plitejs 0.0.1 → 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/LICENSE +4 -1
- package/README.md +83 -0
- package/dist/annotation-store-metrics-Ccjkef45.js +12 -0
- package/dist/annotations/index.d.ts +2 -0
- package/dist/annotations/index.js +2 -0
- package/dist/authored/index.d.ts +596 -0
- package/dist/authored/index.js +18558 -0
- package/dist/authored-veto-DSnQcHGR.js +6 -0
- package/dist/browser-protocol-pvt4HFF7.js +5 -0
- package/dist/comparison-plan-CEQL0ooW.js +1338 -0
- package/dist/comparison-types-Dt-unJZY.d.ts +179 -0
- package/dist/create-editor-CkHtPWXV.js +1107 -0
- package/dist/diff/index.d.ts +32 -0
- package/dist/diff/index.js +1748 -0
- package/dist/dom/index.d.ts +2 -0
- package/dist/dom/index.js +2 -0
- package/dist/dom-Cgfscvnm.js +9220 -0
- package/dist/editor-owner-IUmkTeXz.js +171 -0
- package/dist/editor-view-lifetime-GJKa_QGh.js +23 -0
- package/dist/history/index.d.ts +170 -0
- package/dist/history/index.js +6718 -0
- package/dist/hyperscript/index.d.ts +2 -0
- package/dist/hyperscript/index.js +2 -0
- package/dist/hyperscript-FPuoArEi.js +299 -0
- package/dist/index-BpQx2UG4.d.ts +1093 -0
- package/dist/index-Cw-oC2ps.d.ts +190 -0
- package/dist/index-DPWyk3lG.d.ts +65 -0
- package/dist/index-DpltOCot.d.ts +9753 -0
- package/dist/index-HPYawTae.d.ts +119 -0
- package/dist/index-K0Za9YXc.d.ts +1246 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal/index.js +156 -0
- package/dist/mapped-view-store-ld-6uxEU.js +120 -0
- package/dist/native-grouping-input-DMNcsIaW.js +8 -0
- package/dist/pagination/index.d.ts +169 -0
- package/dist/pagination/index.js +2 -0
- package/dist/pagination/react.d.ts +33 -0
- package/dist/pagination/react.js +1509 -0
- package/dist/pagination-D_A8iPJP.js +1021 -0
- package/dist/plugin-DWzkJbnJ.js +50999 -0
- package/dist/range-geometry-BLAHRE11.d.ts +38 -0
- package/dist/range-geometry-BjeLHOnl.js +486 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +7 -0
- package/dist/react/virtualized.d.ts +13 -0
- package/dist/react/virtualized.js +209 -0
- package/dist/react-DZ15gmz2.js +1018 -0
- package/dist/retraction-BMem8Rfk.js +109 -0
- package/dist/src-cT1OTKP_.js +1386 -0
- package/dist/store-Cz2mXyDe.js +704 -0
- package/dist/testing/index.d.ts +183 -0
- package/dist/testing/index.js +96 -0
- package/dist/use-editor-dom-scope-BbMDSCpW.js +28354 -0
- package/dist/yjs/index.d.ts +2 -0
- package/dist/yjs/index.js +2 -0
- package/dist/yjs/react/index.d.ts +26 -0
- package/dist/yjs/react/index.js +85 -0
- package/dist/yjs-DOK-m7kl.js +13413 -0
- package/package.json +191 -43
|
@@ -0,0 +1,1107 @@
|
|
|
1
|
+
import { $ as first$1, Aa as nodes, Ac as assertNoDocumentViewRead, Ao as subscribeCommit, At as last$1, B as NodeApi, Bf as defineEffect, Bn as getChildList, Bt as point, Ci as withEditorRootChildrenGenerator, Cn as applyTransactionSpecToDocument, Cr as initializeEditorSchemaDocument, Cu as getEditorRuntime, Dc as authoredDocumentCapabilityPoint, Dr as invalidateEditorTransactionSpecs, Er as initializePublicState, Et as isInline, Eu as getEditorSchema, Fr as readEditor, Gn as getCurrentSelection, Go as admitEditorDocument, Hc as hasActiveAnchors, Ji as getFragment, Jr as saveEditorSchemaDocument, Kn as getCurrentSelectionRoot, Ko as documentAdmissionPoint, Ma as node, Mo as createEditorReadApi, Mt as levels$1, No as createEditorUpdateApi, Nr as loadOpenedRecords, Ot as isStart$1, Ou as setEditorRuntime, Ps as isEmptyElement, Rt as parent$1, Sa as getWordDistances, Si as withEditorRootChildren, Ss as mapSelectionThroughChange, Tr as initializeEditorSchemaSnapshot, Tt as isEnd$1, U as after, V as above$1, Vn as getChildren$1, W as before, Wo as admitDocument, Wr as repairEditorValue, Wt as range, Xr as seedUniqueMaps, Yn as getEditorDocumentValue, _ as markEditorDormant, _u as MAIN_ROOT_KEY, aa as range$1, ar as getLiveNode, bt as isBlock$1, cl as assertPluginPublicationInactive, d as extendEditor, di as snapshotInitialDocumentState, dl as getCompiledEditorSchema, dn as voidEditor, dr as getPathByNodeKey, dt as hasInlines$1, eu as failInvariant, fa as elementReadOnly, fu as LocationApi, ga as after$1, gl as initializeBasePluginRegistry, gs as assertSelectionSupported, ha as before$1, hr as getSnapshot$1, hu as PointApi, ip as getDefined, ir as getLastCommit, j as createCommandDispatch, ja as normalizeNodeMatch, jo as subscribeSource, js as constructLoadedDocumentChange, kc as createEditorAnchorApi, kn as createTransactionSpec, ko as subscribe, kt as isVoid, ll as createPluginRegistry, lr as getNodeKey, lt as getSnapshot, ml as getPluginRegistry, mu as RangeApi, nu as point$1, or as getLiveSelection, pl as getPluginContributions, qn as getEditorChildrenRoot, qo as onlyDocumentAdmission, s as createEditorViewPluginApis, sl as setEditorLifecycleErrorSink, sr as getLiveText, ts as createEditorSchema, tt as getChildren, u as destroyEditor, ul as finalizePluginRegistry, uu as isEditorContent, v as prepareInitialPluginPublication, va as resolveShouldMergeNodesRemovePrevNode, vi as transformEditorSnapshotInput, vl as registerEffectTypeInRegistry, vu as getCommonLocationRoot, wr as initializeEditorSchemaSelection, wt as isEmpty$1, xa as getCharacterDistance, xu as PathApi, y as prepareScopedPluginPublication, yi as updateEditor, zt as path$1 } from "./plugin-DWzkJbnJ.js";
|
|
2
|
+
/**
|
|
3
|
+
* Local, ephemeral screen-reader text emitted by an application command.
|
|
4
|
+
*
|
|
5
|
+
* Applications own localization and wording. React hosts consume the effect;
|
|
6
|
+
* headless editors retain it only on the commit that emitted it.
|
|
7
|
+
*/
|
|
8
|
+
const screenReaderAnnouncementEffect = defineEffect({
|
|
9
|
+
collab: "local",
|
|
10
|
+
history: "skip",
|
|
11
|
+
key: "screen-reader-announcement"
|
|
12
|
+
});
|
|
13
|
+
const getScreenReaderAnnouncements = (effects) => effects.flatMap((effect) => effect.type.key === "screen-reader-announcement" && typeof effect.value === "string" && effect.value.trim().length > 0 ? [effect.value] : []);
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/editor/above.ts
|
|
16
|
+
const assertNumericPath = (path) => {
|
|
17
|
+
for (const index of path) if (typeof index !== "number") throw new Error("Got non-numeric path index");
|
|
18
|
+
};
|
|
19
|
+
const above = ((editor, options = {}) => {
|
|
20
|
+
const { voids = false, mode = "lowest", at = getSnapshot(editor).selection, match, type } = options;
|
|
21
|
+
if (!at || !LocationApi.isLocation(at)) return;
|
|
22
|
+
let path;
|
|
23
|
+
path = path$1(editor, at);
|
|
24
|
+
assertNumericPath(path);
|
|
25
|
+
if (!LocationApi.isRange(at) || PathApi.equals(at.focus.path, at.anchor.path)) {
|
|
26
|
+
if (path.length === 0) return void 0;
|
|
27
|
+
path = PathApi.parent(path);
|
|
28
|
+
}
|
|
29
|
+
if (!NodeApi.has(editor, path)) return;
|
|
30
|
+
const [firstMatch] = levels$1(editor, {
|
|
31
|
+
at: path,
|
|
32
|
+
voids,
|
|
33
|
+
match,
|
|
34
|
+
reverse: mode === "lowest",
|
|
35
|
+
type
|
|
36
|
+
});
|
|
37
|
+
return firstMatch;
|
|
38
|
+
});
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/editor/edges.ts
|
|
41
|
+
const edges = (editor, at) => [point(editor, at, { edge: "start" }), point(editor, at, { edge: "end" })];
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/editor/first.ts
|
|
44
|
+
const first = (editor, at) => {
|
|
45
|
+
return node(editor, path$1(editor, at, { edge: "start" }));
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/editor/get-void.ts
|
|
49
|
+
const getVoid = (editor, options = {}) => above$1(editor, {
|
|
50
|
+
...options,
|
|
51
|
+
match: (n) => NodeApi.isElement(n) && isVoid(editor, n)
|
|
52
|
+
});
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/editor/has-blocks.ts
|
|
55
|
+
const hasBlocks = (editor, element) => element.children.some((n) => NodeApi.isElement(n) && isBlock$1(editor, n));
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/editor/has-inlines.ts
|
|
58
|
+
const hasInlines = (editor, element) => element.children.some((n) => NodeApi.isText(n) || isInline(editor, n));
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/editor/has-path.ts
|
|
61
|
+
const hasPath = (editor, path) => NodeApi.has(editor, path);
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/editor/has-texts.ts
|
|
64
|
+
const hasTexts = (_editor, element) => element.children.every((n) => NodeApi.isText(n));
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/editor/is-block.ts
|
|
67
|
+
const isBlock = (editor, value) => getEditorSchema(editor).isBlock(value);
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/editor/is-edge.ts
|
|
70
|
+
const isEdge = (editor, point, at) => isStart$1(editor, point, at) || isEnd$1(editor, point, at);
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/editor/is-empty.ts
|
|
73
|
+
const isEmpty = (editor, element) => isEmptyElement(element, getEditorSchema(editor).getElementBehavior(element));
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/editor/is-end.ts
|
|
76
|
+
const isEnd = (editor, point$3, at) => {
|
|
77
|
+
const end = point(editor, at, { edge: "end" });
|
|
78
|
+
return PointApi.equals(point$3, end);
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/editor/is-start.ts
|
|
82
|
+
const isStart = (editor, point$2, at) => {
|
|
83
|
+
const start = point(editor, at, { edge: "start" });
|
|
84
|
+
return PointApi.equals(point$2, start);
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/editor/last.ts
|
|
88
|
+
const hasLocationPath = (editor, at) => {
|
|
89
|
+
if (LocationApi.isPath(at)) return NodeApi.has(editor, at);
|
|
90
|
+
if (LocationApi.isPoint(at)) return NodeApi.has(editor, at.path);
|
|
91
|
+
const [start, end] = RangeApi.edges(at);
|
|
92
|
+
return NodeApi.has(editor, start.path) && NodeApi.has(editor, end.path);
|
|
93
|
+
};
|
|
94
|
+
const last = (editor, at, options = {}) => {
|
|
95
|
+
if (!hasLocationPath(editor, at)) return;
|
|
96
|
+
const path = path$1(editor, at, { edge: "end" });
|
|
97
|
+
if (typeof options.level === "number") return node(editor, path.slice(0, options.level + 1));
|
|
98
|
+
return node(editor, path);
|
|
99
|
+
};
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/editor/leaf.ts
|
|
102
|
+
const leaf = (editor, at, options = {}) => {
|
|
103
|
+
const path = path$1(editor, at, options);
|
|
104
|
+
return [NodeApi.leaf(editor, path), path];
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/editor/levels.ts
|
|
108
|
+
function* levels(editor, options = {}) {
|
|
109
|
+
const { at = getSnapshot(editor).selection, reverse = false, voids = false } = options;
|
|
110
|
+
const match = normalizeNodeMatch(options.type, options.match) ?? (() => true);
|
|
111
|
+
if (!at || !LocationApi.isLocation(at)) return;
|
|
112
|
+
const innerLevels = [];
|
|
113
|
+
const path = path$1(editor, at);
|
|
114
|
+
for (const [n, p] of NodeApi.levels(editor, path)) {
|
|
115
|
+
const isVoid$1 = !voids && NodeApi.isElement(n) && isVoid(editor, n);
|
|
116
|
+
if (match(n, p)) innerLevels.push([n, p]);
|
|
117
|
+
if (isVoid$1) break;
|
|
118
|
+
}
|
|
119
|
+
if (reverse) innerLevels.reverse();
|
|
120
|
+
yield* innerLevels;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/editor/next.ts
|
|
124
|
+
const next = ((editor, options = {}) => {
|
|
125
|
+
const { from = "after", mode = from === "child" ? "all" : "lowest", voids = false } = options;
|
|
126
|
+
const { at = getSnapshot(editor).selection } = options;
|
|
127
|
+
let match = normalizeNodeMatch(options.type, options.match);
|
|
128
|
+
if (!at || !LocationApi.isLocation(at)) return;
|
|
129
|
+
if (LocationApi.isPath(at) && at.length === 0) return;
|
|
130
|
+
let start;
|
|
131
|
+
if (from === "child" && LocationApi.isPath(at)) {
|
|
132
|
+
const childPath = at.concat(0);
|
|
133
|
+
if (NodeApi.has(editor, childPath)) {
|
|
134
|
+
start = childPath;
|
|
135
|
+
const baseMatch = match;
|
|
136
|
+
match = (node, path) => !PathApi.isAncestor(path, at) && !PathApi.equals(path, at) && (baseMatch?.(node, path) ?? true);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const pointAfterLocation = start ? void 0 : after(editor, at, { voids });
|
|
140
|
+
if (!start) {
|
|
141
|
+
if (!pointAfterLocation) return void 0;
|
|
142
|
+
start = pointAfterLocation.path;
|
|
143
|
+
}
|
|
144
|
+
const lastEntry = last$1(editor, []);
|
|
145
|
+
if (!lastEntry) return;
|
|
146
|
+
const [, to] = lastEntry;
|
|
147
|
+
const span = [start, to];
|
|
148
|
+
if (match == null) if (LocationApi.isPath(at)) {
|
|
149
|
+
const [parent] = parent$1(editor, at);
|
|
150
|
+
const children = NodeApi.isEditor(parent) ? getChildren(editor) : parent.children;
|
|
151
|
+
match = (n) => !NodeApi.isEditor(n) && children.includes(n);
|
|
152
|
+
} else match = () => true;
|
|
153
|
+
const [innerNext] = nodes(editor, {
|
|
154
|
+
at: span,
|
|
155
|
+
match,
|
|
156
|
+
mode,
|
|
157
|
+
voids
|
|
158
|
+
});
|
|
159
|
+
return innerNext;
|
|
160
|
+
});
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/editor/parent.ts
|
|
163
|
+
const parent = ((editor, at, options = {}) => {
|
|
164
|
+
const { match: _match, type: _type, ...pathOptions } = options;
|
|
165
|
+
const path = path$1(editor, at, pathOptions);
|
|
166
|
+
const entry = node(editor, PathApi.parent(path));
|
|
167
|
+
const match = normalizeNodeMatch(options.type, options.match);
|
|
168
|
+
return !match || match(entry[0], entry[1]) ? entry : void 0;
|
|
169
|
+
});
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/editor/path.ts
|
|
172
|
+
const path = (editor, at, options = {}) => {
|
|
173
|
+
const { depth, edge } = options;
|
|
174
|
+
let resolvedAt = at;
|
|
175
|
+
if (LocationApi.isPath(resolvedAt)) {
|
|
176
|
+
if (edge === "start") {
|
|
177
|
+
const [, firstPath] = NodeApi.first(editor, resolvedAt);
|
|
178
|
+
resolvedAt = firstPath;
|
|
179
|
+
} else if (edge === "end") {
|
|
180
|
+
const [, lastPath] = NodeApi.last(editor, resolvedAt);
|
|
181
|
+
resolvedAt = lastPath;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (LocationApi.isRange(resolvedAt)) if (edge === "start") resolvedAt = RangeApi.start(resolvedAt);
|
|
185
|
+
else if (edge === "end") resolvedAt = RangeApi.end(resolvedAt);
|
|
186
|
+
else resolvedAt = PathApi.common(resolvedAt.anchor.path, resolvedAt.focus.path);
|
|
187
|
+
if (LocationApi.isPoint(resolvedAt)) resolvedAt = resolvedAt.path;
|
|
188
|
+
if (depth != null) resolvedAt = resolvedAt.slice(0, depth);
|
|
189
|
+
return resolvedAt;
|
|
190
|
+
};
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/editor/positions.ts
|
|
193
|
+
const comparePoints = (left, right) => {
|
|
194
|
+
const pathComparison = PathApi.compare(left.path, right.path);
|
|
195
|
+
if (pathComparison !== 0) return pathComparison;
|
|
196
|
+
if (left.offset === right.offset) return 0;
|
|
197
|
+
return left.offset < right.offset ? -1 : 1;
|
|
198
|
+
};
|
|
199
|
+
const getAtomicNonTraversablePoint = (editor, path, voids) => {
|
|
200
|
+
if (voids) return null;
|
|
201
|
+
const atomicEntry = above$1(editor, {
|
|
202
|
+
at: path,
|
|
203
|
+
match: (node) => NodeApi.isElement(node) && (getEditorSchema(editor).isAtom(node) || getEditorSchema(editor).isReadOnly(node)),
|
|
204
|
+
mode: "highest",
|
|
205
|
+
voids: true
|
|
206
|
+
});
|
|
207
|
+
if (!atomicEntry) return null;
|
|
208
|
+
const [, atomicPath] = atomicEntry;
|
|
209
|
+
const start = point(editor, atomicPath, { edge: "start" });
|
|
210
|
+
return {
|
|
211
|
+
isStart: PathApi.equals(start.path, path),
|
|
212
|
+
point: start
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
const assertValidPoint = (entry, point) => {
|
|
216
|
+
if (point.offset < 0 || point.offset > entry.text.length) throw new Error(`Point offset ${point.offset} is outside text bounds for ${entry.path.join(".")}`);
|
|
217
|
+
};
|
|
218
|
+
function* walkTextEntries(children, parentPath, start, end, reverse) {
|
|
219
|
+
const depth = parentPath.length;
|
|
220
|
+
const first = PathApi.isAncestor(parentPath, start) ? start[depth] : 0;
|
|
221
|
+
const last = PathApi.isAncestor(parentPath, end) ? Math.min(end[depth], children.length - 1) : children.length - 1;
|
|
222
|
+
for (let index = reverse ? last : first; reverse ? index >= first : index <= last; index += reverse ? -1 : 1) {
|
|
223
|
+
const node = getDefined(children.at(index));
|
|
224
|
+
const path = [...parentPath, index];
|
|
225
|
+
if (NodeApi.isText(node)) {
|
|
226
|
+
yield {
|
|
227
|
+
path,
|
|
228
|
+
text: node.text
|
|
229
|
+
};
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
yield* walkTextEntries(node.children, path, start, end, reverse);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const getTextEntryAtPath = (editor, path) => {
|
|
236
|
+
const node = getLiveText(editor, path);
|
|
237
|
+
return node ? {
|
|
238
|
+
path: [...path],
|
|
239
|
+
text: node.text
|
|
240
|
+
} : null;
|
|
241
|
+
};
|
|
242
|
+
const getTextBlockPath = (editor, path) => {
|
|
243
|
+
for (let depth = path.length - 1; depth > 0; depth--) {
|
|
244
|
+
const candidatePath = path.slice(0, depth);
|
|
245
|
+
const node = getLiveNode(editor, candidatePath);
|
|
246
|
+
if (node && NodeApi.isElement(node) && !isInline(editor, node) && hasInlines$1(editor, node)) return candidatePath;
|
|
247
|
+
}
|
|
248
|
+
return path[0] == null ? [] : [path[0]];
|
|
249
|
+
};
|
|
250
|
+
const toPositionSegment = (editor, entry, start, end, voids) => {
|
|
251
|
+
const atomicPoint = getAtomicNonTraversablePoint(editor, entry.path, voids);
|
|
252
|
+
if (atomicPoint) {
|
|
253
|
+
if (!atomicPoint.isStart) return null;
|
|
254
|
+
if (comparePoints(atomicPoint.point, start) < 0 || comparePoints(atomicPoint.point, end) > 0) return null;
|
|
255
|
+
return {
|
|
256
|
+
atomic: true,
|
|
257
|
+
groupPath: getTextBlockPath(editor, atomicPoint.point.path),
|
|
258
|
+
path: atomicPoint.point.path,
|
|
259
|
+
start: atomicPoint.point.offset,
|
|
260
|
+
end: atomicPoint.point.offset,
|
|
261
|
+
text: ""
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const comparedToStart = PathApi.compare(entry.path, start.path);
|
|
265
|
+
const comparedToEnd = PathApi.compare(entry.path, end.path);
|
|
266
|
+
if (comparedToStart < 0 || comparedToEnd > 0) return null;
|
|
267
|
+
const from = comparedToStart === 0 ? start.offset : 0;
|
|
268
|
+
const to = comparedToEnd === 0 ? end.offset : entry.text.length;
|
|
269
|
+
return {
|
|
270
|
+
groupPath: getTextBlockPath(editor, entry.path),
|
|
271
|
+
path: entry.path,
|
|
272
|
+
start: from,
|
|
273
|
+
end: to,
|
|
274
|
+
text: entry.text.slice(from, to)
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
function* getPositionSegments(editor, range, { reverse, voids }) {
|
|
278
|
+
const [start, end] = RangeApi.edges(range);
|
|
279
|
+
const startEntry = getTextEntryAtPath(editor, start.path);
|
|
280
|
+
const endEntry = getTextEntryAtPath(editor, end.path);
|
|
281
|
+
if (!startEntry || !endEntry) return;
|
|
282
|
+
assertValidPoint(startEntry, start);
|
|
283
|
+
assertValidPoint(endEntry, end);
|
|
284
|
+
for (const entry of walkTextEntries(getEditorRuntime(editor).getChildList(), [], start.path, end.path, reverse)) {
|
|
285
|
+
const segment = toPositionSegment(editor, entry, start, end, voids);
|
|
286
|
+
if (segment && segment.end >= segment.start) yield segment;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const mapLogicalOffsetToPoint = (segments, logicalOffset, boundary = "backward") => {
|
|
290
|
+
let consumed = 0;
|
|
291
|
+
for (const segment of segments) {
|
|
292
|
+
const { length } = segment.text;
|
|
293
|
+
const end = consumed + length;
|
|
294
|
+
if (logicalOffset < end) return {
|
|
295
|
+
path: segment.path,
|
|
296
|
+
offset: segment.start + (logicalOffset - consumed)
|
|
297
|
+
};
|
|
298
|
+
if (logicalOffset === end) {
|
|
299
|
+
if (segment === segments.at(-1) || boundary === "backward") return {
|
|
300
|
+
path: segment.path,
|
|
301
|
+
offset: segment.end
|
|
302
|
+
};
|
|
303
|
+
const next = segments[segments.indexOf(segment) + 1];
|
|
304
|
+
return {
|
|
305
|
+
path: next.path,
|
|
306
|
+
offset: next.start
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
consumed = end;
|
|
310
|
+
}
|
|
311
|
+
const last = segments.at(-1);
|
|
312
|
+
if (!last) throw new Error("Cannot map a logical offset without text segments");
|
|
313
|
+
return {
|
|
314
|
+
path: last.path,
|
|
315
|
+
offset: last.end
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
const getTextRunBetweenAtomics = (editor, path) => {
|
|
319
|
+
const groupPath = getTextBlockPath(editor, path);
|
|
320
|
+
const block = [...getPositionSegments(editor, range(editor, groupPath), {
|
|
321
|
+
reverse: false,
|
|
322
|
+
voids: false
|
|
323
|
+
})].filter((segment) => PathApi.equals(segment.groupPath, groupPath));
|
|
324
|
+
const at = block.findIndex((segment) => !segment.atomic && PathApi.equals(segment.path, path));
|
|
325
|
+
if (at === -1) return null;
|
|
326
|
+
const before = block.findLastIndex((segment, index) => index < at && segment.atomic);
|
|
327
|
+
const after = block.findIndex((segment, index) => index > at && segment.atomic);
|
|
328
|
+
const segments = block.slice(before + 1, after === -1 ? void 0 : after);
|
|
329
|
+
return {
|
|
330
|
+
offsetOf: (point) => {
|
|
331
|
+
let consumed = 0;
|
|
332
|
+
for (const segment of segments) {
|
|
333
|
+
if (PathApi.equals(segment.path, point.path)) return consumed + Math.max(0, point.offset - segment.start);
|
|
334
|
+
consumed += segment.text.length;
|
|
335
|
+
}
|
|
336
|
+
return null;
|
|
337
|
+
},
|
|
338
|
+
pointAt: (offset, boundary) => mapLogicalOffsetToPoint(segments, offset, boundary),
|
|
339
|
+
text: segments.map((segment) => segment.text).join("")
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
function* groupPositionSegments(segments, keyOf, reverse) {
|
|
343
|
+
let group = [];
|
|
344
|
+
let key;
|
|
345
|
+
for (const segment of segments) {
|
|
346
|
+
const segmentKey = keyOf(segment);
|
|
347
|
+
if (key && !PathApi.equals(key, segmentKey)) {
|
|
348
|
+
yield reverse ? group.reverse() : group;
|
|
349
|
+
group = [];
|
|
350
|
+
}
|
|
351
|
+
key = segmentKey;
|
|
352
|
+
group.push(segment);
|
|
353
|
+
}
|
|
354
|
+
if (group.length > 0) yield reverse ? group.reverse() : group;
|
|
355
|
+
}
|
|
356
|
+
const pushUniquePoint = (points, point) => {
|
|
357
|
+
const previous = points.at(-1);
|
|
358
|
+
if (!previous || comparePoints(previous, point) !== 0) points.push(point);
|
|
359
|
+
};
|
|
360
|
+
const getPreviousTraversableSegment = (segments, index) => {
|
|
361
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
362
|
+
const segment = segments[i];
|
|
363
|
+
if (segment && !segment.atomic) return segment;
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
};
|
|
367
|
+
const getNextTraversableSegment = (segments, index) => {
|
|
368
|
+
for (let i = index + 1; i < segments.length; i++) {
|
|
369
|
+
const segment = segments[i];
|
|
370
|
+
if (segment && !segment.atomic) return segment;
|
|
371
|
+
}
|
|
372
|
+
return null;
|
|
373
|
+
};
|
|
374
|
+
const collectCharacterPositions = (segments, reverse = false) => {
|
|
375
|
+
const points = [];
|
|
376
|
+
const orderedSegments = reverse ? [...segments].reverse() : segments;
|
|
377
|
+
const firstSegment = orderedSegments[0];
|
|
378
|
+
if (!firstSegment) return points;
|
|
379
|
+
pushUniquePoint(points, {
|
|
380
|
+
path: firstSegment.path,
|
|
381
|
+
offset: reverse ? firstSegment.end : firstSegment.start
|
|
382
|
+
});
|
|
383
|
+
for (const segment of orderedSegments) {
|
|
384
|
+
const index = segments.indexOf(segment);
|
|
385
|
+
if (segment.atomic) {
|
|
386
|
+
const traversable = reverse ? getPreviousTraversableSegment(segments, index) : getNextTraversableSegment(segments, index);
|
|
387
|
+
pushUniquePoint(points, {
|
|
388
|
+
path: segment.path,
|
|
389
|
+
offset: segment.start
|
|
390
|
+
});
|
|
391
|
+
pushUniquePoint(points, {
|
|
392
|
+
path: traversable?.path ?? segment.path,
|
|
393
|
+
offset: traversable ? reverse ? traversable.end : traversable.start : segment.end
|
|
394
|
+
});
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (reverse) {
|
|
398
|
+
let logicalOffset = segment.text.length;
|
|
399
|
+
while (logicalOffset > 0) {
|
|
400
|
+
const distance = getCharacterDistance(segment.text.slice(0, logicalOffset), true);
|
|
401
|
+
logicalOffset = Math.max(0, logicalOffset - distance);
|
|
402
|
+
pushUniquePoint(points, {
|
|
403
|
+
path: segment.path,
|
|
404
|
+
offset: segment.start + logicalOffset
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
let logicalOffset = 0;
|
|
410
|
+
while (logicalOffset < segment.text.length) {
|
|
411
|
+
const distance = getCharacterDistance(segment.text.slice(logicalOffset));
|
|
412
|
+
logicalOffset = Math.min(segment.text.length, logicalOffset + distance);
|
|
413
|
+
pushUniquePoint(points, {
|
|
414
|
+
path: segment.path,
|
|
415
|
+
offset: segment.start + logicalOffset
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return points;
|
|
420
|
+
};
|
|
421
|
+
const collectRunBoundaryPoints = (segments, reverse = false) => {
|
|
422
|
+
const first = getDefined(segments[0]);
|
|
423
|
+
const last = getDefined(segments.at(-1));
|
|
424
|
+
const start = {
|
|
425
|
+
path: first.path,
|
|
426
|
+
offset: first.start
|
|
427
|
+
};
|
|
428
|
+
const end = {
|
|
429
|
+
path: last.path,
|
|
430
|
+
offset: last.end
|
|
431
|
+
};
|
|
432
|
+
if (comparePoints(start, end) === 0) return [start];
|
|
433
|
+
return reverse ? [end, start] : [start, end];
|
|
434
|
+
};
|
|
435
|
+
function* positions(editor, options = {}) {
|
|
436
|
+
const { at = getCurrentSelection(editor) ?? [], unit = "offset", reverse = false, voids = false } = options;
|
|
437
|
+
if (!LocationApi.isLocation(at)) return;
|
|
438
|
+
const range$3 = range(editor, at);
|
|
439
|
+
const [start, end] = RangeApi.edges(range$3);
|
|
440
|
+
if (comparePoints(start, end) === 0) {
|
|
441
|
+
yield {
|
|
442
|
+
path: [...start.path],
|
|
443
|
+
offset: start.offset
|
|
444
|
+
};
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
const segments = getPositionSegments(editor, range$3, {
|
|
448
|
+
reverse,
|
|
449
|
+
voids
|
|
450
|
+
});
|
|
451
|
+
if (unit === "offset") {
|
|
452
|
+
for (const segment of segments) if (reverse) for (let offset = segment.end; offset >= segment.start; offset -= 1) yield {
|
|
453
|
+
path: segment.path,
|
|
454
|
+
offset
|
|
455
|
+
};
|
|
456
|
+
else for (let offset = segment.start; offset <= segment.end; offset += 1) yield {
|
|
457
|
+
path: segment.path,
|
|
458
|
+
offset
|
|
459
|
+
};
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
for (const group of groupPositionSegments(segments, (segment) => segment.groupPath, reverse)) {
|
|
463
|
+
if (unit === "block" || unit === "line") {
|
|
464
|
+
yield* collectRunBoundaryPoints(group, reverse);
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
if (unit === "character") {
|
|
468
|
+
yield* collectCharacterPositions(group, reverse);
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const text = group.map((segment) => segment.text).join("");
|
|
472
|
+
const logicalPositions = [reverse ? text.length : 0];
|
|
473
|
+
let consumed = 0;
|
|
474
|
+
for (const distance of getWordDistances(text, reverse)) {
|
|
475
|
+
consumed = Math.min(text.length, consumed + distance);
|
|
476
|
+
logicalPositions.push(reverse ? text.length - consumed : consumed);
|
|
477
|
+
}
|
|
478
|
+
const boundary = reverse ? "forward" : "backward";
|
|
479
|
+
for (const position of logicalPositions) yield mapLogicalOffsetToPoint(group, position, boundary);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/editor/previous.ts
|
|
484
|
+
const previous = ((editor, options = {}) => {
|
|
485
|
+
const { from = "before", mode = "lowest", voids = false } = options;
|
|
486
|
+
const { at = getSnapshot(editor).selection } = options;
|
|
487
|
+
let match = normalizeNodeMatch(options.type, options.match);
|
|
488
|
+
if (!at || !LocationApi.isLocation(at)) return;
|
|
489
|
+
if (LocationApi.isPath(at) && at.length === 0) return;
|
|
490
|
+
if (options.sibling) {
|
|
491
|
+
if (!LocationApi.isPath(at)) return;
|
|
492
|
+
if (!PathApi.hasPrevious(at)) return;
|
|
493
|
+
const previousPath = PathApi.previous(at);
|
|
494
|
+
if (!NodeApi.has(editor, previousPath)) return;
|
|
495
|
+
return node(editor, previousPath);
|
|
496
|
+
}
|
|
497
|
+
let start;
|
|
498
|
+
if (from === "parent" && LocationApi.isPath(at) && at.length > 1) {
|
|
499
|
+
start = at;
|
|
500
|
+
const baseMatch = match;
|
|
501
|
+
match = (node, path) => !PathApi.isAfter(path, at) && !PathApi.equals(path, at) && (baseMatch?.(node, path) ?? true);
|
|
502
|
+
}
|
|
503
|
+
const pointBeforeLocation = start ? void 0 : before(editor, at, { voids });
|
|
504
|
+
if (!start) {
|
|
505
|
+
if (!pointBeforeLocation) return;
|
|
506
|
+
start = pointBeforeLocation.path;
|
|
507
|
+
}
|
|
508
|
+
const firstEntry = first$1(editor, []);
|
|
509
|
+
if (!firstEntry) return;
|
|
510
|
+
const [, to] = firstEntry;
|
|
511
|
+
const span = [start, to];
|
|
512
|
+
if (match == null) match = LocationApi.isPath(at) ? (_node, path) => PathApi.isSibling(path, at) : () => true;
|
|
513
|
+
const [innerPrevious] = nodes(editor, {
|
|
514
|
+
reverse: true,
|
|
515
|
+
at: span,
|
|
516
|
+
match,
|
|
517
|
+
mode,
|
|
518
|
+
voids
|
|
519
|
+
});
|
|
520
|
+
return innerPrevious;
|
|
521
|
+
});
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region src/range-projection.ts
|
|
524
|
+
const lastProjection = /* @__PURE__ */ new WeakMap();
|
|
525
|
+
const projectRangeInSnapshot = (snapshot, range) => {
|
|
526
|
+
const cached = lastProjection.get(snapshot);
|
|
527
|
+
if (cached && RangeApi.equals(cached.range, range)) return cached.segments;
|
|
528
|
+
const [start, end] = RangeApi.edges(range);
|
|
529
|
+
const root = {
|
|
530
|
+
children: snapshot.children,
|
|
531
|
+
type: ""
|
|
532
|
+
};
|
|
533
|
+
for (const point of [start, end]) {
|
|
534
|
+
const node = NodeApi.getIf(root, point.path);
|
|
535
|
+
if (!NodeApi.isText(node)) throw new Error("Cannot project a range outside the committed snapshot");
|
|
536
|
+
if (point.offset < 0 || point.offset > node.text.length) throw new Error(`Point offset ${point.offset} is outside text bounds for ${point.path.join(".")}`);
|
|
537
|
+
}
|
|
538
|
+
const segments = [];
|
|
539
|
+
for (const [node, path] of NodeApi.texts(root, {
|
|
540
|
+
from: start.path,
|
|
541
|
+
to: end.path
|
|
542
|
+
})) {
|
|
543
|
+
const key = snapshot.index.keyAt(path);
|
|
544
|
+
if (!key) throw new Error(`Missing node key for text path ${path.join(".")}`);
|
|
545
|
+
segments.push(Object.freeze({
|
|
546
|
+
key,
|
|
547
|
+
path: Object.freeze([...path]),
|
|
548
|
+
start: PathApi.equals(path, start.path) ? start.offset : 0,
|
|
549
|
+
end: PathApi.equals(path, end.path) ? end.offset : node.text.length
|
|
550
|
+
}));
|
|
551
|
+
}
|
|
552
|
+
const projected = Object.freeze(segments);
|
|
553
|
+
lastProjection.set(snapshot, {
|
|
554
|
+
range: {
|
|
555
|
+
anchor: {
|
|
556
|
+
...range.anchor,
|
|
557
|
+
path: [...range.anchor.path]
|
|
558
|
+
},
|
|
559
|
+
focus: {
|
|
560
|
+
...range.focus,
|
|
561
|
+
path: [...range.focus.path]
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
segments: projected
|
|
565
|
+
});
|
|
566
|
+
return projected;
|
|
567
|
+
};
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region src/editor/project-range.ts
|
|
570
|
+
const projectRange = (editor, range) => projectRangeInSnapshot(getSnapshot(editor), range);
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region src/editor/should-merge-nodes-remove-prev-node.ts
|
|
573
|
+
const shouldMergeNodesRemovePrevNode = (editor, previous, current) => resolveShouldMergeNodesRemovePrevNode(editor, previous, current, () => {
|
|
574
|
+
const [previousNode, prevPath] = previous;
|
|
575
|
+
return NodeApi.isElement(previousNode) && isEmpty$1(editor, previousNode) || NodeApi.isText(previousNode) && previousNode.text === "" && getDefined(prevPath.at(-1)) !== 0;
|
|
576
|
+
});
|
|
577
|
+
//#endregion
|
|
578
|
+
//#region src/editor/string.ts
|
|
579
|
+
const string = (editor, at, options = {}) => {
|
|
580
|
+
const { content = false, voids = false } = options;
|
|
581
|
+
let text = "";
|
|
582
|
+
if (LocationApi.isPath(at)) {
|
|
583
|
+
for (const [node] of nodes(editor, {
|
|
584
|
+
at,
|
|
585
|
+
match: NodeApi.isText,
|
|
586
|
+
voids
|
|
587
|
+
})) if (!content || isEditorContent(editor, node)) text += node.text;
|
|
588
|
+
return text;
|
|
589
|
+
}
|
|
590
|
+
const range$2 = range(editor, at);
|
|
591
|
+
const [start, end] = RangeApi.edges(range$2);
|
|
592
|
+
for (const [node, path] of nodes(editor, {
|
|
593
|
+
at: range$2,
|
|
594
|
+
match: NodeApi.isText,
|
|
595
|
+
voids
|
|
596
|
+
})) {
|
|
597
|
+
if (content && !isEditorContent(editor, node)) continue;
|
|
598
|
+
const from = PathApi.equals(path, start.path) ? start.offset : 0;
|
|
599
|
+
const to = PathApi.equals(path, end.path) ? end.offset : node.text.length;
|
|
600
|
+
text += node.text.slice(from, to);
|
|
601
|
+
}
|
|
602
|
+
return text;
|
|
603
|
+
};
|
|
604
|
+
//#endregion
|
|
605
|
+
//#region src/editor/unhang-range.ts
|
|
606
|
+
const unhangRange = (editor, range, options = {}) => {
|
|
607
|
+
const { character = false, unhang = true, voids = false } = options;
|
|
608
|
+
const inputRange = {
|
|
609
|
+
anchor: range.anchor,
|
|
610
|
+
focus: range.focus
|
|
611
|
+
};
|
|
612
|
+
if (character) {
|
|
613
|
+
let [start, end] = RangeApi.edges(range);
|
|
614
|
+
if (PathApi.equals(start.path, end.path)) return inputRange;
|
|
615
|
+
if (end.offset === 0) {
|
|
616
|
+
const pointAfter = after(editor, start, { voids });
|
|
617
|
+
if (pointAfter) end = pointAfter;
|
|
618
|
+
} else {
|
|
619
|
+
const pointBefore = before(editor, end, { voids });
|
|
620
|
+
if (pointBefore) start = pointBefore;
|
|
621
|
+
}
|
|
622
|
+
return {
|
|
623
|
+
anchor: start,
|
|
624
|
+
focus: end
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
if (!unhang) return inputRange;
|
|
628
|
+
const [start, initialEnd] = RangeApi.edges(range);
|
|
629
|
+
let end = initialEnd;
|
|
630
|
+
if (start.offset !== 0 || end.offset !== 0 || RangeApi.isCollapsed(range) || PathApi.hasPrevious(end.path)) return inputRange;
|
|
631
|
+
const endBlock = above$1(editor, {
|
|
632
|
+
at: end,
|
|
633
|
+
match: (n) => NodeApi.isElement(n) && isBlock$1(editor, n),
|
|
634
|
+
voids
|
|
635
|
+
});
|
|
636
|
+
const blockPath = endBlock ? endBlock[1] : [];
|
|
637
|
+
const before$2 = {
|
|
638
|
+
anchor: point(editor, start, { edge: "start" }),
|
|
639
|
+
focus: end
|
|
640
|
+
};
|
|
641
|
+
let skip = true;
|
|
642
|
+
for (const [node, path] of nodes(editor, {
|
|
643
|
+
at: before$2,
|
|
644
|
+
match: NodeApi.isText,
|
|
645
|
+
reverse: true,
|
|
646
|
+
voids
|
|
647
|
+
})) {
|
|
648
|
+
if (skip) {
|
|
649
|
+
skip = false;
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
if (node.text === "" && voids && voidEditor(editor, {
|
|
653
|
+
at: path,
|
|
654
|
+
mode: "highest"
|
|
655
|
+
})) continue;
|
|
656
|
+
if (node.text !== "" || PathApi.isBefore(path, blockPath)) {
|
|
657
|
+
end = {
|
|
658
|
+
path,
|
|
659
|
+
offset: node.text.length
|
|
660
|
+
};
|
|
661
|
+
break;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return {
|
|
665
|
+
anchor: start,
|
|
666
|
+
focus: end
|
|
667
|
+
};
|
|
668
|
+
};
|
|
669
|
+
//#endregion
|
|
670
|
+
//#region src/core/editor-read-runtime.ts
|
|
671
|
+
const getQueryRoot = (editor, locations, { selectionFallback = false } = {}) => {
|
|
672
|
+
const root = getCommonLocationRoot(...locations);
|
|
673
|
+
if (root === null) throw new Error("Cannot read an editor location across multiple roots.");
|
|
674
|
+
return root ?? getEditorChildrenRoot(editor) ?? (selectionFallback && getLiveSelection(editor) ? getCurrentSelectionRoot(editor) : void 0);
|
|
675
|
+
};
|
|
676
|
+
const withQueryRoot = (editor, locations, fn, options) => {
|
|
677
|
+
const root = getQueryRoot(editor, locations, options);
|
|
678
|
+
return root ? withEditorRootChildren(editor, root, fn) : fn();
|
|
679
|
+
};
|
|
680
|
+
const withOptionsQueryRoot = (editor, options, fn, queryOptions) => withQueryRoot(editor, [options?.at], fn, queryOptions);
|
|
681
|
+
const usesImplicitSelectionLocation = (options) => options?.at === void 0;
|
|
682
|
+
const withQueryRootGenerator = (editor, locations, create, options) => (function* rootedQueryGenerator() {
|
|
683
|
+
const root = getQueryRoot(editor, locations, options);
|
|
684
|
+
if (root) {
|
|
685
|
+
yield* withEditorRootChildrenGenerator(editor, root, create);
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
yield* create();
|
|
689
|
+
})();
|
|
690
|
+
const withExplicitPointRoot = (innerPoint, root) => root && root !== "main" && innerPoint && innerPoint.root === void 0 ? {
|
|
691
|
+
...innerPoint,
|
|
692
|
+
root
|
|
693
|
+
} : innerPoint;
|
|
694
|
+
const withExplicitRangeRoot = (innerRange, root) => root ? {
|
|
695
|
+
anchor: withExplicitPointRoot(innerRange.anchor, root),
|
|
696
|
+
focus: withExplicitPointRoot(innerRange.focus, root)
|
|
697
|
+
} : innerRange;
|
|
698
|
+
const createEditorReadRuntime = (editor) => ({
|
|
699
|
+
above: (options) => (({ options: innerOptions }) => withOptionsQueryRoot(editor, innerOptions, () => above(editor, innerOptions), { selectionFallback: usesImplicitSelectionLocation(innerOptions) }))({ options }),
|
|
700
|
+
after: (at, options) => (({ at: innerAt, options: innerOptions2 }) => {
|
|
701
|
+
const root = getQueryRoot(editor, [innerAt]);
|
|
702
|
+
return withQueryRoot(editor, [innerAt], () => withExplicitPointRoot(after$1(editor, innerAt, innerOptions2), root));
|
|
703
|
+
})({
|
|
704
|
+
at,
|
|
705
|
+
options
|
|
706
|
+
}),
|
|
707
|
+
before: (at, options) => (({ at: innerAt2, options: innerOptions3 }) => {
|
|
708
|
+
const root = getQueryRoot(editor, [innerAt2]);
|
|
709
|
+
return withQueryRoot(editor, [innerAt2], () => withExplicitPointRoot(before$1(editor, innerAt2, innerOptions3), root));
|
|
710
|
+
})({
|
|
711
|
+
at,
|
|
712
|
+
options
|
|
713
|
+
}),
|
|
714
|
+
edges: (at) => (({ at: innerAt3 }) => {
|
|
715
|
+
const root = getQueryRoot(editor, [innerAt3]);
|
|
716
|
+
return withQueryRoot(editor, [innerAt3], () => {
|
|
717
|
+
const [start, end] = edges(editor, innerAt3);
|
|
718
|
+
return [withExplicitPointRoot(start, root), withExplicitPointRoot(end, root)];
|
|
719
|
+
});
|
|
720
|
+
})({ at }) ?? failInvariant("Static range read returned no result"),
|
|
721
|
+
elementReadOnly: (options) => (({ options: innerOptions4 }) => withOptionsQueryRoot(editor, innerOptions4, () => elementReadOnly(editor, innerOptions4), { selectionFallback: usesImplicitSelectionLocation(innerOptions4) }))({ options }),
|
|
722
|
+
first: (at) => (({ at: innerAt4 }) => withQueryRoot(editor, [innerAt4], () => first(editor, innerAt4)))({ at }) ?? failInvariant("Static first-node read returned no result"),
|
|
723
|
+
fragment: (at) => {
|
|
724
|
+
const root = getQueryRoot(editor, [at]);
|
|
725
|
+
return (({ options }) => {
|
|
726
|
+
const location = options?.at;
|
|
727
|
+
return withQueryRoot(editor, [location], () => location && RangeApi.isCollapsed(location) ? [] : getFragment(editor, options));
|
|
728
|
+
})({ options: { at: withQueryRoot(editor, [at], () => withExplicitRangeRoot(range$1(editor, at), root)) } });
|
|
729
|
+
},
|
|
730
|
+
hasBlocks: (element) => (({ element: innerElement }) => hasBlocks(editor, innerElement))({ element }),
|
|
731
|
+
hasInlines: (element) => (({ element: innerElement2 }) => hasInlines(editor, innerElement2))({ element }),
|
|
732
|
+
hasPath: (innerPath) => (({ path: innerPath2 }) => hasPath(editor, innerPath2))({ path: innerPath }),
|
|
733
|
+
hasTexts: (element) => (({ element: innerElement3 }) => hasTexts(editor, innerElement3))({ element }),
|
|
734
|
+
isBlock: (element) => (({ element: innerElement4 }) => isBlock(editor, innerElement4))({ element }),
|
|
735
|
+
isEdge: (innerPoint2, at) => (({ at: innerAt5, point: innerPoint3 }) => withQueryRoot(editor, [innerPoint3, innerAt5], () => isEdge(editor, innerPoint3, innerAt5)))({
|
|
736
|
+
at,
|
|
737
|
+
point: innerPoint2
|
|
738
|
+
}),
|
|
739
|
+
isEmpty: (element) => (({ element: innerElement5 }) => isEmpty(editor, innerElement5))({ element }),
|
|
740
|
+
isEnd: (innerPoint4, at) => (({ at: innerAt6, point: innerPoint5 }) => withQueryRoot(editor, [innerPoint5, innerAt6], () => isEnd(editor, innerPoint5, innerAt6)))({
|
|
741
|
+
at,
|
|
742
|
+
point: innerPoint4
|
|
743
|
+
}),
|
|
744
|
+
isStart: (innerPoint6, at) => (({ at: innerAt7, point: innerPoint7 }) => withQueryRoot(editor, [innerPoint7, innerAt7], () => isStart(editor, innerPoint7, innerAt7)))({
|
|
745
|
+
at,
|
|
746
|
+
point: innerPoint6
|
|
747
|
+
}),
|
|
748
|
+
last: (at, options) => (({ at: innerAt8, options: innerOptions5 }) => withQueryRoot(editor, [innerAt8], () => last(editor, innerAt8, innerOptions5)))({
|
|
749
|
+
at,
|
|
750
|
+
options
|
|
751
|
+
}),
|
|
752
|
+
leaf: (at, options) => (({ at: innerAt9, options: innerOptions6 }) => withQueryRoot(editor, [innerAt9], () => leaf(editor, innerAt9, innerOptions6)))({
|
|
753
|
+
at,
|
|
754
|
+
options
|
|
755
|
+
}) ?? failInvariant("Static leaf read returned no result"),
|
|
756
|
+
levels: (options) => (({ options: innerOptions7 }) => withQueryRootGenerator(editor, [innerOptions7?.at], () => levels(editor, innerOptions7), { selectionFallback: usesImplicitSelectionLocation(innerOptions7) }))({ options }),
|
|
757
|
+
next: (options) => (({ options: innerOptions8 }) => withOptionsQueryRoot(editor, innerOptions8, () => next(editor, innerOptions8), { selectionFallback: usesImplicitSelectionLocation(innerOptions8) }))({ options }),
|
|
758
|
+
parent: ((at, options) => (({ at: innerAt10, options: innerOptions9 }) => {
|
|
759
|
+
const filtered = innerOptions9?.type !== void 0 || innerOptions9?.match !== void 0;
|
|
760
|
+
const entry = withQueryRoot(editor, [innerAt10], () => parent(editor, innerAt10, innerOptions9));
|
|
761
|
+
return filtered ? entry : entry ?? failInvariant("Static parent read returned no result");
|
|
762
|
+
})({
|
|
763
|
+
at,
|
|
764
|
+
options
|
|
765
|
+
})),
|
|
766
|
+
path: (at, options) => (({ at: innerAt11, options: innerOptions10 }) => withQueryRoot(editor, [innerAt11], () => path(editor, innerAt11, innerOptions10)))({
|
|
767
|
+
at,
|
|
768
|
+
options
|
|
769
|
+
}) ?? failInvariant("Static path read returned no result"),
|
|
770
|
+
point: (at, options) => (({ at: innerAt12, options: innerOptions11 }) => {
|
|
771
|
+
const root = getQueryRoot(editor, [innerAt12]);
|
|
772
|
+
return withQueryRoot(editor, [innerAt12], () => withExplicitPointRoot(point$1(editor, innerAt12, innerOptions11), root));
|
|
773
|
+
})({
|
|
774
|
+
at,
|
|
775
|
+
options
|
|
776
|
+
}) ?? failInvariant("Static point read returned no result"),
|
|
777
|
+
positions: (options) => (({ options: innerOptions12 }) => {
|
|
778
|
+
const root = getQueryRoot(editor, [innerOptions12?.at], { selectionFallback: usesImplicitSelectionLocation(innerOptions12) });
|
|
779
|
+
return withQueryRootGenerator(editor, [innerOptions12?.at], function* readPositions() {
|
|
780
|
+
for (const innerPoint8 of positions(editor, innerOptions12)) yield withExplicitPointRoot(innerPoint8, root);
|
|
781
|
+
}, { selectionFallback: usesImplicitSelectionLocation(innerOptions12) });
|
|
782
|
+
})({ options }),
|
|
783
|
+
previous: (options) => (({ options: innerOptions13 }) => withOptionsQueryRoot(editor, innerOptions13, () => previous(editor, innerOptions13), { selectionFallback: usesImplicitSelectionLocation(innerOptions13) }))({ options }),
|
|
784
|
+
projectRange: (innerRange2) => (({ range: innerRange3 }) => withQueryRoot(editor, [innerRange3], () => projectRange(editor, innerRange3)))({ range: innerRange2 }),
|
|
785
|
+
range: (at, to) => (({ at: innerAt13, to: innerTo }) => {
|
|
786
|
+
const root = getQueryRoot(editor, [innerAt13, innerTo]);
|
|
787
|
+
return withQueryRoot(editor, [innerAt13, innerTo], () => withExplicitRangeRoot(range$1(editor, innerAt13, innerTo), root));
|
|
788
|
+
})({
|
|
789
|
+
at,
|
|
790
|
+
to
|
|
791
|
+
}) ?? failInvariant("Static range read returned no result"),
|
|
792
|
+
shouldMergeNodesRemovePrevNode: (innerPrevious, current) => (({ current: innerCurrent, previous: innerPrevious2 }) => shouldMergeNodesRemovePrevNode(editor, innerPrevious2, innerCurrent))({
|
|
793
|
+
current,
|
|
794
|
+
previous: innerPrevious
|
|
795
|
+
}),
|
|
796
|
+
string: (at, options) => (({ at: innerAt14, options: innerOptions14 }) => withQueryRoot(editor, [innerAt14], () => string(editor, innerAt14, innerOptions14)))({
|
|
797
|
+
at,
|
|
798
|
+
options
|
|
799
|
+
}),
|
|
800
|
+
unhangRange: (innerRange4, options) => (({ options: innerOptions15, range: innerRange5 }) => {
|
|
801
|
+
const root = getQueryRoot(editor, [innerRange5]);
|
|
802
|
+
return withQueryRoot(editor, [innerRange5], () => withExplicitRangeRoot(unhangRange(editor, innerRange5, innerOptions15), root));
|
|
803
|
+
})({
|
|
804
|
+
options,
|
|
805
|
+
range: innerRange4
|
|
806
|
+
}),
|
|
807
|
+
void: (options) => (({ options: innerOptions16 }) => withOptionsQueryRoot(editor, innerOptions16, () => getVoid(editor, innerOptions16), { selectionFallback: usesImplicitSelectionLocation(innerOptions16) }))({ options })
|
|
808
|
+
});
|
|
809
|
+
//#endregion
|
|
810
|
+
//#region src/internal/editor-options.ts
|
|
811
|
+
/** @internal */
|
|
812
|
+
const EDITOR_OPTION_KEYS = {
|
|
813
|
+
id: true,
|
|
814
|
+
initialSelection: true,
|
|
815
|
+
initialValue: true,
|
|
816
|
+
lifecycleErrorSink: true,
|
|
817
|
+
maxLength: true,
|
|
818
|
+
plugins: true,
|
|
819
|
+
readOnly: true
|
|
820
|
+
};
|
|
821
|
+
const keysEveryObjectInherits = new Set(Object.getOwnPropertyNames(Object.prototype));
|
|
822
|
+
/** @internal */
|
|
823
|
+
const assertEditorOptions = (options, keys) => {
|
|
824
|
+
for (let object = options; object !== null && object !== Object.prototype; object = Object.getPrototypeOf(object)) for (const key of Object.getOwnPropertyNames(object)) {
|
|
825
|
+
if (Object.hasOwn(keys, key)) continue;
|
|
826
|
+
if (object !== options && keysEveryObjectInherits.has(key)) continue;
|
|
827
|
+
throw new TypeError(key === "value" ? "Unknown editor option \"value\". Use \"initialValue\" to set the document." : `Unknown editor option "${key}".`);
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
/**
|
|
831
|
+
* Copies each option in `keys` that `options` holds, own or inherited, into a
|
|
832
|
+
* plain object that a rest or spread copies whole.
|
|
833
|
+
*
|
|
834
|
+
* @internal
|
|
835
|
+
*/
|
|
836
|
+
const readEditorOptions = (options, keys) => {
|
|
837
|
+
const read = {};
|
|
838
|
+
for (const key of Object.keys(keys)) {
|
|
839
|
+
const value = options[key];
|
|
840
|
+
if (value !== void 0 || key in options) read[key] = value;
|
|
841
|
+
}
|
|
842
|
+
return read;
|
|
843
|
+
};
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region src/create-editor.ts
|
|
846
|
+
let nextEditorId = 0;
|
|
847
|
+
const PENDING_SCHEMA_BOOTSTRAP = /* @__PURE__ */ new WeakSet();
|
|
848
|
+
const SCHEMA_BOOTSTRAP_DOCUMENT_CHANGED = /* @__PURE__ */ new WeakSet();
|
|
849
|
+
const SCHEMA_BOOTSTRAP_CLEANUPS = /* @__PURE__ */ new WeakMap();
|
|
850
|
+
const disarmSchemaBootstrap = (editor) => {
|
|
851
|
+
PENDING_SCHEMA_BOOTSTRAP.delete(editor);
|
|
852
|
+
SCHEMA_BOOTSTRAP_DOCUMENT_CHANGED.delete(editor);
|
|
853
|
+
SCHEMA_BOOTSTRAP_CLEANUPS.get(editor)?.();
|
|
854
|
+
SCHEMA_BOOTSTRAP_CLEANUPS.delete(editor);
|
|
855
|
+
};
|
|
856
|
+
const armSchemaBootstrap = (editor) => {
|
|
857
|
+
PENDING_SCHEMA_BOOTSTRAP.add(editor);
|
|
858
|
+
const cleanup = subscribeCommit(editor, (commit) => {
|
|
859
|
+
if (commit.changes.empty) return;
|
|
860
|
+
SCHEMA_BOOTSTRAP_DOCUMENT_CHANGED.add(editor);
|
|
861
|
+
cleanup();
|
|
862
|
+
SCHEMA_BOOTSTRAP_CLEANUPS.delete(editor);
|
|
863
|
+
});
|
|
864
|
+
SCHEMA_BOOTSTRAP_CLEANUPS.set(editor, cleanup);
|
|
865
|
+
};
|
|
866
|
+
const createEditorId = () => `editor-${nextEditorId += 1}`;
|
|
867
|
+
const publishInitialPlugins = (editor, input, explicitInitialDocument, options = {}, compiledEntries = false) => {
|
|
868
|
+
if (hasActiveAnchors(editor)) throw new Error("Editor schema initialization requires an editor without active anchors.");
|
|
869
|
+
const publication = compiledEntries ? prepareScopedPluginPublication(editor, input, {
|
|
870
|
+
initialPublication: true,
|
|
871
|
+
initializeDocument: !explicitInitialDocument
|
|
872
|
+
}) : prepareInitialPluginPublication(editor, input, !explicitInitialDocument);
|
|
873
|
+
const restoreDocument = saveEditorSchemaDocument(editor);
|
|
874
|
+
const initialSelection = getLiveSelection(editor);
|
|
875
|
+
const initialSelectionRoot = getCurrentSelectionRoot(editor);
|
|
876
|
+
const preparedDocumentValidated = publication.configurationChanged && explicitInitialDocument && publication.documentChange.empty;
|
|
877
|
+
try {
|
|
878
|
+
adoptInitialDocumentChange(editor, publication.documentChange, publication.schemaCompilation());
|
|
879
|
+
publication.stage();
|
|
880
|
+
publication.commit();
|
|
881
|
+
const validatePublishedDocument = (requireExplicitDocument = explicitInitialDocument, validateDocument = true) => {
|
|
882
|
+
const publishedDocument = getEditorDocumentValue(editor);
|
|
883
|
+
if (requireExplicitDocument && publishedDocument.children.length === 0) throw new Error("initialValue is invalid! Expected at least one element.");
|
|
884
|
+
assertSelectionSupported(editor, getLiveSelection(editor), publishedDocument);
|
|
885
|
+
if (validateDocument && publication.configurationChanged) publication.validateDocument(publishedDocument);
|
|
886
|
+
else if (validateDocument) getEditorSchema(editor).assertDocument(publishedDocument);
|
|
887
|
+
};
|
|
888
|
+
validatePublishedDocument(explicitInitialDocument, !preparedDocumentValidated);
|
|
889
|
+
if (options.initialValue) {
|
|
890
|
+
initializeEditorSchemaSnapshot(editor, transformEditorSnapshotInput(editor, options.initialValue()));
|
|
891
|
+
validatePublishedDocument(true);
|
|
892
|
+
}
|
|
893
|
+
if (options.initialize) {
|
|
894
|
+
const spec = createTransactionSpec(editor, options.initialize);
|
|
895
|
+
if (spec.effects.length > 0 || spec.annotations.length > 0 || spec.tags.length > 0) throw new Error("Editor schema initialization cannot publish effects, annotations, or tags.");
|
|
896
|
+
const initializedDocument = applyTransactionSpecToDocument(editor, spec, getEditorDocumentValue(editor));
|
|
897
|
+
const admitted = admitEditorDocument(editor, initializedDocument);
|
|
898
|
+
initializeEditorSchemaDocument(editor, admitted.document, getCompiledEditorSchema(editor));
|
|
899
|
+
if (spec.selection) {
|
|
900
|
+
const root = spec.selection.root ?? "main";
|
|
901
|
+
initializeEditorSchemaSelection(editor, mapSelectionThroughChange(editor, spec.selection.value, admitted.change, initializedDocument, admitted.document, root, {
|
|
902
|
+
association: "backward",
|
|
903
|
+
preferPositionMapping: true
|
|
904
|
+
}).selection, root);
|
|
905
|
+
}
|
|
906
|
+
validatePublishedDocument(explicitInitialDocument || !!options.initialValue);
|
|
907
|
+
}
|
|
908
|
+
publication.beforePublish();
|
|
909
|
+
publication.finalize();
|
|
910
|
+
invalidateEditorTransactionSpecs(editor);
|
|
911
|
+
} catch (error) {
|
|
912
|
+
publication.rollback();
|
|
913
|
+
restoreDocument();
|
|
914
|
+
initializeEditorSchemaSelection(editor, initialSelection, initialSelectionRoot);
|
|
915
|
+
throw error;
|
|
916
|
+
}
|
|
917
|
+
publication.afterPublish();
|
|
918
|
+
seedUniqueMaps(editor);
|
|
919
|
+
if (getPluginRegistry(editor).schemaContributions.records.size > 0) disarmSchemaBootstrap(editor);
|
|
920
|
+
};
|
|
921
|
+
const adoptInitialDocumentChange = (editor, change, compilation) => {
|
|
922
|
+
if (change.empty) return;
|
|
923
|
+
const initialDocument = getEditorDocumentValue(editor);
|
|
924
|
+
const initialSelection = getLiveSelection(editor);
|
|
925
|
+
const initialSelectionRoot = getCurrentSelectionRoot(editor);
|
|
926
|
+
const schema = compilation?.schema ?? getCompiledEditorSchema(editor);
|
|
927
|
+
const admitted = admitDocument(compilation && onlyDocumentAdmission(compilation.contributions(documentAdmissionPoint)), change.apply(initialDocument), schema);
|
|
928
|
+
initializeEditorSchemaDocument(editor, admitted.document, schema);
|
|
929
|
+
if (!initialSelection) return;
|
|
930
|
+
const mapped = mapSelectionThroughChange(editor, initialSelection, change.compose(admitted.change), initialDocument, admitted.document, initialSelectionRoot, {
|
|
931
|
+
association: "backward",
|
|
932
|
+
preferPositionMapping: true
|
|
933
|
+
}).selection;
|
|
934
|
+
if (!mapped) throw new Error("Initial selection cannot be mapped through schema fitting.");
|
|
935
|
+
initializeEditorSchemaSelection(editor, mapped, initialSelectionRoot);
|
|
936
|
+
};
|
|
937
|
+
const assertEditorSchemaBootstrap = (editor) => {
|
|
938
|
+
if (!PENDING_SCHEMA_BOOTSTRAP.has(editor)) throw new Error("Editor schema initialization requires an editor without an installed schema.");
|
|
939
|
+
if (getPluginRegistry(editor).schemaContributions.records.size > 0) {
|
|
940
|
+
disarmSchemaBootstrap(editor);
|
|
941
|
+
throw new Error("Editor schema is already initialized.");
|
|
942
|
+
}
|
|
943
|
+
const document = getEditorDocumentValue(editor);
|
|
944
|
+
const hasDocument = document.children.length > 0 || Object.values(document.roots ?? {}).some((children) => children.length > 0);
|
|
945
|
+
if (SCHEMA_BOOTSTRAP_DOCUMENT_CHANGED.has(editor)) {
|
|
946
|
+
disarmSchemaBootstrap(editor);
|
|
947
|
+
throw new Error("Editor schema initialization requires an unchanged document.");
|
|
948
|
+
}
|
|
949
|
+
return hasDocument;
|
|
950
|
+
};
|
|
951
|
+
/**
|
|
952
|
+
* Compile plugins against one unchanged raw editor without publishing them.
|
|
953
|
+
* API factories and schema validators run; document defaults and activation do not.
|
|
954
|
+
*/
|
|
955
|
+
const compileEditorSchemaContract = (editor, input) => {
|
|
956
|
+
assertPluginPublicationInactive(editor);
|
|
957
|
+
if (assertEditorSchemaBootstrap(editor) || hasActiveAnchors(editor)) throw new Error("Editor schema compilation requires an empty editor without active anchors.");
|
|
958
|
+
const publication = prepareInitialPluginPublication(editor, input, "schema-contract");
|
|
959
|
+
try {
|
|
960
|
+
return publication.schemaContract();
|
|
961
|
+
} finally {
|
|
962
|
+
publication.rollback();
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
/** Compile owner-provided plugin entries without publishing them. @internal */
|
|
966
|
+
const compileEditorSchemaContractEntries = (editor, entries) => {
|
|
967
|
+
assertPluginPublicationInactive(editor);
|
|
968
|
+
if (assertEditorSchemaBootstrap(editor) || hasActiveAnchors(editor)) throw new Error("Editor schema compilation requires an empty editor without active anchors.");
|
|
969
|
+
const publication = prepareScopedPluginPublication(editor, entries, {
|
|
970
|
+
initialPublication: true,
|
|
971
|
+
validateDocument: false
|
|
972
|
+
});
|
|
973
|
+
try {
|
|
974
|
+
return publication.schemaContract();
|
|
975
|
+
} finally {
|
|
976
|
+
publication.rollback();
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
/** Compile immutable schema and persistent-field authority without publishing it. @internal */
|
|
980
|
+
const withCompiledEditorSchemaCapabilityEntries = (editor, entries, run) => {
|
|
981
|
+
assertPluginPublicationInactive(editor);
|
|
982
|
+
if (assertEditorSchemaBootstrap(editor) || hasActiveAnchors(editor)) throw new Error("Editor schema compilation requires an empty editor without active anchors.");
|
|
983
|
+
const publication = prepareScopedPluginPublication(editor, entries, {
|
|
984
|
+
initialPublication: true,
|
|
985
|
+
validateDocument: false
|
|
986
|
+
});
|
|
987
|
+
try {
|
|
988
|
+
const compilation = publication.schemaCompilation();
|
|
989
|
+
const authored = compilation.contributions(authoredDocumentCapabilityPoint);
|
|
990
|
+
if (authored.length > 1) throw new Error("Editor schema compilation received multiple authored document capabilities.");
|
|
991
|
+
return run(Object.freeze({
|
|
992
|
+
...authored[0] ? { authored: authored[0] } : {},
|
|
993
|
+
contract: publication.schemaContract(),
|
|
994
|
+
fields: compilation.fields,
|
|
995
|
+
schema: compilation.schema
|
|
996
|
+
}));
|
|
997
|
+
} finally {
|
|
998
|
+
publication.rollback();
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
const compileEditorSchemaCapabilityEntries = (editor, entries) => withCompiledEditorSchemaCapabilityEntries(editor, entries, (result) => result);
|
|
1002
|
+
/** Read the single published authored document capability, when installed. @internal */
|
|
1003
|
+
const getEditorAuthoredDocumentCapability = (editor) => {
|
|
1004
|
+
const capabilities = getPluginContributions(editor, authoredDocumentCapabilityPoint);
|
|
1005
|
+
if (capabilities.length > 1) throw new Error("Editor schema contains multiple authored document capabilities.");
|
|
1006
|
+
return capabilities[0];
|
|
1007
|
+
};
|
|
1008
|
+
/** Replace the derived base schema on one unchanged raw editor. @internal */
|
|
1009
|
+
const initializePlugins = (editor, input, options = {}) => {
|
|
1010
|
+
publishInitialPlugins(editor, input, assertEditorSchemaBootstrap(editor), options);
|
|
1011
|
+
};
|
|
1012
|
+
/** Publish owner-compiled plugin entries against one unchanged editor. @internal */
|
|
1013
|
+
const initializePluginEntries = (editor, entries, options = {}) => {
|
|
1014
|
+
publishInitialPlugins(editor, entries, assertEditorSchemaBootstrap(editor), options, true);
|
|
1015
|
+
};
|
|
1016
|
+
function createEditor(options = {}) {
|
|
1017
|
+
return createEditorImplementation(options, false);
|
|
1018
|
+
}
|
|
1019
|
+
/** @internal */
|
|
1020
|
+
const createDormantEditor = (options = {}) => createEditorImplementation(options, true);
|
|
1021
|
+
const createEditorImplementation = (options, dormant) => {
|
|
1022
|
+
assertEditorOptions(options, EDITOR_OPTION_KEYS);
|
|
1023
|
+
let editor;
|
|
1024
|
+
const runtimeEditor = () => editor;
|
|
1025
|
+
const pluginRuntime = {
|
|
1026
|
+
schema: createEditorSchema(runtimeEditor),
|
|
1027
|
+
install: (plugin, pluginOptions) => extendEditor(editor, plugin, pluginOptions),
|
|
1028
|
+
preparePluginPublication: (entries, publicationOptions) => prepareScopedPluginPublication(editor, entries, publicationOptions)
|
|
1029
|
+
};
|
|
1030
|
+
const snapshotRuntime = {
|
|
1031
|
+
getChildList: () => getChildList(editor),
|
|
1032
|
+
getChildren: () => getChildren$1(editor),
|
|
1033
|
+
getFragment: () => getFragment(editor),
|
|
1034
|
+
getLastCommit: () => getLastCommit(editor),
|
|
1035
|
+
getPathByNodeKey: (nodeKey) => getPathByNodeKey(editor, nodeKey),
|
|
1036
|
+
getNodeKey: (path) => getNodeKey(editor, path),
|
|
1037
|
+
getSelection: () => getLiveSelection(editor),
|
|
1038
|
+
getSnapshot: () => getSnapshot$1(editor)
|
|
1039
|
+
};
|
|
1040
|
+
const runtimeBoundaryEditor = () => editor;
|
|
1041
|
+
const transactionRuntime = {
|
|
1042
|
+
read: (fn) => readEditor(runtimeBoundaryEditor(), fn),
|
|
1043
|
+
runCommand: createCommandDispatch(() => editor),
|
|
1044
|
+
subscribe: (listener) => subscribe(editor, listener),
|
|
1045
|
+
subscribeCommit: (listener) => subscribeCommit(editor, listener),
|
|
1046
|
+
subscribeSource: (source, listener) => subscribeSource(editor, source, listener),
|
|
1047
|
+
update: (fn, innerOptions) => updateEditor(runtimeBoundaryEditor(), fn, innerOptions)
|
|
1048
|
+
};
|
|
1049
|
+
const anchorApi = createEditorAnchorApi(() => editor);
|
|
1050
|
+
const readMain = (fn) => withEditorRootChildren(editor, "main", () => readEditor(editor, fn));
|
|
1051
|
+
const read = createEditorReadApi((fn) => {
|
|
1052
|
+
assertNoDocumentViewRead(editor);
|
|
1053
|
+
return readMain(fn);
|
|
1054
|
+
});
|
|
1055
|
+
read.schema = createEditorReadApi(readMain).schema;
|
|
1056
|
+
const key = ((target) => {
|
|
1057
|
+
assertNoDocumentViewRead(editor);
|
|
1058
|
+
return withEditorRootChildren(editor, MAIN_ROOT_KEY, () => readEditor(editor, (state) => state.key(target)));
|
|
1059
|
+
});
|
|
1060
|
+
const update = createEditorUpdateApi((fn, policy) => updateEditor(editor, fn, { tags: policy.tags }), {
|
|
1061
|
+
hasTxGroup: (groupName) => getPluginRegistry(editor).txGroups.has(groupName),
|
|
1062
|
+
repairValue: () => updateEditor(editor, () => {
|
|
1063
|
+
repairEditorValue(editor);
|
|
1064
|
+
}, { tags: ["history-skip"] })
|
|
1065
|
+
});
|
|
1066
|
+
editor = {
|
|
1067
|
+
api: Object.create(null),
|
|
1068
|
+
anchor: anchorApi,
|
|
1069
|
+
id: options.id ?? createEditorId(),
|
|
1070
|
+
plugin: void 0,
|
|
1071
|
+
key,
|
|
1072
|
+
read,
|
|
1073
|
+
subscribeCommit: (listener) => subscribeCommit(editor, listener),
|
|
1074
|
+
update,
|
|
1075
|
+
install: (plugin, pluginOptions) => extendEditor(editor, plugin, pluginOptions),
|
|
1076
|
+
destroy: () => destroyEditor(editor)
|
|
1077
|
+
};
|
|
1078
|
+
setEditorLifecycleErrorSink(editor, options.lifecycleErrorSink);
|
|
1079
|
+
const readRuntime = createEditorReadRuntime(editor);
|
|
1080
|
+
const runtime = {
|
|
1081
|
+
...pluginRuntime,
|
|
1082
|
+
...readRuntime,
|
|
1083
|
+
...snapshotRuntime,
|
|
1084
|
+
...transactionRuntime
|
|
1085
|
+
};
|
|
1086
|
+
setEditorRuntime(editor, runtime);
|
|
1087
|
+
if (dormant) markEditorDormant(editor);
|
|
1088
|
+
const baseRegistry = createPluginRegistry();
|
|
1089
|
+
registerEffectTypeInRegistry(baseRegistry, "core:screen-reader-announcement", screenReaderAnnouncementEffect);
|
|
1090
|
+
initializeBasePluginRegistry(editor, finalizePluginRegistry(baseRegistry));
|
|
1091
|
+
Object.assign(editor, createEditorViewPluginApis(editor, editor));
|
|
1092
|
+
const initialState = initializePublicState(editor, options);
|
|
1093
|
+
armSchemaBootstrap(editor);
|
|
1094
|
+
if (options.plugins) publishInitialPlugins(editor, options.plugins, initialState.explicit);
|
|
1095
|
+
else {
|
|
1096
|
+
loadOpenedRecords(editor, void 0);
|
|
1097
|
+
const initialDocument = getEditorDocumentValue(editor);
|
|
1098
|
+
if (initialState.explicit && initialDocument.children.length === 0) throw new Error("initialValue is invalid! Expected at least one element.");
|
|
1099
|
+
assertSelectionSupported(editor, getLiveSelection(editor), initialDocument);
|
|
1100
|
+
adoptInitialDocumentChange(editor, constructLoadedDocumentChange(editor, initialDocument), null);
|
|
1101
|
+
seedUniqueMaps(editor);
|
|
1102
|
+
}
|
|
1103
|
+
snapshotInitialDocumentState(editor);
|
|
1104
|
+
return editor;
|
|
1105
|
+
};
|
|
1106
|
+
//#endregion
|
|
1107
|
+
export { screenReaderAnnouncementEffect as _, createEditor as a, initializePlugins as c, assertEditorOptions as d, readEditorOptions as f, getScreenReaderAnnouncements as g, getTextRunBetweenAtomics as h, createDormantEditor as i, withCompiledEditorSchemaCapabilityEntries as l, projectRangeInSnapshot as m, compileEditorSchemaContract as n, getEditorAuthoredDocumentCapability as o, projectRange as p, compileEditorSchemaContractEntries as r, initializePluginEntries as s, compileEditorSchemaCapabilityEntries as t, EDITOR_OPTION_KEYS as u };
|