Skip to content

feat: table row/column drag and drop - #1467

Merged
Philipinho merged 14 commits into
docmost:mainfrom
Saul-Mirone:table-drag-handle
Aug 31, 2025
Merged

Philipinho merged 14 commits into
docmost:mainfrom
Saul-Mirone:table-drag-handle

Conversation

@Saul-Mirone

@Saul-Mirone Saul-Mirone commented Aug 13, 2025 •

Copy link
Copy Markdown
Contributor

Add drag and drop feature for table rows and columns.

Screen.Recording.2025-08-13.at.18.08.16.mov

Summary by CodeRabbit

  • New Features

    • Full table drag-and-drop: draggable row/column handles, live preview, drop indicators, auto-scroll during drag, and move-on-drop with selection preservation.
  • Style

    • UI styles for rotated horizontal handle, drag previews and drop indicators; hides default drop cursor while dragging; added editor container hook.
  • Chores

    • Added positioning helper dependency to improve handle/preview/drop-indicator placement.

@coderabbitai

coderabbitai Bot commented Aug 13, 2025 •

Copy link
Copy Markdown

Walkthrough

Adds a table drag-and-drop feature: a TipTap extension with plugin key, multiple DnD controllers (handles, preview, drop indicator, auto-scroll, empty drag image), DOM hit-testing and drag-over calculations, table/array conversion and move utilities, CSS for handles/previews, Floating UI dependency, and client integration.

Changes

Cohort / File(s) Summary
Client integration
apps/client/src/features/editor/extensions/extensions.ts, apps/client/src/features/editor/page-editor.tsx
Registers TableDndExtension in mainExtensions; adds className="editor-container" to editor wrapper.
Styles
apps/client/src/features/editor/styles/drag-handle.css, apps/client/src/features/editor/styles/table.css
Adds rotation rule for horizontal drag-handle; adds .table-dnd-preview and .table-dnd-drop-indicator styles and hides ProseMirror drop cursors while dragging.
Dependency
package.json
Adds dependency "@floating-ui/dom": "^1.7.3".
DnD extension core & exports
packages/editor-ext/src/lib/table/dnd/dnd-extension.ts, packages/editor-ext/src/lib/table/dnd/index.ts, packages/editor-ext/src/lib/table/index.ts
New TableDndExtension and TableDndKey PluginKey; added dnd re-export to table barrel and dnd index barrel.
DnD controllers & DOM helpers
packages/editor-ext/src/lib/table/dnd/handle/drag-handle-controller.ts, packages/editor-ext/src/lib/table/dnd/handle/empty-image-controller.ts, packages/editor-ext/src/lib/table/dnd/preview/preview-controller.ts, packages/editor-ext/src/lib/table/dnd/preview/drop-indicator-controller.ts, packages/editor-ext/src/lib/table/dnd/preview/render-preview.ts, packages/editor-ext/src/lib/table/dnd/auto-scroll-controller.ts
Implements draggable handles with Floating UI positioning, empty drag image controller, preview rendering and positioning, drop indicator controller, preview render helpers, and auto-scroll controller (edge threshold/scroll speed).
Pointer/target detection
packages/editor-ext/src/lib/table/dnd/calc-drag-over.ts, packages/editor-ext/src/lib/table/dnd/utils.ts
Adds drag-over calculation for rows/columns and utilities to locate hovering cell and related DnD DOMs.
Table query utilities & types
packages/editor-ext/src/lib/table/utils/query.ts, packages/editor-ext/src/lib/table/utils/types.ts, packages/editor-ext/src/lib/table/utils/index.ts
Adds table/cell query helpers and FindParentNodeResult type; introduces shared types and a utils barrel export.
Selection range utilities
packages/editor-ext/src/lib/table/utils/get-selection-range-in-column.ts, packages/editor-ext/src/lib/table/utils/get-selection-range-in-row.ts
Adds functions to compute rectangular selection ranges for columns and rows that account for merged cells.
Cell accessors
packages/editor-ext/src/lib/table/utils/get-cells-in-column.ts, packages/editor-ext/src/lib/table/utils/get-cells-in-row.ts
Adds utilities to collect CellPos entries for full columns or rows from a Selection.
Table ↔ array conversions & transforms
packages/editor-ext/src/lib/table/utils/convert-table-node-to-array-of-rows.ts, packages/editor-ext/src/lib/table/utils/convert-array-of-rows-to-table-node.ts, packages/editor-ext/src/lib/table/utils/transpose.ts, packages/editor-ext/src/lib/table/utils/move-row-in-array-of-rows.ts
Adds conversions between table node and 2D arrays, transpose helper, and in-array row-moving helper.
Move operations
packages/editor-ext/src/lib/table/utils/move-column.ts, packages/editor-ext/src/lib/table/utils/move-row.ts
Implements moveColumn and moveRow operations using the new utilities and exports Move param interfaces and functions.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant E as Editor (TipTap)
  participant X as TableDndExtension
  participant H as Handles/Preview/Indicator
  participant Utl as DnD & Table Utils
  participant PM as ProseMirror (tr)

  U->>E: Hover table
  E->>X: pointerover event
  X->>Utl: getHoveringCell(event)
  Utl-->>X: HoveringCellInfo
  X->>H: show drag handles

  U->>H: start drag
  H->>X: dragstart(type)
  X->>Utl: getDndRelatedDOMs(...)
  X->>H: init preview & drop indicator

  U->>H: move pointer
  H->>X: dragging(x,y)
  X->>Utl: getDragOverColumn/Row(...)
  Utl-->>X: target element/index
  X->>H: update preview & indicator
  X->>AutoScroll: checkXAutoScroll/checkYAutoScroll

  U->>H: drop
  H->>X: drop
  X->>Utl: moveColumn/moveRow(...)
  Utl-->>X: success
  X->>PM: dispatch transaction
  X->>H: cleanup UI
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

