From 9650fbd6b21db8f80df97bc3fd29f64370b89912 Mon Sep 17 00:00:00 2001
From: Aleh Makaranka <29537473+cpoftea@users.noreply.github.com>
Date: Tue, 3 Dec 2024 23:14:42 +0400
Subject: [PATCH] Fix crash when removing the sole table row
`@udecode/plate-table` bug. Fixed at `v40.0.0`.
Added a temporary fix to prevent the error when removing the sole row in a table.
---
changelog.md | 1 +
.../plugins/tablePlugin/ToolbarContent.tsx | 3 ++-
.../tablePlugin/temporaryFixDeleteRow.ts | 25 +++++++++++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)
create mode 100644 uui-editor/src/plugins/tablePlugin/temporaryFixDeleteRow.ts
diff --git a/changelog.md b/changelog.md
index 5cb39a4247..412618ab20 100644
--- a/changelog.md
+++ b/changelog.md
@@ -14,6 +14,7 @@
* [RTE]: fixed scroll to the top of the editor after editor modal windows(Add image/link/video etc.) were close
* [RTE]: fixed error while merging cells without content
* [RTE]: fixed bug when files added from attachment button inserted in preview mode instead of attachment block
+* [RTE]: fixed crash when removing the sole table row
# 5.11.0 - 15.11.2024
diff --git a/uui-editor/src/plugins/tablePlugin/ToolbarContent.tsx b/uui-editor/src/plugins/tablePlugin/ToolbarContent.tsx
index 04e0361382..99ff4b7aaf 100644
--- a/uui-editor/src/plugins/tablePlugin/ToolbarContent.tsx
+++ b/uui-editor/src/plugins/tablePlugin/ToolbarContent.tsx
@@ -14,6 +14,7 @@ import { ToolbarButton } from '../../implementation/ToolbarButton';
import { useEditorRef } from '@udecode/plate-common';
import { getTableEntries, insertTableColumn, insertTableRow, deleteRow, deleteTable, unmergeTableCells, deleteColumn } from '@udecode/plate-table';
import { TABLE_HEADER_CELL_TYPE } from './constants';
+import { temporaryFixDeleteRow } from './temporaryFixDeleteRow';
function StyledRemoveTable() {
return ;
@@ -72,7 +73,7 @@ export function TableToolbarContent({ canUnmerge }:{ canUnmerge:boolean }) {
/>
deleteRow(editor) }
+ onClick={ temporaryFixDeleteRow(editor, () => deleteRow(editor)) }
icon={ RemoveRow }
/>
void) => {
+ return () => {
+ const tableElement = getBlockAbove(editor, { match: (node) => isType(editor, node, TABLE_TYPE) });
+
+ if (!tableElement) {
+ return;
+ }
+
+ const [tableNode] = tableElement;
+
+ if (tableNode.children.length <= 1) {
+ return;
+ }
+
+ deleteRowFn();
+ };
+};