@milesroxas/design-hub 0.11.2 → 0.13.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 (87) hide show
  1. package/README.md +8 -6
  2. package/core/prototype.test.ts +52 -0
  3. package/core/prototype.ts +59 -0
  4. package/core/review/model.ts +20 -0
  5. package/core/review/service.test.ts +262 -37
  6. package/core/review/service.ts +276 -52
  7. package/core/review/store.ts +12 -6
  8. package/core/review/suite-kv.ts +17 -0
  9. package/dist/core/prototype.d.ts +50 -0
  10. package/dist/core/prototype.js +38 -0
  11. package/dist/core/review/model.d.ts +22 -0
  12. package/dist/core/review/model.js +8 -0
  13. package/dist/core/review/service.d.ts +98 -18
  14. package/dist/core/review/service.js +248 -46
  15. package/dist/core/review/store.d.ts +10 -4
  16. package/dist/core/review/store.js +2 -2
  17. package/dist/core/review/suite-kv.d.ts +7 -0
  18. package/dist/core/review/suite-kv.js +12 -0
  19. package/dist/scripts/client.d.ts +3 -3
  20. package/dist/scripts/client.js +55 -69
  21. package/dist/scripts/lib/cli.js +5 -0
  22. package/dist/scripts/lib/dns.d.ts +32 -0
  23. package/dist/scripts/lib/dns.js +69 -1
  24. package/dist/scripts/lib/fake-host.d.ts +35 -11
  25. package/dist/scripts/lib/fake-host.js +27 -13
  26. package/dist/scripts/lib/host.d.ts +13 -25
  27. package/dist/scripts/lib/host.js +15 -324
  28. package/dist/scripts/lib/studio-deps.d.ts +16 -0
  29. package/dist/scripts/lib/studio-deps.js +41 -16
  30. package/dist/scripts/lib/studios.d.ts +17 -5
  31. package/dist/scripts/lib/studios.js +25 -5
  32. package/dist/scripts/lib/vercel-host.d.ts +17 -0
  33. package/dist/scripts/lib/vercel-host.js +410 -0
  34. package/dist/scripts/people.d.ts +7 -4
  35. package/dist/scripts/people.js +147 -39
  36. package/dist/scripts/share.js +3 -2
  37. package/dist/scripts/studio.d.ts +10 -4
  38. package/dist/scripts/studio.js +136 -22
  39. package/dist/server/api.d.ts +12 -13
  40. package/dist/server/api.js +141 -52
  41. package/dist/server/gate.d.ts +97 -0
  42. package/dist/server/gate.js +537 -0
  43. package/dist/server/hosts.d.ts +3 -3
  44. package/dist/server/hosts.js +10 -10
  45. package/dist/server/mark.d.ts +17 -0
  46. package/dist/server/mark.js +46 -1
  47. package/dist/server/session.d.ts +9 -1
  48. package/dist/server/session.js +10 -3
  49. package/dist/server/stores/backends.d.ts +22 -0
  50. package/dist/server/stores/backends.js +96 -0
  51. package/dist/server/{fake-upstash.js → stores/fake-upstash.js} +1 -1
  52. package/dist/server/stores/index.d.ts +41 -0
  53. package/dist/server/stores/index.js +63 -0
  54. package/dist/server/stores/pglite.d.ts +16 -0
  55. package/dist/server/stores/pglite.js +98 -0
  56. package/dist/server/stores/postgres.d.ts +63 -0
  57. package/dist/server/stores/postgres.js +153 -0
  58. package/dist/server/{upstash.d.ts → stores/upstash.d.ts} +1 -1
  59. package/dist/vercel/files.js +1 -1
  60. package/dist/vercel/proxy.d.ts +6 -78
  61. package/dist/vercel/proxy.js +18 -359
  62. package/dist/vite/plugin.d.ts +6 -2
  63. package/dist/vite/plugin.js +22 -4
  64. package/package.json +3 -1
  65. package/shell/Index.tsx +29 -0
  66. package/shell/review/People.tsx +79 -49
  67. package/shell/review/Review.tsx +49 -1
  68. package/shell/review/ThreadCard.tsx +13 -1
  69. package/shell/review/client.ts +54 -21
  70. package/shell/review/review.css +1 -0
  71. package/shell/review/unsent.test.ts +63 -0
  72. package/shell/review/unsent.ts +64 -0
  73. package/shell/review/view.ts +22 -6
  74. package/shell/studio/ClientHub.tsx +9 -36
  75. package/shell/studio/StudioHub.tsx +293 -0
  76. package/shell/studio/hub.css +80 -5
  77. package/shell/studio/page.tsx +57 -0
  78. package/shell/studio/studio.html +14 -0
  79. package/shell/studio/studio.tsx +19 -0
  80. package/skills/miles-deploy/SKILL.md +17 -6
  81. package/skills/miles-design-hub/SKILL.md +3 -3
  82. package/skills/miles-review/SKILL.md +1 -1
  83. package/templates/studio/.env.example +3 -0
  84. package/templates/studio/README.md +45 -13
  85. package/templates/studio/package.json +1 -1
  86. /package/dist/server/{fake-upstash.d.ts → stores/fake-upstash.d.ts} +0 -0
  87. /package/dist/server/{upstash.js → stores/upstash.js} +0 -0
