Reference
jali-layout
Every function and constant jali-layout exports, with its options, defaults and what it returns.
On this page
The framework-free part of Jali: the instance, the layouts it shows, the address and storage ports, commands and keys. Render it with jali-layout/react. Types have their own page, jali-layout types.
npm install jali-layoutpnpm add jali-layoutyarn add jali-layoutbun add jali-layoutvp add jali-layoutFramework adapters import jali-layout/adapter: everything on this page, and, by name, what an adapter needs from inside the package, such as the DomPort through which the core finds the adapter's elements, the instance's store (storeOf), and the pure layout operations (layout). Apps need only what is on this page.
The instance
Link to this section: The instancecreateJali
Makes one instance, ready to render: its state, the model derived from it, its actions and its keymap. Each instance has its own; nothing is shared between two on one page.
createJali(options: JaliOptions): Jali<RefOf<kinds>, PageOf<page>>import { createJali, memoryLocation, memoryStorage } from "jali-layout";import { launcherKind, orderKind, ordersKind } from "./kinds";import { palette } from "jali-layout/palette";import { urlSync } from "jali-layout/url";export const jali = createJali({ panes: [ordersKind, orderKind], // the kinds of pane it can show layout: ordersKind(), // the layout it opens on (or `presets`) launcher: launcherKind, // what Split opens: without one there is no Split name: "Sales desk", // in commands such as "Open Sales desk" features: [urlSync({ prefix: "a.", sizes: "link" }), palette()], // each a value from its own module storage: "sales", // localStorage keys "sales:…", or a StoragePort id: "sales", // DOM ids "sales-pane-…" keyboard: { scope: "local", keymap: { "pane.close": "Mod+K Mod+X" } }, // only keys pressed inside it pageTheme: false, // leave data-theme on <html> to the page});// With no browser (a test, the server): the address and storage in memory, a fixed size, DOM focus left alone.const location = memoryLocation();export const inMemory = createJali({ panes: [orderKind], layout: orderKind({ id: 1041 }), features: [urlSync({ location })], storage: memoryStorage(), size: { width: 1440, height: 900 }, moveFocus: false,});location.entries; // every address Jali pushed or replacedlocation.visit("?tab=2"); // navigation from outside: Jali hears it, as it hears Back and ForwardBefore it returns, it reads the address (a layout link opens as it is, a curated page link opens the page, a link that can't be read opens the starting layout with an error toast), adds what is on screen to Recent, fits the layout to the room and focuses the first pane. A page-only app (a page with no layout and no presets) starts with its page open on firstItem, and leaving it is refused. It throws Jali: no layout to start from can be shown when it has none of them, or when none of them can be shown (a kind it doesn't have, a param it can't read), with the first reason after a colon.
Its type comes from what it is given: jali.actions takes refs of these kinds only, events and the model say which kind (ref.kind narrows ref.params), and jali.page is there only with a page. Declare it once as Register and the React hooks are typed by it too.
Its listeners (keys, Back and Forward, theme and saving) start with jali.start(), which returns their stop and can start again; <JaliRoot> starts it while mounted and stops it on unmount. jali.destroy() is the end.
Parameters
optionsJaliOptionsRequiredShow child parameters
panesreadonly PaneKindBase[]RequireddefinePane. A layout can only show refs of these kinds.layoutLayoutInputOptionalrow(...)), a single ref, or a whole Layout. Give this or presets.presetsreadonly PresetOptions[]OptionalDefault []
{ id, label, layout }. Each gets a layout.preset.<id> command, titled "Layout: label", and "Reset layout" rebuilds the one in use. layout may be a function, to build a fresh one each time. saved gives back the layout the person left a preset in.presetstringOptionalDefault the first preset
presets also gives the first.launcherPaneKindBaseOptionaluseLauncher(). Without one, those commands and the tab strip's "+" are not offered.pagePage | nullOptionalDefault null
definePage (jali-layout/page). A page made any other way is refused: definePage gives it the code that runs it, which an app without a page never ships. With one, jali.page has its actions.namestringOptionalfeaturesreadonly Feature[]OptionalDefault none
[urlSync(), palette(), rename({ run })], or defaultFeatures() for the address, ⌘K, Settings, the chooser and data-pressed at once. A feature given again takes the earlier one's place. See Features.urlUrlWriterOptionalurlSync(): Jali writes through it and reads nothing back. Most apps give urlSync({ location }) instead. See UrlWriter.storagestring | StoragePortOptionalDefault its id in a browser, memory elsewhere
localStorage prefix; or pass a port, such as memoryStorage(). The default prefix is the instance's id ("jali"), so two instances with their own ids keep their own.idstringOptionalDefault "jali"
jali-pane-orders). Give each instance on one page its own.pageThemebooleanOptionalDefault true
data-theme on <html> from the person's theme setting, and on the instance's root and dialog layer too, for rules scoped to the instance. false when the instance sits in a page that has its own theme: then it writes none of them.settingsPartial<Settings>OptionalDefault Jali's (theme system, pane cap 8)
{ theme: "dark" } for a dark-first app. They are not saved; what the person changes is, and wins from then on, setting by setting. See Settings.commandsreadonly Command[]Optionalkeys and a disabled check if it needs one (Command). keyboard.keymap can rebind or unbind their keys like any other ({ "orders.refresh": "Mod+K Mod+U" }). If an id repeats one of Jali's, Jali's wins.keyboardKeyboardOptionsOptionalJali's keys, in one place. See KeyboardOptions.
Show child parameters
keyboard.scope"page" | "local"OptionalDefault "page"
"page": every key on the page. "local": only keys pressed inside it or in its dialogs (the palette, settings and the chooser render outside its root, so a ⌘K chord finishes there), and keys with nothing focused while it was the last one used. Use "local" for two on one page.keyboard.keymapKeymapOverridesOptional{ "pane.zoom": "Mod+K Mod+Enter", "pane.close": null }. A binding is refused (and reported) when it can't be parsed, is a single character key with no Mod, Ctrl or Alt (those belong to the content), or has more than two steps.keyboard.prefixKeyStringOptionalDefault "Mod+K"
"Mod+J" makes "Restore last closed pane" ⌘J ⌘Z. Bindings in keymap are used as written.keyboard.reservedreadonly KeyString[]OptionalonInvalid when the instance is made.keyboard.platform"mac" | "other"Optionalkeyboard.onInvalid(id, binding, reason) => voidOptionalDefault console.warn
keyboard.wordsKeyWordsOptionalDefault messages.keys
messages.keys, English unless you translate them.landmark"region" | "main"OptionalDefault "region"
"region": a <section> labelled "Panes", which sits inside your page's own <main> and adds no second one. "main": the panes render as the page's <main>. Use it when Jali is the whole app and the page has no <main> of its own.labelstringOptionaldirDirectionOptionalDefault the page's
direction where it renders, so <html dir="rtl"> is enough, and it follows a later change of dir. Give one to fix it; <JaliRoot> then sets dir on its elements, so the styles agree. Right to left, a row starts at the right, and every left and right a key, command, drop zone or message names is still the screen's. The layout and its links are the same in both. See Direction.gapnumberOptionalDefault 6
<JaliRoot> writes it on its root and its layer as --jali-gap, so a style that reads the variable agrees with where the panes are.size{ width: number; height: number }Optional<JaliRoot> measures the real one once it renders.moveFocusbooleanOptionalDefault true
false leaves DOM focus alone: for tests and an instance that is never shown.beforeCloseBeforeCloseOptionalsetLayout, Back and Forward, openHere. Return true to let it happen or false to keep the panes, or a promise of either for a check that takes time. Jali's own "Discard unsaved changes?" follows a yes when a pane still reports unsaved work, including work reported while the guard decided. Nothing of the change is written while the guard decides: an action your guard runs meanwhile happens at once, with its real result, and the change is then worked out again against the state it leaves. See BeforeClose.confirmDiscardbooleanOptionalDefault true
false: your app asks about unsaved work itself, from beforeClose. Panes still report it with useUnsaved and show the unsaved mark, but Jali never asks "Discard unsaved changes?" and doesn't hold the page's unload. A following detail with unsaved work still keeps its object.tabMenuTabMenuOptionalundefined or [] for none. See TabMenuItem.allowAllowOptional{ fullScreen: false }), turn Pop out off ({ popOut: false }, with the popOut() feature), and when({ action, pane, presetId, page }) to decide by context; false refuses. Each kind's own allow is asked first, and only takes away. See Choose what people can do with panes and Allow.buttonsPaneButtonsOptionalallow.popOut turns it on) and Close, with Full screen in Maximise's place on a lone pane. A list replaces them; a function adjusts them ((defaults) => defaults.filter((b) => b !== "tuck")). A kind's own buttons win. See PaneButtons.phonePhoneOptionsOptionalphone.below pixels of width (default 600) Jali shows one pane at a time, with a switcher, whatever the panes' minimums. { below: 0 } switches only when even one pane can't fit. See PhoneOptions.onPaneError(error: unknown, info: PaneErrorInfo) => voidOptionalDefault console.error in development
info says which pane (PaneErrorInfo). Send it to your error reporting.messagesMessageOverridesOptionalDefault English (en)
{ commands: { close: "Fermer le volet" } }. Keys you leave out stay English. See en and Translate Jali.Returns
Jali
Jali: actions, page (with a page), dialogs, get(), subscribe(), on(), model(), getLayout(), setLayout(), keymap, env, messages, href(), start() and destroy().actions
What an app asks the instance to do with panes and layouts; a curated page's actions are jali.page (JaliPage) and the dialogs' jali.dialogs (JaliDialogs). Each action reads the current state, makes its change once (layout, focus, address, announcement, toast) and returns what happened: { ok: true, pane }, or { ok: false, reason } with the reason it did not.
jali.actions.openBeside(pane: PaneTarget, ref: ObjectRef, options?: OpenBesideOptions): ActionResultimport { orderKind } from "./kinds";import { store } from "./store";// Read, subscribe, act. An action says what it did: the pane it opened, or why it did not.const off = store.subscribe(() => console.log(store.get().view.focused));const opened = store.actions.openBeside("orders", orderKind({ id: 1042 }));if (!opened.ok) console.log(opened.reason); // "not-found", "unsaved", …store.actions.select("orders", orderKind({ id: 1043 }));store.actions.close(orderKind({ id: 1042 })); // a pane by what it showsstore.on("open", ({ pane, ref }) => console.log("opened", pane, ref.params));store.model().panes.filter((p) => p.where === "shown"); // panes on screen, in tree orderstore.on("toast", (t) => console.log(t.title, t.undo ? "(Undo)" : ""));off();The pane comes first, by its id or by the object it shows: close("order") and close(orderKind({ id: 7 })) both work. An action that would remove or replace a pane with unsaved work is held instead (reason: "unsaved"), and "Discard unsaved changes?" opens. A following detail with unsaved work keeps its object and says so, while the list's other followers move on. Every action is listed under JaliActions.
Pane params
Link to this section: Pane paramsWhat a kind's refs hold, in its params: Number, String, Boolean, oneOf(...) or your own function, each required unless wrapped in optional or appOnly. The Pane kinds guide explains what happens to a ref that is missing a required param.
optional
A param a ref may leave out. The kind's code sees it as optional (tab?: string), and its ref maker takes it or not. An optional param given as undefined is left out of the ref, as a link would leave it.
optional<T extends ParamType>(type: T, options?: ParamOptions): OptionalParam<T>import { definePane, type PaneProps } from "jali-layout/react";import { oneOf, optional } from "jali-layout";// Declared first, so a component written apart from the kind is typed from it.const ticketParams = { id: Number, status: optional(oneOf("open", "pending", "closed")), internal: optional(Boolean),};// params is { id: number; status?: "open" | "pending" | "closed"; internal?: boolean }function TicketView({ params }: PaneProps<typeof ticketParams>) { return ( <h3> Ticket {params.id} · {params.status ?? "any status"} {params.internal ? " · internal notes" : ""} </h3> );}export const ticket = definePane("ticket", { params: ticketParams, title: ({ id }) => `Ticket ${id}`, Component: TicketView,});ticket({ id: 7 }); // { kind: "ticket", params: { id: 7 } }ticket({ id: 7, status: "open", internal: true });Parameters
typeParamTypeRequiredNumber, String, Boolean, oneOf(...) or a function.options.linkfalseOptionalrunId: optional(String, { link: false }). Jali leaves it out of every link it writes (the address bar, Copy link, Back and Forward). Unlike appOnly, it is part of what the pane shows (chart({ runId: "a" }) and chart({ runId: "b" }) are two objects), and a link that does carry it still sets it. Back and Forward keep it on a pane that is still open; after a reload the pane has none, unless the preset the address names gave it one. Use it for a value that means nothing in another tab: a run id, a key into memory.Returns
OptionalParam<T>
appOnly
A param only your app sets, never a link: params: { sql: String, autorun: appOnly(Boolean) }. Use it for anything a link must not be able to turn on, such as a query that runs as it opens. Jali leaves it out of every address it writes (the address bar, Copy link, Back and Forward) and drops it from every link it reads, even when the link holds a value it can't read. What the app gave stays where the app gave it: Back and Forward keep it on a pane that is still open, and a reload keeps what the preset the address names gave a pane, when the pane is exactly the preset's (the same id, showing the same object). A link that changes the pane gets none. It is optional, since a pane opened from a link has none, and it is not part of what the pane shows: query({ sql, autorun: true }) and query({ sql }) are the same object.
appOnly<T extends ParamType>(type: T): AppOnlyParam<T>Parameters
typeParamTypeRequiredNumber, String, Boolean, oneOf(...) or a function.Returns
AppOnlyParam<T>
oneOf
A param that is one of a few values: oneOf("open", "closed") gives "open" | "closed". Values are compared as text, so oneOf(10, 25) reads "25" from a link as 25. Any other value can't be read, and the ref doesn't open.
oneOf<const V extends readonly (string | number)[]>(...values: V): OneOf<V[number]>Parameters
...values(string | number)[]RequiredReturns
OneOf<V[number]>
values.row
Children side by side. A child is a ref (a pane showing it), a pane(ref, options), or another row, column or tabs. Options come first when there are any: row({ weight: 2 }, a, b).
row(...children: LayoutInput[]): SplitDraft
row(options: RowOptions, ...children: LayoutInput[]): SplitDraftimport { column, pane, row, tabs } from "jali-layout";import { orderKind, ordersKind } from "./kinds";// A child is a ref, a pane(ref, options), or another row, column or tabs. Options come first when there are any.export const desk = row( pane(ordersKind(), { id: "orders", px: 320 }), // a fixed 320px column( { weight: 2 }, // twice the share of its siblings pane(orderKind({ id: 1041 }), { id: "order", linkedTo: "orders", follows: true }), tabs(orderKind({ id: 1042 }), orderKind({ id: 1043 })), // two tabs, the first shown ),);Nodes without an id are named after what they hold: "row", "column", "tabs", or the pane's kind, then "order-2" and so on. Give an id to a pane another one links to, or that your code names.
Parameters
optionsRowOptionsOptionalid; weight (its share of the parent, default 1) or px (a fixed length); scroll: "x" for a row that scrolls sideways, its children at their own widths, instead of sharing its width and folding what doesn't fit.children(Draft | ObjectRef)[]RequiredReturns
SplitDraft
createJali({ layout }) or a preset's layout.pane
A pane showing ref, with options. A bare ref in a row is the same as pane(ref).
pane(ref: ObjectRef, options?: PaneNodeOptions): PaneDraftParameters
refObjectRefRequiredorderKind({ id: 1 }).optionsPaneNodeOptionsOptionalShow options
idstringOptionalname-2, ….weightnumberOptionalDefault 1
pxnumberOptionallinkedTostringOptionalfollowsbooleanOptionallinkedTo: it shows whatever is selected in that pane, and moves with the selection.keptbooleanOptionalpinnedbooleanOptionalrolestringOptionalpriority"primary" | "supporting"OptionalhiddenbooleanOptionalReturns
PaneDraft
sameRef
Whether two refs are exactly the same: the same kind and the same params, compared with ===, in any key order (a layout read back from Postgres jsonb shows the same objects). Jali compares refs with this everywhere. 1 and "1" differ here; to ask whether two refs show the same object, use kinds.sameObject.
sameRef(a: ObjectRef | undefined, b: ObjectRef | undefined): booleanimport { sameRef } from "jali-layout";sameRef({ kind: "order", params: { id: 1041 } }, { kind: "order", params: { id: 1041 } }); // truesameRef({ kind: "order", params: { id: 1041 } }, { kind: "order", params: { id: "1041" } }); // false: 1041 !== "1041"sameRef(undefined, { kind: "order", params: {} }); // falseParameters
aObjectRef | undefinedRequiredbObjectRef | undefinedRequiredReturns
boolean
false when either is undefined.The address and storage
Link to this section: The address and storagecreateJali makes these for you from its url and storage options. Pass one yourself for a router, a test or an instance that must not touch the page.
memoryLocation
An address that lives in memory: for tests, server rendering, and an instance in a dialog that must not touch the page's address.
memoryLocation(initial?: string): LocationPort & { entries: string[]; visit(search: string): void }import { createJali, memoryLocation, memoryStorage } from "jali-layout";import { launcherKind, orderKind, ordersKind } from "./kinds";import { palette } from "jali-layout/palette";import { urlSync } from "jali-layout/url";export const jali = createJali({ panes: [ordersKind, orderKind], // the kinds of pane it can show layout: ordersKind(), // the layout it opens on (or `presets`) launcher: launcherKind, // what Split opens: without one there is no Split name: "Sales desk", // in commands such as "Open Sales desk" features: [urlSync({ prefix: "a.", sizes: "link" }), palette()], // each a value from its own module storage: "sales", // localStorage keys "sales:…", or a StoragePort id: "sales", // DOM ids "sales-pane-…" keyboard: { scope: "local", keymap: { "pane.close": "Mod+K Mod+X" } }, // only keys pressed inside it pageTheme: false, // leave data-theme on <html> to the page});// With no browser (a test, the server): the address and storage in memory, a fixed size, DOM focus left alone.const location = memoryLocation();export const inMemory = createJali({ panes: [orderKind], layout: orderKind({ id: 1041 }), features: [urlSync({ location })], storage: memoryStorage(), size: { width: 1440, height: 900 }, moveFocus: false,});location.entries; // every address Jali pushed or replacedlocation.visit("?tab=2"); // navigation from outside: Jali hears it, as it hears Back and ForwardParameters
initialstringOptionalDefault ""
Returns
LocationPort & { entries: string[]; visit(search: string): void }
entries is the history, newest last; href() is memory: plus the search. visit(search) is navigation the instance did not make (Back, a router link): it adds an entry and calls every subscriber. navigate does not call subscribers.memoryStorage
Storage in a Map, for tests, server rendering and embedded instances.
memoryStorage(initial?: Record<string, string>): StoragePortParameters
initialRecord<string, string>OptionalDefault {}
settings, pane-state, …).Returns
StoragePort
Commands and keys
Link to this section: Commands and keyslistCommands
Every command a person can run from a menu now, in the palette's order: the focused pane's own commands first (keys pane:<id>), then the instance's and your own commands. Each has its title, group, keys label for this platform, disabled and the reason, and run. For an app with its own command menu (no palette() feature).
listCommands(jali: Jali): readonly ListedCommand[]import { copyLink, listCommands, runCommand } from "jali-layout";import { store } from "./store";// A toolbar button that runs one of Jali's commands and shows its keys.const zoom = listCommands(store).find((c) => c.id === "pane.zoom")!;const disabled = zoom.disabled;const tooltip = `${zoom.title} · ${zoom.keys}`; // "Maximise or restore pane · ⇧⌘↵"function onClick() { if (!runCommand(store, "pane.zoom")) console.info("refused");}copyLink(store); // the address on the clipboard, and "Link copied" read outexport { disabled, tooltip, onClick };It is worked out on every call, and returns the same array (and the same entries, each with the same run) until something it lists changes. So in React it is a store snapshot as it is: useSyncExternalStore(jali.subscribe, read, read) with read = () => listCommands(jali) (the same read is the server's snapshot) re-renders only when the list changes. What it lists can change without a change of state, when an allow rule reads your own data: call it again then.
Returns
readonly ListedCommand[]
runCommand
Runs a command by id if its check passes. A refusal is not announced here (the keyboard and the palette do that).
runCommand(jali: Jali, id: string): booleanParameters
jaliJaliRequiredidstringRequired"pane.zoom".Returns
boolean
false for an unknown id, a refused check, an action that refused, or an instance after destroy(). A change held for an answer (the host's beforeClose, or "Discard unsaved changes?") ran.edgeScroll
Scrolls a row that scrolls sideways while a drag is held within 56px of its left or right edge, faster the closer it is, so a drag can reach a pane out of view. For an app's own drag; Jali's pane drag (by a header) already does this. Call move on every pointer move and stop when the drag ends. onScroll runs after each step, so the drag can find what is under the pointer again as the panes slide past.
edgeScroll(jali: Jali, onScroll?: () => void): EdgeScrollParameters
jaliJaliRequiredonScroll() => voidOptionalReturns
EdgeScroll
EdgeScroll
What edgeScroll returns: tell it where the pointer is, and when the drag ends.
interface EdgeScroll { move(clientX: number, clientY: number): void; stop(): void }copyLink
Writes jali.href() to the clipboard and announces "Link copied", or "Couldn't copy the link" when the browser refuses. Where navigator.clipboard is missing it does nothing. The layout.copy_link command runs it.
copyLink(jali: Jali): voidParameters
jaliJaliRequiredReturns
void
keyBelongsToContent
Whether a key event belongs to the focused content: its target is a text field, a contenteditable region, a combobox or search box, inside a dialog, or a control that Space presses (a button, link, tab, checkbox, switch, radio or menu item). Use it in a window-level keydown handler that wants a single key such as Space. See Space in lists.
keyBelongsToContent(event: KeyboardEvent): booleanaltClick
The words for Jali's modifier-click, for hints in your own text: "⌥-click" on a Mac and "Alt-click" elsewhere, as in `${altClick()} a tab to open it beside`.
altClick(platform?: Platform): stringParameters
platformPlatformOptionalDefault this platform
keyHint
A binding string printed for the platform: keyHint("Alt+Enter") is "⌥↵" on a Mac and "Alt+Enter" elsewhere. For keys a pane handles itself, which are not in the keymap. Throws on a key or modifier it doesn't know.
keyHint(text: string, platform?: Platform, words?: KeyWords): stringimport { keyHint } from "jali-layout";import { store } from "./store";keyHint("Alt+Enter", "mac"); // "⌥↵"keyHint("Alt+Enter", "other"); // "Alt+Enter"keyHint("Mod+Enter"); // for this platform: "⌘↵" on a Mac, "Ctrl+Enter" elsewherestore.keymap.sequences("pane.zoom").map((s) => store.keymap.format(s));Parameters
textstringRequired"Mod+K Mod+M".platformPlatformOptionalDefault this platform
wordsKeyWordsOptionalDefault English
en.keys, or your translation of them).Returns
string
en
Jali's English messages: every word it shows or says, by area (announcements, toasts, commands, commandGroups, keys, palette, chooser, confirmDiscard, settings, tabs, shelf, pane, peek, panes, page, drop). An instance made without messages says these words. A curated page's own words (the page area, and the announcements, commands and toast only a page uses) come with the page from definePage, so an instance without a page has none of them in jali.messages, and an app that doesn't import en doesn't ship them. Spread it to start a translation. A message that needs values is a function, such as en.announcements.closed(pane); a message with a bold part takes bold and returns its parts in order.
const en: Messagesimport { createJali, en, type MessageOverrides } from "jali-layout";import { orderKind } from "./kinds";const words: MessageOverrides = { commands: { close: "Close tab" }, tabs: { close: (pane) => `Close ${pane} tab` },};const jali = createJali({ panes: [orderKind], layout: orderKind({ id: 1 }), messages: words });jali.messages.commands.close; // "Close tab"jali.messages.commands.zoom; // "Maximise or restore pane", from `en`en.announcements.closed("Order 1041"); // "Order 1041 closed · Undo available"