@portabletext/editor 2.8.4 → 2.9.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.cts +68 -60
- package/lib/_chunks-dts/behavior.types.action.d.ts +70 -62
- package/lib/index.cjs +258 -71
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +258 -71
- 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 +6 -6
- 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/lib/index.cjs
CHANGED
|
@@ -8240,28 +8240,104 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
8240
8240
|
on: "insert.blocks",
|
|
8241
8241
|
guard: ({
|
|
8242
8242
|
event
|
|
8243
|
-
}) =>
|
|
8243
|
+
}) => {
|
|
8244
|
+
const onlyBlock = event.blocks.length === 1 ? event.blocks.at(0) : void 0;
|
|
8245
|
+
return onlyBlock ? {
|
|
8246
|
+
onlyBlock
|
|
8247
|
+
} : !1;
|
|
8248
|
+
},
|
|
8244
8249
|
actions: [({
|
|
8245
8250
|
event
|
|
8246
|
-
}
|
|
8251
|
+
}, {
|
|
8252
|
+
onlyBlock
|
|
8253
|
+
}) => [behaviors_index.raise({
|
|
8254
|
+
type: "insert.block",
|
|
8255
|
+
block: onlyBlock,
|
|
8256
|
+
placement: event.placement,
|
|
8257
|
+
select: event.select ?? "end"
|
|
8258
|
+
})]]
|
|
8259
|
+
}), behaviors_index.defineBehavior({
|
|
8260
|
+
on: "insert.blocks",
|
|
8261
|
+
guard: ({
|
|
8262
|
+
snapshot,
|
|
8263
|
+
event
|
|
8264
|
+
}) => {
|
|
8265
|
+
if (event.placement !== "before")
|
|
8266
|
+
return !1;
|
|
8267
|
+
const firstBlockKey = event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(), lastBlockKey = event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator();
|
|
8268
|
+
return {
|
|
8269
|
+
firstBlockKey,
|
|
8270
|
+
lastBlockKey
|
|
8271
|
+
};
|
|
8272
|
+
},
|
|
8273
|
+
actions: [({
|
|
8274
|
+
snapshot,
|
|
8275
|
+
event
|
|
8276
|
+
}, {
|
|
8277
|
+
firstBlockKey,
|
|
8278
|
+
lastBlockKey
|
|
8279
|
+
}) => [...event.blocks.map((block, index) => behaviors_index.raise({
|
|
8247
8280
|
type: "insert.block",
|
|
8248
8281
|
block,
|
|
8249
8282
|
placement: index === 0 ? "before" : "after",
|
|
8250
|
-
select: event.
|
|
8251
|
-
}))
|
|
8283
|
+
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
8284
|
+
})), ...event.select === "none" ? [behaviors_index.raise({
|
|
8285
|
+
type: "select",
|
|
8286
|
+
at: snapshot.context.selection
|
|
8287
|
+
})] : event.select === "start" ? [behaviors_index.raise({
|
|
8288
|
+
type: "select.block",
|
|
8289
|
+
at: [{
|
|
8290
|
+
_key: firstBlockKey
|
|
8291
|
+
}],
|
|
8292
|
+
select: "start"
|
|
8293
|
+
})] : [behaviors_index.raise({
|
|
8294
|
+
type: "select.block",
|
|
8295
|
+
at: [{
|
|
8296
|
+
_key: lastBlockKey
|
|
8297
|
+
}],
|
|
8298
|
+
select: "end"
|
|
8299
|
+
})]]]
|
|
8252
8300
|
}), behaviors_index.defineBehavior({
|
|
8253
8301
|
on: "insert.blocks",
|
|
8254
8302
|
guard: ({
|
|
8303
|
+
snapshot,
|
|
8255
8304
|
event
|
|
8256
|
-
}) =>
|
|
8305
|
+
}) => {
|
|
8306
|
+
if (event.placement !== "after")
|
|
8307
|
+
return !1;
|
|
8308
|
+
const firstBlockKey = event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(), lastBlockKey = event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator();
|
|
8309
|
+
return {
|
|
8310
|
+
firstBlockKey,
|
|
8311
|
+
lastBlockKey
|
|
8312
|
+
};
|
|
8313
|
+
},
|
|
8257
8314
|
actions: [({
|
|
8315
|
+
snapshot,
|
|
8258
8316
|
event
|
|
8259
|
-
}
|
|
8317
|
+
}, {
|
|
8318
|
+
firstBlockKey,
|
|
8319
|
+
lastBlockKey
|
|
8320
|
+
}) => [...event.blocks.map((block, index) => behaviors_index.raise({
|
|
8260
8321
|
type: "insert.block",
|
|
8261
8322
|
block,
|
|
8262
8323
|
placement: "after",
|
|
8263
|
-
select: event.
|
|
8264
|
-
}))
|
|
8324
|
+
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
8325
|
+
})), ...event.select === "none" ? [behaviors_index.raise({
|
|
8326
|
+
type: "select",
|
|
8327
|
+
at: snapshot.context.selection
|
|
8328
|
+
})] : event.select === "start" ? [behaviors_index.raise({
|
|
8329
|
+
type: "select.block",
|
|
8330
|
+
at: [{
|
|
8331
|
+
_key: firstBlockKey
|
|
8332
|
+
}],
|
|
8333
|
+
select: "start"
|
|
8334
|
+
})] : [behaviors_index.raise({
|
|
8335
|
+
type: "select.block",
|
|
8336
|
+
at: [{
|
|
8337
|
+
_key: lastBlockKey
|
|
8338
|
+
}],
|
|
8339
|
+
select: "end"
|
|
8340
|
+
})]]]
|
|
8265
8341
|
}), behaviors_index.defineBehavior({
|
|
8266
8342
|
on: "insert.blocks",
|
|
8267
8343
|
guard: ({
|
|
@@ -8271,49 +8347,123 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
8271
8347
|
if (event.placement !== "auto")
|
|
8272
8348
|
return !1;
|
|
8273
8349
|
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot);
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
|
|
8350
|
+
if (!focusTextBlock || !util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
8351
|
+
return !1;
|
|
8352
|
+
const firstBlockKey = event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(), lastBlockKey = event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator();
|
|
8353
|
+
return {
|
|
8354
|
+
focusTextBlock,
|
|
8355
|
+
firstBlockKey,
|
|
8356
|
+
lastBlockKey
|
|
8357
|
+
};
|
|
8277
8358
|
},
|
|
8278
8359
|
actions: [({
|
|
8279
|
-
snapshot,
|
|
8280
8360
|
event
|
|
8281
8361
|
}, {
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
block: event.blocks[0],
|
|
8286
|
-
placement: "auto",
|
|
8287
|
-
select: event.select ?? "end"
|
|
8288
|
-
})] : util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusTextBlock.node) ? event.blocks.map((block, index) => behaviors_index.raise({
|
|
8362
|
+
firstBlockKey,
|
|
8363
|
+
lastBlockKey
|
|
8364
|
+
}) => [...event.blocks.map((block, index) => behaviors_index.raise({
|
|
8289
8365
|
type: "insert.block",
|
|
8290
8366
|
block,
|
|
8291
8367
|
placement: index === 0 ? "auto" : "after",
|
|
8292
|
-
select: event.
|
|
8293
|
-
}))
|
|
8294
|
-
type: "
|
|
8295
|
-
|
|
8296
|
-
|
|
8368
|
+
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
8369
|
+
})), ...event.select === "none" || event.select === "start" ? [behaviors_index.raise({
|
|
8370
|
+
type: "select.block",
|
|
8371
|
+
at: [{
|
|
8372
|
+
_key: firstBlockKey
|
|
8373
|
+
}],
|
|
8374
|
+
select: "start"
|
|
8375
|
+
})] : [behaviors_index.raise({
|
|
8376
|
+
type: "select.block",
|
|
8377
|
+
at: [{
|
|
8378
|
+
_key: lastBlockKey
|
|
8379
|
+
}],
|
|
8297
8380
|
select: "end"
|
|
8298
|
-
})
|
|
8381
|
+
})]]]
|
|
8382
|
+
}), behaviors_index.defineBehavior({
|
|
8383
|
+
on: "insert.blocks",
|
|
8384
|
+
guard: ({
|
|
8385
|
+
snapshot,
|
|
8386
|
+
event
|
|
8387
|
+
}) => {
|
|
8388
|
+
if (event.placement !== "auto")
|
|
8389
|
+
return !1;
|
|
8390
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot);
|
|
8391
|
+
if (!focusTextBlock || !snapshot.context.selection)
|
|
8392
|
+
return !1;
|
|
8393
|
+
const focusBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
|
|
8394
|
+
context: snapshot.context,
|
|
8395
|
+
block: focusTextBlock
|
|
8396
|
+
}), focusBlockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
8397
|
+
context: snapshot.context,
|
|
8398
|
+
block: focusTextBlock
|
|
8399
|
+
}), focusTextBlockAfter = util_sliceTextBlock.sliceTextBlock({
|
|
8400
|
+
context: {
|
|
8401
|
+
schema: snapshot.context.schema,
|
|
8402
|
+
selection: {
|
|
8403
|
+
anchor: snapshot.context.selection.focus,
|
|
8404
|
+
focus: focusBlockEndPoint
|
|
8405
|
+
}
|
|
8406
|
+
},
|
|
8407
|
+
block: focusTextBlock.node
|
|
8408
|
+
});
|
|
8409
|
+
return {
|
|
8410
|
+
firstBlockKey: event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(),
|
|
8411
|
+
focusBlockStartPoint,
|
|
8412
|
+
focusBlockEndPoint,
|
|
8413
|
+
focusTextBlockAfter,
|
|
8414
|
+
selection: snapshot.context.selection
|
|
8415
|
+
};
|
|
8416
|
+
},
|
|
8417
|
+
actions: [({
|
|
8418
|
+
event
|
|
8419
|
+
}, {
|
|
8420
|
+
focusBlockEndPoint,
|
|
8421
|
+
focusTextBlockAfter,
|
|
8422
|
+
selection,
|
|
8423
|
+
firstBlockKey,
|
|
8424
|
+
focusBlockStartPoint
|
|
8425
|
+
}) => [...event.blocks.flatMap((block, index) => index === 0 ? [...util_isSelectionCollapsed.isEqualSelectionPoints(selection.focus, focusBlockEndPoint) ? [] : [behaviors_index.raise({
|
|
8426
|
+
type: "delete",
|
|
8427
|
+
at: {
|
|
8428
|
+
anchor: selection.focus,
|
|
8429
|
+
focus: focusBlockEndPoint
|
|
8430
|
+
}
|
|
8431
|
+
})], behaviors_index.raise({
|
|
8299
8432
|
type: "insert.block",
|
|
8300
8433
|
block,
|
|
8301
8434
|
placement: "auto",
|
|
8302
|
-
select:
|
|
8435
|
+
select: "end"
|
|
8303
8436
|
})] : index === event.blocks.length - 1 ? [behaviors_index.raise({
|
|
8304
|
-
type: "select.next block",
|
|
8305
|
-
select: "start"
|
|
8306
|
-
}), behaviors_index.raise({
|
|
8307
8437
|
type: "insert.block",
|
|
8308
8438
|
block,
|
|
8439
|
+
placement: "after",
|
|
8440
|
+
select: "end"
|
|
8441
|
+
}), behaviors_index.raise({
|
|
8442
|
+
type: "insert.block",
|
|
8443
|
+
block: focusTextBlockAfter,
|
|
8309
8444
|
placement: "auto",
|
|
8310
|
-
select: event.select
|
|
8445
|
+
select: event.select === "end" ? "none" : "end"
|
|
8311
8446
|
})] : [behaviors_index.raise({
|
|
8312
8447
|
type: "insert.block",
|
|
8313
8448
|
block,
|
|
8314
8449
|
placement: "after",
|
|
8315
|
-
select:
|
|
8316
|
-
})])
|
|
8450
|
+
select: "end"
|
|
8451
|
+
})]), ...event.select === "none" ? [behaviors_index.raise({
|
|
8452
|
+
type: "select",
|
|
8453
|
+
at: selection
|
|
8454
|
+
})] : event.select === "start" ? [util_isSelectionCollapsed.isEqualSelectionPoints(selection.focus, focusBlockStartPoint) ? behaviors_index.raise({
|
|
8455
|
+
type: "select.block",
|
|
8456
|
+
at: [{
|
|
8457
|
+
_key: firstBlockKey
|
|
8458
|
+
}],
|
|
8459
|
+
select: "start"
|
|
8460
|
+
}) : behaviors_index.raise({
|
|
8461
|
+
type: "select",
|
|
8462
|
+
at: {
|
|
8463
|
+
anchor: selection.focus,
|
|
8464
|
+
focus: selection.focus
|
|
8465
|
+
}
|
|
8466
|
+
})] : []]]
|
|
8317
8467
|
}), behaviors_index.defineBehavior({
|
|
8318
8468
|
on: "insert.blocks",
|
|
8319
8469
|
guard: ({
|
|
@@ -8569,62 +8719,99 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
8569
8719
|
to: nextBlock.path
|
|
8570
8720
|
})]]
|
|
8571
8721
|
})], abstractSelectBehaviors = [behaviors_index.defineBehavior({
|
|
8572
|
-
on: "select.
|
|
8722
|
+
on: "select.block",
|
|
8573
8723
|
guard: ({
|
|
8574
8724
|
snapshot,
|
|
8575
8725
|
event
|
|
8576
8726
|
}) => {
|
|
8577
|
-
|
|
8578
|
-
if (!previousBlock)
|
|
8727
|
+
if (event.select !== "end")
|
|
8579
8728
|
return !1;
|
|
8580
|
-
const
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8588
|
-
|
|
8589
|
-
|
|
8590
|
-
|
|
8729
|
+
const block = selector_isSelectionExpanded.getFocusBlock({
|
|
8730
|
+
...snapshot,
|
|
8731
|
+
context: {
|
|
8732
|
+
...snapshot.context,
|
|
8733
|
+
selection: {
|
|
8734
|
+
anchor: {
|
|
8735
|
+
path: event.at,
|
|
8736
|
+
offset: 0
|
|
8737
|
+
},
|
|
8738
|
+
focus: {
|
|
8739
|
+
path: event.at,
|
|
8740
|
+
offset: 0
|
|
8741
|
+
}
|
|
8742
|
+
}
|
|
8591
8743
|
}
|
|
8592
|
-
};
|
|
8744
|
+
});
|
|
8745
|
+
return block ? {
|
|
8746
|
+
blockEndPoint: util_isSelectionCollapsed.getBlockEndPoint({
|
|
8747
|
+
context: snapshot.context,
|
|
8748
|
+
block
|
|
8749
|
+
})
|
|
8750
|
+
} : !1;
|
|
8593
8751
|
},
|
|
8594
8752
|
actions: [(_, {
|
|
8595
|
-
|
|
8753
|
+
blockEndPoint
|
|
8596
8754
|
}) => [behaviors_index.raise({
|
|
8597
8755
|
type: "select",
|
|
8598
|
-
at:
|
|
8756
|
+
at: {
|
|
8757
|
+
anchor: blockEndPoint,
|
|
8758
|
+
focus: blockEndPoint
|
|
8759
|
+
}
|
|
8599
8760
|
})]]
|
|
8600
8761
|
}), behaviors_index.defineBehavior({
|
|
8601
|
-
on: "select.
|
|
8762
|
+
on: "select.block",
|
|
8763
|
+
actions: [({
|
|
8764
|
+
event
|
|
8765
|
+
}) => [behaviors_index.raise({
|
|
8766
|
+
type: "select",
|
|
8767
|
+
at: {
|
|
8768
|
+
anchor: {
|
|
8769
|
+
path: event.at,
|
|
8770
|
+
offset: 0
|
|
8771
|
+
},
|
|
8772
|
+
focus: {
|
|
8773
|
+
path: event.at,
|
|
8774
|
+
offset: 0
|
|
8775
|
+
}
|
|
8776
|
+
}
|
|
8777
|
+
})]]
|
|
8778
|
+
}), behaviors_index.defineBehavior({
|
|
8779
|
+
on: "select.previous block",
|
|
8602
8780
|
guard: ({
|
|
8603
|
-
snapshot
|
|
8781
|
+
snapshot
|
|
8782
|
+
}) => {
|
|
8783
|
+
const previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
8784
|
+
return previousBlock ? {
|
|
8785
|
+
previousBlock
|
|
8786
|
+
} : !1;
|
|
8787
|
+
},
|
|
8788
|
+
actions: [({
|
|
8604
8789
|
event
|
|
8790
|
+
}, {
|
|
8791
|
+
previousBlock
|
|
8792
|
+
}) => [behaviors_index.raise({
|
|
8793
|
+
type: "select.block",
|
|
8794
|
+
at: previousBlock.path,
|
|
8795
|
+
select: event.select
|
|
8796
|
+
})]]
|
|
8797
|
+
}), behaviors_index.defineBehavior({
|
|
8798
|
+
on: "select.next block",
|
|
8799
|
+
guard: ({
|
|
8800
|
+
snapshot
|
|
8605
8801
|
}) => {
|
|
8606
8802
|
const nextBlock = selector_isSelectingEntireBlocks.getNextBlock(snapshot);
|
|
8607
|
-
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
context: snapshot.context,
|
|
8611
|
-
block: nextBlock
|
|
8612
|
-
}) : util_sliceBlocks.getBlockStartPoint({
|
|
8613
|
-
context: snapshot.context,
|
|
8614
|
-
block: nextBlock
|
|
8615
|
-
});
|
|
8616
|
-
return {
|
|
8617
|
-
selection: {
|
|
8618
|
-
anchor: point,
|
|
8619
|
-
focus: point
|
|
8620
|
-
}
|
|
8621
|
-
};
|
|
8803
|
+
return nextBlock ? {
|
|
8804
|
+
nextBlock
|
|
8805
|
+
} : !1;
|
|
8622
8806
|
},
|
|
8623
|
-
actions: [(
|
|
8624
|
-
|
|
8807
|
+
actions: [({
|
|
8808
|
+
event
|
|
8809
|
+
}, {
|
|
8810
|
+
nextBlock
|
|
8625
8811
|
}) => [behaviors_index.raise({
|
|
8626
|
-
type: "select",
|
|
8627
|
-
at:
|
|
8812
|
+
type: "select.block",
|
|
8813
|
+
at: nextBlock.path,
|
|
8814
|
+
select: event.select
|
|
8628
8815
|
})]]
|
|
8629
8816
|
})], abstractSerializeBehaviors = [behaviors_index.defineBehavior({
|
|
8630
8817
|
on: "serialize",
|
|
@@ -8998,7 +9185,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
8998
9185
|
function isSyntheticBehaviorEvent(event) {
|
|
8999
9186
|
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
9000
9187
|
}
|
|
9001
|
-
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"];
|
|
9188
|
+
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"];
|
|
9002
9189
|
function isAbstractBehaviorEvent(event) {
|
|
9003
9190
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
9004
9191
|
}
|