@portabletext/editor 1.53.0 → 1.54.0
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-cjs/selection-point.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +144 -6
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +6 -140
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
- package/lib/_chunks-es/selection-point.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +148 -10
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +6 -140
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +68 -9
- package/lib/behaviors/index.d.ts +68 -9
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +553 -313
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +69 -13
- package/lib/index.d.ts +69 -13
- package/lib/index.js +534 -294
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +69 -9
- package/lib/plugins/index.d.ts +69 -9
- package/lib/selectors/index.cjs +10 -10
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +42 -27
- package/lib/selectors/index.d.ts +42 -27
- package/lib/selectors/index.js +4 -4
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +27 -5
- package/lib/utils/index.d.ts +27 -5
- package/package.json +14 -14
- package/src/behaviors/behavior.abstract.annotation.ts +51 -0
- package/src/behaviors/behavior.abstract.delete.ts +55 -0
- package/src/behaviors/behavior.perform-event.ts +6 -15
- package/src/behaviors/behavior.types.action.ts +1 -1
- package/src/behaviors/behavior.types.event.ts +32 -8
- package/src/behaviors/behavior.types.guard.ts +1 -1
- package/src/editor/Editable.tsx +3 -0
- package/src/editor/PortableTextEditor.tsx +1 -6
- package/src/editor/create-editor.ts +5 -0
- package/src/{internal-utils/selection-elements.ts → editor/editor-dom.ts} +29 -21
- package/src/editor/editor-provider.tsx +1 -6
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +6 -46
- package/src/editor/plugins/createWithPatches.ts +1 -5
- package/src/editor.ts +2 -0
- package/src/index.ts +2 -0
- package/src/operations/behavior.operation.child.set.ts +103 -0
- package/src/operations/behavior.operation.child.unset.ts +89 -0
- package/src/operations/behavior.operations.ts +18 -0
- package/src/selectors/index.ts +13 -1
- package/src/selectors/selector.get-active-annotations.ts +2 -1
- package/src/selectors/selector.get-active-list-item.ts +1 -1
- package/src/selectors/selector.get-active-style.ts +1 -1
- package/src/selectors/selector.get-anchor-block.ts +3 -2
- package/src/selectors/selector.get-anchor-child.ts +2 -2
- package/src/selectors/selector.get-anchor-span.ts +2 -3
- package/src/selectors/selector.get-anchor-text-block.ts +3 -2
- package/src/selectors/selector.get-caret-word-selection.ts +1 -1
- package/src/selectors/selector.get-first-block.ts +14 -0
- package/src/selectors/selector.get-focus-block-object.ts +18 -0
- package/src/selectors/selector.get-focus-block.ts +23 -0
- package/src/selectors/selector.get-focus-child.ts +36 -0
- package/src/selectors/selector.get-focus-inline-object.ts +4 -8
- package/src/selectors/selector.get-focus-list-block.ts +18 -0
- package/src/selectors/selector.get-focus-span.ts +18 -0
- package/src/selectors/selector.get-focus-text-block.ts +18 -0
- package/src/selectors/selector.get-last-block.ts +16 -0
- package/src/selectors/selector.get-list-state.ts +2 -1
- package/src/selectors/selector.get-next-block.ts +38 -0
- package/src/selectors/selector.get-next-inline-object.ts +5 -8
- package/src/selectors/selector.get-previous-block.ts +35 -0
- package/src/selectors/selector.get-previous-inline-object.ts +5 -8
- package/src/selectors/selector.get-selected-blocks.ts +49 -0
- package/src/selectors/selector.get-selected-spans.test.ts +96 -0
- package/src/selectors/selector.get-selected-spans.ts +4 -3
- package/src/selectors/selector.get-selected-text-blocks.ts +4 -3
- package/src/selectors/selector.get-selection-end-block.ts +4 -1
- package/src/selectors/selector.get-selection-start-block.ts +4 -1
- package/src/selectors/selector.get-text-before.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.ts +1 -1
- package/src/selectors/selector.is-active-annotation.ts +1 -1
- package/src/selectors/selector.is-at-the-end-of-block.ts +3 -2
- package/src/selectors/selector.is-at-the-start-of-block.ts +3 -2
- package/src/selectors/selector.is-selecting-entire-blocks.ts +2 -1
- package/src/types/block-offset.ts +2 -2
- package/src/types/paths.ts +13 -0
- package/src/utils/util.block-offset.ts +2 -4
- package/src/utils/util.get-block-end-point.ts +3 -2
- package/src/utils/util.get-block-start-point.ts +3 -2
- package/src/selectors/selectors.ts +0 -299
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c } from "react-compiler-runtime";
|
|
2
|
-
import React, { useEffect, createContext, useContext, useState, useRef,
|
|
2
|
+
import React, { useEffect, createContext, useContext, useState, useRef, Component, useMemo, startTransition, useCallback, forwardRef, useImperativeHandle } from "react";
|
|
3
3
|
import { useEffectEvent } from "use-effect-event";
|
|
4
4
|
import { useEditor, EditorContext } from "./_chunks-es/use-editor.js";
|
|
5
5
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
@@ -7,15 +7,15 @@ import { useSelector, useActorRef } from "@xstate/react";
|
|
|
7
7
|
import noop from "lodash/noop.js";
|
|
8
8
|
import { Element as Element$1, Text, Range, Editor, Node, Point, Transforms, Path, Operation, createEditor } from "slate";
|
|
9
9
|
import { useSlateStatic, useSelected, withReact, ReactEditor, Slate, useSlate, Editable } from "slate-react";
|
|
10
|
-
import debug$
|
|
10
|
+
import debug$f from "debug";
|
|
11
11
|
import { DOMEditor, isDOMNode } from "slate-dom";
|
|
12
12
|
import { getBlockStartPoint, getBlockKeyFromSelectionPoint, isTextBlock, parseBlock, sliceBlocks, parseAnnotation, blockOffsetToSpanSelectionPoint, parseInlineObject, isKeyedSegment, isSpan$1 as isSpan, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText, parseBlocks } from "./_chunks-es/selection-point.js";
|
|
13
13
|
import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./_chunks-es/util.is-equal-selection-points.js";
|
|
14
14
|
import { isSelectionCollapsed, selectionPointToBlockOffset } from "./_chunks-es/util.selection-point-to-block-offset.js";
|
|
15
15
|
import isEqual from "lodash/isEqual.js";
|
|
16
16
|
import { isKeySegment, defineType, defineField } from "@sanity/types";
|
|
17
|
-
import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1,
|
|
18
|
-
import { getFocusInlineObject, isOverlappingSelection, isSelectingEntireBlocks, getTrimmedSelection, getSelectedSpans, getCaretWordSelection, isAtTheEndOfBlock, isAtTheStartOfBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations as getActiveAnnotations$1 } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
17
|
+
import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1, getFocusChild as getFocusChild$1 } from "./_chunks-es/selector.is-selection-expanded.js";
|
|
18
|
+
import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getTrimmedSelection, getSelectedSpans, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations as getActiveAnnotations$1 } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
19
19
|
import getRandomValues from "get-random-values-esm";
|
|
20
20
|
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
21
21
|
import uniq from "lodash/uniq.js";
|
|
@@ -26,8 +26,8 @@ import { toHTML } from "@portabletext/to-html";
|
|
|
26
26
|
import { Schema } from "@sanity/schema";
|
|
27
27
|
import flatten from "lodash/flatten.js";
|
|
28
28
|
import omit from "lodash/omit.js";
|
|
29
|
-
import { blockOffsetsToSelection } from "./_chunks-es/util.child-selection-point-to-block-offset.js";
|
|
30
29
|
import { applyAll, unset, insert, set, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
30
|
+
import { blockOffsetsToSelection } from "./_chunks-es/util.child-selection-point-to-block-offset.js";
|
|
31
31
|
import get from "lodash/get.js";
|
|
32
32
|
import isUndefined from "lodash/isUndefined.js";
|
|
33
33
|
import omitBy from "lodash/omitBy.js";
|
|
@@ -47,10 +47,10 @@ function EditorEventListener(props) {
|
|
|
47
47
|
return $[3] !== editor ? (t1 = [editor], $[3] = editor, $[4] = t1) : t1 = $[4], useEffect(t0, t1), null;
|
|
48
48
|
}
|
|
49
49
|
const rootName = "sanity-pte:";
|
|
50
|
-
debug$
|
|
50
|
+
debug$f(rootName);
|
|
51
51
|
function debugWithName(name) {
|
|
52
52
|
const namespace = `${rootName}${name}`;
|
|
53
|
-
return debug$
|
|
53
|
+
return debug$f && debug$f.enabled(namespace) ? debug$f(namespace) : debug$f(rootName);
|
|
54
54
|
}
|
|
55
55
|
const VOID_CHILD_KEY = "void-child";
|
|
56
56
|
function keepObjectEquality(object, keyMap) {
|
|
@@ -1498,7 +1498,7 @@ function getEditorSnapshot({
|
|
|
1498
1498
|
}
|
|
1499
1499
|
};
|
|
1500
1500
|
}
|
|
1501
|
-
const debug$
|
|
1501
|
+
const debug$e = debugWithName("plugin:withPortableTextMarkModel");
|
|
1502
1502
|
function createWithPortableTextMarkModel(editorActor) {
|
|
1503
1503
|
return function(editor) {
|
|
1504
1504
|
const {
|
|
@@ -1512,7 +1512,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1512
1512
|
for (const [child, childPath] of children) {
|
|
1513
1513
|
const nextNode = node.children[childPath[1] + 1];
|
|
1514
1514
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
1515
|
-
debug$
|
|
1515
|
+
debug$e("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
1516
1516
|
type: "normalizing"
|
|
1517
1517
|
}), Transforms.mergeNodes(editor, {
|
|
1518
1518
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -1525,7 +1525,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1525
1525
|
}
|
|
1526
1526
|
}
|
|
1527
1527
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
1528
|
-
debug$
|
|
1528
|
+
debug$e("Adding .markDefs to block node"), editorActor.send({
|
|
1529
1529
|
type: "normalizing"
|
|
1530
1530
|
}), Transforms.setNodes(editor, {
|
|
1531
1531
|
markDefs: []
|
|
@@ -1537,7 +1537,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1537
1537
|
return;
|
|
1538
1538
|
}
|
|
1539
1539
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
1540
|
-
debug$
|
|
1540
|
+
debug$e("Adding .marks to span node"), editorActor.send({
|
|
1541
1541
|
type: "normalizing"
|
|
1542
1542
|
}), Transforms.setNodes(editor, {
|
|
1543
1543
|
marks: []
|
|
@@ -1551,7 +1551,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1551
1551
|
if (editor.isTextSpan(node)) {
|
|
1552
1552
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
1553
1553
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
1554
|
-
debug$
|
|
1554
|
+
debug$e("Removing annotations from empty span node"), editorActor.send({
|
|
1555
1555
|
type: "normalizing"
|
|
1556
1556
|
}), Transforms.setNodes(editor, {
|
|
1557
1557
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -1569,7 +1569,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1569
1569
|
if (editor.isTextSpan(child)) {
|
|
1570
1570
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
1571
1571
|
if (orphanedAnnotations.length > 0) {
|
|
1572
|
-
debug$
|
|
1572
|
+
debug$e("Removing orphaned annotations from span node"), editorActor.send({
|
|
1573
1573
|
type: "normalizing"
|
|
1574
1574
|
}), Transforms.setNodes(editor, {
|
|
1575
1575
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -1587,7 +1587,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1587
1587
|
if (editor.isTextBlock(block)) {
|
|
1588
1588
|
const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
1589
1589
|
if (orphanedAnnotations.length > 0) {
|
|
1590
|
-
debug$
|
|
1590
|
+
debug$e("Removing orphaned annotations from span node"), editorActor.send({
|
|
1591
1591
|
type: "normalizing"
|
|
1592
1592
|
}), Transforms.setNodes(editor, {
|
|
1593
1593
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -1605,7 +1605,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1605
1605
|
for (const markDef of markDefs)
|
|
1606
1606
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
1607
1607
|
if (markDefs.length !== newMarkDefs.length) {
|
|
1608
|
-
debug$
|
|
1608
|
+
debug$e("Removing duplicate markDefs"), editorActor.send({
|
|
1609
1609
|
type: "normalizing"
|
|
1610
1610
|
}), Transforms.setNodes(editor, {
|
|
1611
1611
|
markDefs: newMarkDefs
|
|
@@ -1620,7 +1620,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1620
1620
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
1621
1621
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
1622
1622
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
1623
|
-
debug$
|
|
1623
|
+
debug$e("Removing markDef not in use"), editorActor.send({
|
|
1624
1624
|
type: "normalizing"
|
|
1625
1625
|
}), Transforms.setNodes(editor, {
|
|
1626
1626
|
markDefs: newMarkDefs
|
|
@@ -1773,7 +1773,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1773
1773
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
1774
1774
|
if (editor.isTextBlock(targetBlock)) {
|
|
1775
1775
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
1776
|
-
debug$
|
|
1776
|
+
debug$e("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
1777
1777
|
markDefs: newMarkDefs
|
|
1778
1778
|
}, {
|
|
1779
1779
|
at: targetPath,
|
|
@@ -2483,7 +2483,7 @@ function withUndoStep(editor, fn) {
|
|
|
2483
2483
|
function getCurrentUndoStepId(editor) {
|
|
2484
2484
|
return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
|
|
2485
2485
|
}
|
|
2486
|
-
const debug$
|
|
2486
|
+
const debug$d = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2487
2487
|
const state = SAVING.get(editor);
|
|
2488
2488
|
return state === void 0 ? !0 : state;
|
|
2489
2489
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -2496,7 +2496,7 @@ function createWithUndoRedo(options) {
|
|
|
2496
2496
|
const remotePatches = getRemotePatches(editor);
|
|
2497
2497
|
let previousUndoStepId = getCurrentUndoStepId(editor);
|
|
2498
2498
|
options.subscriptions.push(() => {
|
|
2499
|
-
debug$
|
|
2499
|
+
debug$d("Subscribing to patches");
|
|
2500
2500
|
const sub = editorActor.on("patches", ({
|
|
2501
2501
|
patches,
|
|
2502
2502
|
snapshot
|
|
@@ -2505,7 +2505,7 @@ function createWithUndoRedo(options) {
|
|
|
2505
2505
|
patches.forEach((patch) => {
|
|
2506
2506
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
2507
2507
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2508
|
-
debug$
|
|
2508
|
+
debug$d("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
2509
2509
|
undos: [],
|
|
2510
2510
|
redos: []
|
|
2511
2511
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -2521,7 +2521,7 @@ function createWithUndoRedo(options) {
|
|
|
2521
2521
|
}), previousSnapshot = snapshot;
|
|
2522
2522
|
});
|
|
2523
2523
|
return () => {
|
|
2524
|
-
debug$
|
|
2524
|
+
debug$d("Unsubscribing to patches"), sub.unsubscribe();
|
|
2525
2525
|
};
|
|
2526
2526
|
}), editor.history = {
|
|
2527
2527
|
undos: [],
|
|
@@ -2560,7 +2560,7 @@ function createWithUndoRedo(options) {
|
|
|
2560
2560
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
2561
2561
|
timestamp: /* @__PURE__ */ new Date()
|
|
2562
2562
|
};
|
|
2563
|
-
undos.push(newStep), debug$
|
|
2563
|
+
undos.push(newStep), debug$d("Created new undo step", step);
|
|
2564
2564
|
}
|
|
2565
2565
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
2566
2566
|
undos.shift();
|
|
@@ -2578,7 +2578,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2578
2578
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2579
2579
|
if (undos.length > 0) {
|
|
2580
2580
|
const step = undos[undos.length - 1];
|
|
2581
|
-
if (debug$
|
|
2581
|
+
if (debug$d("Undoing", step), step.operations.length > 0) {
|
|
2582
2582
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2583
2583
|
let transformedOperations = step.operations;
|
|
2584
2584
|
otherPatches.forEach((item) => {
|
|
@@ -2596,7 +2596,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2596
2596
|
});
|
|
2597
2597
|
});
|
|
2598
2598
|
} catch (err) {
|
|
2599
|
-
debug$
|
|
2599
|
+
debug$d("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
2600
2600
|
undos: [],
|
|
2601
2601
|
redos: []
|
|
2602
2602
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -2613,7 +2613,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2613
2613
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2614
2614
|
if (redos.length > 0) {
|
|
2615
2615
|
const step = redos[redos.length - 1];
|
|
2616
|
-
if (debug$
|
|
2616
|
+
if (debug$d("Redoing", step), step.operations.length > 0) {
|
|
2617
2617
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2618
2618
|
let transformedOperations = step.operations;
|
|
2619
2619
|
otherPatches.forEach((item) => {
|
|
@@ -2630,7 +2630,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2630
2630
|
});
|
|
2631
2631
|
});
|
|
2632
2632
|
} catch (err) {
|
|
2633
|
-
debug$
|
|
2633
|
+
debug$d("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
2634
2634
|
undos: [],
|
|
2635
2635
|
redos: []
|
|
2636
2636
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -2648,16 +2648,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2648
2648
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
2649
2649
|
_key: blk._key
|
|
2650
2650
|
}, patch.path[0]));
|
|
2651
|
-
return debug$
|
|
2651
|
+
return debug$d(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
2652
2652
|
}
|
|
2653
2653
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
2654
2654
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
|
|
2655
2655
|
_key: blk._key
|
|
2656
2656
|
}, patch.path[0]));
|
|
2657
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
2657
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$d("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
2658
2658
|
}
|
|
2659
2659
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2660
|
-
return debug$
|
|
2660
|
+
return debug$d(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
2661
2661
|
if (patch.type === "diffMatchPatch") {
|
|
2662
2662
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2663
2663
|
return !operationTargetBlock || !isEqual({
|
|
@@ -2990,6 +2990,132 @@ const addAnnotationOperationImplementation = ({
|
|
|
2990
2990
|
}, {
|
|
2991
2991
|
at: location
|
|
2992
2992
|
});
|
|
2993
|
+
}, childSetOperationImplementation = ({
|
|
2994
|
+
context,
|
|
2995
|
+
operation
|
|
2996
|
+
}) => {
|
|
2997
|
+
const location = toSlateRange({
|
|
2998
|
+
anchor: {
|
|
2999
|
+
path: operation.at,
|
|
3000
|
+
offset: 0
|
|
3001
|
+
},
|
|
3002
|
+
focus: {
|
|
3003
|
+
path: operation.at,
|
|
3004
|
+
offset: 0
|
|
3005
|
+
}
|
|
3006
|
+
}, operation.editor);
|
|
3007
|
+
if (!location)
|
|
3008
|
+
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
3009
|
+
const childEntry = Editor.node(operation.editor, location, {
|
|
3010
|
+
depth: 2
|
|
3011
|
+
}), child = childEntry?.[0], childPath = childEntry?.[1];
|
|
3012
|
+
if (!child || !childPath)
|
|
3013
|
+
throw new Error(`Unable to find child at ${JSON.stringify(operation.at)}`);
|
|
3014
|
+
if (operation.editor.isTextSpan(child)) {
|
|
3015
|
+
const {
|
|
3016
|
+
_type,
|
|
3017
|
+
text,
|
|
3018
|
+
...rest
|
|
3019
|
+
} = operation.props;
|
|
3020
|
+
Transforms.setNodes(operation.editor, {
|
|
3021
|
+
...child,
|
|
3022
|
+
...rest
|
|
3023
|
+
}, {
|
|
3024
|
+
at: childPath
|
|
3025
|
+
}), typeof text == "string" && child.text !== text && (operation.editor.apply({
|
|
3026
|
+
type: "remove_text",
|
|
3027
|
+
path: childPath,
|
|
3028
|
+
offset: 0,
|
|
3029
|
+
text: child.text
|
|
3030
|
+
}), operation.editor.apply({
|
|
3031
|
+
type: "insert_text",
|
|
3032
|
+
path: childPath,
|
|
3033
|
+
offset: 0,
|
|
3034
|
+
text
|
|
3035
|
+
}));
|
|
3036
|
+
return;
|
|
3037
|
+
}
|
|
3038
|
+
if (Element$1.isElement(child)) {
|
|
3039
|
+
const definition = context.schema.inlineObjects.find((definition2) => definition2.name === child._type);
|
|
3040
|
+
if (!definition)
|
|
3041
|
+
throw new Error(`Unable to find schema definition for Inline Object type ${child._type}`);
|
|
3042
|
+
const value = "value" in child && typeof child.value == "object" ? child.value : {}, {
|
|
3043
|
+
_type,
|
|
3044
|
+
_key,
|
|
3045
|
+
...rest
|
|
3046
|
+
} = operation.props;
|
|
3047
|
+
for (const prop in rest)
|
|
3048
|
+
definition.fields.some((field) => field.name === prop) || delete rest[prop];
|
|
3049
|
+
Transforms.setNodes(operation.editor, {
|
|
3050
|
+
...child,
|
|
3051
|
+
_key: typeof _key == "string" ? _key : child._key,
|
|
3052
|
+
value: {
|
|
3053
|
+
...value,
|
|
3054
|
+
...rest
|
|
3055
|
+
}
|
|
3056
|
+
}, {
|
|
3057
|
+
at: childPath
|
|
3058
|
+
});
|
|
3059
|
+
return;
|
|
3060
|
+
}
|
|
3061
|
+
throw new Error(`Unable to determine the type of child at ${JSON.stringify(operation.at)}`);
|
|
3062
|
+
}, childUnsetOperationImplementation = ({
|
|
3063
|
+
context,
|
|
3064
|
+
operation
|
|
3065
|
+
}) => {
|
|
3066
|
+
const location = toSlateRange({
|
|
3067
|
+
anchor: {
|
|
3068
|
+
path: operation.at,
|
|
3069
|
+
offset: 0
|
|
3070
|
+
},
|
|
3071
|
+
focus: {
|
|
3072
|
+
path: operation.at,
|
|
3073
|
+
offset: 0
|
|
3074
|
+
}
|
|
3075
|
+
}, operation.editor);
|
|
3076
|
+
if (!location)
|
|
3077
|
+
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
3078
|
+
const childEntry = Editor.node(operation.editor, location, {
|
|
3079
|
+
depth: 2
|
|
3080
|
+
}), child = childEntry?.[0], childPath = childEntry?.[1];
|
|
3081
|
+
if (!child || !childPath)
|
|
3082
|
+
throw new Error(`Unable to find child at ${JSON.stringify(operation.at)}`);
|
|
3083
|
+
if (operation.editor.isTextSpan(child)) {
|
|
3084
|
+
operation.props.includes("text") && operation.editor.apply({
|
|
3085
|
+
type: "remove_text",
|
|
3086
|
+
path: childPath,
|
|
3087
|
+
offset: 0,
|
|
3088
|
+
text: child.text
|
|
3089
|
+
});
|
|
3090
|
+
const newNode = {};
|
|
3091
|
+
for (const prop of operation.props)
|
|
3092
|
+
if (prop !== "_type") {
|
|
3093
|
+
if (prop === "_key") {
|
|
3094
|
+
newNode._key = context.keyGenerator();
|
|
3095
|
+
continue;
|
|
3096
|
+
}
|
|
3097
|
+
newNode[prop] = null;
|
|
3098
|
+
}
|
|
3099
|
+
Transforms.setNodes(operation.editor, newNode, {
|
|
3100
|
+
at: childPath
|
|
3101
|
+
});
|
|
3102
|
+
return;
|
|
3103
|
+
}
|
|
3104
|
+
if (Element$1.isElement(child)) {
|
|
3105
|
+
const value = "value" in child && typeof child.value == "object" ? child.value : {}, patches = operation.props.map((prop) => ({
|
|
3106
|
+
type: "unset",
|
|
3107
|
+
path: [prop]
|
|
3108
|
+
})), newValue = applyAll(value, patches);
|
|
3109
|
+
Transforms.setNodes(operation.editor, {
|
|
3110
|
+
...child,
|
|
3111
|
+
_key: operation.props.includes("_key") ? context.keyGenerator() : child._key,
|
|
3112
|
+
value: newValue
|
|
3113
|
+
}, {
|
|
3114
|
+
at: childPath
|
|
3115
|
+
});
|
|
3116
|
+
return;
|
|
3117
|
+
}
|
|
3118
|
+
throw new Error(`Unable to determine the type of child at ${JSON.stringify(operation.at)}`);
|
|
2993
3119
|
}, decoratorAddOperationImplementation = ({
|
|
2994
3120
|
context,
|
|
2995
3121
|
operation
|
|
@@ -3421,6 +3547,8 @@ const moveBackwardOperationImplementation = ({
|
|
|
3421
3547
|
"annotation.remove": removeAnnotationOperationImplementation,
|
|
3422
3548
|
"block.set": blockSetOperationImplementation,
|
|
3423
3549
|
"block.unset": blockUnsetOperationImplementation,
|
|
3550
|
+
"child.set": childSetOperationImplementation,
|
|
3551
|
+
"child.unset": childUnsetOperationImplementation,
|
|
3424
3552
|
"decorator.add": decoratorAddOperationImplementation,
|
|
3425
3553
|
"decorator.remove": removeDecoratorOperationImplementation,
|
|
3426
3554
|
delete: deleteOperationImplementation,
|
|
@@ -3469,6 +3597,20 @@ function performOperation({
|
|
|
3469
3597
|
});
|
|
3470
3598
|
break;
|
|
3471
3599
|
}
|
|
3600
|
+
case "child.set": {
|
|
3601
|
+
behaviorOperationImplementations["child.set"]({
|
|
3602
|
+
context,
|
|
3603
|
+
operation
|
|
3604
|
+
});
|
|
3605
|
+
break;
|
|
3606
|
+
}
|
|
3607
|
+
case "child.unset": {
|
|
3608
|
+
behaviorOperationImplementations["child.unset"]({
|
|
3609
|
+
context,
|
|
3610
|
+
operation
|
|
3611
|
+
});
|
|
3612
|
+
break;
|
|
3613
|
+
}
|
|
3472
3614
|
case "decorator.add": {
|
|
3473
3615
|
behaviorOperationImplementations["decorator.add"]({
|
|
3474
3616
|
context,
|
|
@@ -4423,7 +4565,7 @@ function withoutPatching(editor, fn) {
|
|
|
4423
4565
|
function isPatching(editor) {
|
|
4424
4566
|
return PATCHING.get(editor);
|
|
4425
4567
|
}
|
|
4426
|
-
const debug$
|
|
4568
|
+
const debug$c = debugWithName("plugin:withPatches");
|
|
4427
4569
|
function createWithPatches({
|
|
4428
4570
|
editorActor,
|
|
4429
4571
|
relayActor,
|
|
@@ -4448,7 +4590,7 @@ function createWithPatches({
|
|
|
4448
4590
|
withoutPatching(editor, () => {
|
|
4449
4591
|
withoutSaving(editor, () => {
|
|
4450
4592
|
for (const patch of patches) {
|
|
4451
|
-
debug$
|
|
4593
|
+
debug$c.enabled && debug$c(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
4452
4594
|
try {
|
|
4453
4595
|
changed = applyPatch(editor, patch);
|
|
4454
4596
|
} catch (error) {
|
|
@@ -4466,10 +4608,10 @@ function createWithPatches({
|
|
|
4466
4608
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
4467
4609
|
};
|
|
4468
4610
|
return subscriptions.push(() => {
|
|
4469
|
-
debug$
|
|
4611
|
+
debug$c("Subscribing to remote patches");
|
|
4470
4612
|
const sub = editorActor.on("patches", handlePatches);
|
|
4471
4613
|
return () => {
|
|
4472
|
-
debug$
|
|
4614
|
+
debug$c("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
4473
4615
|
};
|
|
4474
4616
|
}), editor.apply = (operation) => {
|
|
4475
4617
|
let patches = [];
|
|
@@ -4517,13 +4659,13 @@ function createWithPatches({
|
|
|
4517
4659
|
origin: "local"
|
|
4518
4660
|
},
|
|
4519
4661
|
operationId: getCurrentOperationId(editor),
|
|
4520
|
-
value:
|
|
4662
|
+
value: editor.value
|
|
4521
4663
|
});
|
|
4522
4664
|
return editor;
|
|
4523
4665
|
}, editor;
|
|
4524
4666
|
};
|
|
4525
4667
|
}
|
|
4526
|
-
const debug$
|
|
4668
|
+
const debug$b = debugWithName("plugin:withPlaceholderBlock");
|
|
4527
4669
|
function createWithPlaceholderBlock(editorActor) {
|
|
4528
4670
|
return function(editor) {
|
|
4529
4671
|
const {
|
|
@@ -4548,7 +4690,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4548
4690
|
const node = op.node;
|
|
4549
4691
|
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
4550
4692
|
const nextPath = Path.next(op.path);
|
|
4551
|
-
editor.children[nextPath[0]] || (debug$
|
|
4693
|
+
editor.children[nextPath[0]] || (debug$b("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
4552
4694
|
decorators: []
|
|
4553
4695
|
})));
|
|
4554
4696
|
}
|
|
@@ -4557,7 +4699,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4557
4699
|
}, editor;
|
|
4558
4700
|
};
|
|
4559
4701
|
}
|
|
4560
|
-
const debug$
|
|
4702
|
+
const debug$a = debugWithName("plugin:withSchemaTypes");
|
|
4561
4703
|
function createWithSchemaTypes({
|
|
4562
4704
|
editorActor
|
|
4563
4705
|
}) {
|
|
@@ -4569,7 +4711,7 @@ function createWithSchemaTypes({
|
|
|
4569
4711
|
return editor.normalizeNode = (entry) => {
|
|
4570
4712
|
const [node, path] = entry;
|
|
4571
4713
|
if (node._type === void 0 && path.length === 2) {
|
|
4572
|
-
debug$
|
|
4714
|
+
debug$a("Setting span type on text node without a type");
|
|
4573
4715
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4574
4716
|
editorActor.send({
|
|
4575
4717
|
type: "normalizing"
|
|
@@ -4585,7 +4727,7 @@ function createWithSchemaTypes({
|
|
|
4585
4727
|
return;
|
|
4586
4728
|
}
|
|
4587
4729
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
4588
|
-
debug$
|
|
4730
|
+
debug$a("Setting missing key on child node without a key");
|
|
4589
4731
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
4590
4732
|
editorActor.send({
|
|
4591
4733
|
type: "normalizing"
|
|
@@ -5070,9 +5212,9 @@ const withPlugins = (editor, options) => {
|
|
|
5070
5212
|
editorActor,
|
|
5071
5213
|
editor: e
|
|
5072
5214
|
}))))))))))));
|
|
5073
|
-
}, debug$
|
|
5215
|
+
}, debug$9 = debugWithName("setup");
|
|
5074
5216
|
function createSlateEditor(config) {
|
|
5075
|
-
debug$
|
|
5217
|
+
debug$9("Creating new Slate editor instance");
|
|
5076
5218
|
const instance = withPlugins(withReact(createEditor()), {
|
|
5077
5219
|
editorActor: config.editorActor,
|
|
5078
5220
|
relayActor: config.relayActor,
|
|
@@ -5087,6 +5229,62 @@ function createSlateEditor(config) {
|
|
|
5087
5229
|
initialValue
|
|
5088
5230
|
};
|
|
5089
5231
|
}
|
|
5232
|
+
function createEditorDom(sendBack, slateEditor) {
|
|
5233
|
+
return {
|
|
5234
|
+
getBlockNodes: (snapshot) => getBlockNodes(slateEditor, snapshot),
|
|
5235
|
+
getChildNodes: (snapshot) => getChildNodes(slateEditor, snapshot),
|
|
5236
|
+
setDragGhost: ({
|
|
5237
|
+
event,
|
|
5238
|
+
ghost
|
|
5239
|
+
}) => setDragGhost({
|
|
5240
|
+
sendBack,
|
|
5241
|
+
event,
|
|
5242
|
+
ghost
|
|
5243
|
+
})
|
|
5244
|
+
};
|
|
5245
|
+
}
|
|
5246
|
+
function getBlockNodes(slateEditor, snapshot) {
|
|
5247
|
+
if (!snapshot.context.selection)
|
|
5248
|
+
return [];
|
|
5249
|
+
const range = toSlateRange(snapshot.context.selection, slateEditor);
|
|
5250
|
+
if (!range)
|
|
5251
|
+
return [];
|
|
5252
|
+
try {
|
|
5253
|
+
return Array.from(Editor.nodes(slateEditor, {
|
|
5254
|
+
at: range,
|
|
5255
|
+
mode: "highest",
|
|
5256
|
+
match: (n) => !Editor.isEditor(n)
|
|
5257
|
+
})).map(([blockNode]) => DOMEditor.toDOMNode(slateEditor, blockNode));
|
|
5258
|
+
} catch {
|
|
5259
|
+
return [];
|
|
5260
|
+
}
|
|
5261
|
+
}
|
|
5262
|
+
function getChildNodes(slateEditor, snapshot) {
|
|
5263
|
+
if (!snapshot.context.selection)
|
|
5264
|
+
return [];
|
|
5265
|
+
const range = toSlateRange(snapshot.context.selection, slateEditor);
|
|
5266
|
+
if (!range)
|
|
5267
|
+
return [];
|
|
5268
|
+
try {
|
|
5269
|
+
return Array.from(Editor.nodes(slateEditor, {
|
|
5270
|
+
at: range,
|
|
5271
|
+
mode: "lowest",
|
|
5272
|
+
match: (n) => !Editor.isEditor(n)
|
|
5273
|
+
})).map(([childNode]) => DOMEditor.toDOMNode(slateEditor, childNode));
|
|
5274
|
+
} catch {
|
|
5275
|
+
return [];
|
|
5276
|
+
}
|
|
5277
|
+
}
|
|
5278
|
+
function setDragGhost({
|
|
5279
|
+
sendBack,
|
|
5280
|
+
event,
|
|
5281
|
+
ghost
|
|
5282
|
+
}) {
|
|
5283
|
+
event.originEvent.dataTransfer.setDragImage(ghost.element, ghost.x, ghost.y), sendBack({
|
|
5284
|
+
type: "set drag ghost",
|
|
5285
|
+
ghost: ghost.element
|
|
5286
|
+
});
|
|
5287
|
+
}
|
|
5090
5288
|
const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
5091
5289
|
on: "annotation.add",
|
|
5092
5290
|
guard: ({
|
|
@@ -6006,52 +6204,55 @@ const coreDndBehaviors = [
|
|
|
6006
6204
|
}, coreBehaviorsConfig = [coreAnnotationBehaviors.addAnnotationOnCollapsedSelection, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject].map((behavior) => ({
|
|
6007
6205
|
behavior,
|
|
6008
6206
|
priority: corePriority
|
|
6009
|
-
}))
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
}
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
}
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
}) {
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6207
|
+
})), abstractAnnotationBehaviors = [defineBehavior({
|
|
6208
|
+
on: "annotation.set",
|
|
6209
|
+
guard: ({
|
|
6210
|
+
snapshot,
|
|
6211
|
+
event
|
|
6212
|
+
}) => {
|
|
6213
|
+
const blockKey = event.at[0]._key, markDefKey = event.at[2]._key, block = getFocusTextBlock({
|
|
6214
|
+
context: {
|
|
6215
|
+
...snapshot.context,
|
|
6216
|
+
selection: {
|
|
6217
|
+
anchor: {
|
|
6218
|
+
path: [{
|
|
6219
|
+
_key: blockKey
|
|
6220
|
+
}],
|
|
6221
|
+
offset: 0
|
|
6222
|
+
},
|
|
6223
|
+
focus: {
|
|
6224
|
+
path: [{
|
|
6225
|
+
_key: blockKey
|
|
6226
|
+
}],
|
|
6227
|
+
offset: 0
|
|
6228
|
+
}
|
|
6229
|
+
}
|
|
6230
|
+
}
|
|
6231
|
+
});
|
|
6232
|
+
if (!block)
|
|
6233
|
+
return !1;
|
|
6234
|
+
const updatedMarkDefs = block.node.markDefs?.map((markDef) => markDef._key === markDefKey ? {
|
|
6235
|
+
...markDef,
|
|
6236
|
+
...event.props
|
|
6237
|
+
} : markDef);
|
|
6238
|
+
return {
|
|
6239
|
+
blockKey,
|
|
6240
|
+
updatedMarkDefs
|
|
6241
|
+
};
|
|
6242
|
+
},
|
|
6243
|
+
actions: [(_, {
|
|
6244
|
+
blockKey,
|
|
6245
|
+
updatedMarkDefs
|
|
6246
|
+
}) => [raise({
|
|
6247
|
+
type: "block.set",
|
|
6248
|
+
at: [{
|
|
6249
|
+
_key: blockKey
|
|
6250
|
+
}],
|
|
6251
|
+
props: {
|
|
6252
|
+
markDefs: updatedMarkDefs
|
|
6253
|
+
}
|
|
6254
|
+
})]]
|
|
6255
|
+
}), defineBehavior({
|
|
6055
6256
|
on: "annotation.toggle",
|
|
6056
6257
|
guard: ({
|
|
6057
6258
|
snapshot,
|
|
@@ -6162,6 +6363,57 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
6162
6363
|
}
|
|
6163
6364
|
}
|
|
6164
6365
|
})]]
|
|
6366
|
+
}), defineBehavior({
|
|
6367
|
+
on: "delete.child",
|
|
6368
|
+
guard: ({
|
|
6369
|
+
snapshot,
|
|
6370
|
+
event
|
|
6371
|
+
}) => {
|
|
6372
|
+
const focusChild = getFocusChild$1({
|
|
6373
|
+
context: {
|
|
6374
|
+
...snapshot.context,
|
|
6375
|
+
selection: {
|
|
6376
|
+
anchor: {
|
|
6377
|
+
path: event.at,
|
|
6378
|
+
offset: 0
|
|
6379
|
+
},
|
|
6380
|
+
focus: {
|
|
6381
|
+
path: event.at,
|
|
6382
|
+
offset: 0
|
|
6383
|
+
}
|
|
6384
|
+
}
|
|
6385
|
+
}
|
|
6386
|
+
});
|
|
6387
|
+
return focusChild ? isSpan(snapshot.context, focusChild.node) ? {
|
|
6388
|
+
selection: {
|
|
6389
|
+
anchor: {
|
|
6390
|
+
path: event.at,
|
|
6391
|
+
offset: 0
|
|
6392
|
+
},
|
|
6393
|
+
focus: {
|
|
6394
|
+
path: event.at,
|
|
6395
|
+
offset: focusChild.node.text.length
|
|
6396
|
+
}
|
|
6397
|
+
}
|
|
6398
|
+
} : {
|
|
6399
|
+
selection: {
|
|
6400
|
+
anchor: {
|
|
6401
|
+
path: event.at,
|
|
6402
|
+
offset: 0
|
|
6403
|
+
},
|
|
6404
|
+
focus: {
|
|
6405
|
+
path: event.at,
|
|
6406
|
+
offset: 0
|
|
6407
|
+
}
|
|
6408
|
+
}
|
|
6409
|
+
} : !1;
|
|
6410
|
+
},
|
|
6411
|
+
actions: [(_, {
|
|
6412
|
+
selection
|
|
6413
|
+
}) => [raise({
|
|
6414
|
+
type: "delete",
|
|
6415
|
+
at: selection
|
|
6416
|
+
})]]
|
|
6165
6417
|
}), defineBehavior({
|
|
6166
6418
|
on: "delete.text",
|
|
6167
6419
|
guard: ({
|
|
@@ -6945,7 +7197,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
6945
7197
|
function isSyntheticBehaviorEvent(event) {
|
|
6946
7198
|
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
6947
7199
|
}
|
|
6948
|
-
const abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.forward", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
7200
|
+
const abstractBehaviorEventTypes = ["annotation.set", "annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.child", "delete.forward", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
6949
7201
|
function isAbstractBehaviorEvent(event) {
|
|
6950
7202
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
6951
7203
|
}
|
|
@@ -6956,7 +7208,7 @@ function isNativeBehaviorEvent(event) {
|
|
|
6956
7208
|
function isCustomBehaviorEvent(event) {
|
|
6957
7209
|
return event.type.startsWith("custom.");
|
|
6958
7210
|
}
|
|
6959
|
-
const debug$
|
|
7211
|
+
const debug$8 = debugWithName("behaviors:event");
|
|
6960
7212
|
function eventCategory(event) {
|
|
6961
7213
|
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "synthetic" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
6962
7214
|
}
|
|
@@ -6972,7 +7224,7 @@ function performEvent({
|
|
|
6972
7224
|
nativeEvent,
|
|
6973
7225
|
sendBack
|
|
6974
7226
|
}) {
|
|
6975
|
-
debug$
|
|
7227
|
+
debug$8(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
6976
7228
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
6977
7229
|
if (behavior.on === "*")
|
|
6978
7230
|
return !0;
|
|
@@ -6981,7 +7233,7 @@ function performEvent({
|
|
|
6981
7233
|
});
|
|
6982
7234
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
6983
7235
|
nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
6984
|
-
debug$
|
|
7236
|
+
debug$8(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
6985
7237
|
context: {
|
|
6986
7238
|
keyGenerator,
|
|
6987
7239
|
schema
|
|
@@ -6991,7 +7243,7 @@ function performEvent({
|
|
|
6991
7243
|
editor
|
|
6992
7244
|
}
|
|
6993
7245
|
});
|
|
6994
|
-
})
|
|
7246
|
+
});
|
|
6995
7247
|
return;
|
|
6996
7248
|
}
|
|
6997
7249
|
const guardSnapshot = getSnapshot();
|
|
@@ -7023,11 +7275,10 @@ function performEvent({
|
|
|
7023
7275
|
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
7024
7276
|
}
|
|
7025
7277
|
if (actions.length !== 0) {
|
|
7026
|
-
if (actions.some((action) => action.type === "execute")) {
|
|
7278
|
+
if (nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward"), actions.some((action) => action.type === "execute")) {
|
|
7027
7279
|
withUndoStep(editor, () => {
|
|
7028
7280
|
for (const action of actions) {
|
|
7029
7281
|
if (action.type === "effect") {
|
|
7030
|
-
nativeEventPrevented = !0;
|
|
7031
7282
|
try {
|
|
7032
7283
|
action.effect();
|
|
7033
7284
|
} catch (error) {
|
|
@@ -7052,7 +7303,7 @@ function performEvent({
|
|
|
7052
7303
|
continue;
|
|
7053
7304
|
}
|
|
7054
7305
|
if (action.type === "raise") {
|
|
7055
|
-
|
|
7306
|
+
performEvent({
|
|
7056
7307
|
mode: "raise",
|
|
7057
7308
|
behaviors,
|
|
7058
7309
|
remainingEventBehaviors: behaviors,
|
|
@@ -7066,7 +7317,7 @@ function performEvent({
|
|
|
7066
7317
|
});
|
|
7067
7318
|
continue;
|
|
7068
7319
|
}
|
|
7069
|
-
|
|
7320
|
+
performEvent({
|
|
7070
7321
|
mode: "execute",
|
|
7071
7322
|
behaviors,
|
|
7072
7323
|
remainingEventBehaviors: isAbstractBehaviorEvent(action.event) ? behaviors : [],
|
|
@@ -7084,7 +7335,6 @@ function performEvent({
|
|
|
7084
7335
|
}
|
|
7085
7336
|
for (const action of actions) {
|
|
7086
7337
|
if (action.type === "effect") {
|
|
7087
|
-
nativeEventPrevented = !0;
|
|
7088
7338
|
try {
|
|
7089
7339
|
action.effect();
|
|
7090
7340
|
} catch (error) {
|
|
@@ -7109,7 +7359,7 @@ function performEvent({
|
|
|
7109
7359
|
continue;
|
|
7110
7360
|
}
|
|
7111
7361
|
if (action.type === "raise") {
|
|
7112
|
-
|
|
7362
|
+
performEvent({
|
|
7113
7363
|
mode: "raise",
|
|
7114
7364
|
behaviors,
|
|
7115
7365
|
remainingEventBehaviors: behaviors,
|
|
@@ -7131,7 +7381,7 @@ function performEvent({
|
|
|
7131
7381
|
}
|
|
7132
7382
|
}
|
|
7133
7383
|
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
7134
|
-
debug$
|
|
7384
|
+
debug$8(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
7135
7385
|
context: {
|
|
7136
7386
|
keyGenerator,
|
|
7137
7387
|
schema
|
|
@@ -7141,7 +7391,7 @@ function performEvent({
|
|
|
7141
7391
|
editor
|
|
7142
7392
|
}
|
|
7143
7393
|
});
|
|
7144
|
-
})
|
|
7394
|
+
})) : nativeEventPrevented && nativeEvent?.preventDefault();
|
|
7145
7395
|
}
|
|
7146
7396
|
function sortByPriority(items) {
|
|
7147
7397
|
if (items.length === 0)
|
|
@@ -7220,7 +7470,7 @@ function createEditorSnapshot({
|
|
|
7220
7470
|
}
|
|
7221
7471
|
};
|
|
7222
7472
|
}
|
|
7223
|
-
const debug$
|
|
7473
|
+
const debug$7 = debugWithName("editor machine"), editorMachine = setup({
|
|
7224
7474
|
types: {
|
|
7225
7475
|
context: {},
|
|
7226
7476
|
events: {},
|
|
@@ -7422,10 +7672,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7422
7672
|
states: {
|
|
7423
7673
|
"determine initial edit mode": {
|
|
7424
7674
|
entry: [() => {
|
|
7425
|
-
debug$
|
|
7675
|
+
debug$7("entry: edit mode->read only->determine initial edit mode");
|
|
7426
7676
|
}],
|
|
7427
7677
|
exit: [() => {
|
|
7428
|
-
debug$
|
|
7678
|
+
debug$7("exit: edit mode->read only->determine initial edit mode");
|
|
7429
7679
|
}],
|
|
7430
7680
|
on: {
|
|
7431
7681
|
"done syncing value": [{
|
|
@@ -7440,10 +7690,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7440
7690
|
},
|
|
7441
7691
|
"read only": {
|
|
7442
7692
|
entry: [() => {
|
|
7443
|
-
debug$
|
|
7693
|
+
debug$7("entry: edit mode->read only->read only");
|
|
7444
7694
|
}],
|
|
7445
7695
|
exit: [() => {
|
|
7446
|
-
debug$
|
|
7696
|
+
debug$7("exit: edit mode->read only->read only");
|
|
7447
7697
|
}],
|
|
7448
7698
|
on: {
|
|
7449
7699
|
"update readOnly": {
|
|
@@ -7485,10 +7735,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7485
7735
|
states: {
|
|
7486
7736
|
idle: {
|
|
7487
7737
|
entry: [() => {
|
|
7488
|
-
debug$
|
|
7738
|
+
debug$7("entry: edit mode->editable->idle");
|
|
7489
7739
|
}],
|
|
7490
7740
|
exit: [() => {
|
|
7491
|
-
debug$
|
|
7741
|
+
debug$7("exit: edit mode->editable-idle");
|
|
7492
7742
|
}],
|
|
7493
7743
|
on: {
|
|
7494
7744
|
dragstart: {
|
|
@@ -7508,10 +7758,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7508
7758
|
states: {
|
|
7509
7759
|
"checking if busy": {
|
|
7510
7760
|
entry: [() => {
|
|
7511
|
-
debug$
|
|
7761
|
+
debug$7("entry: edit mode->editable->focusing->checking if busy");
|
|
7512
7762
|
}],
|
|
7513
7763
|
exit: [() => {
|
|
7514
|
-
debug$
|
|
7764
|
+
debug$7("exit: edit mode->editable->focusing->checking if busy");
|
|
7515
7765
|
}],
|
|
7516
7766
|
always: [{
|
|
7517
7767
|
guard: "slate is busy",
|
|
@@ -7523,10 +7773,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7523
7773
|
},
|
|
7524
7774
|
busy: {
|
|
7525
7775
|
entry: [() => {
|
|
7526
|
-
debug$
|
|
7776
|
+
debug$7("entry: edit mode->editable->focusing-busy");
|
|
7527
7777
|
}],
|
|
7528
7778
|
exit: [() => {
|
|
7529
|
-
debug$
|
|
7779
|
+
debug$7("exit: edit mode->editable->focusing->busy");
|
|
7530
7780
|
}],
|
|
7531
7781
|
after: {
|
|
7532
7782
|
10: {
|
|
@@ -7538,10 +7788,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7538
7788
|
},
|
|
7539
7789
|
"dragging internally": {
|
|
7540
7790
|
entry: [() => {
|
|
7541
|
-
debug$
|
|
7791
|
+
debug$7("entry: edit mode->editable->dragging internally");
|
|
7542
7792
|
}],
|
|
7543
7793
|
exit: [() => {
|
|
7544
|
-
debug$
|
|
7794
|
+
debug$7("exit: edit mode->editable->dragging internally");
|
|
7545
7795
|
}, ({
|
|
7546
7796
|
context
|
|
7547
7797
|
}) => {
|
|
@@ -7575,10 +7825,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7575
7825
|
states: {
|
|
7576
7826
|
"setting up": {
|
|
7577
7827
|
entry: [() => {
|
|
7578
|
-
debug$
|
|
7828
|
+
debug$7("entry: setup->setting up");
|
|
7579
7829
|
}],
|
|
7580
7830
|
exit: [() => {
|
|
7581
|
-
debug$
|
|
7831
|
+
debug$7("exit: setup->setting up");
|
|
7582
7832
|
}, "emit ready", "emit pending incoming patches", "clear pending incoming patches"],
|
|
7583
7833
|
on: {
|
|
7584
7834
|
"internal.patch": {
|
|
@@ -7603,10 +7853,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7603
7853
|
states: {
|
|
7604
7854
|
idle: {
|
|
7605
7855
|
entry: [() => {
|
|
7606
|
-
debug$
|
|
7856
|
+
debug$7("entry: setup->set up->value sync->idle");
|
|
7607
7857
|
}],
|
|
7608
7858
|
exit: [() => {
|
|
7609
|
-
debug$
|
|
7859
|
+
debug$7("exit: setup->set up->value sync->idle");
|
|
7610
7860
|
}],
|
|
7611
7861
|
on: {
|
|
7612
7862
|
patches: {
|
|
@@ -7621,10 +7871,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7621
7871
|
},
|
|
7622
7872
|
"syncing value": {
|
|
7623
7873
|
entry: [() => {
|
|
7624
|
-
debug$
|
|
7874
|
+
debug$7("entry: setup->set up->value sync->syncing value");
|
|
7625
7875
|
}],
|
|
7626
7876
|
exit: [() => {
|
|
7627
|
-
debug$
|
|
7877
|
+
debug$7("exit: setup->set up->value sync->syncing value");
|
|
7628
7878
|
}, "emit pending incoming patches", "clear pending incoming patches"],
|
|
7629
7879
|
on: {
|
|
7630
7880
|
patches: {
|
|
@@ -7645,10 +7895,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7645
7895
|
states: {
|
|
7646
7896
|
idle: {
|
|
7647
7897
|
entry: [() => {
|
|
7648
|
-
debug$
|
|
7898
|
+
debug$7("entry: setup->set up->writing->pristine->idle");
|
|
7649
7899
|
}],
|
|
7650
7900
|
exit: [() => {
|
|
7651
|
-
debug$
|
|
7901
|
+
debug$7("exit: setup->set up->writing->pristine->idle");
|
|
7652
7902
|
}],
|
|
7653
7903
|
on: {
|
|
7654
7904
|
normalizing: {
|
|
@@ -7666,10 +7916,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7666
7916
|
},
|
|
7667
7917
|
normalizing: {
|
|
7668
7918
|
entry: [() => {
|
|
7669
|
-
debug$
|
|
7919
|
+
debug$7("entry: setup->set up->writing->pristine->normalizing");
|
|
7670
7920
|
}],
|
|
7671
7921
|
exit: [() => {
|
|
7672
|
-
debug$
|
|
7922
|
+
debug$7("exit: setup->set up->writing->pristine->normalizing");
|
|
7673
7923
|
}],
|
|
7674
7924
|
on: {
|
|
7675
7925
|
"done normalizing": {
|
|
@@ -7687,10 +7937,10 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
7687
7937
|
},
|
|
7688
7938
|
dirty: {
|
|
7689
7939
|
entry: [() => {
|
|
7690
|
-
debug$
|
|
7940
|
+
debug$7("entry: setup->set up->writing->dirty");
|
|
7691
7941
|
}, "emit pending events", "clear pending events"],
|
|
7692
7942
|
exit: [() => {
|
|
7693
|
-
debug$
|
|
7943
|
+
debug$7("exit: setup->set up->writing->dirty");
|
|
7694
7944
|
}],
|
|
7695
7945
|
on: {
|
|
7696
7946
|
"internal.patch": {
|
|
@@ -7904,7 +8154,7 @@ function compileSchemaDefinitionToLegacySchema(definition) {
|
|
|
7904
8154
|
} : inlineObject)
|
|
7905
8155
|
};
|
|
7906
8156
|
}
|
|
7907
|
-
const debug$
|
|
8157
|
+
const debug$6 = debugWithName("mutation-machine"), mutationMachine = setup({
|
|
7908
8158
|
types: {
|
|
7909
8159
|
context: {},
|
|
7910
8160
|
events: {},
|
|
@@ -8058,10 +8308,10 @@ const debug$7 = debugWithName("mutation-machine"), mutationMachine = setup({
|
|
|
8058
8308
|
states: {
|
|
8059
8309
|
idle: {
|
|
8060
8310
|
entry: [() => {
|
|
8061
|
-
debug$
|
|
8311
|
+
debug$6("entry: typing->idle");
|
|
8062
8312
|
}],
|
|
8063
8313
|
exit: [() => {
|
|
8064
|
-
debug$
|
|
8314
|
+
debug$6("exit: typing->idle"), debug$6("entry: typing->typing");
|
|
8065
8315
|
}],
|
|
8066
8316
|
on: {
|
|
8067
8317
|
typing: {
|
|
@@ -8074,7 +8324,7 @@ const debug$7 = debugWithName("mutation-machine"), mutationMachine = setup({
|
|
|
8074
8324
|
"type debounce": {
|
|
8075
8325
|
target: "idle",
|
|
8076
8326
|
actions: [() => {
|
|
8077
|
-
debug$
|
|
8327
|
+
debug$6("exit: typing->typing");
|
|
8078
8328
|
}]
|
|
8079
8329
|
}
|
|
8080
8330
|
},
|
|
@@ -8095,10 +8345,10 @@ const debug$7 = debugWithName("mutation-machine"), mutationMachine = setup({
|
|
|
8095
8345
|
states: {
|
|
8096
8346
|
idle: {
|
|
8097
8347
|
entry: [() => {
|
|
8098
|
-
debug$
|
|
8348
|
+
debug$6("entry: mutations->idle");
|
|
8099
8349
|
}],
|
|
8100
8350
|
exit: [() => {
|
|
8101
|
-
debug$
|
|
8351
|
+
debug$6("exit: mutations->idle");
|
|
8102
8352
|
}],
|
|
8103
8353
|
on: {
|
|
8104
8354
|
patch: [{
|
|
@@ -8113,10 +8363,10 @@ const debug$7 = debugWithName("mutation-machine"), mutationMachine = setup({
|
|
|
8113
8363
|
},
|
|
8114
8364
|
"has pending mutations": {
|
|
8115
8365
|
entry: [() => {
|
|
8116
|
-
debug$
|
|
8366
|
+
debug$6("entry: mutations->has pending mutations");
|
|
8117
8367
|
}, "emit has pending mutations"],
|
|
8118
8368
|
exit: [() => {
|
|
8119
|
-
debug$
|
|
8369
|
+
debug$6("exit: mutations->has pending mutations");
|
|
8120
8370
|
}],
|
|
8121
8371
|
invoke: {
|
|
8122
8372
|
src: "mutation debouncer"
|
|
@@ -8138,7 +8388,7 @@ const debug$7 = debugWithName("mutation-machine"), mutationMachine = setup({
|
|
|
8138
8388
|
}
|
|
8139
8389
|
}
|
|
8140
8390
|
}
|
|
8141
|
-
}), debug$
|
|
8391
|
+
}), debug$5 = debugWithName("API:editable");
|
|
8142
8392
|
function createEditableAPI(editor, editorActor) {
|
|
8143
8393
|
const types = editorActor.getSnapshot().context.schema;
|
|
8144
8394
|
return {
|
|
@@ -8269,7 +8519,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8269
8519
|
}], {
|
|
8270
8520
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
8271
8521
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode2 = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
|
|
8272
|
-
return isSpanNode2 && focusNode._type !== types.span.name && (debug$
|
|
8522
|
+
return isSpanNode2 && focusNode._type !== types.span.name && (debug$5("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
8273
8523
|
distance: 1,
|
|
8274
8524
|
unit: "character"
|
|
8275
8525
|
})), Transforms.insertNodes(editor, child, {
|
|
@@ -8415,18 +8665,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8415
8665
|
throw new Error("Invalid range");
|
|
8416
8666
|
if (range) {
|
|
8417
8667
|
if (!options?.mode || options?.mode === "selected") {
|
|
8418
|
-
debug$
|
|
8668
|
+
debug$5("Deleting content in selection"), Transforms.delete(editor, {
|
|
8419
8669
|
at: range,
|
|
8420
8670
|
hanging: !0,
|
|
8421
8671
|
voids: !0
|
|
8422
8672
|
}), editor.onChange();
|
|
8423
8673
|
return;
|
|
8424
8674
|
}
|
|
8425
|
-
options?.mode === "blocks" && (debug$
|
|
8675
|
+
options?.mode === "blocks" && (debug$5("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
|
|
8426
8676
|
at: range,
|
|
8427
8677
|
voids: !0,
|
|
8428
8678
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
|
|
8429
|
-
})), options?.mode === "children" && (debug$
|
|
8679
|
+
})), options?.mode === "children" && (debug$5("Deleting children touched by selection"), Transforms.removeNodes(editor, {
|
|
8430
8680
|
at: range,
|
|
8431
8681
|
voids: !0,
|
|
8432
8682
|
match: (node) => node._type === types.span.name || // Text children
|
|
@@ -8864,7 +9114,7 @@ function validateValue(value, types, keyGenerator) {
|
|
|
8864
9114
|
value
|
|
8865
9115
|
});
|
|
8866
9116
|
}
|
|
8867
|
-
const debug$
|
|
9117
|
+
const debug$4 = debugWithName("sync machine"), syncValueCallback = ({
|
|
8868
9118
|
sendBack,
|
|
8869
9119
|
input
|
|
8870
9120
|
}) => {
|
|
@@ -8919,7 +9169,7 @@ const debug$5 = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
8919
9169
|
context
|
|
8920
9170
|
}) => {
|
|
8921
9171
|
const editable = !context.readOnly, isProcessingLocalChanges = context.isProcessingLocalChanges, isChanging = isChangingRemotely(context.slateEditor) ?? !1, isBusy = editable && (isProcessingLocalChanges || isChanging);
|
|
8922
|
-
return debug$
|
|
9172
|
+
return debug$4("isBusy", {
|
|
8923
9173
|
isBusy,
|
|
8924
9174
|
editable,
|
|
8925
9175
|
isProcessingLocalChanges,
|
|
@@ -8987,10 +9237,10 @@ const debug$5 = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
8987
9237
|
states: {
|
|
8988
9238
|
idle: {
|
|
8989
9239
|
entry: [() => {
|
|
8990
|
-
debug$
|
|
9240
|
+
debug$4("entry: syncing->idle");
|
|
8991
9241
|
}],
|
|
8992
9242
|
exit: [() => {
|
|
8993
|
-
debug$
|
|
9243
|
+
debug$4("exit: syncing->idle");
|
|
8994
9244
|
}],
|
|
8995
9245
|
on: {
|
|
8996
9246
|
"update value": [{
|
|
@@ -9013,21 +9263,21 @@ const debug$5 = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
9013
9263
|
}, {
|
|
9014
9264
|
guard: not("initial value synced"),
|
|
9015
9265
|
actions: [() => {
|
|
9016
|
-
debug$
|
|
9266
|
+
debug$4("no new value \u2013 setting initial value as synced");
|
|
9017
9267
|
}, "assign initial value synced", "emit done syncing value"]
|
|
9018
9268
|
}, {
|
|
9019
9269
|
actions: [() => {
|
|
9020
|
-
debug$
|
|
9270
|
+
debug$4("no new value and initial value already synced");
|
|
9021
9271
|
}]
|
|
9022
9272
|
}]
|
|
9023
9273
|
}
|
|
9024
9274
|
},
|
|
9025
9275
|
busy: {
|
|
9026
9276
|
entry: [() => {
|
|
9027
|
-
debug$
|
|
9277
|
+
debug$4("entry: syncing->busy");
|
|
9028
9278
|
}],
|
|
9029
9279
|
exit: [() => {
|
|
9030
|
-
debug$
|
|
9280
|
+
debug$4("exit: syncing->busy");
|
|
9031
9281
|
}],
|
|
9032
9282
|
after: {
|
|
9033
9283
|
1e3: [{
|
|
@@ -9035,7 +9285,7 @@ const debug$5 = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
9035
9285
|
target: ".",
|
|
9036
9286
|
reenter: !0,
|
|
9037
9287
|
actions: [() => {
|
|
9038
|
-
debug$
|
|
9288
|
+
debug$4("reenter: syncing->busy");
|
|
9039
9289
|
}]
|
|
9040
9290
|
}, {
|
|
9041
9291
|
target: "syncing"
|
|
@@ -9050,10 +9300,10 @@ const debug$5 = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
9050
9300
|
},
|
|
9051
9301
|
syncing: {
|
|
9052
9302
|
entry: [() => {
|
|
9053
|
-
debug$
|
|
9303
|
+
debug$4("entry: syncing->syncing");
|
|
9054
9304
|
}, "emit syncing value"],
|
|
9055
9305
|
exit: [() => {
|
|
9056
|
-
debug$
|
|
9306
|
+
debug$4("exit: syncing->syncing");
|
|
9057
9307
|
}, "emit done syncing value"],
|
|
9058
9308
|
invoke: {
|
|
9059
9309
|
src: "sync value",
|
|
@@ -9114,7 +9364,7 @@ async function updateValue({
|
|
|
9114
9364
|
}) {
|
|
9115
9365
|
let doneSyncing = !1, isChanged = !1, isValid = !0;
|
|
9116
9366
|
const hadSelection = !!slateEditor.selection;
|
|
9117
|
-
if ((!value || value.length === 0) && (debug$
|
|
9367
|
+
if ((!value || value.length === 0) && (debug$4("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
|
|
9118
9368
|
withoutSaving(slateEditor, () => {
|
|
9119
9369
|
withRemoteChanges(slateEditor, () => {
|
|
9120
9370
|
withoutPatching(slateEditor, () => {
|
|
@@ -9200,14 +9450,14 @@ async function updateValue({
|
|
|
9200
9450
|
});
|
|
9201
9451
|
}
|
|
9202
9452
|
if (!isValid) {
|
|
9203
|
-
debug$
|
|
9453
|
+
debug$4("Invalid value, returning"), doneSyncing = !0, sendBack({
|
|
9204
9454
|
type: "done syncing",
|
|
9205
9455
|
value
|
|
9206
9456
|
});
|
|
9207
9457
|
return;
|
|
9208
9458
|
}
|
|
9209
9459
|
if (isChanged) {
|
|
9210
|
-
debug$
|
|
9460
|
+
debug$4("Server value changed, syncing editor");
|
|
9211
9461
|
try {
|
|
9212
9462
|
slateEditor.onChange();
|
|
9213
9463
|
} catch (err) {
|
|
@@ -9235,7 +9485,7 @@ async function updateValue({
|
|
|
9235
9485
|
value
|
|
9236
9486
|
});
|
|
9237
9487
|
} else
|
|
9238
|
-
debug$
|
|
9488
|
+
debug$4("Server value and editor value is equal, no need to sync.");
|
|
9239
9489
|
doneSyncing = !0, sendBack({
|
|
9240
9490
|
type: "done syncing",
|
|
9241
9491
|
value
|
|
@@ -9283,7 +9533,7 @@ function syncBlock({
|
|
|
9283
9533
|
type: "patch",
|
|
9284
9534
|
patch
|
|
9285
9535
|
});
|
|
9286
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
9536
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$4.enabled && debug$4("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$4.enabled && debug$4("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
9287
9537
|
type: "invalid value",
|
|
9288
9538
|
resolution: validation.resolution,
|
|
9289
9539
|
value
|
|
@@ -9291,9 +9541,9 @@ function syncBlock({
|
|
|
9291
9541
|
}
|
|
9292
9542
|
if (!oldBlock && blockValid) {
|
|
9293
9543
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
9294
|
-
debug$
|
|
9544
|
+
debug$4.enabled && debug$4("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
9295
9545
|
at: [currentBlockIndex]
|
|
9296
|
-
}) : (debug$
|
|
9546
|
+
}) : (debug$4("Invalid", validation), sendBack({
|
|
9297
9547
|
type: "invalid value",
|
|
9298
9548
|
resolution: validation.resolution,
|
|
9299
9549
|
value
|
|
@@ -9321,14 +9571,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
9321
9571
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
9322
9572
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
9323
9573
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
9324
|
-
childIndex > 0 && (debug$
|
|
9574
|
+
childIndex > 0 && (debug$4("Removing child"), Transforms.removeNodes(slateEditor, {
|
|
9325
9575
|
at: [currentBlockIndex, childIndex]
|
|
9326
9576
|
}));
|
|
9327
9577
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
9328
9578
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
9329
9579
|
if (isChildChanged)
|
|
9330
9580
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
9331
|
-
debug$
|
|
9581
|
+
debug$4("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
9332
9582
|
at: path
|
|
9333
9583
|
});
|
|
9334
9584
|
const isSpanNode2 = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -9345,25 +9595,25 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
9345
9595
|
}
|
|
9346
9596
|
}), Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
9347
9597
|
at: path
|
|
9348
|
-
}), slateEditor.onChange()) : isSpanNode2 || (debug$
|
|
9598
|
+
}), slateEditor.onChange()) : isSpanNode2 || (debug$4("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
|
|
9349
9599
|
_key: VOID_CHILD_KEY
|
|
9350
9600
|
}, {
|
|
9351
9601
|
at: [...path, 0],
|
|
9352
9602
|
voids: !0
|
|
9353
9603
|
}));
|
|
9354
|
-
} else oldBlockChild ? (debug$
|
|
9604
|
+
} else oldBlockChild ? (debug$4("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
|
|
9355
9605
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
9356
9606
|
}), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
9357
9607
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
9358
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
9608
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$4("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
9359
9609
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
9360
9610
|
}), slateEditor.onChange());
|
|
9361
9611
|
});
|
|
9362
9612
|
}
|
|
9363
9613
|
}
|
|
9364
|
-
const debug$
|
|
9614
|
+
const debug$3 = debugWithName("setup");
|
|
9365
9615
|
function createInternalEditor(config) {
|
|
9366
|
-
debug$
|
|
9616
|
+
debug$3("Creating new Editor instance");
|
|
9367
9617
|
const subscriptions = [], editorActor = createActor(editorMachine, {
|
|
9368
9618
|
input: editorConfigToMachineInput(config)
|
|
9369
9619
|
}), relayActor = createActor(relayMachine), slateEditor = createSlateEditor({
|
|
@@ -9378,7 +9628,101 @@ function createInternalEditor(config) {
|
|
|
9378
9628
|
relayActor,
|
|
9379
9629
|
slateEditor: slateEditor.instance,
|
|
9380
9630
|
subscriptions
|
|
9381
|
-
})
|
|
9631
|
+
}), editor = {
|
|
9632
|
+
dom: createEditorDom((event) => editorActor.send(event), slateEditor.instance),
|
|
9633
|
+
getSnapshot: () => getEditorSnapshot({
|
|
9634
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
9635
|
+
slateEditorInstance: slateEditor.instance
|
|
9636
|
+
}),
|
|
9637
|
+
registerBehavior: (behaviorConfig) => {
|
|
9638
|
+
const priority = createEditorPriority({
|
|
9639
|
+
name: "custom",
|
|
9640
|
+
reference: {
|
|
9641
|
+
priority: corePriority,
|
|
9642
|
+
importance: "higher"
|
|
9643
|
+
}
|
|
9644
|
+
}), behaviorConfigWithPriority = {
|
|
9645
|
+
...behaviorConfig,
|
|
9646
|
+
priority
|
|
9647
|
+
};
|
|
9648
|
+
return editorActor.send({
|
|
9649
|
+
type: "add behavior",
|
|
9650
|
+
behaviorConfig: behaviorConfigWithPriority
|
|
9651
|
+
}), () => {
|
|
9652
|
+
editorActor.send({
|
|
9653
|
+
type: "remove behavior",
|
|
9654
|
+
behaviorConfig: behaviorConfigWithPriority
|
|
9655
|
+
});
|
|
9656
|
+
};
|
|
9657
|
+
},
|
|
9658
|
+
send: (event) => {
|
|
9659
|
+
switch (event.type) {
|
|
9660
|
+
case "update value":
|
|
9661
|
+
syncActor.send(event);
|
|
9662
|
+
break;
|
|
9663
|
+
case "update readOnly":
|
|
9664
|
+
case "patches":
|
|
9665
|
+
case "update maxBlocks":
|
|
9666
|
+
editorActor.send(event);
|
|
9667
|
+
break;
|
|
9668
|
+
case "blur":
|
|
9669
|
+
editorActor.send({
|
|
9670
|
+
type: "blur",
|
|
9671
|
+
editor: slateEditor.instance
|
|
9672
|
+
});
|
|
9673
|
+
break;
|
|
9674
|
+
case "focus":
|
|
9675
|
+
editorActor.send({
|
|
9676
|
+
type: "focus",
|
|
9677
|
+
editor: slateEditor.instance
|
|
9678
|
+
});
|
|
9679
|
+
break;
|
|
9680
|
+
case "insert.block object":
|
|
9681
|
+
editorActor.send({
|
|
9682
|
+
type: "behavior event",
|
|
9683
|
+
behaviorEvent: {
|
|
9684
|
+
type: "insert.block",
|
|
9685
|
+
block: {
|
|
9686
|
+
_type: event.blockObject.name,
|
|
9687
|
+
...event.blockObject.value ?? {}
|
|
9688
|
+
},
|
|
9689
|
+
placement: event.placement
|
|
9690
|
+
},
|
|
9691
|
+
editor: slateEditor.instance
|
|
9692
|
+
});
|
|
9693
|
+
break;
|
|
9694
|
+
default:
|
|
9695
|
+
editorActor.send({
|
|
9696
|
+
type: "behavior event",
|
|
9697
|
+
behaviorEvent: event,
|
|
9698
|
+
editor: slateEditor.instance
|
|
9699
|
+
});
|
|
9700
|
+
}
|
|
9701
|
+
},
|
|
9702
|
+
on: (event, listener) => relayActor.on(event, (event2) => {
|
|
9703
|
+
switch (event2.type) {
|
|
9704
|
+
case "blurred":
|
|
9705
|
+
case "done loading":
|
|
9706
|
+
case "editable":
|
|
9707
|
+
case "focused":
|
|
9708
|
+
case "invalid value":
|
|
9709
|
+
case "loading":
|
|
9710
|
+
case "mutation":
|
|
9711
|
+
case "patch":
|
|
9712
|
+
case "read only":
|
|
9713
|
+
case "ready":
|
|
9714
|
+
case "selection":
|
|
9715
|
+
case "value changed":
|
|
9716
|
+
listener(event2);
|
|
9717
|
+
break;
|
|
9718
|
+
}
|
|
9719
|
+
}),
|
|
9720
|
+
_internal: {
|
|
9721
|
+
editable,
|
|
9722
|
+
editorActor,
|
|
9723
|
+
slateEditor
|
|
9724
|
+
}
|
|
9725
|
+
};
|
|
9382
9726
|
return {
|
|
9383
9727
|
actors: {
|
|
9384
9728
|
editorActor,
|
|
@@ -9386,100 +9730,7 @@ function createInternalEditor(config) {
|
|
|
9386
9730
|
relayActor,
|
|
9387
9731
|
syncActor
|
|
9388
9732
|
},
|
|
9389
|
-
editor
|
|
9390
|
-
getSnapshot: () => getEditorSnapshot({
|
|
9391
|
-
editorActorSnapshot: editorActor.getSnapshot(),
|
|
9392
|
-
slateEditorInstance: slateEditor.instance
|
|
9393
|
-
}),
|
|
9394
|
-
registerBehavior: (behaviorConfig) => {
|
|
9395
|
-
const priority = createEditorPriority({
|
|
9396
|
-
name: "custom",
|
|
9397
|
-
reference: {
|
|
9398
|
-
priority: corePriority,
|
|
9399
|
-
importance: "higher"
|
|
9400
|
-
}
|
|
9401
|
-
}), behaviorConfigWithPriority = {
|
|
9402
|
-
...behaviorConfig,
|
|
9403
|
-
priority
|
|
9404
|
-
};
|
|
9405
|
-
return editorActor.send({
|
|
9406
|
-
type: "add behavior",
|
|
9407
|
-
behaviorConfig: behaviorConfigWithPriority
|
|
9408
|
-
}), () => {
|
|
9409
|
-
editorActor.send({
|
|
9410
|
-
type: "remove behavior",
|
|
9411
|
-
behaviorConfig: behaviorConfigWithPriority
|
|
9412
|
-
});
|
|
9413
|
-
};
|
|
9414
|
-
},
|
|
9415
|
-
send: (event) => {
|
|
9416
|
-
switch (event.type) {
|
|
9417
|
-
case "update value":
|
|
9418
|
-
syncActor.send(event);
|
|
9419
|
-
break;
|
|
9420
|
-
case "update readOnly":
|
|
9421
|
-
case "patches":
|
|
9422
|
-
case "update maxBlocks":
|
|
9423
|
-
editorActor.send(event);
|
|
9424
|
-
break;
|
|
9425
|
-
case "blur":
|
|
9426
|
-
editorActor.send({
|
|
9427
|
-
type: "blur",
|
|
9428
|
-
editor: slateEditor.instance
|
|
9429
|
-
});
|
|
9430
|
-
break;
|
|
9431
|
-
case "focus":
|
|
9432
|
-
editorActor.send({
|
|
9433
|
-
type: "focus",
|
|
9434
|
-
editor: slateEditor.instance
|
|
9435
|
-
});
|
|
9436
|
-
break;
|
|
9437
|
-
case "insert.block object":
|
|
9438
|
-
editorActor.send({
|
|
9439
|
-
type: "behavior event",
|
|
9440
|
-
behaviorEvent: {
|
|
9441
|
-
type: "insert.block",
|
|
9442
|
-
block: {
|
|
9443
|
-
_type: event.blockObject.name,
|
|
9444
|
-
...event.blockObject.value ?? {}
|
|
9445
|
-
},
|
|
9446
|
-
placement: event.placement
|
|
9447
|
-
},
|
|
9448
|
-
editor: slateEditor.instance
|
|
9449
|
-
});
|
|
9450
|
-
break;
|
|
9451
|
-
default:
|
|
9452
|
-
editorActor.send({
|
|
9453
|
-
type: "behavior event",
|
|
9454
|
-
behaviorEvent: event,
|
|
9455
|
-
editor: slateEditor.instance
|
|
9456
|
-
});
|
|
9457
|
-
}
|
|
9458
|
-
},
|
|
9459
|
-
on: (event, listener) => relayActor.on(event, (event2) => {
|
|
9460
|
-
switch (event2.type) {
|
|
9461
|
-
case "blurred":
|
|
9462
|
-
case "done loading":
|
|
9463
|
-
case "editable":
|
|
9464
|
-
case "focused":
|
|
9465
|
-
case "invalid value":
|
|
9466
|
-
case "loading":
|
|
9467
|
-
case "mutation":
|
|
9468
|
-
case "patch":
|
|
9469
|
-
case "read only":
|
|
9470
|
-
case "ready":
|
|
9471
|
-
case "selection":
|
|
9472
|
-
case "value changed":
|
|
9473
|
-
listener(event2);
|
|
9474
|
-
break;
|
|
9475
|
-
}
|
|
9476
|
-
}),
|
|
9477
|
-
_internal: {
|
|
9478
|
-
editable,
|
|
9479
|
-
editorActor,
|
|
9480
|
-
slateEditor
|
|
9481
|
-
}
|
|
9482
|
-
},
|
|
9733
|
+
editor,
|
|
9483
9734
|
subscriptions
|
|
9484
9735
|
};
|
|
9485
9736
|
}
|
|
@@ -9506,7 +9757,7 @@ function compileSchemasFromEditorConfig(config) {
|
|
|
9506
9757
|
};
|
|
9507
9758
|
}
|
|
9508
9759
|
function createActors(config) {
|
|
9509
|
-
debug$
|
|
9760
|
+
debug$3("Creating new Actors");
|
|
9510
9761
|
const mutationActor = createActor(mutationMachine, {
|
|
9511
9762
|
input: {
|
|
9512
9763
|
readOnly: config.editorActor.getSnapshot().matches({
|
|
@@ -9612,29 +9863,6 @@ function createActors(config) {
|
|
|
9612
9863
|
syncActor
|
|
9613
9864
|
};
|
|
9614
9865
|
}
|
|
9615
|
-
const PortableTextEditorSelectionContext = createContext(null), usePortableTextEditorSelection = () => {
|
|
9616
|
-
const selection = useContext(PortableTextEditorSelectionContext);
|
|
9617
|
-
if (selection === void 0)
|
|
9618
|
-
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
9619
|
-
return selection;
|
|
9620
|
-
}, debug$3 = debugWithName("component:PortableTextEditor:SelectionProvider");
|
|
9621
|
-
function PortableTextEditorSelectionProvider(props) {
|
|
9622
|
-
const $ = c(6), [selection, setSelection] = useState(null);
|
|
9623
|
-
let t0, t1;
|
|
9624
|
-
$[0] !== props.editorActor ? (t0 = () => {
|
|
9625
|
-
debug$3("Subscribing to selection changes");
|
|
9626
|
-
const subscription = props.editorActor.on("selection", (event) => {
|
|
9627
|
-
startTransition(() => {
|
|
9628
|
-
setSelection(event.selection);
|
|
9629
|
-
});
|
|
9630
|
-
});
|
|
9631
|
-
return () => {
|
|
9632
|
-
debug$3("Unsubscribing to selection changes"), subscription.unsubscribe();
|
|
9633
|
-
};
|
|
9634
|
-
}, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1);
|
|
9635
|
-
let t2;
|
|
9636
|
-
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
9637
|
-
}
|
|
9638
9866
|
const RelayActorContext = createContext({});
|
|
9639
9867
|
function RouteEventsToChanges(props) {
|
|
9640
9868
|
const $ = c(7);
|
|
@@ -9774,7 +10002,7 @@ class PortableTextEditor extends Component {
|
|
|
9774
10002
|
const legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
|
|
9775
10003
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
9776
10004
|
legacyPatches ? /* @__PURE__ */ jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editor._internal.editorActor, patches$: legacyPatches }) : null,
|
|
9777
|
-
/* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsx(RelayActorContext.Provider, { value: this.actors.relayActor, children: /* @__PURE__ */ jsx(Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children:
|
|
10005
|
+
/* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsx(RelayActorContext.Provider, { value: this.actors.relayActor, children: /* @__PURE__ */ jsx(Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children: this.props.children }) }) }) })
|
|
9778
10006
|
] });
|
|
9779
10007
|
}
|
|
9780
10008
|
/**
|
|
@@ -10820,7 +11048,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10820
11048
|
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
10821
11049
|
type: "focused",
|
|
10822
11050
|
event: event_2
|
|
10823
|
-
}), !slateEditor.selection && isEqualToEmptyEditor(slateEditor.children, editorActor.getSnapshot().context.schema) &&
|
|
11051
|
+
}), !slateEditor.selection && isEqualToEmptyEditor(slateEditor.children, editorActor.getSnapshot().context.schema) && Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.selection && slateEditor.onChange());
|
|
10824
11052
|
}, [editorActor, onFocus, relayActor, slateEditor]), handleClick = useCallback((event_3) => {
|
|
10825
11053
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
10826
11054
|
return;
|
|
@@ -11115,7 +11343,7 @@ function useConstant(factory) {
|
|
|
11115
11343
|
}), ref.current.constant;
|
|
11116
11344
|
}
|
|
11117
11345
|
function EditorProvider(props) {
|
|
11118
|
-
const $ = c(
|
|
11346
|
+
const $ = c(32);
|
|
11119
11347
|
let t0;
|
|
11120
11348
|
$[0] !== props.initialConfig ? (t0 = () => {
|
|
11121
11349
|
const internalEditor = createInternalEditor(props.initialConfig), portableTextEditor = new PortableTextEditor({
|
|
@@ -11150,21 +11378,33 @@ function EditorProvider(props) {
|
|
|
11150
11378
|
let t4;
|
|
11151
11379
|
$[12] !== internalEditor_0.actors.relayActor || $[13] !== t3 ? (t4 = /* @__PURE__ */ jsx(RouteEventsToChanges, { relayActor: internalEditor_0.actors.relayActor, onChange: t3 }), $[12] = internalEditor_0.actors.relayActor, $[13] = t3, $[14] = t4) : t4 = $[14];
|
|
11152
11380
|
let t5;
|
|
11153
|
-
$[15] !==
|
|
11381
|
+
$[15] !== portableTextEditor_0 || $[16] !== props.children ? (t5 = /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: portableTextEditor_0, children: props.children }), $[15] = portableTextEditor_0, $[16] = props.children, $[17] = t5) : t5 = $[17];
|
|
11154
11382
|
let t6;
|
|
11155
|
-
$[18] !==
|
|
11383
|
+
$[18] !== internalEditor_0.editor._internal.slateEditor.initialValue || $[19] !== internalEditor_0.editor._internal.slateEditor.instance || $[20] !== t5 ? (t6 = /* @__PURE__ */ jsx(Slate, { editor: internalEditor_0.editor._internal.slateEditor.instance, initialValue: internalEditor_0.editor._internal.slateEditor.initialValue, children: t5 }), $[18] = internalEditor_0.editor._internal.slateEditor.initialValue, $[19] = internalEditor_0.editor._internal.slateEditor.instance, $[20] = t5, $[21] = t6) : t6 = $[21];
|
|
11156
11384
|
let t7;
|
|
11157
|
-
$[
|
|
11385
|
+
$[22] !== internalEditor_0.actors.relayActor || $[23] !== t6 ? (t7 = /* @__PURE__ */ jsx(RelayActorContext.Provider, { value: internalEditor_0.actors.relayActor, children: t6 }), $[22] = internalEditor_0.actors.relayActor, $[23] = t6, $[24] = t7) : t7 = $[24];
|
|
11158
11386
|
let t8;
|
|
11159
|
-
$[25] !== internalEditor_0.actors.
|
|
11387
|
+
$[25] !== internalEditor_0.actors.editorActor || $[26] !== t7 ? (t8 = /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: internalEditor_0.actors.editorActor, children: t7 }), $[25] = internalEditor_0.actors.editorActor, $[26] = t7, $[27] = t8) : t8 = $[27];
|
|
11160
11388
|
let t9;
|
|
11161
|
-
$[28] !== internalEditor_0.
|
|
11162
|
-
let t10;
|
|
11163
|
-
return $[31] !== internalEditor_0.editor || $[32] !== t4 || $[33] !== t9 ? (t10 = /* @__PURE__ */ jsxs(EditorContext.Provider, { value: internalEditor_0.editor, children: [
|
|
11389
|
+
return $[28] !== internalEditor_0.editor || $[29] !== t4 || $[30] !== t8 ? (t9 = /* @__PURE__ */ jsxs(EditorContext.Provider, { value: internalEditor_0.editor, children: [
|
|
11164
11390
|
t4,
|
|
11165
|
-
|
|
11166
|
-
] }), $[
|
|
11391
|
+
t8
|
|
11392
|
+
] }), $[28] = internalEditor_0.editor, $[29] = t4, $[30] = t8, $[31] = t9) : t9 = $[31], t9;
|
|
11167
11393
|
}
|
|
11394
|
+
const usePortableTextEditorSelection = () => {
|
|
11395
|
+
const $ = c(3), editorActor = useContext(EditorActorContext), [selection, setSelection] = useState(null);
|
|
11396
|
+
let t0, t1;
|
|
11397
|
+
return $[0] !== editorActor ? (t0 = () => {
|
|
11398
|
+
const subscription = editorActor.on("selection", (event) => {
|
|
11399
|
+
startTransition(() => {
|
|
11400
|
+
setSelection(event.selection);
|
|
11401
|
+
});
|
|
11402
|
+
});
|
|
11403
|
+
return () => {
|
|
11404
|
+
subscription.unsubscribe();
|
|
11405
|
+
};
|
|
11406
|
+
}, t1 = [editorActor], $[0] = editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1), selection;
|
|
11407
|
+
};
|
|
11168
11408
|
export {
|
|
11169
11409
|
EditorEventListener,
|
|
11170
11410
|
EditorProvider,
|