Core concepts
Mosyn has a small set of concepts, but they work together closely. A dashboard has one shared interaction provider, one or more grids, and tiles that describe each grid’s layout and content.
Start with one shared provider
Section titled “Start with one shared provider”MosynManager is required around every <Mosyn /> that belongs to the same dashboard. It owns the dashboard’s drag manager, which coordinates selection, dragging, resizing, and movement between registered grids.
Use one provider for the root grid, every nested grid, and every component that calls a Mosyn hook. Do not create another provider around a child grid: it would create a separate manager and interaction space.
import { MosynManager } from 'mosyn';
export function Dashboard() { return ( <MosynManager> <DashboardContents /> </MosynManager> );}Hooks such as useMosynManager() and useGridStore() must run in a descendant of the provider. They cannot run in the component that creates the provider, because that component is outside the context it returns.
A complete dashboard shape
Section titled “A complete dashboard shape”This example shows the normal relationship between application UI, the manager, the root-grid store, and the grid itself.
import { Mosyn, useGridStore, useMosynManager } from 'mosyn';import type { Tile } from 'mosyn';
const dashboardTiles: Tile[] = [ { id: 'revenue', x: 1, y: 1, w: 58, h: 18, renderer: <section>Revenue</section> }, { id: 'activity', x: 61, y: 1, w: 58, h: 18, renderer: <section>Activity</section> },];
function DashboardToolbar() { const { manager, selected, setSelected } = useMosynManager(); const tileCount = useGridStore((state) => state.tiles.length); const addTile = useGridStore((state) => state.addTile);
return ( <header> <span>{tileCount} tiles</span> <button type="button" onClick={() => setSelected(undefined)} disabled={!selected}> Clear selection </button> <button type="button" onClick={() => manager.setSelected(dashboardTiles[0])}> Select revenue </button> <button type="button" onClick={() => addTile({ id: crypto.randomUUID(), x: 1, y: 21, w: 30, h: 14, renderer: <section>New tile</section>, })} > Add tile </button> </header> );}
export function DashboardContents() { return ( <> <DashboardToolbar /> <Mosyn tiles={dashboardTiles} DragCancel={['button', 'input', 'textarea', 'select']} /> </> );}useMosynManager() is the normal way to access the shared manager. It exposes manager, reactive selection state, and setSelected; it can also receive selection callbacks. useGridStore(selector) subscribes to the root grid’s live state or actions. See the Hooks reference for each hook’s full contract.
The dashboard model
Section titled “The dashboard model”| Concept | What it represents |
|---|---|
| Provider | The dashboard-scoped interaction boundary. It creates the shared MosynManager and makes manager and store hooks available below it. |
| Manager | The coordinator behind selection, drag/resize state, grid registration, and transfers between grids. Access it with useMosynManager() rather than constructing one yourself. |
| Grid | An independently stored arrangement of tiles. <Mosyn /> renders one grid. |
| Tile | One layout item: its stable identity, grid-unit geometry, optional constraints/data, and React renderer. |
| Store / layout | The live, committed tile arrangement for one grid. Read it reactively with useGridStore(). |
| Container tile / sub-grid | A tile marked as a workspace that renders another <Mosyn /> and owns a child grid. |
Grids and tiles
Section titled “Grids and tiles”A grid is the surface where tiles are placed. Each <Mosyn /> creates a separate Zustand-backed store, so the root grid and each nested grid have independent live layouts.
A tile is the record Mosyn uses to render and arrange one item. id, x, y, w, and h are required. A tile can also carry application data, React content through renderer, inline style, header/footer content, and minimum or maximum dimensions.
import type { Tile } from 'mosyn';
export const tiles: Tile[] = [ { id: 'revenue', x: 1, y: 1, w: 58, h: 18, minW: 30, minH: 14, data: { period: 'This month' }, renderer: (tile) => <RevenueChart period={tile.data?.period} />, },];id is a tile’s identity for its whole lifetime. Keep it stable and unique across the entire dashboard, including nested grids. Changing it makes Mosyn treat the entry as a different tile.
Mosyn owns placement and interaction; your application owns the tile UI. The renderer field accepts a React element or a function receiving the current tile. Use the function form when content needs current tile data or dimensions. See Tile for the full type.
Coordinates and size
Section titled “Coordinates and size”Tile positions and dimensions are grid units, not pixels:
xandyplace the tile’s top-left corner.wandhdefine its width and height.- Positions start at
1. Leave one grid unit between initial tiles, because directly adjacent tiles count as colliding. - The root grid always has 120 columns. Its column width flexes with the host width, while each row is 12px high.
Mosyn fills its host, so the host must have a resolved height—especially inside flex layouts.
.dashboard { display: flex; min-height: 0; height: 100vh; }Layout state lives in each grid store
Section titled “Layout state lives in each grid store”The tiles prop seeds a grid’s layout. Once mounted, Mosyn writes interaction results to that grid’s live store. It does not emit an onChange callback.
Keep the input array stable across unrelated parent renders. Define static tiles outside the component, or memoize derived tiles. Passing a new array replaces the grid’s live layout.
import { useMemo } from 'react';
const initialTiles = [/* ... */];
export function DashboardContents() { const tiles = useMemo(() => initialTiles, []); return <Mosyn tiles={tiles} />;}Use useGridStore() from a provider descendant when application UI needs the current layout or a store action.
import { useGridStore } from 'mosyn';
export function SaveLayoutButton() { const tiles = useGridStore((state) => state.tiles); return <button onClick={() => saveLayout(tiles)}>Save layout</button>;}By default, the hook reads the root grid. Pass a container tile id to read a nested grid instead:
const workspaceTiles = useGridStore((state) => state.tiles, 'workspace');For saving, persist structural tile data and your own serializable data—not React renderer values—then reattach renderers when you load. See State and persistence.
Container tiles and sub-grids
Section titled “Container tiles and sub-grids”Make a tile a container with isContainer: true. Give it children for its initial child layout, then render a nested <Mosyn /> from the container renderer. Pass that current container tile through the container prop.
import { Mosyn } from 'mosyn';import type { Tile } from 'mosyn';
const workspaceTiles: Tile[] = [ { id: 'workspace-notes', parentId: 'workspace', x: 1, y: 1, w: 24, h: 14, renderer: <Notes /> }, { id: 'workspace-tasks', parentId: 'workspace', x: 27, y: 1, w: 24, h: 14, renderer: <Tasks /> },];
export const workspace: Tile = { id: 'workspace', x: 1, y: 21, w: 78, h: 40, isContainer: true, children: workspaceTiles, renderer: (tile) => <Mosyn tiles={tile.children ?? []} container={tile} />,};The container’s id identifies its nested grid. Each child tile’s parentId identifies the container grid it belongs to; Mosyn updates that ownership when a tile moves between grids. Use the tile passed to renderer, rather than closing over the original workspaceTiles, so the nested grid receives current children.
The nested grid must remain below the same top-level MosynManager as its root grid. That shared manager lets Mosyn coordinate the complete workspace and preserve non-container tile content while it moves between grids. See Nested grids for the full pattern.
What happens during interaction?
Section titled “What happens during interaction?”Click a tile to select it. Drag a tile to move it, or use one of the selected tile’s edges or corners to resize it. Mosyn shows a preview before release, then writes the committed result to the relevant grid store.
When dragging over another tile, the pointer position chooses a contextual action:
| Drop target | Result |
|---|---|
| Free space | Move the tile to that position. |
| Centre of another tile | Swap their positions and sizes. |
| Left, right, top, or bottom region | Split the target region in that direction. |
Use DragCancel for controls that must stay clickable inside a tile, such as buttons, inputs, editors, menus, and links. For exact interaction behavior, constraints, and read-only grids, see Drag and resize.
Next steps
Section titled “Next steps”- Components — provider and grid props.
- Tile — every tile field and constraint.
- Hooks — manager, selection, and store subscriptions.
- Drag and resize — interaction and cancellation controls.
- Nested grids — container workspaces.
- State and persistence — save and restore layouts.