platejs 54.0.0-beta.4 → 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-DrUahdTc.d.ts → AIChatRequestContext-BYpGufVe.d.ts} +2 -2
- package/dist/{BaseSuggestionPlugin-_7Ka6nY3.d.ts → BaseSuggestionPlugin-C52LR8RN.d.ts} +4 -4
- package/dist/{PlateStatic-D3Cb-QwH.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-Dr0OYZIE.d.ts → combobox-DgYdu5mZ.d.ts} +2 -2
- package/dist/{comparison-types-DdwE6mYq-BogsHoUO.d.ts → comparison-types-DBQFu7Rt-DYc2TC2H.d.ts} +1 -1
- package/dist/compiler/index.d.ts +2 -2
- package/dist/{core-BqR-fEDp.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/dom.md +5 -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 +279 -33
- package/dist/docs/installation/plate-ui.md +40 -14
- package/dist/docs/link.md +1 -1
- package/dist/docs/llms.txt +1 -1
- package/dist/docs/media.md +88 -2
- package/dist/docs/migration/plite-to-plate.md +105 -4
- package/dist/docs/plugin-input-rules.md +4 -3
- package/dist/docs/plugin-methods.md +3 -1
- package/dist/docs/roots.md +33 -10
- 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/code-block/lib/BaseCodeBlockPlugin.js +14 -18
- package/dist/features/combobox/index.d.ts +2 -2
- package/dist/features/comments/BaseCommentsPlugin.js +6 -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 +3 -3
- package/dist/features/field/lib/BaseFieldPlugin.js +109 -40
- package/dist/features/field/lib/applyFieldValues.js +313 -83
- package/dist/features/field/lib/fieldRules.internal.js +92 -4
- 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/media/lib/media-embed/BaseMediaEmbedPlugin.js +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-eT2ZGDAj.d.ts → htmlTypes-8IFX0ezP.d.ts} +1 -1
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-C9Fu-P4E.d.ts → index-AOVPovEr.d.ts} +156 -18
- package/dist/{index-BTx5oK7k.d.ts → index-B4oeyc99.d.ts} +1 -1
- package/dist/{index-BXwU9QH6.d.ts → index-BAz_KJSV.d.ts} +2 -2
- package/dist/{index-B8-5Sr7I.d.ts → index-BBsiQIzw.d.ts} +2 -2
- package/dist/{index-DNQXzU-X.d.ts → index-BIP1GoWI.d.ts} +1 -1
- package/dist/{index-B8QJDAmG.d.ts → index-BTFrh2Cz.d.ts} +2 -2
- package/dist/{index-M781pyx9.d.ts → index-BapA_uvI.d.ts} +4 -4
- package/dist/{index-DPowErHa.d.ts → index-BbsVGwn8.d.ts} +22 -15
- package/dist/{index-DShbzec2.d.ts → index-BcuSI8EM.d.ts} +6 -3
- package/dist/{index-DwWQVwQt.d.ts → index-BfHCmKG3.d.ts} +41 -16
- package/dist/{index-BWPcE4ac-Cto_IsNs.d.ts → index-BvQzYVAW-Jvz2iG8B.d.ts} +1 -1
- package/dist/{index-BkwR-5hH.d.ts → index-C-5w6252.d.ts} +3 -3
- package/dist/{index-JWgwL5l3.d.ts → index-Cp0QfjUV.d.ts} +3 -3
- package/dist/{index-B7moSod7.d.ts → index-CrUMAwqm.d.ts} +5 -1
- package/dist/{index-B33E1CRJ.d.ts → index-D2w_9_tb.d.ts} +3 -3
- package/dist/{index-DYdObeFQ.d.ts → index-DE1Mcccg.d.ts} +3 -3
- package/dist/{index-CpY7Xnxw.d.ts → index-DFMkcY5V.d.ts} +4 -4
- package/dist/{index-BXjLmx1n-CXk17buG.d.ts → index-DHt8nZQ6-NUTahb8N.d.ts} +111 -70
- package/dist/{index-BsV2McRr.d.ts → index-DM6z4D7q.d.ts} +5 -5
- package/dist/{index-Cob_iBdu.d.ts → index-DUk2VZ_1.d.ts} +3 -3
- package/dist/{index-d7io3MzC.d.ts → index-DbPoiwq_.d.ts} +3 -3
- package/dist/{index-Ca48r1ng.d.ts → index-Dh7pWHZo.d.ts} +3 -3
- package/dist/{index-Dq3Jlj8O-BJ6NxZm0.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/internal/utils/vscodeClipboard.js +11 -0
- 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/MarkdownPlugin.js +2 -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 +56 -18
- 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 +17 -7
- 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-BGohy8vH.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
|
|
|
@@ -14,12 +14,15 @@ The demo is a lease template for a landlord and a tenant. Insert a field from th
|
|
|
14
14
|
|
|
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
|
-
- A condition that names another field by its `fieldId` and tests that field's value.
|
|
18
|
-
-
|
|
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.
|
|
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.
|
|
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.
|
|
21
24
|
- HTML and Markdown that keep every property, and Word export that keeps each answer and reports the settings it drops.
|
|
22
|
-
- A field chip with a settings popover, an insert menu and a static renderer in the registry UI.
|
|
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.
|
|
23
26
|
|
|
24
27
|
</PackageInfo>
|
|
25
28
|
|
|
@@ -71,7 +74,7 @@ export function FieldToolbar() {
|
|
|
71
74
|
|
|
72
75
|
### Add static rendering
|
|
73
76
|
|
|
74
|
-
`BaseFieldKit` renders each field
|
|
77
|
+
`BaseFieldKit` renders each field for read-only output with `platejs/static`. A field shows its answer in place: a choice as its option's label, a checkbox as a ticked or empty box, and a number as written, `0` included. A field other than a checkbox shows a blank line when it has no filled answer. An app makes the PDF of a filled document from this output, as [Print the filled document](#print-the-filled-document) shows.
|
|
75
78
|
|
|
76
79
|
_Registry item `field-static`: `npx shadcn@latest add @plate/field-static`._
|
|
77
80
|
|
|
@@ -129,6 +132,7 @@ A field sits inside a paragraph, like a date or a mention.
|
|
|
129
132
|
"kind": "text",
|
|
130
133
|
"role": "tenant",
|
|
131
134
|
"label": "Tenant name",
|
|
135
|
+
"name": "tenant_name",
|
|
132
136
|
"required": true,
|
|
133
137
|
"children": [{ "text": "" }]
|
|
134
138
|
},
|
|
@@ -143,11 +147,12 @@ A field sits inside a paragraph, like a date or a mention.
|
|
|
143
147
|
| `fieldId` | `string` | Unique in the document. A new field gets a random `nanoid`. |
|
|
144
148
|
| `kind` | `FieldKind` | `'text'`, `'number'`, `'date'`, `'checkbox'`, `'choice'` or `'signature'`. Required. |
|
|
145
149
|
| `role` | `string` | The role that fills the field, such as `'tenant'`. Required. |
|
|
146
|
-
| `label` | `string` | Required. The chip shows it, and
|
|
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). |
|
|
152
|
+
| `required` | `boolean` | Marks a field that needs a filled answer while it applies. `applyFieldValues` refuses a submission that leaves it unfilled. |
|
|
148
153
|
| `defaultValue` | `FieldValue` | A value of the field's kind. |
|
|
149
154
|
| `options` | `FieldOption[]` | Choice fields only. Each option is `{ value, label }`, and no two share a `value`. |
|
|
150
|
-
| `value` | `FieldValue` | The answer. A field without one
|
|
155
|
+
| `value` | `FieldValue` | The answer. A field is unfilled without one, or when `fillsField` says its answer does not fill it. |
|
|
151
156
|
| `condition` | `FieldCondition` | `{ ref, test, value? }`, see [Conditions](#conditions). |
|
|
152
157
|
| `children` | `[{ text: '' }]` | Required child of an inline void element. |
|
|
153
158
|
|
|
@@ -166,14 +171,36 @@ Each kind fixes the shape of its value and the tests a condition on it may use.
|
|
|
166
171
|
|
|
167
172
|
A choice stores the option's `value`, so renaming an option's `label` keeps every answer and condition that names it.
|
|
168
173
|
|
|
174
|
+
`fillsField(field, value)` from `platejs/field` says whether a value is a filled answer for a field. `required` and the `filled` and `blank` tests read the same rule. A filled answer is a ticked checkbox, or a value that fits the field's kind. A text or signature answer also needs a character that JavaScript's `\s` does not match. So `false`, an empty text and a text of spaces fit a field but do not fill it, and `0` fills a number field.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { fillsField } from 'platejs/field';
|
|
178
|
+
|
|
179
|
+
fillsField({ kind: 'text' }, ' '); // false
|
|
180
|
+
fillsField({ kind: 'number' }, 0); // true
|
|
181
|
+
fillsField({ kind: 'checkbox' }, false); // false
|
|
182
|
+
```
|
|
183
|
+
|
|
169
184
|
## Roles
|
|
170
185
|
|
|
171
186
|
Each field names the role that fills it, such as `landlord` or `tenant`. A role is any string. Plate stores it and never checks who a user is. Your app maps each person to a role, as it maps each comment to its author.
|
|
172
187
|
|
|
173
|
-
A [fill-only view](#fill-as-one-role) stops one role from changing another role's field, or the text around it, in that editor. An app that collects answers from several people still checks each
|
|
188
|
+
A [fill-only view](#fill-as-one-role) stops one role from changing another role's field, or the text around it, in that editor. An app that collects answers from several people still checks each role's answers on its server, with [`applyFieldValues`](#apply-answers-on-the-server).
|
|
174
189
|
|
|
175
190
|
The settings popover offers the roles the document's fields already use, and takes a new one.
|
|
176
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
|
+
|
|
177
204
|
## Insert and update
|
|
178
205
|
|
|
179
206
|
`insert` takes a field's settings and returns its new `fieldId`. Its second argument takes node insert options, such as `at` and `select`.
|
|
@@ -181,17 +208,18 @@ The settings popover offers the roles the document's fields already use, and tak
|
|
|
181
208
|
```tsx
|
|
182
209
|
import { BaseFieldPlugin } from 'platejs/field';
|
|
183
210
|
|
|
184
|
-
editor.update(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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',
|
|
189
217
|
});
|
|
190
218
|
```
|
|
191
219
|
|
|
192
|
-
`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.
|
|
193
221
|
|
|
194
|
-
`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.
|
|
195
223
|
|
|
196
224
|
```tsx
|
|
197
225
|
editor.update((tx) => {
|
|
@@ -203,6 +231,7 @@ editor.update((tx) => {
|
|
|
203
231
|
|
|
204
232
|
- no field holds `fieldId`;
|
|
205
233
|
- a setting the patch names does not fit the field's kind;
|
|
234
|
+
- the patch names a `name` the name rule refuses;
|
|
206
235
|
- the patch removes `kind`, `role` or `label`, or names `fieldId`;
|
|
207
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.
|
|
208
237
|
|
|
@@ -210,7 +239,7 @@ A patch that changes `kind` or `options` also drops each value, default and opti
|
|
|
210
239
|
|
|
211
240
|
## Conditions
|
|
212
241
|
|
|
213
|
-
A condition says when a field applies. It applies when the field whose `fieldId` is `ref` passes `test`. Every test but `filled` and `blank` compares against `value`, which takes the shape of the named field's value. The demo's Pet name field applies when the Pets choice is `yes`:
|
|
242
|
+
A condition says when a field applies. It applies when the field whose `fieldId` is `ref` passes `test`. Every test but `filled` and `blank` compares against `value`, which takes the shape of the named field's value. The demo's Pet name field, which the tenant fills, applies when the landlord's Pets allowed choice is `yes`:
|
|
214
243
|
|
|
215
244
|
```tsx
|
|
216
245
|
editor.update((tx) => {
|
|
@@ -220,13 +249,20 @@ editor.update((tx) => {
|
|
|
220
249
|
});
|
|
221
250
|
```
|
|
222
251
|
|
|
223
|
-
The popover's Show when list offers the field the condition names and every other field whose conditions do not lead back to this one. Its test list offers only the tests that field's kind takes.
|
|
252
|
+
The popover's Show when list offers the field the condition names and every other field whose conditions do not lead back to this one. Its test list offers only the tests that field's kind takes.
|
|
253
|
+
|
|
254
|
+
The editor never hides a field. A field whose condition fails is skipped. It needs no answer even when it is `required`, and `applyFieldValues` refuses a filled answer for it. A condition tests the answer of the field it names:
|
|
255
|
+
|
|
256
|
+
- `equals` holds when the answer is `value`, and `not-equals` when it is not, no answer included.
|
|
257
|
+
- `above` and `below` compare numbers, and ISO dates as dates. Neither holds without an answer.
|
|
258
|
+
- An answer that does not fit its field's kind counts as no answer, and so does the answer of a field that is skipped itself.
|
|
259
|
+
- A checkbox with no answer reads as `false` once its role is done answering. In the editor, that holds for a checkbox of the role that fills the field being read. In `applyFieldValues`, it holds once the checkbox's role has submitted.
|
|
224
260
|
|
|
225
261
|
`update` refuses a condition that would close a loop, such as A naming B while B names A, or a field naming itself. A new test or value on a field of a loop passes. A loop can still come from a loaded document, a plain node write or two peers' updates made at the same time, and each of its fields then reports `condition-loop`.
|
|
226
262
|
|
|
227
263
|
## Read fields and their problems
|
|
228
264
|
|
|
229
|
-
`read.field(fieldId)` returns the field that holds an id, in any root, or `null`. It looks up that field, then one field for each condition it follows along the chain. `read.fields()` returns every field of the document in reading order. Each read is a `FieldRead`: `{ fieldId, node, problems }`.
|
|
265
|
+
`read.field(fieldId)` returns the field that holds an id, in any root, or `null`. It looks up that field, then one field for each condition it follows along the chain. `read.fields()` returns every field of the document in reading order. Each read is a `FieldRead`: `{ applies, fieldId, node, problems }`.
|
|
230
266
|
|
|
231
267
|
```tsx
|
|
232
268
|
import { BaseFieldPlugin } from 'platejs/field';
|
|
@@ -235,6 +271,7 @@ const fields = editor.plugin(BaseFieldPlugin).read;
|
|
|
235
271
|
|
|
236
272
|
const tenant = fields.field(tenantId);
|
|
237
273
|
const broken = fields.fields().filter((field) => field.problems.length > 0);
|
|
274
|
+
const skipped = fields.fields().filter((field) => field.applies === false);
|
|
238
275
|
```
|
|
239
276
|
|
|
240
277
|
| Problem | When |
|
|
@@ -243,16 +280,27 @@ const broken = fields.fields().filter((field) => field.problems.length > 0);
|
|
|
243
280
|
| `unsupported-test` | The kind of the field its condition names does not take the condition's test. |
|
|
244
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. |
|
|
245
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. |
|
|
285
|
+
|
|
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.
|
|
287
|
+
|
|
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:
|
|
289
|
+
|
|
290
|
+
- `true` for a field with no condition, a condition that has a problem or one in a loop, and a condition that holds.
|
|
291
|
+
- `false` for a skipped field, whose condition fails.
|
|
292
|
+
- `null` while it depends on an answer another role has not given, such as the tenant's Pet name before the landlord picks Pets allowed. Only `applyFieldValues` knows which roles have submitted, so the editor reads such a field as waiting.
|
|
246
293
|
|
|
247
|
-
|
|
294
|
+
A field whose condition names a skipped field is decided, even when another role owns that field.
|
|
248
295
|
|
|
249
|
-
In React, `useFieldRead(fieldId)` from `platejs/field/react` reads one field and
|
|
296
|
+
In React, `useFieldRead(fieldId)` from `platejs/field/react` reads one field, its problems and whether it applies. A commit that changes an element reads it again, and the component renders again only when the field, its problems or `applies` changed. The registry chip uses it to show a warning when the field its condition names is deleted, and an undo clears the warning. The chip also mutes a field whose `applies` is `false` and marks it skipped. The chip of a field that waits is not muted.
|
|
250
297
|
|
|
251
298
|
```tsx
|
|
252
299
|
import { useFieldRead } from 'platejs/field/react';
|
|
253
300
|
|
|
254
301
|
const field = useFieldRead(element.fieldId);
|
|
255
302
|
const problems = field?.problems ?? [];
|
|
303
|
+
const skipped = field?.applies === false;
|
|
256
304
|
```
|
|
257
305
|
|
|
258
306
|
## Fill as one role
|
|
@@ -299,13 +347,205 @@ A peer's change passes whole. Every commit tagged `collaboration` passes, so col
|
|
|
299
347
|
|
|
300
348
|
The fill check runs in the field plugin's `activate`, and the undo step boundary in its `corrections`. A plugin that extends the field plugin with its own `activate` or `corrections` replaces them, so put that work in a companion plugin.
|
|
301
349
|
|
|
302
|
-
The fill check runs in the person's browser, where anyone can run their own code. Your server assigns each person's role and checks each
|
|
350
|
+
The fill check runs in the person's browser, where anyone can run their own code. Your server assigns each person's role and checks each submission with `applyFieldValues`.
|
|
351
|
+
|
|
352
|
+
## Submit answers
|
|
353
|
+
|
|
354
|
+
A client reads one role's answers from the editor and posts them. The server checks every role's answers against the template it saved, and keeps the filled document.
|
|
355
|
+
|
|
356
|
+
### Read a role's answers
|
|
357
|
+
|
|
358
|
+
`read.submission(role)` returns a `FieldSubmission`, `{ role, values }`. `values` holds the `value` of each field of the role that has one, keyed by `fieldId`.
|
|
359
|
+
|
|
360
|
+
```tsx
|
|
361
|
+
import { FieldPlugin } from 'platejs/field/react';
|
|
362
|
+
|
|
363
|
+
const submission = editor.plugin(FieldPlugin).read.submission('tenant');
|
|
364
|
+
// { role: 'tenant', values: { tenant: 'Grace Hopper', 'pet-name': 'Milo', rules: true } }
|
|
365
|
+
```
|
|
366
|
+
|
|
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.
|
|
368
|
+
|
|
369
|
+
### Apply answers on the server
|
|
370
|
+
|
|
371
|
+
`applyFieldValues(template, submissions, options?)` from `platejs/field` checks each role's answers and builds the filled document. It imports no React and checks each submission's shape itself, so a server passes parsed JSON straight in. In this route, `frozenTemplate` is the template your app saved, `accepted` holds the submissions it accepted before, and `saveFilled` stores the result.
|
|
372
|
+
|
|
373
|
+
```ts
|
|
374
|
+
import { applyFieldValues } from 'platejs/field';
|
|
375
|
+
|
|
376
|
+
const result = applyFieldValues(frozenTemplate, [...accepted, submission]);
|
|
377
|
+
|
|
378
|
+
if (!result.ok) {
|
|
379
|
+
return Response.json({ refusals: result.refusals }, { status: 400 });
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
await saveFilled(result.document);
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
- `template` is the authored document as your app saved it, with its `fieldId`s and no answers, so the fill view and `applyFieldValues` start from the same ids. It takes a `Value` or a document with named roots, and `result.document` has the same shape. `applyFieldValues` reads fields in the main root and each named root, never in `meta` or records.
|
|
386
|
+
- `submissions` lists each role's submission in the order the roles submitted. Each one is checked against the roles before it plus its own answers.
|
|
387
|
+
- `options.type` names the field element's type when your app renamed it with `schema.override`. It defaults to `field`.
|
|
388
|
+
|
|
389
|
+
The filled document is the template with each accepted answer set as its field's `value`. A default stays a setting and never becomes an answer.
|
|
390
|
+
|
|
391
|
+
On success, `pending` lists each role that has not submitted and holds a required field that applies or waits. It also lists the role whose answer each such waiting field needs next. An optional field never puts a role in `pending`. The demo shows `pending` as Waiting on.
|
|
392
|
+
|
|
393
|
+
### Refusals
|
|
394
|
+
|
|
395
|
+
On a refusal, `result` is `{ ok: false, refusals }` with at least one refusal. When the template has refusals, the result lists all of them and checks no submission. Otherwise it lists the refusals of the first submission that has any.
|
|
396
|
+
|
|
397
|
+
| Code | When |
|
|
398
|
+
|------|------|
|
|
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. |
|
|
400
|
+
| `invalid-submission` | A submission is not an object with a `role` string and a `values` object. The refusal names its `index`. |
|
|
401
|
+
| `duplicate-role` | A role already in the list submits again. |
|
|
402
|
+
| `unknown-role` | The role owns no field. |
|
|
403
|
+
| `unknown-field` | An answer names no field of the template. |
|
|
404
|
+
| `wrong-role` | An answer is for another role's field. |
|
|
405
|
+
| `invalid-value` | An answer does not fit its field. |
|
|
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. |
|
|
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. |
|
|
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.
|
|
412
|
+
|
|
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
|
+
```
|
|
424
|
+
|
|
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.
|
|
426
|
+
|
|
427
|
+
A template where two roles each wait on the other passes, because a third role's answer can end the wait by making a field along the chain skip. While both fields still wait, the role that submits first is refused as `waiting` on the other.
|
|
428
|
+
|
|
429
|
+
### Print the filled document
|
|
430
|
+
|
|
431
|
+
Render the filled document with `BaseFieldKit` through `platejs/static`, and make its PDF from that output. Static output shows a field other than a checkbox as a blank line when it has no filled answer, while `editor.api.html.serialize()` writes the label in brackets for a field with no answer.
|
|
432
|
+
|
|
433
|
+
```tsx
|
|
434
|
+
import { createEditor } from 'platejs';
|
|
435
|
+
import { renderStaticHtml } from 'platejs/static';
|
|
436
|
+
|
|
437
|
+
import { BaseFieldKit } from '@/components/editor/field-static';
|
|
438
|
+
|
|
439
|
+
const filled = createEditor({
|
|
440
|
+
initialValue: result.document,
|
|
441
|
+
plugins: [
|
|
442
|
+
// ...otherPlugins,
|
|
443
|
+
...BaseFieldKit,
|
|
444
|
+
],
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
const { data } = await renderStaticHtml(filled);
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
[Static Rendering](/docs/static) covers `EditorStatic` and `renderStaticHtml`.
|
|
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`.
|
|
303
542
|
|
|
304
543
|
## Copy and paste
|
|
305
544
|
|
|
306
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:
|
|
307
546
|
|
|
308
|
-
- 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.
|
|
309
549
|
- A copied condition whose field was not copied, or did not land, keeps naming the original.
|
|
310
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.
|
|
311
551
|
- A paste into another document gets new ids too.
|
|
@@ -316,10 +556,10 @@ In Suggesting mode, a change from a field to a mention shows the field as delete
|
|
|
316
556
|
|
|
317
557
|
## HTML
|
|
318
558
|
|
|
319
|
-
`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:
|
|
320
560
|
|
|
321
561
|
```html
|
|
322
|
-
<p>Pets? <span data-field-id="pets" data-field-kind="choice" data-field-label="Pets" data-field-options="[{"label":"Yes","value":"yes"},{"label":"No","value":"no"}]" data-field-role="
|
|
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>
|
|
323
563
|
```
|
|
324
564
|
|
|
325
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.
|
|
@@ -331,7 +571,7 @@ The demo's HTML panel serializes with `lossPolicy: 'allow'`, because the date el
|
|
|
331
571
|
Markdown writes each field as a `<field>` tag with every property, the `fieldId` and the condition included:
|
|
332
572
|
|
|
333
573
|
```md
|
|
334
|
-
Pets? <field kind="choice" label="Pets" options="[{"label":"Yes","value":"yes"},{"label":"No","value":"no"}]" role="
|
|
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" />
|
|
335
575
|
```
|
|
336
576
|
|
|
337
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.
|
|
@@ -349,7 +589,7 @@ const dropped = result.diagnostics.filter(
|
|
|
349
589
|
);
|
|
350
590
|
```
|
|
351
591
|
|
|
352
|
-
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.
|
|
353
593
|
|
|
354
594
|
Plain text, through `serializePlainText` from `platejs`, writes the same text as Word.
|
|
355
595
|
|
|
@@ -360,11 +600,17 @@ Plain text, through `serializePlainText` from `platejs`, writes the same text as
|
|
|
360
600
|
| `BaseFieldPlugin` | `platejs/field` | Headless inline void field plugin. |
|
|
361
601
|
| `FieldPlugin` | `platejs/field/react` | React field plugin. |
|
|
362
602
|
| `tx.plugin(BaseFieldPlugin).insert(settings, options?)` | `BaseFieldPlugin` update | Inserts a field and returns its `fieldId`. |
|
|
363
|
-
| `tx.plugin(BaseFieldPlugin).update(fieldId, patch)` | `BaseFieldPlugin` update | Changes a field's settings or value. |
|
|
364
|
-
| `editor.plugin(BaseFieldPlugin).read.field(fieldId)` | `BaseFieldPlugin` read | The field that holds an id, with its problems, or `null`. |
|
|
365
|
-
| `editor.plugin(BaseFieldPlugin).read.fields()` | `BaseFieldPlugin` read | Every field in reading order, with its problems. |
|
|
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. |
|
|
604
|
+
| `editor.plugin(BaseFieldPlugin).read.field(fieldId)` | `BaseFieldPlugin` read | The field that holds an id, with its problems and whether it applies, or `null`. |
|
|
605
|
+
| `editor.plugin(BaseFieldPlugin).read.fields()` | `BaseFieldPlugin` read | Every field in reading order, with its problems and whether it applies. |
|
|
606
|
+
| `editor.plugin(BaseFieldPlugin).read.submission(role)` | `BaseFieldPlugin` read | The values of one role's fields, keyed by `fieldId`, to pass to `applyFieldValues`. |
|
|
366
607
|
| `fillRole` | `BaseFieldPlugin` state | The role this editor fills as, or `null` while authoring. Set it through `initialState` or `editor.plugin(FieldPlugin).store.set`. |
|
|
367
|
-
| `useFieldRead(fieldId)` | `platejs/field/react` | Reads one field and
|
|
608
|
+
| `useFieldRead(fieldId)` | `platejs/field/react` | Reads one field, its problems and whether it applies, and renders again when any of them changes. |
|
|
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`. |
|
|
368
613
|
| `fitsField(field, value)` | `platejs/field` | Whether a value fits a field's kind and options. |
|
|
614
|
+
| `fillsField(field, value)` | `platejs/field` | Whether a value is a filled answer for a field. |
|
|
369
615
|
| `FIELD_TESTS` | `platejs/field` | The tests a condition may use on each kind. |
|
|
370
|
-
| `FieldElement`, `FieldSettings`, `FieldPatch`, `FieldRead`, `FieldCondition`, `FieldProblem`, `FieldKind`, `FieldTest`, `FieldValue`, `FieldOption` | `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/link.md
CHANGED
|
@@ -8,7 +8,7 @@ _Example `link-demo` in the Plate repository: `apps/www/src/registry/examples/de
|
|
|
8
8
|
|
|
9
9
|
- Insert, edit, and remove hyperlinks.
|
|
10
10
|
- Markdown shortcut: type `[text](url)` and close with `)` to turn it into a link.
|
|
11
|
-
- Plain URL autolink: paste a URL, or type a URL then press space or `Enter`.
|
|
11
|
+
- Plain URL autolink: paste a URL, or type a URL then press space or `Enter`. With `MediaKit`, a video or post link pasted alone on an empty line lands as a link. Then an embed of that link goes in above the line, and the line empties, as [Media](/docs/media#input-rules) describes.
|
|
12
12
|
|
|
13
13
|
</PackageInfo>
|
|
14
14
|
|
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
|
|