@portabletext/editor 7.9.0 → 7.10.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/behavior.types.action.d.ts +110 -274
- package/lib/_chunks-dts/behavior.types.action.d.ts.map +1 -1
- package/lib/_chunks-dts/block-offset.d.ts +10 -0
- package/lib/_chunks-dts/block-offset.d.ts.map +1 -0
- package/lib/_chunks-dts/editor-selector.d.ts +33 -0
- package/lib/_chunks-dts/editor-selector.d.ts.map +1 -0
- package/lib/_chunks-dts/editor.d.ts +99 -0
- package/lib/_chunks-dts/editor.d.ts.map +1 -0
- package/lib/_chunks-es/{get-first-child.js → get-container.js} +10 -1
- package/lib/_chunks-es/get-container.js.map +1 -0
- package/lib/_chunks-es/get-path-sub-schema.js +38 -6
- package/lib/_chunks-es/get-path-sub-schema.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +3 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/{util.is-empty-text-block.js → util.is-equal-selections.js} +7 -2
- package/lib/_chunks-es/util.is-equal-selections.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +1 -8
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/index.d.ts +67 -2
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +333 -169
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +2 -1
- package/lib/plugins/index.d.ts.map +1 -1
- package/lib/selectors/index.d.ts +3 -1
- package/lib/selectors/index.d.ts.map +1 -1
- package/lib/selectors/index.js +4 -2
- package/lib/selectors/index.js.map +1 -1
- package/lib/traversal/index.d.ts +11 -2
- package/lib/traversal/index.d.ts.map +1 -1
- package/lib/traversal/index.js +3 -2
- package/lib/utils/index.d.ts +3 -3
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +3 -6
- package/lib/utils/index.js.map +1 -1
- package/package.json +20 -20
- package/lib/_chunks-es/get-first-child.js.map +0 -1
- package/lib/_chunks-es/util.is-empty-text-block.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -3,22 +3,23 @@ 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
5
|
import { serializePath, isKeyedSegment, getNode, getParent, parentPath, getChildren, getNodeChildren } from "./_chunks-es/get-parent.js";
|
|
6
|
-
import { isPath, getLeaf, isRange, isPoint, isObject, isLeafObject, getAncestor, pathContains, getSpan, isBeforePoint, getText, rangeIntersects, getTextBlock, getUnionSchema, getFirstChild } from "./_chunks-es/get-
|
|
7
|
-
import { rangeEdges, isTextBlockNode, isBackwardRange, hasNode, getNodes, isAncestorPath, isEditableContainer, getSibling, isInline, isObject as isObject$1, isSpanNode, isBlock, getEnclosingBlock, getAncestors, getPathSubSchema, getBlock, resolveContainerAt,
|
|
6
|
+
import { isPath, getLeaf, isRange, isPoint, isObject, isLeafObject, getAncestor, pathContains, getSpan, isBeforePoint, getText, rangeIntersects, getTextBlock, getUnionSchema, getFirstChild, getContainer } from "./_chunks-es/get-container.js";
|
|
7
|
+
import { rangeEdges, isTextBlockNode, isBackwardRange, hasNode, getNodes, isAncestorPath, isEditableContainer, getSibling, isInline, isObject as isObject$1, isSpanNode, isBlock, getEnclosingBlock, getAncestors, getPathSubSchema, getBlock, resolveContainerAt, resolveChildEntryIndex, getEnclosingContainer, comparePoints$1 as comparePoints, comparePaths, isAfterPoint } from "./_chunks-es/get-path-sub-schema.js";
|
|
8
8
|
import { isSpan, isTextBlock, getSubSchema, compileSchema } from "@portabletext/schema";
|
|
9
9
|
import { defineSchema } from "@portabletext/schema";
|
|
10
10
|
import scrollIntoView from "scroll-into-view-if-needed";
|
|
11
11
|
import { createKeyboardShortcut, undo, redo, code, underline, italic as italic$1, bold as bold$1 } from "@portabletext/keyboard-shortcuts";
|
|
12
|
-
import { rangesOverlap, getFocusInlineObject, getFocusTextBlock, getFocusSpan, getFragment, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection,
|
|
12
|
+
import { rangesOverlap, getFocusInlineObject, isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan, getFragment, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection, getFocusBlock, getSelectedBlocks, isSelectingEntireBlocks, getSelectedValue, isActiveAnnotation, getActiveAnnotationsMarks, getActiveDecorators, getCaretWordSelection, getSelectionStartChild, getSelectionStartPoint, getSelectionEndChild, getSelectionEndPoint, getPreviousSpan, getNextSpan, getFocusBlockObject, getLastBlock, getFirstBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getRootAcceptedTypes, getMarkState, getFocusListBlock, getNextBlock, getPreviousBlock, getSelectedTextBlocks, isActiveDecorator, getFocusChild, getActiveAnnotations, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
|
|
13
13
|
import { isEqualSelectionPoints, blockOffsetToSpanSelectionPoint, getBlockKeyFromSelectionPoint, getBlockEndPoint, getBlockStartPoint, isSelectionCollapsed, defaultKeyGenerator, parseBlocks, parseBlock, isListBlock, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject } from "./_chunks-es/util.slice-blocks.js";
|
|
14
14
|
import rawDebug from "debug";
|
|
15
|
-
import { isEmptyTextBlock, getTextBlockText } from "./_chunks-es/util.is-
|
|
15
|
+
import { isEmptyTextBlock, isEqualSelections, getTextBlockText } from "./_chunks-es/util.is-equal-selections.js";
|
|
16
16
|
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
17
17
|
import { setup, fromCallback, assign, and, assertEvent, enqueueActions, emit, not, raise as raise$1, createActor } from "xstate";
|
|
18
18
|
import { htmlToPortableText } from "@portabletext/html";
|
|
19
19
|
import { toHTML } from "@portabletext/to-html";
|
|
20
20
|
import { markdownToPortableText, portableTextToMarkdown } from "@portabletext/markdown";
|
|
21
21
|
import { applyAll, unset, set, insert, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
22
|
+
import "xstate/guards";
|
|
22
23
|
import { EditorContext as EditorContext$1 } from "./_chunks-es/use-editor.js";
|
|
23
24
|
import { useEditor } from "./_chunks-es/use-editor.js";
|
|
24
25
|
function getDomNode(editor, path2) {
|
|
@@ -1605,7 +1606,8 @@ function transformTextDiff(textDiff, op) {
|
|
|
1605
1606
|
id
|
|
1606
1607
|
} : null;
|
|
1607
1608
|
}
|
|
1608
|
-
const RESOLVE_DELAY = 25, FLUSH_DELAY = 200,
|
|
1609
|
+
const RESOLVE_DELAY = 25, FLUSH_DELAY = 200, debug$1 = (..._) => {
|
|
1610
|
+
}, isDataTransfer = (value) => value?.constructor.name === "DataTransfer";
|
|
1609
1611
|
function createAndroidInputManager({
|
|
1610
1612
|
editor,
|
|
1611
1613
|
editorActor,
|
|
@@ -1642,6 +1644,7 @@ function createAndroidInputManager({
|
|
|
1642
1644
|
const selectionRef = editor.snapshot.context.selection && rangeRef(editor, editor.snapshot.context.selection, {
|
|
1643
1645
|
affinity: "forward"
|
|
1644
1646
|
});
|
|
1647
|
+
debug$1("flush", editor.pendingAction, editor.pendingDiffs);
|
|
1645
1648
|
let scheduleSelectionChange = hasPendingDiffs(), diff2;
|
|
1646
1649
|
for (; diff2 = editor.pendingDiffs?.[0]; ) {
|
|
1647
1650
|
const range2 = targetRange(diff2);
|
|
@@ -2874,7 +2877,13 @@ const useChildren = (props) => {
|
|
|
2874
2877
|
});
|
|
2875
2878
|
return childContainer && childContainer !== parentContainer ? /* @__PURE__ */ jsx(ParentContainerContext, { value: childContainer, children: /* @__PURE__ */ jsx(NewPipelineContext.Provider, { value: !0, children: elements }) }) : /* @__PURE__ */ jsx(Fragment, { children: elements });
|
|
2876
2879
|
}, EngineSelectorContext = createContext({}), refEquality = (a, b) => a === b;
|
|
2877
|
-
function
|
|
2880
|
+
function useRegistrationsSelector(selector, equalityFn = refEquality) {
|
|
2881
|
+
return useChannelSelector(selector, equalityFn, "registrations");
|
|
2882
|
+
}
|
|
2883
|
+
function useListIndexSelector(selector, equalityFn = refEquality) {
|
|
2884
|
+
return useChannelSelector(selector, equalityFn, "listIndex");
|
|
2885
|
+
}
|
|
2886
|
+
function useChannelSelector(selector, equalityFn, channel) {
|
|
2878
2887
|
const context = useContext(EngineSelectorContext);
|
|
2879
2888
|
if (!context)
|
|
2880
2889
|
throw new Error("The `useEngineSelector` hook must be used inside the <Engine> component's context.");
|
|
@@ -2882,36 +2891,32 @@ function useEngineSelector(selector, equalityFn = refEquality) {
|
|
|
2882
2891
|
addEventListener
|
|
2883
2892
|
} = context, editor = useEngineStatic(), genericSelector = useCallback(() => selector(editor), [editor, selector]), [selectedState, update] = useGenericSelector(genericSelector, equalityFn);
|
|
2884
2893
|
return useIsomorphicLayoutEffect(() => {
|
|
2885
|
-
const unsubscribe = addEventListener(update);
|
|
2894
|
+
const unsubscribe = addEventListener(update, channel);
|
|
2886
2895
|
return update(), unsubscribe;
|
|
2887
|
-
}, [addEventListener, update]), selectedState;
|
|
2896
|
+
}, [addEventListener, update, channel]), selectedState;
|
|
2888
2897
|
}
|
|
2889
2898
|
function useSelectorContext() {
|
|
2890
|
-
const eventListeners = useRef(/* @__PURE__ */ new Set()),
|
|
2899
|
+
const eventListeners = useRef(/* @__PURE__ */ new Set()), registrationListeners = useRef(/* @__PURE__ */ new Set()), listIndexListeners = useRef(/* @__PURE__ */ new Set()), onChange = useCallback((changed) => {
|
|
2891
2900
|
eventListeners.current.forEach((listener) => {
|
|
2892
2901
|
listener();
|
|
2893
|
-
})
|
|
2894
|
-
}, []), flushDeferred = useCallback(() => {
|
|
2895
|
-
deferredEventListeners.current.forEach((listener) => {
|
|
2902
|
+
}), changed.registrations && registrationListeners.current.forEach((listener) => {
|
|
2896
2903
|
listener();
|
|
2897
|
-
}),
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
}
|
|
2904
|
+
}), changed.listIndex && listIndexListeners.current.forEach((listener) => {
|
|
2905
|
+
listener();
|
|
2906
|
+
});
|
|
2907
|
+
}, []), addEventListener = useCallback((callbackProp, channel) => {
|
|
2908
|
+
const listeners = channel === "registrations" ? registrationListeners.current : channel === "listIndex" ? listIndexListeners.current : eventListeners.current;
|
|
2909
|
+
return listeners.add(callbackProp), () => {
|
|
2910
|
+
listeners.delete(callbackProp);
|
|
2911
|
+
};
|
|
2912
|
+
}, []);
|
|
2901
2913
|
return {
|
|
2902
2914
|
selectorContext: useMemo(() => ({
|
|
2903
|
-
addEventListener
|
|
2904
|
-
|
|
2905
|
-
}), [addEventListener, flushDeferred]),
|
|
2915
|
+
addEventListener
|
|
2916
|
+
}), [addEventListener]),
|
|
2906
2917
|
onChange
|
|
2907
2918
|
};
|
|
2908
2919
|
}
|
|
2909
|
-
function useFlushDeferredSelectorsOnRender() {
|
|
2910
|
-
const {
|
|
2911
|
-
flushDeferred
|
|
2912
|
-
} = useContext(EngineSelectorContext);
|
|
2913
|
-
useIsomorphicLayoutEffect(flushDeferred);
|
|
2914
|
-
}
|
|
2915
2920
|
const useEngine = () => {
|
|
2916
2921
|
const {
|
|
2917
2922
|
addEventListener
|
|
@@ -3094,10 +3099,8 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3094
3099
|
const domSelection = getSelection(root2);
|
|
3095
3100
|
if (activeElement === el2)
|
|
3096
3101
|
state.latestElement = activeElement, editor.focused = !0;
|
|
3097
|
-
else
|
|
3098
|
-
editor.focused = !1;
|
|
3102
|
+
else if (editor.focused = !1, !readOnly)
|
|
3099
3103
|
return;
|
|
3100
|
-
}
|
|
3101
3104
|
if (!domSelection)
|
|
3102
3105
|
return deselect(editor);
|
|
3103
3106
|
const {
|
|
@@ -3109,7 +3112,16 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3109
3112
|
exactMatch: !1,
|
|
3110
3113
|
suppressThrow: !0
|
|
3111
3114
|
});
|
|
3112
|
-
|
|
3115
|
+
if (range2)
|
|
3116
|
+
if (!editor.composing && !androidInputManager?.hasPendingChanges() && !androidInputManager?.isFlushing()) {
|
|
3117
|
+
if (editor.select(range2), domSelection.isCollapsed && anchorNode && anchorNode.nodeType === Node.ELEMENT_NODE)
|
|
3118
|
+
try {
|
|
3119
|
+
const canonicalRange = DOMEditor.toDOMRange(editor, range2);
|
|
3120
|
+
domSelection.setBaseAndExtent(canonicalRange.startContainer, canonicalRange.startOffset, canonicalRange.startContainer, canonicalRange.startOffset);
|
|
3121
|
+
} catch {
|
|
3122
|
+
}
|
|
3123
|
+
} else
|
|
3124
|
+
androidInputManager?.handleUserSelect(range2);
|
|
3113
3125
|
}
|
|
3114
3126
|
readOnly && (!anchorNodeSelectable || !focusNodeInEditor) && deselect(editor);
|
|
3115
3127
|
}
|
|
@@ -3470,7 +3482,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3470
3482
|
};
|
|
3471
3483
|
}, [scheduleOnDOMSelectionChange]);
|
|
3472
3484
|
const decorations = decorate([editor, []]), decorateContext = useDecorateContext(decorate);
|
|
3473
|
-
return
|
|
3485
|
+
return /* @__PURE__ */ jsx(ReadOnlyContext.Provider, { value: readOnly, children: /* @__PURE__ */ jsx(DecorateContext.Provider, { value: decorateContext, children: /* @__PURE__ */ jsx(RestoreDOM, { node: ref, receivedUserInput, children: /* @__PURE__ */ jsx(
|
|
3474
3486
|
"div",
|
|
3475
3487
|
{
|
|
3476
3488
|
role: readOnly ? void 0 : "textbox",
|
|
@@ -4046,6 +4058,33 @@ const debug = {
|
|
|
4046
4058
|
syncValue: createDebugger("sync:value"),
|
|
4047
4059
|
syncPatch: createDebugger("sync:patch")
|
|
4048
4060
|
};
|
|
4061
|
+
function getPointAtCoordinates(editorEngine, coordinates) {
|
|
4062
|
+
let domRange;
|
|
4063
|
+
try {
|
|
4064
|
+
const window2 = DOMEditor.getWindow(editorEngine);
|
|
4065
|
+
if (window2.document.caretPositionFromPoint !== void 0) {
|
|
4066
|
+
const position = window2.document.caretPositionFromPoint(coordinates.x, coordinates.y);
|
|
4067
|
+
if (position)
|
|
4068
|
+
try {
|
|
4069
|
+
domRange = window2.document.createRange(), domRange.setStart(position.offsetNode, position.offset), domRange.setEnd(position.offsetNode, position.offset);
|
|
4070
|
+
} catch {
|
|
4071
|
+
}
|
|
4072
|
+
} else window2.document.caretRangeFromPoint !== void 0 && (domRange = window2.document.caretRangeFromPoint(coordinates.x, coordinates.y) ?? void 0);
|
|
4073
|
+
} catch {
|
|
4074
|
+
return null;
|
|
4075
|
+
}
|
|
4076
|
+
if (!domRange)
|
|
4077
|
+
return null;
|
|
4078
|
+
try {
|
|
4079
|
+
return DOMEditor.toEditorSelection(editorEngine, domRange, {
|
|
4080
|
+
exactMatch: !1,
|
|
4081
|
+
// It can still throw even with this option set to true
|
|
4082
|
+
suppressThrow: !1
|
|
4083
|
+
})?.focus ?? null;
|
|
4084
|
+
} catch {
|
|
4085
|
+
return null;
|
|
4086
|
+
}
|
|
4087
|
+
}
|
|
4049
4088
|
function isDragEvent(event) {
|
|
4050
4089
|
return "dataTransfer" in event;
|
|
4051
4090
|
}
|
|
@@ -4217,31 +4256,14 @@ function getEventPositionBlock({
|
|
|
4217
4256
|
function getSelectionFromEvent(editor, event) {
|
|
4218
4257
|
if (!event.target || !isDOMNode(event.target))
|
|
4219
4258
|
return;
|
|
4220
|
-
const
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
}
|
|
4229
|
-
} else if (window2.document.caretRangeFromPoint !== void 0)
|
|
4230
|
-
domRange = window2.document.caretRangeFromPoint(event.clientX, event.clientY) ?? void 0;
|
|
4231
|
-
else {
|
|
4232
|
-
console.warn("Neither caretPositionFromPoint nor caretRangeFromPoint is supported");
|
|
4233
|
-
return;
|
|
4234
|
-
}
|
|
4235
|
-
if (domRange)
|
|
4236
|
-
try {
|
|
4237
|
-
return DOMEditor.toEditorSelection(editor, domRange, {
|
|
4238
|
-
exactMatch: !1,
|
|
4239
|
-
// It can still throw even with this option set to true
|
|
4240
|
-
suppressThrow: !1
|
|
4241
|
-
});
|
|
4242
|
-
} catch {
|
|
4243
|
-
return;
|
|
4244
|
-
}
|
|
4259
|
+
const point2 = getPointAtCoordinates(editor, {
|
|
4260
|
+
x: event.clientX,
|
|
4261
|
+
y: event.clientY
|
|
4262
|
+
});
|
|
4263
|
+
return point2 ? {
|
|
4264
|
+
anchor: point2,
|
|
4265
|
+
focus: point2
|
|
4266
|
+
} : void 0;
|
|
4245
4267
|
}
|
|
4246
4268
|
function isEventContainer(editorEngine, eventNode, eventPath) {
|
|
4247
4269
|
return isEditor(eventNode) ? !0 : isEditableContainer(editorEngine.snapshot, eventNode, eventPath);
|
|
@@ -4260,6 +4282,7 @@ function getDragSelection({
|
|
|
4260
4282
|
}))
|
|
4261
4283
|
return dragSelection;
|
|
4262
4284
|
const draggingCollapsedSelection = isSelectionCollapsed$1({
|
|
4285
|
+
...snapshot,
|
|
4263
4286
|
context: {
|
|
4264
4287
|
...snapshot.context,
|
|
4265
4288
|
selection: eventSelection
|
|
@@ -5518,7 +5541,7 @@ function RenderTextBlock(props) {
|
|
|
5518
5541
|
const serializedPath = t2, selected = useIsSelectedContainer(serializedPath), focused = useIsFocusedContainer(serializedPath), dropPosition = useElementDropPosition(props.path);
|
|
5519
5542
|
let t3;
|
|
5520
5543
|
$[7] !== serializedPath ? (t3 = (editor) => getListIndexMap(editor).get(serializedPath), $[7] = serializedPath, $[8] = t3) : t3 = $[8];
|
|
5521
|
-
const listIndex =
|
|
5544
|
+
const listIndex = useListIndexSelector(t3), subSchema = useBlockSubSchema(props.path);
|
|
5522
5545
|
let children = props.children;
|
|
5523
5546
|
if (props.legacy.renderStyle && props.textBlock.style) {
|
|
5524
5547
|
let t42;
|
|
@@ -5684,7 +5707,7 @@ function RenderElement(props) {
|
|
|
5684
5707
|
const inlinePositionalOverride = t1;
|
|
5685
5708
|
let t2;
|
|
5686
5709
|
$[6] !== type ? (t2 = (engine) => [engine.containers.get(type), engine.blockObjects.get(type), engine.blockObjects.get("*"), engine.inlineObjects.get(type), engine.inlineObjects.get("*"), engine.textBlocks.get(type), engine.textBlocks.get("*")], $[6] = type, $[7] = t2) : t2 = $[7];
|
|
5687
|
-
const [globalContainerConfig, globalBlockObjectConfig, globalBlockObjectCatchAll, globalInlineObjectConfig, globalInlineObjectCatchAll, textBlockConfig, textBlockCatchAll] =
|
|
5710
|
+
const [globalContainerConfig, globalBlockObjectConfig, globalBlockObjectCatchAll, globalInlineObjectConfig, globalInlineObjectCatchAll, textBlockConfig, textBlockCatchAll] = useRegistrationsSelector(t2, tupleRefEqual);
|
|
5688
5711
|
let t3;
|
|
5689
5712
|
bb0: {
|
|
5690
5713
|
if (blockPositionalOverride && "container" in blockPositionalOverride) {
|
|
@@ -5876,7 +5899,7 @@ function useSpanConfig(node, _path) {
|
|
|
5876
5899
|
const positional = t0;
|
|
5877
5900
|
let t1;
|
|
5878
5901
|
$[3] !== node._type ? (t1 = (engine) => [engine.spans.get(node._type), engine.spans.get("*")], $[3] = node._type, $[4] = t1) : t1 = $[4];
|
|
5879
|
-
const [globalSpan, globalSpanCatchAll] =
|
|
5902
|
+
const [globalSpan, globalSpanCatchAll] = useRegistrationsSelector(t1, tupleRefEqual);
|
|
5880
5903
|
return positional && "span" in positional ? positional.span.render === void 0 ? globalSpan ?? globalSpanCatchAll : positional : globalSpan ?? globalSpanCatchAll;
|
|
5881
5904
|
}
|
|
5882
5905
|
function RenderSpan(props) {
|
|
@@ -5893,7 +5916,7 @@ function RenderSpan(props) {
|
|
|
5893
5916
|
}, parent) ? parent : void 0;
|
|
5894
5917
|
let t2;
|
|
5895
5918
|
$[3] !== block?.children || $[4] !== props.leaf._key ? (t2 = block?.children.find((_child) => _child._key === props.leaf._key), $[3] = block?.children, $[4] = props.leaf._key, $[5] = t2) : t2 = $[5];
|
|
5896
|
-
const child = t2, subSchema = useBlockSubSchema(props.path), spanConfig = useSpanConfig(child ?? props.leaf), isInNewPipeline = useContext(NewPipelineContext);
|
|
5919
|
+
const child = t2, subSchema = useBlockSubSchema(props.path), spanConfig = useSpanConfig(child ?? props.leaf, props.path), isInNewPipeline = useContext(NewPipelineContext);
|
|
5897
5920
|
let t3;
|
|
5898
5921
|
$[6] !== props.path ? (t3 = serializePath(props.path), $[6] = props.path, $[7] = t3) : t3 = $[7];
|
|
5899
5922
|
const serializedPath = t3, focused = useIsFocusedLeaf(serializedPath), selected = useIsSelectedLeaf(serializedPath);
|
|
@@ -6135,15 +6158,19 @@ function validateSelection(editorEngine, editorElement) {
|
|
|
6135
6158
|
if (!root || editorElement !== root.activeElement)
|
|
6136
6159
|
return;
|
|
6137
6160
|
const domSelection = DOMEditor.getWindow(editorEngine).getSelection();
|
|
6138
|
-
if (!domSelection || domSelection.rangeCount === 0)
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6161
|
+
if (!(!domSelection || domSelection.rangeCount === 0))
|
|
6162
|
+
try {
|
|
6163
|
+
const domEditorSelection = DOMEditor.toEditorSelection(editorEngine, domSelection, {
|
|
6164
|
+
exactMatch: !1,
|
|
6165
|
+
suppressThrow: !0
|
|
6166
|
+
});
|
|
6167
|
+
if (domEditorSelection && isEqualSelections(domEditorSelection, editorEngine.snapshot.context.selection))
|
|
6168
|
+
return;
|
|
6169
|
+
const newDOMRange = DOMEditor.toDOMRange(editorEngine, editorEngine.snapshot.context.selection);
|
|
6170
|
+
debug.selection("DOM range out of sync, validating selection"), domSelection.removeAllRanges(), domSelection.addRange(newDOMRange);
|
|
6171
|
+
} catch {
|
|
6172
|
+
debug.selection("Could not resolve selection, skipping DOM sync this tick");
|
|
6173
|
+
}
|
|
6147
6174
|
}
|
|
6148
6175
|
const PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
6149
6176
|
const $ = c(179);
|
|
@@ -6742,7 +6769,11 @@ const Engine = (props) => {
|
|
|
6742
6769
|
selectorContext,
|
|
6743
6770
|
onChange: handleSelectorChange
|
|
6744
6771
|
} = useSelectorContext(), onContextChange = useCallback(() => {
|
|
6745
|
-
|
|
6772
|
+
const pending = editor.selectorChannelsPending, registrations = pending.registrations, listIndex = pending.listIndex;
|
|
6773
|
+
pending.registrations = !1, pending.listIndex = !1, handleSelectorChange({
|
|
6774
|
+
registrations,
|
|
6775
|
+
listIndex
|
|
6776
|
+
});
|
|
6746
6777
|
}, [editor, handleSelectorChange]);
|
|
6747
6778
|
return useEffect(() => (editor.onContextChange = onContextChange, () => {
|
|
6748
6779
|
editor.onContextChange = () => {
|
|
@@ -7686,6 +7717,87 @@ function transformRangeRef(ref, op, root) {
|
|
|
7686
7717
|
});
|
|
7687
7718
|
ref.current = path2, path2 == null && ref.unref();
|
|
7688
7719
|
}
|
|
7720
|
+
function splitNodePath(path2) {
|
|
7721
|
+
let nodePathEnd = path2.length;
|
|
7722
|
+
for (; nodePathEnd > 0 && typeof path2[nodePathEnd - 1] == "string"; )
|
|
7723
|
+
nodePathEnd--;
|
|
7724
|
+
return {
|
|
7725
|
+
nodePath: path2.slice(0, nodePathEnd),
|
|
7726
|
+
propertyPath: path2.slice(nodePathEnd)
|
|
7727
|
+
};
|
|
7728
|
+
}
|
|
7729
|
+
function findNearestSpans(snapshot, path2) {
|
|
7730
|
+
return {
|
|
7731
|
+
previousSpan: findPreviousSpan(snapshot, path2),
|
|
7732
|
+
nextSpan: findNextSpan(snapshot, path2)
|
|
7733
|
+
};
|
|
7734
|
+
}
|
|
7735
|
+
function findNextSpan(snapshot, path2) {
|
|
7736
|
+
const descendantSpan = firstSpanIn(snapshot, path2);
|
|
7737
|
+
if (descendantSpan)
|
|
7738
|
+
return descendantSpan;
|
|
7739
|
+
let currentPath = path2;
|
|
7740
|
+
for (; currentPath.length > 0; ) {
|
|
7741
|
+
const parentPath2 = nodeParentPath(currentPath), siblings = getChildren(snapshot, parentPath2), index = resolveChildEntryIndex(snapshot.blockIndexMap, siblings, currentPath);
|
|
7742
|
+
if (index !== -1)
|
|
7743
|
+
for (let siblingIndex = index + 1; siblingIndex < siblings.length; siblingIndex++) {
|
|
7744
|
+
const sibling = siblings[siblingIndex];
|
|
7745
|
+
if (isSpan({
|
|
7746
|
+
schema: snapshot.context.schema
|
|
7747
|
+
}, sibling.node))
|
|
7748
|
+
return {
|
|
7749
|
+
node: sibling.node,
|
|
7750
|
+
path: sibling.path
|
|
7751
|
+
};
|
|
7752
|
+
const siblingDescendantSpan = firstSpanIn(snapshot, sibling.path);
|
|
7753
|
+
if (siblingDescendantSpan)
|
|
7754
|
+
return siblingDescendantSpan;
|
|
7755
|
+
}
|
|
7756
|
+
currentPath = parentPath2;
|
|
7757
|
+
}
|
|
7758
|
+
}
|
|
7759
|
+
function findPreviousSpan(snapshot, path2) {
|
|
7760
|
+
let currentPath = path2;
|
|
7761
|
+
for (; currentPath.length > 0; ) {
|
|
7762
|
+
const parentPath2 = nodeParentPath(currentPath), siblings = getChildren(snapshot, parentPath2), index = resolveChildEntryIndex(snapshot.blockIndexMap, siblings, currentPath);
|
|
7763
|
+
if (index !== -1)
|
|
7764
|
+
for (let siblingIndex = index - 1; siblingIndex >= 0; siblingIndex--) {
|
|
7765
|
+
const sibling = siblings[siblingIndex], siblingDescendantSpan = lastSpanIn(snapshot, sibling.path);
|
|
7766
|
+
if (siblingDescendantSpan)
|
|
7767
|
+
return siblingDescendantSpan;
|
|
7768
|
+
if (isSpan({
|
|
7769
|
+
schema: snapshot.context.schema
|
|
7770
|
+
}, sibling.node))
|
|
7771
|
+
return {
|
|
7772
|
+
node: sibling.node,
|
|
7773
|
+
path: sibling.path
|
|
7774
|
+
};
|
|
7775
|
+
}
|
|
7776
|
+
currentPath = parentPath2;
|
|
7777
|
+
}
|
|
7778
|
+
}
|
|
7779
|
+
function firstSpanIn(snapshot, path2) {
|
|
7780
|
+
for (const entry of getNodes(snapshot, {
|
|
7781
|
+
at: path2,
|
|
7782
|
+
match: (node) => isSpan({
|
|
7783
|
+
schema: snapshot.context.schema
|
|
7784
|
+
}, node)
|
|
7785
|
+
}))
|
|
7786
|
+
return entry;
|
|
7787
|
+
}
|
|
7788
|
+
function lastSpanIn(snapshot, path2) {
|
|
7789
|
+
for (const entry of getNodes(snapshot, {
|
|
7790
|
+
at: path2,
|
|
7791
|
+
match: (node) => isSpan({
|
|
7792
|
+
schema: snapshot.context.schema
|
|
7793
|
+
}, node),
|
|
7794
|
+
reverse: !0
|
|
7795
|
+
}))
|
|
7796
|
+
return entry;
|
|
7797
|
+
}
|
|
7798
|
+
function nodeParentPath(path2) {
|
|
7799
|
+
return splitNodePath(path2.slice(0, -1)).nodePath;
|
|
7800
|
+
}
|
|
7689
7801
|
function getValue(root, path2) {
|
|
7690
7802
|
let current = root;
|
|
7691
7803
|
for (const segment of path2) {
|
|
@@ -7915,7 +8027,7 @@ function applyOperation(editor, op) {
|
|
|
7915
8027
|
const {
|
|
7916
8028
|
nodePath: setNodePath,
|
|
7917
8029
|
propertyPath: setPropertyPath
|
|
7918
|
-
} =
|
|
8030
|
+
} = splitNodePath(path2);
|
|
7919
8031
|
if (setNodePath.length === 0)
|
|
7920
8032
|
break;
|
|
7921
8033
|
if (setPropertyPath.length === 0) {
|
|
@@ -7970,26 +8082,16 @@ function applyOperation(editor, op) {
|
|
|
7970
8082
|
if (selection != null && result != null)
|
|
7971
8083
|
selection[key] = result;
|
|
7972
8084
|
else {
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
} of getNodes(editor.snapshot))
|
|
7978
|
-
if (isSpan({
|
|
7979
|
-
schema: editor.snapshot.context.schema
|
|
7980
|
-
}, n) && !pathEquals(p, path2))
|
|
7981
|
-
if (comparePaths(p, path2, editor.snapshot.context) === -1)
|
|
7982
|
-
prev = [n, p];
|
|
7983
|
-
else {
|
|
7984
|
-
next = [n, p];
|
|
7985
|
-
break;
|
|
7986
|
-
}
|
|
8085
|
+
const {
|
|
8086
|
+
previousSpan,
|
|
8087
|
+
nextSpan
|
|
8088
|
+
} = findNearestSpans(editor.snapshot, path2);
|
|
7987
8089
|
let preferNext = !1;
|
|
7988
|
-
|
|
7989
|
-
path:
|
|
7990
|
-
offset:
|
|
7991
|
-
} :
|
|
7992
|
-
path:
|
|
8090
|
+
previousSpan && nextSpan && (isSiblingPath(previousSpan.path, path2) ? preferNext = !1 : preferNext = commonPath(previousSpan.path, path2).length < commonPath(nextSpan.path, path2).length), previousSpan && !preferNext ? selection[key] = {
|
|
8091
|
+
path: previousSpan.path,
|
|
8092
|
+
offset: previousSpan.node.text.length
|
|
8093
|
+
} : nextSpan ? selection[key] = {
|
|
8094
|
+
path: nextSpan.path,
|
|
7993
8095
|
offset: 0
|
|
7994
8096
|
} : selection = null;
|
|
7995
8097
|
}
|
|
@@ -8026,7 +8128,7 @@ function applyOperation(editor, op) {
|
|
|
8026
8128
|
const {
|
|
8027
8129
|
nodePath: unsetNodePath,
|
|
8028
8130
|
propertyPath: unsetPropertyPath
|
|
8029
|
-
} =
|
|
8131
|
+
} = splitNodePath(path2);
|
|
8030
8132
|
if (unsetPropertyPath.length === 0 || unsetNodePath.length === 0)
|
|
8031
8133
|
break;
|
|
8032
8134
|
if (!op.inverse && !editor.isProcessingRemoteChanges) {
|
|
@@ -8133,26 +8235,6 @@ function resolveBlockIndex(editor, segment) {
|
|
|
8133
8235
|
const value = editor.snapshot.context.value, index = editor.blockIndexMap.get(serializePath([segment]));
|
|
8134
8236
|
return index !== void 0 && value[index]?._key === segment._key ? index : value.findIndex((block) => block._key === segment._key);
|
|
8135
8237
|
}
|
|
8136
|
-
function splitNodeAndPropertyPath(path2) {
|
|
8137
|
-
let lastKeyedOrNumericIndex = -1;
|
|
8138
|
-
for (let i = path2.length - 1; i >= 0; i--) {
|
|
8139
|
-
const segment = path2[i];
|
|
8140
|
-
if (isKeyedSegment(segment) || typeof segment == "number") {
|
|
8141
|
-
lastKeyedOrNumericIndex = i;
|
|
8142
|
-
break;
|
|
8143
|
-
}
|
|
8144
|
-
}
|
|
8145
|
-
if (lastKeyedOrNumericIndex === -1)
|
|
8146
|
-
return {
|
|
8147
|
-
nodePath: [],
|
|
8148
|
-
propertyPath: path2.filter((segment) => typeof segment == "string")
|
|
8149
|
-
};
|
|
8150
|
-
const nodePath = path2.slice(0, lastKeyedOrNumericIndex + 1), propertyPath = path2.slice(lastKeyedOrNumericIndex + 1).filter((segment) => typeof segment == "string");
|
|
8151
|
-
return {
|
|
8152
|
-
nodePath,
|
|
8153
|
-
propertyPath
|
|
8154
|
-
};
|
|
8155
|
-
}
|
|
8156
8238
|
function deepSet(node, propertyPath, value) {
|
|
8157
8239
|
if (propertyPath.length === 0)
|
|
8158
8240
|
return node;
|
|
@@ -10393,7 +10475,7 @@ function transformBlockIndexMap(map, op, beforeValue, afterValue, context) {
|
|
|
10393
10475
|
return;
|
|
10394
10476
|
}
|
|
10395
10477
|
if (typeof op.path[op.path.length - 1] == "string") {
|
|
10396
|
-
hasKeyedEntries(
|
|
10478
|
+
hasKeyedEntries(getValue(beforeValue, op.path)) && reconcileOwnerSubtree(map, context, beforeValue, afterValue, op.path);
|
|
10397
10479
|
return;
|
|
10398
10480
|
}
|
|
10399
10481
|
const removeIndex = childIndexFromMap(map, beforeValue, op.path);
|
|
@@ -10421,7 +10503,7 @@ function transformBlockIndexMap(map, op, beforeValue, afterValue, context) {
|
|
|
10421
10503
|
handleKeyChange(map, beforeValue, afterValue, op.path.slice(0, -1), context);
|
|
10422
10504
|
return;
|
|
10423
10505
|
}
|
|
10424
|
-
(op.value !== null && typeof op.value == "object" || hasKeyedEntries(
|
|
10506
|
+
(op.value !== null && typeof op.value == "object" || hasKeyedEntries(getValue(beforeValue, op.path))) && reconcileOwnerSubtree(map, context, beforeValue, afterValue, op.path);
|
|
10425
10507
|
return;
|
|
10426
10508
|
}
|
|
10427
10509
|
const childIndex = childIndexFromMap(map, beforeValue, op.path);
|
|
@@ -10558,33 +10640,14 @@ function resolveIndexableNode(context, value, keyedPath) {
|
|
|
10558
10640
|
};
|
|
10559
10641
|
}
|
|
10560
10642
|
function reconcileOwnerSubtree(map, context, beforeValue, afterValue, propertyPath) {
|
|
10561
|
-
|
|
10562
|
-
|
|
10563
|
-
ownerPathEnd--;
|
|
10564
|
-
if (ownerPathEnd === 0)
|
|
10565
|
-
return;
|
|
10566
|
-
const ownerPath = propertyPath.slice(0, ownerPathEnd);
|
|
10567
|
-
pruneSubtreeAtPath(
|
|
10643
|
+
const ownerPath = splitNodePath(propertyPath).nodePath;
|
|
10644
|
+
ownerPath.length !== 0 && (pruneSubtreeAtPath(
|
|
10568
10645
|
map,
|
|
10569
10646
|
beforeValue,
|
|
10570
10647
|
ownerPath,
|
|
10571
10648
|
/*keepSelf*/
|
|
10572
10649
|
!0
|
|
10573
|
-
), addSubtree(map, context, afterValue, ownerPath);
|
|
10574
|
-
}
|
|
10575
|
-
function resolveValueAtPath(value, path2) {
|
|
10576
|
-
let nodePathEnd = path2.length;
|
|
10577
|
-
for (; nodePathEnd > 0 && typeof path2[nodePathEnd - 1] == "string"; )
|
|
10578
|
-
nodePathEnd--;
|
|
10579
|
-
if (nodePathEnd === 0)
|
|
10580
|
-
return;
|
|
10581
|
-
let current = resolveNodeAtPath(value, path2.slice(0, nodePathEnd));
|
|
10582
|
-
for (let i = nodePathEnd; i < path2.length; i++) {
|
|
10583
|
-
if (current === null || typeof current != "object")
|
|
10584
|
-
return;
|
|
10585
|
-
current = current[path2[i]];
|
|
10586
|
-
}
|
|
10587
|
-
return current;
|
|
10650
|
+
), addSubtree(map, context, afterValue, ownerPath));
|
|
10588
10651
|
}
|
|
10589
10652
|
function hasKeyedEntries(value) {
|
|
10590
10653
|
return Array.isArray(value) && value.some((entry) => entry !== null && typeof entry == "object" && entry._key !== void 0);
|
|
@@ -10733,7 +10796,7 @@ ${safeStringify(event.operation, 2)}`);
|
|
|
10733
10796
|
operation.type !== "set.selection" && (operation.type === "insert.text" || operation.type === "remove.text" || (transformBlockIndexMap(editor.blockIndexMap, operation, event.beforeValue, editor.snapshot.context.value, {
|
|
10734
10797
|
schema: context.schema,
|
|
10735
10798
|
containers: editor.snapshot.context.containers
|
|
10736
|
-
}), editor.listIndexMapDirty = !0, invalidateVerifiedGroups(editor.verifiedUniqueChildGroups, operation)));
|
|
10799
|
+
}), editor.listIndexMapDirty = !0, editor.selectorChannelsPending.listIndex = !0, invalidateVerifiedGroups(editor.verifiedUniqueChildGroups, operation)));
|
|
10737
10800
|
});
|
|
10738
10801
|
return () => {
|
|
10739
10802
|
unsubscribeNormalizationLog?.(), unsubscribeIndexMaps();
|
|
@@ -10767,7 +10830,10 @@ function createEditorEngine(config) {
|
|
|
10767
10830
|
}, editor.containers = /* @__PURE__ */ new Map(), editor.blockObjects = /* @__PURE__ */ new Map(), editor.inlineObjects = /* @__PURE__ */ new Map(), editor.spans = /* @__PURE__ */ new Map(), editor.textBlocks = /* @__PURE__ */ new Map(), editor.decoratedRanges = [], editor.blockIndexMap = blockIndexMap, editor.history = {
|
|
10768
10831
|
undos: [],
|
|
10769
10832
|
redos: []
|
|
10770
|
-
}, editor.listIndexMap = /* @__PURE__ */ new Map(), editor.listIndexMapDirty = !1, editor.
|
|
10833
|
+
}, editor.listIndexMap = /* @__PURE__ */ new Map(), editor.listIndexMapDirty = !1, editor.selectorChannelsPending = {
|
|
10834
|
+
registrations: !1,
|
|
10835
|
+
listIndex: !1
|
|
10836
|
+
}, editor.verifiedUniqueChildGroups = /* @__PURE__ */ new Set(), editor.remotePatches = [], editor.undoStepId = void 0, editor.isDeferringMutations = !1, editor.isNormalizingNode = !1, editor.isPatching = !0, editor.isPerformingBehaviorOperation = !1, editor.isProcessingRemoteChanges = !1, editor.isRedoing = !1, editor.isUndoing = !1, editor.withHistory = !0;
|
|
10771
10837
|
const editorEngine = plugins(withDOM(editor), {
|
|
10772
10838
|
editorActor: config.editorActor
|
|
10773
10839
|
});
|
|
@@ -10808,7 +10874,8 @@ function createEditorDom(sendBack, editorEngine) {
|
|
|
10808
10874
|
getBlockNodes: (snapshot) => getBlockNodes(editorEngine, snapshot),
|
|
10809
10875
|
getChildNodes: (snapshot) => getChildNodes(editorEngine, snapshot),
|
|
10810
10876
|
getEditorElement: () => getEditorElement(editorEngine),
|
|
10811
|
-
getSelectionRect: (snapshot) => getSelectionRect(snapshot),
|
|
10877
|
+
getSelectionRect: (snapshot) => getSelectionRect(editorEngine, snapshot),
|
|
10878
|
+
getPointAtCoordinates: (coordinates) => getPointAtCoordinates(editorEngine, coordinates),
|
|
10812
10879
|
getStartBlockElement: (snapshot) => getStartBlockElement(editorEngine, snapshot),
|
|
10813
10880
|
getEndBlockElement: (snapshot) => getEndBlockElement(editorEngine, snapshot),
|
|
10814
10881
|
setDragGhost: ({
|
|
@@ -10861,12 +10928,15 @@ function getChildNodes(editorEngine, snapshot) {
|
|
|
10861
10928
|
function getEditorElement(editorEngine) {
|
|
10862
10929
|
return getDomNode(editorEngine, []);
|
|
10863
10930
|
}
|
|
10864
|
-
function getSelectionRect(snapshot) {
|
|
10865
|
-
|
|
10931
|
+
function getSelectionRect(editorEngine, snapshot) {
|
|
10932
|
+
const selection = snapshot.context.selection;
|
|
10933
|
+
if (!selection)
|
|
10866
10934
|
return null;
|
|
10867
10935
|
try {
|
|
10868
|
-
const
|
|
10869
|
-
|
|
10936
|
+
const engineRange = resolveSelection({
|
|
10937
|
+
snapshot
|
|
10938
|
+
}, selection);
|
|
10939
|
+
return engineRange ? DOMEditor.toDOMRange(editorEngine, engineRange).getBoundingClientRect() : null;
|
|
10870
10940
|
} catch {
|
|
10871
10941
|
return null;
|
|
10872
10942
|
}
|
|
@@ -10915,6 +10985,7 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
10915
10985
|
return !1;
|
|
10916
10986
|
const caretWordSelection = getCaretWordSelection(adjustedSnapshot);
|
|
10917
10987
|
return !caretWordSelection || !isSelectionExpanded({
|
|
10988
|
+
...adjustedSnapshot,
|
|
10918
10989
|
context: {
|
|
10919
10990
|
...adjustedSnapshot.context,
|
|
10920
10991
|
selection: caretWordSelection
|
|
@@ -11102,6 +11173,22 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
11102
11173
|
undo,
|
|
11103
11174
|
redo
|
|
11104
11175
|
},
|
|
11176
|
+
selectAll: createKeyboardShortcut({
|
|
11177
|
+
default: [{
|
|
11178
|
+
key: "A",
|
|
11179
|
+
alt: !1,
|
|
11180
|
+
ctrl: !0,
|
|
11181
|
+
meta: !1,
|
|
11182
|
+
shift: !1
|
|
11183
|
+
}],
|
|
11184
|
+
apple: [{
|
|
11185
|
+
key: "A",
|
|
11186
|
+
alt: !1,
|
|
11187
|
+
ctrl: !1,
|
|
11188
|
+
meta: !0,
|
|
11189
|
+
shift: !1
|
|
11190
|
+
}]
|
|
11191
|
+
}),
|
|
11105
11192
|
tab: createKeyboardShortcut({
|
|
11106
11193
|
default: [{
|
|
11107
11194
|
key: "Tab",
|
|
@@ -12144,11 +12231,13 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
12144
12231
|
if (!isListBlock(snapshot.context, startBlock) || !isListBlock(snapshot.context, endBlock))
|
|
12145
12232
|
return !1;
|
|
12146
12233
|
const deleteStartPoint = getSelectionStartPoint({
|
|
12234
|
+
...snapshot,
|
|
12147
12235
|
context: {
|
|
12148
12236
|
...snapshot.context,
|
|
12149
12237
|
selection: at
|
|
12150
12238
|
}
|
|
12151
12239
|
}), deleteEndPoint = getSelectionEndPoint({
|
|
12240
|
+
...snapshot,
|
|
12152
12241
|
context: {
|
|
12153
12242
|
...snapshot.context,
|
|
12154
12243
|
selection: at
|
|
@@ -14558,7 +14647,14 @@ const moveBackwardOperationImplementation = ({
|
|
|
14558
14647
|
}, selectOperationImplementation = ({
|
|
14559
14648
|
operation
|
|
14560
14649
|
}) => {
|
|
14561
|
-
|
|
14650
|
+
let newSelection = resolveSelection(operation.editor, operation.at);
|
|
14651
|
+
if (newSelection) {
|
|
14652
|
+
const anchorContainer = getContainer(operation.editor.snapshot, newSelection.anchor.path), focusContainer = getContainer(operation.editor.snapshot, newSelection.focus.path), containers = anchorContainer ? [anchorContainer] : [];
|
|
14653
|
+
focusContainer && focusContainer.node !== anchorContainer?.node && containers.push(focusContainer), containers.length > 0 && (withoutNormalizing(operation.editor, () => {
|
|
14654
|
+
for (const entry of containers)
|
|
14655
|
+
operation.editor.isNormalizingNode = !0, operation.editor.normalizeNode([entry.node, entry.path]), operation.editor.isNormalizingNode = !1;
|
|
14656
|
+
}), newSelection = resolveSelection(operation.editor, operation.at));
|
|
14657
|
+
}
|
|
14562
14658
|
newSelection ? applySelect(operation.editor, newSelection) : applyDeselect(operation.editor), operation.editor.focused && operation.editor.snapshot.context.readOnly && (operation.editor.focused = !1);
|
|
14563
14659
|
}, setOperationImplementation = ({
|
|
14564
14660
|
operation
|
|
@@ -15853,6 +15949,50 @@ const abstractInsertBehaviors = [
|
|
|
15853
15949
|
type: "history.redo"
|
|
15854
15950
|
})]]
|
|
15855
15951
|
}),
|
|
15952
|
+
/**
|
|
15953
|
+
* Manual handling of select-all. The native gesture cannot be trusted to
|
|
15954
|
+
* build the range: chromium produces an already-collapsed range whenever a
|
|
15955
|
+
* non-editable element sits at either content edge of the editing host,
|
|
15956
|
+
* which any document starting or ending with a void block or a
|
|
15957
|
+
* chrome-bearing container render does. "Everything" is a model-level
|
|
15958
|
+
* statement, so the range is computed from the model instead of
|
|
15959
|
+
* round-tripping through the DOM selection.
|
|
15960
|
+
*/
|
|
15961
|
+
defineBehavior({
|
|
15962
|
+
on: "keyboard.keydown",
|
|
15963
|
+
guard: ({
|
|
15964
|
+
snapshot,
|
|
15965
|
+
event
|
|
15966
|
+
}) => {
|
|
15967
|
+
if (!defaultKeyboardShortcuts.selectAll.guard(event.originEvent))
|
|
15968
|
+
return !1;
|
|
15969
|
+
const startLeaf = getLeaf(snapshot, [], {
|
|
15970
|
+
edge: "start"
|
|
15971
|
+
}), endLeaf = getLeaf(snapshot, [], {
|
|
15972
|
+
edge: "end"
|
|
15973
|
+
}), startBlock = startLeaf ? getEnclosingBlock(snapshot, startLeaf.path) : void 0, endBlock = endLeaf ? getEnclosingBlock(snapshot, endLeaf.path) : void 0;
|
|
15974
|
+
return !startBlock || !endBlock ? !1 : {
|
|
15975
|
+
anchor: getBlockStartPoint({
|
|
15976
|
+
context: snapshot.context,
|
|
15977
|
+
block: startBlock
|
|
15978
|
+
}),
|
|
15979
|
+
focus: getBlockEndPoint({
|
|
15980
|
+
context: snapshot.context,
|
|
15981
|
+
block: endBlock
|
|
15982
|
+
})
|
|
15983
|
+
};
|
|
15984
|
+
},
|
|
15985
|
+
actions: [(_, {
|
|
15986
|
+
anchor,
|
|
15987
|
+
focus
|
|
15988
|
+
}) => [raise({
|
|
15989
|
+
type: "select",
|
|
15990
|
+
at: {
|
|
15991
|
+
anchor,
|
|
15992
|
+
focus
|
|
15993
|
+
}
|
|
15994
|
+
})]]
|
|
15995
|
+
}),
|
|
15856
15996
|
/**
|
|
15857
15997
|
* Fix edge case where Shift+ArrowLeft didn't reduce a selection hanging
|
|
15858
15998
|
* onto an empty text block.
|
|
@@ -16727,15 +16867,17 @@ function synthesizeBlockChildrenField(schema) {
|
|
|
16727
16867
|
of: ofMembers
|
|
16728
16868
|
};
|
|
16729
16869
|
}
|
|
16730
|
-
function resolveFieldOn(fields,
|
|
16870
|
+
function resolveFieldOn(fields, fieldName) {
|
|
16731
16871
|
const field = fields.find((candidate) => candidate.name === fieldName);
|
|
16732
|
-
|
|
16733
|
-
|
|
16734
|
-
|
|
16735
|
-
|
|
16736
|
-
|
|
16737
|
-
|
|
16738
|
-
}
|
|
16872
|
+
return field ? isChildArrayField(field) ? containsOnlyPrimitiveTypes(field) ? {
|
|
16873
|
+
failure: "field-primitive-only"
|
|
16874
|
+
} : {
|
|
16875
|
+
field
|
|
16876
|
+
} : {
|
|
16877
|
+
failure: "field-not-array"
|
|
16878
|
+
} : {
|
|
16879
|
+
failure: "field-missing"
|
|
16880
|
+
};
|
|
16739
16881
|
}
|
|
16740
16882
|
function findInlineDeclarationIn(parentOf, type) {
|
|
16741
16883
|
for (const member of parentOf)
|
|
@@ -16763,28 +16905,35 @@ function findInlineFields(schema, type) {
|
|
|
16763
16905
|
isChildArrayField(field) && walk(field.of);
|
|
16764
16906
|
return best;
|
|
16765
16907
|
}
|
|
16766
|
-
function
|
|
16908
|
+
function resolveContainerFieldResolution(schema, type, fieldName, parentOf) {
|
|
16767
16909
|
if (type === "block")
|
|
16768
|
-
return fieldName !== "children" ?
|
|
16910
|
+
return fieldName !== "children" ? {
|
|
16911
|
+
failure: "field-missing"
|
|
16912
|
+
} : {
|
|
16913
|
+
field: synthesizeBlockChildrenField(schema)
|
|
16914
|
+
};
|
|
16769
16915
|
if (parentOf) {
|
|
16770
16916
|
const inlineMatch = findInlineDeclarationIn(parentOf, type);
|
|
16771
16917
|
if (inlineMatch)
|
|
16772
|
-
return resolveFieldOn(inlineMatch,
|
|
16918
|
+
return resolveFieldOn(inlineMatch, fieldName);
|
|
16773
16919
|
}
|
|
16774
16920
|
const rootMatch = schema.blockObjects.find((blockObject) => blockObject.name === type), rootFields = rootMatch && "fields" in rootMatch && rootMatch.fields && rootMatch.fields.length > 0 ? rootMatch.fields : void 0, inlineFields = rootFields ? void 0 : findInlineFields(schema, type), fields = rootFields ?? inlineFields;
|
|
16775
|
-
|
|
16776
|
-
|
|
16921
|
+
return fields ? resolveFieldOn(fields, fieldName) : rootMatch ? {
|
|
16922
|
+
failure: "field-missing"
|
|
16923
|
+
} : {
|
|
16924
|
+
failure: "unknown-type"
|
|
16925
|
+
};
|
|
16777
16926
|
}
|
|
16778
16927
|
function resolveNestedContainer(schema, container, chain = [], onFailure = "warn", parentOf) {
|
|
16779
|
-
const
|
|
16780
|
-
if (
|
|
16781
|
-
const location = chain.length > 0 ? ` (nested inside ${chain.map((type) => `"${type}"`).join(" inside ")})` : "", message = `registerNode:
|
|
16928
|
+
const resolution = resolveContainerFieldResolution(schema, container.type, container.arrayField, parentOf);
|
|
16929
|
+
if ("failure" in resolution) {
|
|
16930
|
+
const location = chain.length > 0 ? ` (nested inside ${chain.map((type) => `"${type}"`).join(" inside ")})` : "", message = `registerNode: ${describeContainerFailure(resolution.failure, container)}${location}. Registration skipped.`;
|
|
16782
16931
|
if (onFailure === "throw")
|
|
16783
16932
|
throw new Error(message);
|
|
16784
16933
|
console.warn(message);
|
|
16785
16934
|
return;
|
|
16786
16935
|
}
|
|
16787
|
-
const nextChain = [...chain, container.type], resolvedOf = container.of ? container.of.flatMap((entry) => {
|
|
16936
|
+
const field = resolution.field, nextChain = [...chain, container.type], resolvedOf = container.of ? container.of.flatMap((entry) => {
|
|
16788
16937
|
if (entry.kind === "container") {
|
|
16789
16938
|
const resolved = resolveNestedContainer(schema, entry, nextChain, onFailure, field.of);
|
|
16790
16939
|
return resolved ? [resolved] : [];
|
|
@@ -16801,6 +16950,18 @@ function resolveNestedContainer(schema, container, chain = [], onFailure = "warn
|
|
|
16801
16950
|
} : {}
|
|
16802
16951
|
};
|
|
16803
16952
|
}
|
|
16953
|
+
function describeContainerFailure(failure, container) {
|
|
16954
|
+
switch (failure) {
|
|
16955
|
+
case "unknown-type":
|
|
16956
|
+
return `type "${container.type}" not found in the schema`;
|
|
16957
|
+
case "field-missing":
|
|
16958
|
+
return `field "${container.arrayField}" not found on type "${container.type}"`;
|
|
16959
|
+
case "field-not-array":
|
|
16960
|
+
return `field "${container.arrayField}" on type "${container.type}" is not an array`;
|
|
16961
|
+
case "field-primitive-only":
|
|
16962
|
+
return `field "${container.arrayField}" on type "${container.type}" contains only primitive types and cannot hold block content`;
|
|
16963
|
+
}
|
|
16964
|
+
}
|
|
16804
16965
|
function resolveTextBlockConfig(textBlock) {
|
|
16805
16966
|
const resolvedOf = textBlock.of ? textBlock.of.flatMap((entry) => entry.kind === "span" ? [{
|
|
16806
16967
|
span: entry
|
|
@@ -16853,14 +17014,14 @@ function registerNodeOnEngine(engine, node) {
|
|
|
16853
17014
|
const containers = new Map(engine.containers);
|
|
16854
17015
|
containers.set(node.type, containerConfig), engine.containers = containers, engine.snapshot.context.containers = buildPublicContainers(containers), normalize(engine, {
|
|
16855
17016
|
force: !0
|
|
16856
|
-
}), engine
|
|
17017
|
+
}), notifyRegistrationsChanged(engine);
|
|
16857
17018
|
return;
|
|
16858
17019
|
}
|
|
16859
17020
|
if (node.kind === "textBlock") {
|
|
16860
17021
|
if (isTypeAlreadyRegistered(engine, "textBlock", node.type))
|
|
16861
17022
|
return;
|
|
16862
17023
|
const textBlocks = new Map(engine.textBlocks);
|
|
16863
|
-
textBlocks.set(node.type, resolveTextBlockConfig(node)), engine.textBlocks = textBlocks, engine
|
|
17024
|
+
textBlocks.set(node.type, resolveTextBlockConfig(node)), engine.textBlocks = textBlocks, notifyRegistrationsChanged(engine);
|
|
16864
17025
|
return;
|
|
16865
17026
|
}
|
|
16866
17027
|
if (node.kind === "span") {
|
|
@@ -16869,7 +17030,7 @@ function registerNodeOnEngine(engine, node) {
|
|
|
16869
17030
|
const spans = new Map(engine.spans);
|
|
16870
17031
|
spans.set(node.type, {
|
|
16871
17032
|
span: node
|
|
16872
|
-
}), engine.spans = spans, engine
|
|
17033
|
+
}), engine.spans = spans, notifyRegistrationsChanged(engine);
|
|
16873
17034
|
return;
|
|
16874
17035
|
}
|
|
16875
17036
|
if (node.kind === "blockObject") {
|
|
@@ -16878,7 +17039,7 @@ function registerNodeOnEngine(engine, node) {
|
|
|
16878
17039
|
const blockObjects = new Map(engine.blockObjects);
|
|
16879
17040
|
blockObjects.set(node.type, {
|
|
16880
17041
|
blockObject: node
|
|
16881
|
-
}), engine.blockObjects = blockObjects, engine
|
|
17042
|
+
}), engine.blockObjects = blockObjects, notifyRegistrationsChanged(engine);
|
|
16882
17043
|
return;
|
|
16883
17044
|
}
|
|
16884
17045
|
if (isTypeAlreadyRegistered(engine, "inlineObject", node.type))
|
|
@@ -16886,33 +17047,36 @@ function registerNodeOnEngine(engine, node) {
|
|
|
16886
17047
|
const inlineObjects = new Map(engine.inlineObjects);
|
|
16887
17048
|
inlineObjects.set(node.type, {
|
|
16888
17049
|
inlineObject: node
|
|
16889
|
-
}), engine.inlineObjects = inlineObjects, engine
|
|
17050
|
+
}), engine.inlineObjects = inlineObjects, notifyRegistrationsChanged(engine);
|
|
16890
17051
|
}
|
|
16891
17052
|
function unregisterNodeOnEngine(engine, node) {
|
|
16892
17053
|
if (node.kind === "container") {
|
|
16893
17054
|
const containers = new Map(engine.containers);
|
|
16894
17055
|
containers.delete(node.type), engine.containers = containers, engine.snapshot.context.containers = buildPublicContainers(containers), normalize(engine, {
|
|
16895
17056
|
force: !0
|
|
16896
|
-
}), engine
|
|
17057
|
+
}), notifyRegistrationsChanged(engine);
|
|
16897
17058
|
return;
|
|
16898
17059
|
}
|
|
16899
17060
|
if (node.kind === "textBlock") {
|
|
16900
17061
|
const textBlocks = new Map(engine.textBlocks);
|
|
16901
|
-
textBlocks.delete(node.type), engine.textBlocks = textBlocks, engine
|
|
17062
|
+
textBlocks.delete(node.type), engine.textBlocks = textBlocks, notifyRegistrationsChanged(engine);
|
|
16902
17063
|
return;
|
|
16903
17064
|
}
|
|
16904
17065
|
if (node.kind === "span") {
|
|
16905
17066
|
const spans = new Map(engine.spans);
|
|
16906
|
-
spans.delete(node.type), engine.spans = spans, engine
|
|
17067
|
+
spans.delete(node.type), engine.spans = spans, notifyRegistrationsChanged(engine);
|
|
16907
17068
|
return;
|
|
16908
17069
|
}
|
|
16909
17070
|
if (node.kind === "blockObject") {
|
|
16910
17071
|
const blockObjects = new Map(engine.blockObjects);
|
|
16911
|
-
blockObjects.delete(node.type), engine.blockObjects = blockObjects, engine
|
|
17072
|
+
blockObjects.delete(node.type), engine.blockObjects = blockObjects, notifyRegistrationsChanged(engine);
|
|
16912
17073
|
return;
|
|
16913
17074
|
}
|
|
16914
17075
|
const inlineObjects = new Map(engine.inlineObjects);
|
|
16915
|
-
inlineObjects.delete(node.type), engine.inlineObjects = inlineObjects, engine
|
|
17076
|
+
inlineObjects.delete(node.type), engine.inlineObjects = inlineObjects, notifyRegistrationsChanged(engine);
|
|
17077
|
+
}
|
|
17078
|
+
function notifyRegistrationsChanged(engine) {
|
|
17079
|
+
engine.selectorChannelsPending.registrations = !0, engine.onChange();
|
|
16916
17080
|
}
|
|
16917
17081
|
function rerouteExternalBehaviorEvent({
|
|
16918
17082
|
event,
|