@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var jsxRuntime = require("react/jsx-runtime"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$e = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"),
|
|
2
|
+
var jsxRuntime = require("react/jsx-runtime"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$e = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), parseBlocks = require("./parse-blocks.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), omit = require("lodash/omit.js"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
|
|
3
3
|
function _interopDefaultCompat(e) {
|
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
5
|
}
|
|
@@ -307,7 +307,65 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
307
307
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
308
308
|
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.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 && slate.Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
|
|
309
309
|
}
|
|
310
|
-
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(),
|
|
310
|
+
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 = React.createContext({});
|
|
311
|
+
function getActiveDecorators({
|
|
312
|
+
schema: schema2,
|
|
313
|
+
slateEditorInstance
|
|
314
|
+
}) {
|
|
315
|
+
const decorators = schema2.decorators.map((decorator) => decorator.value);
|
|
316
|
+
return ({
|
|
317
|
+
...slate.Editor.marks(slateEditorInstance) ?? {}
|
|
318
|
+
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
319
|
+
}
|
|
320
|
+
function getValue({
|
|
321
|
+
editorActorSnapshot,
|
|
322
|
+
slateEditorInstance
|
|
323
|
+
}) {
|
|
324
|
+
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
325
|
+
}
|
|
326
|
+
function defaultCompare(a, b) {
|
|
327
|
+
return a === b;
|
|
328
|
+
}
|
|
329
|
+
function useEditorSelector(editor, selector, t0) {
|
|
330
|
+
const $ = reactCompilerRuntime.c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
331
|
+
let t1;
|
|
332
|
+
return $[0] !== editor._internal.slateEditor.instance || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
333
|
+
const snapshot = getEditorSnapshot({
|
|
334
|
+
editorActorSnapshot,
|
|
335
|
+
slateEditorInstance: editor._internal.slateEditor.instance
|
|
336
|
+
});
|
|
337
|
+
return selector(snapshot);
|
|
338
|
+
}, $[0] = editor._internal.slateEditor.instance, $[1] = selector, $[2] = t1) : t1 = $[2], react.useSelector(editor._internal.editorActor, t1, compare);
|
|
339
|
+
}
|
|
340
|
+
function getEditorSnapshot({
|
|
341
|
+
editorActorSnapshot,
|
|
342
|
+
slateEditorInstance
|
|
343
|
+
}) {
|
|
344
|
+
return {
|
|
345
|
+
context: {
|
|
346
|
+
converters: [...editorActorSnapshot.context.converters],
|
|
347
|
+
activeDecorators: getActiveDecorators({
|
|
348
|
+
schema: editorActorSnapshot.context.schema,
|
|
349
|
+
slateEditorInstance
|
|
350
|
+
}),
|
|
351
|
+
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
352
|
+
readOnly: editorActorSnapshot.matches({
|
|
353
|
+
"edit mode": "read only"
|
|
354
|
+
}),
|
|
355
|
+
schema: editorActorSnapshot.context.schema,
|
|
356
|
+
selection: editorActorSnapshot.context.selection,
|
|
357
|
+
value: getValue({
|
|
358
|
+
editorActorSnapshot,
|
|
359
|
+
slateEditorInstance
|
|
360
|
+
})
|
|
361
|
+
},
|
|
362
|
+
beta: {
|
|
363
|
+
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
364
|
+
internalDrag: editorActorSnapshot.context.internalDrag
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
const PortableTextEditorContext = React.createContext(null), usePortableTextEditor = () => {
|
|
311
369
|
const editor = React.useContext(PortableTextEditorContext);
|
|
312
370
|
if (!editor)
|
|
313
371
|
throw new Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");
|
|
@@ -2401,7 +2459,8 @@ const converterJson = {
|
|
|
2401
2459
|
snapshot,
|
|
2402
2460
|
event
|
|
2403
2461
|
}) => {
|
|
2404
|
-
|
|
2462
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2463
|
+
if (!selection)
|
|
2405
2464
|
return {
|
|
2406
2465
|
type: "serialization.failure",
|
|
2407
2466
|
mimeType: "application/x-portable-text",
|
|
@@ -2410,7 +2469,7 @@ const converterJson = {
|
|
|
2410
2469
|
};
|
|
2411
2470
|
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2412
2471
|
blocks: snapshot.context.value,
|
|
2413
|
-
selection
|
|
2472
|
+
selection
|
|
2414
2473
|
});
|
|
2415
2474
|
return {
|
|
2416
2475
|
type: "serialization.success",
|
|
@@ -2431,7 +2490,7 @@ const converterJson = {
|
|
|
2431
2490
|
reason: "Data is not an array"
|
|
2432
2491
|
};
|
|
2433
2492
|
const parsedBlocks = blocks.flatMap((block) => {
|
|
2434
|
-
const parsedBlock =
|
|
2493
|
+
const parsedBlock = parseBlocks.parseBlock({
|
|
2435
2494
|
context: snapshot.context,
|
|
2436
2495
|
block,
|
|
2437
2496
|
options: {
|
|
@@ -2460,7 +2519,8 @@ const converterJson = {
|
|
|
2460
2519
|
snapshot,
|
|
2461
2520
|
event
|
|
2462
2521
|
}) => {
|
|
2463
|
-
|
|
2522
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2523
|
+
if (!selection)
|
|
2464
2524
|
return {
|
|
2465
2525
|
type: "serialization.failure",
|
|
2466
2526
|
mimeType: "text/html",
|
|
@@ -2469,7 +2529,7 @@ const converterJson = {
|
|
|
2469
2529
|
};
|
|
2470
2530
|
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2471
2531
|
blocks: snapshot.context.value,
|
|
2472
|
-
selection
|
|
2532
|
+
selection
|
|
2473
2533
|
}), html = toHtml.toHTML(blocks, {
|
|
2474
2534
|
onMissingComponent: !1,
|
|
2475
2535
|
components: {
|
|
@@ -2513,21 +2573,24 @@ const converterJson = {
|
|
|
2513
2573
|
serialize: ({
|
|
2514
2574
|
snapshot,
|
|
2515
2575
|
event
|
|
2516
|
-
}) =>
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2576
|
+
}) => {
|
|
2577
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2578
|
+
return selection ? {
|
|
2579
|
+
type: "serialization.success",
|
|
2580
|
+
data: util_sliceBlocks.sliceBlocks({
|
|
2581
|
+
blocks: snapshot.context.value,
|
|
2582
|
+
selection
|
|
2583
|
+
}).map((block) => types.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(`
|
|
2522
2584
|
|
|
2523
2585
|
`),
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2586
|
+
mimeType: "text/plain",
|
|
2587
|
+
originEvent: event.originEvent
|
|
2588
|
+
} : {
|
|
2589
|
+
type: "serialization.failure",
|
|
2590
|
+
mimeType: "text/plain",
|
|
2591
|
+
originEvent: event.originEvent,
|
|
2592
|
+
reason: "No selection"
|
|
2593
|
+
};
|
|
2531
2594
|
},
|
|
2532
2595
|
deserialize: ({
|
|
2533
2596
|
snapshot,
|
|
@@ -2791,7 +2854,8 @@ const insertBreakActionImplementation = ({
|
|
|
2791
2854
|
const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
2792
2855
|
if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
2793
2856
|
slate.Transforms.splitNodes(editor, {
|
|
2794
|
-
at: editor.selection
|
|
2857
|
+
at: editor.selection,
|
|
2858
|
+
always: !0
|
|
2795
2859
|
});
|
|
2796
2860
|
const [nextBlock, nextBlockPath] = slate.Editor.node(editor, slate.Path.next(focusBlockPath), {
|
|
2797
2861
|
depth: 1
|
|
@@ -3026,21 +3090,23 @@ const decoratorAddActionImplementation = ({
|
|
|
3026
3090
|
split: !0,
|
|
3027
3091
|
hanging: !0
|
|
3028
3092
|
});
|
|
3029
|
-
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection =
|
|
3093
|
+
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = parseBlocks.blockOffsetsToSelection({
|
|
3030
3094
|
value: newValue,
|
|
3031
3095
|
offsets: {
|
|
3032
3096
|
anchor: anchorOffset,
|
|
3033
3097
|
focus: focusOffset
|
|
3034
3098
|
},
|
|
3035
3099
|
backward: editorSelection?.backward
|
|
3036
|
-
}), trimmedSelection =
|
|
3100
|
+
}), trimmedSelection = selector_isOverlappingSelection.getTrimmedSelection({
|
|
3037
3101
|
beta: {
|
|
3038
|
-
hasTag: () => !1
|
|
3102
|
+
hasTag: () => !1,
|
|
3103
|
+
internalDrag: void 0
|
|
3039
3104
|
},
|
|
3040
3105
|
context: {
|
|
3041
3106
|
activeDecorators: [],
|
|
3042
3107
|
converters: [],
|
|
3043
3108
|
keyGenerator: context.keyGenerator,
|
|
3109
|
+
readOnly: !1,
|
|
3044
3110
|
schema: context.schema,
|
|
3045
3111
|
selection: newSelection,
|
|
3046
3112
|
value: newValue
|
|
@@ -4073,49 +4139,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4073
4139
|
editor: action.editor
|
|
4074
4140
|
}
|
|
4075
4141
|
});
|
|
4076
|
-
}
|
|
4077
|
-
function insertBlock({
|
|
4078
|
-
block,
|
|
4079
|
-
placement,
|
|
4080
|
-
editor,
|
|
4081
|
-
schema: schema2
|
|
4082
|
-
}) {
|
|
4083
|
-
if (editor.selection) {
|
|
4084
|
-
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(editor, {
|
|
4085
|
-
at: editor.selection.focus.path.slice(0, 1),
|
|
4086
|
-
match: (n) => !slate.Editor.isEditor(n)
|
|
4087
|
-
}))[0] ?? [void 0, void 0];
|
|
4088
|
-
if (placement === "after") {
|
|
4089
|
-
const nextPath = [focusBlockPath[0] + 1];
|
|
4090
|
-
slate.Transforms.insertNodes(editor, block, {
|
|
4091
|
-
at: nextPath
|
|
4092
|
-
}), slate.Transforms.select(editor, {
|
|
4093
|
-
anchor: {
|
|
4094
|
-
path: [nextPath[0], 0],
|
|
4095
|
-
offset: 0
|
|
4096
|
-
},
|
|
4097
|
-
focus: {
|
|
4098
|
-
path: [nextPath[0], 0],
|
|
4099
|
-
offset: 0
|
|
4100
|
-
}
|
|
4101
|
-
});
|
|
4102
|
-
} else placement === "before" ? slate.Transforms.insertNodes(editor, block, {
|
|
4103
|
-
at: focusBlockPath
|
|
4104
|
-
}) : (slate.Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock], schema2) && slate.Transforms.removeNodes(editor, {
|
|
4105
|
-
at: focusBlockPath
|
|
4106
|
-
}));
|
|
4107
|
-
} else {
|
|
4108
|
-
const lastBlock = Array.from(slate.Editor.nodes(editor, {
|
|
4109
|
-
match: (n) => !slate.Editor.isEditor(n),
|
|
4110
|
-
at: [],
|
|
4111
|
-
reverse: !0
|
|
4112
|
-
}))[0];
|
|
4113
|
-
slate.Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], schema2) && slate.Transforms.removeNodes(editor, {
|
|
4114
|
-
at: lastBlock[1]
|
|
4115
|
-
});
|
|
4116
|
-
}
|
|
4117
|
-
}
|
|
4118
|
-
const blockSetBehaviorActionImplementation = ({
|
|
4142
|
+
}, blockSetBehaviorActionImplementation = ({
|
|
4119
4143
|
context,
|
|
4120
4144
|
action
|
|
4121
4145
|
}) => {
|
|
@@ -4142,7 +4166,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4142
4166
|
const {
|
|
4143
4167
|
_type,
|
|
4144
4168
|
...filteredProps
|
|
4145
|
-
} = action.props, updatedBlock =
|
|
4169
|
+
} = action.props, updatedBlock = parseBlocks.parseBlock({
|
|
4146
4170
|
context,
|
|
4147
4171
|
block: {
|
|
4148
4172
|
...parsedBlock,
|
|
@@ -4186,8 +4210,8 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4186
4210
|
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
|
|
4187
4211
|
if (!parsedBlock)
|
|
4188
4212
|
throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
|
|
4189
|
-
if (
|
|
4190
|
-
const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock =
|
|
4213
|
+
if (parseBlocks.isTextBlock(context.schema, parsedBlock)) {
|
|
4214
|
+
const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = parseBlocks.parseBlock({
|
|
4191
4215
|
context,
|
|
4192
4216
|
block: omit__default.default(parsedBlock, propsToRemove),
|
|
4193
4217
|
options: {
|
|
@@ -4204,7 +4228,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4204
4228
|
});
|
|
4205
4229
|
return;
|
|
4206
4230
|
}
|
|
4207
|
-
const updatedBlockObject =
|
|
4231
|
+
const updatedBlockObject = parseBlocks.parseBlock({
|
|
4208
4232
|
context,
|
|
4209
4233
|
block: omit__default.default(parsedBlock, action.props.filter((prop) => prop !== "_type")),
|
|
4210
4234
|
options: {
|
|
@@ -4225,6 +4249,10 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4225
4249
|
}, {
|
|
4226
4250
|
at: location
|
|
4227
4251
|
});
|
|
4252
|
+
}, blurActionImplementation = ({
|
|
4253
|
+
action
|
|
4254
|
+
}) => {
|
|
4255
|
+
slateReact.ReactEditor.blur(action.editor);
|
|
4228
4256
|
}, dataTransferSetActionImplementation = ({
|
|
4229
4257
|
action
|
|
4230
4258
|
}) => {
|
|
@@ -4235,12 +4263,42 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4235
4263
|
const range = toSlateRange(action.selection, action.editor);
|
|
4236
4264
|
if (!range)
|
|
4237
4265
|
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.selection)}`);
|
|
4238
|
-
|
|
4266
|
+
action.editor.delete({
|
|
4267
|
+
at: range
|
|
4268
|
+
});
|
|
4269
|
+
}, deleteBackwardActionImplementation = ({
|
|
4270
|
+
action
|
|
4271
|
+
}) => {
|
|
4272
|
+
action.editor.deleteBackward(action.unit);
|
|
4273
|
+
}, deleteBlockActionImplementation = ({
|
|
4274
|
+
action
|
|
4275
|
+
}) => {
|
|
4276
|
+
const range = toSlateRange({
|
|
4277
|
+
anchor: {
|
|
4278
|
+
path: action.blockPath,
|
|
4279
|
+
offset: 0
|
|
4280
|
+
},
|
|
4281
|
+
focus: {
|
|
4282
|
+
path: action.blockPath,
|
|
4283
|
+
offset: 0
|
|
4284
|
+
}
|
|
4285
|
+
}, action.editor);
|
|
4286
|
+
if (!range) {
|
|
4287
|
+
console.error("Unable to find Slate range from selection points");
|
|
4288
|
+
return;
|
|
4289
|
+
}
|
|
4290
|
+
slate.Transforms.removeNodes(action.editor, {
|
|
4291
|
+
at: range
|
|
4292
|
+
});
|
|
4293
|
+
}, deleteForwardActionImplementation = ({
|
|
4294
|
+
action
|
|
4295
|
+
}) => {
|
|
4296
|
+
action.editor.deleteForward(action.unit);
|
|
4239
4297
|
}, deleteTextActionImplementation = ({
|
|
4240
4298
|
context,
|
|
4241
4299
|
action
|
|
4242
4300
|
}) => {
|
|
4243
|
-
const value = fromSlateValue(action.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)), selection =
|
|
4301
|
+
const value = fromSlateValue(action.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)), selection = parseBlocks.blockOffsetsToSelection({
|
|
4244
4302
|
value,
|
|
4245
4303
|
offsets: {
|
|
4246
4304
|
anchor: action.anchor,
|
|
@@ -4249,15 +4307,17 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4249
4307
|
});
|
|
4250
4308
|
if (!selection)
|
|
4251
4309
|
throw new Error("Unable to find selection from block offsets");
|
|
4252
|
-
const trimmedSelection =
|
|
4310
|
+
const trimmedSelection = selector_isOverlappingSelection.getTrimmedSelection({
|
|
4253
4311
|
beta: {
|
|
4254
|
-
hasTag: () => !1
|
|
4312
|
+
hasTag: () => !1,
|
|
4313
|
+
internalDrag: void 0
|
|
4255
4314
|
},
|
|
4256
4315
|
context: {
|
|
4257
4316
|
converters: [],
|
|
4258
4317
|
schema: context.schema,
|
|
4259
4318
|
keyGenerator: context.keyGenerator,
|
|
4260
4319
|
activeDecorators: [],
|
|
4320
|
+
readOnly: !1,
|
|
4261
4321
|
value,
|
|
4262
4322
|
selection
|
|
4263
4323
|
}
|
|
@@ -4270,176 +4330,563 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4270
4330
|
slate.Transforms.delete(action.editor, {
|
|
4271
4331
|
at: range
|
|
4272
4332
|
});
|
|
4273
|
-
},
|
|
4333
|
+
}, deserializationFailureActionImplementation = ({
|
|
4334
|
+
action
|
|
4335
|
+
}) => {
|
|
4336
|
+
console.warn(`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`);
|
|
4337
|
+
};
|
|
4338
|
+
function getFocusBlock({
|
|
4339
|
+
editor
|
|
4340
|
+
}) {
|
|
4341
|
+
return editor.selection ? Array.from(slate.Editor.nodes(editor, {
|
|
4342
|
+
at: editor.selection.focus.path.slice(0, 1),
|
|
4343
|
+
match: (n) => !slate.Editor.isEditor(n)
|
|
4344
|
+
})).at(0) ?? [void 0, void 0] : [void 0, void 0];
|
|
4345
|
+
}
|
|
4346
|
+
function getFocusChild({
|
|
4347
|
+
editor
|
|
4348
|
+
}) {
|
|
4349
|
+
const [focusBlock, focusBlockPath] = getFocusBlock({
|
|
4350
|
+
editor
|
|
4351
|
+
}), childIndex = editor.selection?.focus.path.at(1);
|
|
4352
|
+
if (!focusBlock || !focusBlockPath || childIndex === void 0)
|
|
4353
|
+
return [void 0, void 0];
|
|
4354
|
+
const focusChild = slate.Node.child(focusBlock, childIndex);
|
|
4355
|
+
return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
|
|
4356
|
+
}
|
|
4357
|
+
function getLastBlock({
|
|
4358
|
+
editor
|
|
4359
|
+
}) {
|
|
4360
|
+
return Array.from(slate.Editor.nodes(editor, {
|
|
4361
|
+
match: (n) => !slate.Editor.isEditor(n),
|
|
4362
|
+
at: [],
|
|
4363
|
+
reverse: !0
|
|
4364
|
+
})).at(0) ?? [void 0, void 0];
|
|
4365
|
+
}
|
|
4366
|
+
const insertBlockActionImplementation = ({
|
|
4274
4367
|
context,
|
|
4275
4368
|
action
|
|
4276
4369
|
}) => {
|
|
4277
|
-
const
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4370
|
+
const parsedBlock = parseBlocks.parseBlock({
|
|
4371
|
+
block: action.block,
|
|
4372
|
+
context,
|
|
4373
|
+
options: {
|
|
4374
|
+
refreshKeys: !1
|
|
4375
|
+
}
|
|
4376
|
+
});
|
|
4377
|
+
if (!parsedBlock)
|
|
4378
|
+
throw new Error(`Failed to parse block ${JSON.stringify(action.block)}`);
|
|
4379
|
+
const fragment = toSlateValue([parsedBlock], {
|
|
4282
4380
|
schemaTypes: context.schema
|
|
4283
4381
|
})[0];
|
|
4382
|
+
if (!fragment)
|
|
4383
|
+
throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
|
|
4284
4384
|
insertBlock({
|
|
4285
|
-
block,
|
|
4385
|
+
block: fragment,
|
|
4286
4386
|
placement: action.placement,
|
|
4387
|
+
select: action.select ?? "start",
|
|
4287
4388
|
editor: action.editor,
|
|
4288
4389
|
schema: context.schema
|
|
4289
4390
|
});
|
|
4290
|
-
}
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
at: slate.Editor.start(action.editor, [])
|
|
4301
|
-
});
|
|
4302
|
-
return;
|
|
4303
|
-
}
|
|
4304
|
-
if (action.placement === "after") {
|
|
4305
|
-
action.editor.insertFragment(fragment, {
|
|
4306
|
-
at: slate.Editor.end(action.editor, [])
|
|
4307
|
-
});
|
|
4308
|
-
return;
|
|
4309
|
-
}
|
|
4310
|
-
action.editor.insertFragment(fragment);
|
|
4311
|
-
return;
|
|
4312
|
-
}
|
|
4313
|
-
const [focusBlock, focusPath] = slate.Editor.node(action.editor, action.editor.selection, {
|
|
4314
|
-
depth: 1
|
|
4391
|
+
};
|
|
4392
|
+
function insertBlock({
|
|
4393
|
+
block,
|
|
4394
|
+
placement,
|
|
4395
|
+
select,
|
|
4396
|
+
editor,
|
|
4397
|
+
schema: schema2
|
|
4398
|
+
}) {
|
|
4399
|
+
const [focusBlock, focusBlockPath] = getFocusBlock({
|
|
4400
|
+
editor
|
|
4315
4401
|
});
|
|
4316
|
-
if (
|
|
4317
|
-
|
|
4318
|
-
|
|
4402
|
+
if (!editor.selection || !focusBlock || !focusBlockPath) {
|
|
4403
|
+
select !== "none" && slateDom.DOMEditor.focus(editor);
|
|
4404
|
+
const [lastBlock, lastBlockPath] = getLastBlock({
|
|
4405
|
+
editor
|
|
4319
4406
|
});
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4407
|
+
if (placement === "before")
|
|
4408
|
+
slate.Transforms.insertNodes(editor, [block], {
|
|
4409
|
+
at: [0]
|
|
4410
|
+
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, [0])) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, [0]));
|
|
4411
|
+
else if (placement === "after") {
|
|
4412
|
+
const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
|
|
4413
|
+
slate.Transforms.insertNodes(editor, [block], {
|
|
4414
|
+
at: nextPath,
|
|
4415
|
+
select: !1
|
|
4416
|
+
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
|
|
4417
|
+
} else {
|
|
4418
|
+
if (lastBlock && isEqualToEmptyEditor([lastBlock], schema2)) {
|
|
4419
|
+
slate.Transforms.removeNodes(editor, {
|
|
4420
|
+
at: lastBlockPath
|
|
4421
|
+
}), slate.Transforms.insertNodes(editor, [block], {
|
|
4422
|
+
at: lastBlockPath,
|
|
4423
|
+
select: !1
|
|
4424
|
+
}), slate.Transforms.deselect(editor), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, lastBlockPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, lastBlockPath));
|
|
4425
|
+
return;
|
|
4426
|
+
}
|
|
4427
|
+
if (editor.isTextBlock(block) && lastBlock && editor.isTextBlock(lastBlock)) {
|
|
4428
|
+
const selectionBefore = slate.Editor.end(editor, lastBlockPath);
|
|
4429
|
+
slate.Transforms.insertFragment(editor, [block], {
|
|
4430
|
+
at: slate.Editor.end(editor, lastBlockPath)
|
|
4431
|
+
}), select === "start" ? slate.Transforms.select(editor, selectionBefore) : select === "none" && slate.Transforms.deselect(editor);
|
|
4432
|
+
return;
|
|
4334
4433
|
}
|
|
4434
|
+
const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
|
|
4435
|
+
slate.Transforms.insertNodes(editor, [block], {
|
|
4436
|
+
at: nextPath,
|
|
4437
|
+
select: !1
|
|
4438
|
+
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
|
|
4439
|
+
}
|
|
4440
|
+
} else if (placement === "before") {
|
|
4441
|
+
const currentSelection = editor.selection;
|
|
4442
|
+
slate.Transforms.insertNodes(editor, [block], {
|
|
4443
|
+
at: focusBlockPath,
|
|
4444
|
+
select: !1
|
|
4335
4445
|
});
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
markDefs
|
|
4341
|
-
} = focusBlock;
|
|
4342
|
-
isEqual__default.default(markDefs, fragment[0].markDefs) || slate.Transforms.setNodes(action.editor, {
|
|
4343
|
-
markDefs: uniq__default.default([...fragment[0].markDefs || [], ...markDefs || []])
|
|
4344
|
-
}, {
|
|
4345
|
-
at: focusPath,
|
|
4346
|
-
mode: "lowest",
|
|
4347
|
-
voids: !1
|
|
4446
|
+
const adjustedSelection = slate.Range.transform(currentSelection, {
|
|
4447
|
+
type: "move_node",
|
|
4448
|
+
path: focusBlockPath,
|
|
4449
|
+
newPath: [focusBlockPath[0] + 1]
|
|
4348
4450
|
});
|
|
4451
|
+
adjustedSelection ? slate.Transforms.select(editor, adjustedSelection) : slate.Transforms.select(editor, currentSelection), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, focusBlockPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, focusBlockPath));
|
|
4452
|
+
} else if (placement === "after") {
|
|
4453
|
+
const nextPath = [focusBlockPath[0] + 1], currentSelection = editor.selection;
|
|
4454
|
+
slate.Transforms.insertNodes(editor, [block], {
|
|
4455
|
+
at: nextPath,
|
|
4456
|
+
select: !1
|
|
4457
|
+
}), slate.Transforms.select(editor, currentSelection), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
|
|
4458
|
+
} else {
|
|
4459
|
+
const currentSelection = editor.selection, focusBlockStartPoint = slate.Editor.start(editor, focusBlockPath);
|
|
4460
|
+
if (editor.isTextBlock(focusBlock) && editor.isTextBlock(block)) {
|
|
4461
|
+
if (select === "end") {
|
|
4462
|
+
slate.Transforms.insertFragment(editor, [block], {
|
|
4463
|
+
voids: !0
|
|
4464
|
+
});
|
|
4465
|
+
return;
|
|
4466
|
+
}
|
|
4467
|
+
slate.Transforms.insertFragment(editor, [block], {
|
|
4468
|
+
at: currentSelection,
|
|
4469
|
+
voids: !0
|
|
4470
|
+
}), select === "start" ? slate.Point.equals(currentSelection.anchor, focusBlockStartPoint) ? slate.Transforms.select(editor, slate.Editor.start(editor, focusBlockPath)) : slate.Transforms.select(editor, currentSelection) : slate.Point.equals(currentSelection.anchor, focusBlockStartPoint) || slate.Transforms.select(editor, currentSelection);
|
|
4471
|
+
} else if (editor.isTextBlock(focusBlock)) {
|
|
4472
|
+
const focusBlockStartPoint2 = slate.Editor.start(editor, focusBlockPath), focusBlockEndPoint = slate.Editor.end(editor, focusBlockPath);
|
|
4473
|
+
if (slate.Point.equals(currentSelection.anchor, focusBlockStartPoint2))
|
|
4474
|
+
slate.Transforms.insertNodes(editor, [block], {
|
|
4475
|
+
at: focusBlockPath,
|
|
4476
|
+
select: !1
|
|
4477
|
+
}), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor, focusBlockPath)), isEqualToEmptyEditor([focusBlock], schema2) && slate.Transforms.removeNodes(editor, {
|
|
4478
|
+
at: slate.Path.next(focusBlockPath)
|
|
4479
|
+
});
|
|
4480
|
+
else if (slate.Point.equals(currentSelection.focus, focusBlockEndPoint)) {
|
|
4481
|
+
const nextPath = [focusBlockPath[0] + 1];
|
|
4482
|
+
slate.Transforms.insertNodes(editor, [block], {
|
|
4483
|
+
at: nextPath,
|
|
4484
|
+
select: !1
|
|
4485
|
+
}), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor, nextPath));
|
|
4486
|
+
} else {
|
|
4487
|
+
const currentSelection2 = editor.selection, [focusChild] = getFocusChild({
|
|
4488
|
+
editor
|
|
4489
|
+
});
|
|
4490
|
+
if (focusChild && editor.isTextSpan(focusChild))
|
|
4491
|
+
slate.Transforms.insertFragment(editor, [block], {
|
|
4492
|
+
at: currentSelection2
|
|
4493
|
+
}), select === "start" || select === "end" ? slate.Transforms.select(editor, [focusBlockPath[0] + 1]) : slate.Transforms.select(editor, currentSelection2);
|
|
4494
|
+
else {
|
|
4495
|
+
const nextPath = [focusBlockPath[0] + 1];
|
|
4496
|
+
slate.Transforms.insertNodes(editor, [block], {
|
|
4497
|
+
at: nextPath,
|
|
4498
|
+
select: !1
|
|
4499
|
+
}), slate.Transforms.select(editor, currentSelection2), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
|
|
4500
|
+
}
|
|
4501
|
+
}
|
|
4502
|
+
} else {
|
|
4503
|
+
slate.Transforms.insertNodes(editor, [block], {
|
|
4504
|
+
select: !1
|
|
4505
|
+
});
|
|
4506
|
+
const nextPath = [focusBlockPath[0] + 1];
|
|
4507
|
+
select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
|
|
4508
|
+
}
|
|
4349
4509
|
}
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4510
|
+
}
|
|
4511
|
+
const selectActionImplementation = ({
|
|
4512
|
+
action
|
|
4513
|
+
}) => {
|
|
4514
|
+
const newSelection = toSlateRange(action.selection, action.editor);
|
|
4515
|
+
newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
|
|
4516
|
+
}, selectNextBlockActionImplementation = ({
|
|
4356
4517
|
context,
|
|
4357
4518
|
action
|
|
4358
4519
|
}) => {
|
|
4359
|
-
if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
|
|
4360
|
-
console.error("Unable to insert unknown inline object");
|
|
4361
|
-
return;
|
|
4362
|
-
}
|
|
4363
4520
|
if (!action.editor.selection) {
|
|
4364
|
-
console.error("Unable to
|
|
4365
|
-
return;
|
|
4366
|
-
}
|
|
4367
|
-
const [focusTextBlock] = Array.from(slate.Editor.nodes(action.editor, {
|
|
4368
|
-
at: action.editor.selection.focus.path,
|
|
4369
|
-
match: (node) => action.editor.isTextBlock(node)
|
|
4370
|
-
})).at(0) ?? [void 0, void 0];
|
|
4371
|
-
if (!focusTextBlock) {
|
|
4372
|
-
console.error("Unable to perform action without focus text block");
|
|
4521
|
+
console.error("Unable to select previous block without a selection");
|
|
4373
4522
|
return;
|
|
4374
4523
|
}
|
|
4375
|
-
const
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
...action.inlineObject.value ?? {}
|
|
4382
|
-
}]
|
|
4383
|
-
}], {
|
|
4384
|
-
schemaTypes: context.schema
|
|
4385
|
-
}).at(0)?.children.at(0);
|
|
4386
|
-
if (!child) {
|
|
4387
|
-
console.error("Unable to insert inline object");
|
|
4524
|
+
const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1], position = action.select === "end" ? slate.Editor.end(action.editor, nextBlockPath) : slate.Editor.start(action.editor, nextBlockPath), newSelection = toPortableTextRange(action.editor.children, {
|
|
4525
|
+
anchor: position,
|
|
4526
|
+
focus: position
|
|
4527
|
+
}, context.schema);
|
|
4528
|
+
if (!newSelection) {
|
|
4529
|
+
console.error("Could not find selection for next block");
|
|
4388
4530
|
return;
|
|
4389
4531
|
}
|
|
4390
|
-
|
|
4391
|
-
|
|
4532
|
+
selectActionImplementation({
|
|
4533
|
+
context,
|
|
4534
|
+
action: {
|
|
4535
|
+
type: "select",
|
|
4536
|
+
selection: newSelection,
|
|
4537
|
+
editor: action.editor
|
|
4538
|
+
}
|
|
4539
|
+
});
|
|
4540
|
+
}, selectPreviousBlockActionImplementation = ({
|
|
4392
4541
|
context,
|
|
4393
4542
|
action
|
|
4394
4543
|
}) => {
|
|
4395
4544
|
if (!action.editor.selection) {
|
|
4396
|
-
console.error("Unable to
|
|
4545
|
+
console.error("Unable to select previous block without a selection");
|
|
4397
4546
|
return;
|
|
4398
4547
|
}
|
|
4399
|
-
const
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
}))[0] ?? [void 0, void 0];
|
|
4403
|
-
if (!focusBlock || !focusBlockPath) {
|
|
4404
|
-
console.error("Unable to perform action without focus block", action);
|
|
4548
|
+
const blockPath = action.editor.selection.focus.path.slice(0, 1);
|
|
4549
|
+
if (!slate.Path.hasPrevious(blockPath)) {
|
|
4550
|
+
console.error("There's no previous block to select");
|
|
4405
4551
|
return;
|
|
4406
4552
|
}
|
|
4407
|
-
const
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
}
|
|
4415
|
-
|
|
4416
|
-
_key: context.keyGenerator(),
|
|
4417
|
-
text: action.text,
|
|
4418
|
-
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
|
|
4419
|
-
});
|
|
4420
|
-
}, insertBlockActionImplementation = ({
|
|
4421
|
-
context,
|
|
4422
|
-
action
|
|
4423
|
-
}) => {
|
|
4424
|
-
const parsedBlock = util_blockOffsetsToSelection.parseBlock({
|
|
4425
|
-
block: action.block,
|
|
4553
|
+
const position = action.select === "end" ? slate.Editor.end(action.editor, slate.Path.previous(blockPath)) : slate.Editor.start(action.editor, slate.Path.previous(blockPath)), newSelection = toPortableTextRange(action.editor.children, {
|
|
4554
|
+
anchor: position,
|
|
4555
|
+
focus: position
|
|
4556
|
+
}, context.schema);
|
|
4557
|
+
if (!newSelection) {
|
|
4558
|
+
console.error("Could not find selection for previous block");
|
|
4559
|
+
return;
|
|
4560
|
+
}
|
|
4561
|
+
selectActionImplementation({
|
|
4426
4562
|
context,
|
|
4563
|
+
action: {
|
|
4564
|
+
type: "select",
|
|
4565
|
+
selection: newSelection,
|
|
4566
|
+
editor: action.editor
|
|
4567
|
+
}
|
|
4568
|
+
});
|
|
4569
|
+
}, insertBlocksActionImplementation = ({
|
|
4570
|
+
context,
|
|
4571
|
+
action
|
|
4572
|
+
}) => {
|
|
4573
|
+
const parsedBlocks = parseBlocks.parseBlocks({
|
|
4574
|
+
context,
|
|
4575
|
+
blocks: action.blocks,
|
|
4427
4576
|
options: {
|
|
4428
4577
|
refreshKeys: !1
|
|
4429
4578
|
}
|
|
4430
4579
|
});
|
|
4431
|
-
if (
|
|
4432
|
-
throw new Error(`Failed to parse
|
|
4433
|
-
const fragment = toSlateValue(
|
|
4580
|
+
if (parsedBlocks.length === 0)
|
|
4581
|
+
throw new Error(`Failed to parse blocks ${JSON.stringify(action.blocks)}`);
|
|
4582
|
+
const fragment = toSlateValue(parsedBlocks, {
|
|
4434
4583
|
schemaTypes: context.schema
|
|
4435
|
-
})
|
|
4436
|
-
if (
|
|
4437
|
-
throw new Error(`Failed to convert
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4584
|
+
});
|
|
4585
|
+
if (fragment.length === 0)
|
|
4586
|
+
throw new Error(`Failed to convert blocks to Slate fragment ${JSON.stringify(parsedBlocks)}`);
|
|
4587
|
+
const [focusBlock] = getFocusBlock({
|
|
4588
|
+
editor: action.editor
|
|
4589
|
+
});
|
|
4590
|
+
if (action.placement === "before") {
|
|
4591
|
+
let index = 0;
|
|
4592
|
+
for (const block of fragment)
|
|
4593
|
+
insertBlock({
|
|
4594
|
+
block,
|
|
4595
|
+
placement: index === 0 ? "before" : "after",
|
|
4596
|
+
select: "end",
|
|
4597
|
+
editor: action.editor,
|
|
4598
|
+
schema: context.schema
|
|
4599
|
+
}), index++;
|
|
4600
|
+
} else if (action.placement === "after")
|
|
4601
|
+
for (const block of fragment)
|
|
4602
|
+
insertBlock({
|
|
4603
|
+
block,
|
|
4604
|
+
placement: "after",
|
|
4605
|
+
select: "end",
|
|
4606
|
+
editor: action.editor,
|
|
4607
|
+
schema: context.schema
|
|
4608
|
+
});
|
|
4609
|
+
else if (focusBlock && action.editor.isTextBlock(focusBlock)) {
|
|
4610
|
+
if (fragment.length === 1) {
|
|
4611
|
+
insertBlock({
|
|
4612
|
+
block: fragment[0],
|
|
4613
|
+
placement: "auto",
|
|
4614
|
+
select: "end",
|
|
4615
|
+
editor: action.editor,
|
|
4616
|
+
schema: context.schema
|
|
4617
|
+
});
|
|
4618
|
+
return;
|
|
4619
|
+
}
|
|
4620
|
+
let index = 0;
|
|
4621
|
+
for (const block of fragment)
|
|
4622
|
+
index === 0 ? (insertBreakActionImplementation({
|
|
4623
|
+
context,
|
|
4624
|
+
action: {
|
|
4625
|
+
type: "insert.break",
|
|
4626
|
+
editor: action.editor
|
|
4627
|
+
}
|
|
4628
|
+
}), selectPreviousBlockActionImplementation({
|
|
4629
|
+
context,
|
|
4630
|
+
action: {
|
|
4631
|
+
type: "select.previous block",
|
|
4632
|
+
editor: action.editor,
|
|
4633
|
+
select: "end"
|
|
4634
|
+
}
|
|
4635
|
+
}), insertBlock({
|
|
4636
|
+
block,
|
|
4637
|
+
placement: "auto",
|
|
4638
|
+
select: "end",
|
|
4639
|
+
editor: action.editor,
|
|
4640
|
+
schema: context.schema
|
|
4641
|
+
})) : index === fragment.length - 1 ? (selectNextBlockActionImplementation({
|
|
4642
|
+
context,
|
|
4643
|
+
action: {
|
|
4644
|
+
type: "select.next block",
|
|
4645
|
+
editor: action.editor,
|
|
4646
|
+
select: "start"
|
|
4647
|
+
}
|
|
4648
|
+
}), insertBlock({
|
|
4649
|
+
block,
|
|
4650
|
+
placement: "auto",
|
|
4651
|
+
select: "end",
|
|
4652
|
+
editor: action.editor,
|
|
4653
|
+
schema: context.schema
|
|
4654
|
+
})) : insertBlock({
|
|
4655
|
+
block,
|
|
4656
|
+
placement: "after",
|
|
4657
|
+
select: "end",
|
|
4658
|
+
editor: action.editor,
|
|
4659
|
+
schema: context.schema
|
|
4660
|
+
}), index++;
|
|
4661
|
+
} else
|
|
4662
|
+
for (const block of fragment)
|
|
4663
|
+
insertBlock({
|
|
4664
|
+
block,
|
|
4665
|
+
placement: "auto",
|
|
4666
|
+
select: "end",
|
|
4667
|
+
editor: action.editor,
|
|
4668
|
+
schema: context.schema
|
|
4669
|
+
});
|
|
4670
|
+
}, deserializationSuccessActionImplementation = ({
|
|
4671
|
+
context,
|
|
4672
|
+
action
|
|
4673
|
+
}) => {
|
|
4674
|
+
insertBlocksActionImplementation({
|
|
4675
|
+
context,
|
|
4676
|
+
action: {
|
|
4677
|
+
type: "insert.blocks",
|
|
4678
|
+
blocks: action.data,
|
|
4679
|
+
editor: action.editor,
|
|
4680
|
+
placement: "auto"
|
|
4681
|
+
}
|
|
4682
|
+
});
|
|
4683
|
+
}, effectActionImplementation = ({
|
|
4684
|
+
action
|
|
4685
|
+
}) => {
|
|
4686
|
+
action.effect();
|
|
4687
|
+
}, focusActionImplementation = ({
|
|
4688
|
+
action
|
|
4689
|
+
}) => {
|
|
4690
|
+
slateReact.ReactEditor.focus(action.editor);
|
|
4691
|
+
}, insertInlineObjectActionImplementation = ({
|
|
4692
|
+
context,
|
|
4693
|
+
action
|
|
4694
|
+
}) => {
|
|
4695
|
+
if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
|
|
4696
|
+
console.error("Unable to insert unknown inline object");
|
|
4697
|
+
return;
|
|
4698
|
+
}
|
|
4699
|
+
if (!action.editor.selection) {
|
|
4700
|
+
console.error("Unable to insert inline object without selection");
|
|
4701
|
+
return;
|
|
4702
|
+
}
|
|
4703
|
+
const [focusTextBlock] = Array.from(slate.Editor.nodes(action.editor, {
|
|
4704
|
+
at: action.editor.selection.focus.path,
|
|
4705
|
+
match: (node) => action.editor.isTextBlock(node)
|
|
4706
|
+
})).at(0) ?? [void 0, void 0];
|
|
4707
|
+
if (!focusTextBlock) {
|
|
4708
|
+
console.error("Unable to perform action without focus text block");
|
|
4709
|
+
return;
|
|
4710
|
+
}
|
|
4711
|
+
const child = toSlateValue([{
|
|
4712
|
+
_type: context.schema.block.name,
|
|
4713
|
+
_key: context.keyGenerator(),
|
|
4714
|
+
children: [{
|
|
4715
|
+
_type: action.inlineObject.name,
|
|
4716
|
+
_key: context.keyGenerator(),
|
|
4717
|
+
...action.inlineObject.value ?? {}
|
|
4718
|
+
}]
|
|
4719
|
+
}], {
|
|
4720
|
+
schemaTypes: context.schema
|
|
4721
|
+
}).at(0)?.children.at(0);
|
|
4722
|
+
if (!child) {
|
|
4723
|
+
console.error("Unable to insert inline object");
|
|
4724
|
+
return;
|
|
4725
|
+
}
|
|
4726
|
+
slate.Transforms.insertNodes(action.editor, child);
|
|
4727
|
+
}, insertSpanActionImplementation = ({
|
|
4728
|
+
context,
|
|
4729
|
+
action
|
|
4730
|
+
}) => {
|
|
4731
|
+
if (!action.editor.selection) {
|
|
4732
|
+
console.error("Unable to perform action without selection", action);
|
|
4733
|
+
return;
|
|
4734
|
+
}
|
|
4735
|
+
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(action.editor, {
|
|
4736
|
+
at: action.editor.selection.focus.path,
|
|
4737
|
+
match: (node) => action.editor.isTextBlock(node)
|
|
4738
|
+
}))[0] ?? [void 0, void 0];
|
|
4739
|
+
if (!focusBlock || !focusBlockPath) {
|
|
4740
|
+
console.error("Unable to perform action without focus block", action);
|
|
4741
|
+
return;
|
|
4742
|
+
}
|
|
4743
|
+
const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
|
|
4744
|
+
_type: annotation.name,
|
|
4745
|
+
_key: context.keyGenerator(),
|
|
4746
|
+
...annotation.value
|
|
4747
|
+
})) : void 0;
|
|
4748
|
+
annotations && annotations.length > 0 && slate.Transforms.setNodes(action.editor, {
|
|
4749
|
+
markDefs: [...markDefs, ...annotations]
|
|
4750
|
+
}), slate.Transforms.insertNodes(action.editor, {
|
|
4751
|
+
_type: "span",
|
|
4752
|
+
_key: context.keyGenerator(),
|
|
4753
|
+
text: action.text,
|
|
4754
|
+
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
|
|
4755
|
+
});
|
|
4756
|
+
}, insertBlockObjectActionImplementation = ({
|
|
4757
|
+
context,
|
|
4758
|
+
action
|
|
4759
|
+
}) => {
|
|
4760
|
+
insertBlockActionImplementation({
|
|
4761
|
+
context,
|
|
4762
|
+
action: {
|
|
4763
|
+
type: "insert.block",
|
|
4764
|
+
block: {
|
|
4765
|
+
_key: context.keyGenerator(),
|
|
4766
|
+
_type: action.blockObject.name,
|
|
4767
|
+
...action.blockObject.value ? action.blockObject.value : {}
|
|
4768
|
+
},
|
|
4769
|
+
editor: action.editor,
|
|
4770
|
+
placement: action.placement
|
|
4771
|
+
}
|
|
4772
|
+
});
|
|
4773
|
+
}, insertTextActionImplementation = ({
|
|
4774
|
+
action
|
|
4775
|
+
}) => {
|
|
4776
|
+
action.editor.insertText(action.text);
|
|
4777
|
+
}, insertTextBlockActionImplementation = ({
|
|
4778
|
+
context,
|
|
4779
|
+
action
|
|
4780
|
+
}) => {
|
|
4781
|
+
insertBlockActionImplementation({
|
|
4782
|
+
context,
|
|
4783
|
+
action: {
|
|
4784
|
+
type: "insert.block",
|
|
4785
|
+
block: {
|
|
4786
|
+
_key: context.keyGenerator(),
|
|
4787
|
+
_type: context.schema.block.name,
|
|
4788
|
+
children: action.textBlock?.children?.map((child) => ({
|
|
4789
|
+
...child,
|
|
4790
|
+
_key: context.keyGenerator()
|
|
4791
|
+
})) ?? [{
|
|
4792
|
+
_type: context.schema.span.name,
|
|
4793
|
+
_key: context.keyGenerator(),
|
|
4794
|
+
text: "",
|
|
4795
|
+
marks: []
|
|
4796
|
+
}],
|
|
4797
|
+
markDefs: [],
|
|
4798
|
+
style: context.schema.styles[0].value ?? "normal"
|
|
4799
|
+
},
|
|
4800
|
+
editor: action.editor,
|
|
4801
|
+
placement: action.placement,
|
|
4802
|
+
select: "start"
|
|
4803
|
+
}
|
|
4804
|
+
});
|
|
4805
|
+
}, moveBlockActionImplementation = ({
|
|
4806
|
+
action
|
|
4807
|
+
}) => {
|
|
4808
|
+
const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
|
|
4809
|
+
slate.Transforms.moveNodes(action.editor, {
|
|
4810
|
+
at,
|
|
4811
|
+
to,
|
|
4812
|
+
mode: "highest"
|
|
4813
|
+
});
|
|
4814
|
+
}, moveBlockDownActionImplementation = ({
|
|
4815
|
+
context,
|
|
4816
|
+
action
|
|
4817
|
+
}) => {
|
|
4818
|
+
const at = [toSlatePath(action.at, action.editor)[0]], to = [slate.Path.next(at)[0]], selection = toPortableTextRange(action.editor.children, {
|
|
4819
|
+
anchor: {
|
|
4820
|
+
path: to,
|
|
4821
|
+
offset: 0
|
|
4822
|
+
},
|
|
4823
|
+
focus: {
|
|
4824
|
+
path: to,
|
|
4825
|
+
offset: 0
|
|
4826
|
+
}
|
|
4827
|
+
}, context.schema), destinationBlockKey = selection && util_sliceBlocks.isKeyedSegment(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
|
|
4828
|
+
if (destinationBlockKey === void 0) {
|
|
4829
|
+
console.error("Could not find destination block key");
|
|
4830
|
+
return;
|
|
4831
|
+
}
|
|
4832
|
+
moveBlockActionImplementation({
|
|
4833
|
+
context,
|
|
4834
|
+
action: {
|
|
4835
|
+
type: "move.block",
|
|
4836
|
+
at: action.at,
|
|
4837
|
+
to: [{
|
|
4838
|
+
_key: destinationBlockKey
|
|
4839
|
+
}],
|
|
4840
|
+
editor: action.editor
|
|
4841
|
+
}
|
|
4842
|
+
});
|
|
4843
|
+
}, moveBlockUpActionImplementation = ({
|
|
4844
|
+
context,
|
|
4845
|
+
action
|
|
4846
|
+
}) => {
|
|
4847
|
+
const at = [toSlatePath(action.at, action.editor)[0]];
|
|
4848
|
+
if (!slate.Path.hasPrevious(at))
|
|
4849
|
+
return;
|
|
4850
|
+
const to = [slate.Path.previous(at)[0]], selection = toPortableTextRange(action.editor.children, {
|
|
4851
|
+
anchor: {
|
|
4852
|
+
path: to,
|
|
4853
|
+
offset: 0
|
|
4854
|
+
},
|
|
4855
|
+
focus: {
|
|
4856
|
+
path: to,
|
|
4857
|
+
offset: 0
|
|
4858
|
+
}
|
|
4859
|
+
}, context.schema), destinationBlockKey = selection && util_sliceBlocks.isKeyedSegment(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
|
|
4860
|
+
if (destinationBlockKey === void 0) {
|
|
4861
|
+
console.error("Could not find destination block key");
|
|
4862
|
+
return;
|
|
4863
|
+
}
|
|
4864
|
+
moveBlockActionImplementation({
|
|
4865
|
+
context,
|
|
4866
|
+
action: {
|
|
4867
|
+
type: "move.block",
|
|
4868
|
+
at: action.at,
|
|
4869
|
+
to: [{
|
|
4870
|
+
_key: destinationBlockKey
|
|
4871
|
+
}],
|
|
4872
|
+
editor: action.editor
|
|
4873
|
+
}
|
|
4874
|
+
});
|
|
4875
|
+
}, noopActionImplementation = () => {
|
|
4876
|
+
}, serializationFailureActionImplementation = ({
|
|
4877
|
+
action
|
|
4878
|
+
}) => {
|
|
4879
|
+
console.warn(`Serialization of ${action.mimeType} failed with reason "${action.reason}"`);
|
|
4880
|
+
}, serializationSuccessActionImplementation = ({
|
|
4881
|
+
context,
|
|
4882
|
+
action
|
|
4883
|
+
}) => {
|
|
4884
|
+
dataTransferSetActionImplementation({
|
|
4885
|
+
context,
|
|
4886
|
+
action: {
|
|
4887
|
+
...action,
|
|
4888
|
+
type: "data transfer.set"
|
|
4889
|
+
}
|
|
4443
4890
|
});
|
|
4444
4891
|
}, behaviorActionImplementations = {
|
|
4445
4892
|
"annotation.add": addAnnotationActionImplementation,
|
|
@@ -4447,72 +4894,19 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4447
4894
|
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
4448
4895
|
"block.set": blockSetBehaviorActionImplementation,
|
|
4449
4896
|
"block.unset": blockUnsetBehaviorActionImplementation,
|
|
4450
|
-
blur:
|
|
4451
|
-
action
|
|
4452
|
-
}) => {
|
|
4453
|
-
slateReact.ReactEditor.blur(action.editor);
|
|
4454
|
-
},
|
|
4897
|
+
blur: blurActionImplementation,
|
|
4455
4898
|
"data transfer.set": dataTransferSetActionImplementation,
|
|
4456
4899
|
"decorator.add": decoratorAddActionImplementation,
|
|
4457
4900
|
"decorator.remove": removeDecoratorActionImplementation,
|
|
4458
4901
|
"decorator.toggle": toggleDecoratorActionImplementation,
|
|
4459
|
-
focus:
|
|
4460
|
-
action
|
|
4461
|
-
}) => {
|
|
4462
|
-
slateReact.ReactEditor.focus(action.editor);
|
|
4463
|
-
},
|
|
4902
|
+
focus: focusActionImplementation,
|
|
4464
4903
|
delete: deleteActionImplementation,
|
|
4465
|
-
"delete.backward":
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
action.editor.deleteBackward(action.unit);
|
|
4469
|
-
},
|
|
4470
|
-
"delete.forward": ({
|
|
4471
|
-
action
|
|
4472
|
-
}) => {
|
|
4473
|
-
slate.deleteForward(action.editor, action.unit);
|
|
4474
|
-
},
|
|
4475
|
-
"delete.block": ({
|
|
4476
|
-
action
|
|
4477
|
-
}) => {
|
|
4478
|
-
const range = toSlateRange({
|
|
4479
|
-
anchor: {
|
|
4480
|
-
path: action.blockPath,
|
|
4481
|
-
offset: 0
|
|
4482
|
-
},
|
|
4483
|
-
focus: {
|
|
4484
|
-
path: action.blockPath,
|
|
4485
|
-
offset: 0
|
|
4486
|
-
}
|
|
4487
|
-
}, action.editor);
|
|
4488
|
-
if (!range) {
|
|
4489
|
-
console.error("Unable to find Slate range from selection points");
|
|
4490
|
-
return;
|
|
4491
|
-
}
|
|
4492
|
-
slate.Transforms.removeNodes(action.editor, {
|
|
4493
|
-
at: range
|
|
4494
|
-
});
|
|
4495
|
-
},
|
|
4904
|
+
"delete.backward": deleteBackwardActionImplementation,
|
|
4905
|
+
"delete.forward": deleteForwardActionImplementation,
|
|
4906
|
+
"delete.block": deleteBlockActionImplementation,
|
|
4496
4907
|
"delete.text": deleteTextActionImplementation,
|
|
4497
|
-
"deserialization.failure":
|
|
4498
|
-
|
|
4499
|
-
}) => {
|
|
4500
|
-
console.warn(`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`);
|
|
4501
|
-
},
|
|
4502
|
-
"deserialization.success": ({
|
|
4503
|
-
context,
|
|
4504
|
-
action
|
|
4505
|
-
}) => {
|
|
4506
|
-
insertBlocksActionImplementation({
|
|
4507
|
-
context,
|
|
4508
|
-
action: {
|
|
4509
|
-
type: "insert.blocks",
|
|
4510
|
-
blocks: action.data,
|
|
4511
|
-
editor: action.editor,
|
|
4512
|
-
placement: "auto"
|
|
4513
|
-
}
|
|
4514
|
-
});
|
|
4515
|
-
},
|
|
4908
|
+
"deserialization.failure": deserializationFailureActionImplementation,
|
|
4909
|
+
"deserialization.success": deserializationSuccessActionImplementation,
|
|
4516
4910
|
"history.redo": historyRedoActionImplementation,
|
|
4517
4911
|
"history.undo": historyUndoActionImplementation,
|
|
4518
4912
|
"insert.block": insertBlockActionImplementation,
|
|
@@ -4522,129 +4916,21 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4522
4916
|
"insert.inline object": insertInlineObjectActionImplementation,
|
|
4523
4917
|
"insert.soft break": insertSoftBreakActionImplementation,
|
|
4524
4918
|
"insert.span": insertSpanActionImplementation,
|
|
4525
|
-
"insert.text":
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
slate.insertText(action.editor, action.text);
|
|
4529
|
-
},
|
|
4530
|
-
"insert.text block": ({
|
|
4531
|
-
context,
|
|
4532
|
-
action
|
|
4533
|
-
}) => {
|
|
4534
|
-
const block = toSlateValue([{
|
|
4535
|
-
_key: context.keyGenerator(),
|
|
4536
|
-
_type: context.schema.block.name,
|
|
4537
|
-
style: context.schema.styles[0].value ?? "normal",
|
|
4538
|
-
markDefs: [],
|
|
4539
|
-
children: action.textBlock?.children?.map((child) => ({
|
|
4540
|
-
...child,
|
|
4541
|
-
_key: context.keyGenerator()
|
|
4542
|
-
})) ?? [{
|
|
4543
|
-
_type: context.schema.span.name,
|
|
4544
|
-
_key: context.keyGenerator(),
|
|
4545
|
-
text: ""
|
|
4546
|
-
}]
|
|
4547
|
-
}], {
|
|
4548
|
-
schemaTypes: context.schema
|
|
4549
|
-
})[0];
|
|
4550
|
-
insertBlock({
|
|
4551
|
-
block,
|
|
4552
|
-
editor: action.editor,
|
|
4553
|
-
schema: context.schema,
|
|
4554
|
-
placement: action.placement
|
|
4555
|
-
});
|
|
4556
|
-
},
|
|
4557
|
-
effect: ({
|
|
4558
|
-
action
|
|
4559
|
-
}) => {
|
|
4560
|
-
action.effect();
|
|
4561
|
-
},
|
|
4919
|
+
"insert.text": insertTextActionImplementation,
|
|
4920
|
+
"insert.text block": insertTextBlockActionImplementation,
|
|
4921
|
+
effect: effectActionImplementation,
|
|
4562
4922
|
"list item.add": addListItemActionImplementation,
|
|
4563
4923
|
"list item.remove": removeListItemActionImplementation,
|
|
4564
4924
|
"list item.toggle": toggleListItemActionImplementation,
|
|
4565
|
-
"move.block":
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
},
|
|
4575
|
-
"move.block down": ({
|
|
4576
|
-
action
|
|
4577
|
-
}) => {
|
|
4578
|
-
const at = [toSlatePath(action.at, action.editor)[0]], to = [slate.Path.next(at)[0]];
|
|
4579
|
-
slate.Transforms.moveNodes(action.editor, {
|
|
4580
|
-
at,
|
|
4581
|
-
to,
|
|
4582
|
-
mode: "highest"
|
|
4583
|
-
});
|
|
4584
|
-
},
|
|
4585
|
-
"move.block up": ({
|
|
4586
|
-
action
|
|
4587
|
-
}) => {
|
|
4588
|
-
const at = [toSlatePath(action.at, action.editor)[0]];
|
|
4589
|
-
if (!slate.Path.hasPrevious(at))
|
|
4590
|
-
return;
|
|
4591
|
-
const to = [slate.Path.previous(at)[0]];
|
|
4592
|
-
slate.Transforms.moveNodes(action.editor, {
|
|
4593
|
-
at,
|
|
4594
|
-
to,
|
|
4595
|
-
mode: "highest"
|
|
4596
|
-
});
|
|
4597
|
-
},
|
|
4598
|
-
noop: () => {
|
|
4599
|
-
},
|
|
4600
|
-
select: ({
|
|
4601
|
-
action
|
|
4602
|
-
}) => {
|
|
4603
|
-
const newSelection = toSlateRange(action.selection, action.editor);
|
|
4604
|
-
newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
|
|
4605
|
-
},
|
|
4606
|
-
"select.previous block": ({
|
|
4607
|
-
action
|
|
4608
|
-
}) => {
|
|
4609
|
-
if (!action.editor.selection) {
|
|
4610
|
-
console.error("Unable to select previous block without a selection");
|
|
4611
|
-
return;
|
|
4612
|
-
}
|
|
4613
|
-
const blockPath = action.editor.selection.focus.path.slice(0, 1);
|
|
4614
|
-
if (!slate.Path.hasPrevious(blockPath)) {
|
|
4615
|
-
console.error("There's no previous block to select");
|
|
4616
|
-
return;
|
|
4617
|
-
}
|
|
4618
|
-
const previousBlockPath = slate.Path.previous(blockPath);
|
|
4619
|
-
slate.Transforms.select(action.editor, previousBlockPath);
|
|
4620
|
-
},
|
|
4621
|
-
"select.next block": ({
|
|
4622
|
-
action
|
|
4623
|
-
}) => {
|
|
4624
|
-
if (!action.editor.selection) {
|
|
4625
|
-
console.error("Unable to select next block without a selection");
|
|
4626
|
-
return;
|
|
4627
|
-
}
|
|
4628
|
-
const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
|
|
4629
|
-
slate.Transforms.select(action.editor, nextBlockPath);
|
|
4630
|
-
},
|
|
4631
|
-
"serialization.failure": ({
|
|
4632
|
-
action
|
|
4633
|
-
}) => {
|
|
4634
|
-
console.warn(`Serialization of ${action.mimeType} failed with reason "${action.reason}"`);
|
|
4635
|
-
},
|
|
4636
|
-
"serialization.success": ({
|
|
4637
|
-
context,
|
|
4638
|
-
action
|
|
4639
|
-
}) => {
|
|
4640
|
-
dataTransferSetActionImplementation({
|
|
4641
|
-
context,
|
|
4642
|
-
action: {
|
|
4643
|
-
...action,
|
|
4644
|
-
type: "data transfer.set"
|
|
4645
|
-
}
|
|
4646
|
-
});
|
|
4647
|
-
},
|
|
4925
|
+
"move.block": moveBlockActionImplementation,
|
|
4926
|
+
"move.block down": moveBlockDownActionImplementation,
|
|
4927
|
+
"move.block up": moveBlockUpActionImplementation,
|
|
4928
|
+
noop: noopActionImplementation,
|
|
4929
|
+
select: selectActionImplementation,
|
|
4930
|
+
"select.previous block": selectPreviousBlockActionImplementation,
|
|
4931
|
+
"select.next block": selectNextBlockActionImplementation,
|
|
4932
|
+
"serialization.failure": serializationFailureActionImplementation,
|
|
4933
|
+
"serialization.success": serializationSuccessActionImplementation,
|
|
4648
4934
|
"style.toggle": toggleStyleActionImplementation,
|
|
4649
4935
|
"style.add": addStyleActionImplementation,
|
|
4650
4936
|
"style.remove": removeStyleActionImplementation
|
|
@@ -4652,27 +4938,6 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4652
4938
|
function performAction({
|
|
4653
4939
|
context,
|
|
4654
4940
|
action
|
|
4655
|
-
}) {
|
|
4656
|
-
switch (action.type) {
|
|
4657
|
-
case "noop":
|
|
4658
|
-
break;
|
|
4659
|
-
case "effect": {
|
|
4660
|
-
behaviorActionImplementations.effect({
|
|
4661
|
-
context,
|
|
4662
|
-
action
|
|
4663
|
-
});
|
|
4664
|
-
break;
|
|
4665
|
-
}
|
|
4666
|
-
default:
|
|
4667
|
-
performDefaultAction({
|
|
4668
|
-
context,
|
|
4669
|
-
action
|
|
4670
|
-
});
|
|
4671
|
-
}
|
|
4672
|
-
}
|
|
4673
|
-
function performDefaultAction({
|
|
4674
|
-
context,
|
|
4675
|
-
action
|
|
4676
4941
|
}) {
|
|
4677
4942
|
switch (action.type) {
|
|
4678
4943
|
case "annotation.add": {
|
|
@@ -4794,6 +5059,13 @@ function performDefaultAction({
|
|
|
4794
5059
|
});
|
|
4795
5060
|
break;
|
|
4796
5061
|
}
|
|
5062
|
+
case "effect": {
|
|
5063
|
+
behaviorActionImplementations.effect({
|
|
5064
|
+
context,
|
|
5065
|
+
action
|
|
5066
|
+
});
|
|
5067
|
+
break;
|
|
5068
|
+
}
|
|
4797
5069
|
case "focus": {
|
|
4798
5070
|
behaviorActionImplementations.focus({
|
|
4799
5071
|
context,
|
|
@@ -4920,6 +5192,8 @@ function performDefaultAction({
|
|
|
4920
5192
|
});
|
|
4921
5193
|
break;
|
|
4922
5194
|
}
|
|
5195
|
+
case "noop":
|
|
5196
|
+
break;
|
|
4923
5197
|
case "select": {
|
|
4924
5198
|
behaviorActionImplementations.select({
|
|
4925
5199
|
context,
|
|
@@ -5027,10 +5301,8 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5027
5301
|
deleteBackward,
|
|
5028
5302
|
deleteForward,
|
|
5029
5303
|
insertBreak,
|
|
5030
|
-
insertData,
|
|
5031
5304
|
insertText,
|
|
5032
|
-
select
|
|
5033
|
-
setFragmentData
|
|
5305
|
+
select
|
|
5034
5306
|
} = editor;
|
|
5035
5307
|
return editor.deleteBackward = (unit) => {
|
|
5036
5308
|
if (isApplyingBehaviorActions(editor)) {
|
|
@@ -5070,19 +5342,8 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5070
5342
|
},
|
|
5071
5343
|
editor
|
|
5072
5344
|
});
|
|
5073
|
-
}, editor.insertData = (
|
|
5074
|
-
|
|
5075
|
-
insertData(dataTransfer);
|
|
5076
|
-
return;
|
|
5077
|
-
}
|
|
5078
|
-
editorActor.send({
|
|
5079
|
-
type: "behavior event",
|
|
5080
|
-
behaviorEvent: {
|
|
5081
|
-
type: "deserialize",
|
|
5082
|
-
dataTransfer
|
|
5083
|
-
},
|
|
5084
|
-
editor
|
|
5085
|
-
});
|
|
5345
|
+
}, editor.insertData = () => {
|
|
5346
|
+
console.warn("Unexpected call to .insertData(...)");
|
|
5086
5347
|
}, editor.insertSoftBreak = () => {
|
|
5087
5348
|
if (isApplyingBehaviorActions(editor)) {
|
|
5088
5349
|
insertSoftBreakActionImplementation({
|
|
@@ -5159,20 +5420,8 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5159
5420
|
select(location);
|
|
5160
5421
|
}
|
|
5161
5422
|
});
|
|
5162
|
-
}, editor.setFragmentData = (
|
|
5163
|
-
|
|
5164
|
-
setFragmentData(dataTransfer);
|
|
5165
|
-
return;
|
|
5166
|
-
}
|
|
5167
|
-
dataTransfer.clearData(), editorActor.send({
|
|
5168
|
-
type: "behavior event",
|
|
5169
|
-
behaviorEvent: {
|
|
5170
|
-
type: "serialize",
|
|
5171
|
-
dataTransfer,
|
|
5172
|
-
originEvent: originEvent ?? "unknown"
|
|
5173
|
-
},
|
|
5174
|
-
editor
|
|
5175
|
-
});
|
|
5423
|
+
}, editor.setFragmentData = () => {
|
|
5424
|
+
console.warn("Unexpected call to .setFragmentData(...)");
|
|
5176
5425
|
}, editor.undo = () => {
|
|
5177
5426
|
if (isApplyingBehaviorActions(editor)) {
|
|
5178
5427
|
performAction({
|
|
@@ -5886,7 +6135,7 @@ const keyIs = {
|
|
|
5886
6135
|
guard: ({
|
|
5887
6136
|
snapshot,
|
|
5888
6137
|
event
|
|
5889
|
-
}) =>
|
|
6138
|
+
}) => selector_isOverlappingSelection.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5890
6139
|
actions: [({
|
|
5891
6140
|
event
|
|
5892
6141
|
}) => [behavior_core.raise({
|
|
@@ -5898,7 +6147,7 @@ const keyIs = {
|
|
|
5898
6147
|
guard: ({
|
|
5899
6148
|
snapshot,
|
|
5900
6149
|
event
|
|
5901
|
-
}) => !
|
|
6150
|
+
}) => !selector_isOverlappingSelection.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5902
6151
|
actions: [({
|
|
5903
6152
|
event
|
|
5904
6153
|
}) => [behavior_core.raise({
|
|
@@ -5910,7 +6159,7 @@ const keyIs = {
|
|
|
5910
6159
|
guard: ({
|
|
5911
6160
|
snapshot,
|
|
5912
6161
|
event
|
|
5913
|
-
}) =>
|
|
6162
|
+
}) => selector_isOverlappingSelection.isActiveDecorator(event.decorator)(snapshot),
|
|
5914
6163
|
actions: [({
|
|
5915
6164
|
event
|
|
5916
6165
|
}) => [behavior_core.raise({
|
|
@@ -5922,7 +6171,7 @@ const keyIs = {
|
|
|
5922
6171
|
guard: ({
|
|
5923
6172
|
snapshot,
|
|
5924
6173
|
event
|
|
5925
|
-
}) => !
|
|
6174
|
+
}) => !selector_isOverlappingSelection.isActiveDecorator(event.decorator)(snapshot),
|
|
5926
6175
|
actions: [({
|
|
5927
6176
|
event
|
|
5928
6177
|
}) => [behavior_core.raise({
|
|
@@ -5934,7 +6183,7 @@ const keyIs = {
|
|
|
5934
6183
|
guard: ({
|
|
5935
6184
|
snapshot,
|
|
5936
6185
|
event
|
|
5937
|
-
}) =>
|
|
6186
|
+
}) => selector_isOverlappingSelection.isActiveListItem(event.listItem)(snapshot),
|
|
5938
6187
|
actions: [({
|
|
5939
6188
|
event
|
|
5940
6189
|
}) => [behavior_core.raise({
|
|
@@ -5946,7 +6195,7 @@ const keyIs = {
|
|
|
5946
6195
|
guard: ({
|
|
5947
6196
|
snapshot,
|
|
5948
6197
|
event
|
|
5949
|
-
}) => !
|
|
6198
|
+
}) => !selector_isOverlappingSelection.isActiveListItem(event.listItem)(snapshot),
|
|
5950
6199
|
actions: [({
|
|
5951
6200
|
event
|
|
5952
6201
|
}) => [behavior_core.raise({
|
|
@@ -5958,7 +6207,7 @@ const keyIs = {
|
|
|
5958
6207
|
guard: ({
|
|
5959
6208
|
snapshot,
|
|
5960
6209
|
event
|
|
5961
|
-
}) =>
|
|
6210
|
+
}) => selector_isOverlappingSelection.isActiveStyle(event.style)(snapshot),
|
|
5962
6211
|
actions: [({
|
|
5963
6212
|
event
|
|
5964
6213
|
}) => [behavior_core.raise({
|
|
@@ -5970,7 +6219,7 @@ const keyIs = {
|
|
|
5970
6219
|
guard: ({
|
|
5971
6220
|
snapshot,
|
|
5972
6221
|
event
|
|
5973
|
-
}) => !
|
|
6222
|
+
}) => !selector_isOverlappingSelection.isActiveStyle(event.style)(snapshot),
|
|
5974
6223
|
actions: [({
|
|
5975
6224
|
event
|
|
5976
6225
|
}) => [behavior_core.raise({
|
|
@@ -6003,16 +6252,8 @@ const keyIs = {
|
|
|
6003
6252
|
event
|
|
6004
6253
|
}, deserializeEvent) => [behavior_core.raise({
|
|
6005
6254
|
...deserializeEvent,
|
|
6006
|
-
dataTransfer: event.dataTransfer
|
|
6007
|
-
|
|
6008
|
-
}), raiseInsertBlocks = behavior_core.defineBehavior({
|
|
6009
|
-
on: "deserialization.success",
|
|
6010
|
-
actions: [({
|
|
6011
|
-
event
|
|
6012
|
-
}) => [behavior_core.raise({
|
|
6013
|
-
type: "insert.blocks",
|
|
6014
|
-
blocks: event.data,
|
|
6015
|
-
placement: "auto"
|
|
6255
|
+
dataTransfer: event.dataTransfer,
|
|
6256
|
+
originEvent: event.originEvent
|
|
6016
6257
|
})]]
|
|
6017
6258
|
}), raiseSerializationSuccessOrFailure = behavior_core.defineBehavior({
|
|
6018
6259
|
on: "serialize",
|
|
@@ -6024,7 +6265,10 @@ const keyIs = {
|
|
|
6024
6265
|
return !1;
|
|
6025
6266
|
const serializeEvents = snapshot.context.converters.map((converter) => converter.serialize({
|
|
6026
6267
|
snapshot,
|
|
6027
|
-
event
|
|
6268
|
+
event: {
|
|
6269
|
+
...event,
|
|
6270
|
+
originEvent: event.originEvent.type
|
|
6271
|
+
}
|
|
6028
6272
|
}));
|
|
6029
6273
|
return serializeEvents.length === 0 ? !1 : serializeEvents;
|
|
6030
6274
|
},
|
|
@@ -6032,9 +6276,69 @@ const keyIs = {
|
|
|
6032
6276
|
event
|
|
6033
6277
|
}, serializeEvents) => serializeEvents.map((serializeEvent) => behavior_core.raise({
|
|
6034
6278
|
...serializeEvent,
|
|
6279
|
+
originEvent: event.originEvent,
|
|
6035
6280
|
dataTransfer: event.dataTransfer
|
|
6036
6281
|
}))]
|
|
6037
|
-
}),
|
|
6282
|
+
}), defaultBehaviors = [behavior_core.defineBehavior({
|
|
6283
|
+
on: "copy",
|
|
6284
|
+
guard: ({
|
|
6285
|
+
snapshot
|
|
6286
|
+
}) => {
|
|
6287
|
+
const focusSpan = selector_isAtTheStartOfBlock.getFocusSpan(snapshot), selectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed(snapshot);
|
|
6288
|
+
return focusSpan && selectionCollapsed;
|
|
6289
|
+
},
|
|
6290
|
+
actions: [() => [{
|
|
6291
|
+
type: "noop"
|
|
6292
|
+
}]]
|
|
6293
|
+
}), behavior_core.defineBehavior({
|
|
6294
|
+
on: "copy",
|
|
6295
|
+
actions: [({
|
|
6296
|
+
event
|
|
6297
|
+
}) => [behavior_core.raise({
|
|
6298
|
+
type: "serialize",
|
|
6299
|
+
dataTransfer: event.data,
|
|
6300
|
+
originEvent: event
|
|
6301
|
+
})]]
|
|
6302
|
+
}), behavior_core.defineBehavior({
|
|
6303
|
+
on: "cut",
|
|
6304
|
+
guard: ({
|
|
6305
|
+
snapshot
|
|
6306
|
+
}) => {
|
|
6307
|
+
const focusSpan = selector_isAtTheStartOfBlock.getFocusSpan(snapshot), selectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed(snapshot);
|
|
6308
|
+
return focusSpan && selectionCollapsed;
|
|
6309
|
+
},
|
|
6310
|
+
actions: [() => [{
|
|
6311
|
+
type: "noop"
|
|
6312
|
+
}]]
|
|
6313
|
+
}), behavior_core.defineBehavior({
|
|
6314
|
+
on: "cut",
|
|
6315
|
+
guard: ({
|
|
6316
|
+
snapshot
|
|
6317
|
+
}) => snapshot.context.selection ? {
|
|
6318
|
+
selection: snapshot.context.selection
|
|
6319
|
+
} : !1,
|
|
6320
|
+
actions: [({
|
|
6321
|
+
event
|
|
6322
|
+
}, {
|
|
6323
|
+
selection
|
|
6324
|
+
}) => [behavior_core.raise({
|
|
6325
|
+
type: "serialize",
|
|
6326
|
+
dataTransfer: event.dataTransfer,
|
|
6327
|
+
originEvent: event
|
|
6328
|
+
}), behavior_core.raise({
|
|
6329
|
+
type: "delete",
|
|
6330
|
+
selection
|
|
6331
|
+
})]]
|
|
6332
|
+
}), behavior_core.defineBehavior({
|
|
6333
|
+
on: "drag.dragstart",
|
|
6334
|
+
actions: [({
|
|
6335
|
+
event
|
|
6336
|
+
}) => [behavior_core.raise({
|
|
6337
|
+
type: "serialize",
|
|
6338
|
+
dataTransfer: event.dataTransfer,
|
|
6339
|
+
originEvent: event
|
|
6340
|
+
})]]
|
|
6341
|
+
}), behavior_core.defineBehavior({
|
|
6038
6342
|
on: "serialization.success",
|
|
6039
6343
|
actions: [({
|
|
6040
6344
|
event
|
|
@@ -6044,22 +6348,129 @@ const keyIs = {
|
|
|
6044
6348
|
dataTransfer: event.dataTransfer,
|
|
6045
6349
|
mimeType: event.mimeType
|
|
6046
6350
|
})]]
|
|
6047
|
-
}),
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6351
|
+
}), behavior_core.defineBehavior({
|
|
6352
|
+
on: "drag.drop",
|
|
6353
|
+
guard: ({
|
|
6354
|
+
snapshot,
|
|
6355
|
+
event
|
|
6356
|
+
}) => {
|
|
6357
|
+
const dragOrigin = snapshot.beta.internalDrag?.origin, dropPosition = event.position.selection;
|
|
6358
|
+
return dragOrigin ? selector_isOverlappingSelection.isOverlappingSelection(dropPosition)({
|
|
6359
|
+
...snapshot,
|
|
6360
|
+
context: {
|
|
6361
|
+
...snapshot.context,
|
|
6362
|
+
selection: dragOrigin.selection
|
|
6363
|
+
}
|
|
6364
|
+
}) : !1;
|
|
6365
|
+
},
|
|
6366
|
+
actions: [() => [{
|
|
6367
|
+
type: "noop"
|
|
6368
|
+
}]]
|
|
6369
|
+
}), behavior_core.defineBehavior({
|
|
6370
|
+
on: "drag.drop",
|
|
6371
|
+
actions: [({
|
|
6372
|
+
event
|
|
6373
|
+
}) => [behavior_core.raise({
|
|
6374
|
+
type: "deserialize",
|
|
6375
|
+
dataTransfer: event.dataTransfer,
|
|
6376
|
+
originEvent: event
|
|
6377
|
+
})]]
|
|
6378
|
+
}), behavior_core.defineBehavior({
|
|
6379
|
+
on: "deserialization.success",
|
|
6380
|
+
guard: ({
|
|
6381
|
+
snapshot,
|
|
6382
|
+
event
|
|
6383
|
+
}) => {
|
|
6384
|
+
if (event.originEvent.type !== "drag.drop" || snapshot.beta.internalDrag === void 0)
|
|
6385
|
+
return !1;
|
|
6386
|
+
const dragOrigin = snapshot.beta.internalDrag.origin, dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? selector_isOverlappingSelection.isOverlappingSelection(dropPosition)({
|
|
6387
|
+
...snapshot,
|
|
6388
|
+
context: {
|
|
6389
|
+
...snapshot.context,
|
|
6390
|
+
selection: dragOrigin.selection
|
|
6391
|
+
}
|
|
6392
|
+
}) : !1, draggingEntireBlocks = selector_isOverlappingSelection.isSelectingEntireBlocks({
|
|
6393
|
+
...snapshot,
|
|
6394
|
+
context: {
|
|
6395
|
+
...snapshot.context,
|
|
6396
|
+
selection: dragOrigin.selection
|
|
6397
|
+
}
|
|
6398
|
+
}), draggedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks({
|
|
6399
|
+
...snapshot,
|
|
6400
|
+
context: {
|
|
6401
|
+
...snapshot.context,
|
|
6402
|
+
selection: dragOrigin.selection
|
|
6403
|
+
}
|
|
6404
|
+
});
|
|
6405
|
+
return droppingOnDragOrigin ? !1 : {
|
|
6406
|
+
draggingEntireBlocks,
|
|
6407
|
+
draggedBlocks,
|
|
6408
|
+
dragOrigin
|
|
6409
|
+
};
|
|
6410
|
+
},
|
|
6411
|
+
actions: [({
|
|
6412
|
+
event
|
|
6413
|
+
}, {
|
|
6414
|
+
draggingEntireBlocks,
|
|
6415
|
+
draggedBlocks,
|
|
6416
|
+
dragOrigin
|
|
6417
|
+
}) => [behavior_core.raise({
|
|
6418
|
+
type: "insert.blocks",
|
|
6419
|
+
blocks: event.data,
|
|
6420
|
+
placement: draggingEntireBlocks ? event.originEvent.position.block === "start" ? "before" : event.originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
6421
|
+
}), ...draggingEntireBlocks ? draggedBlocks.map((block) => behavior_core.raise({
|
|
6422
|
+
type: "delete.block",
|
|
6423
|
+
blockPath: block.path
|
|
6424
|
+
})) : [behavior_core.raise({
|
|
6425
|
+
type: "delete",
|
|
6426
|
+
selection: dragOrigin.selection
|
|
6427
|
+
})]]]
|
|
6428
|
+
}), behavior_core.defineBehavior({
|
|
6429
|
+
on: "deserialization.success",
|
|
6430
|
+
actions: [({
|
|
6431
|
+
event
|
|
6432
|
+
}) => [behavior_core.raise({
|
|
6433
|
+
type: "insert.blocks",
|
|
6434
|
+
blocks: event.data,
|
|
6435
|
+
placement: "auto"
|
|
6436
|
+
})]]
|
|
6437
|
+
}), behavior_core.defineBehavior({
|
|
6438
|
+
on: "paste",
|
|
6439
|
+
guard: ({
|
|
6440
|
+
snapshot
|
|
6441
|
+
}) => snapshot.context.selection && selector_isAtTheStartOfBlock.isSelectionExpanded(snapshot) ? {
|
|
6442
|
+
selection: snapshot.context.selection
|
|
6443
|
+
} : !1,
|
|
6444
|
+
actions: [({
|
|
6445
|
+
event
|
|
6446
|
+
}, {
|
|
6447
|
+
selection
|
|
6448
|
+
}) => [behavior_core.raise({
|
|
6449
|
+
type: "delete",
|
|
6450
|
+
selection
|
|
6451
|
+
}), behavior_core.raise({
|
|
6452
|
+
type: "deserialize",
|
|
6453
|
+
dataTransfer: event.data,
|
|
6454
|
+
originEvent: event
|
|
6455
|
+
})]]
|
|
6456
|
+
}), behavior_core.defineBehavior({
|
|
6457
|
+
on: "paste",
|
|
6458
|
+
actions: [({
|
|
6459
|
+
event
|
|
6460
|
+
}) => [behavior_core.raise({
|
|
6461
|
+
type: "deserialize",
|
|
6462
|
+
dataTransfer: event.data,
|
|
6463
|
+
originEvent: event
|
|
6464
|
+
})]]
|
|
6465
|
+
}), toggleAnnotationOff, toggleAnnotationOn, toggleDecoratorOff, toggleDecoratorOn, toggleListItemOff, toggleListItemOn, toggleStyleOff, toggleStyleOn, raiseDeserializationSuccessOrFailure, raiseSerializationSuccessOrFailure, raiseInsertSoftBreak];
|
|
6057
6466
|
function createEditorSnapshot({
|
|
6058
6467
|
converters,
|
|
6059
6468
|
editor,
|
|
6060
6469
|
keyGenerator,
|
|
6470
|
+
readOnly,
|
|
6061
6471
|
schema: schema2,
|
|
6062
|
-
hasTag
|
|
6472
|
+
hasTag,
|
|
6473
|
+
internalDrag
|
|
6063
6474
|
}) {
|
|
6064
6475
|
const value = fromSlateValue(editor.children, schema2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), selection = toPortableTextRange(value, editor.selection, schema2);
|
|
6065
6476
|
return {
|
|
@@ -6070,12 +6481,14 @@ function createEditorSnapshot({
|
|
|
6070
6481
|
}),
|
|
6071
6482
|
converters,
|
|
6072
6483
|
keyGenerator,
|
|
6484
|
+
readOnly,
|
|
6073
6485
|
schema: schema2,
|
|
6074
6486
|
selection,
|
|
6075
6487
|
value
|
|
6076
6488
|
},
|
|
6077
6489
|
beta: {
|
|
6078
|
-
hasTag
|
|
6490
|
+
hasTag,
|
|
6491
|
+
internalDrag
|
|
6079
6492
|
}
|
|
6080
6493
|
};
|
|
6081
6494
|
}
|
|
@@ -6157,10 +6570,10 @@ const editorMachine = xstate.setup({
|
|
|
6157
6570
|
self
|
|
6158
6571
|
}) => {
|
|
6159
6572
|
xstate.assertEvent(event, ["behavior event", "custom behavior event"]);
|
|
6160
|
-
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 : {
|
|
6573
|
+
const defaultAction = event.type === "custom behavior event" || behavior_core.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" || behavior_core.isMouseBehaviorEvent(event.behaviorEvent) || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
|
|
6161
6574
|
...event.behaviorEvent,
|
|
6162
6575
|
editor: event.editor
|
|
6163
|
-
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => behavior.on === "*" || behavior.on === event.behaviorEvent.type);
|
|
6576
|
+
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => behavior.on === "*" ? !0 : behavior_core.isDragBehaviorEvent(event.behaviorEvent) && behavior.on === "drag.*" || behavior.on === event.behaviorEvent.type);
|
|
6164
6577
|
if (eventBehaviors.length === 0) {
|
|
6165
6578
|
if (defaultActionCallback) {
|
|
6166
6579
|
withApplyingBehaviorActions(event.editor, () => {
|
|
@@ -6177,7 +6590,10 @@ const editorMachine = xstate.setup({
|
|
|
6177
6590
|
withApplyingBehaviorActions(event.editor, () => {
|
|
6178
6591
|
try {
|
|
6179
6592
|
performAction({
|
|
6180
|
-
context
|
|
6593
|
+
context: {
|
|
6594
|
+
keyGenerator: context.keyGenerator,
|
|
6595
|
+
schema: context.schema
|
|
6596
|
+
},
|
|
6181
6597
|
action: defaultAction
|
|
6182
6598
|
});
|
|
6183
6599
|
} catch (error) {
|
|
@@ -6190,8 +6606,12 @@ const editorMachine = xstate.setup({
|
|
|
6190
6606
|
converters: [...context.converters],
|
|
6191
6607
|
editor: event.editor,
|
|
6192
6608
|
keyGenerator: context.keyGenerator,
|
|
6609
|
+
readOnly: self.getSnapshot().matches({
|
|
6610
|
+
"edit mode": "read only"
|
|
6611
|
+
}),
|
|
6193
6612
|
schema: context.schema,
|
|
6194
|
-
hasTag: (tag) => self.getSnapshot().hasTag(tag)
|
|
6613
|
+
hasTag: (tag) => self.getSnapshot().hasTag(tag),
|
|
6614
|
+
internalDrag: context.internalDrag
|
|
6195
6615
|
});
|
|
6196
6616
|
let behaviorOverwritten = !1;
|
|
6197
6617
|
for (const eventBehavior of eventBehaviors) {
|
|
@@ -6228,7 +6648,10 @@ const editorMachine = xstate.setup({
|
|
|
6228
6648
|
};
|
|
6229
6649
|
try {
|
|
6230
6650
|
performAction({
|
|
6231
|
-
context
|
|
6651
|
+
context: {
|
|
6652
|
+
keyGenerator: context.keyGenerator,
|
|
6653
|
+
schema: context.schema
|
|
6654
|
+
},
|
|
6232
6655
|
action: internalAction
|
|
6233
6656
|
});
|
|
6234
6657
|
} catch (error) {
|
|
@@ -6258,7 +6681,10 @@ const editorMachine = xstate.setup({
|
|
|
6258
6681
|
withApplyingBehaviorActions(event.editor, () => {
|
|
6259
6682
|
try {
|
|
6260
6683
|
performAction({
|
|
6261
|
-
context
|
|
6684
|
+
context: {
|
|
6685
|
+
keyGenerator: context.keyGenerator,
|
|
6686
|
+
schema: context.schema
|
|
6687
|
+
},
|
|
6262
6688
|
action: defaultAction
|
|
6263
6689
|
});
|
|
6264
6690
|
} catch (error) {
|
|
@@ -6533,11 +6959,26 @@ const editorMachine = xstate.setup({
|
|
|
6533
6959
|
idle: {
|
|
6534
6960
|
on: {
|
|
6535
6961
|
dragstart: {
|
|
6962
|
+
actions: [xstate.assign({
|
|
6963
|
+
internalDrag: ({
|
|
6964
|
+
event
|
|
6965
|
+
}) => ({
|
|
6966
|
+
ghost: event.ghost,
|
|
6967
|
+
origin: event.origin
|
|
6968
|
+
})
|
|
6969
|
+
})],
|
|
6536
6970
|
target: "dragging internally"
|
|
6537
6971
|
}
|
|
6538
6972
|
}
|
|
6539
6973
|
},
|
|
6540
6974
|
"dragging internally": {
|
|
6975
|
+
exit: [({
|
|
6976
|
+
context
|
|
6977
|
+
}) => {
|
|
6978
|
+
context.internalDrag?.ghost && document.body.removeChild(context.internalDrag.ghost);
|
|
6979
|
+
}, xstate.assign({
|
|
6980
|
+
internalDrag: void 0
|
|
6981
|
+
})],
|
|
6541
6982
|
tags: ["dragging internally"],
|
|
6542
6983
|
on: {
|
|
6543
6984
|
dragend: {
|
|
@@ -6617,50 +7058,6 @@ const editorMachine = xstate.setup({
|
|
|
6617
7058
|
}
|
|
6618
7059
|
}
|
|
6619
7060
|
});
|
|
6620
|
-
function getValue({
|
|
6621
|
-
editorActorSnapshot,
|
|
6622
|
-
slateEditorInstance
|
|
6623
|
-
}) {
|
|
6624
|
-
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
6625
|
-
}
|
|
6626
|
-
function defaultCompare(a, b) {
|
|
6627
|
-
return a === b;
|
|
6628
|
-
}
|
|
6629
|
-
function useEditorSelector(editor, selector, t0) {
|
|
6630
|
-
const $ = reactCompilerRuntime.c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
6631
|
-
let t1;
|
|
6632
|
-
return $[0] !== editor._internal.slateEditor.instance || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
6633
|
-
const snapshot = getEditorSnapshot({
|
|
6634
|
-
editorActorSnapshot,
|
|
6635
|
-
slateEditorInstance: editor._internal.slateEditor.instance
|
|
6636
|
-
});
|
|
6637
|
-
return selector(snapshot);
|
|
6638
|
-
}, $[0] = editor._internal.slateEditor.instance, $[1] = selector, $[2] = t1) : t1 = $[2], react.useSelector(editor._internal.editorActor, t1, compare);
|
|
6639
|
-
}
|
|
6640
|
-
function getEditorSnapshot({
|
|
6641
|
-
editorActorSnapshot,
|
|
6642
|
-
slateEditorInstance
|
|
6643
|
-
}) {
|
|
6644
|
-
return {
|
|
6645
|
-
context: {
|
|
6646
|
-
converters: [...editorActorSnapshot.context.converters],
|
|
6647
|
-
activeDecorators: getActiveDecorators({
|
|
6648
|
-
schema: editorActorSnapshot.context.schema,
|
|
6649
|
-
slateEditorInstance
|
|
6650
|
-
}),
|
|
6651
|
-
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
6652
|
-
schema: editorActorSnapshot.context.schema,
|
|
6653
|
-
selection: editorActorSnapshot.context.selection,
|
|
6654
|
-
value: getValue({
|
|
6655
|
-
editorActorSnapshot,
|
|
6656
|
-
slateEditorInstance
|
|
6657
|
-
})
|
|
6658
|
-
},
|
|
6659
|
-
beta: {
|
|
6660
|
-
hasTag: (tag) => editorActorSnapshot.hasTag(tag)
|
|
6661
|
-
}
|
|
6662
|
-
};
|
|
6663
|
-
}
|
|
6664
7061
|
function createEditor(config) {
|
|
6665
7062
|
const editorActor = xstate.createActor(editorMachine, {
|
|
6666
7063
|
input: editorConfigToMachineInput(config)
|
|
@@ -6737,7 +7134,7 @@ function createEditorFromActor(editorActor) {
|
|
|
6737
7134
|
}
|
|
6738
7135
|
};
|
|
6739
7136
|
}
|
|
6740
|
-
const
|
|
7137
|
+
const PortableTextEditorSelectionContext = React.createContext(null), usePortableTextEditorSelection = () => {
|
|
6741
7138
|
const selection = React.useContext(PortableTextEditorSelectionContext);
|
|
6742
7139
|
if (selection === void 0)
|
|
6743
7140
|
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
@@ -7306,21 +7703,17 @@ function useEditor() {
|
|
|
7306
7703
|
}
|
|
7307
7704
|
exports.EditorActorContext = EditorActorContext;
|
|
7308
7705
|
exports.EditorProvider = EditorProvider;
|
|
7309
|
-
exports.IS_DRAGGING = IS_DRAGGING;
|
|
7310
|
-
exports.IS_DRAGGING_BLOCK_ELEMENT = IS_DRAGGING_BLOCK_ELEMENT;
|
|
7311
|
-
exports.IS_DRAGGING_BLOCK_TARGET_POSITION = IS_DRAGGING_BLOCK_TARGET_POSITION;
|
|
7312
|
-
exports.IS_DRAGGING_ELEMENT_TARGET = IS_DRAGGING_ELEMENT_TARGET;
|
|
7313
7706
|
exports.KEY_TO_VALUE_ELEMENT = KEY_TO_VALUE_ELEMENT;
|
|
7314
7707
|
exports.PortableTextEditor = PortableTextEditor;
|
|
7315
7708
|
exports.debugWithName = debugWithName;
|
|
7316
7709
|
exports.defaultKeyGenerator = defaultKeyGenerator;
|
|
7317
7710
|
exports.defineSchema = defineSchema;
|
|
7318
7711
|
exports.fromSlateValue = fromSlateValue;
|
|
7712
|
+
exports.getEditorSnapshot = getEditorSnapshot;
|
|
7319
7713
|
exports.isEqualToEmptyEditor = isEqualToEmptyEditor;
|
|
7320
7714
|
exports.moveRangeByOperation = moveRangeByOperation;
|
|
7321
7715
|
exports.toPortableTextRange = toPortableTextRange;
|
|
7322
7716
|
exports.toSlateRange = toSlateRange;
|
|
7323
|
-
exports.toSlateValue = toSlateValue;
|
|
7324
7717
|
exports.useEditor = useEditor;
|
|
7325
7718
|
exports.useEditorSelector = useEditorSelector;
|
|
7326
7719
|
exports.usePortableTextEditor = usePortableTextEditor;
|