@portabletext/editor 3.0.9 → 3.1.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-dts/index.d.ts +16 -10
- package/lib/index.js +134 -179
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.types.event.ts +1 -1
- package/src/editor/PortableTextEditor.tsx +14 -0
- package/src/editor/plugins/createWithEditableAPI.ts +18 -83
- package/src/editor/plugins/createWithPatches.ts +1 -1
- package/src/editor/plugins/createWithPlaceholderBlock.ts +5 -1
- package/src/editor/plugins/with-plugins.ts +8 -14
- package/src/editor/sync-machine.ts +10 -5
- package/src/internal-utils/applyPatch.ts +19 -14
- package/src/operations/behavior.operation.delete.ts +19 -1
- package/src/types/editor.ts +0 -9
- package/src/editor/plugins/createWithUtils.ts +0 -52
package/lib/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import noop from "lodash/noop.js";
|
|
|
5
5
|
import { createContext, useContext, useEffect, useState, useRef, forwardRef, Component, startTransition } from "react";
|
|
6
6
|
import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Transforms, Operation, deleteText, createEditor } from "slate";
|
|
7
7
|
import { useSelected, useSlateSelector, useSlateStatic, ReactEditor, useSlate, Editable, withReact, Slate } from "slate-react";
|
|
8
|
-
import debug$
|
|
8
|
+
import debug$i from "debug";
|
|
9
9
|
import { DOMEditor, isDOMNode, EDITOR_TO_PENDING_SELECTION, IS_FOCUSED, IS_READ_ONLY } from "slate-dom";
|
|
10
10
|
import { getBlockEndPoint, getBlockStartPoint, getBlockKeyFromSelectionPoint, isSelectionCollapsed, isEqualSelectionPoints, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint } from "./_chunks-es/util.slice-blocks.js";
|
|
11
11
|
import isEqual from "lodash/isEqual.js";
|
|
@@ -29,10 +29,10 @@ import { EditorContext } from "./_chunks-es/use-editor.js";
|
|
|
29
29
|
import { useEditor } from "./_chunks-es/use-editor.js";
|
|
30
30
|
import { Subject } from "rxjs";
|
|
31
31
|
const rootName = "sanity-pte:";
|
|
32
|
-
debug$
|
|
32
|
+
debug$i(rootName);
|
|
33
33
|
function debugWithName(name) {
|
|
34
34
|
const namespace = `${rootName}${name}`;
|
|
35
|
-
return debug$
|
|
35
|
+
return debug$i && debug$i.enabled(namespace) ? debug$i(namespace) : debug$i(rootName);
|
|
36
36
|
}
|
|
37
37
|
const VOID_CHILD_KEY = "void-child";
|
|
38
38
|
function keepObjectEquality(object, keyMap) {
|
|
@@ -1538,7 +1538,7 @@ function toKeyName(name) {
|
|
|
1538
1538
|
const keyName = name.toLowerCase();
|
|
1539
1539
|
return aliases[keyName] ?? keyName;
|
|
1540
1540
|
}
|
|
1541
|
-
const debug$
|
|
1541
|
+
const debug$h = debugWithName("plugin:withHotKeys");
|
|
1542
1542
|
function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
|
|
1543
1543
|
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
|
|
1544
1544
|
return function(editor) {
|
|
@@ -1553,7 +1553,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
1553
1553
|
const possibleMark = activeHotkeys[cat];
|
|
1554
1554
|
if (possibleMark) {
|
|
1555
1555
|
const mark = possibleMark[hotkey];
|
|
1556
|
-
debug$
|
|
1556
|
+
debug$h(`HotKey ${hotkey} to toggle ${mark}`), editorActor.send({
|
|
1557
1557
|
type: "behavior event",
|
|
1558
1558
|
behaviorEvent: {
|
|
1559
1559
|
type: "decorator.toggle",
|
|
@@ -1882,7 +1882,7 @@ function createDecorate(schema, slateEditor) {
|
|
|
1882
1882
|
}) || Range.includes(decoratedRange, path));
|
|
1883
1883
|
};
|
|
1884
1884
|
}
|
|
1885
|
-
const RelayActorContext = createContext({}), debug$
|
|
1885
|
+
const RelayActorContext = createContext({}), debug$g = debugWithName("validate selection machine"), validateSelectionSetup = setup({
|
|
1886
1886
|
types: {
|
|
1887
1887
|
context: {},
|
|
1888
1888
|
input: {},
|
|
@@ -1954,12 +1954,12 @@ function validateSelection(slateEditor, editorElement) {
|
|
|
1954
1954
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
1955
1955
|
try {
|
|
1956
1956
|
const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
1957
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug$
|
|
1957
|
+
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug$g("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
1958
1958
|
} catch {
|
|
1959
|
-
debug$
|
|
1959
|
+
debug$g("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.onChange();
|
|
1960
1960
|
}
|
|
1961
1961
|
}
|
|
1962
|
-
const debug$
|
|
1962
|
+
const debug$f = debugWithName("component:Editable"), PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
1963
1963
|
const $ = c(176);
|
|
1964
1964
|
let hotkeys, onBeforeInput, onBlur, onClick, onCopy, onCut, onDrag, onDragEnd, onDragEnter, onDragLeave, onDragOver, onDragStart, onDrop, onFocus, onPaste, propsSelection, rangeDecorations, renderAnnotation, renderBlock, renderChild, renderDecorator, renderListItem, renderPlaceholder, renderStyle, restProps, scrollSelectionIntoView, spellCheck;
|
|
1965
1965
|
$[0] !== props ? ({
|
|
@@ -2048,10 +2048,10 @@ const debug$g = debugWithName("component:Editable"), PortableTextEditable = forw
|
|
|
2048
2048
|
let t14;
|
|
2049
2049
|
$[63] !== editorActor || $[64] !== propsSelection || $[65] !== slateEditor ? (t14 = () => {
|
|
2050
2050
|
if (propsSelection) {
|
|
2051
|
-
debug$
|
|
2051
|
+
debug$f(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
2052
2052
|
const normalizedSelection = normalizeSelection(propsSelection, slateEditor.value);
|
|
2053
2053
|
if (normalizedSelection !== null) {
|
|
2054
|
-
debug$
|
|
2054
|
+
debug$f(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
2055
2055
|
const slateRange = toSlateRange({
|
|
2056
2056
|
context: {
|
|
2057
2057
|
schema: editorActor.getSnapshot().context.schema,
|
|
@@ -2163,8 +2163,8 @@ const debug$g = debugWithName("component:Editable"), PortableTextEditable = forw
|
|
|
2163
2163
|
event_1.preventDefault(), relayActor.send({
|
|
2164
2164
|
type: "loading"
|
|
2165
2165
|
}), Promise.resolve(onPasteResult).then((result_1) => {
|
|
2166
|
-
if (debug$
|
|
2167
|
-
debug$
|
|
2166
|
+
if (debug$f("Custom paste function from client resolved", result_1), !result_1 || !result_1.insert) {
|
|
2167
|
+
debug$f("No result from custom paste handler, pasting normally");
|
|
2168
2168
|
const selection_1 = editorActor.getSnapshot().context.selection, position_1 = selection_1 ? {
|
|
2169
2169
|
selection: selection_1
|
|
2170
2170
|
} : void 0;
|
|
@@ -2232,7 +2232,7 @@ const debug$g = debugWithName("component:Editable"), PortableTextEditable = forw
|
|
|
2232
2232
|
nativeEvent: event_1
|
|
2233
2233
|
});
|
|
2234
2234
|
}
|
|
2235
|
-
debug$
|
|
2235
|
+
debug$f("No result from custom paste handler, pasting normally");
|
|
2236
2236
|
}, $[85] = editorActor, $[86] = onPaste, $[87] = portableTextEditor, $[88] = relayActor, $[89] = slateEditor, $[90] = t21) : t21 = $[90];
|
|
2237
2237
|
const handlePaste = t21;
|
|
2238
2238
|
let t22;
|
|
@@ -2972,7 +2972,7 @@ function mergeIntoLastStep(steps, lastStep, op) {
|
|
|
2972
2972
|
operations: [...lastStep.operations, op]
|
|
2973
2973
|
}];
|
|
2974
2974
|
}
|
|
2975
|
-
const debug$
|
|
2975
|
+
const debug$e = debugWithName("plugin:history"), UNDO_STEP_LIMIT = 1e3;
|
|
2976
2976
|
function pluginHistory({
|
|
2977
2977
|
editorActor,
|
|
2978
2978
|
subscriptions
|
|
@@ -2989,7 +2989,7 @@ function pluginHistory({
|
|
|
2989
2989
|
for (const patch of patches)
|
|
2990
2990
|
if (!reset && patch.origin !== "local") {
|
|
2991
2991
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2992
|
-
debug$
|
|
2992
|
+
debug$e("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
2993
2993
|
undos: [],
|
|
2994
2994
|
redos: []
|
|
2995
2995
|
}, remotePatches.splice(0, remotePatches.length), setWithHistory(editor, !0), reset = !0;
|
|
@@ -3074,7 +3074,7 @@ function getNextSpan({
|
|
|
3074
3074
|
}
|
|
3075
3075
|
return nextSpan;
|
|
3076
3076
|
}
|
|
3077
|
-
const debug$
|
|
3077
|
+
const debug$d = debugWithName("plugin:withPortableTextMarkModel");
|
|
3078
3078
|
function createWithPortableTextMarkModel(editorActor) {
|
|
3079
3079
|
return function(editor) {
|
|
3080
3080
|
const {
|
|
@@ -3088,7 +3088,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3088
3088
|
for (const [child, childPath] of children) {
|
|
3089
3089
|
const nextNode = node.children[childPath[1] + 1];
|
|
3090
3090
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3091
|
-
debug$
|
|
3091
|
+
debug$d("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), withNormalizeNode(editor, () => {
|
|
3092
3092
|
Transforms.mergeNodes(editor, {
|
|
3093
3093
|
at: [childPath[0], childPath[1] + 1],
|
|
3094
3094
|
voids: !0
|
|
@@ -3099,7 +3099,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3099
3099
|
}
|
|
3100
3100
|
}
|
|
3101
3101
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3102
|
-
debug$
|
|
3102
|
+
debug$d("Adding .markDefs to block node"), withNormalizeNode(editor, () => {
|
|
3103
3103
|
Transforms.setNodes(editor, {
|
|
3104
3104
|
markDefs: []
|
|
3105
3105
|
}, {
|
|
@@ -3109,7 +3109,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3109
3109
|
return;
|
|
3110
3110
|
}
|
|
3111
3111
|
if (defaultStyle && editor.isTextBlock(node) && typeof node.style > "u") {
|
|
3112
|
-
debug$
|
|
3112
|
+
debug$d("Adding .style to block node"), withNormalizeNode(editor, () => {
|
|
3113
3113
|
Transforms.setNodes(editor, {
|
|
3114
3114
|
style: defaultStyle
|
|
3115
3115
|
}, {
|
|
@@ -3119,7 +3119,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3119
3119
|
return;
|
|
3120
3120
|
}
|
|
3121
3121
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3122
|
-
debug$
|
|
3122
|
+
debug$d("Adding .marks to span node"), withNormalizeNode(editor, () => {
|
|
3123
3123
|
Transforms.setNodes(editor, {
|
|
3124
3124
|
marks: []
|
|
3125
3125
|
}, {
|
|
@@ -3131,7 +3131,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3131
3131
|
if (editor.isTextSpan(node)) {
|
|
3132
3132
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3133
3133
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3134
|
-
debug$
|
|
3134
|
+
debug$d("Removing annotations from empty span node"), withNormalizeNode(editor, () => {
|
|
3135
3135
|
Transforms.setNodes(editor, {
|
|
3136
3136
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
3137
3137
|
}, {
|
|
@@ -3147,7 +3147,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3147
3147
|
if (editor.isTextSpan(child)) {
|
|
3148
3148
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3149
3149
|
if (orphanedAnnotations.length > 0) {
|
|
3150
|
-
debug$
|
|
3150
|
+
debug$d("Removing orphaned annotations from span node"), withNormalizeNode(editor, () => {
|
|
3151
3151
|
Transforms.setNodes(editor, {
|
|
3152
3152
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
3153
3153
|
}, {
|
|
@@ -3163,7 +3163,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3163
3163
|
if (editor.isTextBlock(block)) {
|
|
3164
3164
|
const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3165
3165
|
if (orphanedAnnotations.length > 0) {
|
|
3166
|
-
debug$
|
|
3166
|
+
debug$d("Removing orphaned annotations from span node"), withNormalizeNode(editor, () => {
|
|
3167
3167
|
Transforms.setNodes(editor, {
|
|
3168
3168
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
3169
3169
|
}, {
|
|
@@ -3179,7 +3179,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3179
3179
|
for (const markDef of markDefs)
|
|
3180
3180
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3181
3181
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3182
|
-
debug$
|
|
3182
|
+
debug$d("Removing duplicate markDefs"), withNormalizeNode(editor, () => {
|
|
3183
3183
|
Transforms.setNodes(editor, {
|
|
3184
3184
|
markDefs: newMarkDefs
|
|
3185
3185
|
}, {
|
|
@@ -3192,7 +3192,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3192
3192
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3193
3193
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3194
3194
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
3195
|
-
debug$
|
|
3195
|
+
debug$d("Removing markDef not in use"), withNormalizeNode(editor, () => {
|
|
3196
3196
|
Transforms.setNodes(editor, {
|
|
3197
3197
|
markDefs: newMarkDefs
|
|
3198
3198
|
}, {
|
|
@@ -3284,7 +3284,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3284
3284
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
3285
3285
|
if (editor.isTextBlock(targetBlock)) {
|
|
3286
3286
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
3287
|
-
debug$
|
|
3287
|
+
debug$d("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
3288
3288
|
markDefs: newMarkDefs
|
|
3289
3289
|
}, {
|
|
3290
3290
|
at: targetPath,
|
|
@@ -3980,7 +3980,7 @@ function parse(textline) {
|
|
|
3980
3980
|
function toInt(num) {
|
|
3981
3981
|
return parseInt(num, 10);
|
|
3982
3982
|
}
|
|
3983
|
-
const debug$
|
|
3983
|
+
const debug$c = debugWithName("transformOperation");
|
|
3984
3984
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
3985
3985
|
const transformedOperation = {
|
|
3986
3986
|
...operation
|
|
@@ -3989,16 +3989,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
3989
3989
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
3990
3990
|
_key: blk._key
|
|
3991
3991
|
}, patch.path[0]));
|
|
3992
|
-
return debug$
|
|
3992
|
+
return debug$c(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
3993
3993
|
}
|
|
3994
3994
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
3995
3995
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
|
|
3996
3996
|
_key: blk._key
|
|
3997
3997
|
}, patch.path[0]));
|
|
3998
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
3998
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$c("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
3999
3999
|
}
|
|
4000
4000
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
4001
|
-
return debug$
|
|
4001
|
+
return debug$c(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
4002
4002
|
if (patch.type === "diffMatchPatch") {
|
|
4003
4003
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
4004
4004
|
return !operationTargetBlock || !isEqual({
|
|
@@ -4069,7 +4069,7 @@ function findOperationTargetBlock(editor, operation) {
|
|
|
4069
4069
|
let block;
|
|
4070
4070
|
return operation.type === "set_selection" && editor.selection ? block = editor.children[editor.selection.focus.path[0]] : "path" in operation && (block = editor.children[operation.path[0]]), block;
|
|
4071
4071
|
}
|
|
4072
|
-
const debug$
|
|
4072
|
+
const debug$b = debugWithName("behavior.operation.history.redo"), historyRedoOperationImplementation = ({
|
|
4073
4073
|
operation
|
|
4074
4074
|
}) => {
|
|
4075
4075
|
const editor = operation.editor, {
|
|
@@ -4077,7 +4077,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4077
4077
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
4078
4078
|
if (redos.length > 0) {
|
|
4079
4079
|
const step = redos[redos.length - 1];
|
|
4080
|
-
if (debug$
|
|
4080
|
+
if (debug$b("Redoing", step), step.operations.length > 0) {
|
|
4081
4081
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
4082
4082
|
let transformedOperations = step.operations;
|
|
4083
4083
|
otherPatches.forEach((item) => {
|
|
@@ -4094,7 +4094,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4094
4094
|
});
|
|
4095
4095
|
});
|
|
4096
4096
|
} catch (err) {
|
|
4097
|
-
debug$
|
|
4097
|
+
debug$b("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
4098
4098
|
undos: [],
|
|
4099
4099
|
redos: []
|
|
4100
4100
|
}, setWithHistory(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -4103,7 +4103,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4103
4103
|
editor.history.undos.push(step), editor.history.redos.pop();
|
|
4104
4104
|
}
|
|
4105
4105
|
}
|
|
4106
|
-
}, debug$
|
|
4106
|
+
}, debug$a = debugWithName("behavior.operation.history.undo"), historyUndoOperationImplementation = ({
|
|
4107
4107
|
operation
|
|
4108
4108
|
}) => {
|
|
4109
4109
|
const editor = operation.editor, {
|
|
@@ -4111,7 +4111,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4111
4111
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
4112
4112
|
if (undos.length > 0) {
|
|
4113
4113
|
const step = undos[undos.length - 1];
|
|
4114
|
-
if (debug$
|
|
4114
|
+
if (debug$a("Undoing", step), step.operations.length > 0) {
|
|
4115
4115
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
4116
4116
|
let transformedOperations = step.operations;
|
|
4117
4117
|
otherPatches.forEach((item) => {
|
|
@@ -4129,7 +4129,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4129
4129
|
});
|
|
4130
4130
|
});
|
|
4131
4131
|
} catch (err) {
|
|
4132
|
-
debug$
|
|
4132
|
+
debug$a("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
4133
4133
|
undos: [],
|
|
4134
4134
|
redos: []
|
|
4135
4135
|
}, setWithHistory(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -4586,6 +4586,16 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4586
4586
|
}), operation.editor.children.length === 0 && Transforms.insertNodes(operation.editor, createPlaceholderBlock(context));
|
|
4587
4587
|
return;
|
|
4588
4588
|
}
|
|
4589
|
+
if (operation.unit === "child") {
|
|
4590
|
+
const range = at ?? operation.editor.selection ?? void 0;
|
|
4591
|
+
if (!range)
|
|
4592
|
+
throw new Error("Unable to delete children without a selection");
|
|
4593
|
+
Transforms.removeNodes(operation.editor, {
|
|
4594
|
+
at: range,
|
|
4595
|
+
match: (node) => isSpan(context, node) && node._key !== VOID_CHILD_KEY || "__inline" in node && node.__inline === !0
|
|
4596
|
+
});
|
|
4597
|
+
return;
|
|
4598
|
+
}
|
|
4589
4599
|
if (operation.direction === "backward" && operation.unit === "line") {
|
|
4590
4600
|
const range = at ?? operation.editor.selection ?? void 0;
|
|
4591
4601
|
if (!range)
|
|
@@ -5565,16 +5575,16 @@ function createWithObjectKeys(editorActor) {
|
|
|
5565
5575
|
}, editor;
|
|
5566
5576
|
};
|
|
5567
5577
|
}
|
|
5568
|
-
function createApplyPatch(
|
|
5578
|
+
function createApplyPatch(context) {
|
|
5569
5579
|
return (editor, patch) => {
|
|
5570
5580
|
let changed = !1;
|
|
5571
5581
|
try {
|
|
5572
5582
|
switch (patch.type) {
|
|
5573
5583
|
case "insert":
|
|
5574
|
-
changed = insertPatch(editor, patch
|
|
5584
|
+
changed = insertPatch(context, editor, patch);
|
|
5575
5585
|
break;
|
|
5576
5586
|
case "unset":
|
|
5577
|
-
changed = unsetPatch(editor, patch);
|
|
5587
|
+
changed = unsetPatch(context, editor, patch);
|
|
5578
5588
|
break;
|
|
5579
5589
|
case "set":
|
|
5580
5590
|
changed = setPatch(editor, patch);
|
|
@@ -5614,7 +5624,7 @@ function diffMatchPatch(editor, patch) {
|
|
|
5614
5624
|
}) : op === DIFF_EQUAL && (offset += text.length);
|
|
5615
5625
|
return !0;
|
|
5616
5626
|
}
|
|
5617
|
-
function insertPatch(editor, patch
|
|
5627
|
+
function insertPatch(context, editor, patch) {
|
|
5618
5628
|
const block = findBlock(editor.children, patch.path);
|
|
5619
5629
|
if (!block || patch.path.length > 1 && patch.path[1] !== "children")
|
|
5620
5630
|
return !1;
|
|
@@ -5623,8 +5633,8 @@ function insertPatch(editor, patch, schema) {
|
|
|
5623
5633
|
items: items2,
|
|
5624
5634
|
position: position2
|
|
5625
5635
|
} = patch, blocksToInsert = items2.map((item) => toSlateBlock(item, {
|
|
5626
|
-
schemaTypes: schema
|
|
5627
|
-
}, KEY_TO_SLATE_ELEMENT.get(editor))), targetBlockIndex = block.index, normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex, editorWasEmptyBefore = isEqualToEmptyEditor(editor.value, schema);
|
|
5636
|
+
schemaTypes: context.schema
|
|
5637
|
+
}, KEY_TO_SLATE_ELEMENT.get(editor))), targetBlockIndex = block.index, normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex, editorWasEmptyBefore = isEqualToEmptyEditor(editor.value, context.schema);
|
|
5628
5638
|
return Transforms.insertNodes(editor, blocksToInsert, {
|
|
5629
5639
|
at: [normalizedIdx2]
|
|
5630
5640
|
}), editorWasEmptyBefore && typeof patch.path[0] == "number" && patch.path[0] === 0 && Transforms.removeNodes(editor, {
|
|
@@ -5641,7 +5651,7 @@ function insertPatch(editor, patch, schema) {
|
|
|
5641
5651
|
...block.node,
|
|
5642
5652
|
children: items
|
|
5643
5653
|
}, {
|
|
5644
|
-
schemaTypes: schema
|
|
5654
|
+
schemaTypes: context.schema
|
|
5645
5655
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), normalizedIdx = position === "after" ? targetChild.index + 1 : targetChild.index, childInsertPath = [block.index, normalizedIdx];
|
|
5646
5656
|
return childrenToInsert && Element$1.isElement(childrenToInsert) && Transforms.insertNodes(editor, childrenToInsert.children, {
|
|
5647
5657
|
at: childInsertPath
|
|
@@ -5781,7 +5791,7 @@ function setPatch(editor, patch) {
|
|
|
5781
5791
|
return !1;
|
|
5782
5792
|
return !0;
|
|
5783
5793
|
}
|
|
5784
|
-
function unsetPatch(editor, patch) {
|
|
5794
|
+
function unsetPatch(context, editor, patch) {
|
|
5785
5795
|
if (patch.path.length === 0) {
|
|
5786
5796
|
const previousSelection = editor.selection;
|
|
5787
5797
|
Transforms.deselect(editor);
|
|
@@ -5792,9 +5802,7 @@ function unsetPatch(editor, patch) {
|
|
|
5792
5802
|
Transforms.removeNodes(editor, {
|
|
5793
5803
|
at: path
|
|
5794
5804
|
});
|
|
5795
|
-
return Transforms.insertNodes(editor,
|
|
5796
|
-
decorators: []
|
|
5797
|
-
})), previousSelection && Transforms.select(editor, {
|
|
5805
|
+
return Transforms.insertNodes(editor, createPlaceholderBlock(context)), previousSelection && Transforms.select(editor, {
|
|
5798
5806
|
anchor: {
|
|
5799
5807
|
path: [0, 0],
|
|
5800
5808
|
offset: 0
|
|
@@ -5813,9 +5821,7 @@ function unsetPatch(editor, patch) {
|
|
|
5813
5821
|
const previousSelection = editor.selection;
|
|
5814
5822
|
return Transforms.deselect(editor), Transforms.removeNodes(editor, {
|
|
5815
5823
|
at: [block.index]
|
|
5816
|
-
}), Transforms.insertNodes(editor,
|
|
5817
|
-
decorators: []
|
|
5818
|
-
})), previousSelection && Transforms.select(editor, {
|
|
5824
|
+
}), Transforms.insertNodes(editor, createPlaceholderBlock(context)), previousSelection && Transforms.select(editor, {
|
|
5819
5825
|
anchor: {
|
|
5820
5826
|
path: [0, 0],
|
|
5821
5827
|
offset: 0
|
|
@@ -6220,14 +6226,14 @@ function withoutPatching(editor, fn) {
|
|
|
6220
6226
|
function isPatching(editor) {
|
|
6221
6227
|
return PATCHING.get(editor);
|
|
6222
6228
|
}
|
|
6223
|
-
const debug$
|
|
6229
|
+
const debug$9 = debugWithName("plugin:withPatches");
|
|
6224
6230
|
function createWithPatches({
|
|
6225
6231
|
editorActor,
|
|
6226
6232
|
relayActor,
|
|
6227
6233
|
subscriptions
|
|
6228
6234
|
}) {
|
|
6229
6235
|
let previousValue;
|
|
6230
|
-
const applyPatch = createApplyPatch(editorActor.getSnapshot().context
|
|
6236
|
+
const applyPatch = createApplyPatch(editorActor.getSnapshot().context);
|
|
6231
6237
|
return function(editor) {
|
|
6232
6238
|
IS_PROCESSING_REMOTE_CHANGES.set(editor, !1), PATCHING.set(editor, !0), previousValue = [...editor.value];
|
|
6233
6239
|
const {
|
|
@@ -6245,7 +6251,7 @@ function createWithPatches({
|
|
|
6245
6251
|
withoutPatching(editor, () => {
|
|
6246
6252
|
pluginWithoutHistory(editor, () => {
|
|
6247
6253
|
for (const patch of patches) {
|
|
6248
|
-
debug$
|
|
6254
|
+
debug$9.enabled && debug$9(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
6249
6255
|
try {
|
|
6250
6256
|
changed = applyPatch(editor, patch);
|
|
6251
6257
|
} catch (error) {
|
|
@@ -6263,10 +6269,10 @@ function createWithPatches({
|
|
|
6263
6269
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
6264
6270
|
};
|
|
6265
6271
|
return subscriptions.push(() => {
|
|
6266
|
-
debug$
|
|
6272
|
+
debug$9("Subscribing to remote patches");
|
|
6267
6273
|
const sub = editorActor.on("patches", handlePatches);
|
|
6268
6274
|
return () => {
|
|
6269
|
-
debug$
|
|
6275
|
+
debug$9("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
6270
6276
|
};
|
|
6271
6277
|
}), editor.apply = (operation) => {
|
|
6272
6278
|
let patches = [];
|
|
@@ -6320,7 +6326,7 @@ function createWithPatches({
|
|
|
6320
6326
|
}, editor;
|
|
6321
6327
|
};
|
|
6322
6328
|
}
|
|
6323
|
-
const debug$
|
|
6329
|
+
const debug$8 = debugWithName("plugin:withPlaceholderBlock");
|
|
6324
6330
|
function createWithPlaceholderBlock(editorActor) {
|
|
6325
6331
|
return function(editor) {
|
|
6326
6332
|
const {
|
|
@@ -6343,15 +6349,13 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
6343
6349
|
}
|
|
6344
6350
|
if (op.type === "remove_node") {
|
|
6345
6351
|
const blockIndex = op.path.at(0), isLonelyBlock = op.path.length === 1 && blockIndex === 0 && editor.children.length === 1, isBlockObject = op.node._type !== editorActor.getSnapshot().context.schema.block.name;
|
|
6346
|
-
isLonelyBlock && isBlockObject && (debug$
|
|
6347
|
-
decorators: []
|
|
6348
|
-
})));
|
|
6352
|
+
isLonelyBlock && isBlockObject && (debug$8("Adding placeholder block"), Editor.insertNode(editor, createPlaceholderBlock(editorActor.getSnapshot().context)));
|
|
6349
6353
|
}
|
|
6350
6354
|
apply2(op);
|
|
6351
6355
|
}, editor;
|
|
6352
6356
|
};
|
|
6353
6357
|
}
|
|
6354
|
-
const debug$
|
|
6358
|
+
const debug$7 = debugWithName("plugin:withSchemaTypes");
|
|
6355
6359
|
function createWithSchemaTypes({
|
|
6356
6360
|
editorActor
|
|
6357
6361
|
}) {
|
|
@@ -6363,7 +6367,7 @@ function createWithSchemaTypes({
|
|
|
6363
6367
|
return editor.normalizeNode = (entry) => {
|
|
6364
6368
|
const [node, path] = entry;
|
|
6365
6369
|
if (node._type === void 0 && path.length === 2) {
|
|
6366
|
-
debug$
|
|
6370
|
+
debug$7("Setting span type on text node without a type");
|
|
6367
6371
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
6368
6372
|
withNormalizeNode(editor, () => {
|
|
6369
6373
|
Transforms.setNodes(editor, {
|
|
@@ -6377,7 +6381,7 @@ function createWithSchemaTypes({
|
|
|
6377
6381
|
return;
|
|
6378
6382
|
}
|
|
6379
6383
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
6380
|
-
debug$
|
|
6384
|
+
debug$7("Setting missing key on child node without a key");
|
|
6381
6385
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
6382
6386
|
withNormalizeNode(editor, () => {
|
|
6383
6387
|
Transforms.setNodes(editor, {
|
|
@@ -6394,34 +6398,6 @@ function createWithSchemaTypes({
|
|
|
6394
6398
|
}, editor;
|
|
6395
6399
|
};
|
|
6396
6400
|
}
|
|
6397
|
-
function createWithUtils({
|
|
6398
|
-
editorActor
|
|
6399
|
-
}) {
|
|
6400
|
-
return function(editor) {
|
|
6401
|
-
return editor.pteCreateTextBlock = (options) => toSlateBlock({
|
|
6402
|
-
_type: editorActor.getSnapshot().context.schema.block.name,
|
|
6403
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
6404
|
-
style: editorActor.getSnapshot().context.schema.styles[0].name || "normal",
|
|
6405
|
-
...options.listItem ? {
|
|
6406
|
-
listItem: options.listItem
|
|
6407
|
-
} : {},
|
|
6408
|
-
...options.level ? {
|
|
6409
|
-
level: options.level
|
|
6410
|
-
} : {},
|
|
6411
|
-
markDefs: [],
|
|
6412
|
-
children: [{
|
|
6413
|
-
_type: "span",
|
|
6414
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
6415
|
-
text: "",
|
|
6416
|
-
marks: options.decorators.filter((decorator) => editorActor.getSnapshot().context.schema.decorators.find(({
|
|
6417
|
-
name
|
|
6418
|
-
}) => name === decorator))
|
|
6419
|
-
}]
|
|
6420
|
-
}, {
|
|
6421
|
-
schemaTypes: editorActor.getSnapshot().context.schema
|
|
6422
|
-
}), editor;
|
|
6423
|
-
};
|
|
6424
|
-
}
|
|
6425
6401
|
function pluginUpdateSelection({
|
|
6426
6402
|
editor,
|
|
6427
6403
|
editorActor
|
|
@@ -6762,16 +6738,14 @@ const withPlugins = (editor, options) => {
|
|
|
6762
6738
|
}), withUndoRedo = pluginHistory({
|
|
6763
6739
|
editorActor,
|
|
6764
6740
|
subscriptions: options.subscriptions
|
|
6765
|
-
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor)
|
|
6766
|
-
|
|
6767
|
-
});
|
|
6768
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withUndoRedo(withPatches(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateSelection({
|
|
6741
|
+
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor);
|
|
6742
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUndoRedo(withPatches(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateSelection({
|
|
6769
6743
|
editorActor,
|
|
6770
6744
|
editor: e
|
|
6771
|
-
})))))))))
|
|
6772
|
-
}, debug$
|
|
6745
|
+
})))))))));
|
|
6746
|
+
}, debug$6 = debugWithName("setup");
|
|
6773
6747
|
function createSlateEditor(config) {
|
|
6774
|
-
debug$
|
|
6748
|
+
debug$6("Creating new Slate editor instance");
|
|
6775
6749
|
const placeholderBlock = createPlaceholderBlock(config.editorActor.getSnapshot().context), editor = createEditor();
|
|
6776
6750
|
editor.decoratedRanges = [], editor.decoratorState = {}, editor.value = [placeholderBlock], editor.blockIndexMap = /* @__PURE__ */ new Map(), editor.listIndexMap = /* @__PURE__ */ new Map();
|
|
6777
6751
|
const instance = withPlugins(withReact(editor), {
|
|
@@ -9847,7 +9821,7 @@ function isNativeBehaviorEvent(event) {
|
|
|
9847
9821
|
function isCustomBehaviorEvent(event) {
|
|
9848
9822
|
return event.type.startsWith("custom.");
|
|
9849
9823
|
}
|
|
9850
|
-
const debug$
|
|
9824
|
+
const debug$5 = debugWithName("behaviors:event");
|
|
9851
9825
|
function eventCategory(event) {
|
|
9852
9826
|
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "synthetic" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
9853
9827
|
}
|
|
@@ -9863,7 +9837,7 @@ function performEvent({
|
|
|
9863
9837
|
nativeEvent,
|
|
9864
9838
|
sendBack
|
|
9865
9839
|
}) {
|
|
9866
|
-
mode === "send" && !isNativeBehaviorEvent(event) && createUndoStepId(editor), debug$
|
|
9840
|
+
mode === "send" && !isNativeBehaviorEvent(event) && createUndoStepId(editor), debug$5(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
9867
9841
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
9868
9842
|
if (behavior.on === "*")
|
|
9869
9843
|
return !0;
|
|
@@ -9872,7 +9846,7 @@ function performEvent({
|
|
|
9872
9846
|
});
|
|
9873
9847
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
9874
9848
|
nativeEvent?.preventDefault(), mode === "send" && clearUndoStepId(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9875
|
-
debug$
|
|
9849
|
+
debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9876
9850
|
context: {
|
|
9877
9851
|
keyGenerator,
|
|
9878
9852
|
schema
|
|
@@ -9983,7 +9957,7 @@ function performEvent({
|
|
|
9983
9957
|
break;
|
|
9984
9958
|
}
|
|
9985
9959
|
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStepId(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9986
|
-
debug$
|
|
9960
|
+
debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9987
9961
|
context: {
|
|
9988
9962
|
keyGenerator,
|
|
9989
9963
|
schema
|
|
@@ -10063,7 +10037,7 @@ function createEditorSnapshot({
|
|
|
10063
10037
|
decoratorState: editor.decoratorState
|
|
10064
10038
|
};
|
|
10065
10039
|
}
|
|
10066
|
-
const debug$
|
|
10040
|
+
const debug$4 = debugWithName("editor machine");
|
|
10067
10041
|
function rerouteExternalBehaviorEvent({
|
|
10068
10042
|
event,
|
|
10069
10043
|
slateEditor
|
|
@@ -10320,10 +10294,10 @@ const editorMachine = setup({
|
|
|
10320
10294
|
states: {
|
|
10321
10295
|
"determine initial edit mode": {
|
|
10322
10296
|
entry: [() => {
|
|
10323
|
-
debug$
|
|
10297
|
+
debug$4("entry: edit mode->read only->determine initial edit mode");
|
|
10324
10298
|
}],
|
|
10325
10299
|
exit: [() => {
|
|
10326
|
-
debug$
|
|
10300
|
+
debug$4("exit: edit mode->read only->determine initial edit mode");
|
|
10327
10301
|
}],
|
|
10328
10302
|
on: {
|
|
10329
10303
|
"done syncing value": [{
|
|
@@ -10338,10 +10312,10 @@ const editorMachine = setup({
|
|
|
10338
10312
|
},
|
|
10339
10313
|
"read only": {
|
|
10340
10314
|
entry: [() => {
|
|
10341
|
-
debug$
|
|
10315
|
+
debug$4("entry: edit mode->read only->read only");
|
|
10342
10316
|
}],
|
|
10343
10317
|
exit: [() => {
|
|
10344
|
-
debug$
|
|
10318
|
+
debug$4("exit: edit mode->read only->read only");
|
|
10345
10319
|
}],
|
|
10346
10320
|
on: {
|
|
10347
10321
|
"update readOnly": {
|
|
@@ -10383,10 +10357,10 @@ const editorMachine = setup({
|
|
|
10383
10357
|
states: {
|
|
10384
10358
|
idle: {
|
|
10385
10359
|
entry: [() => {
|
|
10386
|
-
debug$
|
|
10360
|
+
debug$4("entry: edit mode->editable->idle");
|
|
10387
10361
|
}],
|
|
10388
10362
|
exit: [() => {
|
|
10389
|
-
debug$
|
|
10363
|
+
debug$4("exit: edit mode->editable-idle");
|
|
10390
10364
|
}],
|
|
10391
10365
|
on: {
|
|
10392
10366
|
dragstart: {
|
|
@@ -10406,10 +10380,10 @@ const editorMachine = setup({
|
|
|
10406
10380
|
states: {
|
|
10407
10381
|
"checking if busy": {
|
|
10408
10382
|
entry: [() => {
|
|
10409
|
-
debug$
|
|
10383
|
+
debug$4("entry: edit mode->editable->focusing->checking if busy");
|
|
10410
10384
|
}],
|
|
10411
10385
|
exit: [() => {
|
|
10412
|
-
debug$
|
|
10386
|
+
debug$4("exit: edit mode->editable->focusing->checking if busy");
|
|
10413
10387
|
}],
|
|
10414
10388
|
always: [{
|
|
10415
10389
|
guard: "slate is busy",
|
|
@@ -10421,10 +10395,10 @@ const editorMachine = setup({
|
|
|
10421
10395
|
},
|
|
10422
10396
|
busy: {
|
|
10423
10397
|
entry: [() => {
|
|
10424
|
-
debug$
|
|
10398
|
+
debug$4("entry: edit mode->editable->focusing-busy");
|
|
10425
10399
|
}],
|
|
10426
10400
|
exit: [() => {
|
|
10427
|
-
debug$
|
|
10401
|
+
debug$4("exit: edit mode->editable->focusing->busy");
|
|
10428
10402
|
}],
|
|
10429
10403
|
after: {
|
|
10430
10404
|
10: {
|
|
@@ -10436,10 +10410,10 @@ const editorMachine = setup({
|
|
|
10436
10410
|
},
|
|
10437
10411
|
"dragging internally": {
|
|
10438
10412
|
entry: [() => {
|
|
10439
|
-
debug$
|
|
10413
|
+
debug$4("entry: edit mode->editable->dragging internally");
|
|
10440
10414
|
}],
|
|
10441
10415
|
exit: [() => {
|
|
10442
|
-
debug$
|
|
10416
|
+
debug$4("exit: edit mode->editable->dragging internally");
|
|
10443
10417
|
}, ({
|
|
10444
10418
|
context
|
|
10445
10419
|
}) => {
|
|
@@ -10473,10 +10447,10 @@ const editorMachine = setup({
|
|
|
10473
10447
|
states: {
|
|
10474
10448
|
"setting up": {
|
|
10475
10449
|
entry: [() => {
|
|
10476
|
-
debug$
|
|
10450
|
+
debug$4("entry: setup->setting up");
|
|
10477
10451
|
}],
|
|
10478
10452
|
exit: [() => {
|
|
10479
|
-
debug$
|
|
10453
|
+
debug$4("exit: setup->setting up");
|
|
10480
10454
|
}, "emit ready", "emit pending incoming patches", "clear pending incoming patches"],
|
|
10481
10455
|
on: {
|
|
10482
10456
|
"internal.patch": {
|
|
@@ -10501,10 +10475,10 @@ const editorMachine = setup({
|
|
|
10501
10475
|
states: {
|
|
10502
10476
|
idle: {
|
|
10503
10477
|
entry: [() => {
|
|
10504
|
-
debug$
|
|
10478
|
+
debug$4("entry: setup->set up->value sync->idle");
|
|
10505
10479
|
}],
|
|
10506
10480
|
exit: [() => {
|
|
10507
|
-
debug$
|
|
10481
|
+
debug$4("exit: setup->set up->value sync->idle");
|
|
10508
10482
|
}],
|
|
10509
10483
|
on: {
|
|
10510
10484
|
patches: {
|
|
@@ -10519,10 +10493,10 @@ const editorMachine = setup({
|
|
|
10519
10493
|
},
|
|
10520
10494
|
"syncing value": {
|
|
10521
10495
|
entry: [() => {
|
|
10522
|
-
debug$
|
|
10496
|
+
debug$4("entry: setup->set up->value sync->syncing value");
|
|
10523
10497
|
}],
|
|
10524
10498
|
exit: [() => {
|
|
10525
|
-
debug$
|
|
10499
|
+
debug$4("exit: setup->set up->value sync->syncing value");
|
|
10526
10500
|
}, "emit pending incoming patches", "clear pending incoming patches"],
|
|
10527
10501
|
on: {
|
|
10528
10502
|
patches: {
|
|
@@ -10543,10 +10517,10 @@ const editorMachine = setup({
|
|
|
10543
10517
|
states: {
|
|
10544
10518
|
idle: {
|
|
10545
10519
|
entry: [() => {
|
|
10546
|
-
debug$
|
|
10520
|
+
debug$4("entry: setup->set up->writing->pristine->idle");
|
|
10547
10521
|
}],
|
|
10548
10522
|
exit: [() => {
|
|
10549
|
-
debug$
|
|
10523
|
+
debug$4("exit: setup->set up->writing->pristine->idle");
|
|
10550
10524
|
}],
|
|
10551
10525
|
on: {
|
|
10552
10526
|
"internal.patch": [{
|
|
@@ -10569,10 +10543,10 @@ const editorMachine = setup({
|
|
|
10569
10543
|
},
|
|
10570
10544
|
dirty: {
|
|
10571
10545
|
entry: [() => {
|
|
10572
|
-
debug$
|
|
10546
|
+
debug$4("entry: setup->set up->writing->dirty");
|
|
10573
10547
|
}, "emit pending events", "clear pending events"],
|
|
10574
10548
|
exit: [() => {
|
|
10575
|
-
debug$
|
|
10549
|
+
debug$4("exit: setup->set up->writing->dirty");
|
|
10576
10550
|
}],
|
|
10577
10551
|
on: {
|
|
10578
10552
|
"internal.patch": {
|
|
@@ -10590,7 +10564,7 @@ const editorMachine = setup({
|
|
|
10590
10564
|
}
|
|
10591
10565
|
}
|
|
10592
10566
|
}
|
|
10593
|
-
}), debug$
|
|
10567
|
+
}), debug$3 = debugWithName("mutation-machine"), mutationMachine = setup({
|
|
10594
10568
|
types: {
|
|
10595
10569
|
context: {},
|
|
10596
10570
|
events: {},
|
|
@@ -10738,10 +10712,10 @@ const editorMachine = setup({
|
|
|
10738
10712
|
states: {
|
|
10739
10713
|
idle: {
|
|
10740
10714
|
entry: [() => {
|
|
10741
|
-
debug$
|
|
10715
|
+
debug$3("entry: typing->idle");
|
|
10742
10716
|
}],
|
|
10743
10717
|
exit: [() => {
|
|
10744
|
-
debug$
|
|
10718
|
+
debug$3("exit: typing->idle"), debug$3("entry: typing->typing");
|
|
10745
10719
|
}],
|
|
10746
10720
|
on: {
|
|
10747
10721
|
typing: {
|
|
@@ -10756,7 +10730,7 @@ const editorMachine = setup({
|
|
|
10756
10730
|
actions: [raise$1({
|
|
10757
10731
|
type: "emit changes"
|
|
10758
10732
|
}), () => {
|
|
10759
|
-
debug$
|
|
10733
|
+
debug$3("exit: typing->typing");
|
|
10760
10734
|
}]
|
|
10761
10735
|
}
|
|
10762
10736
|
},
|
|
@@ -10780,10 +10754,10 @@ const editorMachine = setup({
|
|
|
10780
10754
|
states: {
|
|
10781
10755
|
idle: {
|
|
10782
10756
|
entry: [() => {
|
|
10783
|
-
debug$
|
|
10757
|
+
debug$3("entry: mutations->idle");
|
|
10784
10758
|
}],
|
|
10785
10759
|
exit: [() => {
|
|
10786
|
-
debug$
|
|
10760
|
+
debug$3("exit: mutations->idle");
|
|
10787
10761
|
}],
|
|
10788
10762
|
on: {
|
|
10789
10763
|
patch: [{
|
|
@@ -10798,10 +10772,10 @@ const editorMachine = setup({
|
|
|
10798
10772
|
},
|
|
10799
10773
|
"has pending mutations": {
|
|
10800
10774
|
entry: [() => {
|
|
10801
|
-
debug$
|
|
10775
|
+
debug$3("entry: mutations->has pending mutations");
|
|
10802
10776
|
}, "emit has pending mutations"],
|
|
10803
10777
|
exit: [() => {
|
|
10804
|
-
debug$
|
|
10778
|
+
debug$3("exit: mutations->has pending mutations");
|
|
10805
10779
|
}],
|
|
10806
10780
|
invoke: {
|
|
10807
10781
|
src: "mutation interval"
|
|
@@ -10823,7 +10797,7 @@ const editorMachine = setup({
|
|
|
10823
10797
|
}
|
|
10824
10798
|
}
|
|
10825
10799
|
}
|
|
10826
|
-
})
|
|
10800
|
+
});
|
|
10827
10801
|
function createEditableAPI(editor, editorActor) {
|
|
10828
10802
|
const types = editorActor.getSnapshot().context.schema;
|
|
10829
10803
|
return {
|
|
@@ -11083,48 +11057,15 @@ function createEditableAPI(editor, editorActor) {
|
|
|
11083
11057
|
};
|
|
11084
11058
|
},
|
|
11085
11059
|
delete: (selection, options) => {
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
11096
|
-
throw new Error("Invalid range");
|
|
11097
|
-
if (range) {
|
|
11098
|
-
if (!options?.mode || options?.mode === "selected") {
|
|
11099
|
-
debug$3("Deleting content in selection"), Transforms.delete(editor, {
|
|
11100
|
-
at: range,
|
|
11101
|
-
hanging: !0,
|
|
11102
|
-
voids: !0
|
|
11103
|
-
}), editor.onChange();
|
|
11104
|
-
return;
|
|
11105
|
-
}
|
|
11106
|
-
if (options?.mode === "blocks" && (debug$3("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
|
|
11107
|
-
at: range,
|
|
11108
|
-
voids: !0,
|
|
11109
|
-
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
|
|
11110
|
-
})), options?.mode === "children" && (debug$3("Deleting children touched by selection"), Transforms.removeNodes(editor, {
|
|
11111
|
-
at: range,
|
|
11112
|
-
voids: !0,
|
|
11113
|
-
match: (node) => node._type === types.span.name || // Text children
|
|
11114
|
-
!editor.isTextBlock(node) && Element$1.isElement(node)
|
|
11115
|
-
})), editor.children.length === 0) {
|
|
11116
|
-
const placeholderBlock = createPlaceholderBlock(editorActor.getSnapshot().context);
|
|
11117
|
-
editor.children = [placeholderBlock], editor.value = [placeholderBlock], buildIndexMaps({
|
|
11118
|
-
schema: editorActor.getSnapshot().context.schema,
|
|
11119
|
-
value: editor.value
|
|
11120
|
-
}, {
|
|
11121
|
-
blockIndexMap: editor.blockIndexMap,
|
|
11122
|
-
listIndexMap: editor.listIndexMap
|
|
11123
|
-
});
|
|
11124
|
-
}
|
|
11125
|
-
editor.onChange();
|
|
11126
|
-
}
|
|
11127
|
-
}
|
|
11060
|
+
selection && editorActor.send({
|
|
11061
|
+
type: "behavior event",
|
|
11062
|
+
behaviorEvent: {
|
|
11063
|
+
type: "delete",
|
|
11064
|
+
at: selection,
|
|
11065
|
+
unit: options?.mode === "blocks" ? "block" : options?.mode === "children" ? "child" : void 0
|
|
11066
|
+
},
|
|
11067
|
+
editor
|
|
11068
|
+
});
|
|
11128
11069
|
},
|
|
11129
11070
|
removeAnnotation: (type) => {
|
|
11130
11071
|
editorActor.send({
|
|
@@ -11825,6 +11766,7 @@ async function updateValue({
|
|
|
11825
11766
|
let doneSyncing = !1, isChanged = !1, isValid = !0;
|
|
11826
11767
|
const hadSelection = !!slateEditor.selection;
|
|
11827
11768
|
if ((!value || value.length === 0) && (debug$2("Value is empty"), clearEditor({
|
|
11769
|
+
context,
|
|
11828
11770
|
slateEditor,
|
|
11829
11771
|
doneSyncing,
|
|
11830
11772
|
hadSelection
|
|
@@ -11934,6 +11876,7 @@ async function* getStreamedBlocks({
|
|
|
11934
11876
|
index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
11935
11877
|
}
|
|
11936
11878
|
function clearEditor({
|
|
11879
|
+
context,
|
|
11937
11880
|
slateEditor,
|
|
11938
11881
|
doneSyncing,
|
|
11939
11882
|
hadSelection
|
|
@@ -11950,9 +11893,7 @@ function clearEditor({
|
|
|
11950
11893
|
Transforms.removeNodes(slateEditor, {
|
|
11951
11894
|
at: [childrenLength - 1 - index]
|
|
11952
11895
|
});
|
|
11953
|
-
}), Transforms.insertNodes(slateEditor,
|
|
11954
|
-
decorators: []
|
|
11955
|
-
}), {
|
|
11896
|
+
}), Transforms.insertNodes(slateEditor, createPlaceholderBlock(context), {
|
|
11956
11897
|
at: [0]
|
|
11957
11898
|
}), hadSelection && Transforms.select(slateEditor, [0, 0]);
|
|
11958
11899
|
});
|
|
@@ -12537,6 +12478,20 @@ class PortableTextEditor extends Component {
|
|
|
12537
12478
|
static blur = (editor) => {
|
|
12538
12479
|
debug("Host blurred"), editor.editable?.blur();
|
|
12539
12480
|
};
|
|
12481
|
+
/**
|
|
12482
|
+
* @deprecated
|
|
12483
|
+
* Use `editor.send(...)` instead
|
|
12484
|
+
*
|
|
12485
|
+
* ```
|
|
12486
|
+
* const editor = useEditor()
|
|
12487
|
+
* editor.send({
|
|
12488
|
+
* type: 'delete',
|
|
12489
|
+
* at: {...},
|
|
12490
|
+
* direction: '...',
|
|
12491
|
+
* unit: '...',
|
|
12492
|
+
* })
|
|
12493
|
+
* ```
|
|
12494
|
+
*/
|
|
12540
12495
|
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
12541
12496
|
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
12542
12497
|
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|