@portabletext/editor 7.0.2 → 7.0.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/lib/_chunks-dts/behavior.types.action.d.ts +32 -32
- package/lib/_chunks-dts/behavior.types.action.d.ts.map +1 -1
- package/lib/_chunks-dts/resolve-containers.d.ts.map +1 -1
- package/lib/_chunks-es/get-first-child.js +1 -1
- package/lib/_chunks-es/get-first-child.js.map +1 -1
- package/lib/_chunks-es/{get-ancestor.js → get-node.js} +55 -55
- package/lib/_chunks-es/get-node.js.map +1 -0
- package/lib/_chunks-es/get-path-sub-schema.js +54 -54
- package/lib/_chunks-es/get-path-sub-schema.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/{util.is-empty-text-block.js → util.is-equal-selections.js} +7 -2
- package/lib/_chunks-es/util.is-equal-selections.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +1 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.js +1367 -1344
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.js +1 -1
- package/lib/selectors/index.js.map +1 -1
- package/lib/traversal/index.js +2 -2
- package/lib/traversal/index.js.map +1 -1
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +4 -7
- package/lib/utils/index.js.map +1 -1
- package/package.json +2 -2
- package/lib/_chunks-es/get-ancestor.js.map +0 -1
- package/lib/_chunks-es/util.is-empty-text-block.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react/compiler-runtime";
|
|
3
3
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
4
|
-
import React, { useRef, useEffect, useLayoutEffect, useState,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { isKeyedSegment, getNode, getChildren, getAncestor, isObjectNode, getAncestors, getNodeChildren } from "./_chunks-es/get-ancestor.js";
|
|
4
|
+
import React, { createContext, useContext, useRef, useEffect, useLayoutEffect, useState, useReducer, useCallback, memo, forwardRef, useMemo, Component, useSyncExternalStore, startTransition } from "react";
|
|
5
|
+
import { isKeyedSegment, getAncestor, isObjectNode, getNode, getChildren, getAncestors, getNodeChildren } from "./_chunks-es/get-node.js";
|
|
6
|
+
import { isTextBlockNode, hasNode, getNodes, isAncestorPath, getSibling, isInline, parentPath, isSpanNode, isBlock, getEnclosingBlock, getPathSubSchema, getBlock, resolveContainerAt, getParent, getEnclosingContainer } from "./_chunks-es/get-path-sub-schema.js";
|
|
8
7
|
import { getLeaf, getSpanNode, getText, getTextBlockNode, getUnionSchema, isLeaf, getFirstChild } from "./_chunks-es/get-first-child.js";
|
|
9
|
-
import { isTextBlockNode, isBlock, hasNode, getEnclosingBlock, isAncestorPath, getNodes, getSibling, isInline, parentPath, isSpanNode, getPathSubSchema, getBlock, resolveContainerAt, getParent, getEnclosingContainer } from "./_chunks-es/get-path-sub-schema.js";
|
|
10
8
|
import { rangeEdges, isEditableContainer, isBackwardRange, comparePoints, rangesOverlap, isAfterPoint, comparePaths, isSelectionCollapsed as isSelectionCollapsed$1, getFocusInlineObject, getFocusTextBlock, getFocusSpan, getFragment, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection, getFocusBlock, getSelectedBlocks, isSelectingEntireBlocks, getSelectedValue, isActiveAnnotation, getActiveAnnotationsMarks, getActiveDecorators, getCaretWordSelection, getSelectionStartChild, getSelectionEndChild, getPreviousSpan, getNextSpan, getSelectionStartPoint, getSelectionEndPoint, getFocusBlockObject, getLastBlock, getFirstBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getMarkState, getFocusListBlock, getNextBlock, getPreviousBlock, getSelectedTextBlocks, getRootAcceptedTypes, isActiveDecorator, getFocusChild, getActiveAnnotations, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
9
|
+
import { isSpan, isTextBlock, compileSchema } from "@portabletext/schema";
|
|
10
|
+
import { defineSchema } from "@portabletext/schema";
|
|
13
11
|
import scrollIntoView from "scroll-into-view-if-needed";
|
|
12
|
+
import { getAncestorTextBlock, isEqualSelectionPoints, blockOffsetToSpanSelectionPoint, getBlockKeyFromSelectionPoint, getBlockEndPoint, getBlockStartPoint, isSelectionCollapsed, defaultKeyGenerator, parseBlocks, parseBlock, isListBlock, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject, isEqualPathSegments } from "./_chunks-es/util.slice-blocks.js";
|
|
14
13
|
import { createKeyboardShortcut, undo, redo, code, underline, italic as italic$1, bold as bold$1 } from "@portabletext/keyboard-shortcuts";
|
|
15
|
-
import
|
|
14
|
+
import rawDebug from "debug";
|
|
15
|
+
import { isEmptyTextBlock, getTextBlockText, isEqualSelections } from "./_chunks-es/util.is-equal-selections.js";
|
|
16
16
|
import { setup, fromCallback, assign, and, assertEvent, enqueueActions, emit, not, raise as raise$1, createActor } from "xstate";
|
|
17
17
|
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
18
18
|
import { htmlToPortableText } from "@portabletext/html";
|
|
@@ -21,6 +21,211 @@ import { markdownToPortableText, portableTextToMarkdown } from "@portabletext/ma
|
|
|
21
21
|
import { insert, setIfMissing, diffMatchPatch as diffMatchPatch$1, unset, set, applyAll } from "@portabletext/patches";
|
|
22
22
|
import { EditorContext as EditorContext$1 } from "./_chunks-es/use-editor.js";
|
|
23
23
|
import { useEditor } from "./_chunks-es/use-editor.js";
|
|
24
|
+
function serializePath(path2) {
|
|
25
|
+
return path2.reduce((result, segment, index) => isKeyedSegment(segment) ? `${result}[_key=="${segment._key}"]` : `${result}${index === 0 ? "" : "."}${segment}`, "");
|
|
26
|
+
}
|
|
27
|
+
function getDomNode(editor, path2) {
|
|
28
|
+
const editorElement = editor.domElement;
|
|
29
|
+
if (!editorElement)
|
|
30
|
+
return;
|
|
31
|
+
if (path2.length === 0)
|
|
32
|
+
return editorElement;
|
|
33
|
+
const serializedPath = serializePath(path2), selector = `[data-pt-path="${CSS.escape(serializedPath)}"]`, blockSegment = path2[0];
|
|
34
|
+
if (isKeyedSegment(blockSegment)) {
|
|
35
|
+
const blockIndex = editor.blockIndexMap.get(blockSegment._key);
|
|
36
|
+
if (blockIndex !== void 0) {
|
|
37
|
+
const blockNode = editorElement.children[blockIndex];
|
|
38
|
+
if (blockNode instanceof HTMLElement) {
|
|
39
|
+
if (blockNode.matches(selector))
|
|
40
|
+
return blockNode.closest("[data-pt-editor]") !== editorElement ? void 0 : blockNode;
|
|
41
|
+
const domNode2 = blockNode.querySelector(selector);
|
|
42
|
+
if (domNode2 instanceof HTMLElement)
|
|
43
|
+
return domNode2.closest("[data-pt-editor]") !== editorElement ? void 0 : domNode2;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const domNode = editorElement.querySelector(selector);
|
|
48
|
+
if (!(!(domNode instanceof HTMLElement) || domNode.closest("[data-pt-editor]") !== editorElement))
|
|
49
|
+
return domNode;
|
|
50
|
+
}
|
|
51
|
+
const getDefaultView = (value) => value && value.ownerDocument && value.ownerDocument.defaultView || null, isDOMComment = (value) => isDOMNode(value) && value.nodeType === 8, isDOMElement = (value) => isDOMNode(value) && value.nodeType === 1, isDOMNode = (value) => {
|
|
52
|
+
const window2 = getDefaultView(value);
|
|
53
|
+
return !!window2 && value instanceof window2.Node;
|
|
54
|
+
}, isDOMSelection = (value) => {
|
|
55
|
+
const window2 = value && value.anchorNode && getDefaultView(value.anchorNode);
|
|
56
|
+
return !!window2 && value instanceof window2.Selection;
|
|
57
|
+
}, isPlainTextOnlyPaste = (event) => event.clipboardData && event.clipboardData.getData("text/plain") !== "" && event.clipboardData.types.length === 1, normalizeDOMPoint = (domPoint) => {
|
|
58
|
+
let [node, offset] = domPoint;
|
|
59
|
+
if (isDOMElement(node) && node.childNodes.length) {
|
|
60
|
+
let isLast = offset === node.childNodes.length, index = isLast ? offset - 1 : offset;
|
|
61
|
+
for ([node, index] = getEditableChildAndIndex(node, index, isLast ? "backward" : "forward"), isLast = index < offset; isDOMElement(node) && node.childNodes.length; ) {
|
|
62
|
+
const i = isLast ? node.childNodes.length - 1 : 0;
|
|
63
|
+
node = getEditableChild(node, i, isLast ? "backward" : "forward");
|
|
64
|
+
}
|
|
65
|
+
offset = isLast && node.textContent != null ? node.textContent.length : 0;
|
|
66
|
+
}
|
|
67
|
+
return [node, offset];
|
|
68
|
+
}, hasShadowRoot = (node) => {
|
|
69
|
+
let parent = node && node.parentNode;
|
|
70
|
+
for (; parent; ) {
|
|
71
|
+
if (parent.toString() === "[object ShadowRoot]")
|
|
72
|
+
return !0;
|
|
73
|
+
parent = parent.parentNode;
|
|
74
|
+
}
|
|
75
|
+
return !1;
|
|
76
|
+
}, getEditableChildAndIndex = (parent, index, direction) => {
|
|
77
|
+
const {
|
|
78
|
+
childNodes
|
|
79
|
+
} = parent;
|
|
80
|
+
let child = childNodes[index], i = index, triedForward = !1, triedBackward = !1;
|
|
81
|
+
for (; (isDOMComment(child) || isDOMElement(child) && child.childNodes.length === 0 || isDOMElement(child) && child.getAttribute("contenteditable") === "false") && !(triedForward && triedBackward); ) {
|
|
82
|
+
if (i >= childNodes.length) {
|
|
83
|
+
triedForward = !0, i = index - 1, direction = "backward";
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (i < 0) {
|
|
87
|
+
triedBackward = !0, i = index + 1, direction = "forward";
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
child = childNodes[i], index = i, i += direction === "forward" ? 1 : -1;
|
|
91
|
+
}
|
|
92
|
+
return [child, index];
|
|
93
|
+
}, getEditableChild = (parent, index, direction) => {
|
|
94
|
+
const [child] = getEditableChildAndIndex(parent, index, direction);
|
|
95
|
+
return child;
|
|
96
|
+
}, getSelection = (root) => "getSelection" in root && typeof root.getSelection == "function" ? root.getSelection() : document.getSelection(), isTrackedMutation = (editor, mutation, batch) => {
|
|
97
|
+
const {
|
|
98
|
+
target
|
|
99
|
+
} = mutation;
|
|
100
|
+
if (isDOMElement(target) && target.matches('[contentEditable="false"]'))
|
|
101
|
+
return !1;
|
|
102
|
+
const {
|
|
103
|
+
document: document2
|
|
104
|
+
} = DOMEditor.getWindow(editor);
|
|
105
|
+
if (containsShadowAware(document2, target))
|
|
106
|
+
return DOMEditor.hasDOMNode(editor, target, {
|
|
107
|
+
editable: !0
|
|
108
|
+
});
|
|
109
|
+
const parentMutation = batch.find(({
|
|
110
|
+
addedNodes,
|
|
111
|
+
removedNodes
|
|
112
|
+
}) => {
|
|
113
|
+
for (const node of addedNodes)
|
|
114
|
+
if (node === target || containsShadowAware(node, target))
|
|
115
|
+
return !0;
|
|
116
|
+
for (const node of removedNodes)
|
|
117
|
+
if (node === target || containsShadowAware(node, target))
|
|
118
|
+
return !0;
|
|
119
|
+
return !1;
|
|
120
|
+
});
|
|
121
|
+
return !parentMutation || parentMutation === mutation ? !1 : isTrackedMutation(editor, parentMutation, batch);
|
|
122
|
+
}, getActiveElement = () => {
|
|
123
|
+
let activeElement = document.activeElement;
|
|
124
|
+
for (; activeElement?.shadowRoot && activeElement.shadowRoot?.activeElement; )
|
|
125
|
+
activeElement = activeElement?.shadowRoot?.activeElement;
|
|
126
|
+
return activeElement;
|
|
127
|
+
}, isBefore = (node, otherNode) => !!(node.compareDocumentPosition(otherNode) & Node.DOCUMENT_POSITION_PRECEDING), isAfter = (node, otherNode) => !!(node.compareDocumentPosition(otherNode) & Node.DOCUMENT_POSITION_FOLLOWING), closestShadowAware = (element, selector) => {
|
|
128
|
+
if (!element)
|
|
129
|
+
return null;
|
|
130
|
+
let current = element;
|
|
131
|
+
for (; current; ) {
|
|
132
|
+
if (current.matches && current.matches(selector))
|
|
133
|
+
return current;
|
|
134
|
+
if (current.parentElement)
|
|
135
|
+
current = current.parentElement;
|
|
136
|
+
else if (current.parentNode && "host" in current.parentNode)
|
|
137
|
+
current = current.parentNode.host;
|
|
138
|
+
else
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}, containsShadowAware = (parent, child) => {
|
|
143
|
+
if (!parent || !child)
|
|
144
|
+
return !1;
|
|
145
|
+
if (parent.contains(child))
|
|
146
|
+
return !0;
|
|
147
|
+
let current = child;
|
|
148
|
+
for (; current; ) {
|
|
149
|
+
if (current === parent)
|
|
150
|
+
return !0;
|
|
151
|
+
if (current.parentNode)
|
|
152
|
+
"host" in current.parentNode ? current = current.parentNode.host : current = current.parentNode;
|
|
153
|
+
else
|
|
154
|
+
return !1;
|
|
155
|
+
}
|
|
156
|
+
return !1;
|
|
157
|
+
}, KEYED_SEGMENT_PATTERN = /\[_key=="(.+?)"\]/;
|
|
158
|
+
function deserializePath(serializedPath) {
|
|
159
|
+
const path2 = [];
|
|
160
|
+
let remaining = serializedPath;
|
|
161
|
+
for (; remaining.length > 0; ) {
|
|
162
|
+
remaining.startsWith(".") && (remaining = remaining.slice(1));
|
|
163
|
+
const keyMatch = remaining.match(KEYED_SEGMENT_PATTERN);
|
|
164
|
+
if (keyMatch?.[1] && remaining.startsWith("[")) {
|
|
165
|
+
path2.push({
|
|
166
|
+
_key: keyMatch[1]
|
|
167
|
+
}), remaining = remaining.slice(keyMatch[0].length);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const nextBracket = remaining.indexOf("["), nextDot = remaining.indexOf(".");
|
|
171
|
+
let end2;
|
|
172
|
+
nextBracket === -1 && nextDot === -1 ? end2 = remaining.length : nextBracket === -1 ? end2 = nextDot : nextDot === -1 ? end2 = nextBracket : end2 = Math.min(nextBracket, nextDot);
|
|
173
|
+
const fieldName = remaining.slice(0, end2);
|
|
174
|
+
fieldName && path2.push(fieldName), remaining = remaining.slice(end2);
|
|
175
|
+
}
|
|
176
|
+
return path2;
|
|
177
|
+
}
|
|
178
|
+
function getDomNodePath(domNode) {
|
|
179
|
+
let element = isDOMElement(domNode) ? domNode : domNode.parentElement;
|
|
180
|
+
if (element && !element.hasAttribute("data-pt-path") && (element = element.closest("[data-pt-path]")), !element)
|
|
181
|
+
return;
|
|
182
|
+
const dataPath = element.getAttribute("data-pt-path");
|
|
183
|
+
if (dataPath !== null)
|
|
184
|
+
return dataPath === "" ? [] : deserializePath(dataPath);
|
|
185
|
+
}
|
|
186
|
+
function safeStringify(value, space) {
|
|
187
|
+
try {
|
|
188
|
+
return JSON.stringify(value, null, space);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
return console.error(error), "JSON.stringify failed";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function safeParse(text) {
|
|
194
|
+
try {
|
|
195
|
+
return JSON.parse(text);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
return console.error(error), "JSON.parse failed";
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function getAncestorObjectNode(snapshot, path2) {
|
|
201
|
+
const result = getAncestor(snapshot, path2, (node) => isObjectNode({
|
|
202
|
+
schema: snapshot.context.schema
|
|
203
|
+
}, node));
|
|
204
|
+
if (result && isObjectNode({
|
|
205
|
+
schema: snapshot.context.schema
|
|
206
|
+
}, result.node))
|
|
207
|
+
return {
|
|
208
|
+
node: result.node,
|
|
209
|
+
path: result.path
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function commonPath(path2, another) {
|
|
213
|
+
const common = [];
|
|
214
|
+
for (let i = 0; i < path2.length && i < another.length; i++) {
|
|
215
|
+
const segment = path2.at(i), otherSegment = another.at(i);
|
|
216
|
+
if (segment === void 0 || otherSegment === void 0)
|
|
217
|
+
break;
|
|
218
|
+
if (isKeyedSegment(segment) && isKeyedSegment(otherSegment)) {
|
|
219
|
+
if (segment._key !== otherSegment._key)
|
|
220
|
+
break;
|
|
221
|
+
common.push(segment);
|
|
222
|
+
} else if (segment === otherSegment)
|
|
223
|
+
common.push(segment);
|
|
224
|
+
else
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
return common;
|
|
228
|
+
}
|
|
24
229
|
function isPath(value) {
|
|
25
230
|
return Array.isArray(value) && (value.length === 0 || typeof value[0] == "number" || typeof value[0] == "string" || isKeyedSegment(value[0]));
|
|
26
231
|
}
|
|
@@ -31,7 +236,37 @@ function isPoint(value) {
|
|
|
31
236
|
function isRange(value) {
|
|
32
237
|
return isObject(value) && isPoint(value.anchor) && isPoint(value.focus);
|
|
33
238
|
}
|
|
34
|
-
|
|
239
|
+
function rangeEnd(range2, root) {
|
|
240
|
+
const [, end2] = rangeEdges(range2, root);
|
|
241
|
+
return end2;
|
|
242
|
+
}
|
|
243
|
+
function rangeStart(range2, root) {
|
|
244
|
+
const [start2] = rangeEdges(range2, root);
|
|
245
|
+
return start2;
|
|
246
|
+
}
|
|
247
|
+
function path(editor, at, options = {}) {
|
|
248
|
+
const {
|
|
249
|
+
depth,
|
|
250
|
+
edge
|
|
251
|
+
} = options;
|
|
252
|
+
if (isPath(at) && (edge === "start" || edge === "end")) {
|
|
253
|
+
const leaf = getLeaf(editor, at, {
|
|
254
|
+
edge
|
|
255
|
+
});
|
|
256
|
+
leaf && (at = leaf.path);
|
|
257
|
+
}
|
|
258
|
+
return isRange(at) && (edge === "start" ? at = rangeStart(at, editor) : edge === "end" ? at = rangeEnd(at, editor) : at = commonPath(at.anchor.path, at.focus.path)), isPoint(at) && (at = at.path), depth != null && (at = sliceToNodeDepth(at, depth)), at;
|
|
259
|
+
}
|
|
260
|
+
function sliceToNodeDepth(nodePath, depth) {
|
|
261
|
+
let nodeCount = 0;
|
|
262
|
+
for (let i = 0; i < nodePath.length; i++) {
|
|
263
|
+
const segment = nodePath[i];
|
|
264
|
+
if ((isKeyedSegment(segment) || typeof segment == "number") && (nodeCount++, nodeCount === depth))
|
|
265
|
+
return nodePath.slice(0, i + 1);
|
|
266
|
+
}
|
|
267
|
+
return nodePath;
|
|
268
|
+
}
|
|
269
|
+
const EDITOR_BRAND = /* @__PURE__ */ Symbol.for("editor-engine");
|
|
35
270
|
function isEditor(value) {
|
|
36
271
|
return isObject(value) && value[EDITOR_BRAND] === !0;
|
|
37
272
|
}
|
|
@@ -74,16 +309,16 @@ function point(editor, at, options = {}) {
|
|
|
74
309
|
}
|
|
75
310
|
return at;
|
|
76
311
|
}
|
|
77
|
-
function end(editor, at) {
|
|
78
|
-
return point(editor, at, {
|
|
79
|
-
edge: "end"
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
312
|
function start(editor, at) {
|
|
83
313
|
return point(editor, at, {
|
|
84
314
|
edge: "start"
|
|
85
315
|
});
|
|
86
316
|
}
|
|
317
|
+
function isVoidNode(snapshot, node, path2) {
|
|
318
|
+
return isObjectNode({
|
|
319
|
+
schema: snapshot.context.schema
|
|
320
|
+
}, node) && !isEditableContainer(snapshot, node, path2);
|
|
321
|
+
}
|
|
87
322
|
function pathEquals(path2, another) {
|
|
88
323
|
if (path2.length !== another.length)
|
|
89
324
|
return !1;
|
|
@@ -100,269 +335,6 @@ function pathEquals(path2, another) {
|
|
|
100
335
|
function pointEquals(point2, another) {
|
|
101
336
|
return point2.offset === another.offset && pathEquals(point2.path, another.path);
|
|
102
337
|
}
|
|
103
|
-
function resolveSelection(editor, selection) {
|
|
104
|
-
if (!selection)
|
|
105
|
-
return null;
|
|
106
|
-
if (isEqualSelectionPoints(selection.anchor, selection.focus)) {
|
|
107
|
-
const anchorPoint2 = resolveSelectionPoint(editor, selection.anchor, selection.backward ? "backward" : "forward");
|
|
108
|
-
return anchorPoint2 ? {
|
|
109
|
-
anchor: anchorPoint2,
|
|
110
|
-
focus: anchorPoint2
|
|
111
|
-
} : null;
|
|
112
|
-
}
|
|
113
|
-
const anchorPoint = resolveSelectionPoint(editor, selection.anchor, selection.backward ? "forward" : "backward"), focusPoint = resolveSelectionPoint(editor, selection.focus, selection.backward ? "backward" : "forward");
|
|
114
|
-
return !anchorPoint || !focusPoint ? null : {
|
|
115
|
-
anchor: anchorPoint,
|
|
116
|
-
focus: focusPoint
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function resolveSelectionPoint(editor, selectionPoint, direction) {
|
|
120
|
-
const snapshot = {
|
|
121
|
-
context: {
|
|
122
|
-
schema: editor.schema,
|
|
123
|
-
containers: editor.publicContainers,
|
|
124
|
-
value: editor.children
|
|
125
|
-
},
|
|
126
|
-
blockIndexMap: editor.blockIndexMap
|
|
127
|
-
}, entry = getNode(snapshot, selectionPoint.path);
|
|
128
|
-
if (entry) {
|
|
129
|
-
if (getChildren(snapshot, entry.path).length === 0)
|
|
130
|
-
return {
|
|
131
|
-
path: entry.path,
|
|
132
|
-
offset: isSpan({
|
|
133
|
-
schema: editor.schema
|
|
134
|
-
}, entry.node) ? Math.min(entry.node.text.length, selectionPoint.offset) : 0
|
|
135
|
-
};
|
|
136
|
-
const isBlockLevelPath = isBlock(snapshot, selectionPoint.path);
|
|
137
|
-
if (isTextBlock({
|
|
138
|
-
schema: editor.schema
|
|
139
|
-
}, entry.node) && isBlockLevelPath) {
|
|
140
|
-
const spanPoint = blockOffsetToSpanSelectionPoint({
|
|
141
|
-
snapshot,
|
|
142
|
-
blockOffset: {
|
|
143
|
-
path: entry.path,
|
|
144
|
-
offset: selectionPoint.offset
|
|
145
|
-
},
|
|
146
|
-
direction
|
|
147
|
-
});
|
|
148
|
-
if (spanPoint)
|
|
149
|
-
return spanPoint;
|
|
150
|
-
}
|
|
151
|
-
const leaf2 = getLeaf(snapshot, entry.path, {
|
|
152
|
-
edge: direction === "forward" ? "start" : "end"
|
|
153
|
-
});
|
|
154
|
-
return leaf2 ? {
|
|
155
|
-
path: leaf2.path,
|
|
156
|
-
offset: 0
|
|
157
|
-
} : {
|
|
158
|
-
path: entry.path,
|
|
159
|
-
offset: 0
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
const blockKey = getBlockKeyFromSelectionPoint(selectionPoint);
|
|
163
|
-
if (!blockKey)
|
|
164
|
-
return;
|
|
165
|
-
const blockEntry = getNode(snapshot, [{
|
|
166
|
-
_key: blockKey
|
|
167
|
-
}]);
|
|
168
|
-
if (!blockEntry)
|
|
169
|
-
return;
|
|
170
|
-
const leaf = getLeaf(snapshot, blockEntry.path, {
|
|
171
|
-
edge: "start"
|
|
172
|
-
});
|
|
173
|
-
return leaf ? {
|
|
174
|
-
path: leaf.path,
|
|
175
|
-
offset: 0
|
|
176
|
-
} : {
|
|
177
|
-
path: blockEntry.path,
|
|
178
|
-
offset: 0
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
function applySelect(editor, target) {
|
|
182
|
-
const range2 = toRange(editor, target), {
|
|
183
|
-
selection
|
|
184
|
-
} = editor;
|
|
185
|
-
if (selection) {
|
|
186
|
-
const oldProps = {}, newProps = {};
|
|
187
|
-
range2.anchor != null && !pointEquals(range2.anchor, selection.anchor) && (oldProps.anchor = selection.anchor, newProps.anchor = range2.anchor), range2.focus != null && !pointEquals(range2.focus, selection.focus) && (oldProps.focus = selection.focus, newProps.focus = range2.focus), Object.keys(oldProps).length > 0 && editor.apply({
|
|
188
|
-
type: "set_selection",
|
|
189
|
-
properties: oldProps,
|
|
190
|
-
newProperties: newProps
|
|
191
|
-
});
|
|
192
|
-
} else
|
|
193
|
-
editor.apply({
|
|
194
|
-
type: "set_selection",
|
|
195
|
-
properties: null,
|
|
196
|
-
newProperties: range2
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
function applyDeselect(editor) {
|
|
200
|
-
const {
|
|
201
|
-
selection
|
|
202
|
-
} = editor;
|
|
203
|
-
selection && editor.apply({
|
|
204
|
-
type: "set_selection",
|
|
205
|
-
properties: selection,
|
|
206
|
-
newProperties: null
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
function toRange(editor, target) {
|
|
210
|
-
if (isRange(target))
|
|
211
|
-
return target;
|
|
212
|
-
if (isPoint(target))
|
|
213
|
-
return {
|
|
214
|
-
anchor: target,
|
|
215
|
-
focus: target
|
|
216
|
-
};
|
|
217
|
-
const start$1 = start(editor, target), end$1 = end(editor, target);
|
|
218
|
-
return {
|
|
219
|
-
anchor: start$1,
|
|
220
|
-
focus: end$1
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
const rootName = "pte:";
|
|
224
|
-
function createDebugger(name) {
|
|
225
|
-
const namespace = `${rootName}${name}`;
|
|
226
|
-
return rawDebug && rawDebug.enabled(namespace) ? rawDebug(namespace) : rawDebug(rootName);
|
|
227
|
-
}
|
|
228
|
-
const debug = {
|
|
229
|
-
behaviors: createDebugger("behaviors"),
|
|
230
|
-
history: createDebugger("history"),
|
|
231
|
-
mutation: createDebugger("mutation"),
|
|
232
|
-
normalization: createDebugger("normalization"),
|
|
233
|
-
operation: createDebugger("operation"),
|
|
234
|
-
selection: createDebugger("selection"),
|
|
235
|
-
setup: createDebugger("setup"),
|
|
236
|
-
state: createDebugger("state"),
|
|
237
|
-
syncValue: createDebugger("sync:value"),
|
|
238
|
-
syncPatch: createDebugger("sync:patch")
|
|
239
|
-
};
|
|
240
|
-
function serializePath(path2) {
|
|
241
|
-
return path2.reduce((result, segment, index) => isKeyedSegment(segment) ? `${result}[_key=="${segment._key}"]` : `${result}${index === 0 ? "" : "."}${segment}`, "");
|
|
242
|
-
}
|
|
243
|
-
function getDomNode(editor, path2) {
|
|
244
|
-
const editorElement = editor.domElement;
|
|
245
|
-
if (!editorElement)
|
|
246
|
-
return;
|
|
247
|
-
if (path2.length === 0)
|
|
248
|
-
return editorElement;
|
|
249
|
-
const serializedPath = serializePath(path2), selector = `[data-pt-path="${CSS.escape(serializedPath)}"]`, blockSegment = path2[0];
|
|
250
|
-
if (isKeyedSegment(blockSegment)) {
|
|
251
|
-
const blockIndex = editor.blockIndexMap.get(blockSegment._key);
|
|
252
|
-
if (blockIndex !== void 0) {
|
|
253
|
-
const blockNode = editorElement.children[blockIndex];
|
|
254
|
-
if (blockNode instanceof HTMLElement) {
|
|
255
|
-
if (blockNode.matches(selector))
|
|
256
|
-
return blockNode.closest("[data-pt-editor]") !== editorElement ? void 0 : blockNode;
|
|
257
|
-
const domNode2 = blockNode.querySelector(selector);
|
|
258
|
-
if (domNode2 instanceof HTMLElement)
|
|
259
|
-
return domNode2.closest("[data-pt-editor]") !== editorElement ? void 0 : domNode2;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
const domNode = editorElement.querySelector(selector);
|
|
264
|
-
if (!(!(domNode instanceof HTMLElement) || domNode.closest("[data-pt-editor]") !== editorElement))
|
|
265
|
-
return domNode;
|
|
266
|
-
}
|
|
267
|
-
const KEYED_SEGMENT_PATTERN = /\[_key=="(.+?)"\]/;
|
|
268
|
-
function deserializePath(serializedPath) {
|
|
269
|
-
const path2 = [];
|
|
270
|
-
let remaining = serializedPath;
|
|
271
|
-
for (; remaining.length > 0; ) {
|
|
272
|
-
remaining.startsWith(".") && (remaining = remaining.slice(1));
|
|
273
|
-
const keyMatch = remaining.match(KEYED_SEGMENT_PATTERN);
|
|
274
|
-
if (keyMatch?.[1] && remaining.startsWith("[")) {
|
|
275
|
-
path2.push({
|
|
276
|
-
_key: keyMatch[1]
|
|
277
|
-
}), remaining = remaining.slice(keyMatch[0].length);
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
const nextBracket = remaining.indexOf("["), nextDot = remaining.indexOf(".");
|
|
281
|
-
let end2;
|
|
282
|
-
nextBracket === -1 && nextDot === -1 ? end2 = remaining.length : nextBracket === -1 ? end2 = nextDot : nextDot === -1 ? end2 = nextBracket : end2 = Math.min(nextBracket, nextDot);
|
|
283
|
-
const fieldName = remaining.slice(0, end2);
|
|
284
|
-
fieldName && path2.push(fieldName), remaining = remaining.slice(end2);
|
|
285
|
-
}
|
|
286
|
-
return path2;
|
|
287
|
-
}
|
|
288
|
-
function safeStringify(value, space) {
|
|
289
|
-
try {
|
|
290
|
-
return JSON.stringify(value, null, space);
|
|
291
|
-
} catch (error) {
|
|
292
|
-
return console.error(error), "JSON.stringify failed";
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
function safeParse(text) {
|
|
296
|
-
try {
|
|
297
|
-
return JSON.parse(text);
|
|
298
|
-
} catch (error) {
|
|
299
|
-
return console.error(error), "JSON.parse failed";
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
function getAncestorObjectNode(snapshot, path2) {
|
|
303
|
-
const result = getAncestor(snapshot, path2, (node) => isObjectNode({
|
|
304
|
-
schema: snapshot.context.schema
|
|
305
|
-
}, node));
|
|
306
|
-
if (result && isObjectNode({
|
|
307
|
-
schema: snapshot.context.schema
|
|
308
|
-
}, result.node))
|
|
309
|
-
return {
|
|
310
|
-
node: result.node,
|
|
311
|
-
path: result.path
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
function commonPath(path2, another) {
|
|
315
|
-
const common = [];
|
|
316
|
-
for (let i = 0; i < path2.length && i < another.length; i++) {
|
|
317
|
-
const segment = path2.at(i), otherSegment = another.at(i);
|
|
318
|
-
if (segment === void 0 || otherSegment === void 0)
|
|
319
|
-
break;
|
|
320
|
-
if (isKeyedSegment(segment) && isKeyedSegment(otherSegment)) {
|
|
321
|
-
if (segment._key !== otherSegment._key)
|
|
322
|
-
break;
|
|
323
|
-
common.push(segment);
|
|
324
|
-
} else if (segment === otherSegment)
|
|
325
|
-
common.push(segment);
|
|
326
|
-
else
|
|
327
|
-
break;
|
|
328
|
-
}
|
|
329
|
-
return common;
|
|
330
|
-
}
|
|
331
|
-
function rangeEnd(range2, root) {
|
|
332
|
-
const [, end2] = rangeEdges(range2, root);
|
|
333
|
-
return end2;
|
|
334
|
-
}
|
|
335
|
-
function rangeStart(range2, root) {
|
|
336
|
-
const [start2] = rangeEdges(range2, root);
|
|
337
|
-
return start2;
|
|
338
|
-
}
|
|
339
|
-
function path(editor, at, options = {}) {
|
|
340
|
-
const {
|
|
341
|
-
depth,
|
|
342
|
-
edge
|
|
343
|
-
} = options;
|
|
344
|
-
if (isPath(at) && (edge === "start" || edge === "end")) {
|
|
345
|
-
const leaf = getLeaf(editor, at, {
|
|
346
|
-
edge
|
|
347
|
-
});
|
|
348
|
-
leaf && (at = leaf.path);
|
|
349
|
-
}
|
|
350
|
-
return isRange(at) && (edge === "start" ? at = rangeStart(at, editor) : edge === "end" ? at = rangeEnd(at, editor) : at = commonPath(at.anchor.path, at.focus.path)), isPoint(at) && (at = at.path), depth != null && (at = sliceToNodeDepth(at, depth)), at;
|
|
351
|
-
}
|
|
352
|
-
function sliceToNodeDepth(nodePath, depth) {
|
|
353
|
-
let nodeCount = 0;
|
|
354
|
-
for (let i = 0; i < nodePath.length; i++) {
|
|
355
|
-
const segment = nodePath[i];
|
|
356
|
-
if ((isKeyedSegment(segment) || typeof segment == "number") && (nodeCount++, nodeCount === depth))
|
|
357
|
-
return nodePath.slice(0, i + 1);
|
|
358
|
-
}
|
|
359
|
-
return nodePath;
|
|
360
|
-
}
|
|
361
|
-
function isVoidNode(snapshot, node, path2) {
|
|
362
|
-
return isObjectNode({
|
|
363
|
-
schema: snapshot.context.schema
|
|
364
|
-
}, node) && !isEditableContainer(snapshot, node, path2);
|
|
365
|
-
}
|
|
366
338
|
function isCollapsedRange(range2) {
|
|
367
339
|
const {
|
|
368
340
|
anchor,
|
|
@@ -455,7 +427,7 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
455
427
|
toDOMPoint: (editor, point2) => {
|
|
456
428
|
const nodeEntry = getNode(editor, point2.path), el = getDomNode(editor, point2.path);
|
|
457
429
|
if (!el)
|
|
458
|
-
throw new Error(`Cannot
|
|
430
|
+
throw new Error(`Cannot find a DOM node for editor path: ${point2.path}`);
|
|
459
431
|
let domPoint;
|
|
460
432
|
if (nodeEntry && isVoidNode(editor, nodeEntry.node, point2.path)) {
|
|
461
433
|
const spacer = el.querySelector("[data-pt-zero-width]");
|
|
@@ -494,7 +466,7 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
494
466
|
start2 = end2;
|
|
495
467
|
}
|
|
496
468
|
if (!domPoint)
|
|
497
|
-
throw new Error(`Cannot
|
|
469
|
+
throw new Error(`Cannot find a DOM position for editor location: ${safeStringify(point2)}`);
|
|
498
470
|
return domPoint;
|
|
499
471
|
},
|
|
500
472
|
toDOMRange: (editor, range2) => {
|
|
@@ -504,7 +476,7 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
504
476
|
} = range2, isBackward = isBackwardRange(range2, editor), domAnchor = DOMEditor.toDOMPoint(editor, anchor), domFocus = isCollapsedRange(range2) ? domAnchor : DOMEditor.toDOMPoint(editor, focus), domRange = DOMEditor.getWindow(editor).document.createRange(), [startNode, startOffset] = isBackward ? domFocus : domAnchor, [endNode, endOffset] = isBackward ? domAnchor : domFocus, isStartAtZeroWidth = !!(isDOMElement(startNode) ? startNode : startNode.parentElement).getAttribute("data-pt-zero-width"), isEndAtZeroWidth = !!(isDOMElement(endNode) ? endNode : endNode.parentElement).getAttribute("data-pt-zero-width");
|
|
505
477
|
return domRange.setStart(startNode, isStartAtZeroWidth ? 1 : startOffset), domRange.setEnd(endNode, isEndAtZeroWidth ? 1 : endOffset), domRange;
|
|
506
478
|
},
|
|
507
|
-
|
|
479
|
+
toSelectionPoint: (editor, domPoint, options) => {
|
|
508
480
|
const {
|
|
509
481
|
exactMatch,
|
|
510
482
|
suppressThrow,
|
|
@@ -553,7 +525,7 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
553
525
|
}
|
|
554
526
|
domNode && offset === domNode.textContent.length && // COMPAT: Android IMEs might remove the zero width space while composing,
|
|
555
527
|
// and we don't add it for line-breaks.
|
|
556
|
-
IS_ANDROID && domNode.hasAttribute("data-pt-zero-width") && !domNode.hasAttribute("data-pt-line-break") && domNode.textContent?.startsWith("\uFEFF") && // COMPAT: If the parent node is a
|
|
528
|
+
IS_ANDROID && domNode.hasAttribute("data-pt-zero-width") && !domNode.hasAttribute("data-pt-line-break") && domNode.textContent?.startsWith("\uFEFF") && // COMPAT: If the parent node is a zero-width space, editor is
|
|
557
529
|
// because the text node should have no characters. However, during IME
|
|
558
530
|
// composition the ASCII characters will be prepended to the zero-width
|
|
559
531
|
// space, so subtract 1 from the offset to account for the zero-width
|
|
@@ -574,7 +546,7 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
574
546
|
if (!nodePath) {
|
|
575
547
|
if (suppressThrow)
|
|
576
548
|
return null;
|
|
577
|
-
throw new Error(`Cannot
|
|
549
|
+
throw new Error(`Cannot map DOM position to an editor location: ${domPoint}`);
|
|
578
550
|
}
|
|
579
551
|
let {
|
|
580
552
|
path: path22,
|
|
@@ -617,13 +589,13 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
617
589
|
if (!textNode) {
|
|
618
590
|
if (suppressThrow)
|
|
619
591
|
return null;
|
|
620
|
-
throw new Error(`Cannot
|
|
592
|
+
throw new Error(`Cannot map DOM position to an editor location: ${domPoint}`);
|
|
621
593
|
}
|
|
622
594
|
const path2 = getDomNodePath(textNode);
|
|
623
595
|
if (!path2) {
|
|
624
596
|
if (suppressThrow)
|
|
625
597
|
return null;
|
|
626
|
-
throw new Error(`Cannot
|
|
598
|
+
throw new Error(`Cannot map DOM position to an editor location: ${domPoint}`);
|
|
627
599
|
}
|
|
628
600
|
if (path2.length > 1) {
|
|
629
601
|
const parentPath2 = path2.slice(0, -1), parentEntry = getNode(editor, parentPath2);
|
|
@@ -638,7 +610,7 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
638
610
|
offset
|
|
639
611
|
};
|
|
640
612
|
},
|
|
641
|
-
|
|
613
|
+
toEditorSelection: (editor, domRange, options) => {
|
|
642
614
|
const {
|
|
643
615
|
exactMatch,
|
|
644
616
|
suppressThrow
|
|
@@ -664,308 +636,29 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
664
636
|
anchorNode = domRange.startContainer, anchorOffset = domRange.startOffset, focusNode = domRange.endContainer, focusOffset = domRange.endOffset, isCollapsed = domRange.collapsed;
|
|
665
637
|
if (anchorNode == null || focusNode == null || anchorOffset == null || focusOffset == null) {
|
|
666
638
|
if (suppressThrow)
|
|
667
|
-
return null;
|
|
668
|
-
throw new Error(`Cannot
|
|
669
|
-
}
|
|
670
|
-
IS_FIREFOX && focusNode.textContent?.endsWith(`
|
|
671
|
-
|
|
672
|
-
`) && focusOffset === focusNode.textContent.length && focusOffset--;
|
|
673
|
-
const anchor = DOMEditor.toSlatePoint(editor, [anchorNode, anchorOffset], {
|
|
674
|
-
exactMatch,
|
|
675
|
-
suppressThrow
|
|
676
|
-
});
|
|
677
|
-
if (!anchor)
|
|
678
|
-
return null;
|
|
679
|
-
const focusBeforeAnchor = isBefore(anchorNode, focusNode) || anchorNode === focusNode && focusOffset < anchorOffset, focus = isCollapsed ? anchor : DOMEditor.toSlatePoint(editor, [focusNode, focusOffset], {
|
|
680
|
-
exactMatch,
|
|
681
|
-
suppressThrow,
|
|
682
|
-
searchDirection: focusBeforeAnchor ? "forward" : "backward"
|
|
683
|
-
});
|
|
684
|
-
return focus ? {
|
|
685
|
-
anchor,
|
|
686
|
-
focus
|
|
687
|
-
} : null;
|
|
688
|
-
}
|
|
689
|
-
}, getDefaultView = (value) => value && value.ownerDocument && value.ownerDocument.defaultView || null, isDOMComment = (value) => isDOMNode(value) && value.nodeType === 8, isDOMElement = (value) => isDOMNode(value) && value.nodeType === 1, isDOMNode = (value) => {
|
|
690
|
-
const window2 = getDefaultView(value);
|
|
691
|
-
return !!window2 && value instanceof window2.Node;
|
|
692
|
-
}, isDOMSelection = (value) => {
|
|
693
|
-
const window2 = value && value.anchorNode && getDefaultView(value.anchorNode);
|
|
694
|
-
return !!window2 && value instanceof window2.Selection;
|
|
695
|
-
}, isPlainTextOnlyPaste = (event) => event.clipboardData && event.clipboardData.getData("text/plain") !== "" && event.clipboardData.types.length === 1, normalizeDOMPoint = (domPoint) => {
|
|
696
|
-
let [node, offset] = domPoint;
|
|
697
|
-
if (isDOMElement(node) && node.childNodes.length) {
|
|
698
|
-
let isLast = offset === node.childNodes.length, index = isLast ? offset - 1 : offset;
|
|
699
|
-
for ([node, index] = getEditableChildAndIndex(node, index, isLast ? "backward" : "forward"), isLast = index < offset; isDOMElement(node) && node.childNodes.length; ) {
|
|
700
|
-
const i = isLast ? node.childNodes.length - 1 : 0;
|
|
701
|
-
node = getEditableChild(node, i, isLast ? "backward" : "forward");
|
|
702
|
-
}
|
|
703
|
-
offset = isLast && node.textContent != null ? node.textContent.length : 0;
|
|
704
|
-
}
|
|
705
|
-
return [node, offset];
|
|
706
|
-
}, hasShadowRoot = (node) => {
|
|
707
|
-
let parent = node && node.parentNode;
|
|
708
|
-
for (; parent; ) {
|
|
709
|
-
if (parent.toString() === "[object ShadowRoot]")
|
|
710
|
-
return !0;
|
|
711
|
-
parent = parent.parentNode;
|
|
712
|
-
}
|
|
713
|
-
return !1;
|
|
714
|
-
}, getEditableChildAndIndex = (parent, index, direction) => {
|
|
715
|
-
const {
|
|
716
|
-
childNodes
|
|
717
|
-
} = parent;
|
|
718
|
-
let child = childNodes[index], i = index, triedForward = !1, triedBackward = !1;
|
|
719
|
-
for (; (isDOMComment(child) || isDOMElement(child) && child.childNodes.length === 0 || isDOMElement(child) && child.getAttribute("contenteditable") === "false") && !(triedForward && triedBackward); ) {
|
|
720
|
-
if (i >= childNodes.length) {
|
|
721
|
-
triedForward = !0, i = index - 1, direction = "backward";
|
|
722
|
-
continue;
|
|
723
|
-
}
|
|
724
|
-
if (i < 0) {
|
|
725
|
-
triedBackward = !0, i = index + 1, direction = "forward";
|
|
726
|
-
continue;
|
|
727
|
-
}
|
|
728
|
-
child = childNodes[i], index = i, i += direction === "forward" ? 1 : -1;
|
|
729
|
-
}
|
|
730
|
-
return [child, index];
|
|
731
|
-
}, getEditableChild = (parent, index, direction) => {
|
|
732
|
-
const [child] = getEditableChildAndIndex(parent, index, direction);
|
|
733
|
-
return child;
|
|
734
|
-
}, getSelection = (root) => "getSelection" in root && typeof root.getSelection == "function" ? root.getSelection() : document.getSelection(), isTrackedMutation = (editor, mutation, batch) => {
|
|
735
|
-
const {
|
|
736
|
-
target
|
|
737
|
-
} = mutation;
|
|
738
|
-
if (isDOMElement(target) && target.matches('[contentEditable="false"]'))
|
|
739
|
-
return !1;
|
|
740
|
-
const {
|
|
741
|
-
document: document2
|
|
742
|
-
} = DOMEditor.getWindow(editor);
|
|
743
|
-
if (containsShadowAware(document2, target))
|
|
744
|
-
return DOMEditor.hasDOMNode(editor, target, {
|
|
745
|
-
editable: !0
|
|
746
|
-
});
|
|
747
|
-
const parentMutation = batch.find(({
|
|
748
|
-
addedNodes,
|
|
749
|
-
removedNodes
|
|
750
|
-
}) => {
|
|
751
|
-
for (const node of addedNodes)
|
|
752
|
-
if (node === target || containsShadowAware(node, target))
|
|
753
|
-
return !0;
|
|
754
|
-
for (const node of removedNodes)
|
|
755
|
-
if (node === target || containsShadowAware(node, target))
|
|
756
|
-
return !0;
|
|
757
|
-
return !1;
|
|
758
|
-
});
|
|
759
|
-
return !parentMutation || parentMutation === mutation ? !1 : isTrackedMutation(editor, parentMutation, batch);
|
|
760
|
-
}, getActiveElement = () => {
|
|
761
|
-
let activeElement = document.activeElement;
|
|
762
|
-
for (; activeElement?.shadowRoot && activeElement.shadowRoot?.activeElement; )
|
|
763
|
-
activeElement = activeElement?.shadowRoot?.activeElement;
|
|
764
|
-
return activeElement;
|
|
765
|
-
}, isBefore = (node, otherNode) => !!(node.compareDocumentPosition(otherNode) & Node.DOCUMENT_POSITION_PRECEDING), isAfter = (node, otherNode) => !!(node.compareDocumentPosition(otherNode) & Node.DOCUMENT_POSITION_FOLLOWING), closestShadowAware = (element, selector) => {
|
|
766
|
-
if (!element)
|
|
767
|
-
return null;
|
|
768
|
-
let current = element;
|
|
769
|
-
for (; current; ) {
|
|
770
|
-
if (current.matches && current.matches(selector))
|
|
771
|
-
return current;
|
|
772
|
-
if (current.parentElement)
|
|
773
|
-
current = current.parentElement;
|
|
774
|
-
else if (current.parentNode && "host" in current.parentNode)
|
|
775
|
-
current = current.parentNode.host;
|
|
776
|
-
else
|
|
777
|
-
return null;
|
|
778
|
-
}
|
|
779
|
-
return null;
|
|
780
|
-
}, containsShadowAware = (parent, child) => {
|
|
781
|
-
if (!parent || !child)
|
|
782
|
-
return !1;
|
|
783
|
-
if (parent.contains(child))
|
|
784
|
-
return !0;
|
|
785
|
-
let current = child;
|
|
786
|
-
for (; current; ) {
|
|
787
|
-
if (current === parent)
|
|
788
|
-
return !0;
|
|
789
|
-
if (current.parentNode)
|
|
790
|
-
"host" in current.parentNode ? current = current.parentNode.host : current = current.parentNode;
|
|
791
|
-
else
|
|
792
|
-
return !1;
|
|
793
|
-
}
|
|
794
|
-
return !1;
|
|
795
|
-
};
|
|
796
|
-
function getDomNodePath(domNode) {
|
|
797
|
-
let element = isDOMElement(domNode) ? domNode : domNode.parentElement;
|
|
798
|
-
if (element && !element.hasAttribute("data-pt-path") && (element = element.closest("[data-pt-path]")), !element)
|
|
799
|
-
return;
|
|
800
|
-
const dataPath = element.getAttribute("data-pt-path");
|
|
801
|
-
if (dataPath !== null)
|
|
802
|
-
return dataPath === "" ? [] : deserializePath(dataPath);
|
|
803
|
-
}
|
|
804
|
-
function getEventPosition({
|
|
805
|
-
editorActor,
|
|
806
|
-
slateEditor,
|
|
807
|
-
event
|
|
808
|
-
}) {
|
|
809
|
-
if (editorActor.getSnapshot().matches({
|
|
810
|
-
setup: "setting up"
|
|
811
|
-
}))
|
|
812
|
-
return;
|
|
813
|
-
const eventResult = getEventNode({
|
|
814
|
-
slateEditor,
|
|
815
|
-
event
|
|
816
|
-
});
|
|
817
|
-
if (!eventResult)
|
|
818
|
-
return;
|
|
819
|
-
const {
|
|
820
|
-
node: eventNode,
|
|
821
|
-
path: eventPath
|
|
822
|
-
} = eventResult, eventBlockEntry = getEnclosingBlock(slateEditor, eventPath), eventBlock = eventBlockEntry?.node, eventBlockPath = eventBlockEntry?.path, eventPositionBlock = getEventPositionBlock({
|
|
823
|
-
nodePath: eventPath,
|
|
824
|
-
slateEditor,
|
|
825
|
-
event
|
|
826
|
-
}), eventSelection = getSelectionFromEvent(slateEditor, event) ?? null;
|
|
827
|
-
if (eventBlock && eventBlockPath && eventPositionBlock && !eventSelection && !isEventContainer(slateEditor, eventNode, eventPath))
|
|
828
|
-
return {
|
|
829
|
-
block: eventPositionBlock,
|
|
830
|
-
isEditor: !1,
|
|
831
|
-
isContainer: !1,
|
|
832
|
-
selection: {
|
|
833
|
-
anchor: getBlockStartPoint({
|
|
834
|
-
context: slateEditor,
|
|
835
|
-
block: {
|
|
836
|
-
node: eventBlock,
|
|
837
|
-
path: eventBlockPath
|
|
838
|
-
}
|
|
839
|
-
}),
|
|
840
|
-
focus: getBlockEndPoint({
|
|
841
|
-
context: slateEditor,
|
|
842
|
-
block: {
|
|
843
|
-
node: eventBlock,
|
|
844
|
-
path: eventBlockPath
|
|
845
|
-
}
|
|
846
|
-
})
|
|
847
|
-
}
|
|
848
|
-
};
|
|
849
|
-
if (!eventPositionBlock || !eventSelection)
|
|
850
|
-
return;
|
|
851
|
-
const eventSelectionFocusBlock = getEnclosingBlock(slateEditor, eventSelection.focus.path);
|
|
852
|
-
if (eventSelectionFocusBlock)
|
|
853
|
-
return isSelectionCollapsed(eventSelection) && eventBlock && eventBlockPath && eventSelectionFocusBlock.node._key !== eventBlock._key && !isAncestorPath(eventBlockPath, eventSelectionFocusBlock.path) ? {
|
|
854
|
-
block: eventPositionBlock,
|
|
855
|
-
isEditor: !1,
|
|
856
|
-
isContainer: !1,
|
|
857
|
-
selection: {
|
|
858
|
-
anchor: getBlockStartPoint({
|
|
859
|
-
context: slateEditor,
|
|
860
|
-
block: {
|
|
861
|
-
node: eventBlock,
|
|
862
|
-
path: eventBlockPath
|
|
863
|
-
}
|
|
864
|
-
}),
|
|
865
|
-
focus: getBlockEndPoint({
|
|
866
|
-
context: slateEditor,
|
|
867
|
-
block: {
|
|
868
|
-
node: eventBlock,
|
|
869
|
-
path: eventBlockPath
|
|
870
|
-
}
|
|
871
|
-
})
|
|
872
|
-
}
|
|
873
|
-
} : {
|
|
874
|
-
block: eventPositionBlock,
|
|
875
|
-
isEditor: isEditor(eventNode),
|
|
876
|
-
isContainer: isEditor(eventNode) ? !1 : isEditableContainer(slateEditor, eventNode, eventPath),
|
|
877
|
-
selection: eventSelection
|
|
878
|
-
};
|
|
879
|
-
}
|
|
880
|
-
function getEventNode({
|
|
881
|
-
slateEditor,
|
|
882
|
-
event
|
|
883
|
-
}) {
|
|
884
|
-
if (DOMEditor.hasTarget(slateEditor, event.target))
|
|
885
|
-
try {
|
|
886
|
-
const path2 = getDomNodePath(event.target);
|
|
887
|
-
if (path2) {
|
|
888
|
-
if (path2.length === 0)
|
|
889
|
-
return {
|
|
890
|
-
node: slateEditor,
|
|
891
|
-
path: path2
|
|
892
|
-
};
|
|
893
|
-
{
|
|
894
|
-
const nodeEntry = getNode(slateEditor, path2);
|
|
895
|
-
if (nodeEntry)
|
|
896
|
-
return {
|
|
897
|
-
node: nodeEntry.node,
|
|
898
|
-
path: path2
|
|
899
|
-
};
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
} catch (error) {
|
|
903
|
-
console.error(error);
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
function getEventPositionBlock({
|
|
907
|
-
nodePath,
|
|
908
|
-
slateEditor,
|
|
909
|
-
event
|
|
910
|
-
}) {
|
|
911
|
-
const firstBlockEntry = getNode(slateEditor, [0]);
|
|
912
|
-
if (!firstBlockEntry)
|
|
913
|
-
return;
|
|
914
|
-
const firstBlockElement = getDomNode(slateEditor, firstBlockEntry.path);
|
|
915
|
-
if (!firstBlockElement)
|
|
916
|
-
return;
|
|
917
|
-
const firstBlockRect = firstBlockElement.getBoundingClientRect();
|
|
918
|
-
if (event.pageY < firstBlockRect.top)
|
|
919
|
-
return "start";
|
|
920
|
-
const lastBlock = slateEditor.children.at(-1), lastBlockEntry = lastBlock ? getNode(slateEditor, [{
|
|
921
|
-
_key: lastBlock._key
|
|
922
|
-
}]) : void 0;
|
|
923
|
-
if (!lastBlockEntry)
|
|
924
|
-
return;
|
|
925
|
-
const lastBlockElement = getDomNode(slateEditor, lastBlockEntry.path);
|
|
926
|
-
if (!lastBlockElement)
|
|
927
|
-
return;
|
|
928
|
-
const lastBlockRef = lastBlockElement.getBoundingClientRect();
|
|
929
|
-
if (event.pageY > lastBlockRef.bottom)
|
|
930
|
-
return "end";
|
|
931
|
-
const element = getDomNode(slateEditor, nodePath);
|
|
932
|
-
if (!element)
|
|
933
|
-
return;
|
|
934
|
-
const elementRect = element.getBoundingClientRect(), top = elementRect.top, height = elementRect.height;
|
|
935
|
-
return Math.abs(top - event.pageY) < height / 2 ? "start" : "end";
|
|
936
|
-
}
|
|
937
|
-
function getSelectionFromEvent(editor, event) {
|
|
938
|
-
if (!event.target || !isDOMNode(event.target))
|
|
939
|
-
return;
|
|
940
|
-
const window2 = DOMEditor.getWindow(editor);
|
|
941
|
-
let domRange;
|
|
942
|
-
if (window2.document.caretPositionFromPoint !== void 0) {
|
|
943
|
-
const position = window2.document.caretPositionFromPoint(event.clientX, event.clientY);
|
|
944
|
-
if (position)
|
|
945
|
-
try {
|
|
946
|
-
domRange = window2.document.createRange(), domRange.setStart(position.offsetNode, position.offset), domRange.setEnd(position.offsetNode, position.offset);
|
|
947
|
-
} catch {
|
|
948
|
-
}
|
|
949
|
-
} else if (window2.document.caretRangeFromPoint !== void 0)
|
|
950
|
-
domRange = window2.document.caretRangeFromPoint(event.clientX, event.clientY) ?? void 0;
|
|
951
|
-
else {
|
|
952
|
-
console.warn("Neither caretPositionFromPoint nor caretRangeFromPoint is supported");
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
if (domRange)
|
|
956
|
-
try {
|
|
957
|
-
return DOMEditor.toSlateRange(editor, domRange, {
|
|
958
|
-
exactMatch: !1,
|
|
959
|
-
// It can still throw even with this option set to true
|
|
960
|
-
suppressThrow: !1
|
|
961
|
-
});
|
|
962
|
-
} catch {
|
|
963
|
-
return;
|
|
639
|
+
return null;
|
|
640
|
+
throw new Error(`Cannot map DOM range to an editor selection: ${domRange}`);
|
|
964
641
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
642
|
+
IS_FIREFOX && focusNode.textContent?.endsWith(`
|
|
643
|
+
|
|
644
|
+
`) && focusOffset === focusNode.textContent.length && focusOffset--;
|
|
645
|
+
const anchor = DOMEditor.toSelectionPoint(editor, [anchorNode, anchorOffset], {
|
|
646
|
+
exactMatch,
|
|
647
|
+
suppressThrow
|
|
648
|
+
});
|
|
649
|
+
if (!anchor)
|
|
650
|
+
return null;
|
|
651
|
+
const focusBeforeAnchor = isBefore(anchorNode, focusNode) || anchorNode === focusNode && focusOffset < anchorOffset, focus = isCollapsed ? anchor : DOMEditor.toSelectionPoint(editor, [focusNode, focusOffset], {
|
|
652
|
+
exactMatch,
|
|
653
|
+
suppressThrow,
|
|
654
|
+
searchDirection: focusBeforeAnchor ? "forward" : "backward"
|
|
655
|
+
});
|
|
656
|
+
return focus ? {
|
|
657
|
+
anchor,
|
|
658
|
+
focus
|
|
659
|
+
} : null;
|
|
660
|
+
}
|
|
661
|
+
};
|
|
969
662
|
function getVoidAncestor(snapshot, path2) {
|
|
970
663
|
return getAncestor(snapshot, path2, (node, ancestorPath) => isVoidNode(snapshot, node, ancestorPath));
|
|
971
664
|
}
|
|
@@ -999,6 +692,11 @@ function deselect(editor) {
|
|
|
999
692
|
newProperties: null
|
|
1000
693
|
});
|
|
1001
694
|
}
|
|
695
|
+
function end(editor, at) {
|
|
696
|
+
return point(editor, at, {
|
|
697
|
+
edge: "end"
|
|
698
|
+
});
|
|
699
|
+
}
|
|
1002
700
|
const getCharacterDistance = (str, isRTL = !1) => {
|
|
1003
701
|
const isLTR = !isRTL, codepoints = isRTL ? codepointsIteratorRTL(str) : str;
|
|
1004
702
|
let left = CodepointType.None, right = CodepointType.None, distance = 0, gb11 = null, gb12Or13 = null;
|
|
@@ -1620,6 +1318,12 @@ function isExpandedRange(range2) {
|
|
|
1620
1318
|
function rangeEquals(range2, another) {
|
|
1621
1319
|
return pointEquals(range2.anchor, another.anchor) && pointEquals(range2.focus, another.focus);
|
|
1622
1320
|
}
|
|
1321
|
+
const EditorContext = createContext(null), useEngineStatic = () => {
|
|
1322
|
+
const editor = useContext(EditorContext);
|
|
1323
|
+
if (!editor)
|
|
1324
|
+
throw new Error("The `useEngineStatic` hook must be used inside the <Engine> component's context.");
|
|
1325
|
+
return editor;
|
|
1326
|
+
};
|
|
1623
1327
|
function useIsMounted() {
|
|
1624
1328
|
const isMountedRef = useRef(!1);
|
|
1625
1329
|
return useEffect(() => (isMountedRef.current = !0, () => {
|
|
@@ -1637,12 +1341,6 @@ function useMutationObserver(node, callback, options) {
|
|
|
1637
1341
|
return mutationObserver.observe(node.current, options), () => mutationObserver.disconnect();
|
|
1638
1342
|
}, [mutationObserver, node, options]);
|
|
1639
1343
|
}
|
|
1640
|
-
const EditorContext = createContext(null), useSlateStatic = () => {
|
|
1641
|
-
const editor = useContext(EditorContext);
|
|
1642
|
-
if (!editor)
|
|
1643
|
-
throw new Error("The `useSlateStatic` hook must be used inside the <Slate> component's context.");
|
|
1644
|
-
return editor;
|
|
1645
|
-
};
|
|
1646
1344
|
function isDescendantPath(path2, another) {
|
|
1647
1345
|
return isAncestorPath(another, path2);
|
|
1648
1346
|
}
|
|
@@ -2052,12 +1750,12 @@ function createAndroidInputManager({
|
|
|
2052
1750
|
const data = event.dataTransfer || event.data || void 0;
|
|
2053
1751
|
insertPositionHint !== !1 && type !== "insertText" && type !== "insertCompositionText" && (insertPositionHint = !1);
|
|
2054
1752
|
let [nativeTargetRange] = event.getTargetRanges();
|
|
2055
|
-
nativeTargetRange && (targetRange2 = DOMEditor.
|
|
1753
|
+
nativeTargetRange && (targetRange2 = DOMEditor.toEditorSelection(editor, nativeTargetRange, {
|
|
2056
1754
|
exactMatch: !1,
|
|
2057
1755
|
suppressThrow: !0
|
|
2058
1756
|
}));
|
|
2059
1757
|
const domSelection = DOMEditor.getWindow(editor).getSelection();
|
|
2060
|
-
if (!targetRange2 && domSelection && (nativeTargetRange = domSelection, targetRange2 = DOMEditor.
|
|
1758
|
+
if (!targetRange2 && domSelection && (nativeTargetRange = domSelection, targetRange2 = DOMEditor.toEditorSelection(editor, domSelection, {
|
|
2061
1759
|
exactMatch: !1,
|
|
2062
1760
|
suppressThrow: !0
|
|
2063
1761
|
})), targetRange2 = targetRange2 ?? editor.selection, !targetRange2)
|
|
@@ -2442,7 +2140,7 @@ const MUTATION_OBSERVER_CONFIG$1 = {
|
|
|
2442
2140
|
}) => {
|
|
2443
2141
|
if (!IS_ANDROID)
|
|
2444
2142
|
return null;
|
|
2445
|
-
const editor =
|
|
2143
|
+
const editor = useEngineStatic(), isMounted = useIsMounted(), [inputManager] = useState(() => createAndroidInputManager({
|
|
2446
2144
|
editor,
|
|
2447
2145
|
editorActor,
|
|
2448
2146
|
...options
|
|
@@ -2586,7 +2284,7 @@ function isError(error) {
|
|
|
2586
2284
|
return error instanceof Error;
|
|
2587
2285
|
}
|
|
2588
2286
|
const DecorateContext = createContext({}), useDecorations = (node, path2, parentDecorations) => {
|
|
2589
|
-
const $ = c(11), editor =
|
|
2287
|
+
const $ = c(11), editor = useEngineStatic(), {
|
|
2590
2288
|
decorate,
|
|
2591
2289
|
addEventListener
|
|
2592
2290
|
} = useContext(DecorateContext);
|
|
@@ -2641,7 +2339,7 @@ const Element$1 = (props) => {
|
|
|
2641
2339
|
renderElement,
|
|
2642
2340
|
renderLeaf,
|
|
2643
2341
|
renderText
|
|
2644
|
-
} = props, dataPath = serializePath(props.path), editor =
|
|
2342
|
+
} = props, dataPath = serializePath(props.path), editor = useEngineStatic(), isInline$1 = isInline(editor, props.path), isInNewPipeline = useContext(NewPipelineContext), decorations = useDecorations(element, props.path, parentDecorations);
|
|
2645
2343
|
let t0;
|
|
2646
2344
|
$[0] !== decorations || $[1] !== element || $[2] !== props.path || $[3] !== renderElement || $[4] !== renderLeaf || $[5] !== renderText ? (t0 = {
|
|
2647
2345
|
decorations,
|
|
@@ -2957,14 +2655,14 @@ function getTextContent(editor, path2) {
|
|
|
2957
2655
|
}
|
|
2958
2656
|
return text;
|
|
2959
2657
|
}
|
|
2960
|
-
const
|
|
2658
|
+
const EngineString = (props) => {
|
|
2961
2659
|
const $ = c(6), {
|
|
2962
2660
|
isLast,
|
|
2963
2661
|
leaf,
|
|
2964
2662
|
parent,
|
|
2965
2663
|
path: path2,
|
|
2966
2664
|
text
|
|
2967
|
-
} = props, editor =
|
|
2665
|
+
} = props, editor = useEngineStatic(), parentPath$1 = parentPath(path2), leafText = leaf.text ?? "";
|
|
2968
2666
|
if (leafText === "" && isTextBlock({
|
|
2969
2667
|
schema: editor.schema
|
|
2970
2668
|
}, parent) && parent.children[parent.children.length - 1] === text && getTextContent(editor, parentPath$1) === "") {
|
|
@@ -3009,20 +2707,20 @@ const SlateString = (props) => {
|
|
|
3009
2707
|
})), ZeroWidthString = (props) => {
|
|
3010
2708
|
const $ = c(10), {
|
|
3011
2709
|
isLineBreak: t0
|
|
3012
|
-
} = props, isLineBreak = t0 === void 0 ? !1 : t0, isInNewPipeline = useContext(NewPipelineContext),
|
|
2710
|
+
} = props, isLineBreak = t0 === void 0 ? !1 : t0, isInNewPipeline = useContext(NewPipelineContext), engineValue = isLineBreak ? "n" : "z";
|
|
3013
2711
|
let t1;
|
|
3014
|
-
$[0] !==
|
|
2712
|
+
$[0] !== engineValue || $[1] !== isInNewPipeline || $[2] !== isLineBreak ? (t1 = isInNewPipeline ? {
|
|
3015
2713
|
"data-pt-zero-width": !0,
|
|
3016
2714
|
...isLineBreak ? {
|
|
3017
2715
|
"data-pt-line-break": !0
|
|
3018
2716
|
} : {}
|
|
3019
2717
|
} : {
|
|
3020
|
-
"data-slate-zero-width":
|
|
2718
|
+
"data-slate-zero-width": engineValue,
|
|
3021
2719
|
"data-pt-zero-width": !0,
|
|
3022
2720
|
...isLineBreak ? {
|
|
3023
2721
|
"data-pt-line-break": !0
|
|
3024
2722
|
} : {}
|
|
3025
|
-
}, $[0] =
|
|
2723
|
+
}, $[0] = engineValue, $[1] = isInNewPipeline, $[2] = isLineBreak, $[3] = t1) : t1 = $[3];
|
|
3026
2724
|
const attributes = t1, t2 = !IS_ANDROID || !isLineBreak ? "\uFEFF" : null;
|
|
3027
2725
|
let t3;
|
|
3028
2726
|
$[4] !== isLineBreak ? (t3 = isLineBreak ? /* @__PURE__ */ jsx("br", {}) : null, $[4] = isLineBreak, $[5] = t3) : t3 = $[5];
|
|
@@ -3042,7 +2740,7 @@ const SlateString = (props) => {
|
|
|
3042
2740
|
leafPosition
|
|
3043
2741
|
} = props, renderLeaf = t0 === void 0 ? defaultRenderLeaf : t0, isInNewPipeline = useContext(NewPipelineContext);
|
|
3044
2742
|
let t1;
|
|
3045
|
-
$[0] !== isLast || $[1] !== leaf || $[2] !== parent || $[3] !== path2 || $[4] !== text ? (t1 = /* @__PURE__ */ jsx(
|
|
2743
|
+
$[0] !== isLast || $[1] !== leaf || $[2] !== parent || $[3] !== path2 || $[4] !== text ? (t1 = /* @__PURE__ */ jsx(EngineString, { isLast, leaf, parent, path: path2, text }), $[0] = isLast, $[1] = leaf, $[2] = parent, $[3] = path2, $[4] = text, $[5] = t1) : t1 = $[5];
|
|
3046
2744
|
const children = t1;
|
|
3047
2745
|
let t2;
|
|
3048
2746
|
return $[6] !== children || $[7] !== isInNewPipeline || $[8] !== leaf || $[9] !== leafPosition || $[10] !== path2 || $[11] !== renderLeaf || $[12] !== text ? (t2 = renderLeaf({
|
|
@@ -3139,7 +2837,7 @@ const useChildren = (props) => {
|
|
|
3139
2837
|
renderElement,
|
|
3140
2838
|
renderText,
|
|
3141
2839
|
renderLeaf
|
|
3142
|
-
} = props, editor =
|
|
2840
|
+
} = props, editor = useEngineStatic();
|
|
3143
2841
|
editor.isNodeMapDirty = !1;
|
|
3144
2842
|
const parentContainer = useParentContainer(), parentIsInNewPipeline = useContext(NewPipelineContext), decorationsByChild = useDecorationsByChild(editor, node, parentPath2, decorations);
|
|
3145
2843
|
let children = [], arrayFieldName = "children", childContainer = parentContainer;
|
|
@@ -3237,14 +2935,14 @@ const useChildren = (props) => {
|
|
|
3237
2935
|
throw new Error("Unexpected node type");
|
|
3238
2936
|
});
|
|
3239
2937
|
return childContainer && childContainer !== parentContainer ? /* @__PURE__ */ jsx(ParentContainerContext, { value: childContainer, children: /* @__PURE__ */ jsx(NewPipelineContext.Provider, { value: !0, children: elements }) }) : /* @__PURE__ */ jsx(Fragment, { children: elements });
|
|
3240
|
-
},
|
|
3241
|
-
function
|
|
3242
|
-
const context = useContext(
|
|
2938
|
+
}, EngineSelectorContext = createContext({}), refEquality = (a, b) => a === b;
|
|
2939
|
+
function useEngineSelector(selector, equalityFn = refEquality) {
|
|
2940
|
+
const context = useContext(EngineSelectorContext);
|
|
3243
2941
|
if (!context)
|
|
3244
|
-
throw new Error("The `
|
|
2942
|
+
throw new Error("The `useEngineSelector` hook must be used inside the <Engine> component's context.");
|
|
3245
2943
|
const {
|
|
3246
2944
|
addEventListener
|
|
3247
|
-
} = context, editor =
|
|
2945
|
+
} = context, editor = useEngineStatic(), genericSelector = useCallback(() => selector(editor), [editor, selector]), [selectedState, update] = useGenericSelector(genericSelector, equalityFn);
|
|
3248
2946
|
return useIsomorphicLayoutEffect(() => {
|
|
3249
2947
|
const unsubscribe = addEventListener(update);
|
|
3250
2948
|
return update(), unsubscribe;
|
|
@@ -3273,19 +2971,19 @@ function useSelectorContext() {
|
|
|
3273
2971
|
function useFlushDeferredSelectorsOnRender() {
|
|
3274
2972
|
const {
|
|
3275
2973
|
flushDeferred
|
|
3276
|
-
} = useContext(
|
|
2974
|
+
} = useContext(EngineSelectorContext);
|
|
3277
2975
|
useIsomorphicLayoutEffect(flushDeferred);
|
|
3278
2976
|
}
|
|
3279
|
-
const
|
|
2977
|
+
const useEngine = () => {
|
|
3280
2978
|
const {
|
|
3281
2979
|
addEventListener
|
|
3282
|
-
} = useContext(
|
|
2980
|
+
} = useContext(EngineSelectorContext), [, forceRender] = useReducer((s) => s + 1, 0);
|
|
3283
2981
|
if (!addEventListener)
|
|
3284
|
-
throw new Error("The `
|
|
3285
|
-
return useIsomorphicLayoutEffect(() => addEventListener(forceRender), [addEventListener]),
|
|
2982
|
+
throw new Error("The `useEngine` hook must be used inside the <Engine> component's context.");
|
|
2983
|
+
return useIsomorphicLayoutEffect(() => addEventListener(forceRender), [addEventListener]), useEngineStatic();
|
|
3286
2984
|
};
|
|
3287
2985
|
function useTrackUserInput() {
|
|
3288
|
-
const editor =
|
|
2986
|
+
const editor = useEngineStatic(), receivedUserInput = useRef(!1), animationFrameIdRef = useRef(0), onUserInput = useCallback(() => {
|
|
3289
2987
|
if (receivedUserInput.current)
|
|
3290
2988
|
return;
|
|
3291
2989
|
receivedUserInput.current = !0;
|
|
@@ -3423,7 +3121,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3423
3121
|
scrollSelectionIntoView = defaultScrollSelectionIntoView,
|
|
3424
3122
|
style: userStyle = {},
|
|
3425
3123
|
...attributes
|
|
3426
|
-
} = props, editor =
|
|
3124
|
+
} = props, editor = useEngine(), ref = useRef(null), deferredOperations = useRef([]), processing = useRef(!1), {
|
|
3427
3125
|
onUserInput,
|
|
3428
3126
|
receivedUserInput
|
|
3429
3127
|
} = useTrackUserInput(), [, forceRender] = useReducer((s) => s + 1, 0);
|
|
@@ -3469,7 +3167,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3469
3167
|
focusNode
|
|
3470
3168
|
} = domSelection, anchorNodeSelectable = DOMEditor.hasEditableTarget(editor, anchorNode) || DOMEditor.isTargetInsideNonReadonlyVoid(editor, anchorNode), focusNodeInEditor = DOMEditor.hasTarget(editor, focusNode);
|
|
3471
3169
|
if (anchorNodeSelectable && focusNodeInEditor) {
|
|
3472
|
-
const range2 = DOMEditor.
|
|
3170
|
+
const range2 = DOMEditor.toEditorSelection(editor, domSelection, {
|
|
3473
3171
|
exactMatch: !1,
|
|
3474
3172
|
suppressThrow: !0
|
|
3475
3173
|
});
|
|
@@ -3505,17 +3203,17 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3505
3203
|
const editorElement = editor.domElement;
|
|
3506
3204
|
let hasDomSelectionInEditor = !1;
|
|
3507
3205
|
if (containsShadowAware(editorElement, anchorNode) && containsShadowAware(editorElement, focusNode) && (hasDomSelectionInEditor = !0), hasDomSelection && hasDomSelectionInEditor && selection && !forceChange) {
|
|
3508
|
-
const
|
|
3206
|
+
const editorSelection = DOMEditor.toEditorSelection(editor, domSelection, {
|
|
3509
3207
|
exactMatch: !0,
|
|
3510
|
-
// domSelection is not necessarily a valid
|
|
3208
|
+
// domSelection is not necessarily a valid range
|
|
3511
3209
|
// (e.g. when clicking on contentEditable:false element)
|
|
3512
3210
|
suppressThrow: !0
|
|
3513
3211
|
});
|
|
3514
|
-
if (
|
|
3212
|
+
if (editorSelection && rangeEquals(editorSelection, selection))
|
|
3515
3213
|
return;
|
|
3516
3214
|
}
|
|
3517
3215
|
if (selection && !DOMEditor.hasRange(editor, selection)) {
|
|
3518
|
-
const fallbackRange = DOMEditor.
|
|
3216
|
+
const fallbackRange = DOMEditor.toEditorSelection(editor, domSelection, {
|
|
3519
3217
|
exactMatch: !1,
|
|
3520
3218
|
suppressThrow: !0
|
|
3521
3219
|
});
|
|
@@ -3571,11 +3269,11 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3571
3269
|
if (processing?.current && IS_WEBKIT && root instanceof ShadowRoot) {
|
|
3572
3270
|
const range2 = event.getTargetRanges()[0], newRange = new window.Range();
|
|
3573
3271
|
newRange.setStart(range2.startContainer, range2.startOffset), newRange.setEnd(range2.endContainer, range2.endOffset);
|
|
3574
|
-
const
|
|
3272
|
+
const editorSelection = DOMEditor.toEditorSelection(editor, newRange, {
|
|
3575
3273
|
exactMatch: !1,
|
|
3576
3274
|
suppressThrow: !1
|
|
3577
3275
|
});
|
|
3578
|
-
editor.select(
|
|
3276
|
+
editor.select(editorSelection), event.preventDefault(), event.stopImmediatePropagation();
|
|
3579
3277
|
return;
|
|
3580
3278
|
}
|
|
3581
3279
|
if (onUserInput(), !readOnly && DOMEditor.hasEditableTarget(editor, event.target) && !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
|
|
@@ -3612,7 +3310,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3612
3310
|
if ((!type.startsWith("delete") || type.startsWith("deleteBy")) && !editor.isNodeMapDirty) {
|
|
3613
3311
|
const [targetRange2] = event.getTargetRanges();
|
|
3614
3312
|
if (targetRange2) {
|
|
3615
|
-
const range2 = DOMEditor.
|
|
3313
|
+
const range2 = DOMEditor.toEditorSelection(editor, targetRange2, {
|
|
3616
3314
|
exactMatch: !1,
|
|
3617
3315
|
suppressThrow: !1
|
|
3618
3316
|
});
|
|
@@ -4212,57 +3910,360 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
4212
3910
|
}
|
|
4213
3911
|
}
|
|
4214
3912
|
}
|
|
4215
|
-
}, [readOnly, editor, editorActor, attributes.onKeyDown]),
|
|
4216
|
-
onPaste: useCallback((event) => {
|
|
4217
|
-
!readOnly && DOMEditor.hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onPaste) && (!HAS_BEFORE_INPUT_SUPPORT || isPlainTextOnlyPaste(event.nativeEvent) || IS_WEBKIT) && (event.preventDefault(), editorActor.send({
|
|
4218
|
-
type: "behavior event",
|
|
4219
|
-
behaviorEvent: {
|
|
4220
|
-
type: "input.*",
|
|
4221
|
-
originEvent: {
|
|
4222
|
-
dataTransfer: event.clipboardData
|
|
4223
|
-
}
|
|
4224
|
-
},
|
|
4225
|
-
editor
|
|
4226
|
-
}));
|
|
4227
|
-
}, [readOnly, editor, editorActor, attributes.onPaste]),
|
|
4228
|
-
children: /* @__PURE__ */ jsx(Children, { decorations, node: editor, path: [], renderElement, renderLeaf, renderText })
|
|
4229
|
-
}
|
|
4230
|
-
) }) }) });
|
|
4231
|
-
}), defaultDecorate = () => [], defaultScrollSelectionIntoView = (editor, domRange) => {
|
|
4232
|
-
const isBackward = !!editor.selection && isBackwardRange(editor.selection, editor), domFocusPoint = domRange.cloneRange();
|
|
4233
|
-
if (domFocusPoint.collapse(isBackward), domFocusPoint.getBoundingClientRect) {
|
|
4234
|
-
const leafEl = domFocusPoint.startContainer.parentElement, domRect = domFocusPoint.getBoundingClientRect();
|
|
4235
|
-
if (domRect.width === 0 && domRect.height === 0 && domRect.x === 0 && domRect.y === 0) {
|
|
4236
|
-
const leafRect = leafEl.getBoundingClientRect();
|
|
4237
|
-
if (leafRect.width > 0 || leafRect.height > 0)
|
|
4238
|
-
return;
|
|
3913
|
+
}, [readOnly, editor, editorActor, attributes.onKeyDown]),
|
|
3914
|
+
onPaste: useCallback((event) => {
|
|
3915
|
+
!readOnly && DOMEditor.hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onPaste) && (!HAS_BEFORE_INPUT_SUPPORT || isPlainTextOnlyPaste(event.nativeEvent) || IS_WEBKIT) && (event.preventDefault(), editorActor.send({
|
|
3916
|
+
type: "behavior event",
|
|
3917
|
+
behaviorEvent: {
|
|
3918
|
+
type: "input.*",
|
|
3919
|
+
originEvent: {
|
|
3920
|
+
dataTransfer: event.clipboardData
|
|
3921
|
+
}
|
|
3922
|
+
},
|
|
3923
|
+
editor
|
|
3924
|
+
}));
|
|
3925
|
+
}, [readOnly, editor, editorActor, attributes.onPaste]),
|
|
3926
|
+
children: /* @__PURE__ */ jsx(Children, { decorations, node: editor, path: [], renderElement, renderLeaf, renderText })
|
|
3927
|
+
}
|
|
3928
|
+
) }) }) });
|
|
3929
|
+
}), defaultDecorate = () => [], defaultScrollSelectionIntoView = (editor, domRange) => {
|
|
3930
|
+
const isBackward = !!editor.selection && isBackwardRange(editor.selection, editor), domFocusPoint = domRange.cloneRange();
|
|
3931
|
+
if (domFocusPoint.collapse(isBackward), domFocusPoint.getBoundingClientRect) {
|
|
3932
|
+
const leafEl = domFocusPoint.startContainer.parentElement, domRect = domFocusPoint.getBoundingClientRect();
|
|
3933
|
+
if (domRect.width === 0 && domRect.height === 0 && domRect.x === 0 && domRect.y === 0) {
|
|
3934
|
+
const leafRect = leafEl.getBoundingClientRect();
|
|
3935
|
+
if (leafRect.width > 0 || leafRect.height > 0)
|
|
3936
|
+
return;
|
|
3937
|
+
}
|
|
3938
|
+
leafEl.getBoundingClientRect = domFocusPoint.getBoundingClientRect.bind(domFocusPoint), scrollIntoView(leafEl, {
|
|
3939
|
+
scrollMode: "if-needed"
|
|
3940
|
+
}), delete leafEl.getBoundingClientRect;
|
|
3941
|
+
}
|
|
3942
|
+
}, isEventHandled = (event, handler) => handler ? handler(event) ?? (event.isDefaultPrevented() || event.isPropagationStopped()) : !1, isDOMEventTargetInput = (event) => isDOMNode(event.target) && (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement), isDOMEventHandled = (event, handler) => handler ? handler(event) ?? event.defaultPrevented : !1, handleNativeHistoryEvents = (editor, editorActor, event) => {
|
|
3943
|
+
if (event.inputType === "historyUndo") {
|
|
3944
|
+
editorActor.send({
|
|
3945
|
+
type: "behavior event",
|
|
3946
|
+
behaviorEvent: {
|
|
3947
|
+
type: "history.undo"
|
|
3948
|
+
},
|
|
3949
|
+
editor
|
|
3950
|
+
});
|
|
3951
|
+
return;
|
|
3952
|
+
}
|
|
3953
|
+
if (event.inputType === "historyRedo") {
|
|
3954
|
+
editorActor.send({
|
|
3955
|
+
type: "behavior event",
|
|
3956
|
+
behaviorEvent: {
|
|
3957
|
+
type: "history.redo"
|
|
3958
|
+
},
|
|
3959
|
+
editor
|
|
3960
|
+
});
|
|
3961
|
+
return;
|
|
3962
|
+
}
|
|
3963
|
+
};
|
|
3964
|
+
function resolveSelection(editor, selection) {
|
|
3965
|
+
if (!selection)
|
|
3966
|
+
return null;
|
|
3967
|
+
if (isEqualSelectionPoints(selection.anchor, selection.focus)) {
|
|
3968
|
+
const anchorPoint2 = resolveSelectionPoint(editor, selection.anchor, selection.backward ? "backward" : "forward");
|
|
3969
|
+
return anchorPoint2 ? {
|
|
3970
|
+
anchor: anchorPoint2,
|
|
3971
|
+
focus: anchorPoint2
|
|
3972
|
+
} : null;
|
|
3973
|
+
}
|
|
3974
|
+
const anchorPoint = resolveSelectionPoint(editor, selection.anchor, selection.backward ? "forward" : "backward"), focusPoint = resolveSelectionPoint(editor, selection.focus, selection.backward ? "backward" : "forward");
|
|
3975
|
+
return !anchorPoint || !focusPoint ? null : {
|
|
3976
|
+
anchor: anchorPoint,
|
|
3977
|
+
focus: focusPoint
|
|
3978
|
+
};
|
|
3979
|
+
}
|
|
3980
|
+
function resolveSelectionPoint(editor, selectionPoint, direction) {
|
|
3981
|
+
const snapshot = {
|
|
3982
|
+
context: {
|
|
3983
|
+
schema: editor.schema,
|
|
3984
|
+
containers: editor.publicContainers,
|
|
3985
|
+
value: editor.children
|
|
3986
|
+
},
|
|
3987
|
+
blockIndexMap: editor.blockIndexMap
|
|
3988
|
+
}, entry = getNode(snapshot, selectionPoint.path);
|
|
3989
|
+
if (entry) {
|
|
3990
|
+
if (getChildren(snapshot, entry.path).length === 0)
|
|
3991
|
+
return {
|
|
3992
|
+
path: entry.path,
|
|
3993
|
+
offset: isSpan({
|
|
3994
|
+
schema: editor.schema
|
|
3995
|
+
}, entry.node) ? Math.min(entry.node.text.length, selectionPoint.offset) : 0
|
|
3996
|
+
};
|
|
3997
|
+
const isBlockLevelPath = isBlock(snapshot, selectionPoint.path);
|
|
3998
|
+
if (isTextBlock({
|
|
3999
|
+
schema: editor.schema
|
|
4000
|
+
}, entry.node) && isBlockLevelPath) {
|
|
4001
|
+
const spanPoint = blockOffsetToSpanSelectionPoint({
|
|
4002
|
+
snapshot,
|
|
4003
|
+
blockOffset: {
|
|
4004
|
+
path: entry.path,
|
|
4005
|
+
offset: selectionPoint.offset
|
|
4006
|
+
},
|
|
4007
|
+
direction
|
|
4008
|
+
});
|
|
4009
|
+
if (spanPoint)
|
|
4010
|
+
return spanPoint;
|
|
4011
|
+
}
|
|
4012
|
+
const leaf2 = getLeaf(snapshot, entry.path, {
|
|
4013
|
+
edge: direction === "forward" ? "start" : "end"
|
|
4014
|
+
});
|
|
4015
|
+
return leaf2 ? {
|
|
4016
|
+
path: leaf2.path,
|
|
4017
|
+
offset: 0
|
|
4018
|
+
} : {
|
|
4019
|
+
path: entry.path,
|
|
4020
|
+
offset: 0
|
|
4021
|
+
};
|
|
4022
|
+
}
|
|
4023
|
+
const blockKey = getBlockKeyFromSelectionPoint(selectionPoint);
|
|
4024
|
+
if (!blockKey)
|
|
4025
|
+
return;
|
|
4026
|
+
const blockEntry = getNode(snapshot, [{
|
|
4027
|
+
_key: blockKey
|
|
4028
|
+
}]);
|
|
4029
|
+
if (!blockEntry)
|
|
4030
|
+
return;
|
|
4031
|
+
const leaf = getLeaf(snapshot, blockEntry.path, {
|
|
4032
|
+
edge: "start"
|
|
4033
|
+
});
|
|
4034
|
+
return leaf ? {
|
|
4035
|
+
path: leaf.path,
|
|
4036
|
+
offset: 0
|
|
4037
|
+
} : {
|
|
4038
|
+
path: blockEntry.path,
|
|
4039
|
+
offset: 0
|
|
4040
|
+
};
|
|
4041
|
+
}
|
|
4042
|
+
function applySelect(editor, target) {
|
|
4043
|
+
const range2 = toRange(editor, target), {
|
|
4044
|
+
selection
|
|
4045
|
+
} = editor;
|
|
4046
|
+
if (selection) {
|
|
4047
|
+
const oldProps = {}, newProps = {};
|
|
4048
|
+
range2.anchor != null && !pointEquals(range2.anchor, selection.anchor) && (oldProps.anchor = selection.anchor, newProps.anchor = range2.anchor), range2.focus != null && !pointEquals(range2.focus, selection.focus) && (oldProps.focus = selection.focus, newProps.focus = range2.focus), Object.keys(oldProps).length > 0 && editor.apply({
|
|
4049
|
+
type: "set_selection",
|
|
4050
|
+
properties: oldProps,
|
|
4051
|
+
newProperties: newProps
|
|
4052
|
+
});
|
|
4053
|
+
} else
|
|
4054
|
+
editor.apply({
|
|
4055
|
+
type: "set_selection",
|
|
4056
|
+
properties: null,
|
|
4057
|
+
newProperties: range2
|
|
4058
|
+
});
|
|
4059
|
+
}
|
|
4060
|
+
function applyDeselect(editor) {
|
|
4061
|
+
const {
|
|
4062
|
+
selection
|
|
4063
|
+
} = editor;
|
|
4064
|
+
selection && editor.apply({
|
|
4065
|
+
type: "set_selection",
|
|
4066
|
+
properties: selection,
|
|
4067
|
+
newProperties: null
|
|
4068
|
+
});
|
|
4069
|
+
}
|
|
4070
|
+
function toRange(editor, target) {
|
|
4071
|
+
if (isRange(target))
|
|
4072
|
+
return target;
|
|
4073
|
+
if (isPoint(target))
|
|
4074
|
+
return {
|
|
4075
|
+
anchor: target,
|
|
4076
|
+
focus: target
|
|
4077
|
+
};
|
|
4078
|
+
const start$1 = start(editor, target), end$1 = end(editor, target);
|
|
4079
|
+
return {
|
|
4080
|
+
anchor: start$1,
|
|
4081
|
+
focus: end$1
|
|
4082
|
+
};
|
|
4083
|
+
}
|
|
4084
|
+
const rootName = "pte:";
|
|
4085
|
+
function createDebugger(name) {
|
|
4086
|
+
const namespace = `${rootName}${name}`;
|
|
4087
|
+
return rawDebug && rawDebug.enabled(namespace) ? rawDebug(namespace) : rawDebug(rootName);
|
|
4088
|
+
}
|
|
4089
|
+
const debug = {
|
|
4090
|
+
behaviors: createDebugger("behaviors"),
|
|
4091
|
+
history: createDebugger("history"),
|
|
4092
|
+
mutation: createDebugger("mutation"),
|
|
4093
|
+
normalization: createDebugger("normalization"),
|
|
4094
|
+
operation: createDebugger("operation"),
|
|
4095
|
+
selection: createDebugger("selection"),
|
|
4096
|
+
setup: createDebugger("setup"),
|
|
4097
|
+
state: createDebugger("state"),
|
|
4098
|
+
syncValue: createDebugger("sync:value"),
|
|
4099
|
+
syncPatch: createDebugger("sync:patch")
|
|
4100
|
+
};
|
|
4101
|
+
function getEventPosition({
|
|
4102
|
+
editorActor,
|
|
4103
|
+
editorEngine,
|
|
4104
|
+
event
|
|
4105
|
+
}) {
|
|
4106
|
+
if (editorActor.getSnapshot().matches({
|
|
4107
|
+
setup: "setting up"
|
|
4108
|
+
}))
|
|
4109
|
+
return;
|
|
4110
|
+
const eventResult = getEventNode({
|
|
4111
|
+
editorEngine,
|
|
4112
|
+
event
|
|
4113
|
+
});
|
|
4114
|
+
if (!eventResult)
|
|
4115
|
+
return;
|
|
4116
|
+
const {
|
|
4117
|
+
node: eventNode,
|
|
4118
|
+
path: eventPath
|
|
4119
|
+
} = eventResult, eventBlockEntry = getEnclosingBlock(editorEngine, eventPath), eventBlock = eventBlockEntry?.node, eventBlockPath = eventBlockEntry?.path, eventPositionBlock = getEventPositionBlock({
|
|
4120
|
+
nodePath: eventPath,
|
|
4121
|
+
editorEngine,
|
|
4122
|
+
event
|
|
4123
|
+
}), eventSelection = getSelectionFromEvent(editorEngine, event) ?? null;
|
|
4124
|
+
if (eventBlock && eventBlockPath && eventPositionBlock && !eventSelection && !isEventContainer(editorEngine, eventNode, eventPath))
|
|
4125
|
+
return {
|
|
4126
|
+
block: eventPositionBlock,
|
|
4127
|
+
isEditor: !1,
|
|
4128
|
+
isContainer: !1,
|
|
4129
|
+
selection: {
|
|
4130
|
+
anchor: getBlockStartPoint({
|
|
4131
|
+
context: editorEngine,
|
|
4132
|
+
block: {
|
|
4133
|
+
node: eventBlock,
|
|
4134
|
+
path: eventBlockPath
|
|
4135
|
+
}
|
|
4136
|
+
}),
|
|
4137
|
+
focus: getBlockEndPoint({
|
|
4138
|
+
context: editorEngine,
|
|
4139
|
+
block: {
|
|
4140
|
+
node: eventBlock,
|
|
4141
|
+
path: eventBlockPath
|
|
4142
|
+
}
|
|
4143
|
+
})
|
|
4144
|
+
}
|
|
4145
|
+
};
|
|
4146
|
+
if (!eventPositionBlock || !eventSelection)
|
|
4147
|
+
return;
|
|
4148
|
+
const eventSelectionFocusBlock = getEnclosingBlock(editorEngine, eventSelection.focus.path);
|
|
4149
|
+
if (eventSelectionFocusBlock)
|
|
4150
|
+
return isSelectionCollapsed(eventSelection) && eventBlock && eventBlockPath && eventSelectionFocusBlock.node._key !== eventBlock._key && !isAncestorPath(eventBlockPath, eventSelectionFocusBlock.path) ? {
|
|
4151
|
+
block: eventPositionBlock,
|
|
4152
|
+
isEditor: !1,
|
|
4153
|
+
isContainer: !1,
|
|
4154
|
+
selection: {
|
|
4155
|
+
anchor: getBlockStartPoint({
|
|
4156
|
+
context: editorEngine,
|
|
4157
|
+
block: {
|
|
4158
|
+
node: eventBlock,
|
|
4159
|
+
path: eventBlockPath
|
|
4160
|
+
}
|
|
4161
|
+
}),
|
|
4162
|
+
focus: getBlockEndPoint({
|
|
4163
|
+
context: editorEngine,
|
|
4164
|
+
block: {
|
|
4165
|
+
node: eventBlock,
|
|
4166
|
+
path: eventBlockPath
|
|
4167
|
+
}
|
|
4168
|
+
})
|
|
4169
|
+
}
|
|
4170
|
+
} : {
|
|
4171
|
+
block: eventPositionBlock,
|
|
4172
|
+
isEditor: isEditor(eventNode),
|
|
4173
|
+
isContainer: isEditor(eventNode) ? !1 : isEditableContainer(editorEngine, eventNode, eventPath),
|
|
4174
|
+
selection: eventSelection
|
|
4175
|
+
};
|
|
4176
|
+
}
|
|
4177
|
+
function getEventNode({
|
|
4178
|
+
editorEngine,
|
|
4179
|
+
event
|
|
4180
|
+
}) {
|
|
4181
|
+
if (DOMEditor.hasTarget(editorEngine, event.target))
|
|
4182
|
+
try {
|
|
4183
|
+
const path2 = getDomNodePath(event.target);
|
|
4184
|
+
if (path2) {
|
|
4185
|
+
if (path2.length === 0)
|
|
4186
|
+
return {
|
|
4187
|
+
node: editorEngine,
|
|
4188
|
+
path: path2
|
|
4189
|
+
};
|
|
4190
|
+
{
|
|
4191
|
+
const nodeEntry = getNode(editorEngine, path2);
|
|
4192
|
+
if (nodeEntry)
|
|
4193
|
+
return {
|
|
4194
|
+
node: nodeEntry.node,
|
|
4195
|
+
path: path2
|
|
4196
|
+
};
|
|
4197
|
+
}
|
|
4198
|
+
}
|
|
4199
|
+
} catch (error) {
|
|
4200
|
+
console.error(error);
|
|
4239
4201
|
}
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
behaviorEvent: {
|
|
4249
|
-
type: "history.undo"
|
|
4250
|
-
},
|
|
4251
|
-
editor
|
|
4252
|
-
});
|
|
4202
|
+
}
|
|
4203
|
+
function getEventPositionBlock({
|
|
4204
|
+
nodePath,
|
|
4205
|
+
editorEngine,
|
|
4206
|
+
event
|
|
4207
|
+
}) {
|
|
4208
|
+
const firstBlockEntry = getNode(editorEngine, [0]);
|
|
4209
|
+
if (!firstBlockEntry)
|
|
4253
4210
|
return;
|
|
4254
|
-
|
|
4255
|
-
if (
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4211
|
+
const firstBlockElement = getDomNode(editorEngine, firstBlockEntry.path);
|
|
4212
|
+
if (!firstBlockElement)
|
|
4213
|
+
return;
|
|
4214
|
+
const firstBlockRect = firstBlockElement.getBoundingClientRect();
|
|
4215
|
+
if (event.pageY < firstBlockRect.top)
|
|
4216
|
+
return "start";
|
|
4217
|
+
const lastBlock = editorEngine.children.at(-1), lastBlockEntry = lastBlock ? getNode(editorEngine, [{
|
|
4218
|
+
_key: lastBlock._key
|
|
4219
|
+
}]) : void 0;
|
|
4220
|
+
if (!lastBlockEntry)
|
|
4221
|
+
return;
|
|
4222
|
+
const lastBlockElement = getDomNode(editorEngine, lastBlockEntry.path);
|
|
4223
|
+
if (!lastBlockElement)
|
|
4224
|
+
return;
|
|
4225
|
+
const lastBlockRef = lastBlockElement.getBoundingClientRect();
|
|
4226
|
+
if (event.pageY > lastBlockRef.bottom)
|
|
4227
|
+
return "end";
|
|
4228
|
+
const element = getDomNode(editorEngine, nodePath);
|
|
4229
|
+
if (!element)
|
|
4230
|
+
return;
|
|
4231
|
+
const elementRect = element.getBoundingClientRect(), top = elementRect.top, height = elementRect.height;
|
|
4232
|
+
return Math.abs(top - event.pageY) < height / 2 ? "start" : "end";
|
|
4233
|
+
}
|
|
4234
|
+
function getSelectionFromEvent(editor, event) {
|
|
4235
|
+
if (!event.target || !isDOMNode(event.target))
|
|
4236
|
+
return;
|
|
4237
|
+
const window2 = DOMEditor.getWindow(editor);
|
|
4238
|
+
let domRange;
|
|
4239
|
+
if (window2.document.caretPositionFromPoint !== void 0) {
|
|
4240
|
+
const position = window2.document.caretPositionFromPoint(event.clientX, event.clientY);
|
|
4241
|
+
if (position)
|
|
4242
|
+
try {
|
|
4243
|
+
domRange = window2.document.createRange(), domRange.setStart(position.offsetNode, position.offset), domRange.setEnd(position.offsetNode, position.offset);
|
|
4244
|
+
} catch {
|
|
4245
|
+
}
|
|
4246
|
+
} else if (window2.document.caretRangeFromPoint !== void 0)
|
|
4247
|
+
domRange = window2.document.caretRangeFromPoint(event.clientX, event.clientY) ?? void 0;
|
|
4248
|
+
else {
|
|
4249
|
+
console.warn("Neither caretPositionFromPoint nor caretRangeFromPoint is supported");
|
|
4263
4250
|
return;
|
|
4264
4251
|
}
|
|
4265
|
-
|
|
4252
|
+
if (domRange)
|
|
4253
|
+
try {
|
|
4254
|
+
return DOMEditor.toEditorSelection(editor, domRange, {
|
|
4255
|
+
exactMatch: !1,
|
|
4256
|
+
// It can still throw even with this option set to true
|
|
4257
|
+
suppressThrow: !1
|
|
4258
|
+
});
|
|
4259
|
+
} catch {
|
|
4260
|
+
return;
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
function isEventContainer(editorEngine, eventNode, eventPath) {
|
|
4264
|
+
return isEditor(eventNode) ? !0 : isEditableContainer(editorEngine, eventNode, eventPath);
|
|
4265
|
+
}
|
|
4266
|
+
const EditorActorContext = createContext({}), IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
|
|
4266
4267
|
alt: "altKey",
|
|
4267
4268
|
control: "ctrlKey",
|
|
4268
4269
|
meta: "metaKey",
|
|
@@ -4419,13 +4420,6 @@ function performHotkey({
|
|
|
4419
4420
|
}
|
|
4420
4421
|
});
|
|
4421
4422
|
}
|
|
4422
|
-
function moveRangeByOperation(range2, operation) {
|
|
4423
|
-
const anchor = transformPoint$1(range2.anchor, operation), focus = transformPoint$1(range2.focus, operation);
|
|
4424
|
-
return anchor === null || focus === null ? null : pointEquals(anchor, range2.anchor) && pointEquals(focus, range2.focus) ? range2 : {
|
|
4425
|
-
anchor,
|
|
4426
|
-
focus
|
|
4427
|
-
};
|
|
4428
|
-
}
|
|
4429
4423
|
function rangeIncludes(range2, target, root) {
|
|
4430
4424
|
if (isRange(target)) {
|
|
4431
4425
|
if (rangeIncludes(range2, target.anchor, root) || rangeIncludes(range2, target.focus, root))
|
|
@@ -4437,18 +4431,25 @@ function rangeIncludes(range2, target, root) {
|
|
|
4437
4431
|
let isAfterStart = !1, isBeforeEnd = !1;
|
|
4438
4432
|
return isPoint(target) ? (isAfterStart = comparePoints(target, start2, root) >= 0, isBeforeEnd = comparePoints(target, end2, root) <= 0) : (isAfterStart = comparePaths(target, start2.path, root) >= 0, isBeforeEnd = comparePaths(target, end2.path, root) <= 0), isAfterStart && isBeforeEnd;
|
|
4439
4433
|
}
|
|
4440
|
-
|
|
4434
|
+
function moveRangeByOperation(range2, operation) {
|
|
4435
|
+
const anchor = transformPoint$1(range2.anchor, operation), focus = transformPoint$1(range2.focus, operation);
|
|
4436
|
+
return anchor === null || focus === null ? null : pointEquals(anchor, range2.anchor) && pointEquals(focus, range2.focus) ? range2 : {
|
|
4437
|
+
anchor,
|
|
4438
|
+
focus
|
|
4439
|
+
};
|
|
4440
|
+
}
|
|
4441
|
+
const engineOperationCallback = ({
|
|
4441
4442
|
input,
|
|
4442
4443
|
sendBack
|
|
4443
4444
|
}) => {
|
|
4444
|
-
const originalApply = input.
|
|
4445
|
-
return input.
|
|
4445
|
+
const originalApply = input.editorEngine.apply;
|
|
4446
|
+
return input.editorEngine.apply = (op) => {
|
|
4446
4447
|
op.type !== "set_selection" && sendBack({
|
|
4447
|
-
type: "
|
|
4448
|
+
type: "engine operation",
|
|
4448
4449
|
operation: op
|
|
4449
4450
|
}), originalApply(op);
|
|
4450
4451
|
}, () => {
|
|
4451
|
-
input.
|
|
4452
|
+
input.editorEngine.apply = originalApply;
|
|
4452
4453
|
};
|
|
4453
4454
|
}, rangeDecorationsMachine = setup({
|
|
4454
4455
|
types: {
|
|
@@ -4481,7 +4482,7 @@ const slateOperationCallback = ({
|
|
|
4481
4482
|
...rangeDecoration.selection
|
|
4482
4483
|
});
|
|
4483
4484
|
}
|
|
4484
|
-
context.
|
|
4485
|
+
context.editorEngine.decoratedRanges = rangeDecorationState;
|
|
4485
4486
|
},
|
|
4486
4487
|
"update range decorations": ({
|
|
4487
4488
|
context,
|
|
@@ -4504,16 +4505,16 @@ const slateOperationCallback = ({
|
|
|
4504
4505
|
...rangeDecoration.selection
|
|
4505
4506
|
});
|
|
4506
4507
|
}
|
|
4507
|
-
context.
|
|
4508
|
+
context.editorEngine.decoratedRanges = rangeDecorationState;
|
|
4508
4509
|
},
|
|
4509
4510
|
"move range decorations": ({
|
|
4510
4511
|
context,
|
|
4511
4512
|
event
|
|
4512
4513
|
}) => {
|
|
4513
|
-
if (event.type !== "
|
|
4514
|
+
if (event.type !== "engine operation")
|
|
4514
4515
|
return;
|
|
4515
4516
|
const rangeDecorationState = [];
|
|
4516
|
-
for (const decoratedRange of context.
|
|
4517
|
+
for (const decoratedRange of context.editorEngine.decoratedRanges) {
|
|
4517
4518
|
const currentSelection = decoratedRange.rangeDecoration.selection;
|
|
4518
4519
|
if (!currentSelection) {
|
|
4519
4520
|
decoratedRange.rangeDecoration.onMoved?.({
|
|
@@ -4536,7 +4537,7 @@ const slateOperationCallback = ({
|
|
|
4536
4537
|
}
|
|
4537
4538
|
});
|
|
4538
4539
|
}
|
|
4539
|
-
context.
|
|
4540
|
+
context.editorEngine.decoratedRanges = rangeDecorationState;
|
|
4540
4541
|
},
|
|
4541
4542
|
"assign readOnly": assign({
|
|
4542
4543
|
readOnly: ({
|
|
@@ -4548,12 +4549,12 @@ const slateOperationCallback = ({
|
|
|
4548
4549
|
decorate: ({
|
|
4549
4550
|
context
|
|
4550
4551
|
}) => ({
|
|
4551
|
-
fn: createDecorate(context.schema, context.
|
|
4552
|
+
fn: createDecorate(context.schema, context.editorEngine)
|
|
4552
4553
|
})
|
|
4553
4554
|
})
|
|
4554
4555
|
},
|
|
4555
4556
|
actors: {
|
|
4556
|
-
"
|
|
4557
|
+
"engine operation listener": fromCallback(engineOperationCallback)
|
|
4557
4558
|
},
|
|
4558
4559
|
guards: {
|
|
4559
4560
|
"has pending range decorations": ({
|
|
@@ -4561,14 +4562,14 @@ const slateOperationCallback = ({
|
|
|
4561
4562
|
}) => context.pendingRangeDecorations.length > 0,
|
|
4562
4563
|
"has range decorations": ({
|
|
4563
4564
|
context
|
|
4564
|
-
}) => context.
|
|
4565
|
+
}) => context.editorEngine.decoratedRanges.length > 0,
|
|
4565
4566
|
"has different decorations": ({
|
|
4566
4567
|
context,
|
|
4567
4568
|
event
|
|
4568
4569
|
}) => {
|
|
4569
4570
|
if (event.type !== "range decorations updated")
|
|
4570
4571
|
return !1;
|
|
4571
|
-
const existingRangeDecorations = context.
|
|
4572
|
+
const existingRangeDecorations = context.editorEngine.decoratedRanges.map((decoratedRange) => ({
|
|
4572
4573
|
anchor: decoratedRange.rangeDecoration.selection?.anchor,
|
|
4573
4574
|
focus: decoratedRange.rangeDecoration.selection?.focus,
|
|
4574
4575
|
payload: decoratedRange.rangeDecoration.payload
|
|
@@ -4596,17 +4597,17 @@ const slateOperationCallback = ({
|
|
|
4596
4597
|
decoratedRanges: [],
|
|
4597
4598
|
skipSetup: input.skipSetup,
|
|
4598
4599
|
schema: input.schema,
|
|
4599
|
-
|
|
4600
|
+
editorEngine: input.editorEngine,
|
|
4600
4601
|
decorate: {
|
|
4601
|
-
fn: createDecorate(input.schema, input.
|
|
4602
|
+
fn: createDecorate(input.schema, input.editorEngine)
|
|
4602
4603
|
}
|
|
4603
4604
|
}),
|
|
4604
4605
|
invoke: {
|
|
4605
|
-
src: "
|
|
4606
|
+
src: "engine operation listener",
|
|
4606
4607
|
input: ({
|
|
4607
4608
|
context
|
|
4608
4609
|
}) => ({
|
|
4609
|
-
|
|
4610
|
+
editorEngine: context.editorEngine
|
|
4610
4611
|
})
|
|
4611
4612
|
},
|
|
4612
4613
|
on: {
|
|
@@ -4650,7 +4651,7 @@ const slateOperationCallback = ({
|
|
|
4650
4651
|
states: {
|
|
4651
4652
|
idle: {
|
|
4652
4653
|
on: {
|
|
4653
|
-
"
|
|
4654
|
+
"engine operation": {
|
|
4654
4655
|
target: "moving range decorations",
|
|
4655
4656
|
guard: and(["has range decorations", "not read only"])
|
|
4656
4657
|
}
|
|
@@ -4666,10 +4667,10 @@ const slateOperationCallback = ({
|
|
|
4666
4667
|
}
|
|
4667
4668
|
}
|
|
4668
4669
|
});
|
|
4669
|
-
function createDecorate(schema,
|
|
4670
|
+
function createDecorate(schema, editorEngine) {
|
|
4670
4671
|
return function([node, path2]) {
|
|
4671
|
-
const defaultStyle = schema.styles.at(0)?.name, firstBlock =
|
|
4672
|
-
return
|
|
4672
|
+
const defaultStyle = schema.styles.at(0)?.name, firstBlock = editorEngine.children[0];
|
|
4673
|
+
return editorEngine.children.length === 1 && firstBlock && isEmptyTextBlock({
|
|
4673
4674
|
schema
|
|
4674
4675
|
}, firstBlock) && (!firstBlock.style || firstBlock.style === defaultStyle) && !firstBlock.listItem ? [{
|
|
4675
4676
|
anchor: {
|
|
@@ -4682,10 +4683,10 @@ function createDecorate(schema, slateEditor) {
|
|
|
4682
4683
|
},
|
|
4683
4684
|
placeholder: !0
|
|
4684
4685
|
}] : path2.length === 0 ? [] : !isTextBlock({
|
|
4685
|
-
schema:
|
|
4686
|
-
}, node) || node.children.length === 0 ? [] :
|
|
4686
|
+
schema: editorEngine.schema
|
|
4687
|
+
}, node) || node.children.length === 0 ? [] : editorEngine.decoratedRanges.filter((decoratedRange) => {
|
|
4687
4688
|
if (isCollapsedRange(decoratedRange)) {
|
|
4688
|
-
const anchorBlock = getEnclosingBlock(
|
|
4689
|
+
const anchorBlock = getEnclosingBlock(editorEngine, decoratedRange.anchor.path), anchorChildSegment = decoratedRange.anchor.path.at(-1);
|
|
4689
4690
|
return !anchorBlock || !isKeyedSegment(anchorChildSegment) ? !1 : anchorBlock.node._key === node._key && node.children.some((child) => child._key === anchorChildSegment._key);
|
|
4690
4691
|
}
|
|
4691
4692
|
return rangeIntersection(decoratedRange, {
|
|
@@ -4697,7 +4698,7 @@ function createDecorate(schema, slateEditor) {
|
|
|
4697
4698
|
path: path2,
|
|
4698
4699
|
offset: 0
|
|
4699
4700
|
}
|
|
4700
|
-
},
|
|
4701
|
+
}, editorEngine) || rangeIncludes(decoratedRange, path2, editorEngine);
|
|
4701
4702
|
});
|
|
4702
4703
|
};
|
|
4703
4704
|
}
|
|
@@ -4797,22 +4798,22 @@ function useEditorSelector(editor, selector, t0) {
|
|
|
4797
4798
|
}
|
|
4798
4799
|
function getEditorSnapshot({
|
|
4799
4800
|
editorActorSnapshot,
|
|
4800
|
-
|
|
4801
|
+
editorEngineInstance
|
|
4801
4802
|
}) {
|
|
4802
4803
|
return {
|
|
4803
|
-
blockIndexMap:
|
|
4804
|
+
blockIndexMap: editorEngineInstance.blockIndexMap,
|
|
4804
4805
|
context: {
|
|
4805
|
-
containers:
|
|
4806
|
+
containers: editorEngineInstance.publicContainers,
|
|
4806
4807
|
converters: editorActorSnapshot.context.converters,
|
|
4807
4808
|
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
4808
4809
|
readOnly: editorActorSnapshot.matches({
|
|
4809
4810
|
"edit mode": "read only"
|
|
4810
4811
|
}),
|
|
4811
4812
|
schema: editorActorSnapshot.context.schema,
|
|
4812
|
-
selection:
|
|
4813
|
-
value:
|
|
4813
|
+
selection: editorEngineInstance.selection,
|
|
4814
|
+
value: editorEngineInstance.children
|
|
4814
4815
|
},
|
|
4815
|
-
decoratorState:
|
|
4816
|
+
decoratorState: editorEngineInstance.decoratorState
|
|
4816
4817
|
};
|
|
4817
4818
|
}
|
|
4818
4819
|
const emptySet$1 = /* @__PURE__ */ new Set(), emptyState = {
|
|
@@ -4891,12 +4892,12 @@ const defaultStore = {
|
|
|
4891
4892
|
function SelectionStateProvider(t0) {
|
|
4892
4893
|
const $ = c(10), {
|
|
4893
4894
|
children
|
|
4894
|
-
} = t0, editorActor = useContext(EditorActorContext),
|
|
4895
|
+
} = t0, editorActor = useContext(EditorActorContext), editorEngine = useEngineStatic();
|
|
4895
4896
|
let t1;
|
|
4896
|
-
$[0] !== editorActor || $[1] !==
|
|
4897
|
+
$[0] !== editorActor || $[1] !== editorEngine ? (t1 = () => {
|
|
4897
4898
|
const actorSnapshot = editorActor.getSnapshot(), snapshot = getEditorSnapshot({
|
|
4898
4899
|
editorActorSnapshot: actorSnapshot,
|
|
4899
|
-
|
|
4900
|
+
editorEngineInstance: editorEngine
|
|
4900
4901
|
}), selection = snapshot.context.selection ? {
|
|
4901
4902
|
anchorPath: snapshot.context.selection.anchor.path,
|
|
4902
4903
|
focusPath: snapshot.context.selection.focus.path,
|
|
@@ -4906,12 +4907,12 @@ function SelectionStateProvider(t0) {
|
|
|
4906
4907
|
return getSelectionState({
|
|
4907
4908
|
context: {
|
|
4908
4909
|
schema: snapshot.context.schema,
|
|
4909
|
-
containers:
|
|
4910
|
+
containers: editorEngine.publicContainers,
|
|
4910
4911
|
value: snapshot.context.value
|
|
4911
4912
|
},
|
|
4912
|
-
blockIndexMap:
|
|
4913
|
+
blockIndexMap: editorEngine.blockIndexMap
|
|
4913
4914
|
}, selection);
|
|
4914
|
-
}, $[0] = editorActor, $[1] =
|
|
4915
|
+
}, $[0] = editorActor, $[1] = editorEngine, $[2] = t1) : t1 = $[2];
|
|
4915
4916
|
const computeCurrent = t1, [seed] = useState(computeCurrent), stateRef = useRef(seed), [initialSubscribers] = useState(_temp$2), subscribersRef = useRef(initialSubscribers);
|
|
4916
4917
|
let t2, t3;
|
|
4917
4918
|
$[3] !== computeCurrent || $[4] !== editorActor ? (t2 = () => {
|
|
@@ -5095,7 +5096,7 @@ function RenderContainer(props) {
|
|
|
5095
5096
|
return t2;
|
|
5096
5097
|
}
|
|
5097
5098
|
function useBlockSubSchema(path2) {
|
|
5098
|
-
const $ = c(3), editor =
|
|
5099
|
+
const $ = c(3), editor = useEngineStatic();
|
|
5099
5100
|
let t0;
|
|
5100
5101
|
return $[0] !== editor || $[1] !== path2 ? (t0 = getPathSubSchema(editor, path2), $[0] = editor, $[1] = path2, $[2] = t0) : t0 = $[2], t0;
|
|
5101
5102
|
}
|
|
@@ -5206,7 +5207,7 @@ function RenderTextBlock(props) {
|
|
|
5206
5207
|
const serializedPath = t2, selected = useIsSelectedContainer(serializedPath), focused = useIsFocusedContainer(serializedPath);
|
|
5207
5208
|
let t3;
|
|
5208
5209
|
$[7] !== props.textBlock._key ? (t3 = (editor) => editor.listIndexMap.get(props.textBlock._key), $[7] = props.textBlock._key, $[8] = t3) : t3 = $[8];
|
|
5209
|
-
const listIndex =
|
|
5210
|
+
const listIndex = useEngineSelector(t3), subSchema = useBlockSubSchema(props.path);
|
|
5210
5211
|
let children = props.children;
|
|
5211
5212
|
if (props.legacy.renderStyle && props.textBlock.style) {
|
|
5212
5213
|
let t42;
|
|
@@ -5367,7 +5368,7 @@ function tupleRefEqual(previous, next) {
|
|
|
5367
5368
|
return !0;
|
|
5368
5369
|
}
|
|
5369
5370
|
function RenderElement(props) {
|
|
5370
|
-
const $ = c(84), editorActor = useContext(EditorActorContext), parentContainer = useContext(ParentContainerContext), parentTextBlock = useContext(ParentTextBlockContext), isInNewPipeline = useContext(NewPipelineContext),
|
|
5371
|
+
const $ = c(84), editorActor = useContext(EditorActorContext), parentContainer = useContext(ParentContainerContext), parentTextBlock = useContext(ParentTextBlockContext), isInNewPipeline = useContext(NewPipelineContext), engineStatic = useEngineStatic(), schema = props.schema, type = props.element._type;
|
|
5371
5372
|
let t0;
|
|
5372
5373
|
$[0] !== parentContainer || $[1] !== type ? (t0 = findBlockPositionalOverride(parentContainer, type), $[0] = parentContainer, $[1] = type, $[2] = t0) : t0 = $[2];
|
|
5373
5374
|
const blockPositionalOverride = t0;
|
|
@@ -5490,7 +5491,7 @@ function RenderElement(props) {
|
|
|
5490
5491
|
}
|
|
5491
5492
|
return rendered;
|
|
5492
5493
|
}
|
|
5493
|
-
if (isInline(
|
|
5494
|
+
if (isInline(engineStatic, props.path)) {
|
|
5494
5495
|
if (isInNewPipeline && !inlineObjectConfig) {
|
|
5495
5496
|
let rest_0;
|
|
5496
5497
|
if ($[44] !== props.attributes) {
|
|
@@ -5960,19 +5961,19 @@ const PortableTextEditorContext = createContext(null), usePortableTextEditor = (
|
|
|
5960
5961
|
guards: {
|
|
5961
5962
|
"pending operations": ({
|
|
5962
5963
|
context
|
|
5963
|
-
}) => context.
|
|
5964
|
+
}) => context.editorEngine.operations.length > 0
|
|
5964
5965
|
}
|
|
5965
5966
|
}), validateSelectionAction = validateSelectionSetup.createAction(({
|
|
5966
5967
|
context,
|
|
5967
5968
|
event
|
|
5968
5969
|
}) => {
|
|
5969
|
-
validateSelection(context.
|
|
5970
|
+
validateSelection(context.editorEngine, event.editorElement);
|
|
5970
5971
|
}), validateSelectionMachine = validateSelectionSetup.createMachine({
|
|
5971
5972
|
id: "validate selection",
|
|
5972
5973
|
context: ({
|
|
5973
5974
|
input
|
|
5974
5975
|
}) => ({
|
|
5975
|
-
|
|
5976
|
+
editorEngine: input.editorEngine
|
|
5976
5977
|
}),
|
|
5977
5978
|
initial: "idle",
|
|
5978
5979
|
states: {
|
|
@@ -6007,25 +6008,25 @@ const PortableTextEditorContext = createContext(null), usePortableTextEditor = (
|
|
|
6007
6008
|
}
|
|
6008
6009
|
}
|
|
6009
6010
|
});
|
|
6010
|
-
function validateSelection(
|
|
6011
|
-
if (!
|
|
6011
|
+
function validateSelection(editorEngine, editorElement) {
|
|
6012
|
+
if (!editorEngine.selection)
|
|
6012
6013
|
return;
|
|
6013
6014
|
let root;
|
|
6014
6015
|
try {
|
|
6015
|
-
root = DOMEditor.findDocumentOrShadowRoot(
|
|
6016
|
+
root = DOMEditor.findDocumentOrShadowRoot(editorEngine);
|
|
6016
6017
|
} catch {
|
|
6017
6018
|
}
|
|
6018
6019
|
if (!root || editorElement !== root.activeElement)
|
|
6019
6020
|
return;
|
|
6020
|
-
const domSelection = DOMEditor.getWindow(
|
|
6021
|
+
const domSelection = DOMEditor.getWindow(editorEngine).getSelection();
|
|
6021
6022
|
if (!domSelection || domSelection.rangeCount === 0)
|
|
6022
6023
|
return;
|
|
6023
6024
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
6024
6025
|
try {
|
|
6025
|
-
const newDOMRange = DOMEditor.toDOMRange(
|
|
6026
|
+
const newDOMRange = DOMEditor.toDOMRange(editorEngine, editorEngine.selection);
|
|
6026
6027
|
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug.selection("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
6027
6028
|
} catch {
|
|
6028
|
-
debug.selection("Could not resolve selection, selecting top document"), applyDeselect(
|
|
6029
|
+
debug.selection("Could not resolve selection, selecting top document"), applyDeselect(editorEngine), editorEngine.children.length > 0 && applySelect(editorEngine, start(editorEngine, [])), editorEngine.onChange();
|
|
6029
6030
|
}
|
|
6030
6031
|
}
|
|
6031
6032
|
const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
@@ -6062,13 +6063,13 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6062
6063
|
const portableTextEditor = usePortableTextEditor(), [hasInvalidValue, setHasInvalidValue] = useState(!1), editorActor = useContext(EditorActorContext), relayActor = useContext(RelayActorContext);
|
|
6063
6064
|
let t0;
|
|
6064
6065
|
$[27] !== editorActor ? (t0 = editorActor.getSnapshot(), $[27] = editorActor, $[28] = t0) : t0 = $[28];
|
|
6065
|
-
const schema = t0.context.schema, readOnly = useSelector(editorActor, _temp),
|
|
6066
|
+
const schema = t0.context.schema, readOnly = useSelector(editorActor, _temp), editorEngine = useEngine();
|
|
6066
6067
|
let t1;
|
|
6067
|
-
$[29] !==
|
|
6068
|
+
$[29] !== editorEngine ? (t1 = {
|
|
6068
6069
|
input: {
|
|
6069
|
-
|
|
6070
|
+
editorEngine
|
|
6070
6071
|
}
|
|
6071
|
-
}, $[29] =
|
|
6072
|
+
}, $[29] = editorEngine, $[30] = t1) : t1 = $[30];
|
|
6072
6073
|
const validateSelectionActor = useActorRef(validateSelectionMachine, t1);
|
|
6073
6074
|
let t2;
|
|
6074
6075
|
$[31] !== rangeDecorations ? (t2 = rangeDecorations ?? [], $[31] = rangeDecorations, $[32] = t2) : t2 = $[32];
|
|
@@ -6078,15 +6079,15 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6078
6079
|
}), $[33] = editorActor, $[34] = t3) : t3 = $[34];
|
|
6079
6080
|
const t4 = !t3;
|
|
6080
6081
|
let t5;
|
|
6081
|
-
$[35] !==
|
|
6082
|
+
$[35] !== editorEngine || $[36] !== readOnly || $[37] !== schema || $[38] !== t2 || $[39] !== t4 ? (t5 = {
|
|
6082
6083
|
input: {
|
|
6083
6084
|
rangeDecorations: t2,
|
|
6084
6085
|
readOnly,
|
|
6085
6086
|
schema,
|
|
6086
|
-
|
|
6087
|
+
editorEngine,
|
|
6087
6088
|
skipSetup: t4
|
|
6088
6089
|
}
|
|
6089
|
-
}, $[35] =
|
|
6090
|
+
}, $[35] = editorEngine, $[36] = readOnly, $[37] = schema, $[38] = t2, $[39] = t4, $[40] = t5) : t5 = $[40];
|
|
6090
6091
|
const rangeDecorationsActor = useActorRef(rangeDecorationsMachine, t5), decorate = useSelector(rangeDecorationsActor, _temp2), dropPosition = useDropPosition();
|
|
6091
6092
|
let t6, t7;
|
|
6092
6093
|
$[41] !== rangeDecorationsActor || $[42] !== readOnly ? (t6 = () => {
|
|
@@ -6117,16 +6118,16 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6117
6118
|
$[59] !== readOnly || $[60] !== renderAnnotation || $[61] !== renderChild || $[62] !== renderDecorator || $[63] !== renderPlaceholder || $[64] !== schema ? (t12 = (leafProps) => /* @__PURE__ */ jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schema }), $[59] = readOnly, $[60] = renderAnnotation, $[61] = renderChild, $[62] = renderDecorator, $[63] = renderPlaceholder, $[64] = schema, $[65] = t12) : t12 = $[65];
|
|
6118
6119
|
const renderLeaf = t12, renderText = _temp3;
|
|
6119
6120
|
let t13;
|
|
6120
|
-
$[66] !== editorActor || $[67] !==
|
|
6121
|
+
$[66] !== editorActor || $[67] !== editorEngine || $[68] !== propsSelection ? (t13 = () => {
|
|
6121
6122
|
if (propsSelection) {
|
|
6122
6123
|
debug.selection.enabled && debug.selection(`Selection from props ${safeStringify(propsSelection)}`);
|
|
6123
|
-
const resolvedSelection = resolveSelection(
|
|
6124
|
-
resolvedSelection && (debug.selection.enabled && debug.selection(`Resolved selection from props ${safeStringify(resolvedSelection)}`),
|
|
6124
|
+
const resolvedSelection = resolveSelection(editorEngine, propsSelection);
|
|
6125
|
+
resolvedSelection && (debug.selection.enabled && debug.selection(`Resolved selection from props ${safeStringify(resolvedSelection)}`), editorEngine.select(resolvedSelection), editorEngine.operations.some(_temp4) || editorActor.send({
|
|
6125
6126
|
type: "update selection",
|
|
6126
6127
|
selection: resolvedSelection
|
|
6127
|
-
}),
|
|
6128
|
+
}), editorEngine.onChange());
|
|
6128
6129
|
}
|
|
6129
|
-
}, $[66] = editorActor, $[67] =
|
|
6130
|
+
}, $[66] = editorActor, $[67] = editorEngine, $[68] = propsSelection, $[69] = t13) : t13 = $[69];
|
|
6130
6131
|
const restoreSelectionFromProps = t13;
|
|
6131
6132
|
let t14, t15;
|
|
6132
6133
|
$[70] !== editorActor || $[71] !== rangeDecorationsActor || $[72] !== restoreSelectionFromProps ? (t14 = () => {
|
|
@@ -6148,13 +6149,13 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6148
6149
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
6149
6150
|
}, t17 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[75] = hasInvalidValue, $[76] = propsSelection, $[77] = restoreSelectionFromProps, $[78] = t16, $[79] = t17) : (t16 = $[78], t17 = $[79]), useEffect(t16, t17);
|
|
6150
6151
|
let t18;
|
|
6151
|
-
$[80] !== editorActor || $[81] !==
|
|
6152
|
-
if (DOMEditor.hasSelectableTarget(
|
|
6152
|
+
$[80] !== editorActor || $[81] !== editorEngine || $[82] !== onCopy ? (t18 = (event) => {
|
|
6153
|
+
if (DOMEditor.hasSelectableTarget(editorEngine, event.target)) {
|
|
6153
6154
|
if (onCopy)
|
|
6154
6155
|
onCopy(event) !== void 0 && event.preventDefault();
|
|
6155
6156
|
else if (event.nativeEvent.clipboardData) {
|
|
6156
6157
|
event.stopPropagation(), event.preventDefault();
|
|
6157
|
-
const selection =
|
|
6158
|
+
const selection = editorEngine.selection ?? void 0, position = selection ? {
|
|
6158
6159
|
selection
|
|
6159
6160
|
} : void 0;
|
|
6160
6161
|
if (!position) {
|
|
@@ -6170,16 +6171,16 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6170
6171
|
},
|
|
6171
6172
|
position
|
|
6172
6173
|
},
|
|
6173
|
-
editor:
|
|
6174
|
+
editor: editorEngine,
|
|
6174
6175
|
nativeEvent: event
|
|
6175
6176
|
});
|
|
6176
6177
|
}
|
|
6177
6178
|
}
|
|
6178
|
-
}, $[80] = editorActor, $[81] =
|
|
6179
|
+
}, $[80] = editorActor, $[81] = editorEngine, $[82] = onCopy, $[83] = t18) : t18 = $[83];
|
|
6179
6180
|
const handleCopy = t18;
|
|
6180
6181
|
let t19;
|
|
6181
|
-
$[84] !== editorActor || $[85] !==
|
|
6182
|
-
if (DOMEditor.hasSelectableTarget(
|
|
6182
|
+
$[84] !== editorActor || $[85] !== editorEngine || $[86] !== onCut ? (t19 = (event_0) => {
|
|
6183
|
+
if (DOMEditor.hasSelectableTarget(editorEngine, event_0.target)) {
|
|
6183
6184
|
if (onCut)
|
|
6184
6185
|
onCut(event_0) !== void 0 && event_0.preventDefault();
|
|
6185
6186
|
else if (event_0.nativeEvent.clipboardData) {
|
|
@@ -6200,22 +6201,22 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6200
6201
|
},
|
|
6201
6202
|
position: position_0
|
|
6202
6203
|
},
|
|
6203
|
-
editor:
|
|
6204
|
+
editor: editorEngine,
|
|
6204
6205
|
nativeEvent: event_0
|
|
6205
6206
|
});
|
|
6206
6207
|
}
|
|
6207
6208
|
}
|
|
6208
|
-
}, $[84] = editorActor, $[85] =
|
|
6209
|
+
}, $[84] = editorActor, $[85] = editorEngine, $[86] = onCut, $[87] = t19) : t19 = $[87];
|
|
6209
6210
|
const handleCut = t19;
|
|
6210
6211
|
let t20;
|
|
6211
|
-
$[88] !== editorActor || $[89] !==
|
|
6212
|
-
const value =
|
|
6212
|
+
$[88] !== editorActor || $[89] !== editorEngine || $[90] !== onPaste || $[91] !== portableTextEditor || $[92] !== relayActor ? (t20 = (event_1) => {
|
|
6213
|
+
const value = editorEngine.children, path2 = editorEngine.selection?.focus.path || [], onPasteResult = onPaste?.({
|
|
6213
6214
|
event: event_1,
|
|
6214
6215
|
value,
|
|
6215
6216
|
path: path2,
|
|
6216
6217
|
schemaTypes: portableTextEditor.schemaTypes
|
|
6217
6218
|
});
|
|
6218
|
-
if (onPasteResult || !
|
|
6219
|
+
if (onPasteResult || !editorEngine.selection)
|
|
6219
6220
|
event_1.preventDefault(), relayActor.send({
|
|
6220
6221
|
type: "loading"
|
|
6221
6222
|
}), Promise.resolve(onPasteResult).then((result_1) => {
|
|
@@ -6237,7 +6238,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6237
6238
|
},
|
|
6238
6239
|
position: position_1
|
|
6239
6240
|
},
|
|
6240
|
-
editor:
|
|
6241
|
+
editor: editorEngine,
|
|
6241
6242
|
nativeEvent: event_1
|
|
6242
6243
|
});
|
|
6243
6244
|
} else
|
|
@@ -6257,7 +6258,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6257
6258
|
}),
|
|
6258
6259
|
placement: "auto"
|
|
6259
6260
|
},
|
|
6260
|
-
editor:
|
|
6261
|
+
editor: editorEngine
|
|
6261
6262
|
}) : console.warn("Your onPaste function returned something unexpected:", result_1);
|
|
6262
6263
|
}).catch(_temp5).finally(() => {
|
|
6263
6264
|
relayActor.send({
|
|
@@ -6282,28 +6283,28 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6282
6283
|
},
|
|
6283
6284
|
position: position_2
|
|
6284
6285
|
},
|
|
6285
|
-
editor:
|
|
6286
|
+
editor: editorEngine,
|
|
6286
6287
|
nativeEvent: event_1
|
|
6287
6288
|
});
|
|
6288
6289
|
}
|
|
6289
6290
|
debug.behaviors("No result from custom paste handler, pasting normally");
|
|
6290
|
-
}, $[88] = editorActor, $[89] =
|
|
6291
|
+
}, $[88] = editorActor, $[89] = editorEngine, $[90] = onPaste, $[91] = portableTextEditor, $[92] = relayActor, $[93] = t20) : t20 = $[93];
|
|
6291
6292
|
const handlePaste = t20;
|
|
6292
6293
|
let t21;
|
|
6293
|
-
$[94] !== editorActor || $[95] !==
|
|
6294
|
+
$[94] !== editorActor || $[95] !== editorEngine || $[96] !== onFocus || $[97] !== relayActor ? (t21 = (event_2) => {
|
|
6294
6295
|
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
6295
6296
|
type: "focused",
|
|
6296
6297
|
event: event_2
|
|
6297
|
-
}), !
|
|
6298
|
-
}, $[94] = editorActor, $[95] =
|
|
6298
|
+
}), !editorEngine.selection && editorEngine.children.length === 1 && isEmptyTextBlock(editorActor.getSnapshot().context, editorEngine.children.at(0)) && (editorEngine.select(start(editorEngine, [])), editorEngine.onChange()));
|
|
6299
|
+
}, $[94] = editorActor, $[95] = editorEngine, $[96] = onFocus, $[97] = relayActor, $[98] = t21) : t21 = $[98];
|
|
6299
6300
|
const handleOnFocus = t21;
|
|
6300
6301
|
let t22;
|
|
6301
|
-
$[99] !== editorActor || $[100] !==
|
|
6302
|
+
$[99] !== editorActor || $[100] !== editorEngine || $[101] !== onClick ? (t22 = (event_3) => {
|
|
6302
6303
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
6303
6304
|
return;
|
|
6304
6305
|
const position_3 = getEventPosition({
|
|
6305
6306
|
editorActor,
|
|
6306
|
-
|
|
6307
|
+
editorEngine,
|
|
6307
6308
|
event: event_3.nativeEvent
|
|
6308
6309
|
});
|
|
6309
6310
|
position_3 && editorActor.send({
|
|
@@ -6312,10 +6313,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6312
6313
|
type: "mouse.click",
|
|
6313
6314
|
position: position_3
|
|
6314
6315
|
},
|
|
6315
|
-
editor:
|
|
6316
|
+
editor: editorEngine,
|
|
6316
6317
|
nativeEvent: event_3
|
|
6317
6318
|
});
|
|
6318
|
-
}, $[99] = editorActor, $[100] =
|
|
6319
|
+
}, $[99] = editorActor, $[100] = editorEngine, $[101] = onClick, $[102] = t22) : t22 = $[102];
|
|
6319
6320
|
const handleClick = t22;
|
|
6320
6321
|
let t23;
|
|
6321
6322
|
$[103] !== onBlur || $[104] !== relayActor ? (t23 = (event_4) => {
|
|
@@ -6331,10 +6332,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6331
6332
|
}, $[106] = onBeforeInput, $[107] = t24) : t24 = $[107];
|
|
6332
6333
|
const handleOnBeforeInput = t24;
|
|
6333
6334
|
let t25;
|
|
6334
|
-
$[108] !== editorActor || $[109] !==
|
|
6335
|
+
$[108] !== editorActor || $[109] !== editorEngine || $[110] !== hotkeys || $[111] !== portableTextEditor || $[112] !== props ? (t25 = (event_6) => {
|
|
6335
6336
|
props.onKeyDown && props.onKeyDown(event_6), event_6.isDefaultPrevented() || performHotkey({
|
|
6336
6337
|
editorActor,
|
|
6337
|
-
editor:
|
|
6338
|
+
editor: editorEngine,
|
|
6338
6339
|
portableTextEditor,
|
|
6339
6340
|
hotkeys: hotkeys ?? {},
|
|
6340
6341
|
event: event_6
|
|
@@ -6351,13 +6352,13 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6351
6352
|
shiftKey: event_6.shiftKey
|
|
6352
6353
|
}
|
|
6353
6354
|
},
|
|
6354
|
-
editor:
|
|
6355
|
+
editor: editorEngine,
|
|
6355
6356
|
nativeEvent: event_6
|
|
6356
6357
|
});
|
|
6357
|
-
}, $[108] = editorActor, $[109] =
|
|
6358
|
+
}, $[108] = editorActor, $[109] = editorEngine, $[110] = hotkeys, $[111] = portableTextEditor, $[112] = props, $[113] = t25) : t25 = $[113];
|
|
6358
6359
|
const handleKeyDown = t25;
|
|
6359
6360
|
let t26;
|
|
6360
|
-
$[114] !== editorActor || $[115] !==
|
|
6361
|
+
$[114] !== editorActor || $[115] !== editorEngine || $[116] !== props ? (t26 = (event_7) => {
|
|
6361
6362
|
props.onKeyUp && props.onKeyUp(event_7), event_7.isDefaultPrevented() || editorActor.send({
|
|
6362
6363
|
type: "behavior event",
|
|
6363
6364
|
behaviorEvent: {
|
|
@@ -6371,10 +6372,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6371
6372
|
shiftKey: event_7.shiftKey
|
|
6372
6373
|
}
|
|
6373
6374
|
},
|
|
6374
|
-
editor:
|
|
6375
|
+
editor: editorEngine,
|
|
6375
6376
|
nativeEvent: event_7
|
|
6376
6377
|
});
|
|
6377
|
-
}, $[114] = editorActor, $[115] =
|
|
6378
|
+
}, $[114] = editorActor, $[115] = editorEngine, $[116] = props, $[117] = t26) : t26 = $[117];
|
|
6378
6379
|
const handleKeyUp = t26;
|
|
6379
6380
|
let t27;
|
|
6380
6381
|
bb0: {
|
|
@@ -6391,10 +6392,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6391
6392
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
6392
6393
|
}, $[118] = portableTextEditor, $[119] = scrollSelectionIntoView, $[120] = t282) : t282 = $[120], t27 = t282;
|
|
6393
6394
|
}
|
|
6394
|
-
const
|
|
6395
|
+
const scrollSelectionIntoViewToEngine = t27;
|
|
6395
6396
|
let t28, t29;
|
|
6396
|
-
$[121] !== editorActor || $[122] !==
|
|
6397
|
-
const window2 = DOMEditor.getWindow(
|
|
6397
|
+
$[121] !== editorActor || $[122] !== editorEngine ? (t28 = () => {
|
|
6398
|
+
const window2 = DOMEditor.getWindow(editorEngine), onDragEnd_0 = () => {
|
|
6398
6399
|
editorActor.send({
|
|
6399
6400
|
type: "dragend"
|
|
6400
6401
|
});
|
|
@@ -6406,14 +6407,14 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6406
6407
|
return window2.document.addEventListener("dragend", onDragEnd_0), window2.document.addEventListener("drop", onDrop_0), () => {
|
|
6407
6408
|
window2.document.removeEventListener("dragend", onDragEnd_0), window2.document.removeEventListener("drop", onDrop_0);
|
|
6408
6409
|
};
|
|
6409
|
-
}, t29 = [
|
|
6410
|
+
}, t29 = [editorEngine, editorActor], $[121] = editorActor, $[122] = editorEngine, $[123] = t28, $[124] = t29) : (t28 = $[123], t29 = $[124]), useEffect(t28, t29);
|
|
6410
6411
|
let t30;
|
|
6411
|
-
$[125] !== editorActor || $[126] !==
|
|
6412
|
-
if (readOnly || !DOMEditor.hasTarget(
|
|
6412
|
+
$[125] !== editorActor || $[126] !== editorEngine || $[127] !== onDragStart || $[128] !== readOnly ? (t30 = (event_8) => {
|
|
6413
|
+
if (readOnly || !DOMEditor.hasTarget(editorEngine, event_8.target) || (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped()))
|
|
6413
6414
|
return;
|
|
6414
6415
|
const position_4 = getEventPosition({
|
|
6415
6416
|
editorActor,
|
|
6416
|
-
|
|
6417
|
+
editorEngine,
|
|
6417
6418
|
event: event_8.nativeEvent
|
|
6418
6419
|
});
|
|
6419
6420
|
if (!position_4) {
|
|
@@ -6434,15 +6435,15 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6434
6435
|
},
|
|
6435
6436
|
position: position_4
|
|
6436
6437
|
},
|
|
6437
|
-
editor:
|
|
6438
|
+
editor: editorEngine
|
|
6438
6439
|
}), !0;
|
|
6439
|
-
}, $[125] = editorActor, $[126] =
|
|
6440
|
+
}, $[125] = editorActor, $[126] = editorEngine, $[127] = onDragStart, $[128] = readOnly, $[129] = t30) : t30 = $[129];
|
|
6440
6441
|
const handleDragStart = t30;
|
|
6441
6442
|
let t31;
|
|
6442
|
-
$[130] !== editorActor || $[131] !==
|
|
6443
|
+
$[130] !== editorActor || $[131] !== editorEngine || $[132] !== onDrag ? (t31 = (event_9) => {
|
|
6443
6444
|
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
|
|
6444
6445
|
editorActor,
|
|
6445
|
-
|
|
6446
|
+
editorEngine,
|
|
6446
6447
|
event: event_9.nativeEvent
|
|
6447
6448
|
})))
|
|
6448
6449
|
return editorActor.send({
|
|
@@ -6453,12 +6454,12 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6453
6454
|
dataTransfer: event_9.dataTransfer
|
|
6454
6455
|
}
|
|
6455
6456
|
},
|
|
6456
|
-
editor:
|
|
6457
|
+
editor: editorEngine
|
|
6457
6458
|
}), !0;
|
|
6458
|
-
}, $[130] = editorActor, $[131] =
|
|
6459
|
+
}, $[130] = editorActor, $[131] = editorEngine, $[132] = onDrag, $[133] = t31) : t31 = $[133];
|
|
6459
6460
|
const handleDrag = t31;
|
|
6460
6461
|
let t32;
|
|
6461
|
-
$[134] !== editorActor || $[135] !==
|
|
6462
|
+
$[134] !== editorActor || $[135] !== editorEngine || $[136] !== onDragEnd ? (t32 = (event_10) => {
|
|
6462
6463
|
if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
|
|
6463
6464
|
return editorActor.send({
|
|
6464
6465
|
type: "behavior event",
|
|
@@ -6468,17 +6469,17 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6468
6469
|
dataTransfer: event_10.dataTransfer
|
|
6469
6470
|
}
|
|
6470
6471
|
},
|
|
6471
|
-
editor:
|
|
6472
|
+
editor: editorEngine
|
|
6472
6473
|
}), !0;
|
|
6473
|
-
}, $[134] = editorActor, $[135] =
|
|
6474
|
+
}, $[134] = editorActor, $[135] = editorEngine, $[136] = onDragEnd, $[137] = t32) : t32 = $[137];
|
|
6474
6475
|
const handleDragEnd = t32;
|
|
6475
6476
|
let t33;
|
|
6476
|
-
$[138] !== editorActor || $[139] !==
|
|
6477
|
+
$[138] !== editorActor || $[139] !== editorEngine || $[140] !== onDragEnter ? (t33 = (event_11) => {
|
|
6477
6478
|
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
6478
6479
|
return;
|
|
6479
6480
|
const position_6 = getEventPosition({
|
|
6480
6481
|
editorActor,
|
|
6481
|
-
|
|
6482
|
+
editorEngine,
|
|
6482
6483
|
event: event_11.nativeEvent
|
|
6483
6484
|
});
|
|
6484
6485
|
if (position_6)
|
|
@@ -6491,17 +6492,17 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6491
6492
|
},
|
|
6492
6493
|
position: position_6
|
|
6493
6494
|
},
|
|
6494
|
-
editor:
|
|
6495
|
+
editor: editorEngine
|
|
6495
6496
|
}), !0;
|
|
6496
|
-
}, $[138] = editorActor, $[139] =
|
|
6497
|
+
}, $[138] = editorActor, $[139] = editorEngine, $[140] = onDragEnter, $[141] = t33) : t33 = $[141];
|
|
6497
6498
|
const handleDragEnter = t33;
|
|
6498
6499
|
let t34;
|
|
6499
|
-
$[142] !== editorActor || $[143] !==
|
|
6500
|
+
$[142] !== editorActor || $[143] !== editorEngine || $[144] !== onDragOver ? (t34 = (event_12) => {
|
|
6500
6501
|
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
6501
6502
|
return;
|
|
6502
6503
|
const position_7 = getEventPosition({
|
|
6503
6504
|
editorActor,
|
|
6504
|
-
|
|
6505
|
+
editorEngine,
|
|
6505
6506
|
event: event_12.nativeEvent
|
|
6506
6507
|
});
|
|
6507
6508
|
if (position_7)
|
|
@@ -6515,18 +6516,18 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6515
6516
|
dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
|
|
6516
6517
|
position: position_7
|
|
6517
6518
|
},
|
|
6518
|
-
editor:
|
|
6519
|
+
editor: editorEngine,
|
|
6519
6520
|
nativeEvent: event_12
|
|
6520
6521
|
}), !0;
|
|
6521
|
-
}, $[142] = editorActor, $[143] =
|
|
6522
|
+
}, $[142] = editorActor, $[143] = editorEngine, $[144] = onDragOver, $[145] = t34) : t34 = $[145];
|
|
6522
6523
|
const handleDragOver = t34;
|
|
6523
6524
|
let t35;
|
|
6524
|
-
$[146] !== editorActor || $[147] !==
|
|
6525
|
+
$[146] !== editorActor || $[147] !== editorEngine || $[148] !== onDrop ? (t35 = (event_13) => {
|
|
6525
6526
|
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
6526
6527
|
return;
|
|
6527
6528
|
const position_8 = getEventPosition({
|
|
6528
6529
|
editorActor,
|
|
6529
|
-
|
|
6530
|
+
editorEngine,
|
|
6530
6531
|
event: event_13.nativeEvent
|
|
6531
6532
|
});
|
|
6532
6533
|
if (!position_8) {
|
|
@@ -6543,16 +6544,16 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6543
6544
|
dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
|
|
6544
6545
|
position: position_8
|
|
6545
6546
|
},
|
|
6546
|
-
editor:
|
|
6547
|
+
editor: editorEngine,
|
|
6547
6548
|
nativeEvent: event_13
|
|
6548
6549
|
}), !0;
|
|
6549
|
-
}, $[146] = editorActor, $[147] =
|
|
6550
|
+
}, $[146] = editorActor, $[147] = editorEngine, $[148] = onDrop, $[149] = t35) : t35 = $[149];
|
|
6550
6551
|
const handleDrop = t35;
|
|
6551
6552
|
let t36;
|
|
6552
|
-
$[150] !== editorActor || $[151] !==
|
|
6553
|
+
$[150] !== editorActor || $[151] !== editorEngine || $[152] !== onDragLeave ? (t36 = (event_14) => {
|
|
6553
6554
|
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
|
|
6554
6555
|
editorActor,
|
|
6555
|
-
|
|
6556
|
+
editorEngine,
|
|
6556
6557
|
event: event_14.nativeEvent
|
|
6557
6558
|
})))
|
|
6558
6559
|
return editorActor.send({
|
|
@@ -6563,9 +6564,9 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6563
6564
|
dataTransfer: event_14.dataTransfer
|
|
6564
6565
|
}
|
|
6565
6566
|
},
|
|
6566
|
-
editor:
|
|
6567
|
+
editor: editorEngine
|
|
6567
6568
|
}), !0;
|
|
6568
|
-
}, $[150] = editorActor, $[151] =
|
|
6569
|
+
}, $[150] = editorActor, $[151] = editorEngine, $[152] = onDragLeave, $[153] = t36) : t36 = $[153];
|
|
6569
6570
|
const handleDragLeave = t36;
|
|
6570
6571
|
let t37;
|
|
6571
6572
|
$[154] !== forwardedRef || $[155] !== validateSelectionActor ? (t37 = (editorElement) => {
|
|
@@ -6591,7 +6592,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6591
6592
|
if (!portableTextEditor)
|
|
6592
6593
|
return null;
|
|
6593
6594
|
let t38;
|
|
6594
|
-
return $[157] !== callbackRef || $[158] !== decorate || $[159] !== editorActor || $[160] !== handleClick || $[161] !== handleCopy || $[162] !== handleCut || $[163] !== handleDrag || $[164] !== handleDragEnd || $[165] !== handleDragEnter || $[166] !== handleDragLeave || $[167] !== handleDragOver || $[168] !== handleDragStart || $[169] !== handleDrop || $[170] !== handleKeyDown || $[171] !== handleKeyUp || $[172] !== handleOnBeforeInput || $[173] !== handleOnBlur || $[174] !== handleOnFocus || $[175] !== handlePaste || $[176] !== hasInvalidValue || $[177] !== readOnly || $[178] !== renderElement || $[179] !== renderLeaf || $[180] !== restProps || $[181] !==
|
|
6595
|
+
return $[157] !== callbackRef || $[158] !== decorate || $[159] !== editorActor || $[160] !== handleClick || $[161] !== handleCopy || $[162] !== handleCut || $[163] !== handleDrag || $[164] !== handleDragEnd || $[165] !== handleDragEnter || $[166] !== handleDragLeave || $[167] !== handleDragOver || $[168] !== handleDragStart || $[169] !== handleDrop || $[170] !== handleKeyDown || $[171] !== handleKeyUp || $[172] !== handleOnBeforeInput || $[173] !== handleOnBlur || $[174] !== handleOnFocus || $[175] !== handlePaste || $[176] !== hasInvalidValue || $[177] !== readOnly || $[178] !== renderElement || $[179] !== renderLeaf || $[180] !== restProps || $[181] !== scrollSelectionIntoViewToEngine ? (t38 = hasInvalidValue ? null : /* @__PURE__ */ jsx(SelectionStateProvider, { children: /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, editorActor, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToEngine }) }), $[157] = callbackRef, $[158] = decorate, $[159] = editorActor, $[160] = handleClick, $[161] = handleCopy, $[162] = handleCut, $[163] = handleDrag, $[164] = handleDragEnd, $[165] = handleDragEnter, $[166] = handleDragLeave, $[167] = handleDragOver, $[168] = handleDragStart, $[169] = handleDrop, $[170] = handleKeyDown, $[171] = handleKeyUp, $[172] = handleOnBeforeInput, $[173] = handleOnBlur, $[174] = handleOnFocus, $[175] = handlePaste, $[176] = hasInvalidValue, $[177] = readOnly, $[178] = renderElement, $[179] = renderLeaf, $[180] = restProps, $[181] = scrollSelectionIntoViewToEngine, $[182] = t38) : t38 = $[182], t38;
|
|
6595
6596
|
});
|
|
6596
6597
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
6597
6598
|
function noop() {
|
|
@@ -6613,7 +6614,21 @@ function _temp4(o) {
|
|
|
6613
6614
|
function _temp5(error) {
|
|
6614
6615
|
return console.warn(error), error;
|
|
6615
6616
|
}
|
|
6616
|
-
const
|
|
6617
|
+
const Engine = (props) => {
|
|
6618
|
+
const {
|
|
6619
|
+
editor,
|
|
6620
|
+
children
|
|
6621
|
+
} = props, {
|
|
6622
|
+
selectorContext,
|
|
6623
|
+
onChange: handleSelectorChange
|
|
6624
|
+
} = useSelectorContext(), onContextChange = useCallback(() => {
|
|
6625
|
+
handleSelectorChange();
|
|
6626
|
+
}, [editor, handleSelectorChange]);
|
|
6627
|
+
return useEffect(() => (editor.onContextChange = onContextChange, () => {
|
|
6628
|
+
editor.onContextChange = () => {
|
|
6629
|
+
};
|
|
6630
|
+
}), [editor, onContextChange]), /* @__PURE__ */ jsx(EngineSelectorContext.Provider, { value: selectorContext, children: /* @__PURE__ */ jsx(EditorContext.Provider, { value: editor, children }) });
|
|
6631
|
+
}, forEachActor = (actorRef, callback) => {
|
|
6617
6632
|
callback(actorRef);
|
|
6618
6633
|
const children = actorRef.getSnapshot().children;
|
|
6619
6634
|
children && Object.values(children).forEach((child) => {
|
|
@@ -6630,21 +6645,6 @@ function stopActor(actorRef) {
|
|
|
6630
6645
|
ref._processingStatus = 0, ref._snapshot = snapshot;
|
|
6631
6646
|
});
|
|
6632
6647
|
}
|
|
6633
|
-
const Slate = (props) => {
|
|
6634
|
-
const {
|
|
6635
|
-
editor,
|
|
6636
|
-
children
|
|
6637
|
-
} = props, {
|
|
6638
|
-
selectorContext,
|
|
6639
|
-
onChange: handleSelectorChange
|
|
6640
|
-
} = useSelectorContext(), onContextChange = useCallback(() => {
|
|
6641
|
-
handleSelectorChange();
|
|
6642
|
-
}, [editor, handleSelectorChange]);
|
|
6643
|
-
return useEffect(() => (editor.onContextChange = onContextChange, () => {
|
|
6644
|
-
editor.onContextChange = () => {
|
|
6645
|
-
};
|
|
6646
|
-
}), [editor, onContextChange]), /* @__PURE__ */ jsx(SlateSelectorContext.Provider, { value: selectorContext, children: /* @__PURE__ */ jsx(EditorContext.Provider, { value: editor, children }) });
|
|
6647
|
-
};
|
|
6648
6648
|
const converterJson = {
|
|
6649
6649
|
mimeType: "application/json",
|
|
6650
6650
|
serialize: ({
|
|
@@ -7000,14 +7000,14 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7000
7000
|
isMarkActive: (mark) => {
|
|
7001
7001
|
const snapshot = getEditorSnapshot({
|
|
7002
7002
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7003
|
-
|
|
7003
|
+
editorEngineInstance: editor
|
|
7004
7004
|
});
|
|
7005
7005
|
return getActiveDecorators(snapshot).includes(mark);
|
|
7006
7006
|
},
|
|
7007
7007
|
marks: () => {
|
|
7008
7008
|
const snapshot = getEditorSnapshot({
|
|
7009
7009
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7010
|
-
|
|
7010
|
+
editorEngineInstance: editor
|
|
7011
7011
|
}), activeAnnotations = getActiveAnnotationsMarks(snapshot), activeDecorators = getActiveDecorators(snapshot);
|
|
7012
7012
|
return [...activeAnnotations, ...activeDecorators];
|
|
7013
7013
|
},
|
|
@@ -7149,14 +7149,14 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7149
7149
|
isAnnotationActive: (annotationType) => {
|
|
7150
7150
|
const snapshot = getEditorSnapshot({
|
|
7151
7151
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7152
|
-
|
|
7152
|
+
editorEngineInstance: editor
|
|
7153
7153
|
});
|
|
7154
7154
|
return isActiveAnnotation(annotationType)(snapshot);
|
|
7155
7155
|
},
|
|
7156
7156
|
addAnnotation: (type, value) => {
|
|
7157
7157
|
const snapshotBefore = getEditorSnapshot({
|
|
7158
7158
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7159
|
-
|
|
7159
|
+
editorEngineInstance: editor
|
|
7160
7160
|
}), selectedValueBefore = getSelectedValue(snapshotBefore), focusSpanBefore = getFocusSpan(snapshotBefore), markDefsBefore = selectedValueBefore.flatMap((block) => isTextBlock(snapshotBefore.context, block) ? block.markDefs ?? [] : []);
|
|
7161
7161
|
editorActor.send({
|
|
7162
7162
|
type: "behavior event",
|
|
@@ -7171,7 +7171,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7171
7171
|
});
|
|
7172
7172
|
const snapshotAfter = getEditorSnapshot({
|
|
7173
7173
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7174
|
-
|
|
7174
|
+
editorEngineInstance: editor
|
|
7175
7175
|
}), selectedValueAfter = getSelectedValue(snapshotAfter), focusBlockAfter = getFocusBlock(snapshotAfter), focusSpanAfter = getFocusSpan(snapshotAfter), focusSpanDecorators = focusSpanAfter ? getPathSubSchema(snapshotAfter, focusSpanAfter.path).decorators.map((decorator) => decorator.name) : snapshotAfter.context.schema.decorators.map((decorator) => decorator.name), newMarkDefKeysOnFocusSpan = focusSpanAfter?.node.marks?.filter((mark) => !focusSpanBefore?.node.marks?.includes(mark) && !focusSpanDecorators.includes(mark)), markDefs = selectedValueAfter.flatMap((block) => isTextBlock(snapshotAfter.context, block) ? block.markDefs?.map((markDef2) => ({
|
|
7176
7176
|
markDef: markDef2,
|
|
7177
7177
|
path: [{
|
|
@@ -7206,142 +7206,33 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7206
7206
|
annotation: {
|
|
7207
7207
|
name: type.name
|
|
7208
7208
|
}
|
|
7209
|
-
},
|
|
7210
|
-
editor
|
|
7211
|
-
});
|
|
7212
|
-
},
|
|
7213
|
-
getSelection: () => editor.selection,
|
|
7214
|
-
getValue: () => editor.children,
|
|
7215
|
-
isCollapsedSelection: () => !!editor.selection && isCollapsedRange(editor.selection),
|
|
7216
|
-
isExpandedSelection: () => !!editor.selection && isExpandedRange(editor.selection),
|
|
7217
|
-
insertBreak: () => {
|
|
7218
|
-
editorActor.send({
|
|
7219
|
-
type: "behavior event",
|
|
7220
|
-
behaviorEvent: {
|
|
7221
|
-
type: "insert.break"
|
|
7222
|
-
},
|
|
7223
|
-
editor
|
|
7224
|
-
});
|
|
7225
|
-
},
|
|
7226
|
-
getFragment: () => {
|
|
7227
|
-
const snapshot = getEditorSnapshot({
|
|
7228
|
-
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7229
|
-
slateEditorInstance: editor
|
|
7230
|
-
});
|
|
7231
|
-
return getFragment(snapshot).map((entry) => entry.node);
|
|
7232
|
-
},
|
|
7233
|
-
isSelectionsOverlapping: (selectionA, selectionB) => !selectionA || !selectionB ? !1 : rangeIncludes(selectionA, selectionB, editor)
|
|
7234
|
-
};
|
|
7235
|
-
}
|
|
7236
|
-
const levelIndexMaps = /* @__PURE__ */ new Map();
|
|
7237
|
-
function buildIndexMaps(context, {
|
|
7238
|
-
blockIndexMap,
|
|
7239
|
-
listIndexMap
|
|
7240
|
-
}) {
|
|
7241
|
-
blockIndexMap.clear(), listIndexMap.clear(), levelIndexMaps.clear();
|
|
7242
|
-
let previousListItem;
|
|
7243
|
-
for (let blockIndex = 0; blockIndex < context.value.length; blockIndex++) {
|
|
7244
|
-
const block = context.value.at(blockIndex);
|
|
7245
|
-
if (block === void 0)
|
|
7246
|
-
continue;
|
|
7247
|
-
if (blockIndexMap.set(block._key, blockIndex), !isTextBlockNode(context, block)) {
|
|
7248
|
-
levelIndexMaps.clear(), previousListItem = void 0;
|
|
7249
|
-
continue;
|
|
7250
|
-
}
|
|
7251
|
-
if (block.listItem === void 0 || block.level === void 0) {
|
|
7252
|
-
levelIndexMaps.clear(), previousListItem = void 0;
|
|
7253
|
-
continue;
|
|
7254
|
-
}
|
|
7255
|
-
if (!previousListItem) {
|
|
7256
|
-
const levelIndexMap2 = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map();
|
|
7257
|
-
levelIndexMap2.set(block.level, 1), levelIndexMaps.set(block.listItem, levelIndexMap2), listIndexMap.set(block._key, 1), previousListItem = {
|
|
7258
|
-
listItem: block.listItem,
|
|
7259
|
-
level: block.level
|
|
7260
|
-
};
|
|
7261
|
-
continue;
|
|
7262
|
-
}
|
|
7263
|
-
if (previousListItem.listItem === block.listItem && previousListItem.level < block.level) {
|
|
7264
|
-
const levelIndexMap2 = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map();
|
|
7265
|
-
levelIndexMap2.set(block.level, 1), levelIndexMaps.set(block.listItem, levelIndexMap2), listIndexMap.set(block._key, 1), previousListItem = {
|
|
7266
|
-
listItem: block.listItem,
|
|
7267
|
-
level: block.level
|
|
7268
|
-
};
|
|
7269
|
-
continue;
|
|
7270
|
-
}
|
|
7271
|
-
levelIndexMaps.forEach((levelIndexMap2, listItem) => {
|
|
7272
|
-
if (listItem === block.listItem)
|
|
7273
|
-
return;
|
|
7274
|
-
const levelsToDelete = [];
|
|
7275
|
-
levelIndexMap2.forEach((_, level) => {
|
|
7276
|
-
level >= block.level && levelsToDelete.push(level);
|
|
7277
|
-
}), levelsToDelete.forEach((level) => {
|
|
7278
|
-
levelIndexMap2.delete(level);
|
|
7209
|
+
},
|
|
7210
|
+
editor
|
|
7279
7211
|
});
|
|
7280
|
-
}
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
|
|
7292
|
-
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
}
|
|
7301
|
-
|
|
7302
|
-
}
|
|
7303
|
-
function resolveDefaultStyle(snapshot, path2) {
|
|
7304
|
-
const rootFallback = snapshot.context.schema.styles[0]?.name ?? "normal";
|
|
7305
|
-
return path2 ? getPathSubSchema(snapshot, path2).styles[0]?.name ?? rootFallback : rootFallback;
|
|
7306
|
-
}
|
|
7307
|
-
function buildPublicContainers(resolved) {
|
|
7308
|
-
const projected = /* @__PURE__ */ new Map();
|
|
7309
|
-
for (const [type, config] of resolved)
|
|
7310
|
-
projected.set(type, toRegisteredContainer(config));
|
|
7311
|
-
return projected;
|
|
7312
|
-
}
|
|
7313
|
-
function toRegisteredContainer(config) {
|
|
7314
|
-
return {
|
|
7315
|
-
kind: "container",
|
|
7316
|
-
type: config.container.type,
|
|
7317
|
-
field: config.field,
|
|
7318
|
-
...config.of ? {
|
|
7319
|
-
of: config.of.map(toRegisteredOfEntry).filter(isDefined)
|
|
7320
|
-
} : {}
|
|
7212
|
+
},
|
|
7213
|
+
getSelection: () => editor.selection,
|
|
7214
|
+
getValue: () => editor.children,
|
|
7215
|
+
isCollapsedSelection: () => !!editor.selection && isCollapsedRange(editor.selection),
|
|
7216
|
+
isExpandedSelection: () => !!editor.selection && isExpandedRange(editor.selection),
|
|
7217
|
+
insertBreak: () => {
|
|
7218
|
+
editorActor.send({
|
|
7219
|
+
type: "behavior event",
|
|
7220
|
+
behaviorEvent: {
|
|
7221
|
+
type: "insert.break"
|
|
7222
|
+
},
|
|
7223
|
+
editor
|
|
7224
|
+
});
|
|
7225
|
+
},
|
|
7226
|
+
getFragment: () => {
|
|
7227
|
+
const snapshot = getEditorSnapshot({
|
|
7228
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7229
|
+
editorEngineInstance: editor
|
|
7230
|
+
});
|
|
7231
|
+
return getFragment(snapshot).map((entry) => entry.node);
|
|
7232
|
+
},
|
|
7233
|
+
isSelectionsOverlapping: (selectionA, selectionB) => !selectionA || !selectionB ? !1 : rangeIncludes(selectionA, selectionB, editor)
|
|
7321
7234
|
};
|
|
7322
7235
|
}
|
|
7323
|
-
function toRegisteredOfEntry(entry) {
|
|
7324
|
-
if ("container" in entry)
|
|
7325
|
-
return toRegisteredContainer(entry);
|
|
7326
|
-
if ("span" in entry)
|
|
7327
|
-
return {
|
|
7328
|
-
kind: "span",
|
|
7329
|
-
type: entry.span.type
|
|
7330
|
-
};
|
|
7331
|
-
if ("blockObject" in entry)
|
|
7332
|
-
return {
|
|
7333
|
-
kind: "blockObject",
|
|
7334
|
-
type: entry.blockObject.type
|
|
7335
|
-
};
|
|
7336
|
-
if ("inlineObject" in entry)
|
|
7337
|
-
return {
|
|
7338
|
-
kind: "inlineObject",
|
|
7339
|
-
type: entry.inlineObject.type
|
|
7340
|
-
};
|
|
7341
|
-
}
|
|
7342
|
-
function isDefined(value) {
|
|
7343
|
-
return value !== void 0;
|
|
7344
|
-
}
|
|
7345
7236
|
function createBehaviorApiPlugin(editorActor) {
|
|
7346
7237
|
return function(editor) {
|
|
7347
7238
|
const {
|
|
@@ -7522,6 +7413,75 @@ function createHistoryPlugin({
|
|
|
7522
7413
|
}, editor;
|
|
7523
7414
|
};
|
|
7524
7415
|
}
|
|
7416
|
+
function isNormalizing(editor) {
|
|
7417
|
+
return editor.normalizing;
|
|
7418
|
+
}
|
|
7419
|
+
function setNormalizing(editor, isNormalizing2) {
|
|
7420
|
+
editor.normalizing = isNormalizing2;
|
|
7421
|
+
}
|
|
7422
|
+
function withoutNormalizing(editor, fn) {
|
|
7423
|
+
const value = isNormalizing(editor);
|
|
7424
|
+
setNormalizing(editor, !1);
|
|
7425
|
+
try {
|
|
7426
|
+
fn();
|
|
7427
|
+
} finally {
|
|
7428
|
+
setNormalizing(editor, value);
|
|
7429
|
+
}
|
|
7430
|
+
normalize(editor);
|
|
7431
|
+
}
|
|
7432
|
+
function normalize(editor, options = {}) {
|
|
7433
|
+
const {
|
|
7434
|
+
force = !1,
|
|
7435
|
+
operation
|
|
7436
|
+
} = options, getDirtyPaths2 = (editor2) => editor2.dirtyPaths, getDirtyPathKeys = (editor2) => editor2.dirtyPathKeys, popDirtyPath = (editor2) => {
|
|
7437
|
+
const path2 = getDirtyPaths2(editor2).pop(), key = serializePath(path2);
|
|
7438
|
+
return getDirtyPathKeys(editor2).delete(key), path2;
|
|
7439
|
+
};
|
|
7440
|
+
if (isNormalizing(editor)) {
|
|
7441
|
+
if (force) {
|
|
7442
|
+
const allPaths = Array.from(getNodes(editor), (entry) => entry.path), allPathKeys = new Set(allPaths.map((p) => serializePath(p)));
|
|
7443
|
+
editor.dirtyPaths = allPaths, editor.dirtyPathKeys = allPathKeys;
|
|
7444
|
+
}
|
|
7445
|
+
getDirtyPaths2(editor).length !== 0 && withoutNormalizing(editor, () => {
|
|
7446
|
+
for (const dirtyPath of getDirtyPaths2(editor))
|
|
7447
|
+
if (dirtyPath.length !== 0 && hasNode(editor, dirtyPath)) {
|
|
7448
|
+
const entry = getNode(editor, dirtyPath);
|
|
7449
|
+
if (!entry)
|
|
7450
|
+
continue;
|
|
7451
|
+
const entryNode = entry.node;
|
|
7452
|
+
isTextBlock({
|
|
7453
|
+
schema: editor.schema
|
|
7454
|
+
}, entryNode) && entryNode.children.length === 0 && (editor.isNormalizingNode = !0, editor.normalizeNode([entry.node, entry.path], {
|
|
7455
|
+
operation
|
|
7456
|
+
}), editor.isNormalizingNode = !1);
|
|
7457
|
+
}
|
|
7458
|
+
let dirtyPaths = getDirtyPaths2(editor);
|
|
7459
|
+
const initialDirtyPathsLength = dirtyPaths.length;
|
|
7460
|
+
let iteration = 0;
|
|
7461
|
+
for (; dirtyPaths.length !== 0; ) {
|
|
7462
|
+
if (!editor.shouldNormalize({
|
|
7463
|
+
dirtyPaths,
|
|
7464
|
+
iteration,
|
|
7465
|
+
initialDirtyPathsLength,
|
|
7466
|
+
operation
|
|
7467
|
+
}))
|
|
7468
|
+
return;
|
|
7469
|
+
const dirtyPath = popDirtyPath(editor);
|
|
7470
|
+
if (dirtyPath.length === 0)
|
|
7471
|
+
editor.isNormalizingNode = !0, editor.normalizeNode([editor, dirtyPath], {
|
|
7472
|
+
operation
|
|
7473
|
+
}), editor.isNormalizingNode = !1;
|
|
7474
|
+
else if (hasNode(editor, dirtyPath)) {
|
|
7475
|
+
const entry = getNode(editor, dirtyPath);
|
|
7476
|
+
entry && (editor.isNormalizingNode = !0, editor.normalizeNode([entry.node, entry.path], {
|
|
7477
|
+
operation
|
|
7478
|
+
}), editor.isNormalizingNode = !1);
|
|
7479
|
+
}
|
|
7480
|
+
iteration++, dirtyPaths = getDirtyPaths2(editor);
|
|
7481
|
+
}
|
|
7482
|
+
});
|
|
7483
|
+
}
|
|
7484
|
+
}
|
|
7525
7485
|
function cloneDiff(diff2) {
|
|
7526
7486
|
const [type, patch] = diff2;
|
|
7527
7487
|
return [type, patch];
|
|
@@ -8179,7 +8139,7 @@ function getValue(root, path2) {
|
|
|
8179
8139
|
}
|
|
8180
8140
|
return current;
|
|
8181
8141
|
}
|
|
8182
|
-
function
|
|
8142
|
+
function toEngineBlock(block, {
|
|
8183
8143
|
schemaTypes
|
|
8184
8144
|
}) {
|
|
8185
8145
|
const {
|
|
@@ -8371,75 +8331,6 @@ function insertNodePatch(operation) {
|
|
|
8371
8331
|
const arrayFieldPath = operation.path.slice(0, -1);
|
|
8372
8332
|
return arrayFieldPath.length === 0 ? [insert([operation.node], operation.position, operation.path)] : [setIfMissing([], arrayFieldPath), insert([operation.node], operation.position, operation.path)];
|
|
8373
8333
|
}
|
|
8374
|
-
function isNormalizing(editor) {
|
|
8375
|
-
return editor.normalizing;
|
|
8376
|
-
}
|
|
8377
|
-
function setNormalizing(editor, isNormalizing2) {
|
|
8378
|
-
editor.normalizing = isNormalizing2;
|
|
8379
|
-
}
|
|
8380
|
-
function withoutNormalizing(editor, fn) {
|
|
8381
|
-
const value = isNormalizing(editor);
|
|
8382
|
-
setNormalizing(editor, !1);
|
|
8383
|
-
try {
|
|
8384
|
-
fn();
|
|
8385
|
-
} finally {
|
|
8386
|
-
setNormalizing(editor, value);
|
|
8387
|
-
}
|
|
8388
|
-
normalize(editor);
|
|
8389
|
-
}
|
|
8390
|
-
function normalize(editor, options = {}) {
|
|
8391
|
-
const {
|
|
8392
|
-
force = !1,
|
|
8393
|
-
operation
|
|
8394
|
-
} = options, getDirtyPaths2 = (editor2) => editor2.dirtyPaths, getDirtyPathKeys = (editor2) => editor2.dirtyPathKeys, popDirtyPath = (editor2) => {
|
|
8395
|
-
const path2 = getDirtyPaths2(editor2).pop(), key = serializePath(path2);
|
|
8396
|
-
return getDirtyPathKeys(editor2).delete(key), path2;
|
|
8397
|
-
};
|
|
8398
|
-
if (isNormalizing(editor)) {
|
|
8399
|
-
if (force) {
|
|
8400
|
-
const allPaths = Array.from(getNodes(editor), (entry) => entry.path), allPathKeys = new Set(allPaths.map((p) => serializePath(p)));
|
|
8401
|
-
editor.dirtyPaths = allPaths, editor.dirtyPathKeys = allPathKeys;
|
|
8402
|
-
}
|
|
8403
|
-
getDirtyPaths2(editor).length !== 0 && withoutNormalizing(editor, () => {
|
|
8404
|
-
for (const dirtyPath of getDirtyPaths2(editor))
|
|
8405
|
-
if (dirtyPath.length !== 0 && hasNode(editor, dirtyPath)) {
|
|
8406
|
-
const entry = getNode(editor, dirtyPath);
|
|
8407
|
-
if (!entry)
|
|
8408
|
-
continue;
|
|
8409
|
-
const entryNode = entry.node;
|
|
8410
|
-
isTextBlock({
|
|
8411
|
-
schema: editor.schema
|
|
8412
|
-
}, entryNode) && entryNode.children.length === 0 && (editor.isNormalizingNode = !0, editor.normalizeNode([entry.node, entry.path], {
|
|
8413
|
-
operation
|
|
8414
|
-
}), editor.isNormalizingNode = !1);
|
|
8415
|
-
}
|
|
8416
|
-
let dirtyPaths = getDirtyPaths2(editor);
|
|
8417
|
-
const initialDirtyPathsLength = dirtyPaths.length;
|
|
8418
|
-
let iteration = 0;
|
|
8419
|
-
for (; dirtyPaths.length !== 0; ) {
|
|
8420
|
-
if (!editor.shouldNormalize({
|
|
8421
|
-
dirtyPaths,
|
|
8422
|
-
iteration,
|
|
8423
|
-
initialDirtyPathsLength,
|
|
8424
|
-
operation
|
|
8425
|
-
}))
|
|
8426
|
-
return;
|
|
8427
|
-
const dirtyPath = popDirtyPath(editor);
|
|
8428
|
-
if (dirtyPath.length === 0)
|
|
8429
|
-
editor.isNormalizingNode = !0, editor.normalizeNode([editor, dirtyPath], {
|
|
8430
|
-
operation
|
|
8431
|
-
}), editor.isNormalizingNode = !1;
|
|
8432
|
-
else if (hasNode(editor, dirtyPath)) {
|
|
8433
|
-
const entry = getNode(editor, dirtyPath);
|
|
8434
|
-
entry && (editor.isNormalizingNode = !0, editor.normalizeNode([entry.node, entry.path], {
|
|
8435
|
-
operation
|
|
8436
|
-
}), editor.isNormalizingNode = !1);
|
|
8437
|
-
}
|
|
8438
|
-
iteration++, dirtyPaths = getDirtyPaths2(editor);
|
|
8439
|
-
}
|
|
8440
|
-
});
|
|
8441
|
-
}
|
|
8442
|
-
}
|
|
8443
8334
|
function withRemoteChanges(editor, fn) {
|
|
8444
8335
|
const prev = editor.isProcessingRemoteChanges;
|
|
8445
8336
|
editor.isProcessingRemoteChanges = !0, fn(), editor.isProcessingRemoteChanges = prev;
|
|
@@ -8552,21 +8443,73 @@ function updateSelectionPlugin({
|
|
|
8552
8443
|
type: "update selection",
|
|
8553
8444
|
selection: editor.selection
|
|
8554
8445
|
});
|
|
8555
|
-
}, {
|
|
8556
|
-
onChange
|
|
8557
|
-
} = editor;
|
|
8558
|
-
return editor.onChange = () => {
|
|
8559
|
-
onChange(), editorActor.getSnapshot().matches({
|
|
8560
|
-
setup: "setting up"
|
|
8561
|
-
}) || updateSelection();
|
|
8562
|
-
}, editor;
|
|
8446
|
+
}, {
|
|
8447
|
+
onChange
|
|
8448
|
+
} = editor;
|
|
8449
|
+
return editor.onChange = () => {
|
|
8450
|
+
onChange(), editorActor.getSnapshot().matches({
|
|
8451
|
+
setup: "setting up"
|
|
8452
|
+
}) || updateSelection();
|
|
8453
|
+
}, editor;
|
|
8454
|
+
}
|
|
8455
|
+
const levelIndexMaps = /* @__PURE__ */ new Map();
|
|
8456
|
+
function buildIndexMaps(context, {
|
|
8457
|
+
blockIndexMap,
|
|
8458
|
+
listIndexMap
|
|
8459
|
+
}) {
|
|
8460
|
+
blockIndexMap.clear(), listIndexMap.clear(), levelIndexMaps.clear();
|
|
8461
|
+
let previousListItem;
|
|
8462
|
+
for (let blockIndex = 0; blockIndex < context.value.length; blockIndex++) {
|
|
8463
|
+
const block = context.value.at(blockIndex);
|
|
8464
|
+
if (block === void 0)
|
|
8465
|
+
continue;
|
|
8466
|
+
if (blockIndexMap.set(block._key, blockIndex), !isTextBlockNode(context, block)) {
|
|
8467
|
+
levelIndexMaps.clear(), previousListItem = void 0;
|
|
8468
|
+
continue;
|
|
8469
|
+
}
|
|
8470
|
+
if (block.listItem === void 0 || block.level === void 0) {
|
|
8471
|
+
levelIndexMaps.clear(), previousListItem = void 0;
|
|
8472
|
+
continue;
|
|
8473
|
+
}
|
|
8474
|
+
if (!previousListItem) {
|
|
8475
|
+
const levelIndexMap2 = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map();
|
|
8476
|
+
levelIndexMap2.set(block.level, 1), levelIndexMaps.set(block.listItem, levelIndexMap2), listIndexMap.set(block._key, 1), previousListItem = {
|
|
8477
|
+
listItem: block.listItem,
|
|
8478
|
+
level: block.level
|
|
8479
|
+
};
|
|
8480
|
+
continue;
|
|
8481
|
+
}
|
|
8482
|
+
if (previousListItem.listItem === block.listItem && previousListItem.level < block.level) {
|
|
8483
|
+
const levelIndexMap2 = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map();
|
|
8484
|
+
levelIndexMap2.set(block.level, 1), levelIndexMaps.set(block.listItem, levelIndexMap2), listIndexMap.set(block._key, 1), previousListItem = {
|
|
8485
|
+
listItem: block.listItem,
|
|
8486
|
+
level: block.level
|
|
8487
|
+
};
|
|
8488
|
+
continue;
|
|
8489
|
+
}
|
|
8490
|
+
levelIndexMaps.forEach((levelIndexMap2, listItem) => {
|
|
8491
|
+
if (listItem === block.listItem)
|
|
8492
|
+
return;
|
|
8493
|
+
const levelsToDelete = [];
|
|
8494
|
+
levelIndexMap2.forEach((_, level) => {
|
|
8495
|
+
level >= block.level && levelsToDelete.push(level);
|
|
8496
|
+
}), levelsToDelete.forEach((level) => {
|
|
8497
|
+
levelIndexMap2.delete(level);
|
|
8498
|
+
});
|
|
8499
|
+
});
|
|
8500
|
+
const levelIndexMap = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map(), levelCounter = levelIndexMap.get(block.level) ?? 0;
|
|
8501
|
+
levelIndexMap.set(block.level, levelCounter + 1), levelIndexMaps.set(block.listItem, levelIndexMap), listIndexMap.set(block._key, levelCounter + 1), previousListItem = {
|
|
8502
|
+
listItem: block.listItem,
|
|
8503
|
+
level: block.level
|
|
8504
|
+
};
|
|
8505
|
+
}
|
|
8563
8506
|
}
|
|
8564
8507
|
function updateValuePlugin(context, editor) {
|
|
8565
8508
|
const {
|
|
8566
8509
|
apply: apply2
|
|
8567
8510
|
} = editor;
|
|
8568
8511
|
return editor.apply = (operation) => {
|
|
8569
|
-
if (editor.isNormalizingNode && debug.normalization.enabled && debug.normalization(`(
|
|
8512
|
+
if (editor.isNormalizingNode && debug.normalization.enabled && debug.normalization(`((engine operation))
|
|
8570
8513
|
${safeStringify(operation, 2)}`), operation.type === "set_selection") {
|
|
8571
8514
|
apply2(operation);
|
|
8572
8515
|
return;
|
|
@@ -9766,6 +9709,25 @@ function transformPointForMerge(point2, mergePath, prevKey, position) {
|
|
|
9766
9709
|
offset
|
|
9767
9710
|
};
|
|
9768
9711
|
}
|
|
9712
|
+
function createPlaceholderBlock(snapshot, path2) {
|
|
9713
|
+
const style = resolveDefaultStyle(snapshot, path2);
|
|
9714
|
+
return {
|
|
9715
|
+
_type: snapshot.context.schema.block.name,
|
|
9716
|
+
_key: snapshot.context.keyGenerator(),
|
|
9717
|
+
style,
|
|
9718
|
+
markDefs: [],
|
|
9719
|
+
children: [{
|
|
9720
|
+
_type: snapshot.context.schema.span.name,
|
|
9721
|
+
_key: snapshot.context.keyGenerator(),
|
|
9722
|
+
text: "",
|
|
9723
|
+
marks: []
|
|
9724
|
+
}]
|
|
9725
|
+
};
|
|
9726
|
+
}
|
|
9727
|
+
function resolveDefaultStyle(snapshot, path2) {
|
|
9728
|
+
const rootFallback = snapshot.context.schema.styles[0]?.name ?? "normal";
|
|
9729
|
+
return path2 ? getPathSubSchema(snapshot, path2).styles[0]?.name ?? rootFallback : rootFallback;
|
|
9730
|
+
}
|
|
9769
9731
|
function setNodeProperties(editor, props, path2) {
|
|
9770
9732
|
const nodeEntry = getNode(editor, path2);
|
|
9771
9733
|
if (!nodeEntry)
|
|
@@ -10427,8 +10389,46 @@ const shouldNormalize = (_editor, {
|
|
|
10427
10389
|
onContextChange && onContextChange(options), onChange(options);
|
|
10428
10390
|
}, e;
|
|
10429
10391
|
};
|
|
10430
|
-
function
|
|
10431
|
-
|
|
10392
|
+
function buildPublicContainers(resolved) {
|
|
10393
|
+
const projected = /* @__PURE__ */ new Map();
|
|
10394
|
+
for (const [type, config] of resolved)
|
|
10395
|
+
projected.set(type, toRegisteredContainer(config));
|
|
10396
|
+
return projected;
|
|
10397
|
+
}
|
|
10398
|
+
function toRegisteredContainer(config) {
|
|
10399
|
+
return {
|
|
10400
|
+
kind: "container",
|
|
10401
|
+
type: config.container.type,
|
|
10402
|
+
field: config.field,
|
|
10403
|
+
...config.of ? {
|
|
10404
|
+
of: config.of.map(toRegisteredOfEntry).filter(isDefined)
|
|
10405
|
+
} : {}
|
|
10406
|
+
};
|
|
10407
|
+
}
|
|
10408
|
+
function toRegisteredOfEntry(entry) {
|
|
10409
|
+
if ("container" in entry)
|
|
10410
|
+
return toRegisteredContainer(entry);
|
|
10411
|
+
if ("span" in entry)
|
|
10412
|
+
return {
|
|
10413
|
+
kind: "span",
|
|
10414
|
+
type: entry.span.type
|
|
10415
|
+
};
|
|
10416
|
+
if ("blockObject" in entry)
|
|
10417
|
+
return {
|
|
10418
|
+
kind: "blockObject",
|
|
10419
|
+
type: entry.blockObject.type
|
|
10420
|
+
};
|
|
10421
|
+
if ("inlineObject" in entry)
|
|
10422
|
+
return {
|
|
10423
|
+
kind: "inlineObject",
|
|
10424
|
+
type: entry.inlineObject.type
|
|
10425
|
+
};
|
|
10426
|
+
}
|
|
10427
|
+
function isDefined(value) {
|
|
10428
|
+
return value !== void 0;
|
|
10429
|
+
}
|
|
10430
|
+
function createEditorEngine(config) {
|
|
10431
|
+
debug.setup("creating new editor engine instance");
|
|
10432
10432
|
const context = config.editorActor.getSnapshot().context, placeholderBlock = createPlaceholderBlock({
|
|
10433
10433
|
context: {
|
|
10434
10434
|
schema: context.schema,
|
|
@@ -10442,27 +10442,27 @@ function createSlateEditor(config) {
|
|
|
10442
10442
|
undos: [],
|
|
10443
10443
|
redos: []
|
|
10444
10444
|
}, editor.listIndexMap = /* @__PURE__ */ new Map(), editor.remotePatches = [], editor.undoStepId = void 0, editor.children = [placeholderBlock], editor.isDeferringMutations = !1, editor.isNormalizingNode = !1, editor.isPatching = !0, editor.isPerformingBehaviorOperation = !1, editor.isProcessingRemoteChanges = !1, editor.isRedoing = !1, editor.isUndoing = !1, editor.withHistory = !0;
|
|
10445
|
-
const
|
|
10445
|
+
const editorEngine = plugins(withDOM(editor), {
|
|
10446
10446
|
editorActor: config.editorActor,
|
|
10447
10447
|
relayActor: config.relayActor,
|
|
10448
10448
|
subscriptions: config.subscriptions
|
|
10449
10449
|
});
|
|
10450
10450
|
return buildIndexMaps({
|
|
10451
10451
|
schema: context.schema,
|
|
10452
|
-
value:
|
|
10452
|
+
value: editorEngine.children
|
|
10453
10453
|
}, {
|
|
10454
|
-
blockIndexMap:
|
|
10455
|
-
listIndexMap:
|
|
10456
|
-
}),
|
|
10454
|
+
blockIndexMap: editorEngine.blockIndexMap,
|
|
10455
|
+
listIndexMap: editorEngine.listIndexMap
|
|
10456
|
+
}), editorEngine;
|
|
10457
10457
|
}
|
|
10458
|
-
function createEditorDom(sendBack,
|
|
10458
|
+
function createEditorDom(sendBack, editorEngine) {
|
|
10459
10459
|
return {
|
|
10460
|
-
getBlockNodes: (snapshot) => getBlockNodes(
|
|
10461
|
-
getChildNodes: (snapshot) => getChildNodes(
|
|
10462
|
-
getEditorElement: () => getEditorElement(
|
|
10460
|
+
getBlockNodes: (snapshot) => getBlockNodes(editorEngine, snapshot),
|
|
10461
|
+
getChildNodes: (snapshot) => getChildNodes(editorEngine, snapshot),
|
|
10462
|
+
getEditorElement: () => getEditorElement(editorEngine),
|
|
10463
10463
|
getSelectionRect: (snapshot) => getSelectionRect(snapshot),
|
|
10464
|
-
getStartBlockElement: (snapshot) => getStartBlockElement(
|
|
10465
|
-
getEndBlockElement: (snapshot) => getEndBlockElement(
|
|
10464
|
+
getStartBlockElement: (snapshot) => getStartBlockElement(editorEngine, snapshot),
|
|
10465
|
+
getEndBlockElement: (snapshot) => getEndBlockElement(editorEngine, snapshot),
|
|
10466
10466
|
setDragGhost: ({
|
|
10467
10467
|
event,
|
|
10468
10468
|
ghost
|
|
@@ -10473,25 +10473,25 @@ function createEditorDom(sendBack, slateEditor) {
|
|
|
10473
10473
|
})
|
|
10474
10474
|
};
|
|
10475
10475
|
}
|
|
10476
|
-
function getBlockNodes(
|
|
10476
|
+
function getBlockNodes(editorEngine, snapshot) {
|
|
10477
10477
|
if (!snapshot.context.selection)
|
|
10478
10478
|
return [];
|
|
10479
10479
|
try {
|
|
10480
10480
|
return getFragment(snapshot).flatMap((entry) => {
|
|
10481
|
-
const domNode = getDomNode(
|
|
10481
|
+
const domNode = getDomNode(editorEngine, entry.path);
|
|
10482
10482
|
return domNode ? [domNode] : [];
|
|
10483
10483
|
});
|
|
10484
10484
|
} catch {
|
|
10485
10485
|
return [];
|
|
10486
10486
|
}
|
|
10487
10487
|
}
|
|
10488
|
-
function getChildNodes(
|
|
10488
|
+
function getChildNodes(editorEngine, snapshot) {
|
|
10489
10489
|
if (!snapshot.context.selection)
|
|
10490
10490
|
return [];
|
|
10491
10491
|
try {
|
|
10492
|
-
const [start2, end2] = rangeEdges(snapshot.context.selection,
|
|
10492
|
+
const [start2, end2] = rangeEdges(snapshot.context.selection, editorEngine), childEntries = [];
|
|
10493
10493
|
let buffered;
|
|
10494
|
-
for (const entry of getNodes(
|
|
10494
|
+
for (const entry of getNodes(editorEngine, {
|
|
10495
10495
|
from: start2.path,
|
|
10496
10496
|
to: end2.path
|
|
10497
10497
|
})) {
|
|
@@ -10505,13 +10505,13 @@ function getChildNodes(slateEditor, snapshot) {
|
|
|
10505
10505
|
}
|
|
10506
10506
|
buffered = entry;
|
|
10507
10507
|
}
|
|
10508
|
-
return buffered && childEntries.push(buffered), childEntries.flatMap((childEntry) => getDomNode(
|
|
10508
|
+
return buffered && childEntries.push(buffered), childEntries.flatMap((childEntry) => getDomNode(editorEngine, childEntry.path) || []);
|
|
10509
10509
|
} catch {
|
|
10510
10510
|
return [];
|
|
10511
10511
|
}
|
|
10512
10512
|
}
|
|
10513
|
-
function getEditorElement(
|
|
10514
|
-
return getDomNode(
|
|
10513
|
+
function getEditorElement(editorEngine) {
|
|
10514
|
+
return getDomNode(editorEngine, []);
|
|
10515
10515
|
}
|
|
10516
10516
|
function getSelectionRect(snapshot) {
|
|
10517
10517
|
if (!snapshot.context.selection)
|
|
@@ -10523,18 +10523,18 @@ function getSelectionRect(snapshot) {
|
|
|
10523
10523
|
return null;
|
|
10524
10524
|
}
|
|
10525
10525
|
}
|
|
10526
|
-
function getStartBlockElement(
|
|
10526
|
+
function getStartBlockElement(editorEngine, snapshot) {
|
|
10527
10527
|
const startBlock = getSelectionStartBlock(snapshot);
|
|
10528
10528
|
if (!startBlock)
|
|
10529
10529
|
return null;
|
|
10530
|
-
const startBlockNode = getDomNode(
|
|
10530
|
+
const startBlockNode = getDomNode(editorEngine, startBlock.path);
|
|
10531
10531
|
return startBlockNode instanceof Element ? startBlockNode : null;
|
|
10532
10532
|
}
|
|
10533
|
-
function getEndBlockElement(
|
|
10533
|
+
function getEndBlockElement(editorEngine, snapshot) {
|
|
10534
10534
|
const endBlock = getSelectionEndBlock(snapshot);
|
|
10535
10535
|
if (!endBlock)
|
|
10536
10536
|
return null;
|
|
10537
|
-
const endBlockNode = getDomNode(
|
|
10537
|
+
const endBlockNode = getDomNode(editorEngine, endBlock.path);
|
|
10538
10538
|
return endBlockNode instanceof Element ? endBlockNode : null;
|
|
10539
10539
|
}
|
|
10540
10540
|
function setDragGhost({
|
|
@@ -12061,6 +12061,13 @@ function createEditorSnapshot({
|
|
|
12061
12061
|
decoratorState: editor.decoratorState
|
|
12062
12062
|
};
|
|
12063
12063
|
}
|
|
12064
|
+
function withPerformingBehaviorOperation(editor, fn) {
|
|
12065
|
+
const prev = editor.isPerformingBehaviorOperation;
|
|
12066
|
+
editor.isPerformingBehaviorOperation = !0, fn(), editor.isPerformingBehaviorOperation = prev;
|
|
12067
|
+
}
|
|
12068
|
+
function withoutNormalizingConditional(editor, predicate, fn) {
|
|
12069
|
+
predicate() ? withoutNormalizing(editor, fn) : fn();
|
|
12070
|
+
}
|
|
12064
12071
|
const addAnnotationOperationImplementation = ({
|
|
12065
12072
|
snapshot,
|
|
12066
12073
|
operation
|
|
@@ -12282,8 +12289,8 @@ const blockSetOperationImplementation = ({
|
|
|
12282
12289
|
} = snapshot, blockEntry = getNode(operation.editor, operation.at);
|
|
12283
12290
|
if (!blockEntry)
|
|
12284
12291
|
throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
|
|
12285
|
-
const
|
|
12286
|
-
if (isTextBlockNode(context,
|
|
12292
|
+
const engineBlock = blockEntry.node;
|
|
12293
|
+
if (isTextBlockNode(context, engineBlock)) {
|
|
12287
12294
|
const subSchema = getPathSubSchema(snapshot, blockEntry.path), filteredProps = {};
|
|
12288
12295
|
for (const key of Object.keys(operation.props))
|
|
12289
12296
|
if (key !== "_type") {
|
|
@@ -12321,7 +12328,7 @@ const blockSetOperationImplementation = ({
|
|
|
12321
12328
|
}
|
|
12322
12329
|
setNodeProperties(operation.editor, filteredProps, blockEntry.path);
|
|
12323
12330
|
} else {
|
|
12324
|
-
const schemaDefinition = getBlockObjectSchema(snapshot,
|
|
12331
|
+
const schemaDefinition = getBlockObjectSchema(snapshot, engineBlock, blockEntry.path), filteredProps = {};
|
|
12325
12332
|
for (const key of Object.keys(operation.props))
|
|
12326
12333
|
if (key !== "_type") {
|
|
12327
12334
|
if (key === "_key") {
|
|
@@ -12330,8 +12337,8 @@ const blockSetOperationImplementation = ({
|
|
|
12330
12337
|
}
|
|
12331
12338
|
schemaDefinition?.fields?.some((field) => field.name === key) && (filteredProps[key] = operation.props[key]);
|
|
12332
12339
|
}
|
|
12333
|
-
const patches = Object.entries(filteredProps).map(([key, value]) => set(value, [key])),
|
|
12334
|
-
setNodeProperties(operation.editor,
|
|
12340
|
+
const patches = Object.entries(filteredProps).map(([key, value]) => set(value, [key])), updatedEngineBlock = applyAll(engineBlock, patches);
|
|
12341
|
+
setNodeProperties(operation.editor, updatedEngineBlock, blockEntry.path);
|
|
12335
12342
|
}
|
|
12336
12343
|
}, blockUnsetOperationImplementation = ({
|
|
12337
12344
|
snapshot,
|
|
@@ -12342,8 +12349,8 @@ const blockSetOperationImplementation = ({
|
|
|
12342
12349
|
} = snapshot, blockEntry = getNode(operation.editor, operation.at);
|
|
12343
12350
|
if (!blockEntry)
|
|
12344
12351
|
throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
|
|
12345
|
-
const
|
|
12346
|
-
if (isTextBlockNode(context,
|
|
12352
|
+
const engineBlock = blockEntry.node;
|
|
12353
|
+
if (isTextBlockNode(context, engineBlock)) {
|
|
12347
12354
|
const propsToRemove = operation.props.filter((prop) => prop !== "_type" && prop !== "_key"), unsetProps2 = {};
|
|
12348
12355
|
for (const prop of propsToRemove)
|
|
12349
12356
|
unsetProps2[prop] = null;
|
|
@@ -12630,6 +12637,58 @@ const childSetOperationImplementation = ({
|
|
|
12630
12637
|
}
|
|
12631
12638
|
}
|
|
12632
12639
|
};
|
|
12640
|
+
function unhangRange(snapshot, range2) {
|
|
12641
|
+
const {
|
|
12642
|
+
context
|
|
12643
|
+
} = snapshot;
|
|
12644
|
+
let [start2, end2] = rangeEdges(range2, {
|
|
12645
|
+
children: context.value
|
|
12646
|
+
});
|
|
12647
|
+
if (start2.offset !== 0 || end2.offset !== 0 || isCollapsedRange(range2) || getSibling(snapshot, end2.path, "previous") !== void 0)
|
|
12648
|
+
return range2;
|
|
12649
|
+
const endBlock = getAncestorTextBlock(snapshot, end2.path), blockPath = endBlock ? endBlock.path : [];
|
|
12650
|
+
for (const {
|
|
12651
|
+
path: path2
|
|
12652
|
+
} of getNodes(snapshot, {
|
|
12653
|
+
from: start2.path,
|
|
12654
|
+
to: end2.path,
|
|
12655
|
+
match: (candidate, candidatePath) => isVoidNode(snapshot, candidate, candidatePath) || isEditableContainer(snapshot, candidate, candidatePath)
|
|
12656
|
+
}))
|
|
12657
|
+
if (!isAncestorPath(path2, start2.path) && !isAncestorPath(path2, end2.path))
|
|
12658
|
+
return range2;
|
|
12659
|
+
let skip = !0;
|
|
12660
|
+
for (const {
|
|
12661
|
+
node,
|
|
12662
|
+
path: nodePath
|
|
12663
|
+
} of getNodes(snapshot, {
|
|
12664
|
+
from: start2.path,
|
|
12665
|
+
to: end2.path,
|
|
12666
|
+
match: (n) => isSpan({
|
|
12667
|
+
schema: context.schema
|
|
12668
|
+
}, n),
|
|
12669
|
+
reverse: !0
|
|
12670
|
+
})) {
|
|
12671
|
+
if (skip) {
|
|
12672
|
+
skip = !1;
|
|
12673
|
+
continue;
|
|
12674
|
+
}
|
|
12675
|
+
if (isSpan({
|
|
12676
|
+
schema: context.schema
|
|
12677
|
+
}, node) && (node.text !== "" || isBeforePath(nodePath, blockPath, {
|
|
12678
|
+
children: context.value
|
|
12679
|
+
}))) {
|
|
12680
|
+
end2 = {
|
|
12681
|
+
path: nodePath,
|
|
12682
|
+
offset: node.text.length
|
|
12683
|
+
};
|
|
12684
|
+
break;
|
|
12685
|
+
}
|
|
12686
|
+
}
|
|
12687
|
+
return {
|
|
12688
|
+
anchor: start2,
|
|
12689
|
+
focus: end2
|
|
12690
|
+
};
|
|
12691
|
+
}
|
|
12633
12692
|
function getHighestObjectNode(snapshot, path2) {
|
|
12634
12693
|
const ancestors = getAncestors(snapshot, path2);
|
|
12635
12694
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
@@ -13125,58 +13184,6 @@ function isEmptyContainer(snapshot, path2) {
|
|
|
13125
13184
|
const children = getChildren(snapshot, path2);
|
|
13126
13185
|
return children.length === 1 && isEmptyTextBlock(snapshot.context, children[0].node);
|
|
13127
13186
|
}
|
|
13128
|
-
function unhangRange(snapshot, range2) {
|
|
13129
|
-
const {
|
|
13130
|
-
context
|
|
13131
|
-
} = snapshot;
|
|
13132
|
-
let [start2, end2] = rangeEdges(range2, {
|
|
13133
|
-
children: context.value
|
|
13134
|
-
});
|
|
13135
|
-
if (start2.offset !== 0 || end2.offset !== 0 || isCollapsedRange(range2) || getSibling(snapshot, end2.path, "previous") !== void 0)
|
|
13136
|
-
return range2;
|
|
13137
|
-
const endBlock = getAncestorTextBlock(snapshot, end2.path), blockPath = endBlock ? endBlock.path : [];
|
|
13138
|
-
for (const {
|
|
13139
|
-
path: path2
|
|
13140
|
-
} of getNodes(snapshot, {
|
|
13141
|
-
from: start2.path,
|
|
13142
|
-
to: end2.path,
|
|
13143
|
-
match: (candidate, candidatePath) => isVoidNode(snapshot, candidate, candidatePath) || isEditableContainer(snapshot, candidate, candidatePath)
|
|
13144
|
-
}))
|
|
13145
|
-
if (!isAncestorPath(path2, start2.path) && !isAncestorPath(path2, end2.path))
|
|
13146
|
-
return range2;
|
|
13147
|
-
let skip = !0;
|
|
13148
|
-
for (const {
|
|
13149
|
-
node,
|
|
13150
|
-
path: nodePath
|
|
13151
|
-
} of getNodes(snapshot, {
|
|
13152
|
-
from: start2.path,
|
|
13153
|
-
to: end2.path,
|
|
13154
|
-
match: (n) => isSpan({
|
|
13155
|
-
schema: context.schema
|
|
13156
|
-
}, n),
|
|
13157
|
-
reverse: !0
|
|
13158
|
-
})) {
|
|
13159
|
-
if (skip) {
|
|
13160
|
-
skip = !1;
|
|
13161
|
-
continue;
|
|
13162
|
-
}
|
|
13163
|
-
if (isSpan({
|
|
13164
|
-
schema: context.schema
|
|
13165
|
-
}, node) && (node.text !== "" || isBeforePath(nodePath, blockPath, {
|
|
13166
|
-
children: context.value
|
|
13167
|
-
}))) {
|
|
13168
|
-
end2 = {
|
|
13169
|
-
path: nodePath,
|
|
13170
|
-
offset: node.text.length
|
|
13171
|
-
};
|
|
13172
|
-
break;
|
|
13173
|
-
}
|
|
13174
|
-
}
|
|
13175
|
-
return {
|
|
13176
|
-
anchor: start2,
|
|
13177
|
-
focus: end2
|
|
13178
|
-
};
|
|
13179
|
-
}
|
|
13180
13187
|
const deleteOperationImplementation = ({
|
|
13181
13188
|
operation
|
|
13182
13189
|
}) => {
|
|
@@ -13239,6 +13246,10 @@ const deleteOperationImplementation = ({
|
|
|
13239
13246
|
removeEmptyStartBlock: !0
|
|
13240
13247
|
});
|
|
13241
13248
|
};
|
|
13249
|
+
function pluginRedoing(editor, fn) {
|
|
13250
|
+
const prev = editor.isRedoing;
|
|
13251
|
+
editor.isRedoing = !0, fn(), editor.isRedoing = prev;
|
|
13252
|
+
}
|
|
13242
13253
|
function transformOperation(editor, patch, operation) {
|
|
13243
13254
|
const snapshot = editor, transformedOperation = {
|
|
13244
13255
|
...operation
|
|
@@ -13292,10 +13303,6 @@ function findOperationTargetBlock(snapshot, editor, operation) {
|
|
|
13292
13303
|
function pathStartsWith(path2, prefix) {
|
|
13293
13304
|
return pathEquals(path2, prefix) || isAncestorPath(prefix, path2);
|
|
13294
13305
|
}
|
|
13295
|
-
function pluginRedoing(editor, fn) {
|
|
13296
|
-
const prev = editor.isRedoing;
|
|
13297
|
-
editor.isRedoing = !0, fn(), editor.isRedoing = prev;
|
|
13298
|
-
}
|
|
13299
13306
|
const historyRedoOperationImplementation = ({
|
|
13300
13307
|
operation
|
|
13301
13308
|
}) => {
|
|
@@ -13478,7 +13485,7 @@ const historyUndoOperationImplementation = ({
|
|
|
13478
13485
|
});
|
|
13479
13486
|
if (!parsedBlock)
|
|
13480
13487
|
return;
|
|
13481
|
-
const block =
|
|
13488
|
+
const block = toEngineBlock(parsedBlock, {
|
|
13482
13489
|
schemaTypes: context.schema
|
|
13483
13490
|
}), target = resolveTarget({
|
|
13484
13491
|
editor,
|
|
@@ -14060,27 +14067,6 @@ const moveBackwardOperationImplementation = ({
|
|
|
14060
14067
|
distance: operation.distance,
|
|
14061
14068
|
reverse: !0
|
|
14062
14069
|
});
|
|
14063
|
-
}, moveBlockOperationImplementation = ({
|
|
14064
|
-
operation
|
|
14065
|
-
}) => {
|
|
14066
|
-
const editor = operation.editor, originEntry = getNode(editor, operation.at);
|
|
14067
|
-
if (!originEntry)
|
|
14068
|
-
throw new Error(`Failed to resolve origin block at ${safeStringify(operation.at)}`);
|
|
14069
|
-
const destinationEntry = getNode(editor, operation.to);
|
|
14070
|
-
if (!destinationEntry)
|
|
14071
|
-
throw new Error(`Failed to resolve destination block at ${safeStringify(operation.to)}`);
|
|
14072
|
-
const siblings = getChildren(editor, parentPath(originEntry.path)), originIndex = siblings.findIndex((sibling) => sibling.node._key === originEntry.node._key), destinationIndex = siblings.findIndex((sibling) => sibling.node._key === destinationEntry.node._key), movingDown = originIndex !== -1 && destinationIndex !== -1 && originIndex < destinationIndex, node = originEntry.node, savedSelection = editor.selection;
|
|
14073
|
-
withoutNormalizing(editor, () => {
|
|
14074
|
-
editor.apply({
|
|
14075
|
-
type: "unset",
|
|
14076
|
-
path: originEntry.path
|
|
14077
|
-
}), editor.apply({
|
|
14078
|
-
type: "insert",
|
|
14079
|
-
path: destinationEntry.path,
|
|
14080
|
-
node,
|
|
14081
|
-
position: movingDown ? "after" : "before"
|
|
14082
|
-
});
|
|
14083
|
-
}), savedSelection && (editor.selection = savedSelection);
|
|
14084
14070
|
}, moveForwardOperationImplementation = ({
|
|
14085
14071
|
operation
|
|
14086
14072
|
}) => {
|
|
@@ -14134,7 +14120,6 @@ const moveBackwardOperationImplementation = ({
|
|
|
14134
14120
|
"insert.child": insertChildOperationImplementation,
|
|
14135
14121
|
"insert.text": insertTextOperationImplementation,
|
|
14136
14122
|
"move.backward": moveBackwardOperationImplementation,
|
|
14137
|
-
"move.block": moveBlockOperationImplementation,
|
|
14138
14123
|
"move.forward": moveForwardOperationImplementation,
|
|
14139
14124
|
"remove.text": removeTextOperationImplementation,
|
|
14140
14125
|
select: selectOperationImplementation,
|
|
@@ -14158,13 +14143,6 @@ function performOperation({
|
|
|
14158
14143
|
};
|
|
14159
14144
|
isNormalizing(operation.editor) ? withoutNormalizing(operation.editor, perform) : perform();
|
|
14160
14145
|
}
|
|
14161
|
-
function withPerformingBehaviorOperation(editor, fn) {
|
|
14162
|
-
const prev = editor.isPerformingBehaviorOperation;
|
|
14163
|
-
editor.isPerformingBehaviorOperation = !0, fn(), editor.isPerformingBehaviorOperation = prev;
|
|
14164
|
-
}
|
|
14165
|
-
function withoutNormalizingConditional(editor, predicate, fn) {
|
|
14166
|
-
predicate() ? withoutNormalizing(editor, fn) : fn();
|
|
14167
|
-
}
|
|
14168
14146
|
const abstractAnnotationBehaviors = [defineBehavior({
|
|
14169
14147
|
on: "annotation.set",
|
|
14170
14148
|
guard: ({
|
|
@@ -15306,7 +15284,7 @@ const abstractInsertBehaviors = [
|
|
|
15306
15284
|
}]
|
|
15307
15285
|
}), abstractKeyboardBehaviors = [
|
|
15308
15286
|
/**
|
|
15309
|
-
* When Backspace is pressed on an inline object,
|
|
15287
|
+
* When Backspace is pressed on an inline object, the engine raises a
|
|
15310
15288
|
* `delete.backward` event with `unit: 'block'`. This is wrong and this
|
|
15311
15289
|
* Behavior adjusts that.
|
|
15312
15290
|
*/
|
|
@@ -15322,7 +15300,7 @@ const abstractInsertBehaviors = [
|
|
|
15322
15300
|
})]]
|
|
15323
15301
|
}),
|
|
15324
15302
|
/**
|
|
15325
|
-
* When Delete is pressed on an inline object,
|
|
15303
|
+
* When Delete is pressed on an inline object, the engine raises a
|
|
15326
15304
|
* `delete.forward` event with `unit: 'block'`. This is wrong and this
|
|
15327
15305
|
* Behavior adjusts that.
|
|
15328
15306
|
*/
|
|
@@ -15525,6 +15503,35 @@ const abstractInsertBehaviors = [
|
|
|
15525
15503
|
listItem: event.listItem
|
|
15526
15504
|
})]]
|
|
15527
15505
|
})], abstractMoveBehaviors = [defineBehavior({
|
|
15506
|
+
on: "move.block",
|
|
15507
|
+
guard: ({
|
|
15508
|
+
snapshot,
|
|
15509
|
+
event
|
|
15510
|
+
}) => {
|
|
15511
|
+
const originEntry = getNode(snapshot, event.at), destinationEntry = getNode(snapshot, event.to);
|
|
15512
|
+
if (!originEntry || !destinationEntry || pathEquals(originEntry.path, destinationEntry.path))
|
|
15513
|
+
return !1;
|
|
15514
|
+
const siblings = getChildren(snapshot, parentPath(originEntry.path)), originIndex = siblings.findIndex((sibling) => sibling.node._key === originEntry.node._key), destinationIndex = siblings.findIndex((sibling) => sibling.node._key === destinationEntry.node._key), movingDown = originIndex !== -1 && destinationIndex !== -1 && originIndex < destinationIndex;
|
|
15515
|
+
return {
|
|
15516
|
+
originEntry,
|
|
15517
|
+
destinationEntry,
|
|
15518
|
+
movingDown
|
|
15519
|
+
};
|
|
15520
|
+
},
|
|
15521
|
+
actions: [(_, {
|
|
15522
|
+
originEntry,
|
|
15523
|
+
destinationEntry,
|
|
15524
|
+
movingDown
|
|
15525
|
+
}) => [raise({
|
|
15526
|
+
type: "unset",
|
|
15527
|
+
at: originEntry.path
|
|
15528
|
+
}), raise({
|
|
15529
|
+
type: "insert",
|
|
15530
|
+
at: destinationEntry.path,
|
|
15531
|
+
value: originEntry.node,
|
|
15532
|
+
position: movingDown ? "after" : "before"
|
|
15533
|
+
})]]
|
|
15534
|
+
}), defineBehavior({
|
|
15528
15535
|
on: "move.block up",
|
|
15529
15536
|
guard: ({
|
|
15530
15537
|
snapshot,
|
|
@@ -15532,18 +15539,26 @@ const abstractInsertBehaviors = [
|
|
|
15532
15539
|
}) => {
|
|
15533
15540
|
const previousSibling = getSibling(snapshot, event.at, "previous");
|
|
15534
15541
|
return previousSibling ? {
|
|
15535
|
-
previousSibling
|
|
15542
|
+
previousSibling,
|
|
15543
|
+
savedSelection: snapshot.context.selection
|
|
15536
15544
|
} : !1;
|
|
15537
15545
|
},
|
|
15538
15546
|
actions: [({
|
|
15539
15547
|
event
|
|
15540
15548
|
}, {
|
|
15541
|
-
previousSibling
|
|
15542
|
-
|
|
15543
|
-
|
|
15544
|
-
|
|
15545
|
-
|
|
15546
|
-
|
|
15549
|
+
previousSibling,
|
|
15550
|
+
savedSelection
|
|
15551
|
+
}) => {
|
|
15552
|
+
const actions = [raise({
|
|
15553
|
+
type: "move.block",
|
|
15554
|
+
at: event.at,
|
|
15555
|
+
to: previousSibling.path
|
|
15556
|
+
})];
|
|
15557
|
+
return savedSelection && actions.push(raise({
|
|
15558
|
+
type: "select",
|
|
15559
|
+
at: savedSelection
|
|
15560
|
+
})), actions;
|
|
15561
|
+
}]
|
|
15547
15562
|
}), defineBehavior({
|
|
15548
15563
|
on: "move.block down",
|
|
15549
15564
|
guard: ({
|
|
@@ -15552,18 +15567,26 @@ const abstractInsertBehaviors = [
|
|
|
15552
15567
|
}) => {
|
|
15553
15568
|
const nextSibling = getSibling(snapshot, event.at, "next");
|
|
15554
15569
|
return nextSibling ? {
|
|
15555
|
-
nextSibling
|
|
15570
|
+
nextSibling,
|
|
15571
|
+
savedSelection: snapshot.context.selection
|
|
15556
15572
|
} : !1;
|
|
15557
15573
|
},
|
|
15558
15574
|
actions: [({
|
|
15559
15575
|
event
|
|
15560
15576
|
}, {
|
|
15561
|
-
nextSibling
|
|
15562
|
-
|
|
15563
|
-
|
|
15564
|
-
|
|
15565
|
-
|
|
15566
|
-
|
|
15577
|
+
nextSibling,
|
|
15578
|
+
savedSelection
|
|
15579
|
+
}) => {
|
|
15580
|
+
const actions = [raise({
|
|
15581
|
+
type: "move.block",
|
|
15582
|
+
at: event.at,
|
|
15583
|
+
to: nextSibling.path
|
|
15584
|
+
})];
|
|
15585
|
+
return savedSelection && actions.push(raise({
|
|
15586
|
+
type: "select",
|
|
15587
|
+
at: savedSelection
|
|
15588
|
+
})), actions;
|
|
15589
|
+
}]
|
|
15567
15590
|
})], abstractSelectBehaviors = [defineBehavior({
|
|
15568
15591
|
on: "select.block",
|
|
15569
15592
|
guard: ({
|
|
@@ -15955,7 +15978,7 @@ const abstractInsertBehaviors = [
|
|
|
15955
15978
|
function isSyntheticBehaviorEvent(event) {
|
|
15956
15979
|
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
15957
15980
|
}
|
|
15958
|
-
const abstractBehaviorEventTypes = ["annotation.set", "annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.child", "delete.forward", "delete.text", "deserialize", "deserialize.data", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.inline object", "insert.soft break", "insert.span", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.block", "select.previous block", "select.next block", "serialize", "serialize.data", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
15981
|
+
const abstractBehaviorEventTypes = ["annotation.set", "annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.child", "delete.forward", "delete.text", "deserialize", "deserialize.data", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.inline object", "insert.soft break", "insert.span", "list item.add", "list item.remove", "list item.toggle", "move.block", "move.block down", "move.block up", "select.block", "select.previous block", "select.next block", "serialize", "serialize.data", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
15959
15982
|
function isAbstractBehaviorEvent(event) {
|
|
15960
15983
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
15961
15984
|
}
|
|
@@ -16310,18 +16333,18 @@ function isTypeAlreadyRegistered(maps, attempting, type) {
|
|
|
16310
16333
|
}
|
|
16311
16334
|
function rerouteExternalBehaviorEvent({
|
|
16312
16335
|
event,
|
|
16313
|
-
|
|
16336
|
+
editorEngine
|
|
16314
16337
|
}) {
|
|
16315
16338
|
switch (event.type) {
|
|
16316
16339
|
case "blur":
|
|
16317
16340
|
return {
|
|
16318
16341
|
type: "blur",
|
|
16319
|
-
editor:
|
|
16342
|
+
editor: editorEngine
|
|
16320
16343
|
};
|
|
16321
16344
|
case "focus":
|
|
16322
16345
|
return {
|
|
16323
16346
|
type: "focus",
|
|
16324
|
-
editor:
|
|
16347
|
+
editor: editorEngine
|
|
16325
16348
|
};
|
|
16326
16349
|
case "insert.block object":
|
|
16327
16350
|
return {
|
|
@@ -16334,13 +16357,13 @@ function rerouteExternalBehaviorEvent({
|
|
|
16334
16357
|
},
|
|
16335
16358
|
placement: event.placement
|
|
16336
16359
|
},
|
|
16337
|
-
editor:
|
|
16360
|
+
editor: editorEngine
|
|
16338
16361
|
};
|
|
16339
16362
|
default:
|
|
16340
16363
|
return {
|
|
16341
16364
|
type: "behavior event",
|
|
16342
16365
|
behaviorEvent: event,
|
|
16343
|
-
editor:
|
|
16366
|
+
editor: editorEngine
|
|
16344
16367
|
};
|
|
16345
16368
|
}
|
|
16346
16369
|
}
|
|
@@ -16366,11 +16389,11 @@ const editorMachine = setup({
|
|
|
16366
16389
|
event
|
|
16367
16390
|
}) => (assertEvent(event, "remove behavior"), context.behaviors.delete(event.behaviorConfig), /* @__PURE__ */ new Set([...context.behaviors]))
|
|
16368
16391
|
}),
|
|
16369
|
-
"add
|
|
16370
|
-
|
|
16392
|
+
"add editor engine to context": assign({
|
|
16393
|
+
editorEngine: ({
|
|
16371
16394
|
context,
|
|
16372
16395
|
event
|
|
16373
|
-
}) => event.type === "add
|
|
16396
|
+
}) => event.type === "add editor engine" ? event.editor : context.editorEngine
|
|
16374
16397
|
}),
|
|
16375
16398
|
register: assign(({
|
|
16376
16399
|
context,
|
|
@@ -16385,9 +16408,9 @@ const editorMachine = setup({
|
|
|
16385
16408
|
if (!containerConfig)
|
|
16386
16409
|
return {};
|
|
16387
16410
|
const containers = new Map(context.containers);
|
|
16388
|
-
return containers.set(node.type, containerConfig), context.
|
|
16411
|
+
return containers.set(node.type, containerConfig), context.editorEngine && (context.editorEngine.containers = containers, context.editorEngine.publicContainers = buildPublicContainers(containers), normalize(context.editorEngine, {
|
|
16389
16412
|
force: !0
|
|
16390
|
-
}), context.
|
|
16413
|
+
}), context.editorEngine.onChange()), {
|
|
16391
16414
|
containers
|
|
16392
16415
|
};
|
|
16393
16416
|
}
|
|
@@ -16395,7 +16418,7 @@ const editorMachine = setup({
|
|
|
16395
16418
|
if (isTypeAlreadyRegistered(context, "textBlock", node.type))
|
|
16396
16419
|
return {};
|
|
16397
16420
|
const textBlocks = new Map(context.textBlocks);
|
|
16398
|
-
return textBlocks.set(node.type, resolveTextBlockConfig(node)), context.
|
|
16421
|
+
return textBlocks.set(node.type, resolveTextBlockConfig(node)), context.editorEngine && (context.editorEngine.textBlocks = textBlocks, context.editorEngine.onChange()), {
|
|
16399
16422
|
textBlocks
|
|
16400
16423
|
};
|
|
16401
16424
|
}
|
|
@@ -16405,7 +16428,7 @@ const editorMachine = setup({
|
|
|
16405
16428
|
const spans = new Map(context.spans);
|
|
16406
16429
|
return spans.set(node.type, {
|
|
16407
16430
|
span: node
|
|
16408
|
-
}), context.
|
|
16431
|
+
}), context.editorEngine && (context.editorEngine.spans = spans, context.editorEngine.onChange()), {
|
|
16409
16432
|
spans
|
|
16410
16433
|
};
|
|
16411
16434
|
}
|
|
@@ -16415,7 +16438,7 @@ const editorMachine = setup({
|
|
|
16415
16438
|
const blockObjects = new Map(context.blockObjects);
|
|
16416
16439
|
return blockObjects.set(node.type, {
|
|
16417
16440
|
blockObject: node
|
|
16418
|
-
}), context.
|
|
16441
|
+
}), context.editorEngine && (context.editorEngine.blockObjects = blockObjects, context.editorEngine.onChange()), {
|
|
16419
16442
|
blockObjects
|
|
16420
16443
|
};
|
|
16421
16444
|
}
|
|
@@ -16424,7 +16447,7 @@ const editorMachine = setup({
|
|
|
16424
16447
|
const inlineObjects = new Map(context.inlineObjects);
|
|
16425
16448
|
return inlineObjects.set(node.type, {
|
|
16426
16449
|
inlineObject: node
|
|
16427
|
-
}), context.
|
|
16450
|
+
}), context.editorEngine && (context.editorEngine.inlineObjects = inlineObjects, context.editorEngine.onChange()), {
|
|
16428
16451
|
inlineObjects
|
|
16429
16452
|
};
|
|
16430
16453
|
}),
|
|
@@ -16436,41 +16459,41 @@ const editorMachine = setup({
|
|
|
16436
16459
|
const node = event.node;
|
|
16437
16460
|
if (node.kind === "container") {
|
|
16438
16461
|
const containers = new Map(context.containers);
|
|
16439
|
-
return containers.delete(node.type), context.
|
|
16462
|
+
return containers.delete(node.type), context.editorEngine && (context.editorEngine.containers = containers, context.editorEngine.publicContainers = buildPublicContainers(containers), normalize(context.editorEngine, {
|
|
16440
16463
|
force: !0
|
|
16441
|
-
}), context.
|
|
16464
|
+
}), context.editorEngine.onChange()), {
|
|
16442
16465
|
containers
|
|
16443
16466
|
};
|
|
16444
16467
|
}
|
|
16445
16468
|
if (node.kind === "textBlock") {
|
|
16446
16469
|
const textBlocks = new Map(context.textBlocks);
|
|
16447
|
-
return textBlocks.delete(node.type), context.
|
|
16470
|
+
return textBlocks.delete(node.type), context.editorEngine && (context.editorEngine.textBlocks = textBlocks, context.editorEngine.onChange()), {
|
|
16448
16471
|
textBlocks
|
|
16449
16472
|
};
|
|
16450
16473
|
}
|
|
16451
16474
|
if (node.kind === "span") {
|
|
16452
16475
|
const spans = new Map(context.spans);
|
|
16453
|
-
return spans.delete(node.type), context.
|
|
16476
|
+
return spans.delete(node.type), context.editorEngine && (context.editorEngine.spans = spans, context.editorEngine.onChange()), {
|
|
16454
16477
|
spans
|
|
16455
16478
|
};
|
|
16456
16479
|
}
|
|
16457
16480
|
if (node.kind === "blockObject") {
|
|
16458
16481
|
const blockObjects = new Map(context.blockObjects);
|
|
16459
|
-
return blockObjects.delete(node.type), context.
|
|
16482
|
+
return blockObjects.delete(node.type), context.editorEngine && (context.editorEngine.blockObjects = blockObjects, context.editorEngine.onChange()), {
|
|
16460
16483
|
blockObjects
|
|
16461
16484
|
};
|
|
16462
16485
|
}
|
|
16463
16486
|
const inlineObjects = new Map(context.inlineObjects);
|
|
16464
|
-
return inlineObjects.delete(node.type), context.
|
|
16487
|
+
return inlineObjects.delete(node.type), context.editorEngine && (context.editorEngine.inlineObjects = inlineObjects, context.editorEngine.onChange()), {
|
|
16465
16488
|
inlineObjects
|
|
16466
16489
|
};
|
|
16467
16490
|
}),
|
|
16468
|
-
"attach maps to
|
|
16491
|
+
"attach maps to editor engine": ({
|
|
16469
16492
|
context
|
|
16470
16493
|
}) => {
|
|
16471
|
-
context.
|
|
16494
|
+
context.editorEngine && (context.editorEngine.containers = context.containers, context.editorEngine.publicContainers = buildPublicContainers(context.containers), context.editorEngine.blockObjects = context.blockObjects, context.editorEngine.inlineObjects = context.inlineObjects, context.editorEngine.spans = context.spans, context.editorEngine.textBlocks = context.textBlocks, normalize(context.editorEngine, {
|
|
16472
16495
|
force: !0
|
|
16473
|
-
}), context.
|
|
16496
|
+
}), context.editorEngine.onChange());
|
|
16474
16497
|
},
|
|
16475
16498
|
"emit patch event": emit(({
|
|
16476
16499
|
event
|
|
@@ -16546,14 +16569,14 @@ const editorMachine = setup({
|
|
|
16546
16569
|
"handle focus": ({
|
|
16547
16570
|
context
|
|
16548
16571
|
}) => {
|
|
16549
|
-
const
|
|
16550
|
-
if (!
|
|
16551
|
-
console.error("No
|
|
16572
|
+
const editorEngine = context.editorEngine;
|
|
16573
|
+
if (!editorEngine) {
|
|
16574
|
+
console.error("No editor engine found to focus");
|
|
16552
16575
|
return;
|
|
16553
16576
|
}
|
|
16554
16577
|
try {
|
|
16555
|
-
const currentSelection =
|
|
16556
|
-
DOMEditor.focus(
|
|
16578
|
+
const currentSelection = editorEngine.selection;
|
|
16579
|
+
DOMEditor.focus(editorEngine), currentSelection && (editorEngine.select(currentSelection), editorEngine.pendingSelection = editorEngine.selection, editorEngine.onChange());
|
|
16557
16580
|
} catch (error) {
|
|
16558
16581
|
console.error(new Error(`Failed to focus editor: ${error instanceof Error ? error.message : error}`));
|
|
16559
16582
|
}
|
|
@@ -16586,7 +16609,7 @@ const editorMachine = setup({
|
|
|
16586
16609
|
}
|
|
16587
16610
|
self.send(rerouteExternalBehaviorEvent({
|
|
16588
16611
|
event: eventSentBack,
|
|
16589
|
-
|
|
16612
|
+
editorEngine: event.editor
|
|
16590
16613
|
}));
|
|
16591
16614
|
}
|
|
16592
16615
|
});
|
|
@@ -16602,12 +16625,12 @@ const editorMachine = setup({
|
|
|
16602
16625
|
})
|
|
16603
16626
|
},
|
|
16604
16627
|
guards: {
|
|
16605
|
-
"
|
|
16628
|
+
"engine is busy": ({
|
|
16606
16629
|
context
|
|
16607
|
-
}) => context.
|
|
16608
|
-
"
|
|
16630
|
+
}) => context.editorEngine ? context.editorEngine.operations.length > 0 : !1,
|
|
16631
|
+
"engine is normalizing node": ({
|
|
16609
16632
|
context
|
|
16610
|
-
}) => context.
|
|
16633
|
+
}) => context.editorEngine ? context.editorEngine.isNormalizingNode : !1
|
|
16611
16634
|
}
|
|
16612
16635
|
}).createMachine({
|
|
16613
16636
|
id: "editor",
|
|
@@ -16637,8 +16660,8 @@ const editorMachine = setup({
|
|
|
16637
16660
|
"remove behavior": {
|
|
16638
16661
|
actions: "remove behavior from context"
|
|
16639
16662
|
},
|
|
16640
|
-
"add
|
|
16641
|
-
actions: ["add
|
|
16663
|
+
"add editor engine": {
|
|
16664
|
+
actions: ["add editor engine to context", "attach maps to editor engine"]
|
|
16642
16665
|
},
|
|
16643
16666
|
register: {
|
|
16644
16667
|
actions: ["register"]
|
|
@@ -16737,7 +16760,7 @@ const editorMachine = setup({
|
|
|
16737
16760
|
focus: {
|
|
16738
16761
|
target: ".focusing",
|
|
16739
16762
|
actions: [assign({
|
|
16740
|
-
|
|
16763
|
+
editorEngine: ({
|
|
16741
16764
|
event
|
|
16742
16765
|
}) => event.editor
|
|
16743
16766
|
})]
|
|
@@ -16776,7 +16799,7 @@ const editorMachine = setup({
|
|
|
16776
16799
|
debug.state("exit: edit mode->editable->focusing->checking if busy");
|
|
16777
16800
|
}],
|
|
16778
16801
|
always: [{
|
|
16779
|
-
guard: "
|
|
16802
|
+
guard: "engine is busy",
|
|
16780
16803
|
target: "busy"
|
|
16781
16804
|
}, {
|
|
16782
16805
|
target: "#editor.edit mode.editable.idle",
|
|
@@ -16923,14 +16946,14 @@ const editorMachine = setup({
|
|
|
16923
16946
|
}],
|
|
16924
16947
|
on: {
|
|
16925
16948
|
"internal.patch": [{
|
|
16926
|
-
guard: "
|
|
16949
|
+
guard: "engine is normalizing node",
|
|
16927
16950
|
actions: "defer event"
|
|
16928
16951
|
}, {
|
|
16929
16952
|
actions: "defer event",
|
|
16930
16953
|
target: "#editor.setup.set up.writing.dirty"
|
|
16931
16954
|
}],
|
|
16932
16955
|
mutation: [{
|
|
16933
|
-
guard: "
|
|
16956
|
+
guard: "engine is normalizing node",
|
|
16934
16957
|
actions: "defer event"
|
|
16935
16958
|
}, {
|
|
16936
16959
|
actions: "defer event",
|
|
@@ -16992,7 +17015,7 @@ const editorMachine = setup({
|
|
|
16992
17015
|
"set is deferring mutations": ({
|
|
16993
17016
|
context
|
|
16994
17017
|
}) => {
|
|
16995
|
-
context.
|
|
17018
|
+
context.editorEngine.isDeferringMutations = !0;
|
|
16996
17019
|
},
|
|
16997
17020
|
"emit mutations": enqueueActions(({
|
|
16998
17021
|
context,
|
|
@@ -17004,7 +17027,7 @@ const editorMachine = setup({
|
|
|
17004
17027
|
patches: bulk.patches,
|
|
17005
17028
|
snapshot: bulk.value
|
|
17006
17029
|
});
|
|
17007
|
-
context.
|
|
17030
|
+
context.editorEngine.isDeferringMutations = !1;
|
|
17008
17031
|
}),
|
|
17009
17032
|
"clear pending mutations": assign({
|
|
17010
17033
|
pendingMutations: []
|
|
@@ -17054,15 +17077,15 @@ const editorMachine = setup({
|
|
|
17054
17077
|
input,
|
|
17055
17078
|
sendBack
|
|
17056
17079
|
}) => {
|
|
17057
|
-
const originalApply = input.
|
|
17058
|
-
return input.
|
|
17080
|
+
const originalApply = input.editorEngine.apply;
|
|
17081
|
+
return input.editorEngine.apply = (op) => {
|
|
17059
17082
|
op.type === "insert_text" || op.type === "remove_text" ? sendBack({
|
|
17060
17083
|
type: "typing"
|
|
17061
17084
|
}) : sendBack({
|
|
17062
17085
|
type: "not typing"
|
|
17063
17086
|
}), originalApply(op);
|
|
17064
17087
|
}, () => {
|
|
17065
|
-
input.
|
|
17088
|
+
input.editorEngine.apply = originalApply;
|
|
17066
17089
|
};
|
|
17067
17090
|
}),
|
|
17068
17091
|
"mutation interval": fromCallback(({
|
|
@@ -17086,9 +17109,9 @@ const editorMachine = setup({
|
|
|
17086
17109
|
"is read-only": ({
|
|
17087
17110
|
context
|
|
17088
17111
|
}) => context.readOnly,
|
|
17089
|
-
"
|
|
17112
|
+
"engine is normalizing": ({
|
|
17090
17113
|
context
|
|
17091
|
-
}) => isNormalizing(context.
|
|
17114
|
+
}) => isNormalizing(context.editorEngine)
|
|
17092
17115
|
},
|
|
17093
17116
|
delays: {
|
|
17094
17117
|
"type debounce": 250
|
|
@@ -17102,7 +17125,7 @@ const editorMachine = setup({
|
|
|
17102
17125
|
pendingPatchEvents: [],
|
|
17103
17126
|
readOnly: input.readOnly,
|
|
17104
17127
|
schema: input.schema,
|
|
17105
|
-
|
|
17128
|
+
editorEngine: input.editorEngine
|
|
17106
17129
|
}),
|
|
17107
17130
|
on: {
|
|
17108
17131
|
"update readOnly": {
|
|
@@ -17118,7 +17141,7 @@ const editorMachine = setup({
|
|
|
17118
17141
|
input: ({
|
|
17119
17142
|
context
|
|
17120
17143
|
}) => ({
|
|
17121
|
-
|
|
17144
|
+
editorEngine: context.editorEngine
|
|
17122
17145
|
})
|
|
17123
17146
|
},
|
|
17124
17147
|
states: {
|
|
@@ -17194,7 +17217,7 @@ const editorMachine = setup({
|
|
|
17194
17217
|
},
|
|
17195
17218
|
on: {
|
|
17196
17219
|
"emit changes": {
|
|
17197
|
-
guard: and([not("is read-only"), "
|
|
17220
|
+
guard: and([not("is read-only"), "engine is normalizing"]),
|
|
17198
17221
|
target: "idle",
|
|
17199
17222
|
actions: ["emit pending patch events", "clear pending patch events", "emit mutations", "clear pending mutations"]
|
|
17200
17223
|
},
|
|
@@ -17246,7 +17269,7 @@ const editorMachine = setup({
|
|
|
17246
17269
|
guard: ({
|
|
17247
17270
|
context,
|
|
17248
17271
|
event
|
|
17249
|
-
}) => context.prevSelection
|
|
17272
|
+
}) => !isEqualSelections(context.prevSelection, event.selection),
|
|
17250
17273
|
actions: [assign({
|
|
17251
17274
|
prevSelection: ({
|
|
17252
17275
|
event
|
|
@@ -17606,7 +17629,7 @@ const syncValueCallback = ({
|
|
|
17606
17629
|
updateValue({
|
|
17607
17630
|
context: input.context,
|
|
17608
17631
|
sendBack,
|
|
17609
|
-
|
|
17632
|
+
editorEngine: input.editorEngine,
|
|
17610
17633
|
value: input.value,
|
|
17611
17634
|
streamBlocks: input.streamBlocks
|
|
17612
17635
|
});
|
|
@@ -17653,11 +17676,11 @@ const syncValueCallback = ({
|
|
|
17653
17676
|
"is busy": ({
|
|
17654
17677
|
context
|
|
17655
17678
|
}) => {
|
|
17656
|
-
const isBusy = context.
|
|
17679
|
+
const isBusy = context.editorEngine.isDeferringMutations || context.editorEngine.isProcessingRemoteChanges;
|
|
17657
17680
|
return debug.syncValue(safeStringify({
|
|
17658
17681
|
isBusy,
|
|
17659
|
-
isDeferringMutations: context.
|
|
17660
|
-
isProcessingRemoteChanges: context.
|
|
17682
|
+
isDeferringMutations: context.editorEngine.isDeferringMutations,
|
|
17683
|
+
isProcessingRemoteChanges: context.editorEngine.isProcessingRemoteChanges
|
|
17661
17684
|
})), isBusy;
|
|
17662
17685
|
},
|
|
17663
17686
|
"is empty value": ({
|
|
@@ -17697,7 +17720,7 @@ const syncValueCallback = ({
|
|
|
17697
17720
|
keyGenerator: input.keyGenerator,
|
|
17698
17721
|
schema: input.schema,
|
|
17699
17722
|
readOnly: input.readOnly,
|
|
17700
|
-
|
|
17723
|
+
editorEngine: input.editorEngine,
|
|
17701
17724
|
pendingValue: void 0,
|
|
17702
17725
|
previousValue: void 0
|
|
17703
17726
|
}),
|
|
@@ -17796,7 +17819,7 @@ const syncValueCallback = ({
|
|
|
17796
17819
|
readOnly: context.readOnly,
|
|
17797
17820
|
schema: context.schema
|
|
17798
17821
|
},
|
|
17799
|
-
|
|
17822
|
+
editorEngine: context.editorEngine,
|
|
17800
17823
|
streamBlocks: !context.initialValueSynced,
|
|
17801
17824
|
value: context.pendingValue
|
|
17802
17825
|
})
|
|
@@ -17837,14 +17860,14 @@ const syncValueCallback = ({
|
|
|
17837
17860
|
async function updateValue({
|
|
17838
17861
|
context,
|
|
17839
17862
|
sendBack,
|
|
17840
|
-
|
|
17863
|
+
editorEngine,
|
|
17841
17864
|
streamBlocks,
|
|
17842
17865
|
value
|
|
17843
17866
|
}) {
|
|
17844
17867
|
let doneSyncing = !1, isChanged = !1, isValid = !0;
|
|
17845
|
-
const hadSelection = !!
|
|
17868
|
+
const hadSelection = !!editorEngine.selection;
|
|
17846
17869
|
if ((!value || value.length === 0) && (clearEditor({
|
|
17847
|
-
|
|
17870
|
+
editorEngine,
|
|
17848
17871
|
doneSyncing
|
|
17849
17872
|
}), isChanged = !0), value && value.length > 0)
|
|
17850
17873
|
if (streamBlocks)
|
|
@@ -17854,7 +17877,7 @@ async function updateValue({
|
|
|
17854
17877
|
return;
|
|
17855
17878
|
}
|
|
17856
17879
|
isChanged = removeExtraBlocks({
|
|
17857
|
-
|
|
17880
|
+
editorEngine,
|
|
17858
17881
|
value
|
|
17859
17882
|
}), (async () => {
|
|
17860
17883
|
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
@@ -17868,7 +17891,7 @@ async function updateValue({
|
|
|
17868
17891
|
sendBack,
|
|
17869
17892
|
block: currentBlock,
|
|
17870
17893
|
index: currentBlockIndex,
|
|
17871
|
-
|
|
17894
|
+
editorEngine,
|
|
17872
17895
|
value
|
|
17873
17896
|
});
|
|
17874
17897
|
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
@@ -17881,7 +17904,7 @@ async function updateValue({
|
|
|
17881
17904
|
if (doneSyncing)
|
|
17882
17905
|
return;
|
|
17883
17906
|
isChanged = removeExtraBlocks({
|
|
17884
|
-
|
|
17907
|
+
editorEngine,
|
|
17885
17908
|
value
|
|
17886
17909
|
});
|
|
17887
17910
|
let index = 0;
|
|
@@ -17894,7 +17917,7 @@ async function updateValue({
|
|
|
17894
17917
|
sendBack,
|
|
17895
17918
|
block,
|
|
17896
17919
|
index,
|
|
17897
|
-
|
|
17920
|
+
editorEngine,
|
|
17898
17921
|
value
|
|
17899
17922
|
});
|
|
17900
17923
|
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
|
|
@@ -17912,7 +17935,7 @@ async function updateValue({
|
|
|
17912
17935
|
if (isChanged) {
|
|
17913
17936
|
debug.syncValue("remote value changed, syncing local value");
|
|
17914
17937
|
try {
|
|
17915
|
-
|
|
17938
|
+
editorEngine.onChange();
|
|
17916
17939
|
} catch (err) {
|
|
17917
17940
|
console.error(err), sendBack({
|
|
17918
17941
|
type: "invalid value",
|
|
@@ -17924,7 +17947,7 @@ async function updateValue({
|
|
|
17924
17947
|
});
|
|
17925
17948
|
return;
|
|
17926
17949
|
}
|
|
17927
|
-
hadSelection && !
|
|
17950
|
+
hadSelection && !editorEngine.selection && editorEngine.children.length > 0 && (applySelect(editorEngine, start(editorEngine, [])), editorEngine.onChange()), sendBack({
|
|
17928
17951
|
type: "value changed",
|
|
17929
17952
|
value
|
|
17930
17953
|
});
|
|
@@ -17943,19 +17966,19 @@ async function* getStreamedBlocks({
|
|
|
17943
17966
|
index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
17944
17967
|
}
|
|
17945
17968
|
function clearEditor({
|
|
17946
|
-
|
|
17969
|
+
editorEngine,
|
|
17947
17970
|
doneSyncing
|
|
17948
17971
|
}) {
|
|
17949
|
-
withoutNormalizing(
|
|
17950
|
-
pluginWithoutHistory(
|
|
17951
|
-
withRemoteChanges(
|
|
17952
|
-
withoutPatching(
|
|
17972
|
+
withoutNormalizing(editorEngine, () => {
|
|
17973
|
+
pluginWithoutHistory(editorEngine, () => {
|
|
17974
|
+
withRemoteChanges(editorEngine, () => {
|
|
17975
|
+
withoutPatching(editorEngine, () => {
|
|
17953
17976
|
if (doneSyncing)
|
|
17954
17977
|
return;
|
|
17955
|
-
const childrenLength =
|
|
17956
|
-
|
|
17957
|
-
const removeNode =
|
|
17958
|
-
removeNode &&
|
|
17978
|
+
const childrenLength = editorEngine.children.length;
|
|
17979
|
+
editorEngine.children.forEach((_, index) => {
|
|
17980
|
+
const removeNode = editorEngine.children[childrenLength - 1 - index];
|
|
17981
|
+
removeNode && editorEngine.apply({
|
|
17959
17982
|
type: "unset",
|
|
17960
17983
|
path: [{
|
|
17961
17984
|
_key: removeNode._key
|
|
@@ -17968,18 +17991,18 @@ function clearEditor({
|
|
|
17968
17991
|
});
|
|
17969
17992
|
}
|
|
17970
17993
|
function removeExtraBlocks({
|
|
17971
|
-
|
|
17994
|
+
editorEngine,
|
|
17972
17995
|
value
|
|
17973
17996
|
}) {
|
|
17974
17997
|
let isChanged = !1;
|
|
17975
|
-
return withoutNormalizing(
|
|
17976
|
-
withRemoteChanges(
|
|
17977
|
-
withoutPatching(
|
|
17978
|
-
const childrenLength =
|
|
17998
|
+
return withoutNormalizing(editorEngine, () => {
|
|
17999
|
+
withRemoteChanges(editorEngine, () => {
|
|
18000
|
+
withoutPatching(editorEngine, () => {
|
|
18001
|
+
const childrenLength = editorEngine.children.length;
|
|
17979
18002
|
if (value.length < childrenLength) {
|
|
17980
18003
|
for (let i = childrenLength - 1; i > value.length - 1; i--) {
|
|
17981
|
-
const removeNode =
|
|
17982
|
-
removeNode &&
|
|
18004
|
+
const removeNode = editorEngine.children[i];
|
|
18005
|
+
removeNode && editorEngine.apply({
|
|
17983
18006
|
type: "unset",
|
|
17984
18007
|
path: [{
|
|
17985
18008
|
_key: removeNode._key
|
|
@@ -17997,23 +18020,23 @@ function syncBlock({
|
|
|
17997
18020
|
sendBack,
|
|
17998
18021
|
block,
|
|
17999
18022
|
index,
|
|
18000
|
-
|
|
18023
|
+
editorEngine,
|
|
18001
18024
|
value
|
|
18002
18025
|
}) {
|
|
18003
|
-
const
|
|
18004
|
-
if (!
|
|
18026
|
+
const oldEngineBlock = editorEngine.children.at(index), oldBlock = editorEngine.children.at(index);
|
|
18027
|
+
if (!oldEngineBlock || !oldBlock) {
|
|
18005
18028
|
const validation2 = validateValue([block], context.schema, context.keyGenerator);
|
|
18006
18029
|
if (debug.syncValue("Validating and inserting new block in the end of the value", block), validation2.valid || validation2.resolution?.autoResolve) {
|
|
18007
|
-
const
|
|
18030
|
+
const engineBlock = toEngineBlock(block, {
|
|
18008
18031
|
schemaTypes: context.schema
|
|
18009
18032
|
});
|
|
18010
|
-
return withoutNormalizing(
|
|
18011
|
-
withRemoteChanges(
|
|
18012
|
-
withoutPatching(
|
|
18013
|
-
|
|
18033
|
+
return withoutNormalizing(editorEngine, () => {
|
|
18034
|
+
withRemoteChanges(editorEngine, () => {
|
|
18035
|
+
withoutPatching(editorEngine, () => {
|
|
18036
|
+
editorEngine.apply({
|
|
18014
18037
|
type: "insert",
|
|
18015
|
-
path: [
|
|
18016
|
-
node:
|
|
18038
|
+
path: [editorEngine.children.length],
|
|
18039
|
+
node: engineBlock,
|
|
18017
18040
|
position: "before"
|
|
18018
18041
|
});
|
|
18019
18042
|
});
|
|
@@ -18049,24 +18072,24 @@ function syncBlock({
|
|
|
18049
18072
|
type: "patch",
|
|
18050
18073
|
patch
|
|
18051
18074
|
});
|
|
18052
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key && oldBlock._type === block._type ? (debug.syncValue("Updating block", oldBlock, block), withoutNormalizing(
|
|
18053
|
-
withRemoteChanges(
|
|
18054
|
-
withoutPatching(
|
|
18075
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key && oldBlock._type === block._type ? (debug.syncValue("Updating block", oldBlock, block), withoutNormalizing(editorEngine, () => {
|
|
18076
|
+
withRemoteChanges(editorEngine, () => {
|
|
18077
|
+
withoutPatching(editorEngine, () => {
|
|
18055
18078
|
updateBlock({
|
|
18056
18079
|
context,
|
|
18057
|
-
|
|
18058
|
-
|
|
18080
|
+
editorEngine,
|
|
18081
|
+
oldEngineBlock,
|
|
18059
18082
|
block,
|
|
18060
18083
|
index
|
|
18061
18084
|
});
|
|
18062
18085
|
});
|
|
18063
18086
|
});
|
|
18064
|
-
})) : (debug.syncValue("Replacing block", oldBlock, block), withoutNormalizing(
|
|
18065
|
-
withRemoteChanges(
|
|
18066
|
-
withoutPatching(
|
|
18087
|
+
})) : (debug.syncValue("Replacing block", oldBlock, block), withoutNormalizing(editorEngine, () => {
|
|
18088
|
+
withRemoteChanges(editorEngine, () => {
|
|
18089
|
+
withoutPatching(editorEngine, () => {
|
|
18067
18090
|
replaceBlock({
|
|
18068
18091
|
context,
|
|
18069
|
-
|
|
18092
|
+
editorEngine,
|
|
18070
18093
|
block,
|
|
18071
18094
|
index
|
|
18072
18095
|
});
|
|
@@ -18086,84 +18109,84 @@ function syncBlock({
|
|
|
18086
18109
|
}
|
|
18087
18110
|
function replaceBlock({
|
|
18088
18111
|
context,
|
|
18089
|
-
|
|
18112
|
+
editorEngine,
|
|
18090
18113
|
block,
|
|
18091
18114
|
index
|
|
18092
18115
|
}) {
|
|
18093
|
-
const
|
|
18116
|
+
const engineBlock = toEngineBlock(block, {
|
|
18094
18117
|
schemaTypes: context.schema
|
|
18095
|
-
}), currentSelection =
|
|
18096
|
-
selectionFocusOnBlock && applyDeselect(
|
|
18097
|
-
const oldNode =
|
|
18098
|
-
oldNode && (
|
|
18118
|
+
}), currentSelection = editorEngine.selection, focusBlockSegment = currentSelection?.focus.path[0], blockAtIndex = editorEngine.children[index], selectionFocusOnBlock = currentSelection && isKeyedSegment(focusBlockSegment) && blockAtIndex && focusBlockSegment._key === blockAtIndex._key;
|
|
18119
|
+
selectionFocusOnBlock && applyDeselect(editorEngine);
|
|
18120
|
+
const oldNode = editorEngine.children[index];
|
|
18121
|
+
oldNode && (editorEngine.apply({
|
|
18099
18122
|
type: "unset",
|
|
18100
18123
|
path: [{
|
|
18101
18124
|
_key: oldNode._key
|
|
18102
18125
|
}]
|
|
18103
|
-
}),
|
|
18126
|
+
}), editorEngine.apply({
|
|
18104
18127
|
type: "insert",
|
|
18105
18128
|
path: [index],
|
|
18106
|
-
node:
|
|
18129
|
+
node: engineBlock,
|
|
18107
18130
|
position: "before"
|
|
18108
|
-
}),
|
|
18131
|
+
}), editorEngine.onChange(), selectionFocusOnBlock && hasNode(editorEngine, currentSelection.anchor.path) && hasNode(editorEngine, currentSelection.focus.path) && applySelect(editorEngine, currentSelection));
|
|
18109
18132
|
}
|
|
18110
18133
|
function updateBlock({
|
|
18111
18134
|
context,
|
|
18112
|
-
|
|
18113
|
-
|
|
18135
|
+
editorEngine,
|
|
18136
|
+
oldEngineBlock,
|
|
18114
18137
|
block,
|
|
18115
18138
|
index: _index
|
|
18116
18139
|
}) {
|
|
18117
|
-
const
|
|
18140
|
+
const engineBlock = toEngineBlock(block, {
|
|
18118
18141
|
schemaTypes: context.schema
|
|
18119
18142
|
}), {
|
|
18120
18143
|
children: _children,
|
|
18121
18144
|
...blockProps
|
|
18122
|
-
} =
|
|
18123
|
-
setNodeProperties(
|
|
18124
|
-
_key:
|
|
18145
|
+
} = engineBlock;
|
|
18146
|
+
setNodeProperties(editorEngine, blockProps, [{
|
|
18147
|
+
_key: oldEngineBlock._key
|
|
18125
18148
|
}]);
|
|
18126
|
-
const oldRecord =
|
|
18149
|
+
const oldRecord = oldEngineBlock, newRecord = engineBlock, removedProperties = {};
|
|
18127
18150
|
for (const key of Object.keys(oldRecord))
|
|
18128
18151
|
key === "children" || key === "text" || newRecord.hasOwnProperty(key) || (removedProperties[key] = null);
|
|
18129
|
-
if (Object.keys(removedProperties).length > 0 && setNodeProperties(
|
|
18130
|
-
_key:
|
|
18152
|
+
if (Object.keys(removedProperties).length > 0 && setNodeProperties(editorEngine, removedProperties, [{
|
|
18153
|
+
_key: oldEngineBlock._key
|
|
18131
18154
|
}]), isTextBlock({
|
|
18132
|
-
schema:
|
|
18133
|
-
},
|
|
18134
|
-
schema:
|
|
18135
|
-
},
|
|
18136
|
-
const oldKeys =
|
|
18155
|
+
schema: editorEngine.schema
|
|
18156
|
+
}, engineBlock) && isTextBlock({
|
|
18157
|
+
schema: editorEngine.schema
|
|
18158
|
+
}, oldEngineBlock)) {
|
|
18159
|
+
const oldKeys = oldEngineBlock.children.map((c2) => c2._key), newKeys = engineBlock.children.map((c2) => c2._key), oldKeySet = new Set(oldKeys), hasSharedKeys = newKeys.some((key) => oldKeySet.has(key));
|
|
18137
18160
|
if (oldKeys.length === newKeys.length && oldKeys.length > 0 && oldKeySet.size === oldKeys.length && oldKeys.some((key, i) => key !== newKeys[i]) && newKeys.every((key) => oldKeySet.has(key)) || newKeys.length > 0 && !hasSharedKeys) {
|
|
18138
|
-
debug.syncValue("Replacing children via set"), setNodeProperties(
|
|
18139
|
-
children:
|
|
18161
|
+
debug.syncValue("Replacing children via set"), setNodeProperties(editorEngine, {
|
|
18162
|
+
children: engineBlock.children
|
|
18140
18163
|
}, [{
|
|
18141
|
-
_key:
|
|
18142
|
-
}]),
|
|
18164
|
+
_key: oldEngineBlock._key
|
|
18165
|
+
}]), editorEngine.onChange();
|
|
18143
18166
|
return;
|
|
18144
18167
|
}
|
|
18145
|
-
const oldBlockChildrenLength =
|
|
18146
|
-
|
|
18168
|
+
const oldBlockChildrenLength = oldEngineBlock.children.length;
|
|
18169
|
+
engineBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - engineBlock.children.length)).forEach((_, i) => {
|
|
18147
18170
|
const childIndex = oldBlockChildrenLength - 1 - i;
|
|
18148
18171
|
if (childIndex > 0) {
|
|
18149
18172
|
debug.syncValue("Removing child");
|
|
18150
|
-
const childNode =
|
|
18173
|
+
const childNode = oldEngineBlock.children[childIndex];
|
|
18151
18174
|
if (!childNode)
|
|
18152
18175
|
return;
|
|
18153
|
-
|
|
18176
|
+
editorEngine.apply({
|
|
18154
18177
|
type: "unset",
|
|
18155
18178
|
path: [{
|
|
18156
|
-
_key:
|
|
18179
|
+
_key: oldEngineBlock._key
|
|
18157
18180
|
}, "children", {
|
|
18158
18181
|
_key: childNode._key
|
|
18159
18182
|
}]
|
|
18160
18183
|
});
|
|
18161
18184
|
}
|
|
18162
|
-
}),
|
|
18163
|
-
const oldBlockChild =
|
|
18164
|
-
schema:
|
|
18185
|
+
}), engineBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
18186
|
+
const oldBlockChild = oldEngineBlock.children.at(currentBlockChildIndex), isChildChanged = !oldBlockChild || !isEqualChild(currentBlockChild, oldBlockChild, editorEngine.schema.span.name), isTextChanged = oldBlockChild && isSpan({
|
|
18187
|
+
schema: editorEngine.schema
|
|
18165
18188
|
}, oldBlockChild) && currentBlockChild.text !== oldBlockChild.text, path2 = [{
|
|
18166
|
-
_key:
|
|
18189
|
+
_key: oldEngineBlock._key
|
|
18167
18190
|
}, "children", {
|
|
18168
18191
|
_key: currentBlockChild._key
|
|
18169
18192
|
}];
|
|
@@ -18174,13 +18197,13 @@ function updateBlock({
|
|
|
18174
18197
|
text: _text,
|
|
18175
18198
|
...childProps
|
|
18176
18199
|
} = currentBlockChild;
|
|
18177
|
-
setNodeProperties(
|
|
18200
|
+
setNodeProperties(editorEngine, childProps, path2);
|
|
18178
18201
|
const isSpanNode2 = isSpan({
|
|
18179
18202
|
schema: context.schema
|
|
18180
18203
|
}, currentBlockChild) && isSpan({
|
|
18181
18204
|
schema: context.schema
|
|
18182
18205
|
}, oldBlockChild);
|
|
18183
|
-
isSpanNode2 && isTextChanged ? (oldBlockChild.text.length > 0 && deleteRange(
|
|
18206
|
+
isSpanNode2 && isTextChanged ? (oldBlockChild.text.length > 0 && deleteRange(editorEngine, {
|
|
18184
18207
|
focus: {
|
|
18185
18208
|
path: path2,
|
|
18186
18209
|
offset: 0
|
|
@@ -18192,63 +18215,63 @@ function updateBlock({
|
|
|
18192
18215
|
}, {
|
|
18193
18216
|
selection: "preserve",
|
|
18194
18217
|
removeEmptyStartBlock: !0
|
|
18195
|
-
}),
|
|
18218
|
+
}), editorEngine.apply({
|
|
18196
18219
|
type: "insert_text",
|
|
18197
18220
|
path: path2,
|
|
18198
18221
|
offset: 0,
|
|
18199
18222
|
text: currentBlockChild.text
|
|
18200
|
-
}),
|
|
18223
|
+
}), editorEngine.onChange()) : isSpanNode2 || debug.syncValue("Updating changed inline object child", currentBlockChild);
|
|
18201
18224
|
} else if (oldBlockChild) {
|
|
18202
18225
|
debug.syncValue("Replacing child", currentBlockChild);
|
|
18203
|
-
const oldChild =
|
|
18226
|
+
const oldChild = oldEngineBlock.children[currentBlockChildIndex];
|
|
18204
18227
|
if (!oldChild)
|
|
18205
18228
|
return;
|
|
18206
|
-
|
|
18229
|
+
editorEngine.apply({
|
|
18207
18230
|
type: "unset",
|
|
18208
18231
|
path: [{
|
|
18209
|
-
_key:
|
|
18232
|
+
_key: oldEngineBlock._key
|
|
18210
18233
|
}, "children", {
|
|
18211
18234
|
_key: oldChild._key
|
|
18212
18235
|
}]
|
|
18213
18236
|
});
|
|
18214
|
-
const prevSibling = currentBlockChildIndex > 0 ?
|
|
18215
|
-
prevSibling ?
|
|
18237
|
+
const prevSibling = currentBlockChildIndex > 0 ? oldEngineBlock.children[currentBlockChildIndex - 1] : void 0;
|
|
18238
|
+
prevSibling ? editorEngine.apply({
|
|
18216
18239
|
type: "insert",
|
|
18217
18240
|
path: [{
|
|
18218
|
-
_key:
|
|
18241
|
+
_key: oldEngineBlock._key
|
|
18219
18242
|
}, "children", {
|
|
18220
18243
|
_key: prevSibling._key
|
|
18221
18244
|
}],
|
|
18222
18245
|
node: currentBlockChild,
|
|
18223
18246
|
position: "after"
|
|
18224
|
-
}) :
|
|
18247
|
+
}) : editorEngine.apply({
|
|
18225
18248
|
type: "insert",
|
|
18226
18249
|
path: [{
|
|
18227
|
-
_key:
|
|
18250
|
+
_key: oldEngineBlock._key
|
|
18228
18251
|
}, "children", 0],
|
|
18229
18252
|
node: currentBlockChild,
|
|
18230
18253
|
position: "before"
|
|
18231
|
-
}),
|
|
18254
|
+
}), editorEngine.onChange();
|
|
18232
18255
|
} else if (!oldBlockChild) {
|
|
18233
18256
|
debug.syncValue("Inserting new child", currentBlockChild);
|
|
18234
|
-
const prevChild = currentBlockChildIndex > 0 ?
|
|
18235
|
-
prevChild ?
|
|
18257
|
+
const prevChild = currentBlockChildIndex > 0 ? engineBlock.children[currentBlockChildIndex - 1] : void 0;
|
|
18258
|
+
prevChild ? editorEngine.apply({
|
|
18236
18259
|
type: "insert",
|
|
18237
18260
|
path: [{
|
|
18238
|
-
_key:
|
|
18261
|
+
_key: oldEngineBlock._key
|
|
18239
18262
|
}, "children", {
|
|
18240
18263
|
_key: prevChild._key
|
|
18241
18264
|
}],
|
|
18242
18265
|
node: currentBlockChild,
|
|
18243
18266
|
position: "after"
|
|
18244
|
-
}) :
|
|
18267
|
+
}) : editorEngine.apply({
|
|
18245
18268
|
type: "insert",
|
|
18246
18269
|
path: [{
|
|
18247
|
-
_key:
|
|
18270
|
+
_key: oldEngineBlock._key
|
|
18248
18271
|
}, "children", 0],
|
|
18249
18272
|
node: currentBlockChild,
|
|
18250
18273
|
position: "before"
|
|
18251
|
-
}),
|
|
18274
|
+
}), editorEngine.onChange();
|
|
18252
18275
|
}
|
|
18253
18276
|
}
|
|
18254
18277
|
});
|
|
@@ -18258,23 +18281,23 @@ function createInternalEditor(config) {
|
|
|
18258
18281
|
debug.setup("creating new editor instance");
|
|
18259
18282
|
const subscriptions = [], editorActor = createActor(editorMachine, {
|
|
18260
18283
|
input: editorConfigToMachineInput(config)
|
|
18261
|
-
}), relayActor = createActor(relayMachine),
|
|
18284
|
+
}), relayActor = createActor(relayMachine), editorEngine = createEditorEngine({
|
|
18262
18285
|
editorActor,
|
|
18263
18286
|
relayActor,
|
|
18264
18287
|
subscriptions
|
|
18265
|
-
}), editable = createEditableAPI(
|
|
18288
|
+
}), editable = createEditableAPI(editorEngine, editorActor), {
|
|
18266
18289
|
mutationActor,
|
|
18267
18290
|
syncActor
|
|
18268
18291
|
} = createActors({
|
|
18269
18292
|
editorActor,
|
|
18270
18293
|
relayActor,
|
|
18271
|
-
|
|
18294
|
+
editorEngine,
|
|
18272
18295
|
subscriptions
|
|
18273
18296
|
}), editor = {
|
|
18274
|
-
dom: createEditorDom((event) => editorActor.send(event),
|
|
18297
|
+
dom: createEditorDom((event) => editorActor.send(event), editorEngine),
|
|
18275
18298
|
getSnapshot: () => getEditorSnapshot({
|
|
18276
18299
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
18277
|
-
|
|
18300
|
+
editorEngineInstance: editorEngine
|
|
18278
18301
|
}),
|
|
18279
18302
|
registerBehavior: (behaviorConfig) => {
|
|
18280
18303
|
const priority = createEditorPriority({
|
|
@@ -18318,7 +18341,7 @@ function createInternalEditor(config) {
|
|
|
18318
18341
|
default:
|
|
18319
18342
|
editorActor.send(rerouteExternalBehaviorEvent({
|
|
18320
18343
|
event,
|
|
18321
|
-
|
|
18344
|
+
editorEngine
|
|
18322
18345
|
}));
|
|
18323
18346
|
}
|
|
18324
18347
|
},
|
|
@@ -18360,7 +18383,7 @@ function createInternalEditor(config) {
|
|
|
18360
18383
|
},
|
|
18361
18384
|
editor,
|
|
18362
18385
|
editable,
|
|
18363
|
-
|
|
18386
|
+
editorEngine,
|
|
18364
18387
|
subscriptions
|
|
18365
18388
|
};
|
|
18366
18389
|
}
|
|
@@ -18382,7 +18405,7 @@ function createActors(config) {
|
|
|
18382
18405
|
"edit mode": "read only"
|
|
18383
18406
|
}),
|
|
18384
18407
|
schema: config.editorActor.getSnapshot().context.schema,
|
|
18385
|
-
|
|
18408
|
+
editorEngine: config.editorEngine
|
|
18386
18409
|
}
|
|
18387
18410
|
}), syncActor = createActor(syncMachine, {
|
|
18388
18411
|
input: {
|
|
@@ -18392,7 +18415,7 @@ function createActors(config) {
|
|
|
18392
18415
|
"edit mode": "read only"
|
|
18393
18416
|
}),
|
|
18394
18417
|
schema: config.editorActor.getSnapshot().context.schema,
|
|
18395
|
-
|
|
18418
|
+
editorEngine: config.editorEngine
|
|
18396
18419
|
}
|
|
18397
18420
|
});
|
|
18398
18421
|
return config.subscriptions.push(() => {
|
|
@@ -18421,7 +18444,7 @@ function createActors(config) {
|
|
|
18421
18444
|
config.editorActor.send({
|
|
18422
18445
|
...event,
|
|
18423
18446
|
type: "internal.patch",
|
|
18424
|
-
value: config.
|
|
18447
|
+
value: config.editorEngine.children
|
|
18425
18448
|
});
|
|
18426
18449
|
break;
|
|
18427
18450
|
default:
|
|
@@ -18483,7 +18506,7 @@ class PortableTextEditor {
|
|
|
18483
18506
|
* A lookup table for all the relevant schema types for this portable text type.
|
|
18484
18507
|
*/
|
|
18485
18508
|
/*
|
|
18486
|
-
* The editor API (
|
|
18509
|
+
* The editor API (the engine).
|
|
18487
18510
|
*/
|
|
18488
18511
|
constructor(config) {
|
|
18489
18512
|
this.schemaTypes = config.editorActor.getSnapshot().context.schema, this.editable = config.editable;
|
|
@@ -18875,25 +18898,25 @@ function EditorProvider(props) {
|
|
|
18875
18898
|
portableTextEditor: portableTextEditor_0
|
|
18876
18899
|
} = t1;
|
|
18877
18900
|
let t2;
|
|
18878
|
-
$[2] !== internalEditor_0.actors.editorActor || $[3] !== internalEditor_0.actors.mutationActor || $[4] !== internalEditor_0.actors.relayActor || $[5] !== internalEditor_0.actors.syncActor || $[6] !== internalEditor_0.
|
|
18901
|
+
$[2] !== internalEditor_0.actors.editorActor || $[3] !== internalEditor_0.actors.mutationActor || $[4] !== internalEditor_0.actors.relayActor || $[5] !== internalEditor_0.actors.syncActor || $[6] !== internalEditor_0.editorEngine || $[7] !== internalEditor_0.subscriptions ? (t2 = () => {
|
|
18879
18902
|
const unsubscribers = [];
|
|
18880
18903
|
for (const subscription of internalEditor_0.subscriptions)
|
|
18881
18904
|
unsubscribers.push(subscription());
|
|
18882
18905
|
return internalEditor_0.actors.editorActor.start(), internalEditor_0.actors.editorActor.send({
|
|
18883
|
-
type: "add
|
|
18884
|
-
editor: internalEditor_0.
|
|
18906
|
+
type: "add editor engine",
|
|
18907
|
+
editor: internalEditor_0.editorEngine
|
|
18885
18908
|
}), internalEditor_0.actors.mutationActor.start(), internalEditor_0.actors.relayActor.start(), internalEditor_0.actors.syncActor.start(), () => {
|
|
18886
18909
|
for (const unsubscribe of unsubscribers)
|
|
18887
18910
|
unsubscribe();
|
|
18888
18911
|
stopActor(internalEditor_0.actors.editorActor), stopActor(internalEditor_0.actors.mutationActor), stopActor(internalEditor_0.actors.relayActor), stopActor(internalEditor_0.actors.syncActor);
|
|
18889
18912
|
};
|
|
18890
|
-
}, $[2] = internalEditor_0.actors.editorActor, $[3] = internalEditor_0.actors.mutationActor, $[4] = internalEditor_0.actors.relayActor, $[5] = internalEditor_0.actors.syncActor, $[6] = internalEditor_0.
|
|
18913
|
+
}, $[2] = internalEditor_0.actors.editorActor, $[3] = internalEditor_0.actors.mutationActor, $[4] = internalEditor_0.actors.relayActor, $[5] = internalEditor_0.actors.syncActor, $[6] = internalEditor_0.editorEngine, $[7] = internalEditor_0.subscriptions, $[8] = t2) : t2 = $[8];
|
|
18891
18914
|
let t3;
|
|
18892
18915
|
$[9] !== internalEditor_0 ? (t3 = [internalEditor_0], $[9] = internalEditor_0, $[10] = t3) : t3 = $[10], useEffect(t2, t3);
|
|
18893
18916
|
let t4;
|
|
18894
18917
|
$[11] !== portableTextEditor_0 || $[12] !== props.children ? (t4 = /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: portableTextEditor_0, children: props.children }), $[11] = portableTextEditor_0, $[12] = props.children, $[13] = t4) : t4 = $[13];
|
|
18895
18918
|
let t5;
|
|
18896
|
-
$[14] !== internalEditor_0.
|
|
18919
|
+
$[14] !== internalEditor_0.editorEngine || $[15] !== t4 ? (t5 = /* @__PURE__ */ jsx(Engine, { editor: internalEditor_0.editorEngine, children: t4 }), $[14] = internalEditor_0.editorEngine, $[15] = t4, $[16] = t5) : t5 = $[16];
|
|
18897
18920
|
let t6;
|
|
18898
18921
|
$[17] !== internalEditor_0.actors.relayActor || $[18] !== t5 ? (t6 = /* @__PURE__ */ jsx(RelayActorContext.Provider, { value: internalEditor_0.actors.relayActor, children: t5 }), $[17] = internalEditor_0.actors.relayActor, $[18] = t5, $[19] = t6) : t6 = $[19];
|
|
18899
18922
|
let t7;
|