@@ -10,11 +10,11 @@ import { createRequire } from 'node:module';
10
10
  import { dirname, join } from 'node:path';
11
11
  import react from '@vitejs/plugin-react';
12
12
  import { build, searchForWorkspaceRoot } from 'vite';
13
- import { isProjectSlug } from '../core/prototype.js';
13
+ import { isProjectSlug, STUDIO_DIR, STUDIO_PAGE } from '../core/prototype.js';
14
14
  import { devReview } from '../server/dev.js';
15
15
  import { devPort, readEnv } from '../server/env.js';
16
+ import { GATE_FONT, gatePreview } from '../server/gate.js';
16
17
  import { PACKAGE, PACKAGE_KIT, SHELL } from '../server/paths.js';
17
- import { GATE_FONT, gatePreview } from '../vercel/proxy.js';
18
18
  import { kitResolver } from './kit.js';
19
19
  import { lapse } from './lapse.js';
20
20
  import { markdownDocs } from './markdown.js';
@@ -113,8 +113,10 @@ export async function buildHub(options) {
113
113
  /**
114
114
  * A studio site's build (its `build.mjs`): the client hub from
115
115
  * `shell/studio/`, the gate's font at the host root where the gate pages ask
116
- * for it, and the favicon. `root` is the studio folder; it keeps no kit, so
117
- * `@kit/*` is the package's.
116
+ * for it, and the favicon; then, beside them, the studio hub
117
+ * (`shell/studio/studio.html`), its page at STUDIO_PAGE and its bundle
118
+ * below STUDIO_DIR, which only the studio's own host serves. `root` is the
119
+ * studio folder; it keeps no kit, so `@kit/*` is the package's.
118
120
  */
119
121
  export function studioConfig(root) {
120
122
  return {
@@ -129,6 +131,22 @@ export function studioConfig(root) {
129
131
  build: { outDir: join(root, 'dist'), emptyOutDir: true },
130
132
  };
131
133
  }
134
+ /** The studio hub's build, after studioConfig's into the same `dist/`: its own page and bundle, nothing shared with the client hub's. */
135
+ export function studioHubConfig(root) {
136
+ const config = studioConfig(root);
137
+ return {
138
+ ...config,
139
+ publicDir: false,
140
+ plugins: [react(), kitResolver(join(root, 'kit'), PACKAGE_KIT)],
141
+ build: {
142
+ outDir: join(root, 'dist'),
143
+ emptyOutDir: false,
144
+ assetsDir: STUDIO_DIR,
145
+ rollupOptions: { input: join(SHELL, 'studio', STUDIO_PAGE.slice(1)) },
146
+ },
147
+ };
148
+ }
132
149
  export const buildStudio = async (root) => {
133
150
  await build(studioConfig(root));
151
+ await build(studioHubConfig(root));
134
152
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milesroxas/design-hub",
3
- "version": "0.11.2",
3
+ "version": "0.13.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": {
@@ -72,10 +72,12 @@
72
72
  "marked": "^18.1.2",
73
73
  "motion": "^14.6.0",
74
74
  "postcss": "^8.5.32",
75
+ "postgres": "3.4.9",
75
76
  "typescript": "^7.0.2",
76
77
  "vite": "~8.3.5"
77
78
  },
78
79
  "devDependencies": {
80
+ "@electric-sql/pglite": "0.5.16",
79
81
  "react": "^19.3.1",
80
82
  "react-dom": "^19.3.1"
81
83
  },
package/shell/Index.tsx CHANGED
@@ -245,6 +245,8 @@ function LoadFailed({ loaded }: { loaded: Extract<Loaded, { status: 'error' }> }
245
245
  }
246
246
 
247
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>;
248
250
  return (
249
251
  <header className="index-head">
250
252
  <div className="index-head-row">
@@ -258,6 +260,33 @@ function IndexHead({ children }: { children?: ReactNode }) {
258
260
  );
259
261
  }
260
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
+
261
290
  /** Studio's audience controls, outside Client view: the client-facing slugs and the switch. */
262
291
  type AudienceControls = {
263
292
  clientFacing: string[];
@@ -4,7 +4,7 @@
4
4
  // out everywhere, a change of access length, and Revoke.
5
5
  import { fmtDate } from '@kit/format';
6
6
  import { Button, Select } from '@kit/ui';
7
- import { type FormEvent, type ReactNode, useId, useRef, useState } from 'react';
7
+ import { createContext, type FormEvent, type ReactNode, useContext, useId, useRef, useState } from 'react';
8
8
  import { type Access, LIMITS, LINK_DAYS, type PersonKind } from '../../core/review/model';
9
9
  import { Action } from './Card';
10
10
  import { act, type Me, type ReviewStore } from './client';
@@ -30,26 +30,55 @@ const LENGTH_OPTIONS: { value: Access; label: string }[] = [
30
30
  { value: 'open', label: ACCESS_NAMES.open },
31
31
  ];
32
32
 
33
+ /** The class every select's popup carries: the review panel's harness material, unless the page says otherwise. */
34
+ const MenuClass = createContext('rv-menu');
35
+
33
36
  /** The add form's choices: the default for this kind first, then each length. */
34
- function accessOptions(kind: PersonKind, projectDefault: Access | null) {
37
+ function accessOptions(kind: PersonKind, clientDefault: Access | null) {
35
38
  const fallback =
36
- kind === 'studio' ? 'Open-ended for Studio' : `Project default: ${ACCESS_NAMES[projectDefault ?? '3m']}`;
39
+ kind === 'studio' ? 'Open-ended for Studio' : `Client default: ${ACCESS_NAMES[clientDefault ?? '3m']}`;
37
40
  return [{ value: 'default', label: 'Default', desc: fallback }, ...LENGTH_OPTIONS];
38
41
  }
39
42
 
43
+ /** The People ops the card calls: the review store's, wherever it runs. */
44
+ type PeopleStore = Pick<ReviewStore, 'addPerson' | 'newLink' | 'signOut' | 'setAccess' | 'revoke'>;
45
+
46
+ /** Who the form adds: a choice of kind, or the one kind a section holds (`only`), with no choice shown. */
47
+ function KindField({ kind, onKind }: { kind: PersonKind; onKind: (k: PersonKind) => void }) {
48
+ const kindLabel = useId();
49
+ const menu = useContext(MenuClass);
50
+ return (
51
+ <div className="field">
52
+ <span id={kindLabel} className="field-label">
53
+ Kind
54
+ </span>
55
+ <Select
56
+ labelId={kindLabel}
57
+ menuClassName={menu}
58
+ value={kind}
59
+ options={KIND_OPTIONS}
60
+ onChange={(next) => onKind(next as PersonKind)}
61
+ />
62
+ </div>
63
+ );
64
+ }
65
+
40
66
  function AddForm({
41
67
  store,
42
- projectDefault,
68
+ clientDefault,
69
+ only,
43
70
  onLink,
44
71
  }: {
45
- store: ReviewStore;
46
- projectDefault: Access | null;
72
+ store: PeopleStore;
73
+ clientDefault: Access | null;
74
+ only?: PersonKind;
47
75
  onLink: (link: Link) => void;
48
76
  }) {
49
- const [kind, setKind] = useState<PersonKind>('client');
77
+ const [chosen, setKind] = useState<PersonKind>('client');
78
+ const kind = only ?? chosen;
79
+ const menu = useContext(MenuClass);
50
80
  const [access, setAccess] = useState('default');
51
81
  const [busy, setBusy] = useState(false);
52
- const kindLabel = useId();
53
82
  const accessLabel = useId();
54
83
  const add = (e: FormEvent<HTMLFormElement>) => {
55
84
  e.preventDefault();
@@ -80,27 +109,16 @@ function AddForm({
80
109
  data-autofocus=""
81
110
  />
82
111
  </label>
83
- <div className="field">
84
- <span id={kindLabel} className="field-label">
85
- Kind
86
- </span>
87
- <Select
88
- labelId={kindLabel}
89
- menuClassName="rv-menu"
90
- value={kind}
91
- options={KIND_OPTIONS}
92
- onChange={(next) => setKind(next as PersonKind)}
93
- />
94
- </div>
112
+ {only ? null : <KindField kind={kind} onKind={setKind} />}
95
113
  <div className="field">
96
114
  <span id={accessLabel} className="field-label">
97
115
  Access
98
116
  </span>
99
117
  <Select
100
118
  labelId={accessLabel}
101
- menuClassName="rv-menu"
119
+ menuClassName={menu}
102
120
  value={access}
103
- options={accessOptions(kind, projectDefault)}
121
+ options={accessOptions(kind, clientDefault)}
104
122
  onChange={setAccess}
105
123
  />
106
124
  </div>
@@ -180,8 +198,9 @@ function Confirm({
180
198
  );
181
199
  }
182
200
 
183
- function AccessPicker({ person, store, onDone }: { person: Me; store: ReviewStore; onDone: () => void }) {
201
+ function AccessPicker({ person, store, onDone }: { person: Me; store: PeopleStore; onDone: () => void }) {
184
202
  const label = useId();
203
+ const menu = useContext(MenuClass);
185
204
  return (
186
205
  <>
187
206
  <span id={label} className="rv-confirm">
@@ -189,7 +208,7 @@ function AccessPicker({ person, store, onDone }: { person: Me; store: ReviewStor
189
208
  </span>
190
209
  <Select
191
210
  labelId={label}
192
- menuClassName="rv-menu"
211
+ menuClassName={menu}
193
212
  value={null}
194
213
  placeholder="Choose"
195
214
  options={LENGTH_OPTIONS}
@@ -200,7 +219,7 @@ function AccessPicker({ person, store, onDone }: { person: Me; store: ReviewStor
200
219
  );
201
220
  }
202
221
 
203
- type RowProps = { person: Me; store: ReviewStore; onLink: (link: Link) => void };
222
+ type RowProps = { person: Me; store: PeopleStore; onLink: (link: Link) => void };
204
223
 
205
224
  function PersonActions({ person, store, onLink, setMode }: RowProps & { setMode: (m: Mode) => void }) {
206
225
  const linked = (pending: Promise<string>) =>
@@ -256,41 +275,52 @@ function PersonRow({ person, store, onLink }: RowProps) {
256
275
  return <div className="rv-row rv-acts">{views[mode]()}</div>;
257
276
  }
258
277
 
278
+ /**
279
+ * `only` fixes the kind the form adds, for a list that holds one kind (the
280
+ * studio hub's sections); `menuClassName` is the class of every select's
281
+ * popup, the review panel's harness material unless a page gives its own.
282
+ */
259
283
  export function People({
260
284
  store,
261
285
  me,
262
286
  people,
263
287
  access,
288
+ only,
289
+ menuClassName = 'rv-menu',
264
290
  }: {
265
- store: ReviewStore;
291
+ store: PeopleStore;
266
292
  me: Me | null;
267
293
  people: Me[] | null;
268
294
  access: Access | null;
295
+ only?: PersonKind;
296
+ menuClassName?: string;
269
297
  }) {
270
298
  const [link, setLink] = useState<Link | null>(null);
271
299
  return (
272
- <div className="rv-body">
273
- <AddForm store={store} projectDefault={access} onLink={setLink} />
274
- {/* Keyed by the link, so a second one starts on Copy again. */}
275
- {link && <ShareLink key={link.href} link={link} />}
276
- <HowLinksWork />
277
- {people === null ? (
278
- <p className="rv-muted">Loading people…</p>
279
- ) : (
280
- <ul className="rv-people">
281
- {people.map((p) => (
282
- <li key={p.id} data-revoked={p.revokedAt ? '' : undefined}>
283
- <div className="rv-person">
284
- <strong>{p.name}</strong>
285
- <span className="rv-muted">
286
- {p.team} · {KIND_NAMES[p.kind]} · {p.revokedAt ? 'revoked' : accessText(p)}
287
- </span>
288
- </div>
289
- {p.id !== me?.id && !p.revokedAt && <PersonRow person={p} store={store} onLink={setLink} />}
290
- </li>
291
- ))}
292
- </ul>
293
- )}
294
- </div>
300
+ <MenuClass.Provider value={menuClassName}>
301
+ <div className="rv-body">
302
+ <AddForm store={store} clientDefault={access} only={only} onLink={setLink} />
303
+ {/* Keyed by the link, so a second one starts on Copy again. */}
304
+ {link && <ShareLink key={link.href} link={link} />}
305
+ <HowLinksWork />
306
+ {people === null ? (
307
+ <p className="rv-muted">Loading people…</p>
308
+ ) : (
309
+ <ul className="rv-people">
310
+ {people.map((p) => (
311
+ <li key={p.id} data-revoked={p.revokedAt ? '' : undefined}>
312
+ <div className="rv-person">
313
+ <strong>{p.name}</strong>
314
+ <span className="rv-muted">
315
+ {p.team} · {KIND_NAMES[p.kind]} · {p.revokedAt ? 'revoked' : accessText(p)}
316
+ </span>
317
+ </div>
318
+ {p.id !== me?.id && !p.revokedAt && <PersonRow person={p} store={store} onLink={setLink} />}
319
+ </li>
320
+ ))}
321
+ </ul>
322
+ )}
323
+ </div>
324
+ </MenuClass.Provider>
295
325
  );
296
326
  }
@@ -22,6 +22,7 @@ import { describe, draftPoint, PickLayer } from './PickLayer';
22
22
  import { Pins } from './Pins';
23
23
  import { DEFAULT_SPOT, isSpot, type Spot } from './snap';
24
24
  import { ThreadCard } from './ThreadCard';
25
+ import { keptOn, takeUnsent } from './unsent';
25
26
  import {
26
27
  type Draft,
27
28
  draftOf,
@@ -29,6 +30,7 @@ import {
29
30
  filterNote,
30
31
  initialView,
31
32
  lensOf,
33
+ replyOf,
32
34
  roundOf,
33
35
  scopeOf,
34
36
  stepTarget,
@@ -109,10 +111,30 @@ function useView(store: ReviewStore): [View, Dispatch<ViewAction>] {
109
111
  return [v, dispatch];
110
112
  }
111
113
 
114
+ /**
115
+ * Once signed in, a comment kept when the session ended mid-send (unsent.ts)
116
+ * comes back, to the person who wrote it on this page only, once: its thread
117
+ * opens with the reply in the box, or a new comment on the whole page opens
118
+ * with the words in it (the spot it was pinned to is not kept). Anything
119
+ * else kept is dropped.
120
+ */
121
+ function useResume(s: Pick<State, 'status' | 'me'>, dispatch: Dispatch<ViewAction>) {
122
+ const me = s.status === 'ready' ? (s.me?.id ?? null) : null;
123
+ useEffect(() => {
124
+ if (!me) return;
125
+ const kept = takeUnsent(me, location.pathname);
126
+ if (!kept) return;
127
+ if (kept.thread) return dispatch({ type: 'open', id: kept.thread, body: kept.body });
128
+ dispatch({ type: 'start' });
129
+ dispatch({ type: 'draft', draft: { target: null, offset: null, body: kept.body } });
130
+ }, [me, dispatch]);
131
+ }
132
+
112
133
  export function Review({ prototype, feature, states }: Props) {
113
134
  const store = useMemo(() => createReviewStore(prototype), [prototype]);
114
135
  const s = useReviewState(store);
115
136
  const [v, dispatch] = useView(store);
137
+ useResume(s, dispatch);
116
138
  const [spot, setSpot] = useSpot();
117
139
  const url = useCurrentUrl();
118
140
 
@@ -152,16 +174,36 @@ export function Review({ prototype, feature, states }: Props) {
152
174
  );
153
175
  }
154
176
 
177
+ /** Where a kept comment comes back, in plain words. */
178
+ const KEPT = {
179
+ reply: 'Your reply is kept in this tab. Reload once you are signed in and it comes back in its thread.',
180
+ comment:
181
+ 'Your comment is kept in this tab. Reload once you are signed in and it comes back as a comment on the whole page, not pinned.',
182
+ };
183
+
155
184
  /**
156
185
  * The session ended after the page loaded (a revoke, a sign out everywhere,
157
186
  * or the end of their access): comment mode is this card and nothing else.
187
+ * Reload picks up a session signed in since, in another tab; a comment the
188
+ * send lost is kept in this tab for then, and the card says where it comes back.
158
189
  */
159
190
  function GuestCard({ onClose }: { onClose: () => void }) {
191
+ const kept = keptOn(location.pathname);
160
192
  return (
161
193
  <Card at={null} label="Comments" onDismiss={onClose}>
162
194
  <div className="rv-note">
163
195
  <strong>You are signed out</strong>
164
- <p>Ask the studio for a new link to read and leave comments.</p>
196
+ <p>
197
+ Ask the studio for a new link to read and leave comments. Signed in again in another tab? Reload.
198
+ </p>
199
+ {kept ? <p>{kept.reply ? KEPT.reply : KEPT.comment}</p> : null}
200
+ <Button
201
+ kind="secondary"
202
+ size={null}
203
+ className="rv-note-act"
204
+ label="Reload"
205
+ onClick={() => location.reload()}
206
+ />
165
207
  </div>
166
208
  </Card>
167
209
  );
@@ -223,6 +265,7 @@ function Commenting({ store, s: real, v, dispatch, url, where, states, roots }:
223
265
  store={store}
224
266
  s={s}
225
267
  root={current}
268
+ reply={replyOf(v.card)}
226
269
  round={round}
227
270
  mark={lens.asStudio}
228
271
  url={url}
@@ -327,6 +370,7 @@ function OpenThread({
327
370
  store,
328
371
  s,
329
372
  root,
373
+ reply,
330
374
  round,
331
375
  mark,
332
376
  url,
@@ -338,6 +382,8 @@ function OpenThread({
338
382
  store: ReviewStore;
339
383
  s: State;
340
384
  root: Comment;
385
+ /** A reply given back after a reload, which the box starts with. */
386
+ reply?: string;
341
387
  round: Comment[];
342
388
  mark: boolean;
343
389
  url: string;
@@ -354,6 +400,7 @@ function OpenThread({
354
400
  me={s.me}
355
401
  scope={pageScope(s)}
356
402
  root={root}
403
+ reply={reply}
357
404
  replies={s.comments.filter((c) => c.thread === root.id && c.id !== root.id)}
358
405
  mark={mark}
359
406
  index={round.indexOf(root)}
@@ -446,6 +493,7 @@ function DraftCard({
446
493
  label="New comment"
447
494
  placeholder="Add a comment"
448
495
  send="Post"
496
+ initial={draft.body}
449
497
  autoFocus
450
498
  onSend={async (body) => {
451
499
  const anchor = captureAnchor(where, draft.target, draftPoint(draft));
@@ -343,11 +343,13 @@ function Stepper({ index, total, onStep }: { index: number; total: number; onSte
343
343
  function Foot({
344
344
  store,
345
345
  root,
346
+ reply,
346
347
  confirming,
347
348
  onKeep,
348
349
  }: {
349
350
  store: ReviewStore;
350
351
  root: Comment;
352
+ reply?: string;
351
353
  confirming: boolean;
352
354
  onKeep: () => void;
353
355
  }) {
@@ -366,6 +368,7 @@ function Foot({
366
368
  label={`Reply to ${root.author.name}`}
367
369
  placeholder="Reply"
368
370
  send="Reply"
371
+ initial={reply}
369
372
  autoFocus
370
373
  onSend={(body) => store.reply(root.id, body)}
371
374
  />
@@ -455,6 +458,7 @@ export function ThreadCard({
455
458
  me,
456
459
  scope,
457
460
  root,
461
+ reply,
458
462
  replies,
459
463
  mark,
460
464
  index,
@@ -469,6 +473,8 @@ export function ThreadCard({
469
473
  me: Me | null;
470
474
  scope: Scope;
471
475
  root: Comment;
476
+ /** A reply given back after a reload (unsent.ts), which the reply box starts with. */
477
+ reply?: string;
472
478
  replies: Comment[];
473
479
  mark: boolean;
474
480
  index: number;
@@ -512,7 +518,13 @@ export function ThreadCard({
512
518
  <Entry key={r.id} store={store} me={me} scope={scope} root={root} comment={r} />
513
519
  ))}
514
520
  </div>
515
- <Foot store={store} root={root} confirming={confirming} onKeep={() => setConfirming(false)} />
521
+ <Foot
522
+ store={store}
523
+ root={root}
524
+ reply={reply}
525
+ confirming={confirming}
526
+ onKeep={() => setConfirming(false)}
527
+ />
516
528
  </Card>
517
529
  );
518
530
  }
@@ -6,6 +6,7 @@
6
6
  // what the server sent for this person: nothing here filters it.
7
7
  import { useSyncExternalStore } from 'react';
8
8
  import type { Access, Anchor, Audience, Comment, Person, PersonKind, Scope } from '../../core/review/model';
9
+ import { keepUnsent } from './unsent';
9
10
  import { afterFailure, signedOutState } from './view';
10
11
 
11
12
  export type Me = Omit<Person, 'epoch'>;
@@ -104,7 +105,13 @@ export const signedOut = (error: unknown) => error instanceof ApiError && error.
104
105
  export const noApi = (error: unknown) =>
105
106
  isOff(error) || (error instanceof ApiError && error.notJson && !signedOut(error));
106
107
 
107
- export function createReviewStore(prototype: string) {
108
+ /**
109
+ * `client` is the studio hub's: the client whose people a section manages,
110
+ * sent with every people op, which the studio's own host checks. None on a
111
+ * client's host, whose API never reads it, and none for the studio's own people.
112
+ */
113
+ export function createReviewStore(prototype: string, client?: string) {
114
+ const at: Record<string, string> = client ? { client } : {};
108
115
  let state: State = {
109
116
  status: 'loading',
110
117
  me: null,
@@ -148,7 +155,23 @@ export function createReviewStore(prototype: string) {
148
155
  throw error;
149
156
  }
150
157
  };
151
- /** A command that answers with a person and their link: merges the person, resolves to the whole URL. */
158
+ /**
159
+ * A new comment or a reply: met by a 401, its words are kept in this tab,
160
+ * with who wrote them and the page, for after a reload (unsent.ts). Who is
161
+ * read now: the 401 signs the store out before the send settles.
162
+ */
163
+ const sending = <T>(thread: string | null, body: string, pending: Promise<T>) => {
164
+ const person = state.me?.id ?? null;
165
+ return pending.catch((error: unknown) => {
166
+ if (person && signedOut(error)) keepUnsent({ person, path: location.pathname, thread, body });
167
+ throw error;
168
+ });
169
+ };
170
+ /**
171
+ * A command that answers with a person and their link: merges the person,
172
+ * resolves to the whole URL. A client's host answers a path at its root; the
173
+ * studio's own host answers the whole link, on the host it signs in on.
174
+ */
152
175
  const linkOf = (pending: Promise<{ person: Me; link: string }>) =>
153
176
  attempt(async () => {
154
177
  const r = await pending;
@@ -184,21 +207,29 @@ export function createReviewStore(prototype: string) {
184
207
 
185
208
  /** A new thread; `audience` is Studio's choice, and the server sets a Client's whatever is sent. */
186
209
  add: (body: string, anchor: Anchor, states: string[], audience: Audience | null) =>
187
- attempt(async () =>
188
- merge(
189
- (
190
- await call<{ comment: Comment }>('comment.add', {
191
- body,
192
- anchor,
193
- states,
194
- ...(audience ? { audience } : {}),
195
- })
196
- ).comment,
210
+ sending(
211
+ null,
212
+ body,
213
+ attempt(async () =>
214
+ merge(
215
+ (
216
+ await call<{ comment: Comment }>('comment.add', {
217
+ body,
218
+ anchor,
219
+ states,
220
+ ...(audience ? { audience } : {}),
221
+ })
222
+ ).comment,
223
+ ),
197
224
  ),
198
225
  ),
199
226
  reply: (thread: string, body: string) =>
200
- attempt(async () =>
201
- merge((await call<{ comment: Comment }>('comment.reply', { prototype, thread, body })).comment),
227
+ sending(
228
+ thread,
229
+ body,
230
+ attempt(async () =>
231
+ merge((await call<{ comment: Comment }>('comment.reply', { prototype, thread, body })).comment),
232
+ ),
202
233
  ),
203
234
  edit: (id: string, body: string) =>
204
235
  attempt(async () =>
@@ -223,23 +254,25 @@ export function createReviewStore(prototype: string) {
223
254
  loadPeople: () =>
224
255
  attempt(async () => {
225
256
  const [{ people }, { access }] = await Promise.all([
226
- call<{ people: Me[] }>('people'),
227
- call<{ access: Access }>('access'),
257
+ call<{ people: Me[] }>('people', undefined, at),
258
+ call<{ access: Access }>('access', undefined, at),
228
259
  ]);
229
260
  set({ people, access });
230
261
  }),
231
262
  /** A new person; `access` null takes the default for their kind. Resolves to their link. */
232
263
  /** The server names their team: the studio's for Studio, the client's for a Client. */
233
264
  addPerson: (name: string, kind: PersonKind, access: Access | null) =>
234
- linkOf(call('people.add', { name, kind, ...(access ? { access } : {}) })),
265
+ linkOf(call('people.add', { name, kind, ...(access ? { access } : {}), ...at })),
235
266
  /** Another one-time link, for another device. */
236
- newLink: (id: string) => linkOf(call('people.link', { id })),
267
+ newLink: (id: string) => linkOf(call('people.link', { id, ...at })),
237
268
  /** Ends every session and unused link; resolves to the one new link. */
238
- signOut: (id: string) => linkOf(call('people.signOut', { id })),
269
+ signOut: (id: string) => linkOf(call('people.signOut', { id, ...at })),
239
270
  setAccess: (id: string, access: Access) =>
240
- attempt(async () => mergePerson((await call<{ person: Me }>('people.access', { id, access })).person)),
271
+ attempt(async () =>
272
+ mergePerson((await call<{ person: Me }>('people.access', { id, access, ...at })).person),
273
+ ),
241
274
  revoke: (id: string) =>
242
- attempt(async () => mergePerson((await call<{ person: Me }>('people.revoke', { id })).person)),
275
+ attempt(async () => mergePerson((await call<{ person: Me }>('people.revoke', { id, ...at })).person)),
243
276
  clearError: () => set({ error: null }),
244
277
  };
245
278
  }
@@ -476,6 +476,7 @@
476
476
 
477
477
  .rv-note { display: flex; flex-direction: column; gap: 4px; padding: 16px; }
478
478
  .rv-note strong { color: var(--rv-fg-strong); font-weight: 600; }
479
+ .rv-note .rv-note-act { align-self: flex-start; margin-top: 8px; }
479
480
 
480
481
  /* Text actions: 28px tall, the fill showing only under the pointer. */
481
482
  .rv .btn.rv-act { height: 28px; padding: 0 8px; color: var(--harness-fg-muted); }