@portabletext/editor 1.22.0 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +65 -2
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +26 -12
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +65 -2
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +26 -12
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +1111 -44
- package/lib/behaviors/index.d.ts +1111 -44
- package/lib/index.cjs +542 -333
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +446 -1
- package/lib/index.d.ts +446 -1
- package/lib/index.js +546 -335
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.d.cts +73 -0
- package/lib/selectors/index.d.ts +73 -0
- package/package.json +23 -18
- package/src/behavior-actions/behavior.action.data-transfer-set.ts +7 -0
- package/src/behavior-actions/behavior.action.insert-blocks.ts +61 -0
- package/src/behavior-actions/behavior.actions.ts +75 -0
- package/src/behaviors/behavior.core.deserialize.ts +46 -0
- package/src/behaviors/behavior.core.serialize.ts +44 -0
- package/src/behaviors/behavior.core.ts +7 -0
- package/src/behaviors/behavior.types.ts +39 -2
- package/src/converters/converter.json.ts +53 -0
- package/src/converters/converter.portable-text.deserialize.test.ts +686 -0
- package/src/converters/converter.portable-text.ts +59 -0
- package/src/converters/converter.text-html.deserialize.test.ts +349 -0
- package/src/converters/converter.text-html.serialize.test.ts +233 -0
- package/src/converters/converter.text-html.ts +61 -0
- package/src/converters/converter.text-plain.test.ts +241 -0
- package/src/converters/converter.text-plain.ts +91 -0
- package/src/converters/converter.ts +65 -0
- package/src/converters/converters.ts +11 -0
- package/src/editor/Editable.tsx +3 -13
- package/src/editor/create-editor.ts +3 -0
- package/src/editor/editor-machine.ts +25 -1
- package/src/editor/editor-selector.ts +1 -0
- package/src/editor/editor-snapshot.ts +5 -0
- package/src/editor/plugins/create-with-event-listeners.ts +44 -0
- package/src/internal-utils/asserters.ts +9 -0
- package/src/internal-utils/mime-type.ts +1 -0
- package/src/internal-utils/parse-blocks.ts +136 -0
- package/src/internal-utils/test-key-generator.ts +9 -0
- package/src/selectors/selector.get-selected-spans.test.ts +1 -0
- package/src/selectors/selector.get-selection-text.test.ts +1 -0
- package/src/selectors/selector.is-active-decorator.test.ts +1 -0
- package/src/utils/util.slice-blocks.test.ts +216 -35
- package/src/utils/util.slice-blocks.ts +37 -10
- package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +0 -181
- package/src/editor/plugins/createWithInsertData.ts +0 -425
package/lib/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$
|
|
3
|
+
var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$j = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isSelectionCollapsed = require("./_chunks-cjs/selector.is-selection-collapsed.cjs"), util_isEmptyTextBlock = require("./_chunks-cjs/util.is-empty-text-block.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$
|
|
7
|
+
var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$j), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
|
|
8
8
|
function createEditorSchema(portableTextType) {
|
|
9
9
|
if (!portableTextType)
|
|
10
10
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
@@ -370,7 +370,7 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING
|
|
|
370
370
|
] }), $[1] = props.value._key, $[2] = props.value._type, $[3] = t1) : t1 = $[3], t1;
|
|
371
371
|
};
|
|
372
372
|
DefaultObject.displayName = "DefaultObject";
|
|
373
|
-
const debug$
|
|
373
|
+
const debug$i = debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
|
|
374
374
|
const $ = reactCompilerRuntime.c(51), {
|
|
375
375
|
children,
|
|
376
376
|
element,
|
|
@@ -408,39 +408,39 @@ const debug$j = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
408
408
|
$[16] !== editor || $[17] !== element ? (t9 = (event_0) => {
|
|
409
409
|
const targetBlock = IS_DRAGGING_ELEMENT_TARGET.get(editor);
|
|
410
410
|
if (targetBlock) {
|
|
411
|
-
IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$
|
|
411
|
+
IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$i("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
|
|
412
412
|
const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor);
|
|
413
413
|
IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor);
|
|
414
414
|
let targetPath = slateReact.ReactEditor.findPath(editor, targetBlock);
|
|
415
415
|
const myPath = slateReact.ReactEditor.findPath(editor, element), isBefore = slate.Path.isBefore(myPath, targetPath);
|
|
416
416
|
if (dragPosition === "bottom" && !isBefore) {
|
|
417
417
|
if (targetPath[0] >= editor.children.length - 1) {
|
|
418
|
-
debug$
|
|
418
|
+
debug$i("target is already at the bottom, not moving");
|
|
419
419
|
return;
|
|
420
420
|
}
|
|
421
421
|
const originalPath = targetPath;
|
|
422
|
-
targetPath = slate.Path.next(targetPath), debug$
|
|
422
|
+
targetPath = slate.Path.next(targetPath), debug$i(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
|
|
423
423
|
}
|
|
424
424
|
if (dragPosition === "top" && isBefore && targetPath[0] !== editor.children.length - 1) {
|
|
425
425
|
const originalPath_0 = targetPath;
|
|
426
|
-
targetPath = slate.Path.previous(targetPath), debug$
|
|
426
|
+
targetPath = slate.Path.previous(targetPath), debug$i(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
|
|
427
427
|
}
|
|
428
428
|
if (slate.Path.equals(targetPath, myPath)) {
|
|
429
|
-
event_0.preventDefault(), debug$
|
|
429
|
+
event_0.preventDefault(), debug$i("targetPath and myPath is the same, not moving");
|
|
430
430
|
return;
|
|
431
431
|
}
|
|
432
|
-
debug$
|
|
432
|
+
debug$i(`Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), slate.Transforms.moveNodes(editor, {
|
|
433
433
|
at: myPath,
|
|
434
434
|
to: targetPath
|
|
435
435
|
}), editor.onChange();
|
|
436
436
|
return;
|
|
437
437
|
}
|
|
438
|
-
debug$
|
|
438
|
+
debug$i("No target element, not doing anything");
|
|
439
439
|
}, $[16] = editor, $[17] = element, $[18] = t9) : t9 = $[18];
|
|
440
440
|
const handleDragEnd = t9;
|
|
441
441
|
let t10;
|
|
442
442
|
$[19] !== editor || $[20] !== element ? (t10 = (event_1) => {
|
|
443
|
-
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$
|
|
443
|
+
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$i("On drop (prevented)", element), event_1.preventDefault(), event_1.stopPropagation(), setIsDragOver(!1));
|
|
444
444
|
}, $[19] = editor, $[20] = element, $[21] = t10) : t10 = $[21];
|
|
445
445
|
const handleDrop = t10;
|
|
446
446
|
let t11;
|
|
@@ -457,10 +457,10 @@ const debug$j = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
457
457
|
let t12;
|
|
458
458
|
$[26] !== blockElement || $[27] !== editor || $[28] !== handleDrag || $[29] !== isInline || $[30] !== isVoid ? (t12 = (event_3) => {
|
|
459
459
|
if (!isVoid || isInline) {
|
|
460
|
-
debug$
|
|
460
|
+
debug$i("Not dragging block"), IS_DRAGGING_BLOCK_ELEMENT.delete(editor), IS_DRAGGING.set(editor, !1);
|
|
461
461
|
return;
|
|
462
462
|
}
|
|
463
|
-
if (debug$
|
|
463
|
+
if (debug$i("Drag start"), IS_DRAGGING.set(editor, !0), event_3.dataTransfer && (event_3.dataTransfer.setData("application/portable-text", "something"), event_3.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
|
|
464
464
|
let dragGhost = blockElement.cloneNode(!0);
|
|
465
465
|
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
466
466
|
if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
|
|
@@ -1497,14 +1497,14 @@ function getAlphabetFromPattern(pattern) {
|
|
|
1497
1497
|
for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
|
|
1498
1498
|
return s;
|
|
1499
1499
|
}
|
|
1500
|
-
function match(text, pattern, searchLocation) {
|
|
1500
|
+
function match(text, pattern, searchLocation, options = {}) {
|
|
1501
1501
|
if (text === null || pattern === null || searchLocation === null) throw new Error("Null input. (match())");
|
|
1502
1502
|
const loc = Math.max(0, Math.min(searchLocation, text.length));
|
|
1503
1503
|
if (text === pattern) return 0;
|
|
1504
1504
|
if (text.length) {
|
|
1505
1505
|
if (text.substring(loc, loc + pattern.length) === pattern) return loc;
|
|
1506
1506
|
} else return -1;
|
|
1507
|
-
return bitap(text, pattern, loc);
|
|
1507
|
+
return bitap(text, pattern, loc, options);
|
|
1508
1508
|
}
|
|
1509
1509
|
function diffText1(diffs) {
|
|
1510
1510
|
const text = [];
|
|
@@ -1536,10 +1536,10 @@ function levenshtein(diffs) {
|
|
|
1536
1536
|
}
|
|
1537
1537
|
return leven += Math.max(insertions, deletions), leven;
|
|
1538
1538
|
}
|
|
1539
|
-
function xIndex(diffs,
|
|
1539
|
+
function xIndex(diffs, location) {
|
|
1540
1540
|
let chars1 = 0, chars2 = 0, lastChars1 = 0, lastChars2 = 0, x;
|
|
1541
|
-
for (x = 0; x < diffs.length && (diffs[x][0] !== DIFF_INSERT && (chars1 += diffs[x][1].length), diffs[x][0] !== DIFF_DELETE && (chars2 += diffs[x][1].length), !(chars1 >
|
|
1542
|
-
return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (
|
|
1541
|
+
for (x = 0; x < diffs.length && (diffs[x][0] !== DIFF_INSERT && (chars1 += diffs[x][1].length), diffs[x][0] !== DIFF_DELETE && (chars2 += diffs[x][1].length), !(chars1 > location)); x++) lastChars1 = chars1, lastChars2 = chars2;
|
|
1542
|
+
return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (location - lastChars1);
|
|
1543
1543
|
}
|
|
1544
1544
|
function countUtf8Bytes(str) {
|
|
1545
1545
|
let bytes = 0;
|
|
@@ -1732,7 +1732,7 @@ function isRedoing(editor) {
|
|
|
1732
1732
|
function setIsRedoing(editor, isRedoing2) {
|
|
1733
1733
|
IS_REDOING.set(editor, isRedoing2);
|
|
1734
1734
|
}
|
|
1735
|
-
const debug$
|
|
1735
|
+
const debug$h = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
1736
1736
|
const state = SAVING.get(editor);
|
|
1737
1737
|
return state === void 0 ? !0 : state;
|
|
1738
1738
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -1745,7 +1745,7 @@ function createWithUndoRedo(options) {
|
|
|
1745
1745
|
let previousSnapshot = fromSlateValue(editor.children, blockSchemaType.name);
|
|
1746
1746
|
const remotePatches = getRemotePatches(editor);
|
|
1747
1747
|
options.subscriptions.push(() => {
|
|
1748
|
-
debug$
|
|
1748
|
+
debug$h("Subscribing to patches");
|
|
1749
1749
|
const sub = editorActor.on("patches", ({
|
|
1750
1750
|
patches: patches2,
|
|
1751
1751
|
snapshot
|
|
@@ -1754,7 +1754,7 @@ function createWithUndoRedo(options) {
|
|
|
1754
1754
|
patches2.forEach((patch) => {
|
|
1755
1755
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
1756
1756
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
1757
|
-
debug$
|
|
1757
|
+
debug$h("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
1758
1758
|
undos: [],
|
|
1759
1759
|
redos: []
|
|
1760
1760
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -1770,7 +1770,7 @@ function createWithUndoRedo(options) {
|
|
|
1770
1770
|
}), previousSnapshot = snapshot;
|
|
1771
1771
|
});
|
|
1772
1772
|
return () => {
|
|
1773
|
-
debug$
|
|
1773
|
+
debug$h("Unsubscribing to patches"), sub.unsubscribe();
|
|
1774
1774
|
};
|
|
1775
1775
|
}), editor.history = {
|
|
1776
1776
|
undos: [],
|
|
@@ -1809,7 +1809,7 @@ function createWithUndoRedo(options) {
|
|
|
1809
1809
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
1810
1810
|
timestamp: /* @__PURE__ */ new Date()
|
|
1811
1811
|
};
|
|
1812
|
-
undos.push(newStep), debug$
|
|
1812
|
+
undos.push(newStep), debug$h("Created new undo step", step);
|
|
1813
1813
|
}
|
|
1814
1814
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
1815
1815
|
undos.shift();
|
|
@@ -1826,7 +1826,7 @@ function createWithUndoRedo(options) {
|
|
|
1826
1826
|
} = editor.history;
|
|
1827
1827
|
if (undos.length > 0) {
|
|
1828
1828
|
const step = undos[undos.length - 1];
|
|
1829
|
-
if (debug$
|
|
1829
|
+
if (debug$h("Undoing", step), step.operations.length > 0) {
|
|
1830
1830
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
1831
1831
|
let transformedOperations = step.operations;
|
|
1832
1832
|
otherPatches.forEach((item) => {
|
|
@@ -1844,7 +1844,7 @@ function createWithUndoRedo(options) {
|
|
|
1844
1844
|
});
|
|
1845
1845
|
}), editor.normalize(), editor.onChange();
|
|
1846
1846
|
} catch (err) {
|
|
1847
|
-
debug$
|
|
1847
|
+
debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
1848
1848
|
undos: [],
|
|
1849
1849
|
redos: []
|
|
1850
1850
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -1863,7 +1863,7 @@ function createWithUndoRedo(options) {
|
|
|
1863
1863
|
} = editor.history;
|
|
1864
1864
|
if (redos.length > 0) {
|
|
1865
1865
|
const step = redos[redos.length - 1];
|
|
1866
|
-
if (debug$
|
|
1866
|
+
if (debug$h("Redoing", step), step.operations.length > 0) {
|
|
1867
1867
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
1868
1868
|
let transformedOperations = step.operations;
|
|
1869
1869
|
otherPatches.forEach((item) => {
|
|
@@ -1880,7 +1880,7 @@ function createWithUndoRedo(options) {
|
|
|
1880
1880
|
});
|
|
1881
1881
|
}), editor.normalize(), editor.onChange();
|
|
1882
1882
|
} catch (err) {
|
|
1883
|
-
debug$
|
|
1883
|
+
debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
1884
1884
|
undos: [],
|
|
1885
1885
|
redos: []
|
|
1886
1886
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -1900,16 +1900,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
1900
1900
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
|
|
1901
1901
|
_key: blk._key
|
|
1902
1902
|
}, patch.path[0]));
|
|
1903
|
-
return debug$
|
|
1903
|
+
return debug$h(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
1904
1904
|
}
|
|
1905
1905
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
1906
1906
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
|
|
1907
1907
|
_key: blk._key
|
|
1908
1908
|
}, patch.path[0]));
|
|
1909
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
1909
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$h("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
1910
1910
|
}
|
|
1911
1911
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
1912
|
-
return debug$
|
|
1912
|
+
return debug$h(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
1913
1913
|
if (patch.type === "diffMatchPatch") {
|
|
1914
1914
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
1915
1915
|
return !operationTargetBlock || !isEqual__default.default({
|
|
@@ -2189,7 +2189,7 @@ const syncValueCallback = ({
|
|
|
2189
2189
|
}
|
|
2190
2190
|
}
|
|
2191
2191
|
}
|
|
2192
|
-
}), debug$
|
|
2192
|
+
}), debug$g = debugWithName("hook:useSyncValue");
|
|
2193
2193
|
async function updateValue({
|
|
2194
2194
|
context,
|
|
2195
2195
|
sendBack,
|
|
@@ -2199,7 +2199,7 @@ async function updateValue({
|
|
|
2199
2199
|
}) {
|
|
2200
2200
|
let isChanged = !1, isValid = !0;
|
|
2201
2201
|
const hadSelection = !!slateEditor.selection;
|
|
2202
|
-
if ((!value || value.length === 0) && (debug$
|
|
2202
|
+
if ((!value || value.length === 0) && (debug$g("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
2203
2203
|
withoutSaving(slateEditor, () => {
|
|
2204
2204
|
withoutPatching(slateEditor, () => {
|
|
2205
2205
|
hadSelection && slate.Transforms.deselect(slateEditor);
|
|
@@ -2255,14 +2255,14 @@ async function updateValue({
|
|
|
2255
2255
|
});
|
|
2256
2256
|
}
|
|
2257
2257
|
if (!isValid) {
|
|
2258
|
-
debug$
|
|
2258
|
+
debug$g("Invalid value, returning"), sendBack({
|
|
2259
2259
|
type: "done syncing",
|
|
2260
2260
|
value
|
|
2261
2261
|
});
|
|
2262
2262
|
return;
|
|
2263
2263
|
}
|
|
2264
2264
|
if (isChanged) {
|
|
2265
|
-
debug$
|
|
2265
|
+
debug$g("Server value changed, syncing editor");
|
|
2266
2266
|
try {
|
|
2267
2267
|
slateEditor.onChange();
|
|
2268
2268
|
} catch (err) {
|
|
@@ -2290,7 +2290,7 @@ async function updateValue({
|
|
|
2290
2290
|
value
|
|
2291
2291
|
});
|
|
2292
2292
|
} else
|
|
2293
|
-
debug$
|
|
2293
|
+
debug$g("Server value and editor value is equal, no need to sync.");
|
|
2294
2294
|
sendBack({
|
|
2295
2295
|
type: "done syncing",
|
|
2296
2296
|
value
|
|
@@ -2324,7 +2324,7 @@ function syncBlock({
|
|
|
2324
2324
|
type: "patch",
|
|
2325
2325
|
patch
|
|
2326
2326
|
});
|
|
2327
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
2327
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$g.enabled && debug$g("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$g.enabled && debug$g("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
2328
2328
|
type: "invalid value",
|
|
2329
2329
|
resolution: validation.resolution,
|
|
2330
2330
|
value
|
|
@@ -2332,9 +2332,9 @@ function syncBlock({
|
|
|
2332
2332
|
}
|
|
2333
2333
|
if (!oldBlock && blockValid) {
|
|
2334
2334
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2335
|
-
debug$
|
|
2335
|
+
debug$g.enabled && debug$g("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2336
2336
|
at: [currentBlockIndex]
|
|
2337
|
-
}) : (debug$
|
|
2337
|
+
}) : (debug$g("Invalid", validation), sendBack({
|
|
2338
2338
|
type: "invalid value",
|
|
2339
2339
|
resolution: validation.resolution,
|
|
2340
2340
|
value
|
|
@@ -2362,14 +2362,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2362
2362
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
2363
2363
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
2364
2364
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
2365
|
-
childIndex > 0 && (debug$
|
|
2365
|
+
childIndex > 0 && (debug$g("Removing child"), slate.Transforms.removeNodes(slateEditor, {
|
|
2366
2366
|
at: [currentBlockIndex, childIndex]
|
|
2367
2367
|
}));
|
|
2368
2368
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
2369
2369
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2370
2370
|
if (isChildChanged)
|
|
2371
2371
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2372
|
-
debug$
|
|
2372
|
+
debug$g("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2373
2373
|
at: path
|
|
2374
2374
|
});
|
|
2375
2375
|
const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -2386,23 +2386,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2386
2386
|
}
|
|
2387
2387
|
}), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
2388
2388
|
at: path
|
|
2389
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
2389
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$g("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
|
|
2390
2390
|
_key: VOID_CHILD_KEY
|
|
2391
2391
|
}, {
|
|
2392
2392
|
at: [...path, 0],
|
|
2393
2393
|
voids: !0
|
|
2394
2394
|
}));
|
|
2395
|
-
} else oldBlockChild ? (debug$
|
|
2395
|
+
} else oldBlockChild ? (debug$g("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
|
|
2396
2396
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2397
2397
|
}), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2398
2398
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2399
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
2399
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$g("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2400
2400
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2401
2401
|
}), slateEditor.onChange());
|
|
2402
2402
|
});
|
|
2403
2403
|
}
|
|
2404
2404
|
}
|
|
2405
|
-
const debug$
|
|
2405
|
+
const debug$f = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
2406
2406
|
function Synchronizer(props) {
|
|
2407
2407
|
const $ = reactCompilerRuntime.c(40), {
|
|
2408
2408
|
editorActor,
|
|
@@ -2473,19 +2473,19 @@ function Synchronizer(props) {
|
|
|
2473
2473
|
}, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), React.useEffect(t11, t12);
|
|
2474
2474
|
let t13, t14;
|
|
2475
2475
|
$[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
|
|
2476
|
-
debug$
|
|
2476
|
+
debug$f("Value from props changed, syncing new value"), syncActorRef.send({
|
|
2477
2477
|
type: "update value",
|
|
2478
2478
|
value
|
|
2479
2479
|
});
|
|
2480
2480
|
}, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), React.useEffect(t13, t14);
|
|
2481
2481
|
let t15;
|
|
2482
2482
|
$[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
|
|
2483
|
-
debug$
|
|
2483
|
+
debug$f("Subscribing to patch events");
|
|
2484
2484
|
const sub = editorActor.on("patch", (event_1) => {
|
|
2485
2485
|
mutationActorRef.send(event_1);
|
|
2486
2486
|
});
|
|
2487
2487
|
return () => {
|
|
2488
|
-
debug$
|
|
2488
|
+
debug$f("Unsubscribing to patch events"), sub.unsubscribe();
|
|
2489
2489
|
};
|
|
2490
2490
|
}, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
|
|
2491
2491
|
let t16;
|
|
@@ -2500,11 +2500,255 @@ function _temp(s) {
|
|
|
2500
2500
|
return s.context.value;
|
|
2501
2501
|
}
|
|
2502
2502
|
Synchronizer.displayName = "Synchronizer";
|
|
2503
|
-
const
|
|
2503
|
+
const converterJson = {
|
|
2504
|
+
serialize: ({
|
|
2505
|
+
context,
|
|
2506
|
+
event
|
|
2507
|
+
}) => {
|
|
2508
|
+
const portableTextConverter = context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2509
|
+
return portableTextConverter ? {
|
|
2510
|
+
...portableTextConverter.serialize({
|
|
2511
|
+
context,
|
|
2512
|
+
event
|
|
2513
|
+
}),
|
|
2514
|
+
mimeType: "application/json",
|
|
2515
|
+
originEvent: event.originEvent
|
|
2516
|
+
} : {
|
|
2517
|
+
type: "serialization.failure",
|
|
2518
|
+
mimeType: "application/json",
|
|
2519
|
+
originEvent: event.originEvent,
|
|
2520
|
+
reason: "No application/x-portable-text Converter found"
|
|
2521
|
+
};
|
|
2522
|
+
},
|
|
2523
|
+
deserialize: ({
|
|
2524
|
+
context,
|
|
2525
|
+
event
|
|
2526
|
+
}) => {
|
|
2527
|
+
const portableTextConverter = context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2528
|
+
return portableTextConverter ? {
|
|
2529
|
+
...portableTextConverter.deserialize({
|
|
2530
|
+
context,
|
|
2531
|
+
event
|
|
2532
|
+
}),
|
|
2533
|
+
mimeType: "application/json"
|
|
2534
|
+
} : {
|
|
2535
|
+
type: "deserialization.failure",
|
|
2536
|
+
mimeType: "application/json",
|
|
2537
|
+
reason: "No application/x-portable-text Converter found"
|
|
2538
|
+
};
|
|
2539
|
+
},
|
|
2540
|
+
mimeType: "application/json"
|
|
2541
|
+
};
|
|
2542
|
+
function isTypedObject(object) {
|
|
2543
|
+
return isRecord(object) && typeof object._type == "string";
|
|
2544
|
+
}
|
|
2545
|
+
function isRecord(value) {
|
|
2546
|
+
return !!value && (typeof value == "object" || typeof value == "function");
|
|
2547
|
+
}
|
|
2548
|
+
function parseBlock({
|
|
2549
|
+
context,
|
|
2550
|
+
block
|
|
2551
|
+
}) {
|
|
2552
|
+
if (!isTypedObject(block) || block._type !== context.schema.block.name && !context.schema.blockObjects.some((blockObject) => blockObject.name === block._type))
|
|
2553
|
+
return;
|
|
2554
|
+
if (!types.isPortableTextTextBlock(block))
|
|
2555
|
+
return {
|
|
2556
|
+
...block,
|
|
2557
|
+
_key: context.keyGenerator()
|
|
2558
|
+
};
|
|
2559
|
+
const markDefKeyMap = /* @__PURE__ */ new Map(), markDefs = (block.markDefs ?? []).flatMap((markDef) => {
|
|
2560
|
+
if (context.schema.annotations.some((annotation) => annotation.name === markDef._type)) {
|
|
2561
|
+
const _key = context.keyGenerator();
|
|
2562
|
+
return markDefKeyMap.set(markDef._key, _key), [{
|
|
2563
|
+
...markDef,
|
|
2564
|
+
_key
|
|
2565
|
+
}];
|
|
2566
|
+
}
|
|
2567
|
+
return [];
|
|
2568
|
+
}), children = block.children.flatMap((child) => {
|
|
2569
|
+
if (!isTypedObject(child))
|
|
2570
|
+
return [];
|
|
2571
|
+
if (child._type !== context.schema.span.name && !context.schema.inlineObjects.some((inlineObject) => inlineObject.name === child._type))
|
|
2572
|
+
return [];
|
|
2573
|
+
if (!types.isPortableTextSpan(child))
|
|
2574
|
+
return [{
|
|
2575
|
+
...child,
|
|
2576
|
+
_key: context.keyGenerator()
|
|
2577
|
+
}];
|
|
2578
|
+
const marks = (child.marks ?? []).flatMap((mark) => markDefKeyMap.has(mark) ? [markDefKeyMap.get(mark)] : context.schema.decorators.some((decorator) => decorator.value === mark) ? [mark] : []);
|
|
2579
|
+
return [{
|
|
2580
|
+
...child,
|
|
2581
|
+
_key: context.keyGenerator(),
|
|
2582
|
+
marks
|
|
2583
|
+
}];
|
|
2584
|
+
}), parsedBlock = {
|
|
2585
|
+
...block,
|
|
2586
|
+
_key: context.keyGenerator(),
|
|
2587
|
+
children: children.length > 0 ? children : [{
|
|
2588
|
+
_key: context.keyGenerator(),
|
|
2589
|
+
_type: context.schema.span.name,
|
|
2590
|
+
text: "",
|
|
2591
|
+
marks: []
|
|
2592
|
+
}],
|
|
2593
|
+
markDefs
|
|
2594
|
+
};
|
|
2595
|
+
if (!context.schema.styles.find((style) => style.value === block.style)) {
|
|
2596
|
+
const defaultStyle = context.schema.styles[0].value;
|
|
2597
|
+
defaultStyle !== void 0 ? parsedBlock.style = defaultStyle : delete parsedBlock.style;
|
|
2598
|
+
}
|
|
2599
|
+
return context.schema.lists.find((list) => list.value === block.listItem) || (delete parsedBlock.listItem, delete parsedBlock.level), parsedBlock;
|
|
2600
|
+
}
|
|
2601
|
+
const converterPortableText = {
|
|
2602
|
+
serialize: ({
|
|
2603
|
+
context,
|
|
2604
|
+
event
|
|
2605
|
+
}) => {
|
|
2606
|
+
if (!context.selection)
|
|
2607
|
+
return {
|
|
2608
|
+
type: "serialization.failure",
|
|
2609
|
+
mimeType: "application/x-portable-text",
|
|
2610
|
+
originEvent: event.originEvent,
|
|
2611
|
+
reason: "No selection"
|
|
2612
|
+
};
|
|
2613
|
+
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2614
|
+
blocks: context.value,
|
|
2615
|
+
selection: context.selection
|
|
2616
|
+
});
|
|
2617
|
+
return {
|
|
2618
|
+
type: "serialization.success",
|
|
2619
|
+
data: JSON.stringify(blocks),
|
|
2620
|
+
mimeType: "application/x-portable-text",
|
|
2621
|
+
originEvent: event.originEvent
|
|
2622
|
+
};
|
|
2623
|
+
},
|
|
2624
|
+
deserialize: ({
|
|
2625
|
+
context,
|
|
2626
|
+
event
|
|
2627
|
+
}) => {
|
|
2628
|
+
const blocks = JSON.parse(event.data);
|
|
2629
|
+
if (!Array.isArray(blocks))
|
|
2630
|
+
return {
|
|
2631
|
+
type: "deserialization.failure",
|
|
2632
|
+
mimeType: "application/x-portable-text",
|
|
2633
|
+
reason: "Data is not an array"
|
|
2634
|
+
};
|
|
2635
|
+
const parsedBlocks = blocks.flatMap((block) => {
|
|
2636
|
+
const parsedBlock = parseBlock({
|
|
2637
|
+
context,
|
|
2638
|
+
block
|
|
2639
|
+
});
|
|
2640
|
+
return parsedBlock ? [parsedBlock] : [];
|
|
2641
|
+
});
|
|
2642
|
+
return parsedBlocks.length === 0 && blocks.length > 0 ? {
|
|
2643
|
+
type: "deserialization.failure",
|
|
2644
|
+
mimeType: "application/x-portable-text",
|
|
2645
|
+
reason: "No blocks were parsed"
|
|
2646
|
+
} : {
|
|
2647
|
+
type: "deserialization.success",
|
|
2648
|
+
data: parsedBlocks,
|
|
2649
|
+
mimeType: "application/x-portable-text"
|
|
2650
|
+
};
|
|
2651
|
+
},
|
|
2652
|
+
mimeType: "application/x-portable-text"
|
|
2653
|
+
}, converterTextHtml = {
|
|
2654
|
+
serialize: ({
|
|
2655
|
+
context,
|
|
2656
|
+
event
|
|
2657
|
+
}) => {
|
|
2658
|
+
if (!context.selection)
|
|
2659
|
+
return {
|
|
2660
|
+
type: "serialization.failure",
|
|
2661
|
+
mimeType: "text/html",
|
|
2662
|
+
originEvent: event.originEvent,
|
|
2663
|
+
reason: "No selection"
|
|
2664
|
+
};
|
|
2665
|
+
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2666
|
+
blocks: context.value,
|
|
2667
|
+
selection: context.selection
|
|
2668
|
+
}), html = toHtml.toHTML(blocks, {
|
|
2669
|
+
onMissingComponent: !1,
|
|
2670
|
+
components: {
|
|
2671
|
+
unknownType: ({
|
|
2672
|
+
children
|
|
2673
|
+
}) => children !== void 0 ? `${children}` : ""
|
|
2674
|
+
}
|
|
2675
|
+
});
|
|
2676
|
+
return html === "" ? {
|
|
2677
|
+
type: "serialization.failure",
|
|
2678
|
+
mimeType: "text/html",
|
|
2679
|
+
originEvent: event.originEvent,
|
|
2680
|
+
reason: "Serialized HTML is empty"
|
|
2681
|
+
} : {
|
|
2682
|
+
type: "serialization.success",
|
|
2683
|
+
data: html,
|
|
2684
|
+
mimeType: "text/html",
|
|
2685
|
+
originEvent: event.originEvent
|
|
2686
|
+
};
|
|
2687
|
+
},
|
|
2688
|
+
deserialize: ({
|
|
2689
|
+
context,
|
|
2690
|
+
event
|
|
2691
|
+
}) => ({
|
|
2692
|
+
type: "deserialization.success",
|
|
2693
|
+
data: blockTools.htmlToBlocks(event.data, context.schema.portableText, {
|
|
2694
|
+
keyGenerator: context.keyGenerator,
|
|
2695
|
+
unstable_whitespaceOnPasteMode: context.schema.block.options.unstable_whitespaceOnPasteMode
|
|
2696
|
+
}),
|
|
2697
|
+
mimeType: "text/html"
|
|
2698
|
+
}),
|
|
2699
|
+
mimeType: "text/html"
|
|
2700
|
+
}, converterTextPlain = {
|
|
2701
|
+
mimeType: "text/plain",
|
|
2702
|
+
serialize: ({
|
|
2703
|
+
context,
|
|
2704
|
+
event
|
|
2705
|
+
}) => context.selection ? {
|
|
2706
|
+
type: "serialization.success",
|
|
2707
|
+
data: util_sliceBlocks.sliceBlocks({
|
|
2708
|
+
blocks: context.value,
|
|
2709
|
+
selection: context.selection
|
|
2710
|
+
}).map((block) => types.isPortableTextTextBlock(block) ? block.children.map((child) => child._type === context.schema.span.name ? child.text : `[${context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]`).join("") : `[${context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]`).join(`
|
|
2711
|
+
|
|
2712
|
+
`),
|
|
2713
|
+
mimeType: "text/plain",
|
|
2714
|
+
originEvent: event.originEvent
|
|
2715
|
+
} : {
|
|
2716
|
+
type: "serialization.failure",
|
|
2717
|
+
mimeType: "text/plain",
|
|
2718
|
+
originEvent: event.originEvent,
|
|
2719
|
+
reason: "No selection"
|
|
2720
|
+
},
|
|
2721
|
+
deserialize: ({
|
|
2722
|
+
context,
|
|
2723
|
+
event
|
|
2724
|
+
}) => {
|
|
2725
|
+
const textToHtml = `<html><body>${escapeHtml(event.data).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`;
|
|
2726
|
+
return {
|
|
2727
|
+
type: "deserialization.success",
|
|
2728
|
+
data: blockTools.htmlToBlocks(textToHtml, context.schema.portableText, {
|
|
2729
|
+
keyGenerator: context.keyGenerator
|
|
2730
|
+
}),
|
|
2731
|
+
mimeType: "text/plain"
|
|
2732
|
+
};
|
|
2733
|
+
}
|
|
2734
|
+
}, entityMap = {
|
|
2735
|
+
"&": "&",
|
|
2736
|
+
"<": "<",
|
|
2737
|
+
">": ">",
|
|
2738
|
+
'"': """,
|
|
2739
|
+
"'": "'",
|
|
2740
|
+
"/": "/",
|
|
2741
|
+
"`": "`",
|
|
2742
|
+
"=": "="
|
|
2743
|
+
};
|
|
2744
|
+
function escapeHtml(str) {
|
|
2745
|
+
return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
|
|
2746
|
+
}
|
|
2747
|
+
const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$e = debugWithName("operationToPatches");
|
|
2504
2748
|
function createOperationToPatches(types2) {
|
|
2505
2749
|
const textBlockName = types2.block.name;
|
|
2506
2750
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
2507
|
-
debug$
|
|
2751
|
+
debug$e.enabled && debug$e("Operation", JSON.stringify(operation, null, 2));
|
|
2508
2752
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
2509
2753
|
if (!block)
|
|
2510
2754
|
throw new Error("Could not find block");
|
|
@@ -2597,7 +2841,7 @@ function createOperationToPatches(types2) {
|
|
|
2597
2841
|
_key: block.children[operation.path[1] - 1]._key
|
|
2598
2842
|
}])];
|
|
2599
2843
|
}
|
|
2600
|
-
return debug$
|
|
2844
|
+
return debug$e("Something was inserted into a void block. Not producing editor patches."), [];
|
|
2601
2845
|
}
|
|
2602
2846
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
2603
2847
|
const patches$1 = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -2655,9 +2899,9 @@ function createOperationToPatches(types2) {
|
|
|
2655
2899
|
_key: block._key
|
|
2656
2900
|
}, "children", {
|
|
2657
2901
|
_key: spanToRemove._key
|
|
2658
|
-
}])] : (debug$
|
|
2902
|
+
}])] : (debug$e("Span not found in editor trying to remove node"), []);
|
|
2659
2903
|
} else
|
|
2660
|
-
return debug$
|
|
2904
|
+
return debug$e("Not creating patch inside object block"), [];
|
|
2661
2905
|
}
|
|
2662
2906
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2663
2907
|
const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -2683,7 +2927,7 @@ function createOperationToPatches(types2) {
|
|
|
2683
2927
|
_key: removedSpan._key
|
|
2684
2928
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
2685
2929
|
} else
|
|
2686
|
-
debug$
|
|
2930
|
+
debug$e("Void nodes can't be merged, not creating any patches");
|
|
2687
2931
|
return patches$1;
|
|
2688
2932
|
}
|
|
2689
2933
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -2864,9 +3108,11 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2864
3108
|
deleteBackward,
|
|
2865
3109
|
deleteForward,
|
|
2866
3110
|
insertBreak,
|
|
3111
|
+
insertData,
|
|
2867
3112
|
insertSoftBreak,
|
|
2868
3113
|
insertText,
|
|
2869
|
-
select
|
|
3114
|
+
select,
|
|
3115
|
+
setFragmentData
|
|
2870
3116
|
} = editor;
|
|
2871
3117
|
return editor.deleteBackward = (unit) => {
|
|
2872
3118
|
if (isApplyingBehaviorActions(editor)) {
|
|
@@ -2906,6 +3152,19 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2906
3152
|
},
|
|
2907
3153
|
editor
|
|
2908
3154
|
});
|
|
3155
|
+
}, editor.insertData = (dataTransfer) => {
|
|
3156
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
3157
|
+
insertData(dataTransfer);
|
|
3158
|
+
return;
|
|
3159
|
+
}
|
|
3160
|
+
editorActor.send({
|
|
3161
|
+
type: "behavior event",
|
|
3162
|
+
behaviorEvent: {
|
|
3163
|
+
type: "deserialize",
|
|
3164
|
+
dataTransfer
|
|
3165
|
+
},
|
|
3166
|
+
editor
|
|
3167
|
+
});
|
|
2909
3168
|
}, editor.insertSoftBreak = () => {
|
|
2910
3169
|
if (isApplyingBehaviorActions(editor)) {
|
|
2911
3170
|
insertSoftBreak();
|
|
@@ -2952,6 +3211,24 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2952
3211
|
select(location);
|
|
2953
3212
|
}
|
|
2954
3213
|
});
|
|
3214
|
+
}, editor.setFragmentData = (dataTransfer, originEvent) => {
|
|
3215
|
+
if (originEvent === "drag") {
|
|
3216
|
+
setFragmentData(dataTransfer);
|
|
3217
|
+
return;
|
|
3218
|
+
}
|
|
3219
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
3220
|
+
setFragmentData(dataTransfer);
|
|
3221
|
+
return;
|
|
3222
|
+
}
|
|
3223
|
+
dataTransfer.clearData(), editorActor.send({
|
|
3224
|
+
type: "behavior event",
|
|
3225
|
+
behaviorEvent: {
|
|
3226
|
+
type: "serialize",
|
|
3227
|
+
dataTransfer,
|
|
3228
|
+
originEvent: originEvent ?? "unknown"
|
|
3229
|
+
},
|
|
3230
|
+
editor
|
|
3231
|
+
});
|
|
2955
3232
|
}, editor;
|
|
2956
3233
|
};
|
|
2957
3234
|
}
|
|
@@ -3049,13 +3326,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3049
3326
|
}, editor;
|
|
3050
3327
|
};
|
|
3051
3328
|
}
|
|
3052
|
-
const debug$
|
|
3329
|
+
const debug$d = debugWithName("applyPatches"), debugVerbose = debug$d.enabled && !0;
|
|
3053
3330
|
function createApplyPatch(schemaTypes) {
|
|
3054
3331
|
return (editor, patch) => {
|
|
3055
3332
|
let changed = !1;
|
|
3056
|
-
debugVerbose && (debug$
|
|
3333
|
+
debugVerbose && (debug$d(`
|
|
3057
3334
|
|
|
3058
|
-
NEW PATCH =============================================================`), debug$
|
|
3335
|
+
NEW PATCH =============================================================`), debug$d(JSON.stringify(patch, null, 2)));
|
|
3059
3336
|
try {
|
|
3060
3337
|
switch (patch.type) {
|
|
3061
3338
|
case "insert":
|
|
@@ -3071,7 +3348,7 @@ NEW PATCH =============================================================`), debug
|
|
|
3071
3348
|
changed = diffMatchPatch(editor, patch);
|
|
3072
3349
|
break;
|
|
3073
3350
|
default:
|
|
3074
|
-
debug$
|
|
3351
|
+
debug$d("Unhandled patch", patch.type);
|
|
3075
3352
|
}
|
|
3076
3353
|
} catch (err) {
|
|
3077
3354
|
console.error(err);
|
|
@@ -3086,9 +3363,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
3086
3363
|
childPath
|
|
3087
3364
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3088
3365
|
if (!block)
|
|
3089
|
-
return debug$
|
|
3366
|
+
return debug$d("Block not found"), !1;
|
|
3090
3367
|
if (!child || !childPath)
|
|
3091
|
-
return debug$
|
|
3368
|
+
return debug$d("Child not found"), !1;
|
|
3092
3369
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
|
|
3093
3370
|
return !1;
|
|
3094
3371
|
const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
|
|
@@ -3118,9 +3395,9 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3118
3395
|
childPath: targetChildPath
|
|
3119
3396
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3120
3397
|
if (!targetBlock || !targetBlockPath)
|
|
3121
|
-
return debug$
|
|
3398
|
+
return debug$d("Block not found"), !1;
|
|
3122
3399
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
3123
|
-
return debug$
|
|
3400
|
+
return debug$d("Ignoring patch targeting void value"), !1;
|
|
3124
3401
|
if (patch.path.length === 1) {
|
|
3125
3402
|
const {
|
|
3126
3403
|
items: items2,
|
|
@@ -3128,7 +3405,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3128
3405
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
3129
3406
|
schemaTypes
|
|
3130
3407
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
3131
|
-
return debug$
|
|
3408
|
+
return debug$d(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
|
|
3132
3409
|
at: [normalizedIdx2]
|
|
3133
3410
|
}), debugState(editor, "after"), !0;
|
|
3134
3411
|
}
|
|
@@ -3137,14 +3414,14 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3137
3414
|
position
|
|
3138
3415
|
} = patch;
|
|
3139
3416
|
if (!targetChild || !targetChildPath)
|
|
3140
|
-
return debug$
|
|
3417
|
+
return debug$d("Child not found"), !1;
|
|
3141
3418
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3142
3419
|
...targetBlock,
|
|
3143
3420
|
children: items
|
|
3144
3421
|
}], {
|
|
3145
3422
|
schemaTypes
|
|
3146
3423
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3147
|
-
return debug$
|
|
3424
|
+
return debug$d(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
3148
3425
|
at: childInsertPath
|
|
3149
3426
|
}), debugState(editor, "after"), !0;
|
|
3150
3427
|
}
|
|
@@ -3158,14 +3435,14 @@ function setPatch(editor, patch) {
|
|
|
3158
3435
|
childPath
|
|
3159
3436
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3160
3437
|
if (!block)
|
|
3161
|
-
return debug$
|
|
3438
|
+
return debug$d("Block not found"), !1;
|
|
3162
3439
|
const isTextBlock = editor.isTextBlock(block);
|
|
3163
3440
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
3164
|
-
return debug$
|
|
3441
|
+
return debug$d("Ignoring setting void value"), !1;
|
|
3165
3442
|
if (debugState(editor, "before"), isTextBlock && child && childPath) {
|
|
3166
3443
|
if (slate.Text.isText(value) && slate.Text.isText(child)) {
|
|
3167
3444
|
const newText = child.text;
|
|
3168
|
-
value.text !== newText && (debug$
|
|
3445
|
+
value.text !== newText && (debug$d("Setting text property"), editor.apply({
|
|
3169
3446
|
type: "remove_text",
|
|
3170
3447
|
path: childPath,
|
|
3171
3448
|
offset: 0,
|
|
@@ -3177,7 +3454,7 @@ function setPatch(editor, patch) {
|
|
|
3177
3454
|
text: value.text
|
|
3178
3455
|
}), editor.onChange());
|
|
3179
3456
|
} else
|
|
3180
|
-
debug$
|
|
3457
|
+
debug$d("Setting non-text property"), editor.apply({
|
|
3181
3458
|
type: "set_node",
|
|
3182
3459
|
path: childPath,
|
|
3183
3460
|
properties: {},
|
|
@@ -3185,7 +3462,7 @@ function setPatch(editor, patch) {
|
|
|
3185
3462
|
});
|
|
3186
3463
|
return !0;
|
|
3187
3464
|
} else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3188
|
-
debug$
|
|
3465
|
+
debug$d("Setting block property");
|
|
3189
3466
|
const {
|
|
3190
3467
|
children,
|
|
3191
3468
|
...nextRest
|
|
@@ -3202,7 +3479,7 @@ function setPatch(editor, patch) {
|
|
|
3202
3479
|
...prevRest
|
|
3203
3480
|
},
|
|
3204
3481
|
newProperties: nextRest
|
|
3205
|
-
}), debug$
|
|
3482
|
+
}), debug$d("Setting children"), block.children.forEach((c, cIndex) => {
|
|
3206
3483
|
editor.apply({
|
|
3207
3484
|
type: "remove_node",
|
|
3208
3485
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -3228,7 +3505,7 @@ function setPatch(editor, patch) {
|
|
|
3228
3505
|
}
|
|
3229
3506
|
function unsetPatch(editor, patch) {
|
|
3230
3507
|
if (patch.path.length === 0) {
|
|
3231
|
-
debug$
|
|
3508
|
+
debug$d("Removing everything"), debugState(editor, "before");
|
|
3232
3509
|
const previousSelection = editor.selection;
|
|
3233
3510
|
return slate.Transforms.deselect(editor), editor.children.forEach((_child, i) => {
|
|
3234
3511
|
slate.Transforms.removeNodes(editor, {
|
|
@@ -3255,13 +3532,13 @@ function unsetPatch(editor, patch) {
|
|
|
3255
3532
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3256
3533
|
if (patch.path.length === 1) {
|
|
3257
3534
|
if (!block || !blockPath)
|
|
3258
|
-
return debug$
|
|
3535
|
+
return debug$d("Block not found"), !1;
|
|
3259
3536
|
const blockIndex = blockPath[0];
|
|
3260
|
-
return debug$
|
|
3537
|
+
return debug$d(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
|
|
3261
3538
|
at: [blockIndex]
|
|
3262
3539
|
}), debugState(editor, "after"), !0;
|
|
3263
3540
|
}
|
|
3264
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
3541
|
+
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$d("Child not found"), !1) : (debug$d(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$d(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
|
|
3265
3542
|
at: childPath
|
|
3266
3543
|
}), debugState(editor, "after"), !0) : !1;
|
|
3267
3544
|
}
|
|
@@ -3269,7 +3546,7 @@ function isKeyedSegment(segment) {
|
|
|
3269
3546
|
return typeof segment == "object" && "_key" in segment;
|
|
3270
3547
|
}
|
|
3271
3548
|
function debugState(editor, stateName) {
|
|
3272
|
-
debugVerbose && (debug$
|
|
3549
|
+
debugVerbose && (debug$d(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$d(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
3273
3550
|
}
|
|
3274
3551
|
function findBlockFromPath(editor, path) {
|
|
3275
3552
|
let blockIndex = -1;
|
|
@@ -3311,7 +3588,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3311
3588
|
childPath: void 0
|
|
3312
3589
|
};
|
|
3313
3590
|
}
|
|
3314
|
-
const debug$
|
|
3591
|
+
const debug$c = debugWithName("plugin:withPatches");
|
|
3315
3592
|
function createWithPatches({
|
|
3316
3593
|
editorActor,
|
|
3317
3594
|
patchFunctions,
|
|
@@ -3337,7 +3614,7 @@ function createWithPatches({
|
|
|
3337
3614
|
withoutPatching(editor, () => {
|
|
3338
3615
|
withoutSaving(editor, () => {
|
|
3339
3616
|
patches2.forEach((patch) => {
|
|
3340
|
-
debug$
|
|
3617
|
+
debug$c.enabled && debug$c(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
3341
3618
|
});
|
|
3342
3619
|
});
|
|
3343
3620
|
});
|
|
@@ -3350,10 +3627,10 @@ function createWithPatches({
|
|
|
3350
3627
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
3351
3628
|
};
|
|
3352
3629
|
return subscriptions.push(() => {
|
|
3353
|
-
debug$
|
|
3630
|
+
debug$c("Subscribing to remote patches");
|
|
3354
3631
|
const sub = editorActor.on("patches", handlePatches);
|
|
3355
3632
|
return () => {
|
|
3356
|
-
debug$
|
|
3633
|
+
debug$c("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
3357
3634
|
};
|
|
3358
3635
|
}), editor.apply = (operation) => {
|
|
3359
3636
|
let patches$1 = [];
|
|
@@ -3404,7 +3681,7 @@ function createWithPatches({
|
|
|
3404
3681
|
}, editor;
|
|
3405
3682
|
};
|
|
3406
3683
|
}
|
|
3407
|
-
const debug$
|
|
3684
|
+
const debug$b = debugWithName("plugin:withPlaceholderBlock");
|
|
3408
3685
|
function createWithPlaceholderBlock(editorActor) {
|
|
3409
3686
|
return function(editor) {
|
|
3410
3687
|
const {
|
|
@@ -3429,7 +3706,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3429
3706
|
const node = op.node;
|
|
3430
3707
|
if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
|
|
3431
3708
|
const nextPath = slate.Path.next(op.path);
|
|
3432
|
-
editor.children[nextPath[0]] || (debug$
|
|
3709
|
+
editor.children[nextPath[0]] || (debug$b("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
3433
3710
|
decorators: []
|
|
3434
3711
|
})));
|
|
3435
3712
|
}
|
|
@@ -3438,7 +3715,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3438
3715
|
}, editor;
|
|
3439
3716
|
};
|
|
3440
3717
|
}
|
|
3441
|
-
const debug$
|
|
3718
|
+
const debug$a = debugWithName("plugin:withPortableTextBlockStyle");
|
|
3442
3719
|
function createWithPortableTextBlockStyle(editorActor, types2) {
|
|
3443
3720
|
const defaultStyle = types2.styles[0].value;
|
|
3444
3721
|
return function(editor) {
|
|
@@ -3451,7 +3728,7 @@ function createWithPortableTextBlockStyle(editorActor, types2) {
|
|
|
3451
3728
|
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)) {
|
|
3452
3729
|
const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
|
|
3453
3730
|
if (slate.Text.isText(child) && child.text === "") {
|
|
3454
|
-
debug$
|
|
3731
|
+
debug$a(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
3455
3732
|
type: "normalizing"
|
|
3456
3733
|
}), slate.Transforms.setNodes(editor, {
|
|
3457
3734
|
style: defaultStyle
|
|
@@ -3511,7 +3788,7 @@ function getNextSpan({
|
|
|
3511
3788
|
}
|
|
3512
3789
|
return nextSpan;
|
|
3513
3790
|
}
|
|
3514
|
-
const debug$
|
|
3791
|
+
const debug$9 = debugWithName("plugin:withPortableTextMarkModel");
|
|
3515
3792
|
function createWithPortableTextMarkModel(editorActor, types2) {
|
|
3516
3793
|
return function(editor) {
|
|
3517
3794
|
const {
|
|
@@ -3525,7 +3802,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3525
3802
|
for (const [child, childPath] of children) {
|
|
3526
3803
|
const nextNode = node.children[childPath[1] + 1];
|
|
3527
3804
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3528
|
-
debug$
|
|
3805
|
+
debug$9("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3529
3806
|
type: "normalizing"
|
|
3530
3807
|
}), slate.Transforms.mergeNodes(editor, {
|
|
3531
3808
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -3538,7 +3815,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3538
3815
|
}
|
|
3539
3816
|
}
|
|
3540
3817
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3541
|
-
debug$
|
|
3818
|
+
debug$9("Adding .markDefs to block node"), editorActor.send({
|
|
3542
3819
|
type: "normalizing"
|
|
3543
3820
|
}), slate.Transforms.setNodes(editor, {
|
|
3544
3821
|
markDefs: []
|
|
@@ -3550,7 +3827,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3550
3827
|
return;
|
|
3551
3828
|
}
|
|
3552
3829
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3553
|
-
debug$
|
|
3830
|
+
debug$9("Adding .marks to span node"), editorActor.send({
|
|
3554
3831
|
type: "normalizing"
|
|
3555
3832
|
}), slate.Transforms.setNodes(editor, {
|
|
3556
3833
|
marks: []
|
|
@@ -3564,7 +3841,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3564
3841
|
if (editor.isTextSpan(node)) {
|
|
3565
3842
|
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3566
3843
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3567
|
-
debug$
|
|
3844
|
+
debug$9("Removing annotations from empty span node"), editorActor.send({
|
|
3568
3845
|
type: "normalizing"
|
|
3569
3846
|
}), slate.Transforms.setNodes(editor, {
|
|
3570
3847
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -3582,7 +3859,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3582
3859
|
if (editor.isTextSpan(child)) {
|
|
3583
3860
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3584
3861
|
if (orphanedAnnotations.length > 0) {
|
|
3585
|
-
debug$
|
|
3862
|
+
debug$9("Removing orphaned annotations from span node"), editorActor.send({
|
|
3586
3863
|
type: "normalizing"
|
|
3587
3864
|
}), slate.Transforms.setNodes(editor, {
|
|
3588
3865
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3600,7 +3877,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3600
3877
|
if (editor.isTextBlock(block)) {
|
|
3601
3878
|
const decorators2 = types2.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3602
3879
|
if (orphanedAnnotations.length > 0) {
|
|
3603
|
-
debug$
|
|
3880
|
+
debug$9("Removing orphaned annotations from span node"), editorActor.send({
|
|
3604
3881
|
type: "normalizing"
|
|
3605
3882
|
}), slate.Transforms.setNodes(editor, {
|
|
3606
3883
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3618,7 +3895,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3618
3895
|
for (const markDef of markDefs)
|
|
3619
3896
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3620
3897
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3621
|
-
debug$
|
|
3898
|
+
debug$9("Removing duplicate markDefs"), editorActor.send({
|
|
3622
3899
|
type: "normalizing"
|
|
3623
3900
|
}), slate.Transforms.setNodes(editor, {
|
|
3624
3901
|
markDefs: newMarkDefs
|
|
@@ -3633,7 +3910,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3633
3910
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3634
3911
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3635
3912
|
if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
|
|
3636
|
-
debug$
|
|
3913
|
+
debug$9("Removing markDef not in use"), editorActor.send({
|
|
3637
3914
|
type: "normalizing"
|
|
3638
3915
|
}), slate.Transforms.setNodes(editor, {
|
|
3639
3916
|
markDefs: newMarkDefs
|
|
@@ -3850,7 +4127,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3850
4127
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
3851
4128
|
if (editor.isTextBlock(targetBlock)) {
|
|
3852
4129
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
3853
|
-
debug$
|
|
4130
|
+
debug$9("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
|
|
3854
4131
|
markDefs: newMarkDefs
|
|
3855
4132
|
}, {
|
|
3856
4133
|
at: targetPath,
|
|
@@ -4050,7 +4327,7 @@ function createWithPortableTextSelections(editorActor, types2) {
|
|
|
4050
4327
|
}, editor;
|
|
4051
4328
|
};
|
|
4052
4329
|
}
|
|
4053
|
-
const debug$
|
|
4330
|
+
const debug$8 = debugWithName("plugin:withSchemaTypes");
|
|
4054
4331
|
function createWithSchemaTypes({
|
|
4055
4332
|
editorActor,
|
|
4056
4333
|
schemaTypes
|
|
@@ -4063,7 +4340,7 @@ function createWithSchemaTypes({
|
|
|
4063
4340
|
return editor.normalizeNode = (entry) => {
|
|
4064
4341
|
const [node, path] = entry;
|
|
4065
4342
|
if (node._type === void 0 && path.length === 2) {
|
|
4066
|
-
debug$
|
|
4343
|
+
debug$8("Setting span type on text node without a type");
|
|
4067
4344
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4068
4345
|
editorActor.send({
|
|
4069
4346
|
type: "normalizing"
|
|
@@ -4079,7 +4356,7 @@ function createWithSchemaTypes({
|
|
|
4079
4356
|
return;
|
|
4080
4357
|
}
|
|
4081
4358
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
4082
|
-
debug$
|
|
4359
|
+
debug$8("Setting missing key on child node without a key");
|
|
4083
4360
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
4084
4361
|
editorActor.send({
|
|
4085
4362
|
type: "normalizing"
|
|
@@ -4096,7 +4373,7 @@ function createWithSchemaTypes({
|
|
|
4096
4373
|
}, editor;
|
|
4097
4374
|
};
|
|
4098
4375
|
}
|
|
4099
|
-
const debug$
|
|
4376
|
+
const debug$7 = debugWithName("plugin:withUtils");
|
|
4100
4377
|
function createWithUtils({
|
|
4101
4378
|
editorActor,
|
|
4102
4379
|
schemaTypes
|
|
@@ -4111,14 +4388,14 @@ function createWithUtils({
|
|
|
4111
4388
|
depth: 2
|
|
4112
4389
|
});
|
|
4113
4390
|
if (!textNode || !slate.Text.isText(textNode) || textNode.text.length === 0) {
|
|
4114
|
-
debug$
|
|
4391
|
+
debug$7("pteExpandToWord: Can't expand to word here");
|
|
4115
4392
|
return;
|
|
4116
4393
|
}
|
|
4117
4394
|
const {
|
|
4118
4395
|
focus
|
|
4119
4396
|
} = 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);
|
|
4120
4397
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4121
|
-
debug$
|
|
4398
|
+
debug$7("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
|
|
4122
4399
|
anchor: {
|
|
4123
4400
|
...selection.anchor,
|
|
4124
4401
|
offset: newStartOffset
|
|
@@ -4130,7 +4407,7 @@ function createWithUtils({
|
|
|
4130
4407
|
});
|
|
4131
4408
|
return;
|
|
4132
4409
|
}
|
|
4133
|
-
debug$
|
|
4410
|
+
debug$7("pteExpandToWord: Can't expand to word here");
|
|
4134
4411
|
}
|
|
4135
4412
|
}, editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
4136
4413
|
_type: schemaTypes.block.name,
|
|
@@ -4176,12 +4453,12 @@ const withPlugins = (editor, options) => {
|
|
|
4176
4453
|
schemaTypes
|
|
4177
4454
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
|
|
4178
4455
|
return createWithEventListeners(editorActor, options.subscriptions)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
4179
|
-
}, debug$
|
|
4456
|
+
}, debug$6 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
4180
4457
|
function createSlateEditor(config) {
|
|
4181
4458
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
4182
4459
|
if (existingSlateEditor)
|
|
4183
|
-
return debug$
|
|
4184
|
-
debug$
|
|
4460
|
+
return debug$6("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
|
|
4461
|
+
debug$6("Creating new Slate editor instance", config.editorActor.id);
|
|
4185
4462
|
const unsubscriptions = [], subscriptions = [], instance = withPlugins(slateReact.withReact(slate.createEditor()), {
|
|
4186
4463
|
editorActor: config.editorActor,
|
|
4187
4464
|
subscriptions
|
|
@@ -4326,7 +4603,7 @@ function isStyleActive({
|
|
|
4326
4603
|
})];
|
|
4327
4604
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
4328
4605
|
}
|
|
4329
|
-
const debug$
|
|
4606
|
+
const debug$5 = debugWithName("API:editable");
|
|
4330
4607
|
function createEditableAPI(editor, editorActor) {
|
|
4331
4608
|
const types2 = editorActor.getSnapshot().context.schema;
|
|
4332
4609
|
return {
|
|
@@ -4445,7 +4722,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4445
4722
|
}], {
|
|
4446
4723
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
4447
4724
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
4448
|
-
return isSpanNode && focusNode._type !== types2.span.name && (debug$
|
|
4725
|
+
return isSpanNode && focusNode._type !== types2.span.name && (debug$5("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
4449
4726
|
distance: 1,
|
|
4450
4727
|
unit: "character"
|
|
4451
4728
|
})), slate.Transforms.insertNodes(editor, child, {
|
|
@@ -4583,18 +4860,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4583
4860
|
throw new Error("Invalid range");
|
|
4584
4861
|
if (range) {
|
|
4585
4862
|
if (!options?.mode || options?.mode === "selected") {
|
|
4586
|
-
debug$
|
|
4863
|
+
debug$5("Deleting content in selection"), slate.Transforms.delete(editor, {
|
|
4587
4864
|
at: range,
|
|
4588
4865
|
hanging: !0,
|
|
4589
4866
|
voids: !0
|
|
4590
4867
|
}), editor.onChange();
|
|
4591
4868
|
return;
|
|
4592
4869
|
}
|
|
4593
|
-
options?.mode === "blocks" && (debug$
|
|
4870
|
+
options?.mode === "blocks" && (debug$5("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
4594
4871
|
at: range,
|
|
4595
4872
|
voids: !0,
|
|
4596
4873
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
4597
|
-
})), options?.mode === "children" && (debug$
|
|
4874
|
+
})), options?.mode === "children" && (debug$5("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
4598
4875
|
at: range,
|
|
4599
4876
|
voids: !0,
|
|
4600
4877
|
match: (node) => node._type === types2.span.name || // Text children
|
|
@@ -4728,7 +5005,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4728
5005
|
action
|
|
4729
5006
|
}) => {
|
|
4730
5007
|
const editor = action.editor;
|
|
4731
|
-
if (debug$
|
|
5008
|
+
if (debug$5("Removing annotation", action.annotation.name), !!editor.selection)
|
|
4732
5009
|
if (slate.Range.isCollapsed(editor.selection)) {
|
|
4733
5010
|
const [block, blockPath] = slate.Editor.node(editor, editor.selection, {
|
|
4734
5011
|
depth: 1
|
|
@@ -4859,7 +5136,11 @@ function insertBlock({
|
|
|
4859
5136
|
});
|
|
4860
5137
|
}
|
|
4861
5138
|
}
|
|
4862
|
-
const
|
|
5139
|
+
const dataTransferSetActionImplementation = ({
|
|
5140
|
+
action
|
|
5141
|
+
}) => {
|
|
5142
|
+
action.dataTransfer.setData(action.mimeType, action.data);
|
|
5143
|
+
}, insertBlockObjectActionImplementation = ({
|
|
4863
5144
|
context,
|
|
4864
5145
|
action
|
|
4865
5146
|
}) => {
|
|
@@ -4876,6 +5157,35 @@ const insertBlockObjectActionImplementation = ({
|
|
|
4876
5157
|
editor: action.editor,
|
|
4877
5158
|
schema: context.schema
|
|
4878
5159
|
});
|
|
5160
|
+
}, insertBlocksActionImplementation = ({
|
|
5161
|
+
context,
|
|
5162
|
+
action
|
|
5163
|
+
}) => {
|
|
5164
|
+
const fragment = toSlateValue(action.blocks, {
|
|
5165
|
+
schemaTypes: context.schema
|
|
5166
|
+
});
|
|
5167
|
+
if (!action.editor.selection)
|
|
5168
|
+
return;
|
|
5169
|
+
const [focusBlock, focusPath] = slate.Editor.node(action.editor, action.editor.selection, {
|
|
5170
|
+
depth: 1
|
|
5171
|
+
});
|
|
5172
|
+
if (action.editor.isTextBlock(focusBlock) && action.editor.isTextBlock(fragment[0])) {
|
|
5173
|
+
const {
|
|
5174
|
+
markDefs
|
|
5175
|
+
} = focusBlock;
|
|
5176
|
+
isEqual__default.default(markDefs, fragment[0].markDefs) || slate.Transforms.setNodes(action.editor, {
|
|
5177
|
+
markDefs: uniq__default.default([...fragment[0].markDefs || [], ...markDefs || []])
|
|
5178
|
+
}, {
|
|
5179
|
+
at: focusPath,
|
|
5180
|
+
mode: "lowest",
|
|
5181
|
+
voids: !1
|
|
5182
|
+
});
|
|
5183
|
+
}
|
|
5184
|
+
isEqualToEmptyEditor(action.editor.children, context.schema) ? (slate.Transforms.splitNodes(action.editor, {
|
|
5185
|
+
at: [0, 0]
|
|
5186
|
+
}), action.editor.insertFragment(fragment), slate.Transforms.removeNodes(action.editor, {
|
|
5187
|
+
at: [0]
|
|
5188
|
+
})) : action.editor.insertFragment(fragment);
|
|
4879
5189
|
}, insertBreakActionImplementation = ({
|
|
4880
5190
|
context,
|
|
4881
5191
|
action
|
|
@@ -5104,6 +5414,7 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5104
5414
|
}) => {
|
|
5105
5415
|
slateReact.ReactEditor.blur(action.editor);
|
|
5106
5416
|
},
|
|
5417
|
+
"data transfer.set": dataTransferSetActionImplementation,
|
|
5107
5418
|
"decorator.add": addDecoratorActionImplementation,
|
|
5108
5419
|
"decorator.remove": removeDecoratorActionImplementation,
|
|
5109
5420
|
"decorator.toggle": toggleDecoratorActionImplementation,
|
|
@@ -5170,6 +5481,25 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5170
5481
|
at: range
|
|
5171
5482
|
});
|
|
5172
5483
|
},
|
|
5484
|
+
"deserialization.failure": ({
|
|
5485
|
+
action
|
|
5486
|
+
}) => {
|
|
5487
|
+
console.error(`Deserialization of ${action.mimeType} failed with reason ${action.reason}`);
|
|
5488
|
+
},
|
|
5489
|
+
"deserialization.success": ({
|
|
5490
|
+
context,
|
|
5491
|
+
action
|
|
5492
|
+
}) => {
|
|
5493
|
+
insertBlocksActionImplementation({
|
|
5494
|
+
context,
|
|
5495
|
+
action: {
|
|
5496
|
+
type: "insert.blocks",
|
|
5497
|
+
blocks: action.data,
|
|
5498
|
+
editor: action.editor
|
|
5499
|
+
}
|
|
5500
|
+
});
|
|
5501
|
+
},
|
|
5502
|
+
"insert.blocks": insertBlocksActionImplementation,
|
|
5173
5503
|
"insert.block object": insertBlockObjectActionImplementation,
|
|
5174
5504
|
"insert.break": insertBreakActionImplementation,
|
|
5175
5505
|
"insert.inline object": insertInlineObjectActionImplementation,
|
|
@@ -5281,6 +5611,23 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5281
5611
|
const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
|
|
5282
5612
|
slate.Transforms.select(action.editor, nextBlockPath);
|
|
5283
5613
|
},
|
|
5614
|
+
"serialization.failure": ({
|
|
5615
|
+
action
|
|
5616
|
+
}) => {
|
|
5617
|
+
console.error(`Serialization of ${action.mimeType} failed with reason ${action.reason}`);
|
|
5618
|
+
},
|
|
5619
|
+
"serialization.success": ({
|
|
5620
|
+
context,
|
|
5621
|
+
action
|
|
5622
|
+
}) => {
|
|
5623
|
+
dataTransferSetActionImplementation({
|
|
5624
|
+
context,
|
|
5625
|
+
action: {
|
|
5626
|
+
...action,
|
|
5627
|
+
type: "data transfer.set"
|
|
5628
|
+
}
|
|
5629
|
+
});
|
|
5630
|
+
},
|
|
5284
5631
|
"style.toggle": toggleStyleActionImplementation,
|
|
5285
5632
|
"style.add": addStyleActionImplementation,
|
|
5286
5633
|
"style.remove": removeStyleActionImplementation,
|
|
@@ -5467,6 +5814,13 @@ function performDefaultAction({
|
|
|
5467
5814
|
});
|
|
5468
5815
|
break;
|
|
5469
5816
|
}
|
|
5817
|
+
case "data transfer.set": {
|
|
5818
|
+
behaviorActionImplementations["data transfer.set"]({
|
|
5819
|
+
context,
|
|
5820
|
+
action
|
|
5821
|
+
});
|
|
5822
|
+
break;
|
|
5823
|
+
}
|
|
5470
5824
|
case "decorator.toggle": {
|
|
5471
5825
|
behaviorActionImplementations["decorator.toggle"]({
|
|
5472
5826
|
context,
|
|
@@ -5488,6 +5842,20 @@ function performDefaultAction({
|
|
|
5488
5842
|
});
|
|
5489
5843
|
break;
|
|
5490
5844
|
}
|
|
5845
|
+
case "deserialization.failure": {
|
|
5846
|
+
behaviorActionImplementations["deserialization.failure"]({
|
|
5847
|
+
context,
|
|
5848
|
+
action
|
|
5849
|
+
});
|
|
5850
|
+
break;
|
|
5851
|
+
}
|
|
5852
|
+
case "deserialization.success": {
|
|
5853
|
+
behaviorActionImplementations["deserialization.success"]({
|
|
5854
|
+
context,
|
|
5855
|
+
action
|
|
5856
|
+
});
|
|
5857
|
+
break;
|
|
5858
|
+
}
|
|
5491
5859
|
case "focus": {
|
|
5492
5860
|
behaviorActionImplementations.focus({
|
|
5493
5861
|
context,
|
|
@@ -5495,6 +5863,13 @@ function performDefaultAction({
|
|
|
5495
5863
|
});
|
|
5496
5864
|
break;
|
|
5497
5865
|
}
|
|
5866
|
+
case "insert.blocks": {
|
|
5867
|
+
behaviorActionImplementations["insert.blocks"]({
|
|
5868
|
+
context,
|
|
5869
|
+
action
|
|
5870
|
+
});
|
|
5871
|
+
break;
|
|
5872
|
+
}
|
|
5498
5873
|
case "insert.block object": {
|
|
5499
5874
|
behaviorActionImplementations["insert.block object"]({
|
|
5500
5875
|
context,
|
|
@@ -5544,6 +5919,20 @@ function performDefaultAction({
|
|
|
5544
5919
|
});
|
|
5545
5920
|
break;
|
|
5546
5921
|
}
|
|
5922
|
+
case "serialization.failure": {
|
|
5923
|
+
behaviorActionImplementations["serialization.failure"]({
|
|
5924
|
+
context,
|
|
5925
|
+
action
|
|
5926
|
+
});
|
|
5927
|
+
break;
|
|
5928
|
+
}
|
|
5929
|
+
case "serialization.success": {
|
|
5930
|
+
behaviorActionImplementations["serialization.success"]({
|
|
5931
|
+
context,
|
|
5932
|
+
action
|
|
5933
|
+
});
|
|
5934
|
+
break;
|
|
5935
|
+
}
|
|
5547
5936
|
default:
|
|
5548
5937
|
behaviorActionImplementations["style.toggle"]({
|
|
5549
5938
|
context,
|
|
@@ -5561,6 +5950,7 @@ function getActiveDecorators({
|
|
|
5561
5950
|
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
5562
5951
|
}
|
|
5563
5952
|
function createEditorSnapshot({
|
|
5953
|
+
converters,
|
|
5564
5954
|
editor,
|
|
5565
5955
|
keyGenerator,
|
|
5566
5956
|
schema: schema2
|
|
@@ -5572,6 +5962,7 @@ function createEditorSnapshot({
|
|
|
5572
5962
|
schema: schema2,
|
|
5573
5963
|
slateEditorInstance: editor
|
|
5574
5964
|
}),
|
|
5965
|
+
converters,
|
|
5575
5966
|
keyGenerator,
|
|
5576
5967
|
schema: schema2,
|
|
5577
5968
|
selection,
|
|
@@ -5646,7 +6037,7 @@ const editorMachine = xstate.setup({
|
|
|
5646
6037
|
enqueue
|
|
5647
6038
|
}) => {
|
|
5648
6039
|
xstate.assertEvent(event, ["behavior event", "custom behavior event"]);
|
|
5649
|
-
const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
|
|
6040
|
+
const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
|
|
5650
6041
|
...event.behaviorEvent,
|
|
5651
6042
|
editor: event.editor
|
|
5652
6043
|
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values()].filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
@@ -5680,6 +6071,7 @@ const editorMachine = xstate.setup({
|
|
|
5680
6071
|
return;
|
|
5681
6072
|
}
|
|
5682
6073
|
const editorSnapshot = createEditorSnapshot({
|
|
6074
|
+
converters: [...context.converters],
|
|
5683
6075
|
editor: event.editor,
|
|
5684
6076
|
keyGenerator: context.keyGenerator,
|
|
5685
6077
|
schema: context.schema
|
|
@@ -5769,6 +6161,7 @@ const editorMachine = xstate.setup({
|
|
|
5769
6161
|
input
|
|
5770
6162
|
}) => ({
|
|
5771
6163
|
behaviors: new Set(input.behaviors ?? behavior_core.coreBehaviors),
|
|
6164
|
+
converters: new Set(input.converters ?? []),
|
|
5772
6165
|
keyGenerator: input.keyGenerator,
|
|
5773
6166
|
pendingEvents: [],
|
|
5774
6167
|
schema: input.schema,
|
|
@@ -5841,6 +6234,13 @@ const editorMachine = xstate.setup({
|
|
|
5841
6234
|
"update behaviors": {
|
|
5842
6235
|
actions: "assign behaviors"
|
|
5843
6236
|
},
|
|
6237
|
+
"update key generator": {
|
|
6238
|
+
actions: xstate.assign({
|
|
6239
|
+
keyGenerator: ({
|
|
6240
|
+
event
|
|
6241
|
+
}) => event.keyGenerator
|
|
6242
|
+
})
|
|
6243
|
+
},
|
|
5844
6244
|
"update schema": {
|
|
5845
6245
|
actions: "assign schema"
|
|
5846
6246
|
},
|
|
@@ -5881,6 +6281,12 @@ const editorMachine = xstate.setup({
|
|
|
5881
6281
|
},
|
|
5882
6282
|
"read only": {
|
|
5883
6283
|
on: {
|
|
6284
|
+
"behavior event": {
|
|
6285
|
+
actions: "handle behavior event",
|
|
6286
|
+
guard: ({
|
|
6287
|
+
event
|
|
6288
|
+
}) => event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "data transfer.set" || event.behaviorEvent.type === "serialize" || event.behaviorEvent.type === "serialization.failure" || event.behaviorEvent.type === "serialization.success" || event.behaviorEvent.type === "select"
|
|
6289
|
+
},
|
|
5884
6290
|
"update readOnly": {
|
|
5885
6291
|
guard: ({
|
|
5886
6292
|
event
|
|
@@ -6050,6 +6456,7 @@ function getEditorSnapshot({
|
|
|
6050
6456
|
}) {
|
|
6051
6457
|
return {
|
|
6052
6458
|
context: {
|
|
6459
|
+
converters: [...editorActorSnapshot.context.converters],
|
|
6053
6460
|
activeDecorators: getActiveDecorators({
|
|
6054
6461
|
schema: editorActorSnapshot.context.schema,
|
|
6055
6462
|
slateEditorInstance
|
|
@@ -6104,6 +6511,7 @@ function useCreateEditor(config) {
|
|
|
6104
6511
|
function editorConfigToMachineInput(config) {
|
|
6105
6512
|
return {
|
|
6106
6513
|
behaviors: config.behaviors,
|
|
6514
|
+
converters: coreConverters,
|
|
6107
6515
|
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
6108
6516
|
maxBlocks: config.maxBlocks,
|
|
6109
6517
|
readOnly: config.readOnly,
|
|
@@ -6149,25 +6557,25 @@ const EditorActorContext = React.createContext({}), PortableTextEditorSelectionC
|
|
|
6149
6557
|
if (selection === void 0)
|
|
6150
6558
|
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
6151
6559
|
return selection;
|
|
6152
|
-
}, debug$
|
|
6560
|
+
}, debug$4 = debugWithName("component:PortableTextEditor:SelectionProvider");
|
|
6153
6561
|
function PortableTextEditorSelectionProvider(props) {
|
|
6154
6562
|
const $ = reactCompilerRuntime.c(6), [selection, setSelection] = React.useState(null);
|
|
6155
6563
|
let t0, t1;
|
|
6156
6564
|
$[0] !== props.editorActor ? (t0 = () => {
|
|
6157
|
-
debug$
|
|
6565
|
+
debug$4("Subscribing to selection changes");
|
|
6158
6566
|
const subscription = props.editorActor.on("selection", (event) => {
|
|
6159
6567
|
React.startTransition(() => {
|
|
6160
6568
|
setSelection(event.selection);
|
|
6161
6569
|
});
|
|
6162
6570
|
});
|
|
6163
6571
|
return () => {
|
|
6164
|
-
debug$
|
|
6572
|
+
debug$4("Unsubscribing to selection changes"), subscription.unsubscribe();
|
|
6165
6573
|
};
|
|
6166
6574
|
}, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), React.useEffect(t0, t1);
|
|
6167
6575
|
let t2;
|
|
6168
6576
|
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
6169
6577
|
}
|
|
6170
|
-
const debug$
|
|
6578
|
+
const debug$3 = debugWithName("component:PortableTextEditor");
|
|
6171
6579
|
class PortableTextEditor extends React.Component {
|
|
6172
6580
|
static displayName = "PortableTextEditor";
|
|
6173
6581
|
/**
|
|
@@ -6229,13 +6637,13 @@ class PortableTextEditor extends React.Component {
|
|
|
6229
6637
|
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
6230
6638
|
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
6231
6639
|
static blur = (editor) => {
|
|
6232
|
-
debug$
|
|
6640
|
+
debug$3("Host blurred"), editor.editable?.blur();
|
|
6233
6641
|
};
|
|
6234
6642
|
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
6235
6643
|
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
6236
6644
|
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
6237
6645
|
static focus = (editor) => {
|
|
6238
|
-
debug$
|
|
6646
|
+
debug$3("Host requesting focus"), editor.editable?.focus();
|
|
6239
6647
|
};
|
|
6240
6648
|
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
6241
6649
|
static focusChild = (editor) => editor.editable?.focusChild();
|
|
@@ -6246,7 +6654,7 @@ class PortableTextEditor extends React.Component {
|
|
|
6246
6654
|
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
6247
6655
|
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
6248
6656
|
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
6249
|
-
static insertChild = (editor, type, value) => (debug$
|
|
6657
|
+
static insertChild = (editor, type, value) => (debug$3("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
6250
6658
|
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
6251
6659
|
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
6252
6660
|
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
@@ -6257,20 +6665,20 @@ class PortableTextEditor extends React.Component {
|
|
|
6257
6665
|
};
|
|
6258
6666
|
static marks = (editor) => editor.editable?.marks();
|
|
6259
6667
|
static select = (editor, selection) => {
|
|
6260
|
-
debug$
|
|
6668
|
+
debug$3("Host setting selection", selection), editor.editable?.select(selection);
|
|
6261
6669
|
};
|
|
6262
6670
|
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
6263
|
-
static toggleBlockStyle = (editor, blockStyle) => (debug$
|
|
6671
|
+
static toggleBlockStyle = (editor, blockStyle) => (debug$3("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
6264
6672
|
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
6265
6673
|
static toggleMark = (editor, mark) => {
|
|
6266
|
-
debug$
|
|
6674
|
+
debug$3("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
6267
6675
|
};
|
|
6268
|
-
static getFragment = (editor) => (debug$
|
|
6676
|
+
static getFragment = (editor) => (debug$3("Host getting fragment"), editor.editable?.getFragment());
|
|
6269
6677
|
static undo = (editor) => {
|
|
6270
|
-
debug$
|
|
6678
|
+
debug$3("Host undoing"), editor.editable?.undo();
|
|
6271
6679
|
};
|
|
6272
6680
|
static redo = (editor) => {
|
|
6273
|
-
debug$
|
|
6681
|
+
debug$3("Host redoing"), editor.editable?.redo();
|
|
6274
6682
|
};
|
|
6275
6683
|
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
6276
6684
|
}
|
|
@@ -6296,7 +6704,7 @@ function RouteEventsToChanges(props) {
|
|
|
6296
6704
|
const handleChange = useEffectEvent.useEffectEvent(t0);
|
|
6297
6705
|
let t1, t2;
|
|
6298
6706
|
return $[2] !== handleChange || $[3] !== props.editorActor ? (t1 = () => {
|
|
6299
|
-
debug$
|
|
6707
|
+
debug$3("Subscribing to editor changes");
|
|
6300
6708
|
const sub = props.editorActor.on("*", (event) => {
|
|
6301
6709
|
bb5: switch (event.type) {
|
|
6302
6710
|
case "blurred": {
|
|
@@ -6370,11 +6778,11 @@ function RouteEventsToChanges(props) {
|
|
|
6370
6778
|
}
|
|
6371
6779
|
});
|
|
6372
6780
|
return () => {
|
|
6373
|
-
debug$
|
|
6781
|
+
debug$3("Unsubscribing to changes"), sub.unsubscribe();
|
|
6374
6782
|
};
|
|
6375
6783
|
}, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), React.useEffect(t1, t2), null;
|
|
6376
6784
|
}
|
|
6377
|
-
const debug$
|
|
6785
|
+
const debug$2 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
6378
6786
|
const {
|
|
6379
6787
|
editorActor,
|
|
6380
6788
|
attributes,
|
|
@@ -6402,7 +6810,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6402
6810
|
const setSelectedFromRange = React.useCallback(() => {
|
|
6403
6811
|
if (!shouldTrackSelectionAndFocus)
|
|
6404
6812
|
return;
|
|
6405
|
-
debug$
|
|
6813
|
+
debug$2("Setting selection and focus from range");
|
|
6406
6814
|
const winSelection = window.getSelection();
|
|
6407
6815
|
if (!winSelection) {
|
|
6408
6816
|
setSelected(!1);
|
|
@@ -6498,7 +6906,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6498
6906
|
return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6499
6907
|
};
|
|
6500
6908
|
Leaf.displayName = "Leaf";
|
|
6501
|
-
const debug$
|
|
6909
|
+
const debug$1 = debugWithName("plugin:withHotKeys");
|
|
6502
6910
|
function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
|
|
6503
6911
|
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
|
|
6504
6912
|
return function(editor) {
|
|
@@ -6513,7 +6921,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
6513
6921
|
const possibleMark = activeHotkeys[cat];
|
|
6514
6922
|
if (possibleMark) {
|
|
6515
6923
|
const mark = possibleMark[hotkey];
|
|
6516
|
-
debug$
|
|
6924
|
+
debug$1(`HotKey ${hotkey} to toggle ${mark}`), editorActor.send({
|
|
6517
6925
|
type: "behavior event",
|
|
6518
6926
|
behaviorEvent: {
|
|
6519
6927
|
type: "decorator.toggle",
|
|
@@ -6540,204 +6948,6 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
6540
6948
|
}, editor;
|
|
6541
6949
|
};
|
|
6542
6950
|
}
|
|
6543
|
-
const debug$1 = debugWithName("plugin:withInsertData");
|
|
6544
|
-
function createWithInsertData(editorActor, schemaTypes) {
|
|
6545
|
-
return function(editor) {
|
|
6546
|
-
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => editor.isTextBlock(block) ? block.children.map((child) => child._type === spanTypeName ? child.text : `[${schemaTypes.inlineObjects.find((t) => t.name === child._type)?.title || "Object"}]`).join("") : `[${schemaTypes.blockObjects.find((t) => t.name === block._type)?.title || "Object"}]`).join(`
|
|
6547
|
-
|
|
6548
|
-
`);
|
|
6549
|
-
return editor.setFragmentData = (data, originEvent) => {
|
|
6550
|
-
const {
|
|
6551
|
-
selection
|
|
6552
|
-
} = editor;
|
|
6553
|
-
if (!selection)
|
|
6554
|
-
return;
|
|
6555
|
-
const [start, end] = slate.Range.edges(selection), startVoid = slate.Editor.void(editor, {
|
|
6556
|
-
at: start.path
|
|
6557
|
-
}), endVoid = slate.Editor.void(editor, {
|
|
6558
|
-
at: end.path
|
|
6559
|
-
});
|
|
6560
|
-
if (slate.Range.isCollapsed(selection) && !startVoid)
|
|
6561
|
-
return;
|
|
6562
|
-
const domRange = slateReact.ReactEditor.toDOMRange(editor, selection);
|
|
6563
|
-
let contents = domRange.cloneContents();
|
|
6564
|
-
if (endVoid) {
|
|
6565
|
-
const [voidNode] = endVoid, r = domRange.cloneRange(), domNode = slateReact.ReactEditor.toDOMNode(editor, voidNode);
|
|
6566
|
-
r.setEndAfter(domNode), contents = r.cloneContents();
|
|
6567
|
-
}
|
|
6568
|
-
Array.from(contents.querySelectorAll("[data-slate-zero-width]")).forEach((zw) => {
|
|
6569
|
-
const isNewline = zw.getAttribute("data-slate-zero-width") === "n";
|
|
6570
|
-
zw.textContent = isNewline ? `
|
|
6571
|
-
` : "";
|
|
6572
|
-
}), Array.from(contents.querySelectorAll("*")).forEach((elm) => {
|
|
6573
|
-
elm.removeAttribute("contentEditable"), elm.removeAttribute("data-slate-inline"), elm.removeAttribute("data-slate-leaf"), elm.removeAttribute("data-slate-node"), elm.removeAttribute("data-slate-spacer"), elm.removeAttribute("data-slate-string"), elm.removeAttribute("data-slate-zero-width"), elm.removeAttribute("draggable");
|
|
6574
|
-
for (const key in elm.attributes)
|
|
6575
|
-
elm.hasAttribute(key) && elm.removeAttribute(key);
|
|
6576
|
-
});
|
|
6577
|
-
const div = contents.ownerDocument.createElement("div");
|
|
6578
|
-
div.appendChild(contents), div.setAttribute("hidden", "true"), contents.ownerDocument.body.appendChild(div);
|
|
6579
|
-
const asHTML = div.innerHTML;
|
|
6580
|
-
contents.ownerDocument.body.removeChild(div);
|
|
6581
|
-
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
6582
|
-
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$1("text", asPlainText), data.setData("application/x-portable-text-event-origin", originEvent || "external"), debug$1("Set fragment data", asJSON, asHTML);
|
|
6583
|
-
}, editor.insertPortableTextData = (data) => {
|
|
6584
|
-
if (!editor.selection)
|
|
6585
|
-
return !1;
|
|
6586
|
-
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
6587
|
-
if (debug$1(`Inserting portable text from ${origin} event`, pText), pText) {
|
|
6588
|
-
const parsed = JSON.parse(pText);
|
|
6589
|
-
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
6590
|
-
const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
|
|
6591
|
-
schemaTypes
|
|
6592
|
-
}), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
6593
|
-
if (!validation.valid && !validation.resolution?.autoResolve) {
|
|
6594
|
-
const errorDescription = `${validation.resolution?.description}`;
|
|
6595
|
-
return editorActor.send({
|
|
6596
|
-
type: "error",
|
|
6597
|
-
name: "pasteError",
|
|
6598
|
-
description: errorDescription,
|
|
6599
|
-
data: validation
|
|
6600
|
-
}), debug$1("Invalid insert result", validation), !1;
|
|
6601
|
-
}
|
|
6602
|
-
return _insertFragment(editor, slateValue, schemaTypes), !0;
|
|
6603
|
-
}
|
|
6604
|
-
}
|
|
6605
|
-
return !1;
|
|
6606
|
-
}, editor.insertTextOrHTMLData = (data) => {
|
|
6607
|
-
if (!editor.selection)
|
|
6608
|
-
return debug$1("No selection, not inserting"), !1;
|
|
6609
|
-
const html = data.getData("text/html"), text = data.getData("text/plain");
|
|
6610
|
-
if (html || text) {
|
|
6611
|
-
debug$1("Inserting data", data);
|
|
6612
|
-
let portableText, fragment, insertedType;
|
|
6613
|
-
if (html) {
|
|
6614
|
-
if (portableText = blockTools.htmlToBlocks(html, schemaTypes.portableText, {
|
|
6615
|
-
unstable_whitespaceOnPasteMode: whitespaceOnPasteMode,
|
|
6616
|
-
keyGenerator: editorActor.getSnapshot().context.keyGenerator
|
|
6617
|
-
}), fragment = toSlateValue(portableText, {
|
|
6618
|
-
schemaTypes
|
|
6619
|
-
}), insertedType = "HTML", portableText.length === 0)
|
|
6620
|
-
return !1;
|
|
6621
|
-
} else {
|
|
6622
|
-
const textToHtml = `<html><body>${escapeHtml(text).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`;
|
|
6623
|
-
portableText = blockTools.htmlToBlocks(textToHtml, schemaTypes.portableText, {
|
|
6624
|
-
keyGenerator: editorActor.getSnapshot().context.keyGenerator
|
|
6625
|
-
}), fragment = toSlateValue(portableText, {
|
|
6626
|
-
schemaTypes
|
|
6627
|
-
}), insertedType = "text";
|
|
6628
|
-
}
|
|
6629
|
-
const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
6630
|
-
if (!validation.valid) {
|
|
6631
|
-
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
6632
|
-
${validation.resolution?.description}
|
|
6633
|
-
Try to insert as plain text (shift-paste) instead.`;
|
|
6634
|
-
return editorActor.send({
|
|
6635
|
-
type: "error",
|
|
6636
|
-
name: "pasteError",
|
|
6637
|
-
description: errorDescription,
|
|
6638
|
-
data: validation
|
|
6639
|
-
}), debug$1("Invalid insert result", validation), !1;
|
|
6640
|
-
}
|
|
6641
|
-
return debug$1(`Inserting ${insertedType} fragment at ${JSON.stringify(editor.selection)}`), _insertFragment(editor, fragment, schemaTypes), !0;
|
|
6642
|
-
}
|
|
6643
|
-
return !1;
|
|
6644
|
-
}, editor.insertData = (data) => {
|
|
6645
|
-
editor.insertPortableTextData(data) || editor.insertTextOrHTMLData(data);
|
|
6646
|
-
}, editor.insertFragmentData = (data) => {
|
|
6647
|
-
const fragment = data.getData("application/x-portable-text");
|
|
6648
|
-
if (fragment) {
|
|
6649
|
-
const parsed = JSON.parse(fragment);
|
|
6650
|
-
return editor.insertFragment(parsed), !0;
|
|
6651
|
-
}
|
|
6652
|
-
return !1;
|
|
6653
|
-
}, editor;
|
|
6654
|
-
};
|
|
6655
|
-
}
|
|
6656
|
-
const entityMap = {
|
|
6657
|
-
"&": "&",
|
|
6658
|
-
"<": "<",
|
|
6659
|
-
">": ">",
|
|
6660
|
-
'"': """,
|
|
6661
|
-
"'": "'",
|
|
6662
|
-
"/": "/",
|
|
6663
|
-
"`": "`",
|
|
6664
|
-
"=": "="
|
|
6665
|
-
};
|
|
6666
|
-
function escapeHtml(str) {
|
|
6667
|
-
return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
|
|
6668
|
-
}
|
|
6669
|
-
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
|
|
6670
|
-
return fragment.map((node) => {
|
|
6671
|
-
const newNode = {
|
|
6672
|
-
...node
|
|
6673
|
-
};
|
|
6674
|
-
if (editor.isTextBlock(newNode)) {
|
|
6675
|
-
const annotations = editorTypes.annotations.map((t) => t.name);
|
|
6676
|
-
if (annotations.length === 0) {
|
|
6677
|
-
const {
|
|
6678
|
-
markDefs,
|
|
6679
|
-
...NewNodeNoDefs
|
|
6680
|
-
} = newNode;
|
|
6681
|
-
return {
|
|
6682
|
-
...NewNodeNoDefs,
|
|
6683
|
-
_key: keyGenerator()
|
|
6684
|
-
};
|
|
6685
|
-
}
|
|
6686
|
-
if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
|
|
6687
|
-
const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
|
|
6688
|
-
return {
|
|
6689
|
-
...newNode,
|
|
6690
|
-
markDefs: allowedAnnotations,
|
|
6691
|
-
_key: keyGenerator()
|
|
6692
|
-
};
|
|
6693
|
-
}
|
|
6694
|
-
newNode.markDefs = (newNode.markDefs || []).map((def) => {
|
|
6695
|
-
const oldKey = def._key, newKey = keyGenerator();
|
|
6696
|
-
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
6697
|
-
...child,
|
|
6698
|
-
marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
|
|
6699
|
-
} : child), {
|
|
6700
|
-
...def,
|
|
6701
|
-
_key: newKey
|
|
6702
|
-
};
|
|
6703
|
-
});
|
|
6704
|
-
}
|
|
6705
|
-
const nodeWithNewKeys = {
|
|
6706
|
-
...newNode,
|
|
6707
|
-
_key: keyGenerator()
|
|
6708
|
-
};
|
|
6709
|
-
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
|
|
6710
|
-
...child,
|
|
6711
|
-
_key: keyGenerator()
|
|
6712
|
-
}))), nodeWithNewKeys;
|
|
6713
|
-
});
|
|
6714
|
-
}
|
|
6715
|
-
function _insertFragment(editor, fragment, schemaTypes) {
|
|
6716
|
-
editor.withoutNormalizing(() => {
|
|
6717
|
-
if (!editor.selection)
|
|
6718
|
-
return;
|
|
6719
|
-
const [focusBlock, focusPath] = slate.Editor.node(editor, editor.selection, {
|
|
6720
|
-
depth: 1
|
|
6721
|
-
});
|
|
6722
|
-
if (editor.isTextBlock(focusBlock) && editor.isTextBlock(fragment[0])) {
|
|
6723
|
-
const {
|
|
6724
|
-
markDefs
|
|
6725
|
-
} = focusBlock;
|
|
6726
|
-
debug$1("Mixing markDefs of focusBlock and fragments[0] block", markDefs, fragment[0].markDefs), isEqual__default.default(markDefs, fragment[0].markDefs) || slate.Transforms.setNodes(editor, {
|
|
6727
|
-
markDefs: uniq__default.default([...fragment[0].markDefs || [], ...markDefs || []])
|
|
6728
|
-
}, {
|
|
6729
|
-
at: focusPath,
|
|
6730
|
-
mode: "lowest",
|
|
6731
|
-
voids: !1
|
|
6732
|
-
});
|
|
6733
|
-
}
|
|
6734
|
-
isEqualToEmptyEditor(editor.children, schemaTypes) ? (slate.Transforms.splitNodes(editor, {
|
|
6735
|
-
at: [0, 0]
|
|
6736
|
-
}), editor.insertFragment(fragment), slate.Transforms.removeNodes(editor, {
|
|
6737
|
-
at: [0]
|
|
6738
|
-
})) : editor.insertFragment(fragment);
|
|
6739
|
-
}), editor.onChange();
|
|
6740
|
-
}
|
|
6741
6951
|
function withSyncRangeDecorations({
|
|
6742
6952
|
editorActor,
|
|
6743
6953
|
slateEditor,
|
|
@@ -6785,12 +6995,11 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6785
6995
|
"edit mode": "read only"
|
|
6786
6996
|
})), schemaTypes = react.useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name;
|
|
6787
6997
|
React.useMemo(() => {
|
|
6788
|
-
const withInsertData = createWithInsertData(editorActor, schemaTypes);
|
|
6789
6998
|
if (readOnly)
|
|
6790
|
-
return debug("Editable is in read only mode"),
|
|
6999
|
+
return debug("Editable is in read only mode"), slateEditor;
|
|
6791
7000
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
6792
|
-
return debug("Editable is in edit mode"),
|
|
6793
|
-
}, [editorActor, hotkeys, portableTextEditor, readOnly,
|
|
7001
|
+
return debug("Editable is in edit mode"), withHotKeys(slateEditor);
|
|
7002
|
+
}, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
|
|
6794
7003
|
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = React.useCallback((lProps) => {
|
|
6795
7004
|
if (lProps.leaf._type === "span") {
|
|
6796
7005
|
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|