@dowel-ui/react 0.3.0 → 0.4.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 (71) hide show
  1. package/README.md +9 -8
  2. package/dist/components/ai-disclosure/ai-disclosure.d.ts +92 -0
  3. package/dist/components/ai-disclosure/ai-disclosure.d.ts.map +1 -0
  4. package/dist/components/ai-disclosure/ai-disclosure.js +122 -0
  5. package/dist/components/ai-disclosure/ai-disclosure.js.map +1 -0
  6. package/dist/components/ai-disclosure/index.d.ts +2 -0
  7. package/dist/components/ai-disclosure/index.js +2 -0
  8. package/dist/components/ai-disclosure/meta.js +17 -0
  9. package/dist/components/ai-disclosure/meta.js.map +1 -0
  10. package/dist/components/avatar/avatar.d.ts +1 -1
  11. package/dist/components/date-picker/date-picker.js +1 -1
  12. package/dist/components/diff-viewer/diff-model.d.ts +69 -0
  13. package/dist/components/diff-viewer/diff-model.d.ts.map +1 -0
  14. package/dist/components/diff-viewer/diff-model.js +180 -0
  15. package/dist/components/diff-viewer/diff-model.js.map +1 -0
  16. package/dist/components/diff-viewer/diff-viewer.d.ts +42 -0
  17. package/dist/components/diff-viewer/diff-viewer.d.ts.map +1 -0
  18. package/dist/components/diff-viewer/diff-viewer.js +212 -0
  19. package/dist/components/diff-viewer/diff-viewer.js.map +1 -0
  20. package/dist/components/diff-viewer/index.d.ts +3 -0
  21. package/dist/components/diff-viewer/index.js +3 -0
  22. package/dist/components/diff-viewer/meta.js +17 -0
  23. package/dist/components/diff-viewer/meta.js.map +1 -0
  24. package/dist/components/log-viewer/index.d.ts +3 -0
  25. package/dist/components/log-viewer/index.js +3 -0
  26. package/dist/components/log-viewer/log-stream.d.ts +68 -0
  27. package/dist/components/log-viewer/log-stream.d.ts.map +1 -0
  28. package/dist/components/log-viewer/log-stream.js +120 -0
  29. package/dist/components/log-viewer/log-stream.js.map +1 -0
  30. package/dist/components/log-viewer/log-viewer.d.ts +51 -0
  31. package/dist/components/log-viewer/log-viewer.d.ts.map +1 -0
  32. package/dist/components/log-viewer/log-viewer.js +284 -0
  33. package/dist/components/log-viewer/log-viewer.js.map +1 -0
  34. package/dist/components/log-viewer/meta.js +17 -0
  35. package/dist/components/log-viewer/meta.js.map +1 -0
  36. package/dist/components/spinner/spinner.d.ts +1 -1
  37. package/dist/components/time-range-picker/index.d.ts +3 -0
  38. package/dist/components/time-range-picker/index.js +3 -0
  39. package/dist/components/time-range-picker/meta.js +22 -0
  40. package/dist/components/time-range-picker/meta.js.map +1 -0
  41. package/dist/components/time-range-picker/time-expression.d.ts +88 -0
  42. package/dist/components/time-range-picker/time-expression.d.ts.map +1 -0
  43. package/dist/components/time-range-picker/time-expression.js +335 -0
  44. package/dist/components/time-range-picker/time-expression.js.map +1 -0
  45. package/dist/components/time-range-picker/time-range-picker.d.ts +65 -0
  46. package/dist/components/time-range-picker/time-range-picker.d.ts.map +1 -0
  47. package/dist/components/time-range-picker/time-range-picker.js +377 -0
  48. package/dist/components/time-range-picker/time-range-picker.js.map +1 -0
  49. package/dist/index.d.ts +12 -1
  50. package/dist/index.js +9 -2
  51. package/dist/registry/components.d.ts.map +1 -1
  52. package/dist/registry/components.js +58 -50
  53. package/dist/registry/components.js.map +1 -1
  54. package/package.json +6 -4
  55. package/src/components/ai-disclosure/ai-disclosure.tsx +244 -0
  56. package/src/components/ai-disclosure/index.ts +9 -0
  57. package/src/components/ai-disclosure/meta.ts +23 -0
  58. package/src/components/diff-viewer/diff-model.ts +256 -0
  59. package/src/components/diff-viewer/diff-viewer.tsx +339 -0
  60. package/src/components/diff-viewer/index.ts +17 -0
  61. package/src/components/diff-viewer/meta.ts +20 -0
  62. package/src/components/log-viewer/index.ts +21 -0
  63. package/src/components/log-viewer/log-stream.ts +176 -0
  64. package/src/components/log-viewer/log-viewer.tsx +424 -0
  65. package/src/components/log-viewer/meta.ts +21 -0
  66. package/src/components/time-range-picker/index.ts +25 -0
  67. package/src/components/time-range-picker/meta.ts +22 -0
  68. package/src/components/time-range-picker/time-expression.ts +491 -0
  69. package/src/components/time-range-picker/time-range-picker.tsx +522 -0
  70. package/src/index.ts +4 -0
  71. package/src/registry/components.ts +8 -0
