@portabletext/editor 1.1.12-canary.2 → 1.1.12-canary.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.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
2
- import { c } from "react-compiler-runtime";
3
2
  import isEqual from "lodash/isEqual.js";
4
3
  import noop from "lodash/noop.js";
5
4
  import { useRef, useState, useEffect, useMemo, createContext, useContext, useCallback, startTransition, Component, forwardRef, useImperativeHandle } from "react";
@@ -7,6 +6,7 @@ import { Editor, Element as Element$1, Range, Point, Text, Path, Transforms, Nod
7
6
  import { useSlateStatic, ReactEditor, useSelected, withReact, Slate, useSlate, Editable } from "slate-react";
8
7
  import debug$m from "debug";
9
8
  import { isKeySegment, isPortableTextTextBlock, isPortableTextSpan, isPortableTextListBlock } from "@sanity/types";
9
+ import { c } from "react-compiler-runtime";
10
10
  import { styled } from "styled-components";
11
11
  import uniq from "lodash/uniq.js";
12
12
  import { Subject } from "rxjs";
@@ -798,6 +798,25 @@ function getFocusBlockObject(context) {
798
798
  path: focusBlock.path
799
799
  } : void 0;
800
800
  }
801
+ function getFocusChild(context) {
802
+ const focusBlock = getFocusTextBlock(context);
803
+ if (!focusBlock)
804
+ return;
805
+ const key = context.selection && isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
806
+ return node && key ? {
807
+ node,
808
+ path: [...focusBlock.path, "children", {
809
+ _key: key
810
+ }]
811
+ } : void 0;
812
+ }
813
+ function getFocusSpan(context) {
814
+ const focusChild = getFocusChild(context);
815
+ return focusChild && isPortableTextSpan(focusChild.node) ? {
816
+ node: focusChild.node,
817
+ path: focusChild.path
818
+ } : void 0;
819
+ }
801
820
  function getSelectionStartBlock(context) {
802
821
  const key = context.selection.backward ? isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
803
822
  return node && key ? {
@@ -864,14 +883,7 @@ function getNextBlock(context) {
864
883
  function isEmptyTextBlock(block) {
865
884
  return block.children.length === 1 && block.children[0].text === "";
866
885
  }
867
- const softReturn = {
868
- on: "insert soft break",
869
- actions: [() => [{
870
- type: "insert text",
871
- text: `
872
- `
873
- }]]
874
- }, breakingVoidBlock = {
886
+ const breakingVoidBlock = {
875
887
  on: "insert break",
876
888
  guard: ({
877
889
  context
@@ -958,7 +970,50 @@ const softReturn = {
958
970
  }
959
971
  }
960
972
  }]]
961
- }, coreBehaviors = [softReturn, breakingVoidBlock, deletingEmptyTextBlockAfterBlockObject, deletingEmptyTextBlockBeforeBlockObject], debug$k = debugWithName("operationToPatches");
973
+ }, coreBlockObjectBehaviors = [breakingVoidBlock, deletingEmptyTextBlockAfterBlockObject, deletingEmptyTextBlockBeforeBlockObject], clearListOnBackspace = {
974
+ on: "delete backward",
975
+ guard: ({
976
+ context
977
+ }) => {
978
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
979
+ return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
980
+ focusTextBlock
981
+ } : !1;
982
+ },
983
+ actions: [(_, {
984
+ focusTextBlock
985
+ }) => [{
986
+ type: "unset block",
987
+ props: ["listItem", "level"],
988
+ paths: [focusTextBlock.path]
989
+ }]]
990
+ }, unindentListOnBackspace = {
991
+ on: "delete backward",
992
+ guard: ({
993
+ context
994
+ }) => {
995
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
996
+ return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
997
+ focusTextBlock,
998
+ level: focusTextBlock.node.level - 1
999
+ } : !1;
1000
+ },
1001
+ actions: [(_, {
1002
+ focusTextBlock,
1003
+ level
1004
+ }) => [{
1005
+ type: "set block",
1006
+ level,
1007
+ paths: [focusTextBlock.path]
1008
+ }]]
1009
+ }, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
1010
+ on: "insert soft break",
1011
+ actions: [() => [{
1012
+ type: "insert text",
1013
+ text: `
1014
+ `
1015
+ }]]
1016
+ }, coreBehaviors = [softReturn, ...coreBlockObjectBehaviors, ...coreListBehaviors], debug$k = debugWithName("operationToPatches");
962
1017
  function createOperationToPatches(types) {
963
1018
  const textBlockName = types.block.name;
964
1019
  function insertTextPatch(editor, operation, beforeValue) {
@@ -4703,28 +4758,20 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
4703
4758
  }
4704
4759
  const debug$4 = debugWithName("component:PortableTextEditor:Synchronizer"), debugVerbose$1 = debug$4.enabled && !1, FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3;
4705
4760
  function Synchronizer(props) {
4706
- const $ = c(36), portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), {
4761
+ const portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), {
4707
4762
  editorActor,
4708
4763
  getValue,
4709
4764
  onChange,
4710
4765
  value
4711
- } = props;
4712
- let t0;
4713
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
4714
- const pendingPatches = useRef(t0);
4715
- let t1;
4716
- $[1] !== editorActor || $[2] !== portableTextEditor || $[3] !== readOnly ? (t1 = {
4766
+ } = props, pendingPatches = useRef([]), syncValue = useSyncValue({
4717
4767
  editorActor,
4718
4768
  portableTextEditor,
4719
4769
  readOnly
4720
- }, $[1] = editorActor, $[2] = portableTextEditor, $[3] = readOnly, $[4] = t1) : t1 = $[4];
4721
- const syncValue = useSyncValue(t1), slateEditor = useSlate();
4722
- let t2, t3;
4723
- $[5] !== slateEditor ? (t2 = () => {
4770
+ }), slateEditor = useSlate();
4771
+ useEffect(() => {
4724
4772
  IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
4725
- }, t3 = [slateEditor], $[5] = slateEditor, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3);
4726
- let t4;
4727
- $[8] !== getValue || $[9] !== editorActor || $[10] !== slateEditor ? (t4 = () => {
4773
+ }, [slateEditor]);
4774
+ const onFlushPendingPatches = useCallback(() => {
4728
4775
  if (pendingPatches.current.length > 0) {
4729
4776
  debug$4("Flushing pending patches"), debugVerbose$1 && debug$4(`Patches:
4730
4777
  ${JSON.stringify(pendingPatches.current, null, 2)}`);
@@ -4736,68 +4783,61 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
4736
4783
  }), pendingPatches.current = [];
4737
4784
  }
4738
4785
  IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
4739
- }, $[8] = getValue, $[9] = editorActor, $[10] = slateEditor, $[11] = t4) : t4 = $[11];
4740
- const onFlushPendingPatches = t4;
4741
- let t5, t6;
4742
- $[12] !== onFlushPendingPatches ? (t5 = () => () => {
4786
+ }, [editorActor, slateEditor, getValue]), onFlushPendingPatchesThrottled = useMemo(() => throttle(() => {
4787
+ if (Editor.isNormalizing(slateEditor)) {
4788
+ onFlushPendingPatches();
4789
+ return;
4790
+ }
4791
+ onFlushPendingPatchesThrottled();
4792
+ }, FLUSH_PATCHES_THROTTLED_MS, {
4793
+ leading: !1,
4794
+ trailing: !0
4795
+ }), [onFlushPendingPatches, slateEditor]);
4796
+ useEffect(() => () => {
4743
4797
  onFlushPendingPatches();
4744
- }, t6 = [onFlushPendingPatches], $[12] = onFlushPendingPatches, $[13] = t5, $[14] = t6) : (t5 = $[13], t6 = $[14]), useEffect(t5, t6);
4745
- let t7;
4746
- $[15] !== onChange ? (t7 = (change) => onChange(change), $[15] = onChange, $[16] = t7) : t7 = $[16];
4747
- const handleChange = useEffectEvent(t7);
4748
- let t8, t9;
4749
- $[17] !== slateEditor || $[18] !== onFlushPendingPatches || $[19] !== editorActor || $[20] !== handleChange ? (t8 = () => {
4750
- const onFlushPendingPatchesThrottled = throttle(() => {
4751
- if (Editor.isNormalizing(slateEditor)) {
4752
- onFlushPendingPatches();
4753
- return;
4754
- }
4755
- onFlushPendingPatchesThrottled();
4756
- }, FLUSH_PATCHES_THROTTLED_MS, {
4757
- leading: !1,
4758
- trailing: !0
4759
- });
4798
+ }, [onFlushPendingPatches]);
4799
+ const handleChange = useEffectEvent((change) => onChange(change));
4800
+ useEffect(() => {
4760
4801
  debug$4("Subscribing to editor changes");
4761
4802
  const sub = editorActor.on("*", (event) => {
4762
- bb18: switch (event.type) {
4763
- case "patch": {
4803
+ switch (event.type) {
4804
+ case "patch":
4764
4805
  IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !0), pendingPatches.current.push(event.patch), onFlushPendingPatchesThrottled(), handleChange(event);
4765
- break bb18;
4766
- }
4806
+ break;
4767
4807
  case "loading": {
4768
4808
  handleChange({
4769
4809
  type: "loading",
4770
4810
  isLoading: !0
4771
4811
  });
4772
- break bb18;
4812
+ break;
4773
4813
  }
4774
4814
  case "done loading": {
4775
4815
  handleChange({
4776
4816
  type: "loading",
4777
4817
  isLoading: !1
4778
4818
  });
4779
- break bb18;
4819
+ break;
4780
4820
  }
4781
4821
  case "offline": {
4782
4822
  handleChange({
4783
4823
  type: "connection",
4784
4824
  value: "offline"
4785
4825
  });
4786
- break bb18;
4826
+ break;
4787
4827
  }
4788
4828
  case "online": {
4789
4829
  handleChange({
4790
4830
  type: "connection",
4791
4831
  value: "online"
4792
4832
  });
4793
- break bb18;
4833
+ break;
4794
4834
  }
4795
4835
  case "value changed": {
4796
4836
  handleChange({
4797
4837
  type: "value",
4798
4838
  value: event.value
4799
4839
  });
4800
- break bb18;
4840
+ break;
4801
4841
  }
4802
4842
  case "invalid value": {
4803
4843
  handleChange({
@@ -4805,14 +4845,14 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
4805
4845
  resolution: event.resolution,
4806
4846
  value: event.value
4807
4847
  });
4808
- break bb18;
4848
+ break;
4809
4849
  }
4810
4850
  case "error": {
4811
4851
  handleChange({
4812
4852
  ...event,
4813
4853
  level: "warning"
4814
4854
  });
4815
- break bb18;
4855
+ break;
4816
4856
  }
4817
4857
  default:
4818
4858
  handleChange(event);
@@ -4821,28 +4861,24 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
4821
4861
  return () => {
4822
4862
  debug$4("Unsubscribing to changes"), sub.unsubscribe();
4823
4863
  };
4824
- }, t9 = [editorActor, handleChange, onFlushPendingPatches, slateEditor], $[17] = slateEditor, $[18] = onFlushPendingPatches, $[19] = editorActor, $[20] = handleChange, $[21] = t8, $[22] = t9) : (t8 = $[21], t9 = $[22]), useEffect(t8, t9);
4825
- let t10;
4826
- $[23] !== syncValue || $[24] !== value ? (t10 = () => {
4864
+ }, [handleChange, editorActor, onFlushPendingPatchesThrottled, slateEditor]);
4865
+ const handleOnline = useCallback(() => {
4827
4866
  debug$4("Editor is online, syncing from props.value"), syncValue(value);
4828
- }, $[23] = syncValue, $[24] = value, $[25] = t10) : t10 = $[25];
4829
- const handleOnline = t10;
4830
- let t11, t12;
4831
- $[26] !== editorActor || $[27] !== portableTextEditor.props.patches$ || $[28] !== handleOnline ? (t11 = () => {
4867
+ }, [syncValue, value]);
4868
+ useEffect(() => {
4832
4869
  const subscription = editorActor.on("online", () => {
4833
4870
  portableTextEditor.props.patches$ && handleOnline();
4834
4871
  });
4835
4872
  return () => {
4836
4873
  subscription.unsubscribe();
4837
4874
  };
4838
- }, t12 = [handleOnline, editorActor, portableTextEditor.props.patches$], $[26] = editorActor, $[27] = portableTextEditor.props.patches$, $[28] = handleOnline, $[29] = t11, $[30] = t12) : (t11 = $[29], t12 = $[30]), useEffect(t11, t12);
4875
+ }, [handleOnline, editorActor, portableTextEditor.props.patches$]);
4839
4876
  const isInitialValueFromProps = useRef(!0);
4840
- let t13, t14;
4841
- return $[31] !== syncValue || $[32] !== value || $[33] !== editorActor ? (t13 = () => {
4877
+ return useEffect(() => {
4842
4878
  debug$4("Value from props changed, syncing new value"), syncValue(value), isInitialValueFromProps.current && (editorActor.send({
4843
4879
  type: "ready"
4844
4880
  }), isInitialValueFromProps.current = !1);
4845
- }, t14 = [editorActor, syncValue, value], $[31] = syncValue, $[32] = value, $[33] = editorActor, $[34] = t13, $[35] = t14) : (t13 = $[34], t14 = $[35]), useEffect(t13, t14), null;
4881
+ }, [editorActor, syncValue, value]), null;
4846
4882
  }
4847
4883
  Synchronizer.displayName = "Synchronizer";
4848
4884
  const EditorActorContext = createContext({}), insertBreakActionImplementation = ({
@@ -5666,14 +5702,6 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
5666
5702
  return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
5667
5703
  };
5668
5704
  Leaf.displayName = "Leaf";
5669
- function withSyncRangeDecorations(slateEditor, syncRangeDecorations) {
5670
- const originalApply = slateEditor.apply;
5671
- return slateEditor.apply = (op) => {
5672
- originalApply(op), op.type !== "set_selection" && syncRangeDecorations(op);
5673
- }, () => {
5674
- slateEditor.apply = originalApply;
5675
- };
5676
- }
5677
5705
  const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5678
5706
  position: "absolute",
5679
5707
  userSelect: "none",
@@ -5681,9 +5709,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5681
5709
  left: 0,
5682
5710
  right: 0
5683
5711
  }, PortableTextEditable = forwardRef(function(props, forwardedRef) {
5684
- const $ = c(122);
5685
- let rangeDecorations, hotkeys, spellCheck, renderBlock, renderChild, renderListItem, renderStyle, renderAnnotation, renderDecorator, renderPlaceholder, propsSelection, onCopy, onPaste, onFocus, onClick, onBlur, onBeforeInput, scrollSelectionIntoView, restProps;
5686
- $[0] !== props ? ({
5712
+ const {
5687
5713
  hotkeys,
5688
5714
  onBlur,
5689
5715
  onFocus,
@@ -5703,30 +5729,13 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5703
5729
  scrollSelectionIntoView,
5704
5730
  spellCheck,
5705
5731
  ...restProps
5706
- } = props, $[0] = props, $[1] = rangeDecorations, $[2] = hotkeys, $[3] = spellCheck, $[4] = renderBlock, $[5] = renderChild, $[6] = renderListItem, $[7] = renderStyle, $[8] = renderAnnotation, $[9] = renderDecorator, $[10] = renderPlaceholder, $[11] = propsSelection, $[12] = onCopy, $[13] = onPaste, $[14] = onFocus, $[15] = onClick, $[16] = onBlur, $[17] = onBeforeInput, $[18] = scrollSelectionIntoView, $[19] = restProps) : (rangeDecorations = $[1], hotkeys = $[2], spellCheck = $[3], renderBlock = $[4], renderChild = $[5], renderListItem = $[6], renderStyle = $[7], renderAnnotation = $[8], renderDecorator = $[9], renderPlaceholder = $[10], propsSelection = $[11], onCopy = $[12], onPaste = $[13], onFocus = $[14], onClick = $[15], onBlur = $[16], onBeforeInput = $[17], scrollSelectionIntoView = $[18], restProps = $[19]);
5707
- const portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1);
5708
- let t0;
5709
- $[20] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[20] = t0) : t0 = $[20];
5710
- const [rangeDecorationState, setRangeDecorationsState] = useState(t0);
5711
- let t1;
5712
- $[21] === Symbol.for("react.memo_cache_sentinel") ? (t1 = () => ref.current, $[21] = t1) : t1 = $[21], useImperativeHandle(forwardedRef, t1);
5732
+ } = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1), [rangeDecorationState, setRangeDecorationsState] = useState([]);
5733
+ useImperativeHandle(forwardedRef, () => ref.current);
5713
5734
  const rangeDecorationsRef = useRef(rangeDecorations), editorActor = useContext(EditorActorContext), {
5714
5735
  schemaTypes
5715
- } = portableTextEditor, slateEditor = useSlate(), blockTypeName = schemaTypes.block.name;
5716
- bb0: {
5717
- const withInsertData = createWithInsertData(editorActor, schemaTypes);
5718
- if (readOnly) {
5719
- debug("Editable is in read only mode"), withInsertData(slateEditor);
5720
- break bb0;
5721
- }
5722
- const withHotKeys = createWithHotkeys(portableTextEditor, hotkeys);
5723
- debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
5724
- }
5725
- let t3;
5726
- $[22] !== readOnly || $[23] !== renderBlock || $[24] !== renderChild || $[25] !== renderListItem || $[26] !== renderStyle || $[27] !== schemaTypes || $[28] !== spellCheck ? (t3 = (eProps) => /* @__PURE__ */ jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), $[22] = readOnly, $[23] = renderBlock, $[24] = renderChild, $[25] = renderListItem, $[26] = renderStyle, $[27] = schemaTypes, $[28] = spellCheck, $[29] = t3) : t3 = $[29];
5727
- const renderElement = t3;
5728
- let t4;
5729
- $[30] !== editorActor || $[31] !== schemaTypes || $[32] !== renderAnnotation || $[33] !== renderChild || $[34] !== renderDecorator || $[35] !== readOnly || $[36] !== renderPlaceholder ? (t4 = (lProps) => {
5736
+ } = portableTextEditor, slateEditor = useSlate(), blockTypeName = schemaTypes.block.name, withInsertData = useMemo(() => createWithInsertData(editorActor, schemaTypes), [editorActor, schemaTypes]), withHotKeys = useMemo(() => createWithHotkeys(portableTextEditor, hotkeys), [hotkeys, portableTextEditor]);
5737
+ useMemo(() => readOnly ? (debug("Editable is in read only mode"), withInsertData(slateEditor)) : (debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor))), [readOnly, slateEditor, withHotKeys, withInsertData]);
5738
+ const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((lProps) => {
5730
5739
  if (lProps.leaf._type === "span") {
5731
5740
  let rendered = /* @__PURE__ */ jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
5732
5741
  if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
@@ -5740,10 +5749,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5740
5749
  })), rendered;
5741
5750
  }
5742
5751
  return lProps.children;
5743
- }, $[30] = editorActor, $[31] = schemaTypes, $[32] = renderAnnotation, $[33] = renderChild, $[34] = renderDecorator, $[35] = readOnly, $[36] = renderPlaceholder, $[37] = t4) : t4 = $[37];
5744
- const renderLeaf = t4;
5745
- let t5;
5746
- $[38] !== propsSelection || $[39] !== slateEditor || $[40] !== blockTypeName || $[41] !== editorActor ? (t5 = () => {
5752
+ }, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schemaTypes]), restoreSelectionFromProps = useCallback(() => {
5747
5753
  if (propsSelection) {
5748
5754
  debug(`Selection from props ${JSON.stringify(propsSelection)}`);
5749
5755
  const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, blockTypeName));
@@ -5756,10 +5762,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5756
5762
  }), slateEditor.onChange());
5757
5763
  }
5758
5764
  }
5759
- }, $[38] = propsSelection, $[39] = slateEditor, $[40] = blockTypeName, $[41] = editorActor, $[42] = t5) : t5 = $[42];
5760
- const restoreSelectionFromProps = t5;
5761
- let t6;
5762
- $[43] !== rangeDecorations || $[44] !== slateEditor || $[45] !== portableTextEditor || $[46] !== schemaTypes ? (t6 = (operation) => {
5765
+ }, [blockTypeName, editorActor, propsSelection, slateEditor]), syncRangeDecorations = useCallback((operation) => {
5763
5766
  if (rangeDecorations && rangeDecorations.length > 0) {
5764
5767
  const newSlateRanges = [];
5765
5768
  if (rangeDecorations.forEach((rangeDecorationItem) => {
@@ -5791,10 +5794,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5791
5794
  }
5792
5795
  }
5793
5796
  setRangeDecorationsState((rangeDecorationState_0) => rangeDecorationState_0.length > 0 ? [] : rangeDecorationState_0);
5794
- }, $[43] = rangeDecorations, $[44] = slateEditor, $[45] = portableTextEditor, $[46] = schemaTypes, $[47] = t6) : t6 = $[47];
5795
- const syncRangeDecorations = t6;
5796
- let t7, t8;
5797
- $[48] !== editorActor || $[49] !== restoreSelectionFromProps ? (t7 = () => {
5797
+ }, [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]);
5798
+ useEffect(() => {
5798
5799
  const onReady = editorActor.on("ready", () => {
5799
5800
  restoreSelectionFromProps();
5800
5801
  }), onInvalidValue = editorActor.on("invalid value", () => {
@@ -5805,32 +5806,22 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5805
5806
  return () => {
5806
5807
  onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
5807
5808
  };
5808
- }, t8 = [editorActor, restoreSelectionFromProps], $[48] = editorActor, $[49] = restoreSelectionFromProps, $[50] = t7, $[51] = t8) : (t7 = $[50], t8 = $[51]), useEffect(t7, t8);
5809
- let t9, t10;
5810
- $[52] !== propsSelection || $[53] !== hasInvalidValue || $[54] !== restoreSelectionFromProps ? (t9 = () => {
5809
+ }, [editorActor, restoreSelectionFromProps]), useEffect(() => {
5811
5810
  propsSelection && !hasInvalidValue && restoreSelectionFromProps();
5812
- }, t10 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[52] = propsSelection, $[53] = hasInvalidValue, $[54] = restoreSelectionFromProps, $[55] = t9, $[56] = t10) : (t9 = $[55], t10 = $[56]), useEffect(t9, t10);
5813
- const [syncedRangeDecorations, setSyncedRangeDecorations] = useState(!1);
5814
- let t11, t12;
5815
- $[57] !== syncedRangeDecorations || $[58] !== syncRangeDecorations ? (t11 = () => {
5811
+ }, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
5812
+ const originalApply = useMemo(() => slateEditor.apply, [slateEditor]), [syncedRangeDecorations, setSyncedRangeDecorations] = useState(!1);
5813
+ useEffect(() => {
5816
5814
  syncedRangeDecorations || (setSyncedRangeDecorations(!0), syncRangeDecorations());
5817
- }, t12 = [syncRangeDecorations, syncedRangeDecorations], $[57] = syncedRangeDecorations, $[58] = syncRangeDecorations, $[59] = t11, $[60] = t12) : (t11 = $[59], t12 = $[60]), useEffect(t11, t12);
5818
- let t13, t14;
5819
- $[61] !== rangeDecorations || $[62] !== syncRangeDecorations ? (t13 = () => {
5815
+ }, [syncRangeDecorations, syncedRangeDecorations]), useEffect(() => {
5820
5816
  isEqual(rangeDecorations, rangeDecorationsRef.current) || syncRangeDecorations(), rangeDecorationsRef.current = rangeDecorations;
5821
- }, t14 = [rangeDecorations, syncRangeDecorations], $[61] = rangeDecorations, $[62] = syncRangeDecorations, $[63] = t13, $[64] = t14) : (t13 = $[63], t14 = $[64]), useEffect(t13, t14);
5822
- let t15, t16;
5823
- $[65] !== slateEditor || $[66] !== syncRangeDecorations ? (t15 = () => {
5824
- const teardown = withSyncRangeDecorations(slateEditor, syncRangeDecorations);
5825
- return () => teardown();
5826
- }, t16 = [slateEditor, syncRangeDecorations], $[65] = slateEditor, $[66] = syncRangeDecorations, $[67] = t15, $[68] = t16) : (t15 = $[67], t16 = $[68]), useEffect(t15, t16);
5827
- let t17;
5828
- $[69] !== onCopy ? (t17 = (event) => {
5817
+ }, [rangeDecorations, syncRangeDecorations]), useEffect(() => (slateEditor.apply = (op) => {
5818
+ originalApply(op), op.type !== "set_selection" && syncRangeDecorations(op);
5819
+ }, () => {
5820
+ slateEditor.apply = originalApply;
5821
+ }), [originalApply, slateEditor, syncRangeDecorations]);
5822
+ const handleCopy = useCallback((event) => {
5829
5823
  onCopy && onCopy(event) !== void 0 && event.preventDefault();
5830
- }, $[69] = onCopy, $[70] = t17) : t17 = $[70];
5831
- const handleCopy = t17;
5832
- let t18;
5833
- $[71] !== slateEditor || $[72] !== onPaste || $[73] !== portableTextEditor || $[74] !== schemaTypes || $[75] !== editorActor ? (t18 = (event_0) => {
5824
+ }, [onCopy]), handlePaste = useCallback((event_0) => {
5834
5825
  if (event_0.preventDefault(), !slateEditor.selection)
5835
5826
  return;
5836
5827
  if (!onPaste) {
@@ -5854,10 +5845,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5854
5845
  type: "done loading"
5855
5846
  });
5856
5847
  }));
5857
- }, $[71] = slateEditor, $[72] = onPaste, $[73] = portableTextEditor, $[74] = schemaTypes, $[75] = editorActor, $[76] = t18) : t18 = $[76];
5858
- const handlePaste = t18;
5859
- let t19;
5860
- $[77] !== onFocus || $[78] !== portableTextEditor || $[79] !== slateEditor || $[80] !== editorActor ? (t19 = (event_1) => {
5848
+ }, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = useCallback((event_1) => {
5861
5849
  if (onFocus && onFocus(event_1), !event_1.isDefaultPrevented()) {
5862
5850
  const selection = PortableTextEditor.getSelection(portableTextEditor);
5863
5851
  selection === null && (Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
@@ -5870,10 +5858,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5870
5858
  selection
5871
5859
  });
5872
5860
  }
5873
- }, $[77] = onFocus, $[78] = portableTextEditor, $[79] = slateEditor, $[80] = editorActor, $[81] = t19) : t19 = $[81];
5874
- const handleOnFocus = t19;
5875
- let t20;
5876
- $[82] !== onClick || $[83] !== slateEditor ? (t20 = (event_2) => {
5861
+ }, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = useCallback((event_2) => {
5877
5862
  if (onClick && onClick(event_2), slateEditor.selection && event_2.target === event_2.currentTarget) {
5878
5863
  const [lastBlock, path_0] = Node.last(slateEditor, []), focusPath = slateEditor.selection.focus.path.slice(0, 1), lastPath = path_0.slice(0, 1);
5879
5864
  if (Path.equals(focusPath, lastPath)) {
@@ -5883,23 +5868,33 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5883
5868
  })), slateEditor.onChange());
5884
5869
  }
5885
5870
  }
