Skip to content

Commit 5adb8ed

Browse files
doc: add missing APIs in the doc (#5835)
* doc: add missing APIs in the doc * refactor: apply lint
1 parent 8b2414a commit 5adb8ed

File tree

6 files changed

+51
-3
lines changed

6 files changed

+51
-3
lines changed

docs/api/locations/path-ref.md

+7
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ interface PathRef {
1010
}
1111
```
1212

13+
- [Instance methods](path-ref.md#instance-methods)
1314
- [Static methods](path-ref.md#static-methods)
1415
- [Transform methods](path-ref.md#trasnform-methods)
1516

17+
## Instance methods
18+
19+
#### `unref() => Path | null`
20+
21+
Free the resources used by the PathRef. This should be called when you no longer need to track the path. Returns the final path value before being unrefed, or null if the path was already invalid.
22+
1623
## Static methods
1724

1825
### Transform methods

docs/api/locations/path.md

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ Check is a value implements the `Path` interface.
115115
116116
Check if a path is a sibling of another.
117117
118+
#### `Path.operationCanTransformPath(operation: Operation) => operation is InsertNodeOperation | RemoveNodeOperation | MergeNodeOperation | SplitNodeOperation | MoveNodeOperation`
119+
120+
Returns whether this operation can affect paths or not.
121+
118122
### Transform method
119123
120124
#### `Path.transform(path: Path, operation: Operation, options?) => Path | null`

docs/api/locations/point-ref.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface PointRef {
1616

1717
## Instance methods
1818

19-
#### `unRef() => Point`
19+
#### `unref() => Point | null`
2020

2121
Call this when you no longer need to sync this point.
2222
It also returns the current value.

docs/api/locations/range-ref.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Transforms.select(editor, selectionRef.unref())
2727

2828
## Instance methods
2929

30-
#### `unref() => Range`
30+
#### `unref() => Range | null`
3131

3232
Call this when you no longer need to sync this range.
3333
It also returns the current value.

docs/api/nodes/editor.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ Delete the content in the current selection.
246246

247247
Insert a block break at the current selection.
248248

249+
#### `Editor.insertSoftBreak(editor: Editor) => void`
250+
251+
Insert a soft break at the current selection.
252+
249253
#### `Editor.insertFragment(editor: Editor, fragment: Node[], options?) => void`
250254

251255
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
444448

445449
### getFragment method
446450

447-
#### `getFragment() => Descendant`
451+
#### `getFragment() => Descendant[]`
448452

449453
Returns the fragment at the current selection. Used when cutting or copying, as an example, to get the fragment at the current selection.
450454

docs/api/nodes/node.md

+33
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ Return a generator of all the element nodes inside a root node. Each iteration w
5151

5252
Options: `{from?: Path, to?: Path, reverse?: boolean, pass?: (node: NodeEntry => boolean)}`
5353

54+
#### `Node.extractProps(node: Node) => NodeProps`
55+
56+
Extract all properties from a Node except for its content-related fields (`children` for Element nodes and `text` for Text nodes).
57+
58+
```typescript
59+
// For an Element node
60+
const element = {
61+
type: 'paragraph',
62+
align: 'center',
63+
children: [{ text: 'Try it out for yourself!' }],
64+
}
65+
const props = Node.extractProps(element)
66+
// Returns: { type: 'paragraph', align: "center" }
67+
68+
// For a Text node
69+
const text = { text: 'Hello', bold: true }
70+
const props = Node.extractProps(text)
71+
// Returns: { bold: true }
72+
```
73+
5474
#### `Node.first(root: Node, path: Path) => NodeEntry`
5575

5676
Get the first node entry in a root node from a `path`.
@@ -63,6 +83,19 @@ Get the sliced fragment represented by the `range`.
6383

6484
Get the descendant node referred to by a specific `path`. If the path is an empty array, get the root node itself.
6585

86+
#### `Node.getIf(root: Node, path: Path) => Node | undefined`
87+
88+
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.
89+
90+
```typescript
91+
const node = Node.getIf(root, [0, 1])
92+
if (node) {
93+
// node exists at path [0, 1]
94+
} else {
95+
// no node exists at path [0, 1]
96+
}
97+
```
98+
6699
#### `Node.last(root: Node, path: Path) => NodeEntry`
67100

68101
Get the last node entry in a root node at a specific `path`.

0 commit comments

Comments
 (0)