@milesroxas/design-hub 0.13.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 (101) hide show
  1. package/README.md +38 -33
  2. package/core/catalog.test.ts +28 -1
  3. package/core/catalog.ts +21 -4
  4. package/core/prototype.test.ts +12 -1
  5. package/core/prototype.ts +21 -2
  6. package/core/review/model.ts +71 -6
  7. package/core/review/service.test.ts +536 -1
  8. package/core/review/service.ts +452 -25
  9. package/core/review/store.ts +45 -4
  10. package/dist/core/catalog.d.ts +8 -1
  11. package/dist/core/catalog.js +12 -3
  12. package/dist/core/prototype.d.ts +20 -2
  13. package/dist/core/prototype.js +17 -2
  14. package/dist/core/review/model.d.ts +42 -3
  15. package/dist/core/review/model.js +52 -3
  16. package/dist/core/review/service.d.ts +81 -7
  17. package/dist/core/review/service.js +407 -23
  18. package/dist/core/review/store.d.ts +29 -2
  19. package/dist/core/review/store.js +4 -0
  20. package/dist/scripts/client.d.ts +1 -1
  21. package/dist/scripts/client.js +1 -1
  22. package/dist/scripts/lib/catalog.d.ts +1 -1
  23. package/dist/scripts/lib/catalog.js +3 -3
  24. package/dist/scripts/lib/dns.d.ts +16 -2
  25. package/dist/scripts/lib/dns.js +66 -3
  26. package/dist/scripts/lib/fake-host.d.ts +16 -1
  27. package/dist/scripts/lib/fake-host.js +36 -1
  28. package/dist/scripts/lib/host.d.ts +2 -0
  29. package/dist/scripts/lib/resend.d.ts +36 -0
  30. package/dist/scripts/lib/resend.js +66 -0
  31. package/dist/scripts/lib/studio-deps.d.ts +7 -0
  32. package/dist/scripts/lib/studio-deps.js +6 -1
  33. package/dist/scripts/lib/studios.d.ts +2 -2
  34. package/dist/scripts/lib/studios.js +5 -5
  35. package/dist/scripts/lib/vercel-host.js +6 -0
  36. package/dist/scripts/new.d.ts +8 -3
  37. package/dist/scripts/new.js +15 -4
  38. package/dist/scripts/people.d.ts +16 -4
  39. package/dist/scripts/people.js +67 -17
  40. package/dist/scripts/preflight.js +1 -1
  41. package/dist/scripts/share.js +3 -3
  42. package/dist/scripts/studio.d.ts +19 -3
  43. package/dist/scripts/studio.js +327 -6
  44. package/dist/server/api.d.ts +25 -2
  45. package/dist/server/api.js +77 -17
  46. package/dist/server/dev-studio.d.ts +36 -0
  47. package/dist/server/dev-studio.js +181 -0
  48. package/dist/server/dev.d.ts +16 -1
  49. package/dist/server/dev.js +23 -3
  50. package/dist/server/gate.d.ts +26 -3
  51. package/dist/server/gate.js +323 -52
  52. package/dist/server/mailer.d.ts +60 -0
  53. package/dist/server/mailer.js +104 -0
  54. package/dist/server/mailers/fake.d.ts +8 -0
  55. package/dist/server/mailers/fake.js +16 -0
  56. package/dist/server/mailers/resend.d.ts +21 -0
  57. package/dist/server/mailers/resend.js +49 -0
  58. package/dist/server/session.js +4 -1
  59. package/dist/vercel/proxy.js +10 -3
  60. package/dist/vite/plugin.js +6 -1
  61. package/kit/ViewTools.tsx +9 -0
  62. package/kit/prefs.ts +3 -4
  63. package/kit/ui/Menu.tsx +29 -18
  64. package/kit/ui/layer.ts +41 -0
  65. package/package.json +1 -1
  66. package/shell/Command.tsx +142 -0
  67. package/shell/Index.tsx +902 -400
  68. package/shell/Milestone.tsx +302 -0
  69. package/shell/Sidebar.tsx +236 -0
  70. package/shell/index.css +224 -0
  71. package/shell/milestones.test.ts +157 -0
  72. package/shell/milestones.ts +144 -0
  73. package/shell/registry.ts +4 -3
  74. package/shell/review/Bar.tsx +1 -0
  75. package/shell/review/Card.tsx +17 -7
  76. package/shell/review/People.tsx +908 -134
  77. package/shell/review/Review.tsx +2 -2
  78. package/shell/review/anchor.ts +6 -1
  79. package/shell/review/client.ts +41 -7
  80. package/shell/review/menu-place.test.ts +41 -0
  81. package/shell/review/place.test.ts +26 -1
  82. package/shell/review/place.ts +17 -0
  83. package/shell/review/review.css +97 -11
  84. package/shell/review/view.test.ts +115 -1
  85. package/shell/review/view.ts +92 -2
  86. package/shell/shell.css +8 -175
  87. package/shell/sidebar.css +86 -0
  88. package/shell/studio/ClientHub.tsx +21 -10
  89. package/shell/studio/StudioHub.tsx +121 -45
  90. package/shell/studio/hub.css +118 -27
  91. package/shell/studio/page.tsx +28 -17
  92. package/shell/system.css +12 -0
  93. package/skills/miles-deploy/SKILL.md +25 -4
  94. package/skills/miles-new-feature/SKILL.md +2 -1
  95. package/skills/miles-prototype/SKILL.md +1 -1
  96. package/templates/app/README.md +1 -1
  97. package/templates/brand/README.md +1 -1
  98. package/templates/site/README.md +1 -1
  99. package/templates/space/README.md +1 -1
  100. package/templates/studio/.env.example +6 -0
  101. package/templates/studio/package.json +1 -1
package/shell/Index.tsx CHANGED
@@ -1,105 +1,57 @@
1
- import { fmtDate, plural } from '@kit/format';
2
- import { useStoredState } from '@kit/hooks';
1
+ import { plural } from '@kit/format';
2
+ import { useHashRoute, useStoredState } from '@kit/hooks';
3
3
  import { Icon } from '@kit/Icon';
4
4
  import { isClientView, setClientView } from '@kit/prefs';
5
- import { Button, Toaster, toast } from '@kit/ui';
6
- import {
7
- type CSSProperties,
8
- type KeyboardEvent,
9
- type MouseEvent,
10
- type ReactNode,
11
- useCallback,
12
- useDeferredValue,
13
- useEffect,
14
- useRef,
15
- useState,
16
- } from 'react';
17
- import { placeLabel } from '../core/catalog';
18
- import { featureTitle, guideHref } from '../core/feature';
5
+ import { Button, Toaster, toast, useMenu } from '@kit/ui';
6
+ import { type ReactNode, type RefObject, useCallback, useEffect, useRef, useState } from 'react';
7
+ import { guideHref } from '../core/feature';
19
8
  import { TRACK_LABEL, TRACKS, type Track } from '../core/project';
20
9
  import type { Audience } from '../core/review/model';
21
10
  import { AUDIENCE_LABEL, audienceIn, emptyState, lensOf, withAudience } from './audience';
22
11
  import { ClientViewNote } from './ClientViewNote';
12
+ import { type CommandItem, CommandMenu } from './Command';
23
13
  import { type Hub, loadHub, saveAudience } from './hub';
14
+ import { CenterPeek, MilestoneHome } from './Milestone';
15
+ import {
16
+ byOrder,
17
+ fmtShort,
18
+ type Milestone,
19
+ milestonesOf,
20
+ type Order,
21
+ startsFolded,
22
+ statusLabel,
23
+ waits,
24
+ withRecent,
25
+ } from './milestones';
24
26
  import { type Entry, guides } from './registry';
25
27
  import { signedOut } from './review/client';
28
+ import { Sidebar } from './Sidebar';
26
29
  import './shell.css';
30
+ import './index.css';
27
31
 
28
32
  // The index is built from the server's answer (shell/hub.ts): Studio's view
29
- // lists every prototype, a Client's only the client-facing ones. Studio,
30
- // outside Client view, sees each prototype's audience and a switch for it.
33
+ // lists every prototype, a Client's only the client-facing ones.
31
34
  //
