@portabletext/editor 2.12.1 → 2.12.3

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
@@ -1734,7 +1734,7 @@ function createDecorate(schema, slateEditor) {
1734
1734
  };
1735
1735
  }
1736
1736
  const RelayActorContext = createContext({}), debug$d = debugWithName("component:Editable"), PortableTextEditable = forwardRef(function(props, forwardedRef) {
1737
- const $ = c(172);
1737
+ const $ = c(171);
1738
1738
  let hotkeys, onBeforeInput, onBlur, onClick, onCopy, onCut, onDrag, onDragEnd, onDragEnter, onDragLeave, onDragOver, onDragStart, onDrop, onFocus, onPaste, propsSelection, rangeDecorations, renderAnnotation, renderBlock, renderChild, renderDecorator, renderListItem, renderPlaceholder, renderStyle, restProps, scrollSelectionIntoView, spellCheck;
1739
1739
  $[0] !== props ? ({
1740
1740
  hotkeys,
@@ -2271,50 +2271,16 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
2271
2271
  }, $[140] = editorActor, $[141] = onDragLeave, $[142] = slateEditor, $[143] = t34) : t34 = $[143];
2272
2272
  const handleDragLeave = t34;
2273
2273
  let t35;
2274
- $[144] !== forwardedRef || $[145] !== slateEditor ? (t35 = (node) => {
2275
- if (typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node), node) {
2276
- const mutationObserver = new MutationObserver(() => {
2277
- validateSelection(slateEditor, node);
2278
- });
2279
- return mutationObserver.observe(node, {
2280
- attributeOldValue: !1,
2281
- attributes: !1,
2282
- characterData: !1,
2283
- childList: !0,
2284
- subtree: !0
2285
- }), () => {
2286
- mutationObserver.disconnect();
2287
- };
2288
- }
2289
- }, $[144] = forwardedRef, $[145] = slateEditor, $[146] = t35) : t35 = $[146];
2274
+ $[144] !== forwardedRef ? (t35 = (node) => {
2275
+ typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node);
2276
+ }, $[144] = forwardedRef, $[145] = t35) : t35 = $[145];
2290
2277
  const callbackRef = t35;
2291
2278
  if (!portableTextEditor)
2292
2279
  return null;
2293
2280
  let t36;
2294
- return $[147] !== callbackRef || $[148] !== decorate || $[149] !== handleClick || $[150] !== handleCopy || $[151] !== handleCut || $[152] !== handleDrag || $[153] !== handleDragEnd || $[154] !== handleDragEnter || $[155] !== handleDragLeave || $[156] !== handleDragOver || $[157] !== handleDragStart || $[158] !== handleDrop || $[159] !== handleKeyDown || $[160] !== handleKeyUp || $[161] !== handleOnBeforeInput || $[162] !== handleOnBlur || $[163] !== handleOnFocus || $[164] !== handlePaste || $[165] !== hasInvalidValue || $[166] !== readOnly || $[167] !== renderElement || $[168] !== renderLeaf || $[169] !== restProps || $[170] !== scrollSelectionIntoViewToSlate ? (t36 = hasInvalidValue ? null : /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderPlaceholder: void 0, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToSlate }), $[147] = callbackRef, $[148] = decorate, $[149] = handleClick, $[150] = handleCopy, $[151] = handleCut, $[152] = handleDrag, $[153] = handleDragEnd, $[154] = handleDragEnter, $[155] = handleDragLeave, $[156] = handleDragOver, $[157] = handleDragStart, $[158] = handleDrop, $[159] = handleKeyDown, $[160] = handleKeyUp, $[161] = handleOnBeforeInput, $[162] = handleOnBlur, $[163] = handleOnFocus, $[164] = handlePaste, $[165] = hasInvalidValue, $[166] = readOnly, $[167] = renderElement, $[168] = renderLeaf, $[169] = restProps, $[170] = scrollSelectionIntoViewToSlate, $[171] = t36) : t36 = $[171], t36;
2281
+ return $[146] !== callbackRef || $[147] !== decorate || $[148] !== handleClick || $[149] !== handleCopy || $[150] !== handleCut || $[151] !== handleDrag || $[152] !== handleDragEnd || $[153] !== handleDragEnter || $[154] !== handleDragLeave || $[155] !== handleDragOver || $[156] !== handleDragStart || $[157] !== handleDrop || $[158] !== handleKeyDown || $[159] !== handleKeyUp || $[160] !== handleOnBeforeInput || $[161] !== handleOnBlur || $[162] !== handleOnFocus || $[163] !== handlePaste || $[164] !== hasInvalidValue || $[165] !== readOnly || $[166] !== renderElement || $[167] !== renderLeaf || $[168] !== restProps || $[169] !== scrollSelectionIntoViewToSlate ? (t36 = hasInvalidValue ? null : /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderPlaceholder: void 0, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToSlate }), $[146] = callbackRef, $[147] = decorate, $[148] = handleClick, $[149] = handleCopy, $[150] = handleCut, $[151] = handleDrag, $[152] = handleDragEnd, $[153] = handleDragEnter, $[154] = handleDragLeave, $[155] = handleDragOver, $[156] = handleDragStart, $[157] = handleDrop, $[158] = handleKeyDown, $[159] = handleKeyUp, $[160] = handleOnBeforeInput, $[161] = handleOnBlur, $[162] = handleOnFocus, $[163] = handlePaste, $[164] = hasInvalidValue, $[165] = readOnly, $[166] = renderElement, $[167] = renderLeaf, $[168] = restProps, $[169] = scrollSelectionIntoViewToSlate, $[170] = t36) : t36 = $[170], t36;
2295
2282
  });
