# Jali > A new layout primitive for React apps. Split any part of your app into adaptive tiling panes; your users arrange them the way they work, on any screen. The whole of Jali's docs, one page after another. The same pages ship inside the package as `node_modules/jali-layout/docs/`, for the installed version. --- # Introduction What Jali is, the problem it solves for apps where people work on several things at once, and when not to use it. Jali is a layout library for apps where people work on several things at once. Each thing gets a pane, and the panes sit in rows, columns and tabs. You describe the kinds of pane your app has. Jali decides where they go, how they fit the window, and how people move between them. Its core has no framework and no dependencies. React renders it, from `jali-layout/react`. ## The problem Some work doesn't happen one screen at a time. A support agent reads a ticket while checking the customer's last order. A credit reviewer keeps an application open beside the borrower's file. Someone in operations compares two shipments. Most web apps show one view at a time, so people open browser tabs, lose their place and copy details between windows. Building panes by hand is a lot of work. You have to split and resize, decide what happens when the window gets narrow, keep focus in the right place, and remember the layout. Jali does that work once, for every screen size. ## What it gives you ### Panes that fold instead of squeeze Each [pane kind](https://jali.ramizrahman.com/get-started/key-concepts#kind) says the narrowest and shortest it can be and still work. When the window is too small for every pane, Jali folds some of them into tabs of their neighbours. It never squeezes a tiled pane below its minimum. When the room comes back, so do the panes. The pane you are working in, the pane it was opened from, and the details it opened fold last. On a phone, Jali shows one pane at a time; widen the window and the arrangement you had comes back. ### Focus, undo and the keyboard One pane has focus, and commands act on it. Closing or tucking a pane away can be undone. F6 moves focus to the next pane, and every command has a key you can change or turn off. With the palette feature, ⌘K (Ctrl+K on Windows and Linux) lists them all. A pane can report unsaved work, such as an edited query that hasn't run. Jali asks before any change would lose it. ### A detail that follows a list Open a record from a list, and the record's pane follows the list's selection: move down the list and the detail shows each row in turn. It waits until the selection rests, so holding a key doesn't load every row on the way. **Keep** the detail to hold it on one record. ### The layout in the address With the `urlSync()` feature, the layout is written into the URL. A link opens the same panes in the same places, and Back and Forward step through the changes people made. If your app has a router, the router can own the address instead. ### Curated pages For work that centres on one item, such as reviewing a loan application, you can design a page: a set of views in tabs, with a list of items beside it. - In **Single view**, people see one view at a time, like any web app, and links open in a sheet over it. - In **Split view**, they lay the views out side by side, starting from the layout you designed. ### Only what you use Everything beyond laying out panes is a feature you pass in: the address, the ⌘K palette, Settings, renaming, Pop out. An app ships only the features it imports. See [Features](https://jali.ramizrahman.com/guides/your-app#choose-features). ## One package `jali-layout` is one package, with an entry for each part: - [`jali-layout`](https://jali.ramizrahman.com/reference/core): pane kinds, layouts, `createJali`, actions and events. No framework. - [`jali-layout/react`](https://jali.ramizrahman.com/reference/react): ``, `definePane`, the hooks and the parts you place in your own chrome. - One entry per feature, such as `jali-layout/url` and `jali-layout/palette`, and [`jali-layout/features`](https://jali.ramizrahman.com/reference/features) for Jali's usual set. - [`jali-layout/testing`](https://jali.ramizrahman.com/reference/testing) for your tests. To give an AI model your panes as tools, see [Let an agent arrange panes](https://jali.ramizrahman.com/guides/your-app#let-an-agent-arrange-panes). ```sh npm install jali-layout ``` ## When not to use it - **An app that shows one view at a time.** If people never need two things on screen together, a router and ordinary pages are simpler. - **A dashboard of fixed tiles.** Jali is for panes that people open, close, move and resize. A grid of charts that never changes shape doesn't need a layout tree. - **Windows that float and overlap.** Jali's panes tile: they sit in rows, columns and tabs, not on top of each other. The one exception is Pop out, which moves a single pane into a window of its own. - **Bundle size above all.** With React, Jali's floor is about 84 KB gzipped (its core, its React parts and its styles), because it fits, focuses, undoes and announces. A splitter on its own is much smaller. See [Why Jali](https://jali.ramizrahman.com/get-started/why-jali). ## Next - [Installation](https://jali.ramizrahman.com/get-started/installation): Add Jali to a Vite, Next.js or other React app. - [Quickstart](https://jali.ramizrahman.com/get-started/quickstart): Build the smallest app, step by step. - [Key concepts](https://jali.ramizrahman.com/get-started/key-concepts): The words Jali uses, and what each one means. --- # Why Jali Jali beside dockview, FlexLayout, react-mosaic, Golden Layout and react-resizable-panels: when each is the better choice, and what Jali costs and works with. Several good libraries lay out panes on the web. They solve different problems. This page says what Jali does differently, and where another library fits better. Every claim about another library comes from its own README or site (read on 22 Nov 2026); where its docs don't say, the table says "not stated", not "no". ## What Jali is built around Most layout libraries give people a docking surface: drag tabs and groups anywhere, and save the result. Jali starts from a different question: **what should the app show when there isn't room for everything?** - **Fold, never squeeze.** Each kind of pane declares its minimum width and height. When the window is too small, Jali folds panes into tabs of their neighbours, in an order that protects the pane you are working in. When room returns, they come back to their exact place. See [How a layout fits](https://jali.ramizrahman.com/learn/fitting). - **Panes show objects.** A pane is a kind plus params (`order({ id: 7 })`), not a component instance. That is what makes a layout fit in a link, lets a detail follow a list's selection, and lets one object have one pane. - **The address is the layout.** With `urlSync()`, a link reopens the same panes in the same places, and Back and Forward step through deliberate changes. See [Keep the layout in the URL](https://jali.ramizrahman.com/guides/url-and-routers). - **Typed refusals.** Every action returns what happened, or why it didn't (`{ ok: false, reason: "unsaved" }`). Nothing throws at a person's click. - **A framework-free core.** The layout, fitting, actions and keys are plain TypeScript with no dependencies. React is one adapter. ## At a glance | | Jali | dockview | FlexLayout | react-mosaic | Golden Layout | react-resizable-panels | | --- | --- | --- | --- | --- | --- | --- | | Frameworks | React (core has none) | React, Vue, Angular, plain TS | React | React | Plain JS; guides for React and Angular | React | | Runtime dependencies | None | "Zero dependencies" | "only dependency is React" | Built on react-dnd | Not stated | Not stated | | Licence | Apache-2.0 | MIT (an enterprise add-on is commercial) | MIT | Apache-2.0 | MIT | MIT | | Splits and tabs | Rows, columns, tab stacks | Grids, split views, tab groups | Rows, tabsets, borders | N-ary splits, tabs | Not stated in the README | Groups, panels, grids | | Drag to rearrange | Yes | Yes | Yes | Yes | Yes | Resize by dragging | | Floating panels | No (tiles only) | Floating groups | Floating panels | Not stated | Not stated | Not stated | | Pop out to a window | One pane, Chrome and Edge | Popout windows | Popout windows | Not stated | Native popout windows | Not stated | | Save and restore | Layout JSON, the URL, presets | Serialisation | `toJson` / `fromJson` | Controlled tree value | Load and save layouts | `defaultLayout`, `getLayout` | | Too little room | Panes fold into tabs and return | Not stated | Tab overflow menu | Not stated | Not stated | Min and max sizes; panels can collapse | | Layout in the URL | Yes, with `urlSync()` | Not stated | Not stated | Not stated | Not stated | Not stated | | Keyboard and ARIA | Every command keyed; APG separators, tabs and dialogs | Not stated | ARIA roles, configurable keymap | Not stated | Not stated | Keyboard separators with ARIA | Sources: [dockview](https://dockview.dev/), [FlexLayout](https://github.com/caplin/FlexLayout), [react-mosaic](https://github.com/nomcopter/react-mosaic), [Golden Layout](https://github.com/golden-layout/golden-layout), [react-resizable-panels](https://github.com/bvaughn/react-resizable-panels). ## When another library is the better choice - **Choose dockview** for an IDE-style docking surface with floating groups, or if your app is built with Vue or Angular. - **Choose FlexLayout** for a React docking layout with border panels around the edges and tabs that pop out into floating panels. - **Choose react-mosaic** for a tiling window manager in React where you want to own the tree as controlled state. - **Choose Golden Layout** for a framework-free layout manager with native popout windows. - **Choose react-resizable-panels** when you need resizable split panels and nothing more. It is a much smaller dependency than Jali. ## When Jali is the better choice - People open records from other records, and the layout must stay usable as they do: on a laptop, on a large screen, and on a phone. - A link should reopen exactly what someone was looking at, and Back should undo a layout change. - A detail pane should follow the selection in a list. - You want keyboard access, screen reader announcements and focus handling done for you, and checked by tests. - You want to ship only the features you use, and test layouts without a browser (`jali-layout/testing`). ## What it costs Jali does more than a splitter, and it weighs more. Measured with `pnpm size` in this repo (gzipped, minified, production build): | What the app ships | Jali's core | Jali's React parts | Styles | | --- | --- | --- | --- | | The floor: one kind of pane, no features | 51.9 KB | 23.5 KB | 8.3 KB | | With `defaultFeatures()` | 55.4 KB | 26.2 KB | 8.3 KB | | Without React (`headless`) | 46.4 KB | | | | Only the layout tree (`row`, `column`, the `layout` namespace) | 10.3 KB | | | Each feature's own cost is on [Features](https://jali.ramizrahman.com/guides/your-app#choose-features). ## Before you choose ### Does it work with server rendering and Next.js? Yes. `jali-layout/react` is marked `"use client"`, and Jali renders on the server and hydrates without a mismatch when both sides get the same inputs. See [Installation](https://jali.ramizrahman.com/get-started/installation#next-js-app-router). ### Does it work with Vue, Svelte or Solid? Not yet. The core (`jali-layout`) has no framework, and `jali-layout/adapter` holds what an adapter needs, but only the React adapter exists. ### Does it work with React Native? No. Jali renders to the DOM. ### Can panes float and overlap? No. Panes tile in rows, columns and tabs. One pane at a time can pop out into a window of its own with `popOut()` (Chrome and Edge on desktop). ### Which versions are stable? Jali hasn't reached 1.0 yet. The public entries (`jali-layout`, `jali-layout/react`, the feature entries, `jali-layout/page` and `jali-layout/testing`) are the API being stabilised for 1.0. `jali-layout/adapter`, for framework adapters, is outside that promise: it may change in any minor version. --- # Installation Add Jali to a React app with Vite, Next.js or another bundler, render it on the server, and set up TypeScript. ## Install ```sh npm install jali-layout ``` That is the only package. It holds the framework-free core (`jali-layout`), the React parts (`jali-layout/react`), one entry per feature and the styles. - **React:** 18.2 or later, 18 or 19. React is an optional peer dependency: an app that uses only `jali-layout` (no `jali-layout/react`) needs none. - **Browsers:** Baseline 2024. Chrome and Edge 123, Firefox 120, Safari 17.5, and Electron 30. The colours are `light-dark()` pairs, the newest CSS Jali needs; older browsers show the panes without their colours. - **TypeScript:** optional. The types ship in the package. Jali's own code is checked with `strict`. - **Dependencies:** none at run time. ## Add the styles Import `jali-layout/styles.css` once, and name the order of your CSS cascade layers before it: ```css filename="app.css" @layer base, jali; ``` Every rule in Jali's styles sits in the `jali` layer. Your resets go in a layer before it. Your own styles go in a later layer, or outside any layer, and win without `!important`. With Tailwind 4 the line is `@layer theme, base, jali, components, utilities;`. See [Theming](https://jali.ramizrahman.com/guides/theming). Jali fills the box you give it, so that box needs a height. In development, a console warning says so when it has none. ## Vite Nothing to configure. Import the styles from your entry file, after your own stylesheet that holds the `@layer` line: ```tsx filename="src/main.tsx" import { createRoot } from "react-dom/client"; import { createJali, row } from "jali-layout"; import { JaliRoot, definePane } from "jali-layout/react"; import "./app.css"; import "jali-layout/styles.css"; const note = definePane("note", { params: { id: Number }, title: ({ id }) => `Note ${id}`, Component: ({ params }) =>
Note {params.id}
, }); const jali = createJali({ panes: [note], layout: row(note({ id: 1 }), note({ id: 2 })) }); createRoot(document.getElementById("root")!).render(); ``` The [Quickstart](https://jali.ramizrahman.com/get-started/quickstart) builds this app step by step. ## Next.js (App Router) `jali-layout/react` starts with `"use client"`, so its components render inside your server components. The instance itself holds functions, so it can't cross from a server component to a client one. Make it in a client component: `app/notes/panes.tsx` ```tsx "use client"; // app/notes/panes.tsx: a client component. The instance is made here, once per render tree, never in a server // component (it holds functions and can't be passed from server to client). import { useState } from "react"; import { createJali, memoryLocation, row } from "jali-layout"; import { JaliRoot, definePane } from "jali-layout/react"; import { defaultFeatures } from "jali-layout/features"; import { urlSync } from "jali-layout/url"; const note = definePane("note", { params: { id: Number }, title: ({ id }) => `Note ${id}`, Component: ({ params }) =>
Note {params.id}
, }); export function Panes({ search }: { search: string }) { const [jali] = useState(() => createJali({ panes: [note], layout: row(note({ id: 1 }), note({ id: 2 })), features: [ ...defaultFeatures(), // On the server, the request's address; in the browser, the browser's. urlSync(typeof window === "undefined" ? { location: memoryLocation(search) } : {}), ], // The first render fits this size on both sides, so the HTML matches; then measures the real one. size: { width: 1280, height: 800 }, }), ); return ; } ``` Then render that component from a page. Pass it the request's search, so the server renders the layout a link names: `app/notes/page.tsx` ```tsx // app/notes/page.tsx: a server component. It passes the request's search to the client component, so the server // renders the layout the link names. import { Panes } from "./panes"; export default async function NotesPage({ searchParams, }: { searchParams: Promise>; }) { const params = new URLSearchParams(); for (const [key, value] of Object.entries(await searchParams)) for (const v of [value].flat()) if (v !== undefined) params.append(key, v); return (
); } ``` Import the styles from your root layout, after the stylesheet that names the layers: ```tsx filename="app/layout.tsx" nocheck import "./globals.css"; // starts with @layer base, jali; import "jali-layout/styles.css"; ``` - **One instance per render tree.** `useState(() => createJali(...))` makes one per request on the server and one per page in the browser. A module-level instance in a client file would be shared by every request the server handles. - **Leaving the route.** `` stops the instance's listeners when it unmounts. Don't call `jali.destroy()` in an effect's cleanup: in development, Strict Mode runs each cleanup once at mount, and a destroyed instance refuses every call after. ## Server rendering and hydration Jali renders on the server with `renderToString` or a streaming renderer, and hydrates without a mismatch. The repo's `pnpm pack-check` does exactly that with the packed package. Three things make the server's HTML and the browser's first render agree: 1. **The same inputs on both sides:** the same kinds, layout or presets, and features. 2. **The same address.** On the server, give `urlSync()` the request's search with `memoryLocation(search)`. In the browser, `urlSync()` reads the real address, which holds the same search. 3. **The same size for the first render.** The server has no window, so pass `size`. Pass the same `size` in the browser; `` measures the real size after hydration and fits again. On the server, storage is in memory, and the keys, Back and Forward, theme and saving don't start: `` starts them in the browser. A pane's own content renders on the server like any React component, so data it reads must be ready there too. Other frameworks follow the same rules: React Router's framework mode, Remix and Astro's React islands all render a client component that makes the instance. ## TypeScript: register your instance Declare your instance once, and the React hooks know its kinds and page: ```ts filename="src/jali.ts" import { createJali } from "jali-layout"; import { definePane } from "jali-layout/react"; const order = definePane("order", { params: { id: Number }, title: ({ id }) => `Order ${id}`, Component: () => null }); export const jali = createJali({ panes: [order], layout: order({ id: 1 }) }); declare module "jali-layout" { interface Register { jali: typeof jali; } } ``` Then `useJali().actions.openBeside` takes refs of your kinds only, and `jali.on("open", ({ ref }) => …)` narrows `ref.params` by `ref.kind`. ## Linked or in a monorepo If your app gets Jali through `link:`, `file:` or `workspace:`, or from a symlinked checkout, two things can go wrong: - **Two copies of React.** Jali finds its own copy of React beside its source, the app bundles two, and hooks fail with "Invalid hook call". With Vite, add `resolve: { dedupe: ["react", "react-dom"] }` to `vite.config.ts`. With webpack, alias `react` and `react-dom` to your app's copy. - **A stale build.** A linked Jali resolves to its built files in `dist/`, which don't rebuild when its source changes. Rebuild it with `pnpm build:packages` in the Jali repo. Or read its source: with Vite, add the `"source"` condition, `resolve: { conditions: ["source", ...defaultClientConditions] }`. For Vitest, also add `ssr: { resolve: { conditions: ["source", ...defaultServerConditions] } }`. Both defaults come from `vite`. ## Next - [Quickstart](https://jali.ramizrahman.com/get-started/quickstart): Build the smallest app, step by step. - [Features](https://jali.ramizrahman.com/guides/your-app#choose-features): Choose what Jali does beyond laying out panes. - [Troubleshooting](https://jali.ramizrahman.com/guides/troubleshooting): Fixes for the problems people meet first. --- # Quickstart Build the smallest Jali app, a note whose button opens the next note beside it. This page builds a small app, one file at a time: a note with a button that opens the next note beside it. The finished app is [`examples/minimal`](https://github.com/ramiz-rahman/jali/tree/master/examples/minimal) in the repo, which adds a launcher and makes the panes the page's `
`. You need Node and a React app. Start from a new one, or skip this step and use your own: ```sh npm create vite@latest notes -- --template react-ts cd notes ``` *Live demo on the site: What you are building, running. Click a note's button to open the next note beside it, then drag the line between them.* ### Install Jali ```sh npm install jali-layout ``` One package: `jali-layout` holds the model (the layout, the panes and their commands) and has no framework; `jali-layout/react` renders it. If your app links Jali from a checkout or a monorepo, see [Installation](https://jali.ramizrahman.com/get-started/installation#linked-or-in-a-monorepo). ### Define a pane A [pane kind](https://jali.ramizrahman.com/get-started/key-concepts#kind) says what one kind of pane shows and how. This one shows a note. `note.tsx` ```tsx import { definePane } from "jali-layout/react"; // A kind of pane: what it shows (its params), its title, and the component that renders it. export const note = definePane("note", { params: { id: Number }, title: ({ id }) => `Note ${id}`, Component: ({ params }) => (

Note {params.id}

), }); ``` - `"note"` is the kind's name. Every pane of this kind carries it. - `params` says what a note pane needs to know: its `id`, a number. A link turns every value into text, so `Number` reads it back as a number. - `title` names the pane in its header, its tab and ⌘K. - `Component` renders the pane. It gets the params, typed, along with the functions a pane uses to open other panes. `note` is now also how you name a note: `note({ id: 1 })` is the [ref](https://jali.ramizrahman.com/get-started/key-concepts#ref) of note 1, `{ kind: "note", params: { id: 1 } }`. You use refs to open panes and to write layouts. ### Create the instance `createJali` makes the [instance](https://jali.ramizrahman.com/get-started/key-concepts#instance): it holds the panes, focus, history and settings. It takes the kinds it can show and the [layout](https://jali.ramizrahman.com/get-started/key-concepts#layout-tree) it opens on. `jali.ts` ```tsx import { createJali } from "jali-layout"; import { defaultFeatures } from "jali-layout/features"; import { note } from "./note"; export const jali = createJali({ panes: [note], layout: note({ id: 1 }), features: defaultFeatures(), }); ``` The layout here is one pane, note 1. Several are written the same way: `row(note({ id: 1 }), note({ id: 2 }))` puts panes side by side, and `column(...)` one above the other. See [Lay out panes](https://jali.ramizrahman.com/guides/layouts). `features` turns on what Jali does beyond laying out panes. `defaultFeatures()` is Jali's usual set: the layout in the address bar, the ⌘K palette, Settings and the chooser. Reload the page and the layout comes back; Back and Forward step through changes. If the address already holds a layout, that one opens instead. An app that wants less picks each feature from its own entry, and ships only those: see [Features](https://jali.ramizrahman.com/reference/features). ### Render it `` draws the panes and the features' dialogs, such as the ⌘K palette. While it is on the page, it also turns on the keyboard, Back and Forward, the theme and saving. `main.tsx` ```tsx import { createRoot } from "react-dom/client"; import { JaliRoot } from "jali-layout/react"; import "jali-layout/styles.css"; import "./app.css"; import { jali } from "./jali"; createRoot(document.getElementById("root")!).render(); ``` The panes fill the box you give them, so that box needs a height: here `html`, `body` and `#root` are the full window. To add your own top bar or sidebar, put it inside `` with `` where the panes go: the panes take the room it leaves. If the box has no height, the panes have none either, and a warning in the console says so while you develop. Screen readers meet the panes as a region named "Panes", inside your page's own `
`. When Jali is the whole page and it has no `
` of its own, pass `landmark: "main"` to `createJali` so the panes are the page's `
`. ### Add the styles and the layer line `jali/styles.css` is Jali's default theme and the panes' layout. Every rule in it sits in a CSS cascade layer named `jali`. `app.css` ```css /* Name the layers once. Jali's styles sit in `jali`; anything in a later layer wins without !important. */ @layer base, jali; @layer base { html, body, #root { height: 100%; margin: 0; } body { font-family: system-ui, sans-serif; background: var(--jali-canvas); color: var(--jali-text); } } /* Jali fills whatever box you give it. */ .app { height: 100%; display: grid; } .note { padding: 1rem; } ``` The `@layer` line names the order of the layers once. Your resets go in a layer before `jali`; your own styles go after it, or outside any layer, and win without `!important`. With Tailwind, the line is `@layer theme, base, jali, components, utilities;`. Run the app. You see note 1, filling the window. Press ⌘K (Ctrl+K on Windows and Linux) to see every command. ### Open a pane beside A pane opens another with `openBeside`. Pass it the ref of what to open. `note.tsx` ```tsx import { definePane } from "jali-layout/react"; export const note = definePane("note", { params: { id: Number }, title: ({ id }) => `Note ${id}`, Component: ({ params, openBeside }) => (

Note {params.id}

), }); ``` Click the button in note 1. Note 2 opens to its right, and focus stays in note 1, so you can keep working where you were. Drag the line between them to resize. Click note 1's button again. Note 2 is already beside it, so Jali opens no copy: it lights note 2 up for a moment and says "Already open". A link never opens a second copy of a pane it opened. Keep clicking the button in the newest note. Each click opens the next note beside the one you clicked in. When the panes no longer fit at their minimum width, some fold into tabs, and the note you are working in stays on screen. Widen the window and they come back. [How a layout fits](https://jali.ramizrahman.com/learn/fitting) explains the order, and [Opening and linking](https://jali.ramizrahman.com/learn/opening-and-linking) explains what `openBeside` does when a pane opens several links. ## Next - [Key concepts](https://jali.ramizrahman.com/get-started/key-concepts): Every Jali word in one place, with a picture or an example. - [The layout tree](https://jali.ramizrahman.com/learn/layout-tree): Rows, columns, stacks and sizes, live. - [How a layout fits](https://jali.ramizrahman.com/learn/fitting): What folds when the window is too small, and what comes back first. --- # Key concepts Every word Jali uses, defined in a sentence or two, most with an example or a picture. Jali lays out an app's panes: lists, records and editors side by side, which the person can open, move, resize and close. This page names the parts. Each term has its own link, and other pages link here the first time they use a word. The examples use a support desk: a list of tickets, a ticket, the customer who sent it, and their orders. ## Panes and what they show

Pane

A pane is one box in the layout that shows one object, such as a ticket or a customer. It has a header with its title, and it can be focused, moved, resized, put in tabs and closed. What is inside is your component.

Kind

A kind is one sort of pane: its name, what it shows, its title, the smallest size it works at, and the component that draws it. You define one with `definePane`. `ticket.tsx` ```tsx import { definePane } from "jali-layout/react"; import { customer } from "./customer"; import { ticketById } from "./data"; export const ticket = definePane("ticket", { params: { id: Number }, title: ({ id }) => `Ticket ${id}`, width: { min: 320, // narrower than this, the pane folds into a tab comfortable: 420, // spare room brings it here first max: 640, // past this, spare room goes to its neighbours first }, height: { min: 200 }, Component: ({ params, openBeside }) => { const t = ticketById(params.id); if (!t) return

Ticket {params.id} was not found.

; return (

{t.subject}

Status: {t.status}

); }, }); ``` A kind is data plus a component. Each instance has its own list of kinds (`createJali({ panes })`), so two instances on one page never share them.

Ref

A ref is what a pane shows: a kind and a few params, small enough to put in a link. The kind makes its refs: ```ts ticket({ id: 101 }); // { kind: "ticket", params: { id: 101 } } ``` Params are text, numbers and `true`/`false` only. Two refs show the same object when their kind and params match, with ids compared as text, so `101` and `"101"` are the same ticket. A kind can change that rule with `identity`, or say that two kinds show the same objects with `shows`. ## The layout

Layout tree

A layout is a tree. Its leaves are panes. Its other nodes are a **row** (children side by side), a **column** (children one above the other) or a **stack** (panes as tabs, one shown at a time). `layouts.ts` ```tsx import { column, pane, row, tabs } from "jali-layout"; import { customer, customerOrders } from "./customer"; import { ticket } from "./ticket"; import { ticketList } from "./ticket-list"; // A fixed-width list, and a column beside it: the ticket above, two tabs below. export const triage = row( pane(ticketList({ queue: "open" }), { id: "list", px: 360 }), column( pane(ticket({ id: 101 }), { id: "detail", weight: 2, linkedTo: "list", follows: true }), tabs(customer({ id: 7 }), customerOrders({ customer: 7 })), ), ); // One pane: the list alone. export const listOnly = pane(ticketList({ queue: "open" }), { id: "list" }); ``` Every node has a size along its parent: `weight: 2` takes a share of the room in proportion to its siblings, and `px: 360` asks for a fixed length. `row`, `column` and `tabs` build a plain JSON tree, and that tree is what goes in the address. *Live demo on the site: A row with a column inside it. Hover a node to light its pane.*

Overlay

The overlay is a set of notes, kept beside the tree, about panes that are not shown in their own place. A pane can be **folded** (no room), **tucked** (the person put it away) or **hidden** (a curated page's view that is not on screen). The tree itself never changes when a pane folds, tucks or hides. That is why a pane can always go back exactly where it was.

Fitting and folding

Each kind says the narrowest it works at (`width.min`). When the window is too narrow for every pane at its minimum, Jali folds panes into tabs of their neighbours, one at a time, instead of squeezing them. When room returns, they unfold. *Live demo on the site: Narrow the frame: panes fold into tabs one at a time, and come back as it widens.* Folded panes wait behind one **N folded** chip at the end of the tab strip, never mixed with the tabs the person made. They need nothing from the person. [How a layout fits](https://jali.ramizrahman.com/learn/fitting) explains what folds first.

Pane cap

The pane cap is the most panes shown at once, 8 by default. Past it, the oldest pane that is not kept or focused becomes a tab, even when there is room.

One pane at a time

On a phone, or whenever even one pane can't fit at its minimum, Jali shows one pane at a time with a switcher at the top. The layout itself is kept, and widening restores it. (This is not the curated page's [Single view](#single-and-split), which is a choice the person makes.)

Tuck and the shelf

Tucking puts a pane away by hand: it becomes a tab of a neighbour (its home), and the home takes its space. Nothing else on screen moves. A tucked tab has a **Put back** button that restores its slot. The shelf, ``, lists tucked panes by home; you place it in your own chrome, such as a status line. It holds only what the person put away, never what the layout folded. ## Working in panes

Focus

One pane at a time has focus, marked by an accent edge. Keys and commands act on it. F6 and Shift+F6 move focus between panes. Opening a pane beside keeps focus where it was, so the person keeps working in the list they opened from.

Peek

A peek is a sheet over the right of the panes that shows an object without adding a pane. It is not part of the layout. In a list, Space usually opens it. From the sheet, **Open beside** opens the object as a pane. Esc closes it.

Selection and the following detail

A list reports its selected item with `select(ref)`. A detail opened from that item follows the list: move the selection and the detail shows the new item, in place. The detail waits until the selection rests for 150ms, so holding J doesn't load every row on the way. [Following a list](https://jali.ramizrahman.com/learn/following) has the rules.

Linked and kept

A pane opened from another is linked to it (`linkedTo`). A plain link, such as a customer name in a ticket, replaces the earlier link of the same kind from the same pane instead of adding another pane. A kept pane stays on its object: it never follows and is never reused for another link, and it folds after panes that are not kept. A linked pane's header says **Following**; clicking it keeps the pane, and it says **Kept**. Other tools call this pinning a follower; in Jali, "pin" is for tabs. ## Curated pages

Curated page

A curated page is a designed layout about one item, such as a customer: a list of items at the left, a header, and tabs of views. You describe it with `definePage` (from `jali-layout/page`): its views, what each shows for an item, and its designed layout. Without a curated page, the person builds the layout. With one, the page's design leads and the person adjusts it. [Curated pages](https://jali.ramizrahman.com/learn/curated-pages) builds one.

View

A view is one tab of a curated page, such as Orders. In code, a view is a **role** (`roles` in `definePage`). A view is **primary** or **supporting**; supporting views give way first when room runs out.

Single view and Split view

**Single view** shows one view at a time, chosen from the tabs, and links open as a peek. **Split view** lets the person lay views out side by side, starting from the page's design. The person chooses; the mode and their layout stay on their device.

Opened panes

In Split view, following a link opens a pane after the page's views, marked **Opened**. **Back to** the page closes the opened panes and returns the layout to how it was before the first link. ## The instance and its ports

Instance and actions

The instance holds the layout, focus, selection, settings and history. You make it with `createJali`, and every change is an action on it: `jali.actions` for panes and layouts, `jali.page` for a curated page, and `jali.dialogs` for the palette, Settings and the chooser. `actions.ts` ```tsx import { ticket } from "./ticket"; import { jali } from "./store"; // Every change is an action. The pane id comes from the layout. jali.actions.openBeside("list", ticket({ id: 103 })); jali.actions.focus("detail"); jali.actions.preset("list"); // Read state, or subscribe to it. const unsubscribe = jali.subscribe(() => console.log(jali.get().view.focused)); unsubscribe(); ``` Every action is a pure function from one state to the next. Jali commits the result, writes the address and announces the change to screen readers. An action that can't happen returns why, such as `{ ok: false, reason: "unsaved" }`, instead of throwing.

Presets

A preset is a layout the person can switch to, by id and label. The first opens by default, ⌘K lists them as "Layout: …", and Reset layout rebuilds the last one chosen. ```ts import { createJali, row } from "jali-layout"; const triage = row(ticket({ id: 101 }), customer({ id: 7 })); const jali = createJali({ panes, presets: [{ id: "triage", label: "Triage", layout: triage }] }); ```

Ports: the address and storage

A port is a small interface for something outside Jali, so your app or a test can own it. - The **location** port is the address. Jali reads and writes only its own search params and keeps every other param as it is. The default is the browser's history; an app with a router passes a small adapter. - The **storage** port is what one person keeps on one device: settings, pane state, a curated page's mode. The default is `localStorage` under a prefix. `jali.ts` ```tsx import { createJali } from "jali-layout"; import { customer, customerOrders, order } from "./customer"; import { listOnly, triage } from "./layouts"; import { ticket } from "./ticket"; import { ticketList } from "./ticket-list"; export const jali = createJali({ // The kinds of pane it can show. Each instance has its own. panes: [ticketList, ticket, customer, customerOrders, order], // Layouts to start from, in ⌘K as "Layout: Triage". The first opens when no link says otherwise. presets: [ { id: "triage", label: "Triage", layout: triage }, { id: "list", label: "One list", layout: listOnly }, ], // What this person keeps on this device (settings, pane state, sizes): localStorage under this prefix. storage: "support-desk", // Rebind or unbind commands. Ids not listed keep their default keys. keyboard: { keymap: { "pane.close": "Mod+K Mod+X", "pane.zoom": null } }, }); ``` `urlSync({ location: memoryLocation() })` and `storage: memoryStorage()` keep both in memory, for tests and for panes that must not touch the page's address. The location port is only read with the `urlSync()` [feature](https://jali.ramizrahman.com/guides/your-app#choose-features). `urlSync({ sizes })` chooses what a link says about sizes. `"local"`, the default, writes the layout as designed and keeps the sizes the person dragged on their device. `"link"` writes every size, so a link reopens exactly as the sender saw it. ## The pane contract

Unsaved work

A pane reports work the person would lose with `useUnsaved("an unsaved reply")`, and clears it with `null`. While it is set, closing the pane, a preset, Back, or showing another object in it asks "Discard unsaved changes?" first. Moving, tabbing, folding and tucking never ask: the pane's content stays mounted, so the work stays too.

Pane state

`usePaneState(key, initial)` is like `useState`, but Jali keeps the value through folds, tabs, tucks and reloads. It goes when the pane closes for good or shows another object. Values must be JSON. ```tsx import { usePaneState } from "jali-layout/react"; function OrderList() { const [sort, setSort] = usePaneState("sort", { column: "id", dir: "asc" }); return ; } ```

Paused

A pane gets `paused: true` while it is out of sight: behind a tab, tucked, folded or behind a maximised pane. It should pause live work, such as polling, and keep its state.

Commands and the keymap

A command is something Jali can do, with an id such as `pane.close`. The keymap binds keys to commands. ⌘K (Ctrl+K) starts a two-key chord, such as ⌘K ⌘Z to restore a closed pane, and opens the command palette when the `palette()` feature is on. Each instance has its own keymap. Rebind or unbind a command with `createJali({ keyboard: { keymap: { "pane.zoom": null } } })`. Your app adds its own commands with `createJali({ commands })`, and a pane adds its own to ⌘K with `useCommands`.

Content first

Keys go to the pane's content first. Content claims a key with `event.preventDefault()`, and Jali leaves it alone; every key the content does not claim bubbles to Jali. Single letter keys, Enter, Space and the first Esc belong to the content. --- # Using Jali with coding agents The rules a coding agent, or a person, should follow when adding Jali to an app. Jali does a lot for a pane: it places it, folds it, keeps its state and asks before it loses work. It can only do that if the pane's content follows a few rules. This page lists them, with the reason for each. Give it to your agent along with the task. > **Tip: The docs come with the package.** Every page of these docs is in `jali-layout` as Markdown, for the version you installed: `node_modules/jali-layout/docs/README.md` lists them, and this page is `docs/get-started/coding-agents.md`. An agent that reads them there works from docs that match its code. Each page here is also Markdown from the buttons under its title. To give an agent the workflow as well, add Jali's skill, `skills/jali` in Jali's repository. It tells the agent to read these rules and the installed docs first, and to check its work against them. ## The rules ### 1. A kind is data plus a component Define each kind of pane with `definePane("kind", { params, title, width, height, Component })` in its own module, and pass the app's kinds to `createJali({ panes })`. Nothing about a kind is global, so two instances on one page never share kinds. Name objects with the kind itself, `ticket({ id: 101 })`, never with a hand-written `{ kind, params }`. Set `width.min` to the narrowest width the content still works at once it adapts, not the width it looks best at. Jali folds a pane into a tab rather than squeeze it below its minimum, so a minimum that is too large folds panes early. Use `width.comfortable` and `width.max` for the rest ([How a layout fits](https://jali.ramizrahman.com/learn/fitting)). ### 2. Declare params, and read them typed What a pane shows arrives as `params`, read with the kind's `params` types: `params: { id: Number }` gives `params.id` as a number, so never cast it. Declare every param: one a pane may leave out is `optional(String)`, a flag is `Boolean`, a fixed choice is `oneOf("open", "closed")`. A component written apart from its kind takes `PaneProps`, with the params declared first, never the type written out again. Keep params small: ids, never the data itself, because they go in the address. ### 3. Claim your keys, let the rest bubble Keys reach the pane's content first. Handle the keys your content uses and call `event.preventDefault()` on each one. Jali leaves a claimed key alone. Let every other key bubble, so ⌘K, F6 and Jali's commands keep working inside your pane. - Never stop propagation of every key in a container. It cuts off ⌘K and F6. - Letter keys (J, K) must only act while your content has focus. - Content that needs every key, such as a code editor, marks its element `data-pane-keys="content"`. Jali then takes only F6 and Shift+F6 there, so focus can always leave. `ticket-list.tsx` ```tsx import { useState, type KeyboardEvent } from "react"; import { definePane, type PaneProps } from "jali-layout/react"; import { tickets } from "./data"; import { ticket } from "./ticket"; function TicketList({ node, select, peek, openBeside }: PaneProps) { const [index, setIndex] = useState(null); const current = index === null ? undefined : tickets[index]; const optionId = (id: number) => `${node.id}-ticket-${id}`; // unique per pane // Move the cursor and tell Jali what is selected. A following detail shows it once it rests. const selectAt = (i: number) => { const next = Math.max(0, Math.min(tickets.length - 1, i)); setIndex(next); select(ticket({ id: tickets[next]!.id })); }; // Select first, then open: the detail that opens is linked to the selection, so it follows the list. const openAt = (i: number) => { if (i !== index) selectAt(i); openBeside(ticket({ id: tickets[i]!.id })); }; const onKeyDown = (e: KeyboardEvent) => { if (e.metaKey || e.ctrlKey) return; // ⌘K and Jali's keys bubble on if ((e.key === "j" || e.key === "ArrowDown") && !e.altKey) selectAt((index ?? -1) + 1); else if ((e.key === "k" || e.key === "ArrowUp") && !e.altKey) selectAt((index ?? 1) - 1); else if (e.key === " " && current) peek(ticket({ id: current.id })); else if (e.key === "Enter" && e.altKey && index !== null) openAt(index); else return; // not ours: let it bubble e.preventDefault(); // claimed: Jali leaves this key alone }; return ( // One tab stop; the cursor is the active option, which screen readers follow (aria-activedescendant).
    {tickets.map((t, i) => (
  • selectAt(i)} onDoubleClick={() => openAt(i)} > #{t.id} {t.subject}
  • ))}
); } export const ticketList = definePane("tickets", { title: "Tickets", width: { min: 320 }, height: { min: 200 }, Component: TicketList, }); ``` ### 4. Select before you open A list reports its selected item with `select(ref)` as the cursor moves (J/K, arrows, a click). To open a row, select it first, then call `openBeside(ref)`. Jali then knows the pane came from the selection, so it becomes a [following detail](https://jali.ramizrahman.com/get-started/key-concepts#selection) that follows the list. If the list's filter no longer shows the selected item, say so with `select(ref, { inResults: false })`. A following detail keeps the item, with a note. The usual row keys are J/K or the arrows to select, Space to `peek(ref)`, and ⌥↵ (Alt+Enter) to `openBeside(ref)`. ### 5. Report unsaved work If closing the pane would lose something the person typed, report it with `useUnsaved(dirty && "a short description")`; it clears when the work is saved or the pane goes. While it is set, closing the pane, closing others, a preset, Back and Forward, or showing another object in the pane asks the person first. Leaving the page triggers the browser's own prompt. Don't build your own "are you sure" for these. Moving, tabbing, folding and tucking never ask, because the content stays mounted. ### 6. Use `usePaneState` for what the person expects back A draft, a sort, a scroll position: keep these with `usePaneState(key, initial)` instead of `useState`. Jali keeps the value through folds, tabs, tucks and reloads, and drops it when the pane closes for good or shows another object. Values must be JSON. Use React state for everything else. `note-editor.tsx` ```tsx import { useState } from "react"; import { keyHint } from "jali-layout"; import { definePane, useCommands, usePaneState, useUnsaved, type PaneProps, } from "jali-layout/react"; import { noteBody, saveNote } from "./data"; const noteParams = { id: Number }; function NoteEditor({ params }: PaneProps) { const [saved, setSaved] = useState(() => noteBody(params.id)); // The draft is pane state: it survives a fold, a tab switch, a tuck and a reload, and goes when the pane closes. const [draft, setDraft] = usePaneState("draft", saved); const save = () => { saveNote(params.id, draft); setSaved(draft); }; const dirty = draft !== saved; // Work the person would lose: closing the pane, or showing another note in it, asks first. useUnsaved(dirty && "an unsaved edit to this note"); // What this pane adds to ⌘K while it is focused. `keys` is a label: the content handles the key itself. useCommands([ { id: "save", title: "Save note", keys: keyHint("Mod+Enter"), disabled: dirty ? false : "Nothing to save", run: save, }, ]); return (