@@ -0,0 +1,284 @@
1
+ "use client";
2
+ import { disabledStyles, focusRing } from "../../lib/styles.js";
3
+ import { cn } from "../../lib/utils.js";
4
+ import { LOG_LEVELS, segment } from "./log-stream.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { useEffect, useId, useRef, useState } from "react";
7
+ import { useVirtualizer } from "@tanstack/react-virtual";
8
+ //#region src/components/log-viewer/log-viewer.tsx
9
+ /**
10
+ * A streaming console: filter, follow, expand.
11
+ *
12
+ * The incumbent is react-lazylog, which was last published in 2022, is built on
13
+ * react-virtualized, and cannot run on React 19 — while still taking about
14
+ * 15,000 downloads a week. This is for those people.
15
+ *
16
+ * Two accessibility decisions worth stating rather than discovering.
17
+ *
18
+ * `role="log"` implies `aria-live="polite"`, which is right for a handful of
19
+ * events and catastrophic for a console: a screen reader would read every line
20
+ * of a build as it scrolls past, and nothing else would be audible. Announcing
21
+ * is therefore off by default and opt-in through `announce`. The role stays,
22
+ * because it still describes what the region is.
23
+ *
24
+ * And virtualization means most rows are not in the DOM. That is a real trade,
25
+ * not an implementation detail: assistive technology cannot reach what is not
26
+ * rendered, so a reader who needs the whole log needs an escape — which is what
27
+ * `onDownload` is for. A log viewer with no way out of the virtual window is
28
+ * not accessible however good its ARIA is.
29
+ */
30
+ const LEVEL_STYLES = {
31
+ trace: "text-muted-foreground",
32
+ debug: "text-muted-foreground",
33
+ info: "text-foreground",
34
+ warn: "text-warning",
35
+ error: "text-destructive",
36
+ fatal: "text-destructive font-semibold"
37
+ };
38
+ /** Distance from the bottom, in pixels, that still counts as "at the end". */
39
+ const FOLLOW_THRESHOLD = 24;
40
+ function LogViewer({ className, lines, label, rowHeight = 22, height = 360, announce = false, onDownload, children, ...props }) {
41
+ const scrollRef = useRef(null);
42
+ const [following, setFollowing] = useState(true);
43
+ const [expanded, setExpanded] = useState(/* @__PURE__ */ new Set());
44
+ const labelId = useId();
45
+ const virtualizer = useVirtualizer({
46
+ count: lines.length,
47
+ getScrollElement: () => scrollRef.current,
48
+ estimateSize: () => rowHeight,
49
+ overscan: 12,
50
+ initialRect: {
51
+ width: 0,
52
+ height: typeof height === "number" ? height : 360
53
+ }
54
+ });
55
+ useEffect(() => {
56
+ if (!following || lines.length === 0) return;
57
+ virtualizer.scrollToIndex(lines.length - 1, { align: "end" });
58
+ }, [
59
+ following,
60
+ lines.length,
61
+ virtualizer
62
+ ]);
63
+ function handleScroll() {
64
+ const element = scrollRef.current;
65
+ if (!element) return;
66
+ const distance = element.scrollHeight - element.scrollTop - element.clientHeight;
67
+ setFollowing(distance <= FOLLOW_THRESHOLD);
68
+ }
69
+ function toggleExpanded(id) {
70
+ setExpanded((current) => {
71
+ const next = new Set(current);
72
+ if (next.has(id)) next.delete(id);
73
+ else next.add(id);
74
+ return next;
75
+ });
76
+ }
77
+ const items = virtualizer.getVirtualItems();
78
+ return /* @__PURE__ */ jsxs("div", {
79
+ "data-slot": "log-viewer",
80
+ className: cn("flex flex-col gap-2", className),
81
+ ...props,
82
+ children: [
83
+ /* @__PURE__ */ jsxs("div", {
84
+ className: "flex flex-wrap items-center justify-between gap-2",
85
+ children: [/* @__PURE__ */ jsx("span", {
86
+ id: labelId,
87
+ className: "text-sm font-medium",
88
+ children: label
89
+ }), /* @__PURE__ */ jsxs("div", {
90
+ className: "flex items-center gap-2",
91
+ children: [!following ? /* @__PURE__ */ jsx("button", {
92
+ type: "button",
93
+ "data-slot": "log-viewer-jump",
94
+ onClick: () => {
95
+ setFollowing(true);
96
+ },
97
+ className: cn("rounded-md border border-input bg-background px-2 py-0.5 text-xs font-medium", "transition-colors hover:bg-accent hover:text-accent-foreground", focusRing),
98
+ children: "Jump to latest"
99
+ }) : /* @__PURE__ */ jsx("span", {
100
+ className: "text-xs text-muted-foreground",
101
+ children: "Following"
102
+ }), onDownload ? /* @__PURE__ */ jsx("button", {
103
+ type: "button",
104
+ "data-slot": "log-viewer-download",
105
+ onClick: onDownload,
106
+ className: cn("rounded-md border border-input bg-background px-2 py-0.5 text-xs font-medium", "transition-colors hover:bg-accent hover:text-accent-foreground", focusRing),
107
+ children: "Download full log"
108
+ }) : null]
109
+ })]
110
+ }),
111
+ children,
112
+ /* @__PURE__ */ jsx("div", {
113
+ ref: scrollRef,
114
+ onScroll: handleScroll,
115
+ role: "log",
116
+ "aria-labelledby": labelId,
117
+ "aria-live": announce ? "polite" : "off",
118
+ tabIndex: 0,
119
+ style: { height },
120
+ className: cn("overflow-auto rounded-lg border border-border bg-muted/30 font-mono text-xs", focusRing),
121
+ children: lines.length === 0 ? /* @__PURE__ */ jsx("p", {
122
+ className: "p-3 text-muted-foreground",
123
+ children: "No lines match the current filter."
124
+ }) : /* @__PURE__ */ jsx("div", {
125
+ style: {
126
+ height: virtualizer.getTotalSize(),
127
+ position: "relative"
128
+ },
129
+ children: items.map((item) => {
130
+ const line = lines[item.index];
131
+ if (!line) return null;
132
+ return /* @__PURE__ */ jsx("div", {
133
+ ref: virtualizer.measureElement,
134
+ "data-index": item.index,
135
+ "data-slot": "log-viewer-row",
136
+ "data-level": line.level,
137
+ className: "absolute top-0 left-0 w-full",
138
+ style: { transform: `translateY(${String(item.start)}px)` },
139
+ children: /* @__PURE__ */ jsx(LogViewerRow, {
140
+ line,
141
+ expanded: expanded.has(line.id),
142
+ onToggle: () => {
143
+ toggleExpanded(line.id);
144
+ }
145
+ })
146
+ }, line.id);
147
+ })
148
+ })
149
+ })
150
+ ]
151
+ });
152
+ }
153
+ /**
154
+ * One line.
155
+ *
156
+ * Exported because the virtualized container cannot be measured outside a real
157
+ * browser — jsdom reports every box as zero — so the row's behaviour would
158
+ * otherwise be untestable. It is also genuinely useful on its own for anyone
159
+ * rendering a short log without virtualization.
160
+ */
161
+ function LogViewerRow({ line, expanded = false, onToggle }) {
162
+ const hasFields = line.fields !== void 0 && Object.keys(line.fields).length > 0;
163
+ const parts = segment(line.message, line.matches);
164
+ return /* @__PURE__ */ jsxs("div", {
165
+ className: "px-3 py-0.5 hover:bg-accent/40",
166
+ children: [/* @__PURE__ */ jsxs("div", {
167
+ className: "flex items-baseline gap-2",
168
+ children: [
169
+ line.timestamp ? /* @__PURE__ */ jsx("time", {
170
+ className: "shrink-0 text-muted-foreground tabular-nums",
171
+ children: line.timestamp
172
+ }) : null,
173
+ line.level ? /* @__PURE__ */ jsx("span", {
174
+ className: cn("w-11 shrink-0 uppercase", LEVEL_STYLES[line.level]),
175
+ children: line.level
176
+ }) : null,
177
+ /* @__PURE__ */ jsx("span", {
178
+ className: cn("min-w-0 flex-1 break-all whitespace-pre-wrap", line.level && LEVEL_STYLES[line.level]),
179
+ children: parts.map((part, index) => part.match ? /* @__PURE__ */ jsx("mark", {
180
+ className: "rounded-[2px] bg-warning/35 text-inherit",
181
+ children: part.text
182
+ }, index) : /* @__PURE__ */ jsx("span", { children: part.text }, index))
183
+ }),
184
+ hasFields ? /* @__PURE__ */ jsx("button", {
185
+ type: "button",
186
+ "data-slot": "log-viewer-expand",
187
+ "aria-expanded": expanded,
188
+ onClick: onToggle,
189
+ className: cn("shrink-0 rounded px-1 text-2xs text-muted-foreground", "transition-colors hover:text-foreground", focusRing, disabledStyles),
190
+ children: expanded ? "Hide fields" : "Fields"
191
+ }) : null
192
+ ]
193
+ }), expanded && line.fields ? /* @__PURE__ */ jsx("dl", {
194
+ "data-slot": "log-viewer-fields",
195
+ className: "mt-1 mb-1 ml-4 grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 border-l border-border pl-3",
196
+ children: Object.entries(line.fields).map(([key, value]) => /* @__PURE__ */ jsxs("div", {
197
+ className: "contents",
198
+ children: [/* @__PURE__ */ jsx("dt", {
199
+ className: "text-muted-foreground",
200
+ children: key
201
+ }), /* @__PURE__ */ jsx("dd", {
202
+ className: "m-0 break-all",
203
+ children: typeof value === "string" ? value : JSON.stringify(value)
204
+ })]
205
+ }, key))
206
+ }) : null]
207
+ });
208
+ }
209
+ function LogViewerToolbar({ className, query, onQueryChange, regex, onRegexChange, levels, onToggleLevel, counts, invalidPattern = false, showing, total, ...props }) {
210
+ const filterId = useId();
211
+ const errorId = useId();
212
+ return /* @__PURE__ */ jsxs("div", {
213
+ "data-slot": "log-viewer-toolbar",
214
+ className: cn("flex flex-wrap items-center gap-2", className),
215
+ ...props,
216
+ children: [
217
+ /* @__PURE__ */ jsxs("div", {
218
+ className: "flex min-w-0 flex-1 items-center gap-2",
219
+ children: [
220
+ /* @__PURE__ */ jsx("label", {
221
+ htmlFor: filterId,
222
+ className: "sr-only",
223
+ children: "Filter log"
224
+ }),
225
+ /* @__PURE__ */ jsx("input", {
226
+ id: filterId,
227
+ type: "search",
228
+ value: query,
229
+ placeholder: regex ? "Pattern…" : "Filter…",
230
+ "aria-invalid": invalidPattern || void 0,
231
+ "aria-describedby": invalidPattern ? errorId : void 0,
232
+ onChange: (event) => {
233
+ onQueryChange(event.target.value);
234
+ },
235
+ className: cn("min-w-32 flex-1 rounded-md border border-input bg-background px-2 py-1 text-sm", invalidPattern && "border-destructive", focusRing)
236
+ }),
237
+ /* @__PURE__ */ jsxs("label", {
238
+ className: "flex shrink-0 items-center gap-1 text-xs text-muted-foreground",
239
+ children: [/* @__PURE__ */ jsx("input", {
240
+ type: "checkbox",
241
+ checked: regex,
242
+ onChange: (event) => {
243
+ onRegexChange(event.target.checked);
244
+ },
245
+ className: cn("size-3.5 rounded border-input", focusRing)
246
+ }), "Regex"]
247
+ })
248
+ ]
249
+ }),
250
+ /* @__PURE__ */ jsx("div", {
251
+ className: "flex flex-wrap items-center gap-1",
252
+ children: LOG_LEVELS.filter((level) => counts.has(level)).map((level) => {
253
+ const on = levels.size === 0 || levels.has(level);
254
+ return /* @__PURE__ */ jsxs("button", {
255
+ type: "button",
256
+ "data-slot": "log-viewer-facet",
257
+ "aria-pressed": on,
258
+ onClick: () => {
259
+ onToggleLevel(level);
260
+ },
261
+ className: cn("rounded-md border px-1.5 py-0.5 font-mono text-2xs uppercase transition-colors", on ? "border-transparent bg-secondary text-secondary-foreground" : "border-input bg-background text-muted-foreground line-through", focusRing),
262
+ children: [
263
+ level,
264
+ " ",
265
+ counts.get(level) ?? 0
266
+ ]
267
+ }, level);
268
+ })
269
+ }),
270
+ /* @__PURE__ */ jsx("p", {
271
+ className: "w-full text-xs text-muted-foreground tabular-nums",
272
+ children: invalidPattern ? /* @__PURE__ */ jsx("span", {
273
+ id: errorId,
274
+ className: "text-destructive",
275
+ children: "Incomplete pattern — showing everything until it is valid"
276
+ }) : `${String(showing)} of ${String(total)} lines`
277
+ })
278
+ ]
279
+ });
280
+ }
281
+ //#endregion
282
+ export { LogViewer, LogViewerRow, LogViewerToolbar };
283
+
284
+ //# sourceMappingURL=log-viewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-viewer.js","names":[],"sources":["../../../src/components/log-viewer/log-viewer.tsx"],"sourcesContent":["\"use client\";\n\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport {\n useEffect,\n useId,\n useRef,\n useState,\n type ComponentPropsWithRef,\n type ReactNode,\n} from \"react\";\n\nimport { disabledStyles, focusRing } from \"@/lib/styles\";\nimport { cn } from \"@/lib/utils\";\n\nimport { LOG_LEVELS, segment, type LogLevel, type VisibleLine } from \"./log-stream\";\n\n/**\n * A streaming console: filter, follow, expand.\n *\n * The incumbent is react-lazylog, which was last published in 2022, is built on\n * react-virtualized, and cannot run on React 19 — while still taking about\n * 15,000 downloads a week. This is for those people.\n *\n * Two accessibility decisions worth stating rather than discovering.\n *\n * `role=\"log\"` implies `aria-live=\"polite\"`, which is right for a handful of\n * events and catastrophic for a console: a screen reader would read every line\n * of a build as it scrolls past, and nothing else would be audible. Announcing\n * is therefore off by default and opt-in through `announce`. The role stays,\n * because it still describes what the region is.\n *\n * And virtualization means most rows are not in the DOM. That is a real trade,\n * not an implementation detail: assistive technology cannot reach what is not\n * rendered, so a reader who needs the whole log needs an escape — which is what\n * `onDownload` is for. A log viewer with no way out of the virtual window is\n * not accessible however good its ARIA is.\n */\n\nconst LEVEL_STYLES: Record<LogLevel, string> = {\n trace: \"text-muted-foreground\",\n debug: \"text-muted-foreground\",\n info: \"text-foreground\",\n warn: \"text-warning\",\n error: \"text-destructive\",\n fatal: \"text-destructive font-semibold\",\n};\n\n/** Distance from the bottom, in pixels, that still counts as \"at the end\". */\nconst FOLLOW_THRESHOLD = 24;\n\nexport interface LogViewerProps extends Omit<ComponentPropsWithRef<\"div\">, \"children\"> {\n lines: VisibleLine[];\n /** Names the region. */\n label: string;\n /** Row height in pixels. Rows are one line; expansion is measured. */\n rowHeight?: number;\n height?: number | string;\n /**\n * Read new lines aloud. Off by default — a console that announces every line\n * makes a screen reader useless for anything else.\n */\n announce?: boolean;\n /** The way out of the virtual window, for anyone who needs the whole log. */\n onDownload?: () => void;\n children?: ReactNode;\n}\n\nexport function LogViewer({\n className,\n lines,\n label,\n rowHeight = 22,\n height = 360,\n announce = false,\n onDownload,\n children,\n ...props\n}: LogViewerProps) {\n const scrollRef = useRef<HTMLDivElement | null>(null);\n const [following, setFollowing] = useState(true);\n const [expanded, setExpanded] = useState<Set<string>>(new Set());\n const labelId = useId();\n\n const virtualizer = useVirtualizer({\n count: lines.length,\n getScrollElement: () => scrollRef.current,\n estimateSize: () => rowHeight,\n overscan: 12,\n // Without a starting rect the virtualizer renders nothing until a\n // ResizeObserver fires, so the first paint is an empty box. Seeding it from\n // the declared height means rows are there immediately, and it is measured\n // properly a moment later.\n initialRect: { width: 0, height: typeof height === \"number\" ? height : 360 },\n });\n\n // Follow mode, hand-written rather than delegated. A spring-anchoring library\n // wants to own the scroll container and so does the virtualizer, and the two\n // fight; this is scrollToIndex on append plus a proximity check.\n useEffect(() => {\n if (!following || lines.length === 0) return;\n virtualizer.scrollToIndex(lines.length - 1, { align: \"end\" });\n }, [following, lines.length, virtualizer]);\n\n function handleScroll() {\n const element = scrollRef.current;\n if (!element) return;\n\n const distance = element.scrollHeight - element.scrollTop - element.clientHeight;\n // Scrolling up detaches, because the reader is looking at something and\n // yanking them back to the tail would lose it. Returning to the bottom\n // re-attaches, which is the gesture people already expect.\n setFollowing(distance <= FOLLOW_THRESHOLD);\n }\n\n function toggleExpanded(id: string) {\n setExpanded((current) => {\n const next = new Set(current);\n if (next.has(id)) next.delete(id);\n else next.add(id);\n return next;\n });\n }\n\n const items = virtualizer.getVirtualItems();\n\n return (\n <div data-slot=\"log-viewer\" className={cn(\"flex flex-col gap-2\", className)} {...props}>\n <div className=\"flex flex-wrap items-center justify-between gap-2\">\n <span id={labelId} className=\"text-sm font-medium\">\n {label}\n </span>\n <div className=\"flex items-center gap-2\">\n {!following ? (\n <button\n type=\"button\"\n data-slot=\"log-viewer-jump\"\n onClick={() => {\n setFollowing(true);\n }}\n className={cn(\n \"rounded-md border border-input bg-background px-2 py-0.5 text-xs font-medium\",\n \"transition-colors hover:bg-accent hover:text-accent-foreground\",\n focusRing,\n )}\n >\n Jump to latest\n </button>\n ) : (\n <span className=\"text-xs text-muted-foreground\">Following</span>\n )}\n {onDownload ? (\n <button\n type=\"button\"\n data-slot=\"log-viewer-download\"\n onClick={onDownload}\n className={cn(\n \"rounded-md border border-input bg-background px-2 py-0.5 text-xs font-medium\",\n \"transition-colors hover:bg-accent hover:text-accent-foreground\",\n focusRing,\n )}\n >\n Download full log\n </button>\n ) : null}\n </div>\n </div>\n\n {children}\n\n <div\n ref={scrollRef}\n onScroll={handleScroll}\n role=\"log\"\n aria-labelledby={labelId}\n // Explicitly off unless asked for: role=\"log\" implies polite, and a\n // console that reads every line aloud drowns out everything else.\n aria-live={announce ? \"polite\" : \"off\"}\n // A scrollable region must be focusable, or its content is unreachable\n // without a pointer — WCAG 2.1.1, and axe's scrollable-region-focusable\n // requires exactly this. jsx-a11y's heuristic cannot see that this\n // element scrolls, so here the requirement outranks the rule.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n style={{ height }}\n className={cn(\n \"overflow-auto rounded-lg border border-border bg-muted/30 font-mono text-xs\",\n focusRing,\n )}\n >\n {lines.length === 0 ? (\n <p className=\"p-3 text-muted-foreground\">No lines match the current filter.</p>\n ) : (\n <div style={{ height: virtualizer.getTotalSize(), position: \"relative\" }}>\n {items.map((item) => {\n const line = lines[item.index];\n if (!line) return null;\n\n return (\n <div\n key={line.id}\n ref={virtualizer.measureElement}\n data-index={item.index}\n data-slot=\"log-viewer-row\"\n data-level={line.level}\n className=\"absolute top-0 left-0 w-full\"\n style={{ transform: `translateY(${String(item.start)}px)` }}\n >\n <LogViewerRow\n line={line}\n expanded={expanded.has(line.id)}\n onToggle={() => {\n toggleExpanded(line.id);\n }}\n />\n </div>\n );\n })}\n </div>\n )}\n </div>\n </div>\n );\n}\n\nexport interface LogViewerRowProps {\n line: VisibleLine;\n expanded?: boolean;\n onToggle?: () => void;\n}\n\n/**\n * One line.\n *\n * Exported because the virtualized container cannot be measured outside a real\n * browser — jsdom reports every box as zero — so the row's behaviour would\n * otherwise be untestable. It is also genuinely useful on its own for anyone\n * rendering a short log without virtualization.\n */\nexport function LogViewerRow({ line, expanded = false, onToggle }: LogViewerRowProps) {\n const hasFields = line.fields !== undefined && Object.keys(line.fields).length > 0;\n const parts = segment(line.message, line.matches);\n\n return (\n <div className=\"px-3 py-0.5 hover:bg-accent/40\">\n <div className=\"flex items-baseline gap-2\">\n {line.timestamp ? (\n <time className=\"shrink-0 text-muted-foreground tabular-nums\">{line.timestamp}</time>\n ) : null}\n\n {line.level ? (\n // The level in text, not a coloured bar. Colour alone cannot\n // distinguish warn from error for everyone reading.\n <span className={cn(\"w-11 shrink-0 uppercase\", LEVEL_STYLES[line.level])}>\n {line.level}\n </span>\n ) : null}\n\n <span\n className={cn(\n \"min-w-0 flex-1 break-all whitespace-pre-wrap\",\n line.level && LEVEL_STYLES[line.level],\n )}\n >\n {parts.map((part, index) =>\n part.match ? (\n // A mark element, so the match is conveyed structurally rather\n // than only as a background colour.\n <mark key={index} className=\"rounded-[2px] bg-warning/35 text-inherit\">\n {part.text}\n </mark>\n ) : (\n <span key={index}>{part.text}</span>\n ),\n )}\n </span>\n\n {hasFields ? (\n <button\n type=\"button\"\n data-slot=\"log-viewer-expand\"\n aria-expanded={expanded}\n onClick={onToggle}\n className={cn(\n \"shrink-0 rounded px-1 text-2xs text-muted-foreground\",\n \"transition-colors hover:text-foreground\",\n focusRing,\n disabledStyles,\n )}\n >\n {expanded ? \"Hide fields\" : \"Fields\"}\n </button>\n ) : null}\n </div>\n\n {expanded && line.fields ? (\n <dl\n data-slot=\"log-viewer-fields\"\n className=\"mt-1 mb-1 ml-4 grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 border-l border-border pl-3\"\n >\n {Object.entries(line.fields).map(([key, value]) => (\n <div key={key} className=\"contents\">\n <dt className=\"text-muted-foreground\">{key}</dt>\n <dd className=\"m-0 break-all\">\n {typeof value === \"string\" ? value : JSON.stringify(value)}\n </dd>\n </div>\n ))}\n </dl>\n ) : null}\n </div>\n );\n}\n\nexport interface LogViewerToolbarProps extends Omit<ComponentPropsWithRef<\"div\">, \"onChange\"> {\n query: string;\n onQueryChange: (query: string) => void;\n regex: boolean;\n onRegexChange: (regex: boolean) => void;\n levels: Set<LogLevel>;\n onToggleLevel: (level: LogLevel) => void;\n counts: Map<LogLevel, number>;\n invalidPattern?: boolean;\n /** Shown as \"N of M lines\". */\n showing: number;\n total: number;\n}\n\nexport function LogViewerToolbar({\n className,\n query,\n onQueryChange,\n regex,\n onRegexChange,\n levels,\n onToggleLevel,\n counts,\n invalidPattern = false,\n showing,\n total,\n ...props\n}: LogViewerToolbarProps) {\n const filterId = useId();\n const errorId = useId();\n\n return (\n <div\n data-slot=\"log-viewer-toolbar\"\n className={cn(\"flex flex-wrap items-center gap-2\", className)}\n {...props}\n >\n <div className=\"flex min-w-0 flex-1 items-center gap-2\">\n <label htmlFor={filterId} className=\"sr-only\">\n Filter log\n </label>\n <input\n id={filterId}\n type=\"search\"\n value={query}\n placeholder={regex ? \"Pattern…\" : \"Filter…\"}\n aria-invalid={invalidPattern || undefined}\n aria-describedby={invalidPattern ? errorId : undefined}\n onChange={(event) => {\n onQueryChange(event.target.value);\n }}\n className={cn(\n \"min-w-32 flex-1 rounded-md border border-input bg-background px-2 py-1 text-sm\",\n invalidPattern && \"border-destructive\",\n focusRing,\n )}\n />\n <label className=\"flex shrink-0 items-center gap-1 text-xs text-muted-foreground\">\n <input\n type=\"checkbox\"\n checked={regex}\n onChange={(event) => {\n onRegexChange(event.target.checked);\n }}\n className={cn(\"size-3.5 rounded border-input\", focusRing)}\n />\n Regex\n </label>\n </div>\n\n <div className=\"flex flex-wrap items-center gap-1\">\n {LOG_LEVELS.filter((level) => counts.has(level)).map((level) => {\n const on = levels.size === 0 || levels.has(level);\n return (\n <button\n key={level}\n type=\"button\"\n data-slot=\"log-viewer-facet\"\n aria-pressed={on}\n onClick={() => {\n onToggleLevel(level);\n }}\n className={cn(\n \"rounded-md border px-1.5 py-0.5 font-mono text-2xs uppercase transition-colors\",\n on\n ? \"border-transparent bg-secondary text-secondary-foreground\"\n : \"border-input bg-background text-muted-foreground line-through\",\n focusRing,\n )}\n >\n {level} {counts.get(level) ?? 0}\n </button>\n );\n })}\n </div>\n\n <p className=\"w-full text-xs text-muted-foreground tabular-nums\">\n {invalidPattern ? (\n // Said out loud rather than shown as an empty log, which reads as\n // \"nothing matched\" and sends the reader looking for the wrong thing.\n <span id={errorId} className=\"text-destructive\">\n Incomplete pattern — showing everything until it is valid\n </span>\n ) : (\n `${String(showing)} of ${String(total)} lines`\n )}\n </p>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,eAAyC;CAC7C,OAAO;CACP,OAAO;CACP,MAAM;CACN,MAAM;CACN,OAAO;CACP,OAAO;AACT;;AAGA,MAAM,mBAAmB;AAmBzB,SAAgB,UAAU,EACxB,WACA,OACA,OACA,YAAY,IACZ,SAAS,KACT,WAAW,OACX,YACA,UACA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
1
+ import { defineMeta } from "../../registry/schema.js";
2
+ //#region src/components/log-viewer/meta.ts
3
+ const meta = defineMeta({
4
+ name: "log-viewer",
5
+ title: "Log Viewer",
6
+ description: "A streaming console with filtering, level facets and follow mode.",
7
+ category: "data",
8
+ status: "stable",
9
+ dependencies: ["@tanstack/react-virtual"],
10
+ registryDependencies: [],
11
+ files: ["log-stream.ts", "log-viewer.tsx"],
12
+ a11y: "role=\"log\" implies aria-live=\"polite\", which is right for a few events and unusable for a console — a screen reader would read every line of a build and nothing else would be audible. Announcing is off by default and opt-in. Virtualization is the harder trade: most rows are not in the DOM, so assistive technology cannot reach them, which is why the component takes an onDownload escape rather than pretending the virtual window is the whole log. Levels are written in text as well as coloured, matches use mark elements rather than a background colour, and an invalid pattern is announced instead of silently showing an empty log that reads as \"nothing matched\"."
13
+ });
14
+ //#endregion
15
+ export { meta };
16
+
17
+ //# sourceMappingURL=meta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.js","names":[],"sources":["../../../src/components/log-viewer/meta.ts"],"sourcesContent":["import { defineMeta } from \"@/registry/schema\";\n\nexport const meta = defineMeta({\n name: \"log-viewer\",\n title: \"Log Viewer\",\n description: \"A streaming console with filtering, level facets and follow mode.\",\n category: \"data\",\n status: \"stable\",\n dependencies: [\"@tanstack/react-virtual\"],\n registryDependencies: [],\n files: [\"log-stream.ts\", \"log-viewer.tsx\"],\n a11y:\n 'role=\"log\" implies aria-live=\"polite\", which is right for a few events and unusable for a ' +\n \"console — a screen reader would read every line of a build and nothing else would be \" +\n \"audible. Announcing is off by default and opt-in. Virtualization is the harder trade: most \" +\n \"rows are not in the DOM, so assistive technology cannot reach them, which is why the \" +\n \"component takes an onDownload escape rather than pretending the virtual window is the whole \" +\n \"log. Levels are written in text as well as coloured, matches use mark elements rather than \" +\n \"a background colour, and an invalid pattern is announced instead of silently showing an \" +\n 'empty log that reads as \"nothing matched\".',\n});\n"],"mappings":";;AAEA,MAAa,OAAO,WAAW;CAC7B,MAAM;CACN,OAAO;CACP,aAAa;CACb,UAAU;CACV,QAAQ;CACR,cAAc,CAAC,yBAAyB;CACxC,sBAAsB,CAAC;CACvB,OAAO,CAAC,iBAAiB,gBAAgB;CACzC,MACE;AAQJ,CAAC"}
@@ -2,7 +2,7 @@ import { VariantProps } from "class-variance-authority";
2
2
  import { ComponentPropsWithRef } from "react";
