Skip to content

Commit

Permalink
Merge pull request #2680 from cpoftea/fix/sole-row-removing-error
Browse files Browse the repository at this point in the history
Fix crash when removing the sole table row
  • Loading branch information
AlekseyManetov authored Dec 4, 2024
2 parents 9201ef3 + 9650fbd commit 183a3fd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion uui-editor/src/plugins/tablePlugin/ToolbarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <RemoveTable className={ css.removeTableIcon } />;
Expand Down Expand Up @@ -72,7 +73,7 @@ export function TableToolbarContent({ canUnmerge }:{ canUnmerge:boolean }) {
/>
<ToolbarButton
key="delete-row"
onClick={ () => deleteRow(editor) }
onClick={ temporaryFixDeleteRow(editor, () => deleteRow(editor)) }
icon={ RemoveRow }
/>
<ToolbarButton
Expand Down
25 changes: 25 additions & 0 deletions uui-editor/src/plugins/tablePlugin/temporaryFixDeleteRow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { isType, type PlateEditor, getBlockAbove } from '@udecode/plate-common';
import { TABLE_TYPE } from './constants';
import type { TableElementType } from './types';

/**
* Remove fix wrapper function when `@udecode/plate-table` will be updated to 40.0.0
* See {@link https://github.com/udecode/plate/blob/f8fa0e7f4c0b4dd3ab445fd0aa55738db1596de9/packages/table/CHANGELOG.md#4000} for details
*/
export const temporaryFixDeleteRow = (editor: PlateEditor, deleteRowFn: () => void) => {
return () => {
const tableElement = getBlockAbove<TableElementType>(editor, { match: (node) => isType(editor, node, TABLE_TYPE) });

if (!tableElement) {
return;
}

const [tableNode] = tableElement;

if (tableNode.children.length <= 1) {
return;
}

deleteRowFn();
};
};

0 comments on commit 183a3fd

Please sign in to comment.