@portabletext/editor 1.49.10 → 1.49.12
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/behaviors/index.d.cts +159 -2872
- package/lib/behaviors/index.d.ts +159 -2872
- package/lib/index.cjs +346 -308
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +176 -2857
- package/lib/index.d.ts +176 -2857
- package/lib/index.js +349 -311
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +168 -2862
- package/lib/plugins/index.d.ts +168 -2862
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +159 -2872
- package/lib/selectors/index.d.ts +159 -2872
- package/lib/utils/index.d.cts +159 -2872
- package/lib/utils/index.d.ts +159 -2872
- package/package.json +1 -1
- package/src/editor/Editable.tsx +14 -12
- package/src/editor/PortableTextEditor.tsx +21 -26
- package/src/editor/__tests__/self-solving.test.tsx +9 -9
- package/src/editor/create-editor.ts +81 -49
- package/src/editor/create-slate-editor.tsx +3 -0
- package/src/editor/editor-machine.ts +15 -127
- package/src/editor/editor-provider.tsx +20 -15
- package/src/editor/mutation-machine.ts +125 -7
- package/src/editor/plugins/createWithPatches.ts +5 -2
- package/src/editor/plugins/createWithPortableTextSelections.ts +4 -2
- package/src/editor/plugins/with-plugins.ts +8 -3
- package/src/editor/relay-actor-context.ts +4 -0
- package/src/editor/relay-machine.ts +100 -0
- package/src/editor/route-events-to-changes.tsx +4 -10
- package/src/editor/sync-machine.ts +2 -2
- package/src/editor-event-listener.tsx +1 -1
- package/src/editor.ts +2 -4
- package/src/index.ts +3 -6
- package/src/internal-utils/__tests__/operationToPatches.test.ts +3 -1
- package/src/internal-utils/__tests__/patchToOperations.test.ts +2 -0
- package/src/plugins/plugin.event-listener.tsx +1 -1
- package/src/types/editor.ts +12 -4
package/lib/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$
|
|
3
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$j = require("debug"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$
|
|
7
|
+
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$j), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
|
|
8
8
|
function EditorEventListener(props) {
|
|
9
9
|
const $ = reactCompilerRuntime.c(5), editor = useEditor.useEditor(), on = useEffectEvent.useEffectEvent(props.on);
|
|
10
10
|
let t0;
|
|
@@ -1067,14 +1067,7 @@ const PortableTextEditorContext = React.createContext(null), usePortableTextEdit
|
|
|
1067
1067
|
if (!editor)
|
|
1068
1068
|
throw new Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");
|
|
1069
1069
|
return editor;
|
|
1070
|
-
}
|
|
1071
|
-
function compileType(rawType) {
|
|
1072
|
-
return schema.Schema.compile({
|
|
1073
|
-
name: "blockTypeSchema",
|
|
1074
|
-
types: [rawType]
|
|
1075
|
-
}).get(rawType.name);
|
|
1076
|
-
}
|
|
1077
|
-
const forEachActor = (actorRef, callback) => {
|
|
1070
|
+
}, forEachActor = (actorRef, callback) => {
|
|
1078
1071
|
callback(actorRef);
|
|
1079
1072
|
const children = actorRef.getSnapshot().children;
|
|
1080
1073
|
children && Object.values(children).forEach((child) => {
|
|
@@ -1343,11 +1336,17 @@ function escapeHtml(str) {
|
|
|
1343
1336
|
function createCoreConverters(legacySchema) {
|
|
1344
1337
|
return [converterJson, converterPortableText, createConverterTextHtml(legacySchema), createConverterTextPlain(legacySchema)];
|
|
1345
1338
|
}
|
|
1346
|
-
|
|
1339
|
+
function compileType(rawType) {
|
|
1340
|
+
return schema.Schema.compile({
|
|
1341
|
+
name: "blockTypeSchema",
|
|
1342
|
+
types: [rawType]
|
|
1343
|
+
}).get(rawType.name);
|
|
1344
|
+
}
|
|
1345
|
+
const debug$i = debugWithName("operationToPatches");
|
|
1347
1346
|
function createOperationToPatches(editorActor) {
|
|
1348
1347
|
const textBlockName = editorActor.getSnapshot().context.schema.block.name;
|
|
1349
1348
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
1350
|
-
debug$
|
|
1349
|
+
debug$i.enabled && debug$i("Operation", JSON.stringify(operation, null, 2));
|
|
1351
1350
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
1352
1351
|
if (!block)
|
|
1353
1352
|
throw new Error("Could not find block");
|
|
@@ -1440,7 +1439,7 @@ function createOperationToPatches(editorActor) {
|
|
|
1440
1439
|
_key: block.children[operation.path[1] - 1]._key
|
|
1441
1440
|
}])];
|
|
1442
1441
|
}
|
|
1443
|
-
return debug$
|
|
1442
|
+
return debug$i("Something was inserted into a void block. Not producing editor patches."), [];
|
|
1444
1443
|
}
|
|
1445
1444
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
1446
1445
|
const patches$1 = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -1498,9 +1497,9 @@ function createOperationToPatches(editorActor) {
|
|
|
1498
1497
|
_key: block._key
|
|
1499
1498
|
}, "children", {
|
|
1500
1499
|
_key: spanToRemove._key
|
|
1501
|
-
}])] : (debug$
|
|
1500
|
+
}])] : (debug$i("Span not found in editor trying to remove node"), []);
|
|
1502
1501
|
} else
|
|
1503
|
-
return debug$
|
|
1502
|
+
return debug$i("Not creating patch inside object block"), [];
|
|
1504
1503
|
}
|
|
1505
1504
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
1506
1505
|
const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -1526,7 +1525,7 @@ function createOperationToPatches(editorActor) {
|
|
|
1526
1525
|
_key: removedSpan._key
|
|
1527
1526
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
1528
1527
|
} else
|
|
1529
|
-
debug$
|
|
1528
|
+
debug$i("Void nodes can't be merged, not creating any patches");
|
|
1530
1529
|
return patches$1;
|
|
1531
1530
|
}
|
|
1532
1531
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -1644,7 +1643,7 @@ function isRedoing(editor) {
|
|
|
1644
1643
|
function setIsRedoing(editor, isRedoing2) {
|
|
1645
1644
|
IS_REDOING.set(editor, isRedoing2);
|
|
1646
1645
|
}
|
|
1647
|
-
const debug$
|
|
1646
|
+
const debug$h = debugWithName("plugin:withPortableTextMarkModel");
|
|
1648
1647
|
function createWithPortableTextMarkModel(editorActor) {
|
|
1649
1648
|
return function(editor) {
|
|
1650
1649
|
const {
|
|
@@ -1658,7 +1657,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1658
1657
|
for (const [child, childPath] of children) {
|
|
1659
1658
|
const nextNode = node.children[childPath[1] + 1];
|
|
1660
1659
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
1661
|
-
debug$
|
|
1660
|
+
debug$h("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
1662
1661
|
type: "normalizing"
|
|
1663
1662
|
}), slate.Transforms.mergeNodes(editor, {
|
|
1664
1663
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -1671,7 +1670,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1671
1670
|
}
|
|
1672
1671
|
}
|
|
1673
1672
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
1674
|
-
debug$
|
|
1673
|
+
debug$h("Adding .markDefs to block node"), editorActor.send({
|
|
1675
1674
|
type: "normalizing"
|
|
1676
1675
|
}), slate.Transforms.setNodes(editor, {
|
|
1677
1676
|
markDefs: []
|
|
@@ -1683,7 +1682,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1683
1682
|
return;
|
|
1684
1683
|
}
|
|
1685
1684
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
1686
|
-
debug$
|
|
1685
|
+
debug$h("Adding .marks to span node"), editorActor.send({
|
|
1687
1686
|
type: "normalizing"
|
|
1688
1687
|
}), slate.Transforms.setNodes(editor, {
|
|
1689
1688
|
marks: []
|
|
@@ -1697,7 +1696,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1697
1696
|
if (editor.isTextSpan(node)) {
|
|
1698
1697
|
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
1699
1698
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
1700
|
-
debug$
|
|
1699
|
+
debug$h("Removing annotations from empty span node"), editorActor.send({
|
|
1701
1700
|
type: "normalizing"
|
|
1702
1701
|
}), slate.Transforms.setNodes(editor, {
|
|
1703
1702
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -1715,7 +1714,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1715
1714
|
if (editor.isTextSpan(child)) {
|
|
1716
1715
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
1717
1716
|
if (orphanedAnnotations.length > 0) {
|
|
1718
|
-
debug$
|
|
1717
|
+
debug$h("Removing orphaned annotations from span node"), editorActor.send({
|
|
1719
1718
|
type: "normalizing"
|
|
1720
1719
|
}), slate.Transforms.setNodes(editor, {
|
|
1721
1720
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -1733,7 +1732,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1733
1732
|
if (editor.isTextBlock(block)) {
|
|
1734
1733
|
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));
|
|
1735
1734
|
if (orphanedAnnotations.length > 0) {
|
|
1736
|
-
debug$
|
|
1735
|
+
debug$h("Removing orphaned annotations from span node"), editorActor.send({
|
|
1737
1736
|
type: "normalizing"
|
|
1738
1737
|
}), slate.Transforms.setNodes(editor, {
|
|
1739
1738
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -1751,7 +1750,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1751
1750
|
for (const markDef of markDefs)
|
|
1752
1751
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
1753
1752
|
if (markDefs.length !== newMarkDefs.length) {
|
|
1754
|
-
debug$
|
|
1753
|
+
debug$h("Removing duplicate markDefs"), editorActor.send({
|
|
1755
1754
|
type: "normalizing"
|
|
1756
1755
|
}), slate.Transforms.setNodes(editor, {
|
|
1757
1756
|
markDefs: newMarkDefs
|
|
@@ -1766,7 +1765,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1766
1765
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
1767
1766
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
1768
1767
|
if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
|
|
1769
|
-
debug$
|
|
1768
|
+
debug$h("Removing markDef not in use"), editorActor.send({
|
|
1770
1769
|
type: "normalizing"
|
|
1771
1770
|
}), slate.Transforms.setNodes(editor, {
|
|
1772
1771
|
markDefs: newMarkDefs
|
|
@@ -1986,7 +1985,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1986
1985
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
1987
1986
|
if (editor.isTextBlock(targetBlock)) {
|
|
1988
1987
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
1989
|
-
debug$
|
|
1988
|
+
debug$h("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
|
|
1990
1989
|
markDefs: newMarkDefs
|
|
1991
1990
|
}, {
|
|
1992
1991
|
at: targetPath,
|
|
@@ -2723,7 +2722,7 @@ function withUndoStep(editor, fn) {
|
|
|
2723
2722
|
function getCurrentUndoStepId(editor) {
|
|
2724
2723
|
return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
|
|
2725
2724
|
}
|
|
2726
|
-
const debug$
|
|
2725
|
+
const debug$g = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2727
2726
|
const state = SAVING.get(editor);
|
|
2728
2727
|
return state === void 0 ? !0 : state;
|
|
2729
2728
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -2736,7 +2735,7 @@ function createWithUndoRedo(options) {
|
|
|
2736
2735
|
const remotePatches = getRemotePatches(editor);
|
|
2737
2736
|
let previousUndoStepId = getCurrentUndoStepId(editor);
|
|
2738
2737
|
options.subscriptions.push(() => {
|
|
2739
|
-
debug$
|
|
2738
|
+
debug$g("Subscribing to patches");
|
|
2740
2739
|
const sub = editorActor.on("patches", ({
|
|
2741
2740
|
patches: patches2,
|
|
2742
2741
|
snapshot
|
|
@@ -2745,7 +2744,7 @@ function createWithUndoRedo(options) {
|
|
|
2745
2744
|
patches2.forEach((patch) => {
|
|
2746
2745
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
2747
2746
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2748
|
-
debug$
|
|
2747
|
+
debug$g("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
2749
2748
|
undos: [],
|
|
2750
2749
|
redos: []
|
|
2751
2750
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -2761,7 +2760,7 @@ function createWithUndoRedo(options) {
|
|
|
2761
2760
|
}), previousSnapshot = snapshot;
|
|
2762
2761
|
});
|
|
2763
2762
|
return () => {
|
|
2764
|
-
debug$
|
|
2763
|
+
debug$g("Unsubscribing to patches"), sub.unsubscribe();
|
|
2765
2764
|
};
|
|
2766
2765
|
}), editor.history = {
|
|
2767
2766
|
undos: [],
|
|
@@ -2800,7 +2799,7 @@ function createWithUndoRedo(options) {
|
|
|
2800
2799
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
2801
2800
|
timestamp: /* @__PURE__ */ new Date()
|
|
2802
2801
|
};
|
|
2803
|
-
undos.push(newStep), debug$
|
|
2802
|
+
undos.push(newStep), debug$g("Created new undo step", step);
|
|
2804
2803
|
}
|
|
2805
2804
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
2806
2805
|
undos.shift();
|
|
@@ -2818,7 +2817,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2818
2817
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2819
2818
|
if (undos.length > 0) {
|
|
2820
2819
|
const step = undos[undos.length - 1];
|
|
2821
|
-
if (debug$
|
|
2820
|
+
if (debug$g("Undoing", step), step.operations.length > 0) {
|
|
2822
2821
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2823
2822
|
let transformedOperations = step.operations;
|
|
2824
2823
|
otherPatches.forEach((item) => {
|
|
@@ -2836,7 +2835,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2836
2835
|
});
|
|
2837
2836
|
});
|
|
2838
2837
|
} catch (err) {
|
|
2839
|
-
debug$
|
|
2838
|
+
debug$g("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
2840
2839
|
undos: [],
|
|
2841
2840
|
redos: []
|
|
2842
2841
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -2853,7 +2852,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2853
2852
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2854
2853
|
if (redos.length > 0) {
|
|
2855
2854
|
const step = redos[redos.length - 1];
|
|
2856
|
-
if (debug$
|
|
2855
|
+
if (debug$g("Redoing", step), step.operations.length > 0) {
|
|
2857
2856
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2858
2857
|
let transformedOperations = step.operations;
|
|
2859
2858
|
otherPatches.forEach((item) => {
|
|
@@ -2870,7 +2869,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2870
2869
|
});
|
|
2871
2870
|
});
|
|
2872
2871
|
} catch (err) {
|
|
2873
|
-
debug$
|
|
2872
|
+
debug$g("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
2874
2873
|
undos: [],
|
|
2875
2874
|
redos: []
|
|
2876
2875
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -2888,16 +2887,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2888
2887
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2889
2888
|
_key: blk._key
|
|
2890
2889
|
}, patch.path[0]));
|
|
2891
|
-
return debug$
|
|
2890
|
+
return debug$g(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
2892
2891
|
}
|
|
2893
2892
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
2894
2893
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2895
2894
|
_key: blk._key
|
|
2896
2895
|
}, patch.path[0]));
|
|
2897
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
2896
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$g("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
2898
2897
|
}
|
|
2899
2898
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2900
|
-
return debug$
|
|
2899
|
+
return debug$g(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
2901
2900
|
if (patch.type === "diffMatchPatch") {
|
|
2902
2901
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2903
2902
|
return !operationTargetBlock || !isEqual__default.default({
|
|
@@ -4121,13 +4120,13 @@ function createWithObjectKeys(editorActor) {
|
|
|
4121
4120
|
}, editor;
|
|
4122
4121
|
};
|
|
4123
4122
|
}
|
|
4124
|
-
const debug$
|
|
4123
|
+
const debug$f = debugWithName("applyPatches"), debugVerbose = debug$f.enabled && !0;
|
|
4125
4124
|
function createApplyPatch(schema2) {
|
|
4126
4125
|
return (editor, patch) => {
|
|
4127
4126
|
let changed = !1;
|
|
4128
|
-
debugVerbose && (debug$
|
|
4127
|
+
debugVerbose && (debug$f(`
|
|
4129
4128
|
|
|
4130
|
-
NEW PATCH =============================================================`), debug$
|
|
4129
|
+
NEW PATCH =============================================================`), debug$f(JSON.stringify(patch, null, 2)));
|
|
4131
4130
|
try {
|
|
4132
4131
|
switch (patch.type) {
|
|
4133
4132
|
case "insert":
|
|
@@ -4143,7 +4142,7 @@ NEW PATCH =============================================================`), debug
|
|
|
4143
4142
|
changed = diffMatchPatch(editor, patch);
|
|
4144
4143
|
break;
|
|
4145
4144
|
default:
|
|
4146
|
-
debug$
|
|
4145
|
+
debug$f("Unhandled patch", patch.type);
|
|
4147
4146
|
}
|
|
4148
4147
|
} catch (err) {
|
|
4149
4148
|
console.error(err);
|
|
@@ -4158,9 +4157,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
4158
4157
|
childPath
|
|
4159
4158
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
4160
4159
|
if (!block)
|
|
4161
|
-
return debug$
|
|
4160
|
+
return debug$f("Block not found"), !1;
|
|
4162
4161
|
if (!child || !childPath)
|
|
4163
|
-
return debug$
|
|
4162
|
+
return debug$f("Child not found"), !1;
|
|
4164
4163
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
|
|
4165
4164
|
return !1;
|
|
4166
4165
|
const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
|
|
@@ -4190,9 +4189,9 @@ function insertPatch(editor, patch, schema2) {
|
|
|
4190
4189
|
childPath: targetChildPath
|
|
4191
4190
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
4192
4191
|
if (!targetBlock || !targetBlockPath)
|
|
4193
|
-
return debug$
|
|
4192
|
+
return debug$f("Block not found"), !1;
|
|
4194
4193
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
4195
|
-
return debug$
|
|
4194
|
+
return debug$f("Ignoring patch targeting void value"), !1;
|
|
4196
4195
|
if (patch.path.length === 1) {
|
|
4197
4196
|
const {
|
|
4198
4197
|
items: items2,
|
|
@@ -4200,7 +4199,7 @@ function insertPatch(editor, patch, schema2) {
|
|
|
4200
4199
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
4201
4200
|
schemaTypes: schema2
|
|
4202
4201
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
4203
|
-
debug$
|
|
4202
|
+
debug$f(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before");
|
|
4204
4203
|
const editorWasEmptyBefore = isEqualToEmptyEditor(editor.children, schema2);
|
|
4205
4204
|
return slate.Transforms.insertNodes(editor, blocksToInsert, {
|
|
4206
4205
|
at: [normalizedIdx2]
|
|
@@ -4213,14 +4212,14 @@ function insertPatch(editor, patch, schema2) {
|
|
|
4213
4212
|
position
|
|
4214
4213
|
} = patch;
|
|
4215
4214
|
if (!targetChild || !targetChildPath)
|
|
4216
|
-
return debug$
|
|
4215
|
+
return debug$f("Child not found"), !1;
|
|
4217
4216
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
4218
4217
|
...targetBlock,
|
|
4219
4218
|
children: items
|
|
4220
4219
|
}], {
|
|
4221
4220
|
schemaTypes: schema2
|
|
4222
4221
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
4223
|
-
return debug$
|
|
4222
|
+
return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
4224
4223
|
at: childInsertPath
|
|
4225
4224
|
}), debugState(editor, "after"), !0;
|
|
4226
4225
|
}
|
|
@@ -4234,14 +4233,14 @@ function setPatch(editor, patch) {
|
|
|
4234
4233
|
childPath
|
|
4235
4234
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
4236
4235
|
if (!block)
|
|
4237
|
-
return debug$
|
|
4236
|
+
return debug$f("Block not found"), !1;
|
|
4238
4237
|
const isTextBlock = editor.isTextBlock(block);
|
|
4239
4238
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
4240
|
-
return debug$
|
|
4239
|
+
return debug$f("Ignoring setting void value"), !1;
|
|
4241
4240
|
if (debugState(editor, "before"), isTextBlock && child && childPath) {
|
|
4242
4241
|
if (slate.Text.isText(value) && slate.Text.isText(child)) {
|
|
4243
4242
|
const newText = child.text;
|
|
4244
|
-
value.text !== newText && (debug$
|
|
4243
|
+
value.text !== newText && (debug$f("Setting text property"), editor.apply({
|
|
4245
4244
|
type: "remove_text",
|
|
4246
4245
|
path: childPath,
|
|
4247
4246
|
offset: 0,
|
|
@@ -4253,7 +4252,7 @@ function setPatch(editor, patch) {
|
|
|
4253
4252
|
text: value.text
|
|
4254
4253
|
}), editor.onChange());
|
|
4255
4254
|
} else
|
|
4256
|
-
debug$
|
|
4255
|
+
debug$f("Setting non-text property"), editor.apply({
|
|
4257
4256
|
type: "set_node",
|
|
4258
4257
|
path: childPath,
|
|
4259
4258
|
properties: {},
|
|
@@ -4261,7 +4260,7 @@ function setPatch(editor, patch) {
|
|
|
4261
4260
|
});
|
|
4262
4261
|
return !0;
|
|
4263
4262
|
} else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
4264
|
-
debug$
|
|
4263
|
+
debug$f("Setting block property");
|
|
4265
4264
|
const {
|
|
4266
4265
|
children,
|
|
4267
4266
|
...nextRest
|
|
@@ -4278,7 +4277,7 @@ function setPatch(editor, patch) {
|
|
|
4278
4277
|
...prevRest
|
|
4279
4278
|
},
|
|
4280
4279
|
newProperties: nextRest
|
|
4281
|
-
}), debug$
|
|
4280
|
+
}), debug$f("Setting children"), block.children.forEach((c, cIndex) => {
|
|
4282
4281
|
editor.apply({
|
|
4283
4282
|
type: "remove_node",
|
|
4284
4283
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -4309,7 +4308,7 @@ function setPatch(editor, patch) {
|
|
|
4309
4308
|
}
|
|
4310
4309
|
function unsetPatch(editor, patch) {
|
|
4311
4310
|
if (patch.path.length === 0) {
|
|
4312
|
-
debug$
|
|
4311
|
+
debug$f("Removing everything"), debugState(editor, "before");
|
|
4313
4312
|
const previousSelection = editor.selection;
|
|
4314
4313
|
slate.Transforms.deselect(editor);
|
|
4315
4314
|
const children = slate.Node.children(editor, [], {
|
|
@@ -4340,13 +4339,13 @@ function unsetPatch(editor, patch) {
|
|
|
4340
4339
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
4341
4340
|
if (patch.path.length === 1) {
|
|
4342
4341
|
if (!block || !blockPath)
|
|
4343
|
-
return debug$
|
|
4342
|
+
return debug$f("Block not found"), !1;
|
|
4344
4343
|
const blockIndex = blockPath[0];
|
|
4345
|
-
return debug$
|
|
4344
|
+
return debug$f(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
|
|
4346
4345
|
at: [blockIndex]
|
|
4347
4346
|
}), debugState(editor, "after"), !0;
|
|
4348
4347
|
}
|
|
4349
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
4348
|
+
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$f("Child not found"), !1) : (debug$f(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$f(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
|
|
4350
4349
|
at: childPath
|
|
4351
4350
|
}), debugState(editor, "after"), !0) : !1;
|
|
4352
4351
|
}
|
|
@@ -4354,7 +4353,7 @@ function isKeyedSegment(segment) {
|
|
|
4354
4353
|
return typeof segment == "object" && "_key" in segment;
|
|
4355
4354
|
}
|
|
4356
4355
|
function debugState(editor, stateName) {
|
|
4357
|
-
debugVerbose && (debug$
|
|
4356
|
+
debugVerbose && (debug$f(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$f(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
4358
4357
|
}
|
|
4359
4358
|
function findBlockFromPath(editor, path) {
|
|
4360
4359
|
let blockIndex = -1;
|
|
@@ -4404,9 +4403,10 @@ function withoutPatching(editor, fn) {
|
|
|
4404
4403
|
function isPatching(editor) {
|
|
4405
4404
|
return PATCHING.get(editor);
|
|
4406
4405
|
}
|
|
4407
|
-
const debug$
|
|
4406
|
+
const debug$e = debugWithName("plugin:withPatches");
|
|
4408
4407
|
function createWithPatches({
|
|
4409
4408
|
editorActor,
|
|
4409
|
+
relayActor,
|
|
4410
4410
|
patchFunctions,
|
|
4411
4411
|
subscriptions
|
|
4412
4412
|
}) {
|
|
@@ -4429,7 +4429,7 @@ function createWithPatches({
|
|
|
4429
4429
|
withoutPatching(editor, () => {
|
|
4430
4430
|
withoutSaving(editor, () => {
|
|
4431
4431
|
for (const patch of patches2) {
|
|
4432
|
-
debug$
|
|
4432
|
+
debug$e.enabled && debug$e(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
4433
4433
|
try {
|
|
4434
4434
|
changed = applyPatch(editor, patch);
|
|
4435
4435
|
} catch (error) {
|
|
@@ -4447,10 +4447,10 @@ function createWithPatches({
|
|
|
4447
4447
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
4448
4448
|
};
|
|
4449
4449
|
return subscriptions.push(() => {
|
|
4450
|
-
debug$
|
|
4450
|
+
debug$e("Subscribing to remote patches");
|
|
4451
4451
|
const sub = editorActor.on("patches", handlePatches);
|
|
4452
4452
|
return () => {
|
|
4453
|
-
debug$
|
|
4453
|
+
debug$e("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
4454
4454
|
};
|
|
4455
4455
|
}), editor.apply = (operation) => {
|
|
4456
4456
|
let patches$1 = [];
|
|
@@ -4486,8 +4486,8 @@ function createWithPatches({
|
|
|
4486
4486
|
patches$1 = [...patches$1, ...patchFunctions.moveNodePatch(editor, operation, previousChildren)];
|
|
4487
4487
|
break;
|
|
4488
4488
|
}
|
|
4489
|
-
if (!editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches$1 = [...patches$1, patches.unset([])],
|
|
4490
|
-
type: "
|
|
4489
|
+
if (!editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches$1 = [...patches$1, patches.unset([])], relayActor.send({
|
|
4490
|
+
type: "unset",
|
|
4491
4491
|
previousValue: fromSlateValue(previousChildren, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
|
|
4492
4492
|
})), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0)
|
|
4493
4493
|
for (const patch of patches$1)
|
|
@@ -4504,7 +4504,7 @@ function createWithPatches({
|
|
|
4504
4504
|
}, editor;
|
|
4505
4505
|
};
|
|
4506
4506
|
}
|
|
4507
|
-
const debug$
|
|
4507
|
+
const debug$d = debugWithName("plugin:withPlaceholderBlock");
|
|
4508
4508
|
function createWithPlaceholderBlock(editorActor) {
|
|
4509
4509
|
return function(editor) {
|
|
4510
4510
|
const {
|
|
@@ -4529,7 +4529,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4529
4529
|
const node = op.node;
|
|
4530
4530
|
if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
|
|
4531
4531
|
const nextPath = slate.Path.next(op.path);
|
|
4532
|
-
editor.children[nextPath[0]] || (debug$
|
|
4532
|
+
editor.children[nextPath[0]] || (debug$d("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
4533
4533
|
decorators: []
|
|
4534
4534
|
})));
|
|
4535
4535
|
}
|
|
@@ -4538,7 +4538,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4538
4538
|
}, editor;
|
|
4539
4539
|
};
|
|
4540
4540
|
}
|
|
4541
|
-
const debug$
|
|
4541
|
+
const debug$c = debugWithName("plugin:withPortableTextBlockStyle");
|
|
4542
4542
|
function createWithPortableTextBlockStyle(editorActor) {
|
|
4543
4543
|
const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
|
|
4544
4544
|
return function(editor) {
|
|
@@ -4551,7 +4551,7 @@ function createWithPortableTextBlockStyle(editorActor) {
|
|
|
4551
4551
|
if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !slate.Path.equals(path, op.path)) {
|
|
4552
4552
|
const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
|
|
4553
4553
|
if (slate.Text.isText(child) && child.text === "") {
|
|
4554
|
-
debug$
|
|
4554
|
+
debug$c(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
4555
4555
|
type: "normalizing"
|
|
4556
4556
|
}), slate.Transforms.setNodes(editor, {
|
|
4557
4557
|
style: defaultStyle
|
|
@@ -4569,7 +4569,7 @@ function createWithPortableTextBlockStyle(editorActor) {
|
|
|
4569
4569
|
};
|
|
4570
4570
|
}
|
|
4571
4571
|
debugWithName("plugin:withPortableTextSelections");
|
|
4572
|
-
function createWithPortableTextSelections(editorActor) {
|
|
4572
|
+
function createWithPortableTextSelections(editorActor, relayActor) {
|
|
4573
4573
|
let prevSelection = null;
|
|
4574
4574
|
return function(editor) {
|
|
4575
4575
|
const emitPortableTextSelection = () => {
|
|
@@ -4583,11 +4583,11 @@ function createWithPortableTextSelections(editorActor) {
|
|
|
4583
4583
|
range: editor.selection
|
|
4584
4584
|
}), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange));
|
|
4585
4585
|
}
|
|
4586
|
-
ptRange ?
|
|
4587
|
-
type: "
|
|
4586
|
+
ptRange ? relayActor.send({
|
|
4587
|
+
type: "selection",
|
|
4588
4588
|
selection: ptRange
|
|
4589
|
-
}) :
|
|
4590
|
-
type: "
|
|
4589
|
+
}) : relayActor.send({
|
|
4590
|
+
type: "selection",
|
|
4591
4591
|
selection: null
|
|
4592
4592
|
});
|
|
4593
4593
|
}
|
|
@@ -4602,7 +4602,7 @@ function createWithPortableTextSelections(editorActor) {
|
|
|
4602
4602
|
}, editor;
|
|
4603
4603
|
};
|
|
4604
4604
|
}
|
|
4605
|
-
const debug$
|
|
4605
|
+
const debug$b = debugWithName("plugin:withSchemaTypes");
|
|
4606
4606
|
function createWithSchemaTypes({
|
|
4607
4607
|
editorActor
|
|
4608
4608
|
}) {
|
|
@@ -4614,7 +4614,7 @@ function createWithSchemaTypes({
|
|
|
4614
4614
|
return editor.normalizeNode = (entry) => {
|
|
4615
4615
|
const [node, path] = entry;
|
|
4616
4616
|
if (node._type === void 0 && path.length === 2) {
|
|
4617
|
-
debug$
|
|
4617
|
+
debug$b("Setting span type on text node without a type");
|
|
4618
4618
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4619
4619
|
editorActor.send({
|
|
4620
4620
|
type: "normalizing"
|
|
@@ -4630,7 +4630,7 @@ function createWithSchemaTypes({
|
|
|
4630
4630
|
return;
|
|
4631
4631
|
}
|
|
4632
4632
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
4633
|
-
debug$
|
|
4633
|
+
debug$b("Setting missing key on child node without a key");
|
|
4634
4634
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
4635
4635
|
editorActor.send({
|
|
4636
4636
|
type: "normalizing"
|
|
@@ -4677,11 +4677,13 @@ function createWithUtils({
|
|
|
4677
4677
|
}
|
|
4678
4678
|
const withPlugins = (editor, options) => {
|
|
4679
4679
|
const e = editor, {
|
|
4680
|
-
editorActor
|
|
4680
|
+
editorActor,
|
|
4681
|
+
relayActor
|
|
4681
4682
|
} = options, operationToPatches = createOperationToPatches(editorActor), withObjectKeys = createWithObjectKeys(editorActor), withSchemaTypes = createWithSchemaTypes({
|
|
4682
4683
|
editorActor
|
|
4683
4684
|
}), withPatches = createWithPatches({
|
|
4684
4685
|
editorActor,
|
|
4686
|
+
relayActor,
|
|
4685
4687
|
patchFunctions: operationToPatches,
|
|
4686
4688
|
subscriptions: options.subscriptions
|
|
4687
4689
|
}), withMaxBlocks = createWithMaxBlocks(editorActor), withUndoRedo = createWithUndoRedo({
|
|
@@ -4689,13 +4691,14 @@ const withPlugins = (editor, options) => {
|
|
|
4689
4691
|
subscriptions: options.subscriptions
|
|
4690
4692
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
4691
4693
|
editorActor
|
|
4692
|
-
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
4694
|
+
}), withPortableTextSelections = createWithPortableTextSelections(editorActor, relayActor);
|
|
4693
4695
|
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
4694
|
-
}, debug$
|
|
4696
|
+
}, debug$a = debugWithName("setup");
|
|
4695
4697
|
function createSlateEditor(config) {
|
|
4696
|
-
debug$
|
|
4698
|
+
debug$a("Creating new Slate editor instance");
|
|
4697
4699
|
const instance = withPlugins(slateReact.withReact(slate.createEditor()), {
|
|
4698
4700
|
editorActor: config.editorActor,
|
|
4701
|
+
relayActor: config.relayActor,
|
|
4699
4702
|
subscriptions: config.subscriptions
|
|
4700
4703
|
});
|
|
4701
4704
|
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {});
|
|
@@ -6271,7 +6274,7 @@ function isNativeBehaviorEvent(event) {
|
|
|
6271
6274
|
function isCustomBehaviorEvent(event) {
|
|
6272
6275
|
return event.type.startsWith("custom.");
|
|
6273
6276
|
}
|
|
6274
|
-
const debug$
|
|
6277
|
+
const debug$9 = debugWithName("behaviors:event");
|
|
6275
6278
|
function eventCategory(event) {
|
|
6276
6279
|
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "synthetic" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
6277
6280
|
}
|
|
@@ -6286,7 +6289,7 @@ function performEvent({
|
|
|
6286
6289
|
getSnapshot,
|
|
6287
6290
|
nativeEvent
|
|
6288
6291
|
}) {
|
|
6289
|
-
debug$
|
|
6292
|
+
debug$9(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
6290
6293
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
6291
6294
|
if (behavior.on === "*")
|
|
6292
6295
|
return !0;
|
|
@@ -6295,7 +6298,7 @@ function performEvent({
|
|
|
6295
6298
|
});
|
|
6296
6299
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
6297
6300
|
nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
6298
|
-
debug$
|
|
6301
|
+
debug$9(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
6299
6302
|
context: {
|
|
6300
6303
|
keyGenerator,
|
|
6301
6304
|
schema: schema2
|
|
@@ -6438,7 +6441,7 @@ function performEvent({
|
|
|
6438
6441
|
}
|
|
6439
6442
|
}
|
|
6440
6443
|
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
6441
|
-
debug$
|
|
6444
|
+
debug$9(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
6442
6445
|
context: {
|
|
6443
6446
|
keyGenerator,
|
|
6444
6447
|
schema: schema2
|
|
@@ -6563,7 +6566,7 @@ function createEditorSnapshot({
|
|
|
6563
6566
|
}
|
|
6564
6567
|
};
|
|
6565
6568
|
}
|
|
6566
|
-
const debug$
|
|
6569
|
+
const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
6567
6570
|
types: {
|
|
6568
6571
|
context: {},
|
|
6569
6572
|
events: {},
|
|
@@ -6584,19 +6587,11 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
6584
6587
|
event
|
|
6585
6588
|
}) => (xstate.assertEvent(event, "remove behavior"), context.behaviors.delete(event.behaviorConfig), /* @__PURE__ */ new Set([...context.behaviors]))
|
|
6586
6589
|
}),
|
|
6587
|
-
"assign schema": xstate.assign({
|
|
6588
|
-
schema: ({
|
|
6589
|
-
event
|
|
6590
|
-
}) => (xstate.assertEvent(event, "update schema"), event.schema)
|
|
6591
|
-
}),
|
|
6592
6590
|
"emit patch event": xstate.enqueueActions(({
|
|
6593
6591
|
event,
|
|
6594
6592
|
enqueue
|
|
6595
6593
|
}) => {
|
|
6596
|
-
xstate.assertEvent(event, "internal.patch"), enqueue.emit(event)
|
|
6597
|
-
type: "patch",
|
|
6598
|
-
patch: event.patch
|
|
6599
|
-
});
|
|
6594
|
+
xstate.assertEvent(event, "internal.patch"), enqueue.emit(event);
|
|
6600
6595
|
}),
|
|
6601
6596
|
"emit mutation event": xstate.emit(({
|
|
6602
6597
|
event
|
|
@@ -6618,10 +6613,7 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
6618
6613
|
enqueue
|
|
6619
6614
|
}) => {
|
|
6620
6615
|
for (const event of context.pendingEvents)
|
|
6621
|
-
|
|
6622
|
-
type: "patch",
|
|
6623
|
-
patch: event.patch
|
|
6624
|
-
})) : enqueue.emit(event);
|
|
6616
|
+
enqueue.emit(event);
|
|
6625
6617
|
}),
|
|
6626
6618
|
"emit ready": xstate.emit({
|
|
6627
6619
|
type: "ready"
|
|
@@ -6726,98 +6718,25 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
6726
6718
|
initialValue: input.initialValue
|
|
6727
6719
|
}),
|
|
6728
6720
|
on: {
|
|
6729
|
-
"notify.blurred": {
|
|
6730
|
-
actions: xstate.emit(({
|
|
6731
|
-
event
|
|
6732
|
-
}) => ({
|
|
6733
|
-
...event,
|
|
6734
|
-
type: "blurred"
|
|
6735
|
-
}))
|
|
6736
|
-
},
|
|
6737
|
-
"notify.done loading": {
|
|
6738
|
-
actions: xstate.emit({
|
|
6739
|
-
type: "done loading"
|
|
6740
|
-
})
|
|
6741
|
-
},
|
|
6742
|
-
"notify.error": {
|
|
6743
|
-
actions: xstate.emit(({
|
|
6744
|
-
event
|
|
6745
|
-
}) => ({
|
|
6746
|
-
...event,
|
|
6747
|
-
type: "error"
|
|
6748
|
-
}))
|
|
6749
|
-
},
|
|
6750
|
-
"notify.invalid value": {
|
|
6751
|
-
actions: xstate.emit(({
|
|
6752
|
-
event
|
|
6753
|
-
}) => ({
|
|
6754
|
-
...event,
|
|
6755
|
-
type: "invalid value"
|
|
6756
|
-
}))
|
|
6757
|
-
},
|
|
6758
|
-
"notify.focused": {
|
|
6759
|
-
actions: xstate.emit(({
|
|
6760
|
-
event
|
|
6761
|
-
}) => ({
|
|
6762
|
-
...event,
|
|
6763
|
-
type: "focused"
|
|
6764
|
-
}))
|
|
6765
|
-
},
|
|
6766
|
-
"notify.selection": {
|
|
6767
|
-
actions: [xstate.assign({
|
|
6768
|
-
selection: ({
|
|
6769
|
-
event
|
|
6770
|
-
}) => event.selection
|
|
6771
|
-
}), xstate.emit(({
|
|
6772
|
-
event
|
|
6773
|
-
}) => ({
|
|
6774
|
-
...event,
|
|
6775
|
-
type: "selection"
|
|
6776
|
-
}))]
|
|
6777
|
-
},
|
|
6778
|
-
"notify.unset": {
|
|
6779
|
-
actions: xstate.emit(({
|
|
6780
|
-
event
|
|
6781
|
-
}) => ({
|
|
6782
|
-
...event,
|
|
6783
|
-
type: "unset"
|
|
6784
|
-
}))
|
|
6785
|
-
},
|
|
6786
|
-
"notify.loading": {
|
|
6787
|
-
actions: xstate.emit({
|
|
6788
|
-
type: "loading"
|
|
6789
|
-
})
|
|
6790
|
-
},
|
|
6791
|
-
"notify.value changed": {
|
|
6792
|
-
actions: xstate.emit(({
|
|
6793
|
-
event
|
|
6794
|
-
}) => ({
|
|
6795
|
-
...event,
|
|
6796
|
-
type: "value changed"
|
|
6797
|
-
}))
|
|
6798
|
-
},
|
|
6799
6721
|
"add behavior": {
|
|
6800
6722
|
actions: "add behavior to context"
|
|
6801
6723
|
},
|
|
6802
6724
|
"remove behavior": {
|
|
6803
6725
|
actions: "remove behavior from context"
|
|
6804
6726
|
},
|
|
6805
|
-
"update key generator": {
|
|
6806
|
-
actions: xstate.assign({
|
|
6807
|
-
keyGenerator: ({
|
|
6808
|
-
event
|
|
6809
|
-
}) => event.keyGenerator
|
|
6810
|
-
})
|
|
6811
|
-
},
|
|
6812
|
-
"update schema": {
|
|
6813
|
-
actions: "assign schema"
|
|
6814
|
-
},
|
|
6815
6727
|
"update maxBlocks": {
|
|
6816
6728
|
actions: xstate.assign({
|
|
6817
6729
|
maxBlocks: ({
|
|
6818
6730
|
event
|
|
6819
6731
|
}) => event.maxBlocks
|
|
6820
6732
|
})
|
|
6733
|
+
},
|
|
6734
|
+
"update selection": {
|
|
6735
|
+
actions: [xstate.assign({
|
|
6736
|
+
selection: ({
|
|
6737
|
+
event
|
|
6738
|
+
}) => event.selection
|
|
6739
|
+
})]
|
|
6821
6740
|
}
|
|
6822
6741
|
},
|
|
6823
6742
|
type: "parallel",
|
|
@@ -6838,10 +6757,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
6838
6757
|
states: {
|
|
6839
6758
|
"determine initial edit mode": {
|
|
6840
6759
|
entry: [() => {
|
|
6841
|
-
debug$
|
|
6760
|
+
debug$8("entry: edit mode->read only->determine initial edit mode");
|
|
6842
6761
|
}],
|
|
6843
6762
|
exit: [() => {
|
|
6844
|
-
debug$
|
|
6763
|
+
debug$8("exit: edit mode->read only->determine initial edit mode");
|
|
6845
6764
|
}],
|
|
6846
6765
|
on: {
|
|
6847
6766
|
"done syncing value": [{
|
|
@@ -6856,10 +6775,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
6856
6775
|
},
|
|
6857
6776
|
"read only": {
|
|
6858
6777
|
entry: [() => {
|
|
6859
|
-
debug$
|
|
6778
|
+
debug$8("entry: edit mode->read only->read only");
|
|
6860
6779
|
}],
|
|
6861
6780
|
exit: [() => {
|
|
6862
|
-
debug$
|
|
6781
|
+
debug$8("exit: edit mode->read only->read only");
|
|
6863
6782
|
}],
|
|
6864
6783
|
on: {
|
|
6865
6784
|
"update readOnly": {
|
|
@@ -6901,10 +6820,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
6901
6820
|
states: {
|
|
6902
6821
|
idle: {
|
|
6903
6822
|
entry: [() => {
|
|
6904
|
-
debug$
|
|
6823
|
+
debug$8("entry: edit mode->editable->idle");
|
|
6905
6824
|
}],
|
|
6906
6825
|
exit: [() => {
|
|
6907
|
-
debug$
|
|
6826
|
+
debug$8("exit: edit mode->editable-idle");
|
|
6908
6827
|
}],
|
|
6909
6828
|
on: {
|
|
6910
6829
|
dragstart: {
|
|
@@ -6925,10 +6844,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
6925
6844
|
states: {
|
|
6926
6845
|
"checking if busy": {
|
|
6927
6846
|
entry: [() => {
|
|
6928
|
-
debug$
|
|
6847
|
+
debug$8("entry: edit mode->editable->focusing->checking if busy");
|
|
6929
6848
|
}],
|
|
6930
6849
|
exit: [() => {
|
|
6931
|
-
debug$
|
|
6850
|
+
debug$8("exit: edit mode->editable->focusing->checking if busy");
|
|
6932
6851
|
}],
|
|
6933
6852
|
always: [{
|
|
6934
6853
|
guard: "slate is busy",
|
|
@@ -6940,10 +6859,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
6940
6859
|
},
|
|
6941
6860
|
busy: {
|
|
6942
6861
|
entry: [() => {
|
|
6943
|
-
debug$
|
|
6862
|
+
debug$8("entry: edit mode->editable->focusing-busy");
|
|
6944
6863
|
}],
|
|
6945
6864
|
exit: [() => {
|
|
6946
|
-
debug$
|
|
6865
|
+
debug$8("exit: edit mode->editable->focusing->busy");
|
|
6947
6866
|
}],
|
|
6948
6867
|
after: {
|
|
6949
6868
|
10: {
|
|
@@ -6955,10 +6874,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
6955
6874
|
},
|
|
6956
6875
|
"dragging internally": {
|
|
6957
6876
|
entry: [() => {
|
|
6958
|
-
debug$
|
|
6877
|
+
debug$8("entry: edit mode->editable->dragging internally");
|
|
6959
6878
|
}],
|
|
6960
6879
|
exit: [() => {
|
|
6961
|
-
debug$
|
|
6880
|
+
debug$8("exit: edit mode->editable->dragging internally");
|
|
6962
6881
|
}, ({
|
|
6963
6882
|
context
|
|
6964
6883
|
}) => {
|
|
@@ -6990,10 +6909,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
6990
6909
|
states: {
|
|
6991
6910
|
"setting up": {
|
|
6992
6911
|
entry: [() => {
|
|
6993
|
-
debug$
|
|
6912
|
+
debug$8("entry: setup->setting up");
|
|
6994
6913
|
}],
|
|
6995
6914
|
exit: [() => {
|
|
6996
|
-
debug$
|
|
6915
|
+
debug$8("exit: setup->setting up");
|
|
6997
6916
|
}, "emit ready", "emit pending incoming patches", "clear pending incoming patches"],
|
|
6998
6917
|
on: {
|
|
6999
6918
|
"internal.patch": {
|
|
@@ -7018,10 +6937,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
7018
6937
|
states: {
|
|
7019
6938
|
idle: {
|
|
7020
6939
|
entry: [() => {
|
|
7021
|
-
debug$
|
|
6940
|
+
debug$8("entry: setup->set up->value sync->idle");
|
|
7022
6941
|
}],
|
|
7023
6942
|
exit: [() => {
|
|
7024
|
-
debug$
|
|
6943
|
+
debug$8("exit: setup->set up->value sync->idle");
|
|
7025
6944
|
}],
|
|
7026
6945
|
on: {
|
|
7027
6946
|
patches: {
|
|
@@ -7036,10 +6955,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
7036
6955
|
},
|
|
7037
6956
|
"syncing value": {
|
|
7038
6957
|
entry: [() => {
|
|
7039
|
-
debug$
|
|
6958
|
+
debug$8("entry: setup->set up->value sync->syncing value");
|
|
7040
6959
|
}],
|
|
7041
6960
|
exit: [() => {
|
|
7042
|
-
debug$
|
|
6961
|
+
debug$8("exit: setup->set up->value sync->syncing value");
|
|
7043
6962
|
}, "emit pending incoming patches", "clear pending incoming patches"],
|
|
7044
6963
|
on: {
|
|
7045
6964
|
patches: {
|
|
@@ -7060,10 +6979,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
7060
6979
|
states: {
|
|
7061
6980
|
idle: {
|
|
7062
6981
|
entry: [() => {
|
|
7063
|
-
debug$
|
|
6982
|
+
debug$8("entry: setup->set up->writing->pristine->idle");
|
|
7064
6983
|
}],
|
|
7065
6984
|
exit: [() => {
|
|
7066
|
-
debug$
|
|
6985
|
+
debug$8("exit: setup->set up->writing->pristine->idle");
|
|
7067
6986
|
}],
|
|
7068
6987
|
on: {
|
|
7069
6988
|
normalizing: {
|
|
@@ -7081,10 +7000,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
7081
7000
|
},
|
|
7082
7001
|
normalizing: {
|
|
7083
7002
|
entry: [() => {
|
|
7084
|
-
debug$
|
|
7003
|
+
debug$8("entry: setup->set up->writing->pristine->normalizing");
|
|
7085
7004
|
}],
|
|
7086
7005
|
exit: [() => {
|
|
7087
|
-
debug$
|
|
7006
|
+
debug$8("exit: setup->set up->writing->pristine->normalizing");
|
|
7088
7007
|
}],
|
|
7089
7008
|
on: {
|
|
7090
7009
|
"done normalizing": {
|
|
@@ -7102,10 +7021,10 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
7102
7021
|
},
|
|
7103
7022
|
dirty: {
|
|
7104
7023
|
entry: [() => {
|
|
7105
|
-
debug$
|
|
7024
|
+
debug$8("entry: setup->set up->writing->dirty");
|
|
7106
7025
|
}, "emit pending events", "clear pending events"],
|
|
7107
7026
|
exit: [() => {
|
|
7108
|
-
debug$
|
|
7027
|
+
debug$8("exit: setup->set up->writing->dirty");
|
|
7109
7028
|
}],
|
|
7110
7029
|
on: {
|
|
7111
7030
|
"internal.patch": {
|
|
@@ -7358,7 +7277,7 @@ function getEditorSnapshot({
|
|
|
7358
7277
|
}
|
|
7359
7278
|
};
|
|
7360
7279
|
}
|
|
7361
|
-
const mutationMachine = xstate.setup({
|
|
7280
|
+
const debug$7 = debugWithName("mutation-machine"), mutationMachine = xstate.setup({
|
|
7362
7281
|
types: {
|
|
7363
7282
|
context: {},
|
|
7364
7283
|
events: {},
|
|
@@ -7366,8 +7285,23 @@ const mutationMachine = xstate.setup({
|
|
|
7366
7285
|
emitted: {}
|
|
7367
7286
|
},
|
|
7368
7287
|
actions: {
|
|
7369
|
-
"
|
|
7370
|
-
|
|
7288
|
+
"assign readOnly": xstate.assign({
|
|
7289
|
+
readOnly: ({
|
|
7290
|
+
context,
|
|
7291
|
+
event
|
|
7292
|
+
}) => event.type === "update readOnly" ? event.readOnly : context.readOnly
|
|
7293
|
+
}),
|
|
7294
|
+
"emit patch": xstate.enqueueActions(({
|
|
7295
|
+
event,
|
|
7296
|
+
enqueue
|
|
7297
|
+
}) => {
|
|
7298
|
+
event.type === "patch" && enqueue.emit({
|
|
7299
|
+
type: "patch",
|
|
7300
|
+
patch: event.patch
|
|
7301
|
+
});
|
|
7302
|
+
}),
|
|
7303
|
+
"emit has pending mutations": xstate.emit({
|
|
7304
|
+
type: "has pending mutations"
|
|
7371
7305
|
}),
|
|
7372
7306
|
"emit mutations": xstate.enqueueActions(({
|
|
7373
7307
|
context,
|
|
@@ -7383,7 +7317,7 @@ const mutationMachine = xstate.setup({
|
|
|
7383
7317
|
"clear pending mutations": xstate.assign({
|
|
7384
7318
|
pendingMutations: []
|
|
7385
7319
|
}),
|
|
7386
|
-
"defer
|
|
7320
|
+
"defer mutation": xstate.assign({
|
|
7387
7321
|
pendingMutations: ({
|
|
7388
7322
|
context,
|
|
7389
7323
|
event
|
|
@@ -7405,6 +7339,22 @@ const mutationMachine = xstate.setup({
|
|
|
7405
7339
|
patches: [event.patch]
|
|
7406
7340
|
});
|
|
7407
7341
|
}
|
|
7342
|
+
}),
|
|
7343
|
+
"clear pending patch events": xstate.assign({
|
|
7344
|
+
pendingPatchEvents: []
|
|
7345
|
+
}),
|
|
7346
|
+
"defer patch": xstate.assign({
|
|
7347
|
+
pendingPatchEvents: ({
|
|
7348
|
+
context,
|
|
7349
|
+
event
|
|
7350
|
+
}) => event.type === "patch" ? [...context.pendingPatchEvents, event] : context.pendingPatchEvents
|
|
7351
|
+
}),
|
|
7352
|
+
"emit pending patch events": xstate.enqueueActions(({
|
|
7353
|
+
context,
|
|
7354
|
+
enqueue
|
|
7355
|
+
}) => {
|
|
7356
|
+
for (const event of context.pendingPatchEvents)
|
|
7357
|
+
enqueue.emit(event);
|
|
7408
7358
|
})
|
|
7409
7359
|
},
|
|
7410
7360
|
actors: {
|
|
@@ -7425,6 +7375,9 @@ const mutationMachine = xstate.setup({
|
|
|
7425
7375
|
})
|
|
7426
7376
|
},
|
|
7427
7377
|
guards: {
|
|
7378
|
+
"is read-only": ({
|
|
7379
|
+
context
|
|
7380
|
+
}) => context.readOnly,
|
|
7428
7381
|
"is typing": xstate.stateIn({
|
|
7429
7382
|
typing: "typing"
|
|
7430
7383
|
}),
|
|
@@ -7445,9 +7398,16 @@ const mutationMachine = xstate.setup({
|
|
|
7445
7398
|
input
|
|
7446
7399
|
}) => ({
|
|
7447
7400
|
pendingMutations: [],
|
|
7401
|
+
pendingPatchEvents: [],
|
|
7402
|
+
readOnly: input.readOnly,
|
|
7448
7403
|
schema: input.schema,
|
|
7449
7404
|
slateEditor: input.slateEditor
|
|
7450
7405
|
}),
|
|
7406
|
+
on: {
|
|
7407
|
+
"update readOnly": {
|
|
7408
|
+
actions: ["assign readOnly"]
|
|
7409
|
+
}
|
|
7410
|
+
},
|
|
7451
7411
|
type: "parallel",
|
|
7452
7412
|
states: {
|
|
7453
7413
|
typing: {
|
|
@@ -7462,6 +7422,12 @@ const mutationMachine = xstate.setup({
|
|
|
7462
7422
|
},
|
|
7463
7423
|
states: {
|
|
7464
7424
|
idle: {
|
|
7425
|
+
entry: [() => {
|
|
7426
|
+
debug$7("entry: typing->idle");
|
|
7427
|
+
}],
|
|
7428
|
+
exit: [() => {
|
|
7429
|
+
debug$7("exit: typing->idle");
|
|
7430
|
+
}],
|
|
7465
7431
|
on: {
|
|
7466
7432
|
typing: {
|
|
7467
7433
|
target: "typing"
|
|
@@ -7469,6 +7435,12 @@ const mutationMachine = xstate.setup({
|
|
|
7469
7435
|
}
|
|
7470
7436
|
},
|
|
7471
7437
|
typing: {
|
|
7438
|
+
entry: [() => {
|
|
7439
|
+
debug$7("entry: typing->typing");
|
|
7440
|
+
}],
|
|
7441
|
+
exit: [() => {
|
|
7442
|
+
debug$7("exit: typing->typing");
|
|
7443
|
+
}],
|
|
7472
7444
|
after: {
|
|
7473
7445
|
"type debounce": {
|
|
7474
7446
|
target: "idle"
|
|
@@ -7490,16 +7462,31 @@ const mutationMachine = xstate.setup({
|
|
|
7490
7462
|
initial: "idle",
|
|
7491
7463
|
states: {
|
|
7492
7464
|
idle: {
|
|
7465
|
+
entry: [() => {
|
|
7466
|
+
debug$7("entry: mutations->idle");
|
|
7467
|
+
}],
|
|
7468
|
+
exit: [() => {
|
|
7469
|
+
debug$7("exit: mutations->idle");
|
|
7470
|
+
}],
|
|
7493
7471
|
on: {
|
|
7494
7472
|
patch: {
|
|
7495
|
-
actions: ["
|
|
7473
|
+
actions: ["emit patch", "defer mutation", "emit has pending mutations"],
|
|
7496
7474
|
target: "emitting mutations"
|
|
7497
7475
|
}
|
|
7498
7476
|
}
|
|
7499
7477
|
},
|
|
7500
7478
|
"emitting mutations": {
|
|
7479
|
+
entry: [() => {
|
|
7480
|
+
debug$7("entry: mutations->emitting mutations");
|
|
7481
|
+
}],
|
|
7482
|
+
exit: [() => {
|
|
7483
|
+
debug$7("exit: mutations->emitting mutations");
|
|
7484
|
+
}],
|
|
7501
7485
|
after: {
|
|
7502
7486
|
"mutation debounce": [{
|
|
7487
|
+
guard: "is read-only",
|
|
7488
|
+
target: "read-only"
|
|
7489
|
+
}, {
|
|
7503
7490
|
guard: xstate.and([xstate.not("is typing"), "slate is normalizing"]),
|
|
7504
7491
|
target: "idle",
|
|
7505
7492
|
actions: ["emit mutations", "clear pending mutations"]
|
|
@@ -7511,10 +7498,28 @@ const mutationMachine = xstate.setup({
|
|
|
7511
7498
|
on: {
|
|
7512
7499
|
patch: {
|
|
7513
7500
|
target: "emitting mutations",
|
|
7514
|
-
actions: ["
|
|
7501
|
+
actions: ["emit patch", "defer mutation"],
|
|
7515
7502
|
reenter: !0
|
|
7516
7503
|
}
|
|
7517
7504
|
}
|
|
7505
|
+
},
|
|
7506
|
+
"read-only": {
|
|
7507
|
+
entry: [() => {
|
|
7508
|
+
debug$7("entry: mutations->read-only");
|
|
7509
|
+
}],
|
|
7510
|
+
exit: [() => {
|
|
7511
|
+
debug$7("exit: mutations->read-only");
|
|
7512
|
+
}],
|
|
7513
|
+
always: [{
|
|
7514
|
+
guard: xstate.not("is read-only"),
|
|
7515
|
+
target: "emitting mutations",
|
|
7516
|
+
actions: ["emit pending patch events", "clear pending patch events"]
|
|
7517
|
+
}],
|
|
7518
|
+
on: {
|
|
7519
|
+
patch: {
|
|
7520
|
+
actions: ["defer patch", "defer mutation"]
|
|
7521
|
+
}
|
|
7522
|
+
}
|
|
7518
7523
|
}
|
|
7519
7524
|
}
|
|
7520
7525
|
}
|
|
@@ -7881,6 +7886,21 @@ function isAnnotationActive({
|
|
|
7881
7886
|
return !1;
|
|
7882
7887
|
}
|
|
7883
7888
|
}
|
|
7889
|
+
const relayMachine = xstate.setup({
|
|
7890
|
+
types: {
|
|
7891
|
+
events: {},
|
|
7892
|
+
emitted: {}
|
|
7893
|
+
}
|
|
7894
|
+
}).createMachine({
|
|
7895
|
+
id: "relay",
|
|
7896
|
+
on: {
|
|
7897
|
+
"*": {
|
|
7898
|
+
actions: xstate.emit(({
|
|
7899
|
+
event
|
|
7900
|
+
}) => event)
|
|
7901
|
+
}
|
|
7902
|
+
}
|
|
7903
|
+
});
|
|
7884
7904
|
function validateValue(value, types2, keyGenerator) {
|
|
7885
7905
|
let resolution = null, valid = !0;
|
|
7886
7906
|
const validChildTypes = [types2.span.name, ...types2.inlineObjects.map((t) => t.name)], validBlockTypes = [types2.block.name, ...types2.blockObjects.map((t) => t.name)];
|
|
@@ -8317,7 +8337,7 @@ const debug$5 = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
8317
8337
|
value: context.initialValue
|
|
8318
8338
|
}))],
|
|
8319
8339
|
on: {
|
|
8320
|
-
"has pending
|
|
8340
|
+
"has pending mutations": {
|
|
8321
8341
|
actions: xstate.assign({
|
|
8322
8342
|
isProcessingLocalChanges: !0
|
|
8323
8343
|
})
|
|
@@ -8708,40 +8728,20 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
8708
8728
|
}
|
|
8709
8729
|
}
|
|
8710
8730
|
const debug$4 = debugWithName("setup");
|
|
8711
|
-
function compileSchemasFromEditorConfig(config) {
|
|
8712
|
-
const legacySchema = config.schemaDefinition ? compileSchemaDefinitionToLegacySchema(config.schemaDefinition) : createLegacySchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), schema2 = legacySchemaToEditorSchema(legacySchema);
|
|
8713
|
-
return {
|
|
8714
|
-
legacySchema,
|
|
8715
|
-
schema: schema2
|
|
8716
|
-
};
|
|
8717
|
-
}
|
|
8718
|
-
function editorConfigToMachineInput(config) {
|
|
8719
|
-
const {
|
|
8720
|
-
legacySchema,
|
|
8721
|
-
schema: schema2
|
|
8722
|
-
} = compileSchemasFromEditorConfig(config);
|
|
8723
|
-
return {
|
|
8724
|
-
converters: createCoreConverters(legacySchema),
|
|
8725
|
-
getLegacySchema: () => legacySchema,
|
|
8726
|
-
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
8727
|
-
maxBlocks: config.maxBlocks,
|
|
8728
|
-
readOnly: config.readOnly,
|
|
8729
|
-
schema: schema2,
|
|
8730
|
-
initialValue: config.initialValue
|
|
8731
|
-
};
|
|
8732
|
-
}
|
|
8733
8731
|
function createInternalEditor(config) {
|
|
8734
8732
|
debug$4("Creating new Editor instance");
|
|
8735
8733
|
const subscriptions = [], editorActor = xstate.createActor(editorMachine, {
|
|
8736
8734
|
input: editorConfigToMachineInput(config)
|
|
8737
|
-
}), slateEditor = createSlateEditor({
|
|
8735
|
+
}), relayActor = xstate.createActor(relayMachine), slateEditor = createSlateEditor({
|
|
8738
8736
|
editorActor,
|
|
8737
|
+
relayActor,
|
|
8739
8738
|
subscriptions
|
|
8740
8739
|
}), editable = createEditableAPI(slateEditor.instance, editorActor), {
|
|
8741
8740
|
mutationActor,
|
|
8742
8741
|
syncActor
|
|
8743
8742
|
} = createActors({
|
|
8744
8743
|
editorActor,
|
|
8744
|
+
relayActor,
|
|
8745
8745
|
slateEditor: slateEditor.instance,
|
|
8746
8746
|
subscriptions
|
|
8747
8747
|
});
|
|
@@ -8749,6 +8749,7 @@ function createInternalEditor(config) {
|
|
|
8749
8749
|
actors: {
|
|
8750
8750
|
editorActor,
|
|
8751
8751
|
mutationActor,
|
|
8752
|
+
relayActor,
|
|
8752
8753
|
syncActor
|
|
8753
8754
|
},
|
|
8754
8755
|
editor: {
|
|
@@ -8782,10 +8783,8 @@ function createInternalEditor(config) {
|
|
|
8782
8783
|
case "update value":
|
|
8783
8784
|
syncActor.send(event);
|
|
8784
8785
|
break;
|
|
8785
|
-
case "update key generator":
|
|
8786
8786
|
case "update readOnly":
|
|
8787
8787
|
case "patches":
|
|
8788
|
-
case "update schema":
|
|
8789
8788
|
case "update maxBlocks":
|
|
8790
8789
|
editorActor.send(event);
|
|
8791
8790
|
break;
|
|
@@ -8823,12 +8822,11 @@ function createInternalEditor(config) {
|
|
|
8823
8822
|
});
|
|
8824
8823
|
}
|
|
8825
8824
|
},
|
|
8826
|
-
on: (event, listener) =>
|
|
8825
|
+
on: (event, listener) => relayActor.on(event, (event2) => {
|
|
8827
8826
|
switch (event2.type) {
|
|
8828
8827
|
case "blurred":
|
|
8829
8828
|
case "done loading":
|
|
8830
8829
|
case "editable":
|
|
8831
|
-
case "error":
|
|
8832
8830
|
case "focused":
|
|
8833
8831
|
case "invalid value":
|
|
8834
8832
|
case "loading":
|
|
@@ -8851,10 +8849,35 @@ function createInternalEditor(config) {
|
|
|
8851
8849
|
subscriptions
|
|
8852
8850
|
};
|
|
8853
8851
|
}
|
|
8852
|
+
function editorConfigToMachineInput(config) {
|
|
8853
|
+
const {
|
|
8854
|
+
legacySchema,
|
|
8855
|
+
schema: schema2
|
|
8856
|
+
} = compileSchemasFromEditorConfig(config);
|
|
8857
|
+
return {
|
|
8858
|
+
converters: createCoreConverters(legacySchema),
|
|
8859
|
+
getLegacySchema: () => legacySchema,
|
|
8860
|
+
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
8861
|
+
maxBlocks: config.maxBlocks,
|
|
8862
|
+
readOnly: config.readOnly,
|
|
8863
|
+
schema: schema2,
|
|
8864
|
+
initialValue: config.initialValue
|
|
8865
|
+
};
|
|
8866
|
+
}
|
|
8867
|
+
function compileSchemasFromEditorConfig(config) {
|
|
8868
|
+
const legacySchema = config.schemaDefinition ? compileSchemaDefinitionToLegacySchema(config.schemaDefinition) : createLegacySchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), schema2 = legacySchemaToEditorSchema(legacySchema);
|
|
8869
|
+
return {
|
|
8870
|
+
legacySchema,
|
|
8871
|
+
schema: schema2
|
|
8872
|
+
};
|
|
8873
|
+
}
|
|
8854
8874
|
function createActors(config) {
|
|
8855
8875
|
debug$4("Creating new Actors");
|
|
8856
8876
|
const mutationActor = xstate.createActor(mutationMachine, {
|
|
8857
8877
|
input: {
|
|
8878
|
+
readOnly: config.editorActor.getSnapshot().matches({
|
|
8879
|
+
"edit mode": "read only"
|
|
8880
|
+
}),
|
|
8858
8881
|
schema: config.editorActor.getSnapshot().context.schema,
|
|
8859
8882
|
slateEditor: config.slateEditor
|
|
8860
8883
|
}
|
|
@@ -8871,8 +8894,8 @@ function createActors(config) {
|
|
|
8871
8894
|
});
|
|
8872
8895
|
return config.subscriptions.push(() => {
|
|
8873
8896
|
const subscription = mutationActor.on("*", (event) => {
|
|
8874
|
-
event.type === "has pending
|
|
8875
|
-
type: "has pending
|
|
8897
|
+
event.type === "has pending mutations" && syncActor.send({
|
|
8898
|
+
type: "has pending mutations"
|
|
8876
8899
|
}), event.type === "mutation" && (syncActor.send({
|
|
8877
8900
|
type: "mutation"
|
|
8878
8901
|
}), config.editorActor.send({
|
|
@@ -8880,7 +8903,17 @@ function createActors(config) {
|
|
|
8880
8903
|
patches: event.patches,
|
|
8881
8904
|
snapshot: event.snapshot,
|
|
8882
8905
|
value: event.snapshot
|
|
8883
|
-
}));
|
|
8906
|
+
})), event.type === "patch" && config.relayActor.send(event);
|
|
8907
|
+
});
|
|
8908
|
+
return () => {
|
|
8909
|
+
subscription.unsubscribe();
|
|
8910
|
+
};
|
|
8911
|
+
}), config.subscriptions.push(() => {
|
|
8912
|
+
const subscription = config.relayActor.on("*", (event) => {
|
|
8913
|
+
event.type === "selection" && config.editorActor.send({
|
|
8914
|
+
type: "update selection",
|
|
8915
|
+
selection: event.selection
|
|
8916
|
+
});
|
|
8884
8917
|
});
|
|
8885
8918
|
return () => {
|
|
8886
8919
|
subscription.unsubscribe();
|
|
@@ -8889,16 +8922,10 @@ function createActors(config) {
|
|
|
8889
8922
|
const subscription = syncActor.on("*", (event) => {
|
|
8890
8923
|
switch (event.type) {
|
|
8891
8924
|
case "invalid value":
|
|
8892
|
-
config.
|
|
8893
|
-
...event,
|
|
8894
|
-
type: "notify.invalid value"
|
|
8895
|
-
});
|
|
8925
|
+
config.relayActor.send(event);
|
|
8896
8926
|
break;
|
|
8897
8927
|
case "value changed":
|
|
8898
|
-
config.
|
|
8899
|
-
...event,
|
|
8900
|
-
type: "notify.value changed"
|
|
8901
|
-
});
|
|
8928
|
+
config.relayActor.send(event);
|
|
8902
8929
|
break;
|
|
8903
8930
|
case "patch":
|
|
8904
8931
|
config.editorActor.send({
|
|
@@ -8918,30 +8945,46 @@ function createActors(config) {
|
|
|
8918
8945
|
const subscription = config.editorActor.subscribe((snapshot) => {
|
|
8919
8946
|
snapshot.matches({
|
|
8920
8947
|
"edit mode": "read only"
|
|
8921
|
-
}) ?
|
|
8948
|
+
}) ? (mutationActor.send({
|
|
8922
8949
|
type: "update readOnly",
|
|
8923
8950
|
readOnly: !0
|
|
8924
|
-
})
|
|
8951
|
+
}), syncActor.send({
|
|
8952
|
+
type: "update readOnly",
|
|
8953
|
+
readOnly: !0
|
|
8954
|
+
})) : (mutationActor.send({
|
|
8925
8955
|
type: "update readOnly",
|
|
8926
8956
|
readOnly: !1
|
|
8927
|
-
})
|
|
8957
|
+
}), syncActor.send({
|
|
8958
|
+
type: "update readOnly",
|
|
8959
|
+
readOnly: !1
|
|
8960
|
+
}));
|
|
8928
8961
|
});
|
|
8929
8962
|
return () => {
|
|
8930
8963
|
subscription.unsubscribe();
|
|
8931
8964
|
};
|
|
8932
8965
|
}), config.subscriptions.push(() => {
|
|
8933
8966
|
const subscription = config.editorActor.on("*", (event) => {
|
|
8934
|
-
event.type
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8967
|
+
switch (event.type) {
|
|
8968
|
+
case "editable":
|
|
8969
|
+
case "mutation":
|
|
8970
|
+
case "ready":
|
|
8971
|
+
case "read only":
|
|
8972
|
+
config.relayActor.send(event);
|
|
8973
|
+
break;
|
|
8974
|
+
case "internal.patch":
|
|
8975
|
+
mutationActor.send({
|
|
8976
|
+
...event,
|
|
8977
|
+
type: "patch"
|
|
8978
|
+
});
|
|
8979
|
+
break;
|
|
8980
|
+
}
|
|
8938
8981
|
});
|
|
8939
8982
|
return () => {
|
|
8940
8983
|
subscription.unsubscribe();
|
|
8941
8984
|
};
|
|
8942
8985
|
}), {
|
|
8943
|
-
|
|
8944
|
-
|
|
8986
|
+
mutationActor,
|
|
8987
|
+
syncActor
|
|
8945
8988
|
};
|
|
8946
8989
|
}
|
|
8947
8990
|
const PortableTextEditorSelectionContext = React.createContext(null), usePortableTextEditorSelection = () => {
|
|
@@ -8967,23 +9010,24 @@ function PortableTextEditorSelectionProvider(props) {
|
|
|
8967
9010
|
let t2;
|
|
8968
9011
|
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
8969
9012
|
}
|
|
9013
|
+
const RelayActorContext = React.createContext({});
|
|
8970
9014
|
function RouteEventsToChanges(props) {
|
|
8971
9015
|
const $ = reactCompilerRuntime.c(7);
|
|
8972
9016
|
let t0;
|
|
8973
9017
|
$[0] !== props ? (t0 = (change) => props.onChange(change), $[0] = props, $[1] = t0) : t0 = $[1];
|
|
8974
9018
|
const handleChange = useEffectEvent.useEffectEvent(t0);
|
|
8975
9019
|
let t1;
|
|
8976
|
-
$[2] !== handleChange || $[3] !== props.
|
|
8977
|
-
const sub = props.
|
|
9020
|
+
$[2] !== handleChange || $[3] !== props.relayActor ? (t1 = () => {
|
|
9021
|
+
const sub = props.relayActor.on("*", (event) => {
|
|
8978
9022
|
const change_0 = eventToChange(event);
|
|
8979
9023
|
change_0 && handleChange(change_0);
|
|
8980
9024
|
});
|
|
8981
9025
|
return () => {
|
|
8982
9026
|
sub.unsubscribe();
|
|
8983
9027
|
};
|
|
8984
|
-
}, $[2] = handleChange, $[3] = props.
|
|
9028
|
+
}, $[2] = handleChange, $[3] = props.relayActor, $[4] = t1) : t1 = $[4];
|
|
8985
9029
|
let t2;
|
|
8986
|
-
return $[5] !== props.
|
|
9030
|
+
return $[5] !== props.relayActor ? (t2 = [props.relayActor], $[5] = props.relayActor, $[6] = t2) : t2 = $[6], React.useEffect(t1, t2), null;
|
|
8987
9031
|
}
|
|
8988
9032
|
function eventToChange(event) {
|
|
8989
9033
|
switch (event.type) {
|
|
@@ -9020,11 +9064,6 @@ function eventToChange(event) {
|
|
|
9020
9064
|
resolution: event.resolution,
|
|
9021
9065
|
value: event.value
|
|
9022
9066
|
};
|
|
9023
|
-
case "error":
|
|
9024
|
-
return {
|
|
9025
|
-
...event,
|
|
9026
|
-
level: "warning"
|
|
9027
|
-
};
|
|
9028
9067
|
case "mutation":
|
|
9029
9068
|
return event;
|
|
9030
9069
|
case "ready":
|
|
@@ -9068,7 +9107,7 @@ class PortableTextEditor extends React.Component {
|
|
|
9068
9107
|
schema: props.schemaType
|
|
9069
9108
|
});
|
|
9070
9109
|
this.unsubscribers.push((() => {
|
|
9071
|
-
const subscription = actors.
|
|
9110
|
+
const subscription = actors.relayActor.on("*", (event) => {
|
|
9072
9111
|
const change = eventToChange(event);
|
|
9073
9112
|
change && (props.onChange(change), this.change$.next(change));
|
|
9074
9113
|
});
|
|
@@ -9083,13 +9122,10 @@ class PortableTextEditor extends React.Component {
|
|
|
9083
9122
|
this.editable = this.editor._internal.editable;
|
|
9084
9123
|
}
|
|
9085
9124
|
componentDidMount() {
|
|
9086
|
-
this.actors && (this.actors.editorActor.start(), this.actors.mutationActor.start(), this.actors.syncActor.start());
|
|
9125
|
+
this.actors && (this.actors.editorActor.start(), this.actors.mutationActor.start(), this.actors.relayActor.start(), this.actors.syncActor.start());
|
|
9087
9126
|
}
|
|
9088
9127
|
componentDidUpdate(prevProps) {
|
|
9089
|
-
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (
|
|
9090
|
-
type: "update schema",
|
|
9091
|
-
schema: legacySchemaToEditorSchema(this.schemaTypes)
|
|
9092
|
-
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
9128
|
+
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && console.warn("Updating schema type is no longer supported"), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
9093
9129
|
type: "update readOnly",
|
|
9094
9130
|
readOnly: this.props.readOnly ?? !1
|
|
9095
9131
|
}), this.props.maxBlocks !== prevProps.maxBlocks && this.editor._internal.editorActor.send({
|
|
@@ -9103,7 +9139,7 @@ class PortableTextEditor extends React.Component {
|
|
|
9103
9139
|
componentWillUnmount() {
|
|
9104
9140
|
for (const unsubscribe of this.unsubscribers)
|
|
9105
9141
|
unsubscribe();
|
|
9106
|
-
this.actors && (stopActor(this.actors.editorActor), stopActor(this.actors.mutationActor), stopActor(this.actors.syncActor));
|
|
9142
|
+
this.actors && (stopActor(this.actors.editorActor), stopActor(this.actors.mutationActor), stopActor(this.actors.relayActor), stopActor(this.actors.syncActor));
|
|
9107
9143
|
}
|
|
9108
9144
|
setEditable = (editable) => {
|
|
9109
9145
|
this.editor._internal.editable = {
|
|
@@ -9115,7 +9151,7 @@ class PortableTextEditor extends React.Component {
|
|
|
9115
9151
|
const legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
|
|
9116
9152
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
9117
9153
|
legacyPatches ? /* @__PURE__ */ jsxRuntime.jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editor._internal.editorActor, patches$: legacyPatches }) : null,
|
|
9118
|
-
/* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
|
|
9154
|
+
/* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsxRuntime.jsx(RelayActorContext.Provider, { value: this.actors.relayActor, children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) }) })
|
|
9119
9155
|
] });
|
|
9120
9156
|
}
|
|
9121
9157
|
/**
|
|
@@ -9964,7 +10000,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
9964
10000
|
...restProps
|
|
9965
10001
|
} = props, portableTextEditor = usePortableTextEditor(), ref = React.useRef(null), [editableElement, setEditableElement] = React.useState(null), [hasInvalidValue, setHasInvalidValue] = React.useState(!1);
|
|
9966
10002
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
9967
|
-
const editorActor = React.useContext(EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.matches({
|
|
10003
|
+
const editorActor = React.useContext(EditorActorContext), relayActor = React.useContext(RelayActorContext), readOnly = react.useSelector(editorActor, (s) => s.matches({
|
|
9968
10004
|
"edit mode": "read only"
|
|
9969
10005
|
})), slateEditor = slateReact.useSlate(), rangeDecorationsActor = react.useActorRef(rangeDecorationsMachine, {
|
|
9970
10006
|
input: {
|
|
@@ -9997,13 +10033,13 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
9997
10033
|
if (normalizedSelection !== null) {
|
|
9998
10034
|
debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
9999
10035
|
const slateRange = toSlateRange(normalizedSelection, slateEditor);
|
|
10000
|
-
slateRange && (slate.Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") ||
|
|
10001
|
-
type: "
|
|
10036
|
+
slateRange && (slate.Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") || relayActor.send({
|
|
10037
|
+
type: "selection",
|
|
10002
10038
|
selection: normalizedSelection
|
|
10003
10039
|
}), slateEditor.onChange());
|
|
10004
10040
|
}
|
|
10005
10041
|
}
|
|
10006
|
-
}, [editorActor, propsSelection, slateEditor]);
|
|
10042
|
+
}, [editorActor, propsSelection, relayActor, slateEditor]);
|
|
10007
10043
|
React.useEffect(() => {
|
|
10008
10044
|
const onReady = editorActor.on("ready", () => {
|
|
10009
10045
|
rangeDecorationsActor.send({
|
|
@@ -10086,8 +10122,8 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
10086
10122
|
schemaTypes: portableTextEditor.schemaTypes
|
|
10087
10123
|
});
|
|
10088
10124
|
if (onPasteResult || !slateEditor.selection)
|
|
10089
|
-
event_1.preventDefault(),
|
|
10090
|
-
type: "
|
|
10125
|
+
event_1.preventDefault(), relayActor.send({
|
|
10126
|
+
type: "loading"
|
|
10091
10127
|
}), Promise.resolve(onPasteResult).then((result_1) => {
|
|
10092
10128
|
if (debug("Custom paste function from client resolved", result_1), !result_1 || !result_1.insert) {
|
|
10093
10129
|
debug("No result from custom paste handler, pasting normally");
|
|
@@ -10130,8 +10166,8 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
10130
10166
|
editor: slateEditor
|
|
10131
10167
|
}) : console.warn("Your onPaste function returned something unexpected:", result_1);
|
|
10132
10168
|
}).catch((error) => (console.warn(error), error)).finally(() => {
|
|
10133
|
-
|
|
10134
|
-
type: "
|
|
10169
|
+
relayActor.send({
|
|
10170
|
+
type: "done loading"
|
|
10135
10171
|
});
|
|
10136
10172
|
});
|
|
10137
10173
|
else if (event_1.nativeEvent.clipboardData) {
|
|
@@ -10157,20 +10193,20 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
10157
10193
|
});
|
|
10158
10194
|
}
|
|
10159
10195
|
debug("No result from custom paste handler, pasting normally");
|
|
10160
|
-
}, [editorActor, onPaste, portableTextEditor, slateEditor]), handleOnFocus = React.useCallback((event_2) => {
|
|
10196
|
+
}, [editorActor, onPaste, portableTextEditor, relayActor, slateEditor]), handleOnFocus = React.useCallback((event_2) => {
|
|
10161
10197
|
if (onFocus && onFocus(event_2), !event_2.isDefaultPrevented()) {
|
|
10162
10198
|
const selection_3 = PortableTextEditor.getSelection(portableTextEditor);
|
|
10163
|
-
selection_3 === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()),
|
|
10164
|
-
type: "
|
|
10199
|
+
selection_3 === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()), relayActor.send({
|
|
10200
|
+
type: "focused",
|
|
10165
10201
|
event: event_2
|
|
10166
10202
|
});
|
|
10167
10203
|
const newSelection = PortableTextEditor.getSelection(portableTextEditor);
|
|
10168
|
-
selection_3 === newSelection &&
|
|
10169
|
-
type: "
|
|
10204
|
+
selection_3 === newSelection && relayActor.send({
|
|
10205
|
+
type: "selection",
|
|
10170
10206
|
selection: selection_3
|
|
10171
10207
|
});
|
|
10172
10208
|
}
|
|
10173
|
-
}, [
|
|
10209
|
+
}, [onFocus, slateEditor, portableTextEditor, relayActor]), handleClick = React.useCallback((event_3) => {
|
|
10174
10210
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
10175
10211
|
return;
|
|
10176
10212
|
const position_3 = getEventPosition({
|
|
@@ -10188,11 +10224,11 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
10188
10224
|
nativeEvent: event_3
|
|
10189
10225
|
});
|
|
10190
10226
|
}, [onClick, editorActor, slateEditor]), handleOnBlur = React.useCallback((event_4) => {
|
|
10191
|
-
onBlur && onBlur(event_4), event_4.isPropagationStopped() ||
|
|
10192
|
-
type: "
|
|
10227
|
+
onBlur && onBlur(event_4), event_4.isPropagationStopped() || relayActor.send({
|
|
10228
|
+
type: "blurred",
|
|
10193
10229
|
event: event_4
|
|
10194
10230
|
});
|
|
10195
|
-
}, [
|
|
10231
|
+
}, [relayActor, onBlur]), handleOnBeforeInput = React.useCallback((event_5) => {
|
|
10196
10232
|
onBeforeInput && onBeforeInput(event_5);
|
|
10197
10233
|
}, [onBeforeInput]), validateSelection = React.useCallback(() => {
|
|
10198
10234
|
if (!slateEditor.selection)
|
|
@@ -10516,7 +10552,7 @@ function useConstant(factory) {
|
|
|
10516
10552
|
}), ref.current.constant;
|
|
10517
10553
|
}
|
|
10518
10554
|
function EditorProvider(props) {
|
|
10519
|
-
const $ = reactCompilerRuntime.c(
|
|
10555
|
+
const $ = reactCompilerRuntime.c(35);
|
|
10520
10556
|
let t0;
|
|
10521
10557
|
$[0] !== props.initialConfig ? (t0 = () => {
|
|
10522
10558
|
const internalEditor = createInternalEditor(props.initialConfig), portableTextEditor = new PortableTextEditor({
|
|
@@ -10532,37 +10568,39 @@ function EditorProvider(props) {
|
|
|
10532
10568
|
portableTextEditor: portableTextEditor_0
|
|
10533
10569
|
} = useConstant(t0);
|
|
10534
10570
|
let t1;
|
|
10535
|
-
$[2] !== internalEditor_0.actors.editorActor || $[3] !== internalEditor_0.actors.mutationActor || $[4] !== internalEditor_0.actors.
|
|
10571
|
+
$[2] !== internalEditor_0.actors.editorActor || $[3] !== internalEditor_0.actors.mutationActor || $[4] !== internalEditor_0.actors.relayActor || $[5] !== internalEditor_0.actors.syncActor || $[6] !== internalEditor_0.subscriptions ? (t1 = () => {
|
|
10536
10572
|
const unsubscribers = [];
|
|
10537
10573
|
for (const subscription of internalEditor_0.subscriptions)
|
|
10538
10574
|
unsubscribers.push(subscription());
|
|
10539
|
-
return internalEditor_0.actors.editorActor.start(), internalEditor_0.actors.mutationActor.start(), internalEditor_0.actors.syncActor.start(), () => {
|
|
10575
|
+
return internalEditor_0.actors.editorActor.start(), internalEditor_0.actors.mutationActor.start(), internalEditor_0.actors.relayActor.start(), internalEditor_0.actors.syncActor.start(), () => {
|
|
10540
10576
|
for (const unsubscribe of unsubscribers)
|
|
10541
10577
|
unsubscribe();
|
|
10542
|
-
stopActor(internalEditor_0.actors.editorActor), stopActor(internalEditor_0.actors.mutationActor), stopActor(internalEditor_0.actors.syncActor);
|
|
10578
|
+
stopActor(internalEditor_0.actors.editorActor), stopActor(internalEditor_0.actors.mutationActor), stopActor(internalEditor_0.actors.relayActor), stopActor(internalEditor_0.actors.syncActor);
|
|
10543
10579
|
};
|
|
10544
|
-
}, $[2] = internalEditor_0.actors.editorActor, $[3] = internalEditor_0.actors.mutationActor, $[4] = internalEditor_0.actors.
|
|
10580
|
+
}, $[2] = internalEditor_0.actors.editorActor, $[3] = internalEditor_0.actors.mutationActor, $[4] = internalEditor_0.actors.relayActor, $[5] = internalEditor_0.actors.syncActor, $[6] = internalEditor_0.subscriptions, $[7] = t1) : t1 = $[7];
|
|
10545
10581
|
let t2;
|
|
10546
|
-
$[
|
|
10582
|
+
$[8] !== internalEditor_0 ? (t2 = [internalEditor_0], $[8] = internalEditor_0, $[9] = t2) : t2 = $[9], React.useEffect(t1, t2);
|
|
10547
10583
|
let t3;
|
|
10548
|
-
$[
|
|
10584
|
+
$[10] !== portableTextEditor_0.change$ ? (t3 = (change) => {
|
|
10549
10585
|
portableTextEditor_0.change$.next(change);
|
|
10550
|
-
}, $[
|
|
10586
|
+
}, $[10] = portableTextEditor_0.change$, $[11] = t3) : t3 = $[11];
|
|
10551
10587
|
let t4;
|
|
10552
|
-
$[
|
|
10588
|
+
$[12] !== internalEditor_0.actors.relayActor || $[13] !== t3 ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { relayActor: internalEditor_0.actors.relayActor, onChange: t3 }), $[12] = internalEditor_0.actors.relayActor, $[13] = t3, $[14] = t4) : t4 = $[14];
|
|
10553
10589
|
let t5;
|
|
10554
|
-
$[
|
|
10590
|
+
$[15] !== internalEditor_0.actors.editorActor || $[16] !== props.children ? (t5 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionProvider, { editorActor: internalEditor_0.actors.editorActor, children: props.children }), $[15] = internalEditor_0.actors.editorActor, $[16] = props.children, $[17] = t5) : t5 = $[17];
|
|
10555
10591
|
let t6;
|
|
10556
|
-
$[
|
|
10592
|
+
$[18] !== portableTextEditor_0 || $[19] !== t5 ? (t6 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: portableTextEditor_0, children: t5 }), $[18] = portableTextEditor_0, $[19] = t5, $[20] = t6) : t6 = $[20];
|
|
10557
10593
|
let t7;
|
|
10558
|
-
$[
|
|
10594
|
+
$[21] !== internalEditor_0.editor._internal.slateEditor.initialValue || $[22] !== internalEditor_0.editor._internal.slateEditor.instance || $[23] !== t6 ? (t7 = /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: internalEditor_0.editor._internal.slateEditor.instance, initialValue: internalEditor_0.editor._internal.slateEditor.initialValue, children: t6 }), $[21] = internalEditor_0.editor._internal.slateEditor.initialValue, $[22] = internalEditor_0.editor._internal.slateEditor.instance, $[23] = t6, $[24] = t7) : t7 = $[24];
|
|
10559
10595
|
let t8;
|
|
10560
|
-
$[
|
|
10596
|
+
$[25] !== internalEditor_0.actors.relayActor || $[26] !== t7 ? (t8 = /* @__PURE__ */ jsxRuntime.jsx(RelayActorContext.Provider, { value: internalEditor_0.actors.relayActor, children: t7 }), $[25] = internalEditor_0.actors.relayActor, $[26] = t7, $[27] = t8) : t8 = $[27];
|
|
10561
10597
|
let t9;
|
|
10562
|
-
|
|
10598
|
+
$[28] !== internalEditor_0.actors.editorActor || $[29] !== t8 ? (t9 = /* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: internalEditor_0.actors.editorActor, children: t8 }), $[28] = internalEditor_0.actors.editorActor, $[29] = t8, $[30] = t9) : t9 = $[30];
|
|
10599
|
+
let t10;
|
|
10600
|
+
return $[31] !== internalEditor_0.editor || $[32] !== t4 || $[33] !== t9 ? (t10 = /* @__PURE__ */ jsxRuntime.jsxs(useEditor.EditorContext.Provider, { value: internalEditor_0.editor, children: [
|
|
10563
10601
|
t4,
|
|
10564
|
-
|
|
10565
|
-
] }), $[
|
|
10602
|
+
t9
|
|
10603
|
+
] }), $[31] = internalEditor_0.editor, $[32] = t4, $[33] = t9, $[34] = t10) : t10 = $[34], t10;
|
|
10566
10604
|
}
|
|
10567
10605
|
exports.useEditor = useEditor.useEditor;
|
|
10568
10606
|
exports.EditorEventListener = EditorEventListener;
|