@portabletext/editor 1.47.10 → 1.47.12
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 +61 -3
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +167 -105
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.get-selection-start-point.cjs +10 -0
- package/lib/_chunks-cjs/util.get-selection-start-point.cjs.map +1 -0
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +0 -4
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +63 -4
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +168 -105
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.get-selection-start-point.js +11 -0
- package/lib/_chunks-es/util.get-selection-start-point.js.map +1 -0
- package/lib/_chunks-es/util.is-selection-collapsed.js +0 -4
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -1
- package/lib/behaviors/index.d.cts +359 -339
- package/lib/behaviors/index.d.ts +359 -339
- package/lib/behaviors/index.js +1 -1
- package/lib/index.cjs +3 -3
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +4 -4
- package/lib/index.d.ts +4 -4
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +0 -9
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +4 -4
- package/lib/plugins/index.d.ts +4 -4
- package/lib/plugins/index.js +0 -9
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +4 -4
- package/lib/selectors/index.d.ts +4 -4
- package/lib/utils/index.cjs +3 -6
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +4 -4
- package/lib/utils/index.d.ts +4 -4
- package/lib/utils/index.js +2 -4
- package/lib/utils/index.js.map +1 -1
- package/package.json +3 -3
- package/src/behavior-actions/behavior.action.insert.block.ts +136 -45
- package/src/behavior-actions/behavior.actions.ts +0 -9
- package/src/behaviors/behavior.abstract.insert.ts +2 -2
- package/src/behaviors/behavior.abstract.split.ts +118 -0
- package/src/behaviors/behavior.core.insert-break.ts +113 -0
- package/src/behaviors/behavior.core.ts +2 -0
- package/src/behaviors/behavior.default.ts +2 -0
- package/src/behaviors/behavior.types.event.ts +4 -4
- package/src/internal-utils/slate-utils.ts +50 -1
- package/src/plugins/plugin.one-line.tsx +0 -7
- package/src/behavior-actions/behavior.action.split.block.ts +0 -146
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), React = require("react"), slateReact = require("slate-react"), reactCompilerRuntime = require("react-compiler-runtime"), debug$g = 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"), omit = require("lodash/omit.js"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), selector_isSelectingEntireBlocks = require("./selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
|
|
2
|
+
var jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), React = require("react"), slateReact = require("slate-react"), reactCompilerRuntime = require("react-compiler-runtime"), debug$g = 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"), omit = require("lodash/omit.js"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), selector_isSelectingEntireBlocks = require("./selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), util_getSelectionStartPoint = require("./util.get-selection-start-point.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
|
}
|
|
@@ -3403,13 +3403,35 @@ function getFocusBlock({
|
|
|
3403
3403
|
return [void 0, void 0];
|
|
3404
3404
|
}
|
|
3405
3405
|
}
|
|
3406
|
+
function getSelectionStartBlock({
|
|
3407
|
+
editor
|
|
3408
|
+
}) {
|
|
3409
|
+
if (!editor.selection)
|
|
3410
|
+
return [void 0, void 0];
|
|
3411
|
+
const selectionStartPoint = slate.Range.start(editor.selection);
|
|
3412
|
+
return getPointBlock({
|
|
3413
|
+
editor,
|
|
3414
|
+
point: selectionStartPoint
|
|
3415
|
+
});
|
|
3416
|
+
}
|
|
3417
|
+
function getSelectionEndBlock({
|
|
3418
|
+
editor
|
|
3419
|
+
}) {
|
|
3420
|
+
if (!editor.selection)
|
|
3421
|
+
return [void 0, void 0];
|
|
3422
|
+
const selectionEndPoint = slate.Range.end(editor.selection);
|
|
3423
|
+
return getPointBlock({
|
|
3424
|
+
editor,
|
|
3425
|
+
point: selectionEndPoint
|
|
3426
|
+
});
|
|
3427
|
+
}
|
|
3406
3428
|
function getPointBlock({
|
|
3407
3429
|
editor,
|
|
3408
3430
|
point
|
|
3409
3431
|
}) {
|
|
3410
3432
|
try {
|
|
3411
3433
|
const [block] = slate.Editor.node(editor, point.path.slice(0, 1)) ?? [void 0, void 0];
|
|
3412
|
-
return block ? [block, point.path] : [void 0, void 0];
|
|
3434
|
+
return block ? [block, point.path.slice(0, 1)] : [void 0, void 0];
|
|
3413
3435
|
} catch {
|
|
3414
3436
|
return [void 0, void 0];
|
|
3415
3437
|
}
|
|
@@ -3823,10 +3845,12 @@ function insertBlock({
|
|
|
3823
3845
|
editor,
|
|
3824
3846
|
schema: schema2
|
|
3825
3847
|
}) {
|
|
3826
|
-
const [
|
|
3848
|
+
const [startBlock, startBlockPath] = getSelectionStartBlock({
|
|
3849
|
+
editor
|
|
3850
|
+
}), [endBlock, endBlockPath] = getSelectionEndBlock({
|
|
3827
3851
|
editor
|
|
3828
3852
|
});
|
|
3829
|
-
if (!editor.selection || !
|
|
3853
|
+
if (!editor.selection || !startBlock || !startBlockPath || !endBlock || !endBlockPath) {
|
|
3830
3854
|
select !== "none" && slateDom.DOMEditor.focus(editor);
|
|
3831
3855
|
const [lastBlock, lastBlockPath] = getLastBlock({
|
|
3832
3856
|
editor
|
|
@@ -3865,26 +3889,41 @@ function insertBlock({
|
|
|
3865
3889
|
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
|
|
3866
3890
|
}
|
|
3867
3891
|
} else if (placement === "before") {
|
|
3868
|
-
const currentSelection = editor.selection;
|
|
3892
|
+
const currentSelection = editor.selection, selectionStartPoint = slate.Range.start(currentSelection);
|
|
3869
3893
|
slate.Transforms.insertNodes(editor, [block], {
|
|
3870
|
-
at:
|
|
3894
|
+
at: [selectionStartPoint.path[0]],
|
|
3871
3895
|
select: !1
|
|
3872
|
-
});
|
|
3873
|
-
const adjustedSelection = slate.Range.transform(currentSelection, {
|
|
3874
|
-
type: "move_node",
|
|
3875
|
-
path: focusBlockPath,
|
|
3876
|
-
newPath: [focusBlockPath[0] + 1]
|
|
3877
|
-
});
|
|
3878
|
-
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));
|
|
3896
|
+
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, [selectionStartPoint.path[0]])) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, [selectionStartPoint.path[0]]));
|
|
3879
3897
|
} else if (placement === "after") {
|
|
3880
|
-
const nextPath = [
|
|
3898
|
+
const currentSelection = editor.selection, nextPath = [slate.Range.end(currentSelection).path[0] + 1];
|
|
3881
3899
|
slate.Transforms.insertNodes(editor, [block], {
|
|
3882
3900
|
at: nextPath,
|
|
3883
3901
|
select: !1
|
|
3884
|
-
}),
|
|
3902
|
+
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
|
|
3885
3903
|
} else {
|
|
3886
|
-
const currentSelection = editor.selection,
|
|
3887
|
-
if (
|
|
3904
|
+
const currentSelection = editor.selection, endBlockEndPoint = slate.Editor.start(editor, endBlockPath);
|
|
3905
|
+
if (slate.Range.isExpanded(currentSelection) && !editor.isTextBlock(block)) {
|
|
3906
|
+
slate.Transforms.delete(editor, {
|
|
3907
|
+
at: currentSelection
|
|
3908
|
+
});
|
|
3909
|
+
const newSelection = editor.selection, [focusBlock, focusBlockPath] = getFocusBlock({
|
|
3910
|
+
editor
|
|
3911
|
+
});
|
|
3912
|
+
slate.Transforms.insertNodes(editor, [block], {
|
|
3913
|
+
voids: !0
|
|
3914
|
+
});
|
|
3915
|
+
const adjustedSelection = newSelection.anchor.offset === 0 ? slate.Range.transform(newSelection, {
|
|
3916
|
+
type: "insert_node",
|
|
3917
|
+
node: block,
|
|
3918
|
+
path: [newSelection.anchor.path[0]]
|
|
3919
|
+
}) : newSelection;
|
|
3920
|
+
select === "none" && adjustedSelection && slate.Transforms.select(editor, adjustedSelection), focusBlock && isEqualToEmptyEditor([focusBlock], schema2) && slate.Transforms.removeNodes(editor, {
|
|
3921
|
+
at: focusBlockPath
|
|
3922
|
+
});
|
|
3923
|
+
return;
|
|
3924
|
+
}
|
|
3925
|
+
if (editor.isTextBlock(endBlock) && editor.isTextBlock(block)) {
|
|
3926
|
+
const selectionStartPoint = slate.Range.start(currentSelection);
|
|
3888
3927
|
if (select === "end") {
|
|
3889
3928
|
slate.Transforms.insertFragment(editor, [block], {
|
|
3890
3929
|
voids: !0
|
|
@@ -3894,32 +3933,44 @@ function insertBlock({
|
|
|
3894
3933
|
slate.Transforms.insertFragment(editor, [block], {
|
|
3895
3934
|
at: currentSelection,
|
|
3896
3935
|
voids: !0
|
|
3897
|
-
}), select === "start" ? slate.
|
|
3898
|
-
} else if (editor.isTextBlock(
|
|
3899
|
-
const
|
|
3900
|
-
if (slate.Point.equals(
|
|
3936
|
+
}), select === "start" ? slate.Transforms.select(editor, selectionStartPoint) : slate.Point.equals(selectionStartPoint, endBlockEndPoint) || slate.Transforms.select(editor, selectionStartPoint);
|
|
3937
|
+
} else if (editor.isTextBlock(endBlock)) {
|
|
3938
|
+
const endBlockStartPoint = slate.Editor.start(editor, endBlockPath), endBlockEndPoint2 = slate.Editor.end(editor, endBlockPath), selectionStartPoint = slate.Range.start(currentSelection), selectionEndPoint = slate.Range.end(currentSelection);
|
|
3939
|
+
if (slate.Range.isCollapsed(currentSelection) && slate.Point.equals(selectionStartPoint, endBlockStartPoint))
|
|
3901
3940
|
slate.Transforms.insertNodes(editor, [block], {
|
|
3902
|
-
at:
|
|
3941
|
+
at: endBlockPath,
|
|
3903
3942
|
select: !1
|
|
3904
|
-
}), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor,
|
|
3905
|
-
at: slate.Path.next(
|
|
3943
|
+
}), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor, endBlockPath)), isEqualToEmptyEditor([endBlock], schema2) && slate.Transforms.removeNodes(editor, {
|
|
3944
|
+
at: slate.Path.next(endBlockPath)
|
|
3906
3945
|
});
|
|
3907
|
-
else if (slate.Point.equals(
|
|
3908
|
-
const nextPath = [
|
|
3946
|
+
else if (slate.Range.isCollapsed(currentSelection) && slate.Point.equals(selectionEndPoint, endBlockEndPoint2)) {
|
|
3947
|
+
const nextPath = [endBlockPath[0] + 1];
|
|
3909
3948
|
slate.Transforms.insertNodes(editor, [block], {
|
|
3910
3949
|
at: nextPath,
|
|
3911
3950
|
select: !1
|
|
3912
3951
|
}), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor, nextPath));
|
|
3913
|
-
} else
|
|
3952
|
+
} else if (slate.Range.isExpanded(currentSelection) && slate.Point.equals(selectionStartPoint, endBlockStartPoint) && slate.Point.equals(selectionEndPoint, endBlockEndPoint2))
|
|
3953
|
+
slate.Transforms.insertFragment(editor, [block], {
|
|
3954
|
+
at: currentSelection
|
|
3955
|
+
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, endBlockPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, endBlockPath));
|
|
3956
|
+
else if (slate.Range.isExpanded(currentSelection) && slate.Point.equals(selectionStartPoint, endBlockStartPoint))
|
|
3957
|
+
slate.Transforms.insertFragment(editor, [block], {
|
|
3958
|
+
at: currentSelection
|
|
3959
|
+
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, endBlockPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, endBlockPath));
|
|
3960
|
+
else if (slate.Range.isExpanded(currentSelection) && slate.Point.equals(selectionEndPoint, endBlockEndPoint2))
|
|
3961
|
+
slate.Transforms.insertFragment(editor, [block], {
|
|
3962
|
+
at: currentSelection
|
|
3963
|
+
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, slate.Path.next(endBlockPath))) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, slate.Path.next(endBlockPath)));
|
|
3964
|
+
else {
|
|
3914
3965
|
const currentSelection2 = editor.selection, [focusChild] = getFocusChild({
|
|
3915
3966
|
editor
|
|
3916
3967
|
});
|
|
3917
3968
|
if (focusChild && editor.isTextSpan(focusChild))
|
|
3918
3969
|
slate.Transforms.insertFragment(editor, [block], {
|
|
3919
3970
|
at: currentSelection2
|
|
3920
|
-
}), select === "start" || select === "end" ? slate.Transforms.select(editor, [
|
|
3971
|
+
}), select === "start" || select === "end" ? slate.Transforms.select(editor, [endBlockPath[0] + 1]) : slate.Transforms.select(editor, currentSelection2);
|
|
3921
3972
|
else {
|
|
3922
|
-
const nextPath = [
|
|
3973
|
+
const nextPath = [endBlockPath[0] + 1];
|
|
3923
3974
|
slate.Transforms.insertNodes(editor, [block], {
|
|
3924
3975
|
at: nextPath,
|
|
3925
3976
|
select: !1
|
|
@@ -3930,7 +3981,7 @@ function insertBlock({
|
|
|
3930
3981
|
slate.Transforms.insertNodes(editor, [block], {
|
|
3931
3982
|
select: !1
|
|
3932
3983
|
});
|
|
3933
|
-
const nextPath = [
|
|
3984
|
+
const nextPath = [endBlockPath[0] + 1];
|
|
3934
3985
|
select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
|
|
3935
3986
|
}
|
|
3936
3987
|
}
|
|
@@ -3965,69 +4016,6 @@ const moveBackwardActionImplementation = ({
|
|
|
3965
4016
|
}) => {
|
|
3966
4017
|
const newSelection = toSlateRange(action.at, action.editor);
|
|
3967
4018
|
newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
|
|
3968
|
-
}, splitBlockActionImplementation = ({
|
|
3969
|
-
context,
|
|
3970
|
-
action
|
|
3971
|
-
}) => {
|
|
3972
|
-
const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
|
|
3973
|
-
if (!editor.selection)
|
|
3974
|
-
return;
|
|
3975
|
-
const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
3976
|
-
if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
3977
|
-
slate.Transforms.splitNodes(editor, {
|
|
3978
|
-
at: editor.selection,
|
|
3979
|
-
always: !0
|
|
3980
|
-
});
|
|
3981
|
-
const [nextBlock, nextBlockPath] = slate.Editor.node(editor, slate.Path.next(focusBlockPath), {
|
|
3982
|
-
depth: 1
|
|
3983
|
-
}), nextChild = slate.Node.child(nextBlock, 0);
|
|
3984
|
-
if (!editor.isTextSpan(nextChild) && slate.Transforms.insertNodes(editor, {
|
|
3985
|
-
_key: context.keyGenerator(),
|
|
3986
|
-
_type: "span",
|
|
3987
|
-
text: "",
|
|
3988
|
-
marks: []
|
|
3989
|
-
}, {
|
|
3990
|
-
at: [nextBlockPath[0], 0]
|
|
3991
|
-
}), slate.Transforms.setSelection(editor, {
|
|
3992
|
-
anchor: {
|
|
3993
|
-
path: [...nextBlockPath, 0],
|
|
3994
|
-
offset: 0
|
|
3995
|
-
},
|
|
3996
|
-
focus: {
|
|
3997
|
-
path: [...nextBlockPath, 0],
|
|
3998
|
-
offset: 0
|
|
3999
|
-
}
|
|
4000
|
-
}), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
|
|
4001
|
-
const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(slate.Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = slate.Node.children(editor, nextBlockPath);
|
|
4002
|
-
for (const [child, childPath] of children) {
|
|
4003
|
-
if (!editor.isTextSpan(child))
|
|
4004
|
-
continue;
|
|
4005
|
-
const marks = child.marks ?? [];
|
|
4006
|
-
for (const mark of marks)
|
|
4007
|
-
schema2.decorators.some((decorator) => decorator.name === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
4008
|
-
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
4009
|
-
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
4010
|
-
marks: newMarks
|
|
4011
|
-
}, {
|
|
4012
|
-
at: childPath
|
|
4013
|
-
});
|
|
4014
|
-
}
|
|
4015
|
-
const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
|
|
4016
|
-
...markDef,
|
|
4017
|
-
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
4018
|
-
}));
|
|
4019
|
-
isEqual__default.default(nextBlock.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
4020
|
-
markDefs: newMarkDefs
|
|
4021
|
-
}, {
|
|
4022
|
-
at: nextBlockPath,
|
|
4023
|
-
match: (node) => editor.isTextBlock(node)
|
|
4024
|
-
});
|
|
4025
|
-
}
|
|
4026
|
-
return;
|
|
4027
|
-
}
|
|
4028
|
-
slate.Transforms.splitNodes(editor, {
|
|
4029
|
-
always: !0
|
|
4030
|
-
});
|
|
4031
4019
|
}, debug$a = debugWithName("behaviors:action"), behaviorActionImplementations = {
|
|
4032
4020
|
"annotation.add": addAnnotationActionImplementation,
|
|
4033
4021
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
@@ -4050,8 +4038,7 @@ const moveBackwardActionImplementation = ({
|
|
|
4050
4038
|
"move.block": moveBlockActionImplementation,
|
|
4051
4039
|
"move.forward": moveForwardActionImplementation,
|
|
4052
4040
|
noop: noopActionImplementation,
|
|
4053
|
-
select: selectActionImplementation
|
|
4054
|
-
"split.block": splitBlockActionImplementation
|
|
4041
|
+
select: selectActionImplementation
|
|
4055
4042
|
};
|
|
4056
4043
|
function performAction({
|
|
4057
4044
|
context,
|
|
@@ -4200,13 +4187,6 @@ function performAction({
|
|
|
4200
4187
|
}
|
|
4201
4188
|
case "noop":
|
|
4202
4189
|
break;
|
|
4203
|
-
case "split.block": {
|
|
4204
|
-
behaviorActionImplementations["split.block"]({
|
|
4205
|
-
context,
|
|
4206
|
-
action
|
|
4207
|
-
});
|
|
4208
|
-
break;
|
|
4209
|
-
}
|
|
4210
4190
|
default: {
|
|
4211
4191
|
behaviorActionImplementations.select({
|
|
4212
4192
|
context,
|
|
@@ -5938,7 +5918,7 @@ const EditorActorContext = React.createContext({}), abstractAnnotationBehaviors
|
|
|
5938
5918
|
placement: index === 0 ? "auto" : "after",
|
|
5939
5919
|
select: "end"
|
|
5940
5920
|
})) : event.blocks.flatMap((block, index) => index === 0 ? [behavior_core.raise({
|
|
5941
|
-
type: "split
|
|
5921
|
+
type: "split"
|
|
5942
5922
|
}), behavior_core.raise({
|
|
5943
5923
|
type: "select.previous block",
|
|
5944
5924
|
select: "end"
|
|
@@ -5977,7 +5957,7 @@ const EditorActorContext = React.createContext({}), abstractAnnotationBehaviors
|
|
|
5977
5957
|
}), behavior_core.defineBehavior({
|
|
5978
5958
|
on: "insert.break",
|
|
5979
5959
|
actions: [() => [behavior_core.raise({
|
|
5980
|
-
type: "split
|
|
5960
|
+
type: "split"
|
|
5981
5961
|
})]]
|
|
5982
5962
|
}), behavior_core.defineBehavior({
|
|
5983
5963
|
on: "insert.soft break",
|
|
@@ -6157,6 +6137,87 @@ const EditorActorContext = React.createContext({}), abstractAnnotationBehaviors
|
|
|
6157
6137
|
type: "select",
|
|
6158
6138
|
at: selection
|
|
6159
6139
|
})]]
|
|
6140
|
+
})], abstractSplitBehaviors = [behavior_core.defineBehavior({
|
|
6141
|
+
on: "split",
|
|
6142
|
+
guard: ({
|
|
6143
|
+
snapshot
|
|
6144
|
+
}) => {
|
|
6145
|
+
if (!snapshot.context.selection)
|
|
6146
|
+
return !1;
|
|
6147
|
+
const selectionStartPoint = util_getSelectionStartPoint.getSelectionStartPoint(snapshot.context.selection), selectionEndPoint = util_getSelectionStartPoint.getSelectionEndPoint(snapshot.context.selection), focusTextBlock = selector_isOverlappingSelection.getFocusTextBlock({
|
|
6148
|
+
context: {
|
|
6149
|
+
...snapshot.context,
|
|
6150
|
+
selection: {
|
|
6151
|
+
anchor: selectionStartPoint,
|
|
6152
|
+
focus: selectionEndPoint
|
|
6153
|
+
}
|
|
6154
|
+
}
|
|
6155
|
+
});
|
|
6156
|
+
if (focusTextBlock) {
|
|
6157
|
+
const blockEndPoint = util_sliceBlocks.getBlockEndPoint(focusTextBlock), newTextBlockSelection = {
|
|
6158
|
+
anchor: selectionEndPoint,
|
|
6159
|
+
focus: blockEndPoint
|
|
6160
|
+
}, newTextBlock = parseBlocks.parseBlock({
|
|
6161
|
+
block: util_sliceBlocks.sliceBlocks({
|
|
6162
|
+
blocks: [focusTextBlock.node],
|
|
6163
|
+
selection: newTextBlockSelection
|
|
6164
|
+
}).at(0),
|
|
6165
|
+
context: snapshot.context,
|
|
6166
|
+
options: {
|
|
6167
|
+
refreshKeys: !0
|
|
6168
|
+
}
|
|
6169
|
+
});
|
|
6170
|
+
return !newTextBlock || !parseBlocks.isTextBlock(snapshot.context.schema, newTextBlock) ? !1 : {
|
|
6171
|
+
newTextBlock,
|
|
6172
|
+
newTextBlockSelection,
|
|
6173
|
+
selection: {
|
|
6174
|
+
anchor: selectionStartPoint,
|
|
6175
|
+
focus: blockEndPoint
|
|
6176
|
+
}
|
|
6177
|
+
};
|
|
6178
|
+
}
|
|
6179
|
+
if (selector_isOverlappingSelection.getFocusBlockObject({
|
|
6180
|
+
context: {
|
|
6181
|
+
...snapshot.context,
|
|
6182
|
+
selection: {
|
|
6183
|
+
anchor: selectionStartPoint,
|
|
6184
|
+
focus: selectionEndPoint
|
|
6185
|
+
}
|
|
6186
|
+
}
|
|
6187
|
+
})) {
|
|
6188
|
+
const newTextBlock = parseBlocks.parseBlock({
|
|
6189
|
+
block: {
|
|
6190
|
+
_type: snapshot.context.schema.block.name,
|
|
6191
|
+
children: []
|
|
6192
|
+
},
|
|
6193
|
+
context: snapshot.context,
|
|
6194
|
+
options: {
|
|
6195
|
+
refreshKeys: !0
|
|
6196
|
+
}
|
|
6197
|
+
});
|
|
6198
|
+
return newTextBlock ? {
|
|
6199
|
+
newTextBlock,
|
|
6200
|
+
newTextBlockSelection: {
|
|
6201
|
+
anchor: selectionEndPoint,
|
|
6202
|
+
focus: selectionEndPoint
|
|
6203
|
+
},
|
|
6204
|
+
selection: snapshot.context.selection
|
|
6205
|
+
} : !1;
|
|
6206
|
+
}
|
|
6207
|
+
return !1;
|
|
6208
|
+
},
|
|
6209
|
+
actions: [(_, {
|
|
6210
|
+
newTextBlock,
|
|
6211
|
+
selection
|
|
6212
|
+
}) => [behavior_core.raise({
|
|
6213
|
+
type: "delete",
|
|
6214
|
+
at: selection
|
|
6215
|
+
}), behavior_core.raise({
|
|
6216
|
+
type: "insert.block",
|
|
6217
|
+
block: newTextBlock,
|
|
6218
|
+
placement: "after",
|
|
6219
|
+
select: "start"
|
|
6220
|
+
})]]
|
|
6160
6221
|
})], abstractStyleBehaviors = [behavior_core.defineBehavior({
|
|
6161
6222
|
on: "style.add",
|
|
6162
6223
|
guard: ({
|
|
@@ -6568,10 +6629,11 @@ const EditorActorContext = React.createContext({}), abstractAnnotationBehaviors
|
|
|
6568
6629
|
...abstractMoveBehaviors,
|
|
6569
6630
|
...abstractStyleBehaviors,
|
|
6570
6631
|
...abstractSelectBehaviors,
|
|
6632
|
+
...abstractSplitBehaviors,
|
|
6571
6633
|
raiseDeserializationSuccessOrFailure,
|
|
6572
6634
|
raiseSerializationSuccessOrFailure,
|
|
6573
6635
|
raiseInsertSoftBreak
|
|
6574
|
-
], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "style.add", "style.remove", "style.toggle"];
|
|
6636
|
+
], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
6575
6637
|
function isAbstractBehaviorEvent(event) {
|
|
6576
6638
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
6577
6639
|
}
|