platejs 54.0.0-beta.5 → 54.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AIChatRequestContext-CwCmEMVV.d.ts → AIChatRequestContext-BYpGufVe.d.ts} +2 -2
- package/dist/{BaseSuggestionPlugin-CpVkv7k2.d.ts → BaseSuggestionPlugin-C52LR8RN.d.ts} +4 -4
- package/dist/{PlateStatic-C7FfXu-Z.d.ts → PlateStatic-DMClx-tH.d.ts} +3 -3
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/react/index.d.ts +9 -9
- package/dist/authored/index.d.ts +3 -3
- package/dist/code-block/codemirror/index.d.ts +1 -1
- package/dist/{combobox-BhhymlUs.d.ts → combobox-DgYdu5mZ.d.ts} +2 -2
- package/dist/{comparison-types-Bvvxzxq2-08gzpgF6.d.ts → comparison-types-DBQFu7Rt-DYc2TC2H.d.ts} +1 -1
- package/dist/compiler/index.d.ts +2 -2
- package/dist/{core-Bu--Bog3.d.ts → core-CQKT9eNc.d.ts} +6 -6
- package/dist/diff/index.d.ts +2 -2
- package/dist/docs/annotations.md +4 -2
- package/dist/docs/api/anchor.md +15 -0
- package/dist/docs/api/core/plate-components.md +12 -4
- package/dist/docs/api/core.md +4 -3
- package/dist/docs/api/range.md +17 -0
- package/dist/docs/authored-changes.md +3 -3
- package/dist/docs/board.md +2 -1
- package/dist/docs/comment.md +3 -1
- package/dist/docs/editor.md +5 -2
- package/dist/docs/field.md +148 -20
- package/dist/docs/installation/plate-ui.md +40 -14
- package/dist/docs/llms.txt +1 -1
- package/dist/docs/migration/plite-to-plate.md +105 -4
- package/dist/docs/plugin-methods.md +3 -1
- package/dist/docs/roots.md +18 -1
- package/dist/docs/selection.md +5 -0
- package/dist/docs/suggestion.md +2 -2
- package/dist/docs/toolbar.md +11 -2
- package/dist/docx/export/index.d.ts +3 -3
- package/dist/docx/export/lib/internal/unit-conversion.js +1 -1
- package/dist/docx/export/lib/internal/xml-builder.js +1 -1
- package/dist/docx/import/index.d.ts +4 -4
- package/dist/docx/paste/index.d.ts +4 -4
- package/dist/dom/index.d.ts +1 -1
- package/dist/excalidraw/index.d.ts +3 -3
- package/dist/excalidraw/react/index.d.ts +3 -3
- package/dist/facade.js +2 -2
- package/dist/features/board/index.d.ts +1 -1
- package/dist/features/board/lib/boardShape.internal.js +1 -1
- package/dist/features/callout/index.d.ts +3 -3
- package/dist/features/combobox/index.d.ts +2 -2
- package/dist/features/comments/index.d.ts +1 -1
- package/dist/features/date/index.d.ts +3 -3
- package/dist/features/details/index.d.ts +3 -3
- package/dist/features/field/index.d.ts +2 -2
- package/dist/features/field/index.js +2 -2
- package/dist/features/field/lib/BaseFieldPlugin.js +108 -39
- package/dist/features/field/lib/applyFieldValues.js +312 -82
- package/dist/features/field/lib/fieldRules.internal.js +84 -1
- package/dist/features/find/index.d.ts +3 -3
- package/dist/features/footnote/index.d.ts +1 -1
- package/dist/features/ink/index.d.ts +1 -1
- package/dist/features/ink/lib/BaseInkPlugin.js +28 -31
- package/dist/features/ink/lib/inkCodec.internal.js +16 -1
- package/dist/features/ink/lib/inkGone.internal.js +1 -1
- package/dist/features/ink/lib/inkMatch.internal.js +35 -11
- package/dist/features/ink/lib/inkPlaces.internal.js +8 -3
- package/dist/features/layout/index.d.ts +1 -1
- package/dist/features/lint/index.d.ts +3 -3
- package/dist/features/list/lib/listIndex.internal.js +1 -1
- package/dist/features/list/lib/listNumbering.internal.js +1 -1
- package/dist/features/media/index.d.ts +1 -1
- package/dist/features/mention/index.d.ts +5 -5
- package/dist/features/suggestion/BaseSuggestionPlugin.js +3 -2
- package/dist/features/suggestion/index.d.ts +5 -4
- package/dist/features/suggestion/suggestionColorOf.js +5 -4
- package/dist/features/table/index.d.ts +1 -1
- package/dist/features/table/lib/internal/selection.js +1 -1
- package/dist/features/toc/index.d.ts +1 -1
- package/dist/features/upload/index.d.ts +1 -1
- package/dist/history/index.d.ts +2 -2
- package/dist/html/index.d.ts +3 -3
- package/dist/html/server/index.d.ts +1 -1
- package/dist/{htmlTypes-aE9Qlenu.d.ts → htmlTypes-8IFX0ezP.d.ts} +1 -1
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-CbcYN_S_.d.ts → index-AOVPovEr.d.ts} +150 -18
- package/dist/{index-C9WSACSv.d.ts → index-B4oeyc99.d.ts} +1 -1
- package/dist/{index-BYAqyTSY.d.ts → index-BAz_KJSV.d.ts} +2 -2
- package/dist/{index-DqKFQcfb.d.ts → index-BBsiQIzw.d.ts} +2 -2
- package/dist/{index-CTwrWir_.d.ts → index-BIP1GoWI.d.ts} +1 -1
- package/dist/{index-Bf6EwY5O.d.ts → index-BTFrh2Cz.d.ts} +2 -2
- package/dist/{index-CYR4jNU7.d.ts → index-BapA_uvI.d.ts} +4 -4
- package/dist/{index-DhVOU0pS.d.ts → index-BbsVGwn8.d.ts} +6 -6
- package/dist/{index-DlBey0zf.d.ts → index-BcuSI8EM.d.ts} +1 -1
- package/dist/{index-Be_YFFLS.d.ts → index-BfHCmKG3.d.ts} +41 -16
- package/dist/{index-CRmyGzS8-BTrk6JzL.d.ts → index-BvQzYVAW-Jvz2iG8B.d.ts} +1 -1
- package/dist/{index-BT1-fX5o.d.ts → index-C-5w6252.d.ts} +3 -3
- package/dist/{index-dpi2ErEe.d.ts → index-Cp0QfjUV.d.ts} +3 -3
- package/dist/{index-DhurStYU.d.ts → index-CrUMAwqm.d.ts} +5 -1
- package/dist/{index-CGUt4h_4.d.ts → index-D2w_9_tb.d.ts} +3 -3
- package/dist/{index-BR2S-6Js.d.ts → index-DE1Mcccg.d.ts} +3 -3
- package/dist/{index-DFvzP8N_.d.ts → index-DFMkcY5V.d.ts} +4 -4
- package/dist/{index-QuqD4Dyj-DlOIX0sH.d.ts → index-DHt8nZQ6-NUTahb8N.d.ts} +111 -70
- package/dist/{index-BXs4598V.d.ts → index-DM6z4D7q.d.ts} +5 -5
- package/dist/{index-CeVE8JR-.d.ts → index-DUk2VZ_1.d.ts} +3 -3
- package/dist/{index-DqpzKYwP.d.ts → index-DbPoiwq_.d.ts} +3 -3
- package/dist/{index-DgVsTFYL.d.ts → index-Dh7pWHZo.d.ts} +3 -3
- package/dist/{index-BwmXxqbi-COlJb0HZ.d.ts → index-PDROnF1G-Ds_dbJsr.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/internal/penStroke.internal.js +28 -3
- package/dist/internal/plugin/OverridePlugin.js +2 -0
- package/dist/internal/plugin/compilePlateModel.js +2 -8
- package/dist/internal/plugin/pluginStore.js +0 -3
- package/dist/internal/plugin/resolvePlugins.js +1 -1
- package/dist/lib/plugin/createPluginContext.internal.js +2 -3
- package/dist/lib/plugins/html/HtmlPlugin.js +1 -0
- package/dist/markdown/index.d.ts +1 -1
- package/dist/markdown/lib/internal/markdownRawHtml.js +1 -1
- package/dist/markdown/lib/serializer/convertNodesSerialize.js +1 -1
- package/dist/markdown/lib/serializer/listToMdastTree.js +1 -1
- package/dist/math/index.d.ts +3 -3
- package/dist/math/react/index.d.ts +4 -4
- package/dist/migrations/index.d.ts +3 -3
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/react/index.d.ts +2 -2
- package/dist/react/features/board/BoardShape.js +351 -130
- package/dist/react/features/board/boardIndex.internal.js +2 -1
- package/dist/react/features/board/boardInk.internal.js +2 -13
- package/dist/react/features/board/index.d.ts +55 -43
- package/dist/react/features/board/index.js +2 -2
- package/dist/react/features/callout/index.d.ts +3 -3
- package/dist/react/features/combobox/index.d.ts +5 -5
- package/dist/react/features/comments/index.d.ts +6 -6
- package/dist/react/features/date/index.d.ts +4 -4
- package/dist/react/features/details/index.d.ts +4 -4
- package/dist/react/features/field/index.d.ts +20 -5
- package/dist/react/features/footnote/index.d.ts +7 -7
- package/dist/react/features/format-painter/index.d.ts +4 -4
- package/dist/react/features/ink/InkContent.js +45 -20
- package/dist/react/features/ink/InkPlugin.js +52 -5
- package/dist/react/features/ink/index.d.ts +312 -16
- package/dist/react/features/ink/inkCapture.internal.js +36 -9
- package/dist/react/features/ink/inkMeasure.internal.js +1 -1
- package/dist/react/features/ink/inkPaint.internal.js +13 -6
- package/dist/react/features/ink/inkPick.internal.js +218 -0
- package/dist/react/features/ink/inkPlacement.internal.js +8 -3
- package/dist/react/features/ink/inkWatch.internal.js +1 -1
- package/dist/react/features/layout/index.d.ts +5 -5
- package/dist/react/features/media/index.d.ts +5 -5
- package/dist/react/features/mention/index.d.ts +6 -6
- package/dist/react/features/suggestion/index.d.ts +6 -6
- package/dist/react/features/table/index.d.ts +5 -5
- package/dist/react/features/toc/index.d.ts +2 -2
- package/dist/react/features/upload/index.d.ts +5 -5
- package/dist/react/index.d.ts +5 -5
- package/dist/react/internal/rendered-attributes.js +1 -1
- package/dist/react/virtualized.d.ts +2 -2
- package/dist/{source-GMnTi_Vr.d.ts → source-D5CyclpX.d.ts} +3 -3
- package/dist/static/index.d.ts +5 -5
- package/dist/tabbable/index.d.ts +1 -1
- package/dist/tabbable/react/index.d.ts +3 -3
- package/dist/testing/index.d.ts +2 -2
- package/dist/yjs/index.d.ts +1 -1
- package/dist/yjs/react/index.d.ts +5 -5
- package/package.json +2 -2
package/dist/docs/field.md
CHANGED
|
@@ -6,7 +6,7 @@ A field is a typed blank in a document that one role fills, such as a tenant's n
|
|
|
6
6
|
|
|
7
7
|
_Example `field-demo` in the Plate repository: `apps/www/src/registry/examples/field-demo.tsx`, `apps/www/src/registry/examples/values/field-value.tsx`, `apps/www/src/registry/examples/values/cn/field-value.tsx`._
|
|
8
8
|
|
|
9
|
-
The demo is a lease template for a landlord and
|
|
9
|
+
The demo is a lease template for a landlord, a tenant and an `app` role that holds the address and the rent. Insert a field from the toolbar's menu, click a field to change its settings, and read the HTML, Markdown and Word panels under the editor. Pick Fill as landlord or Fill as tenant above the editor to fill the lease as that role. In the Author view, Fill from sample data submits the app's answers from a sample record and opens the tenant's view with the tenant's name from the same record. Submit checks that role's answers after the answers of the roles that submitted before it. The Submission panel then shows each refusal, or the filled document as static output with the roles it still waits on, and the Answers panel lists each role's answers by name.
|
|
10
10
|
|
|
11
11
|
<PackageInfo>
|
|
12
12
|
|
|
@@ -15,10 +15,12 @@ The demo is a lease template for a landlord and a tenant. Insert a field from th
|
|
|
15
15
|
- Inline void `field` element of six kinds: text, number, date, checkbox, choice and signature.
|
|
16
16
|
- A role per field, a label, and an optional required flag, default, choice options and value, each checked against the field's kind.
|
|
17
17
|
- A condition that names another field by its `fieldId` and tests that field's value. A field whose condition fails is skipped, so it needs no answer.
|
|
18
|
+
- An optional `name` that gives the fields of one role one answer, so a question the document asks twice is answered once.
|
|
18
19
|
- `insert` and `update` commands that refuse a setting or condition that does not fit, and reads that report what is wrong with each field and whether it applies.
|
|
19
20
|
- A fill-only view of one role, which takes that role's answers, refuses every other local change and undoes only that role's answers.
|
|
20
21
|
- `applyFieldValues`, which checks each role's answers against the template on a server and builds the filled document.
|
|
21
|
-
-
|
|
22
|
+
- `fieldSubmission`, `startFieldValues` and `readFieldAnswers`, which build a submission from app data by name, start a role from app values and read a saved document's answers by name.
|
|
23
|
+
- New ids for the fields a paste, a drag copy, a duplicate or a table fill copies, which keep their names, with copied conditions that name the copies.
|
|
22
24
|
- HTML and Markdown that keep every property, and Word export that keeps each answer and reports the settings it drops.
|
|
23
25
|
- A field chip with a settings popover that mutes a skipped field, an insert menu, and a static renderer that shows each answer in place or a blank line, in the registry UI.
|
|
24
26
|
|
|
@@ -130,6 +132,7 @@ A field sits inside a paragraph, like a date or a mention.
|
|
|
130
132
|
"kind": "text",
|
|
131
133
|
"role": "tenant",
|
|
132
134
|
"label": "Tenant name",
|
|
135
|
+
"name": "tenant_name",
|
|
133
136
|
"required": true,
|
|
134
137
|
"children": [{ "text": "" }]
|
|
135
138
|
},
|
|
@@ -145,6 +148,7 @@ A field sits inside a paragraph, like a date or a mention.
|
|
|
145
148
|
| `kind` | `FieldKind` | `'text'`, `'number'`, `'date'`, `'checkbox'`, `'choice'` or `'signature'`. Required. |
|
|
146
149
|
| `role` | `string` | The role that fills the field, such as `'tenant'`. Required. |
|
|
147
150
|
| `label` | `string` | Required. The chip shows it, and HTML, Word and plain text show it in brackets when the field has no answer. |
|
|
151
|
+
| `name` | `string` | Fields of one role that share a name hold one answer, see [Names](#names). |
|
|
148
152
|
| `required` | `boolean` | Marks a field that needs a filled answer while it applies. `applyFieldValues` refuses a submission that leaves it unfilled. |
|
|
149
153
|
| `defaultValue` | `FieldValue` | A value of the field's kind. |
|
|
150
154
|
| `options` | `FieldOption[]` | Choice fields only. Each option is `{ value, label }`, and no two share a `value`. |
|
|
@@ -185,6 +189,18 @@ A [fill-only view](#fill-as-one-role) stops one role from changing another role'
|
|
|
185
189
|
|
|
186
190
|
The settings popover offers the roles the document's fields already use, and takes a new one.
|
|
187
191
|
|
|
192
|
+
## Names
|
|
193
|
+
|
|
194
|
+
A `name` says that fields of one role ask for the same answer, such as a lease that asks for the tenant's name at the top and again by the signature. Fields of one role that share a name hold one answer. The same name in two roles is two answers. A field with no name works by its `fieldId` alone.
|
|
195
|
+
|
|
196
|
+
A name is a text that is not empty, has no whitespace at either end, and holds no control character, line or paragraph separator or lone surrogate. Loading, `insert`, `update` and a plain `tx.nodes.set` refuse any other name. In the registry UI, the settings popover's Name input sets a field's name and shows an error for a name the rule refuses.
|
|
197
|
+
|
|
198
|
+
`update` writes a `value`, a cleared one included, to every field of the role that shares the field's name, in the same commit and the same undo step. No other setting reaches the other fields. In the demo, the lease asks for the tenant's name twice under one name, so typing it in one place fills the other, and undo takes it back in both.
|
|
199
|
+
|
|
200
|
+
Fields of one role that share a name must share their kind, the values of their options and their condition. A default takes no part. Two conditions match when they name the same field, or fields of one role and name, with the same test and value. Each field of a name whose fields differ reads `name-conflict`, and `update` then writes a value to its own field alone. `insert` and `update` never refuse a name conflict, so an author can change the fields of a name one at a time.
|
|
201
|
+
|
|
202
|
+
Each field of a name whose fields hold different values reads `answer-conflict`. An empty text and no value differ, and so do `false` and no value. `insert` and a paste write no other field. So a field that joins a name with another value, or with none, reads `answer-conflict` until an `update` writes a value to a field of that name, which writes every field of it.
|
|
203
|
+
|
|
188
204
|
## Insert and update
|
|
189
205
|
|
|
190
206
|
`insert` takes a field's settings and returns its new `fieldId`. Its second argument takes node insert options, such as `at` and `select`.
|
|
@@ -192,17 +208,18 @@ The settings popover offers the roles the document's fields already use, and tak
|
|
|
192
208
|
```tsx
|
|
193
209
|
import { BaseFieldPlugin } from 'platejs/field';
|
|
194
210
|
|
|
195
|
-
editor.update(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
211
|
+
const fieldId = editor.plugin(BaseFieldPlugin).update.insert({
|
|
212
|
+
kind: 'text',
|
|
213
|
+
label: 'Tenant name',
|
|
214
|
+
name: 'tenant_name',
|
|
215
|
+
required: true,
|
|
216
|
+
role: 'tenant',
|
|
200
217
|
});
|
|
201
218
|
```
|
|
202
219
|
|
|
203
|
-
`insert` throws when a value, default or options do not fit the kind, when the settings name a `fieldId
|
|
220
|
+
`insert` throws when a value, default or options do not fit the kind, when the settings name a `fieldId` or a name the [name rule](#names) refuses, or when the condition names no field, or a test or value that the named field's kind does not take.
|
|
204
221
|
|
|
205
|
-
`update` changes the settings or value of the field that holds a `fieldId`. A setting given as `undefined` is removed.
|
|
222
|
+
`update` changes the settings or value of the field that holds a `fieldId`. A setting given as `undefined` is removed. A `value` also goes to every other field of the role and name.
|
|
206
223
|
|
|
207
224
|
```tsx
|
|
208
225
|
editor.update((tx) => {
|
|
@@ -214,6 +231,7 @@ editor.update((tx) => {
|
|
|
214
231
|
|
|
215
232
|
- no field holds `fieldId`;
|
|
216
233
|
- a setting the patch names does not fit the field's kind;
|
|
234
|
+
- the patch names a `name` the name rule refuses;
|
|
217
235
|
- the patch removes `kind`, `role` or `label`, or names `fieldId`;
|
|
218
236
|
- the condition names no field, a test or value that the named field's kind does not take, or a field it did not name before whose chain of conditions leads back to this one.
|
|
219
237
|
|
|
@@ -262,8 +280,10 @@ const skipped = fields.fields().filter((field) => field.applies === false);
|
|
|
262
280
|
| `unsupported-test` | The kind of the field its condition names does not take the condition's test. |
|
|
263
281
|
| `invalid-value` | Its value, default or options do not fit its kind, or its condition's value does not fit the test or the named field's kind. |
|
|
264
282
|
| `condition-loop` | Its condition names a field whose chain of conditions leads back to it, such as A naming B while B names A. |
|
|
283
|
+
| `name-conflict` | A field of its role and name has another kind, other option values or another condition. |
|
|
284
|
+
| `answer-conflict` | A field of its role and name holds another value, or none. |
|
|
265
285
|
|
|
266
|
-
`insert` and `update` refuse a write that would cause a
|
|
286
|
+
`insert` and `update` refuse a write that would cause one of the first four problems. They never refuse a name or answer conflict, which the read reports. A problem comes from a later edit, such as deleting or changing the field a condition names, or from a write that skipped the commands, such as a plain `tx.nodes.set` or a loaded document.
|
|
267
287
|
|
|
268
288
|
`applies` says whether the field applies under its condition. It reads the answers the document holds now, along the whole chain of conditions, as the field's own role reads them:
|
|
269
289
|
|
|
@@ -344,7 +364,7 @@ const submission = editor.plugin(FieldPlugin).read.submission('tenant');
|
|
|
344
364
|
// { role: 'tenant', values: { tenant: 'Grace Hopper', 'pet-name': 'Milo', rules: true } }
|
|
345
365
|
```
|
|
346
366
|
|
|
347
|
-
The submission keeps `false`, `0`, an empty text, a text of spaces and a value that no longer fits its field's kind, so the server judges each of them. It leaves out a field with no `value`, so a checkbox never touched and one ticked and then unticked stay apart.
|
|
367
|
+
Fields of one name keep their own keys, so the submission holds the answer once for each of them. The submission keeps `false`, `0`, an empty text, a text of spaces and a value that no longer fits its field's kind, so the server judges each of them. It leaves out a field with no `value`, so a checkbox never touched and one ticked and then unticked stay apart.
|
|
348
368
|
|
|
349
369
|
### Apply answers on the server
|
|
350
370
|
|
|
@@ -376,7 +396,7 @@ On a refusal, `result` is `{ ok: false, refusals }` with at least one refusal. W
|
|
|
376
396
|
|
|
377
397
|
| Code | When |
|
|
378
398
|
|------|------|
|
|
379
|
-
| `invalid-template` | A template field holds an answer (`answered`), lacks a `fieldId`, holds anything but one text or has a kind, role, label, setting or condition of the wrong shape (`malformed`), repeats a `fieldId` (`duplicate-id`), or has a problem a read reports, `condition-loop` included. The refusal names the `problem`, the field's `path`, its `root` in a named root and its `fieldId` when it has
|
|
399
|
+
| `invalid-template` | A template field holds an answer (`answered`), lacks a `fieldId`, holds anything but one text or has a kind, role, label, setting or condition of the wrong shape (`malformed`), repeats a `fieldId` (`duplicate-id`), or has a problem a read reports, `condition-loop` and `name-conflict` included. The refusal names the `problem`, the field's `path`, its `root` in a named root, and its `fieldId` and `name` when it has them. |
|
|
380
400
|
| `invalid-submission` | A submission is not an object with a `role` string and a `values` object. The refusal names its `index`. |
|
|
381
401
|
| `duplicate-role` | A role already in the list submits again. |
|
|
382
402
|
| `unknown-role` | The role owns no field. |
|
|
@@ -386,8 +406,21 @@ On a refusal, `result` is `{ ok: false, refusals }` with at least one refusal. W
|
|
|
386
406
|
| `waiting` | A field of the role waits on a role that has not submitted, which `waitsOn` names. It is reported even when the field's answer is refused too. |
|
|
387
407
|
| `skipped` | A field of the role is skipped and holds a filled answer. An unfilled answer stays as written, so clearing the answer or unticking the box ends the refusal. |
|
|
388
408
|
| `missing-required` | A required field of the role applies and has no filled answer. |
|
|
409
|
+
| `answer-conflict` | Once the role's answers apply, the fields of one of its names hold different values. The refusal names the `name` and lists every field of the name in document order as `fieldIds`. A name gets none when the submission already refused one of its fields as `invalid-value`, `waiting` or `skipped`. A required field left out does not stop it, so it can come beside `missing-required`. |
|
|
410
|
+
|
|
411
|
+
`invalid-submission`, `duplicate-role` and `unknown-role` come alone. The other submission refusals name the `role`, and the `fieldId` of their field and its `name` when it has one. An `answer-conflict` names `fieldIds` instead of a `fieldId`. The result lists every refusal of that submission.
|
|
389
412
|
|
|
390
|
-
|
|
413
|
+
In a template whose landlord's Rent field is named `rent`, and whose tenant's two name fields share `tenant_name`:
|
|
414
|
+
|
|
415
|
+
```ts
|
|
416
|
+
applyFieldValues(template, [{ role: 'landlord', values: {} }]);
|
|
417
|
+
// { ok: false, refusals: [{ code: 'missing-required', fieldId: 'rent', name: 'rent', role: 'landlord' }] }
|
|
418
|
+
|
|
419
|
+
applyFieldValues(template, [
|
|
420
|
+
{ role: 'tenant', values: { tenant: 'Ada Lovelace', 'tenant-again': 'Ada' } },
|
|
421
|
+
]);
|
|
422
|
+
// { ok: false, refusals: [{ code: 'answer-conflict', fieldIds: ['tenant', 'tenant-again'], name: 'tenant_name', role: 'tenant' }] }
|
|
423
|
+
```
|
|
391
424
|
|
|
392
425
|
In the demo, the tenant's Submit before the landlord's gets a `waiting` refusal, because Pet name waits on the landlord's Pets allowed. When the landlord submits No, a pet name the tenant types anyway is refused as `skipped` until it is cleared.
|
|
393
426
|
|
|
@@ -416,11 +449,103 @@ const { data } = await renderStaticHtml(filled);
|
|
|
416
449
|
|
|
417
450
|
[Static Rendering](/docs/static) covers `EditorStatic` and `renderStaticHtml`.
|
|
418
451
|
|
|
452
|
+
### App data
|
|
453
|
+
|
|
454
|
+
Give the fields your app fills itself a role of their own, such as `app`, and submit that role's answers before anyone signs. Every other role's [fill view](#fill-as-one-role) refuses a write to those fields, and `applyFieldValues` refuses another role's answer for one as `wrong-role`, so the app's values stay locked. Your server keeps the app's submission and sends it first in every list.
|
|
455
|
+
|
|
456
|
+
In a lease whose `app` role holds fields named `address` and `rent`, and whose tenant's two name fields share `tenant_name`, the app fills its own fields and starts the tenant's name from the same record:
|
|
457
|
+
|
|
458
|
+
```ts
|
|
459
|
+
import {
|
|
460
|
+
applyFieldValues,
|
|
461
|
+
BaseFieldPlugin,
|
|
462
|
+
fieldSubmission,
|
|
463
|
+
readFieldAnswers,
|
|
464
|
+
startFieldValues,
|
|
465
|
+
} from 'platejs/field';
|
|
466
|
+
|
|
467
|
+
const record = {
|
|
468
|
+
address: '1 Main St',
|
|
469
|
+
rent: 1200,
|
|
470
|
+
tenant_name: 'Ada Lovelace',
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
// The app's own role fills locked values before anyone signs.
|
|
474
|
+
const app = fieldSubmission(template, 'app', record);
|
|
475
|
+
|
|
476
|
+
// The tenant's fill view opens on the app's answers, with the record's values as a start.
|
|
477
|
+
const start = startFieldValues(
|
|
478
|
+
template,
|
|
479
|
+
[app],
|
|
480
|
+
fieldSubmission(template, 'tenant', record)
|
|
481
|
+
);
|
|
482
|
+
if (!start.ok) throw new Error(start.refusals[0].code);
|
|
483
|
+
|
|
484
|
+
// The tenant fills start.document in an editor whose fillRole is 'tenant'.
|
|
485
|
+
const tenant = editor.plugin(BaseFieldPlugin).read.submission('tenant');
|
|
486
|
+
|
|
487
|
+
// The server applies every role.
|
|
488
|
+
const result = applyFieldValues(template, [app, tenant]);
|
|
489
|
+
if (!result.ok) throw new Error(result.refusals[0].code);
|
|
490
|
+
|
|
491
|
+
// The saved document reads back by name.
|
|
492
|
+
readFieldAnswers(result.document).tenant?.tenant_name;
|
|
493
|
+
// { kind: 'text', value: 'Ada Lovelace' } when the tenant kept the starting name
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
#### Build a submission by name
|
|
497
|
+
|
|
498
|
+
`fieldSubmission(template, role, values, options?)` turns a record keyed by field `name` into one role's `FieldSubmission`, keyed by `fieldId`. Each field of `role` whose name is an own key of `values` gets that key's value, so a name the role asks twice gets it on both fields.
|
|
499
|
+
|
|
500
|
+
- `null` and `undefined` leave the field out.
|
|
501
|
+
- A name the role lacks, a key that names no field and an unnamed field are ignored, so one wide record serves every role. A key the record inherits, such as `constructor`, never counts.
|
|
502
|
+
- It checks no value. `applyFieldValues` judges each one, and refuses an app submission that misses a required field as `missing-required` with the field's `name`.
|
|
503
|
+
- `options.type` names a renamed field type, as it does for `applyFieldValues`.
|
|
504
|
+
|
|
505
|
+
#### Start a role from app values
|
|
506
|
+
|
|
507
|
+
`startFieldValues(template, submissions, start, options?)` checks `submissions` as `applyFieldValues` does, then writes the values of `start`, a `FieldSubmission` of a role that has not submitted, on that role's fields. It returns `applyFieldValues`'s result shape. On success, `document` is the filled document the role starts from, to open in that role's fill view.
|
|
508
|
+
|
|
509
|
+
- A value goes on its field and on every other field of its role and name, as `update` writes it.
|
|
510
|
+
- A field `start` gives no value starts blank, even one with a `defaultValue`.
|
|
511
|
+
- Conditions read the earlier roles' answers and `start`'s own values, as if the role had submitted. A value on a field that skips, or that waits on a role that has not submitted, is left out with no refusal, and the field starts blank. So an app can start from a wide record before every role has answered.
|
|
512
|
+
- `pending` comes from `submissions` alone, so `start` never takes its role off it.
|
|
513
|
+
|
|
514
|
+
The person who fills keeps, changes or clears each starting value. Their submission is their own answer, and `applyFieldValues` judges it like any other. It refuses a cleared required value as `missing-required`, and a kept value on a field that another answer then skips as `skipped` until it is cleared.
|
|
515
|
+
|
|
516
|
+
`startFieldValues` first refuses what `applyFieldValues` refuses for `submissions`. Then it refuses `start` alone as `invalid-submission` when it is malformed, with `index` equal to `submissions.length`, as `duplicate-role` when its role already submitted, and as `unknown-role` when the role owns no field. Otherwise it lists together `unknown-field`, `wrong-role` or `invalid-value` for each value that names no field, another role's field or a value that does not fit, and `answer-conflict` for each name that `start` gives two different values. It never refuses `start` as `missing-required`, `skipped` or `waiting`, because a start may leave any field blank.
|
|
517
|
+
|
|
518
|
+
#### Read saved answers by name
|
|
519
|
+
|
|
520
|
+
`readFieldAnswers(document, options?)` reads a saved document and returns each role's answers keyed by name, as `answers[role][name]`. Each role that has a named field gets a record, and unnamed fields are left out. Both levels are records with no prototype, so a role or name such as `constructor` reads as its own key. It reads fields as `applyFieldValues` reads them, so a node that is not a valid field is skipped, and a duplicated `fieldId` reads from its first holder. `options.type` names a renamed field type.
|
|
521
|
+
|
|
522
|
+
Each answer is a `FieldAnswer`:
|
|
523
|
+
|
|
524
|
+
| Answer | When |
|
|
525
|
+
|--------|------|
|
|
526
|
+
| `{ kind, value }` | The fields of the name hold one value that fits `kind`. `value` is a `boolean` for a checkbox, a `number` for a number and a `string` for every other kind. |
|
|
527
|
+
| `{ kind }` | The fields hold no value, or one value that does not fit `kind`. |
|
|
528
|
+
| `{ kind, problem: 'answer-conflict' }` | The fields hold different values. |
|
|
529
|
+
| `{ problem: 'name-conflict' }` | The fields differ in kind, option values or condition, so the name has no one kind. |
|
|
530
|
+
|
|
531
|
+
Check `'problem' in answer` first, then narrow on `kind` to read `value`:
|
|
532
|
+
|
|
533
|
+
```ts
|
|
534
|
+
const rent = readFieldAnswers(result.document).app?.rent;
|
|
535
|
+
|
|
536
|
+
if (rent && !('problem' in rent) && rent.kind === 'number') {
|
|
537
|
+
rent.value; // number | undefined
|
|
538
|
+
}
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
The read keeps no record of submissions, so it says nothing of which fields apply. A role that submitted nothing and one that left every field blank read the same. An app that needs to know which fields apply takes that from the result of `applyFieldValues`.
|
|
542
|
+
|
|
419
543
|
## Copy and paste
|
|
420
544
|
|
|
421
545
|
A field keeps its `fieldId` through a move, a drag move included, through an undo that brings it back and when a saved document loads. A copy gets new ids:
|
|
422
546
|
|
|
423
|
-
- A paste, a drag copy, `tx.blocks.duplicate` and a table fill give each field they copy a new id. A copied condition that names a field in the same copy names that field's copy.
|
|
547
|
+
- A paste, a drag copy, `tx.blocks.duplicate` and a table fill give each field they copy a new id and keep its name. A copied condition that names a field in the same copy names that field's copy.
|
|
548
|
+
- A copied clause can hold a named field together with the unnamed field its condition names. The copy's condition then names the copied field, so the two fields of the name test different fields and both read `name-conflict`. Give the condition's field and its copy one name, and the conflict ends.
|
|
424
549
|
- A copied condition whose field was not copied, or did not land, keeps naming the original.
|
|
425
550
|
- A paste into a table cell selection copies once per cell, so a condition in each cell names the copy in its own cell.
|
|
426
551
|
- A paste into another document gets new ids too.
|
|
@@ -431,10 +556,10 @@ In Suggesting mode, a change from a field to a mention shows the field as delete
|
|
|
431
556
|
|
|
432
557
|
## HTML
|
|
433
558
|
|
|
434
|
-
`editor.api.html.serialize()` writes each field as a `span` with one `data-field-*` attribute per property. The span's text is the answer, a choice as its option's label, or the label in brackets when the field has no answer. The id, kind, label and role attributes hold plain text, and the others hold JSON:
|
|
559
|
+
`editor.api.html.serialize()` writes each field as a `span` with one `data-field-*` attribute per property. The span's text is the answer, a choice as its option's label, or the label in brackets when the field has no answer. The id, kind, label, name and role attributes hold plain text, and the others hold JSON:
|
|
435
560
|
|
|
436
561
|
```html
|
|
437
|
-
<p>Pets allowed? <span data-field-id="pets" data-field-kind="choice" data-field-label="Pets allowed" data-field-options="[{"label":"Yes","value":"yes"},{"label":"No","value":"no"}]" data-field-required="true" data-field-role="landlord" data-field-value=""yes"">Yes</span> Pet name: <span data-field-condition="{"ref":"pets","test":"equals","value":"yes"}" data-field-id="pet-name" data-field-kind="text" data-field-label="Pet name" data-field-required="true" data-field-role="tenant">[Pet name]</span></p>
|
|
562
|
+
<p>Pets allowed? <span data-field-id="pets" data-field-kind="choice" data-field-label="Pets allowed" data-field-name="pets_allowed" data-field-options="[{"label":"Yes","value":"yes"},{"label":"No","value":"no"}]" data-field-required="true" data-field-role="landlord" data-field-value=""yes"">Yes</span> Pet name: <span data-field-condition="{"ref":"pets","test":"equals","value":"yes"}" data-field-id="pet-name" data-field-kind="text" data-field-label="Pet name" data-field-name="pet_name" data-field-required="true" data-field-role="tenant">[Pet name]</span></p>
|
|
438
563
|
```
|
|
439
564
|
|
|
440
565
|
Parsing that HTML reads every property back. A span needs `data-field-kind`, `data-field-label` and `data-field-role` to read as a field. A pasted HTML template gets new ids, and its conditions name the copies.
|
|
@@ -446,7 +571,7 @@ The demo's HTML panel serializes with `lossPolicy: 'allow'`, because the date el
|
|
|
446
571
|
Markdown writes each field as a `<field>` tag with every property, the `fieldId` and the condition included:
|
|
447
572
|
|
|
448
573
|
```md
|
|
449
|
-
Pets allowed? <field kind="choice" label="Pets allowed" options="[{"label":"Yes","value":"yes"},{"label":"No","value":"no"}]" required role="landlord" value="yes" fieldId="pets" /> Pet name: <field kind="text" label="Pet name" required role="tenant" condition="{"ref":"pets","test":"equals","value":"yes"}" fieldId="pet-name" />
|
|
574
|
+
Pets allowed? <field kind="choice" label="Pets allowed" name="pets_allowed" options="[{"label":"Yes","value":"yes"},{"label":"No","value":"no"}]" required role="landlord" value="yes" fieldId="pets" /> Pet name: <field kind="text" label="Pet name" name="pet_name" required role="tenant" condition="{"ref":"pets","test":"equals","value":"yes"}" fieldId="pet-name" />
|
|
450
575
|
```
|
|
451
576
|
|
|
452
577
|
The reader needs `kind`, `label` and `role`. A tag without them stays as text, with a `markdown-unsupported-node` diagnostic. A pasted Markdown template gets new ids, and its conditions name the copies.
|
|
@@ -464,7 +589,7 @@ const dropped = result.diagnostics.filter(
|
|
|
464
589
|
);
|
|
465
590
|
```
|
|
466
591
|
|
|
467
|
-
The export drops each field's id, kind, role, settings and condition. It reports them with one `property-dropped` warning whose message is "Word keeps each field answer and drops its settings.", whose `feature` is `field` and whose `count` is the number of fields. The warning never refuses an export, under `lossPolicy: 'allow'` or `'reject'`. The demo's Word panel shows that warning, and its count goes up as you insert fields.
|
|
592
|
+
The export drops each field's id, kind, role, name, settings and condition. It reports them with one `property-dropped` warning whose message is "Word keeps each field answer and drops its name and settings.", whose `feature` is `field` and whose `count` is the number of fields. The warning never refuses an export, under `lossPolicy: 'allow'` or `'reject'`. The demo's Word panel shows that warning, and its count goes up as you insert fields.
|
|
468
593
|
|
|
469
594
|
Plain text, through `serializePlainText` from `platejs`, writes the same text as Word.
|
|
470
595
|
|
|
@@ -475,14 +600,17 @@ Plain text, through `serializePlainText` from `platejs`, writes the same text as
|
|
|
475
600
|
| `BaseFieldPlugin` | `platejs/field` | Headless inline void field plugin. |
|
|
476
601
|
| `FieldPlugin` | `platejs/field/react` | React field plugin. |
|
|
477
602
|
| `tx.plugin(BaseFieldPlugin).insert(settings, options?)` | `BaseFieldPlugin` update | Inserts a field and returns its `fieldId`. |
|
|
478
|
-
| `tx.plugin(BaseFieldPlugin).update(fieldId, patch)` | `BaseFieldPlugin` update | Changes a field's settings or value. |
|
|
603
|
+
| `tx.plugin(BaseFieldPlugin).update(fieldId, patch)` | `BaseFieldPlugin` update | Changes a field's settings or value, and writes a value to every field of its role and name. |
|
|
479
604
|
| `editor.plugin(BaseFieldPlugin).read.field(fieldId)` | `BaseFieldPlugin` read | The field that holds an id, with its problems and whether it applies, or `null`. |
|
|
480
605
|
| `editor.plugin(BaseFieldPlugin).read.fields()` | `BaseFieldPlugin` read | Every field in reading order, with its problems and whether it applies. |
|
|
481
606
|
| `editor.plugin(BaseFieldPlugin).read.submission(role)` | `BaseFieldPlugin` read | The values of one role's fields, keyed by `fieldId`, to pass to `applyFieldValues`. |
|
|
482
607
|
| `fillRole` | `BaseFieldPlugin` state | The role this editor fills as, or `null` while authoring. Set it through `initialState` or `editor.plugin(FieldPlugin).store.set`. |
|
|
483
608
|
| `useFieldRead(fieldId)` | `platejs/field/react` | Reads one field, its problems and whether it applies, and renders again when any of them changes. |
|
|
484
609
|
| `applyFieldValues(template, submissions, options?)` | `platejs/field` | Checks each role's answers against the template, and returns the filled document with `pending` or the refusals. |
|
|
610
|
+
| `fieldSubmission(template, role, values, options?)` | `platejs/field` | Builds one role's submission, keyed by `fieldId`, from a record keyed by field name. |
|
|
611
|
+
| `startFieldValues(template, submissions, start, options?)` | `platejs/field` | Checks the submissions, and returns the document a role starts filling from with `pending`, or the refusals. |
|
|
612
|
+
| `readFieldAnswers(document, options?)` | `platejs/field` | Reads a saved document's answers by role and name, each as a `FieldAnswer`. |
|
|
485
613
|
| `fitsField(field, value)` | `platejs/field` | Whether a value fits a field's kind and options. |
|
|
486
614
|
| `fillsField(field, value)` | `platejs/field` | Whether a value is a filled answer for a field. |
|
|
487
615
|
| `FIELD_TESTS` | `platejs/field` | The tests a condition may use on each kind. |
|
|
488
|
-
| `FieldElement`, `FieldSettings`, `FieldPatch`, `FieldRead`, `FieldCondition`, `FieldProblem`, `FieldKind`, `FieldTest`, `FieldValue`, `FieldOption`, `FieldSubmission`, `FieldRefusal`, `FieldApplyResult` | `platejs/field` | Field types. |
|
|
616
|
+
| `FieldElement`, `FieldSettings`, `FieldPatch`, `FieldRead`, `FieldCondition`, `FieldProblem`, `FieldKind`, `FieldTest`, `FieldValue`, `FieldOption`, `FieldSubmission`, `FieldRefusal`, `FieldApplyResult`, `FieldAnswer` | `platejs/field` | Field types. |
|
|
@@ -21,12 +21,14 @@ This is the fastest way to integrate Plate UI's core dependencies and base style
|
|
|
21
21
|
npx shadcn@latest add @plate/plate-ui
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
The command also adds the [editor color](#editor-color) to your global stylesheet.
|
|
25
|
+
|
|
24
26
|
### Basic usage
|
|
25
27
|
|
|
26
28
|
With Plate UI's core installed, proceed to the guide specific to your framework:
|
|
27
29
|
|
|
28
|
-
* **[Next.js Guide](./next)
|
|
29
|
-
* **[React Guide](./react)
|
|
30
|
+
* **[Next.js Guide](./next)**: for server-side rendered applications (Next, Remix, etc.)
|
|
31
|
+
* **[React Guide](./react)**: for single-page applications (Vite, React Router, etc.)
|
|
30
32
|
|
|
31
33
|
</Steps>
|
|
32
34
|
|
|
@@ -47,11 +49,38 @@ Base and style matching needs a Plate registry URL that holds `{style}`, because
|
|
|
47
49
|
- A `base-*` style, such as `base-nova`, installs Base UI files, and a `radix-*` style, such as `radix-luma`, installs Radix files. Each file uses your style's classes.
|
|
48
50
|
- A `base-*` or `radix-*` style that Plate does not serve yet installs the Nova files of its base.
|
|
49
51
|
- In a `base-*` or `radix-*` style, icons come from your icon library: Lucide, Tabler, Hugeicons, Phosphor or Remix Icon.
|
|
50
|
-
- The older styles `new-york`, `new-york-v4` and
|
|
52
|
+
- The older styles `new-york`, `new-york-v4` and `default` install the Radix Nova files with Lucide icons.
|
|
53
|
+
- Plate UI needs Tailwind v4. In a Tailwind v3 app, such as one on shadcn's `default` style, the copied files and the editor color do not work.
|
|
51
54
|
- Toolbar buttons use your project's own `toggle` and `tooltip` components.
|
|
52
55
|
|
|
53
56
|
Plate serves no files for shadcn's React Aria base, so an item fails to install in an `aria-*` style.
|
|
54
57
|
|
|
58
|
+
## Editor color
|
|
59
|
+
|
|
60
|
+
Plate UI paints the editor's text selection, caret, block selection and drop line with the Tailwind color `editor-primary`. Installing `@plate/plate-ui` adds it to your global stylesheet:
|
|
61
|
+
|
|
62
|
+
```css title="app/globals.css"
|
|
63
|
+
@theme inline {
|
|
64
|
+
--color-editor-primary: var(--editor-primary, var(--primary));
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The color needs Tailwind v4. It follows shadcn's `--primary`, so a shadcn theme recolors the editor too.
|
|
69
|
+
|
|
70
|
+
To give the editor a color of its own, add `--editor-primary` to your stylesheet. The install does not add it. A value in `:root` also applies in dark mode unless `.dark` sets its own:
|
|
71
|
+
|
|
72
|
+
```css title="app/globals.css"
|
|
73
|
+
:root {
|
|
74
|
+
--editor-primary: oklch(0.623 0.214 259.815);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.dark {
|
|
78
|
+
--editor-primary: oklch(0.707 0.165 254.624);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
An app without shadcn's theme has no `--primary`, so it must set `--editor-primary`.
|
|
83
|
+
|
|
55
84
|
## Manual installation
|
|
56
85
|
|
|
57
86
|
If you prefer a step-by-step approach or are not using the shadcn CLI, follow these steps:
|
|
@@ -71,21 +100,18 @@ npm install platejs
|
|
|
71
100
|
lists its peers; the CLI installs them with copied components.
|
|
72
101
|
</Callout>
|
|
73
102
|
|
|
74
|
-
###
|
|
103
|
+
### Add the editor color
|
|
75
104
|
|
|
76
|
-
Add the
|
|
105
|
+
Add the editor color to your global stylesheet:
|
|
77
106
|
|
|
78
107
|
```css title="app/globals.css"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
--brand: oklch(0.623 0.214 259.815);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.dark {
|
|
85
|
-
--brand: oklch(0.707 0.165 254.624);
|
|
108
|
+
@theme inline {
|
|
109
|
+
--color-editor-primary: var(--editor-primary, var(--primary));
|
|
86
110
|
}
|
|
87
111
|
```
|
|
88
112
|
|
|
113
|
+
Without shadcn's theme, also set `--editor-primary`, as [Editor color](#editor-color) shows.
|
|
114
|
+
|
|
89
115
|
### Add components
|
|
90
116
|
|
|
91
117
|
With Plate UI's core installed, you can now add individual Plate UI components to build your editor interface. For example, to add the `FixedToolbar` and a `MarkToolbarButton`:
|
|
@@ -122,8 +148,8 @@ Explore the available [UI Components](/docs/components) and [Plugin Components](
|
|
|
122
148
|
|
|
123
149
|
With Plate UI's core installed, proceed to the guide specific to your framework:
|
|
124
150
|
|
|
125
|
-
* **[Next.js Guide](./next)
|
|
126
|
-
* **[React Guide](./react)
|
|
151
|
+
* **[Next.js Guide](./next)**: for server-side rendered applications (Next, Remix, etc.)
|
|
152
|
+
* **[React Guide](./react)**: for single-page applications (Vite, React Router, etc.)
|
|
127
153
|
|
|
128
154
|
</Steps>
|
|
129
155
|
|
package/dist/docs/llms.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Plate docs for platejs@54.0.0-beta.
|
|
1
|
+
# Plate docs for platejs@54.0.0-beta.6
|
|
2
2
|
|
|
3
3
|
These pages match the installed `platejs` version. A `/docs/<path>` link in a page is the file `<path>.md` in this folder when the list below names it, and `/docs` is `index.md`. Read the pages your task needs before you write editor code.
|
|
4
4
|
|
|
@@ -16,11 +16,23 @@ Use feature packages only for the nodes, marks, or behavior you add to the
|
|
|
16
16
|
editor. Plate UI users should start with [Plate UI](/docs/installation/plate-ui)
|
|
17
17
|
instead of rebuilding every component by hand.
|
|
18
18
|
|
|
19
|
+
## Unchanged Imports
|
|
20
|
+
|
|
21
|
+
Plate re-exports Plite's document model with the same bindings. Unless
|
|
22
|
+
[Renamed And Dropped Names](#renamed-and-dropped-names) lists a value, change
|
|
23
|
+
only its import path: `plitejs` becomes `platejs`, and `plitejs/<entrypoint>`
|
|
24
|
+
becomes `platejs/<entrypoint>`. `editor.read`, `editor.update`, `tx`, `NodeApi`
|
|
25
|
+
and the rest of the document API work as before. `platejs/diff`,
|
|
26
|
+
`platejs/history`, `platejs/hyperscript`, `platejs/pagination`,
|
|
27
|
+
`platejs/testing`, `platejs/yjs` and `platejs/yjs/react` re-export their Plite
|
|
28
|
+
entrypoint whole.
|
|
29
|
+
|
|
19
30
|
## Migration Map
|
|
20
31
|
|
|
21
32
|
| Plite surface | Plate surface |
|
|
22
33
|
| --- | --- |
|
|
23
|
-
| `useEditor()` from `plitejs/react
|
|
34
|
+
| `useEditor(options)` from `plitejs/react`, which creates an editor | `useCreateEditor(options)` in React components, or `createEditor(options)` in factories and tests. Plate's `useEditor()` returns the editor from context. |
|
|
35
|
+
| `useEditorContext()` | `useEditor()`. |
|
|
24
36
|
| `<EditorRoot>` plus `<Editable>` | `<EditorRoot>` plus `<EditorContent>`. |
|
|
25
37
|
| `renderElement` / `renderLeaf` switch statements | Plugin components through `.configure({ component })`. |
|
|
26
38
|
| Plite plugins | Constructor `api`, `read`, `selectors`, `update`, native Plite fields, and format mappings built by `defineFormats`. |
|
|
@@ -39,7 +51,7 @@ import { EditorRoot, EditorContent, useCreateEditor } from 'platejs/react';
|
|
|
39
51
|
|
|
40
52
|
const initialValue = [
|
|
41
53
|
{
|
|
42
|
-
children: [{ text: 'Hello
|
|
54
|
+
children: [{ text: 'Hello world.' }],
|
|
43
55
|
type: 'paragraph',
|
|
44
56
|
},
|
|
45
57
|
];
|
|
@@ -121,13 +133,13 @@ const editor = createEditor({
|
|
|
121
133
|
Put a reusable document command under the plugin's `update` contribution. The
|
|
122
134
|
command is available inside `editor.update(...)` under the plugin name.
|
|
123
135
|
|
|
124
|
-
```tsx title="components/editor/
|
|
136
|
+
```tsx title="components/editor/signature-plugin.tsx" showLineNumbers
|
|
125
137
|
import { definePlugin } from 'platejs/react';
|
|
126
138
|
|
|
127
139
|
export const SignaturePlugin = definePlugin('signature', {
|
|
128
140
|
update: ({ tx }) => ({
|
|
129
141
|
insert() {
|
|
130
|
-
tx.text.insert(' -
|
|
142
|
+
tx.text.insert(' - Signed');
|
|
131
143
|
},
|
|
132
144
|
}),
|
|
133
145
|
});
|
|
@@ -243,6 +255,95 @@ export const editor = createEditor({
|
|
|
243
255
|
});
|
|
244
256
|
```
|
|
245
257
|
|
|
258
|
+
## Renamed And Dropped Names
|
|
259
|
+
|
|
260
|
+
These tables list each Plite value that Plate drops, renames, or exports under
|
|
261
|
+
the same name with a different contract, and the types an app imports with
|
|
262
|
+
them. Every other value keeps its binding, as
|
|
263
|
+
[Unchanged Imports](#unchanged-imports) says.
|
|
264
|
+
|
|
265
|
+
### Editor And Plugins
|
|
266
|
+
|
|
267
|
+
| Plite | Plate | Notes |
|
|
268
|
+
| --- | --- | --- |
|
|
269
|
+
| `useEditor(options, deps)` | `useCreateEditor(options, deps)` | Plate's `useEditor()` takes no arguments and returns the editor from context. |
|
|
270
|
+
| `useEditorContext()` | `useEditor()` | |
|
|
271
|
+
| `useOptionalEditorContext()` | `useOptionalEditor()` | |
|
|
272
|
+
| `useCaretEditor()` | `useEditor()` outside `EditorContent` | Outside every editing area, `useEditor()` returns the editor of the root that holds the caret. |
|
|
273
|
+
| `createEditor(options)` | `createEditor(options)` from `platejs`, or from `platejs/react` in React | The options are the same except `clipboardFormatKey`, which Plate refuses. |
|
|
274
|
+
| `definePlugin(name, definition)` | `definePlugin(name, definition)` from `platejs`, or from `platejs/react` in React | The definition fields are the same. The result is a Plate plugin with `.configure()` and `.extend()`, and a `name` key inside the definition throws. |
|
|
275
|
+
| `useCommand(command, options)` | `editor.update.command(command, input)`, with the editor from `useEditor()` | Plate has no `root` or `focus` option for a command. |
|
|
276
|
+
|
|
277
|
+
### Rendering
|
|
278
|
+
|
|
279
|
+
| Plite | Plate | Notes |
|
|
280
|
+
| --- | --- | --- |
|
|
281
|
+
| `Editable` | `EditorContent` | Move `renderElement`, `renderLeaf`, `renderText`, `renderPlaceholder` and `renderVoid` into plugin components. The other props carry over. |
|
|
282
|
+
| `PagedEditable` from `plitejs/pagination/react` | `PagedEditorContent` from `platejs/pagination/react` | The render props move into plugin components, as with `EditorContent`. |
|
|
283
|
+
| `VirtualizedEditable` from `plitejs/react/virtualized` | `VirtualizedEditorContent` from `platejs/react/virtualized` | The render props move into plugin components, as with `EditorContent`. |
|
|
284
|
+
| `EditorPlaceholder` | `placeholder` on `EditorContent`, or `BlockPlaceholderPlugin` for empty blocks | Plate has no `renderPlaceholder`. |
|
|
285
|
+
| `EditorRoot` | `EditorRoot` | `onValueChange` receives the whole document value, `{ children, ... }`, instead of the children array. Plate's `EditorRoot` has no `authorId`, `decorations`, `document` or `root` prop. Pass `userId` to `createEditor`, decorate through a plugin's `decorate`, and set `root` on `EditorContent`. To render another document, create an editor for it with `createEditor({ initialValue })`. |
|
|
286
|
+
| `EditorElement`, `EditorLeaf`, `EditorText` | `EditorElement`, `EditorLeaf`, `EditorText` | Plate's take the props a plugin component receives, so spread them: `<EditorElement {...props}>`. Plite's read the node from context. |
|
|
287
|
+
| `EditorReadOnlyProvider` | `readOnly` on `EditorRoot` or `EditorContent` | |
|
|
288
|
+
| `useClaimEditableDOMCommit`, `setDOMTextSyncRendererCapability`, `setRetainedTextFlowRendererCapability` | None | Plate's renderers call them for every plugin component. |
|
|
289
|
+
|
|
290
|
+
### Hooks
|
|
291
|
+
|
|
292
|
+
| Plite | Plate | Notes |
|
|
293
|
+
| --- | --- | --- |
|
|
294
|
+
| `useEditorSelector(selector, options)` | `useEditorSelector(selector, options)` | The options are `equalityFn` and `shouldUpdate` only. The hook follows the editor of the root that holds the caret. |
|
|
295
|
+
| `useEditorState(selector, options)` | `useEditorState(selector, options)` | There is no `deferred` option. |
|
|
296
|
+
| `useEditorSelection`, `useEditorFocused`, `useEditorComposing`, `useEditorReadOnly` | The same names | The calls are the same. Plate reads the selected editing area. |
|
|
297
|
+
| `useOptionalEditorReadOnly()` | `useEditorReadOnly()` | Plate always returns a boolean. |
|
|
298
|
+
| `useEditorHistory(options)` | `useEditorHistory(options)` | The options are the same. |
|
|
299
|
+
| `useElement<MyElement>()` | `useElement(MyPlugin)` | `useElement()` without arguments still returns the nearest element, and throws outside an element component. |
|
|
300
|
+
| `useOptionalElement()` | None | Call `useElement()` inside an element plugin's component. |
|
|
301
|
+
| `useNodeSelector(selector)` | `useElementSelector(selector)` inside an element component | The selector receives the element. Plate has no hook that selects a node by key. |
|
|
302
|
+
| `useTextSelector(selector)` | None | A text plugin component receives its `text` in props. |
|
|
303
|
+
| `useEditorEditableElement()` | `useEditableRef()` | The ref is `null` before mount and does not rerender when the element mounts. `useEditorMounted()` returns a boolean. |
|
|
304
|
+
|
|
305
|
+
### Types
|
|
306
|
+
|
|
307
|
+
| Plite | Plate | Notes |
|
|
308
|
+
| --- | --- | --- |
|
|
309
|
+
| `EditableProps` | `EditorContentProps` | Plate's `EditableProps` is an internal renderer type. |
|
|
310
|
+
| `PagedEditableProps`, `VirtualizedEditableProps` | `PagedEditorContentProps`, `VirtualizedEditorContentProps` | |
|
|
311
|
+
| `UseEditorOptions` | `CreateEditorOptions` | |
|
|
312
|
+
| `EditorSelectorOptions`, `EditorStateSelectorOptions` | `UseEditorSelectorOptions`, `UseEditorStateOptions` | |
|
|
313
|
+
| `EditorRootProps`, `ValueChangeContext` | The same names | `value` is the whole document value. |
|
|
314
|
+
| `NodeProps` from `plitejs/react` | `NodeProps` from `platejs` | `NodeProps` from `platejs/react` types the props a plugin injects into its node. |
|
|
315
|
+
| `Editor`, `Plugin` | The same names | Plate's take other type parameters, and `Plugin` is the type of a Plate plugin. |
|
|
316
|
+
| `ReactPlugin` | `RuntimeReactPlugin` | |
|
|
317
|
+
|
|
318
|
+
### DOM
|
|
319
|
+
|
|
320
|
+
`platejs/dom` keeps `ariaKeyShortcuts`, `dataTransferFormats`, `domCommands`,
|
|
321
|
+
`DOMResolutionError`, `isHotkey`, `usesAppleDOMHotkeys` and
|
|
322
|
+
`writeDataTransferFragment`. The other `plitejs/dom` values map as follows.
|
|
323
|
+
|
|
324
|
+
| Plite | Plate | Notes |
|
|
325
|
+
| --- | --- | --- |
|
|
326
|
+
| `DOMEditor.focus(editor)` and the other `DOMEditor` methods | `editor.api.dom.focus()` and the other `editor.api.dom` methods | Drop the editor argument. |
|
|
327
|
+
| `getEditorDOMRoot(editor)` | `editor.api.dom.root()` | |
|
|
328
|
+
| `dom` | None | `createEditor` from `platejs/react` installs Plate's DOM plugin. A headless editor adds `DOMPlugin` from `platejs`. |
|
|
329
|
+
| `getDOMClipboardFormatKey`, `writeDOMFragmentData`, `writeDOMRangeData`, `cleanDOMClipboardContents` | `editor.api.dom.clipboard` and a plugin's `dataTransferFormats` | |
|
|
330
|
+
| `Hotkeys` | `Hotkeys` from `platejs` | Plate's set has other members. |
|
|
331
|
+
| `createCompiledHotkeyMatcher`, `Key` | `isHotkey`, or a plugin's `shortcuts` | |
|
|
332
|
+
| `readDOMSelectionRange`, `writeDOMSelection` | None | `EditorContent` reads and writes the DOM selection. |
|
|
333
|
+
| `isEditor`, `isElement`, `isLeaf`, `isNode`, `isString`, `isText`, `isVoid`, `getElements`, `getNodeDataAttributeKeys`, `keyToDataAttribute` | None | They read Plite's DOM data attributes. `isEditor` from `platejs` is a different function that checks an editor object. |
|
|
334
|
+
| `getSelection`, `getActiveElement`, `getDefaultView`, `isDOMNode`, `isDOMElement`, `isDOMText`, `isDOMSelection`, `hasShadowRoot`, `closestShadowAware`, `containsShadowAware`, `isAfter`, `isBefore`, `normalizeDOMPoint`, `isPlainTextOnlyPaste`, `CAN_USE_DOM`, `isGeckoDOMHost`, `TRIPLE_CLICK` | None | Use the DOM API. |
|
|
335
|
+
| `DOMCoverage`, `isTrackedMutation`, `applyStringDiff`, `mergeStringDiffs`, `normalizeStringDiff`, `normalizePoint`, `normalizeRange`, `targetRange`, `verifyDiffState` | None | `EditorContent` owns DOM coverage, mutation tracking and Android input diffs. |
|
|
336
|
+
|
|
337
|
+
### Review And Annotations
|
|
338
|
+
|
|
339
|
+
| Plite | Plate | Notes |
|
|
340
|
+
| --- | --- | --- |
|
|
341
|
+
| `authored({ authorId })` from `plitejs/authored` | `AuthoredPlugin` from `platejs/authored` in `plugins` | The author is the editor's `userId`, or the `authorId` of a view from `createEditorView`. |
|
|
342
|
+
| `authoredRecords` | None | `AuthoredPlugin` installs it. |
|
|
343
|
+
| `createAuthoredPlugin` | None | It is Plite's test helper with fixed ids and clock. |
|
|
344
|
+
| `AuthoredPlugin` type | `typeof AuthoredPlugin` | Plate's `AuthoredPlugin` is the plugin value. |
|
|
345
|
+
| `createAnnotationStore` from `plitejs/annotations` | `useAnnotationStore(editor, annotations, options)` from `platejs/react` | Plate has no headless annotation store. The annotation types move to `platejs/react`. |
|
|
346
|
+
|
|
246
347
|
## Related
|
|
247
348
|
|
|
248
349
|
- [Editor](/docs/editor) for editor creation options.
|
|
@@ -292,7 +292,9 @@ editor.update.highlight.clear({ at: bodyBlock }); // clears one primary-document
|
|
|
292
292
|
|
|
293
293
|
A call whose targets sit in two roots throws before the method runs.
|
|
294
294
|
`txSelection` and `txOnly` methods, and a call that passes a function, run in
|
|
295
|
-
the caller's root.
|
|
295
|
+
the caller's root. A `txLocate` method called with a node key or live node that
|
|
296
|
+
no root holds does nothing and returns `undefined`, even when the call passes a
|
|
297
|
+
function.
|
|
296
298
|
|
|
297
299
|
## Declare feature format mappings
|
|
298
300
|
|
package/dist/docs/roots.md
CHANGED
|
@@ -274,6 +274,18 @@ const SyncedBlock = ({ attributes, element, slots }) => (
|
|
|
274
274
|
);
|
|
275
275
|
```
|
|
276
276
|
|
|
277
|
+
Undo and redo keys pressed in an editable move focus to the view that made the
|
|
278
|
+
step, when that view shows another root inside the same `<Editable>`. Type in
|
|
279
|
+
the second of two copies of a synced block, click the page and press Mod+Z.
|
|
280
|
+
Focus goes to the second copy, and the caret goes back to where it was before
|
|
281
|
+
that typing. Focus stays where the key was pressed when the view that made the
|
|
282
|
+
step is gone, hidden or read-only, when that view is outside the `<Editable>`,
|
|
283
|
+
or when the step's selection ran from one view into another. It also stays for
|
|
284
|
+
a step whose plugin history effect settles after the replay, such as creating a
|
|
285
|
+
comment thread. A history control from `useEditorHistory`, an external control
|
|
286
|
+
wired to history and the browser handle's `undo()` never move focus to the view
|
|
287
|
+
that made the step.
|
|
288
|
+
|
|
277
289
|
A root whose blocks are selected as whole objects, such as a board's shapes,
|
|
278
290
|
can give focus to an element of its own instead of its editable. Pass
|
|
279
291
|
`nodeSelectionFocus`, a ref to that element, and give the element
|
|
@@ -291,7 +303,12 @@ a focus call replaces it, focus falls to the page. An element that inherits
|
|
|
291
303
|
editing runs the editable's own focus handler, which in Firefox moves focus to
|
|
292
304
|
the editable. Unless the element is a control, such as a button, the editor
|
|
293
305
|
reads no keys from it, so it must handle the keys it needs, such as undo and
|
|
294
|
-
redo through the `onKeyDown` of `useEditorHistory`.
|
|
306
|
+
redo through the `onKeyDown` of `useEditorHistory`. An undo or redo key leaves
|
|
307
|
+
focus where it was pressed when the view that made the step, or the view where
|
|
308
|
+
the key was pressed, renders inside a slot that passes `nodeSelectionFocus`. So
|
|
309
|
+
an undo pressed in the document of a step made on a board leaves focus and the
|
|
310
|
+
caret in the document. An undo pressed on the board of a step made in the
|
|
311
|
+
document leaves them on the board.
|
|
295
312
|
|
|
296
313
|
```tsx
|
|
297
314
|
const Board = ({ attributes, children, slots }) => {
|
package/dist/docs/selection.md
CHANGED
|
@@ -60,6 +60,11 @@ editor.update.selection.setNodes([imagePath], { mode: 'object' });
|
|
|
60
60
|
editor.read.selection.nodeMode(); // 'object'
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
+
Press `Escape` to leave a node selection. The editor collapses it to a caret at
|
|
64
|
+
the end of the focus block, or right after a selected object. A menu, toolbar
|
|
65
|
+
or plugin keydown handler that handles `Escape` first keeps the selection, and
|
|
66
|
+
so does a read-only editor.
|
|
67
|
+
|
|
63
68
|
Use [Editor Methods](/docs/editor-methods) for editor access inside React and
|
|
64
69
|
[Selection API](/docs/api/selection) for the complete query and
|
|
65
70
|
validation contracts.
|