@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.js
CHANGED
|
@@ -3219,12 +3219,16 @@ function splitHeadingsAtBrSequences(html) {
|
|
|
3219
3219
|
});
|
|
3220
3220
|
return doc.body.innerHTML;
|
|
3221
3221
|
}
|
|
3222
|
-
var CustomOnChangePlugin = ({ value, onChange }) => {
|
|
3222
|
+
var CustomOnChangePlugin = ({ value, onChange, isReadOnly }) => {
|
|
3223
3223
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
3224
3224
|
const initializedRef = React9.useRef(false);
|
|
3225
|
+
const lastImportedValueRef = React9.useRef(null);
|
|
3225
3226
|
React9.useEffect(() => {
|
|
3226
|
-
if (!value
|
|
3227
|
+
if (!value) return;
|
|
3228
|
+
if (!isReadOnly && initializedRef.current) return;
|
|
3229
|
+
if (value === lastImportedValueRef.current) return;
|
|
3227
3230
|
initializedRef.current = true;
|
|
3231
|
+
lastImportedValueRef.current = value;
|
|
3228
3232
|
editor.update(() => {
|
|
3229
3233
|
const root = lexical.$getRoot();
|
|
3230
3234
|
root.clear();
|
|
@@ -3235,14 +3239,17 @@ var CustomOnChangePlugin = ({ value, onChange }) => {
|
|
|
3235
3239
|
const nodes = html.$generateNodesFromDOM(editor, dom);
|
|
3236
3240
|
root.append(...nodes);
|
|
3237
3241
|
});
|
|
3238
|
-
}, [editor, value]);
|
|
3242
|
+
}, [editor, value, isReadOnly]);
|
|
3239
3243
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3240
3244
|
LexicalOnChangePlugin.OnChangePlugin,
|
|
3241
3245
|
{
|
|
3246
|
+
ignoreSelectionChange: true,
|
|
3242
3247
|
onChange: (editorState) => {
|
|
3243
3248
|
editorState.read(() => {
|
|
3244
3249
|
const raw = html.$generateHtmlFromNodes(editor);
|
|
3245
|
-
|
|
3250
|
+
const html$1 = postProcessOutput(splitHeadingsAtBrSequences(raw));
|
|
3251
|
+
lastImportedValueRef.current = html$1;
|
|
3252
|
+
onChange(html$1);
|
|
3246
3253
|
});
|
|
3247
3254
|
}
|
|
3248
3255
|
}
|
|
@@ -5375,9 +5382,25 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
5375
5382
|
const canShow = isInTable && !!anchorRect && isAnchorVisible && !disabled;
|
|
5376
5383
|
const handleStyle = React9__namespace.useMemo(() => {
|
|
5377
5384
|
if (!anchorRect) return void 0;
|
|
5378
|
-
const
|
|
5379
|
-
const
|
|
5380
|
-
const
|
|
5385
|
+
const BUTTON_SIZE = 28;
|
|
5386
|
+
const PAD = 8;
|
|
5387
|
+
const editorRect = editor.getRootElement()?.getBoundingClientRect();
|
|
5388
|
+
const clipRect = editorRect ? {
|
|
5389
|
+
top: Math.max(editorRect.top, 0),
|
|
5390
|
+
left: Math.max(editorRect.left, 0),
|
|
5391
|
+
right: Math.min(editorRect.right, window.innerWidth),
|
|
5392
|
+
bottom: Math.min(editorRect.bottom, window.innerHeight)
|
|
5393
|
+
} : { top: 0, left: 0, right: window.innerWidth, bottom: window.innerHeight };
|
|
5394
|
+
const isCellVisible = anchorRect.bottom > clipRect.top && anchorRect.top < clipRect.bottom && anchorRect.right > clipRect.left && anchorRect.left < clipRect.right;
|
|
5395
|
+
if (!isCellVisible) return void 0;
|
|
5396
|
+
const minTop = editorRect ? editorRect.top + PAD : PAD;
|
|
5397
|
+
const maxTop = editorRect ? Math.max(minTop, editorRect.bottom - BUTTON_SIZE - PAD) : window.innerHeight - BUTTON_SIZE - PAD;
|
|
5398
|
+
const minLeft = editorRect ? editorRect.left + PAD : PAD;
|
|
5399
|
+
const maxLeft = editorRect ? Math.max(minLeft, editorRect.right - BUTTON_SIZE - PAD) : window.innerWidth - BUTTON_SIZE - PAD;
|
|
5400
|
+
const top = Math.min(Math.max(anchorRect.top + 6, minTop), maxTop);
|
|
5401
|
+
const clampedCellRight = Math.min(anchorRect.right, maxLeft + BUTTON_SIZE);
|
|
5402
|
+
const rawLeft = contentRight !== null ? Math.max(anchorRect.left + 4, Math.min(contentRight + 4, clampedCellRight - 32)) : anchorRect.left + 8;
|
|
5403
|
+
const left = Math.min(Math.max(rawLeft, minLeft), maxLeft);
|
|
5381
5404
|
return {
|
|
5382
5405
|
position: "fixed",
|
|
5383
5406
|
top,
|
|
@@ -5387,7 +5410,7 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
5387
5410
|
// button renders behind the modal chrome in a full-page/Panel view.
|
|
5388
5411
|
zIndex: 10000010
|
|
5389
5412
|
};
|
|
5390
|
-
}, [anchorRect, contentRight]);
|
|
5413
|
+
}, [anchorRect, contentRight, editor]);
|
|
5391
5414
|
const dangerStyle = {
|
|
5392
5415
|
color: "var(--colorPaletteRedForeground1)"
|
|
5393
5416
|
};
|
|
@@ -8662,7 +8685,14 @@ var ContentEditorComponent = React9.forwardRef(
|
|
|
8662
8685
|
}
|
|
8663
8686
|
),
|
|
8664
8687
|
!isReadOnly && props.showFloatingToolbar && /* @__PURE__ */ jsxRuntime.jsx(CharacterStylesPopupPlugin, {}),
|
|
8665
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8688
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8689
|
+
CustomOnChangePlugin,
|
|
8690
|
+
{
|
|
8691
|
+
value: props.value,
|
|
8692
|
+
onChange: props.onChange,
|
|
8693
|
+
isReadOnly
|
|
8694
|
+
}
|
|
8695
|
+
),
|
|
8666
8696
|
(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__ */ jsxRuntime.jsx(ContentMetricsPlugin, { onMetricsChange: handleMetrics }),
|
|
8667
8697
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
8668
8698
|
RefApiPlugin,
|