2296
2283
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
2297
- function validateSelection(slateEditor, activeElement) {
2298
- if (!slateEditor.selection)
2299
- return;
2300
- let root;
2301
- try {
2302
- root = ReactEditor.findDocumentOrShadowRoot(slateEditor);
2303
- } catch {
2304
- }
2305
- if (!root || activeElement !== root.activeElement)
2306
- return;
2307
- const domSelection = ReactEditor.getWindow(slateEditor).getSelection();
2308
- if (!domSelection || domSelection.rangeCount === 0)
2309
- return;
2310
- const existingDOMRange = domSelection.getRangeAt(0);
2311
- try {
2312
- const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
2313
- (newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug$d("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
2314
- } catch {
2315
- debug$d("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
2316
- }
2317
- }
2318
2284
  function _temp(s) {
2319
2285
  return s.matches({
2320
2286
  "edit mode": "read only"
@@ -8739,6 +8705,20 @@ const abstractAnnotationBehaviors = [defineBehavior({
8739
8705
  type: "insert.break"
8740
8706
  })]]
8741
8707
  }),
8708
+ /**
8709
+ * On Firefox, Enter might collapse the selection. To mitigate this, we
8710
+ * `raise` an `insert.break` event manually.
8711
+ */
8712
+ defineBehavior({
8713
+ on: "keyboard.keydown",
8714
+ guard: ({
8715
+ snapshot,
8716
+ event
8717
+ }) => defaultKeyboardShortcuts.break.guard(event.originEvent) && isSelectionExpanded(snapshot),
8718
+ actions: [() => [raise({
8719
+ type: "insert.break"
8720
+ })]]
8721
+ }),
8742
8722
  /**
8743
8723
  * On WebKit, Shift+Enter results in an `insertParagraph` input event rather
8744
8724
  * than an `insertLineBreak` input event. This Behavior makes sure we catch
@@ -9488,86 +9468,88 @@ function performEvent({
9488
9468
  } catch (error) {
9489
9469
  console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error.message}`));
9490
9470
  }
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
9471
+ if (!shouldRun)
9472
+ continue;
9473
+ defaultBehaviorOverwritten = !0, eventBehavior.actions.length === 0 && (nativeEventPrevented = !0);
9474
+ let actionSetIndex = -1;
9475
+ for (const actionSet of eventBehavior.actions) {
9476
+ actionSetIndex++;
9477
+ const actionsSnapshot = getSnapshot();
9478
+ let actions = [];
9479
+ try {
9480
+ actions = actionSet({
9481
+ snapshot: actionsSnapshot,
9482
+ event,
9483
+ dom: createEditorDom(sendBack, editor)
9484
+ }, shouldRun);
9485
+ } catch (error) {
9486
+ console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
9487
+ }
9488
+ if (actions.length === 0)
9489
+ continue;
9490
+ nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
9491
+ let undoStepCreated = !1;
9492
+ actionSetIndex > 0 && (createUndoStep(editor), undoStepCreated = !0), !undoStepCreated && actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
9493
+ 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");
9494
+ withoutNormalizingConditional(editor, () => raiseGroup || executeGroup, () => {
9495
+ for (const action of actions) {
9496
+ if (action.type === "effect") {
9497
+ try {
9498
+ action.effect({
9499
+ send: sendBack
9551
9500
  });
9552
- continue;
9501
+ } catch (error) {
9502
+ console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
9553
9503
  }
9504
+ continue;
9505
+ }
9506
+ if (action.type === "forward") {
9507
+ const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
9554
9508
  performEvent({
9555
- mode: "execute",
9509
+ mode: mode === "execute" ? "execute" : "forward",
9556
9510
  behaviors,
9557
- remainingEventBehaviors: [],
9511
+ remainingEventBehaviors: remainingEventBehaviors2,
9558
9512
  event: action.event,
9559
9513
  editor,
9560
9514
  keyGenerator,
9561
9515
  schema,
9562
9516
  getSnapshot,
9563
- nativeEvent: void 0,
9517
+ nativeEvent,
9564
9518
  sendBack
9565
9519
  });
9520
+ continue;
9566
9521
  }
9567
- }), undoStepCreated && clearUndoStep(editor);
9568
- }
9569
- break;
9522
+ if (action.type === "raise") {
9523
+ performEvent({
9524
+ mode: mode === "execute" ? "execute" : "raise",
9525
+ behaviors,
9526
+ remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
9527
+ event: action.event,
9528
+ editor,
9529
+ keyGenerator,
9530
+ schema,
9531
+ getSnapshot,
9532
+ nativeEvent,
9533
+ sendBack
9534
+ });
9535
+ continue;
9536
+ }
9537
+ performEvent({
9538
+ mode: "execute",
9539
+ behaviors,
9540
+ remainingEventBehaviors: [],
9541
+ event: action.event,
9542
+ editor,
9543
+ keyGenerator,
9544
+ schema,
9545
+ getSnapshot,
9546
+ nativeEvent: void 0,
9547
+ sendBack
9548
+ });
9549
+ }
9550
+ }), undoStepCreated && clearUndoStep(editor);
9570
9551
  }
9552
+ break;
9571
9553
  }
9572
9554
  !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
9573
9555
  debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({