@portabletext/editor 1.6.0 → 1.6.1
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.esm.js +21 -8
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +21 -8
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +21 -8
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/editor/Editable.tsx +21 -24
- package/src/editor/withSyncRangeDecorations.ts +20 -0
package/lib/index.js
CHANGED
|
@@ -6215,6 +6215,14 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6215
6215
|
return react.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content2 }, leaf._key), [leaf, attributes, content2]);
|
|
6216
6216
|
};
|
|
6217
6217
|
Leaf.displayName = "Leaf";
|
|
6218
|
+
function withSyncRangeDecorations(slateEditor, syncRangeDecorations) {
|
|
6219
|
+
const originalApply = slateEditor.apply;
|
|
6220
|
+
return slateEditor.apply = (op) => {
|
|
6221
|
+
originalApply(op), op.type !== "set_selection" && syncRangeDecorations(op);
|
|
6222
|
+
}, () => {
|
|
6223
|
+
slateEditor.apply = originalApply;
|
|
6224
|
+
};
|
|
6225
|
+
}
|
|
6218
6226
|
const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
6219
6227
|
position: "absolute",
|
|
6220
6228
|
userSelect: "none",
|
|
@@ -6246,8 +6254,14 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6246
6254
|
react.useImperativeHandle(forwardedRef, () => ref.current);
|
|
6247
6255
|
const rangeDecorationsRef = react.useRef(rangeDecorations), editorActor = react.useContext(EditorActorContext), {
|
|
6248
6256
|
schemaTypes
|
|
6249
|
-
} = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name
|
|
6250
|
-
react.useMemo(() =>
|
|
6257
|
+
} = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name;
|
|
6258
|
+
react.useMemo(() => {
|
|
6259
|
+
const withInsertData = createWithInsertData(editorActor, schemaTypes);
|
|
6260
|
+
if (readOnly)
|
|
6261
|
+
return debug("Editable is in read only mode"), withInsertData(slateEditor);
|
|
6262
|
+
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
6263
|
+
return debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
|
|
6264
|
+
}, [editorActor, hotkeys, portableTextEditor, readOnly, schemaTypes, slateEditor]);
|
|
6251
6265
|
const renderElement = react.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = react.useCallback((lProps) => {
|
|
6252
6266
|
if (lProps.leaf._type === "span") {
|
|
6253
6267
|
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|
|
@@ -6322,16 +6336,15 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6322
6336
|
}, [editorActor, restoreSelectionFromProps]), react.useEffect(() => {
|
|
6323
6337
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
6324
6338
|
}, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
|
|
6325
|
-
const
|
|
6339
|
+
const [syncedRangeDecorations, setSyncedRangeDecorations] = react.useState(!1);
|
|
6326
6340
|
react.useEffect(() => {
|
|
6327
6341
|
syncedRangeDecorations || (setSyncedRangeDecorations(!0), syncRangeDecorations());
|
|
6328
6342
|
}, [syncRangeDecorations, syncedRangeDecorations]), react.useEffect(() => {
|
|
6329
6343
|
isEqual__default.default(rangeDecorations, rangeDecorationsRef.current) || syncRangeDecorations(), rangeDecorationsRef.current = rangeDecorations;
|
|
6330
|
-
}, [rangeDecorations, syncRangeDecorations]), react.useEffect(() =>
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
}), [originalApply, slateEditor, syncRangeDecorations]);
|
|
6344
|
+
}, [rangeDecorations, syncRangeDecorations]), react.useEffect(() => {
|
|
6345
|
+
const teardown = withSyncRangeDecorations(slateEditor, syncRangeDecorations);
|
|
6346
|
+
return () => teardown();
|
|
6347
|
+
}, [slateEditor, syncRangeDecorations]);
|
|
6335
6348
|
const handleCopy = react.useCallback((event) => {
|
|
6336
6349
|
onCopy && onCopy(event) !== void 0 && event.preventDefault();
|
|
6337
6350
|
}, [onCopy]), handlePaste = react.useCallback((event_0) => {
|