Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table bugfixes #3083

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-flowers-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-table": patch
---

Hotfix: reset cell entries list when table is overflown
5 changes: 5 additions & 0 deletions .changeset/orange-actors-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-table": patch
---

Use getRowSpan\getColSpan instead of pointing at `rowspan` and `colspan` fields directly
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ export const useTableCellElement = ({

return {
props: {
colSpan: element.colSpan,
rowSpan: element.rowSpan,
colSpan: getColSpan(element),
rowSpan: getRowSpan(element),
},
};
};
5 changes: 3 additions & 2 deletions packages/table/src/merge/computeCellIndices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TTableElement,
TTableRowElement,
} from '../types';
import { getColSpan } from '../queries';

export function computeCellIndices<V extends Value>(
editor: PlateEditor<V>,
Expand All @@ -32,7 +33,7 @@ export function computeCellIndices<V extends Value>(
rowIndex = r;
break;
}
cIndex += cell.colSpan || 1; // consider 0 and undefined as 1
cIndex += getColSpan(cell);
}
}

Expand All @@ -52,7 +53,7 @@ export function computeCellIndices<V extends Value>(
_rowSpan > 1 &&
rowIndex - _rowIndex < _rowSpan
) {
colIndex += prevCell.colSpan || 1;
colIndex += getColSpan(prevCell);
}
}
});
Expand Down
3 changes: 2 additions & 1 deletion packages/table/src/merge/isTableRectangular.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getColSpan } from '../queries';
import { getRowSpan } from '../queries/getRowSpan';
import { TTableCellElement, TTableElement, TTableRowElement } from '../types';

Expand All @@ -20,7 +21,7 @@ export const isTableRectangular = (table?: TTableElement) => {
if (!arr[rI + i]) {
arr[rI + i] = 0;
}
arr[rI + i] += cellElem?.colSpan || 1;
arr[rI + i] += getColSpan(cellElem);
});
});
});
Expand Down
12 changes: 5 additions & 7 deletions packages/table/src/withSetFragmentDataTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { Path } from 'slate';

import { ELEMENT_TH } from './createTablePlugin';
import { getTableGridAbove } from './queries/index';
import { getColSpan, getRowSpan, getTableGridAbove } from './queries/index';
import { TTableCellElement } from './types';

export const withSetFragmentDataTable = <
Expand Down Expand Up @@ -106,12 +106,10 @@ export const withSetFragmentDataTable = <

const cellElement = document.createElement('td');

if (cell.colSpan !== undefined) {
cellElement.colSpan = cell.colSpan;
}
if (cell.rowSpan !== undefined) {
cellElement.rowSpan = cell.rowSpan;
}
const colSpan = getColSpan(cell);
cellElement.colSpan = colSpan;
const rowSpan = getRowSpan(cell);
cellElement.rowSpan = rowSpan;

cellElement.innerHTML = data.getData('text/html');
rowElement.append(cellElement);
Expand Down