refactor: table drag preview using decorations#8597
refactor: table drag preview using decorations#8597Palanikannan1437 merged 3 commits intopreviewfrom
Conversation
📝 WalkthroughWalkthroughTable cell content hiding was changed from a persistent node attribute to transient ProseMirror decorations driven by transaction metadata via a new TableDragStatePlugin; drag handlers now compute selected cell positions and use utilities to hide/show content through the plugin. 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 start — build preview
DragHandle->>Utils: constructDragPreview(selection, table)
Utils->>Utils: getSelectedCellPositions(selection, table)
Utils->>Plugin: hideCellContent(editor, cellPositions)
Plugin->>Plugin: updateTransactionMeta(tr, cellPositions)
Plugin->>Decorations: create decorations (apply "content-hidden" class)
Decorations-->>Editor: render cells with hidden content (local)
Note over Editor,Decorations: Drag end — restore
DragHandle->>Utils: showCellContent(editor)
Utils->>Plugin: showCellContent(editor)
Plugin->>Plugin: updateTransactionMeta(tr, null)
Plugin->>Decorations: clear decorations
Decorations-->>Editor: restore normal rendering
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
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.
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.
packages/editor/src/core/extensions/table/plugins/drag-handles/utils.ts
Outdated
Show resolved
Hide resolved
…actor/table-drag-preview
Description
This PR improves the drag preview logic for table rows and columns-
Type of Change
Summary by CodeRabbit
New Features
Bug Fixes
Refactor