@portabletext/editor 1.44.6 → 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 +2 -2
- 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.js
CHANGED
|
@@ -831,7 +831,14 @@ const slateOperationCallback = ({
|
|
|
831
831
|
}
|
|
832
832
|
newRange !== null && rangeDecorationState.push({
|
|
833
833
|
...newRange || slateRange,
|
|
834
|
-
rangeDecoration:
|
|
834
|
+
rangeDecoration: {
|
|
835
|
+
...decoratedRange.rangeDecoration,
|
|
836
|
+
selection: slateRangeToSelection({
|
|
837
|
+
schema: context.schema,
|
|
838
|
+
editor: context.slateEditor,
|
|
839
|
+
range: newRange
|
|
840
|
+
})
|
|
841
|
+
}
|
|
835
842
|
});
|
|
836
843
|
}
|
|
837
844
|
return rangeDecorationState;
|
|
@@ -841,6 +848,11 @@ const slateOperationCallback = ({
|
|
|
841
848
|
readOnly: ({
|
|
842
849
|
event
|
|
843
850
|
}) => (assertEvent(event, "update read only"), event.readOnly)
|
|
851
|
+
}),
|
|
852
|
+
"increment update count": assign({
|
|
853
|
+
updateCount: ({
|
|
854
|
+
context
|
|
855
|
+
}) => context.updateCount + 1
|
|
844
856
|
})
|
|
845
857
|
},
|
|
846
858
|
actors: {
|
|
@@ -853,7 +865,17 @@ const slateOperationCallback = ({
|
|
|
853
865
|
"has different decorations": ({
|
|
854
866
|
context,
|
|
855
867
|
event
|
|
856
|
-
}) =>
|
|
868
|
+
}) => {
|
|
869
|
+
assertEvent(event, "range decorations updated");
|
|
870
|
+
const existingRangeDecorations = context.decoratedRanges.map((decoratedRange) => ({
|
|
871
|
+
anchor: decoratedRange.rangeDecoration.selection?.anchor,
|
|
872
|
+
focus: decoratedRange.rangeDecoration.selection?.focus
|
|
873
|
+
})), newRangeDecorations = event.rangeDecorations.map((rangeDecoration) => ({
|
|
874
|
+
anchor: rangeDecoration.selection?.anchor,
|
|
875
|
+
focus: rangeDecoration.selection?.focus
|
|
876
|
+
}));
|
|
877
|
+
return !isEqual(existingRangeDecorations, newRangeDecorations);
|
|
878
|
+
},
|
|
857
879
|
"not read only": ({
|
|
858
880
|
context
|
|
859
881
|
}) => !context.readOnly
|
|
@@ -867,7 +889,8 @@ const slateOperationCallback = ({
|
|
|
867
889
|
pendingRangeDecorations: input.rangeDecorations,
|
|
868
890
|
decoratedRanges: [],
|
|
869
891
|
schema: input.schema,
|
|
870
|
-
slateEditor: input.slateEditor
|
|
892
|
+
slateEditor: input.slateEditor,
|
|
893
|
+
updateCount: 0
|
|
871
894
|
}),
|
|
872
895
|
invoke: {
|
|
873
896
|
src: "slate operation listener",
|
|
@@ -901,7 +924,7 @@ const slateOperationCallback = ({
|
|
|
901
924
|
"range decorations updated": {
|
|
902
925
|
target: ".idle",
|
|
903
926
|
guard: "has different decorations",
|
|
904
|
-
actions: ["update range decorations", "update
|
|
927
|
+
actions: ["update range decorations", "increment update count"]
|
|
905
928
|
}
|
|
906
929
|
},
|
|
907
930
|
states: {
|
|
@@ -998,7 +1021,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
998
1021
|
schema: schemaTypes,
|
|
999
1022
|
rangeDecorations: rangeDecorations ?? []
|
|
1000
1023
|
}
|
|
1001
|
-
})
|
|
1024
|
+
});
|
|
1025
|
+
useSelector(rangeDecorationsActor, (s_1) => s_1.context.updateCount);
|
|
1026
|
+
const decorate = useMemo(() => createDecorate(rangeDecorationsActor), [rangeDecorationsActor]);
|
|
1002
1027
|
useEffect(() => {
|
|
1003
1028
|
rangeDecorationsActor.send({
|
|
1004
1029
|
type: "update read only",
|