@portabletext/editor 1.48.5 → 1.48.6
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 +93 -112
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +94 -113
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/package.json +3 -3
- 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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), React = require("react"), slateReact = require("slate-react"), reactCompilerRuntime = require("react-compiler-runtime"), debug$
|
|
2
|
+
var jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), React = require("react"), slateReact = require("slate-react"), reactCompilerRuntime = require("react-compiler-runtime"), debug$f = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), parseBlocks = require("./parse-blocks.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), omit = require("lodash/omit.js"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), selector_isSelectingEntireBlocks = require("./selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), util_getSelectionStartPoint = require("./util.get-selection-start-point.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
|
|
3
3
|
function _interopDefaultCompat(e) {
|
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
5
|
}
|
|
6
|
-
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$
|
|
6
|
+
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$f), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase);
|
|
7
7
|
const rootName = "sanity-pte:";
|
|
8
8
|
debug__default.default(rootName);
|
|
9
9
|
function debugWithName(name) {
|
|
@@ -1323,7 +1323,7 @@ function withUndoStep(editor, fn) {
|
|
|
1323
1323
|
function getCurrentUndoStepId(editor) {
|
|
1324
1324
|
return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
|
|
1325
1325
|
}
|
|
1326
|
-
const debug$
|
|
1326
|
+
const debug$e = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
1327
1327
|
const state = SAVING.get(editor);
|
|
1328
1328
|
return state === void 0 ? !0 : state;
|
|
1329
1329
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -1336,7 +1336,7 @@ function createWithUndoRedo(options) {
|
|
|
1336
1336
|
const remotePatches = getRemotePatches(editor);
|
|
1337
1337
|
let previousUndoStepId = getCurrentUndoStepId(editor);
|
|
1338
1338
|
options.subscriptions.push(() => {
|
|
1339
|
-
debug$
|
|
1339
|
+
debug$e("Subscribing to patches");
|
|
1340
1340
|
const sub = editorActor.on("patches", ({
|
|
1341
1341
|
patches: patches2,
|
|
1342
1342
|
snapshot
|
|
@@ -1345,7 +1345,7 @@ function createWithUndoRedo(options) {
|
|
|
1345
1345
|
patches2.forEach((patch) => {
|
|
1346
1346
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
1347
1347
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
1348
|
-
debug$
|
|
1348
|
+
debug$e("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
1349
1349
|
undos: [],
|
|
1350
1350
|
redos: []
|
|
1351
1351
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -1361,7 +1361,7 @@ function createWithUndoRedo(options) {
|
|
|
1361
1361
|
}), previousSnapshot = snapshot;
|
|
1362
1362
|
});
|
|
1363
1363
|
return () => {
|
|
1364
|
-
debug$
|
|
1364
|
+
debug$e("Unsubscribing to patches"), sub.unsubscribe();
|
|
1365
1365
|
};
|
|
1366
1366
|
}), editor.history = {
|
|
1367
1367
|
undos: [],
|
|
@@ -1400,7 +1400,7 @@ function createWithUndoRedo(options) {
|
|
|
1400
1400
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
1401
1401
|
timestamp: /* @__PURE__ */ new Date()
|
|
1402
1402
|
};
|
|
1403
|
-
undos.push(newStep), debug$
|
|
1403
|
+
undos.push(newStep), debug$e("Created new undo step", step);
|
|
1404
1404
|
}
|
|
1405
1405
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
1406
1406
|
undos.shift();
|
|
@@ -1418,7 +1418,7 @@ const historyUndoActionImplementation = ({
|
|
|
1418
1418
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
1419
1419
|
if (undos.length > 0) {
|
|
1420
1420
|
const step = undos[undos.length - 1];
|
|
1421
|
-
if (debug$
|
|
1421
|
+
if (debug$e("Undoing", step), step.operations.length > 0) {
|
|
1422
1422
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
1423
1423
|
let transformedOperations = step.operations;
|
|
1424
1424
|
otherPatches.forEach((item) => {
|
|
@@ -1436,7 +1436,7 @@ const historyUndoActionImplementation = ({
|
|
|
1436
1436
|
});
|
|
1437
1437
|
});
|
|
1438
1438
|
} catch (err) {
|
|
1439
|
-
debug$
|
|
1439
|
+
debug$e("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
1440
1440
|
undos: [],
|
|
1441
1441
|
redos: []
|
|
1442
1442
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -1453,7 +1453,7 @@ const historyUndoActionImplementation = ({
|
|
|
1453
1453
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
1454
1454
|
if (redos.length > 0) {
|
|
1455
1455
|
const step = redos[redos.length - 1];
|
|
1456
|
-
if (debug$
|
|
1456
|
+
if (debug$e("Redoing", step), step.operations.length > 0) {
|
|
1457
1457
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
1458
1458
|
let transformedOperations = step.operations;
|
|
1459
1459
|
otherPatches.forEach((item) => {
|
|
@@ -1470,7 +1470,7 @@ const historyUndoActionImplementation = ({
|
|
|
1470
1470
|
});
|
|
1471
1471
|
});
|
|
1472
1472
|
} catch (err) {
|
|
1473
|
-
debug$
|
|
1473
|
+
debug$e("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
1474
1474
|
undos: [],
|
|
1475
1475
|
redos: []
|
|
1476
1476
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -1488,16 +1488,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
1488
1488
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
|
|
1489
1489
|
_key: blk._key
|
|
1490
1490
|
}, patch.path[0]));
|
|
1491
|
-
return debug$
|
|
1491
|
+
return debug$e(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
1492
1492
|
}
|
|
1493
1493
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
1494
1494
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
|
|
1495
1495
|
_key: blk._key
|
|
1496
1496
|
}, patch.path[0]));
|
|
1497
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
1497
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$e("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
1498
1498
|
}
|
|
1499
1499
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
1500
|
-
return debug$
|
|
1500
|
+
return debug$e(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
1501
1501
|
if (patch.type === "diffMatchPatch") {
|
|
1502
1502
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
1503
1503
|
return !operationTargetBlock || !isEqual__default.default({
|
|
@@ -1584,7 +1584,7 @@ function findOperationTargetBlock(editor, operation) {
|
|
|
1584
1584
|
let block;
|
|
1585
1585
|
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;
|
|
1586
1586
|
}
|
|
1587
|
-
const debug$
|
|
1587
|
+
const debug$d = debugWithName("sync machine"), syncValueCallback = ({
|
|
1588
1588
|
sendBack,
|
|
1589
1589
|
input
|
|
1590
1590
|
}) => {
|
|
@@ -1636,7 +1636,7 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1636
1636
|
context
|
|
1637
1637
|
}) => {
|
|
1638
1638
|
const editable = !context.readOnly, isProcessingLocalChanges = context.isProcessingLocalChanges, isChanging = isChangingRemotely(context.slateEditor) ?? !1, isBusy = editable && (isProcessingLocalChanges || isChanging);
|
|
1639
|
-
return debug$
|
|
1639
|
+
return debug$d("isBusy", {
|
|
1640
1640
|
isBusy,
|
|
1641
1641
|
editable,
|
|
1642
1642
|
isProcessingLocalChanges,
|
|
@@ -1690,10 +1690,10 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1690
1690
|
states: {
|
|
1691
1691
|
"syncing initial value": {
|
|
1692
1692
|
entry: [() => {
|
|
1693
|
-
debug$
|
|
1693
|
+
debug$d("entry: syncing initial value");
|
|
1694
1694
|
}],
|
|
1695
1695
|
exit: [() => {
|
|
1696
|
-
debug$
|
|
1696
|
+
debug$d("exit: syncing initial value");
|
|
1697
1697
|
}],
|
|
1698
1698
|
always: {
|
|
1699
1699
|
guard: "initial value synced",
|
|
@@ -1702,10 +1702,10 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1702
1702
|
},
|
|
1703
1703
|
"done syncing initial value": {
|
|
1704
1704
|
entry: ["emit done syncing initial value", () => {
|
|
1705
|
-
debug$
|
|
1705
|
+
debug$d("entry: done syncing initial value");
|
|
1706
1706
|
}],
|
|
1707
1707
|
exit: [() => {
|
|
1708
|
-
debug$
|
|
1708
|
+
debug$d("exit: done syncing initial value");
|
|
1709
1709
|
}],
|
|
1710
1710
|
type: "final"
|
|
1711
1711
|
}
|
|
@@ -1716,10 +1716,10 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1716
1716
|
states: {
|
|
1717
1717
|
idle: {
|
|
1718
1718
|
entry: [() => {
|
|
1719
|
-
debug$
|
|
1719
|
+
debug$d("entry: syncing->idle");
|
|
1720
1720
|
}],
|
|
1721
1721
|
exit: [() => {
|
|
1722
|
-
debug$
|
|
1722
|
+
debug$d("exit: syncing->idle");
|
|
1723
1723
|
}],
|
|
1724
1724
|
on: {
|
|
1725
1725
|
"update value": [{
|
|
@@ -1734,10 +1734,10 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1734
1734
|
},
|
|
1735
1735
|
busy: {
|
|
1736
1736
|
entry: [() => {
|
|
1737
|
-
debug$
|
|
1737
|
+
debug$d("entry: syncing->busy");
|
|
1738
1738
|
}],
|
|
1739
1739
|
exit: [() => {
|
|
1740
|
-
debug$
|
|
1740
|
+
debug$d("exit: syncing->busy");
|
|
1741
1741
|
}],
|
|
1742
1742
|
after: {
|
|
1743
1743
|
1e3: [{
|
|
@@ -1745,7 +1745,7 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1745
1745
|
target: ".",
|
|
1746
1746
|
reenter: !0,
|
|
1747
1747
|
actions: [() => {
|
|
1748
|
-
debug$
|
|
1748
|
+
debug$d("reenter: syncing->busy");
|
|
1749
1749
|
}]
|
|
1750
1750
|
}, {
|
|
1751
1751
|
target: "syncing"
|
|
@@ -1759,10 +1759,10 @@ const debug$e = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1759
1759
|
},
|
|
1760
1760
|
syncing: {
|
|
1761
1761
|
entry: [() => {
|
|
1762
|
-
debug$
|
|
1762
|
+
debug$d("entry: syncing->syncing");
|
|
1763
1763
|
}],
|
|
1764
1764
|
exit: [() => {
|
|
1765
|
-
debug$
|
|
1765
|
+
debug$d("exit: syncing->syncing");
|
|
1766
1766
|
}],
|
|
1767
1767
|
always: {
|
|
1768
1768
|
guard: "pending value equals previous value",
|
|
@@ -1829,7 +1829,7 @@ async function updateValue({
|
|
|
1829
1829
|
}) {
|
|
1830
1830
|
let isChanged = !1, isValid = !0;
|
|
1831
1831
|
const hadSelection = !!slateEditor.selection;
|
|
1832
|
-
if ((!value || value.length === 0) && (debug$
|
|
1832
|
+
if ((!value || value.length === 0) && (debug$d("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
1833
1833
|
withoutSaving(slateEditor, () => {
|
|
1834
1834
|
withoutPatching(slateEditor, () => {
|
|
1835
1835
|
hadSelection && slate.Transforms.deselect(slateEditor);
|
|
@@ -1885,14 +1885,14 @@ async function updateValue({
|
|
|
1885
1885
|
});
|
|
1886
1886
|
}
|
|
1887
1887
|
if (!isValid) {
|
|
1888
|
-
debug$
|
|
1888
|
+
debug$d("Invalid value, returning"), sendBack({
|
|
1889
1889
|
type: "done syncing",
|
|
1890
1890
|
value
|
|
1891
1891
|
});
|
|
1892
1892
|
return;
|
|
1893
1893
|
}
|
|
1894
1894
|
if (isChanged) {
|
|
1895
|
-
debug$
|
|
1895
|
+
debug$d("Server value changed, syncing editor");
|
|
1896
1896
|
try {
|
|
1897
1897
|
slateEditor.onChange();
|
|
1898
1898
|
} catch (err) {
|
|
@@ -1920,7 +1920,7 @@ async function updateValue({
|
|
|
1920
1920
|
value
|
|
1921
1921
|
});
|
|
1922
1922
|
} else
|
|
1923
|
-
debug$
|
|
1923
|
+
debug$d("Server value and editor value is equal, no need to sync.");
|
|
1924
1924
|
sendBack({
|
|
1925
1925
|
type: "done syncing",
|
|
1926
1926
|
value
|
|
@@ -1954,7 +1954,7 @@ function syncBlock({
|
|
|
1954
1954
|
type: "patch",
|
|
1955
1955
|
patch
|
|
1956
1956
|
});
|
|
1957
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
1957
|
+
})), 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({
|
|
1958
1958
|
type: "invalid value",
|
|
1959
1959
|
resolution: validation.resolution,
|
|
1960
1960
|
value
|
|
@@ -1962,9 +1962,9 @@ function syncBlock({
|
|
|
1962
1962
|
}
|
|
1963
1963
|
if (!oldBlock && blockValid) {
|
|
1964
1964
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
1965
|
-
debug$
|
|
1965
|
+
debug$d.enabled && debug$d("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
1966
1966
|
at: [currentBlockIndex]
|
|
1967
|
-
}) : (debug$
|
|
1967
|
+
}) : (debug$d("Invalid", validation), sendBack({
|
|
1968
1968
|
type: "invalid value",
|
|
1969
1969
|
resolution: validation.resolution,
|
|
1970
1970
|
value
|
|
@@ -1992,14 +1992,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
1992
1992
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
1993
1993
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
1994
1994
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
1995
|
-
childIndex > 0 && (debug$
|
|
1995
|
+
childIndex > 0 && (debug$d("Removing child"), slate.Transforms.removeNodes(slateEditor, {
|
|
1996
1996
|
at: [currentBlockIndex, childIndex]
|
|
1997
1997
|
}));
|
|
1998
1998
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
1999
1999
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2000
2000
|
if (isChildChanged)
|
|
2001
2001
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2002
|
-
debug$
|
|
2002
|
+
debug$d("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2003
2003
|
at: path
|
|
2004
2004
|
});
|
|
2005
2005
|
const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -2016,23 +2016,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2016
2016
|
}
|
|
2017
2017
|
}), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
2018
2018
|
at: path
|
|
2019
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
2019
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$d("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
|
|
2020
2020
|
_key: VOID_CHILD_KEY
|
|
2021
2021
|
}, {
|
|
2022
2022
|
at: [...path, 0],
|
|
2023
2023
|
voids: !0
|
|
2024
2024
|
}));
|
|
2025
|
-
} else oldBlockChild ? (debug$
|
|
2025
|
+
} else oldBlockChild ? (debug$d("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
|
|
2026
2026
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2027
2027
|
}), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2028
2028
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2029
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
2029
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$d("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2030
2030
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2031
2031
|
}), slateEditor.onChange());
|
|
2032
2032
|
});
|
|
2033
2033
|
}
|
|
2034
2034
|
}
|
|
2035
|
-
const debug$
|
|
2035
|
+
const debug$c = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
2036
2036
|
function Synchronizer(props) {
|
|
2037
2037
|
const $ = reactCompilerRuntime.c(41), {
|
|
2038
2038
|
editorActor,
|
|
@@ -2128,14 +2128,14 @@ function Synchronizer(props) {
|
|
|
2128
2128
|
}, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), React.useEffect(t11, t12);
|
|
2129
2129
|
let t13, t14;
|
|
2130
2130
|
$[30] !== incomingValue || $[31] !== syncActorRef ? (t13 = () => {
|
|
2131
|
-
debug$
|
|
2131
|
+
debug$c("Value from props changed, syncing new value"), syncActorRef.send({
|
|
2132
2132
|
type: "update value",
|
|
2133
2133
|
value: incomingValue
|
|
2134
2134
|
});
|
|
2135
2135
|
}, t14 = [syncActorRef, incomingValue], $[30] = incomingValue, $[31] = syncActorRef, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), React.useEffect(t13, t14);
|
|
2136
2136
|
let t15;
|
|
2137
2137
|
$[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
|
|
2138
|
-
debug$
|
|
2138
|
+
debug$c("Subscribing to patch events");
|
|
2139
2139
|
const sub = editorActor.on("internal.patch", (event_1) => {
|
|
2140
2140
|
mutationActorRef.send({
|
|
2141
2141
|
...event_1,
|
|
@@ -2143,7 +2143,7 @@ function Synchronizer(props) {
|
|
|
2143
2143
|
});
|
|
2144
2144
|
});
|
|
2145
2145
|
return () => {
|
|
2146
|
-
debug$
|
|
2146
|
+
debug$c("Unsubscribing to patch events"), sub.unsubscribe();
|
|
2147
2147
|
};
|
|
2148
2148
|
}, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
|
|
2149
2149
|
let t16;
|
|
@@ -2404,11 +2404,11 @@ function compileType(rawType) {
|
|
|
2404
2404
|
types: [rawType]
|
|
2405
2405
|
}).get(rawType.name);
|
|
2406
2406
|
}
|
|
2407
|
-
const debug$
|
|
2407
|
+
const debug$b = debugWithName("operationToPatches");
|
|
2408
2408
|
function createOperationToPatches(editorActor) {
|
|
2409
2409
|
const textBlockName = editorActor.getSnapshot().context.schema.block.name;
|
|
2410
2410
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
2411
|
-
debug$
|
|
2411
|
+
debug$b.enabled && debug$b("Operation", JSON.stringify(operation, null, 2));
|
|
2412
2412
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
2413
2413
|
if (!block)
|
|
2414
2414
|
throw new Error("Could not find block");
|
|
@@ -2501,7 +2501,7 @@ function createOperationToPatches(editorActor) {
|
|
|
2501
2501
|
_key: block.children[operation.path[1] - 1]._key
|
|
2502
2502
|
}])];
|
|
2503
2503
|
}
|
|
2504
|
-
return debug$
|
|
2504
|
+
return debug$b("Something was inserted into a void block. Not producing editor patches."), [];
|
|
2505
2505
|
}
|
|
2506
2506
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
2507
2507
|
const patches$1 = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -2559,9 +2559,9 @@ function createOperationToPatches(editorActor) {
|
|
|
2559
2559
|
_key: block._key
|
|
2560
2560
|
}, "children", {
|
|
2561
2561
|
_key: spanToRemove._key
|
|
2562
|
-
}])] : (debug$
|
|
2562
|
+
}])] : (debug$b("Span not found in editor trying to remove node"), []);
|
|
2563
2563
|
} else
|
|
2564
|
-
return debug$
|
|
2564
|
+
return debug$b("Not creating patch inside object block"), [];
|
|
2565
2565
|
}
|
|
2566
2566
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2567
2567
|
const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -2587,7 +2587,7 @@ function createOperationToPatches(editorActor) {
|
|
|
2587
2587
|
_key: removedSpan._key
|
|
2588
2588
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
2589
2589
|
} else
|
|
2590
|
-
debug$
|
|
2590
|
+
debug$b("Void nodes can't be merged, not creating any patches");
|
|
2591
2591
|
return patches$1;
|
|
2592
2592
|
}
|
|
2593
2593
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -2677,7 +2677,7 @@ function getNextSpan({
|
|
|
2677
2677
|
}
|
|
2678
2678
|
return nextSpan;
|
|
2679
2679
|
}
|
|
2680
|
-
const debug$
|
|
2680
|
+
const debug$a = debugWithName("plugin:withPortableTextMarkModel");
|
|
2681
2681
|
function createWithPortableTextMarkModel(editorActor) {
|
|
2682
2682
|
return function(editor) {
|
|
2683
2683
|
const {
|
|
@@ -2691,7 +2691,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2691
2691
|
for (const [child, childPath] of children) {
|
|
2692
2692
|
const nextNode = node.children[childPath[1] + 1];
|
|
2693
2693
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
2694
|
-
debug$
|
|
2694
|
+
debug$a("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
2695
2695
|
type: "normalizing"
|
|
2696
2696
|
}), slate.Transforms.mergeNodes(editor, {
|
|
2697
2697
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -2704,7 +2704,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2704
2704
|
}
|
|
2705
2705
|
}
|
|
2706
2706
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
2707
|
-
debug$
|
|
2707
|
+
debug$a("Adding .markDefs to block node"), editorActor.send({
|
|
2708
2708
|
type: "normalizing"
|
|
2709
2709
|
}), slate.Transforms.setNodes(editor, {
|
|
2710
2710
|
markDefs: []
|
|
@@ -2716,7 +2716,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2716
2716
|
return;
|
|
2717
2717
|
}
|
|
2718
2718
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
2719
|
-
debug$
|
|
2719
|
+
debug$a("Adding .marks to span node"), editorActor.send({
|
|
2720
2720
|
type: "normalizing"
|
|
2721
2721
|
}), slate.Transforms.setNodes(editor, {
|
|
2722
2722
|
marks: []
|
|
@@ -2730,7 +2730,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2730
2730
|
if (editor.isTextSpan(node)) {
|
|
2731
2731
|
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));
|
|
2732
2732
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
2733
|
-
debug$
|
|
2733
|
+
debug$a("Removing annotations from empty span node"), editorActor.send({
|
|
2734
2734
|
type: "normalizing"
|
|
2735
2735
|
}), slate.Transforms.setNodes(editor, {
|
|
2736
2736
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -2748,7 +2748,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2748
2748
|
if (editor.isTextSpan(child)) {
|
|
2749
2749
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
2750
2750
|
if (orphanedAnnotations.length > 0) {
|
|
2751
|
-
debug$
|
|
2751
|
+
debug$a("Removing orphaned annotations from span node"), editorActor.send({
|
|
2752
2752
|
type: "normalizing"
|
|
2753
2753
|
}), slate.Transforms.setNodes(editor, {
|
|
2754
2754
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -2766,7 +2766,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2766
2766
|
if (editor.isTextBlock(block)) {
|
|
2767
2767
|
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));
|
|
2768
2768
|
if (orphanedAnnotations.length > 0) {
|
|
2769
|
-
debug$
|
|
2769
|
+
debug$a("Removing orphaned annotations from span node"), editorActor.send({
|
|
2770
2770
|
type: "normalizing"
|
|
2771
2771
|
}), slate.Transforms.setNodes(editor, {
|
|
2772
2772
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -2784,7 +2784,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2784
2784
|
for (const markDef of markDefs)
|
|
2785
2785
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
2786
2786
|
if (markDefs.length !== newMarkDefs.length) {
|
|
2787
|
-
debug$
|
|
2787
|
+
debug$a("Removing duplicate markDefs"), editorActor.send({
|
|
2788
2788
|
type: "normalizing"
|
|
2789
2789
|
}), slate.Transforms.setNodes(editor, {
|
|
2790
2790
|
markDefs: newMarkDefs
|
|
@@ -2799,7 +2799,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
2799
2799
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
2800
2800
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
2801
2801
|
if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
|
|
2802
|
-
debug$
|
|
2802
|
+
debug$a("Removing markDef not in use"), editorActor.send({
|
|
2803
2803
|
type: "normalizing"
|
|
2804
2804
|
}), slate.Transforms.setNodes(editor, {
|
|
2805
2805
|
markDefs: newMarkDefs
|
|
@@ -3019,7 +3019,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3019
3019
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
3020
3020
|
if (editor.isTextBlock(targetBlock)) {
|
|
3021
3021
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
3022
|
-
debug$
|
|
3022
|
+
debug$a("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
|
|
3023
3023
|
markDefs: newMarkDefs
|
|
3024
3024
|
}, {
|
|
3025
3025
|
at: targetPath,
|
|
@@ -4015,7 +4015,7 @@ const moveBackwardActionImplementation = ({
|
|
|
4015
4015
|
}) => {
|
|
4016
4016
|
const newSelection = toSlateRange(action.at, action.editor);
|
|
4017
4017
|
newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
|
|
4018
|
-
},
|
|
4018
|
+
}, behaviorActionImplementations = {
|
|
4019
4019
|
"annotation.add": addAnnotationActionImplementation,
|
|
4020
4020
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
4021
4021
|
"block.set": blockSetBehaviorActionImplementation,
|
|
@@ -4042,7 +4042,7 @@ function performAction({
|
|
|
4042
4042
|
context,
|
|
4043
4043
|
action
|
|
4044
4044
|
}) {
|
|
4045
|
-
switch (
|
|
4045
|
+
switch (action.type) {
|
|
4046
4046
|
case "annotation.add": {
|
|
4047
4047
|
behaviorActionImplementations["annotation.add"]({
|
|
4048
4048
|
context,
|
|
@@ -6636,7 +6636,11 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6636
6636
|
raiseDeserializationSuccessOrFailure,
|
|
6637
6637
|
raiseSerializationSuccessOrFailure,
|
|
6638
6638
|
raiseInsertSoftBreak
|
|
6639
|
-
]
|
|
6639
|
+
];
|
|
6640
|
+
function isSyntheticBehaviorEvent(event) {
|
|
6641
|
+
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
6642
|
+
}
|
|
6643
|
+
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"];
|
|
6640
6644
|
function isAbstractBehaviorEvent(event) {
|
|
6641
6645
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
6642
6646
|
}
|
|
@@ -6663,29 +6667,27 @@ function performEvent({
|
|
|
6663
6667
|
nativeEvent
|
|
6664
6668
|
}) {
|
|
6665
6669
|
debug$2(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
6666
|
-
const
|
|
6667
|
-
...event,
|
|
6668
|
-
editor
|
|
6669
|
-
}, eventBehaviors = [...remainingEventBehaviors, ...defaultBehaviors].filter((behavior) => {
|
|
6670
|
+
const eventBehaviors = [...remainingEventBehaviors, ...defaultBehaviors].filter((behavior) => {
|
|
6670
6671
|
if (behavior.on === "*")
|
|
6671
6672
|
return !0;
|
|
6672
6673
|
const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
|
|
6673
6674
|
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
6674
6675
|
});
|
|
6675
|
-
if (eventBehaviors.length === 0) {
|
|
6676
|
-
|
|
6677
|
-
return;
|
|
6678
|
-
withApplyingBehaviorActions(editor, () => {
|
|
6676
|
+
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
6677
|
+
nativeEvent?.preventDefault(), withApplyingBehaviorActions(editor, () => {
|
|
6679
6678
|
try {
|
|
6680
|
-
performAction({
|
|
6679
|
+
debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performAction({
|
|
6681
6680
|
context: {
|
|
6682
6681
|
keyGenerator,
|
|
6683
6682
|
schema: schema2
|
|
6684
6683
|
},
|
|
6685
|
-
action:
|
|
6684
|
+
action: {
|
|
6685
|
+
...event,
|
|
6686
|
+
editor
|
|
6687
|
+
}
|
|
6686
6688
|
});
|
|
6687
6689
|
} catch (error) {
|
|
6688
|
-
console.error(new Error(`
|
|
6690
|
+
console.error(new Error(`Executing "${event.type}" failed due to: ${error.message}`));
|
|
6689
6691
|
}
|
|
6690
6692
|
}), editor.onChange();
|
|
6691
6693
|
return;
|
|
@@ -6751,41 +6753,17 @@ function performEvent({
|
|
|
6751
6753
|
});
|
|
6752
6754
|
continue;
|
|
6753
6755
|
}
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
});
|
|
6766
|
-
else {
|
|
6767
|
-
nativeEventPrevented = !0;
|
|
6768
|
-
const internalAction = {
|
|
6769
|
-
...action.event,
|
|
6770
|
-
editor
|
|
6771
|
-
};
|
|
6772
|
-
let actionFailed = !1;
|
|
6773
|
-
if (withApplyingBehaviorActions(editor, () => {
|
|
6774
|
-
try {
|
|
6775
|
-
performAction({
|
|
6776
|
-
context: {
|
|
6777
|
-
keyGenerator,
|
|
6778
|
-
schema: schema2
|
|
6779
|
-
},
|
|
6780
|
-
action: internalAction
|
|
6781
|
-
});
|
|
6782
|
-
} catch (error) {
|
|
6783
|
-
console.error(new Error(`Performing action "${action.event.type}" as a result of "${event.type}" failed due to: ${error.message}`)), actionFailed = !0;
|
|
6784
|
-
}
|
|
6785
|
-
}), actionFailed)
|
|
6786
|
-
break;
|
|
6787
|
-
editor.onChange();
|
|
6788
|
-
}
|
|
6756
|
+
nativeEventPrevented = !0, performEvent({
|
|
6757
|
+
mode: "execute",
|
|
6758
|
+
behaviors,
|
|
6759
|
+
remainingEventBehaviors: isAbstractBehaviorEvent(action.event) ? behaviors : [],
|
|
6760
|
+
event: action.event,
|
|
6761
|
+
editor,
|
|
6762
|
+
keyGenerator,
|
|
6763
|
+
schema: schema2,
|
|
6764
|
+
getSnapshot,
|
|
6765
|
+
nativeEvent: void 0
|
|
6766
|
+
});
|
|
6789
6767
|
}
|
|
6790
6768
|
});
|
|
6791
6769
|
continue;
|
|
@@ -6840,17 +6818,20 @@ function performEvent({
|
|
|
6840
6818
|
break;
|
|
6841
6819
|
}
|
|
6842
6820
|
}
|
|
6843
|
-
!defaultBehaviorOverwritten &&
|
|
6821
|
+
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorActions(editor, () => {
|
|
6844
6822
|
try {
|
|
6845
|
-
performAction({
|
|
6823
|
+
debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performAction({
|
|
6846
6824
|
context: {
|
|
6847
6825
|
keyGenerator,
|
|
6848
6826
|
schema: schema2
|
|
6849
6827
|
},
|
|
6850
|
-
action:
|
|
6828
|
+
action: {
|
|
6829
|
+
...event,
|
|
6830
|
+
editor
|
|
6831
|
+
}
|
|
6851
6832
|
});
|
|
6852
6833
|
} catch (error) {
|
|
6853
|
-
console.error(new Error(`
|
|
6834
|
+
console.error(new Error(`Executing "${event.type}" failed due to: ${error.message}`));
|
|
6854
6835
|
}
|
|
6855
6836
|
}), editor.onChange()) : nativeEventPrevented && nativeEvent?.preventDefault();
|
|
6856
6837
|
}
|