@cmodjs/core 8.5.0 → 8.6.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
@@ -87,7 +87,7 @@ Tabs(props: { tabs: readonly { key: string; label: string; hotkey?: string }[];
87
87
  Split(props: { children: readonly JSX.Element[] })
88
88
  Panel(props: { title: string; 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 })
@@ -100,7 +100,7 @@ Progress(props: { value: number; width?: number; label?: string })
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
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`.
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 `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
 
@@ -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, and as the bare view when it is the view's outermost element, 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
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.
260
+ - `Input` draws a field with its `label` inside it, before the text, and `rows` above 1 a text area. Each change runs `onInput`, and Enter runs `onSubmit`.
261
+ - `Select` draws a button with its `label` and the chosen option, 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.6.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.6.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.6.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
@@ -155,14 +155,23 @@ const elements = {
155
155
  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
156
  },
157
157
  List: (props, drawing) => `<ul class="list"${attribute('aria-label', textOr(props['label'], ''))}>${nodeHtml(props['children'], drawing)}</ul>`,
158
- ListItem: (props) => {
158
+ ListItem: (props, drawing) => {
159
159
  const dot = props['tone'] === undefined ? '' : `<span class="dot tone-${toneOf(props['tone'])}" aria-hidden="true"></span>`;
160
+ const leading = typeof props['leading'] === 'string' ? `<span class="leading">${escaped(props['leading'])}</span>` : '';
160
161
  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}`;
162
+ const trailing = props['trailing'] === undefined ? '' : `<span class="trailing">${nodeHtml(props['trailing'], drawing)}</span>`;
163
+ const inner = `${dot}${leading}<span class="item-label">${escaped(textOr(props['label'], ''))}</span>${description}${trailing}`;
162
164
  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>`;
165
+ const depth = typeof props['depth'] === 'number' ? props['depth'] : undefined;
166
+ const isOpen = typeof props['isOpen'] === 'boolean' ? props['isOpen'] : undefined;
167
+ const opener = depth === undefined
168
+ ? ''
169
+ : isOpen === undefined || handlerOf(props['onToggle']) === undefined
170
+ ? '<span class="opener" aria-hidden="true"></span>'
171
+ : `<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>`;
172
+ const level = depth === undefined ? '' : ` style="--depth:${depth}" aria-level="${depth + 1}"`;
173
+ 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>`;
174
+ return `<li class="list-row${depth === undefined ? '' : ' tree-row'}"${isSelected ? ' aria-current="true"' : ''}${level}>${opener}${row}</li>`;
166
175
  },
167
176
  Badge: (props, drawing) => `<span class="badge tone-${toneOf(props['tone'])}">${nodeHtml(props['children'], drawing)}</span>`,
168
177
  Banner: (props, drawing) => {
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.6.0'
503
503
 
504
504
  export const oldestCmodVersion = '8.0.0'
505
505
 
@@ -173,13 +173,24 @@ const elements: Readonly<Record<string, (props: Props, drawing: Drawing) => stri
173
173
  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
174
  },
175
175
  List: (props, drawing) => `<ul class="list"${attribute('aria-label', textOr(props['label'], ''))}>${nodeHtml(props['children'], drawing)}</ul>`,
176
- ListItem: (props) => {
176
+ ListItem: (props, drawing) => {
177
177
  const dot = props['tone'] === undefined ? '' : `<span class="dot tone-${toneOf(props['tone'])}" aria-hidden="true"></span>`
178
+ const leading = typeof props['leading'] === 'string' ? `<span class="leading">${escaped(props['leading'])}</span>` : ''
178
179
  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}`
180
+ const trailing = props['trailing'] === undefined ? '' : `<span class="trailing">${nodeHtml(props['trailing'], drawing)}</span>`
181
+ const inner = `${dot}${leading}<span class="item-label">${escaped(textOr(props['label'], ''))}</span>${description}${trailing}`
180
182
  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>`
183
+ const depth = typeof props['depth'] === 'number' ? props['depth'] : undefined
184
+ const isOpen = typeof props['isOpen'] === 'boolean' ? props['isOpen'] : undefined
185
+ const opener =
186
+ depth === undefined
187
+ ? ''
188
+ : isOpen === undefined || handlerOf(props['onToggle']) === undefined
189
+ ? '<span class="opener" aria-hidden="true"></span>'
190
+ : `<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>`
191
+ const level = depth === undefined ? '' : ` style="--depth:${depth}" aria-level="${depth + 1}"`
192
+ 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>`
193
+ return `<li class="list-row${depth === undefined ? '' : ' tree-row'}"${isSelected ? ' aria-current="true"' : ''}${level}>${opener}${row}</li>`
183
194
  },
184
195
  Badge: (props, drawing) => `<span class="badge tone-${toneOf(props['tone'])}">${nodeHtml(props['children'], drawing)}</span>`,
185
196
  Banner: (props, drawing) => {
@@ -128,15 +128,29 @@ export const List = hostComponent(
128
128
  ({ children }: { readonly label: string; readonly children?: JSX.Children }) => Box({ flexDirection: 'column', children }),
129
129
  )
130
130
 
131
- type ListItemProps = { readonly key: string; readonly label: string; readonly description?: string; readonly tone?: Tone | 'off'; readonly isSelected?: boolean; readonly onPress?: Pressed }
131
+ 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 }
132
+
133
+ type ListItemProps = ListItemShared & { readonly onOpenChange?: (isOpen: boolean) => void }
134
+
135
+ type ListItemData = ListItemShared & { readonly onToggle?: Pressed }
132
136
 
133
137
  const statusOf = (tone: ListItemProps['tone']) => (tone === undefined ? [] : [tone === 'off' ? Text({ dimColor: true, children: '○ ' }) : Text({ ...textOf(tone), children: '● ' })])
134
138
 
139
+ function treeRow({ key, label, leading, trailing, tone, isSelected, depth = 0, isOpen, onToggle, onPress }: ListItemData): JSX.Element {
140
+ const opener = isOpen !== undefined && onToggle !== undefined ? Button({ plain: true, key: `${key}:toggle`, onPress: onToggle, children: Text({ dimColor: true, children: isOpen ? '▾' : '▸' }) }) : Text({ children: ' ' })
141
+ const shown = Text({ wrap: 'truncate-end', ...(isSelected === true ? { bold: true } : {}), children: [...statusOf(tone), ...(leading === undefined ? [] : [Text({ dimColor: true, children: `${leading} ` })]), label] })
142
+ const row = Box({ columnGap: 1, children: [opener, onPress === undefined ? shown : Button({ plain: true, key, onPress, children: shown })] })
143
+ if (trailing === undefined) return Box({ paddingLeft: depth * 2, children: row })
144
+ return Box({ width: '100%', paddingLeft: depth * 2, columnGap: 1, justifyContent: 'space-between', children: [row, Box({ flexShrink: 0, children: trailing })] })
145
+ }
146
+
135
147
  export const ListItem = hostComponent(
136
148
  '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}` })])]
149
+ ({ onOpenChange, ...props }: ListItemProps): ListItemData => ({ ...props, ...(onOpenChange === undefined || props.isOpen === undefined ? {} : { onToggle: () => onOpenChange(props.isOpen !== true) }) }),
150
+ (props: ListItemData) => {
151
+ const { key, label, description, leading, trailing, tone, isSelected, depth, onPress } = props
152
+ if (depth !== undefined) return treeRow(props)
153
+ const shown = [...statusOf(tone), ...(leading === undefined ? [] : [Text({ dimColor: true, children: `${leading} ` })]), label, ...(description === undefined ? [] : [Text({ dimColor: true, children: ` ${description}` })]), ...(trailing === undefined ? [] : [' ', trailing])]
140
154
  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
155
  return Box({ paddingX: 1, children: Button({ plain: true, dimColor: true, key, onPress, children: shown }) })
142
156
  },
@@ -51,14 +51,21 @@ export declare const List: (props: {
51
51
  readonly label: string;
52
52
  readonly children?: JSX.Children;
53
53
  }) => JSX.Element;
54
- type ListItemProps = {
54
+ type ListItemShared = {
55
55
  readonly key: string;
56
56
  readonly label: string;
57
57
  readonly description?: string;
58
+ readonly leading?: string;
59
+ readonly trailing?: JSX.Children;
58
60
  readonly tone?: Tone | 'off';
59
61
  readonly isSelected?: boolean;
62
+ readonly depth?: number;
63
+ readonly isOpen?: boolean;
60
64
  readonly onPress?: Pressed;
61
65
  };
66
+ type ListItemProps = ListItemShared & {
67
+ readonly onOpenChange?: (isOpen: boolean) => void;
68
+ };
62
69
  export declare const ListItem: (props: ListItemProps) => JSX.Element;
63
70
  export declare const Badge: (props: {
64
71
  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,eAAO,MAAM,KAAK;uBAEoB,SAAS,GAAG,CAAC,OAAO,EAAE;iBAK3D,CAAA;AAED,eAAO,MAAM,KAAK;oBAEwB,MAAM;wBAAsB,GAAG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,KAAK,IAAI;iBAenH,CAAA;AAED,eAAO,MAAM,QAAQ;oBAE8B,MAAM;qBAAmB,MAAM;qBAAmB,MAAM;iBAK1G,CAAA;AAED,eAAO,MAAM,IAAI;oBAEyB,MAAM;wBAAsB,GAAG,CAAC,QAAQ;iBAEjF,CAAA;AAED,KAAK,cAAc,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC;IAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAE/S,KAAK,aAAa,GAAG,cAAc,GAAG;IAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;CAAE,CAAA;AAc3F,eAAO,MAAM,QAAQ,uCAUpB,CAAA;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
@@ -62,8 +62,19 @@ export const Progress = hostComponent('Progress', ({ value, width = 24, label })
62
62
  });
63
63
  export const List = hostComponent('List', ({ label, children }) => ({ label, ...(children === undefined ? {} : { children }) }), ({ children }) => Box({ flexDirection: 'column', children }));
64
64
  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}` })])];
65
+ function treeRow({ key, label, leading, trailing, tone, isSelected, depth = 0, isOpen, onToggle, onPress }) {
66
+ const opener = isOpen !== undefined && onToggle !== undefined ? Button({ plain: true, key: `${key}:toggle`, onPress: onToggle, children: Text({ dimColor: true, children: isOpen ? '▾' : '▸' }) }) : Text({ children: ' ' });
67
+ const shown = Text({ wrap: 'truncate-end', ...(isSelected === true ? { bold: true } : {}), children: [...statusOf(tone), ...(leading === undefined ? [] : [Text({ dimColor: true, children: `${leading} ` })]), label] });
68
+ const row = Box({ columnGap: 1, children: [opener, onPress === undefined ? shown : Button({ plain: true, key, onPress, children: shown })] });
69
+ if (trailing === undefined)
70
+ return Box({ paddingLeft: depth * 2, children: row });
71
+ return Box({ width: '100%', paddingLeft: depth * 2, columnGap: 1, justifyContent: 'space-between', children: [row, Box({ flexShrink: 0, children: trailing })] });
72
+ }
73
+ export const ListItem = hostComponent('ListItem', ({ onOpenChange, ...props }) => ({ ...props, ...(onOpenChange === undefined || props.isOpen === undefined ? {} : { onToggle: () => onOpenChange(props.isOpen !== true) }) }), (props) => {
74
+ const { key, label, description, leading, trailing, tone, isSelected, depth, onPress } = props;
75
+ if (depth !== undefined)
76
+ return treeRow(props);
77
+ const shown = [...statusOf(tone), ...(leading === undefined ? [] : [Text({ dimColor: true, children: `${leading} ` })]), label, ...(description === undefined ? [] : [Text({ dimColor: true, children: ` ${description}` })]), ...(trailing === undefined ? [] : [' ', trailing])];
67
78
  if (isSelected === true || onPress === undefined)
68
79
  return Box({ ...(isSelected === true ? { backgroundColor: 'userMessageBackground' } : {}), paddingX: 1, children: Text({ wrap: 'truncate-end', ...(isSelected === true ? { bold: true } : {}), children: shown }) });
69
80
  return Box({ paddingX: 1, children: Button({ plain: true, dimColor: true, key, onPress, children: shown }) });