@eifi1/ui-kit 0.7.1 → 0.8.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.
Files changed (222) hide show
  1. package/README.md +32 -17
  2. package/dist/chart.d.ts +3 -2
  3. package/dist/components/alert-banner.d.ts +59 -10
  4. package/dist/components/alert-banner.js +114 -8
  5. package/dist/components/alert-banner.js.map +1 -1
  6. package/dist/components/amount-input.d.ts +3 -0
  7. package/dist/components/button-group.d.ts +26 -0
  8. package/dist/components/button-group.js +49 -0
  9. package/dist/components/button-group.js.map +1 -0
  10. package/dist/components/calculator.d.ts +3 -0
  11. package/dist/components/chart-zoom.d.ts +63 -14
  12. package/dist/components/chart-zoom.js +82 -16
  13. package/dist/components/chart-zoom.js.map +1 -1
  14. package/dist/components/chip.d.ts +67 -2
  15. package/dist/components/chip.js +73 -8
  16. package/dist/components/chip.js.map +1 -1
  17. package/dist/components/confirm-dialog.d.ts +120 -0
  18. package/dist/components/confirm-dialog.js +96 -0
  19. package/dist/components/confirm-dialog.js.map +1 -0
  20. package/dist/components/copy-button.d.ts +62 -0
  21. package/dist/components/copy-button.js +95 -0
  22. package/dist/components/copy-button.js.map +1 -0
  23. package/dist/components/data-table-filter-popover.d.ts +1 -1
  24. package/dist/components/data-table-filters.d.ts +1 -1
  25. package/dist/components/data-table-pagination.d.ts +5 -1
  26. package/dist/components/data-table-pagination.js +71 -58
  27. package/dist/components/data-table-pagination.js.map +1 -1
  28. package/dist/components/data-table-sort.d.ts +28 -5
  29. package/dist/components/data-table-sort.js +11 -7
  30. package/dist/components/data-table-sort.js.map +1 -1
  31. package/dist/components/data-table.d.ts +1 -1
  32. package/dist/components/data-table.js +544 -423
  33. package/dist/components/data-table.js.map +1 -1
  34. package/dist/components/date-picker.d.ts +51 -5
  35. package/dist/components/date-picker.js +152 -40
  36. package/dist/components/date-picker.js.map +1 -1
  37. package/dist/components/description-list.d.ts +60 -0
  38. package/dist/components/description-list.js +112 -0
  39. package/dist/components/description-list.js.map +1 -0
  40. package/dist/components/disclosure.d.ts +37 -2
  41. package/dist/components/disclosure.js +14 -5
  42. package/dist/components/disclosure.js.map +1 -1
  43. package/dist/components/facing-pair.d.ts +2 -0
  44. package/dist/components/file-button.d.ts +17 -1
  45. package/dist/components/file-button.js +8 -1
  46. package/dist/components/file-button.js.map +1 -1
  47. package/dist/components/file-dropzone.d.ts +54 -9
  48. package/dist/components/file-dropzone.js +100 -70
  49. package/dist/components/file-dropzone.js.map +1 -1
  50. package/dist/components/floating-panel.d.ts +107 -0
  51. package/dist/components/floating-panel.js +206 -0
  52. package/dist/components/floating-panel.js.map +1 -0
  53. package/dist/components/full-bleed-dialog.d.ts +12 -1
  54. package/dist/components/full-bleed-dialog.js +26 -5
  55. package/dist/components/full-bleed-dialog.js.map +1 -1
  56. package/dist/components/modal.d.ts +6 -2
  57. package/dist/components/modal.js +2 -1
  58. package/dist/components/modal.js.map +1 -1
  59. package/dist/components/number-field.d.ts +3 -0
  60. package/dist/components/number-input.d.ts +3 -0
  61. package/dist/components/numpad-sheet.d.ts +3 -0
  62. package/dist/components/progress-bar.d.ts +54 -0
  63. package/dist/components/progress-bar.js +94 -0
  64. package/dist/components/progress-bar.js.map +1 -0
  65. package/dist/components/scroll-area.d.ts +53 -0
  66. package/dist/components/scroll-area.js +86 -0
  67. package/dist/components/scroll-area.js.map +1 -0
  68. package/dist/components/separator.d.ts +23 -0
  69. package/dist/components/separator.js +24 -0
  70. package/dist/components/separator.js.map +1 -0
  71. package/dist/components/series-chart-ticks.d.ts +34 -1
  72. package/dist/components/series-chart-ticks.js +83 -1
  73. package/dist/components/series-chart-ticks.js.map +1 -1
  74. package/dist/components/series-chart.d.ts +314 -19
  75. package/dist/components/series-chart.js +510 -120
  76. package/dist/components/series-chart.js.map +1 -1
  77. package/dist/components/skeleton.d.ts +36 -0
  78. package/dist/components/skeleton.js +35 -0
  79. package/dist/components/skeleton.js.map +1 -0
  80. package/dist/components/stat-tile.d.ts +60 -6
  81. package/dist/components/stat-tile.js +60 -26
  82. package/dist/components/stat-tile.js.map +1 -1
  83. package/dist/components/table.d.ts +83 -0
  84. package/dist/components/table.js +166 -0
  85. package/dist/components/table.js.map +1 -0
  86. package/dist/components/toggle-legend.d.ts +3 -2
  87. package/dist/components/toggle-legend.js +1 -1
  88. package/dist/components/toggle-legend.js.map +1 -1
  89. package/dist/components/tree-view.d.ts +129 -0
  90. package/dist/components/tree-view.js +376 -0
  91. package/dist/components/tree-view.js.map +1 -0
  92. package/dist/components/treemap.d.ts +9 -2
  93. package/dist/components/treemap.js +2 -1
  94. package/dist/components/treemap.js.map +1 -1
  95. package/dist/components/ui.d.ts +87 -13
  96. package/dist/components/ui.js +111 -29
  97. package/dist/components/ui.js.map +1 -1
  98. package/dist/components/use-table-state.d.ts +1 -1
  99. package/dist/{data-table-filters-noy0Abvi.d.ts → data-table-filters-CF1PXqjQ.d.ts} +73 -3
  100. package/dist/data-table.d.ts +2 -2
  101. package/dist/data-table.js.map +1 -1
  102. package/dist/hooks/use-copy-to-clipboard.d.ts +28 -0
  103. package/dist/hooks/use-copy-to-clipboard.js +81 -0
  104. package/dist/hooks/use-copy-to-clipboard.js.map +1 -0
  105. package/dist/hooks/use-debounce.d.ts +43 -0
  106. package/dist/hooks/use-debounce.js +56 -0
  107. package/dist/hooks/use-debounce.js.map +1 -0
  108. package/dist/hooks/use-file-drop.d.ts +72 -0
  109. package/dist/hooks/use-file-drop.js +57 -0
  110. package/dist/hooks/use-file-drop.js.map +1 -0
  111. package/dist/i18n/defaults.d.ts +3 -0
  112. package/dist/i18n/defaults.js +7 -1
  113. package/dist/i18n/defaults.js.map +1 -1
  114. package/dist/i18n/kit-labels.d.ts +15 -0
  115. package/dist/i18n/kit-labels.js +6 -2
  116. package/dist/i18n/kit-labels.js.map +1 -1
  117. package/dist/i18n/locales/de-CH-informal.d.ts +43 -0
  118. package/dist/i18n/locales/de-CH-informal.js +8 -0
  119. package/dist/i18n/locales/de-CH-informal.js.map +1 -0
  120. package/dist/i18n/locales/de-CH.d.ts +3 -0
  121. package/dist/i18n/locales/de-CH.js +1 -14
  122. package/dist/i18n/locales/de-CH.js.map +1 -1
  123. package/dist/i18n/locales/de-informal.d.ts +64 -0
  124. package/dist/i18n/locales/de-informal.js +37 -0
  125. package/dist/i18n/locales/de-informal.js.map +1 -0
  126. package/dist/i18n/locales/de.d.ts +3 -0
  127. package/dist/i18n/locales/de.js +25 -0
  128. package/dist/i18n/locales/de.js.map +1 -1
  129. package/dist/i18n/locales/es.d.ts +3 -0
  130. package/dist/i18n/locales/es.js +25 -0
  131. package/dist/i18n/locales/es.js.map +1 -1
  132. package/dist/i18n/locales/fr.d.ts +3 -0
  133. package/dist/i18n/locales/fr.js +25 -0
  134. package/dist/i18n/locales/fr.js.map +1 -1
  135. package/dist/i18n/locales/hu.d.ts +3 -0
  136. package/dist/i18n/locales/hu.js +25 -0
  137. package/dist/i18n/locales/hu.js.map +1 -1
  138. package/dist/i18n/locales/it.d.ts +3 -0
  139. package/dist/i18n/locales/it.js +25 -0
  140. package/dist/i18n/locales/it.js.map +1 -1
  141. package/dist/i18n/locales/zh.d.ts +3 -0
  142. package/dist/i18n/locales/zh.js +25 -0
  143. package/dist/i18n/locales/zh.js.map +1 -1
  144. package/dist/i18n/swiss.d.ts +13 -0
  145. package/dist/i18n/swiss.js +19 -0
  146. package/dist/i18n/swiss.js.map +1 -0
  147. package/dist/index.d.ts +25 -10
  148. package/dist/index.js +22 -0
  149. package/dist/index.js.map +1 -1
  150. package/dist/lib/dates.d.ts +37 -1
  151. package/dist/lib/dates.js +19 -0
  152. package/dist/lib/dates.js.map +1 -1
  153. package/dist/search/command-palette.d.ts +15 -1
  154. package/dist/search/command-palette.js +10 -2
  155. package/dist/search/command-palette.js.map +1 -1
  156. package/dist/wizard/stepper-nav.d.ts +35 -2
  157. package/dist/wizard/stepper-nav.js +54 -22
  158. package/dist/wizard/stepper-nav.js.map +1 -1
  159. package/dist/wizard/types.d.ts +107 -5
  160. package/dist/wizard/types.js +2 -1
  161. package/dist/wizard/types.js.map +1 -1
  162. package/dist/wizard/use-wizard.js +141 -21
  163. package/dist/wizard/use-wizard.js.map +1 -1
  164. package/dist/wizard/wizard-summary.d.ts +10 -2
  165. package/dist/wizard/wizard-summary.js +3 -1
  166. package/dist/wizard/wizard-summary.js.map +1 -1
  167. package/dist/wizard.d.ts +4 -1
  168. package/dist/wizard.js.map +1 -1
  169. package/package.json +1 -1
  170. package/src/components/alert-banner.tsx +211 -20
  171. package/src/components/button-group.tsx +75 -0
  172. package/src/components/chart-zoom.tsx +158 -20
  173. package/src/components/chip.tsx +160 -9
  174. package/src/components/confirm-dialog.tsx +242 -0
  175. package/src/components/copy-button.tsx +158 -0
  176. package/src/components/data-table-pagination.tsx +19 -6
  177. package/src/components/data-table-sort.ts +49 -10
  178. package/src/components/data-table.tsx +293 -24
  179. package/src/components/date-picker.tsx +262 -57
  180. package/src/components/description-list.tsx +174 -0
  181. package/src/components/disclosure.tsx +58 -5
  182. package/src/components/file-button.tsx +22 -2
  183. package/src/components/file-dropzone.tsx +198 -100
  184. package/src/components/floating-panel.tsx +341 -0
  185. package/src/components/full-bleed-dialog.tsx +48 -5
  186. package/src/components/modal.tsx +9 -2
  187. package/src/components/progress-bar.tsx +163 -0
  188. package/src/components/scroll-area.tsx +129 -0
  189. package/src/components/separator.tsx +37 -0
  190. package/src/components/series-chart-ticks.ts +135 -0
  191. package/src/components/series-chart.tsx +934 -67
  192. package/src/components/skeleton.tsx +65 -0
  193. package/src/components/stat-tile.tsx +160 -27
  194. package/src/components/table.tsx +263 -0
  195. package/src/components/toggle-legend.tsx +4 -3
  196. package/src/components/tree-view.tsx +589 -0
  197. package/src/components/treemap.tsx +10 -2
  198. package/src/components/ui.tsx +263 -39
  199. package/src/data-table.ts +2 -0
  200. package/src/hooks/use-copy-to-clipboard.ts +122 -0
  201. package/src/hooks/use-debounce.ts +105 -0
  202. package/src/hooks/use-file-drop.ts +123 -0
  203. package/src/i18n/defaults.ts +6 -0
  204. package/src/i18n/kit-labels.tsx +19 -0
  205. package/src/i18n/locales/de-CH-informal.ts +10 -0
  206. package/src/i18n/locales/de-CH.ts +1 -16
  207. package/src/i18n/locales/de-informal.ts +61 -0
  208. package/src/i18n/locales/de.ts +25 -0
  209. package/src/i18n/locales/es.ts +25 -0
  210. package/src/i18n/locales/fr.ts +25 -0
  211. package/src/i18n/locales/hu.ts +25 -0
  212. package/src/i18n/locales/it.ts +25 -0
  213. package/src/i18n/locales/zh.ts +25 -0
  214. package/src/i18n/swiss.ts +25 -0
  215. package/src/index.ts +29 -0
  216. package/src/lib/dates.ts +48 -0
  217. package/src/search/command-palette.tsx +29 -3
  218. package/src/wizard/stepper-nav.tsx +102 -28
  219. package/src/wizard/types.ts +106 -4
  220. package/src/wizard/use-wizard.ts +211 -31
  221. package/src/wizard/wizard-summary.tsx +24 -12
  222. package/src/wizard.ts +3 -2
