@portabletext/editor 1.44.6 → 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 +45 -12
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +45 -12
- 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 +72 -30
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,19 +848,37 @@ 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: {
|
|
847
859
|
"slate operation listener": fromCallback(slateOperationCallback)
|
|
848
860
|
},
|
|
849
861
|
guards: {
|
|
862
|
+
"has pending range decorations": ({
|
|
863
|
+
context
|
|
864
|
+
}) => context.pendingRangeDecorations.length > 0,
|
|
850
865
|
"has range decorations": ({
|
|
851
866
|
context
|
|
852
867
|
}) => context.decoratedRanges.length > 0,
|
|
853
868
|
"has different decorations": ({
|
|
854
869
|
context,
|
|
855
870
|
event
|
|
856
|
-
}) =>
|
|
871
|
+
}) => {
|
|
872
|
+
assertEvent(event, "range decorations updated");
|
|
873
|
+
const existingRangeDecorations = context.decoratedRanges.map((decoratedRange) => ({
|
|
874
|
+
anchor: decoratedRange.rangeDecoration.selection?.anchor,
|
|
875
|
+
focus: decoratedRange.rangeDecoration.selection?.focus
|
|
876
|
+
})), newRangeDecorations = event.rangeDecorations.map((rangeDecoration) => ({
|
|
877
|
+
anchor: rangeDecoration.selection?.anchor,
|
|
878
|
+
focus: rangeDecoration.selection?.focus
|
|
879
|
+
}));
|
|
880
|
+
return !isEqual(existingRangeDecorations, newRangeDecorations);
|
|
881
|
+
},
|
|
857
882
|
"not read only": ({
|
|
858
883
|
context
|
|
859
884
|
}) => !context.readOnly
|
|
@@ -867,7 +892,8 @@ const slateOperationCallback = ({
|
|
|
867
892
|
pendingRangeDecorations: input.rangeDecorations,
|
|
868
893
|
decoratedRanges: [],
|
|
869
894
|
schema: input.schema,
|
|
870
|
-
slateEditor: input.slateEditor
|
|
895
|
+
slateEditor: input.slateEditor,
|
|
896
|
+
updateCount: 0
|
|
871
897
|
}),
|
|
872
898
|
invoke: {
|
|
873
899
|
src: "slate operation listener",
|
|
@@ -889,10 +915,13 @@ const slateOperationCallback = ({
|
|
|
889
915
|
"range decorations updated": {
|
|
890
916
|
actions: ["update pending range decorations"]
|
|
891
917
|
},
|
|
892
|
-
ready: {
|
|
918
|
+
ready: [{
|
|
893
919
|
target: "ready",
|
|
894
|
-
|
|
895
|
-
|
|
920
|
+
guard: "has pending range decorations",
|
|
921
|
+
actions: ["set up initial range decorations", "increment update count"]
|
|
922
|
+
}, {
|
|
923
|
+
target: "ready"
|
|
924
|
+
}]
|
|
896
925
|
}
|
|
897
926
|
},
|
|
898
927
|
ready: {
|
|
@@ -901,7 +930,7 @@ const slateOperationCallback = ({
|
|
|
901
930
|
"range decorations updated": {
|
|
902
931
|
target: ".idle",
|
|
903
932
|
guard: "has different decorations",
|
|
904
|
-
actions: ["update range decorations", "update
|
|
933
|
+
actions: ["update range decorations", "increment update count"]
|
|
905
934
|
}
|
|
906
935
|
},
|
|
907
936
|
states: {
|
|
@@ -924,7 +953,7 @@ const slateOperationCallback = ({
|
|
|
924
953
|
}
|
|
925
954
|
});
|
|
926
955
|
function createDecorate(rangeDecorationActor) {
|
|
927
|
-
return function([, path]) {
|
|
956
|
+
return function([node, path]) {
|
|
928
957
|
if (isEqualToEmptyEditor(rangeDecorationActor.getSnapshot().context.slateEditor.children, rangeDecorationActor.getSnapshot().context.schema))
|
|
929
958
|
return [{
|
|
930
959
|
anchor: {
|
|
@@ -939,7 +968,10 @@ function createDecorate(rangeDecorationActor) {
|
|
|
939
968
|
}];
|
|
940
969
|
if (path.length === 0)
|
|
941
970
|
return [];
|
|
942
|
-
|
|
971
|
+
if (!Element$2.isElement(node) || node.children.length === 0)
|
|
972
|
+
return [];
|
|
973
|
+
const blockIndex = path.at(0);
|
|
974
|
+
return blockIndex === void 0 ? [] : rangeDecorationActor.getSnapshot().context.decoratedRanges.filter((decoratedRange) => Range.isCollapsed(decoratedRange) ? node.children.some((_, childIndex) => Path.equals(decoratedRange.anchor.path, [blockIndex, childIndex]) && Path.equals(decoratedRange.focus.path, [blockIndex, childIndex])) : Range.intersection(decoratedRange, {
|
|
943
975
|
anchor: {
|
|
944
976
|
path,
|
|
945
977
|
offset: 0
|
|
@@ -948,8 +980,7 @@ function createDecorate(rangeDecorationActor) {
|
|
|
948
980
|
path,
|
|
949
981
|
offset: 0
|
|
950
982
|
}
|
|
951
|
-
}) || Range.includes(
|
|
952
|
-
return result.length > 0 ? result : [];
|
|
983
|
+
}) || Range.includes(decoratedRange, path));
|
|
953
984
|
};
|
|
954
985
|
}
|
|
955
986
|
const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
@@ -998,7 +1029,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
998
1029
|
schema: schemaTypes,
|
|
999
1030
|
rangeDecorations: rangeDecorations ?? []
|
|
1000
1031
|
}
|
|
1001
|
-
})
|
|
1032
|
+
});
|
|
1033
|
+
useSelector(rangeDecorationsActor, (s_1) => s_1.context.updateCount);
|
|
1034
|
+
const decorate = useMemo(() => createDecorate(rangeDecorationsActor), [rangeDecorationsActor]);
|
|
1002
1035
|
useEffect(() => {
|
|
1003
1036
|
rangeDecorationsActor.send({
|
|
1004
1037
|
type: "update read only",
|