@portabletext/editor 6.0.2 → 6.0.4

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
@@ -6993,7 +6993,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
6993
6993
  };
6994
6994
  });
6995
6995
  const onDOMBeforeInput = useCallback((event) => {
6996
- handleNativeHistoryEvents(editor, event);
6996
+ handleNativeHistoryEvents(editor, editorActor, event);
6997
6997
  const root = ReactEditor.toDOMNode(editor, editor).getRootNode();
6998
6998
  if (processing?.current && IS_WEBKIT && root instanceof ShadowRoot) {
6999
6999
  const range2 = event.getTargetRanges()[0], newRange = new window.Range();
@@ -7369,9 +7369,9 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
7369
7369
  }
7370
7370
  for (const op of deferredOperations.current)
7371
7371
  op();
7372
- deferredOperations.current = [], ReactEditor.isFocused(editor) || handleNativeHistoryEvents(editor, event.nativeEvent);
7372
+ deferredOperations.current = [], ReactEditor.isFocused(editor) || handleNativeHistoryEvents(editor, editorActor, event.nativeEvent);
7373
7373
  }
7374
- }, [attributes.onInput, editor]),
7374
+ }, [attributes.onInput, editor, editorActor]),
7375
7375
  onBlur: useCallback((event) => {
7376
7376
  if (readOnly || state.isUpdatingSelection || !ReactEditor.hasSelectableTarget(editor, event.target) || isEventHandled(event, attributes.onBlur))
7377
7377
  return;
@@ -7553,15 +7553,23 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
7553
7553
  selection
7554
7554
  } = editor, element = editor.children[selection !== null ? selection.focus.path[0] : 0], isRTL = getDirection(Node$1.string(element)) === "rtl";
7555
7555
  if (Hotkeys.isRedo(nativeEvent)) {
7556
- event.preventDefault();
7557
- const maybeHistoryEditor = editor;
7558
- typeof maybeHistoryEditor.redo == "function" && maybeHistoryEditor.redo();
7556
+ event.preventDefault(), editorActor.send({
7557
+ type: "behavior event",
7558
+ behaviorEvent: {
7559
+ type: "history.redo"
7560
+ },
7561
+ editor
7562
+ });
7559
7563
  return;
7560
7564
  }
7561
7565
  if (Hotkeys.isUndo(nativeEvent)) {
7562
- event.preventDefault();
7563
- const maybeHistoryEditor = editor;
7564
- typeof maybeHistoryEditor.undo == "function" && maybeHistoryEditor.undo();
7566
+ event.preventDefault(), editorActor.send({
7567
+ type: "behavior event",
7568
+ behaviorEvent: {
7569
+ type: "history.undo"
7570
+ },
7571
+ editor
7572
+ });
7565
7573
  return;
7566
7574
  }
7567
7575
  if (Hotkeys.isMoveLineBackward(nativeEvent)) {
@@ -7815,14 +7823,25 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
7815
7823
  scrollMode: "if-needed"
7816
7824
  }), delete leafEl.getBoundingClientRect;
7817
7825
  }
7818
- }, isEventHandled = (event, handler) => handler ? handler(event) ?? (event.isDefaultPrevented() || event.isPropagationStopped()) : !1, isDOMEventTargetInput = (event) => isDOMNode(event.target) && (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement), isDOMEventHandled = (event, handler) => handler ? handler(event) ?? event.defaultPrevented : !1, handleNativeHistoryEvents = (editor, event) => {
7819
- const maybeHistoryEditor = editor;
7820
- if (event.inputType === "historyUndo" && typeof maybeHistoryEditor.undo == "function") {
7821
- maybeHistoryEditor.undo();
7826
+ }, isEventHandled = (event, handler) => handler ? handler(event) ?? (event.isDefaultPrevented() || event.isPropagationStopped()) : !1, isDOMEventTargetInput = (event) => isDOMNode(event.target) && (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement), isDOMEventHandled = (event, handler) => handler ? handler(event) ?? event.defaultPrevented : !1, handleNativeHistoryEvents = (editor, editorActor, event) => {
7827
+ if (event.inputType === "historyUndo") {
7828
+ editorActor.send({
7829
+ type: "behavior event",
7830
+ behaviorEvent: {
7831
+ type: "history.undo"
7832
+ },
7833
+ editor
7834
+ });
7822
7835
  return;
7823
7836
  }
7824
- if (event.inputType === "historyRedo" && typeof maybeHistoryEditor.redo == "function") {
7825
- maybeHistoryEditor.redo();
7837
+ if (event.inputType === "historyRedo") {
7838
+ editorActor.send({
7839
+ type: "behavior event",
7840
+ behaviorEvent: {
7841
+ type: "history.redo"
7842
+ },
7843
+ editor
7844
+ });
7826
7845
  return;
7827
7846
  }
7828
7847
  }, FocusedContext = createContext(!1), REACT_MAJOR_VERSION = parseInt(React.version.split(".")[0], 10), Slate = (props) => {
@@ -12381,7 +12400,7 @@ function insertTextPatch(schema, children, operation, beforeValue) {
12381
12400
  schema
12382
12401
  }, children[operation.path[0]]) && children[operation.path[0]];
12383
12402
  if (!block)
12384
- throw new Error("Could not find block");
12403
+ return [];
12385
12404
  const textChild = isTextBlock({
12386
12405
  schema
12387
12406
  }, block) && isSpan({
@@ -12402,11 +12421,11 @@ function insertTextPatch(schema, children, operation, beforeValue) {
12402
12421
  }
12403
12422
  function removeTextPatch(schema, children, operation, beforeValue) {
12404
12423
  const block = children[operation.path[0]];
12405
- if (!block)
12406
- throw new Error("Could not find block");
12407
- const child = isTextBlock({
12424
+ if (!block || !isTextBlock({
12408
12425
  schema
12409
- }, block) && block.children[operation.path[1]] || void 0, textChild = isSpan({
12426
+ }, block))
12427
+ return [];
12428
+ const child = block.children[operation.path[1]] || void 0, textChild = isSpan({
12410
12429
  schema
12411
12430
  }, child) ? child : void 0;
12412
12431
  if (child && !textChild)
@@ -16570,15 +16589,21 @@ const insertChildOperationImplementation = ({
16570
16589
  operation
16571
16590
  }) => {
16572
16591
  const {
16592
+ editor
16593
+ } = operation, {
16573
16594
  selection
16574
- } = operation.editor;
16575
- if (!selection || !Range.isCollapsed(selection))
16595
+ } = editor;
16596
+ if (!selection || !Range.isCollapsed(selection) || Editor.void(editor, {
16597
+ at: selection
16598
+ }) || Editor.elementReadOnly(editor, {
16599
+ at: selection
16600
+ }))
16576
16601
  return;
16577
16602
  const {
16578
16603
  path: path2,
16579
16604
  offset
16580
16605
  } = selection.anchor;
16581
- operation.text.length > 0 && operation.editor.apply({
16606
+ operation.text.length > 0 && editor.apply({
16582
16607
  type: "insert_text",
16583
16608
  path: path2,
16584
16609
  offset,