@milesroxas/design-hub 0.5.0 → 0.6.1

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 CHANGED
@@ -64,7 +64,7 @@ A speculation rule in `shell/index.html` prefetches a prototype's page when its
64
64
 
65
65
  ## The walkthrough
66
66
 
67
- `/guide/<feature>/` is `docs/sprints/<feature>/guide.md`, rendered for reviewers who have the password but not the repo; `/guide/` alone opens the only guide, or lists them. The registry plugin lists the guides, so a new feature's walkthrough appears the moment the file exists (`design-hub guide <feature>` starts one from `templates/guide.md`). The Markdown stays the one source: a Vite plugin (`vite/markdown.ts`, the `?doc` import) compiles it at build time with `marked`, so nothing is parsed in the browser. It turns the first H1 into the title, every H2 and H3 into the contents rail, each image into a figure with its pixel size (no layout shift, lazy below the first), and `> [!NOTE]` quotes into callouts. A paragraph that starts `Controls → …` renders as a click path. Links to other Markdown files lose their href, since nothing serves them. The page reads at 16px on a 680px measure; screenshots and tables take the full 960px column, because a 1440px shot at 680px is unreadable. Two raw values: a screenshot wears a 1px inset outline at 10% (black on light, white on dark) and a callout a 6% ring (8% on dark), alphas rather than tokens because they composite on any surface the page is set on. The slug `guide` is the hub's (`design-hub new guide` refuses it). The page's **Open the prototype** button goes to the feature's sprint prototype, and every prototype of the feature answers with **Open the walkthrough** as the last row of Controls, under every group, in a new tab, so a reviewer reads and clicks side by side. A sheet inside the product was rejected: it would be modal over the thing under review, and testing aids never sit in the product chrome.
67
+ `/guide/<feature>/` is `docs/sprints/<feature>/guide.md`, rendered for reviewers who have the password but not the repo; `/guide/` alone opens the only guide, or lists them. The registry plugin lists the guides, so a new feature's walkthrough appears the moment the file exists (`design-hub guide <feature>` starts one from `templates/guide.md`). The Markdown stays the one source: a Vite plugin (`vite/markdown.ts`, the `?doc` import) compiles it at build time with `marked`, so nothing is parsed in the browser. It turns the first H1 into the title, every H2 and H3 into the contents rail, each image into a figure with its pixel size (no layout shift, lazy below the first), and `> [!NOTE]` quotes into callouts. A paragraph that starts `Controls → …` renders as a click path. Links to other Markdown files lose their href, since nothing serves them. The page reads at 16px on a 680px measure; screenshots and tables take the full 960px column, because a 1440px shot at 680px is unreadable. Two raw values: a screenshot wears a 1px inset outline at 10% (black on light, white on dark) and a callout a 6% ring (8% on dark), alphas rather than tokens because they composite on any surface the page is set on. The slug `guide` is the hub's (`design-hub new guide` refuses it). The page's **Open the prototype** button goes to the feature's sprint prototype, and every prototype of the feature answers with **Open the walkthrough** as the last row of Controls, under every group, in a new tab, so a reviewer reads and clicks side by side. Above it, on every prototype, **All prototypes** goes back to `/` in the same tab. A sheet inside the product was rejected: it would be modal over the thing under review, and testing aids never sit in the product chrome.
68
68
 
69
69
  ## Deploying, and the password
70
70
 
package/kit/dials.css CHANGED
@@ -28,9 +28,9 @@
28
28
  .dial-hint:not(.is-on) { transition-duration: 90ms; }
29
29
  :root[data-motion="reduce"] .dial-hint { transform: none; transition: opacity 120ms var(--ease-hover); }
30
30
 
