platejs 54.0.0-beta.2 → 54.0.0-beta.4

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.
Files changed (255) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +56 -0
  3. package/dist/{AIChatRequestContext-BMVWhfPV.d.ts → AIChatRequestContext-DrUahdTc.d.ts} +2 -2
  4. package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-_7Ka6nY3.d.ts} +7 -3
  5. package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-D3Cb-QwH.d.ts} +7 -7
  6. package/dist/ai/index.d.ts +1 -1
  7. package/dist/ai/react/AIChatPlugin.js +113 -78
  8. package/dist/ai/react/CopilotPlugin.js +1 -1
  9. package/dist/ai/react/index.d.ts +23 -16
  10. package/dist/authored/index.d.ts +4 -4
  11. package/dist/code-block/codemirror/createCodeMirrorAdapter.js +12 -9
  12. package/dist/code-block/codemirror/index.d.ts +1 -1
  13. package/dist/{combobox-DkBGgyd3.d.ts → combobox-Dr0OYZIE.d.ts} +2 -2
  14. package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-DdwE6mYq-BogsHoUO.d.ts} +10 -2
  15. package/dist/compiler/index.d.ts +2 -2
  16. package/dist/{core-BJG8l_mk.d.ts → core-BqR-fEDp.d.ts} +493 -116
  17. package/dist/diff/index.d.ts +2 -2
  18. package/dist/docs/ai.md +4 -3
  19. package/dist/docs/api/core/plate-components.md +0 -19
  20. package/dist/docs/api/core/plate-controller.md +5 -3
  21. package/dist/docs/api/core/plate-plugin.md +3 -0
  22. package/dist/docs/api/core/plate-store.md +3 -3
  23. package/dist/docs/api/core.md +45 -5
  24. package/dist/docs/api/dom.md +11 -4
  25. package/dist/docs/api/editor-transforms.md +2 -1
  26. package/dist/docs/api/react-hooks.md +45 -13
  27. package/dist/docs/authored-changes.md +9 -4
  28. package/dist/docs/basic-blocks.md +42 -29
  29. package/dist/docs/block-placeholder.md +4 -2
  30. package/dist/docs/blockquote.md +5 -3
  31. package/dist/docs/board.md +118 -10
  32. package/dist/docs/code-block.md +47 -0
  33. package/dist/docs/comment.md +2 -2
  34. package/dist/docs/discussion.md +1 -1
  35. package/dist/docs/document-model.md +15 -3
  36. package/dist/docs/docx.md +1 -1
  37. package/dist/docs/dom-coverage.md +5 -0
  38. package/dist/docs/editor.md +50 -4
  39. package/dist/docs/examples/editable-voids.md +2 -3
  40. package/dist/docs/external-text.md +2 -0
  41. package/dist/docs/field.md +370 -0
  42. package/dist/docs/find.md +9 -6
  43. package/dist/docs/form.md +2 -0
  44. package/dist/docs/heading.md +6 -0
  45. package/dist/docs/installation/manual.md +0 -4
  46. package/dist/docs/link.md +3 -3
  47. package/dist/docs/llms.txt +4 -2
  48. package/dist/docs/markdown.md +270 -14
  49. package/dist/docs/plugin-components.md +13 -10
  50. package/dist/docs/plugin-input-rules.md +66 -15
  51. package/dist/docs/prompt-editor.md +205 -0
  52. package/dist/docs/roots.md +8 -6
  53. package/dist/docs/rtl.md +6 -4
  54. package/dist/docs/selection.md +7 -4
  55. package/dist/docs/suggestion.md +1 -1
  56. package/dist/docs/toolbar.md +26 -30
  57. package/dist/docs/upload.md +106 -17
  58. package/dist/docx/export/index.d.ts +3 -3
  59. package/dist/docx/export/lib/docxStaticComponents.js +12 -2
  60. package/dist/docx/export/lib/exportDocx.js +46 -17
  61. package/dist/docx/export/lib/internal/xml-builder.js +11 -16
  62. package/dist/docx/export/lib/reviewPart.js +1 -1
  63. package/dist/docx/export/lib/reviewProjection.js +52 -10
  64. package/dist/docx/import/index.d.ts +4 -4
  65. package/dist/docx/paste/index.d.ts +4 -4
  66. package/dist/dom/index.d.ts +1 -6
  67. package/dist/dom/plite-dom.internal.js +2 -2
  68. package/dist/excalidraw/index.d.ts +3 -2
  69. package/dist/excalidraw/react/index.d.ts +3 -2
  70. package/dist/facade.js +2 -2
  71. package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +13 -5
  72. package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +32 -10
  73. package/dist/features/board/index.d.ts +2 -2
  74. package/dist/features/board/lib/BaseBoardPlugin.js +14 -1
  75. package/dist/features/board/lib/boardStroke.internal.js +13 -1
  76. package/dist/features/board/lib/boardTypes.internal.js +16 -0
  77. package/dist/features/callout/index.d.ts +3 -2
  78. package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +14 -5
  79. package/dist/features/combobox/index.d.ts +2 -2
  80. package/dist/features/comments/BaseCommentsPlugin.js +33 -17
  81. package/dist/features/comments/index.d.ts +1 -1
  82. package/dist/features/date/index.d.ts +3 -2
  83. package/dist/features/details/index.d.ts +3 -2
  84. package/dist/features/details/lib/BaseDetailsPlugin.js +25 -12
  85. package/dist/features/field/index.d.ts +2 -0
  86. package/dist/features/field/index.js +4 -0
  87. package/dist/features/field/lib/BaseFieldPlugin.js +360 -0
  88. package/dist/features/field/lib/applyFieldValues.js +188 -0
  89. package/dist/features/field/lib/fieldRules.internal.js +204 -0
  90. package/dist/features/find/index.d.ts +3 -2
  91. package/dist/features/footnote/index.d.ts +1 -1
  92. package/dist/features/ink/index.d.ts +1 -1
  93. package/dist/features/ink/lib/BaseInkPlugin.js +126 -103
  94. package/dist/features/ink/lib/inkCodec.internal.js +130 -0
  95. package/dist/features/ink/lib/inkGone.internal.js +229 -48
  96. package/dist/features/ink/lib/inkPlaces.internal.js +534 -64
  97. package/dist/features/layout/index.d.ts +1 -1
  98. package/dist/features/link/lib/BaseLinkPlugin.js +6 -4
  99. package/dist/features/lint/index.d.ts +3 -2
  100. package/dist/features/media/index.d.ts +2 -2
  101. package/dist/features/media/index.js +2 -2
  102. package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
  103. package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +206 -4
  104. package/dist/features/mention/index.d.ts +5 -4
  105. package/dist/features/suggestion/index.d.ts +1 -1
  106. package/dist/features/table/index.d.ts +1 -1
  107. package/dist/features/table/lib/BaseTablePlugin.js +64 -15
  108. package/dist/features/table/lib/internal/selection.js +4 -2
  109. package/dist/features/toc/index.d.ts +1 -1
  110. package/dist/features/upload/index.d.ts +2 -2
  111. package/dist/features/upload/lib/BaseUploadPlugin.js +464 -250
  112. package/dist/history/index.d.ts +2 -2
  113. package/dist/html/index.d.ts +3 -3
  114. package/dist/html/server/index.d.ts +1 -1
  115. package/dist/{htmlTypes-DjeFG3P8.d.ts → htmlTypes-eT2ZGDAj.d.ts} +2 -31
  116. package/dist/hyperscript/index.d.ts +1 -1
  117. package/dist/{index-DzD6BIFJ.d.ts → index-B33E1CRJ.d.ts} +295 -6
  118. package/dist/{index-Cl77E9yr.d.ts → index-B7moSod7.d.ts} +2 -2
  119. package/dist/{index-hsC_sOn2.d.ts → index-B8-5Sr7I.d.ts} +35 -5
  120. package/dist/{index-BiQerPJS.d.ts → index-B8QJDAmG.d.ts} +2 -2
  121. package/dist/{index-BBKGrsG3.d.ts → index-BTx5oK7k.d.ts} +1 -1
  122. package/dist/{index-iaZOhA76.d.ts → index-BWPcE4ac-Cto_IsNs.d.ts} +7 -1
  123. package/dist/{index-BU6k1Aev.d.ts → index-BXjLmx1n-CXk17buG.d.ts} +4781 -4584
  124. package/dist/{index-kLKMc-pI.d.ts → index-BXwU9QH6.d.ts} +2 -2
  125. package/dist/{index-DTgaSxKr.d.ts → index-BkwR-5hH.d.ts} +40 -4
  126. package/dist/{index-Bq3sdm3S.d.ts → index-BsV2McRr.d.ts} +5 -4
  127. package/dist/index-C9Fu-P4E.d.ts +773 -0
  128. package/dist/{index-D5W-p9bS.d.ts → index-Ca48r1ng.d.ts} +49 -4
  129. package/dist/{index-CcZbqPqk.d.ts → index-Cob_iBdu.d.ts} +116 -41
  130. package/dist/{index-Bxfvicyy.d.ts → index-CpY7Xnxw.d.ts} +4 -3
  131. package/dist/{index-BkR7-GLI.d.ts → index-DNQXzU-X.d.ts} +2 -2
  132. package/dist/{index-D1CFXA-i.d.ts → index-DPowErHa.d.ts} +471 -141
  133. package/dist/{index-DaM37gF6.d.ts → index-DShbzec2.d.ts} +38 -23
  134. package/dist/{index-DC_MNGyu.d.ts → index-DYdObeFQ.d.ts} +3 -3
  135. package/dist/{index-Bc2Yg_2j.d.ts → index-Dq3Jlj8O-BJ6NxZm0.d.ts} +2 -2
  136. package/dist/{index-CT7miqQN.d.ts → index-DwWQVwQt.d.ts} +29 -11
  137. package/dist/{index-xdmCBvlT.d.ts → index-JWgwL5l3.d.ts} +5 -2
  138. package/dist/{index-DLA2DUR2.d.ts → index-M781pyx9.d.ts} +4 -3
  139. package/dist/{index-DdIRduDG.d.ts → index-d7io3MzC.d.ts} +3 -2
  140. package/dist/index.d.ts +4 -4
  141. package/dist/{react/internal → internal}/penStroke.internal.js +1 -1
  142. package/dist/internal/plugin/OverridePlugin.js +101 -119
  143. package/dist/internal/plugin/collectPlateNodeMappings.js +5 -1
  144. package/dist/internal/plugin/pastedUploadFiles.js +4 -0
  145. package/dist/internal/plugin/resolvePlugin.js +1 -1
  146. package/dist/internal/plugin/resolvePlugins.js +3 -0
  147. package/dist/internal/plugin/uploadDrafts.js +6 -0
  148. package/dist/internal/utils/mergePlugins.js +1 -0
  149. package/dist/lib/plugins/element-id/ElementIdPlugin.js +14 -18
  150. package/dist/lib/plugins/html/HtmlPlugin.js +9 -0
  151. package/dist/lib/plugins/html/htmlSafety.js +1 -1
  152. package/dist/lib/plugins/input-rules/InputRulesPlugin.js +77 -28
  153. package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
  154. package/dist/markdown/index.d.ts +2 -2
  155. package/dist/markdown/index.js +3 -1
  156. package/dist/markdown/lib/MarkdownPlugin.js +14 -11
  157. package/dist/markdown/lib/RawHtmlPlugin.js +26 -0
  158. package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
  159. package/dist/markdown/lib/internal/markdownConversion.js +776 -74
  160. package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
  161. package/dist/markdown/lib/internal/markdownFootnoteWriter.js +35 -0
  162. package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
  163. package/dist/markdown/lib/internal/markdownIntrinsics.js +125 -43
  164. package/dist/markdown/lib/internal/markdownLine.js +5 -3
  165. package/dist/markdown/lib/internal/markdownMappings.js +19 -7
  166. package/dist/markdown/lib/internal/markdownOpenTail.js +381 -0
  167. package/dist/markdown/lib/internal/markdownRawHtml.js +353 -0
  168. package/dist/markdown/lib/internal/markdownSegments.js +57 -48
  169. package/dist/markdown/lib/internal/markdownTags.js +29 -9
  170. package/dist/markdown/lib/serializer/convertNodesSerialize.js +10 -8
  171. package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +226 -0
  172. package/dist/markdown/lib/serializer/listToMdastTree.js +2 -0
  173. package/dist/math/index.d.ts +3 -2
  174. package/dist/math/react/index.d.ts +4 -3
  175. package/dist/migrations/index.d.ts +3 -3
  176. package/dist/migrations/migratePlateV54.js +4 -6
  177. package/dist/migrations/migratePlateV54RetiredMarks.internal.js +23 -8
  178. package/dist/migrations/migratePlateV54Suggestions.internal.js +2 -2
  179. package/dist/migrations/v53-manifest.internal.js +4 -0
  180. package/dist/pagination/index.d.ts +1 -1
  181. package/dist/pagination/react/index.d.ts +4 -4
  182. package/dist/react/components/EditorContentView.internal.js +42 -23
  183. package/dist/react/components/EditorProvider.js +5 -5
  184. package/dist/react/components/Plate.js +102 -128
  185. package/dist/react/components/PlateContainer.js +40 -32
  186. package/dist/react/components/PlateController.js +28 -16
  187. package/dist/react/components/PlateRoot.internal.js +3 -2
  188. package/dist/react/core.js +4 -4
  189. package/dist/react/features/board/BoardSurface.js +116 -87
  190. package/dist/react/features/board/boardClipboard.internal.js +15 -5
  191. package/dist/react/features/board/boardExport.internal.js +470 -0
  192. package/dist/react/features/board/boardGesture.internal.js +6 -3
  193. package/dist/react/features/board/boardIndex.internal.js +7 -18
  194. package/dist/react/features/board/boardPictureStyles.internal.js +415 -0
  195. package/dist/react/features/board/boardPictures.internal.js +19 -13
  196. package/dist/react/features/board/boardView.internal.js +190 -50
  197. package/dist/react/features/board/boardVoice.internal.js +10 -11
  198. package/dist/react/features/board/index.d.ts +108 -18
  199. package/dist/react/features/callout/index.d.ts +3 -2
  200. package/dist/react/features/combobox/index.d.ts +8 -8
  201. package/dist/react/features/comments/index.d.ts +6 -5
  202. package/dist/react/features/date/index.d.ts +4 -3
  203. package/dist/react/features/details/index.d.ts +4 -3
  204. package/dist/react/features/field/FieldPlugin.js +35 -0
  205. package/dist/react/features/field/index.d.ts +315 -0
  206. package/dist/react/features/field/index.js +2 -0
  207. package/dist/react/features/footnote/index.d.ts +7 -6
  208. package/dist/react/features/format-painter/index.d.ts +4 -3
  209. package/dist/react/features/ink/InkContent.js +313 -0
  210. package/dist/react/features/ink/index.d.ts +57 -33
  211. package/dist/react/features/ink/index.js +2 -2
  212. package/dist/react/features/ink/inkCapture.internal.js +39 -17
  213. package/dist/react/features/ink/inkInput.internal.js +1 -1
  214. package/dist/react/features/ink/inkLayout.internal.js +6 -3
  215. package/dist/react/features/ink/inkPaint.internal.js +78 -2
  216. package/dist/react/features/ink/inkPlacement.internal.js +332 -104
  217. package/dist/react/features/ink/inkWatch.internal.js +7 -5
  218. package/dist/react/features/layout/index.d.ts +5 -4
  219. package/dist/react/features/media/index.d.ts +5 -4
  220. package/dist/react/features/mention/index.d.ts +6 -5
  221. package/dist/react/features/resizable/Resizable.js +4 -6
  222. package/dist/react/features/resizable/index.d.ts +5 -5
  223. package/dist/react/features/suggestion/index.d.ts +6 -5
  224. package/dist/react/features/table/TablePlugin.js +4 -11
  225. package/dist/react/features/table/index.d.ts +10 -8
  226. package/dist/react/features/table/useTableResize.js +10 -1
  227. package/dist/react/features/toc/index.d.ts +2 -2
  228. package/dist/react/features/upload/index.d.ts +11 -6
  229. package/dist/react/index.d.ts +6 -6
  230. package/dist/react/index.js +4 -4
  231. package/dist/react/internal/plate-context.js +434 -188
  232. package/dist/react/plite-react.js +2 -2
  233. package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +12 -10
  234. package/dist/react/stores/plate/useEditor.js +32 -14
  235. package/dist/react/stores/plate/useEditorHistory.js +55 -0
  236. package/dist/react/stores/plate/useEditorSelector.js +79 -21
  237. package/dist/react/utils/BlockPlaceholderPlugin.js +5 -2
  238. package/dist/react/utils/pipeRenderElement.internal.js +1 -1
  239. package/dist/react/utils/pluginRenderElement.internal.js +1 -1
  240. package/dist/react/virtualized.d.ts +4 -4
  241. package/dist/{source-CNKy99Th.d.ts → source-BGohy8vH.d.ts} +4 -4
  242. package/dist/static/index.d.ts +18 -18
  243. package/dist/static/internal/renderStaticHtmlWithOverrides.js +2 -2
  244. package/dist/static/internal/staticPresentation.js +4 -4
  245. package/dist/static/internal/writeStaticSelectionClipboardData.js +7 -2
  246. package/dist/tabbable/index.d.ts +1 -1
  247. package/dist/tabbable/react/index.d.ts +3 -3
  248. package/dist/testing/index.d.ts +3 -3
  249. package/dist/yjs/index.d.ts +1 -1
  250. package/dist/yjs/react/index.d.ts +6 -6
  251. package/package.json +20 -2
  252. package/dist/markdown/lib/serializer/convertTextsSerialize.js +0 -163
  253. package/dist/react/components/EditorSelectionView.js +0 -40
  254. package/dist/react/features/ink/InkLayer.js +0 -218
  255. package/dist/react/internal/createPlateTargetScope.js +0 -62
