From c4667bf4d4771d975b6224bf208c04a3c76cfba1 Mon Sep 17 00:00:00 2001 From: Nikita Korovin Date: Tue, 19 Mar 2024 13:45:24 +0400 Subject: [PATCH 1/2] Check user selection on useTableMergeState --- .changeset/popular-cups-bake.md | 5 +++++ packages/table/src/merge/useTableMergeState.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/popular-cups-bake.md diff --git a/.changeset/popular-cups-bake.md b/.changeset/popular-cups-bake.md new file mode 100644 index 0000000000..e3ed7b0f57 --- /dev/null +++ b/.changeset/popular-cups-bake.md @@ -0,0 +1,5 @@ +--- +"@udecode/plate-table": patch +--- + +canMerge = true only if user selected more than one cell diff --git a/packages/table/src/merge/useTableMergeState.ts b/packages/table/src/merge/useTableMergeState.ts index 0ff2f09776..3b231e2ff0 100644 --- a/packages/table/src/merge/useTableMergeState.ts +++ b/packages/table/src/merge/useTableMergeState.ts @@ -12,7 +12,7 @@ import { getTableGridAbove } from '../queries'; import { getColSpan } from '../queries/getColSpan'; import { getRowSpan } from '../queries/getRowSpan'; import { useTableStore } from '../stores'; -import { TablePlugin } from '../types'; +import { TTableCellElement, TablePlugin } from '../types'; import { isTableRectangular } from './isTableRectangular'; export const useTableMergeState = () => { @@ -41,18 +41,20 @@ export const useTableMergeState = () => { [] ); + if (!selectedTable) return { canMerge: false, canUnmerge: false }; + const canMerge = !readOnly && selected && selectionExpanded && + selectedCellEntries.length > 1 && isTableRectangular(selectedTable); const canUnmerge = collapsed && - selectedCellEntries && selectedCellEntries.length === 1 && - (getColSpan(selectedCellEntries[0][0] as any) > 1 || - getRowSpan(selectedCellEntries[0][0] as any) > 1); + (getColSpan(selectedCellEntries[0][0] as TTableCellElement) > 1 || + getRowSpan(selectedCellEntries[0][0] as TTableCellElement) > 1); return { canMerge, canUnmerge }; }; From 8d7a8c22bcd4eee6b9439a2e27806fe1f5d25b1a Mon Sep 17 00:00:00 2001 From: Nikita Korovin Date: Tue, 19 Mar 2024 13:46:48 +0400 Subject: [PATCH 2/2] typo fix --- packages/table/src/merge/useTableMergeState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/table/src/merge/useTableMergeState.ts b/packages/table/src/merge/useTableMergeState.ts index 3b231e2ff0..c925a42681 100644 --- a/packages/table/src/merge/useTableMergeState.ts +++ b/packages/table/src/merge/useTableMergeState.ts @@ -41,7 +41,7 @@ export const useTableMergeState = () => { [] ); - if (!selectedTable) return { canMerge: false, canUnmerge: false }; + if (!selectedCellEntries) return { canMerge: false, canUnmerge: false }; const canMerge = !readOnly &&