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
|
@@ -1,26 +1,121 @@
|
|
|
1
|
-
import { ElementApi, afterActiveTransactionEnds, getActiveEditorUpdateId, getDocumentValueNode, getEditorRuntimeOwner } from "../../../facade.js";
|
|
1
|
+
import { DocumentChange, ElementApi, afterActiveTransactionEnds, canonicalRecordJson, getActiveEditorUpdateId, getDocumentValueNode, getEditorRuntimeOwner, getRecordSetVersion, readRecord, readShownRecords, recordSetChanges } from "../../../facade.js";
|
|
2
2
|
//#region src/features/ink/lib/inkGone.internal.ts
|
|
3
|
+
const COPIES = "ink-copies";
|
|
3
4
|
const GONE = "ink-gone";
|
|
5
|
+
const MARKS = "ink-marks";
|
|
4
6
|
const ADD_LOOKBACK_UPDATES = 4;
|
|
5
7
|
const sessions = /* @__PURE__ */ new WeakMap();
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const sessionOf = (owner) => {
|
|
9
|
+
let session = sessions.get(owner);
|
|
10
|
+
if (!session) {
|
|
11
|
+
session = {
|
|
12
|
+
departed: /* @__PURE__ */ new Map(),
|
|
13
|
+
holdCounts: /* @__PURE__ */ new Map(),
|
|
14
|
+
kept: /* @__PURE__ */ new Map(),
|
|
15
|
+
pending: /* @__PURE__ */ new Map(),
|
|
16
|
+
queued: /* @__PURE__ */ new Map(),
|
|
17
|
+
recent: [],
|
|
18
|
+
runs: 0,
|
|
19
|
+
update: void 0
|
|
20
|
+
};
|
|
21
|
+
sessions.set(owner, session);
|
|
22
|
+
}
|
|
23
|
+
return session;
|
|
24
|
+
};
|
|
25
|
+
const keepHeldChains = ({ holdCounts, kept }, departed, order) => {
|
|
26
|
+
let grew = holdCounts.size > 0;
|
|
27
|
+
while (grew) {
|
|
28
|
+
grew = false;
|
|
29
|
+
const named = new Set([...kept.values()].flatMap(({ place }) => [place.next, place.previous]));
|
|
30
|
+
for (const [id, place] of departed) {
|
|
31
|
+
const saved = kept.get(id);
|
|
32
|
+
if (saved && saved.order >= order) continue;
|
|
33
|
+
if (saved || holdCounts.has(id) || named.has(id)) {
|
|
34
|
+
kept.set(id, {
|
|
35
|
+
order,
|
|
36
|
+
place: gapPlace(...place)
|
|
37
|
+
});
|
|
38
|
+
grew = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const holdInkBlock = (editor, block) => {
|
|
44
|
+
const session = sessionOf(getEditorRuntimeOwner(editor));
|
|
45
|
+
session.holdCounts.set(block, (session.holdCounts.get(block) ?? 0) + 1);
|
|
46
|
+
let released = false;
|
|
47
|
+
return () => {
|
|
48
|
+
if (released) return;
|
|
49
|
+
released = true;
|
|
50
|
+
const count = (session.holdCounts.get(block) ?? 1) - 1;
|
|
51
|
+
if (count > 0) session.holdCounts.set(block, count);
|
|
52
|
+
else session.holdCounts.delete(block);
|
|
53
|
+
if (session.holdCounts.size === 0) session.kept.clear();
|
|
11
54
|
};
|
|
12
55
|
};
|
|
56
|
+
const goneOf = (record) => record && {
|
|
57
|
+
...typeof record.next === "string" ? { next: record.next } : {},
|
|
58
|
+
...typeof record.previous === "string" ? { previous: record.previous } : {}
|
|
59
|
+
};
|
|
60
|
+
const goneIn = (version, id) => goneOf(readRecord(version, id));
|
|
61
|
+
const NAMING_FIELDS = [[COPIES, ["block"]], [GONE, [
|
|
62
|
+
"id",
|
|
63
|
+
"next",
|
|
64
|
+
"previous"
|
|
65
|
+
]]];
|
|
66
|
+
const namedBlocks = /* @__PURE__ */ new WeakMap();
|
|
67
|
+
const namedInkBlocks = (editor) => {
|
|
68
|
+
const owner = getEditorRuntimeOwner(editor);
|
|
69
|
+
const store = readShownRecords(editor);
|
|
70
|
+
let named = namedBlocks.get(owner);
|
|
71
|
+
if (!named) {
|
|
72
|
+
named = {
|
|
73
|
+
names: /* @__PURE__ */ new Map(),
|
|
74
|
+
versions: /* @__PURE__ */ new Map()
|
|
75
|
+
};
|
|
76
|
+
namedBlocks.set(owner, named);
|
|
77
|
+
}
|
|
78
|
+
const { names, versions } = named;
|
|
79
|
+
for (const [set, fields] of NAMING_FIELDS) {
|
|
80
|
+
const before = versions.get(set) ?? null;
|
|
81
|
+
const after = getRecordSetVersion(store, set);
|
|
82
|
+
for (const id of recordSetChanges(before, after)) for (const [version, step] of [[before, -1], [after, 1]]) {
|
|
83
|
+
const record = readRecord(version, id);
|
|
84
|
+
for (const field of fields) {
|
|
85
|
+
const block = field === "id" && record ? id : record?.[field];
|
|
86
|
+
if (typeof block !== "string") continue;
|
|
87
|
+
const key = `${field} ${block}`;
|
|
88
|
+
const ids = names.get(key) ?? /* @__PURE__ */ new Set();
|
|
89
|
+
if (step > 0) names.set(key, ids.add(id));
|
|
90
|
+
else if (ids.delete(id) && ids.size === 0) names.delete(key);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
versions.set(set, after);
|
|
94
|
+
}
|
|
95
|
+
return names;
|
|
96
|
+
};
|
|
13
97
|
const sameGone = (a, b) => a !== void 0 && a.next === b.next && a.previous === b.previous;
|
|
14
98
|
const idOf = (node) => ElementApi.isElement(node) && typeof node.id === "string" ? node.id : void 0;
|
|
15
|
-
const
|
|
99
|
+
const metrics = {
|
|
100
|
+
besides: 0,
|
|
101
|
+
chains: 0,
|
|
102
|
+
hops: 0,
|
|
103
|
+
reads: 0
|
|
104
|
+
};
|
|
105
|
+
const besideAt = (document, gap, step, skips) => {
|
|
106
|
+
metrics.besides += 1;
|
|
16
107
|
const parent = gap.slice(0, -1);
|
|
17
108
|
let [index] = gap.slice(-1);
|
|
18
109
|
if (step === -1) index -= 1;
|
|
19
110
|
while (true) {
|
|
20
|
-
const
|
|
111
|
+
const path = [...parent, index];
|
|
112
|
+
const node = index >= 0 ? getDocumentValueNode(document, path) : null;
|
|
21
113
|
if (node) {
|
|
22
114
|
const id = idOf(node);
|
|
23
|
-
if (id) return
|
|
115
|
+
if (id && !skips?.(path)) return {
|
|
116
|
+
id,
|
|
117
|
+
path
|
|
118
|
+
};
|
|
24
119
|
index += step;
|
|
25
120
|
} else if (parent.length > 0) {
|
|
26
121
|
const [up] = parent.splice(-1);
|
|
@@ -28,25 +123,67 @@ const beside = (document, gap, step) => {
|
|
|
28
123
|
} else return;
|
|
29
124
|
}
|
|
30
125
|
};
|
|
126
|
+
const beside = (document, gap, step) => besideAt(document, gap, step)?.id;
|
|
127
|
+
const goneFrom = (previous, next) => ({
|
|
128
|
+
...next ? { next } : {},
|
|
129
|
+
...previous ? { previous } : {}
|
|
130
|
+
});
|
|
131
|
+
const gapPlace = (after, gap) => goneFrom(beside(after, gap, -1), beside(after, gap, 1));
|
|
132
|
+
const blockAbove = (document, gap) => beside(document, gap, -1);
|
|
133
|
+
const reachGone = (walk, from, side, memo, count) => {
|
|
134
|
+
const seen = /* @__PURE__ */ new Set([from]);
|
|
135
|
+
let last = from;
|
|
136
|
+
let found;
|
|
137
|
+
count.chains += 1;
|
|
138
|
+
while (true) {
|
|
139
|
+
const to = memo?.[side].get(last);
|
|
140
|
+
if (to !== void 0 && !seen.has(to)) {
|
|
141
|
+
last = to;
|
|
142
|
+
seen.add(to);
|
|
143
|
+
}
|
|
144
|
+
const at = walk.record(last)?.[side];
|
|
145
|
+
if (at === void 0 || seen.has(at)) break;
|
|
146
|
+
count.hops += 1;
|
|
147
|
+
const holder = walk.holder(at);
|
|
148
|
+
if (holder !== void 0) {
|
|
149
|
+
found = {
|
|
150
|
+
holder,
|
|
151
|
+
id: at,
|
|
152
|
+
side
|
|
153
|
+
};
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
if (!walk.record(at)) break;
|
|
157
|
+
last = at;
|
|
158
|
+
seen.add(at);
|
|
159
|
+
}
|
|
160
|
+
if (memo && "walked" in memo) for (const block of seen) {
|
|
161
|
+
memo.walked.add(block);
|
|
162
|
+
if (block !== last) memo[side].set(block, last);
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
found,
|
|
166
|
+
last
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
const walkGone = (walk, id, memo, count) => {
|
|
170
|
+
const { found: above, last } = reachGone(walk, id, "previous", memo, count);
|
|
171
|
+
const next = (from) => reachGone(walk, from, "next", memo, count).found;
|
|
172
|
+
const belowTop = () => next(last);
|
|
173
|
+
const belowBlock = () => last === id ? void 0 : next(id);
|
|
174
|
+
return {
|
|
175
|
+
found: above ?? belowTop() ?? belowBlock(),
|
|
176
|
+
last
|
|
177
|
+
};
|
|
178
|
+
};
|
|
31
179
|
const currentSession = (editor) => {
|
|
32
180
|
const session = sessions.get(getEditorRuntimeOwner(editor));
|
|
33
181
|
return session?.update?.deref() === getActiveEditorUpdateId(editor) ? session : void 0;
|
|
34
182
|
};
|
|
35
|
-
const captureGone = (editor,
|
|
183
|
+
const captureGone = (editor, tx, after, [gap, id], memo) => {
|
|
36
184
|
const update = getActiveEditorUpdateId(editor);
|
|
37
185
|
if (!update) return;
|
|
38
|
-
const
|
|
39
|
-
let session = sessions.get(owner);
|
|
40
|
-
if (!session) {
|
|
41
|
-
session = {
|
|
42
|
-
departed: /* @__PURE__ */ new Map(),
|
|
43
|
-
pending: /* @__PURE__ */ new Set(),
|
|
44
|
-
recent: [],
|
|
45
|
-
runs: 0,
|
|
46
|
-
update: void 0
|
|
47
|
-
};
|
|
48
|
-
sessions.set(owner, session);
|
|
49
|
-
}
|
|
186
|
+
const session = sessionOf(getEditorRuntimeOwner(editor));
|
|
50
187
|
if (session.update?.deref() !== update) {
|
|
51
188
|
const departed = /* @__PURE__ */ new Map();
|
|
52
189
|
session.runs += 1;
|
|
@@ -54,7 +191,8 @@ const captureGone = (editor, tags, after, { gap, id }) => {
|
|
|
54
191
|
const { recent } = session;
|
|
55
192
|
session.update = new WeakRef(update);
|
|
56
193
|
session.departed = departed;
|
|
57
|
-
session.pending = /* @__PURE__ */ new
|
|
194
|
+
session.pending = /* @__PURE__ */ new Map();
|
|
195
|
+
session.queued = /* @__PURE__ */ new Map();
|
|
58
196
|
afterActiveTransactionEnds(editor, () => {
|
|
59
197
|
const at = recent.findIndex((run) => run.order > order);
|
|
60
198
|
recent.splice(at === -1 ? recent.length : at, 0, {
|
|
@@ -62,46 +200,89 @@ const captureGone = (editor, tags, after, { gap, id }) => {
|
|
|
62
200
|
order
|
|
63
201
|
});
|
|
64
202
|
if (recent.length > ADD_LOOKBACK_UPDATES) recent.shift();
|
|
65
|
-
|
|
203
|
+
keepHeldChains(session, departed, order);
|
|
204
|
+
}, { beforeListeners: true });
|
|
66
205
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
206
|
+
session.departed.set(id, [after, gap]);
|
|
207
|
+
if (tx.tags.has("collaboration")) return;
|
|
208
|
+
const names = namedInkBlocks(editor);
|
|
209
|
+
const { pending, queued } = session;
|
|
210
|
+
const walk = {
|
|
211
|
+
holder: (block) => tx.unique.holder("id", block) ?? void 0,
|
|
212
|
+
record: (block) => pending.get(block) ?? savedGone(editor, block)
|
|
213
|
+
};
|
|
214
|
+
const gone = (block) => !walk.holder(block);
|
|
215
|
+
const named = (side) => [...new Set([names, queued].flatMap((map) => [...map.get(`${side} ${id}`) ?? []]))].filter((block) => gone(block) && (!pending.has(block) || pending.get(block)?.[side] === id));
|
|
216
|
+
const asNext = named("next");
|
|
217
|
+
const namers = named("previous");
|
|
218
|
+
const watched = names.has(`block ${id}`) || session.holdCounts.has(id) || names.has(`id ${id}`) || pending.has(id);
|
|
219
|
+
if (!watched && asNext.length + namers.length === 0) return;
|
|
220
|
+
const place = gapPlace(after, gap);
|
|
221
|
+
const atGap = (block) => {
|
|
222
|
+
const { found } = walkGone(walk, block, memo, metrics);
|
|
223
|
+
return found ? found.id === place[found.side] : place.previous === void 0 && place.next === void 0;
|
|
224
|
+
};
|
|
225
|
+
const saved = walk.record(id);
|
|
226
|
+
const was = saved?.previous;
|
|
227
|
+
if (watched ? was !== void 0 && (was === place.previous || gone(was) && walk.record(was) !== void 0 && atGap(was)) && (asNext.length === 0 || saved?.next === place.next || reachGone(walk, id, "next", memo, metrics).found?.id === place.next) : [...asNext, ...namers].every(atGap)) return;
|
|
228
|
+
pending.set(id, place);
|
|
229
|
+
for (const key of Object.entries(place).map((pair) => pair.join(" "))) queued.set(key, (queued.get(key) ?? /* @__PURE__ */ new Set()).add(id));
|
|
74
230
|
};
|
|
75
231
|
const hasPendingGone = (editor) => !!currentSession(editor)?.pending.size;
|
|
76
|
-
const
|
|
77
|
-
|
|
232
|
+
const savedGone = (editor, id) => {
|
|
233
|
+
metrics.reads += 1;
|
|
234
|
+
return goneIn(getRecordSetVersion(readShownRecords(editor), GONE), id);
|
|
235
|
+
};
|
|
236
|
+
const writeGone = (editor, tx, ids, placeOf, writes) => {
|
|
78
237
|
const queue = [...ids];
|
|
79
238
|
const done = /* @__PURE__ */ new Set();
|
|
239
|
+
const texts = /* @__PURE__ */ new Map();
|
|
80
240
|
for (const id of queue) {
|
|
81
241
|
if (done.has(id)) continue;
|
|
82
242
|
done.add(id);
|
|
83
243
|
const place = placeOf(id);
|
|
84
|
-
if (!place
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (saved) tx.records.drop(GONE, id);
|
|
88
|
-
tx.records.put(GONE, id, place);
|
|
244
|
+
if (!place) continue;
|
|
245
|
+
if (!writes(savedGone(editor, id), place)) continue;
|
|
246
|
+
texts.set(id, canonicalRecordJson(place));
|
|
89
247
|
for (const neighbor of [place.next, place.previous]) if (neighbor !== void 0 && !done.has(neighbor)) queue.push(neighbor);
|
|
90
248
|
}
|
|
249
|
+
if (texts.size === 0) return;
|
|
250
|
+
tx.changes.apply(DocumentChange.fromJSON({
|
|
251
|
+
records: { [GONE]: Object.fromEntries(texts) },
|
|
252
|
+
version: 3
|
|
253
|
+
}));
|
|
91
254
|
};
|
|
92
|
-
const flushGone = (editor, tx
|
|
255
|
+
const flushGone = (editor, tx) => {
|
|
93
256
|
const session = currentSession(editor);
|
|
94
257
|
if (!session) return;
|
|
95
|
-
const {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
session.pending = /* @__PURE__ */ new Set();
|
|
99
|
-
writeGone(tx, ids, (id) => departed.get(id), (saved, place) => !sameGone(saved, place));
|
|
258
|
+
const { pending } = session;
|
|
259
|
+
session.pending = /* @__PURE__ */ new Map();
|
|
260
|
+
writeGone(editor, tx, pending.keys(), (id) => tx.unique.holder("id", id) ? void 0 : pending.get(id), (saved, place) => !sameGone(saved, place));
|
|
100
261
|
};
|
|
101
|
-
const addGone = (editor, tx,
|
|
262
|
+
const addGone = (editor, tx, copies) => {
|
|
263
|
+
const blocks = copies.map(({ record }) => record.block);
|
|
102
264
|
const current = currentSession(editor)?.departed;
|
|
103
|
-
const
|
|
104
|
-
|
|
265
|
+
const session = sessions.get(getEditorRuntimeOwner(editor));
|
|
266
|
+
const recent = session?.recent ?? [];
|
|
267
|
+
const standing = /* @__PURE__ */ new Map();
|
|
268
|
+
const stand = (id) => {
|
|
269
|
+
const holder = tx.unique.holder("id", id);
|
|
270
|
+
if (holder?.root !== "main" || standing.has(id)) return;
|
|
271
|
+
const { path } = holder;
|
|
272
|
+
const value = tx.value();
|
|
273
|
+
const past = [...path.slice(0, -1), (path.at(-1) ?? 0) + 1];
|
|
274
|
+
standing.set(id, goneFrom(beside(value, path, -1), beside(value, past, 1)));
|
|
275
|
+
};
|
|
276
|
+
for (const block of blocks) {
|
|
277
|
+
stand(block);
|
|
278
|
+
for (const side of Object.values(standing.get(block) ?? {})) stand(side);
|
|
279
|
+
}
|
|
280
|
+
writeGone(editor, tx, standing.keys(), (id) => standing.get(id), (saved, place) => !sameGone(saved, place));
|
|
281
|
+
writeGone(editor, tx, blocks, (id) => {
|
|
282
|
+
if (tx.unique.holder("id", id)) return void 0;
|
|
283
|
+
const departure = current?.get(id) ?? (session?.kept.has(id) ? void 0 : recent.findLast((run) => run.departed.has(id))?.departed.get(id));
|
|
284
|
+
return departure ? gapPlace(...departure) : session?.kept.get(id)?.place;
|
|
285
|
+
}, (saved) => saved === void 0);
|
|
105
286
|
};
|
|
106
287
|
//#endregion
|
|
107
|
-
export { GONE, addGone, captureGone, flushGone, goneIn, hasPendingGone, idOf };
|
|
288
|
+
export { COPIES, GONE, MARKS, addGone, besideAt, blockAbove, captureGone, flushGone, goneIn, hasPendingGone, holdInkBlock, idOf, namedInkBlocks, reachGone, walkGone };
|