I’m a rabbit coder, light and quick,
I hop on tables, pull a trick.
Handles spin and previews glow,
Columns leap and rows can flow.
I nibble bugs — then off I flick. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 79abfb5 and 6740f89.

📒 Files selected for processing (1)
  • packages/editor-ext/src/lib/table/dnd/dnd-extension.ts (1 hunks)
🔇 Additional comments (14)
packages/editor-ext/src/lib/table/dnd/dnd-extension.ts (14)

1-12: LGTM! Well-structured imports.

The imports are logically organized and clearly separate TipTap core functionality from local table drag-and-drop utilities and controllers.


13-13: LGTM! Plugin key properly exported.

The plugin key follows TipTap conventions and is correctly exported for external use.


15-34: LGTM! Comprehensive drag-and-drop state management.

The class properties properly track all aspects of the drag-and-drop operation including coordinates, indices, direction, and controller references.


36-54: LGTM! Proper controller initialization and event binding.

The constructor correctly initializes all controllers and binds drag events. The separation of concerns between different controllers is well-designed.


56-67: LGTM! DOM elements properly appended to editor wrapper.

The view method correctly adds all necessary DOM elements to the editor wrapper and returns the appropriate lifecycle methods.


82-92: LGTM! Proper hover handling with dragging guard.

The pointer over handler correctly prevents interference during dragging and manages drag handle visibility based on cell hover state.


94-96: LGTM! Clean separation of column and row drag start handlers.

The separate handlers for column and row dragging provide clear entry points and delegate to a common implementation.

Also applies to: 116-118


98-114: LGTM! Column dragging logic is well-implemented.

The column dragging handler properly updates coordinates, handles preview rendering, manages auto-scroll, and calculates drop targets with direction awareness.


120-136: LGTM! Row dragging mirrors column implementation correctly.

The row dragging logic properly handles Y-axis scrolling and vertical direction calculations, maintaining consistency with the column implementation.


138-146: LGTM! Comprehensive drag end cleanup.

The drag end handler properly resets all dragging state and notifies all controllers to clean up their UI elements.


148-182: LGTM! Thorough event binding with proper cleanup.

The event binding method correctly attaches all necessary drag events and document-level events, with proper cleanup disposables for each listener.


211-219: LGTM! Proper drag event routing.

The drag handler correctly prevents default behavior and routes to the appropriate column or row dragging logic based on direction.


221-258: LGTM! Drop handling correctly processes both directions.

The drop handler properly extracts indices, creates transactions, and dispatches updates for both column and row movements. The early returns provide clear control flow.


261-271: LGTM! Extension creation follows TipTap patterns.

The extension is properly created with the correct name and plugin instantiation following TipTap conventions.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@CLAassistant

CLAassistant commented Aug 13, 2025 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 29

🧹 Nitpick comments (15)
apps/client/src/features/editor/styles/drag-handle.css (1)

49-51: Rotate uses the new individual transform property; confirm cross-browser support or add a safe fallback plan.

rotate: 90deg composes well with Floating UI’s translate transforms (unlike transform: rotate), which is good. However, older browsers may lack full support for individual transform properties. If you must support older Safari/Firefox, validate rendering; otherwise, keep as-is.

Please sanity-check on Safari 16.x and Firefox ESR.

Consider preventing accidental text selection during drag by adding this to .drag-handle (not specific to horizontal):

.drag-handle {
  user-select: none;
}
dev-container/Dockerfile (2)

6-6: Set explicit NODE_ENV for the dev container.

Make the intent clear (dev container). This also influences dependency resolution in some tools.

 WORKDIR /app
+ENV NODE_ENV=development

8-12: Layer caching opportunity: copy manifests before sources.

Current COPY . . invalidates the pnpm install layer for any source change. For faster rebuilds, copy only manifest files (package.json, pnpm-lock.yaml, pnpm-workspace.yaml, etc.) first, run pnpm install, then copy the rest. This is optional but speeds up dev cycles.

If you want, I can prepare a variant that copies the workspace manifests first; confirm the set of manifests present in this repo and I’ll tailor the COPY sequence accordingly.

packages/editor-ext/src/lib/table/utils/transpose.ts (1)

18-22: Doc nit: avoid using === with arrays in the example.

Array equality is reference-based; the example is misleading.

- * const result = transpose(arr);
- * result === [
+ * const result = transpose(arr);
+ * // result:
  *   ['a1', 'b1', 'c1', 'd1'],
  *   ['a2', 'b2', 'c2', 'd2'],
  *   ['a3', 'b3', 'c3', 'd3'],
  * ]
packages/editor-ext/src/lib/table/dnd/calc-drag-over.ts (1)

1-26: Optimize element boundary calculations.

