@uibot/blocks-studio 0.0.0-stage → 0.2.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/dist/blocks/charts.d.ts +9 -0
- package/dist/blocks/content.d.ts +40 -0
- package/dist/blocks/data-studio.d.ts +18 -0
- package/dist/blocks/grid.d.ts +7 -0
- package/dist/blocks/interactive.d.ts +27 -0
- package/dist/blocks/kanban.d.ts +9 -0
- package/dist/blocks/marketing.d.ts +36 -0
- package/dist/blocks/presentation.d.ts +37 -0
- package/dist/blocks/sections.d.ts +74 -0
- package/dist/catalog.d.ts +8 -0
- package/dist/catalog.js +2 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +3 -0
- package/dist/registry-source.d.ts +21 -0
- package/dist/registry-source.js +21 -0
- package/package.json +51 -4
- package/src/blocks/charts.tsx +140 -0
- package/src/blocks/content.tsx +637 -0
- package/src/blocks/data-studio.tsx +293 -0
- package/src/blocks/grid.tsx +62 -0
- package/src/blocks/interactive.tsx +374 -0
- package/src/blocks/kanban.tsx +150 -0
- package/src/blocks/marketing.tsx +531 -0
- package/src/blocks/presentation.tsx +435 -0
- package/src/blocks/sections.tsx +1069 -0
- package/README.md +0 -3
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import type { RendererComponent } from "@uibot/renderer-react";
|
|
2
|
+
|
|
3
|
+
function cn(...cls: (string | false | null | undefined)[]) {
|
|
4
|
+
return cls.filter(Boolean).join(" ");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// ── StatGrid ────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
// Static literal class maps — see grid.tsx for the Tailwind purge rationale.
|
|
10
|
+
const STAT_COLS: Record<string, string> = {
|
|
11
|
+
"1": "grid-cols-1",
|
|
12
|
+
"2": "grid-cols-1 sm:grid-cols-2",
|
|
13
|
+
"3": "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",
|
|
14
|
+
"4": "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4",
|
|
15
|
+
auto: "grid-cols-[repeat(auto-fit,minmax(180px,1fr))]",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
interface StatItem {
|
|
19
|
+
label?: string | undefined;
|
|
20
|
+
value?: unknown;
|
|
21
|
+
change?: string | undefined;
|
|
22
|
+
trend?: "up" | "down" | undefined;
|
|
23
|
+
description?: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function parseStatItems(raw: unknown): StatItem[] {
|
|
27
|
+
if (!Array.isArray(raw)) return [];
|
|
28
|
+
return raw
|
|
29
|
+
.filter((it): it is Record<string, unknown> => Boolean(it) && typeof it === "object")
|
|
30
|
+
.map((it) => ({
|
|
31
|
+
label: typeof it["label"] === "string" ? it["label"] : undefined,
|
|
32
|
+
value: it["value"],
|
|
33
|
+
change: typeof it["change"] === "string" ? it["change"] : undefined,
|
|
34
|
+
trend: it["trend"] === "up" || it["trend"] === "down" ? it["trend"] : undefined,
|
|
35
|
+
description: typeof it["description"] === "string" ? it["description"] : undefined,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Responsive grid of KPI cards. Prefers rendered `children` (e.g. existing Stat
|
|
41
|
+
* blocks); when there are none it falls back to inline rendering of `items`.
|
|
42
|
+
*/
|
|
43
|
+
export const StatGrid: RendererComponent = (props, ctx) => {
|
|
44
|
+
const cols = String(props["cols"] ?? "auto");
|
|
45
|
+
const colsCls = STAT_COLS[cols] ?? STAT_COLS["auto"];
|
|
46
|
+
const children = ctx.children as React.ReactNode[];
|
|
47
|
+
const items = parseStatItems(props["items"]);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div className={cn("uibot-stat-grid grid gap-4", colsCls)} data-uibot-type="StatGrid">
|
|
51
|
+
{children.length > 0
|
|
52
|
+
? children
|
|
53
|
+
: items.map((it, i) => (
|
|
54
|
+
<div key={i} className="bg-card text-card-foreground rounded-xl border p-5 shadow-sm">
|
|
55
|
+
<p className="text-sm font-medium text-muted-foreground">{it.label ?? "Stat"}</p>
|
|
56
|
+
<p className="mt-1.5 text-3xl font-bold tracking-tight">
|
|
57
|
+
{it.value !== undefined ? String(it.value) : "—"}
|
|
58
|
+
</p>
|
|
59
|
+
{(it.change || it.description) && (
|
|
60
|
+
<div className="mt-1.5 flex items-center gap-1.5">
|
|
61
|
+
{it.change && (
|
|
62
|
+
<span
|
|
63
|
+
className={cn(
|
|
64
|
+
"text-xs font-medium",
|
|
65
|
+
it.trend === "up"
|
|
66
|
+
? "text-green-600"
|
|
67
|
+
: it.trend === "down"
|
|
68
|
+
? "text-destructive"
|
|
69
|
+
: "text-muted-foreground",
|
|
70
|
+
)}
|
|
71
|
+
>
|
|
72
|
+
{it.change}
|
|
73
|
+
</span>
|
|
74
|
+
)}
|
|
75
|
+
{it.description && (
|
|
76
|
+
<span className="text-xs text-muted-foreground">{it.description}</span>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
)}
|
|
80
|
+
</div>
|
|
81
|
+
))}
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// ── DiagnosticsList ───────────────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
type Level = "info" | "warn" | "error";
|
|
89
|
+
|
|
90
|
+
const LEVEL_BAR: Record<Level, string> = {
|
|
91
|
+
info: "border-l-sky-500",
|
|
92
|
+
warn: "border-l-amber-500",
|
|
93
|
+
error: "border-l-destructive",
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const LEVEL_ICON: Record<Level, string> = {
|
|
97
|
+
info: "ℹ",
|
|
98
|
+
warn: "⚠",
|
|
99
|
+
error: "✕",
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const LEVEL_ICON_COLOR: Record<Level, string> = {
|
|
103
|
+
info: "text-sky-500",
|
|
104
|
+
warn: "text-amber-500",
|
|
105
|
+
error: "text-destructive",
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
interface Diagnostic {
|
|
109
|
+
level: Level;
|
|
110
|
+
title: string;
|
|
111
|
+
detail?: string | undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function parseDiagnostics(raw: unknown): Diagnostic[] {
|
|
115
|
+
if (!Array.isArray(raw)) return [];
|
|
116
|
+
return raw
|
|
117
|
+
.filter((it): it is Record<string, unknown> => Boolean(it) && typeof it === "object")
|
|
118
|
+
.map((it) => {
|
|
119
|
+
const level: Level = it["level"] === "warn" || it["level"] === "error" ? it["level"] : "info";
|
|
120
|
+
return {
|
|
121
|
+
level,
|
|
122
|
+
title: typeof it["title"] === "string" ? it["title"] : "",
|
|
123
|
+
detail: typeof it["detail"] === "string" ? it["detail"] : undefined,
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Levelled diagnostics list with a coloured left bar + glyph per severity. */
|
|
129
|
+
export const DiagnosticsList: RendererComponent = (props) => {
|
|
130
|
+
const items = parseDiagnostics(props["items"]);
|
|
131
|
+
return (
|
|
132
|
+
<ul className="uibot-diagnostics space-y-2" data-uibot-type="DiagnosticsList">
|
|
133
|
+
{items.map((d, i) => (
|
|
134
|
+
<li
|
|
135
|
+
key={i}
|
|
136
|
+
className={cn("flex gap-3 rounded-md border border-l-4 bg-card p-3", LEVEL_BAR[d.level])}
|
|
137
|
+
>
|
|
138
|
+
<span className={cn("text-sm leading-5", LEVEL_ICON_COLOR[d.level])} aria-hidden="true">
|
|
139
|
+
{LEVEL_ICON[d.level]}
|
|
140
|
+
</span>
|
|
141
|
+
<div className="min-w-0">
|
|
142
|
+
<p className="text-sm font-medium text-foreground">{d.title}</p>
|
|
143
|
+
{d.detail && <p className="text-xs text-muted-foreground">{d.detail}</p>}
|
|
144
|
+
</div>
|
|
145
|
+
</li>
|
|
146
|
+
))}
|
|
147
|
+
{items.length === 0 && (
|
|
148
|
+
<li className="rounded-md border border-dashed py-6 text-center text-sm text-muted-foreground">
|
|
149
|
+
No diagnostics
|
|
150
|
+
</li>
|
|
151
|
+
)}
|
|
152
|
+
</ul>
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// ── Matrix / Heatmap ──────────────────────────────────────────────────────────
|
|
157
|
+
|
|
158
|
+
function toStringArray(raw: unknown): string[] {
|
|
159
|
+
return Array.isArray(raw) ? raw.map((v) => String(v)) : [];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function toCellGrid(raw: unknown): number[][] {
|
|
163
|
+
if (!Array.isArray(raw)) return [];
|
|
164
|
+
return raw.map((row) =>
|
|
165
|
+
Array.isArray(row) ? row.map((v) => (typeof v === "number" ? v : Number(v) || 0)) : [],
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Two-dimensional intensity grid (heatmap). Cell intensities are 0..1 and map
|
|
171
|
+
* to a `color-mix` of the primary token via inline style (avoids dynamic class
|
|
172
|
+
* purge). Use `showValues` to print the numeric value inside each cell.
|
|
173
|
+
*/
|
|
174
|
+
export const Matrix: RendererComponent = (props) => {
|
|
175
|
+
const rows = toStringArray(props["rows"]);
|
|
176
|
+
const cols = toStringArray(props["cols"]);
|
|
177
|
+
const cells = toCellGrid(props["cells"]);
|
|
178
|
+
const caption = typeof props["caption"] === "string" ? props["caption"] : undefined;
|
|
179
|
+
const showValues = props["showValues"] === true;
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<div className="uibot-matrix w-full overflow-auto rounded-lg border" data-uibot-type="Matrix">
|
|
183
|
+
<table className="w-full border-collapse text-sm" aria-label={caption}>
|
|
184
|
+
{caption && <caption className="py-2 text-sm text-muted-foreground">{caption}</caption>}
|
|
185
|
+
<thead>
|
|
186
|
+
<tr>
|
|
187
|
+
<th className="bg-muted/50 px-3 py-2" />
|
|
188
|
+
{cols.map((col, i) => (
|
|
189
|
+
<th
|
|
190
|
+
key={i}
|
|
191
|
+
scope="col"
|
|
192
|
+
className="bg-muted/50 px-3 py-2 text-xs font-medium uppercase tracking-wide text-muted-foreground"
|
|
193
|
+
>
|
|
194
|
+
{col}
|
|
195
|
+
</th>
|
|
196
|
+
))}
|
|
197
|
+
</tr>
|
|
198
|
+
</thead>
|
|
199
|
+
<tbody>
|
|
200
|
+
{rows.map((rowLabel, r) => (
|
|
201
|
+
<tr key={r}>
|
|
202
|
+
<th
|
|
203
|
+
scope="row"
|
|
204
|
+
className="whitespace-nowrap bg-muted/30 px-3 py-2 text-left text-xs font-medium text-muted-foreground"
|
|
205
|
+
>
|
|
206
|
+
{rowLabel}
|
|
207
|
+
</th>
|
|
208
|
+
{cols.map((_, c) => {
|
|
209
|
+
const v = Math.max(0, Math.min(1, cells[r]?.[c] ?? 0));
|
|
210
|
+
return (
|
|
211
|
+
<td
|
|
212
|
+
key={c}
|
|
213
|
+
className="px-3 py-2 text-center text-xs tabular-nums"
|
|
214
|
+
title={String(v)}
|
|
215
|
+
style={{
|
|
216
|
+
backgroundColor: `color-mix(in srgb, var(--primary) ${(v * 100).toFixed(0)}%, transparent)`,
|
|
217
|
+
}}
|
|
218
|
+
>
|
|
219
|
+
{showValues ? v.toFixed(2) : ""}
|
|
220
|
+
</td>
|
|
221
|
+
);
|
|
222
|
+
})}
|
|
223
|
+
</tr>
|
|
224
|
+
))}
|
|
225
|
+
</tbody>
|
|
226
|
+
</table>
|
|
227
|
+
</div>
|
|
228
|
+
);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/** Alias of {@link Matrix} for specs that prefer the Heatmap name. */
|
|
232
|
+
export const Heatmap = Matrix;
|
|
233
|
+
|
|
234
|
+
// ── TimelineList ──────────────────────────────────────────────────────────────
|
|
235
|
+
|
|
236
|
+
type TimelineStatus = "ok" | "warn" | "error";
|
|
237
|
+
|
|
238
|
+
const TIMELINE_DOT: Record<TimelineStatus, string> = {
|
|
239
|
+
ok: "bg-primary",
|
|
240
|
+
warn: "bg-amber-500",
|
|
241
|
+
error: "bg-destructive",
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
interface TimelineItem {
|
|
245
|
+
time: string;
|
|
246
|
+
title: string;
|
|
247
|
+
desc?: string | undefined;
|
|
248
|
+
status?: TimelineStatus | undefined;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function parseTimelineItems(raw: unknown): TimelineItem[] {
|
|
252
|
+
if (!Array.isArray(raw)) return [];
|
|
253
|
+
return raw
|
|
254
|
+
.filter((it): it is Record<string, unknown> => Boolean(it) && typeof it === "object")
|
|
255
|
+
.map((it) => {
|
|
256
|
+
const status =
|
|
257
|
+
it["status"] === "warn" || it["status"] === "error" || it["status"] === "ok"
|
|
258
|
+
? (it["status"] as TimelineStatus)
|
|
259
|
+
: undefined;
|
|
260
|
+
return {
|
|
261
|
+
time: typeof it["time"] === "string" ? it["time"] : "",
|
|
262
|
+
title: typeof it["title"] === "string" ? it["title"] : "",
|
|
263
|
+
desc: typeof it["desc"] === "string" ? it["desc"] : undefined,
|
|
264
|
+
status,
|
|
265
|
+
};
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Vertical timeline with a left rail and a status dot per item. */
|
|
270
|
+
export const TimelineList: RendererComponent = (props) => {
|
|
271
|
+
const items = parseTimelineItems(props["items"]);
|
|
272
|
+
return (
|
|
273
|
+
<ol className="uibot-timeline relative space-y-4 border-l pl-5" data-uibot-type="TimelineList">
|
|
274
|
+
{items.map((it, i) => (
|
|
275
|
+
<li key={i} className="relative">
|
|
276
|
+
<span
|
|
277
|
+
className={cn(
|
|
278
|
+
"absolute -left-[23px] top-1 h-2.5 w-2.5 rounded-full ring-2 ring-background",
|
|
279
|
+
TIMELINE_DOT[it.status ?? "ok"],
|
|
280
|
+
)}
|
|
281
|
+
aria-hidden="true"
|
|
282
|
+
/>
|
|
283
|
+
<div className="flex items-baseline gap-2">
|
|
284
|
+
<p className="text-sm font-medium text-foreground">{it.title}</p>
|
|
285
|
+
{it.time && <span className="text-xs text-muted-foreground">{it.time}</span>}
|
|
286
|
+
</div>
|
|
287
|
+
{it.desc && <p className="mt-0.5 text-xs text-muted-foreground">{it.desc}</p>}
|
|
288
|
+
</li>
|
|
289
|
+
))}
|
|
290
|
+
{items.length === 0 && <li className="text-sm text-muted-foreground">No events</li>}
|
|
291
|
+
</ol>
|
|
292
|
+
);
|
|
293
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { RendererComponent } from "@uibot/renderer-react";
|
|
2
|
+
|
|
3
|
+
function cn(...cls: (string | false | null | undefined)[]) {
|
|
4
|
+
return cls.filter(Boolean).join(" ");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Static literal class maps so Tailwind's content scanner keeps these in the
|
|
8
|
+
// build. Never interpolate the column count into a template string — a dynamic
|
|
9
|
+
// `grid-cols-${n}` would be purged by the JIT compiler.
|
|
10
|
+
const COLS: Record<string, string> = {
|
|
11
|
+
"1": "grid-cols-1",
|
|
12
|
+
"2": "grid-cols-2",
|
|
13
|
+
"3": "grid-cols-3",
|
|
14
|
+
"4": "grid-cols-4",
|
|
15
|
+
"5": "grid-cols-5",
|
|
16
|
+
"6": "grid-cols-6",
|
|
17
|
+
auto: "grid-cols-[repeat(auto-fit,minmax(220px,1fr))]",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Responsive ladders — explicit literal classes, one per supported column count.
|
|
21
|
+
const RESP: Record<string, string> = {
|
|
22
|
+
"2": "grid-cols-1 sm:grid-cols-2",
|
|
23
|
+
"3": "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",
|
|
24
|
+
"4": "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4",
|
|
25
|
+
"5": "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5",
|
|
26
|
+
"6": "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const GAP: Record<string, string> = {
|
|
30
|
+
none: "gap-0",
|
|
31
|
+
xs: "gap-1",
|
|
32
|
+
sm: "gap-2",
|
|
33
|
+
md: "gap-4",
|
|
34
|
+
lg: "gap-6",
|
|
35
|
+
xl: "gap-8",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Declarative grid layout. Maps `cols`/`gap`/`responsive` props onto static
|
|
40
|
+
* Tailwind grid classes; children become grid cells directly. This is the
|
|
41
|
+
* primary way a spec expresses overall page layout in studio dogfooding.
|
|
42
|
+
*/
|
|
43
|
+
export const Grid: RendererComponent = (props, ctx) => {
|
|
44
|
+
const cols = String(props["cols"] ?? "auto");
|
|
45
|
+
const responsive = props["responsive"] === true;
|
|
46
|
+
const colsCls = (responsive && RESP[cols]) || COLS[cols] || COLS["auto"];
|
|
47
|
+
const gap = GAP[typeof props["gap"] === "string" ? props["gap"] : ""] ?? GAP["md"];
|
|
48
|
+
const align = typeof props["align"] === "string" ? `items-${props["align"]}` : "";
|
|
49
|
+
const justify = typeof props["justify"] === "string" ? `justify-${props["justify"]}` : "";
|
|
50
|
+
const userCls = typeof props["className"] === "string" ? props["className"] : "";
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
className={cn("uibot-grid grid", colsCls, gap, align, justify, userCls)}
|
|
55
|
+
data-uibot-type="Grid"
|
|
56
|
+
role="group"
|
|
57
|
+
aria-label="Grid layout"
|
|
58
|
+
>
|
|
59
|
+
{ctx.children as React.ReactNode[]}
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
};
|