Skip to content

feat: snap-to-grid for entity drag#61

Merged
lucasfelixs merged 3 commits into
mainfrom
40/grid-snapping
Jun 16, 2026
Merged

feat: snap-to-grid for entity drag#61
lucasfelixs merged 3 commits into
mainfrom
40/grid-snapping

Conversation

@lucasfelixs

@lucasfelixs lucasfelixs commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds a snapToGrid(value, gridSize) pure utility to @floormap-tools/core that rounds a world-space coordinate to the nearest grid multiple
  • Wires the option through both handler implementations (packages/svg/src/handlers.ts and packages/adapters/react/src/internal/attachHandlers.ts) and exposes it as snapToGrid?: number on SvgRendererOptions and FloormapCanvasProps
  • Snap is applied to the entity's absolute position (not the drag delta) on every pointermove, preventing floating-point accumulation across frames
  • Adds UI controls to both example apps — a checkbox to toggle snap and a number input for grid size; the vanilla JS example remounts the renderer on change since mountSvgRenderer bakes options at mount time

Changes

Package What changed
@floormap-tools/core New snapToGrid export in utils.ts; 5 new unit tests
@floormap-tools/svg snapToGrid?: number option on SvgRendererOptions; applied in handlers.ts; 3 new integration tests
@floormap-tools/react snapToGrid?: number prop on FloormapCanvas; wired through attachHandlers
examples/js-vanilla Snap toggle + grid-size input; destroy/remount pattern
examples/react Snap toggle + conditional grid-size input via React state
.claude/skills New /issue skill for creating and editing GitHub issues

Test plan

  • pnpm test — all 159+ tests pass, including new snapToGrid unit tests and handler integration tests
  • pnpm typecheck — no errors across all packages
  • Open http://localhost:5173 (vanilla) or http://localhost:5174 (React), enable "Snap to grid", drag an entity — position should snap to the nearest 40-unit grid point
  • Change grid size to 20, drag again — tighter snap grid
  • Disable snap, drag — free movement, no snapping

Closes #40

🤖 Generated with Claude Code

@lucasfelixs lucasfelixs self-assigned this Jun 14, 2026
@lucasfelixs lucasfelixs added the enhancement New feature or request label Jun 14, 2026
@lucasfelixs lucasfelixs merged commit f9c8c20 into main Jun 16, 2026
1 check passed
@lucasfelixs lucasfelixs deleted the 40/grid-snapping branch June 16, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Snapping ao grid

1 participant