Skip to content

Commit

Permalink
Merge pull request #3083 from KorovinQuantori/main
Browse files Browse the repository at this point in the history
Table bugfixes
  • Loading branch information
zbeyens authored Mar 28, 2024
2 parents 6725247 + ddcd093 commit 78cefe2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
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

0 comments on commit 78cefe2

Please sign in to comment.