@cmodjs/core 8.5.0 → 8.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/ui.md CHANGED
@@ -85,9 +85,9 @@ An element built outside a render, at module load or in a hook, holds its props
85
85
  type Tone = 'neutral' | 'info' | 'success' | 'warning' | 'critical'
86
86
  Tabs(props: { tabs: readonly { key: string; label: string; hotkey?: string }[]; selected: string; onSelect(key: string): void; children? })
87
87
  Split(props: { children: readonly JSX.Element[] })
88
- Panel(props: { title: string; children? })
88
+ Panel(props: { title: string; description?: string; actions?; children? })
89
89
  List(props: { label: string; children? })
90
- ListItem(props: { key: string; label: string; description?: string; tone?: Tone | 'off'; isSelected?: boolean; onPress?(): void })
90
+ ListItem(props: { key: string; label: string; leading?: string; description?: string; trailing?; tone?: Tone | 'off'; isSelected?: boolean; onPress?(): void; depth?: number; isOpen?: boolean; onOpenChange?(isOpen: boolean): void })
91
91
  Badge(props: { tone?: Tone; children })
92
92
  Banner(props: { tone?: Tone; title?: string; children?; actions? })
93
93
  Toggle(props: { label: string; checked: boolean; onChange(checked: boolean): void })
@@ -99,8 +99,8 @@ Progress(props: { value: number; width?: number; label?: string })
99
99
  ```
100
100
 
101
101
  - `Tabs` draws a row of tabs over `children`. The selected tab's label is bold and underlined. Each other tab is a `Button`, so a part that holds the keyboard switches tabs by Tab and Enter or a click. A tab given a `hotkey`, one digit or one lowercase letter, draws it before its label, as `o: Open`, and that key switches to it. Leave the Sidebar's digits to the Sidebar: inside a page, a tab's hotkey that matches one replaces it.
102
- - `Split` lays its children side by side in equal widths. `Panel` frames one part of a page or pane in a rounded border with its bold title in the top border, as `╭─ Changed files ──╮`, grows to fill the room its parent gives it, and is never narrower than its title.
103
- - `List` holds `ListItem` rows, and `label` names the list for a screen reader. A `ListItem` draws `● label` with the dot in its `tone`'s color, `○` for `'off'`, and `description` dim after the label. The selected row draws on the highlight background in bold, and any other row with `onPress` is a quiet `Button` keyed `key`.
102
+ - `Split` lays its children side by side in equal widths. `Panel` frames one part of a page or pane in a rounded border with its bold title in the top border, as `╭─ Changed files ──╮`, grows to fill the room its parent gives it, and is never narrower than its title. Its `description` and `actions`, the buttons, draw on its first line, the description dim at the left and the actions at the right, as the header of a page about one thing.
103
+ - `List` holds `ListItem` rows, and `label` names the list for a screen reader. A `ListItem` draws `● leading label` with the dot in its `tone`'s color, `○` for `'off'`, `leading` and `description` dim before and after the label, and `trailing`, such as a `Badge`, last. The selected row draws on the highlight background in bold, and any other row with `onPress` is a quiet `Button` keyed `key`. A row given a `depth` is a row of a tree: it is indented two columns a level, keeps a column for `▸`, and puts `description` and `trailing` at the right edge. Give it `isOpen` and `onOpenChange` too, and that column is a `▸` or `▾` Button keyed `<key>:toggle`.
104
104
  - `Badge` draws a short status, such as `warning`, in its `tone`'s color. `Banner` draws a notice that needs the person: its `title` and text in its `tone`'s color, and its `actions`, the buttons, in a row under them.
105
105
  - `Toggle` draws `[x] label` or `[ ] label` as a `Button`. Enter or a click calls `onChange` with the other value.
106
106
  - `Tooltip` shows `text` in an inverted card above its children while the pointer rests on them. The card opens upward, because Claude Code paints a card over the rows drawn before it and under the rows drawn after it. It has no border, so a one-line card needs one free row above its children. The pointer alone opens it, so put nothing only a tooltip says.
@@ -108,7 +108,7 @@ Progress(props: { value: number; width?: number; label?: string })
108
108
  - `Dialog` lays out a dialog's title, body, and `actions`, the buttons in a row. Put the safe action first, as the `primary` Button with `autoFocus`.
109
109
  - `Pagination` draws `p: Previous 2 of 5 n: Next`. `p` and `n` are its hotkeys, and an end it cannot pass is dim text.
110
110
  - `Progress` fills `value` percent of `width` columns, 24 unless given, and `label` names the bar for a screen reader. Put the count beside it in a `Text`, or pass it as a loading toast's `description`.
111
- - `Tabs`, `Toggle`, `Help`, and `Pagination` hold no state of their own. Keep their value in `mod.state` and set it in the callback, as in React's controlled components.
111
+ - `Tabs`, `Toggle`, `Help`, `Pagination`, and a tree `ListItem` hold no state of their own. Keep their value in `mod.state` and set it in the callback, as in React's controlled components.
112
112
 
113
113
  ## Views and pages
114
114
 
@@ -240,11 +240,11 @@ It shows the session of the focused terminal: the terminal's foreground process,
240
240
 
241
241
  It never docks itself, because Herdr writes a dock into whichever layout file shows when it first sees the mod, once per Herdr home, and a layout another mod rewrites loses it for good. Herdr shows it in two ways. `mod.open` with `{ "name": "cmod" }` opens the dock as a window over any layout, Herdr's own included, and closes it when run again: from `herdr-app do mod.open:cmod`, a `keys.json` binding such as `"ctrl-shift-m": "mod.open:cmod"`, or another mod's `run`. The window takes no keyboard, so the dock keeps following the focused terminal, and Herdr remembers where it was dragged. A layout author places it anywhere a mod goes instead, with the `props` that say what it shows:
242
242
 
243
- - `{ "mod": "cmod" }`, or `{ "show": "views" }`, shows the focused session's views as tabs, and hosts the focused session, in a layout and in the `mod.open` window alike: its `show` carries `isHost`, so the session opens no Sidebar of its own. An `Open` with `isAsked` selects the view's tab, and a dock in a layout also shows its own block: it selects the block's branch of each stack above it and shows each hidden node on the way, with `layout.select` and `layout.show`, wherever the layout puts it. It shows the views in the order `views` lists them, the cmod plugin's own `dashboard`, `history`, and `settings` among them, and the session's open pages after them in the same row, which scrolls. A page opens as a Herdr tab, `tab.new` with `{ "show": "page", "session", "mod", "id", "title" }`. A page a mod opens itself opens the same way on `Open`, and its tab closes on `Close`. A view a mod opens becomes the shown tab, and a `Close` of the shown view goes back to the first one, as the Sidebar takes a closed view away.
243
+ - `{ "mod": "cmod" }`, or `{ "show": "views" }`, shows the focused session's views as tabs, and hosts the focused session, in a layout and in the `mod.open` window alike: its `show` carries `isHost`, so the session opens no Sidebar of its own. An `Open` with `isAsked` selects the view's tab, and a dock in a layout also shows its own block: it selects the block's branch of each stack above it and shows each hidden node on the way, with `layout.select` and `layout.show`, wherever the layout puts it. It shows the views in the order `views` lists them, the cmod plugin's own `history` and `settings` among them, with `dashboard` only while a widget is on the Dashboard, each label starting with a capital, and the session's open pages after them in the same row, which scrolls. It draws every view the session lists and draws each again on its `Redraw`, so a switch of tab shows its drawing at once, and a `Redraw` that comes while that view's drawing is on its way draws it once more after it lands. A page opens as a Herdr tab, `tab.new` with `{ "show": "page", "session", "mod", "id", "title" }`. A page a mod opens itself opens the same way on `Open`, and its tab closes on `Close`. A view a mod opens becomes the shown tab, and a `Close` of the shown view goes back to the first one, as the Sidebar takes a closed view away.
244
244
  - `{ "show": "widgets", "area": "belowPrompt" }` draws in a row each widget that lists that area, drawn for that area, for a status bar block. `area` is the value of an area constant: `abovePrompt`, `belowPrompt`, `working`, `turnEnd`, or `dashboard`, the default. In a pane header Herdr gives `props().terminal`, so each pane's header draws its own session's widgets.
245
245
  - `{ "show": "page", "session": "<id>", "mod": "<mod>", "id": "<page>" }` draws one page of one session, as a page in the dock's row opens it.
246
246
 
247
- Each dock and page tab tells `show` the view or page it draws, under a client name it makes once, so the mod's view or page counts as `isShown` while Herdr shows it. It tells again when its shown tab or its focused session changes, renews the list every 5 seconds, and clears it when its focused session changes or the placement closes. A `{ "show": "widgets" }` block tells nothing, because `isShown` is about views and pages.
247
+ Each dock and page tab tells `show` the views or page it draws, under a client name it makes once: a dock tells every view of the session, so each counts as `isShown` and keeps its state while Herdr shows the session. It tells again when its focused session changes, renews the list every 5 seconds, and clears it when its focused session changes or the placement closes. A `{ "show": "widgets" }` block tells nothing, because `isShown` is about views and pages.
248
248
 
249
249
  ```json
