@portabletext/editor 2.12.1 → 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/index.js CHANGED
@@ -8739,6 +8739,20 @@ const abstractAnnotationBehaviors = [defineBehavior({
8739
8739
  type: "insert.break"
8740
8740
  })]]
8741
8741
  }),
8742
+ /**
8743
+ * On Firefox, Enter might collapse the selection. To mitigate this, we
8744
+ * `raise` an `insert.break` event manually.
8745
+ */
8746
+ defineBehavior({
8747
+ on: "keyboard.keydown",
8748
+ guard: ({
8749
+ snapshot,
8750
+ event
8751
+ }) => defaultKeyboardShortcuts.break.guard(event.originEvent) && isSelectionExpanded(snapshot),
8752
+ actions: [() => [raise({
8753
+ type: "insert.break"
8754
+ })]]
8755
+ }),
8742
8756
  /**
8743
8757
  * On WebKit, Shift+Enter results in an `insertParagraph` input event rather
8744
8758
  * than an `insertLineBreak` input event. This Behavior makes sure we catch
@@ -9488,86 +9502,88 @@ function performEvent({
9488
9502
  } catch (error) {
9489
9503
  console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error.message}`));
9490
9504
  }
9491
- if (shouldRun) {
9492
- defaultBehaviorOverwritten = !0, eventBehavior.actions.length === 0 && (nativeEventPrevented = !0);
9493
- for (const actionSet of eventBehavior.actions) {
9494
- const actionsSnapshot = getSnapshot();
9495
- let actions = [];
9496
- try {
9497
- actions = actionSet({
9498
- snapshot: actionsSnapshot,
9499
- event,
9500
- dom: createEditorDom(sendBack, editor)
9501
- }, shouldRun);
9502
- } catch (error) {
9503
- console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
9504
- }
9505
- if (actions.length === 0)
9506
- continue;
9507
- nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
9508
- let undoStepCreated = !1;
9509
- actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
9510
- 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");
9511
- withoutNormalizingConditional(editor, () => raiseGroup || executeGroup, () => {
9512
- for (const action of actions) {
9513
- if (action.type === "effect") {
9514
- try {
9515
- action.effect({
9516
- send: sendBack
9517
- });
9518
- } catch (error) {
9519
- console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
9520
- }
9521
- continue;
9522
- }
9523
- if (action.type === "forward") {
9524
- const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
9525
- performEvent({
9526
- mode: mode === "execute" ? "execute" : "forward",
9527
- behaviors,
9528
- remainingEventBehaviors: remainingEventBehaviors2,
9529
- event: action.event,
9530
- editor,
9531
- keyGenerator,
9532
- schema,
9533
- getSnapshot,
9534
- nativeEvent,
9535
- sendBack
9536
- });
9537
- continue;
9538
- }
9539
- if (action.type === "raise") {
9540
- performEvent({
9541
- mode: mode === "execute" ? "execute" : "raise",
9542
- behaviors,
9543
- remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
9544
- event: action.event,
9545
- editor,
9546
- keyGenerator,
9547
- schema,
9548
- getSnapshot,
9549
- nativeEvent,
9550
- sendBack
9505
+ if (!shouldRun)
9506
+ continue;
9507
+ defaultBehaviorOverwritten = !0, eventBehavior.actions.length === 0 && (nativeEventPrevented = !0);
9508
+ let actionSetIndex = -1;
9509
+ for (const actionSet of eventBehavior.actions) {
9510
+ actionSetIndex++;
9511
+ const actionsSnapshot = getSnapshot();
9512
+ let actions = [];
9513
+ try {
9514
+ actions = actionSet({
9515
+ snapshot: actionsSnapshot,
9516
+ event,
9517
+ dom: createEditorDom(sendBack, editor)
9518
+ }, shouldRun);
9519
+ } catch (error) {
9520
+ console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
9521
+ }
9522
+ if (actions.length === 0)
9523
+ continue;
9524
+ nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
9525
+ let undoStepCreated = !1;
9526
+ actionSetIndex > 0 && (createUndoStep(editor), undoStepCreated = !0), !undoStepCreated && actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
9527
+ 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");
9528
+ withoutNormalizingConditional(editor, () => raiseGroup || executeGroup, () => {
9529
+ for (const action of actions) {
9530
+ if (action.type === "effect") {
9531
+ try {
9532
+ action.effect({
9533
+ send: sendBack
9551
9534
  });
9552
- continue;
9535
+ } catch (error) {
9536
+ console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
9553
9537
  }
9538
+ continue;
9539
+ }
9540
+ if (action.type === "forward") {
9541
+ const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
9554
9542
  performEvent({
9555
- mode: "execute",
9543
+ mode: mode === "execute" ? "execute" : "forward",
9556
9544
  behaviors,
9557
- remainingEventBehaviors: [],
9545
+ remainingEventBehaviors: remainingEventBehaviors2,
9558
9546
  event: action.event,
9559
9547
  editor,
9560
9548
  keyGenerator,
9561
9549
  schema,
9562
9550
  getSnapshot,
9563
- nativeEvent: void 0,
9551
+ nativeEvent,
9564
9552
  sendBack
9565
9553
  });
9554
+ continue;
9566
9555
  }
9567
- }), undoStepCreated && clearUndoStep(editor);
9568
- }
9569
- break;
9556
+ if (action.type === "raise") {
9557
+ performEvent({
9558
+ mode: mode === "execute" ? "execute" : "raise",
9559
+ behaviors,
9560
+ remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
9561
+ event: action.event,
9562
+ editor,
9563
+ keyGenerator,
9564
+ schema,
9565
+ getSnapshot,
9566
+ nativeEvent,
9567
+ sendBack
9568
+ });
9569
+ continue;
9570
+ }
9571
+ performEvent({
9572
+ mode: "execute",
9573
+ behaviors,
9574
+ remainingEventBehaviors: [],
9575
+ event: action.event,
9576
+ editor,
9577
+ keyGenerator,
9578
+ schema,
9579
+ getSnapshot,
9580
+ nativeEvent: void 0,
9581
+ sendBack
9582
+ });
9583
+ }
9584
+ }), undoStepCreated && clearUndoStep(editor);
9570
9585
  }
9586
+ break;
9571
9587
  }
9572
9588
  !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
9573
9589
  debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({