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 cells merging #2666

Closed
wants to merge 46 commits into from
Closed

Table cells merging #2666

wants to merge 46 commits into from

Conversation

zbeyens
Copy link
Member

@zbeyens zbeyens commented Oct 2, 2023

Follow-up of #2590

dimaanj and others added 21 commits August 24, 2023 17:35
…lls-merging-poc-2

# Conflicts:
#	packages/table/src/transforms/insertTableRow.ts
#	yarn.lock
…lls-merging-poc-2

# Conflicts:
#	apps/www/src/registry/default/plate-ui/table-element.tsx
#	packages/table/src/components/TableCellElement/useTableCellElementResizable.ts
#	packages/table/src/components/TableCellElement/useTableCellElementState.ts
#	yarn.lock
@changeset-bot
Copy link

changeset-bot bot commented Oct 2, 2023

⚠️ No Changeset found

Latest commit: c2b1fb5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 2, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plate ❌ Failed (Inspect) Oct 3, 2023 5:59pm

@zbeyens zbeyens changed the title Table cells merging poc 3 Table cells merging Oct 2, 2023
@reviewpad reviewpad bot added the large Pull request is large label Oct 2, 2023
zbeyens added 2 commits October 3, 2023 19:43
Copy link
Member Author

@zbeyens zbeyens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • added disableMergeCells plugin option, it is important to keep the merging cell logic decoupled so we can prevent running that code when disabled. Also important for maintenance, readability and testing. I've created a merge folder to start with.
  • TTableCellElement: rowIndex and colIndex should not be stored on the element. These can be retrieved using findNodePath, and could even be stored in a WeakMap. I see many colSpan and rowSpan additions in the tests. We should keep the previous default: keep undefined when value is 1. So rowIndex={1} colIndex={1} rowSpan={1} colSpan={1} are redundant.
  • deleteColumn, deleteRow, insertTableColumn, insertTableRow: decouple and don't call the new logic when merging is disabled
  • last thing to do is to decouple the state from the UI since it's not versioned. I'll take care of that.

Thanks again for your contribution @dimaanj, I understand that you may be pressed for time regarding this PR. I will try to find some time this month to finalize any remaining point.

if (!colSizes.includes(0)) {
colSizes.push('100%' as any);
}
const tableWidth = colSizes.reduce((acc, cur) => acc + cur, 0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should support auto width when merging is disabled.

readOnly,
selected,
hovered,
hoveredLeft,
rowSize,
borders,
isSelectingCell,
cellRef,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should come from useTableCellElement

Comment on lines +76 to +82
if (cellRef.current && hoveredColIndex === null && cellOffsets) {
const cellOffset = cellRef.current.offsetLeft;
const startColIndex = getClosest(cellOffset, cellOffsets);

startCIndex.current = startColIndex;
endColIndex.current = startColIndex + cellElement.colSpan - 1;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref and its relative logic is DOM related, so it should be moved to useTableCellElement

export const getTableColumnCount = (tableNode: TElement) => {
return (tableNode.children as TElement[])?.[0]?.children?.length ?? 0;
Copy link
Member Author

@zbeyens zbeyens Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New logic should be called only when merging not disabled

Comment on lines +6 to +7
* colSizes with default widths. Since colSizes should always return valid widths
* of the columns for table cells merging feature.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0-filled array was used for auto layout. We need to keep support for it when merging is disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
large Pull request is large
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants