1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-20 06:01:24 +02:00

Remove commands (#3351)

* remove commands in favor of editor-level functions

* update examples

* fix lint
This commit is contained in:
Ian Storm Taylor
2019-12-18 15:00:42 -05:00
committed by GitHub
parent c2d7905e19
commit 0bbe121d76
578 changed files with 3532 additions and 3370 deletions

View File

@@ -103,13 +103,13 @@ Another special group of helper functions exposed on the `Editor` interface are
```js
// Insert an element node at a specific path.
Editor.insertNodes(editor, [element], { at: path })
Transforms.insertNodes(editor, [element], { at: path })
// Split the nodes in half at a specific point.
Editor.splitNodes(editor, { at: point })
Transforms.splitNodes(editor, { at: point })
// Add a quote format to all the block nodes in the selection.
Editor.setNodes(editor, { type: 'quote' })
Transforms.setNodes(editor, { type: 'quote' })
```
The editor-specific helpers are the ones you'll use most often when working with Slate editors, so it pays to become very familiar with them.

View File

@@ -14,7 +14,7 @@ const withImages = editor => {
if (command.type === 'insert_image') {
const { url } = command
const element = { type: 'image', url, children: [{ text: '' }] }
Editor.insertNodes(editor, element)
Transforms.insertNodes(editor, element)
} else {
exec(command)
}

View File

@@ -41,7 +41,7 @@ const withParagraphs = editor => {
if (Element.isElement(node) && node.type === 'paragraph') {
for (const [child, childPath] of Node.children(editor, path)) {
if (Element.isElement(child) && !editor.isInline(child)) {
Editor.unwrapNodes(editor, { at: childPath })
Transforms.unwrapNodes(editor, { at: childPath })
return
}
}
@@ -67,7 +67,7 @@ If you check the example above again, you'll notice the `return` statement:
```js
if (Element.isElement(child) && !editor.isInline(child)) {
Editor.unwrapNodes(editor, { at: childPath })
Transforms.unwrapNodes(editor, { at: childPath })
return
}
```
@@ -135,7 +135,7 @@ const withLinks = editor => {
node.type === 'link' &&
typeof node.url !== 'string'
) {
Editor.setNodes(editor, { url: null }, { at: path })
Transforms.setNodes(editor, { url: null }, { at: path })
return
}