Skip to content

[PE-255] fix: remove drag handles from content within table cells#6487

Merged
sriramveeraghanta merged 4 commits intopreviewfrom
fix/drag-handle-inside-table
Jan 28, 2025
Merged

[PE-255] fix: remove drag handles from content within table cells#6487
sriramveeraghanta merged 4 commits intopreviewfrom
fix/drag-handle-inside-table

Conversation

@Palanikannan1437
Copy link
Member

@Palanikannan1437 Palanikannan1437 commented Jan 28, 2025

Description

This PR removes drag handles from the content within table cells

Type of Change

  • Improvement (change that would cause existing functionality to not work as expected)

Screenshots and Media (if applicable)

Test Scenarios

References

Summary by CodeRabbit

  • New Features

    • Enhanced table creation functionality by allowing specification of column widths during insertion.
    • Improved cell creation to accept and apply additional attributes.
  • Bug Fixes

    • Improved side menu positioning logic when interacting with table cells.
    • Enhanced element selection in the drag handle plugin to prioritize table wrappers.
  • Style

    • Adjusted padding for table cells to improve layout and spacing.

These changes refine the editor's table handling capabilities and enhance user interactions with table elements.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

Walkthrough

The pull request introduces modifications to the side menu and drag handle positioning logic in the editor. Changes focus on refining how elements are selected and positioned, particularly in relation to table cells and wrappers. The modifications aim to improve the precision of element selection and side menu rendering by adjusting event handling and element detection strategies, including updates to table creation functionalities.

Changes

File Change Summary
packages/editor/src/core/extensions/side-menu.tsx Removed conditional block adjusting rect.left for td and th parent elements, simplifying side menu positioning logic.
packages/editor/src/core/plugins/drag-handle.ts Modified nodeDOMAtCoords function to prioritize .table-wrapper elements and remove special handling for <p> tags within table cells.
packages/editor/src/styles/table.css Changed padding for td and th from padding: 10px 20px; to padding: 7px 10px;, reducing both vertical and horizontal padding.
packages/editor/src/core/extensions/table/table/table.ts Updated insertTable method signature to include an optional columnWidth parameter and modified implementation to use this parameter.
packages/editor/src/core/extensions/table/table/utilities/create-cell.ts Modified createCell function to include an optional attrs parameter for passing attributes when creating a cell.
packages/editor/src/core/extensions/table/table/utilities/create-table.ts Added columnWidth parameter to createTable function, affecting cell creation with specified column widths.
packages/editor/src/core/helpers/editor-commands.ts Updated insertTableCommand to include a columnWidth property in the insertTable method call, ensuring defined column widths upon table insertion.

Possibly related PRs

  • fix: drag handle scrolling fixed #5619: The changes in the drag-handle.ts file regarding the nodeDOMAtCoords function are related to the main PR's modifications in the side-menu.tsx file, as both involve adjustments to how elements are selected and handled in the editor's UI.
  • [WEB-2528] fix: side menu rendering even if created already #5687: The modifications in the side-menu.tsx file, particularly the changes to the initialization logic and the handling of the rect.left property, are directly related to the main PR's changes in the same file, focusing on the side menu's rendering behavior.

Suggested labels

🐛bug, 🌐frontend, ✍️editor

Suggested reviewers

  • aaryan610
  • SatishGandham

Poem

🐰 In the realm of pixels and code,
Where menus dance and handles abode,
A rabbit hops through table's grace,
Refining position with surgical trace,
Precision is our coding ode! 🖱️

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Palanikannan1437 Palanikannan1437 marked this pull request as ready for review January 28, 2025 10:31
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/editor/src/core/plugins/drag-handle.ts (1)

91-102: Add test coverage for table drag handle behavior.

The changes look good but would benefit from additional test coverage to ensure the drag handle behavior works correctly with tables. Consider adding tests for:

  1. Table wrapper selection
  2. Preventing drag handles on table cell content
  3. Edge cases with nested draggable elements

Would you like me to help generate the test cases?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f32635a and 3737f7a.

