@tarviks/lexical-rich-editor 1.3.12 → 1.3.13
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/dist/index.js +39 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3198,12 +3198,16 @@ function splitHeadingsAtBrSequences(html) {
|
|
|
3198
3198
|
});
|
|
3199
3199
|
return doc.body.innerHTML;
|
|
3200
3200
|
}
|
|
3201
|
-
var CustomOnChangePlugin = ({ value, onChange }) => {
|
|
3201
|
+
var CustomOnChangePlugin = ({ value, onChange, isReadOnly }) => {
|
|
3202
3202
|
const [editor] = useLexicalComposerContext();
|
|
3203
3203
|
const initializedRef = useRef(false);
|
|
3204
|
+
const lastImportedValueRef = useRef(null);
|
|
3204
3205
|
useEffect(() => {
|
|
3205
|
-
if (!value
|
|
3206
|
+
if (!value) return;
|
|
3207
|
+
if (!isReadOnly && initializedRef.current) return;
|
|
3208
|
+
if (value === lastImportedValueRef.current) return;
|
|
3206
3209
|
initializedRef.current = true;
|
|
3210
|
+
lastImportedValueRef.current = value;
|
|
3207
3211
|
editor.update(() => {
|
|
3208
3212
|
const root = $getRoot();
|
|
3209
3213
|
root.clear();
|
|
@@ -3214,14 +3218,17 @@ var CustomOnChangePlugin = ({ value, onChange }) => {
|
|
|
3214
3218
|
const nodes = $generateNodesFromDOM(editor, dom);
|
|
3215
3219
|
root.append(...nodes);
|
|
3216
3220
|
});
|
|
3217
|
-
}, [editor, value]);
|
|
3221
|
+
}, [editor, value, isReadOnly]);
|
|
3218
3222
|
return /* @__PURE__ */ jsx(
|
|
3219
3223
|
OnChangePlugin,
|
|
3220
3224
|
{
|
|
3225
|
+
ignoreSelectionChange: true,
|
|
3221
3226
|
onChange: (editorState) => {
|
|
3222
3227
|
editorState.read(() => {
|
|
3223
3228
|
const raw = $generateHtmlFromNodes(editor);
|
|
3224
|
-
|
|
3229
|
+
const html = postProcessOutput(splitHeadingsAtBrSequences(raw));
|
|
3230
|
+
lastImportedValueRef.current = html;
|
|
3231
|
+
onChange(html);
|
|
3225
3232
|
});
|
|
3226
3233
|
}
|
|
3227
3234
|
}
|
|
@@ -5354,9 +5361,25 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
5354
5361
|
const canShow = isInTable && !!anchorRect && isAnchorVisible && !disabled;
|
|
5355
5362
|
const handleStyle = React9.useMemo(() => {
|
|
5356
5363
|
if (!anchorRect) return void 0;
|
|
5357
|
-
const
|
|
5358
|
-
const
|
|
5359
|
-
const
|
|
5364
|
+
const BUTTON_SIZE = 28;
|
|
5365
|
+
const PAD = 8;
|
|
5366
|
+
const editorRect = editor.getRootElement()?.getBoundingClientRect();
|
|
5367
|
+
const clipRect = editorRect ? {
|
|
5368
|
+
top: Math.max(editorRect.top, 0),
|
|
5369
|
+
left: Math.max(editorRect.left, 0),
|
|
5370
|
+
right: Math.min(editorRect.right, window.innerWidth),
|
|
5371
|
+
bottom: Math.min(editorRect.bottom, window.innerHeight)
|
|
5372
|
+
} : { top: 0, left: 0, right: window.innerWidth, bottom: window.innerHeight };
|
|
5373
|
+
const isCellVisible = anchorRect.bottom > clipRect.top && anchorRect.top < clipRect.bottom && anchorRect.right > clipRect.left && anchorRect.left < clipRect.right;
|
|
5374
|
+
if (!isCellVisible) return void 0;
|
|
5375
|
+
const minTop = editorRect ? editorRect.top + PAD : PAD;
|
|
5376
|
+
const maxTop = editorRect ? Math.max(minTop, editorRect.bottom - BUTTON_SIZE - PAD) : window.innerHeight - BUTTON_SIZE - PAD;
|
|
5377
|
+
const minLeft = editorRect ? editorRect.left + PAD : PAD;
|
|
5378
|
+
const maxLeft = editorRect ? Math.max(minLeft, editorRect.right - BUTTON_SIZE - PAD) : window.innerWidth - BUTTON_SIZE - PAD;
|
|
5379
|
+
const top = Math.min(Math.max(anchorRect.top + 6, minTop), maxTop);
|
|
5380
|
+
const clampedCellRight = Math.min(anchorRect.right, maxLeft + BUTTON_SIZE);
|
|
5381
|
+
const rawLeft = contentRight !== null ? Math.max(anchorRect.left + 4, Math.min(contentRight + 4, clampedCellRight - 32)) : anchorRect.left + 8;
|
|
5382
|
+
const left = Math.min(Math.max(rawLeft, minLeft), maxLeft);
|
|
5360
5383
|
return {
|
|
5361
5384
|
position: "fixed",
|
|
5362
5385
|
top,
|
|
@@ -5366,7 +5389,7 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
5366
5389
|
// button renders behind the modal chrome in a full-page/Panel view.
|
|
5367
5390
|
zIndex: 10000010
|
|
5368
5391
|
};
|
|
5369
|
-
}, [anchorRect, contentRight]);
|
|
5392
|
+
}, [anchorRect, contentRight, editor]);
|
|
5370
5393
|
const dangerStyle = {
|
|
5371
5394
|
color: "var(--colorPaletteRedForeground1)"
|
|
5372
5395
|
};
|
|
@@ -8641,7 +8664,14 @@ var ContentEditorComponent = forwardRef(
|
|
|
8641
8664
|
}
|
|
8642
8665
|
),
|
|
8643
8666
|
!isReadOnly && props.showFloatingToolbar && /* @__PURE__ */ jsx(CharacterStylesPopupPlugin, {}),
|
|
8644
|
-
/* @__PURE__ */ jsx(
|
|
8667
|
+
/* @__PURE__ */ jsx(
|
|
8668
|
+
CustomOnChangePlugin,
|
|
8669
|
+
{
|
|
8670
|
+
value: props.value,
|
|
8671
|
+
onChange: props.onChange,
|
|
8672
|
+
isReadOnly
|
|
8673
|
+
}
|
|
8674
|
+
),
|
|
8645
8675
|
(props.wordLimit !== void 0 || props.required || props.minWords !== void 0 || props.maxWords !== void 0 || props.minChars !== void 0 || props.maxChars !== void 0 || props.noImages || props.maxImages !== void 0 || props.noLinks || props.maxLinks !== void 0 || props.noTables) && /* @__PURE__ */ jsx(ContentMetricsPlugin, { onMetricsChange: handleMetrics }),
|
|
8646
8676
|
/* @__PURE__ */ jsx(
|
|
8647
8677
|
RefApiPlugin,
|