Skip to Content
New — snapgrid now ships for Svelte 5: the same dnd-kit-native, headless-first grid — drag, resize, repack, and drag between grids. See it in Svelte →
SvelteDocumentationAPI ReferenceOverview

API Overview

A map of the public surface. Follow a link for details.

@snapgridjs/svelte

The main package. Runes-based factories (the headless layer), turnkey components, and a re-export of the engine types. Headless grids render inside a dnd-kit DragDropProvider; <GridLayout> bundles one.

Factories (headless)

ExportReturns
createGridContainer{ attach, style, isDropTarget, group, controller } — the grid host
createGridItem{ attach, attachHandle, style, isDragging, item }
createGridResizeHandle{ attach, handleProps, isResizing }
createGridPlaceholder{ current }{ item, style } | null
createContainerWidth{ width, mounted, attach }
createResponsiveLayout{ breakpoint, cols, layout, onLayoutChange }
resolveControllerGridController — resolve a grid by its group

Components (turnkey)

ExportPurpose
GridLayoutDrop-in controlled grid with an item snippet (bundles the provider).
ResponsiveGridLayoutPer-breakpoint layouts.
GridItemA positioned tile with default markup + handles.
GridPlaceholderDefault landing-cell marker.
SnapGridGroupShares one provider across sibling grids (cross-grid).

Re-exported dnd-kit primitives

For convenience (one import source), @snapgridjs/svelte re-exports the dnd-kit pieces you commonly reach for with a grid: DragDropProvider (the drag context headless grids render inside), DragOverlay (an optional separate floating preview), createDraggable / createDroppable (e.g. an external-drop palette), and Feedback / PointerSensor / KeyboardSensor. Import them from @snapgridjs/svelte rather than directly from @dnd-kit/* so they share snapgrid’s single dnd-kit instance — a second copy of @dnd-kit/svelte is a separate DragDropProvider context, and drags from it never reach the grid.

There’s no overlay component to reach for: a dragged tile floats itself (dnd-kit lifts it into the top layer), so the common case needs nothing extra. The re-exported DragOverlay is the escape hatch for when the floating preview must differ from the tile — a clone, a ghost, or wholly custom markup.

To nest a non-grid drop zone inside a grid, nestedDropCollisionDetector and SNAPGRID_DROPPABLE_ATTR are exported too — pass them to your own createDroppable so the zone outranks the grid it sits in (innermost-wins). See the nesting guide.

Interop

snapMove(layout, event) — the reducer for dnd-kit interop: place a dragged item (a foreign createSortable card, or a tile crossing a grid ⇄ list seam) into a Layout at the pointer cell, with compaction. It resolves the destination grid’s geometry and compactor from the grid under the pointer, so the optional context is override-only. Pair it with removeItemWithCompactor to take a tile back out. Types: SnapMoveContext, SnapMoveEvent.

Utilities & compactors

DEFAULT_BREAKPOINTS, DEFAULT_BREAKPOINT_COLS, and the built-in compactors verticalCompactor, horizontalCompactor, noCompactor, getCompactor. Plus the layout-op and geometry helpers handy for interop, re-exported from @snapgridjs/core: insertItemWithCompactor, removeItemWithCompactor, toPositionParams, defaultGridConfig.

Types & config

Layout, LayoutItem, GridConfig, DragConfig, ResizeConfig, DropConfig, GridDropData, GridEventCallback, Compactor, CompactType, Breakpoints, BreakpointCols, ResponsiveLayouts, PositionParams, ResizeHandleAxis. See Types & config.

@snapgridjs/core

The framework-agnostic layout math: geometry, move/resize/insert/remove operations, and the drag session state machine. Most apps never import it directly. See Core engine & extras.

@snapgridjs/dnd

The framework-agnostic dnd-kit engine @snapgridjs/svelte is built on — one per-manager drag/resize/cross-grid engine (attachEngine), the observable GridController render bridge, the snapMove interop reducer, and the collision/sensor/payload helpers a binding wires up. Comes in automatically with @snapgridjs/svelte; import it directly only to build a binding for another framework.

@snapgridjs/extras

Optional packers: masonryCompactor, gravityCompactor, shelfCompactor, plus wrapCompactor and the fast O(n log n) compactors re-exported from react-grid-layout. See Core engine & extras.

Last updated on