@zenera/cli 1.3.21 → 1.3.23
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/package.json +6 -6
- package/templates/editor/.github/skills/zen-review/scripts/check-paths.sh +1 -1
- package/templates/project/agents/skills/html-page/SKILL.md +96 -51
- package/templates/project/agents/skills/html-page/assets/app/api/items.api.py +3 -2
- package/templates/project/agents/skills/html-page/assets/app/app.tsx +140 -0
- package/templates/project/agents/skills/html-page/assets/dashboard.tsx +162 -0
- package/templates/project/agents/skills/html-page/kit/Chart.tsx +79 -0
- package/templates/project/agents/skills/html-page/kit/Table.tsx +89 -0
- package/templates/project/agents/skills/html-page/kit/api.ts +93 -0
- package/templates/project/agents/skills/html-page/kit/components.tsx +266 -0
- package/templates/project/agents/skills/html-page/kit/format.ts +60 -0
- package/templates/project/agents/skills/html-page/kit/hooks.ts +159 -0
- package/templates/project/agents/skills/html-page/kit/index.ts +35 -0
- package/templates/project/agents/skills/html-page/kit/modules.d.ts +37 -0
- package/templates/project/agents/skills/html-page/kit/mount.tsx +62 -0
- package/templates/project/agents/skills/html-page/kit/shell.html +19 -0
- package/templates/project/agents/skills/html-page/kit/theme.css +326 -0
- package/templates/project/agents/skills/html-page/references/charts-and-tables.md +105 -53
- package/templates/project/agents/skills/html-page/references/python-functions.md +40 -29
- package/templates/project/agents/skills/html-page/scripts/build.ts +825 -0
- package/templates/project/agents/skills/html-page/assets/api.js +0 -87
- package/templates/project/agents/skills/html-page/assets/app/index.html +0 -278
- package/templates/project/agents/skills/html-page/assets/dashboard.html +0 -423
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The page kit, imported by pages as `@page/kit`. The build bundles it into each page.
|
|
2
|
+
import './theme.css';
|
|
3
|
+
|
|
4
|
+
export { ApiError, api, call, type AnyApi } from './api.ts';
|
|
5
|
+
export {
|
|
6
|
+
fetchJson,
|
|
7
|
+
toError,
|
|
8
|
+
useAction,
|
|
9
|
+
useCall,
|
|
10
|
+
useDarkMode,
|
|
11
|
+
useData,
|
|
12
|
+
useHashState,
|
|
13
|
+
type Action,
|
|
14
|
+
type Call,
|
|
15
|
+
} from './hooks.ts';
|
|
16
|
+
export { fmt, groupSum, sum, uniq } from './format.ts';
|
|
17
|
+
export {
|
|
18
|
+
Card,
|
|
19
|
+
ConfirmButton,
|
|
20
|
+
Empty,
|
|
21
|
+
ErrorBox,
|
|
22
|
+
Field,
|
|
23
|
+
Grid,
|
|
24
|
+
Kpi,
|
|
25
|
+
Kpis,
|
|
26
|
+
Loading,
|
|
27
|
+
Page,
|
|
28
|
+
SafeHtml,
|
|
29
|
+
Select,
|
|
30
|
+
Split,
|
|
31
|
+
Toolbar,
|
|
32
|
+
type Option,
|
|
33
|
+
} from './components.tsx';
|
|
34
|
+
export { Chart, type ChartEvent, type ChartOption } from './Chart.tsx';
|
|
35
|
+
export { Table, type Column } from './Table.tsx';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Files a page may import: the build inlines them (images and fonts as data: URLs, text as a string).
|
|
2
|
+
declare module '*.png' {
|
|
3
|
+
const src: string;
|
|
4
|
+
export default src;
|
|
5
|
+
}
|
|
6
|
+
declare module '*.jpg' {
|
|
7
|
+
const src: string;
|
|
8
|
+
export default src;
|
|
9
|
+
}
|
|
10
|
+
declare module '*.jpeg' {
|
|
11
|
+
const src: string;
|
|
12
|
+
export default src;
|
|
13
|
+
}
|
|
14
|
+
declare module '*.gif' {
|
|
15
|
+
const src: string;
|
|
16
|
+
export default src;
|
|
17
|
+
}
|
|
18
|
+
declare module '*.webp' {
|
|
19
|
+
const src: string;
|
|
20
|
+
export default src;
|
|
21
|
+
}
|
|
22
|
+
declare module '*.svg' {
|
|
23
|
+
const src: string;
|
|
24
|
+
export default src;
|
|
25
|
+
}
|
|
26
|
+
declare module '*.woff2' {
|
|
27
|
+
const src: string;
|
|
28
|
+
export default src;
|
|
29
|
+
}
|
|
30
|
+
declare module '*.txt' {
|
|
31
|
+
const text: string;
|
|
32
|
+
export default text;
|
|
33
|
+
}
|
|
34
|
+
declare module '*.md' {
|
|
35
|
+
const text: string;
|
|
36
|
+
export default text;
|
|
37
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Component, StrictMode, type ComponentType, type ErrorInfo, type ReactNode } from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
|
|
4
|
+
// The build's entry: it mounts the page's default export into #root. Pages never call this.
|
|
5
|
+
|
|
6
|
+
class Boundary extends Component<{ children: ReactNode }, { error: Error | null }> {
|
|
7
|
+
override state: { error: Error | null } = { error: null };
|
|
8
|
+
|
|
9
|
+
static getDerivedStateFromError(error: unknown) {
|
|
10
|
+
return { error: error instanceof Error ? error : new Error(String(error)) };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override componentDidCatch(error: unknown, info: ErrorInfo) {
|
|
14
|
+
console.error(error, info.componentStack);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override render() {
|
|
18
|
+
const { error } = this.state;
|
|
19
|
+
if (!error) return this.props.children;
|
|
20
|
+
return (
|
|
21
|
+
<main className="page page-narrow">
|
|
22
|
+
<div className="card error" role="alert">
|
|
23
|
+
<strong>This page hit an error.</strong>
|
|
24
|
+
<span>{error.message}</span>
|
|
25
|
+
<button onClick={() => this.setState({ error: null })}>Try again</button>
|
|
26
|
+
</div>
|
|
27
|
+
</main>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Errors outside rendering (a handler, a promise nobody awaited): shown, not swallowed. */
|
|
33
|
+
function reportUncaught() {
|
|
34
|
+
const show = (message: string) => {
|
|
35
|
+
let bar = document.getElementById('page-uncaught');
|
|
36
|
+
if (!bar) {
|
|
37
|
+
bar = document.createElement('div');
|
|
38
|
+
bar.id = 'page-uncaught';
|
|
39
|
+
bar.className = 'uncaught';
|
|
40
|
+
bar.setAttribute('role', 'alert');
|
|
41
|
+
bar.addEventListener('click', () => bar?.remove());
|
|
42
|
+
document.body.append(bar);
|
|
43
|
+
}
|
|
44
|
+
bar.textContent = `Something went wrong: ${message} (click to dismiss)`;
|
|
45
|
+
};
|
|
46
|
+
window.addEventListener('error', (e) => show(e.message || 'an error'));
|
|
47
|
+
window.addEventListener('unhandledrejection', (e) => {
|
|
48
|
+
const reason: unknown = e.reason;
|
|
49
|
+
show(reason instanceof Error ? reason.message : String(reason));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function mount(App: ComponentType) {
|
|
54
|
+
reportUncaught();
|
|
55
|
+
createRoot(document.getElementById('root')!).render(
|
|
56
|
+
<StrictMode>
|
|
57
|
+
<Boundary>
|
|
58
|
+
<App />
|
|
59
|
+
</Boundary>
|
|
60
|
+
</StrictMode>,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<!--STAMP-->
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
<title><!--TITLE--></title>
|
|
8
|
+
<!--HEAD-->
|
|
9
|
+
<style>
|
|
10
|
+
<!--CSS-->
|
|
11
|
+
</style>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div id="root"></div>
|
|
15
|
+
<script type="module">
|
|
16
|
+
<!--JS-->
|
|
17
|
+
</script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/* The kit's look: colours from these variables only, light and dark. */
|
|
2
|
+
:root {
|
|
3
|
+
color-scheme: light dark;
|
|
4
|
+
--bg: #f7f7f8;
|
|
5
|
+
--card: #ffffff;
|
|
6
|
+
--fg: #1d1d1f;
|
|
7
|
+
--muted: #6e6e73;
|
|
8
|
+
--line: #e3e3e6;
|
|
9
|
+
--accent: #2563eb;
|
|
10
|
+
--accent-fg: #ffffff;
|
|
11
|
+
--up: #15803d;
|
|
12
|
+
--down: #b91c1c;
|
|
13
|
+
--danger: #b91c1c;
|
|
14
|
+
--gap: 16px;
|
|
15
|
+
--radius: 10px;
|
|
16
|
+
font:
|
|
17
|
+
14px/1.45 system-ui,
|
|
18
|
+
-apple-system,
|
|
19
|
+
'Segoe UI',
|
|
20
|
+
Roboto,
|
|
21
|
+
sans-serif;
|
|
22
|
+
}
|
|
23
|
+
@media (prefers-color-scheme: dark) {
|
|
24
|
+
:root {
|
|
25
|
+
--bg: #141416;
|
|
26
|
+
--card: #1e1e21;
|
|
27
|
+
--fg: #ececf0;
|
|
28
|
+
--muted: #9a9aa2;
|
|
29
|
+
--line: #2e2e33;
|
|
30
|
+
--accent: #60a5fa;
|
|
31
|
+
--accent-fg: #0b1220;
|
|
32
|
+
--up: #4ade80;
|
|
33
|
+
--down: #f87171;
|
|
34
|
+
--danger: #f87171;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
* {
|
|
38
|
+
box-sizing: border-box;
|
|
39
|
+
}
|
|
40
|
+
body {
|
|
41
|
+
margin: 0;
|
|
42
|
+
background: var(--bg);
|
|
43
|
+
color: var(--fg);
|
|
44
|
+
}
|
|
45
|
+
[hidden] {
|
|
46
|
+
display: none !important;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* The page */
|
|
50
|
+
.page {
|
|
51
|
+
margin: 0 auto;
|
|
52
|
+
padding: var(--gap);
|
|
53
|
+
display: grid;
|
|
54
|
+
gap: var(--gap);
|
|
55
|
+
container: page / inline-size;
|
|
56
|
+
}
|
|
57
|
+
.page > * {
|
|
58
|
+
min-width: 0;
|
|
59
|
+
}
|
|
60
|
+
.page-wide {
|
|
61
|
+
max-width: 1400px;
|
|
62
|
+
}
|
|
63
|
+
.page-narrow {
|
|
64
|
+
max-width: 900px;
|
|
65
|
+
}
|
|
66
|
+
.page-header {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-wrap: wrap;
|
|
69
|
+
gap: 8px 16px;
|
|
70
|
+
align-items: start;
|
|
71
|
+
justify-content: space-between;
|
|
72
|
+
}
|
|
73
|
+
.page-header h1 {
|
|
74
|
+
margin: 0;
|
|
75
|
+
font-size: 1.4rem;
|
|
76
|
+
}
|
|
77
|
+
.page-header p {
|
|
78
|
+
margin: 4px 0 0;
|
|
79
|
+
color: var(--muted);
|
|
80
|
+
}
|
|
81
|
+
.page-footer {
|
|
82
|
+
color: var(--muted);
|
|
83
|
+
font-size: 0.8rem;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* Boxes and layout */
|
|
87
|
+
.card {
|
|
88
|
+
background: var(--card);
|
|
89
|
+
border: 1px solid var(--line);
|
|
90
|
+
border-radius: var(--radius);
|
|
91
|
+
padding: var(--gap);
|
|
92
|
+
min-width: 0;
|
|
93
|
+
}
|
|
94
|
+
.card-header {
|
|
95
|
+
display: flex;
|
|
96
|
+
flex-wrap: wrap;
|
|
97
|
+
gap: 8px;
|
|
98
|
+
align-items: center;
|
|
99
|
+
justify-content: space-between;
|
|
100
|
+
margin: 0 0 8px;
|
|
101
|
+
}
|
|
102
|
+
.card h2 {
|
|
103
|
+
margin: 0;
|
|
104
|
+
font-size: 1rem;
|
|
105
|
+
}
|
|
106
|
+
.grid {
|
|
107
|
+
display: grid;
|
|
108
|
+
gap: var(--gap);
|
|
109
|
+
grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--min, 420px)), 1fr));
|
|
110
|
+
}
|
|
111
|
+
.grid > * {
|
|
112
|
+
min-width: 0;
|
|
113
|
+
}
|
|
114
|
+
.wide {
|
|
115
|
+
grid-column: 1 / -1;
|
|
116
|
+
}
|
|
117
|
+
.row {
|
|
118
|
+
display: flex;
|
|
119
|
+
flex-wrap: wrap;
|
|
120
|
+
gap: 8px;
|
|
121
|
+
align-items: center;
|
|
122
|
+
}
|
|
123
|
+
.row > * {
|
|
124
|
+
min-width: 0;
|
|
125
|
+
}
|
|
126
|
+
.split {
|
|
127
|
+
display: grid;
|
|
128
|
+
gap: var(--gap);
|
|
129
|
+
}
|
|
130
|
+
.split > * {
|
|
131
|
+
min-width: 0;
|
|
132
|
+
}
|
|
133
|
+
.split.split-open > .split-list,
|
|
134
|
+
.split:not(.split-open) > .split-detail {
|
|
135
|
+
display: none;
|
|
136
|
+
}
|
|
137
|
+
@container page (min-width: 860px) {
|
|
138
|
+
.split {
|
|
139
|
+
grid-template-columns: minmax(280px, 2fr) 3fr;
|
|
140
|
+
align-items: start;
|
|
141
|
+
}
|
|
142
|
+
.split.split-open > .split-list,
|
|
143
|
+
.split:not(.split-open) > .split-detail {
|
|
144
|
+
display: block;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* Controls */
|
|
149
|
+
.toolbar {
|
|
150
|
+
display: flex;
|
|
151
|
+
flex-wrap: wrap;
|
|
152
|
+
gap: 8px 16px;
|
|
153
|
+
align-items: end;
|
|
154
|
+
}
|
|
155
|
+
.field {
|
|
156
|
+
display: grid;
|
|
157
|
+
gap: 2px;
|
|
158
|
+
font-size: 0.85rem;
|
|
159
|
+
color: var(--muted);
|
|
160
|
+
}
|
|
161
|
+
input,
|
|
162
|
+
select,
|
|
163
|
+
textarea,
|
|
164
|
+
button {
|
|
165
|
+
font: inherit;
|
|
166
|
+
color: var(--fg);
|
|
167
|
+
background: var(--card);
|
|
168
|
+
border: 1px solid var(--line);
|
|
169
|
+
border-radius: 6px;
|
|
170
|
+
padding: 6px 10px;
|
|
171
|
+
max-width: 100%;
|
|
172
|
+
}
|
|
173
|
+
select {
|
|
174
|
+
min-width: 9rem;
|
|
175
|
+
}
|
|
176
|
+
input[type='text'],
|
|
177
|
+
input[type='search'],
|
|
178
|
+
input:not([type]),
|
|
179
|
+
textarea {
|
|
180
|
+
flex: 1 1 14rem;
|
|
181
|
+
}
|
|
182
|
+
input[type='checkbox'],
|
|
183
|
+
input[type='radio'] {
|
|
184
|
+
padding: 0;
|
|
185
|
+
}
|
|
186
|
+
button {
|
|
187
|
+
cursor: pointer;
|
|
188
|
+
}
|
|
189
|
+
button.primary {
|
|
190
|
+
background: var(--accent);
|
|
191
|
+
border-color: var(--accent);
|
|
192
|
+
color: var(--accent-fg);
|
|
193
|
+
}
|
|
194
|
+
button.danger {
|
|
195
|
+
color: var(--danger);
|
|
196
|
+
}
|
|
197
|
+
button:disabled {
|
|
198
|
+
opacity: 0.6;
|
|
199
|
+
cursor: default;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/* Headline numbers */
|
|
203
|
+
.kpis {
|
|
204
|
+
display: grid;
|
|
205
|
+
gap: var(--gap);
|
|
206
|
+
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
|
207
|
+
}
|
|
208
|
+
.kpi-label {
|
|
209
|
+
color: var(--muted);
|
|
210
|
+
font-size: 0.85rem;
|
|
211
|
+
}
|
|
212
|
+
.kpi-value {
|
|
213
|
+
font-size: 1.6rem;
|
|
214
|
+
font-weight: 600;
|
|
215
|
+
font-variant-numeric: tabular-nums;
|
|
216
|
+
}
|
|
217
|
+
.kpi-delta.up {
|
|
218
|
+
color: var(--up);
|
|
219
|
+
}
|
|
220
|
+
.kpi-delta.down {
|
|
221
|
+
color: var(--down);
|
|
222
|
+
}
|
|
223
|
+
.kpi-hint {
|
|
224
|
+
color: var(--muted);
|
|
225
|
+
font-size: 0.8rem;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/* Lists */
|
|
229
|
+
ul.list {
|
|
230
|
+
list-style: none;
|
|
231
|
+
margin: 0;
|
|
232
|
+
padding: 0;
|
|
233
|
+
}
|
|
234
|
+
ul.list li {
|
|
235
|
+
display: flex;
|
|
236
|
+
gap: 10px;
|
|
237
|
+
align-items: center;
|
|
238
|
+
padding: 8px 0;
|
|
239
|
+
border-bottom: 1px solid var(--line);
|
|
240
|
+
}
|
|
241
|
+
ul.list li:last-child {
|
|
242
|
+
border-bottom: 0;
|
|
243
|
+
}
|
|
244
|
+
ul.list .grow {
|
|
245
|
+
flex: 1;
|
|
246
|
+
min-width: 0;
|
|
247
|
+
overflow-wrap: anywhere;
|
|
248
|
+
}
|
|
249
|
+
ul.list li.done .grow {
|
|
250
|
+
color: var(--muted);
|
|
251
|
+
text-decoration: line-through;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/* States */
|
|
255
|
+
.muted {
|
|
256
|
+
color: var(--muted);
|
|
257
|
+
}
|
|
258
|
+
.empty {
|
|
259
|
+
margin: 0;
|
|
260
|
+
}
|
|
261
|
+
.error {
|
|
262
|
+
color: var(--danger);
|
|
263
|
+
border-color: var(--danger);
|
|
264
|
+
display: flex;
|
|
265
|
+
flex-wrap: wrap;
|
|
266
|
+
gap: 8px 12px;
|
|
267
|
+
align-items: center;
|
|
268
|
+
}
|
|
269
|
+
.uncaught {
|
|
270
|
+
position: fixed;
|
|
271
|
+
inset: auto 8px 8px;
|
|
272
|
+
z-index: 1000;
|
|
273
|
+
padding: 10px 14px;
|
|
274
|
+
border-radius: var(--radius);
|
|
275
|
+
background: var(--danger);
|
|
276
|
+
color: #fff;
|
|
277
|
+
cursor: pointer;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/* Charts, tables, embedded html */
|
|
281
|
+
.chart {
|
|
282
|
+
width: 100%;
|
|
283
|
+
}
|
|
284
|
+
.safe-html {
|
|
285
|
+
width: 100%;
|
|
286
|
+
border: 1px solid var(--line);
|
|
287
|
+
border-radius: var(--radius);
|
|
288
|
+
background: #fff;
|
|
289
|
+
}
|
|
290
|
+
.tabulator {
|
|
291
|
+
font-size: 0.9rem;
|
|
292
|
+
background: transparent;
|
|
293
|
+
border-color: var(--line);
|
|
294
|
+
}
|
|
295
|
+
.tabulator .tabulator-header,
|
|
296
|
+
.tabulator .tabulator-header .tabulator-col,
|
|
297
|
+
.tabulator .tabulator-tableholder,
|
|
298
|
+
.tabulator .tabulator-tableholder .tabulator-table,
|
|
299
|
+
.tabulator-row,
|
|
300
|
+
.tabulator .tabulator-footer {
|
|
301
|
+
background: var(--card);
|
|
302
|
+
color: var(--fg);
|
|
303
|
+
border-color: var(--line);
|
|
304
|
+
}
|
|
305
|
+
.tabulator-row.tabulator-row-even {
|
|
306
|
+
background: color-mix(in srgb, var(--card) 94%, var(--fg));
|
|
307
|
+
}
|
|
308
|
+
.tabulator-row.tabulator-selectable:hover {
|
|
309
|
+
background: color-mix(in srgb, var(--card) 85%, var(--accent));
|
|
310
|
+
}
|
|
311
|
+
.tabulator input,
|
|
312
|
+
.tabulator select {
|
|
313
|
+
color: var(--fg);
|
|
314
|
+
background: var(--bg);
|
|
315
|
+
border: 1px solid var(--line);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
@media (max-width: 520px) {
|
|
319
|
+
:root {
|
|
320
|
+
--gap: 10px;
|
|
321
|
+
font-size: 13px;
|
|
322
|
+
}
|
|
323
|
+
.kpi-value {
|
|
324
|
+
font-size: 1.3rem;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# Charts, tables and headline numbers
|
|
2
2
|
|
|
3
|
-
For a page built from `/skills/html-page/assets/dashboard.
|
|
4
|
-
rules (where it goes, the sandbox, adaptive layout,
|
|
3
|
+
For a page built from `/skills/html-page/assets/dashboard.tsx`. The core
|
|
4
|
+
rules (where it goes, the sandbox, adaptive layout, the build) are in
|
|
5
|
+
`SKILL.md`.
|
|
5
6
|
|
|
6
7
|
## Its data
|
|
7
8
|
|
|
8
|
-
- Default: `data.json` beside the page, loaded with
|
|
9
|
-
`
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- Live data instead:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
`
|
|
9
|
+
- Default: `data.json` beside the page, loaded with
|
|
10
|
+
`const report = useData<Report>('data.json')` - `report.data`,
|
|
11
|
+
`report.error`, `report.loading`, `report.reload`. Give `Report` the
|
|
12
|
+
data's real shape: the build then checks every field the page reads.
|
|
13
|
+
- Live data instead: `useCall(() => api<ReportApi>('api/report').get_data(), [])`,
|
|
14
|
+
a function of `api/report.api.py` that returns the same shape
|
|
15
|
+
(`python-functions.md`). Filters over many rows go to the function as
|
|
16
|
+
arguments (`useCall(() => report.get_data({ region }), [region])`) and are
|
|
17
|
+
applied in SQL, instead of loading every row.
|
|
16
18
|
- Ship the data the page needs, not the raw source: aggregate in Python, SQL
|
|
17
19
|
or DuckDB first. Keep it under ~5 MB; past ~20 000 rows send aggregates plus
|
|
18
20
|
the top rows, and say so on the page.
|
|
@@ -21,51 +23,101 @@ rules (where it goes, the sandbox, adaptive layout, checks) are in `SKILL.md`.
|
|
|
21
23
|
chart. Numbers as numbers, dates as ISO strings (`2026-03-31`), no `NaN`
|
|
22
24
|
(write `null`).
|
|
23
25
|
- Several pages can share one data file by a relative path that starts with
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
##
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
26
|
+
`..` (`useData('../shared/data.json')`).
|
|
27
|
+
|
|
28
|
+
## Charts: `Chart`
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
const byCategory = useMemo(() => {
|
|
32
|
+
const totals = groupSum(rows, 'category', 'amount').sort((a, b) => b[1] - a[1]);
|
|
33
|
+
return {
|
|
34
|
+
xAxis: { type: 'category', data: totals.map((d) => d[0]) },
|
|
35
|
+
yAxis: { type: 'value' },
|
|
36
|
+
series: [{ type: 'bar', data: totals.map((d) => d[1]) }],
|
|
37
|
+
};
|
|
38
|
+
}, [rows]);
|
|
39
|
+
|
|
40
|
+
<Card title="Amount by category, USD">
|
|
41
|
+
<Chart option={byCategory} onClick={(e) => setCategory(e.name)} />
|
|
42
|
+
</Card>;
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- `option` is a plain ECharts option object - every chart type ECharts has:
|
|
46
|
+
bar, line, area, pie, scatter, heatmap, treemap, sankey, funnel, gauge,
|
|
47
|
+
`map` with GeoJSON you write to the folder. Same library as the chat's
|
|
48
|
+
charts, so `a2ui-charts` advice on choosing a chart type applies.
|
|
49
|
+
- Build `option` in `useMemo` from the filtered rows: the chart redraws when
|
|
50
|
+
it changes, not on every render.
|
|
51
|
+
- Defaults: an axis tooltip (`confine: true`, stays inside a narrow panel)
|
|
52
|
+
and a tight grid. A top-level key of `option` replaces its default: a pie
|
|
53
|
+
wants `tooltip: { trigger: 'item' }`.
|
|
54
|
+
- `height` (default 320) is the chart's; its width is the card's. It follows
|
|
55
|
+
the panel being resized and switches light/dark by itself. Never size a
|
|
56
|
+
chart in `vh` or by the window.
|
|
57
|
+
- `onClick` gets the clicked bar, point or slice: `e.name` is its category -
|
|
58
|
+
set a filter from it.
|
|
59
|
+
- Long time series: `dataZoom: [{ type: 'inside' }]`, plus
|
|
60
|
+
`{ type: 'slider' }` on wide pages.
|
|
61
|
+
- Show `Empty` ("No data for these filters") instead of an empty chart.
|
|
62
|
+
|
|
63
|
+
## Tables: `Table`
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
const columns: Column[] = [
|
|
67
|
+
{ title: 'Date', field: 'date', headerFilter: 'input', minWidth: 100 },
|
|
68
|
+
{ title: 'Customer', field: 'customer', headerFilter: 'input' },
|
|
69
|
+
{
|
|
70
|
+
title: 'Amount',
|
|
71
|
+
field: 'amount',
|
|
72
|
+
hozAlign: 'right',
|
|
73
|
+
sorter: 'number',
|
|
74
|
+
formatter: (cell: { getValue(): number }) => fmt.money(cell.getValue()),
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
<Card title="Orders" wide>
|
|
79
|
+
<Table data={rows} columns={columns} onRowClick={(row) => setOpen(row.id)} />
|
|
80
|
+
</Card>;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
- Tabulator underneath: `columns` take its column options
|
|
84
|
+
(`sorter`, `hozAlign`, `headerFilter`, `formatter`, `minWidth`, `width`).
|
|
85
|
+
Define `columns` outside `App` or in `useMemo`.
|
|
86
|
+
- It sorts, filters per column, pages (25 rows) and collapses the columns
|
|
87
|
+
that do not fit a narrow panel - put the most important columns first.
|
|
88
|
+
- New `data` replaces the rows in place (page and sort are kept). `options`
|
|
89
|
+
passes more Tabulator options (`{ paginationSize: 50 }`,
|
|
90
|
+
`{ pagination: false }` for a short table).
|
|
91
|
+
- A short, fixed table (under ~15 rows, no sorting needed) can be a plain
|
|
92
|
+
`<table>` in a `Card` instead.
|
|
93
|
+
|
|
94
|
+
## Headline numbers and filters
|
|
95
|
+
|
|
96
|
+
| Need | Use |
|
|
97
|
+
| -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
98
|
+
| Headline numbers with change vs. a previous period | `<Kpis><Kpi label="Revenue" value={fmt.money(total)} delta={0.12} hint="vs. Q4" /></Kpis>` |
|
|
99
|
+
| A filter over the whole page | `<Select label="Region" all="All" value={region} options={uniq(rows, 'region')} onChange={setRegion} />` |
|
|
100
|
+
| A date or number range | `<Field label="From"><input type="date" value={from} onChange={(e) => setFrom(e.target.value)} /></Field>` |
|
|
101
|
+
| Number, money, percent and date formatting | `fmt.num(v, 2)`, `fmt.money(v, 'EUR')`, `fmt.pct(0.12)`, `fmt.date('2026-03-31')` - never by hand |
|
|
102
|
+
| Totals and groups of rows | `sum(rows, 'amount')`, `groupSum(rows, 'region', 'amount')`, `uniq(rows, 'region')` |
|
|
103
|
+
| Text sections, notes, method | JSX in a `Card`; `<details>` for anything secondary |
|
|
104
|
+
| Tabs between views | Buttons that set `useHashState('tab', 'summary')`, and render the active view |
|
|
105
|
+
|
|
106
|
+
Avoid: CSS frameworks and other npm packages, and other chart or table
|
|
107
|
+
libraries - the page has React, the kit, and ECharts and Tabulator from the
|
|
108
|
+
CDN, added by the build when `Chart` or `Table` is used. No Leaflet or any map
|
|
109
|
+
with tiles (blocked): use an ECharts `map` with GeoJSON you write to the
|
|
110
|
+
folder.
|
|
57
111
|
|
|
58
112
|
Every chart and table has a short heading saying what it shows, with units.
|
|
59
|
-
The page footer names the source and the date of the data.
|
|
113
|
+
The page footer (`Page footer=...`) names the source and the date of the data.
|
|
60
114
|
|
|
61
115
|
## Interactivity
|
|
62
116
|
|
|
63
|
-
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
- Filters over live data with many rows: pass them to the function
|
|
71
|
-
(`get_data({ region })`) and filter in SQL, instead of loading every row.
|
|
117
|
+
- Filters are `useState` in `App`; the filtered rows are a `useMemo` of the
|
|
118
|
+
data and the filters; KPIs, chart options and the table all come from
|
|
119
|
+
those rows. They then always agree.
|
|
120
|
+
- Clicking a bar or slice may set a filter (`onClick` above); show the
|
|
121
|
+
active filters in the `Toolbar` so they can be cleared.
|
|
122
|
+
- Keep the view a user would share (the tab, the open record) in
|
|
123
|
+
`useHashState`, so a reload or a link opens it again.
|