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.
Files changed (166) hide show
  1. package/dist/{AIChatRequestContext-DrUahdTc.d.ts → AIChatRequestContext-BYpGufVe.d.ts} +2 -2
  2. package/dist/{BaseSuggestionPlugin-_7Ka6nY3.d.ts → BaseSuggestionPlugin-C52LR8RN.d.ts} +4 -4
  3. package/dist/{PlateStatic-D3Cb-QwH.d.ts → PlateStatic-DMClx-tH.d.ts} +3 -3
  4. package/dist/ai/index.d.ts +1 -1
  5. package/dist/ai/react/index.d.ts +9 -9
  6. package/dist/authored/index.d.ts +3 -3
  7. package/dist/code-block/codemirror/index.d.ts +1 -1
  8. package/dist/{combobox-Dr0OYZIE.d.ts → combobox-DgYdu5mZ.d.ts} +2 -2
  9. package/dist/{comparison-types-DdwE6mYq-BogsHoUO.d.ts → comparison-types-DBQFu7Rt-DYc2TC2H.d.ts} +1 -1
  10. package/dist/compiler/index.d.ts +2 -2
  11. package/dist/{core-BqR-fEDp.d.ts → core-CQKT9eNc.d.ts} +6 -6
  12. package/dist/diff/index.d.ts +2 -2
  13. package/dist/docs/annotations.md +4 -2
  14. package/dist/docs/api/anchor.md +15 -0
  15. package/dist/docs/api/core/plate-components.md +12 -4
  16. package/dist/docs/api/core.md +4 -3
  17. package/dist/docs/api/dom.md +5 -3
  18. package/dist/docs/api/range.md +17 -0
  19. package/dist/docs/authored-changes.md +3 -3
  20. package/dist/docs/board.md +2 -1
  21. package/dist/docs/comment.md +3 -1
  22. package/dist/docs/editor.md +5 -2
  23. package/dist/docs/field.md +279 -33
  24. package/dist/docs/installation/plate-ui.md +40 -14
  25. package/dist/docs/link.md +1 -1
  26. package/dist/docs/llms.txt +1 -1
  27. package/dist/docs/media.md +88 -2
  28. package/dist/docs/migration/plite-to-plate.md +105 -4
  29. package/dist/docs/plugin-input-rules.md +4 -3
  30. package/dist/docs/plugin-methods.md +3 -1
  31. package/dist/docs/roots.md +33 -10
  32. package/dist/docs/selection.md +5 -0
  33. package/dist/docs/suggestion.md +2 -2
  34. package/dist/docs/toolbar.md +11 -2
  35. package/dist/docx/export/index.d.ts +3 -3
  36. package/dist/docx/export/lib/internal/unit-conversion.js +1 -1
  37. package/dist/docx/export/lib/internal/xml-builder.js +1 -1
  38. package/dist/docx/import/index.d.ts +4 -4
  39. package/dist/docx/paste/index.d.ts +4 -4
  40. package/dist/dom/index.d.ts +1 -1
  41. package/dist/excalidraw/index.d.ts +3 -3
  42. package/dist/excalidraw/react/index.d.ts +3 -3
  43. package/dist/facade.js +2 -2
  44. package/dist/features/board/index.d.ts +1 -1
  45. package/dist/features/board/lib/boardShape.internal.js +1 -1
  46. package/dist/features/callout/index.d.ts +3 -3
  47. package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +14 -18
  48. package/dist/features/combobox/index.d.ts +2 -2
  49. package/dist/features/comments/BaseCommentsPlugin.js +6 -2
  50. package/dist/features/comments/index.d.ts +1 -1
  51. package/dist/features/date/index.d.ts +3 -3
  52. package/dist/features/details/index.d.ts +3 -3
  53. package/dist/features/field/index.d.ts +2 -2
  54. package/dist/features/field/index.js +3 -3
  55. package/dist/features/field/lib/BaseFieldPlugin.js +109 -40
  56. package/dist/features/field/lib/applyFieldValues.js +313 -83
  57. package/dist/features/field/lib/fieldRules.internal.js +92 -4
  58. package/dist/features/find/index.d.ts +3 -3
  59. package/dist/features/footnote/index.d.ts +1 -1
  60. package/dist/features/ink/index.d.ts +1 -1
  61. package/dist/features/ink/lib/BaseInkPlugin.js +28 -31
  62. package/dist/features/ink/lib/inkCodec.internal.js +16 -1
  63. package/dist/features/ink/lib/inkGone.internal.js +1 -1
  64. package/dist/features/ink/lib/inkMatch.internal.js +35 -11
  65. package/dist/features/ink/lib/inkPlaces.internal.js +8 -3
  66. package/dist/features/layout/index.d.ts +1 -1
  67. package/dist/features/lint/index.d.ts +3 -3
  68. package/dist/features/list/lib/listIndex.internal.js +1 -1
  69. package/dist/features/list/lib/listNumbering.internal.js +1 -1
  70. package/dist/features/media/index.d.ts +1 -1
  71. package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +1 -1
  72. package/dist/features/mention/index.d.ts +5 -5
  73. package/dist/features/suggestion/BaseSuggestionPlugin.js +3 -2
  74. package/dist/features/suggestion/index.d.ts +5 -4
  75. package/dist/features/suggestion/suggestionColorOf.js +5 -4
  76. package/dist/features/table/index.d.ts +1 -1
  77. package/dist/features/table/lib/internal/selection.js +1 -1
  78. package/dist/features/toc/index.d.ts +1 -1
  79. package/dist/features/upload/index.d.ts +1 -1
  80. package/dist/history/index.d.ts +2 -2
  81. package/dist/html/index.d.ts +3 -3
  82. package/dist/html/server/index.d.ts +1 -1
  83. package/dist/{htmlTypes-eT2ZGDAj.d.ts → htmlTypes-8IFX0ezP.d.ts} +1 -1
  84. package/dist/hyperscript/index.d.ts +1 -1
  85. package/dist/{index-C9Fu-P4E.d.ts → index-AOVPovEr.d.ts} +156 -18
  86. package/dist/{index-BTx5oK7k.d.ts → index-B4oeyc99.d.ts} +1 -1
  87. package/dist/{index-BXwU9QH6.d.ts → index-BAz_KJSV.d.ts} +2 -2
  88. package/dist/{index-B8-5Sr7I.d.ts → index-BBsiQIzw.d.ts} +2 -2
  89. package/dist/{index-DNQXzU-X.d.ts → index-BIP1GoWI.d.ts} +1 -1
  90. package/dist/{index-B8QJDAmG.d.ts → index-BTFrh2Cz.d.ts} +2 -2
  91. package/dist/{index-M781pyx9.d.ts → index-BapA_uvI.d.ts} +4 -4
  92. package/dist/{index-DPowErHa.d.ts → index-BbsVGwn8.d.ts} +22 -15
  93. package/dist/{index-DShbzec2.d.ts → index-BcuSI8EM.d.ts} +6 -3
  94. package/dist/{index-DwWQVwQt.d.ts → index-BfHCmKG3.d.ts} +41 -16
  95. package/dist/{index-BWPcE4ac-Cto_IsNs.d.ts → index-BvQzYVAW-Jvz2iG8B.d.ts} +1 -1
  96. package/dist/{index-BkwR-5hH.d.ts → index-C-5w6252.d.ts} +3 -3
  97. package/dist/{index-JWgwL5l3.d.ts → index-Cp0QfjUV.d.ts} +3 -3
  98. package/dist/{index-B7moSod7.d.ts → index-CrUMAwqm.d.ts} +5 -1
  99. package/dist/{index-B33E1CRJ.d.ts → index-D2w_9_tb.d.ts} +3 -3
  100. package/dist/{index-DYdObeFQ.d.ts → index-DE1Mcccg.d.ts} +3 -3
  101. package/dist/{index-CpY7Xnxw.d.ts → index-DFMkcY5V.d.ts} +4 -4
  102. package/dist/{index-BXjLmx1n-CXk17buG.d.ts → index-DHt8nZQ6-NUTahb8N.d.ts} +111 -70
  103. package/dist/{index-BsV2McRr.d.ts → index-DM6z4D7q.d.ts} +5 -5
  104. package/dist/{index-Cob_iBdu.d.ts → index-DUk2VZ_1.d.ts} +3 -3
  105. package/dist/{index-d7io3MzC.d.ts → index-DbPoiwq_.d.ts} +3 -3
  106. package/dist/{index-Ca48r1ng.d.ts → index-Dh7pWHZo.d.ts} +3 -3
  107. package/dist/{index-Dq3Jlj8O-BJ6NxZm0.d.ts → index-PDROnF1G-Ds_dbJsr.d.ts} +1 -1
  108. package/dist/index.d.ts +3 -3
  109. package/dist/internal/penStroke.internal.js +28 -3
  110. package/dist/internal/plugin/OverridePlugin.js +2 -0
  111. package/dist/internal/plugin/compilePlateModel.js +2 -8
  112. package/dist/internal/plugin/pluginStore.js +0 -3
  113. package/dist/internal/plugin/resolvePlugins.js +1 -1
  114. package/dist/internal/utils/vscodeClipboard.js +11 -0
  115. package/dist/lib/plugin/createPluginContext.internal.js +2 -3
  116. package/dist/lib/plugins/html/HtmlPlugin.js +1 -0
  117. package/dist/markdown/index.d.ts +1 -1
  118. package/dist/markdown/lib/MarkdownPlugin.js +2 -1
  119. package/dist/markdown/lib/internal/markdownRawHtml.js +1 -1
  120. package/dist/markdown/lib/serializer/convertNodesSerialize.js +1 -1
  121. package/dist/markdown/lib/serializer/listToMdastTree.js +1 -1
  122. package/dist/math/index.d.ts +3 -3
  123. package/dist/math/react/index.d.ts +4 -4
  124. package/dist/migrations/index.d.ts +3 -3
  125. package/dist/pagination/index.d.ts +1 -1
  126. package/dist/pagination/react/index.d.ts +2 -2
  127. package/dist/react/features/board/BoardShape.js +351 -130
  128. package/dist/react/features/board/boardIndex.internal.js +2 -1
  129. package/dist/react/features/board/boardInk.internal.js +2 -13
  130. package/dist/react/features/board/index.d.ts +55 -43
  131. package/dist/react/features/board/index.js +2 -2
  132. package/dist/react/features/callout/index.d.ts +3 -3
  133. package/dist/react/features/combobox/index.d.ts +5 -5
  134. package/dist/react/features/comments/index.d.ts +6 -6
  135. package/dist/react/features/date/index.d.ts +4 -4
  136. package/dist/react/features/details/index.d.ts +4 -4
  137. package/dist/react/features/field/index.d.ts +20 -5
  138. package/dist/react/features/footnote/index.d.ts +7 -7
  139. package/dist/react/features/format-painter/index.d.ts +4 -4
  140. package/dist/react/features/ink/InkContent.js +56 -18
  141. package/dist/react/features/ink/InkPlugin.js +52 -5
  142. package/dist/react/features/ink/index.d.ts +312 -16
  143. package/dist/react/features/ink/inkCapture.internal.js +36 -9
  144. package/dist/react/features/ink/inkMeasure.internal.js +1 -1
  145. package/dist/react/features/ink/inkPaint.internal.js +17 -7
  146. package/dist/react/features/ink/inkPick.internal.js +218 -0
  147. package/dist/react/features/ink/inkPlacement.internal.js +8 -3
  148. package/dist/react/features/ink/inkWatch.internal.js +1 -1
  149. package/dist/react/features/layout/index.d.ts +5 -5
  150. package/dist/react/features/media/index.d.ts +5 -5
  151. package/dist/react/features/mention/index.d.ts +6 -6
  152. package/dist/react/features/suggestion/index.d.ts +6 -6
  153. package/dist/react/features/table/index.d.ts +5 -5
  154. package/dist/react/features/toc/index.d.ts +2 -2
  155. package/dist/react/features/upload/index.d.ts +5 -5
  156. package/dist/react/index.d.ts +5 -5
  157. package/dist/react/internal/rendered-attributes.js +1 -1
  158. package/dist/react/virtualized.d.ts +2 -2
  159. package/dist/{source-BGohy8vH.d.ts → source-D5CyclpX.d.ts} +3 -3
  160. package/dist/static/index.d.ts +5 -5
  161. package/dist/tabbable/index.d.ts +1 -1
  162. package/dist/tabbable/react/index.d.ts +3 -3
  163. package/dist/testing/index.d.ts +2 -2
  164. package/dist/yjs/index.d.ts +1 -1
  165. package/dist/yjs/react/index.d.ts +5 -5
  166. package/package.json +2 -2
