@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
|
@@ -315,10 +315,7 @@ function isEqualToEmptyEditor(children, schemaTypes) {
|
|
|
315
315
|
function getFocusBlock({
|
|
316
316
|
editor
|
|
317
317
|
}) {
|
|
318
|
-
return editor.selection ?
|
|
319
|
-
at: editor.selection.focus.path.slice(0, 1),
|
|
320
|
-
match: (n) => !slate.Editor.isEditor(n)
|
|
321
|
-
})).at(0) ?? [void 0, void 0] : [void 0, void 0];
|
|
318
|
+
return editor.selection ? slate.Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0] : [void 0, void 0];
|
|
322
319
|
}
|
|
323
320
|
function getFocusChild({
|
|
324
321
|
editor
|
|
@@ -2979,112 +2976,6 @@ function isPortableTextBlock(node) {
|
|
|
2979
2976
|
node.children.every((child) => typeof child == "object" && "_type" in child)
|
|
2980
2977
|
);
|
|
2981
2978
|
}
|
|
2982
|
-
const decoratorAddActionImplementation = ({
|
|
2983
|
-
context,
|
|
2984
|
-
action
|
|
2985
|
-
}) => {
|
|
2986
|
-
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 ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
2987
|
-
value,
|
|
2988
|
-
blockOffset: action.offsets.anchor,
|
|
2989
|
-
direction: "backward"
|
|
2990
|
-
}) : void 0, manualFocus = action.offsets?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
2991
|
-
value,
|
|
2992
|
-
blockOffset: action.offsets.focus,
|
|
2993
|
-
direction: "forward"
|
|
2994
|
-
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
2995
|
-
anchor: manualAnchor,
|
|
2996
|
-
focus: manualFocus
|
|
2997
|
-
} : void 0, selection = manualSelection ? toSlateRange(manualSelection, action.editor) ?? editor.selection : editor.selection;
|
|
2998
|
-
if (!selection)
|
|
2999
|
-
return;
|
|
3000
|
-
const editorSelection = toPortableTextRange(value, selection, context.schema), anchorOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
|
|
3001
|
-
value,
|
|
3002
|
-
selectionPoint: editorSelection.anchor
|
|
3003
|
-
}) : void 0, focusOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
|
|
3004
|
-
value,
|
|
3005
|
-
selectionPoint: editorSelection.focus
|
|
3006
|
-
}) : void 0;
|
|
3007
|
-
if (!anchorOffset || !focusOffset)
|
|
3008
|
-
throw new Error("Unable to find anchor or focus offset");
|
|
3009
|
-
if (slate.Range.isExpanded(selection)) {
|
|
3010
|
-
slate.Transforms.setNodes(editor, {}, {
|
|
3011
|
-
at: selection,
|
|
3012
|
-
match: slate.Text.isText,
|
|
3013
|
-
split: !0,
|
|
3014
|
-
hanging: !0
|
|
3015
|
-
});
|
|
3016
|
-
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
3017
|
-
value: newValue,
|
|
3018
|
-
offsets: {
|
|
3019
|
-
anchor: anchorOffset,
|
|
3020
|
-
focus: focusOffset
|
|
3021
|
-
},
|
|
3022
|
-
backward: editorSelection?.backward
|
|
3023
|
-
}), trimmedSelection = selector_isSelectingEntireBlocks.getTrimmedSelection({
|
|
3024
|
-
context: {
|
|
3025
|
-
activeDecorators: [],
|
|
3026
|
-
converters: [],
|
|
3027
|
-
keyGenerator: context.keyGenerator,
|
|
3028
|
-
readOnly: !1,
|
|
3029
|
-
schema: context.schema,
|
|
3030
|
-
selection: newSelection,
|
|
3031
|
-
value: newValue
|
|
3032
|
-
}
|
|
3033
|
-
});
|
|
3034
|
-
if (!trimmedSelection)
|
|
3035
|
-
throw new Error("Unable to find trimmed selection");
|
|
3036
|
-
const newRange = toSlateRange(trimmedSelection, editor);
|
|
3037
|
-
if (!newRange)
|
|
3038
|
-
throw new Error("Unable to find new selection");
|
|
3039
|
-
const splitTextNodes = slate.Range.isRange(newRange) ? [...slate.Editor.nodes(editor, {
|
|
3040
|
-
at: newRange,
|
|
3041
|
-
match: (node) => slate.Text.isText(node)
|
|
3042
|
-
})] : [];
|
|
3043
|
-
for (const [node, path] of splitTextNodes) {
|
|
3044
|
-
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
3045
|
-
slate.Transforms.setNodes(editor, {
|
|
3046
|
-
marks
|
|
3047
|
-
}, {
|
|
3048
|
-
at: path,
|
|
3049
|
-
match: slate.Text.isText,
|
|
3050
|
-
split: !0,
|
|
3051
|
-
hanging: !0
|
|
3052
|
-
});
|
|
3053
|
-
}
|
|
3054
|
-
} else {
|
|
3055
|
-
if (!Array.from(slate.Editor.nodes(editor, {
|
|
3056
|
-
at: selection,
|
|
3057
|
-
match: (node) => editor.isTextSpan(node)
|
|
3058
|
-
}))?.at(0))
|
|
3059
|
-
return;
|
|
3060
|
-
const [block, blockPath] = slate.Editor.node(editor, selection, {
|
|
3061
|
-
depth: 1
|
|
3062
|
-
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
3063
|
-
if (lonelyEmptySpan) {
|
|
3064
|
-
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
3065
|
-
slate.Transforms.setNodes(editor, {
|
|
3066
|
-
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
3067
|
-
}, {
|
|
3068
|
-
at: blockPath,
|
|
3069
|
-
match: (node) => editor.isTextSpan(node)
|
|
3070
|
-
});
|
|
3071
|
-
} else {
|
|
3072
|
-
const existingMarks = {
|
|
3073
|
-
...slate.Editor.marks(editor) || {}
|
|
3074
|
-
}.marks || [], marks = {
|
|
3075
|
-
...slate.Editor.marks(editor) || {},
|
|
3076
|
-
marks: [...existingMarks, mark]
|
|
3077
|
-
};
|
|
3078
|
-
editor.marks = marks;
|
|
3079
|
-
}
|
|
3080
|
-
}
|
|
3081
|
-
if (editor.selection) {
|
|
3082
|
-
const selection2 = editor.selection;
|
|
3083
|
-
editor.selection = {
|
|
3084
|
-
...selection2
|
|
3085
|
-
};
|
|
3086
|
-
}
|
|
3087
|
-
};
|
|
3088
2979
|
function getPreviousSpan({
|
|
3089
2980
|
editor,
|
|
3090
2981
|
blockPath,
|
|
@@ -3542,25 +3433,7 @@ function isDecoratorActive({
|
|
|
3542
3433
|
...slate.Editor.marks(editor) || {}
|
|
3543
3434
|
}.marks || []).includes(decorator);
|
|
3544
3435
|
}
|
|
3545
|
-
const
|
|
3546
|
-
context,
|
|
3547
|
-
action
|
|
3548
|
-
}) => {
|
|
3549
|
-
isDecoratorActive({
|
|
3550
|
-
editor: action.editor,
|
|
3551
|
-
decorator: action.decorator
|
|
3552
|
-
}) ? removeDecoratorActionImplementation({
|
|
3553
|
-
action: {
|
|
3554
|
-
editor: action.editor,
|
|
3555
|
-
decorator: action.decorator
|
|
3556
|
-
}
|
|
3557
|
-
}) : decoratorAddActionImplementation({
|
|
3558
|
-
context,
|
|
3559
|
-
action: {
|
|
3560
|
-
...action
|
|
3561
|
-
}
|
|
3562
|
-
});
|
|
3563
|
-
}, debug$a = debugWithName("API:editable");
|
|
3436
|
+
const debug$a = debugWithName("API:editable");
|
|
3564
3437
|
function createEditableAPI(editor, editorActor) {
|
|
3565
3438
|
const types2 = editorActor.getSnapshot().context.schema;
|
|
3566
3439
|
return {
|
|
@@ -4031,30 +3904,6 @@ const addAnnotationActionImplementation = ({
|
|
|
4031
3904
|
}
|
|
4032
3905
|
}
|
|
4033
3906
|
}
|
|
4034
|
-
}, toggleAnnotationActionImplementation = ({
|
|
4035
|
-
context,
|
|
4036
|
-
action
|
|
4037
|
-
}) => {
|
|
4038
|
-
if (isAnnotationActive({
|
|
4039
|
-
editor: action.editor,
|
|
4040
|
-
annotation: {
|
|
4041
|
-
name: action.annotation.name
|
|
4042
|
-
}
|
|
4043
|
-
}))
|
|
4044
|
-
removeAnnotationActionImplementation({
|
|
4045
|
-
action: {
|
|
4046
|
-
annotation: action.annotation,
|
|
4047
|
-
editor: action.editor
|
|
4048
|
-
}
|
|
4049
|
-
});
|
|
4050
|
-
else
|
|
4051
|
-
return addAnnotationActionImplementation({
|
|
4052
|
-
context,
|
|
4053
|
-
action: {
|
|
4054
|
-
annotation: action.annotation,
|
|
4055
|
-
editor: action.editor
|
|
4056
|
-
}
|
|
4057
|
-
});
|
|
4058
3907
|
}, blockSetBehaviorActionImplementation = ({
|
|
4059
3908
|
context,
|
|
4060
3909
|
action
|
|
@@ -4169,6 +4018,111 @@ const addAnnotationActionImplementation = ({
|
|
|
4169
4018
|
action
|
|
4170
4019
|
}) => {
|
|
4171
4020
|
slateReact.ReactEditor.blur(action.editor);
|
|
4021
|
+
}, decoratorAddActionImplementation = ({
|
|
4022
|
+
context,
|
|
4023
|
+
action
|
|
4024
|
+
}) => {
|
|
4025
|
+
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 ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
4026
|
+
value,
|
|
4027
|
+
blockOffset: action.offsets.anchor,
|
|
4028
|
+
direction: "backward"
|
|
4029
|
+
}) : void 0, manualFocus = action.offsets?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
4030
|
+
value,
|
|
4031
|
+
blockOffset: action.offsets.focus,
|
|
4032
|
+
direction: "forward"
|
|
4033
|
+
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
4034
|
+
anchor: manualAnchor,
|
|
4035
|
+
focus: manualFocus
|
|
4036
|
+
} : void 0, selection = manualSelection ? toSlateRange(manualSelection, action.editor) ?? editor.selection : editor.selection;
|
|
4037
|
+
if (!selection)
|
|
4038
|
+
return;
|
|
4039
|
+
const editorSelection = toPortableTextRange(value, selection, context.schema), anchorOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
|
|
4040
|
+
value,
|
|
4041
|
+
selectionPoint: editorSelection.anchor
|
|
4042
|
+
}) : void 0, focusOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
|
|
4043
|
+
value,
|
|
4044
|
+
selectionPoint: editorSelection.focus
|
|
4045
|
+
}) : void 0;
|
|
4046
|
+
if (!anchorOffset || !focusOffset)
|
|
4047
|
+
throw new Error("Unable to find anchor or focus offset");
|
|
4048
|
+
if (slate.Range.isExpanded(selection)) {
|
|
4049
|
+
slate.Transforms.setNodes(editor, {}, {
|
|
4050
|
+
at: selection,
|
|
4051
|
+
match: slate.Text.isText,
|
|
4052
|
+
split: !0,
|
|
4053
|
+
hanging: !0
|
|
4054
|
+
});
|
|
4055
|
+
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
4056
|
+
value: newValue,
|
|
4057
|
+
offsets: {
|
|
4058
|
+
anchor: anchorOffset,
|
|
4059
|
+
focus: focusOffset
|
|
4060
|
+
},
|
|
4061
|
+
backward: editorSelection?.backward
|
|
4062
|
+
}), trimmedSelection = selector_isSelectingEntireBlocks.getTrimmedSelection({
|
|
4063
|
+
context: {
|
|
4064
|
+
activeDecorators: [],
|
|
4065
|
+
converters: [],
|
|
4066
|
+
keyGenerator: context.keyGenerator,
|
|
4067
|
+
readOnly: !1,
|
|
4068
|
+
schema: context.schema,
|
|
4069
|
+
selection: newSelection,
|
|
4070
|
+
value: newValue
|
|
4071
|
+
}
|
|
4072
|
+
});
|
|
4073
|
+
if (!trimmedSelection)
|
|
4074
|
+
throw new Error("Unable to find trimmed selection");
|
|
4075
|
+
const newRange = toSlateRange(trimmedSelection, editor);
|
|
4076
|
+
if (!newRange)
|
|
4077
|
+
throw new Error("Unable to find new selection");
|
|
4078
|
+
const splitTextNodes = slate.Range.isRange(newRange) ? [...slate.Editor.nodes(editor, {
|
|
4079
|
+
at: newRange,
|
|
4080
|
+
match: (node) => slate.Text.isText(node)
|
|
4081
|
+
})] : [];
|
|
4082
|
+
for (const [node, path] of splitTextNodes) {
|
|
4083
|
+
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
4084
|
+
slate.Transforms.setNodes(editor, {
|
|
4085
|
+
marks
|
|
4086
|
+
}, {
|
|
4087
|
+
at: path,
|
|
4088
|
+
match: slate.Text.isText,
|
|
4089
|
+
split: !0,
|
|
4090
|
+
hanging: !0
|
|
4091
|
+
});
|
|
4092
|
+
}
|
|
4093
|
+
} else {
|
|
4094
|
+
if (!Array.from(slate.Editor.nodes(editor, {
|
|
4095
|
+
at: selection,
|
|
4096
|
+
match: (node) => editor.isTextSpan(node)
|
|
4097
|
+
}))?.at(0))
|
|
4098
|
+
return;
|
|
4099
|
+
const [block, blockPath] = slate.Editor.node(editor, selection, {
|
|
4100
|
+
depth: 1
|
|
4101
|
+
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4102
|
+
if (lonelyEmptySpan) {
|
|
4103
|
+
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
4104
|
+
slate.Transforms.setNodes(editor, {
|
|
4105
|
+
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
4106
|
+
}, {
|
|
4107
|
+
at: blockPath,
|
|
4108
|
+
match: (node) => editor.isTextSpan(node)
|
|
4109
|
+
});
|
|
4110
|
+
} else {
|
|
4111
|
+
const existingMarks = {
|
|
4112
|
+
...slate.Editor.marks(editor) || {}
|
|
4113
|
+
}.marks || [], marks = {
|
|
4114
|
+
...slate.Editor.marks(editor) || {},
|
|
4115
|
+
marks: [...existingMarks, mark]
|
|
4116
|
+
};
|
|
4117
|
+
editor.marks = marks;
|
|
4118
|
+
}
|
|
4119
|
+
}
|
|
4120
|
+
if (editor.selection) {
|
|
4121
|
+
const selection2 = editor.selection;
|
|
4122
|
+
editor.selection = {
|
|
4123
|
+
...selection2
|
|
4124
|
+
};
|
|
4125
|
+
}
|
|
4172
4126
|
}, deleteActionImplementation = ({
|
|
4173
4127
|
action
|
|
4174
4128
|
}) => {
|
|
@@ -4469,63 +4423,6 @@ const insertTextActionImplementation = ({
|
|
|
4469
4423
|
to,
|
|
4470
4424
|
mode: "highest"
|
|
4471
4425
|
});
|
|
4472
|
-
}, moveBlockDownActionImplementation = ({
|
|
4473
|
-
context,
|
|
4474
|
-
action
|
|
4475
|
-
}) => {
|
|
4476
|
-
const at = [toSlatePath(action.at, action.editor)[0]], to = [slate.Path.next(at)[0]], selection = toPortableTextRange(action.editor.children, {
|
|
4477
|
-
anchor: {
|
|
4478
|
-
path: to,
|
|
4479
|
-
offset: 0
|
|
4480
|
-
},
|
|
4481
|
-
focus: {
|
|
4482
|
-
path: to,
|
|
4483
|
-
offset: 0
|
|
4484
|
-
}
|
|
4485
|
-
}, context.schema), destinationBlockKey = selection && util_sliceBlocks.isKeyedSegment(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
|
|
4486
|
-
if (destinationBlockKey === void 0) {
|
|
4487
|
-
console.error("Could not find destination block key");
|
|
4488
|
-
return;
|
|
4489
|
-
}
|
|
4490
|
-
moveBlockActionImplementation({
|
|
4491
|
-
action: {
|
|
4492
|
-
at: action.at,
|
|
4493
|
-
to: [{
|
|
4494
|
-
_key: destinationBlockKey
|
|
4495
|
-
}],
|
|
4496
|
-
editor: action.editor
|
|
4497
|
-
}
|
|
4498
|
-
});
|
|
4499
|
-
}, moveBlockUpActionImplementation = ({
|
|
4500
|
-
context,
|
|
4501
|
-
action
|
|
4502
|
-
}) => {
|
|
4503
|
-
const at = [toSlatePath(action.at, action.editor)[0]];
|
|
4504
|
-
if (!slate.Path.hasPrevious(at))
|
|
4505
|
-
return;
|
|
4506
|
-
const to = [slate.Path.previous(at)[0]], selection = toPortableTextRange(action.editor.children, {
|
|
4507
|
-
anchor: {
|
|
4508
|
-
path: to,
|
|
4509
|
-
offset: 0
|
|
4510
|
-
},
|
|
4511
|
-
focus: {
|
|
4512
|
-
path: to,
|
|
4513
|
-
offset: 0
|
|
4514
|
-
}
|
|
4515
|
-
}, context.schema), destinationBlockKey = selection && util_sliceBlocks.isKeyedSegment(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
|
|
4516
|
-
if (destinationBlockKey === void 0) {
|
|
4517
|
-
console.error("Could not find destination block key");
|
|
4518
|
-
return;
|
|
4519
|
-
}
|
|
4520
|
-
moveBlockActionImplementation({
|
|
4521
|
-
action: {
|
|
4522
|
-
at: action.at,
|
|
4523
|
-
to: [{
|
|
4524
|
-
_key: destinationBlockKey
|
|
4525
|
-
}],
|
|
4526
|
-
editor: action.editor
|
|
4527
|
-
}
|
|
4528
|
-
});
|
|
4529
4426
|
}, noopActionImplementation = () => {
|
|
4530
4427
|
}, selectActionImplementation = ({
|
|
4531
4428
|
action
|
|
@@ -4535,13 +4432,11 @@ const insertTextActionImplementation = ({
|
|
|
4535
4432
|
}, debug$9 = debugWithName("behaviors:action"), behaviorActionImplementations = {
|
|
4536
4433
|
"annotation.add": addAnnotationActionImplementation,
|
|
4537
4434
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
4538
|
-
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
4539
4435
|
"block.set": blockSetBehaviorActionImplementation,
|
|
4540
4436
|
"block.unset": blockUnsetBehaviorActionImplementation,
|
|
4541
4437
|
blur: blurActionImplementation,
|
|
4542
4438
|
"decorator.add": decoratorAddActionImplementation,
|
|
4543
4439
|
"decorator.remove": removeDecoratorActionImplementation,
|
|
4544
|
-
"decorator.toggle": toggleDecoratorActionImplementation,
|
|
4545
4440
|
focus: focusActionImplementation,
|
|
4546
4441
|
delete: deleteActionImplementation,
|
|
4547
4442
|
"delete.backward": deleteBackwardActionImplementation,
|
|
@@ -4558,8 +4453,6 @@ const insertTextActionImplementation = ({
|
|
|
4558
4453
|
"insert.text": insertTextActionImplementation,
|
|
4559
4454
|
effect: effectActionImplementation,
|
|
4560
4455
|
"move.block": moveBlockActionImplementation,
|
|
4561
|
-
"move.block down": moveBlockDownActionImplementation,
|
|
4562
|
-
"move.block up": moveBlockUpActionImplementation,
|
|
4563
4456
|
noop: noopActionImplementation,
|
|
4564
4457
|
select: selectActionImplementation
|
|
4565
4458
|
};
|
|
@@ -4582,13 +4475,6 @@ function performAction({
|
|
|
4582
4475
|
});
|
|
4583
4476
|
break;
|
|
4584
4477
|
}
|
|
4585
|
-
case "annotation.toggle": {
|
|
4586
|
-
behaviorActionImplementations["annotation.toggle"]({
|
|
4587
|
-
context,
|
|
4588
|
-
action
|
|
4589
|
-
});
|
|
4590
|
-
break;
|
|
4591
|
-
}
|
|
4592
4478
|
case "block.set": {
|
|
4593
4479
|
behaviorActionImplementations["block.set"]({
|
|
4594
4480
|
context,
|
|
@@ -4624,13 +4510,6 @@ function performAction({
|
|
|
4624
4510
|
});
|
|
4625
4511
|
break;
|
|
4626
4512
|
}
|
|
4627
|
-
case "decorator.toggle": {
|
|
4628
|
-
behaviorActionImplementations["decorator.toggle"]({
|
|
4629
|
-
context,
|
|
4630
|
-
action
|
|
4631
|
-
});
|
|
4632
|
-
break;
|
|
4633
|
-
}
|
|
4634
4513
|
case "delete": {
|
|
4635
4514
|
behaviorActionImplementations.delete({
|
|
4636
4515
|
context,
|
|
@@ -4743,20 +4622,6 @@ function performAction({
|
|
|
4743
4622
|
});
|
|
4744
4623
|
break;
|
|
4745
4624
|
}
|
|
4746
|
-
case "move.block down": {
|
|
4747
|
-
behaviorActionImplementations["move.block down"]({
|
|
4748
|
-
context,
|
|
4749
|
-
action
|
|
4750
|
-
});
|
|
4751
|
-
break;
|
|
4752
|
-
}
|
|
4753
|
-
case "move.block up": {
|
|
4754
|
-
behaviorActionImplementations["move.block up"]({
|
|
4755
|
-
context,
|
|
4756
|
-
action
|
|
4757
|
-
});
|
|
4758
|
-
break;
|
|
4759
|
-
}
|
|
4760
4625
|
case "noop":
|
|
4761
4626
|
break;
|
|
4762
4627
|
default: {
|
|
@@ -4768,65 +4633,10 @@ function performAction({
|
|
|
4768
4633
|
}
|
|
4769
4634
|
}
|
|
4770
4635
|
}
|
|
4771
|
-
function createWithEventListeners(editorActor
|
|
4636
|
+
function createWithEventListeners(editorActor) {
|
|
4772
4637
|
return function(editor) {
|
|
4773
4638
|
if (editorActor.getSnapshot().context.maxBlocks !== void 0)
|
|
4774
4639
|
return editor;
|
|
4775
|
-
subscriptions.push(() => {
|
|
4776
|
-
const subscription = editorActor.on("*", (event) => {
|
|
4777
|
-
switch (event.type) {
|
|
4778
|
-
// These events are not relevant for Behaviors
|
|
4779
|
-
case "blurred":
|
|
4780
|
-
case "done loading":
|
|
4781
|
-
case "editable":
|
|
4782
|
-
case "error":
|
|
4783
|
-
case "focused":
|
|
4784
|
-
case "invalid value":
|
|
4785
|
-
case "loading":
|
|
4786
|
-
case "mutation":
|
|
4787
|
-
case "patch":
|
|
4788
|
-
case "internal.patch":
|
|
4789
|
-
case "patches":
|
|
4790
|
-
case "read only":
|
|
4791
|
-
case "ready":
|
|
4792
|
-
case "selection":
|
|
4793
|
-
case "value changed":
|
|
4794
|
-
case "unset":
|
|
4795
|
-
break;
|
|
4796
|
-
case "custom.*":
|
|
4797
|
-
editorActor.send({
|
|
4798
|
-
type: "custom behavior event",
|
|
4799
|
-
behaviorEvent: event.event,
|
|
4800
|
-
editor
|
|
4801
|
-
});
|
|
4802
|
-
break;
|
|
4803
|
-
case "insert.block object":
|
|
4804
|
-
editorActor.send({
|
|
4805
|
-
type: "behavior event",
|
|
4806
|
-
behaviorEvent: {
|
|
4807
|
-
type: "insert.block",
|
|
4808
|
-
block: {
|
|
4809
|
-
_type: event.blockObject.name,
|
|
4810
|
-
...event.blockObject.value ?? {}
|
|
4811
|
-
},
|
|
4812
|
-
placement: event.placement
|
|
4813
|
-
},
|
|
4814
|
-
editor
|
|
4815
|
-
});
|
|
4816
|
-
break;
|
|
4817
|
-
default:
|
|
4818
|
-
editorActor.send({
|
|
4819
|
-
type: "behavior event",
|
|
4820
|
-
behaviorEvent: event,
|
|
4821
|
-
editor
|
|
4822
|
-
});
|
|
4823
|
-
break;
|
|
4824
|
-
}
|
|
4825
|
-
});
|
|
4826
|
-
return () => {
|
|
4827
|
-
subscription.unsubscribe();
|
|
4828
|
-
};
|
|
4829
|
-
});
|
|
4830
4640
|
const {
|
|
4831
4641
|
deleteBackward,
|
|
4832
4642
|
deleteForward,
|
|
@@ -5637,7 +5447,7 @@ const withPlugins = (editor, options) => {
|
|
|
5637
5447
|
editorActor,
|
|
5638
5448
|
schemaTypes
|
|
5639
5449
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
|
|
5640
|
-
return createWithEventListeners(editorActor
|
|
5450
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5641
5451
|
}, debug$3 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
5642
5452
|
function createSlateEditor(config) {
|
|
5643
5453
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
@@ -5659,17 +5469,67 @@ function createSlateEditor(config) {
|
|
|
5659
5469
|
};
|
|
5660
5470
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
5661
5471
|
}
|
|
5662
|
-
const
|
|
5663
|
-
|
|
5664
|
-
}, raiseInsertSoftBreak = behavior_core.defineBehavior({
|
|
5665
|
-
on: "keyboard.keydown",
|
|
5472
|
+
const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
5473
|
+
on: "annotation.toggle",
|
|
5666
5474
|
guard: ({
|
|
5475
|
+
snapshot,
|
|
5667
5476
|
event
|
|
5668
|
-
}) =>
|
|
5669
|
-
actions: [(
|
|
5670
|
-
|
|
5477
|
+
}) => selector_isSelectingEntireBlocks.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5478
|
+
actions: [({
|
|
5479
|
+
event
|
|
5480
|
+
}) => [behavior_core.raise({
|
|
5481
|
+
type: "annotation.remove",
|
|
5482
|
+
annotation: event.annotation
|
|
5483
|
+
})]]
|
|
5484
|
+
}), behavior_core.defineBehavior({
|
|
5485
|
+
on: "annotation.toggle",
|
|
5486
|
+
guard: ({
|
|
5487
|
+
snapshot,
|
|
5488
|
+
event
|
|
5489
|
+
}) => !selector_isSelectingEntireBlocks.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5490
|
+
actions: [({
|
|
5491
|
+
event
|
|
5492
|
+
}) => [behavior_core.raise({
|
|
5493
|
+
type: "annotation.add",
|
|
5494
|
+
annotation: event.annotation
|
|
5671
5495
|
})]]
|
|
5672
|
-
}),
|
|
5496
|
+
})], abstractDecoratorBehaviors = [behavior_core.defineBehavior({
|
|
5497
|
+
on: "decorator.toggle",
|
|
5498
|
+
guard: ({
|
|
5499
|
+
snapshot,
|
|
5500
|
+
event
|
|
5501
|
+
}) => selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)(snapshot),
|
|
5502
|
+
actions: [({
|
|
5503
|
+
event
|
|
5504
|
+
}) => [behavior_core.raise({
|
|
5505
|
+
type: "decorator.remove",
|
|
5506
|
+
decorator: event.decorator
|
|
5507
|
+
})]]
|
|
5508
|
+
}), behavior_core.defineBehavior({
|
|
5509
|
+
on: "decorator.toggle",
|
|
5510
|
+
guard: ({
|
|
5511
|
+
snapshot,
|
|
5512
|
+
event
|
|
5513
|
+
}) => {
|
|
5514
|
+
const manualSelection = event.offsets ? util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
5515
|
+
value: snapshot.context.value,
|
|
5516
|
+
offsets: event.offsets
|
|
5517
|
+
}) : null;
|
|
5518
|
+
return manualSelection ? !selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)({
|
|
5519
|
+
...snapshot,
|
|
5520
|
+
context: {
|
|
5521
|
+
...snapshot.context,
|
|
5522
|
+
selection: manualSelection
|
|
5523
|
+
}
|
|
5524
|
+
}) : !selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)(snapshot);
|
|
5525
|
+
},
|
|
5526
|
+
actions: [({
|
|
5527
|
+
event
|
|
5528
|
+
}) => [behavior_core.raise({
|
|
5529
|
+
...event,
|
|
5530
|
+
type: "decorator.add"
|
|
5531
|
+
})]]
|
|
5532
|
+
})], abstractInsertBehaviors = [behavior_core.defineBehavior({
|
|
5673
5533
|
on: "insert.blocks",
|
|
5674
5534
|
guard: ({
|
|
5675
5535
|
event
|
|
@@ -5745,7 +5605,7 @@ const keyIs = {
|
|
|
5745
5605
|
placement: index === 0 ? "auto" : "after",
|
|
5746
5606
|
select: "end"
|
|
5747
5607
|
}))]
|
|
5748
|
-
})],
|
|
5608
|
+
})], abstractListItemBehaviors = [behavior_core.defineBehavior({
|
|
5749
5609
|
on: "list item.add",
|
|
5750
5610
|
guard: ({
|
|
5751
5611
|
snapshot
|
|
@@ -5802,7 +5662,75 @@ const keyIs = {
|
|
|
5802
5662
|
type: "list item.add",
|
|
5803
5663
|
listItem: event.listItem
|
|
5804
5664
|
})]]
|
|
5805
|
-
})],
|
|
5665
|
+
})], abstractMoveBehaviors = [behavior_core.defineBehavior({
|
|
5666
|
+
on: "move.block up",
|
|
5667
|
+
guard: ({
|
|
5668
|
+
snapshot,
|
|
5669
|
+
event
|
|
5670
|
+
}) => {
|
|
5671
|
+
const previousBlock = selector_isOverlappingSelection.getPreviousBlock({
|
|
5672
|
+
context: {
|
|
5673
|
+
...snapshot.context,
|
|
5674
|
+
selection: {
|
|
5675
|
+
anchor: {
|
|
5676
|
+
path: event.at,
|
|
5677
|
+
offset: 0
|
|
5678
|
+
},
|
|
5679
|
+
focus: {
|
|
5680
|
+
path: event.at,
|
|
5681
|
+
offset: 0
|
|
5682
|
+
}
|
|
5683
|
+
}
|
|
5684
|
+
}
|
|
5685
|
+
});
|
|
5686
|
+
return previousBlock ? {
|
|
5687
|
+
previousBlock
|
|
5688
|
+
} : !1;
|
|
5689
|
+
},
|
|
5690
|
+
actions: [({
|
|
5691
|
+
event
|
|
5692
|
+
}, {
|
|
5693
|
+
previousBlock
|
|
5694
|
+
}) => [behavior_core.raise({
|
|
5695
|
+
type: "move.block",
|
|
5696
|
+
at: event.at,
|
|
5697
|
+
to: previousBlock.path
|
|
5698
|
+
})]]
|
|
5699
|
+
}), behavior_core.defineBehavior({
|
|
5700
|
+
on: "move.block down",
|
|
5701
|
+
guard: ({
|
|
5702
|
+
snapshot,
|
|
5703
|
+
event
|
|
5704
|
+
}) => {
|
|
5705
|
+
const nextBlock = selector_isOverlappingSelection.getNextBlock({
|
|
5706
|
+
context: {
|
|
5707
|
+
...snapshot.context,
|
|
5708
|
+
selection: {
|
|
5709
|
+
anchor: {
|
|
5710
|
+
path: event.at,
|
|
5711
|
+
offset: 0
|
|
5712
|
+
},
|
|
5713
|
+
focus: {
|
|
5714
|
+
path: event.at,
|
|
5715
|
+
offset: 0
|
|
5716
|
+
}
|
|
5717
|
+
}
|
|
5718
|
+
}
|
|
5719
|
+
});
|
|
5720
|
+
return nextBlock ? {
|
|
5721
|
+
nextBlock
|
|
5722
|
+
} : !1;
|
|
5723
|
+
},
|
|
5724
|
+
actions: [({
|
|
5725
|
+
event
|
|
5726
|
+
}, {
|
|
5727
|
+
nextBlock
|
|
5728
|
+
}) => [behavior_core.raise({
|
|
5729
|
+
type: "move.block",
|
|
5730
|
+
at: event.at,
|
|
5731
|
+
to: nextBlock.path
|
|
5732
|
+
})]]
|
|
5733
|
+
})], abstractSelectBehaviors = [behavior_core.defineBehavior({
|
|
5806
5734
|
on: "select.previous block",
|
|
5807
5735
|
guard: ({
|
|
5808
5736
|
snapshot,
|
|
@@ -5848,7 +5776,7 @@ const keyIs = {
|
|
|
5848
5776
|
type: "select",
|
|
5849
5777
|
selection
|
|
5850
5778
|
})]]
|
|
5851
|
-
})],
|
|
5779
|
+
})], abstractStyleBehaviors = [behavior_core.defineBehavior({
|
|
5852
5780
|
on: "style.add",
|
|
5853
5781
|
guard: ({
|
|
5854
5782
|
snapshot
|
|
@@ -5904,65 +5832,15 @@ const keyIs = {
|
|
|
5904
5832
|
type: "style.add",
|
|
5905
5833
|
style: event.style
|
|
5906
5834
|
})]]
|
|
5907
|
-
})],
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
event
|
|
5912
|
-
}) => selector_isSelectingEntireBlocks.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5913
|
-
actions: [({
|
|
5914
|
-
event
|
|
5915
|
-
}) => [behavior_core.raise({
|
|
5916
|
-
type: "annotation.remove",
|
|
5917
|
-
annotation: event.annotation
|
|
5918
|
-
})]]
|
|
5919
|
-
}), toggleAnnotationOn = behavior_core.defineBehavior({
|
|
5920
|
-
on: "annotation.toggle",
|
|
5921
|
-
guard: ({
|
|
5922
|
-
snapshot,
|
|
5923
|
-
event
|
|
5924
|
-
}) => !selector_isSelectingEntireBlocks.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5925
|
-
actions: [({
|
|
5926
|
-
event
|
|
5927
|
-
}) => [behavior_core.raise({
|
|
5928
|
-
type: "annotation.add",
|
|
5929
|
-
annotation: event.annotation
|
|
5930
|
-
})]]
|
|
5931
|
-
}), toggleDecoratorOff = behavior_core.defineBehavior({
|
|
5932
|
-
on: "decorator.toggle",
|
|
5933
|
-
guard: ({
|
|
5934
|
-
snapshot,
|
|
5935
|
-
event
|
|
5936
|
-
}) => selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)(snapshot),
|
|
5937
|
-
actions: [({
|
|
5938
|
-
event
|
|
5939
|
-
}) => [behavior_core.raise({
|
|
5940
|
-
type: "decorator.remove",
|
|
5941
|
-
decorator: event.decorator
|
|
5942
|
-
})]]
|
|
5943
|
-
}), toggleDecoratorOn = behavior_core.defineBehavior({
|
|
5944
|
-
on: "decorator.toggle",
|
|
5835
|
+
})], keyIs = {
|
|
5836
|
+
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
5837
|
+
}, raiseInsertSoftBreak = behavior_core.defineBehavior({
|
|
5838
|
+
on: "keyboard.keydown",
|
|
5945
5839
|
guard: ({
|
|
5946
|
-
snapshot,
|
|
5947
|
-
event
|
|
5948
|
-
}) => {
|
|
5949
|
-
const manualSelection = event.offsets ? util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
5950
|
-
value: snapshot.context.value,
|
|
5951
|
-
offsets: event.offsets
|
|
5952
|
-
}) : null;
|
|
5953
|
-
return manualSelection ? !selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)({
|
|
5954
|
-
...snapshot,
|
|
5955
|
-
context: {
|
|
5956
|
-
...snapshot.context,
|
|
5957
|
-
selection: manualSelection
|
|
5958
|
-
}
|
|
5959
|
-
}) : !selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)(snapshot);
|
|
5960
|
-
},
|
|
5961
|
-
actions: [({
|
|
5962
5840
|
event
|
|
5963
|
-
}) =>
|
|
5964
|
-
|
|
5965
|
-
type: "
|
|
5841
|
+
}) => keyIs.lineBreak(event.originEvent),
|
|
5842
|
+
actions: [() => [behavior_core.raise({
|
|
5843
|
+
type: "insert.soft break"
|
|
5966
5844
|
})]]
|
|
5967
5845
|
}), raiseDeserializationSuccessOrFailure = behavior_core.defineBehavior({
|
|
5968
5846
|
on: "deserialize",
|
|
@@ -6292,45 +6170,30 @@ const keyIs = {
|
|
|
6292
6170
|
originEvent: event
|
|
6293
6171
|
})]]
|
|
6294
6172
|
}),
|
|
6295
|
-
...
|
|
6296
|
-
...
|
|
6297
|
-
...
|
|
6298
|
-
...
|
|
6299
|
-
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
toggleDecoratorOn,
|
|
6173
|
+
...abstractAnnotationBehaviors,
|
|
6174
|
+
...abstractDecoratorBehaviors,
|
|
6175
|
+
...abstractInsertBehaviors,
|
|
6176
|
+
...abstractListItemBehaviors,
|
|
6177
|
+
...abstractMoveBehaviors,
|
|
6178
|
+
...abstractStyleBehaviors,
|
|
6179
|
+
...abstractSelectBehaviors,
|
|
6303
6180
|
raiseDeserializationSuccessOrFailure,
|
|
6304
6181
|
raiseSerializationSuccessOrFailure,
|
|
6305
6182
|
raiseInsertSoftBreak
|
|
6306
|
-
];
|
|
6307
|
-
function
|
|
6308
|
-
return event.type
|
|
6309
|
-
}
|
|
6310
|
-
function isInternalBehaviorEvent(event) {
|
|
6311
|
-
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.");
|
|
6183
|
+
], 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"];
|
|
6184
|
+
function isAbstractBehaviorEvent(event) {
|
|
6185
|
+
return abstractBehaviorEventTypes.includes(event.type);
|
|
6312
6186
|
}
|
|
6187
|
+
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"];
|
|
6313
6188
|
function isNativeBehaviorEvent(event) {
|
|
6314
|
-
return
|
|
6315
|
-
}
|
|
6316
|
-
function isClipboardBehaviorEvent(event) {
|
|
6317
|
-
return event.type.startsWith("clipboard.");
|
|
6318
|
-
}
|
|
6319
|
-
function isDragBehaviorEvent(event) {
|
|
6320
|
-
return event.type.startsWith("drag.");
|
|
6321
|
-
}
|
|
6322
|
-
function isInputBehaviorEvent(event) {
|
|
6323
|
-
return event.type.startsWith("input.");
|
|
6324
|
-
}
|
|
6325
|
-
function isMouseBehaviorEvent(event) {
|
|
6326
|
-
return event.type.startsWith("mouse.");
|
|
6189
|
+
return nativeBehaviorEventTypes.includes(event.type);
|
|
6327
6190
|
}
|
|
6328
6191
|
function isCustomBehaviorEvent(event) {
|
|
6329
6192
|
return event.type.startsWith("custom.");
|
|
6330
6193
|
}
|
|
6331
6194
|
const debug$2 = debugWithName("behaviors:event");
|
|
6332
6195
|
function eventCategory(event) {
|
|
6333
|
-
return isNativeBehaviorEvent(event) ? "native" :
|
|
6196
|
+
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "abstract" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
6334
6197
|
}
|
|
6335
6198
|
function performEvent({
|
|
6336
6199
|
behaviors,
|
|
@@ -6343,7 +6206,7 @@ function performEvent({
|
|
|
6343
6206
|
defaultActionCallback
|
|
6344
6207
|
}) {
|
|
6345
6208
|
debug$2(`(${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
6346
|
-
const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) ||
|
|
6209
|
+
const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isAbstractBehaviorEvent(event) ? void 0 : {
|
|
6347
6210
|
...event,
|
|
6348
6211
|
editor
|
|
6349
6212
|
}, eventBehaviors = behaviors.filter((behavior) => {
|
|
@@ -6462,6 +6325,34 @@ function performEvent({
|
|
|
6462
6325
|
}), editor.onChange();
|
|
6463
6326
|
}
|
|
6464
6327
|
}
|
|
6328
|
+
function slateChildrenToBlocks(schema2, value) {
|
|
6329
|
+
const blocks = new Array(value.length);
|
|
6330
|
+
for (let blockIndex = 0; blockIndex < value.length; blockIndex++) {
|
|
6331
|
+
const descendant = value[blockIndex];
|
|
6332
|
+
if (descendant._type !== schema2.block.name) {
|
|
6333
|
+
blocks[blockIndex] = {
|
|
6334
|
+
_key: descendant._key,
|
|
6335
|
+
_type: descendant._type,
|
|
6336
|
+
..."value" in descendant && typeof descendant.value == "object" ? descendant.value : {}
|
|
6337
|
+
};
|
|
6338
|
+
continue;
|
|
6339
|
+
}
|
|
6340
|
+
const children = "children" in descendant ? descendant.children : [], processedChildren = new Array(children.length);
|
|
6341
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
6342
|
+
const child = children[childIndex];
|
|
6343
|
+
processedChildren[childIndex] = child._type === schema2.span.name ? child : {
|
|
6344
|
+
_key: child._key,
|
|
6345
|
+
_type: child._type,
|
|
6346
|
+
..."value" in child && typeof child.value == "object" ? child.value : {}
|
|
6347
|
+
};
|
|
6348
|
+
}
|
|
6349
|
+
blocks[blockIndex] = {
|
|
6350
|
+
...descendant,
|
|
6351
|
+
children: processedChildren
|
|
6352
|
+
};
|
|
6353
|
+
}
|
|
6354
|
+
return blocks;
|
|
6355
|
+
}
|
|
6465
6356
|
function getActiveDecorators({
|
|
6466
6357
|
schema: schema2,
|
|
6467
6358
|
slateEditorInstance
|
|
@@ -6480,7 +6371,7 @@ function createEditorSnapshot({
|
|
|
6480
6371
|
hasTag,
|
|
6481
6372
|
internalDrag
|
|
6482
6373
|
}) {
|
|
6483
|
-
const value =
|
|
6374
|
+
const value = slateChildrenToBlocks(schema2, editor.children), selection = toPortableTextRange(value, editor.selection, schema2);
|
|
6484
6375
|
return {
|
|
6485
6376
|
context: {
|
|
6486
6377
|
activeDecorators: getActiveDecorators({
|
|
@@ -6576,7 +6467,7 @@ const editorMachine = xstate.setup({
|
|
|
6576
6467
|
event,
|
|
6577
6468
|
self
|
|
6578
6469
|
}) => {
|
|
6579
|
-
xstate.assertEvent(event, ["behavior event"
|
|
6470
|
+
xstate.assertEvent(event, ["behavior event"]), performEvent({
|
|
6580
6471
|
behaviors: [...context.behaviors.values(), ...defaultBehaviors],
|
|
6581
6472
|
event: event.behaviorEvent,
|
|
6582
6473
|
editor: event.editor,
|
|
@@ -6775,87 +6666,6 @@ const editorMachine = xstate.setup({
|
|
|
6775
6666
|
},
|
|
6776
6667
|
"behavior event": {
|
|
6777
6668
|
actions: "handle behavior event"
|
|
6778
|
-
},
|
|
6779
|
-
"custom behavior event": {
|
|
6780
|
-
actions: "handle behavior event"
|
|
6781
|
-
},
|
|
6782
|
-
"annotation.*": {
|
|
6783
|
-
actions: xstate.emit(({
|
|
6784
|
-
event
|
|
6785
|
-
}) => event)
|
|
6786
|
-
},
|
|
6787
|
-
"block.*": {
|
|
6788
|
-
actions: xstate.emit(({
|
|
6789
|
-
event
|
|
6790
|
-
}) => event)
|
|
6791
|
-
},
|
|
6792
|
-
blur: {
|
|
6793
|
-
actions: xstate.emit(({
|
|
6794
|
-
event
|
|
6795
|
-
}) => event)
|
|
6796
|
-
},
|
|
6797
|
-
"custom.*": {
|
|
6798
|
-
actions: xstate.emit(({
|
|
6799
|
-
event
|
|
6800
|
-
}) => ({
|
|
6801
|
-
type: "custom.*",
|
|
6802
|
-
event
|
|
6803
|
-
}))
|
|
6804
|
-
},
|
|
6805
|
-
"decorator.*": {
|
|
6806
|
-
actions: xstate.emit(({
|
|
6807
|
-
event
|
|
6808
|
-
}) => event)
|
|
6809
|
-
},
|
|
6810
|
-
"delete.*": {
|
|
6811
|
-
actions: xstate.emit(({
|
|
6812
|
-
event
|
|
6813
|
-
}) => event)
|
|
6814
|
-
},
|
|
6815
|
-
focus: {
|
|
6816
|
-
actions: xstate.emit(({
|
|
6817
|
-
event
|
|
6818
|
-
}) => event)
|
|
6819
|
-
},
|
|
6820
|
-
"history.*": {
|
|
6821
|
-
actions: xstate.emit(({
|
|
6822
|
-
event
|
|
6823
|
-
}) => event)
|
|
6824
|
-
},
|
|
6825
|
-
"insert.*": {
|
|
6826
|
-
actions: xstate.emit(({
|
|
6827
|
-
event
|
|
6828
|
-
}) => event)
|
|
6829
|
-
},
|
|
6830
|
-
"list item.*": {
|
|
6831
|
-
actions: xstate.emit(({
|
|
6832
|
-
event
|
|
6833
|
-
}) => event)
|
|
6834
|
-
},
|
|
6835
|
-
"move.*": {
|
|
6836
|
-
actions: xstate.emit(({
|
|
6837
|
-
event
|
|
6838
|
-
}) => event)
|
|
6839
|
-
},
|
|
6840
|
-
select: {
|
|
6841
|
-
actions: xstate.emit(({
|
|
6842
|
-
event
|
|
6843
|
-
}) => event)
|
|
6844
|
-
},
|
|
6845
|
-
"select.*": {
|
|
6846
|
-
actions: xstate.emit(({
|
|
6847
|
-
event
|
|
6848
|
-
}) => event)
|
|
6849
|
-
},
|
|
6850
|
-
"style.*": {
|
|
6851
|
-
actions: xstate.emit(({
|
|
6852
|
-
event
|
|
6853
|
-
}) => event)
|
|
6854
|
-
},
|
|
6855
|
-
"text block.*": {
|
|
6856
|
-
actions: xstate.emit(({
|
|
6857
|
-
event
|
|
6858
|
-
}) => event)
|
|
6859
6669
|
}
|
|
6860
6670
|
},
|
|
6861
6671
|
initial: "idle",
|
|
@@ -6967,12 +6777,6 @@ const editorMachine = xstate.setup({
|
|
|
6967
6777
|
}
|
|
6968
6778
|
}
|
|
6969
6779
|
});
|
|
6970
|
-
function getValue({
|
|
6971
|
-
editorActorSnapshot,
|
|
6972
|
-
slateEditorInstance
|
|
6973
|
-
}) {
|
|
6974
|
-
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
6975
|
-
}
|
|
6976
6780
|
function defaultCompare(a, b) {
|
|
6977
6781
|
return a === b;
|
|
6978
6782
|
}
|
|
@@ -7004,10 +6808,7 @@ function getEditorSnapshot({
|
|
|
7004
6808
|
}),
|
|
7005
6809
|
schema: editorActorSnapshot.context.schema,
|
|
7006
6810
|
selection: editorActorSnapshot.context.selection,
|
|
7007
|
-
value:
|
|
7008
|
-
editorActorSnapshot,
|
|
7009
|
-
slateEditorInstance
|
|
7010
|
-
})
|
|
6811
|
+
value: slateChildrenToBlocks(editorActorSnapshot.context.schema, slateEditorInstance.children)
|
|
7011
6812
|
},
|
|
7012
6813
|
beta: {
|
|
7013
6814
|
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
@@ -7063,7 +6864,39 @@ function createInternalEditorFromActor(editorActor) {
|
|
|
7063
6864
|
});
|
|
7064
6865
|
}),
|
|
7065
6866
|
send: (event) => {
|
|
7066
|
-
|
|
6867
|
+
switch (event.type) {
|
|
6868
|
+
case "add behavior":
|
|
6869
|
+
case "remove behavior":
|
|
6870
|
+
case "update behaviors":
|
|
6871
|
+
case "update key generator":
|
|
6872
|
+
case "update readOnly":
|
|
6873
|
+
case "patches":
|
|
6874
|
+
case "update value":
|
|
6875
|
+
case "update schema":
|
|
6876
|
+
case "update maxBlocks":
|
|
6877
|
+
editorActor.send(event);
|
|
6878
|
+
break;
|
|
6879
|
+
case "insert.block object":
|
|
6880
|
+
editorActor.send({
|
|
6881
|
+
type: "behavior event",
|
|
6882
|
+
behaviorEvent: {
|
|
6883
|
+
type: "insert.block",
|
|
6884
|
+
block: {
|
|
6885
|
+
_type: event.blockObject.name,
|
|
6886
|
+
...event.blockObject.value ?? {}
|
|
6887
|
+
},
|
|
6888
|
+
placement: event.placement
|
|
6889
|
+
},
|
|
6890
|
+
editor: slateEditor.instance
|
|
6891
|
+
});
|
|
6892
|
+
break;
|
|
6893
|
+
default:
|
|
6894
|
+
editorActor.send({
|
|
6895
|
+
type: "behavior event",
|
|
6896
|
+
behaviorEvent: event,
|
|
6897
|
+
editor: slateEditor.instance
|
|
6898
|
+
});
|
|
6899
|
+
}
|
|
7067
6900
|
},
|
|
7068
6901
|
on: (event, listener) => editorActor.on(event, (event2) => {
|
|
7069
6902
|
switch (event2.type) {
|