32
- // One group per feature: its one primary prototype, its alternates on a rail
33
- // under it, then its explorations folded away. A second sprint
34
- // becomes an alternate, since a feature has one primary. Prototypes with no
35
- // feature fold into their own group. Archived ones leave their group.
36
- type Group = {
37
- id: string;
38
- title: string;
39
- guide?: string;
40
- items: Entry[];
41
- alternates: Entry[];
42
- explorations: Entry[];
43
- };
44
- const groupsOf = (list: Entry[]): Group[] => {
45
- const live = list.filter((e) => e.status !== 'archived');
46
- const features = [...new Set(live.map((e) => e.feature).filter(Boolean))];
47
- return [
48
- ...features.map((f) => {
49
- const own = live.filter((e) => e.feature === f);
50
- const primary = own.find((e) => e.kind === 'sprint');
51
- const alternates = own.filter((e) => e.kind !== 'exploration' && e !== primary);
52
- return {
53
- id: `feature-${f}`,
54
- title: featureTitle(f),
55
- guide: guides.has(f)
56
- ? import.meta.env.BASE_URL === '/'
57
- ? guideHref(f)
58
- : `${import.meta.env.BASE_URL}guide/${f}/`
59
- : undefined,
60
- items: primary ? [primary] : alternates,
61
- alternates: primary ? alternates : [],
62
- explorations: own.filter((e) => e.kind === 'exploration'),
63
- };
64
- }),
65
- {
66
- id: 'unassigned',
67
- title: 'Without a feature',
68
- items: [],
69
- alternates: [],
70
- explorations: live.filter((e) => !e.feature),
71
- },
72
- {
73
- id: 'archived',
74
- title: 'Archived',
75
- items: list.filter((e) => e.status === 'archived'),
76
- alternates: [],
77
- explorations: [],
78
- },
79
- ].filter((g) => g.items.length || g.alternates.length || g.explorations.length);
80
- };
81
-
82
- /** The track the index shows, remembered per browser. Only the tracks the prototypes use are offered; a stale choice shows all. */
83
- function useTrackFilter(entries: Entry[]) {
84
- const [track, setTrack] = useStoredState<Track | 'all'>('index-track', 'all');
85
- const tracks = TRACKS.filter((t) => entries.some((e) => e.track === t));
86
- const inTrack = (e: Entry) => track === 'all' || !tracks.includes(track) || e.track === track;
87
- return { filter: { tracks, value: track, onChange: setTrack }, inTrack };
88
- }
89
-
90
- const byQuery = (q: string) => (e: Entry) =>
91
- !q || `${e.title} ${e.summary} ${e.slug}`.toLowerCase().includes(q);
92
-
93
- /** The filter text and the track, and the entries they leave: the chosen track's, matching the text. */
94
- function useIndexFilter(entries: Entry[]) {
95
- const [query, setQuery] = useState('');
96
- const q = useDeferredValue(query.trim().toLowerCase());
97
- const { filter, inTrack } = useTrackFilter(entries);
98
- return { query, setQuery, q, shown: entries.filter(inTrack).filter(byQuery(q)), trackFilter: filter };
99
- }
100
-
101
- const RISE_CAP = 8;
102
- const rise = (i: number) => ({ '--i': Math.min(i, RISE_CAP) }) as CSSProperties;
35
+ // It lists milestones (shell/milestones.ts), not prototypes. A milestone row
36
+ // opens the milestone's home over the list (Milestone.tsx); the rows under it
37
+ // are quick links to what is live, and each opens what it names: its Main,
38
+ // its Guide, and its explorations still in motion. Everything else is one
39
+ // level down, in the home. Search is the command menu (Command.tsx). Tools
40
+ // make assets for several milestones, so they list in a view of their own.
41
+ const VIEWS = {
42
+ milestones: { href: '#/', title: 'Milestones', icon: 'target-04' },
43
+ tools: { href: '#/tools', title: 'Tools', icon: 'sliders-04' },
44
+ } as const;
45
+ type View = keyof typeof VIEWS;
46
+ const HOME = '#/m/';
47
+ const homeHash = (id: string) => `${HOME}${id}`;
48
+ const hrefOf = (e: Entry) => `${import.meta.env.BASE_URL}${e.slug}/`;
49
+ const guideFor = (f: string) =>
50
+ guides.has(f)
51
+ ? import.meta.env.BASE_URL === '/'
52
+ ? guideHref(f)
53
+ : `${import.meta.env.BASE_URL}guide/${f}/`
54
+ : undefined;
103
55
 
104
56
  type Loaded =
105
57
  | { status: 'loading' }
@@ -175,68 +127,100 @@ export function Index() {
175
127
  const [clientView, setView] = useClientView();
176
128
  const { loaded, onSwitch, saving } = useHub(clientView);
177
129
  const lens = loaded.status === 'ready' ? lensOf(loaded.hub.me, loaded.hub.view) : null;
178
- // Leave stays in reach when the index did not load, so Client view is never a dead end.
179
- const note = lens ? lens.clientView : loaded.status === 'error' && clientView;
180
130
  return (
181
131
  <>
182
132
  <IndexPage
183
133
  loaded={loaded}
184
134
  controls={lens?.controls ? { onSwitch, saving } : null}
185
- head={lens?.controls ? <ClientViewButton onEnter={() => setView(true)} /> : null}
135
+ onClientView={toggleOf(lens, setView)}
186
136
  />
187
- {note ? <ClientViewNote onLeave={() => setView(false)} /> : null}
137
+ {notes(loaded, lens, clientView) ? <ClientViewNote onLeave={() => setView(false)} /> : null}
188
138
  <Toaster />
189
139
  </>
190
140
  );
191
141
  }
192
142
 
