@portabletext/editor 1.48.5 → 1.48.7
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 +109 -112
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +110 -113
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +5 -0
- package/lib/plugins/index.d.ts +5 -0
- package/lib/plugins/index.js.map +1 -1
- package/package.json +3 -3
- package/src/behavior-actions/behavior.action.delete.ts +21 -1
- package/src/behavior-actions/behavior.actions.ts +0 -6
- package/src/behaviors/behavior.perform-event.ts +38 -67
- package/src/behaviors/behavior.types.event.ts +12 -4
- package/src/plugins/plugin.decorator-shortcut.ts +1 -0
- package/src/plugins/plugin.markdown.tsx +2 -0
- package/src/plugins/plugin.one-line.tsx +2 -0
|
@@ -3,7 +3,7 @@ import { useSelector, useActorRef } from "@xstate/react";
|
|
|
3
3
|
import React, { useEffect, createContext, useContext, useState, startTransition, Component, useMemo } from "react";
|
|
4
4
|
import { withReact, ReactEditor, Slate } from "slate-react";
|
|
5
5
|
import { c } from "react-compiler-runtime";
|
|
6
|
-
import debug$
|
|
6
|
+
import debug$f from "debug";
|
|
7
7
|
import isEqual from "lodash/isEqual.js";
|
|
8
8
|
import { Element, Text, Editor, Operation, Transforms, Path, Node, Range, Point, createEditor } from "slate";
|
|
9
9
|
import { setup, stateIn, fromCallback, assign, enqueueActions, emit, assertEvent, and, not, createActor } from "xstate";
|
|
@@ -32,10 +32,10 @@ import { getSelectionStartPoint, getSelectionEndPoint } from "./util.get-selecti
|
|
|
32
32
|
import { Subject } from "rxjs";
|
|
33
33
|
import { useEffectEvent } from "use-effect-event";
|
|
34
34
|
const rootName = "sanity-pte:";
|
|
35
|
-
debug$
|
|
35
|
+
debug$f(rootName);
|
|
36
36
|
function debugWithName(name) {
|
|
37
37
|
const namespace = `${rootName}${name}`;
|
|
38
|
-
return debug$
|
|
38
|
+
return debug$f && debug$f.enabled(namespace) ? debug$f(namespace) : debug$f(rootName);
|
|
39
39
|
}
|
|
40
40
|
const VOID_CHILD_KEY = "void-child";
|
|
41
41
|
function keepObjectEquality(object, keyMap) {
|
|
@@ -1350,7 +1350,7 @@ function withUndoStep(editor, fn) {
|
|
|
1350
1350
|
function getCurrentUndoStepId(editor) {
|
|
1351
1351
|
return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
|
|
1352
1352
|
}
|
|
1353
|
-
const debug$
|
|
1353
|
+
const debug$e = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
1354
1354
|
const state = SAVING.get(editor);
|
|
1355
1355
|
return state === void 0 ? !0 : state;
|
|
1356
1356
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -1363,7 +1363,7 @@ function createWithUndoRedo(options) {
|
|
|
1363
1363
|
const remotePatches = getRemotePatches(editor);
|
|
1364
1364
|
let previousUndoStepId = getCurrentUndoStepId(editor);
|
|
1365
1365
|
options.subscriptions.push(() => {
|
|
1366
|
-
debug$
|
|
1366
|
+
debug$e("Subscribing to patches");
|
|
1367
1367
|
const sub = editorActor.on("patches", ({
|
|
1368
1368
|
patches,
|
|
1369
1369
|
snapshot
|
|
@@ -1372,7 +1372,7 @@ function createWithUndoRedo(options) {
|
|
|
1372
1372
|
patches.forEach((patch) => {
|
|
1373
1373
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
1374
1374
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
1375
|
-
debug$
|
|
1375
|
+
debug$e("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
1376
1376
|
undos: [],
|
|
1377
1377
|
redos: []
|
|
1378
1378
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -1388,7 +1388,7 @@ function createWithUndoRedo(options) {
|
|
|
1388
1388
|
}), previousSnapshot = snapshot;
|
|
1389
1389
|
});
|
|
1390
1390
|
return () => {
|
|
1391
|
-
debug$
|
|
1391
|
+
debug$e("Unsubscribing to patches"), sub.unsubscribe();
|
|
1392
1392
|
};
|
|
1393
1393
|
}), editor.history = {
|
|
1394
1394
|
undos: [],
|
|
@@ -1427,7 +1427,7 @@ function createWithUndoRedo(options) {
|
|
|
1427
1427
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
1428
1428
|
timestamp: /* @__PURE__ */ new Date()
|
|
1429
1429
|
};
|
|
1430
|
-
undos.push(newStep), debug$
|
|
1430
|
+
undos.push(newStep), debug$e("Created new undo step", step);
|
|
1431
1431
|
}
|
|
1432
1432
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
1433
1433
|
undos.shift();
|
|
@@ -1445,7 +1445,7 @@ const historyUndoActionImplementation = ({
|
|
|
1445
1445
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
1446
1446
|
if (undos.length > 0) {
|
|
1447
1447
|
const step = undos[undos.length - 1];
|
|
1448
|
-
if (debug$
|
|
1448
|
+
if (debug$e("Undoing", step), step.operations.length > 0) {
|
|
1449
1449
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
1450
1450
|
let transformedOperations = step.operations;
|
|
1451
1451
|
otherPatches.forEach((item) => {
|
|
@@ -1463,7 +1463,7 @@ const historyUndoActionImplementation = ({
|
|
|
1463
1463
|
});
|
|
1464
1464
|
});
|
|
1465
1465
|
} catch (err) {
|
|
1466
|
-
debug$
|
|
1466
|
+
debug$e("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
1467
1467
|
undos: [],
|
|
1468
1468
|
redos: []
|
|
1469
1469
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -1480,7 +1480,7 @@ const historyUndoActionImplementation = ({
|
|
|
1480
1480
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
1481
1481
|
if (redos.length > 0) {
|
|
1482
1482
|
const step = redos[redos.length - 1];
|
|
1483
|
-
if (debug$
|
|
1483
|
+
if (debug$e("Redoing", step), step.operations.length > 0) {
|
|
1484
1484
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
1485
1485
|
let transformedOperations = step.operations;
|
|
1486
1486
|
otherPatches.forEach((item) => {
|
|
@@ -1497,7 +1497,7 @@ const historyUndoActionImplementation = ({
|
|
|
1497
1497
|
});
|
|
1498
1498
|
});
|
|
1499
1499
|
} catch (err) {
|
|
1500
|
-
debug$
|
|
1500
|
+
debug$e("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
1501
1501
|
undos: [],
|
|
1502
1502
|
redos: []
|
|
1503
1503
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -1515,16 +1515,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
1515
1515
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
1516
1516
|
_key: blk._key
|
|
1517
1517
|
}, patch.path[0]));
|
|
1518
|
-
return debug$
|
|
1518
|
+
return debug$e(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
1519
1519
|
}
|
|
1520
1520
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
1521
1521
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
|
|
1522
1522
|
_key: blk._key
|
|
1523
1523
|
}, patch.path[0]));
|
|
1524
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
1524
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$e("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
1525
1525
|
}
|
|
1526
1526
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
1527
|
-
return debug$
|
|
1527
|
+
return debug$e(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
1528
1528
|
if (patch.type === "diffMatchPatch") {
|
|
1529
1529
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
1530
1530
|
return !operationTargetBlock || !isEqual({
|
|
@@ -1611,7 +1611,7 @@ function findOperationTargetBlock(editor, operation) {
|
|
|
1611
1611
|
let block;
|
|
1612
1612
|
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;
|
|
1613
1613
|
}
|
|
1614
|
-
const debug$
|
|
1614
|
+
const debug$d = debugWithName("sync machine"), syncValueCallback = ({
|
|
1615
1615
|
sendBack,
|
|
1616
1616
|
input
|
|
1617
1617
|
}) => {
|
|
@@ -1663,7 +1663,7 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1663
1663
|
context
|
|
1664
1664
|
}) => {
|
|
1665
1665
|
const editable = !context.readOnly, isProcessingLocalChanges = context.isProcessingLocalChanges, isChanging = isChangingRemotely(context.slateEditor) ?? !1, isBusy = editable && (isProcessingLocalChanges || isChanging);
|
|
1666
|
-
return debug$
|
|
1666
|
+
return debug$d("isBusy", {
|
|
1667
1667
|
isBusy,
|
|
1668
1668
|
editable,
|
|
1669
1669
|
isProcessingLocalChanges,
|
|
@@ -1717,10 +1717,10 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1717
1717
|
states: {
|
|
1718
1718
|
"syncing initial value": {
|
|
1719
1719
|
entry: [() => {
|
|
1720
|
-
debug$
|
|
1720
|
+
debug$d("entry: syncing initial value");
|
|
1721
1721
|
}],
|
|
1722
1722
|
exit: [() => {
|
|
1723
|
-
debug$
|
|
1723
|
+
debug$d("exit: syncing initial value");
|
|
1724
1724
|
}],
|
|
1725
1725
|
always: {
|
|
1726
1726
|
guard: "initial value synced",
|
|
@@ -1729,10 +1729,10 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1729
1729
|
},
|
|
1730
1730
|
"done syncing initial value": {
|
|
1731
1731
|
entry: ["emit done syncing initial value", () => {
|
|
1732
|
-
debug$
|
|
1732
|
+
debug$d("entry: done syncing initial value");
|
|
1733
1733
|
}],
|
|
1734
1734
|
exit: [() => {
|
|
1735
|
-
debug$
|
|
1735
|
+
debug$d("exit: done syncing initial value");
|
|
1736
1736
|
}],
|
|
1737
1737
|
type: "final"
|
|
1738
1738
|
}
|
|
@@ -1743,10 +1743,10 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1743
1743
|
states: {
|
|
1744
1744
|
idle: {
|
|
1745
1745
|
entry: [() => {
|
|
1746
|
-
debug$
|
|
1746
|
+
debug$d("entry: syncing->idle");
|
|
1747
1747
|
}],
|
|
1748
1748
|
exit: [() => {
|
|
1749
|
-
debug$
|
|
1749
|
+
debug$d("exit: syncing->idle");
|
|
1750
1750
|
}],
|
|
1751
1751
|
on: {
|
|
1752
1752
|
"update value": [{
|
|
@@ -1761,10 +1761,10 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1761
1761
|
},
|
|
1762
1762
|
busy: {
|
|
1763
1763
|
entry: [() => {
|
|
1764
|
-
debug$
|
|
1764
|
+
debug$d("entry: syncing->busy");
|
|
1765
1765
|
}],
|
|
1766
1766
|
exit: [() => {
|
|
1767
|
-
debug$
|
|
1767
|
+
debug$d("exit: syncing->busy");
|
|
1768
1768
|
}],
|
|
1769
1769
|
after: {
|
|
1770
1770
|
1e3: [{
|
|
@@ -1772,7 +1772,7 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1772
1772
|
target: ".",
|
|
1773
1773
|
reenter: !0,
|
|
1774
1774
|
actions: [() => {
|
|
1775
|
-
debug$
|
|
1775
|
+
debug$d("reenter: syncing->busy");
|
|
1776
1776
|
}]
|
|
1777
1777
|
}, {
|
|
1778
1778
|
target: "syncing"
|
|
@@ -1786,10 +1786,10 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1786
1786
|
},
|
|
1787
1787
|
syncing: {
|
|
1788
1788
|
entry: [() => {
|
|
1789
|
-
debug$
|
|
1789
|
+
debug$d("entry: syncing->syncing");
|
|
1790
1790
|
}],
|
|
1791
1791
|
exit: [() => {
|
|
1792
|
-
debug$
|
|
1792
|
+
debug$d("exit: syncing->syncing");
|
|
1793
1793
|
}],
|
|
1794
1794
|
always: {
|
|
1795
1795
|
guard: "pending value equals previous value",
|
|
@@ -1856,7 +1856,7 @@ async function updateValue({
|
|
|
1856
1856
|
}) {
|
|
1857
1857
|
let isChanged = !1, isValid = !0;
|
|
1858
1858
|
const hadSelection = !!slateEditor.selection;
|
|
1859
|
-
if ((!value || value.length === 0) && (debug$
|
|
1859
|
+
if ((!value || value.length === 0) && (debug$d("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
|
|
1860
1860
|
withoutSaving(slateEditor, () => {
|
|
1861
1861
|
withoutPatching(slateEditor, () => {
|
|
1862
1862
|
hadSelection && Transforms.deselect(slateEditor);
|
|
@@ -1912,14 +1912,14 @@ async function updateValue({
|
|
|
1912
1912
|
});
|
|
1913
1913
|
}
|
|
1914
1914
|
if (!isValid) {
|
|
1915
|
-
debug$
|
|
1915
|
+
debug$d("Invalid value, returning"), sendBack({
|
|
1916
1916
|
type: "done syncing",
|
|
1917
1917
|
value
|
|
1918
1918
|
});
|
|
1919
1919
|
return;
|
|
1920
1920
|
}
|
|
1921
1921
|
if (isChanged) {
|
|
1922
|
-
debug$
|
|
1922
|
+
debug$d("Server value changed, syncing editor");
|
|
1923
1923
|
try {
|
|
1924
1924
|
slateEditor.onChange();
|
|
1925
1925
|
} catch (err) {
|
|
@@ -1947,7 +1947,7 @@ async function updateValue({
|
|
|
1947
1947
|
value
|
|
1948
1948
|
});
|
|
1949
1949
|
} else
|
|
1950
|
-
debug$
|
|
1950
|
+
debug$d("Server value and editor value is equal, no need to sync.");
|
|
1951
1951
|
sendBack({
|
|
1952
1952
|
type: "done syncing",
|
|
1953
1953
|
value
|
|
@@ -1981,7 +1981,7 @@ function syncBlock({
|
|
|
1981
1981
|
type: "patch",
|
|
1982
1982
|
patch
|
|
1983
1983
|
});
|
|
1984
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
1984
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$d.enabled && debug$d("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$d.enabled && debug$d("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
1985
1985
|
type: "invalid value",
|
|
1986
1986
|
resolution: validation.resolution,
|
|
1987
1987
|
value
|
|
@@ -1989,9 +1989,9 @@ function syncBlock({
|
|
|
1989
1989
|
}
|
|
1990
1990
|
if (!oldBlock && blockValid) {
|
|
1991
1991
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
1992
|
-
debug$
|
|
1992
|
+
debug$d.enabled && debug$d("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
1993
1993
|
at: [currentBlockIndex]
|
|
1994
|
-
}) : (debug$
|
|
1994
|
+
}) : (debug$d("Invalid", validation), sendBack({
|
|
1995
1995
|
type: "invalid value",
|
|
1996
1996
|
resolution: validation.resolution,
|
|
1997
1997
|
value
|
|
@@ -2019,14 +2019,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2019
2019
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
2020
2020
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
2021
2021
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
2022
|
-
childIndex > 0 && (debug$
|
|
2022
|
+
childIndex > 0 && (debug$d("Removing child"), Transforms.removeNodes(slateEditor, {
|
|
2023
2023
|
at: [currentBlockIndex, childIndex]
|
|
2024
2024
|
}));
|
|
2025
2025
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
2026
2026
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2027
2027
|
if (isChildChanged)
|
|
2028
2028
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2029
|
-
debug$
|
|
2029
|
+
debug$d("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2030
2030
|
at: path
|
|
2031
2031
|
});
|
|
2032
2032
|
const isSpanNode = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -2043,23 +2043,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2043
2043
|
}
|
|
2044
2044
|
}), Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
2045
2045
|
at: path
|
|
2046
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
2046
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$d("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
|
|
2047
2047
|
_key: VOID_CHILD_KEY
|
|
2048
2048
|
}, {
|
|
2049
2049
|
at: [...path, 0],
|
|
2050
2050
|
voids: !0
|
|
2051
2051
|
}));
|
|
2052
|
-
} else oldBlockChild ? (debug$
|
|
2052
|
+
} else oldBlockChild ? (debug$d("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
|
|
2053
2053
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2054
2054
|
}), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2055
2055
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2056
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
2056
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$d("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2057
2057
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2058
2058
|
}), slateEditor.onChange());
|
|
2059
2059
|
});
|
|
2060
2060
|
}
|
|
2061
2061
|
}
|
|
2062
|
-
const debug$
|
|
2062
|
+
const debug$c = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
2063
2063
|
function Synchronizer(props) {
|
|
2064
2064
|
const $ = c(41), {
|
|
2065
2065
|
editorActor,
|
|
@@ -2155,14 +2155,14 @@ function Synchronizer(props) {
|
|
|
2155
2155
|
}, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), useEffect(t11, t12);
|
|
2156
2156
|
let t13, t14;
|
|
2157
2157
|
$[30] !== incomingValue || $[31] !== syncActorRef ? (t13 = () => {
|
|
2158
|
-
debug$
|
|
2158
|
+
debug$c("Value from props changed, syncing new value"), syncActorRef.send({
|
|
2159
2159
|
type: "update value",
|
|
2160
2160
|
value: incomingValue
|
|
2161
2161
|
});
|
|
2162
2162
|
}, t14 = [syncActorRef, incomingValue], $[30] = incomingValue, $[31] = syncActorRef, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), useEffect(t13, t14);
|
|
2163
2163
|
let t15;
|
|
2164
2164
|
$[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
|
|
2165
|
-
debug$
|
|
2165
|
+
debug$c("Subscribing to patch events");
|
|
2166
2166
|
const sub = editorActor.on("internal.patch", (event_1) => {
|
|
2167
2167
|
mutationActorRef.send({
|
|
2168
2168
|
...event_1,
|
|
@@ -2170,7 +2170,7 @@ function Synchronizer(props) {
|
|
|
2170
2170
|
});
|
|
2171
2171
|
});
|
|
2172
2172
|
return () => {
|
|
2173
|
-
debug$
|
|
2173
|
+
debug$c("Unsubscribing to patch events"), sub.unsubscribe();
|
|
2174
2174
|
};
|
|
2175
2175
|
}, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
|
|
2176
2176
|
let t16;
|
|
@@ -2431,11 +2431,11 @@ function compileType(rawType) {
|
|
|
2431
2431
|
types: [rawType]
|
|
2432
2432
|
}).get(rawType.name);
|
|
2433
2433
|
}
|
|
2434
|
-
const debug$
|
|
2434
|
+
const debug$b = debugWithName("operationToPatches");
|
|
2435
2435
|
function createOperationToPatches(editorActor) {
|
|
2436
2436
|
const textBlockName = editorActor.getSnapshot().context.schema.block.name;
|
|
2437
2437
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
2438
|
-
debug$
|
|
2438
|
+
debug$b.enabled && debug$b("Operation", JSON.stringify(operation, null, 2));
|
|
2439
2439
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
2440
2440
|
if (!block)
|
|
2441
2441
|
throw new Error("Could not find block");
|
|
@@ -2528,7 +2528,7 @@ function createOperationToPatches(editorActor) {
|
|
|
2528
2528
|
_key: block.children[operation.path[1] - 1]._key
|
|
2529
2529
|
}])];
|
|
2530
2530
|
}
|
|
2531
|
-
return debug$
|
|
2531
|
+
return debug$b("Something was inserted into a void block. Not producing editor patches."), [];
|
|
2532
2532
|
}
|
|
2533
2533
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
2534
2534
|
const patches = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -2586,9 +2586,9 @@ function createOperationToPatches(editorActor) {
|
|
|
2586
2586
|
_key: block._key
|
|
2587
2587
|
}, "children", {
|
|
2588
2588
|
_key: spanToRemove._key
|
|
2589
|
-
}])] : (debug$
|
|
2589
|
+
}])] : (debug$b("Span not found in editor trying to remove node"), []);
|
|
2590
2590
|
} else
|
|
2591
|
-
return debug$
|
|
2591
|
+
return debug$b("Not creating patch inside object block"), [];
|
|
2592
2592
|
}
|
|
2593
2593
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2594
2594
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -2614,7 +2614,7 @@ function createOperationToPatches(editorActor) {
|
|
|
2614
2614
|
_key: removedSpan._key
|
|
2615
2615
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
2616
2616
|
} else
|
|
2617
|
-
debug$
|
|
2617
|
+
debug$b("Void nodes can't be merged, not creating any patches");
|
|
2618
2618
|
return patches;
|
|
2619
2619
|
}
|
|
2620
2620
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -2704,7 +2704,7 @@ function getNextSpan({
|
|
|
2704
2704
|
}
|
|
2705
2705
|
return nextSpan;
|
|
2706
2706
|
}
|
|
2707
|
-
const debug$
|
|
2707
|
+
const debug$a = debugWithName("plugin:withPortableTextMarkModel");
|
|
2708
2708
|
function createWithPortableTextMarkModel(editorActor) {
|
|
2709
2709
|
return function(editor) {
|
|
2710
2710
|
const {
|
|
@@ -2718,7 +2718,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2718
2718
|
for (const [child, childPath] of children) {
|
|
2719
2719
|
const nextNode = node.children[childPath[1] + 1];
|
|
2720
2720
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
2721
|
-
debug$
|
|
2721
|
+
debug$a("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
2722
2722
|
type: "normalizing"
|
|
2723
2723
|
}), Transforms.mergeNodes(editor, {
|
|
2724
2724
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -2731,7 +2731,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2731
2731
|
}
|
|
2732
2732
|
}
|
|
2733
2733
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
2734
|
-
debug$
|
|
2734
|
+
debug$a("Adding .markDefs to block node"), editorActor.send({
|
|
2735
2735
|
type: "normalizing"
|
|
2736
2736
|
}), Transforms.setNodes(editor, {
|
|
2737
2737
|
markDefs: []
|
|
@@ -2743,7 +2743,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2743
2743
|
return;
|
|
2744
2744
|
}
|
|
2745
2745
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
2746
|
-
debug$
|
|
2746
|
+
debug$a("Adding .marks to span node"), editorActor.send({
|
|
2747
2747
|
type: "normalizing"
|
|
2748
2748
|
}), Transforms.setNodes(editor, {
|
|
2749
2749
|
marks: []
|
|
@@ -2757,7 +2757,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2757
2757
|
if (editor.isTextSpan(node)) {
|
|
2758
2758
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
2759
2759
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
2760
|
-
debug$
|
|
2760
|
+
debug$a("Removing annotations from empty span node"), editorActor.send({
|
|
2761
2761
|
type: "normalizing"
|
|
2762
2762
|
}), Transforms.setNodes(editor, {
|
|
2763
2763
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -2775,7 +2775,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2775
2775
|
if (editor.isTextSpan(child)) {
|
|
2776
2776
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
2777
2777
|
if (orphanedAnnotations.length > 0) {
|
|
2778
|
-
debug$
|
|
2778
|
+
debug$a("Removing orphaned annotations from span node"), editorActor.send({
|
|
2779
2779
|
type: "normalizing"
|
|
2780
2780
|
}), Transforms.setNodes(editor, {
|
|
2781
2781
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -2793,7 +2793,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2793
2793
|
if (editor.isTextBlock(block)) {
|
|
2794
2794
|
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));
|
|
2795
2795
|
if (orphanedAnnotations.length > 0) {
|
|
2796
|
-
debug$
|
|
2796
|
+
debug$a("Removing orphaned annotations from span node"), editorActor.send({
|
|
2797
2797
|
type: "normalizing"
|
|
2798
2798
|
}), Transforms.setNodes(editor, {
|
|
2799
2799
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -2811,7 +2811,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2811
2811
|
for (const markDef of markDefs)
|
|
2812
2812
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
2813
2813
|
if (markDefs.length !== newMarkDefs.length) {
|
|
2814
|
-
debug$
|
|
2814
|
+
debug$a("Removing duplicate markDefs"), editorActor.send({
|
|
2815
2815
|
type: "normalizing"
|
|
2816
2816
|
}), Transforms.setNodes(editor, {
|
|
2817
2817
|
markDefs: newMarkDefs
|
|
@@ -2826,7 +2826,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2826
2826
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
2827
2827
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
2828
2828
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
2829
|
-
debug$
|
|
2829
|
+
debug$a("Removing markDef not in use"), editorActor.send({
|
|
2830
2830
|
type: "normalizing"
|
|
2831
2831
|
}), Transforms.setNodes(editor, {
|
|
2832
2832
|
markDefs: newMarkDefs
|
|
@@ -3046,7 +3046,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3046
3046
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
3047
3047
|
if (editor.isTextBlock(targetBlock)) {
|
|
3048
3048
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
3049
|
-
debug$
|
|
3049
|
+
debug$a("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
3050
3050
|
markDefs: newMarkDefs
|
|
3051
3051
|
}, {
|
|
3052
3052
|
at: targetPath,
|
|
@@ -3730,11 +3730,27 @@ const decoratorAddActionImplementation = ({
|
|
|
3730
3730
|
};
|
|
3731
3731
|
}
|
|
3732
3732
|
}, deleteActionImplementation = ({
|
|
3733
|
+
context,
|
|
3733
3734
|
action
|
|
3734
3735
|
}) => {
|
|
3735
3736
|
const range = toSlateRange(action.at, action.editor);
|
|
3736
3737
|
if (!range)
|
|
3737
3738
|
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.at)}`);
|
|
3739
|
+
if (Range.isCollapsed(range)) {
|
|
3740
|
+
const [focusBlock] = getFocusBlock({
|
|
3741
|
+
editor: {
|
|
3742
|
+
...action.editor,
|
|
3743
|
+
selection: range
|
|
3744
|
+
}
|
|
3745
|
+
}), [focusChild] = getFocusChild({
|
|
3746
|
+
editor: {
|
|
3747
|
+
...action.editor,
|
|
3748
|
+
selection: range
|
|
3749
|
+
}
|
|
3750
|
+
});
|
|
3751
|
+
if (focusBlock && focusBlock._type === context.schema.block.name && focusChild && focusChild._type === context.schema.span.name)
|
|
3752
|
+
return;
|
|
3753
|
+
}
|
|
3738
3754
|
action.editor.delete({
|
|
3739
3755
|
at: range
|
|
3740
3756
|
});
|
|
@@ -4042,7 +4058,7 @@ const moveBackwardActionImplementation = ({
|
|
|
4042
4058
|
}) => {
|
|
4043
4059
|
const newSelection = toSlateRange(action.at, action.editor);
|
|
4044
4060
|
newSelection ? Transforms.select(action.editor, newSelection) : Transforms.deselect(action.editor);
|
|
4045
|
-
},
|
|
4061
|
+
}, behaviorActionImplementations = {
|
|
4046
4062
|
"annotation.add": addAnnotationActionImplementation,
|
|
4047
4063
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
4048
4064
|
"block.set": blockSetBehaviorActionImplementation,
|
|
@@ -4069,7 +4085,7 @@ function performAction({
|
|
|
4069
4085
|
context,
|
|
4070
4086
|
action
|
|
4071
4087
|
}) {
|
|
4072
|
-
switch (
|
|
4088
|
+
switch (action.type) {
|
|
4073
4089
|
case "annotation.add": {
|
|
4074
4090
|
behaviorActionImplementations["annotation.add"]({
|
|
4075
4091
|
context,
|
|
@@ -6663,7 +6679,11 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6663
6679
|
raiseDeserializationSuccessOrFailure,
|
|
6664
6680
|
raiseSerializationSuccessOrFailure,
|
|
6665
6681
|
raiseInsertSoftBreak
|
|
6666
|
-
]
|
|
6682
|
+
];
|
|
6683
|
+
function isSyntheticBehaviorEvent(event) {
|
|
6684
|
+
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
6685
|
+
}
|
|
6686
|
+
const abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
6667
6687
|
function isAbstractBehaviorEvent(event) {
|
|
6668
6688
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
6669
6689
|
}
|
|
@@ -6690,29 +6710,27 @@ function performEvent({
|
|
|
6690
6710
|
nativeEvent
|
|
6691
6711
|
}) {
|
|
6692
6712
|
debug$2(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
6693
|
-
const
|
|
6694
|
-
...event,
|
|
6695
|
-
editor
|
|
6696
|
-
}, eventBehaviors = [...remainingEventBehaviors, ...defaultBehaviors].filter((behavior) => {
|
|
6713
|
+
const eventBehaviors = [...remainingEventBehaviors, ...defaultBehaviors].filter((behavior) => {
|
|
6697
6714
|
if (behavior.on === "*")
|
|
6698
6715
|
return !0;
|
|
6699
6716
|
const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
|
|
6700
6717
|
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
6701
6718
|
});
|
|
6702
|
-
if (eventBehaviors.length === 0) {
|
|
6703
|
-
|
|
6704
|
-
return;
|
|
6705
|
-
withApplyingBehaviorActions(editor, () => {
|
|
6719
|
+
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
6720
|
+
nativeEvent?.preventDefault(), withApplyingBehaviorActions(editor, () => {
|
|
6706
6721
|
try {
|
|
6707
|
-
performAction({
|
|
6722
|
+
debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performAction({
|
|
6708
6723
|
context: {
|
|
6709
6724
|
keyGenerator,
|
|
6710
6725
|
schema
|
|
6711
6726
|
},
|
|
6712
|
-
action:
|
|
6727
|
+
action: {
|
|
6728
|
+
...event,
|
|
6729
|
+
editor
|
|
6730
|
+
}
|
|
6713
6731
|
});
|
|
6714
6732
|
} catch (error) {
|
|
6715
|
-
console.error(new Error(`
|
|
6733
|
+
console.error(new Error(`Executing "${event.type}" failed due to: ${error.message}`));
|
|
6716
6734
|
}
|
|
6717
6735
|
}), editor.onChange();
|
|
6718
6736
|
return;
|
|
@@ -6778,41 +6796,17 @@ function performEvent({
|
|
|
6778
6796
|
});
|
|
6779
6797
|
continue;
|
|
6780
6798
|
}
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
});
|
|
6793
|
-
else {
|
|
6794
|
-
nativeEventPrevented = !0;
|
|
6795
|
-
const internalAction = {
|
|
6796
|
-
...action.event,
|
|
6797
|
-
editor
|
|
6798
|
-
};
|
|
6799
|
-
let actionFailed = !1;
|
|
6800
|
-
if (withApplyingBehaviorActions(editor, () => {
|
|
6801
|
-
try {
|
|
6802
|
-
performAction({
|
|
6803
|
-
context: {
|
|
6804
|
-
keyGenerator,
|
|
6805
|
-
schema
|
|
6806
|
-
},
|
|
6807
|
-
action: internalAction
|
|
6808
|
-
});
|
|
6809
|
-
} catch (error) {
|
|
6810
|
-
console.error(new Error(`Performing action "${action.event.type}" as a result of "${event.type}" failed due to: ${error.message}`)), actionFailed = !0;
|
|
6811
|
-
}
|
|
6812
|
-
}), actionFailed)
|
|
6813
|
-
break;
|
|
6814
|
-
editor.onChange();
|
|
6815
|
-
}
|
|
6799
|
+
nativeEventPrevented = !0, performEvent({
|
|
6800
|
+
mode: "execute",
|
|
6801
|
+
behaviors,
|
|
6802
|
+
remainingEventBehaviors: isAbstractBehaviorEvent(action.event) ? behaviors : [],
|
|
6803
|
+
event: action.event,
|
|
6804
|
+
editor,
|
|
6805
|
+
keyGenerator,
|
|
6806
|
+
schema,
|
|
6807
|
+
getSnapshot,
|
|
6808
|
+
nativeEvent: void 0
|
|
6809
|
+
});
|
|
6816
6810
|
}
|
|
6817
6811
|
});
|
|
6818
6812
|
continue;
|
|
@@ -6867,17 +6861,20 @@ function performEvent({
|
|
|
6867
6861
|
break;
|
|
6868
6862
|
}
|
|
6869
6863
|
}
|
|
6870
|
-
!defaultBehaviorOverwritten &&
|
|
6864
|
+
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorActions(editor, () => {
|
|
6871
6865
|
try {
|
|
6872
|
-
performAction({
|
|
6866
|
+
debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performAction({
|
|
6873
6867
|
context: {
|
|
6874
6868
|
keyGenerator,
|
|
6875
6869
|
schema
|
|
6876
6870
|
},
|
|
6877
|
-
action:
|
|
6871
|
+
action: {
|
|
6872
|
+
...event,
|
|
6873
|
+
editor
|
|
6874
|
+
}
|
|
6878
6875
|
});
|
|
6879
6876
|
} catch (error) {
|
|
6880
|
-
console.error(new Error(`
|
|
6877
|
+
console.error(new Error(`Executing "${event.type}" failed due to: ${error.message}`));
|
|
6881
6878
|
}
|
|
6882
6879
|
}), editor.onChange()) : nativeEventPrevented && nativeEvent?.preventDefault();
|
|
6883
6880
|
}
|