Skip to content

Add drag-to-reorder for thumbnail rail in dev mode#72

Merged
1weiho merged 3 commits intomainfrom
claude/add-slide-list-drag-drop-kazYX
May 7, 2026
Merged

Add drag-to-reorder for thumbnail rail in dev mode#72
1weiho merged 3 commits intomainfrom
claude/add-slide-list-drag-drop-kazYX

Conversation

@1weiho
Copy link
Copy Markdown
Owner

@1weiho 1weiho commented May 7, 2026

Summary

Adds drag-and-drop reordering functionality to the thumbnail rail in development mode, allowing users to reorder pages by dragging thumbnails. The new order is persisted back to the slide's index.tsx file.

Key Changes

  • Thumbnail Rail Component (thumbnail-rail.tsx):

    • Integrated @dnd-kit for drag-and-drop functionality
    • Added optional onReorder callback prop to enable reordering
    • Extracted thumbnail rendering logic into ThumbContents component for reusability
    • Created SortableRail wrapper component to manage drag context and handle reorder events
    • Created SortableThumb component that wraps individual thumbnails with drag handles
    • Conditionally renders sortable or static thumbnails based on onReorder prop
  • Files Plugin (files-plugin.ts):

    • Added findDefaultExportArray() to parse and locate array elements in the default export using Babel
    • Implemented reorderDefaultExportPagesInSource() to reorder array elements while preserving formatting, comments, and separators
    • Added /reorder PUT endpoint to handle page reordering requests and write changes back to disk
    • Validates reorder requests and returns appropriate error responses
  • Slide Route (slide.tsx):

    • Added local state to track page order separately from the imported module
    • Implemented reorderPage() callback that:
      • Updates local page state optimistically
      • Maintains user's current page selection during reorder
      • Sends reorder request to backend
      • Reverts changes on failure with error toast
    • Passes reorderPage to thumbnail rail only in dev mode
  • Tests (files-plugin.test.ts):

    • Added comprehensive test suite for reorderDefaultExportPagesInSource()
    • Tests cover multi-line arrays, inline arrays, identity permutations, validation, edge cases, and file preservation

Implementation Details

  • The reordering preserves exact source formatting including indentation, trailing commas, and inline comments
  • Drag activation requires a 5px pointer movement to avoid accidental triggers
  • Keyboard support included via sortableKeyboardCoordinates
  • The feature is dev-mode only (import.meta.env.DEV)
  • Optimistic UI updates with automatic rollback on server errors
  • Page selection follows the moved page during reorder to maintain user context

https://claude.ai/code/session_01VW9S5dJWqn6Du9PnsX27of

Pages in the left rail at /s/<id> are sortable via @dnd-kit.
Drop-end PUTs /__slides/<id>/reorder, which rewrites the slide's
`export default [...]` array via Babel-located source slices.
HMR reloads the slide module so the rail and canvas stay in sync.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
open-slide-demo Ready Ready Preview, Comment May 7, 2026 3:43pm
open-slide-web Ready Ready Preview, Comment May 7, 2026 3:43pm

Request Review

Zero out the x component of the sortable transform so a dragged
thumbnail can't drift sideways during reorder. Vertical reordering
behavior is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Both entries describe the same unreleased feature; fold the
axis-lock note into the original minor changeset.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@1weiho 1weiho merged commit e6b1cb8 into main May 7, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request May 7, 2026
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.

2 participants