-
Notifications
You must be signed in to change notification settings - Fork 3.5k
refactor: table drag preview using decorations #8597
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
base: preview
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe changes refactor table cell content visibility management in a rich text editor. Instead of persisting Changes
Sequence DiagramsequenceDiagram
participant Editor
participant DragHandle as Drag Handle
participant Utils as Cell Utils
participant Plugin as TableDragStatePlugin
participant Decorations as Decorations
Note over Editor,Decorations: Drag Operation Initialization
DragHandle->>Utils: constructDragPreview()
Utils->>Utils: getSelectedCellPositions(selection, table)
Utils->>Plugin: hideCellContent(editor, cellPositions)
Plugin->>Plugin: updateTransactionMeta(tr, cellPositions)
Plugin->>Decorations: Apply decorations with "content-hidden" class
Decorations-->>Editor: Render cells with hidden content (local only)
Note over Editor,Decorations: Drag Operation Completion
DragHandle->>Utils: showCellContent(editor)
Utils->>Plugin: showCellContent clears metadata
Plugin->>Plugin: updateTransactionMeta(tr, null)
Plugin->>Decorations: Clear decorations
Decorations-->>Editor: Restore normal cell rendering
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors table row/column drag previews to use ProseMirror decorations instead of node attributes, ensuring drag-only visual states are local, non-persistent, and not broadcast to other users.
Changes:
- Introduces a
TableDragStatePluginthat applies acontent-hiddendecoration to selected table cells during drag operations. - Removes the
hideContentattribute from table header and cell node schemas and from the HTML sanitization allowlist, relying solely on decorations and CSS for hiding content. - Updates row and column drag handle utilities/components to compute selected cell positions, hide them via the new plugin on drag start, and restore them on drag end.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/editor/src/core/extensions/table/table/table.ts | Registers the new TableDragStatePlugin in the table extension’s ProseMirror plugins to manage drag-related decorations. |
| packages/editor/src/core/extensions/table/table-header.ts | Simplifies TableHeader attrs and render logic by removing hideContent and the conditional content-hidden class. |
| packages/editor/src/core/extensions/table/table-cell.ts | Removes hideContent from TableCell attrs and rendering, keeping only style-based background/text color configuration. |
| packages/editor/src/core/extensions/table/plugins/drag-state.ts | Adds a dedicated plugin keyed by tableDragState that tracks hidden cell positions in transaction meta and applies/remaps content-hidden node decorations. |
| packages/editor/src/core/extensions/table/plugins/drag-handles/utils.ts | Provides shared helpers to clone cells, compute selected cell positions, and hide/show cell content via transaction meta and CORE_EDITOR_META.ADD_TO_HISTORY. |
| packages/editor/src/core/extensions/table/plugins/drag-handles/row/utils.ts | Refactors row drag preview construction to use getSelectedCellPositions/hideCellContent instead of node attribute updates. |
| packages/editor/src/core/extensions/table/plugins/drag-handles/row/drag-handle.tsx | On row drag completion, clears drag/drop markers and restores cell visibility via showCellContent. |
| packages/editor/src/core/extensions/table/plugins/drag-handles/column/utils.ts | Mirrors the row logic for columns, using decorations to hide selected column cells during drag preview. |
| packages/editor/src/core/extensions/table/plugins/drag-handles/column/drag-handle.tsx | On column drag completion, removes markers and clears decoration-based hiding with showCellContent. |
| apps/api/plane/utils/content_validator.py | Aligns HTML sanitization rules with the new model by removing hideContent/hidecontent from allowed <th>/<td> attributes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export const showCellContent = (editor: Editor): void => { | ||
| const tr = editor.view.state.tr; | ||
| updateTransactionMeta(tr, null); | ||
| tr.setMeta(CORE_EDITOR_META.ADD_TO_HISTORY, true); |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
showCellContent sets CORE_EDITOR_META.ADD_TO_HISTORY to true, whereas hideCellContent sets it to false and the previous updateCellContentVisibility helper always disabled history for these drag-only visibility changes. This makes the "show" operation behave differently from the previous implementation and from the "hide" operation, and may cause purely visual decoration updates to be recorded in the undo history. To keep drag-preview visibility changes invisible to undo/redo (as before), consider setting ADD_TO_HISTORY to false here as well.
| tr.setMeta(CORE_EDITOR_META.ADD_TO_HISTORY, true); | |
| tr.setMeta(CORE_EDITOR_META.ADD_TO_HISTORY, false); |
Description
This PR improves the drag preview logic for table rows and columns-
Type of Change
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.