@portabletext/editor 7.0.2 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-dts/behavior.types.action.d.ts +30 -30
- 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.slice-blocks.js +1 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.js +1318 -1313
- 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.js +1 -1
- package/package.json +2 -2
- package/lib/_chunks-es/get-ancestor.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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";
|
|
14
|
+
import rawDebug from "debug";
|
|
15
15
|
import { isEmptyTextBlock, getTextBlockText } from "./_chunks-es/util.is-empty-text-block.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";
|
|
@@ -21,222 +21,6 @@ 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 isPath(value) {
|
|
25
|
-
return Array.isArray(value) && (value.length === 0 || typeof value[0] == "number" || typeof value[0] == "string" || isKeyedSegment(value[0]));
|
|
26
|
-
}
|
|
27
|
-
const isObject = (value) => typeof value == "object" && value !== null;
|
|
28
|
-
function isPoint(value) {
|
|
29
|
-
return isObject(value) && typeof value.offset == "number" && isPath(value.path);
|
|
30
|
-
}
|
|
31
|
-
function isRange(value) {
|
|
32
|
-
return isObject(value) && isPoint(value.anchor) && isPoint(value.focus);
|
|
33
|
-
}
|
|
34
|
-
const EDITOR_BRAND = /* @__PURE__ */ Symbol.for("slate-editor");
|
|
35
|
-
function isEditor(value) {
|
|
36
|
-
return isObject(value) && value[EDITOR_BRAND] === !0;
|
|
37
|
-
}
|
|
38
|
-
function point(editor, at, options = {}) {
|
|
39
|
-
const {
|
|
40
|
-
edge = "start"
|
|
41
|
-
} = options;
|
|
42
|
-
if (isPath(at)) {
|
|
43
|
-
let path2;
|
|
44
|
-
const deepest = getLeaf(editor, at, {
|
|
45
|
-
edge: edge === "end" ? "end" : "start"
|
|
46
|
-
});
|
|
47
|
-
if (!deepest)
|
|
48
|
-
throw new Error(`Cannot get the ${edge} point in the node at path [${at}] because it has no ${edge} text node.`);
|
|
49
|
-
const {
|
|
50
|
-
node,
|
|
51
|
-
path: nodePath
|
|
52
|
-
} = deepest;
|
|
53
|
-
if (path2 = nodePath, !isSpan({
|
|
54
|
-
schema: editor.schema
|
|
55
|
-
}, node) && !isTextBlockNode({
|
|
56
|
-
schema: editor.schema
|
|
57
|
-
}, node) && !isEditor(node))
|
|
58
|
-
return {
|
|
59
|
-
path: path2,
|
|
60
|
-
offset: 0
|
|
61
|
-
};
|
|
62
|
-
if (!isSpan({
|
|
63
|
-
schema: editor.schema
|
|
64
|
-
}, node))
|
|
65
|
-
throw new Error(`Cannot get the ${edge} point in the node at path [${at}] because it has no ${edge} text node.`);
|
|
66
|
-
return {
|
|
67
|
-
path: path2,
|
|
68
|
-
offset: edge === "end" ? node.text.length : 0
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
if (isRange(at)) {
|
|
72
|
-
const [start2, end2] = rangeEdges(at, editor);
|
|
73
|
-
return edge === "start" ? start2 : end2;
|
|
74
|
-
}
|
|
75
|
-
return at;
|
|
76
|
-
}
|
|
77
|
-
function end(editor, at) {
|
|
78
|
-
return point(editor, at, {
|
|
79
|
-
edge: "end"
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function start(editor, at) {
|
|
83
|
-
return point(editor, at, {
|
|
84
|
-
edge: "start"
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
function pathEquals(path2, another) {
|
|
88
|
-
if (path2.length !== another.length)
|
|
89
|
-
return !1;
|
|
90
|
-
for (let i = 0; i < path2.length; i++) {
|
|
91
|
-
const segment = path2[i], otherSegment = another[i];
|
|
92
|
-
if (isKeyedSegment(segment) && isKeyedSegment(otherSegment)) {
|
|
93
|
-
if (segment._key !== otherSegment._key)
|
|
94
|
-
return !1;
|
|
95
|
-
} else if (segment !== otherSegment)
|
|
96
|
-
return !1;
|
|
97
|
-
}
|
|
98
|
-
return !0;
|
|
99
|
-
}
|
|
100
|
-
function pointEquals(point2, another) {
|
|
101
|
-
return point2.offset === another.offset && pathEquals(point2.path, another.path);
|
|
102
|
-
}
|
|
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
24
|
function serializePath(path2) {
|
|
241
25
|
return path2.reduce((result, segment, index) => isKeyedSegment(segment) ? `${result}[_key=="${segment._key}"]` : `${result}${index === 0 ? "" : "."}${segment}`, "");
|
|
242
26
|
}
|
|
@@ -264,7 +48,113 @@ function getDomNode(editor, path2) {
|
|
|
264
48
|
if (!(!(domNode instanceof HTMLElement) || domNode.closest("[data-pt-editor]") !== editorElement))
|
|
265
49
|
return domNode;
|
|
266
50
|
}
|
|
267
|
-
const
|
|
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=="(.+?)"\]/;
|
|
268
158
|
function deserializePath(serializedPath) {
|
|
269
159
|
const path2 = [];
|
|
270
160
|
let remaining = serializedPath;
|
|
@@ -285,6 +175,14 @@ function deserializePath(serializedPath) {
|
|
|
285
175
|
}
|
|
286
176
|
return path2;
|
|
287
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
|
+
}
|
|
288
186
|
function safeStringify(value, space) {
|
|
289
187
|
try {
|
|
290
188
|
return JSON.stringify(value, null, space);
|
|
@@ -328,6 +226,16 @@ function commonPath(path2, another) {
|
|
|
328
226
|
}
|
|
329
227
|
return common;
|
|
330
228
|
}
|
|
229
|
+
function isPath(value) {
|
|
230
|
+
return Array.isArray(value) && (value.length === 0 || typeof value[0] == "number" || typeof value[0] == "string" || isKeyedSegment(value[0]));
|
|
231
|
+
}
|
|
232
|
+
const isObject = (value) => typeof value == "object" && value !== null;
|
|
233
|
+
function isPoint(value) {
|
|
234
|
+
return isObject(value) && typeof value.offset == "number" && isPath(value.path);
|
|
235
|
+
}
|
|
236
|
+
function isRange(value) {
|
|
237
|
+
return isObject(value) && isPoint(value.anchor) && isPoint(value.focus);
|
|
238
|
+
}
|
|
331
239
|
function rangeEnd(range2, root) {
|
|
332
240
|
const [, end2] = rangeEdges(range2, root);
|
|
333
241
|
return end2;
|
|
@@ -358,11 +266,75 @@ function sliceToNodeDepth(nodePath, depth) {
|
|
|
358
266
|
}
|
|
359
267
|
return nodePath;
|
|
360
268
|
}
|
|
269
|
+
const EDITOR_BRAND = /* @__PURE__ */ Symbol.for("editor-engine");
|
|
270
|
+
function isEditor(value) {
|
|
271
|
+
return isObject(value) && value[EDITOR_BRAND] === !0;
|
|
272
|
+
}
|
|
273
|
+
function point(editor, at, options = {}) {
|
|
274
|
+
const {
|
|
275
|
+
edge = "start"
|
|
276
|
+
} = options;
|
|
277
|
+
if (isPath(at)) {
|
|
278
|
+
let path2;
|
|
279
|
+
const deepest = getLeaf(editor, at, {
|
|
280
|
+
edge: edge === "end" ? "end" : "start"
|
|
281
|
+
});
|
|
282
|
+
if (!deepest)
|
|
283
|
+
throw new Error(`Cannot get the ${edge} point in the node at path [${at}] because it has no ${edge} text node.`);
|
|
284
|
+
const {
|
|
285
|
+
node,
|
|
286
|
+
path: nodePath
|
|
287
|
+
} = deepest;
|
|
288
|
+
if (path2 = nodePath, !isSpan({
|
|
289
|
+
schema: editor.schema
|
|
290
|
+
}, node) && !isTextBlockNode({
|
|
291
|
+
schema: editor.schema
|
|
292
|
+
}, node) && !isEditor(node))
|
|
293
|
+
return {
|
|
294
|
+
path: path2,
|
|
295
|
+
offset: 0
|
|
296
|
+
};
|
|
297
|
+
if (!isSpan({
|
|
298
|
+
schema: editor.schema
|
|
299
|
+
}, node))
|
|
300
|
+
throw new Error(`Cannot get the ${edge} point in the node at path [${at}] because it has no ${edge} text node.`);
|
|
301
|
+
return {
|
|
302
|
+
path: path2,
|
|
303
|
+
offset: edge === "end" ? node.text.length : 0
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
if (isRange(at)) {
|
|
307
|
+
const [start2, end2] = rangeEdges(at, editor);
|
|
308
|
+
return edge === "start" ? start2 : end2;
|
|
309
|
+
}
|
|
310
|
+
return at;
|
|
311
|
+
}
|
|
312
|
+
function start(editor, at) {
|
|
313
|
+
return point(editor, at, {
|
|
314
|
+
edge: "start"
|
|
315
|
+
});
|
|
316
|
+
}
|
|
361
317
|
function isVoidNode(snapshot, node, path2) {
|
|
362
318
|
return isObjectNode({
|
|
363
319
|
schema: snapshot.context.schema
|
|
364
320
|
}, node) && !isEditableContainer(snapshot, node, path2);
|
|
365
321
|
}
|
|
322
|
+
function pathEquals(path2, another) {
|
|
323
|
+
if (path2.length !== another.length)
|
|
324
|
+
return !1;
|
|
325
|
+
for (let i = 0; i < path2.length; i++) {
|
|
326
|
+
const segment = path2[i], otherSegment = another[i];
|
|
327
|
+
if (isKeyedSegment(segment) && isKeyedSegment(otherSegment)) {
|
|
328
|
+
if (segment._key !== otherSegment._key)
|
|
329
|
+
return !1;
|
|
330
|
+
} else if (segment !== otherSegment)
|
|
331
|
+
return !1;
|
|
332
|
+
}
|
|
333
|
+
return !0;
|
|
334
|
+
}
|
|
335
|
+
function pointEquals(point2, another) {
|
|
336
|
+
return point2.offset === another.offset && pathEquals(point2.path, another.path);
|
|
337
|
+
}
|
|
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
|
|
@@ -665,18 +637,18 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
665
637
|
if (anchorNode == null || focusNode == null || anchorOffset == null || focusOffset == null) {
|
|
666
638
|
if (suppressThrow)
|
|
667
639
|
return null;
|
|
668
|
-
throw new Error(`Cannot
|
|
640
|
+
throw new Error(`Cannot map DOM range to an editor selection: ${domRange}`);
|
|
669
641
|
}
|
|
670
642
|
IS_FIREFOX && focusNode.textContent?.endsWith(`
|
|
671
643
|
|
|
672
644
|
`) && focusOffset === focusNode.textContent.length && focusOffset--;
|
|
673
|
-
const anchor = DOMEditor.
|
|
645
|
+
const anchor = DOMEditor.toSelectionPoint(editor, [anchorNode, anchorOffset], {
|
|
674
646
|
exactMatch,
|
|
675
647
|
suppressThrow
|
|
676
648
|
});
|
|
677
649
|
if (!anchor)
|
|
678
650
|
return null;
|
|
679
|
-
const focusBeforeAnchor = isBefore(anchorNode, focusNode) || anchorNode === focusNode && focusOffset < anchorOffset, focus = isCollapsed ? anchor : DOMEditor.
|
|
651
|
+
const focusBeforeAnchor = isBefore(anchorNode, focusNode) || anchorNode === focusNode && focusOffset < anchorOffset, focus = isCollapsed ? anchor : DOMEditor.toSelectionPoint(editor, [focusNode, focusOffset], {
|
|
680
652
|
exactMatch,
|
|
681
653
|
suppressThrow,
|
|
682
654
|
searchDirection: focusBeforeAnchor ? "forward" : "backward"
|
|
@@ -686,286 +658,7 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
686
658
|
focus
|
|
687
659
|
} : null;
|
|
688
660
|
}
|
|
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
661
|
};
|
|
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;
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
function isEventContainer(slateEditor, eventNode, eventPath) {
|
|
967
|
-
return isEditor(eventNode) ? !0 : isEditableContainer(slateEditor, eventNode, eventPath);
|
|
968
|
-
}
|
|
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
|
}
|
|
@@ -1672,57 +1370,52 @@ function transformPoint$1(point2, op, options = {}) {
|
|
|
1672
1370
|
const {
|
|
1673
1371
|
affinity = "forward"
|
|
1674
1372
|
} = options;
|
|
1675
|
-
let {
|
|
1676
|
-
path: path2,
|
|
1677
|
-
offset
|
|
1678
|
-
} = point2;
|
|
1679
1373
|
switch (op.type) {
|
|
1680
|
-
case "insert_text":
|
|
1681
|
-
pathEquals(op.path,
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1374
|
+
case "insert_text":
|
|
1375
|
+
return pathEquals(op.path, point2.path) && (op.offset < point2.offset || op.offset === point2.offset && affinity === "forward") ? {
|
|
1376
|
+
path: point2.path,
|
|
1377
|
+
offset: point2.offset + op.text.length
|
|
1378
|
+
} : point2;
|
|
1379
|
+
case "remove_text":
|
|
1380
|
+
return pathEquals(op.path, point2.path) && op.offset <= point2.offset ? {
|
|
1381
|
+
path: point2.path,
|
|
1382
|
+
offset: point2.offset - Math.min(point2.offset - op.offset, op.text.length)
|
|
1383
|
+
} : point2;
|
|
1688
1384
|
case "set": {
|
|
1689
1385
|
const propertyName = op.path[op.path.length - 1], nodePath = op.path.slice(0, -1);
|
|
1386
|
+
let path2 = point2.path, offset = point2.offset;
|
|
1690
1387
|
if (propertyName === "_key" && typeof op.value == "string") {
|
|
1691
1388
|
const oldKey = op.inverse?.type === "set" && typeof op.inverse.value == "string" ? op.inverse.value : void 0;
|
|
1692
1389
|
if (oldKey) {
|
|
1693
|
-
|
|
1694
|
-
let
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
isKeyedSegment(segment) && segment._key === oldKey && (newPath[i] = {
|
|
1390
|
+
let newPath;
|
|
1391
|
+
for (let i = 0; i < path2.length; i++) {
|
|
1392
|
+
const segment = path2[i];
|
|
1393
|
+
isKeyedSegment(segment) && segment._key === oldKey && (newPath === void 0 && (newPath = [...path2]), newPath[i] = {
|
|
1698
1394
|
_key: op.value
|
|
1699
|
-
}
|
|
1395
|
+
});
|
|
1700
1396
|
}
|
|
1701
|
-
|
|
1397
|
+
newPath !== void 0 && (path2 = newPath);
|
|
1702
1398
|
}
|
|
1703
1399
|
}
|
|
1704
|
-
propertyName === "text" && pathEquals(nodePath, path2) && (op.value == null || typeof op.value != "string" ? offset = 0 : offset > op.value.length && (offset = op.value.length))
|
|
1705
|
-
|
|
1400
|
+
return propertyName === "text" && pathEquals(nodePath, path2) && (op.value == null || typeof op.value != "string" ? offset = 0 : offset > op.value.length && (offset = op.value.length)), path2 === point2.path && offset === point2.offset ? point2 : {
|
|
1401
|
+
path: path2,
|
|
1402
|
+
offset
|
|
1403
|
+
};
|
|
1706
1404
|
}
|
|
1707
1405
|
case "unset": {
|
|
1708
1406
|
const lastSegment = op.path[op.path.length - 1];
|
|
1709
|
-
if (isKeyedSegment(lastSegment))
|
|
1710
|
-
|
|
1711
|
-
return null;
|
|
1712
|
-
break;
|
|
1713
|
-
}
|
|
1407
|
+
if (isKeyedSegment(lastSegment))
|
|
1408
|
+
return pathEquals(op.path, point2.path) || isAncestorPath(op.path, point2.path) ? null : point2;
|
|
1714
1409
|
const propertyName = lastSegment, nodePath = op.path.slice(0, -1);
|
|
1715
|
-
propertyName === "text" && pathEquals(nodePath,
|
|
1716
|
-
|
|
1410
|
+
return propertyName === "text" && pathEquals(nodePath, point2.path) && point2.offset !== 0 ? {
|
|
1411
|
+
path: point2.path,
|
|
1412
|
+
offset: 0
|
|
1413
|
+
} : point2;
|
|
1717
1414
|
}
|
|
1718
1415
|
// set_selection: no transform needed
|
|
1719
1416
|
default:
|
|
1720
1417
|
return point2;
|
|
1721
1418
|
}
|
|
1722
|
-
return {
|
|
1723
|
-
path: path2,
|
|
1724
|
-
offset
|
|
1725
|
-
};
|
|
1726
1419
|
}
|
|
1727
1420
|
function verifyDiffState(editor, textDiff) {
|
|
1728
1421
|
const {
|
|
@@ -2052,12 +1745,12 @@ function createAndroidInputManager({
|
|
|
2052
1745
|
const data = event.dataTransfer || event.data || void 0;
|
|
2053
1746
|
insertPositionHint !== !1 && type !== "insertText" && type !== "insertCompositionText" && (insertPositionHint = !1);
|
|
2054
1747
|
let [nativeTargetRange] = event.getTargetRanges();
|
|
2055
|
-
nativeTargetRange && (targetRange2 = DOMEditor.
|
|
1748
|
+
nativeTargetRange && (targetRange2 = DOMEditor.toEditorSelection(editor, nativeTargetRange, {
|
|
2056
1749
|
exactMatch: !1,
|
|
2057
1750
|
suppressThrow: !0
|
|
2058
1751
|
}));
|
|
2059
1752
|
const domSelection = DOMEditor.getWindow(editor).getSelection();
|
|
2060
|
-
if (!targetRange2 && domSelection && (nativeTargetRange = domSelection, targetRange2 = DOMEditor.
|
|
1753
|
+
if (!targetRange2 && domSelection && (nativeTargetRange = domSelection, targetRange2 = DOMEditor.toEditorSelection(editor, domSelection, {
|
|
2061
1754
|
exactMatch: !1,
|
|
2062
1755
|
suppressThrow: !0
|
|
2063
1756
|
})), targetRange2 = targetRange2 ?? editor.selection, !targetRange2)
|
|
@@ -2442,7 +2135,7 @@ const MUTATION_OBSERVER_CONFIG$1 = {
|
|
|
2442
2135
|
}) => {
|
|
2443
2136
|
if (!IS_ANDROID)
|
|
2444
2137
|
return null;
|
|
2445
|
-
const editor =
|
|
2138
|
+
const editor = useEngineStatic(), isMounted = useIsMounted(), [inputManager] = useState(() => createAndroidInputManager({
|
|
2446
2139
|
editor,
|
|
2447
2140
|
editorActor,
|
|
2448
2141
|
...options
|
|
@@ -2586,7 +2279,7 @@ function isError(error) {
|
|
|
2586
2279
|
return error instanceof Error;
|
|
2587
2280
|
}
|
|
2588
2281
|
const DecorateContext = createContext({}), useDecorations = (node, path2, parentDecorations) => {
|
|
2589
|
-
const $ = c(11), editor =
|
|
2282
|
+
const $ = c(11), editor = useEngineStatic(), {
|
|
2590
2283
|
decorate,
|
|
2591
2284
|
addEventListener
|
|
2592
2285
|
} = useContext(DecorateContext);
|
|
@@ -2641,7 +2334,7 @@ const Element$1 = (props) => {
|
|
|
2641
2334
|
renderElement,
|
|
2642
2335
|
renderLeaf,
|
|
2643
2336
|
renderText
|
|
2644
|
-
} = props, dataPath = serializePath(props.path), editor =
|
|
2337
|
+
} = props, dataPath = serializePath(props.path), editor = useEngineStatic(), isInline$1 = isInline(editor, props.path), isInNewPipeline = useContext(NewPipelineContext), decorations = useDecorations(element, props.path, parentDecorations);
|
|
2645
2338
|
let t0;
|
|
2646
2339
|
$[0] !== decorations || $[1] !== element || $[2] !== props.path || $[3] !== renderElement || $[4] !== renderLeaf || $[5] !== renderText ? (t0 = {
|
|
2647
2340
|
decorations,
|
|
@@ -2957,14 +2650,14 @@ function getTextContent(editor, path2) {
|
|
|
2957
2650
|
}
|
|
2958
2651
|
return text;
|
|
2959
2652
|
}
|
|
2960
|
-
const
|
|
2653
|
+
const EngineString = (props) => {
|
|
2961
2654
|
const $ = c(6), {
|
|
2962
2655
|
isLast,
|
|
2963
2656
|
leaf,
|
|
2964
2657
|
parent,
|
|
2965
2658
|
path: path2,
|
|
2966
2659
|
text
|
|
2967
|
-
} = props, editor =
|
|
2660
|
+
} = props, editor = useEngineStatic(), parentPath$1 = parentPath(path2), leafText = leaf.text ?? "";
|
|
2968
2661
|
if (leafText === "" && isTextBlock({
|
|
2969
2662
|
schema: editor.schema
|
|
2970
2663
|
}, parent) && parent.children[parent.children.length - 1] === text && getTextContent(editor, parentPath$1) === "") {
|
|
@@ -3009,20 +2702,20 @@ const SlateString = (props) => {
|
|
|
3009
2702
|
})), ZeroWidthString = (props) => {
|
|
3010
2703
|
const $ = c(10), {
|
|
3011
2704
|
isLineBreak: t0
|
|
3012
|
-
} = props, isLineBreak = t0 === void 0 ? !1 : t0, isInNewPipeline = useContext(NewPipelineContext),
|
|
2705
|
+
} = props, isLineBreak = t0 === void 0 ? !1 : t0, isInNewPipeline = useContext(NewPipelineContext), engineValue = isLineBreak ? "n" : "z";
|
|
3013
2706
|
let t1;
|
|
3014
|
-
$[0] !==
|
|
2707
|
+
$[0] !== engineValue || $[1] !== isInNewPipeline || $[2] !== isLineBreak ? (t1 = isInNewPipeline ? {
|
|
3015
2708
|
"data-pt-zero-width": !0,
|
|
3016
2709
|
...isLineBreak ? {
|
|
3017
2710
|
"data-pt-line-break": !0
|
|
3018
2711
|
} : {}
|
|
3019
2712
|
} : {
|
|
3020
|
-
"data-slate-zero-width":
|
|
2713
|
+
"data-slate-zero-width": engineValue,
|
|
3021
2714
|
"data-pt-zero-width": !0,
|
|
3022
2715
|
...isLineBreak ? {
|
|
3023
2716
|
"data-pt-line-break": !0
|
|
3024
2717
|
} : {}
|
|
3025
|
-
}, $[0] =
|
|
2718
|
+
}, $[0] = engineValue, $[1] = isInNewPipeline, $[2] = isLineBreak, $[3] = t1) : t1 = $[3];
|
|
3026
2719
|
const attributes = t1, t2 = !IS_ANDROID || !isLineBreak ? "\uFEFF" : null;
|
|
3027
2720
|
let t3;
|
|
3028
2721
|
$[4] !== isLineBreak ? (t3 = isLineBreak ? /* @__PURE__ */ jsx("br", {}) : null, $[4] = isLineBreak, $[5] = t3) : t3 = $[5];
|
|
@@ -3042,7 +2735,7 @@ const SlateString = (props) => {
|
|
|
3042
2735
|
leafPosition
|
|
3043
2736
|
} = props, renderLeaf = t0 === void 0 ? defaultRenderLeaf : t0, isInNewPipeline = useContext(NewPipelineContext);
|
|
3044
2737
|
let t1;
|
|
3045
|
-
$[0] !== isLast || $[1] !== leaf || $[2] !== parent || $[3] !== path2 || $[4] !== text ? (t1 = /* @__PURE__ */ jsx(
|
|
2738
|
+
$[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
2739
|
const children = t1;
|
|
3047
2740
|
let t2;
|
|
3048
2741
|
return $[6] !== children || $[7] !== isInNewPipeline || $[8] !== leaf || $[9] !== leafPosition || $[10] !== path2 || $[11] !== renderLeaf || $[12] !== text ? (t2 = renderLeaf({
|
|
@@ -3139,7 +2832,7 @@ const useChildren = (props) => {
|
|
|
3139
2832
|
renderElement,
|
|
3140
2833
|
renderText,
|
|
3141
2834
|
renderLeaf
|
|
3142
|
-
} = props, editor =
|
|
2835
|
+
} = props, editor = useEngineStatic();
|
|
3143
2836
|
editor.isNodeMapDirty = !1;
|
|
3144
2837
|
const parentContainer = useParentContainer(), parentIsInNewPipeline = useContext(NewPipelineContext), decorationsByChild = useDecorationsByChild(editor, node, parentPath2, decorations);
|
|
3145
2838
|
let children = [], arrayFieldName = "children", childContainer = parentContainer;
|
|
@@ -3237,14 +2930,14 @@ const useChildren = (props) => {
|
|
|
3237
2930
|
throw new Error("Unexpected node type");
|
|
3238
2931
|
});
|
|
3239
2932
|
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(
|
|
2933
|
+
}, EngineSelectorContext = createContext({}), refEquality = (a, b) => a === b;
|
|
2934
|
+
function useEngineSelector(selector, equalityFn = refEquality) {
|
|
2935
|
+
const context = useContext(EngineSelectorContext);
|
|
3243
2936
|
if (!context)
|
|
3244
|
-
throw new Error("The `
|
|
2937
|
+
throw new Error("The `useEngineSelector` hook must be used inside the <Engine> component's context.");
|
|
3245
2938
|
const {
|
|
3246
2939
|
addEventListener
|
|
3247
|
-
} = context, editor =
|
|
2940
|
+
} = context, editor = useEngineStatic(), genericSelector = useCallback(() => selector(editor), [editor, selector]), [selectedState, update] = useGenericSelector(genericSelector, equalityFn);
|
|
3248
2941
|
return useIsomorphicLayoutEffect(() => {
|
|
3249
2942
|
const unsubscribe = addEventListener(update);
|
|
3250
2943
|
return update(), unsubscribe;
|
|
@@ -3273,19 +2966,19 @@ function useSelectorContext() {
|
|
|
3273
2966
|
function useFlushDeferredSelectorsOnRender() {
|
|
3274
2967
|
const {
|
|
3275
2968
|
flushDeferred
|
|
3276
|
-
} = useContext(
|
|
2969
|
+
} = useContext(EngineSelectorContext);
|
|
3277
2970
|
useIsomorphicLayoutEffect(flushDeferred);
|
|
3278
2971
|
}
|
|
3279
|
-
const
|
|
2972
|
+
const useEngine = () => {
|
|
3280
2973
|
const {
|
|
3281
2974
|
addEventListener
|
|
3282
|
-
} = useContext(
|
|
2975
|
+
} = useContext(EngineSelectorContext), [, forceRender] = useReducer((s) => s + 1, 0);
|
|
3283
2976
|
if (!addEventListener)
|
|
3284
|
-
throw new Error("The `
|
|
3285
|
-
return useIsomorphicLayoutEffect(() => addEventListener(forceRender), [addEventListener]),
|
|
2977
|
+
throw new Error("The `useEngine` hook must be used inside the <Engine> component's context.");
|
|
2978
|
+
return useIsomorphicLayoutEffect(() => addEventListener(forceRender), [addEventListener]), useEngineStatic();
|
|
3286
2979
|
};
|
|
3287
2980
|
function useTrackUserInput() {
|
|
3288
|
-
const editor =
|
|
2981
|
+
const editor = useEngineStatic(), receivedUserInput = useRef(!1), animationFrameIdRef = useRef(0), onUserInput = useCallback(() => {
|
|
3289
2982
|
if (receivedUserInput.current)
|
|
3290
2983
|
return;
|
|
3291
2984
|
receivedUserInput.current = !0;
|
|
@@ -3423,7 +3116,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3423
3116
|
scrollSelectionIntoView = defaultScrollSelectionIntoView,
|
|
3424
3117
|
style: userStyle = {},
|
|
3425
3118
|
...attributes
|
|
3426
|
-
} = props, editor =
|
|
3119
|
+
} = props, editor = useEngine(), ref = useRef(null), deferredOperations = useRef([]), processing = useRef(!1), {
|
|
3427
3120
|
onUserInput,
|
|
3428
3121
|
receivedUserInput
|
|
3429
3122
|
} = useTrackUserInput(), [, forceRender] = useReducer((s) => s + 1, 0);
|
|
@@ -3469,7 +3162,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3469
3162
|
focusNode
|
|
3470
3163
|
} = domSelection, anchorNodeSelectable = DOMEditor.hasEditableTarget(editor, anchorNode) || DOMEditor.isTargetInsideNonReadonlyVoid(editor, anchorNode), focusNodeInEditor = DOMEditor.hasTarget(editor, focusNode);
|
|
3471
3164
|
if (anchorNodeSelectable && focusNodeInEditor) {
|
|
3472
|
-
const range2 = DOMEditor.
|
|
3165
|
+
const range2 = DOMEditor.toEditorSelection(editor, domSelection, {
|
|
3473
3166
|
exactMatch: !1,
|
|
3474
3167
|
suppressThrow: !0
|
|
3475
3168
|
});
|
|
@@ -3505,17 +3198,17 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3505
3198
|
const editorElement = editor.domElement;
|
|
3506
3199
|
let hasDomSelectionInEditor = !1;
|
|
3507
3200
|
if (containsShadowAware(editorElement, anchorNode) && containsShadowAware(editorElement, focusNode) && (hasDomSelectionInEditor = !0), hasDomSelection && hasDomSelectionInEditor && selection && !forceChange) {
|
|
3508
|
-
const
|
|
3201
|
+
const editorSelection = DOMEditor.toEditorSelection(editor, domSelection, {
|
|
3509
3202
|
exactMatch: !0,
|
|
3510
|
-
// domSelection is not necessarily a valid
|
|
3203
|
+
// domSelection is not necessarily a valid range
|
|
3511
3204
|
// (e.g. when clicking on contentEditable:false element)
|
|
3512
3205
|
suppressThrow: !0
|
|
3513
3206
|
});
|
|
3514
|
-
if (
|
|
3207
|
+
if (editorSelection && rangeEquals(editorSelection, selection))
|
|
3515
3208
|
return;
|
|
3516
3209
|
}
|
|
3517
3210
|
if (selection && !DOMEditor.hasRange(editor, selection)) {
|
|
3518
|
-
const fallbackRange = DOMEditor.
|
|
3211
|
+
const fallbackRange = DOMEditor.toEditorSelection(editor, domSelection, {
|
|
3519
3212
|
exactMatch: !1,
|
|
3520
3213
|
suppressThrow: !0
|
|
3521
3214
|
});
|
|
@@ -3571,11 +3264,11 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3571
3264
|
if (processing?.current && IS_WEBKIT && root instanceof ShadowRoot) {
|
|
3572
3265
|
const range2 = event.getTargetRanges()[0], newRange = new window.Range();
|
|
3573
3266
|
newRange.setStart(range2.startContainer, range2.startOffset), newRange.setEnd(range2.endContainer, range2.endOffset);
|
|
3574
|
-
const
|
|
3267
|
+
const editorSelection = DOMEditor.toEditorSelection(editor, newRange, {
|
|
3575
3268
|
exactMatch: !1,
|
|
3576
3269
|
suppressThrow: !1
|
|
3577
3270
|
});
|
|
3578
|
-
editor.select(
|
|
3271
|
+
editor.select(editorSelection), event.preventDefault(), event.stopImmediatePropagation();
|
|
3579
3272
|
return;
|
|
3580
3273
|
}
|
|
3581
3274
|
if (onUserInput(), !readOnly && DOMEditor.hasEditableTarget(editor, event.target) && !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
|
|
@@ -3612,7 +3305,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3612
3305
|
if ((!type.startsWith("delete") || type.startsWith("deleteBy")) && !editor.isNodeMapDirty) {
|
|
3613
3306
|
const [targetRange2] = event.getTargetRanges();
|
|
3614
3307
|
if (targetRange2) {
|
|
3615
|
-
const range2 = DOMEditor.
|
|
3308
|
+
const range2 = DOMEditor.toEditorSelection(editor, targetRange2, {
|
|
3616
3309
|
exactMatch: !1,
|
|
3617
3310
|
suppressThrow: !1
|
|
3618
3311
|
});
|
|
@@ -4212,57 +3905,360 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
4212
3905
|
}
|
|
4213
3906
|
}
|
|
4214
3907
|
}
|
|
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;
|
|
3908
|
+
}, [readOnly, editor, editorActor, attributes.onKeyDown]),
|
|
3909
|
+
onPaste: useCallback((event) => {
|
|
3910
|
+
!readOnly && DOMEditor.hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onPaste) && (!HAS_BEFORE_INPUT_SUPPORT || isPlainTextOnlyPaste(event.nativeEvent) || IS_WEBKIT) && (event.preventDefault(), editorActor.send({
|
|
3911
|
+
type: "behavior event",
|
|
3912
|
+
behaviorEvent: {
|
|
3913
|
+
type: "input.*",
|
|
3914
|
+
originEvent: {
|
|
3915
|
+
dataTransfer: event.clipboardData
|
|
3916
|
+
}
|
|
3917
|
+
},
|
|
3918
|
+
editor
|
|
3919
|
+
}));
|
|
3920
|
+
}, [readOnly, editor, editorActor, attributes.onPaste]),
|
|
3921
|
+
children: /* @__PURE__ */ jsx(Children, { decorations, node: editor, path: [], renderElement, renderLeaf, renderText })
|
|
3922
|
+
}
|
|
3923
|
+
) }) }) });
|
|
3924
|
+
}), defaultDecorate = () => [], defaultScrollSelectionIntoView = (editor, domRange) => {
|
|
3925
|
+
const isBackward = !!editor.selection && isBackwardRange(editor.selection, editor), domFocusPoint = domRange.cloneRange();
|
|
3926
|
+
if (domFocusPoint.collapse(isBackward), domFocusPoint.getBoundingClientRect) {
|
|
3927
|
+
const leafEl = domFocusPoint.startContainer.parentElement, domRect = domFocusPoint.getBoundingClientRect();
|
|
3928
|
+
if (domRect.width === 0 && domRect.height === 0 && domRect.x === 0 && domRect.y === 0) {
|
|
3929
|
+
const leafRect = leafEl.getBoundingClientRect();
|
|
3930
|
+
if (leafRect.width > 0 || leafRect.height > 0)
|
|
3931
|
+
return;
|
|
3932
|
+
}
|
|
3933
|
+
leafEl.getBoundingClientRect = domFocusPoint.getBoundingClientRect.bind(domFocusPoint), scrollIntoView(leafEl, {
|
|
3934
|
+
scrollMode: "if-needed"
|
|
3935
|
+
}), delete leafEl.getBoundingClientRect;
|
|
3936
|
+
}
|
|
3937
|
+
}, 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) => {
|
|
3938
|
+
if (event.inputType === "historyUndo") {
|
|
3939
|
+
editorActor.send({
|
|
3940
|
+
type: "behavior event",
|
|
3941
|
+
behaviorEvent: {
|
|
3942
|
+
type: "history.undo"
|
|
3943
|
+
},
|
|
3944
|
+
editor
|
|
3945
|
+
});
|
|
3946
|
+
return;
|
|
3947
|
+
}
|
|
3948
|
+
if (event.inputType === "historyRedo") {
|
|
3949
|
+
editorActor.send({
|
|
3950
|
+
type: "behavior event",
|
|
3951
|
+
behaviorEvent: {
|
|
3952
|
+
type: "history.redo"
|
|
3953
|
+
},
|
|
3954
|
+
editor
|
|
3955
|
+
});
|
|
3956
|
+
return;
|
|
3957
|
+
}
|
|
3958
|
+
};
|
|
3959
|
+
function resolveSelection(editor, selection) {
|
|
3960
|
+
if (!selection)
|
|
3961
|
+
return null;
|
|
3962
|
+
if (isEqualSelectionPoints(selection.anchor, selection.focus)) {
|
|
3963
|
+
const anchorPoint2 = resolveSelectionPoint(editor, selection.anchor, selection.backward ? "backward" : "forward");
|
|
3964
|
+
return anchorPoint2 ? {
|
|
3965
|
+
anchor: anchorPoint2,
|
|
3966
|
+
focus: anchorPoint2
|
|
3967
|
+
} : null;
|
|
3968
|
+
}
|
|
3969
|
+
const anchorPoint = resolveSelectionPoint(editor, selection.anchor, selection.backward ? "forward" : "backward"), focusPoint = resolveSelectionPoint(editor, selection.focus, selection.backward ? "backward" : "forward");
|
|
3970
|
+
return !anchorPoint || !focusPoint ? null : {
|
|
3971
|
+
anchor: anchorPoint,
|
|
3972
|
+
focus: focusPoint
|
|
3973
|
+
};
|
|
3974
|
+
}
|
|
3975
|
+
function resolveSelectionPoint(editor, selectionPoint, direction) {
|
|
3976
|
+
const snapshot = {
|
|
3977
|
+
context: {
|
|
3978
|
+
schema: editor.schema,
|
|
3979
|
+
containers: editor.publicContainers,
|
|
3980
|
+
value: editor.children
|
|
3981
|
+
},
|
|
3982
|
+
blockIndexMap: editor.blockIndexMap
|
|
3983
|
+
}, entry = getNode(snapshot, selectionPoint.path);
|
|
3984
|
+
if (entry) {
|
|
3985
|
+
if (getChildren(snapshot, entry.path).length === 0)
|
|
3986
|
+
return {
|
|
3987
|
+
path: entry.path,
|
|
3988
|
+
offset: isSpan({
|
|
3989
|
+
schema: editor.schema
|
|
3990
|
+
}, entry.node) ? Math.min(entry.node.text.length, selectionPoint.offset) : 0
|
|
3991
|
+
};
|
|
3992
|
+
const isBlockLevelPath = isBlock(snapshot, selectionPoint.path);
|
|
3993
|
+
if (isTextBlock({
|
|
3994
|
+
schema: editor.schema
|
|
3995
|
+
}, entry.node) && isBlockLevelPath) {
|
|
3996
|
+
const spanPoint = blockOffsetToSpanSelectionPoint({
|
|
3997
|
+
snapshot,
|
|
3998
|
+
blockOffset: {
|
|
3999
|
+
path: entry.path,
|
|
4000
|
+
offset: selectionPoint.offset
|
|
4001
|
+
},
|
|
4002
|
+
direction
|
|
4003
|
+
});
|
|
4004
|
+
if (spanPoint)
|
|
4005
|
+
return spanPoint;
|
|
4006
|
+
}
|
|
4007
|
+
const leaf2 = getLeaf(snapshot, entry.path, {
|
|
4008
|
+
edge: direction === "forward" ? "start" : "end"
|
|
4009
|
+
});
|
|
4010
|
+
return leaf2 ? {
|
|
4011
|
+
path: leaf2.path,
|
|
4012
|
+
offset: 0
|
|
4013
|
+
} : {
|
|
4014
|
+
path: entry.path,
|
|
4015
|
+
offset: 0
|
|
4016
|
+
};
|
|
4017
|
+
}
|
|
4018
|
+
const blockKey = getBlockKeyFromSelectionPoint(selectionPoint);
|
|
4019
|
+
if (!blockKey)
|
|
4020
|
+
return;
|
|
4021
|
+
const blockEntry = getNode(snapshot, [{
|
|
4022
|
+
_key: blockKey
|
|
4023
|
+
}]);
|
|
4024
|
+
if (!blockEntry)
|
|
4025
|
+
return;
|
|
4026
|
+
const leaf = getLeaf(snapshot, blockEntry.path, {
|
|
4027
|
+
edge: "start"
|
|
4028
|
+
});
|
|
4029
|
+
return leaf ? {
|
|
4030
|
+
path: leaf.path,
|
|
4031
|
+
offset: 0
|
|
4032
|
+
} : {
|
|
4033
|
+
path: blockEntry.path,
|
|
4034
|
+
offset: 0
|
|
4035
|
+
};
|
|
4036
|
+
}
|
|
4037
|
+
function applySelect(editor, target) {
|
|
4038
|
+
const range2 = toRange(editor, target), {
|
|
4039
|
+
selection
|
|
4040
|
+
} = editor;
|
|
4041
|
+
if (selection) {
|
|
4042
|
+
const oldProps = {}, newProps = {};
|
|
4043
|
+
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({
|
|
4044
|
+
type: "set_selection",
|
|
4045
|
+
properties: oldProps,
|
|
4046
|
+
newProperties: newProps
|
|
4047
|
+
});
|
|
4048
|
+
} else
|
|
4049
|
+
editor.apply({
|
|
4050
|
+
type: "set_selection",
|
|
4051
|
+
properties: null,
|
|
4052
|
+
newProperties: range2
|
|
4053
|
+
});
|
|
4054
|
+
}
|
|
4055
|
+
function applyDeselect(editor) {
|
|
4056
|
+
const {
|
|
4057
|
+
selection
|
|
4058
|
+
} = editor;
|
|
4059
|
+
selection && editor.apply({
|
|
4060
|
+
type: "set_selection",
|
|
4061
|
+
properties: selection,
|
|
4062
|
+
newProperties: null
|
|
4063
|
+
});
|
|
4064
|
+
}
|
|
4065
|
+
function toRange(editor, target) {
|
|
4066
|
+
if (isRange(target))
|
|
4067
|
+
return target;
|
|
4068
|
+
if (isPoint(target))
|
|
4069
|
+
return {
|
|
4070
|
+
anchor: target,
|
|
4071
|
+
focus: target
|
|
4072
|
+
};
|
|
4073
|
+
const start$1 = start(editor, target), end$1 = end(editor, target);
|
|
4074
|
+
return {
|
|
4075
|
+
anchor: start$1,
|
|
4076
|
+
focus: end$1
|
|
4077
|
+
};
|
|
4078
|
+
}
|
|
4079
|
+
const rootName = "pte:";
|
|
4080
|
+
function createDebugger(name) {
|
|
4081
|
+
const namespace = `${rootName}${name}`;
|
|
4082
|
+
return rawDebug && rawDebug.enabled(namespace) ? rawDebug(namespace) : rawDebug(rootName);
|
|
4083
|
+
}
|
|
4084
|
+
const debug = {
|
|
4085
|
+
behaviors: createDebugger("behaviors"),
|
|
4086
|
+
history: createDebugger("history"),
|
|
4087
|
+
mutation: createDebugger("mutation"),
|
|
4088
|
+
normalization: createDebugger("normalization"),
|
|
4089
|
+
operation: createDebugger("operation"),
|
|
4090
|
+
selection: createDebugger("selection"),
|
|
4091
|
+
setup: createDebugger("setup"),
|
|
4092
|
+
state: createDebugger("state"),
|
|
4093
|
+
syncValue: createDebugger("sync:value"),
|
|
4094
|
+
syncPatch: createDebugger("sync:patch")
|
|
4095
|
+
};
|
|
4096
|
+
function getEventPosition({
|
|
4097
|
+
editorActor,
|
|
4098
|
+
editorEngine,
|
|
4099
|
+
event
|
|
4100
|
+
}) {
|
|
4101
|
+
if (editorActor.getSnapshot().matches({
|
|
4102
|
+
setup: "setting up"
|
|
4103
|
+
}))
|
|
4104
|
+
return;
|
|
4105
|
+
const eventResult = getEventNode({
|
|
4106
|
+
editorEngine,
|
|
4107
|
+
event
|
|
4108
|
+
});
|
|
4109
|
+
if (!eventResult)
|
|
4110
|
+
return;
|
|
4111
|
+
const {
|
|
4112
|
+
node: eventNode,
|
|
4113
|
+
path: eventPath
|
|
4114
|
+
} = eventResult, eventBlockEntry = getEnclosingBlock(editorEngine, eventPath), eventBlock = eventBlockEntry?.node, eventBlockPath = eventBlockEntry?.path, eventPositionBlock = getEventPositionBlock({
|
|
4115
|
+
nodePath: eventPath,
|
|
4116
|
+
editorEngine,
|
|
4117
|
+
event
|
|
4118
|
+
}), eventSelection = getSelectionFromEvent(editorEngine, event) ?? null;
|
|
4119
|
+
if (eventBlock && eventBlockPath && eventPositionBlock && !eventSelection && !isEventContainer(editorEngine, eventNode, eventPath))
|
|
4120
|
+
return {
|
|
4121
|
+
block: eventPositionBlock,
|
|
4122
|
+
isEditor: !1,
|
|
4123
|
+
isContainer: !1,
|
|
4124
|
+
selection: {
|
|
4125
|
+
anchor: getBlockStartPoint({
|
|
4126
|
+
context: editorEngine,
|
|
4127
|
+
block: {
|
|
4128
|
+
node: eventBlock,
|
|
4129
|
+
path: eventBlockPath
|
|
4130
|
+
}
|
|
4131
|
+
}),
|
|
4132
|
+
focus: getBlockEndPoint({
|
|
4133
|
+
context: editorEngine,
|
|
4134
|
+
block: {
|
|
4135
|
+
node: eventBlock,
|
|
4136
|
+
path: eventBlockPath
|
|
4137
|
+
}
|
|
4138
|
+
})
|
|
4139
|
+
}
|
|
4140
|
+
};
|
|
4141
|
+
if (!eventPositionBlock || !eventSelection)
|
|
4142
|
+
return;
|
|
4143
|
+
const eventSelectionFocusBlock = getEnclosingBlock(editorEngine, eventSelection.focus.path);
|
|
4144
|
+
if (eventSelectionFocusBlock)
|
|
4145
|
+
return isSelectionCollapsed(eventSelection) && eventBlock && eventBlockPath && eventSelectionFocusBlock.node._key !== eventBlock._key && !isAncestorPath(eventBlockPath, eventSelectionFocusBlock.path) ? {
|
|
4146
|
+
block: eventPositionBlock,
|
|
4147
|
+
isEditor: !1,
|
|
4148
|
+
isContainer: !1,
|
|
4149
|
+
selection: {
|
|
4150
|
+
anchor: getBlockStartPoint({
|
|
4151
|
+
context: editorEngine,
|
|
4152
|
+
block: {
|
|
4153
|
+
node: eventBlock,
|
|
4154
|
+
path: eventBlockPath
|
|
4155
|
+
}
|
|
4156
|
+
}),
|
|
4157
|
+
focus: getBlockEndPoint({
|
|
4158
|
+
context: editorEngine,
|
|
4159
|
+
block: {
|
|
4160
|
+
node: eventBlock,
|
|
4161
|
+
path: eventBlockPath
|
|
4162
|
+
}
|
|
4163
|
+
})
|
|
4164
|
+
}
|
|
4165
|
+
} : {
|
|
4166
|
+
block: eventPositionBlock,
|
|
4167
|
+
isEditor: isEditor(eventNode),
|
|
4168
|
+
isContainer: isEditor(eventNode) ? !1 : isEditableContainer(editorEngine, eventNode, eventPath),
|
|
4169
|
+
selection: eventSelection
|
|
4170
|
+
};
|
|
4171
|
+
}
|
|
4172
|
+
function getEventNode({
|
|
4173
|
+
editorEngine,
|
|
4174
|
+
event
|
|
4175
|
+
}) {
|
|
4176
|
+
if (DOMEditor.hasTarget(editorEngine, event.target))
|
|
4177
|
+
try {
|
|
4178
|
+
const path2 = getDomNodePath(event.target);
|
|
4179
|
+
if (path2) {
|
|
4180
|
+
if (path2.length === 0)
|
|
4181
|
+
return {
|
|
4182
|
+
node: editorEngine,
|
|
4183
|
+
path: path2
|
|
4184
|
+
};
|
|
4185
|
+
{
|
|
4186
|
+
const nodeEntry = getNode(editorEngine, path2);
|
|
4187
|
+
if (nodeEntry)
|
|
4188
|
+
return {
|
|
4189
|
+
node: nodeEntry.node,
|
|
4190
|
+
path: path2
|
|
4191
|
+
};
|
|
4192
|
+
}
|
|
4193
|
+
}
|
|
4194
|
+
} catch (error) {
|
|
4195
|
+
console.error(error);
|
|
4239
4196
|
}
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
behaviorEvent: {
|
|
4249
|
-
type: "history.undo"
|
|
4250
|
-
},
|
|
4251
|
-
editor
|
|
4252
|
-
});
|
|
4197
|
+
}
|
|
4198
|
+
function getEventPositionBlock({
|
|
4199
|
+
nodePath,
|
|
4200
|
+
editorEngine,
|
|
4201
|
+
event
|
|
4202
|
+
}) {
|
|
4203
|
+
const firstBlockEntry = getNode(editorEngine, [0]);
|
|
4204
|
+
if (!firstBlockEntry)
|
|
4253
4205
|
return;
|
|
4254
|
-
|
|
4255
|
-
if (
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4206
|
+
const firstBlockElement = getDomNode(editorEngine, firstBlockEntry.path);
|
|
4207
|
+
if (!firstBlockElement)
|
|
4208
|
+
return;
|
|
4209
|
+
const firstBlockRect = firstBlockElement.getBoundingClientRect();
|
|
4210
|
+
if (event.pageY < firstBlockRect.top)
|
|
4211
|
+
return "start";
|
|
4212
|
+
const lastBlock = editorEngine.children.at(-1), lastBlockEntry = lastBlock ? getNode(editorEngine, [{
|
|
4213
|
+
_key: lastBlock._key
|
|
4214
|
+
}]) : void 0;
|
|
4215
|
+
if (!lastBlockEntry)
|
|
4216
|
+
return;
|
|
4217
|
+
const lastBlockElement = getDomNode(editorEngine, lastBlockEntry.path);
|
|
4218
|
+
if (!lastBlockElement)
|
|
4219
|
+
return;
|
|
4220
|
+
const lastBlockRef = lastBlockElement.getBoundingClientRect();
|
|
4221
|
+
if (event.pageY > lastBlockRef.bottom)
|
|
4222
|
+
return "end";
|
|
4223
|
+
const element = getDomNode(editorEngine, nodePath);
|
|
4224
|
+
if (!element)
|
|
4225
|
+
return;
|
|
4226
|
+
const elementRect = element.getBoundingClientRect(), top = elementRect.top, height = elementRect.height;
|
|
4227
|
+
return Math.abs(top - event.pageY) < height / 2 ? "start" : "end";
|
|
4228
|
+
}
|
|
4229
|
+
function getSelectionFromEvent(editor, event) {
|
|
4230
|
+
if (!event.target || !isDOMNode(event.target))
|
|
4231
|
+
return;
|
|
4232
|
+
const window2 = DOMEditor.getWindow(editor);
|
|
4233
|
+
let domRange;
|
|
4234
|
+
if (window2.document.caretPositionFromPoint !== void 0) {
|
|
4235
|
+
const position = window2.document.caretPositionFromPoint(event.clientX, event.clientY);
|
|
4236
|
+
if (position)
|
|
4237
|
+
try {
|
|
4238
|
+
domRange = window2.document.createRange(), domRange.setStart(position.offsetNode, position.offset), domRange.setEnd(position.offsetNode, position.offset);
|
|
4239
|
+
} catch {
|
|
4240
|
+
}
|
|
4241
|
+
} else if (window2.document.caretRangeFromPoint !== void 0)
|
|
4242
|
+
domRange = window2.document.caretRangeFromPoint(event.clientX, event.clientY) ?? void 0;
|
|
4243
|
+
else {
|
|
4244
|
+
console.warn("Neither caretPositionFromPoint nor caretRangeFromPoint is supported");
|
|
4263
4245
|
return;
|
|
4264
4246
|
}
|
|
4265
|
-
|
|
4247
|
+
if (domRange)
|
|
4248
|
+
try {
|
|
4249
|
+
return DOMEditor.toEditorSelection(editor, domRange, {
|
|
4250
|
+
exactMatch: !1,
|
|
4251
|
+
// It can still throw even with this option set to true
|
|
4252
|
+
suppressThrow: !1
|
|
4253
|
+
});
|
|
4254
|
+
} catch {
|
|
4255
|
+
return;
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
function isEventContainer(editorEngine, eventNode, eventPath) {
|
|
4259
|
+
return isEditor(eventNode) ? !0 : isEditableContainer(editorEngine, eventNode, eventPath);
|
|
4260
|
+
}
|
|
4261
|
+
const EditorActorContext = createContext({}), IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
|
|
4266
4262
|
alt: "altKey",
|
|
4267
4263
|
control: "ctrlKey",
|
|
4268
4264
|
meta: "metaKey",
|
|
@@ -4419,13 +4415,6 @@ function performHotkey({
|
|
|
4419
4415
|
}
|
|
4420
4416
|
});
|
|
4421
4417
|
}
|
|
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
4418
|
function rangeIncludes(range2, target, root) {
|
|
4430
4419
|
if (isRange(target)) {
|
|
4431
4420
|
if (rangeIncludes(range2, target.anchor, root) || rangeIncludes(range2, target.focus, root))
|
|
@@ -4437,18 +4426,25 @@ function rangeIncludes(range2, target, root) {
|
|
|
4437
4426
|
let isAfterStart = !1, isBeforeEnd = !1;
|
|
4438
4427
|
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
4428
|
}
|
|
4440
|
-
|
|
4429
|
+
function moveRangeByOperation(range2, operation) {
|
|
4430
|
+
const anchor = transformPoint$1(range2.anchor, operation), focus = transformPoint$1(range2.focus, operation);
|
|
4431
|
+
return anchor === null || focus === null ? null : pointEquals(anchor, range2.anchor) && pointEquals(focus, range2.focus) ? range2 : {
|
|
4432
|
+
anchor,
|
|
4433
|
+
focus
|
|
4434
|
+
};
|
|
4435
|
+
}
|
|
4436
|
+
const engineOperationCallback = ({
|
|
4441
4437
|
input,
|
|
4442
4438
|
sendBack
|
|
4443
4439
|
}) => {
|
|
4444
|
-
const originalApply = input.
|
|
4445
|
-
return input.
|
|
4440
|
+
const originalApply = input.editorEngine.apply;
|
|
4441
|
+
return input.editorEngine.apply = (op) => {
|
|
4446
4442
|
op.type !== "set_selection" && sendBack({
|
|
4447
|
-
type: "
|
|
4443
|
+
type: "engine operation",
|
|
4448
4444
|
operation: op
|
|
4449
4445
|
}), originalApply(op);
|
|
4450
4446
|
}, () => {
|
|
4451
|
-
input.
|
|
4447
|
+
input.editorEngine.apply = originalApply;
|
|
4452
4448
|
};
|
|
4453
4449
|
}, rangeDecorationsMachine = setup({
|
|
4454
4450
|
types: {
|
|
@@ -4481,7 +4477,7 @@ const slateOperationCallback = ({
|
|
|
4481
4477
|
...rangeDecoration.selection
|
|
4482
4478
|
});
|
|
4483
4479
|
}
|
|
4484
|
-
context.
|
|
4480
|
+
context.editorEngine.decoratedRanges = rangeDecorationState;
|
|
4485
4481
|
},
|
|
4486
4482
|
"update range decorations": ({
|
|
4487
4483
|
context,
|
|
@@ -4504,16 +4500,16 @@ const slateOperationCallback = ({
|
|
|
4504
4500
|
...rangeDecoration.selection
|
|
4505
4501
|
});
|
|
4506
4502
|
}
|
|
4507
|
-
context.
|
|
4503
|
+
context.editorEngine.decoratedRanges = rangeDecorationState;
|
|
4508
4504
|
},
|
|
4509
4505
|
"move range decorations": ({
|
|
4510
4506
|
context,
|
|
4511
4507
|
event
|
|
4512
4508
|
}) => {
|
|
4513
|
-
if (event.type !== "
|
|
4509
|
+
if (event.type !== "engine operation")
|
|
4514
4510
|
return;
|
|
4515
4511
|
const rangeDecorationState = [];
|
|
4516
|
-
for (const decoratedRange of context.
|
|
4512
|
+
for (const decoratedRange of context.editorEngine.decoratedRanges) {
|
|
4517
4513
|
const currentSelection = decoratedRange.rangeDecoration.selection;
|
|
4518
4514
|
if (!currentSelection) {
|
|
4519
4515
|
decoratedRange.rangeDecoration.onMoved?.({
|
|
@@ -4536,7 +4532,7 @@ const slateOperationCallback = ({
|
|
|
4536
4532
|
}
|
|
4537
4533
|
});
|
|
4538
4534
|
}
|
|
4539
|
-
context.
|
|
4535
|
+
context.editorEngine.decoratedRanges = rangeDecorationState;
|
|
4540
4536
|
},
|
|
4541
4537
|
"assign readOnly": assign({
|
|
4542
4538
|
readOnly: ({
|
|
@@ -4548,12 +4544,12 @@ const slateOperationCallback = ({
|
|
|
4548
4544
|
decorate: ({
|
|
4549
4545
|
context
|
|
4550
4546
|
}) => ({
|
|
4551
|
-
fn: createDecorate(context.schema, context.
|
|
4547
|
+
fn: createDecorate(context.schema, context.editorEngine)
|
|
4552
4548
|
})
|
|
4553
4549
|
})
|
|
4554
4550
|
},
|
|
4555
4551
|
actors: {
|
|
4556
|
-
"
|
|
4552
|
+
"engine operation listener": fromCallback(engineOperationCallback)
|
|
4557
4553
|
},
|
|
4558
4554
|
guards: {
|
|
4559
4555
|
"has pending range decorations": ({
|
|
@@ -4561,14 +4557,14 @@ const slateOperationCallback = ({
|
|
|
4561
4557
|
}) => context.pendingRangeDecorations.length > 0,
|
|
4562
4558
|
"has range decorations": ({
|
|
4563
4559
|
context
|
|
4564
|
-
}) => context.
|
|
4560
|
+
}) => context.editorEngine.decoratedRanges.length > 0,
|
|
4565
4561
|
"has different decorations": ({
|
|
4566
4562
|
context,
|
|
4567
4563
|
event
|
|
4568
4564
|
}) => {
|
|
4569
4565
|
if (event.type !== "range decorations updated")
|
|
4570
4566
|
return !1;
|
|
4571
|
-
const existingRangeDecorations = context.
|
|
4567
|
+
const existingRangeDecorations = context.editorEngine.decoratedRanges.map((decoratedRange) => ({
|
|
4572
4568
|
anchor: decoratedRange.rangeDecoration.selection?.anchor,
|
|
4573
4569
|
focus: decoratedRange.rangeDecoration.selection?.focus,
|
|
4574
4570
|
payload: decoratedRange.rangeDecoration.payload
|
|
@@ -4596,17 +4592,17 @@ const slateOperationCallback = ({
|
|
|
4596
4592
|
decoratedRanges: [],
|
|
4597
4593
|
skipSetup: input.skipSetup,
|
|
4598
4594
|
schema: input.schema,
|
|
4599
|
-
|
|
4595
|
+
editorEngine: input.editorEngine,
|
|
4600
4596
|
decorate: {
|
|
4601
|
-
fn: createDecorate(input.schema, input.
|
|
4597
|
+
fn: createDecorate(input.schema, input.editorEngine)
|
|
4602
4598
|
}
|
|
4603
4599
|
}),
|
|
4604
4600
|
invoke: {
|
|
4605
|
-
src: "
|
|
4601
|
+
src: "engine operation listener",
|
|
4606
4602
|
input: ({
|
|
4607
4603
|
context
|
|
4608
4604
|
}) => ({
|
|
4609
|
-
|
|
4605
|
+
editorEngine: context.editorEngine
|
|
4610
4606
|
})
|
|
4611
4607
|
},
|
|
4612
4608
|
on: {
|
|
@@ -4650,7 +4646,7 @@ const slateOperationCallback = ({
|
|
|
4650
4646
|
states: {
|
|
4651
4647
|
idle: {
|
|
4652
4648
|
on: {
|
|
4653
|
-
"
|
|
4649
|
+
"engine operation": {
|
|
4654
4650
|
target: "moving range decorations",
|
|
4655
4651
|
guard: and(["has range decorations", "not read only"])
|
|
4656
4652
|
}
|
|
@@ -4666,10 +4662,10 @@ const slateOperationCallback = ({
|
|
|
4666
4662
|
}
|
|
4667
4663
|
}
|
|
4668
4664
|
});
|
|
4669
|
-
function createDecorate(schema,
|
|
4665
|
+
function createDecorate(schema, editorEngine) {
|
|
4670
4666
|
return function([node, path2]) {
|
|
4671
|
-
const defaultStyle = schema.styles.at(0)?.name, firstBlock =
|
|
4672
|
-
return
|
|
4667
|
+
const defaultStyle = schema.styles.at(0)?.name, firstBlock = editorEngine.children[0];
|
|
4668
|
+
return editorEngine.children.length === 1 && firstBlock && isEmptyTextBlock({
|
|
4673
4669
|
schema
|
|
4674
4670
|
}, firstBlock) && (!firstBlock.style || firstBlock.style === defaultStyle) && !firstBlock.listItem ? [{
|
|
4675
4671
|
anchor: {
|
|
@@ -4682,10 +4678,10 @@ function createDecorate(schema, slateEditor) {
|
|
|
4682
4678
|
},
|
|
4683
4679
|
placeholder: !0
|
|
4684
4680
|
}] : path2.length === 0 ? [] : !isTextBlock({
|
|
4685
|
-
schema:
|
|
4686
|
-
}, node) || node.children.length === 0 ? [] :
|
|
4681
|
+
schema: editorEngine.schema
|
|
4682
|
+
}, node) || node.children.length === 0 ? [] : editorEngine.decoratedRanges.filter((decoratedRange) => {
|
|
4687
4683
|
if (isCollapsedRange(decoratedRange)) {
|
|
4688
|
-
const anchorBlock = getEnclosingBlock(
|
|
4684
|
+
const anchorBlock = getEnclosingBlock(editorEngine, decoratedRange.anchor.path), anchorChildSegment = decoratedRange.anchor.path.at(-1);
|
|
4689
4685
|
return !anchorBlock || !isKeyedSegment(anchorChildSegment) ? !1 : anchorBlock.node._key === node._key && node.children.some((child) => child._key === anchorChildSegment._key);
|
|
4690
4686
|
}
|
|
4691
4687
|
return rangeIntersection(decoratedRange, {
|
|
@@ -4697,7 +4693,7 @@ function createDecorate(schema, slateEditor) {
|
|
|
4697
4693
|
path: path2,
|
|
4698
4694
|
offset: 0
|
|
4699
4695
|
}
|
|
4700
|
-
},
|
|
4696
|
+
}, editorEngine) || rangeIncludes(decoratedRange, path2, editorEngine);
|
|
4701
4697
|
});
|
|
4702
4698
|
};
|
|
4703
4699
|
}
|
|
@@ -4797,22 +4793,22 @@ function useEditorSelector(editor, selector, t0) {
|
|
|
4797
4793
|
}
|
|
4798
4794
|
function getEditorSnapshot({
|
|
4799
4795
|
editorActorSnapshot,
|
|
4800
|
-
|
|
4796
|
+
editorEngineInstance
|
|
4801
4797
|
}) {
|
|
4802
4798
|
return {
|
|
4803
|
-
blockIndexMap:
|
|
4799
|
+
blockIndexMap: editorEngineInstance.blockIndexMap,
|
|
4804
4800
|
context: {
|
|
4805
|
-
containers:
|
|
4801
|
+
containers: editorEngineInstance.publicContainers,
|
|
4806
4802
|
converters: editorActorSnapshot.context.converters,
|
|
4807
4803
|
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
4808
4804
|
readOnly: editorActorSnapshot.matches({
|
|
4809
4805
|
"edit mode": "read only"
|
|
4810
4806
|
}),
|
|
4811
4807
|
schema: editorActorSnapshot.context.schema,
|
|
4812
|
-
selection:
|
|
4813
|
-
value:
|
|
4808
|
+
selection: editorEngineInstance.selection,
|
|
4809
|
+
value: editorEngineInstance.children
|
|
4814
4810
|
},
|
|
4815
|
-
decoratorState:
|
|
4811
|
+
decoratorState: editorEngineInstance.decoratorState
|
|
4816
4812
|
};
|
|
4817
4813
|
}
|
|
4818
4814
|
const emptySet$1 = /* @__PURE__ */ new Set(), emptyState = {
|
|
@@ -4891,12 +4887,12 @@ const defaultStore = {
|
|
|
4891
4887
|
function SelectionStateProvider(t0) {
|
|
4892
4888
|
const $ = c(10), {
|
|
4893
4889
|
children
|
|
4894
|
-
} = t0, editorActor = useContext(EditorActorContext),
|
|
4890
|
+
} = t0, editorActor = useContext(EditorActorContext), editorEngine = useEngineStatic();
|
|
4895
4891
|
let t1;
|
|
4896
|
-
$[0] !== editorActor || $[1] !==
|
|
4892
|
+
$[0] !== editorActor || $[1] !== editorEngine ? (t1 = () => {
|
|
4897
4893
|
const actorSnapshot = editorActor.getSnapshot(), snapshot = getEditorSnapshot({
|
|
4898
4894
|
editorActorSnapshot: actorSnapshot,
|
|
4899
|
-
|
|
4895
|
+
editorEngineInstance: editorEngine
|
|
4900
4896
|
}), selection = snapshot.context.selection ? {
|
|
4901
4897
|
anchorPath: snapshot.context.selection.anchor.path,
|
|
4902
4898
|
focusPath: snapshot.context.selection.focus.path,
|
|
@@ -4906,12 +4902,12 @@ function SelectionStateProvider(t0) {
|
|
|
4906
4902
|
return getSelectionState({
|
|
4907
4903
|
context: {
|
|
4908
4904
|
schema: snapshot.context.schema,
|
|
4909
|
-
containers:
|
|
4905
|
+
containers: editorEngine.publicContainers,
|
|
4910
4906
|
value: snapshot.context.value
|
|
4911
4907
|
},
|
|
4912
|
-
blockIndexMap:
|
|
4908
|
+
blockIndexMap: editorEngine.blockIndexMap
|
|
4913
4909
|
}, selection);
|
|
4914
|
-
}, $[0] = editorActor, $[1] =
|
|
4910
|
+
}, $[0] = editorActor, $[1] = editorEngine, $[2] = t1) : t1 = $[2];
|
|
4915
4911
|
const computeCurrent = t1, [seed] = useState(computeCurrent), stateRef = useRef(seed), [initialSubscribers] = useState(_temp$2), subscribersRef = useRef(initialSubscribers);
|
|
4916
4912
|
let t2, t3;
|
|
4917
4913
|
$[3] !== computeCurrent || $[4] !== editorActor ? (t2 = () => {
|
|
@@ -5095,7 +5091,7 @@ function RenderContainer(props) {
|
|
|
5095
5091
|
return t2;
|
|
5096
5092
|
}
|
|
5097
5093
|
function useBlockSubSchema(path2) {
|
|
5098
|
-
const $ = c(3), editor =
|
|
5094
|
+
const $ = c(3), editor = useEngineStatic();
|
|
5099
5095
|
let t0;
|
|
5100
5096
|
return $[0] !== editor || $[1] !== path2 ? (t0 = getPathSubSchema(editor, path2), $[0] = editor, $[1] = path2, $[2] = t0) : t0 = $[2], t0;
|
|
5101
5097
|
}
|
|
@@ -5206,7 +5202,7 @@ function RenderTextBlock(props) {
|
|
|
5206
5202
|
const serializedPath = t2, selected = useIsSelectedContainer(serializedPath), focused = useIsFocusedContainer(serializedPath);
|
|
5207
5203
|
let t3;
|
|
5208
5204
|
$[7] !== props.textBlock._key ? (t3 = (editor) => editor.listIndexMap.get(props.textBlock._key), $[7] = props.textBlock._key, $[8] = t3) : t3 = $[8];
|
|
5209
|
-
const listIndex =
|
|
5205
|
+
const listIndex = useEngineSelector(t3), subSchema = useBlockSubSchema(props.path);
|
|
5210
5206
|
let children = props.children;
|
|
5211
5207
|
if (props.legacy.renderStyle && props.textBlock.style) {
|
|
5212
5208
|
let t42;
|
|
@@ -5367,7 +5363,7 @@ function tupleRefEqual(previous, next) {
|
|
|
5367
5363
|
return !0;
|
|
5368
5364
|
}
|
|
5369
5365
|
function RenderElement(props) {
|
|
5370
|
-
const $ = c(84), editorActor = useContext(EditorActorContext), parentContainer = useContext(ParentContainerContext), parentTextBlock = useContext(ParentTextBlockContext), isInNewPipeline = useContext(NewPipelineContext),
|
|
5366
|
+
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
5367
|
let t0;
|
|
5372
5368
|
$[0] !== parentContainer || $[1] !== type ? (t0 = findBlockPositionalOverride(parentContainer, type), $[0] = parentContainer, $[1] = type, $[2] = t0) : t0 = $[2];
|
|
5373
5369
|
const blockPositionalOverride = t0;
|
|
@@ -5490,7 +5486,7 @@ function RenderElement(props) {
|
|
|
5490
5486
|
}
|
|
5491
5487
|
return rendered;
|
|
5492
5488
|
}
|
|
5493
|
-
if (isInline(
|
|
5489
|
+
if (isInline(engineStatic, props.path)) {
|
|
5494
5490
|
if (isInNewPipeline && !inlineObjectConfig) {
|
|
5495
5491
|
let rest_0;
|
|
5496
5492
|
if ($[44] !== props.attributes) {
|
|
@@ -5960,19 +5956,19 @@ const PortableTextEditorContext = createContext(null), usePortableTextEditor = (
|
|
|
5960
5956
|
guards: {
|
|
5961
5957
|
"pending operations": ({
|
|
5962
5958
|
context
|
|
5963
|
-
}) => context.
|
|
5959
|
+
}) => context.editorEngine.operations.length > 0
|
|
5964
5960
|
}
|
|
5965
5961
|
}), validateSelectionAction = validateSelectionSetup.createAction(({
|
|
5966
5962
|
context,
|
|
5967
5963
|
event
|
|
5968
5964
|
}) => {
|
|
5969
|
-
validateSelection(context.
|
|
5965
|
+
validateSelection(context.editorEngine, event.editorElement);
|
|
5970
5966
|
}), validateSelectionMachine = validateSelectionSetup.createMachine({
|
|
5971
5967
|
id: "validate selection",
|
|
5972
5968
|
context: ({
|
|
5973
5969
|
input
|
|
5974
5970
|
}) => ({
|
|
5975
|
-
|
|
5971
|
+
editorEngine: input.editorEngine
|
|
5976
5972
|
}),
|
|
5977
5973
|
initial: "idle",
|
|
5978
5974
|
states: {
|
|
@@ -6007,25 +6003,25 @@ const PortableTextEditorContext = createContext(null), usePortableTextEditor = (
|
|
|
6007
6003
|
}
|
|
6008
6004
|
}
|
|
6009
6005
|
});
|
|
6010
|
-
function validateSelection(
|
|
6011
|
-
if (!
|
|
6006
|
+
function validateSelection(editorEngine, editorElement) {
|
|
6007
|
+
if (!editorEngine.selection)
|
|
6012
6008
|
return;
|
|
6013
6009
|
let root;
|
|
6014
6010
|
try {
|
|
6015
|
-
root = DOMEditor.findDocumentOrShadowRoot(
|
|
6011
|
+
root = DOMEditor.findDocumentOrShadowRoot(editorEngine);
|
|
6016
6012
|
} catch {
|
|
6017
6013
|
}
|
|
6018
6014
|
if (!root || editorElement !== root.activeElement)
|
|
6019
6015
|
return;
|
|
6020
|
-
const domSelection = DOMEditor.getWindow(
|
|
6016
|
+
const domSelection = DOMEditor.getWindow(editorEngine).getSelection();
|
|
6021
6017
|
if (!domSelection || domSelection.rangeCount === 0)
|
|
6022
6018
|
return;
|
|
6023
6019
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
6024
6020
|
try {
|
|
6025
|
-
const newDOMRange = DOMEditor.toDOMRange(
|
|
6021
|
+
const newDOMRange = DOMEditor.toDOMRange(editorEngine, editorEngine.selection);
|
|
6026
6022
|
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug.selection("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
6027
6023
|
} catch {
|
|
6028
|
-
debug.selection("Could not resolve selection, selecting top document"), applyDeselect(
|
|
6024
|
+
debug.selection("Could not resolve selection, selecting top document"), applyDeselect(editorEngine), editorEngine.children.length > 0 && applySelect(editorEngine, start(editorEngine, [])), editorEngine.onChange();
|
|
6029
6025
|
}
|
|
6030
6026
|
}
|
|
6031
6027
|
const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
@@ -6062,13 +6058,13 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6062
6058
|
const portableTextEditor = usePortableTextEditor(), [hasInvalidValue, setHasInvalidValue] = useState(!1), editorActor = useContext(EditorActorContext), relayActor = useContext(RelayActorContext);
|
|
6063
6059
|
let t0;
|
|
6064
6060
|
$[27] !== editorActor ? (t0 = editorActor.getSnapshot(), $[27] = editorActor, $[28] = t0) : t0 = $[28];
|
|
6065
|
-
const schema = t0.context.schema, readOnly = useSelector(editorActor, _temp),
|
|
6061
|
+
const schema = t0.context.schema, readOnly = useSelector(editorActor, _temp), editorEngine = useEngine();
|
|
6066
6062
|
let t1;
|
|
6067
|
-
$[29] !==
|
|
6063
|
+
$[29] !== editorEngine ? (t1 = {
|
|
6068
6064
|
input: {
|
|
6069
|
-
|
|
6065
|
+
editorEngine
|
|
6070
6066
|
}
|
|
6071
|
-
}, $[29] =
|
|
6067
|
+
}, $[29] = editorEngine, $[30] = t1) : t1 = $[30];
|
|
6072
6068
|
const validateSelectionActor = useActorRef(validateSelectionMachine, t1);
|
|
6073
6069
|
let t2;
|
|
6074
6070
|
$[31] !== rangeDecorations ? (t2 = rangeDecorations ?? [], $[31] = rangeDecorations, $[32] = t2) : t2 = $[32];
|
|
@@ -6078,15 +6074,15 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6078
6074
|
}), $[33] = editorActor, $[34] = t3) : t3 = $[34];
|
|
6079
6075
|
const t4 = !t3;
|
|
6080
6076
|
let t5;
|
|
6081
|
-
$[35] !==
|
|
6077
|
+
$[35] !== editorEngine || $[36] !== readOnly || $[37] !== schema || $[38] !== t2 || $[39] !== t4 ? (t5 = {
|
|
6082
6078
|
input: {
|
|
6083
6079
|
rangeDecorations: t2,
|
|
6084
6080
|
readOnly,
|
|
6085
6081
|
schema,
|
|
6086
|
-
|
|
6082
|
+
editorEngine,
|
|
6087
6083
|
skipSetup: t4
|
|
6088
6084
|
}
|
|
6089
|
-
}, $[35] =
|
|
6085
|
+
}, $[35] = editorEngine, $[36] = readOnly, $[37] = schema, $[38] = t2, $[39] = t4, $[40] = t5) : t5 = $[40];
|
|
6090
6086
|
const rangeDecorationsActor = useActorRef(rangeDecorationsMachine, t5), decorate = useSelector(rangeDecorationsActor, _temp2), dropPosition = useDropPosition();
|
|
6091
6087
|
let t6, t7;
|
|
6092
6088
|
$[41] !== rangeDecorationsActor || $[42] !== readOnly ? (t6 = () => {
|
|
@@ -6117,16 +6113,16 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6117
6113
|
$[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
6114
|
const renderLeaf = t12, renderText = _temp3;
|
|
6119
6115
|
let t13;
|
|
6120
|
-
$[66] !== editorActor || $[67] !==
|
|
6116
|
+
$[66] !== editorActor || $[67] !== editorEngine || $[68] !== propsSelection ? (t13 = () => {
|
|
6121
6117
|
if (propsSelection) {
|
|
6122
6118
|
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)}`),
|
|
6119
|
+
const resolvedSelection = resolveSelection(editorEngine, propsSelection);
|
|
6120
|
+
resolvedSelection && (debug.selection.enabled && debug.selection(`Resolved selection from props ${safeStringify(resolvedSelection)}`), editorEngine.select(resolvedSelection), editorEngine.operations.some(_temp4) || editorActor.send({
|
|
6125
6121
|
type: "update selection",
|
|
6126
6122
|
selection: resolvedSelection
|
|
6127
|
-
}),
|
|
6123
|
+
}), editorEngine.onChange());
|
|
6128
6124
|
}
|
|
6129
|
-
}, $[66] = editorActor, $[67] =
|
|
6125
|
+
}, $[66] = editorActor, $[67] = editorEngine, $[68] = propsSelection, $[69] = t13) : t13 = $[69];
|
|
6130
6126
|
const restoreSelectionFromProps = t13;
|
|
6131
6127
|
let t14, t15;
|
|
6132
6128
|
$[70] !== editorActor || $[71] !== rangeDecorationsActor || $[72] !== restoreSelectionFromProps ? (t14 = () => {
|
|
@@ -6148,13 +6144,13 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6148
6144
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
6149
6145
|
}, t17 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[75] = hasInvalidValue, $[76] = propsSelection, $[77] = restoreSelectionFromProps, $[78] = t16, $[79] = t17) : (t16 = $[78], t17 = $[79]), useEffect(t16, t17);
|
|
6150
6146
|
let t18;
|
|
6151
|
-
$[80] !== editorActor || $[81] !==
|
|
6152
|
-
if (DOMEditor.hasSelectableTarget(
|
|
6147
|
+
$[80] !== editorActor || $[81] !== editorEngine || $[82] !== onCopy ? (t18 = (event) => {
|
|
6148
|
+
if (DOMEditor.hasSelectableTarget(editorEngine, event.target)) {
|
|
6153
6149
|
if (onCopy)
|
|
6154
6150
|
onCopy(event) !== void 0 && event.preventDefault();
|
|
6155
6151
|
else if (event.nativeEvent.clipboardData) {
|
|
6156
6152
|
event.stopPropagation(), event.preventDefault();
|
|
6157
|
-
const selection =
|
|
6153
|
+
const selection = editorEngine.selection ?? void 0, position = selection ? {
|
|
6158
6154
|
selection
|
|
6159
6155
|
} : void 0;
|
|
6160
6156
|
if (!position) {
|
|
@@ -6170,16 +6166,16 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6170
6166
|
},
|
|
6171
6167
|
position
|
|
6172
6168
|
},
|
|
6173
|
-
editor:
|
|
6169
|
+
editor: editorEngine,
|
|
6174
6170
|
nativeEvent: event
|
|
6175
6171
|
});
|
|
6176
6172
|
}
|
|
6177
6173
|
}
|
|
6178
|
-
}, $[80] = editorActor, $[81] =
|
|
6174
|
+
}, $[80] = editorActor, $[81] = editorEngine, $[82] = onCopy, $[83] = t18) : t18 = $[83];
|
|
6179
6175
|
const handleCopy = t18;
|
|
6180
6176
|
let t19;
|
|
6181
|
-
$[84] !== editorActor || $[85] !==
|
|
6182
|
-
if (DOMEditor.hasSelectableTarget(
|
|
6177
|
+
$[84] !== editorActor || $[85] !== editorEngine || $[86] !== onCut ? (t19 = (event_0) => {
|
|
6178
|
+
if (DOMEditor.hasSelectableTarget(editorEngine, event_0.target)) {
|
|
6183
6179
|
if (onCut)
|
|
6184
6180
|
onCut(event_0) !== void 0 && event_0.preventDefault();
|
|
6185
6181
|
else if (event_0.nativeEvent.clipboardData) {
|
|
@@ -6200,22 +6196,22 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6200
6196
|
},
|
|
6201
6197
|
position: position_0
|
|
6202
6198
|
},
|
|
6203
|
-
editor:
|
|
6199
|
+
editor: editorEngine,
|
|
6204
6200
|
nativeEvent: event_0
|
|
6205
6201
|
});
|
|
6206
6202
|
}
|
|
6207
6203
|
}
|
|
6208
|
-
}, $[84] = editorActor, $[85] =
|
|
6204
|
+
}, $[84] = editorActor, $[85] = editorEngine, $[86] = onCut, $[87] = t19) : t19 = $[87];
|
|
6209
6205
|
const handleCut = t19;
|
|
6210
6206
|
let t20;
|
|
6211
|
-
$[88] !== editorActor || $[89] !==
|
|
6212
|
-
const value =
|
|
6207
|
+
$[88] !== editorActor || $[89] !== editorEngine || $[90] !== onPaste || $[91] !== portableTextEditor || $[92] !== relayActor ? (t20 = (event_1) => {
|
|
6208
|
+
const value = editorEngine.children, path2 = editorEngine.selection?.focus.path || [], onPasteResult = onPaste?.({
|
|
6213
6209
|
event: event_1,
|
|
6214
6210
|
value,
|
|
6215
6211
|
path: path2,
|
|
6216
6212
|
schemaTypes: portableTextEditor.schemaTypes
|
|
6217
6213
|
});
|
|
6218
|
-
if (onPasteResult || !
|
|
6214
|
+
if (onPasteResult || !editorEngine.selection)
|
|
6219
6215
|
event_1.preventDefault(), relayActor.send({
|
|
6220
6216
|
type: "loading"
|
|
6221
6217
|
}), Promise.resolve(onPasteResult).then((result_1) => {
|
|
@@ -6237,7 +6233,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6237
6233
|
},
|
|
6238
6234
|
position: position_1
|
|
6239
6235
|
},
|
|
6240
|
-
editor:
|
|
6236
|
+
editor: editorEngine,
|
|
6241
6237
|
nativeEvent: event_1
|
|
6242
6238
|
});
|
|
6243
6239
|
} else
|
|
@@ -6257,7 +6253,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6257
6253
|
}),
|
|
6258
6254
|
placement: "auto"
|
|
6259
6255
|
},
|
|
6260
|
-
editor:
|
|
6256
|
+
editor: editorEngine
|
|
6261
6257
|
}) : console.warn("Your onPaste function returned something unexpected:", result_1);
|
|
6262
6258
|
}).catch(_temp5).finally(() => {
|
|
6263
6259
|
relayActor.send({
|
|
@@ -6282,28 +6278,28 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6282
6278
|
},
|
|
6283
6279
|
position: position_2
|
|
6284
6280
|
},
|
|
6285
|
-
editor:
|
|
6281
|
+
editor: editorEngine,
|
|
6286
6282
|
nativeEvent: event_1
|
|
6287
6283
|
});
|
|
6288
6284
|
}
|
|
6289
6285
|
debug.behaviors("No result from custom paste handler, pasting normally");
|
|
6290
|
-
}, $[88] = editorActor, $[89] =
|
|
6286
|
+
}, $[88] = editorActor, $[89] = editorEngine, $[90] = onPaste, $[91] = portableTextEditor, $[92] = relayActor, $[93] = t20) : t20 = $[93];
|
|
6291
6287
|
const handlePaste = t20;
|
|
6292
6288
|
let t21;
|
|
6293
|
-
$[94] !== editorActor || $[95] !==
|
|
6289
|
+
$[94] !== editorActor || $[95] !== editorEngine || $[96] !== onFocus || $[97] !== relayActor ? (t21 = (event_2) => {
|
|
6294
6290
|
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
6295
6291
|
type: "focused",
|
|
6296
6292
|
event: event_2
|
|
6297
|
-
}), !
|
|
6298
|
-
}, $[94] = editorActor, $[95] =
|
|
6293
|
+
}), !editorEngine.selection && editorEngine.children.length === 1 && isEmptyTextBlock(editorActor.getSnapshot().context, editorEngine.children.at(0)) && (editorEngine.select(start(editorEngine, [])), editorEngine.onChange()));
|
|
6294
|
+
}, $[94] = editorActor, $[95] = editorEngine, $[96] = onFocus, $[97] = relayActor, $[98] = t21) : t21 = $[98];
|
|
6299
6295
|
const handleOnFocus = t21;
|
|
6300
6296
|
let t22;
|
|
6301
|
-
$[99] !== editorActor || $[100] !==
|
|
6297
|
+
$[99] !== editorActor || $[100] !== editorEngine || $[101] !== onClick ? (t22 = (event_3) => {
|
|
6302
6298
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
6303
6299
|
return;
|
|
6304
6300
|
const position_3 = getEventPosition({
|
|
6305
6301
|
editorActor,
|
|
6306
|
-
|
|
6302
|
+
editorEngine,
|
|
6307
6303
|
event: event_3.nativeEvent
|
|
6308
6304
|
});
|
|
6309
6305
|
position_3 && editorActor.send({
|
|
@@ -6312,10 +6308,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6312
6308
|
type: "mouse.click",
|
|
6313
6309
|
position: position_3
|
|
6314
6310
|
},
|
|
6315
|
-
editor:
|
|
6311
|
+
editor: editorEngine,
|
|
6316
6312
|
nativeEvent: event_3
|
|
6317
6313
|
});
|
|
6318
|
-
}, $[99] = editorActor, $[100] =
|
|
6314
|
+
}, $[99] = editorActor, $[100] = editorEngine, $[101] = onClick, $[102] = t22) : t22 = $[102];
|
|
6319
6315
|
const handleClick = t22;
|
|
6320
6316
|
let t23;
|
|
6321
6317
|
$[103] !== onBlur || $[104] !== relayActor ? (t23 = (event_4) => {
|
|
@@ -6331,10 +6327,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6331
6327
|
}, $[106] = onBeforeInput, $[107] = t24) : t24 = $[107];
|
|
6332
6328
|
const handleOnBeforeInput = t24;
|
|
6333
6329
|
let t25;
|
|
6334
|
-
$[108] !== editorActor || $[109] !==
|
|
6330
|
+
$[108] !== editorActor || $[109] !== editorEngine || $[110] !== hotkeys || $[111] !== portableTextEditor || $[112] !== props ? (t25 = (event_6) => {
|
|
6335
6331
|
props.onKeyDown && props.onKeyDown(event_6), event_6.isDefaultPrevented() || performHotkey({
|
|
6336
6332
|
editorActor,
|
|
6337
|
-
editor:
|
|
6333
|
+
editor: editorEngine,
|
|
6338
6334
|
portableTextEditor,
|
|
6339
6335
|
hotkeys: hotkeys ?? {},
|
|
6340
6336
|
event: event_6
|
|
@@ -6351,13 +6347,13 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6351
6347
|
shiftKey: event_6.shiftKey
|
|
6352
6348
|
}
|
|
6353
6349
|
},
|
|
6354
|
-
editor:
|
|
6350
|
+
editor: editorEngine,
|
|
6355
6351
|
nativeEvent: event_6
|
|
6356
6352
|
});
|
|
6357
|
-
}, $[108] = editorActor, $[109] =
|
|
6353
|
+
}, $[108] = editorActor, $[109] = editorEngine, $[110] = hotkeys, $[111] = portableTextEditor, $[112] = props, $[113] = t25) : t25 = $[113];
|
|
6358
6354
|
const handleKeyDown = t25;
|
|
6359
6355
|
let t26;
|
|
6360
|
-
$[114] !== editorActor || $[115] !==
|
|
6356
|
+
$[114] !== editorActor || $[115] !== editorEngine || $[116] !== props ? (t26 = (event_7) => {
|
|
6361
6357
|
props.onKeyUp && props.onKeyUp(event_7), event_7.isDefaultPrevented() || editorActor.send({
|
|
6362
6358
|
type: "behavior event",
|
|
6363
6359
|
behaviorEvent: {
|
|
@@ -6371,10 +6367,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6371
6367
|
shiftKey: event_7.shiftKey
|
|
6372
6368
|
}
|
|
6373
6369
|
},
|
|
6374
|
-
editor:
|
|
6370
|
+
editor: editorEngine,
|
|
6375
6371
|
nativeEvent: event_7
|
|
6376
6372
|
});
|
|
6377
|
-
}, $[114] = editorActor, $[115] =
|
|
6373
|
+
}, $[114] = editorActor, $[115] = editorEngine, $[116] = props, $[117] = t26) : t26 = $[117];
|
|
6378
6374
|
const handleKeyUp = t26;
|
|
6379
6375
|
let t27;
|
|
6380
6376
|
bb0: {
|
|
@@ -6391,10 +6387,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6391
6387
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
6392
6388
|
}, $[118] = portableTextEditor, $[119] = scrollSelectionIntoView, $[120] = t282) : t282 = $[120], t27 = t282;
|
|
6393
6389
|
}
|
|
6394
|
-
const
|
|
6390
|
+
const scrollSelectionIntoViewToEngine = t27;
|
|
6395
6391
|
let t28, t29;
|
|
6396
|
-
$[121] !== editorActor || $[122] !==
|
|
6397
|
-
const window2 = DOMEditor.getWindow(
|
|
6392
|
+
$[121] !== editorActor || $[122] !== editorEngine ? (t28 = () => {
|
|
6393
|
+
const window2 = DOMEditor.getWindow(editorEngine), onDragEnd_0 = () => {
|
|
6398
6394
|
editorActor.send({
|
|
6399
6395
|
type: "dragend"
|
|
6400
6396
|
});
|
|
@@ -6406,14 +6402,14 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6406
6402
|
return window2.document.addEventListener("dragend", onDragEnd_0), window2.document.addEventListener("drop", onDrop_0), () => {
|
|
6407
6403
|
window2.document.removeEventListener("dragend", onDragEnd_0), window2.document.removeEventListener("drop", onDrop_0);
|
|
6408
6404
|
};
|
|
6409
|
-
}, t29 = [
|
|
6405
|
+
}, t29 = [editorEngine, editorActor], $[121] = editorActor, $[122] = editorEngine, $[123] = t28, $[124] = t29) : (t28 = $[123], t29 = $[124]), useEffect(t28, t29);
|
|
6410
6406
|
let t30;
|
|
6411
|
-
$[125] !== editorActor || $[126] !==
|
|
6412
|
-
if (readOnly || !DOMEditor.hasTarget(
|
|
6407
|
+
$[125] !== editorActor || $[126] !== editorEngine || $[127] !== onDragStart || $[128] !== readOnly ? (t30 = (event_8) => {
|
|
6408
|
+
if (readOnly || !DOMEditor.hasTarget(editorEngine, event_8.target) || (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped()))
|
|
6413
6409
|
return;
|
|
6414
6410
|
const position_4 = getEventPosition({
|
|
6415
6411
|
editorActor,
|
|
6416
|
-
|
|
6412
|
+
editorEngine,
|
|
6417
6413
|
event: event_8.nativeEvent
|
|
6418
6414
|
});
|
|
6419
6415
|
if (!position_4) {
|
|
@@ -6434,15 +6430,15 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6434
6430
|
},
|
|
6435
6431
|
position: position_4
|
|
6436
6432
|
},
|
|
6437
|
-
editor:
|
|
6433
|
+
editor: editorEngine
|
|
6438
6434
|
}), !0;
|
|
6439
|
-
}, $[125] = editorActor, $[126] =
|
|
6435
|
+
}, $[125] = editorActor, $[126] = editorEngine, $[127] = onDragStart, $[128] = readOnly, $[129] = t30) : t30 = $[129];
|
|
6440
6436
|
const handleDragStart = t30;
|
|
6441
6437
|
let t31;
|
|
6442
|
-
$[130] !== editorActor || $[131] !==
|
|
6438
|
+
$[130] !== editorActor || $[131] !== editorEngine || $[132] !== onDrag ? (t31 = (event_9) => {
|
|
6443
6439
|
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
|
|
6444
6440
|
editorActor,
|
|
6445
|
-
|
|
6441
|
+
editorEngine,
|
|
6446
6442
|
event: event_9.nativeEvent
|
|
6447
6443
|
})))
|
|
6448
6444
|
return editorActor.send({
|
|
@@ -6453,12 +6449,12 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6453
6449
|
dataTransfer: event_9.dataTransfer
|
|
6454
6450
|
}
|
|
6455
6451
|
},
|
|
6456
|
-
editor:
|
|
6452
|
+
editor: editorEngine
|
|
6457
6453
|
}), !0;
|
|
6458
|
-
}, $[130] = editorActor, $[131] =
|
|
6454
|
+
}, $[130] = editorActor, $[131] = editorEngine, $[132] = onDrag, $[133] = t31) : t31 = $[133];
|
|
6459
6455
|
const handleDrag = t31;
|
|
6460
6456
|
let t32;
|
|
6461
|
-
$[134] !== editorActor || $[135] !==
|
|
6457
|
+
$[134] !== editorActor || $[135] !== editorEngine || $[136] !== onDragEnd ? (t32 = (event_10) => {
|
|
6462
6458
|
if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
|
|
6463
6459
|
return editorActor.send({
|
|
6464
6460
|
type: "behavior event",
|
|
@@ -6468,17 +6464,17 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6468
6464
|
dataTransfer: event_10.dataTransfer
|
|
6469
6465
|
}
|
|
6470
6466
|
},
|
|
6471
|
-
editor:
|
|
6467
|
+
editor: editorEngine
|
|
6472
6468
|
}), !0;
|
|
6473
|
-
}, $[134] = editorActor, $[135] =
|
|
6469
|
+
}, $[134] = editorActor, $[135] = editorEngine, $[136] = onDragEnd, $[137] = t32) : t32 = $[137];
|
|
6474
6470
|
const handleDragEnd = t32;
|
|
6475
6471
|
let t33;
|
|
6476
|
-
$[138] !== editorActor || $[139] !==
|
|
6472
|
+
$[138] !== editorActor || $[139] !== editorEngine || $[140] !== onDragEnter ? (t33 = (event_11) => {
|
|
6477
6473
|
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
6478
6474
|
return;
|
|
6479
6475
|
const position_6 = getEventPosition({
|
|
6480
6476
|
editorActor,
|
|
6481
|
-
|
|
6477
|
+
editorEngine,
|
|
6482
6478
|
event: event_11.nativeEvent
|
|
6483
6479
|
});
|
|
6484
6480
|
if (position_6)
|
|
@@ -6491,17 +6487,17 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6491
6487
|
},
|
|
6492
6488
|
position: position_6
|
|
6493
6489
|
},
|
|
6494
|
-
editor:
|
|
6490
|
+
editor: editorEngine
|
|
6495
6491
|
}), !0;
|
|
6496
|
-
}, $[138] = editorActor, $[139] =
|
|
6492
|
+
}, $[138] = editorActor, $[139] = editorEngine, $[140] = onDragEnter, $[141] = t33) : t33 = $[141];
|
|
6497
6493
|
const handleDragEnter = t33;
|
|
6498
6494
|
let t34;
|
|
6499
|
-
$[142] !== editorActor || $[143] !==
|
|
6495
|
+
$[142] !== editorActor || $[143] !== editorEngine || $[144] !== onDragOver ? (t34 = (event_12) => {
|
|
6500
6496
|
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
6501
6497
|
return;
|
|
6502
6498
|
const position_7 = getEventPosition({
|
|
6503
6499
|
editorActor,
|
|
6504
|
-
|
|
6500
|
+
editorEngine,
|
|
6505
6501
|
event: event_12.nativeEvent
|
|
6506
6502
|
});
|
|
6507
6503
|
if (position_7)
|
|
@@ -6515,18 +6511,18 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6515
6511
|
dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
|
|
6516
6512
|
position: position_7
|
|
6517
6513
|
},
|
|
6518
|
-
editor:
|
|
6514
|
+
editor: editorEngine,
|
|
6519
6515
|
nativeEvent: event_12
|
|
6520
6516
|
}), !0;
|
|
6521
|
-
}, $[142] = editorActor, $[143] =
|
|
6517
|
+
}, $[142] = editorActor, $[143] = editorEngine, $[144] = onDragOver, $[145] = t34) : t34 = $[145];
|
|
6522
6518
|
const handleDragOver = t34;
|
|
6523
6519
|
let t35;
|
|
6524
|
-
$[146] !== editorActor || $[147] !==
|
|
6520
|
+
$[146] !== editorActor || $[147] !== editorEngine || $[148] !== onDrop ? (t35 = (event_13) => {
|
|
6525
6521
|
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
6526
6522
|
return;
|
|
6527
6523
|
const position_8 = getEventPosition({
|
|
6528
6524
|
editorActor,
|
|
6529
|
-
|
|
6525
|
+
editorEngine,
|
|
6530
6526
|
event: event_13.nativeEvent
|
|
6531
6527
|
});
|
|
6532
6528
|
if (!position_8) {
|
|
@@ -6543,16 +6539,16 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6543
6539
|
dragOrigin: editorActor.getSnapshot().context.internalDrag?.origin,
|
|
6544
6540
|
position: position_8
|
|
6545
6541
|
},
|
|
6546
|
-
editor:
|
|
6542
|
+
editor: editorEngine,
|
|
6547
6543
|
nativeEvent: event_13
|
|
6548
6544
|
}), !0;
|
|
6549
|
-
}, $[146] = editorActor, $[147] =
|
|
6545
|
+
}, $[146] = editorActor, $[147] = editorEngine, $[148] = onDrop, $[149] = t35) : t35 = $[149];
|
|
6550
6546
|
const handleDrop = t35;
|
|
6551
6547
|
let t36;
|
|
6552
|
-
$[150] !== editorActor || $[151] !==
|
|
6548
|
+
$[150] !== editorActor || $[151] !== editorEngine || $[152] !== onDragLeave ? (t36 = (event_14) => {
|
|
6553
6549
|
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
|
|
6554
6550
|
editorActor,
|
|
6555
|
-
|
|
6551
|
+
editorEngine,
|
|
6556
6552
|
event: event_14.nativeEvent
|
|
6557
6553
|
})))
|
|
6558
6554
|
return editorActor.send({
|
|
@@ -6563,9 +6559,9 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6563
6559
|
dataTransfer: event_14.dataTransfer
|
|
6564
6560
|
}
|
|
6565
6561
|
},
|
|
6566
|
-
editor:
|
|
6562
|
+
editor: editorEngine
|
|
6567
6563
|
}), !0;
|
|
6568
|
-
}, $[150] = editorActor, $[151] =
|
|
6564
|
+
}, $[150] = editorActor, $[151] = editorEngine, $[152] = onDragLeave, $[153] = t36) : t36 = $[153];
|
|
6569
6565
|
const handleDragLeave = t36;
|
|
6570
6566
|
let t37;
|
|
6571
6567
|
$[154] !== forwardedRef || $[155] !== validateSelectionActor ? (t37 = (editorElement) => {
|
|
@@ -6591,7 +6587,7 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
|
6591
6587
|
if (!portableTextEditor)
|
|
6592
6588
|
return null;
|
|
6593
6589
|
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] !==
|
|
6590
|
+
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
6591
|
});
|
|
6596
6592
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
6597
6593
|
function noop() {
|
|
@@ -6613,7 +6609,21 @@ function _temp4(o) {
|
|
|
6613
6609
|
function _temp5(error) {
|
|
6614
6610
|
return console.warn(error), error;
|
|
6615
6611
|
}
|
|
6616
|
-
const
|
|
6612
|
+
const Engine = (props) => {
|
|
6613
|
+
const {
|
|
6614
|
+
editor,
|
|
6615
|
+
children
|
|
6616
|
+
} = props, {
|
|
6617
|
+
selectorContext,
|
|
6618
|
+
onChange: handleSelectorChange
|
|
6619
|
+
} = useSelectorContext(), onContextChange = useCallback(() => {
|
|
6620
|
+
handleSelectorChange();
|
|
6621
|
+
}, [editor, handleSelectorChange]);
|
|
6622
|
+
return useEffect(() => (editor.onContextChange = onContextChange, () => {
|
|
6623
|
+
editor.onContextChange = () => {
|
|
6624
|
+
};
|
|
6625
|
+
}), [editor, onContextChange]), /* @__PURE__ */ jsx(EngineSelectorContext.Provider, { value: selectorContext, children: /* @__PURE__ */ jsx(EditorContext.Provider, { value: editor, children }) });
|
|
6626
|
+
}, forEachActor = (actorRef, callback) => {
|
|
6617
6627
|
callback(actorRef);
|
|
6618
6628
|
const children = actorRef.getSnapshot().children;
|
|
6619
6629
|
children && Object.values(children).forEach((child) => {
|
|
@@ -6630,21 +6640,6 @@ function stopActor(actorRef) {
|
|
|
6630
6640
|
ref._processingStatus = 0, ref._snapshot = snapshot;
|
|
6631
6641
|
});
|
|
6632
6642
|
}
|
|
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
6643
|
const converterJson = {
|
|
6649
6644
|
mimeType: "application/json",
|
|
6650
6645
|
serialize: ({
|
|
@@ -7000,14 +6995,14 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7000
6995
|
isMarkActive: (mark) => {
|
|
7001
6996
|
const snapshot = getEditorSnapshot({
|
|
7002
6997
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7003
|
-
|
|
6998
|
+
editorEngineInstance: editor
|
|
7004
6999
|
});
|
|
7005
7000
|
return getActiveDecorators(snapshot).includes(mark);
|
|
7006
7001
|
},
|
|
7007
7002
|
marks: () => {
|
|
7008
7003
|
const snapshot = getEditorSnapshot({
|
|
7009
7004
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7010
|
-
|
|
7005
|
+
editorEngineInstance: editor
|
|
7011
7006
|
}), activeAnnotations = getActiveAnnotationsMarks(snapshot), activeDecorators = getActiveDecorators(snapshot);
|
|
7012
7007
|
return [...activeAnnotations, ...activeDecorators];
|
|
7013
7008
|
},
|
|
@@ -7149,14 +7144,14 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7149
7144
|
isAnnotationActive: (annotationType) => {
|
|
7150
7145
|
const snapshot = getEditorSnapshot({
|
|
7151
7146
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7152
|
-
|
|
7147
|
+
editorEngineInstance: editor
|
|
7153
7148
|
});
|
|
7154
7149
|
return isActiveAnnotation(annotationType)(snapshot);
|
|
7155
7150
|
},
|
|
7156
7151
|
addAnnotation: (type, value) => {
|
|
7157
7152
|
const snapshotBefore = getEditorSnapshot({
|
|
7158
7153
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7159
|
-
|
|
7154
|
+
editorEngineInstance: editor
|
|
7160
7155
|
}), selectedValueBefore = getSelectedValue(snapshotBefore), focusSpanBefore = getFocusSpan(snapshotBefore), markDefsBefore = selectedValueBefore.flatMap((block) => isTextBlock(snapshotBefore.context, block) ? block.markDefs ?? [] : []);
|
|
7161
7156
|
editorActor.send({
|
|
7162
7157
|
type: "behavior event",
|
|
@@ -7171,7 +7166,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7171
7166
|
});
|
|
7172
7167
|
const snapshotAfter = getEditorSnapshot({
|
|
7173
7168
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7174
|
-
|
|
7169
|
+
editorEngineInstance: editor
|
|
7175
7170
|
}), 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
7171
|
markDef: markDef2,
|
|
7177
7172
|
path: [{
|
|
@@ -7213,135 +7208,26 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7213
7208
|
getSelection: () => editor.selection,
|
|
7214
7209
|
getValue: () => editor.children,
|
|
7215
7210
|
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);
|
|
7211
|
+
isExpandedSelection: () => !!editor.selection && isExpandedRange(editor.selection),
|
|
7212
|
+
insertBreak: () => {
|
|
7213
|
+
editorActor.send({
|
|
7214
|
+
type: "behavior event",
|
|
7215
|
+
behaviorEvent: {
|
|
7216
|
+
type: "insert.break"
|
|
7217
|
+
},
|
|
7218
|
+
editor
|
|
7279
7219
|
});
|
|
7280
|
-
}
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
}
|
|
7288
|
-
|
|
7289
|
-
const style = resolveDefaultStyle(snapshot, path2);
|
|
7290
|
-
return {
|
|
7291
|
-
_type: snapshot.context.schema.block.name,
|
|
7292
|
-
_key: snapshot.context.keyGenerator(),
|
|
7293
|
-
style,
|
|
7294
|
-
markDefs: [],
|
|
7295
|
-
children: [{
|
|
7296
|
-
_type: snapshot.context.schema.span.name,
|
|
7297
|
-
_key: snapshot.context.keyGenerator(),
|
|
7298
|
-
text: "",
|
|
7299
|
-
marks: []
|
|
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
|
-
} : {}
|
|
7220
|
+
},
|
|
7221
|
+
getFragment: () => {
|
|
7222
|
+
const snapshot = getEditorSnapshot({
|
|
7223
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7224
|
+
editorEngineInstance: editor
|
|
7225
|
+
});
|
|
7226
|
+
return getFragment(snapshot).map((entry) => entry.node);
|
|
7227
|
+
},
|
|
7228
|
+
isSelectionsOverlapping: (selectionA, selectionB) => !selectionA || !selectionB ? !1 : rangeIncludes(selectionA, selectionB, editor)
|
|
7321
7229
|
};
|
|
7322
7230
|
}
|
|
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
7231
|
function createBehaviorApiPlugin(editorActor) {
|
|
7346
7232
|
return function(editor) {
|
|
7347
7233
|
const {
|
|
@@ -7522,6 +7408,75 @@ function createHistoryPlugin({
|
|
|
7522
7408
|
}, editor;
|
|
7523
7409
|
};
|
|
7524
7410
|
}
|
|
7411
|
+
function isNormalizing(editor) {
|
|
7412
|
+
return editor.normalizing;
|
|
7413
|
+
}
|
|
7414
|
+
function setNormalizing(editor, isNormalizing2) {
|
|
7415
|
+
editor.normalizing = isNormalizing2;
|
|
7416
|
+
}
|
|
7417
|
+
function withoutNormalizing(editor, fn) {
|
|
7418
|
+
const value = isNormalizing(editor);
|
|
7419
|
+
setNormalizing(editor, !1);
|
|
7420
|
+
try {
|
|
7421
|
+
fn();
|
|
7422
|
+
} finally {
|
|
7423
|
+
setNormalizing(editor, value);
|
|
7424
|
+
}
|
|
7425
|
+
normalize(editor);
|
|
7426
|
+
}
|
|
7427
|
+
function normalize(editor, options = {}) {
|
|
7428
|
+
const {
|
|
7429
|
+
force = !1,
|
|
7430
|
+
operation
|
|
7431
|
+
} = options, getDirtyPaths2 = (editor2) => editor2.dirtyPaths, getDirtyPathKeys = (editor2) => editor2.dirtyPathKeys, popDirtyPath = (editor2) => {
|
|
7432
|
+
const path2 = getDirtyPaths2(editor2).pop(), key = serializePath(path2);
|
|
7433
|
+
return getDirtyPathKeys(editor2).delete(key), path2;
|
|
7434
|
+
};
|
|
7435
|
+
if (isNormalizing(editor)) {
|
|
7436
|
+
if (force) {
|
|
7437
|
+
const allPaths = Array.from(getNodes(editor), (entry) => entry.path), allPathKeys = new Set(allPaths.map((p) => serializePath(p)));
|
|
7438
|
+
editor.dirtyPaths = allPaths, editor.dirtyPathKeys = allPathKeys;
|
|
7439
|
+
}
|
|
7440
|
+
getDirtyPaths2(editor).length !== 0 && withoutNormalizing(editor, () => {
|
|
7441
|
+
for (const dirtyPath of getDirtyPaths2(editor))
|
|
7442
|
+
if (dirtyPath.length !== 0 && hasNode(editor, dirtyPath)) {
|
|
7443
|
+
const entry = getNode(editor, dirtyPath);
|
|
7444
|
+
if (!entry)
|
|
7445
|
+
continue;
|
|
7446
|
+
const entryNode = entry.node;
|
|
7447
|
+
isTextBlock({
|
|
7448
|
+
schema: editor.schema
|
|
7449
|
+
}, entryNode) && entryNode.children.length === 0 && (editor.isNormalizingNode = !0, editor.normalizeNode([entry.node, entry.path], {
|
|
7450
|
+
operation
|
|
7451
|
+
}), editor.isNormalizingNode = !1);
|
|
7452
|
+
}
|
|
7453
|
+
let dirtyPaths = getDirtyPaths2(editor);
|
|
7454
|
+
const initialDirtyPathsLength = dirtyPaths.length;
|
|
7455
|
+
let iteration = 0;
|
|
7456
|
+
for (; dirtyPaths.length !== 0; ) {
|
|
7457
|
+
if (!editor.shouldNormalize({
|
|
7458
|
+
dirtyPaths,
|
|
7459
|
+
iteration,
|
|
7460
|
+
initialDirtyPathsLength,
|
|
7461
|
+
operation
|
|
7462
|
+
}))
|
|
7463
|
+
return;
|
|
7464
|
+
const dirtyPath = popDirtyPath(editor);
|
|
7465
|
+
if (dirtyPath.length === 0)
|
|
7466
|
+
editor.isNormalizingNode = !0, editor.normalizeNode([editor, dirtyPath], {
|
|
7467
|
+
operation
|
|
7468
|
+
}), editor.isNormalizingNode = !1;
|
|
7469
|
+
else if (hasNode(editor, dirtyPath)) {
|
|
7470
|
+
const entry = getNode(editor, dirtyPath);
|
|
7471
|
+
entry && (editor.isNormalizingNode = !0, editor.normalizeNode([entry.node, entry.path], {
|
|
7472
|
+
operation
|
|
7473
|
+
}), editor.isNormalizingNode = !1);
|
|
7474
|
+
}
|
|
7475
|
+
iteration++, dirtyPaths = getDirtyPaths2(editor);
|
|
7476
|
+
}
|
|
7477
|
+
});
|
|
7478
|
+
}
|
|
7479
|
+
}
|
|
7525
7480
|
function cloneDiff(diff2) {
|
|
7526
7481
|
const [type, patch] = diff2;
|
|
7527
7482
|
return [type, patch];
|
|
@@ -8179,7 +8134,7 @@ function getValue(root, path2) {
|
|
|
8179
8134
|
}
|
|
8180
8135
|
return current;
|
|
8181
8136
|
}
|
|
8182
|
-
function
|
|
8137
|
+
function toEngineBlock(block, {
|
|
8183
8138
|
schemaTypes
|
|
8184
8139
|
}) {
|
|
8185
8140
|
const {
|
|
@@ -8371,75 +8326,6 @@ function insertNodePatch(operation) {
|
|
|
8371
8326
|
const arrayFieldPath = operation.path.slice(0, -1);
|
|
8372
8327
|
return arrayFieldPath.length === 0 ? [insert([operation.node], operation.position, operation.path)] : [setIfMissing([], arrayFieldPath), insert([operation.node], operation.position, operation.path)];
|
|
8373
8328
|
}
|
|
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
8329
|
function withRemoteChanges(editor, fn) {
|
|
8444
8330
|
const prev = editor.isProcessingRemoteChanges;
|
|
8445
8331
|
editor.isProcessingRemoteChanges = !0, fn(), editor.isProcessingRemoteChanges = prev;
|
|
@@ -8561,12 +8447,64 @@ function updateSelectionPlugin({
|
|
|
8561
8447
|
}) || updateSelection();
|
|
8562
8448
|
}, editor;
|
|
8563
8449
|
}
|
|
8450
|
+
const levelIndexMaps = /* @__PURE__ */ new Map();
|
|
8451
|
+
function buildIndexMaps(context, {
|
|
8452
|
+
blockIndexMap,
|
|
8453
|
+
listIndexMap
|
|
8454
|
+
}) {
|
|
8455
|
+
blockIndexMap.clear(), listIndexMap.clear(), levelIndexMaps.clear();
|
|
8456
|
+
let previousListItem;
|
|
8457
|
+
for (let blockIndex = 0; blockIndex < context.value.length; blockIndex++) {
|
|
8458
|
+
const block = context.value.at(blockIndex);
|
|
8459
|
+
if (block === void 0)
|
|
8460
|
+
continue;
|
|
8461
|
+
if (blockIndexMap.set(block._key, blockIndex), !isTextBlockNode(context, block)) {
|
|
8462
|
+
levelIndexMaps.clear(), previousListItem = void 0;
|
|
8463
|
+
continue;
|
|
8464
|
+
}
|
|
8465
|
+
if (block.listItem === void 0 || block.level === void 0) {
|
|
8466
|
+
levelIndexMaps.clear(), previousListItem = void 0;
|
|
8467
|
+
continue;
|
|
8468
|
+
}
|
|
8469
|
+
if (!previousListItem) {
|
|
8470
|
+
const levelIndexMap2 = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map();
|
|
8471
|
+
levelIndexMap2.set(block.level, 1), levelIndexMaps.set(block.listItem, levelIndexMap2), listIndexMap.set(block._key, 1), previousListItem = {
|
|
8472
|
+
listItem: block.listItem,
|
|
8473
|
+
level: block.level
|
|
8474
|
+
};
|
|
8475
|
+
continue;
|
|
8476
|
+
}
|
|
8477
|
+
if (previousListItem.listItem === block.listItem && previousListItem.level < block.level) {
|
|
8478
|
+
const levelIndexMap2 = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map();
|
|
8479
|
+
levelIndexMap2.set(block.level, 1), levelIndexMaps.set(block.listItem, levelIndexMap2), listIndexMap.set(block._key, 1), previousListItem = {
|
|
8480
|
+
listItem: block.listItem,
|
|
8481
|
+
level: block.level
|
|
8482
|
+
};
|
|
8483
|
+
continue;
|
|
8484
|
+
}
|
|
8485
|
+
levelIndexMaps.forEach((levelIndexMap2, listItem) => {
|
|
8486
|
+
if (listItem === block.listItem)
|
|
8487
|
+
return;
|
|
8488
|
+
const levelsToDelete = [];
|
|
8489
|
+
levelIndexMap2.forEach((_, level) => {
|
|
8490
|
+
level >= block.level && levelsToDelete.push(level);
|
|
8491
|
+
}), levelsToDelete.forEach((level) => {
|
|
8492
|
+
levelIndexMap2.delete(level);
|
|
8493
|
+
});
|
|
8494
|
+
});
|
|
8495
|
+
const levelIndexMap = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map(), levelCounter = levelIndexMap.get(block.level) ?? 0;
|
|
8496
|
+
levelIndexMap.set(block.level, levelCounter + 1), levelIndexMaps.set(block.listItem, levelIndexMap), listIndexMap.set(block._key, levelCounter + 1), previousListItem = {
|
|
8497
|
+
listItem: block.listItem,
|
|
8498
|
+
level: block.level
|
|
8499
|
+
};
|
|
8500
|
+
}
|
|
8501
|
+
}
|
|
8564
8502
|
function updateValuePlugin(context, editor) {
|
|
8565
8503
|
const {
|
|
8566
8504
|
apply: apply2
|
|
8567
8505
|
} = editor;
|
|
8568
8506
|
return editor.apply = (operation) => {
|
|
8569
|
-
if (editor.isNormalizingNode && debug.normalization.enabled && debug.normalization(`(
|
|
8507
|
+
if (editor.isNormalizingNode && debug.normalization.enabled && debug.normalization(`((engine operation))
|
|
8570
8508
|
${safeStringify(operation, 2)}`), operation.type === "set_selection") {
|
|
8571
8509
|
apply2(operation);
|
|
8572
8510
|
return;
|
|
@@ -9219,15 +9157,15 @@ function applyOperation(editor, op) {
|
|
|
9219
9157
|
}
|
|
9220
9158
|
}
|
|
9221
9159
|
if (transformSelection && editor.selection) {
|
|
9222
|
-
const selection =
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
};
|
|
9160
|
+
const anchor = transformPoint$1(editor.selection.anchor, op), focus = transformPoint$1(editor.selection.focus, op);
|
|
9161
|
+
!anchor || !focus ? editor.selection = null : (anchor !== editor.selection.anchor || focus !== editor.selection.focus) && (editor.selection = {
|
|
9162
|
+
anchor,
|
|
9163
|
+
focus,
|
|
9164
|
+
backward: isBackwardRange({
|
|
9165
|
+
anchor,
|
|
9166
|
+
focus
|
|
9167
|
+
}, editor)
|
|
9168
|
+
});
|
|
9231
9169
|
}
|
|
9232
9170
|
}
|
|
9233
9171
|
function replaceLastSegment(path2, segment) {
|
|
@@ -9766,6 +9704,25 @@ function transformPointForMerge(point2, mergePath, prevKey, position) {
|
|
|
9766
9704
|
offset
|
|
9767
9705
|
};
|
|
9768
9706
|
}
|
|
9707
|
+
function createPlaceholderBlock(snapshot, path2) {
|
|
9708
|
+
const style = resolveDefaultStyle(snapshot, path2);
|
|
9709
|
+
return {
|
|
9710
|
+
_type: snapshot.context.schema.block.name,
|
|
9711
|
+
_key: snapshot.context.keyGenerator(),
|
|
9712
|
+
style,
|
|
9713
|
+
markDefs: [],
|
|
9714
|
+
children: [{
|
|
9715
|
+
_type: snapshot.context.schema.span.name,
|
|
9716
|
+
_key: snapshot.context.keyGenerator(),
|
|
9717
|
+
text: "",
|
|
9718
|
+
marks: []
|
|
9719
|
+
}]
|
|
9720
|
+
};
|
|
9721
|
+
}
|
|
9722
|
+
function resolveDefaultStyle(snapshot, path2) {
|
|
9723
|
+
const rootFallback = snapshot.context.schema.styles[0]?.name ?? "normal";
|
|
9724
|
+
return path2 ? getPathSubSchema(snapshot, path2).styles[0]?.name ?? rootFallback : rootFallback;
|
|
9725
|
+
}
|
|
9769
9726
|
function setNodeProperties(editor, props, path2) {
|
|
9770
9727
|
const nodeEntry = getNode(editor, path2);
|
|
9771
9728
|
if (!nodeEntry)
|
|
@@ -10427,8 +10384,46 @@ const shouldNormalize = (_editor, {
|
|
|
10427
10384
|
onContextChange && onContextChange(options), onChange(options);
|
|
10428
10385
|
}, e;
|
|
10429
10386
|
};
|
|
10430
|
-
function
|
|
10431
|
-
|
|
10387
|
+
function buildPublicContainers(resolved) {
|
|
10388
|
+
const projected = /* @__PURE__ */ new Map();
|
|
10389
|
+
for (const [type, config] of resolved)
|
|
10390
|
+
projected.set(type, toRegisteredContainer(config));
|
|
10391
|
+
return projected;
|
|
10392
|
+
}
|
|
10393
|
+
function toRegisteredContainer(config) {
|
|
10394
|
+
return {
|
|
10395
|
+
kind: "container",
|
|
10396
|
+
type: config.container.type,
|
|
10397
|
+
field: config.field,
|
|
10398
|
+
...config.of ? {
|
|
10399
|
+
of: config.of.map(toRegisteredOfEntry).filter(isDefined)
|
|
10400
|
+
} : {}
|
|
10401
|
+
};
|
|
10402
|
+
}
|
|
10403
|
+
function toRegisteredOfEntry(entry) {
|
|
10404
|
+
if ("container" in entry)
|
|
10405
|
+
return toRegisteredContainer(entry);
|
|
10406
|
+
if ("span" in entry)
|
|
10407
|
+
return {
|
|
10408
|
+
kind: "span",
|
|
10409
|
+
type: entry.span.type
|
|
10410
|
+
};
|
|
10411
|
+
if ("blockObject" in entry)
|
|
10412
|
+
return {
|
|
10413
|
+
kind: "blockObject",
|
|
10414
|
+
type: entry.blockObject.type
|
|
10415
|
+
};
|
|
10416
|
+
if ("inlineObject" in entry)
|
|
10417
|
+
return {
|
|
10418
|
+
kind: "inlineObject",
|
|
10419
|
+
type: entry.inlineObject.type
|
|
10420
|
+
};
|
|
10421
|
+
}
|
|
10422
|
+
function isDefined(value) {
|
|
10423
|
+
return value !== void 0;
|
|
10424
|
+
}
|
|
10425
|
+
function createEditorEngine(config) {
|
|
10426
|
+
debug.setup("creating new editor engine instance");
|
|
10432
10427
|
const context = config.editorActor.getSnapshot().context, placeholderBlock = createPlaceholderBlock({
|
|
10433
10428
|
context: {
|
|
10434
10429
|
schema: context.schema,
|
|
@@ -10442,27 +10437,27 @@ function createSlateEditor(config) {
|
|
|
10442
10437
|
undos: [],
|
|
10443
10438
|
redos: []
|
|
10444
10439
|
}, 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
|
|
10440
|
+
const editorEngine = plugins(withDOM(editor), {
|
|
10446
10441
|
editorActor: config.editorActor,
|
|
10447
10442
|
relayActor: config.relayActor,
|
|
10448
10443
|
subscriptions: config.subscriptions
|
|
10449
10444
|
});
|
|
10450
10445
|
return buildIndexMaps({
|
|
10451
10446
|
schema: context.schema,
|
|
10452
|
-
value:
|
|
10447
|
+
value: editorEngine.children
|
|
10453
10448
|
}, {
|
|
10454
|
-
blockIndexMap:
|
|
10455
|
-
listIndexMap:
|
|
10456
|
-
}),
|
|
10449
|
+
blockIndexMap: editorEngine.blockIndexMap,
|
|
10450
|
+
listIndexMap: editorEngine.listIndexMap
|
|
10451
|
+
}), editorEngine;
|
|
10457
10452
|
}
|
|
10458
|
-
function createEditorDom(sendBack,
|
|
10453
|
+
function createEditorDom(sendBack, editorEngine) {
|
|
10459
10454
|
return {
|
|
10460
|
-
getBlockNodes: (snapshot) => getBlockNodes(
|
|
10461
|
-
getChildNodes: (snapshot) => getChildNodes(
|
|
10462
|
-
getEditorElement: () => getEditorElement(
|
|
10455
|
+
getBlockNodes: (snapshot) => getBlockNodes(editorEngine, snapshot),
|
|
10456
|
+
getChildNodes: (snapshot) => getChildNodes(editorEngine, snapshot),
|
|
10457
|
+
getEditorElement: () => getEditorElement(editorEngine),
|
|
10463
10458
|
getSelectionRect: (snapshot) => getSelectionRect(snapshot),
|
|
10464
|
-
getStartBlockElement: (snapshot) => getStartBlockElement(
|
|
10465
|
-
getEndBlockElement: (snapshot) => getEndBlockElement(
|
|
10459
|
+
getStartBlockElement: (snapshot) => getStartBlockElement(editorEngine, snapshot),
|
|
10460
|
+
getEndBlockElement: (snapshot) => getEndBlockElement(editorEngine, snapshot),
|
|
10466
10461
|
setDragGhost: ({
|
|
10467
10462
|
event,
|
|
10468
10463
|
ghost
|
|
@@ -10473,25 +10468,25 @@ function createEditorDom(sendBack, slateEditor) {
|
|
|
10473
10468
|
})
|
|
10474
10469
|
};
|
|
10475
10470
|
}
|
|
10476
|
-
function getBlockNodes(
|
|
10471
|
+
function getBlockNodes(editorEngine, snapshot) {
|
|
10477
10472
|
if (!snapshot.context.selection)
|
|
10478
10473
|
return [];
|
|
10479
10474
|
try {
|
|
10480
10475
|
return getFragment(snapshot).flatMap((entry) => {
|
|
10481
|
-
const domNode = getDomNode(
|
|
10476
|
+
const domNode = getDomNode(editorEngine, entry.path);
|
|
10482
10477
|
return domNode ? [domNode] : [];
|
|
10483
10478
|
});
|
|
10484
10479
|
} catch {
|
|
10485
10480
|
return [];
|
|
10486
10481
|
}
|
|
10487
10482
|
}
|
|
10488
|
-
function getChildNodes(
|
|
10483
|
+
function getChildNodes(editorEngine, snapshot) {
|
|
10489
10484
|
if (!snapshot.context.selection)
|
|
10490
10485
|
return [];
|
|
10491
10486
|
try {
|
|
10492
|
-
const [start2, end2] = rangeEdges(snapshot.context.selection,
|
|
10487
|
+
const [start2, end2] = rangeEdges(snapshot.context.selection, editorEngine), childEntries = [];
|
|
10493
10488
|
let buffered;
|
|
10494
|
-
for (const entry of getNodes(
|
|
10489
|
+
for (const entry of getNodes(editorEngine, {
|
|
10495
10490
|
from: start2.path,
|
|
10496
10491
|
to: end2.path
|
|
10497
10492
|
})) {
|
|
@@ -10505,13 +10500,13 @@ function getChildNodes(slateEditor, snapshot) {
|
|
|
10505
10500
|
}
|
|
10506
10501
|
buffered = entry;
|
|
10507
10502
|
}
|
|
10508
|
-
return buffered && childEntries.push(buffered), childEntries.flatMap((childEntry) => getDomNode(
|
|
10503
|
+
return buffered && childEntries.push(buffered), childEntries.flatMap((childEntry) => getDomNode(editorEngine, childEntry.path) || []);
|
|
10509
10504
|
} catch {
|
|
10510
10505
|
return [];
|
|
10511
10506
|
}
|
|
10512
10507
|
}
|
|
10513
|
-
function getEditorElement(
|
|
10514
|
-
return getDomNode(
|
|
10508
|
+
function getEditorElement(editorEngine) {
|
|
10509
|
+
return getDomNode(editorEngine, []);
|
|
10515
10510
|
}
|
|
10516
10511
|
function getSelectionRect(snapshot) {
|
|
10517
10512
|
if (!snapshot.context.selection)
|
|
@@ -10523,18 +10518,18 @@ function getSelectionRect(snapshot) {
|
|
|
10523
10518
|
return null;
|
|
10524
10519
|
}
|
|
10525
10520
|
}
|
|
10526
|
-
function getStartBlockElement(
|
|
10521
|
+
function getStartBlockElement(editorEngine, snapshot) {
|
|
10527
10522
|
const startBlock = getSelectionStartBlock(snapshot);
|
|
10528
10523
|
if (!startBlock)
|
|
10529
10524
|
return null;
|
|
10530
|
-
const startBlockNode = getDomNode(
|
|
10525
|
+
const startBlockNode = getDomNode(editorEngine, startBlock.path);
|
|
10531
10526
|
return startBlockNode instanceof Element ? startBlockNode : null;
|
|
10532
10527
|
}
|
|
10533
|
-
function getEndBlockElement(
|
|
10528
|
+
function getEndBlockElement(editorEngine, snapshot) {
|
|
10534
10529
|
const endBlock = getSelectionEndBlock(snapshot);
|
|
10535
10530
|
if (!endBlock)
|
|
10536
10531
|
return null;
|
|
10537
|
-
const endBlockNode = getDomNode(
|
|
10532
|
+
const endBlockNode = getDomNode(editorEngine, endBlock.path);
|
|
10538
10533
|
return endBlockNode instanceof Element ? endBlockNode : null;
|
|
10539
10534
|
}
|
|
10540
10535
|
function setDragGhost({
|
|
@@ -12061,6 +12056,13 @@ function createEditorSnapshot({
|
|
|
12061
12056
|
decoratorState: editor.decoratorState
|
|
12062
12057
|
};
|
|
12063
12058
|
}
|
|
12059
|
+
function withPerformingBehaviorOperation(editor, fn) {
|
|
12060
|
+
const prev = editor.isPerformingBehaviorOperation;
|
|
12061
|
+
editor.isPerformingBehaviorOperation = !0, fn(), editor.isPerformingBehaviorOperation = prev;
|
|
12062
|
+
}
|
|
12063
|
+
function withoutNormalizingConditional(editor, predicate, fn) {
|
|
12064
|
+
predicate() ? withoutNormalizing(editor, fn) : fn();
|
|
12065
|
+
}
|
|
12064
12066
|
const addAnnotationOperationImplementation = ({
|
|
12065
12067
|
snapshot,
|
|
12066
12068
|
operation
|
|
@@ -12282,8 +12284,8 @@ const blockSetOperationImplementation = ({
|
|
|
12282
12284
|
} = snapshot, blockEntry = getNode(operation.editor, operation.at);
|
|
12283
12285
|
if (!blockEntry)
|
|
12284
12286
|
throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
|
|
12285
|
-
const
|
|
12286
|
-
if (isTextBlockNode(context,
|
|
12287
|
+
const engineBlock = blockEntry.node;
|
|
12288
|
+
if (isTextBlockNode(context, engineBlock)) {
|
|
12287
12289
|
const subSchema = getPathSubSchema(snapshot, blockEntry.path), filteredProps = {};
|
|
12288
12290
|
for (const key of Object.keys(operation.props))
|
|
12289
12291
|
if (key !== "_type") {
|
|
@@ -12321,7 +12323,7 @@ const blockSetOperationImplementation = ({
|
|
|
12321
12323
|
}
|
|
12322
12324
|
setNodeProperties(operation.editor, filteredProps, blockEntry.path);
|
|
12323
12325
|
} else {
|
|
12324
|
-
const schemaDefinition = getBlockObjectSchema(snapshot,
|
|
12326
|
+
const schemaDefinition = getBlockObjectSchema(snapshot, engineBlock, blockEntry.path), filteredProps = {};
|
|
12325
12327
|
for (const key of Object.keys(operation.props))
|
|
12326
12328
|
if (key !== "_type") {
|
|
12327
12329
|
if (key === "_key") {
|
|
@@ -12330,8 +12332,8 @@ const blockSetOperationImplementation = ({
|
|
|
12330
12332
|
}
|
|
12331
12333
|
schemaDefinition?.fields?.some((field) => field.name === key) && (filteredProps[key] = operation.props[key]);
|
|
12332
12334
|
}
|
|
12333
|
-
const patches = Object.entries(filteredProps).map(([key, value]) => set(value, [key])),
|
|
12334
|
-
setNodeProperties(operation.editor,
|
|
12335
|
+
const patches = Object.entries(filteredProps).map(([key, value]) => set(value, [key])), updatedEngineBlock = applyAll(engineBlock, patches);
|
|
12336
|
+
setNodeProperties(operation.editor, updatedEngineBlock, blockEntry.path);
|
|
12335
12337
|
}
|
|
12336
12338
|
}, blockUnsetOperationImplementation = ({
|
|
12337
12339
|
snapshot,
|
|
@@ -12342,8 +12344,8 @@ const blockSetOperationImplementation = ({
|
|
|
12342
12344
|
} = snapshot, blockEntry = getNode(operation.editor, operation.at);
|
|
12343
12345
|
if (!blockEntry)
|
|
12344
12346
|
throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
|
|
12345
|
-
const
|
|
12346
|
-
if (isTextBlockNode(context,
|
|
12347
|
+
const engineBlock = blockEntry.node;
|
|
12348
|
+
if (isTextBlockNode(context, engineBlock)) {
|
|
12347
12349
|
const propsToRemove = operation.props.filter((prop) => prop !== "_type" && prop !== "_key"), unsetProps2 = {};
|
|
12348
12350
|
for (const prop of propsToRemove)
|
|
12349
12351
|
unsetProps2[prop] = null;
|
|
@@ -12630,6 +12632,58 @@ const childSetOperationImplementation = ({
|
|
|
12630
12632
|
}
|
|
12631
12633
|
}
|
|
12632
12634
|
};
|
|
12635
|
+
function unhangRange(snapshot, range2) {
|
|
12636
|
+
const {
|
|
12637
|
+
context
|
|
12638
|
+
} = snapshot;
|
|
12639
|
+
let [start2, end2] = rangeEdges(range2, {
|
|
12640
|
+
children: context.value
|
|
12641
|
+
});
|
|
12642
|
+
if (start2.offset !== 0 || end2.offset !== 0 || isCollapsedRange(range2) || getSibling(snapshot, end2.path, "previous") !== void 0)
|
|
12643
|
+
return range2;
|
|
12644
|
+
const endBlock = getAncestorTextBlock(snapshot, end2.path), blockPath = endBlock ? endBlock.path : [];
|
|
12645
|
+
for (const {
|
|
12646
|
+
path: path2
|
|
12647
|
+
} of getNodes(snapshot, {
|
|
12648
|
+
from: start2.path,
|
|
12649
|
+
to: end2.path,
|
|
12650
|
+
match: (candidate, candidatePath) => isVoidNode(snapshot, candidate, candidatePath) || isEditableContainer(snapshot, candidate, candidatePath)
|
|
12651
|
+
}))
|
|
12652
|
+
if (!isAncestorPath(path2, start2.path) && !isAncestorPath(path2, end2.path))
|
|
12653
|
+
return range2;
|
|
12654
|
+
let skip = !0;
|
|
12655
|
+
for (const {
|
|
12656
|
+
node,
|
|
12657
|
+
path: nodePath
|
|
12658
|
+
} of getNodes(snapshot, {
|
|
12659
|
+
from: start2.path,
|
|
12660
|
+
to: end2.path,
|
|
12661
|
+
match: (n) => isSpan({
|
|
12662
|
+
schema: context.schema
|
|
12663
|
+
}, n),
|
|
12664
|
+
reverse: !0
|
|
12665
|
+
})) {
|
|
12666
|
+
if (skip) {
|
|
12667
|
+
skip = !1;
|
|
12668
|
+
continue;
|
|
12669
|
+
}
|
|
12670
|
+
if (isSpan({
|
|
12671
|
+
schema: context.schema
|
|
12672
|
+
}, node) && (node.text !== "" || isBeforePath(nodePath, blockPath, {
|
|
12673
|
+
children: context.value
|
|
12674
|
+
}))) {
|
|
12675
|
+
end2 = {
|
|
12676
|
+
path: nodePath,
|
|
12677
|
+
offset: node.text.length
|
|
12678
|
+
};
|
|
12679
|
+
break;
|
|
12680
|
+
}
|
|
12681
|
+
}
|
|
12682
|
+
return {
|
|
12683
|
+
anchor: start2,
|
|
12684
|
+
focus: end2
|
|
12685
|
+
};
|
|
12686
|
+
}
|
|
12633
12687
|
function getHighestObjectNode(snapshot, path2) {
|
|
12634
12688
|
const ancestors = getAncestors(snapshot, path2);
|
|
12635
12689
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
@@ -13125,58 +13179,6 @@ function isEmptyContainer(snapshot, path2) {
|
|
|
13125
13179
|
const children = getChildren(snapshot, path2);
|
|
13126
13180
|
return children.length === 1 && isEmptyTextBlock(snapshot.context, children[0].node);
|
|
13127
13181
|
}
|
|
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
13182
|
const deleteOperationImplementation = ({
|
|
13181
13183
|
operation
|
|
13182
13184
|
}) => {
|
|
@@ -13239,6 +13241,10 @@ const deleteOperationImplementation = ({
|
|
|
13239
13241
|
removeEmptyStartBlock: !0
|
|
13240
13242
|
});
|
|
13241
13243
|
};
|
|
13244
|
+
function pluginRedoing(editor, fn) {
|
|
13245
|
+
const prev = editor.isRedoing;
|
|
13246
|
+
editor.isRedoing = !0, fn(), editor.isRedoing = prev;
|
|
13247
|
+
}
|
|
13242
13248
|
function transformOperation(editor, patch, operation) {
|
|
13243
13249
|
const snapshot = editor, transformedOperation = {
|
|
13244
13250
|
...operation
|
|
@@ -13292,10 +13298,6 @@ function findOperationTargetBlock(snapshot, editor, operation) {
|
|
|
13292
13298
|
function pathStartsWith(path2, prefix) {
|
|
13293
13299
|
return pathEquals(path2, prefix) || isAncestorPath(prefix, path2);
|
|
13294
13300
|
}
|
|
13295
|
-
function pluginRedoing(editor, fn) {
|
|
13296
|
-
const prev = editor.isRedoing;
|
|
13297
|
-
editor.isRedoing = !0, fn(), editor.isRedoing = prev;
|
|
13298
|
-
}
|
|
13299
13301
|
const historyRedoOperationImplementation = ({
|
|
13300
13302
|
operation
|
|
13301
13303
|
}) => {
|
|
@@ -13478,7 +13480,7 @@ const historyUndoOperationImplementation = ({
|
|
|
13478
13480
|
});
|
|
13479
13481
|
if (!parsedBlock)
|
|
13480
13482
|
return;
|
|
13481
|
-
const block =
|
|
13483
|
+
const block = toEngineBlock(parsedBlock, {
|
|
13482
13484
|
schemaTypes: context.schema
|
|
13483
13485
|
}), target = resolveTarget({
|
|
13484
13486
|
editor,
|
|
@@ -14060,27 +14062,6 @@ const moveBackwardOperationImplementation = ({
|
|
|
14060
14062
|
distance: operation.distance,
|
|
14061
14063
|
reverse: !0
|
|
14062
14064
|
});
|
|
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
14065
|
}, moveForwardOperationImplementation = ({
|
|
14085
14066
|
operation
|
|
14086
14067
|
}) => {
|
|
@@ -14134,7 +14115,6 @@ const moveBackwardOperationImplementation = ({
|
|
|
14134
14115
|
"insert.child": insertChildOperationImplementation,
|
|
14135
14116
|
"insert.text": insertTextOperationImplementation,
|
|
14136
14117
|
"move.backward": moveBackwardOperationImplementation,
|
|
14137
|
-
"move.block": moveBlockOperationImplementation,
|
|
14138
14118
|
"move.forward": moveForwardOperationImplementation,
|
|
14139
14119
|
"remove.text": removeTextOperationImplementation,
|
|
14140
14120
|
select: selectOperationImplementation,
|
|
@@ -14158,13 +14138,6 @@ function performOperation({
|
|
|
14158
14138
|
};
|
|
14159
14139
|
isNormalizing(operation.editor) ? withoutNormalizing(operation.editor, perform) : perform();
|
|
14160
14140
|
}
|
|
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
14141
|
const abstractAnnotationBehaviors = [defineBehavior({
|
|
14169
14142
|
on: "annotation.set",
|
|
14170
14143
|
guard: ({
|
|
@@ -15306,7 +15279,7 @@ const abstractInsertBehaviors = [
|
|
|
15306
15279
|
}]
|
|
15307
15280
|
}), abstractKeyboardBehaviors = [
|
|
15308
15281
|
/**
|
|
15309
|
-
* When Backspace is pressed on an inline object,
|
|
15282
|
+
* When Backspace is pressed on an inline object, the engine raises a
|
|
15310
15283
|
* `delete.backward` event with `unit: 'block'`. This is wrong and this
|
|
15311
15284
|
* Behavior adjusts that.
|
|
15312
15285
|
*/
|
|
@@ -15322,7 +15295,7 @@ const abstractInsertBehaviors = [
|
|
|
15322
15295
|
})]]
|
|
15323
15296
|
}),
|
|
15324
15297
|
/**
|
|
15325
|
-
* When Delete is pressed on an inline object,
|
|
15298
|
+
* When Delete is pressed on an inline object, the engine raises a
|
|
15326
15299
|
* `delete.forward` event with `unit: 'block'`. This is wrong and this
|
|
15327
15300
|
* Behavior adjusts that.
|
|
15328
15301
|
*/
|
|
@@ -15525,6 +15498,35 @@ const abstractInsertBehaviors = [
|
|
|
15525
15498
|
listItem: event.listItem
|
|
15526
15499
|
})]]
|
|
15527
15500
|
})], abstractMoveBehaviors = [defineBehavior({
|
|
15501
|
+
on: "move.block",
|
|
15502
|
+
guard: ({
|
|
15503
|
+
snapshot,
|
|
15504
|
+
event
|
|
15505
|
+
}) => {
|
|
15506
|
+
const originEntry = getNode(snapshot, event.at), destinationEntry = getNode(snapshot, event.to);
|
|
15507
|
+
if (!originEntry || !destinationEntry || pathEquals(originEntry.path, destinationEntry.path))
|
|
15508
|
+
return !1;
|
|
15509
|
+
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;
|
|
15510
|
+
return {
|
|
15511
|
+
originEntry,
|
|
15512
|
+
destinationEntry,
|
|
15513
|
+
movingDown
|
|
15514
|
+
};
|
|
15515
|
+
},
|
|
15516
|
+
actions: [(_, {
|
|
15517
|
+
originEntry,
|
|
15518
|
+
destinationEntry,
|
|
15519
|
+
movingDown
|
|
15520
|
+
}) => [raise({
|
|
15521
|
+
type: "unset",
|
|
15522
|
+
at: originEntry.path
|
|
15523
|
+
}), raise({
|
|
15524
|
+
type: "insert",
|
|
15525
|
+
at: destinationEntry.path,
|
|
15526
|
+
value: originEntry.node,
|
|
15527
|
+
position: movingDown ? "after" : "before"
|
|
15528
|
+
})]]
|
|
15529
|
+
}), defineBehavior({
|
|
15528
15530
|
on: "move.block up",
|
|
15529
15531
|
guard: ({
|
|
15530
15532
|
snapshot,
|
|
@@ -15532,18 +15534,26 @@ const abstractInsertBehaviors = [
|
|
|
15532
15534
|
}) => {
|
|
15533
15535
|
const previousSibling = getSibling(snapshot, event.at, "previous");
|
|
15534
15536
|
return previousSibling ? {
|
|
15535
|
-
previousSibling
|
|
15537
|
+
previousSibling,
|
|
15538
|
+
savedSelection: snapshot.context.selection
|
|
15536
15539
|
} : !1;
|
|
15537
15540
|
},
|
|
15538
15541
|
actions: [({
|
|
15539
15542
|
event
|
|
15540
15543
|
}, {
|
|
15541
|
-
previousSibling
|
|
15542
|
-
|
|
15543
|
-
|
|
15544
|
-
|
|
15545
|
-
|
|
15546
|
-
|
|
15544
|
+
previousSibling,
|
|
15545
|
+
savedSelection
|
|
15546
|
+
}) => {
|
|
15547
|
+
const actions = [raise({
|
|
15548
|
+
type: "move.block",
|
|
15549
|
+
at: event.at,
|
|
15550
|
+
to: previousSibling.path
|
|
15551
|
+
})];
|
|
15552
|
+
return savedSelection && actions.push(raise({
|
|
15553
|
+
type: "select",
|
|
15554
|
+
at: savedSelection
|
|
15555
|
+
})), actions;
|
|
15556
|
+
}]
|
|
15547
15557
|
}), defineBehavior({
|
|
15548
15558
|
on: "move.block down",
|
|
15549
15559
|
guard: ({
|
|
@@ -15552,18 +15562,26 @@ const abstractInsertBehaviors = [
|
|
|
15552
15562
|
}) => {
|
|
15553
15563
|
const nextSibling = getSibling(snapshot, event.at, "next");
|
|
15554
15564
|
return nextSibling ? {
|
|
15555
|
-
nextSibling
|
|
15565
|
+
nextSibling,
|
|
15566
|
+
savedSelection: snapshot.context.selection
|
|
15556
15567
|
} : !1;
|
|
15557
15568
|
},
|
|
15558
15569
|
actions: [({
|
|
15559
15570
|
event
|
|
15560
15571
|
}, {
|
|
15561
|
-
nextSibling
|
|
15562
|
-
|
|
15563
|
-
|
|
15564
|
-
|
|
15565
|
-
|
|
15566
|
-
|
|
15572
|
+
nextSibling,
|
|
15573
|
+
savedSelection
|
|
15574
|
+
}) => {
|
|
15575
|
+
const actions = [raise({
|
|
15576
|
+
type: "move.block",
|
|
15577
|
+
at: event.at,
|
|
15578
|
+
to: nextSibling.path
|
|
15579
|
+
})];
|
|
15580
|
+
return savedSelection && actions.push(raise({
|
|
15581
|
+
type: "select",
|
|
15582
|
+
at: savedSelection
|
|
15583
|
+
})), actions;
|
|
15584
|
+
}]
|
|
15567
15585
|
})], abstractSelectBehaviors = [defineBehavior({
|
|
15568
15586
|
on: "select.block",
|
|
15569
15587
|
guard: ({
|
|
@@ -15955,7 +15973,7 @@ const abstractInsertBehaviors = [
|
|
|
15955
15973
|
function isSyntheticBehaviorEvent(event) {
|
|
15956
15974
|
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
15957
15975
|
}
|
|
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"];
|
|
15976
|
+
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
15977
|
function isAbstractBehaviorEvent(event) {
|
|
15960
15978
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
15961
15979
|
}
|
|
@@ -16310,18 +16328,18 @@ function isTypeAlreadyRegistered(maps, attempting, type) {
|
|
|
16310
16328
|
}
|
|
16311
16329
|
function rerouteExternalBehaviorEvent({
|
|
16312
16330
|
event,
|
|
16313
|
-
|
|
16331
|
+
editorEngine
|
|
16314
16332
|
}) {
|
|
16315
16333
|
switch (event.type) {
|
|
16316
16334
|
case "blur":
|
|
16317
16335
|
return {
|
|
16318
16336
|
type: "blur",
|
|
16319
|
-
editor:
|
|
16337
|
+
editor: editorEngine
|
|
16320
16338
|
};
|
|
16321
16339
|
case "focus":
|
|
16322
16340
|
return {
|
|
16323
16341
|
type: "focus",
|
|
16324
|
-
editor:
|
|
16342
|
+
editor: editorEngine
|
|
16325
16343
|
};
|
|
16326
16344
|
case "insert.block object":
|
|
16327
16345
|
return {
|
|
@@ -16334,13 +16352,13 @@ function rerouteExternalBehaviorEvent({
|
|
|
16334
16352
|
},
|
|
16335
16353
|
placement: event.placement
|
|
16336
16354
|
},
|
|
16337
|
-
editor:
|
|
16355
|
+
editor: editorEngine
|
|
16338
16356
|
};
|
|
16339
16357
|
default:
|
|
16340
16358
|
return {
|
|
16341
16359
|
type: "behavior event",
|
|
16342
16360
|
behaviorEvent: event,
|
|
16343
|
-
editor:
|
|
16361
|
+
editor: editorEngine
|
|
16344
16362
|
};
|
|
16345
16363
|
}
|
|
16346
16364
|
}
|
|
@@ -16366,11 +16384,11 @@ const editorMachine = setup({
|
|
|
16366
16384
|
event
|
|
16367
16385
|
}) => (assertEvent(event, "remove behavior"), context.behaviors.delete(event.behaviorConfig), /* @__PURE__ */ new Set([...context.behaviors]))
|
|
16368
16386
|
}),
|
|
16369
|
-
"add
|
|
16370
|
-
|
|
16387
|
+
"add editor engine to context": assign({
|
|
16388
|
+
editorEngine: ({
|
|
16371
16389
|
context,
|
|
16372
16390
|
event
|
|
16373
|
-
}) => event.type === "add
|
|
16391
|
+
}) => event.type === "add editor engine" ? event.editor : context.editorEngine
|
|
16374
16392
|
}),
|
|
16375
16393
|
register: assign(({
|
|
16376
16394
|
context,
|
|
@@ -16385,9 +16403,9 @@ const editorMachine = setup({
|
|
|
16385
16403
|
if (!containerConfig)
|
|
16386
16404
|
return {};
|
|
16387
16405
|
const containers = new Map(context.containers);
|
|
16388
|
-
return containers.set(node.type, containerConfig), context.
|
|
16406
|
+
return containers.set(node.type, containerConfig), context.editorEngine && (context.editorEngine.containers = containers, context.editorEngine.publicContainers = buildPublicContainers(containers), normalize(context.editorEngine, {
|
|
16389
16407
|
force: !0
|
|
16390
|
-
}), context.
|
|
16408
|
+
}), context.editorEngine.onChange()), {
|
|
16391
16409
|
containers
|
|
16392
16410
|
};
|
|
16393
16411
|
}
|
|
@@ -16395,7 +16413,7 @@ const editorMachine = setup({
|
|
|
16395
16413
|
if (isTypeAlreadyRegistered(context, "textBlock", node.type))
|
|
16396
16414
|
return {};
|
|
16397
16415
|
const textBlocks = new Map(context.textBlocks);
|
|
16398
|
-
return textBlocks.set(node.type, resolveTextBlockConfig(node)), context.
|
|
16416
|
+
return textBlocks.set(node.type, resolveTextBlockConfig(node)), context.editorEngine && (context.editorEngine.textBlocks = textBlocks, context.editorEngine.onChange()), {
|
|
16399
16417
|
textBlocks
|
|
16400
16418
|
};
|
|
16401
16419
|
}
|
|
@@ -16405,7 +16423,7 @@ const editorMachine = setup({
|
|
|
16405
16423
|
const spans = new Map(context.spans);
|
|
16406
16424
|
return spans.set(node.type, {
|
|
16407
16425
|
span: node
|
|
16408
|
-
}), context.
|
|
16426
|
+
}), context.editorEngine && (context.editorEngine.spans = spans, context.editorEngine.onChange()), {
|
|
16409
16427
|
spans
|
|
16410
16428
|
};
|
|
16411
16429
|
}
|
|
@@ -16415,7 +16433,7 @@ const editorMachine = setup({
|
|
|
16415
16433
|
const blockObjects = new Map(context.blockObjects);
|
|
16416
16434
|
return blockObjects.set(node.type, {
|
|
16417
16435
|
blockObject: node
|
|
16418
|
-
}), context.
|
|
16436
|
+
}), context.editorEngine && (context.editorEngine.blockObjects = blockObjects, context.editorEngine.onChange()), {
|
|
16419
16437
|
blockObjects
|
|
16420
16438
|
};
|
|
16421
16439
|
}
|
|
@@ -16424,7 +16442,7 @@ const editorMachine = setup({
|
|
|
16424
16442
|
const inlineObjects = new Map(context.inlineObjects);
|
|
16425
16443
|
return inlineObjects.set(node.type, {
|
|
16426
16444
|
inlineObject: node
|
|
16427
|
-
}), context.
|
|
16445
|
+
}), context.editorEngine && (context.editorEngine.inlineObjects = inlineObjects, context.editorEngine.onChange()), {
|
|
16428
16446
|
inlineObjects
|
|
16429
16447
|
};
|
|
16430
16448
|
}),
|
|
@@ -16436,41 +16454,41 @@ const editorMachine = setup({
|
|
|
16436
16454
|
const node = event.node;
|
|
16437
16455
|
if (node.kind === "container") {
|
|
16438
16456
|
const containers = new Map(context.containers);
|
|
16439
|
-
return containers.delete(node.type), context.
|
|
16457
|
+
return containers.delete(node.type), context.editorEngine && (context.editorEngine.containers = containers, context.editorEngine.publicContainers = buildPublicContainers(containers), normalize(context.editorEngine, {
|
|
16440
16458
|
force: !0
|
|
16441
|
-
}), context.
|
|
16459
|
+
}), context.editorEngine.onChange()), {
|
|
16442
16460
|
containers
|
|
16443
16461
|
};
|
|
16444
16462
|
}
|
|
16445
16463
|
if (node.kind === "textBlock") {
|
|
16446
16464
|
const textBlocks = new Map(context.textBlocks);
|
|
16447
|
-
return textBlocks.delete(node.type), context.
|
|
16465
|
+
return textBlocks.delete(node.type), context.editorEngine && (context.editorEngine.textBlocks = textBlocks, context.editorEngine.onChange()), {
|
|
16448
16466
|
textBlocks
|
|
16449
16467
|
};
|
|
16450
16468
|
}
|
|
16451
16469
|
if (node.kind === "span") {
|
|
16452
16470
|
const spans = new Map(context.spans);
|
|
16453
|
-
return spans.delete(node.type), context.
|
|
16471
|
+
return spans.delete(node.type), context.editorEngine && (context.editorEngine.spans = spans, context.editorEngine.onChange()), {
|
|
16454
16472
|
spans
|
|
16455
16473
|
};
|
|
16456
16474
|
}
|
|
16457
16475
|
if (node.kind === "blockObject") {
|
|
16458
16476
|
const blockObjects = new Map(context.blockObjects);
|
|
16459
|
-
return blockObjects.delete(node.type), context.
|
|
16477
|
+
return blockObjects.delete(node.type), context.editorEngine && (context.editorEngine.blockObjects = blockObjects, context.editorEngine.onChange()), {
|
|
16460
16478
|
blockObjects
|
|
16461
16479
|
};
|
|
16462
16480
|
}
|
|
16463
16481
|
const inlineObjects = new Map(context.inlineObjects);
|
|
16464
|
-
return inlineObjects.delete(node.type), context.
|
|
16482
|
+
return inlineObjects.delete(node.type), context.editorEngine && (context.editorEngine.inlineObjects = inlineObjects, context.editorEngine.onChange()), {
|
|
16465
16483
|
inlineObjects
|
|
16466
16484
|
};
|
|
16467
16485
|
}),
|
|
16468
|
-
"attach maps to
|
|
16486
|
+
"attach maps to editor engine": ({
|
|
16469
16487
|
context
|
|
16470
16488
|
}) => {
|
|
16471
|
-
context.
|
|
16489
|
+
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
16490
|
force: !0
|
|
16473
|
-
}), context.
|
|
16491
|
+
}), context.editorEngine.onChange());
|
|
16474
16492
|
},
|
|
16475
16493
|
"emit patch event": emit(({
|
|
16476
16494
|
event
|
|
@@ -16546,14 +16564,14 @@ const editorMachine = setup({
|
|
|
16546
16564
|
"handle focus": ({
|
|
16547
16565
|
context
|
|
16548
16566
|
}) => {
|
|
16549
|
-
const
|
|
16550
|
-
if (!
|
|
16551
|
-
console.error("No
|
|
16567
|
+
const editorEngine = context.editorEngine;
|
|
16568
|
+
if (!editorEngine) {
|
|
16569
|
+
console.error("No editor engine found to focus");
|
|
16552
16570
|
return;
|
|
16553
16571
|
}
|
|
16554
16572
|
try {
|
|
16555
|
-
const currentSelection =
|
|
16556
|
-
DOMEditor.focus(
|
|
16573
|
+
const currentSelection = editorEngine.selection;
|
|
16574
|
+
DOMEditor.focus(editorEngine), currentSelection && (editorEngine.select(currentSelection), editorEngine.pendingSelection = editorEngine.selection, editorEngine.onChange());
|
|
16557
16575
|
} catch (error) {
|
|
16558
16576
|
console.error(new Error(`Failed to focus editor: ${error instanceof Error ? error.message : error}`));
|
|
16559
16577
|
}
|
|
@@ -16586,7 +16604,7 @@ const editorMachine = setup({
|
|
|
16586
16604
|
}
|
|
16587
16605
|
self.send(rerouteExternalBehaviorEvent({
|
|
16588
16606
|
event: eventSentBack,
|
|
16589
|
-
|
|
16607
|
+
editorEngine: event.editor
|
|
16590
16608
|
}));
|
|
16591
16609
|
}
|
|
16592
16610
|
});
|
|
@@ -16602,12 +16620,12 @@ const editorMachine = setup({
|
|
|
16602
16620
|
})
|
|
16603
16621
|
},
|
|
16604
16622
|
guards: {
|
|
16605
|
-
"
|
|
16623
|
+
"engine is busy": ({
|
|
16606
16624
|
context
|
|
16607
|
-
}) => context.
|
|
16608
|
-
"
|
|
16625
|
+
}) => context.editorEngine ? context.editorEngine.operations.length > 0 : !1,
|
|
16626
|
+
"engine is normalizing node": ({
|
|
16609
16627
|
context
|
|
16610
|
-
}) => context.
|
|
16628
|
+
}) => context.editorEngine ? context.editorEngine.isNormalizingNode : !1
|
|
16611
16629
|
}
|
|
16612
16630
|
}).createMachine({
|
|
16613
16631
|
id: "editor",
|
|
@@ -16637,8 +16655,8 @@ const editorMachine = setup({
|
|
|
16637
16655
|
"remove behavior": {
|
|
16638
16656
|
actions: "remove behavior from context"
|
|
16639
16657
|
},
|
|
16640
|
-
"add
|
|
16641
|
-
actions: ["add
|
|
16658
|
+
"add editor engine": {
|
|
16659
|
+
actions: ["add editor engine to context", "attach maps to editor engine"]
|
|
16642
16660
|
},
|
|
16643
16661
|
register: {
|
|
16644
16662
|
actions: ["register"]
|
|
@@ -16737,7 +16755,7 @@ const editorMachine = setup({
|
|
|
16737
16755
|
focus: {
|
|
16738
16756
|
target: ".focusing",
|
|
16739
16757
|
actions: [assign({
|
|
16740
|
-
|
|
16758
|
+
editorEngine: ({
|
|
16741
16759
|
event
|
|
16742
16760
|
}) => event.editor
|
|
16743
16761
|
})]
|
|
@@ -16776,7 +16794,7 @@ const editorMachine = setup({
|
|
|
16776
16794
|
debug.state("exit: edit mode->editable->focusing->checking if busy");
|
|
16777
16795
|
}],
|
|
16778
16796
|
always: [{
|
|
16779
|
-
guard: "
|
|
16797
|
+
guard: "engine is busy",
|
|
16780
16798
|
target: "busy"
|
|
16781
16799
|
}, {
|
|
16782
16800
|
target: "#editor.edit mode.editable.idle",
|
|
@@ -16923,14 +16941,14 @@ const editorMachine = setup({
|
|
|
16923
16941
|
}],
|
|
16924
16942
|
on: {
|
|
16925
16943
|
"internal.patch": [{
|
|
16926
|
-
guard: "
|
|
16944
|
+
guard: "engine is normalizing node",
|
|
16927
16945
|
actions: "defer event"
|
|
16928
16946
|
}, {
|
|
16929
16947
|
actions: "defer event",
|
|
16930
16948
|
target: "#editor.setup.set up.writing.dirty"
|
|
16931
16949
|
}],
|
|
16932
16950
|
mutation: [{
|
|
16933
|
-
guard: "
|
|
16951
|
+
guard: "engine is normalizing node",
|
|
16934
16952
|
actions: "defer event"
|
|
16935
16953
|
}, {
|
|
16936
16954
|
actions: "defer event",
|
|
@@ -16992,7 +17010,7 @@ const editorMachine = setup({
|
|
|
16992
17010
|
"set is deferring mutations": ({
|
|
16993
17011
|
context
|
|
16994
17012
|
}) => {
|
|
16995
|
-
context.
|
|
17013
|
+
context.editorEngine.isDeferringMutations = !0;
|
|
16996
17014
|
},
|
|
16997
17015
|
"emit mutations": enqueueActions(({
|
|
16998
17016
|
context,
|
|
@@ -17004,7 +17022,7 @@ const editorMachine = setup({
|
|
|
17004
17022
|
patches: bulk.patches,
|
|
17005
17023
|
snapshot: bulk.value
|
|
17006
17024
|
});
|
|
17007
|
-
context.
|
|
17025
|
+
context.editorEngine.isDeferringMutations = !1;
|
|
17008
17026
|
}),
|
|
17009
17027
|
"clear pending mutations": assign({
|
|
17010
17028
|
pendingMutations: []
|
|
@@ -17054,15 +17072,15 @@ const editorMachine = setup({
|
|
|
17054
17072
|
input,
|
|
17055
17073
|
sendBack
|
|
17056
17074
|
}) => {
|
|
17057
|
-
const originalApply = input.
|
|
17058
|
-
return input.
|
|
17075
|
+
const originalApply = input.editorEngine.apply;
|
|
17076
|
+
return input.editorEngine.apply = (op) => {
|
|
17059
17077
|
op.type === "insert_text" || op.type === "remove_text" ? sendBack({
|
|
17060
17078
|
type: "typing"
|
|
17061
17079
|
}) : sendBack({
|
|
17062
17080
|
type: "not typing"
|
|
17063
17081
|
}), originalApply(op);
|
|
17064
17082
|
}, () => {
|
|
17065
|
-
input.
|
|
17083
|
+
input.editorEngine.apply = originalApply;
|
|
17066
17084
|
};
|
|
17067
17085
|
}),
|
|
17068
17086
|
"mutation interval": fromCallback(({
|
|
@@ -17086,9 +17104,9 @@ const editorMachine = setup({
|
|
|
17086
17104
|
"is read-only": ({
|
|
17087
17105
|
context
|
|
17088
17106
|
}) => context.readOnly,
|
|
17089
|
-
"
|
|
17107
|
+
"engine is normalizing": ({
|
|
17090
17108
|
context
|
|
17091
|
-
}) => isNormalizing(context.
|
|
17109
|
+
}) => isNormalizing(context.editorEngine)
|
|
17092
17110
|
},
|
|
17093
17111
|
delays: {
|
|
17094
17112
|
"type debounce": 250
|
|
@@ -17102,7 +17120,7 @@ const editorMachine = setup({
|
|
|
17102
17120
|
pendingPatchEvents: [],
|
|
17103
17121
|
readOnly: input.readOnly,
|
|
17104
17122
|
schema: input.schema,
|
|
17105
|
-
|
|
17123
|
+
editorEngine: input.editorEngine
|
|
17106
17124
|
}),
|
|
17107
17125
|
on: {
|
|
17108
17126
|
"update readOnly": {
|
|
@@ -17118,7 +17136,7 @@ const editorMachine = setup({
|
|
|
17118
17136
|
input: ({
|
|
17119
17137
|
context
|
|
17120
17138
|
}) => ({
|
|
17121
|
-
|
|
17139
|
+
editorEngine: context.editorEngine
|
|
17122
17140
|
})
|
|
17123
17141
|
},
|
|
17124
17142
|
states: {
|
|
@@ -17194,7 +17212,7 @@ const editorMachine = setup({
|
|
|
17194
17212
|
},
|
|
17195
17213
|
on: {
|
|
17196
17214
|
"emit changes": {
|
|
17197
|
-
guard: and([not("is read-only"), "
|
|
17215
|
+
guard: and([not("is read-only"), "engine is normalizing"]),
|
|
17198
17216
|
target: "idle",
|
|
17199
17217
|
actions: ["emit pending patch events", "clear pending patch events", "emit mutations", "clear pending mutations"]
|
|
17200
17218
|
},
|
|
@@ -17229,24 +17247,11 @@ const editorMachine = setup({
|
|
|
17229
17247
|
event
|
|
17230
17248
|
}) => event)]
|
|
17231
17249
|
},
|
|
17232
|
-
selection:
|
|
17233
|
-
guard: ({
|
|
17234
|
-
context
|
|
17235
|
-
}) => context.lastEventWasFocused,
|
|
17236
|
-
actions: [assign({
|
|
17237
|
-
prevSelection: ({
|
|
17238
|
-
event
|
|
17239
|
-
}) => event.selection
|
|
17240
|
-
}), emit(({
|
|
17241
|
-
event
|
|
17242
|
-
}) => event), assign({
|
|
17243
|
-
lastEventWasFocused: !1
|
|
17244
|
-
})]
|
|
17245
|
-
}, {
|
|
17250
|
+
selection: {
|
|
17246
17251
|
guard: ({
|
|
17247
17252
|
context,
|
|
17248
17253
|
event
|
|
17249
|
-
}) => context.prevSelection !== event.selection,
|
|
17254
|
+
}) => context.lastEventWasFocused || context.prevSelection !== event.selection,
|
|
17250
17255
|
actions: [assign({
|
|
17251
17256
|
prevSelection: ({
|
|
17252
17257
|
event
|
|
@@ -17256,7 +17261,7 @@ const editorMachine = setup({
|
|
|
17256
17261
|
}) => event), assign({
|
|
17257
17262
|
lastEventWasFocused: !1
|
|
17258
17263
|
})]
|
|
17259
|
-
}
|
|
17264
|
+
},
|
|
17260
17265
|
"*": {
|
|
17261
17266
|
actions: [emit(({
|
|
17262
17267
|
event
|
|
@@ -17606,7 +17611,7 @@ const syncValueCallback = ({
|
|
|
17606
17611
|
updateValue({
|
|
17607
17612
|
context: input.context,
|
|
17608
17613
|
sendBack,
|
|
17609
|
-
|
|
17614
|
+
editorEngine: input.editorEngine,
|
|
17610
17615
|
value: input.value,
|
|
17611
17616
|
streamBlocks: input.streamBlocks
|
|
17612
17617
|
});
|
|
@@ -17653,11 +17658,11 @@ const syncValueCallback = ({
|
|
|
17653
17658
|
"is busy": ({
|
|
17654
17659
|
context
|
|
17655
17660
|
}) => {
|
|
17656
|
-
const isBusy = context.
|
|
17661
|
+
const isBusy = context.editorEngine.isDeferringMutations || context.editorEngine.isProcessingRemoteChanges;
|
|
17657
17662
|
return debug.syncValue(safeStringify({
|
|
17658
17663
|
isBusy,
|
|
17659
|
-
isDeferringMutations: context.
|
|
17660
|
-
isProcessingRemoteChanges: context.
|
|
17664
|
+
isDeferringMutations: context.editorEngine.isDeferringMutations,
|
|
17665
|
+
isProcessingRemoteChanges: context.editorEngine.isProcessingRemoteChanges
|
|
17661
17666
|
})), isBusy;
|
|
17662
17667
|
},
|
|
17663
17668
|
"is empty value": ({
|
|
@@ -17697,7 +17702,7 @@ const syncValueCallback = ({
|
|
|
17697
17702
|
keyGenerator: input.keyGenerator,
|
|
17698
17703
|
schema: input.schema,
|
|
17699
17704
|
readOnly: input.readOnly,
|
|
17700
|
-
|
|
17705
|
+
editorEngine: input.editorEngine,
|
|
17701
17706
|
pendingValue: void 0,
|
|
17702
17707
|
previousValue: void 0
|
|
17703
17708
|
}),
|
|
@@ -17796,7 +17801,7 @@ const syncValueCallback = ({
|
|
|
17796
17801
|
readOnly: context.readOnly,
|
|
17797
17802
|
schema: context.schema
|
|
17798
17803
|
},
|
|
17799
|
-
|
|
17804
|
+
editorEngine: context.editorEngine,
|
|
17800
17805
|
streamBlocks: !context.initialValueSynced,
|
|
17801
17806
|
value: context.pendingValue
|
|
17802
17807
|
})
|
|
@@ -17837,14 +17842,14 @@ const syncValueCallback = ({
|
|
|
17837
17842
|
async function updateValue({
|
|
17838
17843
|
context,
|
|
17839
17844
|
sendBack,
|
|
17840
|
-
|
|
17845
|
+
editorEngine,
|
|
17841
17846
|
streamBlocks,
|
|
17842
17847
|
value
|
|
17843
17848
|
}) {
|
|
17844
17849
|
let doneSyncing = !1, isChanged = !1, isValid = !0;
|
|
17845
|
-
const hadSelection = !!
|
|
17850
|
+
const hadSelection = !!editorEngine.selection;
|
|
17846
17851
|
if ((!value || value.length === 0) && (clearEditor({
|
|
17847
|
-
|
|
17852
|
+
editorEngine,
|
|
17848
17853
|
doneSyncing
|
|
17849
17854
|
}), isChanged = !0), value && value.length > 0)
|
|
17850
17855
|
if (streamBlocks)
|
|
@@ -17854,7 +17859,7 @@ async function updateValue({
|
|
|
17854
17859
|
return;
|
|
17855
17860
|
}
|
|
17856
17861
|
isChanged = removeExtraBlocks({
|
|
17857
|
-
|
|
17862
|
+
editorEngine,
|
|
17858
17863
|
value
|
|
17859
17864
|
}), (async () => {
|
|
17860
17865
|
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
@@ -17868,7 +17873,7 @@ async function updateValue({
|
|
|
17868
17873
|
sendBack,
|
|
17869
17874
|
block: currentBlock,
|
|
17870
17875
|
index: currentBlockIndex,
|
|
17871
|
-
|
|
17876
|
+
editorEngine,
|
|
17872
17877
|
value
|
|
17873
17878
|
});
|
|
17874
17879
|
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
@@ -17881,7 +17886,7 @@ async function updateValue({
|
|
|
17881
17886
|
if (doneSyncing)
|
|
17882
17887
|
return;
|
|
17883
17888
|
isChanged = removeExtraBlocks({
|
|
17884
|
-
|
|
17889
|
+
editorEngine,
|
|
17885
17890
|
value
|
|
17886
17891
|
});
|
|
17887
17892
|
let index = 0;
|
|
@@ -17894,7 +17899,7 @@ async function updateValue({
|
|
|
17894
17899
|
sendBack,
|
|
17895
17900
|
block,
|
|
17896
17901
|
index,
|
|
17897
|
-
|
|
17902
|
+
editorEngine,
|
|
17898
17903
|
value
|
|
17899
17904
|
});
|
|
17900
17905
|
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
|
|
@@ -17912,7 +17917,7 @@ async function updateValue({
|
|
|
17912
17917
|
if (isChanged) {
|
|
17913
17918
|
debug.syncValue("remote value changed, syncing local value");
|
|
17914
17919
|
try {
|
|
17915
|
-
|
|
17920
|
+
editorEngine.onChange();
|
|
17916
17921
|
} catch (err) {
|
|
17917
17922
|
console.error(err), sendBack({
|
|
17918
17923
|
type: "invalid value",
|
|
@@ -17924,7 +17929,7 @@ async function updateValue({
|
|
|
17924
17929
|
});
|
|
17925
17930
|
return;
|
|
17926
17931
|
}
|
|
17927
|
-
hadSelection && !
|
|
17932
|
+
hadSelection && !editorEngine.selection && editorEngine.children.length > 0 && (applySelect(editorEngine, start(editorEngine, [])), editorEngine.onChange()), sendBack({
|
|
17928
17933
|
type: "value changed",
|
|
17929
17934
|
value
|
|
17930
17935
|
});
|
|
@@ -17943,19 +17948,19 @@ async function* getStreamedBlocks({
|
|
|
17943
17948
|
index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
17944
17949
|
}
|
|
17945
17950
|
function clearEditor({
|
|
17946
|
-
|
|
17951
|
+
editorEngine,
|
|
17947
17952
|
doneSyncing
|
|
17948
17953
|
}) {
|
|
17949
|
-
withoutNormalizing(
|
|
17950
|
-
pluginWithoutHistory(
|
|
17951
|
-
withRemoteChanges(
|
|
17952
|
-
withoutPatching(
|
|
17954
|
+
withoutNormalizing(editorEngine, () => {
|
|
17955
|
+
pluginWithoutHistory(editorEngine, () => {
|
|
17956
|
+
withRemoteChanges(editorEngine, () => {
|
|
17957
|
+
withoutPatching(editorEngine, () => {
|
|
17953
17958
|
if (doneSyncing)
|
|
17954
17959
|
return;
|
|
17955
|
-
const childrenLength =
|
|
17956
|
-
|
|
17957
|
-
const removeNode =
|
|
17958
|
-
removeNode &&
|
|
17960
|
+
const childrenLength = editorEngine.children.length;
|
|
17961
|
+
editorEngine.children.forEach((_, index) => {
|
|
17962
|
+
const removeNode = editorEngine.children[childrenLength - 1 - index];
|
|
17963
|
+
removeNode && editorEngine.apply({
|
|
17959
17964
|
type: "unset",
|
|
17960
17965
|
path: [{
|
|
17961
17966
|
_key: removeNode._key
|
|
@@ -17968,18 +17973,18 @@ function clearEditor({
|
|
|
17968
17973
|
});
|
|
17969
17974
|
}
|
|
17970
17975
|
function removeExtraBlocks({
|
|
17971
|
-
|
|
17976
|
+
editorEngine,
|
|
17972
17977
|
value
|
|
17973
17978
|
}) {
|
|
17974
17979
|
let isChanged = !1;
|
|
17975
|
-
return withoutNormalizing(
|
|
17976
|
-
withRemoteChanges(
|
|
17977
|
-
withoutPatching(
|
|
17978
|
-
const childrenLength =
|
|
17980
|
+
return withoutNormalizing(editorEngine, () => {
|
|
17981
|
+
withRemoteChanges(editorEngine, () => {
|
|
17982
|
+
withoutPatching(editorEngine, () => {
|
|
17983
|
+
const childrenLength = editorEngine.children.length;
|
|
17979
17984
|
if (value.length < childrenLength) {
|
|
17980
17985
|
for (let i = childrenLength - 1; i > value.length - 1; i--) {
|
|
17981
|
-
const removeNode =
|
|
17982
|
-
removeNode &&
|
|
17986
|
+
const removeNode = editorEngine.children[i];
|
|
17987
|
+
removeNode && editorEngine.apply({
|
|
17983
17988
|
type: "unset",
|
|
17984
17989
|
path: [{
|
|
17985
17990
|
_key: removeNode._key
|
|
@@ -17997,23 +18002,23 @@ function syncBlock({
|
|
|
17997
18002
|
sendBack,
|
|
17998
18003
|
block,
|
|
17999
18004
|
index,
|
|
18000
|
-
|
|
18005
|
+
editorEngine,
|
|
18001
18006
|
value
|
|
18002
18007
|
}) {
|
|
18003
|
-
const
|
|
18004
|
-
if (!
|
|
18008
|
+
const oldEngineBlock = editorEngine.children.at(index), oldBlock = editorEngine.children.at(index);
|
|
18009
|
+
if (!oldEngineBlock || !oldBlock) {
|
|
18005
18010
|
const validation2 = validateValue([block], context.schema, context.keyGenerator);
|
|
18006
18011
|
if (debug.syncValue("Validating and inserting new block in the end of the value", block), validation2.valid || validation2.resolution?.autoResolve) {
|
|
18007
|
-
const
|
|
18012
|
+
const engineBlock = toEngineBlock(block, {
|
|
18008
18013
|
schemaTypes: context.schema
|
|
18009
18014
|
});
|
|
18010
|
-
return withoutNormalizing(
|
|
18011
|
-
withRemoteChanges(
|
|
18012
|
-
withoutPatching(
|
|
18013
|
-
|
|
18015
|
+
return withoutNormalizing(editorEngine, () => {
|
|
18016
|
+
withRemoteChanges(editorEngine, () => {
|
|
18017
|
+
withoutPatching(editorEngine, () => {
|
|
18018
|
+
editorEngine.apply({
|
|
18014
18019
|
type: "insert",
|
|
18015
|
-
path: [
|
|
18016
|
-
node:
|
|
18020
|
+
path: [editorEngine.children.length],
|
|
18021
|
+
node: engineBlock,
|
|
18017
18022
|
position: "before"
|
|
18018
18023
|
});
|
|
18019
18024
|
});
|
|
@@ -18049,24 +18054,24 @@ function syncBlock({
|
|
|
18049
18054
|
type: "patch",
|
|
18050
18055
|
patch
|
|
18051
18056
|
});
|
|
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(
|
|
18057
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key && oldBlock._type === block._type ? (debug.syncValue("Updating block", oldBlock, block), withoutNormalizing(editorEngine, () => {
|
|
18058
|
+
withRemoteChanges(editorEngine, () => {
|
|
18059
|
+
withoutPatching(editorEngine, () => {
|
|
18055
18060
|
updateBlock({
|
|
18056
18061
|
context,
|
|
18057
|
-
|
|
18058
|
-
|
|
18062
|
+
editorEngine,
|
|
18063
|
+
oldEngineBlock,
|
|
18059
18064
|
block,
|
|
18060
18065
|
index
|
|
18061
18066
|
});
|
|
18062
18067
|
});
|
|
18063
18068
|
});
|
|
18064
|
-
})) : (debug.syncValue("Replacing block", oldBlock, block), withoutNormalizing(
|
|
18065
|
-
withRemoteChanges(
|
|
18066
|
-
withoutPatching(
|
|
18069
|
+
})) : (debug.syncValue("Replacing block", oldBlock, block), withoutNormalizing(editorEngine, () => {
|
|
18070
|
+
withRemoteChanges(editorEngine, () => {
|
|
18071
|
+
withoutPatching(editorEngine, () => {
|
|
18067
18072
|
replaceBlock({
|
|
18068
18073
|
context,
|
|
18069
|
-
|
|
18074
|
+
editorEngine,
|
|
18070
18075
|
block,
|
|
18071
18076
|
index
|
|
18072
18077
|
});
|
|
@@ -18086,84 +18091,84 @@ function syncBlock({
|
|
|
18086
18091
|
}
|
|
18087
18092
|
function replaceBlock({
|
|
18088
18093
|
context,
|
|
18089
|
-
|
|
18094
|
+
editorEngine,
|
|
18090
18095
|
block,
|
|
18091
18096
|
index
|
|
18092
18097
|
}) {
|
|
18093
|
-
const
|
|
18098
|
+
const engineBlock = toEngineBlock(block, {
|
|
18094
18099
|
schemaTypes: context.schema
|
|
18095
|
-
}), currentSelection =
|
|
18096
|
-
selectionFocusOnBlock && applyDeselect(
|
|
18097
|
-
const oldNode =
|
|
18098
|
-
oldNode && (
|
|
18100
|
+
}), currentSelection = editorEngine.selection, focusBlockSegment = currentSelection?.focus.path[0], blockAtIndex = editorEngine.children[index], selectionFocusOnBlock = currentSelection && isKeyedSegment(focusBlockSegment) && blockAtIndex && focusBlockSegment._key === blockAtIndex._key;
|
|
18101
|
+
selectionFocusOnBlock && applyDeselect(editorEngine);
|
|
18102
|
+
const oldNode = editorEngine.children[index];
|
|
18103
|
+
oldNode && (editorEngine.apply({
|
|
18099
18104
|
type: "unset",
|
|
18100
18105
|
path: [{
|
|
18101
18106
|
_key: oldNode._key
|
|
18102
18107
|
}]
|
|
18103
|
-
}),
|
|
18108
|
+
}), editorEngine.apply({
|
|
18104
18109
|
type: "insert",
|
|
18105
18110
|
path: [index],
|
|
18106
|
-
node:
|
|
18111
|
+
node: engineBlock,
|
|
18107
18112
|
position: "before"
|
|
18108
|
-
}),
|
|
18113
|
+
}), editorEngine.onChange(), selectionFocusOnBlock && hasNode(editorEngine, currentSelection.anchor.path) && hasNode(editorEngine, currentSelection.focus.path) && applySelect(editorEngine, currentSelection));
|
|
18109
18114
|
}
|
|
18110
18115
|
function updateBlock({
|
|
18111
18116
|
context,
|
|
18112
|
-
|
|
18113
|
-
|
|
18117
|
+
editorEngine,
|
|
18118
|
+
oldEngineBlock,
|
|
18114
18119
|
block,
|
|
18115
18120
|
index: _index
|
|
18116
18121
|
}) {
|
|
18117
|
-
const
|
|
18122
|
+
const engineBlock = toEngineBlock(block, {
|
|
18118
18123
|
schemaTypes: context.schema
|
|
18119
18124
|
}), {
|
|
18120
18125
|
children: _children,
|
|
18121
18126
|
...blockProps
|
|
18122
|
-
} =
|
|
18123
|
-
setNodeProperties(
|
|
18124
|
-
_key:
|
|
18127
|
+
} = engineBlock;
|
|
18128
|
+
setNodeProperties(editorEngine, blockProps, [{
|
|
18129
|
+
_key: oldEngineBlock._key
|
|
18125
18130
|
}]);
|
|
18126
|
-
const oldRecord =
|
|
18131
|
+
const oldRecord = oldEngineBlock, newRecord = engineBlock, removedProperties = {};
|
|
18127
18132
|
for (const key of Object.keys(oldRecord))
|
|
18128
18133
|
key === "children" || key === "text" || newRecord.hasOwnProperty(key) || (removedProperties[key] = null);
|
|
18129
|
-
if (Object.keys(removedProperties).length > 0 && setNodeProperties(
|
|
18130
|
-
_key:
|
|
18134
|
+
if (Object.keys(removedProperties).length > 0 && setNodeProperties(editorEngine, removedProperties, [{
|
|
18135
|
+
_key: oldEngineBlock._key
|
|
18131
18136
|
}]), isTextBlock({
|
|
18132
|
-
schema:
|
|
18133
|
-
},
|
|
18134
|
-
schema:
|
|
18135
|
-
},
|
|
18136
|
-
const oldKeys =
|
|
18137
|
+
schema: editorEngine.schema
|
|
18138
|
+
}, engineBlock) && isTextBlock({
|
|
18139
|
+
schema: editorEngine.schema
|
|
18140
|
+
}, oldEngineBlock)) {
|
|
18141
|
+
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
18142
|
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:
|
|
18143
|
+
debug.syncValue("Replacing children via set"), setNodeProperties(editorEngine, {
|
|
18144
|
+
children: engineBlock.children
|
|
18140
18145
|
}, [{
|
|
18141
|
-
_key:
|
|
18142
|
-
}]),
|
|
18146
|
+
_key: oldEngineBlock._key
|
|
18147
|
+
}]), editorEngine.onChange();
|
|
18143
18148
|
return;
|
|
18144
18149
|
}
|
|
18145
|
-
const oldBlockChildrenLength =
|
|
18146
|
-
|
|
18150
|
+
const oldBlockChildrenLength = oldEngineBlock.children.length;
|
|
18151
|
+
engineBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - engineBlock.children.length)).forEach((_, i) => {
|
|
18147
18152
|
const childIndex = oldBlockChildrenLength - 1 - i;
|
|
18148
18153
|
if (childIndex > 0) {
|
|
18149
18154
|
debug.syncValue("Removing child");
|
|
18150
|
-
const childNode =
|
|
18155
|
+
const childNode = oldEngineBlock.children[childIndex];
|
|
18151
18156
|
if (!childNode)
|
|
18152
18157
|
return;
|
|
18153
|
-
|
|
18158
|
+
editorEngine.apply({
|
|
18154
18159
|
type: "unset",
|
|
18155
18160
|
path: [{
|
|
18156
|
-
_key:
|
|
18161
|
+
_key: oldEngineBlock._key
|
|
18157
18162
|
}, "children", {
|
|
18158
18163
|
_key: childNode._key
|
|
18159
18164
|
}]
|
|
18160
18165
|
});
|
|
18161
18166
|
}
|
|
18162
|
-
}),
|
|
18163
|
-
const oldBlockChild =
|
|
18164
|
-
schema:
|
|
18167
|
+
}), engineBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
18168
|
+
const oldBlockChild = oldEngineBlock.children.at(currentBlockChildIndex), isChildChanged = !oldBlockChild || !isEqualChild(currentBlockChild, oldBlockChild, editorEngine.schema.span.name), isTextChanged = oldBlockChild && isSpan({
|
|
18169
|
+
schema: editorEngine.schema
|
|
18165
18170
|
}, oldBlockChild) && currentBlockChild.text !== oldBlockChild.text, path2 = [{
|
|
18166
|
-
_key:
|
|
18171
|
+
_key: oldEngineBlock._key
|
|
18167
18172
|
}, "children", {
|
|
18168
18173
|
_key: currentBlockChild._key
|
|
18169
18174
|
}];
|
|
@@ -18174,13 +18179,13 @@ function updateBlock({
|
|
|
18174
18179
|
text: _text,
|
|
18175
18180
|
...childProps
|
|
18176
18181
|
} = currentBlockChild;
|
|
18177
|
-
setNodeProperties(
|
|
18182
|
+
setNodeProperties(editorEngine, childProps, path2);
|
|
18178
18183
|
const isSpanNode2 = isSpan({
|
|
18179
18184
|
schema: context.schema
|
|
18180
18185
|
}, currentBlockChild) && isSpan({
|
|
18181
18186
|
schema: context.schema
|
|
18182
18187
|
}, oldBlockChild);
|
|
18183
|
-
isSpanNode2 && isTextChanged ? (oldBlockChild.text.length > 0 && deleteRange(
|
|
18188
|
+
isSpanNode2 && isTextChanged ? (oldBlockChild.text.length > 0 && deleteRange(editorEngine, {
|
|
18184
18189
|
focus: {
|
|
18185
18190
|
path: path2,
|
|
18186
18191
|
offset: 0
|
|
@@ -18192,63 +18197,63 @@ function updateBlock({
|
|
|
18192
18197
|
}, {
|
|
18193
18198
|
selection: "preserve",
|
|
18194
18199
|
removeEmptyStartBlock: !0
|
|
18195
|
-
}),
|
|
18200
|
+
}), editorEngine.apply({
|
|
18196
18201
|
type: "insert_text",
|
|
18197
18202
|
path: path2,
|
|
18198
18203
|
offset: 0,
|
|
18199
18204
|
text: currentBlockChild.text
|
|
18200
|
-
}),
|
|
18205
|
+
}), editorEngine.onChange()) : isSpanNode2 || debug.syncValue("Updating changed inline object child", currentBlockChild);
|
|
18201
18206
|
} else if (oldBlockChild) {
|
|
18202
18207
|
debug.syncValue("Replacing child", currentBlockChild);
|
|
18203
|
-
const oldChild =
|
|
18208
|
+
const oldChild = oldEngineBlock.children[currentBlockChildIndex];
|
|
18204
18209
|
if (!oldChild)
|
|
18205
18210
|
return;
|
|
18206
|
-
|
|
18211
|
+
editorEngine.apply({
|
|
18207
18212
|
type: "unset",
|
|
18208
18213
|
path: [{
|
|
18209
|
-
_key:
|
|
18214
|
+
_key: oldEngineBlock._key
|
|
18210
18215
|
}, "children", {
|
|
18211
18216
|
_key: oldChild._key
|
|
18212
18217
|
}]
|
|
18213
18218
|
});
|
|
18214
|
-
const prevSibling = currentBlockChildIndex > 0 ?
|
|
18215
|
-
prevSibling ?
|
|
18219
|
+
const prevSibling = currentBlockChildIndex > 0 ? oldEngineBlock.children[currentBlockChildIndex - 1] : void 0;
|
|
18220
|
+
prevSibling ? editorEngine.apply({
|
|
18216
18221
|
type: "insert",
|
|
18217
18222
|
path: [{
|
|
18218
|
-
_key:
|
|
18223
|
+
_key: oldEngineBlock._key
|
|
18219
18224
|
}, "children", {
|
|
18220
18225
|
_key: prevSibling._key
|
|
18221
18226
|
}],
|
|
18222
18227
|
node: currentBlockChild,
|
|
18223
18228
|
position: "after"
|
|
18224
|
-
}) :
|
|
18229
|
+
}) : editorEngine.apply({
|
|
18225
18230
|
type: "insert",
|
|
18226
18231
|
path: [{
|
|
18227
|
-
_key:
|
|
18232
|
+
_key: oldEngineBlock._key
|
|
18228
18233
|
}, "children", 0],
|
|
18229
18234
|
node: currentBlockChild,
|
|
18230
18235
|
position: "before"
|
|
18231
|
-
}),
|
|
18236
|
+
}), editorEngine.onChange();
|
|
18232
18237
|
} else if (!oldBlockChild) {
|
|
18233
18238
|
debug.syncValue("Inserting new child", currentBlockChild);
|
|
18234
|
-
const prevChild = currentBlockChildIndex > 0 ?
|
|
18235
|
-
prevChild ?
|
|
18239
|
+
const prevChild = currentBlockChildIndex > 0 ? engineBlock.children[currentBlockChildIndex - 1] : void 0;
|
|
18240
|
+
prevChild ? editorEngine.apply({
|
|
18236
18241
|
type: "insert",
|
|
18237
18242
|
path: [{
|
|
18238
|
-
_key:
|
|
18243
|
+
_key: oldEngineBlock._key
|
|
18239
18244
|
}, "children", {
|
|
18240
18245
|
_key: prevChild._key
|
|
18241
18246
|
}],
|
|
18242
18247
|
node: currentBlockChild,
|
|
18243
18248
|
position: "after"
|
|
18244
|
-
}) :
|
|
18249
|
+
}) : editorEngine.apply({
|
|
18245
18250
|
type: "insert",
|
|
18246
18251
|
path: [{
|
|
18247
|
-
_key:
|
|
18252
|
+
_key: oldEngineBlock._key
|
|
18248
18253
|
}, "children", 0],
|
|
18249
18254
|
node: currentBlockChild,
|
|
18250
18255
|
position: "before"
|
|
18251
|
-
}),
|
|
18256
|
+
}), editorEngine.onChange();
|
|
18252
18257
|
}
|
|
18253
18258
|
}
|
|
18254
18259
|
});
|
|
@@ -18258,23 +18263,23 @@ function createInternalEditor(config) {
|
|
|
18258
18263
|
debug.setup("creating new editor instance");
|
|
18259
18264
|
const subscriptions = [], editorActor = createActor(editorMachine, {
|
|
18260
18265
|
input: editorConfigToMachineInput(config)
|
|
18261
|
-
}), relayActor = createActor(relayMachine),
|
|
18266
|
+
}), relayActor = createActor(relayMachine), editorEngine = createEditorEngine({
|
|
18262
18267
|
editorActor,
|
|
18263
18268
|
relayActor,
|
|
18264
18269
|
subscriptions
|
|
18265
|
-
}), editable = createEditableAPI(
|
|
18270
|
+
}), editable = createEditableAPI(editorEngine, editorActor), {
|
|
18266
18271
|
mutationActor,
|
|
18267
18272
|
syncActor
|
|
18268
18273
|
} = createActors({
|
|
18269
18274
|
editorActor,
|
|
18270
18275
|
relayActor,
|
|
18271
|
-
|
|
18276
|
+
editorEngine,
|
|
18272
18277
|
subscriptions
|
|
18273
18278
|
}), editor = {
|
|
18274
|
-
dom: createEditorDom((event) => editorActor.send(event),
|
|
18279
|
+
dom: createEditorDom((event) => editorActor.send(event), editorEngine),
|
|
18275
18280
|
getSnapshot: () => getEditorSnapshot({
|
|
18276
18281
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
18277
|
-
|
|
18282
|
+
editorEngineInstance: editorEngine
|
|
18278
18283
|
}),
|
|
18279
18284
|
registerBehavior: (behaviorConfig) => {
|
|
18280
18285
|
const priority = createEditorPriority({
|
|
@@ -18318,7 +18323,7 @@ function createInternalEditor(config) {
|
|
|
18318
18323
|
default:
|
|
18319
18324
|
editorActor.send(rerouteExternalBehaviorEvent({
|
|
18320
18325
|
event,
|
|
18321
|
-
|
|
18326
|
+
editorEngine
|
|
18322
18327
|
}));
|
|
18323
18328
|
}
|
|
18324
18329
|
},
|
|
@@ -18360,7 +18365,7 @@ function createInternalEditor(config) {
|
|
|
18360
18365
|
},
|
|
18361
18366
|
editor,
|
|
18362
18367
|
editable,
|
|
18363
|
-
|
|
18368
|
+
editorEngine,
|
|
18364
18369
|
subscriptions
|
|
18365
18370
|
};
|
|
18366
18371
|
}
|
|
@@ -18382,7 +18387,7 @@ function createActors(config) {
|
|
|
18382
18387
|
"edit mode": "read only"
|
|
18383
18388
|
}),
|
|
18384
18389
|
schema: config.editorActor.getSnapshot().context.schema,
|
|
18385
|
-
|
|
18390
|
+
editorEngine: config.editorEngine
|
|
18386
18391
|
}
|
|
18387
18392
|
}), syncActor = createActor(syncMachine, {
|
|
18388
18393
|
input: {
|
|
@@ -18392,7 +18397,7 @@ function createActors(config) {
|
|
|
18392
18397
|
"edit mode": "read only"
|
|
18393
18398
|
}),
|
|
18394
18399
|
schema: config.editorActor.getSnapshot().context.schema,
|
|
18395
|
-
|
|
18400
|
+
editorEngine: config.editorEngine
|
|
18396
18401
|
}
|
|
18397
18402
|
});
|
|
18398
18403
|
return config.subscriptions.push(() => {
|
|
@@ -18421,7 +18426,7 @@ function createActors(config) {
|
|
|
18421
18426
|
config.editorActor.send({
|
|
18422
18427
|
...event,
|
|
18423
18428
|
type: "internal.patch",
|
|
18424
|
-
value: config.
|
|
18429
|
+
value: config.editorEngine.children
|
|
18425
18430
|
});
|
|
18426
18431
|
break;
|
|
18427
18432
|
default:
|
|
@@ -18483,7 +18488,7 @@ class PortableTextEditor {
|
|
|
18483
18488
|
* A lookup table for all the relevant schema types for this portable text type.
|
|
18484
18489
|
*/
|
|
18485
18490
|
/*
|
|
18486
|
-
* The editor API (
|
|
18491
|
+
* The editor API (the engine).
|
|
18487
18492
|
*/
|
|
18488
18493
|
constructor(config) {
|
|
18489
18494
|
this.schemaTypes = config.editorActor.getSnapshot().context.schema, this.editable = config.editable;
|
|
@@ -18875,25 +18880,25 @@ function EditorProvider(props) {
|
|
|
18875
18880
|
portableTextEditor: portableTextEditor_0
|
|
18876
18881
|
} = t1;
|
|
18877
18882
|
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.
|
|
18883
|
+
$[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
18884
|
const unsubscribers = [];
|
|
18880
18885
|
for (const subscription of internalEditor_0.subscriptions)
|
|
18881
18886
|
unsubscribers.push(subscription());
|
|
18882
18887
|
return internalEditor_0.actors.editorActor.start(), internalEditor_0.actors.editorActor.send({
|
|
18883
|
-
type: "add
|
|
18884
|
-
editor: internalEditor_0.
|
|
18888
|
+
type: "add editor engine",
|
|
18889
|
+
editor: internalEditor_0.editorEngine
|
|
18885
18890
|
}), internalEditor_0.actors.mutationActor.start(), internalEditor_0.actors.relayActor.start(), internalEditor_0.actors.syncActor.start(), () => {
|
|
18886
18891
|
for (const unsubscribe of unsubscribers)
|
|
18887
18892
|
unsubscribe();
|
|
18888
18893
|
stopActor(internalEditor_0.actors.editorActor), stopActor(internalEditor_0.actors.mutationActor), stopActor(internalEditor_0.actors.relayActor), stopActor(internalEditor_0.actors.syncActor);
|
|
18889
18894
|
};
|
|
18890
|
-
}, $[2] = internalEditor_0.actors.editorActor, $[3] = internalEditor_0.actors.mutationActor, $[4] = internalEditor_0.actors.relayActor, $[5] = internalEditor_0.actors.syncActor, $[6] = internalEditor_0.
|
|
18895
|
+
}, $[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
18896
|
let t3;
|
|
18892
18897
|
$[9] !== internalEditor_0 ? (t3 = [internalEditor_0], $[9] = internalEditor_0, $[10] = t3) : t3 = $[10], useEffect(t2, t3);
|
|
18893
18898
|
let t4;
|
|
18894
18899
|
$[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
18900
|
let t5;
|
|
18896
|
-
$[14] !== internalEditor_0.
|
|
18901
|
+
$[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
18902
|
let t6;
|
|
18898
18903
|
$[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
18904
|
let t7;
|