@@ -10,6 +10,7 @@ import { BaseParagraphPlugin } from "../../../lib/plugins/paragraph/BaseParagrap
10
10
  import { PLUGINS } from "../../../utils/plate-keys.js";
11
11
  import { ContentSlice, ElementApi, NodeApi, PathApi, RangeApi, SelectionApi, authoredVeto, editorCommands, locateAt, property, schema, txLocate } from "../../../core.js";
12
12
  import { applyBlockReleases, canReplaceContainers, readBlockReleases } from "../../../internal/plugin/blockRelease.js";
13
+ import { readVSCodeLanguage } from "../../../internal/utils/vscodeClipboard.js";
13
14
  //#region src/features/code-block/lib/BaseCodeBlockPlugin.ts
14
15
  const CODE_LANGUAGE_CLASS_RE = /(?:^|\s)language-([^\s]+)/;
15
16
  const NON_WHITESPACE = /\S/;
@@ -431,28 +432,23 @@ const BaseCodeBlockPlugin = definePlugin(PLUGINS.codeBlock, {
431
432
  },
432
433
  mimeType: "text/html",
433
434
  priority: 200
435
+ }, {
436
+ decode: ({ data, snapshot }) => {
437
+ const language = readVSCodeLanguage(snapshot);
438
+ if (language === null || language === "markdown") return null;
439
+ return ContentSlice.closed([{
440
+ children: [{ text: data }],
441
+ language,
442
+ type: context.schema.type
443
+ }]);
444
+ },
445
+ mimeType: "text/plain",
446
+ priority: 200
434
447
  }],