@@ -0,0 +1,370 @@
1
+ # Field
2
+
3
+ Inline void fields that one role fills, each with a kind, settings, an optional condition on another field and an id unique in the document.
4
+
5
+ A field is a typed blank in a document that one role fills, such as a tenant's name, a start date, a checkbox or a signature. Each field is an inline void `field` element with a `kind`, a `role`, a `label` and a `fieldId` that no other field in the document holds. A field's `condition` names another field by that id. Plate checks roles, never users. Your app decides which person fills which role.
6
+
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
+
9
+ The demo is a lease template for a landlord and a tenant. 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.
10
+
11
+ <PackageInfo>
12
+
13
+ ## Features
14
+
15
+ - Inline void `field` element of six kinds: text, number, date, checkbox, choice and signature.
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
+ - `insert` and `update` commands that refuse a setting or condition that does not fit, and reads that report what is wrong with each field.
19
+ - 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
+ - New ids for the fields a paste, a drag copy, a duplicate or a table fill copies, with copied conditions that name the copies.
21
+ - 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.
23
+
24
+ </PackageInfo>
25
+
26
+ ## Kit usage
27
+
28
+ <Steps>
29
+
30
+ ### Installation
31
+
32
+ The fastest way to add fields is `FieldKit`, which installs `FieldPlugin` with the registry `FieldElement`. Installing `field` also installs `field-toolbar-button`.
33
+
34
+ _Registry item `field`: `npx shadcn@latest add @plate/field`._
35
+
36
+ - [`FieldElement`](/docs/components/field): renders the field chip and its settings popover.
37
+
38
+ ### Add kit
39
+
40
+ ```tsx
41
+ import { useCreateEditor } from 'platejs/react';
42
+
43
+ import { FieldKit } from '@/components/editor/field';
44
+
45
+ const editor = useCreateEditor({
46
+ plugins: [
47
+ // ...otherPlugins,
48
+ ...FieldKit,
49
+ ],
50
+ });
51
+ ```
52
+
53
+ ### Add the insert menu
54
+
55
+ `FieldToolbarButton` inserts a field of each kind. A new field takes the role of the document's first field, or `signer` in a document with no field. The main insert and slash menus have no Field item, so add this menu to a toolbar.
56
+
57
+ _Registry item `field-toolbar-button`: `npx shadcn@latest add @plate/field-toolbar-button`._
58
+
59
+ ```tsx
60
+ import { FieldToolbarButton } from '@/components/editor/field-toolbar-button';
61
+ import { Toolbar } from '@/components/editor/toolbar';
62
+
63
+ export function FieldToolbar() {
64
+ return (
65
+ <Toolbar>
66
+ <FieldToolbarButton />
67
+ </Toolbar>
68
+ );
69
+ }
70
+ ```
71
+
72
+ ### Add static rendering
73
+
74
+ `BaseFieldKit` renders each field's answer, a choice as its option's label, or the field's label when it has no answer, for read-only output with `platejs/static`.
75
+
76
+ _Registry item `field-static`: `npx shadcn@latest add @plate/field-static`._
77
+
78
+ </Steps>
79
+
80
+ ## Manual usage
81
+
82
+ <Steps>
83
+
84
+ ### Installation
85
+
86
+ ```bash
87
+ npm install platejs
88
+ ```
89
+
90
+ ### Add the plugin
91
+
92
+ ```tsx
93
+ import { FieldPlugin } from 'platejs/field/react';
94
+ import { useCreateEditor } from 'platejs/react';
95
+
96
+ import { FieldElement } from '@/components/editor/field';
97
+
98
+ const editor = useCreateEditor({
99
+ plugins: [FieldPlugin.configure({ component: FieldElement })],
100
+ });
101
+ ```
102
+
103
+ `BaseFieldPlugin` from `platejs/field` runs without React, such as on a server that reads a submitted document:
104
+
105
+ ```ts
106
+ import { createEditor, type Value } from 'platejs';
107
+ import { BaseFieldPlugin } from 'platejs/field';
108
+
109
+ export const readFields = (value: Value) =>
110
+ createEditor({ initialValue: value, plugins: [BaseFieldPlugin] })
111
+ .plugin(BaseFieldPlugin)
112
+ .read.fields();
113
+ ```
114
+
115
+ </Steps>
116
+
117
+ ## Value shape
118
+
119
+ A field sits inside a paragraph, like a date or a mention.
120
+
121
+ ```json
122
+ {
123
+ "type": "paragraph",
124
+ "children": [
125
+ { "text": "Tenant name: " },
126
+ {
127
+ "type": "field",
128
+ "fieldId": "f_k2x9",
129
+ "kind": "text",
130
+ "role": "tenant",
131
+ "label": "Tenant name",
132
+ "required": true,
133
+ "children": [{ "text": "" }]
134
+ },
135
+ { "text": "" }
136
+ ]
137
+ }
138
+ ```
139
+
140
+ | Property | Type | Notes |
141
+ |----------|------|-------|
142
+ | `type` | `'field'` | Inline void element owned by `BaseFieldPlugin`. |
143
+ | `fieldId` | `string` | Unique in the document. A new field gets a random `nanoid`. |
144
+ | `kind` | `FieldKind` | `'text'`, `'number'`, `'date'`, `'checkbox'`, `'choice'` or `'signature'`. Required. |
145
+ | `role` | `string` | The role that fills the field, such as `'tenant'`. Required. |
146
+ | `label` | `string` | Required. The chip shows it, and output shows it when the field has no answer. |
147
+ | `required` | `boolean` | Marks a field that must be filled. Plate stores it, and your app checks it when it collects answers. |
148
+ | `defaultValue` | `FieldValue` | A value of the field's kind. |
149
+ | `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 is unfilled. |
151
+ | `condition` | `FieldCondition` | `{ ref, test, value? }`, see [Conditions](#conditions). |
152
+ | `children` | `[{ text: '' }]` | Required child of an inline void element. |
153
+
154
+ ## Kinds
155
+
156
+ Each kind fixes the shape of its value and the tests a condition on it may use. `fitsField(field, value)` from `platejs/field` says whether a value fits a field's kind, and `FIELD_TESTS` lists each kind's tests.
157
+
158
+ | Kind | Value | Tests |
159
+ |------|-------|-------|
160
+ | `text` | a string | `filled`, `blank`, `equals`, `not-equals` |
161
+ | `number` | a finite number | `filled`, `blank`, `equals`, `not-equals`, `above`, `below` |
162
+ | `date` | an ISO date, `YYYY-MM-DD` | `filled`, `blank`, `equals`, `not-equals`, `above`, `below` |
163
+ | `checkbox` | `true` or `false` | `equals`, `not-equals` |
164
+ | `choice` | one option's `value` | `filled`, `blank`, `equals`, `not-equals` |
165
+ | `signature` | a string your app owns, such as a stored image's id | `filled`, `blank` |
166
+
167
+ A choice stores the option's `value`, so renaming an option's `label` keeps every answer and condition that names it.
168
+
169
+ ## Roles
170
+
171
+ 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
+
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 submitted value on its server.
174
+
175
+ The settings popover offers the roles the document's fields already use, and takes a new one.
176
+
177
+ ## Insert and update
178
+
179
+ `insert` takes a field's settings and returns its new `fieldId`. Its second argument takes node insert options, such as `at` and `select`.
180
+
181
+ ```tsx
182
+ import { BaseFieldPlugin } from 'platejs/field';
183
+
184
+ editor.update((tx) => {
185
+ const fieldId = tx.plugin(BaseFieldPlugin).insert(
186
+ { kind: 'text', label: 'Full name', required: true, role: 'tenant' },
187
+ { select: true }
188
+ );
189
+ });
190
+ ```
191
+
192
+ `insert` throws when a value, default or options do not fit the kind, when the settings name a `fieldId`, or when the condition names no field, or a test or value that the named field's kind does not take.
193
+
194
+ `update` changes the settings or value of the field that holds a `fieldId`. A setting given as `undefined` is removed.
195
+
196
+ ```tsx
197
+ editor.update((tx) => {
198
+ tx.plugin(BaseFieldPlugin).update(fieldId, { value: 'Ada Lovelace' });
199
+ });
200
+ ```
201
+
202
+ `update` throws, and changes nothing, when:
203
+
204
+ - no field holds `fieldId`;
205
+ - a setting the patch names does not fit the field's kind;
206
+ - the patch removes `kind`, `role` or `label`, or names `fieldId`;
207
+ - 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
+
209
+ A patch that changes `kind` or `options` also drops each value, default and options that the field no longer fits. Turning a number field with a default into a date field drops the default. The field keeps its `fieldId`.
210
+
211
+ ## Conditions
212
+
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`:
214
+
215
+ ```tsx
216
+ editor.update((tx) => {
217
+ tx.plugin(BaseFieldPlugin).update(petNameId, {
218
+ condition: { ref: petsId, test: 'equals', value: 'yes' },
219
+ });
220
+ });
221
+ ```
222
+
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. Plate stores the condition and checks that it fits the field it names. It does not hide a field or skip it, so your app decides what a condition that fails means.
224
+
225
+ `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
+
227
+ ## Read fields and their problems
228
+
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 }`.
230
+
231
+ ```tsx
232
+ import { BaseFieldPlugin } from 'platejs/field';
233
+
234
+ const fields = editor.plugin(BaseFieldPlugin).read;
235
+
236
+ const tenant = fields.field(tenantId);
237
+ const broken = fields.fields().filter((field) => field.problems.length > 0);
238
+ ```
239
+
240
+ | Problem | When |
241
+ |---------|------|
242
+ | `missing-target` | No field holds the id its condition names, such as after that field is deleted. |
243
+ | `unsupported-test` | The kind of the field its condition names does not take the condition's test. |
244
+ | `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
+ | `condition-loop` | Its condition names a field whose chain of conditions leads back to it, such as A naming B while B names A. |
246
+
247
+ `insert` and `update` refuse a write that would cause a problem. 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.
248
+
249
+ In React, `useFieldRead(fieldId)` from `platejs/field/react` reads one field and its problems. A commit that changes an element reads it again, and the component renders again only when the field or its problems changed. The registry chip uses it to show a warning when the field its condition names is deleted, and an undo clears the warning.
250
+
251
+ ```tsx
252
+ import { useFieldRead } from 'platejs/field/react';
253
+
254
+ const field = useFieldRead(element.fieldId);
255
+ const problems = field?.problems ?? [];
256
+ ```
257
+
258
+ ## Fill as one role
259
+
260
+ Set `fillRole` to open a fill-only view of one role. The editor then takes answers for that role's fields and refuses every other local change, so a tenant fills the tenant's fields and changes nothing else.
261
+
262
+ ```tsx
263
+ import { FieldPlugin } from 'platejs/field/react';
264
+ import { useCreateEditor } from 'platejs/react';
265
+
266
+ import { FieldElement } from '@/components/editor/field';
267
+
268
+ const editor = useCreateEditor({
269
+ initialValue: template,
270
+ plugins: [
271
+ // ...otherPlugins,
272
+ FieldPlugin.configure({
273
+ component: FieldElement,
274
+ initialState: { fillRole: 'tenant' },
275
+ }),
276
+ ],
277
+ });
278
+ ```
279
+
280
+ The demo switches one editor between authoring and each role through the plugin store, and `null` returns to authoring:
281
+
282
+ ```tsx
283
+ editor.plugin(FieldPlugin).store.set({ fillRole: 'landlord' });
284
+ editor.plugin(FieldPlugin).store.set({ fillRole: null });
285
+ ```
286
+
287
+ `usePluginStore(FieldPlugin, 'fillRole')` from `platejs/react` reads the role in a component. The role is editor state, so every view of one editor fills as the same role. Switch it between updates. A switch writes nothing to the document and leaves undo and redo as they are.
288
+
289
+ While a role is set:
290
+
291
+ - The registry chip of the role's field opens a popover with an input for the answer and a Clear button, and the role's checkbox ticks and unticks on click. A chip whose answer holds a pending suggestion says it waits for review and opens nothing. Another role's chip opens nothing, no chip drags, and the insert menu is disabled.
292
+ - The editor refuses a local commit that writes anything besides a fitting or cleared answer on the role's fields. Typing, paste, cut, a drop, Enter and AI writes change nothing. A refused update throws nothing to its caller and changes nothing.
293
+ - Selection, state fields without `persist` and effects that neither persist nor sync to peers pass, so a person can still select and copy.
294
+ - Undo and redo take back only the role's own answers. Undo stops at the first step that changed anything else, such as the author's edit, and returns `{ reason, status: 'blocked' }`. The first answer after a switch is its own undo step, so an answer typed right after a switch takes two undos.
295
+ - A document replacement, such as `tx.value.replace` or loading another template, is refused, and so is a plugin reconfiguration. Load the template and configure plugins before you set the role, or clear the role first.
296
+ - A comment lands, because creating its thread is a local effect. Your app decides whether people may comment in a fill view. The comment adds an undo step, and undo stops at that step, so the answers before the comment can no longer be undone.
297
+
298
+ A peer's change passes whole. Every commit tagged `collaboration` passes, so collaborators keep one document. Apply a peer's Yjs update from your provider's events, never from inside an editor update. A local write made inside a peer's change takes its `collaboration` tag, passes and never reaches peers. For the same reason, a Yjs `UndoManager` that your app drives itself, or a local update that your app tags `collaboration`, passes the fill check.
299
+
300
+ 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
+
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 submitted answer.
303
+
304
+ ## Copy and paste
305
+
306
+ 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
+
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.
309
+ - A copied condition whose field was not copied, or did not land, keeps naming the original.
310
+ - 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
+ - A paste into another document gets new ids too.
312
+ - Cut and paste gives the field a new id, so a condition elsewhere that named it reports `missing-target` until an undo.
313
+ - An app that copies a field with `tx.schema.copy` and inserts the result gets a new id, and the copy's condition keeps naming the original.
314
+
315
+ In Suggesting mode, a change from a field to a mention shows the field as deleted beside the inserted mention, so rejecting it keeps the field and its `fieldId`.
316
+
317
+ ## HTML
318
+
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:
320
+
321
+ ```html
322
+ <p>Pets? <span data-field-id="pets" data-field-kind="choice" data-field-label="Pets" data-field-options="[{&quot;label&quot;:&quot;Yes&quot;,&quot;value&quot;:&quot;yes&quot;},{&quot;label&quot;:&quot;No&quot;,&quot;value&quot;:&quot;no&quot;}]" data-field-role="tenant" data-field-value="&quot;yes&quot;">Yes</span> Pet name: <span data-field-condition="{&quot;ref&quot;:&quot;pets&quot;,&quot;test&quot;:&quot;equals&quot;,&quot;value&quot;:&quot;yes&quot;}" data-field-id="pet-name" data-field-kind="text" data-field-label="Pet name" data-field-role="tenant">[Pet name]</span></p>
323
+ ```
324
+
325
+ 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.
326
+
327
+ The demo's HTML panel serializes with `lossPolicy: 'allow'`, because the date element has no HTML encoder. The panel lists one `html-unsupported-content` line for the date it drops.
328
+
329
+ ## Markdown
330
+
331
+ Markdown writes each field as a `<field>` tag with every property, the `fieldId` and the condition included:
332
+
333
+ ```md
334
+ Pets? <field kind="choice" label="Pets" options="[{&quot;label&quot;:&quot;Yes&quot;,&quot;value&quot;:&quot;yes&quot;},{&quot;label&quot;:&quot;No&quot;,&quot;value&quot;:&quot;no&quot;}]" role="tenant" value="yes" fieldId="pets" /> Pet name: <field kind="text" label="Pet name" role="tenant" condition="{&quot;ref&quot;:&quot;pets&quot;,&quot;test&quot;:&quot;equals&quot;,&quot;value&quot;:&quot;yes&quot;}" fieldId="pet-name" />
335
+ ```
336
+
337
+ 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.
338
+
339
+ ## Word
340
+
341
+ Word has no field element. Word export writes each field's answer as text, a choice as its option's label, or the label in brackets when the field has no answer. It needs no static field component, so a headless export keeps the answers.
342
+
343
+ ```tsx
344
+ import { exportDocx } from 'platejs/docx/export';
345
+
346
+ const result = await exportDocx(editor);
347
+ const dropped = result.diagnostics.filter(
348
+ (diagnostic) => diagnostic.code === 'property-dropped'
349
+ );
350
+ ```
351
+
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.
353
+
354
+ Plain text, through `serializePlainText` from `platejs`, writes the same text as Word.
355
+
356
+ ## API Reference
357
+
358
+ | API | Package | Use |
359
+ |-----|---------|-----|
360
+ | `BaseFieldPlugin` | `platejs/field` | Headless inline void field plugin. |
361
+ | `FieldPlugin` | `platejs/field/react` | React field plugin. |
362
+ | `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. |
366
+ | `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 its problems, and renders again when either changes. |
368
+ | `fitsField(field, value)` | `platejs/field` | Whether a value fits a field's kind and options. |
369
+ | `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. |
package/dist/docs/find.md CHANGED
@@ -8,7 +8,8 @@ _Example `find-demo` in the Plate repository: `apps/www/src/registry/examples/fi
8
8
 
9
9
  ## Features
10
10
 
11
- - Opens with `Mod+F` and seeds the query from an expanded editor selection.
11
+ - Opens from its Find button or with `Mod+F`, and seeds the query from an
12
+ expanded editor selection.
12
13
  - Highlights every match without writing marks into the document or history.
13
14
  - Finds a match that runs across text leaves and inline elements within one
14
15
  block. Find searches text placed directly beside a block on its own.
@@ -45,9 +46,10 @@ const editor = createEditor({
45
46
  ```