@@ -0,0 +1,376 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
4
+ import { ChevronRight } from "lucide-react";
5
+ import { cn } from "../lib/cn.js";
6
+ import { horizontalStep } from "../lib/direction.js";
7
+ import { Spinner } from "./ui.js";
8
+ const DEFAULT_INDENT = 16;
9
+ const CHEVRON = 16;
10
+ const ROW_PAD = 4;
11
+ function TreeRow({
12
+ level,
13
+ expanded,
14
+ onToggle,
15
+ toggleLabel,
16
+ label,
17
+ icon,
18
+ trailing,
19
+ indent = DEFAULT_INDENT,
20
+ guides = true,
21
+ selected,
22
+ loading,
23
+ children,
24
+ className,
25
+ style,
26
+ ...rest
27
+ }) {
28
+ const labelId = useId();
29
+ const depth = Math.max(0, level - 1);
30
+ const expandable = expanded !== void 0;
31
+ const chevron = /* @__PURE__ */ jsx(
32
+ ChevronRight,
33
+ {
34
+ "aria-hidden": true,
35
+ className: cn(
36
+ "size-4 transition-transform motion-reduce:transition-none rtl:-scale-x-100",
37
+ expanded && "rotate-90 rtl:-rotate-90"
38
+ )
39
+ }
40
+ );
41
+ return /* @__PURE__ */ jsxs(
42
+ "div",
43
+ {
44
+ ...rest,
45
+ "data-tree-row": "",
46
+ "data-selected": selected || void 0,
47
+ style: { paddingInlineStart: ROW_PAD + depth * indent, ...style },
48
+ className: cn(
49
+ "relative flex min-h-8 items-center gap-1.5 rounded pe-2 text-sm",
50
+ selected ? "bg-[var(--bg-active)] font-medium text-[var(--text-primary)]" : "text-[var(--text-secondary)]",
51
+ className
52
+ ),
53
+ children: [
54
+ guides && Array.from({ length: depth }, (_, i) => /* @__PURE__ */ jsx(
55
+ "span",
56
+ {
57
+ "aria-hidden": true,
58
+ "data-tree-guide": "",
59
+ className: "pointer-events-none absolute inset-y-0 w-px bg-[var(--border)]",
60
+ style: { insetInlineStart: ROW_PAD + i * indent + CHEVRON / 2 }
61
+ },
62
+ i
63
+ )),
64
+ loading ? /* @__PURE__ */ jsx("span", { className: "flex size-4 shrink-0 items-center justify-center", children: /* @__PURE__ */ jsx(Spinner, { label: null, className: "size-3 border" }) }) : expandable && onToggle ? /* @__PURE__ */ jsx(
65
+ "button",
66
+ {
67
+ type: "button",
68
+ "aria-expanded": expanded,
69
+ "aria-label": toggleLabel,
70
+ "aria-labelledby": toggleLabel ? void 0 : labelId,
71
+ onClick: (e) => {
72
+ e.stopPropagation();
73
+ onToggle();
74
+ },
75
+ className: "flex size-4 shrink-0 items-center justify-center rounded text-[var(--text-muted)] outline-none hover:text-[var(--text-primary)] focus-visible:ring-2 focus-visible:ring-[var(--brand)]",
76
+ children: chevron
77
+ }
78
+ ) : expandable ? /* @__PURE__ */ jsx("span", { "data-tree-toggle": "", className: "flex size-4 shrink-0 cursor-pointer items-center justify-center text-[var(--text-muted)]", children: chevron }) : /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "size-4 shrink-0" }),
79
+ children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
80
+ icon && /* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-center", children: icon }),
81
+ /* @__PURE__ */ jsx("span", { id: labelId, "data-tree-label": "", className: "min-w-0 flex-1 truncate", children: label }),
82
+ trailing !== void 0 && trailing !== null && /* @__PURE__ */ jsx("span", { className: "ms-auto flex shrink-0 items-center gap-1 text-xs tabular-nums text-[var(--text-muted)]", children: trailing })
83
+ ] })
84
+ ]
85
+ }
86
+ );
87
+ }
88
+ const isExpandable = (n) => Boolean(n.children?.length || n.hasChildren);
89
+ function useControllable(value, initial) {
90
+ const [own, setOwn] = useState(initial);
91
+ const controlled = value !== void 0;
92
+ const set = (next) => {
93
+ if (!controlled) setOwn(next);
94
+ };
95
+ return [controlled ? value : own, set];
96
+ }
97
+ const TYPEAHEAD_MS = 500;
98
+ function TreeView({
99
+ items,
100
+ expanded: expandedProp,
101
+ defaultExpanded,
102
+ onExpandedChange,
103
+ selected: selectedProp,
104
+ defaultSelected,
105
+ onSelectedChange,
106
+ selectionMode = "single",
107
+ renderItem,
108
+ loadChildren,
109
+ indent = DEFAULT_INDENT,
110
+ indentGuides = true,
111
+ rowClassName,
112
+ className,
113
+ onKeyDown,
114
+ onClick,
115
+ ...rest
116
+ }) {
117
+ const [expandedList, setExpandedOwn] = useControllable(
118
+ expandedProp,
119
+ defaultExpanded ?? []
120
+ );
121
+ const [selected, setSelectedOwn] = useControllable(
122
+ selectedProp,
123
+ defaultSelected ?? null
124
+ );
125
+ const expandedSet = useMemo(() => new Set(expandedList), [expandedList]);
126
+ const [loading, setLoading] = useState(() => /* @__PURE__ */ new Set());
127
+ const [focusedId, setFocusedId] = useState(null);
128
+ const itemRefs = useRef(/* @__PURE__ */ new Map());
129
+ const pendingFocus = useRef(null);
130
+ const typeahead = useRef({ text: "", at: 0 });
131
+ const baseId = useId();
132
+ const { byId, visible } = useMemo(() => {
133
+ const map = /* @__PURE__ */ new Map();
134
+ const rows = [];
135
+ const walk = (nodes, level, parentId, shown) => {
136
+ for (const node of nodes) {
137
+ const flat = { node, level, parentId };
138
+ map.set(node.id, flat);
139
+ if (shown) rows.push(flat);
140
+ if (node.children) walk(node.children, level + 1, node.id, shown && expandedSet.has(node.id));
141
+ }
142
+ };
143
+ walk(items, 1, null, true);
144
+ return { byId: map, visible: rows };
145
+ }, [items, expandedSet]);
146
+ const visibleIds = useMemo(() => new Set(visible.map((f) => f.node.id)), [visible]);
147
+ const nearestVisible = (id) => {
148
+ let cur = id;
149
+ while (cur && !visibleIds.has(cur)) cur = byId.get(cur)?.parentId ?? null;
150
+ return cur;
151
+ };
152
+ const tabbable = nearestVisible(focusedId) ?? nearestVisible(selected) ?? visible[0]?.node.id ?? null;
153
+ useEffect(() => {
154
+ const id = pendingFocus.current;
155
+ if (!id) return;
156
+ pendingFocus.current = null;
157
+ itemRefs.current.get(id)?.focus();
158
+ });
159
+ const focusRow = (id) => {
160
+ setFocusedId(id);
161
+ pendingFocus.current = id;
162
+ itemRefs.current.get(id)?.focus();
163
+ };
164
+ const setExpanded = (next) => {
165
+ const list = [...next];
166
+ setExpandedOwn(list);
167
+ onExpandedChange?.(list);
168
+ };
169
+ const open = (node) => {
170
+ if (expandedSet.has(node.id) || !isExpandable(node)) return;
171
+ const next = new Set(expandedSet);
172
+ next.add(node.id);
173
+ setExpanded(next);
174
+ if (loadChildren && node.hasChildren && !node.children?.length) {
175
+ const pending = loadChildren(node);
176
+ if (pending && typeof pending.then === "function") {
177
+ setLoading((s) => new Set(s).add(node.id));
178
+ const done = () => setLoading((s) => {
179
+ const n = new Set(s);
180
+ n.delete(node.id);
181
+ return n;
182
+ });
183
+ pending.then(done, done);
184
+ }
185
+ }
186
+ };
187
+ const close = (node) => {
188
+ if (!expandedSet.has(node.id)) return;
189
+ const next = new Set(expandedSet);
190
+ next.delete(node.id);
191
+ setExpanded(next);
192
+ };
193
+ const toggle = (node) => expandedSet.has(node.id) ? close(node) : open(node);
194
+ const select = (node) => {
195
+ if (node.disabled) return;
196
+ if (selectionMode === "none") {
197
+ toggle(node);
198
+ return;
199
+ }
200
+ setSelectedOwn(node.id);
201
+ onSelectedChange?.(node.id, node);
202
+ };
203
+ const idOf = (target) => target?.closest?.('[role="treeitem"]')?.dataset.treeId ?? null;
204
+ const textOf = (flat) => {
205
+ if (flat.node.textValue !== void 0) return flat.node.textValue;
206
+ if (typeof flat.node.label === "string") return flat.node.label;
207
+ const row = itemRefs.current.get(flat.node.id)?.querySelector("[data-tree-row]");
208
+ return row?.textContent ?? "";
209
+ };
210
+ const findByText = (fromIndex, text) => {
211
+ const needle = text.toLocaleLowerCase();
212
+ for (let i = 1; i <= visible.length; i++) {
213
+ const flat = visible[(fromIndex + i) % visible.length];
214
+ if (textOf(flat).trim().toLocaleLowerCase().startsWith(needle)) return flat.node.id;
215
+ }
216
+ return null;
217
+ };
218
+ const handleKeyDown = (e) => {
219
+ onKeyDown?.(e);
220
+ if (e.defaultPrevented) return;
221
+ const id = idOf(e.target);
222
+ const flat = id ? byId.get(id) : void 0;
223
+ if (!flat) return;
224
+ const { node } = flat;
225
+ const index = visible.findIndex((f) => f.node.id === node.id);
226
+ const expandedNow = expandedSet.has(node.id);
227
+ const step = horizontalStep(e.key, e.target);
228
+ const inRun = Date.now() - typeahead.current.at < TYPEAHEAD_MS && typeahead.current.text !== "";
229
+ const key = e.key === " " && inRun ? "typeahead" : e.key;
230
+ let handled = true;
231
+ if (step === 1) {
232
+ if (!isExpandable(node)) handled = false;
233
+ else if (!expandedNow) open(node);
234
+ else if (node.children?.length) focusRow(node.children[0].id);
235
+ } else if (step === -1) {
236
+ if (expandedNow) close(node);
237
+ else if (flat.parentId) focusRow(flat.parentId);
238
+ else handled = false;
239
+ } else {
240
+ switch (key) {
241
+ case "ArrowDown":
242
+ if (index < visible.length - 1) focusRow(visible[index + 1].node.id);
243
+ break;
244
+ case "ArrowUp":
245
+ if (index > 0) focusRow(visible[index - 1].node.id);
246
+ break;
247
+ case "Home":
248
+ if (visible.length) focusRow(visible[0].node.id);
249
+ break;
250
+ case "End":
251
+ if (visible.length) focusRow(visible[visible.length - 1].node.id);
252
+ break;
253
+ case "Enter":
254
+ case " ":
255
+ select(node);
256
+ break;
257
+ case "*": {
258
+ const siblings = flat.parentId ? byId.get(flat.parentId)?.node.children ?? [] : items;
259
+ const next = new Set(expandedSet);
260
+ for (const s of siblings) if (isExpandable(s)) next.add(s.id);
261
+ setExpanded(next);
262
+ break;
263
+ }
264
+ default: {
265
+ const printable = e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;
266
+ if (!printable) {
267
+ handled = false;
268
+ break;
269
+ }
270
+ const now = Date.now();
271
+ const run = now - typeahead.current.at < TYPEAHEAD_MS ? typeahead.current.text : "";
272
+ typeahead.current = { text: run + e.key, at: now };
273
+ const typed = typeahead.current.text;
274
+ const repeated = typed.length > 1 && [...typed].every((c) => c === typed[0]);
275
+ const target = repeated ? findByText(index, typed[0]) : typed.length > 1 && textOf(flat).trim().toLocaleLowerCase().startsWith(typed.toLocaleLowerCase()) ? node.id : findByText(index, typed);
276
+ if (target) focusRow(target);
277
+ }
278
+ }
279
+ }
280
+ if (handled) {
281
+ e.preventDefault();
282
+ e.stopPropagation();
283
+ }
284
+ };
285
+ const handleClick = (e) => {
286
+ onClick?.(e);
287
+ const id = idOf(e.target);
288
+ const flat = id ? byId.get(id) : void 0;
289
+ if (!flat) return;
290
+ const control = e.target.closest("button, a[href], input, select, textarea");
291
+ if (control && itemRefs.current.get(flat.node.id)?.contains(control)) return;
292
+ setFocusedId(flat.node.id);
293
+ if (e.target.closest("[data-tree-toggle]")) {
294
+ toggle(flat.node);
295
+ return;
296
+ }
297
+ select(flat.node);
298
+ };
299
+ const renderNodes = (nodes, level, path) => nodes.map((node, i) => {
300
+ const rowId = `${baseId}-${path}${i}`;
301
+ const expandable = isExpandable(node);
302
+ const isOpen = expandable && expandedSet.has(node.id);
303
+ const isSelected = selectionMode !== "none" && selected === node.id;
304
+ const isLoading = loading.has(node.id);
305
+ const state = {
306
+ level,
307
+ expanded: isOpen,
308
+ selected: isSelected,
309
+ expandable,
310
+ loading: isLoading,
311
+ disabled: Boolean(node.disabled)
312
+ };
313
+ return /* @__PURE__ */ jsxs(
314
+ "li",
315
+ {
316
+ ref: (el) => {
317
+ if (el) itemRefs.current.set(node.id, el);
318
+ else itemRefs.current.delete(node.id);
319
+ },
320
+ role: "treeitem",
321
+ "data-tree-id": node.id,
322
+ "aria-labelledby": rowId,
323
+ "aria-level": level,
324
+ "aria-expanded": expandable ? isOpen : void 0,
325
+ "aria-selected": selectionMode === "none" ? void 0 : isSelected,
326
+ "aria-disabled": node.disabled || void 0,
327
+ "aria-busy": isLoading || void 0,
328
+ tabIndex: node.id === tabbable ? 0 : -1,
329
+ onFocus: (e) => {
330
+ if (e.target === e.currentTarget) setFocusedId(node.id);
331
+ },
332
+ className: "outline-none [&:focus-visible>[data-tree-row]]:ring-2 [&:focus-visible>[data-tree-row]]:ring-[var(--brand)]",
333
+ children: [
334
+ /* @__PURE__ */ jsx(
335
+ TreeRow,
336
+ {
337
+ id: rowId,
338
+ level,
339
+ expanded: expandable ? isOpen : void 0,
340
+ label: node.label,
341
+ icon: node.icon,
342
+ trailing: node.trailing,
343
+ indent,
344
+ guides: indentGuides,
345
+ selected: isSelected,
346
+ loading: isLoading,
347
+ className: cn(
348
+ node.disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer hover:bg-[var(--bg-hover)]",
349
+ rowClassName
350
+ ),
351
+ children: renderItem ? renderItem(node, state) : void 0
352
+ }
353
+ ),
354
+ isOpen && /* @__PURE__ */ jsx("ul", { role: "group", children: node.children?.length ? renderNodes(node.children, level + 1, `${path}${i}-`) : null })
355
+ ]
356
+ },
357
+ node.id
358
+ );
359
+ });
360
+ return /* @__PURE__ */ jsx(
361
+ "ul",
362
+ {
363
+ ...rest,
364
+ role: "tree",
365
+ onKeyDown: handleKeyDown,
366
+ onClick: handleClick,
367
+ className: cn("flex flex-col text-sm", className),
368
+ children: renderNodes(items, 1, "")
369
+ }
370
+ );
371
+ }
372
+ export {
373
+ TreeRow,
374
+ TreeView
375
+ };
376
+ //# sourceMappingURL=tree-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/tree-view.tsx"],"sourcesContent":["import { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, KeyboardEvent, MouseEvent, ReactNode } from \"react\";\nimport { ChevronRight } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { horizontalStep } from \"../lib/direction\";\nimport { Spinner } from \"./ui\";\n\n/**\n * A hierarchy you walk with the keyboard: kastlan's chart of accounts (Assets › Current\n * assets › Bank › 1020 Operating account), and — through {@link TreeRow} alone — the\n * row labels of its gantt, which indent and fold like a tree but sit beside a timeline\n * and so cannot be one.\n *\n * Both apps had written it as nested `<div>`s with a chevron button per row: every\n * row a Tab stop (a 300-account chart was 300 presses to get past), no way to say\n * \"level 3 of 5, collapsed\" to a screen reader, and no ←/→ at all. This is the WAI-ARIA\n * tree pattern instead:\n *\n * - `role=\"tree\"` › `treeitem` (with `aria-level`, `aria-expanded` on a parent,\n * `aria-selected` when selectable) › `role=\"group\"` for its children — so the\n * reader announces the position and the state it needs.\n * - ONE Tab stop (roving tabindex). ↑/↓ walk the visible rows, → opens a closed\n * parent and then steps into it, ← closes an open one and then steps out to the\n * parent, Home/End jump to the ends, `*` opens every sibling, and typing a few\n * letters jumps to the next row that starts with them. ←/→ follow the reading\n * direction (`horizontalStep`): in an RTL tree the children hang off to the left,\n * and ← is what opens them.\n * - Enter / Space, or a click, select. The chevron alone toggles on click.\n *\n * `expanded` and `selected` each work controlled or uncontrolled.\n */\n\n/* ── Nodes ───────────────────────────────────────────────────────────────── */\n\nexport interface TreeNode<T = unknown> {\n /** Unique across the whole tree — it is what `expanded` and `selected` hold. */\n id: string;\n label: ReactNode;\n /** The text type-ahead matches. Defaults to the row's rendered text. */\n textValue?: string;\n /** Before the label: an account-type icon, a colour dot. */\n icon?: ReactNode;\n /** After the label, pushed to the end of the row: a balance, a count, an action. */\n trailing?: ReactNode;\n children?: readonly TreeNode<T>[];\n /**\n * The node has children that are not loaded yet — it gets a chevron, and opening it\n * calls `loadChildren`. Pass the children in `items` once they arrive.\n */\n hasChildren?: boolean;\n /** Focusable and announced as unavailable (`aria-disabled`), but not selectable. */\n disabled?: boolean;\n /** Anything of the host's own, handed back to `renderItem` and `onSelectedChange`. */\n data?: T;\n}\n\n/** What {@link TreeViewProps.renderItem} is told about a row. */\nexport interface TreeItemState {\n level: number;\n expanded: boolean;\n selected: boolean;\n /** It has children, loaded or not — it shows a chevron. */\n expandable: boolean;\n loading: boolean;\n disabled: boolean;\n}\n\n/* ── TreeRow ─────────────────────────────────────────────────────────────── */\n\nexport interface TreeRowProps extends ComponentPropsWithoutRef<\"div\"> {\n /** 1 for a top-level row. Sets the indent and the number of guides. */\n level: number;\n /** `true`/`false` for a row that can fold; leave it `undefined` for a leaf, which\n * gets a chevron-sized gap instead so labels at one level still line up. */\n expanded?: boolean;\n /**\n * Make the chevron a real button (with `aria-expanded`, named by the label) that\n * calls this. For a row used ON ITS OWN — kastlan's gantt labels, where each row is\n * a line of a timeline and not an item of a tree widget. Inside {@link TreeView} it\n * is omitted: the tree owns the keys, and a button per row would be a Tab stop per\n * row, which is what the tree exists to remove.\n */\n onToggle?: () => void;\n /** The toggle button's name. By default it is named by the row's label (the state\n * is `aria-expanded`'s to say); required when `children` replaces the label. */\n toggleLabel?: string;\n label: ReactNode;\n icon?: ReactNode;\n trailing?: ReactNode;\n /** Pixels per level. Default 16. */\n indent?: number;\n /** Draw a vertical hairline per ancestor level. Default `true`. */\n guides?: boolean;\n selected?: boolean;\n /** A spinner in place of the chevron, while lazy children load. */\n loading?: boolean;\n /** Replace the label + trailing part of the row (the indent and chevron stay). */\n children?: ReactNode;\n}\n\nconst DEFAULT_INDENT = 16;\n/** The chevron's box; the guide for a level runs through its centre. */\nconst CHEVRON = 16;\n/** The row's start padding, before any indent. */\nconst ROW_PAD = 4;\n\n/**\n * One row: indent, guides, chevron, icon, label, trailing — no tree semantics of its\n * own. {@link TreeView} is built from it, and a host that needs the look without the\n * widget (a gantt's label column) uses it directly.\n *\n * Laid out with logical properties throughout (`padding-inline-start`,\n * `inset-inline-start`), so the indent, the guides and the chevron all hang from the\n * reading start in an RTL layout without a second code path.\n */\nexport function TreeRow({\n level,\n expanded,\n onToggle,\n toggleLabel,\n label,\n icon,\n trailing,\n indent = DEFAULT_INDENT,\n guides = true,\n selected,\n loading,\n children,\n className,\n style,\n ...rest\n}: TreeRowProps) {\n const labelId = useId();\n const depth = Math.max(0, level - 1);\n const expandable = expanded !== undefined;\n // A right-pointing chevron that turns DOWN when open. In RTL it is mirrored to point\n // left, and turning that one clockwise would point it UP — so it turns the other way.\n const chevron = (\n <ChevronRight\n aria-hidden\n className={cn(\n \"size-4 transition-transform motion-reduce:transition-none rtl:-scale-x-100\",\n expanded && \"rotate-90 rtl:-rotate-90\",\n )}\n />\n );\n return (\n <div\n {...rest}\n data-tree-row=\"\"\n data-selected={selected || undefined}\n style={{ paddingInlineStart: ROW_PAD + depth * indent, ...style }}\n className={cn(\n \"relative flex min-h-8 items-center gap-1.5 rounded pe-2 text-sm\",\n selected\n ? \"bg-[var(--bg-active)] font-medium text-[var(--text-primary)]\"\n : \"text-[var(--text-secondary)]\",\n className,\n )}\n >\n {guides &&\n Array.from({ length: depth }, (_, i) => (\n <span\n key={i}\n aria-hidden\n data-tree-guide=\"\"\n className=\"pointer-events-none absolute inset-y-0 w-px bg-[var(--border)]\"\n style={{ insetInlineStart: ROW_PAD + i * indent + CHEVRON / 2 }}\n />\n ))}\n {loading ? (\n <span className=\"flex size-4 shrink-0 items-center justify-center\">\n <Spinner label={null} className=\"size-3 border\" />\n </span>\n ) : expandable && onToggle ? (\n <button\n type=\"button\"\n aria-expanded={expanded}\n aria-label={toggleLabel}\n aria-labelledby={toggleLabel ? undefined : labelId}\n onClick={(e) => {\n e.stopPropagation();\n onToggle();\n }}\n className=\"flex size-4 shrink-0 items-center justify-center rounded text-[var(--text-muted)] outline-none hover:text-[var(--text-primary)] focus-visible:ring-2 focus-visible:ring-[var(--brand)]\"\n >\n {chevron}\n </button>\n ) : expandable ? (\n <span data-tree-toggle=\"\" className=\"flex size-4 shrink-0 cursor-pointer items-center justify-center text-[var(--text-muted)]\">\n {chevron}\n </span>\n ) : (\n <span aria-hidden className=\"size-4 shrink-0\" />\n )}\n {children ?? (\n <>\n {icon && <span className=\"flex shrink-0 items-center\">{icon}</span>}\n <span id={labelId} data-tree-label=\"\" className=\"min-w-0 flex-1 truncate\">\n {label}\n </span>\n {trailing !== undefined && trailing !== null && (\n <span className=\"ms-auto flex shrink-0 items-center gap-1 text-xs tabular-nums text-[var(--text-muted)]\">\n {trailing}\n </span>\n )}\n </>\n )}\n </div>\n );\n}\n\n/* ── TreeView ────────────────────────────────────────────────────────────── */\n\nexport interface TreeViewProps<T = unknown>\n extends Omit<ComponentPropsWithoutRef<\"ul\">, \"onSelect\" | \"children\" | \"defaultValue\"> {\n items: readonly TreeNode<T>[];\n /** Open nodes, controlled. */\n expanded?: readonly string[];\n /** Open nodes on first render, uncontrolled. */\n defaultExpanded?: readonly string[];\n onExpandedChange?: (expanded: string[]) => void;\n /** The selected node's id, controlled; `null` for none. */\n selected?: string | null;\n defaultSelected?: string | null;\n onSelectedChange?: (id: string, node: TreeNode<T>) => void;\n /** `\"none\"` makes it a navigation-only tree: no `aria-selected`, Enter toggles. */\n selectionMode?: \"single\" | \"none\";\n /** The whole row content after the chevron, per node. Wins over `label`/`trailing`. */\n renderItem?: (node: TreeNode<T>, state: TreeItemState) => ReactNode;\n /**\n * Called when a node with `hasChildren` and no `children` is opened. While the\n * promise is pending the row shows a spinner and is `aria-busy`; put the children\n * into `items` before it resolves (or after — the row opens either way).\n */\n loadChildren?: (node: TreeNode<T>) => Promise<void> | void;\n /** Pixels per level. Default 16. */\n indent?: number;\n /** Vertical hairlines per level. Default `true`. */\n indentGuides?: boolean;\n /** Extra classes for each row (the `TreeRow`), e.g. a denser height. */\n rowClassName?: string;\n}\n\ninterface FlatNode<T> {\n node: TreeNode<T>;\n level: number;\n parentId: string | null;\n}\n\nconst isExpandable = (n: TreeNode<unknown>) => Boolean(n.children?.length || n.hasChildren);\n\n/** Controlled when `value` is given, otherwise state seeded from `initial`. */\nfunction useControllable<V>(value: V | undefined, initial: V): [V, (next: V) => void] {\n const [own, setOwn] = useState<V>(initial);\n const controlled = value !== undefined;\n const set = (next: V) => {\n if (!controlled) setOwn(next);\n };\n return [controlled ? value : own, set];\n}\n\n/** How long a type-ahead run stays open between keys — the APG's suggested half second. */\nconst TYPEAHEAD_MS = 500;\n\nexport function TreeView<T = unknown>({\n items,\n expanded: expandedProp,\n defaultExpanded,\n onExpandedChange,\n selected: selectedProp,\n defaultSelected,\n onSelectedChange,\n selectionMode = \"single\",\n renderItem,\n loadChildren,\n indent = DEFAULT_INDENT,\n indentGuides = true,\n rowClassName,\n className,\n onKeyDown,\n onClick,\n ...rest\n}: TreeViewProps<T>) {\n const [expandedList, setExpandedOwn] = useControllable<readonly string[]>(\n expandedProp,\n defaultExpanded ?? [],\n );\n const [selected, setSelectedOwn] = useControllable<string | null>(\n selectedProp,\n defaultSelected ?? null,\n );\n const expandedSet = useMemo(() => new Set(expandedList), [expandedList]);\n const [loading, setLoading] = useState<ReadonlySet<string>>(() => new Set());\n const [focusedId, setFocusedId] = useState<string | null>(null);\n const itemRefs = useRef(new Map<string, HTMLLIElement>());\n const pendingFocus = useRef<string | null>(null);\n const typeahead = useRef({ text: \"\", at: 0 });\n const baseId = useId();\n\n // Every node by id (for parents and lookups), and the rows currently on screen in\n // order — the list the arrow keys walk.\n const { byId, visible } = useMemo(() => {\n const map = new Map<string, FlatNode<T>>();\n const rows: FlatNode<T>[] = [];\n const walk = (nodes: readonly TreeNode<T>[], level: number, parentId: string | null, shown: boolean) => {\n for (const node of nodes) {\n const flat = { node, level, parentId };\n map.set(node.id, flat);\n if (shown) rows.push(flat);\n if (node.children) walk(node.children, level + 1, node.id, shown && expandedSet.has(node.id));\n }\n };\n walk(items, 1, null, true);\n return { byId: map, visible: rows };\n }, [items, expandedSet]);\n\n // The one tabbable row. Focus that was inside a branch that has since closed (a\n // click on its parent's chevron) moves up to the nearest ancestor still on screen,\n // so the tab stop never points at a row that is not rendered.\n const visibleIds = useMemo(() => new Set(visible.map((f) => f.node.id)), [visible]);\n const nearestVisible = (id: string | null): string | null => {\n let cur = id;\n while (cur && !visibleIds.has(cur)) cur = byId.get(cur)?.parentId ?? null;\n return cur;\n };\n const tabbable =\n nearestVisible(focusedId) ?? nearestVisible(selected) ?? visible[0]?.node.id ?? null;\n\n useEffect(() => {\n const id = pendingFocus.current;\n if (!id) return;\n pendingFocus.current = null;\n itemRefs.current.get(id)?.focus();\n });\n\n const focusRow = (id: string) => {\n setFocusedId(id);\n // After the commit: moving into a branch that just opened targets a row that is\n // not in the DOM yet.\n pendingFocus.current = id;\n itemRefs.current.get(id)?.focus();\n };\n\n const setExpanded = (next: Set<string>) => {\n const list = [...next];\n setExpandedOwn(list);\n onExpandedChange?.(list);\n };\n\n const open = (node: TreeNode<T>) => {\n if (expandedSet.has(node.id) || !isExpandable(node)) return;\n const next = new Set(expandedSet);\n next.add(node.id);\n setExpanded(next);\n if (loadChildren && node.hasChildren && !node.children?.length) {\n const pending = loadChildren(node);\n if (pending && typeof pending.then === \"function\") {\n setLoading((s) => new Set(s).add(node.id));\n const done = () =>\n setLoading((s) => {\n const n = new Set(s);\n n.delete(node.id);\n return n;\n });\n pending.then(done, done);\n }\n }\n };\n\n const close = (node: TreeNode<T>) => {\n if (!expandedSet.has(node.id)) return;\n const next = new Set(expandedSet);\n next.delete(node.id);\n setExpanded(next);\n };\n\n const toggle = (node: TreeNode<T>) => (expandedSet.has(node.id) ? close(node) : open(node));\n\n const select = (node: TreeNode<T>) => {\n if (node.disabled) return;\n if (selectionMode === \"none\") {\n toggle(node);\n return;\n }\n setSelectedOwn(node.id);\n onSelectedChange?.(node.id, node);\n };\n\n const idOf = (target: EventTarget | null): string | null =>\n (target as Element | null)?.closest?.<HTMLElement>('[role=\"treeitem\"]')?.dataset.treeId ?? null;\n\n const textOf = (flat: FlatNode<T>): string => {\n if (flat.node.textValue !== undefined) return flat.node.textValue;\n if (typeof flat.node.label === \"string\") return flat.node.label;\n const row = itemRefs.current.get(flat.node.id)?.querySelector(\"[data-tree-row]\");\n return row?.textContent ?? \"\";\n };\n\n const findByText = (fromIndex: number, text: string): string | null => {\n const needle = text.toLocaleLowerCase();\n for (let i = 1; i <= visible.length; i++) {\n const flat = visible[(fromIndex + i) % visible.length];\n if (textOf(flat).trim().toLocaleLowerCase().startsWith(needle)) return flat.node.id;\n }\n return null;\n };\n\n const handleKeyDown = (e: KeyboardEvent<HTMLUListElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n const id = idOf(e.target);\n const flat = id ? byId.get(id) : undefined;\n if (!flat) return;\n const { node } = flat;\n const index = visible.findIndex((f) => f.node.id === node.id);\n const expandedNow = expandedSet.has(node.id);\n // Forward / backward along the reading direction, from the row itself.\n const step = horizontalStep(e.key, e.target as Element);\n // A space inside a type-ahead run is part of the name being typed (\"current a…\"),\n // not a request to select.\n const inRun = Date.now() - typeahead.current.at < TYPEAHEAD_MS && typeahead.current.text !== \"\";\n const key = e.key === \" \" && inRun ? \"typeahead\" : e.key;\n\n let handled = true;\n if (step === 1) {\n if (!isExpandable(node)) handled = false;\n else if (!expandedNow) open(node);\n else if (node.children?.length) focusRow(node.children[0].id);\n } else if (step === -1) {\n if (expandedNow) close(node);\n else if (flat.parentId) focusRow(flat.parentId);\n else handled = false;\n } else {\n switch (key) {\n case \"ArrowDown\":\n if (index < visible.length - 1) focusRow(visible[index + 1].node.id);\n break;\n case \"ArrowUp\":\n if (index > 0) focusRow(visible[index - 1].node.id);\n break;\n case \"Home\":\n if (visible.length) focusRow(visible[0].node.id);\n break;\n case \"End\":\n if (visible.length) focusRow(visible[visible.length - 1].node.id);\n break;\n case \"Enter\":\n case \" \":\n select(node);\n break;\n case \"*\": {\n // Every sibling at this level, as the pattern suggests.\n const siblings = flat.parentId ? (byId.get(flat.parentId)?.node.children ?? []) : items;\n const next = new Set(expandedSet);\n for (const s of siblings) if (isExpandable(s)) next.add(s.id);\n setExpanded(next);\n break;\n }\n default: {\n const printable = e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;\n if (!printable) {\n handled = false;\n break;\n }\n const now = Date.now();\n const run = now - typeahead.current.at < TYPEAHEAD_MS ? typeahead.current.text : \"\";\n typeahead.current = { text: run + e.key, at: now };\n const typed = typeahead.current.text;\n // \"aaa\" cycles through the rows starting with \"a\", as a file list does;\n // anything else extends the prefix, searched from the row after this one\n // (or from this one, when it still matches the longer prefix).\n const repeated = typed.length > 1 && [...typed].every((c) => c === typed[0]);\n const target = repeated\n ? findByText(index, typed[0])\n : typed.length > 1 && textOf(flat).trim().toLocaleLowerCase().startsWith(typed.toLocaleLowerCase())\n ? node.id\n : findByText(index, typed);\n if (target) focusRow(target);\n }\n }\n }\n if (handled) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleClick = (e: MouseEvent<HTMLUListElement>) => {\n onClick?.(e);\n const id = idOf(e.target);\n const flat = id ? byId.get(id) : undefined;\n if (!flat) return;\n // Controls a host rendered into a row (an action in `trailing`) are their own.\n const control = (e.target as Element).closest(\"button, a[href], input, select, textarea\");\n if (control && itemRefs.current.get(flat.node.id)?.contains(control)) return;\n setFocusedId(flat.node.id);\n if ((e.target as Element).closest(\"[data-tree-toggle]\")) {\n toggle(flat.node);\n return;\n }\n select(flat.node);\n };\n\n const renderNodes = (nodes: readonly TreeNode<T>[], level: number, path: string): ReactNode =>\n nodes.map((node, i) => {\n // Named by its own row, not by its content: a treeitem's content is the whole\n // open branch below it, and \"Assets Current assets 1020 Bank …\" is not a name.\n // A path of indices, because a host's id may hold spaces an idref cannot.\n const rowId = `${baseId}-${path}${i}`;\n const expandable = isExpandable(node);\n const isOpen = expandable && expandedSet.has(node.id);\n const isSelected = selectionMode !== \"none\" && selected === node.id;\n const isLoading = loading.has(node.id);\n const state: TreeItemState = {\n level,\n expanded: isOpen,\n selected: isSelected,\n expandable,\n loading: isLoading,\n disabled: Boolean(node.disabled),\n };\n return (\n <li\n key={node.id}\n ref={(el) => {\n if (el) itemRefs.current.set(node.id, el);\n else itemRefs.current.delete(node.id);\n }}\n role=\"treeitem\"\n data-tree-id={node.id}\n aria-labelledby={rowId}\n aria-level={level}\n aria-expanded={expandable ? isOpen : undefined}\n aria-selected={selectionMode === \"none\" ? undefined : isSelected}\n aria-disabled={node.disabled || undefined}\n aria-busy={isLoading || undefined}\n tabIndex={node.id === tabbable ? 0 : -1}\n onFocus={(e) => {\n // Only the row itself: a focus event bubbling up from a nested row, or from\n // a control inside this one, is not this row being focused.\n if (e.target === e.currentTarget) setFocusedId(node.id);\n }}\n // The ring goes on this row's own box, not the <li>: the <li> contains the\n // whole open branch below it, and ringing that would outline a subtree.\n className=\"outline-none [&:focus-visible>[data-tree-row]]:ring-2 [&:focus-visible>[data-tree-row]]:ring-[var(--brand)]\"\n >\n <TreeRow\n id={rowId}\n level={level}\n expanded={expandable ? isOpen : undefined}\n label={node.label}\n icon={node.icon}\n trailing={node.trailing}\n indent={indent}\n guides={indentGuides}\n selected={isSelected}\n loading={isLoading}\n className={cn(\n node.disabled ? \"cursor-not-allowed opacity-50\" : \"cursor-pointer hover:bg-[var(--bg-hover)]\",\n rowClassName,\n )}\n >\n {renderItem ? renderItem(node, state) : undefined}\n </TreeRow>\n {isOpen && (\n <ul role=\"group\">\n {/* Empty while lazy children load: a \"Loading…\" line in here would be\n a child that is not a treeitem, and the parent row already says\n `aria-busy` and shows the spinner. */}\n {node.children?.length ? renderNodes(node.children, level + 1, `${path}${i}-`) : null}\n </ul>\n )}\n </li>\n );\n });\n\n return (\n <ul\n {...rest}\n role=\"tree\"\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n className={cn(\"flex flex-col text-sm\", className)}\n >\n {renderNodes(items, 1, \"\")}\n </ul>\n );\n}\n"],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f;AAAA,cACA,QAAQ;AAAA,cACR,UAAU;AAAA,cACV,SAAS;AAAA,cACT,WAAW;AAAA,gBACT,KAAK,WAAW,kCAAkC;AAAA,gBAClD;AAAA,cACF;AAAA,cAEC,uBAAa,WAAW,MAAM,KAAK,IAAI;AAAA;AAAA,UAC1C;AAAA,UACC,UACC,oBAAC,QAAG,MAAK,SAIN,eAAK,UAAU,SAAS,YAAY,KAAK,UAAU,QAAQ,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,MACnF;AAAA;AAAA;AAAA,MA/CG,KAAK;AAAA,IAiDZ;AAAA,EAEJ,CAAC;AAEH,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,MAAK;AAAA,MACL,WAAW;AAAA,MACX,SAAS;AAAA,MACT,WAAW,GAAG,yBAAyB,SAAS;AAAA,MAE/C,sBAAY,OAAO,GAAG,EAAE;AAAA;AAAA,EAC3B;AAEJ;","names":[]}
@@ -23,8 +23,13 @@ interface TreemapNode {
23
23
  /** Overrides the by-index palette colour for this tile — e.g. to paint every child
24
24
  * in its parent group's colour, so the groups stay legible in one picture. A
25
25
  * concrete `#rrggbb` keeps the label ink measured; anything else (a CSS var) gets
26
- * `currentColor` ink, because there is nothing to measure. */
26
+ * `currentColor` ink, because there is nothing to measure — set `labelColor` then. */
27
27
  fill?: string;
28
+ /** The label's ink, for a `fill` the kit cannot measure (a `var()` or `color-mix()`):
29
+ * keksdose's recency plot fills with `color-mix(in srgb, var(--chart-1) N%,
30
+ * transparent)`, where `currentColor` put dark page text on full-strength indigo
31
+ * (~1.5:1). Wins over the measured ink when given. */
32
+ labelColor?: string;
28
33
  }
