@portabletext/editor 1.23.0 → 1.25.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 +249 -62
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.is-selection-collapsed.cjs → selector.is-active-style.cjs} +158 -3
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs +23 -9
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +225 -38
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/{selector.is-selection-collapsed.js → selector.is-active-style.js} +159 -4
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +23 -9
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.cjs +27 -27
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +2830 -139
- package/lib/behaviors/index.d.ts +2830 -139
- package/lib/behaviors/index.js +1 -1
- package/lib/index.cjs +695 -526
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +8950 -246
- package/lib/index.d.ts +8950 -246
- package/lib/index.js +696 -525
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +24 -171
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +73 -0
- package/lib/selectors/index.d.ts +73 -0
- package/lib/selectors/index.js +3 -151
- package/lib/selectors/index.js.map +1 -1
- package/package.json +11 -10
- 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 +159 -83
- package/src/behaviors/behavior.core.annotations.ts +29 -0
- package/src/behaviors/behavior.core.block-objects.ts +13 -13
- package/src/behaviors/behavior.core.decorators.ts +19 -0
- package/src/behaviors/behavior.core.deserialize.ts +46 -0
- package/src/behaviors/behavior.core.lists.ts +57 -23
- package/src/behaviors/behavior.core.serialize.ts +44 -0
- package/src/behaviors/behavior.core.style.ts +19 -0
- package/src/behaviors/behavior.core.ts +19 -0
- package/src/behaviors/behavior.types.ts +126 -89
- 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 +48 -6
- package/src/editor/editor-machine.ts +56 -2
- 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 +82 -106
- 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 +87 -0
- package/src/utils/util.slice-blocks.ts +27 -10
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selection-collapsed.js.map +0 -1
- 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,14 +17,16 @@ 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";
|
|
23
|
-
import { createGuards } from "./_chunks-es/selector.is-
|
|
26
|
+
import { createGuards } from "./_chunks-es/selector.is-active-style.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) {
|
|
@@ -2757,123 +3003,54 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2757
3003
|
subscriptions.push(() => {
|
|
2758
3004
|
const subscription = editorActor.on("*", (event) => {
|
|
2759
3005
|
switch (event.type) {
|
|
2760
|
-
case "
|
|
2761
|
-
editorActor.send({
|
|
2762
|
-
type: "behavior event",
|
|
2763
|
-
behaviorEvent: {
|
|
2764
|
-
type: "annotation.add",
|
|
2765
|
-
annotation: event.annotation
|
|
2766
|
-
},
|
|
2767
|
-
editor
|
|
2768
|
-
});
|
|
2769
|
-
break;
|
|
2770
|
-
}
|
|
2771
|
-
case "annotation.remove": {
|
|
2772
|
-
editorActor.send({
|
|
2773
|
-
type: "behavior event",
|
|
2774
|
-
behaviorEvent: {
|
|
2775
|
-
type: "annotation.remove",
|
|
2776
|
-
annotation: event.annotation
|
|
2777
|
-
},
|
|
2778
|
-
editor
|
|
2779
|
-
});
|
|
2780
|
-
break;
|
|
2781
|
-
}
|
|
2782
|
-
case "blur": {
|
|
2783
|
-
editorActor.send({
|
|
2784
|
-
type: "behavior event",
|
|
2785
|
-
behaviorEvent: {
|
|
2786
|
-
type: "blur"
|
|
2787
|
-
},
|
|
2788
|
-
editor
|
|
2789
|
-
});
|
|
2790
|
-
break;
|
|
2791
|
-
}
|
|
2792
|
-
case "custom.*": {
|
|
3006
|
+
case "custom.*":
|
|
2793
3007
|
editorActor.send({
|
|
2794
3008
|
type: "custom behavior event",
|
|
2795
3009
|
behaviorEvent: event.event,
|
|
2796
3010
|
editor
|
|
2797
3011
|
});
|
|
2798
3012
|
break;
|
|
2799
|
-
|
|
2800
|
-
case "
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
case "
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
case "
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
case "
|
|
3013
|
+
case "annotation.add":
|
|
3014
|
+
case "annotation.remove":
|
|
3015
|
+
case "annotation.toggle":
|
|
3016
|
+
case "blur":
|
|
3017
|
+
case "data transfer.set":
|
|
3018
|
+
case "decorator.add":
|
|
3019
|
+
case "decorator.remove":
|
|
3020
|
+
case "decorator.toggle":
|
|
3021
|
+
case "delete.backward":
|
|
3022
|
+
case "delete.block":
|
|
3023
|
+
case "delete.forward":
|
|
3024
|
+
case "delete.text":
|
|
3025
|
+
case "deserialization.failure":
|
|
3026
|
+
case "deserialization.success":
|
|
3027
|
+
case "focus":
|
|
3028
|
+
case "insert.block object":
|
|
3029
|
+
case "insert.inline object":
|
|
3030
|
+
case "insert.span":
|
|
3031
|
+
case "insert.text block":
|
|
3032
|
+
case "list item.add":
|
|
3033
|
+
case "list item.remove":
|
|
3034
|
+
case "list item.toggle":
|
|
3035
|
+
case "move.block":
|
|
3036
|
+
case "move.block down":
|
|
3037
|
+
case "move.block up":
|
|
3038
|
+
case "select":
|
|
3039
|
+
case "select.next block":
|
|
3040
|
+
case "select.previous block":
|
|
3041
|
+
case "serialization.failure":
|
|
3042
|
+
case "serialization.success":
|
|
3043
|
+
case "style.add":
|
|
3044
|
+
case "style.remove":
|
|
3045
|
+
case "style.toggle":
|
|
3046
|
+
case "text block.set":
|
|
3047
|
+
case "text block.unset":
|
|
2834
3048
|
editorActor.send({
|
|
2835
3049
|
type: "behavior event",
|
|
2836
|
-
behaviorEvent:
|
|
2837
|
-
type: "insert.inline object",
|
|
2838
|
-
inlineObject: event.inlineObject
|
|
2839
|
-
},
|
|
3050
|
+
behaviorEvent: event,
|
|
2840
3051
|
editor
|
|
2841
3052
|
});
|
|
2842
3053
|
break;
|
|
2843
|
-
}
|
|
2844
|
-
case "list item.toggle": {
|
|
2845
|
-
editorActor.send({
|
|
2846
|
-
type: "behavior event",
|
|
2847
|
-
behaviorEvent: {
|
|
2848
|
-
type: "list item.toggle",
|
|
2849
|
-
listItem: event.listItem
|
|
2850
|
-
},
|
|
2851
|
-
editor
|
|
2852
|
-
});
|
|
2853
|
-
break;
|
|
2854
|
-
}
|
|
2855
|
-
case "select": {
|
|
2856
|
-
editorActor.send({
|
|
2857
|
-
type: "behavior event",
|
|
2858
|
-
behaviorEvent: {
|
|
2859
|
-
type: "select",
|
|
2860
|
-
selection: event.selection
|
|
2861
|
-
},
|
|
2862
|
-
editor
|
|
2863
|
-
});
|
|
2864
|
-
break;
|
|
2865
|
-
}
|
|
2866
|
-
case "style.toggle": {
|
|
2867
|
-
editorActor.send({
|
|
2868
|
-
type: "behavior event",
|
|
2869
|
-
behaviorEvent: {
|
|
2870
|
-
type: "style.toggle",
|
|
2871
|
-
style: event.style
|
|
2872
|
-
},
|
|
2873
|
-
editor
|
|
2874
|
-
});
|
|
2875
|
-
break;
|
|
2876
|
-
}
|
|
2877
3054
|
}
|
|
2878
3055
|
});
|
|
2879
3056
|
return () => {
|
|
@@ -2884,9 +3061,11 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2884
3061
|
deleteBackward: deleteBackward2,
|
|
2885
3062
|
deleteForward: deleteForward2,
|
|
2886
3063
|
insertBreak,
|
|
3064
|
+
insertData,
|
|
2887
3065
|
insertSoftBreak,
|
|
2888
3066
|
insertText: insertText2,
|
|
2889
|
-
select
|
|
3067
|
+
select,
|
|
3068
|
+
setFragmentData
|
|
2890
3069
|
} = editor;
|
|
2891
3070
|
return editor.deleteBackward = (unit) => {
|
|
2892
3071
|
if (isApplyingBehaviorActions(editor)) {
|
|
@@ -2926,6 +3105,19 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2926
3105
|
},
|
|
2927
3106
|
editor
|
|
2928
3107
|
});
|
|
3108
|
+
}, editor.insertData = (dataTransfer) => {
|
|
3109
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
3110
|
+
insertData(dataTransfer);
|
|
3111
|
+
return;
|
|
3112
|
+
}
|
|
3113
|
+
editorActor.send({
|
|
3114
|
+
type: "behavior event",
|
|
3115
|
+
behaviorEvent: {
|
|
3116
|
+
type: "deserialize",
|
|
3117
|
+
dataTransfer
|
|
3118
|
+
},
|
|
3119
|
+
editor
|
|
3120
|
+
});
|
|
2929
3121
|
}, editor.insertSoftBreak = () => {
|
|
2930
3122
|
if (isApplyingBehaviorActions(editor)) {
|
|
2931
3123
|
insertSoftBreak();
|
|
@@ -2972,6 +3164,24 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2972
3164
|
select(location);
|
|
2973
3165
|
}
|
|
2974
3166
|
});
|
|
3167
|
+
}, editor.setFragmentData = (dataTransfer, originEvent) => {
|
|
3168
|
+
if (originEvent === "drag") {
|
|
3169
|
+
setFragmentData(dataTransfer);
|
|
3170
|
+
return;
|
|
3171
|
+
}
|
|
3172
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
3173
|
+
setFragmentData(dataTransfer);
|
|
3174
|
+
return;
|
|
3175
|
+
}
|
|
3176
|
+
dataTransfer.clearData(), editorActor.send({
|
|
3177
|
+
type: "behavior event",
|
|
3178
|
+
behaviorEvent: {
|
|
3179
|
+
type: "serialize",
|
|
3180
|
+
dataTransfer,
|
|
3181
|
+
originEvent: originEvent ?? "unknown"
|
|
3182
|
+
},
|
|
3183
|
+
editor
|
|
3184
|
+
});
|
|
2975
3185
|
}, editor;
|
|
2976
3186
|
};
|
|
2977
3187
|
}
|
|
@@ -3069,13 +3279,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3069
3279
|
}, editor;
|
|
3070
3280
|
};
|
|
3071
3281
|
}
|
|
3072
|
-
const debug$
|
|
3282
|
+
const debug$d = debugWithName("applyPatches"), debugVerbose = debug$d.enabled && !0;
|
|
3073
3283
|
function createApplyPatch(schemaTypes) {
|
|
3074
3284
|
return (editor, patch) => {
|
|
3075
3285
|
let changed = !1;
|
|
3076
|
-
debugVerbose && (debug$
|
|
3286
|
+
debugVerbose && (debug$d(`
|
|
3077
3287
|
|
|
3078
|
-
NEW PATCH =============================================================`), debug$
|
|
3288
|
+
NEW PATCH =============================================================`), debug$d(JSON.stringify(patch, null, 2)));
|
|
3079
3289
|
try {
|
|
3080
3290
|
switch (patch.type) {
|
|
3081
3291
|
case "insert":
|
|
@@ -3091,7 +3301,7 @@ NEW PATCH =============================================================`), debug
|
|
|
3091
3301
|
changed = diffMatchPatch(editor, patch);
|
|
3092
3302
|
break;
|
|
3093
3303
|
default:
|
|
3094
|
-
debug$
|
|
3304
|
+
debug$d("Unhandled patch", patch.type);
|
|
3095
3305
|
}
|
|
3096
3306
|
} catch (err) {
|
|
3097
3307
|
console.error(err);
|
|
@@ -3106,9 +3316,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
3106
3316
|
childPath
|
|
3107
3317
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3108
3318
|
if (!block)
|
|
3109
|
-
return debug$
|
|
3319
|
+
return debug$d("Block not found"), !1;
|
|
3110
3320
|
if (!child || !childPath)
|
|
3111
|
-
return debug$
|
|
3321
|
+
return debug$d("Child not found"), !1;
|
|
3112
3322
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !Text.isText(child))
|
|
3113
3323
|
return !1;
|
|
3114
3324
|
const patches = parse(patch.value), [newValue] = apply(patches, child.text, {
|
|
@@ -3138,9 +3348,9 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3138
3348
|
childPath: targetChildPath
|
|
3139
3349
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3140
3350
|
if (!targetBlock || !targetBlockPath)
|
|
3141
|
-
return debug$
|
|
3351
|
+
return debug$d("Block not found"), !1;
|
|
3142
3352
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
3143
|
-
return debug$
|
|
3353
|
+
return debug$d("Ignoring patch targeting void value"), !1;
|
|
3144
3354
|
if (patch.path.length === 1) {
|
|
3145
3355
|
const {
|
|
3146
3356
|
items: items2,
|
|
@@ -3148,7 +3358,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3148
3358
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
3149
3359
|
schemaTypes
|
|
3150
3360
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
3151
|
-
return debug$
|
|
3361
|
+
return debug$d(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
|
|
3152
3362
|
at: [normalizedIdx2]
|
|
3153
3363
|
}), debugState(editor, "after"), !0;
|
|
3154
3364
|
}
|
|
@@ -3157,14 +3367,14 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3157
3367
|
position
|
|
3158
3368
|
} = patch;
|
|
3159
3369
|
if (!targetChild || !targetChildPath)
|
|
3160
|
-
return debug$
|
|
3370
|
+
return debug$d("Child not found"), !1;
|
|
3161
3371
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3162
3372
|
...targetBlock,
|
|
3163
3373
|
children: items
|
|
3164
3374
|
}], {
|
|
3165
3375
|
schemaTypes
|
|
3166
3376
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3167
|
-
return debug$
|
|
3377
|
+
return debug$d(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
3168
3378
|
at: childInsertPath
|
|
3169
3379
|
}), debugState(editor, "after"), !0;
|
|
3170
3380
|
}
|
|
@@ -3178,14 +3388,14 @@ function setPatch(editor, patch) {
|
|
|
3178
3388
|
childPath
|
|
3179
3389
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3180
3390
|
if (!block)
|
|
3181
|
-
return debug$
|
|
3391
|
+
return debug$d("Block not found"), !1;
|
|
3182
3392
|
const isTextBlock = editor.isTextBlock(block);
|
|
3183
3393
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
3184
|
-
return debug$
|
|
3394
|
+
return debug$d("Ignoring setting void value"), !1;
|
|
3185
3395
|
if (debugState(editor, "before"), isTextBlock && child && childPath) {
|
|
3186
3396
|
if (Text.isText(value) && Text.isText(child)) {
|
|
3187
3397
|
const newText = child.text;
|
|
3188
|
-
value.text !== newText && (debug$
|
|
3398
|
+
value.text !== newText && (debug$d("Setting text property"), editor.apply({
|
|
3189
3399
|
type: "remove_text",
|
|
3190
3400
|
path: childPath,
|
|
3191
3401
|
offset: 0,
|
|
@@ -3197,7 +3407,7 @@ function setPatch(editor, patch) {
|
|
|
3197
3407
|
text: value.text
|
|
3198
3408
|
}), editor.onChange());
|
|
3199
3409
|
} else
|
|
3200
|
-
debug$
|
|
3410
|
+
debug$d("Setting non-text property"), editor.apply({
|
|
3201
3411
|
type: "set_node",
|
|
3202
3412
|
path: childPath,
|
|
3203
3413
|
properties: {},
|
|
@@ -3205,7 +3415,7 @@ function setPatch(editor, patch) {
|
|
|
3205
3415
|
});
|
|
3206
3416
|
return !0;
|
|
3207
3417
|
} else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3208
|
-
debug$
|
|
3418
|
+
debug$d("Setting block property");
|
|
3209
3419
|
const {
|
|
3210
3420
|
children,
|
|
3211
3421
|
...nextRest
|
|
@@ -3222,7 +3432,7 @@ function setPatch(editor, patch) {
|
|
|
3222
3432
|
...prevRest
|
|
3223
3433
|
},
|
|
3224
3434
|
newProperties: nextRest
|
|
3225
|
-
}), debug$
|
|
3435
|
+
}), debug$d("Setting children"), block.children.forEach((c2, cIndex) => {
|
|
3226
3436
|
editor.apply({
|
|
3227
3437
|
type: "remove_node",
|
|
3228
3438
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -3248,7 +3458,7 @@ function setPatch(editor, patch) {
|
|
|
3248
3458
|
}
|
|
3249
3459
|
function unsetPatch(editor, patch) {
|
|
3250
3460
|
if (patch.path.length === 0) {
|
|
3251
|
-
debug$
|
|
3461
|
+
debug$d("Removing everything"), debugState(editor, "before");
|
|
3252
3462
|
const previousSelection = editor.selection;
|
|
3253
3463
|
return Transforms.deselect(editor), editor.children.forEach((_child, i) => {
|
|
3254
3464
|
Transforms.removeNodes(editor, {
|
|
@@ -3275,13 +3485,13 @@ function unsetPatch(editor, patch) {
|
|
|
3275
3485
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3276
3486
|
if (patch.path.length === 1) {
|
|
3277
3487
|
if (!block || !blockPath)
|
|
3278
|
-
return debug$
|
|
3488
|
+
return debug$d("Block not found"), !1;
|
|
3279
3489
|
const blockIndex = blockPath[0];
|
|
3280
|
-
return debug$
|
|
3490
|
+
return debug$d(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
|
|
3281
3491
|
at: [blockIndex]
|
|
3282
3492
|
}), debugState(editor, "after"), !0;
|
|
3283
3493
|
}
|
|
3284
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
3494
|
+
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
3495
|
at: childPath
|
|
3286
3496
|
}), debugState(editor, "after"), !0) : !1;
|
|
3287
3497
|
}
|
|
@@ -3289,7 +3499,7 @@ function isKeyedSegment(segment) {
|
|
|
3289
3499
|
return typeof segment == "object" && "_key" in segment;
|
|
3290
3500
|
}
|
|
3291
3501
|
function debugState(editor, stateName) {
|
|
3292
|
-
debugVerbose && (debug$
|
|
3502
|
+
debugVerbose && (debug$d(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$d(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
3293
3503
|
}
|
|
3294
3504
|
function findBlockFromPath(editor, path) {
|
|
3295
3505
|
let blockIndex = -1;
|
|
@@ -3331,7 +3541,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3331
3541
|
childPath: void 0
|
|
3332
3542
|
};
|
|
3333
3543
|
}
|
|
3334
|
-
const debug$
|
|
3544
|
+
const debug$c = debugWithName("plugin:withPatches");
|
|
3335
3545
|
function createWithPatches({
|
|
3336
3546
|
editorActor,
|
|
3337
3547
|
patchFunctions,
|
|
@@ -3357,7 +3567,7 @@ function createWithPatches({
|
|
|
3357
3567
|
withoutPatching(editor, () => {
|
|
3358
3568
|
withoutSaving(editor, () => {
|
|
3359
3569
|
patches.forEach((patch) => {
|
|
3360
|
-
debug$
|
|
3570
|
+
debug$c.enabled && debug$c(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
3361
3571
|
});
|
|
3362
3572
|
});
|
|
3363
3573
|
});
|
|
@@ -3370,10 +3580,10 @@ function createWithPatches({
|
|
|
3370
3580
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
3371
3581
|
};
|
|
3372
3582
|
return subscriptions.push(() => {
|
|
3373
|
-
debug$
|
|
3583
|
+
debug$c("Subscribing to remote patches");
|
|
3374
3584
|
const sub = editorActor.on("patches", handlePatches);
|
|
3375
3585
|
return () => {
|
|
3376
|
-
debug$
|
|
3586
|
+
debug$c("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
3377
3587
|
};
|
|
3378
3588
|
}), editor.apply = (operation) => {
|
|
3379
3589
|
let patches = [];
|
|
@@ -3424,7 +3634,7 @@ function createWithPatches({
|
|
|
3424
3634
|
}, editor;
|
|
3425
3635
|
};
|
|
3426
3636
|
}
|
|
3427
|
-
const debug$
|
|
3637
|
+
const debug$b = debugWithName("plugin:withPlaceholderBlock");
|
|
3428
3638
|
function createWithPlaceholderBlock(editorActor) {
|
|
3429
3639
|
return function(editor) {
|
|
3430
3640
|
const {
|
|
@@ -3449,7 +3659,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3449
3659
|
const node = op.node;
|
|
3450
3660
|
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
3451
3661
|
const nextPath = Path.next(op.path);
|
|
3452
|
-
editor.children[nextPath[0]] || (debug$
|
|
3662
|
+
editor.children[nextPath[0]] || (debug$b("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
3453
3663
|
decorators: []
|
|
3454
3664
|
})));
|
|
3455
3665
|
}
|
|
@@ -3458,7 +3668,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3458
3668
|
}, editor;
|
|
3459
3669
|
};
|
|
3460
3670
|
}
|
|
3461
|
-
const debug$
|
|
3671
|
+
const debug$a = debugWithName("plugin:withPortableTextBlockStyle");
|
|
3462
3672
|
function createWithPortableTextBlockStyle(editorActor, types) {
|
|
3463
3673
|
const defaultStyle = types.styles[0].value;
|
|
3464
3674
|
return function(editor) {
|
|
@@ -3471,7 +3681,7 @@ function createWithPortableTextBlockStyle(editorActor, types) {
|
|
|
3471
3681
|
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
3682
|
const [child] = Editor.node(editor, [op.path[0] + 1, 0]);
|
|
3473
3683
|
if (Text.isText(child) && child.text === "") {
|
|
3474
|
-
debug$
|
|
3684
|
+
debug$a(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
3475
3685
|
type: "normalizing"
|
|
3476
3686
|
}), Transforms.setNodes(editor, {
|
|
3477
3687
|
style: defaultStyle
|
|
@@ -3531,7 +3741,7 @@ function getNextSpan({
|
|
|
3531
3741
|
}
|
|
3532
3742
|
return nextSpan;
|
|
3533
3743
|
}
|
|
3534
|
-
const debug$
|
|
3744
|
+
const debug$9 = debugWithName("plugin:withPortableTextMarkModel");
|
|
3535
3745
|
function createWithPortableTextMarkModel(editorActor, types) {
|
|
3536
3746
|
return function(editor) {
|
|
3537
3747
|
const {
|
|
@@ -3545,7 +3755,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3545
3755
|
for (const [child, childPath] of children) {
|
|
3546
3756
|
const nextNode = node.children[childPath[1] + 1];
|
|
3547
3757
|
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$
|
|
3758
|
+
debug$9("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3549
3759
|
type: "normalizing"
|
|
3550
3760
|
}), Transforms.mergeNodes(editor, {
|
|
3551
3761
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -3558,7 +3768,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3558
3768
|
}
|
|
3559
3769
|
}
|
|
3560
3770
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3561
|
-
debug$
|
|
3771
|
+
debug$9("Adding .markDefs to block node"), editorActor.send({
|
|
3562
3772
|
type: "normalizing"
|
|
3563
3773
|
}), Transforms.setNodes(editor, {
|
|
3564
3774
|
markDefs: []
|
|
@@ -3570,7 +3780,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3570
3780
|
return;
|
|
3571
3781
|
}
|
|
3572
3782
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3573
|
-
debug$
|
|
3783
|
+
debug$9("Adding .marks to span node"), editorActor.send({
|
|
3574
3784
|
type: "normalizing"
|
|
3575
3785
|
}), Transforms.setNodes(editor, {
|
|
3576
3786
|
marks: []
|
|
@@ -3584,7 +3794,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3584
3794
|
if (editor.isTextSpan(node)) {
|
|
3585
3795
|
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
3796
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3587
|
-
debug$
|
|
3797
|
+
debug$9("Removing annotations from empty span node"), editorActor.send({
|
|
3588
3798
|
type: "normalizing"
|
|
3589
3799
|
}), Transforms.setNodes(editor, {
|
|
3590
3800
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -3602,7 +3812,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3602
3812
|
if (editor.isTextSpan(child)) {
|
|
3603
3813
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3604
3814
|
if (orphanedAnnotations.length > 0) {
|
|
3605
|
-
debug$
|
|
3815
|
+
debug$9("Removing orphaned annotations from span node"), editorActor.send({
|
|
3606
3816
|
type: "normalizing"
|
|
3607
3817
|
}), Transforms.setNodes(editor, {
|
|
3608
3818
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3620,7 +3830,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3620
3830
|
if (editor.isTextBlock(block)) {
|
|
3621
3831
|
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
3832
|
if (orphanedAnnotations.length > 0) {
|
|
3623
|
-
debug$
|
|
3833
|
+
debug$9("Removing orphaned annotations from span node"), editorActor.send({
|
|
3624
3834
|
type: "normalizing"
|
|
3625
3835
|
}), Transforms.setNodes(editor, {
|
|
3626
3836
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3638,7 +3848,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3638
3848
|
for (const markDef of markDefs)
|
|
3639
3849
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3640
3850
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3641
|
-
debug$
|
|
3851
|
+
debug$9("Removing duplicate markDefs"), editorActor.send({
|
|
3642
3852
|
type: "normalizing"
|
|
3643
3853
|
}), Transforms.setNodes(editor, {
|
|
3644
3854
|
markDefs: newMarkDefs
|
|
@@ -3653,7 +3863,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3653
3863
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3654
3864
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3655
3865
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
3656
|
-
debug$
|
|
3866
|
+
debug$9("Removing markDef not in use"), editorActor.send({
|
|
3657
3867
|
type: "normalizing"
|
|
3658
3868
|
}), Transforms.setNodes(editor, {
|
|
3659
3869
|
markDefs: newMarkDefs
|
|
@@ -3870,7 +4080,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3870
4080
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
3871
4081
|
if (editor.isTextBlock(targetBlock)) {
|
|
3872
4082
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
3873
|
-
debug$
|
|
4083
|
+
debug$9("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
3874
4084
|
markDefs: newMarkDefs
|
|
3875
4085
|
}, {
|
|
3876
4086
|
at: targetPath,
|
|
@@ -4070,7 +4280,7 @@ function createWithPortableTextSelections(editorActor, types) {
|
|
|
4070
4280
|
}, editor;
|
|
4071
4281
|
};
|
|
4072
4282
|
}
|
|
4073
|
-
const debug$
|
|
4283
|
+
const debug$8 = debugWithName("plugin:withSchemaTypes");
|
|
4074
4284
|
function createWithSchemaTypes({
|
|
4075
4285
|
editorActor,
|
|
4076
4286
|
schemaTypes
|
|
@@ -4083,7 +4293,7 @@ function createWithSchemaTypes({
|
|
|
4083
4293
|
return editor.normalizeNode = (entry) => {
|
|
4084
4294
|
const [node, path] = entry;
|
|
4085
4295
|
if (node._type === void 0 && path.length === 2) {
|
|
4086
|
-
debug$
|
|
4296
|
+
debug$8("Setting span type on text node without a type");
|
|
4087
4297
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4088
4298
|
editorActor.send({
|
|
4089
4299
|
type: "normalizing"
|
|
@@ -4099,7 +4309,7 @@ function createWithSchemaTypes({
|
|
|
4099
4309
|
return;
|
|
4100
4310
|
}
|
|
4101
4311
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
4102
|
-
debug$
|
|
4312
|
+
debug$8("Setting missing key on child node without a key");
|
|
4103
4313
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
4104
4314
|
editorActor.send({
|
|
4105
4315
|
type: "normalizing"
|
|
@@ -4116,7 +4326,7 @@ function createWithSchemaTypes({
|
|
|
4116
4326
|
}, editor;
|
|
4117
4327
|
};
|
|
4118
4328
|
}
|
|
4119
|
-
const debug$
|
|
4329
|
+
const debug$7 = debugWithName("plugin:withUtils");
|
|
4120
4330
|
function createWithUtils({
|
|
4121
4331
|
editorActor,
|
|
4122
4332
|
schemaTypes
|
|
@@ -4131,14 +4341,14 @@ function createWithUtils({
|
|
|
4131
4341
|
depth: 2
|
|
4132
4342
|
});
|
|
4133
4343
|
if (!textNode || !Text.isText(textNode) || textNode.text.length === 0) {
|
|
4134
|
-
debug$
|
|
4344
|
+
debug$7("pteExpandToWord: Can't expand to word here");
|
|
4135
4345
|
return;
|
|
4136
4346
|
}
|
|
4137
4347
|
const {
|
|
4138
4348
|
focus
|
|
4139
4349
|
} = 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
4350
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4141
|
-
debug$
|
|
4351
|
+
debug$7("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
|
|
4142
4352
|
anchor: {
|
|
4143
4353
|
...selection.anchor,
|
|
4144
4354
|
offset: newStartOffset
|
|
@@ -4150,7 +4360,7 @@ function createWithUtils({
|
|
|
4150
4360
|
});
|
|
4151
4361
|
return;
|
|
4152
4362
|
}
|
|
4153
|
-
debug$
|
|
4363
|
+
debug$7("pteExpandToWord: Can't expand to word here");
|
|
4154
4364
|
}
|
|
4155
4365
|
}, editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
4156
4366
|
_type: schemaTypes.block.name,
|
|
@@ -4196,12 +4406,12 @@ const withPlugins = (editor, options) => {
|
|
|
4196
4406
|
schemaTypes
|
|
4197
4407
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
|
|
4198
4408
|
return createWithEventListeners(editorActor, options.subscriptions)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
4199
|
-
}, debug$
|
|
4409
|
+
}, debug$6 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
4200
4410
|
function createSlateEditor(config) {
|
|
4201
4411
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
4202
4412
|
if (existingSlateEditor)
|
|
4203
|
-
return debug$
|
|
4204
|
-
debug$
|
|
4413
|
+
return debug$6("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
|
|
4414
|
+
debug$6("Creating new Slate editor instance", config.editorActor.id);
|
|
4205
4415
|
const unsubscriptions = [], subscriptions = [], instance = withPlugins(withReact(createEditor$1()), {
|
|
4206
4416
|
editorActor: config.editorActor,
|
|
4207
4417
|
subscriptions
|
|
@@ -4346,7 +4556,7 @@ function isStyleActive({
|
|
|
4346
4556
|
})];
|
|
4347
4557
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
4348
4558
|
}
|
|
4349
|
-
const debug$
|
|
4559
|
+
const debug$5 = debugWithName("API:editable");
|
|
4350
4560
|
function createEditableAPI(editor, editorActor) {
|
|
4351
4561
|
const types = editorActor.getSnapshot().context.schema;
|
|
4352
4562
|
return {
|
|
@@ -4465,7 +4675,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4465
4675
|
}], {
|
|
4466
4676
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
4467
4677
|
})[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$
|
|
4678
|
+
return isSpanNode && focusNode._type !== types.span.name && (debug$5("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
4469
4679
|
distance: 1,
|
|
4470
4680
|
unit: "character"
|
|
4471
4681
|
})), Transforms.insertNodes(editor, child, {
|
|
@@ -4603,18 +4813,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4603
4813
|
throw new Error("Invalid range");
|
|
4604
4814
|
if (range) {
|
|
4605
4815
|
if (!options?.mode || options?.mode === "selected") {
|
|
4606
|
-
debug$
|
|
4816
|
+
debug$5("Deleting content in selection"), Transforms.delete(editor, {
|
|
4607
4817
|
at: range,
|
|
4608
4818
|
hanging: !0,
|
|
4609
4819
|
voids: !0
|
|
4610
4820
|
}), editor.onChange();
|
|
4611
4821
|
return;
|
|
4612
4822
|
}
|
|
4613
|
-
options?.mode === "blocks" && (debug$
|
|
4823
|
+
options?.mode === "blocks" && (debug$5("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
|
|
4614
4824
|
at: range,
|
|
4615
4825
|
voids: !0,
|
|
4616
4826
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
|
|
4617
|
-
})), options?.mode === "children" && (debug$
|
|
4827
|
+
})), options?.mode === "children" && (debug$5("Deleting children touched by selection"), Transforms.removeNodes(editor, {
|
|
4618
4828
|
at: range,
|
|
4619
4829
|
voids: !0,
|
|
4620
4830
|
match: (node) => node._type === types.span.name || // Text children
|
|
@@ -4748,7 +4958,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4748
4958
|
action
|
|
4749
4959
|
}) => {
|
|
4750
4960
|
const editor = action.editor;
|
|
4751
|
-
if (debug$
|
|
4961
|
+
if (debug$5("Removing annotation", action.annotation.name), !!editor.selection)
|
|
4752
4962
|
if (Range.isCollapsed(editor.selection)) {
|
|
4753
4963
|
const [block, blockPath] = Editor.node(editor, editor.selection, {
|
|
4754
4964
|
depth: 1
|
|
@@ -4879,7 +5089,11 @@ function insertBlock({
|
|
|
4879
5089
|
});
|
|
4880
5090
|
}
|
|
4881
5091
|
}
|
|
4882
|
-
const
|
|
5092
|
+
const dataTransferSetActionImplementation = ({
|
|
5093
|
+
action
|
|
5094
|
+
}) => {
|
|
5095
|
+
action.dataTransfer.setData(action.mimeType, action.data);
|
|
5096
|
+
}, insertBlockObjectActionImplementation = ({
|
|
4883
5097
|
context,
|
|
4884
5098
|
action
|
|
4885
5099
|
}) => {
|
|
@@ -4896,6 +5110,35 @@ const insertBlockObjectActionImplementation = ({
|
|
|
4896
5110
|
editor: action.editor,
|
|
4897
5111
|
schema: context.schema
|
|
4898
5112
|
});
|
|
5113
|
+
}, insertBlocksActionImplementation = ({
|
|
5114
|
+
context,
|
|
5115
|
+
action
|
|
5116
|
+
}) => {
|
|
5117
|
+
const fragment = toSlateValue(action.blocks, {
|
|
5118
|
+
schemaTypes: context.schema
|
|
5119
|
+
});
|
|
5120
|
+
if (!action.editor.selection)
|
|
5121
|
+
return;
|
|
5122
|
+
const [focusBlock, focusPath] = Editor.node(action.editor, action.editor.selection, {
|
|
5123
|
+
depth: 1
|
|
5124
|
+
});
|
|
5125
|
+
if (action.editor.isTextBlock(focusBlock) && action.editor.isTextBlock(fragment[0])) {
|
|
5126
|
+
const {
|
|
5127
|
+
markDefs
|
|
5128
|
+
} = focusBlock;
|
|
5129
|
+
isEqual(markDefs, fragment[0].markDefs) || Transforms.setNodes(action.editor, {
|
|
5130
|
+
markDefs: uniq([...fragment[0].markDefs || [], ...markDefs || []])
|
|
5131
|
+
}, {
|
|
5132
|
+
at: focusPath,
|
|
5133
|
+
mode: "lowest",
|
|
5134
|
+
voids: !1
|
|
5135
|
+
});
|
|
5136
|
+
}
|
|
5137
|
+
isEqualToEmptyEditor(action.editor.children, context.schema) ? (Transforms.splitNodes(action.editor, {
|
|
5138
|
+
at: [0, 0]
|
|
5139
|
+
}), action.editor.insertFragment(fragment), Transforms.removeNodes(action.editor, {
|
|
5140
|
+
at: [0]
|
|
5141
|
+
})) : action.editor.insertFragment(fragment);
|
|
4899
5142
|
}, insertBreakActionImplementation = ({
|
|
4900
5143
|
context,
|
|
4901
5144
|
action
|
|
@@ -5124,6 +5367,7 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5124
5367
|
}) => {
|
|
5125
5368
|
ReactEditor.blur(action.editor);
|
|
5126
5369
|
},
|
|
5370
|
+
"data transfer.set": dataTransferSetActionImplementation,
|
|
5127
5371
|
"decorator.add": addDecoratorActionImplementation,
|
|
5128
5372
|
"decorator.remove": removeDecoratorActionImplementation,
|
|
5129
5373
|
"decorator.toggle": toggleDecoratorActionImplementation,
|
|
@@ -5190,6 +5434,25 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5190
5434
|
at: range
|
|
5191
5435
|
});
|
|
5192
5436
|
},
|
|
5437
|
+
"deserialization.failure": ({
|
|
5438
|
+
action
|
|
5439
|
+
}) => {
|
|
5440
|
+
console.error(`Deserialization of ${action.mimeType} failed with reason ${action.reason}`);
|
|
5441
|
+
},
|
|
5442
|
+
"deserialization.success": ({
|
|
5443
|
+
context,
|
|
5444
|
+
action
|
|
5445
|
+
}) => {
|
|
5446
|
+
insertBlocksActionImplementation({
|
|
5447
|
+
context,
|
|
5448
|
+
action: {
|
|
5449
|
+
type: "insert.blocks",
|
|
5450
|
+
blocks: action.data,
|
|
5451
|
+
editor: action.editor
|
|
5452
|
+
}
|
|
5453
|
+
});
|
|
5454
|
+
},
|
|
5455
|
+
"insert.blocks": insertBlocksActionImplementation,
|
|
5193
5456
|
"insert.block object": insertBlockObjectActionImplementation,
|
|
5194
5457
|
"insert.break": insertBreakActionImplementation,
|
|
5195
5458
|
"insert.inline object": insertInlineObjectActionImplementation,
|
|
@@ -5301,6 +5564,23 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5301
5564
|
const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
|
|
5302
5565
|
Transforms.select(action.editor, nextBlockPath);
|
|
5303
5566
|
},
|
|
5567
|
+
"serialization.failure": ({
|
|
5568
|
+
action
|
|
5569
|
+
}) => {
|
|
5570
|
+
console.error(`Serialization of ${action.mimeType} failed with reason ${action.reason}`);
|
|
5571
|
+
},
|
|
5572
|
+
"serialization.success": ({
|
|
5573
|
+
context,
|
|
5574
|
+
action
|
|
5575
|
+
}) => {
|
|
5576
|
+
dataTransferSetActionImplementation({
|
|
5577
|
+
context,
|
|
5578
|
+
action: {
|
|
5579
|
+
...action,
|
|
5580
|
+
type: "data transfer.set"
|
|
5581
|
+
}
|
|
5582
|
+
});
|
|
5583
|
+
},
|
|
5304
5584
|
"style.toggle": toggleStyleActionImplementation,
|
|
5305
5585
|
"style.add": addStyleActionImplementation,
|
|
5306
5586
|
"style.remove": removeStyleActionImplementation,
|
|
@@ -5312,6 +5592,48 @@ function performAction({
|
|
|
5312
5592
|
action
|
|
5313
5593
|
}) {
|
|
5314
5594
|
switch (action.type) {
|
|
5595
|
+
case "noop":
|
|
5596
|
+
break;
|
|
5597
|
+
case "effect": {
|
|
5598
|
+
behaviorActionImplementations.effect({
|
|
5599
|
+
context,
|
|
5600
|
+
action
|
|
5601
|
+
});
|
|
5602
|
+
break;
|
|
5603
|
+
}
|
|
5604
|
+
case "select": {
|
|
5605
|
+
behaviorActionImplementations.select({
|
|
5606
|
+
context,
|
|
5607
|
+
action
|
|
5608
|
+
});
|
|
5609
|
+
break;
|
|
5610
|
+
}
|
|
5611
|
+
default:
|
|
5612
|
+
performDefaultAction({
|
|
5613
|
+
context,
|
|
5614
|
+
action
|
|
5615
|
+
});
|
|
5616
|
+
}
|
|
5617
|
+
}
|
|
5618
|
+
function performDefaultAction({
|
|
5619
|
+
context,
|
|
5620
|
+
action
|
|
5621
|
+
}) {
|
|
5622
|
+
switch (action.type) {
|
|
5623
|
+
case "annotation.add": {
|
|
5624
|
+
behaviorActionImplementations["annotation.add"]({
|
|
5625
|
+
context,
|
|
5626
|
+
action
|
|
5627
|
+
});
|
|
5628
|
+
break;
|
|
5629
|
+
}
|
|
5630
|
+
case "annotation.remove": {
|
|
5631
|
+
behaviorActionImplementations["annotation.remove"]({
|
|
5632
|
+
context,
|
|
5633
|
+
action
|
|
5634
|
+
});
|
|
5635
|
+
break;
|
|
5636
|
+
}
|
|
5315
5637
|
case "annotation.toggle": {
|
|
5316
5638
|
behaviorActionImplementations["annotation.toggle"]({
|
|
5317
5639
|
context,
|
|
@@ -5319,256 +5641,258 @@ function performAction({
|
|
|
5319
5641
|
});
|
|
5320
5642
|
break;
|
|
5321
5643
|
}
|
|
5322
|
-
case "
|
|
5323
|
-
behaviorActionImplementations
|
|
5644
|
+
case "blur": {
|
|
5645
|
+
behaviorActionImplementations.blur({
|
|
5324
5646
|
context,
|
|
5325
5647
|
action
|
|
5326
5648
|
});
|
|
5327
5649
|
break;
|
|
5328
5650
|
}
|
|
5329
|
-
case "
|
|
5330
|
-
behaviorActionImplementations["
|
|
5651
|
+
case "data transfer.set": {
|
|
5652
|
+
behaviorActionImplementations["data transfer.set"]({
|
|
5331
5653
|
context,
|
|
5332
5654
|
action
|
|
5333
5655
|
});
|
|
5334
5656
|
break;
|
|
5335
5657
|
}
|
|
5336
|
-
case "
|
|
5337
|
-
behaviorActionImplementations["
|
|
5658
|
+
case "decorator.add": {
|
|
5659
|
+
behaviorActionImplementations["decorator.add"]({
|
|
5338
5660
|
context,
|
|
5339
5661
|
action
|
|
5340
5662
|
});
|
|
5341
5663
|
break;
|
|
5342
5664
|
}
|
|
5343
|
-
case "
|
|
5344
|
-
behaviorActionImplementations["
|
|
5665
|
+
case "decorator.remove": {
|
|
5666
|
+
behaviorActionImplementations["decorator.remove"]({
|
|
5345
5667
|
context,
|
|
5346
5668
|
action
|
|
5347
5669
|
});
|
|
5348
5670
|
break;
|
|
5349
5671
|
}
|
|
5350
|
-
case "
|
|
5351
|
-
behaviorActionImplementations["
|
|
5672
|
+
case "decorator.toggle": {
|
|
5673
|
+
behaviorActionImplementations["decorator.toggle"]({
|
|
5352
5674
|
context,
|
|
5353
5675
|
action
|
|
5354
5676
|
});
|
|
5355
5677
|
break;
|
|
5356
5678
|
}
|
|
5357
|
-
case "
|
|
5358
|
-
behaviorActionImplementations["
|
|
5679
|
+
case "delete.backward": {
|
|
5680
|
+
behaviorActionImplementations["delete.backward"]({
|
|
5359
5681
|
context,
|
|
5360
5682
|
action
|
|
5361
5683
|
});
|
|
5362
5684
|
break;
|
|
5363
5685
|
}
|
|
5364
|
-
case "
|
|
5365
|
-
behaviorActionImplementations["
|
|
5686
|
+
case "delete.block": {
|
|
5687
|
+
behaviorActionImplementations["delete.block"]({
|
|
5366
5688
|
context,
|
|
5367
5689
|
action
|
|
5368
5690
|
});
|
|
5369
5691
|
break;
|
|
5370
5692
|
}
|
|
5371
|
-
case "
|
|
5372
|
-
behaviorActionImplementations["
|
|
5693
|
+
case "delete.forward": {
|
|
5694
|
+
behaviorActionImplementations["delete.forward"]({
|
|
5373
5695
|
context,
|
|
5374
5696
|
action
|
|
5375
5697
|
});
|
|
5376
5698
|
break;
|
|
5377
5699
|
}
|
|
5378
|
-
case "
|
|
5379
|
-
behaviorActionImplementations["
|
|
5700
|
+
case "delete.text": {
|
|
5701
|
+
behaviorActionImplementations["delete.text"]({
|
|
5380
5702
|
context,
|
|
5381
5703
|
action
|
|
5382
5704
|
});
|
|
5383
5705
|
break;
|
|
5384
5706
|
}
|
|
5385
|
-
case "
|
|
5386
|
-
behaviorActionImplementations["
|
|
5707
|
+
case "deserialization.failure": {
|
|
5708
|
+
behaviorActionImplementations["deserialization.failure"]({
|
|
5387
5709
|
context,
|
|
5388
5710
|
action
|
|
5389
5711
|
});
|
|
5390
5712
|
break;
|
|
5391
5713
|
}
|
|
5392
|
-
case "
|
|
5393
|
-
behaviorActionImplementations["
|
|
5714
|
+
case "deserialization.success": {
|
|
5715
|
+
behaviorActionImplementations["deserialization.success"]({
|
|
5394
5716
|
context,
|
|
5395
5717
|
action
|
|
5396
5718
|
});
|
|
5397
5719
|
break;
|
|
5398
5720
|
}
|
|
5399
|
-
case "
|
|
5721
|
+
case "focus": {
|
|
5722
|
+
behaviorActionImplementations.focus({
|
|
5723
|
+
context,
|
|
5724
|
+
action
|
|
5725
|
+
});
|
|
5400
5726
|
break;
|
|
5401
|
-
|
|
5402
|
-
|
|
5727
|
+
}
|
|
5728
|
+
case "insert.blocks": {
|
|
5729
|
+
behaviorActionImplementations["insert.blocks"]({
|
|
5403
5730
|
context,
|
|
5404
5731
|
action
|
|
5405
5732
|
});
|
|
5406
5733
|
break;
|
|
5407
5734
|
}
|
|
5408
|
-
case "
|
|
5409
|
-
behaviorActionImplementations.
|
|
5735
|
+
case "insert.block object": {
|
|
5736
|
+
behaviorActionImplementations["insert.block object"]({
|
|
5410
5737
|
context,
|
|
5411
5738
|
action
|
|
5412
5739
|
});
|
|
5413
5740
|
break;
|
|
5414
5741
|
}
|
|
5415
|
-
case "
|
|
5416
|
-
behaviorActionImplementations["
|
|
5742
|
+
case "insert.inline object": {
|
|
5743
|
+
behaviorActionImplementations["insert.inline object"]({
|
|
5417
5744
|
context,
|
|
5418
5745
|
action
|
|
5419
5746
|
});
|
|
5420
5747
|
break;
|
|
5421
5748
|
}
|
|
5422
|
-
case "
|
|
5423
|
-
behaviorActionImplementations["
|
|
5749
|
+
case "insert.break": {
|
|
5750
|
+
behaviorActionImplementations["insert.break"]({
|
|
5424
5751
|
context,
|
|
5425
5752
|
action
|
|
5426
5753
|
});
|
|
5427
5754
|
break;
|
|
5428
5755
|
}
|
|
5429
|
-
case "
|
|
5430
|
-
behaviorActionImplementations["
|
|
5756
|
+
case "insert.soft break": {
|
|
5757
|
+
behaviorActionImplementations["insert.soft break"]({
|
|
5431
5758
|
context,
|
|
5432
5759
|
action
|
|
5433
5760
|
});
|
|
5434
5761
|
break;
|
|
5435
5762
|
}
|
|
5436
|
-
case "
|
|
5437
|
-
behaviorActionImplementations["
|
|
5763
|
+
case "insert.span": {
|
|
5764
|
+
behaviorActionImplementations["insert.span"]({
|
|
5438
5765
|
context,
|
|
5439
5766
|
action
|
|
5440
5767
|
});
|
|
5441
5768
|
break;
|
|
5442
5769
|
}
|
|
5443
|
-
case "text
|
|
5444
|
-
behaviorActionImplementations["text
|
|
5770
|
+
case "insert.text": {
|
|
5771
|
+
behaviorActionImplementations["insert.text"]({
|
|
5445
5772
|
context,
|
|
5446
5773
|
action
|
|
5447
5774
|
});
|
|
5448
5775
|
break;
|
|
5449
5776
|
}
|
|
5450
|
-
case "text block
|
|
5451
|
-
behaviorActionImplementations["text block
|
|
5777
|
+
case "insert.text block": {
|
|
5778
|
+
behaviorActionImplementations["insert.text block"]({
|
|
5452
5779
|
context,
|
|
5453
5780
|
action
|
|
5454
5781
|
});
|
|
5455
5782
|
break;
|
|
5456
5783
|
}
|
|
5457
|
-
|
|
5458
|
-
|
|
5784
|
+
case "list item.add": {
|
|
5785
|
+
behaviorActionImplementations["list item.add"]({
|
|
5459
5786
|
context,
|
|
5460
5787
|
action
|
|
5461
5788
|
});
|
|
5462
|
-
|
|
5463
|
-
}
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
action
|
|
5467
|
-
}) {
|
|
5468
|
-
switch (action.type) {
|
|
5469
|
-
case "annotation.add": {
|
|
5470
|
-
behaviorActionImplementations["annotation.add"]({
|
|
5789
|
+
break;
|
|
5790
|
+
}
|
|
5791
|
+
case "list item.remove": {
|
|
5792
|
+
behaviorActionImplementations["list item.remove"]({
|
|
5471
5793
|
context,
|
|
5472
5794
|
action
|
|
5473
5795
|
});
|
|
5474
5796
|
break;
|
|
5475
5797
|
}
|
|
5476
|
-
case "
|
|
5477
|
-
behaviorActionImplementations["
|
|
5798
|
+
case "list item.toggle": {
|
|
5799
|
+
behaviorActionImplementations["list item.toggle"]({
|
|
5478
5800
|
context,
|
|
5479
5801
|
action
|
|
5480
5802
|
});
|
|
5481
5803
|
break;
|
|
5482
5804
|
}
|
|
5483
|
-
case "
|
|
5484
|
-
behaviorActionImplementations.
|
|
5805
|
+
case "move.block": {
|
|
5806
|
+
behaviorActionImplementations["move.block"]({
|
|
5485
5807
|
context,
|
|
5486
5808
|
action
|
|
5487
5809
|
});
|
|
5488
5810
|
break;
|
|
5489
5811
|
}
|
|
5490
|
-
case "
|
|
5491
|
-
behaviorActionImplementations["
|
|
5812
|
+
case "move.block down": {
|
|
5813
|
+
behaviorActionImplementations["move.block down"]({
|
|
5492
5814
|
context,
|
|
5493
5815
|
action
|
|
5494
5816
|
});
|
|
5495
5817
|
break;
|
|
5496
5818
|
}
|
|
5497
|
-
case "
|
|
5498
|
-
behaviorActionImplementations["
|
|
5819
|
+
case "move.block up": {
|
|
5820
|
+
behaviorActionImplementations["move.block up"]({
|
|
5499
5821
|
context,
|
|
5500
5822
|
action
|
|
5501
5823
|
});
|
|
5502
5824
|
break;
|
|
5503
5825
|
}
|
|
5504
|
-
case "
|
|
5505
|
-
behaviorActionImplementations
|
|
5826
|
+
case "select": {
|
|
5827
|
+
behaviorActionImplementations.select({
|
|
5506
5828
|
context,
|
|
5507
5829
|
action
|
|
5508
5830
|
});
|
|
5509
5831
|
break;
|
|
5510
5832
|
}
|
|
5511
|
-
case "
|
|
5512
|
-
behaviorActionImplementations.
|
|
5833
|
+
case "select.previous block": {
|
|
5834
|
+
behaviorActionImplementations["select.previous block"]({
|
|
5513
5835
|
context,
|
|
5514
5836
|
action
|
|
5515
5837
|
});
|
|
5516
5838
|
break;
|
|
5517
5839
|
}
|
|
5518
|
-
case "
|
|
5519
|
-
behaviorActionImplementations["
|
|
5840
|
+
case "select.next block": {
|
|
5841
|
+
behaviorActionImplementations["select.next block"]({
|
|
5520
5842
|
context,
|
|
5521
5843
|
action
|
|
5522
5844
|
});
|
|
5523
5845
|
break;
|
|
5524
5846
|
}
|
|
5525
|
-
case "
|
|
5526
|
-
behaviorActionImplementations["
|
|
5847
|
+
case "serialization.failure": {
|
|
5848
|
+
behaviorActionImplementations["serialization.failure"]({
|
|
5527
5849
|
context,
|
|
5528
5850
|
action
|
|
5529
5851
|
});
|
|
5530
5852
|
break;
|
|
5531
5853
|
}
|
|
5532
|
-
case "
|
|
5533
|
-
behaviorActionImplementations["
|
|
5854
|
+
case "serialization.success": {
|
|
5855
|
+
behaviorActionImplementations["serialization.success"]({
|
|
5534
5856
|
context,
|
|
5535
5857
|
action
|
|
5536
5858
|
});
|
|
5537
5859
|
break;
|
|
5538
5860
|
}
|
|
5539
|
-
case "
|
|
5540
|
-
behaviorActionImplementations["
|
|
5861
|
+
case "style.add": {
|
|
5862
|
+
behaviorActionImplementations["style.add"]({
|
|
5541
5863
|
context,
|
|
5542
5864
|
action
|
|
5543
5865
|
});
|
|
5544
5866
|
break;
|
|
5545
5867
|
}
|
|
5546
|
-
case "
|
|
5547
|
-
behaviorActionImplementations["
|
|
5868
|
+
case "style.remove": {
|
|
5869
|
+
behaviorActionImplementations["style.remove"]({
|
|
5548
5870
|
context,
|
|
5549
5871
|
action
|
|
5550
5872
|
});
|
|
5551
5873
|
break;
|
|
5552
5874
|
}
|
|
5553
|
-
case "
|
|
5554
|
-
behaviorActionImplementations["
|
|
5875
|
+
case "style.toggle": {
|
|
5876
|
+
behaviorActionImplementations["style.toggle"]({
|
|
5555
5877
|
context,
|
|
5556
5878
|
action
|
|
5557
5879
|
});
|
|
5558
5880
|
break;
|
|
5559
5881
|
}
|
|
5560
|
-
case "
|
|
5561
|
-
behaviorActionImplementations.
|
|
5882
|
+
case "text block.set": {
|
|
5883
|
+
behaviorActionImplementations["text block.set"]({
|
|
5562
5884
|
context,
|
|
5563
5885
|
action
|
|
5564
5886
|
});
|
|
5565
5887
|
break;
|
|
5566
5888
|
}
|
|
5567
|
-
|
|
5568
|
-
behaviorActionImplementations["
|
|
5889
|
+
case "text block.unset": {
|
|
5890
|
+
behaviorActionImplementations["text block.unset"]({
|
|
5569
5891
|
context,
|
|
5570
5892
|
action
|
|
5571
5893
|
});
|
|
5894
|
+
break;
|
|
5895
|
+
}
|
|
5572
5896
|
}
|
|
5573
5897
|
}
|
|
5574
5898
|
function getActiveDecorators({
|
|
@@ -5581,6 +5905,7 @@ function getActiveDecorators({
|
|
|
5581
5905
|
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
5582
5906
|
}
|
|
5583
5907
|
function createEditorSnapshot({
|
|
5908
|
+
converters,
|
|
5584
5909
|
editor,
|
|
5585
5910
|
keyGenerator,
|
|
5586
5911
|
schema
|
|
@@ -5592,6 +5917,7 @@ function createEditorSnapshot({
|
|
|
5592
5917
|
schema,
|
|
5593
5918
|
slateEditorInstance: editor
|
|
5594
5919
|
}),
|
|
5920
|
+
converters,
|
|
5595
5921
|
keyGenerator,
|
|
5596
5922
|
schema,
|
|
5597
5923
|
selection,
|
|
@@ -5666,7 +5992,7 @@ const editorMachine = setup({
|
|
|
5666
5992
|
enqueue
|
|
5667
5993
|
}) => {
|
|
5668
5994
|
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 : {
|
|
5995
|
+
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
5996
|
...event.behaviorEvent,
|
|
5671
5997
|
editor: event.editor
|
|
5672
5998
|
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values()].filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
@@ -5700,6 +6026,7 @@ const editorMachine = setup({
|
|
|
5700
6026
|
return;
|
|
5701
6027
|
}
|
|
5702
6028
|
const editorSnapshot = createEditorSnapshot({
|
|
6029
|
+
converters: [...context.converters],
|
|
5703
6030
|
editor: event.editor,
|
|
5704
6031
|
keyGenerator: context.keyGenerator,
|
|
5705
6032
|
schema: context.schema
|
|
@@ -5789,6 +6116,7 @@ const editorMachine = setup({
|
|
|
5789
6116
|
input
|
|
5790
6117
|
}) => ({
|
|
5791
6118
|
behaviors: new Set(input.behaviors ?? coreBehaviors),
|
|
6119
|
+
converters: new Set(input.converters ?? []),
|
|
5792
6120
|
keyGenerator: input.keyGenerator,
|
|
5793
6121
|
pendingEvents: [],
|
|
5794
6122
|
schema: input.schema,
|
|
@@ -5908,6 +6236,12 @@ const editorMachine = setup({
|
|
|
5908
6236
|
},
|
|
5909
6237
|
"read only": {
|
|
5910
6238
|
on: {
|
|
6239
|
+
"behavior event": {
|
|
6240
|
+
actions: "handle behavior event",
|
|
6241
|
+
guard: ({
|
|
6242
|
+
event
|
|
6243
|
+
}) => 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"
|
|
6244
|
+
},
|
|
5911
6245
|
"update readOnly": {
|
|
5912
6246
|
guard: ({
|
|
5913
6247
|
event
|
|
@@ -5957,6 +6291,11 @@ const editorMachine = setup({
|
|
|
5957
6291
|
event
|
|
5958
6292
|
}) => event)
|
|
5959
6293
|
},
|
|
6294
|
+
"delete.*": {
|
|
6295
|
+
actions: emit(({
|
|
6296
|
+
event
|
|
6297
|
+
}) => event)
|
|
6298
|
+
},
|
|
5960
6299
|
focus: {
|
|
5961
6300
|
actions: emit(({
|
|
5962
6301
|
event
|
|
@@ -5972,15 +6311,30 @@ const editorMachine = setup({
|
|
|
5972
6311
|
event
|
|
5973
6312
|
}) => event)
|
|
5974
6313
|
},
|
|
6314
|
+
"move.*": {
|
|
6315
|
+
actions: emit(({
|
|
6316
|
+
event
|
|
6317
|
+
}) => event)
|
|
6318
|
+
},
|
|
5975
6319
|
select: {
|
|
5976
6320
|
actions: emit(({
|
|
5977
6321
|
event
|
|
5978
6322
|
}) => event)
|
|
5979
6323
|
},
|
|
6324
|
+
"select.*": {
|
|
6325
|
+
actions: emit(({
|
|
6326
|
+
event
|
|
6327
|
+
}) => event)
|
|
6328
|
+
},
|
|
5980
6329
|
"style.*": {
|
|
5981
6330
|
actions: emit(({
|
|
5982
6331
|
event
|
|
5983
6332
|
}) => event)
|
|
6333
|
+
},
|
|
6334
|
+
"text block.*": {
|
|
6335
|
+
actions: emit(({
|
|
6336
|
+
event
|
|
6337
|
+
}) => event)
|
|
5984
6338
|
}
|
|
5985
6339
|
}
|
|
5986
6340
|
}
|
|
@@ -6077,6 +6431,7 @@ function getEditorSnapshot({
|
|
|
6077
6431
|
}) {
|
|
6078
6432
|
return {
|
|
6079
6433
|
context: {
|
|
6434
|
+
converters: [...editorActorSnapshot.context.converters],
|
|
6080
6435
|
activeDecorators: getActiveDecorators({
|
|
6081
6436
|
schema: editorActorSnapshot.context.schema,
|
|
6082
6437
|
slateEditorInstance
|
|
@@ -6131,6 +6486,7 @@ function useCreateEditor(config) {
|
|
|
6131
6486
|
function editorConfigToMachineInput(config) {
|
|
6132
6487
|
return {
|
|
6133
6488
|
behaviors: config.behaviors,
|
|
6489
|
+
converters: coreConverters,
|
|
6134
6490
|
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
6135
6491
|
maxBlocks: config.maxBlocks,
|
|
6136
6492
|
readOnly: config.readOnly,
|
|
@@ -6159,11 +6515,25 @@ function createEditorFromActor(editorActor) {
|
|
|
6159
6515
|
send: (event) => {
|
|
6160
6516
|
editorActor.send(event);
|
|
6161
6517
|
},
|
|
6162
|
-
on: (event, listener) => editorActor.on(
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6518
|
+
on: (event, listener) => editorActor.on(event, (event2) => {
|
|
6519
|
+
switch (event2.type) {
|
|
6520
|
+
case "blurred":
|
|
6521
|
+
case "done loading":
|
|
6522
|
+
case "editable":
|
|
6523
|
+
case "error":
|
|
6524
|
+
case "focused":
|
|
6525
|
+
case "invalid value":
|
|
6526
|
+
case "loading":
|
|
6527
|
+
case "mutation":
|
|
6528
|
+
case "patch":
|
|
6529
|
+
case "read only":
|
|
6530
|
+
case "ready":
|
|
6531
|
+
case "selection":
|
|
6532
|
+
case "value changed":
|
|
6533
|
+
listener(event2);
|
|
6534
|
+
break;
|
|
6535
|
+
}
|
|
6536
|
+
}),
|
|
6167
6537
|
_internal: {
|
|
6168
6538
|
editable,
|
|
6169
6539
|
editorActor,
|
|
@@ -6176,25 +6546,25 @@ const EditorActorContext = createContext({}), PortableTextEditorSelectionContext
|
|
|
6176
6546
|
if (selection === void 0)
|
|
6177
6547
|
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
6178
6548
|
return selection;
|
|
6179
|
-
}, debug$
|
|
6549
|
+
}, debug$4 = debugWithName("component:PortableTextEditor:SelectionProvider");
|
|
6180
6550
|
function PortableTextEditorSelectionProvider(props) {
|
|
6181
6551
|
const $ = c(6), [selection, setSelection] = useState(null);
|
|
6182
6552
|
let t0, t1;
|
|
6183
6553
|
$[0] !== props.editorActor ? (t0 = () => {
|
|
6184
|
-
debug$
|
|
6554
|
+
debug$4("Subscribing to selection changes");
|
|
6185
6555
|
const subscription = props.editorActor.on("selection", (event) => {
|
|
6186
6556
|
startTransition(() => {
|
|
6187
6557
|
setSelection(event.selection);
|
|
6188
6558
|
});
|
|
6189
6559
|
});
|
|
6190
6560
|
return () => {
|
|
6191
|
-
debug$
|
|
6561
|
+
debug$4("Unsubscribing to selection changes"), subscription.unsubscribe();
|
|
6192
6562
|
};
|
|
6193
6563
|
}, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1);
|
|
6194
6564
|
let t2;
|
|
6195
6565
|
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;
|
|
6196
6566
|
}
|
|
6197
|
-
const debug$
|
|
6567
|
+
const debug$3 = debugWithName("component:PortableTextEditor");
|
|
6198
6568
|
class PortableTextEditor extends Component {
|
|
6199
6569
|
static displayName = "PortableTextEditor";
|
|
6200
6570
|
/**
|
|
@@ -6256,13 +6626,13 @@ class PortableTextEditor extends Component {
|
|
|
6256
6626
|
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
6257
6627
|
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
6258
6628
|
static blur = (editor) => {
|
|
6259
|
-
debug$
|
|
6629
|
+
debug$3("Host blurred"), editor.editable?.blur();
|
|
6260
6630
|
};
|
|
6261
6631
|
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
6262
6632
|
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
6263
6633
|
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
6264
6634
|
static focus = (editor) => {
|
|
6265
|
-
debug$
|
|
6635
|
+
debug$3("Host requesting focus"), editor.editable?.focus();
|
|
6266
6636
|
};
|
|
6267
6637
|
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
6268
6638
|
static focusChild = (editor) => editor.editable?.focusChild();
|
|
@@ -6273,7 +6643,7 @@ class PortableTextEditor extends Component {
|
|
|
6273
6643
|
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
6274
6644
|
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
6275
6645
|
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
6276
|
-
static insertChild = (editor, type, value) => (debug$
|
|
6646
|
+
static insertChild = (editor, type, value) => (debug$3("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
6277
6647
|
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
6278
6648
|
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
6279
6649
|
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
@@ -6284,20 +6654,20 @@ class PortableTextEditor extends Component {
|
|
|
6284
6654
|
};
|
|
6285
6655
|
static marks = (editor) => editor.editable?.marks();
|
|
6286
6656
|
static select = (editor, selection) => {
|
|
6287
|
-
debug$
|
|
6657
|
+
debug$3("Host setting selection", selection), editor.editable?.select(selection);
|
|
6288
6658
|
};
|
|
6289
6659
|
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
6290
|
-
static toggleBlockStyle = (editor, blockStyle) => (debug$
|
|
6660
|
+
static toggleBlockStyle = (editor, blockStyle) => (debug$3("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
6291
6661
|
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
6292
6662
|
static toggleMark = (editor, mark) => {
|
|
6293
|
-
debug$
|
|
6663
|
+
debug$3("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
6294
6664
|
};
|
|
6295
|
-
static getFragment = (editor) => (debug$
|
|
6665
|
+
static getFragment = (editor) => (debug$3("Host getting fragment"), editor.editable?.getFragment());
|
|
6296
6666
|
static undo = (editor) => {
|
|
6297
|
-
debug$
|
|
6667
|
+
debug$3("Host undoing"), editor.editable?.undo();
|
|
6298
6668
|
};
|
|
6299
6669
|
static redo = (editor) => {
|
|
6300
|
-
debug$
|
|
6670
|
+
debug$3("Host redoing"), editor.editable?.redo();
|
|
6301
6671
|
};
|
|
6302
6672
|
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
6303
6673
|
}
|
|
@@ -6323,7 +6693,7 @@ function RouteEventsToChanges(props) {
|
|
|
6323
6693
|
const handleChange = useEffectEvent(t0);
|
|
6324
6694
|
let t1, t2;
|
|
6325
6695
|
return $[2] !== handleChange || $[3] !== props.editorActor ? (t1 = () => {
|
|
6326
|
-
debug$
|
|
6696
|
+
debug$3("Subscribing to editor changes");
|
|
6327
6697
|
const sub = props.editorActor.on("*", (event) => {
|
|
6328
6698
|
bb5: switch (event.type) {
|
|
6329
6699
|
case "blurred": {
|
|
@@ -6397,11 +6767,11 @@ function RouteEventsToChanges(props) {
|
|
|
6397
6767
|
}
|
|
6398
6768
|
});
|
|
6399
6769
|
return () => {
|
|
6400
|
-
debug$
|
|
6770
|
+
debug$3("Unsubscribing to changes"), sub.unsubscribe();
|
|
6401
6771
|
};
|
|
6402
6772
|
}, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2), null;
|
|
6403
6773
|
}
|
|
6404
|
-
const debug$
|
|
6774
|
+
const debug$2 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
6405
6775
|
const {
|
|
6406
6776
|
editorActor,
|
|
6407
6777
|
attributes,
|
|
@@ -6429,7 +6799,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6429
6799
|
const setSelectedFromRange = useCallback(() => {
|
|
6430
6800
|
if (!shouldTrackSelectionAndFocus)
|
|
6431
6801
|
return;
|
|
6432
|
-
debug$
|
|
6802
|
+
debug$2("Setting selection and focus from range");
|
|
6433
6803
|
const winSelection = window.getSelection();
|
|
6434
6804
|
if (!winSelection) {
|
|
6435
6805
|
setSelected(!1);
|
|
@@ -6525,7 +6895,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6525
6895
|
return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6526
6896
|
};
|
|
6527
6897
|
Leaf.displayName = "Leaf";
|
|
6528
|
-
const debug$
|
|
6898
|
+
const debug$1 = debugWithName("plugin:withHotKeys");
|
|
6529
6899
|
function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
|
|
6530
6900
|
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
|
|
6531
6901
|
return function(editor) {
|
|
@@ -6540,7 +6910,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
6540
6910
|
const possibleMark = activeHotkeys[cat];
|
|
6541
6911
|
if (possibleMark) {
|
|
6542
6912
|
const mark = possibleMark[hotkey];
|
|
6543
|
-
debug$
|
|
6913
|
+
debug$1(`HotKey ${hotkey} to toggle ${mark}`), editorActor.send({
|
|
6544
6914
|
type: "behavior event",
|
|
6545
6915
|
behaviorEvent: {
|
|
6546
6916
|
type: "decorator.toggle",
|
|
@@ -6567,204 +6937,6 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
6567
6937
|
}, editor;
|
|
6568
6938
|
};
|
|
6569
6939
|
}
|
|
6570
|
-
const debug$1 = debugWithName("plugin:withInsertData");
|
|
6571
|
-
function createWithInsertData(editorActor, schemaTypes) {
|
|
6572
|
-
return function(editor) {
|
|
6573
|
-
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(`
|
|
6574
|
-
|
|
6575
|
-
`);
|
|
6576
|
-
return editor.setFragmentData = (data, originEvent) => {
|
|
6577
|
-
const {
|
|
6578
|
-
selection
|
|
6579
|
-
} = editor;
|
|
6580
|
-
if (!selection)
|
|
6581
|
-
return;
|
|
6582
|
-
const [start, end] = Range.edges(selection), startVoid = Editor.void(editor, {
|
|
6583
|
-
at: start.path
|
|
6584
|
-
}), endVoid = Editor.void(editor, {
|
|
6585
|
-
at: end.path
|
|
6586
|
-
});
|
|
6587
|
-
if (Range.isCollapsed(selection) && !startVoid)
|
|
6588
|
-
return;
|
|
6589
|
-
const domRange = ReactEditor.toDOMRange(editor, selection);
|
|
6590
|
-
let contents = domRange.cloneContents();
|
|
6591
|
-
if (endVoid) {
|
|
6592
|
-
const [voidNode] = endVoid, r = domRange.cloneRange(), domNode = ReactEditor.toDOMNode(editor, voidNode);
|
|
6593
|
-
r.setEndAfter(domNode), contents = r.cloneContents();
|
|
6594
|
-
}
|
|
6595
|
-
Array.from(contents.querySelectorAll("[data-slate-zero-width]")).forEach((zw) => {
|
|
6596
|
-
const isNewline = zw.getAttribute("data-slate-zero-width") === "n";
|
|
6597
|
-
zw.textContent = isNewline ? `
|
|
6598
|
-
` : "";
|
|
6599
|
-
}), Array.from(contents.querySelectorAll("*")).forEach((elm) => {
|
|
6600
|
-
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");
|
|
6601
|
-
for (const key in elm.attributes)
|
|
6602
|
-
elm.hasAttribute(key) && elm.removeAttribute(key);
|
|
6603
|
-
});
|
|
6604
|
-
const div = contents.ownerDocument.createElement("div");
|
|
6605
|
-
div.appendChild(contents), div.setAttribute("hidden", "true"), contents.ownerDocument.body.appendChild(div);
|
|
6606
|
-
const asHTML = div.innerHTML;
|
|
6607
|
-
contents.ownerDocument.body.removeChild(div);
|
|
6608
|
-
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
6609
|
-
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);
|
|
6610
|
-
}, editor.insertPortableTextData = (data) => {
|
|
6611
|
-
if (!editor.selection)
|
|
6612
|
-
return !1;
|
|
6613
|
-
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
6614
|
-
if (debug$1(`Inserting portable text from ${origin} event`, pText), pText) {
|
|
6615
|
-
const parsed = JSON.parse(pText);
|
|
6616
|
-
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
6617
|
-
const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
|
|
6618
|
-
schemaTypes
|
|
6619
|
-
}), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
6620
|
-
if (!validation.valid && !validation.resolution?.autoResolve) {
|
|
6621
|
-
const errorDescription = `${validation.resolution?.description}`;
|
|
6622
|
-
return editorActor.send({
|
|
6623
|
-
type: "error",
|
|
6624
|
-
name: "pasteError",
|
|
6625
|
-
description: errorDescription,
|
|
6626
|
-
data: validation
|
|
6627
|
-
}), debug$1("Invalid insert result", validation), !1;
|
|
6628
|
-
}
|
|
6629
|
-
return _insertFragment(editor, slateValue, schemaTypes), !0;
|
|
6630
|
-
}
|
|
6631
|
-
}
|
|
6632
|
-
return !1;
|
|
6633
|
-
}, editor.insertTextOrHTMLData = (data) => {
|
|
6634
|
-
if (!editor.selection)
|
|
6635
|
-
return debug$1("No selection, not inserting"), !1;
|
|
6636
|
-
const html = data.getData("text/html"), text = data.getData("text/plain");
|
|
6637
|
-
if (html || text) {
|
|
6638
|
-
debug$1("Inserting data", data);
|
|
6639
|
-
let portableText, fragment, insertedType;
|
|
6640
|
-
if (html) {
|
|
6641
|
-
if (portableText = htmlToBlocks(html, schemaTypes.portableText, {
|
|
6642
|
-
unstable_whitespaceOnPasteMode: whitespaceOnPasteMode,
|
|
6643
|
-
keyGenerator: editorActor.getSnapshot().context.keyGenerator
|
|
6644
|
-
}), fragment = toSlateValue(portableText, {
|
|
6645
|
-
schemaTypes
|
|
6646
|
-
}), insertedType = "HTML", portableText.length === 0)
|
|
6647
|
-
return !1;
|
|
6648
|
-
} else {
|
|
6649
|
-
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>`;
|
|
6650
|
-
portableText = htmlToBlocks(textToHtml, schemaTypes.portableText, {
|
|
6651
|
-
keyGenerator: editorActor.getSnapshot().context.keyGenerator
|
|
6652
|
-
}), fragment = toSlateValue(portableText, {
|
|
6653
|
-
schemaTypes
|
|
6654
|
-
}), insertedType = "text";
|
|
6655
|
-
}
|
|
6656
|
-
const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
6657
|
-
if (!validation.valid) {
|
|
6658
|
-
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
6659
|
-
${validation.resolution?.description}
|
|
6660
|
-
Try to insert as plain text (shift-paste) instead.`;
|
|
6661
|
-
return editorActor.send({
|
|
6662
|
-
type: "error",
|
|
6663
|
-
name: "pasteError",
|
|
6664
|
-
description: errorDescription,
|
|
6665
|
-
data: validation
|
|
6666
|
-
}), debug$1("Invalid insert result", validation), !1;
|
|
6667
|
-
}
|
|
6668
|
-
return debug$1(`Inserting ${insertedType} fragment at ${JSON.stringify(editor.selection)}`), _insertFragment(editor, fragment, schemaTypes), !0;
|
|
6669
|
-
}
|
|
6670
|
-
return !1;
|
|
6671
|
-
}, editor.insertData = (data) => {
|
|
6672
|
-
editor.insertPortableTextData(data) || editor.insertTextOrHTMLData(data);
|
|
6673
|
-
}, editor.insertFragmentData = (data) => {
|
|
6674
|
-
const fragment = data.getData("application/x-portable-text");
|
|
6675
|
-
if (fragment) {
|
|
6676
|
-
const parsed = JSON.parse(fragment);
|
|
6677
|
-
return editor.insertFragment(parsed), !0;
|
|
6678
|
-
}
|
|
6679
|
-
return !1;
|
|
6680
|
-
}, editor;
|
|
6681
|
-
};
|
|
6682
|
-
}
|
|
6683
|
-
const entityMap = {
|
|
6684
|
-
"&": "&",
|
|
6685
|
-
"<": "<",
|
|
6686
|
-
">": ">",
|
|
6687
|
-
'"': """,
|
|
6688
|
-
"'": "'",
|
|
6689
|
-
"/": "/",
|
|
6690
|
-
"`": "`",
|
|
6691
|
-
"=": "="
|
|
6692
|
-
};
|
|
6693
|
-
function escapeHtml(str) {
|
|
6694
|
-
return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
|
|
6695
|
-
}
|
|
6696
|
-
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
|
|
6697
|
-
return fragment.map((node) => {
|
|
6698
|
-
const newNode = {
|
|
6699
|
-
...node
|
|
6700
|
-
};
|
|
6701
|
-
if (editor.isTextBlock(newNode)) {
|
|
6702
|
-
const annotations = editorTypes.annotations.map((t) => t.name);
|
|
6703
|
-
if (annotations.length === 0) {
|
|
6704
|
-
const {
|
|
6705
|
-
markDefs,
|
|
6706
|
-
...NewNodeNoDefs
|
|
6707
|
-
} = newNode;
|
|
6708
|
-
return {
|
|
6709
|
-
...NewNodeNoDefs,
|
|
6710
|
-
_key: keyGenerator()
|
|
6711
|
-
};
|
|
6712
|
-
}
|
|
6713
|
-
if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
|
|
6714
|
-
const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
|
|
6715
|
-
return {
|
|
6716
|
-
...newNode,
|
|
6717
|
-
markDefs: allowedAnnotations,
|
|
6718
|
-
_key: keyGenerator()
|
|
6719
|
-
};
|
|
6720
|
-
}
|
|
6721
|
-
newNode.markDefs = (newNode.markDefs || []).map((def) => {
|
|
6722
|
-
const oldKey = def._key, newKey = keyGenerator();
|
|
6723
|
-
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
6724
|
-
...child,
|
|
6725
|
-
marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
|
|
6726
|
-
} : child), {
|
|
6727
|
-
...def,
|
|
6728
|
-
_key: newKey
|
|
6729
|
-
};
|
|
6730
|
-
});
|
|
6731
|
-
}
|
|
6732
|
-
const nodeWithNewKeys = {
|
|
6733
|
-
...newNode,
|
|
6734
|
-
_key: keyGenerator()
|
|
6735
|
-
};
|
|
6736
|
-
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
|
|
6737
|
-
...child,
|
|
6738
|
-
_key: keyGenerator()
|
|
6739
|
-
}))), nodeWithNewKeys;
|
|
6740
|
-
});
|
|
6741
|
-
}
|
|
6742
|
-
function _insertFragment(editor, fragment, schemaTypes) {
|
|
6743
|
-
editor.withoutNormalizing(() => {
|
|
6744
|
-
if (!editor.selection)
|
|
6745
|
-
return;
|
|
6746
|
-
const [focusBlock, focusPath] = Editor.node(editor, editor.selection, {
|
|
6747
|
-
depth: 1
|
|
6748
|
-
});
|
|
6749
|
-
if (editor.isTextBlock(focusBlock) && editor.isTextBlock(fragment[0])) {
|
|
6750
|
-
const {
|
|
6751
|
-
markDefs
|
|
6752
|
-
} = focusBlock;
|
|
6753
|
-
debug$1("Mixing markDefs of focusBlock and fragments[0] block", markDefs, fragment[0].markDefs), isEqual(markDefs, fragment[0].markDefs) || Transforms.setNodes(editor, {
|
|
6754
|
-
markDefs: uniq([...fragment[0].markDefs || [], ...markDefs || []])
|
|
6755
|
-
}, {
|
|
6756
|
-
at: focusPath,
|
|
6757
|
-
mode: "lowest",
|
|
6758
|
-
voids: !1
|
|
6759
|
-
});
|
|
6760
|
-
}
|
|
6761
|
-
isEqualToEmptyEditor(editor.children, schemaTypes) ? (Transforms.splitNodes(editor, {
|
|
6762
|
-
at: [0, 0]
|
|
6763
|
-
}), editor.insertFragment(fragment), Transforms.removeNodes(editor, {
|
|
6764
|
-
at: [0]
|
|
6765
|
-
})) : editor.insertFragment(fragment);
|
|
6766
|
-
}), editor.onChange();
|
|
6767
|
-
}
|
|
6768
6940
|
function withSyncRangeDecorations({
|
|
6769
6941
|
editorActor,
|
|
6770
6942
|
slateEditor,
|
|
@@ -6812,12 +6984,11 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6812
6984
|
"edit mode": "read only"
|
|
6813
6985
|
})), schemaTypes = useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = useSlate(), blockTypeName = schemaTypes.block.name;
|
|
6814
6986
|
useMemo(() => {
|
|
6815
|
-
const withInsertData = createWithInsertData(editorActor, schemaTypes);
|
|
6816
6987
|
if (readOnly)
|
|
6817
|
-
return debug("Editable is in read only mode"),
|
|
6988
|
+
return debug("Editable is in read only mode"), slateEditor;
|
|
6818
6989
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
6819
|
-
return debug("Editable is in edit mode"),
|
|
6820
|
-
}, [editorActor, hotkeys, portableTextEditor, readOnly,
|
|
6990
|
+
return debug("Editable is in edit mode"), withHotKeys(slateEditor);
|
|
6991
|
+
}, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
|
|
6821
6992
|
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) => {
|
|
6822
6993
|
if (lProps.leaf._type === "span") {
|
|
6823
6994
|
let rendered = /* @__PURE__ */ jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|