Skip to content

Refactor: Extract toolbar drag logic into createToolbarDrag primitive#248

Merged
aidenybai merged 7 commits intomainfrom
refactor/extract-toolbar-drag
Mar 17, 2026
Merged

Refactor: Extract toolbar drag logic into createToolbarDrag primitive#248
aidenybai merged 7 commits intomainfrom
refactor/extract-toolbar-drag

Conversation

@aidenybai
Copy link
Owner

@aidenybai aidenybai commented Mar 17, 2026

Summary

  • Extract drag interaction logic (pointer tracking, velocity, snap calculation, drag-aware click handling) from toolbar/index.tsx into a new createToolbarDrag SolidJS primitive (utils/create-toolbar-drag.ts)
  • Extract pure position functions (calculateExpandedPositionFromCollapsed, getCollapsedPosition) into utils/toolbar-position.ts
  • Fix bug where onDragStart callback fired on every pointermove after threshold instead of once
  • Remove dead onDragEnd callback, unused exports (velocity, hasDragMoved), and convert dragOffset from signal to plain variable

Toolbar reduced from 1608 to ~1390 lines (-13%). No behavioral changes — regression-reviewed against original code.

Test plan

  • pnpm typecheck passes
  • pnpm lint passes (0 warnings, 0 errors)
  • All 584 e2e tests pass
  • Regression review: verified all 7 behavioral paths match original code

🤖 Generated with Claude Code


Note

Medium Risk
Moderate risk because it refactors pointer/drag/snapping behavior and related event listeners/timeouts; small logic mistakes could break toolbar movement or click handling. Overlay dismiss right-click behavior is now configurable and could affect dismissal in other overlays if misused.

Overview
Refactors toolbar drag/snapping logic by extracting pointer tracking, velocity-based snapping, snap animation timing, and drag-aware click suppression into a new createToolbarDrag primitive, and wiring Toolbar to use drag.handlePointerDown, drag.isDragging, and drag.isSnapping.

Moves position math into shared utilities by adding calculateExpandedPositionFromCollapsed and getCollapsedPosition to toolbar-position.ts, removing duplicated inline calculations and simplifying collapse/expand positioning.

Behavioral tweak: registerOverlayDismiss now supports an optional shouldIgnoreRightClick flag; ContextMenu opts in so right-clicks outside don’t dismiss it.

Written by Cursor Bugbot for commit 31dac51. This will update automatically on new commits. Configure here.


Summary by cubic

Extracted toolbar drag/snapping into a reusable createToolbarDrag primitive and moved position math to toolbar-position, cutting toolbar size by ~13% with no behavior changes. Also made right-click filtering opt-in in registerOverlayDismiss to restore per-component behavior.

  • Refactors

    • Added utils/create-toolbar-drag for pointer tracking, velocity, snapping, and drag-aware click; toolbar now uses drag.handlePointerDown, drag.isDragging, and drag.isSnapping.
    • Moved position helpers to utils/toolbar-position (calculateExpandedPositionFromCollapsed, getCollapsedPosition); toolbar calls a small wrapper for clarity.
    • Merged latest main and resolved conflicts in favor of the new primitive and position utilities.
  • Bug Fixes

    • onDragStart fires once after the threshold instead of on every pointermove.
    • Made right-click filtering opt-in in registerOverlayDismiss; enabled only for ContextMenu to match original behavior.

Written for commit 31dac51. Summary will update on new commits.

aidenybai and others added 5 commits March 16, 2026 01:38
…s the application. Replace PANEL_STYLES with "bg-white" in multiple components to standardize appearance.
…ents for enhanced clarity and maintainability. Adjust event handling in context menus and toolbars to streamline user interactions.
Move drag interaction (pointer tracking, velocity, snap calculation, drag-aware
click handling) out of the 1608-line toolbar component into a focused SolidJS
primitive. Extract pure position functions (calculateExpandedPositionFromCollapsed,
getCollapsedPosition) into toolbar-position.ts.

Toolbar reduced from 1608 to ~1390 lines. All 584 e2e tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pullfrog
Copy link
Contributor

pullfrog bot commented Mar 17, 2026

Error

agent completed without reporting progress

Pullfrog  | Rerun failed job ➔View workflow run | Triggered by Pullfrogpullfrog.com𝕏

@vercel
Copy link
Contributor

vercel bot commented Mar 17, 2026

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

Project Deployment Actions Updated (UTC)
react-grab-website Ready Ready Preview, Comment Mar 17, 2026 11:38am

Resolve conflicts by keeping our extracted createToolbarDrag primitive and
position utility functions that main had removed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 17, 2026

Open in StackBlitz

@react-grab/cli

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/cli@248

grab

npm i https://pkg.pr.new/aidenybai/react-grab/grab@248

@react-grab/amp

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/amp@248

@react-grab/claude-code

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/claude-code@248

@react-grab/codex

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/codex@248

@react-grab/copilot

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/copilot@248

@react-grab/cursor

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/cursor@248

@react-grab/droid

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/droid@248

@react-grab/gemini

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/gemini@248

@react-grab/opencode

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/opencode@248

react-grab

npm i https://pkg.pr.new/aidenybai/react-grab@248

@react-grab/relay

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/relay@248

@react-grab/utils

npm i https://pkg.pr.new/aidenybai/react-grab/@react-grab/utils@248

commit: 31dac51

The shared registerOverlayDismiss utility unconditionally filtered
right-clicks (event.button === 2), but this check only existed in
the original ContextMenu code. ClearHistoryPrompt and ToolbarMenu
dismissed on any mousedown including right-clicks.

Add shouldIgnoreRightClick option (default false) and only enable
it for ContextMenu to restore original per-component behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@aidenybai aidenybai merged commit 54b8d26 into main Mar 17, 2026
16 checks passed
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.

1 participant