250
250
  { "id": "cmod", "type": "block", "size": { "px": 360 }, "content": { "mod": "cmod", "props": { "show": "views" } } }
@@ -254,11 +254,11 @@ Each dock and page tab tells `show` the view or page it draws, under a client na
254
254
  Each element draws as Herdr's own, and each `label`, or a `Text`'s text, is its accessible name:
255
255
 
256
256
  - `Box` draws a flex row or column with its gap, padding, margin, sizes, and background, a column as 8 pixels across, a row as 20 pixels down, and a space step as 8 pixels. A `borderStyle` draws a card.
257
- - Each component of `ui/components.js` draws as Herdr's control of the same job: `Tabs` as its tabs, `Panel` as a heading above a card, `List` and `ListItem` as a list with a status dot, `Toggle` as its switch, `Progress` as its progress bar, `Pagination` with a disabled end, `Badge` and `Banner` in their tone's color, `Tooltip` and `Help` as its tooltip, and `Split` as equal columns.
257
+ - Each component of `ui/components.js` draws as Herdr's control of the same job: `Tabs` as its tabs, `Panel` as a section under its title, with no card, as a page header with its title, `description`, and `actions` when it has either, and as the bare view when it is the view's outermost element with neither, since the tab names it, `List` and `ListItem` as a list of rows with a status dot and, given a `depth`, as an indented tree row with its disclosure button, `Toggle` as its switch, `Progress` as its progress bar, `Pagination` with a disabled end, `Badge` and `Banner` tinted in their tone's color, `Tooltip` and `Help` as its tooltip, and `Split` as equal columns.
258
258
  - `Text` draws its text with its color, weight, and style. A theme color such as `'success'` draws in the Herdr theme's color of the same meaning. A `Text` with a `backgroundColor` draws as a chip, and text that lays out in cells, with block or box-drawing characters or a run of spaces, keeps the terminal font so its columns line up.
