@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.js
CHANGED
|
@@ -8,7 +8,7 @@ import noop from "lodash/noop.js";
|
|
|
8
8
|
import React, { useRef, useState, useEffect, useMemo, createContext, useContext, startTransition, Component, useCallback, forwardRef, useImperativeHandle } from "react";
|
|
9
9
|
import { Editor, Element as Element$1, Range, Point, Text, Path, Transforms, Operation, Node, createEditor as createEditor$1, deleteBackward, deleteForward, insertText } from "slate";
|
|
10
10
|
import { useSlateStatic, ReactEditor, useSelected, withReact, Slate, useSlate, Editable } from "slate-react";
|
|
11
|
-
import debug$
|
|
11
|
+
import debug$j from "debug";
|
|
12
12
|
import { c } from "react-compiler-runtime";
|
|
13
13
|
import uniq from "lodash/uniq.js";
|
|
14
14
|
import { Subject } from "rxjs";
|
|
@@ -17,6 +17,9 @@ import { setup, emit, assign, fromCallback, assertEvent, enqueueActions, createA
|
|
|
17
17
|
import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
|
|
18
18
|
import flatten from "lodash/flatten.js";
|
|
19
19
|
import isPlainObject from "lodash/isPlainObject.js";
|
|
20
|
+
import { sliceBlocks } from "./_chunks-es/util.slice-blocks.js";
|
|
21
|
+
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
22
|
+
import { toHTML } from "@portabletext/to-html";
|
|
20
23
|
import get from "lodash/get.js";
|
|
21
24
|
import isUndefined from "lodash/isUndefined.js";
|
|
22
25
|
import omitBy from "lodash/omitBy.js";
|
|
@@ -24,7 +27,6 @@ import { createGuards } from "./_chunks-es/selector.is-selection-collapsed.js";
|
|
|
24
27
|
import { blockOffsetToSpanSelectionPoint } from "./_chunks-es/util.is-empty-text-block.js";
|
|
25
28
|
import { coreBehaviors, isCustomBehaviorEvent, isHotkey } from "./_chunks-es/behavior.core.js";
|
|
26
29
|
import getRandomValues from "get-random-values-esm";
|
|
27
|
-
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
28
30
|
function createEditorSchema(portableTextType) {
|
|
29
31
|
if (!portableTextType)
|
|
30
32
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
@@ -140,10 +142,10 @@ function compileSchemaDefinition(definition) {
|
|
|
140
142
|
};
|
|
141
143
|
}
|
|
142
144
|
const rootName = "sanity-pte:";
|
|
143
|
-
debug$
|
|
145
|
+
debug$j(rootName);
|
|
144
146
|
function debugWithName(name) {
|
|
145
147
|
const namespace = `${rootName}${name}`;
|
|
146
|
-
return debug$
|
|
148
|
+
return debug$j && debug$j.enabled(namespace) ? debug$j(namespace) : debug$j(rootName);
|
|
147
149
|
}
|
|
148
150
|
function createKeyedPath(point, value, types) {
|
|
149
151
|
const blockPath = [point.path[0]];
|
|
@@ -390,7 +392,7 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING
|
|
|
390
392
|
] }), $[1] = props.value._key, $[2] = props.value._type, $[3] = t1) : t1 = $[3], t1;
|
|
391
393
|
};
|
|
392
394
|
DefaultObject.displayName = "DefaultObject";
|
|
393
|
-
const debug$
|
|
395
|
+
const debug$i = debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
|
|
394
396
|
const $ = c(51), {
|
|
395
397
|
children,
|
|
396
398
|
element,
|
|
@@ -428,39 +430,39 @@ const debug$j = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
428
430
|
$[16] !== editor || $[17] !== element ? (t9 = (event_0) => {
|
|
429
431
|
const targetBlock = IS_DRAGGING_ELEMENT_TARGET.get(editor);
|
|
430
432
|
if (targetBlock) {
|
|
431
|
-
IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$
|
|
433
|
+
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));
|
|
432
434
|
const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor);
|
|
433
435
|
IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor);
|
|
434
436
|
let targetPath = ReactEditor.findPath(editor, targetBlock);
|
|
435
437
|
const myPath = ReactEditor.findPath(editor, element), isBefore = Path.isBefore(myPath, targetPath);
|
|
436
438
|
if (dragPosition === "bottom" && !isBefore) {
|
|
437
439
|
if (targetPath[0] >= editor.children.length - 1) {
|
|
438
|
-
debug$
|
|
440
|
+
debug$i("target is already at the bottom, not moving");
|
|
439
441
|
return;
|
|
440
442
|
}
|
|
441
443
|
const originalPath = targetPath;
|
|
442
|
-
targetPath = Path.next(targetPath), debug$
|
|
444
|
+
targetPath = Path.next(targetPath), debug$i(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
|
|
443
445
|
}
|
|
444
446
|
if (dragPosition === "top" && isBefore && targetPath[0] !== editor.children.length - 1) {
|
|
445
447
|
const originalPath_0 = targetPath;
|
|
446
|
-
targetPath = Path.previous(targetPath), debug$
|
|
448
|
+
targetPath = Path.previous(targetPath), debug$i(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
|
|
447
449
|
}
|
|
448
450
|
if (Path.equals(targetPath, myPath)) {
|
|
449
|
-
event_0.preventDefault(), debug$
|
|
451
|
+
event_0.preventDefault(), debug$i("targetPath and myPath is the same, not moving");
|
|
450
452
|
return;
|
|
451
453
|
}
|
|
452
|
-
debug$
|
|
454
|
+
debug$i(`Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), Transforms.moveNodes(editor, {
|
|
453
455
|
at: myPath,
|
|
454
456
|
to: targetPath
|
|
455
457
|
}), editor.onChange();
|
|
456
458
|
return;
|
|
457
459
|
}
|
|
458
|
-
debug$
|
|
460
|
+
debug$i("No target element, not doing anything");
|
|
459
461
|
}, $[16] = editor, $[17] = element, $[18] = t9) : t9 = $[18];
|
|
460
462
|
const handleDragEnd = t9;
|
|
461
463
|
let t10;
|
|
462
464
|
$[19] !== editor || $[20] !== element ? (t10 = (event_1) => {
|
|
463
|
-
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$
|
|
465
|
+
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$i("On drop (prevented)", element), event_1.preventDefault(), event_1.stopPropagation(), setIsDragOver(!1));
|
|
464
466
|
}, $[19] = editor, $[20] = element, $[21] = t10) : t10 = $[21];
|
|
465
467
|
const handleDrop = t10;
|
|
466
468
|
let t11;
|
|
@@ -477,10 +479,10 @@ const debug$j = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
477
479
|
let t12;
|
|
478
480
|
$[26] !== blockElement || $[27] !== editor || $[28] !== handleDrag || $[29] !== isInline || $[30] !== isVoid ? (t12 = (event_3) => {
|
|
479
481
|
if (!isVoid || isInline) {
|
|
480
|
-
debug$
|
|
482
|
+
debug$i("Not dragging block"), IS_DRAGGING_BLOCK_ELEMENT.delete(editor), IS_DRAGGING.set(editor, !1);
|
|
481
483
|
return;
|
|
482
484
|
}
|
|
483
|
-
if (debug$
|
|
485
|
+
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) {
|
|
484
486
|
let dragGhost = blockElement.cloneNode(!0);
|
|
485
487
|
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
486
488
|
if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
|
|
@@ -1517,14 +1519,14 @@ function getAlphabetFromPattern(pattern) {
|
|
|
1517
1519
|
for (let i = 0; i < pattern.length; i++) s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
|
|
1518
1520
|
return s;
|
|
1519
1521
|
}
|
|
1520
|
-
function match(text, pattern, searchLocation) {
|
|
1522
|
+
function match(text, pattern, searchLocation, options = {}) {
|
|
1521
1523
|
if (text === null || pattern === null || searchLocation === null) throw new Error("Null input. (match())");
|
|
1522
1524
|
const loc = Math.max(0, Math.min(searchLocation, text.length));
|
|
1523
1525
|
if (text === pattern) return 0;
|
|
1524
1526
|
if (text.length) {
|
|
1525
1527
|
if (text.substring(loc, loc + pattern.length) === pattern) return loc;
|
|
1526
1528
|
} else return -1;
|
|
1527
|
-
return bitap(text, pattern, loc);
|
|
1529
|
+
return bitap(text, pattern, loc, options);
|
|
1528
1530
|
}
|
|
1529
1531
|
function diffText1(diffs) {
|
|
1530
1532
|
const text = [];
|
|
@@ -1556,10 +1558,10 @@ function levenshtein(diffs) {
|
|
|
1556
1558
|
}
|
|
1557
1559
|
return leven += Math.max(insertions, deletions), leven;
|
|
1558
1560
|
}
|
|
1559
|
-
function xIndex(diffs,
|
|
1561
|
+
function xIndex(diffs, location) {
|
|
1560
1562
|
let chars1 = 0, chars2 = 0, lastChars1 = 0, lastChars2 = 0, x;
|
|
1561
|
-
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 >
|
|
1562
|
-
return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (
|
|
1563
|
+
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;
|
|
1564
|
+
return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (location - lastChars1);
|
|
1563
1565
|
}
|
|
1564
1566
|
function countUtf8Bytes(str) {
|
|
1565
1567
|
let bytes = 0;
|
|
@@ -1752,7 +1754,7 @@ function isRedoing(editor) {
|
|
|
1752
1754
|
function setIsRedoing(editor, isRedoing2) {
|
|
1753
1755
|
IS_REDOING.set(editor, isRedoing2);
|
|
1754
1756
|
}
|
|
1755
|
-
const debug$
|
|
1757
|
+
const debug$h = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
1756
1758
|
const state = SAVING.get(editor);
|
|
1757
1759
|
return state === void 0 ? !0 : state;
|
|
1758
1760
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -1765,7 +1767,7 @@ function createWithUndoRedo(options) {
|
|
|
1765
1767
|
let previousSnapshot = fromSlateValue(editor.children, blockSchemaType.name);
|
|
1766
1768
|
const remotePatches = getRemotePatches(editor);
|
|
1767
1769
|
options.subscriptions.push(() => {
|
|
1768
|
-
debug$
|
|
1770
|
+
debug$h("Subscribing to patches");
|
|
1769
1771
|
const sub = editorActor.on("patches", ({
|
|
1770
1772
|
patches,
|
|
1771
1773
|
snapshot
|
|
@@ -1774,7 +1776,7 @@ function createWithUndoRedo(options) {
|
|
|
1774
1776
|
patches.forEach((patch) => {
|
|
1775
1777
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
1776
1778
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
1777
|
-
debug$
|
|
1779
|
+
debug$h("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
1778
1780
|
undos: [],
|
|
1779
1781
|
redos: []
|
|
1780
1782
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -1790,7 +1792,7 @@ function createWithUndoRedo(options) {
|
|
|
1790
1792
|
}), previousSnapshot = snapshot;
|
|
1791
1793
|
});
|
|
1792
1794
|
return () => {
|
|
1793
|
-
debug$
|
|
1795
|
+
debug$h("Unsubscribing to patches"), sub.unsubscribe();
|
|
1794
1796
|
};
|
|
1795
1797
|
}), editor.history = {
|
|
1796
1798
|
undos: [],
|
|
@@ -1829,7 +1831,7 @@ function createWithUndoRedo(options) {
|
|
|
1829
1831
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
1830
1832
|
timestamp: /* @__PURE__ */ new Date()
|
|
1831
1833
|
};
|
|
1832
|
-
undos.push(newStep), debug$
|
|
1834
|
+
undos.push(newStep), debug$h("Created new undo step", step);
|
|
1833
1835
|
}
|
|
1834
1836
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
1835
1837
|
undos.shift();
|
|
@@ -1846,7 +1848,7 @@ function createWithUndoRedo(options) {
|
|
|
1846
1848
|
} = editor.history;
|
|
1847
1849
|
if (undos.length > 0) {
|
|
1848
1850
|
const step = undos[undos.length - 1];
|
|
1849
|
-
if (debug$
|
|
1851
|
+
if (debug$h("Undoing", step), step.operations.length > 0) {
|
|
1850
1852
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
1851
1853
|
let transformedOperations = step.operations;
|
|
1852
1854
|
otherPatches.forEach((item) => {
|
|
@@ -1864,7 +1866,7 @@ function createWithUndoRedo(options) {
|
|
|
1864
1866
|
});
|
|
1865
1867
|
}), editor.normalize(), editor.onChange();
|
|
1866
1868
|
} catch (err) {
|
|
1867
|
-
debug$
|
|
1869
|
+
debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
1868
1870
|
undos: [],
|
|
1869
1871
|
redos: []
|
|
1870
1872
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -1883,7 +1885,7 @@ function createWithUndoRedo(options) {
|
|
|
1883
1885
|
} = editor.history;
|
|
1884
1886
|
if (redos.length > 0) {
|
|
1885
1887
|
const step = redos[redos.length - 1];
|
|
1886
|
-
if (debug$
|
|
1888
|
+
if (debug$h("Redoing", step), step.operations.length > 0) {
|
|
1887
1889
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
1888
1890
|
let transformedOperations = step.operations;
|
|
1889
1891
|
otherPatches.forEach((item) => {
|
|
@@ -1900,7 +1902,7 @@ function createWithUndoRedo(options) {
|
|
|
1900
1902
|
});
|
|
1901
1903
|
}), editor.normalize(), editor.onChange();
|
|
1902
1904
|
} catch (err) {
|
|
1903
|
-
debug$
|
|
1905
|
+
debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
1904
1906
|
undos: [],
|
|
1905
1907
|
redos: []
|
|
1906
1908
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -1920,16 +1922,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
1920
1922
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
1921
1923
|
_key: blk._key
|
|
1922
1924
|
}, patch.path[0]));
|
|
1923
|
-
return debug$
|
|
1925
|
+
return debug$h(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
1924
1926
|
}
|
|
1925
1927
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
1926
1928
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
|
|
1927
1929
|
_key: blk._key
|
|
1928
1930
|
}, patch.path[0]));
|
|
1929
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
1931
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$h("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
1930
1932
|
}
|
|
1931
1933
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
1932
|
-
return debug$
|
|
1934
|
+
return debug$h(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
1933
1935
|
if (patch.type === "diffMatchPatch") {
|
|
1934
1936
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
1935
1937
|
return !operationTargetBlock || !isEqual({
|
|
@@ -2209,7 +2211,7 @@ const syncValueCallback = ({
|
|
|
2209
2211
|
}
|
|
2210
2212
|
}
|
|
2211
2213
|
}
|
|
2212
|
-
}), debug$
|
|
2214
|
+
}), debug$g = debugWithName("hook:useSyncValue");
|
|
2213
2215
|
async function updateValue({
|
|
2214
2216
|
context,
|
|
2215
2217
|
sendBack,
|
|
@@ -2219,7 +2221,7 @@ async function updateValue({
|
|
|
2219
2221
|
}) {
|
|
2220
2222
|
let isChanged = !1, isValid = !0;
|
|
2221
2223
|
const hadSelection = !!slateEditor.selection;
|
|
2222
|
-
if ((!value || value.length === 0) && (debug$
|
|
2224
|
+
if ((!value || value.length === 0) && (debug$g("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
|
|
2223
2225
|
withoutSaving(slateEditor, () => {
|
|
2224
2226
|
withoutPatching(slateEditor, () => {
|
|
2225
2227
|
hadSelection && Transforms.deselect(slateEditor);
|
|
@@ -2275,14 +2277,14 @@ async function updateValue({
|
|
|
2275
2277
|
});
|
|
2276
2278
|
}
|
|
2277
2279
|
if (!isValid) {
|
|
2278
|
-
debug$
|
|
2280
|
+
debug$g("Invalid value, returning"), sendBack({
|
|
2279
2281
|
type: "done syncing",
|
|
2280
2282
|
value
|
|
2281
2283
|
});
|
|
2282
2284
|
return;
|
|
2283
2285
|
}
|
|
2284
2286
|
if (isChanged) {
|
|
2285
|
-
debug$
|
|
2287
|
+
debug$g("Server value changed, syncing editor");
|
|
2286
2288
|
try {
|
|
2287
2289
|
slateEditor.onChange();
|
|
2288
2290
|
} catch (err) {
|
|
@@ -2310,7 +2312,7 @@ async function updateValue({
|
|
|
2310
2312
|
value
|
|
2311
2313
|
});
|
|
2312
2314
|
} else
|
|
2313
|
-
debug$
|
|
2315
|
+
debug$g("Server value and editor value is equal, no need to sync.");
|
|
2314
2316
|
sendBack({
|
|
2315
2317
|
type: "done syncing",
|
|
2316
2318
|
value
|
|
@@ -2344,7 +2346,7 @@ function syncBlock({
|
|
|
2344
2346
|
type: "patch",
|
|
2345
2347
|
patch
|
|
2346
2348
|
});
|
|
2347
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
2349
|
+
})), 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({
|
|
2348
2350
|
type: "invalid value",
|
|
2349
2351
|
resolution: validation.resolution,
|
|
2350
2352
|
value
|
|
@@ -2352,9 +2354,9 @@ function syncBlock({
|
|
|
2352
2354
|
}
|
|
2353
2355
|
if (!oldBlock && blockValid) {
|
|
2354
2356
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2355
|
-
debug$
|
|
2357
|
+
debug$g.enabled && debug$g("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2356
2358
|
at: [currentBlockIndex]
|
|
2357
|
-
}) : (debug$
|
|
2359
|
+
}) : (debug$g("Invalid", validation), sendBack({
|
|
2358
2360
|
type: "invalid value",
|
|
2359
2361
|
resolution: validation.resolution,
|
|
2360
2362
|
value
|
|
@@ -2382,14 +2384,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2382
2384
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
2383
2385
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
2384
2386
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
2385
|
-
childIndex > 0 && (debug$
|
|
2387
|
+
childIndex > 0 && (debug$g("Removing child"), Transforms.removeNodes(slateEditor, {
|
|
2386
2388
|
at: [currentBlockIndex, childIndex]
|
|
2387
2389
|
}));
|
|
2388
2390
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
2389
2391
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2390
2392
|
if (isChildChanged)
|
|
2391
2393
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2392
|
-
debug$
|
|
2394
|
+
debug$g("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2393
2395
|
at: path
|
|
2394
2396
|
});
|
|
2395
2397
|
const isSpanNode = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -2406,23 +2408,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2406
2408
|
}
|
|
2407
2409
|
}), Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
2408
2410
|
at: path
|
|
2409
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
2411
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$g("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
|
|
2410
2412
|
_key: VOID_CHILD_KEY
|
|
2411
2413
|
}, {
|
|
2412
2414
|
at: [...path, 0],
|
|
2413
2415
|
voids: !0
|
|
2414
2416
|
}));
|
|
2415
|
-
} else oldBlockChild ? (debug$
|
|
2417
|
+
} else oldBlockChild ? (debug$g("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
|
|
2416
2418
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2417
2419
|
}), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2418
2420
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2419
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
2421
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$g("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2420
2422
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2421
2423
|
}), slateEditor.onChange());
|
|
2422
2424
|
});
|
|
2423
2425
|
}
|
|
2424
2426
|
}
|
|
2425
|
-
const debug$
|
|
2427
|
+
const debug$f = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
2426
2428
|
function Synchronizer(props) {
|
|
2427
2429
|
const $ = c(40), {
|
|
2428
2430
|
editorActor,
|
|
@@ -2493,19 +2495,19 @@ function Synchronizer(props) {
|
|
|
2493
2495
|
}, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), useEffect(t11, t12);
|
|
2494
2496
|
let t13, t14;
|
|
2495
2497
|
$[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
|
|
2496
|
-
debug$
|
|
2498
|
+
debug$f("Value from props changed, syncing new value"), syncActorRef.send({
|
|
2497
2499
|
type: "update value",
|
|
2498
2500
|
value
|
|
2499
2501
|
});
|
|
2500
2502
|
}, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), useEffect(t13, t14);
|
|
2501
2503
|
let t15;
|
|
2502
2504
|
$[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
|
|
2503
|
-
debug$
|
|
2505
|
+
debug$f("Subscribing to patch events");
|
|
2504
2506
|
const sub = editorActor.on("patch", (event_1) => {
|
|
2505
2507
|
mutationActorRef.send(event_1);
|
|
2506
2508
|
});
|
|
2507
2509
|
return () => {
|
|
2508
|
-
debug$
|
|
2510
|
+
debug$f("Unsubscribing to patch events"), sub.unsubscribe();
|
|
2509
2511
|
};
|
|
2510
2512
|
}, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
|
|
2511
2513
|
let t16;
|
|
@@ -2520,11 +2522,255 @@ function _temp(s) {
|
|
|
2520
2522
|
return s.context.value;
|
|
2521
2523
|
}
|
|
2522
2524
|
Synchronizer.displayName = "Synchronizer";
|
|
2523
|
-
const
|
|
2525
|
+
const converterJson = {
|
|
2526
|
+
serialize: ({
|
|
2527
|
+
context,
|
|
2528
|
+
event
|
|
2529
|
+
}) => {
|
|
2530
|
+
const portableTextConverter = context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2531
|
+
return portableTextConverter ? {
|
|
2532
|
+
...portableTextConverter.serialize({
|
|
2533
|
+
context,
|
|
2534
|
+
event
|
|
2535
|
+
}),
|
|
2536
|
+
mimeType: "application/json",
|
|
2537
|
+
originEvent: event.originEvent
|
|
2538
|
+
} : {
|
|
2539
|
+
type: "serialization.failure",
|
|
2540
|
+
mimeType: "application/json",
|
|
2541
|
+
originEvent: event.originEvent,
|
|
2542
|
+
reason: "No application/x-portable-text Converter found"
|
|
2543
|
+
};
|
|
2544
|
+
},
|
|
2545
|
+
deserialize: ({
|
|
2546
|
+
context,
|
|
2547
|
+
event
|
|
2548
|
+
}) => {
|
|
2549
|
+
const portableTextConverter = context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2550
|
+
return portableTextConverter ? {
|
|
2551
|
+
...portableTextConverter.deserialize({
|
|
2552
|
+
context,
|
|
2553
|
+
event
|
|
2554
|
+
}),
|
|
2555
|
+
mimeType: "application/json"
|
|
2556
|
+
} : {
|
|
2557
|
+
type: "deserialization.failure",
|
|
2558
|
+
mimeType: "application/json",
|
|
2559
|
+
reason: "No application/x-portable-text Converter found"
|
|
2560
|
+
};
|
|
2561
|
+
},
|
|
2562
|
+
mimeType: "application/json"
|
|
2563
|
+
};
|
|
2564
|
+
function isTypedObject(object) {
|
|
2565
|
+
return isRecord(object) && typeof object._type == "string";
|
|
2566
|
+
}
|
|
2567
|
+
function isRecord(value) {
|
|
2568
|
+
return !!value && (typeof value == "object" || typeof value == "function");
|
|
2569
|
+
}
|
|
2570
|
+
function parseBlock({
|
|
2571
|
+
context,
|
|
2572
|
+
block
|
|
2573
|
+
}) {
|
|
2574
|
+
if (!isTypedObject(block) || block._type !== context.schema.block.name && !context.schema.blockObjects.some((blockObject) => blockObject.name === block._type))
|
|
2575
|
+
return;
|
|
2576
|
+
if (!isPortableTextTextBlock(block))
|
|
2577
|
+
return {
|
|
2578
|
+
...block,
|
|
2579
|
+
_key: context.keyGenerator()
|
|
2580
|
+
};
|
|
2581
|
+
const markDefKeyMap = /* @__PURE__ */ new Map(), markDefs = (block.markDefs ?? []).flatMap((markDef) => {
|
|
2582
|
+
if (context.schema.annotations.some((annotation) => annotation.name === markDef._type)) {
|
|
2583
|
+
const _key = context.keyGenerator();
|
|
2584
|
+
return markDefKeyMap.set(markDef._key, _key), [{
|
|
2585
|
+
...markDef,
|
|
2586
|
+
_key
|
|
2587
|
+
}];
|
|
2588
|
+
}
|
|
2589
|
+
return [];
|
|
2590
|
+
}), children = block.children.flatMap((child) => {
|
|
2591
|
+
if (!isTypedObject(child))
|
|
2592
|
+
return [];
|
|
2593
|
+
if (child._type !== context.schema.span.name && !context.schema.inlineObjects.some((inlineObject) => inlineObject.name === child._type))
|
|
2594
|
+
return [];
|
|
2595
|
+
if (!isPortableTextSpan$1(child))
|
|
2596
|
+
return [{
|
|
2597
|
+
...child,
|
|
2598
|
+
_key: context.keyGenerator()
|
|
2599
|
+
}];
|
|
2600
|
+
const marks = (child.marks ?? []).flatMap((mark) => markDefKeyMap.has(mark) ? [markDefKeyMap.get(mark)] : context.schema.decorators.some((decorator) => decorator.value === mark) ? [mark] : []);
|
|
2601
|
+
return [{
|
|
2602
|
+
...child,
|
|
2603
|
+
_key: context.keyGenerator(),
|
|
2604
|
+
marks
|
|
2605
|
+
}];
|
|
2606
|
+
}), parsedBlock = {
|
|
2607
|
+
...block,
|
|
2608
|
+
_key: context.keyGenerator(),
|
|
2609
|
+
children: children.length > 0 ? children : [{
|
|
2610
|
+
_key: context.keyGenerator(),
|
|
2611
|
+
_type: context.schema.span.name,
|
|
2612
|
+
text: "",
|
|
2613
|
+
marks: []
|
|
2614
|
+
}],
|
|
2615
|
+
markDefs
|
|
2616
|
+
};
|
|
2617
|
+
if (!context.schema.styles.find((style) => style.value === block.style)) {
|
|
2618
|
+
const defaultStyle = context.schema.styles[0].value;
|
|
2619
|
+
defaultStyle !== void 0 ? parsedBlock.style = defaultStyle : delete parsedBlock.style;
|
|
2620
|
+
}
|
|
2621
|
+
return context.schema.lists.find((list) => list.value === block.listItem) || (delete parsedBlock.listItem, delete parsedBlock.level), parsedBlock;
|
|
2622
|
+
}
|
|
2623
|
+
const converterPortableText = {
|
|
2624
|
+
serialize: ({
|
|
2625
|
+
context,
|
|
2626
|
+
event
|
|
2627
|
+
}) => {
|
|
2628
|
+
if (!context.selection)
|
|
2629
|
+
return {
|
|
2630
|
+
type: "serialization.failure",
|
|
2631
|
+
mimeType: "application/x-portable-text",
|
|
2632
|
+
originEvent: event.originEvent,
|
|
2633
|
+
reason: "No selection"
|
|
2634
|
+
};
|
|
2635
|
+
const blocks = sliceBlocks({
|
|
2636
|
+
blocks: context.value,
|
|
2637
|
+
selection: context.selection
|
|
2638
|
+
});
|
|
2639
|
+
return {
|
|
2640
|
+
type: "serialization.success",
|
|
2641
|
+
data: JSON.stringify(blocks),
|
|
2642
|
+
mimeType: "application/x-portable-text",
|
|
2643
|
+
originEvent: event.originEvent
|
|
2644
|
+
};
|
|
2645
|
+
},
|
|
2646
|
+
deserialize: ({
|
|
2647
|
+
context,
|
|
2648
|
+
event
|
|
2649
|
+
}) => {
|
|
2650
|
+
const blocks = JSON.parse(event.data);
|
|
2651
|
+
if (!Array.isArray(blocks))
|
|
2652
|
+
return {
|
|
2653
|
+
type: "deserialization.failure",
|
|
2654
|
+
mimeType: "application/x-portable-text",
|
|
2655
|
+
reason: "Data is not an array"
|
|
2656
|
+
};
|
|
2657
|
+
const parsedBlocks = blocks.flatMap((block) => {
|
|
2658
|
+
const parsedBlock = parseBlock({
|
|
2659
|
+
context,
|
|
2660
|
+
block
|
|
2661
|
+
});
|
|
2662
|
+
return parsedBlock ? [parsedBlock] : [];
|
|
2663
|
+
});
|
|
2664
|
+
return parsedBlocks.length === 0 && blocks.length > 0 ? {
|
|
2665
|
+
type: "deserialization.failure",
|
|
2666
|
+
mimeType: "application/x-portable-text",
|
|
2667
|
+
reason: "No blocks were parsed"
|
|
2668
|
+
} : {
|
|
2669
|
+
type: "deserialization.success",
|
|
2670
|
+
data: parsedBlocks,
|
|
2671
|
+
mimeType: "application/x-portable-text"
|
|
2672
|
+
};
|
|
2673
|
+
},
|
|
2674
|
+
mimeType: "application/x-portable-text"
|
|
2675
|
+
}, converterTextHtml = {
|
|
2676
|
+
serialize: ({
|
|
2677
|
+
context,
|
|
2678
|
+
event
|
|
2679
|
+
}) => {
|
|
2680
|
+
if (!context.selection)
|
|
2681
|
+
return {
|
|
2682
|
+
type: "serialization.failure",
|
|
2683
|
+
mimeType: "text/html",
|
|
2684
|
+
originEvent: event.originEvent,
|
|
2685
|
+
reason: "No selection"
|
|
2686
|
+
};
|
|
2687
|
+
const blocks = sliceBlocks({
|
|
2688
|
+
blocks: context.value,
|
|
2689
|
+
selection: context.selection
|
|
2690
|
+
}), html = toHTML(blocks, {
|
|
2691
|
+
onMissingComponent: !1,
|
|
2692
|
+
components: {
|
|
2693
|
+
unknownType: ({
|
|
2694
|
+
children
|
|
2695
|
+
}) => children !== void 0 ? `${children}` : ""
|
|
2696
|
+
}
|
|
2697
|
+
});
|
|
2698
|
+
return html === "" ? {
|
|
2699
|
+
type: "serialization.failure",
|
|
2700
|
+
mimeType: "text/html",
|
|
2701
|
+
originEvent: event.originEvent,
|
|
2702
|
+
reason: "Serialized HTML is empty"
|
|
2703
|
+
} : {
|
|
2704
|
+
type: "serialization.success",
|
|
2705
|
+
data: html,
|
|
2706
|
+
mimeType: "text/html",
|
|
2707
|
+
originEvent: event.originEvent
|
|
2708
|
+
};
|
|
2709
|
+
},
|
|
2710
|
+
deserialize: ({
|
|
2711
|
+
context,
|
|
2712
|
+
event
|
|
2713
|
+
}) => ({
|
|
2714
|
+
type: "deserialization.success",
|
|
2715
|
+
data: htmlToBlocks(event.data, context.schema.portableText, {
|
|
2716
|
+
keyGenerator: context.keyGenerator,
|
|
2717
|
+
unstable_whitespaceOnPasteMode: context.schema.block.options.unstable_whitespaceOnPasteMode
|
|
2718
|
+
}),
|
|
2719
|
+
mimeType: "text/html"
|
|
2720
|
+
}),
|
|
2721
|
+
mimeType: "text/html"
|
|
2722
|
+
}, converterTextPlain = {
|
|
2723
|
+
mimeType: "text/plain",
|
|
2724
|
+
serialize: ({
|
|
2725
|
+
context,
|
|
2726
|
+
event
|
|
2727
|
+
}) => context.selection ? {
|
|
2728
|
+
type: "serialization.success",
|
|
2729
|
+
data: sliceBlocks({
|
|
2730
|
+
blocks: context.value,
|
|
2731
|
+
selection: context.selection
|
|
2732
|
+
}).map((block) => 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(`
|
|
2733
|
+
|
|
2734
|
+
`),
|
|
2735
|
+
mimeType: "text/plain",
|
|
2736
|
+
originEvent: event.originEvent
|
|
2737
|
+
} : {
|
|
2738
|
+
type: "serialization.failure",
|
|
2739
|
+
mimeType: "text/plain",
|
|
2740
|
+
originEvent: event.originEvent,
|
|
2741
|
+
reason: "No selection"
|
|
2742
|
+
},
|
|
2743
|
+
deserialize: ({
|
|
2744
|
+
context,
|
|
2745
|
+
event
|
|
2746
|
+
}) => {
|
|
2747
|
+
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>`;
|
|
2748
|
+
return {
|
|
2749
|
+
type: "deserialization.success",
|
|
2750
|
+
data: htmlToBlocks(textToHtml, context.schema.portableText, {
|
|
2751
|
+
keyGenerator: context.keyGenerator
|
|
2752
|
+
}),
|
|
2753
|
+
mimeType: "text/plain"
|
|
2754
|
+
};
|
|
2755
|
+
}
|
|
2756
|
+
}, entityMap = {
|
|
2757
|
+
"&": "&",
|
|
2758
|
+
"<": "<",
|
|
2759
|
+
">": ">",
|
|
2760
|
+
'"': """,
|
|
2761
|
+
"'": "'",
|
|
2762
|
+
"/": "/",
|
|
2763
|
+
"`": "`",
|
|
2764
|
+
"=": "="
|
|
2765
|
+
};
|
|
2766
|
+
function escapeHtml(str) {
|
|
2767
|
+
return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
|
|
2768
|
+
}
|
|
2769
|
+
const coreConverters = [converterJson, converterPortableText, converterTextHtml, converterTextPlain], debug$e = debugWithName("operationToPatches");
|
|
2524
2770
|
function createOperationToPatches(types) {
|
|
2525
2771
|
const textBlockName = types.block.name;
|
|
2526
2772
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
2527
|
-
debug$
|
|
2773
|
+
debug$e.enabled && debug$e("Operation", JSON.stringify(operation, null, 2));
|
|
2528
2774
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
2529
2775
|
if (!block)
|
|
2530
2776
|
throw new Error("Could not find block");
|
|
@@ -2617,7 +2863,7 @@ function createOperationToPatches(types) {
|
|
|
2617
2863
|
_key: block.children[operation.path[1] - 1]._key
|
|
2618
2864
|
}])];
|
|
2619
2865
|
}
|
|
2620
|
-
return debug$
|
|
2866
|
+
return debug$e("Something was inserted into a void block. Not producing editor patches."), [];
|
|
2621
2867
|
}
|
|
2622
2868
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
2623
2869
|
const patches = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -2675,9 +2921,9 @@ function createOperationToPatches(types) {
|
|
|
2675
2921
|
_key: block._key
|
|
2676
2922
|
}, "children", {
|
|
2677
2923
|
_key: spanToRemove._key
|
|
2678
|
-
}])] : (debug$
|
|
2924
|
+
}])] : (debug$e("Span not found in editor trying to remove node"), []);
|
|
2679
2925
|
} else
|
|
2680
|
-
return debug$
|
|
2926
|
+
return debug$e("Not creating patch inside object block"), [];
|
|
2681
2927
|
}
|
|
2682
2928
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2683
2929
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -2703,7 +2949,7 @@ function createOperationToPatches(types) {
|
|
|
2703
2949
|
_key: removedSpan._key
|
|
2704
2950
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
2705
2951
|
} else
|
|
2706
|
-
debug$
|
|
2952
|
+
debug$e("Void nodes can't be merged, not creating any patches");
|
|
2707
2953
|
return patches;
|
|
2708
2954
|
}
|
|
2709
2955
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -2884,9 +3130,11 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2884
3130
|
deleteBackward: deleteBackward2,
|
|
2885
3131
|
deleteForward: deleteForward2,
|
|
2886
3132
|
insertBreak,
|
|
3133
|
+
insertData,
|
|
2887
3134
|
insertSoftBreak,
|
|
2888
3135
|
insertText: insertText2,
|
|
2889
|
-
select
|
|
3136
|
+
select,
|
|
3137
|
+
setFragmentData
|
|
2890
3138
|
} = editor;
|
|
2891
3139
|
return editor.deleteBackward = (unit) => {
|
|
2892
3140
|
if (isApplyingBehaviorActions(editor)) {
|
|
@@ -2926,6 +3174,19 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2926
3174
|
},
|
|
2927
3175
|
editor
|
|
2928
3176
|
});
|
|
3177
|
+
}, editor.insertData = (dataTransfer) => {
|
|
3178
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
3179
|
+
insertData(dataTransfer);
|
|
3180
|
+
return;
|
|
3181
|
+
}
|
|
3182
|
+
editorActor.send({
|
|
3183
|
+
type: "behavior event",
|
|
3184
|
+
behaviorEvent: {
|
|
3185
|
+
type: "deserialize",
|
|
3186
|
+
dataTransfer
|
|
3187
|
+
},
|
|
3188
|
+
editor
|
|
3189
|
+
});
|
|
2929
3190
|
}, editor.insertSoftBreak = () => {
|
|
2930
3191
|
if (isApplyingBehaviorActions(editor)) {
|
|
2931
3192
|
insertSoftBreak();
|
|
@@ -2972,6 +3233,24 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2972
3233
|
select(location);
|
|
2973
3234
|
}
|
|
2974
3235
|
});
|
|
3236
|
+
}, editor.setFragmentData = (dataTransfer, originEvent) => {
|
|
3237
|
+
if (originEvent === "drag") {
|
|
3238
|
+
setFragmentData(dataTransfer);
|
|
3239
|
+
return;
|
|
3240
|
+
}
|
|
3241
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
3242
|
+
setFragmentData(dataTransfer);
|
|
3243
|
+
return;
|
|
3244
|
+
}
|
|
3245
|
+
dataTransfer.clearData(), editorActor.send({
|
|
3246
|
+
type: "behavior event",
|
|
3247
|
+
behaviorEvent: {
|
|
3248
|
+
type: "serialize",
|
|
3249
|
+
dataTransfer,
|
|
3250
|
+
originEvent: originEvent ?? "unknown"
|
|
3251
|
+
},
|
|
3252
|
+
editor
|
|
3253
|
+
});
|
|
2975
3254
|
}, editor;
|
|
2976
3255
|
};
|
|
2977
3256
|
}
|
|
@@ -3069,13 +3348,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3069
3348
|
}, editor;
|
|
3070
3349
|
};
|
|
3071
3350
|
}
|
|
3072
|
-
const debug$
|
|
3351
|
+
const debug$d = debugWithName("applyPatches"), debugVerbose = debug$d.enabled && !0;
|
|
3073
3352
|
function createApplyPatch(schemaTypes) {
|
|
3074
3353
|
return (editor, patch) => {
|
|
3075
3354
|
let changed = !1;
|
|
3076
|
-
debugVerbose && (debug$
|
|
3355
|
+
debugVerbose && (debug$d(`
|
|
3077
3356
|
|
|
3078
|
-
NEW PATCH =============================================================`), debug$
|
|
3357
|
+
NEW PATCH =============================================================`), debug$d(JSON.stringify(patch, null, 2)));
|
|
3079
3358
|
try {
|
|
3080
3359
|
switch (patch.type) {
|
|
3081
3360
|
case "insert":
|
|
@@ -3091,7 +3370,7 @@ NEW PATCH =============================================================`), debug
|
|
|
3091
3370
|
changed = diffMatchPatch(editor, patch);
|
|
3092
3371
|
break;
|
|
3093
3372
|
default:
|
|
3094
|
-
debug$
|
|
3373
|
+
debug$d("Unhandled patch", patch.type);
|
|
3095
3374
|
}
|
|
3096
3375
|
} catch (err) {
|
|
3097
3376
|
console.error(err);
|
|
@@ -3106,9 +3385,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
3106
3385
|
childPath
|
|
3107
3386
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3108
3387
|
if (!block)
|
|
3109
|
-
return debug$
|
|
3388
|
+
return debug$d("Block not found"), !1;
|
|
3110
3389
|
if (!child || !childPath)
|
|
3111
|
-
return debug$
|
|
3390
|
+
return debug$d("Child not found"), !1;
|
|
3112
3391
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !Text.isText(child))
|
|
3113
3392
|
return !1;
|
|
3114
3393
|
const patches = parse(patch.value), [newValue] = apply(patches, child.text, {
|
|
@@ -3138,9 +3417,9 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3138
3417
|
childPath: targetChildPath
|
|
3139
3418
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3140
3419
|
if (!targetBlock || !targetBlockPath)
|
|
3141
|
-
return debug$
|
|
3420
|
+
return debug$d("Block not found"), !1;
|
|
3142
3421
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
3143
|
-
return debug$
|
|
3422
|
+
return debug$d("Ignoring patch targeting void value"), !1;
|
|
3144
3423
|
if (patch.path.length === 1) {
|
|
3145
3424
|
const {
|
|
3146
3425
|
items: items2,
|
|
@@ -3148,7 +3427,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3148
3427
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
3149
3428
|
schemaTypes
|
|
3150
3429
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
3151
|
-
return debug$
|
|
3430
|
+
return debug$d(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
|
|
3152
3431
|
at: [normalizedIdx2]
|
|
3153
3432
|
}), debugState(editor, "after"), !0;
|
|
3154
3433
|
}
|
|
@@ -3157,14 +3436,14 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3157
3436
|
position
|
|
3158
3437
|
} = patch;
|
|
3159
3438
|
if (!targetChild || !targetChildPath)
|
|
3160
|
-
return debug$
|
|
3439
|
+
return debug$d("Child not found"), !1;
|
|
3161
3440
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3162
3441
|
...targetBlock,
|
|
3163
3442
|
children: items
|
|
3164
3443
|
}], {
|
|
3165
3444
|
schemaTypes
|
|
3166
3445
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3167
|
-
return debug$
|
|
3446
|
+
return debug$d(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
3168
3447
|
at: childInsertPath
|
|
3169
3448
|
}), debugState(editor, "after"), !0;
|
|
3170
3449
|
}
|
|
@@ -3178,14 +3457,14 @@ function setPatch(editor, patch) {
|
|
|
3178
3457
|
childPath
|
|
3179
3458
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3180
3459
|
if (!block)
|
|
3181
|
-
return debug$
|
|
3460
|
+
return debug$d("Block not found"), !1;
|
|
3182
3461
|
const isTextBlock = editor.isTextBlock(block);
|
|
3183
3462
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
3184
|
-
return debug$
|
|
3463
|
+
return debug$d("Ignoring setting void value"), !1;
|
|
3185
3464
|
if (debugState(editor, "before"), isTextBlock && child && childPath) {
|
|
3186
3465
|
if (Text.isText(value) && Text.isText(child)) {
|
|
3187
3466
|
const newText = child.text;
|
|
3188
|
-
value.text !== newText && (debug$
|
|
3467
|
+
value.text !== newText && (debug$d("Setting text property"), editor.apply({
|
|
3189
3468
|
type: "remove_text",
|
|
3190
3469
|
path: childPath,
|
|
3191
3470
|
offset: 0,
|
|
@@ -3197,7 +3476,7 @@ function setPatch(editor, patch) {
|
|
|
3197
3476
|
text: value.text
|
|
3198
3477
|
}), editor.onChange());
|
|
3199
3478
|
} else
|
|
3200
|
-
debug$
|
|
3479
|
+
debug$d("Setting non-text property"), editor.apply({
|
|
3201
3480
|
type: "set_node",
|
|
3202
3481
|
path: childPath,
|
|
3203
3482
|
properties: {},
|
|
@@ -3205,7 +3484,7 @@ function setPatch(editor, patch) {
|
|
|
3205
3484
|
});
|
|
3206
3485
|
return !0;
|
|
3207
3486
|
} else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3208
|
-
debug$
|
|
3487
|
+
debug$d("Setting block property");
|
|
3209
3488
|
const {
|
|
3210
3489
|
children,
|
|
3211
3490
|
...nextRest
|
|
@@ -3222,7 +3501,7 @@ function setPatch(editor, patch) {
|
|
|
3222
3501
|
...prevRest
|
|
3223
3502
|
},
|
|
3224
3503
|
newProperties: nextRest
|
|
3225
|
-
}), debug$
|
|
3504
|
+
}), debug$d("Setting children"), block.children.forEach((c2, cIndex) => {
|
|
3226
3505
|
editor.apply({
|
|
3227
3506
|
type: "remove_node",
|
|
3228
3507
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -3248,7 +3527,7 @@ function setPatch(editor, patch) {
|
|
|
3248
3527
|
}
|
|
3249
3528
|
function unsetPatch(editor, patch) {
|
|
3250
3529
|
if (patch.path.length === 0) {
|
|
3251
|
-
debug$
|
|
3530
|
+
debug$d("Removing everything"), debugState(editor, "before");
|
|
3252
3531
|
const previousSelection = editor.selection;
|
|
3253
3532
|
return Transforms.deselect(editor), editor.children.forEach((_child, i) => {
|
|
3254
3533
|
Transforms.removeNodes(editor, {
|
|
@@ -3275,13 +3554,13 @@ function unsetPatch(editor, patch) {
|
|
|
3275
3554
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3276
3555
|
if (patch.path.length === 1) {
|
|
3277
3556
|
if (!block || !blockPath)
|
|
3278
|
-
return debug$
|
|
3557
|
+
return debug$d("Block not found"), !1;
|
|
3279
3558
|
const blockIndex = blockPath[0];
|
|
3280
|
-
return debug$
|
|
3559
|
+
return debug$d(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
|
|
3281
3560
|
at: [blockIndex]
|
|
3282
3561
|
}), debugState(editor, "after"), !0;
|
|
3283
3562
|
}
|
|
3284
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
3563
|
+
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)}`), Transforms.removeNodes(editor, {
|
|
3285
3564
|
at: childPath
|
|
3286
3565
|
}), debugState(editor, "after"), !0) : !1;
|
|
3287
3566
|
}
|
|
@@ -3289,7 +3568,7 @@ function isKeyedSegment(segment) {
|
|
|
3289
3568
|
return typeof segment == "object" && "_key" in segment;
|
|
3290
3569
|
}
|
|
3291
3570
|
function debugState(editor, stateName) {
|
|
3292
|
-
debugVerbose && (debug$
|
|
3571
|
+
debugVerbose && (debug$d(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$d(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
3293
3572
|
}
|
|
3294
3573
|
function findBlockFromPath(editor, path) {
|
|
3295
3574
|
let blockIndex = -1;
|
|
@@ -3331,7 +3610,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3331
3610
|
childPath: void 0
|
|
3332
3611
|
};
|
|
3333
3612
|
}
|
|
3334
|
-
const debug$
|
|
3613
|
+
const debug$c = debugWithName("plugin:withPatches");
|
|
3335
3614
|
function createWithPatches({
|
|
3336
3615
|
editorActor,
|
|
3337
3616
|
patchFunctions,
|
|
@@ -3357,7 +3636,7 @@ function createWithPatches({
|
|
|
3357
3636
|
withoutPatching(editor, () => {
|
|
3358
3637
|
withoutSaving(editor, () => {
|
|
3359
3638
|
patches.forEach((patch) => {
|
|
3360
|
-
debug$
|
|
3639
|
+
debug$c.enabled && debug$c(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
3361
3640
|
});
|
|
3362
3641
|
});
|
|
3363
3642
|
});
|
|
@@ -3370,10 +3649,10 @@ function createWithPatches({
|
|
|
3370
3649
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
3371
3650
|
};
|
|
3372
3651
|
return subscriptions.push(() => {
|
|
3373
|
-
debug$
|
|
3652
|
+
debug$c("Subscribing to remote patches");
|
|
3374
3653
|
const sub = editorActor.on("patches", handlePatches);
|
|
3375
3654
|
return () => {
|
|
3376
|
-
debug$
|
|
3655
|
+
debug$c("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
3377
3656
|
};
|
|
3378
3657
|
}), editor.apply = (operation) => {
|
|
3379
3658
|
let patches = [];
|
|
@@ -3424,7 +3703,7 @@ function createWithPatches({
|
|
|
3424
3703
|
}, editor;
|
|
3425
3704
|
};
|
|
3426
3705
|
}
|
|
3427
|
-
const debug$
|
|
3706
|
+
const debug$b = debugWithName("plugin:withPlaceholderBlock");
|
|
3428
3707
|
function createWithPlaceholderBlock(editorActor) {
|
|
3429
3708
|
return function(editor) {
|
|
3430
3709
|
const {
|
|
@@ -3449,7 +3728,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3449
3728
|
const node = op.node;
|
|
3450
3729
|
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
3451
3730
|
const nextPath = Path.next(op.path);
|
|
3452
|
-
editor.children[nextPath[0]] || (debug$
|
|
3731
|
+
editor.children[nextPath[0]] || (debug$b("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
3453
3732
|
decorators: []
|
|
3454
3733
|
})));
|
|
3455
3734
|
}
|
|
@@ -3458,7 +3737,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3458
3737
|
}, editor;
|
|
3459
3738
|
};
|
|
3460
3739
|
}
|
|
3461
|
-
const debug$
|
|
3740
|
+
const debug$a = debugWithName("plugin:withPortableTextBlockStyle");
|
|
3462
3741
|
function createWithPortableTextBlockStyle(editorActor, types) {
|
|
3463
3742
|
const defaultStyle = types.styles[0].value;
|
|
3464
3743
|
return function(editor) {
|
|
@@ -3471,7 +3750,7 @@ function createWithPortableTextBlockStyle(editorActor, types) {
|
|
|
3471
3750
|
if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !Path.equals(path, op.path)) {
|
|
3472
3751
|
const [child] = Editor.node(editor, [op.path[0] + 1, 0]);
|
|
3473
3752
|
if (Text.isText(child) && child.text === "") {
|
|
3474
|
-
debug$
|
|
3753
|
+
debug$a(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
3475
3754
|
type: "normalizing"
|
|
3476
3755
|
}), Transforms.setNodes(editor, {
|
|
3477
3756
|
style: defaultStyle
|
|
@@ -3531,7 +3810,7 @@ function getNextSpan({
|
|
|
3531
3810
|
}
|
|
3532
3811
|
return nextSpan;
|
|
3533
3812
|
}
|
|
3534
|
-
const debug$
|
|
3813
|
+
const debug$9 = debugWithName("plugin:withPortableTextMarkModel");
|
|
3535
3814
|
function createWithPortableTextMarkModel(editorActor, types) {
|
|
3536
3815
|
return function(editor) {
|
|
3537
3816
|
const {
|
|
@@ -3545,7 +3824,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3545
3824
|
for (const [child, childPath] of children) {
|
|
3546
3825
|
const nextNode = node.children[childPath[1] + 1];
|
|
3547
3826
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3548
|
-
debug$
|
|
3827
|
+
debug$9("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3549
3828
|
type: "normalizing"
|
|
3550
3829
|
}), Transforms.mergeNodes(editor, {
|
|
3551
3830
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -3558,7 +3837,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3558
3837
|
}
|
|
3559
3838
|
}
|
|
3560
3839
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3561
|
-
debug$
|
|
3840
|
+
debug$9("Adding .markDefs to block node"), editorActor.send({
|
|
3562
3841
|
type: "normalizing"
|
|
3563
3842
|
}), Transforms.setNodes(editor, {
|
|
3564
3843
|
markDefs: []
|
|
@@ -3570,7 +3849,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3570
3849
|
return;
|
|
3571
3850
|
}
|
|
3572
3851
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3573
|
-
debug$
|
|
3852
|
+
debug$9("Adding .marks to span node"), editorActor.send({
|
|
3574
3853
|
type: "normalizing"
|
|
3575
3854
|
}), Transforms.setNodes(editor, {
|
|
3576
3855
|
marks: []
|
|
@@ -3584,7 +3863,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3584
3863
|
if (editor.isTextSpan(node)) {
|
|
3585
3864
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3586
3865
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3587
|
-
debug$
|
|
3866
|
+
debug$9("Removing annotations from empty span node"), editorActor.send({
|
|
3588
3867
|
type: "normalizing"
|
|
3589
3868
|
}), Transforms.setNodes(editor, {
|
|
3590
3869
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -3602,7 +3881,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3602
3881
|
if (editor.isTextSpan(child)) {
|
|
3603
3882
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3604
3883
|
if (orphanedAnnotations.length > 0) {
|
|
3605
|
-
debug$
|
|
3884
|
+
debug$9("Removing orphaned annotations from span node"), editorActor.send({
|
|
3606
3885
|
type: "normalizing"
|
|
3607
3886
|
}), Transforms.setNodes(editor, {
|
|
3608
3887
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3620,7 +3899,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3620
3899
|
if (editor.isTextBlock(block)) {
|
|
3621
3900
|
const decorators2 = types.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3622
3901
|
if (orphanedAnnotations.length > 0) {
|
|
3623
|
-
debug$
|
|
3902
|
+
debug$9("Removing orphaned annotations from span node"), editorActor.send({
|
|
3624
3903
|
type: "normalizing"
|
|
3625
3904
|
}), Transforms.setNodes(editor, {
|
|
3626
3905
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3638,7 +3917,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3638
3917
|
for (const markDef of markDefs)
|
|
3639
3918
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3640
3919
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3641
|
-
debug$
|
|
3920
|
+
debug$9("Removing duplicate markDefs"), editorActor.send({
|
|
3642
3921
|
type: "normalizing"
|
|
3643
3922
|
}), Transforms.setNodes(editor, {
|
|
3644
3923
|
markDefs: newMarkDefs
|
|
@@ -3653,7 +3932,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3653
3932
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3654
3933
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3655
3934
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
3656
|
-
debug$
|
|
3935
|
+
debug$9("Removing markDef not in use"), editorActor.send({
|
|
3657
3936
|
type: "normalizing"
|
|
3658
3937
|
}), Transforms.setNodes(editor, {
|
|
3659
3938
|
markDefs: newMarkDefs
|
|
@@ -3870,7 +4149,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3870
4149
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
3871
4150
|
if (editor.isTextBlock(targetBlock)) {
|
|
3872
4151
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
3873
|
-
debug$
|
|
4152
|
+
debug$9("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
3874
4153
|
markDefs: newMarkDefs
|
|
3875
4154
|
}, {
|
|
3876
4155
|
at: targetPath,
|
|
@@ -4070,7 +4349,7 @@ function createWithPortableTextSelections(editorActor, types) {
|
|
|
4070
4349
|
}, editor;
|
|
4071
4350
|
};
|
|
4072
4351
|
}
|
|
4073
|
-
const debug$
|
|
4352
|
+
const debug$8 = debugWithName("plugin:withSchemaTypes");
|
|
4074
4353
|
function createWithSchemaTypes({
|
|
4075
4354
|
editorActor,
|
|
4076
4355
|
schemaTypes
|
|
@@ -4083,7 +4362,7 @@ function createWithSchemaTypes({
|
|
|
4083
4362
|
return editor.normalizeNode = (entry) => {
|
|
4084
4363
|
const [node, path] = entry;
|
|
4085
4364
|
if (node._type === void 0 && path.length === 2) {
|
|
4086
|
-
debug$
|
|
4365
|
+
debug$8("Setting span type on text node without a type");
|
|
4087
4366
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4088
4367
|
editorActor.send({
|
|
4089
4368
|
type: "normalizing"
|
|
@@ -4099,7 +4378,7 @@ function createWithSchemaTypes({
|
|
|
4099
4378
|
return;
|
|
4100
4379
|
}
|
|
4101
4380
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
4102
|
-
debug$
|
|
4381
|
+
debug$8("Setting missing key on child node without a key");
|
|
4103
4382
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
4104
4383
|
editorActor.send({
|
|
4105
4384
|
type: "normalizing"
|
|
@@ -4116,7 +4395,7 @@ function createWithSchemaTypes({
|
|
|
4116
4395
|
}, editor;
|
|
4117
4396
|
};
|
|
4118
4397
|
}
|
|
4119
|
-
const debug$
|
|
4398
|
+
const debug$7 = debugWithName("plugin:withUtils");
|
|
4120
4399
|
function createWithUtils({
|
|
4121
4400
|
editorActor,
|
|
4122
4401
|
schemaTypes
|
|
@@ -4131,14 +4410,14 @@ function createWithUtils({
|
|
|
4131
4410
|
depth: 2
|
|
4132
4411
|
});
|
|
4133
4412
|
if (!textNode || !Text.isText(textNode) || textNode.text.length === 0) {
|
|
4134
|
-
debug$
|
|
4413
|
+
debug$7("pteExpandToWord: Can't expand to word here");
|
|
4135
4414
|
return;
|
|
4136
4415
|
}
|
|
4137
4416
|
const {
|
|
4138
4417
|
focus
|
|
4139
4418
|
} = 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);
|
|
4140
4419
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4141
|
-
debug$
|
|
4420
|
+
debug$7("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
|
|
4142
4421
|
anchor: {
|
|
4143
4422
|
...selection.anchor,
|
|
4144
4423
|
offset: newStartOffset
|
|
@@ -4150,7 +4429,7 @@ function createWithUtils({
|
|
|
4150
4429
|
});
|
|
4151
4430
|
return;
|
|
4152
4431
|
}
|
|
4153
|
-
debug$
|
|
4432
|
+
debug$7("pteExpandToWord: Can't expand to word here");
|
|
4154
4433
|
}
|
|
4155
4434
|
}, editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
4156
4435
|
_type: schemaTypes.block.name,
|
|
@@ -4196,12 +4475,12 @@ const withPlugins = (editor, options) => {
|
|
|
4196
4475
|
schemaTypes
|
|
4197
4476
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
|
|
4198
4477
|
return createWithEventListeners(editorActor, options.subscriptions)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
4199
|
-
}, debug$
|
|
4478
|
+
}, debug$6 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
4200
4479
|
function createSlateEditor(config) {
|
|
4201
4480
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
4202
4481
|
if (existingSlateEditor)
|
|
4203
|
-
return debug$
|
|
4204
|
-
debug$
|
|
4482
|
+
return debug$6("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
|
|
4483
|
+
debug$6("Creating new Slate editor instance", config.editorActor.id);
|
|
4205
4484
|
const unsubscriptions = [], subscriptions = [], instance = withPlugins(withReact(createEditor$1()), {
|
|
4206
4485
|
editorActor: config.editorActor,
|
|
4207
4486
|
subscriptions
|
|
@@ -4346,7 +4625,7 @@ function isStyleActive({
|
|
|
4346
4625
|
})];
|
|
4347
4626
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
4348
4627
|
}
|
|
4349
|
-
const debug$
|
|
4628
|
+
const debug$5 = debugWithName("API:editable");
|
|
4350
4629
|
function createEditableAPI(editor, editorActor) {
|
|
4351
4630
|
const types = editorActor.getSnapshot().context.schema;
|
|
4352
4631
|
return {
|
|
@@ -4465,7 +4744,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4465
4744
|
}], {
|
|
4466
4745
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
4467
4746
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
|
|
4468
|
-
return isSpanNode && focusNode._type !== types.span.name && (debug$
|
|
4747
|
+
return isSpanNode && focusNode._type !== types.span.name && (debug$5("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
4469
4748
|
distance: 1,
|
|
4470
4749
|
unit: "character"
|
|
4471
4750
|
})), Transforms.insertNodes(editor, child, {
|
|
@@ -4603,18 +4882,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4603
4882
|
throw new Error("Invalid range");
|
|
4604
4883
|
if (range) {
|
|
4605
4884
|
if (!options?.mode || options?.mode === "selected") {
|
|
4606
|
-
debug$
|
|
4885
|
+
debug$5("Deleting content in selection"), Transforms.delete(editor, {
|
|
4607
4886
|
at: range,
|
|
4608
4887
|
hanging: !0,
|
|
4609
4888
|
voids: !0
|
|
4610
4889
|
}), editor.onChange();
|
|
4611
4890
|
return;
|
|
4612
4891
|
}
|
|
4613
|
-
options?.mode === "blocks" && (debug$
|
|
4892
|
+
options?.mode === "blocks" && (debug$5("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
|
|
4614
4893
|
at: range,
|
|
4615
4894
|
voids: !0,
|
|
4616
4895
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
|
|
4617
|
-
})), options?.mode === "children" && (debug$
|
|
4896
|
+
})), options?.mode === "children" && (debug$5("Deleting children touched by selection"), Transforms.removeNodes(editor, {
|
|
4618
4897
|
at: range,
|
|
4619
4898
|
voids: !0,
|
|
4620
4899
|
match: (node) => node._type === types.span.name || // Text children
|
|
@@ -4748,7 +5027,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4748
5027
|
action
|
|
4749
5028
|
}) => {
|
|
4750
5029
|
const editor = action.editor;
|
|
4751
|
-
if (debug$
|
|
5030
|
+
if (debug$5("Removing annotation", action.annotation.name), !!editor.selection)
|
|
4752
5031
|
if (Range.isCollapsed(editor.selection)) {
|
|
4753
5032
|
const [block, blockPath] = Editor.node(editor, editor.selection, {
|
|
4754
5033
|
depth: 1
|
|
@@ -4879,7 +5158,11 @@ function insertBlock({
|
|
|
4879
5158
|
});
|
|
4880
5159
|
}
|
|
4881
5160
|
}
|
|
4882
|
-
const
|
|
5161
|
+
const dataTransferSetActionImplementation = ({
|
|
5162
|
+
action
|
|
5163
|
+
}) => {
|
|
5164
|
+
action.dataTransfer.setData(action.mimeType, action.data);
|
|
5165
|
+
}, insertBlockObjectActionImplementation = ({
|
|
4883
5166
|
context,
|
|
4884
5167
|
action
|
|
4885
5168
|
}) => {
|
|
@@ -4896,6 +5179,35 @@ const insertBlockObjectActionImplementation = ({
|
|
|
4896
5179
|
editor: action.editor,
|
|
4897
5180
|
schema: context.schema
|
|
4898
5181
|
});
|
|
5182
|
+
}, insertBlocksActionImplementation = ({
|
|
5183
|
+
context,
|
|
5184
|
+
action
|
|
5185
|
+
}) => {
|
|
5186
|
+
const fragment = toSlateValue(action.blocks, {
|
|
5187
|
+
schemaTypes: context.schema
|
|
5188
|
+
});
|
|
5189
|
+
if (!action.editor.selection)
|
|
5190
|
+
return;
|
|
5191
|
+
const [focusBlock, focusPath] = Editor.node(action.editor, action.editor.selection, {
|
|
5192
|
+
depth: 1
|
|
5193
|
+
});
|
|
5194
|
+
if (action.editor.isTextBlock(focusBlock) && action.editor.isTextBlock(fragment[0])) {
|
|
5195
|
+
const {
|
|
5196
|
+
markDefs
|
|
5197
|
+
} = focusBlock;
|
|
5198
|
+
isEqual(markDefs, fragment[0].markDefs) || Transforms.setNodes(action.editor, {
|
|
5199
|
+
markDefs: uniq([...fragment[0].markDefs || [], ...markDefs || []])
|
|
5200
|
+
}, {
|
|
5201
|
+
at: focusPath,
|
|
5202
|
+
mode: "lowest",
|
|
5203
|
+
voids: !1
|
|
5204
|
+
});
|
|
5205
|
+
}
|
|
5206
|
+
isEqualToEmptyEditor(action.editor.children, context.schema) ? (Transforms.splitNodes(action.editor, {
|
|
5207
|
+
at: [0, 0]
|
|
5208
|
+
}), action.editor.insertFragment(fragment), Transforms.removeNodes(action.editor, {
|
|
5209
|
+
at: [0]
|
|
5210
|
+
})) : action.editor.insertFragment(fragment);
|
|
4899
5211
|
}, insertBreakActionImplementation = ({
|
|
4900
5212
|
context,
|
|
4901
5213
|
action
|
|
@@ -5124,6 +5436,7 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5124
5436
|
}) => {
|
|
5125
5437
|
ReactEditor.blur(action.editor);
|
|
5126
5438
|
},
|
|
5439
|
+
"data transfer.set": dataTransferSetActionImplementation,
|
|
5127
5440
|
"decorator.add": addDecoratorActionImplementation,
|
|
5128
5441
|
"decorator.remove": removeDecoratorActionImplementation,
|
|
5129
5442
|
"decorator.toggle": toggleDecoratorActionImplementation,
|
|
@@ -5190,6 +5503,25 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5190
5503
|
at: range
|
|
5191
5504
|
});
|
|
5192
5505
|
},
|
|
5506
|
+
"deserialization.failure": ({
|
|
5507
|
+
action
|
|
5508
|
+
}) => {
|
|
5509
|
+
console.error(`Deserialization of ${action.mimeType} failed with reason ${action.reason}`);
|
|
5510
|
+
},
|
|
5511
|
+
"deserialization.success": ({
|
|
5512
|
+
context,
|
|
5513
|
+
action
|
|
5514
|
+
}) => {
|
|
5515
|
+
insertBlocksActionImplementation({
|
|
5516
|
+
context,
|
|
5517
|
+
action: {
|
|
5518
|
+
type: "insert.blocks",
|
|
5519
|
+
blocks: action.data,
|
|
5520
|
+
editor: action.editor
|
|
5521
|
+
}
|
|
5522
|
+
});
|
|
5523
|
+
},
|
|
5524
|
+
"insert.blocks": insertBlocksActionImplementation,
|
|
5193
5525
|
"insert.block object": insertBlockObjectActionImplementation,
|
|
5194
5526
|
"insert.break": insertBreakActionImplementation,
|
|
5195
5527
|
"insert.inline object": insertInlineObjectActionImplementation,
|
|
@@ -5301,6 +5633,23 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5301
5633
|
const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
|
|
5302
5634
|
Transforms.select(action.editor, nextBlockPath);
|
|
5303
5635
|
},
|
|
5636
|
+
"serialization.failure": ({
|
|
5637
|
+
action
|
|
5638
|
+
}) => {
|
|
5639
|
+
console.error(`Serialization of ${action.mimeType} failed with reason ${action.reason}`);
|
|
5640
|
+
},
|
|
5641
|
+
"serialization.success": ({
|
|
5642
|
+
context,
|
|
5643
|
+
action
|
|
5644
|
+
}) => {
|
|
5645
|
+
dataTransferSetActionImplementation({
|
|
5646
|
+
context,
|
|
5647
|
+
action: {
|
|
5648
|
+
...action,
|
|
5649
|
+
type: "data transfer.set"
|
|
5650
|
+
}
|
|
5651
|
+
});
|
|
5652
|
+
},
|
|
5304
5653
|
"style.toggle": toggleStyleActionImplementation,
|
|
5305
5654
|
"style.add": addStyleActionImplementation,
|
|
5306
5655
|
"style.remove": removeStyleActionImplementation,
|
|
@@ -5487,6 +5836,13 @@ function performDefaultAction({
|
|
|
5487
5836
|
});
|
|
5488
5837
|
break;
|
|
5489
5838
|
}
|
|
5839
|
+
case "data transfer.set": {
|
|
5840
|
+
behaviorActionImplementations["data transfer.set"]({
|
|
5841
|
+
context,
|
|
5842
|
+
action
|
|
5843
|
+
});
|
|
5844
|
+
break;
|
|
5845
|
+
}
|
|
5490
5846
|
case "decorator.toggle": {
|
|
5491
5847
|
behaviorActionImplementations["decorator.toggle"]({
|
|
5492
5848
|
context,
|
|
@@ -5508,6 +5864,20 @@ function performDefaultAction({
|
|
|
5508
5864
|
});
|
|
5509
5865
|
break;
|
|
5510
5866
|
}
|
|
5867
|
+
case "deserialization.failure": {
|
|
5868
|
+
behaviorActionImplementations["deserialization.failure"]({
|
|
5869
|
+
context,
|
|
5870
|
+
action
|
|
5871
|
+
});
|
|
5872
|
+
break;
|
|
5873
|
+
}
|
|
5874
|
+
case "deserialization.success": {
|
|
5875
|
+
behaviorActionImplementations["deserialization.success"]({
|
|
5876
|
+
context,
|
|
5877
|
+
action
|
|
5878
|
+
});
|
|
5879
|
+
break;
|
|
5880
|
+
}
|
|
5511
5881
|
case "focus": {
|
|
5512
5882
|
behaviorActionImplementations.focus({
|
|
5513
5883
|
context,
|
|
@@ -5515,6 +5885,13 @@ function performDefaultAction({
|
|
|
5515
5885
|
});
|
|
5516
5886
|
break;
|
|
5517
5887
|
}
|
|
5888
|
+
case "insert.blocks": {
|
|
5889
|
+
behaviorActionImplementations["insert.blocks"]({
|
|
5890
|
+
context,
|
|
5891
|
+
action
|
|
5892
|
+
});
|
|
5893
|
+
break;
|
|
5894
|
+
}
|
|
5518
5895
|
case "insert.block object": {
|
|
5519
5896
|
behaviorActionImplementations["insert.block object"]({
|
|
5520
5897
|
context,
|
|
@@ -5564,6 +5941,20 @@ function performDefaultAction({
|
|
|
5564
5941
|
});
|
|
5565
5942
|
break;
|
|
5566
5943
|
}
|
|
5944
|
+
case "serialization.failure": {
|
|
5945
|
+
behaviorActionImplementations["serialization.failure"]({
|
|
5946
|
+
context,
|
|
5947
|
+
action
|
|
5948
|
+
});
|
|
5949
|
+
break;
|
|
5950
|
+
}
|
|
5951
|
+
case "serialization.success": {
|
|
5952
|
+
behaviorActionImplementations["serialization.success"]({
|
|
5953
|
+
context,
|
|
5954
|
+
action
|
|
5955
|
+
});
|
|
5956
|
+
break;
|
|
5957
|
+
}
|
|
5567
5958
|
default:
|
|
5568
5959
|
behaviorActionImplementations["style.toggle"]({
|
|
5569
5960
|
context,
|
|
@@ -5581,6 +5972,7 @@ function getActiveDecorators({
|
|
|
5581
5972
|
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
5582
5973
|
}
|
|
5583
5974
|
function createEditorSnapshot({
|
|
5975
|
+
converters,
|
|
5584
5976
|
editor,
|
|
5585
5977
|
keyGenerator,
|
|
5586
5978
|
schema
|
|
@@ -5592,6 +5984,7 @@ function createEditorSnapshot({
|
|
|
5592
5984
|
schema,
|
|
5593
5985
|
slateEditorInstance: editor
|
|
5594
5986
|
}),
|
|
5987
|
+
converters,
|
|
5595
5988
|
keyGenerator,
|
|
5596
5989
|
schema,
|
|
5597
5990
|
selection,
|
|
@@ -5666,7 +6059,7 @@ const editorMachine = setup({
|
|
|
5666
6059
|
enqueue
|
|
5667
6060
|
}) => {
|
|
5668
6061
|
assertEvent(event, ["behavior event", "custom behavior event"]);
|
|
5669
|
-
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 : {
|
|
6062
|
+
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 : {
|
|
5670
6063
|
...event.behaviorEvent,
|
|
5671
6064
|
editor: event.editor
|
|
5672
6065
|
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values()].filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
@@ -5700,6 +6093,7 @@ const editorMachine = setup({
|
|
|
5700
6093
|
return;
|
|
5701
6094
|
}
|
|
5702
6095
|
const editorSnapshot = createEditorSnapshot({
|
|
6096
|
+
converters: [...context.converters],
|
|
5703
6097
|
editor: event.editor,
|
|
5704
6098
|
keyGenerator: context.keyGenerator,
|
|
5705
6099
|
schema: context.schema
|
|
@@ -5789,6 +6183,7 @@ const editorMachine = setup({
|
|
|
5789
6183
|
input
|
|
5790
6184
|
}) => ({
|
|
5791
6185
|
behaviors: new Set(input.behaviors ?? coreBehaviors),
|
|
6186
|
+
converters: new Set(input.converters ?? []),
|
|
5792
6187
|
keyGenerator: input.keyGenerator,
|
|
5793
6188
|
pendingEvents: [],
|
|
5794
6189
|
schema: input.schema,
|
|
@@ -5861,6 +6256,13 @@ const editorMachine = setup({
|
|
|
5861
6256
|
"update behaviors": {
|
|
5862
6257
|
actions: "assign behaviors"
|
|
5863
6258
|
},
|
|
6259
|
+
"update key generator": {
|
|
6260
|
+
actions: assign({
|
|
6261
|
+
keyGenerator: ({
|
|
6262
|
+
event
|
|
6263
|
+
}) => event.keyGenerator
|
|
6264
|
+
})
|
|
6265
|
+
},
|
|
5864
6266
|
"update schema": {
|
|
5865
6267
|
actions: "assign schema"
|
|
5866
6268
|
},
|
|
@@ -5901,6 +6303,12 @@ const editorMachine = setup({
|
|
|
5901
6303
|
},
|
|
5902
6304
|
"read only": {
|
|
5903
6305
|
on: {
|
|
6306
|
+
"behavior event": {
|
|
6307
|
+
actions: "handle behavior event",
|
|
6308
|
+
guard: ({
|
|
6309
|
+
event
|
|
6310
|
+
}) => 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"
|
|
6311
|
+
},
|
|
5904
6312
|
"update readOnly": {
|
|
5905
6313
|
guard: ({
|
|
5906
6314
|
event
|
|
@@ -6070,6 +6478,7 @@ function getEditorSnapshot({
|
|
|
6070
6478
|
}) {
|
|
6071
6479
|
return {
|
|
6072
6480
|
context: {
|
|
6481
|
+
converters: [...editorActorSnapshot.context.converters],
|
|
6073
6482
|
activeDecorators: getActiveDecorators({
|
|
6074
6483
|
schema: editorActorSnapshot.context.schema,
|
|
6075
6484
|
slateEditorInstance
|
|
@@ -6124,6 +6533,7 @@ function useCreateEditor(config) {
|
|
|
6124
6533
|
function editorConfigToMachineInput(config) {
|
|
6125
6534
|
return {
|
|
6126
6535
|
behaviors: config.behaviors,
|
|
6536
|
+
converters: coreConverters,
|
|
6127
6537
|
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
6128
6538
|
maxBlocks: config.maxBlocks,
|
|
6129
6539
|
readOnly: config.readOnly,
|
|
@@ -6169,25 +6579,25 @@ const EditorActorContext = createContext({}), PortableTextEditorSelectionContext
|
|
|
6169
6579
|
if (selection === void 0)
|
|
6170
6580
|
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
6171
6581
|
return selection;
|
|
6172
|
-
}, debug$
|
|
6582
|
+
}, debug$4 = debugWithName("component:PortableTextEditor:SelectionProvider");
|
|
6173
6583
|
function PortableTextEditorSelectionProvider(props) {
|
|
6174
6584
|
const $ = c(6), [selection, setSelection] = useState(null);
|
|
6175
6585
|
let t0, t1;
|
|
6176
6586
|
$[0] !== props.editorActor ? (t0 = () => {
|
|
6177
|
-
debug$
|
|
6587
|
+
debug$4("Subscribing to selection changes");
|
|
6178
6588
|
const subscription = props.editorActor.on("selection", (event) => {
|
|
6179
6589
|
startTransition(() => {
|
|
6180
6590
|
setSelection(event.selection);
|
|
6181
6591
|
});
|
|
6182
6592
|
});
|
|
6183
6593
|
return () => {
|
|
6184
|
-
debug$
|
|
6594
|
+
debug$4("Unsubscribing to selection changes"), subscription.unsubscribe();
|
|
6185
6595
|
};
|
|
6186
6596
|
}, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1);
|
|
6187
6597
|
let t2;
|
|
6188
6598
|
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
6189
6599
|
}
|
|
6190
|
-
const debug$
|
|
6600
|
+
const debug$3 = debugWithName("component:PortableTextEditor");
|
|
6191
6601
|
class PortableTextEditor extends Component {
|
|
6192
6602
|
static displayName = "PortableTextEditor";
|
|
6193
6603
|
/**
|
|
@@ -6249,13 +6659,13 @@ class PortableTextEditor extends Component {
|
|
|
6249
6659
|
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
6250
6660
|
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
6251
6661
|
static blur = (editor) => {
|
|
6252
|
-
debug$
|
|
6662
|
+
debug$3("Host blurred"), editor.editable?.blur();
|
|
6253
6663
|
};
|
|
6254
6664
|
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
6255
6665
|
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
6256
6666
|
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
6257
6667
|
static focus = (editor) => {
|
|
6258
|
-
debug$
|
|
6668
|
+
debug$3("Host requesting focus"), editor.editable?.focus();
|
|
6259
6669
|
};
|
|
6260
6670
|
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
6261
6671
|
static focusChild = (editor) => editor.editable?.focusChild();
|
|
@@ -6266,7 +6676,7 @@ class PortableTextEditor extends Component {
|
|
|
6266
6676
|
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
6267
6677
|
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
6268
6678
|
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
6269
|
-
static insertChild = (editor, type, value) => (debug$
|
|
6679
|
+
static insertChild = (editor, type, value) => (debug$3("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
6270
6680
|
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
6271
6681
|
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
6272
6682
|
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
@@ -6277,20 +6687,20 @@ class PortableTextEditor extends Component {
|
|
|
6277
6687
|
};
|
|
6278
6688
|
static marks = (editor) => editor.editable?.marks();
|
|
6279
6689
|
static select = (editor, selection) => {
|
|
6280
|
-
debug$
|
|
6690
|
+
debug$3("Host setting selection", selection), editor.editable?.select(selection);
|
|
6281
6691
|
};
|
|
6282
6692
|
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
6283
|
-
static toggleBlockStyle = (editor, blockStyle) => (debug$
|
|
6693
|
+
static toggleBlockStyle = (editor, blockStyle) => (debug$3("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
6284
6694
|
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
6285
6695
|
static toggleMark = (editor, mark) => {
|
|
6286
|
-
debug$
|
|
6696
|
+
debug$3("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
6287
6697
|
};
|
|
6288
|
-
static getFragment = (editor) => (debug$
|
|
6698
|
+
static getFragment = (editor) => (debug$3("Host getting fragment"), editor.editable?.getFragment());
|
|
6289
6699
|
static undo = (editor) => {
|
|
6290
|
-
debug$
|
|
6700
|
+
debug$3("Host undoing"), editor.editable?.undo();
|
|
6291
6701
|
};
|
|
6292
6702
|
static redo = (editor) => {
|
|
6293
|
-
debug$
|
|
6703
|
+
debug$3("Host redoing"), editor.editable?.redo();
|
|
6294
6704
|
};
|
|
6295
6705
|
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
6296
6706
|
}
|
|
@@ -6316,7 +6726,7 @@ function RouteEventsToChanges(props) {
|
|
|
6316
6726
|
const handleChange = useEffectEvent(t0);
|
|
6317
6727
|
let t1, t2;
|
|
6318
6728
|
return $[2] !== handleChange || $[3] !== props.editorActor ? (t1 = () => {
|
|
6319
|
-
debug$
|
|
6729
|
+
debug$3("Subscribing to editor changes");
|
|
6320
6730
|
const sub = props.editorActor.on("*", (event) => {
|
|
6321
6731
|
bb5: switch (event.type) {
|
|
6322
6732
|
case "blurred": {
|
|
@@ -6390,11 +6800,11 @@ function RouteEventsToChanges(props) {
|
|
|
6390
6800
|
}
|
|
6391
6801
|
});
|
|
6392
6802
|
return () => {
|
|
6393
|
-
debug$
|
|
6803
|
+
debug$3("Unsubscribing to changes"), sub.unsubscribe();
|
|
6394
6804
|
};
|
|
6395
6805
|
}, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2), null;
|
|
6396
6806
|
}
|
|
6397
|
-
const debug$
|
|
6807
|
+
const debug$2 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
6398
6808
|
const {
|
|
6399
6809
|
editorActor,
|
|
6400
6810
|
attributes,
|
|
@@ -6422,7 +6832,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6422
6832
|
const setSelectedFromRange = useCallback(() => {
|
|
6423
6833
|
if (!shouldTrackSelectionAndFocus)
|
|
6424
6834
|
return;
|
|
6425
|
-
debug$
|
|
6835
|
+
debug$2("Setting selection and focus from range");
|
|
6426
6836
|
const winSelection = window.getSelection();
|
|
6427
6837
|
if (!winSelection) {
|
|
6428
6838
|
setSelected(!1);
|
|
@@ -6518,7 +6928,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6518
6928
|
return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6519
6929
|
};
|
|
6520
6930
|
Leaf.displayName = "Leaf";
|
|
6521
|
-
const debug$
|
|
6931
|
+
const debug$1 = debugWithName("plugin:withHotKeys");
|
|
6522
6932
|
function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
|
|
6523
6933
|
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
|
|
6524
6934
|
return function(editor) {
|
|
@@ -6533,7 +6943,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
6533
6943
|
const possibleMark = activeHotkeys[cat];
|
|
6534
6944
|
if (possibleMark) {
|
|
6535
6945
|
const mark = possibleMark[hotkey];
|
|
6536
|
-
debug$
|
|
6946
|
+
debug$1(`HotKey ${hotkey} to toggle ${mark}`), editorActor.send({
|
|
6537
6947
|
type: "behavior event",
|
|
6538
6948
|
behaviorEvent: {
|
|
6539
6949
|
type: "decorator.toggle",
|
|
@@ -6560,204 +6970,6 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
6560
6970
|
}, editor;
|
|
6561
6971
|
};
|
|
6562
6972
|
}
|
|
6563
|
-
const debug$1 = debugWithName("plugin:withInsertData");
|
|
6564
|
-
function createWithInsertData(editorActor, schemaTypes) {
|
|
6565
|
-
return function(editor) {
|
|
6566
|
-
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(`
|
|
6567
|
-
|
|
6568
|
-
`);
|
|
6569
|
-
return editor.setFragmentData = (data, originEvent) => {
|
|
6570
|
-
const {
|
|
6571
|
-
selection
|
|
6572
|
-
} = editor;
|
|
6573
|
-
if (!selection)
|
|
6574
|
-
return;
|
|
6575
|
-
const [start, end] = Range.edges(selection), startVoid = Editor.void(editor, {
|
|
6576
|
-
at: start.path
|
|
6577
|
-
}), endVoid = Editor.void(editor, {
|
|
6578
|
-
at: end.path
|
|
6579
|
-
});
|
|
6580
|
-
if (Range.isCollapsed(selection) && !startVoid)
|
|
6581
|
-
return;
|
|
6582
|
-
const domRange = ReactEditor.toDOMRange(editor, selection);
|
|
6583
|
-
let contents = domRange.cloneContents();
|
|
6584
|
-
if (endVoid) {
|
|
6585
|
-
const [voidNode] = endVoid, r = domRange.cloneRange(), domNode = ReactEditor.toDOMNode(editor, voidNode);
|
|
6586
|
-
r.setEndAfter(domNode), contents = r.cloneContents();
|
|
6587
|
-
}
|
|
6588
|
-
Array.from(contents.querySelectorAll("[data-slate-zero-width]")).forEach((zw) => {
|
|
6589
|
-
const isNewline = zw.getAttribute("data-slate-zero-width") === "n";
|
|
6590
|
-
zw.textContent = isNewline ? `
|
|
6591
|
-
` : "";
|
|
6592
|
-
}), Array.from(contents.querySelectorAll("*")).forEach((elm) => {
|
|
6593
|
-
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");
|
|
6594
|
-
for (const key in elm.attributes)
|
|
6595
|
-
elm.hasAttribute(key) && elm.removeAttribute(key);
|
|
6596
|
-
});
|
|
6597
|
-
const div = contents.ownerDocument.createElement("div");
|
|
6598
|
-
div.appendChild(contents), div.setAttribute("hidden", "true"), contents.ownerDocument.body.appendChild(div);
|
|
6599
|
-
const asHTML = div.innerHTML;
|
|
6600
|
-
contents.ownerDocument.body.removeChild(div);
|
|
6601
|
-
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
6602
|
-
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);
|
|
6603
|
-
}, editor.insertPortableTextData = (data) => {
|
|
6604
|
-
if (!editor.selection)
|
|
6605
|
-
return !1;
|
|
6606
|
-
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
6607
|
-
if (debug$1(`Inserting portable text from ${origin} event`, pText), pText) {
|
|
6608
|
-
const parsed = JSON.parse(pText);
|
|
6609
|
-
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
6610
|
-
const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
|
|
6611
|
-
schemaTypes
|
|
6612
|
-
}), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
6613
|
-
if (!validation.valid && !validation.resolution?.autoResolve) {
|
|
6614
|
-
const errorDescription = `${validation.resolution?.description}`;
|
|
6615
|
-
return editorActor.send({
|
|
6616
|
-
type: "error",
|
|
6617
|
-
name: "pasteError",
|
|
6618
|
-
description: errorDescription,
|
|
6619
|
-
data: validation
|
|
6620
|
-
}), debug$1("Invalid insert result", validation), !1;
|
|
6621
|
-
}
|
|
6622
|
-
return _insertFragment(editor, slateValue, schemaTypes), !0;
|
|
6623
|
-
}
|
|
6624
|
-
}
|
|
6625
|
-
return !1;
|
|
6626
|
-
}, editor.insertTextOrHTMLData = (data) => {
|
|
6627
|
-
if (!editor.selection)
|
|
6628
|
-
return debug$1("No selection, not inserting"), !1;
|
|
6629
|
-
const html = data.getData("text/html"), text = data.getData("text/plain");
|
|
6630
|
-
if (html || text) {
|
|
6631
|
-
debug$1("Inserting data", data);
|
|
6632
|
-
let portableText, fragment, insertedType;
|
|
6633
|
-
if (html) {
|
|
6634
|
-
if (portableText = htmlToBlocks(html, schemaTypes.portableText, {
|
|
6635
|
-
unstable_whitespaceOnPasteMode: whitespaceOnPasteMode,
|
|
6636
|
-
keyGenerator: editorActor.getSnapshot().context.keyGenerator
|
|
6637
|
-
}), fragment = toSlateValue(portableText, {
|
|
6638
|
-
schemaTypes
|
|
6639
|
-
}), insertedType = "HTML", portableText.length === 0)
|
|
6640
|
-
return !1;
|
|
6641
|
-
} else {
|
|
6642
|
-
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>`;
|
|
6643
|
-
portableText = htmlToBlocks(textToHtml, schemaTypes.portableText, {
|
|
6644
|
-
keyGenerator: editorActor.getSnapshot().context.keyGenerator
|
|
6645
|
-
}), fragment = toSlateValue(portableText, {
|
|
6646
|
-
schemaTypes
|
|
6647
|
-
}), insertedType = "text";
|
|
6648
|
-
}
|
|
6649
|
-
const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
6650
|
-
if (!validation.valid) {
|
|
6651
|
-
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
6652
|
-
${validation.resolution?.description}
|
|
6653
|
-
Try to insert as plain text (shift-paste) instead.`;
|
|
6654
|
-
return editorActor.send({
|
|
6655
|
-
type: "error",
|
|
6656
|
-
name: "pasteError",
|
|
6657
|
-
description: errorDescription,
|
|
6658
|
-
data: validation
|
|
6659
|
-
}), debug$1("Invalid insert result", validation), !1;
|
|
6660
|
-
}
|
|
6661
|
-
return debug$1(`Inserting ${insertedType} fragment at ${JSON.stringify(editor.selection)}`), _insertFragment(editor, fragment, schemaTypes), !0;
|
|
6662
|
-
}
|
|
6663
|
-
return !1;
|
|
6664
|
-
}, editor.insertData = (data) => {
|
|
6665
|
-
editor.insertPortableTextData(data) || editor.insertTextOrHTMLData(data);
|
|
6666
|
-
}, editor.insertFragmentData = (data) => {
|
|
6667
|
-
const fragment = data.getData("application/x-portable-text");
|
|
6668
|
-
if (fragment) {
|
|
6669
|
-
const parsed = JSON.parse(fragment);
|
|
6670
|
-
return editor.insertFragment(parsed), !0;
|
|
6671
|
-
}
|
|
6672
|
-
return !1;
|
|
6673
|
-
}, editor;
|
|
6674
|
-
};
|
|
6675
|
-
}
|
|
6676
|
-
const entityMap = {
|
|
6677
|
-
"&": "&",
|
|
6678
|
-
"<": "<",
|
|
6679
|
-
">": ">",
|
|
6680
|
-
'"': """,
|
|
6681
|
-
"'": "'",
|
|
6682
|
-
"/": "/",
|
|
6683
|
-
"`": "`",
|
|
6684
|
-
"=": "="
|
|
6685
|
-
};
|
|
6686
|
-
function escapeHtml(str) {
|
|
6687
|
-
return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
|
|
6688
|
-
}
|
|
6689
|
-
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
|
|
6690
|
-
return fragment.map((node) => {
|
|
6691
|
-
const newNode = {
|
|
6692
|
-
...node
|
|
6693
|
-
};
|
|
6694
|
-
if (editor.isTextBlock(newNode)) {
|
|
6695
|
-
const annotations = editorTypes.annotations.map((t) => t.name);
|
|
6696
|
-
if (annotations.length === 0) {
|
|
6697
|
-
const {
|
|
6698
|
-
markDefs,
|
|
6699
|
-
...NewNodeNoDefs
|
|
6700
|
-
} = newNode;
|
|
6701
|
-
return {
|
|
6702
|
-
...NewNodeNoDefs,
|
|
6703
|
-
_key: keyGenerator()
|
|
6704
|
-
};
|
|
6705
|
-
}
|
|
6706
|
-
if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
|
|
6707
|
-
const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
|
|
6708
|
-
return {
|
|
6709
|
-
...newNode,
|
|
6710
|
-
markDefs: allowedAnnotations,
|
|
6711
|
-
_key: keyGenerator()
|
|
6712
|
-
};
|
|
6713
|
-
}
|
|
6714
|
-
newNode.markDefs = (newNode.markDefs || []).map((def) => {
|
|
6715
|
-
const oldKey = def._key, newKey = keyGenerator();
|
|
6716
|
-
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
6717
|
-
...child,
|
|
6718
|
-
marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
|
|
6719
|
-
} : child), {
|
|
6720
|
-
...def,
|
|
6721
|
-
_key: newKey
|
|
6722
|
-
};
|
|
6723
|
-
});
|
|
6724
|
-
}
|
|
6725
|
-
const nodeWithNewKeys = {
|
|
6726
|
-
...newNode,
|
|
6727
|
-
_key: keyGenerator()
|
|
6728
|
-
};
|
|
6729
|
-
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
|
|
6730
|
-
...child,
|
|
6731
|
-
_key: keyGenerator()
|
|
6732
|
-
}))), nodeWithNewKeys;
|
|
6733
|
-
});
|
|
6734
|
-
}
|
|
6735
|
-
function _insertFragment(editor, fragment, schemaTypes) {
|
|
6736
|
-
editor.withoutNormalizing(() => {
|
|
6737
|
-
if (!editor.selection)
|
|
6738
|
-
return;
|
|
6739
|
-
const [focusBlock, focusPath] = Editor.node(editor, editor.selection, {
|
|
6740
|
-
depth: 1
|
|
6741
|
-
});
|
|
6742
|
-
if (editor.isTextBlock(focusBlock) && editor.isTextBlock(fragment[0])) {
|
|
6743
|
-
const {
|
|
6744
|
-
markDefs
|
|
6745
|
-
} = focusBlock;
|
|
6746
|
-
debug$1("Mixing markDefs of focusBlock and fragments[0] block", markDefs, fragment[0].markDefs), isEqual(markDefs, fragment[0].markDefs) || Transforms.setNodes(editor, {
|
|
6747
|
-
markDefs: uniq([...fragment[0].markDefs || [], ...markDefs || []])
|
|
6748
|
-
}, {
|
|
6749
|
-
at: focusPath,
|
|
6750
|
-
mode: "lowest",
|
|
6751
|
-
voids: !1
|
|
6752
|
-
});
|
|
6753
|
-
}
|
|
6754
|
-
isEqualToEmptyEditor(editor.children, schemaTypes) ? (Transforms.splitNodes(editor, {
|
|
6755
|
-
at: [0, 0]
|
|
6756
|
-
}), editor.insertFragment(fragment), Transforms.removeNodes(editor, {
|
|
6757
|
-
at: [0]
|
|
6758
|
-
})) : editor.insertFragment(fragment);
|
|
6759
|
-
}), editor.onChange();
|
|
6760
|
-
}
|
|
6761
6973
|
function withSyncRangeDecorations({
|
|
6762
6974
|
editorActor,
|
|
6763
6975
|
slateEditor,
|
|
@@ -6805,12 +7017,11 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6805
7017
|
"edit mode": "read only"
|
|
6806
7018
|
})), schemaTypes = useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = useSlate(), blockTypeName = schemaTypes.block.name;
|
|
6807
7019
|
useMemo(() => {
|
|
6808
|
-
const withInsertData = createWithInsertData(editorActor, schemaTypes);
|
|
6809
7020
|
if (readOnly)
|
|
6810
|
-
return debug("Editable is in read only mode"),
|
|
7021
|
+
return debug("Editable is in read only mode"), slateEditor;
|
|
6811
7022
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
6812
|
-
return debug("Editable is in edit mode"),
|
|
6813
|
-
}, [editorActor, hotkeys, portableTextEditor, readOnly,
|
|
7023
|
+
return debug("Editable is in edit mode"), withHotKeys(slateEditor);
|
|
7024
|
+
}, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
|
|
6814
7025
|
const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((lProps) => {
|
|
6815
7026
|
if (lProps.leaf._type === "span") {
|
|
6816
7027
|
let rendered = /* @__PURE__ */ jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|