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.
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES.md +56 -0
- package/dist/{AIChatRequestContext-BMVWhfPV.d.ts → AIChatRequestContext-DrUahdTc.d.ts} +2 -2
- package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-_7Ka6nY3.d.ts} +7 -3
- package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-D3Cb-QwH.d.ts} +7 -7
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/react/AIChatPlugin.js +113 -78
- package/dist/ai/react/CopilotPlugin.js +1 -1
- package/dist/ai/react/index.d.ts +23 -16
- package/dist/authored/index.d.ts +4 -4
- package/dist/code-block/codemirror/createCodeMirrorAdapter.js +12 -9
- package/dist/code-block/codemirror/index.d.ts +1 -1
- package/dist/{combobox-DkBGgyd3.d.ts → combobox-Dr0OYZIE.d.ts} +2 -2
- package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-DdwE6mYq-BogsHoUO.d.ts} +10 -2
- package/dist/compiler/index.d.ts +2 -2
- package/dist/{core-BJG8l_mk.d.ts → core-BqR-fEDp.d.ts} +493 -116
- package/dist/diff/index.d.ts +2 -2
- package/dist/docs/ai.md +4 -3
- package/dist/docs/api/core/plate-components.md +0 -19
- package/dist/docs/api/core/plate-controller.md +5 -3
- package/dist/docs/api/core/plate-plugin.md +3 -0
- package/dist/docs/api/core/plate-store.md +3 -3
- package/dist/docs/api/core.md +45 -5
- package/dist/docs/api/dom.md +11 -4
- package/dist/docs/api/editor-transforms.md +2 -1
- package/dist/docs/api/react-hooks.md +45 -13
- package/dist/docs/authored-changes.md +9 -4
- package/dist/docs/basic-blocks.md +42 -29
- package/dist/docs/block-placeholder.md +4 -2
- package/dist/docs/blockquote.md +5 -3
- package/dist/docs/board.md +118 -10
- package/dist/docs/code-block.md +47 -0
- package/dist/docs/comment.md +2 -2
- package/dist/docs/discussion.md +1 -1
- package/dist/docs/document-model.md +15 -3
- package/dist/docs/docx.md +1 -1
- package/dist/docs/dom-coverage.md +5 -0
- package/dist/docs/editor.md +50 -4
- package/dist/docs/examples/editable-voids.md +2 -3
- package/dist/docs/external-text.md +2 -0
- package/dist/docs/field.md +370 -0
- package/dist/docs/find.md +9 -6
- package/dist/docs/form.md +2 -0
- package/dist/docs/heading.md +6 -0
- package/dist/docs/installation/manual.md +0 -4
- package/dist/docs/link.md +3 -3
- package/dist/docs/llms.txt +4 -2
- package/dist/docs/markdown.md +270 -14
- package/dist/docs/plugin-components.md +13 -10
- package/dist/docs/plugin-input-rules.md +66 -15
- package/dist/docs/prompt-editor.md +205 -0
- package/dist/docs/roots.md +8 -6
- package/dist/docs/rtl.md +6 -4
- package/dist/docs/selection.md +7 -4
- package/dist/docs/suggestion.md +1 -1
- package/dist/docs/toolbar.md +26 -30
- package/dist/docs/upload.md +106 -17
- package/dist/docx/export/index.d.ts +3 -3
- package/dist/docx/export/lib/docxStaticComponents.js +12 -2
- package/dist/docx/export/lib/exportDocx.js +46 -17
- package/dist/docx/export/lib/internal/xml-builder.js +11 -16
- package/dist/docx/export/lib/reviewPart.js +1 -1
- package/dist/docx/export/lib/reviewProjection.js +52 -10
- package/dist/docx/import/index.d.ts +4 -4
- package/dist/docx/paste/index.d.ts +4 -4
- package/dist/dom/index.d.ts +1 -6
- package/dist/dom/plite-dom.internal.js +2 -2
- package/dist/excalidraw/index.d.ts +3 -2
- package/dist/excalidraw/react/index.d.ts +3 -2
- package/dist/facade.js +2 -2
- package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +13 -5
- package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +32 -10
- package/dist/features/board/index.d.ts +2 -2
- package/dist/features/board/lib/BaseBoardPlugin.js +14 -1
- package/dist/features/board/lib/boardStroke.internal.js +13 -1
- package/dist/features/board/lib/boardTypes.internal.js +16 -0
- package/dist/features/callout/index.d.ts +3 -2
- package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +14 -5
- package/dist/features/combobox/index.d.ts +2 -2
- package/dist/features/comments/BaseCommentsPlugin.js +33 -17
- package/dist/features/comments/index.d.ts +1 -1
- package/dist/features/date/index.d.ts +3 -2
- package/dist/features/details/index.d.ts +3 -2
- package/dist/features/details/lib/BaseDetailsPlugin.js +25 -12
- package/dist/features/field/index.d.ts +2 -0
- package/dist/features/field/index.js +4 -0
- package/dist/features/field/lib/BaseFieldPlugin.js +360 -0
- package/dist/features/field/lib/applyFieldValues.js +188 -0
- package/dist/features/field/lib/fieldRules.internal.js +204 -0
- package/dist/features/find/index.d.ts +3 -2
- package/dist/features/footnote/index.d.ts +1 -1
- package/dist/features/ink/index.d.ts +1 -1
- package/dist/features/ink/lib/BaseInkPlugin.js +126 -103
- package/dist/features/ink/lib/inkCodec.internal.js +130 -0
- package/dist/features/ink/lib/inkGone.internal.js +229 -48
- package/dist/features/ink/lib/inkPlaces.internal.js +534 -64
- package/dist/features/layout/index.d.ts +1 -1
- package/dist/features/link/lib/BaseLinkPlugin.js +6 -4
- package/dist/features/lint/index.d.ts +3 -2
- package/dist/features/media/index.d.ts +2 -2
- package/dist/features/media/index.js +2 -2
- package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
- package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +206 -4
- package/dist/features/mention/index.d.ts +5 -4
- package/dist/features/suggestion/index.d.ts +1 -1
- package/dist/features/table/index.d.ts +1 -1
- package/dist/features/table/lib/BaseTablePlugin.js +64 -15
- package/dist/features/table/lib/internal/selection.js +4 -2
- package/dist/features/toc/index.d.ts +1 -1
- package/dist/features/upload/index.d.ts +2 -2
- package/dist/features/upload/lib/BaseUploadPlugin.js +464 -250
- package/dist/history/index.d.ts +2 -2
- package/dist/html/index.d.ts +3 -3
- package/dist/html/server/index.d.ts +1 -1
- package/dist/{htmlTypes-DjeFG3P8.d.ts → htmlTypes-eT2ZGDAj.d.ts} +2 -31
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-DzD6BIFJ.d.ts → index-B33E1CRJ.d.ts} +295 -6
- package/dist/{index-Cl77E9yr.d.ts → index-B7moSod7.d.ts} +2 -2
- package/dist/{index-hsC_sOn2.d.ts → index-B8-5Sr7I.d.ts} +35 -5
- package/dist/{index-BiQerPJS.d.ts → index-B8QJDAmG.d.ts} +2 -2
- package/dist/{index-BBKGrsG3.d.ts → index-BTx5oK7k.d.ts} +1 -1
- package/dist/{index-iaZOhA76.d.ts → index-BWPcE4ac-Cto_IsNs.d.ts} +7 -1
- package/dist/{index-BU6k1Aev.d.ts → index-BXjLmx1n-CXk17buG.d.ts} +4781 -4584
- package/dist/{index-kLKMc-pI.d.ts → index-BXwU9QH6.d.ts} +2 -2
- package/dist/{index-DTgaSxKr.d.ts → index-BkwR-5hH.d.ts} +40 -4
- package/dist/{index-Bq3sdm3S.d.ts → index-BsV2McRr.d.ts} +5 -4
- package/dist/index-C9Fu-P4E.d.ts +773 -0
- package/dist/{index-D5W-p9bS.d.ts → index-Ca48r1ng.d.ts} +49 -4
- package/dist/{index-CcZbqPqk.d.ts → index-Cob_iBdu.d.ts} +116 -41
- package/dist/{index-Bxfvicyy.d.ts → index-CpY7Xnxw.d.ts} +4 -3
- package/dist/{index-BkR7-GLI.d.ts → index-DNQXzU-X.d.ts} +2 -2
- package/dist/{index-D1CFXA-i.d.ts → index-DPowErHa.d.ts} +471 -141
- package/dist/{index-DaM37gF6.d.ts → index-DShbzec2.d.ts} +38 -23
- package/dist/{index-DC_MNGyu.d.ts → index-DYdObeFQ.d.ts} +3 -3
- package/dist/{index-Bc2Yg_2j.d.ts → index-Dq3Jlj8O-BJ6NxZm0.d.ts} +2 -2
- package/dist/{index-CT7miqQN.d.ts → index-DwWQVwQt.d.ts} +29 -11
- package/dist/{index-xdmCBvlT.d.ts → index-JWgwL5l3.d.ts} +5 -2
- package/dist/{index-DLA2DUR2.d.ts → index-M781pyx9.d.ts} +4 -3
- package/dist/{index-DdIRduDG.d.ts → index-d7io3MzC.d.ts} +3 -2
- package/dist/index.d.ts +4 -4
- package/dist/{react/internal → internal}/penStroke.internal.js +1 -1
- package/dist/internal/plugin/OverridePlugin.js +101 -119
- package/dist/internal/plugin/collectPlateNodeMappings.js +5 -1
- package/dist/internal/plugin/pastedUploadFiles.js +4 -0
- package/dist/internal/plugin/resolvePlugin.js +1 -1
- package/dist/internal/plugin/resolvePlugins.js +3 -0
- package/dist/internal/plugin/uploadDrafts.js +6 -0
- package/dist/internal/utils/mergePlugins.js +1 -0
- package/dist/lib/plugins/element-id/ElementIdPlugin.js +14 -18
- package/dist/lib/plugins/html/HtmlPlugin.js +9 -0
- package/dist/lib/plugins/html/htmlSafety.js +1 -1
- package/dist/lib/plugins/input-rules/InputRulesPlugin.js +77 -28
- package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
- package/dist/markdown/index.d.ts +2 -2
- package/dist/markdown/index.js +3 -1
- package/dist/markdown/lib/MarkdownPlugin.js +14 -11
- package/dist/markdown/lib/RawHtmlPlugin.js +26 -0
- package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
- package/dist/markdown/lib/internal/markdownConversion.js +776 -74
- package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
- package/dist/markdown/lib/internal/markdownFootnoteWriter.js +35 -0
- package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
- package/dist/markdown/lib/internal/markdownIntrinsics.js +125 -43
- package/dist/markdown/lib/internal/markdownLine.js +5 -3
- package/dist/markdown/lib/internal/markdownMappings.js +19 -7
- package/dist/markdown/lib/internal/markdownOpenTail.js +381 -0
- package/dist/markdown/lib/internal/markdownRawHtml.js +353 -0
- package/dist/markdown/lib/internal/markdownSegments.js +57 -48
- package/dist/markdown/lib/internal/markdownTags.js +29 -9
- package/dist/markdown/lib/serializer/convertNodesSerialize.js +10 -8
- package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +226 -0
- package/dist/markdown/lib/serializer/listToMdastTree.js +2 -0
- package/dist/math/index.d.ts +3 -2
- package/dist/math/react/index.d.ts +4 -3
- package/dist/migrations/index.d.ts +3 -3
- package/dist/migrations/migratePlateV54.js +4 -6
- package/dist/migrations/migratePlateV54RetiredMarks.internal.js +23 -8
- package/dist/migrations/migratePlateV54Suggestions.internal.js +2 -2
- package/dist/migrations/v53-manifest.internal.js +4 -0
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/react/index.d.ts +4 -4
- package/dist/react/components/EditorContentView.internal.js +42 -23
- package/dist/react/components/EditorProvider.js +5 -5
- package/dist/react/components/Plate.js +102 -128
- package/dist/react/components/PlateContainer.js +40 -32
- package/dist/react/components/PlateController.js +28 -16
- package/dist/react/components/PlateRoot.internal.js +3 -2
- package/dist/react/core.js +4 -4
- package/dist/react/features/board/BoardSurface.js +116 -87
- package/dist/react/features/board/boardClipboard.internal.js +15 -5
- package/dist/react/features/board/boardExport.internal.js +470 -0
- package/dist/react/features/board/boardGesture.internal.js +6 -3
- package/dist/react/features/board/boardIndex.internal.js +7 -18
- package/dist/react/features/board/boardPictureStyles.internal.js +415 -0
- package/dist/react/features/board/boardPictures.internal.js +19 -13
- package/dist/react/features/board/boardView.internal.js +190 -50
- package/dist/react/features/board/boardVoice.internal.js +10 -11
- package/dist/react/features/board/index.d.ts +108 -18
- package/dist/react/features/callout/index.d.ts +3 -2
- package/dist/react/features/combobox/index.d.ts +8 -8
- package/dist/react/features/comments/index.d.ts +6 -5
- package/dist/react/features/date/index.d.ts +4 -3
- package/dist/react/features/details/index.d.ts +4 -3
- package/dist/react/features/field/FieldPlugin.js +35 -0
- package/dist/react/features/field/index.d.ts +315 -0
- package/dist/react/features/field/index.js +2 -0
- package/dist/react/features/footnote/index.d.ts +7 -6
- package/dist/react/features/format-painter/index.d.ts +4 -3
- package/dist/react/features/ink/InkContent.js +313 -0
- package/dist/react/features/ink/index.d.ts +57 -33
- package/dist/react/features/ink/index.js +2 -2
- package/dist/react/features/ink/inkCapture.internal.js +39 -17
- package/dist/react/features/ink/inkInput.internal.js +1 -1
- package/dist/react/features/ink/inkLayout.internal.js +6 -3
- package/dist/react/features/ink/inkPaint.internal.js +78 -2
- package/dist/react/features/ink/inkPlacement.internal.js +332 -104
- package/dist/react/features/ink/inkWatch.internal.js +7 -5
- package/dist/react/features/layout/index.d.ts +5 -4
- package/dist/react/features/media/index.d.ts +5 -4
- package/dist/react/features/mention/index.d.ts +6 -5
- package/dist/react/features/resizable/Resizable.js +4 -6
- package/dist/react/features/resizable/index.d.ts +5 -5
- package/dist/react/features/suggestion/index.d.ts +6 -5
- package/dist/react/features/table/TablePlugin.js +4 -11
- package/dist/react/features/table/index.d.ts +10 -8
- package/dist/react/features/table/useTableResize.js +10 -1
- package/dist/react/features/toc/index.d.ts +2 -2
- package/dist/react/features/upload/index.d.ts +11 -6
- package/dist/react/index.d.ts +6 -6
- package/dist/react/index.js +4 -4
- package/dist/react/internal/plate-context.js +434 -188
- package/dist/react/plite-react.js +2 -2
- package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +12 -10
- package/dist/react/stores/plate/useEditor.js +32 -14
- package/dist/react/stores/plate/useEditorHistory.js +55 -0
- package/dist/react/stores/plate/useEditorSelector.js +79 -21
- package/dist/react/utils/BlockPlaceholderPlugin.js +5 -2
- package/dist/react/utils/pipeRenderElement.internal.js +1 -1
- package/dist/react/utils/pluginRenderElement.internal.js +1 -1
- package/dist/react/virtualized.d.ts +4 -4
- package/dist/{source-CNKy99Th.d.ts → source-BGohy8vH.d.ts} +4 -4
- package/dist/static/index.d.ts +18 -18
- package/dist/static/internal/renderStaticHtmlWithOverrides.js +2 -2
- package/dist/static/internal/staticPresentation.js +4 -4
- package/dist/static/internal/writeStaticSelectionClipboardData.js +7 -2
- package/dist/tabbable/index.d.ts +1 -1
- package/dist/tabbable/react/index.d.ts +3 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/yjs/index.d.ts +1 -1
- package/dist/yjs/react/index.d.ts +6 -6
- package/package.json +20 -2
- package/dist/markdown/lib/serializer/convertTextsSerialize.js +0 -163
- package/dist/react/components/EditorSelectionView.js +0 -40
- package/dist/react/features/ink/InkLayer.js +0 -218
- 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 {
|
|
2
|
-
import
|
|
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-
|
|
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-
|
|
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 {
|
|
7
|
-
import {
|
|
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
|
|
11
|
-
const
|
|
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]: {
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
|
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:
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
|
265
|
-
*
|
|
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: {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
|
307
|
-
const
|
|
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 =
|
|
325
|
-
return record &&
|
|
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 =
|
|
333
|
-
const copies =
|
|
334
|
-
let byCopies =
|
|
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
|
-
|
|
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
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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.
|
|
363
|
-
*
|
|
364
|
-
*
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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. */
|