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,204 @@
1
+ import { getActiveEditorUpdateId, getEditorRuntimeOwner, getSnapshotVersion, readShownDocument } from "../../../facade.js";
2
+ import { failInvariant } from "../../../internal/failInvariant.js";
3
+ //#region src/features/field/lib/fieldRules.internal.ts
4
+ const FIELD_KINDS = [
5
+ "checkbox",
6
+ "choice",
7
+ "date",
8
+ "number",
9
+ "signature",
10
+ "text"
11
+ ];
12
+ /**
13
+ * The tests a condition may use on a field of each kind. `insert` and `update`
14
+ * refuse any other test, and a read reports it as `unsupported-test`.
15
+ */
16
+ const FIELD_TESTS = {
17
+ checkbox: ["equals", "not-equals"],
18
+ choice: [
19
+ "filled",
20
+ "blank",
21
+ "equals",
22
+ "not-equals"
23
+ ],
24
+ date: [
25
+ "filled",
26
+ "blank",
27
+ "equals",
28
+ "not-equals",
29
+ "above",
30
+ "below"
31
+ ],
32
+ number: [
33
+ "filled",
34
+ "blank",
35
+ "equals",
36
+ "not-equals",
37
+ "above",
38
+ "below"
39
+ ],
40
+ signature: ["filled", "blank"],
41
+ text: [
42
+ "filled",
43
+ "blank",
44
+ "equals",
45
+ "not-equals"
46
+ ]
47
+ };
48
+ const isFieldValue = (value) => typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
49
+ const isFieldOptions = (value) => Array.isArray(value) && value.every((option) => typeof option?.label === "string" && typeof option.value === "string") && new Set(value.map((option) => option.value)).size === value.length;
50
+ const isFieldCondition = (value) => {
51
+ if (!value || typeof value !== "object") return false;
52
+ const { ref, test, value: compared } = value;
53
+ return typeof ref === "string" && Object.values(FIELD_TESTS).some((tests) => tests.some((known) => known === test)) && (compared === void 0 || isFieldValue(compared));
54
+ };
55
+ const isFieldKind = (value) => FIELD_KINDS.some((kind) => kind === value);
56
+ const ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
57
+ const isIsoDate = (value) => {
58
+ if (!ISO_DATE_PATTERN.test(value)) return false;
59
+ const date = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
60
+ return !Number.isNaN(date.getTime()) && date.toISOString().startsWith(value);
61
+ };
62
+ /**
63
+ * Whether a value fits a field's kind: a boolean for a checkbox, one of its
64
+ * options' values for a choice, an ISO date string for a date, a finite number
65
+ * other than -0 for a number, a string with no line break for a text field,
66
+ * and a string for a signature field.
67
+ */
68
+ const fitsField = ({ kind, options = [] }, value) => {
69
+ switch (kind) {
70
+ case "checkbox": return typeof value === "boolean";
71
+ case "choice": return options.some((option) => option.value === value);
72
+ case "date": return typeof value === "string" && isIsoDate(value);
73
+ case "number": return typeof value === "number" && Number.isFinite(value) && !Object.is(value, -0);
74
+ case "text": return typeof value === "string" && !/[\n\r]/.test(value);
75
+ default: return typeof value === "string";
76
+ }
77
+ };
78
+ const conditionProblem = ({ test, value }, named) => {
79
+ if (!named) return "missing-target";
80
+ if (!FIELD_TESTS[named.kind].includes(test)) return "unsupported-test";
81
+ return (test === "filled" || test === "blank" ? value === void 0 : fitsField(named, value)) ? void 0 : "invalid-value";
82
+ };
83
+ const isFilled = (field, answer) => field.kind === "checkbox" ? answer === true : fitsField(field, answer) && (field.kind !== "text" && field.kind !== "signature" || /\S/.test(String(answer)));
84
+ const holds = ({ test, value }, target, answer) => {
85
+ const before = (a, b) => target.kind === "number" ? Number(a) < Number(b) : String(a) < String(b);
86
+ switch (test) {
87
+ case "above":
88
+ case "below":
89
+ if (answer === void 0) return false;
90
+ return test === "above" ? before(value, answer) : before(answer, value);
91
+ case "blank": return !isFilled(target, answer);
92
+ case "equals": return answer === value;
93
+ case "filled": return isFilled(target, answer);
94
+ default: return answer !== value;
95
+ }
96
+ };
97
+ const APPLIES = { applies: true };
98
+ const SKIPS = { applies: false };
99
+ const verdictOf = (applies) => applies ? APPLIES : SKIPS;
100
+ const SHAPED_SETTINGS = [
101
+ "defaultValue",
102
+ "options",
103
+ "value"
104
+ ];
105
+ const fitsSetting = (field, setting) => field[setting] === void 0 || (setting === "options" ? field.kind === "choice" : fitsField(field, field[setting]));
106
+ const unfitSettings = (field) => SHAPED_SETTINGS.filter((setting) => !fitsSetting(field, setting));
107
+ const fieldProblems = (field, link) => {
108
+ const own = unfitSettings(field).length === 0 ? [] : ["invalid-value"];
109
+ const conditioned = field.condition && conditionProblem(field.condition, link.target);
110
+ const problems = conditioned && !own.includes(conditioned) ? [...own, conditioned] : own;
111
+ return link.loop ? [...problems, "condition-loop"] : problems;
112
+ };
113
+ const judge = (condition, target, reached, settled) => {
114
+ if (reached.applies === null) return reached;
115
+ if (!reached.applies) return verdictOf(holds(condition, target, void 0));
116
+ if (fitsField(target, target.value)) return verdictOf(holds(condition, target, target.value));
117
+ if (!settled) return {
118
+ applies: null,
119
+ waitsOn: target.role
120
+ };
121
+ return verdictOf(holds(condition, target, target.kind === "checkbox" ? false : void 0));
122
+ };
123
+ const linksWith = (settles) => {
124
+ const chains = /* @__PURE__ */ new Map();
125
+ const byReadingRole = /* @__PURE__ */ new Map();
126
+ const chainOf = (field, held) => {
127
+ const path = [];
128
+ const places = /* @__PURE__ */ new Map();
129
+ let next = field;
130
+ while (next && !chains.has(next.fieldId) && !places.has(next.fieldId)) {
131
+ places.set(next.fieldId, path.length);
132
+ path.push(next);
133
+ next = next.condition && held(next.condition.ref);
134
+ }
135
+ const loopStart = next ? places.get(next.fieldId) : void 0;
136
+ for (let index = path.length - 1; index >= 0; index--) chains.set(path[index].fieldId, {
137
+ loop: loopStart !== void 0 && index >= loopStart,
138
+ target: path[index + 1] ?? next
139
+ });
140
+ return chains.get(field.fieldId) ?? failInvariant("A field was read before its link.");
141
+ };
142
+ const appliesOf = (field, held, readingRole = field.role) => {
143
+ const known = byReadingRole.get(readingRole) ?? /* @__PURE__ */ new Map();
144
+ byReadingRole.set(readingRole, known);
145
+ const waiting = [];
146
+ let at = field;
147
+ let reached = known.get(at.fieldId);
148
+ while (reached === void 0) {
149
+ const { loop, target } = chainOf(at, held);
150
+ if (loop || !at.condition || !target || conditionProblem(at.condition, target)) {
151
+ reached = APPLIES;
152
+ known.set(at.fieldId, reached);
153
+ break;
154
+ }
155
+ waiting.push([at, at.condition]);
156
+ at = target;
157
+ reached = known.get(at.fieldId);
158
+ }
159
+ for (let index = waiting.length - 1; index >= 0; index--) {
160
+ const [next, condition] = waiting[index];
161
+ reached = judge(condition, at, reached, settles(at.role, readingRole));
162
+ known.set(next.fieldId, reached);
163
+ at = next;
164
+ }
165
+ return reached;
166
+ };
167
+ return {
168
+ link: (field, held) => ({
169
+ ...chainOf(field, held),
170
+ ...appliesOf(field, held)
171
+ }),
172
+ linkCopy: (field, held) => {
173
+ const { condition } = field;
174
+ const target = condition && held(condition.ref);
175
+ return {
176
+ ...!condition || !target || conditionProblem(condition, target) ? APPLIES : judge(condition, target, appliesOf(target, held, field.role), settles(target.role, field.role)),
177
+ loop: false,
178
+ target
179
+ };
180
+ }
181
+ };
182
+ };
183
+ const fieldLinks = () => linksWith((role, readingRole) => role === readingRole);
184
+ const submittedFieldLinks = (roles) => linksWith((role) => roles.has(role));
185
+ const shared = /* @__PURE__ */ new WeakMap();
186
+ const linksOf = (key, version) => {
187
+ const kept = shared.get(key);
188
+ if (kept && kept.version === version) return kept.links;
189
+ const links = fieldLinks();
190
+ shared.set(key, {
191
+ links,
192
+ version
193
+ });
194
+ return links;
195
+ };
196
+ const sharedFieldLinks = (editor) => {
197
+ if (getActiveEditorUpdateId(editor)) return fieldLinks();
198
+ const shown = readShownDocument(editor);
199
+ if (shown) return linksOf(shown);
200
+ const owner = getEditorRuntimeOwner(editor);
201
+ return linksOf(owner, getSnapshotVersion(owner));
202
+ };
203
+ //#endregion
204
+ export { FIELD_KINDS, FIELD_TESTS, conditionProblem, fieldLinks, fieldProblems, fitsField, isFieldCondition, isFieldKind, isFieldOptions, isFieldValue, isFilled, sharedFieldLinks, submittedFieldLinks, unfitSettings };
@@ -1,5 +1,6 @@
1
- import { Qo as TxDeclaredMethod, zu as Range } from "../../index-BU6k1Aev.js";
2
- import { _ as BasePlugin, ko as PluginSelectorMethods, po as NormalizePluginSelectors } from "../../core-BJG8l_mk.js";
1
+ import { iu as TxDeclaredMethod, ps as Range } from "../../index-BXjLmx1n-CXk17buG.js";
2
+ import "../../htmlTypes-eT2ZGDAj.js";
3
+ import { Mo as PluginSelectorMethods, _ as BasePlugin, go as NormalizePluginSelectors } from "../../core-BqR-fEDp.js";
3
4
  type FindMatch = Readonly<{
4
5
  id: string;
5
6
  range: Range;
@@ -1,2 +1,2 @@
1
- import { a as FootnoteDefinition, c as FootnotePluginState, i as FootnoteAnchor, l as FootnoteReferenceElement, n as BaseFootnotePlugin, o as FootnoteDefinitionElement, r as CreateFootnoteDefinitionOptions, s as FootnoteElement, t as BaseFootnoteDefinitionPlugin } from "../../index-Bq3sdm3S.js";
1
+ import { a as FootnoteDefinition, c as FootnotePluginState, i as FootnoteAnchor, l as FootnoteReferenceElement, n as BaseFootnotePlugin, o as FootnoteDefinitionElement, r as CreateFootnoteDefinitionOptions, s as FootnoteElement, t as BaseFootnoteDefinitionPlugin } from "../../index-BsV2McRr.js";
2
2
  export { BaseFootnoteDefinitionPlugin, BaseFootnotePlugin, CreateFootnoteDefinitionOptions, FootnoteAnchor, FootnoteDefinition, FootnoteDefinitionElement, FootnoteElement, FootnotePluginState, FootnoteReferenceElement };
@@ -1,2 +1,2 @@
1
- import { a as InkCopyPlace, c as InkMargin, d as InkMarkInput, f as InkRun, g as InkViewState, h as InkTool, i as InkCopy, l as InkMark, m as InkSignPlace, n as InkBlockInput, o as InkDirection, p as InkSample, r as InkBrush, s as InkLine, t as BaseInkPlugin, u as InkMarkBlock } from "../../index-CT7miqQN.js";
1
+ import { a as InkCopyPlace, c as InkMargin, d as InkMarkInput, f as InkRun, g as InkViewState, h as InkTool, i as InkCopy, l as InkMark, m as InkSignPlace, n as InkBlockInput, o as InkDirection, p as InkSample, r as InkBrush, s as InkLine, t as BaseInkPlugin, u as InkMarkBlock } from "../../index-DwWQVwQt.js";
2
2
  export { BaseInkPlugin, InkBlockInput, InkBrush, InkCopy, InkCopyPlace, InkDirection, InkLine, InkMargin, InkMark, InkMarkBlock, InkMarkInput, InkRun, InkSample, InkSignPlace, InkTool, InkViewState };
@@ -1,53 +1,44 @@
1
- import { defineRuntimePlugin, getDocumentValueNode } from "../../../facade.js";
1
+ import { defineRuntimePlugin, getDocumentValueNode, getRecordSetVersion, readRecord, readShownRecords, recordSetIds } 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 { ElementIdPlugin } from "../../../lib/plugins/element-id/ElementIdPlugin.js";
5
5
  import { txLocate } from "../../../core.js";
6
- import { GONE, addGone, captureGone, flushGone, hasPendingGone, idOf } from "./inkGone.internal.js";
7
- import { readInkPlace } from "./inkPlaces.internal.js";
6
+ import { countInkDecode, decodePoints, encodePoints, isInkRefusal, refuse, roundSample } from "./inkCodec.internal.js";
7
+ import { COPIES, GONE, MARKS, addGone, captureGone, flushGone, hasPendingGone, idOf } from "./inkGone.internal.js";
8
+ import { advanceInkPlaces, readInkPlace, takeFirstChangeWalkMemo } from "./inkPlaces.internal.js";
8
9
  import { nanoid } from "nanoid";
9
10
  //#region src/features/ink/lib/BaseInkPlugin.ts
10
- const MARKS = "ink-marks";
11
- const COPIES = "ink-copies";
11
+ const copiesOf = ({ copies }) => {
12
+ const ids = typeof copies === "string" ? copies.split(" ") : Array.isArray(copies) ? copies : [];
13
+ return ids.length > 0 && ids.every((id) => typeof id === "string" && id !== "") ? ids : null;
14
+ };
15
+ const beta2MayUndoTo = (id) => id.startsWith("c_");
12
16
  const inkRecords = defineRuntimePlugin("ink-records", {
13
17
  schema: { records: {
14
- [COPIES]: { history: "retain" },
18
+ [COPIES]: {
19
+ history: "retain",
20
+ namedBy: {
21
+ keep: beta2MayUndoTo,
22
+ names: copiesOf,
23
+ set: MARKS
24
+ }
25
+ },
15
26
  [GONE]: { history: "retain" },
16
27
  [MARKS]: {}
17
28
  } },
18
29
  update: ({ editor, tx }) => ({ flush: txLocate(false, () => {
19
- flushGone(editor, tx, (id) => isNamed(tx.value().records, id));
30
+ flushGone(editor, tx);
20
31
  }) })
21
32
  });
22
- const NO_RECORDS = {};
23
- const namedCache = /* @__PURE__ */ new WeakMap();
24
- const namedBy = (set, fields) => {
25
- let ids = namedCache.get(set);
26
- if (!ids) {
27
- const found = /* @__PURE__ */ new Set();
28
- for (const record of Object.values(set)) for (const field of fields) {
29
- const id = record[field];
30
- if (typeof id === "string") found.add(id);
31
- }
32
- ids = found;
33
- namedCache.set(set, ids);
34
- }
35
- return ids;
36
- };
37
- const isNamed = (records, id) => namedBy(records?.[COPIES] ?? NO_RECORDS, ["block"]).has(id) || namedBy(records?.["ink-gone"] ?? NO_RECORDS, ["next", "previous"]).has(id);
38
33
  const decodedCopies = /* @__PURE__ */ new WeakMap();
39
34
  const decodedMarks = /* @__PURE__ */ new WeakMap();
35
+ const markLists = /* @__PURE__ */ new WeakMap();
36
+ const EMPTY_SET_VERSION = {};
40
37
  const frozen = (value) => {
41
38
  for (const field of Object.values(value)) if (typeof field === "object" && field !== null) frozen(field);
42
39
  Object.freeze(value);
43
40
  return value;
44
41
  };
45
- var InkRefusalError = class extends TypeError {
46
- name = "InkRefusalError";
47
- };
48
- const refuse = (message) => {
49
- throw new InkRefusalError(`Ink mark refused: ${message}.`);
50
- };
51
42
  const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
52
43
  const numberIn = (value, name, min = -Infinity, max = Infinity) => {
53
44
  if (!isNumber(value) || value < min || value > max) return refuse(`${name} must be a finite number from ${min} to ${max}`);
@@ -61,19 +52,22 @@ const textIn = (value, name) => typeof value === "string" && value.length > 0 ?
61
52
  const listIn = (value, name) => Array.isArray(value) ? value : refuse(`${name} must be an array`);
62
53
  const directionIn = (value) => value === "ltr" || value === "rtl" ? value : refuse("direction must be 'ltr' or 'rtl'");
63
54
  const sideIn = (value) => value === "left" || value === "right" ? value : refuse("margin.side must be 'left' or 'right'");
64
- const encodeSamples = (input) => {
55
+ const encodeSamples = (input, shape) => {
65
56
  const samples = listIn(input, "samples");
66
- const numbers = [];
67
57
  let time = 0;
68
58
  if (samples.length === 0) refuse("a mark needs at least one sample");
69
- for (const [at, sample] of samples.entries()) {
59
+ const checked = samples.map((sample, at) => {
70
60
  const name = `samples[${at}]`;
71
61
  if (!Array.isArray(sample) || sample.length !== 4) refuse(`${name} must be [x, y, pressure, time]`);
72
- numbers.push(numberIn(sample[0], `${name} x`), numberIn(sample[1], `${name} y`), numberIn(sample[2], `${name} pressure`, 0, 1));
73
62
  time = numberIn(sample[3], `${name} time`, time);
74
- numbers.push(time);
75
- }
76
- return numbers.join(" ");
63
+ return [
64
+ numberIn(sample[0], `${name} x`),
65
+ numberIn(sample[1], `${name} y`),
66
+ numberIn(sample[2], `${name} pressure`, 0, 1),
67
+ time
68
+ ];
69
+ });
70
+ return shape === "packed" ? encodePoints(checked.map(roundSample)) : checked.flat().join(" ");
77
71
  };
78
72
  const copyRecord = (copy, name) => {
79
73
  const text = typeof copy.text === "string" ? copy.text : refuse(`${name}.text must be a string`);
@@ -94,7 +88,8 @@ const copyRecord = (copy, name) => {
94
88
  width: numberIn(copy.width, `${name}.width`, 0)
95
89
  };
96
90
  };
97
- const encodeMark = (input, author) => {
91
+ const encodeMark = (input, author, shape = "packed") => {
92
+ const list = (values) => shape === "packed" ? values.join(" ") : values;
98
93
  if (typeof input !== "object" || input === null) refuse("input must be an object");
99
94
  const blocks = listIn(input.blocks, "blocks");
100
95
  const { margin } = input;
@@ -102,9 +97,16 @@ const encodeMark = (input, author) => {
102
97
  if (margin !== void 0 && blocks.length !== 1) refuse("a margin note sits beside exactly one block");
103
98
  if (new Set(blocks.map((block) => block?.block)).size !== blocks.length) refuse("a mark names each block once");
104
99
  const copies = blocks.map((block, at) => {
105
- const record = typeof block === "object" && block !== null ? copyRecord(block, `blocks[${at}]`) : refuse(`blocks[${at}] must be an object`);
100
+ const { block: id, height, lines, text, width } = typeof block === "object" && block !== null ? copyRecord(block, `blocks[${at}]`) : refuse(`blocks[${at}] must be an object`);
101
+ const record = {
102
+ block: id,
103
+ height,
104
+ lines: list(lines),
105
+ text,
106
+ width
107
+ };
106
108
  return {
107
- id: `c_${digest(JSON.stringify(record))}`,
109
+ id: `${shape === "packed" ? "p" : "c"}_${digest(JSON.stringify(record))}`,
108
110
  record
109
111
  };
110
112
  });
@@ -123,7 +125,7 @@ const encodeMark = (input, author) => {
123
125
  }
124
126
  }
125
127
  const brush = typeof input.brush === "object" && input.brush !== null ? input.brush : refuse("brush must be an object");
126
- const place = margin === void 0 ? { runs } : {
128
+ const place = margin === void 0 ? { runs: list(runs) } : {
127
129
  reach: numberIn(margin.reach, "margin.reach", 0),
128
130
  side: sideIn(margin.side)
129
131
  };
@@ -133,11 +135,10 @@ const encodeMark = (input, author) => {
133
135
  at: numberIn(input.at, "at", 0),
134
136
  author,
135
137
  color: textIn(brush.color, "brush.color"),
136
- copies: copies.map((copy) => copy.id),
138
+ copies: list(copies.map((copy) => copy.id)),
137
139
  direction: directionIn(input.direction),
138
140
  opacity: numberIn(brush.opacity, "brush.opacity", 0, 1),
139
- origins,
140
- points: encodeSamples(input.samples),
141
+ origins: list(origins),
141
142
  size: numberIn(brush.size, "brush.size", 0),
142
143
  ...place
143
144
  }
@@ -162,7 +163,7 @@ const readSaved = (read) => {
162
163
  try {
163
164
  return read();
164
165
  } catch (error) {
165
- if (error instanceof InkRefusalError) return void 0;
166
+ if (isInkRefusal(error)) return void 0;
166
167
  throw error;
167
168
  }
168
169
  };
@@ -170,13 +171,15 @@ const sameFields = (encoded, saved) => Object.entries(encoded).every(([key, valu
170
171
  const other = saved[key];
171
172
  return Array.isArray(value) && Array.isArray(other) ? value.length === other.length && value.every((item, at) => item === other[at]) : value === other;
172
173
  });
174
+ const savedList = (value, name) => typeof value === "string" ? value === "" ? [] : value.split(" ") : listIn(value, name);
173
175
  const savedNumbers = (value, name, stride) => {
174
- const numbers = listIn(value, name);
176
+ const numbers = savedList(value, name).map((number) => typeof number === "string" ? Number(number) : number);
175
177
  if (numbers.length % stride !== 0) refuse(`${name} must hold ${stride} numbers per entry`);
176
178
  return numbers.map((number, at) => numberIn(number, `${name}[${at}]`));
177
179
  };
178
180
  const groupsOf = (numbers, stride, build) => Array.from({ length: numbers.length / stride }, (_, index) => build(index * stride));
179
181
  const decodeCopy = (id, record) => readSaved(() => {
182
+ countInkDecode("copies");
180
183
  const numbers = savedNumbers(record.lines, "lines", 5);
181
184
  const lines = groupsOf(numbers, 5, (at) => ({
182
185
  end: numbers[at],
@@ -185,10 +188,11 @@ const decodeCopy = (id, record) => readSaved(() => {
185
188
  top: numbers[at + 2],
186
189
  width: numbers[at + 3]
187
190
  }));
188
- const { block, height, text, width } = copyRecord({
191
+ const { block, height, text, width, ...written } = copyRecord({
189
192
  ...record,
190
193
  lines
191
194
  }, "copy");
195
+ if (typeof record.lines === "string" && written.lines.join(" ") !== record.lines) refuse("a saved copy must be what add writes");
192
196
  return frozen({
193
197
  block,
194
198
  height,
@@ -199,10 +203,12 @@ const decodeCopy = (id, record) => readSaved(() => {
199
203
  });
200
204
  });
201
205
  const decodeMark = (id, record, copyOf) => readSaved(() => {
202
- const copies = listIn(record.copies, "copies").map((copy, at) => typeof copy === "string" && copyOf(copy) || refuse(`copies[${at}] must name a saved copy`));
206
+ countInkDecode("marks");
207
+ const shape = typeof record.copies === "string" ? "packed" : "beta2";
208
+ const copies = savedList(record.copies, "copies").map((copy, at) => typeof copy === "string" && copyOf(copy) || refuse(`copies[${at}] must name a saved copy`));
203
209
  const origins = savedNumbers(record.origins, "origins", 2);
204
210
  const runs = record.runs === void 0 ? [] : savedNumbers(record.runs, "runs", 5);
205
- const points = savedNumbers(typeof record.points === "string" ? record.points.split(" ").map(Number) : void 0, "points", 4);
211
+ const points = shape === "packed" ? [] : savedNumbers(record.points, "points", 4);
206
212
  const marked = groupsOf(runs, 5, (at) => ({
207
213
  copy: runs[at],
208
214
  run: {
@@ -231,7 +237,7 @@ const decodeMark = (id, record, copyOf) => readSaved(() => {
231
237
  reach: numberIn(record.reach, "reach"),
232
238
  side: sideIn(record.side)
233
239
  } } : {},
234
- samples: groupsOf(points, 4, (at) => [
240
+ samples: shape === "packed" ? decodePoints(textIn(record.points, "points")) : groupsOf(points, 4, (at) => [
235
241
  points[at],
236
242
  points[at + 1],
237
243
  points[at + 2],
@@ -248,8 +254,8 @@ const decodeMark = (id, record, copyOf) => readSaved(() => {
248
254
  text: copies[index].text,
249
255
  width: copies[index].width
250
256
  }))
251
- }, author).mark;
252
- if (!sameFields(written, record)) refuse("a saved mark must be what add writes");
257
+ }, author, shape).mark;
258
+ if (!sameFields(written, record) || shape === "beta2" && encodeSamples(mark.samples, "beta2") !== record.points) refuse("a saved mark must be what add writes");
253
259
  return frozen({
254
260
  ...mark,
255
261
  author,
@@ -257,12 +263,28 @@ const decodeMark = (id, record, copyOf) => readSaved(() => {
257
263
  id
258
264
  });
259
265
  });
266
+ const copyIn = (copies, id) => {
267
+ const record = readRecord(copies, id);
268
+ if (record && !decodedCopies.has(record)) decodedCopies.set(record, decodeCopy(id, record));
269
+ return record && decodedCopies.get(record);
270
+ };
271
+ const markIn = (id, record, copies) => {
272
+ const named = (copiesOf(record) ?? []).map((copy) => readRecord(copies, copy));
273
+ const decoded = decodedMarks.get(record);
274
+ if (decoded?.named.every((copy, at) => copy === named[at])) return decoded.mark;
275
+ const mark = decodeMark(id, record, (copy) => copyIn(copies, copy));
276
+ decodedMarks.set(record, {
277
+ mark,
278
+ named
279
+ });
280
+ return mark;
281
+ };
260
282
  /**
261
283
  * Pen marks on a document's text, saved as records of the document value.
262
284
  * Its updates add and remove marks, and its reads return them decoded and say
263
285
  * where each copy's block stands. It turns on block ids, because a mark names
264
- * its blocks by id, and saves where a deleted block stood in the update that
265
- * deletes it.
286
+ * its blocks by id, and saves where each marked block stands with its stroke,
287
+ * and again in a delete that leaves that place wrong.
266
288
  */
267
289
  const BaseInkPlugin = definePlugin("ink", {
268
290
  corrections: [{
@@ -284,63 +306,55 @@ const BaseInkPlugin = definePlugin("ink", {
284
306
  picked: [],
285
307
  tool: null
286
308
  }),
287
- on: { transactionChange: ({ after, before, changed, editor, tx }) => {
288
- if (!changed.has("structure") && !changed.has("properties")) return;
289
- for (const { node, path } of changed.removed()) {
290
- const id = idOf(node);
291
- if (id) captureGone(editor, tx.tags, after, {
292
- gap: path,
293
- id
294
- });
295
- }
296
- if (changed.has("structure")) return;
297
- for (const path of changed.paths()) {
298
- const id = idOf(getDocumentValueNode(before, path));
299
- if (id && id !== idOf(getDocumentValueNode(after, path))) captureGone(editor, tx.tags, after, {
300
- gap: path,
301
- id
302
- });
309
+ on: {
310
+ commit: ({ commit, editor }) => {
311
+ advanceInkPlaces(editor, commit);
312
+ },
313
+ transactionChange: ({ after, before, changed, editor, tx }) => {
314
+ if (!changed.has("structure") && !changed.has("properties")) return;
315
+ const memo = takeFirstChangeWalkMemo(editor);
316
+ for (const { node, path } of changed.removed()) {
317
+ const id = idOf(node);
318
+ if (id) captureGone(editor, tx, after, [path, id], memo);
319
+ }
320
+ if (changed.has("structure")) return;
321
+ for (const path of changed.paths()) {
322
+ const id = idOf(getDocumentValueNode(before, path));
323
+ if (id && id !== idOf(getDocumentValueNode(after, path))) captureGone(editor, tx, after, [path, id], memo);
324
+ }
303
325
  }
304
- } },
305
- read: ({ state }) => {
306
- const set = (name) => state.value().records?.[name];
307
- const copyReader = (saved = set(COPIES) ?? NO_RECORDS) => {
308
- const decoded = decodedCopies.get(saved) ?? /* @__PURE__ */ new Map();
309
- decodedCopies.set(saved, decoded);
310
- return (id) => {
311
- if (!decoded.has(id)) {
312
- const record = saved[id];
313
- decoded.set(id, record && decodeCopy(id, record));
314
- }
315
- return decoded.get(id);
316
- };
317
- };
318
- const copy = (id) => copyReader()(id);
326
+ },
327
+ read: ({ editor, state }) => {
328
+ const version = (set) => getRecordSetVersion(readShownRecords(editor), set);
329
+ const copy = (id) => copyIn(version(COPIES), id);
319
330
  return {
320
331
  /** The copy saved under `id`, or `undefined`. */
321
332
  copy,
322
333
  /** The mark saved under `id`, or `undefined`. */
323
334
  mark: (id) => {
324
- const record = set(MARKS)?.[id];
325
- return record && decodeMark(id, record, copyReader());
335
+ const record = readRecord(version(MARKS), id);
336
+ return record && markIn(id, record, version("ink-copies"));
326
337
  },
327
338
  /**
328
339
  * Every saved mark, oldest first, frozen, as the same list while the
329
- * saved marks and copies stay the same.
340
+ * saved marks and copies stay the same. Each mark stays the same object
341
+ * while its record and the copies it names stay the same.
330
342
  */
331
343
  marks: () => {
332
- const saved = set(MARKS) ?? NO_RECORDS;
333
- const copies = set(COPIES) ?? NO_RECORDS;
334
- let byCopies = decodedMarks.get(saved);
344
+ const saved = version(MARKS);
345
+ const copies = version(COPIES);
346
+ let byCopies = markLists.get(saved ?? EMPTY_SET_VERSION);
335
347
  if (!byCopies) {
336
348
  byCopies = /* @__PURE__ */ new WeakMap();
337
- decodedMarks.set(saved, byCopies);
349
+ markLists.set(saved ?? EMPTY_SET_VERSION, byCopies);
338
350
  }
339
- let marks = byCopies.get(copies);
351
+ let marks = byCopies.get(copies ?? EMPTY_SET_VERSION);
340
352
  if (!marks) {
341
- const copyOf = copyReader(copies);
342
- marks = Object.freeze(Object.entries(saved).flatMap(([id, record]) => decodeMark(id, record, copyOf) ?? []).sort((a, b) => a.at - b.at || (a.id < b.id ? -1 : 1)));
343
- byCopies.set(copies, marks);
353
+ marks = Object.freeze(recordSetIds(saved).flatMap((id) => {
354
+ const record = readRecord(saved, id);
355
+ return (record && markIn(id, record, copies)) ?? [];
356
+ }).sort((a, b) => a.at - b.at || (a.id < b.id ? -1 : 1)));
357
+ byCopies.set(copies ?? EMPTY_SET_VERSION, marks);
344
358
  }
345
359
  return marks;
346
360
  },
@@ -352,6 +366,7 @@ const BaseInkPlugin = definePlugin("ink", {
352
366
  */
353
367
  place: (copyId) => readInkPlace({
354
368
  copy,
369
+ editor,
355
370
  state
356
371
  }, copyId)
357
372
  };
@@ -359,18 +374,26 @@ const BaseInkPlugin = definePlugin("ink", {
359
374
  update: ({ editor, tx }) => ({
360
375
  /**
361
376
  * Save one mark and each copy not saved yet, as one undo step, and
362
- * return the mark's id. Refuses malformed input, writing nothing. A copy's
363
- * block deleted by this update, or by one of the last four updates that
364
- * deleted blocks, gets its place saved too.
377
+ * return the mark's id. Each sample saves rounded to a hundredth of a
378
+ * pixel, a thousandth of pressure and a whole millisecond. Refuses
379
+ * malformed input, and a sample whose hundredths of a pixel or
380
+ * milliseconds pass a quarter of `Number.MAX_SAFE_INTEGER`, writing
381
+ * nothing. A copy's
382
+ * block deleted by this update, by one of the last four updates that
383
+ * deleted blocks, or while a stroke that entered it was still unsaved,
384
+ * gets its place saved too.
385
+ * Each other copy's block and the block on each side of it get theirs.
365
386
  */
366
387
  add: txLocate(false, (input) => {
367
388
  const { copies, mark } = encodeMark(input, readEditorAuthor(editor));
389
+ const points = encodeSamples(input.samples, "packed");
368
390
  const id = `m_${nanoid()}`;
369
- for (const copy of copies) {
370
- tx.records.put(COPIES, copy.id, copy.record);
371
- addGone(editor, tx, copy.record.block);
372
- }
373
- tx.records.put(MARKS, id, mark);
391
+ for (const copy of copies) tx.records.put(COPIES, copy.id, copy.record);
392
+ addGone(editor, tx, copies);
393
+ tx.records.put(MARKS, id, {
394
+ ...mark,
395
+ points
396
+ });
374
397
  return id;
375
398
  }),
376
399
  /** Drop the marks `ids` names. Their copies stay. */