mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 14:41:23 +02:00
update changes docs, add missing selection changes
This commit is contained in:
@@ -101,21 +101,17 @@ Warning: Calling `setValue` with a `Value` object has unpredictable behavior inc
|
|||||||
|
|
||||||
Hint: Wrapping the call to `setValue` as follows can be helpful if you want to update a value, like in the value's `data` but do not want to have another save point in the undo history: `change.setOperationFlag({save: false}).setValue({data: myNewDataObject}).setOperationFlag({save: true}).
|
Hint: Wrapping the call to `setValue` as follows can be helpful if you want to update a value, like in the value's `data` but do not want to have another save point in the undo history: `change.setOperationFlag({save: false}).setValue({data: myNewDataObject}).setOperationFlag({save: true}).
|
||||||
|
|
||||||
## Current Value Changes
|
## Current Selection Changes
|
||||||
|
|
||||||
These changes act on the `document` based on the current `selection`. They are equivalent to calling the [Document Changes](#document-changes) with the current selection as the `range` argument, but they are there for convenience, since you often want to act with the current selection, as a user would.
|
These changes act on the `document` based on the current `selection`. They are equivalent to calling the [Document Range Changes](#document-range-changes) with the current selection as the `range` argument, but they are there for convenience, since you often want to act with the current selection, as a user would.
|
||||||
|
|
||||||
### `deleteBackward`
|
### `addMark`
|
||||||
|
|
||||||
`deleteBackward(n: Number) => Change`
|
`addMark(mark: Mark) => Change` <br/>
|
||||||
|
`addMark(properties: Object) => Change` <br/>
|
||||||
|
`addMark(type: String) => Change`
|
||||||
|
|
||||||
Delete backward `n` characters at the current cursor. If the selection is expanded, this method is equivalent to a regular [`delete()`](#delete). `n` defaults to `1`.
|
Add a [`mark`](./mark.md) to the characters in the current selection. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type.
|
||||||
|
|
||||||
### `deleteForward`
|
|
||||||
|
|
||||||
`deleteForward(n: Number) => Change`
|
|
||||||
|
|
||||||
Delete forward `n` characters at the current cursor. If the selection is expanded, this method is equivalent to a regular [`delete()`](#delete). `n` defaults to `1`.
|
|
||||||
|
|
||||||
### `delete`
|
### `delete`
|
||||||
|
|
||||||
@@ -129,6 +125,18 @@ Delete everything in the current selection.
|
|||||||
`insertBlock(properties: Object) => Change` <br/>
|
`insertBlock(properties: Object) => Change` <br/>
|
||||||
`insertBlock(type: String) => Change`
|
`insertBlock(type: String) => Change`
|
||||||
|
|
||||||
|
### `deleteBackward`
|
||||||
|
|
||||||
|
`deleteBackward(n: Number) => Change`
|
||||||
|
|
||||||
|
Delete backward `n` characters at the current cursor. If the selection is expanded, this method is equivalent to a regular [`delete()`](#delete). `n` defaults to `1`.
|
||||||
|
|
||||||
|
### `deleteForward`
|
||||||
|
|
||||||
|
`deleteForward(n: Number) => Change`
|
||||||
|
|
||||||
|
Delete forward `n` characters at the current cursor. If the selection is expanded, this method is equivalent to a regular [`delete()`](#delete). `n` defaults to `1`.
|
||||||
|
|
||||||
Insert a new block at the same level as the current block, splitting the current block to make room if it is non-empty. If the selection is expanded, it will be deleted first.
|
Insert a new block at the same level as the current block, splitting the current block to make room if it is non-empty. If the selection is expanded, it will be deleted first.
|
||||||
|
|
||||||
### `insertFragment`
|
### `insertFragment`
|
||||||
@@ -150,14 +158,6 @@ Insert a new inline at the current cursor position, splitting the text to make r
|
|||||||
|
|
||||||
Insert a string of `text` at the current selection. If the selection is expanded, it will be deleted first.
|
Insert a string of `text` at the current selection. If the selection is expanded, it will be deleted first.
|
||||||
|
|
||||||
### `addMark`
|
|
||||||
|
|
||||||
`addMark(mark: Mark) => Change` <br/>
|
|
||||||
`addMark(properties: Object) => Change` <br/>
|
|
||||||
`addMark(type: String) => Change`
|
|
||||||
|
|
||||||
Add a [`mark`](./mark.md) to the characters in the current selection. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type.
|
|
||||||
|
|
||||||
### `setBlocks`
|
### `setBlocks`
|
||||||
|
|
||||||
`setBlocks(properties: Object) => Change` <br/>
|
`setBlocks(properties: Object) => Change` <br/>
|
||||||
@@ -252,41 +252,11 @@ These changes change the current `selection`, without touching the `document`.
|
|||||||
|
|
||||||
Blur the current selection.
|
Blur the current selection.
|
||||||
|
|
||||||
### `collapseTo{Edge}`
|
### `deselect`
|
||||||
|
|
||||||
`collapseTo{Edge}() => Change`
|
`deselect() => Change`
|
||||||
|
|
||||||
Collapse the current selection to its `{Edge}`. Where `{Edge}` is either `Anchor`, `Focus`, `Start` or `End`.
|
Unset the selection.
|
||||||
|
|
||||||
### `collapseTo{Edge}Of`
|
|
||||||
|
|
||||||
`collapseTo{Edge}Of(node: Node) => Change`
|
|
||||||
|
|
||||||
Collapse the current selection to the `{Edge}` of `node`. Where `{Edge}` is either `Start` or `End`.
|
|
||||||
|
|
||||||
### `collapseTo{Edge}Of{Direction}Block`
|
|
||||||
|
|
||||||
`collapseTo{Edge}Of{Direction}Block() => Change`
|
|
||||||
|
|
||||||
Collapse the current selection to the `{Edge}` of the next [`Block`](./block.md) node in `{Direction}`. Where `{Edge}` is either `Start` or `End` and `{Direction}` is either `Next` or `Previous`.
|
|
||||||
|
|
||||||
### `collapseTo{Edge}Of{Direction}Text`
|
|
||||||
|
|
||||||
`collapseTo{Edge}Of{Direction}Text() => Change`
|
|
||||||
|
|
||||||
Collapse the current selection to the `{Edge}` of the next [`Text`](./text.md) node in `{Direction}`. Where `{Edge}` is either `Start` or `End` and `{Direction}` is either `Next` or `Previous`.
|
|
||||||
|
|
||||||
### `extend`
|
|
||||||
|
|
||||||
`extend(n: Number) => Change`
|
|
||||||
|
|
||||||
Extend the current selection's points by `n` characters. `n` can be positive or negative to indicate direction.
|
|
||||||
|
|
||||||
### `extendTo{Edge}Of`
|
|
||||||
|
|
||||||
`extendTo{Edge}Of(node: Node) => Change`
|
|
||||||
|
|
||||||
Extend the current selection to the `{Edge}` of a `node`. Where `{Edge}` is either `Start` or `End`.
|
|
||||||
|
|
||||||
### `flip`
|
### `flip`
|
||||||
|
|
||||||
@@ -300,23 +270,79 @@ Flip the selection.
|
|||||||
|
|
||||||
Focus the current selection.
|
Focus the current selection.
|
||||||
|
|
||||||
### `move`
|
### `move{Point}Backward`
|
||||||
|
|
||||||
`move(n: Number) => Change`
|
`move{Point}Backward(n: Number) => Change`
|
||||||
|
|
||||||
Move the current selection's offsets by `n`.
|
Move the `{Point}` of the selection backward `n` characters. Where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
### `move{Edge}`
|
### `move{Point}Forward`
|
||||||
|
|
||||||
`move{Edge}(n: Number) => Change`
|
`move{Point}Forward(n: Number) => Change`
|
||||||
|
|
||||||
Move the current selection's `{Edge}` offset by `n`. `{Edge}` can be one of `Start`, `End`.
|
Move the `{Point}` of the selection forward `n` characters. Where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
### `moveOffsetsTo`
|
### `move{Point}To`
|
||||||
|
|
||||||
`moveOffsetsTo(anchorOffset: Number, focusOffset: Number) => Change`
|
`moveTo(path: List, offset: Number) => Change`
|
||||||
|
`moveTo(key: String, offset: Number) => Change`
|
||||||
|
`moveTo(offset: Number) => Change`
|
||||||
|
|
||||||
Move the current selection's offsets to a new `anchorOffset` and `focusOffset`.
|
Move the `{Point}` of the selection to a new `path` or `key` and `offset`. Where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
|
### `moveTo{Point}`
|
||||||
|
|
||||||
|
`moveTo{Point}() => Change`
|
||||||
|
|
||||||
|
Collapse the current selection to one of its points. Where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`.
|
||||||
|
|
||||||
|
### `move{Point}To{Edge}OfBlock`
|
||||||
|
|
||||||
|
`move{Point}To{Edge}OfBlock() => Change`
|
||||||
|
|
||||||
|
Move the current selection to the `{Edge}` of the closest block parent. Where `{Edge}` is either `Start` or `End`. And where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
|
### `move{Point}To{Edge}OfDocument`
|
||||||
|
|
||||||
|
`move{Point}To{Edge}OfDocument() => Change`
|
||||||
|
|
||||||
|
Move the current selection to the `{Edge}` of the document. Where `{Edge}` is either `Start` or `End`. And where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
|
### `move{Point}To{Edge}OfInline`
|
||||||
|
|
||||||
|
`move{Point}To{Edge}OfInline() => Change`
|
||||||
|
|
||||||
|
Move the current selection to the `{Edge}` of the closest inline parent. Where `{Edge}` is either `Start` or `End`. And where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
|
### `move{Point}To{Edge}OfNode`
|
||||||
|
|
||||||
|
`move{Point}To{Edge}OfNode(node: Node) => Change`
|
||||||
|
|
||||||
|
Move the current selection to the `{Edge}` of a `node`. Where `{Edge}` is either `Start` or `End`. And where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
|
### `move{Point}To{Edge}OfText`
|
||||||
|
|
||||||
|
`move{Point}To{Edge}OfText() => Change`
|
||||||
|
|
||||||
|
Move the current selection to the `{Edge}` of the current text node. Where `{Edge}` is either `Start` or `End`. And where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
|
### `move{Point}To{Edge}Of{Direction}Block`
|
||||||
|
|
||||||
|
`move{Point}To{Edge}Of{Direction}Block() => Change`
|
||||||
|
|
||||||
|
Move the current selection to the `{Edge}` of the closest block parent. Where `{Edge}` is either `Start` or `End`. And where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
|
### `move{Point}To{Edge}Of{Direction}Inline`
|
||||||
|
|
||||||
|
`move{Point}To{Edge}Of{Direction}Inline() => Change`
|
||||||
|
|
||||||
|
Move the current selection to the `{Edge}` of the closest inline parent. Where `{Edge}` is either `Start` or `End`. And where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
|
### `move{Point}To{Edge}Of{Direction}Text`
|
||||||
|
|
||||||
|
`move{Point}To{Edge}Of{Direction}Text() => Change`
|
||||||
|
|
||||||
|
Move the current selection to the `{Edge}` of the current text node. Where `{Edge}` is either `Start` or `End`. And where `{Point}` is either `Anchor`, `Focus`, `Start` or `End`. You can also omit `{Point}` to move both the anchor and focus points at the same time.
|
||||||
|
|
||||||
### `moveToRangeOf`
|
### `moveToRangeOf`
|
||||||
|
|
||||||
@@ -324,28 +350,36 @@ Move the current selection's offsets to a new `anchorOffset` and `focusOffset`.
|
|||||||
|
|
||||||
Move the current selection's anchor point to the start of a `node` and its focus point to the end of the `node`.
|
Move the current selection's anchor point to the start of a `node` and its focus point to the end of the `node`.
|
||||||
|
|
||||||
|
### `moveToRangeOfDocument`
|
||||||
|
|
||||||
|
`moveToRangeOf() => Change`
|
||||||
|
|
||||||
|
Move the current selection's anchor point to the start of the document and its focus point to the end of the document, selecting everything.
|
||||||
|
|
||||||
### `select`
|
### `select`
|
||||||
|
|
||||||
`select(properties: Range || Object) => Change`
|
`select(properties: Range || Object) => Change`
|
||||||
|
|
||||||
Set the current selection to a range with merged `properties`. The `properties` can either be a [`Range`](./range.md) object or a plain Javascript object of selection properties.
|
Set the current selection to a range with merged `properties`. The `properties` can either be a [`Range`](./range.md) object or a plain Javascript object of selection properties.
|
||||||
|
|
||||||
### `selectAll`
|
## Document Range Changes
|
||||||
|
|
||||||
`selectAll() => Change`
|
|
||||||
|
|
||||||
Select the entire document and focus the selection.
|
|
||||||
|
|
||||||
### `deselect`
|
|
||||||
|
|
||||||
`deselect() => Change`
|
|
||||||
|
|
||||||
Unset the selection.
|
|
||||||
|
|
||||||
## Document Changes
|
|
||||||
|
|
||||||
These changes act on a specific [`Range`](./range.md) of the document.
|
These changes act on a specific [`Range`](./range.md) of the document.
|
||||||
|
|
||||||
|
### `addMarkAtRange`
|
||||||
|
|
||||||
|
`addMarkAtRange(range: Range, mark: Mark) => Change` <br/>
|
||||||
|
`addMarkAtRange(range: Range, properties: Object) => Change` <br/>
|
||||||
|
`addMarkAtRange(range: Range, type: String) => Change`
|
||||||
|
|
||||||
|
Add a [`mark`](./mark.md) to the characters in a `range`. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type.
|
||||||
|
|
||||||
|
### `deleteAtRange`
|
||||||
|
|
||||||
|
`deleteAtRange(range: Range, ) => Change`
|
||||||
|
|
||||||
|
Delete everything in a `range`.
|
||||||
|
|
||||||
### `deleteBackwardAtRange`
|
### `deleteBackwardAtRange`
|
||||||
|
|
||||||
`deleteBackwardAtRange(range: Range, n: Number) => Change`
|
`deleteBackwardAtRange(range: Range, n: Number) => Change`
|
||||||
@@ -358,12 +392,6 @@ Delete backward `n` characters at a `range`. If the `range` is expanded, this me
|
|||||||
|
|
||||||
Delete forward `n` characters at a `range`. If the `range` is expanded, this method is equivalent to a regular [`delete()`](#delete). `n` defaults to `1`.
|
Delete forward `n` characters at a `range`. If the `range` is expanded, this method is equivalent to a regular [`delete()`](#delete). `n` defaults to `1`.
|
||||||
|
|
||||||
### `deleteAtRange`
|
|
||||||
|
|
||||||
`deleteAtRange(range: Range, ) => Change`
|
|
||||||
|
|
||||||
Delete everything in a `range`.
|
|
||||||
|
|
||||||
### `insertBlockAtRange`
|
### `insertBlockAtRange`
|
||||||
|
|
||||||
`insertBlockAtRange(range: Range, block: Block) => Change` <br/>
|
`insertBlockAtRange(range: Range, block: Block) => Change` <br/>
|
||||||
@@ -391,14 +419,6 @@ Insert a new inline at a `range`, splitting the text to make room if it is non-e
|
|||||||
|
|
||||||
Insert a string of `text` at a `range`. If the selection is expanded, it will be deleted first.
|
Insert a string of `text` at a `range`. If the selection is expanded, it will be deleted first.
|
||||||
|
|
||||||
### `addMarkAtRange`
|
|
||||||
|
|
||||||
`addMarkAtRange(range: Range, mark: Mark) => Change` <br/>
|
|
||||||
`addMarkAtRange(range: Range, properties: Object) => Change` <br/>
|
|
||||||
`addMarkAtRange(range: Range, type: String) => Change`
|
|
||||||
|
|
||||||
Add a [`mark`](./mark.md) to the characters in a `range`. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type.
|
|
||||||
|
|
||||||
### `setBlocksAtRange`
|
### `setBlocksAtRange`
|
||||||
|
|
||||||
`setBlocksAtRange(range: Range, properties: Object) => Change` <br/>
|
`setBlocksAtRange(range: Range, properties: Object) => Change` <br/>
|
||||||
@@ -477,118 +497,148 @@ Surround the text in a `range` with `prefix` and `suffix` strings. If the `suffi
|
|||||||
|
|
||||||
## Node Changes
|
## Node Changes
|
||||||
|
|
||||||
These changes are lower-level, and act on a specific node by its `key`. They're often used in your custom components because you'll have access to `props.node`.
|
These changes are lower-level, and act on a specific node by its `key` or `path`. They're often used in your custom components because you'll have access to `props.node`.
|
||||||
|
|
||||||
### `addMarkByKey`
|
### `addMarkByKey/Path`
|
||||||
|
|
||||||
`addMarkByKey(key: String, offset: Number, length: Number, mark: Mark) => Change`
|
`addMarkByKey(key: String, offset: Number, length: Number, mark: Mark) => Change`
|
||||||
|
`addMarkByPath(path: List, offset: Number, length: Number, mark: Mark) => Change`
|
||||||
|
|
||||||
Add a `mark` to `length` characters starting at an `offset` in a [`Node`](./node.md) by its `key`.
|
Add a `mark` to `length` characters starting at an `offset` in a [`Node`](./node.md) by its `key` or `path`.
|
||||||
|
|
||||||
### `insertNodeByKey`
|
### `insertNodeByKey/Path`
|
||||||
|
|
||||||
`insertNodeByKey(key: String, index: Number, node: Node) => Change`
|
`insertNodeByKey(key: String, index: Number, node: Node) => Change`
|
||||||
|
`insertNodeByPath(path: List, index: Number, node: Node) => Change`
|
||||||
|
|
||||||
Insert a `node` at `index` inside a parent [`Node`](./node.md) by its `key`.
|
Insert a `node` at `index` inside a parent [`Node`](./node.md) by its `key` or `path`.
|
||||||
|
|
||||||
### `insertFragmentByKey`
|
### `insertFragmentByKey/Path`
|
||||||
|
|
||||||
`insertFragmentByKey(key: String, index: Number, fragment: Fragment) => Transform`
|
`insertFragmentByKey(key: String, index: Number, fragment: Fragment) => Transform`
|
||||||
|
`insertFragmentByPath(path: list, index: Number, fragment: Fragment) => Transform`
|
||||||
|
|
||||||
Insert a [`Fragment`](./fragment.md) at `index` inside a parent [`Node`](./node.md) by its `key`.
|
Insert a [`Fragment`](./fragment.md) at `index` inside a parent [`Node`](./node.md) by its `key` or `path`.
|
||||||
|
|
||||||
### `insertTextByKey`
|
### `insertTextByKey/Path`
|
||||||
|
|
||||||
`insertTextByKey(key: String, offset: Number, text: String, [marks: Set]) => Change`
|
`insertTextByKey(key: String, offset: Number, text: String, [marks: Set]) => Change`
|
||||||
|
`insertTextByPath(path: List, offset: Number, text: String, [marks: Set]) => Change`
|
||||||
|
|
||||||
Insert `text` at an `offset` in a [`Text Node`](./text.md) by its `key` with optional `marks`.
|
Insert `text` at an `offset` in a [`Text Node`](./text.md) by its `key` with optional `marks`.
|
||||||
|
|
||||||
### `moveNodeByKey`
|
### `mergeNodeByKey/Path`
|
||||||
|
|
||||||
|
`mergeNodeByKey(key: String) => Change`
|
||||||
|
`mergeNodeByPath(path: List) => Change`
|
||||||
|
|
||||||
|
Merge a [`Node`](./node.md) by its `key` or `path` with its previous sibling.
|
||||||
|
|
||||||
|
### `moveNodeByKey/Path`
|
||||||
|
|
||||||
`moveNodeByKey(key: String, newKey: String, newIndex: Number) => Change`
|
`moveNodeByKey(key: String, newKey: String, newIndex: Number) => Change`
|
||||||
|
`moveNodeByPath(path: List, newKey: String, newIndex: Number) => Change`
|
||||||
|
|
||||||
Move a [`Node`](./node.md) by its `key` to a new parent node with its `newKey` and at a `newIndex`.
|
Move a [`Node`](./node.md) by its `key` or `path` to a new parent node with its `newKey` and at a `newIndex`.
|
||||||
|
|
||||||
### `removeMarkByKey`
|
### `removeMarkByKey/Path`
|
||||||
|
|
||||||
`removeMarkByKey(key: String, offset: Number, length: Number, mark: Mark) => Change`
|
`removeMarkByKey(key: String, offset: Number, length: Number, mark: Mark) => Change`
|
||||||
|
`removeMarkByPath(path: List, offset: Number, length: Number, mark: Mark) => Change`
|
||||||
|
|
||||||
Remove a `mark` from `length` characters starting at an `offset` in a [`Node`](./node.md) by its `key`.
|
Remove a `mark` from `length` characters starting at an `offset` in a [`Node`](./node.md) by its `key` or `path`.
|
||||||
|
|
||||||
### `removeNodeByKey`
|
### `removeNodeByKey/Path`
|
||||||
|
|
||||||
`removeNodeByKey(key: String) => Change`
|
`removeNodeByKey(key: String) => Change`
|
||||||
|
`removeNodeByPath(path: List) => Change`
|
||||||
|
|
||||||
Remove a [`Node`](./node.md) from the document by its `key`.
|
Remove a [`Node`](./node.md) from the document by its `key` or `path`.
|
||||||
|
|
||||||
### `replaceNodeByKey`
|
### `replaceNodeByKey/Path`
|
||||||
|
|
||||||
`replaceNodeByKey(key: String, node: Node) => Change`
|
`replaceNodeByKey(key: String, node: Node) => Change`
|
||||||
|
`replaceNodeByPath(path: List, node: Node) => Change`
|
||||||
|
|
||||||
Replace a [`Node`](./node.md) in the document with a new [`Node`](./node.md) by its `key`.
|
Replace a [`Node`](./node.md) in the document with a new [`Node`](./node.md) by its `key` or `path`.
|
||||||
|
|
||||||
### `removeTextByKey`
|
### `removeTextByKey/Path`
|
||||||
|
|
||||||
`removeTextByKey(key: String, offset: Number, length: Number) => Change`
|
`removeTextByKey(key: String, offset: Number, length: Number) => Change`
|
||||||
|
`removeTextByPath(path: List, offset: Number, length: Number) => Change`
|
||||||
|
|
||||||
Remove `length` characters of text starting at an `offset` in a [`Node`](./node.md) by its `key`.
|
Remove `length` characters of text starting at an `offset` in a [`Node`](./node.md) by its `key` or `path`.
|
||||||
|
|
||||||
### `setMarkByKey`
|
### `setMarkByKey/Path`
|
||||||
|
|
||||||
`setMarkByKey(key: String, offset: Number, length: Number, mark: Mark, properties: Object) => Change`
|
`setMarkByKey(key: String, offset: Number, length: Number, mark: Mark, properties: Object) => Change`
|
||||||
|
`setMarkByPath(path: List, offset: Number, length: Number, mark: Mark, properties: Object) => Change`
|
||||||
|
|
||||||
Set a dictionary of `properties` on a [`mark`](./mark.md) on a [`Node`](./node.md) by its `key`.
|
Set a dictionary of `properties` on a [`mark`](./mark.md) on a [`Node`](./node.md) by its `key` or `path`.
|
||||||
|
|
||||||
### `setNodeByKey`
|
### `setNodeByKey/Path`
|
||||||
|
|
||||||
`setNodeByKey(key: String, properties: Object) => Change` <br/>
|
`setNodeByKey(key: String, properties: Object) => Change` <br/>
|
||||||
`setNodeByKey(key: String, type: String) => Change`
|
`setNodeByKey(key: String, type: String) => Change`
|
||||||
|
`setNodeByPath(path: List, properties: Object) => Change` <br/>
|
||||||
|
`setNodeByPath(path: List, type: String) => Change`
|
||||||
|
|
||||||
Set a dictionary of `properties` on a [`Node`](./node.md) by its `key`. For convenience, you can pass a `type` string or `properties` object.
|
Set a dictionary of `properties` on a [`Node`](./node.md) by its `key` or `path`. For convenience, you can pass a `type` string or `properties` object.
|
||||||
|
|
||||||
### `splitNodeByKey`
|
### `splitNodeByKey/Path`
|
||||||
|
|
||||||
`splitNodeByKey(key: String, offset: Number) => Change`
|
`splitNodeByKey(key: String, offset: Number) => Change`
|
||||||
|
`splitNodeByPath(path: List, offset: Number) => Change`
|
||||||
|
|
||||||
Split a node by its `key` at an `offset`.
|
Split a node by its `key` or `path` at an `offset`.
|
||||||
|
|
||||||
### `unwrapInlineByKey`
|
### `unwrapInlineByKey/Path`
|
||||||
|
|
||||||
`unwrapInlineByKey(key: String, properties: Object) => Change` <br/>
|
`unwrapInlineByKey(key: String, properties: Object) => Change` <br/>
|
||||||
`unwrapInlineByKey(key: String, type: String) => Change`
|
`unwrapInlineByKey(key: String, type: String) => Change`
|
||||||
|
`unwrapInlineByPath(path: List, properties: Object) => Change` <br/>
|
||||||
|
`unwrapInlineByPath(path: List, type: String) => Change`
|
||||||
|
|
||||||
Unwrap all inner content of an [`Inline`](./inline.md) node by its `key` that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
Unwrap all inner content of an [`Inline`](./inline.md) node by its `key` or `path` that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
||||||
|
|
||||||
### `unwrapBlockByKey`
|
### `unwrapBlockByKey/Path`
|
||||||
|
|
||||||
`unwrapBlockByKey(key: String, properties: Object) => Change` <br/>
|
`unwrapBlockByKey(key: String, properties: Object) => Change` <br/>
|
||||||
`unwrapBlockByKey(key: String, type: String) => Change`
|
`unwrapBlockByKey(key: String, type: String) => Change`
|
||||||
|
`unwrapBlockByPath(path: List, properties: Object) => Change` <br/>
|
||||||
|
`unwrapBlockByPath(path: List, type: String) => Change`
|
||||||
|
|
||||||
Unwrap all inner content of a [`Block`](./block.md) node by its `key` that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
Unwrap all inner content of a [`Block`](./block.md) node by its `key` or `path` that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
||||||
|
|
||||||
### `unwrapNodeByKey`
|
### `unwrapNodeByKey/Path`
|
||||||
|
|
||||||
`unwrapNodeByKey(key: String) => Change`
|
`unwrapNodeByKey(key: String) => Change`
|
||||||
|
`unwrapNodeByPath(path: List) => Change`
|
||||||
|
|
||||||
Unwrap a single node from its parent. If the node is surrounded with siblings, its parent will be split. If the node is the only child, the parent is removed, and simply replaced by the node itself. Cannot unwrap a root node.
|
Unwrap a single node from its parent. If the node is surrounded with siblings, its parent will be split. If the node is the only child, the parent is removed, and simply replaced by the node itself. Cannot unwrap a root node.
|
||||||
|
|
||||||
### `wrapBlockByKey`
|
### `wrapBlockByKey/Path`
|
||||||
|
|
||||||
`wrapBlockByKey(key: String, properties: Object) => Change` <br/>
|
`wrapBlockByKey(key: String, properties: Object) => Change` <br/>
|
||||||
`wrapBlockByKey(key: String, type: String) => Change`
|
`wrapBlockByKey(key: String, type: String) => Change`
|
||||||
|
`wrapBlockByPath(path: List, properties: Object) => Change` <br/>
|
||||||
|
`wrapBlockByPath(path: List, type: String) => Change`
|
||||||
|
|
||||||
Wrap the given node in a [`Block`](./block.md) node that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
Wrap the given node in a [`Block`](./block.md) node that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
||||||
|
|
||||||
### `wrapInlineByKey`
|
### `wrapInlineByKey/Path`
|
||||||
|
|
||||||
`wrapInlineByKey(key: String, properties: Object) => Change` <br/>
|
`wrapInlineByKey(key: String, properties: Object) => Change` <br/>
|
||||||
`wrapInlineByKey(key: String, type: String) => Change`
|
`wrapInlineByKey(key: String, type: String) => Change`
|
||||||
|
`wrapInlineByPath(path: List, properties: Object) => Change` <br/>
|
||||||
|
`wrapInlineByPath(path: List, type: String) => Change`
|
||||||
|
|
||||||
Wrap the given node in a [`Inline`](./inline.md) node that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
Wrap the given node in a [`Inline`](./inline.md) node that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
||||||
|
|
||||||
### `wrapNodeByKey`
|
### `wrapNodeByKey/Path`
|
||||||
|
|
||||||
`wraNodeByKey(key: String, parent: Node) => Change` <br/>
|
`wraNodeByKey(key: String, parent: Node) => Change` <br/>
|
||||||
|
`wraNodeByPath(path: List, parent: Node) => Change` <br/>
|
||||||
|
|
||||||
Wrap the node with the specified key with the parent [`Node`](./node.md). This will clear all children of the parent.
|
Wrap the node with the specified key with the parent [`Node`](./node.md). This will clear all children of the parent.
|
||||||
|
|
||||||
@@ -612,4 +662,4 @@ Move backward one step in the history.
|
|||||||
|
|
||||||
`snapshotSelection() => Change`
|
`snapshotSelection() => Change`
|
||||||
|
|
||||||
Snapshot `value.selection` for `undo` purposes, useful with delete operations like `removeNodeByKey(focusBlock.key).undo()`
|
Snapshot `value.selection` for `undo` purposes, useful with delete operations like `change.removeNodeByKey(focusBlock.key).undo()`.
|
||||||
|
@@ -222,24 +222,6 @@ Changes.insertText = (change, text, marks) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Split the block node at the current selection, to optional `depth`.
|
|
||||||
*
|
|
||||||
* @param {Change} change
|
|
||||||
* @param {Number} depth (optional)
|
|
||||||
*/
|
|
||||||
|
|
||||||
Changes.splitBlock = (change, depth = 1) => {
|
|
||||||
const { value } = change
|
|
||||||
const { selection, document } = value
|
|
||||||
const marks = selection.marks || document.getInsertMarksAtRange(selection)
|
|
||||||
change.splitBlockAtRange(selection, depth).moveToEnd()
|
|
||||||
|
|
||||||
if (marks && marks.size !== 0) {
|
|
||||||
change.select({ marks })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a `mark` from the characters in the current selection.
|
* Remove a `mark` from the characters in the current selection.
|
||||||
*
|
*
|
||||||
@@ -278,6 +260,24 @@ Changes.replaceMark = (change, oldMark, newMark) => {
|
|||||||
change.addMark(newMark)
|
change.addMark(newMark)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split the block node at the current selection, to optional `depth`.
|
||||||
|
*
|
||||||
|
* @param {Change} change
|
||||||
|
* @param {Number} depth (optional)
|
||||||
|
*/
|
||||||
|
|
||||||
|
Changes.splitBlock = (change, depth = 1) => {
|
||||||
|
const { value } = change
|
||||||
|
const { selection, document } = value
|
||||||
|
const marks = selection.marks || document.getInsertMarksAtRange(selection)
|
||||||
|
change.splitBlockAtRange(selection, depth).moveToEnd()
|
||||||
|
|
||||||
|
if (marks && marks.size !== 0) {
|
||||||
|
change.select({ marks })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add or remove a `mark` from the characters in the current selection,
|
* Add or remove a `mark` from the characters in the current selection,
|
||||||
* depending on whether it's already there.
|
* depending on whether it's already there.
|
||||||
|
@@ -296,77 +296,6 @@ Changes.removeNodeByPath = (change, path, options) => {
|
|||||||
change.normalizeParentByPath(path, options)
|
change.normalizeParentByPath(path, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert `text` at `offset` in node by `path`.
|
|
||||||
*
|
|
||||||
* @param {Change} change
|
|
||||||
* @param {Array} path
|
|
||||||
* @param {String} text
|
|
||||||
* @param {Set<Mark>} marks (optional)
|
|
||||||
* @param {Object} options
|
|
||||||
*/
|
|
||||||
|
|
||||||
Changes.setTextByPath = (change, path, text, marks, options) => {
|
|
||||||
const { value } = change
|
|
||||||
const { document } = value
|
|
||||||
const node = document.assertNode(path)
|
|
||||||
const end = node.text.length
|
|
||||||
change.replaceTextByPath(path, 0, end, text, marks, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace A Length of Text with another string or text
|
|
||||||
* @param {Change} change
|
|
||||||
* @param {String} key
|
|
||||||
* @param {Number} offset
|
|
||||||
* @param {Number} length
|
|
||||||
* @param {string} text
|
|
||||||
* @param {Set<Mark>} marks (optional)
|
|
||||||
* @param {Object} options
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
Changes.replaceTextByPath = (
|
|
||||||
change,
|
|
||||||
path,
|
|
||||||
offset,
|
|
||||||
length,
|
|
||||||
text,
|
|
||||||
marks,
|
|
||||||
options
|
|
||||||
) => {
|
|
||||||
const { document } = change.value
|
|
||||||
const node = document.assertNode(path)
|
|
||||||
|
|
||||||
if (length + offset > node.text.length) {
|
|
||||||
length = node.text.length - offset
|
|
||||||
}
|
|
||||||
|
|
||||||
const range = document.createRange({
|
|
||||||
anchor: { path, offset },
|
|
||||||
focus: { path, offset: offset + length },
|
|
||||||
})
|
|
||||||
|
|
||||||
let activeMarks = document.getActiveMarksAtRange(range)
|
|
||||||
|
|
||||||
change.removeTextByPath(path, offset, length, { normalize: false })
|
|
||||||
|
|
||||||
if (!marks) {
|
|
||||||
// Do not use mark at index when marks and activeMarks are both empty
|
|
||||||
marks = activeMarks ? activeMarks : []
|
|
||||||
} else if (activeMarks) {
|
|
||||||
// Do not use `has` because we may want to reset marks like font-size with
|
|
||||||
// an updated data;
|
|
||||||
activeMarks = activeMarks.filter(
|
|
||||||
activeMark => !marks.find(m => activeMark.type === m.type)
|
|
||||||
)
|
|
||||||
|
|
||||||
marks = activeMarks.merge(marks)
|
|
||||||
}
|
|
||||||
|
|
||||||
change.insertTextByPath(path, offset, text, marks, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove text at `offset` and `length` in node by `path`.
|
* Remove text at `offset` and `length` in node by `path`.
|
||||||
*
|
*
|
||||||
@@ -438,6 +367,59 @@ Changes.replaceNodeByPath = (change, path, newNode, options) => {
|
|||||||
change.normalizeParentByPath(path, options)
|
change.normalizeParentByPath(path, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace A Length of Text with another string or text
|
||||||
|
* @param {Change} change
|
||||||
|
* @param {String} key
|
||||||
|
* @param {Number} offset
|
||||||
|
* @param {Number} length
|
||||||
|
* @param {string} text
|
||||||
|
* @param {Set<Mark>} marks (optional)
|
||||||
|
* @param {Object} options
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
Changes.replaceTextByPath = (
|
||||||
|
change,
|
||||||
|
path,
|
||||||
|
offset,
|
||||||
|
length,
|
||||||
|
text,
|
||||||
|
marks,
|
||||||
|
options
|
||||||
|
) => {
|
||||||
|
const { document } = change.value
|
||||||
|
const node = document.assertNode(path)
|
||||||
|
|
||||||
|
if (length + offset > node.text.length) {
|
||||||
|
length = node.text.length - offset
|
||||||
|
}
|
||||||
|
|
||||||
|
const range = document.createRange({
|
||||||
|
anchor: { path, offset },
|
||||||
|
focus: { path, offset: offset + length },
|
||||||
|
})
|
||||||
|
|
||||||
|
let activeMarks = document.getActiveMarksAtRange(range)
|
||||||
|
|
||||||
|
change.removeTextByPath(path, offset, length, { normalize: false })
|
||||||
|
|
||||||
|
if (!marks) {
|
||||||
|
// Do not use mark at index when marks and activeMarks are both empty
|
||||||
|
marks = activeMarks ? activeMarks : []
|
||||||
|
} else if (activeMarks) {
|
||||||
|
// Do not use `has` because we may want to reset marks like font-size with
|
||||||
|
// an updated data;
|
||||||
|
activeMarks = activeMarks.filter(
|
||||||
|
activeMark => !marks.find(m => activeMark.type === m.type)
|
||||||
|
)
|
||||||
|
|
||||||
|
marks = activeMarks.merge(marks)
|
||||||
|
}
|
||||||
|
|
||||||
|
change.insertTextByPath(path, offset, text, marks, options)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set `properties` on mark on text at `offset` and `length` in node by `path`.
|
* Set `properties` on mark on text at `offset` and `length` in node by `path`.
|
||||||
*
|
*
|
||||||
@@ -501,6 +483,24 @@ Changes.setNodeByPath = (change, path, properties, options) => {
|
|||||||
change.normalizeNodeByPath(path, options)
|
change.normalizeNodeByPath(path, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert `text` at `offset` in node by `path`.
|
||||||
|
*
|
||||||
|
* @param {Change} change
|
||||||
|
* @param {Array} path
|
||||||
|
* @param {String} text
|
||||||
|
* @param {Set<Mark>} marks (optional)
|
||||||
|
* @param {Object} options
|
||||||
|
*/
|
||||||
|
|
||||||
|
Changes.setTextByPath = (change, path, text, marks, options) => {
|
||||||
|
const { value } = change
|
||||||
|
const { document } = value
|
||||||
|
const node = document.assertNode(path)
|
||||||
|
const end = node.text.length
|
||||||
|
change.replaceTextByPath(path, 0, end, text, marks, options)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split a node by `path` at `position`.
|
* Split a node by `path` at `position`.
|
||||||
*
|
*
|
||||||
|
@@ -44,6 +44,10 @@ Changes.moveAnchorToEndOfInline = change => {
|
|||||||
change.call(pointEdgeObject, 'anchor', 'end', 'inline')
|
change.call(pointEdgeObject, 'anchor', 'end', 'inline')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Changes.moveAnchorToEndOfDocument = change => {
|
||||||
|
change.moveAnchorToEndOfNode(change.value.document).moveToAnchor()
|
||||||
|
}
|
||||||
|
|
||||||
Changes.moveAnchorToEndOfNextBlock = change => {
|
Changes.moveAnchorToEndOfNextBlock = change => {
|
||||||
change.call(pointEdgeSideObject, 'anchor', 'end', 'previous', 'block')
|
change.call(pointEdgeSideObject, 'anchor', 'end', 'previous', 'block')
|
||||||
}
|
}
|
||||||
@@ -80,6 +84,10 @@ Changes.moveAnchorToStartOfBlock = change => {
|
|||||||
change.call(pointEdgeObject, 'anchor', 'start', 'block')
|
change.call(pointEdgeObject, 'anchor', 'start', 'block')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Changes.moveAnchorToStartOfDocument = change => {
|
||||||
|
change.moveAnchorToStartOfNode(change.value.document).moveToAnchor()
|
||||||
|
}
|
||||||
|
|
||||||
Changes.moveAnchorToStartOfInline = change => {
|
Changes.moveAnchorToStartOfInline = change => {
|
||||||
change.call(pointEdgeObject, 'anchor', 'start', 'inline')
|
change.call(pointEdgeObject, 'anchor', 'start', 'inline')
|
||||||
}
|
}
|
||||||
@@ -136,6 +144,10 @@ Changes.moveEndToEndOfBlock = change => {
|
|||||||
change.call(pointEdgeObject, 'end', 'end', 'block')
|
change.call(pointEdgeObject, 'end', 'end', 'block')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Changes.moveEndToEndOfDocument = change => {
|
||||||
|
change.moveEndToEndOfNode(change.value.document).moveToEnd()
|
||||||
|
}
|
||||||
|
|
||||||
Changes.moveEndToEndOfInline = change => {
|
Changes.moveEndToEndOfInline = change => {
|
||||||
change.call(pointEdgeObject, 'end', 'end', 'inline')
|
change.call(pointEdgeObject, 'end', 'end', 'inline')
|
||||||
}
|
}
|
||||||
@@ -176,6 +188,10 @@ Changes.moveEndToStartOfBlock = change => {
|
|||||||
change.call(pointEdgeObject, 'end', 'start', 'block')
|
change.call(pointEdgeObject, 'end', 'start', 'block')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Changes.moveEndToStartOfDocument = change => {
|
||||||
|
change.moveEndToStartOfNode(change.value.document).moveToEnd()
|
||||||
|
}
|
||||||
|
|
||||||
Changes.moveEndToStartOfInline = change => {
|
Changes.moveEndToStartOfInline = change => {
|
||||||
change.call(pointEdgeObject, 'end', 'start', 'inline')
|
change.call(pointEdgeObject, 'end', 'start', 'inline')
|
||||||
}
|
}
|
||||||
@@ -228,6 +244,10 @@ Changes.moveFocusToEndOfBlock = change => {
|
|||||||
change.call(pointEdgeObject, 'focus', 'end', 'block')
|
change.call(pointEdgeObject, 'focus', 'end', 'block')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Changes.moveFocusToEndOfDocument = change => {
|
||||||
|
change.moveFocusToEndOfNode(change.value.document).moveToFocus()
|
||||||
|
}
|
||||||
|
|
||||||
Changes.moveFocusToEndOfInline = change => {
|
Changes.moveFocusToEndOfInline = change => {
|
||||||
change.call(pointEdgeObject, 'focus', 'end', 'inline')
|
change.call(pointEdgeObject, 'focus', 'end', 'inline')
|
||||||
}
|
}
|
||||||
@@ -268,6 +288,10 @@ Changes.moveFocusToStartOfBlock = change => {
|
|||||||
change.call(pointEdgeObject, 'focus', 'start', 'block')
|
change.call(pointEdgeObject, 'focus', 'start', 'block')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Changes.moveFocusToStartOfDocument = change => {
|
||||||
|
change.moveFocusToStartOfNode(change.value.document).moveToFocus()
|
||||||
|
}
|
||||||
|
|
||||||
Changes.moveFocusToStartOfInline = change => {
|
Changes.moveFocusToStartOfInline = change => {
|
||||||
change.call(pointEdgeObject, 'focus', 'start', 'inline')
|
change.call(pointEdgeObject, 'focus', 'start', 'inline')
|
||||||
}
|
}
|
||||||
@@ -324,6 +348,10 @@ Changes.moveStartToEndOfBlock = change => {
|
|||||||
change.call(pointEdgeObject, 'start', 'end', 'block')
|
change.call(pointEdgeObject, 'start', 'end', 'block')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Changes.moveStartToEndOfDocument = change => {
|
||||||
|
change.moveStartToEndOfNode(change.value.document).moveToStart()
|
||||||
|
}
|
||||||
|
|
||||||
Changes.moveStartToEndOfInline = change => {
|
Changes.moveStartToEndOfInline = change => {
|
||||||
change.call(pointEdgeObject, 'start', 'end', 'inline')
|
change.call(pointEdgeObject, 'start', 'end', 'inline')
|
||||||
}
|
}
|
||||||
@@ -364,6 +392,10 @@ Changes.moveStartToStartOfBlock = change => {
|
|||||||
change.call(pointEdgeObject, 'start', 'start', 'block')
|
change.call(pointEdgeObject, 'start', 'start', 'block')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Changes.moveStartToStartOfDocument = change => {
|
||||||
|
change.moveStartToStartOfNode(change.value.document).moveToStart()
|
||||||
|
}
|
||||||
|
|
||||||
Changes.moveStartToStartOfInline = change => {
|
Changes.moveStartToStartOfInline = change => {
|
||||||
change.call(pointEdgeObject, 'start', 'start', 'inline')
|
change.call(pointEdgeObject, 'start', 'start', 'inline')
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user