@portabletext/editor 1.47.1 → 1.47.2
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 +9 -11
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +9 -11
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/src/editor/Editable.tsx +9 -9
package/lib/index.cjs
CHANGED
|
@@ -1036,18 +1036,18 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1036
1036
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
1037
1037
|
const editorActor = React.useContext(editorProvider.EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.matches({
|
|
1038
1038
|
"edit mode": "read only"
|
|
1039
|
-
})),
|
|
1039
|
+
})), slateEditor = slateReact.useSlate(), rangeDecorationsActor = react.useActorRef(rangeDecorationsMachine, {
|
|
1040
1040
|
input: {
|
|
1041
1041
|
rangeDecorations: rangeDecorations ?? [],
|
|
1042
1042
|
readOnly,
|
|
1043
|
-
schema:
|
|
1043
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1044
1044
|
slateEditor,
|
|
1045
1045
|
skipSetup: !editorActor.getSnapshot().matches({
|
|
1046
1046
|
setup: "setting up"
|
|
1047
1047
|
})
|
|
1048
1048
|
}
|
|
1049
1049
|
});
|
|
1050
|
-
react.useSelector(rangeDecorationsActor, (
|
|
1050
|
+
react.useSelector(rangeDecorationsActor, (s_0) => s_0.context.updateCount);
|
|
1051
1051
|
const decorate = React.useMemo(() => createDecorate(rangeDecorationsActor), [rangeDecorationsActor]);
|
|
1052
1052
|
React.useEffect(() => {
|
|
1053
1053
|
rangeDecorationsActor.send({
|
|
@@ -1059,9 +1059,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1059
1059
|
type: "range decorations updated",
|
|
1060
1060
|
rangeDecorations: rangeDecorations ?? []
|
|
1061
1061
|
});
|
|
1062
|
-
}, [rangeDecorationsActor, rangeDecorations])
|
|
1063
|
-
const blockTypeName = schemaTypes.block.name;
|
|
1064
|
-
React.useMemo(() => {
|
|
1062
|
+
}, [rangeDecorationsActor, rangeDecorations]), React.useMemo(() => {
|
|
1065
1063
|
if (readOnly)
|
|
1066
1064
|
return debug("Editable is in read only mode"), slateEditor;
|
|
1067
1065
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
@@ -1081,10 +1079,10 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1081
1079
|
})), rendered;
|
|
1082
1080
|
}
|
|
1083
1081
|
return lProps.children;
|
|
1084
|
-
}, [editorActor, portableTextEditor
|
|
1082
|
+
}, [editorActor, portableTextEditor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder]), restoreSelectionFromProps = React.useCallback(() => {
|
|
1085
1083
|
if (propsSelection) {
|
|
1086
1084
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
1087
|
-
const normalizedSelection = normalizeSelection(propsSelection, editorProvider.fromSlateValue(slateEditor.children,
|
|
1085
|
+
const normalizedSelection = normalizeSelection(propsSelection, editorProvider.fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
1088
1086
|
if (normalizedSelection !== null) {
|
|
1089
1087
|
debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
1090
1088
|
const slateRange = editorProvider.toSlateRange(normalizedSelection, slateEditor);
|
|
@@ -1094,7 +1092,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1094
1092
|
}), slateEditor.onChange());
|
|
1095
1093
|
}
|
|
1096
1094
|
}
|
|
1097
|
-
}, [
|
|
1095
|
+
}, [editorActor, propsSelection, slateEditor]);
|
|
1098
1096
|
React.useEffect(() => {
|
|
1099
1097
|
const onReady = editorActor.on("ready", () => {
|
|
1100
1098
|
rangeDecorationsActor.send({
|
|
@@ -1167,7 +1165,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1167
1165
|
}
|
|
1168
1166
|
}, [onCut, editorActor, slateEditor]), handlePaste = React.useCallback((event_1) => {
|
|
1169
1167
|
const value = editorProvider.PortableTextEditor.getValue(portableTextEditor), path = (slateEditor.selection ? editorProvider.slateRangeToSelection({
|
|
1170
|
-
schema:
|
|
1168
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1171
1169
|
editor: slateEditor,
|
|
1172
1170
|
range: slateEditor.selection
|
|
1173
1171
|
}) : null)?.focus.path || [], onPasteResult = onPaste?.({
|
|
@@ -1247,7 +1245,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1247
1245
|
});
|
|
1248
1246
|
}
|
|
1249
1247
|
debug("No result from custom paste handler, pasting normally");
|
|
1250
|
-
}, [editorActor, onPaste, portableTextEditor,
|
|
1248
|
+
}, [editorActor, onPaste, portableTextEditor, slateEditor]), handleOnFocus = React.useCallback((event_2) => {
|
|
1251
1249
|
if (onFocus && onFocus(event_2), !event_2.isDefaultPrevented()) {
|
|
1252
1250
|
const selection_3 = editorProvider.PortableTextEditor.getSelection(portableTextEditor);
|
|
1253
1251
|
selection_3 === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
|