@milesroxas/design-hub 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +37 -32
  2. package/core/catalog.test.ts +28 -1
  3. package/core/catalog.ts +21 -4
  4. package/dist/core/catalog.d.ts +8 -1
  5. package/dist/core/catalog.js +12 -3
  6. package/dist/scripts/lib/catalog.d.ts +1 -1
  7. package/dist/scripts/lib/catalog.js +3 -3
  8. package/dist/scripts/new.d.ts +8 -3
  9. package/dist/scripts/new.js +15 -4
  10. package/dist/scripts/preflight.js +1 -1
  11. package/dist/scripts/share.js +3 -3
  12. package/dist/server/api.d.ts +11 -0
  13. package/dist/server/api.js +6 -0
  14. package/dist/server/dev-studio.d.ts +36 -0
  15. package/dist/server/dev-studio.js +181 -0
  16. package/dist/server/dev.d.ts +16 -1
  17. package/dist/server/dev.js +4 -4
  18. package/dist/vite/plugin.js +3 -0
  19. package/kit/ViewTools.tsx +9 -0
  20. package/kit/prefs.ts +3 -4
  21. package/package.json +1 -1
  22. package/shell/Command.tsx +142 -0
  23. package/shell/Index.tsx +902 -400
  24. package/shell/Milestone.tsx +302 -0
  25. package/shell/Sidebar.tsx +236 -0
  26. package/shell/index.css +224 -0
  27. package/shell/milestones.test.ts +157 -0
  28. package/shell/milestones.ts +144 -0
  29. package/shell/registry.ts +4 -3
  30. package/shell/shell.css +8 -175
  31. package/shell/sidebar.css +86 -0
  32. package/shell/studio/ClientHub.tsx +21 -10
  33. package/shell/studio/StudioHub.tsx +120 -45
  34. package/shell/studio/hub.css +20 -15
  35. package/shell/studio/page.tsx +28 -17
  36. package/shell/system.css +12 -0
  37. package/skills/miles-deploy/SKILL.md +1 -1
  38. package/skills/miles-new-feature/SKILL.md +2 -1
  39. package/skills/miles-prototype/SKILL.md +1 -1
  40. package/templates/app/README.md +1 -1
  41. package/templates/brand/README.md +1 -1
  42. package/templates/site/README.md +1 -1
  43. package/templates/space/README.md +1 -1
  44. package/templates/studio/package.json +1 -1
