@milesroxas/design-hub 0.8.1 → 0.10.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/README.md +7 -2
- package/core/controls.test.ts +176 -0
- package/core/controls.ts +195 -0
- package/core/prototype.test.ts +83 -0
- package/core/prototype.ts +84 -0
- package/core/review/model.ts +32 -0
- package/core/review/policy.test.ts +4 -2
- package/core/review/policy.ts +4 -2
- package/core/review/service.test.ts +223 -4
- package/core/review/service.ts +111 -2
- package/core/review/store.ts +13 -0
- package/dist/core/controls.d.ts +55 -0
- package/dist/core/controls.js +174 -0
- package/dist/core/prototype.d.ts +35 -0
- package/dist/core/prototype.js +84 -0
- package/dist/core/review/model.d.ts +13 -0
- package/dist/core/review/model.js +27 -0
- package/dist/core/review/policy.d.ts +1 -1
- package/dist/core/review/policy.js +1 -0
- package/dist/core/review/service.d.ts +50 -1
- package/dist/core/review/service.js +97 -3
- package/dist/core/review/store.d.ts +13 -0
- package/dist/core/review/store.js +13 -0
- package/dist/scripts/guard.d.ts +11 -0
- package/dist/scripts/guard.js +44 -0
- package/dist/scripts/lib/cdp.js +6 -1
- package/dist/scripts/lib/export-smoke.d.ts +18 -0
- package/dist/scripts/lib/export-smoke.js +73 -0
- package/dist/scripts/lib/rules.d.ts +1 -0
- package/dist/scripts/lib/rules.js +1 -0
- package/dist/scripts/new.js +5 -2
- package/dist/scripts/release-check.d.ts +5 -3
- package/dist/scripts/release-check.js +17 -4
- package/dist/scripts/share.d.ts +2 -2
- package/dist/server/api.js +21 -0
- package/dist/server/session.d.ts +5 -1
- package/dist/server/session.js +39 -21
- package/dist/vercel/proxy.js +44 -8
- package/dist/vite/boundary.d.ts +93 -0
- package/dist/vite/boundary.js +218 -0
- package/dist/vite/css-boundary.d.ts +39 -0
- package/dist/vite/css-boundary.js +167 -0
- package/dist/vite/kit.js +15 -6
- package/dist/vite/leaks.d.ts +37 -0
- package/dist/vite/leaks.js +331 -0
- package/dist/vite/plugin.js +2 -1
- package/dist/vite/registry.d.ts +15 -4
- package/dist/vite/registry.js +531 -27
- package/dist/vite/settle.d.ts +27 -0
- package/dist/vite/settle.js +185 -0
- package/kit/Artboard.tsx +21 -8
- package/kit/Space.tsx +4 -3
- package/kit/Variants.tsx +193 -65
- package/kit/ViewTools.tsx +77 -11
- package/kit/audience.ts +85 -0
- package/kit/dials.css +59 -0
- package/kit/dials.tsx +272 -35
- package/kit/harness.css +34 -0
- package/kit/prefs.ts +23 -1
- package/package.json +5 -4
- package/shell/ClientViewNote.tsx +46 -0
- package/shell/Guide.tsx +17 -2
- package/shell/Index.tsx +257 -25
- package/shell/audience.test.ts +63 -0
- package/shell/audience.ts +47 -0
- package/shell/controls.ts +26 -0
- package/shell/hub.ts +36 -0
- package/shell/main.tsx +51 -5
- package/shell/registry.ts +28 -7
- package/shell/registry.virtual.d.ts +12 -4
- package/shell/review/client.ts +16 -4
- package/shell/review/review.css +2 -2
- package/shell/shell.css +54 -3
- package/shell/system.css +5 -0
- package/skills/miles-brand/SKILL.md +11 -1
- package/skills/miles-deploy/SKILL.md +19 -0
- package/skills/miles-new-feature/SKILL.md +1 -1
- package/skills/miles-prototype/SKILL.md +48 -2
package/kit/prefs.ts
CHANGED
|
@@ -22,6 +22,7 @@ const COMMENTS_KEY = 'proto:comments';
|
|
|
22
22
|
const CLIENT_VIEW_KEY = 'proto:client-view';
|
|
23
23
|
|
|
24
24
|
let appearance: Appearance = readAppearance();
|
|
25
|
+
let pinned: 'light' | 'dark' | null = null;
|
|
25
26
|
let commentsHidden = readStored(COMMENTS_KEY) === 'hidden';
|
|
26
27
|
let clientView = readStored(CLIENT_VIEW_KEY) === 'on';
|
|
27
28
|
let forceReduce = false;
|
|
@@ -61,7 +62,8 @@ function subscribe(fn: () => void) {
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
function applyTheme() {
|
|
64
|
-
const
|
|
65
|
+
const shown = pinned ?? appearance;
|
|
66
|
+
const dark = shown === 'dark' || (shown === 'system' && darkQuery.matches);
|
|
65
67
|
// The browser chrome and native controls follow the app's theme, not the OS: the class decides.
|
|
66
68
|
root.style.colorScheme = dark ? 'dark' : 'light';
|
|
67
69
|
document.querySelector('meta[name="theme-color"]')?.setAttribute('content', dark ? '#0c0e12' : '#ffffff');
|
|
@@ -76,6 +78,24 @@ function applyMotion() {
|
|
|
76
78
|
else delete root.dataset.motion;
|
|
77
79
|
}
|
|
78
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Holds the page to one look whatever the person's own theme is, without
|
|
83
|
+
* changing or storing that choice; null lets it go. A `Board` pins the look
|
|
84
|
+
* its files export in, so what is on screen is what `pnpm export` writes.
|
|
85
|
+
*/
|
|
86
|
+
export function pinAppearance(next: 'light' | 'dark' | null) {
|
|
87
|
+
if (next === pinned) return;
|
|
88
|
+
pinned = next;
|
|
89
|
+
applyTheme();
|
|
90
|
+
emit();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The look `?theme=` asks for, when it names one: what an export of this page is written in. */
|
|
94
|
+
export const urlAppearance = (): 'light' | 'dark' | null => {
|
|
95
|
+
const asked = params.get('theme');
|
|
96
|
+
return asked === 'light' || asked === 'dark' ? asked : null;
|
|
97
|
+
};
|
|
98
|
+
|
|
79
99
|
export function setAppearance(next: Appearance) {
|
|
80
100
|
if (next === appearance) return;
|
|
81
101
|
appearance = next;
|
|
@@ -117,6 +137,8 @@ export function setClientView(on: boolean) {
|
|
|
117
137
|
export const isDark = () => root.classList.contains('dark-mode');
|
|
118
138
|
export const prefersReducedMotion = () => root.dataset.motion === 'reduce';
|
|
119
139
|
|
|
140
|
+
/** Client view, for the controls that step aside in it (kit/audience.ts). */
|
|
141
|
+
export const useClientView = () => useSyncExternalStore(subscribe, isClientView);
|
|
120
142
|
export const useAppearance = () => useSyncExternalStore(subscribe, () => appearance);
|
|
121
143
|
export const useDark = () => useSyncExternalStore(subscribe, isDark);
|
|
122
144
|
export const useReducedMotion = () => useSyncExternalStore(subscribe, prefersReducedMotion);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milesroxas/design-hub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the sign-in gate, the kit, and the design-hub CLI. A project installs it and keeps only its prototypes, kit materials and docs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -67,11 +67,12 @@
|
|
|
67
67
|
"@vercel/functions": "^3.10.4",
|
|
68
68
|
"@vitejs/plugin-react": "^6.1.2",
|
|
69
69
|
"axe-core": "^4.14.0",
|
|
70
|
-
"dialkit": "^2.1
|
|
70
|
+
"dialkit": "^2.2.1",
|
|
71
71
|
"marked": "^18.1.2",
|
|
72
72
|
"motion": "^14.6.0",
|
|
73
|
+
"postcss": "^8.5.32",
|
|
73
74
|
"typescript": "^7.0.2",
|
|
74
|
-
"vite": "
|
|
75
|
+
"vite": "~8.3.5"
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
78
|
"react": "^19.3.1",
|
|
@@ -82,6 +83,6 @@
|
|
|
82
83
|
"check": "tsc --noEmit && biome check .",
|
|
83
84
|
"fix": "biome check --write .",
|
|
84
85
|
"test": "node --test \"core/**/*.test.ts\" \"shell/**/*.test.ts\" \"server/**/*.test.ts\" \"scripts/**/*.test.ts\" \"vite/**/*.test.ts\" \"vercel/**/*.test.ts\"",
|
|
85
|
-
"quality": "
|
|
86
|
+
"quality": "mkdir -p .coverage && c=$(mktemp -d .coverage/run-XXXXXX) && if NODE_V8_COVERAGE=$c/v8 pnpm run --silent test > $c/test.log 2>&1; then npx -y fallow@3.38.0 --coverage $c/v8; s=$?; else cat $c/test.log; echo 'pnpm quality: the test step failed; its output is above.' >&2; s=1; fi; rm -rf $c; exit $s"
|
|
86
87
|
}
|
|
87
88
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useControls } from '@kit/audience';
|
|
2
|
+
import { Icon } from '@kit/Icon';
|
|
3
|
+
import { setClientView, useClientView } from '@kit/prefs';
|
|
4
|
+
import { Button } from '@kit/ui';
|
|
5
|
+
import './shell.css';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Client view on: the comment layer's note (shell/review, .rv-viewing), in
|
|
9
|
+
* its words and look, with the one way back. On the index and on a
|
|
10
|
+
* prototype's page that Client view shows as missing.
|
|
11
|
+
*/
|
|
12
|
+
export function ClientViewNote({
|
|
13
|
+
onLeave,
|
|
14
|
+
text = 'Client view: prototypes as a client sees them',
|
|
15
|
+
at,
|
|
16
|
+
}: {
|
|
17
|
+
onLeave: () => void;
|
|
18
|
+
text?: string;
|
|
19
|
+
/** On a prototype's page the note sits at the top: the picker and the comment bar hold the bottom. */
|
|
20
|
+
at?: 'top';
|
|
21
|
+
}) {
|
|
22
|
+
return (
|
|
23
|
+
<p className="index-viewing sys" role="status" data-at={at}>
|
|
24
|
+
<Icon name="briefcase-01" size={14} />
|
|
25
|
+
<span>{text}</span>
|
|
26
|
+
<Button kind="tertiary" size={null} className="index-viewing-act" label="Leave" onClick={onLeave} />
|
|
27
|
+
</p>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* On a prototype's page, for a Studio person in Client view: what the page
|
|
33
|
+
* is showing, and the way back. Client view is entered from the Controls
|
|
34
|
+
* panel or the comment bar; it is left from here, from either of them, or
|
|
35
|
+
* from the index.
|
|
36
|
+
*/
|
|
37
|
+
export function PrototypeClientView() {
|
|
38
|
+
const { person } = useControls();
|
|
39
|
+
const on = useClientView();
|
|
40
|
+
if (!person || !on) return null;
|
|
41
|
+
const leave = () => {
|
|
42
|
+
setClientView(false);
|
|
43
|
+
location.reload();
|
|
44
|
+
};
|
|
45
|
+
return <ClientViewNote onLeave={leave} at="top" text="Client view: this prototype as a client gets it" />;
|
|
46
|
+
}
|
package/shell/Guide.tsx
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Icon } from '@kit/Icon';
|
|
2
2
|
import '@kit/ui/ui.css';
|
|
3
|
+
import { isClientView } from '@kit/prefs';
|
|
3
4
|
import { Suspense, use, useEffect, useState } from 'react';
|
|
4
5
|
import { featureTitle, guideHref } from '../core/feature';
|
|
5
6
|
import type { Doc } from './doc';
|
|
7
|
+
import { loadHub } from './hub';
|
|
6
8
|
import { Boundary, Notice } from './Notice';
|
|
7
|
-
import { featureEntry, guides } from './registry';
|
|
9
|
+
import { type Entry, featureEntry, guides } from './registry';
|
|
8
10
|
import './guide.css';
|
|
9
11
|
|
|
10
12
|
const fmtDate = (iso: string) =>
|
|
@@ -29,6 +31,19 @@ function docOf(feature: string) {
|
|
|
29
31
|
return doc;
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
// The prototype a walkthrough opens, among the ones this person may see; none when the index does not load.
|
|
35
|
+
const openers = new Map<string, Promise<Entry | undefined>>();
|
|
36
|
+
function openerOf(feature: string) {
|
|
37
|
+
let found = openers.get(feature);
|
|
38
|
+
if (!found) {
|
|
39
|
+
found = loadHub(isClientView())
|
|
40
|
+
.then((hub) => featureEntry(hub.entries, feature))
|
|
41
|
+
.catch(() => undefined);
|
|
42
|
+
openers.set(feature, found);
|
|
43
|
+
}
|
|
44
|
+
return found;
|
|
45
|
+
}
|
|
46
|
+
|
|
32
47
|
// /guide/<feature>/ renders docs/sprints/<feature>/guide.md. /guide/ alone
|
|
33
48
|
// opens the only guide when there is one, and lists them otherwise.
|
|
34
49
|
export default function Guide({ feature }: { feature?: string }) {
|
|
@@ -71,7 +86,7 @@ function GuideList() {
|
|
|
71
86
|
// The Markdown is the source; this page is how a reviewer without the repo reads it.
|
|
72
87
|
function GuidePage({ feature }: { feature: string }) {
|
|
73
88
|
const { html, meta, title, toc } = use(docOf(feature));
|
|
74
|
-
const prototype =
|
|
89
|
+
const prototype = use(openerOf(feature));
|
|
75
90
|
const [current, setCurrent] = useState<string | null>(null);
|
|
76
91
|
|
|
77
92
|
useEffect(() => {
|
package/shell/Index.tsx
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { fmtDate, plural } from '@kit/format';
|
|
2
2
|
import { useStoredState } from '@kit/hooks';
|
|
3
3
|
import { Icon } from '@kit/Icon';
|
|
4
|
+
import { isClientView, setClientView } from '@kit/prefs';
|
|
5
|
+
import { Button, Toaster, toast } from '@kit/ui';
|
|
4
6
|
import {
|
|
5
7
|
type CSSProperties,
|
|
6
8
|
type KeyboardEvent,
|
|
7
9
|
type MouseEvent,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
useCallback,
|
|
8
12
|
useDeferredValue,
|
|
9
13
|
useEffect,
|
|
10
14
|
useRef,
|
|
@@ -13,11 +17,19 @@ import {
|
|
|
13
17
|
import { placeLabel } from '../core/catalog';
|
|
14
18
|
import { featureTitle, guideHref } from '../core/feature';
|
|
15
19
|
import { TRACK_LABEL, TRACKS, type Track } from '../core/project';
|
|
16
|
-
import
|
|
20
|
+
import type { Audience } from '../core/review/model';
|
|
21
|
+
import { AUDIENCE_LABEL, audienceIn, emptyState, lensOf, withAudience } from './audience';
|
|
22
|
+
import { ClientViewNote } from './ClientViewNote';
|
|
23
|
+
import { type Hub, loadHub, saveAudience } from './hub';
|
|
24
|
+
import { type Entry, guides } from './registry';
|
|
17
25
|
import './shell.css';
|
|
18
26
|
|
|
27
|
+
// The index is built from the server's answer (shell/hub.ts): Studio's view
|
|
28
|
+
// lists every prototype, a Client's only the client-facing ones. Studio,
|
|
29
|
+
// outside Client view, sees each prototype's audience and a switch for it.
|
|
30
|
+
//
|
|
19
31
|
// One group per feature: its one primary prototype, its alternates on a rail
|
|
20
|
-
// under it, then its
|
|
32
|
+
// under it, then its explorations folded away. A second sprint
|
|
21
33
|
// becomes an alternate, since a feature has one primary. Prototypes with no
|
|
22
34
|
// feature fold into their own group. Archived ones leave their group.
|
|
23
35
|
type Group = {
|
|
@@ -63,7 +75,7 @@ const groupsOf = (list: Entry[]): Group[] => {
|
|
|
63
75
|
};
|
|
64
76
|
|
|
65
77
|
/** The track the index shows, remembered per browser. Only the tracks the prototypes use are offered; a stale choice shows all. */
|
|
66
|
-
function useTrackFilter() {
|
|
78
|
+
function useTrackFilter(entries: Entry[]) {
|
|
67
79
|
const [track, setTrack] = useStoredState<Track | 'all'>('index-track', 'all');
|
|
68
80
|
const tracks = TRACKS.filter((t) => entries.some((e) => e.track === t));
|
|
69
81
|
const inTrack = (e: Entry) => track === 'all' || !tracks.includes(track) || e.track === track;
|
|
@@ -74,25 +86,184 @@ const byQuery = (q: string) => (e: Entry) =>
|
|
|
74
86
|
!q || `${e.title} ${e.summary} ${e.slug}`.toLowerCase().includes(q);
|
|
75
87
|
|
|
76
88
|
/** The filter text and the track, and the entries they leave: the chosen track's, matching the text. */
|
|
77
|
-
function useIndexFilter() {
|
|
89
|
+
function useIndexFilter(entries: Entry[]) {
|
|
78
90
|
const [query, setQuery] = useState('');
|
|
79
91
|
const q = useDeferredValue(query.trim().toLowerCase());
|
|
80
|
-
const { filter, inTrack } = useTrackFilter();
|
|
92
|
+
const { filter, inTrack } = useTrackFilter(entries);
|
|
81
93
|
return { query, setQuery, q, shown: entries.filter(inTrack).filter(byQuery(q)), trackFilter: filter };
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
const RISE_CAP = 8;
|
|
85
97
|
const rise = (i: number) => ({ '--i': Math.min(i, RISE_CAP) }) as CSSProperties;
|
|
86
98
|
|
|
99
|
+
type Loaded = { status: 'loading' } | { status: 'error'; message: string } | { status: 'ready'; hub: Hub };
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The index as the server answers it for this view, and Studio's switch.
|
|
103
|
+
* A switch shows at once and is undone, with a toast, if the save fails.
|
|
104
|
+
* One save at a time per prototype: its switch waits until the answer, so a
|
|
105
|
+
* late failure never undoes a later switch.
|
|
106
|
+
*/
|
|
107
|
+
function useHub(clientView: boolean) {
|
|
108
|
+
const [loaded, setLoaded] = useState<Loaded>({ status: 'loading' });
|
|
109
|
+
const [saving, setSaving] = useState<ReadonlySet<string>>(new Set());
|
|
110
|
+
const busy = useRef(new Set<string>());
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
let current = true;
|
|
113
|
+
setLoaded({ status: 'loading' });
|
|
114
|
+
loadHub(clientView).then(
|
|
115
|
+
(hub) => current && setLoaded({ status: 'ready', hub }),
|
|
116
|
+
(error: Error) => current && setLoaded({ status: 'error', message: error.message }),
|
|
117
|
+
);
|
|
118
|
+
return () => {
|
|
119
|
+
current = false;
|
|
120
|
+
};
|
|
121
|
+
}, [clientView]);
|
|
122
|
+
const mark = useCallback((slug: string, audience: Audience) => {
|
|
123
|
+
setLoaded((l) =>
|
|
124
|
+
l.status === 'ready'
|
|
125
|
+
? {
|
|
126
|
+
status: 'ready',
|
|
127
|
+
hub: { ...l.hub, clientFacing: withAudience(l.hub.clientFacing, slug, audience) },
|
|
128
|
+
}
|
|
129
|
+
: l,
|
|
130
|
+
);
|
|
131
|
+
}, []);
|
|
132
|
+
const onSwitch = useCallback(
|
|
133
|
+
(entry: Entry, audience: Audience) => {
|
|
134
|
+
if (busy.current.has(entry.slug)) return;
|
|
135
|
+
busy.current.add(entry.slug);
|
|
136
|
+
setSaving(new Set(busy.current));
|
|
137
|
+
mark(entry.slug, audience);
|
|
138
|
+
saveAudience(entry.slug, audience)
|
|
139
|
+
.catch((error: Error) => {
|
|
140
|
+
// Only this prototype, back to what it was before this save.
|
|
141
|
+
mark(entry.slug, audience === 'client' ? 'internal' : 'client');
|
|
142
|
+
const as = audience === 'client' ? 'client-facing' : 'internal';
|
|
143
|
+
toast(`Could not mark ${entry.title} ${as}. ${error.message}`, { kind: 'error' });
|
|
144
|
+
})
|
|
145
|
+
.finally(() => {
|
|
146
|
+
busy.current.delete(entry.slug);
|
|
147
|
+
setSaving(new Set(busy.current));
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
[mark],
|
|
151
|
+
);
|
|
152
|
+
return { loaded, onSwitch, saving };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Client view, remembered per browser in kit/prefs (the comment layer reads the same choice). */
|
|
156
|
+
function useClientView(): [boolean, (on: boolean) => void] {
|
|
157
|
+
const [on, setOn] = useState(isClientView);
|
|
158
|
+
const set = useCallback((next: boolean) => {
|
|
159
|
+
setClientView(next);
|
|
160
|
+
setOn(next);
|
|
161
|
+
}, []);
|
|
162
|
+
return [on, set];
|
|
163
|
+
}
|
|
164
|
+
|
|
87
165
|
export function Index() {
|
|
88
|
-
const
|
|
166
|
+
const [clientView, setView] = useClientView();
|
|
167
|
+
const { loaded, onSwitch, saving } = useHub(clientView);
|
|
168
|
+
const lens = loaded.status === 'ready' ? lensOf(loaded.hub.me, loaded.hub.view) : null;
|
|
169
|
+
// Leave stays in reach when the index did not load, so Client view is never a dead end.
|
|
170
|
+
const note = lens ? lens.clientView : loaded.status === 'error' && clientView;
|
|
171
|
+
return (
|
|
172
|
+
<>
|
|
173
|
+
<IndexPage
|
|
174
|
+
loaded={loaded}
|
|
175
|
+
controls={lens?.controls ? { onSwitch, saving } : null}
|
|
176
|
+
head={lens?.controls ? <ClientViewButton onEnter={() => setView(true)} /> : null}
|
|
177
|
+
/>
|
|
178
|
+
{note ? <ClientViewNote onLeave={() => setView(false)} /> : null}
|
|
179
|
+
<Toaster />
|
|
180
|
+
</>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Studio's way into Client view: the index, and every comment, as a client gets them. */
|
|
185
|
+
function ClientViewButton({ onEnter }: { onEnter: () => void }) {
|
|
186
|
+
return (
|
|
187
|
+
<Button
|
|
188
|
+
kind="tertiary"
|
|
189
|
+
size="sm"
|
|
190
|
+
icon="briefcase-01"
|
|
191
|
+
iconSize={16}
|
|
192
|
+
className="index-client-view"
|
|
193
|
+
label="Client view"
|
|
194
|
+
title="See the prototypes as a client does"
|
|
195
|
+
onClick={onEnter}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
type Controls = Omit<NonNullable<AudienceControls>, 'clientFacing'> | null;
|
|
201
|
+
|
|
202
|
+
function IndexPage({ loaded, controls, head }: { loaded: Loaded; controls: Controls; head: ReactNode }) {
|
|
203
|
+
if (loaded.status === 'ready')
|
|
204
|
+
return (
|
|
205
|
+
<IndexList
|
|
206
|
+
entries={loaded.hub.entries}
|
|
207
|
+
failed={loaded.hub.failed}
|
|
208
|
+
view={loaded.hub.view}
|
|
209
|
+
audience={controls ? { ...controls, clientFacing: loaded.hub.clientFacing } : null}
|
|
210
|
+
head={head}
|
|
211
|
+
/>
|
|
212
|
+
);
|
|
213
|
+
return (
|
|
214
|
+
<main className="index" aria-busy={loaded.status === 'loading'}>
|
|
215
|
+
<IndexHead>{head}</IndexHead>
|
|
216
|
+
{loaded.status === 'error' ? (
|
|
217
|
+
<p className="index-none" role="alert">
|
|
218
|
+
The prototypes did not load: {loaded.message}
|
|
219
|
+
</p>
|
|
220
|
+
) : null}
|
|
221
|
+
</main>
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function IndexHead({ children }: { children?: ReactNode }) {
|
|
226
|
+
return (
|
|
227
|
+
<header className="index-head">
|
|
228
|
+
<div className="index-head-row">
|
|
229
|
+
<h1>Prototypes</h1>
|
|
230
|
+
{children}
|
|
231
|
+
</div>
|
|
232
|
+
<p className="index-voice">
|
|
233
|
+
High-fidelity sketches in code, made as we sprint on features and improve the product.
|
|
234
|
+
</p>
|
|
235
|
+
</header>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Studio's audience controls, outside Client view: the client-facing slugs and the switch. */
|
|
240
|
+
type AudienceControls = {
|
|
241
|
+
clientFacing: string[];
|
|
242
|
+
onSwitch: (entry: Entry, audience: Audience) => void;
|
|
243
|
+
/** Prototypes whose switch waits on a save. */
|
|
244
|
+
saving: ReadonlySet<string>;
|
|
245
|
+
} | null;
|
|
246
|
+
|
|
247
|
+
function IndexList({
|
|
248
|
+
entries,
|
|
249
|
+
failed,
|
|
250
|
+
view,
|
|
251
|
+
audience,
|
|
252
|
+
head,
|
|
253
|
+
}: {
|
|
254
|
+
entries: Entry[];
|
|
255
|
+
failed: number;
|
|
256
|
+
view: Hub['view'];
|
|
257
|
+
audience: AudienceControls;
|
|
258
|
+
head: ReactNode;
|
|
259
|
+
}) {
|
|
260
|
+
const { query, setQuery, q, shown, trackFilter } = useIndexFilter(entries);
|
|
89
261
|
const [leaving, setLeaving] = useState<string | null>(null);
|
|
90
262
|
const [opened, setOpened] = useStoredState<Record<string, boolean>>('index-explorations-open', {});
|
|
91
263
|
const [instant, setInstant] = useState(false);
|
|
92
264
|
const main = useRef<HTMLElement>(null);
|
|
93
265
|
const groups = groupsOf(shown);
|
|
94
266
|
const archivedTotal = entries.filter((e) => e.status === 'archived').length;
|
|
95
|
-
|
|
96
267
|
// A back-forward cache restore brings the faded page back; undo the exit.
|
|
97
268
|
useEffect(() => {
|
|
98
269
|
const restore = (e: PageTransitionEvent) => {
|
|
@@ -143,18 +314,14 @@ export function Index() {
|
|
|
143
314
|
<span className="index-summary">{e.summary}</span>
|
|
144
315
|
<EntryMeta entry={e} className="index-meta" />
|
|
145
316
|
</a>
|
|
317
|
+
<AudienceSwitch entry={e} controls={audience} />
|
|
146
318
|
</li>
|
|
147
319
|
));
|
|
148
320
|
|
|
149
321
|
let slot = 0;
|
|
150
322
|
return (
|
|
151
|
-
<main className={leaving
|
|
152
|
-
<
|
|
153
|
-
<h1>Prototypes</h1>
|
|
154
|
-
<p className="index-voice">
|
|
155
|
-
High-fidelity sketches in code, made as we sprint on features and improve the product.
|
|
156
|
-
</p>
|
|
157
|
-
</header>
|
|
323
|
+
<main className={indexClass(leaving, audience)} ref={main} onKeyDown={onKeyDown}>
|
|
324
|
+
<IndexHead>{head}</IndexHead>
|
|
158
325
|
<TrackFilter {...trackFilter} />
|
|
159
326
|
{entries.length > 6 ? (
|
|
160
327
|
<label className="index-filter">
|
|
@@ -168,15 +335,7 @@ export function Index() {
|
|
|
168
335
|
/>
|
|
169
336
|
</label>
|
|
170
337
|
) : null}
|
|
171
|
-
{entries.length
|
|
172
|
-
<section className="index-empty index-rise" style={rise(0)}>
|
|
173
|
-
<h2>No prototypes yet</h2>
|
|
174
|
-
<p>
|
|
175
|
-
Write the problem and the one question in a README, then start one with{' '}
|
|
176
|
-
<code>pnpm new <slug></code>.
|
|
177
|
-
</p>
|
|
178
|
-
</section>
|
|
179
|
-
) : null}
|
|
338
|
+
<IndexNotes view={view} total={entries.length} failed={failed} />
|
|
180
339
|
{groups.map((g) => {
|
|
181
340
|
const from = slot;
|
|
182
341
|
const alt = from + 1 + g.items.length;
|
|
@@ -217,6 +376,7 @@ export function Index() {
|
|
|
217
376
|
open={open}
|
|
218
377
|
instant={instant}
|
|
219
378
|
leaving={leaving}
|
|
379
|
+
audience={audience}
|
|
220
380
|
onToggle={(ev) => onToggle(ev, g.id)}
|
|
221
381
|
onOpen={onOpen}
|
|
222
382
|
/>
|
|
@@ -241,13 +401,14 @@ export function Index() {
|
|
|
241
401
|
);
|
|
242
402
|
}
|
|
243
403
|
|
|
244
|
-
/** A group's
|
|
404
|
+
/** A group's explorations, folded away under a toggle until asked for or a search matches them. */
|
|
245
405
|
function Explorations({
|
|
246
406
|
group,
|
|
247
407
|
at,
|
|
248
408
|
open,
|
|
249
409
|
instant,
|
|
250
410
|
leaving,
|
|
411
|
+
audience,
|
|
251
412
|
onToggle,
|
|
252
413
|
onOpen,
|
|
253
414
|
}: {
|
|
@@ -256,6 +417,7 @@ function Explorations({
|
|
|
256
417
|
open: boolean;
|
|
257
418
|
instant: boolean;
|
|
258
419
|
leaving: string | null;
|
|
420
|
+
audience: AudienceControls;
|
|
259
421
|
onToggle: (e: MouseEvent<HTMLButtonElement>) => void;
|
|
260
422
|
onOpen: (e: MouseEvent<HTMLAnchorElement>, slug: string) => void;
|
|
261
423
|
}) {
|
|
@@ -270,7 +432,7 @@ function Explorations({
|
|
|
270
432
|
aria-controls={foldId}
|
|
271
433
|
onClick={onToggle}
|
|
272
434
|
>
|
|
273
|
-
|
|
435
|
+
Explorations
|
|
274
436
|
<span className="index-fold-count tabular">{group.explorations.length}</span>
|
|
275
437
|
<Icon name="chevron-down" size={16} />
|
|
276
438
|
</button>
|
|
@@ -298,6 +460,7 @@ function Explorations({
|
|
|
298
460
|
<span className="index-summary">{e.summary}</span>
|
|
299
461
|
<EntryMeta entry={e} className="index-card-meta" />
|
|
300
462
|
</a>
|
|
463
|
+
<AudienceSwitch entry={e} controls={audience} />
|
|
301
464
|
</li>
|
|
302
465
|
))}
|
|
303
466
|
</ul>
|
|
@@ -344,3 +507,72 @@ function EntryMeta({ entry, className }: { entry: Entry; className: string }) {
|
|
|
344
507
|
</span>
|
|
345
508
|
);
|
|
346
509
|
}
|
|
510
|
+
|
|
511
|
+
const indexClass = (leaving: string | null, audience: AudienceControls) =>
|
|
512
|
+
['index', leaving && 'is-leaving', audience && 'has-audience'].filter(Boolean).join(' ');
|
|
513
|
+
|
|
514
|
+
/** The empty index, or how many prototypes did not load. One that failed to load is never an empty index. */
|
|
515
|
+
function IndexNotes({ view, total, failed }: { view: Hub['view']; total: number; failed: number }) {
|
|
516
|
+
const empty = emptyState(view, total + failed);
|
|
517
|
+
if (empty) return <EmptyIndex kind={empty} />;
|
|
518
|
+
if (!failed) return null;
|
|
519
|
+
return (
|
|
520
|
+
<p className="index-none" role="alert">
|
|
521
|
+
{plural(failed, 'prototype')} did not load. Reload the page to try again.
|
|
522
|
+
</p>
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** The empty index: Studio's says how to start one; a Client's, or Client view's, that nothing is shared yet. */
|
|
527
|
+
function EmptyIndex({ kind }: { kind: 'studio' | 'client' }) {
|
|
528
|
+
return (
|
|
529
|
+
<section className="index-empty index-rise" style={rise(0)}>
|
|
530
|
+
{kind === 'studio' ? (
|
|
531
|
+
<>
|
|
532
|
+
<h2>No prototypes yet</h2>
|
|
533
|
+
<p>
|
|
534
|
+
Write the problem and the one question in a README, then start one with{' '}
|
|
535
|
+
<code>pnpm new <slug></code>.
|
|
536
|
+
</p>
|
|
537
|
+
</>
|
|
538
|
+
) : (
|
|
539
|
+
<>
|
|
540
|
+
<h2>Nothing shared yet</h2>
|
|
541
|
+
<p>Prototypes appear here once the studio shares them with you.</p>
|
|
542
|
+
</>
|
|
543
|
+
)}
|
|
544
|
+
</section>
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Studio's switch for one prototype, beside its row and never inside the
|
|
550
|
+
* link: the audience in words (Internal in the internal comments' amber),
|
|
551
|
+
* and a switch that marks it client-facing. It waits while its save is out.
|
|
552
|
+
* Nothing outside Studio's view.
|
|
553
|
+
*/
|
|
554
|
+
function AudienceSwitch({ entry, controls }: { entry: Entry; controls: AudienceControls }) {
|
|
555
|
+
if (!controls) return null;
|
|
556
|
+
const audience = audienceIn(controls.clientFacing, entry.slug);
|
|
557
|
+
const on = audience === 'client';
|
|
558
|
+
const waiting = controls.saving.has(entry.slug);
|
|
559
|
+
return (
|
|
560
|
+
<span className="index-audience">
|
|
561
|
+
<span className="index-audience-word" data-audience={audience}>
|
|
562
|
+
{AUDIENCE_LABEL[audience]}
|
|
563
|
+
</span>
|
|
564
|
+
<button
|
|
565
|
+
type="button"
|
|
566
|
+
role="switch"
|
|
567
|
+
aria-checked={on}
|
|
568
|
+
aria-disabled={waiting || undefined}
|
|
569
|
+
aria-label={`Client-facing: ${entry.title}`}
|
|
570
|
+
title={on ? 'Clients can open this prototype' : 'Only the studio can open this prototype'}
|
|
571
|
+
className="index-switch"
|
|
572
|
+
onClick={() => controls.onSwitch(entry, on ? 'internal' : 'client')}
|
|
573
|
+
>
|
|
574
|
+
<span className="index-switch-thumb" aria-hidden="true" />
|
|
575
|
+
</button>
|
|
576
|
+
</span>
|
|
577
|
+
);
|
|
578
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import {
|
|
4
|
+
AUDIENCE_LABEL,
|
|
5
|
+
audienceIn,
|
|
6
|
+
emptyState,
|
|
7
|
+
hiddenFor,
|
|
8
|
+
lensOf,
|
|
9
|
+
slugsFor,
|
|
10
|
+
withAudience,
|
|
11
|
+
} from './audience.ts';
|
|
12
|
+
|
|
13
|
+
const studio = { kind: 'studio' as const };
|
|
14
|
+
const client = { kind: 'client' as const };
|
|
15
|
+
|
|
16
|
+
test('a prototype is client-facing only when the server lists it', () => {
|
|
17
|
+
assert.equal(audienceIn(['a', 'b'], 'a'), 'client');
|
|
18
|
+
assert.equal(audienceIn(['a', 'b'], 'c'), 'internal');
|
|
19
|
+
assert.equal(audienceIn([], 'a'), 'internal');
|
|
20
|
+
assert.deepEqual(AUDIENCE_LABEL, { internal: 'Internal', client: 'Client-facing' });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('switching one prototype changes only it, and switching back restores the list', () => {
|
|
24
|
+
const start = ['b', 'd'];
|
|
25
|
+
const on = withAudience(start, 'c', 'client');
|
|
26
|
+
assert.deepEqual(on, ['b', 'c', 'd']);
|
|
27
|
+
assert.deepEqual(withAudience(on, 'c', 'client'), ['b', 'c', 'd']);
|
|
28
|
+
assert.deepEqual(withAudience(on, 'c', 'internal'), start);
|
|
29
|
+
assert.deepEqual(withAudience(start, 'x', 'internal'), start);
|
|
30
|
+
// The rollback after a failed switch is the switch the other way.
|
|
31
|
+
assert.deepEqual(withAudience(withAudience(start, 'b', 'internal'), 'b', 'client'), start);
|
|
32
|
+
assert.deepEqual(start, ['b', 'd']);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('Studio’s view loads every slug; a Client’s view only the client-facing', () => {
|
|
36
|
+
const all = ['a', 'b', 'c'];
|
|
37
|
+
assert.deepEqual(slugsFor({ view: 'studio', clientFacing: ['b'] }, all), all);
|
|
38
|
+
assert.deepEqual(slugsFor({ view: 'client', clientFacing: ['b'] }, all), ['b']);
|
|
39
|
+
assert.deepEqual(slugsFor({ view: 'client', clientFacing: [] }, all), []);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('Studio’s controls show outside Client view only; the Client view note for Studio only', () => {
|
|
43
|
+
assert.deepEqual(lensOf(studio, 'studio'), { controls: true, clientView: false });
|
|
44
|
+
assert.deepEqual(lensOf(studio, 'client'), { controls: false, clientView: true });
|
|
45
|
+
assert.deepEqual(lensOf(client, 'client'), { controls: false, clientView: false });
|
|
46
|
+
// A Client's stored Client view changes nothing; nobody signed in gets neither.
|
|
47
|
+
assert.deepEqual(lensOf(client, 'studio'), { controls: false, clientView: false });
|
|
48
|
+
assert.deepEqual(lensOf(null, 'studio'), { controls: false, clientView: false });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('the empty index speaks to its view', () => {
|
|
52
|
+
assert.equal(emptyState('studio', 0), 'studio');
|
|
53
|
+
assert.equal(emptyState('client', 0), 'client');
|
|
54
|
+
assert.equal(emptyState('client', 2), null);
|
|
55
|
+
assert.equal(emptyState('studio', 1), null);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('in Client view an internal prototype’s page reads as missing; no answer hides nothing', () => {
|
|
59
|
+
assert.equal(hiddenFor({ view: 'client', clientFacing: ['a'] }, 'b'), true);
|
|
60
|
+
assert.equal(hiddenFor({ view: 'client', clientFacing: ['a'] }, 'a'), false);
|
|
61
|
+
assert.equal(hiddenFor({ view: 'studio', clientFacing: [] }, 'b'), false);
|
|
62
|
+
assert.equal(hiddenFor(null, 'b'), false);
|
|
63
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// What the index decides from the server's answer, kept pure so it is
|
|
2
|
+
// tested (shell/audience.test.ts). The answer is the view the person gets
|
|
3
|
+
// and the client-facing slugs; the server and the gate decide what reaches
|
|
4
|
+
// whom, and nothing here is the boundary.
|
|
5
|
+
import type { Audience, Person, PersonKind } from '../core/review/model';
|
|
6
|
+
|
|
7
|
+
/** The index read (`prototypes`): the view the caller gets, and every client-facing slug. */
|
|
8
|
+
export type HubAnswer = { view: PersonKind; clientFacing: string[] };
|
|
9
|
+
|
|
10
|
+
export const AUDIENCE_LABEL: Record<Audience, string> = { internal: 'Internal', client: 'Client-facing' };
|
|
11
|
+
|
|
12
|
+
export const audienceIn = (clientFacing: readonly string[], slug: string): Audience =>
|
|
13
|
+
clientFacing.includes(slug) ? 'client' : 'internal';
|
|
14
|
+
|
|
15
|
+
/** The client-facing list after one prototype is switched, sorted, each slug once. */
|
|
16
|
+
export function withAudience(clientFacing: readonly string[], slug: string, audience: Audience): string[] {
|
|
17
|
+
const rest = clientFacing.filter((s) => s !== slug);
|
|
18
|
+
return audience === 'client' ? [...rest, slug].sort() : rest;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Which slugs the index loads: every one in Studio's view, only the client-facing in a Client's. */
|
|
22
|
+
export const slugsFor = (answer: HubAnswer, all: readonly string[]): string[] =>
|
|
23
|
+
answer.view === 'studio' ? [...all] : [...answer.clientFacing];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* How the index treats the person: Studio outside Client view sees each
|
|
27
|
+
* prototype's audience and its switch; Studio in Client view sees what a
|
|
28
|
+
* Client sees, with the note to leave it; anyone else sees neither.
|
|
29
|
+
*/
|
|
30
|
+
export function lensOf(me: Pick<Person, 'kind'> | null, view: PersonKind) {
|
|
31
|
+
const studio = me?.kind === 'studio';
|
|
32
|
+
return { controls: studio && view === 'studio', clientView: studio && view === 'client' };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The empty index, by view: Studio's says how to start one; a Client's says nothing is shared yet. Null when not empty. */
|
|
36
|
+
export function emptyState(view: PersonKind, total: number): 'studio' | 'client' | null {
|
|
37
|
+
if (total > 0) return null;
|
|
38
|
+
return view === 'studio' ? 'studio' : 'client';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Whether a prototype's page shows as missing: in Client view (or for a
|
|
43
|
+
* Client), when the prototype is not client-facing. No answer hides nothing,
|
|
44
|
+
* since the gate already refused it to a Client.
|
|
45
|
+
*/
|
|
46
|
+
export const hiddenFor = (answer: HubAnswer | null, slug: string): boolean =>
|
|
47
|
+
!!answer && answer.view === 'client' && !answer.clientFacing.includes(slug);
|