@innoviatech/lexical-text-editor 2.0.6 → 3.0.0

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.
Files changed (111) hide show
  1. package/README.md +390 -241
  2. package/dist/components/AlignmentSelectionList.js +19 -0
  3. package/dist/components/ColorPicker.js +30 -0
  4. package/dist/components/ContentPreview.js +11 -0
  5. package/dist/components/DisplayControls.d.ts +16 -0
  6. package/dist/components/DropdownList.js +18 -0
  7. package/dist/components/FindReplaceModal.d.ts +11 -0
  8. package/dist/components/FindReplaceModal.js +120 -0
  9. package/dist/components/FontSelectionList.d.ts +17 -0
  10. package/dist/components/FontSelectionList.js +17 -0
  11. package/dist/components/HeadingSelectionList.js +19 -0
  12. package/dist/components/ImageComponent.d.ts +1 -0
  13. package/dist/components/ImageComponent.js +111 -0
  14. package/dist/components/InsertDropdownList.js +17 -0
  15. package/dist/components/LexicalTextEditor.d.ts +11 -0
  16. package/dist/components/LexicalTextEditor.js +128 -0
  17. package/dist/components/LinkModal.js +47 -0
  18. package/dist/components/Separator.js +4 -0
  19. package/dist/components/SourceView.d.ts +13 -0
  20. package/dist/components/SourceView.js +50 -0
  21. package/dist/components/StatusBar.d.ts +14 -0
  22. package/dist/components/StatusBar.js +30 -0
  23. package/dist/components/ToolbarOverflowModal.d.ts +15 -0
  24. package/dist/components/common/Dialog.js +27 -0
  25. package/dist/components/common/Popover.d.ts +10 -1
  26. package/dist/components/common/Popover.js +37 -0
  27. package/dist/components/common/Tooltip.d.ts +7 -0
  28. package/dist/components/common/Tooltip.js +20 -0
  29. package/dist/components/ui/button.js +35 -0
  30. package/dist/components/ui/command.js +33 -0
  31. package/dist/components/ui/dialog.js +35 -0
  32. package/dist/components/ui/input.js +6 -0
  33. package/dist/components/ui/popover.js +16 -0
  34. package/dist/components/ui/scroll-area.js +12 -0
  35. package/dist/components/ui/tooltip.js +16 -0
  36. package/dist/constants/index.d.ts +23 -1
  37. package/dist/constants/index.js +224 -0
  38. package/dist/index.d.ts +11 -0
  39. package/dist/index.esm.js +1 -1
  40. package/dist/index.esm.js.map +1 -1
  41. package/dist/index.js +1 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/lexical-editor.css +1 -1
  44. package/dist/lib/utils.js +5 -0
  45. package/dist/nodes/ExtendedTextNode.js +140 -0
  46. package/dist/nodes/ImageNode.d.ts +5 -1
  47. package/dist/nodes/ImageNode.js +149 -0
  48. package/dist/nodes/VideoNode.js +80 -0
  49. package/dist/nodes/YoutubeNode.js +64 -0
  50. package/dist/plugins/CodeBlockPlugin.d.ts +1 -0
  51. package/dist/plugins/CodeBlockPlugin.js +88 -0
  52. package/dist/plugins/ColorPlugin.js +47 -0
  53. package/dist/plugins/CustomOnChangePlugin.js +33 -0
  54. package/dist/plugins/FontFamilyPlugin.d.ts +1 -0
  55. package/dist/plugins/FontFamilyPlugin.js +53 -0
  56. package/dist/plugins/FontSizePlugin.d.ts +1 -0
  57. package/dist/plugins/FontSizePlugin.js +48 -0
  58. package/dist/plugins/ImagePlugin.d.ts +3 -1
  59. package/dist/plugins/ImagePlugin.js +91 -0
  60. package/dist/plugins/ListPlugin.js +44 -0
  61. package/dist/plugins/TablePlugin.d.ts +1 -0
  62. package/dist/plugins/TablePlugin.js +92 -0
  63. package/dist/plugins/ToolbarPlugin.d.ts +14 -1
  64. package/dist/plugins/ToolbarPlugin.js +381 -0
  65. package/dist/plugins/VideoPlugin.js +49 -0
  66. package/dist/plugins/YoutubePlugin.js +30 -0
  67. package/dist/tsconfig.tsbuildinfo +1 -0
  68. package/editor_screenshot.png +0 -0
  69. package/package.json +11 -4
  70. package/googlebd703883f12c69e4.html +0 -1
  71. package/rollup.config.js +0 -55
  72. package/src/components/AlignmentSelectionList.tsx +0 -61
  73. package/src/components/ColorPicker.tsx +0 -66
  74. package/src/components/ContentPreview.tsx +0 -51
  75. package/src/components/DropdownList.tsx +0 -57
  76. package/src/components/HeadingSelectionList.tsx +0 -61
  77. package/src/components/ImageComponent.tsx +0 -140
  78. package/src/components/InsertDropdownList.tsx +0 -36
  79. package/src/components/LexicalTextEditor.tsx +0 -119
  80. package/src/components/LinkModal.tsx +0 -127
  81. package/src/components/Separator.tsx +0 -7
  82. package/src/components/common/Dialog.tsx +0 -47
  83. package/src/components/common/Popover.tsx +0 -87
  84. package/src/components/common/Tooltip.tsx +0 -43
  85. package/src/components/ui/button.tsx +0 -58
  86. package/src/components/ui/command.tsx +0 -183
  87. package/src/components/ui/dialog.tsx +0 -142
  88. package/src/components/ui/input.tsx +0 -21
  89. package/src/components/ui/popover.tsx +0 -46
  90. package/src/components/ui/scroll-area.tsx +0 -56
  91. package/src/components/ui/tooltip.tsx +0 -59
  92. package/src/constants/index.tsx +0 -177
  93. package/src/index.ts +0 -6
  94. package/src/lib/utils.ts +0 -6
  95. package/src/nodes/ExtendedTextNode.tsx +0 -185
  96. package/src/nodes/ImageNode.tsx +0 -195
  97. package/src/nodes/VideoNode.tsx +0 -134
  98. package/src/nodes/YoutubeNode.tsx +0 -101
  99. package/src/plugins/ColorPlugin.tsx +0 -85
  100. package/src/plugins/CustomOnChangePlugin.tsx +0 -50
  101. package/src/plugins/ImagePlugin.tsx +0 -118
  102. package/src/plugins/ListPlugin.tsx +0 -58
  103. package/src/plugins/ToolbarPlugin.tsx +0 -500
  104. package/src/plugins/VideoPlugin.tsx +0 -100
  105. package/src/plugins/YoutubePlugin.tsx +0 -83
  106. package/src/styles/lexical-editor.css +0 -1053
  107. package/src/types/global.d.ts +0 -34
  108. package/src/types/other.d.ts +0 -11
  109. package/src/types/react-icons.d.ts +0 -11
  110. package/tailwind.config.js +0 -10
  111. package/tsconfig.json +0 -32
