mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-19 05:31:56 +02:00
doc: add missing APIs in the doc (#5835)
* doc: add missing APIs in the doc * refactor: apply lint
This commit is contained in:
@@ -246,6 +246,10 @@ Delete the content in the current selection.
|
||||
|
||||
Insert a block break at the current selection.
|
||||
|
||||
#### `Editor.insertSoftBreak(editor: Editor) => void`
|
||||
|
||||
Insert a soft break at the current selection.
|
||||
|
||||
#### `Editor.insertFragment(editor: Editor, fragment: Node[], options?) => void`
|
||||
|
||||
Inserts a fragment at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
|
||||
@@ -444,7 +448,7 @@ Remove a custom property from the leaf text nodes within non-void nodes or void
|
||||
|
||||
### getFragment method
|
||||
|
||||
#### `getFragment() => Descendant`
|
||||
#### `getFragment() => Descendant[]`
|
||||
|
||||
Returns the fragment at the current selection. Used when cutting or copying, as an example, to get the fragment at the current selection.
|
||||
|
||||
|
@@ -51,6 +51,26 @@ Return a generator of all the element nodes inside a root node. Each iteration w
|
||||
|
||||
Options: `{from?: Path, to?: Path, reverse?: boolean, pass?: (node: NodeEntry => boolean)}`
|
||||
|
||||
#### `Node.extractProps(node: Node) => NodeProps`
|
||||
|
||||
Extract all properties from a Node except for its content-related fields (`children` for Element nodes and `text` for Text nodes).
|
||||
|
||||
```typescript
|
||||
// For an Element node
|
||||
const element = {
|
||||
type: 'paragraph',
|
||||
align: 'center',
|
||||
children: [{ text: 'Try it out for yourself!' }],
|
||||
}
|
||||
const props = Node.extractProps(element)
|
||||
// Returns: { type: 'paragraph', align: "center" }
|
||||
|
||||
// For a Text node
|
||||
const text = { text: 'Hello', bold: true }
|
||||
const props = Node.extractProps(text)
|
||||
// Returns: { bold: true }
|
||||
```
|
||||
|
||||
#### `Node.first(root: Node, path: Path) => NodeEntry`
|
||||
|
||||
Get the first node entry in a root node from a `path`.
|
||||
@@ -63,6 +83,19 @@ Get the sliced fragment represented by the `range`.
|
||||
|
||||
Get the descendant node referred to by a specific `path`. If the path is an empty array, get the root node itself.
|
||||
|
||||
#### `Node.getIf(root: Node, path: Path) => Node | undefined`
|
||||
|
||||
Get a descendant node at a specific path, returning `undefined` if the node does not exist. This is a safer alternative to `Node.get()` as it won't throw an error if the path is invalid.
|
||||
|
||||
```typescript
|
||||
const node = Node.getIf(root, [0, 1])
|
||||
if (node) {
|
||||
// node exists at path [0, 1]
|
||||
} else {
|
||||
// no node exists at path [0, 1]
|
||||
}
|
||||
```
|
||||
|
||||
#### `Node.last(root: Node, path: Path) => NodeEntry`
|
||||
|
||||
Get the last node entry in a root node at a specific `path`.
|
||||
|
Reference in New Issue
Block a user