The current implementation calls getBoundingClientRect() on every element during the search, which is expensive. Consider caching these calculations or using a more efficient search algorithm.

 function findDragOverElement(
   elements: Element[],
   pointer: number,
   axis: 'x' | 'y',
 ): [Element, number] | undefined {
   const startProp = axis === 'x' ? 'left' : 'top'
   const endProp = axis === 'x' ? 'right' : 'bottom'
   const lastIndex = elements.length - 1

+  // Pre-calculate all boundaries for better performance
+  const boundaries = elements.map(el => {
+    const rect = el.getBoundingClientRect()
+    return {
+      start: rect[startProp],
+      end: rect[endProp]
+    }
+  })

-  const index = elements.findIndex((el, index) => {
-    const rect = el.getBoundingClientRect()
-    const boundaryStart = rect[startProp]
-    const boundaryEnd = rect[endProp]
+  const index = boundaries.findIndex((boundary, index) => {
+    const { start: boundaryStart, end: boundaryEnd } = boundary

     // The pointer is within the boundary of the current element.
     if (boundaryStart <= pointer && pointer <= boundaryEnd) return true
     // The pointer is beyond the last element.
     if (index === lastIndex && pointer > boundaryEnd) return true
     // The pointer is before the first element.
     if (index === 0 && pointer < boundaryStart) return true

     return false
   })

   return index >= 0 ? [elements[index], index] : undefined
 }
dev-container/docker-compose.yml (2)

6-8: depends_on doesn’t ensure DB/Redis readiness; add healthchecks or retry logic.

depends_on controls start order only. Without readiness checks the app may try connecting before Postgres/Redis are accepting connections.

Option A (recommended): add healthchecks for db and redis, and ensure the app retries on connection failure. Example healthchecks:

   db:
     image: postgres:16-alpine
+    healthcheck:
+      test: ["CMD-SHELL", "pg_isready -U docmost -d docmost"]
+      interval: 5s
+      timeout: 3s
+      retries: 20

   redis:
     image: redis:7.2-alpine
+    healthcheck:
+      test: ["CMD", "redis-cli", "ping"]
+      interval: 5s
+      timeout: 3s
+      retries: 20

Note: Some compose variants don’t support depends_on:condition. Even with healthchecks, keep application-level retry logic for robustness.


21-28: Use non-sensitive defaults and clarify that credentials are dev-only.

POSTGRES_PASSWORD is committed as plain text. It’s acceptable in a dev-only compose, but better to:

  • Move to .env (consistent with docmost service).
  • Use a clearly dev-only placeholder and document not to reuse in prod.

Example:

   db:
     image: postgres:16-alpine
     environment:
       POSTGRES_DB: docmost
       POSTGRES_USER: docmost
-      POSTGRES_PASSWORD: STRONG_DB_PASSWORD
+      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-docmost}
apps/client/src/features/editor/extensions/extensions.ts (1)

164-173: Placement of TableDndExtension after table nodes is good; verify CSS and handle interactions.

  • Ordering: Adding TableDndExtension after CustomTable/TableRow/TableCell/TableHeader is appropriate for plugin composition.
  • Interactions: You also use GlobalDragHandle. Verify no pointer event conflicts between the global handle and the table handles (e.g., on small cells or when starting a drag near cell edges).
  • Styling: Ensure the new DnD UI CSS (drag handles, preview, drop indicators) is loaded by the client so handles render and are clickable.

If you want a simple feature toggle (e.g., for A/B or to disable in environments without CSS), consider gating the extension behind a flag:

// pseudocode
if (features.tableDnd) {
  extensions.push(TableDndExtension)
}
packages/editor-ext/src/lib/table/index.ts (1)

1-5: Consider re-exporting the new table utils if they’re intended to be public.

packages/editor-ext/src/lib/table/utils/index.ts was added but isn’t re-exported here. If external consumers should access move-row/column/query via the table barrel, add a re-export.

 export * from "./row";
 export * from "./cell";
 export * from "./header";
 export * from "./table";
 export * from "./dnd";
+export * from "./utils";
packages/editor-ext/src/lib/table/utils/index.ts (1)

1-3: Barrel for table utils looks good.

Centralizing move-column, move-row, and query exports improves discoverability. Ensure any additional helpers (e.g., transpose) are exported here if needed by consumers.

packages/editor-ext/src/lib/table/utils/convert-array-of-rows-to-table-node.ts (1)

9-12: Consider renaming parameter for clarity

The parameter name arrayOfNodes could be more descriptive. Since this is a 2D array representing table cells, consider renaming it to cellsArray or tableCells for better clarity.

packages/editor-ext/src/lib/table/dnd/preview/render-preview.ts (2)

1-5: Consider using replaceChildren for better performance

The while loop for clearing DOM children can be replaced with the more performant replaceChildren() method.

 export function clearPreviewDOM(previewRoot: HTMLElement): void {
-  while (previewRoot.firstChild) {
-    previewRoot.removeChild(previewRoot.firstChild)
-  }
+  previewRoot.replaceChildren()
 }

27-36: Optimize column preview generation

For column preview, consider checking if the column index is valid before iterating through all rows to avoid unnecessary DOM operations.

 } else {
+  // Early return if column index is clearly out of bounds
+  if (index < 0) return
+  
   rows.forEach((row) => {
     const rowDOM = row.cloneNode(false)
     const cells = row.querySelectorAll('th,td')
     if (cells[index]) {
       const cellDOM = cells[index].cloneNode(true)
       rowDOM.appendChild(cellDOM)
       previewTableBody.appendChild(rowDOM)
     }
   })
 }
packages/editor-ext/src/lib/table/utils/move-column.ts (2)

39-39: Consider edge case when origin equals target

