@gemboss/ui 0.57.0 → 0.58.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/CHANGELOG.md +136 -0
- package/README.md +54 -0
- package/catalog/editor.html +1 -1
- package/catalog/index.html +3 -3
- package/gemboss-ui.css +2 -2
- package/package.json +17 -1
- package/parts/components.css +1 -1
- package/parts/core.css +1 -1
- package/parts/shell.css +1 -1
- package/src/assistant/host.tsx +21 -5
- package/src/assistant/sessions.tsx +36 -18
- package/src/collections.css +1 -1
- package/src/collections.tsx +5 -2
- package/src/dialog.tsx +4 -1
- package/src/editor/controls.tsx +18 -7
- package/src/editor/index.ts +1 -1
- package/src/editor/picker.tsx +9 -3
- package/src/editor/repeater.tsx +26 -14
- package/src/editor/swatch.ts +86 -0
- package/src/editor-color.css +1 -1
- package/src/editor-picker.css +1 -1
- package/src/editor-plain.js +1 -1
- package/src/editor-popover.css +1 -1
- package/src/index.ts +7 -0
- package/src/job-card.css +1 -0
- package/src/job-card.tsx +130 -0
- package/src/narration.css +1 -0
- package/src/save-bar.css +1 -0
- package/src/save-bar.tsx +50 -0
- package/src/skill-flow/canvas.tsx +574 -0
- package/src/skill-flow/index.ts +10 -0
- package/src/skill-flow/layout.ts +229 -0
- package/src/skill-flow/model.ts +256 -0
- package/src/skill-flow.css +1 -0
- package/src/skill-stats.css +1 -0
- package/src/skill-stats.tsx +213 -0
- package/src/skill-view.css +1 -0
- package/src/skill-view.tsx +257 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillStats — @gemboss/ui, unreleased (03/11/2026, the shared skills UI, plan "Clone cả store" S5 + S7). How one skill is used,
|
|
3
|
+
* drawn from ONE entry of the usage read both products answer the same way:
|
|
4
|
+
*
|
|
5
|
+
* GET …/skills/usage?days=30 → { days, generated_at, skills: [{ skill_id, pack, version, runs, runs_7d, stores?,
|
|
6
|
+
* by_engine: { claude_subscription, codex_subscription, byok, gemboss_key, unknown }, outcomes: { done, stopped, blocked, error },
|
|
7
|
+
* top_blocked_by: [{ guard, count }], avg_fidelity, published_rate, last_used_at, by_version: [{ version, runs, avg_fidelity,
|
|
8
|
+
* published_rate }] }] }
|
|
9
|
+
*
|
|
10
|
+
* What it draws, quietest first (Chris's rules: few words, one accent, status as small dots, empty things hidden):
|
|
11
|
+
* - the runs in the window, the last 7 days, and the stores (when the surface counts them);
|
|
12
|
+
* - who ran it: one split bar over the engines that ran it at least once, each named with its share. An engine at 0 is not drawn
|
|
13
|
+
* (content-radar only ever has Claude, and later Codex); a single engine is one full bar and "All on Claude", no legend;
|
|
14
|
+
* - how runs ended: a dot, a word and a count per outcome that happened;
|
|
15
|
+
* - the rule that blocked it most, the average fidelity and the published share, each only when known;
|
|
16
|
+
* - versions side by side when there are two or more.
|
|
17
|
+
* No runs (or no entry): one quiet line, never a zero dressed as data. The numbers are the surface's: it never fakes one.
|
|
18
|
+
* Server-renderable (no state, no effect). `skill-stats.css` is its own entry; the bar is the kit's ShareBar (minichart.css).
|
|
19
|
+
*/
|
|
20
|
+
import "./skill-stats.css";
|
|
21
|
+
import React from "react";
|
|
22
|
+
import { ShareBar, type ShareTone } from "./minichart";
|
|
23
|
+
|
|
24
|
+
const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean).join(" ");
|
|
25
|
+
|
|
26
|
+
export type SkillEngine = "claude_subscription" | "codex_subscription" | "byok" | "gemboss_key" | "unknown";
|
|
27
|
+
export type SkillOutcome = "done" | "stopped" | "blocked" | "error";
|
|
28
|
+
|
|
29
|
+
/** One skill's entry of the usage read. Every field may be missing on an older answer; the component draws what is there. */
|
|
30
|
+
export interface SkillUsage {
|
|
31
|
+
skill_id: string;
|
|
32
|
+
pack?: string;
|
|
33
|
+
version?: number | string | null;
|
|
34
|
+
runs: number;
|
|
35
|
+
runs_7d?: number;
|
|
36
|
+
stores?: number | null;
|
|
37
|
+
by_engine?: Partial<Record<SkillEngine, number>>;
|
|
38
|
+
outcomes?: Partial<Record<SkillOutcome, number>>;
|
|
39
|
+
top_blocked_by?: ReadonlyArray<{ guard: string; count: number }>;
|
|
40
|
+
avg_fidelity?: number | null;
|
|
41
|
+
published_rate?: number | null;
|
|
42
|
+
last_used_at?: string | null;
|
|
43
|
+
by_version?: ReadonlyArray<{ version: number | string; runs: number; avg_fidelity?: number | null; published_rate?: number | null }>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface SkillStatsLabels {
|
|
47
|
+
runs: (days: number) => string;
|
|
48
|
+
last7: string;
|
|
49
|
+
stores: string;
|
|
50
|
+
engines: string;
|
|
51
|
+
engine: Record<SkillEngine, string>;
|
|
52
|
+
allOn: (engine: string) => string;
|
|
53
|
+
outcomes: string;
|
|
54
|
+
outcome: Record<SkillOutcome, string>;
|
|
55
|
+
topBlock: string;
|
|
56
|
+
fidelity: string;
|
|
57
|
+
published: string;
|
|
58
|
+
versions: string;
|
|
59
|
+
versionRow: string;
|
|
60
|
+
lastUsed: (when: string) => string;
|
|
61
|
+
empty: string;
|
|
62
|
+
emptyLine: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const SKILL_STATS_LABELS: SkillStatsLabels = {
|
|
66
|
+
runs: (days) => `Runs · ${days} days`,
|
|
67
|
+
last7: "Last 7 days",
|
|
68
|
+
stores: "Stores",
|
|
69
|
+
engines: "Who ran it",
|
|
70
|
+
engine: { claude_subscription: "Claude", codex_subscription: "Codex", byok: "Own key", gemboss_key: "GemBoss key", unknown: "Unknown" },
|
|
71
|
+
allOn: (engine) => `All on ${engine}`,
|
|
72
|
+
outcomes: "How runs ended",
|
|
73
|
+
outcome: { done: "Done", stopped: "Stopped", blocked: "Blocked", error: "Error" },
|
|
74
|
+
topBlock: "Blocked most by",
|
|
75
|
+
fidelity: "Avg fidelity",
|
|
76
|
+
published: "Published",
|
|
77
|
+
versions: "Versions",
|
|
78
|
+
versionRow: "Version",
|
|
79
|
+
lastUsed: (when) => `Last used ${when}`,
|
|
80
|
+
empty: "No runs yet",
|
|
81
|
+
emptyLine: "Numbers show here once this skill has run.",
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** The engines in a FIXED order with a fixed tone each: a colour follows its engine, never its rank (a filter that drops one
|
|
85
|
+
* engine does not repaint the others). Unknown is the neutral grey, not a hue. */
|
|
86
|
+
export const SKILL_ENGINES: ReadonlyArray<{ key: SkillEngine; tone: ShareTone }> = [
|
|
87
|
+
{ key: "claude_subscription", tone: "series-1" },
|
|
88
|
+
{ key: "codex_subscription", tone: "series-2" },
|
|
89
|
+
{ key: "byok", tone: "series-3" },
|
|
90
|
+
{ key: "gemboss_key", tone: "series-4" },
|
|
91
|
+
{ key: "unknown", tone: "neutral" },
|
|
92
|
+
];
|
|
93
|
+
const OUTCOMES: readonly SkillOutcome[] = ["done", "stopped", "blocked", "error"];
|
|
94
|
+
const OUTCOME_CLASS: Record<SkillOutcome, string> = {
|
|
95
|
+
done: "ui-skillstats__out ui-skillstats__out--done",
|
|
96
|
+
stopped: "ui-skillstats__out ui-skillstats__out--stopped",
|
|
97
|
+
blocked: "ui-skillstats__out ui-skillstats__out--blocked",
|
|
98
|
+
error: "ui-skillstats__out ui-skillstats__out--error",
|
|
99
|
+
};
|
|
100
|
+
const TONE_CLASS: Record<string, string> = {
|
|
101
|
+
"series-1": "ui-skillstats__key ui-skillstats__key--s1", "series-2": "ui-skillstats__key ui-skillstats__key--s2",
|
|
102
|
+
"series-3": "ui-skillstats__key ui-skillstats__key--s3", "series-4": "ui-skillstats__key ui-skillstats__key--s4",
|
|
103
|
+
neutral: "ui-skillstats__key ui-skillstats__key--neutral",
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const n0 = (v: unknown) => (typeof v === "number" && Number.isFinite(v) && v > 0 ? v : 0);
|
|
107
|
+
/** A share 0…1 (or 0…100) printed as a whole percent; null when unknown. */
|
|
108
|
+
export const pct = (v: number | null | undefined): string | null => {
|
|
109
|
+
if (typeof v !== "number" || !Number.isFinite(v)) return null;
|
|
110
|
+
const p = v <= 1 ? v * 100 : v;
|
|
111
|
+
return `${Math.round(Math.max(0, Math.min(100, p)))}%`;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** The engines that ran it at least once, in the fixed order, each with its share of the runs they add up to. */
|
|
115
|
+
export function engineParts(by: SkillUsage["by_engine"]): Array<{ key: SkillEngine; tone: ShareTone; runs: number; share: number }> {
|
|
116
|
+
const parts = SKILL_ENGINES.map((e) => ({ ...e, runs: n0(by?.[e.key]) })).filter((e) => e.runs > 0);
|
|
117
|
+
const total = parts.reduce((a, p) => a + p.runs, 0);
|
|
118
|
+
return parts.map((p) => ({ ...p, share: total ? p.runs / total : 0 }));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface SkillStatsProps {
|
|
122
|
+
/** One skill's entry, or null / undefined when the read has nothing for it. */
|
|
123
|
+
usage?: SkillUsage | null;
|
|
124
|
+
/** The window the read covered (its `days`). */
|
|
125
|
+
days?: number;
|
|
126
|
+
/** The read's last-used date, already worded by the surface ("2 days ago"). */
|
|
127
|
+
lastUsed?: string | null;
|
|
128
|
+
labels?: Partial<SkillStatsLabels>;
|
|
129
|
+
className?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function SkillStats({ usage, days = 30, lastUsed, labels, className }: SkillStatsProps) {
|
|
133
|
+
const L = { ...SKILL_STATS_LABELS, ...labels };
|
|
134
|
+
const runs = n0(usage?.runs);
|
|
135
|
+
if (!usage || !runs) {
|
|
136
|
+
return (
|
|
137
|
+
<div className={cx("ui-skillstats ui-skillstats--empty", className)}>
|
|
138
|
+
<p className="ui-skillstats__empty"><b>{L.empty}</b><span>{L.emptyLine}</span></p>
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
const engines = engineParts(usage.by_engine);
|
|
143
|
+
const outs = OUTCOMES.map((k) => ({ k, n: n0(usage.outcomes?.[k]) })).filter((o) => o.n > 0);
|
|
144
|
+
const top = (usage.top_blocked_by ?? []).filter((b) => b && b.guard && n0(b.count) > 0).sort((a, b) => b.count - a.count)[0];
|
|
145
|
+
const fidelity = pct(usage.avg_fidelity);
|
|
146
|
+
const published = pct(usage.published_rate);
|
|
147
|
+
const versions = (usage.by_version ?? []).filter((v) => v && v.version !== undefined && v.version !== null);
|
|
148
|
+
const stores = typeof usage.stores === "number" && usage.stores >= 0 ? usage.stores : null;
|
|
149
|
+
const nums: Array<[string, string]> = [
|
|
150
|
+
[L.runs(days), String(runs)],
|
|
151
|
+
...(typeof usage.runs_7d === "number" ? [[L.last7, String(n0(usage.runs_7d))] as [string, string]] : []),
|
|
152
|
+
...(stores !== null ? [[L.stores, String(stores)] as [string, string]] : []),
|
|
153
|
+
...(fidelity ? [[L.fidelity, fidelity] as [string, string]] : []),
|
|
154
|
+
...(published ? [[L.published, published] as [string, string]] : []),
|
|
155
|
+
];
|
|
156
|
+
return (
|
|
157
|
+
<div className={cx("ui-skillstats", className)}>
|
|
158
|
+
<dl className="ui-skillstats__nums">
|
|
159
|
+
{nums.map(([k, v]) => <div key={k} className="ui-skillstats__num"><dt>{k}</dt><dd>{v}</dd></div>)}
|
|
160
|
+
</dl>
|
|
161
|
+
{lastUsed ? <p className="ui-skillstats__last">{L.lastUsed(lastUsed)}</p> : null}
|
|
162
|
+
|
|
163
|
+
{engines.length ? (
|
|
164
|
+
<section className="ui-skillstats__sec" aria-label={L.engines}>
|
|
165
|
+
<h4 className="ui-skillstats__h">{L.engines}</h4>
|
|
166
|
+
<ShareBar parts={engines.map((e) => ({ key: e.key, label: L.engine[e.key], value: e.runs, tone: e.tone }))} label={L.engines} />
|
|
167
|
+
{engines.length === 1 ? (
|
|
168
|
+
<p className="ui-skillstats__one">{L.allOn(L.engine[engines[0]!.key])}</p>
|
|
169
|
+
) : (
|
|
170
|
+
<ul className="ui-skillstats__legend">
|
|
171
|
+
{engines.map((e) => (
|
|
172
|
+
<li key={e.key} className={TONE_CLASS[e.tone]}>
|
|
173
|
+
<i aria-hidden="true" />{L.engine[e.key]}<span>{e.runs} · {pct(e.share)}</span>
|
|
174
|
+
</li>
|
|
175
|
+
))}
|
|
176
|
+
</ul>
|
|
177
|
+
)}
|
|
178
|
+
</section>
|
|
179
|
+
) : null}
|
|
180
|
+
|
|
181
|
+
{outs.length ? (
|
|
182
|
+
<section className="ui-skillstats__sec" aria-label={L.outcomes}>
|
|
183
|
+
<h4 className="ui-skillstats__h">{L.outcomes}</h4>
|
|
184
|
+
<ul className="ui-skillstats__outs">
|
|
185
|
+
{outs.map((o) => <li key={o.k} className={OUTCOME_CLASS[o.k]}><i aria-hidden="true" />{L.outcome[o.k]}<span>{o.n}</span></li>)}
|
|
186
|
+
</ul>
|
|
187
|
+
{top ? <p className="ui-skillstats__top">{L.topBlock} <code>{top.guard}</code> <span>· {top.count}</span></p> : null}
|
|
188
|
+
</section>
|
|
189
|
+
) : null}
|
|
190
|
+
|
|
191
|
+
{versions.length > 1 ? (
|
|
192
|
+
<section className="ui-skillstats__sec" aria-label={L.versions}>
|
|
193
|
+
<h4 className="ui-skillstats__h">{L.versions}</h4>
|
|
194
|
+
<div className="ui-skillstats__vwrap">
|
|
195
|
+
<table className="ui-skillstats__versions">
|
|
196
|
+
<thead><tr><th scope="col">{L.versionRow}</th><th scope="col">{L.runs(days)}</th><th scope="col">{L.fidelity}</th><th scope="col">{L.published}</th></tr></thead>
|
|
197
|
+
<tbody>
|
|
198
|
+
{versions.map((v) => (
|
|
199
|
+
<tr key={String(v.version)}>
|
|
200
|
+
<th scope="row">v{v.version}</th>
|
|
201
|
+
<td>{n0(v.runs)}</td>
|
|
202
|
+
<td>{pct(v.avg_fidelity) ?? "–"}</td>
|
|
203
|
+
<td>{pct(v.published_rate) ?? "–"}</td>
|
|
204
|
+
</tr>
|
|
205
|
+
))}
|
|
206
|
+
</tbody>
|
|
207
|
+
</table>
|
|
208
|
+
</div>
|
|
209
|
+
</section>
|
|
210
|
+
) : null}
|
|
211
|
+
</div>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ui-skillview{--skf-sticky: 56px;display:flex;flex-direction:column;gap:16px;color:var(--gemboss-text, #1b1c1e)}.ui-skillview>*{flex:none}dialog.ui-modal.ui-reader.ui-skillview-pop .ui-reader__scroll.ui-skillview{padding-top:16px}.ui-skillview-pop .ui-modal__head .ui-skillview__back{flex:none;display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 10px 0 6px;margin-right:4px;border:0;border-radius:8px;background:transparent;color:var(--gemboss-text, #1b1c1e);font:inherit;font-size:13px;font-weight:550;cursor:pointer;white-space:nowrap}.ui-skillview-pop .ui-modal__head .ui-skillview__back:hover,.ui-skillview-pop .ui-modal__head .ui-skillview__back:active{background:var(--gemboss-hover, #eceef2);color:var(--gemboss-text, #1b1c1e)}.ui-skillview-pop .ui-modal__head .ui-skillview__back:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:2px}.ui-skillview__hero{display:flex;align-items:flex-start;gap:14px;max-width:72ch}.ui-skillview__icon{flex:none;display:grid;place-items:center;width:44px;height:44px;border-radius:12px;background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-skillview__icon svg{width:22px;height:22px}.ui-skillview__lead{display:grid;gap:8px;min-width:0}.ui-skillview__intro{margin:0;font-size:14px;line-height:21px}.ui-skillview__facts{display:flex;flex-wrap:wrap;gap:6px;margin:0;padding:0;list-style:none}.ui-skillview__fact{padding:0 8px;border:1px solid var(--gemboss-divider, #e5e7ea);border-radius:999px;font-size:12px;line-height:20px;color:var(--gemboss-text-muted, #686b71);font-variant-numeric:tabular-nums}.ui-skillview__why{font-size:13px;color:var(--gemboss-text-muted, #686b71)}.ui-skillview__why>summary{width:fit-content;cursor:pointer;font-weight:550;color:var(--gemboss-text, #1b1c1e);list-style-position:inside}.ui-skillview__why>summary:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:2px;border-radius:4px}.ui-skillview__whytext{margin-top:6px;line-height:20px}.ui-skillview__error{margin:0;padding:8px 12px;border-radius:8px;font-size:13px;background:var(--gemboss-danger-soft, #fff0e9);color:var(--gemboss-danger-strong, #b42318)}.ui-skillview__loading{margin:0;font-size:13px;color:var(--gemboss-text-muted, #686b71)}.ui-skillview .ui-skillview__tabs{position:sticky;top:-16px;z-index:8;margin:0 -32px;padding:0 32px;background:var(--gemboss-surface, #ffffff)}.ui-skillview__count{min-width:18px;padding:0 5px;border-radius:999px;font-size:11px;line-height:16px;text-align:center;background:var(--gemboss-primary-soft, #f2f3f5);color:var(--gemboss-text-muted, #686b71);font-variant-numeric:tabular-nums}@media (max-width: 47.9975em){.ui-skillview .ui-skillview__tabs{margin:0 -16px;padding:0 16px}}.ui-skillview__panel{display:grid;gap:20px;min-width:0}.ui-skillview__panel:focus{outline:none}.ui-skillview__sec{display:grid;gap:8px;min-width:0}.ui-skillview__h{margin:0;font-size:12px;line-height:16px;font-weight:650;letter-spacing:.06em;text-transform:uppercase;color:var(--gemboss-text-muted, #686b71)}.ui-skillview__note{margin:0;font-size:13px;line-height:19px;color:var(--gemboss-text-muted, #686b71);max-width:72ch}.ui-skillview__rules{display:grid;margin:0;padding:0;list-style:none;border:1px solid var(--gemboss-divider, #e5e7ea);border-radius:12px}.ui-skillview__rule{display:flex;align-items:flex-start;gap:12px;padding:10px 14px;min-width:0}.ui-skillview__rule+.ui-skillview__rule{border-top:1px solid var(--gemboss-divider, #e5e7ea)}.ui-skillview__code{flex:none;min-width:28px;padding:0 6px;border-radius:6px;font:600 11px/20px ui-monospace,SFMono-Regular,Menlo,monospace;text-align:center;background:var(--gemboss-primary-soft, #f2f3f5);color:var(--gemboss-text, #1b1c1e)}.ui-skillview__rulebody{display:grid;gap:2px;flex:1 1 auto;min-width:0}.ui-skillview__ruletitle{font-size:13px;line-height:20px;font-weight:600}.ui-skillview__ruleline{font-size:12px;line-height:18px;color:var(--gemboss-text-muted, #686b71)}.ui-skillview__hold{flex:none;display:inline-flex;align-items:center;gap:6px;font-size:12px;line-height:20px;color:var(--gemboss-text-muted, #686b71);white-space:nowrap}.ui-skillview__hold>i{width:7px;height:7px;box-sizing:border-box;border-radius:50%;border:1.5px solid currentColor}.ui-skillview__hold--checked>i{border-color:var(--gemboss-success, #007f5f);background:var(--gemboss-success, #007f5f)}.ui-skillview__hold--seeded>i{border-color:var(--gemboss-accent, #5661f5);background:var(--gemboss-accent, #5661f5)}.ui-skillview__hold--declared>i{border-color:var(--gemboss-chip-line, #cfd6ce)}@media (max-width: 47.9975em){.ui-skillview__rule{flex-wrap:wrap;row-gap:4px;padding:10px 12px}.ui-skillview__hold{flex-basis:100%;padding-left:40px}}.ui-skillgroup{display:grid;gap:12px;min-width:0}.ui-skillgroup+.ui-skillgroup{margin-top:28px}.ui-skillgroup__head{display:grid;gap:2px}.ui-skillgroup__title{margin:0;font-size:14px;line-height:20px;font-weight:650;color:var(--gemboss-text, #1b1c1e)}.ui-skillgroup__line{margin:0;font-size:13px;line-height:19px;color:var(--gemboss-text-muted, #686b71)}.ui-skillgroup__grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,220px),1fr));gap:12px}.ui-skillcard{display:flex;flex-direction:column;align-items:stretch;gap:6px;min-width:0;box-sizing:border-box;margin:0;padding:14px;border:1px solid var(--gemboss-divider, #e5e7ea);border-radius:12px;background:var(--gemboss-surface, #ffffff);color:var(--gemboss-text, #1b1c1e);font:inherit;text-align:left;text-decoration:none;cursor:pointer;transition:border-color .12s ease,box-shadow .12s ease}.ui-skillcard:hover,.ui-skillcard:active{border-color:var(--gemboss-chip-line, #cfd6ce);background:var(--gemboss-surface, #ffffff);color:var(--gemboss-text, #1b1c1e);box-shadow:var(--gemboss-shadow-resting, 0 1px 2px rgba(31, 30, 29, .04), 0 2px 6px rgba(31, 30, 29, .06))}.ui-skillcard:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:2px}@media (prefers-reduced-motion: reduce){.ui-skillcard{transition:none}}.ui-skillcard__top{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;margin-bottom:4px}.ui-skillcard__icon{display:grid;place-items:center;width:32px;height:32px;border-radius:8px;background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-skillcard__icon svg{width:18px;height:18px}.ui-skillcard__badge{padding:0 8px;border-radius:999px;font-size:11px;line-height:20px;font-weight:600;background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent-strong, #3a44de)}.ui-skillcard__title{font-size:14px;line-height:19px;font-weight:600}.ui-skillcard__line{font-size:12px;line-height:18px;color:var(--gemboss-text-muted, #686b71)}.ui-skillcard__foot{display:flex;flex-wrap:wrap;align-items:baseline;justify-content:space-between;gap:2px 8px;margin-top:auto;padding-top:6px}.ui-skillcard__meta{font:500 11px/16px ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--gemboss-text-muted, #686b71)}.ui-skillcard__stat{font-size:12px;line-height:16px;color:var(--gemboss-text-muted, #686b71);font-variant-numeric:tabular-nums}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SkillView — @gemboss/ui, unreleased (03/11/2026, the shared skills UI, plan "Clone cả store" S5). One skill, read in a popup over
|
|
5
|
+
* the list it came from: content-radar's skill popup (SkillDialog + SkillView, 24–26/10/2026) as a kit shell, so GemBoss's
|
|
6
|
+
* Assistant › Skills and content-radar's /v2/skills draw the same thing.
|
|
7
|
+
*
|
|
8
|
+
* It is the kit's ReaderDialog with a head (an icon, one short line, a few facts, the long reason behind "Why?") and a row of tabs.
|
|
9
|
+
* The tabs are SLOTS: the surface fills each one (a Flow canvas, its rules, its history, its stats) and a tab whose content is
|
|
10
|
+
* null is not drawn, so a skill with no flow simply has no Flow tab. Props only: no fetching, no routing; the surface keeps the open
|
|
11
|
+
* tab if it wants it in its URL (`tab` + `onTab`), or lets the popup keep it (`defaultTab`).
|
|
12
|
+
*
|
|
13
|
+
* The tab bar is the kit's `ui-tabs` (button tabs, arrow keys move between them) and stays at the top while the body scrolls; a
|
|
14
|
+
* Flow canvas inside reads `--skf-sticky` so its zoom bar sticks under the tabs, not under them. `back` puts "← <label>" first in
|
|
15
|
+
* the head (Chris's popups: the way back top left); ✕ and Escape still close it. skill-view.css is its own entry.
|
|
16
|
+
*/
|
|
17
|
+
import "./skill-view.css";
|
|
18
|
+
import React, { useId, useRef, useState, type ReactNode } from "react";
|
|
19
|
+
import { ReaderDialog } from "./reader-dialog";
|
|
20
|
+
|
|
21
|
+
const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean).join(" ");
|
|
22
|
+
|
|
23
|
+
/** The tabs in the order both products show them. A surface may add its own; these keys keep their place. */
|
|
24
|
+
export const SKILL_VIEW_TABS = [
|
|
25
|
+
{ key: "overview", label: "Overview" },
|
|
26
|
+
{ key: "flow", label: "Flow" },
|
|
27
|
+
{ key: "rules", label: "Rules" },
|
|
28
|
+
{ key: "history", label: "History" },
|
|
29
|
+
{ key: "lessons", label: "Lessons" },
|
|
30
|
+
{ key: "stats", label: "Stats" },
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
export interface SkillViewTab {
|
|
34
|
+
key: string;
|
|
35
|
+
label: string;
|
|
36
|
+
/** A small number after the label (7 rules). Hidden when absent or 0. */
|
|
37
|
+
count?: number;
|
|
38
|
+
/** The tab's body. null / undefined: the tab is not drawn. */
|
|
39
|
+
content?: ReactNode;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SkillViewProps {
|
|
43
|
+
open: boolean;
|
|
44
|
+
onClose: () => void;
|
|
45
|
+
title: ReactNode;
|
|
46
|
+
/** One line under the title: "advertorial · v2 · updated 28 Oct". */
|
|
47
|
+
subtitle?: ReactNode;
|
|
48
|
+
/** Beside the title, before ✕: "Use this skill". */
|
|
49
|
+
actions?: ReactNode;
|
|
50
|
+
/** "← Skills" first in the head. `onClick` defaults to closing. */
|
|
51
|
+
back?: { label: string; onClick?: () => void };
|
|
52
|
+
/** The skill's picture: a kit icon on a tile. */
|
|
53
|
+
icon?: ReactNode;
|
|
54
|
+
/** What it does, one short line. */
|
|
55
|
+
intro?: ReactNode;
|
|
56
|
+
/** A few facts as quiet chips (a version, a count of rules). Empty ones are dropped. */
|
|
57
|
+
facts?: readonly ReactNode[];
|
|
58
|
+
/** The longer reason, folded behind "Why?". */
|
|
59
|
+
why?: ReactNode;
|
|
60
|
+
whyLabel?: string;
|
|
61
|
+
tabs: readonly SkillViewTab[];
|
|
62
|
+
/** Controlled tab; with `onTab`. */
|
|
63
|
+
tab?: string;
|
|
64
|
+
onTab?: (key: string) => void;
|
|
65
|
+
defaultTab?: string;
|
|
66
|
+
/** While the skill's details load: a quiet line instead of the tabs' bodies. */
|
|
67
|
+
loading?: boolean;
|
|
68
|
+
loadingLabel?: string;
|
|
69
|
+
/** A read that failed, said in the body. */
|
|
70
|
+
error?: ReactNode;
|
|
71
|
+
className?: string;
|
|
72
|
+
closeLabel?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function SkillView({
|
|
76
|
+
open, onClose, title, subtitle, actions, back, icon, intro, facts = [], why, whyLabel = "Why?", tabs, tab, onTab, defaultTab,
|
|
77
|
+
loading = false, loadingLabel = "Loading…", error, className, closeLabel,
|
|
78
|
+
}: SkillViewProps) {
|
|
79
|
+
const shown = tabs.filter((t) => t.content !== null && t.content !== undefined && t.content !== false);
|
|
80
|
+
const [own, setOwn] = useState<string | undefined>(defaultTab);
|
|
81
|
+
const want = tab ?? own;
|
|
82
|
+
const cur = shown.find((t) => t.key === want) ?? shown[0];
|
|
83
|
+
const pick = (key: string) => { if (tab === undefined) setOwn(key); onTab?.(key); };
|
|
84
|
+
const base = useId();
|
|
85
|
+
const tabsRef = useRef<HTMLDivElement>(null);
|
|
86
|
+
const chips = facts.filter((f) => f !== null && f !== undefined && f !== false && f !== "");
|
|
87
|
+
// Arrow keys move along the tabs and pick (the kit's tabs are a tablist; Home / End go to the ends).
|
|
88
|
+
const onKeyDown = (e: React.KeyboardEvent) => {
|
|
89
|
+
const i = shown.findIndex((t) => t.key === cur?.key);
|
|
90
|
+
const to = e.key === "ArrowRight" ? i + 1 : e.key === "ArrowLeft" ? i - 1 : e.key === "Home" ? 0 : e.key === "End" ? shown.length - 1 : null;
|
|
91
|
+
if (to === null || !shown.length) return;
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
const next = shown[(to + shown.length) % shown.length]!;
|
|
94
|
+
pick(next.key);
|
|
95
|
+
tabsRef.current?.querySelector<HTMLButtonElement>(`[data-tab="${next.key}"]`)?.focus();
|
|
96
|
+
};
|
|
97
|
+
return (
|
|
98
|
+
// The popup itself takes the focus on opening (as Sheet does), not "← Back": a ring on the way out is the first thing a mouse
|
|
99
|
+
// reader saw, and the arrow keys and Page Down read the skill from there.
|
|
100
|
+
<ReaderDialog open={open} onClose={onClose} title={title} subtitle={subtitle} actions={actions} closeLabel={closeLabel} focusPanel
|
|
101
|
+
className={cx("ui-skillview-pop", className)}
|
|
102
|
+
lead={back ? (
|
|
103
|
+
<button type="button" className="ui-skillview__back" onClick={back.onClick ?? onClose}>
|
|
104
|
+
<span aria-hidden="true">←</span> {back.label}
|
|
105
|
+
</button>
|
|
106
|
+
) : undefined}>
|
|
107
|
+
<div className="ui-reader__scroll ui-skillview" tabIndex={-1}>
|
|
108
|
+
{icon || intro || chips.length || why ? (
|
|
109
|
+
<header className="ui-skillview__hero">
|
|
110
|
+
{icon ? <span className="ui-skillview__icon" aria-hidden="true">{icon}</span> : null}
|
|
111
|
+
<div className="ui-skillview__lead">
|
|
112
|
+
{intro ? <p className="ui-skillview__intro">{intro}</p> : null}
|
|
113
|
+
{chips.length ? <ul className="ui-skillview__facts">{chips.map((f, i) => <li key={i} className="ui-skillview__fact">{f}</li>)}</ul> : null}
|
|
114
|
+
{why ? (
|
|
115
|
+
<details className="ui-skillview__why">
|
|
116
|
+
<summary>{whyLabel}</summary>
|
|
117
|
+
<div className="ui-skillview__whytext">{why}</div>
|
|
118
|
+
</details>
|
|
119
|
+
) : null}
|
|
120
|
+
</div>
|
|
121
|
+
</header>
|
|
122
|
+
) : null}
|
|
123
|
+
{error ? <p className="ui-skillview__error" role="alert">{error}</p> : null}
|
|
124
|
+
{shown.length > 1 ? (
|
|
125
|
+
<div className="ui-tabs ui-skillview__tabs" role="tablist" aria-label="Skill sections" ref={tabsRef} onKeyDown={onKeyDown}>
|
|
126
|
+
{shown.map((t) => (
|
|
127
|
+
<button key={t.key} type="button" role="tab" id={`${base}-t-${t.key}`} data-tab={t.key} aria-selected={cur?.key === t.key}
|
|
128
|
+
aria-controls={`${base}-p-${t.key}`} tabIndex={cur?.key === t.key ? 0 : -1} onClick={() => pick(t.key)}>
|
|
129
|
+
{t.label}{t.count ? <span className="ui-skillview__count">{t.count}</span> : null}
|
|
130
|
+
</button>
|
|
131
|
+
))}
|
|
132
|
+
</div>
|
|
133
|
+
) : null}
|
|
134
|
+
{loading ? <p className="ui-skillview__loading">{loadingLabel}</p> : cur ? (
|
|
135
|
+
<div className="ui-skillview__panel" role={shown.length > 1 ? "tabpanel" : undefined} id={`${base}-p-${cur.key}`}
|
|
136
|
+
aria-labelledby={shown.length > 1 ? `${base}-t-${cur.key}` : undefined} data-tab={cur.key}>
|
|
137
|
+
{cur.content}
|
|
138
|
+
</div>
|
|
139
|
+
) : null}
|
|
140
|
+
</div>
|
|
141
|
+
</ReaderDialog>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** How a rule is held, as the Rules tab says it: by the system before work starts, at the finish, at publish, measured, put on
|
|
146
|
+
* the page from the start, or only declared (the skill asks, nothing checks). The surface writes the words. */
|
|
147
|
+
export type SkillRuleHold = "door" | "gate" | "finish" | "publish" | "measured" | "seeded" | "declared";
|
|
148
|
+
export interface SkillRule {
|
|
149
|
+
key: string;
|
|
150
|
+
/** "P1", "C5": the rule's code in its pack. */
|
|
151
|
+
code?: string;
|
|
152
|
+
title: ReactNode;
|
|
153
|
+
/** One short line. Longer words go behind the surface's own "Why?". */
|
|
154
|
+
line?: ReactNode;
|
|
155
|
+
hold: SkillRuleHold;
|
|
156
|
+
/** The chip's words for `hold` ("Checked at publish"). */
|
|
157
|
+
holdLabel: ReactNode;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const HOLD_CLASS: Record<SkillRuleHold, string> = {
|
|
161
|
+
door: "ui-skillview__hold ui-skillview__hold--checked", gate: "ui-skillview__hold ui-skillview__hold--checked",
|
|
162
|
+
finish: "ui-skillview__hold ui-skillview__hold--checked", publish: "ui-skillview__hold ui-skillview__hold--checked",
|
|
163
|
+
measured: "ui-skillview__hold ui-skillview__hold--checked", seeded: "ui-skillview__hold ui-skillview__hold--seeded",
|
|
164
|
+
declared: "ui-skillview__hold ui-skillview__hold--declared",
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/** A skill's rules, one row each: the code, the rule, one line, and how it is held as a chip (a filled dot when the system checks
|
|
168
|
+
* it, an empty ring when it is only declared). */
|
|
169
|
+
export function SkillRuleList({ rules, className }: { rules: readonly SkillRule[]; className?: string }) {
|
|
170
|
+
if (!rules.length) return null;
|
|
171
|
+
return (
|
|
172
|
+
<ul className={cx("ui-skillview__rules", className)}>
|
|
173
|
+
{rules.map((r) => (
|
|
174
|
+
<li key={r.key} className="ui-skillview__rule">
|
|
175
|
+
{r.code ? <code className="ui-skillview__code">{r.code}</code> : null}
|
|
176
|
+
<span className="ui-skillview__rulebody">
|
|
177
|
+
<b className="ui-skillview__ruletitle">{r.title}</b>
|
|
178
|
+
{r.line ? <span className="ui-skillview__ruleline">{r.line}</span> : null}
|
|
179
|
+
</span>
|
|
180
|
+
<span className={HOLD_CLASS[r.hold] ?? HOLD_CLASS.declared}><i aria-hidden="true" />{r.holdLabel}</span>
|
|
181
|
+
</li>
|
|
182
|
+
))}
|
|
183
|
+
</ul>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* A skill on the list: a kit icon on a tile (never content-radar's mascot art; Stage pictures come later), its title by the job it
|
|
189
|
+
* does, one short line, a quiet foot ("advertorial · v2") and, when the surface has it, how often it ran. A button (or a link with
|
|
190
|
+
* `href`, the press handled by `onOpen` unless a modifier asks for a new tab). Hover and press states are its own, so an app's
|
|
191
|
+
* bare `button:hover` cannot paint it.
|
|
192
|
+
*/
|
|
193
|
+
export function SkillCard({ title, line, icon, meta, stat, badge, href, onOpen, className }: {
|
|
194
|
+
title: ReactNode;
|
|
195
|
+
line?: ReactNode;
|
|
196
|
+
icon?: ReactNode;
|
|
197
|
+
/** "advertorial · v2". */
|
|
198
|
+
meta?: ReactNode;
|
|
199
|
+
/** "12 runs · 30 days": only when there is a number. */
|
|
200
|
+
stat?: ReactNode;
|
|
201
|
+
/** One word in the corner ("New"). */
|
|
202
|
+
badge?: ReactNode;
|
|
203
|
+
href?: string;
|
|
204
|
+
onOpen?: () => void;
|
|
205
|
+
className?: string;
|
|
206
|
+
}) {
|
|
207
|
+
const body = (
|
|
208
|
+
<>
|
|
209
|
+
<span className="ui-skillcard__top">
|
|
210
|
+
{icon ? <span className="ui-skillcard__icon" aria-hidden="true">{icon}</span> : null}
|
|
211
|
+
{badge ? <span className="ui-skillcard__badge">{badge}</span> : null}
|
|
212
|
+
</span>
|
|
213
|
+
<b className="ui-skillcard__title">{title}</b>
|
|
214
|
+
{line ? <span className="ui-skillcard__line">{line}</span> : null}
|
|
215
|
+
{meta || stat ? (
|
|
216
|
+
<span className="ui-skillcard__foot">
|
|
217
|
+
{meta ? <span className="ui-skillcard__meta">{meta}</span> : null}
|
|
218
|
+
{stat ? <span className="ui-skillcard__stat">{stat}</span> : null}
|
|
219
|
+
</span>
|
|
220
|
+
) : null}
|
|
221
|
+
</>
|
|
222
|
+
);
|
|
223
|
+
return href ? (
|
|
224
|
+
<a href={href} className={cx("ui-skillcard", className)}
|
|
225
|
+
onClick={(e) => { if (!onOpen || e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return; e.preventDefault(); onOpen(); }}>{body}</a>
|
|
226
|
+
) : (
|
|
227
|
+
<button type="button" className={cx("ui-skillcard", className)} onClick={onOpen}>{body}</button>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Skills that do one job, under its name and one line, as a grid of cards. Nothing in it: nothing drawn. */
|
|
232
|
+
export function SkillGroup({ title, line, children, className, id }: { title: ReactNode; line?: ReactNode; children?: ReactNode; className?: string; id?: string }) {
|
|
233
|
+
if (!React.Children.toArray(children).length) return null;
|
|
234
|
+
return (
|
|
235
|
+
<section className={cx("ui-skillgroup", className)} aria-labelledby={id ? `${id}-h` : undefined}>
|
|
236
|
+
<div className="ui-skillgroup__head">
|
|
237
|
+
<h2 className="ui-skillgroup__title" id={id ? `${id}-h` : undefined}>{title}</h2>
|
|
238
|
+
{line ? <p className="ui-skillgroup__line">{line}</p> : null}
|
|
239
|
+
</div>
|
|
240
|
+
<div className="ui-skillgroup__grid">{children}</div>
|
|
241
|
+
</section>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* One block of a tab: a small heading, an optional one-line note, then the body. The pieces every tab is made of, so the surfaces
|
|
247
|
+
* write their Rules and History the same way.
|
|
248
|
+
*/
|
|
249
|
+
export function SkillViewSection({ title, note, children, className }: { title?: ReactNode; note?: ReactNode; children?: ReactNode; className?: string }) {
|
|
250
|
+
return (
|
|
251
|
+
<section className={cx("ui-skillview__sec", className)}>
|
|
252
|
+
{title ? <h3 className="ui-skillview__h">{title}</h3> : null}
|
|
253
|
+
{note ? <p className="ui-skillview__note">{note}</p> : null}
|
|
254
|
+
{children}
|
|
255
|
+
</section>
|
|
256
|
+
);
|
|
257
|
+
}
|