435
448
  commands: ({ around, handle }) => [
436
449
  around(domCommands.insertData, ({ input, next, state }) => {
437
450
  const text = input.getData("text/plain");
438
- const vscodeDataString = input.getData("vscode-editor-data");
439
- const block = state.nodes.block();
440
- const isInCodeBlock = block?.[0].type === context.schema.type;
441
- if (vscodeDataString) try {
442
- const vscodeData = JSON.parse(vscodeDataString);
443
- const language = typeof vscodeData === "object" && vscodeData !== null && "mode" in vscodeData && typeof vscodeData.mode === "string" ? vscodeData.mode : void 0;
444
- if (isInCodeBlock) return state.transaction((tx) => {
445
- tx.text.insert(text);
446
- });
447
- if (!block) return next();
448
- return state.transaction((tx) => {
449
- tx.fragment.replace([{
450
- children: [{ text }],
451
- language,
452
- type: context.schema.type
453
- }], { at: PathApi.next(block[1]) });
454
- });
455
- } catch {}
451
+ const isInCodeBlock = state.nodes.block()?.[0].type === context.schema.type;
456
452
  const textIsHtmlMarkup = text === input.getData("text/html");
457
453
  if (isInCodeBlock && text && !textIsHtmlMarkup) return state.transaction((tx) => {
458
454
  tx.text.insert(text);
@@ -1,3 +1,3 @@
1
- import { n as ComboboxState, t as ComboboxEditor } from "../../combobox-Dr0OYZIE.js";
2
- import { n as filterWords, t as FilterWordsOptions } from "../../index-BTx5oK7k.js";
1
+ import { n as ComboboxState, t as ComboboxEditor } from "../../combobox-DgYdu5mZ.js";
2
+ import { n as filterWords, t as FilterWordsOptions } from "../../index-B4oeyc99.js";
3
3
  export { ComboboxEditor, ComboboxState, FilterWordsOptions, filterWords };
@@ -1,4 +1,4 @@
1
- import { notifyObservers, readDocumentRange, runEditorObserver, subscribeEditorViewState, withStoredAuthoredRead } from "../../facade.js";
1
+ import { getAnchorRuntimeId, notifyObservers, readDocumentRange, restoreAnchor, runEditorObserver, subscribeEditorViewState, withStoredAuthoredRead } from "../../facade.js";
2
2
  import { definePlugin } from "../../lib/plugin/definePlugin.js";
3
3
  import { readEditorAuthor } from "../../lib/editor/editorUser.internal.js";
4
4
  import { nanoid } from "../../lib/libs/nanoid.js";
@@ -744,7 +744,8 @@ const BaseCommentsPlugin = definePlugin("comments", {
744
744
  status: "blocked"
745
745
  }
746
746
  };
747
- restoredAnchor = editor.anchor.restore(transition.attachment);
747
+ const kept = orphans.get(thread.id);
748
+ restoredAnchor = kept && transition.anchorId !== null && getAnchorRuntimeId(kept) === transition.anchorId ? kept : restoreAnchor(editor, transition.attachment, transition.anchorId);
748
749
  hold(restoredAnchor);
749
750
  if (!restoredAnchor.resolve()) return {
750
751
  status: "applied",
@@ -755,6 +756,7 @@ const BaseCommentsPlugin = definePlugin("comments", {
755
756
  };
756
757
  }
757
758
  let value = null;
759
+ const removed = transition.value ? void 0 : anchors.get(thread.id);
758
760
  const mutation = await commitMutation(thread.id, transition.value ? "createThread" : "removeThread", transition.value, restoredAnchor, {
759
761
  afterWrite: (canonical) => {
760
762
  value = canonical;
@@ -775,6 +777,7 @@ const BaseCommentsPlugin = definePlugin("comments", {
775
777
  status: "applied",
776
778
  value: Object.freeze({
777
779
  ...transition,
780
+ anchorId: removed ? getAnchorRuntimeId(removed) : transition.anchorId,
778
781
  previous: current,
779
782
  value
780
783
  })
@@ -914,6 +917,7 @@ const BaseCommentsPlugin = definePlugin("comments", {
914
917
  if (!canonical || viewRefuses) return;
915
918
  commandEditor.update((tx) => {
916
919
  tx.effects.emit(commentCreationHistoryEffect, {
920
+ anchorId: anchor ? getAnchorRuntimeId(anchor) : null,
917
921
  attachment: anchor ? commandEditor.anchor.save(anchor) : null,
918
922
  messageId: canonical.messages[0].id,
919
923
  previous: null,
@@ -1,2 +1,2 @@
1
- import { S as SavedComments, _ as CommentsLoadIssue, a as CommentDataValue, b as CreateCommentThreadInput, c as CommentMutationRequest, d as CommentRanges, f as CommentResolution, g as CommentsChange, h as CommentUser, i as CommentDataList, l as CommentMutationResult, m as CommentThread, n as CommentAttachment, o as CommentMessage, p as CommentTarget, r as CommentData, s as CommentMutationDecision, t as BaseCommentsPlugin, u as CommentOperation, v as CommentsPluginState, x as PendingComment, y as CommentsSnapshot } from "../../index-CpY7Xnxw.js";
1
+ import { S as SavedComments, _ as CommentsLoadIssue, a as CommentDataValue, b as CreateCommentThreadInput, c as CommentMutationRequest, d as CommentRanges, f as CommentResolution, g as CommentsChange, h as CommentUser, i as CommentDataList, l as CommentMutationResult, m as CommentThread, n as CommentAttachment, o as CommentMessage, p as CommentTarget, r as CommentData, s as CommentMutationDecision, t as BaseCommentsPlugin, u as CommentOperation, v as CommentsPluginState, x as PendingComment, y as CommentsSnapshot } from "../../index-DFMkcY5V.js";
2
2
  export { BaseCommentsPlugin, CommentAttachment, CommentData, CommentDataList, CommentDataValue, CommentMessage, CommentMutationDecision, CommentMutationRequest, CommentMutationResult, CommentOperation, CommentRanges, CommentResolution, CommentTarget, CommentThread, CommentUser, CommentsChange, CommentsLoadIssue, CommentsPluginState, CommentsSnapshot, CreateCommentThreadInput, PendingComment, SavedComments };
@@ -1,6 +1,6 @@
1
- import { iu as TxDeclaredMethod, ji as ElementOf, ss as PropertyStringDescriptor } from "../../index-BXjLmx1n-CXk17buG.js";
2
- import "../../htmlTypes-eT2ZGDAj.js";
3
- import { _ as BasePlugin, _t as NodeInsertOptions } from "../../core-BqR-fEDp.js";
1
+ import { iu as TxDeclaredMethod, ji as ElementOf, ss as PropertyStringDescriptor } from "../../index-DHt8nZQ6-NUTahb8N.js";
2
+ import "../../htmlTypes-8IFX0ezP.js";
3
+ import { _ as BasePlugin, _t as NodeInsertOptions } from "../../core-CQKT9eNc.js";
4
4
  declare const BaseDatePlugin: BasePlugin<Readonly<{
5
5
  readonly __pluginWritableProperties: Readonly<{
6
6
  descriptor: PropertyStringDescriptor<{
@@ -1,6 +1,6 @@
1
- import { As as SchemaContentPrefixSlot, Ca as NodeKey, Ds as SchemaContentDefault, Ht as EditorJsonValue, Ia as NodeSelection, Ji as Location, Ls as SchemaContentRule, iu as TxDeclaredMethod, ji as ElementOf, ts as PropertyJsonDescriptor } from "../../index-BXjLmx1n-CXk17buG.js";
2
- import "../../htmlTypes-eT2ZGDAj.js";
3
- import { Co as PluginReference, Qn as HeadingLevel, _ as BasePlugin, ct as BlockInsertOptions, lt as BlockUpsertOptions, xo as PluginDependency } from "../../core-BqR-fEDp.js";
1
+ import { As as SchemaContentPrefixSlot, Ca as NodeKey, Ds as SchemaContentDefault, Ht as EditorJsonValue, Ia as NodeSelection, Ji as Location, Ls as SchemaContentRule, iu as TxDeclaredMethod, ji as ElementOf, ts as PropertyJsonDescriptor } from "../../index-DHt8nZQ6-NUTahb8N.js";
2
+ import "../../htmlTypes-8IFX0ezP.js";
3
+ import { Co as PluginReference, Qn as HeadingLevel, _ as BasePlugin, ct as BlockInsertOptions, lt as BlockUpsertOptions, xo as PluginDependency } from "../../core-CQKT9eNc.js";
4
4
  declare const isSummaryHeadingLevel: (value: unknown) => value is HeadingLevel;
5
5
  type BaseDetailsViewState = {
6
6
  openKeys: Set<NodeKey>;
@@ -1,2 +1,2 @@
1
- import { _ as fitsField, a as FieldCondition, c as FieldOption, d as FieldRead, f as FieldSettings, g as FIELD_TESTS, h as FieldValue, i as BaseFieldPlugin, l as FieldPatch, m as FieldTest, n as FieldRefusal, o as FieldElement, p as FieldSubmission, r as applyFieldValues, s as FieldKind, t as FieldApplyResult, u as FieldProblem } from "../../index-C9Fu-P4E.js";
2
- export { BaseFieldPlugin, FIELD_TESTS, FieldApplyResult, FieldCondition, FieldElement, FieldKind, FieldOption, FieldPatch, FieldProblem, FieldRead, FieldRefusal, FieldSettings, FieldSubmission, FieldTest, FieldValue, applyFieldValues, fitsField };
1
+ import { S as fitsField, _ as FieldSubmission, a as fieldSubmission, b as FIELD_TESTS, c as BaseFieldPlugin, d as FieldKind, f as FieldOption, g as FieldSettings, h as FieldRead, i as applyFieldValues, l as FieldCondition, m as FieldProblem, n as FieldApplyResult, o as readFieldAnswers, p as FieldPatch, r as FieldRefusal, s as startFieldValues, t as FieldAnswer, u as FieldElement, v as FieldTest, x as fillsField, y as FieldValue } from "../../index-AOVPovEr.js";
2
+ export { BaseFieldPlugin, FIELD_TESTS, FieldAnswer, FieldApplyResult, FieldCondition, FieldElement, FieldKind, FieldOption, FieldPatch, FieldProblem, FieldRead, FieldRefusal, FieldSettings, FieldSubmission, FieldTest, FieldValue, applyFieldValues, fieldSubmission, fillsField, fitsField, readFieldAnswers, startFieldValues };
@@ -1,4 +1,4 @@
1
- import { FIELD_TESTS, fitsField } from "./lib/fieldRules.internal.js";
1
+ import { FIELD_TESTS, fillsField, fitsField } from "./lib/fieldRules.internal.js";
2
2
  import { BaseFieldPlugin } from "./lib/BaseFieldPlugin.js";
3
- import { applyFieldValues } from "./lib/applyFieldValues.js";
4
- export { BaseFieldPlugin, FIELD_TESTS, applyFieldValues, fitsField };
3
+ import { applyFieldValues, fieldSubmission, readFieldAnswers, startFieldValues } from "./lib/applyFieldValues.js";
4
+ export { BaseFieldPlugin, FIELD_TESTS, applyFieldValues, fieldSubmission, fillsField, fitsField, readFieldAnswers, startFieldValues };
@@ -1,8 +1,8 @@
1
- import { EditorRefusalError, claimsHistoryReplay, getActiveEditorUpdateId, getActiveEditorUpdateTags, getSnapshotVersion, readElementPropertyWrites, readRootEntries, readViewPage, registerEditorTransactionGuard } from "../../../facade.js";
1
+ import { EditorRefusalError, claimsHistoryReplay, getActiveEditorUpdateId, getActiveEditorUpdateTags, getEditorRuntimeOwner, getMutationVersion, getSnapshotVersion, readElementPropertyWrites, readRootEntries, readViewPage, registerEditorTransactionGuard } from "../../../facade.js";
2
2
  import { failInvariant } from "../../../internal/failInvariant.js";
3
3
  import { definePlugin } from "../../../lib/plugin/definePlugin.js";
4
4
  import { ElementApi, documentReplacement, locateAt, property, schema, target, txLocate } from "../../../core.js";
5
- import { FIELD_KINDS, FIELD_TESTS, conditionProblem, fieldLinks, fieldProblems, fitsField, isFieldCondition, isFieldKind, isFieldOptions, isFieldValue, sharedFieldLinks, unfitSettings } from "./fieldRules.internal.js";
5
+ import { FIELD_KINDS, FIELD_TESTS, carryFieldNames, conditionProblem, dropFieldNames, fieldLinks, fieldProblems, fillsField, fitsField, holdsFieldNames, indexFieldNames, isFieldCondition, isFieldKind, isFieldName, isFieldOptions, isFieldValue, nameProblems, sharedFieldLinks, sharedFieldNames, unfitSettings } from "./fieldRules.internal.js";
6
6
  import { nanoid } from "nanoid";
7
7
  //#region src/features/field/lib/BaseFieldPlugin.ts
8
8
  const fieldText = ({ node: { label, options, value } }) => {
@@ -12,7 +12,7 @@ const FIELD_TYPE = "field";
12
12
  const fieldSchemaPlugin = definePlugin(FIELD_TYPE, {
13
13
  formats: ({ defineFormats, schema: { type } }) => defineFormats({
14
14
  docx: {
15
- dropped: "Word keeps each field answer and drops its settings.",
15
+ dropped: "Word keeps each field answer and drops its name and settings.",
16
16
  text: fieldText
17
17
  },
18
18
  html: {
@@ -22,6 +22,7 @@ const fieldSchemaPlugin = definePlugin(FIELD_TYPE, {
22
22
  const role = element.getAttribute("data-field-role");
23
23
  if (!isFieldKind(kind) || label === null || role === null) return;
24
24
  const fieldId = element.getAttribute("data-field-id");
25
+ const name = element.getAttribute("data-field-name");
25
26
  const claimIfValid = (attribute, is) => {
26
27
  let value;
27
28
  try {
@@ -38,6 +39,8 @@ const fieldSchemaPlugin = definePlugin(FIELD_TYPE, {
38
39
  const options = claimIfValid("data-field-options", isFieldOptions);
39
40
  const required = claimIfValid("data-field-required", (value) => typeof value === "boolean");
40
41
  const value = claimIfValid("data-field-value", isFieldValue);
42
+ const named = isFieldName(name);
43
+ if (named) preserve("data-field-name");
41
44
  preserve("data-field-id", "data-field-kind", "data-field-label", "data-field-role");
42
45
  return {
43
46
  children: [{ text: "" }],
@@ -46,6 +49,7 @@ const fieldSchemaPlugin = definePlugin(FIELD_TYPE, {
46
49
  ...fieldId === null ? {} : { fieldId },
47
50
  kind,
48
51
  label,
52
+ ...named ? { name } : {},
49
53
  ...options === void 0 ? {} : { options },
50
54
  ...required === void 0 ? {} : { required },
51
55
  role,
@@ -54,7 +58,7 @@ const fieldSchemaPlugin = definePlugin(FIELD_TYPE, {
54
58
  },
55
59
  encode: ({ content, node, preserve }) => {
56
60
  const json = (value) => value === void 0 ? void 0 : JSON.stringify(value);
57
- preserve("condition", "defaultValue", "fieldId", "kind", "label", "options", "required", "role", "value");
61
+ preserve("condition", "defaultValue", "fieldId", "kind", "label", "name", "options", "required", "role", "value");
58
62
  return {
59
63
  attributes: {
60
64
  "data-field-condition": json(node.condition),
@@ -62,6 +66,7 @@ const fieldSchemaPlugin = definePlugin(FIELD_TYPE, {
62
66
  "data-field-id": node.fieldId,
63
67
  "data-field-kind": node.kind,
64
68
  "data-field-label": node.label,
69
+ "data-field-name": node.name,
65
70
  "data-field-options": json(node.options),
66
71
  "data-field-required": json(node.required),
67
72
  "data-field-role": node.role,
@@ -107,6 +112,10 @@ const fieldSchemaPlugin = definePlugin(FIELD_TYPE, {
107
112
  }),
108
113
  kind: property.enum(FIELD_KINDS, { required: true }),
109
114
  label: property.string({ required: true }),
115
+ name: property.string({
116
+ validate: isFieldName,
117
+ validationVersion: 1
118
+ }),
110
119
  options: property.json({
111
120
  validate: isFieldOptions,
112
121
  validationVersion: 1
@@ -154,14 +163,63 @@ const UNKNOWN_FILL_MODE = Symbol("unknown fill mode");
154
163
  */
155
164
  const BaseFieldPlugin = fieldSchemaPlugin.extend(({ editor, schema: { properties, type }, store }) => {
156
165
  const isField = (node) => ElementApi.isElement(node) && node.type === type;
166
+ const writesOnlyFieldValues = (writes) => writes !== null && writes.every(({ element, modifications }) => isField(element) && modifications.every(({ key }) => key === "value"));
157
167
  let topStep = {
158
168
  mode: null,
159
169
  version: -1
160
170
  };
161
171
  let openWrite = null;
162
172
  const openWriteOfThisUpdate = () => openWrite?.updateId === getActiveEditorUpdateId(editor) ? openWrite : null;
173
+ const fieldsIn = (nodes) => nodes.flatMap((node) => {
174
+ if (isField(node)) return [node];
175
+ return ElementApi.isElement(node) ? fieldsIn(node.children) : [];
176
+ });
177
+ const documentOf = (reader, state) => {
178
+ const held = (fieldId) => {
179
+ const holder = state.unique.holder("fieldId", fieldId);
180
+ const node = holder && state.nodes.get(holder.key)?.[0];
181
+ return node && isField(node) ? node : void 0;
182
+ };
183
+ const roots = () => getActiveEditorUpdateId(reader) ? readRootEntries(reader) : reader.read.roots();
184
+ const page = () => readViewPage(state) ?? state.children();
185
+ const shown = () => [page(), ...roots().map(({ root }) => state.root(root))];
186
+ const listed = () => {
187
+ const nodes = shown().flatMap(fieldsIn);
188
+ const byId = /* @__PURE__ */ new Map();
189
+ const repeated = /* @__PURE__ */ new Set();
190
+ for (const node of nodes) {
191
+ if (typeof node.fieldId !== "string") continue;
192
+ if (byId.has(node.fieldId)) repeated.add(node.fieldId);
193
+ else byId.set(node.fieldId, node);
194
+ }
195
+ const lookup = (id) => repeated.has(id) ? held(id) : byId.get(id);
196
+ return {
197
+ lookup,
198
+ nodes
199
+ };
200
+ };
201
+ return {
202
+ held,
203
+ listed
204
+ };
205
+ };
206
+ const owner = getEditorRuntimeOwner(editor);
207
+ let countAtCommit = null;
208
+ let afterValueWrite = null;
209
+ const readCountAtCommit = () => {
210
+ if (!getActiveEditorUpdateId(owner)) countAtCommit = getMutationVersion(owner);
211
+ };
212
+ const namesOfUntouchedDraft = (reader, nodes) => {
213
+ const updateId = getActiveEditorUpdateId(reader);
214
+ if (!updateId) return sharedFieldNames(reader, nodes);
215
+ const count = getMutationVersion(owner);
216
+ if (afterValueWrite?.updateId === updateId) return afterValueWrite.count === count ? afterValueWrite.index : void 0;
217
+ return countAtCommit === count ? sharedFieldNames(reader, nodes) : void 0;
218
+ };
163
219
  return {
164
- activate({ onCleanup }) {
220
+ activate({ afterPublish, onCleanup }) {
221
+ afterPublish(readCountAtCommit);
222
+ onCleanup(owner.subscribeCommit(readCountAtCommit));
165
223
  topStep = {
166
224
  mode: store.get("fillRole") ?? null,
167
225
  version: getSnapshotVersion(editor)
@@ -185,12 +243,22 @@ const BaseFieldPlugin = fieldSchemaPlugin.extend(({ editor, schema: { properties
185
243
  version: commit.version
186
244
  };
187
245
  } : void 0;
188
- if (role === null || collaboration) return publish;
246
+ const from = getSnapshotVersion(editor);
247
+ const writesOnlyValues = holdsFieldNames(editor) ? writesOnlyFieldValues(readElementPropertyWrites(editor, {
248
+ before,
249
+ commit
250
+ })) : void 0;
251
+ const settle = writesOnlyValues === void 0 ? publish : () => {
252
+ publish?.();
253
+ if (writesOnlyValues) carryFieldNames(editor, from, commit.version);
254
+ else dropFieldNames(editor, from);
255
+ };
256
+ if (role === null || collaboration) return settle;
189
257
  if (replaces) throw refuse(`A fill as ${JSON.stringify(role)} cannot replace the document.`);
190
258
  if ((claimsHistoryReplay(commit) || effects.some(({ type: effect }) => effect.collab === "shared" || effect.persist) ? null : readElementPropertyWrites(editor, {
191
259
  before,
192
260
  commit
193
- }))?.every(({ element, modifications }) => isField(element) && element.role === role && modifications.every((modification) => modification.key === "value" && (modification.type === "unset" || modification.type === "set" && fitsField(element, modification.value))))) return publish;
261
+ }))?.every(({ element, modifications }) => isField(element) && element.role === role && modifications.every((modification) => modification.key === "value" && (modification.type === "unset" || modification.type === "set" && fitsField(element, modification.value))))) return settle;
194
262
  throw refuse(`A fill as ${JSON.stringify(role)} changes only the values of that role's fields.`);
195
263
  }));
196
264
  },
@@ -215,31 +283,9 @@ const BaseFieldPlugin = fieldSchemaPlugin.extend(({ editor, schema: { properties
215
283
  }
216
284
  }],
217
285
  read: ({ editor: reader, state }) => {
218
- const held = (fieldId) => {
219
- const holder = state.unique.holder("fieldId", fieldId);
220
- const node = holder && state.nodes.get(holder.key)?.[0];
221
- return node && isField(node) ? node : void 0;
222
- };
223
- const fieldsIn = (nodes) => nodes.flatMap((node) => {
224
- if (isField(node)) return [node];
225
- return ElementApi.isElement(node) ? fieldsIn(node.children) : [];
226
- });
227
- const listed = () => {
228
- const roots = getActiveEditorUpdateId(reader) ? readRootEntries(reader) : reader.read.roots();
229
- const nodes = [readViewPage(state) ?? state.children(), ...roots.map(({ root }) => state.root(root))].flatMap(fieldsIn);
230
- const byId = /* @__PURE__ */ new Map();
231
- const repeated = /* @__PURE__ */ new Set();
232
- for (const node of nodes) {
233
- if (typeof node.fieldId !== "string") continue;
234
- if (byId.has(node.fieldId)) repeated.add(node.fieldId);
235
- else byId.set(node.fieldId, node);
236
- }
237
- const lookup = (id) => repeated.has(id) ? held(id) : byId.get(id);
238
- return {
239
- lookup,
240
- nodes
241
- };
242
- };
286
+ readCountAtCommit();
287
+ const { held, listed } = documentOf(reader, state);
288
+ const names = (nodes) => namesOfUntouchedDraft(reader, nodes) ?? indexFieldNames(nodes());
243
289
  return {
244
290
  /**
245
291
  * The field whose `fieldId` is `fieldId`, in any root, or null when
@@ -254,20 +300,21 @@ const BaseFieldPlugin = fieldSchemaPlugin.extend(({ editor, schema: { properties
254
300
  applies: link.applies,
255
301
  fieldId,
256
302
  node,
257
- problems: fieldProblems(node, link)
303
+ problems: [...fieldProblems(node, link), ...node.name === void 0 ? [] : nameProblems(node, names(() => listed().nodes), held)]
258
304
  };
259
305
  },
260
306
  /** Every field of the document, in reading order. */
261
307
  fields: () => {
262
308
  const { lookup, nodes } = listed();
263
309
  const links = fieldLinks();
310
+ const index = nodes.some(({ name }) => name !== void 0) ? names(() => nodes) : void 0;
264
311
  return nodes.map((node) => {
265
312
  const link = lookup(node.fieldId) === node ? links.link(node, lookup) : links.linkCopy(node, lookup);
266
313
  return {
267
314
  applies: link.applies,
268
315
  fieldId: node.fieldId,
269
316
  node,
270
- problems: fieldProblems(node, link)
317
+ problems: [...fieldProblems(node, link), ...index ? nameProblems(node, index, lookup) : []]
271
318
  };
272
319
  });
273
320
  },
@@ -287,7 +334,8 @@ const BaseFieldPlugin = fieldSchemaPlugin.extend(({ editor, schema: { properties
287
334
  }
288
335
  };
289
336
  },
290
- update: ({ tx }) => {
337
+ update: ({ editor: writer, tx }) => {
338
+ const document = documentOf(writer, tx);
291
339
  const held = (fieldId) => {
292
340
  const holder = tx.unique.holder("fieldId", fieldId);
293
341
  const node = holder && tx.nodes.get(holder.key)?.[0];
@@ -302,7 +350,9 @@ const BaseFieldPlugin = fieldSchemaPlugin.extend(({ editor, schema: { properties
302
350
  * Insert a field and return its new `fieldId`. Throws when a value,
303
351
  * default or options do not fit `kind`, or the condition names no
304
352
  * field, or a test or value the named field's kind does not take,
305
- * or the settings name a `fieldId`.
353
+ * or the settings name a `fieldId`, or a `name` that is empty, has
354
+ * whitespace at either end, or holds a control character, a line or
355
+ * paragraph separator or a lone surrogate.
306
356
  */
307
357
  insert: txLocate(locateAt(1), (settings, options = {}) => {
308
358
  if ("fieldId" in settings) throw refusal("fieldId is not a setting");
@@ -316,11 +366,15 @@ const BaseFieldPlugin = fieldSchemaPlugin.extend(({ editor, schema: { properties
316
366
  /**
317
367
  * Change the settings or value of the field whose `fieldId` is
318
368
  * `fieldId`. A new kind or new options drop each value, default or
319
- * options the patch leaves out and the field no longer fits. Throws,
369
+ * options the patch leaves out and the field no longer fits. A
370
+ * `value`, a cleared one included, also goes to every other field of
371
+ * the same role and name, unless the field has the `name-conflict`
372
+ * problem; no other setting does. Throws,
320
373
  * and changes nothing, when no field holds `fieldId`, a setting the
321
374
  * patch names does not fit the field's kind, the patch removes `kind`,
322
- * `role` or `label` or names `fieldId`, or its condition names no
323
- * field, a test or value the named field's kind does not take, or a
375
+ * `role` or `label`, names `fieldId` or gives a `name` that `insert`
376
+ * refuses, or its condition names no field, a test or value the
377
+ * named field's kind does not take, or a
324
378
  * field it did not name before whose chain of conditions leads back
325
379
  * to this one. While a fill role is set, a missing field or a
326
380
  * setting that does not fit refuses the whole update instead, which
@@ -347,14 +401,29 @@ const BaseFieldPlugin = fieldSchemaPlugin.extend(({ editor, schema: { properties
347
401
  if (patch.condition.ref !== field.condition?.ref && fieldLinks().link(next, (id) => id === fieldId ? next : held(id)[0]).loop) throw refusal("its condition closes a loop");
348
402
  }
349
403
  const reshaped = "kind" in patch || "options" in patch;
404
+ const valuesOnly = Object.keys(patch).every((setting) => setting === "value");
405
+ const kept = field.name === void 0 || !valuesOnly ? void 0 : namesOfUntouchedDraft(writer, () => document.listed().nodes);
350
406
  tx.nodes.set({
351
407
  ...patch,
352
408
  ...reshaped ? Object.fromEntries(unfit.map((setting) => [setting, void 0])) : {}
353
409
  }, { at: key });
410
+ const written = document.held(fieldId);
411
+ if (!("value" in patch) || written?.name === void 0) return;
412
+ const index = kept ?? indexFieldNames(document.listed().nodes);
413
+ if (!nameProblems(written, index, document.held).includes("name-conflict")) for (const id of index.byRole.get(written.role)?.get(written.name) ?? []) {
414
+ if (id === fieldId) continue;
415
+ const [, at] = held(id);
416
+ if (at) tx.nodes.set({ value: written.value }, { at });
417
+ }
418
+ afterValueWrite = {
419
+ count: getMutationVersion(owner),
420
+ index,
421
+ updateId: getActiveEditorUpdateId(writer)
422
+ };
354
423
  })
355
424
  };
356
425
  }
357
426
  };
358
427
  });
359
428
  //#endregion
360
- export { BaseFieldPlugin, FIELD_TESTS, fitsField };
429
+ export { BaseFieldPlugin, FIELD_TESTS, fillsField, fitsField };