1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-26 00:27:28 +02:00

docs: improve editor docs (#4218)

This commit is contained in:
Sunny Hirai
2021-04-22 16:41:11 -07:00
committed by GitHub
parent 602f170156
commit f198d0bd1f

View File

@@ -330,9 +330,7 @@ Options: `{force?: boolean}`
Call a function, deferring normalization until after it completes. Call a function, deferring normalization until after it completes.
## Instance methods ## Schema-specific instance methods to override
### Schema-specific methods to override
Replace these methods to modify the original behavior of the editor when building [Plugins](https://github.com/ianstormtaylor/slate/tree/a02787539a460fb70730085e26df13cca959fabd/concepts/07-plugins/README.md). When modifying behavior, call the original method when appropriate. For example, a plugin that marks image nodes as "void": Replace these methods to modify the original behavior of the editor when building [Plugins](https://github.com/ianstormtaylor/slate/tree/a02787539a460fb70730085e26df13cca959fabd/concepts/07-plugins/README.md). When modifying behavior, call the original method when appropriate. For example, a plugin that marks image nodes as "void":
@@ -348,6 +346,10 @@ const withImages = editor => {
} }
``` ```
### Override element type methods
Use these methods that Slate can identify certain elements as [inlines](../concepts/02-nodes#blocks-vs-inlines) or [voids](../concepts/02-nodes#voids).
#### `isInline(element: Element)` #### `isInline(element: Element)`
Check if a value is an inline `Element` object. Check if a value is an inline `Element` object.
@@ -356,15 +358,19 @@ Check if a value is an inline `Element` object.
Check if a value is a void `Element` object. Check if a value is a void `Element` object.
### Override normalize method
#### `normalizeNode(entry: NodeEntry)` #### `normalizeNode(entry: NodeEntry)`
Normalize a Node according to the schema. Normalize a Node according to the schema.
### Override callback method
#### `onChange()` #### `onChange()`
Called when there is a change in the editor. Called when there is a change in the editor.
### Core actions ### Override mark methods
#### `addMark(key: string, value: any)` #### `addMark(key: string, value: any)`
@@ -374,6 +380,10 @@ Add a custom property to the leaf text nodes in the current selection. If the se
Remove a custom property from the leaf text nodes in the current selection. Remove a custom property from the leaf text nodes in the current selection.
### Override delete methods
When a user presses backspace or delete, it invokes the method based on the selection. For example, if the selection is expanded over some text and the user presses the backspace key, `deleteFragment` will be called but if the selecttion is collapsed, `deleteBackward` will be called.
#### `deleteBackward(options?: {unit?: 'character' | 'word' | 'line' | 'block'})` #### `deleteBackward(options?: {unit?: 'character' | 'word' | 'line' | 'block'})`
Delete content in the editor backward from the current selection. Delete content in the editor backward from the current selection.
@@ -382,14 +392,16 @@ Delete content in the editor backward from the current selection.
Delete content in the editor forward from the current selection. Delete content in the editor forward from the current selection.
#### `insertFragment(fragment: Node[])`
Insert a fragment at the current selection. If the selection is currently expanded, delete it first.
#### `deleteFragment()` #### `deleteFragment()`
Delete the content of the current selection. Delete the content of the current selection.
### Override insert methods
#### `insertFragment(fragment: Node[])`
Insert a fragment at the current selection. If the selection is currently expanded, delete it first.
#### `insertBreak()` #### `insertBreak()`
Insert a block break at the current selection. If the selection is currently expanded, delete it first. Insert a block break at the current selection. If the selection is currently expanded, delete it first.
@@ -402,6 +414,8 @@ Insert a node at the current selection. If the selection is currently expanded,
Insert text at the current selection. If the selection is currently expanded, delete it first. Insert text at the current selection. If the selection is currently expanded, delete it first.
### Override operation handling method
#### `apply(operation: Operation)` #### `apply(operation: Operation)`
Apply an operation in the editor. Apply an operation in the editor.