46
47
 
47
48
  `BaseFindPlugin` owns the current query, matches, navigation and transient
48
- decoration data. `FindKit` supplies the shortcut, deferred input and accessible
49
- search bar. Its configured `decorate.attributes` supplies ordinary and active
50
- match styling. Each mounted Editable owns its open bar, draft, focus and scroll
49
+ decoration data. `FindKit` supplies the Find button, the shortcut, deferred
50
+ input and accessible search bar. The button sits where the bar opens and lets
51
+ a touch screen without `Mod+F` open Find. The open bar takes the button's place.
52
+ Its configured `decorate.attributes` supplies ordinary and active match styling. Each mounted Editable owns its open bar, draft, focus and scroll
51
53
  requests. Views of the same editor share committed queries and results; opening
52
54
  one bar does not open another. Open bars follow the committed query when they
53
55
  have no pending draft. Only the focused bar scrolls its view. Detaching a view
@@ -112,8 +114,9 @@ Custom renderers can style `data-find-match` and `data-find-active` attributes.
112
114
 
113
115
  ## Custom controls
114
116
 
115
- Use `useFind` in a component rendered by that Editable's `beforeEditable` or
116
- `afterEditable` slot. `FindKit` supplies the context through `wrapRoot`, so a
117
+ `FindKit` already shows a Find button in each Editable. For another opening
118
+ control, use `useFind` in a component rendered by that Editable's
119
+ `beforeEditable` or `afterEditable` slot. `FindKit` supplies the context through `wrapRoot`, so a
117
120
  custom control addresses one mounted view without subscribing to search results:
