Skip to main content

Overview

The store module provides centralized state management using Zustand. It manages bins, grid configuration, view modes, selection state, drag interactions, and undo/redo history.

Import

Types

Bin

Represents a single Gridfinity bin with all its properties.
string
required
UUID generated automatically on creation
number
required
Grid column position (0-indexed)
number
required
Grid row position (0-indexed)
number
required
Width in grid units (1 unit = 42mm)
number
required
Depth in grid units (1 unit = 42mm)
number
required
Height in grid units (1 unit = 7mm)

ViewMode

Controls the viewport layout.

RenderMode

Controls the 3D rendering style.

DragState

Tracks drag-and-drop interactions for placing and moving bins.

State Properties

Grid Configuration

number
default:"6"
Number of grid columns
number
default:"6"
Number of grid rows

Bin Management

Bin[]
default:"[]"
Array of all bins in the grid
string | null
default:"null"
ID of the primary selected bin
string[]
default:"[]"
Array of all selected bin IDs (supports multi-select)

View Settings

ViewMode
default:"'split'"
Current viewport layout mode
RenderMode
default:"'standard'"
Current 3D rendering style
boolean
default:"true"
Whether to render the baseplate
boolean
default:"false"
Whether to show dimension annotations
boolean
default:"false"
Whether to enable section view (cut-through)

Interaction State

DragState
Current drag-and-drop state

History

Bin[][]
default:"[[]]"
Undo/redo history stack of bin states
number
default:"0"
Current position in history stack

Actions

addBin

Adds a new bin to the grid.
Omit<Bin, 'id'>
required
Bin configuration without ID (generated automatically)
Example:
Source: src/store/useStore.ts:112-121

removeBin

Removes a bin by ID.
string
required
ID of the bin to remove
Source: src/store/useStore.ts:123-133

updateBin

Updates properties of an existing bin.
string
required
ID of the bin to update
Partial<Bin>
required
Properties to update (partial update)
Example:
Source: src/store/useStore.ts:135-139

moveBin

Moves a bin to a new grid position.
string
required
ID of the bin to move
number
required
New X grid position
number
required
New Y grid position
Source: src/store/useStore.ts:141-145

selectBin

Selects a bin, with optional multi-select support.
string | null
required
ID of bin to select, or null to clear selection
boolean
default:"false"
Whether to add to selection (multi-select mode)
Behavior:
  • If id is null, clears all selections
  • If multi is false, replaces current selection
  • If multi is true, toggles the bin in the selection set
Source: src/store/useStore.ts:147-160

setGridSize

Updates the grid dimensions.
number
required
Number of columns
number
required
Number of rows
Source: src/store/useStore.ts:162

setViewMode

Changes the viewport layout.
ViewMode
required
New view mode: ‘2d’, ‘3d’, or ‘split’
Source: src/store/useStore.ts:164

setRenderMode

Changes the 3D rendering style.
RenderMode
required
New render mode: ‘standard’, ‘technical’, or ‘blueprint’
Source: src/store/useStore.ts:166

setShowDimensions

Toggles dimension annotations.
boolean
required
Whether to show dimensions
Source: src/store/useStore.ts:168

setSectionView

Toggles section view (cut-through).
boolean
required
Whether to enable section view
Source: src/store/useStore.ts:170

clearAll

Removes all bins and clears selection.
Source: src/store/useStore.ts:172-175

setDragState

Updates the drag state (used internally by drag handlers).
Partial<DragState>
required
Partial drag state to merge
Source: src/store/useStore.ts:177-179

startPlacing

Enters bin placement mode with a configuration template.
Omit<Bin, 'id' | 'x' | 'y'>
required
Bin configuration for placement (position determined by user click)
Source: src/store/useStore.ts:181-190

cancelPlacing

Exits placement mode without creating a bin.
Source: src/store/useStore.ts:192

undo

Reverts to the previous state in history.
Source: src/store/useStore.ts:194-201

redo

Reapplies the next state in history.
Source: src/store/useStore.ts:203-210

Usage Example

History Management

The store automatically tracks bin changes for undo/redo:
  • Recorded operations: addBin, removeBin, updateBin, moveBin, clearAll
  • History stack: Maintains a snapshot of bins array after each operation
  • Max history: Limited only by browser memory
  • Implementation: Uses deep cloning via JSON.parse(JSON.stringify())
Source: src/store/useStore.ts:87-91