@tarviks/lexical-rich-editor 1.0.1 → 1.0.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/LICENSE +21 -0
- package/README.md +198 -198
- package/dist/index.js +96 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -90
- package/dist/index.mjs.map +1 -1
- package/package.json +92 -92
package/dist/index.js
CHANGED
|
@@ -2463,6 +2463,8 @@ function CharacterStylesPopupPlugin(props) {
|
|
|
2463
2463
|
var CustomOnChangePlugin = ({ value, onChange }) => {
|
|
2464
2464
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
2465
2465
|
const initializedRef = React6.useRef(false);
|
|
2466
|
+
const onChangeRef = React6.useRef(onChange);
|
|
2467
|
+
onChangeRef.current = onChange;
|
|
2466
2468
|
React6.useEffect(() => {
|
|
2467
2469
|
if (!value || initializedRef.current) return;
|
|
2468
2470
|
initializedRef.current = true;
|
|
@@ -2473,16 +2475,19 @@ var CustomOnChangePlugin = ({ value, onChange }) => {
|
|
|
2473
2475
|
const dom = parser.parseFromString(value, "text/html");
|
|
2474
2476
|
const nodes = html.$generateNodesFromDOM(editor, dom);
|
|
2475
2477
|
root.append(...nodes);
|
|
2478
|
+
lexical.$setSelection(null);
|
|
2476
2479
|
});
|
|
2477
2480
|
}, [editor, value]);
|
|
2481
|
+
const handleChange = React6.useCallback((editorState) => {
|
|
2482
|
+
editorState.read(() => {
|
|
2483
|
+
onChangeRef.current(html.$generateHtmlFromNodes(editor));
|
|
2484
|
+
});
|
|
2485
|
+
}, [editor]);
|
|
2478
2486
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2479
2487
|
LexicalOnChangePlugin.OnChangePlugin,
|
|
2480
2488
|
{
|
|
2481
|
-
onChange:
|
|
2482
|
-
|
|
2483
|
-
onChange(html.$generateHtmlFromNodes(editor));
|
|
2484
|
-
});
|
|
2485
|
-
}
|
|
2489
|
+
onChange: handleChange,
|
|
2490
|
+
ignoreSelectionChange: true
|
|
2486
2491
|
}
|
|
2487
2492
|
);
|
|
2488
2493
|
};
|
|
@@ -4294,8 +4299,8 @@ function SpellCheckPlugin({
|
|
|
4294
4299
|
function TableActionMenuPlugin({ disabled = false }) {
|
|
4295
4300
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
4296
4301
|
const [isInTable, setIsInTable] = React6__namespace.useState(false);
|
|
4297
|
-
const [anchorRect, setAnchorRect] = React6__namespace.useState(null);
|
|
4298
4302
|
const [open, setOpen] = React6__namespace.useState(false);
|
|
4303
|
+
const [menuPos, setMenuPos] = React6__namespace.useState(null);
|
|
4299
4304
|
const updateFromSelection = React6__namespace.useCallback(() => {
|
|
4300
4305
|
const root = editor.getRootElement();
|
|
4301
4306
|
if (!root) return;
|
|
@@ -4304,34 +4309,21 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
4304
4309
|
if (table.$isTableSelection(selection)) {
|
|
4305
4310
|
const tableNode = selection.getNodes().find((n) => table.$isTableNode(n));
|
|
4306
4311
|
if (tableNode) {
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
setIsInTable(true);
|
|
4310
|
-
setAnchorRect(dom.getBoundingClientRect());
|
|
4311
|
-
return;
|
|
4312
|
-
}
|
|
4312
|
+
setIsInTable(true);
|
|
4313
|
+
return;
|
|
4313
4314
|
}
|
|
4314
4315
|
}
|
|
4315
4316
|
if (!lexical.$isRangeSelection(selection)) {
|
|
4316
4317
|
setIsInTable(false);
|
|
4317
|
-
setAnchorRect(null);
|
|
4318
4318
|
return;
|
|
4319
4319
|
}
|
|
4320
4320
|
const anchorNode = selection.anchor.getNode();
|
|
4321
4321
|
const cellNode = table.$isTableCellNode(anchorNode) ? anchorNode : lexical.$findMatchingParent(anchorNode, (n) => table.$isTableCellNode(n));
|
|
4322
4322
|
if (!cellNode || !table.$isTableCellNode(cellNode)) {
|
|
4323
4323
|
setIsInTable(false);
|
|
4324
|
-
setAnchorRect(null);
|
|
4325
|
-
return;
|
|
4326
|
-
}
|
|
4327
|
-
const cellDom = editor.getElementByKey(cellNode.getKey());
|
|
4328
|
-
if (!cellDom) {
|
|
4329
|
-
setIsInTable(false);
|
|
4330
|
-
setAnchorRect(null);
|
|
4331
4324
|
return;
|
|
4332
4325
|
}
|
|
4333
4326
|
setIsInTable(true);
|
|
4334
|
-
setAnchorRect(cellDom.getBoundingClientRect());
|
|
4335
4327
|
});
|
|
4336
4328
|
}, [editor]);
|
|
4337
4329
|
React6__namespace.useEffect(() => {
|
|
@@ -4393,18 +4385,33 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
4393
4385
|
React6__namespace.useEffect(() => {
|
|
4394
4386
|
if (!isInTable && open) setOpen(false);
|
|
4395
4387
|
}, [isInTable, open]);
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
if (!
|
|
4399
|
-
const
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4388
|
+
React6__namespace.useEffect(() => {
|
|
4389
|
+
const root = editor.getRootElement();
|
|
4390
|
+
if (!root) return;
|
|
4391
|
+
const handleContextMenu = (e) => {
|
|
4392
|
+
if (disabled) return;
|
|
4393
|
+
let inTable = false;
|
|
4394
|
+
editor.getEditorState().read(() => {
|
|
4395
|
+
const selection = lexical.$getSelection();
|
|
4396
|
+
if (table.$isTableSelection(selection)) {
|
|
4397
|
+
inTable = true;
|
|
4398
|
+
return;
|
|
4399
|
+
}
|
|
4400
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
4401
|
+
const node = selection.anchor.getNode();
|
|
4402
|
+
const cell = table.$isTableCellNode(node) ? node : lexical.$findMatchingParent(node, (n) => table.$isTableCellNode(n));
|
|
4403
|
+
if (cell) inTable = true;
|
|
4404
|
+
}
|
|
4405
|
+
});
|
|
4406
|
+
if (inTable) {
|
|
4407
|
+
e.preventDefault();
|
|
4408
|
+
setMenuPos({ x: e.clientX, y: e.clientY });
|
|
4409
|
+
setOpen(true);
|
|
4410
|
+
}
|
|
4406
4411
|
};
|
|
4407
|
-
|
|
4412
|
+
root.addEventListener("contextmenu", handleContextMenu);
|
|
4413
|
+
return () => root.removeEventListener("contextmenu", handleContextMenu);
|
|
4414
|
+
}, [editor, disabled]);
|
|
4408
4415
|
const dangerStyle = {
|
|
4409
4416
|
color: "var(--colorPaletteRedForeground1)"
|
|
4410
4417
|
};
|
|
@@ -4437,63 +4444,55 @@ function TableActionMenuPlugin({ disabled = false }) {
|
|
|
4437
4444
|
const table$1 = table.$getTableNodeFromLexicalNodeOrThrow(cell);
|
|
4438
4445
|
table$1.remove();
|
|
4439
4446
|
});
|
|
4440
|
-
|
|
4447
|
+
const virtualTarget = React6__namespace.useMemo(() => {
|
|
4448
|
+
if (!menuPos) return void 0;
|
|
4449
|
+
return {
|
|
4450
|
+
getBoundingClientRect: () => new DOMRect(menuPos.x, menuPos.y, 0, 0)
|
|
4451
|
+
};
|
|
4452
|
+
}, [menuPos]);
|
|
4453
|
+
if (disabled) return null;
|
|
4441
4454
|
return reactDom.createPortal(
|
|
4442
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4443
|
-
/* @__PURE__ */ jsxRuntime.
|
|
4444
|
-
"
|
|
4445
|
-
{
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4458
|
-
|
|
4459
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuLabel", children: [
|
|
4460
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactIcons.ArrowUpRegular, {}),
|
|
4461
|
-
" Row above"
|
|
4462
|
-
] }),
|
|
4463
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "aoMenuShortcut", children: "Alt \u21E7 \u2191" })
|
|
4464
|
-
] }) }),
|
|
4465
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuItem, { icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.RowTripleRegular, {}), onClick: insertRowBelow, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuRow", children: [
|
|
4466
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuLabel", children: [
|
|
4467
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactIcons.ArrowDownRegular, {}),
|
|
4468
|
-
" Row below"
|
|
4469
|
-
] }),
|
|
4470
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "aoMenuShortcut", children: "Alt \u21E7 \u2193" })
|
|
4471
|
-
] }) }),
|
|
4472
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuDivider, {}),
|
|
4473
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuItem, { icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.ColumnTripleRegular, {}), onClick: insertColLeft, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuRow", children: [
|
|
4474
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuLabel", children: [
|
|
4475
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactIcons.ArrowLeftRegular, {}),
|
|
4476
|
-
" Column left"
|
|
4477
|
-
] }),
|
|
4478
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "aoMenuShortcut", children: "Alt \u21E7 \u2190" })
|
|
4479
|
-
] }) }),
|
|
4480
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuItem, { icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.ColumnTripleRegular, {}), onClick: insertColRight, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuRow", children: [
|
|
4481
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuLabel", children: [
|
|
4482
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactIcons.ArrowRightRegular, {}),
|
|
4483
|
-
" Column right"
|
|
4484
|
-
] }),
|
|
4485
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "aoMenuShortcut", children: "Alt \u21E7 \u2192" })
|
|
4486
|
-
] }) })
|
|
4487
|
-
] }),
|
|
4455
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.Menu, { open, onOpenChange: (_, data) => setOpen(data.open), positioning: { target: virtualTarget }, children: /* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuPopover, { className: "aoTableActionPopover", children: /* @__PURE__ */ jsxRuntime.jsxs(reactComponents.MenuList, { children: [
|
|
4456
|
+
/* @__PURE__ */ jsxRuntime.jsxs(reactComponents.MenuGroup, { children: [
|
|
4457
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuGroupHeader, { children: "Insert" }),
|
|
4458
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuItem, { icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.RowTripleRegular, {}), onClick: insertRowAbove, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuRow", children: [
|
|
4459
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuLabel", children: [
|
|
4460
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactIcons.ArrowUpRegular, {}),
|
|
4461
|
+
" Row above"
|
|
4462
|
+
] }),
|
|
4463
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "aoMenuShortcut", children: "Alt \u21E7 \u2191" })
|
|
4464
|
+
] }) }),
|
|
4465
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuItem, { icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.RowTripleRegular, {}), onClick: insertRowBelow, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuRow", children: [
|
|
4466
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuLabel", children: [
|
|
4467
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactIcons.ArrowDownRegular, {}),
|
|
4468
|
+
" Row below"
|
|
4469
|
+
] }),
|
|
4470
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "aoMenuShortcut", children: "Alt \u21E7 \u2193" })
|
|
4471
|
+
] }) }),
|
|
4488
4472
|
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuDivider, {}),
|
|
4489
|
-
/* @__PURE__ */ jsxRuntime.
|
|
4490
|
-
/* @__PURE__ */ jsxRuntime.
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4473
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuItem, { icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.ColumnTripleRegular, {}), onClick: insertColLeft, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuRow", children: [
|
|
4474
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuLabel", children: [
|
|
4475
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactIcons.ArrowLeftRegular, {}),
|
|
4476
|
+
" Column left"
|
|
4477
|
+
] }),
|
|
4478
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "aoMenuShortcut", children: "Alt \u21E7 \u2190" })
|
|
4479
|
+
] }) }),
|
|
4480
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuItem, { icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.ColumnTripleRegular, {}), onClick: insertColRight, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuRow", children: [
|
|
4481
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "aoMenuLabel", children: [
|
|
4482
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactIcons.ArrowRightRegular, {}),
|
|
4483
|
+
" Column right"
|
|
4484
|
+
] }),
|
|
4485
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "aoMenuShortcut", children: "Alt \u21E7 \u2192" })
|
|
4486
|
+
] }) })
|
|
4487
|
+
] }),
|
|
4488
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuDivider, {}),
|
|
4489
|
+
/* @__PURE__ */ jsxRuntime.jsxs(reactComponents.MenuGroup, { children: [
|
|
4490
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuGroupHeader, { children: "Delete" }),
|
|
4491
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuItem, { icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.DeleteRegular, {}), onClick: deleteRow, style: dangerStyle, children: "Delete row" }),
|
|
4492
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuItem, { icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.DeleteRegular, {}), onClick: deleteCol, style: dangerStyle, children: "Delete column" }),
|
|
4493
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactComponents.MenuItem, { icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.DeleteRegular, {}), onClick: deleteTable, style: dangerStyle, children: "Delete table" })
|
|
4494
|
+
] })
|
|
4495
|
+
] }) }) }),
|
|
4497
4496
|
document.body
|
|
4498
4497
|
);
|
|
4499
4498
|
}
|
|
@@ -6486,6 +6485,9 @@ function FocusEventsPlugin({
|
|
|
6486
6485
|
const next = e.relatedTarget;
|
|
6487
6486
|
const stillInside = !!next && root.contains(next);
|
|
6488
6487
|
if (stillInside) return;
|
|
6488
|
+
editor.update(() => {
|
|
6489
|
+
lexical.$setSelection(null);
|
|
6490
|
+
});
|
|
6489
6491
|
setFocused(false);
|
|
6490
6492
|
onBlur?.();
|
|
6491
6493
|
};
|
|
@@ -6856,7 +6858,13 @@ var ContentEditorComponent = React6.forwardRef(
|
|
|
6856
6858
|
}
|
|
6857
6859
|
),
|
|
6858
6860
|
!isReadOnly && props.showFloatingToolbar && /* @__PURE__ */ jsxRuntime.jsx(CharacterStylesPopupPlugin, {}),
|
|
6859
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6861
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6862
|
+
CustomOnChangePlugin,
|
|
6863
|
+
{
|
|
6864
|
+
value: props.value,
|
|
6865
|
+
onChange: props.onChange
|
|
6866
|
+
}
|
|
6867
|
+
),
|
|
6860
6868
|
props.wordLimit !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(WordCountPlugin, { onCountChange: handleWordCount }),
|
|
6861
6869
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6862
6870
|
RefApiPlugin,
|