The function checks if the target is within the origin range but doesn't explicitly handle the case where originIndex === targetIndex. While this would be caught by the includes check, it might be clearer to handle it explicitly.

Consider adding an explicit check for clarity:

 if (!indexesOriginColumn || !indexesTargetColumn) return false

+if (originIndex === targetIndex) return false
+
 if (indexesOriginColumn.includes(targetIndex)) return false

75-79: Consider performance optimization for large tables

The function performs two transpose operations on the entire table. For large tables, this could be computationally expensive.

Consider implementing a direct column manipulation approach that avoids the double transpose for better performance with large tables. However, the current implementation is correct and the transpose approach provides clean, maintainable code.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 08135a2 and 994f79d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (29)
  • apps/client/src/features/editor/extensions/extensions.ts (2 hunks)
  • apps/client/src/features/editor/styles/drag-handle.css (1 hunks)
  • apps/client/src/features/editor/styles/table.css (1 hunks)
  • dev-container/Dockerfile (1 hunks)
  • dev-container/docker-compose.yml (1 hunks)
  • package.json (1 hunks)
  • packages/editor-ext/src/lib/table/dnd/calc-drag-over.ts (1 hunks)
  • packages/editor-ext/src/lib/table/dnd/dnd-extension.ts (1 hunks)
  • packages/editor-ext/src/lib/table/dnd/handle/drag-handle-controller.ts (1 hunks)
  • packages/editor-ext/src/lib/table/dnd/handle/empty-image-controller.ts (1 hunks)
  • packages/editor-ext/src/lib/table/dnd/index.ts (1 hunks)
  • packages/editor-ext/src/lib/table/dnd/preview/drop-indicator-controller.ts (1 hunks)
  • packages/editor-ext/src/lib/table/dnd/preview/preview-controller.ts (1 hunks)
  • packages/editor-ext/src/lib/table/dnd/preview/render-preview.ts (1 hunks)
  • packages/editor-ext/src/lib/table/dnd/utils.ts (1 hunks)
  • packages/editor-ext/src/lib/table/index.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/convert-array-of-rows-to-table-node.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/convert-table-node-to-array-of-rows.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/get-cells-in-column.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/get-cells-in-row.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/get-selection-range-in-column.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/get-selection-range-in-row.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/index.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/move-column.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/move-row-in-array-of-rows.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/move-row.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/query.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/transpose.ts (1 hunks)
  • packages/editor-ext/src/lib/table/utils/types.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (12)
packages/editor-ext/src/lib/table/dnd/preview/render-preview.ts (1)
packages/editor-ext/src/lib/table/dnd/preview/preview-controller.ts (1)
  • previewRoot (19-21)
packages/editor-ext/src/lib/table/utils/move-row.ts (5)
packages/editor-ext/src/lib/table/utils/query.ts (1)
  • findTable (27-29)
packages/editor-ext/src/lib/table/utils/get-selection-range-in-row.ts (1)
  • getSelectionRangeInRow (17-89)
packages/editor-ext/src/lib/table/utils/convert-table-node-to-array-of-rows.ts (1)
  • convertTableNodeToArrayOfRows (29-61)
packages/editor-ext/src/lib/table/utils/move-row-in-array-of-rows.ts (1)
  • moveRowInArrayOfRows (6-30)
packages/editor-ext/src/lib/table/utils/convert-array-of-rows-to-table-node.ts (1)
  • convertArrayOfRowsToTableNode (9-44)
packages/editor-ext/src/lib/table/dnd/handle/drag-handle-controller.ts (1)
packages/editor-ext/src/lib/table/dnd/utils.ts (1)
  • HoveringCellInfo (48-54)
packages/editor-ext/src/lib/table/dnd/preview/preview-controller.ts (2)
packages/editor-ext/src/lib/table/dnd/utils.ts (1)
  • DraggingDOMs (95-98)
packages/editor-ext/src/lib/table/dnd/preview/render-preview.ts (2)
  • createPreviewDOM (7-37)
  • clearPreviewDOM (1-5)
apps/client/src/features/editor/extensions/extensions.ts (1)
packages/editor-ext/src/lib/table/dnd/dnd-extension.ts (1)
  • TableDndExtension (252-262)
packages/editor-ext/src/lib/table/utils/get-selection-range-in-column.ts (3)
packages/editor-ext/src/lib/table/utils/types.ts (1)
  • CellSelectionRange (13-18)
packages/editor-ext/src/lib/table/utils/get-cells-in-column.ts (1)
  • getCellsInColumn (12-36)
packages/editor-ext/src/lib/table/utils/get-cells-in-row.ts (1)
  • getCellsInRow (12-36)
packages/editor-ext/src/lib/table/utils/move-column.ts (6)
packages/editor-ext/src/lib/table/utils/query.ts (1)
  • findTable (27-29)
packages/editor-ext/src/lib/table/utils/get-selection-range-in-column.ts (1)
  • getSelectionRangeInColumn (17-91)
packages/editor-ext/src/lib/table/utils/transpose.ts (1)
  • transpose (25-29)
packages/editor-ext/src/lib/table/utils/convert-table-node-to-array-of-rows.ts (1)
  • convertTableNodeToArrayOfRows (29-61)
packages/editor-ext/src/lib/table/utils/move-row-in-array-of-rows.ts (1)
  • moveRowInArrayOfRows (6-30)
packages/editor-ext/src/lib/table/utils/convert-array-of-rows-to-table-node.ts (1)
  • convertArrayOfRowsToTableNode (9-44)
