@portabletext/editor 1.44.0 → 1.44.2
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 +3 -3
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +323 -490
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +3 -3
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +325 -492
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.cjs +2 -2
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +8390 -16283
- package/lib/behaviors/index.d.ts +8390 -16283
- package/lib/behaviors/index.js +4 -4
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +2 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2237 -15969
- package/lib/index.d.ts +2237 -15969
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +2088 -15821
- package/lib/plugins/index.d.ts +2088 -15821
- package/lib/selectors/index.d.cts +1738 -15472
- package/lib/selectors/index.d.ts +1738 -15472
- package/lib/utils/index.d.cts +1738 -15472
- package/lib/utils/index.d.ts +1738 -15472
- package/package.json +2 -2
- package/src/behavior-actions/behavior.actions.ts +1 -39
- package/src/behaviors/behavior.abstract.annotation.ts +26 -0
- package/src/behaviors/behavior.abstract.decorator.ts +47 -0
- package/src/behaviors/{behavior.internal.insert.ts → behavior.abstract.insert.ts} +1 -1
- package/src/behaviors/{behavior.internal.list-item.ts → behavior.abstract.list-item.ts} +1 -1
- package/src/behaviors/behavior.abstract.move.ts +78 -0
- package/src/behaviors/{behavior.internal.select.ts → behavior.abstract.select.ts} +1 -1
- package/src/behaviors/{behavior.internal.style.ts → behavior.abstract.style.ts} +1 -1
- package/src/behaviors/behavior.code-editor.ts +13 -8
- package/src/behaviors/behavior.default.ts +15 -78
- package/src/behaviors/behavior.perform-event.ts +4 -4
- package/src/behaviors/behavior.types.action.ts +3 -3
- package/src/behaviors/behavior.types.behavior.ts +4 -3
- package/src/behaviors/behavior.types.event.ts +164 -160
- package/src/editor/components/Leaf.tsx +2 -2
- package/src/editor/create-editor.ts +37 -11
- package/src/editor/editor-machine.ts +4 -76
- package/src/editor/editor-selector.ts +5 -2
- package/src/editor/editor-snapshot.ts +2 -7
- package/src/editor/plugins/create-with-event-listeners.ts +1 -64
- package/src/editor/plugins/createWithEditableAPI.ts +0 -30
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -29
- package/src/editor/plugins/with-plugins.ts +1 -4
- package/src/internal-utils/slate-children-to-blocks.ts +49 -0
- package/src/internal-utils/slate-utils.ts +6 -8
- package/src/type-utils.ts +2 -0
- package/src/behavior-actions/behavior.action.move.block-down.ts +0 -48
- package/src/behavior-actions/behavior.action.move.block-up.ts +0 -53
|
@@ -14,7 +14,7 @@ import isPlainObject from "lodash/isPlainObject.js";
|
|
|
14
14
|
import uniq from "lodash/uniq.js";
|
|
15
15
|
import getRandomValues from "get-random-values-esm";
|
|
16
16
|
import { parseBlock, isTextBlock } from "./parse-blocks.js";
|
|
17
|
-
import { sliceBlocks, blockOffsetToSpanSelectionPoint,
|
|
17
|
+
import { sliceBlocks, blockOffsetToSpanSelectionPoint, getBlockEndPoint, getBlockStartPoint, getTextBlockText } from "./util.slice-blocks.js";
|
|
18
18
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
19
19
|
import { toHTML } from "@portabletext/to-html";
|
|
20
20
|
import { Schema } from "@sanity/schema";
|
|
@@ -23,7 +23,7 @@ import isUndefined from "lodash/isUndefined.js";
|
|
|
23
23
|
import omitBy from "lodash/omitBy.js";
|
|
24
24
|
import omit from "lodash/omit.js";
|
|
25
25
|
import { selectionPointToBlockOffset, blockOffsetsToSelection } from "./util.selection-point-to-block-offset.js";
|
|
26
|
-
import { getTrimmedSelection,
|
|
26
|
+
import { getTrimmedSelection, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, isSelectingEntireBlocks, getActiveAnnotations } from "./selector.is-selecting-entire-blocks.js";
|
|
27
27
|
import { DOMEditor } from "slate-dom";
|
|
28
28
|
import startCase from "lodash.startcase";
|
|
29
29
|
import { defineBehavior, raise, coreBehaviors } from "./behavior.core.js";
|
|
@@ -341,10 +341,7 @@ function isEqualToEmptyEditor(children, schemaTypes) {
|
|
|
341
341
|
function getFocusBlock({
|
|
342
342
|
editor
|
|
343
343
|
}) {
|
|
344
|
-
return editor.selection ?
|
|
345
|
-
at: editor.selection.focus.path.slice(0, 1),
|
|
346
|
-
match: (n) => !Editor.isEditor(n)
|
|
347
|
-
})).at(0) ?? [void 0, void 0] : [void 0, void 0];
|
|
344
|
+
return editor.selection ? Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0] : [void 0, void 0];
|
|
348
345
|
}
|
|
349
346
|
function getFocusChild({
|
|
350
347
|
editor
|
|
@@ -3005,112 +3002,6 @@ function isPortableTextBlock(node) {
|
|
|
3005
3002
|
node.children.every((child) => typeof child == "object" && "_type" in child)
|
|
3006
3003
|
);
|
|
3007
3004
|
}
|
|
3008
|
-
const decoratorAddActionImplementation = ({
|
|
3009
|
-
context,
|
|
3010
|
-
action
|
|
3011
|
-
}) => {
|
|
3012
|
-
const editor = action.editor, mark = action.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = action.offsets?.anchor ? blockOffsetToSpanSelectionPoint({
|
|
3013
|
-
value,
|
|
3014
|
-
blockOffset: action.offsets.anchor,
|
|
3015
|
-
direction: "backward"
|
|
3016
|
-
}) : void 0, manualFocus = action.offsets?.focus ? blockOffsetToSpanSelectionPoint({
|
|
3017
|
-
value,
|
|
3018
|
-
blockOffset: action.offsets.focus,
|
|
3019
|
-
direction: "forward"
|
|
3020
|
-
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
3021
|
-
anchor: manualAnchor,
|
|
3022
|
-
focus: manualFocus
|
|
3023
|
-
} : void 0, selection = manualSelection ? toSlateRange(manualSelection, action.editor) ?? editor.selection : editor.selection;
|
|
3024
|
-
if (!selection)
|
|
3025
|
-
return;
|
|
3026
|
-
const editorSelection = toPortableTextRange(value, selection, context.schema), anchorOffset = editorSelection ? selectionPointToBlockOffset({
|
|
3027
|
-
value,
|
|
3028
|
-
selectionPoint: editorSelection.anchor
|
|
3029
|
-
}) : void 0, focusOffset = editorSelection ? selectionPointToBlockOffset({
|
|
3030
|
-
value,
|
|
3031
|
-
selectionPoint: editorSelection.focus
|
|
3032
|
-
}) : void 0;
|
|
3033
|
-
if (!anchorOffset || !focusOffset)
|
|
3034
|
-
throw new Error("Unable to find anchor or focus offset");
|
|
3035
|
-
if (Range.isExpanded(selection)) {
|
|
3036
|
-
Transforms.setNodes(editor, {}, {
|
|
3037
|
-
at: selection,
|
|
3038
|
-
match: Text.isText,
|
|
3039
|
-
split: !0,
|
|
3040
|
-
hanging: !0
|
|
3041
|
-
});
|
|
3042
|
-
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = blockOffsetsToSelection({
|
|
3043
|
-
value: newValue,
|
|
3044
|
-
offsets: {
|
|
3045
|
-
anchor: anchorOffset,
|
|
3046
|
-
focus: focusOffset
|
|
3047
|
-
},
|
|
3048
|
-
backward: editorSelection?.backward
|
|
3049
|
-
}), trimmedSelection = getTrimmedSelection({
|
|
3050
|
-
context: {
|
|
3051
|
-
activeDecorators: [],
|
|
3052
|
-
converters: [],
|
|
3053
|
-
keyGenerator: context.keyGenerator,
|
|
3054
|
-
readOnly: !1,
|
|
3055
|
-
schema: context.schema,
|
|
3056
|
-
selection: newSelection,
|
|
3057
|
-
value: newValue
|
|
3058
|
-
}
|
|
3059
|
-
});
|
|
3060
|
-
if (!trimmedSelection)
|
|
3061
|
-
throw new Error("Unable to find trimmed selection");
|
|
3062
|
-
const newRange = toSlateRange(trimmedSelection, editor);
|
|
3063
|
-
if (!newRange)
|
|
3064
|
-
throw new Error("Unable to find new selection");
|
|
3065
|
-
const splitTextNodes = Range.isRange(newRange) ? [...Editor.nodes(editor, {
|
|
3066
|
-
at: newRange,
|
|
3067
|
-
match: (node) => Text.isText(node)
|
|
3068
|
-
})] : [];
|
|
3069
|
-
for (const [node, path] of splitTextNodes) {
|
|
3070
|
-
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
3071
|
-
Transforms.setNodes(editor, {
|
|
3072
|
-
marks
|
|
3073
|
-
}, {
|
|
3074
|
-
at: path,
|
|
3075
|
-
match: Text.isText,
|
|
3076
|
-
split: !0,
|
|
3077
|
-
hanging: !0
|
|
3078
|
-
});
|
|
3079
|
-
}
|
|
3080
|
-
} else {
|
|
3081
|
-
if (!Array.from(Editor.nodes(editor, {
|
|
3082
|
-
at: selection,
|
|
3083
|
-
match: (node) => editor.isTextSpan(node)
|
|
3084
|
-
}))?.at(0))
|
|
3085
|
-
return;
|
|
3086
|
-
const [block, blockPath] = Editor.node(editor, selection, {
|
|
3087
|
-
depth: 1
|
|
3088
|
-
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
3089
|
-
if (lonelyEmptySpan) {
|
|
3090
|
-
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
3091
|
-
Transforms.setNodes(editor, {
|
|
3092
|
-
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
3093
|
-
}, {
|
|
3094
|
-
at: blockPath,
|
|
3095
|
-
match: (node) => editor.isTextSpan(node)
|
|
3096
|
-
});
|
|
3097
|
-
} else {
|
|
3098
|
-
const existingMarks = {
|
|
3099
|
-
...Editor.marks(editor) || {}
|
|
3100
|
-
}.marks || [], marks = {
|
|
3101
|
-
...Editor.marks(editor) || {},
|
|
3102
|
-
marks: [...existingMarks, mark]
|
|
3103
|
-
};
|
|
3104
|
-
editor.marks = marks;
|
|
3105
|
-
}
|
|
3106
|
-
}
|
|
3107
|
-
if (editor.selection) {
|
|
3108
|
-
const selection2 = editor.selection;
|
|
3109
|
-
editor.selection = {
|
|
3110
|
-
...selection2
|
|
3111
|
-
};
|
|
3112
|
-
}
|
|
3113
|
-
};
|
|
3114
3005
|
function getPreviousSpan({
|
|
3115
3006
|
editor,
|
|
3116
3007
|
blockPath,
|
|
@@ -3568,25 +3459,7 @@ function isDecoratorActive({
|
|
|
3568
3459
|
...Editor.marks(editor) || {}
|
|
3569
3460
|
}.marks || []).includes(decorator);
|
|
3570
3461
|
}
|
|
3571
|
-
const
|
|
3572
|
-
context,
|
|
3573
|
-
action
|
|
3574
|
-
}) => {
|
|
3575
|
-
isDecoratorActive({
|
|
3576
|
-
editor: action.editor,
|
|
3577
|
-
decorator: action.decorator
|
|
3578
|
-
}) ? removeDecoratorActionImplementation({
|
|
3579
|
-
action: {
|
|
3580
|
-
editor: action.editor,
|
|
3581
|
-
decorator: action.decorator
|
|
3582
|
-
}
|
|
3583
|
-
}) : decoratorAddActionImplementation({
|
|
3584
|
-
context,
|
|
3585
|
-
action: {
|
|
3586
|
-
...action
|
|
3587
|
-
}
|
|
3588
|
-
});
|
|
3589
|
-
}, debug$a = debugWithName("API:editable");
|
|
3462
|
+
const debug$a = debugWithName("API:editable");
|
|
3590
3463
|
function createEditableAPI(editor, editorActor) {
|
|
3591
3464
|
const types = editorActor.getSnapshot().context.schema;
|
|
3592
3465
|
return {
|
|
@@ -4057,30 +3930,6 @@ const addAnnotationActionImplementation = ({
|
|
|
4057
3930
|
}
|
|
4058
3931
|
}
|
|
4059
3932
|
}
|
|
4060
|
-
}, toggleAnnotationActionImplementation = ({
|
|
4061
|
-
context,
|
|
4062
|
-
action
|
|
4063
|
-
}) => {
|
|
4064
|
-
if (isAnnotationActive({
|
|
4065
|
-
editor: action.editor,
|
|
4066
|
-
annotation: {
|
|
4067
|
-
name: action.annotation.name
|
|
4068
|
-
}
|
|
4069
|
-
}))
|
|
4070
|
-
removeAnnotationActionImplementation({
|
|
4071
|
-
action: {
|
|
4072
|
-
annotation: action.annotation,
|
|
4073
|
-
editor: action.editor
|
|
4074
|
-
}
|
|
4075
|
-
});
|
|
4076
|
-
else
|
|
4077
|
-
return addAnnotationActionImplementation({
|
|
4078
|
-
context,
|
|
4079
|
-
action: {
|
|
4080
|
-
annotation: action.annotation,
|
|
4081
|
-
editor: action.editor
|
|
4082
|
-
}
|
|
4083
|
-
});
|
|
4084
3933
|
}, blockSetBehaviorActionImplementation = ({
|
|
4085
3934
|
context,
|
|
4086
3935
|
action
|
|
@@ -4195,6 +4044,111 @@ const addAnnotationActionImplementation = ({
|
|
|
4195
4044
|
action
|
|
4196
4045
|
}) => {
|
|
4197
4046
|
ReactEditor.blur(action.editor);
|
|
4047
|
+
}, decoratorAddActionImplementation = ({
|
|
4048
|
+
context,
|
|
4049
|
+
action
|
|
4050
|
+
}) => {
|
|
4051
|
+
const editor = action.editor, mark = action.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = action.offsets?.anchor ? blockOffsetToSpanSelectionPoint({
|
|
4052
|
+
value,
|
|
4053
|
+
blockOffset: action.offsets.anchor,
|
|
4054
|
+
direction: "backward"
|
|
4055
|
+
}) : void 0, manualFocus = action.offsets?.focus ? blockOffsetToSpanSelectionPoint({
|
|
4056
|
+
value,
|
|
4057
|
+
blockOffset: action.offsets.focus,
|
|
4058
|
+
direction: "forward"
|
|
4059
|
+
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
4060
|
+
anchor: manualAnchor,
|
|
4061
|
+
focus: manualFocus
|
|
4062
|
+
} : void 0, selection = manualSelection ? toSlateRange(manualSelection, action.editor) ?? editor.selection : editor.selection;
|
|
4063
|
+
if (!selection)
|
|
4064
|
+
return;
|
|
4065
|
+
const editorSelection = toPortableTextRange(value, selection, context.schema), anchorOffset = editorSelection ? selectionPointToBlockOffset({
|
|
4066
|
+
value,
|
|
4067
|
+
selectionPoint: editorSelection.anchor
|
|
4068
|
+
}) : void 0, focusOffset = editorSelection ? selectionPointToBlockOffset({
|
|
4069
|
+
value,
|
|
4070
|
+
selectionPoint: editorSelection.focus
|
|
4071
|
+
}) : void 0;
|
|
4072
|
+
if (!anchorOffset || !focusOffset)
|
|
4073
|
+
throw new Error("Unable to find anchor or focus offset");
|
|
4074
|
+
if (Range.isExpanded(selection)) {
|
|
4075
|
+
Transforms.setNodes(editor, {}, {
|
|
4076
|
+
at: selection,
|
|
4077
|
+
match: Text.isText,
|
|
4078
|
+
split: !0,
|
|
4079
|
+
hanging: !0
|
|
4080
|
+
});
|
|
4081
|
+
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = blockOffsetsToSelection({
|
|
4082
|
+
value: newValue,
|
|
4083
|
+
offsets: {
|
|
4084
|
+
anchor: anchorOffset,
|
|
4085
|
+
focus: focusOffset
|
|
4086
|
+
},
|
|
4087
|
+
backward: editorSelection?.backward
|
|
4088
|
+
}), trimmedSelection = getTrimmedSelection({
|
|
4089
|
+
context: {
|
|
4090
|
+
activeDecorators: [],
|
|
4091
|
+
converters: [],
|
|
4092
|
+
keyGenerator: context.keyGenerator,
|
|
4093
|
+
readOnly: !1,
|
|
4094
|
+
schema: context.schema,
|
|
4095
|
+
selection: newSelection,
|
|
4096
|
+
value: newValue
|
|
4097
|
+
}
|
|
4098
|
+
});
|
|
4099
|
+
if (!trimmedSelection)
|
|
4100
|
+
throw new Error("Unable to find trimmed selection");
|
|
4101
|
+
const newRange = toSlateRange(trimmedSelection, editor);
|
|
4102
|
+
if (!newRange)
|
|
4103
|
+
throw new Error("Unable to find new selection");
|
|
4104
|
+
const splitTextNodes = Range.isRange(newRange) ? [...Editor.nodes(editor, {
|
|
4105
|
+
at: newRange,
|
|
4106
|
+
match: (node) => Text.isText(node)
|
|
4107
|
+
})] : [];
|
|
4108
|
+
for (const [node, path] of splitTextNodes) {
|
|
4109
|
+
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
4110
|
+
Transforms.setNodes(editor, {
|
|
4111
|
+
marks
|
|
4112
|
+
}, {
|
|
4113
|
+
at: path,
|
|
4114
|
+
match: Text.isText,
|
|
4115
|
+
split: !0,
|
|
4116
|
+
hanging: !0
|
|
4117
|
+
});
|
|
4118
|
+
}
|
|
4119
|
+
} else {
|
|
4120
|
+
if (!Array.from(Editor.nodes(editor, {
|
|
4121
|
+
at: selection,
|
|
4122
|
+
match: (node) => editor.isTextSpan(node)
|
|
4123
|
+
}))?.at(0))
|
|
4124
|
+
return;
|
|
4125
|
+
const [block, blockPath] = Editor.node(editor, selection, {
|
|
4126
|
+
depth: 1
|
|
4127
|
+
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4128
|
+
if (lonelyEmptySpan) {
|
|
4129
|
+
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
4130
|
+
Transforms.setNodes(editor, {
|
|
4131
|
+
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
4132
|
+
}, {
|
|
4133
|
+
at: blockPath,
|
|
4134
|
+
match: (node) => editor.isTextSpan(node)
|
|
4135
|
+
});
|
|
4136
|
+
} else {
|
|
4137
|
+
const existingMarks = {
|
|
4138
|
+
...Editor.marks(editor) || {}
|
|
4139
|
+
}.marks || [], marks = {
|
|
4140
|
+
...Editor.marks(editor) || {},
|
|
4141
|
+
marks: [...existingMarks, mark]
|
|
4142
|
+
};
|
|
4143
|
+
editor.marks = marks;
|
|
4144
|
+
}
|
|
4145
|
+
}
|
|
4146
|
+
if (editor.selection) {
|
|
4147
|
+
const selection2 = editor.selection;
|
|
4148
|
+
editor.selection = {
|
|
4149
|
+
...selection2
|
|
4150
|
+
};
|
|
4151
|
+
}
|
|
4198
4152
|
}, deleteActionImplementation = ({
|
|
4199
4153
|
action
|
|
4200
4154
|
}) => {
|
|
@@ -4495,63 +4449,6 @@ const insertTextActionImplementation = ({
|
|
|
4495
4449
|
to,
|
|
4496
4450
|
mode: "highest"
|
|
4497
4451
|
});
|
|
4498
|
-
}, moveBlockDownActionImplementation = ({
|
|
4499
|
-
context,
|
|
4500
|
-
action
|
|
4501
|
-
}) => {
|
|
4502
|
-
const at = [toSlatePath(action.at, action.editor)[0]], to = [Path.next(at)[0]], selection = toPortableTextRange(action.editor.children, {
|
|
4503
|
-
anchor: {
|
|
4504
|
-
path: to,
|
|
4505
|
-
offset: 0
|
|
4506
|
-
},
|
|
4507
|
-
focus: {
|
|
4508
|
-
path: to,
|
|
4509
|
-
offset: 0
|
|
4510
|
-
}
|
|
4511
|
-
}, context.schema), destinationBlockKey = selection && isKeyedSegment$1(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
|
|
4512
|
-
if (destinationBlockKey === void 0) {
|
|
4513
|
-
console.error("Could not find destination block key");
|
|
4514
|
-
return;
|
|
4515
|
-
}
|
|
4516
|
-
moveBlockActionImplementation({
|
|
4517
|
-
action: {
|
|
4518
|
-
at: action.at,
|
|
4519
|
-
to: [{
|
|
4520
|
-
_key: destinationBlockKey
|
|
4521
|
-
}],
|
|
4522
|
-
editor: action.editor
|
|
4523
|
-
}
|
|
4524
|
-
});
|
|
4525
|
-
}, moveBlockUpActionImplementation = ({
|
|
4526
|
-
context,
|
|
4527
|
-
action
|
|
4528
|
-
}) => {
|
|
4529
|
-
const at = [toSlatePath(action.at, action.editor)[0]];
|
|
4530
|
-
if (!Path.hasPrevious(at))
|
|
4531
|
-
return;
|
|
4532
|
-
const to = [Path.previous(at)[0]], selection = toPortableTextRange(action.editor.children, {
|
|
4533
|
-
anchor: {
|
|
4534
|
-
path: to,
|
|
4535
|
-
offset: 0
|
|
4536
|
-
},
|
|
4537
|
-
focus: {
|
|
4538
|
-
path: to,
|
|
4539
|
-
offset: 0
|
|
4540
|
-
}
|
|
4541
|
-
}, context.schema), destinationBlockKey = selection && isKeyedSegment$1(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
|
|
4542
|
-
if (destinationBlockKey === void 0) {
|
|
4543
|
-
console.error("Could not find destination block key");
|
|
4544
|
-
return;
|
|
4545
|
-
}
|
|
4546
|
-
moveBlockActionImplementation({
|
|
4547
|
-
action: {
|
|
4548
|
-
at: action.at,
|
|
4549
|
-
to: [{
|
|
4550
|
-
_key: destinationBlockKey
|
|
4551
|
-
}],
|
|
4552
|
-
editor: action.editor
|
|
4553
|
-
}
|
|
4554
|
-
});
|
|
4555
4452
|
}, noopActionImplementation = () => {
|
|
4556
4453
|
}, selectActionImplementation = ({
|
|
4557
4454
|
action
|
|
@@ -4561,13 +4458,11 @@ const insertTextActionImplementation = ({
|
|
|
4561
4458
|
}, debug$9 = debugWithName("behaviors:action"), behaviorActionImplementations = {
|
|
4562
4459
|
"annotation.add": addAnnotationActionImplementation,
|
|
4563
4460
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
4564
|
-
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
4565
4461
|
"block.set": blockSetBehaviorActionImplementation,
|
|
4566
4462
|
"block.unset": blockUnsetBehaviorActionImplementation,
|
|
4567
4463
|
blur: blurActionImplementation,
|
|
4568
4464
|
"decorator.add": decoratorAddActionImplementation,
|
|
4569
4465
|
"decorator.remove": removeDecoratorActionImplementation,
|
|
4570
|
-
"decorator.toggle": toggleDecoratorActionImplementation,
|
|
4571
4466
|
focus: focusActionImplementation,
|
|
4572
4467
|
delete: deleteActionImplementation,
|
|
4573
4468
|
"delete.backward": deleteBackwardActionImplementation,
|
|
@@ -4584,8 +4479,6 @@ const insertTextActionImplementation = ({
|
|
|
4584
4479
|
"insert.text": insertTextActionImplementation,
|
|
4585
4480
|
effect: effectActionImplementation,
|
|
4586
4481
|
"move.block": moveBlockActionImplementation,
|
|
4587
|
-
"move.block down": moveBlockDownActionImplementation,
|
|
4588
|
-
"move.block up": moveBlockUpActionImplementation,
|
|
4589
4482
|
noop: noopActionImplementation,
|
|
4590
4483
|
select: selectActionImplementation
|
|
4591
4484
|
};
|
|
@@ -4608,13 +4501,6 @@ function performAction({
|
|
|
4608
4501
|
});
|
|
4609
4502
|
break;
|
|
4610
4503
|
}
|
|
4611
|
-
case "annotation.toggle": {
|
|
4612
|
-
behaviorActionImplementations["annotation.toggle"]({
|
|
4613
|
-
context,
|
|
4614
|
-
action
|
|
4615
|
-
});
|
|
4616
|
-
break;
|
|
4617
|
-
}
|
|
4618
4504
|
case "block.set": {
|
|
4619
4505
|
behaviorActionImplementations["block.set"]({
|
|
4620
4506
|
context,
|
|
@@ -4650,13 +4536,6 @@ function performAction({
|
|
|
4650
4536
|
});
|
|
4651
4537
|
break;
|
|
4652
4538
|
}
|
|
4653
|
-
case "decorator.toggle": {
|
|
4654
|
-
behaviorActionImplementations["decorator.toggle"]({
|
|
4655
|
-
context,
|
|
4656
|
-
action
|
|
4657
|
-
});
|
|
4658
|
-
break;
|
|
4659
|
-
}
|
|
4660
4539
|
case "delete": {
|
|
4661
4540
|
behaviorActionImplementations.delete({
|
|
4662
4541
|
context,
|
|
@@ -4769,20 +4648,6 @@ function performAction({
|
|
|
4769
4648
|
});
|
|
4770
4649
|
break;
|
|
4771
4650
|
}
|
|
4772
|
-
case "move.block down": {
|
|
4773
|
-
behaviorActionImplementations["move.block down"]({
|
|
4774
|
-
context,
|
|
4775
|
-
action
|
|
4776
|
-
});
|
|
4777
|
-
break;
|
|
4778
|
-
}
|
|
4779
|
-
case "move.block up": {
|
|
4780
|
-
behaviorActionImplementations["move.block up"]({
|
|
4781
|
-
context,
|
|
4782
|
-
action
|
|
4783
|
-
});
|
|
4784
|
-
break;
|
|
4785
|
-
}
|
|
4786
4651
|
case "noop":
|
|
4787
4652
|
break;
|
|
4788
4653
|
default: {
|
|
@@ -4794,65 +4659,10 @@ function performAction({
|
|
|
4794
4659
|
}
|
|
4795
4660
|
}
|
|
4796
4661
|
}
|
|
4797
|
-
function createWithEventListeners(editorActor
|
|
4662
|
+
function createWithEventListeners(editorActor) {
|
|
4798
4663
|
return function(editor) {
|
|
4799
4664
|
if (editorActor.getSnapshot().context.maxBlocks !== void 0)
|
|
4800
4665
|
return editor;
|
|
4801
|
-
subscriptions.push(() => {
|
|
4802
|
-
const subscription = editorActor.on("*", (event) => {
|
|
4803
|
-
switch (event.type) {
|
|
4804
|
-
// These events are not relevant for Behaviors
|
|
4805
|
-
case "blurred":
|
|
4806
|
-
case "done loading":
|
|
4807
|
-
case "editable":
|
|
4808
|
-
case "error":
|
|
4809
|
-
case "focused":
|
|
4810
|
-
case "invalid value":
|
|
4811
|
-
case "loading":
|
|
4812
|
-
case "mutation":
|
|
4813
|
-
case "patch":
|
|
4814
|
-
case "internal.patch":
|
|
4815
|
-
case "patches":
|
|
4816
|
-
case "read only":
|
|
4817
|
-
case "ready":
|
|
4818
|
-
case "selection":
|
|
4819
|
-
case "value changed":
|
|
4820
|
-
case "unset":
|
|
4821
|
-
break;
|
|
4822
|
-
case "custom.*":
|
|
4823
|
-
editorActor.send({
|
|
4824
|
-
type: "custom behavior event",
|
|
4825
|
-
behaviorEvent: event.event,
|
|
4826
|
-
editor
|
|
4827
|
-
});
|
|
4828
|
-
break;
|
|
4829
|
-
case "insert.block object":
|
|
4830
|
-
editorActor.send({
|
|
4831
|
-
type: "behavior event",
|
|
4832
|
-
behaviorEvent: {
|
|
4833
|
-
type: "insert.block",
|
|
4834
|
-
block: {
|
|
4835
|
-
_type: event.blockObject.name,
|
|
4836
|
-
...event.blockObject.value ?? {}
|
|
4837
|
-
},
|
|
4838
|
-
placement: event.placement
|
|
4839
|
-
},
|
|
4840
|
-
editor
|
|
4841
|
-
});
|
|
4842
|
-
break;
|
|
4843
|
-
default:
|
|
4844
|
-
editorActor.send({
|
|
4845
|
-
type: "behavior event",
|
|
4846
|
-
behaviorEvent: event,
|
|
4847
|
-
editor
|
|
4848
|
-
});
|
|
4849
|
-
break;
|
|
4850
|
-
}
|
|
4851
|
-
});
|
|
4852
|
-
return () => {
|
|
4853
|
-
subscription.unsubscribe();
|
|
4854
|
-
};
|
|
4855
|
-
});
|
|
4856
4666
|
const {
|
|
4857
4667
|
deleteBackward,
|
|
4858
4668
|
deleteForward,
|
|
@@ -5663,7 +5473,7 @@ const withPlugins = (editor, options) => {
|
|
|
5663
5473
|
editorActor,
|
|
5664
5474
|
schemaTypes
|
|
5665
5475
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
|
|
5666
|
-
return createWithEventListeners(editorActor
|
|
5476
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5667
5477
|
}, debug$3 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
5668
5478
|
function createSlateEditor(config) {
|
|
5669
5479
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
@@ -5685,17 +5495,67 @@ function createSlateEditor(config) {
|
|
|
5685
5495
|
};
|
|
5686
5496
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
5687
5497
|
}
|
|
5688
|
-
const
|
|
5689
|
-
|
|
5690
|
-
}, raiseInsertSoftBreak = defineBehavior({
|
|
5691
|
-
on: "keyboard.keydown",
|
|
5498
|
+
const abstractAnnotationBehaviors = [defineBehavior({
|
|
5499
|
+
on: "annotation.toggle",
|
|
5692
5500
|
guard: ({
|
|
5501
|
+
snapshot,
|
|
5693
5502
|
event
|
|
5694
|
-
}) =>
|
|
5695
|
-
actions: [(
|
|
5696
|
-
|
|
5503
|
+
}) => isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5504
|
+
actions: [({
|
|
5505
|
+
event
|
|
5506
|
+
}) => [raise({
|
|
5507
|
+
type: "annotation.remove",
|
|
5508
|
+
annotation: event.annotation
|
|
5509
|
+
})]]
|
|
5510
|
+
}), defineBehavior({
|
|
5511
|
+
on: "annotation.toggle",
|
|
5512
|
+
guard: ({
|
|
5513
|
+
snapshot,
|
|
5514
|
+
event
|
|
5515
|
+
}) => !isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5516
|
+
actions: [({
|
|
5517
|
+
event
|
|
5518
|
+
}) => [raise({
|
|
5519
|
+
type: "annotation.add",
|
|
5520
|
+
annotation: event.annotation
|
|
5697
5521
|
})]]
|
|
5698
|
-
}),
|
|
5522
|
+
})], abstractDecoratorBehaviors = [defineBehavior({
|
|
5523
|
+
on: "decorator.toggle",
|
|
5524
|
+
guard: ({
|
|
5525
|
+
snapshot,
|
|
5526
|
+
event
|
|
5527
|
+
}) => isActiveDecorator(event.decorator)(snapshot),
|
|
5528
|
+
actions: [({
|
|
5529
|
+
event
|
|
5530
|
+
}) => [raise({
|
|
5531
|
+
type: "decorator.remove",
|
|
5532
|
+
decorator: event.decorator
|
|
5533
|
+
})]]
|
|
5534
|
+
}), defineBehavior({
|
|
5535
|
+
on: "decorator.toggle",
|
|
5536
|
+
guard: ({
|
|
5537
|
+
snapshot,
|
|
5538
|
+
event
|
|
5539
|
+
}) => {
|
|
5540
|
+
const manualSelection = event.offsets ? blockOffsetsToSelection({
|
|
5541
|
+
value: snapshot.context.value,
|
|
5542
|
+
offsets: event.offsets
|
|
5543
|
+
}) : null;
|
|
5544
|
+
return manualSelection ? !isActiveDecorator(event.decorator)({
|
|
5545
|
+
...snapshot,
|
|
5546
|
+
context: {
|
|
5547
|
+
...snapshot.context,
|
|
5548
|
+
selection: manualSelection
|
|
5549
|
+
}
|
|
5550
|
+
}) : !isActiveDecorator(event.decorator)(snapshot);
|
|
5551
|
+
},
|
|
5552
|
+
actions: [({
|
|
5553
|
+
event
|
|
5554
|
+
}) => [raise({
|
|
5555
|
+
...event,
|
|
5556
|
+
type: "decorator.add"
|
|
5557
|
+
})]]
|
|
5558
|
+
})], abstractInsertBehaviors = [defineBehavior({
|
|
5699
5559
|
on: "insert.blocks",
|
|
5700
5560
|
guard: ({
|
|
5701
5561
|
event
|
|
@@ -5771,7 +5631,7 @@ const keyIs = {
|
|
|
5771
5631
|
placement: index === 0 ? "auto" : "after",
|
|
5772
5632
|
select: "end"
|
|
5773
5633
|
}))]
|
|
5774
|
-
})],
|
|
5634
|
+
})], abstractListItemBehaviors = [defineBehavior({
|
|
5775
5635
|
on: "list item.add",
|
|
5776
5636
|
guard: ({
|
|
5777
5637
|
snapshot
|
|
@@ -5828,7 +5688,75 @@ const keyIs = {
|
|
|
5828
5688
|
type: "list item.add",
|
|
5829
5689
|
listItem: event.listItem
|
|
5830
5690
|
})]]
|
|
5831
|
-
})],
|
|
5691
|
+
})], abstractMoveBehaviors = [defineBehavior({
|
|
5692
|
+
on: "move.block up",
|
|
5693
|
+
guard: ({
|
|
5694
|
+
snapshot,
|
|
5695
|
+
event
|
|
5696
|
+
}) => {
|
|
5697
|
+
const previousBlock = getPreviousBlock({
|
|
5698
|
+
context: {
|
|
5699
|
+
...snapshot.context,
|
|
5700
|
+
selection: {
|
|
5701
|
+
anchor: {
|
|
5702
|
+
path: event.at,
|
|
5703
|
+
offset: 0
|
|
5704
|
+
},
|
|
5705
|
+
focus: {
|
|
5706
|
+
path: event.at,
|
|
5707
|
+
offset: 0
|
|
5708
|
+
}
|
|
5709
|
+
}
|
|
5710
|
+
}
|
|
5711
|
+
});
|
|
5712
|
+
return previousBlock ? {
|
|
5713
|
+
previousBlock
|
|
5714
|
+
} : !1;
|
|
5715
|
+
},
|
|
5716
|
+
actions: [({
|
|
5717
|
+
event
|
|
5718
|
+
}, {
|
|
5719
|
+
previousBlock
|
|
5720
|
+
}) => [raise({
|
|
5721
|
+
type: "move.block",
|
|
5722
|
+
at: event.at,
|
|
5723
|
+
to: previousBlock.path
|
|
5724
|
+
})]]
|
|
5725
|
+
}), defineBehavior({
|
|
5726
|
+
on: "move.block down",
|
|
5727
|
+
guard: ({
|
|
5728
|
+
snapshot,
|
|
5729
|
+
event
|
|
5730
|
+
}) => {
|
|
5731
|
+
const nextBlock = getNextBlock({
|
|
5732
|
+
context: {
|
|
5733
|
+
...snapshot.context,
|
|
5734
|
+
selection: {
|
|
5735
|
+
anchor: {
|
|
5736
|
+
path: event.at,
|
|
5737
|
+
offset: 0
|
|
5738
|
+
},
|
|
5739
|
+
focus: {
|
|
5740
|
+
path: event.at,
|
|
5741
|
+
offset: 0
|
|
5742
|
+
}
|
|
5743
|
+
}
|
|
5744
|
+
}
|
|
5745
|
+
});
|
|
5746
|
+
return nextBlock ? {
|
|
5747
|
+
nextBlock
|
|
5748
|
+
} : !1;
|
|
5749
|
+
},
|
|
5750
|
+
actions: [({
|
|
5751
|
+
event
|
|
5752
|
+
}, {
|
|
5753
|
+
nextBlock
|
|
5754
|
+
}) => [raise({
|
|
5755
|
+
type: "move.block",
|
|
5756
|
+
at: event.at,
|
|
5757
|
+
to: nextBlock.path
|
|
5758
|
+
})]]
|
|
5759
|
+
})], abstractSelectBehaviors = [defineBehavior({
|
|
5832
5760
|
on: "select.previous block",
|
|
5833
5761
|
guard: ({
|
|
5834
5762
|
snapshot,
|
|
@@ -5874,7 +5802,7 @@ const keyIs = {
|
|
|
5874
5802
|
type: "select",
|
|
5875
5803
|
selection
|
|
5876
5804
|
})]]
|
|
5877
|
-
})],
|
|
5805
|
+
})], abstractStyleBehaviors = [defineBehavior({
|
|
5878
5806
|
on: "style.add",
|
|
5879
5807
|
guard: ({
|
|
5880
5808
|
snapshot
|
|
@@ -5930,65 +5858,15 @@ const keyIs = {
|
|
|
5930
5858
|
type: "style.add",
|
|
5931
5859
|
style: event.style
|
|
5932
5860
|
})]]
|
|
5933
|
-
})],
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
event
|
|
5938
|
-
}) => isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5939
|
-
actions: [({
|
|
5940
|
-
event
|
|
5941
|
-
}) => [raise({
|
|
5942
|
-
type: "annotation.remove",
|
|
5943
|
-
annotation: event.annotation
|
|
5944
|
-
})]]
|
|
5945
|
-
}), toggleAnnotationOn = defineBehavior({
|
|
5946
|
-
on: "annotation.toggle",
|
|
5947
|
-
guard: ({
|
|
5948
|
-
snapshot,
|
|
5949
|
-
event
|
|
5950
|
-
}) => !isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5951
|
-
actions: [({
|
|
5952
|
-
event
|
|
5953
|
-
}) => [raise({
|
|
5954
|
-
type: "annotation.add",
|
|
5955
|
-
annotation: event.annotation
|
|
5956
|
-
})]]
|
|
5957
|
-
}), toggleDecoratorOff = defineBehavior({
|
|
5958
|
-
on: "decorator.toggle",
|
|
5959
|
-
guard: ({
|
|
5960
|
-
snapshot,
|
|
5961
|
-
event
|
|
5962
|
-
}) => isActiveDecorator(event.decorator)(snapshot),
|
|
5963
|
-
actions: [({
|
|
5964
|
-
event
|
|
5965
|
-
}) => [raise({
|
|
5966
|
-
type: "decorator.remove",
|
|
5967
|
-
decorator: event.decorator
|
|
5968
|
-
})]]
|
|
5969
|
-
}), toggleDecoratorOn = defineBehavior({
|
|
5970
|
-
on: "decorator.toggle",
|
|
5861
|
+
})], keyIs = {
|
|
5862
|
+
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
5863
|
+
}, raiseInsertSoftBreak = defineBehavior({
|
|
5864
|
+
on: "keyboard.keydown",
|
|
5971
5865
|
guard: ({
|
|
5972
|
-
snapshot,
|
|
5973
|
-
event
|
|
5974
|
-
}) => {
|
|
5975
|
-
const manualSelection = event.offsets ? blockOffsetsToSelection({
|
|
5976
|
-
value: snapshot.context.value,
|
|
5977
|
-
offsets: event.offsets
|
|
5978
|
-
}) : null;
|
|
5979
|
-
return manualSelection ? !isActiveDecorator(event.decorator)({
|
|
5980
|
-
...snapshot,
|
|
5981
|
-
context: {
|
|
5982
|
-
...snapshot.context,
|
|
5983
|
-
selection: manualSelection
|
|
5984
|
-
}
|
|
5985
|
-
}) : !isActiveDecorator(event.decorator)(snapshot);
|
|
5986
|
-
},
|
|
5987
|
-
actions: [({
|
|
5988
5866
|
event
|
|
5989
|
-
}) =>
|
|
5990
|
-
|
|
5991
|
-
type: "
|
|
5867
|
+
}) => keyIs.lineBreak(event.originEvent),
|
|
5868
|
+
actions: [() => [raise({
|
|
5869
|
+
type: "insert.soft break"
|
|
5992
5870
|
})]]
|
|
5993
5871
|
}), raiseDeserializationSuccessOrFailure = defineBehavior({
|
|
5994
5872
|
on: "deserialize",
|
|
@@ -6318,45 +6196,30 @@ const keyIs = {
|
|
|
6318
6196
|
originEvent: event
|
|
6319
6197
|
})]]
|
|
6320
6198
|
}),
|
|
6321
|
-
...
|
|
6322
|
-
...
|
|
6323
|
-
...
|
|
6324
|
-
...
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
toggleDecoratorOn,
|
|
6199
|
+
...abstractAnnotationBehaviors,
|
|
6200
|
+
...abstractDecoratorBehaviors,
|
|
6201
|
+
...abstractInsertBehaviors,
|
|
6202
|
+
...abstractListItemBehaviors,
|
|
6203
|
+
...abstractMoveBehaviors,
|
|
6204
|
+
...abstractStyleBehaviors,
|
|
6205
|
+
...abstractSelectBehaviors,
|
|
6329
6206
|
raiseDeserializationSuccessOrFailure,
|
|
6330
6207
|
raiseSerializationSuccessOrFailure,
|
|
6331
6208
|
raiseInsertSoftBreak
|
|
6332
|
-
];
|
|
6333
|
-
function
|
|
6334
|
-
return event.type
|
|
6335
|
-
}
|
|
6336
|
-
function isInternalBehaviorEvent(event) {
|
|
6337
|
-
return event.type === "deserialize" || event.type.startsWith("deserialization.") || event.type === "insert.blocks" || event.type.startsWith("list item.") || event.type === "serialize" || event.type.startsWith("serialization.") || event.type === "select.next block" || event.type === "select.previous block" || event.type.startsWith("style.");
|
|
6209
|
+
], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "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"];
|
|
6210
|
+
function isAbstractBehaviorEvent(event) {
|
|
6211
|
+
return abstractBehaviorEventTypes.includes(event.type);
|
|
6338
6212
|
}
|
|
6213
|
+
const nativeBehaviorEventTypes = ["clipboard.copy", "clipboard.cut", "clipboard.paste", "drag.dragstart", "drag.drag", "drag.dragend", "drag.dragenter", "drag.dragover", "drag.dragleave", "drag.drop", "input.*", "keyboard.keydown", "keyboard.keyup", "mouse.click"];
|
|
6339
6214
|
function isNativeBehaviorEvent(event) {
|
|
6340
|
-
return
|
|
6341
|
-
}
|
|
6342
|
-
function isClipboardBehaviorEvent(event) {
|
|
6343
|
-
return event.type.startsWith("clipboard.");
|
|
6344
|
-
}
|
|
6345
|
-
function isDragBehaviorEvent(event) {
|
|
6346
|
-
return event.type.startsWith("drag.");
|
|
6347
|
-
}
|
|
6348
|
-
function isInputBehaviorEvent(event) {
|
|
6349
|
-
return event.type.startsWith("input.");
|
|
6350
|
-
}
|
|
6351
|
-
function isMouseBehaviorEvent(event) {
|
|
6352
|
-
return event.type.startsWith("mouse.");
|
|
6215
|
+
return nativeBehaviorEventTypes.includes(event.type);
|
|
6353
6216
|
}
|
|
6354
6217
|
function isCustomBehaviorEvent(event) {
|
|
6355
6218
|
return event.type.startsWith("custom.");
|
|
6356
6219
|
}
|
|
6357
6220
|
const debug$2 = debugWithName("behaviors:event");
|
|
6358
6221
|
function eventCategory(event) {
|
|
6359
|
-
return isNativeBehaviorEvent(event) ? "native" :
|
|
6222
|
+
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "abstract" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
6360
6223
|
}
|
|
6361
6224
|
function performEvent({
|
|
6362
6225
|
behaviors,
|
|
@@ -6369,7 +6232,7 @@ function performEvent({
|
|
|
6369
6232
|
defaultActionCallback
|
|
6370
6233
|
}) {
|
|
6371
6234
|
debug$2(`(${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
6372
|
-
const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) ||
|
|
6235
|
+
const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isAbstractBehaviorEvent(event) ? void 0 : {
|
|
6373
6236
|
...event,
|
|
6374
6237
|
editor
|
|
6375
6238
|
}, eventBehaviors = behaviors.filter((behavior) => {
|
|
@@ -6488,6 +6351,34 @@ function performEvent({
|
|
|
6488
6351
|
}), editor.onChange();
|
|
6489
6352
|
}
|
|
6490
6353
|
}
|
|
6354
|
+
function slateChildrenToBlocks(schema, value) {
|
|
6355
|
+
const blocks = new Array(value.length);
|
|
6356
|
+
for (let blockIndex = 0; blockIndex < value.length; blockIndex++) {
|
|
6357
|
+
const descendant = value[blockIndex];
|
|
6358
|
+
if (descendant._type !== schema.block.name) {
|
|
6359
|
+
blocks[blockIndex] = {
|
|
6360
|
+
_key: descendant._key,
|
|
6361
|
+
_type: descendant._type,
|
|
6362
|
+
..."value" in descendant && typeof descendant.value == "object" ? descendant.value : {}
|
|
6363
|
+
};
|
|
6364
|
+
continue;
|
|
6365
|
+
}
|
|
6366
|
+
const children = "children" in descendant ? descendant.children : [], processedChildren = new Array(children.length);
|
|
6367
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
6368
|
+
const child = children[childIndex];
|
|
6369
|
+
processedChildren[childIndex] = child._type === schema.span.name ? child : {
|
|
6370
|
+
_key: child._key,
|
|
6371
|
+
_type: child._type,
|
|
6372
|
+
..."value" in child && typeof child.value == "object" ? child.value : {}
|
|
6373
|
+
};
|
|
6374
|
+
}
|
|
6375
|
+
blocks[blockIndex] = {
|
|
6376
|
+
...descendant,
|
|
6377
|
+
children: processedChildren
|
|
6378
|
+
};
|
|
6379
|
+
}
|
|
6380
|
+
return blocks;
|
|
6381
|
+
}
|
|
6491
6382
|
function getActiveDecorators({
|
|
6492
6383
|
schema,
|
|
6493
6384
|
slateEditorInstance
|
|
@@ -6506,7 +6397,7 @@ function createEditorSnapshot({
|
|
|
6506
6397
|
hasTag,
|
|
6507
6398
|
internalDrag
|
|
6508
6399
|
}) {
|
|
6509
|
-
const value =
|
|
6400
|
+
const value = slateChildrenToBlocks(schema, editor.children), selection = toPortableTextRange(value, editor.selection, schema);
|
|
6510
6401
|
return {
|
|
6511
6402
|
context: {
|
|
6512
6403
|
activeDecorators: getActiveDecorators({
|
|
@@ -6602,7 +6493,7 @@ const editorMachine = setup({
|
|
|
6602
6493
|
event,
|
|
6603
6494
|
self
|
|
6604
6495
|
}) => {
|
|
6605
|
-
assertEvent(event, ["behavior event"
|
|
6496
|
+
assertEvent(event, ["behavior event"]), performEvent({
|
|
6606
6497
|
behaviors: [...context.behaviors.values(), ...defaultBehaviors],
|
|
6607
6498
|
event: event.behaviorEvent,
|
|
6608
6499
|
editor: event.editor,
|
|
@@ -6801,87 +6692,6 @@ const editorMachine = setup({
|
|
|
6801
6692
|
},
|
|
6802
6693
|
"behavior event": {
|
|
6803
6694
|
actions: "handle behavior event"
|
|
6804
|
-
},
|
|
6805
|
-
"custom behavior event": {
|
|
6806
|
-
actions: "handle behavior event"
|
|
6807
|
-
},
|
|
6808
|
-
"annotation.*": {
|
|
6809
|
-
actions: emit(({
|
|
6810
|
-
event
|
|
6811
|
-
}) => event)
|
|
6812
|
-
},
|
|
6813
|
-
"block.*": {
|
|
6814
|
-
actions: emit(({
|
|
6815
|
-
event
|
|
6816
|
-
}) => event)
|
|
6817
|
-
},
|
|
6818
|
-
blur: {
|
|
6819
|
-
actions: emit(({
|
|
6820
|
-
event
|
|
6821
|
-
}) => event)
|
|
6822
|
-
},
|
|
6823
|
-
"custom.*": {
|
|
6824
|
-
actions: emit(({
|
|
6825
|
-
event
|
|
6826
|
-
}) => ({
|
|
6827
|
-
type: "custom.*",
|
|
6828
|
-
event
|
|
6829
|
-
}))
|
|
6830
|
-
},
|
|
6831
|
-
"decorator.*": {
|
|
6832
|
-
actions: emit(({
|
|
6833
|
-
event
|
|
6834
|
-
}) => event)
|
|
6835
|
-
},
|
|
6836
|
-
"delete.*": {
|
|
6837
|
-
actions: emit(({
|
|
6838
|
-
event
|
|
6839
|
-
}) => event)
|
|
6840
|
-
},
|
|
6841
|
-
focus: {
|
|
6842
|
-
actions: emit(({
|
|
6843
|
-
event
|
|
6844
|
-
}) => event)
|
|
6845
|
-
},
|
|
6846
|
-
"history.*": {
|
|
6847
|
-
actions: emit(({
|
|
6848
|
-
event
|
|
6849
|
-
}) => event)
|
|
6850
|
-
},
|
|
6851
|
-
"insert.*": {
|
|
6852
|
-
actions: emit(({
|
|
6853
|
-
event
|
|
6854
|
-
}) => event)
|
|
6855
|
-
},
|
|
6856
|
-
"list item.*": {
|
|
6857
|
-
actions: emit(({
|
|
6858
|
-
event
|
|
6859
|
-
}) => event)
|
|
6860
|
-
},
|
|
6861
|
-
"move.*": {
|
|
6862
|
-
actions: emit(({
|
|
6863
|
-
event
|
|
6864
|
-
}) => event)
|
|
6865
|
-
},
|
|
6866
|
-
select: {
|
|
6867
|
-
actions: emit(({
|
|
6868
|
-
event
|
|
6869
|
-
}) => event)
|
|
6870
|
-
},
|
|
6871
|
-
"select.*": {
|
|
6872
|
-
actions: emit(({
|
|
6873
|
-
event
|
|
6874
|
-
}) => event)
|
|
6875
|
-
},
|
|
6876
|
-
"style.*": {
|
|
6877
|
-
actions: emit(({
|
|
6878
|
-
event
|
|
6879
|
-
}) => event)
|
|
6880
|
-
},
|
|
6881
|
-
"text block.*": {
|
|
6882
|
-
actions: emit(({
|
|
6883
|
-
event
|
|
6884
|
-
}) => event)
|
|
6885
6695
|
}
|
|
6886
6696
|
},
|
|
6887
6697
|
initial: "idle",
|
|
@@ -6993,12 +6803,6 @@ const editorMachine = setup({
|
|
|
6993
6803
|
}
|
|
6994
6804
|
}
|
|
6995
6805
|
});
|
|
6996
|
-
function getValue({
|
|
6997
|
-
editorActorSnapshot,
|
|
6998
|
-
slateEditorInstance
|
|
6999
|
-
}) {
|
|
7000
|
-
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
7001
|
-
}
|
|
7002
6806
|
function defaultCompare(a, b) {
|
|
7003
6807
|
return a === b;
|
|
7004
6808
|
}
|
|
@@ -7030,10 +6834,7 @@ function getEditorSnapshot({
|
|
|
7030
6834
|
}),
|
|
7031
6835
|
schema: editorActorSnapshot.context.schema,
|
|
7032
6836
|
selection: editorActorSnapshot.context.selection,
|
|
7033
|
-
value:
|
|
7034
|
-
editorActorSnapshot,
|
|
7035
|
-
slateEditorInstance
|
|
7036
|
-
})
|
|
6837
|
+
value: slateChildrenToBlocks(editorActorSnapshot.context.schema, slateEditorInstance.children)
|
|
7037
6838
|
},
|
|
7038
6839
|
beta: {
|
|
7039
6840
|
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
@@ -7089,7 +6890,39 @@ function createInternalEditorFromActor(editorActor) {
|
|
|
7089
6890
|
});
|
|
7090
6891
|
}),
|
|
7091
6892
|
send: (event) => {
|
|
7092
|
-
|
|
6893
|
+
switch (event.type) {
|
|
6894
|
+
case "add behavior":
|
|
6895
|
+
case "remove behavior":
|
|
6896
|
+
case "update behaviors":
|
|
6897
|
+
case "update key generator":
|
|
6898
|
+
case "update readOnly":
|
|
6899
|
+
case "patches":
|
|
6900
|
+
case "update value":
|
|
6901
|
+
case "update schema":
|
|
6902
|
+
case "update maxBlocks":
|
|
6903
|
+
editorActor.send(event);
|
|
6904
|
+
break;
|
|
6905
|
+
case "insert.block object":
|
|
6906
|
+
editorActor.send({
|
|
6907
|
+
type: "behavior event",
|
|
6908
|
+
behaviorEvent: {
|
|
6909
|
+
type: "insert.block",
|
|
6910
|
+
block: {
|
|
6911
|
+
_type: event.blockObject.name,
|
|
6912
|
+
...event.blockObject.value ?? {}
|
|
6913
|
+
},
|
|
6914
|
+
placement: event.placement
|
|
6915
|
+
},
|
|
6916
|
+
editor: slateEditor.instance
|
|
6917
|
+
});
|
|
6918
|
+
break;
|
|
6919
|
+
default:
|
|
6920
|
+
editorActor.send({
|
|
6921
|
+
type: "behavior event",
|
|
6922
|
+
behaviorEvent: event,
|
|
6923
|
+
editor: slateEditor.instance
|
|
6924
|
+
});
|
|
6925
|
+
}
|
|
7093
6926
|
},
|
|
7094
6927
|
on: (event, listener) => editorActor.on(event, (event2) => {
|
|
7095
6928
|
switch (event2.type) {
|