From 2b9861f1625199ee1acae3dfd13f1acb69e29543 Mon Sep 17 00:00:00 2001 From: Dzmitry Tamashevich Date: Mon, 20 Nov 2023 15:41:49 +0300 Subject: [PATCH] move indices update to useEffect --- .../TableElement/useTableElement.ts | 12 ++--- packages/table/src/withMergedCells.ts | 54 ------------------- packages/table/src/withTable.ts | 3 -- 3 files changed, 6 insertions(+), 63 deletions(-) delete mode 100644 packages/table/src/withMergedCells.ts diff --git a/packages/table/src/components/TableElement/useTableElement.ts b/packages/table/src/components/TableElement/useTableElement.ts index 80e239a325..e50c21d29a 100644 --- a/packages/table/src/components/TableElement/useTableElement.ts +++ b/packages/table/src/components/TableElement/useTableElement.ts @@ -30,10 +30,8 @@ export const useTableElementState = ({ } = {}): TableElementState => { const editor = useEditorRef(); - const { minColumnWidth, disableMarginLeft } = getPluginOptions( - editor, - ELEMENT_TABLE - ); + const { minColumnWidth, disableMarginLeft, disableCellsMerging } = + getPluginOptions(editor, ELEMENT_TABLE); const element = useElement(); const selectedCells = useTableStore().get.selectedCells(); @@ -46,8 +44,10 @@ export const useTableElementState = ({ let colSizes = useTableColSizes(element); useEffect(() => { - computeAllCellIndices(editor, element); - }, [editor, element]); + if (!disableCellsMerging) { + computeAllCellIndices(editor, element); + } + }, [editor, element, disableCellsMerging]); if (transformColSizes) { colSizes = transformColSizes(colSizes); diff --git a/packages/table/src/withMergedCells.ts b/packages/table/src/withMergedCells.ts deleted file mode 100644 index 8a92294e3d..0000000000 --- a/packages/table/src/withMergedCells.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { - getBlockAbove, - getPluginType, - PlateEditor, - TElement, - Value, -} from '@udecode/plate-common'; -import { BaseSelection } from 'slate'; - -import { - ELEMENT_TABLE, - ELEMENT_TD, - ELEMENT_TH, - ELEMENT_TR, -} from './createTablePlugin'; -import { computeAllCellIndices } from './merge/computeCellIndices'; -import { TTableElement } from './types'; - -export const withMergedCells = < - V extends Value = Value, - E extends PlateEditor = PlateEditor, ->( - editor: E -) => { - const { apply } = editor; - - editor.apply = (op) => { - const needsSync = - op.type === 'insert_node' || - op.type === 'merge_node' || - op.type === 'move_node' || - op.type === 'remove_node' || - op.type === 'set_node'; - - const updateTable = (selection: BaseSelection) => { - const tableEntry = getBlockAbove(editor, { - at: selection?.anchor, - match: { type: getPluginType(editor, ELEMENT_TABLE) }, - }); - if (tableEntry) { - const realTable = tableEntry[0] as TTableElement; - // computeAllCellIndices(editor, realTable); - } - }; - - if (needsSync) { - updateTable(editor.selection); - } - - apply(op); - }; - - return editor; -}; diff --git a/packages/table/src/withTable.ts b/packages/table/src/withTable.ts index 59d34a0c5e..ecf76ef4ab 100644 --- a/packages/table/src/withTable.ts +++ b/packages/table/src/withTable.ts @@ -17,9 +17,6 @@ export const withTable = < editor: E, plugin: WithPlatePlugin, V, E> ) => { - editor = plugin.options.disableCellsMerging - ? editor - : withMergedCells(editor); editor = withNormalizeTable(editor); editor = withDeleteTable(editor); editor = withGetFragmentTable(editor);