@portabletext/editor 1.44.5 → 1.44.7
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 +30 -5
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +30 -5
- package/lib/index.js.map +1 -1
- package/package.json +9 -9
- package/src/editor/Editable.tsx +1 -0
- package/src/editor/__tests__/RangeDecorations.test.tsx +2 -2
- package/src/editor/range-decorations-machine.ts +33 -6
package/lib/index.cjs
CHANGED
|
@@ -817,7 +817,14 @@ const slateOperationCallback = ({
|
|
|
817
817
|
}
|
|
818
818
|
newRange !== null && rangeDecorationState.push({
|
|
819
819
|
...newRange || slateRange,
|
|
820
|
-
rangeDecoration:
|
|
820
|
+
rangeDecoration: {
|
|
821
|
+
...decoratedRange.rangeDecoration,
|
|
822
|
+
selection: editorProvider.slateRangeToSelection({
|
|
823
|
+
schema: context.schema,
|
|
824
|
+
editor: context.slateEditor,
|
|
825
|
+
range: newRange
|
|
826
|
+
})
|
|
827
|
+
}
|
|
821
828
|
});
|
|
822
829
|
}
|
|
823
830
|
return rangeDecorationState;
|
|
@@ -827,6 +834,11 @@ const slateOperationCallback = ({
|
|
|
827
834
|
readOnly: ({
|
|
828
835
|
event
|
|
829
836
|
}) => (xstate.assertEvent(event, "update read only"), event.readOnly)
|
|
837
|
+
}),
|
|
838
|
+
"increment update count": xstate.assign({
|
|
839
|
+
updateCount: ({
|
|
840
|
+
context
|
|
841
|
+
}) => context.updateCount + 1
|
|
830
842
|
})
|
|
831
843
|
},
|
|
832
844
|
actors: {
|
|
@@ -839,7 +851,17 @@ const slateOperationCallback = ({
|
|
|
839
851
|
"has different decorations": ({
|
|
840
852
|
context,
|
|
841
853
|
event
|
|
842
|
-
}) =>
|
|
854
|
+
}) => {
|
|
855
|
+
xstate.assertEvent(event, "range decorations updated");
|
|
856
|
+
const existingRangeDecorations = context.decoratedRanges.map((decoratedRange) => ({
|
|
857
|
+
anchor: decoratedRange.rangeDecoration.selection?.anchor,
|
|
858
|
+
focus: decoratedRange.rangeDecoration.selection?.focus
|
|
859
|
+
})), newRangeDecorations = event.rangeDecorations.map((rangeDecoration) => ({
|
|
860
|
+
anchor: rangeDecoration.selection?.anchor,
|
|
861
|
+
focus: rangeDecoration.selection?.focus
|
|
862
|
+
}));
|
|
863
|
+
return !isEqual__default.default(existingRangeDecorations, newRangeDecorations);
|
|
864
|
+
},
|
|
843
865
|
"not read only": ({
|
|
844
866
|
context
|
|
845
867
|
}) => !context.readOnly
|
|
@@ -853,7 +875,8 @@ const slateOperationCallback = ({
|
|
|
853
875
|
pendingRangeDecorations: input.rangeDecorations,
|
|
854
876
|
decoratedRanges: [],
|
|
855
877
|
schema: input.schema,
|
|
856
|
-
slateEditor: input.slateEditor
|
|
878
|
+
slateEditor: input.slateEditor,
|
|
879
|
+
updateCount: 0
|
|
857
880
|
}),
|
|
858
881
|
invoke: {
|
|
859
882
|
src: "slate operation listener",
|
|
@@ -887,7 +910,7 @@ const slateOperationCallback = ({
|
|
|
887
910
|
"range decorations updated": {
|
|
888
911
|
target: ".idle",
|
|
889
912
|
guard: "has different decorations",
|
|
890
|
-
actions: ["update range decorations", "update
|
|
913
|
+
actions: ["update range decorations", "increment update count"]
|
|
891
914
|
}
|
|
892
915
|
},
|
|
893
916
|
states: {
|
|
@@ -984,7 +1007,9 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
984
1007
|
schema: schemaTypes,
|
|
985
1008
|
rangeDecorations: rangeDecorations ?? []
|
|
986
1009
|
}
|
|
987
|
-
})
|
|
1010
|
+
});
|
|
1011
|
+
react.useSelector(rangeDecorationsActor, (s_1) => s_1.context.updateCount);
|
|
1012
|
+
const decorate = React.useMemo(() => createDecorate(rangeDecorationsActor), [rangeDecorationsActor]);
|
|
988
1013
|
React.useEffect(() => {
|
|
989
1014
|
rangeDecorationsActor.send({
|
|
990
1015
|
type: "update read only",
|