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

[lexical-playground] Table Hover Action Buttons #6355

Merged
merged 5 commits into from
Jul 3, 2024

Conversation

ivailop7
Copy link
Collaborator

@ivailop7 ivailop7 commented Jun 30, 2024

Recreate the Experimental Table Hover Action Buttons for the Classic Table as a standalone playground plugin.
Clean up some of the remnants from the original implementation that was deleted a year ago.

Screen.Recording.2024-06-30.at.23.35.38.mov

Ivaylo Pavlov added 2 commits June 3, 2024 00:02
Copy link

vercel bot commented Jun 30, 2024

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

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2024 7:30pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2024 7:30pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 30, 2024
Copy link

github-actions bot commented Jun 30, 2024

size-limit report 📦

Path Size
lexical - cjs 28.47 KB (0%)
lexical - esm 28.28 KB (0%)
@lexical/rich-text - cjs 36.86 KB (0%)
@lexical/rich-text - esm 28.08 KB (0%)
@lexical/plain-text - cjs 35.49 KB (0%)
@lexical/plain-text - esm 25.3 KB (0%)
@lexical/react - cjs 38.82 KB (0%)
@lexical/react - esm 29.27 KB (0%)

Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Looks beautiful! Left some nits

Also, we may want to look into the case where you move from last column to last row or viceversa, it doesn't seem to show in this case

Screen.Recording.2024-07-01.at.10.41.01.AM.mov

return () => {
setShownRow(false);
setShownColumn(false);
debouncedOnMouseMove.cancel();
Copy link
Member

Choose a reason for hiding this comment

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

[Opinionated] debounce is fine, I would've chosen throttle

Copy link
Collaborator Author

@ivailop7 ivailop7 Jul 1, 2024

Choose a reason for hiding this comment

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

Picked it because it's the same way it's done in the CodeActionsPlugin. Where can I see a usage of throttle, which one would offer a more performant approach?

Comment on lines +212 to +228
if (target && target instanceof HTMLElement) {
const tableDOMNode = target.closest<HTMLElement>(
'td.PlaygroundEditorTheme__tableCell, th.PlaygroundEditorTheme__tableCell',
);

const isOutside = !(
tableDOMNode ||
target.closest<HTMLElement>(
'button.PlaygroundEditorTheme__tableAddRows',
) ||
target.closest<HTMLElement>(
'button.PlaygroundEditorTheme__tableAddColumns',
) ||
target.closest<HTMLElement>('div.TableCellResizer__resizer')
);

return {isOutside, tableDOMNode};
Copy link
Member

Choose a reason for hiding this comment

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

I would've considered using getNearestNodeFromDOMNode, nothing beats the performance of your implementation but this method will already do the editor checks for you and will work regardless of the markup.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The limitation with using getNearest here is that the div for the table border and resizer 'div.TableCellResizer__resizer' is not a node, (this was causing for the buttons to disappear when you hover on the borders between the table cells) also because getNearestNodeFromDOMNode needs to run inside editor.update, yet it does only read, I don't want to run an extra update reconciliation check, forced to collaborators when you just move your mouse around the table.

Comment on lines +175 to +181
if (insertRow) {
$insertTableRow__EXPERIMENTAL();
setShownRow(false);
} else {
$insertTableColumn__EXPERIMENTAL();
setShownColumn(false);
}
Copy link
Member

Choose a reason for hiding this comment

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

No strong opinions. Your version is easy to read

Suggested change
if (insertRow) {
$insertTableRow__EXPERIMENTAL();
setShownRow(false);
} else {
$insertTableColumn__EXPERIMENTAL();
setShownColumn(false);
}
$insertTableColumn__EXPERIMENTAL();
setShownColumn(insertRow);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This doesn't work since it's different methods it's setShownRow and setShownColumn, not setShownColumn at all times.

@ivailop7
Copy link
Collaborator Author

ivailop7 commented Jul 1, 2024

Looks beautiful! Left some nits

Also, we may want to look into the case where you move from last column to last row or viceversa, it doesn't seem to show in this case

Screen.Recording.2024-07-01.at.10.41.01.AM.mov

yeah, hovering over the bottom right cell, should show both, but right now only does add row, as a higher priority, running on the assumption that 'add row' would be much more popular than 'add column' in a everyday use. It's good enough IMO in the current state, but open for people polishing the nits.

@ivailop7
Copy link
Collaborator Author

ivailop7 commented Jul 2, 2024

@zurfyx for a second look post addressing comments

@ivailop7 ivailop7 added this pull request to the merge queue Jul 3, 2024
Merged via the queue into facebook:main with commit 4e8c7cc Jul 3, 2024
42 checks passed
2wheeh pushed a commit to 2wheeh/lexical that referenced this pull request Jul 17, 2024
Co-authored-by: Ivaylo Pavlov <ipavlov@Ivaylos-MacBook-Pro.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants