@portabletext/editor 2.12.0 → 2.12.2
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-cjs/selector.is-selecting-entire-blocks.cjs +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.ts +9 -9
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/index.cjs +144 -68
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +144 -68
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +3 -3
- package/lib/utils/index.d.ts +2 -2
- package/package.json +11 -5
- package/src/behaviors/behavior.abstract.keyboard.ts +100 -3
- package/src/behaviors/behavior.perform-event.ts +19 -1
- package/src/internal-utils/slate-utils.test.tsx +1 -1
- package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +1 -1
- package/src/plugins/plugin.markdown.test.tsx +1 -1
- package/src/selectors/selector.get-mark-state.test.ts +76 -0
- package/src/selectors/selector.get-mark-state.ts +1 -1
- package/src/test/_exports/index.ts +1 -0
- package/src/test/gherkin-parameter-types.ts +102 -0
- package/src/test/index.ts +1 -0
- package/src/test/vitest/_exports/index.ts +1 -0
- package/src/test/vitest/index.ts +3 -0
- package/src/test/vitest/step-context.ts +11 -0
- package/src/test/vitest/step-definitions.tsx +779 -0
- package/src/{internal-utils → test/vitest}/test-editor.tsx +8 -5
package/lib/index.cjs
CHANGED
|
@@ -8687,7 +8687,15 @@ const abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
|
|
|
8687
8687
|
marks: [...event.decorators ?? [], ...markDefs.map((markDef) => markDef._key)]
|
|
8688
8688
|
}
|
|
8689
8689
|
})]]
|
|
8690
|
-
})],
|
|
8690
|
+
})], shiftLeft = keyboardShortcuts.createKeyboardShortcut({
|
|
8691
|
+
default: [{
|
|
8692
|
+
key: "ArrowLeft",
|
|
8693
|
+
shift: !0,
|
|
8694
|
+
meta: !1,
|
|
8695
|
+
ctrl: !1,
|
|
8696
|
+
alt: !1
|
|
8697
|
+
}]
|
|
8698
|
+
}), abstractKeyboardBehaviors = [
|
|
8691
8699
|
/**
|
|
8692
8700
|
* Allow raising an `insert.break` event when pressing Enter on an inline
|
|
8693
8701
|
* object.
|
|
@@ -8702,6 +8710,20 @@ const abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
|
|
|
8702
8710
|
type: "insert.break"
|
|
8703
8711
|
})]]
|
|
8704
8712
|
}),
|
|
8713
|
+
/**
|
|
8714
|
+
* On Firefox, Enter might collapse the selection. To mitigate this, we
|
|
8715
|
+
* `raise` an `insert.break` event manually.
|
|
8716
|
+
*/
|
|
8717
|
+
behaviors_index.defineBehavior({
|
|
8718
|
+
on: "keyboard.keydown",
|
|
8719
|
+
guard: ({
|
|
8720
|
+
snapshot,
|
|
8721
|
+
event
|
|
8722
|
+
}) => defaultKeyboardShortcuts.break.guard(event.originEvent) && selector_isSelectionExpanded.isSelectionExpanded(snapshot),
|
|
8723
|
+
actions: [() => [behaviors_index.raise({
|
|
8724
|
+
type: "insert.break"
|
|
8725
|
+
})]]
|
|
8726
|
+
}),
|
|
8705
8727
|
/**
|
|
8706
8728
|
* On WebKit, Shift+Enter results in an `insertParagraph` input event rather
|
|
8707
8729
|
* than an `insertLineBreak` input event. This Behavior makes sure we catch
|
|
@@ -8739,6 +8761,58 @@ const abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
|
|
|
8739
8761
|
actions: [() => [behaviors_index.raise({
|
|
8740
8762
|
type: "history.redo"
|
|
8741
8763
|
})]]
|
|
8764
|
+
}),
|
|
8765
|
+
/**
|
|
8766
|
+
* Fix edge case where Shift+ArrowLeft didn't reduce a selection hanging
|
|
8767
|
+
* onto an empty text block.
|
|
8768
|
+
*/
|
|
8769
|
+
behaviors_index.defineBehavior({
|
|
8770
|
+
on: "keyboard.keydown",
|
|
8771
|
+
guard: ({
|
|
8772
|
+
snapshot,
|
|
8773
|
+
event
|
|
8774
|
+
}) => {
|
|
8775
|
+
if (!snapshot.context.selection || !shiftLeft.guard(event.originEvent))
|
|
8776
|
+
return !1;
|
|
8777
|
+
const focusBlock = selector_isSelectionExpanded.getFocusBlock(snapshot);
|
|
8778
|
+
if (!focusBlock)
|
|
8779
|
+
return !1;
|
|
8780
|
+
const previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock({
|
|
8781
|
+
...snapshot,
|
|
8782
|
+
context: {
|
|
8783
|
+
...snapshot.context,
|
|
8784
|
+
selection: {
|
|
8785
|
+
anchor: {
|
|
8786
|
+
path: focusBlock.path,
|
|
8787
|
+
offset: 0
|
|
8788
|
+
},
|
|
8789
|
+
focus: {
|
|
8790
|
+
path: focusBlock.path,
|
|
8791
|
+
offset: 0
|
|
8792
|
+
}
|
|
8793
|
+
}
|
|
8794
|
+
}
|
|
8795
|
+
});
|
|
8796
|
+
return previousBlock && schema.isTextBlock(snapshot.context, focusBlock.node) && snapshot.context.selection.focus.offset === 0 && util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusBlock.node) ? {
|
|
8797
|
+
previousBlock,
|
|
8798
|
+
selection: snapshot.context.selection
|
|
8799
|
+
} : !1;
|
|
8800
|
+
},
|
|
8801
|
+
actions: [({
|
|
8802
|
+
snapshot
|
|
8803
|
+
}, {
|
|
8804
|
+
previousBlock,
|
|
8805
|
+
selection
|
|
8806
|
+
}) => [behaviors_index.raise({
|
|
8807
|
+
type: "select",
|
|
8808
|
+
at: {
|
|
8809
|
+
anchor: selection.anchor,
|
|
8810
|
+
focus: util_isSelectionCollapsed.getBlockEndPoint({
|
|
8811
|
+
context: snapshot.context,
|
|
8812
|
+
block: previousBlock
|
|
8813
|
+
})
|
|
8814
|
+
}
|
|
8815
|
+
})]]
|
|
8742
8816
|
})
|
|
8743
8817
|
], abstractListItemBehaviors = [behaviors_index.defineBehavior({
|
|
8744
8818
|
on: "list item.add",
|
|
@@ -9399,86 +9473,88 @@ function performEvent({
|
|
|
9399
9473
|
} catch (error) {
|
|
9400
9474
|
console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error.message}`));
|
|
9401
9475
|
}
|
|
9402
|
-
if (shouldRun)
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
}
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
}
|
|
9432
|
-
continue;
|
|
9433
|
-
}
|
|
9434
|
-
if (action.type === "forward") {
|
|
9435
|
-
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9436
|
-
performEvent({
|
|
9437
|
-
mode: mode === "execute" ? "execute" : "forward",
|
|
9438
|
-
behaviors,
|
|
9439
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9440
|
-
event: action.event,
|
|
9441
|
-
editor,
|
|
9442
|
-
keyGenerator,
|
|
9443
|
-
schema: schema2,
|
|
9444
|
-
getSnapshot,
|
|
9445
|
-
nativeEvent,
|
|
9446
|
-
sendBack
|
|
9447
|
-
});
|
|
9448
|
-
continue;
|
|
9449
|
-
}
|
|
9450
|
-
if (action.type === "raise") {
|
|
9451
|
-
performEvent({
|
|
9452
|
-
mode: mode === "execute" ? "execute" : "raise",
|
|
9453
|
-
behaviors,
|
|
9454
|
-
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9455
|
-
event: action.event,
|
|
9456
|
-
editor,
|
|
9457
|
-
keyGenerator,
|
|
9458
|
-
schema: schema2,
|
|
9459
|
-
getSnapshot,
|
|
9460
|
-
nativeEvent,
|
|
9461
|
-
sendBack
|
|
9476
|
+
if (!shouldRun)
|
|
9477
|
+
continue;
|
|
9478
|
+
defaultBehaviorOverwritten = !0, eventBehavior.actions.length === 0 && (nativeEventPrevented = !0);
|
|
9479
|
+
let actionSetIndex = -1;
|
|
9480
|
+
for (const actionSet of eventBehavior.actions) {
|
|
9481
|
+
actionSetIndex++;
|
|
9482
|
+
const actionsSnapshot = getSnapshot();
|
|
9483
|
+
let actions = [];
|
|
9484
|
+
try {
|
|
9485
|
+
actions = actionSet({
|
|
9486
|
+
snapshot: actionsSnapshot,
|
|
9487
|
+
event,
|
|
9488
|
+
dom: createEditorDom(sendBack, editor)
|
|
9489
|
+
}, shouldRun);
|
|
9490
|
+
} catch (error) {
|
|
9491
|
+
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
9492
|
+
}
|
|
9493
|
+
if (actions.length === 0)
|
|
9494
|
+
continue;
|
|
9495
|
+
nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
|
|
9496
|
+
let undoStepCreated = !1;
|
|
9497
|
+
actionSetIndex > 0 && (createUndoStep(editor), undoStepCreated = !0), !undoStepCreated && actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
|
|
9498
|
+
const actionTypes = actions.map((action) => action.type), uniqueActionTypes = new Set(actionTypes), raiseGroup = actionTypes.length > 1 && uniqueActionTypes.size === 1 && uniqueActionTypes.has("raise"), executeGroup = actionTypes.length > 1 && uniqueActionTypes.size === 1 && uniqueActionTypes.has("execute");
|
|
9499
|
+
withoutNormalizingConditional(editor, () => raiseGroup || executeGroup, () => {
|
|
9500
|
+
for (const action of actions) {
|
|
9501
|
+
if (action.type === "effect") {
|
|
9502
|
+
try {
|
|
9503
|
+
action.effect({
|
|
9504
|
+
send: sendBack
|
|
9462
9505
|
});
|
|
9463
|
-
|
|
9506
|
+
} catch (error) {
|
|
9507
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9464
9508
|
}
|
|
9509
|
+
continue;
|
|
9510
|
+
}
|
|
9511
|
+
if (action.type === "forward") {
|
|
9512
|
+
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9465
9513
|
performEvent({
|
|
9466
|
-
mode: "execute",
|
|
9514
|
+
mode: mode === "execute" ? "execute" : "forward",
|
|
9467
9515
|
behaviors,
|
|
9468
|
-
remainingEventBehaviors:
|
|
9516
|
+
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9469
9517
|
event: action.event,
|
|
9470
9518
|
editor,
|
|
9471
9519
|
keyGenerator,
|
|
9472
9520
|
schema: schema2,
|
|
9473
9521
|
getSnapshot,
|
|
9474
|
-
nativeEvent
|
|
9522
|
+
nativeEvent,
|
|
9475
9523
|
sendBack
|
|
9476
9524
|
});
|
|
9525
|
+
continue;
|
|
9477
9526
|
}
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9527
|
+
if (action.type === "raise") {
|
|
9528
|
+
performEvent({
|
|
9529
|
+
mode: mode === "execute" ? "execute" : "raise",
|
|
9530
|
+
behaviors,
|
|
9531
|
+
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9532
|
+
event: action.event,
|
|
9533
|
+
editor,
|
|
9534
|
+
keyGenerator,
|
|
9535
|
+
schema: schema2,
|
|
9536
|
+
getSnapshot,
|
|
9537
|
+
nativeEvent,
|
|
9538
|
+
sendBack
|
|
9539
|
+
});
|
|
9540
|
+
continue;
|
|
9541
|
+
}
|
|
9542
|
+
performEvent({
|
|
9543
|
+
mode: "execute",
|
|
9544
|
+
behaviors,
|
|
9545
|
+
remainingEventBehaviors: [],
|
|
9546
|
+
event: action.event,
|
|
9547
|
+
editor,
|
|
9548
|
+
keyGenerator,
|
|
9549
|
+
schema: schema2,
|
|
9550
|
+
getSnapshot,
|
|
9551
|
+
nativeEvent: void 0,
|
|
9552
|
+
sendBack
|
|
9553
|
+
});
|
|
9554
|
+
}
|
|
9555
|
+
}), undoStepCreated && clearUndoStep(editor);
|
|
9481
9556
|
}
|
|
9557
|
+
break;
|
|
9482
9558
|
}
|
|
9483
9559
|
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9484
9560
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|