diff --git a/src/components/LexicalEditor/plugins/ToolbarPlugin.jsx b/src/components/LexicalEditor/plugins/ToolbarPlugin.jsx index c44e44e..6a3f23a 100644 --- a/src/components/LexicalEditor/plugins/ToolbarPlugin.jsx +++ b/src/components/LexicalEditor/plugins/ToolbarPlugin.jsx @@ -33,6 +33,7 @@ import { $createCodeNode, $isCodeNode, getDefaultCodeLanguage, getCodeLanguages import { INSERT_HORIZONTAL_RULE_COMMAND } from '@lexical/react/LexicalHorizontalRuleNode'; import DropDown, { DropDownItem } from './../ui/DropDown'; import DropdownColorPicker from '../ui/DropdownColorPicker'; +import { INSERT_TABLE_COMMAND } from '@lexical/table'; import { // INSERT_IMAGE_COMMAND, InsertImageDialog, @@ -765,6 +766,54 @@ export default function ToolbarPlugin() { editor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, undefined); }, [editor]); + + const [showTableGrid, setShowTableGrid] = useState(false); + const [hoverRows, setHoverRows] = useState(0); + const [hoverCols, setHoverCols] = useState(0); + // Insert table function + const insertTable = (rows, cols) => { + editor.dispatchCommand(INSERT_TABLE_COMMAND, { rows, columns: cols }); + setHoverRows(0); + setHoverCols(0); + setShowTableGrid(false); + }; + // Generate grid for table selection + const renderTableGrid = () => { + const gridSize = 6; + return ( +
{ + setHoverRows(0); + setHoverCols(0); + }} + > +
+ {[...Array(gridSize)].map((_, rowIndex) => + [...Array(gridSize)].map((_, colIndex) => ( +
{ + setHoverRows(rowIndex + 1); + setHoverCols(colIndex + 1); + }} + onClick={() => insertTable(rowIndex + 1, colIndex + 1)} + /> + )) + )} +
+
+ {hoverRows} × {hoverCols} Table +
+
+ ); + }; + return (