mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-01 03:11:44 +02:00
remove return value from transforms
This commit is contained in:
@@ -40,7 +40,6 @@ const OPERATIONS = {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Object} operation
|
* @param {Object} operation
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function applyOperation(transform, operation) {
|
export function applyOperation(transform, operation) {
|
||||||
@@ -53,11 +52,8 @@ export function applyOperation(transform, operation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug(type, operation)
|
debug(type, operation)
|
||||||
|
|
||||||
transform.state = fn(state, operation)
|
transform.state = fn(state, operation)
|
||||||
transform.operations = operations.concat([operation])
|
transform.operations = operations.concat([operation])
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -6,7 +6,6 @@ import Normalize from '../utils/normalize'
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Mark} mark
|
* @param {Mark} mark
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function addMark(transform, mark) {
|
export function addMark(transform, mark) {
|
||||||
@@ -16,19 +15,19 @@ export function addMark(transform, mark) {
|
|||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
|
|
||||||
if (selection.isExpanded) {
|
if (selection.isExpanded) {
|
||||||
return transform.addMarkAtRange(selection, mark)
|
transform.addMarkAtRange(selection, mark)
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (selection.marks) {
|
else if (selection.marks) {
|
||||||
const marks = selection.marks.add(mark)
|
const marks = selection.marks.add(mark)
|
||||||
const sel = selection.merge({ marks })
|
const sel = selection.merge({ marks })
|
||||||
return transform.moveTo(sel)
|
transform.moveTo(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
const marks = document.getMarksAtRange(selection).add(mark)
|
const marks = document.getMarksAtRange(selection).add(mark)
|
||||||
const sel = selection.merge({ marks })
|
const sel = selection.merge({ marks })
|
||||||
return transform.moveTo(sel)
|
transform.moveTo(sel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +35,6 @@ export function addMark(transform, mark) {
|
|||||||
* Delete at the current selection.
|
* Delete at the current selection.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function _delete(transform) {
|
export function _delete(transform) {
|
||||||
@@ -44,7 +42,7 @@ export function _delete(transform) {
|
|||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
|
|
||||||
// If the selection is collapsed, there's nothing to delete.
|
// If the selection is collapsed, there's nothing to delete.
|
||||||
if (selection.isCollapsed) return transform
|
if (selection.isCollapsed) return
|
||||||
|
|
||||||
const { startText } = state
|
const { startText } = state
|
||||||
const { startKey, startOffset, endKey, endOffset } = selection
|
const { startKey, startOffset, endKey, endOffset } = selection
|
||||||
@@ -95,7 +93,7 @@ export function _delete(transform) {
|
|||||||
after = selection.collapseToStart()
|
after = selection.collapseToStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
transform
|
||||||
.unsetSelection()
|
.unsetSelection()
|
||||||
.deleteAtRange(selection)
|
.deleteAtRange(selection)
|
||||||
.moveTo(after)
|
.moveTo(after)
|
||||||
@@ -106,14 +104,12 @@ export function _delete(transform) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Number} n (optional)
|
* @param {Number} n (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function deleteBackward(transform, n = 1) {
|
export function deleteBackward(transform, n = 1) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
|
transform
|
||||||
return transform
|
|
||||||
.deleteBackwardAtRange(selection, n)
|
.deleteBackwardAtRange(selection, n)
|
||||||
.collapseToEnd()
|
.collapseToEnd()
|
||||||
}
|
}
|
||||||
@@ -123,14 +119,12 @@ export function deleteBackward(transform, n = 1) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Number} n (optional)
|
* @param {Number} n (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function deleteForward(transform, n = 1) {
|
export function deleteForward(transform, n = 1) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
|
transform
|
||||||
return transform
|
|
||||||
.deleteForwardAtRange(selection, n)
|
.deleteForwardAtRange(selection, n)
|
||||||
.collapseToEnd()
|
.collapseToEnd()
|
||||||
}
|
}
|
||||||
@@ -140,7 +134,6 @@ export function deleteForward(transform, n = 1) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {String|Object|Block} block
|
* @param {String|Object|Block} block
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertBlock(transform, block) {
|
export function insertBlock(transform, block) {
|
||||||
@@ -156,7 +149,7 @@ export function insertBlock(transform, block) {
|
|||||||
const text = document.getTexts().find(n => !keys.includes(n.key))
|
const text = document.getTexts().find(n => !keys.includes(n.key))
|
||||||
const after = selection.collapseToEndOf(text)
|
const after = selection.collapseToEndOf(text)
|
||||||
|
|
||||||
return transform.moveTo(after)
|
transform.moveTo(after)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,14 +157,13 @@ export function insertBlock(transform, block) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Document} fragment
|
* @param {Document} fragment
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertFragment(transform, fragment) {
|
export function insertFragment(transform, fragment) {
|
||||||
let { state } = transform
|
let { state } = transform
|
||||||
let { document, selection } = state
|
let { document, selection } = state
|
||||||
|
|
||||||
if (!fragment.length) return transform
|
if (!fragment.length) return
|
||||||
|
|
||||||
const { startText, endText } = state
|
const { startText, endText } = state
|
||||||
const lastText = fragment.getLastText()
|
const lastText = fragment.getLastText()
|
||||||
@@ -207,7 +199,7 @@ export function insertFragment(transform, fragment) {
|
|||||||
.moveForward(lastText.length)
|
.moveForward(lastText.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.moveTo(after)
|
transform.moveTo(after)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -215,7 +207,6 @@ export function insertFragment(transform, fragment) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {String|Object|Block} inline
|
* @param {String|Object|Block} inline
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertInline(transform, inline) {
|
export function insertInline(transform, inline) {
|
||||||
@@ -246,7 +237,7 @@ export function insertInline(transform, inline) {
|
|||||||
after = selection.collapseToEndOf(text)
|
after = selection.collapseToEndOf(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.moveTo(after)
|
transform.moveTo(after)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -255,7 +246,6 @@ export function insertInline(transform, inline) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {String} text
|
* @param {String} text
|
||||||
* @param {Set<Mark>} marks (optional)
|
* @param {Set<Mark>} marks (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertText(transform, text, marks) {
|
export function insertText(transform, text, marks) {
|
||||||
@@ -279,7 +269,7 @@ export function insertText(transform, text, marks) {
|
|||||||
|
|
||||||
marks = marks || selection.marks
|
marks = marks || selection.marks
|
||||||
|
|
||||||
return transform
|
transform
|
||||||
.unsetSelection()
|
.unsetSelection()
|
||||||
.insertTextAtRange(selection, text, marks)
|
.insertTextAtRange(selection, text, marks)
|
||||||
.moveTo(after)
|
.moveTo(after)
|
||||||
@@ -290,13 +280,12 @@ export function insertText(transform, text, marks) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Object} properties
|
* @param {Object} properties
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function setBlock(transform, properties) {
|
export function setBlock(transform, properties) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
return transform.setBlockAtRange(selection, properties)
|
transform.setBlockAtRange(selection, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -304,13 +293,12 @@ export function setBlock(transform, properties) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Object} properties
|
* @param {Object} properties
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function setInline(transform, properties) {
|
export function setInline(transform, properties) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
return transform.setInlineAtRange(selection, properties)
|
transform.setInlineAtRange(selection, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -318,7 +306,6 @@ export function setInline(transform, properties) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Number} depth (optional)
|
* @param {Number} depth (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function splitBlock(transform, depth = 1) {
|
export function splitBlock(transform, depth = 1) {
|
||||||
@@ -354,7 +341,7 @@ export function splitBlock(transform, depth = 1) {
|
|||||||
after = selection.collapseToStartOf(nextText)
|
after = selection.collapseToStartOf(nextText)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.moveTo(after)
|
transform.moveTo(after)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -362,7 +349,6 @@ export function splitBlock(transform, depth = 1) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Number} depth (optional)
|
* @param {Number} depth (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function splitInline(transform, depth = Infinity) {
|
export function splitInline(transform, depth = Infinity) {
|
||||||
@@ -389,7 +375,7 @@ export function splitInline(transform, depth = Infinity) {
|
|||||||
(offset + startOffset == 0) ||
|
(offset + startOffset == 0) ||
|
||||||
(offset + startNode.length == startOffset)
|
(offset + startNode.length == startOffset)
|
||||||
) {
|
) {
|
||||||
return transform
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
transform.unsetSelection()
|
transform.unsetSelection()
|
||||||
@@ -404,7 +390,7 @@ export function splitInline(transform, depth = Infinity) {
|
|||||||
after = selection.collapseToStartOf(nextNode)
|
after = selection.collapseToStartOf(nextNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.moveTo(after)
|
transform.moveTo(after)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -412,29 +398,27 @@ export function splitInline(transform, depth = Infinity) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Mark} mark
|
* @param {Mark} mark
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function removeMark(transform, mark) {
|
export function removeMark(transform, mark) {
|
||||||
mark = Normalize.mark(mark)
|
mark = Normalize.mark(mark)
|
||||||
|
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
|
|
||||||
if (selection.isExpanded) {
|
if (selection.isExpanded) {
|
||||||
return transform.removeMarkAtRange(selection, mark)
|
transform.removeMarkAtRange(selection, mark)
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (selection.marks) {
|
else if (selection.marks) {
|
||||||
const marks = selection.marks.remove(mark)
|
const marks = selection.marks.remove(mark)
|
||||||
const sel = selection.merge({ marks })
|
const sel = selection.merge({ marks })
|
||||||
return transform.moveTo(sel)
|
transform.moveTo(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
const marks = document.getMarksAtRange(selection).remove(mark)
|
const marks = document.getMarksAtRange(selection).remove(mark)
|
||||||
const sel = selection.merge({ marks })
|
const sel = selection.merge({ marks })
|
||||||
return transform.moveTo(sel)
|
transform.moveTo(sel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,19 +428,17 @@ export function removeMark(transform, mark) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Mark} mark
|
* @param {Mark} mark
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function toggleMark(transform, mark) {
|
export function toggleMark(transform, mark) {
|
||||||
mark = Normalize.mark(mark)
|
mark = Normalize.mark(mark)
|
||||||
|
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const exists = state.marks.some(m => m.equals(mark))
|
const exists = state.marks.some(m => m.equals(mark))
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
return transform.removeMark(mark)
|
transform.removeMark(mark)
|
||||||
} else {
|
} else {
|
||||||
return transform.addMark(mark)
|
transform.addMark(mark)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,13 +447,12 @@ export function toggleMark(transform, mark) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Object|String} properties
|
* @param {Object|String} properties
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function unwrapBlock(transform, properties) {
|
export function unwrapBlock(transform, properties) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
return transform.unwrapBlockAtRange(selection, properties)
|
transform.unwrapBlockAtRange(selection, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -479,13 +460,12 @@ export function unwrapBlock(transform, properties) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Object|String} properties
|
* @param {Object|String} properties
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function unwrapInline(transform, properties) {
|
export function unwrapInline(transform, properties) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
return transform.unwrapInlineAtRange(selection, properties)
|
transform.unwrapInlineAtRange(selection, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -494,13 +474,12 @@ export function unwrapInline(transform, properties) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Object|String} properties
|
* @param {Object|String} properties
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function wrapBlock(transform, properties) {
|
export function wrapBlock(transform, properties) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
return transform.wrapBlockAtRange(selection, properties)
|
transform.wrapBlockAtRange(selection, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -508,7 +487,6 @@ export function wrapBlock(transform, properties) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Object|String} properties
|
* @param {Object|String} properties
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function wrapInline(transform, properties) {
|
export function wrapInline(transform, properties) {
|
||||||
@@ -551,7 +529,7 @@ export function wrapInline(transform, properties) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
after = after.normalize(document)
|
after = after.normalize(document)
|
||||||
return transform.moveTo(after)
|
transform.moveTo(after)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -560,7 +538,6 @@ export function wrapInline(transform, properties) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {String} prefix
|
* @param {String} prefix
|
||||||
* @param {String} suffix
|
* @param {String} suffix
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function wrapText(transform, prefix, suffix = prefix) {
|
export function wrapText(transform, prefix, suffix = prefix) {
|
||||||
@@ -580,7 +557,7 @@ export function wrapText(transform, prefix, suffix = prefix) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
transform
|
||||||
.unsetSelection()
|
.unsetSelection()
|
||||||
.wrapTextAtRange(selection, prefix, suffix)
|
.wrapTextAtRange(selection, prefix, suffix)
|
||||||
.moveTo(after)
|
.moveTo(after)
|
||||||
|
@@ -12,11 +12,10 @@ import { List } from 'immutable'
|
|||||||
* @param {Mixed} mark
|
* @param {Mixed} mark
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function addMarkAtRange(transform, range, mark, options = {}) {
|
export function addMarkAtRange(transform, range, mark, options = {}) {
|
||||||
if (range.isCollapsed) return transform
|
if (range.isCollapsed) return
|
||||||
|
|
||||||
const { normalize = true } = options
|
const { normalize = true } = options
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
@@ -35,8 +34,6 @@ export function addMarkAtRange(transform, range, mark, options = {}) {
|
|||||||
|
|
||||||
transform.addMarkByKey(key, index, length, mark, { normalize })
|
transform.addMarkByKey(key, index, length, mark, { normalize })
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,11 +43,10 @@ export function addMarkAtRange(transform, range, mark, options = {}) {
|
|||||||
* @param {Selection} range
|
* @param {Selection} range
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function deleteAtRange(transform, range, options = {}) {
|
export function deleteAtRange(transform, range, options = {}) {
|
||||||
if (range.isCollapsed) return transform
|
if (range.isCollapsed) return
|
||||||
|
|
||||||
const { normalize = true } = options
|
const { normalize = true } = options
|
||||||
const { startKey, startOffset, endKey, endOffset } = range
|
const { startKey, startOffset, endKey, endOffset } = range
|
||||||
@@ -58,7 +54,8 @@ export function deleteAtRange(transform, range, options = {}) {
|
|||||||
if (startKey == endKey) {
|
if (startKey == endKey) {
|
||||||
const index = startOffset
|
const index = startOffset
|
||||||
const length = endOffset - startOffset
|
const length = endOffset - startOffset
|
||||||
return transform.removeTextByKey(startKey, index, length, { normalize })
|
transform.removeTextByKey(startKey, index, length, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let { state } = transform
|
let { state } = transform
|
||||||
@@ -108,8 +105,6 @@ export function deleteAtRange(transform, range, options = {}) {
|
|||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform.normalizeNodeByKey(ancestor.key, SCHEMA)
|
transform.normalizeNodeByKey(ancestor.key, SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,7 +115,6 @@ export function deleteAtRange(transform, range, options = {}) {
|
|||||||
* @param {Number} n (optional)
|
* @param {Number} n (optional)
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function deleteBackwardAtRange(transform, range, n = 1, options = {}) {
|
export function deleteBackwardAtRange(transform, range, n = 1, options = {}) {
|
||||||
@@ -130,21 +124,24 @@ export function deleteBackwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
const { startKey, focusOffset } = range
|
const { startKey, focusOffset } = range
|
||||||
|
|
||||||
if (range.isExpanded) {
|
if (range.isExpanded) {
|
||||||
return transform.deleteAtRange(range, { normalize })
|
transform.deleteAtRange(range, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const block = document.getClosestBlock(startKey)
|
const block = document.getClosestBlock(startKey)
|
||||||
if (block && block.isVoid) {
|
if (block && block.isVoid) {
|
||||||
return transform.removeNodeByKey(block.key, { normalize })
|
transform.removeNodeByKey(block.key, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const inline = document.getClosestInline(startKey)
|
const inline = document.getClosestInline(startKey)
|
||||||
if (inline && inline.isVoid) {
|
if (inline && inline.isVoid) {
|
||||||
return transform.removeNodeByKey(inline.key, { normalize })
|
transform.removeNodeByKey(inline.key, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (range.isAtStartOf(document)) {
|
if (range.isAtStartOf(document)) {
|
||||||
return transform
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const text = document.getDescendant(startKey)
|
const text = document.getDescendant(startKey)
|
||||||
@@ -154,11 +151,13 @@ export function deleteBackwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
const prevInline = document.getClosestInline(prev.key)
|
const prevInline = document.getClosestInline(prev.key)
|
||||||
|
|
||||||
if (prevBlock && prevBlock.isVoid) {
|
if (prevBlock && prevBlock.isVoid) {
|
||||||
return transform.removeNodeByKey(prevBlock.key, { normalize })
|
transform.removeNodeByKey(prevBlock.key, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prevInline && prevInline.isVoid) {
|
if (prevInline && prevInline.isVoid) {
|
||||||
return transform.removeNodeByKey(prevInline.key, { normalize })
|
transform.removeNodeByKey(prevInline.key, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
range = range.merge({
|
range = range.merge({
|
||||||
@@ -166,7 +165,8 @@ export function deleteBackwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
anchorOffset: prev.length,
|
anchorOffset: prev.length,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform.deleteAtRange(range, { normalize })
|
transform.deleteAtRange(range, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
range = range.merge({
|
range = range.merge({
|
||||||
@@ -174,7 +174,7 @@ export function deleteBackwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
isBackward: true,
|
isBackward: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform.deleteAtRange(range, { normalize })
|
transform.deleteAtRange(range, { normalize })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -185,7 +185,6 @@ export function deleteBackwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
* @param {Number} n (optional)
|
* @param {Number} n (optional)
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function deleteForwardAtRange(transform, range, n = 1, options = {}) {
|
export function deleteForwardAtRange(transform, range, n = 1, options = {}) {
|
||||||
@@ -195,21 +194,24 @@ export function deleteForwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
const { startKey, focusOffset } = range
|
const { startKey, focusOffset } = range
|
||||||
|
|
||||||
if (range.isExpanded) {
|
if (range.isExpanded) {
|
||||||
return transform.deleteAtRange(range, { normalize })
|
transform.deleteAtRange(range, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const block = document.getClosestBlock(startKey)
|
const block = document.getClosestBlock(startKey)
|
||||||
if (block && block.isVoid) {
|
if (block && block.isVoid) {
|
||||||
return transform.removeNodeByKey(block.key, { normalize })
|
transform.removeNodeByKey(block.key, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const inline = document.getClosestInline(startKey)
|
const inline = document.getClosestInline(startKey)
|
||||||
if (inline && inline.isVoid) {
|
if (inline && inline.isVoid) {
|
||||||
return transform.removeNodeByKey(inline.key, { normalize })
|
transform.removeNodeByKey(inline.key, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (range.isAtEndOf(document)) {
|
if (range.isAtEndOf(document)) {
|
||||||
return transform
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const text = document.getDescendant(startKey)
|
const text = document.getDescendant(startKey)
|
||||||
@@ -219,11 +221,13 @@ export function deleteForwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
const nextInline = document.getClosestInline(next.key)
|
const nextInline = document.getClosestInline(next.key)
|
||||||
|
|
||||||
if (nextBlock && nextBlock.isVoid) {
|
if (nextBlock && nextBlock.isVoid) {
|
||||||
return transform.removeNodeByKey(nextBlock.key, { normalize })
|
transform.removeNodeByKey(nextBlock.key, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextInline && nextInline.isVoid) {
|
if (nextInline && nextInline.isVoid) {
|
||||||
return transform.removeNodeByKey(nextInline.key, { normalize })
|
transform.removeNodeByKey(nextInline.key, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
range = range.merge({
|
range = range.merge({
|
||||||
@@ -231,14 +235,15 @@ export function deleteForwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
focusOffset: 0
|
focusOffset: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform.deleteAtRange(range, { normalize })
|
transform.deleteAtRange(range, { normalize })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
range = range.merge({
|
range = range.merge({
|
||||||
focusOffset: focusOffset + n
|
focusOffset: focusOffset + n
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform.deleteAtRange(range, { normalize })
|
transform.deleteAtRange(range, { normalize })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -249,7 +254,6 @@ export function deleteForwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
* @param {Block|String|Object} block
|
* @param {Block|String|Object} block
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertBlockAtRange(transform, range, block, options = {}) {
|
export function insertBlockAtRange(transform, range, block, options = {}) {
|
||||||
@@ -295,8 +299,6 @@ export function insertBlockAtRange(transform, range, block, options = {}) {
|
|||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform.normalizeNodeByKey(parent.key, SCHEMA)
|
transform.normalizeNodeByKey(parent.key, SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -307,7 +309,6 @@ export function insertBlockAtRange(transform, range, block, options = {}) {
|
|||||||
* @param {Document} fragment
|
* @param {Document} fragment
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertFragmentAtRange(transform, range, fragment, options = {}) {
|
export function insertFragmentAtRange(transform, range, fragment, options = {}) {
|
||||||
@@ -320,9 +321,7 @@ export function insertFragmentAtRange(transform, range, fragment, options = {})
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the fragment is empty, there's nothing to do after deleting.
|
// If the fragment is empty, there's nothing to do after deleting.
|
||||||
if (!fragment.length) {
|
if (!fragment.length) return
|
||||||
return transform
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regenerate the keys for all of the fragments nodes, so that they're
|
// Regenerate the keys for all of the fragments nodes, so that they're
|
||||||
// guaranteed not to collide with the existing keys in the document. Otherwise
|
// guaranteed not to collide with the existing keys in the document. Otherwise
|
||||||
@@ -412,8 +411,6 @@ export function insertFragmentAtRange(transform, range, fragment, options = {})
|
|||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform.normalizeNodeByKey(parent.key, SCHEMA)
|
transform.normalizeNodeByKey(parent.key, SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -424,7 +421,6 @@ export function insertFragmentAtRange(transform, range, fragment, options = {})
|
|||||||
* @param {Inline|String|Object} inline
|
* @param {Inline|String|Object} inline
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertInlineAtRange(transform, range, inline, options = {}) {
|
export function insertInlineAtRange(transform, range, inline, options = {}) {
|
||||||
@@ -443,9 +439,7 @@ export function insertInlineAtRange(transform, range, inline, options = {}) {
|
|||||||
const startText = document.assertDescendant(startKey)
|
const startText = document.assertDescendant(startKey)
|
||||||
const index = parent.nodes.indexOf(startText)
|
const index = parent.nodes.indexOf(startText)
|
||||||
|
|
||||||
if (parent.isVoid) {
|
if (parent.isVoid) return
|
||||||
return transform
|
|
||||||
}
|
|
||||||
|
|
||||||
transform.splitNodeByKey(startKey, startOffset, { normalize: false })
|
transform.splitNodeByKey(startKey, startOffset, { normalize: false })
|
||||||
transform.insertNodeByKey(parent.key, index + 1, inline, { normalize: false })
|
transform.insertNodeByKey(parent.key, index + 1, inline, { normalize: false })
|
||||||
@@ -453,8 +447,6 @@ export function insertInlineAtRange(transform, range, inline, options = {}) {
|
|||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform.normalizeNodeByKey(parent.key, SCHEMA)
|
transform.normalizeNodeByKey(parent.key, SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -466,7 +458,6 @@ export function insertInlineAtRange(transform, range, inline, options = {}) {
|
|||||||
* @param {Set<Mark>} marks (optional)
|
* @param {Set<Mark>} marks (optional)
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertTextAtRange(transform, range, text, marks, options = {}) {
|
export function insertTextAtRange(transform, range, text, marks, options = {}) {
|
||||||
@@ -476,9 +467,7 @@ export function insertTextAtRange(transform, range, text, marks, options = {}) {
|
|||||||
const { startKey, startOffset } = range
|
const { startKey, startOffset } = range
|
||||||
const parent = document.getParent(startKey)
|
const parent = document.getParent(startKey)
|
||||||
|
|
||||||
if (parent.isVoid) {
|
if (parent.isVoid) return
|
||||||
return transform
|
|
||||||
}
|
|
||||||
|
|
||||||
if (range.isExpanded) {
|
if (range.isExpanded) {
|
||||||
transform.deleteAtRange(range, { normalize: false })
|
transform.deleteAtRange(range, { normalize: false })
|
||||||
@@ -489,7 +478,7 @@ export function insertTextAtRange(transform, range, text, marks, options = {}) {
|
|||||||
normalize = range.isExpanded
|
normalize = range.isExpanded
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.insertTextByKey(startKey, startOffset, text, marks, { normalize })
|
transform.insertTextByKey(startKey, startOffset, text, marks, { normalize })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -500,11 +489,10 @@ export function insertTextAtRange(transform, range, text, marks, options = {}) {
|
|||||||
* @param {Mark|String} mark (optional)
|
* @param {Mark|String} mark (optional)
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function removeMarkAtRange(transform, range, mark, options = {}) {
|
export function removeMarkAtRange(transform, range, mark, options = {}) {
|
||||||
if (range.isCollapsed) return transform
|
if (range.isCollapsed) return
|
||||||
|
|
||||||
const { normalize = true } = options
|
const { normalize = true } = options
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
@@ -523,8 +511,6 @@ export function removeMarkAtRange(transform, range, mark, options = {}) {
|
|||||||
|
|
||||||
transform.removeMarkByKey(key, index, length, mark, { normalize })
|
transform.removeMarkByKey(key, index, length, mark, { normalize })
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -535,7 +521,6 @@ export function removeMarkAtRange(transform, range, mark, options = {}) {
|
|||||||
* @param {Object|String} properties
|
* @param {Object|String} properties
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function setBlockAtRange(transform, range, properties, options = {}) {
|
export function setBlockAtRange(transform, range, properties, options = {}) {
|
||||||
@@ -547,8 +532,6 @@ export function setBlockAtRange(transform, range, properties, options = {}) {
|
|||||||
blocks.forEach((block) => {
|
blocks.forEach((block) => {
|
||||||
transform.setNodeByKey(block.key, properties, { normalize })
|
transform.setNodeByKey(block.key, properties, { normalize })
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -559,7 +542,6 @@ export function setBlockAtRange(transform, range, properties, options = {}) {
|
|||||||
* @param {Object|String} properties
|
* @param {Object|String} properties
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function setInlineAtRange(transform, range, properties, options = {}) {
|
export function setInlineAtRange(transform, range, properties, options = {}) {
|
||||||
@@ -571,8 +553,6 @@ export function setInlineAtRange(transform, range, properties, options = {}) {
|
|||||||
inlines.forEach((inline) => {
|
inlines.forEach((inline) => {
|
||||||
transform.setNodeByKey(inline.key, properties, { normalize})
|
transform.setNodeByKey(inline.key, properties, { normalize})
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -583,7 +563,6 @@ export function setInlineAtRange(transform, range, properties, options = {}) {
|
|||||||
* @param {Number} height (optional)
|
* @param {Number} height (optional)
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function splitBlockAtRange(transform, range, height = 1, options = {}) {
|
export function splitBlockAtRange(transform, range, height = 1, options = {}) {
|
||||||
@@ -609,7 +588,7 @@ export function splitBlockAtRange(transform, range, height = 1, options = {}) {
|
|||||||
h++
|
h++
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.splitNodeByKey(node.key, offset, { normalize })
|
transform.splitNodeByKey(node.key, offset, { normalize })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -620,7 +599,6 @@ export function splitBlockAtRange(transform, range, height = 1, options = {}) {
|
|||||||
* @param {Number} height (optional)
|
* @param {Number} height (optional)
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function splitInlineAtRange(transform, range, height = Infinity, options = {}) {
|
export function splitInlineAtRange(transform, range, height = Infinity, options = {}) {
|
||||||
@@ -646,7 +624,7 @@ export function splitInlineAtRange(transform, range, height = Infinity, options
|
|||||||
h++
|
h++
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.splitNodeByKey(node.key, offset, { normalize })
|
transform.splitNodeByKey(node.key, offset, { normalize })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -658,11 +636,10 @@ export function splitInlineAtRange(transform, range, height = Infinity, options
|
|||||||
* @param {Mixed} mark
|
* @param {Mixed} mark
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function toggleMarkAtRange(transform, range, mark, options = {}) {
|
export function toggleMarkAtRange(transform, range, mark, options = {}) {
|
||||||
if (range.isCollapsed) return transform
|
if (range.isCollapsed) return
|
||||||
|
|
||||||
mark = Normalize.mark(mark)
|
mark = Normalize.mark(mark)
|
||||||
|
|
||||||
@@ -677,8 +654,6 @@ export function toggleMarkAtRange(transform, range, mark, options = {}) {
|
|||||||
} else {
|
} else {
|
||||||
transform.addMarkAtRange(range, mark, { normalize })
|
transform.addMarkAtRange(range, mark, { normalize })
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -689,7 +664,6 @@ export function toggleMarkAtRange(transform, range, mark, options = {}) {
|
|||||||
* @param {String|Object} properties
|
* @param {String|Object} properties
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function unwrapBlockAtRange(transform, range, properties, options = {}) {
|
export function unwrapBlockAtRange(transform, range, properties, options = {}) {
|
||||||
@@ -771,8 +745,6 @@ export function unwrapBlockAtRange(transform, range, properties, options = {}) {
|
|||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform.normalizeDocument(SCHEMA)
|
transform.normalizeDocument(SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -783,7 +755,6 @@ export function unwrapBlockAtRange(transform, range, properties, options = {}) {
|
|||||||
* @param {String|Object} properties
|
* @param {String|Object} properties
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function unwrapInlineAtRange(transform, range, properties, options = {}) {
|
export function unwrapInlineAtRange(transform, range, properties, options = {}) {
|
||||||
@@ -820,8 +791,6 @@ export function unwrapInlineAtRange(transform, range, properties, options = {})
|
|||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform.normalizeDocument(SCHEMA)
|
transform.normalizeDocument(SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -832,7 +801,6 @@ export function unwrapInlineAtRange(transform, range, properties, options = {})
|
|||||||
* @param {Block|Object|String} block
|
* @param {Block|Object|String} block
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function wrapBlockAtRange(transform, range, block, options = {}) {
|
export function wrapBlockAtRange(transform, range, block, options = {}) {
|
||||||
@@ -892,8 +860,6 @@ export function wrapBlockAtRange(transform, range, block, options = {}) {
|
|||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform.normalizeNodeByKey(parent.key, SCHEMA)
|
transform.normalizeNodeByKey(parent.key, SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -904,11 +870,10 @@ export function wrapBlockAtRange(transform, range, block, options = {}) {
|
|||||||
* @param {Inline|Object|String} inline
|
* @param {Inline|Object|String} inline
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function wrapInlineAtRange(transform, range, inline, options = {}) {
|
export function wrapInlineAtRange(transform, range, inline, options = {}) {
|
||||||
if (range.isCollapsed) return transform
|
if (range.isCollapsed) return
|
||||||
|
|
||||||
inline = Normalize.inline(inline)
|
inline = Normalize.inline(inline)
|
||||||
inline = inline.merge({ nodes: inline.nodes.clear() })
|
inline = inline.merge({ nodes: inline.nodes.clear() })
|
||||||
@@ -1016,8 +981,6 @@ export function wrapInlineAtRange(transform, range, inline, options = {}) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1029,7 +992,6 @@ export function wrapInlineAtRange(transform, range, inline, options = {}) {
|
|||||||
* @param {String} suffix (optional)
|
* @param {String} suffix (optional)
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {Boolean} normalize
|
* @property {Boolean} normalize
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function wrapTextAtRange(transform, range, prefix, suffix = prefix, options = {}) {
|
export function wrapTextAtRange(transform, range, prefix, suffix = prefix, options = {}) {
|
||||||
@@ -1042,7 +1004,6 @@ export function wrapTextAtRange(transform, range, prefix, suffix = prefix, optio
|
|||||||
end = end.moveForward(prefix.length)
|
end = end.moveForward(prefix.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
transform.insertTextAtRange(start, prefix, [], { normalize })
|
||||||
.insertTextAtRange(start, prefix, [], { normalize })
|
transform.insertTextAtRange(end, suffix, [], { normalize })
|
||||||
.insertTextAtRange(end, suffix, [], { normalize })
|
|
||||||
}
|
}
|
||||||
|
@@ -8,13 +8,11 @@ import warn from '../utils/warn'
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Schema} schema
|
* @param {Schema} schema
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function normalize(transform, schema) {
|
export function normalize(transform, schema) {
|
||||||
transform.normalizeDocument(schema)
|
transform.normalizeDocument(schema)
|
||||||
transform.normalizeSelection(schema)
|
transform.normalizeSelection(schema)
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,14 +20,12 @@ export function normalize(transform, schema) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Schema} schema
|
* @param {Schema} schema
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function normalizeDocument(transform, schema) {
|
export function normalizeDocument(transform, schema) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document } = state
|
const { document } = state
|
||||||
transform.normalizeNodeByKey(document.key, schema)
|
transform.normalizeNodeByKey(document.key, schema)
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,24 +34,20 @@ export function normalizeDocument(transform, schema) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node|String} key
|
* @param {Node|String} key
|
||||||
* @param {Schema} schema
|
* @param {Schema} schema
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function normalizeNodeByKey(transform, key, schema) {
|
export function normalizeNodeByKey(transform, key, schema) {
|
||||||
assertSchema(schema)
|
assertSchema(schema)
|
||||||
key = Normalize.key(key)
|
|
||||||
|
|
||||||
// If the schema has no validation rules, there's nothing to normalize.
|
// If the schema has no validation rules, there's nothing to normalize.
|
||||||
if (!schema.hasValidators) {
|
if (!schema.hasValidators) return
|
||||||
return transform
|
|
||||||
}
|
|
||||||
|
|
||||||
|
key = Normalize.key(key)
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document } = state
|
const { document } = state
|
||||||
const node = document.assertNode(key)
|
const node = document.assertNode(key)
|
||||||
|
|
||||||
normalizeNodeWith(transform, node, schema)
|
normalizeNodeWith(transform, node, schema)
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,31 +56,26 @@ export function normalizeNodeByKey(transform, key, schema) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node|String} key
|
* @param {Node|String} key
|
||||||
* @param {Schema} schema
|
* @param {Schema} schema
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function normalizeParentsByKey(transform, key, schema) {
|
export function normalizeParentsByKey(transform, key, schema) {
|
||||||
assertSchema(schema)
|
assertSchema(schema)
|
||||||
key = Normalize.key(key)
|
|
||||||
|
|
||||||
// If the schema has no validation rules, there's nothing to normalize.
|
// If the schema has no validation rules, there's nothing to normalize.
|
||||||
if (!schema.hasValidators) {
|
if (!schema.hasValidators) return
|
||||||
return transform
|
|
||||||
}
|
|
||||||
|
|
||||||
|
key = Normalize.key(key)
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document } = state
|
const { document } = state
|
||||||
const node = document.assertNode(key)
|
const node = document.assertNode(key)
|
||||||
|
|
||||||
normalizeParentsWith(transform, node, schema)
|
normalizeParentsWith(transform, node, schema)
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize only the selection.
|
* Normalize only the selection.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function normalizeSelection(transform) {
|
export function normalizeSelection(transform) {
|
||||||
@@ -117,7 +104,6 @@ export function normalizeSelection(transform) {
|
|||||||
|
|
||||||
state = state.merge({ selection })
|
state = state.merge({ selection })
|
||||||
transform.state = state
|
transform.state = state
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +112,6 @@ export function normalizeSelection(transform) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
* @param {Schema} schema
|
* @param {Schema} schema
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function normalizeNodeWith(transform, node, schema) {
|
function normalizeNodeWith(transform, node, schema) {
|
||||||
@@ -145,8 +130,6 @@ function normalizeNodeWith(transform, node, schema) {
|
|||||||
if (node) {
|
if (node) {
|
||||||
normalizeNodeOnly(transform, node, schema)
|
normalizeNodeOnly(transform, node, schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,29 +138,23 @@ function normalizeNodeWith(transform, node, schema) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
* @param {Schema} schema
|
* @param {Schema} schema
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function normalizeParentsWith(transform, node, schema) {
|
function normalizeParentsWith(transform, node, schema) {
|
||||||
normalizeNodeOnly(transform, node, schema)
|
normalizeNodeOnly(transform, node, schema)
|
||||||
|
|
||||||
// Normalize went back up to the very top of the document.
|
// Normalize went back up to the very top of the document.
|
||||||
if (node.kind == 'document') {
|
if (node.kind == 'document') return
|
||||||
return transform
|
|
||||||
}
|
|
||||||
|
|
||||||
// Re-find the node first.
|
// Re-find the node first.
|
||||||
node = refindNode(transform, node)
|
node = refindNode(transform, node)
|
||||||
|
if (!node) return
|
||||||
if (!node) {
|
|
||||||
return transform
|
|
||||||
}
|
|
||||||
|
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document } = state
|
const { document } = state
|
||||||
const parent = document.getParent(node.key)
|
const parent = document.getParent(node.key)
|
||||||
|
|
||||||
return normalizeParentsWith(transform, parent, schema)
|
normalizeParentsWith(transform, parent, schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -203,17 +180,14 @@ function refindNode(transform, node) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
* @param {Schema} schema
|
* @param {Schema} schema
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function normalizeChildrenWith(transform, node, schema) {
|
function normalizeChildrenWith(transform, node, schema) {
|
||||||
if (node.kind == 'text') return transform
|
if (node.kind == 'text') return
|
||||||
|
|
||||||
node.nodes.forEach((child) => {
|
node.nodes.forEach((child) => {
|
||||||
normalizeNodeWith(transform, child, schema)
|
normalizeNodeWith(transform, child, schema)
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -222,7 +196,6 @@ function normalizeChildrenWith(transform, node, schema) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
* @param {Schema} schema
|
* @param {Schema} schema
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function normalizeNodeOnly(transform, node, schema) {
|
function normalizeNodeOnly(transform, node, schema) {
|
||||||
@@ -231,7 +204,7 @@ function normalizeNodeOnly(transform, node, schema) {
|
|||||||
|
|
||||||
function iterate(t, n) {
|
function iterate(t, n) {
|
||||||
const failure = n.validate(schema)
|
const failure = n.validate(schema)
|
||||||
if (!failure) return t
|
if (!failure) return
|
||||||
|
|
||||||
const { value, rule } = failure
|
const { value, rule } = failure
|
||||||
|
|
||||||
@@ -241,7 +214,7 @@ function normalizeNodeOnly(transform, node, schema) {
|
|||||||
// Re-find the node reference, in case it was updated. If the node no longer
|
// Re-find the node reference, in case it was updated. If the node no longer
|
||||||
// exists, we're done for this branch.
|
// exists, we're done for this branch.
|
||||||
n = refindNode(t, n)
|
n = refindNode(t, n)
|
||||||
if (!n) return t
|
if (!n) return
|
||||||
|
|
||||||
// Increment the iterations counter, and check to make sure that we haven't
|
// Increment the iterations counter, and check to make sure that we haven't
|
||||||
// exceeded the max. Without this check, it's easy for the `validate` or
|
// exceeded the max. Without this check, it's easy for the `validate` or
|
||||||
@@ -254,10 +227,10 @@ function normalizeNodeOnly(transform, node, schema) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, iterate again.
|
// Otherwise, iterate again.
|
||||||
return iterate(t, n)
|
iterate(t, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
return iterate(transform, node)
|
iterate(transform, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -3,7 +3,6 @@
|
|||||||
* Redo to the next state in the history.
|
* Redo to the next state in the history.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function redo(transform) {
|
export function redo(transform) {
|
||||||
@@ -13,7 +12,7 @@ export function redo(transform) {
|
|||||||
|
|
||||||
// If there's no next snapshot, abort.
|
// If there's no next snapshot, abort.
|
||||||
let next = redos.peek()
|
let next = redos.peek()
|
||||||
if (!next) return transform
|
if (!next) return
|
||||||
|
|
||||||
// Shift the next state into the undo stack.
|
// Shift the next state into the undo stack.
|
||||||
redos = redos.pop()
|
redos = redos.pop()
|
||||||
@@ -31,7 +30,6 @@ export function redo(transform) {
|
|||||||
|
|
||||||
// Update the transform.
|
// Update the transform.
|
||||||
transform.state = state
|
transform.state = state
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,7 +37,6 @@ export function redo(transform) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function save(transform, options = {}) {
|
export function save(transform, options = {}) {
|
||||||
@@ -49,7 +46,7 @@ export function save(transform, options = {}) {
|
|||||||
let { undos, redos } = history
|
let { undos, redos } = history
|
||||||
|
|
||||||
// If there are no operations, abort.
|
// If there are no operations, abort.
|
||||||
if (!operations.length) return transform
|
if (!operations.length) return
|
||||||
|
|
||||||
// Create a new save point or merge the operations into the previous one.
|
// Create a new save point or merge the operations into the previous one.
|
||||||
if (merge) {
|
if (merge) {
|
||||||
@@ -71,14 +68,12 @@ export function save(transform, options = {}) {
|
|||||||
|
|
||||||
// Update the transform.
|
// Update the transform.
|
||||||
transform.state = state
|
transform.state = state
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undo the previous operations in the history.
|
* Undo the previous operations in the history.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function undo(transform) {
|
export function undo(transform) {
|
||||||
@@ -88,7 +83,7 @@ export function undo(transform) {
|
|||||||
|
|
||||||
// If there's no previous snapshot, abort.
|
// If there's no previous snapshot, abort.
|
||||||
let previous = undos.peek()
|
let previous = undos.peek()
|
||||||
if (!previous) return transform
|
if (!previous) return
|
||||||
|
|
||||||
// Shift the previous operations into the redo stack.
|
// Shift the previous operations into the redo stack.
|
||||||
undos = undos.pop()
|
undos = undos.pop()
|
||||||
@@ -108,5 +103,4 @@ export function undo(transform) {
|
|||||||
|
|
||||||
// Update the transform.
|
// Update the transform.
|
||||||
transform.state = state
|
transform.state = state
|
||||||
return transform
|
|
||||||
}
|
}
|
||||||
|
@@ -3,70 +3,65 @@
|
|||||||
* Blur the selection.
|
* Blur the selection.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function blur(transform) {
|
export function blur(transform) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
const sel = selection.blur()
|
const sel = selection.blur()
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the focus point to the anchor point.
|
* Move the focus point to the anchor point.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToAnchor(transform) {
|
export function collapseToAnchor(transform) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
const sel = selection.collapseToAnchor()
|
const sel = selection.collapseToAnchor()
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the start point to the end point.
|
* Move the start point to the end point.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToEnd(transform) {
|
export function collapseToEnd(transform) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
const sel = selection.collapseToEnd()
|
const sel = selection.collapseToEnd()
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the anchor point to the focus point.
|
* Move the anchor point to the focus point.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToFocus(transform) {
|
export function collapseToFocus(transform) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
const sel = selection.collapseToFocus()
|
const sel = selection.collapseToFocus()
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the end point to the start point.
|
* Move the end point to the start point.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToStart(transform) {
|
export function collapseToStart(transform) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
const sel = selection.collapseToStart()
|
const sel = selection.collapseToStart()
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,21 +69,19 @@ export function collapseToStart(transform) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToEndOf(transform, node) {
|
export function collapseToEndOf(transform, node) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
const sel = selection.collapseToEndOf(node)
|
const sel = selection.collapseToEndOf(node)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the selection to the end of the next block.
|
* Move the selection to the end of the next block.
|
||||||
*
|
*
|
||||||
* @param {Transform} tansform
|
* @param {Transform} tansform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToEndOfNextBlock(transform) {
|
export function collapseToEndOfNextBlock(transform) {
|
||||||
@@ -97,17 +90,16 @@ export function collapseToEndOfNextBlock(transform) {
|
|||||||
const blocks = document.getBlocksAtRange(selection)
|
const blocks = document.getBlocksAtRange(selection)
|
||||||
const last = blocks.last()
|
const last = blocks.last()
|
||||||
const next = document.getNextBlock(last)
|
const next = document.getNextBlock(last)
|
||||||
if (!next) return transform
|
if (!next) return
|
||||||
|
|
||||||
const sel = selection.collapseToEndOf(next)
|
const sel = selection.collapseToEndOf(next)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the selection to the end of the next text.
|
* Move the selection to the end of the next text.
|
||||||
*
|
*
|
||||||
* @param {Transform} tansform
|
* @param {Transform} tansform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToEndOfNextText(transform) {
|
export function collapseToEndOfNextText(transform) {
|
||||||
@@ -116,17 +108,16 @@ export function collapseToEndOfNextText(transform) {
|
|||||||
const texts = document.getTextsAtRange(selection)
|
const texts = document.getTextsAtRange(selection)
|
||||||
const last = texts.last()
|
const last = texts.last()
|
||||||
const next = document.getNextText(last)
|
const next = document.getNextText(last)
|
||||||
if (!next) return transform
|
if (!next) return
|
||||||
|
|
||||||
const sel = selection.collapseToEndOf(next)
|
const sel = selection.collapseToEndOf(next)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the selection to the end of the previous block.
|
* Move the selection to the end of the previous block.
|
||||||
*
|
*
|
||||||
* @param {Transform} tansform
|
* @param {Transform} tansform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToEndOfPreviousBlock(transform) {
|
export function collapseToEndOfPreviousBlock(transform) {
|
||||||
@@ -135,17 +126,16 @@ export function collapseToEndOfPreviousBlock(transform) {
|
|||||||
const blocks = document.getBlocksAtRange(selection)
|
const blocks = document.getBlocksAtRange(selection)
|
||||||
const first = blocks.first()
|
const first = blocks.first()
|
||||||
const previous = document.getPreviousBlock(first)
|
const previous = document.getPreviousBlock(first)
|
||||||
if (!previous) return transform
|
if (!previous) return
|
||||||
|
|
||||||
const sel = selection.collapseToEndOf(previous)
|
const sel = selection.collapseToEndOf(previous)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the selection to the end of the previous text.
|
* Move the selection to the end of the previous text.
|
||||||
*
|
*
|
||||||
* @param {Transform} tansform
|
* @param {Transform} tansform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToEndOfPreviousText(transform) {
|
export function collapseToEndOfPreviousText(transform) {
|
||||||
@@ -154,10 +144,10 @@ export function collapseToEndOfPreviousText(transform) {
|
|||||||
const texts = document.getTextsAtRange(selection)
|
const texts = document.getTextsAtRange(selection)
|
||||||
const first = texts.first()
|
const first = texts.first()
|
||||||
const previous = document.getPreviousText(first)
|
const previous = document.getPreviousText(first)
|
||||||
if (!previous) return transform
|
if (!previous) return
|
||||||
|
|
||||||
const sel = selection.collapseToEndOf(previous)
|
const sel = selection.collapseToEndOf(previous)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,21 +155,19 @@ export function collapseToEndOfPreviousText(transform) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToStartOf(transform, node) {
|
export function collapseToStartOf(transform, node) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
const sel = selection.collapseToStartOf(node)
|
const sel = selection.collapseToStartOf(node)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the selection to the start of the next block.
|
* Move the selection to the start of the next block.
|
||||||
*
|
*
|
||||||
* @param {Transform} tansform
|
* @param {Transform} tansform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToStartOfNextBlock(transform) {
|
export function collapseToStartOfNextBlock(transform) {
|
||||||
@@ -188,17 +176,16 @@ export function collapseToStartOfNextBlock(transform) {
|
|||||||
const blocks = document.getBlocksAtRange(selection)
|
const blocks = document.getBlocksAtRange(selection)
|
||||||
const last = blocks.last()
|
const last = blocks.last()
|
||||||
const next = document.getNextBlock(last)
|
const next = document.getNextBlock(last)
|
||||||
if (!next) return transform
|
if (!next) return
|
||||||
|
|
||||||
const sel = selection.collapseToStartOf(next)
|
const sel = selection.collapseToStartOf(next)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the selection to the start of the next text.
|
* Move the selection to the start of the next text.
|
||||||
*
|
*
|
||||||
* @param {Transform} tansform
|
* @param {Transform} tansform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToStartOfNextText(transform) {
|
export function collapseToStartOfNextText(transform) {
|
||||||
@@ -207,17 +194,16 @@ export function collapseToStartOfNextText(transform) {
|
|||||||
const texts = document.getTextsAtRange(selection)
|
const texts = document.getTextsAtRange(selection)
|
||||||
const last = texts.last()
|
const last = texts.last()
|
||||||
const next = document.getNextText(last)
|
const next = document.getNextText(last)
|
||||||
if (!next) return transform
|
if (!next) return
|
||||||
|
|
||||||
const sel = selection.collapseToStartOf(next)
|
const sel = selection.collapseToStartOf(next)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the selection to the start of the previous block.
|
* Move the selection to the start of the previous block.
|
||||||
*
|
*
|
||||||
* @param {Transform} tansform
|
* @param {Transform} tansform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToStartOfPreviousBlock(transform) {
|
export function collapseToStartOfPreviousBlock(transform) {
|
||||||
@@ -226,17 +212,16 @@ export function collapseToStartOfPreviousBlock(transform) {
|
|||||||
const blocks = document.getBlocksAtRange(selection)
|
const blocks = document.getBlocksAtRange(selection)
|
||||||
const first = blocks.first()
|
const first = blocks.first()
|
||||||
const previous = document.getPreviousBlock(first)
|
const previous = document.getPreviousBlock(first)
|
||||||
if (!previous) return transform
|
if (!previous) return
|
||||||
|
|
||||||
const sel = selection.collapseToStartOf(previous)
|
const sel = selection.collapseToStartOf(previous)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the selection to the start of the previous text.
|
* Move the selection to the start of the previous text.
|
||||||
*
|
*
|
||||||
* @param {Transform} tansform
|
* @param {Transform} tansform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function collapseToStartOfPreviousText(transform) {
|
export function collapseToStartOfPreviousText(transform) {
|
||||||
@@ -245,10 +230,10 @@ export function collapseToStartOfPreviousText(transform) {
|
|||||||
const texts = document.getTextsAtRange(selection)
|
const texts = document.getTextsAtRange(selection)
|
||||||
const first = texts.first()
|
const first = texts.first()
|
||||||
const previous = document.getPreviousText(first)
|
const previous = document.getPreviousText(first)
|
||||||
if (!previous) return transform
|
if (!previous) return
|
||||||
|
|
||||||
const sel = selection.collapseToStartOf(previous)
|
const sel = selection.collapseToStartOf(previous)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -256,14 +241,13 @@ export function collapseToStartOfPreviousText(transform) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Number} n (optional)
|
* @param {Number} n (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function extendBackward(transform, n) {
|
export function extendBackward(transform, n) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
const sel = selection.extendBackward(n).normalize(document)
|
const sel = selection.extendBackward(n).normalize(document)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -271,14 +255,13 @@ export function extendBackward(transform, n) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Number} n (optional)
|
* @param {Number} n (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function extendForward(transform, n) {
|
export function extendForward(transform, n) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
const sel = selection.extendForward(n).normalize(document)
|
const sel = selection.extendForward(n).normalize(document)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -286,14 +269,13 @@ export function extendForward(transform, n) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function extendToEndOf(transform, node) {
|
export function extendToEndOf(transform, node) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
const sel = selection.extendToEndOf(node).normalize(document)
|
const sel = selection.extendToEndOf(node).normalize(document)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -301,28 +283,26 @@ export function extendToEndOf(transform, node) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function extendToStartOf(transform, node) {
|
export function extendToStartOf(transform, node) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
const sel = selection.extendToStartOf(node).normalize(document)
|
const sel = selection.extendToStartOf(node).normalize(document)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Focus the selection.
|
* Focus the selection.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function focus(transform) {
|
export function focus(transform) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
const sel = selection.focus()
|
const sel = selection.focus()
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -330,14 +310,13 @@ export function focus(transform) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Number} n (optional)
|
* @param {Number} n (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function moveBackward(transform, n) {
|
export function moveBackward(transform, n) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
const sel = selection.moveBackward(n).normalize(document)
|
const sel = selection.moveBackward(n).normalize(document)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -345,14 +324,13 @@ export function moveBackward(transform, n) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Number} n (optional)
|
* @param {Number} n (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function moveForward(transform, n) {
|
export function moveForward(transform, n) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
const sel = selection.moveForward(n).normalize(document)
|
const sel = selection.moveForward(n).normalize(document)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -360,11 +338,10 @@ export function moveForward(transform, n) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Object} properties
|
* @param {Object} properties
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function moveTo(transform, properties) {
|
export function moveTo(transform, properties) {
|
||||||
return transform.setSelectionOperation(properties)
|
transform.setSelectionOperation(properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -373,14 +350,13 @@ export function moveTo(transform, properties) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Number} anchor
|
* @param {Number} anchor
|
||||||
* @param {Number} focus (optional)
|
* @param {Number} focus (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function moveToOffsets(transform, anchor, fokus) {
|
export function moveToOffsets(transform, anchor, fokus) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
const sel = selection.moveToOffsets(anchor, fokus)
|
const sel = selection.moveToOffsets(anchor, fokus)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -389,25 +365,23 @@ export function moveToOffsets(transform, anchor, fokus) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Node} start
|
* @param {Node} start
|
||||||
* @param {Node} end (optional)
|
* @param {Node} end (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function moveToRangeOf(transform, start, end) {
|
export function moveToRangeOf(transform, start, end) {
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
const sel = selection.moveToRangeOf(start, end).normalize(document)
|
const sel = selection.moveToRangeOf(start, end).normalize(document)
|
||||||
return transform.setSelectionOperation(sel)
|
transform.setSelectionOperation(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unset the selection, removing an association to a node.
|
* Unset the selection, removing an association to a node.
|
||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function unsetSelection(transform) {
|
export function unsetSelection(transform) {
|
||||||
return transform.setSelectionOperation({
|
transform.setSelectionOperation({
|
||||||
anchorKey: null,
|
anchorKey: null,
|
||||||
anchorOffset: 0,
|
anchorOffset: 0,
|
||||||
focusKey: null,
|
focusKey: null,
|
||||||
|
@@ -9,7 +9,6 @@ import Normalize from '../utils/normalize'
|
|||||||
* @param {Number} offset
|
* @param {Number} offset
|
||||||
* @param {Number} length
|
* @param {Number} length
|
||||||
* @param {Mixed} mark
|
* @param {Mixed} mark
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function addMarkOperation(transform, path, offset, length, mark) {
|
export function addMarkOperation(transform, path, offset, length, mark) {
|
||||||
@@ -30,7 +29,7 @@ export function addMarkOperation(transform, path, offset, length, mark) {
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +39,6 @@ export function addMarkOperation(transform, path, offset, length, mark) {
|
|||||||
* @param {Array} path
|
* @param {Array} path
|
||||||
* @param {Number} index
|
* @param {Number} index
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertNodeOperation(transform, path, index, node) {
|
export function insertNodeOperation(transform, path, index, node) {
|
||||||
@@ -58,7 +56,7 @@ export function insertNodeOperation(transform, path, index, node) {
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +67,6 @@ export function insertNodeOperation(transform, path, index, node) {
|
|||||||
* @param {Number} offset
|
* @param {Number} offset
|
||||||
* @param {String} text
|
* @param {String} text
|
||||||
* @param {Set<Mark>} marks (optional)
|
* @param {Set<Mark>} marks (optional)
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertTextOperation(transform, path, offset, text, marks) {
|
export function insertTextOperation(transform, path, offset, text, marks) {
|
||||||
@@ -90,7 +87,7 @@ export function insertTextOperation(transform, path, offset, text, marks) {
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +96,6 @@ export function insertTextOperation(transform, path, offset, text, marks) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Array} path
|
* @param {Array} path
|
||||||
* @param {Array} withPath
|
* @param {Array} withPath
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function joinNodeOperation(transform, path, withPath) {
|
export function joinNodeOperation(transform, path, withPath) {
|
||||||
@@ -134,7 +130,7 @@ export function joinNodeOperation(transform, path, withPath) {
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,7 +140,6 @@ export function joinNodeOperation(transform, path, withPath) {
|
|||||||
* @param {Array} path
|
* @param {Array} path
|
||||||
* @param {Array} newPath
|
* @param {Array} newPath
|
||||||
* @param {Number} newIndex
|
* @param {Number} newIndex
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function moveNodeOperation(transform, path, newPath, newIndex) {
|
export function moveNodeOperation(transform, path, newPath, newIndex) {
|
||||||
@@ -167,7 +162,7 @@ export function moveNodeOperation(transform, path, newPath, newIndex) {
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,7 +173,6 @@ export function moveNodeOperation(transform, path, newPath, newIndex) {
|
|||||||
* @param {Number} offset
|
* @param {Number} offset
|
||||||
* @param {Number} length
|
* @param {Number} length
|
||||||
* @param {Mark} mark
|
* @param {Mark} mark
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function removeMarkOperation(transform, path, offset, length, mark) {
|
export function removeMarkOperation(transform, path, offset, length, mark) {
|
||||||
@@ -199,7 +193,7 @@ export function removeMarkOperation(transform, path, offset, length, mark) {
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,7 +201,6 @@ export function removeMarkOperation(transform, path, offset, length, mark) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Array} path
|
* @param {Array} path
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function removeNodeOperation(transform, path) {
|
export function removeNodeOperation(transform, path) {
|
||||||
@@ -230,7 +223,7 @@ export function removeNodeOperation(transform, path) {
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -240,7 +233,6 @@ export function removeNodeOperation(transform, path) {
|
|||||||
* @param {Array} path
|
* @param {Array} path
|
||||||
* @param {Number} offset
|
* @param {Number} offset
|
||||||
* @param {Number} length
|
* @param {Number} length
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function removeTextOperation(transform, path, offset, length) {
|
export function removeTextOperation(transform, path, offset, length) {
|
||||||
@@ -282,7 +274,7 @@ export function removeTextOperation(transform, path, offset, length) {
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -294,7 +286,6 @@ export function removeTextOperation(transform, path, offset, length) {
|
|||||||
* @param {Number} length
|
* @param {Number} length
|
||||||
* @param {Mark} mark
|
* @param {Mark} mark
|
||||||
* @param {Mark} newMark
|
* @param {Mark} newMark
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function setMarkOperation(transform, path, offset, length, mark, newMark) {
|
export function setMarkOperation(transform, path, offset, length, mark, newMark) {
|
||||||
@@ -317,7 +308,7 @@ export function setMarkOperation(transform, path, offset, length, mark, newMark)
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -326,7 +317,6 @@ export function setMarkOperation(transform, path, offset, length, mark, newMark)
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Array} path
|
* @param {Array} path
|
||||||
* @param {Object} properties
|
* @param {Object} properties
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function setNodeOperation(transform, path, properties) {
|
export function setNodeOperation(transform, path, properties) {
|
||||||
@@ -352,7 +342,7 @@ export function setNodeOperation(transform, path, properties) {
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -360,7 +350,6 @@ export function setNodeOperation(transform, path, properties) {
|
|||||||
*
|
*
|
||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Mixed} selection
|
* @param {Mixed} selection
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function setSelectionOperation(transform, properties) {
|
export function setSelectionOperation(transform, properties) {
|
||||||
@@ -432,7 +421,7 @@ export function setSelectionOperation(transform, properties) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply the operation.
|
// Apply the operation.
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -441,7 +430,6 @@ export function setSelectionOperation(transform, properties) {
|
|||||||
* @param {Transform} transform
|
* @param {Transform} transform
|
||||||
* @param {Array} path
|
* @param {Array} path
|
||||||
* @param {Number} offset
|
* @param {Number} offset
|
||||||
* @return {Transform}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function splitNodeOperation(transform, path, offset) {
|
export function splitNodeOperation(transform, path, offset) {
|
||||||
@@ -462,5 +450,5 @@ export function splitNodeOperation(transform, path, offset) {
|
|||||||
inverse,
|
inverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform.applyOperation(operation)
|
transform.applyOperation(operation)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user