@portabletext/editor 1.0.8 → 1.0.10
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/index.d.mts +18 -5
- package/lib/index.d.ts +18 -5
- package/lib/index.esm.js +188 -177
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +187 -176
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +188 -177
- package/lib/index.mjs.map +1 -1
- package/package.json +20 -22
- package/src/editor/Editable.tsx +4 -7
- package/src/editor/PortableTextEditor.tsx +31 -17
- package/src/editor/__tests__/RangeDecorations.test.tsx +4 -4
- package/src/editor/components/Synchronizer.tsx +15 -46
- package/src/editor/hooks/usePortableTextEditor.ts +1 -0
- package/src/editor/hooks/usePortableTextEditorKeyGenerator.ts +3 -0
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +63 -0
- package/src/editor/plugins/createWithHotKeys.ts +5 -1
- package/src/types/editor.ts +7 -0
- package/src/types/options.ts +6 -0
- package/src/utils/withChanges.ts +0 -7
- package/src/editor/hooks/usePortableTextEditorSelection.ts +0 -22
- package/src/editor/hooks/usePortableTextEditorValue.ts +0 -16
- package/src/utils/bufferUntil.ts +0 -15
package/lib/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var jsxRuntime = require("react/jsx-runtime"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), react = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$
|
|
3
|
+
var jsxRuntime = require("react/jsx-runtime"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), react = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$m = require("debug"), types = require("@sanity/types"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), 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"), isHotkeyEsm = require("is-hotkey-esm"), blockTools = require("@sanity/block-tools"), isPlainObject = require("lodash/isPlainObject.js"), throttle = require("lodash/throttle.js"), content = require("@sanity/util/content"), debounce = require("lodash/debounce.js");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$
|
|
7
|
+
var isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$m), 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), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), throttle__default = /* @__PURE__ */ _interopDefaultCompat(throttle), debounce__default = /* @__PURE__ */ _interopDefaultCompat(debounce);
|
|
8
8
|
const rootName = "sanity-pte:";
|
|
9
9
|
debug__default.default(rootName);
|
|
10
10
|
function debugWithName(name) {
|
|
@@ -332,7 +332,7 @@ function getCounterContentForListLevel(level) {
|
|
|
332
332
|
return "counter(listItemNumberNextNextNext) '. '";
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
|
-
const debug$
|
|
335
|
+
const debug$l = debugWithName("components:DraggableBlock"), DraggableBlock = ({ children, element, readOnly, blockRef }) => {
|
|
336
336
|
const editor = slateReact.useSlateStatic(), dragGhostRef = react.useRef(), [isDragOver, setIsDragOver] = react.useState(!1), isVoid = react.useMemo(() => slate.Editor.isVoid(editor, element), [editor, element]), isInline = react.useMemo(() => slate.Editor.isInline(editor, element), [editor, element]), [blockElement, setBlockElement] = react.useState(null);
|
|
337
337
|
react.useEffect(
|
|
338
338
|
() => setBlockElement(blockRef ? blockRef.current : slateReact.ReactEditor.toDOMNode(editor, element)),
|
|
@@ -359,18 +359,18 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = ({
|
|
|
359
359
|
(event) => {
|
|
360
360
|
const targetBlock = IS_DRAGGING_ELEMENT_TARGET.get(editor);
|
|
361
361
|
if (targetBlock) {
|
|
362
|
-
IS_DRAGGING.set(editor, !1), event.preventDefault(), event.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$
|
|
362
|
+
IS_DRAGGING.set(editor, !1), event.preventDefault(), event.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$l("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
|
|
363
363
|
const dragPosition2 = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor);
|
|
364
364
|
IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor);
|
|
365
365
|
let targetPath = slateReact.ReactEditor.findPath(editor, targetBlock);
|
|
366
366
|
const myPath = slateReact.ReactEditor.findPath(editor, element), isBefore = slate.Path.isBefore(myPath, targetPath);
|
|
367
367
|
if (dragPosition2 === "bottom" && !isBefore) {
|
|
368
368
|
if (targetPath[0] >= editor.children.length - 1) {
|
|
369
|
-
debug$
|
|
369
|
+
debug$l("target is already at the bottom, not moving");
|
|
370
370
|
return;
|
|
371
371
|
}
|
|
372
372
|
const originalPath = targetPath;
|
|
373
|
-
targetPath = slate.Path.next(targetPath), debug$
|
|
373
|
+
targetPath = slate.Path.next(targetPath), debug$l(
|
|
374
374
|
`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(
|
|
375
375
|
targetPath
|
|
376
376
|
)}`
|
|
@@ -378,29 +378,29 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = ({
|
|
|
378
378
|
}
|
|
379
379
|
if (dragPosition2 === "top" && isBefore && targetPath[0] !== editor.children.length - 1) {
|
|
380
380
|
const originalPath = targetPath;
|
|
381
|
-
targetPath = slate.Path.previous(targetPath), debug$
|
|
381
|
+
targetPath = slate.Path.previous(targetPath), debug$l(
|
|
382
382
|
`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(
|
|
383
383
|
targetPath
|
|
384
384
|
)}`
|
|
385
385
|
);
|
|
386
386
|
}
|
|
387
387
|
if (slate.Path.equals(targetPath, myPath)) {
|
|
388
|
-
event.preventDefault(), debug$
|
|
388
|
+
event.preventDefault(), debug$l("targetPath and myPath is the same, not moving");
|
|
389
389
|
return;
|
|
390
390
|
}
|
|
391
|
-
debug$
|
|
391
|
+
debug$l(
|
|
392
392
|
`Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(
|
|
393
393
|
targetPath
|
|
394
394
|
)} (${dragPosition2})`
|
|
395
395
|
), slate.Transforms.moveNodes(editor, { at: myPath, to: targetPath }), editor.onChange();
|
|
396
396
|
return;
|
|
397
397
|
}
|
|
398
|
-
debug$
|
|
398
|
+
debug$l("No target element, not doing anything");
|
|
399
399
|
},
|
|
400
400
|
[editor, element]
|
|
401
401
|
), handleDrop = react.useCallback(
|
|
402
402
|
(event) => {
|
|
403
|
-
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$
|
|
403
|
+
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$l("On drop (prevented)", element), event.preventDefault(), event.stopPropagation(), setIsDragOver(!1));
|
|
404
404
|
},
|
|
405
405
|
[editor, element]
|
|
406
406
|
), handleDrag = react.useCallback(
|
|
@@ -417,10 +417,10 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = ({
|
|
|
417
417
|
), handleDragStart = react.useCallback(
|
|
418
418
|
(event) => {
|
|
419
419
|
if (!isVoid || isInline) {
|
|
420
|
-
debug$
|
|
420
|
+
debug$l("Not dragging block"), IS_DRAGGING_BLOCK_ELEMENT.delete(editor), IS_DRAGGING.set(editor, !1);
|
|
421
421
|
return;
|
|
422
422
|
}
|
|
423
|
-
if (debug$
|
|
423
|
+
if (debug$l("Drag start"), IS_DRAGGING.set(editor, !0), event.dataTransfer && (event.dataTransfer.setData("application/portable-text", "something"), event.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
|
|
424
424
|
let dragGhost = blockElement.cloneNode(!0);
|
|
425
425
|
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
426
426
|
if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
|
|
@@ -701,12 +701,12 @@ function compileType(rawType) {
|
|
|
701
701
|
types: [rawType]
|
|
702
702
|
}).get(rawType.name);
|
|
703
703
|
}
|
|
704
|
-
const debug$
|
|
705
|
-
debug$
|
|
704
|
+
const debug$k = debugWithName("operationToPatches");
|
|
705
|
+
debug$k.enabled = !1;
|
|
706
706
|
function createOperationToPatches(types2) {
|
|
707
707
|
const textBlockName = types2.block.name;
|
|
708
708
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
709
|
-
debug$
|
|
709
|
+
debug$k.enabled && debug$k("Operation", JSON.stringify(operation, null, 2));
|
|
710
710
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
711
711
|
if (!block)
|
|
712
712
|
throw new Error("Could not find block");
|
|
@@ -797,7 +797,7 @@ function createOperationToPatches(types2) {
|
|
|
797
797
|
])
|
|
798
798
|
];
|
|
799
799
|
}
|
|
800
|
-
return debug$
|
|
800
|
+
return debug$k("Something was inserted into a void block. Not producing editor patches."), [];
|
|
801
801
|
}
|
|
802
802
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
803
803
|
const patches$1 = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -860,9 +860,9 @@ function createOperationToPatches(types2) {
|
|
|
860
860
|
throw new Error("Block not found");
|
|
861
861
|
} else if (editor.isTextBlock(block) && operation.path.length === 2) {
|
|
862
862
|
const spanToRemove = editor.isTextBlock(block) && block.children && block.children[operation.path[1]];
|
|
863
|
-
return spanToRemove ? [patches.unset([{ _key: block._key }, "children", { _key: spanToRemove._key }])] : (debug$
|
|
863
|
+
return spanToRemove ? [patches.unset([{ _key: block._key }, "children", { _key: spanToRemove._key }])] : (debug$k("Span not found in editor trying to remove node"), []);
|
|
864
864
|
} else
|
|
865
|
-
return debug$
|
|
865
|
+
return debug$k("Not creating patch inside object block"), [];
|
|
866
866
|
}
|
|
867
867
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
868
868
|
const patches$1 = [], block = beforeValue[operation.path[0]], targetBlock = editor.children[operation.path[0]];
|
|
@@ -878,7 +878,7 @@ function createOperationToPatches(types2) {
|
|
|
878
878
|
patches.set(targetSpan.text, [{ _key: block._key }, "children", { _key: targetSpan._key }, "text"])
|
|
879
879
|
), mergedSpan && patches$1.push(patches.unset([{ _key: block._key }, "children", { _key: mergedSpan._key }])));
|
|
880
880
|
} else
|
|
881
|
-
debug$
|
|
881
|
+
debug$k("Void nodes can't be merged, not creating any patches");
|
|
882
882
|
return patches$1;
|
|
883
883
|
}
|
|
884
884
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -911,7 +911,7 @@ function createOperationToPatches(types2) {
|
|
|
911
911
|
splitNodePatch
|
|
912
912
|
};
|
|
913
913
|
}
|
|
914
|
-
const debug$
|
|
914
|
+
const debug$j = debugWithName("API:editable");
|
|
915
915
|
function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
916
916
|
return function(editor) {
|
|
917
917
|
return portableTextEditor.setEditable({
|
|
@@ -994,7 +994,7 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
994
994
|
],
|
|
995
995
|
portableTextEditor
|
|
996
996
|
)[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types$1.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
997
|
-
return isSpanNode && focusNode._type !== types$1.span.name && (debug$
|
|
997
|
+
return isSpanNode && focusNode._type !== types$1.span.name && (debug$j("Inserting span child next to inline object child, moving selection + 1"), editor.move({ distance: 1, unit: "character" })), slate.Transforms.insertNodes(editor, child, {
|
|
998
998
|
select: !0,
|
|
999
999
|
at: editor.selection
|
|
1000
1000
|
}), editor.onChange(), ((_a = toPortableTextRange(
|
|
@@ -1193,18 +1193,18 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1193
1193
|
throw new Error("Invalid range");
|
|
1194
1194
|
if (range) {
|
|
1195
1195
|
if (!(options != null && options.mode) || (options == null ? void 0 : options.mode) === "selected") {
|
|
1196
|
-
debug$
|
|
1196
|
+
debug$j("Deleting content in selection"), slate.Transforms.delete(editor, {
|
|
1197
1197
|
at: range,
|
|
1198
1198
|
hanging: !0,
|
|
1199
1199
|
voids: !0
|
|
1200
1200
|
}), editor.onChange();
|
|
1201
1201
|
return;
|
|
1202
1202
|
}
|
|
1203
|
-
(options == null ? void 0 : options.mode) === "blocks" && (debug$
|
|
1203
|
+
(options == null ? void 0 : options.mode) === "blocks" && (debug$j("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
1204
1204
|
at: range,
|
|
1205
1205
|
voids: !0,
|
|
1206
1206
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
1207
|
-
})), (options == null ? void 0 : options.mode) === "children" && (debug$
|
|
1207
|
+
})), (options == null ? void 0 : options.mode) === "children" && (debug$j("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
1208
1208
|
at: range,
|
|
1209
1209
|
voids: !0,
|
|
1210
1210
|
match: (node) => node._type === types$1.span.name || // Text children
|
|
@@ -1215,7 +1215,7 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1215
1215
|
},
|
|
1216
1216
|
removeAnnotation: (type) => {
|
|
1217
1217
|
let { selection } = editor;
|
|
1218
|
-
if (debug$
|
|
1218
|
+
if (debug$j("Removing annotation", type), selection) {
|
|
1219
1219
|
if (slate.Range.isCollapsed(selection)) {
|
|
1220
1220
|
const [node, nodePath] = slate.Editor.node(editor, selection, { depth: 2 });
|
|
1221
1221
|
slate.Text.isText(node) && node.marks && typeof node.text == "string" && (slate.Transforms.select(editor, nodePath), selection = editor.selection);
|
|
@@ -2035,14 +2035,14 @@ function parse(textline) {
|
|
|
2035
2035
|
function toInt(num) {
|
|
2036
2036
|
return parseInt(num, 10);
|
|
2037
2037
|
}
|
|
2038
|
-
const debug$
|
|
2038
|
+
const debug$i = debugWithName("applyPatches"), debugVerbose$4 = debug$i.enabled && !0;
|
|
2039
2039
|
function createApplyPatch(schemaTypes) {
|
|
2040
2040
|
let previousPatch;
|
|
2041
2041
|
return function(editor, patch) {
|
|
2042
2042
|
let changed = !1;
|
|
2043
|
-
debugVerbose$
|
|
2043
|
+
debugVerbose$4 && (debug$i(`
|
|
2044
2044
|
|
|
2045
|
-
NEW PATCH =============================================================`), debug$
|
|
2045
|
+
NEW PATCH =============================================================`), debug$i(JSON.stringify(patch, null, 2)));
|
|
2046
2046
|
try {
|
|
2047
2047
|
switch (patch.type) {
|
|
2048
2048
|
case "insert":
|
|
@@ -2058,7 +2058,7 @@ NEW PATCH =============================================================`), debug
|
|
|
2058
2058
|
changed = diffMatchPatch(editor, patch);
|
|
2059
2059
|
break;
|
|
2060
2060
|
default:
|
|
2061
|
-
debug$
|
|
2061
|
+
debug$i("Unhandled patch", patch.type);
|
|
2062
2062
|
}
|
|
2063
2063
|
} catch (err) {
|
|
2064
2064
|
console.error(err);
|
|
@@ -2069,9 +2069,9 @@ NEW PATCH =============================================================`), debug
|
|
|
2069
2069
|
function diffMatchPatch(editor, patch) {
|
|
2070
2070
|
const { block, child, childPath } = findBlockAndChildFromPath(editor, patch.path);
|
|
2071
2071
|
if (!block)
|
|
2072
|
-
return debug$
|
|
2072
|
+
return debug$i("Block not found"), !1;
|
|
2073
2073
|
if (!child || !childPath)
|
|
2074
|
-
return debug$
|
|
2074
|
+
return debug$i("Child not found"), !1;
|
|
2075
2075
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
|
|
2076
2076
|
return !1;
|
|
2077
2077
|
const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, { allowExceedingIndices: !0 }), diff$1 = cleanupEfficiency(diff(child.text, newValue), 5);
|
|
@@ -2089,40 +2089,40 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
2089
2089
|
childPath: targetChildPath
|
|
2090
2090
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
2091
2091
|
if (!targetBlock || !targetBlockPath)
|
|
2092
|
-
return debug$
|
|
2092
|
+
return debug$i("Block not found"), !1;
|
|
2093
2093
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
2094
|
-
return debug$
|
|
2094
|
+
return debug$i("Ignoring patch targeting void value"), !1;
|
|
2095
2095
|
if (patch.path.length === 1) {
|
|
2096
2096
|
const { items: items2, position: position2 } = patch, blocksToInsert = toSlateValue(
|
|
2097
2097
|
items2,
|
|
2098
2098
|
{ schemaTypes },
|
|
2099
2099
|
KEY_TO_SLATE_ELEMENT.get(editor)
|
|
2100
2100
|
), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
2101
|
-
return debug$
|
|
2101
|
+
return debug$i(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, { at: [normalizedIdx2] }), debugState(editor, "after"), !0;
|
|
2102
2102
|
}
|
|
2103
2103
|
const { items, position } = patch;
|
|
2104
2104
|
if (!targetChild || !targetChildPath)
|
|
2105
|
-
return debug$
|
|
2105
|
+
return debug$i("Child not found"), !1;
|
|
2106
2106
|
const childrenToInsert = targetBlock && toSlateValue(
|
|
2107
2107
|
[{ ...targetBlock, children: items }],
|
|
2108
2108
|
{ schemaTypes },
|
|
2109
2109
|
KEY_TO_SLATE_ELEMENT.get(editor)
|
|
2110
2110
|
), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
2111
|
-
return debug$
|
|
2111
|
+
return debug$i(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, { at: childInsertPath }), debugState(editor, "after"), !0;
|
|
2112
2112
|
}
|
|
2113
2113
|
function setPatch(editor, patch) {
|
|
2114
2114
|
let value = patch.value;
|
|
2115
2115
|
typeof patch.path[3] == "string" && (value = {}, value[patch.path[3]] = patch.value);
|
|
2116
2116
|
const { block, blockPath, child, childPath } = findBlockAndChildFromPath(editor, patch.path);
|
|
2117
2117
|
if (!block)
|
|
2118
|
-
return debug$
|
|
2118
|
+
return debug$i("Block not found"), !1;
|
|
2119
2119
|
const isTextBlock = editor.isTextBlock(block);
|
|
2120
2120
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
2121
|
-
return debug$
|
|
2121
|
+
return debug$i("Ignoring setting void value"), !1;
|
|
2122
2122
|
if (debugState(editor, "before"), isTextBlock && child && childPath) {
|
|
2123
2123
|
if (slate.Text.isText(value) && slate.Text.isText(child)) {
|
|
2124
2124
|
const newText = child.text;
|
|
2125
|
-
value.text !== newText && (debug$
|
|
2125
|
+
value.text !== newText && (debug$i("Setting text property"), editor.apply({
|
|
2126
2126
|
type: "remove_text",
|
|
2127
2127
|
path: childPath,
|
|
2128
2128
|
offset: 0,
|
|
@@ -2134,7 +2134,7 @@ function setPatch(editor, patch) {
|
|
|
2134
2134
|
text: value.text
|
|
2135
2135
|
}), editor.onChange());
|
|
2136
2136
|
} else
|
|
2137
|
-
debug$
|
|
2137
|
+
debug$i("Setting non-text property"), editor.apply({
|
|
2138
2138
|
type: "set_node",
|
|
2139
2139
|
path: childPath,
|
|
2140
2140
|
properties: {},
|
|
@@ -2142,14 +2142,14 @@ function setPatch(editor, patch) {
|
|
|
2142
2142
|
});
|
|
2143
2143
|
return !0;
|
|
2144
2144
|
} else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
2145
|
-
debug$
|
|
2145
|
+
debug$i("Setting block property");
|
|
2146
2146
|
const { children, ...nextRest } = value, { children: prevChildren, ...prevRest } = block || { children: void 0 };
|
|
2147
2147
|
editor.apply({
|
|
2148
2148
|
type: "set_node",
|
|
2149
2149
|
path: blockPath,
|
|
2150
2150
|
properties: { ...prevRest },
|
|
2151
2151
|
newProperties: nextRest
|
|
2152
|
-
}), debug$
|
|
2152
|
+
}), debug$i("Setting children"), block.children.forEach((c, cIndex) => {
|
|
2153
2153
|
editor.apply({
|
|
2154
2154
|
type: "remove_node",
|
|
2155
2155
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -2170,7 +2170,7 @@ function setPatch(editor, patch) {
|
|
|
2170
2170
|
}
|
|
2171
2171
|
function unsetPatch(editor, patch, previousPatch) {
|
|
2172
2172
|
if (patch.path.length === 0) {
|
|
2173
|
-
debug$
|
|
2173
|
+
debug$i("Removing everything"), debugState(editor, "before");
|
|
2174
2174
|
const previousSelection = editor.selection;
|
|
2175
2175
|
return slate.Transforms.deselect(editor), editor.children.forEach((c, i) => {
|
|
2176
2176
|
slate.Transforms.removeNodes(editor, { at: [i] });
|
|
@@ -2182,17 +2182,17 @@ function unsetPatch(editor, patch, previousPatch) {
|
|
|
2182
2182
|
const { block, blockPath, child, childPath } = findBlockAndChildFromPath(editor, patch.path);
|
|
2183
2183
|
if (patch.path.length === 1) {
|
|
2184
2184
|
if (!block || !blockPath)
|
|
2185
|
-
return debug$
|
|
2185
|
+
return debug$i("Block not found"), !1;
|
|
2186
2186
|
const blockIndex = blockPath[0];
|
|
2187
|
-
return debug$
|
|
2187
|
+
return debug$i(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, { at: [blockIndex] }), debugState(editor, "after"), !0;
|
|
2188
2188
|
}
|
|
2189
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
2189
|
+
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$i("Child not found"), !1) : (debug$i(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose$4 && debug$i(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, { at: childPath }), debugState(editor, "after"), !0) : !1;
|
|
2190
2190
|
}
|
|
2191
2191
|
function isKeyedSegment(segment) {
|
|
2192
2192
|
return typeof segment == "object" && "_key" in segment;
|
|
2193
2193
|
}
|
|
2194
2194
|
function debugState(editor, stateName) {
|
|
2195
|
-
debugVerbose$
|
|
2195
|
+
debugVerbose$4 && (debug$i(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$i(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
2196
2196
|
}
|
|
2197
2197
|
function findBlockFromPath(editor, path) {
|
|
2198
2198
|
let blockIndex = -1;
|
|
@@ -2231,7 +2231,7 @@ function withoutPatching(editor, fn) {
|
|
|
2231
2231
|
function isPatching(editor) {
|
|
2232
2232
|
return PATCHING.get(editor);
|
|
2233
2233
|
}
|
|
2234
|
-
const debug$
|
|
2234
|
+
const debug$h = debugWithName("plugin:withUndoRedo"), debugVerbose$3 = debug$h.enabled && !1, SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2235
2235
|
const state = SAVING.get(editor);
|
|
2236
2236
|
return state === void 0 ? !0 : state;
|
|
2237
2237
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -2244,13 +2244,13 @@ function createWithUndoRedo(options) {
|
|
|
2244
2244
|
);
|
|
2245
2245
|
const remotePatches = getRemotePatches(editor);
|
|
2246
2246
|
patches$ && editor.subscriptions.push(() => {
|
|
2247
|
-
debug$
|
|
2247
|
+
debug$h("Subscribing to patches");
|
|
2248
2248
|
const sub = patches$.subscribe(({ patches: patches2, snapshot }) => {
|
|
2249
2249
|
let reset = !1;
|
|
2250
2250
|
patches2.forEach((patch) => {
|
|
2251
2251
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
2252
2252
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2253
|
-
debug$
|
|
2253
|
+
debug$h("Someone else cleared the content, resetting undo/redo history"), editor.history = { undos: [], redos: [] }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
2254
2254
|
return;
|
|
2255
2255
|
}
|
|
2256
2256
|
remotePatches.push({ patch, time: /* @__PURE__ */ new Date(), snapshot, previousSnapshot });
|
|
@@ -2258,7 +2258,7 @@ function createWithUndoRedo(options) {
|
|
|
2258
2258
|
}), previousSnapshot = snapshot;
|
|
2259
2259
|
});
|
|
2260
2260
|
return () => {
|
|
2261
|
-
debug$
|
|
2261
|
+
debug$h("Unsubscribing to patches"), sub.unsubscribe();
|
|
2262
2262
|
};
|
|
2263
2263
|
}), editor.history = { undos: [], redos: [] };
|
|
2264
2264
|
const { apply: apply2 } = editor;
|
|
@@ -2277,7 +2277,7 @@ function createWithUndoRedo(options) {
|
|
|
2277
2277
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
2278
2278
|
timestamp: /* @__PURE__ */ new Date()
|
|
2279
2279
|
};
|
|
2280
|
-
undos.push(newStep), debug$
|
|
2280
|
+
undos.push(newStep), debug$h("Created new undo step", step);
|
|
2281
2281
|
}
|
|
2282
2282
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
2283
2283
|
undos.shift();
|
|
@@ -2290,7 +2290,7 @@ function createWithUndoRedo(options) {
|
|
|
2290
2290
|
const { undos } = editor.history;
|
|
2291
2291
|
if (undos.length > 0) {
|
|
2292
2292
|
const step = undos[undos.length - 1];
|
|
2293
|
-
if (debug$
|
|
2293
|
+
if (debug$h("Undoing", step), step.operations.length > 0) {
|
|
2294
2294
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2295
2295
|
let transformedOperations = step.operations;
|
|
2296
2296
|
otherPatches.forEach((item) => {
|
|
@@ -2311,7 +2311,7 @@ function createWithUndoRedo(options) {
|
|
|
2311
2311
|
});
|
|
2312
2312
|
}), editor.normalize(), editor.onChange();
|
|
2313
2313
|
} catch (err) {
|
|
2314
|
-
debug$
|
|
2314
|
+
debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = { undos: [], redos: [] }, SAVING.set(editor, !0), editor.onChange();
|
|
2315
2315
|
return;
|
|
2316
2316
|
}
|
|
2317
2317
|
editor.history.redos.push(step), editor.history.undos.pop();
|
|
@@ -2323,7 +2323,7 @@ function createWithUndoRedo(options) {
|
|
|
2323
2323
|
const { redos } = editor.history;
|
|
2324
2324
|
if (redos.length > 0) {
|
|
2325
2325
|
const step = redos[redos.length - 1];
|
|
2326
|
-
if (debug$
|
|
2326
|
+
if (debug$h("Redoing", step), step.operations.length > 0) {
|
|
2327
2327
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2328
2328
|
let transformedOperations = step.operations;
|
|
2329
2329
|
otherPatches.forEach((item) => {
|
|
@@ -2344,7 +2344,7 @@ function createWithUndoRedo(options) {
|
|
|
2344
2344
|
});
|
|
2345
2345
|
}), editor.normalize(), editor.onChange();
|
|
2346
2346
|
} catch (err) {
|
|
2347
|
-
debug$
|
|
2347
|
+
debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = { undos: [], redos: [] }, SAVING.set(editor, !0), editor.onChange();
|
|
2348
2348
|
return;
|
|
2349
2349
|
}
|
|
2350
2350
|
editor.history.undos.push(step), editor.history.redos.pop();
|
|
@@ -2354,13 +2354,13 @@ function createWithUndoRedo(options) {
|
|
|
2354
2354
|
};
|
|
2355
2355
|
}
|
|
2356
2356
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2357
|
-
debugVerbose$
|
|
2357
|
+
debugVerbose$3 && (debug$h(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$h(`Operation ${JSON.stringify(operation)}`), debug$h(`Patch ${JSON.stringify(patch)}`));
|
|
2358
2358
|
const transformedOperation = { ...operation };
|
|
2359
2359
|
if (patch.type === "insert" && patch.path.length === 1) {
|
|
2360
2360
|
const insertBlockIndex = (snapshot || []).findIndex(
|
|
2361
2361
|
(blk) => isEqual__default.default({ _key: blk._key }, patch.path[0])
|
|
2362
2362
|
);
|
|
2363
|
-
return debug$
|
|
2363
|
+
return debug$h(
|
|
2364
2364
|
`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`
|
|
2365
2365
|
), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
2366
2366
|
}
|
|
@@ -2368,12 +2368,12 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2368
2368
|
const unsetBlockIndex = (previousSnapshot || []).findIndex(
|
|
2369
2369
|
(blk) => isEqual__default.default({ _key: blk._key }, patch.path[0])
|
|
2370
2370
|
);
|
|
2371
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
2371
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$h("Skipping transformation that targeted removed block"), []) : (debugVerbose$3 && (debug$h(`Selection ${JSON.stringify(editor.selection)}`), debug$h(
|
|
2372
2372
|
`Adjusting block path (-1) for '${transformedOperation.type}' operation and patch '${patch.type}'`
|
|
2373
2373
|
)), [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)]);
|
|
2374
2374
|
}
|
|
2375
2375
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2376
|
-
return debug$
|
|
2376
|
+
return debug$h(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
2377
2377
|
if (patch.type === "diffMatchPatch") {
|
|
2378
2378
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2379
2379
|
return !operationTargetBlock || !isEqual__default.default({ _key: operationTargetBlock._key }, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
@@ -2436,7 +2436,7 @@ function findOperationTargetBlock(editor, operation) {
|
|
|
2436
2436
|
let block;
|
|
2437
2437
|
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;
|
|
2438
2438
|
}
|
|
2439
|
-
const debug$
|
|
2439
|
+
const debug$g = debugWithName("plugin:withPatches");
|
|
2440
2440
|
function createWithPatches({
|
|
2441
2441
|
change$,
|
|
2442
2442
|
patches$,
|
|
@@ -2462,7 +2462,7 @@ function createWithPatches({
|
|
|
2462
2462
|
withoutSaving(editor, () => {
|
|
2463
2463
|
withPreserveKeys(editor, () => {
|
|
2464
2464
|
patches2.forEach((patch) => {
|
|
2465
|
-
debug$
|
|
2465
|
+
debug$g.enabled && debug$g(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
2466
2466
|
});
|
|
2467
2467
|
});
|
|
2468
2468
|
});
|
|
@@ -2474,10 +2474,10 @@ function createWithPatches({
|
|
|
2474
2474
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
2475
2475
|
};
|
|
2476
2476
|
return patches$ && editor.subscriptions.push(() => {
|
|
2477
|
-
debug$
|
|
2477
|
+
debug$g("Subscribing to patches$");
|
|
2478
2478
|
const sub = patches$.subscribe(handlePatches);
|
|
2479
2479
|
return () => {
|
|
2480
|
-
debug$
|
|
2480
|
+
debug$g("Unsubscribing to patches$"), sub.unsubscribe();
|
|
2481
2481
|
};
|
|
2482
2482
|
}), editor.apply = (operation) => {
|
|
2483
2483
|
if (readOnly)
|
|
@@ -2555,7 +2555,7 @@ function createWithPatches({
|
|
|
2555
2555
|
}, editor;
|
|
2556
2556
|
};
|
|
2557
2557
|
}
|
|
2558
|
-
const debug$
|
|
2558
|
+
const debug$f = debugWithName("plugin:withPlaceholderBlock");
|
|
2559
2559
|
function createWithPlaceholderBlock() {
|
|
2560
2560
|
return function(editor) {
|
|
2561
2561
|
const { apply: apply2 } = editor;
|
|
@@ -2564,14 +2564,14 @@ function createWithPlaceholderBlock() {
|
|
|
2564
2564
|
const node = op.node;
|
|
2565
2565
|
if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
|
|
2566
2566
|
const nextPath = slate.Path.next(op.path);
|
|
2567
|
-
editor.children[nextPath[0]] || (debug$
|
|
2567
|
+
editor.children[nextPath[0]] || (debug$f("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateEmptyBlock()));
|
|
2568
2568
|
}
|
|
2569
2569
|
}
|
|
2570
2570
|
apply2(op);
|
|
2571
2571
|
}, editor;
|
|
2572
2572
|
};
|
|
2573
2573
|
}
|
|
2574
|
-
const debug$
|
|
2574
|
+
const debug$e = debugWithName("plugin:withPortableTextBlockStyle");
|
|
2575
2575
|
function createWithPortableTextBlockStyle(types2) {
|
|
2576
2576
|
const defaultStyle = types2.styles[0].value;
|
|
2577
2577
|
return function(editor) {
|
|
@@ -2583,7 +2583,7 @@ function createWithPortableTextBlockStyle(types2) {
|
|
|
2583
2583
|
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)) {
|
|
2584
2584
|
const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
|
|
2585
2585
|
if (slate.Text.isText(child) && child.text === "") {
|
|
2586
|
-
debug$
|
|
2586
|
+
debug$e(`Normalizing split node to ${defaultStyle} style`, op), slate.Transforms.setNodes(editor, { style: defaultStyle }, { at: [op.path[0] + 1], voids: !1 });
|
|
2587
2587
|
break;
|
|
2588
2588
|
}
|
|
2589
2589
|
}
|
|
@@ -2599,9 +2599,9 @@ function createWithPortableTextBlockStyle(types2) {
|
|
|
2599
2599
|
match: (node) => editor.isTextBlock(node)
|
|
2600
2600
|
})
|
|
2601
2601
|
].forEach(([node, path]) => {
|
|
2602
|
-
editor.isTextBlock(node) && node.style === blockStyle ? (debug$
|
|
2602
|
+
editor.isTextBlock(node) && node.style === blockStyle ? (debug$e(`Unsetting block style '${blockStyle}'`), slate.Transforms.setNodes(editor, { ...node, style: defaultStyle }, {
|
|
2603
2603
|
at: path
|
|
2604
|
-
})) : (blockStyle ? debug$
|
|
2604
|
+
})) : (blockStyle ? debug$e(`Setting style '${blockStyle}'`) : debug$e("Setting default style", defaultStyle), slate.Transforms.setNodes(
|
|
2605
2605
|
editor,
|
|
2606
2606
|
{
|
|
2607
2607
|
...node,
|
|
@@ -2613,11 +2613,11 @@ function createWithPortableTextBlockStyle(types2) {
|
|
|
2613
2613
|
}, editor;
|
|
2614
2614
|
};
|
|
2615
2615
|
}
|
|
2616
|
-
const debug$
|
|
2616
|
+
const debug$d = debugWithName("plugin:withPortableTextLists"), MAX_LIST_LEVEL = 10;
|
|
2617
2617
|
function createWithPortableTextLists(types2) {
|
|
2618
2618
|
return function(editor) {
|
|
2619
2619
|
return editor.pteToggleListItem = (listItemStyle) => {
|
|
2620
|
-
editor.pteHasListStyle(listItemStyle) ? (debug$
|
|
2620
|
+
editor.pteHasListStyle(listItemStyle) ? (debug$d(`Remove list item '${listItemStyle}'`), editor.pteUnsetListItem(listItemStyle)) : (debug$d(`Add list item '${listItemStyle}'`), editor.pteSetListItem(listItemStyle));
|
|
2621
2621
|
}, editor.pteUnsetListItem = (listItemStyle) => {
|
|
2622
2622
|
editor.selection && [
|
|
2623
2623
|
...slate.Editor.nodes(editor, {
|
|
@@ -2631,7 +2631,7 @@ function createWithPortableTextLists(types2) {
|
|
|
2631
2631
|
listItem: void 0,
|
|
2632
2632
|
level: void 0
|
|
2633
2633
|
};
|
|
2634
|
-
debug$
|
|
2634
|
+
debug$d(`Unsetting list '${listItemStyle}'`), slate.Transforms.setNodes(editor, newNode, { at: path });
|
|
2635
2635
|
}
|
|
2636
2636
|
});
|
|
2637
2637
|
}, editor.pteSetListItem = (listItemStyle) => {
|
|
@@ -2641,7 +2641,7 @@ function createWithPortableTextLists(types2) {
|
|
|
2641
2641
|
match: (node) => editor.isTextBlock(node)
|
|
2642
2642
|
})
|
|
2643
2643
|
].forEach(([node, path]) => {
|
|
2644
|
-
debug$
|
|
2644
|
+
debug$d(`Setting list '${listItemStyle}'`), slate.Transforms.setNodes(
|
|
2645
2645
|
editor,
|
|
2646
2646
|
{
|
|
2647
2647
|
...node,
|
|
@@ -2661,7 +2661,7 @@ function createWithPortableTextLists(types2) {
|
|
|
2661
2661
|
})
|
|
2662
2662
|
];
|
|
2663
2663
|
return selectedBlocks.length === 0 ? !1 : (selectedBlocks.forEach(([node, path]) => {
|
|
2664
|
-
slate.Element.isElement(node) && (debug$
|
|
2664
|
+
slate.Element.isElement(node) && (debug$d("Unset list"), slate.Transforms.setNodes(
|
|
2665
2665
|
editor,
|
|
2666
2666
|
{
|
|
2667
2667
|
...node,
|
|
@@ -2683,7 +2683,7 @@ function createWithPortableTextLists(types2) {
|
|
|
2683
2683
|
return selectedBlocks.length === 0 ? !1 : (selectedBlocks.forEach(([node, path]) => {
|
|
2684
2684
|
if (editor.isListBlock(node)) {
|
|
2685
2685
|
let level = node.level || 1;
|
|
2686
|
-
reverse ? (level--, debug$
|
|
2686
|
+
reverse ? (level--, debug$d("Decrementing list level", Math.min(MAX_LIST_LEVEL, Math.max(1, level)))) : (level++, debug$d("Incrementing list level", Math.min(MAX_LIST_LEVEL, Math.max(1, level)))), slate.Transforms.setNodes(
|
|
2687
2687
|
editor,
|
|
2688
2688
|
{ level: Math.min(MAX_LIST_LEVEL, Math.max(1, level)) },
|
|
2689
2689
|
{ at: path }
|
|
@@ -2705,7 +2705,7 @@ function createWithPortableTextLists(types2) {
|
|
|
2705
2705
|
}, editor;
|
|
2706
2706
|
};
|
|
2707
2707
|
}
|
|
2708
|
-
const debug$
|
|
2708
|
+
const debug$c = debugWithName("plugin:withPortableTextMarkModel");
|
|
2709
2709
|
function createWithPortableTextMarkModel(types2, change$) {
|
|
2710
2710
|
return function(editor) {
|
|
2711
2711
|
const { apply: apply2, normalizeNode } = editor, decorators = types2.decorators.map((t) => t.value), forceNewSelection = () => {
|
|
@@ -2726,7 +2726,7 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2726
2726
|
) && mergeSpans(editor);
|
|
2727
2727
|
const [node, path] = nodeEntry, isSpan = slate.Text.isText(node) && node._type === types2.span.name, isTextBlock = editor.isTextBlock(node);
|
|
2728
2728
|
if (isSpan || isTextBlock) {
|
|
2729
|
-
if (isSpan && !Array.isArray(node.marks) && (debug$
|
|
2729
|
+
if (isSpan && !Array.isArray(node.marks) && (debug$c("Adding .marks to span node"), slate.Transforms.setNodes(editor, { marks: [] }, { at: path }), editor.onChange()), isSpan && (node.marks || []).length > 0) {
|
|
2730
2730
|
const spanMarks = node.marks || EMPTY_MARKS$1, annotationMarks = spanMarks.filter(
|
|
2731
2731
|
(mark) => !types2.decorators.map((dec) => dec.value).includes(mark)
|
|
2732
2732
|
);
|
|
@@ -2737,7 +2737,7 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2737
2737
|
return !((_a = block.markDefs) != null && _a.find((def) => def._key === mark));
|
|
2738
2738
|
}
|
|
2739
2739
|
) || [];
|
|
2740
|
-
orphanedMarks.length > 0 && (debug$
|
|
2740
|
+
orphanedMarks.length > 0 && (debug$c("Removing orphaned .marks from span node"), slate.Transforms.setNodes(
|
|
2741
2741
|
editor,
|
|
2742
2742
|
{ marks: spanMarks.filter((mark) => !orphanedMarks.includes(mark)) },
|
|
2743
2743
|
{ at: path }
|
|
@@ -2747,14 +2747,14 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2747
2747
|
for (const op of editor.operations) {
|
|
2748
2748
|
if (op.type === "merge_node" && op.path.length === 1 && "markDefs" in op.properties && op.properties._type === types2.block.name && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] - 1 >= 0) {
|
|
2749
2749
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
2750
|
-
if (debug$
|
|
2750
|
+
if (debug$c("Copying markDefs over to merged block", op), editor.isTextBlock(targetBlock)) {
|
|
2751
2751
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
2752
2752
|
isEqual__default.default(newMarkDefs, targetBlock.markDefs) || (slate.Transforms.setNodes(editor, { markDefs: newMarkDefs }, { at: targetPath, voids: !1 }), editor.onChange());
|
|
2753
2753
|
}
|
|
2754
2754
|
}
|
|
2755
2755
|
if (op.type === "split_node" && op.path.length === 1 && slate.Element.isElementProps(op.properties) && op.properties._type === types2.block.name && "markDefs" in op.properties && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] + 1 < editor.children.length) {
|
|
2756
2756
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] + 1]);
|
|
2757
|
-
if (debug$
|
|
2757
|
+
if (debug$c("Copying markDefs over to split block", op), editor.isTextBlock(targetBlock)) {
|
|
2758
2758
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [];
|
|
2759
2759
|
slate.Transforms.setNodes(
|
|
2760
2760
|
editor,
|
|
@@ -2778,7 +2778,7 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2778
2778
|
(op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1
|
|
2779
2779
|
)) {
|
|
2780
2780
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
2781
|
-
node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs) && (debug$
|
|
2781
|
+
node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs) && (debug$c("Removing markDef not in use"), slate.Transforms.setNodes(
|
|
2782
2782
|
editor,
|
|
2783
2783
|
{
|
|
2784
2784
|
markDefs: newMarkDefs
|
|
@@ -2811,7 +2811,7 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2811
2811
|
editor,
|
|
2812
2812
|
{ marks: marksWithoutAnnotationMarks },
|
|
2813
2813
|
{ at: slate.Path.next(selection.focus.path) }
|
|
2814
|
-
), debug$
|
|
2814
|
+
), debug$c("Inserting text at end of annotation");
|
|
2815
2815
|
return;
|
|
2816
2816
|
}
|
|
2817
2817
|
}
|
|
@@ -2903,7 +2903,7 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2903
2903
|
...slate.Editor.marks(editor) || {}
|
|
2904
2904
|
}.marks || []).includes(mark);
|
|
2905
2905
|
}, editor.pteToggleMark = (mark) => {
|
|
2906
|
-
editor.pteIsMarkActive(mark) ? (debug$
|
|
2906
|
+
editor.pteIsMarkActive(mark) ? (debug$c(`Remove mark '${mark}'`), slate.Editor.removeMark(editor, mark)) : (debug$c(`Add mark '${mark}'`), slate.Editor.addMark(editor, mark, !0));
|
|
2907
2907
|
}, editor;
|
|
2908
2908
|
};
|
|
2909
2909
|
function mergeSpans(editor) {
|
|
@@ -2917,12 +2917,12 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2917
2917
|
const [parent] = path.length > 1 ? slate.Editor.node(editor, slate.Path.parent(path)) : [void 0], nextPath = [path[0], path[1] + 1];
|
|
2918
2918
|
if (editor.isTextBlock(parent)) {
|
|
2919
2919
|
const nextNode = parent.children[nextPath[1]];
|
|
2920
|
-
slate.Text.isText(node) && slate.Text.isText(nextNode) && isEqual__default.default(nextNode.marks, node.marks) && (debug$
|
|
2920
|
+
slate.Text.isText(node) && slate.Text.isText(nextNode) && isEqual__default.default(nextNode.marks, node.marks) && (debug$c("Merging spans"), slate.Transforms.mergeNodes(editor, { at: nextPath, voids: !0 }), editor.onChange());
|
|
2921
2921
|
}
|
|
2922
2922
|
}
|
|
2923
2923
|
}
|
|
2924
2924
|
}
|
|
2925
|
-
const debug$
|
|
2925
|
+
const debug$b = debugWithName("plugin:withPortableTextSelections"), debugVerbose$2 = debug$b.enabled && !1;
|
|
2926
2926
|
function createWithPortableTextSelections(change$, types2) {
|
|
2927
2927
|
let prevSelection = null;
|
|
2928
2928
|
return function(editor) {
|
|
@@ -2938,7 +2938,7 @@ function createWithPortableTextSelections(change$, types2) {
|
|
|
2938
2938
|
ptRange = toPortableTextRange(value, editor.selection, types2), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange);
|
|
2939
2939
|
}
|
|
2940
2940
|
}
|
|
2941
|
-
debugVerbose$
|
|
2941
|
+
debugVerbose$2 && debug$b(
|
|
2942
2942
|
`Emitting selection ${JSON.stringify(ptRange || null)} (${JSON.stringify(
|
|
2943
2943
|
editor.selection
|
|
2944
2944
|
)})`
|
|
@@ -2952,7 +2952,7 @@ function createWithPortableTextSelections(change$, types2) {
|
|
|
2952
2952
|
}, editor;
|
|
2953
2953
|
};
|
|
2954
2954
|
}
|
|
2955
|
-
const debug$
|
|
2955
|
+
const debug$a = debugWithName("plugin:withSchemaTypes");
|
|
2956
2956
|
function createWithSchemaTypes({
|
|
2957
2957
|
schemaTypes,
|
|
2958
2958
|
keyGenerator
|
|
@@ -2963,12 +2963,12 @@ function createWithSchemaTypes({
|
|
|
2963
2963
|
return editor.normalizeNode = (entry) => {
|
|
2964
2964
|
const [node, path] = entry;
|
|
2965
2965
|
if (node._type === void 0 && path.length === 2) {
|
|
2966
|
-
debug$
|
|
2966
|
+
debug$a("Setting span type on text node without a type");
|
|
2967
2967
|
const span = node, key = span._key || keyGenerator();
|
|
2968
2968
|
slate.Transforms.setNodes(editor, { ...span, _type: schemaTypes.span.name, _key: key }, { at: path });
|
|
2969
2969
|
}
|
|
2970
2970
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
2971
|
-
debug$
|
|
2971
|
+
debug$a("Setting missing key on child node without a key");
|
|
2972
2972
|
const key = keyGenerator();
|
|
2973
2973
|
slate.Transforms.setNodes(editor, { _key: key }, { at: path });
|
|
2974
2974
|
}
|
|
@@ -2976,7 +2976,7 @@ function createWithSchemaTypes({
|
|
|
2976
2976
|
}, editor;
|
|
2977
2977
|
};
|
|
2978
2978
|
}
|
|
2979
|
-
const debug$
|
|
2979
|
+
const debug$9 = debugWithName("plugin:withUtils");
|
|
2980
2980
|
function createWithUtils({ schemaTypes, keyGenerator, portableTextEditor }) {
|
|
2981
2981
|
return function(editor) {
|
|
2982
2982
|
return editor.pteExpandToWord = () => {
|
|
@@ -2984,18 +2984,18 @@ function createWithUtils({ schemaTypes, keyGenerator, portableTextEditor }) {
|
|
|
2984
2984
|
if (selection && !slate.Range.isExpanded(selection)) {
|
|
2985
2985
|
const [textNode] = slate.Editor.node(editor, selection.focus, { depth: 2 });
|
|
2986
2986
|
if (!textNode || !slate.Text.isText(textNode) || textNode.text.length === 0) {
|
|
2987
|
-
debug$
|
|
2987
|
+
debug$9("pteExpandToWord: Can't expand to word here");
|
|
2988
2988
|
return;
|
|
2989
2989
|
}
|
|
2990
2990
|
const { focus } = selection, focusOffset = focus.offset, charsBefore = textNode.text.slice(0, focusOffset), charsAfter = textNode.text.slice(focusOffset, -1), isEmpty = (str) => str.match(/\s/g), whiteSpaceBeforeIndex = charsBefore.split("").reverse().findIndex((str) => isEmpty(str)), newStartOffset = whiteSpaceBeforeIndex > -1 ? charsBefore.length - whiteSpaceBeforeIndex : 0, whiteSpaceAfterIndex = charsAfter.split("").findIndex((obj) => isEmpty(obj)), newEndOffset = charsBefore.length + (whiteSpaceAfterIndex > -1 ? whiteSpaceAfterIndex : charsAfter.length + 1);
|
|
2991
2991
|
if (!(newStartOffset === newEndOffset || isNaN(newStartOffset) || isNaN(newEndOffset))) {
|
|
2992
|
-
debug$
|
|
2992
|
+
debug$9("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
|
|
2993
2993
|
anchor: { ...selection.anchor, offset: newStartOffset },
|
|
2994
2994
|
focus: { ...selection.focus, offset: newEndOffset }
|
|
2995
2995
|
});
|
|
2996
2996
|
return;
|
|
2997
2997
|
}
|
|
2998
|
-
debug$
|
|
2998
|
+
debug$9("pteExpandToWord: Can't expand to word here");
|
|
2999
2999
|
}
|
|
3000
3000
|
}, editor.pteCreateEmptyBlock = () => toSlateValue(
|
|
3001
3001
|
[
|
|
@@ -3018,7 +3018,7 @@ function createWithUtils({ schemaTypes, keyGenerator, portableTextEditor }) {
|
|
|
3018
3018
|
)[0], editor;
|
|
3019
3019
|
};
|
|
3020
3020
|
}
|
|
3021
|
-
const debug$
|
|
3021
|
+
const debug$8 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
|
|
3022
3022
|
marks: {
|
|
3023
3023
|
"mod+b": "strong",
|
|
3024
3024
|
"mod+i": "em",
|
|
@@ -3031,7 +3031,7 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3031
3031
|
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions || DEFAULT_HOTKEYS;
|
|
3032
3032
|
return function(editor) {
|
|
3033
3033
|
return editor.pteWithHotKeys = (event) => {
|
|
3034
|
-
var _a, _b, _c, _d;
|
|
3034
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3035
3035
|
Object.keys(activeHotkeys).forEach((cat) => {
|
|
3036
3036
|
if (cat === "marks")
|
|
3037
3037
|
for (const hotkey in activeHotkeys[cat]) {
|
|
@@ -3042,7 +3042,7 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3042
3042
|
const possibleMark = activeHotkeys[cat];
|
|
3043
3043
|
if (possibleMark) {
|
|
3044
3044
|
const mark = possibleMark[hotkey];
|
|
3045
|
-
debug$
|
|
3045
|
+
debug$8(`HotKey ${hotkey} to toggle ${mark}`), editor.pteToggleMark(mark);
|
|
3046
3046
|
}
|
|
3047
3047
|
}
|
|
3048
3048
|
}
|
|
@@ -3087,7 +3087,7 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3087
3087
|
if (isBackspace && editor.selection && editor.selection.focus.path[0] > 0 && slate.Range.isCollapsed(editor.selection)) {
|
|
3088
3088
|
const prevPath = slate.Path.previous(editor.selection.focus.path.slice(0, 1)), prevBlock = slate.Node.descendant(editor, prevPath), focusBlock = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
|
|
3089
3089
|
if (prevBlock && focusBlock && slate.Editor.isVoid(editor, prevBlock) && editor.selection.focus.offset === 0) {
|
|
3090
|
-
debug$
|
|
3090
|
+
debug$8("Preventing deleting void block above"), event.preventDefault(), event.stopPropagation();
|
|
3091
3091
|
const isTextBlock = types.isPortableTextTextBlock(focusBlock), isEmptyFocusBlock = isTextBlock && focusBlock.children.length === 1 && ((_d = (_c = focusBlock.children) == null ? void 0 : _c[0]) == null ? void 0 : _d.text) === "";
|
|
3092
3092
|
if (!isTextBlock || isEmptyFocusBlock) {
|
|
3093
3093
|
slate.Transforms.removeNodes(editor, { match: (n) => n === focusBlock }), slate.Transforms.select(editor, prevPath), editor.onChange();
|
|
@@ -3104,9 +3104,9 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3104
3104
|
const nextBlock = slate.Node.descendant(
|
|
3105
3105
|
editor,
|
|
3106
3106
|
slate.Path.next(editor.selection.focus.path.slice(0, 1))
|
|
3107
|
-
), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
3108
|
-
if (nextBlock && focusBlock && !slate.Editor.isVoid(editor, focusBlock) && slate.Editor.isVoid(editor, nextBlock)) {
|
|
3109
|
-
debug$
|
|
3107
|
+
), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath), isEmptyFocusBlock = types.isPortableTextTextBlock(focusBlock) && focusBlock.children.length === 1 && ((_f = (_e = focusBlock.children) == null ? void 0 : _e[0]) == null ? void 0 : _f.text) === "";
|
|
3108
|
+
if (nextBlock && focusBlock && !slate.Editor.isVoid(editor, focusBlock) && slate.Editor.isVoid(editor, nextBlock) && isEmptyFocusBlock) {
|
|
3109
|
+
debug$8("Preventing deleting void block below"), event.preventDefault(), event.stopPropagation(), slate.Transforms.removeNodes(editor, { match: (n) => n === focusBlock }), slate.Transforms.select(editor, focusBlockPath), editor.onChange();
|
|
3110
3110
|
return;
|
|
3111
3111
|
}
|
|
3112
3112
|
}
|
|
@@ -3406,7 +3406,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3406
3406
|
return !1;
|
|
3407
3407
|
}) && (valid = !1), { valid, resolution, value });
|
|
3408
3408
|
}
|
|
3409
|
-
const debug$
|
|
3409
|
+
const debug$7 = debugWithName("plugin:withInsertData");
|
|
3410
3410
|
function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
3411
3411
|
return function(editor) {
|
|
3412
3412
|
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => {
|
|
@@ -3445,13 +3445,13 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3445
3445
|
const asHTML = div.innerHTML;
|
|
3446
3446
|
contents.ownerDocument.body.removeChild(div);
|
|
3447
3447
|
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
3448
|
-
data.clearData(), data.setData("text/plain", asPlainText), data.setData("text/html", asHTML), data.setData("application/json", asJSON), data.setData("application/x-portable-text", asJSON), debug$
|
|
3448
|
+
data.clearData(), data.setData("text/plain", asPlainText), data.setData("text/html", asHTML), data.setData("application/json", asJSON), data.setData("application/x-portable-text", asJSON), debug$7("text", asPlainText), data.setData("application/x-portable-text-event-origin", originEvent || "external"), debug$7("Set fragment data", asJSON, asHTML);
|
|
3449
3449
|
}, editor.insertPortableTextData = (data) => {
|
|
3450
3450
|
var _a, _b;
|
|
3451
3451
|
if (!editor.selection)
|
|
3452
3452
|
return !1;
|
|
3453
3453
|
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
3454
|
-
if (debug$
|
|
3454
|
+
if (debug$7(`Inserting portable text from ${origin} event`, pText), pText) {
|
|
3455
3455
|
const parsed = JSON.parse(pText);
|
|
3456
3456
|
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
3457
3457
|
const slateValue = _regenerateKeys(
|
|
@@ -3469,7 +3469,7 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3469
3469
|
name: "pasteError",
|
|
3470
3470
|
description: errorDescription,
|
|
3471
3471
|
data: validation
|
|
3472
|
-
}), debug$
|
|
3472
|
+
}), debug$7("Invalid insert result", validation), !1;
|
|
3473
3473
|
}
|
|
3474
3474
|
return _insertFragment(editor, slateValue, schemaTypes), !0;
|
|
3475
3475
|
}
|
|
@@ -3478,11 +3478,11 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3478
3478
|
}, editor.insertTextOrHTMLData = (data) => {
|
|
3479
3479
|
var _a;
|
|
3480
3480
|
if (!editor.selection)
|
|
3481
|
-
return debug$
|
|
3481
|
+
return debug$7("No selection, not inserting"), !1;
|
|
3482
3482
|
change$.next({ type: "loading", isLoading: !0 });
|
|
3483
3483
|
const html = data.getData("text/html"), text = data.getData("text/plain");
|
|
3484
3484
|
if (html || text) {
|
|
3485
|
-
debug$
|
|
3485
|
+
debug$7("Inserting data", data);
|
|
3486
3486
|
let portableText, fragment, insertedType;
|
|
3487
3487
|
if (html) {
|
|
3488
3488
|
if (portableText = blockTools.htmlToBlocks(html, schemaTypes.portableText, {
|
|
@@ -3510,9 +3510,9 @@ Try to insert as plain text (shift-paste) instead.`;
|
|
|
3510
3510
|
name: "pasteError",
|
|
3511
3511
|
description: errorDescription,
|
|
3512
3512
|
data: validation
|
|
3513
|
-
}), debug$
|
|
3513
|
+
}), debug$7("Invalid insert result", validation), !1;
|
|
3514
3514
|
}
|
|
3515
|
-
return debug$
|
|
3515
|
+
return debug$7(`Inserting ${insertedType} fragment at ${JSON.stringify(editor.selection)}`), _insertFragment(editor, fragment, schemaTypes), change$.next({ type: "loading", isLoading: !1 }), !0;
|
|
3516
3516
|
}
|
|
3517
3517
|
return change$.next({ type: "loading", isLoading: !1 }), !1;
|
|
3518
3518
|
}, editor.insertData = (data) => {
|
|
@@ -3580,7 +3580,7 @@ function _insertFragment(editor, fragment, schemaTypes) {
|
|
|
3580
3580
|
const [focusBlock, focusPath] = slate.Editor.node(editor, editor.selection, { depth: 1 });
|
|
3581
3581
|
if (editor.isTextBlock(focusBlock) && editor.isTextBlock(fragment[0])) {
|
|
3582
3582
|
const { markDefs } = focusBlock;
|
|
3583
|
-
debug$
|
|
3583
|
+
debug$7("Mixing markDefs of focusBlock and fragments[0] block", markDefs, fragment[0].markDefs), isEqual__default.default(markDefs, fragment[0].markDefs) || slate.Transforms.setNodes(
|
|
3584
3584
|
editor,
|
|
3585
3585
|
{
|
|
3586
3586
|
markDefs: uniq__default.default([...fragment[0].markDefs || [], ...markDefs || []])
|
|
@@ -3663,10 +3663,10 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
3663
3663
|
};
|
|
3664
3664
|
}
|
|
3665
3665
|
};
|
|
3666
|
-
}, debug$
|
|
3666
|
+
}, debug$6 = debugWithName("component:PortableTextEditor:SlateContainer");
|
|
3667
3667
|
function SlateContainer(props) {
|
|
3668
3668
|
const { patches$, portableTextEditor, readOnly, maxBlocks, keyGenerator } = props, [[slateEditor, subscribe]] = react.useState(() => {
|
|
3669
|
-
debug$
|
|
3669
|
+
debug$6("Creating new Slate editor instance");
|
|
3670
3670
|
const { editor, subscribe: _sub } = withPlugins(slateReact.withReact(slate.createEditor()), {
|
|
3671
3671
|
keyGenerator,
|
|
3672
3672
|
maxBlocks,
|
|
@@ -3682,7 +3682,7 @@ function SlateContainer(props) {
|
|
|
3682
3682
|
unsubscribe();
|
|
3683
3683
|
};
|
|
3684
3684
|
}, [subscribe]), react.useEffect(() => {
|
|
3685
|
-
debug$
|
|
3685
|
+
debug$6("Re-initializing plugin chain"), withPlugins(slateEditor, {
|
|
3686
3686
|
keyGenerator,
|
|
3687
3687
|
maxBlocks,
|
|
3688
3688
|
patches$,
|
|
@@ -3692,7 +3692,7 @@ function SlateContainer(props) {
|
|
|
3692
3692
|
}, [keyGenerator, portableTextEditor, maxBlocks, readOnly, patches$, slateEditor]);
|
|
3693
3693
|
const initialValue = react.useMemo(() => [slateEditor.pteCreateEmptyBlock()], [slateEditor]);
|
|
3694
3694
|
return react.useEffect(() => () => {
|
|
3695
|
-
debug$
|
|
3695
|
+
debug$6("Destroying Slate editor"), slateEditor.destroy();
|
|
3696
3696
|
}, [slateEditor]), /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: slateEditor, initialValue, children: props.children });
|
|
3697
3697
|
}
|
|
3698
3698
|
const defaultKeyGenerator = () => content.randomKey(12), PortableTextEditorKeyGeneratorContext = react.createContext(defaultKeyGenerator), usePortableTextEditorKeyGenerator = () => {
|
|
@@ -3702,31 +3702,22 @@ const defaultKeyGenerator = () => content.randomKey(12), PortableTextEditorKeyGe
|
|
|
3702
3702
|
"The `usePortableTextEditorKeyGenerator` hook must be used inside the <PortableTextEditor> component's context."
|
|
3703
3703
|
);
|
|
3704
3704
|
return keyGenerator;
|
|
3705
|
-
},
|
|
3706
|
-
const selection = react.useContext(PortableTextEditorSelectionContext);
|
|
3707
|
-
if (selection === void 0)
|
|
3708
|
-
throw new Error(
|
|
3709
|
-
"The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context."
|
|
3710
|
-
);
|
|
3711
|
-
return selection;
|
|
3712
|
-
}, PortableTextEditorValueContext = react.createContext(
|
|
3713
|
-
void 0
|
|
3714
|
-
), PortableTextEditorReadOnlyContext = react.createContext(!1), usePortableTextEditorReadOnlyStatus = () => {
|
|
3705
|
+
}, PortableTextEditorReadOnlyContext = react.createContext(!1), usePortableTextEditorReadOnlyStatus = () => {
|
|
3715
3706
|
const readOnly = react.useContext(PortableTextEditorReadOnlyContext);
|
|
3716
3707
|
if (readOnly === void 0)
|
|
3717
3708
|
throw new Error(
|
|
3718
3709
|
"The `usePortableTextEditorReadOnly` hook must be used inside the <PortableTextEditor> component's context."
|
|
3719
3710
|
);
|
|
3720
3711
|
return readOnly;
|
|
3721
|
-
}, debug$
|
|
3712
|
+
}, debug$5 = debugWithName("hook:useSyncValue"), CURRENT_VALUE = /* @__PURE__ */ new WeakMap();
|
|
3722
3713
|
function useSyncValue(props) {
|
|
3723
3714
|
const { portableTextEditor, readOnly, keyGenerator } = props, { change$, schemaTypes } = portableTextEditor, previousValue = react.useRef(), slateEditor = slateReact.useSlate(), updateValueFunctionRef = react.useRef(), updateFromCurrentValue = react.useCallback(() => {
|
|
3724
3715
|
const currentValue = CURRENT_VALUE.get(portableTextEditor);
|
|
3725
3716
|
if (previousValue.current === currentValue) {
|
|
3726
|
-
debug$
|
|
3717
|
+
debug$5("Value is the same object as previous, not need to sync");
|
|
3727
3718
|
return;
|
|
3728
3719
|
}
|
|
3729
|
-
updateValueFunctionRef.current && currentValue && (debug$
|
|
3720
|
+
updateValueFunctionRef.current && currentValue && (debug$5("Updating the value debounced"), updateValueFunctionRef.current(currentValue));
|
|
3730
3721
|
}, [portableTextEditor]), updateValueDebounced = react.useMemo(
|
|
3731
3722
|
() => debounce__default.default(updateFromCurrentValue, 1e3, { trailing: !0, leading: !1 }),
|
|
3732
3723
|
[updateFromCurrentValue]
|
|
@@ -3737,17 +3728,17 @@ function useSyncValue(props) {
|
|
|
3737
3728
|
const isProcessingLocalChanges = isChangingLocally(slateEditor), isProcessingRemoteChanges = isChangingRemotely(slateEditor);
|
|
3738
3729
|
if (!readOnly) {
|
|
3739
3730
|
if (isProcessingLocalChanges) {
|
|
3740
|
-
debug$
|
|
3731
|
+
debug$5("Has local changes, not syncing value right now"), updateValueDebounced();
|
|
3741
3732
|
return;
|
|
3742
3733
|
}
|
|
3743
3734
|
if (isProcessingRemoteChanges) {
|
|
3744
|
-
debug$
|
|
3735
|
+
debug$5("Has remote changes, not syncing value right now"), updateValueDebounced();
|
|
3745
3736
|
return;
|
|
3746
3737
|
}
|
|
3747
3738
|
}
|
|
3748
3739
|
let isChanged = !1, isValid = !0;
|
|
3749
3740
|
const hadSelection = !!slateEditor.selection;
|
|
3750
|
-
if ((!value || value.length === 0) && (debug$
|
|
3741
|
+
if ((!value || value.length === 0) && (debug$5("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
3751
3742
|
withoutSaving(slateEditor, () => {
|
|
3752
3743
|
withoutPatching(slateEditor, () => {
|
|
3753
3744
|
hadSelection && slate.Transforms.deselect(slateEditor);
|
|
@@ -3784,7 +3775,7 @@ function useSyncValue(props) {
|
|
|
3784
3775
|
`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${(_c = validation.resolution) == null ? void 0 : _c.description}`
|
|
3785
3776
|
), validation.resolution.patches.forEach((patch) => {
|
|
3786
3777
|
change$.next({ type: "patch", patch });
|
|
3787
|
-
})), validation.valid || (_d = validation.resolution) != null && _d.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
3778
|
+
})), validation.valid || (_d = validation.resolution) != null && _d.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$5.enabled && debug$5("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$5.enabled && debug$5("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), isChanged = !0) : (change$.next({
|
|
3788
3779
|
type: "invalidValue",
|
|
3789
3780
|
resolution: validation.resolution,
|
|
3790
3781
|
value
|
|
@@ -3792,14 +3783,14 @@ function useSyncValue(props) {
|
|
|
3792
3783
|
}
|
|
3793
3784
|
if (!oldBlock && isValid) {
|
|
3794
3785
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, schemaTypes, keyGenerator);
|
|
3795
|
-
debug$
|
|
3786
|
+
debug$5.enabled && debug$5(
|
|
3796
3787
|
"Validating and inserting new block in the end of the value",
|
|
3797
3788
|
currentBlock
|
|
3798
3789
|
), validation.valid || (_e = validation.resolution) != null && _e.autoResolve ? withPreserveKeys(slateEditor, () => {
|
|
3799
3790
|
slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
3800
3791
|
at: [currentBlockIndex]
|
|
3801
3792
|
});
|
|
3802
|
-
}) : (debug$
|
|
3793
|
+
}) : (debug$5("Invalid", validation), change$.next({
|
|
3803
3794
|
type: "invalidValue",
|
|
3804
3795
|
resolution: validation.resolution,
|
|
3805
3796
|
value
|
|
@@ -3812,11 +3803,11 @@ function useSyncValue(props) {
|
|
|
3812
3803
|
});
|
|
3813
3804
|
}
|
|
3814
3805
|
if (!isValid) {
|
|
3815
|
-
debug$
|
|
3806
|
+
debug$5("Invalid value, returning");
|
|
3816
3807
|
return;
|
|
3817
3808
|
}
|
|
3818
3809
|
if (isChanged) {
|
|
3819
|
-
debug$
|
|
3810
|
+
debug$5("Server value changed, syncing editor");
|
|
3820
3811
|
try {
|
|
3821
3812
|
slateEditor.onChange();
|
|
3822
3813
|
} catch (err) {
|
|
@@ -3832,7 +3823,7 @@ function useSyncValue(props) {
|
|
|
3832
3823
|
focus: { path: [0, 0], offset: 0 }
|
|
3833
3824
|
}), slateEditor.onChange()), change$.next({ type: "value", value });
|
|
3834
3825
|
} else
|
|
3835
|
-
debug$
|
|
3826
|
+
debug$5("Server value and editor value is equal, no need to sync.");
|
|
3836
3827
|
previousValue.current = value;
|
|
3837
3828
|
};
|
|
3838
3829
|
return updateValueFunctionRef.current = updateFunction, updateFunction;
|
|
@@ -3860,7 +3851,7 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3860
3851
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach(
|
|
3861
3852
|
(_, index) => {
|
|
3862
3853
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
3863
|
-
childIndex > 0 && (debug$
|
|
3854
|
+
childIndex > 0 && (debug$5("Removing child"), slate.Transforms.removeNodes(slateEditor, {
|
|
3864
3855
|
at: [currentBlockIndex, childIndex]
|
|
3865
3856
|
}));
|
|
3866
3857
|
}
|
|
@@ -3868,7 +3859,7 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3868
3859
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild == null ? void 0 : oldBlockChild.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
3869
3860
|
if (isChildChanged)
|
|
3870
3861
|
if (currentBlockChild._key === (oldBlockChild == null ? void 0 : oldBlockChild._key)) {
|
|
3871
|
-
debug$
|
|
3862
|
+
debug$5("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
3872
3863
|
at: path
|
|
3873
3864
|
});
|
|
3874
3865
|
const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -3876,7 +3867,7 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3876
3867
|
at: { focus: { path, offset: 0 }, anchor: { path, offset: oldBlockChild.text.length } }
|
|
3877
3868
|
}), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
3878
3869
|
at: path
|
|
3879
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
3870
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$5("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(
|
|
3880
3871
|
slateEditor,
|
|
3881
3872
|
{ _key: VOID_CHILD_KEY },
|
|
3882
3873
|
{
|
|
@@ -3884,13 +3875,13 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3884
3875
|
voids: !0
|
|
3885
3876
|
}
|
|
3886
3877
|
));
|
|
3887
|
-
} else oldBlockChild ? (debug$
|
|
3878
|
+
} else oldBlockChild ? (debug$5("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
|
|
3888
3879
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3889
3880
|
}), withPreserveKeys(slateEditor, () => {
|
|
3890
3881
|
slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3891
3882
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3892
3883
|
});
|
|
3893
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
3884
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$5("Inserting new child", currentBlockChild), withPreserveKeys(slateEditor, () => {
|
|
3894
3885
|
slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3895
3886
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3896
3887
|
}), slateEditor.onChange();
|
|
@@ -3898,9 +3889,9 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3898
3889
|
});
|
|
3899
3890
|
}
|
|
3900
3891
|
}
|
|
3901
|
-
const debug$
|
|
3892
|
+
const debug$4 = debugWithName("component:PortableTextEditor:Synchronizer"), debugVerbose$1 = debug$4.enabled && !1, FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3;
|
|
3902
3893
|
function Synchronizer(props) {
|
|
3903
|
-
const
|
|
3894
|
+
const portableTextEditor = usePortableTextEditor(), keyGenerator = usePortableTextEditorKeyGenerator(), readOnly = usePortableTextEditorReadOnlyStatus(), { change$, getValue, onChange, value } = props, pendingPatches = react.useRef([]), syncValue = useSyncValue({
|
|
3904
3895
|
keyGenerator,
|
|
3905
3896
|
onChange,
|
|
3906
3897
|
portableTextEditor,
|
|
@@ -3911,13 +3902,13 @@ function Synchronizer(props) {
|
|
|
3911
3902
|
}, [slateEditor]);
|
|
3912
3903
|
const onFlushPendingPatches = react.useCallback(() => {
|
|
3913
3904
|
if (pendingPatches.current.length > 0) {
|
|
3914
|
-
debug$
|
|
3905
|
+
debug$4("Flushing pending patches"), debugVerbose$1 && debug$4(`Patches:
|
|
3915
3906
|
${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
3916
|
-
const snapshot =
|
|
3907
|
+
const snapshot = getValue();
|
|
3917
3908
|
change$.next({ type: "mutation", patches: pendingPatches.current, snapshot }), pendingPatches.current = [];
|
|
3918
3909
|
}
|
|
3919
3910
|
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
|
|
3920
|
-
}, [slateEditor,
|
|
3911
|
+
}, [slateEditor, getValue, change$]), onFlushPendingPatchesThrottled = react.useMemo(() => throttle__default.default(
|
|
3921
3912
|
() => {
|
|
3922
3913
|
if (slate.Editor.isNormalizing(slateEditor)) {
|
|
3923
3914
|
onFlushPendingPatches();
|
|
@@ -3934,37 +3925,54 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
3934
3925
|
react.useEffect(() => () => {
|
|
3935
3926
|
onFlushPendingPatches();
|
|
3936
3927
|
}, [onFlushPendingPatches]), react.useEffect(() => {
|
|
3937
|
-
debug$
|
|
3928
|
+
debug$4("Subscribing to editor changes$");
|
|
3938
3929
|
const sub = change$.subscribe((next) => {
|
|
3939
3930
|
switch (next.type) {
|
|
3940
3931
|
case "patch":
|
|
3941
3932
|
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !0), pendingPatches.current.push(next.patch), onFlushPendingPatchesThrottled(), onChange(next);
|
|
3942
3933
|
break;
|
|
3943
|
-
case "selection":
|
|
3944
|
-
react.startTransition(() => {
|
|
3945
|
-
debugVerbose && debug$3("Setting selection"), setSelection(next.selection);
|
|
3946
|
-
}), onChange(next);
|
|
3947
|
-
break;
|
|
3948
3934
|
default:
|
|
3949
3935
|
onChange(next);
|
|
3950
3936
|
}
|
|
3951
3937
|
});
|
|
3952
3938
|
return () => {
|
|
3953
|
-
debug$
|
|
3939
|
+
debug$4("Unsubscribing to changes$"), sub.unsubscribe();
|
|
3954
3940
|
};
|
|
3955
3941
|
}, [change$, onChange, onFlushPendingPatchesThrottled, slateEditor]);
|
|
3956
3942
|
const handleOnline = react.useCallback(() => {
|
|
3957
|
-
debug$
|
|
3943
|
+
debug$4("Editor is online, syncing from props.value"), change$.next({ type: "connection", value: "online" }), syncValue(value);
|
|
3958
3944
|
}, [change$, syncValue, value]), handleOffline = react.useCallback(() => {
|
|
3959
|
-
debug$
|
|
3945
|
+
debug$4("Editor is offline"), change$.next({ type: "connection", value: "offline" });
|
|
3960
3946
|
}, [change$]);
|
|
3961
3947
|
react.useEffect(() => (portableTextEditor.props.patches$ && (window.addEventListener("online", handleOnline), window.addEventListener("offline", handleOffline)), () => {
|
|
3962
3948
|
portableTextEditor.props.patches$ && (window.removeEventListener("online", handleOnline), window.removeEventListener("offline", handleOffline));
|
|
3963
3949
|
}));
|
|
3964
3950
|
const isInitialValueFromProps = react.useRef(!0);
|
|
3965
3951
|
return react.useEffect(() => {
|
|
3966
|
-
debug$
|
|
3967
|
-
}, [change$, syncValue, value]),
|
|
3952
|
+
debug$4("Value from props changed, syncing new value"), syncValue(value), isInitialValueFromProps.current && (change$.next({ type: "loading", isLoading: !1 }), change$.next({ type: "ready" }), isInitialValueFromProps.current = !1);
|
|
3953
|
+
}, [change$, syncValue, value]), null;
|
|
3954
|
+
}
|
|
3955
|
+
const PortableTextEditorSelectionContext = react.createContext(null), usePortableTextEditorSelection = () => {
|
|
3956
|
+
const selection = react.useContext(PortableTextEditorSelectionContext);
|
|
3957
|
+
if (selection === void 0)
|
|
3958
|
+
throw new Error(
|
|
3959
|
+
"The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context."
|
|
3960
|
+
);
|
|
3961
|
+
return selection;
|
|
3962
|
+
}, debug$3 = debugWithName("component:PortableTextEditor:SelectionProvider"), debugVerbose = debug$3.enabled && !1;
|
|
3963
|
+
function PortableTextEditorSelectionProvider(props) {
|
|
3964
|
+
const { change$ } = props, [selection, setSelection] = react.useState(null);
|
|
3965
|
+
return react.useEffect(() => {
|
|
3966
|
+
debug$3("Subscribing to selection changes$");
|
|
3967
|
+
const subscription = change$.subscribe((next) => {
|
|
3968
|
+
next.type === "selection" && react.startTransition(() => {
|
|
3969
|
+
debugVerbose && debug$3("Setting selection"), setSelection(next.selection);
|
|
3970
|
+
});
|
|
3971
|
+
});
|
|
3972
|
+
return () => {
|
|
3973
|
+
debug$3("Unsubscribing to selection changes$"), subscription.unsubscribe();
|
|
3974
|
+
};
|
|
3975
|
+
}, [change$]), /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children });
|
|
3968
3976
|
}
|
|
3969
3977
|
var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3970
3978
|
const debug$2 = debugWithName("component:PortableTextEditor");
|
|
@@ -3972,8 +3980,11 @@ class PortableTextEditor extends react.Component {
|
|
|
3972
3980
|
constructor(props) {
|
|
3973
3981
|
if (super(props), __publicField(this, "change$", new rxjs.Subject()), __publicField(this, "schemaTypes"), __publicField(this, "editable"), __publicField(this, "setEditable", (editable) => {
|
|
3974
3982
|
this.editable = { ...this.editable, ...editable };
|
|
3983
|
+
}), __publicField(this, "getValue", () => {
|
|
3984
|
+
if (this.editable)
|
|
3985
|
+
return this.editable.getValue();
|
|
3975
3986
|
}), !props.schemaType)
|
|
3976
|
-
throw new Error('PortableTextEditor: missing "
|
|
3987
|
+
throw new Error('PortableTextEditor: missing "schemaType" property');
|
|
3977
3988
|
props.incomingPatches$ && console.warn("The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"), this.change$.next({ type: "loading", isLoading: !0 }), this.schemaTypes = getPortableTextMemberSchemaTypes(
|
|
3978
3989
|
props.schemaType.hasOwnProperty("jsonType") ? props.schemaType : compileType(props.schemaType)
|
|
3979
3990
|
);
|
|
@@ -3993,18 +4004,18 @@ class PortableTextEditor extends react.Component {
|
|
|
3993
4004
|
patches$: _patches$,
|
|
3994
4005
|
portableTextEditor: this,
|
|
3995
4006
|
readOnly,
|
|
3996
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
)
|
|
4007
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorKeyGeneratorContext.Provider, { value: keyGenerator, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorReadOnlyContext.Provider, { value: readOnly, children: /* @__PURE__ */ jsxRuntime.jsxs(PortableTextEditorSelectionProvider, { change$, children: [
|
|
4008
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4009
|
+
Synchronizer,
|
|
4010
|
+
{
|
|
4011
|
+
change$,
|
|
4012
|
+
getValue: this.getValue,
|
|
4013
|
+
onChange,
|
|
4014
|
+
value
|
|
4015
|
+
}
|
|
4016
|
+
),
|
|
4017
|
+
children
|
|
4018
|
+
] }) }) }) })
|
|
4008
4019
|
}
|
|
4009
4020
|
);
|
|
4010
4021
|
}
|
|
@@ -4264,7 +4275,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4264
4275
|
pointerEvents: "none",
|
|
4265
4276
|
left: 0,
|
|
4266
4277
|
right: 0
|
|
4267
|
-
},
|
|
4278
|
+
}, PortableTextEditable = react.forwardRef(function(props, forwardedRef) {
|
|
4268
4279
|
const {
|
|
4269
4280
|
hotkeys,
|
|
4270
4281
|
onBlur,
|
|
@@ -4285,7 +4296,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4285
4296
|
scrollSelectionIntoView,
|
|
4286
4297
|
spellCheck,
|
|
4287
4298
|
...restProps
|
|
4288
|
-
} = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), keyGenerator = usePortableTextEditorKeyGenerator(), ref = react.useRef(null), [editableElement, setEditableElement] = react.useState(null), [hasInvalidValue, setHasInvalidValue] = react.useState(!1), [rangeDecorationState, setRangeDecorationsState] = react.useState(
|
|
4299
|
+
} = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), keyGenerator = usePortableTextEditorKeyGenerator(), ref = react.useRef(null), [editableElement, setEditableElement] = react.useState(null), [hasInvalidValue, setHasInvalidValue] = react.useState(!1), [rangeDecorationState, setRangeDecorationsState] = react.useState([]);
|
|
4289
4300
|
react.useImperativeHandle(forwardedRef, () => ref.current);
|
|
4290
4301
|
const rangeDecorationsRef = react.useRef(rangeDecorations), { change$, schemaTypes } = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name, withInsertData = react.useMemo(
|
|
4291
4302
|
() => createWithInsertData(change$, schemaTypes, keyGenerator),
|
|
@@ -4377,7 +4388,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4377
4388
|
return;
|
|
4378
4389
|
}
|
|
4379
4390
|
}
|
|
4380
|
-
setRangeDecorationsState(
|
|
4391
|
+
setRangeDecorationsState([]);
|
|
4381
4392
|
},
|
|
4382
4393
|
[portableTextEditor, rangeDecorations, schemaTypes, slateEditor]
|
|
4383
4394
|
);
|
|
@@ -4526,9 +4537,9 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4526
4537
|
}
|
|
4527
4538
|
];
|
|
4528
4539
|
if (path.length === 0)
|
|
4529
|
-
return
|
|
4540
|
+
return [];
|
|
4530
4541
|
const result = rangeDecorationState.filter((item) => slate.Range.isCollapsed(item) ? path.length !== 2 ? !1 : slate.Path.equals(item.focus.path, path) && slate.Path.equals(item.anchor.path, path) : slate.Range.intersection(item, { anchor: { path, offset: 0 }, focus: { path, offset: 0 } }) || slate.Range.includes(item, path));
|
|
4531
|
-
return result.length > 0 ? result :
|
|
4542
|
+
return result.length > 0 ? result : [];
|
|
4532
4543
|
},
|
|
4533
4544
|
[slateEditor, schemaTypes, rangeDecorationState]
|
|
4534
4545
|
);
|