@milesroxas/design-hub 0.11.1 → 0.12.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 (60) hide show
  1. package/README.md +4 -2
  2. package/core/prototype.test.ts +52 -0
  3. package/core/prototype.ts +59 -0
  4. package/core/review/model.ts +32 -3
  5. package/core/review/service.test.ts +240 -0
  6. package/core/review/service.ts +281 -50
  7. package/core/review/store.ts +10 -4
  8. package/dist/core/prototype.d.ts +50 -0
  9. package/dist/core/prototype.js +38 -0
  10. package/dist/core/review/model.d.ts +25 -1
  11. package/dist/core/review/model.js +18 -2
  12. package/dist/core/review/service.d.ts +98 -16
  13. package/dist/core/review/service.js +254 -45
  14. package/dist/core/review/store.d.ts +10 -4
  15. package/dist/scripts/client.d.ts +3 -3
  16. package/dist/scripts/client.js +52 -66
  17. package/dist/scripts/lib/dns.d.ts +32 -0
  18. package/dist/scripts/lib/dns.js +69 -1
  19. package/dist/scripts/lib/fake-host.d.ts +34 -9
  20. package/dist/scripts/lib/fake-host.js +7 -4
  21. package/dist/scripts/lib/review.d.ts +5 -2
  22. package/dist/scripts/lib/review.js +8 -2
  23. package/dist/scripts/lib/studios.d.ts +3 -1
  24. package/dist/scripts/lib/studios.js +2 -0
  25. package/dist/scripts/people.d.ts +8 -5
  26. package/dist/scripts/people.js +152 -41
  27. package/dist/scripts/share.js +1 -1
  28. package/dist/scripts/studio.d.ts +3 -3
  29. package/dist/scripts/studio.js +100 -10
  30. package/dist/server/api.d.ts +6 -8
  31. package/dist/server/api.js +129 -42
  32. package/dist/server/hosts.d.ts +3 -3
  33. package/dist/server/hosts.js +10 -10
  34. package/dist/server/session.d.ts +7 -0
  35. package/dist/server/session.js +8 -1
  36. package/dist/vercel/proxy.d.ts +7 -3
  37. package/dist/vercel/proxy.js +215 -49
  38. package/dist/vite/plugin.d.ts +6 -2
  39. package/dist/vite/plugin.js +21 -3
  40. package/package.json +1 -1
  41. package/shell/Index.tsx +29 -0
  42. package/shell/review/People.tsx +80 -61
  43. package/shell/review/Review.tsx +49 -1
  44. package/shell/review/ThreadCard.tsx +13 -1
  45. package/shell/review/client.ts +56 -22
  46. package/shell/review/review.css +1 -0
  47. package/shell/review/unsent.test.ts +63 -0
  48. package/shell/review/unsent.ts +64 -0
  49. package/shell/review/view.ts +22 -6
  50. package/shell/studio/ClientHub.tsx +9 -36
  51. package/shell/studio/StudioHub.tsx +293 -0
  52. package/shell/studio/hub.css +80 -5
  53. package/shell/studio/page.tsx +57 -0
  54. package/shell/studio/studio.html +14 -0
  55. package/shell/studio/studio.tsx +19 -0
  56. package/skills/miles-deploy/SKILL.md +16 -6
  57. package/skills/miles-design-hub/SKILL.md +3 -3
  58. package/skills/miles-review/SKILL.md +1 -1
  59. package/templates/studio/README.md +32 -13
  60. package/templates/studio/package.json +1 -1