259
- - `Button` draws Herdr's button: `variant: 'primary'` as its solid button, a `plain` and `dimColor` one as a quiet row of a list, and any other as an outlined one, with its `label` and its `hotkey`. A press runs its handler, and a `Button` with `href` opens an `http:` or `https:` page in the browser, and copies any other link.
260
- - `Input` draws a field, and `rows` above 1 a text area. Each change runs `onInput`, and Enter runs `onSubmit`.
261
- - `Select` draws its options as a segmented control, with the selected one marked.
259
+ - `Button` draws Herdr's button: `variant: 'primary'` as its solid button, a `plain` and `dimColor` one as a quiet button, and any other as an outlined one, with its `label`. A press runs its handler, and a `Button` with `href` opens an `http:` or `https:` page in the browser, and copies any other link.
260
+ - `Input` draws a field across the row with its `placeholder`, or, given a `label`, a settings row with the label at the left and the field at the right, and `rows` above 1 a text area. Each change runs `onInput`, and Enter runs `onSubmit`.
261
+ - `Select` draws a button with the chosen option, or its `label` while none is chosen, which opens a menu of the options with the chosen one checked.
262
262
  - `Markdown` draws Herdr's Markdown text. A link it lists in `pressableLinks`, or any link without them, runs `onLinkPress`, and with no `onLinkPress` it opens as a `Button`'s `href` does.
263
263
  - `Code` draws a read-only code view with the language's colors.
264
264
  - `Image` and `Svg` draw the picture, which the mod writes under `mods/cmod/.drawn/` first, because Herdr draws only a picture in its home. An image from shared memory draws its `label`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmodjs/core",
3
- "version": "8.5.0",
3
+ "version": "8.7.0",
4
4
  "description": "Build Claude Code mods: hooks, panes, checks, and an install that just works.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/records.d.ts CHANGED
@@ -194,7 +194,7 @@ export declare function newestLog(entries: readonly LogEntry[]): LogEntry[];
194
194
  export declare function versionsLine({ mod, core, cmod, program, claudeCode }: LogVersions): string;
195
195
  export declare function logReport(entry: LogEntry): string;
196
196
  export declare function parseConsent(value: unknown, path: string): Record<string, string[]>;
197
- export declare const coreVersion = "8.5.0";
197
+ export declare const coreVersion = "8.7.0";
198
198
  export declare const oldestCmodVersion = "8.0.0";
199
199
  export declare function hotkeyCommand(mod: string, hotkey: string): string;
200
200
  export declare function hotkeyBindings(mod: string, hotkeys: Hotkeys | undefined): Record<string, string>;
package/records.js CHANGED
@@ -405,7 +405,7 @@ function readHotkeys(hotkeys) {
405
405
  throw new Error(`package.json "cmod.hotkeys" is not a map of hotkeys to their title and optional default combo. ${fix}`);
406
406
  return { hotkeys: checkHotkeys('package.json "cmod"', hotkeys) };
407
407
  }
408
- export const coreVersion = '8.5.0';
408
+ export const coreVersion = '8.7.0';
409
409
  export const oldestCmodVersion = '8.0.0';
