mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-09 14:40:41 +02:00
Rename Range
to Leaf
, and Selection
to Range
(#1231)
* rename Range to Leaf * rename Selection to Range * add findDOMRange, findNode, findRange helpers * refactor to remove findDropPoint util * revert findDOMNode to throwing errors * export new helpers, fix linter * update docs * update examples
This commit is contained in:
@@ -29,8 +29,8 @@
|
||||
- [Inline](./reference/slate/inline.md)
|
||||
- [Mark](./reference//slate/mark.md)
|
||||
- [Node](./reference/slate/node.md)
|
||||
- [Range](./reference/slate/range.md)
|
||||
- [Schema](./reference/slate/schema.md)
|
||||
- [Selection](./reference/slate/selection.md)
|
||||
- [State](./reference/slate/state.md)
|
||||
- [Text](./reference/slate/text.md)
|
||||
- [setKeyGenerator](./reference/slate/utils.md)
|
||||
|
@@ -31,4 +31,4 @@ Note that even though the node is "void", it will still have an empty text node
|
||||
|
||||
One constraint of Slate documents is that the leaf nodes are always `Text` nodes. No `Block` or `Inline` node will ever have no children. It will always have at least an empty text node. (However, you can _render_ text-less nodes, see the [Void Nodes](#void-nodes) section above!)
|
||||
|
||||
This constraint means that [`Selections`](../reference/slate/selection.md) can always refer to text nodes, and many text-node-level operations are always "safe" regardless of the tree's structure.
|
||||
This constraint means that [`Ranges`](../reference/slate/range.md) can always refer to text nodes, and many text-node-level operations are always "safe" regardless of the tree's structure.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
|
||||
# The Selection Model
|
||||
|
||||
Slate keeps track of the user's selection in the editor in an immutable data store called a [`Selection`](../reference/slate/selection.md). By doing this, it lets Slate manipulate the selection with changes, but still update it in the DOM on `render`.
|
||||
Slate keeps track of the user's selection in the editor in an immutable data store called a [`Range`](../reference/slate/range.md). By doing this, it lets Slate manipulate the selection with changes, but still update it in the DOM on `render`.
|
||||
|
||||
|
||||
### Always References Text
|
||||
|
@@ -70,6 +70,14 @@ Ensure that a value is a Slate `Inline`.
|
||||
|
||||
Ensure that a value is an immutable `List` of Slate [`Inline`](../slate/inline.md) objects.
|
||||
|
||||
### `leaf`
|
||||
|
||||
Ensure that a value is a Slate `Leaf`.
|
||||
|
||||
### `leaves`
|
||||
|
||||
Ensure that a value is an immutable `List` of Slate [`Leaf`](../slate/leaf.md) objects.
|
||||
|
||||
### `mark`
|
||||
|
||||
Ensure that a value is a Slate `Mark`.
|
||||
@@ -98,10 +106,6 @@ Ensure that a value is an immutable `List` of Slate [`Range`](../slate/range.md)
|
||||
|
||||
Ensure that a value is a Slate `Schema`.
|
||||
|
||||
### `selection`
|
||||
|
||||
Ensure that a value is a Slate `Selection`.
|
||||
|
||||
### `stack`
|
||||
|
||||
Ensure that a value is a Slate `Stack`.
|
||||
|
@@ -85,25 +85,25 @@ This handler is equivalent to the `onCopy` handler. If no other plugin handles t
|
||||
|
||||
This handler is called when the user drops content into the `contenteditable` element. The event is already prevented by default, so you must define a state change to have any affect occur.
|
||||
|
||||
The `data` object is a convenience object created to standardize the drop metadata across browsers. Every data object has a `type` property, which can be one of `text`, `html` or `files`, and a `target` property which is a [`Selection`](../slate/selection.md) indicating where the drop occurred. Depending on the type, its structure will be:
|
||||
The `data` object is a convenience object created to standardize the drop metadata across browsers. Every data object has a `type` property, which can be one of `text`, `html` or `files`, and a `target` property which is a [`Range`](../slate/range.md) indicating where the drop occurred. Depending on the type, its structure will be:
|
||||
|
||||
```js
|
||||
{
|
||||
type: 'text',
|
||||
target: Selection,
|
||||
target: Range,
|
||||
text: String
|
||||
}
|
||||
|
||||
{
|
||||
type: 'html',
|
||||
target: Selection,
|
||||
target: Range,
|
||||
text: String,
|
||||
html: String
|
||||
}
|
||||
|
||||
{
|
||||
type: 'files',
|
||||
target: Selection,
|
||||
target: Range,
|
||||
files: FileList
|
||||
}
|
||||
```
|
||||
@@ -180,7 +180,7 @@ If no other plugin handles this event, it will be handled by the [Core plugin](.
|
||||
|
||||
This handler is called whenever the native DOM selection changes.
|
||||
|
||||
The `data` object contains a [`Selection`](../slate/selection.md) object representing the new selection.
|
||||
The `data` object contains a [`Range`](../slate/range.md) object representing the new selection.
|
||||
|
||||
If no other plugin handles this event, it will be handled by the [Core plugin](./core.md).
|
||||
|
||||
|
@@ -5,12 +5,10 @@
|
||||
import { Change } from 'slate'
|
||||
```
|
||||
|
||||
A change allows you to define a series of changes you'd like to make to the current [`Document`](./document.md) or [`Selection`](./selection.md) in a [`State`](./state.md).
|
||||
A change allows you to define a series of changes you'd like to make to the current [`State`](./state.md).
|
||||
|
||||
All changes are performed through `Change` objects, so that a history of changes can be preserved for use in undo/redo operations, and to make collaborative editing possible.
|
||||
|
||||
Change methods can either operate on the [`Document`](./document.md), the [`Selection`](./selection.md), or both at once.
|
||||
|
||||
|
||||
## Properties
|
||||
|
||||
@@ -221,9 +219,9 @@ 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`.
|
||||
|
||||
### `select`
|
||||
`select(properties: Selection || Object) => Change`
|
||||
`select(properties: Range || Object) => Change`
|
||||
|
||||
Set the current selection to a selection with merged `properties`. The `properties` can either be a [`Selection`](./selection.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`
|
||||
`selectAll() => Change`
|
||||
@@ -331,112 +329,112 @@ Wrap the given node in a [`Inline`](./inline.md) node that match `properties`. F
|
||||
## Document Changes
|
||||
|
||||
### `deleteBackwardAtRange`
|
||||
`deleteBackwardAtRange(range: Selection, n: Number) => Change`
|
||||
`deleteBackwardAtRange(range: Range, n: Number) => Change`
|
||||
|
||||
Delete backward `n` characters at a `range`. If the `range` is expanded, this method is equivalent to a regular [`delete()`](#delete). `n` defaults to `1`.
|
||||
|
||||
### `deleteForwardAtRange`
|
||||
`deleteForwardAtRange(range: Selection, n: Number) => Change`
|
||||
`deleteForwardAtRange(range: Range, n: Number) => Change`
|
||||
|
||||
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: Selection, ) => Change`
|
||||
`deleteAtRange(range: Range, ) => Change`
|
||||
|
||||
Delete everything in a `range`.
|
||||
|
||||
### `insertBlockAtRange`
|
||||
`insertBlockAtRange(range: Selection, block: Block) => Change` <br/>
|
||||
`insertBlockAtRange(range: Selection, properties: Object) => Change` <br/>
|
||||
`insertBlockAtRange(range: Selection, type: String) => Change`
|
||||
`insertBlockAtRange(range: Range, block: Block) => Change` <br/>
|
||||
`insertBlockAtRange(range: Range, properties: Object) => Change` <br/>
|
||||
`insertBlockAtRange(range: Range, type: String) => Change`
|
||||
|
||||
Insert a new block at the same level as the leaf block at a `range`, splitting the current block to make room if it is non-empty. If the selection is expanded, it will be deleted first.
|
||||
|
||||
### `insertFragmentAtRange`
|
||||
`insertFragmentAtRange(range: Selection, fragment: Document) => Change`
|
||||
`insertFragmentAtRange(range: Range, fragment: Document) => Change`
|
||||
|
||||
Insert a [`fragment`](./document.md) at a `range`. If the selection is expanded, it will be deleted first.
|
||||
|
||||
### `insertInlineAtRange`
|
||||
`insertInlineAtRange(range: Selection, inline: Inline) => Change` <br/>
|
||||
`insertInlineAtRange(range: Selection, properties: Object) => Change`
|
||||
`insertInlineAtRange(range: Range, inline: Inline) => Change` <br/>
|
||||
`insertInlineAtRange(range: Range, properties: Object) => Change`
|
||||
|
||||
Insert a new inline at a `range`, splitting the text to make room if it is non-empty. If the selection is expanded, it will be deleted first.
|
||||
|
||||
### `insertTextAtRange`
|
||||
`insertTextAtRange(range: Selection, text: String) => Change`
|
||||
`insertTextAtRange(range: Range, text: String) => Change`
|
||||
|
||||
Insert a string of `text` at a `range`. If the selection is expanded, it will be deleted first.
|
||||
|
||||
### `addMarkAtRange`
|
||||
`addMarkAtRange(range: Selection, mark: Mark) => Change` <br/>
|
||||
`addMarkAtRange(range: Selection, properties: Object) => Change` <br/>
|
||||
`addMarkAtRange(range: Selection, type: String) => Change`
|
||||
`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.
|
||||
|
||||
### `setBlockAtRange`
|
||||
`setBlockAtRange(range: Selection, properties: Object) => Change` <br/>
|
||||
`setBlock(range: Selection, type: String) => Change`
|
||||
`setBlockAtRange(range: Range, properties: Object) => Change` <br/>
|
||||
`setBlock(range: Range, type: String) => Change`
|
||||
|
||||
Set the `properties` of the [`Block`](./block.md) in a `range`. For convenience, you can pass a `type` string to set the blocks's type only.
|
||||
|
||||
### `setInlineAtRange`
|
||||
`setInlineAtRange(range: Selection, properties: Object) => Change` <br/>
|
||||
`setInline(range: Selection, type: String) => Change`
|
||||
`setInlineAtRange(range: Range, properties: Object) => Change` <br/>
|
||||
`setInline(range: Range, type: String) => Change`
|
||||
|
||||
Set the `properties` of the [`Inline`](./inline.md) nodes in a `range`. For convenience, you can pass a `type` string to set the inline's type only.
|
||||
|
||||
### `splitBlockAtRange`
|
||||
`splitBlockAtRange(range: Selection, depth: Number) => Change`
|
||||
`splitBlockAtRange(range: Range, depth: Number) => Change`
|
||||
|
||||
Split the [`Block`](./block.md) in a `range` by `depth` levels. If the selection is expanded, it will be deleted first. `depth` defaults to `1`.
|
||||
|
||||
### `splitInlineAtRange`
|
||||
`splitInlineAtRange(range: Selection, depth: Number) => Change`
|
||||
`splitInlineAtRange(range: Range, depth: Number) => Change`
|
||||
|
||||
Split the [`Inline`](./inline.md) node in a `range` by `depth` levels. If the selection is expanded, it will be deleted first. `depth` defaults to `Infinity`.
|
||||
|
||||
### `removeMarkAtRange`
|
||||
`removeMarkAtRange(range: Selection, mark: Mark) => Change` <br/>
|
||||
`removeMarkAtRange(range: Selection, properties: Object) => Change` <br/>
|
||||
`removeMarkAtRange(range: Selection, type: String) => Change`
|
||||
`removeMarkAtRange(range: Range, mark: Mark) => Change` <br/>
|
||||
`removeMarkAtRange(range: Range, properties: Object) => Change` <br/>
|
||||
`removeMarkAtRange(range: Range, type: String) => Change`
|
||||
|
||||
Remove a [`mark`](./mark.md) from 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.
|
||||
|
||||
### `toggleMarkAtRange`
|
||||
`toggleMarkAtRange(range: Selection, mark: Mark) => Change` <br/>
|
||||
`toggleMarkAtRange(range: Selection, properties: Object) => Change` <br/>
|
||||
`toggleMarkAtRange(range: Selection, type: String) => Change`
|
||||
`toggleMarkAtRange(range: Range, mark: Mark) => Change` <br/>
|
||||
`toggleMarkAtRange(range: Range, properties: Object) => Change` <br/>
|
||||
`toggleMarkAtRange(range: Range, type: String) => Change`
|
||||
|
||||
Add or remove a [`mark`](./mark.md) from the characters in a `range`, depending on whether any of them already have the mark. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type.
|
||||
|
||||
### `unwrapBlockAtRange`
|
||||
`unwrapBlockAtRange(range: Selection, properties: Object) => Change` <br/>
|
||||
`unwrapBlockAtRange(range: Selection, type: String) => Change`
|
||||
`unwrapBlockAtRange(range: Range, properties: Object) => Change` <br/>
|
||||
`unwrapBlockAtRange(range: Range, type: String) => Change`
|
||||
|
||||
Unwrap all [`Block`](./block.md) nodes in a `range` that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
||||
|
||||
### `unwrapInlineAtRange`
|
||||
`unwrapInlineAtRange(range: Selection, properties: Object) => Change` <br/>
|
||||
`unwrapInlineAtRange(range: Selection, type: String) => Change`
|
||||
`unwrapInlineAtRange(range: Range, properties: Object) => Change` <br/>
|
||||
`unwrapInlineAtRange(range: Range, type: String) => Change`
|
||||
|
||||
Unwrap all [`Inline`](./inline.md) nodes in a `range` that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
||||
|
||||
### `wrapBlockAtRange`
|
||||
`wrapBlockAtRange(range: Selection, properties: Object) => Change` <br/>
|
||||
`wrapBlockAtRange(range: Selection, type: String) => Change`
|
||||
`wrapBlockAtRange(range: Range, properties: Object) => Change` <br/>
|
||||
`wrapBlockAtRange(range: Range, type: String) => Change`
|
||||
|
||||
Wrap the [`Block`](./block.md) nodes in a `range` with a new [`Block`](./block.md) node with `properties`. For convenience, you can pass a `type` string or `properties` object.
|
||||
|
||||
### `wrapInlineAtRange`
|
||||
`wrapInlineAtRange(range: Selection, properties: Object) => Change` <br/>
|
||||
`wrapInlineAtRange(range: Selection, type: String) => Change`
|
||||
`wrapInlineAtRange(range: Range, properties: Object) => Change` <br/>
|
||||
`wrapInlineAtRange(range: Range, type: String) => Change`
|
||||
|
||||
Wrap the [`Inline`](./inline.md) nodes in a `range` with a new [`Inline`](./inline.md) node with `properties`. For convenience, you can pass a `type` string or `properties` object.
|
||||
|
||||
### `wrapTextAtRange`
|
||||
`wrapTextAtRange(range: Selection, prefix: String, [suffix: String]) => Change`
|
||||
`wrapTextAtRange(range: Range, prefix: String, [suffix: String]) => Change`
|
||||
|
||||
Surround the text in a `range` with `prefix` and `suffix` strings. If the `suffix` is ommitted, the `prefix` will be used instead.
|
||||
|
||||
|
@@ -47,7 +47,7 @@ Deeply filter the descendant nodes of a node by `iterator`.
|
||||
Deeply find a descendant node by `iterator`.
|
||||
|
||||
### `getBlocksAtRange`
|
||||
`getBlocksAtRange(range: Selection) => List`
|
||||
`getBlocksAtRange(range: Range) => List`
|
||||
|
||||
Get all of the bottom-most [`Block`](./block.md) nodes in a `range`.
|
||||
|
||||
@@ -57,7 +57,7 @@ Get all of the bottom-most [`Block`](./block.md) nodes in a `range`.
|
||||
Get all of the bottom-most [`Block`](./block.md) node descendants.
|
||||
|
||||
### `getCharactersAtRange`
|
||||
`getCharactersAtRange(range: Selection) => List`
|
||||
`getCharactersAtRange(range: Range) => List`
|
||||
|
||||
Get a list of all of the [`Characters`](./character.md) in a `range`.
|
||||
|
||||
@@ -97,7 +97,7 @@ Get a descendant node by `key`.
|
||||
Get the first child text node inside a node.
|
||||
|
||||
### `getFragmentAtRange`
|
||||
`getFragmentAtRange(range: Selection) => Document`
|
||||
`getFragmentAtRange(range: Range) => Document`
|
||||
|
||||
Get a document fragment of the nodes in a `range`.
|
||||
|
||||
@@ -127,7 +127,7 @@ Get the furthest inline parent of a node by `key`.
|
||||
Get the furthest ancestor of a node by `key` that has only one child.
|
||||
|
||||
### `getInlinesAtRange`
|
||||
`getInlinesAtRange(range: Selection) => List`
|
||||
`getInlinesAtRange(range: Range) => List`
|
||||
|
||||
Get all of the top-most [`Inline`](./inline.md) nodes in a `range`.
|
||||
|
||||
@@ -137,7 +137,7 @@ Get all of the top-most [`Inline`](./inline.md) nodes in a `range`.
|
||||
Get the last child text node inside a node.
|
||||
|
||||
### `getMarksAtRange`
|
||||
`getMarksAtRange(range: Selection) => Set`
|
||||
`getMarksAtRange(range: Range) => Set`
|
||||
|
||||
Get a set of all of the marks in a `range`.
|
||||
|
||||
@@ -182,7 +182,7 @@ Get the previous [`Text`](./text.md) node before a descendant by `key`.
|
||||
Get the [`Text`](./text.md) node at an `offset`.
|
||||
|
||||
### `getTextsAtRange`
|
||||
`getTextsAtRange(range: Selection) => List`
|
||||
`getTextsAtRange(range: Range) => List`
|
||||
|
||||
Get all of the [`Text`](./text.md) nodes in a `range`.
|
||||
|
||||
|
@@ -103,7 +103,7 @@ Slate schemas are built up of a set of rules. Each of the properties will add ce
|
||||
The `match` property is the only required property of a rule. It determines which objects the rule applies to.
|
||||
|
||||
### `decorate`
|
||||
`Function decorate(node: Node) => List<Selection>|Array<Object>`
|
||||
`Function decorate(node: Node) => List<Range>|Array<Object>`
|
||||
|
||||
```js
|
||||
{
|
||||
@@ -121,7 +121,7 @@ The `match` property is the only required property of a rule. It determines whic
|
||||
}
|
||||
```
|
||||
|
||||
The `decorate` property allows you define a function that will apply extra marks to ranges of text inside a node. It is called with a [`Node`](./node.md). It should return a list of [`Selection`](./selection.md) objects with the desired marks, which will then be added to the text before rendering.
|
||||
The `decorate` property allows you define a function that will apply extra marks to ranges of text inside a node. It is called with a [`Node`](./node.md). It should return a list of [`Range`](./range.md) objects with the desired marks, which will then be added to the text before rendering.
|
||||
|
||||
### `normalize`
|
||||
`Function normalize(change: Change, object: Node, failure: Any) => Change`
|
||||
|
@@ -1,13 +1,13 @@
|
||||
|
||||
# `Selection`
|
||||
# `Range`
|
||||
|
||||
```js
|
||||
import { Selection } from 'slate'
|
||||
import { Range } from 'slate'
|
||||
```
|
||||
|
||||
A selection of a Slate [`Document`](./document.md). Selections in Slate are modeled after the native [DOM Selection API](https://developer.mozilla.org/en-US/docs/Web/API/Selection), using terms like "anchor", "focus" and "collapsed".
|
||||
A range of a Slate [`Document`](./document.md). Ranges in Slate are modeled after a combination of the [DOM Selection API](https://developer.mozilla.org/en-US/docs/Web/API/Selection) and the [DOM Range API](https://developer.mozilla.org/en-US/docs/Web/API/Range), using terms like "anchor", "focus" and "collapsed".
|
||||
|
||||
The "anchor" is the fixed point in a selection, and the "focus" is the non-fixed point, which may move when you move the cursor (eg. when pressing `Shift + Right Arrow`).
|
||||
The "anchor" is the fixed point in a range, and the "focus" is the non-fixed point, which may move when you move the cursor (eg. when pressing `Shift + Right Arrow`).
|
||||
|
||||
Often times, you don't need to specifically know which point is the "anchor" and which is the "focus", and you just need to know which comes first and last in the document. For these cases, there are many convenience equivalent properties and methods referring to the "start" and "end" points.
|
||||
|
||||
@@ -15,7 +15,7 @@ Often times, you don't need to specifically know which point is the "anchor" and
|
||||
## Properties
|
||||
|
||||
```js
|
||||
Selection({
|
||||
Range({
|
||||
anchorKey: String,
|
||||
anchorOffset: Number,
|
||||
focusKey: String,
|
||||
@@ -28,37 +28,37 @@ Selection({
|
||||
### `anchorKey`
|
||||
`String`
|
||||
|
||||
The key of the text node at the selection's anchor point.
|
||||
The key of the text node at the range's anchor point.
|
||||
|
||||
### `anchorOffset`
|
||||
`Number`
|
||||
|
||||
The number of characters from the start of the text node at the selection's anchor point.
|
||||
The number of characters from the start of the text node at the range's anchor point.
|
||||
|
||||
### `focusKey`
|
||||
`String`
|
||||
|
||||
The key of the text node at the selection's focus point.
|
||||
The key of the text node at the range's focus point.
|
||||
|
||||
### `focusOffset`
|
||||
`Number`
|
||||
|
||||
The number of characters from the start of the text node at the selection's focus point.
|
||||
The number of characters from the start of the text node at the range's focus point.
|
||||
|
||||
### `isBackward`
|
||||
`Boolean`
|
||||
|
||||
Whether the selection is backward. A selection is considered "backward" when its focus point references a location earlier in the document than its anchor point.
|
||||
Whether the range is backward. A range is considered "backward" when its focus point references a location earlier in the document than its anchor point.
|
||||
|
||||
### `isFocused`
|
||||
`Boolean`
|
||||
|
||||
Whether the selection currently has focus.
|
||||
Whether the range currently has focus.
|
||||
|
||||
|
||||
## Computed Properties
|
||||
|
||||
These properties aren't supplied when creating a selection, but are instead computed based on the real properties.
|
||||
These properties aren't supplied when creating a range, but are instead computed based on the real properties.
|
||||
|
||||
### `isBlurred`
|
||||
`Boolean`
|
||||
@@ -68,7 +68,7 @@ The opposite of `isFocused`, for convenience.
|
||||
### `isCollapsed`
|
||||
`Boolean`
|
||||
|
||||
Whether the selection is collapsed. A selection is considered "collapsed" when the anchor point and focus point of the selection are the same.
|
||||
Whether the range is collapsed. A range is considered "collapsed" when the anchor point and focus point of the range are the same.
|
||||
|
||||
### `isExpanded`
|
||||
`Boolean`
|
||||
@@ -85,25 +85,25 @@ The opposite of `isBackward`, for convenience.
|
||||
### `endKey`
|
||||
### `endOffset`
|
||||
|
||||
A few convenience properties for accessing the first and last point of the selection. When the selection is forward, `start` refers to the `anchor` point and `end` refers to the `focus` point. And when it's backward they are reversed.
|
||||
A few convenience properties for accessing the first and last point of the range. When the range is forward, `start` refers to the `anchor` point and `end` refers to the `focus` point. And when it's backward they are reversed.
|
||||
|
||||
|
||||
## Static Methods
|
||||
|
||||
### `Selection.create`
|
||||
`Selection.create(properties: Object) => Selection`
|
||||
### `Range.create`
|
||||
`Range.create(properties: Object) => Range`
|
||||
|
||||
Create a new `Selection` instance with `properties`.
|
||||
Create a new `Range` instance with `properties`.
|
||||
|
||||
### `Selection.fromJSON`
|
||||
`Selection.fromJSON(object: Object) => Selection`
|
||||
### `Range.fromJSON`
|
||||
`Range.fromJSON(object: Object) => Range`
|
||||
|
||||
Create a selection from a JSON `object`.
|
||||
Create a range from a JSON `object`.
|
||||
|
||||
### `Selection.isSelection`
|
||||
`Selection.isSelection(maybeSelection: Any) => Boolean`
|
||||
### `Range.isRange`
|
||||
`Range.isRange(maybeRange: Any) => Boolean`
|
||||
|
||||
Returns a boolean if the passed in argument is a `Selection`.
|
||||
Returns a boolean if the passed in argument is a `Range`.
|
||||
|
||||
|
||||
## Instance Methods
|
||||
@@ -111,7 +111,7 @@ Returns a boolean if the passed in argument is a `Selection`.
|
||||
### `toJSON`
|
||||
`toJSON() => Object`
|
||||
|
||||
Returns a JSON representation of the selection.
|
||||
Returns a JSON representation of the range.
|
||||
|
||||
|
||||
## Checking Methods
|
||||
@@ -119,29 +119,29 @@ Returns a JSON representation of the selection.
|
||||
### `has{Edge}AtStartOf`
|
||||
`has{Edge}AtStartOf(node: Node) => Boolean`
|
||||
|
||||
Determine whether a selection has an edge at the start of a `node`. Where `{Edge}` can be one of: `Anchor`, `Focus`, `Start`, `End` or `Edge` (referring to either point).
|
||||
Determine whether a range has an edge at the start of a `node`. Where `{Edge}` can be one of: `Anchor`, `Focus`, `Start`, `End` or `Edge` (referring to either point).
|
||||
|
||||
### `has{Edge}AtEndOf`
|
||||
`has{Edge}AtEndOf(node: Node) => Boolean`
|
||||
|
||||
Determine whether a selection has an edge at the end of a `node`. Where `{Edge}` can be one of: `Anchor`, `Focus`, `Start`, `End` or `Edge` (referring to either point).
|
||||
Determine whether a range has an edge at the end of a `node`. Where `{Edge}` can be one of: `Anchor`, `Focus`, `Start`, `End` or `Edge` (referring to either point).
|
||||
|
||||
### `has{Edge}Between`
|
||||
`has{Edge}Between(node: Node, start: Number, end: Number) => Boolean`
|
||||
|
||||
Determine whether a selection has an edge in a `node` between its `start` and `end` offset. Where `{Edge}` can be one of: `Anchor`, `Focus`, `Start`, `End` or `Edge` (referring to either point).
|
||||
Determine whether a range has an edge in a `node` between its `start` and `end` offset. Where `{Edge}` can be one of: `Anchor`, `Focus`, `Start`, `End` or `Edge` (referring to either point).
|
||||
|
||||
### `has{Edge}In`
|
||||
`has{Edge}In(node: Node) => Boolean`
|
||||
|
||||
Determine whether a selection has an edge inside a `node`. Where `{Edge}` can be one of: `Anchor`, `Focus`, `Start`, `End` or `Edge` (referring to either point).
|
||||
Determine whether a range has an edge inside a `node`. Where `{Edge}` can be one of: `Anchor`, `Focus`, `Start`, `End` or `Edge` (referring to either point).
|
||||
|
||||
### `isAtStartOf`
|
||||
`isAtStartOf(node: Node) => Boolean`
|
||||
|
||||
Determine whether the selection is at the start of a `node`.
|
||||
Determine whether the range is at the start of a `node`.
|
||||
|
||||
### `isAtEndOf`
|
||||
`isAtEndOf(node: Node) => Boolean`
|
||||
|
||||
Determine whether the selection is at the end of a `node`.
|
||||
Determine whether the range is at the end of a `node`.
|
||||
|
@@ -5,11 +5,11 @@
|
||||
import { State } from 'slate'
|
||||
```
|
||||
|
||||
A `State` is the top-level representation of data in Slate, containing both a [`Document`](./document.md) and a [`Selection`](./selection.md). It's what you need to paste into the Slate [`<Editor>`](../slate-react/editor.md) to render something onto the page.
|
||||
A `State` is the top-level representation of data in Slate, containing both a [`Document`](./document.md) and a selection [`Range`](./range.md). It's what you need to pass into the Slate [`<Editor>`](../slate-react/editor.md) to render something onto the page.
|
||||
|
||||
All changes to the document and selection are also performed through the state object, so that they can stay in sync, and be propagated to its internal history of undo/redo state.
|
||||
|
||||
For convenience, in addition to changes, many of the [`Selection`](./selection.md) and [`Document`](./document.md) properties are exposed as proxies on the `State` object.
|
||||
For convenience, in addition to changes, many of the selection and document properties are exposed as proxies on the `State` object.
|
||||
|
||||
|
||||
## Properties
|
||||
@@ -17,7 +17,7 @@ For convenience, in addition to changes, many of the [`Selection`](./selection.m
|
||||
```js
|
||||
State({
|
||||
document: Document,
|
||||
selection: Selection
|
||||
selection: Range
|
||||
})
|
||||
```
|
||||
|
||||
@@ -27,7 +27,7 @@ State({
|
||||
The current document of the state.
|
||||
|
||||
### `selection`
|
||||
`Selection`
|
||||
`Range`
|
||||
|
||||
The current selection of the state.
|
||||
|
||||
@@ -92,9 +92,9 @@ Whether there are undoable snapshots to revert to in the history.
|
||||
|
||||
Whether there are redoable snapshots to revert to in the history.
|
||||
|
||||
## Selection-like Properties
|
||||
## Range-like Properties
|
||||
|
||||
These properties are exact proxies of their [`Selection`](./selection) equivalents.
|
||||
These properties are exact proxies of the selection [`Range`](./range.md) equivalents.
|
||||
|
||||
### `{edge}Key`
|
||||
`String`
|
||||
|
Reference in New Issue
Block a user