@dowel-ui/react 0.2.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.
- package/README.md +14 -7
- package/dist/components/ai-agent-plan/ai-agent-plan.d.ts +50 -0
- package/dist/components/ai-agent-plan/ai-agent-plan.d.ts.map +1 -0
- package/dist/components/ai-agent-plan/ai-agent-plan.js +156 -0
- package/dist/components/ai-agent-plan/ai-agent-plan.js.map +1 -0
- package/dist/components/ai-agent-plan/index.d.ts +2 -0
- package/dist/components/ai-agent-plan/index.js +2 -0
- package/dist/components/ai-agent-plan/meta.js +17 -0
- package/dist/components/ai-agent-plan/meta.js.map +1 -0
- package/dist/components/ai-agent-status/ai-agent-status.d.ts +1 -1
- package/dist/components/ai-approval-request/ai-approval-request.d.ts +67 -0
- package/dist/components/ai-approval-request/ai-approval-request.d.ts.map +1 -0
- package/dist/components/ai-approval-request/ai-approval-request.js +218 -0
- package/dist/components/ai-approval-request/ai-approval-request.js.map +1 -0
- package/dist/components/ai-approval-request/index.d.ts +2 -0
- package/dist/components/ai-approval-request/index.js +2 -0
- package/dist/components/ai-approval-request/meta.js +17 -0
- package/dist/components/ai-approval-request/meta.js.map +1 -0
- package/dist/components/ai-disclosure/ai-disclosure.d.ts +92 -0
- package/dist/components/ai-disclosure/ai-disclosure.d.ts.map +1 -0
- package/dist/components/ai-disclosure/ai-disclosure.js +122 -0
- package/dist/components/ai-disclosure/ai-disclosure.js.map +1 -0
- package/dist/components/ai-disclosure/index.d.ts +2 -0
- package/dist/components/ai-disclosure/index.js +2 -0
- package/dist/components/ai-disclosure/meta.js +17 -0
- package/dist/components/ai-disclosure/meta.js.map +1 -0
- package/dist/components/ai-response/ai-response.d.ts.map +1 -1
- package/dist/components/ai-response/ai-response.js +1 -0
- package/dist/components/ai-response/ai-response.js.map +1 -1
- package/dist/components/ai-structured-output/ai-structured-output.d.ts.map +1 -1
- package/dist/components/ai-structured-output/ai-structured-output.js +13 -2
- package/dist/components/ai-structured-output/ai-structured-output.js.map +1 -1
- package/dist/components/ai-tool/ai-tool.d.ts +1 -1
- package/dist/components/alert/alert.d.ts +1 -1
- package/dist/components/avatar/avatar.d.ts +1 -1
- package/dist/components/badge/badge.d.ts +1 -1
- package/dist/components/button/button.d.ts +1 -1
- package/dist/components/date-picker/date-picker.js +1 -1
- package/dist/components/diff-viewer/diff-model.d.ts +69 -0
- package/dist/components/diff-viewer/diff-model.d.ts.map +1 -0
- package/dist/components/diff-viewer/diff-model.js +180 -0
- package/dist/components/diff-viewer/diff-model.js.map +1 -0
- package/dist/components/diff-viewer/diff-viewer.d.ts +42 -0
- package/dist/components/diff-viewer/diff-viewer.d.ts.map +1 -0
- package/dist/components/diff-viewer/diff-viewer.js +212 -0
- package/dist/components/diff-viewer/diff-viewer.js.map +1 -0
- package/dist/components/diff-viewer/index.d.ts +3 -0
- package/dist/components/diff-viewer/index.js +3 -0
- package/dist/components/diff-viewer/meta.js +17 -0
- package/dist/components/diff-viewer/meta.js.map +1 -0
- package/dist/components/file-upload/file-upload.d.ts +46 -0
- package/dist/components/file-upload/file-upload.d.ts.map +1 -0
- package/dist/components/file-upload/file-upload.js +204 -0
- package/dist/components/file-upload/file-upload.js.map +1 -0
- package/dist/components/file-upload/index.d.ts +3 -0
- package/dist/components/file-upload/index.js +3 -0
- package/dist/components/file-upload/meta.js +17 -0
- package/dist/components/file-upload/meta.js.map +1 -0
- package/dist/components/file-upload/upload-queue.d.ts +87 -0
- package/dist/components/file-upload/upload-queue.d.ts.map +1 -0
- package/dist/components/file-upload/upload-queue.js +249 -0
- package/dist/components/file-upload/upload-queue.js.map +1 -0
- package/dist/components/log-viewer/index.d.ts +3 -0
- package/dist/components/log-viewer/index.js +3 -0
- package/dist/components/log-viewer/log-stream.d.ts +68 -0
- package/dist/components/log-viewer/log-stream.d.ts.map +1 -0
- package/dist/components/log-viewer/log-stream.js +120 -0
- package/dist/components/log-viewer/log-stream.js.map +1 -0
- package/dist/components/log-viewer/log-viewer.d.ts +51 -0
- package/dist/components/log-viewer/log-viewer.d.ts.map +1 -0
- package/dist/components/log-viewer/log-viewer.js +284 -0
- package/dist/components/log-viewer/log-viewer.js.map +1 -0
- package/dist/components/log-viewer/meta.js +17 -0
- package/dist/components/log-viewer/meta.js.map +1 -0
- package/dist/components/progress/progress.d.ts +1 -1
- package/dist/components/progress/progress.js +1 -0
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/spinner/spinner.d.ts +1 -1
- package/dist/components/spinner/spinner.js +1 -0
- package/dist/components/spinner/spinner.js.map +1 -1
- package/dist/components/tags-input/index.d.ts +2 -0
- package/dist/components/tags-input/index.js +2 -0
- package/dist/components/tags-input/meta.js +17 -0
- package/dist/components/tags-input/meta.js.map +1 -0
- package/dist/components/tags-input/tags-input.d.ts +47 -0
- package/dist/components/tags-input/tags-input.d.ts.map +1 -0
- package/dist/components/tags-input/tags-input.js +182 -0
- package/dist/components/tags-input/tags-input.js.map +1 -0
- package/dist/components/time-range-picker/index.d.ts +3 -0
- package/dist/components/time-range-picker/index.js +3 -0
- package/dist/components/time-range-picker/meta.js +22 -0
- package/dist/components/time-range-picker/meta.js.map +1 -0
- package/dist/components/time-range-picker/time-expression.d.ts +88 -0
- package/dist/components/time-range-picker/time-expression.d.ts.map +1 -0
- package/dist/components/time-range-picker/time-expression.js +335 -0
- package/dist/components/time-range-picker/time-expression.js.map +1 -0
- package/dist/components/time-range-picker/time-range-picker.d.ts +65 -0
- package/dist/components/time-range-picker/time-range-picker.d.ts.map +1 -0
- package/dist/components/time-range-picker/time-range-picker.js +377 -0
- package/dist/components/time-range-picker/time-range-picker.js.map +1 -0
- package/dist/components/toast/toast.d.ts +1 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +14 -2
- package/dist/registry/components.d.ts.map +1 -1
- package/dist/registry/components.js +66 -50
- package/dist/registry/components.js.map +1 -1
- package/package.json +6 -4
- package/src/components/ai-agent-plan/ai-agent-plan.tsx +0 -0
- package/src/components/ai-agent-plan/index.ts +10 -0
- package/src/components/ai-agent-plan/meta.ts +19 -0
- package/src/components/ai-approval-request/ai-approval-request.tsx +368 -0
- package/src/components/ai-approval-request/index.ts +7 -0
- package/src/components/ai-approval-request/meta.ts +21 -0
- package/src/components/ai-disclosure/ai-disclosure.tsx +244 -0
- package/src/components/ai-disclosure/index.ts +9 -0
- package/src/components/ai-disclosure/meta.ts +23 -0
- package/src/components/ai-response/ai-response.tsx +1 -0
- package/src/components/ai-structured-output/ai-structured-output.tsx +25 -1
- package/src/components/diff-viewer/diff-model.ts +256 -0
- package/src/components/diff-viewer/diff-viewer.tsx +339 -0
- package/src/components/diff-viewer/index.ts +17 -0
- package/src/components/diff-viewer/meta.ts +20 -0
- package/src/components/file-upload/file-upload.tsx +322 -0
- package/src/components/file-upload/index.ts +20 -0
- package/src/components/file-upload/meta.ts +21 -0
- package/src/components/file-upload/upload-queue.ts +337 -0
- package/src/components/log-viewer/index.ts +21 -0
- package/src/components/log-viewer/log-stream.ts +176 -0
- package/src/components/log-viewer/log-viewer.tsx +424 -0
- package/src/components/log-viewer/meta.ts +21 -0
- package/src/components/progress/progress.tsx +3 -0
- package/src/components/spinner/spinner.tsx +5 -0
- package/src/components/tags-input/index.ts +1 -0
- package/src/components/tags-input/meta.ts +23 -0
- package/src/components/tags-input/tags-input.tsx +300 -0
- package/src/components/time-range-picker/index.ts +25 -0
- package/src/components/time-range-picker/meta.ts +22 -0
- package/src/components/time-range-picker/time-expression.ts +491 -0
- package/src/components/time-range-picker/time-range-picker.tsx +522 -0
- package/src/index.ts +8 -0
- package/src/registry/components.ts +16 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { LOG_LEVELS, compileQuery, findMatches, segment, useLogStream } from "./log-stream.js";
|
|
2
|
+
import { LogViewer, LogViewerRow, LogViewerToolbar } from "./log-viewer.js";
|
|
3
|
+
export { LOG_LEVELS, LogViewer, LogViewerRow, LogViewerToolbar, compileQuery, findMatches, segment, useLogStream };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/components/log-viewer/log-stream.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Filtering and match-finding for a log stream.
|
|
4
|
+
*
|
|
5
|
+
* Separate from the view because it is pure and worth testing without a DOM,
|
|
6
|
+
* and because the awkward parts are here rather than in the rendering: a bad
|
|
7
|
+
* regex must not throw while someone is halfway through typing it, and a match
|
|
8
|
+
* has to be located precisely enough to highlight rather than merely detected.
|
|
9
|
+
*/
|
|
10
|
+
type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
|
11
|
+
declare const LOG_LEVELS: readonly LogLevel[];
|
|
12
|
+
interface LogLine {
|
|
13
|
+
id: string;
|
|
14
|
+
message: string;
|
|
15
|
+
level?: LogLevel;
|
|
16
|
+
/** ISO timestamp, or anything the consumer wants shown in the gutter. */
|
|
17
|
+
timestamp?: string;
|
|
18
|
+
/** Structured fields, revealed when the row is expanded. */
|
|
19
|
+
fields?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/** A [start, end) slice of a message that matched the filter. */
|
|
22
|
+
type MatchRange = readonly [number, number];
|
|
23
|
+
interface FilterState {
|
|
24
|
+
/** Substring, or a pattern when `regex` is on. */
|
|
25
|
+
query: string;
|
|
26
|
+
regex: boolean;
|
|
27
|
+
/** Levels to show. Empty means all of them. */
|
|
28
|
+
levels: Set<LogLevel>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Compiles the query.
|
|
32
|
+
*
|
|
33
|
+
* Returns null for an invalid pattern rather than throwing: the query is being
|
|
34
|
+
* typed, so it spends most of its life syntactically incomplete, and a viewer
|
|
35
|
+
* that crashes on "(" is unusable.
|
|
36
|
+
*/
|
|
37
|
+
declare function compileQuery(query: string, regex: boolean): RegExp | null;
|
|
38
|
+
/** Every match in a line, so each can be highlighted rather than just the first. */
|
|
39
|
+
declare function findMatches(message: string, pattern: RegExp | null): MatchRange[];
|
|
40
|
+
/** Splits a message into alternating plain and matched segments. */
|
|
41
|
+
declare function segment(message: string, ranges: MatchRange[]): {
|
|
42
|
+
text: string;
|
|
43
|
+
match: boolean;
|
|
44
|
+
}[];
|
|
45
|
+
interface VisibleLine extends LogLine {
|
|
46
|
+
matches: MatchRange[];
|
|
47
|
+
}
|
|
48
|
+
interface UseLogStreamOptions {
|
|
49
|
+
lines: LogLine[];
|
|
50
|
+
/** Levels present but unchecked are hidden. Empty shows everything. */
|
|
51
|
+
initialLevels?: Set<LogLevel>;
|
|
52
|
+
}
|
|
53
|
+
declare function useLogStream({ lines, initialLevels }: UseLogStreamOptions): {
|
|
54
|
+
query: string;
|
|
55
|
+
setQuery: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
56
|
+
regex: boolean;
|
|
57
|
+
setRegex: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
58
|
+
levels: Set<LogLevel>;
|
|
59
|
+
toggleLevel: (level: LogLevel) => void;
|
|
60
|
+
setLevels: import("react").Dispatch<import("react").SetStateAction<Set<LogLevel>>>;
|
|
61
|
+
visible: VisibleLine[];
|
|
62
|
+
counts: Map<LogLevel, number>;
|
|
63
|
+
invalidPattern: boolean;
|
|
64
|
+
total: number;
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { FilterState, LOG_LEVELS, LogLevel, LogLine, MatchRange, UseLogStreamOptions, VisibleLine, compileQuery, findMatches, segment, useLogStream };
|
|
68
|
+
//# sourceMappingURL=log-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-stream.d.ts","names":[],"sources":["../../../src/components/log-viewer/log-stream.ts"],"mappings":";;;;;;;;;KAaY;cAEC,qBAAqB;UASjB;EACf;EACA;EACA,QAAQ;;EAER;;EAEA,SAAS;;;KAIC;UAEK;;EAEf;EACA;;EAEA,QAAQ,IAAI;;;;;;;;;iBAUE,aAAa,eAAe,iBAAiB;;iBAY7C,YAAY,iBAAiB,SAAS,gBAAgB;;iBAuBtD,QACd,iBACA,QAAQ;EACL;EAAc;;UAgBF,oBAAoB;EACnC,SAAS;;UAGM;EACf,OAAO;;EAEP,gBAAgB,IAAI;;iBAGN,eAAe,OAAO,iBAAiB;;;;;;EAqCb,cAAA,OAAA"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useMemo, useState } from "react";
|
|
3
|
+
//#region src/components/log-viewer/log-stream.ts
|
|
4
|
+
const LOG_LEVELS = [
|
|
5
|
+
"trace",
|
|
6
|
+
"debug",
|
|
7
|
+
"info",
|
|
8
|
+
"warn",
|
|
9
|
+
"error",
|
|
10
|
+
"fatal"
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* Compiles the query.
|
|
14
|
+
*
|
|
15
|
+
* Returns null for an invalid pattern rather than throwing: the query is being
|
|
16
|
+
* typed, so it spends most of its life syntactically incomplete, and a viewer
|
|
17
|
+
* that crashes on "(" is unusable.
|
|
18
|
+
*/
|
|
19
|
+
function compileQuery(query, regex) {
|
|
20
|
+
if (query.length === 0) return null;
|
|
21
|
+
try {
|
|
22
|
+
return regex ? new RegExp(query, "gi") : new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi");
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Every match in a line, so each can be highlighted rather than just the first. */
|
|
28
|
+
function findMatches(message, pattern) {
|
|
29
|
+
if (!pattern) return [];
|
|
30
|
+
const ranges = [];
|
|
31
|
+
pattern.lastIndex = 0;
|
|
32
|
+
let match = pattern.exec(message);
|
|
33
|
+
while (match !== null) {
|
|
34
|
+
if (match[0].length === 0) pattern.lastIndex += 1;
|
|
35
|
+
else ranges.push([match.index, match.index + match[0].length]);
|
|
36
|
+
match = pattern.exec(message);
|
|
37
|
+
}
|
|
38
|
+
return ranges;
|
|
39
|
+
}
|
|
40
|
+
/** Splits a message into alternating plain and matched segments. */
|
|
41
|
+
function segment(message, ranges) {
|
|
42
|
+
if (ranges.length === 0) return [{
|
|
43
|
+
text: message,
|
|
44
|
+
match: false
|
|
45
|
+
}];
|
|
46
|
+
const parts = [];
|
|
47
|
+
let cursor = 0;
|
|
48
|
+
for (const [start, end] of ranges) {
|
|
49
|
+
if (start > cursor) parts.push({
|
|
50
|
+
text: message.slice(cursor, start),
|
|
51
|
+
match: false
|
|
52
|
+
});
|
|
53
|
+
parts.push({
|
|
54
|
+
text: message.slice(start, end),
|
|
55
|
+
match: true
|
|
56
|
+
});
|
|
57
|
+
cursor = end;
|
|
58
|
+
}
|
|
59
|
+
if (cursor < message.length) parts.push({
|
|
60
|
+
text: message.slice(cursor),
|
|
61
|
+
match: false
|
|
62
|
+
});
|
|
63
|
+
return parts;
|
|
64
|
+
}
|
|
65
|
+
function useLogStream({ lines, initialLevels }) {
|
|
66
|
+
const [query, setQuery] = useState("");
|
|
67
|
+
const [regex, setRegex] = useState(false);
|
|
68
|
+
const [levels, setLevels] = useState(initialLevels ?? /* @__PURE__ */ new Set());
|
|
69
|
+
const pattern = useMemo(() => compileQuery(query, regex), [query, regex]);
|
|
70
|
+
const invalidPattern = regex && query.length > 0 && pattern === null;
|
|
71
|
+
const visible = useMemo(() => {
|
|
72
|
+
const result = [];
|
|
73
|
+
for (const line of lines) {
|
|
74
|
+
if (levels.size > 0 && line.level && !levels.has(line.level)) continue;
|
|
75
|
+
const matches = findMatches(line.message, pattern);
|
|
76
|
+
if (pattern && matches.length === 0) continue;
|
|
77
|
+
result.push({
|
|
78
|
+
...line,
|
|
79
|
+
matches
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}, [
|
|
84
|
+
lines,
|
|
85
|
+
levels,
|
|
86
|
+
pattern
|
|
87
|
+
]);
|
|
88
|
+
const counts = useMemo(() => {
|
|
89
|
+
const byLevel = /* @__PURE__ */ new Map();
|
|
90
|
+
for (const line of lines) {
|
|
91
|
+
if (!line.level) continue;
|
|
92
|
+
byLevel.set(line.level, (byLevel.get(line.level) ?? 0) + 1);
|
|
93
|
+
}
|
|
94
|
+
return byLevel;
|
|
95
|
+
}, [lines]);
|
|
96
|
+
return {
|
|
97
|
+
query,
|
|
98
|
+
setQuery,
|
|
99
|
+
regex,
|
|
100
|
+
setRegex,
|
|
101
|
+
levels,
|
|
102
|
+
toggleLevel: useCallback((level) => {
|
|
103
|
+
setLevels((current) => {
|
|
104
|
+
const next = new Set(current);
|
|
105
|
+
if (next.has(level)) next.delete(level);
|
|
106
|
+
else next.add(level);
|
|
107
|
+
return next;
|
|
108
|
+
});
|
|
109
|
+
}, []),
|
|
110
|
+
setLevels,
|
|
111
|
+
visible,
|
|
112
|
+
counts,
|
|
113
|
+
invalidPattern,
|
|
114
|
+
total: lines.length
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
export { LOG_LEVELS, compileQuery, findMatches, segment, useLogStream };
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=log-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-stream.js","names":[],"sources":["../../../src/components/log-viewer/log-stream.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useMemo, useState } from \"react\";\n\n/**\n * Filtering and match-finding for a log stream.\n *\n * Separate from the view because it is pure and worth testing without a DOM,\n * and because the awkward parts are here rather than in the rendering: a bad\n * regex must not throw while someone is halfway through typing it, and a match\n * has to be located precisely enough to highlight rather than merely detected.\n */\n\nexport type LogLevel = \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"fatal\";\n\nexport const LOG_LEVELS: readonly LogLevel[] = [\n \"trace\",\n \"debug\",\n \"info\",\n \"warn\",\n \"error\",\n \"fatal\",\n];\n\nexport interface LogLine {\n id: string;\n message: string;\n level?: LogLevel;\n /** ISO timestamp, or anything the consumer wants shown in the gutter. */\n timestamp?: string;\n /** Structured fields, revealed when the row is expanded. */\n fields?: Record<string, unknown>;\n}\n\n/** A [start, end) slice of a message that matched the filter. */\nexport type MatchRange = readonly [number, number];\n\nexport interface FilterState {\n /** Substring, or a pattern when `regex` is on. */\n query: string;\n regex: boolean;\n /** Levels to show. Empty means all of them. */\n levels: Set<LogLevel>;\n}\n\n/**\n * Compiles the query.\n *\n * Returns null for an invalid pattern rather than throwing: the query is being\n * typed, so it spends most of its life syntactically incomplete, and a viewer\n * that crashes on \"(\" is unusable.\n */\nexport function compileQuery(query: string, regex: boolean): RegExp | null {\n if (query.length === 0) return null;\n try {\n return regex\n ? new RegExp(query, \"gi\")\n : new RegExp(query.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"), \"gi\");\n } catch {\n return null;\n }\n}\n\n/** Every match in a line, so each can be highlighted rather than just the first. */\nexport function findMatches(message: string, pattern: RegExp | null): MatchRange[] {\n if (!pattern) return [];\n\n const ranges: MatchRange[] = [];\n // Fresh lastIndex: the pattern is reused across lines and a global regex\n // carries position between calls, which would skip matches in later lines.\n pattern.lastIndex = 0;\n\n let match = pattern.exec(message);\n while (match !== null) {\n // A pattern that can match empty — \"a*\" — would loop forever otherwise.\n if (match[0].length === 0) {\n pattern.lastIndex += 1;\n } else {\n ranges.push([match.index, match.index + match[0].length]);\n }\n match = pattern.exec(message);\n }\n\n return ranges;\n}\n\n/** Splits a message into alternating plain and matched segments. */\nexport function segment(\n message: string,\n ranges: MatchRange[],\n): { text: string; match: boolean }[] {\n if (ranges.length === 0) return [{ text: message, match: false }];\n\n const parts: { text: string; match: boolean }[] = [];\n let cursor = 0;\n\n for (const [start, end] of ranges) {\n if (start > cursor) parts.push({ text: message.slice(cursor, start), match: false });\n parts.push({ text: message.slice(start, end), match: true });\n cursor = end;\n }\n if (cursor < message.length) parts.push({ text: message.slice(cursor), match: false });\n\n return parts;\n}\n\nexport interface VisibleLine extends LogLine {\n matches: MatchRange[];\n}\n\nexport interface UseLogStreamOptions {\n lines: LogLine[];\n /** Levels present but unchecked are hidden. Empty shows everything. */\n initialLevels?: Set<LogLevel>;\n}\n\nexport function useLogStream({ lines, initialLevels }: UseLogStreamOptions) {\n const [query, setQuery] = useState(\"\");\n const [regex, setRegex] = useState(false);\n const [levels, setLevels] = useState<Set<LogLevel>>(initialLevels ?? new Set());\n\n const pattern = useMemo(() => compileQuery(query, regex), [query, regex]);\n\n // An invalid pattern is reported, not swallowed: with no feedback the reader\n // sees an empty log and concludes nothing matched.\n const invalidPattern = regex && query.length > 0 && pattern === null;\n\n const visible = useMemo<VisibleLine[]>(() => {\n const result: VisibleLine[] = [];\n\n for (const line of lines) {\n if (levels.size > 0 && line.level && !levels.has(line.level)) continue;\n\n const matches = findMatches(line.message, pattern);\n // A query with no match hides the line; an invalid pattern hides nothing,\n // because the reader has not finished saying what they want yet.\n if (pattern && matches.length === 0) continue;\n\n result.push({ ...line, matches });\n }\n\n return result;\n }, [lines, levels, pattern]);\n\n const counts = useMemo(() => {\n const byLevel = new Map<LogLevel, number>();\n for (const line of lines) {\n if (!line.level) continue;\n byLevel.set(line.level, (byLevel.get(line.level) ?? 0) + 1);\n }\n return byLevel;\n }, [lines]);\n\n const toggleLevel = useCallback((level: LogLevel) => {\n setLevels((current) => {\n const next = new Set(current);\n if (next.has(level)) next.delete(level);\n else next.add(level);\n return next;\n });\n }, []);\n\n return {\n query,\n setQuery,\n regex,\n setRegex,\n levels,\n toggleLevel,\n setLevels,\n visible,\n counts,\n invalidPattern,\n total: lines.length,\n };\n}\n"],"mappings":";;;AAeA,MAAa,aAAkC;CAC7C;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;AA8BA,SAAgB,aAAa,OAAe,OAA+B;CACzE,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,IAAI;EACF,OAAO,QACH,IAAI,OAAO,OAAO,IAAI,IACtB,IAAI,OAAO,MAAM,QAAQ,uBAAuB,MAAM,GAAG,IAAI;CACnE,QAAQ;EACN,OAAO;CACT;AACF;;AAGA,SAAgB,YAAY,SAAiB,SAAsC;CACjF,IAAI,CAAC,SAAS,OAAO,CAAC;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,OAAO,KAAK,KAAK,SAAS,CAAC,OAAO,IAAI,KAAK,KAAK,GAAG;GAE9D,MAAM,UAAU,YAAY,KAAK,SAAS,OAAO;GAGjD,IAAI,WAAW,QAAQ,WAAW,GAAG;GAErC,OAAO,KAAK;IAAE,GAAG;IAAM;GAAQ,CAAC;EAClC;EAEA,OAAO;CACT,GAAG;EAAC;EAAO;EAAQ;CAAO,CAAC;CAE3B,MAAM,SAAS,cAAc;EAC3B,MAAM,0BAAU,IAAI,IAAsB;EAC1C,KAAK,MAAM,QAAQ,OAAO;GACxB,IAAI,CAAC,KAAK,OAAO;GACjB,QAAQ,IAAI,KAAK,QAAQ,QAAQ,IAAI,KAAK,KAAK,KAAK,KAAK,CAAC;EAC5D;EACA,OAAO;CACT,GAAG,CAAC,KAAK,CAAC;CAWV,OAAO;EACL;EACA;EACA;EACA;EACA;EACA,aAfkB,aAAa,UAAoB;GACnD,WAAW,YAAY;IACrB,MAAM,OAAO,IAAI,IAAI,OAAO;IAC5B,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,OAAO,KAAK;SACjC,KAAK,IAAI,KAAK;IACnB,OAAO;GACT,CAAC;EACH,GAAG,CAAC,CAQQ;EACV;EACA;EACA;EACA;EACA,OAAO,MAAM;CACf;AACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { LogLevel, VisibleLine } from "./log-stream.js";
|
|
2
|
+
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
//#region src/components/log-viewer/log-viewer.d.ts
|
|
4
|
+
interface LogViewerProps extends Omit<ComponentPropsWithRef<"div">, "children"> {
|
|
5
|
+
lines: VisibleLine[];
|
|
6
|
+
/** Names the region. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Row height in pixels. Rows are one line; expansion is measured. */
|
|
9
|
+
rowHeight?: number;
|
|
10
|
+
height?: number | string;
|
|
11
|
+
/**
|
|
12
|
+
* Read new lines aloud. Off by default — a console that announces every line
|
|
13
|
+
* makes a screen reader useless for anything else.
|
|
14
|
+
*/
|
|
15
|
+
announce?: boolean;
|
|
16
|
+
/** The way out of the virtual window, for anyone who needs the whole log. */
|
|
17
|
+
onDownload?: () => void;
|
|
18
|
+
children?: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
declare function LogViewer({ className, lines, label, rowHeight, height, announce, onDownload, children, ...props }: LogViewerProps): import("react").JSX.Element;
|
|
21
|
+
interface LogViewerRowProps {
|
|
22
|
+
line: VisibleLine;
|
|
23
|
+
expanded?: boolean;
|
|
24
|
+
onToggle?: () => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One line.
|
|
28
|
+
*
|
|
29
|
+
* Exported because the virtualized container cannot be measured outside a real
|
|
30
|
+
* browser — jsdom reports every box as zero — so the row's behaviour would
|
|
31
|
+
* otherwise be untestable. It is also genuinely useful on its own for anyone
|
|
32
|
+
* rendering a short log without virtualization.
|
|
33
|
+
*/
|
|
34
|
+
declare function LogViewerRow({ line, expanded, onToggle }: LogViewerRowProps): import("react").JSX.Element;
|
|
35
|
+
interface LogViewerToolbarProps extends Omit<ComponentPropsWithRef<"div">, "onChange"> {
|
|
36
|
+
query: string;
|
|
37
|
+
onQueryChange: (query: string) => void;
|
|
38
|
+
regex: boolean;
|
|
39
|
+
onRegexChange: (regex: boolean) => void;
|
|
40
|
+
levels: Set<LogLevel>;
|
|
41
|
+
onToggleLevel: (level: LogLevel) => void;
|
|
42
|
+
counts: Map<LogLevel, number>;
|
|
43
|
+
invalidPattern?: boolean;
|
|
44
|
+
/** Shown as "N of M lines". */
|
|
45
|
+
showing: number;
|
|
46
|
+
total: number;
|
|
47
|
+
}
|
|
48
|
+
declare function LogViewerToolbar({ className, query, onQueryChange, regex, onRegexChange, levels, onToggleLevel, counts, invalidPattern, showing, total, ...props }: LogViewerToolbarProps): import("react").JSX.Element;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { LogViewer, LogViewerProps, LogViewerRow, LogViewerRowProps, LogViewerToolbar, LogViewerToolbarProps };
|
|
51
|
+
//# sourceMappingURL=log-viewer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-viewer.d.ts","names":[],"sources":["../../../src/components/log-viewer/log-viewer.tsx"],"mappings":";;;UAmDiB,uBAAuB,KAAK;EAC3C,OAAO;;EAEP;;EAEA;EACA;;;;;EAKA;;EAEA;EACA,WAAW;;iBAGG,YACd,WACA,OACA,OACA,WACA,QACA,UACA,YACA,aACG,SACF,iCAAc,IAAA;UAmJA;EACf,MAAM;EACN;EACA;;;;;;;;;;iBAWc,eAAe,MAAM,UAAkB,YAAY,oCAAiB,IAAA;UA2EnE,8BAA8B,KAAK;EAClD;EACA,gBAAgB;EAChB;EACA,gBAAgB;EAChB,QAAQ,IAAI;EACZ,gBAAgB,OAAO;EACvB,QAAQ,IAAI;EACZ;;EAEA;EACA;;iBAGc,mBACd,WACA,OACA,eACA,OACA,eACA,QACA,eACA,QACA,gBACA,SACA,UACG,SACF,wCAAqB,IAAA"}
|
|
@@ -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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,UAAA;IAE1C,CAAA,IAEN,GAAG,OAAO,OAAO,EAAE,MAAM,OAAO,KAAK,EAAE;GAExC,CAAA;EACA;;AAET"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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"}
|
|
@@ -4,7 +4,7 @@ import { ComponentPropsWithRef } from "react";
|
|
|
4
4
|
//#region src/components/progress/progress.d.ts
|
|
5
5
|
declare const progressVariants: (props?: ({
|
|
6
6
|
size?: "sm" | "md" | "lg" | null | undefined;
|
|
7
|
-
tone?: "
|
|
7
|
+
tone?: "destructive" | "success" | "warning" | "primary" | null | undefined;
|
|
8
8
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
9
9
|
interface ProgressProps extends ComponentPropsWithRef<typeof Progress.Root>, VariantProps<typeof progressVariants> {}
|
|
10
10
|
/**
|
|
@@ -44,6 +44,7 @@ function Progress$1({ className, size, tone, value, ...props }) {
|
|
|
44
44
|
...props,
|
|
45
45
|
children: /* @__PURE__ */ jsx(Progress.Indicator, {
|
|
46
46
|
"data-slot": "progress-indicator",
|
|
47
|
+
"data-motion": indeterminate ? "indicator" : void 0,
|
|
47
48
|
className: cn("h-full w-full flex-1 rounded-full bg-[var(--progress-fill)]", "transition-transform duration-[var(--duration-slow)] ease-[var(--ease-out-quint)]", indeterminate && "animate-pulse-soft"),
|
|
48
49
|
style: indeterminate ? void 0 : { transform: `translateX(-${String(100 - percent)}%)` }
|
|
49
50
|
})
|