packages/editor-ext/src/lib/table/dnd/dnd-extension.ts (8)
packages/editor-ext/src/lib/table/dnd/utils.ts (4)
  • HoveringCellInfo (48-54)
  • DraggingDOMs (95-98)
  • getHoveringCell (4-37)
  • getDndRelatedDOMs (100-107)
packages/editor-ext/src/lib/table/dnd/preview/preview-controller.ts (1)
  • PreviewController (5-103)
packages/editor-ext/src/lib/table/dnd/preview/drop-indicator-controller.ts (1)
  • DropIndicatorController (6-100)
packages/editor-ext/src/lib/table/dnd/handle/drag-handle-controller.ts (1)
  • DragHandleController (5-105)
packages/editor-ext/src/lib/table/dnd/handle/empty-image-controller.ts (1)
  • EmptyImageController (1-21)
packages/editor-ext/src/lib/table/dnd/calc-drag-over.ts (2)
  • getDragOverColumn (28-36)
  • getDragOverRow (38-44)
packages/editor-ext/src/lib/table/utils/move-column.ts (1)
  • moveColumn (28-67)
packages/editor-ext/src/lib/table/utils/move-row.ts (1)
  • moveRow (27-61)
packages/editor-ext/src/lib/table/utils/get-cells-in-column.ts (2)
packages/editor-ext/src/lib/table/utils/types.ts (1)
  • CellPos (6-11)
packages/editor-ext/src/lib/table/utils/query.ts (1)
  • findTable (27-29)
packages/editor-ext/src/lib/table/utils/get-selection-range-in-row.ts (3)
packages/editor-ext/src/lib/table/utils/types.ts (1)
  • CellSelectionRange (13-18)
packages/editor-ext/src/lib/table/utils/get-cells-in-row.ts (1)
  • getCellsInRow (12-36)
packages/editor-ext/src/lib/table/utils/get-cells-in-column.ts (1)
  • getCellsInColumn (12-36)
packages/editor-ext/src/lib/table/utils/get-cells-in-row.ts (3)
packages/editor-ext/src/lib/selection.ts (1)
  • Selection (5-34)
packages/editor-ext/src/lib/table/utils/types.ts (1)
  • CellPos (6-11)
packages/editor-ext/src/lib/table/utils/query.ts (1)
  • findTable (27-29)
packages/editor-ext/src/lib/table/dnd/preview/drop-indicator-controller.ts (1)
packages/editor-ext/src/lib/table/dnd/utils.ts (1)
  • DraggingDOMs (95-98)
🪛 Checkov (3.2.334)
dev-container/docker-compose.yml

[MEDIUM] 12-13: Basic Auth Credentials

(CKV_SECRET_4)

🔇 Additional comments (20)
packages/editor-ext/src/lib/table/utils/types.ts (1)

1-18: Well-designed type definitions for table editing utilities.

The types are clearly structured and appropriately documented. The CellPos type provides essential positioning information, while CellSelectionRange effectively represents rectangular selections with proper ProseMirror integration.

packages/editor-ext/src/lib/table/utils/convert-table-node-to-array-of-rows.ts (1)

4-28: Excellent documentation with clear visual examples.

The documentation effectively explains the complex table merge handling with a clear ASCII diagram and JavaScript array representation. This will greatly help developers understand the function's behavior.

dev-container/docker-compose.yml (2)

3-5: Build context/Dockerfile path correctness.

Given this compose file resides in dev-container/, build.context: . with dockerfile: Dockerfile will resolve to dev-container/Dockerfile, which matches the intended layout. LGTM.


36-39: Named volumes are fine; no issues.

The persistent volumes for docmost, db, and redis are correctly defined. No action needed.

apps/client/src/features/editor/extensions/extensions.ts (1)

41-42: Importing TableDndExtension via the package entry is correct.

Re-export pathing through @docmost/editor-ext looks good and keeps client code decoupled from internal file structure.

packages/editor-ext/src/lib/table/dnd/index.ts (1)

1-1: Barrel export is minimal and correct.

Re-exporting the DnD extension from the dnd/ index keeps the public API clean. No issues.

packages/editor-ext/src/lib/table/index.ts (1)

5-5: Re-exporting DnD from table/index keeps the surface cohesive.

This makes TableDndExtension available via the table barrel, which is the expected import path for consumers.

packages/editor-ext/src/lib/table/utils/get-cells-in-row.ts (1)

1-36: Well-structured implementation with proper bounds checking

The function correctly handles both single and multiple row indexes, validates bounds, and properly maps cell positions. The implementation follows the same pattern as the column counterpart, ensuring consistency.

packages/editor-ext/src/lib/table/utils/get-cells-in-column.ts (1)

1-36: Clean and consistent implementation

The column selection logic correctly handles bounds validation, properly transforms cell positions to absolute positions, and maintains consistency with the row counterpart. Good use of flatMap for handling multiple columns.

packages/editor-ext/src/lib/table/utils/move-row.ts (1)

27-61: Comprehensive row movement implementation

The function properly handles row movement with appropriate validation checks, manages complex scenarios with merged cells through getSelectionRangeInRow, and correctly updates the selection after the move operation. Good defensive programming with early returns.

packages/editor-ext/src/lib/table/dnd/preview/preview-controller.ts (1)

64-80: Potential NaN offset calculation

