@portabletext/editor 1.37.0 → 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/editor-provider.cjs +868 -534
- 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/editor-provider.js +858 -523
- 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 +10534 -4689
- package/lib/behaviors/index.d.ts +10534 -4689
- package/lib/index.cjs +582 -209
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +5296 -1178
- package/lib/index.d.ts +5296 -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 +5296 -1178
- package/lib/plugins/index.d.ts +5296 -1178
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +15 -152
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +5296 -1178
- package/lib/selectors/index.d.ts +5296 -1178
- package/lib/selectors/index.js +7 -145
- 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 +5296 -1178
- package/lib/utils/index.d.ts +5296 -1178
- package/lib/utils/index.js +3 -4
- package/lib/utils/index.js.map +1 -1
- package/package.json +16 -15
- package/src/behavior-actions/behavior.action.blur.ts +8 -0
- package/src/behavior-actions/behavior.action.decorator.add.ts +1 -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 +1 -1
- 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 -139
- 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 +50 -7
- package/src/editor/editor-selector.ts +1 -0
- package/src/editor/editor-snapshot.ts +13 -0
- package/src/editor/plugins/create-with-event-listeners.ts +6 -40
- package/src/internal-utils/create-test-snapshot.ts +1 -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/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,16 +3090,17 @@ 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: [],
|
|
@@ -4074,49 +4139,7 @@ const addAnnotationActionImplementation = ({
|
|
|
4074
4139
|
editor: action.editor
|
|
4075
4140
|
}
|
|
4076
4141
|
});
|
|
4077
|
-
}
|
|
4078
|
-
function insertBlock({
|
|
4079
|
-
block,
|
|
4080
|
-
placement,
|
|
4081
|
-
editor,
|
|
4082
|
-
schema: schema2
|
|
4083
|
-
}) {
|
|
4084
|
-
if (editor.selection) {
|
|
4085
|
-
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(editor, {
|
|
4086
|
-
at: editor.selection.focus.path.slice(0, 1),
|
|
4087
|
-
match: (n) => !slate.Editor.isEditor(n)
|
|
4088
|
-
}))[0] ?? [void 0, void 0];
|
|
4089
|
-
if (placement === "after") {
|
|
4090
|
-
const nextPath = [focusBlockPath[0] + 1];
|
|
4091
|
-
slate.Transforms.insertNodes(editor, block, {
|
|
4092
|
-
at: nextPath
|
|
4093
|
-
}), slate.Transforms.select(editor, {
|
|
4094
|
-
anchor: {
|
|
4095
|
-
path: [nextPath[0], 0],
|
|
4096
|
-
offset: 0
|
|
4097
|
-
},
|
|
4098
|
-
focus: {
|
|
4099
|
-
path: [nextPath[0], 0],
|
|
4100
|
-
offset: 0
|
|
4101
|
-
}
|
|
4102
|
-
});
|
|
4103
|
-
} else placement === "before" ? slate.Transforms.insertNodes(editor, block, {
|
|
4104
|
-
at: focusBlockPath
|
|
4105
|
-
}) : (slate.Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock], schema2) && slate.Transforms.removeNodes(editor, {
|
|
4106
|
-
at: focusBlockPath
|
|
4107
|
-
}));
|
|
4108
|
-
} else {
|
|
4109
|
-
const lastBlock = Array.from(slate.Editor.nodes(editor, {
|
|
4110
|
-
match: (n) => !slate.Editor.isEditor(n),
|
|
4111
|
-
at: [],
|
|
4112
|
-
reverse: !0
|
|
4113
|
-
}))[0];
|
|
4114
|
-
slate.Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], schema2) && slate.Transforms.removeNodes(editor, {
|
|
4115
|
-
at: lastBlock[1]
|
|
4116
|
-
});
|
|
4117
|
-
}
|
|
4118
|
-
}
|
|
4119
|
-
const blockSetBehaviorActionImplementation = ({
|
|
4142
|
+
}, blockSetBehaviorActionImplementation = ({
|
|
4120
4143
|
context,
|
|
4121
4144
|
action
|
|
4122
4145
|
}) => {
|
|
@@ -4143,7 +4166,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4143
4166
|
const {
|
|
4144
4167
|
_type,
|
|
4145
4168
|
...filteredProps
|
|
4146
|
-
} = action.props, updatedBlock =
|
|
4169
|
+
} = action.props, updatedBlock = parseBlocks.parseBlock({
|
|
4147
4170
|
context,
|
|
4148
4171
|
block: {
|
|
4149
4172
|
...parsedBlock,
|
|
@@ -4187,8 +4210,8 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4187
4210
|
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
|
|
4188
4211
|
if (!parsedBlock)
|
|
4189
4212
|
throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
|
|
4190
|
-
if (
|
|
4191
|
-
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({
|
|
4192
4215
|
context,
|
|
4193
4216
|
block: omit__default.default(parsedBlock, propsToRemove),
|
|
4194
4217
|
options: {
|
|
@@ -4205,7 +4228,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4205
4228
|
});
|
|
4206
4229
|
return;
|
|
4207
4230
|
}
|
|
4208
|
-
const updatedBlockObject =
|
|
4231
|
+
const updatedBlockObject = parseBlocks.parseBlock({
|
|
4209
4232
|
context,
|
|
4210
4233
|
block: omit__default.default(parsedBlock, action.props.filter((prop) => prop !== "_type")),
|
|
4211
4234
|
options: {
|
|
@@ -4226,6 +4249,10 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4226
4249
|
}, {
|
|
4227
4250
|
at: location
|
|
4228
4251
|
});
|
|
4252
|
+
}, blurActionImplementation = ({
|
|
4253
|
+
action
|
|
4254
|
+
}) => {
|
|
4255
|
+
slateReact.ReactEditor.blur(action.editor);
|
|
4229
4256
|
}, dataTransferSetActionImplementation = ({
|
|
4230
4257
|
action
|
|
4231
4258
|
}) => {
|
|
@@ -4239,11 +4266,39 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4239
4266
|
action.editor.delete({
|
|
4240
4267
|
at: range
|
|
4241
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);
|
|
4242
4297
|
}, deleteTextActionImplementation = ({
|
|
4243
4298
|
context,
|
|
4244
4299
|
action
|
|
4245
4300
|
}) => {
|
|
4246
|
-
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({
|
|
4247
4302
|
value,
|
|
4248
4303
|
offsets: {
|
|
4249
4304
|
anchor: action.anchor,
|
|
@@ -4252,9 +4307,10 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4252
4307
|
});
|
|
4253
4308
|
if (!selection)
|
|
4254
4309
|
throw new Error("Unable to find selection from block offsets");
|
|
4255
|
-
const trimmedSelection =
|
|
4310
|
+
const trimmedSelection = selector_isOverlappingSelection.getTrimmedSelection({
|
|
4256
4311
|
beta: {
|
|
4257
|
-
hasTag: () => !1
|
|
4312
|
+
hasTag: () => !1,
|
|
4313
|
+
internalDrag: void 0
|
|
4258
4314
|
},
|
|
4259
4315
|
context: {
|
|
4260
4316
|
converters: [],
|
|
@@ -4274,158 +4330,396 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4274
4330
|
slate.Transforms.delete(action.editor, {
|
|
4275
4331
|
at: range
|
|
4276
4332
|
});
|
|
4277
|
-
},
|
|
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 = ({
|
|
4278
4367
|
context,
|
|
4279
4368
|
action
|
|
4280
4369
|
}) => {
|
|
4281
|
-
const
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
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], {
|
|
4286
4380
|
schemaTypes: context.schema
|
|
4287
4381
|
})[0];
|
|
4382
|
+
if (!fragment)
|
|
4383
|
+
throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
|
|
4288
4384
|
insertBlock({
|
|
4289
|
-
block,
|
|
4385
|
+
block: fragment,
|
|
4290
4386
|
placement: action.placement,
|
|
4387
|
+
select: action.select ?? "start",
|
|
4291
4388
|
editor: action.editor,
|
|
4292
4389
|
schema: context.schema
|
|
4293
4390
|
});
|
|
4294
|
-
}
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
at: slate.Editor.start(action.editor, [])
|
|
4305
|
-
});
|
|
4306
|
-
return;
|
|
4307
|
-
}
|
|
4308
|
-
if (action.placement === "after") {
|
|
4309
|
-
action.editor.insertFragment(fragment, {
|
|
4310
|
-
at: slate.Editor.end(action.editor, [])
|
|
4311
|
-
});
|
|
4312
|
-
return;
|
|
4313
|
-
}
|
|
4314
|
-
action.editor.insertFragment(fragment);
|
|
4315
|
-
return;
|
|
4316
|
-
}
|
|
4317
|
-
const [focusBlock, focusPath] = slate.Editor.node(action.editor, action.editor.selection, {
|
|
4318
|
-
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
|
|
4319
4401
|
});
|
|
4320
|
-
if (
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
return;
|
|
4325
|
-
}
|
|
4326
|
-
if (action.placement === "after" && focusPath) {
|
|
4327
|
-
const nextPath = [focusPath[0] + 1];
|
|
4328
|
-
slate.Transforms.insertNodes(action.editor, fragment, {
|
|
4329
|
-
at: nextPath
|
|
4402
|
+
if (!editor.selection || !focusBlock || !focusBlockPath) {
|
|
4403
|
+
select !== "none" && slateDom.DOMEditor.focus(editor);
|
|
4404
|
+
const [lastBlock, lastBlockPath] = getLastBlock({
|
|
4405
|
+
editor
|
|
4330
4406
|
});
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
}
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
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;
|
|
4349
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
|
|
4350
4445
|
});
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
slate.Transforms.insertNodes(action.editor, fragment, {
|
|
4356
|
-
at: nextPath
|
|
4446
|
+
const adjustedSelection = slate.Range.transform(currentSelection, {
|
|
4447
|
+
type: "move_node",
|
|
4448
|
+
path: focusBlockPath,
|
|
4449
|
+
newPath: [focusBlockPath[0] + 1]
|
|
4357
4450
|
});
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
focus: {
|
|
4374
|
-
path: [nextPath[0], 0],
|
|
4375
|
-
offset: 0
|
|
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;
|
|
4376
4466
|
}
|
|
4377
|
-
|
|
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
|
+
}
|
|
4509
|
+
}
|
|
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 = ({
|
|
4517
|
+
context,
|
|
4518
|
+
action
|
|
4519
|
+
}) => {
|
|
4520
|
+
if (!action.editor.selection) {
|
|
4521
|
+
console.error("Unable to select previous block without a selection");
|
|
4378
4522
|
return;
|
|
4379
4523
|
}
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
at: focusPath,
|
|
4388
|
-
mode: "lowest",
|
|
4389
|
-
voids: !1
|
|
4390
|
-
});
|
|
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");
|
|
4530
|
+
return;
|
|
4391
4531
|
}
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4532
|
+
selectActionImplementation({
|
|
4533
|
+
context,
|
|
4534
|
+
action: {
|
|
4535
|
+
type: "select",
|
|
4536
|
+
selection: newSelection,
|
|
4537
|
+
editor: action.editor
|
|
4538
|
+
}
|
|
4539
|
+
});
|
|
4540
|
+
}, selectPreviousBlockActionImplementation = ({
|
|
4398
4541
|
context,
|
|
4399
4542
|
action
|
|
4400
4543
|
}) => {
|
|
4401
|
-
if (!
|
|
4402
|
-
console.error("Unable to
|
|
4544
|
+
if (!action.editor.selection) {
|
|
4545
|
+
console.error("Unable to select previous block without a selection");
|
|
4403
4546
|
return;
|
|
4404
4547
|
}
|
|
4405
|
-
|
|
4406
|
-
|
|
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");
|
|
4407
4551
|
return;
|
|
4408
4552
|
}
|
|
4409
|
-
const
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
}
|
|
4413
|
-
if (!
|
|
4414
|
-
console.error("
|
|
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");
|
|
4415
4559
|
return;
|
|
4416
4560
|
}
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4561
|
+
selectActionImplementation({
|
|
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,
|
|
4576
|
+
options: {
|
|
4577
|
+
refreshKeys: !1
|
|
4578
|
+
}
|
|
4579
|
+
});
|
|
4580
|
+
if (parsedBlocks.length === 0)
|
|
4581
|
+
throw new Error(`Failed to parse blocks ${JSON.stringify(action.blocks)}`);
|
|
4582
|
+
const fragment = toSlateValue(parsedBlocks, {
|
|
4583
|
+
schemaTypes: context.schema
|
|
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) {
|
|
4429
4723
|
console.error("Unable to insert inline object");
|
|
4430
4724
|
return;
|
|
4431
4725
|
}
|
|
@@ -4459,29 +4753,140 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4459
4753
|
text: action.text,
|
|
4460
4754
|
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
|
|
4461
4755
|
});
|
|
4462
|
-
},
|
|
4756
|
+
}, insertBlockObjectActionImplementation = ({
|
|
4463
4757
|
context,
|
|
4464
4758
|
action
|
|
4465
4759
|
}) => {
|
|
4466
|
-
|
|
4467
|
-
block: action.block,
|
|
4760
|
+
insertBlockActionImplementation({
|
|
4468
4761
|
context,
|
|
4469
|
-
|
|
4470
|
-
|
|
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
|
|
4471
4771
|
}
|
|
4472
4772
|
});
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
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
|
+
}
|
|
4485
4890
|
});
|
|
4486
4891
|
}, behaviorActionImplementations = {
|
|
4487
4892
|
"annotation.add": addAnnotationActionImplementation,
|
|
@@ -4489,72 +4894,19 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4489
4894
|
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
4490
4895
|
"block.set": blockSetBehaviorActionImplementation,
|
|
4491
4896
|
"block.unset": blockUnsetBehaviorActionImplementation,
|
|
4492
|
-
blur:
|
|
4493
|
-
action
|
|
4494
|
-
}) => {
|
|
4495
|
-
slateReact.ReactEditor.blur(action.editor);
|
|
4496
|
-
},
|
|
4897
|
+
blur: blurActionImplementation,
|
|
4497
4898
|
"data transfer.set": dataTransferSetActionImplementation,
|
|
4498
4899
|
"decorator.add": decoratorAddActionImplementation,
|
|
4499
4900
|
"decorator.remove": removeDecoratorActionImplementation,
|
|
4500
4901
|
"decorator.toggle": toggleDecoratorActionImplementation,
|
|
4501
|
-
focus:
|
|
4502
|
-
action
|
|
4503
|
-
}) => {
|
|
4504
|
-
slateReact.ReactEditor.focus(action.editor);
|
|
4505
|
-
},
|
|
4902
|
+
focus: focusActionImplementation,
|
|
4506
4903
|
delete: deleteActionImplementation,
|
|
4507
|
-
"delete.backward":
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
action.editor.deleteBackward(action.unit);
|
|
4511
|
-
},
|
|
4512
|
-
"delete.forward": ({
|
|
4513
|
-
action
|
|
4514
|
-
}) => {
|
|
4515
|
-
slate.deleteForward(action.editor, action.unit);
|
|
4516
|
-
},
|
|
4517
|
-
"delete.block": ({
|
|
4518
|
-
action
|
|
4519
|
-
}) => {
|
|
4520
|
-
const range = toSlateRange({
|
|
4521
|
-
anchor: {
|
|
4522
|
-
path: action.blockPath,
|
|
4523
|
-
offset: 0
|
|
4524
|
-
},
|
|
4525
|
-
focus: {
|
|
4526
|
-
path: action.blockPath,
|
|
4527
|
-
offset: 0
|
|
4528
|
-
}
|
|
4529
|
-
}, action.editor);
|
|
4530
|
-
if (!range) {
|
|
4531
|
-
console.error("Unable to find Slate range from selection points");
|
|
4532
|
-
return;
|
|
4533
|
-
}
|
|
4534
|
-
slate.Transforms.removeNodes(action.editor, {
|
|
4535
|
-
at: range
|
|
4536
|
-
});
|
|
4537
|
-
},
|
|
4904
|
+
"delete.backward": deleteBackwardActionImplementation,
|
|
4905
|
+
"delete.forward": deleteForwardActionImplementation,
|
|
4906
|
+
"delete.block": deleteBlockActionImplementation,
|
|
4538
4907
|
"delete.text": deleteTextActionImplementation,
|
|
4539
|
-
"deserialization.failure":
|
|
4540
|
-
|
|
4541
|
-
}) => {
|
|
4542
|
-
console.warn(`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`);
|
|
4543
|
-
},
|
|
4544
|
-
"deserialization.success": ({
|
|
4545
|
-
context,
|
|
4546
|
-
action
|
|
4547
|
-
}) => {
|
|
4548
|
-
insertBlocksActionImplementation({
|
|
4549
|
-
context,
|
|
4550
|
-
action: {
|
|
4551
|
-
type: "insert.blocks",
|
|
4552
|
-
blocks: action.data,
|
|
4553
|
-
editor: action.editor,
|
|
4554
|
-
placement: "auto"
|
|
4555
|
-
}
|
|
4556
|
-
});
|
|
4557
|
-
},
|
|
4908
|
+
"deserialization.failure": deserializationFailureActionImplementation,
|
|
4909
|
+
"deserialization.success": deserializationSuccessActionImplementation,
|
|
4558
4910
|
"history.redo": historyRedoActionImplementation,
|
|
4559
4911
|
"history.undo": historyUndoActionImplementation,
|
|
4560
4912
|
"insert.block": insertBlockActionImplementation,
|
|
@@ -4564,129 +4916,21 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4564
4916
|
"insert.inline object": insertInlineObjectActionImplementation,
|
|
4565
4917
|
"insert.soft break": insertSoftBreakActionImplementation,
|
|
4566
4918
|
"insert.span": insertSpanActionImplementation,
|
|
4567
|
-
"insert.text":
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
slate.insertText(action.editor, action.text);
|
|
4571
|
-
},
|
|
4572
|
-
"insert.text block": ({
|
|
4573
|
-
context,
|
|
4574
|
-
action
|
|
4575
|
-
}) => {
|
|
4576
|
-
const block = toSlateValue([{
|
|
4577
|
-
_key: context.keyGenerator(),
|
|
4578
|
-
_type: context.schema.block.name,
|
|
4579
|
-
style: context.schema.styles[0].value ?? "normal",
|
|
4580
|
-
markDefs: [],
|
|
4581
|
-
children: action.textBlock?.children?.map((child) => ({
|
|
4582
|
-
...child,
|
|
4583
|
-
_key: context.keyGenerator()
|
|
4584
|
-
})) ?? [{
|
|
4585
|
-
_type: context.schema.span.name,
|
|
4586
|
-
_key: context.keyGenerator(),
|
|
4587
|
-
text: ""
|
|
4588
|
-
}]
|
|
4589
|
-
}], {
|
|
4590
|
-
schemaTypes: context.schema
|
|
4591
|
-
})[0];
|
|
4592
|
-
insertBlock({
|
|
4593
|
-
block,
|
|
4594
|
-
editor: action.editor,
|
|
4595
|
-
schema: context.schema,
|
|
4596
|
-
placement: action.placement
|
|
4597
|
-
});
|
|
4598
|
-
},
|
|
4599
|
-
effect: ({
|
|
4600
|
-
action
|
|
4601
|
-
}) => {
|
|
4602
|
-
action.effect();
|
|
4603
|
-
},
|
|
4919
|
+
"insert.text": insertTextActionImplementation,
|
|
4920
|
+
"insert.text block": insertTextBlockActionImplementation,
|
|
4921
|
+
effect: effectActionImplementation,
|
|
4604
4922
|
"list item.add": addListItemActionImplementation,
|
|
4605
4923
|
"list item.remove": removeListItemActionImplementation,
|
|
4606
4924
|
"list item.toggle": toggleListItemActionImplementation,
|
|
4607
|
-
"move.block":
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
},
|
|
4617
|
-
"move.block down": ({
|
|
4618
|
-
action
|
|
4619
|
-
}) => {
|
|
4620
|
-
const at = [toSlatePath(action.at, action.editor)[0]], to = [slate.Path.next(at)[0]];
|
|
4621
|
-
slate.Transforms.moveNodes(action.editor, {
|
|
4622
|
-
at,
|
|
4623
|
-
to,
|
|
4624
|
-
mode: "highest"
|
|
4625
|
-
});
|
|
4626
|
-
},
|
|
4627
|
-
"move.block up": ({
|
|
4628
|
-
action
|
|
4629
|
-
}) => {
|
|
4630
|
-
const at = [toSlatePath(action.at, action.editor)[0]];
|
|
4631
|
-
if (!slate.Path.hasPrevious(at))
|
|
4632
|
-
return;
|
|
4633
|
-
const to = [slate.Path.previous(at)[0]];
|
|
4634
|
-
slate.Transforms.moveNodes(action.editor, {
|
|
4635
|
-
at,
|
|
4636
|
-
to,
|
|
4637
|
-
mode: "highest"
|
|
4638
|
-
});
|
|
4639
|
-
},
|
|
4640
|
-
noop: () => {
|
|
4641
|
-
},
|
|
4642
|
-
select: ({
|
|
4643
|
-
action
|
|
4644
|
-
}) => {
|
|
4645
|
-
const newSelection = toSlateRange(action.selection, action.editor);
|
|
4646
|
-
newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
|
|
4647
|
-
},
|
|
4648
|
-
"select.previous block": ({
|
|
4649
|
-
action
|
|
4650
|
-
}) => {
|
|
4651
|
-
if (!action.editor.selection) {
|
|
4652
|
-
console.error("Unable to select previous block without a selection");
|
|
4653
|
-
return;
|
|
4654
|
-
}
|
|
4655
|
-
const blockPath = action.editor.selection.focus.path.slice(0, 1);
|
|
4656
|
-
if (!slate.Path.hasPrevious(blockPath)) {
|
|
4657
|
-
console.error("There's no previous block to select");
|
|
4658
|
-
return;
|
|
4659
|
-
}
|
|
4660
|
-
const previousBlockPath = slate.Path.previous(blockPath);
|
|
4661
|
-
slate.Transforms.select(action.editor, previousBlockPath);
|
|
4662
|
-
},
|
|
4663
|
-
"select.next block": ({
|
|
4664
|
-
action
|
|
4665
|
-
}) => {
|
|
4666
|
-
if (!action.editor.selection) {
|
|
4667
|
-
console.error("Unable to select next block without a selection");
|
|
4668
|
-
return;
|
|
4669
|
-
}
|
|
4670
|
-
const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
|
|
4671
|
-
slate.Transforms.select(action.editor, nextBlockPath);
|
|
4672
|
-
},
|
|
4673
|
-
"serialization.failure": ({
|
|
4674
|
-
action
|
|
4675
|
-
}) => {
|
|
4676
|
-
console.warn(`Serialization of ${action.mimeType} failed with reason "${action.reason}"`);
|
|
4677
|
-
},
|
|
4678
|
-
"serialization.success": ({
|
|
4679
|
-
context,
|
|
4680
|
-
action
|
|
4681
|
-
}) => {
|
|
4682
|
-
dataTransferSetActionImplementation({
|
|
4683
|
-
context,
|
|
4684
|
-
action: {
|
|
4685
|
-
...action,
|
|
4686
|
-
type: "data transfer.set"
|
|
4687
|
-
}
|
|
4688
|
-
});
|
|
4689
|
-
},
|
|
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,
|
|
4690
4934
|
"style.toggle": toggleStyleActionImplementation,
|
|
4691
4935
|
"style.add": addStyleActionImplementation,
|
|
4692
4936
|
"style.remove": removeStyleActionImplementation
|
|
@@ -4694,27 +4938,6 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4694
4938
|
function performAction({
|
|
4695
4939
|
context,
|
|
4696
4940
|
action
|
|
4697
|
-
}) {
|
|
4698
|
-
switch (action.type) {
|
|
4699
|
-
case "noop":
|
|
4700
|
-
break;
|
|
4701
|
-
case "effect": {
|
|
4702
|
-
behaviorActionImplementations.effect({
|
|
4703
|
-
context,
|
|
4704
|
-
action
|
|
4705
|
-
});
|
|
4706
|
-
break;
|
|
4707
|
-
}
|
|
4708
|
-
default:
|
|
4709
|
-
performDefaultAction({
|
|
4710
|
-
context,
|
|
4711
|
-
action
|
|
4712
|
-
});
|
|
4713
|
-
}
|
|
4714
|
-
}
|
|
4715
|
-
function performDefaultAction({
|
|
4716
|
-
context,
|
|
4717
|
-
action
|
|
4718
4941
|
}) {
|
|
4719
4942
|
switch (action.type) {
|
|
4720
4943
|
case "annotation.add": {
|
|
@@ -4836,6 +5059,13 @@ function performDefaultAction({
|
|
|
4836
5059
|
});
|
|
4837
5060
|
break;
|
|
4838
5061
|
}
|
|
5062
|
+
case "effect": {
|
|
5063
|
+
behaviorActionImplementations.effect({
|
|
5064
|
+
context,
|
|
5065
|
+
action
|
|
5066
|
+
});
|
|
5067
|
+
break;
|
|
5068
|
+
}
|
|
4839
5069
|
case "focus": {
|
|
4840
5070
|
behaviorActionImplementations.focus({
|
|
4841
5071
|
context,
|
|
@@ -4962,6 +5192,8 @@ function performDefaultAction({
|
|
|
4962
5192
|
});
|
|
4963
5193
|
break;
|
|
4964
5194
|
}
|
|
5195
|
+
case "noop":
|
|
5196
|
+
break;
|
|
4965
5197
|
case "select": {
|
|
4966
5198
|
behaviorActionImplementations.select({
|
|
4967
5199
|
context,
|
|
@@ -5069,10 +5301,8 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5069
5301
|
deleteBackward,
|
|
5070
5302
|
deleteForward,
|
|
5071
5303
|
insertBreak,
|
|
5072
|
-
insertData,
|
|
5073
5304
|
insertText,
|
|
5074
|
-
select
|
|
5075
|
-
setFragmentData
|
|
5305
|
+
select
|
|
5076
5306
|
} = editor;
|
|
5077
5307
|
return editor.deleteBackward = (unit) => {
|
|
5078
5308
|
if (isApplyingBehaviorActions(editor)) {
|
|
@@ -5112,19 +5342,8 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5112
5342
|
},
|
|
5113
5343
|
editor
|
|
5114
5344
|
});
|
|
5115
|
-
}, editor.insertData = (
|
|
5116
|
-
|
|
5117
|
-
insertData(dataTransfer);
|
|
5118
|
-
return;
|
|
5119
|
-
}
|
|
5120
|
-
editorActor.send({
|
|
5121
|
-
type: "behavior event",
|
|
5122
|
-
behaviorEvent: {
|
|
5123
|
-
type: "deserialize",
|
|
5124
|
-
dataTransfer
|
|
5125
|
-
},
|
|
5126
|
-
editor
|
|
5127
|
-
});
|
|
5345
|
+
}, editor.insertData = () => {
|
|
5346
|
+
console.warn("Unexpected call to .insertData(...)");
|
|
5128
5347
|
}, editor.insertSoftBreak = () => {
|
|
5129
5348
|
if (isApplyingBehaviorActions(editor)) {
|
|
5130
5349
|
insertSoftBreakActionImplementation({
|
|
@@ -5201,20 +5420,8 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5201
5420
|
select(location);
|
|
5202
5421
|
}
|
|
5203
5422
|
});
|
|
5204
|
-
}, editor.setFragmentData = (
|
|
5205
|
-
|
|
5206
|
-
setFragmentData(dataTransfer);
|
|
5207
|
-
return;
|
|
5208
|
-
}
|
|
5209
|
-
dataTransfer.clearData(), editorActor.send({
|
|
5210
|
-
type: "behavior event",
|
|
5211
|
-
behaviorEvent: {
|
|
5212
|
-
type: "serialize",
|
|
5213
|
-
dataTransfer,
|
|
5214
|
-
originEvent: originEvent ?? "unknown"
|
|
5215
|
-
},
|
|
5216
|
-
editor
|
|
5217
|
-
});
|
|
5423
|
+
}, editor.setFragmentData = () => {
|
|
5424
|
+
console.warn("Unexpected call to .setFragmentData(...)");
|
|
5218
5425
|
}, editor.undo = () => {
|
|
5219
5426
|
if (isApplyingBehaviorActions(editor)) {
|
|
5220
5427
|
performAction({
|
|
@@ -5928,7 +6135,7 @@ const keyIs = {
|
|
|
5928
6135
|
guard: ({
|
|
5929
6136
|
snapshot,
|
|
5930
6137
|
event
|
|
5931
|
-
}) =>
|
|
6138
|
+
}) => selector_isOverlappingSelection.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5932
6139
|
actions: [({
|
|
5933
6140
|
event
|
|
5934
6141
|
}) => [behavior_core.raise({
|
|
@@ -5940,7 +6147,7 @@ const keyIs = {
|
|
|
5940
6147
|
guard: ({
|
|
5941
6148
|
snapshot,
|
|
5942
6149
|
event
|
|
5943
|
-
}) => !
|
|
6150
|
+
}) => !selector_isOverlappingSelection.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5944
6151
|
actions: [({
|
|
5945
6152
|
event
|
|
5946
6153
|
}) => [behavior_core.raise({
|
|
@@ -5952,7 +6159,7 @@ const keyIs = {
|
|
|
5952
6159
|
guard: ({
|
|
5953
6160
|
snapshot,
|
|
5954
6161
|
event
|
|
5955
|
-
}) =>
|
|
6162
|
+
}) => selector_isOverlappingSelection.isActiveDecorator(event.decorator)(snapshot),
|
|
5956
6163
|
actions: [({
|
|
5957
6164
|
event
|
|
5958
6165
|
}) => [behavior_core.raise({
|
|
@@ -5964,7 +6171,7 @@ const keyIs = {
|
|
|
5964
6171
|
guard: ({
|
|
5965
6172
|
snapshot,
|
|
5966
6173
|
event
|
|
5967
|
-
}) => !
|
|
6174
|
+
}) => !selector_isOverlappingSelection.isActiveDecorator(event.decorator)(snapshot),
|
|
5968
6175
|
actions: [({
|
|
5969
6176
|
event
|
|
5970
6177
|
}) => [behavior_core.raise({
|
|
@@ -5976,7 +6183,7 @@ const keyIs = {
|
|
|
5976
6183
|
guard: ({
|
|
5977
6184
|
snapshot,
|
|
5978
6185
|
event
|
|
5979
|
-
}) =>
|
|
6186
|
+
}) => selector_isOverlappingSelection.isActiveListItem(event.listItem)(snapshot),
|
|
5980
6187
|
actions: [({
|
|
5981
6188
|
event
|
|
5982
6189
|
}) => [behavior_core.raise({
|
|
@@ -5988,7 +6195,7 @@ const keyIs = {
|
|
|
5988
6195
|
guard: ({
|
|
5989
6196
|
snapshot,
|
|
5990
6197
|
event
|
|
5991
|
-
}) => !
|
|
6198
|
+
}) => !selector_isOverlappingSelection.isActiveListItem(event.listItem)(snapshot),
|
|
5992
6199
|
actions: [({
|
|
5993
6200
|
event
|
|
5994
6201
|
}) => [behavior_core.raise({
|
|
@@ -6000,7 +6207,7 @@ const keyIs = {
|
|
|
6000
6207
|
guard: ({
|
|
6001
6208
|
snapshot,
|
|
6002
6209
|
event
|
|
6003
|
-
}) =>
|
|
6210
|
+
}) => selector_isOverlappingSelection.isActiveStyle(event.style)(snapshot),
|
|
6004
6211
|
actions: [({
|
|
6005
6212
|
event
|
|
6006
6213
|
}) => [behavior_core.raise({
|
|
@@ -6012,7 +6219,7 @@ const keyIs = {
|
|
|
6012
6219
|
guard: ({
|
|
6013
6220
|
snapshot,
|
|
6014
6221
|
event
|
|
6015
|
-
}) => !
|
|
6222
|
+
}) => !selector_isOverlappingSelection.isActiveStyle(event.style)(snapshot),
|
|
6016
6223
|
actions: [({
|
|
6017
6224
|
event
|
|
6018
6225
|
}) => [behavior_core.raise({
|
|
@@ -6045,16 +6252,8 @@ const keyIs = {
|
|
|
6045
6252
|
event
|
|
6046
6253
|
}, deserializeEvent) => [behavior_core.raise({
|
|
6047
6254
|
...deserializeEvent,
|
|
6048
|
-
dataTransfer: event.dataTransfer
|
|
6049
|
-
|
|
6050
|
-
}), raiseInsertBlocks = behavior_core.defineBehavior({
|
|
6051
|
-
on: "deserialization.success",
|
|
6052
|
-
actions: [({
|
|
6053
|
-
event
|
|
6054
|
-
}) => [behavior_core.raise({
|
|
6055
|
-
type: "insert.blocks",
|
|
6056
|
-
blocks: event.data,
|
|
6057
|
-
placement: "auto"
|
|
6255
|
+
dataTransfer: event.dataTransfer,
|
|
6256
|
+
originEvent: event.originEvent
|
|
6058
6257
|
})]]
|
|
6059
6258
|
}), raiseSerializationSuccessOrFailure = behavior_core.defineBehavior({
|
|
6060
6259
|
on: "serialize",
|
|
@@ -6066,7 +6265,10 @@ const keyIs = {
|
|
|
6066
6265
|
return !1;
|
|
6067
6266
|
const serializeEvents = snapshot.context.converters.map((converter) => converter.serialize({
|
|
6068
6267
|
snapshot,
|
|
6069
|
-
event
|
|
6268
|
+
event: {
|
|
6269
|
+
...event,
|
|
6270
|
+
originEvent: event.originEvent.type
|
|
6271
|
+
}
|
|
6070
6272
|
}));
|
|
6071
6273
|
return serializeEvents.length === 0 ? !1 : serializeEvents;
|
|
6072
6274
|
},
|
|
@@ -6074,9 +6276,69 @@ const keyIs = {
|
|
|
6074
6276
|
event
|
|
6075
6277
|
}, serializeEvents) => serializeEvents.map((serializeEvent) => behavior_core.raise({
|
|
6076
6278
|
...serializeEvent,
|
|
6279
|
+
originEvent: event.originEvent,
|
|
6077
6280
|
dataTransfer: event.dataTransfer
|
|
6078
6281
|
}))]
|
|
6079
|
-
}),
|
|
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({
|
|
6080
6342
|
on: "serialization.success",
|
|
6081
6343
|
actions: [({
|
|
6082
6344
|
event
|
|
@@ -6086,23 +6348,129 @@ const keyIs = {
|
|
|
6086
6348
|
dataTransfer: event.dataTransfer,
|
|
6087
6349
|
mimeType: event.mimeType
|
|
6088
6350
|
})]]
|
|
6089
|
-
}),
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
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];
|
|
6099
6466
|
function createEditorSnapshot({
|
|
6100
6467
|
converters,
|
|
6101
6468
|
editor,
|
|
6102
6469
|
keyGenerator,
|
|
6103
6470
|
readOnly,
|
|
6104
6471
|
schema: schema2,
|
|
6105
|
-
hasTag
|
|
6472
|
+
hasTag,
|
|
6473
|
+
internalDrag
|
|
6106
6474
|
}) {
|
|
6107
6475
|
const value = fromSlateValue(editor.children, schema2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), selection = toPortableTextRange(value, editor.selection, schema2);
|
|
6108
6476
|
return {
|
|
@@ -6119,7 +6487,8 @@ function createEditorSnapshot({
|
|
|
6119
6487
|
value
|
|
6120
6488
|
},
|
|
6121
6489
|
beta: {
|
|
6122
|
-
hasTag
|
|
6490
|
+
hasTag,
|
|
6491
|
+
internalDrag
|
|
6123
6492
|
}
|
|
6124
6493
|
};
|
|
6125
6494
|
}
|
|
@@ -6201,10 +6570,10 @@ const editorMachine = xstate.setup({
|
|
|
6201
6570
|
self
|
|
6202
6571
|
}) => {
|
|
6203
6572
|
xstate.assertEvent(event, ["behavior event", "custom behavior event"]);
|
|
6204
|
-
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 : {
|
|
6205
6574
|
...event.behaviorEvent,
|
|
6206
6575
|
editor: event.editor
|
|
6207
|
-
}, 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);
|
|
6208
6577
|
if (eventBehaviors.length === 0) {
|
|
6209
6578
|
if (defaultActionCallback) {
|
|
6210
6579
|
withApplyingBehaviorActions(event.editor, () => {
|
|
@@ -6241,7 +6610,8 @@ const editorMachine = xstate.setup({
|
|
|
6241
6610
|
"edit mode": "read only"
|
|
6242
6611
|
}),
|
|
6243
6612
|
schema: context.schema,
|
|
6244
|
-
hasTag: (tag) => self.getSnapshot().hasTag(tag)
|
|
6613
|
+
hasTag: (tag) => self.getSnapshot().hasTag(tag),
|
|
6614
|
+
internalDrag: context.internalDrag
|
|
6245
6615
|
});
|
|
6246
6616
|
let behaviorOverwritten = !1;
|
|
6247
6617
|
for (const eventBehavior of eventBehaviors) {
|
|
@@ -6589,11 +6959,26 @@ const editorMachine = xstate.setup({
|
|
|
6589
6959
|
idle: {
|
|
6590
6960
|
on: {
|
|
6591
6961
|
dragstart: {
|
|
6962
|
+
actions: [xstate.assign({
|
|
6963
|
+
internalDrag: ({
|
|
6964
|
+
event
|
|
6965
|
+
}) => ({
|
|
6966
|
+
ghost: event.ghost,
|
|
6967
|
+
origin: event.origin
|
|
6968
|
+
})
|
|
6969
|
+
})],
|
|
6592
6970
|
target: "dragging internally"
|
|
6593
6971
|
}
|
|
6594
6972
|
}
|
|
6595
6973
|
},
|
|
6596
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
|
+
})],
|
|
6597
6982
|
tags: ["dragging internally"],
|
|
6598
6983
|
on: {
|
|
6599
6984
|
dragend: {
|
|
@@ -6673,53 +7058,6 @@ const editorMachine = xstate.setup({
|
|
|
6673
7058
|
}
|
|
6674
7059
|
}
|
|
6675
7060
|
});
|
|
6676
|
-
function getValue({
|
|
6677
|
-
editorActorSnapshot,
|
|
6678
|
-
slateEditorInstance
|
|
6679
|
-
}) {
|
|
6680
|
-
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
6681
|
-
}
|
|
6682
|
-
function defaultCompare(a, b) {
|
|
6683
|
-
return a === b;
|
|
6684
|
-
}
|
|
6685
|
-
function useEditorSelector(editor, selector, t0) {
|
|
6686
|
-
const $ = reactCompilerRuntime.c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
6687
|
-
let t1;
|
|
6688
|
-
return $[0] !== editor._internal.slateEditor.instance || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
6689
|
-
const snapshot = getEditorSnapshot({
|
|
6690
|
-
editorActorSnapshot,
|
|
6691
|
-
slateEditorInstance: editor._internal.slateEditor.instance
|
|
6692
|
-
});
|
|
6693
|
-
return selector(snapshot);
|
|
6694
|
-
}, $[0] = editor._internal.slateEditor.instance, $[1] = selector, $[2] = t1) : t1 = $[2], react.useSelector(editor._internal.editorActor, t1, compare);
|
|
6695
|
-
}
|
|
6696
|
-
function getEditorSnapshot({
|
|
6697
|
-
editorActorSnapshot,
|
|
6698
|
-
slateEditorInstance
|
|
6699
|
-
}) {
|
|
6700
|
-
return {
|
|
6701
|
-
context: {
|
|
6702
|
-
converters: [...editorActorSnapshot.context.converters],
|
|
6703
|
-
activeDecorators: getActiveDecorators({
|
|
6704
|
-
schema: editorActorSnapshot.context.schema,
|
|
6705
|
-
slateEditorInstance
|
|
6706
|
-
}),
|
|
6707
|
-
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
6708
|
-
readOnly: editorActorSnapshot.matches({
|
|
6709
|
-
"edit mode": "read only"
|
|
6710
|
-
}),
|
|
6711
|
-
schema: editorActorSnapshot.context.schema,
|
|
6712
|
-
selection: editorActorSnapshot.context.selection,
|
|
6713
|
-
value: getValue({
|
|
6714
|
-
editorActorSnapshot,
|
|
6715
|
-
slateEditorInstance
|
|
6716
|
-
})
|
|
6717
|
-
},
|
|
6718
|
-
beta: {
|
|
6719
|
-
hasTag: (tag) => editorActorSnapshot.hasTag(tag)
|
|
6720
|
-
}
|
|
6721
|
-
};
|
|
6722
|
-
}
|
|
6723
7061
|
function createEditor(config) {
|
|
6724
7062
|
const editorActor = xstate.createActor(editorMachine, {
|
|
6725
7063
|
input: editorConfigToMachineInput(config)
|
|
@@ -6796,7 +7134,7 @@ function createEditorFromActor(editorActor) {
|
|
|
6796
7134
|
}
|
|
6797
7135
|
};
|
|
6798
7136
|
}
|
|
6799
|
-
const
|
|
7137
|
+
const PortableTextEditorSelectionContext = React.createContext(null), usePortableTextEditorSelection = () => {
|
|
6800
7138
|
const selection = React.useContext(PortableTextEditorSelectionContext);
|
|
6801
7139
|
if (selection === void 0)
|
|
6802
7140
|
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
@@ -7365,21 +7703,17 @@ function useEditor() {
|
|
|
7365
7703
|
}
|
|
7366
7704
|
exports.EditorActorContext = EditorActorContext;
|
|
7367
7705
|
exports.EditorProvider = EditorProvider;
|
|
7368
|
-
exports.IS_DRAGGING = IS_DRAGGING;
|
|
7369
|
-
exports.IS_DRAGGING_BLOCK_ELEMENT = IS_DRAGGING_BLOCK_ELEMENT;
|
|
7370
|
-
exports.IS_DRAGGING_BLOCK_TARGET_POSITION = IS_DRAGGING_BLOCK_TARGET_POSITION;
|
|
7371
|
-
exports.IS_DRAGGING_ELEMENT_TARGET = IS_DRAGGING_ELEMENT_TARGET;
|
|
7372
7706
|
exports.KEY_TO_VALUE_ELEMENT = KEY_TO_VALUE_ELEMENT;
|
|
7373
7707
|
exports.PortableTextEditor = PortableTextEditor;
|
|
7374
7708
|
exports.debugWithName = debugWithName;
|
|
7375
7709
|
exports.defaultKeyGenerator = defaultKeyGenerator;
|
|
7376
7710
|
exports.defineSchema = defineSchema;
|
|
7377
7711
|
exports.fromSlateValue = fromSlateValue;
|
|
7712
|
+
exports.getEditorSnapshot = getEditorSnapshot;
|
|
7378
7713
|
exports.isEqualToEmptyEditor = isEqualToEmptyEditor;
|
|
7379
7714
|
exports.moveRangeByOperation = moveRangeByOperation;
|
|
7380
7715
|
exports.toPortableTextRange = toPortableTextRange;
|
|
7381
7716
|
exports.toSlateRange = toSlateRange;
|
|
7382
|
-
exports.toSlateValue = toSlateValue;
|
|
7383
7717
|
exports.useEditor = useEditor;
|
|
7384
7718
|
exports.useEditorSelector = useEditorSelector;
|
|
7385
7719
|
exports.usePortableTextEditor = usePortableTextEditor;
|