29
34
  /**
30
35
  * Everything a `<div>` takes reaches the chart's root (`ChartContainer`), so a test id
@@ -100,6 +105,8 @@ interface TreemapCellProps {
100
105
  height?: number;
101
106
  name?: string;
102
107
  fill?: string;
108
+ /** See {@link TreemapNode.labelColor}; recharts hands each node's fields to its cell. */
109
+ labelColor?: string;
103
110
  id?: string;
104
111
  onNodeClick?: (id: string, name: string) => void;
105
112
  redactNames?: boolean;
@@ -120,7 +127,7 @@ interface TreemapCellProps {
120
127
  * (`paint-order: stroke`), which defeats any inherited stroke and keeps the text solid
121
128
  * where it overlaps a lighter or darker part of its own tile.
122
129
  */
123
- declare function TreemapCell({ depth, x, y, width, height, name, fill, id, onNodeClick, redactNames, nodeNote, dir, }: TreemapCellProps): react.JSX.Element | null;
130
+ declare function TreemapCell({ depth, x, y, width, height, name, fill, labelColor, id, onNodeClick, redactNames, nodeNote, dir, }: TreemapCellProps): react.JSX.Element | null;
124
131
  /**
125
132
  * Tile chart: one rectangle per {@link TreemapNode}, sized by `value`, coloured by
126
133
  * index from the chart ramp (or by the node's own `fill`), labelled in whichever of the
@@ -44,6 +44,7 @@ function TreemapCell({
44
44
  height = 0,
45
45
  name,
46
46
  fill,
47
+ labelColor,
47
48
  id,
48
49
  onNodeClick,
49
50
  redactNames,
@@ -56,7 +57,7 @@ function TreemapCell({
56
57
  const pw = Math.round(width);
57
58
  const ph = Math.round(height);
58
59
  const tileFill = fill ?? "var(--chart-1)";
59
- const ink = textOn(tileFill);
60
+ const ink = labelColor ?? textOn(tileFill);
60
61
  const label = pw >= 44 && ph >= 20 ? fitLabel(name ?? "", pw, LABEL_FONT_SIZE) : null;
61
62
  const rawNote = id != null && nodeNote ? nodeNote(id) : void 0;
62
63
  const note = label != null && rawNote != null && ph >= 36 ? fitLabel(rawNote, pw, NOTE_FONT_SIZE) : null;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/treemap.tsx"],"sourcesContent":["// A tile chart (\"treemap\"): one rectangle per node, its AREA the node's share of what\n// is drawn. Lifted out of keksdose's reports, where five cards drew it (spending by\n// group and by category, net worth by account and by type, allocation, payees, food\n// groups) — every domain word is gone and every string it could print is a prop.\n//\n// It uses the kit's own chart shell (`ChartContainer`, `ChartTooltipContent`) and the\n// kit's own ink rule (`textOn`), so it re-skins with the palette like every other\n// chart. The one thing it cannot take from a CSS var is the tile colour: the label ink\n// is MEASURED against the fill, and a `var(--chart-3)` string measures as nothing — see\n// `useChartTokenHex` below for how the concrete hex is found instead.\nimport { useLayoutEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { ComponentProps, ComponentPropsWithoutRef, KeyboardEvent, ReactNode } from \"react\";\nimport { Treemap as RechartsTreemap } from \"recharts\";\nimport { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from \"./chart\";\nimport { PALETTE_HEX, textOn } from \"../theme/chart-palette\";\nimport { parseHex } from \"../theme/color\";\nimport { dirOf, type Direction } from \"../lib/direction\";\n\n/**\n * One tile.\n *\n * `value`, not keksdose's `total`: a treemap's areas are not always money (keksdose\n * already sizes one by transaction COUNT), and `value` is the word every other chart\n * in recharts uses for the number a mark is sized by. Migrating is a rename at the\n * mapping step — `{ id, name, value: row.total }`.\n */\nexport interface TreemapNode {\n /** Stable key, handed back by {@link TreemapProps.onNodeClick} and\n * {@link TreemapProps.nodeNote}. Names can collide; ids must not. */\n id: string;\n name: string;\n /** The tile's area. A node whose value is not a positive finite number is NOT\n * drawn — an area cannot be negative, and recharts lays a negative size out as\n * nonsense rather than refusing it. Saying so is the caller's job: a group that\n * vanishes silently between two views of the same data is a bug report. */\n value: number;\n /** Overrides the by-index palette colour for this tile — e.g. to paint every child\n * in its parent group's colour, so the groups stay legible in one picture. A\n * concrete `#rrggbb` keeps the label ink measured; anything else (a CSS var) gets\n * `currentColor` ink, because there is nothing to measure. */\n fill?: string;\n}\n\n/**\n * Everything a `<div>` takes reaches the chart's root (`ChartContainer`), so a test id\n * or a `data-tour` anchor can find it. `children` is the chart's own.\n */\nexport interface TreemapProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\"> {\n data: TreemapNode[];\n /**\n * Formats a node's value in the tooltip. Handed the node's SHARE of what is drawn\n * (0–1) as a second argument, because a tile is read for how big it is relative to\n * the rest, and \"€412.30\" alone makes the reader estimate that ratio off the areas.\n * The share is `undefined` when the drawn total is not positive.\n *\n * Default: the bare number through `Intl.NumberFormat` in the runtime's locale. A\n * host that has a currency or a locale passes this — the kit knows neither.\n */\n valueFormatter?: (value: number, share: number | undefined) => ReactNode;\n /** Chart height in px. Default 320. */\n height?: number;\n /** A tile was activated — by click, or by Enter/Space on a focused tile. Setting\n * this makes every tile a focusable `role=\"button\"` named by its node name. */\n onNodeClick?: (id: string, name: string) => void;\n /**\n * The node names are the user's own data (payees, not categories): the tile labels\n * and the whole tooltip bubble get `data-private`, the same attribute the kit's\n * `Tooltip redact` and `ChartTooltipContent`'s value cell carry, so the host's one\n * privacy rule reaches them. Off by default — a category name is a label of the app.\n */\n redactNames?: boolean;\n /**\n * A second, smaller line under a tile's label — one extra figure per node that the\n * name cannot carry (a year-on-year `+12%`, `new`). Return `undefined` for a node\n * with nothing to add. Never tagged `data-private`: a ratio reveals no amount.\n *\n * ON THE TILE rather than in the tooltip, for two reasons. The tooltip identifies a\n * node by name or by raw value, so a per-node note would be keyed on an amount (two\n * nodes of equal size would swap notes). And a tooltip is a pointer affordance: a\n * phone never hovers, so a figure that only exists on hover does not exist there.\n */\n nodeNote?: (id: string) => string | undefined;\n /**\n * Draw at most this many tiles (the first N drawable nodes, in the order given —\n * sort first). Unbounded by default. A tile under ~44x20px has no room for a label,\n * and a map made of unlabelled rectangles answers nothing; around 24 is where the\n * smallest tile of a skewed series reaches that floor on a phone-width card. The\n * caller owns the \"N more not shown\" line, since it knows how many it passed.\n */\n maxTiles?: number;\n /**\n * The categorical ramp tiles take by index, as concrete hex. Default: the page's\n * live `--chart-1…9` tokens (see `useChartTokenHex`). Pass one when the host\n * already holds the active palette — e.g. `createPaletteStore`'s `useChartHex()` —\n * so a caller colouring a legend beside the map is guaranteed the same list.\n */\n colors?: readonly string[];\n}\n\n// ── The categorical ramp, as concrete hex ──────────────────────────────────\n//\n// The label ink is measured against the tile's fill, so the fill has to be a colour\n// and not a reference to one. keksdose read it from its palette STORE, which is an\n// app object the kit cannot import. What the kit does own is the token layer: whether\n// a palette arrives through `applyTokenSet` (inline properties on <html>) or through\n// tokens.css (`:root` / `.dark`), the resolved `--chart-N` on <html> is the colour\n// every other chart on the page is being painted with. So that is what is read, and\n// re-read whenever <html>'s class or style changes — which is exactly when a theme\n// toggle or a palette switch lands.\n\nconst CHART_TOKENS = 9;\n\n/** The resolved ramp, joined into ONE string so `useSyncExternalStore` compares a\n * primitive: a fresh array per read would never be `Object.is`-equal to the last and\n * would re-render forever. */\nfunction readChartTokens(): string {\n const root = document.documentElement;\n const fallback = root.classList.contains(\"dark\") ? PALETTE_HEX.dark : PALETTE_HEX.light;\n const style = getComputedStyle(root);\n return Array.from({ length: CHART_TOKENS }, (_, i) => {\n const v = style.getPropertyValue(`--chart-${i + 1}`).trim();\n // An unresolved token (a host that never loaded tokens.css, a test DOM) falls\n // back to the built-in ramp for the current theme rather than to no colour.\n return parseHex(v) ? v : fallback[i];\n }).join(\",\");\n}\n\nfunction subscribeChartTokens(onChange: () => void): () => void {\n const observer = new MutationObserver(onChange);\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"data-theme\"],\n });\n return () => observer.disconnect();\n}\n\nconst SERVER_TOKENS = PALETTE_HEX.light.join(\",\");\n\nfunction useChartTokenHex(): string[] {\n const joined = useSyncExternalStore(subscribeChartTokens, readChartTokens, () => SERVER_TOKENS);\n return joined.split(\",\");\n}\n\n// ── Tile ──────────────────────────────────────────────────────────────────\n\nconst LABEL_FONT_SIZE = 12;\n/** The optional second line, a step down from the name so the tile reads name-first. */\nconst NOTE_FONT_SIZE = 11;\n\n/**\n * Fit a label to its tile: the text itself when it fits, an ellipsised head when it\n * does not, `null` when not even three characters would. Without this a long name ran\n * on across its neighbours and collided with THEIR labels. 0.58em is the average\n * advance of a UI sans at this weight; it only needs to be close, since the tile keeps\n * 6px of padding either side. The full name stays in the tooltip.\n */\nexport function fitLabel(name: string, boxWidth: number, fontSize: number): string | null {\n const max = Math.floor((boxWidth - 12) / (fontSize * 0.58));\n if (max < 3) return null;\n return name.length <= max ? name : `${name.slice(0, max - 1).trimEnd()}…`;\n}\n\n/** What recharts hands a `content` element for each node, plus the three options the\n * chart forwards. Everything optional because recharts clones the element it was\n * given and fills the geometry in — the element as written carries only the options. */\nexport interface TreemapCellProps {\n depth?: number;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n name?: string;\n fill?: string;\n id?: string;\n onNodeClick?: (id: string, name: string) => void;\n redactNames?: boolean;\n nodeNote?: (id: string) => string | undefined;\n /** The page's reading direction, which `Treemap` reads off its own root. In `rtl`\n * the label stands in the tile's top RIGHT corner and is shaped right-to-left, so a\n * clipped name ends in its ellipsis on the reading end. Default `ltr`. */\n dir?: Direction;\n}\n\n/**\n * One tile. Exported so a caller drawing its own recharts `<Treemap>` gets the same\n * label rules.\n *\n * recharts' default cell inherits the chart-level `stroke`, an SVG presentation\n * attribute that lands on the `<svg>` root and cascades into the label — so the glyphs\n * were painted with a 1px outline ON TOP of themselves, which reads as blur. This cell\n * draws its own label with a halo in the TILE colour painted BEHIND the fill\n * (`paint-order: stroke`), which defeats any inherited stroke and keeps the text solid\n * where it overlaps a lighter or darker part of its own tile.\n */\nexport function TreemapCell({\n depth,\n x = 0,\n y = 0,\n width = 0,\n height = 0,\n name,\n fill,\n id,\n onNodeClick,\n redactNames,\n nodeNote,\n dir = \"ltr\",\n}: TreemapCellProps) {\n // Depth 0 is recharts' synthetic root, which spans the whole chart.\n if (!depth) return null;\n // Whole pixels: a rect on a half pixel renders its edge across two half-lit\n // columns, and the text baseline inherits that blur.\n const px = Math.round(x);\n const py = Math.round(y);\n const pw = Math.round(width);\n const ph = Math.round(height);\n const tileFill = fill ?? \"var(--chart-1)\";\n const ink = textOn(tileFill);\n // Below ~44x20 there is no room for a readable word, so no label at all rather than\n // a one-letter stub bleeding over the tile edge.\n const label = pw >= 44 && ph >= 20 ? fitLabel(name ?? \"\", pw, LABEL_FONT_SIZE) : null;\n // Only under a label that is itself drawn — a stray \"+12%\" on an unnamed rectangle\n // names nothing — and only where a second baseline fits: the note's baseline sits\n // 29px down and an 11px glyph hangs ~2px below it, so 36 leaves the same ~5px under\n // the note that the label keeps under itself at the 20px floor.\n const rawNote = id != null && nodeNote ? nodeNote(id) : undefined;\n const note =\n label != null && rawNote != null && ph >= 36 ? fitLabel(rawNote, pw, NOTE_FONT_SIZE) : null;\n // The label's START edge, 6px in from the tile's. The tiles themselves are laid out\n // physically (the plot is not mirrored, see `ChartContainer`) and the chart's SVG is\n // pinned `ltr`, so the direction is set on each <text> explicitly: `start` is then\n // the right end in RTL, and the label grows leftwards from the tile's right edge.\n const textX = dir === \"rtl\" ? px + pw - 6 : px + 6;\n const activate = id != null && onNodeClick ? () => onNodeClick(id, name ?? \"\") : undefined;\n const onKeyDown = activate\n ? (e: KeyboardEvent<SVGGElement>) => {\n if (e.key !== \"Enter\" && e.key !== \" \") return;\n e.preventDefault();\n activate();\n }\n : undefined;\n return (\n <g\n onClick={activate}\n onKeyDown={onKeyDown}\n // A clickable tile is a button to a keyboard and a screen reader too; the\n // drilldown it opens was mouse-only in the app this came from. Named by the node\n // name, which is also why the group carries `data-private` under `redactNames`.\n role={activate ? \"button\" : undefined}\n tabIndex={activate ? 0 : undefined}\n aria-label={activate ? name : undefined}\n data-private={activate && redactNames ? \"\" : undefined}\n cursor={activate ? \"pointer\" : undefined}\n // CSS beats a presentation attribute, so this recolours the rect's own stroke\n // for as long as the tile has keyboard focus.\n className={activate ? \"outline-none [&:focus-visible>rect]:stroke-[var(--brand)]\" : undefined}\n >\n {/* The 2px gutter is the card showing through, not a white grid — on a dark\n surface white lines glare harder than the tiles. */}\n <rect\n x={px}\n y={py}\n width={pw}\n height={ph}\n fill={tileFill}\n stroke=\"var(--bg-surface)\"\n strokeWidth={2}\n rx={3}\n />\n {label != null && (\n <text\n // A plain attribute, so the host's `[data-private]` rule reaches an SVG\n // <text> exactly as it reaches a table cell.\n data-private={redactNames ? \"\" : undefined}\n x={textX}\n y={py + 15}\n direction={dir}\n fill={ink}\n stroke={tileFill}\n strokeWidth={2.5}\n strokeLinejoin=\"round\"\n paintOrder=\"stroke\"\n fontSize={LABEL_FONT_SIZE}\n fontWeight={600}\n style={{ pointerEvents: \"none\" }}\n >\n {label}\n </text>\n )}\n {note != null && (\n <text\n x={textX}\n y={py + 29}\n direction={dir}\n fill={ink}\n fillOpacity={0.85}\n stroke={tileFill}\n strokeWidth={2.5}\n strokeLinejoin=\"round\"\n paintOrder=\"stroke\"\n fontSize={NOTE_FONT_SIZE}\n fontWeight={500}\n style={{ pointerEvents: \"none\" }}\n >\n {note}\n </text>\n )}\n </g>\n );\n}\n\n// ── Chart ─────────────────────────────────────────────────────────────────\n\n// Nodes carry their own `fill`, and `ChartTooltipContent` falls back to it for the\n// swatch, so no series config is needed.\nconst TREEMAP_CONFIG: ChartConfig = {};\n\n/**\n * The shared tooltip with the whole bubble tagged `data-private`, for names that are\n * the user's own data.\n *\n * The bubble, not just the name: `ChartTooltipContent` prints the name either from\n * `item.name` or from a config `label`, and only the config route could be tagged — but\n * a config entry keyed by a payee name is not a CSS identifier, and `ChartStyle` would\n * (rightly) refuse it. The bubble holds the name and the value, and the value cell is\n * already `data-private`, so tagging the wrapper hides nothing extra.\n *\n * recharts CLONES the `content` element to inject `active`/`payload`, so this has to BE\n * that element — a `<div>` wrapped around `<ChartTooltipContent />` in the JSX would\n * take those props itself and hand the tooltip nothing.\n */\nfunction RedactedTooltipContent(props: ComponentProps<typeof ChartTooltipContent>) {\n return (\n <div data-private>\n <ChartTooltipContent {...props} />\n </div>\n );\n}\n\nconst DEFAULT_NUMBER = new Intl.NumberFormat();\n\n/**\n * Tile chart: one rectangle per {@link TreemapNode}, sized by `value`, coloured by\n * index from the chart ramp (or by the node's own `fill`), labelled in whichever of the\n * kit's two inks measures better against it. Hover shows the name and the formatted\n * value; `onNodeClick` turns the tiles into buttons.\n *\n * Renders nothing when no node has a positive value — an empty box is a hole in the\n * card, and the caller's own sentence is the better answer there.\n *\n * Needs `recharts`, like everything behind `@eifi1/ui-kit/chart`.\n */\nexport function Treemap({\n data,\n valueFormatter,\n height = 320,\n onNodeClick,\n redactNames = false,\n nodeNote,\n maxTiles,\n colors,\n style,\n ...rest\n}: TreemapProps) {\n const tokenHex = useChartTokenHex();\n // Read off the DOM after mount: the `dir` a treemap sits under is an ancestor's\n // attribute, and SVG text anchoring cannot follow it by CSS (see TreemapCell). Again\n // on new data, because a map that had nothing to draw rendered no root to read.\n const rootRef = useRef<HTMLDivElement>(null);\n const [dir, setDir] = useState<Direction>(\"ltr\");\n useLayoutEffect(() => {\n setDir(dirOf(rootRef.current));\n }, [data]);\n const ramp = colors && colors.length > 0 ? colors : tokenHex;\n // Coloured by index into `data` AS GIVEN, before anything is dropped: a caller\n // painting a legend or a second map from the same list must land on the same hue\n // for the same row, and filtering first would shift every colour after a gap.\n const nodes = data\n .map((d, idx) => ({\n id: d.id,\n name: d.name,\n size: d.value,\n fill: d.fill ?? ramp[idx % ramp.length],\n }))\n .filter((n) => Number.isFinite(n.size) && n.size > 0)\n .slice(0, maxTiles ?? undefined);\n if (nodes.length === 0) return null;\n\n // The share is of what is DRAWN, so it always reads as \"of this picture\".\n const total = nodes.reduce((acc, n) => acc + n.size, 0);\n const format = (v: number): ReactNode => {\n const share = total > 0 ? v / total : undefined;\n return valueFormatter ? valueFormatter(v, share) : DEFAULT_NUMBER.format(v);\n };\n const Content = redactNames ? RedactedTooltipContent : ChartTooltipContent;\n return (\n <ChartContainer {...rest} ref={rootRef} config={TREEMAP_CONFIG} style={{ ...style, height }}>\n {/* No chart-level `stroke`: recharts spreads it onto the <svg> root, from where\n it inherits into every label (see TreemapCell). Each cell strokes its own rect. */}\n <RechartsTreemap\n data={nodes}\n dataKey=\"size\"\n fill=\"var(--chart-1)\"\n isAnimationActive={false}\n content={\n <TreemapCell onNodeClick={onNodeClick} redactNames={redactNames} nodeNote={nodeNote} dir={dir} />\n }\n >\n <ChartTooltip content={<Content hideLabel valueFormatter={format} />} />\n </RechartsTreem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AI,SAAoB,KAAK;AAC/C,kBAAgB,MAAM;AACpB,WAAO,MAAM,QAAQ,OAAO,CAAC;AAAA,EAC/B,GAAG,CAAC,IAAI,CAAC;AACT,QAAM,OAAO,UAAU,OAAO,SAAS,IAAI,SAAS;AAIpD,QAAM,QAAQ,KACX,IAAI,CAAC,GAAG,SAAS;AAAA,IAChB,IAAI,EAAE;AAAA,IACN,MAAM,EAAE;AAAA,IACR,MAAM,EAAE;AAAA,IACR,MAAM,EAAE,QAAQ,KAAK,MAAM,KAAK,MAAM;AAAA,EACxC,EAAE,EACD,OAAO,CAAC,MAAM,OAAO,SAAS,EAAE,IAAI,KAAK,EAAE,OAAO,CAAC,EACnD,MAAM,GAAG,YAAY,MAAS;AACjC,MAAI,MAAM,WAAW,EAAG,QAAO;AAG/B,QAAM,QAAQ,MAAM,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,MAAM,CAAC;AACtD,QAAM,SAAS,CAAC,MAAyB;AACvC,UAAM,QAAQ,QAAQ,IAAI,IAAI,QAAQ;AACtC,WAAO,iBAAiB,eAAe,GAAG,KAAK,IAAI,eAAe,OAAO,CAAC;AAAA,EAC5E;AACA,QAAM,UAAU,cAAc,yBAAyB;AACvD,SACE,oBAAC,kBAAgB,GAAG,MAAM,KAAK,SAAS,QAAQ,gBAAgB,OAAO,EAAE,GAAG,OAAO,OAAO,GAGxF;AAAA,IAAC;AAAA;AAAA,MACC,MAAM;AAAA,MACN,SAAQ;AAAA,MACR,MAAK;AAAA,MACL,mBAAmB;AAAA,MACnB,SACE,oBAAC,eAAY,aAA0B,aAA0B,UAAoB,KAAU;AAAA,MAGjG,8BAAC,gBAAa,SAAS,oBAAC,WAAQ,WAAS,MAAC,gBAAgB,QAAQ,GAAI;AAAA;AAAA,EACxE,GACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/treemap.tsx"],"sourcesContent":["// A tile chart (\"treemap\"): one rectangle per node, its AREA the node's share of what\n// is drawn. Lifted out of keksdose's reports, where five cards drew it (spending by\n// group and by category, net worth by account and by type, allocation, payees, food\n// groups) — every domain word is gone and every string it could print is a prop.\n//\n// It uses the kit's own chart shell (`ChartContainer`, `ChartTooltipContent`) and the\n// kit's own ink rule (`textOn`), so it re-skins with the palette like every other\n// chart. The one thing it cannot take from a CSS var is the tile colour: the label ink\n// is MEASURED against the fill, and a `var(--chart-3)` string measures as nothing — see\n// `useChartTokenHex` below for how the concrete hex is found instead.\nimport { useLayoutEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { ComponentProps, ComponentPropsWithoutRef, KeyboardEvent, ReactNode } from \"react\";\nimport { Treemap as RechartsTreemap } from \"recharts\";\nimport { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from \"./chart\";\nimport { PALETTE_HEX, textOn } from \"../theme/chart-palette\";\nimport { parseHex } from \"../theme/color\";\nimport { dirOf, type Direction } from \"../lib/direction\";\n\n/**\n * One tile.\n *\n * `value`, not keksdose's `total`: a treemap's areas are not always money (keksdose\n * already sizes one by transaction COUNT), and `value` is the word every other chart\n * in recharts uses for the number a mark is sized by. Migrating is a rename at the\n * mapping step — `{ id, name, value: row.total }`.\n */\nexport interface TreemapNode {\n /** Stable key, handed back by {@link TreemapProps.onNodeClick} and\n * {@link TreemapProps.nodeNote}. Names can collide; ids must not. */\n id: string;\n name: string;\n /** The tile's area. A node whose value is not a positive finite number is NOT\n * drawn — an area cannot be negative, and recharts lays a negative size out as\n * nonsense rather than refusing it. Saying so is the caller's job: a group that\n * vanishes silently between two views of the same data is a bug report. */\n value: number;\n /** Overrides the by-index palette colour for this tile — e.g. to paint every child\n * in its parent group's colour, so the groups stay legible in one picture. A\n * concrete `#rrggbb` keeps the label ink measured; anything else (a CSS var) gets\n * `currentColor` ink, because there is nothing to measure — set `labelColor` then. */\n fill?: string;\n /** The label's ink, for a `fill` the kit cannot measure (a `var()` or `color-mix()`):\n * keksdose's recency plot fills with `color-mix(in srgb, var(--chart-1) N%,\n * transparent)`, where `currentColor` put dark page text on full-strength indigo\n * (~1.5:1). Wins over the measured ink when given. */\n labelColor?: string;\n}\n\n/**\n * Everything a `<div>` takes reaches the chart's root (`ChartContainer`), so a test id\n * or a `data-tour` anchor can find it. `children` is the chart's own.\n */\nexport interface TreemapProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\"> {\n data: TreemapNode[];\n /**\n * Formats a node's value in the tooltip. Handed the node's SHARE of what is drawn\n * (0–1) as a second argument, because a tile is read for how big it is relative to\n * the rest, and \"€412.30\" alone makes the reader estimate that ratio off the areas.\n * The share is `undefined` when the drawn total is not positive.\n *\n * Default: the bare number through `Intl.NumberFormat` in the runtime's locale. A\n * host that has a currency or a locale passes this — the kit knows neither.\n */\n valueFormatter?: (value: number, share: number | undefined) => ReactNode;\n /** Chart height in px. Default 320. */\n height?: number;\n /** A tile was activated — by click, or by Enter/Space on a focused tile. Setting\n * this makes every tile a focusable `role=\"button\"` named by its node name. */\n onNodeClick?: (id: string, name: string) => void;\n /**\n * The node names are the user's own data (payees, not categories): the tile labels\n * and the whole tooltip bubble get `data-private`, the same attribute the kit's\n * `Tooltip redact` and `ChartTooltipContent`'s value cell carry, so the host's one\n * privacy rule reaches them. Off by default — a category name is a label of the app.\n */\n redactNames?: boolean;\n /**\n * A second, smaller line under a tile's label — one extra figure per node that the\n * name cannot carry (a year-on-year `+12%`, `new`). Return `undefined` for a node\n * with nothing to add. Never tagged `data-private`: a ratio reveals no amount.\n *\n * ON THE TILE rather than in the tooltip, for two reasons. The tooltip identifies a\n * node by name or by raw value, so a per-node note would be keyed on an amount (two\n * nodes of equal size would swap notes). And a tooltip is a pointer affordance: a\n * phone never hovers, so a figure that only exists on hover does not exist there.\n */\n nodeNote?: (id: string) => string | undefined;\n /**\n * Draw at most this many tiles (the first N drawable nodes, in the order given —\n * sort first). Unbounded by default. A tile under ~44x20px has no room for a label,\n * and a map made of unlabelled rectangles answers nothing; around 24 is where the\n * smallest tile of a skewed series reaches that floor on a phone-width card. The\n * caller owns the \"N more not shown\" line, since it knows how many it passed.\n */\n maxTiles?: number;\n /**\n * The categorical ramp tiles take by index, as concrete hex. Default: the page's\n * live `--chart-1…9` tokens (see `useChartTokenHex`). Pass one when the host\n * already holds the active palette — e.g. `createPaletteStore`'s `useChartHex()` —\n * so a caller colouring a legend beside the map is guaranteed the same list.\n */\n colors?: readonly string[];\n}\n\n// ── The categorical ramp, as concrete hex ──────────────────────────────────\n//\n// The label ink is measured against the tile's fill, so the fill has to be a colour\n// and not a reference to one. keksdose read it from its palette STORE, which is an\n// app object the kit cannot import. What the kit does own is the token layer: whether\n// a palette arrives through `applyTokenSet` (inline properties on <html>) or through\n// tokens.css (`:root` / `.dark`), the resolved `--chart-N` on <html> is the colour\n// every other chart on the page is being painted with. So that is what is read, and\n// re-read whenever <html>'s class or style changes — which is exactly when a theme\n// toggle or a palette switch lands.\n\nconst CHART_TOKENS = 9;\n\n/** The resolved ramp, joined into ONE string so `useSyncExternalStore` compares a\n * primitive: a fresh array per read would never be `Object.is`-equal to the last and\n * would re-render forever. */\nfunction readChartTokens(): string {\n const root = document.documentElement;\n const fallback = root.classList.contains(\"dark\") ? PALETTE_HEX.dark : PALETTE_HEX.light;\n const style = getComputedStyle(root);\n return Array.from({ length: CHART_TOKENS }, (_, i) => {\n const v = style.getPropertyValue(`--chart-${i + 1}`).trim();\n // An unresolved token (a host that never loaded tokens.css, a test DOM) falls\n // back to the built-in ramp for the current theme rather than to no colour.\n return parseHex(v) ? v : fallback[i];\n }).join(\",\");\n}\n\nfunction subscribeChartTokens(onChange: () => void): () => void {\n const observer = new MutationObserver(onChange);\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"data-theme\"],\n });\n return () => observer.disconnect();\n}\n\nconst SERVER_TOKENS = PALETTE_HEX.light.join(\",\");\n\nfunction useChartTokenHex(): string[] {\n const joined = useSyncExternalStore(subscribeChartTokens, readChartTokens, () => SERVER_TOKENS);\n return joined.split(\",\");\n}\n\n// ── Tile ──────────────────────────────────────────────────────────────────\n\nconst LABEL_FONT_SIZE = 12;\n/** The optional second line, a step down from the name so the tile reads name-first. */\nconst NOTE_FONT_SIZE = 11;\n\n/**\n * Fit a label to its tile: the text itself when it fits, an ellipsised head when it\n * does not, `null` when not even three characters would. Without this a long name ran\n * on across its neighbours and collided with THEIR labels. 0.58em is the average\n * advance of a UI sans at this weight; it only needs to be close, since the tile keeps\n * 6px of padding either side. The full name stays in the tooltip.\n */\nexport function fitLabel(name: string, boxWidth: number, fontSize: number): string | null {\n const max = Math.floor((boxWidth - 12) / (fontSize * 0.58));\n if (max < 3) return null;\n return name.length <= max ? name : `${name.slice(0, max - 1).trimEnd()}…`;\n}\n\n/** What recharts hands a `content` element for each node, plus the three options the\n * chart forwards. Everything optional because recharts clones the element it was\n * given and fills the geometry in — the element as written carries only the options. */\nexport interface TreemapCellProps {\n depth?: number;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n name?: string;\n fill?: string;\n /** See {@link TreemapNode.labelColor}; recharts hands each node's fields to its cell. */\n labelColor?: string;\n id?: string;\n onNodeClick?: (id: string, name: string) => void;\n redactNames?: boolean;\n nodeNote?: (id: string) => string | undefined;\n /** The page's reading direction, which `Treemap` reads off its own root. In `rtl`\n * the label stands in the tile's top RIGHT corner and is shaped right-to-left, so a\n * clipped name ends in its ellipsis on the reading end. Default `ltr`. */\n dir?: Direction;\n}\n\n/**\n * One tile. Exported so a caller drawing its own recharts `<Treemap>` gets the same\n * label rules.\n *\n * recharts' default cell inherits the chart-level `stroke`, an SVG presentation\n * attribute that lands on the `<svg>` root and cascades into the label — so the glyphs\n * were painted with a 1px outline ON TOP of themselves, which reads as blur. This cell\n * draws its own label with a halo in the TILE colour painted BEHIND the fill\n * (`paint-order: stroke`), which defeats any inherited stroke and keeps the text solid\n * where it overlaps a lighter or darker part of its own tile.\n */\nexport function TreemapCell({\n depth,\n x = 0,\n y = 0,\n width = 0,\n height = 0,\n name,\n fill,\n labelColor,\n id,\n onNodeClick,\n redactNames,\n nodeNote,\n dir = \"ltr\",\n}: TreemapCellProps) {\n // Depth 0 is recharts' synthetic root, which spans the whole chart.\n if (!depth) return null;\n // Whole pixels: a rect on a half pixel renders its edge across two half-lit\n // columns, and the text baseline inherits that blur.\n const px = Math.round(x);\n const py = Math.round(y);\n const pw = Math.round(width);\n const ph = Math.round(height);\n const tileFill = fill ?? \"var(--chart-1)\";\n const ink = labelColor ?? textOn(tileFill);\n // Below ~44x20 there is no room for a readable word, so no label at all rather than\n // a one-letter stub bleeding over the tile edge.\n const label = pw >= 44 && ph >= 20 ? fitLabel(name ?? \"\", pw, LABEL_FONT_SIZE) : null;\n // Only under a label that is itself drawn — a stray \"+12%\" on an unnamed rectangle\n // names nothing — and only where a second baseline fits: the note's baseline sits\n // 29px down and an 11px glyph hangs ~2px below it, so 36 leaves the same ~5px under\n // the note that the label keeps under itself at the 20px floor.\n const rawNote = id != null && nodeNote ? nodeNote(id) : undefined;\n const note =\n label != null && rawNote != null && ph >= 36 ? fitLabel(rawNote, pw, NOTE_FONT_SIZE) : null;\n // The label's START edge, 6px in from the tile's. The tiles themselves are laid out\n // physically (the plot is not mirrored, see `ChartContainer`) and the chart's SVG is\n // pinned `ltr`, so the direction is set on each <text> explicitly: `start` is then\n // the right end in RTL, and the label grows leftwards from the tile's right edge.\n const textX = dir === \"rtl\" ? px + pw - 6 : px + 6;\n const activate = id != null && onNodeClick ? () => onNodeClick(id, name ?? \"\") : undefined;\n const onKeyDown = activate\n ? (e: KeyboardEvent<SVGGElement>) => {\n if (e.key !== \"Enter\" && e.key !== \" \") return;\n e.preventDefault();\n activate();\n }\n : undefined;\n return (\n <g\n onClick={activate}\n onKeyDown={onKeyDown}\n // A clickable tile is a button to a keyboard and a screen reader too; the\n // drilldown it opens was mouse-only in the app this came from. Named by the node\n // name, which is also why the group carries `data-private` under `redactNames`.\n role={activate ? \"button\" : undefined}\n tabIndex={activate ? 0 : undefined}\n aria-label={activate ? name : undefined}\n data-private={activate && redactNames ? \"\" : undefined}\n cursor={activate ? \"pointer\" : undefined}\n // CSS beats a presentation attribute, so this recolours the rect's own stroke\n // for as long as the tile has keyboard focus.\n className={activate ? \"outline-none [&:focus-visible>rect]:stroke-[var(--brand)]\" : undefined}\n >\n {/* The 2px gutter is the card showing through, not a white grid — on a dark\n surface white lines glare harder than the tiles. */}\n <rect\n x={px}\n y={py}\n width={pw}\n height={ph}\n fill={tileFill}\n stroke=\"var(--bg-surface)\"\n strokeWidth={2}\n rx={3}\n />\n {label != null && (\n <text\n // A plain attribute, so the host's `[data-private]` rule reaches an SVG\n // <text> exactly as it reaches a table cell.\n data-private={redactNames ? \"\" : undefined}\n x={textX}\n y={py + 15}\n direction={dir}\n fill={ink}\n stroke={tileFill}\n strokeWidth={2.5}\n strokeLinejoin=\"round\"\n paintOrder=\"stroke\"\n fontSize={LABEL_FONT_SIZE}\n fontWeight={600}\n style={{ pointerEvents: \"none\" }}\n >\n {label}\n </text>\n )}\n {note != null && (\n <text\n x={textX}\n y={py + 29}\n direction={dir}\n fill={ink}\n fillOpacity={0.85}\n stroke={tileFill}\n strokeWidth={2.5}\n strokeLinejoin=\"round\"\n paintOrder=\"stroke\"\n fontSize={NOTE_FONT_SIZE}\n fontWeight={500}\n style={{ pointerEvents: \"none\" }}\n >\n {note}\n </text>\n )}\n </g>\n );\n}\n\n// ── Chart ─────────────────────────────────────────────────────────────────\n\n// Nodes carry their own `fill`, and `ChartTooltipContent` falls back to it for the\n// swatch, so no series config is needed.\nconst TREEMAP_CONFIG: ChartConfig = {};\n\n/**\n * The shared tooltip with the whole bubble tagged `data-private`, for names that are\n * the user's own data.\n *\n * The bubble, not just the name: `ChartTooltipContent` prints the name either from\n * `item.name` or from a config `label`, and only the config route could be tagged — but\n * a config entry keyed by a payee name is not a CSS identifier, and `ChartStyle` would\n * (rightly) refuse it. The bubble holds the name and the value, and the value cell is\n * already `data-private`, so tagging the wrapper hides nothing extra.\n *\n * recharts CLONES the `content` element to inject `active`/`payload`, so this has to BE\n * that element — a `<div>` wrapped around `<ChartTooltipContent />` in the JSX would\n * take those props itself and hand the tooltip nothing.\n */\nfunction RedactedTooltipContent(props: ComponentProps<typeof ChartTooltipContent>) {\n return (\n <div data-private>\n <ChartTooltipContent {...props} />\n </div>\n );\n}\n\nconst DEFAULT_NUMBER = new Intl.NumberFormat();\n\n/**\n * Tile chart: one rectangle per {@link TreemapNode}, sized by `value`, coloured by\n * index from the chart ramp (or by the node's own `fill`), labelled in whichever of the\n * kit's two inks measures better against it. Hover shows the name and the formatted\n * value; `onNodeClick` turns the tiles into buttons.\n *\n * Renders nothing when no node has a positive value — an empty box is a hole in the\n * card, and the caller's own sentence is the better answer there.\n *\n * Needs `recharts`, like everything behind `@eifi1/ui-kit/chart`.\n */\nexport function Treemap({\n data,\n valueFormatter,\n height = 320,\n onNodeClick,\n redactNames = false,\n nodeNote,\n maxTiles,\n colors,\n style,\n ...rest\n}: TreemapProps) {\n const tokenHex = useChartTokenHex();\n // Read off the DOM after mount: the `dir` a treemap sits under is an ancestor's\n // attribute, and SVG text anchoring cannot follow it by CSS (see TreemapCell). Again\n // on new data, because a map that had nothing to draw rendered no root to read.\n const rootRef = useRef<HTMLDivElement>(null);\n const [dir, setDir] = useState<Direction>(\"ltr\");\n useLayoutEffect(() => {\n setDir(dirOf(rootRef.current));\n }, [data]);\n const ramp = colors && colors.length > 0 ? colors : tokenHex;\n // Coloured by index into `data` AS GIVEN, before anything is dropped: a caller\n // painting a legend or a second map from the same list must land on the same hue\n // for the same row, and filtering first would shift every colour after a gap.\n const nodes = data\n .map((d, idx) => ({\n id: d.id,\n name: d.name,\n size: d.value,\n fill: d.fill ?? ramp[idx % ramp.length],\n }))\n .filter((n) => Number.isFinite(n.size) && n.size > 0)\n .slice(0, maxTiles ?? undefined);\n if (nodes.length === 0) return null;\n\n // The share is of what is DRAWN, so it always reads as \"of this picture\".\n const total = nodes.reduce((acc, n) => acc + n.size, 0);\n const format = (v: number): ReactNode => {\n const share = total > 0 ? v / total : undefined;\n return valueFormatter ? valueFormatter(v, share) : DEFAULT_NUMBER.format(v);\n };\n const Content = redactNames ? RedactedTooltipContent : ChartTooltipContent;\n return (\n <ChartContainer {...rest} ref={rootRef} config={TREEMAP_CONFIG} style={{ ...style, height }}>\n {/* No chart-level `stroke`: recharts spreads it onto the <svg> root, from where\n it inherits into every label (see TreemapCell). Each cell strokes its own rect. */}\n <RechartsTreemap\n data={nodes}\n dataKey=\"size\"\n fill=\"var(--chart-1)\"\n isAnimationActive={false}\n content={\n <TreemapCell onNodeClick={onNodeClick} redactNames={redactNames} nodeNote={nodeNote} dir={dir} />\n }\n >\n <ChartTooltip content={<Content hideLabel valueFormatter={format} />} />\n </RechartsTreemap>\n </ChartContainer>\n );\n}\n"],"mappings":";AA0PI,SAiBE,KAjBF;AAhPJ,SAAS,iBAAiB,QAAQ,UAAU,4BAA4B;AAExE,SAAS,WAAW,uBAAuB;AAC3C,SAAS,gBAAgB,cAAc,2BAA6C;AACpF,SAAS,aAAa,cAAc;AACpC,SAAS,gBAAgB;AACzB,SAAS,aAA6B;AAmGtC,MAAM,eAAe;AAKrB,SAAS,kBAA0B;AACjC,QAAM,OAAO,SAAS;AACtB,QAAM,WAAW,KAAK,UAAU,SAAS,MAAM,IAAI,YAAY,OAAO,YAAY;AAClF,QAAM,QAAQ,iBAAiB,IAAI;AACnC,SAAO,MAAM,KAAK,EAAE,QAAQ,aAAa,GAAG,CAAC,GAAG,MAAM;AACpD,UAAM,IAAI,MAAM,iBAAiB,WAAW,IAAI,CAAC,EAAE,EAAE,KAAK;AAG1D,WAAO,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC;AAAA,EACrC,CAAC,EAAE,KAAK,GAAG;AACb;AAEA,SAAS,qBAAqB,UAAkC;AAC9D,QAAM,WAAW,IAAI,iBAAiB,QAAQ;AAC9C,WAAS,QAAQ,SAAS,iBAAiB;AAAA,IACzC,YAAY;AAAA,IACZ,iBAAiB,CAAC,SAAS,SAAS,YAAY;AAAA,EAClD,CAAC;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