@portabletext/editor 4.0.2 → 4.0.3
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/index.js +96 -22
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -9289,7 +9289,11 @@ const abstractDeserializeBehaviors = [
|
|
|
9289
9289
|
originEvent: event
|
|
9290
9290
|
})]]
|
|
9291
9291
|
})
|
|
9292
|
-
]
|
|
9292
|
+
];
|
|
9293
|
+
function getUniqueBlockKey(blockKey) {
|
|
9294
|
+
return (snapshot) => !blockKey || snapshot.blockIndexMap.has(blockKey) ? snapshot.context.keyGenerator() : blockKey;
|
|
9295
|
+
}
|
|
9296
|
+
const abstractInsertBehaviors = [
|
|
9293
9297
|
defineBehavior({
|
|
9294
9298
|
on: "insert.blocks",
|
|
9295
9299
|
guard: ({
|
|
@@ -9319,7 +9323,7 @@ const abstractDeserializeBehaviors = [
|
|
|
9319
9323
|
}) => {
|
|
9320
9324
|
if (event.placement !== "before")
|
|
9321
9325
|
return !1;
|
|
9322
|
-
const firstBlockKey = event.blocks.at(0)?._key
|
|
9326
|
+
const firstBlockKey = getUniqueBlockKey(event.blocks.at(0)?._key)(snapshot), lastBlockKey = getUniqueBlockKey(event.blocks.at(-1)?._key)(snapshot);
|
|
9323
9327
|
return {
|
|
9324
9328
|
firstBlockKey,
|
|
9325
9329
|
lastBlockKey
|
|
@@ -9333,7 +9337,13 @@ const abstractDeserializeBehaviors = [
|
|
|
9333
9337
|
lastBlockKey
|
|
9334
9338
|
}) => [...event.blocks.map((block, index) => raise({
|
|
9335
9339
|
type: "insert.block",
|
|
9336
|
-
block
|
|
9340
|
+
block: index === 0 ? {
|
|
9341
|
+
...block,
|
|
9342
|
+
_key: firstBlockKey
|
|
9343
|
+
} : index === event.blocks.length - 1 ? {
|
|
9344
|
+
...block,
|
|
9345
|
+
_key: lastBlockKey
|
|
9346
|
+
} : block,
|
|
9337
9347
|
placement: index === 0 ? "before" : "after",
|
|
9338
9348
|
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
9339
9349
|
})), ...event.select === "none" ? [raise({
|
|
@@ -9361,7 +9371,7 @@ const abstractDeserializeBehaviors = [
|
|
|
9361
9371
|
}) => {
|
|
9362
9372
|
if (event.placement !== "after")
|
|
9363
9373
|
return !1;
|
|
9364
|
-
const firstBlockKey = event.blocks.at(0)?._key
|
|
9374
|
+
const firstBlockKey = getUniqueBlockKey(event.blocks.at(0)?._key)(snapshot), lastBlockKey = getUniqueBlockKey(event.blocks.at(-1)?._key)(snapshot);
|
|
9365
9375
|
return {
|
|
9366
9376
|
firstBlockKey,
|
|
9367
9377
|
lastBlockKey
|
|
@@ -9375,7 +9385,13 @@ const abstractDeserializeBehaviors = [
|
|
|
9375
9385
|
lastBlockKey
|
|
9376
9386
|
}) => [...event.blocks.map((block, index) => raise({
|
|
9377
9387
|
type: "insert.block",
|
|
9378
|
-
block
|
|
9388
|
+
block: index === 0 ? {
|
|
9389
|
+
...block,
|
|
9390
|
+
_key: firstBlockKey
|
|
9391
|
+
} : index === event.blocks.length - 1 ? {
|
|
9392
|
+
...block,
|
|
9393
|
+
_key: lastBlockKey
|
|
9394
|
+
} : block,
|
|
9379
9395
|
placement: "after",
|
|
9380
9396
|
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
9381
9397
|
})), ...event.select === "none" ? [raise({
|
|
@@ -9406,7 +9422,7 @@ const abstractDeserializeBehaviors = [
|
|
|
9406
9422
|
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
9407
9423
|
if (!focusTextBlock || !isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
9408
9424
|
return !1;
|
|
9409
|
-
const firstBlockKey = event.blocks.at(0)?._key
|
|
9425
|
+
const firstBlockKey = getUniqueBlockKey(event.blocks.at(0)?._key)(snapshot), lastBlockKey = getUniqueBlockKey(event.blocks.at(-1)?._key)(snapshot);
|
|
9410
9426
|
return {
|
|
9411
9427
|
focusTextBlock,
|
|
9412
9428
|
firstBlockKey,
|
|
@@ -9420,10 +9436,22 @@ const abstractDeserializeBehaviors = [
|
|
|
9420
9436
|
lastBlockKey
|
|
9421
9437
|
}) => [...event.blocks.map((block, index) => raise({
|
|
9422
9438
|
type: "insert.block",
|
|
9423
|
-
block
|
|
9439
|
+
block: index === 0 ? {
|
|
9440
|
+
...block,
|
|
9441
|
+
_key: firstBlockKey
|
|
9442
|
+
} : index === event.blocks.length - 1 ? {
|
|
9443
|
+
...block,
|
|
9444
|
+
_key: lastBlockKey
|
|
9445
|
+
} : block,
|
|
9424
9446
|
placement: index === 0 ? "auto" : "after",
|
|
9425
9447
|
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
9426
|
-
})), ...event.select === "none"
|
|
9448
|
+
})), ...event.select === "none" ? [raise({
|
|
9449
|
+
type: "select.block",
|
|
9450
|
+
at: [{
|
|
9451
|
+
_key: firstBlockKey
|
|
9452
|
+
}],
|
|
9453
|
+
select: "start"
|
|
9454
|
+
})] : event.select === "start" ? [raise({
|
|
9427
9455
|
type: "select.block",
|
|
9428
9456
|
at: [{
|
|
9429
9457
|
_key: firstBlockKey
|
|
@@ -9463,23 +9491,28 @@ const abstractDeserializeBehaviors = [
|
|
|
9463
9491
|
}
|
|
9464
9492
|
},
|
|
9465
9493
|
block: focusTextBlock.node
|
|
9466
|
-
});
|
|
9494
|
+
}), firstBlockKey = getUniqueBlockKey(event.blocks.at(0)?._key)(snapshot), lastBlockKey = getUniqueBlockKey(event.blocks.at(-1)?._key)(snapshot), isFirstBlockTextBlock = isTextBlock(snapshot.context, event.blocks.at(0));
|
|
9467
9495
|
return {
|
|
9468
|
-
firstBlockKey
|
|
9496
|
+
firstBlockKey,
|
|
9497
|
+
lastBlockKey,
|
|
9469
9498
|
focusBlockStartPoint,
|
|
9470
9499
|
focusBlockEndPoint,
|
|
9471
9500
|
focusTextBlockAfter,
|
|
9472
|
-
selection: snapshot.context.selection
|
|
9501
|
+
selection: snapshot.context.selection,
|
|
9502
|
+
isFirstBlockTextBlock
|
|
9473
9503
|
};
|
|
9474
9504
|
},
|
|
9475
9505
|
actions: [({
|
|
9506
|
+
snapshot,
|
|
9476
9507
|
event
|
|
9477
9508
|
}, {
|
|
9478
9509
|
focusBlockEndPoint,
|
|
9479
9510
|
focusTextBlockAfter,
|
|
9480
9511
|
selection,
|
|
9481
9512
|
firstBlockKey,
|
|
9482
|
-
|
|
9513
|
+
lastBlockKey,
|
|
9514
|
+
focusBlockStartPoint,
|
|
9515
|
+
isFirstBlockTextBlock
|
|
9483
9516
|
}) => [...event.blocks.flatMap((block, index) => index === 0 ? [...isEqualSelectionPoints(selection.focus, focusBlockEndPoint) ? [] : [raise({
|
|
9484
9517
|
type: "delete",
|
|
9485
9518
|
at: {
|
|
@@ -9488,20 +9521,26 @@ const abstractDeserializeBehaviors = [
|
|
|
9488
9521
|
}
|
|
9489
9522
|
})], raise({
|
|
9490
9523
|
type: "insert.block",
|
|
9491
|
-
block
|
|
9524
|
+
block: {
|
|
9525
|
+
...block,
|
|
9526
|
+
_key: firstBlockKey
|
|
9527
|
+
},
|
|
9492
9528
|
placement: "auto",
|
|
9493
9529
|
select: "end"
|
|
9494
9530
|
})] : index === event.blocks.length - 1 ? [raise({
|
|
9495
9531
|
type: "insert.block",
|
|
9496
|
-
block
|
|
9532
|
+
block: {
|
|
9533
|
+
...block,
|
|
9534
|
+
_key: lastBlockKey
|
|
9535
|
+
},
|
|
9497
9536
|
placement: "after",
|
|
9498
9537
|
select: "end"
|
|
9499
|
-
}), raise({
|
|
9538
|
+
}), ...isEmptyTextBlock(snapshot.context, focusTextBlockAfter) ? [] : [raise({
|
|
9500
9539
|
type: "insert.block",
|
|
9501
9540
|
block: focusTextBlockAfter,
|
|
9502
9541
|
placement: "auto",
|
|
9503
9542
|
select: event.select === "end" ? "none" : "end"
|
|
9504
|
-
})] : [raise({
|
|
9543
|
+
})]] : [raise({
|
|
9505
9544
|
type: "insert.block",
|
|
9506
9545
|
block,
|
|
9507
9546
|
placement: "after",
|
|
@@ -9509,7 +9548,7 @@ const abstractDeserializeBehaviors = [
|
|
|
9509
9548
|
})]), ...event.select === "none" ? [raise({
|
|
9510
9549
|
type: "select",
|
|
9511
9550
|
at: selection
|
|
9512
|
-
})] : event.select === "start" ? [isEqualSelectionPoints(selection.focus, focusBlockStartPoint) ? raise({
|
|
9551
|
+
})] : event.select === "start" ? [isEqualSelectionPoints(selection.focus, focusBlockStartPoint) || !isFirstBlockTextBlock ? raise({
|
|
9513
9552
|
type: "select.block",
|
|
9514
9553
|
at: [{
|
|
9515
9554
|
_key: firstBlockKey
|
|
@@ -9526,16 +9565,51 @@ const abstractDeserializeBehaviors = [
|
|
|
9526
9565
|
defineBehavior({
|
|
9527
9566
|
on: "insert.blocks",
|
|
9528
9567
|
guard: ({
|
|
9568
|
+
snapshot,
|
|
9529
9569
|
event
|
|
9530
|
-
}) =>
|
|
9570
|
+
}) => {
|
|
9571
|
+
if (event.placement !== "auto")
|
|
9572
|
+
return !1;
|
|
9573
|
+
const selection = snapshot.context.selection, firstBlockKey = getUniqueBlockKey(event.blocks.at(0)?._key)(snapshot), lastBlockKey = getUniqueBlockKey(event.blocks.at(-1)?._key)(snapshot);
|
|
9574
|
+
return {
|
|
9575
|
+
firstBlockKey,
|
|
9576
|
+
lastBlockKey,
|
|
9577
|
+
selection
|
|
9578
|
+
};
|
|
9579
|
+
},
|
|
9531
9580
|
actions: [({
|
|
9532
9581
|
event
|
|
9533
|
-
}
|
|
9582
|
+
}, {
|
|
9583
|
+
firstBlockKey,
|
|
9584
|
+
lastBlockKey,
|
|
9585
|
+
selection
|
|
9586
|
+
}) => [...event.blocks.map((block, index) => raise({
|
|
9534
9587
|
type: "insert.block",
|
|
9535
|
-
block
|
|
9588
|
+
block: index === 0 ? {
|
|
9589
|
+
...block,
|
|
9590
|
+
_key: firstBlockKey
|
|
9591
|
+
} : index === event.blocks.length - 1 ? {
|
|
9592
|
+
...block,
|
|
9593
|
+
_key: lastBlockKey
|
|
9594
|
+
} : block,
|
|
9536
9595
|
placement: index === 0 ? "auto" : "after",
|
|
9537
|
-
select: event.select ?? "end"
|
|
9538
|
-
}))
|
|
9596
|
+
select: index !== event.blocks.length - 1 ? "end" : event.select ?? "end"
|
|
9597
|
+
})), ...event.select === "none" ? [raise({
|
|
9598
|
+
type: "select",
|
|
9599
|
+
at: selection
|
|
9600
|
+
})] : event.select === "start" ? [raise({
|
|
9601
|
+
type: "select.block",
|
|
9602
|
+
at: [{
|
|
9603
|
+
_key: firstBlockKey
|
|
9604
|
+
}],
|
|
9605
|
+
select: "start"
|
|
9606
|
+
})] : [raise({
|
|
9607
|
+
type: "select.block",
|
|
9608
|
+
at: [{
|
|
9609
|
+
_key: lastBlockKey
|
|
9610
|
+
}],
|
|
9611
|
+
select: "end"
|
|
9612
|
+
})]]]
|
|
9539
9613
|
}),
|
|
9540
9614
|
defineBehavior({
|
|
9541
9615
|
on: "insert.break",
|