@milesroxas/design-hub 0.8.1 → 0.9.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/prototype.test.ts +83 -0
- package/core/prototype.ts +84 -0
- package/core/review/model.ts +7 -0
- package/core/review/policy.test.ts +4 -2
- package/core/review/policy.ts +4 -2
- package/core/review/service.test.ts +144 -4
- package/core/review/service.ts +70 -2
- package/core/review/store.ts +6 -0
- package/dist/core/prototype.d.ts +35 -0
- package/dist/core/prototype.js +84 -0
- package/dist/core/review/model.d.ts +2 -0
- package/dist/core/review/model.js +6 -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 +23 -1
- package/dist/core/review/service.js +62 -3
- package/dist/core/review/store.d.ts +6 -0
- package/dist/core/review/store.js +6 -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/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 +8 -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/package.json +4 -3
- package/shell/ClientViewNote.tsx +18 -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/hub.ts +36 -0
- package/shell/main.tsx +39 -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 +50 -3
- package/shell/system.css +5 -0
- package/skills/miles-deploy/SKILL.md +17 -0
- package/skills/miles-new-feature/SKILL.md +1 -1
- package/skills/miles-prototype/SKILL.md +14 -1
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
// The last step of a build, after Vite's own generateBundle work, so the
|
|
3
|
+
// preload lists Vite writes into each entry are final text. Every asset goes
|
|
4
|
+
// where the owners of its content are (vite/boundary.ts), each file that
|
|
5
|
+
// really reads it is pointed at its own owner's copy, and every read that
|
|
6
|
+
// crosses an owner fails the build, naming reader and source.
|
|
7
|
+
//
|
|
8
|
+
// Sources are recorded, never inferred from who reads a file: a stylesheet's
|
|
9
|
+
// CSS modules as each chunk's sheet is written (registry.ts, renderChunk,
|
|
10
|
+
// before Vite moves a CSS-only chunk's sheet onto its importers), an asset's
|
|
11
|
+
// original files, a worker's output as its bundle is written. A file with no
|
|
12
|
+
// record fails the build unless its name is fixed.
|
|
13
|
+
//
|
|
14
|
+
// A real read is one Vite records (a chunk's imports, its importedCss and
|
|
15
|
+
// importedAssets) or a built file's hashed name in another built file's
|
|
16
|
+
// text: a preload list, a stylesheet's url(), an asset URL in a chunk. Files
|
|
17
|
+
// with fixed names (`_p/all.js`, each `entry.js`, `_gate/*`) are never read
|
|
18
|
+
// for that, never moved, and prose that names them is never rewritten.
|
|
19
|
+
import { createHash } from 'node:crypto';
|
|
20
|
+
import { chunkProblems, copyFor, isFixed, ownersOf, placementsOf, readsAcross, relativeTo, repointText, unrecorded, } from './boundary.js';
|
|
21
|
+
const metaOf = (chunk) => chunk.viteMetadata;
|
|
22
|
+
const textOf = (file) => file.type === 'chunk' ? file.code : typeof file.source === 'string' ? file.source : undefined;
|
|
23
|
+
const hash8 = (source) => createHash('sha256').update(source).digest('hex').slice(0, 8);
|
|
24
|
+
/** A chunk's owner by its modules: one prototype's slug, or null. Two are refused by chunkProblems. */
|
|
25
|
+
const chunkOwner = (chunk, o) => ownersOf(o.owner, chunk.moduleIds)[0] ?? null;
|
|
26
|
+
/**
|
|
27
|
+
* One chunk's sheet as a source: its prototype's, when any of its CSS modules
|
|
28
|
+
* is a prototype's (kit CSS bundled into a prototype's chunk is that
|
|
29
|
+
* prototype's content), else the kit's or the hub's. Two chunks writing the
|
|
30
|
+
* same bytes are two sources.
|
|
31
|
+
*/
|
|
32
|
+
function sheetSource({ modules, writer }, o) {
|
|
33
|
+
const owner = ownersOf(o.owner, modules)[0] ?? null;
|
|
34
|
+
const from = modules.find((id) => o.owner(id) === owner) ?? modules[0];
|
|
35
|
+
return { owner, file: relativeTo(o.root, from), writer };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Where an asset's content comes from, as recorded: a stylesheet's CSS
|
|
39
|
+
* modules, a worker's bundle (the kit's), or an asset's original files.
|
|
40
|
+
* Null when nothing was recorded.
|
|
41
|
+
*/
|
|
42
|
+
function sourcesOf(asset, o) {
|
|
43
|
+
const css = o.css.get(asset.fileName);
|
|
44
|
+
// A sheet with no CSS module recorded is no one's, never the hub's: it fails as unrecorded.
|
|
45
|
+
if (css?.length)
|
|
46
|
+
return css.some((w) => !w.modules.length) ? null : css.map((w) => sheetSource(w, o));
|
|
47
|
+
if (o.workers.has(asset.fileName))
|
|
48
|
+
return [{ owner: null, file: asset.fileName }];
|
|
49
|
+
if (!asset.originalFileNames.length)
|
|
50
|
+
return null;
|
|
51
|
+
return asset.originalFileNames.map((f) => {
|
|
52
|
+
const abs = o.inRoot(f);
|
|
53
|
+
return { owner: o.owner(abs), file: relativeTo(o.root, abs) };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** What a file really reads: the chunks it imports, what Vite records it brings in, and built names in its text. */
|
|
57
|
+
function readsOf(file, all) {
|
|
58
|
+
const text = textOf(file);
|
|
59
|
+
const meta = file.type === 'chunk' ? metaOf(file) : undefined;
|
|
60
|
+
const named = new Set([
|
|
61
|
+
...(file.type === 'chunk' ? [...file.imports, ...file.dynamicImports] : []),
|
|
62
|
+
...(meta ? [...meta.importedCss, ...meta.importedAssets] : []),
|
|
63
|
+
]);
|
|
64
|
+
return all.filter((x) => x !== file && (named.has(x.fileName) || (!isFixed(x.fileName) && text?.includes(x.fileName) === true)));
|
|
65
|
+
}
|
|
66
|
+
/** The owner a kept asset reads as: its one source owner, else the hub. */
|
|
67
|
+
const keptOwner = (plan) => {
|
|
68
|
+
const owners = new Set(plan.sources?.map((s) => s.owner));
|
|
69
|
+
return owners.size === 1 ? [...owners][0] : null;
|
|
70
|
+
};
|
|
71
|
+
function readersOf(file, plans, o) {
|
|
72
|
+
if (file.type === 'chunk')
|
|
73
|
+
return [{ file, owner: chunkOwner(file, o), fileName: file.fileName }];
|
|
74
|
+
const plan = plans.get(file.fileName);
|
|
75
|
+
if (plan?.places)
|
|
76
|
+
return plan.places.map((p) => ({ file, owner: p.owner, fileName: p.fileName }));
|
|
77
|
+
return [{ file, owner: plan ? keptOwner(plan) : null, fileName: file.fileName }];
|
|
78
|
+
}
|
|
79
|
+
/** The copy a reader gets of a file it reads, or the problem that it may not read it. */
|
|
80
|
+
function resolveRead(reader, x, plans, o) {
|
|
81
|
+
if (x.type === 'chunk') {
|
|
82
|
+
const owner = chunkOwner(x, o);
|
|
83
|
+
return owner && owner !== reader.owner
|
|
84
|
+
? { problem: readsAcross(reader.fileName, { owner, file: x.fileName }) }
|
|
85
|
+
: {};
|
|
86
|
+
}
|
|
87
|
+
const plan = plans.get(x.fileName);
|
|
88
|
+
if (!plan.sources)
|
|
89
|
+
return {};
|
|
90
|
+
// Not split: it stays where it is, for its one owner.
|
|
91
|
+
const copy = copyFor(plan.places ?? [{ owner: keptOwner(plan), fileName: x.fileName }], reader.owner);
|
|
92
|
+
if (!copy)
|
|
93
|
+
return { problem: readsAcross(reader.fileName, plan.sources.find((s) => s.owner !== reader.owner)) };
|
|
94
|
+
return copy.fileName === x.fileName ? {} : { to: copy.fileName };
|
|
95
|
+
}
|
|
96
|
+
/** Points Vite's record of what a chunk brings in at the copies it now reads. */
|
|
97
|
+
function repointMeta(file, moved) {
|
|
98
|
+
const meta = file.type === 'chunk' ? metaOf(file) : undefined;
|
|
99
|
+
for (const set of meta ? [meta.importedCss, meta.importedAssets] : [])
|
|
100
|
+
for (const [from, to] of moved)
|
|
101
|
+
if (set.delete(from))
|
|
102
|
+
set.add(to);
|
|
103
|
+
}
|
|
104
|
+
/** Every asset's sources and placement. */
|
|
105
|
+
function planAll(all, o) {
|
|
106
|
+
const plans = new Map();
|
|
107
|
+
for (const f of all)
|
|
108
|
+
if (f.type === 'asset') {
|
|
109
|
+
const sources = sourcesOf(f, o);
|
|
110
|
+
plans.set(f.fileName, { sources, places: placementsOf(f.fileName, sources, o.slugs, hash8(f.source)) });
|
|
111
|
+
}
|
|
112
|
+
return plans;
|
|
113
|
+
}
|
|
114
|
+
/** One reader's reads: where each now points, and the problems. */
|
|
115
|
+
function readAll(reader, all, plans, o) {
|
|
116
|
+
const moved = new Map();
|
|
117
|
+
const problems = [];
|
|
118
|
+
for (const x of readsOf(reader.file, all)) {
|
|
119
|
+
const r = resolveRead(reader, x, plans, o);
|
|
120
|
+
if (r.problem)
|
|
121
|
+
problems.push(r.problem);
|
|
122
|
+
if (r.to)
|
|
123
|
+
moved.set(x.fileName, r.to);
|
|
124
|
+
}
|
|
125
|
+
return { moved, problems };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Places every asset by the owners of its content, points each real read at
|
|
129
|
+
* the reader's own copy, and returns every problem: a chunk with two
|
|
130
|
+
* prototypes' modules or outside its folder, a read across owners, and a
|
|
131
|
+
* file with no record of its source and no fixed name.
|
|
132
|
+
* Writes nothing when there is a problem.
|
|
133
|
+
*/
|
|
134
|
+
export function settle(bundle, o, emit) {
|
|
135
|
+
const all = Object.values(bundle);
|
|
136
|
+
const plans = planAll(all, o);
|
|
137
|
+
const problems = all.flatMap((c) => c.type === 'chunk' ? chunkProblems(c.fileName, ownersOf(o.owner, c.moduleIds)) : []);
|
|
138
|
+
for (const [fileName, plan] of plans)
|
|
139
|
+
if (!plan.sources && !isFixed(fileName))
|
|
140
|
+
problems.push(unrecorded(fileName));
|
|
141
|
+
const edits = [];
|
|
142
|
+
for (const file of all)
|
|
143
|
+
for (const reader of readersOf(file, plans, o)) {
|
|
144
|
+
const read = readAll(reader, all, plans, o);
|
|
145
|
+
problems.push(...read.problems);
|
|
146
|
+
edits.push({ reader, moved: read.moved });
|
|
147
|
+
}
|
|
148
|
+
if (problems.length)
|
|
149
|
+
return [...new Set(problems)];
|
|
150
|
+
apply(bundle, edits, plans, emit);
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
/** Writes the plan: each reader's text and record pointed at its copies, new copies emitted, replaced originals removed. */
|
|
154
|
+
function apply(bundle, edits, plans, emit) {
|
|
155
|
+
// Every new text from the original texts first, so a kept copy's edit never leaks into another copy.
|
|
156
|
+
const written = edits.map(({ reader, moved }) => {
|
|
157
|
+
let text = textOf(reader.file);
|
|
158
|
+
for (const [from, to] of moved)
|
|
159
|
+
if (text !== undefined)
|
|
160
|
+
text = repointText(text, reader.fileName, from, to);
|
|
161
|
+
return { reader, moved, text };
|
|
162
|
+
});
|
|
163
|
+
const kept = new Set();
|
|
164
|
+
const copies = [];
|
|
165
|
+
for (const { reader, moved, text } of written) {
|
|
166
|
+
const { file } = reader;
|
|
167
|
+
if (reader.fileName !== file.fileName) {
|
|
168
|
+
copies.push([reader.fileName, text ?? file.source]);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
kept.add(file.fileName);
|
|
172
|
+
repointMeta(file, moved);
|
|
173
|
+
if (text === undefined)
|
|
174
|
+
continue;
|
|
175
|
+
if (file.type === 'chunk')
|
|
176
|
+
file.code = text;
|
|
177
|
+
else
|
|
178
|
+
file.source = text;
|
|
179
|
+
}
|
|
180
|
+
for (const [fileName, plan] of plans)
|
|
181
|
+
if (plan.places && !kept.has(fileName))
|
|
182
|
+
delete bundle[fileName];
|
|
183
|
+
for (const [fileName, source] of copies)
|
|
184
|
+
emit(fileName, source);
|
|
185
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milesroxas/design-hub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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": {
|
|
@@ -70,8 +70,9 @@
|
|
|
70
70
|
"dialkit": "^2.1.0",
|
|
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,18 @@
|
|
|
1
|
+
import { Icon } from '@kit/Icon';
|
|
2
|
+
import { Button } from '@kit/ui';
|
|
3
|
+
import './shell.css';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Client view on: the comment layer's note (shell/review, .rv-viewing), in
|
|
7
|
+
* its words and look, with the one way back. On the index and on a
|
|
8
|
+
* prototype's page that Client view shows as missing.
|
|
9
|
+
*/
|
|
10
|
+
export function ClientViewNote({ onLeave }: { onLeave: () => void }) {
|
|
11
|
+
return (
|
|
12
|
+
<p className="index-viewing sys" role="status">
|
|
13
|
+
<Icon name="briefcase-01" size={14} />
|
|
14
|
+
<span>Client view: prototypes as a client sees them</span>
|
|
15
|
+
<Button kind="tertiary" size={null} className="index-viewing-act" label="Leave" onClick={onLeave} />
|
|
16
|
+
</p>
|
|
17
|
+
);
|
|
18
|
+
}
|
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
|
+
}
|