@portabletext/editor 4.2.1 → 4.2.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-dts/behavior.types.action.d.ts +1 -0
- package/lib/index.js +695 -238
- package/lib/index.js.map +1 -1
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -3491,7 +3491,7 @@ function createBehaviorApiPlugin(editorActor) {
|
|
|
3491
3491
|
delete: editorDelete,
|
|
3492
3492
|
insertNodes,
|
|
3493
3493
|
select,
|
|
3494
|
-
setSelection
|
|
3494
|
+
setSelection: setSelection2
|
|
3495
3495
|
} = editor;
|
|
3496
3496
|
return editor.delete = (options) => {
|
|
3497
3497
|
if (editor.isNormalizingNode || editor.isPerformingBehaviorOperation) {
|
|
@@ -3645,7 +3645,7 @@ function createBehaviorApiPlugin(editorActor) {
|
|
|
3645
3645
|
});
|
|
3646
3646
|
}, editor.setSelection = (partialRange) => {
|
|
3647
3647
|
if (editor.isNormalizingNode || editor.isPerformingBehaviorOperation) {
|
|
3648
|
-
|
|
3648
|
+
setSelection2(partialRange);
|
|
3649
3649
|
return;
|
|
3650
3650
|
}
|
|
3651
3651
|
const anchor = partialRange.anchor ? slatePointToSelectionPoint({
|
|
@@ -3666,12 +3666,12 @@ function createBehaviorApiPlugin(editorActor) {
|
|
|
3666
3666
|
if (editor.selection) {
|
|
3667
3667
|
const newAnchor = partialRange.anchor ?? editor.selection.anchor, newFocus = partialRange.focus ?? editor.selection.focus;
|
|
3668
3668
|
if (Point.equals(newAnchor, editor.selection.anchor) && Point.equals(newFocus, editor.selection.focus)) {
|
|
3669
|
-
|
|
3669
|
+
setSelection2(partialRange);
|
|
3670
3670
|
return;
|
|
3671
3671
|
}
|
|
3672
3672
|
}
|
|
3673
3673
|
if (!anchor || !focus) {
|
|
3674
|
-
|
|
3674
|
+
setSelection2(partialRange);
|
|
3675
3675
|
return;
|
|
3676
3676
|
}
|
|
3677
3677
|
editorActor.send({
|
|
@@ -6271,25 +6271,44 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
6271
6271
|
guard: ({
|
|
6272
6272
|
snapshot,
|
|
6273
6273
|
event
|
|
6274
|
-
}) =>
|
|
6274
|
+
}) => {
|
|
6275
|
+
const at = event.at ?? snapshot.context.selection;
|
|
6276
|
+
if (!at)
|
|
6277
|
+
return !1;
|
|
6278
|
+
const adjustedSnapshot = {
|
|
6279
|
+
...snapshot,
|
|
6280
|
+
context: {
|
|
6281
|
+
...snapshot.context,
|
|
6282
|
+
selection: at
|
|
6283
|
+
}
|
|
6284
|
+
};
|
|
6285
|
+
return isActiveDecorator(event.decorator)(adjustedSnapshot);
|
|
6286
|
+
},
|
|
6275
6287
|
actions: [({
|
|
6276
6288
|
event
|
|
6277
6289
|
}) => [raise({
|
|
6278
6290
|
type: "decorator.remove",
|
|
6279
|
-
decorator: event.decorator
|
|
6291
|
+
decorator: event.decorator,
|
|
6292
|
+
at: event.at
|
|
6280
6293
|
})]]
|
|
6281
6294
|
}), defineBehavior({
|
|
6282
6295
|
on: "decorator.toggle",
|
|
6283
6296
|
guard: ({
|
|
6284
6297
|
snapshot,
|
|
6285
6298
|
event
|
|
6286
|
-
}) =>
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6299
|
+
}) => {
|
|
6300
|
+
const at = event.at ?? snapshot.context.selection;
|
|
6301
|
+
if (!at)
|
|
6302
|
+
return !1;
|
|
6303
|
+
const adjustedSnapshot = {
|
|
6304
|
+
...snapshot,
|
|
6305
|
+
context: {
|
|
6306
|
+
...snapshot.context,
|
|
6307
|
+
selection: at
|
|
6308
|
+
}
|
|
6309
|
+
};
|
|
6310
|
+
return !isActiveDecorator(event.decorator)(adjustedSnapshot);
|
|
6311
|
+
},
|
|
6293
6312
|
actions: [({
|
|
6294
6313
|
event
|
|
6295
6314
|
}) => [raise({
|
|
@@ -6316,8 +6335,17 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
6316
6335
|
}) => {
|
|
6317
6336
|
if (event.direction !== "backward")
|
|
6318
6337
|
return !1;
|
|
6319
|
-
const
|
|
6320
|
-
if (!
|
|
6338
|
+
const at = event.at ?? snapshot.context.selection;
|
|
6339
|
+
if (!at)
|
|
6340
|
+
return !1;
|
|
6341
|
+
const adjustedSnapshot = {
|
|
6342
|
+
...snapshot,
|
|
6343
|
+
context: {
|
|
6344
|
+
...snapshot.context,
|
|
6345
|
+
selection: at
|
|
6346
|
+
}
|
|
6347
|
+
}, previousBlock = getPreviousBlock(adjustedSnapshot), focusTextBlock = getFocusTextBlock(adjustedSnapshot);
|
|
6348
|
+
if (!previousBlock || !focusTextBlock || !isAtTheStartOfBlock(focusTextBlock)(adjustedSnapshot))
|
|
6321
6349
|
return !1;
|
|
6322
6350
|
const previousBlockEndPoint = getBlockEndPoint({
|
|
6323
6351
|
context: snapshot.context,
|
|
@@ -6414,8 +6442,17 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
6414
6442
|
}) => {
|
|
6415
6443
|
if (event.direction !== "forward")
|
|
6416
6444
|
return !1;
|
|
6417
|
-
const
|
|
6418
|
-
|
|
6445
|
+
const at = event.at ?? snapshot.context.selection;
|
|
6446
|
+
if (!at)
|
|
6447
|
+
return !1;
|
|
6448
|
+
const adjustedSnapshot = {
|
|
6449
|
+
...snapshot,
|
|
6450
|
+
context: {
|
|
6451
|
+
...snapshot.context,
|
|
6452
|
+
selection: at
|
|
6453
|
+
}
|
|
6454
|
+
}, nextBlock = getNextBlock(adjustedSnapshot), focusTextBlock = getFocusTextBlock(adjustedSnapshot);
|
|
6455
|
+
return !nextBlock || !focusTextBlock || !isAtTheEndOfBlock(focusTextBlock)(adjustedSnapshot) || !isTextBlock(snapshot.context, nextBlock.node) ? !1 : {
|
|
6419
6456
|
nextBlock
|
|
6420
6457
|
};
|
|
6421
6458
|
},
|
|
@@ -9104,7 +9141,13 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
9104
9141
|
snapshot,
|
|
9105
9142
|
event
|
|
9106
9143
|
}) => {
|
|
9107
|
-
const
|
|
9144
|
+
const adjustedSnapshot = {
|
|
9145
|
+
...snapshot,
|
|
9146
|
+
context: {
|
|
9147
|
+
...snapshot.context,
|
|
9148
|
+
selection: event.at ?? snapshot.context.selection
|
|
9149
|
+
}
|
|
9150
|
+
}, focusListBlock = getFocusListBlock(adjustedSnapshot);
|
|
9108
9151
|
if (!focusListBlock)
|
|
9109
9152
|
return !1;
|
|
9110
9153
|
const firstInsertedBlock = event.blocks.at(0), secondInsertedBlock = event.blocks.at(1), insertedListBlock = isListBlock(snapshot.context, firstInsertedBlock) ? firstInsertedBlock : isListBlock(snapshot.context, secondInsertedBlock) ? secondInsertedBlock : void 0;
|
|
@@ -9138,7 +9181,13 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
9138
9181
|
snapshot,
|
|
9139
9182
|
event
|
|
9140
9183
|
}) => {
|
|
9141
|
-
const
|
|
9184
|
+
const adjustedSnapshot = {
|
|
9185
|
+
...snapshot,
|
|
9186
|
+
context: {
|
|
9187
|
+
...snapshot.context,
|
|
9188
|
+
selection: event.at ?? snapshot.context.selection
|
|
9189
|
+
}
|
|
9190
|
+
}, focusListBlock = getFocusListBlock(adjustedSnapshot);
|
|
9142
9191
|
if (!focusListBlock || isEmptyTextBlock(snapshot.context, focusListBlock.node))
|
|
9143
9192
|
return !1;
|
|
9144
9193
|
const firstInsertedBlock = event.blocks.at(0), secondInsertedBlock = event.blocks.at(1), insertedListBlock = isListBlock(snapshot.context, firstInsertedBlock) ? firstInsertedBlock : isListBlock(snapshot.context, secondInsertedBlock) ? secondInsertedBlock : void 0;
|
|
@@ -9171,7 +9220,13 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
9171
9220
|
}) => {
|
|
9172
9221
|
if (event.placement !== "auto" || event.block._type !== snapshot.context.schema.block.name || event.block.listItem !== void 0)
|
|
9173
9222
|
return !1;
|
|
9174
|
-
const
|
|
9223
|
+
const adjustedSnapshot = {
|
|
9224
|
+
...snapshot,
|
|
9225
|
+
context: {
|
|
9226
|
+
...snapshot.context,
|
|
9227
|
+
selection: event.at ?? snapshot.context.selection
|
|
9228
|
+
}
|
|
9229
|
+
}, focusListBlock = getFocusListBlock(adjustedSnapshot);
|
|
9175
9230
|
return !focusListBlock || !isEmptyTextBlock(snapshot.context, focusListBlock.node) ? !1 : {
|
|
9176
9231
|
level: focusListBlock.node.level,
|
|
9177
9232
|
listItem: focusListBlock.node.listItem
|
|
@@ -9237,6 +9292,31 @@ function getEventBehaviors(behaviorIndex, type) {
|
|
|
9237
9292
|
const global = behaviorIndex.global, namespace = type.includes(".") ? type.split(".").at(0) : type, namespaced = namespace ? behaviorIndex.namespaced.get(namespace) ?? [] : [], exact = behaviorIndex.exact.get(type) ?? [];
|
|
9238
9293
|
return [...global, ...namespaced, ...exact].sort((a, b) => a.sortOrder - b.sortOrder).map((sortedBehavior) => sortedBehavior.behavior);
|
|
9239
9294
|
}
|
|
9295
|
+
function createEditorSnapshot({
|
|
9296
|
+
converters,
|
|
9297
|
+
editor,
|
|
9298
|
+
keyGenerator,
|
|
9299
|
+
readOnly,
|
|
9300
|
+
schema
|
|
9301
|
+
}) {
|
|
9302
|
+
const selection = editor.selection ? slateRangeToSelection({
|
|
9303
|
+
schema,
|
|
9304
|
+
editor,
|
|
9305
|
+
range: editor.selection
|
|
9306
|
+
}) : null, context = {
|
|
9307
|
+
converters,
|
|
9308
|
+
keyGenerator,
|
|
9309
|
+
readOnly,
|
|
9310
|
+
schema,
|
|
9311
|
+
selection,
|
|
9312
|
+
value: editor.value
|
|
9313
|
+
};
|
|
9314
|
+
return {
|
|
9315
|
+
blockIndexMap: editor.blockIndexMap,
|
|
9316
|
+
context,
|
|
9317
|
+
decoratorState: editor.decoratorState
|
|
9318
|
+
};
|
|
9319
|
+
}
|
|
9240
9320
|
const addAnnotationOperationImplementation = ({
|
|
9241
9321
|
context,
|
|
9242
9322
|
operation
|
|
@@ -9652,19 +9732,31 @@ const addAnnotationOperationImplementation = ({
|
|
|
9652
9732
|
};
|
|
9653
9733
|
}
|
|
9654
9734
|
}, decoratorRemoveOperationImplementation = ({
|
|
9735
|
+
context,
|
|
9655
9736
|
operation
|
|
9656
9737
|
}) => {
|
|
9657
|
-
const editor = operation.editor, mark = operation.decorator, {
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9738
|
+
const editor = operation.editor, mark = operation.decorator, at = operation.at ? toSlateRange({
|
|
9739
|
+
context: {
|
|
9740
|
+
schema: context.schema,
|
|
9741
|
+
value: operation.editor.value,
|
|
9742
|
+
selection: operation.at
|
|
9743
|
+
},
|
|
9744
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
9745
|
+
}) : editor.selection;
|
|
9746
|
+
if (at) {
|
|
9747
|
+
if (Range.isExpanded(at)) {
|
|
9748
|
+
const rangeRef = Editor.rangeRef(editor, at, {
|
|
9749
|
+
affinity: "inward"
|
|
9750
|
+
});
|
|
9662
9751
|
Transforms.setNodes(editor, {}, {
|
|
9752
|
+
at,
|
|
9663
9753
|
match: Text.isText,
|
|
9664
9754
|
split: !0,
|
|
9665
9755
|
hanging: !0
|
|
9666
|
-
})
|
|
9667
|
-
|
|
9756
|
+
});
|
|
9757
|
+
const updatedAt = rangeRef.unref();
|
|
9758
|
+
updatedAt && [...Editor.nodes(editor, {
|
|
9759
|
+
at: updatedAt,
|
|
9668
9760
|
match: Text.isText
|
|
9669
9761
|
})].forEach(([node, path]) => {
|
|
9670
9762
|
const block = editor.children[path[0]];
|
|
@@ -9675,8 +9767,8 @@ const addAnnotationOperationImplementation = ({
|
|
|
9675
9767
|
at: path
|
|
9676
9768
|
});
|
|
9677
9769
|
});
|
|
9678
|
-
else {
|
|
9679
|
-
const [block, blockPath] = Editor.node(editor,
|
|
9770
|
+
} else {
|
|
9771
|
+
const [block, blockPath] = Editor.node(editor, at, {
|
|
9680
9772
|
depth: 1
|
|
9681
9773
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
9682
9774
|
if (lonelyEmptySpan) {
|
|
@@ -9691,9 +9783,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
9691
9783
|
editor.decoratorState[mark] = !1;
|
|
9692
9784
|
}
|
|
9693
9785
|
if (editor.selection) {
|
|
9694
|
-
const
|
|
9786
|
+
const selection = editor.selection;
|
|
9695
9787
|
editor.selection = {
|
|
9696
|
-
...
|
|
9788
|
+
...selection
|
|
9697
9789
|
};
|
|
9698
9790
|
}
|
|
9699
9791
|
}
|
|
@@ -10058,200 +10150,579 @@ function insertBlock(options) {
|
|
|
10058
10150
|
},
|
|
10059
10151
|
blockIndexMap: editor.blockIndexMap
|
|
10060
10152
|
}) : editor.selection;
|
|
10061
|
-
editor.children.length === 0
|
|
10062
|
-
|
|
10063
|
-
|
|
10153
|
+
if (editor.children.length === 0) {
|
|
10154
|
+
insertNodeAt(editor, [0], block, select);
|
|
10155
|
+
return;
|
|
10156
|
+
}
|
|
10064
10157
|
const start = at ? Range.start(at) : Editor.start(editor, []), end = at ? Range.end(at) : Editor.end(editor, []), [startBlock, startBlockPath] = Array.from(Editor.nodes(editor, {
|
|
10065
10158
|
at: start,
|
|
10066
10159
|
mode: "lowest",
|
|
10067
10160
|
match: (node, path) => Element$1.isElement(node) && path.length <= start.path.length
|
|
10068
|
-
})).at(0) ?? [void 0, void 0]
|
|
10161
|
+
})).at(0) ?? [void 0, void 0];
|
|
10162
|
+
let [endBlock, endBlockPath] = Array.from(Editor.nodes(editor, {
|
|
10069
10163
|
at: end,
|
|
10070
10164
|
mode: "lowest",
|
|
10071
10165
|
match: (node, path) => Element$1.isElement(node) && path.length <= end.path.length
|
|
10072
10166
|
})).at(0) ?? [void 0, void 0];
|
|
10073
10167
|
if (!startBlock || !startBlockPath || !endBlock || !endBlockPath)
|
|
10074
10168
|
throw new Error("Unable to insert block without a start and end block");
|
|
10169
|
+
if (placement === "before") {
|
|
10170
|
+
insertNodeAt(editor, startBlockPath, block, select);
|
|
10171
|
+
return;
|
|
10172
|
+
}
|
|
10173
|
+
if (placement === "after") {
|
|
10174
|
+
insertNodeAt(editor, Path.next(endBlockPath), block, select);
|
|
10175
|
+
return;
|
|
10176
|
+
}
|
|
10075
10177
|
if (!at) {
|
|
10076
|
-
if (
|
|
10077
|
-
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
const
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10178
|
+
if (isEmptyTextBlock(context, endBlock)) {
|
|
10179
|
+
replaceEmptyTextBlock(editor, endBlockPath, block, select);
|
|
10180
|
+
return;
|
|
10181
|
+
}
|
|
10182
|
+
if (editor.isTextBlock(block) && editor.isTextBlock(endBlock)) {
|
|
10183
|
+
const selectionBefore = Editor.end(editor, endBlockPath);
|
|
10184
|
+
insertTextBlockFragment(editor, block, selectionBefore), select === "start" ? setSelectionToPoint(editor, selectionBefore) : select === "none" && clearSelection(editor);
|
|
10185
|
+
return;
|
|
10186
|
+
}
|
|
10187
|
+
insertNodeAt(editor, Path.next(endBlockPath), block, select);
|
|
10188
|
+
return;
|
|
10189
|
+
}
|
|
10190
|
+
if (Range.isExpanded(at) && !editor.isTextBlock(block)) {
|
|
10191
|
+
const atBeforeDelete = Editor.rangeRef(editor, at, {
|
|
10192
|
+
affinity: "inward"
|
|
10193
|
+
}), start2 = Range.start(at), startBlock2 = Node.get(editor, [start2.path[0]]), startOfBlock = Editor.start(editor, [start2.path[0]]), isAtStartOfBlock = Element$1.isElement(startBlock2) && Point.equals(start2, startOfBlock);
|
|
10194
|
+
deleteExpandedRange(editor, at);
|
|
10195
|
+
const atAfterDelete = atBeforeDelete.unref() ?? editor.selection, atBeforeInsert = atAfterDelete ? Editor.rangeRef(editor, atAfterDelete, {
|
|
10196
|
+
affinity: "inward"
|
|
10197
|
+
}) : void 0;
|
|
10198
|
+
if (atAfterDelete) {
|
|
10199
|
+
const insertPath = isAtStartOfBlock ? [atAfterDelete.anchor.path[0]] : [atAfterDelete.anchor.path[0] + 1];
|
|
10200
|
+
if (editor.apply({
|
|
10201
|
+
type: "insert_node",
|
|
10202
|
+
path: insertPath,
|
|
10203
|
+
node: block
|
|
10204
|
+
}), select !== "none") {
|
|
10205
|
+
const point = Editor.start(editor, insertPath);
|
|
10206
|
+
editor.apply({
|
|
10207
|
+
type: "set_selection",
|
|
10208
|
+
properties: editor.selection,
|
|
10209
|
+
newProperties: {
|
|
10210
|
+
anchor: point,
|
|
10211
|
+
focus: point
|
|
10212
|
+
}
|
|
10213
|
+
});
|
|
10094
10214
|
}
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10215
|
+
}
|
|
10216
|
+
const atAfterInsert = atBeforeInsert?.unref() ?? editor.selection;
|
|
10217
|
+
if (select === "none" && atAfterInsert && editor.apply({
|
|
10218
|
+
type: "set_selection",
|
|
10219
|
+
properties: editor.selection,
|
|
10220
|
+
newProperties: atAfterInsert
|
|
10221
|
+
}), !editor.isTextBlock(block) && atAfterDelete) {
|
|
10222
|
+
const emptyBlockPath = isAtStartOfBlock ? [atAfterDelete.anchor.path[0] + 1] : [atAfterDelete.anchor.path[0]];
|
|
10223
|
+
try {
|
|
10224
|
+
const potentiallyEmptyBlock = Node.get(editor, emptyBlockPath);
|
|
10225
|
+
Element$1.isElement(potentiallyEmptyBlock) && isEmptyTextBlock(context, potentiallyEmptyBlock) && editor.apply({
|
|
10226
|
+
type: "remove_node",
|
|
10227
|
+
path: emptyBlockPath,
|
|
10228
|
+
node: potentiallyEmptyBlock
|
|
10229
|
+
});
|
|
10230
|
+
} catch {
|
|
10101
10231
|
}
|
|
10102
|
-
const nextPath = Path.next(endBlockPath);
|
|
10103
|
-
Transforms.insertNodes(editor, [block], {
|
|
10104
|
-
at: nextPath,
|
|
10105
|
-
select: !1
|
|
10106
|
-
}), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
10107
10232
|
}
|
|
10108
10233
|
return;
|
|
10109
10234
|
}
|
|
10110
|
-
if (!at)
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
}
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
|
|
10136
|
-
|
|
10137
|
-
|
|
10138
|
-
voids: !0,
|
|
10139
|
-
at: atAfterDelete ?? void 0,
|
|
10140
|
-
select: select !== "none"
|
|
10141
|
-
});
|
|
10142
|
-
const atAfterInsert = atBeforeInsert?.unref() ?? editor.selection;
|
|
10143
|
-
select === "none" && atAfterInsert && Transforms.select(editor, atAfterInsert), isEmptyTextBlock(context, focusBlock) && Transforms.removeNodes(editor, {
|
|
10144
|
-
at: focusBlockPath
|
|
10235
|
+
if (!editor.isTextBlock(block) && editor.isTextBlock(endBlock) && !Range.isExpanded(at)) {
|
|
10236
|
+
const selectionPoint = Range.start(at), blockPath = [selectionPoint.path[0]], blockStartPoint = Editor.start(editor, blockPath), blockEndPoint = Editor.end(editor, blockPath), isAtBlockStart = Point.equals(selectionPoint, blockStartPoint), isAtBlockEnd = Point.equals(selectionPoint, blockEndPoint);
|
|
10237
|
+
if (!isAtBlockStart && !isAtBlockEnd) {
|
|
10238
|
+
const currentBlock = Node.get(editor, blockPath), childIndex = selectionPoint.path[1], childOffset = selectionPoint.offset;
|
|
10239
|
+
if (childOffset > 0) {
|
|
10240
|
+
const textNode = Node.get(editor, selectionPoint.path);
|
|
10241
|
+
if (childOffset < textNode.text.length) {
|
|
10242
|
+
const {
|
|
10243
|
+
text: _2,
|
|
10244
|
+
...properties
|
|
10245
|
+
} = textNode;
|
|
10246
|
+
editor.apply({
|
|
10247
|
+
type: "split_node",
|
|
10248
|
+
path: selectionPoint.path,
|
|
10249
|
+
position: childOffset,
|
|
10250
|
+
properties
|
|
10251
|
+
});
|
|
10252
|
+
}
|
|
10253
|
+
}
|
|
10254
|
+
const splitAtIndex = childOffset > 0 ? childIndex + 1 : childIndex, {
|
|
10255
|
+
children: _,
|
|
10256
|
+
...blockProperties
|
|
10257
|
+
} = currentBlock;
|
|
10258
|
+
editor.apply({
|
|
10259
|
+
type: "split_node",
|
|
10260
|
+
path: blockPath,
|
|
10261
|
+
position: splitAtIndex,
|
|
10262
|
+
properties: blockProperties
|
|
10145
10263
|
});
|
|
10264
|
+
const insertPath = [blockPath[0] + 1];
|
|
10265
|
+
if (editor.apply({
|
|
10266
|
+
type: "insert_node",
|
|
10267
|
+
path: insertPath,
|
|
10268
|
+
node: block
|
|
10269
|
+
}), select === "none") {
|
|
10270
|
+
const firstBlockEndPoint = Editor.end(editor, blockPath);
|
|
10271
|
+
editor.apply({
|
|
10272
|
+
type: "set_selection",
|
|
10273
|
+
properties: editor.selection,
|
|
10274
|
+
newProperties: {
|
|
10275
|
+
anchor: firstBlockEndPoint,
|
|
10276
|
+
focus: firstBlockEndPoint
|
|
10277
|
+
}
|
|
10278
|
+
});
|
|
10279
|
+
} else if (select === "start") {
|
|
10280
|
+
const point = Editor.start(editor, insertPath);
|
|
10281
|
+
editor.apply({
|
|
10282
|
+
type: "set_selection",
|
|
10283
|
+
properties: editor.selection,
|
|
10284
|
+
newProperties: {
|
|
10285
|
+
anchor: point,
|
|
10286
|
+
focus: point
|
|
10287
|
+
}
|
|
10288
|
+
});
|
|
10289
|
+
} else if (select === "end") {
|
|
10290
|
+
const point = Editor.end(editor, insertPath);
|
|
10291
|
+
editor.apply({
|
|
10292
|
+
type: "set_selection",
|
|
10293
|
+
properties: editor.selection,
|
|
10294
|
+
newProperties: {
|
|
10295
|
+
anchor: point,
|
|
10296
|
+
focus: point
|
|
10297
|
+
}
|
|
10298
|
+
});
|
|
10299
|
+
}
|
|
10146
10300
|
return;
|
|
10147
10301
|
}
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
10157
|
-
|
|
10158
|
-
|
|
10159
|
-
|
|
10160
|
-
if (endBlockMarkDefsKeys.includes(markDef._key)) {
|
|
10161
|
-
const newKey = context.keyGenerator();
|
|
10162
|
-
return markDefKeyMap.set(markDef._key, newKey), {
|
|
10163
|
-
...markDef,
|
|
10164
|
-
_key: newKey
|
|
10302
|
+
}
|
|
10303
|
+
if (editor.isTextBlock(endBlock) && editor.isTextBlock(block)) {
|
|
10304
|
+
let selectionStartPoint = Range.start(at), wasCrossBlockDeletion = !1;
|
|
10305
|
+
if (Range.isExpanded(at)) {
|
|
10306
|
+
const [start2, end2] = Range.edges(at), isCrossBlock = start2.path[0] !== end2.path[0];
|
|
10307
|
+
if (deleteExpandedRange(editor, at), isCrossBlock) {
|
|
10308
|
+
wasCrossBlockDeletion = !0;
|
|
10309
|
+
const startBlockPath2 = [start2.path[0]], mergedBlock = Node.get(editor, startBlockPath2);
|
|
10310
|
+
if (editor.isTextBlock(mergedBlock)) {
|
|
10311
|
+
const mergePoint = {
|
|
10312
|
+
path: [...startBlockPath2, start2.path[1]],
|
|
10313
|
+
offset: start2.offset
|
|
10165
10314
|
};
|
|
10315
|
+
setSelectionToPoint(editor, mergePoint), selectionStartPoint = mergePoint;
|
|
10166
10316
|
}
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
|
|
10170
|
-
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
|
|
10317
|
+
}
|
|
10318
|
+
const [newEndBlock, newEndBlockPath] = Array.from(Editor.nodes(editor, {
|
|
10319
|
+
at: Editor.end(editor, []),
|
|
10320
|
+
mode: "lowest",
|
|
10321
|
+
match: (node, path) => Element$1.isElement(node) && path.length === 1
|
|
10322
|
+
})).at(-1) ?? [void 0, void 0];
|
|
10323
|
+
newEndBlock && newEndBlockPath && Element$1.isElement(newEndBlock) && (endBlock = newEndBlock, endBlockPath = newEndBlockPath);
|
|
10324
|
+
}
|
|
10325
|
+
if (!editor.isTextBlock(endBlock))
|
|
10326
|
+
return;
|
|
10327
|
+
if (isEmptyTextBlock(context, endBlock)) {
|
|
10328
|
+
replaceEmptyTextBlock(editor, endBlockPath, block, select);
|
|
10329
|
+
return;
|
|
10330
|
+
}
|
|
10331
|
+
const endBlockChildKeys = endBlock.children.map((child) => child._key), endBlockMarkDefsKeys = endBlock.markDefs?.map((markDef) => markDef._key) ?? [], markDefKeyMap = /* @__PURE__ */ new Map(), adjustedMarkDefs = block.markDefs?.map((markDef) => {
|
|
10332
|
+
if (endBlockMarkDefsKeys.includes(markDef._key)) {
|
|
10333
|
+
const newKey = context.keyGenerator();
|
|
10334
|
+
return markDefKeyMap.set(markDef._key, newKey), {
|
|
10335
|
+
...markDef,
|
|
10336
|
+
_key: newKey
|
|
10337
|
+
};
|
|
10338
|
+
}
|
|
10339
|
+
return markDef;
|
|
10340
|
+
}), adjustedChildren = block.children.map((child) => {
|
|
10341
|
+
if (isSpan(context, child)) {
|
|
10342
|
+
const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
10343
|
+
if (!isEqualMarks(child.marks, marks))
|
|
10344
|
+
return {
|
|
10345
|
+
...child,
|
|
10346
|
+
_key: endBlockChildKeys.includes(child._key) ? context.keyGenerator() : child._key,
|
|
10347
|
+
marks
|
|
10348
|
+
};
|
|
10349
|
+
}
|
|
10350
|
+
return endBlockChildKeys.includes(child._key) ? {
|
|
10351
|
+
...child,
|
|
10352
|
+
_key: context.keyGenerator()
|
|
10353
|
+
} : child;
|
|
10354
|
+
}), endBlockNode = Node.get(editor, endBlockPath);
|
|
10355
|
+
if (Element$1.isElement(endBlockNode) && editor.isTextBlock(endBlockNode)) {
|
|
10356
|
+
const properties = {
|
|
10357
|
+
markDefs: endBlockNode.markDefs
|
|
10358
|
+
}, newProperties = {
|
|
10184
10359
|
markDefs: [...endBlock.markDefs ?? [], ...adjustedMarkDefs ?? []]
|
|
10185
|
-
}, {
|
|
10186
|
-
at: endBlockPath
|
|
10187
|
-
});
|
|
10188
|
-
const adjustedBlock = isEqualChildren(block.children, adjustedChildren) ? block : {
|
|
10189
|
-
...block,
|
|
10190
|
-
children: adjustedChildren
|
|
10191
10360
|
};
|
|
10192
|
-
|
|
10193
|
-
|
|
10194
|
-
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
}
|
|
10198
|
-
|
|
10199
|
-
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
}
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
|
|
10207
|
-
|
|
10208
|
-
|
|
10209
|
-
|
|
10210
|
-
|
|
10211
|
-
|
|
10212
|
-
|
|
10213
|
-
Transforms.insertNodes(editor, [block], {
|
|
10214
|
-
at: nextPath,
|
|
10215
|
-
select: !1
|
|
10216
|
-
}), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, nextPath));
|
|
10217
|
-
} else if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint) && Point.equals(selectionEndPoint, endBlockEndPoint2))
|
|
10218
|
-
Transforms.insertFragment(editor, [block], {
|
|
10219
|
-
at
|
|
10220
|
-
}), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
|
|
10221
|
-
else if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint))
|
|
10222
|
-
Transforms.insertFragment(editor, [block], {
|
|
10223
|
-
at
|
|
10224
|
-
}), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
|
|
10225
|
-
else if (Range.isExpanded(at) && Point.equals(selectionEndPoint, endBlockEndPoint2))
|
|
10226
|
-
Transforms.insertFragment(editor, [block], {
|
|
10227
|
-
at
|
|
10228
|
-
}), select === "start" ? Transforms.select(editor, Editor.start(editor, Path.next(endBlockPath))) : select === "end" && Transforms.select(editor, Editor.end(editor, Path.next(endBlockPath)));
|
|
10361
|
+
editor.apply({
|
|
10362
|
+
type: "set_node",
|
|
10363
|
+
path: endBlockPath,
|
|
10364
|
+
properties,
|
|
10365
|
+
newProperties
|
|
10366
|
+
});
|
|
10367
|
+
}
|
|
10368
|
+
const adjustedBlock = isEqualChildren(block.children, adjustedChildren) ? block : {
|
|
10369
|
+
...block,
|
|
10370
|
+
children: adjustedChildren
|
|
10371
|
+
};
|
|
10372
|
+
if (select === "end") {
|
|
10373
|
+
const insertAt = editor.selection ? Range.end(editor.selection) : Editor.end(editor, endBlockPath);
|
|
10374
|
+
insertTextBlockFragment(editor, adjustedBlock, insertAt);
|
|
10375
|
+
return;
|
|
10376
|
+
}
|
|
10377
|
+
if (insertTextBlockFragment(editor, adjustedBlock, selectionStartPoint), select === "start")
|
|
10378
|
+
setSelectionToPoint(editor, selectionStartPoint);
|
|
10379
|
+
else if (select === "none")
|
|
10380
|
+
if (wasCrossBlockDeletion)
|
|
10381
|
+
setSelectionToPoint(editor, selectionStartPoint);
|
|
10229
10382
|
else {
|
|
10230
|
-
const
|
|
10231
|
-
|
|
10232
|
-
|
|
10233
|
-
|
|
10234
|
-
|
|
10235
|
-
|
|
10236
|
-
|
|
10237
|
-
|
|
10238
|
-
|
|
10239
|
-
|
|
10240
|
-
|
|
10241
|
-
|
|
10242
|
-
|
|
10243
|
-
|
|
10244
|
-
|
|
10383
|
+
const endBlockStartPoint = Editor.start(editor, endBlockPath);
|
|
10384
|
+
Point.equals(selectionStartPoint, endBlockStartPoint) || setSelectionToPoint(editor, selectionStartPoint);
|
|
10385
|
+
}
|
|
10386
|
+
} else {
|
|
10387
|
+
if (!editor.isTextBlock(endBlock)) {
|
|
10388
|
+
insertNodeAt(editor, [endBlockPath[0] + 1], block, select);
|
|
10389
|
+
return;
|
|
10390
|
+
}
|
|
10391
|
+
const endBlockStartPoint = Editor.start(editor, endBlockPath), endBlockEndPoint = Editor.end(editor, endBlockPath), selectionStartPoint = Range.start(at), selectionEndPoint = Range.end(at);
|
|
10392
|
+
if (Range.isCollapsed(at) && Point.equals(selectionStartPoint, endBlockStartPoint)) {
|
|
10393
|
+
editor.apply({
|
|
10394
|
+
type: "insert_node",
|
|
10395
|
+
path: endBlockPath,
|
|
10396
|
+
node: block
|
|
10397
|
+
}), select !== "none" && setSelection(editor, endBlockPath, "start"), isEmptyTextBlock(context, endBlock) && removeNodeAt(editor, Path.next(endBlockPath));
|
|
10398
|
+
return;
|
|
10399
|
+
}
|
|
10400
|
+
if (Range.isCollapsed(at) && Point.equals(selectionEndPoint, endBlockEndPoint)) {
|
|
10401
|
+
const nextPath = [endBlockPath[0] + 1];
|
|
10402
|
+
editor.apply({
|
|
10403
|
+
type: "insert_node",
|
|
10404
|
+
path: nextPath,
|
|
10405
|
+
node: block
|
|
10406
|
+
}), select !== "none" && setSelection(editor, nextPath, "start");
|
|
10407
|
+
return;
|
|
10408
|
+
}
|
|
10409
|
+
if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint) && Point.equals(selectionEndPoint, endBlockEndPoint)) {
|
|
10410
|
+
editor.apply({
|
|
10411
|
+
type: "insert_node",
|
|
10412
|
+
path: endBlockPath,
|
|
10413
|
+
node: block
|
|
10414
|
+
}), removeNodeAt(editor, Path.next(endBlockPath)), select !== "none" && setSelection(editor, endBlockPath, select);
|
|
10415
|
+
return;
|
|
10416
|
+
}
|
|
10417
|
+
if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint)) {
|
|
10418
|
+
const [, end2] = Range.edges(at), endNode = Node.get(editor, end2.path);
|
|
10419
|
+
end2.offset > 0 && editor.apply({
|
|
10420
|
+
type: "remove_text",
|
|
10421
|
+
path: end2.path,
|
|
10422
|
+
offset: 0,
|
|
10423
|
+
text: endNode.text.slice(0, end2.offset)
|
|
10424
|
+
});
|
|
10425
|
+
for (let i = end2.path[1] - 1; i >= 0; i--)
|
|
10426
|
+
removeNodeAt(editor, [...endBlockPath, i]);
|
|
10427
|
+
insertTextBlockFragment(editor, block, Editor.start(editor, endBlockPath)), select !== "none" && setSelection(editor, endBlockPath, select);
|
|
10428
|
+
return;
|
|
10429
|
+
}
|
|
10430
|
+
if (Range.isExpanded(at) && Point.equals(selectionEndPoint, endBlockEndPoint)) {
|
|
10431
|
+
const [start2] = Range.edges(at), blockNode = Node.get(editor, endBlockPath);
|
|
10432
|
+
for (let i = blockNode.children.length - 1; i > start2.path[1]; i--)
|
|
10433
|
+
removeNodeAt(editor, [...endBlockPath, i]);
|
|
10434
|
+
const startNode = Node.get(editor, start2.path);
|
|
10435
|
+
start2.offset < startNode.text.length && editor.apply({
|
|
10436
|
+
type: "remove_text",
|
|
10437
|
+
path: start2.path,
|
|
10438
|
+
offset: start2.offset,
|
|
10439
|
+
text: startNode.text.slice(start2.offset)
|
|
10440
|
+
}), insertTextBlockFragment(editor, block, start2), select !== "none" && setSelection(editor, Path.next(endBlockPath), select);
|
|
10441
|
+
return;
|
|
10442
|
+
}
|
|
10443
|
+
const [focusChild] = getFocusChild({
|
|
10444
|
+
editor
|
|
10445
|
+
});
|
|
10446
|
+
if (focusChild && editor.isTextSpan(focusChild)) {
|
|
10447
|
+
const startPoint = Range.start(at);
|
|
10448
|
+
if (editor.isTextBlock(block)) {
|
|
10449
|
+
const nodeToSplit = Node.get(editor, startPoint.path);
|
|
10450
|
+
if (Text.isText(nodeToSplit)) {
|
|
10451
|
+
const {
|
|
10452
|
+
text: _,
|
|
10453
|
+
...properties
|
|
10454
|
+
} = nodeToSplit;
|
|
10455
|
+
editor.apply({
|
|
10456
|
+
type: "split_node",
|
|
10457
|
+
path: startPoint.path,
|
|
10458
|
+
position: startPoint.offset,
|
|
10459
|
+
properties
|
|
10460
|
+
});
|
|
10461
|
+
}
|
|
10462
|
+
insertTextBlockFragment(editor, block, startPoint), select === "none" ? setSelectionToRange(editor, at) : setSelection(editor, [endBlockPath[0] + 1], "start");
|
|
10463
|
+
} else {
|
|
10464
|
+
let currentPath = startPoint.path, currentOffset = startPoint.offset;
|
|
10465
|
+
const cursorPositionRef = Editor.pointRef(editor, startPoint, {
|
|
10466
|
+
affinity: "backward"
|
|
10467
|
+
}), blockPath = [currentPath[0]], firstBlockPathRef = Editor.pathRef(editor, blockPath), textNode = Node.get(editor, currentPath);
|
|
10468
|
+
if (Text.isText(textNode) && currentOffset > 0 && currentOffset < textNode.text.length) {
|
|
10469
|
+
const {
|
|
10470
|
+
text: _,
|
|
10471
|
+
...properties
|
|
10472
|
+
} = textNode;
|
|
10473
|
+
editor.apply({
|
|
10474
|
+
type: "split_node",
|
|
10475
|
+
path: currentPath,
|
|
10476
|
+
position: currentOffset,
|
|
10477
|
+
properties
|
|
10478
|
+
}), currentPath = Path.next(currentPath), currentOffset = 0;
|
|
10479
|
+
}
|
|
10480
|
+
const splitAtIndex = currentOffset > 0 ? currentPath[1] + 1 : currentPath[1], blockToSplit = Node.get(editor, blockPath);
|
|
10481
|
+
if (splitAtIndex < blockToSplit.children.length && Element$1.isElement(blockToSplit)) {
|
|
10482
|
+
const {
|
|
10483
|
+
children: _,
|
|
10484
|
+
...blockProperties
|
|
10485
|
+
} = blockToSplit;
|
|
10486
|
+
editor.apply({
|
|
10487
|
+
type: "split_node",
|
|
10488
|
+
path: blockPath,
|
|
10489
|
+
position: splitAtIndex,
|
|
10490
|
+
properties: blockProperties
|
|
10491
|
+
});
|
|
10492
|
+
}
|
|
10493
|
+
const currentFirstBlockPath = firstBlockPathRef.unref(), insertPath = currentFirstBlockPath ? [currentFirstBlockPath[0] + 1] : [blockPath[0] + 1];
|
|
10494
|
+
if (editor.apply({
|
|
10495
|
+
type: "insert_node",
|
|
10496
|
+
path: insertPath,
|
|
10497
|
+
node: block
|
|
10498
|
+
}), select === "start" || select === "end") {
|
|
10499
|
+
const point = Editor.start(editor, insertPath);
|
|
10500
|
+
editor.apply({
|
|
10501
|
+
type: "set_selection",
|
|
10502
|
+
properties: editor.selection,
|
|
10503
|
+
newProperties: {
|
|
10504
|
+
anchor: point,
|
|
10505
|
+
focus: point
|
|
10506
|
+
}
|
|
10507
|
+
});
|
|
10508
|
+
} else {
|
|
10509
|
+
const point = cursorPositionRef.unref();
|
|
10510
|
+
point && editor.apply({
|
|
10511
|
+
type: "set_selection",
|
|
10512
|
+
properties: editor.selection,
|
|
10513
|
+
newProperties: {
|
|
10514
|
+
anchor: point,
|
|
10515
|
+
focus: point
|
|
10516
|
+
}
|
|
10517
|
+
});
|
|
10245
10518
|
}
|
|
10246
10519
|
}
|
|
10247
10520
|
} else {
|
|
10248
10521
|
const nextPath = [endBlockPath[0] + 1];
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10522
|
+
editor.apply({
|
|
10523
|
+
type: "insert_node",
|
|
10524
|
+
path: nextPath,
|
|
10525
|
+
node: block
|
|
10526
|
+
}), select === "none" ? setSelectionToRange(editor, at) : setSelection(editor, nextPath, select);
|
|
10527
|
+
}
|
|
10528
|
+
}
|
|
10529
|
+
}
|
|
10530
|
+
function setSelection(editor, path, position) {
|
|
10531
|
+
const point = position === "start" ? Editor.start(editor, path) : Editor.end(editor, path);
|
|
10532
|
+
editor.apply({
|
|
10533
|
+
type: "set_selection",
|
|
10534
|
+
properties: editor.selection,
|
|
10535
|
+
newProperties: {
|
|
10536
|
+
anchor: point,
|
|
10537
|
+
focus: point
|
|
10538
|
+
}
|
|
10539
|
+
});
|
|
10540
|
+
}
|
|
10541
|
+
function clearSelection(editor) {
|
|
10542
|
+
editor.selection && editor.apply({
|
|
10543
|
+
type: "set_selection",
|
|
10544
|
+
properties: editor.selection,
|
|
10545
|
+
newProperties: null
|
|
10546
|
+
});
|
|
10547
|
+
}
|
|
10548
|
+
function setSelectionToPoint(editor, point) {
|
|
10549
|
+
editor.apply({
|
|
10550
|
+
type: "set_selection",
|
|
10551
|
+
properties: editor.selection,
|
|
10552
|
+
newProperties: {
|
|
10553
|
+
anchor: point,
|
|
10554
|
+
focus: point
|
|
10555
|
+
}
|
|
10556
|
+
});
|
|
10557
|
+
}
|
|
10558
|
+
function setSelectionToRange(editor, range) {
|
|
10559
|
+
editor.apply({
|
|
10560
|
+
type: "set_selection",
|
|
10561
|
+
properties: editor.selection,
|
|
10562
|
+
newProperties: range
|
|
10563
|
+
});
|
|
10564
|
+
}
|
|
10565
|
+
function insertNodeAt(editor, path, node, select) {
|
|
10566
|
+
editor.apply({
|
|
10567
|
+
type: "insert_node",
|
|
10568
|
+
path,
|
|
10569
|
+
node
|
|
10570
|
+
}), select !== "none" && setSelection(editor, path, select);
|
|
10571
|
+
}
|
|
10572
|
+
function removeNodeAt(editor, path) {
|
|
10573
|
+
const node = Node.get(editor, path);
|
|
10574
|
+
editor.apply({
|
|
10575
|
+
type: "remove_node",
|
|
10576
|
+
path,
|
|
10577
|
+
node
|
|
10578
|
+
});
|
|
10579
|
+
}
|
|
10580
|
+
function replaceEmptyTextBlock(editor, blockPath, newBlock, select) {
|
|
10581
|
+
const hadSelection = editor.selection !== null;
|
|
10582
|
+
if (editor.apply({
|
|
10583
|
+
type: "insert_node",
|
|
10584
|
+
path: blockPath,
|
|
10585
|
+
node: newBlock
|
|
10586
|
+
}), removeNodeAt(editor, Path.next(blockPath)), select === "none" && !hadSelection)
|
|
10587
|
+
return;
|
|
10588
|
+
const point = select === "end" ? Editor.end(editor, blockPath) : Editor.start(editor, blockPath);
|
|
10589
|
+
clearSelection(editor), editor.apply({
|
|
10590
|
+
type: "set_selection",
|
|
10591
|
+
properties: null,
|
|
10592
|
+
newProperties: {
|
|
10593
|
+
anchor: point,
|
|
10594
|
+
focus: point
|
|
10595
|
+
}
|
|
10596
|
+
});
|
|
10597
|
+
}
|
|
10598
|
+
function deleteSameBlockRange(editor, start, end) {
|
|
10599
|
+
const blockPath = [start.path[0]];
|
|
10600
|
+
if (Path.equals(start.path, end.path)) {
|
|
10601
|
+
const textToRemove = Node.get(editor, start.path).text.slice(start.offset, end.offset);
|
|
10602
|
+
editor.apply({
|
|
10603
|
+
type: "remove_text",
|
|
10604
|
+
path: start.path,
|
|
10605
|
+
offset: start.offset,
|
|
10606
|
+
text: textToRemove
|
|
10607
|
+
});
|
|
10608
|
+
return;
|
|
10609
|
+
}
|
|
10610
|
+
const startNode = Node.get(editor, start.path);
|
|
10611
|
+
if (start.offset < startNode.text.length) {
|
|
10612
|
+
const textToRemove = startNode.text.slice(start.offset);
|
|
10613
|
+
editor.apply({
|
|
10614
|
+
type: "remove_text",
|
|
10615
|
+
path: start.path,
|
|
10616
|
+
offset: start.offset,
|
|
10617
|
+
text: textToRemove
|
|
10618
|
+
});
|
|
10619
|
+
}
|
|
10620
|
+
for (let i = end.path[1] - 1; i > start.path[1]; i--)
|
|
10621
|
+
removeNodeAt(editor, [...blockPath, i]);
|
|
10622
|
+
const newEndPath = [...blockPath, start.path[1] + 1], endNode = Node.get(editor, newEndPath);
|
|
10623
|
+
if (end.offset > 0) {
|
|
10624
|
+
const textToRemove = endNode.text.slice(0, end.offset);
|
|
10625
|
+
editor.apply({
|
|
10626
|
+
type: "remove_text",
|
|
10627
|
+
path: newEndPath,
|
|
10628
|
+
offset: 0,
|
|
10629
|
+
text: textToRemove
|
|
10630
|
+
});
|
|
10631
|
+
}
|
|
10632
|
+
const startNodeAfter = Node.get(editor, start.path), endNodeAfter = Node.get(editor, newEndPath);
|
|
10633
|
+
if (Text.isText(startNodeAfter) && Text.isText(endNodeAfter)) {
|
|
10634
|
+
const {
|
|
10635
|
+
text: _,
|
|
10636
|
+
...properties
|
|
10637
|
+
} = endNodeAfter;
|
|
10638
|
+
editor.apply({
|
|
10639
|
+
type: "merge_node",
|
|
10640
|
+
path: newEndPath,
|
|
10641
|
+
position: startNodeAfter.text.length,
|
|
10642
|
+
properties
|
|
10643
|
+
});
|
|
10644
|
+
}
|
|
10645
|
+
}
|
|
10646
|
+
function deleteCrossBlockRange(editor, start, end) {
|
|
10647
|
+
const startBlockPath = [start.path[0]];
|
|
10648
|
+
if (start.path.length > 1) {
|
|
10649
|
+
const startNode = Node.get(editor, start.path);
|
|
10650
|
+
if (start.offset < startNode.text.length) {
|
|
10651
|
+
const textToRemove = startNode.text.slice(start.offset);
|
|
10652
|
+
editor.apply({
|
|
10653
|
+
type: "remove_text",
|
|
10654
|
+
path: start.path,
|
|
10655
|
+
offset: start.offset,
|
|
10656
|
+
text: textToRemove
|
|
10657
|
+
});
|
|
10658
|
+
}
|
|
10659
|
+
const startBlock2 = Node.get(editor, startBlockPath);
|
|
10660
|
+
for (let i = startBlock2.children.length - 1; i > start.path[1]; i--)
|
|
10661
|
+
removeNodeAt(editor, [...startBlockPath, i]);
|
|
10662
|
+
}
|
|
10663
|
+
for (let i = end.path[0] - 1; i > start.path[0]; i--)
|
|
10664
|
+
removeNodeAt(editor, [i]);
|
|
10665
|
+
const adjustedEndBlockPath = [start.path[0] + 1];
|
|
10666
|
+
if (end.path.length > 1) {
|
|
10667
|
+
for (let i = 0; i < end.path[1]; i++)
|
|
10668
|
+
removeNodeAt(editor, [...adjustedEndBlockPath, 0]);
|
|
10669
|
+
const endNodePath = [...adjustedEndBlockPath, 0], endNode = Node.get(editor, endNodePath);
|
|
10670
|
+
if (end.offset > 0) {
|
|
10671
|
+
const textToRemove = endNode.text.slice(0, end.offset);
|
|
10672
|
+
editor.apply({
|
|
10673
|
+
type: "remove_text",
|
|
10674
|
+
path: endNodePath,
|
|
10675
|
+
offset: 0,
|
|
10676
|
+
text: textToRemove
|
|
10677
|
+
});
|
|
10678
|
+
}
|
|
10679
|
+
}
|
|
10680
|
+
const startBlock = Node.get(editor, startBlockPath), endBlock = Node.get(editor, adjustedEndBlockPath);
|
|
10681
|
+
if (editor.isTextBlock(startBlock) && editor.isTextBlock(endBlock)) {
|
|
10682
|
+
const {
|
|
10683
|
+
children: _,
|
|
10684
|
+
...properties
|
|
10685
|
+
} = endBlock;
|
|
10686
|
+
editor.apply({
|
|
10687
|
+
type: "merge_node",
|
|
10688
|
+
path: adjustedEndBlockPath,
|
|
10689
|
+
position: startBlock.children.length,
|
|
10690
|
+
properties
|
|
10691
|
+
});
|
|
10692
|
+
}
|
|
10693
|
+
}
|
|
10694
|
+
function deleteExpandedRange(editor, range) {
|
|
10695
|
+
const [start, end] = Range.edges(range);
|
|
10696
|
+
start.path[0] === end.path[0] ? deleteSameBlockRange(editor, start, end) : deleteCrossBlockRange(editor, start, end);
|
|
10697
|
+
}
|
|
10698
|
+
function insertTextBlockFragment(editor, block, at) {
|
|
10699
|
+
if (!Element$1.isElement(block) || !editor.isTextBlock(block))
|
|
10700
|
+
return;
|
|
10701
|
+
if (at.offset > 0) {
|
|
10702
|
+
const textNode = Node.get(editor, at.path);
|
|
10703
|
+
if (Text.isText(textNode)) {
|
|
10704
|
+
const {
|
|
10705
|
+
text: _,
|
|
10706
|
+
...properties
|
|
10707
|
+
} = textNode;
|
|
10708
|
+
editor.apply({
|
|
10709
|
+
type: "split_node",
|
|
10710
|
+
path: at.path,
|
|
10711
|
+
position: at.offset,
|
|
10712
|
+
properties
|
|
10713
|
+
});
|
|
10253
10714
|
}
|
|
10254
10715
|
}
|
|
10716
|
+
const parentPath = Path.parent(at.path);
|
|
10717
|
+
let insertIndex = at.path[at.path.length - 1] + (at.offset > 0 ? 1 : 0);
|
|
10718
|
+
for (const child of block.children) {
|
|
10719
|
+
const childPath = [...parentPath, insertIndex];
|
|
10720
|
+
editor.apply({
|
|
10721
|
+
type: "insert_node",
|
|
10722
|
+
path: childPath,
|
|
10723
|
+
node: child
|
|
10724
|
+
}), insertIndex++;
|
|
10725
|
+
}
|
|
10255
10726
|
}
|
|
10256
10727
|
const insertChildOperationImplementation = ({
|
|
10257
10728
|
context,
|
|
@@ -10585,9 +11056,10 @@ function performEvent({
|
|
|
10585
11056
|
forwardFromBehaviors,
|
|
10586
11057
|
event,
|
|
10587
11058
|
editor,
|
|
11059
|
+
converters,
|
|
10588
11060
|
keyGenerator,
|
|
11061
|
+
readOnly,
|
|
10589
11062
|
schema,
|
|
10590
|
-
getSnapshot,
|
|
10591
11063
|
nativeEvent,
|
|
10592
11064
|
sendBack
|
|
10593
11065
|
}) {
|
|
@@ -10605,10 +11077,16 @@ function performEvent({
|
|
|
10605
11077
|
editor
|
|
10606
11078
|
}
|
|
10607
11079
|
});
|
|
10608
|
-
}), editor.onChange();
|
|
11080
|
+
}), mode === "send" && editor.onChange();
|
|
10609
11081
|
return;
|
|
10610
11082
|
}
|
|
10611
|
-
const guardSnapshot =
|
|
11083
|
+
const guardSnapshot = createEditorSnapshot({
|
|
11084
|
+
converters,
|
|
11085
|
+
editor,
|
|
11086
|
+
keyGenerator,
|
|
11087
|
+
readOnly,
|
|
11088
|
+
schema
|
|
11089
|
+
});
|
|
10612
11090
|
let nativeEventPrevented = !1, defaultBehaviorOverwritten = !1, eventBehaviorIndex = -1;
|
|
10613
11091
|
for (const eventBehavior of eventBehaviors) {
|
|
10614
11092
|
eventBehaviorIndex++;
|
|
@@ -10628,7 +11106,13 @@ function performEvent({
|
|
|
10628
11106
|
let actionSetIndex = -1;
|
|
10629
11107
|
for (const actionSet of eventBehavior.actions) {
|
|
10630
11108
|
actionSetIndex++;
|
|
10631
|
-
const actionsSnapshot =
|
|
11109
|
+
const actionsSnapshot = createEditorSnapshot({
|
|
11110
|
+
converters,
|
|
11111
|
+
editor,
|
|
11112
|
+
keyGenerator,
|
|
11113
|
+
readOnly,
|
|
11114
|
+
schema
|
|
11115
|
+
});
|
|
10632
11116
|
let actions = [];
|
|
10633
11117
|
try {
|
|
10634
11118
|
actions = actionSet({
|
|
@@ -10666,9 +11150,10 @@ function performEvent({
|
|
|
10666
11150
|
forwardFromBehaviors: remainingBehaviors,
|
|
10667
11151
|
event: action.event,
|
|
10668
11152
|
editor,
|
|
11153
|
+
converters,
|
|
10669
11154
|
keyGenerator,
|
|
11155
|
+
readOnly,
|
|
10670
11156
|
schema,
|
|
10671
|
-
getSnapshot,
|
|
10672
11157
|
nativeEvent,
|
|
10673
11158
|
sendBack
|
|
10674
11159
|
});
|
|
@@ -10681,9 +11166,10 @@ function performEvent({
|
|
|
10681
11166
|
abstractBehaviorIndex,
|
|
10682
11167
|
event: action.event,
|
|
10683
11168
|
editor,
|
|
11169
|
+
converters,
|
|
10684
11170
|
keyGenerator,
|
|
11171
|
+
readOnly,
|
|
10685
11172
|
schema,
|
|
10686
|
-
getSnapshot,
|
|
10687
11173
|
nativeEvent,
|
|
10688
11174
|
sendBack
|
|
10689
11175
|
});
|
|
@@ -10695,9 +11181,10 @@ function performEvent({
|
|
|
10695
11181
|
abstractBehaviorIndex,
|
|
10696
11182
|
event: action.event,
|
|
10697
11183
|
editor,
|
|
11184
|
+
converters,
|
|
10698
11185
|
keyGenerator,
|
|
11186
|
+
readOnly,
|
|
10699
11187
|
schema,
|
|
10700
|
-
getSnapshot,
|
|
10701
11188
|
nativeEvent: void 0,
|
|
10702
11189
|
sendBack
|
|
10703
11190
|
});
|
|
@@ -10717,7 +11204,7 @@ function performEvent({
|
|
|
10717
11204
|
editor
|
|
10718
11205
|
}
|
|
10719
11206
|
});
|
|
10720
|
-
}), editor.onChange()) : nativeEventPrevented && nativeEvent?.preventDefault();
|
|
11207
|
+
}), mode === "send" && editor.onChange()) : nativeEventPrevented && (nativeEvent?.preventDefault(), mode === "send" && editor.onChange());
|
|
10721
11208
|
}
|
|
10722
11209
|
function sortByPriority(items) {
|
|
10723
11210
|
if (items.length === 0)
|
|
@@ -10762,31 +11249,6 @@ function sortByPriority(items) {
|
|
|
10762
11249
|
result.includes(item) || result.push(item);
|
|
10763
11250
|
return [...result, ...itemsWithoutPriority];
|
|
10764
11251
|
}
|
|
10765
|
-
function createEditorSnapshot({
|
|
10766
|
-
converters,
|
|
10767
|
-
editor,
|
|
10768
|
-
keyGenerator,
|
|
10769
|
-
readOnly,
|
|
10770
|
-
schema
|
|
10771
|
-
}) {
|
|
10772
|
-
const selection = editor.selection ? slateRangeToSelection({
|
|
10773
|
-
schema,
|
|
10774
|
-
editor,
|
|
10775
|
-
range: editor.selection
|
|
10776
|
-
}) : null, context = {
|
|
10777
|
-
converters,
|
|
10778
|
-
keyGenerator,
|
|
10779
|
-
readOnly,
|
|
10780
|
-
schema,
|
|
10781
|
-
selection,
|
|
10782
|
-
value: editor.value
|
|
10783
|
-
};
|
|
10784
|
-
return {
|
|
10785
|
-
blockIndexMap: editor.blockIndexMap,
|
|
10786
|
-
context,
|
|
10787
|
-
decoratorState: editor.decoratorState
|
|
10788
|
-
};
|
|
10789
|
-
}
|
|
10790
11252
|
function rerouteExternalBehaviorEvent({
|
|
10791
11253
|
event,
|
|
10792
11254
|
slateEditor
|
|
@@ -10937,16 +11399,11 @@ const editorMachine = setup({
|
|
|
10937
11399
|
abstractBehaviorIndex: context.abstractBehaviorIndex,
|
|
10938
11400
|
event: event.behaviorEvent,
|
|
10939
11401
|
editor: event.editor,
|
|
11402
|
+
converters: [...context.converters],
|
|
10940
11403
|
keyGenerator: context.keyGenerator,
|
|
10941
11404
|
schema: context.schema,
|
|
10942
|
-
|
|
10943
|
-
|
|
10944
|
-
editor: event.editor,
|
|
10945
|
-
keyGenerator: context.keyGenerator,
|
|
10946
|
-
readOnly: self.getSnapshot().matches({
|
|
10947
|
-
"edit mode": "read only"
|
|
10948
|
-
}),
|
|
10949
|
-
schema: context.schema
|
|
11405
|
+
readOnly: self.getSnapshot().matches({
|
|
11406
|
+
"edit mode": "read only"
|
|
10950
11407
|
}),
|
|
10951
11408
|
nativeEvent: event.nativeEvent,
|
|
10952
11409
|
sendBack: (eventSentBack) => {
|
|
@@ -13260,12 +13717,12 @@ const usePortableTextEditorSelection = () => {
|
|
|
13260
13717
|
const $ = c(5), editorActor = useContext(EditorActorContext);
|
|
13261
13718
|
let t0;
|
|
13262
13719
|
$[0] !== editorActor ? (t0 = editorActor.getSnapshot(), $[0] = editorActor, $[1] = t0) : t0 = $[1];
|
|
13263
|
-
const [selection,
|
|
13720
|
+
const [selection, setSelection2] = useState(t0.context.selection);
|
|
13264
13721
|
let t1, t2;
|
|
13265
13722
|
return $[2] !== editorActor ? (t1 = () => {
|
|
13266
13723
|
const subscription = editorActor.on("selection", (event) => {
|
|
13267
13724
|
startTransition(() => {
|
|
13268
|
-
|
|
13725
|
+
setSelection2(event.selection);
|
|
13269
13726
|
});
|
|
13270
13727
|
});
|
|
13271
13728
|
return () => {
|