Using parseInt on getComputedStyle(this._colDragHandle).height can return NaN if the height isn't a valid integer string (e.g., "auto", "inherit"). This would result in NaN offset values.

Use parseFloat and add validation:

 private _showColDragHandle(editor: Editor, hoveringCell: HoveringCellInfo) {
     const referenceCell = editor.view.nodeDOM(hoveringCell.colFirstCellPos);
     if (!referenceCell) return;

-    const yOffset = -1 * parseInt(getComputedStyle(this._colDragHandle).height) / 2;
+    const height = parseFloat(getComputedStyle(this._colDragHandle).height);
+    const yOffset = isNaN(height) ? 0 : -1 * height / 2;

     computePosition(
         referenceCell as HTMLElement,
         this._colDragHandle,
         {
             placement: 'top',
             middleware: [offset(yOffset)]
         }
     )
         .then(({ x, y }) => {
             Object.assign(this._colDragHandle.style, {
                 display: 'block',
                 top: `${y}px`,
                 left: `${x}px`,
             });
         })
 }

Likely an incorrect or invalid review comment.

packages/editor-ext/src/lib/table/utils/get-selection-range-in-row.ts (1)

17-89: LGTM! Well-structured implementation with proper attribution

The function correctly handles merged cells with rowspan attributes and includes appropriate attribution to the original Atlassian implementation. The logic for expanding the selection range to account for merged cells is sound.

packages/editor-ext/src/lib/table/utils/get-selection-range-in-column.ts (1)

17-91: LGTM! Consistent implementation with row counterpart

The function correctly handles merged cells with colspan attributes and maintains consistency with the row selection range implementation. The attribution to Atlassian is properly included.

packages/editor-ext/src/lib/table/utils/move-column.ts (1)

28-67: LGTM! Well-structured column move implementation

The function correctly handles column movement with proper validation, table reconstruction, and optional selection. The use of helper functions promotes code reusability.

packages/editor-ext/src/lib/table/utils/query.ts (6)

1-12: LGTM!

Clean and well-organized imports with appropriate type-only imports for TypeScript types.


18-20: LGTM!

Proper type guard implementation using instanceof for runtime type checking.


27-29: LGTM!

Concise implementation that properly leverages the generic findParentNode helper with appropriate predicate for table detection.


38-58: LGTM!

Well-structured function with proper fallback logic and null-safety checks. The documentation clearly explains the purpose and behavior.


65-71: LGTM!

Clean implementation with appropriate use of logical OR for fallback between cellAround and cellNear.


103-122: LGTM!

Well-implemented tree traversal with proper handling of the root node case (depth === 0) and clean result structure.

Comment thread dev-container/docker-compose.yml Resolved
Comment thread dev-container/Dockerfile Resolved
Comment thread package.json Resolved
@Philipinho

Copy link
Copy Markdown
Member

Works really well.

Is it possible to disable the default editor indicator when a table drag is ongoing?

Screen.Recording.2025-08-13.at.13.02.32.mov

@Saul-Mirone

Copy link
Copy Markdown
Contributor Author

@Philipinho I've added this optimization from 4954d7f.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
apps/client/src/features/editor/page-editor.tsx (1)

378-405: Ensure data-dragging is toggled on the drop-indicator, not the container

The CSS rule in
apps/client/src/features/editor/styles/table.css:132
relies on:

.editor-container:has(.table-dnd-drop-indicator[data-dragging="true"]) { … }

– so the extension must add and remove data-dragging on the .table-dnd-drop-indicator element (a child of .editor-container) during drag start/end.

• Verify in your Table DnD extension (e.g. wherever .table-dnd-drop-indicator is created) that you’re calling
– element.setAttribute("data-dragging", "true") on drag start
– element.removeAttribute("data-dragging") on drag end
• Confirm that the CSS :has() selector is supported in your target browsers or provide a fallback if needed
• No change is needed on the .editor-container wrapper itself; all logic happens on the drop indicator element

🧹 Nitpick comments (1)
apps/client/src/features/editor/page-editor.tsx (1)

378-378: Prefer CSS over inline style for position context

Move the positioning rule into CSS to avoid inline styles and keep styling concerns centralized.

Apply this diff here:

-    <div className="editor-container" style={{ position: "relative" }}>
+    <div className="editor-container">

And add this rule to your editor styles (e.g., apps/client/src/features/editor/styles/index.css or table.css):