118
121
 
119
122
  ```tsx
package/dist/docs/form.md CHANGED
@@ -247,6 +247,8 @@ function MyForm() {
247
247
 
248
248
  ## Migrating from a shadcn textarea to Plate
249
249
 
250
+ For a chat message field, use [Prompt Editor](/docs/prompt-editor) instead. It takes and reports a string, sends on Enter and holds @ chips.
251
+
250
252
  If you have a standard [Field example from shadcn/ui docs](https://ui.shadcn.com/docs/components/field) and want to replace `<Textarea>` with a Plate editor, follow these steps:
251
253
 
252
254
  ```tsx
@@ -83,6 +83,12 @@ editor.plugin(HeadingPlugin).update.toggle({ level: 2 });
83
83
 
84
84
  Calling toggle with the active level resets the selected heading to the root default block. Calling it with another level changes the level on the same heading type.
85
85
 
86
+ ~~~ts
87
+ editor.plugin(HeadingPlugin).read.canSetLevel(2);
88
+ ~~~
89
+
90
+ `canSetLevel` answers whether every selected block can take that level where it sits, under the rule `setLevel` enforces. A menu can disable a level the caret's parent cannot hold, as the copied Turn into menu does.
91
+
86
92
  ## API Reference
87
93
 
88
94
  | API | Purpose |