📒 Files selected for processing (2)
  • packages/editor/src/core/extensions/side-menu.tsx (0 hunks)
  • packages/editor/src/core/plugins/drag-handle.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/editor/src/core/extensions/side-menu.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/editor/src/core/plugins/drag-handle.ts (2)

91-94: LGTM! Prioritizing table wrapper selection.

The new check correctly prioritizes table wrapper selection, preventing drag handles from being attached to inner table cell content.


100-102: Verify handling of valid draggable elements within tables.

While the skip logic effectively prevents drag handles on table cell content, let's verify that this doesn't affect any valid draggable elements that might be intentionally placed within tables.

✅ Verification successful

Table drag handling implementation is correct

The skip logic for table cells is intentionally designed to:

  • Allow dragging of entire tables as units
  • Prevent disruption of table structure by blocking drag operations on individual cells
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for draggable elements within tables that might be affected.
# Look for elements matching generalSelectors within table wrappers.

echo "Searching for potentially affected draggable elements within tables..."

# First, let's see what elements are typically placed within tables
rg -l "table-wrapper.*(?:$(echo $generalSelectors | sed 's/, /|/g'))"

# Then, check for any explicit drag-related attributes or classes within table contexts
rg -l "table-wrapper.*draggable|drag"

Length of output: 5823


Script:

#!/bin/bash
# Check table and drag-related styles
echo "=== Table CSS styles ==="
cat packages/editor/src/styles/table.css

echo -e "\n=== Drag-drop CSS styles ==="
cat packages/editor/src/styles/drag-drop.css

echo -e "\n=== Drag handle implementation ==="
cat packages/editor/src/core/plugins/drag-handle.ts

Length of output: 20343

@Palanikannan1437 Palanikannan1437 changed the title fix: remove drag handles from content within table cells ,fix: remove drag handles from content within table cells Jan 28, 2025
@Palanikannan1437 Palanikannan1437 changed the title ,fix: remove drag handles from content within table cells [PE-255] fix: remove drag handles from content within table cells Jan 28, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/editor/src/styles/table.css (1)

Line range hint 21-27: Consider adding explicit CSS to prevent drag handles on cell content.

While the backend changes handle drag functionality, adding CSS rules could provide an additional layer of prevention:

.table-wrapper table td,
.table-wrapper table th {
  /* ... existing styles ... */
  
  > * {
    margin-bottom: 0;
+   user-select: none;
+   pointer-events: none;
  }
}

This would ensure cell content cannot be dragged, reinforcing the changes made in the drag handle logic.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3737f7a and 93cbe91.

