@portabletext/editor 1.44.7 → 1.44.8

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
@@ -845,6 +845,9 @@ const slateOperationCallback = ({
845
845
  "slate operation listener": xstate.fromCallback(slateOperationCallback)
846
846
  },
847
847
  guards: {
848
+ "has pending range decorations": ({
849
+ context
850
+ }) => context.pendingRangeDecorations.length > 0,
848
851
  "has range decorations": ({
849
852
  context
850
853
  }) => context.decoratedRanges.length > 0,
@@ -898,10 +901,13 @@ const slateOperationCallback = ({
898
901
  "range decorations updated": {
899
902
  actions: ["update pending range decorations"]
900
903
  },
901
- ready: {
904
+ ready: [{
902
905
  target: "ready",
903
- actions: ["set up initial range decorations"]
904
- }
906
+ guard: "has pending range decorations",
907
+ actions: ["set up initial range decorations", "increment update count"]
908
+ }, {
909
+ target: "ready"
910
+ }]
905
911
  }
906
912
  },
907
913
  ready: {
@@ -933,7 +939,7 @@ const slateOperationCallback = ({
933
939
  }
934
940
  });
935
941
  function createDecorate(rangeDecorationActor) {
936
- return function([, path]) {
942
+ return function([node, path]) {
937
943
  if (editorProvider.isEqualToEmptyEditor(rangeDecorationActor.getSnapshot().context.slateEditor.children, rangeDecorationActor.getSnapshot().context.schema))
938
944
  return [{
939
945
  anchor: {
@@ -948,7 +954,10 @@ function createDecorate(rangeDecorationActor) {
948
954
  }];
949
955
  if (path.length === 0)
950
956
  return [];
951
- const result = rangeDecorationActor.getSnapshot().context.decoratedRanges.filter((item) => slate.Range.isCollapsed(item) ? path.length !== 2 ? !1 : slate.Path.equals(item.focus.path, path) && slate.Path.equals(item.anchor.path, path) : slate.Range.intersection(item, {
957
+ if (!slate.Element.isElement(node) || node.children.length === 0)
958
+ return [];
959
+ const blockIndex = path.at(0);
960
+ return blockIndex === void 0 ? [] : rangeDecorationActor.getSnapshot().context.decoratedRanges.filter((decoratedRange) => slate.Range.isCollapsed(decoratedRange) ? node.children.some((_, childIndex) => slate.Path.equals(decoratedRange.anchor.path, [blockIndex, childIndex]) && slate.Path.equals(decoratedRange.focus.path, [blockIndex, childIndex])) : slate.Range.intersection(decoratedRange, {
952
961
  anchor: {
953
962
  path,
954
963
  offset: 0
@@ -957,8 +966,7 @@ function createDecorate(rangeDecorationActor) {
957
966
  path,
958
967
  offset: 0
959
968
  }
960
- }) || slate.Range.includes(item, path));
961
- return result.length > 0 ? result : [];
969
+ }) || slate.Range.includes(decoratedRange, path));
962
970
  };
963
971
  }
964
972
  const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_STYLE = {