Get started
Key concepts
Every word Jali uses, defined in a sentence or two, most with an example or a picture.
On this page
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
Link to this section: Panes and what they showPane
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.
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 <p>Ticket {params.id} was not found.</p>; return ( <article> <h3>{t.subject}</h3> <p>Status: {t.status}</p> <button onClick={() => openBeside(customer({ id: t.customer }))}> Customer {t.customer} </button> </article> ); },});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:
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
Link to this section: The layoutLayout 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).
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.
- Click an order, and the detail follows
- Drag a pane onto another
- Right-click an order for more
- Point at a box to find its pane
- Drag a divider
- Close a 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.
Drag the frame's edge, or watch it fold.
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 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, 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, <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
Link to this section: Working in panesFocus
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 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
Link to this section: Curated pagesCurated 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 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
Link to this section: The instance and its portsInstance 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.
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.
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
localStorageunder a prefix.
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.
Sizes in links
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
Link to this section: The pane contractUnsaved 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.
import { usePaneState } from "jali-layout/react";function OrderList() { const [sort, setSort] = usePaneState("sort", { column: "id", dir: "asc" }); return <button onClick={() => setSort({ ...sort, dir: "desc" })}>Sort by {sort.column}</button>;}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.