📒 Files selected for processing (1)
  • packages/editor/src/styles/table.css (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint-web
  • GitHub Check: lint-space
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (3)
packages/editor/src/styles/table.css (3)

19-19: LGTM! Padding adjustment helps with drag handle positioning.

The reduction in horizontal padding from 20px to 10px helps maintain consistent spacing and prevents potential overlap with drag handles, aligning well with the PR's objective.


Line range hint 116-121: LGTM! Robust control handling prevents interference.

The implementation properly handles control visibility during drag/resize operations through the resize-cursor class and controls--disabled state, which helps prevent interference between dragging and control interactions.


Line range hint 1-121: Verify complete drag handle removal across related files.

While the CSS changes support the objective, let's verify the complete implementation:

✅ Verification successful

Table drag handle removal is properly implemented

The implementation correctly handles table interactions by:

  • Using dedicated column and row controls for tables
  • Explicitly excluding table cells from drag handle functionality
  • Maintaining proper CSS styling for table controls
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for related drag handle implementations
echo "Searching for drag handle related files..."
rg -l "drag-handle|dragHandle" --type ts --type tsx

# Check for any remaining drag handle styles
echo "Checking for additional drag handle styles..."
rg -l "drag|draggable" --type css

# Look for table-related components
echo "Checking table-related components..."
rg -l "table-wrapper|TableWrapper" --type ts --type tsx

Length of output: 523


Script:

#!/bin/bash
# Check content of drag-drop.css
echo "=== Checking drag-drop.css content ==="
cat packages/editor/src/styles/drag-drop.css

# Search with correct typescript file extensions
echo -e "\n=== Searching for drag handle related files ==="
rg -l "drag-handle|dragHandle" -g "*.ts" -g "*.tsx"

# Check table-related components
echo -e "\n=== Checking table-related components ==="
rg -l "table-wrapper|TableWrapper" -g "*.ts" -g "*.tsx"

Length of output: 4007


Script:

#!/bin/bash
# Check table-related implementations
echo "=== Checking table view implementation ==="
cat packages/editor/src/core/extensions/table/table/table-view.tsx

echo -e "\n=== Checking table controls implementation ==="
cat packages/editor/src/core/extensions/table/table/table-controls.ts

echo -e "\n=== Checking drag handle implementation ==="
cat packages/editor/src/core/plugins/drag-handle.ts

Length of output: 32676

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/editor/src/core/extensions/table/table/utilities/create-cell.ts (1)

5-6: Consider using a more specific type for attrs.

The implementation looks good, but consider using a more specific type for attrs instead of Record<string, any> to improve type safety and documentation.

-  attrs?: Record<string, any>
+  attrs?: {
+    colwidth?: number[];
+    // add other valid attributes here
+  }
packages/editor/src/core/extensions/table/table/table.ts (1)

116-118: Consider extracting default values to constants.

The implementation looks good, but consider extracting magic numbers to named constants for better maintainability.

+const DEFAULT_TABLE_CONFIG = {
+  ROWS: 3,
+  COLS: 3,
+  COLUMN_WIDTH: 150,
+} as const;
+
-        ({ rows = 3, cols = 3, withHeaderRow = false, columnWidth = 150 } = {}) =>
+        ({ rows = DEFAULT_TABLE_CONFIG.ROWS, cols = DEFAULT_TABLE_CONFIG.COLS, withHeaderRow = false, columnWidth = DEFAULT_TABLE_CONFIG.COLUMN_WIDTH } = {}) =>
packages/editor/src/core/helpers/editor-commands.ts (1)

141-143: Consider extracting table options to a variable.

While the implementation is correct, the table options could be extracted to improve readability and maintainability.

+  const tableOptions = { rows: 3, cols: 3, columnWidth: 150 };
+
   if (range)
-    editor.chain().focus().deleteRange(range).clearNodes().insertTable({ rows: 3, cols: 3, columnWidth: 150 }).run();
+    editor.chain().focus().deleteRange(range).clearNodes().insertTable(tableOptions).run();
   else
-    editor.chain().focus().clearNodes().insertTable({ rows: 3, cols: 3, columnWidth: 150 }).run();
+    editor.chain().focus().clearNodes().insertTable(tableOptions).run();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93cbe91 and f91f9c0.

📒 Files selected for processing (5)
  • packages/editor/src/core/extensions/table/table/table.ts (2 hunks)
  • packages/editor/src/core/extensions/table/table/utilities/create-cell.ts (1 hunks)
  • packages/editor/src/core/extensions/table/table/utilities/create-table.ts (1 hunks)
  • packages/editor/src/core/helpers/editor-commands.ts (1 hunks)
  • packages/editor/src/styles/table.css (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/editor/src/styles/table.css
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (4)
packages/editor/src/core/extensions/table/table/utilities/create-cell.ts (1)

9-9: LGTM! Consistent handling of attrs parameter.

The implementation correctly uses the attrs parameter in both cell creation paths.

Also applies to: 12-12

packages/editor/src/core/extensions/table/table/utilities/create-table.ts (1)

19-19: LGTM! Consistent column width handling.

The implementation correctly applies the column width to both regular and header cells, ensuring consistent behavior.

Also applies to: 26-26

packages/editor/src/core/extensions/table/table/table.ts (1)

42-47: LGTM! Well-typed interface extension.

The Commands interface is properly extended to include the new columnWidth parameter.

packages/editor/src/core/helpers/editor-commands.ts (1)

Line range hint 1-1: Verify drag handle removal implementation.

The PR objective is to remove drag handles from content within table cells, but the changes in these files focus on table structure and column width. Please verify if additional changes are needed in CSS or other files to achieve the drag handle removal.

@sriramveeraghanta sriramveeraghanta merged commit 421839e into preview Jan 28, 2025
10 of 14 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix/drag-handle-inside-table branch May 2, 2025 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants