@portabletext/editor 1.36.6 → 1.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +84 -49
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +919 -526
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/{util.block-offsets-to-selection.cjs → parse-blocks.cjs} +36 -21
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-overlapping-selection.cjs} +144 -3
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs +12 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +84 -49
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +1 -1
- package/lib/_chunks-es/editor-provider.js +911 -517
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/{util.block-offsets-to-selection.js → parse-blocks.js} +37 -22
- package/lib/_chunks-es/parse-blocks.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +1 -2
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/{selector.is-active-style.js → selector.is-overlapping-selection.js} +146 -5
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +12 -0
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +10535 -4689
- package/lib/behaviors/index.d.ts +10535 -4689
- package/lib/index.cjs +582 -209
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +5297 -1178
- package/lib/index.d.ts +5297 -1178
- package/lib/index.js +591 -213
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +2 -2
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +5297 -1178
- package/lib/plugins/index.d.ts +5297 -1178
- package/lib/plugins/index.js +2 -2
- package/lib/selectors/index.cjs +21 -103
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +5313 -1178
- package/lib/selectors/index.d.ts +5313 -1178
- package/lib/selectors/index.js +13 -96
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +4 -4
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +5297 -1178
- package/lib/utils/index.d.ts +5297 -1178
- package/lib/utils/index.js +3 -4
- package/lib/utils/index.js.map +1 -1
- package/package.json +15 -14
- package/src/behavior-actions/behavior.action.blur.ts +8 -0
- package/src/behavior-actions/behavior.action.decorator.add.ts +2 -1
- package/src/behavior-actions/behavior.action.delete.backward.ts +7 -0
- package/src/behavior-actions/behavior.action.delete.block.ts +24 -0
- package/src/behavior-actions/behavior.action.delete.forward.ts +7 -0
- package/src/behavior-actions/behavior.action.delete.text.ts +2 -1
- package/src/behavior-actions/behavior.action.delete.ts +1 -3
- package/src/behavior-actions/behavior.action.deserialization.failure.ts +9 -0
- package/src/behavior-actions/behavior.action.deserialization.success.ts +16 -0
- package/src/behavior-actions/behavior.action.effect.ts +7 -0
- package/src/behavior-actions/behavior.action.focus.ts +8 -0
- package/src/behavior-actions/behavior.action.insert-blocks.ts +118 -74
- package/src/behavior-actions/behavior.action.insert-break.ts +1 -0
- package/src/behavior-actions/{behavior.action.insert-block-object.ts → behavior.action.insert.block-object.ts} +9 -14
- package/src/behavior-actions/behavior.action.insert.block.ts +247 -2
- package/src/behavior-actions/behavior.action.insert.text-block.ts +33 -0
- package/src/behavior-actions/behavior.action.insert.text.ts +7 -0
- package/src/behavior-actions/behavior.action.move.block-down.ts +48 -0
- package/src/behavior-actions/behavior.action.move.block-up.ts +53 -0
- package/src/behavior-actions/behavior.action.move.block.ts +16 -0
- package/src/behavior-actions/behavior.action.noop.ts +5 -0
- package/src/behavior-actions/behavior.action.select.next-block.ts +44 -0
- package/src/behavior-actions/behavior.action.select.previous-block.ts +48 -0
- package/src/behavior-actions/behavior.action.select.ts +15 -0
- package/src/behavior-actions/behavior.action.serialization.failure.ts +9 -0
- package/src/behavior-actions/behavior.action.serialization.success.ts +14 -0
- package/src/behavior-actions/behavior.actions.ts +54 -212
- package/src/behaviors/behavior.core.block-objects.ts +35 -6
- package/src/behaviors/behavior.core.insert-break.ts +1 -0
- package/src/behaviors/behavior.core.ts +2 -0
- package/src/behaviors/behavior.default.ts +241 -33
- package/src/behaviors/behavior.types.ts +138 -20
- package/src/converters/converter.portable-text.ts +5 -2
- package/src/converters/converter.text-html.serialize.test.ts +4 -4
- package/src/converters/converter.text-html.ts +5 -2
- package/src/converters/converter.text-plain.test.ts +6 -6
- package/src/converters/converter.text-plain.ts +5 -2
- package/src/converters/converter.types.ts +3 -3
- package/src/editor/Editable.tsx +403 -48
- package/src/editor/components/Element.tsx +133 -18
- package/src/editor/components/use-draggable.ts +34 -102
- package/src/editor/editor-machine.ts +66 -10
- package/src/editor/editor-selector.ts +2 -0
- package/src/editor/editor-snapshot.ts +17 -0
- package/src/editor/plugins/create-with-event-listeners.ts +6 -40
- package/src/internal-utils/create-test-snapshot.ts +2 -0
- package/src/internal-utils/event-position.ts +210 -0
- package/src/internal-utils/slate-utils.ts +56 -0
- package/src/internal-utils/weakMaps.ts +1 -15
- package/src/selectors/index.ts +2 -0
- package/src/selectors/selector.get-focus-inline-object.ts +21 -0
- package/src/selectors/selector.is-overlapping-selection.test.ts +171 -0
- package/src/selectors/selector.is-overlapping-selection.ts +108 -4
- package/src/selectors/selector.is-point-after-selection.ts +3 -1
- package/src/selectors/selector.is-point-before-selection.ts +3 -1
- package/src/selectors/selector.is-selecting-entire-blocks.ts +34 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +0 -1
- package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -14
- package/lib/_chunks-cjs/util.reverse-selection.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +0 -1
- package/lib/_chunks-es/util.reverse-selection.js +0 -15
- package/lib/_chunks-es/util.reverse-selection.js.map +0 -1
- package/src/behavior-actions/behavior.action-utils.insert-block.ts +0 -61
- package/src/editor/__tests__/handleClick.test.tsx +0 -277
- package/src/editor/components/use-droppable.ts +0 -135
|
@@ -5,7 +5,7 @@ import { ReactEditor, withReact, Slate } from "slate-react";
|
|
|
5
5
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
6
6
|
import debug$e from "debug";
|
|
7
7
|
import isEqual from "lodash/isEqual.js";
|
|
8
|
-
import { Editor, Element, Range, Point, Text, Operation, Transforms, Path, Node, insertText,
|
|
8
|
+
import { Editor, Element, Range, Point, Text, Operation, Transforms, Path, Node, insertText, createEditor as createEditor$1 } from "slate";
|
|
9
9
|
import { setup, emit, enqueueActions, assign, assertEvent, fromCallback, stateIn, and, not, createActor } from "xstate";
|
|
10
10
|
import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
|
|
11
11
|
import { defineType, defineField, isKeySegment, isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock } from "@sanity/types";
|
|
@@ -13,19 +13,20 @@ import flatten from "lodash/flatten.js";
|
|
|
13
13
|
import isPlainObject from "lodash/isPlainObject.js";
|
|
14
14
|
import uniq from "lodash/uniq.js";
|
|
15
15
|
import getRandomValues from "get-random-values-esm";
|
|
16
|
-
import { parseBlock, blockOffsetsToSelection, isTextBlock } from "./
|
|
17
|
-
import { sliceBlocks, blockOffsetToSpanSelectionPoint, spanSelectionPointToBlockOffset } from "./util.slice-blocks.js";
|
|
16
|
+
import { parseBlock, blockOffsetsToSelection, isTextBlock, parseBlocks } from "./parse-blocks.js";
|
|
17
|
+
import { sliceBlocks, blockOffsetToSpanSelectionPoint, spanSelectionPointToBlockOffset, isKeyedSegment as isKeyedSegment$1 } from "./util.slice-blocks.js";
|
|
18
18
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
19
19
|
import { toHTML } from "@portabletext/to-html";
|
|
20
20
|
import { Schema } from "@sanity/schema";
|
|
21
21
|
import get from "lodash/get.js";
|
|
22
22
|
import isUndefined from "lodash/isUndefined.js";
|
|
23
23
|
import omitBy from "lodash/omitBy.js";
|
|
24
|
-
import { createGuards } from "./selector.is-at-the-start-of-block.js";
|
|
25
|
-
import { getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle } from "./selector.is-
|
|
24
|
+
import { createGuards, getFocusSpan, isSelectionCollapsed, getSelectedBlocks, isSelectionExpanded } from "./selector.is-at-the-start-of-block.js";
|
|
25
|
+
import { getTrimmedSelection, isOverlappingSelection, isSelectingEntireBlocks, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle } from "./selector.is-overlapping-selection.js";
|
|
26
26
|
import omit from "lodash/omit.js";
|
|
27
|
+
import { DOMEditor } from "slate-dom";
|
|
27
28
|
import startCase from "lodash.startcase";
|
|
28
|
-
import { defineBehavior, raise, coreBehaviors, isCustomBehaviorEvent } from "./behavior.core.js";
|
|
29
|
+
import { defineBehavior, raise, isDragBehaviorEvent, isMouseBehaviorEvent, coreBehaviors, isCustomBehaviorEvent } from "./behavior.core.js";
|
|
29
30
|
import { Subject } from "rxjs";
|
|
30
31
|
import { useEffectEvent } from "use-effect-event";
|
|
31
32
|
function createEditorSchema(portableTextType) {
|
|
@@ -331,7 +332,65 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
331
332
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
332
333
|
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
|
|
333
334
|
}
|
|
334
|
-
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(),
|
|
335
|
+
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), EditorActorContext = createContext({});
|
|
336
|
+
function getActiveDecorators({
|
|
337
|
+
schema,
|
|
338
|
+
slateEditorInstance
|
|
339
|
+
}) {
|
|
340
|
+
const decorators = schema.decorators.map((decorator) => decorator.value);
|
|
341
|
+
return ({
|
|
342
|
+
...Editor.marks(slateEditorInstance) ?? {}
|
|
343
|
+
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
344
|
+
}
|
|
345
|
+
function getValue({
|
|
346
|
+
editorActorSnapshot,
|
|
347
|
+
slateEditorInstance
|
|
348
|
+
}) {
|
|
349
|
+
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
350
|
+
}
|
|
351
|
+
function defaultCompare(a, b) {
|
|
352
|
+
return a === b;
|
|
353
|
+
}
|
|
354
|
+
function useEditorSelector(editor, selector, t0) {
|
|
355
|
+
const $ = c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
356
|
+
let t1;
|
|
357
|
+
return $[0] !== editor._internal.slateEditor.instance || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
358
|
+
const snapshot = getEditorSnapshot({
|
|
359
|
+
editorActorSnapshot,
|
|
360
|
+
slateEditorInstance: editor._internal.slateEditor.instance
|
|
361
|
+
});
|
|
362
|
+
return selector(snapshot);
|
|
363
|
+
}, $[0] = editor._internal.slateEditor.instance, $[1] = selector, $[2] = t1) : t1 = $[2], useSelector(editor._internal.editorActor, t1, compare);
|
|
364
|
+
}
|
|
365
|
+
function getEditorSnapshot({
|
|
366
|
+
editorActorSnapshot,
|
|
367
|
+
slateEditorInstance
|
|
368
|
+
}) {
|
|
369
|
+
return {
|
|
370
|
+
context: {
|
|
371
|
+
converters: [...editorActorSnapshot.context.converters],
|
|
372
|
+
activeDecorators: getActiveDecorators({
|
|
373
|
+
schema: editorActorSnapshot.context.schema,
|
|
374
|
+
slateEditorInstance
|
|
375
|
+
}),
|
|
376
|
+
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
377
|
+
readOnly: editorActorSnapshot.matches({
|
|
378
|
+
"edit mode": "read only"
|
|
379
|
+
}),
|
|
380
|
+
schema: editorActorSnapshot.context.schema,
|
|
381
|
+
selection: editorActorSnapshot.context.selection,
|
|
382
|
+
value: getValue({
|
|
383
|
+
editorActorSnapshot,
|
|
384
|
+
slateEditorInstance
|
|
385
|
+
})
|
|
386
|
+
},
|
|
387
|
+
beta: {
|
|
388
|
+
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
389
|
+
internalDrag: editorActorSnapshot.context.internalDrag
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
const PortableTextEditorContext = createContext(null), usePortableTextEditor = () => {
|
|
335
394
|
const editor = useContext(PortableTextEditorContext);
|
|
336
395
|
if (!editor)
|
|
337
396
|
throw new Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");
|
|
@@ -2425,7 +2484,8 @@ const converterJson = {
|
|
|
2425
2484
|
snapshot,
|
|
2426
2485
|
event
|
|
2427
2486
|
}) => {
|
|
2428
|
-
|
|
2487
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2488
|
+
if (!selection)
|
|
2429
2489
|
return {
|
|
2430
2490
|
type: "serialization.failure",
|
|
2431
2491
|
mimeType: "application/x-portable-text",
|
|
@@ -2434,7 +2494,7 @@ const converterJson = {
|
|
|
2434
2494
|
};
|
|
2435
2495
|
const blocks = sliceBlocks({
|
|
2436
2496
|
blocks: snapshot.context.value,
|
|
2437
|
-
selection
|
|
2497
|
+
selection
|
|
2438
2498
|
});
|
|
2439
2499
|
return {
|
|
2440
2500
|
type: "serialization.success",
|
|
@@ -2484,7 +2544,8 @@ const converterJson = {
|
|
|
2484
2544
|
snapshot,
|
|
2485
2545
|
event
|
|
2486
2546
|
}) => {
|
|
2487
|
-
|
|
2547
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2548
|
+
if (!selection)
|
|
2488
2549
|
return {
|
|
2489
2550
|
type: "serialization.failure",
|
|
2490
2551
|
mimeType: "text/html",
|
|
@@ -2493,7 +2554,7 @@ const converterJson = {
|
|
|
2493
2554
|
};
|
|
2494
2555
|
const blocks = sliceBlocks({
|
|
2495
2556
|
blocks: snapshot.context.value,
|
|
2496
|
-
selection
|
|
2557
|
+
selection
|
|
2497
2558
|
}), html = toHTML(blocks, {
|
|
2498
2559
|
onMissingComponent: !1,
|
|
2499
2560
|
components: {
|
|
@@ -2537,21 +2598,24 @@ const converterJson = {
|
|
|
2537
2598
|
serialize: ({
|
|
2538
2599
|
snapshot,
|
|
2539
2600
|
event
|
|
2540
|
-
}) =>
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2601
|
+
}) => {
|
|
2602
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2603
|
+
return selection ? {
|
|
2604
|
+
type: "serialization.success",
|
|
2605
|
+
data: sliceBlocks({
|
|
2606
|
+
blocks: snapshot.context.value,
|
|
2607
|
+
selection
|
|
2608
|
+
}).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]`).join("") : `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]`).join(`
|
|
2546
2609
|
|
|
2547
2610
|
`),
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2611
|
+
mimeType: "text/plain",
|
|
2612
|
+
originEvent: event.originEvent
|
|
2613
|
+
} : {
|
|
2614
|
+
type: "serialization.failure",
|
|
2615
|
+
mimeType: "text/plain",
|
|
2616
|
+
originEvent: event.originEvent,
|
|
2617
|
+
reason: "No selection"
|
|
2618
|
+
};
|
|
2555
2619
|
},
|
|
2556
2620
|
deserialize: ({
|
|
2557
2621
|
snapshot,
|
|
@@ -2815,7 +2879,8 @@ const insertBreakActionImplementation = ({
|
|
|
2815
2879
|
const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
|
|
2816
2880
|
if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
2817
2881
|
Transforms.splitNodes(editor, {
|
|
2818
|
-
at: editor.selection
|
|
2882
|
+
at: editor.selection,
|
|
2883
|
+
always: !0
|
|
2819
2884
|
});
|
|
2820
2885
|
const [nextBlock, nextBlockPath] = Editor.node(editor, Path.next(focusBlockPath), {
|
|
2821
2886
|
depth: 1
|
|
@@ -3059,12 +3124,14 @@ const decoratorAddActionImplementation = ({
|
|
|
3059
3124
|
backward: editorSelection?.backward
|
|
3060
3125
|
}), trimmedSelection = getTrimmedSelection({
|
|
3061
3126
|
beta: {
|
|
3062
|
-
hasTag: () => !1
|
|
3127
|
+
hasTag: () => !1,
|
|
3128
|
+
internalDrag: void 0
|
|
3063
3129
|
},
|
|
3064
3130
|
context: {
|
|
3065
3131
|
activeDecorators: [],
|
|
3066
3132
|
converters: [],
|
|
3067
3133
|
keyGenerator: context.keyGenerator,
|
|
3134
|
+
readOnly: !1,
|
|
3068
3135
|
schema: context.schema,
|
|
3069
3136
|
selection: newSelection,
|
|
3070
3137
|
value: newValue
|
|
@@ -4097,49 +4164,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4097
4164
|
editor: action.editor
|
|
4098
4165
|
}
|
|
4099
4166
|
});
|
|
4100
|
-
}
|
|
4101
|
-
function insertBlock({
|
|
4102
|
-
block,
|
|
4103
|
-
placement,
|
|
4104
|
-
editor,
|
|
4105
|
-
schema
|
|
4106
|
-
}) {
|
|
4107
|
-
if (editor.selection) {
|
|
4108
|
-
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(editor, {
|
|
4109
|
-
at: editor.selection.focus.path.slice(0, 1),
|
|
4110
|
-
match: (n) => !Editor.isEditor(n)
|
|
4111
|
-
}))[0] ?? [void 0, void 0];
|
|
4112
|
-
if (placement === "after") {
|
|
4113
|
-
const nextPath = [focusBlockPath[0] + 1];
|
|
4114
|
-
Transforms.insertNodes(editor, block, {
|
|
4115
|
-
at: nextPath
|
|
4116
|
-
}), Transforms.select(editor, {
|
|
4117
|
-
anchor: {
|
|
4118
|
-
path: [nextPath[0], 0],
|
|
4119
|
-
offset: 0
|
|
4120
|
-
},
|
|
4121
|
-
focus: {
|
|
4122
|
-
path: [nextPath[0], 0],
|
|
4123
|
-
offset: 0
|
|
4124
|
-
}
|
|
4125
|
-
});
|
|
4126
|
-
} else placement === "before" ? Transforms.insertNodes(editor, block, {
|
|
4127
|
-
at: focusBlockPath
|
|
4128
|
-
}) : (Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock], schema) && Transforms.removeNodes(editor, {
|
|
4129
|
-
at: focusBlockPath
|
|
4130
|
-
}));
|
|
4131
|
-
} else {
|
|
4132
|
-
const lastBlock = Array.from(Editor.nodes(editor, {
|
|
4133
|
-
match: (n) => !Editor.isEditor(n),
|
|
4134
|
-
at: [],
|
|
4135
|
-
reverse: !0
|
|
4136
|
-
}))[0];
|
|
4137
|
-
Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], schema) && Transforms.removeNodes(editor, {
|
|
4138
|
-
at: lastBlock[1]
|
|
4139
|
-
});
|
|
4140
|
-
}
|
|
4141
|
-
}
|
|
4142
|
-
const blockSetBehaviorActionImplementation = ({
|
|
4167
|
+
}, blockSetBehaviorActionImplementation = ({
|
|
4143
4168
|
context,
|
|
4144
4169
|
action
|
|
4145
4170
|
}) => {
|
|
@@ -4249,6 +4274,10 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4249
4274
|
}, {
|
|
4250
4275
|
at: location
|
|
4251
4276
|
});
|
|
4277
|
+
}, blurActionImplementation = ({
|
|
4278
|
+
action
|
|
4279
|
+
}) => {
|
|
4280
|
+
ReactEditor.blur(action.editor);
|
|
4252
4281
|
}, dataTransferSetActionImplementation = ({
|
|
4253
4282
|
action
|
|
4254
4283
|
}) => {
|
|
@@ -4259,7 +4288,37 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4259
4288
|
const range = toSlateRange(action.selection, action.editor);
|
|
4260
4289
|
if (!range)
|
|
4261
4290
|
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.selection)}`);
|
|
4262
|
-
|
|
4291
|
+
action.editor.delete({
|
|
4292
|
+
at: range
|
|
4293
|
+
});
|
|
4294
|
+
}, deleteBackwardActionImplementation = ({
|
|
4295
|
+
action
|
|
4296
|
+
}) => {
|
|
4297
|
+
action.editor.deleteBackward(action.unit);
|
|
4298
|
+
}, deleteBlockActionImplementation = ({
|
|
4299
|
+
action
|
|
4300
|
+
}) => {
|
|
4301
|
+
const range = toSlateRange({
|
|
4302
|
+
anchor: {
|
|
4303
|
+
path: action.blockPath,
|
|
4304
|
+
offset: 0
|
|
4305
|
+
},
|
|
4306
|
+
focus: {
|
|
4307
|
+
path: action.blockPath,
|
|
4308
|
+
offset: 0
|
|
4309
|
+
}
|
|
4310
|
+
}, action.editor);
|
|
4311
|
+
if (!range) {
|
|
4312
|
+
console.error("Unable to find Slate range from selection points");
|
|
4313
|
+
return;
|
|
4314
|
+
}
|
|
4315
|
+
Transforms.removeNodes(action.editor, {
|
|
4316
|
+
at: range
|
|
4317
|
+
});
|
|
4318
|
+
}, deleteForwardActionImplementation = ({
|
|
4319
|
+
action
|
|
4320
|
+
}) => {
|
|
4321
|
+
action.editor.deleteForward(action.unit);
|
|
4263
4322
|
}, deleteTextActionImplementation = ({
|
|
4264
4323
|
context,
|
|
4265
4324
|
action
|
|
@@ -4275,13 +4334,15 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4275
4334
|
throw new Error("Unable to find selection from block offsets");
|
|
4276
4335
|
const trimmedSelection = getTrimmedSelection({
|
|
4277
4336
|
beta: {
|
|
4278
|
-
hasTag: () => !1
|
|
4337
|
+
hasTag: () => !1,
|
|
4338
|
+
internalDrag: void 0
|
|
4279
4339
|
},
|
|
4280
4340
|
context: {
|
|
4281
4341
|
converters: [],
|
|
4282
4342
|
schema: context.schema,
|
|
4283
4343
|
keyGenerator: context.keyGenerator,
|
|
4284
4344
|
activeDecorators: [],
|
|
4345
|
+
readOnly: !1,
|
|
4285
4346
|
value,
|
|
4286
4347
|
selection
|
|
4287
4348
|
}
|
|
@@ -4294,176 +4355,563 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4294
4355
|
Transforms.delete(action.editor, {
|
|
4295
4356
|
at: range
|
|
4296
4357
|
});
|
|
4297
|
-
},
|
|
4358
|
+
}, deserializationFailureActionImplementation = ({
|
|
4359
|
+
action
|
|
4360
|
+
}) => {
|
|
4361
|
+
console.warn(`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`);
|
|
4362
|
+
};
|
|
4363
|
+
function getFocusBlock({
|
|
4364
|
+
editor
|
|
4365
|
+
}) {
|
|
4366
|
+
return editor.selection ? Array.from(Editor.nodes(editor, {
|
|
4367
|
+
at: editor.selection.focus.path.slice(0, 1),
|
|
4368
|
+
match: (n) => !Editor.isEditor(n)
|
|
4369
|
+
})).at(0) ?? [void 0, void 0] : [void 0, void 0];
|
|
4370
|
+
}
|
|
4371
|
+
function getFocusChild({
|
|
4372
|
+
editor
|
|
4373
|
+
}) {
|
|
4374
|
+
const [focusBlock, focusBlockPath] = getFocusBlock({
|
|
4375
|
+
editor
|
|
4376
|
+
}), childIndex = editor.selection?.focus.path.at(1);
|
|
4377
|
+
if (!focusBlock || !focusBlockPath || childIndex === void 0)
|
|
4378
|
+
return [void 0, void 0];
|
|
4379
|
+
const focusChild = Node.child(focusBlock, childIndex);
|
|
4380
|
+
return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
|
|
4381
|
+
}
|
|
4382
|
+
function getLastBlock({
|
|
4383
|
+
editor
|
|
4384
|
+
}) {
|
|
4385
|
+
return Array.from(Editor.nodes(editor, {
|
|
4386
|
+
match: (n) => !Editor.isEditor(n),
|
|
4387
|
+
at: [],
|
|
4388
|
+
reverse: !0
|
|
4389
|
+
})).at(0) ?? [void 0, void 0];
|
|
4390
|
+
}
|
|
4391
|
+
const insertBlockActionImplementation = ({
|
|
4298
4392
|
context,
|
|
4299
4393
|
action
|
|
4300
4394
|
}) => {
|
|
4301
|
-
const
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4395
|
+
const parsedBlock = parseBlock({
|
|
4396
|
+
block: action.block,
|
|
4397
|
+
context,
|
|
4398
|
+
options: {
|
|
4399
|
+
refreshKeys: !1
|
|
4400
|
+
}
|
|
4401
|
+
});
|
|
4402
|
+
if (!parsedBlock)
|
|
4403
|
+
throw new Error(`Failed to parse block ${JSON.stringify(action.block)}`);
|
|
4404
|
+
const fragment = toSlateValue([parsedBlock], {
|
|
4306
4405
|
schemaTypes: context.schema
|
|
4307
4406
|
})[0];
|
|
4407
|
+
if (!fragment)
|
|
4408
|
+
throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
|
|
4308
4409
|
insertBlock({
|
|
4309
|
-
block,
|
|
4410
|
+
block: fragment,
|
|
4310
4411
|
placement: action.placement,
|
|
4412
|
+
select: action.select ?? "start",
|
|
4311
4413
|
editor: action.editor,
|
|
4312
4414
|
schema: context.schema
|
|
4313
4415
|
});
|
|
4314
|
-
}
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
at: Editor.start(action.editor, [])
|
|
4325
|
-
});
|
|
4326
|
-
return;
|
|
4327
|
-
}
|
|
4328
|
-
if (action.placement === "after") {
|
|
4329
|
-
action.editor.insertFragment(fragment, {
|
|
4330
|
-
at: Editor.end(action.editor, [])
|
|
4331
|
-
});
|
|
4332
|
-
return;
|
|
4333
|
-
}
|
|
4334
|
-
action.editor.insertFragment(fragment);
|
|
4335
|
-
return;
|
|
4336
|
-
}
|
|
4337
|
-
const [focusBlock, focusPath] = Editor.node(action.editor, action.editor.selection, {
|
|
4338
|
-
depth: 1
|
|
4416
|
+
};
|
|
4417
|
+
function insertBlock({
|
|
4418
|
+
block,
|
|
4419
|
+
placement,
|
|
4420
|
+
select,
|
|
4421
|
+
editor,
|
|
4422
|
+
schema
|
|
4423
|
+
}) {
|
|
4424
|
+
const [focusBlock, focusBlockPath] = getFocusBlock({
|
|
4425
|
+
editor
|
|
4339
4426
|
});
|
|
4340
|
-
if (
|
|
4341
|
-
|
|
4342
|
-
|
|
4427
|
+
if (!editor.selection || !focusBlock || !focusBlockPath) {
|
|
4428
|
+
select !== "none" && DOMEditor.focus(editor);
|
|
4429
|
+
const [lastBlock, lastBlockPath] = getLastBlock({
|
|
4430
|
+
editor
|
|
4343
4431
|
});
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4432
|
+
if (placement === "before")
|
|
4433
|
+
Transforms.insertNodes(editor, [block], {
|
|
4434
|
+
at: [0]
|
|
4435
|
+
}), select === "start" ? Transforms.select(editor, Editor.start(editor, [0])) : select === "end" && Transforms.select(editor, Editor.end(editor, [0]));
|
|
4436
|
+
else if (placement === "after") {
|
|
4437
|
+
const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
|
|
4438
|
+
Transforms.insertNodes(editor, [block], {
|
|
4439
|
+
at: nextPath,
|
|
4440
|
+
select: !1
|
|
4441
|
+
}), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
4442
|
+
} else {
|
|
4443
|
+
if (lastBlock && isEqualToEmptyEditor([lastBlock], schema)) {
|
|
4444
|
+
Transforms.removeNodes(editor, {
|
|
4445
|
+
at: lastBlockPath
|
|
4446
|
+
}), Transforms.insertNodes(editor, [block], {
|
|
4447
|
+
at: lastBlockPath,
|
|
4448
|
+
select: !1
|
|
4449
|
+
}), Transforms.deselect(editor), select === "start" ? Transforms.select(editor, Editor.start(editor, lastBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, lastBlockPath));
|
|
4450
|
+
return;
|
|
4358
4451
|
}
|
|
4452
|
+
if (editor.isTextBlock(block) && lastBlock && editor.isTextBlock(lastBlock)) {
|
|
4453
|
+
const selectionBefore = Editor.end(editor, lastBlockPath);
|
|
4454
|
+
Transforms.insertFragment(editor, [block], {
|
|
4455
|
+
at: Editor.end(editor, lastBlockPath)
|
|
4456
|
+
}), select === "start" ? Transforms.select(editor, selectionBefore) : select === "none" && Transforms.deselect(editor);
|
|
4457
|
+
return;
|
|
4458
|
+
}
|
|
4459
|
+
const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
|
|
4460
|
+
Transforms.insertNodes(editor, [block], {
|
|
4461
|
+
at: nextPath,
|
|
4462
|
+
select: !1
|
|
4463
|
+
}), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
4464
|
+
}
|
|
4465
|
+
} else if (placement === "before") {
|
|
4466
|
+
const currentSelection = editor.selection;
|
|
4467
|
+
Transforms.insertNodes(editor, [block], {
|
|
4468
|
+
at: focusBlockPath,
|
|
4469
|
+
select: !1
|
|
4359
4470
|
});
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
markDefs
|
|
4365
|
-
} = focusBlock;
|
|
4366
|
-
isEqual(markDefs, fragment[0].markDefs) || Transforms.setNodes(action.editor, {
|
|
4367
|
-
markDefs: uniq([...fragment[0].markDefs || [], ...markDefs || []])
|
|
4368
|
-
}, {
|
|
4369
|
-
at: focusPath,
|
|
4370
|
-
mode: "lowest",
|
|
4371
|
-
voids: !1
|
|
4471
|
+
const adjustedSelection = Range.transform(currentSelection, {
|
|
4472
|
+
type: "move_node",
|
|
4473
|
+
path: focusBlockPath,
|
|
4474
|
+
newPath: [focusBlockPath[0] + 1]
|
|
4372
4475
|
});
|
|
4476
|
+
adjustedSelection ? Transforms.select(editor, adjustedSelection) : Transforms.select(editor, currentSelection), select === "start" ? Transforms.select(editor, Editor.start(editor, focusBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, focusBlockPath));
|
|
4477
|
+
} else if (placement === "after") {
|
|
4478
|
+
const nextPath = [focusBlockPath[0] + 1], currentSelection = editor.selection;
|
|
4479
|
+
Transforms.insertNodes(editor, [block], {
|
|
4480
|
+
at: nextPath,
|
|
4481
|
+
select: !1
|
|
4482
|
+
}), Transforms.select(editor, currentSelection), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
4483
|
+
} else {
|
|
4484
|
+
const currentSelection = editor.selection, focusBlockStartPoint = Editor.start(editor, focusBlockPath);
|
|
4485
|
+
if (editor.isTextBlock(focusBlock) && editor.isTextBlock(block)) {
|
|
4486
|
+
if (select === "end") {
|
|
4487
|
+
Transforms.insertFragment(editor, [block], {
|
|
4488
|
+
voids: !0
|
|
4489
|
+
});
|
|
4490
|
+
return;
|
|
4491
|
+
}
|
|
4492
|
+
Transforms.insertFragment(editor, [block], {
|
|
4493
|
+
at: currentSelection,
|
|
4494
|
+
voids: !0
|
|
4495
|
+
}), select === "start" ? Point.equals(currentSelection.anchor, focusBlockStartPoint) ? Transforms.select(editor, Editor.start(editor, focusBlockPath)) : Transforms.select(editor, currentSelection) : Point.equals(currentSelection.anchor, focusBlockStartPoint) || Transforms.select(editor, currentSelection);
|
|
4496
|
+
} else if (editor.isTextBlock(focusBlock)) {
|
|
4497
|
+
const focusBlockStartPoint2 = Editor.start(editor, focusBlockPath), focusBlockEndPoint = Editor.end(editor, focusBlockPath);
|
|
4498
|
+
if (Point.equals(currentSelection.anchor, focusBlockStartPoint2))
|
|
4499
|
+
Transforms.insertNodes(editor, [block], {
|
|
4500
|
+
at: focusBlockPath,
|
|
4501
|
+
select: !1
|
|
4502
|
+
}), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, focusBlockPath)), isEqualToEmptyEditor([focusBlock], schema) && Transforms.removeNodes(editor, {
|
|
4503
|
+
at: Path.next(focusBlockPath)
|
|
4504
|
+
});
|
|
4505
|
+
else if (Point.equals(currentSelection.focus, focusBlockEndPoint)) {
|
|
4506
|
+
const nextPath = [focusBlockPath[0] + 1];
|
|
4507
|
+
Transforms.insertNodes(editor, [block], {
|
|
4508
|
+
at: nextPath,
|
|
4509
|
+
select: !1
|
|
4510
|
+
}), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, nextPath));
|
|
4511
|
+
} else {
|
|
4512
|
+
const currentSelection2 = editor.selection, [focusChild] = getFocusChild({
|
|
4513
|
+
editor
|
|
4514
|
+
});
|
|
4515
|
+
if (focusChild && editor.isTextSpan(focusChild))
|
|
4516
|
+
Transforms.insertFragment(editor, [block], {
|
|
4517
|
+
at: currentSelection2
|
|
4518
|
+
}), select === "start" || select === "end" ? Transforms.select(editor, [focusBlockPath[0] + 1]) : Transforms.select(editor, currentSelection2);
|
|
4519
|
+
else {
|
|
4520
|
+
const nextPath = [focusBlockPath[0] + 1];
|
|
4521
|
+
Transforms.insertNodes(editor, [block], {
|
|
4522
|
+
at: nextPath,
|
|
4523
|
+
select: !1
|
|
4524
|
+
}), Transforms.select(editor, currentSelection2), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
4525
|
+
}
|
|
4526
|
+
}
|
|
4527
|
+
} else {
|
|
4528
|
+
Transforms.insertNodes(editor, [block], {
|
|
4529
|
+
select: !1
|
|
4530
|
+
});
|
|
4531
|
+
const nextPath = [focusBlockPath[0] + 1];
|
|
4532
|
+
select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
4533
|
+
}
|
|
4373
4534
|
}
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4535
|
+
}
|
|
4536
|
+
const selectActionImplementation = ({
|
|
4537
|
+
action
|
|
4538
|
+
}) => {
|
|
4539
|
+
const newSelection = toSlateRange(action.selection, action.editor);
|
|
4540
|
+
newSelection ? Transforms.select(action.editor, newSelection) : Transforms.deselect(action.editor);
|
|
4541
|
+
}, selectNextBlockActionImplementation = ({
|
|
4380
4542
|
context,
|
|
4381
4543
|
action
|
|
4382
4544
|
}) => {
|
|
4383
|
-
if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
|
|
4384
|
-
console.error("Unable to insert unknown inline object");
|
|
4385
|
-
return;
|
|
4386
|
-
}
|
|
4387
4545
|
if (!action.editor.selection) {
|
|
4388
|
-
console.error("Unable to
|
|
4389
|
-
return;
|
|
4390
|
-
}
|
|
4391
|
-
const [focusTextBlock] = Array.from(Editor.nodes(action.editor, {
|
|
4392
|
-
at: action.editor.selection.focus.path,
|
|
4393
|
-
match: (node) => action.editor.isTextBlock(node)
|
|
4394
|
-
})).at(0) ?? [void 0, void 0];
|
|
4395
|
-
if (!focusTextBlock) {
|
|
4396
|
-
console.error("Unable to perform action without focus text block");
|
|
4546
|
+
console.error("Unable to select previous block without a selection");
|
|
4397
4547
|
return;
|
|
4398
4548
|
}
|
|
4399
|
-
const
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
...action.inlineObject.value ?? {}
|
|
4406
|
-
}]
|
|
4407
|
-
}], {
|
|
4408
|
-
schemaTypes: context.schema
|
|
4409
|
-
}).at(0)?.children.at(0);
|
|
4410
|
-
if (!child) {
|
|
4411
|
-
console.error("Unable to insert inline object");
|
|
4549
|
+
const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1], position = action.select === "end" ? Editor.end(action.editor, nextBlockPath) : Editor.start(action.editor, nextBlockPath), newSelection = toPortableTextRange(action.editor.children, {
|
|
4550
|
+
anchor: position,
|
|
4551
|
+
focus: position
|
|
4552
|
+
}, context.schema);
|
|
4553
|
+
if (!newSelection) {
|
|
4554
|
+
console.error("Could not find selection for next block");
|
|
4412
4555
|
return;
|
|
4413
4556
|
}
|
|
4414
|
-
|
|
4415
|
-
|
|
4557
|
+
selectActionImplementation({
|
|
4558
|
+
context,
|
|
4559
|
+
action: {
|
|
4560
|
+
type: "select",
|
|
4561
|
+
selection: newSelection,
|
|
4562
|
+
editor: action.editor
|
|
4563
|
+
}
|
|
4564
|
+
});
|
|
4565
|
+
}, selectPreviousBlockActionImplementation = ({
|
|
4416
4566
|
context,
|
|
4417
4567
|
action
|
|
4418
4568
|
}) => {
|
|
4419
4569
|
if (!action.editor.selection) {
|
|
4420
|
-
console.error("Unable to
|
|
4570
|
+
console.error("Unable to select previous block without a selection");
|
|
4421
4571
|
return;
|
|
4422
4572
|
}
|
|
4423
|
-
const
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
}))[0] ?? [void 0, void 0];
|
|
4427
|
-
if (!focusBlock || !focusBlockPath) {
|
|
4428
|
-
console.error("Unable to perform action without focus block", action);
|
|
4573
|
+
const blockPath = action.editor.selection.focus.path.slice(0, 1);
|
|
4574
|
+
if (!Path.hasPrevious(blockPath)) {
|
|
4575
|
+
console.error("There's no previous block to select");
|
|
4429
4576
|
return;
|
|
4430
4577
|
}
|
|
4431
|
-
const
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
}
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4578
|
+
const position = action.select === "end" ? Editor.end(action.editor, Path.previous(blockPath)) : Editor.start(action.editor, Path.previous(blockPath)), newSelection = toPortableTextRange(action.editor.children, {
|
|
4579
|
+
anchor: position,
|
|
4580
|
+
focus: position
|
|
4581
|
+
}, context.schema);
|
|
4582
|
+
if (!newSelection) {
|
|
4583
|
+
console.error("Could not find selection for previous block");
|
|
4584
|
+
return;
|
|
4585
|
+
}
|
|
4586
|
+
selectActionImplementation({
|
|
4587
|
+
context,
|
|
4588
|
+
action: {
|
|
4589
|
+
type: "select",
|
|
4590
|
+
selection: newSelection,
|
|
4591
|
+
editor: action.editor
|
|
4592
|
+
}
|
|
4593
|
+
});
|
|
4594
|
+
}, insertBlocksActionImplementation = ({
|
|
4595
|
+
context,
|
|
4596
|
+
action
|
|
4447
4597
|
}) => {
|
|
4448
|
-
const
|
|
4449
|
-
block: action.block,
|
|
4598
|
+
const parsedBlocks = parseBlocks({
|
|
4450
4599
|
context,
|
|
4600
|
+
blocks: action.blocks,
|
|
4451
4601
|
options: {
|
|
4452
4602
|
refreshKeys: !1
|
|
4453
4603
|
}
|
|
4454
4604
|
});
|
|
4455
|
-
if (
|
|
4456
|
-
throw new Error(`Failed to parse
|
|
4457
|
-
const fragment = toSlateValue(
|
|
4605
|
+
if (parsedBlocks.length === 0)
|
|
4606
|
+
throw new Error(`Failed to parse blocks ${JSON.stringify(action.blocks)}`);
|
|
4607
|
+
const fragment = toSlateValue(parsedBlocks, {
|
|
4458
4608
|
schemaTypes: context.schema
|
|
4459
|
-
})
|
|
4460
|
-
if (
|
|
4461
|
-
throw new Error(`Failed to convert
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4609
|
+
});
|
|
4610
|
+
if (fragment.length === 0)
|
|
4611
|
+
throw new Error(`Failed to convert blocks to Slate fragment ${JSON.stringify(parsedBlocks)}`);
|
|
4612
|
+
const [focusBlock] = getFocusBlock({
|
|
4613
|
+
editor: action.editor
|
|
4614
|
+
});
|
|
4615
|
+
if (action.placement === "before") {
|
|
4616
|
+
let index = 0;
|
|
4617
|
+
for (const block of fragment)
|
|
4618
|
+
insertBlock({
|
|
4619
|
+
block,
|
|
4620
|
+
placement: index === 0 ? "before" : "after",
|
|
4621
|
+
select: "end",
|
|
4622
|
+
editor: action.editor,
|
|
4623
|
+
schema: context.schema
|
|
4624
|
+
}), index++;
|
|
4625
|
+
} else if (action.placement === "after")
|
|
4626
|
+
for (const block of fragment)
|
|
4627
|
+
insertBlock({
|
|
4628
|
+
block,
|
|
4629
|
+
placement: "after",
|
|
4630
|
+
select: "end",
|
|
4631
|
+
editor: action.editor,
|
|
4632
|
+
schema: context.schema
|
|
4633
|
+
});
|
|
4634
|
+
else if (focusBlock && action.editor.isTextBlock(focusBlock)) {
|
|
4635
|
+
if (fragment.length === 1) {
|
|
4636
|
+
insertBlock({
|
|
4637
|
+
block: fragment[0],
|
|
4638
|
+
placement: "auto",
|
|
4639
|
+
select: "end",
|
|
4640
|
+
editor: action.editor,
|
|
4641
|
+
schema: context.schema
|
|
4642
|
+
});
|
|
4643
|
+
return;
|
|
4644
|
+
}
|
|
4645
|
+
let index = 0;
|
|
4646
|
+
for (const block of fragment)
|
|
4647
|
+
index === 0 ? (insertBreakActionImplementation({
|
|
4648
|
+
context,
|
|
4649
|
+
action: {
|
|
4650
|
+
type: "insert.break",
|
|
4651
|
+
editor: action.editor
|
|
4652
|
+
}
|
|
4653
|
+
}), selectPreviousBlockActionImplementation({
|
|
4654
|
+
context,
|
|
4655
|
+
action: {
|
|
4656
|
+
type: "select.previous block",
|
|
4657
|
+
editor: action.editor,
|
|
4658
|
+
select: "end"
|
|
4659
|
+
}
|
|
4660
|
+
}), insertBlock({
|
|
4661
|
+
block,
|
|
4662
|
+
placement: "auto",
|
|
4663
|
+
select: "end",
|
|
4664
|
+
editor: action.editor,
|
|
4665
|
+
schema: context.schema
|
|
4666
|
+
})) : index === fragment.length - 1 ? (selectNextBlockActionImplementation({
|
|
4667
|
+
context,
|
|
4668
|
+
action: {
|
|
4669
|
+
type: "select.next block",
|
|
4670
|
+
editor: action.editor,
|
|
4671
|
+
select: "start"
|
|
4672
|
+
}
|
|
4673
|
+
}), insertBlock({
|
|
4674
|
+
block,
|
|
4675
|
+
placement: "auto",
|
|
4676
|
+
select: "end",
|
|
4677
|
+
editor: action.editor,
|
|
4678
|
+
schema: context.schema
|
|
4679
|
+
})) : insertBlock({
|
|
4680
|
+
block,
|
|
4681
|
+
placement: "after",
|
|
4682
|
+
select: "end",
|
|
4683
|
+
editor: action.editor,
|
|
4684
|
+
schema: context.schema
|
|
4685
|
+
}), index++;
|
|
4686
|
+
} else
|
|
4687
|
+
for (const block of fragment)
|
|
4688
|
+
insertBlock({
|
|
4689
|
+
block,
|
|
4690
|
+
placement: "auto",
|
|
4691
|
+
select: "end",
|
|
4692
|
+
editor: action.editor,
|
|
4693
|
+
schema: context.schema
|
|
4694
|
+
});
|
|
4695
|
+
}, deserializationSuccessActionImplementation = ({
|
|
4696
|
+
context,
|
|
4697
|
+
action
|
|
4698
|
+
}) => {
|
|
4699
|
+
insertBlocksActionImplementation({
|
|
4700
|
+
context,
|
|
4701
|
+
action: {
|
|
4702
|
+
type: "insert.blocks",
|
|
4703
|
+
blocks: action.data,
|
|
4704
|
+
editor: action.editor,
|
|
4705
|
+
placement: "auto"
|
|
4706
|
+
}
|
|
4707
|
+
});
|
|
4708
|
+
}, effectActionImplementation = ({
|
|
4709
|
+
action
|
|
4710
|
+
}) => {
|
|
4711
|
+
action.effect();
|
|
4712
|
+
}, focusActionImplementation = ({
|
|
4713
|
+
action
|
|
4714
|
+
}) => {
|
|
4715
|
+
ReactEditor.focus(action.editor);
|
|
4716
|
+
}, insertInlineObjectActionImplementation = ({
|
|
4717
|
+
context,
|
|
4718
|
+
action
|
|
4719
|
+
}) => {
|
|
4720
|
+
if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
|
|
4721
|
+
console.error("Unable to insert unknown inline object");
|
|
4722
|
+
return;
|
|
4723
|
+
}
|
|
4724
|
+
if (!action.editor.selection) {
|
|
4725
|
+
console.error("Unable to insert inline object without selection");
|
|
4726
|
+
return;
|
|
4727
|
+
}
|
|
4728
|
+
const [focusTextBlock] = Array.from(Editor.nodes(action.editor, {
|
|
4729
|
+
at: action.editor.selection.focus.path,
|
|
4730
|
+
match: (node) => action.editor.isTextBlock(node)
|
|
4731
|
+
})).at(0) ?? [void 0, void 0];
|
|
4732
|
+
if (!focusTextBlock) {
|
|
4733
|
+
console.error("Unable to perform action without focus text block");
|
|
4734
|
+
return;
|
|
4735
|
+
}
|
|
4736
|
+
const child = toSlateValue([{
|
|
4737
|
+
_type: context.schema.block.name,
|
|
4738
|
+
_key: context.keyGenerator(),
|
|
4739
|
+
children: [{
|
|
4740
|
+
_type: action.inlineObject.name,
|
|
4741
|
+
_key: context.keyGenerator(),
|
|
4742
|
+
...action.inlineObject.value ?? {}
|
|
4743
|
+
}]
|
|
4744
|
+
}], {
|
|
4745
|
+
schemaTypes: context.schema
|
|
4746
|
+
}).at(0)?.children.at(0);
|
|
4747
|
+
if (!child) {
|
|
4748
|
+
console.error("Unable to insert inline object");
|
|
4749
|
+
return;
|
|
4750
|
+
}
|
|
4751
|
+
Transforms.insertNodes(action.editor, child);
|
|
4752
|
+
}, insertSpanActionImplementation = ({
|
|
4753
|
+
context,
|
|
4754
|
+
action
|
|
4755
|
+
}) => {
|
|
4756
|
+
if (!action.editor.selection) {
|
|
4757
|
+
console.error("Unable to perform action without selection", action);
|
|
4758
|
+
return;
|
|
4759
|
+
}
|
|
4760
|
+
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(action.editor, {
|
|
4761
|
+
at: action.editor.selection.focus.path,
|
|
4762
|
+
match: (node) => action.editor.isTextBlock(node)
|
|
4763
|
+
}))[0] ?? [void 0, void 0];
|
|
4764
|
+
if (!focusBlock || !focusBlockPath) {
|
|
4765
|
+
console.error("Unable to perform action without focus block", action);
|
|
4766
|
+
return;
|
|
4767
|
+
}
|
|
4768
|
+
const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
|
|
4769
|
+
_type: annotation.name,
|
|
4770
|
+
_key: context.keyGenerator(),
|
|
4771
|
+
...annotation.value
|
|
4772
|
+
})) : void 0;
|
|
4773
|
+
annotations && annotations.length > 0 && Transforms.setNodes(action.editor, {
|
|
4774
|
+
markDefs: [...markDefs, ...annotations]
|
|
4775
|
+
}), Transforms.insertNodes(action.editor, {
|
|
4776
|
+
_type: "span",
|
|
4777
|
+
_key: context.keyGenerator(),
|
|
4778
|
+
text: action.text,
|
|
4779
|
+
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
|
|
4780
|
+
});
|
|
4781
|
+
}, insertBlockObjectActionImplementation = ({
|
|
4782
|
+
context,
|
|
4783
|
+
action
|
|
4784
|
+
}) => {
|
|
4785
|
+
insertBlockActionImplementation({
|
|
4786
|
+
context,
|
|
4787
|
+
action: {
|
|
4788
|
+
type: "insert.block",
|
|
4789
|
+
block: {
|
|
4790
|
+
_key: context.keyGenerator(),
|
|
4791
|
+
_type: action.blockObject.name,
|
|
4792
|
+
...action.blockObject.value ? action.blockObject.value : {}
|
|
4793
|
+
},
|
|
4794
|
+
editor: action.editor,
|
|
4795
|
+
placement: action.placement
|
|
4796
|
+
}
|
|
4797
|
+
});
|
|
4798
|
+
}, insertTextActionImplementation = ({
|
|
4799
|
+
action
|
|
4800
|
+
}) => {
|
|
4801
|
+
action.editor.insertText(action.text);
|
|
4802
|
+
}, insertTextBlockActionImplementation = ({
|
|
4803
|
+
context,
|
|
4804
|
+
action
|
|
4805
|
+
}) => {
|
|
4806
|
+
insertBlockActionImplementation({
|
|
4807
|
+
context,
|
|
4808
|
+
action: {
|
|
4809
|
+
type: "insert.block",
|
|
4810
|
+
block: {
|
|
4811
|
+
_key: context.keyGenerator(),
|
|
4812
|
+
_type: context.schema.block.name,
|
|
4813
|
+
children: action.textBlock?.children?.map((child) => ({
|
|
4814
|
+
...child,
|
|
4815
|
+
_key: context.keyGenerator()
|
|
4816
|
+
})) ?? [{
|
|
4817
|
+
_type: context.schema.span.name,
|
|
4818
|
+
_key: context.keyGenerator(),
|
|
4819
|
+
text: "",
|
|
4820
|
+
marks: []
|
|
4821
|
+
}],
|
|
4822
|
+
markDefs: [],
|
|
4823
|
+
style: context.schema.styles[0].value ?? "normal"
|
|
4824
|
+
},
|
|
4825
|
+
editor: action.editor,
|
|
4826
|
+
placement: action.placement,
|
|
4827
|
+
select: "start"
|
|
4828
|
+
}
|
|
4829
|
+
});
|
|
4830
|
+
}, moveBlockActionImplementation = ({
|
|
4831
|
+
action
|
|
4832
|
+
}) => {
|
|
4833
|
+
const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
|
|
4834
|
+
Transforms.moveNodes(action.editor, {
|
|
4835
|
+
at,
|
|
4836
|
+
to,
|
|
4837
|
+
mode: "highest"
|
|
4838
|
+
});
|
|
4839
|
+
}, moveBlockDownActionImplementation = ({
|
|
4840
|
+
context,
|
|
4841
|
+
action
|
|
4842
|
+
}) => {
|
|
4843
|
+
const at = [toSlatePath(action.at, action.editor)[0]], to = [Path.next(at)[0]], selection = toPortableTextRange(action.editor.children, {
|
|
4844
|
+
anchor: {
|
|
4845
|
+
path: to,
|
|
4846
|
+
offset: 0
|
|
4847
|
+
},
|
|
4848
|
+
focus: {
|
|
4849
|
+
path: to,
|
|
4850
|
+
offset: 0
|
|
4851
|
+
}
|
|
4852
|
+
}, context.schema), destinationBlockKey = selection && isKeyedSegment$1(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
|
|
4853
|
+
if (destinationBlockKey === void 0) {
|
|
4854
|
+
console.error("Could not find destination block key");
|
|
4855
|
+
return;
|
|
4856
|
+
}
|
|
4857
|
+
moveBlockActionImplementation({
|
|
4858
|
+
context,
|
|
4859
|
+
action: {
|
|
4860
|
+
type: "move.block",
|
|
4861
|
+
at: action.at,
|
|
4862
|
+
to: [{
|
|
4863
|
+
_key: destinationBlockKey
|
|
4864
|
+
}],
|
|
4865
|
+
editor: action.editor
|
|
4866
|
+
}
|
|
4867
|
+
});
|
|
4868
|
+
}, moveBlockUpActionImplementation = ({
|
|
4869
|
+
context,
|
|
4870
|
+
action
|
|
4871
|
+
}) => {
|
|
4872
|
+
const at = [toSlatePath(action.at, action.editor)[0]];
|
|
4873
|
+
if (!Path.hasPrevious(at))
|
|
4874
|
+
return;
|
|
4875
|
+
const to = [Path.previous(at)[0]], selection = toPortableTextRange(action.editor.children, {
|
|
4876
|
+
anchor: {
|
|
4877
|
+
path: to,
|
|
4878
|
+
offset: 0
|
|
4879
|
+
},
|
|
4880
|
+
focus: {
|
|
4881
|
+
path: to,
|
|
4882
|
+
offset: 0
|
|
4883
|
+
}
|
|
4884
|
+
}, context.schema), destinationBlockKey = selection && isKeyedSegment$1(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
|
|
4885
|
+
if (destinationBlockKey === void 0) {
|
|
4886
|
+
console.error("Could not find destination block key");
|
|
4887
|
+
return;
|
|
4888
|
+
}
|
|
4889
|
+
moveBlockActionImplementation({
|
|
4890
|
+
context,
|
|
4891
|
+
action: {
|
|
4892
|
+
type: "move.block",
|
|
4893
|
+
at: action.at,
|
|
4894
|
+
to: [{
|
|
4895
|
+
_key: destinationBlockKey
|
|
4896
|
+
}],
|
|
4897
|
+
editor: action.editor
|
|
4898
|
+
}
|
|
4899
|
+
});
|
|
4900
|
+
}, noopActionImplementation = () => {
|
|
4901
|
+
}, serializationFailureActionImplementation = ({
|
|
4902
|
+
action
|
|
4903
|
+
}) => {
|
|
4904
|
+
console.warn(`Serialization of ${action.mimeType} failed with reason "${action.reason}"`);
|
|
4905
|
+
}, serializationSuccessActionImplementation = ({
|
|
4906
|
+
context,
|
|
4907
|
+
action
|
|
4908
|
+
}) => {
|
|
4909
|
+
dataTransferSetActionImplementation({
|
|
4910
|
+
context,
|
|
4911
|
+
action: {
|
|
4912
|
+
...action,
|
|
4913
|
+
type: "data transfer.set"
|
|
4914
|
+
}
|
|
4467
4915
|
});
|
|
4468
4916
|
}, behaviorActionImplementations = {
|
|
4469
4917
|
"annotation.add": addAnnotationActionImplementation,
|
|
@@ -4471,72 +4919,19 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4471
4919
|
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
4472
4920
|
"block.set": blockSetBehaviorActionImplementation,
|
|
4473
4921
|
"block.unset": blockUnsetBehaviorActionImplementation,
|
|
4474
|
-
blur:
|
|
4475
|
-
action
|
|
4476
|
-
}) => {
|
|
4477
|
-
ReactEditor.blur(action.editor);
|
|
4478
|
-
},
|
|
4922
|
+
blur: blurActionImplementation,
|
|
4479
4923
|
"data transfer.set": dataTransferSetActionImplementation,
|
|
4480
4924
|
"decorator.add": decoratorAddActionImplementation,
|
|
4481
4925
|
"decorator.remove": removeDecoratorActionImplementation,
|
|
4482
4926
|
"decorator.toggle": toggleDecoratorActionImplementation,
|
|
4483
|
-
focus:
|
|
4484
|
-
action
|
|
4485
|
-
}) => {
|
|
4486
|
-
ReactEditor.focus(action.editor);
|
|
4487
|
-
},
|
|
4927
|
+
focus: focusActionImplementation,
|
|
4488
4928
|
delete: deleteActionImplementation,
|
|
4489
|
-
"delete.backward":
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
action.editor.deleteBackward(action.unit);
|
|
4493
|
-
},
|
|
4494
|
-
"delete.forward": ({
|
|
4495
|
-
action
|
|
4496
|
-
}) => {
|
|
4497
|
-
deleteForward(action.editor, action.unit);
|
|
4498
|
-
},
|
|
4499
|
-
"delete.block": ({
|
|
4500
|
-
action
|
|
4501
|
-
}) => {
|
|
4502
|
-
const range = toSlateRange({
|
|
4503
|
-
anchor: {
|
|
4504
|
-
path: action.blockPath,
|
|
4505
|
-
offset: 0
|
|
4506
|
-
},
|
|
4507
|
-
focus: {
|
|
4508
|
-
path: action.blockPath,
|
|
4509
|
-
offset: 0
|
|
4510
|
-
}
|
|
4511
|
-
}, action.editor);
|
|
4512
|
-
if (!range) {
|
|
4513
|
-
console.error("Unable to find Slate range from selection points");
|
|
4514
|
-
return;
|
|
4515
|
-
}
|
|
4516
|
-
Transforms.removeNodes(action.editor, {
|
|
4517
|
-
at: range
|
|
4518
|
-
});
|
|
4519
|
-
},
|
|
4929
|
+
"delete.backward": deleteBackwardActionImplementation,
|
|
4930
|
+
"delete.forward": deleteForwardActionImplementation,
|
|
4931
|
+
"delete.block": deleteBlockActionImplementation,
|
|
4520
4932
|
"delete.text": deleteTextActionImplementation,
|
|
4521
|
-
"deserialization.failure":
|
|
4522
|
-
|
|
4523
|
-
}) => {
|
|
4524
|
-
console.warn(`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`);
|
|
4525
|
-
},
|
|
4526
|
-
"deserialization.success": ({
|
|
4527
|
-
context,
|
|
4528
|
-
action
|
|
4529
|
-
}) => {
|
|
4530
|
-
insertBlocksActionImplementation({
|
|
4531
|
-
context,
|
|
4532
|
-
action: {
|
|
4533
|
-
type: "insert.blocks",
|
|
4534
|
-
blocks: action.data,
|
|
4535
|
-
editor: action.editor,
|
|
4536
|
-
placement: "auto"
|
|
4537
|
-
}
|
|
4538
|
-
});
|
|
4539
|
-
},
|
|
4933
|
+
"deserialization.failure": deserializationFailureActionImplementation,
|
|
4934
|
+
"deserialization.success": deserializationSuccessActionImplementation,
|
|
4540
4935
|
"history.redo": historyRedoActionImplementation,
|
|
4541
4936
|
"history.undo": historyUndoActionImplementation,
|
|
4542
4937
|
"insert.block": insertBlockActionImplementation,
|
|
@@ -4546,129 +4941,21 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4546
4941
|
"insert.inline object": insertInlineObjectActionImplementation,
|
|
4547
4942
|
"insert.soft break": insertSoftBreakActionImplementation,
|
|
4548
4943
|
"insert.span": insertSpanActionImplementation,
|
|
4549
|
-
"insert.text":
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
insertText(action.editor, action.text);
|
|
4553
|
-
},
|
|
4554
|
-
"insert.text block": ({
|
|
4555
|
-
context,
|
|
4556
|
-
action
|
|
4557
|
-
}) => {
|
|
4558
|
-
const block = toSlateValue([{
|
|
4559
|
-
_key: context.keyGenerator(),
|
|
4560
|
-
_type: context.schema.block.name,
|
|
4561
|
-
style: context.schema.styles[0].value ?? "normal",
|
|
4562
|
-
markDefs: [],
|
|
4563
|
-
children: action.textBlock?.children?.map((child) => ({
|
|
4564
|
-
...child,
|
|
4565
|
-
_key: context.keyGenerator()
|
|
4566
|
-
})) ?? [{
|
|
4567
|
-
_type: context.schema.span.name,
|
|
4568
|
-
_key: context.keyGenerator(),
|
|
4569
|
-
text: ""
|
|
4570
|
-
}]
|
|
4571
|
-
}], {
|
|
4572
|
-
schemaTypes: context.schema
|
|
4573
|
-
})[0];
|
|
4574
|
-
insertBlock({
|
|
4575
|
-
block,
|
|
4576
|
-
editor: action.editor,
|
|
4577
|
-
schema: context.schema,
|
|
4578
|
-
placement: action.placement
|
|
4579
|
-
});
|
|
4580
|
-
},
|
|
4581
|
-
effect: ({
|
|
4582
|
-
action
|
|
4583
|
-
}) => {
|
|
4584
|
-
action.effect();
|
|
4585
|
-
},
|
|
4944
|
+
"insert.text": insertTextActionImplementation,
|
|
4945
|
+
"insert.text block": insertTextBlockActionImplementation,
|
|
4946
|
+
effect: effectActionImplementation,
|
|
4586
4947
|
"list item.add": addListItemActionImplementation,
|
|
4587
4948
|
"list item.remove": removeListItemActionImplementation,
|
|
4588
4949
|
"list item.toggle": toggleListItemActionImplementation,
|
|
4589
|
-
"move.block":
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
},
|
|
4599
|
-
"move.block down": ({
|
|
4600
|
-
action
|
|
4601
|
-
}) => {
|
|
4602
|
-
const at = [toSlatePath(action.at, action.editor)[0]], to = [Path.next(at)[0]];
|
|
4603
|
-
Transforms.moveNodes(action.editor, {
|
|
4604
|
-
at,
|
|
4605
|
-
to,
|
|
4606
|
-
mode: "highest"
|
|
4607
|
-
});
|
|
4608
|
-
},
|
|
4609
|
-
"move.block up": ({
|
|
4610
|
-
action
|
|
4611
|
-
}) => {
|
|
4612
|
-
const at = [toSlatePath(action.at, action.editor)[0]];
|
|
4613
|
-
if (!Path.hasPrevious(at))
|
|
4614
|
-
return;
|
|
4615
|
-
const to = [Path.previous(at)[0]];
|
|
4616
|
-
Transforms.moveNodes(action.editor, {
|
|
4617
|
-
at,
|
|
4618
|
-
to,
|
|
4619
|
-
mode: "highest"
|
|
4620
|
-
});
|
|
4621
|
-
},
|
|
4622
|
-
noop: () => {
|
|
4623
|
-
},
|
|
4624
|
-
select: ({
|
|
4625
|
-
action
|
|
4626
|
-
}) => {
|
|
4627
|
-
const newSelection = toSlateRange(action.selection, action.editor);
|
|
4628
|
-
newSelection ? Transforms.select(action.editor, newSelection) : Transforms.deselect(action.editor);
|
|
4629
|
-
},
|
|
4630
|
-
"select.previous block": ({
|
|
4631
|
-
action
|
|
4632
|
-
}) => {
|
|
4633
|
-
if (!action.editor.selection) {
|
|
4634
|
-
console.error("Unable to select previous block without a selection");
|
|
4635
|
-
return;
|
|
4636
|
-
}
|
|
4637
|
-
const blockPath = action.editor.selection.focus.path.slice(0, 1);
|
|
4638
|
-
if (!Path.hasPrevious(blockPath)) {
|
|
4639
|
-
console.error("There's no previous block to select");
|
|
4640
|
-
return;
|
|
4641
|
-
}
|
|
4642
|
-
const previousBlockPath = Path.previous(blockPath);
|
|
4643
|
-
Transforms.select(action.editor, previousBlockPath);
|
|
4644
|
-
},
|
|
4645
|
-
"select.next block": ({
|
|
4646
|
-
action
|
|
4647
|
-
}) => {
|
|
4648
|
-
if (!action.editor.selection) {
|
|
4649
|
-
console.error("Unable to select next block without a selection");
|
|
4650
|
-
return;
|
|
4651
|
-
}
|
|
4652
|
-
const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
|
|
4653
|
-
Transforms.select(action.editor, nextBlockPath);
|
|
4654
|
-
},
|
|
4655
|
-
"serialization.failure": ({
|
|
4656
|
-
action
|
|
4657
|
-
}) => {
|
|
4658
|
-
console.warn(`Serialization of ${action.mimeType} failed with reason "${action.reason}"`);
|
|
4659
|
-
},
|
|
4660
|
-
"serialization.success": ({
|
|
4661
|
-
context,
|
|
4662
|
-
action
|
|
4663
|
-
}) => {
|
|
4664
|
-
dataTransferSetActionImplementation({
|
|
4665
|
-
context,
|
|
4666
|
-
action: {
|
|
4667
|
-
...action,
|
|
4668
|
-
type: "data transfer.set"
|
|
4669
|
-
}
|
|
4670
|
-
});
|
|
4671
|
-
},
|
|
4950
|
+
"move.block": moveBlockActionImplementation,
|
|
4951
|
+
"move.block down": moveBlockDownActionImplementation,
|
|
4952
|
+
"move.block up": moveBlockUpActionImplementation,
|
|
4953
|
+
noop: noopActionImplementation,
|
|
4954
|
+
select: selectActionImplementation,
|
|
4955
|
+
"select.previous block": selectPreviousBlockActionImplementation,
|
|
4956
|
+
"select.next block": selectNextBlockActionImplementation,
|
|
4957
|
+
"serialization.failure": serializationFailureActionImplementation,
|
|
4958
|
+
"serialization.success": serializationSuccessActionImplementation,
|
|
4672
4959
|
"style.toggle": toggleStyleActionImplementation,
|
|
4673
4960
|
"style.add": addStyleActionImplementation,
|
|
4674
4961
|
"style.remove": removeStyleActionImplementation
|
|
@@ -4676,27 +4963,6 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4676
4963
|
function performAction({
|
|
4677
4964
|
context,
|
|
4678
4965
|
action
|
|
4679
|
-
}) {
|
|
4680
|
-
switch (action.type) {
|
|
4681
|
-
case "noop":
|
|
4682
|
-
break;
|
|
4683
|
-
case "effect": {
|
|
4684
|
-
behaviorActionImplementations.effect({
|
|
4685
|
-
context,
|
|
4686
|
-
action
|
|
4687
|
-
});
|
|
4688
|
-
break;
|
|
4689
|
-
}
|
|
4690
|
-
default:
|
|
4691
|
-
performDefaultAction({
|
|
4692
|
-
context,
|
|
4693
|
-
action
|
|
4694
|
-
});
|
|
4695
|
-
}
|
|
4696
|
-
}
|
|
4697
|
-
function performDefaultAction({
|
|
4698
|
-
context,
|
|
4699
|
-
action
|
|
4700
4966
|
}) {
|
|
4701
4967
|
switch (action.type) {
|
|
4702
4968
|
case "annotation.add": {
|
|
@@ -4818,6 +5084,13 @@ function performDefaultAction({
|
|
|
4818
5084
|
});
|
|
4819
5085
|
break;
|
|
4820
5086
|
}
|
|
5087
|
+
case "effect": {
|
|
5088
|
+
behaviorActionImplementations.effect({
|
|
5089
|
+
context,
|
|
5090
|
+
action
|
|
5091
|
+
});
|
|
5092
|
+
break;
|
|
5093
|
+
}
|
|
4821
5094
|
case "focus": {
|
|
4822
5095
|
behaviorActionImplementations.focus({
|
|
4823
5096
|
context,
|
|
@@ -4944,6 +5217,8 @@ function performDefaultAction({
|
|
|
4944
5217
|
});
|
|
4945
5218
|
break;
|
|
4946
5219
|
}
|
|
5220
|
+
case "noop":
|
|
5221
|
+
break;
|
|
4947
5222
|
case "select": {
|
|
4948
5223
|
behaviorActionImplementations.select({
|
|
4949
5224
|
context,
|
|
@@ -5049,12 +5324,10 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5049
5324
|
});
|
|
5050
5325
|
const {
|
|
5051
5326
|
deleteBackward,
|
|
5052
|
-
deleteForward
|
|
5327
|
+
deleteForward,
|
|
5053
5328
|
insertBreak,
|
|
5054
|
-
insertData,
|
|
5055
5329
|
insertText: insertText2,
|
|
5056
|
-
select
|
|
5057
|
-
setFragmentData
|
|
5330
|
+
select
|
|
5058
5331
|
} = editor;
|
|
5059
5332
|
return editor.deleteBackward = (unit) => {
|
|
5060
5333
|
if (isApplyingBehaviorActions(editor)) {
|
|
@@ -5071,7 +5344,7 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5071
5344
|
});
|
|
5072
5345
|
}, editor.deleteForward = (unit) => {
|
|
5073
5346
|
if (isApplyingBehaviorActions(editor)) {
|
|
5074
|
-
|
|
5347
|
+
deleteForward(unit);
|
|
5075
5348
|
return;
|
|
5076
5349
|
}
|
|
5077
5350
|
editorActor.send({
|
|
@@ -5094,19 +5367,8 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5094
5367
|
},
|
|
5095
5368
|
editor
|
|
5096
5369
|
});
|
|
5097
|
-
}, editor.insertData = (
|
|
5098
|
-
|
|
5099
|
-
insertData(dataTransfer);
|
|
5100
|
-
return;
|
|
5101
|
-
}
|
|
5102
|
-
editorActor.send({
|
|
5103
|
-
type: "behavior event",
|
|
5104
|
-
behaviorEvent: {
|
|
5105
|
-
type: "deserialize",
|
|
5106
|
-
dataTransfer
|
|
5107
|
-
},
|
|
5108
|
-
editor
|
|
5109
|
-
});
|
|
5370
|
+
}, editor.insertData = () => {
|
|
5371
|
+
console.warn("Unexpected call to .insertData(...)");
|
|
5110
5372
|
}, editor.insertSoftBreak = () => {
|
|
5111
5373
|
if (isApplyingBehaviorActions(editor)) {
|
|
5112
5374
|
insertSoftBreakActionImplementation({
|
|
@@ -5168,7 +5430,7 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5168
5430
|
});
|
|
5169
5431
|
}, editor.select = (location) => {
|
|
5170
5432
|
if (isApplyingBehaviorActions(editor)) {
|
|
5171
|
-
|
|
5433
|
+
select(location);
|
|
5172
5434
|
return;
|
|
5173
5435
|
}
|
|
5174
5436
|
const range = Editor.range(editor, location);
|
|
@@ -5180,23 +5442,11 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5180
5442
|
},
|
|
5181
5443
|
editor,
|
|
5182
5444
|
defaultActionCallback: () => {
|
|
5183
|
-
|
|
5445
|
+
select(location);
|
|
5184
5446
|
}
|
|
5185
5447
|
});
|
|
5186
|
-
}, editor.setFragmentData = (
|
|
5187
|
-
|
|
5188
|
-
setFragmentData(dataTransfer);
|
|
5189
|
-
return;
|
|
5190
|
-
}
|
|
5191
|
-
dataTransfer.clearData(), editorActor.send({
|
|
5192
|
-
type: "behavior event",
|
|
5193
|
-
behaviorEvent: {
|
|
5194
|
-
type: "serialize",
|
|
5195
|
-
dataTransfer,
|
|
5196
|
-
originEvent: originEvent ?? "unknown"
|
|
5197
|
-
},
|
|
5198
|
-
editor
|
|
5199
|
-
});
|
|
5448
|
+
}, editor.setFragmentData = () => {
|
|
5449
|
+
console.warn("Unexpected call to .setFragmentData(...)");
|
|
5200
5450
|
}, editor.undo = () => {
|
|
5201
5451
|
if (isApplyingBehaviorActions(editor)) {
|
|
5202
5452
|
performAction({
|
|
@@ -6027,16 +6277,8 @@ const keyIs = {
|
|
|
6027
6277
|
event
|
|
6028
6278
|
}, deserializeEvent) => [raise({
|
|
6029
6279
|
...deserializeEvent,
|
|
6030
|
-
dataTransfer: event.dataTransfer
|
|
6031
|
-
|
|
6032
|
-
}), raiseInsertBlocks = defineBehavior({
|
|
6033
|
-
on: "deserialization.success",
|
|
6034
|
-
actions: [({
|
|
6035
|
-
event
|
|
6036
|
-
}) => [raise({
|
|
6037
|
-
type: "insert.blocks",
|
|
6038
|
-
blocks: event.data,
|
|
6039
|
-
placement: "auto"
|
|
6280
|
+
dataTransfer: event.dataTransfer,
|
|
6281
|
+
originEvent: event.originEvent
|
|
6040
6282
|
})]]
|
|
6041
6283
|
}), raiseSerializationSuccessOrFailure = defineBehavior({
|
|
6042
6284
|
on: "serialize",
|
|
@@ -6048,7 +6290,10 @@ const keyIs = {
|
|
|
6048
6290
|
return !1;
|
|
6049
6291
|
const serializeEvents = snapshot.context.converters.map((converter) => converter.serialize({
|
|
6050
6292
|
snapshot,
|
|
6051
|
-
event
|
|
6293
|
+
event: {
|
|
6294
|
+
...event,
|
|
6295
|
+
originEvent: event.originEvent.type
|
|
6296
|
+
}
|
|
6052
6297
|
}));
|
|
6053
6298
|
return serializeEvents.length === 0 ? !1 : serializeEvents;
|
|
6054
6299
|
},
|
|
@@ -6056,9 +6301,69 @@ const keyIs = {
|
|
|
6056
6301
|
event
|
|
6057
6302
|
}, serializeEvents) => serializeEvents.map((serializeEvent) => raise({
|
|
6058
6303
|
...serializeEvent,
|
|
6304
|
+
originEvent: event.originEvent,
|
|
6059
6305
|
dataTransfer: event.dataTransfer
|
|
6060
6306
|
}))]
|
|
6061
|
-
}),
|
|
6307
|
+
}), defaultBehaviors = [defineBehavior({
|
|
6308
|
+
on: "copy",
|
|
6309
|
+
guard: ({
|
|
6310
|
+
snapshot
|
|
6311
|
+
}) => {
|
|
6312
|
+
const focusSpan = getFocusSpan(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6313
|
+
return focusSpan && selectionCollapsed;
|
|
6314
|
+
},
|
|
6315
|
+
actions: [() => [{
|
|
6316
|
+
type: "noop"
|
|
6317
|
+
}]]
|
|
6318
|
+
}), defineBehavior({
|
|
6319
|
+
on: "copy",
|
|
6320
|
+
actions: [({
|
|
6321
|
+
event
|
|
6322
|
+
}) => [raise({
|
|
6323
|
+
type: "serialize",
|
|
6324
|
+
dataTransfer: event.data,
|
|
6325
|
+
originEvent: event
|
|
6326
|
+
})]]
|
|
6327
|
+
}), defineBehavior({
|
|
6328
|
+
on: "cut",
|
|
6329
|
+
guard: ({
|
|
6330
|
+
snapshot
|
|
6331
|
+
}) => {
|
|
6332
|
+
const focusSpan = getFocusSpan(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6333
|
+
return focusSpan && selectionCollapsed;
|
|
6334
|
+
},
|
|
6335
|
+
actions: [() => [{
|
|
6336
|
+
type: "noop"
|
|
6337
|
+
}]]
|
|
6338
|
+
}), defineBehavior({
|
|
6339
|
+
on: "cut",
|
|
6340
|
+
guard: ({
|
|
6341
|
+
snapshot
|
|
6342
|
+
}) => snapshot.context.selection ? {
|
|
6343
|
+
selection: snapshot.context.selection
|
|
6344
|
+
} : !1,
|
|
6345
|
+
actions: [({
|
|
6346
|
+
event
|
|
6347
|
+
}, {
|
|
6348
|
+
selection
|
|
6349
|
+
}) => [raise({
|
|
6350
|
+
type: "serialize",
|
|
6351
|
+
dataTransfer: event.dataTransfer,
|
|
6352
|
+
originEvent: event
|
|
6353
|
+
}), raise({
|
|
6354
|
+
type: "delete",
|
|
6355
|
+
selection
|
|
6356
|
+
})]]
|
|
6357
|
+
}), defineBehavior({
|
|
6358
|
+
on: "drag.dragstart",
|
|
6359
|
+
actions: [({
|
|
6360
|
+
event
|
|
6361
|
+
}) => [raise({
|
|
6362
|
+
type: "serialize",
|
|
6363
|
+
dataTransfer: event.dataTransfer,
|
|
6364
|
+
originEvent: event
|
|
6365
|
+
})]]
|
|
6366
|
+
}), defineBehavior({
|
|
6062
6367
|
on: "serialization.success",
|
|
6063
6368
|
actions: [({
|
|
6064
6369
|
event
|
|
@@ -6068,22 +6373,129 @@ const keyIs = {
|
|
|
6068
6373
|
dataTransfer: event.dataTransfer,
|
|
6069
6374
|
mimeType: event.mimeType
|
|
6070
6375
|
})]]
|
|
6071
|
-
}),
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6376
|
+
}), defineBehavior({
|
|
6377
|
+
on: "drag.drop",
|
|
6378
|
+
guard: ({
|
|
6379
|
+
snapshot,
|
|
6380
|
+
event
|
|
6381
|
+
}) => {
|
|
6382
|
+
const dragOrigin = snapshot.beta.internalDrag?.origin, dropPosition = event.position.selection;
|
|
6383
|
+
return dragOrigin ? isOverlappingSelection(dropPosition)({
|
|
6384
|
+
...snapshot,
|
|
6385
|
+
context: {
|
|
6386
|
+
...snapshot.context,
|
|
6387
|
+
selection: dragOrigin.selection
|
|
6388
|
+
}
|
|
6389
|
+
}) : !1;
|
|
6390
|
+
},
|
|
6391
|
+
actions: [() => [{
|
|
6392
|
+
type: "noop"
|
|
6393
|
+
}]]
|
|
6394
|
+
}), defineBehavior({
|
|
6395
|
+
on: "drag.drop",
|
|
6396
|
+
actions: [({
|
|
6397
|
+
event
|
|
6398
|
+
}) => [raise({
|
|
6399
|
+
type: "deserialize",
|
|
6400
|
+
dataTransfer: event.dataTransfer,
|
|
6401
|
+
originEvent: event
|
|
6402
|
+
})]]
|
|
6403
|
+
}), defineBehavior({
|
|
6404
|
+
on: "deserialization.success",
|
|
6405
|
+
guard: ({
|
|
6406
|
+
snapshot,
|
|
6407
|
+
event
|
|
6408
|
+
}) => {
|
|
6409
|
+
if (event.originEvent.type !== "drag.drop" || snapshot.beta.internalDrag === void 0)
|
|
6410
|
+
return !1;
|
|
6411
|
+
const dragOrigin = snapshot.beta.internalDrag.origin, dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? isOverlappingSelection(dropPosition)({
|
|
6412
|
+
...snapshot,
|
|
6413
|
+
context: {
|
|
6414
|
+
...snapshot.context,
|
|
6415
|
+
selection: dragOrigin.selection
|
|
6416
|
+
}
|
|
6417
|
+
}) : !1, draggingEntireBlocks = isSelectingEntireBlocks({
|
|
6418
|
+
...snapshot,
|
|
6419
|
+
context: {
|
|
6420
|
+
...snapshot.context,
|
|
6421
|
+
selection: dragOrigin.selection
|
|
6422
|
+
}
|
|
6423
|
+
}), draggedBlocks = getSelectedBlocks({
|
|
6424
|
+
...snapshot,
|
|
6425
|
+
context: {
|
|
6426
|
+
...snapshot.context,
|
|
6427
|
+
selection: dragOrigin.selection
|
|
6428
|
+
}
|
|
6429
|
+
});
|
|
6430
|
+
return droppingOnDragOrigin ? !1 : {
|
|
6431
|
+
draggingEntireBlocks,
|
|
6432
|
+
draggedBlocks,
|
|
6433
|
+
dragOrigin
|
|
6434
|
+
};
|
|
6435
|
+
},
|
|
6436
|
+
actions: [({
|
|
6437
|
+
event
|
|
6438
|
+
}, {
|
|
6439
|
+
draggingEntireBlocks,
|
|
6440
|
+
draggedBlocks,
|
|
6441
|
+
dragOrigin
|
|
6442
|
+
}) => [raise({
|
|
6443
|
+
type: "insert.blocks",
|
|
6444
|
+
blocks: event.data,
|
|
6445
|
+
placement: draggingEntireBlocks ? event.originEvent.position.block === "start" ? "before" : event.originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
6446
|
+
}), ...draggingEntireBlocks ? draggedBlocks.map((block) => raise({
|
|
6447
|
+
type: "delete.block",
|
|
6448
|
+
blockPath: block.path
|
|
6449
|
+
})) : [raise({
|
|
6450
|
+
type: "delete",
|
|
6451
|
+
selection: dragOrigin.selection
|
|
6452
|
+
})]]]
|
|
6453
|
+
}), defineBehavior({
|
|
6454
|
+
on: "deserialization.success",
|
|
6455
|
+
actions: [({
|
|
6456
|
+
event
|
|
6457
|
+
}) => [raise({
|
|
6458
|
+
type: "insert.blocks",
|
|
6459
|
+
blocks: event.data,
|
|
6460
|
+
placement: "auto"
|
|
6461
|
+
})]]
|
|
6462
|
+
}), defineBehavior({
|
|
6463
|
+
on: "paste",
|
|
6464
|
+
guard: ({
|
|
6465
|
+
snapshot
|
|
6466
|
+
}) => snapshot.context.selection && isSelectionExpanded(snapshot) ? {
|
|
6467
|
+
selection: snapshot.context.selection
|
|
6468
|
+
} : !1,
|
|
6469
|
+
actions: [({
|
|
6470
|
+
event
|
|
6471
|
+
}, {
|
|
6472
|
+
selection
|
|
6473
|
+
}) => [raise({
|
|
6474
|
+
type: "delete",
|
|
6475
|
+
selection
|
|
6476
|
+
}), raise({
|
|
6477
|
+
type: "deserialize",
|
|
6478
|
+
dataTransfer: event.data,
|
|
6479
|
+
originEvent: event
|
|
6480
|
+
})]]
|
|
6481
|
+
}), defineBehavior({
|
|
6482
|
+
on: "paste",
|
|
6483
|
+
actions: [({
|
|
6484
|
+
event
|
|
6485
|
+
}) => [raise({
|
|
6486
|
+
type: "deserialize",
|
|
6487
|
+
dataTransfer: event.data,
|
|
6488
|
+
originEvent: event
|
|
6489
|
+
})]]
|
|
6490
|
+
}), toggleAnnotationOff, toggleAnnotationOn, toggleDecoratorOff, toggleDecoratorOn, toggleListItemOff, toggleListItemOn, toggleStyleOff, toggleStyleOn, raiseDeserializationSuccessOrFailure, raiseSerializationSuccessOrFailure, raiseInsertSoftBreak];
|
|
6081
6491
|
function createEditorSnapshot({
|
|
6082
6492
|
converters,
|
|
6083
6493
|
editor,
|
|
6084
6494
|
keyGenerator,
|
|
6495
|
+
readOnly,
|
|
6085
6496
|
schema,
|
|
6086
|
-
hasTag
|
|
6497
|
+
hasTag,
|
|
6498
|
+
internalDrag
|
|
6087
6499
|
}) {
|
|
6088
6500
|
const value = fromSlateValue(editor.children, schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), selection = toPortableTextRange(value, editor.selection, schema);
|
|
6089
6501
|
return {
|
|
@@ -6094,12 +6506,14 @@ function createEditorSnapshot({
|
|
|
6094
6506
|
}),
|
|
6095
6507
|
converters,
|
|
6096
6508
|
keyGenerator,
|
|
6509
|
+
readOnly,
|
|
6097
6510
|
schema,
|
|
6098
6511
|
selection,
|
|
6099
6512
|
value
|
|
6100
6513
|
},
|
|
6101
6514
|
beta: {
|
|
6102
|
-
hasTag
|
|
6515
|
+
hasTag,
|
|
6516
|
+
internalDrag
|
|
6103
6517
|
}
|
|
6104
6518
|
};
|
|
6105
6519
|
}
|
|
@@ -6181,10 +6595,10 @@ const editorMachine = setup({
|
|
|
6181
6595
|
self
|
|
6182
6596
|
}) => {
|
|
6183
6597
|
assertEvent(event, ["behavior event", "custom behavior event"]);
|
|
6184
|
-
const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
|
|
6598
|
+
const defaultAction = event.type === "custom behavior event" || isDragBehaviorEvent(event.behaviorEvent) || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "cut" || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || isMouseBehaviorEvent(event.behaviorEvent) || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
|
|
6185
6599
|
...event.behaviorEvent,
|
|
6186
6600
|
editor: event.editor
|
|
6187
|
-
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => behavior.on === "*" || behavior.on === event.behaviorEvent.type);
|
|
6601
|
+
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => behavior.on === "*" ? !0 : isDragBehaviorEvent(event.behaviorEvent) && behavior.on === "drag.*" || behavior.on === event.behaviorEvent.type);
|
|
6188
6602
|
if (eventBehaviors.length === 0) {
|
|
6189
6603
|
if (defaultActionCallback) {
|
|
6190
6604
|
withApplyingBehaviorActions(event.editor, () => {
|
|
@@ -6201,7 +6615,10 @@ const editorMachine = setup({
|
|
|
6201
6615
|
withApplyingBehaviorActions(event.editor, () => {
|
|
6202
6616
|
try {
|
|
6203
6617
|
performAction({
|
|
6204
|
-
context
|
|
6618
|
+
context: {
|
|
6619
|
+
keyGenerator: context.keyGenerator,
|
|
6620
|
+
schema: context.schema
|
|
6621
|
+
},
|
|
6205
6622
|
action: defaultAction
|
|
6206
6623
|
});
|
|
6207
6624
|
} catch (error) {
|
|
@@ -6214,8 +6631,12 @@ const editorMachine = setup({
|
|
|
6214
6631
|
converters: [...context.converters],
|
|
6215
6632
|
editor: event.editor,
|
|
6216
6633
|
keyGenerator: context.keyGenerator,
|
|
6634
|
+
readOnly: self.getSnapshot().matches({
|
|
6635
|
+
"edit mode": "read only"
|
|
6636
|
+
}),
|
|
6217
6637
|
schema: context.schema,
|
|
6218
|
-
hasTag: (tag) => self.getSnapshot().hasTag(tag)
|
|
6638
|
+
hasTag: (tag) => self.getSnapshot().hasTag(tag),
|
|
6639
|
+
internalDrag: context.internalDrag
|
|
6219
6640
|
});
|
|
6220
6641
|
let behaviorOverwritten = !1;
|
|
6221
6642
|
for (const eventBehavior of eventBehaviors) {
|
|
@@ -6252,7 +6673,10 @@ const editorMachine = setup({
|
|
|
6252
6673
|
};
|
|
6253
6674
|
try {
|
|
6254
6675
|
performAction({
|
|
6255
|
-
context
|
|
6676
|
+
context: {
|
|
6677
|
+
keyGenerator: context.keyGenerator,
|
|
6678
|
+
schema: context.schema
|
|
6679
|
+
},
|
|
6256
6680
|
action: internalAction
|
|
6257
6681
|
});
|
|
6258
6682
|
} catch (error) {
|
|
@@ -6282,7 +6706,10 @@ const editorMachine = setup({
|
|
|
6282
6706
|
withApplyingBehaviorActions(event.editor, () => {
|
|
6283
6707
|
try {
|
|
6284
6708
|
performAction({
|
|
6285
|
-
context
|
|
6709
|
+
context: {
|
|
6710
|
+
keyGenerator: context.keyGenerator,
|
|
6711
|
+
schema: context.schema
|
|
6712
|
+
},
|
|
6286
6713
|
action: defaultAction
|
|
6287
6714
|
});
|
|
6288
6715
|
} catch (error) {
|
|
@@ -6557,11 +6984,26 @@ const editorMachine = setup({
|
|
|
6557
6984
|
idle: {
|
|
6558
6985
|
on: {
|
|
6559
6986
|
dragstart: {
|
|
6987
|
+
actions: [assign({
|
|
6988
|
+
internalDrag: ({
|
|
6989
|
+
event
|
|
6990
|
+
}) => ({
|
|
6991
|
+
ghost: event.ghost,
|
|
6992
|
+
origin: event.origin
|
|
6993
|
+
})
|
|
6994
|
+
})],
|
|
6560
6995
|
target: "dragging internally"
|
|
6561
6996
|
}
|
|
6562
6997
|
}
|
|
6563
6998
|
},
|
|
6564
6999
|
"dragging internally": {
|
|
7000
|
+
exit: [({
|
|
7001
|
+
context
|
|
7002
|
+
}) => {
|
|
7003
|
+
context.internalDrag?.ghost && document.body.removeChild(context.internalDrag.ghost);
|
|
7004
|
+
}, assign({
|
|
7005
|
+
internalDrag: void 0
|
|
7006
|
+
})],
|
|
6565
7007
|
tags: ["dragging internally"],
|
|
6566
7008
|
on: {
|
|
6567
7009
|
dragend: {
|
|
@@ -6641,50 +7083,6 @@ const editorMachine = setup({
|
|
|
6641
7083
|
}
|
|
6642
7084
|
}
|
|
6643
7085
|
});
|
|
6644
|
-
function getValue({
|
|
6645
|
-
editorActorSnapshot,
|
|
6646
|
-
slateEditorInstance
|
|
6647
|
-
}) {
|
|
6648
|
-
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
6649
|
-
}
|
|
6650
|
-
function defaultCompare(a, b) {
|
|
6651
|
-
return a === b;
|
|
6652
|
-
}
|
|
6653
|
-
function useEditorSelector(editor, selector, t0) {
|
|
6654
|
-
const $ = c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
6655
|
-
let t1;
|
|
6656
|
-
return $[0] !== editor._internal.slateEditor.instance || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
6657
|
-
const snapshot = getEditorSnapshot({
|
|
6658
|
-
editorActorSnapshot,
|
|
6659
|
-
slateEditorInstance: editor._internal.slateEditor.instance
|
|
6660
|
-
});
|
|
6661
|
-
return selector(snapshot);
|
|
6662
|
-
}, $[0] = editor._internal.slateEditor.instance, $[1] = selector, $[2] = t1) : t1 = $[2], useSelector(editor._internal.editorActor, t1, compare);
|
|
6663
|
-
}
|
|
6664
|
-
function getEditorSnapshot({
|
|
6665
|
-
editorActorSnapshot,
|
|
6666
|
-
slateEditorInstance
|
|
6667
|
-
}) {
|
|
6668
|
-
return {
|
|
6669
|
-
context: {
|
|
6670
|
-
converters: [...editorActorSnapshot.context.converters],
|
|
6671
|
-
activeDecorators: getActiveDecorators({
|
|
6672
|
-
schema: editorActorSnapshot.context.schema,
|
|
6673
|
-
slateEditorInstance
|
|
6674
|
-
}),
|
|
6675
|
-
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
6676
|
-
schema: editorActorSnapshot.context.schema,
|
|
6677
|
-
selection: editorActorSnapshot.context.selection,
|
|
6678
|
-
value: getValue({
|
|
6679
|
-
editorActorSnapshot,
|
|
6680
|
-
slateEditorInstance
|
|
6681
|
-
})
|
|
6682
|
-
},
|
|
6683
|
-
beta: {
|
|
6684
|
-
hasTag: (tag) => editorActorSnapshot.hasTag(tag)
|
|
6685
|
-
}
|
|
6686
|
-
};
|
|
6687
|
-
}
|
|
6688
7086
|
function createEditor(config) {
|
|
6689
7087
|
const editorActor = createActor(editorMachine, {
|
|
6690
7088
|
input: editorConfigToMachineInput(config)
|
|
@@ -6761,7 +7159,7 @@ function createEditorFromActor(editorActor) {
|
|
|
6761
7159
|
}
|
|
6762
7160
|
};
|
|
6763
7161
|
}
|
|
6764
|
-
const
|
|
7162
|
+
const PortableTextEditorSelectionContext = createContext(null), usePortableTextEditorSelection = () => {
|
|
6765
7163
|
const selection = useContext(PortableTextEditorSelectionContext);
|
|
6766
7164
|
if (selection === void 0)
|
|
6767
7165
|
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
@@ -7331,21 +7729,17 @@ function useEditor() {
|
|
|
7331
7729
|
export {
|
|
7332
7730
|
EditorActorContext,
|
|
7333
7731
|
EditorProvider,
|
|
7334
|
-
IS_DRAGGING,
|
|
7335
|
-
IS_DRAGGING_BLOCK_ELEMENT,
|
|
7336
|
-
IS_DRAGGING_BLOCK_TARGET_POSITION,
|
|
7337
|
-
IS_DRAGGING_ELEMENT_TARGET,
|
|
7338
7732
|
KEY_TO_VALUE_ELEMENT,
|
|
7339
7733
|
PortableTextEditor,
|
|
7340
7734
|
debugWithName,
|
|
7341
7735
|
defaultKeyGenerator,
|
|
7342
7736
|
defineSchema,
|
|
7343
7737
|
fromSlateValue,
|
|
7738
|
+
getEditorSnapshot,
|
|
7344
7739
|
isEqualToEmptyEditor,
|
|
7345
7740
|
moveRangeByOperation,
|
|
7346
7741
|
toPortableTextRange,
|
|
7347
7742
|
toSlateRange,
|
|
7348
|
-
toSlateValue,
|
|
7349
7743
|
useEditor,
|
|
7350
7744
|
useEditorSelector,
|
|
7351
7745
|
usePortableTextEditor,
|