@@ -0,0 +1,47 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import ColorPicker from '../components/ColorPicker';
3
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
4
+ import { $getSelection, $isRangeSelection, SELECTION_CHANGE_COMMAND } from 'lexical';
5
+ import { $patchStyleText, $getSelectionStyleValueForProperty } from '@lexical/selection';
6
+ import { useEffect, useState } from 'react';
7
+ import { mergeRegister } from '@lexical/utils';
8
+ import { LOW_PRIORIRTY } from '../constants';
9
+ import { AiOutlineBgColors, AiOutlineFontColors } from 'react-icons/ai';
10
+ import TooltipX from '../components/common/Tooltip';
11
+ export default function ColorPlugin() {
12
+ const [editor] = useLexicalComposerContext();
13
+ const [{ color, bgColor }, setColors] = useState({
14
+ color: '#000',
15
+ bgColor: '#fff'
16
+ });
17
+ const updateToolbar = () => {
18
+ const selection = $getSelection();
19
+ if ($isRangeSelection(selection)) {
20
+ const color = $getSelectionStyleValueForProperty(selection, "color", "#000");
21
+ const bgColor = $getSelectionStyleValueForProperty(selection, "background", "#fff");
22
+ setColors({ color, bgColor });
23
+ }
24
+ };
25
+ useEffect(() => {
26
+ return mergeRegister(editor.registerUpdateListener(({ editorState }) => {
27
+ editorState.read(() => {
28
+ updateToolbar();
29
+ });
30
+ }), editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
31
+ updateToolbar();
32
+ return false;
33
+ }, LOW_PRIORIRTY));
34
+ }, [editor]);
35
+ const updateColor = ({ property, color }) => {
36
+ editor.update(() => {
37
+ const selection = $getSelection();
38
+ if (selection)
39
+ $patchStyleText(selection, { [property]: color });
40
+ });
41
+ };
42
+ return (_jsxs(_Fragment, { children: [_jsx(TooltipX, { content: "Font Color", direction: "bottom", children: _jsx(ColorPicker, { color: color, onChange: (color) => {
43
+ updateColor({ property: 'color', color });
44
+ }, icon: _jsx(AiOutlineFontColors, {}) }) }), _jsx(TooltipX, { content: "Background Color", direction: "bottom", children: _jsx(ColorPicker, { color: bgColor, onChange: (color) => {
45
+ updateColor({ property: 'background', color });
46
+ }, icon: _jsx(AiOutlineBgColors, {}) }) })] }));
47
+ }
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { OnChangePlugin } from "@lexical/react/LexicalOnChangePlugin";
4
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
5
+ import { $generateHtmlFromNodes, $generateNodesFromDOM } from "@lexical/html";
6
+ import { $getRoot, $insertNodes } from "lexical";
7
+ export default function CustomOnChangePlugin({ value, onChange, }) {
8
+ const [editor] = useLexicalComposerContext();
9
+ const [isFirstRender, setIsFirstRender] = useState(true);
10
+ useEffect(() => {
11
+ if (!value || !isFirstRender)
12
+ return;
13
+ setIsFirstRender(false);
14
+ editor.update(() => {
15
+ const currentHTML = $generateHtmlFromNodes(editor);
16
+ if (currentHTML !== value) {
17
+ $getRoot().clear();
18
+ const parser = new DOMParser();
19
+ const dom = parser.parseFromString(value, "text/html");
20
+ const nodes = $generateNodesFromDOM(editor, dom);
21
+ $insertNodes(nodes);
22
+ }
23
+ });
24
+ }, [editor, value, isFirstRender]);
25
+ useEffect(() => {
26
+ setIsFirstRender(true);
27
+ }, [value]);
28
+ return (_jsx(OnChangePlugin, { onChange: (editorState) => {
29
+ editorState.read(() => {
30
+ onChange($generateHtmlFromNodes(editor));
31
+ });
32
+ } }));
33
+ }
@@ -0,0 +1 @@
1
+ export default function FontFamilyPlugin(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,53 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
+ import { $getSelection, $isRangeSelection, SELECTION_CHANGE_COMMAND } from 'lexical';
4
+ import { $patchStyleText, $getSelectionStyleValueForProperty } from '@lexical/selection';
5
+ import { useEffect, useState } from 'react';
6
+ import { mergeRegister } from '@lexical/utils';
7
+ import { LOW_PRIORIRTY } from '../constants';
8
+ import { RiFontFamily } from 'react-icons/ri';
9
+ import { FontSelectionList } from '../components/FontSelectionList';
10
+ import TooltipX from '../components/common/Tooltip';
11
+ const FONT_FAMILY_OPTIONS = [
12
+ { id: "", label: "Default" },
13
+ { id: "Inter", label: "Inter" },
14
+ { id: "System UI", label: "System" },
15
+ { id: "serif", label: "Serif" },
16
+ { id: "monospace", label: "Monospace" },
17
+ { id: "cursive", label: "Cursive" },
18
+ { id: "Georgia", label: "Georgia" },
19
+ { id: "Courier New", label: "Courier" },
20
+ ];
21
+ /** Inline styles serialize with quotes (e.g. `'Inter', serif`) — strip them for comparison. */
22
+ const normalizeFontFamily = (value) => value.replace(/['"]/g, '').trim();
23
+ export default function FontFamilyPlugin() {
24
+ const [editor] = useLexicalComposerContext();
25
+ const [fontFamily, setFontFamily] = useState("");
26
+ const updateToolbar = () => {
27
+ const selection = $getSelection();
28
+ if ($isRangeSelection(selection)) {
29
+ const value = $getSelectionStyleValueForProperty(selection, "font-family", "");
30
+ setFontFamily(normalizeFontFamily(value));
31
+ }
32
+ };
33
+ useEffect(() => {
34
+ return mergeRegister(editor.registerUpdateListener(({ editorState }) => {
35
+ editorState.read(() => {
36
+ updateToolbar();
37
+ });
38
+ }), editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
39
+ updateToolbar();
40
+ return false;
41
+ }, LOW_PRIORIRTY));
42
+ }, [editor]);
43
+ const updateFontFamily = (value) => {
44
+ editor.update(() => {
45
+ const selection = $getSelection();
46
+ if ($isRangeSelection(selection)) {
47
+ // `null` removes the property so text inherits the theme font
48
+ $patchStyleText(selection, { 'font-family': value === "" ? null : value });
49
+ }
50
+ });
51
+ };
52
+ return (_jsx(TooltipX, { content: "Font Family", direction: "bottom", children: _jsx(FontSelectionList, { icon: _jsx(RiFontFamily, {}), tooltipLabel: "Font Family", currentValue: fontFamily, options: FONT_FAMILY_OPTIONS, onSelect: updateFontFamily }) }));
53
+ }
@@ -0,0 +1 @@
1
+ export default function FontSizePlugin(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
+ import { $getSelection, $isRangeSelection, SELECTION_CHANGE_COMMAND } from 'lexical';
4
+ import { $patchStyleText, $getSelectionStyleValueForProperty } from '@lexical/selection';
5
+ import { useEffect, useState } from 'react';
6
+ import { mergeRegister } from '@lexical/utils';
7
+ import { LOW_PRIORIRTY } from '../constants';
8
+ import { RiFontSize } from 'react-icons/ri';
9
+ import { FontSelectionList } from '../components/FontSelectionList';
10
+ import TooltipX from '../components/common/Tooltip';
11
+ const FONT_SIZES = [12, 14, 16, 18, 20, 24, 28, 32, 36, 48];
12
+ const FONT_SIZE_OPTIONS = [
13
+ { id: "", label: "Default" },
14
+ ...FONT_SIZES.map((size) => ({ id: `${size}px`, label: `${size}` })),
15
+ ];
16
+ /** Inline styles serialize as `16px` — strip the unit for display. */
17
+ const normalizeFontSize = (value) => value.trim();
18
+ export default function FontSizePlugin() {
19
+ const [editor] = useLexicalComposerContext();
20
+ const [fontSize, setFontSize] = useState("");
21
+ const updateToolbar = () => {
22
+ const selection = $getSelection();
23
+ if ($isRangeSelection(selection)) {
24
+ const value = $getSelectionStyleValueForProperty(selection, "font-size", "");
25
+ setFontSize(normalizeFontSize(value));
26
+ }
27
+ };
28
+ useEffect(() => {
29
+ return mergeRegister(editor.registerUpdateListener(({ editorState }) => {
30
+ editorState.read(() => {
31
+ updateToolbar();
32
+ });
33
+ }), editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
34
+ updateToolbar();
35
+ return false;
36
+ }, LOW_PRIORIRTY));
37
+ }, [editor]);
38
+ const updateFontSize = (value) => {
39
+ editor.update(() => {
40
+ const selection = $getSelection();
41
+ if ($isRangeSelection(selection)) {
42
+ // `null` removes the property so text inherits the surrounding size
43
+ $patchStyleText(selection, { 'font-size': value === "" ? null : value });
44
+ }
45
+ });
46
+ };
47
+ return (_jsx(TooltipX, { content: "Font Size", direction: "bottom", children: _jsx(FontSelectionList, { icon: _jsx(RiFontSize, {}), tooltipLabel: "Font Size", currentValue: fontSize, options: FONT_SIZE_OPTIONS, onSelect: updateFontSize }) }));
48
+ }
@@ -1 +1,3 @@
1
- export default function ImagePlugin(): import("react/jsx-runtime").JSX.Element;
1
+ export default function ImagePlugin({ onImageUpload }: {
2
+ onImageUpload?: (file: File) => Promise<string>;
3
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,91 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
+ import { $insertNodes, COMMAND_PRIORITY_LOW, PASTE_COMMAND } from "lexical";
4
+ import { $createImageNode } from "../nodes/ImageNode";
5
+ import { useCallback, useEffect, useRef, useState } from "react";
6
+ import { IoImageOutline } from "react-icons/io5";
7
+ import RawDialog from "../components/common/Dialog";
8
+ import { LuUpload } from "react-icons/lu";
9
+ async function insertImage(editor, { src, altText = "", caption = "" }) {
10
+ editor.update(() => {
11
+ const node = $createImageNode({ src, altText, caption });
12
+ $insertNodes([node]);
13
+ });
14
+ }
15
+ export default function ImagePlugin({ onImageUpload }) {
16
+ const [editor] = useLexicalComposerContext();
17
+ const inputRef = useRef(null);
18
+ const [isOpen, setIsOpen] = useState(false);
19
+ const [url, setURL] = useState("");
20
+ const [altText, setAltText] = useState("");
21
+ const [caption, setCaption] = useState("");
22
+ const [file, setFile] = useState();
23
+ const [isUploading, setIsUploading] = useState(false);
24
+ const handleFileUpload = useCallback(async (file, alt = "", cap = "") => {
25
+ let src;
26
+ if (onImageUpload) {
27
+ src = await onImageUpload(file);
28
+ }
29
+ else {
30
+ src = URL.createObjectURL(file);
31
+ }
32
+ insertImage(editor, { src, altText: alt, caption: cap });
33
+ }, [editor, onImageUpload]);
34
+ const addImage = async () => {
35
+ if (isUploading)
36
+ return;
37
+ if (file) {
38
+ setIsUploading(true);
39
+ try {
40
+ await handleFileUpload(file, altText, caption);
41
+ }
42
+ catch (err) {
43
+ console.error("Image upload failed:", err);
44
+ setIsUploading(false);
45
+ return;
46
+ }
47
+ setIsUploading(false);
48
+ }
49
+ else if (url) {
50
+ insertImage(editor, { src: url, altText, caption });
51
+ }
52
+ else {
53
+ return;
54
+ }
55
+ setFile(undefined);
56
+ setAltText("");
57
+ setCaption("");
58
+ setURL("");
59
+ setIsOpen(false);
60
+ };
61
+ useEffect(() => {
62
+ const unregister = editor.registerCommand(PASTE_COMMAND, (payload) => {
63
+ if (payload instanceof ClipboardEvent) {
64
+ const items = payload.clipboardData?.items;
65
+ if (!items)
66
+ return false;
67
+ for (const item of items) {
68
+ if (item.type.startsWith("image/")) {
69
+ payload.preventDefault();
70
+ const blob = item.getAsFile();
71
+ if (blob) {
72
+ handleFileUpload(blob, "", "").catch(console.error);
73
+ }
74
+ return true;
75
+ }
76
+ }
77
+ }
78
+ return false;
79
+ }, COMMAND_PRIORITY_LOW);
80
+ return () => unregister();
81
+ }, [editor, handleFileUpload]);
82
+ return (_jsxs("div", { className: "lexical-text-editor-dialog", children: [_jsx("input", { type: "file", ref: inputRef, accept: "image/*", className: "lte-hidden", onChange: (e) => {
83
+ const f = e.target.files?.[0];
84
+ if (f)
85
+ setFile(f);
86
+ e.target.value = "";
87
+ } }), _jsx("button", { type: "button", className: `size-8 lexical-btn ${isOpen ? "toolbarActive" : "toolbar"} icon`, onClick: () => setIsOpen((prev) => !prev), children: _jsx(IoImageOutline, { size: 18 }) }), _jsxs(RawDialog, { open: isOpen, onClose: () => setIsOpen(false), children: [_jsx("div", { className: "lte-dialog-header", children: "Add Image" }), _jsxs("div", { className: "lte-dialog-body", children: [_jsx("input", { className: "lte-input", placeholder: "Alt text", value: altText, onChange: (e) => setAltText(e.target.value) }), _jsx("input", { className: "lte-input", placeholder: "Caption", value: caption, onChange: (e) => setCaption(e.target.value) }), _jsx("input", { className: "lte-input", placeholder: "Add image by URL", value: url, onChange: (e) => setURL(e.target.value) }), _jsx("div", { className: "lte-divider", children: _jsx("span", { children: "or" }) }), _jsxs("button", { type: "button", className: `lexical-btn heading-trigger toolbar-active`, onClick: () => inputRef.current?.click(), style: {
88
+ width: 'fit-content',
89
+ margin: '0 auto'
90
+ }, children: [_jsx(LuUpload, { size: 20 }), _jsx("span", { children: "Upload Image" })] }), file && (_jsx("div", { className: "lte-file-name", children: file.name }))] }), _jsx("div", { className: "lte-dialog-footer", children: _jsx("button", { type: "button", className: "lte-primary-btn", disabled: (!url && !file) || isUploading, onClick: addImage, children: isUploading ? "Uploading..." : "Add Image" }) })] })] }));
91
+ }
@@ -0,0 +1,44 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
+ import { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND, } from "@lexical/list";
4
+ import { BsListOl, BsListUl } from "react-icons/bs";
5
+ import TooltipX from "../components/common/Tooltip";
6
+ import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, INDENT_CONTENT_COMMAND, KEY_TAB_COMMAND, OUTDENT_CONTENT_COMMAND, } from "lexical";
7
+ import { $getNearestNodeOfType, mergeRegister } from "@lexical/utils";
8
+ import { ListNode } from "@lexical/list";
9
+ import { useEffect } from "react";
10
+ export default function ListPlugin({ blockType }) {
11
+ const [editor] = useLexicalComposerContext();
12
+ // Tab / Shift+Tab inside lists -> indent / outdent (nested lists)
13
+ useEffect(() => {
14
+ return mergeRegister(editor.registerCommand(KEY_TAB_COMMAND, (event) => {
15
+ const selection = $getSelection();
16
+ if (!$isRangeSelection(selection))
17
+ return false;
18
+ const anchorNode = selection.anchor.getNode();
19
+ const list = $getNearestNodeOfType(anchorNode, ListNode);
20
+ if (!list)
21
+ return false;
22
+ event.preventDefault();
23
+ editor.dispatchCommand(event.shiftKey ? OUTDENT_CONTENT_COMMAND : INDENT_CONTENT_COMMAND, undefined);
24
+ return true;
25
+ }, COMMAND_PRIORITY_EDITOR));
26
+ }, [editor]);
27
+ const handleOrderedList = () => {
28
+ if (blockType === "ol") {
29
+ editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
30
+ }
31
+ else {
32
+ editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
33
+ }
34
+ };
35
+ const handleUnorderedList = () => {
36
+ if (blockType === "ul") {
37
+ editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
38
+ }
39
+ else {
40
+ editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
41
+ }
42
+ };
43
+ return (_jsxs(_Fragment, { children: [_jsx(TooltipX, { content: "Ordered list", direction: "bottom", children: _jsx("button", { type: "button", className: `size-8 lexical-btn ${blockType === "ol" ? "toolbarActive" : "toolbar"} icon`, onClick: handleOrderedList, children: _jsx(BsListOl, {}) }) }), _jsx(TooltipX, { content: "Unordered list", direction: "bottom", children: _jsx("button", { type: "button", className: `size-8 lexical-btn ${blockType === "ul" ? "toolbarActive" : "toolbar"} icon`, onClick: handleUnorderedList, children: _jsx(BsListUl, {}) }) })] }));
44
+ }
@@ -0,0 +1 @@
1
+ export default function TablePlugin(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,92 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
+ import { $getSelection, $isRangeSelection, SELECTION_CHANGE_COMMAND, } from "lexical";
4
+ import { $findCellNode, $isTableCellNode, $deleteTableColumnAtSelection, $deleteTableRowAtSelection, $insertTableColumnAtSelection, $insertTableRowAtSelection, TableCellHeaderStates, INSERT_TABLE_COMMAND } from "@lexical/table";
5
+ import { useEffect, useRef, useState } from "react";
6
+ import { mergeRegister } from "@lexical/utils";
7
+ import { HiChevronDown } from "react-icons/hi2";
8
+ import { BsTable } from "react-icons/bs";
9
+ import { LOW_PRIORIRTY } from "../constants";
10
+ import { Popover, PopoverContent, PopoverTrigger, } from "../components/common/Popover";
11
+ const GRID_SIZE = 5;
12
+ export default function TablePlugin() {
13
+ const [editor] = useLexicalComposerContext();
14
+ const [insideTable, setInsideTable] = useState(false);
15
+ const [open, setOpen] = useState(false);
16
+ const [gridHover, setGridHover] = useState(null);
17
+ const triggerRef = useRef(null);
18
+ const contentRef = useRef(null);
19
+ const updateState = () => {
20
+ const selection = $getSelection();
21
+ if ($isRangeSelection(selection)) {
22
+ const cell = $findCellNode(selection.anchor.getNode());
23
+ setInsideTable(!!cell);
24
+ }
25
+ else {
26
+ setInsideTable(false);
27
+ }
28
+ };
29
+ useEffect(() => {
30
+ return mergeRegister(editor.registerUpdateListener(({ editorState }) => {
31
+ editorState.read(() => {
32
+ updateState();
33
+ });
34
+ }), editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
35
+ updateState();
36
+ return false;
37
+ }, LOW_PRIORIRTY));
38
+ }, [editor]);
39
+ const insertTable = (rows, cols) => {
40
+ editor.dispatchCommand(INSERT_TABLE_COMMAND, {
41
+ rows: String(rows),
42
+ columns: String(cols),
43
+ includeHeaders: false,
44
+ });
45
+ setOpen(false);
46
+ };
47
+ const runTableOp = (op) => {
48
+ editor.update(() => {
49
+ const selection = $getSelection();
50
+ if (!$isRangeSelection(selection))
51
+ return;
52
+ op();
53
+ });
54
+ setOpen(false);
55
+ };
56
+ const toggleHeaderRow = () => {
57
+ runTableOp(() => {
58
+ const selection = $getSelection();
59
+ if (!$isRangeSelection(selection))
60
+ return;
61
+ const cell = $findCellNode(selection.anchor.getNode());
62
+ if (!cell)
63
+ return;
64
+ const row = cell.getParent();
65
+ if (!row)
66
+ return;
67
+ const cells = row.getChildren().filter($isTableCellNode);
68
+ const isHeader = cells.some((c) => c.hasHeaderState(TableCellHeaderStates.ROW));
69
+ for (const c of cells) {
70
+ c.setHeaderStyles(isHeader ? TableCellHeaderStates.NO_STATUS : TableCellHeaderStates.ROW, TableCellHeaderStates.ROW);
71
+ }
72
+ });
73
+ };
74
+ const gridLabel = gridHover ? `${gridHover.rows} × ${gridHover.cols}` : "Insert Table";
75
+ return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { triggerRef: triggerRef, children: _jsxs("button", { type: "button", className: `lexical-btn heading-trigger ${insideTable ? "toolbar-active" : "toolbar"}`, onClick: () => setOpen((prev) => !prev), children: [_jsx(BsTable, {}), _jsx(HiChevronDown, { className: `chevron ${open ? "rotated" : ""}` })] }) }), _jsx(PopoverContent, { open: open, align: "start", onClose: () => setOpen(false), contentRef: contentRef, children: _jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [_jsxs("div", { style: { width: "fit-content" }, children: [_jsx("div", { style: {
76
+ display: "grid",
77
+ gridTemplateColumns: `repeat(${GRID_SIZE}, 18px)`,
78
+ gap: 3,
79
+ }, children: Array.from({ length: GRID_SIZE * GRID_SIZE }, (_, idx) => {
80
+ const r = Math.floor(idx / GRID_SIZE) + 1;
81
+ const c = (idx % GRID_SIZE) + 1;
82
+ const active = gridHover && r <= gridHover.rows && c <= gridHover.cols;
83
+ return (_jsx("div", { onMouseEnter: () => setGridHover({ rows: r, cols: c }), onClick: () => insertTable(r, c), style: {
84
+ width: 18,
85
+ height: 18,
86
+ borderRadius: 3,
87
+ border: "1px solid #d1d5db",
88
+ backgroundColor: active ? "#c7d2fe" : "#fff",
89
+ cursor: "pointer",
90
+ } }, idx));
91
+ }) }), _jsx("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 4 }, children: gridLabel })] }), _jsx("div", { className: "w-full h-[1px] bg-gray-200" }), _jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 5 }, children: [_jsx("button", { type: "button", className: `lexical-btn ${insideTable ? "toolbar" : "toolbar"}`, disabled: !insideTable, onClick: () => runTableOp(() => { $insertTableRowAtSelection(false); }), style: { minWidth: 160 }, children: _jsx("span", { className: "label", children: "Insert row above" }) }), _jsx("button", { type: "button", className: "lexical-btn toolbar", disabled: !insideTable, onClick: () => runTableOp(() => { $insertTableRowAtSelection(true); }), style: { minWidth: 160 }, children: _jsx("span", { className: "label", children: "Insert row below" }) }), _jsx("button", { type: "button", className: "lexical-btn toolbar", disabled: !insideTable, onClick: () => runTableOp(() => { $deleteTableRowAtSelection(); }), style: { minWidth: 160 }, children: _jsx("span", { className: "label", children: "Delete row" }) }), _jsx("button", { type: "button", className: "lexical-btn toolbar", disabled: !insideTable, onClick: () => runTableOp(() => { $insertTableColumnAtSelection(false); }), style: { minWidth: 160 }, children: _jsx("span", { className: "label", children: "Insert column left" }) }), _jsx("button", { type: "button", className: "lexical-btn toolbar", disabled: !insideTable, onClick: () => runTableOp(() => { $insertTableColumnAtSelection(true); }), style: { minWidth: 160 }, children: _jsx("span", { className: "label", children: "Insert column right" }) }), _jsx("button", { type: "button", className: "lexical-btn toolbar", disabled: !insideTable, onClick: () => runTableOp(() => { $deleteTableColumnAtSelection(); }), style: { minWidth: 160 }, children: _jsx("span", { className: "label", children: "Delete column" }) }), _jsx("button", { type: "button", className: "lexical-btn toolbar", disabled: !insideTable, onClick: toggleHeaderRow, style: { minWidth: 160 }, children: _jsx("span", { className: "label", children: "Toggle header row" }) })] })] }) })] }));
92
+ }
@@ -1,3 +1,16 @@
1
- export declare const ToolbarPlugin: ({ value }: {
1
+ export declare const ToolbarPlugin: ({ value, onImageUpload, sourceView, onToggleSourceView, fullscreen, onToggleFullscreen, toolbarStyle, }: {
2
2
  value: string;
3
+ onImageUpload?: (file: File) => Promise<string>;
4
+ sourceView?: boolean;
5
+ onToggleSourceView?: () => void;
6
+ fullscreen?: boolean;
7
+ onToggleFullscreen?: () => void;
8
+ /**
9
+ * 'collapse' (default) — single row; overflowed segments collapse into the
10
+ * "..." button + modal (predictive fit per COLLAPSIBLE_IDS priority).
11
+ * 'wrap' — all tools flow serially; overflow wraps to the next line.
12
+ * 'scrollbar' — single horizontal row with a slim scrollbar.
13
+ * 'normal' — deprecated alias for 'collapse'.
14
+ */
15
+ toolbarStyle?: "wrap" | "collapse" | "scrollbar" | "normal";
3
16
  }) => import("react/jsx-runtime").JSX.Element;