@portabletext/editor 1.18.7 → 1.19.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 +52 -35
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +52 -35
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/behaviors/index.cjs +1 -0
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +76 -84
- package/lib/behaviors/index.d.ts +76 -84
- package/lib/behaviors/index.js +3 -2
- package/lib/index.cjs +234 -251
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +241 -1098
- package/lib/index.d.ts +241 -1098
- package/lib/index.js +235 -252
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +12 -9
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +12 -9
- package/lib/selectors/index.js.map +1 -1
- package/package.json +2 -2
- package/src/behavior-actions/behavior.actions.ts +28 -36
- package/src/behaviors/behavior.core.decorators.ts +36 -42
- package/src/behaviors/behavior.core.ts +4 -3
- package/src/behaviors/behavior.types.ts +38 -24
- package/src/behaviors/index.ts +1 -0
- package/src/editor/PortableTextEditor.tsx +14 -16
- package/src/editor/__tests__/self-solving.test.tsx +4 -11
- package/src/editor/create-editor.ts +1 -3
- package/src/editor/editor-machine.ts +37 -41
- package/src/editor/plugins/create-with-event-listeners.ts +44 -57
- package/src/editor/plugins/createWithHotKeys.ts +1 -11
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +12 -1
- package/src/editor/plugins/createWithPortableTextSelections.ts +1 -5
- package/src/editor/with-applying-behavior-actions.ts +15 -0
- package/src/selectors/selector.get-selected-spans.test.ts +122 -0
- package/src/selectors/selector.get-selected-spans.ts +3 -1
- package/src/selectors/selector.is-active-decorator.test.ts +65 -0
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$k from "debug";
|
|
12
12
|
import { c } from "react-compiler-runtime";
|
|
13
13
|
import { styled } from "styled-components";
|
|
14
14
|
import uniq from "lodash/uniq.js";
|
|
@@ -140,10 +140,10 @@ function compileSchemaDefinition(definition) {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
const rootName = "sanity-pte:";
|
|
143
|
-
debug$
|
|
143
|
+
debug$k(rootName);
|
|
144
144
|
function debugWithName(name) {
|
|
145
145
|
const namespace = `${rootName}${name}`;
|
|
146
|
-
return debug$
|
|
146
|
+
return debug$k && debug$k.enabled(namespace) ? debug$k(namespace) : debug$k(rootName);
|
|
147
147
|
}
|
|
148
148
|
function createKeyedPath(point, value, types) {
|
|
149
149
|
const blockPath = [point.path[0]];
|
|
@@ -214,7 +214,7 @@ function toSlateRange(selection, editor) {
|
|
|
214
214
|
path: toSlatePath(selection.focus.path, editor),
|
|
215
215
|
offset: selection.focus.offset
|
|
216
216
|
};
|
|
217
|
-
return focus.path.length === 0 || anchor.path.length === 0 ? null :
|
|
217
|
+
return focus.path.length === 0 || anchor.path.length === 0 ? null : focus ? {
|
|
218
218
|
anchor,
|
|
219
219
|
focus
|
|
220
220
|
} : null;
|
|
@@ -542,7 +542,7 @@ function getCounterContentForListLevel(level) {
|
|
|
542
542
|
return "counter(listItemNumberNextNextNext) '. '";
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
|
-
const debug$
|
|
545
|
+
const debug$j = debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
|
|
546
546
|
const $ = c(51), {
|
|
547
547
|
children,
|
|
548
548
|
element,
|
|
@@ -580,39 +580,39 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
580
580
|
$[16] !== editor || $[17] !== element ? (t9 = (event_0) => {
|
|
581
581
|
const targetBlock = IS_DRAGGING_ELEMENT_TARGET.get(editor);
|
|
582
582
|
if (targetBlock) {
|
|
583
|
-
IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$
|
|
583
|
+
IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$j("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
|
|
584
584
|
const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor);
|
|
585
585
|
IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor);
|
|
586
586
|
let targetPath = ReactEditor.findPath(editor, targetBlock);
|
|
587
587
|
const myPath = ReactEditor.findPath(editor, element), isBefore = Path.isBefore(myPath, targetPath);
|
|
588
588
|
if (dragPosition === "bottom" && !isBefore) {
|
|
589
589
|
if (targetPath[0] >= editor.children.length - 1) {
|
|
590
|
-
debug$
|
|
590
|
+
debug$j("target is already at the bottom, not moving");
|
|
591
591
|
return;
|
|
592
592
|
}
|
|
593
593
|
const originalPath = targetPath;
|
|
594
|
-
targetPath = Path.next(targetPath), debug$
|
|
594
|
+
targetPath = Path.next(targetPath), debug$j(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
|
|
595
595
|
}
|
|
596
596
|
if (dragPosition === "top" && isBefore && targetPath[0] !== editor.children.length - 1) {
|
|
597
597
|
const originalPath_0 = targetPath;
|
|
598
|
-
targetPath = Path.previous(targetPath), debug$
|
|
598
|
+
targetPath = Path.previous(targetPath), debug$j(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
|
|
599
599
|
}
|
|
600
600
|
if (Path.equals(targetPath, myPath)) {
|
|
601
|
-
event_0.preventDefault(), debug$
|
|
601
|
+
event_0.preventDefault(), debug$j("targetPath and myPath is the same, not moving");
|
|
602
602
|
return;
|
|
603
603
|
}
|
|
604
|
-
debug$
|
|
604
|
+
debug$j(`Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), Transforms.moveNodes(editor, {
|
|
605
605
|
at: myPath,
|
|
606
606
|
to: targetPath
|
|
607
607
|
}), editor.onChange();
|
|
608
608
|
return;
|
|
609
609
|
}
|
|
610
|
-
debug$
|
|
610
|
+
debug$j("No target element, not doing anything");
|
|
611
611
|
}, $[16] = editor, $[17] = element, $[18] = t9) : t9 = $[18];
|
|
612
612
|
const handleDragEnd = t9;
|
|
613
613
|
let t10;
|
|
614
614
|
$[19] !== editor || $[20] !== element ? (t10 = (event_1) => {
|
|
615
|
-
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$
|
|
615
|
+
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$j("On drop (prevented)", element), event_1.preventDefault(), event_1.stopPropagation(), setIsDragOver(!1));
|
|
616
616
|
}, $[19] = editor, $[20] = element, $[21] = t10) : t10 = $[21];
|
|
617
617
|
const handleDrop = t10;
|
|
618
618
|
let t11;
|
|
@@ -629,10 +629,10 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
629
629
|
let t12;
|
|
630
630
|
$[26] !== blockElement || $[27] !== editor || $[28] !== handleDrag || $[29] !== isInline || $[30] !== isVoid ? (t12 = (event_3) => {
|
|
631
631
|
if (!isVoid || isInline) {
|
|
632
|
-
debug$
|
|
632
|
+
debug$j("Not dragging block"), IS_DRAGGING_BLOCK_ELEMENT.delete(editor), IS_DRAGGING.set(editor, !1);
|
|
633
633
|
return;
|
|
634
634
|
}
|
|
635
|
-
if (debug$
|
|
635
|
+
if (debug$j("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) {
|
|
636
636
|
let dragGhost = blockElement.cloneNode(!0);
|
|
637
637
|
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
638
638
|
if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
|
|
@@ -1907,7 +1907,7 @@ function isRedoing(editor) {
|
|
|
1907
1907
|
function setIsRedoing(editor, isRedoing2) {
|
|
1908
1908
|
IS_REDOING.set(editor, isRedoing2);
|
|
1909
1909
|
}
|
|
1910
|
-
const debug$
|
|
1910
|
+
const debug$i = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
1911
1911
|
const state = SAVING.get(editor);
|
|
1912
1912
|
return state === void 0 ? !0 : state;
|
|
1913
1913
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -1920,7 +1920,7 @@ function createWithUndoRedo(options) {
|
|
|
1920
1920
|
let previousSnapshot = fromSlateValue(editor.children, blockSchemaType.name);
|
|
1921
1921
|
const remotePatches = getRemotePatches(editor);
|
|
1922
1922
|
options.subscriptions.push(() => {
|
|
1923
|
-
debug$
|
|
1923
|
+
debug$i("Subscribing to patches");
|
|
1924
1924
|
const sub = editorActor.on("patches", ({
|
|
1925
1925
|
patches,
|
|
1926
1926
|
snapshot
|
|
@@ -1929,7 +1929,7 @@ function createWithUndoRedo(options) {
|
|
|
1929
1929
|
patches.forEach((patch) => {
|
|
1930
1930
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
1931
1931
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
1932
|
-
debug$
|
|
1932
|
+
debug$i("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
1933
1933
|
undos: [],
|
|
1934
1934
|
redos: []
|
|
1935
1935
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -1945,7 +1945,7 @@ function createWithUndoRedo(options) {
|
|
|
1945
1945
|
}), previousSnapshot = snapshot;
|
|
1946
1946
|
});
|
|
1947
1947
|
return () => {
|
|
1948
|
-
debug$
|
|
1948
|
+
debug$i("Unsubscribing to patches"), sub.unsubscribe();
|
|
1949
1949
|
};
|
|
1950
1950
|
}), editor.history = {
|
|
1951
1951
|
undos: [],
|
|
@@ -1984,7 +1984,7 @@ function createWithUndoRedo(options) {
|
|
|
1984
1984
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
1985
1985
|
timestamp: /* @__PURE__ */ new Date()
|
|
1986
1986
|
};
|
|
1987
|
-
undos.push(newStep), debug$
|
|
1987
|
+
undos.push(newStep), debug$i("Created new undo step", step);
|
|
1988
1988
|
}
|
|
1989
1989
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
1990
1990
|
undos.shift();
|
|
@@ -2001,7 +2001,7 @@ function createWithUndoRedo(options) {
|
|
|
2001
2001
|
} = editor.history;
|
|
2002
2002
|
if (undos.length > 0) {
|
|
2003
2003
|
const step = undos[undos.length - 1];
|
|
2004
|
-
if (debug$
|
|
2004
|
+
if (debug$i("Undoing", step), step.operations.length > 0) {
|
|
2005
2005
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2006
2006
|
let transformedOperations = step.operations;
|
|
2007
2007
|
otherPatches.forEach((item) => {
|
|
@@ -2019,7 +2019,7 @@ function createWithUndoRedo(options) {
|
|
|
2019
2019
|
});
|
|
2020
2020
|
}), editor.normalize(), editor.onChange();
|
|
2021
2021
|
} catch (err) {
|
|
2022
|
-
debug$
|
|
2022
|
+
debug$i("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
2023
2023
|
undos: [],
|
|
2024
2024
|
redos: []
|
|
2025
2025
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -2038,7 +2038,7 @@ function createWithUndoRedo(options) {
|
|
|
2038
2038
|
} = editor.history;
|
|
2039
2039
|
if (redos.length > 0) {
|
|
2040
2040
|
const step = redos[redos.length - 1];
|
|
2041
|
-
if (debug$
|
|
2041
|
+
if (debug$i("Redoing", step), step.operations.length > 0) {
|
|
2042
2042
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2043
2043
|
let transformedOperations = step.operations;
|
|
2044
2044
|
otherPatches.forEach((item) => {
|
|
@@ -2055,7 +2055,7 @@ function createWithUndoRedo(options) {
|
|
|
2055
2055
|
});
|
|
2056
2056
|
}), editor.normalize(), editor.onChange();
|
|
2057
2057
|
} catch (err) {
|
|
2058
|
-
debug$
|
|
2058
|
+
debug$i("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
2059
2059
|
undos: [],
|
|
2060
2060
|
redos: []
|
|
2061
2061
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -2068,7 +2068,6 @@ function createWithUndoRedo(options) {
|
|
|
2068
2068
|
};
|
|
2069
2069
|
}
|
|
2070
2070
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2071
|
-
debugVerbose$3 && (debug$j(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$j(`Operation ${JSON.stringify(operation)}`), debug$j(`Patch ${JSON.stringify(patch)}`));
|
|
2072
2071
|
const transformedOperation = {
|
|
2073
2072
|
...operation
|
|
2074
2073
|
};
|
|
@@ -2076,16 +2075,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2076
2075
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
2077
2076
|
_key: blk._key
|
|
2078
2077
|
}, patch.path[0]));
|
|
2079
|
-
return debug$
|
|
2078
|
+
return debug$i(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
2080
2079
|
}
|
|
2081
2080
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
2082
2081
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
|
|
2083
2082
|
_key: blk._key
|
|
2084
2083
|
}, patch.path[0]));
|
|
2085
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
2084
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$i("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
2086
2085
|
}
|
|
2087
2086
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2088
|
-
return debug$
|
|
2087
|
+
return debug$i(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
2089
2088
|
if (patch.type === "diffMatchPatch") {
|
|
2090
2089
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2091
2090
|
return !operationTargetBlock || !isEqual({
|
|
@@ -2365,7 +2364,7 @@ const syncValueCallback = ({
|
|
|
2365
2364
|
}
|
|
2366
2365
|
}
|
|
2367
2366
|
}
|
|
2368
|
-
}), debug$
|
|
2367
|
+
}), debug$h = debugWithName("hook:useSyncValue");
|
|
2369
2368
|
async function updateValue({
|
|
2370
2369
|
context,
|
|
2371
2370
|
sendBack,
|
|
@@ -2375,7 +2374,7 @@ async function updateValue({
|
|
|
2375
2374
|
}) {
|
|
2376
2375
|
let isChanged = !1, isValid = !0;
|
|
2377
2376
|
const hadSelection = !!slateEditor.selection;
|
|
2378
|
-
if ((!value || value.length === 0) && (debug$
|
|
2377
|
+
if ((!value || value.length === 0) && (debug$h("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
|
|
2379
2378
|
withoutSaving(slateEditor, () => {
|
|
2380
2379
|
withoutPatching(slateEditor, () => {
|
|
2381
2380
|
hadSelection && Transforms.deselect(slateEditor);
|
|
@@ -2431,14 +2430,14 @@ async function updateValue({
|
|
|
2431
2430
|
});
|
|
2432
2431
|
}
|
|
2433
2432
|
if (!isValid) {
|
|
2434
|
-
debug$
|
|
2433
|
+
debug$h("Invalid value, returning"), sendBack({
|
|
2435
2434
|
type: "done syncing",
|
|
2436
2435
|
value
|
|
2437
2436
|
});
|
|
2438
2437
|
return;
|
|
2439
2438
|
}
|
|
2440
2439
|
if (isChanged) {
|
|
2441
|
-
debug$
|
|
2440
|
+
debug$h("Server value changed, syncing editor");
|
|
2442
2441
|
try {
|
|
2443
2442
|
slateEditor.onChange();
|
|
2444
2443
|
} catch (err) {
|
|
@@ -2466,7 +2465,7 @@ async function updateValue({
|
|
|
2466
2465
|
value
|
|
2467
2466
|
});
|
|
2468
2467
|
} else
|
|
2469
|
-
debug$
|
|
2468
|
+
debug$h("Server value and editor value is equal, no need to sync.");
|
|
2470
2469
|
sendBack({
|
|
2471
2470
|
type: "done syncing",
|
|
2472
2471
|
value
|
|
@@ -2500,7 +2499,7 @@ function syncBlock({
|
|
|
2500
2499
|
type: "patch",
|
|
2501
2500
|
patch
|
|
2502
2501
|
});
|
|
2503
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
2502
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$h.enabled && debug$h("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$h.enabled && debug$h("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
2504
2503
|
type: "invalid value",
|
|
2505
2504
|
resolution: validation.resolution,
|
|
2506
2505
|
value
|
|
@@ -2508,9 +2507,9 @@ function syncBlock({
|
|
|
2508
2507
|
}
|
|
2509
2508
|
if (!oldBlock && blockValid) {
|
|
2510
2509
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2511
|
-
debug$
|
|
2510
|
+
debug$h.enabled && debug$h("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2512
2511
|
at: [currentBlockIndex]
|
|
2513
|
-
}) : (debug$
|
|
2512
|
+
}) : (debug$h("Invalid", validation), sendBack({
|
|
2514
2513
|
type: "invalid value",
|
|
2515
2514
|
resolution: validation.resolution,
|
|
2516
2515
|
value
|
|
@@ -2538,14 +2537,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2538
2537
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
2539
2538
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
2540
2539
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
2541
|
-
childIndex > 0 && (debug$
|
|
2540
|
+
childIndex > 0 && (debug$h("Removing child"), Transforms.removeNodes(slateEditor, {
|
|
2542
2541
|
at: [currentBlockIndex, childIndex]
|
|
2543
2542
|
}));
|
|
2544
2543
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
2545
2544
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2546
2545
|
if (isChildChanged)
|
|
2547
2546
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2548
|
-
debug$
|
|
2547
|
+
debug$h("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2549
2548
|
at: path
|
|
2550
2549
|
});
|
|
2551
2550
|
const isSpanNode = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -2562,23 +2561,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2562
2561
|
}
|
|
2563
2562
|
}), Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
2564
2563
|
at: path
|
|
2565
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
2564
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$h("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
|
|
2566
2565
|
_key: VOID_CHILD_KEY
|
|
2567
2566
|
}, {
|
|
2568
2567
|
at: [...path, 0],
|
|
2569
2568
|
voids: !0
|
|
2570
2569
|
}));
|
|
2571
|
-
} else oldBlockChild ? (debug$
|
|
2570
|
+
} else oldBlockChild ? (debug$h("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
|
|
2572
2571
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2573
2572
|
}), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2574
2573
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2575
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
2574
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$h("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2576
2575
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2577
2576
|
}), slateEditor.onChange());
|
|
2578
2577
|
});
|
|
2579
2578
|
}
|
|
2580
2579
|
}
|
|
2581
|
-
const debug$
|
|
2580
|
+
const debug$g = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
2582
2581
|
function Synchronizer(props) {
|
|
2583
2582
|
const $ = c(40), {
|
|
2584
2583
|
editorActor,
|
|
@@ -2649,19 +2648,19 @@ function Synchronizer(props) {
|
|
|
2649
2648
|
}, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), useEffect(t11, t12);
|
|
2650
2649
|
let t13, t14;
|
|
2651
2650
|
$[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
|
|
2652
|
-
debug$
|
|
2651
|
+
debug$g("Value from props changed, syncing new value"), syncActorRef.send({
|
|
2653
2652
|
type: "update value",
|
|
2654
2653
|
value
|
|
2655
2654
|
});
|
|
2656
2655
|
}, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), useEffect(t13, t14);
|
|
2657
2656
|
let t15;
|
|
2658
2657
|
$[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
|
|
2659
|
-
debug$
|
|
2658
|
+
debug$g("Subscribing to patch events");
|
|
2660
2659
|
const sub = editorActor.on("patch", (event_1) => {
|
|
2661
2660
|
mutationActorRef.send(event_1);
|
|
2662
2661
|
});
|
|
2663
2662
|
return () => {
|
|
2664
|
-
debug$
|
|
2663
|
+
debug$g("Unsubscribing to patch events"), sub.unsubscribe();
|
|
2665
2664
|
};
|
|
2666
2665
|
}, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
|
|
2667
2666
|
let t16;
|
|
@@ -2676,11 +2675,11 @@ function _temp(s) {
|
|
|
2676
2675
|
return s.context.value;
|
|
2677
2676
|
}
|
|
2678
2677
|
Synchronizer.displayName = "Synchronizer";
|
|
2679
|
-
const debug$
|
|
2678
|
+
const debug$f = debugWithName("operationToPatches");
|
|
2680
2679
|
function createOperationToPatches(types) {
|
|
2681
2680
|
const textBlockName = types.block.name;
|
|
2682
2681
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
2683
|
-
debug$
|
|
2682
|
+
debug$f.enabled && debug$f("Operation", JSON.stringify(operation, null, 2));
|
|
2684
2683
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
2685
2684
|
if (!block)
|
|
2686
2685
|
throw new Error("Could not find block");
|
|
@@ -2773,7 +2772,7 @@ function createOperationToPatches(types) {
|
|
|
2773
2772
|
_key: block.children[operation.path[1] - 1]._key
|
|
2774
2773
|
}])];
|
|
2775
2774
|
}
|
|
2776
|
-
return debug$
|
|
2775
|
+
return debug$f("Something was inserted into a void block. Not producing editor patches."), [];
|
|
2777
2776
|
}
|
|
2778
2777
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
2779
2778
|
const patches = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -2831,9 +2830,9 @@ function createOperationToPatches(types) {
|
|
|
2831
2830
|
_key: block._key
|
|
2832
2831
|
}, "children", {
|
|
2833
2832
|
_key: spanToRemove._key
|
|
2834
|
-
}])] : (debug$
|
|
2833
|
+
}])] : (debug$f("Span not found in editor trying to remove node"), []);
|
|
2835
2834
|
} else
|
|
2836
|
-
return debug$
|
|
2835
|
+
return debug$f("Not creating patch inside object block"), [];
|
|
2837
2836
|
}
|
|
2838
2837
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2839
2838
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -2859,7 +2858,7 @@ function createOperationToPatches(types) {
|
|
|
2859
2858
|
_key: removedSpan._key
|
|
2860
2859
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
2861
2860
|
} else
|
|
2862
|
-
debug$
|
|
2861
|
+
debug$f("Void nodes can't be merged, not creating any patches");
|
|
2863
2862
|
return patches;
|
|
2864
2863
|
}
|
|
2865
2864
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -2898,9 +2897,19 @@ function createOperationToPatches(types) {
|
|
|
2898
2897
|
splitNodePatch
|
|
2899
2898
|
};
|
|
2900
2899
|
}
|
|
2900
|
+
const IS_APPLYING_BEHAVIOR_ACTIONS = /* @__PURE__ */ new WeakMap();
|
|
2901
|
+
function withApplyingBehaviorActions(editor, fn) {
|
|
2902
|
+
const prev = isApplyingBehaviorActions(editor);
|
|
2903
|
+
IS_APPLYING_BEHAVIOR_ACTIONS.set(editor, !0), fn(), IS_APPLYING_BEHAVIOR_ACTIONS.set(editor, prev);
|
|
2904
|
+
}
|
|
2905
|
+
function isApplyingBehaviorActions(editor) {
|
|
2906
|
+
return IS_APPLYING_BEHAVIOR_ACTIONS.get(editor) ?? !1;
|
|
2907
|
+
}
|
|
2901
2908
|
function createWithEventListeners(editorActor, subscriptions) {
|
|
2902
2909
|
return function(editor) {
|
|
2903
|
-
|
|
2910
|
+
if (editorActor.getSnapshot().context.maxBlocks !== void 0)
|
|
2911
|
+
return editor;
|
|
2912
|
+
subscriptions.push(() => {
|
|
2904
2913
|
const subscription = editorActor.on("*", (event) => {
|
|
2905
2914
|
switch (event.type) {
|
|
2906
2915
|
case "annotation.add": {
|
|
@@ -2925,17 +2934,6 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2925
2934
|
});
|
|
2926
2935
|
break;
|
|
2927
2936
|
}
|
|
2928
|
-
case "annotation.toggle": {
|
|
2929
|
-
editorActor.send({
|
|
2930
|
-
type: "behavior event",
|
|
2931
|
-
behaviorEvent: {
|
|
2932
|
-
type: "annotation.toggle",
|
|
2933
|
-
annotation: event.annotation
|
|
2934
|
-
},
|
|
2935
|
-
editor
|
|
2936
|
-
});
|
|
2937
|
-
break;
|
|
2938
|
-
}
|
|
2939
2937
|
case "blur": {
|
|
2940
2938
|
editorActor.send({
|
|
2941
2939
|
type: "behavior event",
|
|
@@ -2946,28 +2944,6 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2946
2944
|
});
|
|
2947
2945
|
break;
|
|
2948
2946
|
}
|
|
2949
|
-
case "decorator.add": {
|
|
2950
|
-
editorActor.send({
|
|
2951
|
-
type: "behavior event",
|
|
2952
|
-
behaviorEvent: {
|
|
2953
|
-
type: "decorator.add",
|
|
2954
|
-
decorator: event.decorator
|
|
2955
|
-
},
|
|
2956
|
-
editor
|
|
2957
|
-
});
|
|
2958
|
-
break;
|
|
2959
|
-
}
|
|
2960
|
-
case "decorator.remove": {
|
|
2961
|
-
editorActor.send({
|
|
2962
|
-
type: "behavior event",
|
|
2963
|
-
behaviorEvent: {
|
|
2964
|
-
type: "decorator.remove",
|
|
2965
|
-
decorator: event.decorator
|
|
2966
|
-
},
|
|
2967
|
-
editor
|
|
2968
|
-
});
|
|
2969
|
-
break;
|
|
2970
|
-
}
|
|
2971
2947
|
case "decorator.toggle": {
|
|
2972
2948
|
editorActor.send({
|
|
2973
2949
|
type: "behavior event",
|
|
@@ -3023,6 +2999,17 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
3023
2999
|
});
|
|
3024
3000
|
break;
|
|
3025
3001
|
}
|
|
3002
|
+
case "select": {
|
|
3003
|
+
editorActor.send({
|
|
3004
|
+
type: "behavior event",
|
|
3005
|
+
behaviorEvent: {
|
|
3006
|
+
type: "select",
|
|
3007
|
+
selection: event.selection
|
|
3008
|
+
},
|
|
3009
|
+
editor
|
|
3010
|
+
});
|
|
3011
|
+
break;
|
|
3012
|
+
}
|
|
3026
3013
|
case "style.toggle": {
|
|
3027
3014
|
editorActor.send({
|
|
3028
3015
|
type: "behavior event",
|
|
@@ -3039,25 +3026,11 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
3039
3026
|
return () => {
|
|
3040
3027
|
subscription.unsubscribe();
|
|
3041
3028
|
};
|
|
3042
|
-
})
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
decorator: mark
|
|
3048
|
-
},
|
|
3049
|
-
editor
|
|
3050
|
-
});
|
|
3051
|
-
}, editor.removeMark = (mark) => {
|
|
3052
|
-
editorActor.send({
|
|
3053
|
-
type: "behavior event",
|
|
3054
|
-
behaviorEvent: {
|
|
3055
|
-
type: "decorator.remove",
|
|
3056
|
-
decorator: mark
|
|
3057
|
-
},
|
|
3058
|
-
editor
|
|
3059
|
-
});
|
|
3060
|
-
}, editor.deleteBackward = (unit) => {
|
|
3029
|
+
});
|
|
3030
|
+
const {
|
|
3031
|
+
select
|
|
3032
|
+
} = editor;
|
|
3033
|
+
return editor.deleteBackward = (unit) => {
|
|
3061
3034
|
editorActor.send({
|
|
3062
3035
|
type: "behavior event",
|
|
3063
3036
|
behaviorEvent: {
|
|
@@ -3101,7 +3074,21 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
3101
3074
|
},
|
|
3102
3075
|
editor
|
|
3103
3076
|
});
|
|
3104
|
-
}
|
|
3077
|
+
}, editor.select = (location) => {
|
|
3078
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
3079
|
+
select(location);
|
|
3080
|
+
return;
|
|
3081
|
+
}
|
|
3082
|
+
const range = Editor.range(editor, location);
|
|
3083
|
+
editorActor.send({
|
|
3084
|
+
type: "behavior event",
|
|
3085
|
+
behaviorEvent: {
|
|
3086
|
+
type: "select",
|
|
3087
|
+
selection: toPortableTextRange(fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), range, editorActor.getSnapshot().context.schema)
|
|
3088
|
+
},
|
|
3089
|
+
editor
|
|
3090
|
+
});
|
|
3091
|
+
}, editor;
|
|
3105
3092
|
};
|
|
3106
3093
|
}
|
|
3107
3094
|
function createWithMaxBlocks(editorActor) {
|
|
@@ -3198,13 +3185,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3198
3185
|
}, editor;
|
|
3199
3186
|
};
|
|
3200
3187
|
}
|
|
3201
|
-
const debug$
|
|
3188
|
+
const debug$e = debugWithName("applyPatches"), debugVerbose = debug$e.enabled && !0;
|
|
3202
3189
|
function createApplyPatch(schemaTypes) {
|
|
3203
3190
|
return (editor, patch) => {
|
|
3204
3191
|
let changed = !1;
|
|
3205
|
-
debugVerbose
|
|
3192
|
+
debugVerbose && (debug$e(`
|
|
3206
3193
|
|
|
3207
|
-
NEW PATCH =============================================================`), debug$
|
|
3194
|
+
NEW PATCH =============================================================`), debug$e(JSON.stringify(patch, null, 2)));
|
|
3208
3195
|
try {
|
|
3209
3196
|
switch (patch.type) {
|
|
3210
3197
|
case "insert":
|
|
@@ -3220,7 +3207,7 @@ NEW PATCH =============================================================`), debug
|
|
|
3220
3207
|
changed = diffMatchPatch(editor, patch);
|
|
3221
3208
|
break;
|
|
3222
3209
|
default:
|
|
3223
|
-
debug$
|
|
3210
|
+
debug$e("Unhandled patch", patch.type);
|
|
3224
3211
|
}
|
|
3225
3212
|
} catch (err) {
|
|
3226
3213
|
console.error(err);
|
|
@@ -3235,9 +3222,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
3235
3222
|
childPath
|
|
3236
3223
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3237
3224
|
if (!block)
|
|
3238
|
-
return debug$
|
|
3225
|
+
return debug$e("Block not found"), !1;
|
|
3239
3226
|
if (!child || !childPath)
|
|
3240
|
-
return debug$
|
|
3227
|
+
return debug$e("Child not found"), !1;
|
|
3241
3228
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !Text.isText(child))
|
|
3242
3229
|
return !1;
|
|
3243
3230
|
const patches = parse(patch.value), [newValue] = apply(patches, child.text, {
|
|
@@ -3267,9 +3254,9 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3267
3254
|
childPath: targetChildPath
|
|
3268
3255
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3269
3256
|
if (!targetBlock || !targetBlockPath)
|
|
3270
|
-
return debug$
|
|
3257
|
+
return debug$e("Block not found"), !1;
|
|
3271
3258
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
3272
|
-
return debug$
|
|
3259
|
+
return debug$e("Ignoring patch targeting void value"), !1;
|
|
3273
3260
|
if (patch.path.length === 1) {
|
|
3274
3261
|
const {
|
|
3275
3262
|
items: items2,
|
|
@@ -3277,7 +3264,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3277
3264
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
3278
3265
|
schemaTypes
|
|
3279
3266
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
3280
|
-
return debug$
|
|
3267
|
+
return debug$e(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
|
|
3281
3268
|
at: [normalizedIdx2]
|
|
3282
3269
|
}), debugState(editor, "after"), !0;
|
|
3283
3270
|
}
|
|
@@ -3286,14 +3273,14 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3286
3273
|
position
|
|
3287
3274
|
} = patch;
|
|
3288
3275
|
if (!targetChild || !targetChildPath)
|
|
3289
|
-
return debug$
|
|
3276
|
+
return debug$e("Child not found"), !1;
|
|
3290
3277
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3291
3278
|
...targetBlock,
|
|
3292
3279
|
children: items
|
|
3293
3280
|
}], {
|
|
3294
3281
|
schemaTypes
|
|
3295
3282
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3296
|
-
return debug$
|
|
3283
|
+
return debug$e(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
3297
3284
|
at: childInsertPath
|
|
3298
3285
|
}), debugState(editor, "after"), !0;
|
|
3299
3286
|
}
|
|
@@ -3307,14 +3294,14 @@ function setPatch(editor, patch) {
|
|
|
3307
3294
|
childPath
|
|
3308
3295
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3309
3296
|
if (!block)
|
|
3310
|
-
return debug$
|
|
3297
|
+
return debug$e("Block not found"), !1;
|
|
3311
3298
|
const isTextBlock = editor.isTextBlock(block);
|
|
3312
3299
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
3313
|
-
return debug$
|
|
3300
|
+
return debug$e("Ignoring setting void value"), !1;
|
|
3314
3301
|
if (debugState(editor, "before"), isTextBlock && child && childPath) {
|
|
3315
3302
|
if (Text.isText(value) && Text.isText(child)) {
|
|
3316
3303
|
const newText = child.text;
|
|
3317
|
-
value.text !== newText && (debug$
|
|
3304
|
+
value.text !== newText && (debug$e("Setting text property"), editor.apply({
|
|
3318
3305
|
type: "remove_text",
|
|
3319
3306
|
path: childPath,
|
|
3320
3307
|
offset: 0,
|
|
@@ -3326,7 +3313,7 @@ function setPatch(editor, patch) {
|
|
|
3326
3313
|
text: value.text
|
|
3327
3314
|
}), editor.onChange());
|
|
3328
3315
|
} else
|
|
3329
|
-
debug$
|
|
3316
|
+
debug$e("Setting non-text property"), editor.apply({
|
|
3330
3317
|
type: "set_node",
|
|
3331
3318
|
path: childPath,
|
|
3332
3319
|
properties: {},
|
|
@@ -3334,7 +3321,7 @@ function setPatch(editor, patch) {
|
|
|
3334
3321
|
});
|
|
3335
3322
|
return !0;
|
|
3336
3323
|
} else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3337
|
-
debug$
|
|
3324
|
+
debug$e("Setting block property");
|
|
3338
3325
|
const {
|
|
3339
3326
|
children,
|
|
3340
3327
|
...nextRest
|
|
@@ -3351,7 +3338,7 @@ function setPatch(editor, patch) {
|
|
|
3351
3338
|
...prevRest
|
|
3352
3339
|
},
|
|
3353
3340
|
newProperties: nextRest
|
|
3354
|
-
}), debug$
|
|
3341
|
+
}), debug$e("Setting children"), block.children.forEach((c2, cIndex) => {
|
|
3355
3342
|
editor.apply({
|
|
3356
3343
|
type: "remove_node",
|
|
3357
3344
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -3377,7 +3364,7 @@ function setPatch(editor, patch) {
|
|
|
3377
3364
|
}
|
|
3378
3365
|
function unsetPatch(editor, patch) {
|
|
3379
3366
|
if (patch.path.length === 0) {
|
|
3380
|
-
debug$
|
|
3367
|
+
debug$e("Removing everything"), debugState(editor, "before");
|
|
3381
3368
|
const previousSelection = editor.selection;
|
|
3382
3369
|
return Transforms.deselect(editor), editor.children.forEach((_child, i) => {
|
|
3383
3370
|
Transforms.removeNodes(editor, {
|
|
@@ -3404,13 +3391,13 @@ function unsetPatch(editor, patch) {
|
|
|
3404
3391
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3405
3392
|
if (patch.path.length === 1) {
|
|
3406
3393
|
if (!block || !blockPath)
|
|
3407
|
-
return debug$
|
|
3394
|
+
return debug$e("Block not found"), !1;
|
|
3408
3395
|
const blockIndex = blockPath[0];
|
|
3409
|
-
return debug$
|
|
3396
|
+
return debug$e(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
|
|
3410
3397
|
at: [blockIndex]
|
|
3411
3398
|
}), debugState(editor, "after"), !0;
|
|
3412
3399
|
}
|
|
3413
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
3400
|
+
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$e("Child not found"), !1) : (debug$e(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$e(`Removing child at path ${JSON.stringify(childPath)}`), Transforms.removeNodes(editor, {
|
|
3414
3401
|
at: childPath
|
|
3415
3402
|
}), debugState(editor, "after"), !0) : !1;
|
|
3416
3403
|
}
|
|
@@ -3418,7 +3405,7 @@ function isKeyedSegment(segment) {
|
|
|
3418
3405
|
return typeof segment == "object" && "_key" in segment;
|
|
3419
3406
|
}
|
|
3420
3407
|
function debugState(editor, stateName) {
|
|
3421
|
-
debugVerbose
|
|
3408
|
+
debugVerbose && (debug$e(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$e(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
3422
3409
|
}
|
|
3423
3410
|
function findBlockFromPath(editor, path) {
|
|
3424
3411
|
let blockIndex = -1;
|
|
@@ -3460,7 +3447,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3460
3447
|
childPath: void 0
|
|
3461
3448
|
};
|
|
3462
3449
|
}
|
|
3463
|
-
const debug$
|
|
3450
|
+
const debug$d = debugWithName("plugin:withPatches");
|
|
3464
3451
|
function createWithPatches({
|
|
3465
3452
|
editorActor,
|
|
3466
3453
|
patchFunctions,
|
|
@@ -3486,7 +3473,7 @@ function createWithPatches({
|
|
|
3486
3473
|
withoutPatching(editor, () => {
|
|
3487
3474
|
withoutSaving(editor, () => {
|
|
3488
3475
|
patches.forEach((patch) => {
|
|
3489
|
-
debug$
|
|
3476
|
+
debug$d.enabled && debug$d(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
3490
3477
|
});
|
|
3491
3478
|
});
|
|
3492
3479
|
});
|
|
@@ -3499,10 +3486,10 @@ function createWithPatches({
|
|
|
3499
3486
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
3500
3487
|
};
|
|
3501
3488
|
return subscriptions.push(() => {
|
|
3502
|
-
debug$
|
|
3489
|
+
debug$d("Subscribing to remote patches");
|
|
3503
3490
|
const sub = editorActor.on("patches", handlePatches);
|
|
3504
3491
|
return () => {
|
|
3505
|
-
debug$
|
|
3492
|
+
debug$d("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
3506
3493
|
};
|
|
3507
3494
|
}), editor.apply = (operation) => {
|
|
3508
3495
|
let patches = [];
|
|
@@ -3553,7 +3540,7 @@ function createWithPatches({
|
|
|
3553
3540
|
}, editor;
|
|
3554
3541
|
};
|
|
3555
3542
|
}
|
|
3556
|
-
const debug$
|
|
3543
|
+
const debug$c = debugWithName("plugin:withPlaceholderBlock");
|
|
3557
3544
|
function createWithPlaceholderBlock(editorActor) {
|
|
3558
3545
|
return function(editor) {
|
|
3559
3546
|
const {
|
|
@@ -3578,7 +3565,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3578
3565
|
const node = op.node;
|
|
3579
3566
|
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
3580
3567
|
const nextPath = Path.next(op.path);
|
|
3581
|
-
editor.children[nextPath[0]] || (debug$
|
|
3568
|
+
editor.children[nextPath[0]] || (debug$c("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
3582
3569
|
decorators: []
|
|
3583
3570
|
})));
|
|
3584
3571
|
}
|
|
@@ -3587,7 +3574,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3587
3574
|
}, editor;
|
|
3588
3575
|
};
|
|
3589
3576
|
}
|
|
3590
|
-
const debug$
|
|
3577
|
+
const debug$b = debugWithName("plugin:withPortableTextBlockStyle");
|
|
3591
3578
|
function createWithPortableTextBlockStyle(editorActor, types) {
|
|
3592
3579
|
const defaultStyle = types.styles[0].value;
|
|
3593
3580
|
return function(editor) {
|
|
@@ -3600,7 +3587,7 @@ function createWithPortableTextBlockStyle(editorActor, types) {
|
|
|
3600
3587
|
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)) {
|
|
3601
3588
|
const [child] = Editor.node(editor, [op.path[0] + 1, 0]);
|
|
3602
3589
|
if (Text.isText(child) && child.text === "") {
|
|
3603
|
-
debug$
|
|
3590
|
+
debug$b(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
3604
3591
|
type: "normalizing"
|
|
3605
3592
|
}), Transforms.setNodes(editor, {
|
|
3606
3593
|
style: defaultStyle
|
|
@@ -3660,7 +3647,7 @@ function getNextSpan({
|
|
|
3660
3647
|
}
|
|
3661
3648
|
return nextSpan;
|
|
3662
3649
|
}
|
|
3663
|
-
const debug$
|
|
3650
|
+
const debug$a = debugWithName("plugin:withPortableTextMarkModel");
|
|
3664
3651
|
function createWithPortableTextMarkModel(editorActor, types) {
|
|
3665
3652
|
return function(editor) {
|
|
3666
3653
|
const {
|
|
@@ -3674,7 +3661,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3674
3661
|
for (const [child, childPath] of children) {
|
|
3675
3662
|
const nextNode = node.children[childPath[1] + 1];
|
|
3676
3663
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3677
|
-
debug$
|
|
3664
|
+
debug$a("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3678
3665
|
type: "normalizing"
|
|
3679
3666
|
}), Transforms.mergeNodes(editor, {
|
|
3680
3667
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -3687,7 +3674,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3687
3674
|
}
|
|
3688
3675
|
}
|
|
3689
3676
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3690
|
-
debug$
|
|
3677
|
+
debug$a("Adding .markDefs to block node"), editorActor.send({
|
|
3691
3678
|
type: "normalizing"
|
|
3692
3679
|
}), Transforms.setNodes(editor, {
|
|
3693
3680
|
markDefs: []
|
|
@@ -3699,7 +3686,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3699
3686
|
return;
|
|
3700
3687
|
}
|
|
3701
3688
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3702
|
-
debug$
|
|
3689
|
+
debug$a("Adding .marks to span node"), editorActor.send({
|
|
3703
3690
|
type: "normalizing"
|
|
3704
3691
|
}), Transforms.setNodes(editor, {
|
|
3705
3692
|
marks: []
|
|
@@ -3713,7 +3700,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3713
3700
|
if (editor.isTextSpan(node)) {
|
|
3714
3701
|
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));
|
|
3715
3702
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3716
|
-
debug$
|
|
3703
|
+
debug$a("Removing annotations from empty span node"), editorActor.send({
|
|
3717
3704
|
type: "normalizing"
|
|
3718
3705
|
}), Transforms.setNodes(editor, {
|
|
3719
3706
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -3731,7 +3718,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3731
3718
|
if (editor.isTextSpan(child)) {
|
|
3732
3719
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3733
3720
|
if (orphanedAnnotations.length > 0) {
|
|
3734
|
-
debug$
|
|
3721
|
+
debug$a("Removing orphaned annotations from span node"), editorActor.send({
|
|
3735
3722
|
type: "normalizing"
|
|
3736
3723
|
}), Transforms.setNodes(editor, {
|
|
3737
3724
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3749,7 +3736,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3749
3736
|
if (editor.isTextBlock(block)) {
|
|
3750
3737
|
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));
|
|
3751
3738
|
if (orphanedAnnotations.length > 0) {
|
|
3752
|
-
debug$
|
|
3739
|
+
debug$a("Removing orphaned annotations from span node"), editorActor.send({
|
|
3753
3740
|
type: "normalizing"
|
|
3754
3741
|
}), Transforms.setNodes(editor, {
|
|
3755
3742
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3767,7 +3754,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3767
3754
|
for (const markDef of markDefs)
|
|
3768
3755
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3769
3756
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3770
|
-
debug$
|
|
3757
|
+
debug$a("Removing duplicate markDefs"), editorActor.send({
|
|
3771
3758
|
type: "normalizing"
|
|
3772
3759
|
}), Transforms.setNodes(editor, {
|
|
3773
3760
|
markDefs: newMarkDefs
|
|
@@ -3782,7 +3769,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3782
3769
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3783
3770
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3784
3771
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
3785
|
-
debug$
|
|
3772
|
+
debug$a("Removing markDef not in use"), editorActor.send({
|
|
3786
3773
|
type: "normalizing"
|
|
3787
3774
|
}), Transforms.setNodes(editor, {
|
|
3788
3775
|
markDefs: newMarkDefs
|
|
@@ -3999,7 +3986,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3999
3986
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
4000
3987
|
if (editor.isTextBlock(targetBlock)) {
|
|
4001
3988
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
4002
|
-
debug$
|
|
3989
|
+
debug$a("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
4003
3990
|
markDefs: newMarkDefs
|
|
4004
3991
|
}, {
|
|
4005
3992
|
at: targetPath,
|
|
@@ -4060,7 +4047,12 @@ const addDecoratorActionImplementation = ({
|
|
|
4060
4047
|
editor.marks = marks;
|
|
4061
4048
|
}
|
|
4062
4049
|
}
|
|
4063
|
-
editor.
|
|
4050
|
+
if (editor.selection) {
|
|
4051
|
+
const selection = editor.selection;
|
|
4052
|
+
editor.selection = {
|
|
4053
|
+
...selection
|
|
4054
|
+
};
|
|
4055
|
+
}
|
|
4064
4056
|
}
|
|
4065
4057
|
}, removeDecoratorActionImplementation = ({
|
|
4066
4058
|
action
|
|
@@ -4068,7 +4060,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4068
4060
|
const editor = action.editor, mark = action.decorator, {
|
|
4069
4061
|
selection
|
|
4070
4062
|
} = editor;
|
|
4071
|
-
if (selection)
|
|
4063
|
+
if (selection) {
|
|
4072
4064
|
if (Range.isExpanded(selection))
|
|
4073
4065
|
Transforms.setNodes(editor, {}, {
|
|
4074
4066
|
match: Text.isText,
|
|
@@ -4111,6 +4103,13 @@ const addDecoratorActionImplementation = ({
|
|
|
4111
4103
|
};
|
|
4112
4104
|
}
|
|
4113
4105
|
}
|
|
4106
|
+
if (editor.selection) {
|
|
4107
|
+
const selection2 = editor.selection;
|
|
4108
|
+
editor.selection = {
|
|
4109
|
+
...selection2
|
|
4110
|
+
};
|
|
4111
|
+
}
|
|
4112
|
+
}
|
|
4114
4113
|
};
|
|
4115
4114
|
function isDecoratorActive({
|
|
4116
4115
|
editor,
|
|
@@ -4151,7 +4150,8 @@ const toggleDecoratorActionImplementation = ({
|
|
|
4151
4150
|
decorator: action.decorator
|
|
4152
4151
|
}
|
|
4153
4152
|
});
|
|
4154
|
-
}
|
|
4153
|
+
};
|
|
4154
|
+
debugWithName("plugin:withPortableTextSelections");
|
|
4155
4155
|
function createWithPortableTextSelections(editorActor, types) {
|
|
4156
4156
|
let prevSelection = null;
|
|
4157
4157
|
return function(editor) {
|
|
@@ -4167,7 +4167,7 @@ function createWithPortableTextSelections(editorActor, types) {
|
|
|
4167
4167
|
ptRange = toPortableTextRange(value, editor.selection, types), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange);
|
|
4168
4168
|
}
|
|
4169
4169
|
}
|
|
4170
|
-
|
|
4170
|
+
ptRange ? editorActor.send({
|
|
4171
4171
|
type: "selection",
|
|
4172
4172
|
selection: ptRange
|
|
4173
4173
|
}) : editorActor.send({
|
|
@@ -4180,10 +4180,9 @@ function createWithPortableTextSelections(editorActor, types) {
|
|
|
4180
4180
|
onChange
|
|
4181
4181
|
} = editor;
|
|
4182
4182
|
return editor.onChange = () => {
|
|
4183
|
-
|
|
4184
|
-
onChange(), hasChanges && !editorActor.getSnapshot().matches({
|
|
4183
|
+
onChange(), editorActor.getSnapshot().matches({
|
|
4185
4184
|
setup: "setting up"
|
|
4186
|
-
})
|
|
4185
|
+
}) || emitPortableTextSelection();
|
|
4187
4186
|
}, editor;
|
|
4188
4187
|
};
|
|
4189
4188
|
}
|
|
@@ -5418,16 +5417,6 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5418
5417
|
const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
|
|
5419
5418
|
Transforms.select(action.editor, nextBlockPath);
|
|
5420
5419
|
},
|
|
5421
|
-
reselect: ({
|
|
5422
|
-
action
|
|
5423
|
-
}) => {
|
|
5424
|
-
const selection = action.editor.selection;
|
|
5425
|
-
selection && (Transforms.select(action.editor, {
|
|
5426
|
-
...selection
|
|
5427
|
-
}), action.editor.selection = {
|
|
5428
|
-
...selection
|
|
5429
|
-
});
|
|
5430
|
-
},
|
|
5431
5420
|
"style.toggle": toggleStyleActionImplementation,
|
|
5432
5421
|
"style.add": addStyleActionImplementation,
|
|
5433
5422
|
"style.remove": removeStyleActionImplementation,
|
|
@@ -5439,6 +5428,27 @@ function performAction({
|
|
|
5439
5428
|
action
|
|
5440
5429
|
}) {
|
|
5441
5430
|
switch (action.type) {
|
|
5431
|
+
case "annotation.toggle": {
|
|
5432
|
+
behaviorActionImplementations["annotation.toggle"]({
|
|
5433
|
+
context,
|
|
5434
|
+
action
|
|
5435
|
+
});
|
|
5436
|
+
break;
|
|
5437
|
+
}
|
|
5438
|
+
case "decorator.add": {
|
|
5439
|
+
behaviorActionImplementations["decorator.add"]({
|
|
5440
|
+
context,
|
|
5441
|
+
action
|
|
5442
|
+
});
|
|
5443
|
+
break;
|
|
5444
|
+
}
|
|
5445
|
+
case "decorator.remove": {
|
|
5446
|
+
behaviorActionImplementations["decorator.remove"]({
|
|
5447
|
+
context,
|
|
5448
|
+
action
|
|
5449
|
+
});
|
|
5450
|
+
break;
|
|
5451
|
+
}
|
|
5442
5452
|
case "delete.block": {
|
|
5443
5453
|
behaviorActionImplementations["delete.block"]({
|
|
5444
5454
|
context,
|
|
@@ -5532,13 +5542,6 @@ function performAction({
|
|
|
5532
5542
|
});
|
|
5533
5543
|
break;
|
|
5534
5544
|
}
|
|
5535
|
-
case "reselect": {
|
|
5536
|
-
behaviorActionImplementations.reselect({
|
|
5537
|
-
context,
|
|
5538
|
-
action
|
|
5539
|
-
});
|
|
5540
|
-
break;
|
|
5541
|
-
}
|
|
5542
5545
|
case "style.add": {
|
|
5543
5546
|
behaviorActionImplementations["style.add"]({
|
|
5544
5547
|
context,
|
|
@@ -5593,13 +5596,6 @@ function performDefaultAction({
|
|
|
5593
5596
|
});
|
|
5594
5597
|
break;
|
|
5595
5598
|
}
|
|
5596
|
-
case "annotation.toggle": {
|
|
5597
|
-
behaviorActionImplementations["annotation.toggle"]({
|
|
5598
|
-
context,
|
|
5599
|
-
action
|
|
5600
|
-
});
|
|
5601
|
-
break;
|
|
5602
|
-
}
|
|
5603
5599
|
case "blur": {
|
|
5604
5600
|
behaviorActionImplementations.blur({
|
|
5605
5601
|
context,
|
|
@@ -5607,20 +5603,6 @@ function performDefaultAction({
|
|
|
5607
5603
|
});
|
|
5608
5604
|
break;
|
|
5609
5605
|
}
|
|
5610
|
-
case "decorator.add": {
|
|
5611
|
-
behaviorActionImplementations["decorator.add"]({
|
|
5612
|
-
context,
|
|
5613
|
-
action
|
|
5614
|
-
});
|
|
5615
|
-
break;
|
|
5616
|
-
}
|
|
5617
|
-
case "decorator.remove": {
|
|
5618
|
-
behaviorActionImplementations["decorator.remove"]({
|
|
5619
|
-
context,
|
|
5620
|
-
action
|
|
5621
|
-
});
|
|
5622
|
-
break;
|
|
5623
|
-
}
|
|
5624
5606
|
case "decorator.toggle": {
|
|
5625
5607
|
behaviorActionImplementations["decorator.toggle"]({
|
|
5626
5608
|
context,
|
|
@@ -5691,6 +5673,13 @@ function performDefaultAction({
|
|
|
5691
5673
|
});
|
|
5692
5674
|
break;
|
|
5693
5675
|
}
|
|
5676
|
+
case "select": {
|
|
5677
|
+
behaviorActionImplementations.select({
|
|
5678
|
+
context,
|
|
5679
|
+
action
|
|
5680
|
+
});
|
|
5681
|
+
break;
|
|
5682
|
+
}
|
|
5694
5683
|
default:
|
|
5695
5684
|
behaviorActionImplementations["style.toggle"]({
|
|
5696
5685
|
context,
|
|
@@ -5769,10 +5758,12 @@ const editorMachine = setup({
|
|
|
5769
5758
|
if (eventBehaviors.length === 0) {
|
|
5770
5759
|
if (!defaultAction)
|
|
5771
5760
|
return;
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5761
|
+
withApplyingBehaviorActions(event.editor, () => {
|
|
5762
|
+
Editor.withoutNormalizing(event.editor, () => {
|
|
5763
|
+
performAction({
|
|
5764
|
+
context,
|
|
5765
|
+
action: defaultAction
|
|
5766
|
+
});
|
|
5776
5767
|
});
|
|
5777
5768
|
}), event.editor.onChange();
|
|
5778
5769
|
return;
|
|
@@ -5800,21 +5791,28 @@ const editorMachine = setup({
|
|
|
5800
5791
|
event: event.behaviorEvent
|
|
5801
5792
|
}, shouldRun));
|
|
5802
5793
|
for (const actionIntends of actionIntendSets)
|
|
5803
|
-
behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"),
|
|
5804
|
-
|
|
5805
|
-
const
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
|
|
5794
|
+
behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), withApplyingBehaviorActions(event.editor, () => {
|
|
5795
|
+
Editor.withoutNormalizing(event.editor, () => {
|
|
5796
|
+
for (const actionIntend of actionIntends) {
|
|
5797
|
+
if (actionIntend.type === "raise") {
|
|
5798
|
+
enqueue.raise({
|
|
5799
|
+
type: "behavior event",
|
|
5800
|
+
behaviorEvent: actionIntend.event,
|
|
5801
|
+
editor: event.editor
|
|
5802
|
+
});
|
|
5803
|
+
continue;
|
|
5804
|
+
}
|
|
5805
|
+
const action = {
|
|
5806
|
+
...actionIntend,
|
|
5807
|
+
editor: event.editor
|
|
5808
|
+
};
|
|
5809
|
+
performAction({
|
|
5810
|
+
context,
|
|
5811
|
+
action
|
|
5812
|
+
});
|
|
5813
|
+
}
|
|
5814
|
+
});
|
|
5815
|
+
}), event.editor.onChange();
|
|
5818
5816
|
if (behaviorOverwritten) {
|
|
5819
5817
|
event.nativeEvent?.preventDefault();
|
|
5820
5818
|
break;
|
|
@@ -5823,10 +5821,12 @@ const editorMachine = setup({
|
|
|
5823
5821
|
if (!behaviorOverwritten) {
|
|
5824
5822
|
if (!defaultAction)
|
|
5825
5823
|
return;
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5824
|
+
withApplyingBehaviorActions(event.editor, () => {
|
|
5825
|
+
Editor.withoutNormalizing(event.editor, () => {
|
|
5826
|
+
performAction({
|
|
5827
|
+
context,
|
|
5828
|
+
action: defaultAction
|
|
5829
|
+
});
|
|
5830
5830
|
});
|
|
5831
5831
|
}), event.editor.onChange();
|
|
5832
5832
|
}
|
|
@@ -5967,17 +5967,7 @@ const editorMachine = setup({
|
|
|
5967
5967
|
"behavior event": {
|
|
5968
5968
|
actions: "handle behavior event"
|
|
5969
5969
|
},
|
|
5970
|
-
"annotation
|
|
5971
|
-
actions: emit(({
|
|
5972
|
-
event
|
|
5973
|
-
}) => event)
|
|
5974
|
-
},
|
|
5975
|
-
"annotation.remove": {
|
|
5976
|
-
actions: emit(({
|
|
5977
|
-
event
|
|
5978
|
-
}) => event)
|
|
5979
|
-
},
|
|
5980
|
-
"annotation.toggle": {
|
|
5970
|
+
"annotation.*": {
|
|
5981
5971
|
actions: emit(({
|
|
5982
5972
|
event
|
|
5983
5973
|
}) => event)
|
|
@@ -6007,6 +5997,11 @@ const editorMachine = setup({
|
|
|
6007
5997
|
event
|
|
6008
5998
|
}) => event)
|
|
6009
5999
|
},
|
|
6000
|
+
select: {
|
|
6001
|
+
actions: emit(({
|
|
6002
|
+
event
|
|
6003
|
+
}) => event)
|
|
6004
|
+
},
|
|
6010
6005
|
"style.*": {
|
|
6011
6006
|
actions: emit(({
|
|
6012
6007
|
event
|
|
@@ -6197,7 +6192,7 @@ const EditorActorContext = createContext({}), PortableTextEditorSelectionContext
|
|
|
6197
6192
|
if (selection === void 0)
|
|
6198
6193
|
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
6199
6194
|
return selection;
|
|
6200
|
-
}, debug$5 = debugWithName("component:PortableTextEditor:SelectionProvider")
|
|
6195
|
+
}, debug$5 = debugWithName("component:PortableTextEditor:SelectionProvider");
|
|
6201
6196
|
function PortableTextEditorSelectionProvider(props) {
|
|
6202
6197
|
const $ = c(6), [selection, setSelection] = useState(null);
|
|
6203
6198
|
let t0, t1;
|
|
@@ -6205,7 +6200,7 @@ function PortableTextEditorSelectionProvider(props) {
|
|
|
6205
6200
|
debug$5("Subscribing to selection changes");
|
|
6206
6201
|
const subscription = props.editorActor.on("selection", (event) => {
|
|
6207
6202
|
startTransition(() => {
|
|
6208
|
-
|
|
6203
|
+
setSelection(event.selection);
|
|
6209
6204
|
});
|
|
6210
6205
|
});
|
|
6211
6206
|
return () => {
|
|
@@ -6401,23 +6396,19 @@ function RouteEventsToChanges(props) {
|
|
|
6401
6396
|
});
|
|
6402
6397
|
break bb5;
|
|
6403
6398
|
}
|
|
6404
|
-
case "
|
|
6405
|
-
|
|
6406
|
-
case "annotation.toggle":
|
|
6407
|
-
case "blur":
|
|
6408
|
-
case "decorator.add":
|
|
6409
|
-
case "decorator.remove":
|
|
6410
|
-
case "decorator.toggle":
|
|
6411
|
-
case "focus":
|
|
6412
|
-
case "insert.block object":
|
|
6413
|
-
case "insert.inline object":
|
|
6414
|
-
case "list item.toggle":
|
|
6415
|
-
case "style.toggle":
|
|
6416
|
-
case "patches":
|
|
6417
|
-
case "editable":
|
|
6418
|
-
case "read only":
|
|
6399
|
+
case "mutation": {
|
|
6400
|
+
handleChange(event);
|
|
6419
6401
|
break bb5;
|
|
6420
|
-
|
|
6402
|
+
}
|
|
6403
|
+
case "ready": {
|
|
6404
|
+
handleChange(event);
|
|
6405
|
+
break bb5;
|
|
6406
|
+
}
|
|
6407
|
+
case "selection": {
|
|
6408
|
+
handleChange(event);
|
|
6409
|
+
break bb5;
|
|
6410
|
+
}
|
|
6411
|
+
case "unset":
|
|
6421
6412
|
handleChange(event);
|
|
6422
6413
|
}
|
|
6423
6414
|
});
|
|
@@ -6550,17 +6541,9 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6550
6541
|
return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6551
6542
|
};
|
|
6552
6543
|
Leaf.displayName = "Leaf";
|
|
6553
|
-
const debug$2 = debugWithName("plugin:withHotKeys")
|
|
6554
|
-
marks: {
|
|
6555
|
-
"mod+b": "strong",
|
|
6556
|
-
"mod+i": "em",
|
|
6557
|
-
"mod+u": "underline",
|
|
6558
|
-
"mod+'": "code"
|
|
6559
|
-
},
|
|
6560
|
-
custom: {}
|
|
6561
|
-
};
|
|
6544
|
+
const debug$2 = debugWithName("plugin:withHotKeys");
|
|
6562
6545
|
function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
|
|
6563
|
-
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions
|
|
6546
|
+
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
|
|
6564
6547
|
return function(editor) {
|
|
6565
6548
|
return editor.pteWithHotKeys = (event) => {
|
|
6566
6549
|
Object.keys(activeHotkeys).forEach((cat) => {
|