platejs 54.0.0-beta.2 → 54.0.0-beta.3
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-DY104TqL.d.ts} +2 -2
- package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-Deo6n6Fs.d.ts} +7 -3
- package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-CJX5bKuv.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-DAOYWuvC.d.ts} +2 -2
- package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-Dt-unJZY-DCddmbSD.d.ts} +10 -2
- package/dist/compiler/index.d.ts +2 -2
- package/dist/{core-BJG8l_mk.d.ts → core-ClHasORr.d.ts} +433 -95
- 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 +4 -2
- package/dist/docs/api/core/plate-plugin.md +3 -0
- package/dist/docs/api/core/plate-store.md +3 -3
- package/dist/docs/api/dom.md +14 -4
- package/dist/docs/api/editor-transforms.md +2 -1
- package/dist/docs/api/react-hooks.md +25 -11
- package/dist/docs/authored-changes.md +5 -2
- package/dist/docs/basic-blocks.md +42 -29
- package/dist/docs/blockquote.md +5 -3
- package/dist/docs/board.md +63 -8
- package/dist/docs/code-block.md +47 -0
- package/dist/docs/discussion.md +1 -1
- package/dist/docs/docx.md +1 -1
- package/dist/docs/dom-coverage.md +5 -0
- 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 +176 -8
- package/dist/docs/plugin-components.md +13 -10
- package/dist/docs/plugin-input-rules.md +4 -12
- 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 +29 -5
- package/dist/docx/export/lib/reviewPart.js +1 -1
- package/dist/docx/export/lib/reviewProjection.js +10 -8
- 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/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 +10 -10
- package/dist/features/field/index.d.ts +2 -0
- package/dist/features/field/index.js +2 -0
- package/dist/features/field/lib/BaseFieldPlugin.js +414 -0
- package/dist/features/field/lib/fieldRules.internal.js +42 -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 +533 -62
- 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 +1 -1
- package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
- package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +6 -2
- 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 +14 -8
- 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-cg_cWsaN.d.ts} +2 -31
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-D1CFXA-i.d.ts → index-8WO2vI0U.d.ts} +475 -143
- package/dist/{index-DaM37gF6.d.ts → index-B5mYEawV.d.ts} +37 -21
- package/dist/{index-Bq3sdm3S.d.ts → index-BZWFoUXt.d.ts} +5 -4
- package/dist/{index-DdIRduDG.d.ts → index-C0POz7rg.d.ts} +3 -2
- package/dist/{index-Bxfvicyy.d.ts → index-C1_JIhL4.d.ts} +4 -3
- package/dist/{index-DC_MNGyu.d.ts → index-C35V_hj0.d.ts} +3 -3
- package/dist/{index-kLKMc-pI.d.ts → index-C6ql9pKw.d.ts} +2 -2
- package/dist/{index-hsC_sOn2.d.ts → index-C9DiGDVj.d.ts} +35 -5
- package/dist/{index-DTgaSxKr.d.ts → index-CLsEe3LY.d.ts} +40 -4
- package/dist/{index-CT7miqQN.d.ts → index-CdOLsPaW.d.ts} +29 -9
- package/dist/{index-DLA2DUR2.d.ts → index-CktYvOgk.d.ts} +4 -3
- package/dist/{index-BBKGrsG3.d.ts → index-Cmuluh6f.d.ts} +1 -1
- package/dist/{index-BiQerPJS.d.ts → index-CzLwBZpY.d.ts} +2 -2
- package/dist/{index-DzD6BIFJ.d.ts → index-D3-2iM1b.d.ts} +7 -5
- package/dist/{index-Cl77E9yr.d.ts → index-DKOFvteF.d.ts} +2 -2
- package/dist/{index-iaZOhA76.d.ts → index-DPWyk3lG-DOYwohXO.d.ts} +1 -1
- package/dist/index-DQnjqtQa.d.ts +678 -0
- package/dist/{index-CcZbqPqk.d.ts → index-Do9pj1GK.d.ts} +73 -39
- package/dist/{index-BU6k1Aev.d.ts → index-DpltOCot-A2b3p3Eb.d.ts} +4735 -4586
- package/dist/{index-Bc2Yg_2j.d.ts → index-HPYawTae-BCUQLEWF.d.ts} +2 -2
- package/dist/{index-BkR7-GLI.d.ts → index-baQOK89E.d.ts} +2 -2
- package/dist/{index-D5W-p9bS.d.ts → index-oIJAZxc2.d.ts} +49 -4
- package/dist/{index-xdmCBvlT.d.ts → index-r7yb77Wy.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 +8 -2
- 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 +5 -15
- package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
- package/dist/markdown/index.d.ts +2 -2
- package/dist/markdown/index.js +2 -1
- package/dist/markdown/lib/MarkdownPlugin.js +16 -9
- package/dist/markdown/lib/RawHtmlPlugin.js +24 -0
- package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
- package/dist/markdown/lib/internal/markdownConversion.js +773 -74
- package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
- 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 +314 -0
- package/dist/markdown/lib/internal/markdownSegments.js +57 -48
- package/dist/markdown/lib/internal/markdownTags.js +22 -8
- 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/pagination/index.d.ts +1 -1
- package/dist/pagination/react/index.d.ts +4 -4
- package/dist/react/components/EditorContentView.internal.js +17 -8
- package/dist/react/components/EditorProvider.js +5 -5
- package/dist/react/components/Plate.js +103 -122
- 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/boardGesture.internal.js +6 -3
- package/dist/react/features/board/boardIndex.internal.js +7 -18
- package/dist/react/features/board/boardPictures.internal.js +19 -13
- package/dist/react/features/board/boardView.internal.js +184 -49
- package/dist/react/features/board/boardVoice.internal.js +10 -11
- package/dist/react/features/board/index.d.ts +64 -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 +34 -0
- package/dist/react/features/field/index.d.ts +312 -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 -29
- 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 +331 -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 +8 -7
- 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 +425 -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 +66 -21
- 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-aUwpNnAw.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,414 @@
|
|
|
1
|
+
import { EditorRefusalError, claimsHistoryReplay, getActiveEditorUpdateId, getActiveEditorUpdateTags, getSnapshotVersion, readElementPropertyWrites, readRootEntries, readViewPage, registerEditorTransactionGuard } from "../../../facade.js";
|
|
2
|
+
import { failInvariant } from "../../../internal/failInvariant.js";
|
|
3
|
+
import { definePlugin } from "../../../lib/plugin/definePlugin.js";
|
|
4
|
+
import { ElementApi, documentReplacement, locateAt, property, schema, target, txLocate } from "../../../core.js";
|
|
5
|
+
import { fieldLinks, sharedFieldLinks } from "./fieldRules.internal.js";
|
|
6
|
+
import { nanoid } from "nanoid";
|
|
7
|
+
//#region src/features/field/lib/BaseFieldPlugin.ts
|
|
8
|
+
const FIELD_KINDS = [
|
|
9
|
+
"checkbox",
|
|
10
|
+
"choice",
|
|
11
|
+
"date",
|
|
12
|
+
"number",
|
|
13
|
+
"signature",
|
|
14
|
+
"text"
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* The tests a condition may use on a field of each kind. `insert` and `update`
|
|
18
|
+
* refuse any other test, and a read reports it as `unsupported-test`.
|
|
19
|
+
*/
|
|
20
|
+
const FIELD_TESTS = {
|
|
21
|
+
checkbox: ["equals", "not-equals"],
|
|
22
|
+
choice: [
|
|
23
|
+
"filled",
|
|
24
|
+
"blank",
|
|
25
|
+
"equals",
|
|
26
|
+
"not-equals"
|
|
27
|
+
],
|
|
28
|
+
date: [
|
|
29
|
+
"filled",
|
|
30
|
+
"blank",
|
|
31
|
+
"equals",
|
|
32
|
+
"not-equals",
|
|
33
|
+
"above",
|
|
34
|
+
"below"
|
|
35
|
+
],
|
|
36
|
+
number: [
|
|
37
|
+
"filled",
|
|
38
|
+
"blank",
|
|
39
|
+
"equals",
|
|
40
|
+
"not-equals",
|
|
41
|
+
"above",
|
|
42
|
+
"below"
|
|
43
|
+
],
|
|
44
|
+
signature: ["filled", "blank"],
|
|
45
|
+
text: [
|
|
46
|
+
"filled",
|
|
47
|
+
"blank",
|
|
48
|
+
"equals",
|
|
49
|
+
"not-equals"
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
const ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
53
|
+
const isIsoDate = (value) => {
|
|
54
|
+
if (!ISO_DATE_PATTERN.test(value)) return false;
|
|
55
|
+
const date = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
|
|
56
|
+
return !Number.isNaN(date.getTime()) && date.toISOString().startsWith(value);
|
|
57
|
+
};
|
|
58
|
+
const isFieldValue = (value) => typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
59
|
+
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;
|
|
60
|
+
const isFieldCondition = (value) => {
|
|
61
|
+
if (!value || typeof value !== "object") return false;
|
|
62
|
+
const { ref, test, value: compared } = value;
|
|
63
|
+
return typeof ref === "string" && Object.values(FIELD_TESTS).some((tests) => tests.some((known) => known === test)) && (compared === void 0 || isFieldValue(compared));
|
|
64
|
+
};
|
|
65
|
+
const isFieldKind = (value) => FIELD_KINDS.some((kind) => kind === value);
|
|
66
|
+
const fieldText = ({ node: { label, options, value } }) => {
|
|
67
|
+
return (options?.find((option) => option.value === value)?.label ?? String(value ?? "")) || `[${label ?? ""}]`;
|
|
68
|
+
};
|
|
69
|
+
const FIELD_TYPE = "field";
|
|
70
|
+
const fieldSchemaPlugin = definePlugin(FIELD_TYPE, {
|
|
71
|
+
formats: ({ defineFormats, schema: { type } }) => defineFormats({
|
|
72
|
+
docx: {
|
|
73
|
+
dropped: "Word keeps each field answer and drops its settings.",
|
|
74
|
+
text: fieldText
|
|
75
|
+
},
|
|
76
|
+
html: {
|
|
77
|
+
decode: ({ element, preserve }) => {
|
|
78
|
+
const kind = element.getAttribute("data-field-kind");
|
|
79
|
+
const label = element.getAttribute("data-field-label");
|
|
80
|
+
const role = element.getAttribute("data-field-role");
|
|
81
|
+
if (!isFieldKind(kind) || label === null || role === null) return;
|
|
82
|
+
const fieldId = element.getAttribute("data-field-id");
|
|
83
|
+
const claimIfValid = (attribute, is) => {
|
|
84
|
+
let value;
|
|
85
|
+
try {
|
|
86
|
+
value = JSON.parse(element.getAttribute(attribute) ?? "");
|
|
87
|
+
} catch {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!is(value)) return void 0;
|
|
91
|
+
preserve(attribute);
|
|
92
|
+
return value;
|
|
93
|
+
};
|
|
94
|
+
const condition = claimIfValid("data-field-condition", isFieldCondition);
|
|
95
|
+
const defaultValue = claimIfValid("data-field-default-value", isFieldValue);
|
|
96
|
+
const options = claimIfValid("data-field-options", isFieldOptions);
|
|
97
|
+
const required = claimIfValid("data-field-required", (value) => typeof value === "boolean");
|
|
98
|
+
const value = claimIfValid("data-field-value", isFieldValue);
|
|
99
|
+
preserve("data-field-id", "data-field-kind", "data-field-label", "data-field-role");
|
|
100
|
+
return {
|
|
101
|
+
children: [{ text: "" }],
|
|
102
|
+
...condition === void 0 ? {} : { condition },
|
|
103
|
+
...defaultValue === void 0 ? {} : { defaultValue },
|
|
104
|
+
...fieldId === null ? {} : { fieldId },
|
|
105
|
+
kind,
|
|
106
|
+
label,
|
|
107
|
+
...options === void 0 ? {} : { options },
|
|
108
|
+
...required === void 0 ? {} : { required },
|
|
109
|
+
role,
|
|
110
|
+
...value === void 0 ? {} : { value }
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
encode: ({ content, node, preserve }) => {
|
|
114
|
+
const json = (value) => value === void 0 ? void 0 : JSON.stringify(value);
|
|
115
|
+
preserve("condition", "defaultValue", "fieldId", "kind", "label", "options", "required", "role", "value");
|
|
116
|
+
return {
|
|
117
|
+
attributes: {
|
|
118
|
+
"data-field-condition": json(node.condition),
|
|
119
|
+
"data-field-default-value": json(node.defaultValue),
|
|
120
|
+
"data-field-id": node.fieldId,
|
|
121
|
+
"data-field-kind": node.kind,
|
|
122
|
+
"data-field-label": node.label,
|
|
123
|
+
"data-field-options": json(node.options),
|
|
124
|
+
"data-field-required": json(node.required),
|
|
125
|
+
"data-field-role": node.role,
|
|
126
|
+
"data-field-value": json(node.value)
|
|
127
|
+
},
|
|
128
|
+
children: [content, { text: fieldText({ node }) }],
|
|
129
|
+
tag: "span"
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
match: [{
|
|
133
|
+
attributes: { "data-field-kind": true },
|
|
134
|
+
tag: "span"
|
|
135
|
+
}]
|
|
136
|
+
},
|
|
137
|
+
markdown: {
|
|
138
|
+
tag: type,
|
|
139
|
+
decode: ({ readTagAttributes, refuse }) => {
|
|
140
|
+
const { attributes, properties } = readTagAttributes();
|
|
141
|
+
if (!("kind" in properties && "label" in properties && "role" in properties)) return refuse("A field tag needs a kind, a label and a role.");
|
|
142
|
+
return {
|
|
143
|
+
...properties,
|
|
144
|
+
...typeof attributes.fieldId === "string" ? { fieldId: attributes.fieldId } : {},
|
|
145
|
+
children: [{ text: "" }],
|
|
146
|
+
type
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
encode: ({ encodeAttributes, encodeNodeAttributes, node }) => ({
|
|
150
|
+
attributes: [...encodeNodeAttributes(), ...encodeAttributes({ fieldId: node.fieldId })],
|
|
151
|
+
children: [],
|
|
152
|
+
name: type,
|
|
153
|
+
type: "mdxJsxTextElement"
|
|
154
|
+
})
|
|
155
|
+
},
|
|
156
|
+
plainText: { encode: fieldText }
|
|
157
|
+
}),
|
|
158
|
+
initialState: { fillRole: null },
|
|
159
|
+
schema: {
|
|
160
|
+
element: {
|
|
161
|
+
properties: {
|
|
162
|
+
defaultValue: property.json({
|
|
163
|
+
validate: isFieldValue,
|
|
164
|
+
validationVersion: 1
|
|
165
|
+
}),
|
|
166
|
+
kind: property.enum(FIELD_KINDS, { required: true }),
|
|
167
|
+
label: property.string({ required: true }),
|
|
168
|
+
options: property.json({
|
|
169
|
+
validate: isFieldOptions,
|
|
170
|
+
validationVersion: 1
|
|
171
|
+
}),
|
|
172
|
+
required: property.boolean(),
|
|
173
|
+
role: property.string({ required: true }),
|
|
174
|
+
value: property.json({
|
|
175
|
+
validate: isFieldValue,
|
|
176
|
+
validationVersion: 1
|
|
177
|
+
})
|
|
178
|
+
},
|
|
179
|
+
void: "inline"
|
|
180
|
+
},
|
|
181
|
+
properties: {
|
|
182
|
+
condition: schema.elementProperty(property.json({
|
|
183
|
+
validate: isFieldCondition,
|
|
184
|
+
validationVersion: 1
|
|
185
|
+
}), {
|
|
186
|
+
references: {
|
|
187
|
+
key: "fieldId",
|
|
188
|
+
map: (condition, renamed) => ({
|
|
189
|
+
...condition,
|
|
190
|
+
ref: renamed(condition.ref) ?? condition.ref
|
|
191
|
+
})
|
|
192
|
+
},
|
|
193
|
+
target: target.types([FIELD_TYPE]),
|
|
194
|
+
typeChange: "preserve-if-allowed"
|
|
195
|
+
}),
|
|
196
|
+
fieldId: schema.elementProperty(property.string({ generate: nanoid }), {
|
|
197
|
+
landing: "preserve",
|
|
198
|
+
role: "metadata",
|
|
199
|
+
target: target.types([FIELD_TYPE]),
|
|
200
|
+
typeChange: "preserve-if-allowed",
|
|
201
|
+
unique: true
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
const SHAPED_SETTINGS = [
|
|
207
|
+
"defaultValue",
|
|
208
|
+
"options",
|
|
209
|
+
"value"
|
|
210
|
+
];
|
|
211
|
+
/**
|
|
212
|
+
* Whether a value fits a field's kind: a boolean for a checkbox, one of its
|
|
213
|
+
* options' values for a choice, an ISO date string for a date, a finite number
|
|
214
|
+
* other than -0 for a number, a string with no line break for a text field,
|
|
215
|
+
* and a string for a signature field.
|
|
216
|
+
*/
|
|
217
|
+
const fitsField = ({ kind, options = [] }, value) => {
|
|
218
|
+
switch (kind) {
|
|
219
|
+
case "checkbox": return typeof value === "boolean";
|
|
220
|
+
case "choice": return options.some((option) => option.value === value);
|
|
221
|
+
case "date": return typeof value === "string" && isIsoDate(value);
|
|
222
|
+
case "number": return typeof value === "number" && Number.isFinite(value) && !Object.is(value, -0);
|
|
223
|
+
case "text": return typeof value === "string" && !/[\n\r]/.test(value);
|
|
224
|
+
default: return typeof value === "string";
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const fitsSetting = (field, setting) => field[setting] === void 0 || (setting === "options" ? field.kind === "choice" : fitsField(field, field[setting]));
|
|
228
|
+
const conditionProblem = ({ test, value }, named) => {
|
|
229
|
+
if (!named) return "missing-target";
|
|
230
|
+
if (!FIELD_TESTS[named.kind].includes(test)) return "unsupported-test";
|
|
231
|
+
return (test === "filled" || test === "blank" ? value === void 0 : fitsField(named, value)) ? void 0 : "invalid-value";
|
|
232
|
+
};
|
|
233
|
+
const fieldProblems = (field, link) => {
|
|
234
|
+
const own = SHAPED_SETTINGS.every((setting) => fitsSetting(field, setting)) ? [] : ["invalid-value"];
|
|
235
|
+
const conditioned = field.condition && conditionProblem(field.condition, link.target);
|
|
236
|
+
const problems = conditioned && !own.includes(conditioned) ? [...own, conditioned] : own;
|
|
237
|
+
return link.loop ? [...problems, "condition-loop"] : problems;
|
|
238
|
+
};
|
|
239
|
+
const refusal = (reason) => /* @__PURE__ */ new TypeError(`Field write refused: ${reason}.`);
|
|
240
|
+
const UNKNOWN_FILL_MODE = Symbol("unknown fill mode");
|
|
241
|
+
/**
|
|
242
|
+
* Fields: inline voids that each collect one value of a kind and hold a
|
|
243
|
+
* document-wide unique `fieldId`. A field's `condition` names another field
|
|
244
|
+
* by that id, so a paste that copies both names the copy.
|
|
245
|
+
*/
|
|
246
|
+
const BaseFieldPlugin = fieldSchemaPlugin.extend(({ editor, schema: { properties, type }, store }) => {
|
|
247
|
+
const isField = (node) => ElementApi.isElement(node) && node.type === type;
|
|
248
|
+
let topStep = {
|
|
249
|
+
mode: null,
|
|
250
|
+
version: -1
|
|
251
|
+
};
|
|
252
|
+
let openWrite = null;
|
|
253
|
+
const openWriteOfThisUpdate = () => openWrite?.updateId === getActiveEditorUpdateId(editor) ? openWrite : null;
|
|
254
|
+
return {
|
|
255
|
+
activate({ onCleanup }) {
|
|
256
|
+
topStep = {
|
|
257
|
+
mode: store.get("fillRole") ?? null,
|
|
258
|
+
version: getSnapshotVersion(editor)
|
|
259
|
+
};
|
|
260
|
+
onCleanup(registerEditorTransactionGuard(editor, ({ before, commit, effects }) => {
|
|
261
|
+
const role = store.get("fillRole") ?? null;
|
|
262
|
+
const write = openWriteOfThisUpdate();
|
|
263
|
+
const refuse = (message) => new EditorRefusalError({
|
|
264
|
+
reason: "field-fill",
|
|
265
|
+
role
|
|
266
|
+
}, message);
|
|
267
|
+
const { tags } = commit;
|
|
268
|
+
const collaboration = tags.includes("collaboration");
|
|
269
|
+
const switched = write !== null && (write.switched || write.mode !== role);
|
|
270
|
+
if (switched && !collaboration) throw refuse(`The fill role changed from ${JSON.stringify(write.mode)} to ${JSON.stringify(role)} inside one update.`);
|
|
271
|
+
const replaces = commit.annotations[documentReplacement.key] === true;
|
|
272
|
+
const publish = tags.includes("historic") || replaces || !tags.includes("history-skip") && (!commit.changes.empty || commit.effects.some(({ type: effect }) => effect.history !== "skip")) ? () => {
|
|
273
|
+
if (commit.version <= topStep.version) return;
|
|
274
|
+
topStep = {
|
|
275
|
+
mode: write === null || switched || tags.includes("historic") || replaces ? UNKNOWN_FILL_MODE : tags.includes("history-push") || write.mode === topStep.mode ? write.mode : UNKNOWN_FILL_MODE,
|
|
276
|
+
version: commit.version
|
|
277
|
+
};
|
|
278
|
+
} : void 0;
|
|
279
|
+
if (role === null || collaboration) return publish;
|
|
280
|
+
if (replaces) throw refuse(`A fill as ${JSON.stringify(role)} cannot replace the document.`);
|
|
281
|
+
if ((claimsHistoryReplay(commit) || effects.some(({ type: effect }) => effect.collab === "shared" || effect.persist) ? null : readElementPropertyWrites(editor, {
|
|
282
|
+
before,
|
|
283
|
+
commit
|
|
284
|
+
}))?.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;
|
|
285
|
+
throw refuse(`A fill as ${JSON.stringify(role)} changes only the values of that role's fields.`);
|
|
286
|
+
}));
|
|
287
|
+
},
|
|
288
|
+
corrections: [{
|
|
289
|
+
event: "properties",
|
|
290
|
+
query: { type },
|
|
291
|
+
correct: ({ tx }) => {
|
|
292
|
+
const mode = store.get("fillRole") ?? null;
|
|
293
|
+
const write = openWriteOfThisUpdate();
|
|
294
|
+
if (write) write.switched ||= write.mode !== mode;
|
|
295
|
+
else openWrite = {
|
|
296
|
+
mode,
|
|
297
|
+
switched: false,
|
|
298
|
+
updateId: getActiveEditorUpdateId(editor)
|
|
299
|
+
};
|
|
300
|
+
if (mode !== topStep.mode && !getActiveEditorUpdateTags(editor).some((tag) => [
|
|
301
|
+
"collaboration",
|
|
302
|
+
"historic",
|
|
303
|
+
"history-merge",
|
|
304
|
+
"history-skip"
|
|
305
|
+
].includes(tag))) tx.tags.add("history-push");
|
|
306
|
+
}
|
|
307
|
+
}],
|
|
308
|
+
read: ({ editor: reader, state }) => {
|
|
309
|
+
const held = (fieldId) => {
|
|
310
|
+
const holder = state.unique.holder("fieldId", fieldId);
|
|
311
|
+
const node = holder && state.nodes.get(holder.key)?.[0];
|
|
312
|
+
return node && isField(node) ? node : void 0;
|
|
313
|
+
};
|
|
314
|
+
const fieldsIn = (nodes) => nodes.flatMap((node) => {
|
|
315
|
+
if (isField(node)) return [node];
|
|
316
|
+
return ElementApi.isElement(node) ? fieldsIn(node.children) : [];
|
|
317
|
+
});
|
|
318
|
+
return {
|
|
319
|
+
/**
|
|
320
|
+
* The field whose `fieldId` is `fieldId`, in any root, or null when
|
|
321
|
+
* no field holds it. Looks up the field, then one field for each
|
|
322
|
+
* condition it follows along the chain.
|
|
323
|
+
*/
|
|
324
|
+
field: (fieldId) => {
|
|
325
|
+
const node = held(fieldId);
|
|
326
|
+
return node ? {
|
|
327
|
+
fieldId,
|
|
328
|
+
node,
|
|
329
|
+
problems: fieldProblems(node, sharedFieldLinks(reader)(node, held))
|
|
330
|
+
} : null;
|
|
331
|
+
},
|
|
332
|
+
/** Every field of the document, in reading order. */
|
|
333
|
+
fields: () => {
|
|
334
|
+
const fields = new Map([readViewPage(state) ?? state.children(), ...readRootEntries(reader).map(({ root }) => state.root(root))].flatMap(fieldsIn).map((node) => [node.fieldId, node]));
|
|
335
|
+
const link = fieldLinks();
|
|
336
|
+
return [...fields].map(([fieldId, node]) => ({
|
|
337
|
+
fieldId,
|
|
338
|
+
node,
|
|
339
|
+
problems: fieldProblems(node, link(node, (id) => fields.get(id)))
|
|
340
|
+
}));
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
},
|
|
344
|
+
update: ({ tx }) => {
|
|
345
|
+
const held = (fieldId) => {
|
|
346
|
+
const holder = tx.unique.holder("fieldId", fieldId);
|
|
347
|
+
const node = holder && tx.nodes.get(holder.key)?.[0];
|
|
348
|
+
return node && isField(node) ? [node, holder.key] : [];
|
|
349
|
+
};
|
|
350
|
+
const checkCondition = (condition, self) => {
|
|
351
|
+
const problem = conditionProblem(condition, condition.ref === self?.fieldId ? self : held(condition.ref)[0]);
|
|
352
|
+
if (problem) throw refusal(`its condition has ${problem}`);
|
|
353
|
+
};
|
|
354
|
+
return {
|
|
355
|
+
/**
|
|
356
|
+
* Insert a field and return its new `fieldId`. Throws when a value,
|
|
357
|
+
* default or options do not fit `kind`, or the condition names no
|
|
358
|
+
* field, or a test or value the named field's kind does not take,
|
|
359
|
+
* or the settings name a `fieldId`.
|
|
360
|
+
*/
|
|
361
|
+
insert: txLocate(locateAt(1), (settings, options = {}) => {
|
|
362
|
+
if ("fieldId" in settings) throw refusal("fieldId is not a setting");
|
|
363
|
+
const unfit = SHAPED_SETTINGS.find((setting) => !fitsSetting(settings, setting));
|
|
364
|
+
if (unfit) throw refusal(`${unfit} does not fit a ${settings.kind} field`);
|
|
365
|
+
if (settings.condition) checkCondition(settings.condition);
|
|
366
|
+
const field = tx.schema.create(type, settings);
|
|
367
|
+
tx.nodes.insert(field, options);
|
|
368
|
+
return tx.schema.getProperty(field, properties.fieldId) ?? failInvariant("A created field holds no fieldId.");
|
|
369
|
+
}),
|
|
370
|
+
/**
|
|
371
|
+
* Change the settings or value of the field whose `fieldId` is
|
|
372
|
+
* `fieldId`. A new kind or new options drop each value, default or
|
|
373
|
+
* options the patch leaves out and the field no longer fits. Throws,
|
|
374
|
+
* and changes nothing, when no field holds `fieldId`, a setting the
|
|
375
|
+
* patch names does not fit the field's kind, the patch removes `kind`,
|
|
376
|
+
* `role` or `label` or names `fieldId`, or its condition names no
|
|
377
|
+
* field, a test or value the named field's kind does not take, or a
|
|
378
|
+
* field it did not name before whose chain of conditions leads back
|
|
379
|
+
* to this one. While a fill role is set, a missing field or a
|
|
380
|
+
* setting that does not fit refuses the whole update instead, which
|
|
381
|
+
* then returns `undefined`.
|
|
382
|
+
*/
|
|
383
|
+
update: txLocate(false, (fieldId, patch) => {
|
|
384
|
+
if ("fieldId" in patch) throw refusal("fieldId is not a setting");
|
|
385
|
+
const role = store.get("fillRole");
|
|
386
|
+
const refusalForRole = (reason) => role == null ? refusal(reason) : new EditorRefusalError({
|
|
387
|
+
reason: "field-fill",
|
|
388
|
+
role
|
|
389
|
+
}, `A fill as ${JSON.stringify(role)} refused: ${reason}.`);
|
|
390
|
+
const [field, key] = held(fieldId);
|
|
391
|
+
if (!field) throw refusalForRole(`no field holds ${JSON.stringify(fieldId)}`);
|
|
392
|
+
const next = {
|
|
393
|
+
...field,
|
|
394
|
+
...patch
|
|
395
|
+
};
|
|
396
|
+
const unfit = SHAPED_SETTINGS.filter((setting) => !fitsSetting(next, setting));
|
|
397
|
+
const named = unfit.find((setting) => setting in patch);
|
|
398
|
+
if (named) throw refusalForRole(`${named} does not fit a ${next.kind} field`);
|
|
399
|
+
if (patch.condition) {
|
|
400
|
+
checkCondition(patch.condition, next);
|
|
401
|
+
if (patch.condition.ref !== field.condition?.ref && fieldLinks()(next, (id) => id === fieldId ? next : held(id)[0]).loop) throw refusal("its condition closes a loop");
|
|
402
|
+
}
|
|
403
|
+
const reshaped = "kind" in patch || "options" in patch;
|
|
404
|
+
tx.nodes.set({
|
|
405
|
+
...patch,
|
|
406
|
+
...reshaped ? Object.fromEntries(unfit.map((setting) => [setting, void 0])) : {}
|
|
407
|
+
}, { at: key });
|
|
408
|
+
})
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
});
|
|
413
|
+
//#endregion
|
|
414
|
+
export { BaseFieldPlugin, FIELD_TESTS, fitsField };
|
|
@@ -0,0 +1,42 @@
|
|
|
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 fieldLinks = () => {
|
|
5
|
+
const links = /* @__PURE__ */ new Map();
|
|
6
|
+
return (field, held) => {
|
|
7
|
+
const path = [];
|
|
8
|
+
const places = /* @__PURE__ */ new Map();
|
|
9
|
+
let next = field;
|
|
10
|
+
while (next && !links.has(next.fieldId) && !places.has(next.fieldId)) {
|
|
11
|
+
places.set(next.fieldId, path.length);
|
|
12
|
+
path.push(next);
|
|
13
|
+
next = next.condition && held(next.condition.ref);
|
|
14
|
+
}
|
|
15
|
+
const loopStart = next ? places.get(next.fieldId) : void 0;
|
|
16
|
+
for (let index = path.length - 1; index >= 0; index--) links.set(path[index].fieldId, {
|
|
17
|
+
loop: loopStart !== void 0 && index >= loopStart,
|
|
18
|
+
target: path[index + 1] ?? next
|
|
19
|
+
});
|
|
20
|
+
return links.get(field.fieldId) ?? failInvariant("A field was read before its link.");
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const shared = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
const linksOf = (key, version) => {
|
|
25
|
+
const kept = shared.get(key);
|
|
26
|
+
if (kept && kept.version === version) return kept.links;
|
|
27
|
+
const links = fieldLinks();
|
|
28
|
+
shared.set(key, {
|
|
29
|
+
links,
|
|
30
|
+
version
|
|
31
|
+
});
|
|
32
|
+
return links;
|
|
33
|
+
};
|
|
34
|
+
const sharedFieldLinks = (editor) => {
|
|
35
|
+
if (getActiveEditorUpdateId(editor)) return fieldLinks();
|
|
36
|
+
const shown = readShownDocument(editor);
|
|
37
|
+
if (shown) return linksOf(shown);
|
|
38
|
+
const owner = getEditorRuntimeOwner(editor);
|
|
39
|
+
return linksOf(owner, getSnapshotVersion(owner));
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { fieldLinks, sharedFieldLinks };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { eu as TxDeclaredMethod, us as Range } from "../../index-DpltOCot-A2b3p3Eb.js";
|
|
2
|
+
import "../../htmlTypes-cg_cWsaN.js";
|
|
3
|
+
import { Ao as PluginSelectorMethods, _ as BasePlugin, mo as NormalizePluginSelectors } from "../../core-ClHasORr.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-BZWFoUXt.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-CdOLsPaW.js";
|
|
2
2
|
export { BaseInkPlugin, InkBlockInput, InkBrush, InkCopy, InkCopyPlace, InkDirection, InkLine, InkMargin, InkMark, InkMarkBlock, InkMarkInput, InkRun, InkSample, InkSignPlace, InkTool, InkViewState };
|