5886
- }, $[82] = onClick, $[83] = slateEditor, $[84] = t20) : t20 = $[84];
5887
- const handleClick = t20;
5888
- let t21;
5889
- $[85] !== onBlur || $[86] !== editorActor ? (t21 = (event_3) => {
5871
+ }, [onClick, slateEditor]), handleOnBlur = useCallback((event_3) => {
5890
5872
  onBlur && onBlur(event_3), event_3.isPropagationStopped() || editorActor.send({
5891
5873
  type: "blur",
5892
5874
  event: event_3
5893
5875
  });
5894
- }, $[85] = onBlur, $[86] = editorActor, $[87] = t21) : t21 = $[87];
5895
- const handleOnBlur = t21;
5896
- let t22;
5897
- $[88] !== onBeforeInput ? (t22 = (event_4) => {
5876
+ }, [editorActor, onBlur]), handleOnBeforeInput = useCallback((event_4) => {
5898
5877
  onBeforeInput && onBeforeInput(event_4);
5899
- }, $[88] = onBeforeInput, $[89] = t22) : t22 = $[89];
5900
- const handleOnBeforeInput = t22, validateSelection = useValidateSelection(ref, slateEditor);
5901
- let t23, t24;
5902
- $[90] !== editableElement || $[91] !== validateSelection ? (t23 = () => {
5878
+ }, [onBeforeInput]), validateSelection = useCallback(() => {
5879
+ if (!slateEditor.selection)
5880
+ return;
5881
+ const root = ReactEditor.findDocumentOrShadowRoot(slateEditor), {
5882
+ activeElement
5883
+ } = root;
5884
+ if (ref.current !== activeElement)
5885
+ return;
5886
+ const domSelection = ReactEditor.getWindow(slateEditor).getSelection();
5887
+ if (!domSelection || domSelection.rangeCount === 0)
5888
+ return;
5889
+ const existingDOMRange = domSelection.getRangeAt(0);
5890
+ try {
5891
+ const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
5892
+ (newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
5893
+ } catch {
5894
+ debug("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
5895
+ }
5896
+ }, [ref, slateEditor]);
5897
+ useEffect(() => {
5903
5898
  if (editableElement) {
5904
5899
  const mutationObserver = new MutationObserver(validateSelection);
5905
5900
  return mutationObserver.observe(editableElement, {
@@ -5912,31 +5907,15 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5912
5907
  mutationObserver.disconnect();
5913
5908
  };
5914
5909
  }
5915
- }, t24 = [validateSelection, editableElement], $[90] = editableElement, $[91] = validateSelection, $[92] = t23, $[93] = t24) : (t23 = $[92], t24 = $[93]), useEffect(t23, t24);
5916
- let t25;
5917
- $[94] !== props || $[95] !== slateEditor ? (t25 = (event_5) => {
5910
+ }, [validateSelection, editableElement]);
5911
+ const handleKeyDown = useCallback((event_5) => {
5918
5912
  props.onKeyDown && props.onKeyDown(event_5), event_5.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_5);
5919
- }, $[94] = props, $[95] = slateEditor, $[96] = t25) : t25 = $[96];
5920
- const handleKeyDown = t25;
5921
- let t26;
5922
- bb1: {
5923
- if (scrollSelectionIntoView === void 0) {
5924
- t26 = void 0;
5925
- break bb1;
5926
- }
5927
- if (scrollSelectionIntoView === null) {
5928
- t26 = noop;
5929
- break bb1;
5930
- }
5931
- let t272;
5932
- $[97] !== scrollSelectionIntoView || $[98] !== portableTextEditor ? (t272 = (_editor, domRange) => {
5933
- scrollSelectionIntoView(portableTextEditor, domRange);
5934
- }, $[97] = scrollSelectionIntoView, $[98] = portableTextEditor, $[99] = t272) : t272 = $[99], t26 = t272;
5935
- }
5936
- const scrollSelectionIntoViewToSlate = t26;
5937
- let t27;
5938
- $[100] !== slateEditor.children || $[101] !== schemaTypes || $[102] !== rangeDecorationState ? (t27 = (t282) => {
5939
- const [, path_1] = t282;
5913
+ }, [props, slateEditor]), scrollSelectionIntoViewToSlate = useMemo(() => {
5914
+ if (scrollSelectionIntoView !== void 0)
5915
+ return scrollSelectionIntoView === null ? noop : (_editor, domRange) => {
5916
+ scrollSelectionIntoView(portableTextEditor, domRange);
5917
+ };
5918
+ }, [portableTextEditor, scrollSelectionIntoView]), decorate = useCallback(([, path_1]) => {
5940
5919
  if (isEqualToEmptyEditor(slateEditor.children, schemaTypes))
5941
5920
  return [{
5942
5921
  anchor: {
@@ -5962,38 +5941,32 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5962
5941
  }
5963
5942
  }) || Range.includes(item, path_1));
5964
5943
  return result_1.length > 0 ? result_1 : [];
5965
- }, $[100] = slateEditor.children, $[101] = schemaTypes, $[102] = rangeDecorationState, $[103] = t27) : t27 = $[103];
5966
- const decorate = t27;
5967
- let t28, t29;
5968
- if ($[104] !== slateEditor ? (t28 = () => {
5944
+ }, [slateEditor, schemaTypes, rangeDecorationState]);
5945
+ return useEffect(() => {
5969
5946
  ref.current = ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
5970
- }, t29 = [slateEditor, ref], $[104] = slateEditor, $[105] = t28, $[106] = t29) : (t28 = $[105], t29 = $[106]), useEffect(t28, t29), !portableTextEditor)
5971
- return null;
5972
- let t30;
5973
- return $[107] !== hasInvalidValue || $[108] !== restProps || $[109] !== decorate || $[110] !== handleOnBlur || $[111] !== handleCopy || $[112] !== handleClick || $[113] !== handleOnBeforeInput || $[114] !== handleOnFocus || $[115] !== handleKeyDown || $[116] !== handlePaste || $[117] !== readOnly || $[118] !== renderElement || $[119] !== renderLeaf || $[120] !== scrollSelectionIntoViewToSlate ? (t30 = hasInvalidValue ? null : /* @__PURE__ */ jsx(Editable, { ...restProps, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onPaste: handlePaste, readOnly, renderPlaceholder: void 0, renderElement, renderLeaf, scrollSelectionIntoView: scrollSelectionIntoViewToSlate }), $[107] = hasInvalidValue, $[108] = restProps, $[109] = decorate, $[110] = handleOnBlur, $[111] = handleCopy, $[112] = handleClick, $[113] = handleOnBeforeInput, $[114] = handleOnFocus, $[115] = handleKeyDown, $[116] = handlePaste, $[117] = readOnly, $[118] = renderElement, $[119] = renderLeaf, $[120] = scrollSelectionIntoViewToSlate, $[121] = t30) : t30 = $[121], t30;
5947
+ }, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsx(
5948
+ Editable,
5949
+ {
5950
+ ...restProps,
5951
+ autoFocus: !1,
5952
+ className: restProps.className || "pt-editable",
5953
+ decorate,
5954
+ onBlur: handleOnBlur,
5955
+ onCopy: handleCopy,
5956
+ onClick: handleClick,
5957
+ onDOMBeforeInput: handleOnBeforeInput,
5958
+ onFocus: handleOnFocus,
5959
+ onKeyDown: handleKeyDown,
5960
+ onPaste: handlePaste,
5961
+ readOnly,
5962
+ renderPlaceholder: void 0,
5963
+ renderElement,
5964
+ renderLeaf,
5965
+ scrollSelectionIntoView: scrollSelectionIntoViewToSlate
5966
+ }
5967
+ ) : null;
5974
5968
  });
5975
5969
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
5976
- function useValidateSelection(ref, slateEditor) {
5977
- return useCallback(() => {
5978
- if (!slateEditor.selection)
5979
- return;
5980
- const root = ReactEditor.findDocumentOrShadowRoot(slateEditor), {
5981
- activeElement
5982
- } = root;
5983
- if (ref.current !== activeElement)
5984
- return;
5985
- const domSelection = ReactEditor.getWindow(slateEditor).getSelection();
5986
- if (!domSelection || domSelection.rangeCount === 0)
5987
- return;
5988
- const existingDOMRange = domSelection.getRangeAt(0);
5989
- try {
5990
- const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
5991
- (newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
5992
- } catch {
5993
- debug("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
5994
- }
5995
- }, [ref, slateEditor]);
5996
- }
5997
5970
  export {
5998
5971
  PortableTextEditable,
5999
5972
  PortableTextEditor,