@portabletext/editor 1.44.15 → 1.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +5 -5
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +28 -22
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +154 -129
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/parse-blocks.cjs +74 -22
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +5 -5
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +28 -22
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +161 -136
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/parse-blocks.js +75 -23
- package/lib/_chunks-es/parse-blocks.js.map +1 -1
- package/lib/behaviors/index.cjs +18 -14
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +862 -636
- package/lib/behaviors/index.d.ts +862 -636
- package/lib/behaviors/index.js +18 -14
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +40 -17
- package/lib/index.d.ts +40 -17
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +20 -14
- package/lib/plugins/index.d.ts +20 -14
- package/lib/plugins/index.js +16 -7
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +20 -14
- package/lib/selectors/index.d.ts +20 -14
- package/lib/utils/index.d.cts +20 -14
- package/lib/utils/index.d.ts +20 -14
- package/package.json +2 -2
- package/src/behavior-actions/behavior.action.annotation.add.ts +26 -5
- package/src/behavior-actions/behavior.action.decorator.add.ts +4 -4
- package/src/behavior-actions/behavior.action.delete.text.ts +1 -4
- package/src/behavior-actions/behavior.action.delete.ts +2 -2
- package/src/behavior-actions/behavior.action.insert-inline-object.ts +14 -13
- package/src/behavior-actions/behavior.action.select.ts +1 -1
- package/src/behavior-actions/{behavior.action.insert-break.ts → behavior.action.split.block.ts} +3 -9
- package/src/behavior-actions/behavior.actions.ts +9 -20
- package/src/behaviors/behavior.abstract.decorator.ts +2 -2
- package/src/behaviors/behavior.abstract.insert.ts +9 -1
- package/src/behaviors/behavior.abstract.select.ts +2 -2
- package/src/behaviors/behavior.core.annotations.ts +1 -1
- package/src/behaviors/behavior.core.block-objects.ts +4 -4
- package/src/behaviors/behavior.decorator-pair.ts +3 -3
- package/src/behaviors/behavior.default.ts +4 -4
- package/src/behaviors/behavior.emoji-picker.ts +18 -14
- package/src/behaviors/behavior.markdown.ts +28 -22
- package/src/behaviors/behavior.types.event.ts +23 -14
- package/src/converters/converter.portable-text.deserialize.test.ts +12 -3
- package/src/converters/converter.text-html.deserialize.test.ts +3 -1
- package/src/editor/Editable.tsx +1 -1
- package/src/editor/define-schema.ts +29 -5
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +2 -2
- package/src/editor/plugins/create-with-event-listeners.ts +4 -4
- package/src/internal-utils/parse-blocks.ts +109 -39
- package/src/plugins/plugin.decorator-shortcut.ts +3 -3
- package/src/plugins/plugin.one-line.tsx +8 -1
|
@@ -2670,74 +2670,10 @@ function createOperationToPatches(types2) {
|
|
|
2670
2670
|
splitNodePatch
|
|
2671
2671
|
};
|
|
2672
2672
|
}
|
|
2673
|
-
const
|
|
2674
|
-
context,
|
|
2675
|
-
action
|
|
2676
|
-
}) => {
|
|
2677
|
-
const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
|
|
2678
|
-
if (!editor.selection)
|
|
2679
|
-
return;
|
|
2680
|
-
const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
2681
|
-
if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
2682
|
-
slate.Transforms.splitNodes(editor, {
|
|
2683
|
-
at: editor.selection,
|
|
2684
|
-
always: !0
|
|
2685
|
-
});
|
|
2686
|
-
const [nextBlock, nextBlockPath] = slate.Editor.node(editor, slate.Path.next(focusBlockPath), {
|
|
2687
|
-
depth: 1
|
|
2688
|
-
}), nextChild = slate.Node.child(nextBlock, 0);
|
|
2689
|
-
if (!editor.isTextSpan(nextChild) && slate.Transforms.insertNodes(editor, {
|
|
2690
|
-
_key: context.keyGenerator(),
|
|
2691
|
-
_type: "span",
|
|
2692
|
-
text: "",
|
|
2693
|
-
marks: []
|
|
2694
|
-
}, {
|
|
2695
|
-
at: [nextBlockPath[0], 0]
|
|
2696
|
-
}), slate.Transforms.setSelection(editor, {
|
|
2697
|
-
anchor: {
|
|
2698
|
-
path: [...nextBlockPath, 0],
|
|
2699
|
-
offset: 0
|
|
2700
|
-
},
|
|
2701
|
-
focus: {
|
|
2702
|
-
path: [...nextBlockPath, 0],
|
|
2703
|
-
offset: 0
|
|
2704
|
-
}
|
|
2705
|
-
}), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
|
|
2706
|
-
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);
|
|
2707
|
-
for (const [child, childPath] of children) {
|
|
2708
|
-
if (!editor.isTextSpan(child))
|
|
2709
|
-
continue;
|
|
2710
|
-
const marks = child.marks ?? [];
|
|
2711
|
-
for (const mark of marks)
|
|
2712
|
-
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
2713
|
-
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
2714
|
-
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
2715
|
-
marks: newMarks
|
|
2716
|
-
}, {
|
|
2717
|
-
at: childPath
|
|
2718
|
-
});
|
|
2719
|
-
}
|
|
2720
|
-
const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
|
|
2721
|
-
...markDef,
|
|
2722
|
-
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
2723
|
-
}));
|
|
2724
|
-
isEqual__default.default(nextBlock.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
2725
|
-
markDefs: newMarkDefs
|
|
2726
|
-
}, {
|
|
2727
|
-
at: nextBlockPath,
|
|
2728
|
-
match: (node) => editor.isTextBlock(node)
|
|
2729
|
-
});
|
|
2730
|
-
}
|
|
2731
|
-
return;
|
|
2732
|
-
}
|
|
2733
|
-
slate.Transforms.splitNodes(editor, {
|
|
2734
|
-
always: !0
|
|
2735
|
-
});
|
|
2736
|
-
}, insertSoftBreakActionImplementation = ({
|
|
2673
|
+
const insertTextActionImplementation = ({
|
|
2737
2674
|
action
|
|
2738
2675
|
}) => {
|
|
2739
|
-
|
|
2740
|
-
`);
|
|
2676
|
+
action.editor.insertText(action.text);
|
|
2741
2677
|
};
|
|
2742
2678
|
function isPortableTextSpan(node) {
|
|
2743
2679
|
return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
|
|
@@ -3215,6 +3151,18 @@ const addAnnotationActionImplementation = ({
|
|
|
3215
3151
|
context,
|
|
3216
3152
|
action
|
|
3217
3153
|
}) => {
|
|
3154
|
+
const parsedAnnotation = parseBlocks.parseAnnotation({
|
|
3155
|
+
annotation: {
|
|
3156
|
+
_type: action.annotation.name,
|
|
3157
|
+
...action.annotation.value
|
|
3158
|
+
},
|
|
3159
|
+
context,
|
|
3160
|
+
options: {
|
|
3161
|
+
refreshKeys: !1
|
|
3162
|
+
}
|
|
3163
|
+
});
|
|
3164
|
+
if (!parsedAnnotation)
|
|
3165
|
+
throw new Error(`Failed to parse annotation ${JSON.stringify(action.annotation)}`);
|
|
3218
3166
|
const editor = action.editor;
|
|
3219
3167
|
if (!editor.selection || slate.Range.isCollapsed(editor.selection))
|
|
3220
3168
|
return;
|
|
@@ -3224,15 +3172,15 @@ const addAnnotationActionImplementation = ({
|
|
|
3224
3172
|
match: (node) => editor.isTextBlock(node),
|
|
3225
3173
|
reverse: slate.Range.isBackward(editor.selection)
|
|
3226
3174
|
});
|
|
3175
|
+
let blockIndex = 0;
|
|
3227
3176
|
for (const [block, blockPath] of selectedBlocks) {
|
|
3228
3177
|
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
3229
3178
|
continue;
|
|
3230
|
-
const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
|
|
3231
|
-
markDefs.find((markDef) => markDef._type ===
|
|
3179
|
+
const annotationKey = blockIndex === 0 ? parsedAnnotation._key : context.keyGenerator(), markDefs = block.markDefs ?? [];
|
|
3180
|
+
markDefs.find((markDef) => markDef._type === parsedAnnotation._type && markDef._key === annotationKey) === void 0 && (slate.Transforms.setNodes(editor, {
|
|
3232
3181
|
markDefs: [...markDefs, {
|
|
3233
|
-
|
|
3234
|
-
_key: annotationKey
|
|
3235
|
-
...action.annotation.value
|
|
3182
|
+
...parsedAnnotation,
|
|
3183
|
+
_key: annotationKey
|
|
3236
3184
|
}]
|
|
3237
3185
|
}, {
|
|
3238
3186
|
at: blockPath
|
|
@@ -3248,7 +3196,7 @@ const addAnnotationActionImplementation = ({
|
|
|
3248
3196
|
for (const [span, path] of children) {
|
|
3249
3197
|
if (!editor.isTextSpan(span) || !slate.Range.includes(editor.selection, path))
|
|
3250
3198
|
continue;
|
|
3251
|
-
const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type ===
|
|
3199
|
+
const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === parsedAnnotation._type));
|
|
3252
3200
|
slate.Transforms.setNodes(editor, {
|
|
3253
3201
|
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
3254
3202
|
}, {
|
|
@@ -3259,6 +3207,7 @@ const addAnnotationActionImplementation = ({
|
|
|
3259
3207
|
_key: span._key
|
|
3260
3208
|
}];
|
|
3261
3209
|
}
|
|
3210
|
+
blockIndex++;
|
|
3262
3211
|
}
|
|
3263
3212
|
return markDefPath && spanPath && (paths = {
|
|
3264
3213
|
markDefPath,
|
|
@@ -3671,13 +3620,13 @@ const decoratorAddActionImplementation = ({
|
|
|
3671
3620
|
context,
|
|
3672
3621
|
action
|
|
3673
3622
|
}) => {
|
|
3674
|
-
const editor = action.editor, mark = action.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = action.
|
|
3623
|
+
const editor = action.editor, mark = action.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = action.at?.anchor ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
3675
3624
|
value,
|
|
3676
|
-
blockOffset: action.
|
|
3625
|
+
blockOffset: action.at.anchor,
|
|
3677
3626
|
direction: "backward"
|
|
3678
|
-
}) : void 0, manualFocus = action.
|
|
3627
|
+
}) : void 0, manualFocus = action.at?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
3679
3628
|
value,
|
|
3680
|
-
blockOffset: action.
|
|
3629
|
+
blockOffset: action.at.focus,
|
|
3681
3630
|
direction: "forward"
|
|
3682
3631
|
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
3683
3632
|
anchor: manualAnchor,
|
|
@@ -3779,9 +3728,9 @@ const decoratorAddActionImplementation = ({
|
|
|
3779
3728
|
}, deleteActionImplementation = ({
|
|
3780
3729
|
action
|
|
3781
3730
|
}) => {
|
|
3782
|
-
const range = toSlateRange(action.
|
|
3731
|
+
const range = toSlateRange(action.at, action.editor);
|
|
3783
3732
|
if (!range)
|
|
3784
|
-
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.
|
|
3733
|
+
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.at)}`);
|
|
3785
3734
|
action.editor.delete({
|
|
3786
3735
|
at: range
|
|
3787
3736
|
});
|
|
@@ -3819,10 +3768,7 @@ const decoratorAddActionImplementation = ({
|
|
|
3819
3768
|
}) => {
|
|
3820
3769
|
const value = fromSlateValue(action.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)), selection = util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
3821
3770
|
value,
|
|
3822
|
-
offsets:
|
|
3823
|
-
anchor: action.anchor,
|
|
3824
|
-
focus: action.focus
|
|
3825
|
-
}
|
|
3771
|
+
offsets: action.at
|
|
3826
3772
|
});
|
|
3827
3773
|
if (!selection)
|
|
3828
3774
|
throw new Error("Unable to find selection from block offsets");
|
|
@@ -3857,10 +3803,18 @@ const decoratorAddActionImplementation = ({
|
|
|
3857
3803
|
context,
|
|
3858
3804
|
action
|
|
3859
3805
|
}) => {
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3806
|
+
const parsedInlineObject = parseBlocks.parseInlineObject({
|
|
3807
|
+
context,
|
|
3808
|
+
inlineObject: {
|
|
3809
|
+
_type: action.inlineObject.name,
|
|
3810
|
+
...action.inlineObject.value ?? {}
|
|
3811
|
+
},
|
|
3812
|
+
options: {
|
|
3813
|
+
refreshKeys: !1
|
|
3814
|
+
}
|
|
3815
|
+
});
|
|
3816
|
+
if (!parsedInlineObject)
|
|
3817
|
+
throw new Error(`Failed to parse inline object ${JSON.stringify(action.inlineObject)}`);
|
|
3864
3818
|
if (!action.editor.selection) {
|
|
3865
3819
|
console.error("Unable to insert inline object without selection");
|
|
3866
3820
|
return;
|
|
@@ -3876,11 +3830,7 @@ const decoratorAddActionImplementation = ({
|
|
|
3876
3830
|
const child = toSlateValue([{
|
|
3877
3831
|
_type: context.schema.block.name,
|
|
3878
3832
|
_key: context.keyGenerator(),
|
|
3879
|
-
children: [
|
|
3880
|
-
_type: action.inlineObject.name,
|
|
3881
|
-
_key: context.keyGenerator(),
|
|
3882
|
-
...action.inlineObject.value ?? {}
|
|
3883
|
-
}]
|
|
3833
|
+
children: [parsedInlineObject]
|
|
3884
3834
|
}], {
|
|
3885
3835
|
schemaTypes: context.schema
|
|
3886
3836
|
}).at(0)?.children.at(0);
|
|
@@ -4063,11 +4013,7 @@ function insertBlock({
|
|
|
4063
4013
|
}
|
|
4064
4014
|
}
|
|
4065
4015
|
}
|
|
4066
|
-
const
|
|
4067
|
-
action
|
|
4068
|
-
}) => {
|
|
4069
|
-
action.editor.insertText(action.text);
|
|
4070
|
-
}, moveBlockActionImplementation = ({
|
|
4016
|
+
const moveBlockActionImplementation = ({
|
|
4071
4017
|
action
|
|
4072
4018
|
}) => {
|
|
4073
4019
|
const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
|
|
@@ -4080,8 +4026,71 @@ const insertTextActionImplementation = ({
|
|
|
4080
4026
|
}, selectActionImplementation = ({
|
|
4081
4027
|
action
|
|
4082
4028
|
}) => {
|
|
4083
|
-
const newSelection = toSlateRange(action.
|
|
4029
|
+
const newSelection = toSlateRange(action.at, action.editor);
|
|
4084
4030
|
newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
|
|
4031
|
+
}, splitBlockActionImplementation = ({
|
|
4032
|
+
context,
|
|
4033
|
+
action
|
|
4034
|
+
}) => {
|
|
4035
|
+
const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
|
|
4036
|
+
if (!editor.selection)
|
|
4037
|
+
return;
|
|
4038
|
+
const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
4039
|
+
if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
4040
|
+
slate.Transforms.splitNodes(editor, {
|
|
4041
|
+
at: editor.selection,
|
|
4042
|
+
always: !0
|
|
4043
|
+
});
|
|
4044
|
+
const [nextBlock, nextBlockPath] = slate.Editor.node(editor, slate.Path.next(focusBlockPath), {
|
|
4045
|
+
depth: 1
|
|
4046
|
+
}), nextChild = slate.Node.child(nextBlock, 0);
|
|
4047
|
+
if (!editor.isTextSpan(nextChild) && slate.Transforms.insertNodes(editor, {
|
|
4048
|
+
_key: context.keyGenerator(),
|
|
4049
|
+
_type: "span",
|
|
4050
|
+
text: "",
|
|
4051
|
+
marks: []
|
|
4052
|
+
}, {
|
|
4053
|
+
at: [nextBlockPath[0], 0]
|
|
4054
|
+
}), slate.Transforms.setSelection(editor, {
|
|
4055
|
+
anchor: {
|
|
4056
|
+
path: [...nextBlockPath, 0],
|
|
4057
|
+
offset: 0
|
|
4058
|
+
},
|
|
4059
|
+
focus: {
|
|
4060
|
+
path: [...nextBlockPath, 0],
|
|
4061
|
+
offset: 0
|
|
4062
|
+
}
|
|
4063
|
+
}), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
|
|
4064
|
+
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);
|
|
4065
|
+
for (const [child, childPath] of children) {
|
|
4066
|
+
if (!editor.isTextSpan(child))
|
|
4067
|
+
continue;
|
|
4068
|
+
const marks = child.marks ?? [];
|
|
4069
|
+
for (const mark of marks)
|
|
4070
|
+
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
4071
|
+
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
4072
|
+
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
4073
|
+
marks: newMarks
|
|
4074
|
+
}, {
|
|
4075
|
+
at: childPath
|
|
4076
|
+
});
|
|
4077
|
+
}
|
|
4078
|
+
const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
|
|
4079
|
+
...markDef,
|
|
4080
|
+
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
4081
|
+
}));
|
|
4082
|
+
isEqual__default.default(nextBlock.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
4083
|
+
markDefs: newMarkDefs
|
|
4084
|
+
}, {
|
|
4085
|
+
at: nextBlockPath,
|
|
4086
|
+
match: (node) => editor.isTextBlock(node)
|
|
4087
|
+
});
|
|
4088
|
+
}
|
|
4089
|
+
return;
|
|
4090
|
+
}
|
|
4091
|
+
slate.Transforms.splitNodes(editor, {
|
|
4092
|
+
always: !0
|
|
4093
|
+
});
|
|
4085
4094
|
}, debug$a = debugWithName("behaviors:action"), behaviorActionImplementations = {
|
|
4086
4095
|
"annotation.add": addAnnotationActionImplementation,
|
|
4087
4096
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
@@ -4099,15 +4108,14 @@ const insertTextActionImplementation = ({
|
|
|
4099
4108
|
"history.redo": historyRedoActionImplementation,
|
|
4100
4109
|
"history.undo": historyUndoActionImplementation,
|
|
4101
4110
|
"insert.block": insertBlockActionImplementation,
|
|
4102
|
-
"insert.break": insertBreakActionImplementation,
|
|
4103
4111
|
"insert.inline object": insertInlineObjectActionImplementation,
|
|
4104
|
-
"insert.soft break": insertSoftBreakActionImplementation,
|
|
4105
4112
|
"insert.span": insertSpanActionImplementation,
|
|
4106
4113
|
"insert.text": insertTextActionImplementation,
|
|
4107
4114
|
effect: effectActionImplementation,
|
|
4108
4115
|
"move.block": moveBlockActionImplementation,
|
|
4109
4116
|
noop: noopActionImplementation,
|
|
4110
|
-
select: selectActionImplementation
|
|
4117
|
+
select: selectActionImplementation,
|
|
4118
|
+
"split.block": splitBlockActionImplementation
|
|
4111
4119
|
};
|
|
4112
4120
|
function performAction({
|
|
4113
4121
|
context,
|
|
@@ -4240,20 +4248,6 @@ function performAction({
|
|
|
4240
4248
|
});
|
|
4241
4249
|
break;
|
|
4242
4250
|
}
|
|
4243
|
-
case "insert.break": {
|
|
4244
|
-
behaviorActionImplementations["insert.break"]({
|
|
4245
|
-
context,
|
|
4246
|
-
action
|
|
4247
|
-
});
|
|
4248
|
-
break;
|
|
4249
|
-
}
|
|
4250
|
-
case "insert.soft break": {
|
|
4251
|
-
behaviorActionImplementations["insert.soft break"]({
|
|
4252
|
-
context,
|
|
4253
|
-
action
|
|
4254
|
-
});
|
|
4255
|
-
break;
|
|
4256
|
-
}
|
|
4257
4251
|
case "insert.span": {
|
|
4258
4252
|
behaviorActionImplementations["insert.span"]({
|
|
4259
4253
|
context,
|
|
@@ -4277,6 +4271,13 @@ function performAction({
|
|
|
4277
4271
|
}
|
|
4278
4272
|
case "noop":
|
|
4279
4273
|
break;
|
|
4274
|
+
case "split.block": {
|
|
4275
|
+
behaviorActionImplementations["split.block"]({
|
|
4276
|
+
context,
|
|
4277
|
+
action
|
|
4278
|
+
});
|
|
4279
|
+
break;
|
|
4280
|
+
}
|
|
4280
4281
|
default: {
|
|
4281
4282
|
behaviorActionImplementations.select({
|
|
4282
4283
|
context,
|
|
@@ -4350,12 +4351,14 @@ function createWithEventListeners(editorActor) {
|
|
|
4350
4351
|
});
|
|
4351
4352
|
}, editor.insertSoftBreak = () => {
|
|
4352
4353
|
if (isApplyingBehaviorActions(editor)) {
|
|
4353
|
-
|
|
4354
|
+
insertTextActionImplementation({
|
|
4354
4355
|
context: {
|
|
4355
4356
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
4356
4357
|
schema: editorActor.getSnapshot().context.schema
|
|
4357
4358
|
},
|
|
4358
4359
|
action: {
|
|
4360
|
+
text: `
|
|
4361
|
+
`,
|
|
4359
4362
|
editor
|
|
4360
4363
|
}
|
|
4361
4364
|
});
|
|
@@ -4415,7 +4418,7 @@ function createWithEventListeners(editorActor) {
|
|
|
4415
4418
|
type: "behavior event",
|
|
4416
4419
|
behaviorEvent: {
|
|
4417
4420
|
type: "select",
|
|
4418
|
-
|
|
4421
|
+
at: slateRangeToSelection({
|
|
4419
4422
|
schema: editorActor.getSnapshot().context.schema,
|
|
4420
4423
|
editor,
|
|
4421
4424
|
range
|
|
@@ -5148,7 +5151,10 @@ function compileSchemaDefinition(definition) {
|
|
|
5148
5151
|
// This avoids the default title which is a title case of the object name
|
|
5149
5152
|
defaultObjectTitles[blockObject.name]
|
|
5150
5153
|
) : blockObject.title,
|
|
5151
|
-
fields:
|
|
5154
|
+
fields: blockObject.fields?.map((field) => ({
|
|
5155
|
+
name: field.name,
|
|
5156
|
+
type: field.type
|
|
5157
|
+
})) ?? []
|
|
5152
5158
|
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
|
|
5153
5159
|
type: "object",
|
|
5154
5160
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
@@ -5158,7 +5164,10 @@ function compileSchemaDefinition(definition) {
|
|
|
5158
5164
|
// This avoids the default title which is a title case of the object name
|
|
5159
5165
|
defaultObjectTitles[inlineObject.name]
|
|
5160
5166
|
) : inlineObject.title,
|
|
5161
|
-
fields:
|
|
5167
|
+
fields: inlineObject.fields?.map((field) => ({
|
|
5168
|
+
name: field.name,
|
|
5169
|
+
type: field.type
|
|
5170
|
+
})) ?? []
|
|
5162
5171
|
})) ?? [], portableTextSchema = types.defineField({
|
|
5163
5172
|
type: "array",
|
|
5164
5173
|
name: "portable-text",
|
|
@@ -5178,7 +5187,11 @@ function compileSchemaDefinition(definition) {
|
|
|
5178
5187
|
annotations: definition?.annotations?.map((annotation) => ({
|
|
5179
5188
|
name: annotation.name,
|
|
5180
5189
|
type: "object",
|
|
5181
|
-
title: annotation.title
|
|
5190
|
+
title: annotation.title,
|
|
5191
|
+
fields: annotation.fields?.map((field) => ({
|
|
5192
|
+
name: field.name,
|
|
5193
|
+
type: field.type
|
|
5194
|
+
})) ?? []
|
|
5182
5195
|
})) ?? []
|
|
5183
5196
|
},
|
|
5184
5197
|
lists: definition?.lists?.map((list) => ({
|
|
@@ -5251,9 +5264,9 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5251
5264
|
snapshot,
|
|
5252
5265
|
event
|
|
5253
5266
|
}) => {
|
|
5254
|
-
const manualSelection = event.
|
|
5267
|
+
const manualSelection = event.at ? util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
5255
5268
|
value: snapshot.context.value,
|
|
5256
|
-
offsets: event.
|
|
5269
|
+
offsets: event.at
|
|
5257
5270
|
}) : null;
|
|
5258
5271
|
return manualSelection ? !selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)({
|
|
5259
5272
|
...snapshot,
|
|
@@ -5309,7 +5322,7 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5309
5322
|
placement: "auto",
|
|
5310
5323
|
select: "end"
|
|
5311
5324
|
})] : event.blocks.flatMap((block, index) => index === 0 ? [behavior_core.raise({
|
|
5312
|
-
type: "
|
|
5325
|
+
type: "split.block"
|
|
5313
5326
|
}), behavior_core.raise({
|
|
5314
5327
|
type: "select.previous block",
|
|
5315
5328
|
select: "end"
|
|
@@ -5345,6 +5358,18 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5345
5358
|
placement: index === 0 ? "auto" : "after",
|
|
5346
5359
|
select: "end"
|
|
5347
5360
|
}))]
|
|
5361
|
+
}), behavior_core.defineBehavior({
|
|
5362
|
+
on: "insert.break",
|
|
5363
|
+
actions: [() => [behavior_core.raise({
|
|
5364
|
+
type: "split.block"
|
|
5365
|
+
})]]
|
|
5366
|
+
}), behavior_core.defineBehavior({
|
|
5367
|
+
on: "insert.soft break",
|
|
5368
|
+
actions: [() => [behavior_core.raise({
|
|
5369
|
+
type: "insert.text",
|
|
5370
|
+
text: `
|
|
5371
|
+
`
|
|
5372
|
+
})]]
|
|
5348
5373
|
})], abstractListItemBehaviors = [behavior_core.defineBehavior({
|
|
5349
5374
|
on: "list item.add",
|
|
5350
5375
|
guard: ({
|
|
@@ -5491,7 +5516,7 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5491
5516
|
selection
|
|
5492
5517
|
}) => [behavior_core.raise({
|
|
5493
5518
|
type: "select",
|
|
5494
|
-
selection
|
|
5519
|
+
at: selection
|
|
5495
5520
|
})]]
|
|
5496
5521
|
}), behavior_core.defineBehavior({
|
|
5497
5522
|
on: "select.next block",
|
|
@@ -5514,7 +5539,7 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5514
5539
|
selection
|
|
5515
5540
|
}) => [behavior_core.raise({
|
|
5516
5541
|
type: "select",
|
|
5517
|
-
selection
|
|
5542
|
+
at: selection
|
|
5518
5543
|
})]]
|
|
5519
5544
|
})], abstractStyleBehaviors = [behavior_core.defineBehavior({
|
|
5520
5545
|
on: "style.add",
|
|
@@ -5692,7 +5717,7 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5692
5717
|
originEvent: event
|
|
5693
5718
|
}), behavior_core.raise({
|
|
5694
5719
|
type: "delete",
|
|
5695
|
-
selection
|
|
5720
|
+
at: selection
|
|
5696
5721
|
})]]
|
|
5697
5722
|
}),
|
|
5698
5723
|
behavior_core.defineBehavior({
|
|
@@ -5751,7 +5776,7 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5751
5776
|
event
|
|
5752
5777
|
}) => [behavior_core.raise({
|
|
5753
5778
|
type: "select",
|
|
5754
|
-
|
|
5779
|
+
at: event.position.selection
|
|
5755
5780
|
}), behavior_core.raise({
|
|
5756
5781
|
type: "deserialize",
|
|
5757
5782
|
originEvent: event
|
|
@@ -5801,7 +5826,7 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5801
5826
|
at: block.path
|
|
5802
5827
|
})) : [behavior_core.raise({
|
|
5803
5828
|
type: "delete",
|
|
5804
|
-
|
|
5829
|
+
at: dragOrigin.selection
|
|
5805
5830
|
})], behavior_core.raise({
|
|
5806
5831
|
type: "insert.blocks",
|
|
5807
5832
|
blocks: event.data,
|
|
@@ -5895,7 +5920,7 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5895
5920
|
selection
|
|
5896
5921
|
}) => [behavior_core.raise({
|
|
5897
5922
|
type: "delete",
|
|
5898
|
-
selection
|
|
5923
|
+
at: selection
|
|
5899
5924
|
}), behavior_core.raise({
|
|
5900
5925
|
type: "deserialize",
|
|
5901
5926
|
originEvent: event
|
|
@@ -5929,7 +5954,7 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5929
5954
|
raiseDeserializationSuccessOrFailure,
|
|
5930
5955
|
raiseSerializationSuccessOrFailure,
|
|
5931
5956
|
raiseInsertSoftBreak
|
|
5932
|
-
], 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"];
|
|
5957
|
+
], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "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"];
|
|
5933
5958
|
function isAbstractBehaviorEvent(event) {
|
|
5934
5959
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
5935
5960
|
}
|