@portabletext/editor 2.8.4 → 2.9.1
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.cts +68 -60
- package/lib/_chunks-dts/behavior.types.action.d.ts +59 -51
- package/lib/index.cjs +264 -73
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +264 -73
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/plugins/index.d.ts +3 -3
- package/package.json +5 -5
- package/src/behaviors/behavior.abstract.insert.ts +258 -60
- package/src/behaviors/behavior.abstract.select.ts +81 -39
- package/src/behaviors/behavior.types.event.ts +6 -0
- package/src/editor/Editable.tsx +12 -1
package/lib/index.js
CHANGED
|
@@ -2284,8 +2284,12 @@ PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
|
2284
2284
|
function validateSelection(slateEditor, activeElement) {
|
|
2285
2285
|
if (!slateEditor.selection)
|
|
2286
2286
|
return;
|
|
2287
|
-
|
|
2288
|
-
|
|
2287
|
+
let root;
|
|
2288
|
+
try {
|
|
2289
|
+
root = ReactEditor.findDocumentOrShadowRoot(slateEditor);
|
|
2290
|
+
} catch {
|
|
2291
|
+
}
|
|
2292
|
+
if (!root || activeElement !== root.activeElement)
|
|
2289
2293
|
return;
|
|
2290
2294
|
const domSelection = ReactEditor.getWindow(slateEditor).getSelection();
|
|
2291
2295
|
if (!domSelection || domSelection.rangeCount === 0)
|
|
@@ -8269,28 +8273,104 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
8269
8273
|
on: "insert.blocks",
|
|
8270
8274
|
guard: ({
|
|
8271
8275
|
event
|
|
8272
|
-
}) =>
|
|
8276
|
+
}) => {
|
|
8277
|
+
const onlyBlock = event.blocks.length === 1 ? event.blocks.at(0) : void 0;
|
|
8278
|
+
return onlyBlock ? {
|
|
8279
|
+
onlyBlock
|
|
8280
|
+
} : !1;
|
|
8281
|
+
},
|
|
8273
8282
|
actions: [({
|
|
8274
8283
|
event
|
|
8275
|
-
}
|
|
8284
|
+
}, {
|
|
8285
|
+
onlyBlock
|
|
8286
|
+
}) => [raise({
|
|
8287
|
+
type: "insert.block",
|
|
8288
|
+
block: onlyBlock,
|
|
8289
|
+
placement: event.placement,
|
|
8290
|
+
select: event.select ?? "end"
|
|
8291
|
+
})]]
|
|
8292
|
+
}), defineBehavior({
|
|
8293
|
+
on: "insert.blocks",
|
|
8294
|
+
guard: ({
|
|
8295
|
+
snapshot,
|
|
8296
|
+
event
|
|
8297
|
+
}) => {
|
|
8298
|
+
if (event.placement !== "before")
|
|
8299
|
+
return !1;
|
|
8300
|
+
const firstBlockKey = event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(), lastBlockKey = event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator();
|
|
8301
|
+
return {
|
|
8302
|
+
firstBlockKey,
|
|
8303
|
+
lastBlockKey
|
|
8304
|
+
};
|
|
8305
|
+
},
|
|
8306
|
+
actions: [({
|
|
8307
|
+
snapshot,
|
|
8308
|
+
event
|
|
8309
|
+
}, {
|
|
8310
|
+
firstBlockKey,
|
|
8311
|
+
lastBlockKey
|
|
8312
|
+
}) => [...event.blocks.map((block, index) => raise({
|
|
8276
8313
|
type: "insert.block",
|
|
8277
8314
|
block,
|
|
8278
8315
|
placement: index === 0 ? "before" : "after",
|
|
8279
|
-
select: event.
|
|
8280
|
-
}))
|
|
8316
|
+
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
8317
|
+
})), ...event.select === "none" ? [raise({
|
|
8318
|
+
type: "select",
|
|
8319
|
+
at: snapshot.context.selection
|
|
8320
|
+
})] : event.select === "start" ? [raise({
|
|
8321
|
+
type: "select.block",
|
|
8322
|
+
at: [{
|
|
8323
|
+
_key: firstBlockKey
|
|
8324
|
+
}],
|
|
8325
|
+
select: "start"
|
|
8326
|
+
})] : [raise({
|
|
8327
|
+
type: "select.block",
|
|
8328
|
+
at: [{
|
|
8329
|
+
_key: lastBlockKey
|
|
8330
|
+
}],
|
|
8331
|
+
select: "end"
|
|
8332
|
+
})]]]
|
|
8281
8333
|
}), defineBehavior({
|
|
8282
8334
|
on: "insert.blocks",
|
|
8283
8335
|
guard: ({
|
|
8336
|
+
snapshot,
|
|
8284
8337
|
event
|
|
8285
|
-
}) =>
|
|
8338
|
+
}) => {
|
|
8339
|
+
if (event.placement !== "after")
|
|
8340
|
+
return !1;
|
|
8341
|
+
const firstBlockKey = event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(), lastBlockKey = event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator();
|
|
8342
|
+
return {
|
|
8343
|
+
firstBlockKey,
|
|
8344
|
+
lastBlockKey
|
|
8345
|
+
};
|
|
8346
|
+
},
|
|
8286
8347
|
actions: [({
|
|
8348
|
+
snapshot,
|
|
8287
8349
|
event
|
|
8288
|
-
}
|
|
8350
|
+
}, {
|
|
8351
|
+
firstBlockKey,
|
|
8352
|
+
lastBlockKey
|
|
8353
|
+
}) => [...event.blocks.map((block, index) => raise({
|
|
8289
8354
|
type: "insert.block",
|
|
8290
8355
|
block,
|
|
8291
8356
|
placement: "after",
|
|
8292
|
-
select: event.
|
|
8293
|
-
}))
|
|
8357
|
+
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
8358
|
+
})), ...event.select === "none" ? [raise({
|
|
8359
|
+
type: "select",
|
|
8360
|
+
at: snapshot.context.selection
|
|
8361
|
+
})] : event.select === "start" ? [raise({
|
|
8362
|
+
type: "select.block",
|
|
8363
|
+
at: [{
|
|
8364
|
+
_key: firstBlockKey
|
|
8365
|
+
}],
|
|
8366
|
+
select: "start"
|
|
8367
|
+
})] : [raise({
|
|
8368
|
+
type: "select.block",
|
|
8369
|
+
at: [{
|
|
8370
|
+
_key: lastBlockKey
|
|
8371
|
+
}],
|
|
8372
|
+
select: "end"
|
|
8373
|
+
})]]]
|
|
8294
8374
|
}), defineBehavior({
|
|
8295
8375
|
on: "insert.blocks",
|
|
8296
8376
|
guard: ({
|
|
@@ -8300,49 +8380,123 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
8300
8380
|
if (event.placement !== "auto")
|
|
8301
8381
|
return !1;
|
|
8302
8382
|
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
|
|
8383
|
+
if (!focusTextBlock || !isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
8384
|
+
return !1;
|
|
8385
|
+
const firstBlockKey = event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(), lastBlockKey = event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator();
|
|
8386
|
+
return {
|
|
8387
|
+
focusTextBlock,
|
|
8388
|
+
firstBlockKey,
|
|
8389
|
+
lastBlockKey
|
|
8390
|
+
};
|
|
8306
8391
|
},
|
|
8307
8392
|
actions: [({
|
|
8308
|
-
snapshot,
|
|
8309
8393
|
event
|
|
8310
8394
|
}, {
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
block: event.blocks[0],
|
|
8315
|
-
placement: "auto",
|
|
8316
|
-
select: event.select ?? "end"
|
|
8317
|
-
})] : isEmptyTextBlock(snapshot.context, focusTextBlock.node) ? event.blocks.map((block, index) => raise({
|
|
8395
|
+
firstBlockKey,
|
|
8396
|
+
lastBlockKey
|
|
8397
|
+
}) => [...event.blocks.map((block, index) => raise({
|
|
8318
8398
|
type: "insert.block",
|
|
8319
8399
|
block,
|
|
8320
8400
|
placement: index === 0 ? "auto" : "after",
|
|
8321
|
-
select: event.
|
|
8322
|
-
}))
|
|
8323
|
-
type: "
|
|
8324
|
-
|
|
8325
|
-
|
|
8401
|
+
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
8402
|
+
})), ...event.select === "none" || event.select === "start" ? [raise({
|
|
8403
|
+
type: "select.block",
|
|
8404
|
+
at: [{
|
|
8405
|
+
_key: firstBlockKey
|
|
8406
|
+
}],
|
|
8407
|
+
select: "start"
|
|
8408
|
+
})] : [raise({
|
|
8409
|
+
type: "select.block",
|
|
8410
|
+
at: [{
|
|
8411
|
+
_key: lastBlockKey
|
|
8412
|
+
}],
|
|
8326
8413
|
select: "end"
|
|
8327
|
-
})
|
|
8414
|
+
})]]]
|
|
8415
|
+
}), defineBehavior({
|
|
8416
|
+
on: "insert.blocks",
|
|
8417
|
+
guard: ({
|
|
8418
|
+
snapshot,
|
|
8419
|
+
event
|
|
8420
|
+
}) => {
|
|
8421
|
+
if (event.placement !== "auto")
|
|
8422
|
+
return !1;
|
|
8423
|
+
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
8424
|
+
if (!focusTextBlock || !snapshot.context.selection)
|
|
8425
|
+
return !1;
|
|
8426
|
+
const focusBlockStartPoint = getBlockStartPoint({
|
|
8427
|
+
context: snapshot.context,
|
|
8428
|
+
block: focusTextBlock
|
|
8429
|
+
}), focusBlockEndPoint = getBlockEndPoint({
|
|
8430
|
+
context: snapshot.context,
|
|
8431
|
+
block: focusTextBlock
|
|
8432
|
+
}), focusTextBlockAfter = sliceTextBlock({
|
|
8433
|
+
context: {
|
|
8434
|
+
schema: snapshot.context.schema,
|
|
8435
|
+
selection: {
|
|
8436
|
+
anchor: snapshot.context.selection.focus,
|
|
8437
|
+
focus: focusBlockEndPoint
|
|
8438
|
+
}
|
|
8439
|
+
},
|
|
8440
|
+
block: focusTextBlock.node
|
|
8441
|
+
});
|
|
8442
|
+
return {
|
|
8443
|
+
firstBlockKey: event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(),
|
|
8444
|
+
focusBlockStartPoint,
|
|
8445
|
+
focusBlockEndPoint,
|
|
8446
|
+
focusTextBlockAfter,
|
|
8447
|
+
selection: snapshot.context.selection
|
|
8448
|
+
};
|
|
8449
|
+
},
|
|
8450
|
+
actions: [({
|
|
8451
|
+
event
|
|
8452
|
+
}, {
|
|
8453
|
+
focusBlockEndPoint,
|
|
8454
|
+
focusTextBlockAfter,
|
|
8455
|
+
selection,
|
|
8456
|
+
firstBlockKey,
|
|
8457
|
+
focusBlockStartPoint
|
|
8458
|
+
}) => [...event.blocks.flatMap((block, index) => index === 0 ? [...isEqualSelectionPoints(selection.focus, focusBlockEndPoint) ? [] : [raise({
|
|
8459
|
+
type: "delete",
|
|
8460
|
+
at: {
|
|
8461
|
+
anchor: selection.focus,
|
|
8462
|
+
focus: focusBlockEndPoint
|
|
8463
|
+
}
|
|
8464
|
+
})], raise({
|
|
8328
8465
|
type: "insert.block",
|
|
8329
8466
|
block,
|
|
8330
8467
|
placement: "auto",
|
|
8331
|
-
select:
|
|
8468
|
+
select: "end"
|
|
8332
8469
|
})] : index === event.blocks.length - 1 ? [raise({
|
|
8333
|
-
type: "select.next block",
|
|
8334
|
-
select: "start"
|
|
8335
|
-
}), raise({
|
|
8336
8470
|
type: "insert.block",
|
|
8337
8471
|
block,
|
|
8472
|
+
placement: "after",
|
|
8473
|
+
select: "end"
|
|
8474
|
+
}), raise({
|
|
8475
|
+
type: "insert.block",
|
|
8476
|
+
block: focusTextBlockAfter,
|
|
8338
8477
|
placement: "auto",
|
|
8339
|
-
select: event.select
|
|
8478
|
+
select: event.select === "end" ? "none" : "end"
|
|
8340
8479
|
})] : [raise({
|
|
8341
8480
|
type: "insert.block",
|
|
8342
8481
|
block,
|
|
8343
8482
|
placement: "after",
|
|
8344
|
-
select:
|
|
8345
|
-
})])
|
|
8483
|
+
select: "end"
|
|
8484
|
+
})]), ...event.select === "none" ? [raise({
|
|
8485
|
+
type: "select",
|
|
8486
|
+
at: selection
|
|
8487
|
+
})] : event.select === "start" ? [isEqualSelectionPoints(selection.focus, focusBlockStartPoint) ? raise({
|
|
8488
|
+
type: "select.block",
|
|
8489
|
+
at: [{
|
|
8490
|
+
_key: firstBlockKey
|
|
8491
|
+
}],
|
|
8492
|
+
select: "start"
|
|
8493
|
+
}) : raise({
|
|
8494
|
+
type: "select",
|
|
8495
|
+
at: {
|
|
8496
|
+
anchor: selection.focus,
|
|
8497
|
+
focus: selection.focus
|
|
8498
|
+
}
|
|
8499
|
+
})] : []]]
|
|
8346
8500
|
}), defineBehavior({
|
|
8347
8501
|
on: "insert.blocks",
|
|
8348
8502
|
guard: ({
|
|
@@ -8598,62 +8752,99 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
8598
8752
|
to: nextBlock.path
|
|
8599
8753
|
})]]
|
|
8600
8754
|
})], abstractSelectBehaviors = [defineBehavior({
|
|
8601
|
-
on: "select.
|
|
8755
|
+
on: "select.block",
|
|
8602
8756
|
guard: ({
|
|
8603
8757
|
snapshot,
|
|
8604
8758
|
event
|
|
8605
8759
|
}) => {
|
|
8606
|
-
|
|
8607
|
-
if (!previousBlock)
|
|
8760
|
+
if (event.select !== "end")
|
|
8608
8761
|
return !1;
|
|
8609
|
-
const
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
|
|
8614
|
-
|
|
8615
|
-
|
|
8616
|
-
|
|
8617
|
-
|
|
8618
|
-
|
|
8619
|
-
|
|
8762
|
+
const block = getFocusBlock$1({
|
|
8763
|
+
...snapshot,
|
|
8764
|
+
context: {
|
|
8765
|
+
...snapshot.context,
|
|
8766
|
+
selection: {
|
|
8767
|
+
anchor: {
|
|
8768
|
+
path: event.at,
|
|
8769
|
+
offset: 0
|
|
8770
|
+
},
|
|
8771
|
+
focus: {
|
|
8772
|
+
path: event.at,
|
|
8773
|
+
offset: 0
|
|
8774
|
+
}
|
|
8775
|
+
}
|
|
8620
8776
|
}
|
|
8621
|
-
};
|
|
8777
|
+
});
|
|
8778
|
+
return block ? {
|
|
8779
|
+
blockEndPoint: getBlockEndPoint({
|
|
8780
|
+
context: snapshot.context,
|
|
8781
|
+
block
|
|
8782
|
+
})
|
|
8783
|
+
} : !1;
|
|
8622
8784
|
},
|
|
8623
8785
|
actions: [(_, {
|
|
8624
|
-
|
|
8786
|
+
blockEndPoint
|
|
8625
8787
|
}) => [raise({
|
|
8626
8788
|
type: "select",
|
|
8627
|
-
at:
|
|
8789
|
+
at: {
|
|
8790
|
+
anchor: blockEndPoint,
|
|
8791
|
+
focus: blockEndPoint
|
|
8792
|
+
}
|
|
8628
8793
|
})]]
|
|
8629
8794
|
}), defineBehavior({
|
|
8630
|
-
on: "select.
|
|
8795
|
+
on: "select.block",
|
|
8796
|
+
actions: [({
|
|
8797
|
+
event
|
|
8798
|
+
}) => [raise({
|
|
8799
|
+
type: "select",
|
|
8800
|
+
at: {
|
|
8801
|
+
anchor: {
|
|
8802
|
+
path: event.at,
|
|
8803
|
+
offset: 0
|
|
8804
|
+
},
|
|
8805
|
+
focus: {
|
|
8806
|
+
path: event.at,
|
|
8807
|
+
offset: 0
|
|
8808
|
+
}
|
|
8809
|
+
}
|
|
8810
|
+
})]]
|
|
8811
|
+
}), defineBehavior({
|
|
8812
|
+
on: "select.previous block",
|
|
8631
8813
|
guard: ({
|
|
8632
|
-
snapshot
|
|
8814
|
+
snapshot
|
|
8815
|
+
}) => {
|
|
8816
|
+
const previousBlock = getPreviousBlock(snapshot);
|
|
8817
|
+
return previousBlock ? {
|
|
8818
|
+
previousBlock
|
|
8819
|
+
} : !1;
|
|
8820
|
+
},
|
|
8821
|
+
actions: [({
|
|
8633
8822
|
event
|
|
8823
|
+
}, {
|
|
8824
|
+
previousBlock
|
|
8825
|
+
}) => [raise({
|
|
8826
|
+
type: "select.block",
|
|
8827
|
+
at: previousBlock.path,
|
|
8828
|
+
select: event.select
|
|
8829
|
+
})]]
|
|
8830
|
+
}), defineBehavior({
|
|
8831
|
+
on: "select.next block",
|
|
8832
|
+
guard: ({
|
|
8833
|
+
snapshot
|
|
8634
8834
|
}) => {
|
|
8635
8835
|
const nextBlock = getNextBlock(snapshot);
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
context: snapshot.context,
|
|
8640
|
-
block: nextBlock
|
|
8641
|
-
}) : getBlockStartPoint({
|
|
8642
|
-
context: snapshot.context,
|
|
8643
|
-
block: nextBlock
|
|
8644
|
-
});
|
|
8645
|
-
return {
|
|
8646
|
-
selection: {
|
|
8647
|
-
anchor: point,
|
|
8648
|
-
focus: point
|
|
8649
|
-
}
|
|
8650
|
-
};
|
|
8836
|
+
return nextBlock ? {
|
|
8837
|
+
nextBlock
|
|
8838
|
+
} : !1;
|
|
8651
8839
|
},
|
|
8652
|
-
actions: [(
|
|
8653
|
-
|
|
8840
|
+
actions: [({
|
|
8841
|
+
event
|
|
8842
|
+
}, {
|
|
8843
|
+
nextBlock
|
|
8654
8844
|
}) => [raise({
|
|
8655
|
-
type: "select",
|
|
8656
|
-
at:
|
|
8845
|
+
type: "select.block",
|
|
8846
|
+
at: nextBlock.path,
|
|
8847
|
+
select: event.select
|
|
8657
8848
|
})]]
|
|
8658
8849
|
})], abstractSerializeBehaviors = [defineBehavior({
|
|
8659
8850
|
on: "serialize",
|
|
@@ -9027,7 +9218,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
9027
9218
|
function isSyntheticBehaviorEvent(event) {
|
|
9028
9219
|
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
9029
9220
|
}
|
|
9030
|
-
const abstractBehaviorEventTypes = ["annotation.set", "annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.child", "delete.forward", "delete.text", "deserialize", "deserialize.data", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.inline object", "insert.soft break", "insert.span", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialize.data", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
9221
|
+
const abstractBehaviorEventTypes = ["annotation.set", "annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.child", "delete.forward", "delete.text", "deserialize", "deserialize.data", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.inline object", "insert.soft break", "insert.span", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.block", "select.previous block", "select.next block", "serialize", "serialize.data", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
9031
9222
|
function isAbstractBehaviorEvent(event) {
|
|
9032
9223
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
9033
9224
|
}
|