193
- /** Studio's way into Client view: the index, and every comment, as a client gets them. */
194
- function ClientViewButton({ onEnter }: { onEnter: () => void }) {
195
- return (
196
- <Button
197
- kind="tertiary"
198
- size="sm"
199
- icon="briefcase-01"
200
- iconSize={16}
201
- className="index-client-view"
202
- label="Client view"
203
- title="See the prototypes as a client does"
204
- onClick={onEnter}
205
- />
206
- );
143
+ type Lens = ReturnType<typeof lensOf> | null;
144
+ /** Studio's way into Client view, the way back out of it, or neither. */
145
+ function toggleOf(lens: Lens, setView: (on: boolean) => void): (() => void) | null {
146
+ if (lens?.controls) return () => setView(true);
147
+ return lens?.clientView ? () => setView(false) : null;
207
148
  }
149
+ /** Leave stays in reach when the index did not load, so Client view is never a dead end. */
150
+ const notes = (loaded: Loaded, lens: Lens, clientView: boolean) =>
151
+ lens ? lens.clientView : loaded.status === 'error' && clientView;
208
152
 
209
153
  type Controls = Omit<NonNullable<AudienceControls>, 'clientFacing'> | null;
210
154
 
211
- function IndexPage({ loaded, controls, head }: { loaded: Loaded; controls: Controls; head: ReactNode }) {
155
+ function IndexPage({
156
+ loaded,
157
+ controls,
158
+ onClientView,
159
+ }: {
160
+ loaded: Loaded;
161
+ controls: Controls;
162
+ onClientView: (() => void) | null;
163
+ }) {
164
+ const route = useRoute();
212
165
  if (loaded.status === 'ready')
213
166
  return (
214
167
  <IndexList
215
- entries={loaded.hub.entries}
216
- failed={loaded.hub.failed}
217
- view={loaded.hub.view}
168
+ route={route}
169
+ hub={loaded.hub}
218
170
  audience={controls ? { ...controls, clientFacing: loaded.hub.clientFacing } : null}
219
- head={head}
171
+ onClientView={onClientView}
220
172
  />
221
173
  );
222
174
  return (
223
- <main className="index" aria-busy={loaded.status === 'loading'}>
224
- <IndexHead>{head}</IndexHead>
225
- {loaded.status === 'error' ? <LoadFailed loaded={loaded} /> : null}
226
- </main>
175
+ <div className="index-frame ix-frame">
176
+ <Sidebar
177
+ back={BACK}
178
+ label="Search"
179
+ views={[
180
+ {
181
+ key: 'milestones',
182
+ label: 'Milestones',
183
+ ...VIEWS.milestones,
184
+ current: route.tab === 'milestones',
185
+ },
186
+ ]}
187
+ />
188
+ <main className="ix-main" aria-busy={loaded.status === 'loading'}>
189
+ <header className="ix-toolbar">
190
+ <div className="ix-toolbar-row">
191
+ <h1>{VIEWS[route.tab].title}</h1>
192
+ </div>
193
+ </header>
194
+ {loaded.status === 'error' ? <LoadFailed loaded={loaded} /> : null}
195
+ </main>
196
+ </div>
227
197
  );
228
198
  }
229
199
 
200
+ /** Under a base, the way back to the client's hub. */
201
+ const BACK = import.meta.env.BASE_URL === '/' ? undefined : { href: '/', label: 'All projects' };
202
+
203
+ /** What the hash names: `#/tools` is Tools, `#/m/<milestone>` that milestone's home over Milestones, anything else Milestones. The tab's title follows it. */
204
+ function useRoute(): { tab: View; home: string | null } {
205
+ const { path } = useHashRoute();
206
+ const tab: View = path === VIEWS.tools.href ? 'tools' : 'milestones';
207
+ const home = path.startsWith(HOME) ? path.slice(HOME.length) : null;
208
+ useEffect(() => {
209
+ document.title = VIEWS[tab].title;
210
+ }, [tab]);
211
+ return { tab, home };
212
+ }
213
+
230
214
  /** The index did not load: signed out says how to sign in again, as the client's hub does; anything else says why. */
231
215
  function LoadFailed({ loaded }: { loaded: Extract<Loaded, { status: 'error' }> }) {
232
216
  if (!loaded.signedOut)
233
217
  return (
234
- <p className="index-none" role="alert">
218
+ <p className="ix-empty" role="alert">
235
219
  The prototypes did not load: {loaded.message}
236
220
  </p>
237
221
  );
238
222
  return (
239
- <section className="index-empty index-signed-out" role="alert">
223
+ <section className="ix-empty" role="alert">
240
224
  <h2>You are signed out</h2>
241
225
  <p>Reload the page to see how to sign in again.</p>
242
226
  <Button kind="secondary" size="sm" label="Reload" onClick={() => location.reload()} />
@@ -244,49 +228,6 @@ function LoadFailed({ loaded }: { loaded: Extract<Loaded, { status: 'error' }> }
244
228
  );
245
229
  }
246
230
 
247
- function IndexHead({ children }: { children?: ReactNode }) {
248
- // Tested in place, so a base `/` build drops the branch and keeps its bytes.
249
- if (import.meta.env.BASE_URL !== '/') return <BasedHead>{children}</BasedHead>;
250
- return (
251
- <header className="index-head">
252
- <div className="index-head-row">
253
- <h1>Prototypes</h1>
254
- {children}
255
- </div>
256
- <p className="index-voice">
257
- High-fidelity sketches in code, made as we sprint on features and improve the product.
258
- </p>
259
- </header>
260
- );
261
- }
262
-
263
- /**
264
- * The head of a project's hub under its base (`/<project>/`): the way back
265
- * to the client's hub at the host root, then the head as at `/`. Styled
266
- * inline, from kit/ui's button, so the hub's stylesheet stays as it was.
267
- */
268
- function BasedHead({ children }: { children?: ReactNode }) {
269
- return (
270
- <header className="index-head">
271
- <a
272
- className="btn btn-tertiary btn-sm"
273
- href="/"
274
- style={{ alignSelf: 'flex-start', height: 44, marginInlineStart: -10 }}
275
- >
276
- <Icon name="arrow-left" size={16} />
277
- <span className="btn-label">All projects</span>
278
- </a>
279
- <div className="index-head-row">
280
- <h1>Prototypes</h1>
281
- {children}
282
- </div>
283
- <p className="index-voice">
284
- High-fidelity sketches in code, made as we sprint on features and improve the product.
285
- </p>
286
- </header>
287
- );
288
- }
289
-
290
231
  /** Studio's audience controls, outside Client view: the client-facing slugs and the switch. */
291
232
  type AudienceControls = {
292
233
  clientFacing: string[];
@@ -295,314 +236,875 @@ type AudienceControls = {
295
236
  saving: ReadonlySet<string>;
296
237
  } | null;
297
238
 
298
- function IndexList({
299
- entries,
300
- failed,
301
- view,
302
- audience,
303
- head,
304
- }: {
305
- entries: Entry[];
306
- failed: number;
307
- view: Hub['view'];
308
- audience: AudienceControls;
309
- head: ReactNode;
310
- }) {
311
- const { query, setQuery, q, shown, trackFilter } = useIndexFilter(entries);
312
- const [leaving, setLeaving] = useState<string | null>(null);
313
- const [opened, setOpened] = useStoredState<Record<string, boolean>>('index-explorations-open', {});
314
- const [instant, setInstant] = useState(false);
315
- const main = useRef<HTMLElement>(null);
316
- const groups = groupsOf(shown);
317
- const archivedTotal = entries.filter((e) => e.status === 'archived').length;
318
- // A back-forward cache restore brings the faded page back; undo the exit.
239
+ type Filters = { track: string[]; status: string[] };
240
+ const NO_FILTERS: Filters = { track: [], status: [] };
241
+ const toggle = (list: string[], v: string) => (list.includes(v) ? list.filter((x) => x !== v) : [...list, v]);
242
+ const passes = (filters: Filters) => (m: Milestone) =>
243
+ (!filters.track.length || filters.track.includes(m.track)) &&
244
+ (!filters.status.length || filters.status.includes(m.status));
245
+
246
+ /** Each milestone's fold, remembered per browser; a milestone nobody has folded follows `startsFolded`. */
247
+ function useFolds(all: Milestone[]) {
248
+ const [folds, setFolds] = useStoredState<Record<string, boolean>>('index-folds', {});
249
+ const isFolded = (m: Milestone) => folds[m.id] ?? startsFolded(m);
250
+ return {
251
+ isFolded,
252
+ allFolded: all.length > 0 && all.every(isFolded),
253
+ fold: (id: string, to: boolean) => setFolds({ ...folds, [id]: to }),
254
+ foldAll: (to: boolean) => setFolds(Object.fromEntries(all.map((m) => [m.id, to]))),
255
+ };
256
+ }
257
+
258
+ const isSearchKey = (e: KeyboardEvent) => (e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k';
259
+ const modified = (e: KeyboardEvent) => e.metaKey || e.ctrlKey || e.altKey || e.shiftKey;
260
+ const STEP: Record<string, number> = { j: 1, ArrowDown: 1, k: -1, ArrowUp: -1 };
261
+ const OWNS_KEYS =
262
+ 'input, textarea, select, [contenteditable="true"], [role="menu"], [role="listbox"], [role="dialog"]';
263
+ const typing = (e: KeyboardEvent) =>
264
+ Boolean((e.target as HTMLElement).closest?.(OWNS_KEYS)) || Boolean(document.querySelector('.menu'));
265
+
266
+ /**
267
+ * The list's keys, from anywhere on the page: Command or Control with K, or
268
+ * `/`, opens search; J and K, or the arrows, walk every row; Left and Right
269
+ * fold and unfold the milestone in focus. Enter and Space are a row's own.
270
+ */
271
+ function useListKeys(
272
+ list: RefObject<HTMLElement | null>,
273
+ off: boolean,
274
+ onSearch: () => void,
275
+ onFold: (id: string, to: boolean) => void,
276
+ ) {
319
277
  useEffect(() => {
320
- const restore = (e: PageTransitionEvent) => {
321
- if (e.persisted) setLeaving(null);
278
+ const walk = (by: number) => {
279
+ const rows = [...(list.current?.querySelectorAll<HTMLElement>('.ix-row') ?? [])];
280
+ const at = rows.indexOf(document.activeElement as HTMLElement);
281
+ rows[Math.max(0, Math.min(rows.length - 1, at + by))]?.focus();
322
282
  };
323
- addEventListener('pageshow', restore);
324
- return () => removeEventListener('pageshow', restore);
325
- }, []);
283
+ const foldFocused = (to: boolean) => {
284
+ const id = (document.activeElement as HTMLElement | null)?.id ?? '';
285
+ if (id.startsWith('ms-')) onFold(id.slice(3), to);
286
+ return id.startsWith('ms-');
287
+ };
288
+ const plain = (e: KeyboardEvent) => {
289
+ if (e.key === '/') onSearch();
290
+ else if (STEP[e.key]) walk(STEP[e.key]);
291
+ else if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return false;
292
+ else return foldFocused(e.key === 'ArrowLeft');
293
+ return true;
294
+ };
295
+ const onKey = (e: KeyboardEvent) => {
296
+ if (off) return;
297
+ if (isSearchKey(e)) onSearch();
298
+ else if (modified(e) || typing(e) || !plain(e)) return;
299
+ e.preventDefault();
300
+ };
301
+ document.addEventListener('keydown', onKey);
302
+ return () => document.removeEventListener('keydown', onKey);
303
+ });
304
+ }
326
305
 
327
- // Arrows walk the rows; keyboard moves never animate.
328
- const onKeyDown = (e: KeyboardEvent) => {
329
- if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
330
- const rows = Array.from(
331
- main.current?.querySelectorAll<HTMLAnchorElement>('.index-row, .index-fold:not([inert]) .index-card') ??
332
- [],
333
- );
334
- if (!rows.length) return;
335
- const at = rows.indexOf(document.activeElement as HTMLAnchorElement);
336
- const next = e.key === 'ArrowDown' ? Math.min(at + 1, rows.length - 1) : Math.max(at - 1, 0);
337
- rows[next]?.focus();
338
- e.preventDefault();
306
+ /** A milestone's home is the hash, so it has a link and Back closes it. It keeps its last milestone while it fades out. */
307
+ function useHome(route: { home: string | null }, all: Milestone<Entry>[]) {
308
+ const [held, setHeld] = useState<string | null>(null);
309
+ const [instant, setInstant] = useState(true);
310
+ const [full, setFull] = useState(false);
311
+ const open = all.some((m) => m.id === route.home);
312
+ useEffect(() => {
313
+ if (route.home) setHeld(route.home);
314
+ }, [route.home]);
315
+ const id = open ? route.home : held;
316
+ // The row behind the home follows it, and takes focus back once the home has closed and the page is no longer inert.
317
+ const last = useRef<string | null>(null);
318
+ useEffect(() => {
319
+ if (open) {
320
+ last.current = route.home;
321
+ document.getElementById(`ms-${route.home}`)?.scrollIntoView({ block: 'nearest' });
322
+ } else if (last.current) {
323
+ document.getElementById(`ms-${last.current}`)?.focus();
324
+ last.current = null;
325
+ }
326
+ }, [open, route.home]);
327
+ return {
328
+ open,
329
+ instant,
330
+ full,
331
+ current: all.find((m) => m.id === id),
332
+ show: (to: string, byKeyboard: boolean) => {
333
+ setInstant(byKeyboard);
334
+ location.hash = homeHash(to);
335
+ },
336
+ toggleFull: () => setFull((f) => !f),
337
+ close: () => {
338
+ setFull(false);
339
+ location.hash = VIEWS.milestones.href;
340
+ },
339
341
  };
342
+ }
340
343
 
341
- // Pointer opens fade the page while the prototype loads. A keyboard open
342
- // (detail 0) is instant, and a modified click opens elsewhere, so neither fades.
343
- const onOpen = (e: MouseEvent<HTMLAnchorElement>, slug: string) => {
344
- if (e.detail === 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
345
- setLeaving(slug);
344
+ /** What was opened last from this index, remembered per browser, as the entries still listed. */
345
+ function useRecent(entries: Entry[]) {
346
+ const [recent, setRecent] = useStoredState<string[]>('index-recent', []);
347
+ return {
348
+ recent: recent.map((s) => entries.find((e) => e.slug === s)).filter((e): e is Entry => Boolean(e)),
349
+ onOpen: (e: Entry) => setRecent(withRecent(recent, e.slug)),
346
350
  };
351
+ }
347
352
 
348
- // A keyboard toggle (detail 0) opens and closes without motion.
349
- const onToggle = (e: MouseEvent<HTMLButtonElement>, id: string) => {
350
- setInstant(e.detail === 0);
351
- setOpened((o) => ({ ...o, [id]: !o[id] }));
353
+ /** A sidebar jump lands on a milestone's row, from either view and through any filter. */
354
+ function useJump(tab: View, clear: () => void) {
355
+ const pending = useRef<string | null>(null);
356
+ useEffect(() => {
357
+ if (!pending.current || tab !== 'milestones') return;
358
+ const row = document.getElementById(pending.current);
359
+ pending.current = null;
360
+ row?.scrollIntoView({ block: 'start' });
361
+ row?.focus({ preventScroll: true });
362
+ });
363
+ return (id: string) => {
364
+ pending.current = `ms-${id}`;
365
+ clear();
366
+ if (location.hash !== VIEWS.milestones.href) location.hash = VIEWS.milestones.href;
352
367
  };
368
+ }
353
369
 
354
- const rows = (items: Entry[], from: number) =>
355
- items.map((e, i) => (
356
- <li key={e.slug} className="index-rise" style={rise(from + i)}>
357
- <a
358
- className="index-row"
359
- href={`${import.meta.env.BASE_URL}${e.slug}/`}
360
- data-kind={e.kind}
361
- data-chosen={leaving === e.slug || undefined}
362
- onClick={(ev) => onOpen(ev, e.slug)}
363
- >
364
- <span className="index-title">{e.title}</span>
365
- <span className="index-summary">{e.summary}</span>
366
- <EntryMeta entry={e} className="index-meta" />
367
- </a>
368
- <AudienceSwitch entry={e} controls={audience} />
369
- </li>
370
- ));
370
+ function IndexList({
371
+ route,
372
+ hub,
373
+ audience,
374
+ onClientView,
375
+ }: {
376
+ route: Route;
377
+ hub: Hub;
378
+ audience: AudienceControls;
379
+ onClientView: (() => void) | null;
380
+ }) {
381
+ const { entries } = hub;
382
+ const { tab } = route;
383
+ const [filters, setFilters] = useState<Filters>(NO_FILTERS);
384
+ const [order, setOrder] = useStoredState<Order>('index-order', 'updated');
385
+ const [cmd, setCmd] = useState(false);
386
+ const list = useRef<HTMLDivElement>(null);
387
+ const { milestones: all, loose } = milestonesOf(entries);
388
+ const milestones = all.filter(passes(filters)).sort(byOrder(order));
389
+ const tools = entries.filter((e) => e.kind === 'tool');
390
+ const folds = useFolds(all);
391
+ const home = useHome(route, all);
392
+ const { recent, onOpen } = useRecent(entries);
393
+ const clear = () => setFilters(NO_FILTERS);
394
+ const jump = useJump(tab, clear);
395
+ useListKeys(list, cmd || home.open, () => setCmd(true), folds.fold);
396
+
397
+ const switchFor = (e: Entry) => <AudienceSwitch entry={e} controls={audience} />;
398
+ const items = commandItems({
399
+ all,
400
+ entries,
401
+ recent,
402
+ clientView: onClientView ? { on: !audience, toggle: onClientView } : null,
403
+ onOpen,
404
+ onMilestone: (id) => {
405
+ clear();
406
+ home.show(id, true);
407
+ },
408
+ });
409
+ const shared = { hub, route, onOpen };
371
410
 
372
- let slot = 0;
373
411
  return (
374
- <main className={indexClass(leaving, audience)} ref={main} onKeyDown={onKeyDown}>
375
- <IndexHead>{head}</IndexHead>
376
- <TrackFilter {...trackFilter} />
377
- {entries.length > 6 ? (
378
- <label className="index-filter">
379
- <span className="sr-only">Filter prototypes</span>
380
- <input
381
- type="search"
382
- placeholder="Filter"
383
- autoComplete="off"
384
- value={query}
385
- onChange={(e) => setQuery(e.target.value)}
412
+ <>
413
+ <div className="index-frame ix-frame">
414
+ <div className="ix-behind" inert={home.open || cmd || undefined}>
415
+ <IndexRail
416
+ {...shared}
417
+ all={all}
418
+ tools={tools}
419
+ recent={recent}
420
+ onSearch={() => setCmd(true)}
421
+ onJump={jump}
386
422
  />
387
- </label>
388
- ) : null}
389
- <IndexNotes view={view} total={entries.length} failed={failed} />
390
- {groups.map((g) => {
391
- const from = slot;
392
- const alt = from + 1 + g.items.length;
393
- const sub = g.alternates.length ? alt + 1 + g.alternates.length : alt;
394
- const open = Boolean(q || opened[g.id]);
395
- slot = g.explorations.length ? sub + 1 + (open ? g.explorations.length : 0) : sub;
396
- return (
397
- <section key={g.id} aria-labelledby={`group-${g.id}`} className="index-group">
398
- <div className="index-section index-rise" style={rise(from)}>
399
- <h2 id={`group-${g.id}`}>{g.title}</h2>
400
- {g.guide ? (
401
- <a className="index-guide" href={g.guide}>
402
- Walkthrough
403
- <span className="sr-only"> for {g.title}</span>
404
- <Icon name="arrow-right" size={16} />
405
- </a>
406
- ) : null}
407
- </div>
408
- {g.items.length ? <ul className="index-list">{rows(g.items, from + 1)}</ul> : null}
409
- {g.alternates.length ? (
410
- <div className="index-alternates">
411
- <h3
412
- id={`group-${g.id}-alternates`}
413
- className="index-alternates-label index-rise"
414
- style={rise(alt)}
415
- >
416
- Alternates
417
- </h3>
418
- <ul className="index-list" aria-labelledby={`group-${g.id}-alternates`}>
419
- {rows(g.alternates, alt + 1)}
420
- </ul>
421
- </div>
422
- ) : null}
423
- {g.explorations.length ? (
424
- <Explorations
425
- group={g}
426
- at={sub}
427
- open={open}
428
- instant={instant}
429
- leaving={leaving}
430
- audience={audience}
431
- onToggle={(ev) => onToggle(ev, g.id)}
432
- onOpen={onOpen}
423
+ <main className="ix-main">
424
+ <Toolbar
425
+ tab={tab}
426
+ milestones={all}
427
+ filters={filters}
428
+ order={order}
429
+ allFolded={folds.allFolded}
430
+ studio={hub.view === 'studio'}
431
+ onFilters={setFilters}
432
+ onOrder={setOrder}
433
+ onFoldAll={folds.foldAll}
434
+ onClientView={audience ? onClientView : null}
435
+ />
436
+ <div className="ix-list" ref={list}>
437
+ <IndexBody
438
+ {...shared}
439
+ milestones={milestones}
440
+ loose={loose}
441
+ tools={tools}
442
+ filtered={filters.track.length + filters.status.length > 0}
443
+ folds={folds}
444
+ home={home}
445
+ audience={audience ? switchFor : null}
446
+ onClear={clear}
433
447
  />
434
- ) : null}
435
- </section>
436
- );
437
- })}
438
- {entries.length > 0 && shown.length === 0 ? (
439
- <p className="index-none" role="status">
440
- Nothing matches “{query}”.
441
- </p>
442
- ) : null}
443
- {entries.length > 0 ? (
444
- <footer className="index-foot index-rise" style={rise(slot)}>
445
- <p className="tabular">
446
- {plural(entries.length - archivedTotal, 'prototype')}
447
- {archivedTotal ? `, ${plural(archivedTotal, 'archived')}` : ''}
448
- </p>
449
- </footer>
450
- ) : null}
451
- </main>
448
+ </div>
449
+ </main>
450
+ </div>
451
+ </div>
452
+ <HomeLayer {...shared} home={home} order={milestones.map((m) => m.id)} audience={switchFor} />
453
+ {cmd ? <CommandMenu items={items} onClose={() => setCmd(false)} /> : null}
454
+ </>
452
455
  );
453
456
  }
454
457
 
455
- /** A group's explorations, folded away under a toggle until asked for or a search matches them. */
456
- function Explorations({
457
- group,
458
- at,
459
- open,
460
- instant,
461
- leaving,
458
+ type Route = { tab: View; home: string | null };
459
+ type Shared = { hub: Hub; route: Route; onOpen: (e: Entry) => void };
460
+
461
+ /** The sidebar: Search opens the command menu, each milestone is a jump, and what was opened last follows. */
462
+ function IndexRail({
463
+ hub,
464
+ route,
465
+ onOpen,
466
+ all,
467
+ tools,
468
+ recent,
469
+ onSearch,
470
+ onJump,
471
+ }: Shared & {
472
+ all: Milestone[];
473
+ tools: Entry[];
474
+ recent: Entry[];
475
+ onSearch: () => void;
476
+ onJump: (id: string) => void;
477
+ }) {
478
+ const views: View[] = tools.length || route.tab === 'tools' ? ['milestones', 'tools'] : ['milestones'];
479
+ const jumps = all.map((m) => ({ key: m.id, label: m.title, hits: true }));
480
+ return (
481
+ <Sidebar
482
+ back={BACK}
483
+ label="Search"
484
+ onSearch={onSearch}
485
+ views={views.map((v) => ({
486
+ key: v,
487
+ label: VIEWS[v].title,
488
+ href: VIEWS[v].href,
489
+ icon: VIEWS[v].icon,
490
+ current: v === route.tab,
491
+ jumps: v === 'milestones' ? jumps : undefined,
492
+ }))}
493
+ jumpsLabel="Jump to a milestone"
494
+ onJump={onJump}
495
+ recent={recent.map((e) => ({ key: e.slug, label: e.title, href: hrefOf(e), onOpen: () => onOpen(e) }))}
496
+ who={hub.me}
497
+ />
498
+ );
499
+ }
500
+
501
+ /** Under the toolbar: Tools, or the milestones and then the prototypes that belong to none. */
502
+ function IndexBody({
503
+ hub,
504
+ route,
505
+ onOpen,
506
+ milestones,
507
+ loose,
508
+ tools,
509
+ filtered,
510
+ folds,
511
+ home,
462
512
  audience,
463
- onToggle,
513
+ onClear,
514
+ }: Shared & {
515
+ milestones: Milestone<Entry>[];
516
+ loose: Entry[];
517
+ tools: Entry[];
518
+ filtered: boolean;
519
+ folds: ReturnType<typeof useFolds>;
520
+ home: ReturnType<typeof useHome>;
521
+ audience: ListProps['audience'];
522
+ onClear: () => void;
523
+ }) {
524
+ const studio = hub.view === 'studio';
525
+ const onTools = route.tab === 'tools';
526
+ const lists = { studio, onOpen, audience };
527
+ const notes = (
528
+ <IndexNotes
529
+ view={hub.view}
530
+ tab={route.tab}
531
+ total={(onTools ? tools : hub.entries).length}
532
+ failed={hub.failed}
533
+ />
534
+ );
535
+ if (onTools)
536
+ return (
537
+ <>
538
+ {notes}
539
+ <Tools list={tools} {...lists} />
540
+ </>
541
+ );
542
+ if (filtered && !milestones.length) return <NoMatch onClear={onClear} />;
543
+ return (
544
+ <>
545
+ {notes}
546
+ {milestones.map((m) => (
547
+ <MilestoneGroup
548
+ key={m.id}
549
+ m={m}
550
+ studio={studio}
551
+ folded={folds.isFolded(m)}
552
+ current={home.open && route.home === m.id}
553
+ onFold={() => folds.fold(m.id, !folds.isFolded(m))}
554
+ onPeek={(byKeyboard) => home.show(m.id, byKeyboard)}
555
+ onOpen={onOpen}
556
+ />
557
+ ))}
558
+ {loose.length && !filtered ? <Loose list={loose} {...lists} /> : null}
559
+ </>
560
+ );
561
+ }
562
+
563
+ /** The open milestone's home, over the index. */
564
+ function HomeLayer({
565
+ hub,
566
+ onOpen,
567
+ home,
568
+ order,
569
+ audience,
570
+ }: Shared & {
571
+ home: ReturnType<typeof useHome>;
572
+ order: string[];
573
+ audience: (e: Entry) => ReactNode;
574
+ }) {
575
+ const m = home.current;
576
+ return (
577
+ <CenterPeek
578
+ open={home.open}
579
+ instant={home.instant}
580
+ order={order}
581
+ id={m?.id}
582
+ full={home.full}
583
+ onFull={home.toggleFull}
584
+ onStep={(id) => home.show(id, true)}
585
+ onPrimary={() => m?.main && openEntry(m.main, onOpen)}
586
+ onClose={home.close}
587
+ >
588
+ {m ? (
589
+ <MilestoneHome
590
+ m={m}
591
+ studio={hub.view === 'studio'}
592
+ guide={guideFor(m.id)}
593
+ hrefOf={hrefOf}
594
+ onOpen={onOpen}
595
+ audience={audience}
596
+ />
597
+ ) : null}
598
+ </CenterPeek>
599
+ );
600
+ }
601
+
602
+ /** Opening by key, where no link was clicked: the prototype is remembered as recent, then the page goes there. */
603
+ function openEntry(e: Entry, onOpen: (e: Entry) => void) {
604
+ onOpen(e);
605
+ location.assign(hrefOf(e));
606
+ }
607
+
608
+ /** Everything the command menu finds: what was opened last, every milestone, prototype and tool, and Client view. */
609
+ function commandItems({
610
+ all,
611
+ entries,
612
+ recent,
613
+ clientView,
464
614
  onOpen,
615
+ onMilestone,
465
616
  }: {
466
- group: Group;
467
- at: number;
468
- open: boolean;
469
- instant: boolean;
470
- leaving: string | null;
471
- audience: AudienceControls;
472
- onToggle: (e: MouseEvent<HTMLButtonElement>) => void;
473
- onOpen: (e: MouseEvent<HTMLAnchorElement>, slug: string) => void;
617
+ all: Milestone<Entry>[];
618
+ entries: Entry[];
619
+ recent: Entry[];
620
+ clientView: { on: boolean; toggle: () => void } | null;
621
+ onOpen: (e: Entry) => void;
622
+ onMilestone: (id: string) => void;
623
+ }): CommandItem[] {
624
+ const title = (id: string) => all.find((m) => m.id === id)?.title;
625
+ const entry = (group: CommandItem['group']) => (e: Entry) => ({
626
+ id: `${group}-${e.slug}`,
627
+ group,
628
+ label: e.title,
629
+ text: `${e.summary} ${e.slug}`,
630
+ hint: title(e.feature),
631
+ icon: e.kind === 'tool' ? ('sliders-04' as const) : ('grid-01' as const),
632
+ run: () => openEntry(e, onOpen),
633
+ });
634
+ return [
635
+ ...recent.map(entry('Recent')),
636
+ ...all.map((m) => ({
637
+ id: `milestone-${m.id}`,
638
+ group: 'Milestones' as const,
639
+ label: m.title,
640
+ text: m.summary,
641
+ icon: 'target-04' as const,
642
+ run: () => onMilestone(m.id),
643
+ })),
644
+ ...entries.filter((e) => e.kind !== 'tool').map(entry('Prototypes')),
645
+ ...entries.filter((e) => e.kind === 'tool').map(entry('Tools')),
646
+ ...(clientView
647
+ ? [
648
+ {
649
+ id: 'client-view',
650
+ group: 'Actions' as const,
651
+ label: clientView.on ? 'Leave client view' : 'Client view',
652
+ icon: 'briefcase-01' as const,
653
+ run: clientView.toggle,
654
+ },
655
+ ]
656
+ : []),
657
+ ];
658
+ }
659
+
660
+ type Facet = { key: keyof Filters; label: string; values: [string, string][] };
661
+
662
+ /** What the list can be narrowed by: the tracks and statuses its milestones have, each offered only when there are two or more. */
663
+ function facetsOf(milestones: Milestone[], studio: boolean): Facet[] {
664
+ const tracks = TRACKS.filter((t) => milestones.some((m) => m.track === t));
665
+ const statuses = [...new Set(milestones.map((m) => m.status))];
666
+ const facets: Facet[] = [
667
+ { key: 'track', label: 'Track', values: tracks.map((t) => [t, TRACK_LABEL[t as Track]]) },
668
+ { key: 'status', label: 'Status', values: statuses.map((s) => [s, statusLabel(s, studio)]) },
669
+ ];
670
+ return facets.filter((f) => f.values.length > 1);
671
+ }
672
+
673
+ function useFilterMenu(facets: Facet[], filters: Filters, onFilters: (f: Filters) => void) {
674
+ return useMenu({
675
+ label: 'Filter',
676
+ align: 'end',
677
+ width: 220,
678
+ items: facets.flatMap((f) => [
679
+ { heading: f.label },
680
+ ...f.values.map(([value, label]) => ({
681
+ label,
682
+ checked: filters[f.key].includes(value),
683
+ onClick: () => onFilters({ ...filters, [f.key]: toggle(filters[f.key], value) }),
684
+ })),
685
+ ]),
686
+ });
687
+ }
688
+
689
+ function useDisplayMenu(
690
+ order: Order,
691
+ onOrder: (o: Order) => void,
692
+ allFolded: boolean,
693
+ onFoldAll: (to: boolean) => void,
694
+ ) {
695
+ return useMenu({
696
+ label: 'Display',
697
+ align: 'end',
698
+ width: 220,
699
+ items: [
700
+ { heading: 'Order' },
701
+ { label: 'Last updated', checked: order === 'updated', onClick: () => onOrder('updated') },
702
+ { label: 'Name', checked: order === 'name', onClick: () => onOrder('name') },
703
+ '-',
704
+ { label: allFolded ? 'Unfold all' : 'Fold all', onClick: () => onFoldAll(!allFolded) },
705
+ ],
706
+ });
707
+ }
708
+
709
+ function Toolbar({
710
+ tab,
711
+ milestones,
712
+ filters,
713
+ order,
714
+ allFolded,
715
+ studio,
716
+ onFilters,
717
+ onOrder,
718
+ onFoldAll,
719
+ onClientView,
720
+ }: {
721
+ tab: View;
722
+ milestones: Milestone[];
723
+ filters: Filters;
724
+ order: Order;
725
+ allFolded: boolean;
726
+ studio: boolean;
727
+ onFilters: (f: Filters) => void;
728
+ onOrder: (o: Order) => void;
729
+ onFoldAll: (to: boolean) => void;
730
+ /** Studio's way into Client view: the index, and every comment, as a client gets them. */
731
+ onClientView: (() => void) | null;
474
732
  }) {
475
- const foldId = `group-${group.id}-explorations`;
733
+ const facets = facetsOf(milestones, studio);
734
+ const filter = useFilterMenu(facets, filters, onFilters);
735
+ const display = useDisplayMenu(order, onOrder, allFolded, onFoldAll);
736
+ const listing = tab === 'milestones' && milestones.length > 0;
737
+ return (
738
+ <header className="ix-toolbar">
739
+ <div className="ix-toolbar-row">
740
+ <h1>{VIEWS[tab].title}</h1>
741
+ <div className="ix-toolbar-actions">
742
+ {listing ? <ListActions filter={facets.length ? filter : null} display={display} /> : null}
743
+ <ClientViewAction sep={listing} onClientView={onClientView} />
744
+ </div>
745
+ </div>
746
+ {listing ? <Chips facets={facets} filters={filters} onFilters={onFilters} /> : null}
747
+ {filter.menu}
748
+ {display.menu}
749
+ </header>
750
+ );
751
+ }
752
+
753
+ /** Studio's way into Client view, set off from the list's own actions. */
754
+ function ClientViewAction({ sep, onClientView }: { sep: boolean; onClientView: (() => void) | null }) {
755
+ if (!onClientView) return null;
476
756
  return (
477
757
  <>
478
- <h3 id={`${foldId}-title`} className="index-subsection index-rise" style={rise(at)}>
758
+ {sep ? <span className="ix-toolbar-sep" aria-hidden="true" /> : null}
759
+ <Button
760
+ kind="tertiary"
761
+ size="sm"
762
+ icon="briefcase-01"
763
+ iconSize={16}
764
+ label="Client view"
765
+ aria-label="Client view"
766
+ title="See the prototypes as a client does"
767
+ onClick={onClientView}
768
+ />
769
+ </>
770
+ );
771
+ }
772
+
773
+ type MenuHandle = ReturnType<typeof useMenu>;
774
+ /** Filter, when there is something to narrow by, and Display. */
775
+ function ListActions({ filter, display }: { filter: MenuHandle | null; display: MenuHandle }) {
776
+ return (
777
+ <>
778
+ {filter ? (
779
+ <Button
780
+ kind="tertiary"
781
+ size="sm"
782
+ icon="filter-lines"
783
+ iconSize={16}
784
+ label="Filter"
785
+ aria-label="Filter"
786
+ {...filter.triggerProps}
787
+ />
788
+ ) : null}
789
+ <Button
790
+ kind="tertiary"
791
+ size="sm"
792
+ icon="sliders-02"
793
+ iconSize={16}
794
+ label="Display"
795
+ aria-label="Display"
796
+ {...display.triggerProps}
797
+ />
798
+ </>
799
+ );
800
+ }
801
+
802
+ /** Each filter in use, as a chip that removes it. */
803
+ function Chips({
804
+ facets,
805
+ filters,
806
+ onFilters,
807
+ }: {
808
+ facets: Facet[];
809
+ filters: Filters;
810
+ onFilters: (f: Filters) => void;
811
+ }) {
812
+ const active = facets.filter((f) => filters[f.key].length);
813
+ if (!active.length) return null;
814
+ const labelOf = (f: Facet, v: string) => f.values.find(([value]) => value === v)?.[1] ?? v;
815
+ return (
816
+ <div className="ix-chips">
817
+ {active.map((f) => (
818
+ <span key={f.key} className="ix-chip">
819
+ <span className="ix-chip-facet">{f.label}</span>
820
+ {filters[f.key].map((v) => labelOf(f, v)).join(', ')}
821
+ <button
822
+ type="button"
823
+ className="ix-chip-x"
824
+ aria-label={`Remove the ${f.label.toLowerCase()} filter`}
825
+ onClick={() => onFilters({ ...filters, [f.key]: [] })}
826
+ >
827
+ <Icon name="x-close" size={14} />
828
+ </button>
829
+ </span>
830
+ ))}
831
+ <button type="button" className="ix-chips-clear" onClick={() => onFilters(NO_FILTERS)}>
832
+ Clear
833
+ </button>
834
+ </div>
835
+ );
836
+ }
837
+
838
+ /** A milestone is the one row with a home: it opens it. The rows under it are quick links, and each opens what it names. */
839
+ function MilestoneGroup({
840
+ m,
841
+ studio,
842
+ folded,
843
+ current,
844
+ onFold,
845
+ onPeek,
846
+ onOpen,
847
+ }: {
848
+ m: Milestone<Entry>;
849
+ studio: boolean;
850
+ folded: boolean;
851
+ current: boolean;
852
+ onFold: () => void;
853
+ onPeek: (byKeyboard: boolean) => void;
854
+ onOpen: (e: Entry) => void;
855
+ }) {
856
+ const guide = guideFor(m.id);
857
+ return (
858
+ <ul className="ix-rows" aria-label={m.title}>
859
+ <li className="ix-item ix-ms" data-current={current || undefined}>
479
860
  <button
480
861
  type="button"
481
- className="index-fold-toggle"
482
- aria-expanded={open}
483
- aria-controls={foldId}
484
- onClick={onToggle}
862
+ className="ix-fold"
863
+ aria-expanded={!folded}
864
+ aria-label={`${m.title} quick links`}
865
+ title={folded ? 'Show quick links' : 'Hide quick links'}
866
+ onClick={onFold}
485
867
  >
486
- Explorations
487
- <span className="index-fold-count tabular">{group.explorations.length}</span>
488
868
  <Icon name="chevron-down" size={16} />
489
869
  </button>
490
- </h3>
491
- <div
492
- id={foldId}
493
- className="index-fold"
494
- data-open={open || undefined}
495
- data-instant={instant || undefined}
496
- inert={!open}
497
- >
498
- <ul className="index-cards" aria-labelledby={`${foldId}-title`}>
499
- {group.explorations.map((e, i) => (
500
- <li key={e.slug} className="index-rise" style={rise(at + 1 + i)}>
501
- <a
502
- className="index-card"
503
- href={`${import.meta.env.BASE_URL}${e.slug}/`}
504
- data-chosen={leaving === e.slug || undefined}
505
- onClick={(ev) => onOpen(ev, e.slug)}
506
- >
507
- <span className="index-card-head">
508
- <span className="index-title">{e.title}</span>
509
- <Icon name="arrow-right" size={16} />
510
- </span>
511
- <span className="index-summary">{e.summary}</span>
512
- <EntryMeta entry={e} className="index-card-meta" />
513
- </a>
514
- <AudienceSwitch entry={e} controls={audience} />
870
+ <a
871
+ id={`ms-${m.id}`}
872
+ className="ix-row"
873
+ href={homeHash(m.id)}
874
+ aria-haspopup="dialog"
875
+ onClick={(e) => {
876
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
877
+ e.preventDefault();
878
+ onPeek(e.detail === 0);
879
+ }}
880
+ >
881
+ <span className="ix-title">{m.title}</span>
882
+ <span className="ix-status" data-status={m.status}>
883
+ {statusLabel(m.status, studio)}
884
+ </span>
885
+ <time className="ix-date tabular" dateTime={m.updated}>
886
+ {fmtShort(m.updated)}
887
+ </time>
888
+ <span className="ix-cue" aria-hidden="true">
889
+ Open
890
+ <Icon name="arrow-right" size={14} />
891
+ </span>
892
+ </a>
893
+ </li>
894
+ {folded ? null : (
895
+ <>
896
+ {m.main ? (
897
+ <LinkRow
898
+ title={m.main.title}
899
+ note="Main"
900
+ href={hrefOf(m.main)}
901
+ onOpen={() => m.main && onOpen(m.main)}
902
+ />
903
+ ) : null}
904
+ {guide ? <LinkRow title="Guide" href={guide} /> : null}
905
+ {m.live.length ? (
906
+ <li className="ix-item ix-kind" data-child>
907
+ Explorations
515
908
  </li>
909
+ ) : null}
910
+ {m.live.map((e) => (
911
+ <LinkRow
912
+ key={e.slug}
913
+ nested
914
+ title={e.title}
915
+ status={waits(e.status) ? e.status : undefined}
916
+ studio={studio}
917
+ href={hrefOf(e)}
918
+ onOpen={() => onOpen(e)}
919
+ />
516
920
  ))}
517
- </ul>
518
- </div>
519
- </>
921
+ </>
922
+ )}
923
+ </ul>
520
924
  );
521
925
  }
522
926
 
523
- /** One button per track the project's prototypes use, plus All; shown only when there are two or more. */
524
- function TrackFilter({
525
- tracks,
526
- value,
527
- onChange,
927
+ /** A quick link: its title, and at the end either a status that waits on someone or a quiet note. */
928
+ function LinkRow({
929
+ nested,
930
+ title,
931
+ note,
932
+ status,
933
+ studio = true,
934
+ date,
935
+ href,
936
+ onOpen,
937
+ audience,
528
938
  }: {
529
- tracks: Track[];
530
- value: Track | 'all';
531
- onChange: (t: Track | 'all') => void;
939
+ nested?: boolean;
940
+ title: string;
941
+ note?: string;
942
+ status?: string;
943
+ studio?: boolean;
944
+ date?: string;
945
+ href: string;
946
+ onOpen?: () => void;
947
+ /** Studio's switch, for a row with no milestone home to hold it. */
948
+ audience?: ReactNode;
532
949
  }) {
533
- if (tracks.length < 2) return null;
534
- const options: (Track | 'all')[] = ['all', ...tracks];
535
950
  return (
536
- <fieldset className="index-tracks">
537
- <legend className="sr-only">Track</legend>
538
- {options.map((t) => (
539
- <button key={t} type="button" aria-pressed={value === t} onClick={() => onChange(t)}>
540
- {t === 'all' ? 'All' : TRACK_LABEL[t]}
541
- </button>
542
- ))}
543
- </fieldset>
951
+ <li className="ix-item" data-child data-nested={nested || undefined}>
952
+ <a className="ix-row ix-link" href={href} onClick={onOpen}>
953
+ <span className="ix-lead">
954
+ <span className="ix-title">{title}</span>
955
+ </span>
956
+ {status ? (
957
+ <span className="ix-status" data-status={status}>
958
+ {statusLabel(status, studio)}
959
+ </span>
960
+ ) : note ? (
961
+ <span className="ix-note">{note}</span>
962
+ ) : null}
963
+ {date ? (
964
+ <time className="ix-date tabular" dateTime={date}>
965
+ {fmtShort(date)}
966
+ </time>
967
+ ) : null}
968
+ </a>
969
+ {audience}
970
+ </li>
544
971
  );
545
972
  }
546
973
 
547
- function EntryMeta({ entry, className }: { entry: Entry; className: string }) {
974
+ type ListProps = {
975
+ list: Entry[];
976
+ studio: boolean;
977
+ onOpen: (e: Entry) => void;
978
+ /** Studio's switch for one prototype; null outside Studio's view. */
979
+ audience: ((e: Entry) => ReactNode) | null;
980
+ };
981
+
982
+ /** Prototypes that belong to no milestone, as links under their own heading. */
983
+ function Loose({ list, studio, onOpen, audience }: ListProps) {
548
984
  return (
549
- <span className={className}>
550
- {entry.track ? <span>{TRACK_LABEL[entry.track]}</span> : null}
551
- <span>{placeLabel(entry)}</span>
552
- <span className="index-status" data-status={entry.status}>
553
- {entry.status}
554
- </span>
555
- <time dateTime={entry.created} className="tabular">
556
- {fmtDate(entry.created)}
557
- </time>
558
- </span>
985
+ <ul className="ix-rows" aria-labelledby="ix-loose" data-audience={audience ? true : undefined}>
986
+ <li className="ix-item ix-ms">
987
+ <h2 id="ix-loose" className="ix-loose-head">
988
+ No milestone
989
+ </h2>
990
+ </li>
991
+ {list.map((e) => (
992
+ <LinkRow
993
+ key={e.slug}
994
+ title={e.title}
995
+ status={waits(e.status) ? e.status : undefined}
996
+ studio={studio}
997
+ href={hrefOf(e)}
998
+ onOpen={() => onOpen(e)}
999
+ audience={audience?.(e)}
1000
+ />
1001
+ ))}
1002
+ </ul>
559
1003
  );
560
1004
  }
561
1005
 
562
- const indexClass = (leaving: string | null, audience: AudienceControls) =>
563
- ['index', leaving && 'is-leaving', audience && 'has-audience'].filter(Boolean).join(' ');
1006
+ /** Tools are one plain list of links, each with where it stands and when it was made; archived ones follow under their own heading. */
1007
+ function Tools({ list, studio, onOpen, audience }: ListProps) {
1008
+ const rows = (tools: Entry[]) =>
1009
+ tools.map((e) => (
1010
+ <LinkRow
1011
+ key={e.slug}
1012
+ title={e.title}
1013
+ note={statusLabel(e.status, studio)}
1014
+ date={e.created}
1015
+ href={hrefOf(e)}
1016
+ onOpen={() => onOpen(e)}
1017
+ audience={audience?.(e)}
1018
+ />
1019
+ ));
1020
+ const archived = list.filter((e) => e.status === 'archived');
1021
+ const live = list.filter((e) => e.status !== 'archived');
1022
+ return (
1023
+ <>
1024
+ {live.length ? (
1025
+ <ul className="ix-rows ix-tools" aria-label="Tools" data-audience={audience ? true : undefined}>
1026
+ {rows(live)}
1027
+ </ul>
1028
+ ) : null}
1029
+ {archived.length ? (
1030
+ <ul
1031
+ className="ix-rows ix-tools"
1032
+ aria-labelledby="ix-tools-archived"
1033
+ data-audience={audience ? true : undefined}
1034
+ >
1035
+ <li className="ix-item ix-ms">
1036
+ <h2 id="ix-tools-archived" className="ix-loose-head">
1037
+ Archived
1038
+ </h2>
1039
+ </li>
1040
+ {rows(archived)}
1041
+ </ul>
1042
+ ) : null}
1043
+ </>
1044
+ );
1045
+ }
564
1046
 
565
- /** The empty index, or how many prototypes did not load. One that failed to load is never an empty index. */
566
- function IndexNotes({ view, total, failed }: { view: Hub['view']; total: number; failed: number }) {
1047
+ /** The empty view, or how many prototypes did not load. One that failed to load is never an empty index. */
1048
+ function IndexNotes({
1049
+ view,
1050
+ tab,
1051
+ total,
1052
+ failed,
1053
+ }: {
1054
+ view: Hub['view'];
1055
+ tab: View;
1056
+ total: number;
1057
+ failed: number;
1058
+ }) {
567
1059
  const empty = emptyState(view, total + failed);
568
- if (empty) return <EmptyIndex kind={empty} />;
1060
+ if (empty) return <EmptyIndex kind={empty} tab={tab} />;
569
1061
  if (!failed) return null;
570
1062
  return (
571
- <p className="index-none" role="alert">
1063
+ <p className="ix-empty" role="alert">
572
1064
  {plural(failed, 'prototype')} did not load. Reload the page to try again.
573
1065
  </p>
574
1066
  );
575
1067
  }
576
1068
 
577
- /** The empty index: Studio's says how to start one; a Client's, or Client view's, that nothing is shared yet. */
578
- function EmptyIndex({ kind }: { kind: 'studio' | 'client' }) {
1069
+ /** The empty view: Studio's says how to start one; a Client's, or Client view's, that nothing is shared yet. */
1070
+ function EmptyIndex({ kind, tab }: { kind: 'studio' | 'client'; tab: View }) {
1071
+ const tools = tab === 'tools';
579
1072
  return (
580
- <section className="index-empty index-rise" style={rise(0)}>
1073
+ <section className="ix-empty">
581
1074
  {kind === 'studio' ? (
582
1075
  <>
583
- <h2>No prototypes yet</h2>
1076
+ <h2>No {tools ? 'tools' : 'milestones'} yet</h2>
584
1077
  <p>
585
1078
  Write the problem and the one question in a README, then start one with{' '}
586
- <code>pnpm new &lt;slug&gt;</code>.
1079
+ <code>pnpm new &lt;slug&gt;{tools ? ' --tool' : ' --feature <milestone>'}</code>.
587
1080
  </p>
588
1081
  </>
589
1082
  ) : (
590
1083
  <>
591
1084
  <h2>Nothing shared yet</h2>
592
- <p>Prototypes appear here once the studio shares them with you.</p>
1085
+ <p>{tools ? 'Tools' : 'Prototypes'} appear here once the studio shares them with you.</p>
593
1086
  </>
594
1087
  )}
595
1088
  </section>
596
1089
  );
597
1090
  }
598
1091
 
1092
+ function NoMatch({ onClear }: { onClear: () => void }) {
1093
+ return (
1094
+ <section className="ix-empty" role="status">
1095
+ <h2>Nothing matches these filters</h2>
1096
+ <Button kind="secondary" size="sm" label="Clear filters" onClick={onClear} />
1097
+ </section>
1098
+ );
1099
+ }
1100
+
599
1101
  /**
600
- * Studio's switch for one prototype, beside its row and never inside the
601
- * link: the audience in words (Internal in the internal comments' amber),
602
- * and a switch that marks it client-facing. It waits while its save is out.
603
- * Nothing outside Studio's view.
1102
+ * Studio's switch for one prototype, at the end of its row in the milestone's
1103
+ * home and never inside the link: the audience in words (Internal in the
1104
+ * internal comments' amber), and a switch that marks it client-facing. It
1105
+ * waits while its save is out. Nothing outside Studio's view.
604
1106
  */
605
- function AudienceSwitch({ entry, controls }: { entry: Entry; controls: AudienceControls }) {
1107
+ function AudienceSwitch({ entry, controls }: { entry: Entry; controls: AudienceControls }): ReactNode {
606
1108
  if (!controls) return null;
607
1109
  const audience = audienceIn(controls.clientFacing, entry.slug);
608
1110
  const on = audience === 'client';