3
3
  //#region src/components/spinner/spinner.d.ts
4
4
  declare const spinnerVariants: (props?: ({
5
- size?: "sm" | "md" | "lg" | "xs" | "xl" | null | undefined;
5
+ size?: "sm" | "md" | "xs" | "lg" | "xl" | null | undefined;
6
6
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
7
  interface SpinnerProps extends Omit<ComponentPropsWithRef<"svg">, "children">, VariantProps<typeof spinnerVariants> {
8
8
  /**
@@ -0,0 +1,3 @@
1
+ import { DEFAULT_PRESETS, ResolveOptions, ResolvedRange, TimeExpressionError, TimeRangePreset, TimeUnit, absoluteExpression, describeTimeRange, formatResolvedRange, isValidTimeRange, resolveExpression, resolveTimeRange } from "./time-expression.js";
2
+ import { TimeRange, TimeRangeCalendar, TimeRangeContent, TimeRangeContentProps, TimeRangeExpression, TimeRangePresets, TimeRangeProps, TimeRangeTrigger, TimeRangeTriggerProps } from "./time-range-picker.js";
3
+ export { DEFAULT_PRESETS, type ResolveOptions, type ResolvedRange, TimeExpressionError, TimeRange, TimeRangeCalendar, TimeRangeContent, type TimeRangeContentProps, TimeRangeExpression, type TimeRangePreset, TimeRangePresets, type TimeRangeProps, TimeRangeTrigger, type TimeRangeTriggerProps, type TimeUnit, absoluteExpression, describeTimeRange, formatResolvedRange, isValidTimeRange, resolveExpression, resolveTimeRange };
@@ -0,0 +1,3 @@
1
+ import { DEFAULT_PRESETS, TimeExpressionError, absoluteExpression, describeTimeRange, formatResolvedRange, isValidTimeRange, resolveExpression, resolveTimeRange } from "./time-expression.js";
2
+ import { TimeRange, TimeRangeCalendar, TimeRangeContent, TimeRangeExpression, TimeRangePresets, TimeRangeTrigger } from "./time-range-picker.js";
3
+ export { DEFAULT_PRESETS, TimeExpressionError, TimeRange, TimeRangeCalendar, TimeRangeContent, TimeRangeExpression, TimeRangePresets, TimeRangeTrigger, absoluteExpression, describeTimeRange, formatResolvedRange, isValidTimeRange, resolveExpression, resolveTimeRange };
@@ -0,0 +1,22 @@
1
+ import { defineMeta } from "../../registry/schema.js";
2
+ //#region src/components/time-range-picker/meta.ts
3
+ const meta = defineMeta({
4
+ name: "time-range-picker",
5
+ title: "Time Range Picker",
6
+ description: "A time range whose value is an expression, so it stays relative across a reload.",
7
+ category: "form",
8
+ status: "stable",
9
+ dependencies: ["react-day-picker"],
10
+ registryDependencies: [
11
+ "button",
12
+ "calendar",
13
+ "input",
14
+ "popover"
15
+ ],
16
+ files: ["time-expression.ts", "time-range-picker.tsx"],
17
+ a11y: "The trigger is named by the range it holds — \"Last 6 hours\" — and the window that resolves to is read after it, so the relative choice is not replaced by two timestamps. The popover carries role=\"dialog\" and is named. Presets are buttons rather than radios because choosing one both selects and dismisses, with aria-pressed carrying which matches the current expression. The expression field reports why an unparseable entry is invalid through one aria-describedby element that the preview and the error share, so a reader hears the error replace the preview rather than both at once; an invalid expression is never applied, because a chart silently re-scoping itself is worse than one that refuses."
18
+ });
19
+ //#endregion
20
+ export { meta };
21
+
22
+ //# sourceMappingURL=meta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.js","names":[],"sources":["../../../src/components/time-range-picker/meta.ts"],"sourcesContent":["import { defineMeta } from \"@/registry/schema\";\n\nexport const meta = defineMeta({\n name: \"time-range-picker\",\n title: \"Time Range Picker\",\n description:\n \"A time range whose value is an expression, so it stays relative across a reload.\",\n category: \"form\",\n status: \"stable\",\n dependencies: [\"react-day-picker\"],\n registryDependencies: [\"button\", \"calendar\", \"input\", \"popover\"],\n files: [\"time-expression.ts\", \"time-range-picker.tsx\"],\n a11y:\n 'The trigger is named by the range it holds — \"Last 6 hours\" — and the window that ' +\n \"resolves to is read after it, so the relative choice is not replaced by two timestamps. \" +\n 'The popover carries role=\"dialog\" and is named. Presets are buttons rather than radios ' +\n \"because choosing one both selects and dismisses, with aria-pressed carrying which matches \" +\n \"the current expression. The expression field reports why an unparseable entry is invalid \" +\n \"through one aria-describedby element that the preview and the error share, so a reader \" +\n \"hears the error replace the preview rather than both at once; an invalid expression is \" +\n \"never applied, because a chart silently re-scoping itself is worse than one that refuses.\",\n});\n"],"mappings":";;AAEA,MAAa,OAAO,WAAW;CAC7B,MAAM;CACN,OAAO;CACP,aACE;CACF,UAAU;CACV,QAAQ;CACR,cAAc,CAAC,kBAAkB;CACjC,sBAAsB;EAAC;EAAU;EAAY;EAAS;CAAS;CAC/D,OAAO,CAAC,sBAAsB,uBAAuB;CACrD,MACE;AAQJ,CAAC"}
@@ -0,0 +1,88 @@
1
+ //#region src/components/time-range-picker/time-expression.d.ts
2
+ /**
3
+ * Time ranges as expressions, not as two frozen timestamps.
4
+ *
5
+ * `now-6h` is still the last six hours tomorrow; a resolved pair is six hours
6
+ * of last Tuesday forever. Storing the expression is what lets a dashboard URL
7
+ * survive being bookmarked and reloaded.
8
+ *
9
+ * The grammar is a deliberate subset of the one Grafana, Datadog and Kibana
10
+ * converged on, so the strings are already familiar:
11
+ *
12
+ * range := expr ".." expr
13
+ * expr := "now" offset* snap? | ISO-8601
14
+ * offset := ("-" | "+") digits unit
15
+ * snap := "/" unit
16
+ * unit := s | m | h | d | w | M | y
17
+ *
18
+ * now-6h..now the last six hours
19
+ * now-6h/h..now the last six hours, starting on the hour
20
+ * now/d..now/d today, all of it
21
+ * now-1d/d..now-1d/d yesterday
22
+ * 2026-01-01..now since a fixed instant
23
+ *
24
+ * Everything here is pure and takes `now` as an argument: reading the clock
25
+ * during render would disagree between the server and the browser.
26
+ */
27
+ type TimeUnit = "s" | "m" | "h" | "d" | "w" | "M" | "y";
28
+ interface ResolveOptions {
29
+ /** The instant `now` refers to. Required, so nothing here reads the clock. */
30
+ now: Date;
31
+ /**
32
+ * IANA zone the snapping happens in — "start of day" is a different instant
33
+ * in Auckland than in Denver. Defaults to the runtime zone.
34
+ */
35
+ timeZone?: string;
36
+ }
37
+ interface ResolvedRange {
38
+ from: Date;
39
+ to: Date;
40
+ }
41
+ /** Why an expression could not be resolved. Shown to the user verbatim. */
42
+ declare class TimeExpressionError extends Error {
43
+ /** The part of the input at fault, for pointing at it. */
44
+ readonly input: string;
45
+ constructor(message: string,
46
+ /** The part of the input at fault, for pointing at it. */
47
+ input: string);
48
+ }
49
+ /** Resolves a single side of a range. Exported for the input's live feedback. */
50
+ declare function resolveExpression(expression: string, edge: "start" | "end", options: ResolveOptions): Date;
51
+ /**
52
+ * Turns a range expression into the two instants a query needs.
53
+ *
54
+ * Throws `TimeExpressionError` rather than returning a fallback range: a chart
55
+ * silently showing the wrong window is worse than one that says it cannot.
56
+ */
57
+ declare function resolveTimeRange(expression: string, options: ResolveOptions): ResolvedRange;
58
+ /** Whether an expression resolves, without the caller writing a try/catch. */
59
+ declare function isValidTimeRange(expression: string, options: ResolveOptions): boolean;
60
+ interface TimeRangePreset {
61
+ expression: string;
62
+ label: string;
63
+ /** Groups presets under a heading in the picker. */
64
+ group: string;
65
+ }
66
+ /** Relative windows first, for debugging; calendar periods after, for reporting. */
67
+ declare const DEFAULT_PRESETS: TimeRangePreset[];
68
+ /**
69
+ * A sentence for the trigger.
70
+ *
71
+ * An unnamed relative range is described in its own terms — "Last 90 minutes" —
72
+ * because showing it as two timestamps throws away what the user chose. Only an
73
+ * absolute range, which has no relative meaning left, is shown as dates.
74
+ */
75
+ declare function describeTimeRange(expression: string, options: ResolveOptions & {
76
+ locale?: string;
77
+ presets?: TimeRangePreset[];
78
+ }): string;
79
+ /** The resolved window, spelled out. Pairs with the relative label, not replaces it. */
80
+ declare function formatResolvedRange(range: ResolvedRange, options?: {
81
+ locale?: string;
82
+ timeZone?: string;
83
+ }): string;
84
+ /** Builds the expression for an absolute range chosen on a calendar. */
85
+ declare function absoluteExpression(from: Date, to: Date): string;
86
+ //#endregion
87
+ export { DEFAULT_PRESETS, ResolveOptions, ResolvedRange, TimeExpressionError, TimeRangePreset, TimeUnit, absoluteExpression, describeTimeRange, formatResolvedRange, isValidTimeRange, resolveExpression, resolveTimeRange };
88
+ //# sourceMappingURL=time-expression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time-expression.d.ts","names":[],"sources":["../../../src/components/time-range-picker/time-expression.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;KA0BY;UAEK;;EAEf,KAAK;;;;;EAKL;;UAGe;EACf,MAAM;EACN,IAAI;;;cAIO,4BAA4B;;WAI5B;EAFT,YAAA,iBAES;;EAAA;;;iBAwOG,kBACd,oBACA,uBACA,SAAS,iBACR;;;;;;;iBAwFa,iBAAiB,oBAAoB,SAAS,iBAAiB;;iBAoB/D,iBAAiB,oBAAoB,SAAS;UAa7C;EACf;EACA;;EAEA;;;cAIW,iBAAiB;;;;;;;;iBAyBd,kBACd,oBACA,SAAS;EAAmB;EAAiB,UAAU;;;iBA2BzC,oBACd,OAAO,eACP;EAAW;EAAiB;;;iBAWd,mBAAmB,MAAM,MAAM,IAAI"}