@poodle64/ui 2026.11.8 → 2026.11.10

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/README.md CHANGED
@@ -1076,15 +1076,30 @@ stays for a dense grid of data; a module's own records are a RecordList.
1076
1076
  | --- | --- |
1077
1077
  | `rows` | `RecordListRow`s: `id`, `title`, `note`, `image` (a thumbnail), `icon` (a row's own tile, for a tool), `flags` (what wants the viewer: the first a chip on line two with "+N more" naming the rest, every one on a phone). |
1078
1078
  | `columns` | The module's columns after the title, the Ledger's `ListColumn` shape plus `total`. List `title` to rename, resize or draw it with `cell`. `on: 'wide'` ticks a column only on a wide list (1200px of list), so extra width shows more columns and the viewer can tick it back. |
1079
- | `preferences`, `onPreferencesChange`, `preferencesNote` | The viewer's `{ columns }` from the Columns menu, which the bar carries while the list has heads. The list stores nothing. |
1079
+ | `preferences`, `onPreferencesChange`, `preferencesNote` | The viewer's `{ columns, group }` from the Columns menu, which the bar carries while the list has heads or offers groupings. Missing or stale fields take the module's defaults; `group` exists only where the list offers `groupings`. The list stores nothing. |
1080
1080
  | `title`, `meta`, `leading`, `toolbar`, `tools`, `action` | The `ListToolbar`. No title, no bar. |
1081
1081
  | `group` | A row's group label: groups show in the order their first rows come, each label on the ground with its count and each column's `total` over its rows. |
1082
+ | `groupings` | The ways the viewer may group, in place of `group`: `{ key, label, group, order, hint }`, offered in the Columns menu's Group by with None after the last, the first the default. `order: 'label'` lists the groups A to Z (numerals as numbers) rather than in the order their first rows come; `hint` says what it does under the choice. |
1082
1083
  | `totalLabel` | A card after the rows with each column's `total` over every row: "All three". |
1083
1084
  | `head` | `false` drops the head card (and the Columns menu): a tools list. |
1084
1085
  | `icon` | The quiet tile a row without a photo or its own `icon` shows; with it every row has a thumbnail. |
1085
1086
  | `href`, `onOpen`, `open` | A row is a link, or a button that opens a detail beside the list; `open` marks that row. A control in a `cell` takes its own click. |
1086
1087
  | `noun`, `empty`, `footer`, `layout` | As the Ledger's. |
1087
1088
 
1089
+ **The Columns menu is the one place a list is reshaped**, the same in the Ledger
1090
+ and the RecordList: the columns to tick, then Group by (the Ledger's periods, a
1091
+ RecordList's `groupings`), then Reset and where the choice is kept. Sort is the
1092
+ heads'; Find (search, filters, views) stays the module's.
1093
+
1094
+ ```svelte
1095
+ <RecordList rows={words} {columns} title="Words" bind:preferences
1096
+ groupings={[
1097
+ { key: 'letter', label: 'Letter', group: (r) => letterOf(r.title) },
1098
+ { key: 'becomes', label: 'Replacement', group: (r) => r.value, order: 'label',
1099
+ hint: 'Every word that becomes the same replacement, under it.' }
1100
+ ]} />
1101
+ ```
1102
+
1088
1103
  A sort orders rows inside their groups, largest first (words from A), then
1089
1104
  reversed, then the list's own order. On a phone (below 480px of list) a row is its thumbnail, title
1090
1105
  and lines, with the first end-aligned column's value beside the title. Measured
@@ -1531,15 +1546,15 @@ so it runs in a load function as happily as in a component.
1531
1546
 
1532
1547
  | Function | What it does |
1533
1548
  | -------------------------------------- | -------------------------------------------------------------------------------------------------- |
1534
- | `formatCurrency(dollars, opts)` | `$1,234.56`. `decimals` (default 2), `currency` (default AUD), `fallback`. |
1549
+ | `formatCurrency(dollars, opts)` | `$1,234.56`. `decimals` (default 2) or `minDecimals`/`maxDecimals` (`$1.50`, `$1.2346`), `currency` (default AUD), `fallback`. |
1535
1550
  | `formatCurrencyFromCents(cents, opts)` | The same, for money stored as integer cents. |
1536
1551
  | `formatCurrencyString(str, opts)` | Groups a money STRING without ever parsing it to a float — for a figure that reaches a tax return. |
1537
1552
  | `compactCurrency(value, opts)` | `$1.1m` / `$12k`, for a chart axis or a dense tile. |
1538
1553
  | `isNegativeMoney(value)` | The sign, without a parse, for choosing a tone class. |
1539
1554
  | `dollarsToCents(dollars)` | Whole cents. |
1540
- | `formatNumber(value, opts)` | `1,234,567`. |
1555
+ | `formatNumber(value, opts)` | `1,234,567`. `maxDecimals: 8` trims a quantity (`0.125`). |
1541
1556
  | `formatPercentage(value, opts)` | Value is already in percentage POINTS: `4.5` → `4.5%`. |
1542
- | `formatRatioAsPercentage(value, opts)` | Value is a 0–1 RATIO: `0.045` → `4.5%`. |
1557
+ | `formatRatioAsPercentage(value, opts)` | Value is a 0–1 RATIO: `0.045` → `4.5%`; `maxDecimals: 2` trims `0.5` → `50%`. |
1543
1558
  | `formatDate(value, opts)` | `19 Dec 2024`, `19 December 2024` (`format: 'long'`) or `19/12/2024` (`format: 'numeric'`). |
1544
1559
  | `formatDateTime(value, opts)` | The same plus a 24-hour time: `19 Dec 2024, 14:05`. |
1545
1560
  | `parseApiDate(iso)` | Reads an offset-less timestamp as UTC — the naive-UTC backend trap below. |
@@ -1,32 +1,44 @@
1
- <script lang="ts" generics="P extends { columns: string[]; period?: LedgerPeriod }">
1
+ <script lang="ts" generics="G extends string">
2
2
  /**
3
- * The viewer's Columns menu: every column the module offers as a tick (the
4
- * ledger's running balance one more, always last), then, where the list
5
- * groups by a period, the period. An icon button named by its tooltip.
6
- * The RecordList's menu is this one without the period.
3
+ * The list's Columns menu, the one place a viewer reshapes a list: every
4
+ * column it offers as a tick, then how its rows group. The Ledger's groups
5
+ * are periods (and its running balance one more column, always last); a
6
+ * RecordList's are the groupings its module offers. Sort is the heads'. An
7
+ * icon button named by its tooltip.
7
8
  */
8
9
  import Columns3 from '@lucide/svelte/icons/columns-3';
9
10
  import { Button, buttonVariants } from '../button/index.js';
10
11
  import { Checkbox } from '../checkbox/index.js';
11
12
  import * as Popover from '../popover/index.js';
12
- import { Segmented } from '../segmented/index.js';
13
+ import { Segmented, type SegmentedOption } from '../segmented/index.js';
13
14
  import * as Tooltip from '../tooltip/index.js';
14
15
  import { cn } from '../../../utils.js';
15
- import { LEDGER_PERIODS } from './ledger.js';
16
- import type { LedgerPeriod } from './types.js';
17
16
 
18
17
  let {
19
18
  offered,
20
- preferences,
19
+ columns,
20
+ grouping,
21
+ name,
21
22
  note,
22
- onchange,
23
+ oncolumns,
23
24
  onreset,
24
25
  owner = 'ledger'
25
26
  }: {
27
+ /** The columns to tick; none, and the menu holds only the grouping. */
26
28
  offered: { key: string; label: string; locked: boolean }[];
27
- preferences: P;
29
+ /** The ticked columns' keys. */
30
+ columns: string[];
31
+ /** How the rows group: the choices, the one in force, and what it does. */
32
+ grouping?: {
33
+ options: readonly SegmentedOption<G>[];
34
+ value: G;
35
+ hint?: string;
36
+ onchange: (value: G) => void;
37
+ };
38
+ /** The trigger's tooltip and accessible name. */
39
+ name: string;
28
40
  note?: string;
29
- onchange: (next: P) => void;
41
+ oncolumns: (columns: string[]) => void;
30
42
  onreset: () => void;
31
43
  /** The `data-slot` prefix: the list that owns the menu. */
32
44
  owner?: string;
@@ -34,26 +46,14 @@
34
46
 
35
47
  let open = $state(false);
36
48
 
37
- const HINT: Record<LedgerPeriod, string> = {
38
- fy: 'Each financial year sits under its own header, which opens and closes.',
39
- cy: 'Each calendar year sits under its own header, which opens and closes.',
40
- month: 'Each month sits under its own header, which opens and closes.',
41
- week: 'Each week sits under its own header, which opens and closes.',
42
- day: 'The date heads each day’s rows, so the Date column goes.',
43
- none: 'One list, newest first, under the column head.'
44
- };
45
-
46
49
  function tick(key: string, on: boolean) {
47
- const next = on ? [...preferences.columns, key] : preferences.columns.filter((k) => k !== key);
48
- onchange({
49
- ...preferences,
50
- columns: offered.map((c) => c.key).filter((k) => next.includes(k))
51
- });
50
+ const next = on ? [...columns, key] : columns.filter((k) => k !== key);
51
+ oncolumns(offered.map((c) => c.key).filter((k) => next.includes(k)));
52
52
  }
53
53
 
54
54
  const eyebrow = 'text-muted-foreground text-2xs tracking-eyebrow font-semibold uppercase';
55
- /** The ledger's menu also holds its running balance and its grouping. */
56
- const name = $derived(preferences.period ? 'Columns, balance and grouping' : 'Columns');
55
+ /** Two to a row past three choices, so a label never truncates in the menu's width. */
56
+ const COLS = ['grid-cols-1', 'grid-cols-2', 'grid-cols-3'];
57
57
  </script>
58
58
 
59
59
  <Popover.Root bind:open>
@@ -75,36 +75,42 @@
75
75
  </Tooltip.Root>
76
76
  </Tooltip.Provider>
77
77
  <Popover.Content align="end" class="w-80 p-0" data-slot="{owner}-columns">
78
- <div class="flex flex-col px-2 pt-2.5 pb-2">
79
- <span class={cn(eyebrow, 'px-1.5 pb-1.5')}>Columns</span>
80
- {#each offered as c (c.key)}
81
- {@const on = c.locked || preferences.columns.includes(c.key)}
82
- <label
83
- class={cn(
84
- 'flex min-h-8 items-center gap-2.5 rounded-md px-1.5 text-sm',
85
- c.locked ? 'text-muted-foreground' : 'hover:bg-accent/50 cursor-pointer'
86
- )}
87
- >
88
- <Checkbox
89
- checked={on}
90
- disabled={c.locked}
91
- onCheckedChange={(v) => tick(c.key, v === true)}
92
- />
93
- <span class="min-w-0 flex-1">{c.label}</span>
94
- {#if c.locked}<span class="text-xs">Always shown</span>{/if}
95
- </label>
96
- {/each}
97
- </div>
98
- {#if preferences.period}
99
- <div class="border-border flex flex-col gap-2 border-t px-3.5 pt-2.5 pb-3">
78
+ {#if offered.length}
79
+ <div class="flex flex-col px-2 pt-2.5 pb-2">
80
+ <span class={cn(eyebrow, 'px-1.5 pb-1.5')}>Columns</span>
81
+ {#each offered as c (c.key)}
82
+ {@const on = c.locked || columns.includes(c.key)}
83
+ <label
84
+ class={cn(
85
+ 'flex min-h-8 items-center gap-2.5 rounded-md px-1.5 text-sm',
86
+ c.locked ? 'text-muted-foreground' : 'hover:bg-accent/50 cursor-pointer'
87
+ )}
88
+ >
89
+ <Checkbox
90
+ checked={on}
91
+ disabled={c.locked}
92
+ onCheckedChange={(v) => tick(c.key, v === true)}
93
+ />
94
+ <span class="min-w-0 flex-1">{c.label}</span>
95
+ {#if c.locked}<span class="text-xs">Always shown</span>{/if}
96
+ </label>
97
+ {/each}
98
+ </div>
99
+ {/if}
100
+ {#if grouping}
101
+ {@const g = grouping}
102
+ <div
103
+ class={cn('flex flex-col gap-2 px-3.5 pt-2.5 pb-3', offered.length && 'border-border border-t')}
104
+ data-slot="{owner}-grouping"
105
+ >
100
106
  <span class={eyebrow}>Group by</span>
101
107
  <Segmented
102
108
  label="Group by"
103
- options={LEDGER_PERIODS}
104
- bind:value={() => preferences.period!, (period) => onchange({ ...preferences, period })}
105
- class="grid w-full grid-cols-2"
109
+ options={g.options}
110
+ bind:value={() => g.value, (value) => g.onchange(value)}
111
+ class={cn('grid w-full', COLS[g.options.length - 1] ?? 'grid-cols-2')}
106
112
  />
107
- <span class="text-muted-foreground text-xs">{HINT[preferences.period]}</span>
113
+ {#if g.hint}<span class="text-muted-foreground text-xs">{g.hint}</span>{/if}
108
114
  </div>
109
115
  {/if}
110
116
  <div class="bg-surface-2 border-border flex items-center gap-2 border-t py-2 pr-2 pl-3.5">
@@ -1,17 +1,25 @@
1
- import type { LedgerPeriod } from './types.js';
2
- declare function $$render<P extends {
3
- columns: string[];
4
- period?: LedgerPeriod;
5
- }>(): {
1
+ import { type SegmentedOption } from '../segmented/index.js';
2
+ declare function $$render<G extends string>(): {
6
3
  props: {
4
+ /** The columns to tick; none, and the menu holds only the grouping. */
7
5
  offered: {
8
6
  key: string;
9
7
  label: string;
10
8
  locked: boolean;
11
9
  }[];
12
- preferences: P;
10
+ /** The ticked columns' keys. */
11
+ columns: string[];
12
+ /** How the rows group: the choices, the one in force, and what it does. */
13
+ grouping?: {
14
+ options: readonly SegmentedOption<G>[];
15
+ value: G;
16
+ hint?: string;
17
+ onchange: (value: G) => void;
18
+ };
19
+ /** The trigger's tooltip and accessible name. */
20
+ name: string;
13
21
  note?: string;
14
- onchange: (next: P) => void;
22
+ oncolumns: (columns: string[]) => void;
15
23
  onreset: () => void;
16
24
  /** The `data-slot` prefix: the list that owns the menu. */
17
25
  owner?: string;
@@ -21,32 +29,20 @@ declare function $$render<P extends {
21
29
  slots: {};
22
30
  events: {};
23
31
  };
24
- declare class __sveltets_Render<P extends {
25
- columns: string[];
26
- period?: LedgerPeriod;
27
- }> {
28
- props(): ReturnType<typeof $$render<P>>['props'];
29
- events(): ReturnType<typeof $$render<P>>['events'];
30
- slots(): ReturnType<typeof $$render<P>>['slots'];
32
+ declare class __sveltets_Render<G extends string> {
33
+ props(): ReturnType<typeof $$render<G>>['props'];
34
+ events(): ReturnType<typeof $$render<G>>['events'];
35
+ slots(): ReturnType<typeof $$render<G>>['slots'];
31
36
  bindings(): "";
32
37
  exports(): {};
33
38
  }
34
39
  interface $$IsomorphicComponent {
35
- new <P extends {
36
- columns: string[];
37
- period?: LedgerPeriod;
38
- }>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<P>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<P>['props']>, ReturnType<__sveltets_Render<P>['events']>, ReturnType<__sveltets_Render<P>['slots']>> & {
39
- $$bindings?: ReturnType<__sveltets_Render<P>['bindings']>;
40
- } & ReturnType<__sveltets_Render<P>['exports']>;
41
- <P extends {
42
- columns: string[];
43
- period?: LedgerPeriod;
44
- }>(internal: unknown, props: ReturnType<__sveltets_Render<P>['props']> & {}): ReturnType<__sveltets_Render<P>['exports']>;
40
+ new <G extends string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<G>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<G>['props']>, ReturnType<__sveltets_Render<G>['events']>, ReturnType<__sveltets_Render<G>['slots']>> & {
41
+ $$bindings?: ReturnType<__sveltets_Render<G>['bindings']>;
42
+ } & ReturnType<__sveltets_Render<G>['exports']>;
43
+ <G extends string>(internal: unknown, props: ReturnType<__sveltets_Render<G>['props']> & {}): ReturnType<__sveltets_Render<G>['exports']>;
45
44
  z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
46
45
  }
47
46
  declare const LedgerColumns: $$IsomorphicComponent;
48
- type LedgerColumns<P extends {
49
- columns: string[];
50
- period?: LedgerPeriod;
51
- }> = InstanceType<typeof LedgerColumns<P>>;
47
+ type LedgerColumns<G extends string> = InstanceType<typeof LedgerColumns<G>>;
52
48
  export default LedgerColumns;
@@ -61,7 +61,13 @@
61
61
  windowOf
62
62
  } from './ledger.js';
63
63
  import type { LedgerDateFormat } from './ledger.js';
64
- import type { LedgerColumn, LedgerOpenContext, LedgerPreferences, LedgerRow } from './types.js';
64
+ import type {
65
+ LedgerColumn,
66
+ LedgerOpenContext,
67
+ LedgerPeriod,
68
+ LedgerPreferences,
69
+ LedgerRow
70
+ } from './types.js';
65
71
 
66
72
  type Id = R['id'];
67
73
 
@@ -215,6 +221,14 @@
215
221
  preferences = next;
216
222
  onPreferencesChange?.(next);
217
223
  }
224
+ const PERIOD_HINT: Record<LedgerPeriod, string> = {
225
+ fy: 'Each financial year sits under its own header, which opens and closes.',
226
+ cy: 'Each calendar year sits under its own header, which opens and closes.',
227
+ month: 'Each month sits under its own header, which opens and closes.',
228
+ week: 'Each week sits under its own header, which opens and closes.',
229
+ day: 'The date heads each day’s rows, so the Date column goes.',
230
+ none: 'One list, newest first, under the column head.'
231
+ };
218
232
 
219
233
  // ── Layout ──
220
234
  let width = $state(0);
@@ -872,9 +886,16 @@
872
886
  >
873
887
  <LedgerColumns
874
888
  offered={resolved.map((c) => ({ key: c.key, label: c.label, locked: c.locked }))}
875
- preferences={prefs}
889
+ columns={prefs.columns}
890
+ grouping={{
891
+ options: LEDGER_PERIODS,
892
+ value: prefs.period,
893
+ hint: PERIOD_HINT[prefs.period],
894
+ onchange: (period) => setPreferences({ ...prefs, period })
895
+ }}
896
+ name="Columns, balance and grouping"
876
897
  note={preferencesNote}
877
- onchange={setPreferences}
898
+ oncolumns={(columns) => setPreferences({ ...prefs, columns })}
878
899
  onreset={() => setPreferences(defaults)}
879
900
  />
880
901
  {@render actions?.()}
@@ -1,3 +1,3 @@
1
1
  export { default as RecordList } from './record-list.svelte';
2
2
  export { default } from './record-list.svelte';
3
- export type { RecordFlag, RecordListColumn, RecordListPreferences, RecordListRow } from './types.js';
3
+ export type { RecordFlag, RecordListColumn, RecordListGrouping, RecordListPreferences, RecordListRow } from './types.js';
@@ -11,6 +11,10 @@
11
11
  * then the module's columns. It opens by its link (`href`) or by `onOpen`,
12
12
  * which marks the row `open` names, for a detail beside the list.
13
13
  *
14
+ * The module groups the rows one way (`group`), or offers the viewer ways
15
+ * to (`groupings`), chosen in the Columns menu beside the columns, as the
16
+ * Ledger's periods are.
17
+ *
14
18
  * It fills its parent's height and scrolls its own rows, so the head card
15
19
  * stays at the top: give it a bounded parent (`flex-1 min-h-0`). Width picks
16
20
  * the layout, as the Ledger's does: a phone's list below 480px, the wide
@@ -46,7 +50,12 @@
46
50
  import type { IconComponent } from '../app-shell/types.js';
47
51
  import Thumbnail from './thumbnail.svelte';
48
52
  import { cn } from '../../../utils.js';
49
- import type { RecordListColumn, RecordListPreferences, RecordListRow } from './types.js';
53
+ import type {
54
+ RecordListColumn,
55
+ RecordListGrouping,
56
+ RecordListPreferences,
57
+ RecordListRow
58
+ } from './types.js';
50
59
 
51
60
  type Id = R['id'];
52
61
 
@@ -64,6 +73,7 @@
64
73
  tools = [],
65
74
  action,
66
75
  group,
76
+ groupings = [],
67
77
  totalLabel,
68
78
  head = true,
69
79
  icon,
@@ -79,7 +89,7 @@
79
89
  rows: readonly R[];
80
90
  /** The module's columns, in order after the title. See `RecordListColumn`. */
81
91
  columns?: RecordListColumn<R>[];
82
- /** The viewer's columns. Missing, the module's defaults. */
92
+ /** The viewer's columns and grouping. Missing, the module's defaults. */
83
93
  preferences?: Partial<RecordListPreferences>;
84
94
  onPreferencesChange?: (next: RecordListPreferences) => void;
85
95
  /** The Columns menu's footnote: where the choice is kept. */
@@ -99,6 +109,11 @@
99
109
  action?: ListAction;
100
110
  /** A row's group, by its label: groups show in the order their first rows come. */
101
111
  group?: (row: R) => string;
112
+ /**
113
+ * The ways the viewer can group, in the Columns menu with None after
114
+ * them; the first is the default. In place of `group`.
115
+ */
116
+ groupings?: RecordListGrouping<R>[];
102
117
  /** Names a card after the rows with each column's total over every row: "All three". */
103
118
  totalLabel?: string;
104
119
  /** The head card. A list whose columns need no heads drops it. */
@@ -152,20 +167,43 @@
152
167
  const WIDE = $derived(mode === 'wide');
153
168
  const PHONE = $derived(mode === 'phone');
154
169
 
170
+ const NONE = 'none';
155
171
  const defaults = $derived<RecordListPreferences>({
156
172
  columns: resolved
157
173
  .filter((c) => !c.locked && (c.on === true || (c.on === 'wide' && WIDE)))
158
- .map((c) => c.key)
174
+ .map((c) => c.key),
175
+ ...(groupings[0] ? { group: groupings[0].key } : {})
159
176
  });
160
- const prefs = $derived<RecordListPreferences>({
161
- columns: preferences?.columns ?? defaults.columns
177
+ /** What the consumer kept, read field by field: a stale or foreign key falls back. */
178
+ const prefs = $derived.by<RecordListPreferences>(() => {
179
+ const columns = preferences?.columns ?? defaults.columns;
180
+ if (!groupings.length) return { columns };
181
+ const kept = preferences?.group;
182
+ const known = kept === NONE || groupings.some((g) => g.key === kept);
183
+ return { columns, group: known && kept ? kept : defaults.group };
162
184
  });
163
185
  function setPreferences(next: RecordListPreferences) {
164
186
  preferences = next;
165
187
  onPreferencesChange?.(next);
166
188
  }
167
- /** The Columns menu, in the bar, when the heads name a column the viewer can choose. */
189
+ /** The grouping in force: the viewer's, else the module's one way. */
190
+ const grouping = $derived<Pick<RecordListGrouping<R>, 'group' | 'order'> | undefined>(
191
+ groupings.length ? groupings.find((g) => g.key === prefs.group) : group && { group }
192
+ );
193
+ /** Columns to tick, while the heads name a column the viewer can choose. */
168
194
  const choosable = $derived(head && resolved.some((c) => !c.locked));
195
+ const menuName = $derived(
196
+ groupings.length ? (choosable ? 'Columns and grouping' : 'Grouping') : 'Columns'
197
+ );
198
+ const groupingOptions = $derived([
199
+ ...groupings.map((g) => ({ value: g.key, label: g.label })),
200
+ { value: NONE, label: 'None' }
201
+ ]);
202
+ const groupingHint = $derived(
203
+ prefs.group === NONE
204
+ ? 'One list, without groups.'
205
+ : groupings.find((g) => g.key === prefs.group)?.hint
206
+ );
169
207
 
170
208
  const shown = $derived(resolved.filter((c) => c.locked || prefs.columns.includes(c.key)));
171
209
  const template = $derived(shown.map((c) => (WIDE ? c.track.wide : c.track.narrow)).join(' '));
@@ -199,15 +237,22 @@
199
237
  return sort && col && sorter(col) ? sort : null;
200
238
  });
201
239
 
202
- // ── Groups, in the order their first rows come; a sort orders rows inside them ──
240
+ // ── Groups, in the order their first rows come or by label; a sort orders rows inside them ──
203
241
  const groups = $derived.by(() => {
204
242
  const out: { key: string; rows: R[] }[] = [];
243
+ const byKey = new Map<string, R[]>();
205
244
  for (const r of rows) {
206
- const key = group ? group(r) : '';
207
- const g = out.find((x) => x.key === key);
208
- if (g) g.rows.push(r);
209
- else out.push({ key, rows: [r] });
245
+ const key = grouping ? grouping.group(r) : '';
246
+ const g = byKey.get(key);
247
+ if (g) g.push(r);
248
+ else {
249
+ const fresh = [r];
250
+ byKey.set(key, fresh);
251
+ out.push({ key, rows: fresh });
252
+ }
210
253
  }
254
+ if (grouping?.order === 'label')
255
+ out.sort((a, b) => a.key.localeCompare(b.key, undefined, { numeric: true, sensitivity: 'base' }));
211
256
  const col = activeSort && shown.find((c) => c.key === activeSort.key);
212
257
  const by = col && sorter(col);
213
258
  return by ? out.map((g) => ({ key: g.key, rows: orderBy(g.rows, by, activeSort!.dir) })) : out;
@@ -381,12 +426,23 @@
381
426
  {action}
382
427
  style="padding-right: {edge};"
383
428
  >
384
- {#if choosable}
429
+ {#if choosable || groupings.length}
385
430
  <LedgerColumns
386
- offered={resolved.map((c) => ({ key: c.key, label: c.label, locked: c.locked }))}
387
- preferences={prefs}
431
+ offered={choosable
432
+ ? resolved.map((c) => ({ key: c.key, label: c.label, locked: c.locked }))
433
+ : []}
434
+ columns={prefs.columns}
435
+ grouping={groupings.length
436
+ ? {
437
+ options: groupingOptions,
438
+ value: prefs.group ?? NONE,
439
+ hint: groupingHint,
440
+ onchange: (group) => setPreferences({ ...prefs, group })
441
+ }
442
+ : undefined}
443
+ name={menuName}
388
444
  note={preferencesNote}
389
- onchange={setPreferences}
445
+ oncolumns={(columns) => setPreferences({ ...prefs, columns })}
390
446
  onreset={() => setPreferences(defaults)}
391
447
  owner="record"
392
448
  />
@@ -427,7 +483,7 @@
427
483
  {#if empty}{@render empty()}{:else}<EmptyState title="No {noun[1]}" />{/if}
428
484
  {:else}
429
485
  {#each groups as g, gi (g.key)}
430
- {#if group}
486
+ {#if grouping}
431
487
  <div class={groupSpacing(gi)}>
432
488
  <div
433
489
  class={cn(GROUP, PHONE ? 'flex items-center gap-2 px-0.5' : 'grid items-center')}
@@ -10,6 +10,10 @@
10
10
  * then the module's columns. It opens by its link (`href`) or by `onOpen`,
11
11
  * which marks the row `open` names, for a detail beside the list.
12
12
  *
13
+ * The module groups the rows one way (`group`), or offers the viewer ways
14
+ * to (`groupings`), chosen in the Columns menu beside the columns, as the
15
+ * Ledger's periods are.
16
+ *
13
17
  * It fills its parent's height and scrolls its own rows, so the head card
14
18
  * stays at the top: give it a bounded parent (`flex-1 min-h-0`). Width picks
15
19
  * the layout, as the Ledger's does: a phone's list below 480px, the wide
@@ -21,13 +25,13 @@ import type { Snippet } from 'svelte';
21
25
  import type { HTMLAttributes } from 'svelte/elements';
22
26
  import type { ListAction, ListIconAction } from '../list-toolbar/types.js';
23
27
  import type { IconComponent } from '../app-shell/types.js';
24
- import type { RecordListColumn, RecordListPreferences, RecordListRow } from './types.js';
28
+ import type { RecordListColumn, RecordListGrouping, RecordListPreferences, RecordListRow } from './types.js';
25
29
  declare function $$render<R extends RecordListRow>(): {
26
30
  props: Omit<HTMLAttributes<HTMLDivElement>, "title"> & {
27
31
  rows: readonly R[];
28
32
  /** The module's columns, in order after the title. See `RecordListColumn`. */
29
33
  columns?: RecordListColumn<R>[];
30
- /** The viewer's columns. Missing, the module's defaults. */
34
+ /** The viewer's columns and grouping. Missing, the module's defaults. */
31
35
  preferences?: Partial<RecordListPreferences>;
32
36
  onPreferencesChange?: (next: RecordListPreferences) => void;
33
37
  /** The Columns menu's footnote: where the choice is kept. */
@@ -47,6 +51,11 @@ declare function $$render<R extends RecordListRow>(): {
47
51
  action?: ListAction;
48
52
  /** A row's group, by its label: groups show in the order their first rows come. */
49
53
  group?: (row: R) => string;
54
+ /**
55
+ * The ways the viewer can group, in the Columns menu with None after
56
+ * them; the first is the default. In place of `group`.
57
+ */
58
+ groupings?: RecordListGrouping<R>[];
50
59
  /** Names a card after the rows with each column's total over every row: "All three". */
51
60
  totalLabel?: string;
52
61
  /** The head card. A list whose columns need no heads drops it. */
@@ -33,8 +33,30 @@ export interface RecordListColumn<R extends RecordListRow = RecordListRow> exten
33
33
  /** The column's total over some rows: each group's on its label, all rows' in the total card. */
34
34
  total?: (rows: readonly R[]) => string;
35
35
  }
36
+ /**
37
+ * A way the viewer can group the list, offered in its Columns menu with None
38
+ * after the last: the first letter, a status, every word that becomes the same
39
+ * replacement.
40
+ */
41
+ export interface RecordListGrouping<R extends RecordListRow = RecordListRow> {
42
+ /** What the viewer's choice keeps. `none` is the list's own and never a grouping's. */
43
+ key: string;
44
+ /** Its name in the menu. */
45
+ label: string;
46
+ /** A row's group, by its label. */
47
+ group: (row: R) => string;
48
+ /**
49
+ * The groups' order: `rows`, the order their first rows come (the
50
+ * default); `label`, A to Z by label, numerals as numbers.
51
+ */
52
+ order?: 'rows' | 'label';
53
+ /** Under the menu's choice: what the grouping does. */
54
+ hint?: string;
55
+ }
36
56
  /** The viewer's own choices, which the consumer persists. */
37
57
  export interface RecordListPreferences {
38
58
  /** The ticked columns' keys. */
39
59
  columns: string[];
60
+ /** The chosen grouping's key, or `none`; only on a list that offers groupings. */
61
+ group?: string;
40
62
  }
package/dist/format.d.ts CHANGED
@@ -45,13 +45,22 @@
45
45
  export declare const AU_LOCALE = "en-AU";
46
46
  /** The one timezone the household's records are kept in. */
47
47
  export declare const AU_TIME_ZONE = "Australia/Brisbane";
48
- export interface CurrencyOptions {
48
+ /** Fraction-digit options every numeric formatter shares. */
49
+ export interface DecimalRange {
50
+ /** Exactly this many fraction digits (min and max both). */
51
+ decimals?: number;
52
+ /** At least this many; with `maxDecimals`, trailing zeros between the two are trimmed. */
53
+ minDecimals?: number;
54
+ /** At most this many. */
55
+ maxDecimals?: number;
56
+ }
57
+ export interface CurrencyOptions extends DecimalRange {
49
58
  /**
50
- * Fraction digits. Defaults to 2: dropping cents is a loss of fidelity the
51
- * caller should have to ask for, not the default that quietly rounds
59
+ * Fraction digits (`decimals`; `minDecimals`/`maxDecimals` for a range, a
60
+ * unit price's 2 to 4). Defaults to 2: dropping cents is a loss of fidelity
61
+ * the caller should have to ask for, not the default that quietly rounds
52
62
  * $1,234.56 up to $1,235. Pass `0` for a dashboard figure.
53
63
  */
54
- decimals?: number;
55
64
  /** Rendered when the value is null, undefined, empty or not a number. */
56
65
  fallback?: string;
57
66
  /**
@@ -77,6 +86,8 @@ export interface CurrencyOptions {
77
86
  * formatCurrency('1234.56', { decimals: 0 }) // '$1,235'
78
87
  * formatCurrency(-500, { decimals: 0 }) // '-$500'
79
88
  * formatCurrency(-500, { negative: 'brackets' }) // '($500.00)'
89
+ * formatCurrency(1.5, { minDecimals: 2, maxDecimals: 4 }) // '$1.50'
90
+ * formatCurrency(1.23456, { minDecimals: 2, maxDecimals: 4 }) // '$1.2346'
80
91
  * formatCurrency(null) // 'N/A'
81
92
  */
82
93
  export declare function formatCurrency(value: string | number | null | undefined, options?: CurrencyOptions): string;
@@ -141,10 +152,10 @@ export declare function isNegativeMoney(value: string | number | null | undefine
141
152
  * @example
142
153
  * formatNumber(1234567) // '1,234,567'
143
154
  * formatNumber(1234.567, { decimals: 2 }) // '1,234.57'
155
+ * formatNumber(0.125, { maxDecimals: 8 }) // '0.125'
144
156
  * formatNumber(null) // 'N/A'
145
157
  */
146
- export declare function formatNumber(value: number | string | null | undefined, options?: {
147
- decimals?: number;
158
+ export declare function formatNumber(value: number | string | null | undefined, options?: DecimalRange & {
148
159
  fallback?: string;
149
160
  }): string;
150
161
  /**
@@ -158,10 +169,10 @@ export declare function formatNumber(value: number | string | null | undefined,
158
169
  * @example
159
170
  * formatPercentage(4.5) // '4.5%'
160
171
  * formatPercentage('4.5', { decimals: 2 }) // '4.50%'
172
+ * formatPercentage(4.5, { maxDecimals: 2 }) // '4.5%'
161
173
  * formatPercentage(null) // 'N/A'
162
174
  */
163
- export declare function formatPercentage(value: number | string | null | undefined, options?: {
164
- decimals?: number;
175
+ export declare function formatPercentage(value: number | string | null | undefined, options?: DecimalRange & {
165
176
  fallback?: string;
166
177
  }): string;
167
178
  /**
@@ -170,10 +181,10 @@ export declare function formatPercentage(value: number | string | null | undefin
170
181
  * @example
171
182
  * formatRatioAsPercentage(0.045) // '4.5%'
172
183
  * formatRatioAsPercentage(1) // '100.0%'
184
+ * formatRatioAsPercentage(0.5, { maxDecimals: 2 }) // '50%'
173
185
  * formatRatioAsPercentage(null) // 'N/A'
174
186
  */
175
- export declare function formatRatioAsPercentage(value: number | string | null | undefined, options?: {
176
- decimals?: number;
187
+ export declare function formatRatioAsPercentage(value: number | string | null | undefined, options?: DecimalRange & {
177
188
  fallback?: string;
178
189
  }): string;
179
190
  /** `19 Dec 2024`, `19 December 2024`, or `19/12/2024`. */
package/dist/format.js CHANGED
@@ -47,6 +47,33 @@ export const AU_LOCALE = 'en-AU';
47
47
  export const AU_TIME_ZONE = 'Australia/Brisbane';
48
48
  /** What a formatter renders when it has nothing to render. */
49
49
  const FALLBACK = 'N/A';
50
+ /**
51
+ * Resolve a `DecimalRange` to a [min, max] pair. `decimals` alone (or nothing:
52
+ * `fallbackDecimals`) pins both, so every caller that predates the range reads
53
+ * as it did. Given a range, an omitted `minDecimals` is `decimals` if set, else
54
+ * `defaultMin` (0 for a quantity or a percent, 2 for money, which keeps cents).
55
+ */
56
+ function resolveDecimals(options, fallbackDecimals, defaultMin) {
57
+ const { decimals, minDecimals, maxDecimals } = options;
58
+ if (minDecimals === undefined && maxDecimals === undefined) {
59
+ const n = decimals ?? fallbackDecimals;
60
+ return [n, n];
61
+ }
62
+ const min = minDecimals ?? decimals ?? defaultMin;
63
+ const max = maxDecimals ?? Math.max(decimals ?? fallbackDecimals, min);
64
+ return [Math.min(min, max), max];
65
+ }
66
+ /** `toFixed(max)` with trailing zeros trimmed down to `min` fraction digits. */
67
+ function toTrimmedFixed(num, min, max) {
68
+ const fixed = num.toFixed(max);
69
+ if (max <= min)
70
+ return fixed;
71
+ const [int, frac = ''] = fixed.split('.');
72
+ let end = frac.length;
73
+ while (end > min && frac[end - 1] === '0')
74
+ end--;
75
+ return end > 0 ? `${int}.${frac.slice(0, end)}` : int;
76
+ }
50
77
  /**
51
78
  * Coerce an API value to a finite number, or null.
52
79
  *
@@ -73,18 +100,21 @@ function toFiniteNumber(value) {
73
100
  * formatCurrency('1234.56', { decimals: 0 }) // '$1,235'
74
101
  * formatCurrency(-500, { decimals: 0 }) // '-$500'
75
102
  * formatCurrency(-500, { negative: 'brackets' }) // '($500.00)'
103
+ * formatCurrency(1.5, { minDecimals: 2, maxDecimals: 4 }) // '$1.50'
104
+ * formatCurrency(1.23456, { minDecimals: 2, maxDecimals: 4 }) // '$1.2346'
76
105
  * formatCurrency(null) // 'N/A'
77
106
  */
78
107
  export function formatCurrency(value, options = {}) {
79
- const { decimals = 2, fallback = FALLBACK, currency = 'AUD', negative = 'sign', locale = AU_LOCALE } = options;
108
+ const { fallback = FALLBACK, currency = 'AUD', negative = 'sign', locale = AU_LOCALE } = options;
80
109
  const num = toFiniteNumber(value);
81
110
  if (num === null)
82
111
  return fallback;
112
+ const [minDigits, maxDigits] = resolveDecimals(options, 2, 2);
83
113
  const format = new Intl.NumberFormat(locale, {
84
114
  style: 'currency',
85
115
  currency,
86
- minimumFractionDigits: decimals,
87
- maximumFractionDigits: decimals
116
+ minimumFractionDigits: minDigits,
117
+ maximumFractionDigits: maxDigits
88
118
  });
89
119
  if (negative !== 'brackets' || num >= 0)
90
120
  return format.format(num);
@@ -220,16 +250,18 @@ export function isNegativeMoney(value) {
220
250
  * @example
221
251
  * formatNumber(1234567) // '1,234,567'
222
252
  * formatNumber(1234.567, { decimals: 2 }) // '1,234.57'
253
+ * formatNumber(0.125, { maxDecimals: 8 }) // '0.125'
223
254
  * formatNumber(null) // 'N/A'
224
255
  */
225
256
  export function formatNumber(value, options = {}) {
226
- const { decimals = 0, fallback = FALLBACK } = options;
257
+ const { fallback = FALLBACK } = options;
227
258
  const num = toFiniteNumber(value);
228
259
  if (num === null)
229
260
  return fallback;
261
+ const [minDigits, maxDigits] = resolveDecimals(options, 0, 0);
230
262
  return new Intl.NumberFormat(AU_LOCALE, {
231
- minimumFractionDigits: decimals,
232
- maximumFractionDigits: decimals
263
+ minimumFractionDigits: minDigits,
264
+ maximumFractionDigits: maxDigits
233
265
  }).format(num);
234
266
  }
235
267
  /**
@@ -243,14 +275,16 @@ export function formatNumber(value, options = {}) {
243
275
  * @example
244
276
  * formatPercentage(4.5) // '4.5%'
245
277
  * formatPercentage('4.5', { decimals: 2 }) // '4.50%'
278
+ * formatPercentage(4.5, { maxDecimals: 2 }) // '4.5%'
246
279
  * formatPercentage(null) // 'N/A'
247
280
  */
248
281
  export function formatPercentage(value, options = {}) {
249
- const { decimals = 1, fallback = FALLBACK } = options;
282
+ const { fallback = FALLBACK } = options;
250
283
  const num = toFiniteNumber(value);
251
284
  if (num === null)
252
285
  return fallback;
253
- return `${num.toFixed(decimals)}%`;
286
+ const [minDigits, maxDigits] = resolveDecimals(options, 1, 0);
287
+ return `${toTrimmedFixed(num, minDigits, maxDigits)}%`;
254
288
  }
255
289
  /**
256
290
  * Format a 0–1 RATIO as a percentage: `0.045` renders `4.5%`.
@@ -258,14 +292,16 @@ export function formatPercentage(value, options = {}) {
258
292
  * @example
259
293
  * formatRatioAsPercentage(0.045) // '4.5%'
260
294
  * formatRatioAsPercentage(1) // '100.0%'
295
+ * formatRatioAsPercentage(0.5, { maxDecimals: 2 }) // '50%'
261
296
  * formatRatioAsPercentage(null) // 'N/A'
262
297
  */
263
298
  export function formatRatioAsPercentage(value, options = {}) {
264
- const { decimals = 1, fallback = FALLBACK } = options;
299
+ const { fallback = FALLBACK } = options;
265
300
  const num = toFiniteNumber(value);
266
301
  if (num === null)
267
302
  return fallback;
268
- return `${(num * 100).toFixed(decimals)}%`;
303
+ const [minDigits, maxDigits] = resolveDecimals(options, 1, 0);
304
+ return `${toTrimmedFixed(num * 100, minDigits, maxDigits)}%`;
269
305
  }
270
306
  // --------------------------------------------------------------------------- //
271
307
  // Dates and times //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poodle64/ui",
3
- "version": "2026.11.8",
3
+ "version": "2026.11.10",
4
4
  "description": "Household shared component layer: shadcn-svelte primitives (bits-ui) plus the composed page chrome every app builds its routes from, restyled by each app's @poodle64/design-tokens alias layer. One fix reaches every app.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "package": "@poodle64/ui",
4
- "version": "2026.11.8",
4
+ "version": "2026.11.10",
5
5
  "generatedBy": "scripts/generate-registry.mjs",
6
6
  "source": "scripts/situations.json + package source (DO NOT EDIT the outputs by hand)",
7
7
  "componentCount": 76,
@@ -143,7 +143,7 @@
143
143
  "name": "RecordList",
144
144
  "dir": "record-list",
145
145
  "import": "@poodle64/ui/record-list",
146
- "props": "rows, columns?, preferences?, onPreferencesChange?, title?, tools?, action?, group?, totalLabel?, icon?, href?, onOpen?, open?",
146
+ "props": "rows, columns?, preferences?, onPreferencesChange?, title?, tools?, action?, group?, groupings?, totalLabel?, icon?, href?, onOpen?, open?",
147
147
  "insteadOf": "a DataTableTanstack, or a boxed Table, for a module's own records (properties, managers, tools, a P&L's lines): the ledger's look (head card, row cards, group labels on the ground) for rows that are not money, so every list in an app reads one way"
148
148
  },
149
149
  {
@@ -1,7 +1,7 @@
1
1
  # @poodle64/ui — situation → component map
2
2
 
3
3
  <!-- GENERATED by scripts/generate-registry.mjs from scripts/situations.json + package source. DO NOT EDIT. -->
4
- Generated from `@poodle64/ui@2026.11.8`. 76 components, 20 situations.
4
+ Generated from `@poodle64/ui@2026.11.10`. 76 components, 20 situations.
5
5
 
6
6
  **Read this before writing a `<div>`.** Find the SITUATION you are in below, then compose the component named for it — do not hand-build it from raw `Card` or utility classes. Import is `import { Name } from '<import path>'`. Props marked `?` are optional. This map is the retrieval step the [`design-frontend` skill] makes mandatory; the [CHI 2026 study] measured composing-from-a-registry at 95% design-system compliance against 71% for writing the CSS from a prose style guide.
7
7
 
@@ -80,7 +80,7 @@ _An index of many peer items — a responsive tile wall, or a sortable/filterabl
80
80
 
81
81
  | Component | Import | Key props | Reach for it instead of |
82
82
  | --- | --- | --- | --- |
83
- | `RecordList` | `@poodle64/ui/record-list` | `rows, columns?, preferences?, onPreferencesChange?, title?, tools?, action?, group?, totalLabel?, icon?, href?, onOpen?, open?` | a DataTableTanstack, or a boxed Table, for a module's own records (properties, managers, tools, a P&L's lines): the ledger's look (head card, row cards, group labels on the ground) for rows that are not money, so every list in an app reads one way |
83
+ | `RecordList` | `@poodle64/ui/record-list` | `rows, columns?, preferences?, onPreferencesChange?, title?, tools?, action?, group?, groupings?, totalLabel?, icon?, href?, onOpen?, open?` | a DataTableTanstack, or a boxed Table, for a module's own records (properties, managers, tools, a P&L's lines): the ledger's look (head card, row cards, group labels on the ground) for rows that are not money, so every list in an app reads one way |
84
84
  | `ListToolbar` | `@poodle64/ui/list-toolbar` | `title?, meta?, leading?, children?, tools?, action?` | a hand-built title, count and button row above a list; the Ledger and the RecordList draw theirs with it |
85
85
  | `TileGrid` | `@poodle64/ui/tile-grid` | `children, min?, gap?, tag?` | a grid with fixed sm:grid-cols-* breakpoints you maintain per page |
86
86
  | `DataTableTanstack` | `@poodle64/ui/data-table-tanstack` | `table, selectable?, selectedId?, onSelect?, emptyMessage?` | a hand-built <table>, or the raw Table primitive wired to TanStack by hand |