@portabletext/editor 1.42.0 → 1.43.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/editor-provider.cjs +522 -418
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-active-style.cjs +14 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +2 -2
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +527 -423
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.is-active-style.js +15 -1
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +2 -2
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.d.cts +11 -11
- package/lib/behaviors/index.d.ts +11 -11
- package/lib/index.d.cts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/plugins/index.d.cts +1 -1
- package/lib/plugins/index.d.ts +1 -1
- package/lib/selectors/index.cjs +3 -8
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +1 -1
- package/lib/selectors/index.d.ts +1 -1
- package/lib/selectors/index.js +5 -11
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/package.json +7 -7
- package/src/behavior-actions/behavior.actions.ts +6 -0
- package/src/behaviors/behavior.default.ts +67 -1
- package/src/behaviors/behavior.perform-event.ts +266 -0
- package/src/editor/editor-machine.ts +31 -254
- package/src/editor/with-applying-behavior-actions.ts +13 -4
- package/src/internal-utils/parse-blocks.ts +14 -0
- package/src/plugins/plugin.markdown.test.tsx +64 -0
- package/src/selectors/selector.get-active-annotations.test.ts +28 -0
- package/src/selectors/selector.get-active-annotations.ts +15 -2
|
@@ -3,9 +3,9 @@ import { c } from "react-compiler-runtime";
|
|
|
3
3
|
import React, { createContext, useContext, useEffect, useState, startTransition, Component } from "react";
|
|
4
4
|
import { ReactEditor, withReact, Slate } from "slate-react";
|
|
5
5
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
6
|
-
import debug$
|
|
6
|
+
import debug$g from "debug";
|
|
7
7
|
import isEqual from "lodash/isEqual.js";
|
|
8
|
-
import { Editor, Element,
|
|
8
|
+
import { Editor, Element, Point, Range, Text, Node, Path, Operation, Transforms, insertText, createEditor } from "slate";
|
|
9
9
|
import { setup, stateIn, fromCallback, assign, enqueueActions, emit, assertEvent, and, not, createActor } from "xstate";
|
|
10
10
|
import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
|
|
11
11
|
import { defineType, defineField, isKeySegment, isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock } from "@sanity/types";
|
|
@@ -14,16 +14,16 @@ import isPlainObject from "lodash/isPlainObject.js";
|
|
|
14
14
|
import uniq from "lodash/uniq.js";
|
|
15
15
|
import getRandomValues from "get-random-values-esm";
|
|
16
16
|
import { parseBlock, selectionPointToBlockOffset, blockOffsetsToSelection, isTextBlock, parseBlocks } from "./util.selection-point-to-block-offset.js";
|
|
17
|
-
import { sliceBlocks, blockOffsetToSpanSelectionPoint, isKeyedSegment as isKeyedSegment$1 } from "./util.slice-blocks.js";
|
|
17
|
+
import { sliceBlocks, blockOffsetToSpanSelectionPoint, isKeyedSegment as isKeyedSegment$1, getTextBlockText } from "./util.slice-blocks.js";
|
|
18
18
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
19
19
|
import { toHTML } from "@portabletext/to-html";
|
|
20
20
|
import { Schema } from "@sanity/schema";
|
|
21
21
|
import get from "lodash/get.js";
|
|
22
22
|
import isUndefined from "lodash/isUndefined.js";
|
|
23
23
|
import omitBy from "lodash/omitBy.js";
|
|
24
|
-
import { createGuards, getFocusSpan, isSelectionCollapsed, isOverlappingSelection, getSelectedBlocks, isSelectionExpanded } from "./selector.is-overlapping-selection.js";
|
|
25
|
-
import { getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isSelectingEntireBlocks } from "./selector.is-active-style.js";
|
|
26
24
|
import omit from "lodash/omit.js";
|
|
25
|
+
import { createGuards, getFocusSpan, isSelectionCollapsed, isOverlappingSelection, getSelectedBlocks, getFocusTextBlock, isSelectionExpanded } from "./selector.is-overlapping-selection.js";
|
|
26
|
+
import { getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isSelectingEntireBlocks, getActiveAnnotations } from "./selector.is-active-style.js";
|
|
27
27
|
import { DOMEditor } from "slate-dom";
|
|
28
28
|
import startCase from "lodash.startcase";
|
|
29
29
|
import { defineBehavior, raise, coreBehaviors } from "./behavior.core.js";
|
|
@@ -144,10 +144,10 @@ function compileSchemaDefinition(definition) {
|
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
const rootName = "sanity-pte:";
|
|
147
|
-
debug$
|
|
147
|
+
debug$g(rootName);
|
|
148
148
|
function debugWithName(name) {
|
|
149
149
|
const namespace = `${rootName}${name}`;
|
|
150
|
-
return debug$
|
|
150
|
+
return debug$g && debug$g.enabled(namespace) ? debug$g(namespace) : debug$g(rootName);
|
|
151
151
|
}
|
|
152
152
|
function createKeyedPath(point, value, types) {
|
|
153
153
|
const blockPath = [point.path[0]];
|
|
@@ -1615,14 +1615,18 @@ function isApplyingBehaviorActions(editor) {
|
|
|
1615
1615
|
const CURRENT_BEHAVIOR_ACTION_SET = /* @__PURE__ */ new WeakMap();
|
|
1616
1616
|
function withApplyingBehaviorActionSet(editor, fn) {
|
|
1617
1617
|
const current = CURRENT_BEHAVIOR_ACTION_SET.get(editor);
|
|
1618
|
-
|
|
1618
|
+
if (current) {
|
|
1619
|
+
withApplyingBehaviorActions(editor, fn);
|
|
1620
|
+
return;
|
|
1621
|
+
}
|
|
1622
|
+
CURRENT_BEHAVIOR_ACTION_SET.set(editor, current ?? {
|
|
1619
1623
|
actionSetId: defaultKeyGenerator()
|
|
1620
|
-
}), withApplyingBehaviorActions(editor, fn), CURRENT_BEHAVIOR_ACTION_SET.set(editor,
|
|
1624
|
+
}), withApplyingBehaviorActions(editor, fn), CURRENT_BEHAVIOR_ACTION_SET.set(editor, void 0);
|
|
1621
1625
|
}
|
|
1622
1626
|
function getCurrentBehaviorActionSetId(editor) {
|
|
1623
1627
|
return CURRENT_BEHAVIOR_ACTION_SET.get(editor)?.actionSetId;
|
|
1624
1628
|
}
|
|
1625
|
-
const debug$
|
|
1629
|
+
const debug$f = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
1626
1630
|
const state = SAVING.get(editor);
|
|
1627
1631
|
return state === void 0 ? !0 : state;
|
|
1628
1632
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -1636,7 +1640,7 @@ function createWithUndoRedo(options) {
|
|
|
1636
1640
|
const remotePatches = getRemotePatches(editor);
|
|
1637
1641
|
let previousBehaviorActionSetId = getCurrentBehaviorActionSetId(editor);
|
|
1638
1642
|
options.subscriptions.push(() => {
|
|
1639
|
-
debug$
|
|
1643
|
+
debug$f("Subscribing to patches");
|
|
1640
1644
|
const sub = editorActor.on("patches", ({
|
|
1641
1645
|
patches,
|
|
1642
1646
|
snapshot
|
|
@@ -1645,7 +1649,7 @@ function createWithUndoRedo(options) {
|
|
|
1645
1649
|
patches.forEach((patch) => {
|
|
1646
1650
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
1647
1651
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
1648
|
-
debug$
|
|
1652
|
+
debug$f("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
1649
1653
|
undos: [],
|
|
1650
1654
|
redos: []
|
|
1651
1655
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -1661,7 +1665,7 @@ function createWithUndoRedo(options) {
|
|
|
1661
1665
|
}), previousSnapshot = snapshot;
|
|
1662
1666
|
});
|
|
1663
1667
|
return () => {
|
|
1664
|
-
debug$
|
|
1668
|
+
debug$f("Unsubscribing to patches"), sub.unsubscribe();
|
|
1665
1669
|
};
|
|
1666
1670
|
}), editor.history = {
|
|
1667
1671
|
undos: [],
|
|
@@ -1700,7 +1704,7 @@ function createWithUndoRedo(options) {
|
|
|
1700
1704
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
1701
1705
|
timestamp: /* @__PURE__ */ new Date()
|
|
1702
1706
|
};
|
|
1703
|
-
undos.push(newStep), debug$
|
|
1707
|
+
undos.push(newStep), debug$f("Created new undo step", step);
|
|
1704
1708
|
}
|
|
1705
1709
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
1706
1710
|
undos.shift();
|
|
@@ -1718,7 +1722,7 @@ const historyUndoActionImplementation = ({
|
|
|
1718
1722
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
1719
1723
|
if (undos.length > 0) {
|
|
1720
1724
|
const step = undos[undos.length - 1];
|
|
1721
|
-
if (debug$
|
|
1725
|
+
if (debug$f("Undoing", step), step.operations.length > 0) {
|
|
1722
1726
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
1723
1727
|
let transformedOperations = step.operations;
|
|
1724
1728
|
otherPatches.forEach((item) => {
|
|
@@ -1736,7 +1740,7 @@ const historyUndoActionImplementation = ({
|
|
|
1736
1740
|
});
|
|
1737
1741
|
});
|
|
1738
1742
|
} catch (err) {
|
|
1739
|
-
debug$
|
|
1743
|
+
debug$f("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
1740
1744
|
undos: [],
|
|
1741
1745
|
redos: []
|
|
1742
1746
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -1753,7 +1757,7 @@ const historyUndoActionImplementation = ({
|
|
|
1753
1757
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
1754
1758
|
if (redos.length > 0) {
|
|
1755
1759
|
const step = redos[redos.length - 1];
|
|
1756
|
-
if (debug$
|
|
1760
|
+
if (debug$f("Redoing", step), step.operations.length > 0) {
|
|
1757
1761
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
1758
1762
|
let transformedOperations = step.operations;
|
|
1759
1763
|
otherPatches.forEach((item) => {
|
|
@@ -1770,7 +1774,7 @@ const historyUndoActionImplementation = ({
|
|
|
1770
1774
|
});
|
|
1771
1775
|
});
|
|
1772
1776
|
} catch (err) {
|
|
1773
|
-
debug$
|
|
1777
|
+
debug$f("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
1774
1778
|
undos: [],
|
|
1775
1779
|
redos: []
|
|
1776
1780
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -1788,16 +1792,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
1788
1792
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
1789
1793
|
_key: blk._key
|
|
1790
1794
|
}, patch.path[0]));
|
|
1791
|
-
return debug$
|
|
1795
|
+
return debug$f(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
1792
1796
|
}
|
|
1793
1797
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
1794
1798
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
|
|
1795
1799
|
_key: blk._key
|
|
1796
1800
|
}, patch.path[0]));
|
|
1797
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
1801
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$f("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
1798
1802
|
}
|
|
1799
1803
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
1800
|
-
return debug$
|
|
1804
|
+
return debug$f(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
1801
1805
|
if (patch.type === "diffMatchPatch") {
|
|
1802
1806
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
1803
1807
|
return !operationTargetBlock || !isEqual({
|
|
@@ -1884,7 +1888,7 @@ function findOperationTargetBlock(editor, operation) {
|
|
|
1884
1888
|
let block;
|
|
1885
1889
|
return operation.type === "set_selection" && editor.selection ? block = editor.children[editor.selection.focus.path[0]] : "path" in operation && (block = editor.children[operation.path[0]]), block;
|
|
1886
1890
|
}
|
|
1887
|
-
const debug$
|
|
1891
|
+
const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
1888
1892
|
sendBack,
|
|
1889
1893
|
input
|
|
1890
1894
|
}) => {
|
|
@@ -1936,7 +1940,7 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1936
1940
|
context
|
|
1937
1941
|
}) => {
|
|
1938
1942
|
const editable = !context.readOnly, isProcessingLocalChanges = context.isProcessingLocalChanges, isChanging = isChangingRemotely(context.slateEditor) ?? !1, isBusy = editable && (isProcessingLocalChanges || isChanging);
|
|
1939
|
-
return debug$
|
|
1943
|
+
return debug$e("isBusy", {
|
|
1940
1944
|
isBusy,
|
|
1941
1945
|
editable,
|
|
1942
1946
|
isProcessingLocalChanges,
|
|
@@ -1990,10 +1994,10 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1990
1994
|
states: {
|
|
1991
1995
|
"syncing initial value": {
|
|
1992
1996
|
entry: [() => {
|
|
1993
|
-
debug$
|
|
1997
|
+
debug$e("entry: syncing initial value");
|
|
1994
1998
|
}],
|
|
1995
1999
|
exit: [() => {
|
|
1996
|
-
debug$
|
|
2000
|
+
debug$e("exit: syncing initial value");
|
|
1997
2001
|
}],
|
|
1998
2002
|
always: {
|
|
1999
2003
|
guard: "initial value synced",
|
|
@@ -2002,10 +2006,10 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
2002
2006
|
},
|
|
2003
2007
|
"done syncing initial value": {
|
|
2004
2008
|
entry: ["emit done syncing initial value", () => {
|
|
2005
|
-
debug$
|
|
2009
|
+
debug$e("entry: done syncing initial value");
|
|
2006
2010
|
}],
|
|
2007
2011
|
exit: [() => {
|
|
2008
|
-
debug$
|
|
2012
|
+
debug$e("exit: done syncing initial value");
|
|
2009
2013
|
}],
|
|
2010
2014
|
type: "final"
|
|
2011
2015
|
}
|
|
@@ -2016,10 +2020,10 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
2016
2020
|
states: {
|
|
2017
2021
|
idle: {
|
|
2018
2022
|
entry: [() => {
|
|
2019
|
-
debug$
|
|
2023
|
+
debug$e("entry: syncing->idle");
|
|
2020
2024
|
}],
|
|
2021
2025
|
exit: [() => {
|
|
2022
|
-
debug$
|
|
2026
|
+
debug$e("exit: syncing->idle");
|
|
2023
2027
|
}],
|
|
2024
2028
|
on: {
|
|
2025
2029
|
"update value": [{
|
|
@@ -2034,10 +2038,10 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
2034
2038
|
},
|
|
2035
2039
|
busy: {
|
|
2036
2040
|
entry: [() => {
|
|
2037
|
-
debug$
|
|
2041
|
+
debug$e("entry: syncing->busy");
|
|
2038
2042
|
}],
|
|
2039
2043
|
exit: [() => {
|
|
2040
|
-
debug$
|
|
2044
|
+
debug$e("exit: syncing->busy");
|
|
2041
2045
|
}],
|
|
2042
2046
|
after: {
|
|
2043
2047
|
1e3: [{
|
|
@@ -2045,7 +2049,7 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
2045
2049
|
target: ".",
|
|
2046
2050
|
reenter: !0,
|
|
2047
2051
|
actions: [() => {
|
|
2048
|
-
debug$
|
|
2052
|
+
debug$e("reenter: syncing->busy");
|
|
2049
2053
|
}]
|
|
2050
2054
|
}, {
|
|
2051
2055
|
target: "syncing"
|
|
@@ -2059,10 +2063,10 @@ const debug$c = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
2059
2063
|
},
|
|
2060
2064
|
syncing: {
|
|
2061
2065
|
entry: [() => {
|
|
2062
|
-
debug$
|
|
2066
|
+
debug$e("entry: syncing->syncing");
|
|
2063
2067
|
}],
|
|
2064
2068
|
exit: [() => {
|
|
2065
|
-
debug$
|
|
2069
|
+
debug$e("exit: syncing->syncing");
|
|
2066
2070
|
}],
|
|
2067
2071
|
always: {
|
|
2068
2072
|
guard: "pending value equals previous value",
|
|
@@ -2129,7 +2133,7 @@ async function updateValue({
|
|
|
2129
2133
|
}) {
|
|
2130
2134
|
let isChanged = !1, isValid = !0;
|
|
2131
2135
|
const hadSelection = !!slateEditor.selection;
|
|
2132
|
-
if ((!value || value.length === 0) && (debug$
|
|
2136
|
+
if ((!value || value.length === 0) && (debug$e("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
|
|
2133
2137
|
withoutSaving(slateEditor, () => {
|
|
2134
2138
|
withoutPatching(slateEditor, () => {
|
|
2135
2139
|
hadSelection && Transforms.deselect(slateEditor);
|
|
@@ -2185,14 +2189,14 @@ async function updateValue({
|
|
|
2185
2189
|
});
|
|
2186
2190
|
}
|
|
2187
2191
|
if (!isValid) {
|
|
2188
|
-
debug$
|
|
2192
|
+
debug$e("Invalid value, returning"), sendBack({
|
|
2189
2193
|
type: "done syncing",
|
|
2190
2194
|
value
|
|
2191
2195
|
});
|
|
2192
2196
|
return;
|
|
2193
2197
|
}
|
|
2194
2198
|
if (isChanged) {
|
|
2195
|
-
debug$
|
|
2199
|
+
debug$e("Server value changed, syncing editor");
|
|
2196
2200
|
try {
|
|
2197
2201
|
slateEditor.onChange();
|
|
2198
2202
|
} catch (err) {
|
|
@@ -2220,7 +2224,7 @@ async function updateValue({
|
|
|
2220
2224
|
value
|
|
2221
2225
|
});
|
|
2222
2226
|
} else
|
|
2223
|
-
debug$
|
|
2227
|
+
debug$e("Server value and editor value is equal, no need to sync.");
|
|
2224
2228
|
sendBack({
|
|
2225
2229
|
type: "done syncing",
|
|
2226
2230
|
value
|
|
@@ -2254,7 +2258,7 @@ function syncBlock({
|
|
|
2254
2258
|
type: "patch",
|
|
2255
2259
|
patch
|
|
2256
2260
|
});
|
|
2257
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
2261
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$e.enabled && debug$e("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$e.enabled && debug$e("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
2258
2262
|
type: "invalid value",
|
|
2259
2263
|
resolution: validation.resolution,
|
|
2260
2264
|
value
|
|
@@ -2262,9 +2266,9 @@ function syncBlock({
|
|
|
2262
2266
|
}
|
|
2263
2267
|
if (!oldBlock && blockValid) {
|
|
2264
2268
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2265
|
-
debug$
|
|
2269
|
+
debug$e.enabled && debug$e("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2266
2270
|
at: [currentBlockIndex]
|
|
2267
|
-
}) : (debug$
|
|
2271
|
+
}) : (debug$e("Invalid", validation), sendBack({
|
|
2268
2272
|
type: "invalid value",
|
|
2269
2273
|
resolution: validation.resolution,
|
|
2270
2274
|
value
|
|
@@ -2292,14 +2296,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2292
2296
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
2293
2297
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
2294
2298
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
2295
|
-
childIndex > 0 && (debug$
|
|
2299
|
+
childIndex > 0 && (debug$e("Removing child"), Transforms.removeNodes(slateEditor, {
|
|
2296
2300
|
at: [currentBlockIndex, childIndex]
|
|
2297
2301
|
}));
|
|
2298
2302
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
2299
2303
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2300
2304
|
if (isChildChanged)
|
|
2301
2305
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2302
|
-
debug$
|
|
2306
|
+
debug$e("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2303
2307
|
at: path
|
|
2304
2308
|
});
|
|
2305
2309
|
const isSpanNode = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -2316,23 +2320,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2316
2320
|
}
|
|
2317
2321
|
}), Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
2318
2322
|
at: path
|
|
2319
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
2323
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$e("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
|
|
2320
2324
|
_key: VOID_CHILD_KEY
|
|
2321
2325
|
}, {
|
|
2322
2326
|
at: [...path, 0],
|
|
2323
2327
|
voids: !0
|
|
2324
2328
|
}));
|
|
2325
|
-
} else oldBlockChild ? (debug$
|
|
2329
|
+
} else oldBlockChild ? (debug$e("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
|
|
2326
2330
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2327
2331
|
}), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2328
2332
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2329
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
2333
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$e("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2330
2334
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2331
2335
|
}), slateEditor.onChange());
|
|
2332
2336
|
});
|
|
2333
2337
|
}
|
|
2334
2338
|
}
|
|
2335
|
-
const debug$
|
|
2339
|
+
const debug$d = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
2336
2340
|
function Synchronizer(props) {
|
|
2337
2341
|
const $ = c(41), {
|
|
2338
2342
|
editorActor,
|
|
@@ -2428,14 +2432,14 @@ function Synchronizer(props) {
|
|
|
2428
2432
|
}, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), useEffect(t11, t12);
|
|
2429
2433
|
let t13, t14;
|
|
2430
2434
|
$[30] !== syncActorRef || $[31] !== value ? (t13 = () => {
|
|
2431
|
-
debug$
|
|
2435
|
+
debug$d("Value from props changed, syncing new value"), syncActorRef.send({
|
|
2432
2436
|
type: "update value",
|
|
2433
2437
|
value
|
|
2434
2438
|
});
|
|
2435
2439
|
}, t14 = [syncActorRef, value], $[30] = syncActorRef, $[31] = value, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), useEffect(t13, t14);
|
|
2436
2440
|
let t15;
|
|
2437
2441
|
$[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
|
|
2438
|
-
debug$
|
|
2442
|
+
debug$d("Subscribing to patch events");
|
|
2439
2443
|
const sub = editorActor.on("internal.patch", (event_1) => {
|
|
2440
2444
|
mutationActorRef.send({
|
|
2441
2445
|
...event_1,
|
|
@@ -2443,7 +2447,7 @@ function Synchronizer(props) {
|
|
|
2443
2447
|
});
|
|
2444
2448
|
});
|
|
2445
2449
|
return () => {
|
|
2446
|
-
debug$
|
|
2450
|
+
debug$d("Unsubscribing to patch events"), sub.unsubscribe();
|
|
2447
2451
|
};
|
|
2448
2452
|
}, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
|
|
2449
2453
|
let t16;
|
|
@@ -2670,11 +2674,11 @@ const converterJson = {
|
|
|
2670
2674
|
function escapeHtml(str) {
|
|
2671
2675
|
return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
|
|
2672
2676
|
}
|
|
2673
|
-
const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$
|
|
2677
|
+
const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$c = debugWithName("operationToPatches");
|
|
2674
2678
|
function createOperationToPatches(types) {
|
|
2675
2679
|
const textBlockName = types.block.name;
|
|
2676
2680
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
2677
|
-
debug$
|
|
2681
|
+
debug$c.enabled && debug$c("Operation", JSON.stringify(operation, null, 2));
|
|
2678
2682
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
2679
2683
|
if (!block)
|
|
2680
2684
|
throw new Error("Could not find block");
|
|
@@ -2767,7 +2771,7 @@ function createOperationToPatches(types) {
|
|
|
2767
2771
|
_key: block.children[operation.path[1] - 1]._key
|
|
2768
2772
|
}])];
|
|
2769
2773
|
}
|
|
2770
|
-
return debug$
|
|
2774
|
+
return debug$c("Something was inserted into a void block. Not producing editor patches."), [];
|
|
2771
2775
|
}
|
|
2772
2776
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
2773
2777
|
const patches = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -2825,9 +2829,9 @@ function createOperationToPatches(types) {
|
|
|
2825
2829
|
_key: block._key
|
|
2826
2830
|
}, "children", {
|
|
2827
2831
|
_key: spanToRemove._key
|
|
2828
|
-
}])] : (debug$
|
|
2832
|
+
}])] : (debug$c("Span not found in editor trying to remove node"), []);
|
|
2829
2833
|
} else
|
|
2830
|
-
return debug$
|
|
2834
|
+
return debug$c("Not creating patch inside object block"), [];
|
|
2831
2835
|
}
|
|
2832
2836
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2833
2837
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -2853,7 +2857,7 @@ function createOperationToPatches(types) {
|
|
|
2853
2857
|
_key: removedSpan._key
|
|
2854
2858
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
2855
2859
|
} else
|
|
2856
|
-
debug$
|
|
2860
|
+
debug$c("Void nodes can't be merged, not creating any patches");
|
|
2857
2861
|
return patches;
|
|
2858
2862
|
}
|
|
2859
2863
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -3234,7 +3238,7 @@ function getNextSpan({
|
|
|
3234
3238
|
}
|
|
3235
3239
|
return nextSpan;
|
|
3236
3240
|
}
|
|
3237
|
-
const debug$
|
|
3241
|
+
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
3238
3242
|
function createWithPortableTextMarkModel(editorActor, types) {
|
|
3239
3243
|
return function(editor) {
|
|
3240
3244
|
const {
|
|
@@ -3248,7 +3252,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3248
3252
|
for (const [child, childPath] of children) {
|
|
3249
3253
|
const nextNode = node.children[childPath[1] + 1];
|
|
3250
3254
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3251
|
-
debug$
|
|
3255
|
+
debug$b("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3252
3256
|
type: "normalizing"
|
|
3253
3257
|
}), Transforms.mergeNodes(editor, {
|
|
3254
3258
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -3261,7 +3265,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3261
3265
|
}
|
|
3262
3266
|
}
|
|
3263
3267
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3264
|
-
debug$
|
|
3268
|
+
debug$b("Adding .markDefs to block node"), editorActor.send({
|
|
3265
3269
|
type: "normalizing"
|
|
3266
3270
|
}), Transforms.setNodes(editor, {
|
|
3267
3271
|
markDefs: []
|
|
@@ -3273,7 +3277,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3273
3277
|
return;
|
|
3274
3278
|
}
|
|
3275
3279
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3276
|
-
debug$
|
|
3280
|
+
debug$b("Adding .marks to span node"), editorActor.send({
|
|
3277
3281
|
type: "normalizing"
|
|
3278
3282
|
}), Transforms.setNodes(editor, {
|
|
3279
3283
|
marks: []
|
|
@@ -3287,7 +3291,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3287
3291
|
if (editor.isTextSpan(node)) {
|
|
3288
3292
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3289
3293
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3290
|
-
debug$
|
|
3294
|
+
debug$b("Removing annotations from empty span node"), editorActor.send({
|
|
3291
3295
|
type: "normalizing"
|
|
3292
3296
|
}), Transforms.setNodes(editor, {
|
|
3293
3297
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -3305,7 +3309,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3305
3309
|
if (editor.isTextSpan(child)) {
|
|
3306
3310
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3307
3311
|
if (orphanedAnnotations.length > 0) {
|
|
3308
|
-
debug$
|
|
3312
|
+
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
3309
3313
|
type: "normalizing"
|
|
3310
3314
|
}), Transforms.setNodes(editor, {
|
|
3311
3315
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3323,7 +3327,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3323
3327
|
if (editor.isTextBlock(block)) {
|
|
3324
3328
|
const decorators2 = types.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3325
3329
|
if (orphanedAnnotations.length > 0) {
|
|
3326
|
-
debug$
|
|
3330
|
+
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
3327
3331
|
type: "normalizing"
|
|
3328
3332
|
}), Transforms.setNodes(editor, {
|
|
3329
3333
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3341,7 +3345,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3341
3345
|
for (const markDef of markDefs)
|
|
3342
3346
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3343
3347
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3344
|
-
debug$
|
|
3348
|
+
debug$b("Removing duplicate markDefs"), editorActor.send({
|
|
3345
3349
|
type: "normalizing"
|
|
3346
3350
|
}), Transforms.setNodes(editor, {
|
|
3347
3351
|
markDefs: newMarkDefs
|
|
@@ -3356,7 +3360,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3356
3360
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3357
3361
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3358
3362
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
3359
|
-
debug$
|
|
3363
|
+
debug$b("Removing markDef not in use"), editorActor.send({
|
|
3360
3364
|
type: "normalizing"
|
|
3361
3365
|
}), Transforms.setNodes(editor, {
|
|
3362
3366
|
markDefs: newMarkDefs
|
|
@@ -3576,7 +3580,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3576
3580
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
3577
3581
|
if (editor.isTextBlock(targetBlock)) {
|
|
3578
3582
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
3579
|
-
debug$
|
|
3583
|
+
debug$b("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
3580
3584
|
markDefs: newMarkDefs
|
|
3581
3585
|
}, {
|
|
3582
3586
|
at: targetPath,
|
|
@@ -3681,7 +3685,7 @@ const toggleDecoratorActionImplementation = ({
|
|
|
3681
3685
|
...action
|
|
3682
3686
|
}
|
|
3683
3687
|
});
|
|
3684
|
-
}, debug$
|
|
3688
|
+
}, debug$a = debugWithName("API:editable");
|
|
3685
3689
|
function createEditableAPI(editor, editorActor) {
|
|
3686
3690
|
const types = editorActor.getSnapshot().context.schema;
|
|
3687
3691
|
return {
|
|
@@ -3816,7 +3820,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
3816
3820
|
}], {
|
|
3817
3821
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
3818
3822
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
|
|
3819
|
-
return isSpanNode && focusNode._type !== types.span.name && (debug$
|
|
3823
|
+
return isSpanNode && focusNode._type !== types.span.name && (debug$a("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
3820
3824
|
distance: 1,
|
|
3821
3825
|
unit: "character"
|
|
3822
3826
|
})), Transforms.insertNodes(editor, child, {
|
|
@@ -3953,18 +3957,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
3953
3957
|
throw new Error("Invalid range");
|
|
3954
3958
|
if (range) {
|
|
3955
3959
|
if (!options?.mode || options?.mode === "selected") {
|
|
3956
|
-
debug$
|
|
3960
|
+
debug$a("Deleting content in selection"), Transforms.delete(editor, {
|
|
3957
3961
|
at: range,
|
|
3958
3962
|
hanging: !0,
|
|
3959
3963
|
voids: !0
|
|
3960
3964
|
}), editor.onChange();
|
|
3961
3965
|
return;
|
|
3962
3966
|
}
|
|
3963
|
-
options?.mode === "blocks" && (debug$
|
|
3967
|
+
options?.mode === "blocks" && (debug$a("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
|
|
3964
3968
|
at: range,
|
|
3965
3969
|
voids: !0,
|
|
3966
3970
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element.isElement(node)
|
|
3967
|
-
})), options?.mode === "children" && (debug$
|
|
3971
|
+
})), options?.mode === "children" && (debug$a("Deleting children touched by selection"), Transforms.removeNodes(editor, {
|
|
3968
3972
|
at: range,
|
|
3969
3973
|
voids: !0,
|
|
3970
3974
|
match: (node) => node._type === types.span.name || // Text children
|
|
@@ -4091,7 +4095,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4091
4095
|
action
|
|
4092
4096
|
}) => {
|
|
4093
4097
|
const editor = action.editor;
|
|
4094
|
-
if (debug$
|
|
4098
|
+
if (debug$a("Removing annotation", action.annotation.name), !!editor.selection)
|
|
4095
4099
|
if (Range.isCollapsed(editor.selection)) {
|
|
4096
4100
|
const [block, blockPath] = Editor.node(editor, editor.selection, {
|
|
4097
4101
|
depth: 1
|
|
@@ -4837,7 +4841,7 @@ const selectActionImplementation = ({
|
|
|
4837
4841
|
mimeType: action.mimeType
|
|
4838
4842
|
}
|
|
4839
4843
|
});
|
|
4840
|
-
}, behaviorActionImplementations = {
|
|
4844
|
+
}, debug$9 = debugWithName("behaviors:action"), behaviorActionImplementations = {
|
|
4841
4845
|
"annotation.add": addAnnotationActionImplementation,
|
|
4842
4846
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
4843
4847
|
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
@@ -4886,7 +4890,7 @@ function performAction({
|
|
|
4886
4890
|
context,
|
|
4887
4891
|
action
|
|
4888
4892
|
}) {
|
|
4889
|
-
switch (action.type) {
|
|
4893
|
+
switch (debug$9(JSON.stringify(omit(action, ["editor"]), null, 2)), action.type) {
|
|
4890
4894
|
case "annotation.add": {
|
|
4891
4895
|
behaviorActionImplementations["annotation.add"]({
|
|
4892
4896
|
context,
|
|
@@ -5498,13 +5502,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
5498
5502
|
}, editor;
|
|
5499
5503
|
};
|
|
5500
5504
|
}
|
|
5501
|
-
const debug$
|
|
5505
|
+
const debug$8 = debugWithName("applyPatches"), debugVerbose = debug$8.enabled && !0;
|
|
5502
5506
|
function createApplyPatch(schemaTypes) {
|
|
5503
5507
|
return (editor, patch) => {
|
|
5504
5508
|
let changed = !1;
|
|
5505
|
-
debugVerbose && (debug$
|
|
5509
|
+
debugVerbose && (debug$8(`
|
|
5506
5510
|
|
|
5507
|
-
NEW PATCH =============================================================`), debug$
|
|
5511
|
+
NEW PATCH =============================================================`), debug$8(JSON.stringify(patch, null, 2)));
|
|
5508
5512
|
try {
|
|
5509
5513
|
switch (patch.type) {
|
|
5510
5514
|
case "insert":
|
|
@@ -5520,7 +5524,7 @@ NEW PATCH =============================================================`), debug
|
|
|
5520
5524
|
changed = diffMatchPatch(editor, patch);
|
|
5521
5525
|
break;
|
|
5522
5526
|
default:
|
|
5523
|
-
debug$
|
|
5527
|
+
debug$8("Unhandled patch", patch.type);
|
|
5524
5528
|
}
|
|
5525
5529
|
} catch (err) {
|
|
5526
5530
|
console.error(err);
|
|
@@ -5535,9 +5539,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
5535
5539
|
childPath
|
|
5536
5540
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5537
5541
|
if (!block)
|
|
5538
|
-
return debug$
|
|
5542
|
+
return debug$8("Block not found"), !1;
|
|
5539
5543
|
if (!child || !childPath)
|
|
5540
|
-
return debug$
|
|
5544
|
+
return debug$8("Child not found"), !1;
|
|
5541
5545
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !Text.isText(child))
|
|
5542
5546
|
return !1;
|
|
5543
5547
|
const patches = parse(patch.value), [newValue] = apply(patches, child.text, {
|
|
@@ -5567,9 +5571,9 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
5567
5571
|
childPath: targetChildPath
|
|
5568
5572
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5569
5573
|
if (!targetBlock || !targetBlockPath)
|
|
5570
|
-
return debug$
|
|
5574
|
+
return debug$8("Block not found"), !1;
|
|
5571
5575
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
5572
|
-
return debug$
|
|
5576
|
+
return debug$8("Ignoring patch targeting void value"), !1;
|
|
5573
5577
|
if (patch.path.length === 1) {
|
|
5574
5578
|
const {
|
|
5575
5579
|
items: items2,
|
|
@@ -5577,7 +5581,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
5577
5581
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
5578
5582
|
schemaTypes
|
|
5579
5583
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
5580
|
-
return debug$
|
|
5584
|
+
return debug$8(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
|
|
5581
5585
|
at: [normalizedIdx2]
|
|
5582
5586
|
}), debugState(editor, "after"), !0;
|
|
5583
5587
|
}
|
|
@@ -5586,14 +5590,14 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
5586
5590
|
position
|
|
5587
5591
|
} = patch;
|
|
5588
5592
|
if (!targetChild || !targetChildPath)
|
|
5589
|
-
return debug$
|
|
5593
|
+
return debug$8("Child not found"), !1;
|
|
5590
5594
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
5591
5595
|
...targetBlock,
|
|
5592
5596
|
children: items
|
|
5593
5597
|
}], {
|
|
5594
5598
|
schemaTypes
|
|
5595
5599
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
5596
|
-
return debug$
|
|
5600
|
+
return debug$8(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
5597
5601
|
at: childInsertPath
|
|
5598
5602
|
}), debugState(editor, "after"), !0;
|
|
5599
5603
|
}
|
|
@@ -5607,14 +5611,14 @@ function setPatch(editor, patch) {
|
|
|
5607
5611
|
childPath
|
|
5608
5612
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5609
5613
|
if (!block)
|
|
5610
|
-
return debug$
|
|
5614
|
+
return debug$8("Block not found"), !1;
|
|
5611
5615
|
const isTextBlock2 = editor.isTextBlock(block);
|
|
5612
5616
|
if (isTextBlock2 && patch.path.length > 1 && patch.path[1] !== "children")
|
|
5613
|
-
return debug$
|
|
5617
|
+
return debug$8("Ignoring setting void value"), !1;
|
|
5614
5618
|
if (debugState(editor, "before"), isTextBlock2 && child && childPath) {
|
|
5615
5619
|
if (Text.isText(value) && Text.isText(child)) {
|
|
5616
5620
|
const newText = child.text;
|
|
5617
|
-
value.text !== newText && (debug$
|
|
5621
|
+
value.text !== newText && (debug$8("Setting text property"), editor.apply({
|
|
5618
5622
|
type: "remove_text",
|
|
5619
5623
|
path: childPath,
|
|
5620
5624
|
offset: 0,
|
|
@@ -5626,7 +5630,7 @@ function setPatch(editor, patch) {
|
|
|
5626
5630
|
text: value.text
|
|
5627
5631
|
}), editor.onChange());
|
|
5628
5632
|
} else
|
|
5629
|
-
debug$
|
|
5633
|
+
debug$8("Setting non-text property"), editor.apply({
|
|
5630
5634
|
type: "set_node",
|
|
5631
5635
|
path: childPath,
|
|
5632
5636
|
properties: {},
|
|
@@ -5634,7 +5638,7 @@ function setPatch(editor, patch) {
|
|
|
5634
5638
|
});
|
|
5635
5639
|
return !0;
|
|
5636
5640
|
} else if (Element.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
5637
|
-
debug$
|
|
5641
|
+
debug$8("Setting block property");
|
|
5638
5642
|
const {
|
|
5639
5643
|
children,
|
|
5640
5644
|
...nextRest
|
|
@@ -5651,7 +5655,7 @@ function setPatch(editor, patch) {
|
|
|
5651
5655
|
...prevRest
|
|
5652
5656
|
},
|
|
5653
5657
|
newProperties: nextRest
|
|
5654
|
-
}), debug$
|
|
5658
|
+
}), debug$8("Setting children"), block.children.forEach((c2, cIndex) => {
|
|
5655
5659
|
editor.apply({
|
|
5656
5660
|
type: "remove_node",
|
|
5657
5661
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -5682,7 +5686,7 @@ function setPatch(editor, patch) {
|
|
|
5682
5686
|
}
|
|
5683
5687
|
function unsetPatch(editor, patch) {
|
|
5684
5688
|
if (patch.path.length === 0) {
|
|
5685
|
-
debug$
|
|
5689
|
+
debug$8("Removing everything"), debugState(editor, "before");
|
|
5686
5690
|
const previousSelection = editor.selection;
|
|
5687
5691
|
return Transforms.deselect(editor), editor.children.forEach((_child, i) => {
|
|
5688
5692
|
Transforms.removeNodes(editor, {
|
|
@@ -5709,13 +5713,13 @@ function unsetPatch(editor, patch) {
|
|
|
5709
5713
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5710
5714
|
if (patch.path.length === 1) {
|
|
5711
5715
|
if (!block || !blockPath)
|
|
5712
|
-
return debug$
|
|
5716
|
+
return debug$8("Block not found"), !1;
|
|
5713
5717
|
const blockIndex = blockPath[0];
|
|
5714
|
-
return debug$
|
|
5718
|
+
return debug$8(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
|
|
5715
5719
|
at: [blockIndex]
|
|
5716
5720
|
}), debugState(editor, "after"), !0;
|
|
5717
5721
|
}
|
|
5718
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
5722
|
+
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$8("Child not found"), !1) : (debug$8(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$8(`Removing child at path ${JSON.stringify(childPath)}`), Transforms.removeNodes(editor, {
|
|
5719
5723
|
at: childPath
|
|
5720
5724
|
}), debugState(editor, "after"), !0) : !1;
|
|
5721
5725
|
}
|
|
@@ -5723,7 +5727,7 @@ function isKeyedSegment(segment) {
|
|
|
5723
5727
|
return typeof segment == "object" && "_key" in segment;
|
|
5724
5728
|
}
|
|
5725
5729
|
function debugState(editor, stateName) {
|
|
5726
|
-
debugVerbose && (debug$
|
|
5730
|
+
debugVerbose && (debug$8(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$8(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
5727
5731
|
}
|
|
5728
5732
|
function findBlockFromPath(editor, path) {
|
|
5729
5733
|
let blockIndex = -1;
|
|
@@ -5765,7 +5769,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
5765
5769
|
childPath: void 0
|
|
5766
5770
|
};
|
|
5767
5771
|
}
|
|
5768
|
-
const debug$
|
|
5772
|
+
const debug$7 = debugWithName("plugin:withPatches");
|
|
5769
5773
|
function createWithPatches({
|
|
5770
5774
|
editorActor,
|
|
5771
5775
|
patchFunctions,
|
|
@@ -5791,7 +5795,7 @@ function createWithPatches({
|
|
|
5791
5795
|
withoutPatching(editor, () => {
|
|
5792
5796
|
withoutSaving(editor, () => {
|
|
5793
5797
|
patches.forEach((patch) => {
|
|
5794
|
-
debug$
|
|
5798
|
+
debug$7.enabled && debug$7(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
5795
5799
|
});
|
|
5796
5800
|
});
|
|
5797
5801
|
});
|
|
@@ -5804,10 +5808,10 @@ function createWithPatches({
|
|
|
5804
5808
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
5805
5809
|
};
|
|
5806
5810
|
return subscriptions.push(() => {
|
|
5807
|
-
debug$
|
|
5811
|
+
debug$7("Subscribing to remote patches");
|
|
5808
5812
|
const sub = editorActor.on("patches", handlePatches);
|
|
5809
5813
|
return () => {
|
|
5810
|
-
debug$
|
|
5814
|
+
debug$7("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
5811
5815
|
};
|
|
5812
5816
|
}), editor.apply = (operation) => {
|
|
5813
5817
|
let patches = [];
|
|
@@ -5861,7 +5865,7 @@ function createWithPatches({
|
|
|
5861
5865
|
}, editor;
|
|
5862
5866
|
};
|
|
5863
5867
|
}
|
|
5864
|
-
const debug$
|
|
5868
|
+
const debug$6 = debugWithName("plugin:withPlaceholderBlock");
|
|
5865
5869
|
function createWithPlaceholderBlock(editorActor) {
|
|
5866
5870
|
return function(editor) {
|
|
5867
5871
|
const {
|
|
@@ -5886,7 +5890,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
5886
5890
|
const node = op.node;
|
|
5887
5891
|
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
5888
5892
|
const nextPath = Path.next(op.path);
|
|
5889
|
-
editor.children[nextPath[0]] || (debug$
|
|
5893
|
+
editor.children[nextPath[0]] || (debug$6("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
5890
5894
|
decorators: []
|
|
5891
5895
|
})));
|
|
5892
5896
|
}
|
|
@@ -5895,7 +5899,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
5895
5899
|
}, editor;
|
|
5896
5900
|
};
|
|
5897
5901
|
}
|
|
5898
|
-
const debug$
|
|
5902
|
+
const debug$5 = debugWithName("plugin:withPortableTextBlockStyle");
|
|
5899
5903
|
function createWithPortableTextBlockStyle(editorActor, types) {
|
|
5900
5904
|
const defaultStyle = types.styles[0].value;
|
|
5901
5905
|
return function(editor) {
|
|
@@ -5908,7 +5912,7 @@ function createWithPortableTextBlockStyle(editorActor, types) {
|
|
|
5908
5912
|
if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !Path.equals(path, op.path)) {
|
|
5909
5913
|
const [child] = Editor.node(editor, [op.path[0] + 1, 0]);
|
|
5910
5914
|
if (Text.isText(child) && child.text === "") {
|
|
5911
|
-
debug$
|
|
5915
|
+
debug$5(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
5912
5916
|
type: "normalizing"
|
|
5913
5917
|
}), Transforms.setNodes(editor, {
|
|
5914
5918
|
style: defaultStyle
|
|
@@ -5960,7 +5964,7 @@ function createWithPortableTextSelections(editorActor, types) {
|
|
|
5960
5964
|
}, editor;
|
|
5961
5965
|
};
|
|
5962
5966
|
}
|
|
5963
|
-
const debug$
|
|
5967
|
+
const debug$4 = debugWithName("plugin:withSchemaTypes");
|
|
5964
5968
|
function createWithSchemaTypes({
|
|
5965
5969
|
editorActor,
|
|
5966
5970
|
schemaTypes
|
|
@@ -5973,7 +5977,7 @@ function createWithSchemaTypes({
|
|
|
5973
5977
|
return editor.normalizeNode = (entry) => {
|
|
5974
5978
|
const [node, path] = entry;
|
|
5975
5979
|
if (node._type === void 0 && path.length === 2) {
|
|
5976
|
-
debug$
|
|
5980
|
+
debug$4("Setting span type on text node without a type");
|
|
5977
5981
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
5978
5982
|
editorActor.send({
|
|
5979
5983
|
type: "normalizing"
|
|
@@ -5989,7 +5993,7 @@ function createWithSchemaTypes({
|
|
|
5989
5993
|
return;
|
|
5990
5994
|
}
|
|
5991
5995
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
5992
|
-
debug$
|
|
5996
|
+
debug$4("Setting missing key on child node without a key");
|
|
5993
5997
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
5994
5998
|
editorActor.send({
|
|
5995
5999
|
type: "normalizing"
|
|
@@ -6055,12 +6059,12 @@ const withPlugins = (editor, options) => {
|
|
|
6055
6059
|
schemaTypes
|
|
6056
6060
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
|
|
6057
6061
|
return createWithEventListeners(editorActor, options.subscriptions)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
6058
|
-
}, debug$
|
|
6062
|
+
}, debug$3 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
6059
6063
|
function createSlateEditor(config) {
|
|
6060
6064
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
6061
6065
|
if (existingSlateEditor)
|
|
6062
|
-
return debug$
|
|
6063
|
-
debug$
|
|
6066
|
+
return debug$3("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
|
|
6067
|
+
debug$3("Creating new Slate editor instance", config.editorActor.id);
|
|
6064
6068
|
const unsubscriptions = [], subscriptions = [], instance = withPlugins(withReact(createEditor()), {
|
|
6065
6069
|
editorActor: config.editorActor,
|
|
6066
6070
|
subscriptions
|
|
@@ -6245,195 +6249,273 @@ const keyIs = {
|
|
|
6245
6249
|
...serializeEvent,
|
|
6246
6250
|
originEvent: event.originEvent
|
|
6247
6251
|
}))]
|
|
6248
|
-
}), defaultBehaviors = [
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
}
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
|
|
6296
|
-
}),
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6300
|
-
})
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
})
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
}),
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
})
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
}
|
|
6367
|
-
|
|
6368
|
-
|
|
6252
|
+
}), defaultBehaviors = [
|
|
6253
|
+
defineBehavior({
|
|
6254
|
+
on: "clipboard.copy",
|
|
6255
|
+
guard: ({
|
|
6256
|
+
snapshot
|
|
6257
|
+
}) => {
|
|
6258
|
+
const focusSpan = getFocusSpan(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6259
|
+
return focusSpan && selectionCollapsed;
|
|
6260
|
+
},
|
|
6261
|
+
actions: [() => [{
|
|
6262
|
+
type: "noop"
|
|
6263
|
+
}]]
|
|
6264
|
+
}),
|
|
6265
|
+
defineBehavior({
|
|
6266
|
+
on: "clipboard.copy",
|
|
6267
|
+
actions: [({
|
|
6268
|
+
event
|
|
6269
|
+
}) => [raise({
|
|
6270
|
+
type: "serialize",
|
|
6271
|
+
originEvent: event
|
|
6272
|
+
})]]
|
|
6273
|
+
}),
|
|
6274
|
+
defineBehavior({
|
|
6275
|
+
on: "clipboard.cut",
|
|
6276
|
+
guard: ({
|
|
6277
|
+
snapshot
|
|
6278
|
+
}) => {
|
|
6279
|
+
const focusSpan = getFocusSpan(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6280
|
+
return focusSpan && selectionCollapsed;
|
|
6281
|
+
},
|
|
6282
|
+
actions: [() => [{
|
|
6283
|
+
type: "noop"
|
|
6284
|
+
}]]
|
|
6285
|
+
}),
|
|
6286
|
+
defineBehavior({
|
|
6287
|
+
on: "clipboard.cut",
|
|
6288
|
+
guard: ({
|
|
6289
|
+
snapshot
|
|
6290
|
+
}) => snapshot.context.selection ? {
|
|
6291
|
+
selection: snapshot.context.selection
|
|
6292
|
+
} : !1,
|
|
6293
|
+
actions: [({
|
|
6294
|
+
event
|
|
6295
|
+
}, {
|
|
6296
|
+
selection
|
|
6297
|
+
}) => [raise({
|
|
6298
|
+
type: "serialize",
|
|
6299
|
+
originEvent: event
|
|
6300
|
+
}), raise({
|
|
6301
|
+
type: "delete",
|
|
6302
|
+
selection
|
|
6303
|
+
})]]
|
|
6304
|
+
}),
|
|
6305
|
+
defineBehavior({
|
|
6306
|
+
on: "drag.dragstart",
|
|
6307
|
+
actions: [({
|
|
6308
|
+
event
|
|
6309
|
+
}) => [raise({
|
|
6310
|
+
type: "serialize",
|
|
6311
|
+
originEvent: event
|
|
6312
|
+
})]]
|
|
6313
|
+
}),
|
|
6314
|
+
defineBehavior({
|
|
6315
|
+
on: "serialization.success",
|
|
6316
|
+
actions: [({
|
|
6317
|
+
event
|
|
6318
|
+
}) => [raise({
|
|
6319
|
+
type: "data transfer.set",
|
|
6320
|
+
data: event.data,
|
|
6321
|
+
dataTransfer: event.originEvent.originEvent.dataTransfer,
|
|
6322
|
+
mimeType: event.mimeType
|
|
6323
|
+
})]]
|
|
6324
|
+
}),
|
|
6325
|
+
defineBehavior({
|
|
6326
|
+
on: "drag.drop",
|
|
6327
|
+
guard: ({
|
|
6328
|
+
snapshot,
|
|
6329
|
+
event
|
|
6330
|
+
}) => {
|
|
6331
|
+
const dragOrigin = snapshot.beta.internalDrag?.origin, dropPosition = event.position.selection;
|
|
6332
|
+
return dragOrigin ? isOverlappingSelection(dropPosition)({
|
|
6333
|
+
...snapshot,
|
|
6334
|
+
context: {
|
|
6335
|
+
...snapshot.context,
|
|
6336
|
+
selection: dragOrigin.selection
|
|
6337
|
+
}
|
|
6338
|
+
}) : !1;
|
|
6339
|
+
},
|
|
6340
|
+
actions: [() => [{
|
|
6341
|
+
type: "noop"
|
|
6342
|
+
}]]
|
|
6343
|
+
}),
|
|
6344
|
+
defineBehavior({
|
|
6345
|
+
on: "drag.drop",
|
|
6346
|
+
actions: [({
|
|
6347
|
+
event
|
|
6348
|
+
}) => [raise({
|
|
6349
|
+
type: "select",
|
|
6350
|
+
selection: event.position.selection
|
|
6351
|
+
}), raise({
|
|
6352
|
+
type: "deserialize",
|
|
6353
|
+
originEvent: event
|
|
6354
|
+
})]]
|
|
6355
|
+
}),
|
|
6356
|
+
defineBehavior({
|
|
6357
|
+
on: "deserialization.success",
|
|
6358
|
+
guard: ({
|
|
6359
|
+
snapshot,
|
|
6360
|
+
event
|
|
6361
|
+
}) => {
|
|
6362
|
+
if (event.originEvent.type !== "drag.drop" || snapshot.beta.internalDrag === void 0)
|
|
6363
|
+
return !1;
|
|
6364
|
+
const dragOrigin = snapshot.beta.internalDrag.origin, dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? isOverlappingSelection(dropPosition)({
|
|
6365
|
+
...snapshot,
|
|
6366
|
+
context: {
|
|
6367
|
+
...snapshot.context,
|
|
6368
|
+
selection: dragOrigin.selection
|
|
6369
|
+
}
|
|
6370
|
+
}) : !1, draggingEntireBlocks = isSelectingEntireBlocks({
|
|
6371
|
+
context: {
|
|
6372
|
+
...snapshot.context,
|
|
6373
|
+
selection: dragOrigin.selection
|
|
6374
|
+
}
|
|
6375
|
+
}), draggedBlocks = getSelectedBlocks({
|
|
6376
|
+
context: {
|
|
6377
|
+
...snapshot.context,
|
|
6378
|
+
selection: dragOrigin.selection
|
|
6379
|
+
}
|
|
6380
|
+
});
|
|
6381
|
+
return droppingOnDragOrigin ? !1 : {
|
|
6382
|
+
draggingEntireBlocks,
|
|
6383
|
+
draggedBlocks,
|
|
6384
|
+
dragOrigin,
|
|
6385
|
+
originEvent: event.originEvent
|
|
6386
|
+
};
|
|
6387
|
+
},
|
|
6388
|
+
actions: [({
|
|
6389
|
+
event
|
|
6390
|
+
}, {
|
|
6369
6391
|
draggingEntireBlocks,
|
|
6370
6392
|
draggedBlocks,
|
|
6371
6393
|
dragOrigin,
|
|
6372
|
-
originEvent
|
|
6373
|
-
}
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
}
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
})
|
|
6394
|
+
originEvent
|
|
6395
|
+
}) => [...draggingEntireBlocks ? draggedBlocks.map((block) => raise({
|
|
6396
|
+
type: "delete.block",
|
|
6397
|
+
at: block.path
|
|
6398
|
+
})) : [raise({
|
|
6399
|
+
type: "delete",
|
|
6400
|
+
selection: dragOrigin.selection
|
|
6401
|
+
})], raise({
|
|
6402
|
+
type: "insert.blocks",
|
|
6403
|
+
blocks: event.data,
|
|
6404
|
+
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
6405
|
+
})]]
|
|
6406
|
+
}),
|
|
6407
|
+
/**
|
|
6408
|
+
* If we are pasting text/plain into a text block then we can probably
|
|
6409
|
+
* assume that the intended behavior is that the pasted text inherits
|
|
6410
|
+
* formatting from the text it's pasted into.
|
|
6411
|
+
*/
|
|
6412
|
+
defineBehavior({
|
|
6413
|
+
on: "deserialization.success",
|
|
6414
|
+
guard: ({
|
|
6415
|
+
snapshot,
|
|
6416
|
+
event
|
|
6417
|
+
}) => {
|
|
6418
|
+
if (getFocusTextBlock(snapshot) && event.mimeType === "text/plain" && event.originEvent.type === "clipboard.paste") {
|
|
6419
|
+
const activeDecorators = snapshot.context.activeDecorators;
|
|
6420
|
+
return {
|
|
6421
|
+
activeAnnotations: getActiveAnnotations(snapshot),
|
|
6422
|
+
activeDecorators,
|
|
6423
|
+
textRuns: event.data.flatMap((block) => isTextBlock(snapshot.context.schema, block) ? [getTextBlockText(block)] : [])
|
|
6424
|
+
};
|
|
6425
|
+
}
|
|
6426
|
+
return !1;
|
|
6427
|
+
},
|
|
6428
|
+
actions: [(_, {
|
|
6429
|
+
activeAnnotations,
|
|
6430
|
+
activeDecorators,
|
|
6431
|
+
textRuns
|
|
6432
|
+
}) => textRuns.flatMap((textRun, index) => index !== textRuns.length - 1 ? [raise({
|
|
6433
|
+
type: "insert.span",
|
|
6434
|
+
text: textRun,
|
|
6435
|
+
decorators: activeDecorators,
|
|
6436
|
+
annotations: activeAnnotations.map(({
|
|
6437
|
+
_key,
|
|
6438
|
+
_type,
|
|
6439
|
+
...value
|
|
6440
|
+
}) => ({
|
|
6441
|
+
name: _type,
|
|
6442
|
+
value
|
|
6443
|
+
}))
|
|
6444
|
+
}), raise({
|
|
6445
|
+
type: "insert.break"
|
|
6446
|
+
})] : [raise({
|
|
6447
|
+
type: "insert.span",
|
|
6448
|
+
text: textRun,
|
|
6449
|
+
decorators: activeDecorators,
|
|
6450
|
+
annotations: activeAnnotations.map(({
|
|
6451
|
+
_key,
|
|
6452
|
+
_type,
|
|
6453
|
+
...value
|
|
6454
|
+
}) => ({
|
|
6455
|
+
name: _type,
|
|
6456
|
+
value
|
|
6457
|
+
}))
|
|
6458
|
+
})])]
|
|
6459
|
+
}),
|
|
6460
|
+
defineBehavior({
|
|
6461
|
+
on: "deserialization.success",
|
|
6462
|
+
actions: [({
|
|
6463
|
+
event
|
|
6464
|
+
}) => [raise({
|
|
6465
|
+
type: "insert.blocks",
|
|
6466
|
+
blocks: event.data,
|
|
6467
|
+
placement: "auto"
|
|
6468
|
+
})]]
|
|
6469
|
+
}),
|
|
6470
|
+
defineBehavior({
|
|
6471
|
+
on: "clipboard.paste",
|
|
6472
|
+
guard: ({
|
|
6473
|
+
snapshot
|
|
6474
|
+
}) => snapshot.context.selection && isSelectionExpanded(snapshot) ? {
|
|
6475
|
+
selection: snapshot.context.selection
|
|
6476
|
+
} : !1,
|
|
6477
|
+
actions: [({
|
|
6478
|
+
event
|
|
6479
|
+
}, {
|
|
6480
|
+
selection
|
|
6481
|
+
}) => [raise({
|
|
6482
|
+
type: "delete",
|
|
6483
|
+
selection
|
|
6484
|
+
}), raise({
|
|
6485
|
+
type: "deserialize",
|
|
6486
|
+
originEvent: event
|
|
6487
|
+
})]]
|
|
6488
|
+
}),
|
|
6489
|
+
defineBehavior({
|
|
6490
|
+
on: "clipboard.paste",
|
|
6491
|
+
actions: [({
|
|
6492
|
+
event
|
|
6493
|
+
}) => [raise({
|
|
6494
|
+
type: "deserialize",
|
|
6495
|
+
originEvent: event
|
|
6496
|
+
})]]
|
|
6497
|
+
}),
|
|
6498
|
+
defineBehavior({
|
|
6499
|
+
on: "input.*",
|
|
6500
|
+
actions: [({
|
|
6501
|
+
event
|
|
6502
|
+
}) => [raise({
|
|
6503
|
+
type: "deserialize",
|
|
6504
|
+
originEvent: event
|
|
6505
|
+
})]]
|
|
6506
|
+
}),
|
|
6507
|
+
toggleAnnotationOff,
|
|
6508
|
+
toggleAnnotationOn,
|
|
6509
|
+
toggleDecoratorOff,
|
|
6510
|
+
toggleDecoratorOn,
|
|
6511
|
+
toggleListItemOff,
|
|
6512
|
+
toggleListItemOn,
|
|
6513
|
+
toggleStyleOff,
|
|
6514
|
+
toggleStyleOn,
|
|
6515
|
+
raiseDeserializationSuccessOrFailure,
|
|
6516
|
+
raiseSerializationSuccessOrFailure,
|
|
6517
|
+
raiseInsertSoftBreak
|
|
6518
|
+
];
|
|
6437
6519
|
function isKeyboardBehaviorEvent(event) {
|
|
6438
6520
|
return event.type.startsWith("keyboard.");
|
|
6439
6521
|
}
|
|
@@ -6452,6 +6534,137 @@ function isMouseBehaviorEvent(event) {
|
|
|
6452
6534
|
function isCustomBehaviorEvent(event) {
|
|
6453
6535
|
return event.type.startsWith("custom.");
|
|
6454
6536
|
}
|
|
6537
|
+
const debug$2 = debugWithName("behaviors:event");
|
|
6538
|
+
function performEvent({
|
|
6539
|
+
behaviors,
|
|
6540
|
+
event,
|
|
6541
|
+
editor,
|
|
6542
|
+
keyGenerator,
|
|
6543
|
+
schema,
|
|
6544
|
+
getSnapshot,
|
|
6545
|
+
nativeEvent,
|
|
6546
|
+
defaultActionCallback
|
|
6547
|
+
}) {
|
|
6548
|
+
debug$2(JSON.stringify(event, null, 2));
|
|
6549
|
+
const defaultAction = isCustomBehaviorEvent(event) || isClipboardBehaviorEvent(event) || isDragBehaviorEvent(event) || isInputBehaviorEvent(event) || isKeyboardBehaviorEvent(event) || isMouseBehaviorEvent(event) || event.type === "deserialize" || event.type === "serialize" ? void 0 : {
|
|
6550
|
+
...event,
|
|
6551
|
+
editor
|
|
6552
|
+
}, eventBehaviors = behaviors.filter((behavior) => {
|
|
6553
|
+
if (behavior.on === "*")
|
|
6554
|
+
return !0;
|
|
6555
|
+
const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
|
|
6556
|
+
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
6557
|
+
});
|
|
6558
|
+
if (eventBehaviors.length === 0) {
|
|
6559
|
+
if (defaultActionCallback) {
|
|
6560
|
+
withApplyingBehaviorActions(editor, () => {
|
|
6561
|
+
try {
|
|
6562
|
+
defaultActionCallback();
|
|
6563
|
+
} catch (error) {
|
|
6564
|
+
console.error(new Error(`Performing action "${event.type}" failed due to: ${error.message}`));
|
|
6565
|
+
}
|
|
6566
|
+
});
|
|
6567
|
+
return;
|
|
6568
|
+
}
|
|
6569
|
+
if (!defaultAction)
|
|
6570
|
+
return;
|
|
6571
|
+
withApplyingBehaviorActions(editor, () => {
|
|
6572
|
+
try {
|
|
6573
|
+
performAction({
|
|
6574
|
+
context: {
|
|
6575
|
+
keyGenerator,
|
|
6576
|
+
schema
|
|
6577
|
+
},
|
|
6578
|
+
action: defaultAction
|
|
6579
|
+
});
|
|
6580
|
+
} catch (error) {
|
|
6581
|
+
console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
|
|
6582
|
+
}
|
|
6583
|
+
}), editor.onChange();
|
|
6584
|
+
return;
|
|
6585
|
+
}
|
|
6586
|
+
const editorSnapshot = getSnapshot();
|
|
6587
|
+
let behaviorOverwritten = !1;
|
|
6588
|
+
for (const eventBehavior of eventBehaviors) {
|
|
6589
|
+
const shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
|
|
6590
|
+
context: editorSnapshot.context,
|
|
6591
|
+
snapshot: editorSnapshot,
|
|
6592
|
+
event
|
|
6593
|
+
});
|
|
6594
|
+
if (!shouldRun)
|
|
6595
|
+
continue;
|
|
6596
|
+
const actionSets = eventBehavior.actions.map((actionSet) => actionSet({
|
|
6597
|
+
context: editorSnapshot.context,
|
|
6598
|
+
snapshot: editorSnapshot,
|
|
6599
|
+
event
|
|
6600
|
+
}, shouldRun));
|
|
6601
|
+
for (const actionSet of actionSets)
|
|
6602
|
+
actionSet.length !== 0 && (behaviorOverwritten = behaviorOverwritten || actionSet.some((action) => action.type !== "effect"), withApplyingBehaviorActionSet(editor, () => {
|
|
6603
|
+
for (const action of actionSet) {
|
|
6604
|
+
if (action.type === "raise") {
|
|
6605
|
+
performEvent({
|
|
6606
|
+
behaviors,
|
|
6607
|
+
event: action.event,
|
|
6608
|
+
editor,
|
|
6609
|
+
keyGenerator,
|
|
6610
|
+
schema,
|
|
6611
|
+
getSnapshot,
|
|
6612
|
+
defaultActionCallback: void 0,
|
|
6613
|
+
nativeEvent: void 0
|
|
6614
|
+
});
|
|
6615
|
+
continue;
|
|
6616
|
+
}
|
|
6617
|
+
const internalAction = {
|
|
6618
|
+
...action,
|
|
6619
|
+
editor
|
|
6620
|
+
};
|
|
6621
|
+
try {
|
|
6622
|
+
performAction({
|
|
6623
|
+
context: {
|
|
6624
|
+
keyGenerator,
|
|
6625
|
+
schema
|
|
6626
|
+
},
|
|
6627
|
+
action: internalAction
|
|
6628
|
+
});
|
|
6629
|
+
} catch (error) {
|
|
6630
|
+
console.error(new Error(`Performing action "${internalAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
|
|
6631
|
+
break;
|
|
6632
|
+
}
|
|
6633
|
+
}
|
|
6634
|
+
}), editor.onChange());
|
|
6635
|
+
if (behaviorOverwritten) {
|
|
6636
|
+
nativeEvent?.preventDefault();
|
|
6637
|
+
break;
|
|
6638
|
+
}
|
|
6639
|
+
}
|
|
6640
|
+
if (!behaviorOverwritten) {
|
|
6641
|
+
if (defaultActionCallback) {
|
|
6642
|
+
withApplyingBehaviorActions(editor, () => {
|
|
6643
|
+
try {
|
|
6644
|
+
defaultActionCallback();
|
|
6645
|
+
} catch (error) {
|
|
6646
|
+
console.error(new Error(`Performing "${event.type}" failed due to: ${error.message}`));
|
|
6647
|
+
}
|
|
6648
|
+
});
|
|
6649
|
+
return;
|
|
6650
|
+
}
|
|
6651
|
+
if (!defaultAction)
|
|
6652
|
+
return;
|
|
6653
|
+
withApplyingBehaviorActions(editor, () => {
|
|
6654
|
+
try {
|
|
6655
|
+
performAction({
|
|
6656
|
+
context: {
|
|
6657
|
+
keyGenerator,
|
|
6658
|
+
schema
|
|
6659
|
+
},
|
|
6660
|
+
action: defaultAction
|
|
6661
|
+
});
|
|
6662
|
+
} catch (error) {
|
|
6663
|
+
console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
|
|
6664
|
+
}
|
|
6665
|
+
}), editor.onChange();
|
|
6666
|
+
}
|
|
6667
|
+
}
|
|
6455
6668
|
function getActiveDecorators({
|
|
6456
6669
|
schema,
|
|
6457
6670
|
slateEditorInstance
|
|
@@ -6561,141 +6774,32 @@ const editorMachine = setup({
|
|
|
6561
6774
|
"clear pending events": assign({
|
|
6562
6775
|
pendingEvents: []
|
|
6563
6776
|
}),
|
|
6564
|
-
"handle behavior event":
|
|
6777
|
+
"handle behavior event": ({
|
|
6565
6778
|
context,
|
|
6566
6779
|
event,
|
|
6567
|
-
enqueue,
|
|
6568
6780
|
self
|
|
6569
6781
|
}) => {
|
|
6570
|
-
assertEvent(event, ["behavior event", "custom behavior event"])
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
editor: event.editor
|
|
6574
|
-
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => {
|
|
6575
|
-
if (behavior.on === "*")
|
|
6576
|
-
return !0;
|
|
6577
|
-
const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.behaviorEvent.type.includes(".") ? event.behaviorEvent.type.split(".") : [void 0];
|
|
6578
|
-
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.behaviorEvent.type ? !0 : behavior.on === event.behaviorEvent.type;
|
|
6579
|
-
});
|
|
6580
|
-
if (eventBehaviors.length === 0) {
|
|
6581
|
-
if (defaultActionCallback) {
|
|
6582
|
-
withApplyingBehaviorActions(event.editor, () => {
|
|
6583
|
-
try {
|
|
6584
|
-
defaultActionCallback();
|
|
6585
|
-
} catch (error) {
|
|
6586
|
-
console.error(new Error(`Performing action "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
6587
|
-
}
|
|
6588
|
-
});
|
|
6589
|
-
return;
|
|
6590
|
-
}
|
|
6591
|
-
if (!defaultAction)
|
|
6592
|
-
return;
|
|
6593
|
-
withApplyingBehaviorActions(event.editor, () => {
|
|
6594
|
-
try {
|
|
6595
|
-
performAction({
|
|
6596
|
-
context: {
|
|
6597
|
-
keyGenerator: context.keyGenerator,
|
|
6598
|
-
schema: context.schema
|
|
6599
|
-
},
|
|
6600
|
-
action: defaultAction
|
|
6601
|
-
});
|
|
6602
|
-
} catch (error) {
|
|
6603
|
-
console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
6604
|
-
}
|
|
6605
|
-
}), event.editor.onChange();
|
|
6606
|
-
return;
|
|
6607
|
-
}
|
|
6608
|
-
const editorSnapshot = createEditorSnapshot({
|
|
6609
|
-
converters: [...context.converters],
|
|
6782
|
+
assertEvent(event, ["behavior event", "custom behavior event"]), performEvent({
|
|
6783
|
+
behaviors: [...context.behaviors.values(), ...defaultBehaviors],
|
|
6784
|
+
event: event.behaviorEvent,
|
|
6610
6785
|
editor: event.editor,
|
|
6611
6786
|
keyGenerator: context.keyGenerator,
|
|
6612
|
-
readOnly: self.getSnapshot().matches({
|
|
6613
|
-
"edit mode": "read only"
|
|
6614
|
-
}),
|
|
6615
6787
|
schema: context.schema,
|
|
6616
|
-
|
|
6617
|
-
|
|
6788
|
+
getSnapshot: () => createEditorSnapshot({
|
|
6789
|
+
converters: [...context.converters],
|
|
6790
|
+
editor: event.editor,
|
|
6791
|
+
keyGenerator: context.keyGenerator,
|
|
6792
|
+
readOnly: self.getSnapshot().matches({
|
|
6793
|
+
"edit mode": "read only"
|
|
6794
|
+
}),
|
|
6795
|
+
schema: context.schema,
|
|
6796
|
+
hasTag: (tag) => self.getSnapshot().hasTag(tag),
|
|
6797
|
+
internalDrag: context.internalDrag
|
|
6798
|
+
}),
|
|
6799
|
+
nativeEvent: event.nativeEvent,
|
|
6800
|
+
defaultActionCallback: event.type === "behavior event" ? event.defaultActionCallback : void 0
|
|
6618
6801
|
});
|
|
6619
|
-
|
|
6620
|
-
for (const eventBehavior of eventBehaviors) {
|
|
6621
|
-
const shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
|
|
6622
|
-
context: editorSnapshot.context,
|
|
6623
|
-
snapshot: editorSnapshot,
|
|
6624
|
-
event: event.behaviorEvent
|
|
6625
|
-
});
|
|
6626
|
-
if (!shouldRun)
|
|
6627
|
-
continue;
|
|
6628
|
-
const actionSets = eventBehavior.actions.map((actionSet) => actionSet({
|
|
6629
|
-
context: editorSnapshot.context,
|
|
6630
|
-
snapshot: editorSnapshot,
|
|
6631
|
-
event: event.behaviorEvent
|
|
6632
|
-
}, shouldRun));
|
|
6633
|
-
for (const actionSet of actionSets)
|
|
6634
|
-
behaviorOverwritten = behaviorOverwritten || actionSet.length > 0 && actionSet.some((action) => action.type !== "effect"), withApplyingBehaviorActionSet(event.editor, () => {
|
|
6635
|
-
for (const action of actionSet) {
|
|
6636
|
-
if (action.type === "raise") {
|
|
6637
|
-
isCustomBehaviorEvent(action.event) ? enqueue.raise({
|
|
6638
|
-
type: "custom behavior event",
|
|
6639
|
-
behaviorEvent: action.event,
|
|
6640
|
-
editor: event.editor
|
|
6641
|
-
}) : enqueue.raise({
|
|
6642
|
-
type: "behavior event",
|
|
6643
|
-
behaviorEvent: action.event,
|
|
6644
|
-
editor: event.editor
|
|
6645
|
-
});
|
|
6646
|
-
continue;
|
|
6647
|
-
}
|
|
6648
|
-
const internalAction = {
|
|
6649
|
-
...action,
|
|
6650
|
-
editor: event.editor
|
|
6651
|
-
};
|
|
6652
|
-
try {
|
|
6653
|
-
performAction({
|
|
6654
|
-
context: {
|
|
6655
|
-
keyGenerator: context.keyGenerator,
|
|
6656
|
-
schema: context.schema
|
|
6657
|
-
},
|
|
6658
|
-
action: internalAction
|
|
6659
|
-
});
|
|
6660
|
-
} catch (error) {
|
|
6661
|
-
console.error(new Error(`Performing action "${internalAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
6662
|
-
break;
|
|
6663
|
-
}
|
|
6664
|
-
}
|
|
6665
|
-
}), event.editor.onChange();
|
|
6666
|
-
if (behaviorOverwritten) {
|
|
6667
|
-
event.nativeEvent?.preventDefault();
|
|
6668
|
-
break;
|
|
6669
|
-
}
|
|
6670
|
-
}
|
|
6671
|
-
if (!behaviorOverwritten) {
|
|
6672
|
-
if (defaultActionCallback) {
|
|
6673
|
-
withApplyingBehaviorActions(event.editor, () => {
|
|
6674
|
-
try {
|
|
6675
|
-
defaultActionCallback();
|
|
6676
|
-
} catch (error) {
|
|
6677
|
-
console.error(new Error(`Performing "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
6678
|
-
}
|
|
6679
|
-
});
|
|
6680
|
-
return;
|
|
6681
|
-
}
|
|
6682
|
-
if (!defaultAction)
|
|
6683
|
-
return;
|
|
6684
|
-
withApplyingBehaviorActions(event.editor, () => {
|
|
6685
|
-
try {
|
|
6686
|
-
performAction({
|
|
6687
|
-
context: {
|
|
6688
|
-
keyGenerator: context.keyGenerator,
|
|
6689
|
-
schema: context.schema
|
|
6690
|
-
},
|
|
6691
|
-
action: defaultAction
|
|
6692
|
-
});
|
|
6693
|
-
} catch (error) {
|
|
6694
|
-
console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
6695
|
-
}
|
|
6696
|
-
}), event.editor.onChange();
|
|
6697
|
-
}
|
|
6698
|
-
})
|
|
6802
|
+
}
|
|
6699
6803
|
}
|
|
6700
6804
|
}).createMachine({
|
|
6701
6805
|
id: "editor",
|