@@ -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();
@@ -59,7 +88,7 @@ function AddForm({
59
88
  setBusy(true);
60
89
  act(
61
90
  store
62
- .addPerson(name, String(f.get('team') ?? ''), kind, access === 'default' ? null : (access as Access))
91
+ .addPerson(name, kind, access === 'default' ? null : (access as Access))
63
92
  .then((href) => {
64
93
  onLink({ name, href });
65
94
  form.reset();
@@ -80,38 +109,16 @@ function AddForm({
80
109
  data-autofocus=""
81
110
  />
82
111
  </label>
83
- <label className="field">
84
- <span className="field-label">Team</span>
85
- <input
86
- className="input"
87
- name="team"
88
- required
89
- maxLength={LIMITS.team}
90
- autoComplete="off"
91
- placeholder="Studio, or the client’s company"
92
- />
93
- </label>
94
- <div className="field">
95
- <span id={kindLabel} className="field-label">
96
- Kind
97
- </span>
98
- <Select
99
- labelId={kindLabel}
100
- menuClassName="rv-menu"
101
- value={kind}
102
- options={KIND_OPTIONS}
103
- onChange={(next) => setKind(next as PersonKind)}
104
- />
105
- </div>
112
+ {only ? null : <KindField kind={kind} onKind={setKind} />}
106
113
  <div className="field">
107
114
  <span id={accessLabel} className="field-label">
108
115
  Access
109
116
  </span>
110
117
  <Select
111
118
  labelId={accessLabel}
112
- menuClassName="rv-menu"
119
+ menuClassName={menu}
113
120
  value={access}
114
- options={accessOptions(kind, projectDefault)}
121
+ options={accessOptions(kind, clientDefault)}
115
122
  onChange={setAccess}
116
123
  />
117
124
  </div>
@@ -191,8 +198,9 @@ function Confirm({
191
198
  );
192
199
  }
193
200
 
194
- function AccessPicker({ person, store, onDone }: { person: Me; store: ReviewStore; onDone: () => void }) {
201
+ function AccessPicker({ person, store, onDone }: { person: Me; store: PeopleStore; onDone: () => void }) {
195
202
  const label = useId();
203
+ const menu = useContext(MenuClass);
196
204
  return (
197
205
  <>
198
206
  <span id={label} className="rv-confirm">
@@ -200,7 +208,7 @@ function AccessPicker({ person, store, onDone }: { person: Me; store: ReviewStor
200
208
  </span>
201
209
  <Select
202
210
  labelId={label}
203
- menuClassName="rv-menu"
211
+ menuClassName={menu}
204
212
  value={null}
205
213
  placeholder="Choose"
206
214
  options={LENGTH_OPTIONS}
@@ -211,7 +219,7 @@ function AccessPicker({ person, store, onDone }: { person: Me; store: ReviewStor
211
219
  );
212
220
  }
213
221
 
214
- type RowProps = { person: Me; store: ReviewStore; onLink: (link: Link) => void };
222
+ type RowProps = { person: Me; store: PeopleStore; onLink: (link: Link) => void };
215
223
 
216
224
  function PersonActions({ person, store, onLink, setMode }: RowProps & { setMode: (m: Mode) => void }) {
217
225
  const linked = (pending: Promise<string>) =>
@@ -267,41 +275,52 @@ function PersonRow({ person, store, onLink }: RowProps) {
267
275
  return <div className="rv-row rv-acts">{views[mode]()}</div>;
268
276
  }
269
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
+ */
270
283
  export function People({
271
284
  store,
272
285
  me,
273
286
  people,
274
287
  access,
288
+ only,
289
+ menuClassName = 'rv-menu',
275
290
  }: {
276
- store: ReviewStore;
291
+ store: PeopleStore;
277
292
  me: Me | null;
278
293
  people: Me[] | null;
279
294
  access: Access | null;
295
+ only?: PersonKind;
296
+ menuClassName?: string;
280
297
  }) {
281
298
  const [link, setLink] = useState<Link | null>(null);
282
299
  return (
283
- <div className="rv-body">
284
- <AddForm store={store} projectDefault={access} onLink={setLink} />
285
- {/* Keyed by the link, so a second one starts on Copy again. */}
286
- {link && <ShareLink key={link.href} link={link} />}
287
- <HowLinksWork />
288
- {people === null ? (
289
- <p className="rv-muted">Loading people…</p>
290
- ) : (
291
- <ul className="rv-people">
292
- {people.map((p) => (
293
- <li key={p.id} data-revoked={p.revokedAt ? '' : undefined}>
294
- <div className="rv-person">
295
- <strong>{p.name}</strong>
296
- <span className="rv-muted">
297
- {p.team} · {KIND_NAMES[p.kind]} · {p.revokedAt ? 'revoked' : accessText(p)}
298
- </span>
299
- </div>
300
- {p.id !== me?.id && !p.revokedAt && <PersonRow person={p} store={store} onLink={setLink} />}
301
- </li>
302
- ))}
303
- </ul>
304
- )}
305
- </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>
306
325
  );
307
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,22 +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
- addPerson: (name: string, team: string, kind: PersonKind, access: Access | null) =>
233
- linkOf(call('people.add', { name, team, kind, ...(access ? { access } : {}) })),
263
+ /** The server names their team: the studio's for Studio, the client's for a Client. */
264
+ addPerson: (name: string, kind: PersonKind, access: Access | null) =>
265
+ linkOf(call('people.add', { name, kind, ...(access ? { access } : {}), ...at })),
234
266
  /** Another one-time link, for another device. */
235
- newLink: (id: string) => linkOf(call('people.link', { id })),
267
+ newLink: (id: string) => linkOf(call('people.link', { id, ...at })),
236
268
  /** Ends every session and unused link; resolves to the one new link. */
237
- signOut: (id: string) => linkOf(call('people.signOut', { id })),
269
+ signOut: (id: string) => linkOf(call('people.signOut', { id, ...at })),
238
270
  setAccess: (id: string, access: Access) =>
239
- 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
+ ),
240
274
  revoke: (id: string) =>
241
- attempt(async () => mergePerson((await call<{ person: Me }>('people.revoke', { id })).person)),
275
+ attempt(async () => mergePerson((await call<{ person: Me }>('people.revoke', { id, ...at })).person)),
242
276
  clearError: () => set({ error: null }),
243
277
  };
244
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); }
@@ -0,0 +1,63 @@
1
+ import assert from 'node:assert/strict';
2
+ import { beforeEach, test } from 'node:test';
3
+ import { keepUnsent, keptOn, takeUnsent } from './unsent.ts';
4
+ import { draftOf, initialView, replyOf, view } from './view.ts';
5
+
6
+ // A tab's sessionStorage, as the browser gives it.
7
+ const store = new Map<string, string>();
8
+ Object.assign(globalThis, {
9
+ sessionStorage: {
10
+ getItem: (k: string) => store.get(k) ?? null,
11
+ setItem: (k: string, v: string) => store.set(k, v),
12
+ removeItem: (k: string) => store.delete(k),
13
+ },
14
+ });
15
+ beforeEach(() => store.clear());
16
+
17
+ const PAGE = '/rebrand/open-plan/';
18
+ const kept = { person: 'ed', path: PAGE, thread: null, body: 'Internal: the grid is off' };
19
+
20
+ test('a kept comment comes back only to the person who wrote it, on the page it was written on', () => {
21
+ keepUnsent(kept);
22
+ assert.deepEqual(takeUnsent('ed', PAGE), kept);
23
+ // Once: it is taken out as it comes back.
24
+ assert.equal(takeUnsent('ed', PAGE), null);
25
+ });
26
+
27
+ test('another person signing in in the tab, or another page, gets nothing, and the comment is dropped', () => {
28
+ keepUnsent(kept);
29
+ assert.equal(takeUnsent('rae', PAGE), null);
30
+ assert.equal(takeUnsent('ed', PAGE), null, 'dropped for its writer too');
31
+ // A same-named prototype of another project is another page.
32
+ keepUnsent(kept);
33
+ assert.equal(takeUnsent('ed', '/launch/open-plan/'), null);
34
+ assert.equal(takeUnsent('ed', PAGE), null);
35
+ });
36
+
37
+ test('the signed-out card reads whether a comment or a reply is kept for this page, without taking it', () => {
38
+ assert.equal(keptOn(PAGE), null);
39
+ keepUnsent(kept);
40
+ assert.deepEqual(keptOn(PAGE), { reply: false });
41
+ assert.equal(keptOn('/launch/open-plan/'), null);
42
+ keepUnsent({ ...kept, thread: 't1' });
43
+ assert.deepEqual(keptOn(PAGE), { reply: true });
44
+ assert.equal(takeUnsent('ed', PAGE)?.thread, 't1');
45
+ });
46
+
47
+ test('a value this page did not write, or no storage at all, keeps nothing and throws nothing', () => {
48
+ store.set('proto:unsent', '{"prototype":"open-plan","thread":null,"body":"x"}');
49
+ assert.equal(keptOn(PAGE), null);
50
+ assert.equal(takeUnsent('ed', PAGE), null);
51
+ store.set('proto:unsent', 'not json');
52
+ assert.equal(takeUnsent('ed', PAGE), null);
53
+ });
54
+
55
+ test('words given back fill one box once: the card that opens with them, and no card after it', () => {
56
+ const draft = view(initialView(false), { type: 'draft', draft: { target: null, offset: null, body: 'x' } });
57
+ assert.equal(draftOf(draft.card)?.body, 'x');
58
+ const next = view(view(draft, { type: 'close' }), { type: 'draft', draft: { target: null, offset: null } });
59
+ assert.equal(draftOf(next.card)?.body, undefined);
60
+ const reply = view(initialView(false), { type: 'open', id: 't1', body: 'y' });
61
+ assert.equal(replyOf(reply.card), 'y');
62
+ assert.equal(replyOf(view(view(reply, { type: 'escape' }), { type: 'open', id: 't1' }).card), undefined);
63
+ });
@@ -0,0 +1,64 @@
1
+ // A comment someone wrote and sent just as their session ended: the send
2
+ // met a 401, the panel signed out, and the words would be gone. It is kept
3
+ // in this tab (sessionStorage) with who wrote it and the page it was written
4
+ // on, and given back once, after a reload, only to that person on that page.
5
+ // Anyone else signing in in this tab, or another page, drops it unread.
6
+
7
+ const KEY = 'proto:unsent';
8
+
9
+ /**
10
+ * The words, who wrote them, the page's full path (base included, so a
11
+ * same-named prototype of another project is another page), and the thread
12
+ * they reply to (null: a new comment, which comes back on the whole page).
13
+ */
14
+ export type Unsent = { person: string; path: string; thread: string | null; body: string };
15
+
16
+ const isUnsent = (v: unknown): v is Unsent => {
17
+ const u = v as Partial<Unsent> | null;
18
+ return (
19
+ !!u &&
20
+ typeof u.person === 'string' &&
21
+ typeof u.path === 'string' &&
22
+ typeof u.body === 'string' &&
23
+ (u.thread === null || typeof u.thread === 'string')
24
+ );
25
+ };
26
+
27
+ function read(): Unsent | null {
28
+ try {
29
+ const kept: unknown = JSON.parse(sessionStorage.getItem(KEY) ?? 'null');
30
+ return isUnsent(kept) ? kept : null;
31
+ } catch {
32
+ // Storage off, or a value this page did not write: nothing is kept.
33
+ return null;
34
+ }
35
+ }
36
+
37
+ export function keepUnsent(unsent: Unsent): void {
38
+ try {
39
+ sessionStorage.setItem(KEY, JSON.stringify(unsent));
40
+ } catch {
41
+ // Storage off (a private window): there is nowhere to keep it.
42
+ }
43
+ }
44
+
45
+ /** Whether a comment is kept for this page, and whether it is a reply; read without taking it, for the signed-out card. */
46
+ export function keptOn(path: string): { reply: boolean } | null {
47
+ const kept = read();
48
+ return kept && kept.path === path ? { reply: kept.thread !== null } : null;
49
+ }
50
+
51
+ /**
52
+ * Once someone is signed in: the comment kept for them on this page, taken
53
+ * out of storage. Whatever is kept is dropped here either way, so it never
54
+ * reaches another person or another page.
55
+ */
56
+ export function takeUnsent(person: string, path: string): Unsent | null {
57
+ const kept = read();
58
+ try {
59
+ sessionStorage.removeItem(KEY);
60
+ } catch {
61
+ // Storage off: it was never there.
62
+ }
63
+ return kept && kept.person === person && kept.path === path ? kept : null;
64
+ }