@@ -152,8 +152,6 @@ import {
152
152
  BlockquotePlugin,
153
153
  BoldPlugin,
154
154
  HeadingPlugin,
155
-
156
-
157
155
  ItalicPlugin,
158
156
  UnderlinePlugin,
159
157
  } from 'platejs/react';
@@ -252,8 +250,6 @@ import {
252
250
  BlockquotePlugin,
253
251
  BoldPlugin,
254
252
  HeadingPlugin,
255
-
256
-
257
253
  ItalicPlugin,
258
254
  UnderlinePlugin,
259
255
  } from 'platejs/react';
package/dist/docs/link.md CHANGED
@@ -86,14 +86,14 @@ const editor = createEditor({
86
86
  LinkPlugin.configure({
87
87
  component: LinkElement,
88
88
  slots: {
89
- afterEditable: LinkFloatingToolbar,
89
+ caret: LinkFloatingToolbar,
90
90
  },
91
91
  }),
92
92
  ],
93
93
  });
94
94
  ```
95
95
 
96
- - `slots.afterEditable`: Renders [`LinkFloatingToolbar`](/docs/components/link) after the editable area for link editing.
96
+ - `slots.caret`: Renders [`LinkFloatingToolbar`](/docs/components/link) after the editable area for link editing, on the view that holds the caret, such as a board note.
97
97
  - `.configure({ component: LinkElement })`: Renders link elements with
98
98
  [`LinkElement`](/docs/components/link).
99
99
 
@@ -161,7 +161,7 @@ LinkPlugin.configure({
161
161
 
162
162
  Options:
163
163
 
164
- - `allowedSchemes?: string[]` — URL schemes the link feature accepts when it
164
+ - `allowedSchemes?: string[]` lists the URL schemes the link feature accepts when it
165
165
  inserts, types, pastes or imports a link, and that a rendered link may use.
166
166
  Relative URLs are always allowed. Add a scheme such as `vscode` for app deep links. Script-capable
167
167
  destinations, such as `javascript:`, `vbscript:`, and `data:`, are never
@@ -1,4 +1,4 @@
1
- # Plate docs for platejs@54.0.0-beta.2
1
+ # Plate docs for platejs@54.0.0-beta.4
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
 
@@ -73,6 +73,7 @@ These pages match the installed `platejs` version. A `/docs/<path>` link in a pa
73
73
  - [Exit Break](exit-break.md)
74
74
  - [External Text Views](external-text.md): Render one canonical Plate Text through an adapter-owned editing surface.
75
75
  - [Feature Kits](feature-kits.md): Use registry kits to add groups of Plate plugins and UI wiring.
76
+ - [Field](field.md): Inline void fields that one role fills, each with a kind, settings, an optional condition on another field and an id unique in the document.
76
77
  - [Find](find.md): Search editable text with transient highlights and keyboard navigation.
77
78
  - [Font](font.md): Provide extended formatting options for document content.
78
79
  - [Footnote](footnote.md)
@@ -116,9 +117,10 @@ These pages match the installed `platejs` version. A `/docs/<path>` link in a pa
116
117
  - [Plugin Rules](plugin-rules.md): Configure common editing behaviors.
117
118
  - [Plugin Shortcuts](plugin-shortcuts.md): Configure keyboard shortcuts on Plate plugins.
118
119
  - [Plugin Configuration](plugin.md): How to configure and customize Plate plugins.
120
+ - [Prompt Editor](prompt-editor.md): A chat message field that holds @ chips and sends on Enter.
119
121
  - [Releases](releases.md)
120
122
  - [Roots](roots.md): Use extra roots for headers, footers, synced blocks, captions, and other editable regions.
121
- - [Right-to-left](rtl.md): Edit Hebrew, Arabic and other right-to-left documents.
123
+ - [Right-to-left](rtl.md): Edit Arabic, Hebrew and other right-to-left documents.
122
124
  - [Schema](schema.md): Declare Plate document structure, validate saved values, and fit imported content.
123
125
  - [Selection](selection.md): Read, update, focus, and render text and node selections in Plate.
124
126
  - [Serializing](serializing.md): Save complete Plate documents and convert them to text, HTML, Markdown, or DOCX.