@@ -0,0 +1,302 @@
1
+ // A milestone's home, over the index: what the milestone is for, its Main,
2
+ // and every exploration by where it stands. The index lists only what is
3
+ // live; the rest is here. One bar holds every control but the primary, which
4
+ // sits alone in the foot.
5
+ import { Button } from '@kit/ui';
6
+ import { type KeyboardEvent, type ReactNode, useEffect, useRef } from 'react';
7
+ import { TRACK_LABEL, type Track } from '../core/project';
8
+ import { fmtShort, type Milestone, statusLabel, waits } from './milestones';
9
+ import type { Entry } from './registry';
10
+
11
+ type HomeProps = {
12
+ m: Milestone<Entry>;
13
+ /** Studio's own view: statuses in the studio's words, and the archive. */
14
+ studio: boolean;
15
+ guide?: string;
16
+ hrefOf: (e: Entry) => string;
17
+ onOpen: (e: Entry) => void;
18
+ /** Studio's switch for one prototype, at the end of its row; nothing outside Studio's view. */
19
+ audience: (e: Entry) => ReactNode;
20
+ };
21
+
22
+ export function MilestoneHome({ m, studio, guide, hrefOf, onOpen, audience }: HomeProps) {
23
+ const groups = [
24
+ { title: 'Main', list: m.main ? [m.main] : [] },
25
+ { title: 'Explorations', list: m.explorations },
26
+ { title: 'Presented', list: m.presented },
27
+ { title: 'Archived', list: studio ? m.archived : [] },
28
+ ].filter((g) => g.list.length);
29
+ return (
30
+ <>
31
+ <div className="ix-modal-body">
32
+ <article className="ix-read" aria-labelledby="ix-peek-title">
33
+ <h2 id="ix-peek-title" className="ix-read-title">
34
+ {m.title}
35
+ </h2>
36
+ {m.summary ? <p className="ix-read-summary">{m.summary}</p> : null}
37
+ {m.question ? (
38
+ <section className="ix-read-question" aria-labelledby="ix-question-label">
39
+ <h3 id="ix-question-label">The question</h3>
40
+ <p>{m.question}</p>
41
+ </section>
42
+ ) : null}
43
+ {groups.map((g) => (
44
+ <section key={g.title} className="ix-home-group" aria-labelledby={`ix-home-${g.title}`}>
45
+ <h3 id={`ix-home-${g.title}`}>{g.title}</h3>
46
+ <ul>
47
+ {g.list.map((e) => (
48
+ <li key={e.slug} className="ix-home-row">
49
+ <a className="ix-home-link" href={hrefOf(e)} onClick={() => onOpen(e)}>
50
+ <span className="ix-home-title">{e.title}</span>
51
+ {waits(e.status) && e !== m.main ? (
52
+ <span className="ix-status" data-status={e.status}>
53
+ {statusLabel(e.status, studio)}
54
+ </span>
55
+ ) : null}
56
+ </a>
57
+ {audience(e)}
58
+ </li>
59
+ ))}
60
+ </ul>
61
+ </section>
62
+ ))}
63
+ </article>
64
+ <Facts m={m} studio={studio} />
65
+ </div>
66
+ <footer className="ix-modal-foot">
67
+ {guide ? (
68
+ <a className="btn btn-tertiary btn-sm ix-foot-guide" href={guide}>
69
+ Guide
70
+ </a>
71
+ ) : null}
72
+ {m.main ? (
73
+ <a
74
+ className="btn btn-primary btn-sm ix-open"
75
+ href={hrefOf(m.main)}
76
+ onClick={() => m.main && onOpen(m.main)}
77
+ >
78
+ Open Main
79
+ <span className="ix-kbd-on" aria-hidden="true">
80
+ ↵
81
+ </span>
82
+ </a>
83
+ ) : (
84
+ <p className="ix-foot-note">No Main yet</p>
85
+ )}
86
+ </footer>
87
+ </>
88
+ );
89
+ }
90
+
91
+ function Facts({ m, studio }: { m: Milestone; studio: boolean }) {
92
+ return (
93
+ <dl className="ix-facts" aria-label="Details">
94
+ <div>
95
+ <dt>Status</dt>
96
+ <dd>
97
+ <span className="ix-status" data-status={m.status}>
98
+ {statusLabel(m.status, studio)}
99
+ </span>
100
+ </dd>
101
+ </div>
102
+ {m.track ? (
103
+ <div>
104
+ <dt>Track</dt>
105
+ <dd>{TRACK_LABEL[m.track as Track] ?? m.track}</dd>
106
+ </div>
107
+ ) : null}
108
+ {m.updated ? (
109
+ <div>
110
+ <dt>Updated</dt>
111
+ <dd>
112
+ <time className="tabular" dateTime={m.updated}>
113
+ {fmtShort(m.updated)}
114
+ </time>
115
+ </dd>
116
+ </div>
117
+ ) : null}
118
+ </dl>
119
+ );
120
+ }
121
+
122
+ const FOCUSABLE = 'button:not([disabled]), a[href], input, [tabindex]:not([tabindex="-1"])';
123
+
124
+ /** Tab stays inside the dialog: past the last control it wraps to the first, and back. */
125
+ function trapTab(e: KeyboardEvent, dialog: HTMLElement) {
126
+ const items = [...dialog.querySelectorAll<HTMLElement>(FOCUSABLE)];
127
+ const head = items[0];
128
+ const end = items.at(-1);
129
+ const at = document.activeElement;
130
+ if (e.shiftKey && (at === head || at === dialog)) {
131
+ e.preventDefault();
132
+ end?.focus();
133
+ } else if (!e.shiftKey && at === end) {
134
+ e.preventDefault();
135
+ head?.focus();
136
+ }
137
+ }
138
+
139
+ type Action = 'close' | 'primary' | 'next' | 'previous' | 'tab';
140
+ const KEYS: Record<string, Action> = { Escape: 'close', Tab: 'tab', j: 'next', k: 'previous' };
141
+ const OWN_KEYS: Record<string, Action> = { ArrowDown: 'next', ArrowUp: 'previous', Enter: 'primary' };
142
+
143
+ /** The key a press means in the dialog: J and K step from anywhere in it, the arrows and Enter only from the dialog itself. */
144
+ function actionOf(e: KeyboardEvent, own: boolean): Action | null {
145
+ if (e.metaKey || e.ctrlKey || e.altKey) return null;
146
+ return KEYS[e.key] ?? (own ? OWN_KEYS[e.key] : null) ?? null;
147
+ }
148
+
149
+ /** Over the list: a centered dialog. Escape or a press on the backdrop closes it; J and K step to the next milestone. */
150
+ export function CenterPeek({
151
+ open,
152
+ instant,
153
+ order,
154
+ id,
155
+ full,
156
+ onFull,
157
+ onStep,
158
+ onPrimary,
159
+ onClose,
160
+ children,
161
+ }: {
162
+ open: boolean;
163
+ /** Opened by keyboard: no motion. */
164
+ instant: boolean;
165
+ /** The milestones the index lists, in its order: what Previous and Next step through. */
166
+ order: string[];
167
+ id?: string;
168
+ full: boolean;
169
+ onFull: () => void;
170
+ onStep: (id: string) => void;
171
+ onPrimary: () => void;
172
+ onClose: () => void;
173
+ children: ReactNode;
174
+ }) {
175
+ const dialog = useRef<HTMLDivElement>(null);
176
+ // A press that starts and ends on the backdrop closes; a touch scroll cancels the press, so it does not.
177
+ const downOnBackdrop = useRef(false);
178
+ const at = id ? order.indexOf(id) : -1;
179
+ const step = (d: number) => {
180
+ const next = at < 0 ? undefined : order[at + d];
181
+ if (next) onStep(next);
182
+ };
183
+
184
+ // Focus lands in the dialog when it opens, and stays there when a step takes the focused control away.
185
+ // biome-ignore lint/correctness/useExhaustiveDependencies: follow the dialog and its milestone only
186
+ useEffect(() => {
187
+ if (open && !dialog.current?.contains(document.activeElement)) dialog.current?.focus();
188
+ }, [open, id]);
189
+
190
+ const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
191
+ const action = actionOf(e, e.target === dialog.current);
192
+ if (!action || document.querySelector('.menu')) return;
193
+ if (action === 'tab') return dialog.current && trapTab(e, dialog.current);
194
+ e.preventDefault();
195
+ if (action === 'close') onClose();
196
+ else if (action === 'primary') onPrimary();
197
+ else step(action === 'next' ? 1 : -1);
198
+ };
199
+
200
+ return (
201
+ <div
202
+ className="ix-overlay"
203
+ data-open={open || undefined}
204
+ data-instant={instant || undefined}
205
+ data-full={full || undefined}
206
+ inert={!open || undefined}
207
+ onPointerDown={(e) => {
208
+ downOnBackdrop.current = e.target === e.currentTarget;
209
+ }}
210
+ onPointerUp={(e) => {
211
+ if (downOnBackdrop.current && e.target === e.currentTarget) onClose();
212
+ downOnBackdrop.current = false;
213
+ }}
214
+ >
215
+ <div
216
+ ref={dialog}
217
+ className="ix-modal"
218
+ role="dialog"
219
+ aria-modal="true"
220
+ aria-labelledby="ix-peek-title"
221
+ tabIndex={-1}
222
+ onKeyDown={onKeyDown}
223
+ >
224
+ <PeekBar
225
+ first={at <= 0}
226
+ last={at < 0 || at >= order.length - 1}
227
+ full={full}
228
+ onStep={step}
229
+ onFull={onFull}
230
+ onClose={onClose}
231
+ />
232
+ {children}
233
+ </div>
234
+ </div>
235
+ );
236
+ }
237
+
238
+ /** The dialog's one bar: where you are, and every control but the primary. */
239
+ function PeekBar({
240
+ first,
241
+ last,
242
+ full,
243
+ onStep,
244
+ onFull,
245
+ onClose,
246
+ }: {
247
+ first: boolean;
248
+ last: boolean;
249
+ full: boolean;
250
+ onStep: (by: number) => void;
251
+ onFull: () => void;
252
+ onClose: () => void;
253
+ }) {
254
+ return (
255
+ <div className="ix-modal-bar">
256
+ <span className="ix-crumb">Milestone</span>
257
+ <div className="ix-modal-tools">
258
+ <Button
259
+ kind="tertiary"
260
+ size="sm"
261
+ icon="chevron-down"
262
+ iconSize={16}
263
+ className="ix-step-up"
264
+ aria-label="Previous milestone"
265
+ title="Previous (K)"
266
+ aria-disabled={first || undefined}
267
+ onClick={() => onStep(-1)}
268
+ />
269
+ <Button
270
+ kind="tertiary"
271
+ size="sm"
272
+ icon="chevron-down"
273
+ iconSize={16}
274
+ aria-label="Next milestone"
275
+ title="Next (J)"
276
+ aria-disabled={last || undefined}
277
+ onClick={() => onStep(1)}
278
+ />
279
+ <Button
280
+ kind="tertiary"
281
+ size="sm"
282
+ icon="expand-01"
283
+ iconSize={16}
284
+ aria-label="Full page"
285
+ title="Full page"
286
+ aria-pressed={full}
287
+ onClick={onFull}
288
+ />
289
+ <Button
290
+ kind="tertiary"
291
+ size="sm"
292
+ icon="x-close"
293
+ iconSize={16}
294
+ className="ix-modal-close"
295
+ aria-label="Close"
296
+ title="Close (Esc)"
297
+ onClick={onClose}
298
+ />
299
+ </div>
300
+ </div>
301
+ );
302
+ }
@@ -0,0 +1,236 @@
1
+ // The sidebar every hub page docks to its left edge: the prototype index
2
+ // (Index.tsx), the studio hub and a client's hub (studio/). Under it, the way
3
+ // back; then Search; then the page's views, each with its jumps nested under
4
+ // it; at its foot, who is signed in. The page says what is searched, what each view holds and where a jump
5
+ // lands; the sidebar only draws them. Its look is sidebar.css.
6
+ import { Icon, type IconName } from '@kit/Icon';
7
+ import { type RefObject, useEffect, useRef } from 'react';
8
+ import './sidebar.css';
9
+
10
+ /** A jump under a view: to a group on that view's page. Without hits while searching, it dims. */
11
+ export type SidebarJump = { key: string; label: string; hits: boolean };
12
+
13
+ export type SidebarView = {
14
+ key: string;
15
+ label: string;
16
+ href: string;
17
+ icon: IconName;
18
+ current: boolean;
19
+ /** Searching leaves nothing in this view: it dims rather than hides, so the sidebar never shifts. */
20
+ empty?: boolean;
21
+ jumps?: SidebarJump[];
22
+ };
23
+
24
+ /** What Search needs once the page has loaded; before that Search holds its place, off. */
25
+ export type SidebarSearch = {
26
+ query: string;
27
+ setQuery: (q: string) => void;
28
+ /** Called on every keystroke, after `setQuery`. */
29
+ onType?: () => void;
30
+ };
31
+
32
+ export function Sidebar({
33
+ back,
34
+ label,
35
+ search,
36
+ views,
37
+ jumpsLabel,
38
+ onJump,
39
+ who,
40
+ onSearch,
41
+ recent,
42
+ }: {
43
+ back?: { href: string; label: string };
44
+ /** What Search searches, for a screen reader: "Search clients and projects". */
45
+ label: string;
46
+ search?: SidebarSearch;
47
+ views: SidebarView[];
48
+ jumpsLabel?: string;
49
+ onJump?: (key: string) => void;
50
+ /** Who is signed in, at the sidebar's foot, once known. */
51
+ who?: { name: string; team: string } | null;
52
+ /** Search as a button that opens the page's own search (the index's command menu), in place of the field. */
53
+ onSearch?: () => void;
54
+ /** What was opened last, under the views: each a link. */
55
+ recent?: { key: string; label: string; href: string; onOpen?: () => void }[];
56
+ }) {
57
+ const input = useRef<HTMLInputElement>(null);
58
+ return (
59
+ <aside className="index-rail" aria-label="Sidebar">
60
+ {back ? (
61
+ <a className="index-rail-link index-rail-back" href={back.href}>
62
+ <Icon name="arrow-left" size={16} />
63
+ {back.label}
64
+ </a>
65
+ ) : null}
66
+ {onSearch ? (
67
+ <button type="button" className="index-search-open" aria-keyshortcuts="Meta+K /" onClick={onSearch}>
68
+ <Icon name="search-md" size={16} />
69
+ <span>Search</span>
70
+ <span className="index-search-key" aria-hidden="true">
71
+ {MOD}K
72
+ </span>
73
+ </button>
74
+ ) : (
75
+ <Search search={search} label={label} input={input} />
76
+ )}
77
+ <nav className="index-rail-nav" aria-label="Views">
78
+ {views.map((v) => (
79
+ <div key={v.key} className="index-rail-item">
80
+ <a
81
+ className="index-rail-link"
82
+ href={v.href}
83
+ aria-current={v.current ? 'page' : undefined}
84
+ data-empty={v.empty || undefined}
85
+ >
86
+ <Icon name={v.icon} size={16} />
87
+ {v.label}
88
+ </a>
89
+ {v.jumps?.length ? (
90
+ <ul className="index-rail-sub" aria-label={jumpsLabel}>
91
+ {v.jumps.map((j) => (
92
+ <li key={j.key}>
93
+ <button
94
+ type="button"
95
+ className="index-rail-link"
96
+ disabled={!j.hits}
97
+ onClick={() => onJump?.(j.key)}
98
+ >
99
+ <span className="index-rail-label">{j.label}</span>
100
+ </button>
101
+ </li>
102
+ ))}
103
+ </ul>
104
+ ) : null}
105
+ </div>
106
+ ))}
107
+ </nav>
108
+ {recent?.length ? (
109
+ <section className="index-rail-recent" aria-labelledby="index-rail-recent">
110
+ <h2 id="index-rail-recent" className="index-rail-heading">
111
+ Recent
112
+ </h2>
113
+ <ul>
114
+ {recent.map((r) => (
115
+ <li key={r.key}>
116
+ <a className="index-rail-link" href={r.href} onClick={r.onOpen}>
117
+ <span className="index-rail-label">{r.label}</span>
118
+ </a>
119
+ </li>
120
+ ))}
121
+ </ul>
122
+ </section>
123
+ ) : null}
124
+ {who ? (
125
+ <p className="index-rail-who">
126
+ <span className="sr-only">Signed in as </span>
127
+ <span className="index-rail-who-name">{who.name}</span>
128
+ <span className="index-rail-who-team">{who.team}</span>
129
+ </p>
130
+ ) : null}
131
+ </aside>
132
+ );
133
+ }
134
+
135
+ /** The modifier a shortcut names: Command on Apple's keyboards, Control elsewhere. */
136
+ const MOD = /mac|iphone|ipad/i.test(navigator.userAgent) ? '⌘' : 'Ctrl ';
137
+
138
+ /** Search: `/` reaches it from anywhere, Escape clears it and then leaves it. */
139
+ function Search({
140
+ search,
141
+ label,
142
+ input,
143
+ }: {
144
+ search?: SidebarSearch;
145
+ label: string;
146
+ input: RefObject<HTMLInputElement | null>;
147
+ }) {
148
+ const on = Boolean(search);
149
+ useEffect(() => {
150
+ if (!on) return;
151
+ const onKey = (e: globalThis.KeyboardEvent) => {
152
+ if (e.key !== '/' || e.metaKey || e.ctrlKey || e.altKey) return;
153
+ const t = e.target as HTMLElement;
154
+ if (t.closest('input, textarea, select, [contenteditable="true"]')) return;
155
+ e.preventDefault();
156
+ input.current?.focus();
157
+ };
158
+ addEventListener('keydown', onKey);
159
+ return () => removeEventListener('keydown', onKey);
160
+ }, [on, input]);
161
+ const query = search?.query ?? '';
162
+ const set = (q: string) => {
163
+ search?.setQuery(q);
164
+ search?.onType?.();
165
+ };
166
+ return (
167
+ <search className="index-search">
168
+ <Icon name="search-md" size={16} />
169
+ <label className="sr-only" htmlFor="index-search">
170
+ {label}
171
+ </label>
172
+ <input
173
+ ref={input}
174
+ id="index-search"
175
+ type="search"
176
+ placeholder="Search"
177
+ autoComplete="off"
178
+ spellCheck={false}
179
+ aria-keyshortcuts="/"
180
+ disabled={!search}
181
+ value={query}
182
+ onChange={(e) => set(e.target.value)}
183
+ onKeyDown={(e) => {
184
+ if (e.key !== 'Escape') return;
185
+ if (query) {
186
+ set('');
187
+ e.stopPropagation();
188
+ } else e.currentTarget.blur();
189
+ }}
190
+ />
191
+ {query ? (
192
+ <button
193
+ type="button"
194
+ className="index-search-clear"
195
+ aria-label="Clear search"
196
+ onClick={() => {
197
+ set('');
198
+ input.current?.focus();
199
+ }}
200
+ >
201
+ <Icon name="x-close" size={16} />
202
+ </button>
203
+ ) : (
204
+ <span className="index-search-key" aria-hidden="true">
205
+ /
206
+ </span>
207
+ )}
208
+ </search>
209
+ );
210
+ }
211
+
212
+ const reveal = (id: string) => {
213
+ const heading = document.getElementById(id);
214
+ heading?.closest('section')?.scrollIntoView({ block: 'start' });
215
+ heading?.focus({ preventScroll: true });
216
+ };
217
+
218
+ /**
219
+ * A jump lands on a group's heading, by its id, from any view: away from the
220
+ * view that holds the groups, it goes there first. The jump is instant and
221
+ * moves focus to the heading, so keyboard and screen reader users land where
222
+ * sighted ones do.
223
+ */
224
+ export function useJump(home: boolean, homeHref: string) {
225
+ const pending = useRef<string | null>(null);
226
+ useEffect(() => {
227
+ if (!home || !pending.current) return;
228
+ reveal(pending.current);
229
+ pending.current = null;
230
+ }, [home]);
231
+ return (id: string) => {
232
+ if (home) return reveal(id);
233
+ pending.current = id;
234
+ location.hash = homeHref;
235
+ };
236
+ }