@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.js
CHANGED
|
@@ -1050,18 +1050,18 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1050
1050
|
useImperativeHandle(forwardedRef, () => ref.current);
|
|
1051
1051
|
const editorActor = useContext(EditorActorContext), readOnly = useSelector(editorActor, (s) => s.matches({
|
|
1052
1052
|
"edit mode": "read only"
|
|
1053
|
-
})),
|
|
1053
|
+
})), slateEditor = useSlate(), rangeDecorationsActor = useActorRef(rangeDecorationsMachine, {
|
|
1054
1054
|
input: {
|
|
1055
1055
|
rangeDecorations: rangeDecorations ?? [],
|
|
1056
1056
|
readOnly,
|
|
1057
|
-
schema:
|
|
1057
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1058
1058
|
slateEditor,
|
|
1059
1059
|
skipSetup: !editorActor.getSnapshot().matches({
|
|
1060
1060
|
setup: "setting up"
|
|
1061
1061
|
})
|
|
1062
1062
|
}
|
|
1063
1063
|
});
|
|
1064
|
-
useSelector(rangeDecorationsActor, (
|
|
1064
|
+
useSelector(rangeDecorationsActor, (s_0) => s_0.context.updateCount);
|
|
1065
1065
|
const decorate = useMemo(() => createDecorate(rangeDecorationsActor), [rangeDecorationsActor]);
|
|
1066
1066
|
useEffect(() => {
|
|
1067
1067
|
rangeDecorationsActor.send({
|
|
@@ -1073,9 +1073,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1073
1073
|
type: "range decorations updated",
|
|
1074
1074
|
rangeDecorations: rangeDecorations ?? []
|
|
1075
1075
|
});
|
|
1076
|
-
}, [rangeDecorationsActor, rangeDecorations])
|
|
1077
|
-
const blockTypeName = schemaTypes.block.name;
|
|
1078
|
-
useMemo(() => {
|
|
1076
|
+
}, [rangeDecorationsActor, rangeDecorations]), useMemo(() => {
|
|
1079
1077
|
if (readOnly)
|
|
1080
1078
|
return debug("Editable is in read only mode"), slateEditor;
|
|
1081
1079
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
@@ -1095,10 +1093,10 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1095
1093
|
})), rendered;
|
|
1096
1094
|
}
|
|
1097
1095
|
return lProps.children;
|
|
1098
|
-
}, [editorActor, portableTextEditor
|
|
1096
|
+
}, [editorActor, portableTextEditor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder]), restoreSelectionFromProps = useCallback(() => {
|
|
1099
1097
|
if (propsSelection) {
|
|
1100
1098
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
1101
|
-
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children,
|
|
1099
|
+
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
1102
1100
|
if (normalizedSelection !== null) {
|
|
1103
1101
|
debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
1104
1102
|
const slateRange = toSlateRange(normalizedSelection, slateEditor);
|
|
@@ -1108,7 +1106,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1108
1106
|
}), slateEditor.onChange());
|
|
1109
1107
|
}
|
|
1110
1108
|
}
|
|
1111
|
-
}, [
|
|
1109
|
+
}, [editorActor, propsSelection, slateEditor]);
|
|
1112
1110
|
useEffect(() => {
|
|
1113
1111
|
const onReady = editorActor.on("ready", () => {
|
|
1114
1112
|
rangeDecorationsActor.send({
|
|
@@ -1181,7 +1179,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1181
1179
|
}
|
|
1182
1180
|
}, [onCut, editorActor, slateEditor]), handlePaste = useCallback((event_1) => {
|
|
1183
1181
|
const value = PortableTextEditor.getValue(portableTextEditor), path = (slateEditor.selection ? slateRangeToSelection({
|
|
1184
|
-
schema:
|
|
1182
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1185
1183
|
editor: slateEditor,
|
|
1186
1184
|
range: slateEditor.selection
|
|
1187
1185
|
}) : null)?.focus.path || [], onPasteResult = onPaste?.({
|
|
@@ -1261,7 +1259,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
1261
1259
|
});
|
|
1262
1260
|
}
|
|
1263
1261
|
debug("No result from custom paste handler, pasting normally");
|
|
1264
|
-
}, [editorActor, onPaste, portableTextEditor,
|
|
1262
|
+
}, [editorActor, onPaste, portableTextEditor, slateEditor]), handleOnFocus = useCallback((event_2) => {
|
|
1265
1263
|
if (onFocus && onFocus(event_2), !event_2.isDefaultPrevented()) {
|
|
1266
1264
|
const selection_3 = PortableTextEditor.getSelection(portableTextEditor);
|
|
1267
1265
|
selection_3 === null && (Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
|