.editor-container {
  position: relative;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 994f79d and 4954d7f.

📒 Files selected for processing (3)
  • apps/client/src/features/editor/page-editor.tsx (1 hunks)
  • apps/client/src/features/editor/styles/table.css (2 hunks)
  • packages/editor-ext/src/lib/table/dnd/preview/drop-indicator-controller.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/editor-ext/src/lib/table/dnd/preview/drop-indicator-controller.ts
  • apps/client/src/features/editor/styles/table.css
🔇 Additional comments (1)
apps/client/src/features/editor/page-editor.tsx (1)

378-378: LGTM: editor-container wrapper enables scoped DnD UI

Adding className="editor-container" (while keeping position: relative) is the right hook for the table DnD handles, previews, and drop indicators to position and scope correctly. This should also allow hiding the default ProseMirror drop cursor during a drag via CSS targeting .editor-container when data-dragging="true".

@Philipinho

Philipinho commented Aug 14, 2025 •

Copy link
Copy Markdown
Member

Larger tables have scroll areas.
I am unable to scroll with my trackpad while dragging in such cases.
We should support scrolling vertically and horizontally with the trackpad while dragging.
What do you think?

In this short demo, I can scroll without dragging but can't while dragging if I want to place the dragged column at the end of the table.

Screen.Recording.2025-08-13.at.21.57.59.mov

@Saul-Mirone

Copy link
Copy Markdown
Contributor Author

@Philipinho Hi, I've added the auto scroll feature.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
packages/editor-ext/src/lib/table/dnd/dnd-extension.ts (2)

71-80: Improve cleanup logic in destroy method.

The destroy method only runs cleanup when the editor is destroyed, but the plugin might need cleanup in other scenarios (e.g., plugin removal).


210-222: Add null check for relatedDoms before using it.

The getDndRelatedDOMs function can return undefined, but relatedDoms is passed to other methods without checking if it's defined.

🧹 Nitpick comments (2)
packages/editor-ext/src/lib/table/dnd/auto-scroll-controller.ts (1)

43-75: Consider supporting simultaneous scrolling on both axes.

The current implementation uses a single interval for both X and Y scrolling, which prevents simultaneous scrolling on both axes. When a user drags near a corner, they might expect diagonal scrolling.

Consider maintaining separate intervals for X and Y axes to enable diagonal scrolling:

-    private _autoScrollInterval?: number;
+    private _autoScrollXInterval?: number;
+    private _autoScrollYInterval?: number;

     private _startXAutoScroll = (scrollContainer: HTMLElement, speed: number) => {
-        if (this._autoScrollInterval) {
-            clearInterval(this._autoScrollInterval);
+        if (this._autoScrollXInterval) {
+            clearInterval(this._autoScrollXInterval);
         }
 
-        this._autoScrollInterval = window.setInterval(() => {
+        this._autoScrollXInterval = window.setInterval(() => {
             scrollContainer.scrollLeft += speed;
         }, 16);
     }
 
     private _stopXAutoScroll = () => {
-        if (this._autoScrollInterval) {
-            clearInterval(this._autoScrollInterval);
-            this._autoScrollInterval = undefined;
+        if (this._autoScrollXInterval) {
+            clearInterval(this._autoScrollXInterval);
+            this._autoScrollXInterval = undefined;
         }
     }
 
     private _startYAutoScroll = (scrollContainer: HTMLElement, speed: number) => {
-        if (this._autoScrollInterval) {
-            clearInterval(this._autoScrollInterval);
+        if (this._autoScrollYInterval) {
+            clearInterval(this._autoScrollYInterval);
         }
 
-        this._autoScrollInterval = window.setInterval(() => {
+        this._autoScrollYInterval = window.setInterval(() => {
             scrollContainer.scrollTop += speed;
         }, 16);
     }
 
     private _stopYAutoScroll = () => {
-        if (this._autoScrollInterval) {
-            clearInterval(this._autoScrollInterval);
-            this._autoScrollInterval = undefined;
+        if (this._autoScrollYInterval) {
+            clearInterval(this._autoScrollYInterval);
+            this._autoScrollYInterval = undefined;
         }
     }
packages/editor-ext/src/lib/table/dnd/dnd-extension.ts (1)

218-222: Simplify index extraction logic.

The index variable is assigned redundantly - you already extract it on Line 206 as draggingIndex.

-        const index = type === 'col' ? this._hoveringCell?.colIndex : this._hoveringCell?.rowIndex;
-
-        this._previewController.onDragStart(relatedDoms, index, type);
+        this._previewController.onDragStart(relatedDoms, draggingIndex, type);
         this._dropIndicatorController.onDragStart(relatedDoms, type);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4954d7f and c25e660.

📒 Files selected for processing (2)
  • packages/editor-ext/src/lib/table/dnd/auto-scroll-controller.ts (1 hunks)
  • packages/editor-ext/src/lib/table/dnd/dnd-extension.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/editor-ext/src/lib/table/dnd/auto-scroll-controller.ts (1)
packages/editor-ext/src/lib/table/dnd/utils.ts (1)
  • DraggingDOMs (95-98)
packages/editor-ext/src/lib/table/dnd/dnd-extension.ts (9)
packages/editor-ext/src/lib/table/dnd/utils.ts (4)
  • HoveringCellInfo (48-54)
  • DraggingDOMs (95-98)
  • getHoveringCell (4-37)
  • getDndRelatedDOMs (100-107)
packages/editor-ext/src/lib/table/dnd/preview/preview-controller.ts (1)
  • PreviewController (5-103)
packages/editor-ext/src/lib/table/dnd/preview/drop-indicator-controller.ts (1)
  • DropIndicatorController (6-102)
packages/editor-ext/src/lib/table/dnd/handle/drag-handle-controller.ts (1)
  • DragHandleController (5-105)
packages/editor-ext/src/lib/table/dnd/handle/empty-image-controller.ts (1)
  • EmptyImageController (1-21)
packages/editor-ext/src/lib/table/dnd/auto-scroll-controller.ts (1)
  • AutoScrollController (6-76)
packages/editor-ext/src/lib/table/dnd/calc-drag-over.ts (2)
  • getDragOverColumn (28-36)
  • getDragOverRow (38-44)
packages/editor-ext/src/lib/table/utils/move-column.ts (1)
  • moveColumn (28-67)
packages/editor-ext/src/lib/table/utils/move-row.ts (1)
  • moveRow (27-61)

@Philipinho

Philipinho commented Aug 14, 2025 •

Copy link
Copy Markdown
Member

My observations.
Safari seem to allow trackpad scrolling on drag by default.
Chrome seem not to, even with the recent change, it doesn't work.

Then on Firefox, reordering does not work at all.
Would love your thoughts on this and if you can reproduce.

Firefox video:

Screen.Recording.2025-08-14.at.12.51.19.mov

@Saul-Mirone

Copy link
Copy Markdown
Contributor Author

@Philipinho I've fixed the issue in firefox. The drag and drop API in firefox has some bugs. Chrome autoscroll works on my machine:

Screen.Recording.2025-08-15.at.15.39.14.mov

@mustafa-yilmaz

Copy link
Copy Markdown

That feature should only work for users with edit access on the page.

If it will also work for users with only view access, changes (alterations) that those users will make should not effect what other users see on the page.

@Saul-Mirone
Saul-Mirone deleted the table-drag-handle branch September 1, 2025 06:56
@coderabbitai coderabbitai Bot mentioned this pull request Sep 30, 2025
github-actions Bot added a commit to antiagingrecord/docmost that referenced this pull request Oct 9, 2025
4231ba9 Merge commit '042836cb6d7cc1f71af3ce44c7957f8abbbf8f25' into feat/aar_edition
042836c sync
4f1f0ba fix
3164b69 feat: api keys management (EE) (docmost#1665)
16c1e86 fix comment space
c9b1cad sync
bf8cf62 feat: Typesense search driver (EE) (docmost#1664)
5a2e16a Merge commit '31350303760163384113bf49d07127e886f94907' into feat/aar_edition
3bc710d Adds CLAUDE.md documentation
16914f1 Block search for non-indexed shares
ca75e29 Set default page mode to Read
3135030 fix editor converter (docmost#1647)
3fae41a fix: editor performance improvements (docmost#1648)
b50e256 sync
1f3b0c7 cloud fix
3c4cab0 v0.23.2
4de25a8 invalidate queries on space deletion
cf5bbb1 fix import html processing
ac17521 sync
9ac180f fix: enhance page import (docmost#1570)
46669fe (cloud) disable page sharing in trial mode
fe6ecdf fix: update combobox props in SpaceSelect component (docmost#1564)
04ae1d7 Allow lastColumnResizable in table
1280f96 feat: implement space and workspace icons (docmost#1558)
61d1cf8 fix: reset file inputs after import
f413720 - sync - reinstantiate S3 client to fix file upload errors during import - delete import zip file after use
8e16ad9 v0.23.1
7ada3cb fix: page import task (docmost#1551)
47c5417 sync
dc06502 sync
091e790 fix attachment search in cloud
ae24ea2 v0.23.0
9df6061 lock file
31053e2 update mermaid
eb8e850 use debug
c99bfb8 make print better
26ea04e sync
6cc58c5 sync
7d2ff34 UI fixes
b08d37f fix
d43ee77 remove debug log
5d91eb4 feat: queue imported attachments for indexing
3e9f6b1 Remove version from docker-compose.yml [deprecated] (docmost#1011)
db55de9 feat: progressive web app (docmost#614)
1919eba New Crowdin updates (docmost#1522)
7951b2e New Crowdin updates (docmost#1509)
73b78f6 more translations
cf7534d fix version display
adec36d fix: adjust margins - use default browser highlight background
f9e1080 sync
00e499b Fixing extra page bug on print (docmost#1478)
5ee6e46 checkbox aligned to text (docmost#1486)
1f797c3 fix: confluence drawio import (docmost#1518)
f12866c feat(EE): full-text search in attachments (docmost#1502)
dcbb65d feat(EE): LDAP integration (docmost#1515)
5968764 feat: emoji callout icon (docmost#1323)
242fb6b fix: set mermaid theme based on computed color scheme (docmost#1438)
74cd890 feat(EE): implement SSO group sync for SAML and OIDC (docmost#1452)
509622a ignore type error
937386e fix: hide table handles in readonly mode
60a373f fix: readonly editor table responsiveness
73ee6ee feat: subpages (child pages) list node (docmost#1462)
7d1e5bc feat: table row/column drag and drop (docmost#1467)
aa58e27 fix: exclude deleted pages (docmost#1494)
08135a2 sync
d92a942 sync
5012a68 sync
5a33777 feat: debug mode env variable (docmost#1450)
3b85f4b fix: enforce C collation for page position ordering to ensure consistent behavior in Postgres 17+ (docmost#1446)
cb2a039 fix: invalidate trashed page from tree state
95b7be6 fix: hide trash from can view permission (docmost#1445)
b0c5572 fix nested taskList in markdown export (docmost#1443)
dddfd48 feat: add attachments support for single page exports (docmost#1440)
aa6eec7 fix: exclude trashed pages from position generation
97a7701 fix local storage copy function (docmost#1442)
b97eb85 sync

git-subtree-dir: vendor/app
git-subtree-split: 4231ba9
This was referenced Dec 6, 2025
nulluserid pushed a commit to N2con-Inc/docmost that referenced this pull request Dec 17, 2025
* chore: add dev container

* feat: add drag handle when hovering cell

* feat: add column drag and drop

* feat: add support for row drag and drop

* refactor: extract preview controllers

* fix: hover issue

* refactor: add handle controller

* chore: f

* chore: remove log

* chore: remove dev files

* feat: hide other drop indicators when table dnd working

* feat: add auto scroll and bug fix

* chore: f

* fix: firefox
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.

4 participants