@portabletext/editor 7.0.6 → 7.1.1
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/resolve-containers.d.ts.map +1 -1
- package/lib/_chunks-es/get-first-child.js +26 -31
- package/lib/_chunks-es/get-first-child.js.map +1 -1
- package/lib/_chunks-es/{get-node.js → get-parent.js} +35 -60
- package/lib/_chunks-es/get-parent.js.map +1 -0
- package/lib/_chunks-es/get-path-sub-schema.js +87 -43
- package/lib/_chunks-es/get-path-sub-schema.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +32 -34
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +6 -15
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +292 -188
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.d.ts.map +1 -1
- package/lib/selectors/index.js +4 -8
- package/lib/selectors/index.js.map +1 -1
- package/lib/traversal/index.d.ts +94 -18
- package/lib/traversal/index.d.ts.map +1 -1
- package/lib/traversal/index.js +8 -7
- package/lib/traversal/index.js.map +1 -1
- package/lib/utils/index.js +7 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/lib/_chunks-es/get-node.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -2,15 +2,15 @@ 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
4
|
import React, { createContext, useContext, useRef, useEffect, useLayoutEffect, useState, useReducer, useCallback, memo, forwardRef, useMemo, Component, useSyncExternalStore, startTransition } from "react";
|
|
5
|
-
import { isKeyedSegment,
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { rangeEdges,
|
|
5
|
+
import { isKeyedSegment, getNode, getParent, parentPath, getChildren, getNodeChildren } from "./_chunks-es/get-parent.js";
|
|
6
|
+
import { getLeaf, isLeafObject, getAncestor, getSpan, getText, getTextBlock, getUnionSchema, getFirstChild } from "./_chunks-es/get-first-child.js";
|
|
7
|
+
import { isTextBlockNode, hasNode, getNodes, isAncestorPath, isEditableContainer, getSibling, isInline, isObject as isObject$1, isSpanNode, isBlock, getEnclosingBlock, getAncestors, getPathSubSchema, getBlock, resolveContainerAt, getEnclosingContainer } from "./_chunks-es/get-path-sub-schema.js";
|
|
8
|
+
import { rangeEdges, 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";
|
|
9
9
|
import { isSpan, isTextBlock, compileSchema } from "@portabletext/schema";
|
|
10
10
|
import { defineSchema } from "@portabletext/schema";
|
|
11
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";
|
|
13
12
|
import { createKeyboardShortcut, undo, redo, code, underline, italic as italic$1, bold as bold$1 } from "@portabletext/keyboard-shortcuts";
|
|
13
|
+
import { 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
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";
|
|
@@ -197,18 +197,6 @@ function safeParse(text) {
|
|
|
197
197
|
return console.error(error), "JSON.parse failed";
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
-
function getAncestorObjectNode(snapshot, path2) {
|
|
201
|
-
const result = getAncestor(snapshot, path2, (node) => isObjectNode({
|
|
202
|
-
schema: snapshot.context.schema
|
|
203
|
-
}, node));
|
|
204
|
-
if (result && isObjectNode({
|
|
205
|
-
schema: snapshot.context.schema
|
|
206
|
-
}, result.node))
|
|
207
|
-
return {
|
|
208
|
-
node: result.node,
|
|
209
|
-
path: result.path
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
200
|
function commonPath(path2, another) {
|
|
213
201
|
const common = [];
|
|
214
202
|
for (let i = 0; i < path2.length && i < another.length; i++) {
|
|
@@ -314,11 +302,6 @@ function start(editor, at) {
|
|
|
314
302
|
edge: "start"
|
|
315
303
|
});
|
|
316
304
|
}
|
|
317
|
-
function isVoidNode(snapshot, node, path2) {
|
|
318
|
-
return isObjectNode({
|
|
319
|
-
schema: snapshot.context.schema
|
|
320
|
-
}, node) && !isEditableContainer(snapshot, node, path2);
|
|
321
|
-
}
|
|
322
305
|
function pathEquals(path2, another) {
|
|
323
306
|
if (path2.length !== another.length)
|
|
324
307
|
return !1;
|
|
@@ -429,7 +412,7 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
429
412
|
if (!el)
|
|
430
413
|
throw new Error(`Cannot find a DOM node for editor path: ${point2.path}`);
|
|
431
414
|
let domPoint;
|
|
432
|
-
if (nodeEntry &&
|
|
415
|
+
if (nodeEntry && isLeafObject(editor, nodeEntry.node, point2.path)) {
|
|
433
416
|
const spacer = el.querySelector("[data-pt-zero-width]");
|
|
434
417
|
if (spacer) {
|
|
435
418
|
const domText = spacer.childNodes[0];
|
|
@@ -444,8 +427,10 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
444
427
|
}
|
|
445
428
|
return [el, 0];
|
|
446
429
|
}
|
|
447
|
-
const pointPath = path(editor, point2), pointEntry = getNode(editor, pointPath), pointObjectNode = pointEntry &&
|
|
448
|
-
|
|
430
|
+
const pointPath = path(editor, point2), pointEntry = getNode(editor, pointPath), pointObjectNode = pointEntry && isLeafObject(editor, pointEntry.node, pointPath) ? pointEntry : getAncestor(editor, point2.path, {
|
|
431
|
+
match: (node, ancestorPath) => isLeafObject(editor, node, ancestorPath)
|
|
432
|
+
});
|
|
433
|
+
pointObjectNode && isLeafObject(editor, pointObjectNode.node, pointObjectNode.path) && (point2 = {
|
|
449
434
|
path: point2.path,
|
|
450
435
|
offset: 0
|
|
451
436
|
});
|
|
@@ -599,7 +584,7 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
599
584
|
}
|
|
600
585
|
if (path2.length > 1) {
|
|
601
586
|
const parentPath2 = path2.slice(0, -1), parentEntry = getNode(editor, parentPath2);
|
|
602
|
-
if (parentEntry &&
|
|
587
|
+
if (parentEntry && isLeafObject(editor, parentEntry.node, parentPath2))
|
|
603
588
|
return {
|
|
604
589
|
path: parentPath2,
|
|
605
590
|
offset: 0
|
|
@@ -659,9 +644,6 @@ typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent
|
|
|
659
644
|
} : null;
|
|
660
645
|
}
|
|
661
646
|
};
|
|
662
|
-
function getVoidAncestor(snapshot, path2) {
|
|
663
|
-
return getAncestor(snapshot, path2, (node, ancestorPath) => isVoidNode(snapshot, node, ancestorPath));
|
|
664
|
-
}
|
|
665
647
|
function collapse(editor, options = {}) {
|
|
666
648
|
const {
|
|
667
649
|
edge = "anchor"
|
|
@@ -848,7 +830,7 @@ function* positions(editor, options = {}) {
|
|
|
848
830
|
}
|
|
849
831
|
isNewBlock = !0;
|
|
850
832
|
}
|
|
851
|
-
if (
|
|
833
|
+
if (isLeafObject(editor, node, nodePath)) {
|
|
852
834
|
yield {
|
|
853
835
|
path: nodePath,
|
|
854
836
|
offset: 0
|
|
@@ -1424,16 +1406,18 @@ function verifyDiffState(editor, textDiff) {
|
|
|
1424
1406
|
} = textDiff;
|
|
1425
1407
|
if (!hasNode(editor, path2))
|
|
1426
1408
|
return !1;
|
|
1427
|
-
const nodeEntry =
|
|
1409
|
+
const nodeEntry = getSpan(editor, path2);
|
|
1428
1410
|
if (!nodeEntry)
|
|
1429
1411
|
return !1;
|
|
1430
1412
|
const node = nodeEntry.node;
|
|
1431
1413
|
if (diff2.start !== node.text.length || diff2.text.length === 0)
|
|
1432
1414
|
return node.text.slice(diff2.start, diff2.start + diff2.text.length) === diff2.text;
|
|
1433
|
-
const nextSibling = getSibling(editor, path2,
|
|
1415
|
+
const nextSibling = getSibling(editor, path2, {
|
|
1416
|
+
direction: "next"
|
|
1417
|
+
});
|
|
1434
1418
|
if (!nextSibling)
|
|
1435
1419
|
return !1;
|
|
1436
|
-
const nextNodeEntry =
|
|
1420
|
+
const nextNodeEntry = getSpan(editor, nextSibling.path);
|
|
1437
1421
|
return !!nextNodeEntry && nextNodeEntry.node.text.startsWith(diff2.text);
|
|
1438
1422
|
}
|
|
1439
1423
|
function applyStringDiff(text, ...diffs) {
|
|
@@ -1496,11 +1480,15 @@ function normalizePoint(editor, point2) {
|
|
|
1496
1480
|
} = point2;
|
|
1497
1481
|
if (!hasNode(editor, path2))
|
|
1498
1482
|
return null;
|
|
1499
|
-
const leafEntry =
|
|
1483
|
+
const leafEntry = getSpan(editor, path2);
|
|
1500
1484
|
if (!leafEntry)
|
|
1501
1485
|
return null;
|
|
1502
1486
|
let leaf = leafEntry.node;
|
|
1503
|
-
const parentBlock =
|
|
1487
|
+
const parentBlock = getParent(editor, path2, {
|
|
1488
|
+
match: (node) => isTextBlock({
|
|
1489
|
+
schema: editor.schema
|
|
1490
|
+
}, node)
|
|
1491
|
+
});
|
|
1504
1492
|
if (!parentBlock)
|
|
1505
1493
|
return null;
|
|
1506
1494
|
for (; offset > leaf.text.length; ) {
|
|
@@ -1707,7 +1695,7 @@ function createAndroidInputManager({
|
|
|
1707
1695
|
}, handleCompositionStart = (_event) => {
|
|
1708
1696
|
editor.composing = !0, compositionEndTimeoutId && (clearTimeout(compositionEndTimeoutId), compositionEndTimeoutId = null);
|
|
1709
1697
|
}, storeDiff = (path2, diff2) => {
|
|
1710
|
-
const pendingDiffs = editor.pendingDiffs, targetEntry =
|
|
1698
|
+
const pendingDiffs = editor.pendingDiffs, targetEntry = getSpan(editor, path2);
|
|
1711
1699
|
if (!targetEntry)
|
|
1712
1700
|
return;
|
|
1713
1701
|
const target = targetEntry.node, idx = pendingDiffs.findIndex((change) => pathEquals(change.path, path2));
|
|
@@ -1761,7 +1749,7 @@ function createAndroidInputManager({
|
|
|
1761
1749
|
let [start2, end2] = rangeEdges(targetRange2, editor);
|
|
1762
1750
|
const leafNodeEntry = getNode(editor, start2.path), leafResult = leafNodeEntry && (isSpan({
|
|
1763
1751
|
schema: editor.schema
|
|
1764
|
-
}, leafNodeEntry.node) ||
|
|
1752
|
+
}, leafNodeEntry.node) || isLeafObject(editor, leafNodeEntry.node, start2.path)) ? leafNodeEntry : void 0;
|
|
1765
1753
|
if (!leafResult)
|
|
1766
1754
|
return scheduleAction(() => editorActor.send({
|
|
1767
1755
|
type: "behavior event",
|
|
@@ -1857,7 +1845,7 @@ function createAndroidInputManager({
|
|
|
1857
1845
|
anchor
|
|
1858
1846
|
} = targetRange2;
|
|
1859
1847
|
if (canStoreDiff && isCollapsedRange(targetRange2)) {
|
|
1860
|
-
const targetNodeEntry =
|
|
1848
|
+
const targetNodeEntry = getSpan(editor, anchor.path);
|
|
1861
1849
|
if (targetNodeEntry && anchor.offset < targetNodeEntry.node.text.length)
|
|
1862
1850
|
return storeDiff(anchor.path, {
|
|
1863
1851
|
text: "",
|
|
@@ -2842,9 +2830,7 @@ const useChildren = (props) => {
|
|
|
2842
2830
|
schema: editor.schema
|
|
2843
2831
|
}, node))
|
|
2844
2832
|
children = node.children;
|
|
2845
|
-
else if (
|
|
2846
|
-
schema: editor.schema
|
|
2847
|
-
}, node)) {
|
|
2833
|
+
else if (isObject$1(editor, node)) {
|
|
2848
2834
|
const containerConfig = resolveContainerForNode(editor, parentContainer, node);
|
|
2849
2835
|
if (containerConfig) {
|
|
2850
2836
|
const fieldValue = node[containerConfig.field.name];
|
|
@@ -2889,9 +2875,7 @@ const useChildren = (props) => {
|
|
|
2889
2875
|
}
|
|
2890
2876
|
return !1;
|
|
2891
2877
|
}
|
|
2892
|
-
if (
|
|
2893
|
-
schema: editor.schema
|
|
2894
|
-
}, n)) {
|
|
2878
|
+
if (isObject$1(editor, n)) {
|
|
2895
2879
|
if (textBlockParent !== void 0)
|
|
2896
2880
|
return !1;
|
|
2897
2881
|
if (editor.blockObjects.has(n._type))
|
|
@@ -2915,9 +2899,7 @@ const useChildren = (props) => {
|
|
|
2915
2899
|
schema: editor.schema
|
|
2916
2900
|
}, n))
|
|
2917
2901
|
return null;
|
|
2918
|
-
if (
|
|
2919
|
-
schema: editor.schema
|
|
2920
|
-
}, n))
|
|
2902
|
+
if (isObject$1(editor, n))
|
|
2921
2903
|
return resolveContainerForNode(editor, childContainer, n) ? wrapNewPipeline(renderElementComponent(n, i, !0), !0, n._key) : wrapNewPipeline(renderObjectNodeComponent(n, i), isInNewPipelineForChild(n), n._key);
|
|
2922
2904
|
if (isSpan({
|
|
2923
2905
|
schema: editor.schema
|
|
@@ -3298,7 +3280,11 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3298
3280
|
lastText === node && lastText.textContent?.length === offset && (native = !1);
|
|
3299
3281
|
}
|
|
3300
3282
|
if (native && node.parentElement && window2?.getComputedStyle(node.parentElement)?.whiteSpace === "pre") {
|
|
3301
|
-
const block =
|
|
3283
|
+
const block = getParent(editor, anchor.path, {
|
|
3284
|
+
match: (node2) => isTextBlock({
|
|
3285
|
+
schema: editor.schema
|
|
3286
|
+
}, node2)
|
|
3287
|
+
});
|
|
3302
3288
|
block && getText(editor, block.path)?.includes(" ") && (native = !1);
|
|
3303
3289
|
}
|
|
3304
3290
|
}
|
|
@@ -3589,7 +3575,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3589
3575
|
const relatedNodeEntry = getNode(editor, relatedPath), relatedNode = relatedNodeEntry ? relatedNodeEntry.node : void 0;
|
|
3590
3576
|
if (relatedNode && (isTextBlockNode({
|
|
3591
3577
|
schema: editor.schema
|
|
3592
|
-
}, relatedNode) ||
|
|
3578
|
+
}, relatedNode) || isLeafObject(editor, relatedNode, relatedPath)))
|
|
3593
3579
|
return;
|
|
3594
3580
|
}
|
|
3595
3581
|
}
|
|
@@ -3609,14 +3595,22 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3609
3595
|
let blockPath = path2;
|
|
3610
3596
|
isTextBlockNode({
|
|
3611
3597
|
schema: editor.schema
|
|
3612
|
-
}, node) || (blockPath =
|
|
3598
|
+
}, node) || (blockPath = getParent(editor, path2, {
|
|
3599
|
+
match: (node2) => isTextBlock({
|
|
3600
|
+
schema: editor.schema
|
|
3601
|
+
}, node2)
|
|
3602
|
+
})?.path ?? path2.slice(0, 1));
|
|
3613
3603
|
const range$1 = range(editor, blockPath);
|
|
3614
3604
|
editor.select(range$1);
|
|
3615
3605
|
return;
|
|
3616
3606
|
}
|
|
3617
3607
|
if (readOnly)
|
|
3618
3608
|
return;
|
|
3619
|
-
const start$1 = start(editor, path2), end$1 = end(editor, path2), startEntry = getNode(editor, start$1.path), startVoidNode = startEntry &&
|
|
3609
|
+
const start$1 = start(editor, path2), end$1 = end(editor, path2), startEntry = getNode(editor, start$1.path), startVoidNode = startEntry && isLeafObject(editor, startEntry.node, start$1.path) ? startEntry : getAncestor(editor, start$1.path, {
|
|
3610
|
+
match: (node2, ancestorPath) => isLeafObject(editor, node2, ancestorPath)
|
|
3611
|
+
}), endEntry = getNode(editor, end$1.path), endVoidNode = endEntry && isLeafObject(editor, endEntry.node, end$1.path) ? endEntry : getAncestor(editor, end$1.path, {
|
|
3612
|
+
match: (node2, ancestorPath) => isLeafObject(editor, node2, ancestorPath)
|
|
3613
|
+
});
|
|
3620
3614
|
if (startVoidNode && endVoidNode && pathEquals(startVoidNode.path, endVoidNode.path)) {
|
|
3621
3615
|
const range$1 = range(editor, start$1);
|
|
3622
3616
|
editor.select(range$1);
|
|
@@ -3758,7 +3752,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3758
3752
|
if (HAS_BEFORE_INPUT_SUPPORT) {
|
|
3759
3753
|
if ((IS_CHROME || IS_WEBKIT) && selection && (Hotkeys.isDeleteBackward(nativeEvent) || Hotkeys.isDeleteForward(nativeEvent)) && isCollapsedRange(selection)) {
|
|
3760
3754
|
const currentNodeEntry = getNode(editor, selection.anchor.path);
|
|
3761
|
-
if (currentNodeEntry &&
|
|
3755
|
+
if (currentNodeEntry && isLeafObject(editor, currentNodeEntry.node, selection.anchor.path)) {
|
|
3762
3756
|
event.preventDefault(), editorActor.send({
|
|
3763
3757
|
type: "behavior event",
|
|
3764
3758
|
behaviorEvent: {
|
|
@@ -7091,7 +7085,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7091
7085
|
node: span,
|
|
7092
7086
|
path: spanPath
|
|
7093
7087
|
} of spans) {
|
|
7094
|
-
const blockEntry =
|
|
7088
|
+
const blockEntry = getTextBlock(editor, parentPath(spanPath));
|
|
7095
7089
|
blockEntry && blockEntry.node.markDefs?.forEach((def) => {
|
|
7096
7090
|
isSpan({
|
|
7097
7091
|
schema: editor.schema
|
|
@@ -8259,7 +8253,7 @@ function unsetPatch(editor, patch) {
|
|
|
8259
8253
|
}), !0;
|
|
8260
8254
|
}
|
|
8261
8255
|
function textPatch(snapshot, operation, beforeValue) {
|
|
8262
|
-
const span =
|
|
8256
|
+
const span = getSpan(snapshot, operation.path);
|
|
8263
8257
|
if (!span)
|
|
8264
8258
|
return [];
|
|
8265
8259
|
const beforeSnapshot = {
|
|
@@ -8269,7 +8263,7 @@ function textPatch(snapshot, operation, beforeValue) {
|
|
|
8269
8263
|
value: beforeValue
|
|
8270
8264
|
},
|
|
8271
8265
|
blockIndexMap: /* @__PURE__ */ new Map()
|
|
8272
|
-
}, prevSpan =
|
|
8266
|
+
}, prevSpan = getSpan(beforeSnapshot, operation.path), patch = diffMatchPatch$1(prevSpan?.node.text ?? "", span.node.text, [...operation.path, "text"]);
|
|
8273
8267
|
return patch.value.length ? [patch] : [];
|
|
8274
8268
|
}
|
|
8275
8269
|
function insertNodePatch(operation) {
|
|
@@ -9257,10 +9251,14 @@ const apply = (editor, op) => {
|
|
|
9257
9251
|
focus: op.newProperties.focus
|
|
9258
9252
|
});
|
|
9259
9253
|
if (previousSelectionIsCollapsed && newSelectionIsCollapsed) {
|
|
9260
|
-
const focusSpan =
|
|
9254
|
+
const focusSpan = getSpan(editor, op.properties.focus.path)?.node, newFocusSpan = getSpan(editor, op.newProperties.focus.path)?.node, sameParent = pathEquals(parentPath(op.properties.focus.path), parentPath(op.newProperties.focus.path));
|
|
9261
9255
|
let movedToNextSpan = !1, movedToPreviousSpan = !1;
|
|
9262
9256
|
if (sameParent && focusSpan && newFocusSpan) {
|
|
9263
|
-
const nextSibling = getSibling(editor, op.properties.focus.path,
|
|
9257
|
+
const nextSibling = getSibling(editor, op.properties.focus.path, {
|
|
9258
|
+
direction: "next"
|
|
9259
|
+
}), previousSibling = getSibling(editor, op.properties.focus.path, {
|
|
9260
|
+
direction: "previous"
|
|
9261
|
+
});
|
|
9264
9262
|
movedToNextSpan = nextSibling !== void 0 && pathEquals(nextSibling.path, op.newProperties.focus.path) && focusSpan.text.length === op.properties.focus.offset && op.newProperties.focus.offset === 0, movedToPreviousSpan = previousSibling !== void 0 && pathEquals(previousSibling.path, op.newProperties.focus.path) && op.properties.focus.offset === 0 && newFocusSpan.text.length === op.newProperties.focus.offset;
|
|
9265
9263
|
}
|
|
9266
9264
|
!movedToNextSpan && !movedToPreviousSpan && (editor.decoratorState = {});
|
|
@@ -9461,9 +9459,7 @@ function applyInsertNodeAtPoint(editor, node, at) {
|
|
|
9461
9459
|
schema: editor.schema
|
|
9462
9460
|
}, n) : (n) => isSpan({
|
|
9463
9461
|
schema: editor.schema
|
|
9464
|
-
}, n) ||
|
|
9465
|
-
schema: editor.schema
|
|
9466
|
-
}, n), nodeEntry = getNode(editor, at.path), entry = nodeEntry && match2(nodeEntry.node) ? nodeEntry : void 0;
|
|
9462
|
+
}, n) || isObject$1(editor, n), nodeEntry = getNode(editor, at.path), entry = nodeEntry && match2(nodeEntry.node) ? nodeEntry : void 0;
|
|
9467
9463
|
if (!entry)
|
|
9468
9464
|
return;
|
|
9469
9465
|
const matchPath = entry.path, ref = pathRef(editor, matchPath), isAtEnd = isEnd(editor, at, matchPath);
|
|
@@ -9485,7 +9481,9 @@ function applyMergeNode(editor, path2, position) {
|
|
|
9485
9481
|
const nodeEntry = getNode(editor, path2);
|
|
9486
9482
|
if (!nodeEntry)
|
|
9487
9483
|
return;
|
|
9488
|
-
const node = nodeEntry.node, prevSibling = getSibling(editor, path2,
|
|
9484
|
+
const node = nodeEntry.node, prevSibling = getSibling(editor, path2, {
|
|
9485
|
+
direction: "previous"
|
|
9486
|
+
});
|
|
9489
9487
|
if (!prevSibling)
|
|
9490
9488
|
return;
|
|
9491
9489
|
const prevPath = prevSibling.path, prevKey = prevSibling.node._key ?? "";
|
|
@@ -9970,7 +9968,7 @@ const normalizeNode = (editor, entry) => {
|
|
|
9970
9968
|
schema: editor.schema
|
|
9971
9969
|
}, node)) {
|
|
9972
9970
|
const blockPath = parentPath(path2);
|
|
9973
|
-
if (!
|
|
9971
|
+
if (!getTextBlock(editor, blockPath))
|
|
9974
9972
|
return;
|
|
9975
9973
|
const decorators = getPathSubSchema(editor, path2).decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators.includes(mark));
|
|
9976
9974
|
if (node.text === "" && annotations && annotations.length > 0) {
|
|
@@ -10003,7 +10001,7 @@ const normalizeNode = (editor, entry) => {
|
|
|
10003
10001
|
if (isSpan({
|
|
10004
10002
|
schema: editor.schema
|
|
10005
10003
|
}, node)) {
|
|
10006
|
-
const blockPath = parentPath(path2), blockEntry2 =
|
|
10004
|
+
const blockPath = parentPath(path2), blockEntry2 = getTextBlock(editor, blockPath);
|
|
10007
10005
|
if (blockEntry2) {
|
|
10008
10006
|
const block = blockEntry2.node, decorators = getPathSubSchema(editor, path2).decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
10009
10007
|
if (orphanedAnnotations.length > 0) {
|
|
@@ -10057,9 +10055,7 @@ const normalizeNode = (editor, entry) => {
|
|
|
10057
10055
|
}
|
|
10058
10056
|
return;
|
|
10059
10057
|
}
|
|
10060
|
-
if (
|
|
10061
|
-
schema: editor.schema
|
|
10062
|
-
}, node)) {
|
|
10058
|
+
if (isObject$1(editor, node)) {
|
|
10063
10059
|
const resolved = resolveContainerByPath(editor, path2, node), arrayField = resolved && "container" in resolved ? resolved.field : void 0;
|
|
10064
10060
|
if (arrayField) {
|
|
10065
10061
|
const fieldValue = node[arrayField.name], needsField = !Array.isArray(fieldValue);
|
|
@@ -10093,9 +10089,7 @@ const normalizeNode = (editor, entry) => {
|
|
|
10093
10089
|
}
|
|
10094
10090
|
}
|
|
10095
10091
|
}
|
|
10096
|
-
if (
|
|
10097
|
-
schema: editor.schema
|
|
10098
|
-
}, node)) {
|
|
10092
|
+
if (isObject$1(editor, node)) {
|
|
10099
10093
|
const children = [...getChildren(editor, path2)];
|
|
10100
10094
|
if (children.length > 1) {
|
|
10101
10095
|
const seen = /* @__PURE__ */ new Map();
|
|
@@ -10148,7 +10142,7 @@ const normalizeNode = (editor, entry) => {
|
|
|
10148
10142
|
node: child,
|
|
10149
10143
|
position: "before"
|
|
10150
10144
|
});
|
|
10151
|
-
const refetched =
|
|
10145
|
+
const refetched = getTextBlock(editor, path2)?.node;
|
|
10152
10146
|
if (!refetched)
|
|
10153
10147
|
return;
|
|
10154
10148
|
element = refetched;
|
|
@@ -10168,7 +10162,7 @@ const normalizeNode = (editor, entry) => {
|
|
|
10168
10162
|
type: "unset",
|
|
10169
10163
|
path: childPath
|
|
10170
10164
|
});
|
|
10171
|
-
const refetched =
|
|
10165
|
+
const refetched = getTextBlock(editor, path2)?.node;
|
|
10172
10166
|
if (!refetched)
|
|
10173
10167
|
return;
|
|
10174
10168
|
element = refetched, n--;
|
|
@@ -10180,7 +10174,7 @@ const normalizeNode = (editor, entry) => {
|
|
|
10180
10174
|
type: "unset",
|
|
10181
10175
|
path: prevPath
|
|
10182
10176
|
});
|
|
10183
|
-
const refetched =
|
|
10177
|
+
const refetched = getTextBlock(editor, path2)?.node;
|
|
10184
10178
|
if (!refetched)
|
|
10185
10179
|
return;
|
|
10186
10180
|
element = refetched, n--;
|
|
@@ -10188,15 +10182,13 @@ const normalizeNode = (editor, entry) => {
|
|
|
10188
10182
|
loose: !0
|
|
10189
10183
|
})) {
|
|
10190
10184
|
applyMergeNode(editor, childPath, prev.text.length);
|
|
10191
|
-
const refetched =
|
|
10185
|
+
const refetched = getTextBlock(editor, path2)?.node;
|
|
10192
10186
|
if (!refetched)
|
|
10193
10187
|
return;
|
|
10194
10188
|
element = refetched, n--;
|
|
10195
10189
|
}
|
|
10196
10190
|
}
|
|
10197
|
-
} else if (
|
|
10198
|
-
schema: editor.schema
|
|
10199
|
-
}, child)) {
|
|
10191
|
+
} else if (isObject$1(editor, child)) {
|
|
10200
10192
|
if (prev == null || !isSpan({
|
|
10201
10193
|
schema: editor.schema
|
|
10202
10194
|
}, prev)) {
|
|
@@ -10207,7 +10199,7 @@ const normalizeNode = (editor, entry) => {
|
|
|
10207
10199
|
node: newChild,
|
|
10208
10200
|
position: "before"
|
|
10209
10201
|
});
|
|
10210
|
-
const refetched =
|
|
10202
|
+
const refetched = getTextBlock(editor, path2)?.node;
|
|
10211
10203
|
if (!refetched)
|
|
10212
10204
|
return;
|
|
10213
10205
|
element = refetched, n++;
|
|
@@ -10222,7 +10214,7 @@ const normalizeNode = (editor, entry) => {
|
|
|
10222
10214
|
node: newChild,
|
|
10223
10215
|
position: "after"
|
|
10224
10216
|
});
|
|
10225
|
-
const refetched =
|
|
10217
|
+
const refetched = getTextBlock(editor, path2)?.node;
|
|
10226
10218
|
if (!refetched)
|
|
10227
10219
|
return;
|
|
10228
10220
|
element = refetched, n++;
|
|
@@ -10731,7 +10723,9 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
10731
10723
|
if (!defaultKeyboardShortcuts.arrowDown.guard(event.originEvent) || !isSelectionCollapsed$1(snapshot))
|
|
10732
10724
|
return !1;
|
|
10733
10725
|
const focusedBlockObject = getFocusBlockObject(snapshot);
|
|
10734
|
-
return focusedBlockObject ? !getSibling(snapshot, focusedBlockObject.path,
|
|
10726
|
+
return focusedBlockObject ? !getSibling(snapshot, focusedBlockObject.path, {
|
|
10727
|
+
direction: "next"
|
|
10728
|
+
}) : !1;
|
|
10735
10729
|
},
|
|
10736
10730
|
actions: [({
|
|
10737
10731
|
snapshot
|
|
@@ -10751,7 +10745,9 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
10751
10745
|
if (!defaultKeyboardShortcuts.arrowUp.guard(event.originEvent) || !isSelectionCollapsed$1(snapshot))
|
|
10752
10746
|
return !1;
|
|
10753
10747
|
const focusedBlockObject = getFocusBlockObject(snapshot);
|
|
10754
|
-
return focusedBlockObject ? !getSibling(snapshot, focusedBlockObject.path,
|
|
10748
|
+
return focusedBlockObject ? !getSibling(snapshot, focusedBlockObject.path, {
|
|
10749
|
+
direction: "previous"
|
|
10750
|
+
}) : !1;
|
|
10755
10751
|
},
|
|
10756
10752
|
actions: [({
|
|
10757
10753
|
snapshot
|
|
@@ -10796,7 +10792,9 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
10796
10792
|
}, focusedBlockObject = getFocusBlockObject(positionSnapshot);
|
|
10797
10793
|
if (!focusedBlockObject)
|
|
10798
10794
|
return !1;
|
|
10799
|
-
const previousSibling = getSibling(snapshot, focusedBlockObject.path,
|
|
10795
|
+
const previousSibling = getSibling(snapshot, focusedBlockObject.path, {
|
|
10796
|
+
direction: "previous"
|
|
10797
|
+
});
|
|
10800
10798
|
return (event.position.isEditor || event.position.isContainer) && event.position.block === "start" && !previousSibling;
|
|
10801
10799
|
},
|
|
10802
10800
|
actions: [({
|
|
@@ -10830,7 +10828,9 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
10830
10828
|
}, focusedBlockObject = getFocusBlockObject(positionSnapshot);
|
|
10831
10829
|
if (!focusedBlockObject)
|
|
10832
10830
|
return !1;
|
|
10833
|
-
const nextSibling = getSibling(snapshot, focusedBlockObject.path,
|
|
10831
|
+
const nextSibling = getSibling(snapshot, focusedBlockObject.path, {
|
|
10832
|
+
direction: "next"
|
|
10833
|
+
});
|
|
10834
10834
|
return (event.position.isEditor || event.position.isContainer) && event.position.block === "end" && !nextSibling;
|
|
10835
10835
|
},
|
|
10836
10836
|
actions: [({
|
|
@@ -10855,7 +10855,9 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
10855
10855
|
const focusedTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot);
|
|
10856
10856
|
if (!focusedTextBlock || !selectionCollapsed)
|
|
10857
10857
|
return !1;
|
|
10858
|
-
const previousSibling = getSibling(snapshot, focusedTextBlock.path,
|
|
10858
|
+
const previousSibling = getSibling(snapshot, focusedTextBlock.path, {
|
|
10859
|
+
direction: "previous"
|
|
10860
|
+
});
|
|
10859
10861
|
if (!previousSibling || isListBlock(snapshot.context, focusedTextBlock.node))
|
|
10860
10862
|
return !1;
|
|
10861
10863
|
if (isEmptyTextBlock(snapshot.context, focusedTextBlock.node) && !isTextBlockNode(snapshot.context, previousSibling.node)) {
|
|
@@ -10896,7 +10898,9 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
10896
10898
|
const focusedTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed$1(snapshot);
|
|
10897
10899
|
if (!focusedTextBlock || !selectionCollapsed)
|
|
10898
10900
|
return !1;
|
|
10899
|
-
const nextSibling = getSibling(snapshot, focusedTextBlock.path,
|
|
10901
|
+
const nextSibling = getSibling(snapshot, focusedTextBlock.path, {
|
|
10902
|
+
direction: "next"
|
|
10903
|
+
});
|
|
10900
10904
|
return nextSibling && isEmptyTextBlock(snapshot.context, focusedTextBlock.node) && !isTextBlockNode(snapshot.context, nextSibling.node) ? {
|
|
10901
10905
|
focusedTextBlock,
|
|
10902
10906
|
nextSibling
|
|
@@ -10950,11 +10954,15 @@ function isAtContainerDeadEnd(snapshot, edge) {
|
|
|
10950
10954
|
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
10951
10955
|
if (!focusTextBlock)
|
|
10952
10956
|
return !1;
|
|
10953
|
-
const container = getAncestor(snapshot, focusTextBlock.path,
|
|
10957
|
+
const container = getAncestor(snapshot, focusTextBlock.path, {
|
|
10958
|
+
match: (node, path2) => isEditableContainer(snapshot, node, path2)
|
|
10959
|
+
});
|
|
10954
10960
|
if (!container)
|
|
10955
10961
|
return !1;
|
|
10956
10962
|
const edgeBlock = edge === "end" ? getLastBlock(snapshot) : getFirstBlock(snapshot);
|
|
10957
|
-
return !edgeBlock || !pathEquals(edgeBlock.path, focusTextBlock.path) || !(edge === "end" ? isAtTheEndOfBlock(focusTextBlock)(snapshot) : isAtTheStartOfBlock(focusTextBlock)(snapshot)) ? !1 : getSibling(snapshot, container.path,
|
|
10963
|
+
return !edgeBlock || !pathEquals(edgeBlock.path, focusTextBlock.path) || !(edge === "end" ? isAtTheEndOfBlock(focusTextBlock)(snapshot) : isAtTheStartOfBlock(focusTextBlock)(snapshot)) ? !1 : getSibling(snapshot, container.path, {
|
|
10964
|
+
direction: edge === "end" ? "next" : "previous"
|
|
10965
|
+
}) === void 0;
|
|
10958
10966
|
}
|
|
10959
10967
|
const breakingOutOfContainer = defineBehavior({
|
|
10960
10968
|
on: "insert.break",
|
|
@@ -10969,7 +10977,9 @@ const breakingOutOfContainer = defineBehavior({
|
|
|
10969
10977
|
const lastBlock = getLastBlock(snapshot);
|
|
10970
10978
|
if (!lastBlock || !pathEquals(lastBlock.path, focusTextBlock.path) || !isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
10971
10979
|
return !1;
|
|
10972
|
-
const previousBlock = getSibling(snapshot, focusTextBlock.path,
|
|
10980
|
+
const previousBlock = getSibling(snapshot, focusTextBlock.path, {
|
|
10981
|
+
direction: "previous"
|
|
10982
|
+
});
|
|
10973
10983
|
if (!previousBlock || !isEmptyTextBlock(snapshot.context, previousBlock.node))
|
|
10974
10984
|
return !1;
|
|
10975
10985
|
const escapeAfter = getEscapeTarget(snapshot, focusTextBlock.path);
|
|
@@ -11009,11 +11019,13 @@ const breakingOutOfContainer = defineBehavior({
|
|
|
11009
11019
|
})]]
|
|
11010
11020
|
});
|
|
11011
11021
|
function getEscapeTarget(snapshot, path2) {
|
|
11012
|
-
return getAncestor(snapshot, path2,
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
|
|
11022
|
+
return getAncestor(snapshot, path2, {
|
|
11023
|
+
match: (node, ancestorPath) => {
|
|
11024
|
+
if (!isEditableContainer(snapshot, node, ancestorPath))
|
|
11025
|
+
return !1;
|
|
11026
|
+
const enclosing = getEnclosingContainer(snapshot, ancestorPath);
|
|
11027
|
+
return enclosing ? enclosing.of.some((member) => member.type === snapshot.context.schema.block.name) : !0;
|
|
11028
|
+
}
|
|
11017
11029
|
})?.path;
|
|
11018
11030
|
}
|
|
11019
11031
|
const coreContainerBehaviors = {
|
|
@@ -11461,7 +11473,7 @@ const coreDndBehaviors = [
|
|
|
11461
11473
|
for (const entry of getNodes(snapshot, {
|
|
11462
11474
|
from: selectionStartBlock.path,
|
|
11463
11475
|
to: selectionEndBlock.path,
|
|
11464
|
-
match: (
|
|
11476
|
+
match: (_, path2) => isBlock(snapshot, path2)
|
|
11465
11477
|
})) {
|
|
11466
11478
|
const block = getBlock(snapshot, entry.path);
|
|
11467
11479
|
block && selectedBlocks.push(block);
|
|
@@ -11518,7 +11530,11 @@ function isAtTheBeginningOfBlock({
|
|
|
11518
11530
|
}) {
|
|
11519
11531
|
if (!isTextBlock(snapshot.context, block) || !snapshot.context.selection || !isSelectionCollapsed(snapshot.context.selection))
|
|
11520
11532
|
return !1;
|
|
11521
|
-
const focusPath = snapshot.context.selection.focus.path, ancestorTextBlock =
|
|
11533
|
+
const focusPath = snapshot.context.selection.focus.path, ancestorTextBlock = getParent(snapshot, focusPath, {
|
|
11534
|
+
match: (node) => isTextBlock({
|
|
11535
|
+
schema: snapshot.context.schema
|
|
11536
|
+
}, node)
|
|
11537
|
+
});
|
|
11522
11538
|
if (!ancestorTextBlock || ancestorTextBlock.node._key !== block._key)
|
|
11523
11539
|
return !1;
|
|
11524
11540
|
const lastSegment = focusPath.at(-1);
|
|
@@ -12069,7 +12085,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
12069
12085
|
}, blockPath);
|
|
12070
12086
|
const splitRange = at ?? editor.selection;
|
|
12071
12087
|
if (splitRange && isRange(splitRange)) {
|
|
12072
|
-
const
|
|
12088
|
+
const splitLeaf = getNode(editor, splitRange.anchor.path)?.node;
|
|
12073
12089
|
if (!(splitLeaf && isCollapsedRange(splitRange) && isSpan({
|
|
12074
12090
|
schema: editor.schema
|
|
12075
12091
|
}, splitLeaf) && splitLeaf.text.length > 0)) {
|
|
@@ -12112,7 +12128,11 @@ const removeAnnotationOperationImplementation = ({
|
|
|
12112
12128
|
const editor = operation.editor, at = operation.at ? resolveSelection(operation.editor, operation.at) : null, effectiveSelection = at ?? editor.selection;
|
|
12113
12129
|
if (effectiveSelection)
|
|
12114
12130
|
if (isCollapsedRange(effectiveSelection)) {
|
|
12115
|
-
const blockEntry =
|
|
12131
|
+
const blockEntry = getParent(snapshot, effectiveSelection.focus.path, {
|
|
12132
|
+
match: (node) => isTextBlock({
|
|
12133
|
+
schema: editor.schema
|
|
12134
|
+
}, node)
|
|
12135
|
+
});
|
|
12116
12136
|
if (!blockEntry)
|
|
12117
12137
|
return;
|
|
12118
12138
|
const {
|
|
@@ -12172,7 +12192,7 @@ const removeAnnotationOperationImplementation = ({
|
|
|
12172
12192
|
withoutNormalizing(editor, () => {
|
|
12173
12193
|
const splitRange = at ?? editor.selection;
|
|
12174
12194
|
if (splitRange && isRange(splitRange)) {
|
|
12175
|
-
const
|
|
12195
|
+
const splitLeaf = getNode(editor, splitRange.anchor.path)?.node;
|
|
12176
12196
|
if (!(splitLeaf && isCollapsedRange(splitRange) && isSpan({
|
|
12177
12197
|
schema: editor.schema
|
|
12178
12198
|
}, splitLeaf) && splitLeaf.text.length > 0)) {
|
|
@@ -12361,9 +12381,7 @@ const childSetOperationImplementation = ({
|
|
|
12361
12381
|
}));
|
|
12362
12382
|
return;
|
|
12363
12383
|
}
|
|
12364
|
-
if (
|
|
12365
|
-
schema: operation.editor.schema
|
|
12366
|
-
}, child)) {
|
|
12384
|
+
if (isObject$1(operation.editor, child)) {
|
|
12367
12385
|
const blockPath = parentPath(childPath), {
|
|
12368
12386
|
inlineObjects
|
|
12369
12387
|
} = getPathSubSchema(snapshot, blockPath), definition = inlineObjects.find((definition2) => definition2.name === child._type);
|
|
@@ -12412,9 +12430,7 @@ const childSetOperationImplementation = ({
|
|
|
12412
12430
|
setNodeProperties(operation.editor, newNode, childPath);
|
|
12413
12431
|
return;
|
|
12414
12432
|
}
|
|
12415
|
-
if (
|
|
12416
|
-
schema: operation.editor.schema
|
|
12417
|
-
}, child)) {
|
|
12433
|
+
if (isObject$1(operation.editor, child)) {
|
|
12418
12434
|
const unsetProps = {};
|
|
12419
12435
|
for (const prop of operation.props)
|
|
12420
12436
|
prop !== "_type" && (prop === "_key" ? unsetProps._key = context.keyGenerator() : unsetProps[prop] = null);
|
|
@@ -12471,7 +12487,11 @@ const childSetOperationImplementation = ({
|
|
|
12471
12487
|
}, node)
|
|
12472
12488
|
}))?.at(0))
|
|
12473
12489
|
return;
|
|
12474
|
-
const blockEntry =
|
|
12490
|
+
const blockEntry = getParent(snapshot, at.focus.path, {
|
|
12491
|
+
match: (node) => isTextBlock({
|
|
12492
|
+
schema: snapshot.context.schema
|
|
12493
|
+
}, node)
|
|
12494
|
+
});
|
|
12475
12495
|
if (!blockEntry)
|
|
12476
12496
|
return;
|
|
12477
12497
|
const {
|
|
@@ -12519,7 +12539,7 @@ const childSetOperationImplementation = ({
|
|
|
12519
12539
|
affinity: "inward"
|
|
12520
12540
|
});
|
|
12521
12541
|
withoutNormalizing(editor, () => {
|
|
12522
|
-
const
|
|
12542
|
+
const decoratorLeaf = getNode(editor, at.anchor.path)?.node;
|
|
12523
12543
|
if (!(decoratorLeaf && isCollapsedRange(at) && isSpan({
|
|
12524
12544
|
schema: editor.schema
|
|
12525
12545
|
}, decoratorLeaf) && decoratorLeaf.text.length > 0)) {
|
|
@@ -12554,7 +12574,11 @@ const childSetOperationImplementation = ({
|
|
|
12554
12574
|
}
|
|
12555
12575
|
});
|
|
12556
12576
|
} else {
|
|
12557
|
-
const textBlockEntry =
|
|
12577
|
+
const textBlockEntry = getParent(snapshot, at.focus.path, {
|
|
12578
|
+
match: (node) => isTextBlock({
|
|
12579
|
+
schema: editor.schema
|
|
12580
|
+
}, node)
|
|
12581
|
+
});
|
|
12558
12582
|
if (!textBlockEntry)
|
|
12559
12583
|
return;
|
|
12560
12584
|
const {
|
|
@@ -12594,15 +12618,21 @@ function unhangRange(snapshot, range2) {
|
|
|
12594
12618
|
let [start2, end2] = rangeEdges(range2, {
|
|
12595
12619
|
children: context.value
|
|
12596
12620
|
});
|
|
12597
|
-
if (start2.offset !== 0 || end2.offset !== 0 || isCollapsedRange(range2) || getSibling(snapshot, end2.path,
|
|
12621
|
+
if (start2.offset !== 0 || end2.offset !== 0 || isCollapsedRange(range2) || getSibling(snapshot, end2.path, {
|
|
12622
|
+
direction: "previous"
|
|
12623
|
+
}) !== void 0)
|
|
12598
12624
|
return range2;
|
|
12599
|
-
const endBlock =
|
|
12625
|
+
const endBlock = getParent(snapshot, end2.path, {
|
|
12626
|
+
match: (node) => isTextBlock({
|
|
12627
|
+
schema: snapshot.context.schema
|
|
12628
|
+
}, node)
|
|
12629
|
+
}), blockPath = endBlock ? endBlock.path : [];
|
|
12600
12630
|
for (const {
|
|
12601
12631
|
path: path2
|
|
12602
12632
|
} of getNodes(snapshot, {
|
|
12603
12633
|
from: start2.path,
|
|
12604
12634
|
to: end2.path,
|
|
12605
|
-
match: (candidate, candidatePath) =>
|
|
12635
|
+
match: (candidate, candidatePath) => isLeafObject(snapshot, candidate, candidatePath) || isEditableContainer(snapshot, candidate, candidatePath)
|
|
12606
12636
|
}))
|
|
12607
12637
|
if (!isAncestorPath(path2, start2.path) && !isAncestorPath(path2, end2.path))
|
|
12608
12638
|
return range2;
|
|
@@ -12639,23 +12669,6 @@ function unhangRange(snapshot, range2) {
|
|
|
12639
12669
|
focus: end2
|
|
12640
12670
|
};
|
|
12641
12671
|
}
|
|
12642
|
-
function getHighestObjectNode(snapshot, path2) {
|
|
12643
|
-
const ancestors = getAncestors(snapshot, path2);
|
|
12644
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
12645
|
-
const ancestor = ancestors[i];
|
|
12646
|
-
if (ancestor && isVoidNode(snapshot, ancestor.node, ancestor.path))
|
|
12647
|
-
return {
|
|
12648
|
-
node: ancestor.node,
|
|
12649
|
-
path: ancestor.path
|
|
12650
|
-
};
|
|
12651
|
-
}
|
|
12652
|
-
const entry = getNode(snapshot, path2);
|
|
12653
|
-
if (entry && isVoidNode(snapshot, entry.node, entry.path))
|
|
12654
|
-
return {
|
|
12655
|
-
node: entry.node,
|
|
12656
|
-
path: entry.path
|
|
12657
|
-
};
|
|
12658
|
-
}
|
|
12659
12672
|
function pointRef(editor, point2, options = {}) {
|
|
12660
12673
|
const {
|
|
12661
12674
|
affinity = "forward"
|
|
@@ -12674,8 +12687,12 @@ function pointRef(editor, point2, options = {}) {
|
|
|
12674
12687
|
function getFullyCoveredContainers(editor, range2) {
|
|
12675
12688
|
const [start2, end2] = rangeEdges(range2, editor);
|
|
12676
12689
|
return {
|
|
12677
|
-
start: getAncestor(editor, start2.path,
|
|
12678
|
-
|
|
12690
|
+
start: getAncestor(editor, start2.path, {
|
|
12691
|
+
match: (node, path2) => isFullyCovered(editor, node, path2, start2, end2)
|
|
12692
|
+
})?.path,
|
|
12693
|
+
end: getAncestor(editor, end2.path, {
|
|
12694
|
+
match: (node, path2) => isFullyCovered(editor, node, path2, start2, end2)
|
|
12695
|
+
})?.path
|
|
12679
12696
|
};
|
|
12680
12697
|
}
|
|
12681
12698
|
function isFullyCovered(editor, node, path2, rangeStart2, rangeEnd2) {
|
|
@@ -12748,21 +12765,23 @@ function deleteSameBlockRange(editor, start2, end2, capture) {
|
|
|
12748
12765
|
if (pathEquals(start2.path, end2.path))
|
|
12749
12766
|
return removeTextRange(editor, start2.path, start2.offset, end2.offset, capture);
|
|
12750
12767
|
const startEntry = getNode(editor, start2.path);
|
|
12751
|
-
if (startEntry &&
|
|
12768
|
+
if (startEntry && isLeafObject(editor, startEntry.node, start2.path))
|
|
12752
12769
|
return editor.apply({
|
|
12753
12770
|
type: "unset",
|
|
12754
12771
|
path: start2.path
|
|
12755
12772
|
}), null;
|
|
12756
12773
|
const removed = removeTextFromOffset(editor, start2.path, start2.offset, capture);
|
|
12757
12774
|
removeChildrenBetween(editor, start2.path, end2.path);
|
|
12758
|
-
const adjustedEnd = getSibling(editor, start2.path,
|
|
12759
|
-
|
|
12775
|
+
const adjustedEnd = getSibling(editor, start2.path, {
|
|
12776
|
+
direction: "next"
|
|
12777
|
+
});
|
|
12778
|
+
return adjustedEnd ? isLeafObject(editor, adjustedEnd.node, adjustedEnd.path) ? (editor.apply({
|
|
12760
12779
|
type: "unset",
|
|
12761
12780
|
path: adjustedEnd.path
|
|
12762
12781
|
}), removed) : (removeTextUpToOffset(editor, adjustedEnd.path, end2.offset), removed) : removed;
|
|
12763
12782
|
}
|
|
12764
12783
|
function deleteSameParentCrossBlockRange(editor, startBlockPath, endBlockPath, start2, end2, removeEmptyStartBlock) {
|
|
12765
|
-
const startBlockNode = getNode(editor, startBlockPath), endBlockNode = getNode(editor, endBlockPath), startIsVoid = startBlockNode != null &&
|
|
12784
|
+
const startBlockNode = getNode(editor, startBlockPath), endBlockNode = getNode(editor, endBlockPath), startIsVoid = startBlockNode != null && isLeafObject(editor, startBlockNode.node, startBlockPath), endIsVoid = endBlockNode != null && isLeafObject(editor, endBlockNode.node, endBlockPath);
|
|
12766
12785
|
if (startIsVoid || (pathEquals(start2.path, startBlockPath) ? removeAllChildren(editor, startBlockPath) : (removeTextFromOffset(editor, start2.path, start2.offset, !1), removeTrailingChildren(editor, start2.path))), removeBlocksBetween(editor, startBlockPath, endBlockPath), startIsVoid && endIsVoid) {
|
|
12767
12786
|
removeNodeAt(editor, endBlockPath), removeNodeAt(editor, startBlockPath);
|
|
12768
12787
|
return;
|
|
@@ -12780,7 +12799,9 @@ function deleteSameParentCrossBlockRange(editor, startBlockPath, endBlockPath, s
|
|
|
12780
12799
|
removeNodeAt(editor, endBlockPath);
|
|
12781
12800
|
return;
|
|
12782
12801
|
}
|
|
12783
|
-
const adjustedEndBlockPath = getSibling(editor, startBlockPath,
|
|
12802
|
+
const adjustedEndBlockPath = getSibling(editor, startBlockPath, {
|
|
12803
|
+
direction: "next"
|
|
12804
|
+
})?.path ?? startBlockPath;
|
|
12784
12805
|
if (!pathEquals(end2.path, endBlockPath)) {
|
|
12785
12806
|
removeLeadingChildrenOf(editor, adjustedEndBlockPath, end2.path);
|
|
12786
12807
|
const firstChild = getFirstChild(editor, adjustedEndBlockPath);
|
|
@@ -12801,10 +12822,14 @@ function deleteCrossParentRange(editor, startBlockPath, endBlockPath, start2, en
|
|
|
12801
12822
|
if (!lcaContainer || lcaContainer.of.some((member) => member.type === editor.schema.block.name))
|
|
12802
12823
|
removeChildrenBetween(editor, startBranchRoot, endBranchRoot);
|
|
12803
12824
|
else {
|
|
12804
|
-
let cursor = getSibling(editor, startBranchRoot,
|
|
12825
|
+
let cursor = getSibling(editor, startBranchRoot, {
|
|
12826
|
+
direction: "next"
|
|
12827
|
+
});
|
|
12805
12828
|
for (; cursor && !pathEquals(cursor.path, endBranchRoot); ) {
|
|
12806
12829
|
const cursorPath = cursor.path;
|
|
12807
|
-
clearContainerContents(editor, cursorPath), cursor = getSibling(editor, cursorPath,
|
|
12830
|
+
clearContainerContents(editor, cursorPath), cursor = getSibling(editor, cursorPath, {
|
|
12831
|
+
direction: "next"
|
|
12832
|
+
});
|
|
12808
12833
|
}
|
|
12809
12834
|
}
|
|
12810
12835
|
let endLevel = endBlockPath;
|
|
@@ -12831,7 +12856,7 @@ function deleteCrossParentRange(editor, startBlockPath, endBlockPath, start2, en
|
|
|
12831
12856
|
});
|
|
12832
12857
|
}
|
|
12833
12858
|
function removeTextRange(editor, path2, startOffset, endOffset, capture) {
|
|
12834
|
-
const span =
|
|
12859
|
+
const span = getSpan(editor, path2);
|
|
12835
12860
|
if (!span)
|
|
12836
12861
|
return null;
|
|
12837
12862
|
const text = span.node.text.slice(startOffset, endOffset);
|
|
@@ -12843,7 +12868,7 @@ function removeTextRange(editor, path2, startOffset, endOffset, capture) {
|
|
|
12843
12868
|
}), capture ? text : null);
|
|
12844
12869
|
}
|
|
12845
12870
|
function removeTextFromOffset(editor, path2, offset, capture) {
|
|
12846
|
-
const span =
|
|
12871
|
+
const span = getSpan(editor, path2);
|
|
12847
12872
|
if (!span || offset >= span.node.text.length)
|
|
12848
12873
|
return null;
|
|
12849
12874
|
const text = span.node.text.slice(offset);
|
|
@@ -12857,7 +12882,7 @@ function removeTextFromOffset(editor, path2, offset, capture) {
|
|
|
12857
12882
|
function removeTextUpToOffset(editor, path2, offset) {
|
|
12858
12883
|
if (offset <= 0)
|
|
12859
12884
|
return;
|
|
12860
|
-
const span =
|
|
12885
|
+
const span = getSpan(editor, path2);
|
|
12861
12886
|
span && editor.apply({
|
|
12862
12887
|
type: "remove_text",
|
|
12863
12888
|
path: path2,
|
|
@@ -12866,9 +12891,13 @@ function removeTextUpToOffset(editor, path2, offset) {
|
|
|
12866
12891
|
});
|
|
12867
12892
|
}
|
|
12868
12893
|
function removeChildrenBetween(editor, startChildPath, endChildPath) {
|
|
12869
|
-
let cursor = getSibling(editor, startChildPath,
|
|
12894
|
+
let cursor = getSibling(editor, startChildPath, {
|
|
12895
|
+
direction: "next"
|
|
12896
|
+
});
|
|
12870
12897
|
for (; cursor && !pathEquals(cursor.path, endChildPath); )
|
|
12871
|
-
removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startChildPath,
|
|
12898
|
+
removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startChildPath, {
|
|
12899
|
+
direction: "next"
|
|
12900
|
+
});
|
|
12872
12901
|
}
|
|
12873
12902
|
function clearContainerContents(editor, containerPath) {
|
|
12874
12903
|
const node = getNode(editor, containerPath)?.node;
|
|
@@ -12895,27 +12924,43 @@ function clearContainerContents(editor, containerPath) {
|
|
|
12895
12924
|
clearContainerContents(editor, child.path);
|
|
12896
12925
|
}
|
|
12897
12926
|
function removeTrailingChildren(editor, startChildPath) {
|
|
12898
|
-
let cursor = getSibling(editor, startChildPath,
|
|
12927
|
+
let cursor = getSibling(editor, startChildPath, {
|
|
12928
|
+
direction: "next"
|
|
12929
|
+
});
|
|
12899
12930
|
for (; cursor; )
|
|
12900
|
-
removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startChildPath,
|
|
12931
|
+
removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startChildPath, {
|
|
12932
|
+
direction: "next"
|
|
12933
|
+
});
|
|
12901
12934
|
}
|
|
12902
12935
|
function clearTrailingSiblings(editor, startChildPath) {
|
|
12903
|
-
let cursor = getSibling(editor, startChildPath,
|
|
12936
|
+
let cursor = getSibling(editor, startChildPath, {
|
|
12937
|
+
direction: "next"
|
|
12938
|
+
});
|
|
12904
12939
|
for (; cursor; ) {
|
|
12905
12940
|
const cursorPath = cursor.path;
|
|
12906
|
-
clearContainerContents(editor, cursorPath), cursor = getSibling(editor, cursorPath,
|
|
12941
|
+
clearContainerContents(editor, cursorPath), cursor = getSibling(editor, cursorPath, {
|
|
12942
|
+
direction: "next"
|
|
12943
|
+
});
|
|
12907
12944
|
}
|
|
12908
12945
|
}
|
|
12909
12946
|
function removePrecedingSiblings(editor, startChildPath) {
|
|
12910
|
-
let cursor = getSibling(editor, startChildPath,
|
|
12947
|
+
let cursor = getSibling(editor, startChildPath, {
|
|
12948
|
+
direction: "previous"
|
|
12949
|
+
});
|
|
12911
12950
|
for (; cursor; )
|
|
12912
|
-
removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startChildPath,
|
|
12951
|
+
removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startChildPath, {
|
|
12952
|
+
direction: "previous"
|
|
12953
|
+
});
|
|
12913
12954
|
}
|
|
12914
12955
|
function clearPrecedingSiblings(editor, startChildPath) {
|
|
12915
|
-
let cursor = getSibling(editor, startChildPath,
|
|
12956
|
+
let cursor = getSibling(editor, startChildPath, {
|
|
12957
|
+
direction: "previous"
|
|
12958
|
+
});
|
|
12916
12959
|
for (; cursor; ) {
|
|
12917
12960
|
const cursorPath = cursor.path;
|
|
12918
|
-
clearContainerContents(editor, cursorPath), cursor = getSibling(editor, cursorPath,
|
|
12961
|
+
clearContainerContents(editor, cursorPath), cursor = getSibling(editor, cursorPath, {
|
|
12962
|
+
direction: "previous"
|
|
12963
|
+
});
|
|
12919
12964
|
}
|
|
12920
12965
|
}
|
|
12921
12966
|
function parentAcceptsTextBlock(editor, path2) {
|
|
@@ -12936,14 +12981,18 @@ function removeLeadingChildrenOf(editor, blockPath, endChildPath) {
|
|
|
12936
12981
|
removeNodeAt(editor, firstChild.path), firstChild = getFirstChild(editor, blockPath);
|
|
12937
12982
|
}
|
|
12938
12983
|
function removeBlocksBetween(editor, startBlockPath, endBlockPath) {
|
|
12939
|
-
let cursor = getSibling(editor, startBlockPath,
|
|
12984
|
+
let cursor = getSibling(editor, startBlockPath, {
|
|
12985
|
+
direction: "next"
|
|
12986
|
+
});
|
|
12940
12987
|
for (; cursor && !pathEquals(cursor.path, endBlockPath); )
|
|
12941
|
-
removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startBlockPath,
|
|
12988
|
+
removeNodeAt(editor, cursor.path), cursor = getSibling(editor, startBlockPath, {
|
|
12989
|
+
direction: "next"
|
|
12990
|
+
});
|
|
12942
12991
|
}
|
|
12943
12992
|
function mergeBlock(editor, startBlockPath, endBlockPath, removeEmptyStartBlock) {
|
|
12944
12993
|
if (pathEquals(startBlockPath, endBlockPath))
|
|
12945
12994
|
return;
|
|
12946
|
-
const startBlock =
|
|
12995
|
+
const startBlock = getTextBlock(editor, startBlockPath), endBlock = getTextBlock(editor, endBlockPath);
|
|
12947
12996
|
if (!startBlock || !endBlock)
|
|
12948
12997
|
return;
|
|
12949
12998
|
if (removeEmptyStartBlock && isEmptyTextBlock({
|
|
@@ -12975,7 +13024,10 @@ function removeNodeAt(editor, path2) {
|
|
|
12975
13024
|
}
|
|
12976
13025
|
function deleteCollapsed(editor, point2, options) {
|
|
12977
13026
|
withoutNormalizing(editor, () => {
|
|
12978
|
-
const furthestObjectNode =
|
|
13027
|
+
const pointEntry = getNode(editor, point2.path), furthestObjectNode = pointEntry && isLeafObject(editor, pointEntry.node, point2.path) ? pointEntry : getAncestor(editor, point2.path, {
|
|
13028
|
+
match: (node, ancestorPath) => isLeafObject(editor, node, ancestorPath),
|
|
13029
|
+
mode: "highest"
|
|
13030
|
+
});
|
|
12979
13031
|
if (furthestObjectNode) {
|
|
12980
13032
|
editor.apply({
|
|
12981
13033
|
type: "unset",
|
|
@@ -13022,11 +13074,19 @@ function resolveExplicitRange(editor, at) {
|
|
|
13022
13074
|
return null;
|
|
13023
13075
|
const [start2, end2] = rangeEdges(at, editor), startBlock = getEnclosingBlock(editor, start2.path), endBlock = getEnclosingBlock(editor, end2.path);
|
|
13024
13076
|
let clampedStart = start2, clampedEnd = end2;
|
|
13025
|
-
|
|
13077
|
+
const startEntry = getNode(editor, start2.path);
|
|
13078
|
+
if ((startEntry && isLeafObject(editor, startEntry.node, start2.path) ? startEntry : getAncestor(editor, start2.path, {
|
|
13079
|
+
match: (node, ancestorPath) => isLeafObject(editor, node, ancestorPath),
|
|
13080
|
+
mode: "highest"
|
|
13081
|
+
})) && startBlock) {
|
|
13026
13082
|
const beforePoint = before(editor, start2);
|
|
13027
13083
|
beforePoint && isAncestorPath(startBlock.path, beforePoint.path) && (clampedStart = beforePoint);
|
|
13028
13084
|
}
|
|
13029
|
-
|
|
13085
|
+
const endEntry = getNode(editor, end2.path);
|
|
13086
|
+
if ((endEntry && isLeafObject(editor, endEntry.node, end2.path) ? endEntry : getAncestor(editor, end2.path, {
|
|
13087
|
+
match: (node, ancestorPath) => isLeafObject(editor, node, ancestorPath),
|
|
13088
|
+
mode: "highest"
|
|
13089
|
+
})) && endBlock) {
|
|
13030
13090
|
const afterPoint = after(editor, end2);
|
|
13031
13091
|
afterPoint && isAncestorPath(endBlock.path, afterPoint.path) && (clampedEnd = afterPoint);
|
|
13032
13092
|
}
|
|
@@ -13130,10 +13190,6 @@ function transformPoint(point2, innerPrefix) {
|
|
|
13130
13190
|
offset: point2.offset
|
|
13131
13191
|
} : point2;
|
|
13132
13192
|
}
|
|
13133
|
-
function isEmptyContainer(snapshot, path2) {
|
|
13134
|
-
const children = getChildren(snapshot, path2);
|
|
13135
|
-
return children.length === 1 && isEmptyTextBlock(snapshot.context, children[0].node);
|
|
13136
|
-
}
|
|
13137
13193
|
const deleteOperationImplementation = ({
|
|
13138
13194
|
operation
|
|
13139
13195
|
}) => {
|
|
@@ -13142,19 +13198,27 @@ const deleteOperationImplementation = ({
|
|
|
13142
13198
|
throw new Error("Unable to delete without a selection");
|
|
13143
13199
|
const [start2, end2] = rangeEdges(at, operation.editor);
|
|
13144
13200
|
if (operation.unit === "block") {
|
|
13145
|
-
unsetMatchedNodesInRange(operation.editor, start2.path, end2.path, (
|
|
13201
|
+
unsetMatchedNodesInRange(operation.editor, start2.path, end2.path, (_, path2) => isBlock(operation.editor, path2));
|
|
13146
13202
|
return;
|
|
13147
13203
|
}
|
|
13148
13204
|
if (operation.unit === "child") {
|
|
13149
|
-
unsetMatchedNodesInRange(operation.editor, start2.path, end2.path, (
|
|
13205
|
+
unsetMatchedNodesInRange(operation.editor, start2.path, end2.path, (_, path2) => isInline(operation.editor, path2));
|
|
13150
13206
|
return;
|
|
13151
13207
|
}
|
|
13152
13208
|
if (operation.direction === "backward" && operation.unit === "line") {
|
|
13153
|
-
const parentBlockEntry = pathEquals(at.anchor.path, at.focus.path) ?
|
|
13209
|
+
const parentBlockEntry = pathEquals(at.anchor.path, at.focus.path) ? getParent(operation.editor, at.anchor.path, {
|
|
13210
|
+
match: (node) => isTextBlock({
|
|
13211
|
+
schema: operation.editor.schema
|
|
13212
|
+
}, node)
|
|
13213
|
+
}) : (() => {
|
|
13154
13214
|
const fromPath = commonPath(at.anchor.path, at.focus.path), nodeEntry = getNode(operation.editor, fromPath);
|
|
13155
13215
|
return nodeEntry && isTextBlockNode({
|
|
13156
13216
|
schema: operation.editor.schema
|
|
13157
|
-
}, nodeEntry.node) ? nodeEntry :
|
|
13217
|
+
}, nodeEntry.node) ? nodeEntry : getParent(operation.editor, fromPath, {
|
|
13218
|
+
match: (node) => isTextBlock({
|
|
13219
|
+
schema: operation.editor.schema
|
|
13220
|
+
}, node)
|
|
13221
|
+
});
|
|
13158
13222
|
})();
|
|
13159
13223
|
if (parentBlockEntry) {
|
|
13160
13224
|
const parentElementRange = range(operation.editor, parentBlockEntry.path, at.anchor), currentLineRange = findCurrentLineRange(operation.editor, parentElementRange);
|
|
@@ -13169,8 +13233,10 @@ const deleteOperationImplementation = ({
|
|
|
13169
13233
|
}
|
|
13170
13234
|
const direction = operation.direction === "backward" ? "backward" : "forward", selection = operation.at ? "preserve" : "collapse-to-start";
|
|
13171
13235
|
if (isCollapsedRange(at)) {
|
|
13172
|
-
const enclosingContainer = getAncestor(operation.editor, at.anchor.path,
|
|
13173
|
-
|
|
13236
|
+
const enclosingContainer = getAncestor(operation.editor, at.anchor.path, {
|
|
13237
|
+
match: (node, path2) => isObject$1(operation.editor, node) && isEditableContainer(operation.editor, node, path2)
|
|
13238
|
+
}), enclosingContainerChildren = enclosingContainer ? getChildren(operation.editor, enclosingContainer.path) : void 0, [firstChild] = enclosingContainerChildren ?? [];
|
|
13239
|
+
if (enclosingContainer && enclosingContainerChildren?.length === 1 && firstChild && isEmptyTextBlock(operation.editor.context, firstChild.node)) {
|
|
13174
13240
|
unwrapContainer(operation.editor, enclosingContainer.path, operation.direction === "backward" ? "before" : "after");
|
|
13175
13241
|
return;
|
|
13176
13242
|
}
|
|
@@ -13627,10 +13693,10 @@ function splitBlockAndInsert(editor, block, blockPath, splitAt) {
|
|
|
13627
13693
|
affinity: "backward"
|
|
13628
13694
|
});
|
|
13629
13695
|
if (splitAt.offset > 0) {
|
|
13630
|
-
const spanEntry =
|
|
13696
|
+
const spanEntry = getSpan(editor, splitAt.path);
|
|
13631
13697
|
spanEntry && splitAt.offset < spanEntry.node.text.length && applySplitNode(editor, splitAt.path, splitAt.offset);
|
|
13632
13698
|
}
|
|
13633
|
-
const currentBlockPath = blockPathRef.current ?? blockPath, blockEntry =
|
|
13699
|
+
const currentBlockPath = blockPathRef.current ?? blockPath, blockEntry = getTextBlock(editor, currentBlockPath);
|
|
13634
13700
|
if (blockEntry) {
|
|
13635
13701
|
const childSegment = splitAt.path[blockPath.length + 1], childIndex = resolveChildIndex(blockEntry.node.children, childSegment), splitAtIndex = splitAt.offset > 0 ? childIndex + 1 : childIndex;
|
|
13636
13702
|
splitAtIndex > 0 && splitAtIndex < blockEntry.node.children.length && applySplitNode(editor, currentBlockPath, splitAtIndex);
|
|
@@ -13647,7 +13713,7 @@ function mergeTextBlockFragment(args) {
|
|
|
13647
13713
|
endBlockPath,
|
|
13648
13714
|
select: select2,
|
|
13649
13715
|
wasCrossBlock
|
|
13650
|
-
} = args, endBlockEntry =
|
|
13716
|
+
} = args, endBlockEntry = getTextBlock(editor, endBlockPath);
|
|
13651
13717
|
if (!endBlockEntry)
|
|
13652
13718
|
return;
|
|
13653
13719
|
const endBlock = endBlockEntry.node, {
|
|
@@ -13705,7 +13771,11 @@ function executeDeleteThenInsert(args) {
|
|
|
13705
13771
|
const collapsedRange = collapsedRangeRef.unref() ?? editor.selection, collapsedPoint = collapsedRange ? rangeStart(collapsedRange, editor) : void 0;
|
|
13706
13772
|
if (!collapsedPoint)
|
|
13707
13773
|
return;
|
|
13708
|
-
const resolvedBlock =
|
|
13774
|
+
const resolvedBlock = getParent(editor, collapsedPoint.path, {
|
|
13775
|
+
match: (node) => isTextBlock({
|
|
13776
|
+
schema: editor.schema
|
|
13777
|
+
}, node)
|
|
13778
|
+
}), blockIsText = isTextBlock({
|
|
13709
13779
|
schema: editor.schema
|
|
13710
13780
|
}, block), postDeleteSelection = select2 === "none" ? collapsedRange : selectionAtEntry;
|
|
13711
13781
|
if (blockIsText && resolvedBlock) {
|
|
@@ -13755,7 +13825,9 @@ function removeAdjacentEmptyTextBlock(args) {
|
|
|
13755
13825
|
insertedPath
|
|
13756
13826
|
} = args;
|
|
13757
13827
|
for (const direction of ["next", "previous"]) {
|
|
13758
|
-
const sibling = getSibling(editor, insertedPath,
|
|
13828
|
+
const sibling = getSibling(editor, insertedPath, {
|
|
13829
|
+
direction
|
|
13830
|
+
});
|
|
13759
13831
|
if (sibling && isEmptyTextBlock(context, sibling.node)) {
|
|
13760
13832
|
editor.apply({
|
|
13761
13833
|
type: "unset",
|
|
@@ -13825,11 +13897,11 @@ function insertFragmentChildren(editor, block, at) {
|
|
|
13825
13897
|
schema: editor.schema
|
|
13826
13898
|
}, block))
|
|
13827
13899
|
return;
|
|
13828
|
-
at.offset > 0 &&
|
|
13900
|
+
at.offset > 0 && getSpan(editor, at.path) && applySplitNode(editor, at.path, at.offset);
|
|
13829
13901
|
const parent = parentPath(at.path);
|
|
13830
13902
|
let firstInsertedKey;
|
|
13831
13903
|
if (at.offset === 0 && block.children.length === 1) {
|
|
13832
|
-
const firstChild = block.children[0], existingEntry =
|
|
13904
|
+
const firstChild = block.children[0], existingEntry = getSpan(editor, at.path);
|
|
13833
13905
|
if (existingEntry && isSpan({
|
|
13834
13906
|
schema: editor.schema
|
|
13835
13907
|
}, firstChild))
|
|
@@ -13863,7 +13935,11 @@ const insertChildOperationImplementation = ({
|
|
|
13863
13935
|
} = snapshot, focus = operation.editor.selection?.focus;
|
|
13864
13936
|
if (!focus)
|
|
13865
13937
|
throw new Error("Unable to insert child without a focus");
|
|
13866
|
-
const focusBlockEntry =
|
|
13938
|
+
const focusBlockEntry = getParent(operation.editor, focus.path, {
|
|
13939
|
+
match: (node) => isTextBlock({
|
|
13940
|
+
schema: operation.editor.schema
|
|
13941
|
+
}, node)
|
|
13942
|
+
});
|
|
13867
13943
|
if (!focusBlockEntry)
|
|
13868
13944
|
throw new Error("Unable to insert child without a focus block");
|
|
13869
13945
|
const focusBlock = focusBlockEntry.node;
|
|
@@ -13891,7 +13967,9 @@ const insertChildOperationImplementation = ({
|
|
|
13891
13967
|
}, focusSpanEntry.node) && focusSpanEntry.node)
|
|
13892
13968
|
applyInsertNodeAtPoint(operation.editor, span, focus);
|
|
13893
13969
|
else {
|
|
13894
|
-
const nextSibling = getSibling(operation.editor, focusChildPath,
|
|
13970
|
+
const nextSibling = getSibling(operation.editor, focusChildPath, {
|
|
13971
|
+
direction: "next"
|
|
13972
|
+
});
|
|
13895
13973
|
nextSibling ? applyInsertNodeAtPath(operation.editor, span, nextSibling.path) : operation.editor.apply({
|
|
13896
13974
|
type: "insert",
|
|
13897
13975
|
path: focusChildPath,
|
|
@@ -13925,7 +14003,9 @@ const insertChildOperationImplementation = ({
|
|
|
13925
14003
|
}, focusSpanEntry.node) && focusSpanEntry.node)
|
|
13926
14004
|
applyInsertNodeAtPoint(operation.editor, inlineNode, focus);
|
|
13927
14005
|
else {
|
|
13928
|
-
const nextSibling = getSibling(operation.editor, focusChildPath,
|
|
14006
|
+
const nextSibling = getSibling(operation.editor, focusChildPath, {
|
|
14007
|
+
direction: "next"
|
|
14008
|
+
});
|
|
13929
14009
|
nextSibling ? applyInsertNodeAtPath(operation.editor, inlineNode, nextSibling.path) : operation.editor.apply({
|
|
13930
14010
|
type: "insert",
|
|
13931
14011
|
path: focusChildPath,
|
|
@@ -13965,12 +14045,12 @@ const insertChildOperationImplementation = ({
|
|
|
13965
14045
|
if (!nodeEntry)
|
|
13966
14046
|
return;
|
|
13967
14047
|
const node = nodeEntry.node;
|
|
13968
|
-
if (
|
|
13969
|
-
|
|
13970
|
-
|
|
13971
|
-
|
|
14048
|
+
if (isLeafObject(editor, node, nodeEntry.path)) {
|
|
14049
|
+
const nextSibling = getSibling(editor, nodeEntry.path, {
|
|
14050
|
+
direction: "next"
|
|
14051
|
+
});
|
|
13972
14052
|
if (nextSibling)
|
|
13973
|
-
if (
|
|
14053
|
+
if (getSpan(editor, nextSibling.path))
|
|
13974
14054
|
path2 = nextSibling.path, offset = 0, applySelect(editor, {
|
|
13975
14055
|
path: path2,
|
|
13976
14056
|
offset
|
|
@@ -14255,7 +14335,9 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
14255
14335
|
}, focusTextBlock = getFocusTextBlock(adjustedSnapshot);
|
|
14256
14336
|
if (!focusTextBlock)
|
|
14257
14337
|
return !1;
|
|
14258
|
-
const previousSibling = getSibling(adjustedSnapshot, focusTextBlock.path,
|
|
14338
|
+
const previousSibling = getSibling(adjustedSnapshot, focusTextBlock.path, {
|
|
14339
|
+
direction: "previous"
|
|
14340
|
+
});
|
|
14259
14341
|
if (!previousSibling || !isAtTheStartOfBlock(focusTextBlock)(adjustedSnapshot) || !isTextBlock(snapshot.context, previousSibling.node))
|
|
14260
14342
|
return !1;
|
|
14261
14343
|
const previousBlock = {
|
|
@@ -14320,7 +14402,9 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
14320
14402
|
}, focusTextBlock = getFocusTextBlock(adjustedSnapshot);
|
|
14321
14403
|
if (!focusTextBlock)
|
|
14322
14404
|
return !1;
|
|
14323
|
-
const nextSibling = getSibling(adjustedSnapshot, focusTextBlock.path,
|
|
14405
|
+
const nextSibling = getSibling(adjustedSnapshot, focusTextBlock.path, {
|
|
14406
|
+
direction: "next"
|
|
14407
|
+
});
|
|
14324
14408
|
if (!nextSibling || !isEmptyTextBlock(snapshot.context, focusTextBlock.node) || !isTextBlock(snapshot.context, nextSibling.node))
|
|
14325
14409
|
return !1;
|
|
14326
14410
|
const nextBlockStartPoint = getBlockStartPoint({
|
|
@@ -14368,7 +14452,9 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
14368
14452
|
}, focusTextBlock = getFocusTextBlock(adjustedSnapshot);
|
|
14369
14453
|
if (!focusTextBlock)
|
|
14370
14454
|
return !1;
|
|
14371
|
-
const nextSibling = getSibling(adjustedSnapshot, focusTextBlock.path,
|
|
14455
|
+
const nextSibling = getSibling(adjustedSnapshot, focusTextBlock.path, {
|
|
14456
|
+
direction: "next"
|
|
14457
|
+
});
|
|
14372
14458
|
return !nextSibling || !isAtTheEndOfBlock(focusTextBlock)(adjustedSnapshot) || !isTextBlockNode(snapshot.context, nextSibling.node) ? !1 : {
|
|
14373
14459
|
nextBlock: {
|
|
14374
14460
|
node: nextSibling.node,
|
|
@@ -15366,7 +15452,9 @@ const abstractInsertBehaviors = [
|
|
|
15366
15452
|
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
15367
15453
|
if (!focusTextBlock)
|
|
15368
15454
|
return !1;
|
|
15369
|
-
const previousSibling = getSibling(snapshot, focusTextBlock.path,
|
|
15455
|
+
const previousSibling = getSibling(snapshot, focusTextBlock.path, {
|
|
15456
|
+
direction: "previous"
|
|
15457
|
+
});
|
|
15370
15458
|
if (!previousSibling)
|
|
15371
15459
|
return !1;
|
|
15372
15460
|
const previousBlock = getBlock(snapshot, previousSibling.path);
|
|
@@ -15487,7 +15575,9 @@ const abstractInsertBehaviors = [
|
|
|
15487
15575
|
snapshot,
|
|
15488
15576
|
event
|
|
15489
15577
|
}) => {
|
|
15490
|
-
const previousSibling = getSibling(snapshot, event.at,
|
|
15578
|
+
const previousSibling = getSibling(snapshot, event.at, {
|
|
15579
|
+
direction: "previous"
|
|
15580
|
+
});
|
|
15491
15581
|
return previousSibling ? {
|
|
15492
15582
|
previousSibling,
|
|
15493
15583
|
savedSelection: snapshot.context.selection
|
|
@@ -15515,7 +15605,9 @@ const abstractInsertBehaviors = [
|
|
|
15515
15605
|
snapshot,
|
|
15516
15606
|
event
|
|
15517
15607
|
}) => {
|
|
15518
|
-
const nextSibling = getSibling(snapshot, event.at,
|
|
15608
|
+
const nextSibling = getSibling(snapshot, event.at, {
|
|
15609
|
+
direction: "next"
|
|
15610
|
+
});
|
|
15519
15611
|
return nextSibling ? {
|
|
15520
15612
|
nextSibling,
|
|
15521
15613
|
savedSelection: snapshot.context.selection
|
|
@@ -15587,7 +15679,9 @@ const abstractInsertBehaviors = [
|
|
|
15587
15679
|
const focusBlockPath = getFocusBlock(snapshot)?.path;
|
|
15588
15680
|
if (!focusBlockPath)
|
|
15589
15681
|
return !1;
|
|
15590
|
-
const previousSibling = getSibling(snapshot, focusBlockPath,
|
|
15682
|
+
const previousSibling = getSibling(snapshot, focusBlockPath, {
|
|
15683
|
+
direction: "previous"
|
|
15684
|
+
});
|
|
15591
15685
|
return previousSibling ? {
|
|
15592
15686
|
previousBlock: previousSibling
|
|
15593
15687
|
} : !1;
|
|
@@ -15609,7 +15703,9 @@ const abstractInsertBehaviors = [
|
|
|
15609
15703
|
const focusBlockPath = getFocusBlock(snapshot)?.path;
|
|
15610
15704
|
if (!focusBlockPath)
|
|
15611
15705
|
return !1;
|
|
15612
|
-
const nextSibling = getSibling(snapshot, focusBlockPath,
|
|
15706
|
+
const nextSibling = getSibling(snapshot, focusBlockPath, {
|
|
15707
|
+
direction: "next"
|
|
15708
|
+
});
|
|
15613
15709
|
return nextSibling ? {
|
|
15614
15710
|
nextBlock: nextSibling
|
|
15615
15711
|
} : !1;
|
|
@@ -15721,7 +15817,15 @@ const abstractInsertBehaviors = [
|
|
|
15721
15817
|
const startPoint = getSelectionStartPoint$1(selection), endPoint = getSelectionEndPoint$1(selection);
|
|
15722
15818
|
if (!startPoint || !endPoint)
|
|
15723
15819
|
return !1;
|
|
15724
|
-
const startBlock =
|
|
15820
|
+
const startBlock = getParent(snapshot, startPoint.path, {
|
|
15821
|
+
match: (node) => isTextBlock({
|
|
15822
|
+
schema: snapshot.context.schema
|
|
15823
|
+
}, node)
|
|
15824
|
+
}), endBlock = getParent(snapshot, endPoint.path, {
|
|
15825
|
+
match: (node) => isTextBlock({
|
|
15826
|
+
schema: snapshot.context.schema
|
|
15827
|
+
}, node)
|
|
15828
|
+
});
|
|
15725
15829
|
if (!startBlock || !endBlock)
|
|
15726
15830
|
return !1;
|
|
15727
15831
|
const startBlockStartPoint = getBlockStartPoint({
|