@portabletext/editor 2.8.3 → 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 +132 -124
- package/lib/_chunks-dts/behavior.types.action.d.ts +69 -61
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +361 -167
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +361 -167
- 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 +8 -8
- package/src/behaviors/behavior.abstract.insert.ts +258 -60
- package/src/behaviors/behavior.abstract.select.ts +81 -39
- package/src/behaviors/behavior.perform-event.ts +71 -61
- package/src/behaviors/behavior.types.action.ts +2 -1
- package/src/behaviors/behavior.types.event.ts +6 -0
- package/src/converters/converter.text-plain.test.ts +1 -2
- package/src/editor/create-editor.ts +7 -35
- package/src/editor/editor-machine.ts +54 -7
- package/src/editor/with-undo-step.ts +10 -0
- package/src/internal-utils/test-editor.tsx +51 -10
package/lib/index.cjs
CHANGED
|
@@ -3669,19 +3669,17 @@ function toInt(num) {
|
|
|
3669
3669
|
return parseInt(num, 10);
|
|
3670
3670
|
}
|
|
3671
3671
|
const CURRENT_UNDO_STEP = /* @__PURE__ */ new WeakMap();
|
|
3672
|
-
function withUndoStep(editor, fn) {
|
|
3673
|
-
const current = CURRENT_UNDO_STEP.get(editor);
|
|
3674
|
-
if (current) {
|
|
3675
|
-
fn();
|
|
3676
|
-
return;
|
|
3677
|
-
}
|
|
3678
|
-
CURRENT_UNDO_STEP.set(editor, current ?? {
|
|
3679
|
-
undoStepId: util_sliceBlocks.defaultKeyGenerator()
|
|
3680
|
-
}), fn(), CURRENT_UNDO_STEP.set(editor, void 0);
|
|
3681
|
-
}
|
|
3682
3672
|
function getCurrentUndoStepId(editor) {
|
|
3683
3673
|
return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
|
|
3684
3674
|
}
|
|
3675
|
+
function createUndoStep(editor) {
|
|
3676
|
+
CURRENT_UNDO_STEP.set(editor, {
|
|
3677
|
+
undoStepId: util_sliceBlocks.defaultKeyGenerator()
|
|
3678
|
+
});
|
|
3679
|
+
}
|
|
3680
|
+
function clearUndoStep(editor) {
|
|
3681
|
+
CURRENT_UNDO_STEP.set(editor, void 0);
|
|
3682
|
+
}
|
|
3685
3683
|
const debug$b = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
3686
3684
|
const state = SAVING.get(editor);
|
|
3687
3685
|
return state === void 0 ? !0 : state;
|
|
@@ -8242,28 +8240,104 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
8242
8240
|
on: "insert.blocks",
|
|
8243
8241
|
guard: ({
|
|
8244
8242
|
event
|
|
8245
|
-
}) =>
|
|
8243
|
+
}) => {
|
|
8244
|
+
const onlyBlock = event.blocks.length === 1 ? event.blocks.at(0) : void 0;
|
|
8245
|
+
return onlyBlock ? {
|
|
8246
|
+
onlyBlock
|
|
8247
|
+
} : !1;
|
|
8248
|
+
},
|
|
8246
8249
|
actions: [({
|
|
8247
8250
|
event
|
|
8248
|
-
}
|
|
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({
|
|
8249
8280
|
type: "insert.block",
|
|
8250
8281
|
block,
|
|
8251
8282
|
placement: index === 0 ? "before" : "after",
|
|
8252
|
-
select: event.
|
|
8253
|
-
}))
|
|
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
|
+
})]]]
|
|
8254
8300
|
}), behaviors_index.defineBehavior({
|
|
8255
8301
|
on: "insert.blocks",
|
|
8256
8302
|
guard: ({
|
|
8303
|
+
snapshot,
|
|
8257
8304
|
event
|
|
8258
|
-
}) =>
|
|
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
|
+
},
|
|
8259
8314
|
actions: [({
|
|
8315
|
+
snapshot,
|
|
8260
8316
|
event
|
|
8261
|
-
}
|
|
8317
|
+
}, {
|
|
8318
|
+
firstBlockKey,
|
|
8319
|
+
lastBlockKey
|
|
8320
|
+
}) => [...event.blocks.map((block, index) => behaviors_index.raise({
|
|
8262
8321
|
type: "insert.block",
|
|
8263
8322
|
block,
|
|
8264
8323
|
placement: "after",
|
|
8265
|
-
select: event.
|
|
8266
|
-
}))
|
|
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
|
+
})]]]
|
|
8267
8341
|
}), behaviors_index.defineBehavior({
|
|
8268
8342
|
on: "insert.blocks",
|
|
8269
8343
|
guard: ({
|
|
@@ -8273,49 +8347,123 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
8273
8347
|
if (event.placement !== "auto")
|
|
8274
8348
|
return !1;
|
|
8275
8349
|
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot);
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
|
|
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
|
+
};
|
|
8279
8358
|
},
|
|
8280
8359
|
actions: [({
|
|
8281
|
-
snapshot,
|
|
8282
8360
|
event
|
|
8283
8361
|
}, {
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
block: event.blocks[0],
|
|
8288
|
-
placement: "auto",
|
|
8289
|
-
select: event.select ?? "end"
|
|
8290
|
-
})] : 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({
|
|
8291
8365
|
type: "insert.block",
|
|
8292
8366
|
block,
|
|
8293
8367
|
placement: index === 0 ? "auto" : "after",
|
|
8294
|
-
select: event.
|
|
8295
|
-
}))
|
|
8296
|
-
type: "
|
|
8297
|
-
|
|
8298
|
-
|
|
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
|
+
}],
|
|
8299
8380
|
select: "end"
|
|
8300
|
-
})
|
|
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({
|
|
8301
8432
|
type: "insert.block",
|
|
8302
8433
|
block,
|
|
8303
8434
|
placement: "auto",
|
|
8304
|
-
select:
|
|
8435
|
+
select: "end"
|
|
8305
8436
|
})] : index === event.blocks.length - 1 ? [behaviors_index.raise({
|
|
8306
|
-
type: "select.next block",
|
|
8307
|
-
select: "start"
|
|
8308
|
-
}), behaviors_index.raise({
|
|
8309
8437
|
type: "insert.block",
|
|
8310
8438
|
block,
|
|
8439
|
+
placement: "after",
|
|
8440
|
+
select: "end"
|
|
8441
|
+
}), behaviors_index.raise({
|
|
8442
|
+
type: "insert.block",
|
|
8443
|
+
block: focusTextBlockAfter,
|
|
8311
8444
|
placement: "auto",
|
|
8312
|
-
select: event.select
|
|
8445
|
+
select: event.select === "end" ? "none" : "end"
|
|
8313
8446
|
})] : [behaviors_index.raise({
|
|
8314
8447
|
type: "insert.block",
|
|
8315
8448
|
block,
|
|
8316
8449
|
placement: "after",
|
|
8317
|
-
select:
|
|
8318
|
-
})])
|
|
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
|
+
})] : []]]
|
|
8319
8467
|
}), behaviors_index.defineBehavior({
|
|
8320
8468
|
on: "insert.blocks",
|
|
8321
8469
|
guard: ({
|
|
@@ -8571,62 +8719,99 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
8571
8719
|
to: nextBlock.path
|
|
8572
8720
|
})]]
|
|
8573
8721
|
})], abstractSelectBehaviors = [behaviors_index.defineBehavior({
|
|
8574
|
-
on: "select.
|
|
8722
|
+
on: "select.block",
|
|
8575
8723
|
guard: ({
|
|
8576
8724
|
snapshot,
|
|
8577
8725
|
event
|
|
8578
8726
|
}) => {
|
|
8579
|
-
|
|
8580
|
-
if (!previousBlock)
|
|
8727
|
+
if (event.select !== "end")
|
|
8581
8728
|
return !1;
|
|
8582
|
-
const
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8588
|
-
|
|
8589
|
-
|
|
8590
|
-
|
|
8591
|
-
|
|
8592
|
-
|
|
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
|
+
}
|
|
8593
8743
|
}
|
|
8594
|
-
};
|
|
8744
|
+
});
|
|
8745
|
+
return block ? {
|
|
8746
|
+
blockEndPoint: util_isSelectionCollapsed.getBlockEndPoint({
|
|
8747
|
+
context: snapshot.context,
|
|
8748
|
+
block
|
|
8749
|
+
})
|
|
8750
|
+
} : !1;
|
|
8595
8751
|
},
|
|
8596
8752
|
actions: [(_, {
|
|
8597
|
-
|
|
8753
|
+
blockEndPoint
|
|
8598
8754
|
}) => [behaviors_index.raise({
|
|
8599
8755
|
type: "select",
|
|
8600
|
-
at:
|
|
8756
|
+
at: {
|
|
8757
|
+
anchor: blockEndPoint,
|
|
8758
|
+
focus: blockEndPoint
|
|
8759
|
+
}
|
|
8601
8760
|
})]]
|
|
8602
8761
|
}), behaviors_index.defineBehavior({
|
|
8603
|
-
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",
|
|
8604
8780
|
guard: ({
|
|
8605
|
-
snapshot
|
|
8781
|
+
snapshot
|
|
8782
|
+
}) => {
|
|
8783
|
+
const previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
8784
|
+
return previousBlock ? {
|
|
8785
|
+
previousBlock
|
|
8786
|
+
} : !1;
|
|
8787
|
+
},
|
|
8788
|
+
actions: [({
|
|
8606
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
|
|
8607
8801
|
}) => {
|
|
8608
8802
|
const nextBlock = selector_isSelectingEntireBlocks.getNextBlock(snapshot);
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
context: snapshot.context,
|
|
8613
|
-
block: nextBlock
|
|
8614
|
-
}) : util_sliceBlocks.getBlockStartPoint({
|
|
8615
|
-
context: snapshot.context,
|
|
8616
|
-
block: nextBlock
|
|
8617
|
-
});
|
|
8618
|
-
return {
|
|
8619
|
-
selection: {
|
|
8620
|
-
anchor: point,
|
|
8621
|
-
focus: point
|
|
8622
|
-
}
|
|
8623
|
-
};
|
|
8803
|
+
return nextBlock ? {
|
|
8804
|
+
nextBlock
|
|
8805
|
+
} : !1;
|
|
8624
8806
|
},
|
|
8625
|
-
actions: [(
|
|
8626
|
-
|
|
8807
|
+
actions: [({
|
|
8808
|
+
event
|
|
8809
|
+
}, {
|
|
8810
|
+
nextBlock
|
|
8627
8811
|
}) => [behaviors_index.raise({
|
|
8628
|
-
type: "select",
|
|
8629
|
-
at:
|
|
8812
|
+
type: "select.block",
|
|
8813
|
+
at: nextBlock.path,
|
|
8814
|
+
select: event.select
|
|
8630
8815
|
})]]
|
|
8631
8816
|
})], abstractSerializeBehaviors = [behaviors_index.defineBehavior({
|
|
8632
8817
|
on: "serialize",
|
|
@@ -9000,7 +9185,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
9000
9185
|
function isSyntheticBehaviorEvent(event) {
|
|
9001
9186
|
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
9002
9187
|
}
|
|
9003
|
-
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"];
|
|
9004
9189
|
function isAbstractBehaviorEvent(event) {
|
|
9005
9190
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
9006
9191
|
}
|
|
@@ -9027,7 +9212,7 @@ function performEvent({
|
|
|
9027
9212
|
nativeEvent,
|
|
9028
9213
|
sendBack
|
|
9029
9214
|
}) {
|
|
9030
|
-
debug$6(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
9215
|
+
mode === "send" && !isNativeBehaviorEvent(event) && createUndoStep(editor), debug$6(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
9031
9216
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
9032
9217
|
if (behavior.on === "*")
|
|
9033
9218
|
return !0;
|
|
@@ -9035,7 +9220,7 @@ function performEvent({
|
|
|
9035
9220
|
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
9036
9221
|
});
|
|
9037
9222
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
9038
|
-
nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
9223
|
+
nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withApplyingBehaviorOperations(editor, () => {
|
|
9039
9224
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9040
9225
|
context: {
|
|
9041
9226
|
keyGenerator,
|
|
@@ -9079,63 +9264,63 @@ function performEvent({
|
|
|
9079
9264
|
}
|
|
9080
9265
|
if (actions.length !== 0) {
|
|
9081
9266
|
if (nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward"), actions.some((action) => action.type === "execute")) {
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
});
|
|
9089
|
-
} catch (error) {
|
|
9090
|
-
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9091
|
-
}
|
|
9092
|
-
continue;
|
|
9093
|
-
}
|
|
9094
|
-
if (action.type === "forward") {
|
|
9095
|
-
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9096
|
-
performEvent({
|
|
9097
|
-
mode: "forward",
|
|
9098
|
-
behaviors,
|
|
9099
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9100
|
-
event: action.event,
|
|
9101
|
-
editor,
|
|
9102
|
-
keyGenerator,
|
|
9103
|
-
schema: schema2,
|
|
9104
|
-
getSnapshot,
|
|
9105
|
-
nativeEvent,
|
|
9106
|
-
sendBack
|
|
9107
|
-
});
|
|
9108
|
-
continue;
|
|
9109
|
-
}
|
|
9110
|
-
if (action.type === "raise") {
|
|
9111
|
-
performEvent({
|
|
9112
|
-
mode: "raise",
|
|
9113
|
-
behaviors,
|
|
9114
|
-
remainingEventBehaviors: behaviors,
|
|
9115
|
-
event: action.event,
|
|
9116
|
-
editor,
|
|
9117
|
-
keyGenerator,
|
|
9118
|
-
schema: schema2,
|
|
9119
|
-
getSnapshot,
|
|
9120
|
-
nativeEvent,
|
|
9121
|
-
sendBack
|
|
9267
|
+
createUndoStep(editor);
|
|
9268
|
+
for (const action of actions) {
|
|
9269
|
+
if (action.type === "effect") {
|
|
9270
|
+
try {
|
|
9271
|
+
action.effect({
|
|
9272
|
+
send: sendBack
|
|
9122
9273
|
});
|
|
9123
|
-
|
|
9274
|
+
} catch (error) {
|
|
9275
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9124
9276
|
}
|
|
9277
|
+
continue;
|
|
9278
|
+
}
|
|
9279
|
+
if (action.type === "forward") {
|
|
9280
|
+
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9125
9281
|
performEvent({
|
|
9126
|
-
mode: "
|
|
9282
|
+
mode: "forward",
|
|
9127
9283
|
behaviors,
|
|
9128
|
-
remainingEventBehaviors:
|
|
9284
|
+
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9129
9285
|
event: action.event,
|
|
9130
9286
|
editor,
|
|
9131
9287
|
keyGenerator,
|
|
9132
9288
|
schema: schema2,
|
|
9133
9289
|
getSnapshot,
|
|
9134
|
-
nativeEvent
|
|
9290
|
+
nativeEvent,
|
|
9135
9291
|
sendBack
|
|
9136
9292
|
});
|
|
9293
|
+
continue;
|
|
9137
9294
|
}
|
|
9138
|
-
|
|
9295
|
+
if (action.type === "raise") {
|
|
9296
|
+
performEvent({
|
|
9297
|
+
mode: "raise",
|
|
9298
|
+
behaviors,
|
|
9299
|
+
remainingEventBehaviors: behaviors,
|
|
9300
|
+
event: action.event,
|
|
9301
|
+
editor,
|
|
9302
|
+
keyGenerator,
|
|
9303
|
+
schema: schema2,
|
|
9304
|
+
getSnapshot,
|
|
9305
|
+
nativeEvent,
|
|
9306
|
+
sendBack
|
|
9307
|
+
});
|
|
9308
|
+
continue;
|
|
9309
|
+
}
|
|
9310
|
+
performEvent({
|
|
9311
|
+
mode: "execute",
|
|
9312
|
+
behaviors,
|
|
9313
|
+
remainingEventBehaviors: [],
|
|
9314
|
+
event: action.event,
|
|
9315
|
+
editor,
|
|
9316
|
+
keyGenerator,
|
|
9317
|
+
schema: schema2,
|
|
9318
|
+
getSnapshot,
|
|
9319
|
+
nativeEvent: void 0,
|
|
9320
|
+
sendBack
|
|
9321
|
+
});
|
|
9322
|
+
}
|
|
9323
|
+
clearUndoStep(editor);
|
|
9139
9324
|
continue;
|
|
9140
9325
|
}
|
|
9141
9326
|
for (const action of actions) {
|
|
@@ -9187,7 +9372,7 @@ function performEvent({
|
|
|
9187
9372
|
break;
|
|
9188
9373
|
}
|
|
9189
9374
|
}
|
|
9190
|
-
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
9375
|
+
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withApplyingBehaviorOperations(editor, () => {
|
|
9191
9376
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9192
9377
|
context: {
|
|
9193
9378
|
keyGenerator,
|
|
@@ -9268,7 +9453,44 @@ function createEditorSnapshot({
|
|
|
9268
9453
|
decoratorState: editor.decoratorState
|
|
9269
9454
|
};
|
|
9270
9455
|
}
|
|
9271
|
-
const debug$5 = debugWithName("editor machine")
|
|
9456
|
+
const debug$5 = debugWithName("editor machine");
|
|
9457
|
+
function rerouteExternalBehaviorEvent({
|
|
9458
|
+
event,
|
|
9459
|
+
slateEditor
|
|
9460
|
+
}) {
|
|
9461
|
+
switch (event.type) {
|
|
9462
|
+
case "blur":
|
|
9463
|
+
return {
|
|
9464
|
+
type: "blur",
|
|
9465
|
+
editor: slateEditor
|
|
9466
|
+
};
|
|
9467
|
+
case "focus":
|
|
9468
|
+
return {
|
|
9469
|
+
type: "focus",
|
|
9470
|
+
editor: slateEditor
|
|
9471
|
+
};
|
|
9472
|
+
case "insert.block object":
|
|
9473
|
+
return {
|
|
9474
|
+
type: "behavior event",
|
|
9475
|
+
behaviorEvent: {
|
|
9476
|
+
type: "insert.block",
|
|
9477
|
+
block: {
|
|
9478
|
+
_type: event.blockObject.name,
|
|
9479
|
+
...event.blockObject.value ?? {}
|
|
9480
|
+
},
|
|
9481
|
+
placement: event.placement
|
|
9482
|
+
},
|
|
9483
|
+
editor: slateEditor
|
|
9484
|
+
};
|
|
9485
|
+
default:
|
|
9486
|
+
return {
|
|
9487
|
+
type: "behavior event",
|
|
9488
|
+
behaviorEvent: event,
|
|
9489
|
+
editor: slateEditor
|
|
9490
|
+
};
|
|
9491
|
+
}
|
|
9492
|
+
}
|
|
9493
|
+
const editorMachine = xstate.setup({
|
|
9272
9494
|
types: {
|
|
9273
9495
|
context: {},
|
|
9274
9496
|
events: {},
|
|
@@ -9370,7 +9592,7 @@ const debug$5 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
9370
9592
|
try {
|
|
9371
9593
|
const behaviors = [...context.behaviors.values()].map((config) => config.behavior);
|
|
9372
9594
|
performEvent({
|
|
9373
|
-
mode: "
|
|
9595
|
+
mode: "send",
|
|
9374
9596
|
behaviors,
|
|
9375
9597
|
remainingEventBehaviors: behaviors,
|
|
9376
9598
|
event: event.behaviorEvent,
|
|
@@ -9392,11 +9614,10 @@ const debug$5 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
9392
9614
|
self.send(eventSentBack);
|
|
9393
9615
|
return;
|
|
9394
9616
|
}
|
|
9395
|
-
self.send({
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
});
|
|
9617
|
+
self.send(rerouteExternalBehaviorEvent({
|
|
9618
|
+
event: eventSentBack,
|
|
9619
|
+
slateEditor: event.editor
|
|
9620
|
+
}));
|
|
9400
9621
|
}
|
|
9401
9622
|
});
|
|
9402
9623
|
} catch (error) {
|
|
@@ -11342,38 +11563,11 @@ function createInternalEditor(config) {
|
|
|
11342
11563
|
case "update maxBlocks":
|
|
11343
11564
|
editorActor.send(event);
|
|
11344
11565
|
break;
|
|
11345
|
-
case "blur":
|
|
11346
|
-
editorActor.send({
|
|
11347
|
-
type: "blur",
|
|
11348
|
-
editor: slateEditor.instance
|
|
11349
|
-
});
|
|
11350
|
-
break;
|
|
11351
|
-
case "focus":
|
|
11352
|
-
editorActor.send({
|
|
11353
|
-
type: "focus",
|
|
11354
|
-
editor: slateEditor.instance
|
|
11355
|
-
});
|
|
11356
|
-
break;
|
|
11357
|
-
case "insert.block object":
|
|
11358
|
-
editorActor.send({
|
|
11359
|
-
type: "behavior event",
|
|
11360
|
-
behaviorEvent: {
|
|
11361
|
-
type: "insert.block",
|
|
11362
|
-
block: {
|
|
11363
|
-
_type: event.blockObject.name,
|
|
11364
|
-
...event.blockObject.value ?? {}
|
|
11365
|
-
},
|
|
11366
|
-
placement: event.placement
|
|
11367
|
-
},
|
|
11368
|
-
editor: slateEditor.instance
|
|
11369
|
-
});
|
|
11370
|
-
break;
|
|
11371
11566
|
default:
|
|
11372
|
-
editorActor.send({
|
|
11373
|
-
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
});
|
|
11567
|
+
editorActor.send(rerouteExternalBehaviorEvent({
|
|
11568
|
+
event,
|
|
11569
|
+
slateEditor: slateEditor.instance
|
|
11570
|
+
}));
|
|
11377
11571
|
}
|
|
11378
11572
|
},
|
|
11379
11573
|
on: (event, listener) => relayActor.on(event, (event2) => {
|