31
- /* The walkthrough link: the panel's last row, drawn as one of DialKit's own
32
- buttons so it reads as part of the panel, with the arrow that says new tab. */
33
- .dial-guide {
31
+ /* The panel's last rows, All prototypes and the walkthrough: drawn as DialKit's
32
+ own buttons so they read as part of the panel. The walkthrough's arrow says new tab. */
33
+ .dial-link {
34
34
  display: flex;
35
35
  align-items: center;
36
36
  justify-content: space-between;
@@ -47,12 +47,13 @@
47
47
  text-decoration: none;
48
48
  transition: background-color var(--dur-hover) var(--ease-hover), color var(--dur-hover) var(--ease-hover), transform var(--dur-press-out) var(--ease-press);
49
49
  }
50
- .dial-guide:hover { background: var(--dial-surface-hover); color: var(--dial-text-primary); }
51
- .dial-guide:active { transform: scale(0.97); }
52
- .dial-guide:focus-visible { outline: 2px solid var(--dial-focus-ring); outline-offset: -2px; }
53
- :root[data-motion="reduce"] .dial-guide:active { transform: none; }
50
+ .dial-link + .dial-link { margin-top: 4px; }
51
+ .dial-link:hover { background: var(--dial-surface-hover); color: var(--dial-text-primary); }
52
+ .dial-link:active { transform: scale(0.97); }
53
+ .dial-link:focus-visible { outline: 2px solid var(--dial-focus-ring); outline-offset: -2px; }
54
+ :root[data-motion="reduce"] .dial-link:active { transform: none; }
54
55
  /* The panel has no bottom padding, so the last row brings its own. */
55
- .dialkit-folder-root > .dialkit-folder-content:has(> .dial-guide) { padding-bottom: 12px; }
56
+ .dialkit-folder-root > .dialkit-folder-content:has(> .dial-link) { padding-bottom: 12px; }
56
57
 
57
58
  /* DialKit draws Copy parameters and Save version at the top of every group,
58
59
  inside its sticky header. Here they close the group instead: the header
package/kit/dials.tsx CHANGED
@@ -12,7 +12,7 @@ import 'dialkit/styles.css';
12
12
  import './dials.css';
13
13
  import { type RefObject, useLayoutEffect } from 'react';
14
14
  import { createRoot } from 'react-dom/client';
15
- import { iconMarkup } from './Icon';
15
+ import { type IconName, iconMarkup } from './Icon';
16
16
 
17
17
  // What the panel calls itself. DialKit hard-codes its own name as the root
18
18
  // title; the prototypes say what the thing is instead.
@@ -55,7 +55,7 @@ export function ensureDialRoot() {
55
55
  // DialKit portals the panel to <body>; it appears once the first panel registers.
56
56
  const settle = (root: HTMLElement) => {
57
57
  retitle(root);
58
- placeGuide(root);
58
+ placeLinks(root);
59
59
  new MutationObserver((records) => {
60
60
  for (const { type, target } of records) {
61
61
  // DialKit keeps the panel's scroll offset when it collapses, which pushes the trigger icon off-centre.
@@ -64,7 +64,7 @@ export function ensureDialRoot() {
64
64
  }
65
65
  }
66
66
  retitle(root);
67
- placeGuide(root);
67
+ placeLinks(root);
68
68
  }).observe(root, { subtree: true, childList: true, attributeFilter: ['data-collapsed'] });
69
69
  };
70
70
  const found = document.body.querySelector<HTMLElement>('.dialkit-root');
@@ -92,25 +92,44 @@ function retitle(root: HTMLElement) {
92
92
  if (title && title.textContent !== DIALS_TITLE) title.textContent = DIALS_TITLE;
93
93
  }
94
94
 
95
- // The walkthrough is the panel's last row, under every group. DialKit remounts
96
- // the content on open and adds groups as panels register, so the link is put
97
- // back whenever it is missing and moved down whenever a group lands below it.
98
- function placeGuide(root: HTMLElement) {
99
- if (!guide) return;
95
+ type PanelLink = { key: string; href: string; label: string; icon: IconName; newTab?: boolean };
96
+
97
+ // The panel's last rows, under every group: the hub's list of every prototype,
98
+ // then the feature's walkthrough when it has one, which stays the very last.
99
+ function panelLinks(): PanelLink[] {
100
+ const home: PanelLink = { key: 'home', href: '/', label: 'All prototypes', icon: 'grid-01' };
101
+ if (!guide) return [home];
102
+ return [
103
+ home,
104
+ { key: 'guide', href: guide, label: 'Open the walkthrough', icon: 'arrow-up-right', newTab: true },
105
+ ];
106
+ }
107
+
108
+ function makeLink({ key, href, label, icon, newTab }: PanelLink) {
109
+ const link = document.createElement('a');
110
+ link.className = 'dial-link';
111
+ link.dataset.dialLink = key;
112
+ link.href = href;
113
+ if (newTab) {
114
+ link.target = '_blank';
115
+ link.rel = 'noopener';
116
+ }
117
+ link.innerHTML = `<span>${label}</span>${iconMarkup(icon, 16)}`;
118
+ return link;
119
+ }
120
+
121
+ // DialKit remounts the content on open and adds groups as panels register, so
122
+ // the rows are put back whenever they are missing and moved down whenever a
123
+ // group lands below them.
124
+ function placeLinks(root: HTMLElement) {
100
125
  const content = root.querySelector('.dialkit-folder-root > .dialkit-folder-content');
101
126
  if (!content) return;
102
- const placed = content.querySelector(':scope > .dial-guide');
103
- if (placed) {
104
- if (content.lastElementChild !== placed) content.append(placed);
105
- return;
106
- }
107
- const link = document.createElement('a');
108
- link.className = 'dial-guide';
109
- link.href = guide;
110
- link.target = '_blank';
111
- link.rel = 'noopener';
112
- link.innerHTML = `<span>Open the walkthrough</span>${iconMarkup('arrow-up-right', 16)}`;
113
- content.append(link);
127
+ const rows = panelLinks().map(
128
+ (l) => content.querySelector<HTMLAnchorElement>(`:scope > [data-dial-link="${l.key}"]`) ?? makeLink(l),
129
+ );
130
+ const tail = Array.from(content.children).slice(-rows.length);
131
+ if (rows.every((row, i) => tail[i] === row)) return;
132
+ content.append(...rows);
114
133
  }
115
134
 
116
135
  // Hints: what each dial does, shown on hover or focus.
package/kit/prefs.ts CHANGED
@@ -2,6 +2,8 @@ import { useSyncExternalStore } from 'react';
2
2
 
3
3
  // Theme, reduced motion and speed for the page, mirrored onto <html>
4
4
  // (.dark-mode, [data-motion="reduce"]) so CSS and JS read one source.
5
+ // Also whether the comments button and pins are hidden: a choice about the
6
+ // page a person is looking at, kept the same way as their theme.
5
7
 
6
8
  export type Appearance = 'system' | 'light' | 'dark';
7
9
 
@@ -15,7 +17,10 @@ const params = new URLSearchParams(location.search);
15
17
  const urlReduce = params.get('motion') === 'reduce';
16
18
  const listeners = new Set<() => void>();
17
19
 
20
+ const COMMENTS_KEY = 'proto:comments';
21
+
18
22
  let appearance: Appearance = readAppearance();
23
+ let commentsHidden = readStored(COMMENTS_KEY) === 'hidden';
19
24
  let forceReduce = false;
20
25
  let speed = 1;
21
26
  let lapse: LapseHandle | null = null;
@@ -23,11 +28,24 @@ let lapse: LapseHandle | null = null;
23
28
  function readAppearance(): Appearance {
24
29
  const fromUrl = params.get('theme');
25
30
  if (fromUrl === 'light' || fromUrl === 'dark' || fromUrl === 'system') return fromUrl;
31
+ const saved = readStored('proto:appearance');
32
+ if (saved === 'light' || saved === 'dark' || saved === 'system') return saved;
33
+ return 'light';
34
+ }
35
+
36
+ // Storage throws in a private window or with site data blocked: the page then runs on its defaults.
37
+ function readStored(key: string): string | null {
38
+ try {
39
+ return localStorage.getItem(key);
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+
45
+ function store(key: string, value: string) {
26
46
  try {
27
- const saved = localStorage.getItem('proto:appearance');
28
- if (saved === 'light' || saved === 'dark' || saved === 'system') return saved;
47
+ localStorage.setItem(key, value);
29
48
  } catch {}
30
- return 'light';
31
49
  }
32
50
 
33
51
  function emit() {
@@ -58,9 +76,7 @@ function applyMotion() {
58
76
  export function setAppearance(next: Appearance) {
59
77
  if (next === appearance) return;
60
78
  appearance = next;
61
- try {
62
- localStorage.setItem('proto:appearance', next);
63
- } catch {}
79
+ store('proto:appearance', next);
64
80
  applyTheme();
65
81
  emit();
66
82
  }
@@ -71,6 +87,16 @@ export function setForceReduce(on: boolean) {
71
87
  emit();
72
88
  }
73
89
 
90
+ /** Whether the comments button and pins are off the page. Remembered per browser. */
91
+ export const areCommentsHidden = () => commentsHidden;
92
+
93
+ export function setCommentsHidden(hidden: boolean) {
94
+ if (hidden === commentsHidden) return;
95
+ commentsHidden = hidden;
96
+ store(COMMENTS_KEY, hidden ? 'hidden' : 'shown');
97
+ emit();
98
+ }
99
+
74
100
  export const isDark = () => root.classList.contains('dark-mode');
75
101
  export const prefersReducedMotion = () => root.dataset.motion === 'reduce';
76
102
 
package/kit/ui/Menu.tsx CHANGED
@@ -21,10 +21,15 @@ export type MenuItem = {
21
21
  keys?: (string | { icon: IconName; label: string })[];
22
22
  danger?: boolean;
23
23
  disabled?: boolean;
24
+ /** One of a set of choices: drawn with a check when true. Several groups can share a menu, unlike `selected`. */
25
+ checked?: boolean;
24
26
  onClick?: () => void;
25
27
  };
26
28
 
27
- export type MenuEntry = MenuItem | '-';
29
+ /** A label over the items that follow it, for a menu that holds more than one group. */
30
+ export type MenuHeading = { heading: string };
31
+
32
+ export type MenuEntry = MenuItem | MenuHeading | '-';
28
33
 
29
34
  export type MenuConfig = {
30
35
  items: MenuEntry[];
@@ -35,6 +40,8 @@ export type MenuConfig = {
35
40
  selected?: string;
36
41
  checkable?: boolean;
37
42
  role?: 'menu' | 'listbox';
43
+ /** Added to the popup, which portals to <body>: the way a layer with its own material and stacking dresses its menus. */
44
+ className?: string;
38
45
  onSelect?: (value: string | undefined, item: MenuItem) => void;
39
46
  };
40
47
 
@@ -202,7 +209,12 @@ function MenuPopup({
202
209
  onSelect?.(item.value, item);
203
210
  };
204
211
 
205
- const cls = ['menu', shown && phase === 'open' ? 'is-open' : '', phase === 'closing' ? 'is-closing' : '']
212
+ const cls = [
213
+ 'menu',
214
+ config.className,
215
+ shown && phase === 'open' ? 'is-open' : '',
216
+ phase === 'closing' ? 'is-closing' : '',
217
+ ]
206
218
  .filter(Boolean)
207
219
  .join(' ');
208
220
 
@@ -226,12 +238,18 @@ function MenuPopup({
226
238
  // biome-ignore lint/a11y/useSemanticElements: an <hr> brings borders the menu rule does not want
227
239
  // biome-ignore lint/suspicious/noArrayIndexKey: separators have no identity; the list is fixed while open
228
240
  if (item === '-') return <div key={`sep-${n}`} className="menu-sep" role="separator" />;
241
+ if ('heading' in item)
242
+ return (
243
+ <div key={`head-${item.heading}`} className="menu-header" role="presentation">
244
+ {item.heading}
245
+ </div>
246
+ );
229
247
  return (
230
248
  <MenuRow
231
249
  key={`${item.label}-${item.value ?? n}`}
232
250
  item={item}
233
- role={role === 'listbox' ? 'option' : checkable ? 'menuitemradio' : 'menuitem'}
234
- selected={selected != null && selected === item.value}
251
+ role={rowRole(role, checkable || item.checked !== undefined)}
252
+ selected={item.checked ?? (selected != null && selected === item.value)}
235
253
  onPick={pick}
236
254
  />
237
255
  );
@@ -278,6 +296,9 @@ function MenuKeys({ keys }: { keys: NonNullable<MenuItem['keys']> }) {
278
296
  );
279
297
  }
280
298
 
299
+ const rowRole = (role: 'menu' | 'listbox', checkable: boolean | undefined) =>
300
+ role === 'listbox' ? 'option' : checkable ? 'menuitemradio' : 'menuitem';
301
+
281
302
  const rowClass = (item: MenuItem, selected: boolean) =>
282
303
  ['menu-item', item.danger && 'is-danger', item.disabled && 'is-disabled', selected && 'is-selected']
283
304
  .filter(Boolean)
@@ -334,6 +355,7 @@ export function Select({
334
355
  onChange,
335
356
  width,
336
357
  className,
358
+ menuClassName,
337
359
  placeholder = 'Select',
338
360
  labelId,
339
361
  'aria-label': ariaLabel,
@@ -343,6 +365,7 @@ export function Select({
343
365
  onChange: (value: string) => void;
344
366
  width?: number;
345
367
  className?: string;
368
+ menuClassName?: string;
346
369
  placeholder?: string;
347
370
  labelId?: string;
348
371
  'aria-label'?: string;
@@ -355,6 +378,7 @@ export function Select({
355
378
  items: options.map((o) => ({ label: o.label, value: o.value })),
356
379
  selected: value ?? undefined,
357
380
  label: ariaLabel,
381
+ className: menuClassName,
358
382
  width: (trigger) => Math.max(trigger.offsetWidth, width || 0),
359
383
  onSelect: (v) => {
360
384
  if (v != null && v !== value) onChange(v);
package/kit/ui/index.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  export { Badge, Button, Checkbox, Chevron, Segmented } from './Button';
2
2
  export { installPressFeedback } from './layer';
3
- export { type MenuConfig, type MenuEntry, type MenuItem, Select, type SelectOption, useMenu } from './Menu';
3
+ export {
4
+ type MenuConfig,
5
+ type MenuEntry,
6
+ type MenuHeading,
7
+ type MenuItem,
8
+ Select,
9
+ type SelectOption,
10
+ useMenu,
11
+ } from './Menu';
4
12
  export {
5
13
  confirmDialog,
6
14
  OverlayHost,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milesroxas/design-hub",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the password 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": {
@@ -81,7 +81,7 @@
81
81
  "build": "rm -rf dist && tsc -p tsconfig.build.json",
82
82
  "check": "tsc --noEmit && biome check .",
83
83
  "fix": "biome check --write .",
84
- "test": "node --test \"core/**/*.test.ts\" \"server/**/*.test.ts\" \"scripts/**/*.test.ts\" \"vite/**/*.test.ts\" \"vercel/**/*.test.ts\"",
84
+ "test": "node --test \"core/**/*.test.ts\" \"shell/**/*.test.ts\" \"server/**/*.test.ts\" \"scripts/**/*.test.ts\" \"vite/**/*.test.ts\" \"vercel/**/*.test.ts\"",
85
85
  "quality": "rm -rf .coverage && NODE_V8_COVERAGE=.coverage pnpm run --silent test > /dev/null && npx -y fallow@3.38.0 --coverage .coverage"
86
86
  }
87
87
  }
@@ -0,0 +1,156 @@
1
+ // Comment mode's bar: one quiet pill in three groups. What a new comment is
2
+ // about (Pin or Page), the threads to step through, and the way out.
3
+ // Everything rarer sits behind ⋯. Only the chosen half of the toggle is
4
+ // filled: the page under the bar is the work.
5
+ import { Icon } from '@kit/Icon';
6
+ import { Button, type MenuEntry, useMenu } from '@kit/ui';
7
+ import type { Scope } from './view';
8
+
9
+ const VERB = matchMedia('(pointer: coarse)').matches ? 'Tap' : 'Click';
10
+
11
+ type Props = {
12
+ count: number;
13
+ /** Where the open thread sits in the round, from 0; -1 with none open. */
14
+ index: number;
15
+ scope: Scope;
16
+ onScope: (scope: Scope) => void;
17
+ resolved: boolean;
18
+ resolvedCount: number;
19
+ editor: boolean;
20
+ error: string | null;
21
+ onStep: (by: number) => void;
22
+ onResolved: () => void;
23
+ onPeople: () => void;
24
+ onHide: () => void;
25
+ onDone: () => void;
26
+ onDismissError: () => void;
27
+ };
28
+
29
+ function moreItems(resolved: boolean, resolvedCount: number, editor: boolean): MenuEntry[] {
30
+ return [
31
+ {
32
+ label: resolved ? 'Hide resolved' : 'Show resolved',
33
+ desc: resolvedCount ? `${resolvedCount} on this prototype` : 'Nothing resolved yet',
34
+ value: 'resolved',
35
+ icon: 'check-circle',
36
+ disabled: !resolvedCount && !resolved,
37
+ },
38
+ ...(editor
39
+ ? [{ label: 'People', desc: 'Who can comment', value: 'people', icon: 'users-01' as const }]
40
+ : []),
41
+ { label: 'Hide comments', desc: 'Tuck the button into the edge', value: 'hide', icon: 'chevron-right' },
42
+ ];
43
+ }
44
+
45
+ function Alert({ error, onDismiss }: { error: string; onDismiss: () => void }) {
46
+ return (
47
+ <p className="rv-alert" role="alert">
48
+ <span>{error}</span>
49
+ <Button kind="tertiary" size={null} className="rv-act" label="Dismiss" onClick={onDismiss} />
50
+ </p>
51
+ );
52
+ }
53
+
54
+ const SCOPES: { value: Scope; label: string; icon: 'target-04' | 'file-06'; title: string }[] = [
55
+ { value: 'pin', label: 'Pin', icon: 'target-04', title: `${VERB} anything to comment on it` },
56
+ { value: 'page', label: 'Page', icon: 'file-06', title: 'Comment on the whole page' },
57
+ ];
58
+
59
+ /** Pin a comment to part of the page, or leave one on the page as a whole. */
60
+ function Toggle({ scope, onScope }: Pick<Props, 'scope' | 'onScope'>) {
61
+ return (
62
+ // biome-ignore lint/a11y/useSemanticElements: a fieldset brings a border and a legend the bar does not want
63
+ <div className="rv-toggle" role="group" aria-label="Comment on">
64
+ {SCOPES.map((s) => (
65
+ <button
66
+ key={s.value}
67
+ type="button"
68
+ aria-pressed={scope === s.value}
69
+ title={s.title}
70
+ onClick={() => onScope(s.value)}
71
+ >
72
+ <Icon name={s.icon} size={16} />
73
+ <span className="rv-toggle-label">{s.label}</span>
74
+ </button>
75
+ ))}
76
+ </div>
77
+ );
78
+ }
79
+
80
+ /** ‹ 2 open › with nothing open, ‹ 1 of 2 › with one: the arrows step straight to a thread. */
81
+ function Stepper({ count, index, resolved, onStep }: Pick<Props, 'count' | 'index' | 'resolved' | 'onStep'>) {
82
+ const label = index < 0 ? `${count} ${resolved ? 'in all' : 'open'}` : `${index + 1} of ${count}`;
83
+ return (
84
+ // biome-ignore lint/a11y/useSemanticElements: a fieldset brings a border and a legend the bar does not want
85
+ <div className="rv-bar-group rv-stepper" role="group" aria-label="Comments on this prototype">
86
+ <Button
87
+ kind="tertiary"
88
+ size={null}
89
+ icon="chevron-left"
90
+ iconSize={16}
91
+ aria-label="Previous comment"
92
+ disabled={!count}
93
+ onClick={() => onStep(-1)}
94
+ />
95
+ <span className="rv-stepper-count tabular" aria-live="polite">
96
+ {label}
97
+ </span>
98
+ <Button
99
+ kind="tertiary"
100
+ size={null}
101
+ icon="chevron-right"
102
+ iconSize={16}
103
+ aria-label="Next comment"
104
+ disabled={!count}
105
+ onClick={() => onStep(1)}
106
+ />
107
+ </div>
108
+ );
109
+ }
110
+
111
+ export function Bar(p: Props) {
112
+ const actions: Record<string, () => void> = {
113
+ resolved: p.onResolved,
114
+ people: p.onPeople,
115
+ hide: p.onHide,
116
+ };
117
+ const more = useMenu({
118
+ className: 'rv-menu',
119
+ label: 'Comment options',
120
+ width: 264,
121
+ align: 'end',
122
+ items: moreItems(p.resolved, p.resolvedCount, p.editor),
123
+ onSelect: (v) => actions[v ?? '']?.(),
124
+ });
125
+ return (
126
+ <div className="rv-bar-stack">
127
+ {p.error && <Alert error={p.error} onDismiss={p.onDismissError} />}
128
+ <section className="rv-bar" aria-label="Comment mode">
129
+ <Toggle scope={p.scope} onScope={p.onScope} />
130
+ <span className="rv-bar-rule" aria-hidden="true" />
131
+ <Stepper count={p.count} index={p.index} resolved={p.resolved} onStep={p.onStep} />
132
+ <span className="rv-bar-rule" aria-hidden="true" />
133
+ <div className="rv-bar-group">
134
+ <Button
135
+ kind="tertiary"
136
+ size={null}
137
+ icon="dots-horizontal"
138
+ iconSize={16}
139
+ aria-label="Comment options"
140
+ {...more.triggerProps}
141
+ />
142
+ {more.menu}
143
+ <Button
144
+ kind="tertiary"
145
+ size={null}
146
+ icon="x-close"
147
+ iconSize={16}
148
+ aria-label="Stop commenting"
149
+ title="Stop commenting (Esc)"
150
+ onClick={p.onDone}
151
+ />
152
+ </div>
153
+ </section>
154
+ </div>
155
+ );
156
+ }
@@ -0,0 +1,106 @@
1
+ // The one card on screen: beside its pin when it has one, beside the
2
+ // Comments button when it does not. It flips and clamps to stay in view and
3
+ // follows the page as it scrolls.
4
+ import { Button } from '@kit/ui';
5
+ import { type CSSProperties, type ReactNode, useEffect, useLayoutEffect, useRef, useState } from 'react';
6
+ import { besideButton, besidePoint, type Placement } from './place';
7
+ import { useKeyboardInset, useNarrow, useRevealPin, useSheetDrag } from './sheet';
8
+
9
+ const toStyle = (p: Placement): CSSProperties => ({ left: p.left, top: p.top, transformOrigin: p.origin });
10
+
11
+ function place(at: { x: number; y: number } | null, h: number): CSSProperties {
12
+ const vp = { width: innerWidth, height: innerHeight };
13
+ if (at) return toStyle(besidePoint(at, h, vp));
14
+ const b = document.querySelector('.rv-launch')?.getBoundingClientRect();
15
+ return b ? toStyle(besideButton(b, h, vp)) : { right: 16, bottom: 72 };
16
+ }
17
+
18
+ /** Re-renders once a frame on scroll and resize, so a card beside a pin moves with it. */
19
+ function useFollow() {
20
+ const [, tick] = useState(0);
21
+ useEffect(() => {
22
+ let frame = 0;
23
+ const on = () => {
24
+ if (frame) return;
25
+ frame = requestAnimationFrame(() => {
26
+ frame = 0;
27
+ tick((n) => n + 1);
28
+ });
29
+ };
30
+ addEventListener('scroll', on, { capture: true, passive: true });
31
+ addEventListener('resize', on);
32
+ return () => {
33
+ cancelAnimationFrame(frame);
34
+ removeEventListener('scroll', on, { capture: true });
35
+ removeEventListener('resize', on);
36
+ };
37
+ }, []);
38
+ }
39
+
40
+ export function Card({
41
+ at,
42
+ label,
43
+ resolved,
44
+ onDismiss,
45
+ children,
46
+ }: {
47
+ at: { x: number; y: number } | null;
48
+ label: string;
49
+ resolved?: boolean;
50
+ /** Dragging the sheet down on a phone calls this. */
51
+ onDismiss?: () => void;
52
+ children: ReactNode;
53
+ }) {
54
+ useFollow();
55
+ const ref = useRef<HTMLElement>(null);
56
+ const narrow = useNarrow();
57
+ const drag = useSheetDrag(ref, narrow, onDismiss);
58
+ useKeyboardInset(ref, narrow);
59
+ useRevealPin(ref, at, narrow);
60
+ const [h, setH] = useState(0);
61
+ useLayoutEffect(() => {
62
+ const el = ref.current;
63
+ if (!el) return;
64
+ const ro = new ResizeObserver(() => setH(el.offsetHeight));
65
+ ro.observe(el);
66
+ return () => ro.disconnect();
67
+ }, []);
68
+ // A card that closes with focus inside hands it to the button, never to <body>.
69
+ useEffect(() => {
70
+ const el = ref.current;
71
+ return () => {
72
+ if (!el?.contains(document.activeElement)) return;
73
+ requestAnimationFrame(() => {
74
+ if (document.activeElement === document.body)
75
+ document.querySelector<HTMLElement>('.rv-launch')?.focus();
76
+ });
77
+ };
78
+ }, []);
79
+ return (
80
+ <section
81
+ ref={ref}
82
+ className="rv-card"
83
+ aria-label={label}
84
+ data-resolved={resolved ? '' : undefined}
85
+ data-sheet={narrow ? '' : undefined}
86
+ style={narrow ? undefined : place(at, h)}
87
+ {...drag}
88
+ >
89
+ {narrow && <span className="rv-grab" aria-hidden="true" />}
90
+ {children}
91
+ </section>
92
+ );
93
+ }
94
+
95
+ /** A quiet text action in a row of them: Edit, Keep, Delete. */
96
+ export function Action({ label, danger, onClick }: { label: string; danger?: boolean; onClick: () => void }) {
97
+ return (
98
+ <Button
99
+ kind="tertiary"
100
+ size={null}
101
+ className={danger ? 'rv-act rv-act-danger' : 'rv-act'}
102
+ label={label}
103
+ onClick={onClick}
104
+ />
105
+ );
106
+ }