410
410
  export function hotkeyCommand(mod, hotkey) {
411
411
  return `${mod}--${hotkey}`;
package/runtime/web.js CHANGED
@@ -134,7 +134,11 @@ const elements = {
134
134
  return `<div class="tabs"><div role="tablist" class="tablist">${buttons.join('')}</div><div role="tabpanel" class="tabpanel">${nodeHtml(props['children'], drawing)}</div></div>`;
135
135
  },
136
136
  Split: (props, drawing) => `<div class="split">${(Array.isArray(props['children']) ? props['children'] : [props['children']]).map((child) => `<div class="split-part">${nodeHtml(child, drawing)}</div>`).join('')}</div>`,
137
- Panel: (props, drawing) => `<section class="panel"><h3 class="panel-title">${escaped(textOr(props['title'], ''))}</h3><div class="panel-body">${nodeHtml(props['children'], drawing)}</div></section>`,
137
+ Panel: (props, drawing) => {
138
+ const description = typeof props['description'] === 'string' ? `<p class="panel-description">${escaped(props['description'])}</p>` : '';
139
+ const actions = props['actions'] === undefined ? '' : `<div class="actions">${nodeHtml(props['actions'], drawing)}</div>`;
140
+ return `<section class="panel"><header class="panel-header"><h3 class="panel-title">${escaped(textOr(props['title'], ''))}</h3>${actions}</header>${description}<div class="panel-body">${nodeHtml(props['children'], drawing)}</div></section>`;
141
+ },
138
142
  Toggle: (props) => {
139
143
  const label = textOr(props['label'], '');
140
144
  return `<button type="button" role="switch" class="switch" aria-checked="${props['checked'] === true}"${attribute('data-key', `${textOr(props['key'], '')}toggle:${label}`)}${handlerAttribute('data-press', props['onToggle'])}><span class="switch-track"></span>${escaped(label)}</button>`;
@@ -155,14 +159,23 @@ const elements = {
155
159
  return `<progress class="progress" max="100" value="${numberOr(props['value'], 0)}"${attribute('aria-label', label)}${attribute('style', `width:${across(numberOr(props['width'], 24))}`)}></progress>`;
156
160
  },
157
161
  List: (props, drawing) => `<ul class="list"${attribute('aria-label', textOr(props['label'], ''))}>${nodeHtml(props['children'], drawing)}</ul>`,
158
- ListItem: (props) => {
162
+ ListItem: (props, drawing) => {
159
163
  const dot = props['tone'] === undefined ? '' : `<span class="dot tone-${toneOf(props['tone'])}" aria-hidden="true"></span>`;
164
+ const leading = typeof props['leading'] === 'string' ? `<span class="leading">${escaped(props['leading'])}</span>` : '';
160
165
  const description = typeof props['description'] === 'string' ? `<span class="description">${escaped(props['description'])}</span>` : '';
161
- const inner = `${dot}<span class="item-label">${escaped(textOr(props['label'], ''))}</span>${description}`;
166
+ const trailing = props['trailing'] === undefined ? '' : `<span class="trailing">${nodeHtml(props['trailing'], drawing)}</span>`;
167
+ const inner = `${dot}${leading}<span class="item-label">${escaped(textOr(props['label'], ''))}</span>${description}${trailing}`;
162
168
  const isSelected = props['isSelected'] === true;
163
- if (handlerOf(props['onPress']) === undefined)
164
- return `<li class="list-item${isSelected ? ' selected' : ''}"${isSelected ? ' aria-current="true"' : ''}>${inner}</li>`;
165
- return `<li><button type="button" class="list-item${isSelected ? ' selected' : ''}"${isSelected ? ' aria-current="true"' : ''}${attribute('data-key', keyOf(props))}${handlerAttribute('data-press', props['onPress'])}>${inner}</button></li>`;
169
+ const depth = typeof props['depth'] === 'number' ? props['depth'] : undefined;
170
+ const isOpen = typeof props['isOpen'] === 'boolean' ? props['isOpen'] : undefined;
171
+ const opener = depth === undefined
172
+ ? ''
173
+ : isOpen === undefined || handlerOf(props['onToggle']) === undefined
174
+ ? '<span class="opener" aria-hidden="true"></span>'
175
+ : `<button type="button" class="opener" aria-label="${isOpen ? 'Close' : 'Open'}" aria-expanded="${isOpen}"${attribute('data-key', `${textOr(props['key'], '')}:toggle`)}${handlerAttribute('data-press', props['onToggle'])}></button>`;
176
+ const level = depth === undefined ? '' : ` style="--depth:${depth}" aria-level="${depth + 1}"`;
177
+ const row = handlerOf(props['onPress']) === undefined ? `<span class="list-item${isSelected ? ' selected' : ''}">${inner}</span>` : `<button type="button" class="list-item${isSelected ? ' selected' : ''}"${attribute('data-key', keyOf(props))}${handlerAttribute('data-press', props['onPress'])}>${inner}</button>`;
178
+ return `<li class="list-row${depth === undefined ? '' : ' tree-row'}"${isSelected ? ' aria-current="true"' : ''}${level}>${opener}${row}</li>`;
166
179
  },
167
180
  Badge: (props, drawing) => `<span class="badge tone-${toneOf(props['tone'])}">${nodeHtml(props['children'], drawing)}</span>`,
168
181
  Banner: (props, drawing) => {
@@ -34,6 +34,7 @@ export type Widgets = {
34
34
  recheck(): Promise<void>;
35
35
  rows(area: Area, at: StyledAt): RenderElement[];
36
36
  draw(area: Area, table: ElementTable, at: StyledAt, turn?: TurnData): Promise<RenderElement[]>;
37
+ onChange(listener: () => void): void;
37
38
  };
38
39
  export declare function layoutOf(value: unknown): WidgetLayout;
39
40
  export declare function placedIn(layout: WidgetLayout, key: string): Area | undefined;
@@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MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IACtE,QAAQ,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,GAAG,SAAS,CAAA;IAC9D,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,QAAQ,KAAK,CAAC,CAAC,KAAK,EAAE,aAAa,KAAK,aAAa,CAAC,GAAG,SAAS,CAAA;CAClH,GAAG,OAAO,CAiLV"}
@@ -105,9 +105,12 @@ export function serveWidgets({ claude, router, store, report, turnClosedBy, part
105
105
  .catch((error) => report('widgets:layout', 'Could not save the widget layout', error));
106
106
  return saving;
107
107
  };
108
+ const listeners = new Set();
108
109
  const place = () => {
109
110
  layout = withNewWidgets(stored);
110
111
  redraw();
112
+ for (const listener of listeners)
113
+ listener();
111
114
  };
112
115
  const withNewWidgets = (current) => placed()
113
116
  .filter(({ key, mod }) => mod !== 'claude' && placedIn(current, key) === undefined && !placedKeys.has(key))
@@ -227,5 +230,6 @@ export function serveWidgets({ claude, router, store, report, turnClosedBy, part
227
230
  recheck,
228
231
  rows,
229
232
  draw,
233
+ onChange: (listener) => void listeners.add(listener),
230
234
  };
231
235
  }
package/src/records.ts CHANGED
@@ -499,7 +499,7 @@ function readHotkeys(hotkeys: unknown): Steps {
499
499
  return { hotkeys: checkHotkeys('package.json "cmod"', hotkeys as Record<string, HotkeyInit>) }
500
500
  }
501
501
 
502
- export const coreVersion = '8.5.0'
502
+ export const coreVersion = '8.7.0'
503
503
 
504
504
  export const oldestCmodVersion = '8.0.0'
505
505
 
@@ -151,7 +151,11 @@ const elements: Readonly<Record<string, (props: Props, drawing: Drawing) => stri
151
151
  return `<div class="tabs"><div role="tablist" class="tablist">${buttons.join('')}</div><div role="tabpanel" class="tabpanel">${nodeHtml(props['children'], drawing)}</div></div>`
152
152
  },
153
153
  Split: (props, drawing) => `<div class="split">${(Array.isArray(props['children']) ? props['children'] : [props['children']]).map((child: unknown) => `<div class="split-part">${nodeHtml(child, drawing)}</div>`).join('')}</div>`,
154
- Panel: (props, drawing) => `<section class="panel"><h3 class="panel-title">${escaped(textOr(props['title'], ''))}</h3><div class="panel-body">${nodeHtml(props['children'], drawing)}</div></section>`,
154
+ Panel: (props, drawing) => {
155
+ const description = typeof props['description'] === 'string' ? `<p class="panel-description">${escaped(props['description'])}</p>` : ''
156
+ const actions = props['actions'] === undefined ? '' : `<div class="actions">${nodeHtml(props['actions'], drawing)}</div>`
157
+ return `<section class="panel"><header class="panel-header"><h3 class="panel-title">${escaped(textOr(props['title'], ''))}</h3>${actions}</header>${description}<div class="panel-body">${nodeHtml(props['children'], drawing)}</div></section>`
158
+ },
155
159
  Toggle: (props) => {
156
160
  const label = textOr(props['label'], '')
157
161
  return `<button type="button" role="switch" class="switch" aria-checked="${props['checked'] === true}"${attribute('data-key', `${textOr(props['key'], '')}toggle:${label}`)}${handlerAttribute('data-press', props['onToggle'])}><span class="switch-track"></span>${escaped(label)}</button>`
@@ -173,13 +177,24 @@ const elements: Readonly<Record<string, (props: Props, drawing: Drawing) => stri
173
177
  return `<progress class="progress" max="100" value="${numberOr(props['value'], 0)}"${attribute('aria-label', label)}${attribute('style', `width:${across(numberOr(props['width'], 24))}`)}></progress>`
174
178
  },
175
179
  List: (props, drawing) => `<ul class="list"${attribute('aria-label', textOr(props['label'], ''))}>${nodeHtml(props['children'], drawing)}</ul>`,
176
- ListItem: (props) => {
180
+ ListItem: (props, drawing) => {
177
181
  const dot = props['tone'] === undefined ? '' : `<span class="dot tone-${toneOf(props['tone'])}" aria-hidden="true"></span>`
182
+ const leading = typeof props['leading'] === 'string' ? `<span class="leading">${escaped(props['leading'])}</span>` : ''
178
183
  const description = typeof props['description'] === 'string' ? `<span class="description">${escaped(props['description'])}</span>` : ''
179
- const inner = `${dot}<span class="item-label">${escaped(textOr(props['label'], ''))}</span>${description}`
184
+ const trailing = props['trailing'] === undefined ? '' : `<span class="trailing">${nodeHtml(props['trailing'], drawing)}</span>`
185
+ const inner = `${dot}${leading}<span class="item-label">${escaped(textOr(props['label'], ''))}</span>${description}${trailing}`
180
186
  const isSelected = props['isSelected'] === true
181
- if (handlerOf(props['onPress']) === undefined) return `<li class="list-item${isSelected ? ' selected' : ''}"${isSelected ? ' aria-current="true"' : ''}>${inner}</li>`
182
- return `<li><button type="button" class="list-item${isSelected ? ' selected' : ''}"${isSelected ? ' aria-current="true"' : ''}${attribute('data-key', keyOf(props))}${handlerAttribute('data-press', props['onPress'])}>${inner}</button></li>`
187
+ const depth = typeof props['depth'] === 'number' ? props['depth'] : undefined
188
+ const isOpen = typeof props['isOpen'] === 'boolean' ? props['isOpen'] : undefined
189
+ const opener =
190
+ depth === undefined
191
+ ? ''
192
+ : isOpen === undefined || handlerOf(props['onToggle']) === undefined
193
+ ? '<span class="opener" aria-hidden="true"></span>'
194
+ : `<button type="button" class="opener" aria-label="${isOpen ? 'Close' : 'Open'}" aria-expanded="${isOpen}"${attribute('data-key', `${textOr(props['key'], '')}:toggle`)}${handlerAttribute('data-press', props['onToggle'])}></button>`
195
+ const level = depth === undefined ? '' : ` style="--depth:${depth}" aria-level="${depth + 1}"`
196
+ const row = handlerOf(props['onPress']) === undefined ? `<span class="list-item${isSelected ? ' selected' : ''}">${inner}</span>` : `<button type="button" class="list-item${isSelected ? ' selected' : ''}"${attribute('data-key', keyOf(props))}${handlerAttribute('data-press', props['onPress'])}>${inner}</button>`
197
+ return `<li class="list-row${depth === undefined ? '' : ' tree-row'}"${isSelected ? ' aria-current="true"' : ''}${level}>${opener}${row}</li>`
183
198
  },
184
199
  Badge: (props, drawing) => `<span class="badge tone-${toneOf(props['tone'])}">${nodeHtml(props['children'], drawing)}</span>`,
185
200
  Banner: (props, drawing) => {
@@ -49,6 +49,7 @@ export type Widgets = {
49
49
  recheck(): Promise<void>
50
50
  rows(area: Area, at: StyledAt): RenderElement[]
51
51
  draw(area: Area, table: ElementTable, at: StyledAt, turn?: TurnData): Promise<RenderElement[]>
52
+ onChange(listener: () => void): void
52
53
  }
53
54
 
54
55
  export function layoutOf(value: unknown): WidgetLayout {
@@ -165,9 +166,12 @@ export function serveWidgets({
165
166
  return saving
166
167
  }
167
168
 
169
+ const listeners = new Set<() => void>()
170
+
168
171
  const place = () => {
169
172
  layout = withNewWidgets(stored)
170
173
  redraw()
174
+ for (const listener of listeners) listener()
171
175
  }
172
176
 
173
177
  const withNewWidgets = (current: WidgetLayout) =>
@@ -297,5 +301,6 @@ export function serveWidgets({
297
301
  recheck,
298
302
  rows,
299
303
  draw,
304
+ onChange: (listener) => void listeners.add(listener),
300
305
  }
301
306
  }
@@ -39,18 +39,22 @@ export const Split = hostComponent(
39
39
  },
40
40
  )
41
41
 
42
+ type PanelProps = { readonly title: string; readonly description?: string; readonly actions?: JSX.Children; readonly children?: JSX.Children }
43
+
42
44
  export const Panel = hostComponent(
43
45
  'Panel',
44
- ({ title, children }: { readonly title: string; readonly children?: JSX.Children }) => ({ title, ...(children === undefined ? {} : { children }) }),
45
- ({ title, children }: { readonly title: string; readonly children?: JSX.Children }) =>
46
- Box({
46
+ ({ title, description, actions, children }: PanelProps): PanelProps => ({ title, ...(description === undefined ? {} : { description }), ...(actions === undefined ? {} : { actions }), ...(children === undefined ? {} : { children }) }),
47
+ ({ title, description, actions, children }: PanelProps) => {
48
+ const header = description === undefined && actions === undefined ? [] : [Box({ justifyContent: 'space-between', columnGap: 2, flexWrap: 'wrap', children: [Text({ dimColor: true, wrap: 'wrap', children: description ?? '' }), ...(actions === undefined ? [] : [Box({ gap: 2, flexShrink: 0, children: actions })])] })]
49
+ return Box({
47
50
  flexDirection: 'column',
48
51
  flexGrow: 1,
49
52
  children: [
50
- Box({ flexDirection: 'column', flexGrow: 1, minWidth: [...title].length + 6, borderStyle: 'round', borderColor: 'subtle', paddingX: 1, children }),
53
+ Box({ flexDirection: 'column', flexGrow: 1, gap: header.length === 0 ? 0 : 1, minWidth: [...title].length + 6, borderStyle: 'round', borderColor: 'subtle', paddingX: 1, children: [...header, children] }),
51
54
  Box({ position: 'absolute', top: 0, left: 2, children: Text({ bold: true, wrap: 'truncate-end', children: ` ${title} ` }) }),
52
55
  ],
53
- }),
56
+ })
57
+ },
54
58
  )
55
59
 
56
60
  export const Toggle = hostComponent(
@@ -128,15 +132,30 @@ export const List = hostComponent(
128
132
  ({ children }: { readonly label: string; readonly children?: JSX.Children }) => Box({ flexDirection: 'column', children }),
129
133
  )
130
134
 
131
- type ListItemProps = { readonly key: string; readonly label: string; readonly description?: string; readonly tone?: Tone | 'off'; readonly isSelected?: boolean; readonly onPress?: Pressed }
135
+ type ListItemShared = { readonly key: string; readonly label: string; readonly description?: string; readonly leading?: string; readonly trailing?: JSX.Children; readonly tone?: Tone | 'off'; readonly isSelected?: boolean; readonly depth?: number; readonly isOpen?: boolean; readonly onPress?: Pressed }
136
+
137
+ type ListItemProps = ListItemShared & { readonly onOpenChange?: (isOpen: boolean) => void }
138
+
139
+ type ListItemData = ListItemShared & { readonly onToggle?: Pressed }
132
140
 
133
141
  const statusOf = (tone: ListItemProps['tone']) => (tone === undefined ? [] : [tone === 'off' ? Text({ dimColor: true, children: '○ ' }) : Text({ ...textOf(tone), children: '● ' })])
134
142
 
143
+ function treeRow({ key, label, description, leading, trailing, tone, isSelected, depth = 0, isOpen, onToggle, onPress }: ListItemData): JSX.Element {
144
+ const opener = isOpen !== undefined && onToggle !== undefined ? Button({ plain: true, key: `${key}:toggle`, onPress: onToggle, children: Text({ dimColor: true, children: isOpen ? '▾' : '▸' }) }) : Text({ children: ' ' })
145
+ const shown = Text({ wrap: 'truncate-end', ...(isSelected === true ? { bold: true } : {}), children: [...statusOf(tone), ...(leading === undefined ? [] : [Text({ dimColor: true, children: `${leading} ` })]), label] })
146
+ const row = Box({ columnGap: 1, minWidth: 0, children: [opener, onPress === undefined ? shown : Button({ plain: true, key, onPress, children: shown })] })
147
+ const end = [...(description === undefined ? [] : [Text({ dimColor: true, children: description })]), ...(trailing === undefined ? [] : [trailing])]
148
+ if (end.length === 0) return Box({ paddingLeft: depth * 2, children: row })
149
+ return Box({ width: '100%', paddingLeft: depth * 2, columnGap: 1, justifyContent: 'space-between', children: [row, Box({ flexShrink: 0, columnGap: 1, children: end })] })
150
+ }
151
+
135
152
  export const ListItem = hostComponent(
136
153
  'ListItem',
137
- (props: ListItemProps) => props,
138
- ({ key, label, description, tone, isSelected, onPress }: ListItemProps) => {
139
- const shown = [...statusOf(tone), label, ...(description === undefined ? [] : [Text({ dimColor: true, children: ` ${description}` })])]
154
+ ({ onOpenChange, ...props }: ListItemProps): ListItemData => ({ ...props, ...(onOpenChange === undefined || props.isOpen === undefined ? {} : { onToggle: () => onOpenChange(props.isOpen !== true) }) }),
155
+ (props: ListItemData) => {
156
+ const { key, label, description, leading, trailing, tone, isSelected, depth, onPress } = props
157
+ if (depth !== undefined) return treeRow(props)
158
+ const shown = [...statusOf(tone), ...(leading === undefined ? [] : [Text({ dimColor: true, children: `${leading} ` })]), label, ...(description === undefined ? [] : [Text({ dimColor: true, children: ` ${description}` })]), ...(trailing === undefined ? [] : [' ', trailing])]
140
159
  if (isSelected === true || onPress === undefined) return Box({ ...(isSelected === true ? { backgroundColor: 'userMessageBackground' } : {}), paddingX: 1, children: Text({ wrap: 'truncate-end', ...(isSelected === true ? { bold: true } : {}), children: shown }) })
141
160
  return Box({ paddingX: 1, children: Button({ plain: true, dimColor: true, key, onPress, children: shown }) })
142
161
  },
@@ -14,10 +14,13 @@ export declare const Tabs: (props: {
14
14
  export declare const Split: (props: {
15
15
  readonly children: readonly JSX.Element[];
16
16
  }) => JSX.Element;
17
- export declare const Panel: (props: {
17
+ type PanelProps = {
18
18
  readonly title: string;
19
+ readonly description?: string;
20
+ readonly actions?: JSX.Children;
19
21
  readonly children?: JSX.Children;
20
- }) => JSX.Element;
22
+ };
23
+ export declare const Panel: (props: PanelProps) => JSX.Element;
21
24
  export declare const Toggle: (props: {
22
25
  readonly label: string;
23
26
  readonly checked: boolean;
@@ -51,14 +54,21 @@ export declare const List: (props: {
51
54
  readonly label: string;
52
55
  readonly children?: JSX.Children;
53
56
  }) => JSX.Element;
54
- type ListItemProps = {
57
+ type ListItemShared = {
55
58
  readonly key: string;
56
59
  readonly label: string;
57
60
  readonly description?: string;
61
+ readonly leading?: string;
62
+ readonly trailing?: JSX.Children;
58
63
  readonly tone?: Tone | 'off';
59
64
  readonly isSelected?: boolean;
65
+ readonly depth?: number;
66
+ readonly isOpen?: boolean;
60
67
  readonly onPress?: Pressed;
61
68
  };
69
+ type ListItemProps = ListItemShared & {
70
+ readonly onOpenChange?: (isOpen: boolean) => void;
71
+ };
62
72
  export declare const ListItem: (props: ListItemProps) => JSX.Element;
63
73
  export declare const Badge: (props: {
64
74
  readonly tone?: Tone;
@@ -1 +1 @@
1
- {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/ui/components.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GAAG,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5F,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAAA;AAE1E,KAAK,OAAO,GAAG,MAAM,IAAI,CAAA;AASzB,eAAO,MAAM,IAAI;mBAE2C,SAAS,GAAG,EAAE;uBAAqB,MAAM;uBAAqB,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI;wBAAsB,GAAG,CAAC,QAAQ;iBAahL,CAAA;AAED,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AA;AAED,eAAO,MAAM,KAAK;oBAEmC,IAAI;uBAAqB,GAAG,CAAC,QAAQ;iBAEzF,CAAA;AAOD,eAAO,MAAM,MAAM;oBAE+C,IAAI;qBAAmB,MAAM;wBAAsB,GAAG,CAAC,QAAQ;uBAAqB,GAAG,CAAC,QAAQ;iBAUjK,CAAA"}
package/ui/components.js CHANGED
@@ -18,14 +18,17 @@ export const Split = hostComponent('Split', ({ children }) => ({ children }), ({
18
18
  const width = `${Math.floor(100 / Math.max(children.length, 1))}%`;
19
19
  return Box({ gap: 1, children: children.map((child) => Box({ width, children: child })) });
20
20
  });
21
- export const Panel = hostComponent('Panel', ({ title, children }) => ({ title, ...(children === undefined ? {} : { children }) }), ({ title, children }) => Box({
22
- flexDirection: 'column',
23
- flexGrow: 1,
24
- children: [
25
- Box({ flexDirection: 'column', flexGrow: 1, minWidth: [...title].length + 6, borderStyle: 'round', borderColor: 'subtle', paddingX: 1, children }),
26
- Box({ position: 'absolute', top: 0, left: 2, children: Text({ bold: true, wrap: 'truncate-end', children: ` ${title} ` }) }),
27
- ],
28
- }));
21
+ export const Panel = hostComponent('Panel', ({ title, description, actions, children }) => ({ title, ...(description === undefined ? {} : { description }), ...(actions === undefined ? {} : { actions }), ...(children === undefined ? {} : { children }) }), ({ title, description, actions, children }) => {
22
+ const header = description === undefined && actions === undefined ? [] : [Box({ justifyContent: 'space-between', columnGap: 2, flexWrap: 'wrap', children: [Text({ dimColor: true, wrap: 'wrap', children: description ?? '' }), ...(actions === undefined ? [] : [Box({ gap: 2, flexShrink: 0, children: actions })])] })];
23
+ return Box({
24
+ flexDirection: 'column',
25
+ flexGrow: 1,
26
+ children: [
27
+ Box({ flexDirection: 'column', flexGrow: 1, gap: header.length === 0 ? 0 : 1, minWidth: [...title].length + 6, borderStyle: 'round', borderColor: 'subtle', paddingX: 1, children: [...header, children] }),
28
+ Box({ position: 'absolute', top: 0, left: 2, children: Text({ bold: true, wrap: 'truncate-end', children: ` ${title} ` }) }),
29
+ ],
30
+ });
31
+ });
29
32
  export const Toggle = hostComponent('Toggle', ({ label, checked, onChange }) => ({ key: '', label, checked, onToggle: () => onChange(!checked) }), ({ key, label, checked, onToggle }) => Button({ plain: true, key: `${key}toggle:${label}`, label: `${checked ? '[x]' : '[ ]'} ${label}`, onPress: onToggle }));
30
33
  const cardColumns = 36;
31
34
  function card(text, isShown) {
@@ -62,8 +65,20 @@ export const Progress = hostComponent('Progress', ({ value, width = 24, label })
62
65
  });
63
66
  export const List = hostComponent('List', ({ label, children }) => ({ label, ...(children === undefined ? {} : { children }) }), ({ children }) => Box({ flexDirection: 'column', children }));
64
67
  const statusOf = (tone) => (tone === undefined ? [] : [tone === 'off' ? Text({ dimColor: true, children: '○ ' }) : Text({ ...textOf(tone), children: '● ' })]);
65
- export const ListItem = hostComponent('ListItem', (props) => props, ({ key, label, description, tone, isSelected, onPress }) => {
66
- const shown = [...statusOf(tone), label, ...(description === undefined ? [] : [Text({ dimColor: true, children: ` ${description}` })])];
68
+ function treeRow({ key, label, description, leading, trailing, tone, isSelected, depth = 0, isOpen, onToggle, onPress }) {
69
+ const opener = isOpen !== undefined && onToggle !== undefined ? Button({ plain: true, key: `${key}:toggle`, onPress: onToggle, children: Text({ dimColor: true, children: isOpen ? '▾' : '▸' }) }) : Text({ children: ' ' });
70
+ const shown = Text({ wrap: 'truncate-end', ...(isSelected === true ? { bold: true } : {}), children: [...statusOf(tone), ...(leading === undefined ? [] : [Text({ dimColor: true, children: `${leading} ` })]), label] });
71
+ const row = Box({ columnGap: 1, minWidth: 0, children: [opener, onPress === undefined ? shown : Button({ plain: true, key, onPress, children: shown })] });
72
+ const end = [...(description === undefined ? [] : [Text({ dimColor: true, children: description })]), ...(trailing === undefined ? [] : [trailing])];
73
+ if (end.length === 0)
74
+ return Box({ paddingLeft: depth * 2, children: row });
75
+ return Box({ width: '100%', paddingLeft: depth * 2, columnGap: 1, justifyContent: 'space-between', children: [row, Box({ flexShrink: 0, columnGap: 1, children: end })] });
76
+ }
77
+ export const ListItem = hostComponent('ListItem', ({ onOpenChange, ...props }) => ({ ...props, ...(onOpenChange === undefined || props.isOpen === undefined ? {} : { onToggle: () => onOpenChange(props.isOpen !== true) }) }), (props) => {
78
+ const { key, label, description, leading, trailing, tone, isSelected, depth, onPress } = props;
79
+ if (depth !== undefined)
80
+ return treeRow(props);
81
+ const shown = [...statusOf(tone), ...(leading === undefined ? [] : [Text({ dimColor: true, children: `${leading} ` })]), label, ...(description === undefined ? [] : [Text({ dimColor: true, children: ` ${description}` })]), ...(trailing === undefined ? [] : [' ', trailing])];
67
82
  if (isSelected === true || onPress === undefined)
68
83
  return Box({ ...(isSelected === true ? { backgroundColor: 'userMessageBackground' } : {}), paddingX: 1, children: Text({ wrap: 'truncate-end', ...(isSelected === true ? { bold: true } : {}), children: shown }) });
69
84
  return Box({ paddingX: 1, children: Button({ plain: true, dimColor: true, key, onPress, children: shown }) });