Types

Generated by website/scripts/generate-api.ts from packages/gridla/src. Do not edit by hand; run bun run generate in website/.

State, action, and event types shared by the provider, hooks, and components.

import {  } from 'gridla/react'
import type { GridActions, GridChangeDetail, GridChangeReason, GridInteraction, GridInteractionMode, GridPreview, GridProviderConfig, GridState } from 'gridla/react'
ExportKindSummary
GridActionstypeImperative layout and selection API exposed by the controller.
GridChangeDetailtypeDescribes an accepted change: the reason, the affected item when there is one, and the solver strategy for solved operations.
GridChangeReasontypeWhy the layout changed, as reported in GridChangeDetail.
GridInteractiontypeThe gesture currently in progress.
GridInteractionModetypeKind of gesture: dragging an item or resizing it.
GridPreviewtypeThe solver's latest answer for the gesture in progress.
GridProviderConfigtypeResolved provider configuration: every SolveOptions field plus the responsive, drag-threshold, and keyboard-step settings with defaults applied.
GridStatetypeController state held in the store.

Types

GridActions

type · interaction/types.ts:99

Imperative layout and selection API exposed by the controller. The object is stable for the controller's lifetime.

export type GridActions<TData = unknown> = {
  /** Replace the whole layout. */
  setLayout: (layout: GridLayout<TData>) => void
  /** Move an item programmatically. Returns whether the solver accepted it. */
  move: (itemId: string, position: GridPoint, options?: SolveOptions) => boolean
  /** Resize an item programmatically. */
  resize: (
    itemId: string,
    change: { edge: GridResizeEdge; delta: GridPoint } | { rect: Partial<GridRect> },
    options?: SolveOptions,
  ) => boolean
  /** Insert an item at a position or centered on a pointer. */
  place: (
    item: NewGridItem<TData>,
    at: { position: GridPoint } | { pointer: GridPoint },
    options?: SolveOptions,
  ) => boolean
  remove: (itemId: string) => void
  /** Patch an item's fields (constraints, policy, data). Geometry is re-clamped. */
  update: (itemId: string, patch: Partial<GridItem<TData>>) => void
  select: (itemId: string | null) => void
  /** Cancel the gesture in progress without committing. */
  cancel: () => void
  /**
   * Preview a new item (for example one dragged from a palette) centered on a
   * pointer position in canvas pixels. Returns the preview, or `null` when it
   * cannot be placed. Follow up with `commitIncoming` or `clearIncoming`.
   */
  previewIncoming: (item: GridItem<TData>, pointer: GridPoint) => GridPreview<TData> | null
  /** Commit the incoming preview into the layout. Returns whether one was committed. */
  commitIncoming: () => boolean
  /** Drop the incoming preview without committing. */
  clearIncoming: () => void
}
MemberTypeDescription
setLayout(layout: GridLayout\<TData\>) =\> voidReplace the whole layout.
move(itemId: string, position: GridPoint, options?: SolveOptions) =\> booleanMove an item programmatically. Returns whether the solver accepted it.
resize`(itemId: string, change: { edge: GridResizeEdge; delta: GridPoint; } \{ rect: Partial<GridRect>; }, options?: SolveOptions) => boolean`
place`(item: NewGridItem<TData>, at: { position: GridPoint; } \{ pointer: GridPoint; }, options?: SolveOptions) => boolean`
remove(itemId: string) =\> void
update(itemId: string, patch: Partial\<GridItem\<TData\>\>) =\> voidPatch an item's fields (constraints, policy, data). Geometry is re-clamped.
select`(itemId: string \null) => void`
cancel() =\> voidCancel the gesture in progress without committing.
previewIncoming`(item: GridItem<TData>, pointer: GridPoint) => GridPreview<TData> \null`
commitIncoming() =\> booleanCommit the incoming preview into the layout. Returns whether one was committed.
clearIncoming() =\> voidDrop the incoming preview without committing.

GridChangeDetail

type · interaction/types.ts:73

Describes an accepted change: the reason, the affected item when there is one, and the solver strategy for solved operations.

export type GridChangeDetail = {
  reason: GridChangeReason
  itemId?: string
  strategy?: SolveStrategy
}
MemberTypeDescription
reasonGridChangeReason
itemId?string
strategy?SolveStrategy

GridChangeReason

type · interaction/types.ts:60

Why the layout changed, as reported in GridChangeDetail.

export type GridChangeReason =
  | 'move'
  | 'resize'
  | 'place'
  | 'remove'
  | 'update'
  | 'transfer'
  | 'set'

GridInteraction

type · interaction/types.ts:17

The gesture currently in progress.

export type GridInteraction = {
  itemId: string
  mode: GridInteractionMode
  edge?: GridResizeEdge
  pointerId: number | null
  /** Where the pointer grabbed the item, relative to its top-left. */
  grabOffset: GridPoint
  /** Item rect at gesture start, in rendered canvas pixels. */
  origin: GridRect
  /** Pointer position at gesture start, in rendered canvas pixels. */
  start: GridPoint
}
MemberTypeDescription
itemIdstring
modeGridInteractionMode
edge?GridResizeEdge
pointerId`number \null`
grabOffsetGridPointWhere the pointer grabbed the item, relative to its top-left.
originGridRectItem rect at gesture start, in rendered canvas pixels.
startGridPointPointer position at gesture start, in rendered canvas pixels.

GridInteractionMode

type · interaction/types.ts:14

Kind of gesture: dragging an item or resizing it.

export type GridInteractionMode = 'move' | 'resize'

GridPreview

type · interaction/types.ts:31

The solver's latest answer for the gesture in progress.

export type GridPreview<TData = unknown> = {
  layout: GridLayout<TData>
  item: GridItem<TData>
  strategy: SolveStrategy
  shiftedSiblings: boolean
  accepted: boolean
}
MemberTypeDescription
layoutGridLayout\<TData\>
itemGridItem\<TData\>
strategySolveStrategy
shiftedSiblingsboolean
acceptedboolean

GridProviderConfig

type · react/types.ts:18

Resolved provider configuration: every SolveOptions field plus the responsive, drag-threshold, and keyboard-step settings with defaults applied. Same shape as GridControllerConfig from gridla/interaction.

export type GridProviderConfig = GridControllerConfig
MemberTypeDescription
gap?numberMinimum distance kept between neighbors. Default 0.
snapDistance?numberDistance within which edges attract. Default 24.
snap?booleanWhen false, alignment snapping is skipped so the item tracks the requested position exactly. Bounds, gap, and constraint rules still apply. Default true.
onTrace?TraceCallbackReceives one event per solve describing which strategy produced the result.
responsivebooleanProject the layout onto the measured canvas size. When false, the canvas element is sized to the layout instead. Default true.
dragThresholdnumberMinimum pointer travel before a press becomes a drag. Default 4.
keyboardStepnumberPixels moved per arrow key press. Default 8; Shift multiplies by 4.

GridState

type · interaction/types.ts:43

Controller state held in the store. layout is what interactions operate on; source is what the caller owns.

export type GridState<TData = unknown> = {
  /** The layout the controller was given (or owns). */
  source: GridLayout<TData>
  /** Measured canvas element size, or `null` until measured. */
  size: GridSize | null
  /** `source` projected onto `size`. Interactions operate on this layout. */
  layout: GridLayout<TData>
  interaction: GridInteraction | null
  /** Rect that tracks the pointer during a gesture, in rendered pixels. */
  activeRect: GridRect | null
  preview: GridPreview<TData> | null
  selectedId: string | null
  /** True while the active item is being previewed in another canvas. */
  transferring: boolean
}
MemberTypeDescription
sourceGridLayout\<TData\>The layout the controller was given (or owns).
size`GridSize \null`
layoutGridLayout\<TData\>source projected onto size. Interactions operate on this layout.
interaction`GridInteraction \null`
activeRect`GridRect \null`
preview`GridPreview<TData> \null`
selectedId`string \null`
transferringbooleanTrue while the active item is being previewed in another canvas.