Repository navigation
feat: table row/column drag and drop - #1467
Conversation
WalkthroughAdds 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
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 detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🔇 Additional comments (14)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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: 20Note: 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 clarityThe parameter name
arrayOfNodescould be more descriptive. Since this is a 2D array representing table cells, consider renaming it tocellsArrayortableCellsfor better clarity.packages/editor-ext/src/lib/table/dnd/preview/render-preview.ts (2)
1-5: Consider using replaceChildren for better performanceThe 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 generationFor 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 targetThe 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 theincludescheck, 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 tablesThe 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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
CellPostype provides essential positioning information, whileCellSelectionRangeeffectively 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 checkingThe 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 implementationThe 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 implementationThe 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 calculationUsing
parseIntongetComputedStyle(this._colDragHandle).heightcan return NaN if the height isn't a valid integer string (e.g., "auto", "inherit"). This would result in NaN offset values.Use
parseFloatand 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 attributionThe 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 counterpartThe 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 implementationThe 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
instanceoffor runtime type checking.
27-29: LGTM!Concise implementation that properly leverages the generic
findParentNodehelper 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
cellAroundandcellNear.
103-122: LGTM!Well-implemented tree traversal with proper handling of the root node case (depth === 0) and clean result structure.
|
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 |
|
@Philipinho I've added this optimization from 4954d7f. |
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
apps/client/src/features/editor/page-editor.tsx (1)
378-405: Ensuredata-draggingis toggled on the drop-indicator, not the containerThe 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-draggingon the.table-dnd-drop-indicatorelement (a child of.editor-container) during drag start/end.• Verify in your Table DnD extension (e.g. wherever
.table-dnd-drop-indicatoris 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-containerwrapper 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 contextMove 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
📒 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 UIAdding 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".
|
Larger tables have scroll areas. 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 |
|
@Philipinho Hi, I've added the auto scroll feature. |
There was a problem hiding this comment.
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
getDndRelatedDOMsfunction can returnundefined, butrelatedDomsis 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
📒 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)
|
My observations. Then on Firefox, reordering does not work at all. Firefox video: Screen.Recording.2025-08-14.at.12.51.19.mov |
|
@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 |
|
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. |
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
* 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
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
Style
Chores