Skip to content

Commit ccc0bb6

Browse files
committed
v2
1 parent 992bb00 commit ccc0bb6

71 files changed

Lines changed: 1203 additions & 1269 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/api/locations/point.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ interface Point {
1111
```
1212

1313
When `root` is omitted, Slate resolves the point against the current editor or
14-
view root. The base editor and pure helpers fall back to `main`; root-bound
15-
views fall back to their own root. Points may also carry `root: 'main'`
16-
explicitly. Points in header, footer, content-root, or other named roots carry
17-
that root key.
14+
view root. The base editor and pure helpers fall back to the primary document;
15+
root-bound views fall back to their own root. Points in header, footer,
16+
content-root, or other extra roots carry that root key.
1817

1918
- [Static methods](point.md#static-methods)
2019
- [Retrieval methods](point.md#retrieval-methods)

‎docs/api/locations/range.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ interface Range {
99
}
1010
```
1111

12-
Both points must resolve inside the same root. The `main` root is implicit; named
13-
roots are stored on each point with `root`.
12+
Both points must resolve inside the same root. The primary document is
13+
implicit; extra roots are stored on each point with `root`.
1414

1515
- [Static methods](range.md#static-methods)
1616
- [Retrieval methods](range.md#retrieval-methods)

‎docs/api/nodes/editor.md‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,30 @@ editor.update((tx, { afterCommit }) => {
134134

135135
## Document roots
136136

137-
The default document root is `main`. A plain block array initializes `main`.
138-
Pass `initialValue.roots` when one editor owns multiple roots.
137+
A plain block array initializes the primary document. Pass
138+
`initialValue.children` plus `initialValue.roots` when one editor owns extra
139+
roots.
139140

140141
```javascript
141142
const editor = createEditor({
142143
initialValue: {
144+
children: [{ type: 'paragraph', children: [{ text: 'Body' }] }],
143145
roots: {
144146
header: [{ type: 'paragraph', children: [{ text: 'Draft' }] }],
145-
main: [{ type: 'paragraph', children: [{ text: 'Body' }] }],
146147
footer: [{ type: 'paragraph', children: [{ text: 'Internal' }] }],
147148
},
148149
},
149150
})
150151
```
151152

152-
Read roots from `state.value.get().roots`.
153+
Read the primary document with `state.value.root()`. Read an extra root by key.
153154

154155
```javascript
155-
const footer = editor.read((state) => state.value.get().roots.footer)
156+
const body = editor.read((state) => state.value.root())
157+
const footer = editor.read((state) => state.value.root('footer'))
156158
```
157159

158-
Create, replace, or delete non-main roots with `tx.roots`.
160+
Create, replace, or delete extra roots with `tx.roots`.
159161

160162
```javascript
161163
editor.update((tx) => {
@@ -165,7 +167,7 @@ editor.update((tx) => {
165167
})
166168
```
167169

168-
Use normal node and text transforms for the `main` root. See
170+
Use normal node and text transforms for the primary document. See
169171
[Roots](../../concepts/13-roots.md) for React rendering, root chrome, and
170172
content roots.
171173

@@ -175,13 +177,14 @@ content roots.
175177

176178
```ts
177179
type EditorDocumentValue = {
178-
roots: Record<string, Descendant[]>
180+
children: Descendant[]
181+
roots?: Record<string, Descendant[]>
179182
state?: Record<string, unknown>
180183
}
181184
```
182185
183-
Use it for database persistence because it includes named roots and persistent
184-
state fields.
186+
Use it for database persistence because it includes the primary document, extra
187+
roots, and persistent state fields.
185188
186189
```javascript
187190
const documentValue = editor.read((state) => state.value.get())

‎docs/api/operations/operation.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
Node, text, selection, fragment, and `replace_children` operations may include
66
`root`. When `root` is omitted, Slate resolves the operation against the
7-
active operation/view root, then falls back to `main` for the base editor.
8-
Serialized non-main operations should preserve `root`.
7+
active operation/view root, then falls back to the primary document for the
8+
base editor. Serialized extra-root operations should preserve `root`.
99

1010
Root lifecycle updates from `tx.roots.create`, `tx.roots.replace`, and
1111
`tx.roots.delete` are represented as `replace_children` operations at `path:
1212
[]`. Those operations carry `root`, `rootWasPresent`, and `rootIsPresent` so
1313
history and collaboration replay can create, replace, or delete the named root
14-
instead of applying the change to `main`.
14+
instead of applying the change to the primary document.
1515

1616
- [Static methods](operation.md#static-methods)
1717
- [Manipulation methods](operation.md#manipulation-methods)

‎docs/api/transforms.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ Replace an existing named root.
324324
325325
#### `tx.roots.delete(root: RootKey)`
326326
327-
Delete a named root. The main root is not deleted through `tx.roots`.
327+
Delete an extra root. The primary document is not deleted through `tx.roots`.
328328
329329
## State field methods
330330

‎docs/concepts/02-nodes.md‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@ two node types:
77
- `Text` nodes hold string content and mark properties.
88

99
The editor runtime can also act as the root ancestor for node APIs, but the
10-
persisted document value is roots plus optional state fields. Save
11-
`state.value.get()` when you need the whole document.
10+
persisted document value is primary children, optional extra roots, and optional
11+
state fields. Save `state.value.get()` when you need the whole document.
1212

1313
```ts
1414
const documentValue = {
15-
roots: {
16-
main: [
17-
{
18-
type: 'paragraph',
19-
children: [{ text: 'A line of text!' }],
20-
},
21-
],
22-
},
15+
children: [
16+
{
17+
type: 'paragraph',
18+
children: [{ text: 'A line of text!' }],
19+
},
20+
],
2321
state: {
2422
'document.title': 'Draft',
2523
},
2624
}
2725
```
2826

2927
The short editor value is still an array of block elements. Slate treats that
30-
array as the `main` root.
28+
array as the primary document.
3129

3230
```ts
3331
const initialValue = [
@@ -39,7 +37,7 @@ const initialValue = [
3937
```
4038

4139
See [Document State](14-document-state.md) for persistence and
42-
[Roots](13-roots.md) for named roots, content roots, and multi-root rendering.
40+
[Roots](13-roots.md) for extra roots, content roots, and multi-root rendering.
4341

4442
## Element
4543

‎docs/concepts/03-locations.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Locations
22

3-
Locations tell Slate where to read or write inside an editor root. The main
3+
Locations tell Slate where to read or write inside an editor root. The core
44
location types are `Path`, `Point`, and `Range`.
55

66
Rootless locations resolve against the current editor or view root. The base
7-
editor uses `main`; root-bound views use their own root. Locations in named
8-
roots carry the root key on their points.
7+
editor uses the primary document; root-bound views use their own root.
8+
Locations in extra roots carry the root key on their points.
99

1010
## Path
1111

@@ -19,7 +19,7 @@ In this root value, the paragraph has path `[0]` and the text node has path
1919
`[0, 0]`.
2020
2121
```ts
22-
const main = [
22+
const children = [
2323
{
2424
type: 'paragraph',
2525
children: [{ text: 'A line of text!' }],

‎docs/concepts/10-serializing.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Read the full persisted document through `state.value.get()`.
88

99
```ts
1010
const documentValue = editor.read((state) => state.value.get())
11-
const main = documentValue.roots.main
11+
const children = documentValue.children
1212
```
1313

1414
For single-root editors, `<Slate onChange>` gives the current provider root
15-
value. Use `state.value.get()` when you need named roots or persistent state
15+
value. Use `state.value.get()` when you need extra roots or persistent state
1616
fields. See [Document State](14-document-state.md).
1717

1818
## Plain Text
@@ -72,7 +72,7 @@ const serializeHtml = (node: Descendant): string => {
7272
}
7373

7474
const html = editor
75-
.read((state) => state.value.get().roots.main)
75+
.read((state) => state.value.root())
7676
.map(serializeHtml)
7777
.join('')
7878
```

‎docs/concepts/13-roots.md‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Roots
22

3-
Slate stores document content in named roots. The default root is `main`; extra
4-
roots let one editor own headers, footers, synced blocks, captions, side panels,
5-
and other editable regions without creating separate editor instances.
3+
Slate stores the primary document as a normal block array. Extra roots let one
4+
editor own headers, footers, synced blocks, captions, side panels, and other
5+
editable regions without creating separate editor instances.
66

77
Use roots when the content should share editor state, history, collaboration,
88
schema, and commands. Use separate editors when the documents should be fully
@@ -11,45 +11,46 @@ independent.
1111
## Value Shape
1212

1313
The shortest editor value is still an array of blocks. Slate treats it as the
14-
`main` root.
14+
primary document.
1515

1616
```tsx
1717
const editor = createEditor({
1818
initialValue: [{ type: 'paragraph', children: [{ text: 'Body' }] }],
1919
})
2020
```
2121

22-
Pass `initialValue.roots` when the editor owns more than one root.
22+
Pass `initialValue.children` plus `initialValue.roots` when the editor owns
23+
extra roots.
2324

2425
```tsx
2526
const editor = createEditor({
2627
initialValue: {
28+
children: [{ type: 'paragraph', children: [{ text: 'Body' }] }],
2729
roots: {
2830
header: [{ type: 'paragraph', children: [{ text: 'Draft' }] }],
29-
main: [{ type: 'paragraph', children: [{ text: 'Body' }] }],
3031
footer: [{ type: 'paragraph', children: [{ text: 'Internal' }] }],
3132
},
3233
},
3334
})
3435
```
3536

3637
Each root is a normal Slate block array. Rootless operations, points, and
37-
selections resolve against the current editor or view root. The base editor's
38-
current root defaults to `main`; a root-bound view resolves rootless locations
39-
against its own root.
38+
selections resolve against the current editor or view root. A root-bound view
39+
resolves rootless locations against its own root.
4040

4141
Persist roots through the full [Document State](14-document-state.md) value
42-
instead of saving only the main root.
42+
instead of saving only the provider root.
4343

4444
## Reading And Writing Roots
4545

46-
Read all roots from `state.value.get().roots`.
46+
Read the primary document with `state.value.root()`. Read an extra root by key.
4747

4848
```tsx
49-
const header = editor.read((state) => state.value.get().roots.header)
49+
const body = editor.read((state) => state.value.root())
50+
const header = editor.read((state) => state.value.root('header'))
5051
```
5152

52-
Create, replace, or delete non-main roots inside `editor.update`.
53+
Create, replace, or delete extra roots inside `editor.update`.
5354

5455
```tsx
5556
editor.update((tx) => {
@@ -59,8 +60,8 @@ editor.update((tx) => {
5960
})
6061
```
6162

62-
`main` is the stable document root. Mutate its children with normal node and
63-
text transforms instead of `tx.roots`.
63+
Mutate the primary document with normal node and text transforms instead of
64+
`tx.roots`.
6465

6566
## Rendering Roots
6667

@@ -96,7 +97,7 @@ that must run against a specific root.
9697
Content roots attach an editable child root to an element in another root. The
9798
element keeps an empty text child as its model anchor. `element.childRoots[slot]`
9899
stores the root key, and the editable content lives in
99-
`state.value.get().roots[rootKey]`.
100+
`state.value.root(rootKey)`.
100101

101102
```tsx
102103
const syncedBlocks = defineEditorExtension({

‎docs/concepts/14-document-state.md‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Document State
22

3-
Slate persists a document as roots plus optional state fields. Use roots for
4-
editable content and state fields for document metadata, settings, and other
5-
small model state that should share the editor runtime.
3+
Slate persists a document as primary children, optional extra roots, and
4+
optional state fields. Use roots for editable content outside the primary
5+
document and state fields for document metadata, settings, and other small model
6+
state that should share the editor runtime.
67

78
Use external stores for comment bodies, permissions, and audit events; Slate can
89
render their anchors through annotations.
@@ -13,12 +14,13 @@ The full persisted value is `EditorDocumentValue`.
1314

1415
```ts
1516
type EditorDocumentValue = {
16-
roots: Record<string, Descendant[]>
17+
children: Descendant[]
18+
roots?: Record<string, Descendant[]>
1719
state?: Record<string, unknown>
1820
}
1921
```
2022
21-
`roots.main` is the default editable body. Named roots store headers, footers,
23+
`children` is the primary editable body. Extra roots store headers, footers,
2224
content roots, synced blocks, captions, and other editable regions owned by the
2325
same editor.
2426
@@ -36,8 +38,8 @@ await saveDocument(JSON.stringify(documentValue))
3638
```
3739

3840
The first argument passed to `<Slate onChange>` is the provider root's block
39-
array. For `<Slate editor={editor}>`, that is `main`. That is enough for a
40-
simple single-root editor, but it drops named roots and persistent state fields.
41+
array. That is enough for a simple single-root editor, but it drops extra roots
42+
and persistent state fields.
4143
Use `editor.subscribe(...)` for full document persistence so state-field-only
4244
commits and edits in other roots are observed.
4345

@@ -66,9 +68,7 @@ const saved = localStorage.getItem('slate.document')
6668
const initialValue = saved
6769
? JSON.parse(saved)
6870
: {
69-
roots: {
70-
main: [{ type: 'paragraph', children: [{ text: 'Body' }] }],
71-
},
71+
children: [{ type: 'paragraph', children: [{ text: 'Body' }] }],
7272
}
7373

7474
const editor = useSlateEditor({

0 commit comments

Comments
 (0)