@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.cjs CHANGED
@@ -1705,7 +1705,7 @@ function createDecorate(schema2, slateEditor) {
1705
1705
  };
1706
1706
  }
1707
1707
  const RelayActorContext = React.createContext({}), debug$d = debugWithName("component:Editable"), PortableTextEditable = React.forwardRef(function(props, forwardedRef) {
1708
- const $ = reactCompilerRuntime.c(172);
1708
+ const $ = reactCompilerRuntime.c(171);
1709
1709
  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;
1710
1710
  $[0] !== props ? ({
1711
1711
  hotkeys,
@@ -2242,50 +2242,16 @@ const RelayActorContext = React.createContext({}), debug$d = debugWithName("comp
2242
2242
  }, $[140] = editorActor, $[141] = onDragLeave, $[142] = slateEditor, $[143] = t34) : t34 = $[143];
2243
2243
  const handleDragLeave = t34;
2244
2244
  let t35;
2245
- $[144] !== forwardedRef || $[145] !== slateEditor ? (t35 = (node) => {
2246
- if (typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node), node) {
2247
- const mutationObserver = new MutationObserver(() => {
2248
- validateSelection(slateEditor, node);
2249
- });
2250
- return mutationObserver.observe(node, {
2251
- attributeOldValue: !1,
2252
- attributes: !1,
2253
- characterData: !1,
2254
- childList: !0,
2255
- subtree: !0
2256
- }), () => {
2257
- mutationObserver.disconnect();
2258
- };
2259
- }
2260
- }, $[144] = forwardedRef, $[145] = slateEditor, $[146] = t35) : t35 = $[146];
2245
+ $[144] !== forwardedRef ? (t35 = (node) => {
2246
+ typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node);
2247
+ }, $[144] = forwardedRef, $[145] = t35) : t35 = $[145];
2261
2248
  const callbackRef = t35;
2262
2249
  if (!portableTextEditor)
2263
2250
  return null;
2264
2251
  let t36;
2265
- 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__ */ jsxRuntime.jsx(slateReact.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;
2252
+ 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__ */ jsxRuntime.jsx(slateReact.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;
2266
2253
  });
2267
2254
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
2268
- function validateSelection(slateEditor, activeElement) {
2269
- if (!slateEditor.selection)
2270
- return;
2271
- let root;
2272
- try {
2273
- root = slateReact.ReactEditor.findDocumentOrShadowRoot(slateEditor);
2274
- } catch {
2275
- }
2276
- if (!root || activeElement !== root.activeElement)
2277
- return;
2278
- const domSelection = slateReact.ReactEditor.getWindow(slateEditor).getSelection();
2279
- if (!domSelection || domSelection.rangeCount === 0)
2280
- return;
2281
- const existingDOMRange = domSelection.getRangeAt(0);
2282
- try {
2283
- const newDOMRange = slateReact.ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
2284
- (newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug$d("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
2285
- } catch {
2286
- debug$d("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
2287
- }
2288
- }
2289
2255
  function _temp(s) {
2290
2256
  return s.matches({
2291
2257
  "edit mode": "read only"
@@ -8710,6 +8676,20 @@ const abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
8710
8676
  type: "insert.break"
8711
8677
  })]]
8712
8678
  }),
8679
+ /**
8680
+ * On Firefox, Enter might collapse the selection. To mitigate this, we
8681
+ * `raise` an `insert.break` event manually.
8682
+ */
8683
+ behaviors_index.defineBehavior({
8684
+ on: "keyboard.keydown",
8685
+ guard: ({
8686
+ snapshot,
8687
+ event
8688
+ }) => defaultKeyboardShortcuts.break.guard(event.originEvent) && selector_isSelectionExpanded.isSelectionExpanded(snapshot),
8689
+ actions: [() => [behaviors_index.raise({
8690
+ type: "insert.break"
8691
+ })]]
8692
+ }),
8713
8693
  /**
8714
8694
  * On WebKit, Shift+Enter results in an `insertParagraph` input event rather
8715
8695
  * than an `insertLineBreak` input event. This Behavior makes sure we catch
@@ -9459,86 +9439,88 @@ function performEvent({
9459
9439
  } catch (error) {
9460
9440
  console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error.message}`));
9461
9441
  }
9462
- if (shouldRun) {
9463
- defaultBehaviorOverwritten = !0, eventBehavior.actions.length === 0 && (nativeEventPrevented = !0);
9464
- for (const actionSet of eventBehavior.actions) {
9465
- const actionsSnapshot = getSnapshot();
9466
- let actions = [];
9467
- try {
9468
- actions = actionSet({
9469
- snapshot: actionsSnapshot,
9470
- event,
9471
- dom: createEditorDom(sendBack, editor)
9472
- }, shouldRun);
9473
- } catch (error) {
9474
- console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
9475
- }
9476
- if (actions.length === 0)
9477
- continue;
9478
- nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
9479
- let undoStepCreated = !1;
9480
- actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
9481
- 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");
9482
- withoutNormalizingConditional(editor, () => raiseGroup || executeGroup, () => {
9483
- for (const action of actions) {
9484
- if (action.type === "effect") {
9485
- try {
9486
- action.effect({
9487
- send: sendBack
9488
- });
9489
- } catch (error) {
9490
- console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
9491
- }
9492
- continue;
9493
- }
9494
- if (action.type === "forward") {
9495
- const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
9496
- performEvent({
9497
- mode: mode === "execute" ? "execute" : "forward",
9498
- behaviors,
9499
- remainingEventBehaviors: remainingEventBehaviors2,
9500
- event: action.event,
9501
- editor,
9502
- keyGenerator,
9503
- schema: schema2,
9504
- getSnapshot,
9505
- nativeEvent,
9506
- sendBack
9507
- });
9508
- continue;
9509
- }
9510
- if (action.type === "raise") {
9511
- performEvent({
9512
- mode: mode === "execute" ? "execute" : "raise",
9513
- behaviors,
9514
- remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
9515
- event: action.event,
9516
- editor,
9517
- keyGenerator,
9518
- schema: schema2,
9519
- getSnapshot,
9520
- nativeEvent,
9521
- sendBack
9442
+ if (!shouldRun)
9443
+ continue;
9444
+ defaultBehaviorOverwritten = !0, eventBehavior.actions.length === 0 && (nativeEventPrevented = !0);
9445
+ let actionSetIndex = -1;
9446
+ for (const actionSet of eventBehavior.actions) {
9447
+ actionSetIndex++;
9448
+ const actionsSnapshot = getSnapshot();
9449
+ let actions = [];
9450
+ try {
9451
+ actions = actionSet({
9452
+ snapshot: actionsSnapshot,
9453
+ event,
9454
+ dom: createEditorDom(sendBack, editor)
9455
+ }, shouldRun);
9456
+ } catch (error) {
9457
+ console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
9458
+ }
9459
+ if (actions.length === 0)
9460
+ continue;
9461
+ nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
9462
+ let undoStepCreated = !1;
9463
+ actionSetIndex > 0 && (createUndoStep(editor), undoStepCreated = !0), !undoStepCreated && actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
9464
+ 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");
9465
+ withoutNormalizingConditional(editor, () => raiseGroup || executeGroup, () => {
9466
+ for (const action of actions) {
9467
+ if (action.type === "effect") {
9468
+ try {
9469
+ action.effect({
9470
+ send: sendBack
9522
9471
  });
9523
- continue;
9472
+ } catch (error) {
9473
+ console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
9524
9474
  }
9475
+ continue;
9476
+ }
9477
+ if (action.type === "forward") {
9478
+ const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
9525
9479
  performEvent({
9526
- mode: "execute",
9480
+ mode: mode === "execute" ? "execute" : "forward",
9527
9481
  behaviors,
9528
- remainingEventBehaviors: [],
9482
+ remainingEventBehaviors: remainingEventBehaviors2,
9529
9483
  event: action.event,
9530
9484
  editor,
9531
9485
  keyGenerator,
9532
9486
  schema: schema2,
9533
9487
  getSnapshot,
9534
- nativeEvent: void 0,
9488
+ nativeEvent,
9535
9489
  sendBack
9536
9490
  });
9491
+ continue;
9537
9492
  }
9538
- }), undoStepCreated && clearUndoStep(editor);
9539
- }
9540
- break;
9493
+ if (action.type === "raise") {
9494
+ performEvent({
9495
+ mode: mode === "execute" ? "execute" : "raise",
9496
+ behaviors,
9497
+ remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
9498
+ event: action.event,
9499
+ editor,
9500
+ keyGenerator,
9501
+ schema: schema2,
9502
+ getSnapshot,
9503
+ nativeEvent,
9504
+ sendBack
9505
+ });
9506
+ continue;
9507
+ }
9508
+ performEvent({
9509
+ mode: "execute",
9510
+ behaviors,
9511
+ remainingEventBehaviors: [],
9512
+ event: action.event,
9513
+ editor,
9514
+ keyGenerator,
9515
+ schema: schema2,
9516
+ getSnapshot,
9517
+ nativeEvent: void 0,
9518
+ sendBack
9519
+ });
9520
+ }
9521
+ }), undoStepCreated && clearUndoStep(editor);
9541
9522
  }
9523
+ break;
9542
9524
  }
9543
9525
  !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
9544
9526
  debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({