@portabletext/editor 3.0.8 → 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/_chunks-es/util.slice-blocks.js +44 -25
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
- package/lib/index.js +203 -251
- package/lib/index.js.map +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.types.event.ts +1 -1
- package/src/editor/Editable.tsx +5 -4
- 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.block.set.ts +82 -27
- package/src/operations/behavior.operation.block.unset.ts +26 -58
- package/src/operations/behavior.operation.delete.ts +19 -1
- package/src/operations/behavior.operation.insert.block.ts +4 -4
- package/src/types/editor.ts +0 -9
- package/src/utils/parse-blocks.ts +64 -39
- package/src/utils/util.is-empty-text-block.ts +1 -1
- package/src/behaviors/behavior.decorator-pair.ts +0 -212
- package/src/behaviors/behavior.markdown.ts +0 -478
- package/src/editor/plugins/createWithUtils.ts +0 -52
- package/src/internal-utils/get-text-to-emphasize.test.ts +0 -60
- package/src/internal-utils/get-text-to-emphasize.ts +0 -40
package/lib/index.js
CHANGED
|
@@ -5,12 +5,13 @@ 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
|
-
import { getBlockEndPoint, getBlockStartPoint, getBlockKeyFromSelectionPoint, isSelectionCollapsed, isEqualSelectionPoints, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, parseAnnotation, parseSpan, parseInlineObject, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint } from "./_chunks-es/util.slice-blocks.js";
|
|
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";
|
|
12
12
|
import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
|
|
13
13
|
import { defineSchema } from "@portabletext/schema";
|
|
14
|
+
import { isEmptyTextBlock, sliceTextBlock, getTextBlockText } from "./_chunks-es/util.slice-text-block.js";
|
|
14
15
|
import { getFocusInlineObject, isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection, getFocusBlock as getFocusBlock$1, isSelectingEntireBlocks, getSelectedValue, getActiveDecorators, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getMarkState, getActiveAnnotationsMarks, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getFocusChild as getFocusChild$1, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
|
|
15
16
|
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
16
17
|
import uniq from "lodash/uniq.js";
|
|
@@ -20,9 +21,7 @@ import { htmlToBlocks } from "@portabletext/block-tools";
|
|
|
20
21
|
import { toHTML } from "@portabletext/to-html";
|
|
21
22
|
import { Schema } from "@sanity/schema";
|
|
22
23
|
import flatten from "lodash/flatten.js";
|
|
23
|
-
import
|
|
24
|
-
import { applyAll, unset, insert, set, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
25
|
-
import { isEmptyTextBlock, sliceTextBlock, getTextBlockText } from "./_chunks-es/util.slice-text-block.js";
|
|
24
|
+
import { set, applyAll, unset, insert, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
26
25
|
import { createDraft, finishDraft } from "immer";
|
|
27
26
|
import { createKeyboardShortcut, code, underline, italic, bold, undo, redo } from "@portabletext/keyboard-shortcuts";
|
|
28
27
|
import isPlainObject from "lodash/isPlainObject.js";
|
|
@@ -30,10 +29,10 @@ import { EditorContext } from "./_chunks-es/use-editor.js";
|
|
|
30
29
|
import { useEditor } from "./_chunks-es/use-editor.js";
|
|
31
30
|
import { Subject } from "rxjs";
|
|
32
31
|
const rootName = "sanity-pte:";
|
|
33
|
-
debug$
|
|
32
|
+
debug$i(rootName);
|
|
34
33
|
function debugWithName(name) {
|
|
35
34
|
const namespace = `${rootName}${name}`;
|
|
36
|
-
return debug$
|
|
35
|
+
return debug$i && debug$i.enabled(namespace) ? debug$i(namespace) : debug$i(rootName);
|
|
37
36
|
}
|
|
38
37
|
const VOID_CHILD_KEY = "void-child";
|
|
39
38
|
function keepObjectEquality(object, keyMap) {
|
|
@@ -1539,7 +1538,7 @@ function toKeyName(name) {
|
|
|
1539
1538
|
const keyName = name.toLowerCase();
|
|
1540
1539
|
return aliases[keyName] ?? keyName;
|
|
1541
1540
|
}
|
|
1542
|
-
const debug$
|
|
1541
|
+
const debug$h = debugWithName("plugin:withHotKeys");
|
|
1543
1542
|
function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
|
|
1544
1543
|
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
|
|
1545
1544
|
return function(editor) {
|
|
@@ -1554,7 +1553,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
1554
1553
|
const possibleMark = activeHotkeys[cat];
|
|
1555
1554
|
if (possibleMark) {
|
|
1556
1555
|
const mark = possibleMark[hotkey];
|
|
1557
|
-
debug$
|
|
1556
|
+
debug$h(`HotKey ${hotkey} to toggle ${mark}`), editorActor.send({
|
|
1558
1557
|
type: "behavior event",
|
|
1559
1558
|
behaviorEvent: {
|
|
1560
1559
|
type: "decorator.toggle",
|
|
@@ -1883,7 +1882,7 @@ function createDecorate(schema, slateEditor) {
|
|
|
1883
1882
|
}) || Range.includes(decoratedRange, path));
|
|
1884
1883
|
};
|
|
1885
1884
|
}
|
|
1886
|
-
const RelayActorContext = createContext({}), debug$
|
|
1885
|
+
const RelayActorContext = createContext({}), debug$g = debugWithName("validate selection machine"), validateSelectionSetup = setup({
|
|
1887
1886
|
types: {
|
|
1888
1887
|
context: {},
|
|
1889
1888
|
input: {},
|
|
@@ -1955,12 +1954,12 @@ function validateSelection(slateEditor, editorElement) {
|
|
|
1955
1954
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
1956
1955
|
try {
|
|
1957
1956
|
const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
1958
|
-
(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));
|
|
1959
1958
|
} catch {
|
|
1960
|
-
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();
|
|
1961
1960
|
}
|
|
1962
1961
|
}
|
|
1963
|
-
const debug$
|
|
1962
|
+
const debug$f = debugWithName("component:Editable"), PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
1964
1963
|
const $ = c(176);
|
|
1965
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;
|
|
1966
1965
|
$[0] !== props ? ({
|
|
@@ -2049,10 +2048,10 @@ const debug$g = debugWithName("component:Editable"), PortableTextEditable = forw
|
|
|
2049
2048
|
let t14;
|
|
2050
2049
|
$[63] !== editorActor || $[64] !== propsSelection || $[65] !== slateEditor ? (t14 = () => {
|
|
2051
2050
|
if (propsSelection) {
|
|
2052
|
-
debug$
|
|
2051
|
+
debug$f(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
2053
2052
|
const normalizedSelection = normalizeSelection(propsSelection, slateEditor.value);
|
|
2054
2053
|
if (normalizedSelection !== null) {
|
|
2055
|
-
debug$
|
|
2054
|
+
debug$f(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
2056
2055
|
const slateRange = toSlateRange({
|
|
2057
2056
|
context: {
|
|
2058
2057
|
schema: editorActor.getSnapshot().context.schema,
|
|
@@ -2164,8 +2163,8 @@ const debug$g = debugWithName("component:Editable"), PortableTextEditable = forw
|
|
|
2164
2163
|
event_1.preventDefault(), relayActor.send({
|
|
2165
2164
|
type: "loading"
|
|
2166
2165
|
}), Promise.resolve(onPasteResult).then((result_1) => {
|
|
2167
|
-
if (debug$
|
|
2168
|
-
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");
|
|
2169
2168
|
const selection_1 = editorActor.getSnapshot().context.selection, position_1 = selection_1 ? {
|
|
2170
2169
|
selection: selection_1
|
|
2171
2170
|
} : void 0;
|
|
@@ -2233,7 +2232,7 @@ const debug$g = debugWithName("component:Editable"), PortableTextEditable = forw
|
|
|
2233
2232
|
nativeEvent: event_1
|
|
2234
2233
|
});
|
|
2235
2234
|
}
|
|
2236
|
-
debug$
|
|
2235
|
+
debug$f("No result from custom paste handler, pasting normally");
|
|
2237
2236
|
}, $[85] = editorActor, $[86] = onPaste, $[87] = portableTextEditor, $[88] = relayActor, $[89] = slateEditor, $[90] = t21) : t21 = $[90];
|
|
2238
2237
|
const handlePaste = t21;
|
|
2239
2238
|
let t22;
|
|
@@ -2241,7 +2240,7 @@ const debug$g = debugWithName("component:Editable"), PortableTextEditable = forw
|
|
|
2241
2240
|
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
2242
2241
|
type: "focused",
|
|
2243
2242
|
event: event_2
|
|
2244
|
-
}), !slateEditor.selection &&
|
|
2243
|
+
}), !slateEditor.selection && slateEditor.children.length === 1 && isEmptyTextBlock(editorActor.getSnapshot().context, slateEditor.value.at(0)) && (Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.onChange()));
|
|
2245
2244
|
}, $[91] = editorActor, $[92] = onFocus, $[93] = relayActor, $[94] = slateEditor, $[95] = t22) : t22 = $[95];
|
|
2246
2245
|
const handleOnFocus = t22;
|
|
2247
2246
|
let t23;
|
|
@@ -2973,7 +2972,7 @@ function mergeIntoLastStep(steps, lastStep, op) {
|
|
|
2973
2972
|
operations: [...lastStep.operations, op]
|
|
2974
2973
|
}];
|
|
2975
2974
|
}
|
|
2976
|
-
const debug$
|
|
2975
|
+
const debug$e = debugWithName("plugin:history"), UNDO_STEP_LIMIT = 1e3;
|
|
2977
2976
|
function pluginHistory({
|
|
2978
2977
|
editorActor,
|
|
2979
2978
|
subscriptions
|
|
@@ -2990,7 +2989,7 @@ function pluginHistory({
|
|
|
2990
2989
|
for (const patch of patches)
|
|
2991
2990
|
if (!reset && patch.origin !== "local") {
|
|
2992
2991
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2993
|
-
debug$
|
|
2992
|
+
debug$e("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
2994
2993
|
undos: [],
|
|
2995
2994
|
redos: []
|
|
2996
2995
|
}, remotePatches.splice(0, remotePatches.length), setWithHistory(editor, !0), reset = !0;
|
|
@@ -3075,7 +3074,7 @@ function getNextSpan({
|
|
|
3075
3074
|
}
|
|
3076
3075
|
return nextSpan;
|
|
3077
3076
|
}
|
|
3078
|
-
const debug$
|
|
3077
|
+
const debug$d = debugWithName("plugin:withPortableTextMarkModel");
|
|
3079
3078
|
function createWithPortableTextMarkModel(editorActor) {
|
|
3080
3079
|
return function(editor) {
|
|
3081
3080
|
const {
|
|
@@ -3089,7 +3088,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3089
3088
|
for (const [child, childPath] of children) {
|
|
3090
3089
|
const nextNode = node.children[childPath[1] + 1];
|
|
3091
3090
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3092
|
-
debug$
|
|
3091
|
+
debug$d("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), withNormalizeNode(editor, () => {
|
|
3093
3092
|
Transforms.mergeNodes(editor, {
|
|
3094
3093
|
at: [childPath[0], childPath[1] + 1],
|
|
3095
3094
|
voids: !0
|
|
@@ -3100,7 +3099,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3100
3099
|
}
|
|
3101
3100
|
}
|
|
3102
3101
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3103
|
-
debug$
|
|
3102
|
+
debug$d("Adding .markDefs to block node"), withNormalizeNode(editor, () => {
|
|
3104
3103
|
Transforms.setNodes(editor, {
|
|
3105
3104
|
markDefs: []
|
|
3106
3105
|
}, {
|
|
@@ -3110,7 +3109,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3110
3109
|
return;
|
|
3111
3110
|
}
|
|
3112
3111
|
if (defaultStyle && editor.isTextBlock(node) && typeof node.style > "u") {
|
|
3113
|
-
debug$
|
|
3112
|
+
debug$d("Adding .style to block node"), withNormalizeNode(editor, () => {
|
|
3114
3113
|
Transforms.setNodes(editor, {
|
|
3115
3114
|
style: defaultStyle
|
|
3116
3115
|
}, {
|
|
@@ -3120,7 +3119,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3120
3119
|
return;
|
|
3121
3120
|
}
|
|
3122
3121
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3123
|
-
debug$
|
|
3122
|
+
debug$d("Adding .marks to span node"), withNormalizeNode(editor, () => {
|
|
3124
3123
|
Transforms.setNodes(editor, {
|
|
3125
3124
|
marks: []
|
|
3126
3125
|
}, {
|
|
@@ -3132,7 +3131,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3132
3131
|
if (editor.isTextSpan(node)) {
|
|
3133
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));
|
|
3134
3133
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3135
|
-
debug$
|
|
3134
|
+
debug$d("Removing annotations from empty span node"), withNormalizeNode(editor, () => {
|
|
3136
3135
|
Transforms.setNodes(editor, {
|
|
3137
3136
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
3138
3137
|
}, {
|
|
@@ -3148,7 +3147,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3148
3147
|
if (editor.isTextSpan(child)) {
|
|
3149
3148
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3150
3149
|
if (orphanedAnnotations.length > 0) {
|
|
3151
|
-
debug$
|
|
3150
|
+
debug$d("Removing orphaned annotations from span node"), withNormalizeNode(editor, () => {
|
|
3152
3151
|
Transforms.setNodes(editor, {
|
|
3153
3152
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
3154
3153
|
}, {
|
|
@@ -3164,7 +3163,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3164
3163
|
if (editor.isTextBlock(block)) {
|
|
3165
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));
|
|
3166
3165
|
if (orphanedAnnotations.length > 0) {
|
|
3167
|
-
debug$
|
|
3166
|
+
debug$d("Removing orphaned annotations from span node"), withNormalizeNode(editor, () => {
|
|
3168
3167
|
Transforms.setNodes(editor, {
|
|
3169
3168
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
3170
3169
|
}, {
|
|
@@ -3180,7 +3179,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3180
3179
|
for (const markDef of markDefs)
|
|
3181
3180
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3182
3181
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3183
|
-
debug$
|
|
3182
|
+
debug$d("Removing duplicate markDefs"), withNormalizeNode(editor, () => {
|
|
3184
3183
|
Transforms.setNodes(editor, {
|
|
3185
3184
|
markDefs: newMarkDefs
|
|
3186
3185
|
}, {
|
|
@@ -3193,7 +3192,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3193
3192
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3194
3193
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3195
3194
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
3196
|
-
debug$
|
|
3195
|
+
debug$d("Removing markDef not in use"), withNormalizeNode(editor, () => {
|
|
3197
3196
|
Transforms.setNodes(editor, {
|
|
3198
3197
|
markDefs: newMarkDefs
|
|
3199
3198
|
}, {
|
|
@@ -3285,7 +3284,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3285
3284
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
3286
3285
|
if (editor.isTextBlock(targetBlock)) {
|
|
3287
3286
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
3288
|
-
debug$
|
|
3287
|
+
debug$d("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
3289
3288
|
markDefs: newMarkDefs
|
|
3290
3289
|
}, {
|
|
3291
3290
|
at: targetPath,
|
|
@@ -3981,7 +3980,7 @@ function parse(textline) {
|
|
|
3981
3980
|
function toInt(num) {
|
|
3982
3981
|
return parseInt(num, 10);
|
|
3983
3982
|
}
|
|
3984
|
-
const debug$
|
|
3983
|
+
const debug$c = debugWithName("transformOperation");
|
|
3985
3984
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
3986
3985
|
const transformedOperation = {
|
|
3987
3986
|
...operation
|
|
@@ -3990,16 +3989,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
3990
3989
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
3991
3990
|
_key: blk._key
|
|
3992
3991
|
}, patch.path[0]));
|
|
3993
|
-
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)];
|
|
3994
3993
|
}
|
|
3995
3994
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
3996
3995
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
|
|
3997
3996
|
_key: blk._key
|
|
3998
3997
|
}, patch.path[0]));
|
|
3999
|
-
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)];
|
|
4000
3999
|
}
|
|
4001
4000
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
4002
|
-
return debug$
|
|
4001
|
+
return debug$c(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
4003
4002
|
if (patch.type === "diffMatchPatch") {
|
|
4004
4003
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
4005
4004
|
return !operationTargetBlock || !isEqual({
|
|
@@ -4070,7 +4069,7 @@ function findOperationTargetBlock(editor, operation) {
|
|
|
4070
4069
|
let block;
|
|
4071
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;
|
|
4072
4071
|
}
|
|
4073
|
-
const debug$
|
|
4072
|
+
const debug$b = debugWithName("behavior.operation.history.redo"), historyRedoOperationImplementation = ({
|
|
4074
4073
|
operation
|
|
4075
4074
|
}) => {
|
|
4076
4075
|
const editor = operation.editor, {
|
|
@@ -4078,7 +4077,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4078
4077
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
4079
4078
|
if (redos.length > 0) {
|
|
4080
4079
|
const step = redos[redos.length - 1];
|
|
4081
|
-
if (debug$
|
|
4080
|
+
if (debug$b("Redoing", step), step.operations.length > 0) {
|
|
4082
4081
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
4083
4082
|
let transformedOperations = step.operations;
|
|
4084
4083
|
otherPatches.forEach((item) => {
|
|
@@ -4095,7 +4094,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4095
4094
|
});
|
|
4096
4095
|
});
|
|
4097
4096
|
} catch (err) {
|
|
4098
|
-
debug$
|
|
4097
|
+
debug$b("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
4099
4098
|
undos: [],
|
|
4100
4099
|
redos: []
|
|
4101
4100
|
}, setWithHistory(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -4104,7 +4103,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4104
4103
|
editor.history.undos.push(step), editor.history.redos.pop();
|
|
4105
4104
|
}
|
|
4106
4105
|
}
|
|
4107
|
-
}, debug$
|
|
4106
|
+
}, debug$a = debugWithName("behavior.operation.history.undo"), historyUndoOperationImplementation = ({
|
|
4108
4107
|
operation
|
|
4109
4108
|
}) => {
|
|
4110
4109
|
const editor = operation.editor, {
|
|
@@ -4112,7 +4111,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4112
4111
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
4113
4112
|
if (undos.length > 0) {
|
|
4114
4113
|
const step = undos[undos.length - 1];
|
|
4115
|
-
if (debug$
|
|
4114
|
+
if (debug$a("Undoing", step), step.operations.length > 0) {
|
|
4116
4115
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
4117
4116
|
let transformedOperations = step.operations;
|
|
4118
4117
|
otherPatches.forEach((item) => {
|
|
@@ -4130,7 +4129,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4130
4129
|
});
|
|
4131
4130
|
});
|
|
4132
4131
|
} catch (err) {
|
|
4133
|
-
debug$
|
|
4132
|
+
debug$a("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
4134
4133
|
undos: [],
|
|
4135
4134
|
redos: []
|
|
4136
4135
|
}, setWithHistory(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -4265,32 +4264,58 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4265
4264
|
const blockIndex = operation.editor.blockIndexMap.get(operation.at[0]._key);
|
|
4266
4265
|
if (blockIndex === void 0)
|
|
4267
4266
|
throw new Error(`Unable to find block index for block at ${JSON.stringify(operation.at)}`);
|
|
4268
|
-
const
|
|
4269
|
-
if (!
|
|
4267
|
+
const slateBlock = operation.editor.children.at(blockIndex);
|
|
4268
|
+
if (!slateBlock)
|
|
4270
4269
|
throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4270
|
+
if (isTextBlock(context, slateBlock)) {
|
|
4271
|
+
const filteredProps = {};
|
|
4272
|
+
for (const key of Object.keys(operation.props))
|
|
4273
|
+
if (!(key === "_type" || key === "children")) {
|
|
4274
|
+
if (key === "style") {
|
|
4275
|
+
context.schema.styles.some((style) => style.name === operation.props[key]) && (filteredProps[key] = operation.props[key]);
|
|
4276
|
+
continue;
|
|
4277
|
+
}
|
|
4278
|
+
if (key === "listItem") {
|
|
4279
|
+
context.schema.lists.some((list) => list.name === operation.props[key]) && (filteredProps[key] = operation.props[key]);
|
|
4280
|
+
continue;
|
|
4281
|
+
}
|
|
4282
|
+
if (key === "level") {
|
|
4283
|
+
filteredProps[key] = operation.props[key];
|
|
4284
|
+
continue;
|
|
4285
|
+
}
|
|
4286
|
+
if (key === "markDefs") {
|
|
4287
|
+
const {
|
|
4288
|
+
markDefs
|
|
4289
|
+
} = parseMarkDefs({
|
|
4290
|
+
context,
|
|
4291
|
+
markDefs: operation.props[key],
|
|
4292
|
+
options: {
|
|
4293
|
+
validateFields: !0
|
|
4294
|
+
}
|
|
4295
|
+
});
|
|
4296
|
+
filteredProps[key] = markDefs;
|
|
4297
|
+
continue;
|
|
4298
|
+
}
|
|
4299
|
+
context.schema.block.fields?.some((field) => field.name === key) && (filteredProps[key] = operation.props[key]);
|
|
4300
|
+
}
|
|
4301
|
+
Transforms.setNodes(operation.editor, filteredProps, {
|
|
4302
|
+
at: [blockIndex]
|
|
4303
|
+
});
|
|
4304
|
+
} else {
|
|
4305
|
+
const schemaDefinition = context.schema.blockObjects.find((definition) => definition.name === slateBlock._type), filteredProps = {};
|
|
4306
|
+
for (const key of Object.keys(operation.props))
|
|
4307
|
+
if (key !== "_type") {
|
|
4308
|
+
if (key === "_key") {
|
|
4309
|
+
filteredProps[key] = operation.props[key];
|
|
4310
|
+
continue;
|
|
4311
|
+
}
|
|
4312
|
+
schemaDefinition?.fields.some((field) => field.name === key) && (filteredProps[key] = operation.props[key]);
|
|
4313
|
+
}
|
|
4314
|
+
const patches = Object.entries(filteredProps).map(([key, value]) => key === "_key" ? set(value, ["_key"]) : set(value, ["value", key])), updatedSlateBlock = applyAll(slateBlock, patches);
|
|
4315
|
+
Transforms.setNodes(operation.editor, updatedSlateBlock, {
|
|
4316
|
+
at: [blockIndex]
|
|
4317
|
+
});
|
|
4318
|
+
}
|
|
4294
4319
|
}, blockUnsetOperationImplementation = ({
|
|
4295
4320
|
context,
|
|
4296
4321
|
operation
|
|
@@ -4298,50 +4323,22 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4298
4323
|
const blockKey = operation.at[0]._key, blockIndex = operation.editor.blockIndexMap.get(blockKey);
|
|
4299
4324
|
if (blockIndex === void 0)
|
|
4300
4325
|
throw new Error(`Unable to find block index for block key ${blockKey}`);
|
|
4301
|
-
const
|
|
4302
|
-
if (!
|
|
4326
|
+
const slateBlock = blockIndex !== void 0 ? operation.editor.children.at(blockIndex) : void 0;
|
|
4327
|
+
if (!slateBlock)
|
|
4303
4328
|
throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
|
|
4304
|
-
if (isTextBlock(context,
|
|
4305
|
-
const propsToRemove = operation.props.filter((prop) => prop !== "_type"
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
validateFields: !0
|
|
4312
|
-
}
|
|
4313
|
-
});
|
|
4314
|
-
if (!updatedTextBlock)
|
|
4315
|
-
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
4316
|
-
const propsToSet = {};
|
|
4317
|
-
for (const prop of propsToRemove)
|
|
4318
|
-
prop in updatedTextBlock ? propsToSet[prop] = updatedTextBlock[prop] : propsToSet[prop] = void 0;
|
|
4319
|
-
Transforms.setNodes(operation.editor, propsToSet, {
|
|
4329
|
+
if (isTextBlock(context, slateBlock)) {
|
|
4330
|
+
const propsToRemove = operation.props.filter((prop) => prop !== "_type" && prop !== "_key" && prop !== "children");
|
|
4331
|
+
Transforms.unsetNodes(operation.editor, propsToRemove, {
|
|
4332
|
+
at: [blockIndex]
|
|
4333
|
+
}), operation.props.includes("_key") && Transforms.setNodes(operation.editor, {
|
|
4334
|
+
_key: context.keyGenerator()
|
|
4335
|
+
}, {
|
|
4320
4336
|
at: [blockIndex]
|
|
4321
4337
|
});
|
|
4322
4338
|
return;
|
|
4323
4339
|
}
|
|
4324
|
-
const
|
|
4325
|
-
|
|
4326
|
-
block: omit(block, operation.props.filter((prop) => prop !== "_type")),
|
|
4327
|
-
options: {
|
|
4328
|
-
normalize: !1,
|
|
4329
|
-
removeUnusedMarkDefs: !0,
|
|
4330
|
-
validateFields: !0
|
|
4331
|
-
}
|
|
4332
|
-
});
|
|
4333
|
-
if (!updatedBlockObject)
|
|
4334
|
-
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
4335
|
-
const {
|
|
4336
|
-
_type,
|
|
4337
|
-
_key,
|
|
4338
|
-
...props
|
|
4339
|
-
} = updatedBlockObject;
|
|
4340
|
-
Transforms.setNodes(operation.editor, {
|
|
4341
|
-
_type,
|
|
4342
|
-
_key,
|
|
4343
|
-
value: props
|
|
4344
|
-
}, {
|
|
4340
|
+
const patches = operation.props.flatMap((key) => key === "_type" ? [] : key === "_key" ? set(context.keyGenerator(), ["_key"]) : unset(["value", key])), updatedSlateBlock = applyAll(slateBlock, patches);
|
|
4341
|
+
Transforms.setNodes(operation.editor, updatedSlateBlock, {
|
|
4345
4342
|
at: [blockIndex]
|
|
4346
4343
|
});
|
|
4347
4344
|
}, childSetOperationImplementation = ({
|
|
@@ -4589,6 +4586,16 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
|
|
|
4589
4586
|
}), operation.editor.children.length === 0 && Transforms.insertNodes(operation.editor, createPlaceholderBlock(context));
|
|
4590
4587
|
return;
|
|
4591
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
|
+
}
|
|
4592
4599
|
if (operation.direction === "backward" && operation.unit === "line") {
|
|
4593
4600
|
const range = at ?? operation.editor.selection ?? void 0;
|
|
4594
4601
|
if (!range)
|
|
@@ -4714,7 +4721,7 @@ function insertBlock(options) {
|
|
|
4714
4721
|
at: nextPath
|
|
4715
4722
|
}), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
4716
4723
|
} else {
|
|
4717
|
-
if (
|
|
4724
|
+
if (isEmptyTextBlock(context, endBlock)) {
|
|
4718
4725
|
Transforms.insertNodes(editor, [block], {
|
|
4719
4726
|
at: endBlockPath,
|
|
4720
4727
|
select: !1
|
|
@@ -4771,14 +4778,14 @@ function insertBlock(options) {
|
|
|
4771
4778
|
select: select !== "none"
|
|
4772
4779
|
});
|
|
4773
4780
|
const atAfterInsert = atBeforeInsert?.unref() ?? editor.selection;
|
|
4774
|
-
select === "none" && atAfterInsert && Transforms.select(editor, atAfterInsert),
|
|
4781
|
+
select === "none" && atAfterInsert && Transforms.select(editor, atAfterInsert), isEmptyTextBlock(context, focusBlock) && Transforms.removeNodes(editor, {
|
|
4775
4782
|
at: focusBlockPath
|
|
4776
4783
|
});
|
|
4777
4784
|
return;
|
|
4778
4785
|
}
|
|
4779
4786
|
if (editor.isTextBlock(endBlock) && editor.isTextBlock(block)) {
|
|
4780
4787
|
const selectionStartPoint = Range.start(at);
|
|
4781
|
-
if (
|
|
4788
|
+
if (isEmptyTextBlock(context, endBlock)) {
|
|
4782
4789
|
Transforms.insertNodes(editor, [block], {
|
|
4783
4790
|
at: endBlockPath,
|
|
4784
4791
|
select: !1
|
|
@@ -5568,16 +5575,16 @@ function createWithObjectKeys(editorActor) {
|
|
|
5568
5575
|
}, editor;
|
|
5569
5576
|
};
|
|
5570
5577
|
}
|
|
5571
|
-
function createApplyPatch(
|
|
5578
|
+
function createApplyPatch(context) {
|
|
5572
5579
|
return (editor, patch) => {
|
|
5573
5580
|
let changed = !1;
|
|
5574
5581
|
try {
|
|
5575
5582
|
switch (patch.type) {
|
|
5576
5583
|
case "insert":
|
|
5577
|
-
changed = insertPatch(editor, patch
|
|
5584
|
+
changed = insertPatch(context, editor, patch);
|
|
5578
5585
|
break;
|
|
5579
5586
|
case "unset":
|
|
5580
|
-
changed = unsetPatch(editor, patch);
|
|
5587
|
+
changed = unsetPatch(context, editor, patch);
|
|
5581
5588
|
break;
|
|
5582
5589
|
case "set":
|
|
5583
5590
|
changed = setPatch(editor, patch);
|
|
@@ -5617,7 +5624,7 @@ function diffMatchPatch(editor, patch) {
|
|
|
5617
5624
|
}) : op === DIFF_EQUAL && (offset += text.length);
|
|
5618
5625
|
return !0;
|
|
5619
5626
|
}
|
|
5620
|
-
function insertPatch(editor, patch
|
|
5627
|
+
function insertPatch(context, editor, patch) {
|
|
5621
5628
|
const block = findBlock(editor.children, patch.path);
|
|
5622
5629
|
if (!block || patch.path.length > 1 && patch.path[1] !== "children")
|
|
5623
5630
|
return !1;
|
|
@@ -5626,8 +5633,8 @@ function insertPatch(editor, patch, schema) {
|
|
|
5626
5633
|
items: items2,
|
|
5627
5634
|
position: position2
|
|
5628
5635
|
} = patch, blocksToInsert = items2.map((item) => toSlateBlock(item, {
|
|
5629
|
-
schemaTypes: schema
|
|
5630
|
-
}, 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);
|
|
5631
5638
|
return Transforms.insertNodes(editor, blocksToInsert, {
|
|
5632
5639
|
at: [normalizedIdx2]
|
|
5633
5640
|
}), editorWasEmptyBefore && typeof patch.path[0] == "number" && patch.path[0] === 0 && Transforms.removeNodes(editor, {
|
|
@@ -5644,7 +5651,7 @@ function insertPatch(editor, patch, schema) {
|
|
|
5644
5651
|
...block.node,
|
|
5645
5652
|
children: items
|
|
5646
5653
|
}, {
|
|
5647
|
-
schemaTypes: schema
|
|
5654
|
+
schemaTypes: context.schema
|
|
5648
5655
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), normalizedIdx = position === "after" ? targetChild.index + 1 : targetChild.index, childInsertPath = [block.index, normalizedIdx];
|
|
5649
5656
|
return childrenToInsert && Element$1.isElement(childrenToInsert) && Transforms.insertNodes(editor, childrenToInsert.children, {
|
|
5650
5657
|
at: childInsertPath
|
|
@@ -5784,7 +5791,7 @@ function setPatch(editor, patch) {
|
|
|
5784
5791
|
return !1;
|
|
5785
5792
|
return !0;
|
|
5786
5793
|
}
|
|
5787
|
-
function unsetPatch(editor, patch) {
|
|
5794
|
+
function unsetPatch(context, editor, patch) {
|
|
5788
5795
|
if (patch.path.length === 0) {
|
|
5789
5796
|
const previousSelection = editor.selection;
|
|
5790
5797
|
Transforms.deselect(editor);
|
|
@@ -5795,9 +5802,7 @@ function unsetPatch(editor, patch) {
|
|
|
5795
5802
|
Transforms.removeNodes(editor, {
|
|
5796
5803
|
at: path
|
|
5797
5804
|
});
|
|
5798
|
-
return Transforms.insertNodes(editor,
|
|
5799
|
-
decorators: []
|
|
5800
|
-
})), previousSelection && Transforms.select(editor, {
|
|
5805
|
+
return Transforms.insertNodes(editor, createPlaceholderBlock(context)), previousSelection && Transforms.select(editor, {
|
|
5801
5806
|
anchor: {
|
|
5802
5807
|
path: [0, 0],
|
|
5803
5808
|
offset: 0
|
|
@@ -5816,9 +5821,7 @@ function unsetPatch(editor, patch) {
|
|
|
5816
5821
|
const previousSelection = editor.selection;
|
|
5817
5822
|
return Transforms.deselect(editor), Transforms.removeNodes(editor, {
|
|
5818
5823
|
at: [block.index]
|
|
5819
|
-
}), Transforms.insertNodes(editor,
|
|
5820
|
-
decorators: []
|
|
5821
|
-
})), previousSelection && Transforms.select(editor, {
|
|
5824
|
+
}), Transforms.insertNodes(editor, createPlaceholderBlock(context)), previousSelection && Transforms.select(editor, {
|
|
5822
5825
|
anchor: {
|
|
5823
5826
|
path: [0, 0],
|
|
5824
5827
|
offset: 0
|
|
@@ -6223,14 +6226,14 @@ function withoutPatching(editor, fn) {
|
|
|
6223
6226
|
function isPatching(editor) {
|
|
6224
6227
|
return PATCHING.get(editor);
|
|
6225
6228
|
}
|
|
6226
|
-
const debug$
|
|
6229
|
+
const debug$9 = debugWithName("plugin:withPatches");
|
|
6227
6230
|
function createWithPatches({
|
|
6228
6231
|
editorActor,
|
|
6229
6232
|
relayActor,
|
|
6230
6233
|
subscriptions
|
|
6231
6234
|
}) {
|
|
6232
6235
|
let previousValue;
|
|
6233
|
-
const applyPatch = createApplyPatch(editorActor.getSnapshot().context
|
|
6236
|
+
const applyPatch = createApplyPatch(editorActor.getSnapshot().context);
|
|
6234
6237
|
return function(editor) {
|
|
6235
6238
|
IS_PROCESSING_REMOTE_CHANGES.set(editor, !1), PATCHING.set(editor, !0), previousValue = [...editor.value];
|
|
6236
6239
|
const {
|
|
@@ -6248,7 +6251,7 @@ function createWithPatches({
|
|
|
6248
6251
|
withoutPatching(editor, () => {
|
|
6249
6252
|
pluginWithoutHistory(editor, () => {
|
|
6250
6253
|
for (const patch of patches) {
|
|
6251
|
-
debug$
|
|
6254
|
+
debug$9.enabled && debug$9(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
6252
6255
|
try {
|
|
6253
6256
|
changed = applyPatch(editor, patch);
|
|
6254
6257
|
} catch (error) {
|
|
@@ -6266,10 +6269,10 @@ function createWithPatches({
|
|
|
6266
6269
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
6267
6270
|
};
|
|
6268
6271
|
return subscriptions.push(() => {
|
|
6269
|
-
debug$
|
|
6272
|
+
debug$9("Subscribing to remote patches");
|
|
6270
6273
|
const sub = editorActor.on("patches", handlePatches);
|
|
6271
6274
|
return () => {
|
|
6272
|
-
debug$
|
|
6275
|
+
debug$9("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
6273
6276
|
};
|
|
6274
6277
|
}), editor.apply = (operation) => {
|
|
6275
6278
|
let patches = [];
|
|
@@ -6323,7 +6326,7 @@ function createWithPatches({
|
|
|
6323
6326
|
}, editor;
|
|
6324
6327
|
};
|
|
6325
6328
|
}
|
|
6326
|
-
const debug$
|
|
6329
|
+
const debug$8 = debugWithName("plugin:withPlaceholderBlock");
|
|
6327
6330
|
function createWithPlaceholderBlock(editorActor) {
|
|
6328
6331
|
return function(editor) {
|
|
6329
6332
|
const {
|
|
@@ -6346,15 +6349,13 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
6346
6349
|
}
|
|
6347
6350
|
if (op.type === "remove_node") {
|
|
6348
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;
|
|
6349
|
-
isLonelyBlock && isBlockObject && (debug$
|
|
6350
|
-
decorators: []
|
|
6351
|
-
})));
|
|
6352
|
+
isLonelyBlock && isBlockObject && (debug$8("Adding placeholder block"), Editor.insertNode(editor, createPlaceholderBlock(editorActor.getSnapshot().context)));
|
|
6352
6353
|
}
|
|
6353
6354
|
apply2(op);
|
|
6354
6355
|
}, editor;
|
|
6355
6356
|
};
|
|
6356
6357
|
}
|
|
6357
|
-
const debug$
|
|
6358
|
+
const debug$7 = debugWithName("plugin:withSchemaTypes");
|
|
6358
6359
|
function createWithSchemaTypes({
|
|
6359
6360
|
editorActor
|
|
6360
6361
|
}) {
|
|
@@ -6366,7 +6367,7 @@ function createWithSchemaTypes({
|
|
|
6366
6367
|
return editor.normalizeNode = (entry) => {
|
|
6367
6368
|
const [node, path] = entry;
|
|
6368
6369
|
if (node._type === void 0 && path.length === 2) {
|
|
6369
|
-
debug$
|
|
6370
|
+
debug$7("Setting span type on text node without a type");
|
|
6370
6371
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
6371
6372
|
withNormalizeNode(editor, () => {
|
|
6372
6373
|
Transforms.setNodes(editor, {
|
|
@@ -6380,7 +6381,7 @@ function createWithSchemaTypes({
|
|
|
6380
6381
|
return;
|
|
6381
6382
|
}
|
|
6382
6383
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
6383
|
-
debug$
|
|
6384
|
+
debug$7("Setting missing key on child node without a key");
|
|
6384
6385
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
6385
6386
|
withNormalizeNode(editor, () => {
|
|
6386
6387
|
Transforms.setNodes(editor, {
|
|
@@ -6397,34 +6398,6 @@ function createWithSchemaTypes({
|
|
|
6397
6398
|
}, editor;
|
|
6398
6399
|
};
|
|
6399
6400
|
}
|
|
6400
|
-
function createWithUtils({
|
|
6401
|
-
editorActor
|
|
6402
|
-
}) {
|
|
6403
|
-
return function(editor) {
|
|
6404
|
-
return editor.pteCreateTextBlock = (options) => toSlateBlock({
|
|
6405
|
-
_type: editorActor.getSnapshot().context.schema.block.name,
|
|
6406
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
6407
|
-
style: editorActor.getSnapshot().context.schema.styles[0].name || "normal",
|
|
6408
|
-
...options.listItem ? {
|
|
6409
|
-
listItem: options.listItem
|
|
6410
|
-
} : {},
|
|
6411
|
-
...options.level ? {
|
|
6412
|
-
level: options.level
|
|
6413
|
-
} : {},
|
|
6414
|
-
markDefs: [],
|
|
6415
|
-
children: [{
|
|
6416
|
-
_type: "span",
|
|
6417
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
6418
|
-
text: "",
|
|
6419
|
-
marks: options.decorators.filter((decorator) => editorActor.getSnapshot().context.schema.decorators.find(({
|
|
6420
|
-
name
|
|
6421
|
-
}) => name === decorator))
|
|
6422
|
-
}]
|
|
6423
|
-
}, {
|
|
6424
|
-
schemaTypes: editorActor.getSnapshot().context.schema
|
|
6425
|
-
}), editor;
|
|
6426
|
-
};
|
|
6427
|
-
}
|
|
6428
6401
|
function pluginUpdateSelection({
|
|
6429
6402
|
editor,
|
|
6430
6403
|
editorActor
|
|
@@ -6765,16 +6738,14 @@ const withPlugins = (editor, options) => {
|
|
|
6765
6738
|
}), withUndoRedo = pluginHistory({
|
|
6766
6739
|
editorActor,
|
|
6767
6740
|
subscriptions: options.subscriptions
|
|
6768
|
-
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor)
|
|
6769
|
-
|
|
6770
|
-
});
|
|
6771
|
-
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({
|
|
6772
6743
|
editorActor,
|
|
6773
6744
|
editor: e
|
|
6774
|
-
})))))))))
|
|
6775
|
-
}, debug$
|
|
6745
|
+
})))))))));
|
|
6746
|
+
}, debug$6 = debugWithName("setup");
|
|
6776
6747
|
function createSlateEditor(config) {
|
|
6777
|
-
debug$
|
|
6748
|
+
debug$6("Creating new Slate editor instance");
|
|
6778
6749
|
const placeholderBlock = createPlaceholderBlock(config.editorActor.getSnapshot().context), editor = createEditor();
|
|
6779
6750
|
editor.decoratedRanges = [], editor.decoratorState = {}, editor.value = [placeholderBlock], editor.blockIndexMap = /* @__PURE__ */ new Map(), editor.listIndexMap = /* @__PURE__ */ new Map();
|
|
6780
6751
|
const instance = withPlugins(withReact(editor), {
|
|
@@ -9850,7 +9821,7 @@ function isNativeBehaviorEvent(event) {
|
|
|
9850
9821
|
function isCustomBehaviorEvent(event) {
|
|
9851
9822
|
return event.type.startsWith("custom.");
|
|
9852
9823
|
}
|
|
9853
|
-
const debug$
|
|
9824
|
+
const debug$5 = debugWithName("behaviors:event");
|
|
9854
9825
|
function eventCategory(event) {
|
|
9855
9826
|
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "synthetic" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
9856
9827
|
}
|
|
@@ -9866,7 +9837,7 @@ function performEvent({
|
|
|
9866
9837
|
nativeEvent,
|
|
9867
9838
|
sendBack
|
|
9868
9839
|
}) {
|
|
9869
|
-
mode === "send" && !isNativeBehaviorEvent(event) && createUndoStepId(editor), debug$
|
|
9840
|
+
mode === "send" && !isNativeBehaviorEvent(event) && createUndoStepId(editor), debug$5(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
9870
9841
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
9871
9842
|
if (behavior.on === "*")
|
|
9872
9843
|
return !0;
|
|
@@ -9875,7 +9846,7 @@ function performEvent({
|
|
|
9875
9846
|
});
|
|
9876
9847
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
9877
9848
|
nativeEvent?.preventDefault(), mode === "send" && clearUndoStepId(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9878
|
-
debug$
|
|
9849
|
+
debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9879
9850
|
context: {
|
|
9880
9851
|
keyGenerator,
|
|
9881
9852
|
schema
|
|
@@ -9986,7 +9957,7 @@ function performEvent({
|
|
|
9986
9957
|
break;
|
|
9987
9958
|
}
|
|
9988
9959
|
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStepId(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9989
|
-
debug$
|
|
9960
|
+
debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9990
9961
|
context: {
|
|
9991
9962
|
keyGenerator,
|
|
9992
9963
|
schema
|
|
@@ -10066,7 +10037,7 @@ function createEditorSnapshot({
|
|
|
10066
10037
|
decoratorState: editor.decoratorState
|
|
10067
10038
|
};
|
|
10068
10039
|
}
|
|
10069
|
-
const debug$
|
|
10040
|
+
const debug$4 = debugWithName("editor machine");
|
|
10070
10041
|
function rerouteExternalBehaviorEvent({
|
|
10071
10042
|
event,
|
|
10072
10043
|
slateEditor
|
|
@@ -10323,10 +10294,10 @@ const editorMachine = setup({
|
|
|
10323
10294
|
states: {
|
|
10324
10295
|
"determine initial edit mode": {
|
|
10325
10296
|
entry: [() => {
|
|
10326
|
-
debug$
|
|
10297
|
+
debug$4("entry: edit mode->read only->determine initial edit mode");
|
|
10327
10298
|
}],
|
|
10328
10299
|
exit: [() => {
|
|
10329
|
-
debug$
|
|
10300
|
+
debug$4("exit: edit mode->read only->determine initial edit mode");
|
|
10330
10301
|
}],
|
|
10331
10302
|
on: {
|
|
10332
10303
|
"done syncing value": [{
|
|
@@ -10341,10 +10312,10 @@ const editorMachine = setup({
|
|
|
10341
10312
|
},
|
|
10342
10313
|
"read only": {
|
|
10343
10314
|
entry: [() => {
|
|
10344
|
-
debug$
|
|
10315
|
+
debug$4("entry: edit mode->read only->read only");
|
|
10345
10316
|
}],
|
|
10346
10317
|
exit: [() => {
|
|
10347
|
-
debug$
|
|
10318
|
+
debug$4("exit: edit mode->read only->read only");
|
|
10348
10319
|
}],
|
|
10349
10320
|
on: {
|
|
10350
10321
|
"update readOnly": {
|
|
@@ -10386,10 +10357,10 @@ const editorMachine = setup({
|
|
|
10386
10357
|
states: {
|
|
10387
10358
|
idle: {
|
|
10388
10359
|
entry: [() => {
|
|
10389
|
-
debug$
|
|
10360
|
+
debug$4("entry: edit mode->editable->idle");
|
|
10390
10361
|
}],
|
|
10391
10362
|
exit: [() => {
|
|
10392
|
-
debug$
|
|
10363
|
+
debug$4("exit: edit mode->editable-idle");
|
|
10393
10364
|
}],
|
|
10394
10365
|
on: {
|
|
10395
10366
|
dragstart: {
|
|
@@ -10409,10 +10380,10 @@ const editorMachine = setup({
|
|
|
10409
10380
|
states: {
|
|
10410
10381
|
"checking if busy": {
|
|
10411
10382
|
entry: [() => {
|
|
10412
|
-
debug$
|
|
10383
|
+
debug$4("entry: edit mode->editable->focusing->checking if busy");
|
|
10413
10384
|
}],
|
|
10414
10385
|
exit: [() => {
|
|
10415
|
-
debug$
|
|
10386
|
+
debug$4("exit: edit mode->editable->focusing->checking if busy");
|
|
10416
10387
|
}],
|
|
10417
10388
|
always: [{
|
|
10418
10389
|
guard: "slate is busy",
|
|
@@ -10424,10 +10395,10 @@ const editorMachine = setup({
|
|
|
10424
10395
|
},
|
|
10425
10396
|
busy: {
|
|
10426
10397
|
entry: [() => {
|
|
10427
|
-
debug$
|
|
10398
|
+
debug$4("entry: edit mode->editable->focusing-busy");
|
|
10428
10399
|
}],
|
|
10429
10400
|
exit: [() => {
|
|
10430
|
-
debug$
|
|
10401
|
+
debug$4("exit: edit mode->editable->focusing->busy");
|
|
10431
10402
|
}],
|
|
10432
10403
|
after: {
|
|
10433
10404
|
10: {
|
|
@@ -10439,10 +10410,10 @@ const editorMachine = setup({
|
|
|
10439
10410
|
},
|
|
10440
10411
|
"dragging internally": {
|
|
10441
10412
|
entry: [() => {
|
|
10442
|
-
debug$
|
|
10413
|
+
debug$4("entry: edit mode->editable->dragging internally");
|
|
10443
10414
|
}],
|
|
10444
10415
|
exit: [() => {
|
|
10445
|
-
debug$
|
|
10416
|
+
debug$4("exit: edit mode->editable->dragging internally");
|
|
10446
10417
|
}, ({
|
|
10447
10418
|
context
|
|
10448
10419
|
}) => {
|
|
@@ -10476,10 +10447,10 @@ const editorMachine = setup({
|
|
|
10476
10447
|
states: {
|
|
10477
10448
|
"setting up": {
|
|
10478
10449
|
entry: [() => {
|
|
10479
|
-
debug$
|
|
10450
|
+
debug$4("entry: setup->setting up");
|
|
10480
10451
|
}],
|
|
10481
10452
|
exit: [() => {
|
|
10482
|
-
debug$
|
|
10453
|
+
debug$4("exit: setup->setting up");
|
|
10483
10454
|
}, "emit ready", "emit pending incoming patches", "clear pending incoming patches"],
|
|
10484
10455
|
on: {
|
|
10485
10456
|
"internal.patch": {
|
|
@@ -10504,10 +10475,10 @@ const editorMachine = setup({
|
|
|
10504
10475
|
states: {
|
|
10505
10476
|
idle: {
|
|
10506
10477
|
entry: [() => {
|
|
10507
|
-
debug$
|
|
10478
|
+
debug$4("entry: setup->set up->value sync->idle");
|
|
10508
10479
|
}],
|
|
10509
10480
|
exit: [() => {
|
|
10510
|
-
debug$
|
|
10481
|
+
debug$4("exit: setup->set up->value sync->idle");
|
|
10511
10482
|
}],
|
|
10512
10483
|
on: {
|
|
10513
10484
|
patches: {
|
|
@@ -10522,10 +10493,10 @@ const editorMachine = setup({
|
|
|
10522
10493
|
},
|
|
10523
10494
|
"syncing value": {
|
|
10524
10495
|
entry: [() => {
|
|
10525
|
-
debug$
|
|
10496
|
+
debug$4("entry: setup->set up->value sync->syncing value");
|
|
10526
10497
|
}],
|
|
10527
10498
|
exit: [() => {
|
|
10528
|
-
debug$
|
|
10499
|
+
debug$4("exit: setup->set up->value sync->syncing value");
|
|
10529
10500
|
}, "emit pending incoming patches", "clear pending incoming patches"],
|
|
10530
10501
|
on: {
|
|
10531
10502
|
patches: {
|
|
@@ -10546,10 +10517,10 @@ const editorMachine = setup({
|
|
|
10546
10517
|
states: {
|
|
10547
10518
|
idle: {
|
|
10548
10519
|
entry: [() => {
|
|
10549
|
-
debug$
|
|
10520
|
+
debug$4("entry: setup->set up->writing->pristine->idle");
|
|
10550
10521
|
}],
|
|
10551
10522
|
exit: [() => {
|
|
10552
|
-
debug$
|
|
10523
|
+
debug$4("exit: setup->set up->writing->pristine->idle");
|
|
10553
10524
|
}],
|
|
10554
10525
|
on: {
|
|
10555
10526
|
"internal.patch": [{
|
|
@@ -10572,10 +10543,10 @@ const editorMachine = setup({
|
|
|
10572
10543
|
},
|
|
10573
10544
|
dirty: {
|
|
10574
10545
|
entry: [() => {
|
|
10575
|
-
debug$
|
|
10546
|
+
debug$4("entry: setup->set up->writing->dirty");
|
|
10576
10547
|
}, "emit pending events", "clear pending events"],
|
|
10577
10548
|
exit: [() => {
|
|
10578
|
-
debug$
|
|
10549
|
+
debug$4("exit: setup->set up->writing->dirty");
|
|
10579
10550
|
}],
|
|
10580
10551
|
on: {
|
|
10581
10552
|
"internal.patch": {
|
|
@@ -10593,7 +10564,7 @@ const editorMachine = setup({
|
|
|
10593
10564
|
}
|
|
10594
10565
|
}
|
|
10595
10566
|
}
|
|
10596
|
-
}), debug$
|
|
10567
|
+
}), debug$3 = debugWithName("mutation-machine"), mutationMachine = setup({
|
|
10597
10568
|
types: {
|
|
10598
10569
|
context: {},
|
|
10599
10570
|
events: {},
|
|
@@ -10741,10 +10712,10 @@ const editorMachine = setup({
|
|
|
10741
10712
|
states: {
|
|
10742
10713
|
idle: {
|
|
10743
10714
|
entry: [() => {
|
|
10744
|
-
debug$
|
|
10715
|
+
debug$3("entry: typing->idle");
|
|
10745
10716
|
}],
|
|
10746
10717
|
exit: [() => {
|
|
10747
|
-
debug$
|
|
10718
|
+
debug$3("exit: typing->idle"), debug$3("entry: typing->typing");
|
|
10748
10719
|
}],
|
|
10749
10720
|
on: {
|
|
10750
10721
|
typing: {
|
|
@@ -10759,7 +10730,7 @@ const editorMachine = setup({
|
|
|
10759
10730
|
actions: [raise$1({
|
|
10760
10731
|
type: "emit changes"
|
|
10761
10732
|
}), () => {
|
|
10762
|
-
debug$
|
|
10733
|
+
debug$3("exit: typing->typing");
|
|
10763
10734
|
}]
|
|
10764
10735
|
}
|
|
10765
10736
|
},
|
|
@@ -10783,10 +10754,10 @@ const editorMachine = setup({
|
|
|
10783
10754
|
states: {
|
|
10784
10755
|
idle: {
|
|
10785
10756
|
entry: [() => {
|
|
10786
|
-
debug$
|
|
10757
|
+
debug$3("entry: mutations->idle");
|
|
10787
10758
|
}],
|
|
10788
10759
|
exit: [() => {
|
|
10789
|
-
debug$
|
|
10760
|
+
debug$3("exit: mutations->idle");
|
|
10790
10761
|
}],
|
|
10791
10762
|
on: {
|
|
10792
10763
|
patch: [{
|
|
@@ -10801,10 +10772,10 @@ const editorMachine = setup({
|
|
|
10801
10772
|
},
|
|
10802
10773
|
"has pending mutations": {
|
|
10803
10774
|
entry: [() => {
|
|
10804
|
-
debug$
|
|
10775
|
+
debug$3("entry: mutations->has pending mutations");
|
|
10805
10776
|
}, "emit has pending mutations"],
|
|
10806
10777
|
exit: [() => {
|
|
10807
|
-
debug$
|
|
10778
|
+
debug$3("exit: mutations->has pending mutations");
|
|
10808
10779
|
}],
|
|
10809
10780
|
invoke: {
|
|
10810
10781
|
src: "mutation interval"
|
|
@@ -10826,7 +10797,7 @@ const editorMachine = setup({
|
|
|
10826
10797
|
}
|
|
10827
10798
|
}
|
|
10828
10799
|
}
|
|
10829
|
-
})
|
|
10800
|
+
});
|
|
10830
10801
|
function createEditableAPI(editor, editorActor) {
|
|
10831
10802
|
const types = editorActor.getSnapshot().context.schema;
|
|
10832
10803
|
return {
|
|
@@ -11086,48 +11057,15 @@ function createEditableAPI(editor, editorActor) {
|
|
|
11086
11057
|
};
|
|
11087
11058
|
},
|
|
11088
11059
|
delete: (selection, options) => {
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
11099
|
-
throw new Error("Invalid range");
|
|
11100
|
-
if (range) {
|
|
11101
|
-
if (!options?.mode || options?.mode === "selected") {
|
|
11102
|
-
debug$3("Deleting content in selection"), Transforms.delete(editor, {
|
|
11103
|
-
at: range,
|
|
11104
|
-
hanging: !0,
|
|
11105
|
-
voids: !0
|
|
11106
|
-
}), editor.onChange();
|
|
11107
|
-
return;
|
|
11108
|
-
}
|
|
11109
|
-
if (options?.mode === "blocks" && (debug$3("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
|
|
11110
|
-
at: range,
|
|
11111
|
-
voids: !0,
|
|
11112
|
-
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
|
|
11113
|
-
})), options?.mode === "children" && (debug$3("Deleting children touched by selection"), Transforms.removeNodes(editor, {
|
|
11114
|
-
at: range,
|
|
11115
|
-
voids: !0,
|
|
11116
|
-
match: (node) => node._type === types.span.name || // Text children
|
|
11117
|
-
!editor.isTextBlock(node) && Element$1.isElement(node)
|
|
11118
|
-
})), editor.children.length === 0) {
|
|
11119
|
-
const placeholderBlock = createPlaceholderBlock(editorActor.getSnapshot().context);
|
|
11120
|
-
editor.children = [placeholderBlock], editor.value = [placeholderBlock], buildIndexMaps({
|
|
11121
|
-
schema: editorActor.getSnapshot().context.schema,
|
|
11122
|
-
value: editor.value
|
|
11123
|
-
}, {
|
|
11124
|
-
blockIndexMap: editor.blockIndexMap,
|
|
11125
|
-
listIndexMap: editor.listIndexMap
|
|
11126
|
-
});
|
|
11127
|
-
}
|
|
11128
|
-
editor.onChange();
|
|
11129
|
-
}
|
|
11130
|
-
}
|
|
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
|
+
});
|
|
11131
11069
|
},
|
|
11132
11070
|
removeAnnotation: (type) => {
|
|
11133
11071
|
editorActor.send({
|
|
@@ -11828,6 +11766,7 @@ async function updateValue({
|
|
|
11828
11766
|
let doneSyncing = !1, isChanged = !1, isValid = !0;
|
|
11829
11767
|
const hadSelection = !!slateEditor.selection;
|
|
11830
11768
|
if ((!value || value.length === 0) && (debug$2("Value is empty"), clearEditor({
|
|
11769
|
+
context,
|
|
11831
11770
|
slateEditor,
|
|
11832
11771
|
doneSyncing,
|
|
11833
11772
|
hadSelection
|
|
@@ -11937,6 +11876,7 @@ async function* getStreamedBlocks({
|
|
|
11937
11876
|
index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
11938
11877
|
}
|
|
11939
11878
|
function clearEditor({
|
|
11879
|
+
context,
|
|
11940
11880
|
slateEditor,
|
|
11941
11881
|
doneSyncing,
|
|
11942
11882
|
hadSelection
|
|
@@ -11953,9 +11893,7 @@ function clearEditor({
|
|
|
11953
11893
|
Transforms.removeNodes(slateEditor, {
|
|
11954
11894
|
at: [childrenLength - 1 - index]
|
|
11955
11895
|
});
|
|
11956
|
-
}), Transforms.insertNodes(slateEditor,
|
|
11957
|
-
decorators: []
|
|
11958
|
-
}), {
|
|
11896
|
+
}), Transforms.insertNodes(slateEditor, createPlaceholderBlock(context), {
|
|
11959
11897
|
at: [0]
|
|
11960
11898
|
}), hadSelection && Transforms.select(slateEditor, [0, 0]);
|
|
11961
11899
|
});
|
|
@@ -12540,6 +12478,20 @@ class PortableTextEditor extends Component {
|
|
|
12540
12478
|
static blur = (editor) => {
|
|
12541
12479
|
debug("Host blurred"), editor.editable?.blur();
|
|
12542
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
|
+
*/
|
|
12543
12495
|
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
12544
12496
|
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
12545
12497
|
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|