@portabletext/editor 1.47.9 → 1.47.11
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/editor-provider.cjs +105 -73
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +0 -4
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +8 -0
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +108 -76
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js +0 -4
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +8 -0
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.d.cts +359 -339
- package/lib/behaviors/index.d.ts +359 -339
- package/lib/behaviors/index.js +1 -1
- package/lib/index.cjs +3 -3
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +4 -4
- package/lib/index.d.ts +4 -4
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +4 -4
- package/lib/plugins/index.d.ts +4 -4
- package/lib/selectors/index.d.cts +4 -4
- package/lib/selectors/index.d.ts +4 -4
- package/lib/utils/index.cjs +2 -5
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +4 -4
- package/lib/utils/index.d.ts +4 -4
- package/lib/utils/index.js +2 -5
- package/lib/utils/index.js.map +1 -1
- package/package.json +4 -4
- package/src/behavior-actions/behavior.actions.ts +0 -9
- package/src/behaviors/behavior.abstract.split.ts +162 -0
- package/src/behaviors/behavior.default.ts +2 -0
- package/src/behaviors/behavior.types.event.ts +4 -4
- package/src/behavior-actions/behavior.action.split.block.ts +0 -146
|
@@ -3965,69 +3965,6 @@ const moveBackwardActionImplementation = ({
|
|
|
3965
3965
|
}) => {
|
|
3966
3966
|
const newSelection = toSlateRange(action.at, action.editor);
|
|
3967
3967
|
newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
|
|
3968
|
-
}, splitBlockActionImplementation = ({
|
|
3969
|
-
context,
|
|
3970
|
-
action
|
|
3971
|
-
}) => {
|
|
3972
|
-
const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
|
|
3973
|
-
if (!editor.selection)
|
|
3974
|
-
return;
|
|
3975
|
-
const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
3976
|
-
if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
3977
|
-
slate.Transforms.splitNodes(editor, {
|
|
3978
|
-
at: editor.selection,
|
|
3979
|
-
always: !0
|
|
3980
|
-
});
|
|
3981
|
-
const [nextBlock, nextBlockPath] = slate.Editor.node(editor, slate.Path.next(focusBlockPath), {
|
|
3982
|
-
depth: 1
|
|
3983
|
-
}), nextChild = slate.Node.child(nextBlock, 0);
|
|
3984
|
-
if (!editor.isTextSpan(nextChild) && slate.Transforms.insertNodes(editor, {
|
|
3985
|
-
_key: context.keyGenerator(),
|
|
3986
|
-
_type: "span",
|
|
3987
|
-
text: "",
|
|
3988
|
-
marks: []
|
|
3989
|
-
}, {
|
|
3990
|
-
at: [nextBlockPath[0], 0]
|
|
3991
|
-
}), slate.Transforms.setSelection(editor, {
|
|
3992
|
-
anchor: {
|
|
3993
|
-
path: [...nextBlockPath, 0],
|
|
3994
|
-
offset: 0
|
|
3995
|
-
},
|
|
3996
|
-
focus: {
|
|
3997
|
-
path: [...nextBlockPath, 0],
|
|
3998
|
-
offset: 0
|
|
3999
|
-
}
|
|
4000
|
-
}), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
|
|
4001
|
-
const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(slate.Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = slate.Node.children(editor, nextBlockPath);
|
|
4002
|
-
for (const [child, childPath] of children) {
|
|
4003
|
-
if (!editor.isTextSpan(child))
|
|
4004
|
-
continue;
|
|
4005
|
-
const marks = child.marks ?? [];
|
|
4006
|
-
for (const mark of marks)
|
|
4007
|
-
schema2.decorators.some((decorator) => decorator.name === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
4008
|
-
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
4009
|
-
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
4010
|
-
marks: newMarks
|
|
4011
|
-
}, {
|
|
4012
|
-
at: childPath
|
|
4013
|
-
});
|
|
4014
|
-
}
|
|
4015
|
-
const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
|
|
4016
|
-
...markDef,
|
|
4017
|
-
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
4018
|
-
}));
|
|
4019
|
-
isEqual__default.default(nextBlock.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
4020
|
-
markDefs: newMarkDefs
|
|
4021
|
-
}, {
|
|
4022
|
-
at: nextBlockPath,
|
|
4023
|
-
match: (node) => editor.isTextBlock(node)
|
|
4024
|
-
});
|
|
4025
|
-
}
|
|
4026
|
-
return;
|
|
4027
|
-
}
|
|
4028
|
-
slate.Transforms.splitNodes(editor, {
|
|
4029
|
-
always: !0
|
|
4030
|
-
});
|
|
4031
3968
|
}, debug$a = debugWithName("behaviors:action"), behaviorActionImplementations = {
|
|
4032
3969
|
"annotation.add": addAnnotationActionImplementation,
|
|
4033
3970
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
@@ -4050,8 +3987,7 @@ const moveBackwardActionImplementation = ({
|
|
|
4050
3987
|
"move.block": moveBlockActionImplementation,
|
|
4051
3988
|
"move.forward": moveForwardActionImplementation,
|
|
4052
3989
|
noop: noopActionImplementation,
|
|
4053
|
-
select: selectActionImplementation
|
|
4054
|
-
"split.block": splitBlockActionImplementation
|
|
3990
|
+
select: selectActionImplementation
|
|
4055
3991
|
};
|
|
4056
3992
|
function performAction({
|
|
4057
3993
|
context,
|
|
@@ -4200,13 +4136,6 @@ function performAction({
|
|
|
4200
4136
|
}
|
|
4201
4137
|
case "noop":
|
|
4202
4138
|
break;
|
|
4203
|
-
case "split.block": {
|
|
4204
|
-
behaviorActionImplementations["split.block"]({
|
|
4205
|
-
context,
|
|
4206
|
-
action
|
|
4207
|
-
});
|
|
4208
|
-
break;
|
|
4209
|
-
}
|
|
4210
4139
|
default: {
|
|
4211
4140
|
behaviorActionImplementations.select({
|
|
4212
4141
|
context,
|
|
@@ -6157,6 +6086,108 @@ const EditorActorContext = React.createContext({}), abstractAnnotationBehaviors
|
|
|
6157
6086
|
type: "select",
|
|
6158
6087
|
at: selection
|
|
6159
6088
|
})]]
|
|
6089
|
+
})], abstractSplitBehaviors = [behavior_core.defineBehavior({
|
|
6090
|
+
on: "split.block",
|
|
6091
|
+
guard: ({
|
|
6092
|
+
snapshot
|
|
6093
|
+
}) => {
|
|
6094
|
+
if (!snapshot.context.selection || !selector_isOverlappingSelection.isSelectionExpanded(snapshot))
|
|
6095
|
+
return !1;
|
|
6096
|
+
const firstBlock = selector_isOverlappingSelection.getFirstBlock(snapshot), lastBlock = selector_isOverlappingSelection.getLastBlock(snapshot);
|
|
6097
|
+
if (!firstBlock || !lastBlock)
|
|
6098
|
+
return !1;
|
|
6099
|
+
const firstBlockStartPoint = util_sliceBlocks.getBlockStartPoint(firstBlock), selectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint(snapshot.context.selection), lastBlockEndPoint = util_sliceBlocks.getBlockEndPoint(lastBlock), selectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint(snapshot.context.selection);
|
|
6100
|
+
return util_sliceBlocks.isEqualSelectionPoints(firstBlockStartPoint, selectionStartPoint) && util_sliceBlocks.isEqualSelectionPoints(lastBlockEndPoint, selectionEndPoint) ? {
|
|
6101
|
+
selection: snapshot.context.selection
|
|
6102
|
+
} : !1;
|
|
6103
|
+
},
|
|
6104
|
+
actions: [(_, {
|
|
6105
|
+
selection
|
|
6106
|
+
}) => [behavior_core.raise({
|
|
6107
|
+
type: "delete",
|
|
6108
|
+
at: selection
|
|
6109
|
+
})]]
|
|
6110
|
+
}), behavior_core.defineBehavior({
|
|
6111
|
+
on: "split.block",
|
|
6112
|
+
guard: ({
|
|
6113
|
+
snapshot
|
|
6114
|
+
}) => {
|
|
6115
|
+
if (!snapshot.context.selection)
|
|
6116
|
+
return !1;
|
|
6117
|
+
const selectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint(snapshot.context.selection), selectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint(snapshot.context.selection), focusTextBlock = selector_isOverlappingSelection.getFocusTextBlock({
|
|
6118
|
+
context: {
|
|
6119
|
+
...snapshot.context,
|
|
6120
|
+
selection: {
|
|
6121
|
+
anchor: selectionStartPoint,
|
|
6122
|
+
focus: selectionEndPoint
|
|
6123
|
+
}
|
|
6124
|
+
}
|
|
6125
|
+
});
|
|
6126
|
+
if (focusTextBlock) {
|
|
6127
|
+
const blockEndPoint = util_sliceBlocks.getBlockEndPoint(focusTextBlock), newTextBlockSelection = {
|
|
6128
|
+
anchor: selectionEndPoint,
|
|
6129
|
+
focus: blockEndPoint
|
|
6130
|
+
}, newTextBlock = parseBlocks.parseBlock({
|
|
6131
|
+
block: util_sliceBlocks.sliceBlocks({
|
|
6132
|
+
blocks: [focusTextBlock.node],
|
|
6133
|
+
selection: newTextBlockSelection
|
|
6134
|
+
}).at(0),
|
|
6135
|
+
context: snapshot.context,
|
|
6136
|
+
options: {
|
|
6137
|
+
refreshKeys: !0
|
|
6138
|
+
}
|
|
6139
|
+
});
|
|
6140
|
+
return !newTextBlock || !parseBlocks.isTextBlock(snapshot.context.schema, newTextBlock) ? !1 : {
|
|
6141
|
+
newTextBlock,
|
|
6142
|
+
newTextBlockSelection,
|
|
6143
|
+
selection: {
|
|
6144
|
+
anchor: selectionStartPoint,
|
|
6145
|
+
focus: blockEndPoint
|
|
6146
|
+
}
|
|
6147
|
+
};
|
|
6148
|
+
}
|
|
6149
|
+
if (selector_isOverlappingSelection.getFocusBlockObject({
|
|
6150
|
+
context: {
|
|
6151
|
+
...snapshot.context,
|
|
6152
|
+
selection: {
|
|
6153
|
+
anchor: selectionStartPoint,
|
|
6154
|
+
focus: selectionEndPoint
|
|
6155
|
+
}
|
|
6156
|
+
}
|
|
6157
|
+
})) {
|
|
6158
|
+
const newTextBlock = parseBlocks.parseBlock({
|
|
6159
|
+
block: {
|
|
6160
|
+
_type: snapshot.context.schema.block.name,
|
|
6161
|
+
children: []
|
|
6162
|
+
},
|
|
6163
|
+
context: snapshot.context,
|
|
6164
|
+
options: {
|
|
6165
|
+
refreshKeys: !0
|
|
6166
|
+
}
|
|
6167
|
+
});
|
|
6168
|
+
return newTextBlock ? {
|
|
6169
|
+
newTextBlock,
|
|
6170
|
+
newTextBlockSelection: {
|
|
6171
|
+
anchor: selectionEndPoint,
|
|
6172
|
+
focus: selectionEndPoint
|
|
6173
|
+
},
|
|
6174
|
+
selection: snapshot.context.selection
|
|
6175
|
+
} : !1;
|
|
6176
|
+
}
|
|
6177
|
+
return !1;
|
|
6178
|
+
},
|
|
6179
|
+
actions: [(_, {
|
|
6180
|
+
newTextBlock,
|
|
6181
|
+
selection
|
|
6182
|
+
}) => [behavior_core.raise({
|
|
6183
|
+
type: "delete",
|
|
6184
|
+
at: selection
|
|
6185
|
+
}), behavior_core.raise({
|
|
6186
|
+
type: "insert.block",
|
|
6187
|
+
block: newTextBlock,
|
|
6188
|
+
placement: "after",
|
|
6189
|
+
select: "start"
|
|
6190
|
+
})]]
|
|
6160
6191
|
})], abstractStyleBehaviors = [behavior_core.defineBehavior({
|
|
6161
6192
|
on: "style.add",
|
|
6162
6193
|
guard: ({
|
|
@@ -6568,10 +6599,11 @@ const EditorActorContext = React.createContext({}), abstractAnnotationBehaviors
|
|
|
6568
6599
|
...abstractMoveBehaviors,
|
|
6569
6600
|
...abstractStyleBehaviors,
|
|
6570
6601
|
...abstractSelectBehaviors,
|
|
6602
|
+
...abstractSplitBehaviors,
|
|
6571
6603
|
raiseDeserializationSuccessOrFailure,
|
|
6572
6604
|
raiseSerializationSuccessOrFailure,
|
|
6573
6605
|
raiseInsertSoftBreak
|
|
6574
|
-
], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "style.add", "style.remove", "style.toggle"];
|
|
6606
|
+
], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "delete.text", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "split.block", "style.add", "style.remove", "style.toggle"];
|
|
6575
6607
|
function isAbstractBehaviorEvent(event) {
|
|
6576
6608
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
6577
6609
|
}
|