@portabletext/editor 4.1.4 → 4.2.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-dts/behavior.types.action.d.ts +1 -0
- package/lib/_chunks-es/{selector.is-at-the-start-of-block.js → selector.is-selecting-entire-blocks.js} +243 -245
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -0
- package/lib/index.js +233 -244
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.js +2 -2
- package/package.json +3 -3
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
|
|
|
11
11
|
import { defineSchema } from "@portabletext/schema";
|
|
12
12
|
import { isEmptyTextBlock, sliceTextBlock, getTextBlockText } from "./_chunks-es/util.slice-text-block.js";
|
|
13
13
|
import { setup, fromCallback, assign, and, enqueueActions, emit, assertEvent, raise as raise$1, not, createActor } from "xstate";
|
|
14
|
-
import { isSelectionCollapsed as isSelectionCollapsed$1,
|
|
14
|
+
import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusChild as getFocusChild$1, getSelectedChildren, getSelectionStartPoint, getSelectionEndPoint, getFocusInlineObject, getFocusTextBlock, getFocusSpan as getFocusSpan$1, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection, getFocusBlock as getFocusBlock$1, isSelectingEntireBlocks, getSelectedValue, isActiveAnnotation, getActiveAnnotationsMarks, getActiveDecorators, getSelectionStartChild, getSelectionEndChild, getPreviousSpan, getNextSpan, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getMarkState, isAtTheEndOfBlock, isAtTheStartOfBlock, getFocusListBlock, isActiveDecorator, getActiveAnnotations, getLastBlock as getLastBlock$1, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
15
15
|
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
16
16
|
import { compileSchemaDefinitionToPortableTextMemberSchemaTypes, createPortableTextMemberSchemaTypes, portableTextMemberSchemaTypesToSchema } from "@portabletext/sanity-bridge";
|
|
17
17
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
@@ -1214,7 +1214,7 @@ function SelectionStateProvider(t0) {
|
|
|
1214
1214
|
return defaultSelectionState;
|
|
1215
1215
|
const isCollapsed = isSelectionCollapsed$1(snapshot);
|
|
1216
1216
|
let focusedChildKey;
|
|
1217
|
-
isCollapsed && (focusedChildKey =
|
|
1217
|
+
isCollapsed && (focusedChildKey = getFocusChild$1(snapshot)?.node._key);
|
|
1218
1218
|
const selectedChildren = getSelectedChildren()(snapshot);
|
|
1219
1219
|
let selectedChildKeys = selectedChildren.length > 0 ? new Set(selectedChildren.map(_temp$4)) : emptySet;
|
|
1220
1220
|
isCollapsed && focusedChildKey && !selectedChildKeys.has(focusedChildKey) && (selectedChildKeys = new Set(selectedChildKeys), selectedChildKeys.add(focusedChildKey));
|
|
@@ -8477,11 +8477,11 @@ function insertBlock(options) {
|
|
|
8477
8477
|
}
|
|
8478
8478
|
}
|
|
8479
8479
|
} else {
|
|
8480
|
-
Transforms.insertNodes(editor, [block], {
|
|
8481
|
-
select: !1
|
|
8482
|
-
});
|
|
8483
8480
|
const nextPath = [endBlockPath[0] + 1];
|
|
8484
|
-
|
|
8481
|
+
Transforms.insertNodes(editor, [block], {
|
|
8482
|
+
select: !1,
|
|
8483
|
+
at: nextPath
|
|
8484
|
+
}), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
8485
8485
|
}
|
|
8486
8486
|
}
|
|
8487
8487
|
}
|
|
@@ -9349,104 +9349,70 @@ const abstractInsertBehaviors = [
|
|
|
9349
9349
|
type: "insert.block",
|
|
9350
9350
|
block: onlyBlock,
|
|
9351
9351
|
placement: event.placement,
|
|
9352
|
-
select: event.select ?? "end"
|
|
9352
|
+
select: event.select ?? "end",
|
|
9353
|
+
...event.at ? {
|
|
9354
|
+
at: event.at
|
|
9355
|
+
} : {}
|
|
9353
9356
|
})]]
|
|
9354
9357
|
}),
|
|
9355
9358
|
defineBehavior({
|
|
9356
9359
|
on: "insert.blocks",
|
|
9357
9360
|
guard: ({
|
|
9358
|
-
snapshot,
|
|
9359
9361
|
event
|
|
9360
|
-
}) =>
|
|
9361
|
-
if (event.placement !== "before")
|
|
9362
|
-
return !1;
|
|
9363
|
-
const firstBlockKey = getUniqueBlockKey(event.blocks.at(0)?._key)(snapshot), lastBlockKey = getUniqueBlockKey(event.blocks.at(-1)?._key)(snapshot);
|
|
9364
|
-
return {
|
|
9365
|
-
firstBlockKey,
|
|
9366
|
-
lastBlockKey
|
|
9367
|
-
};
|
|
9368
|
-
},
|
|
9362
|
+
}) => event.placement === "before" || event.placement === "after",
|
|
9369
9363
|
actions: [({
|
|
9370
9364
|
snapshot,
|
|
9371
9365
|
event
|
|
9372
|
-
}, {
|
|
9373
|
-
firstBlockKey,
|
|
9374
|
-
lastBlockKey
|
|
9375
|
-
}) => [...event.blocks.map((block, index) => raise({
|
|
9376
|
-
type: "insert.block",
|
|
9377
|
-
block: index === 0 ? {
|
|
9378
|
-
...block,
|
|
9379
|
-
_key: firstBlockKey
|
|
9380
|
-
} : index === event.blocks.length - 1 ? {
|
|
9381
|
-
...block,
|
|
9382
|
-
_key: lastBlockKey
|
|
9383
|
-
} : block,
|
|
9384
|
-
placement: index === 0 ? "before" : "after",
|
|
9385
|
-
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
9386
|
-
})), ...event.select === "none" ? [raise({
|
|
9387
|
-
type: "select",
|
|
9388
|
-
at: snapshot.context.selection
|
|
9389
|
-
})] : event.select === "start" ? [raise({
|
|
9390
|
-
type: "select.block",
|
|
9391
|
-
at: [{
|
|
9392
|
-
_key: firstBlockKey
|
|
9393
|
-
}],
|
|
9394
|
-
select: "start"
|
|
9395
|
-
})] : [raise({
|
|
9396
|
-
type: "select.block",
|
|
9397
|
-
at: [{
|
|
9398
|
-
_key: lastBlockKey
|
|
9399
|
-
}],
|
|
9400
|
-
select: "end"
|
|
9401
|
-
})]]]
|
|
9402
|
-
}),
|
|
9403
|
-
defineBehavior({
|
|
9404
|
-
on: "insert.blocks",
|
|
9405
|
-
guard: ({
|
|
9406
|
-
snapshot,
|
|
9407
|
-
event
|
|
9408
9366
|
}) => {
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9367
|
+
let firstBlockKey, lastBlockKey, previousBlockKey;
|
|
9368
|
+
const actions = [];
|
|
9369
|
+
let index = -1;
|
|
9370
|
+
for (const block of event.blocks) {
|
|
9371
|
+
index++;
|
|
9372
|
+
const key = getUniqueBlockKey(block._key)(snapshot);
|
|
9373
|
+
index === 0 && (firstBlockKey = key), index === event.blocks.length - 1 && (lastBlockKey = key), actions.push(raise({
|
|
9374
|
+
type: "insert.block",
|
|
9375
|
+
block: key !== block._key ? {
|
|
9376
|
+
...block,
|
|
9377
|
+
_key: key
|
|
9378
|
+
} : block,
|
|
9379
|
+
placement: event.placement === "after" ? "after" : index === 0 ? "before" : "after",
|
|
9380
|
+
select: "none",
|
|
9381
|
+
...previousBlockKey ? {
|
|
9382
|
+
at: {
|
|
9383
|
+
anchor: {
|
|
9384
|
+
path: [{
|
|
9385
|
+
_key: previousBlockKey
|
|
9386
|
+
}],
|
|
9387
|
+
offset: 0
|
|
9388
|
+
},
|
|
9389
|
+
focus: {
|
|
9390
|
+
path: [{
|
|
9391
|
+
_key: previousBlockKey
|
|
9392
|
+
}],
|
|
9393
|
+
offset: 0
|
|
9394
|
+
}
|
|
9395
|
+
}
|
|
9396
|
+
} : event.at ? {
|
|
9397
|
+
at: event.at
|
|
9398
|
+
} : {}
|
|
9399
|
+
})), previousBlockKey = key;
|
|
9400
|
+
}
|
|
9401
|
+
const select = event.select ?? "end";
|
|
9402
|
+
return select === "start" && firstBlockKey && actions.push(raise({
|
|
9403
|
+
type: "select.block",
|
|
9404
|
+
at: [{
|
|
9405
|
+
_key: firstBlockKey
|
|
9406
|
+
}],
|
|
9407
|
+
select: "start"
|
|
9408
|
+
})), select === "end" && lastBlockKey && actions.push(raise({
|
|
9409
|
+
type: "select.block",
|
|
9410
|
+
at: [{
|
|
9411
|
+
_key: lastBlockKey
|
|
9412
|
+
}],
|
|
9413
|
+
select: "end"
|
|
9414
|
+
})), actions;
|
|
9415
|
+
}]
|
|
9450
9416
|
}),
|
|
9451
9417
|
defineBehavior({
|
|
9452
9418
|
on: "insert.blocks",
|
|
@@ -9456,62 +9422,17 @@ const abstractInsertBehaviors = [
|
|
|
9456
9422
|
}) => {
|
|
9457
9423
|
if (event.placement !== "auto")
|
|
9458
9424
|
return !1;
|
|
9459
|
-
const
|
|
9460
|
-
if (!
|
|
9425
|
+
const at = event.at ?? snapshot.context.selection;
|
|
9426
|
+
if (!at)
|
|
9461
9427
|
return !1;
|
|
9462
|
-
const
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
event
|
|
9471
|
-
}, {
|
|
9472
|
-
firstBlockKey,
|
|
9473
|
-
lastBlockKey
|
|
9474
|
-
}) => [...event.blocks.map((block, index) => raise({
|
|
9475
|
-
type: "insert.block",
|
|
9476
|
-
block: index === 0 ? {
|
|
9477
|
-
...block,
|
|
9478
|
-
_key: firstBlockKey
|
|
9479
|
-
} : index === event.blocks.length - 1 ? {
|
|
9480
|
-
...block,
|
|
9481
|
-
_key: lastBlockKey
|
|
9482
|
-
} : block,
|
|
9483
|
-
placement: index === 0 ? "auto" : "after",
|
|
9484
|
-
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
9485
|
-
})), ...event.select === "none" ? [raise({
|
|
9486
|
-
type: "select.block",
|
|
9487
|
-
at: [{
|
|
9488
|
-
_key: firstBlockKey
|
|
9489
|
-
}],
|
|
9490
|
-
select: "start"
|
|
9491
|
-
})] : event.select === "start" ? [raise({
|
|
9492
|
-
type: "select.block",
|
|
9493
|
-
at: [{
|
|
9494
|
-
_key: firstBlockKey
|
|
9495
|
-
}],
|
|
9496
|
-
select: "start"
|
|
9497
|
-
})] : [raise({
|
|
9498
|
-
type: "select.block",
|
|
9499
|
-
at: [{
|
|
9500
|
-
_key: lastBlockKey
|
|
9501
|
-
}],
|
|
9502
|
-
select: "end"
|
|
9503
|
-
})]]]
|
|
9504
|
-
}),
|
|
9505
|
-
defineBehavior({
|
|
9506
|
-
on: "insert.blocks",
|
|
9507
|
-
guard: ({
|
|
9508
|
-
snapshot,
|
|
9509
|
-
event
|
|
9510
|
-
}) => {
|
|
9511
|
-
if (event.placement !== "auto")
|
|
9512
|
-
return !1;
|
|
9513
|
-
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
9514
|
-
if (!focusTextBlock || !snapshot.context.selection)
|
|
9428
|
+
const adjustedSnapshot = {
|
|
9429
|
+
...snapshot,
|
|
9430
|
+
context: {
|
|
9431
|
+
...snapshot.context,
|
|
9432
|
+
selection: at
|
|
9433
|
+
}
|
|
9434
|
+
}, focusTextBlock = getFocusTextBlock(adjustedSnapshot);
|
|
9435
|
+
if (!focusTextBlock || isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
9515
9436
|
return !1;
|
|
9516
9437
|
const focusBlockStartPoint = getBlockStartPoint({
|
|
9517
9438
|
context: snapshot.context,
|
|
@@ -9523,19 +9444,19 @@ const abstractInsertBehaviors = [
|
|
|
9523
9444
|
context: {
|
|
9524
9445
|
schema: snapshot.context.schema,
|
|
9525
9446
|
selection: {
|
|
9526
|
-
anchor:
|
|
9447
|
+
anchor: at.focus,
|
|
9527
9448
|
focus: focusBlockEndPoint
|
|
9528
9449
|
}
|
|
9529
9450
|
},
|
|
9530
9451
|
block: focusTextBlock.node
|
|
9531
|
-
}),
|
|
9452
|
+
}), isFirstBlockTextBlock = isTextBlock(snapshot.context, event.blocks.at(0));
|
|
9532
9453
|
return {
|
|
9533
|
-
|
|
9534
|
-
lastBlockKey,
|
|
9454
|
+
focusTextBlock,
|
|
9535
9455
|
focusBlockStartPoint,
|
|
9536
9456
|
focusBlockEndPoint,
|
|
9537
9457
|
focusTextBlockAfter,
|
|
9538
|
-
|
|
9458
|
+
at,
|
|
9459
|
+
originalSelection: snapshot.context.selection,
|
|
9539
9460
|
isFirstBlockTextBlock
|
|
9540
9461
|
};
|
|
9541
9462
|
},
|
|
@@ -9543,110 +9464,178 @@ const abstractInsertBehaviors = [
|
|
|
9543
9464
|
snapshot,
|
|
9544
9465
|
event
|
|
9545
9466
|
}, {
|
|
9467
|
+
focusTextBlock,
|
|
9546
9468
|
focusBlockEndPoint,
|
|
9547
9469
|
focusTextBlockAfter,
|
|
9548
|
-
|
|
9549
|
-
firstBlockKey,
|
|
9550
|
-
lastBlockKey,
|
|
9470
|
+
at,
|
|
9551
9471
|
focusBlockStartPoint,
|
|
9552
|
-
isFirstBlockTextBlock
|
|
9553
|
-
|
|
9554
|
-
|
|
9555
|
-
|
|
9556
|
-
|
|
9557
|
-
|
|
9558
|
-
|
|
9559
|
-
|
|
9560
|
-
|
|
9561
|
-
|
|
9562
|
-
|
|
9563
|
-
|
|
9564
|
-
|
|
9565
|
-
|
|
9566
|
-
|
|
9567
|
-
|
|
9568
|
-
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
|
|
9581
|
-
|
|
9582
|
-
|
|
9583
|
-
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9472
|
+
isFirstBlockTextBlock,
|
|
9473
|
+
originalSelection
|
|
9474
|
+
}) => {
|
|
9475
|
+
let previousBlockKey, firstBlockKey;
|
|
9476
|
+
const actions = [];
|
|
9477
|
+
let index = -1;
|
|
9478
|
+
for (const block of event.blocks) {
|
|
9479
|
+
if (index++, index === 0) {
|
|
9480
|
+
isEqualSelectionPoints(at.focus, focusBlockEndPoint) || actions.push(raise({
|
|
9481
|
+
type: "delete",
|
|
9482
|
+
at: {
|
|
9483
|
+
anchor: at.focus,
|
|
9484
|
+
focus: focusBlockEndPoint
|
|
9485
|
+
}
|
|
9486
|
+
}));
|
|
9487
|
+
const key2 = getUniqueBlockKey(block._key)(snapshot), deletingEndToEnd = isEqualSelectionPoints(at.focus, focusBlockStartPoint);
|
|
9488
|
+
isTextBlock(snapshot.context, block) && !deletingEndToEnd ? (firstBlockKey = focusTextBlock.node._key, previousBlockKey = focusTextBlock.node._key) : (firstBlockKey = key2, previousBlockKey = key2), actions.push(raise({
|
|
9489
|
+
type: "insert.block",
|
|
9490
|
+
block: key2 !== block._key ? {
|
|
9491
|
+
...block,
|
|
9492
|
+
_key: key2
|
|
9493
|
+
} : block,
|
|
9494
|
+
placement: "auto",
|
|
9495
|
+
select: "end",
|
|
9496
|
+
...event.at ? {
|
|
9497
|
+
at: event.at
|
|
9498
|
+
} : {}
|
|
9499
|
+
}));
|
|
9500
|
+
continue;
|
|
9501
|
+
}
|
|
9502
|
+
if (index === event.blocks.length - 1) {
|
|
9503
|
+
actions.push(raise({
|
|
9504
|
+
type: "insert.block",
|
|
9505
|
+
block,
|
|
9506
|
+
placement: "after",
|
|
9507
|
+
select: "end",
|
|
9508
|
+
at: previousBlockKey ? {
|
|
9509
|
+
anchor: {
|
|
9510
|
+
path: [{
|
|
9511
|
+
_key: previousBlockKey
|
|
9512
|
+
}],
|
|
9513
|
+
offset: 0
|
|
9514
|
+
},
|
|
9515
|
+
focus: {
|
|
9516
|
+
path: [{
|
|
9517
|
+
_key: previousBlockKey
|
|
9518
|
+
}],
|
|
9519
|
+
offset: 0
|
|
9520
|
+
}
|
|
9521
|
+
} : void 0
|
|
9522
|
+
}));
|
|
9523
|
+
continue;
|
|
9524
|
+
}
|
|
9525
|
+
const key = getUniqueBlockKey(block._key)(snapshot);
|
|
9526
|
+
actions.push(raise({
|
|
9527
|
+
type: "insert.block",
|
|
9528
|
+
block: key !== block._key ? {
|
|
9529
|
+
...block,
|
|
9530
|
+
_key: key
|
|
9531
|
+
} : block,
|
|
9532
|
+
placement: "after",
|
|
9533
|
+
select: previousBlockKey ? "none" : "end",
|
|
9534
|
+
at: previousBlockKey ? {
|
|
9535
|
+
anchor: {
|
|
9536
|
+
path: [{
|
|
9537
|
+
_key: previousBlockKey
|
|
9538
|
+
}],
|
|
9539
|
+
offset: 0
|
|
9540
|
+
},
|
|
9541
|
+
focus: {
|
|
9542
|
+
path: [{
|
|
9543
|
+
_key: previousBlockKey
|
|
9544
|
+
}],
|
|
9545
|
+
offset: 0
|
|
9546
|
+
}
|
|
9547
|
+
} : void 0
|
|
9548
|
+
})), previousBlockKey = key;
|
|
9599
9549
|
}
|
|
9600
|
-
|
|
9550
|
+
return isEmptyTextBlock(snapshot.context, focusTextBlockAfter) || actions.push(raise({
|
|
9551
|
+
type: "insert.block",
|
|
9552
|
+
block: focusTextBlockAfter,
|
|
9553
|
+
placement: "auto",
|
|
9554
|
+
select: event.select === "end" ? "none" : "end"
|
|
9555
|
+
})), event.select === "none" && actions.push(raise({
|
|
9556
|
+
type: "select",
|
|
9557
|
+
at: originalSelection
|
|
9558
|
+
})), event.select === "start" && ((isEqualSelectionPoints(at.focus, focusBlockStartPoint) || !isFirstBlockTextBlock) && firstBlockKey ? actions.push(raise({
|
|
9559
|
+
type: "select.block",
|
|
9560
|
+
at: [{
|
|
9561
|
+
_key: firstBlockKey
|
|
9562
|
+
}],
|
|
9563
|
+
select: "start"
|
|
9564
|
+
})) : actions.push(raise({
|
|
9565
|
+
type: "select",
|
|
9566
|
+
at: {
|
|
9567
|
+
anchor: at.focus,
|
|
9568
|
+
focus: at.focus
|
|
9569
|
+
}
|
|
9570
|
+
}))), actions;
|
|
9571
|
+
}]
|
|
9601
9572
|
}),
|
|
9602
9573
|
defineBehavior({
|
|
9603
9574
|
on: "insert.blocks",
|
|
9604
9575
|
guard: ({
|
|
9605
9576
|
snapshot,
|
|
9606
9577
|
event
|
|
9607
|
-
}) => {
|
|
9608
|
-
|
|
9609
|
-
return !1;
|
|
9610
|
-
const selection = snapshot.context.selection, firstBlockKey = getUniqueBlockKey(event.blocks.at(0)?._key)(snapshot), lastBlockKey = getUniqueBlockKey(event.blocks.at(-1)?._key)(snapshot);
|
|
9611
|
-
return {
|
|
9612
|
-
firstBlockKey,
|
|
9613
|
-
lastBlockKey,
|
|
9614
|
-
selection
|
|
9615
|
-
};
|
|
9578
|
+
}) => event.placement !== "auto" ? !1 : {
|
|
9579
|
+
originalSelection: snapshot.context.selection
|
|
9616
9580
|
},
|
|
9617
9581
|
actions: [({
|
|
9582
|
+
snapshot,
|
|
9618
9583
|
event
|
|
9619
9584
|
}, {
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
|
|
9626
|
-
|
|
9627
|
-
_key
|
|
9628
|
-
|
|
9629
|
-
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
9635
|
-
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
|
|
9639
|
-
|
|
9640
|
-
|
|
9641
|
-
|
|
9642
|
-
|
|
9643
|
-
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
|
|
9648
|
-
|
|
9649
|
-
|
|
9585
|
+
originalSelection
|
|
9586
|
+
}) => {
|
|
9587
|
+
let firstBlockKey, lastBlockKey, previousBlockKey;
|
|
9588
|
+
const actions = [];
|
|
9589
|
+
let index = -1;
|
|
9590
|
+
for (const block of event.blocks) {
|
|
9591
|
+
index++;
|
|
9592
|
+
const key = getUniqueBlockKey(block._key)(snapshot);
|
|
9593
|
+
index === 0 && (firstBlockKey = key), index === event.blocks.length - 1 && (lastBlockKey = key), actions.push(raise({
|
|
9594
|
+
type: "insert.block",
|
|
9595
|
+
block: key !== block._key ? {
|
|
9596
|
+
...block,
|
|
9597
|
+
_key: key
|
|
9598
|
+
} : block,
|
|
9599
|
+
placement: index === 0 ? "auto" : "after",
|
|
9600
|
+
select: "none",
|
|
9601
|
+
...previousBlockKey ? {
|
|
9602
|
+
at: {
|
|
9603
|
+
anchor: {
|
|
9604
|
+
path: [{
|
|
9605
|
+
_key: previousBlockKey
|
|
9606
|
+
}],
|
|
9607
|
+
offset: 0
|
|
9608
|
+
},
|
|
9609
|
+
focus: {
|
|
9610
|
+
path: [{
|
|
9611
|
+
_key: previousBlockKey
|
|
9612
|
+
}],
|
|
9613
|
+
offset: 0
|
|
9614
|
+
}
|
|
9615
|
+
}
|
|
9616
|
+
} : event.at ? {
|
|
9617
|
+
at: event.at
|
|
9618
|
+
} : {}
|
|
9619
|
+
})), previousBlockKey = key;
|
|
9620
|
+
}
|
|
9621
|
+
const select = event.select ?? "end";
|
|
9622
|
+
return select === "none" ? actions.push(raise({
|
|
9623
|
+
type: "select",
|
|
9624
|
+
at: originalSelection
|
|
9625
|
+
})) : select === "start" && firstBlockKey ? actions.push(raise({
|
|
9626
|
+
type: "select.block",
|
|
9627
|
+
at: [{
|
|
9628
|
+
_key: firstBlockKey
|
|
9629
|
+
}],
|
|
9630
|
+
select: "start"
|
|
9631
|
+
})) : lastBlockKey && actions.push(raise({
|
|
9632
|
+
type: "select.block",
|
|
9633
|
+
at: [{
|
|
9634
|
+
_key: lastBlockKey
|
|
9635
|
+
}],
|
|
9636
|
+
select: "end"
|
|
9637
|
+
})), actions;
|
|
9638
|
+
}]
|
|
9650
9639
|
}),
|
|
9651
9640
|
defineBehavior({
|
|
9652
9641
|
on: "insert.break",
|