@milesroxas/design-hub 0.9.0 → 0.11.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 (150) hide show
  1. package/README.md +13 -11
  2. package/core/controls.test.ts +176 -0
  3. package/core/controls.ts +195 -0
  4. package/core/files.test.ts +76 -0
  5. package/core/files.ts +131 -0
  6. package/core/prototype.test.ts +124 -7
  7. package/core/prototype.ts +133 -24
  8. package/core/review/model.ts +144 -2
  9. package/core/review/policy.test.ts +79 -22
  10. package/core/review/policy.ts +36 -8
  11. package/core/review/service.test.ts +1525 -322
  12. package/core/review/service.ts +810 -183
  13. package/core/review/store.test.ts +91 -0
  14. package/core/review/store.ts +143 -26
  15. package/dist/core/controls.d.ts +55 -0
  16. package/dist/core/controls.js +174 -0
  17. package/dist/core/files.d.ts +39 -0
  18. package/dist/core/files.js +107 -0
  19. package/dist/core/prototype.d.ts +61 -12
  20. package/dist/core/prototype.js +105 -26
  21. package/dist/core/review/model.d.ts +87 -2
  22. package/dist/core/review/model.js +97 -1
  23. package/dist/core/review/policy.d.ts +11 -4
  24. package/dist/core/review/policy.js +14 -2
  25. package/dist/core/review/service.d.ts +222 -43
  26. package/dist/core/review/service.js +727 -182
  27. package/dist/core/review/store.d.ts +84 -24
  28. package/dist/core/review/store.js +66 -26
  29. package/dist/scripts/bootstrap.d.ts +4 -34
  30. package/dist/scripts/bootstrap.js +9 -244
  31. package/dist/scripts/cli.js +6 -0
  32. package/dist/scripts/client.d.ts +45 -0
  33. package/dist/scripts/client.js +320 -0
  34. package/dist/scripts/commands.js +6 -0
  35. package/dist/scripts/comments.d.ts +8 -26
  36. package/dist/scripts/comments.js +27 -14
  37. package/dist/scripts/guard.d.ts +11 -0
  38. package/dist/scripts/guard.js +44 -0
  39. package/dist/scripts/lib/builds.d.ts +40 -0
  40. package/dist/scripts/lib/builds.js +198 -0
  41. package/dist/scripts/lib/cli.js +3 -1
  42. package/dist/scripts/lib/deploy.d.ts +6 -90
  43. package/dist/scripts/lib/deploy.js +24 -137
  44. package/dist/scripts/lib/dns.d.ts +49 -0
  45. package/dist/scripts/lib/dns.js +141 -0
  46. package/dist/scripts/lib/fake-host.d.ts +168 -0
  47. package/dist/scripts/lib/fake-host.js +244 -0
  48. package/dist/scripts/lib/host.d.ts +87 -0
  49. package/dist/scripts/lib/host.js +362 -0
  50. package/dist/scripts/lib/linked.d.ts +51 -0
  51. package/dist/scripts/lib/linked.js +124 -0
  52. package/dist/scripts/lib/names.d.ts +35 -0
  53. package/dist/scripts/lib/names.js +77 -0
  54. package/dist/scripts/lib/review.d.ts +23 -2
  55. package/dist/scripts/lib/review.js +32 -15
  56. package/dist/scripts/lib/rules.d.ts +1 -0
  57. package/dist/scripts/lib/rules.js +1 -0
  58. package/dist/scripts/lib/studio-deps.d.ts +35 -0
  59. package/dist/scripts/lib/studio-deps.js +79 -0
  60. package/dist/scripts/lib/studios.d.ts +70 -0
  61. package/dist/scripts/lib/studios.js +187 -0
  62. package/dist/scripts/lib/update.d.ts +33 -0
  63. package/dist/scripts/lib/update.js +40 -0
  64. package/dist/scripts/lib/vercel.d.ts +1 -23
  65. package/dist/scripts/lib/vercel.js +6 -81
  66. package/dist/scripts/people.d.ts +7 -11
  67. package/dist/scripts/people.js +51 -46
  68. package/dist/scripts/preflight.d.ts +8 -1
  69. package/dist/scripts/preflight.js +36 -19
  70. package/dist/scripts/project.d.ts +86 -0
  71. package/dist/scripts/project.js +141 -0
  72. package/dist/scripts/share.d.ts +105 -30
  73. package/dist/scripts/share.js +82 -154
  74. package/dist/scripts/skills.d.ts +18 -2
  75. package/dist/scripts/skills.js +22 -3
  76. package/dist/scripts/studio.d.ts +75 -0
  77. package/dist/scripts/studio.js +401 -0
  78. package/dist/scripts/upgrade.d.ts +10 -2
  79. package/dist/scripts/upgrade.js +44 -14
  80. package/dist/server/api.d.ts +22 -11
  81. package/dist/server/api.js +125 -44
  82. package/dist/server/blob.d.ts +10 -0
  83. package/dist/server/blob.js +53 -0
  84. package/dist/server/checks.js +2 -2
  85. package/dist/server/dev.js +4 -4
  86. package/dist/server/env.d.ts +2 -0
  87. package/dist/server/env.js +9 -0
  88. package/dist/server/fake-upstash.js +52 -3
  89. package/dist/server/hosts.d.ts +11 -0
  90. package/dist/server/hosts.js +31 -0
  91. package/dist/server/local.d.ts +7 -1
  92. package/dist/server/local.js +10 -1
  93. package/dist/server/mark.d.ts +41 -0
  94. package/dist/server/mark.js +111 -0
  95. package/dist/server/session.d.ts +17 -9
  96. package/dist/server/session.js +22 -45
  97. package/dist/server/upstash.js +20 -0
  98. package/dist/vercel/files.d.ts +11 -0
  99. package/dist/vercel/files.js +68 -0
  100. package/dist/vercel/index.d.ts +4 -3
  101. package/dist/vercel/index.js +12 -8
  102. package/dist/vercel/proxy.d.ts +69 -4
  103. package/dist/vercel/proxy.js +171 -107
  104. package/dist/vite/plugin.d.ts +24 -1
  105. package/dist/vite/plugin.js +46 -2
  106. package/kit/Artboard.tsx +21 -8
  107. package/kit/Space.tsx +4 -3
  108. package/kit/Variants.tsx +193 -65
  109. package/kit/ViewTools.tsx +77 -11
  110. package/kit/audience.ts +85 -0
  111. package/kit/dials.css +59 -0
  112. package/kit/dials.tsx +272 -35
  113. package/kit/harness.css +34 -0
  114. package/kit/prefs.ts +23 -1
  115. package/package.json +3 -2
  116. package/shell/ClientViewNote.tsx +31 -3
  117. package/shell/Guide.tsx +11 -5
  118. package/shell/Index.tsx +32 -10
  119. package/shell/Notice.tsx +1 -1
  120. package/shell/controls.ts +26 -0
  121. package/shell/hub.ts +5 -1
  122. package/shell/main.tsx +33 -6
  123. package/shell/review/Review.tsx +2 -2
  124. package/shell/review/ThreadCard.tsx +5 -5
  125. package/shell/review/client.ts +28 -11
  126. package/shell/review/view.test.ts +19 -0
  127. package/shell/review/view.ts +25 -0
  128. package/shell/shell.css +8 -0
  129. package/shell/studio/ClientHub.tsx +98 -0
  130. package/shell/studio/hub.css +48 -0
  131. package/shell/studio/index.html +14 -0
  132. package/shell/studio/main.tsx +17 -0
  133. package/skills/miles-brand/SKILL.md +11 -1
  134. package/skills/miles-deploy/SKILL.md +121 -64
  135. package/skills/miles-design-hub/SKILL.md +11 -9
  136. package/skills/miles-prototype/SKILL.md +34 -1
  137. package/skills/miles-review/SKILL.md +5 -7
  138. package/skills/miles-worktrees/SKILL.md +3 -3
  139. package/templates/conductor/settings.toml +1 -1
  140. package/templates/studio/.env.example +9 -0
  141. package/templates/studio/.vercelignore +5 -0
  142. package/templates/studio/README.md +84 -0
  143. package/templates/studio/_gitignore +7 -0
  144. package/templates/studio/api/files.ts +4 -0
  145. package/templates/studio/api/review.ts +4 -0
  146. package/templates/studio/build.mjs +4 -0
  147. package/templates/studio/package.json +16 -0
  148. package/templates/studio/proxy.ts +4 -0
  149. package/templates/studio/studio.json +9 -0
  150. package/templates/studio/vercel.json +27 -0
package/kit/Variants.tsx CHANGED
@@ -1,5 +1,7 @@
1
1
  import { type ComponentType, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
+ import { clientVariants } from '../core/controls.ts';
4
+ import { markControl, useControls } from './audience';
3
5
  import './harness.css';
4
6
 
5
7
  type Props = {
@@ -16,9 +18,10 @@ const HARNESS = '.dialkit-root, [data-harness], [data-lapse-panel]';
16
18
  const popupOpen = () =>
17
19
  [...document.querySelectorAll(POPUPS)].some((el) => !el.closest(HARNESS) && el.getClientRects().length > 0);
18
20
 
19
- function initialIndex(count: number) {
21
+ /** `?v=N` counts the prototype's own variants, so a link names the same one for Studio and a Client. */
22
+ function initialName(names: string[]) {
20
23
  const v = Number(new URLSearchParams(location.search).get('v'));
21
- return Number.isInteger(v) && v >= 1 && v <= count ? v - 1 : 0;
24
+ return names[Number.isInteger(v) && v >= 1 && v <= names.length ? v - 1 : 0];
22
25
  }
23
26
 
24
27
  const modified = (e: KeyboardEvent) => e.metaKey || e.ctrlKey || e.altKey || e.shiftKey;
@@ -36,30 +39,68 @@ function keyTarget(key: string, index: number, count: number): number | 'again'
36
39
  return key.toLowerCase() === 'r' ? 'again' : null;
37
40
  }
38
41
 
39
- export function Variants({ options, replay = true, onReplay, position = 'bottom' }: Props) {
40
- const names = Object.keys(options);
41
- const [index, setIndex] = useState(() => initialIndex(names.length));
42
- const [take, setTake] = useState(0);
42
+ /**
43
+ * The variants the person looking gets (core/controls.ts). Studio gets every
44
+ * one. A Client gets the ones Studio marked, or the first when none is; with
45
+ * one, there is no picker.
46
+ */
47
+ function useShown(names: string[]) {
48
+ const { studio, canMark, marks } = useControls();
49
+ const theirs = clientVariants(names, marks);
50
+ return {
51
+ shown: studio ? names : theirs,
52
+ theirs,
53
+ /** The ones Studio marked itself: the first variant is a Client's without a mark when none is. */
54
+ marked: marks.variants,
55
+ canMark,
56
+ picker: studio || theirs.length > 1,
57
+ };
58
+ }
59
+
60
+ const EYE =
61
+ 'M2.4 12.7a1.2 1.2 0 0 1 0-1.4C3.5 9.6 6.7 5 12 5s8.5 4.6 9.6 6.3a1.2 1.2 0 0 1 0 1.4C20.5 14.4 17.3 19 12 19s-8.5-4.6-9.6-6.3Z';
62
+
63
+ const Eye = () => (
64
+ <svg
65
+ width="16"
66
+ height="16"
67
+ viewBox="0 0 24 24"
68
+ fill="none"
69
+ stroke="currentColor"
70
+ strokeWidth="2"
71
+ strokeLinecap="round"
72
+ strokeLinejoin="round"
73
+ aria-hidden="true"
74
+ >
75
+ <path d={EYE} />
76
+ <circle cx="12" cy="12" r="3" />
77
+ </svg>
78
+ );
79
+
80
+ type PickerProps = {
81
+ shown: string[];
82
+ /** The open variant's place in `shown`, or -1 while Studio is marking. */
83
+ active: number;
84
+ /** What a Client gets, dotted in Studio's picker. Empty where nobody marks. */
85
+ theirs: string[];
86
+ position: 'bottom' | 'top';
87
+ choosing: boolean;
88
+ onPick: (name: string) => void;
89
+ onReplay?: () => void;
90
+ /** Studio's eye: turns marking on and off. Absent for a Client. */
91
+ onChoose?: () => void;
92
+ };
93
+
94
+ function Picker({ shown, active, theirs, position, choosing, onPick, onReplay, onChoose }: PickerProps) {
43
95
  const [ready, setReady] = useState(false);
44
96
  const items = useRef<(HTMLButtonElement | null)[]>([]);
45
97
  const highlight = useRef<HTMLSpanElement>(null);
98
+ const count = shown.length;
46
99
 
47
- const select = useCallback(
48
- (i: number) => {
49
- if (i < 0 || i >= names.length) return;
50
- setIndex(i);
51
- const url = new URL(location.href);
52
- url.searchParams.set('v', String(i + 1));
53
- history.replaceState(history.state, '', url);
54
- },
55
- [names.length],
56
- );
57
-
58
- const again = useCallback(() => (onReplay ? onReplay() : setTake((t) => t + 1)), [onReplay]);
59
-
100
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the dots change each item's width
60
101
  useLayoutEffect(() => {
61
102
  const move = () => {
62
- const el = items.current[index];
103
+ const el = items.current[active];
63
104
  if (!el || !highlight.current) return;
64
105
  highlight.current.style.width = `${el.offsetWidth}px`;
65
106
  highlight.current.style.transform = `translateX(${el.offsetLeft}px)`;
@@ -67,68 +108,155 @@ export function Variants({ options, replay = true, onReplay, position = 'bottom'
67
108
  move();
68
109
  addEventListener('resize', move);
69
110
  return () => removeEventListener('resize', move);
70
- }, [index]);
111
+ }, [active, count, theirs.length]);
71
112
 
72
113
  useEffect(() => {
73
114
  const id = requestAnimationFrame(() => requestAnimationFrame(() => setReady(true)));
74
115
  return () => cancelAnimationFrame(id);
75
116
  }, []);
76
117
 
118
+ return (
119
+ <>
120
+ {choosing ? (
121
+ <p className="proto-picker-note" data-position={position === 'top' ? 'top' : undefined} role="status">
122
+ Pick what a client can flip between
123
+ </p>
124
+ ) : null}
125
+ <nav
126
+ className="proto-picker"
127
+ aria-label="Prototype variants"
128
+ data-ready={ready ? '' : undefined}
129
+ data-position={position === 'top' ? 'top' : undefined}
130
+ >
131
+ <span ref={highlight} className="proto-picker-highlight" aria-hidden="true" hidden={active < 0} />
132
+ {shown.map((name, i) => (
133
+ <button
134
+ key={name}
135
+ ref={(el) => {
136
+ items.current[i] = el;
137
+ }}
138
+ type="button"
139
+ className="proto-picker-item"
140
+ data-active={i === active ? '' : undefined}
141
+ data-theirs={theirs.includes(name) ? '' : undefined}
142
+ aria-current={i === active ? 'true' : undefined}
143
+ aria-pressed={choosing ? theirs.includes(name) : undefined}
144
+ title={onChoose && theirs.includes(name) ? 'A client gets this one' : undefined}
145
+ onClick={() => onPick(name)}
146
+ >
147
+ {onChoose ? <span className="proto-picker-dot" aria-hidden="true" /> : null}
148
+ {name}
149
+ </button>
150
+ ))}
151
+ <Tools choosing={choosing} onReplay={onReplay} onChoose={onChoose} />
152
+ </nav>
153
+ </>
154
+ );
155
+ }
156
+
157
+ function Tools({ choosing, onReplay, onChoose }: Pick<PickerProps, 'choosing' | 'onReplay' | 'onChoose'>) {
158
+ if (!onReplay && !onChoose) return null;
159
+ return (
160
+ <>
161
+ <span className="proto-picker-divider" aria-hidden="true" />
162
+ {onReplay ? (
163
+ <button
164
+ type="button"
165
+ className="proto-picker-item proto-picker-replay"
166
+ aria-label="Replay animation (R)"
167
+ onClick={onReplay}
168
+ >
169
+ ↻
170
+ </button>
171
+ ) : null}
172
+ {onChoose ? (
173
+ <button
174
+ type="button"
175
+ className="proto-picker-item proto-picker-choose"
176
+ aria-pressed={choosing}
177
+ aria-label="Choose what a client gets"
178
+ title="Choose what a client gets"
179
+ onClick={onChoose}
180
+ >
181
+ {choosing ? 'Done' : <Eye />}
182
+ </button>
183
+ ) : null}
184
+ </>
185
+ );
186
+ }
187
+
188
+ /** The open variant, kept in `?v=N`, and the way to open another. */
189
+ function usePicked(names: string[]) {
190
+ const [picked, setPicked] = useState(() => initialName(names));
191
+ const key = names.join('\n');
192
+ const select = useCallback(
193
+ (next: string | undefined) => {
194
+ if (next === undefined) return;
195
+ setPicked(next);
196
+ const url = new URL(location.href);
197
+ url.searchParams.set('v', String(key.split('\n').indexOf(next) + 1));
198
+ history.replaceState(history.state, '', url);
199
+ },
200
+ [key],
201
+ );
202
+ return { picked, select };
203
+ }
204
+
205
+ /** 1 to N, the arrows and R, over the variants the person looking has. */
206
+ function usePickerKeys(shown: string[], index: number, select: (name: string) => void, again: () => void) {
207
+ const shownKey = shown.join('\n');
77
208
  useEffect(() => {
209
+ const list = shownKey.split('\n');
78
210
  const onKey = (e: KeyboardEvent) => {
79
211
  if (!pickerOwns(e)) return;
80
- const next = keyTarget(e.key, index, names.length);
212
+ const next = keyTarget(e.key, index, list.length);
81
213
  if (next === 'again') again();
82
- else if (next !== null) select(next);
214
+ else if (next !== null) select(list[next]);
83
215
  };
84
216
  document.addEventListener('keydown', onKey);
85
217
  return () => document.removeEventListener('keydown', onKey);
86
- }, [index, names.length, select, again]);
218
+ }, [index, shownKey, select, again]);
219
+ }
220
+
221
+ /** Studio's second state of the picker: a click marks a variant instead of opening it. */
222
+ function useMarking(canMark: boolean, marked: string[]) {
223
+ const [marking, setMarking] = useState(false);
224
+ return {
225
+ choosing: marking && canMark,
226
+ onChoose: canMark ? () => setMarking((m) => !m) : undefined,
227
+ mark: (n: string) => void markControl('variant', n, marked.includes(n) ? 'internal' : 'client'),
228
+ };
229
+ }
230
+
231
+ export function Variants({ options, replay = true, onReplay, position = 'bottom' }: Props) {
232
+ const names = Object.keys(options);
233
+ const { shown, theirs, marked, canMark, picker } = useShown(names);
234
+ const { picked, select } = usePicked(names);
235
+ const [take, setTake] = useState(0);
236
+ const { choosing, onChoose, mark } = useMarking(canMark, marked);
237
+ const name = shown.includes(picked) ? picked : shown[0];
238
+ const index = shown.indexOf(name);
239
+ const again = useCallback(() => (onReplay ? onReplay() : setTake((t) => t + 1)), [onReplay]);
240
+ usePickerKeys(shown, index, select, again);
87
241
 
88
- const Current = options[names[index]];
242
+ const Current = options[name];
243
+ const bar = (
244
+ <Picker
245
+ shown={shown}
246
+ active={choosing ? -1 : index}
247
+ theirs={onChoose ? theirs : []}
248
+ position={position}
249
+ choosing={choosing}
250
+ onPick={choosing ? mark : select}
251
+ onReplay={replay ? again : undefined}
252
+ onChoose={onChoose}
253
+ />
254
+ );
89
255
 
90
256
  return (
91
257
  <>
92
- <Current key={`${index}:${take}`} />
93
- {createPortal(
94
- <nav
95
- className="proto-picker"
96
- aria-label="Prototype variants"
97
- data-ready={ready ? '' : undefined}
98
- data-position={position === 'top' ? 'top' : undefined}
99
- >
100
- <span ref={highlight} className="proto-picker-highlight" aria-hidden="true" />
101
- {names.map((name, i) => (
102
- <button
103
- key={name}
104
- ref={(el) => {
105
- items.current[i] = el;
106
- }}
107
- type="button"
108
- className="proto-picker-item"
109
- data-active={i === index ? '' : undefined}
110
- aria-current={i === index ? 'true' : undefined}
111
- onClick={() => select(i)}
112
- >
113
- {name}
114
- </button>
115
- ))}
116
- {replay && (
117
- <>
118
- <span className="proto-picker-divider" aria-hidden="true" />
119
- <button
120
- type="button"
121
- className="proto-picker-item proto-picker-replay"
122
- aria-label="Replay animation (R)"
123
- onClick={again}
124
- >
125
- ↻
126
- </button>
127
- </>
128
- )}
129
- </nav>,
130
- document.body,
131
- )}
258
+ {Current ? <Current key={`${name}:${take}`} /> : null}
259
+ {picker ? createPortal(bar, document.body) : null}
132
260
  </>
133
261
  );
134
262
  }
package/kit/ViewTools.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useDialKitController } from 'dialkit';
2
- import { useEffect, useLayoutEffect, useState } from 'react';
2
+ import { createContext, useContext, useEffect, useLayoutEffect, useState } from 'react';
3
3
  import { ensureDialRoot } from './dials';
4
4
  import {
5
5
  type Appearance,
@@ -12,23 +12,89 @@ import {
12
12
 
13
13
  const SPEEDS: Record<string, number> = { '1×': 1, '0.5×': 0.5, '0.25×': 0.25, '0.1×': 0.1 };
14
14
 
15
- // The View dials every prototype gets, in the Space and the app shell alike.
15
+ /**
16
+ * What the View panel can hold. `theme` is system, light and dark. `motion`
17
+ * is Reduce motion and Speed together: both are about things that move.
18
+ */
19
+ export type ViewTool = 'theme' | 'motion';
20
+ const ALL: readonly ViewTool[] = ['theme', 'motion'];
21
+
22
+ /**
23
+ * The tools that make sense where a prototype stands, set by what it stands
24
+ * on. A `Board` allows none: collateral is a still file with one look, so it
25
+ * has no motion to slow and no theme to flip. Null allows all of them.
26
+ */
27
+ export const ViewScope = createContext<readonly ViewTool[] | null>(null);
28
+
29
+ /** The tools asked for that the surroundings allow. */
30
+ function useAllowed(tools: readonly ViewTool[] | undefined) {
31
+ const scope = useContext(ViewScope);
32
+ return (tools ?? ALL).filter((t) => !scope || scope.includes(t));
33
+ }
34
+
35
+ // The View dials a prototype gets, in the Space and the shells alike: only the
36
+ // ones that change something there. With none, there is no View panel.
16
37
  // Theme mirrors @kit/prefs both ways, so a product setting or ?theme= moves the dial too.
17
- export function ViewTools() {
38
+ export function ViewTools({ tools }: { tools?: readonly ViewTool[] }) {
39
+ const allowed = useAllowed(tools);
40
+ if (allowed.length === 0) return null;
41
+ return (
42
+ <ViewPanel key={allowed.join()} theme={allowed.includes('theme')} motion={allowed.includes('motion')} />
43
+ );
44
+ }
45
+
46
+ function ViewPanel({ theme, motion }: { theme: boolean; motion: boolean }) {
18
47
  const appearance = useAppearance();
19
48
  const [config] = useState(() => ({
20
- theme: { type: 'select' as const, options: ['system', 'light', 'dark'], default: appearance },
21
- reduceMotion: prefersReducedMotion(),
22
- speed: { type: 'select' as const, options: Object.keys(SPEEDS), default: '1×' },
49
+ ...(theme
50
+ ? { theme: { type: 'select' as const, options: ['system', 'light', 'dark'], default: appearance } }
51
+ : {}),
52
+ ...(motion
53
+ ? {
54
+ reduceMotion: prefersReducedMotion(),
55
+ speed: { type: 'select' as const, options: Object.keys(SPEEDS), default: '1×' },
56
+ }
57
+ : {}),
23
58
  }));
24
59
  useLayoutEffect(ensureDialRoot, []);
25
- const { values: v, setValue } = useDialKitController('View', config, {
60
+ const { values, setValue } = useDialKitController('View', config, {
26
61
  id: 'view',
27
62
  defaultCollapsed: true,
28
63
  });
29
- useEffect(() => setAppearance(v.theme as Appearance), [v.theme]);
30
- useEffect(() => setValue('theme', appearance), [appearance, setValue]);
31
- useEffect(() => setForceReduce(v.reduceMotion), [v.reduceMotion]);
32
- useEffect(() => setSpeed(SPEEDS[v.speed] ?? 1), [v.speed]);
64
+ const v = values as { theme?: string; reduceMotion?: boolean; speed?: string };
65
+ useTheme(theme, v.theme, appearance, setValue as (path: string, value: string) => void);
66
+ useMotion(motion, v.reduceMotion, v.speed);
33
67
  return null;
34
68
  }
69
+
70
+ function useTheme(
71
+ on: boolean,
72
+ value: string | undefined,
73
+ appearance: Appearance,
74
+ setValue: (path: string, value: string) => void,
75
+ ) {
76
+ useEffect(() => {
77
+ if (on && value) setAppearance(value as Appearance);
78
+ }, [on, value]);
79
+ useEffect(() => {
80
+ if (on) setValue('theme', appearance);
81
+ }, [on, appearance, setValue]);
82
+ }
83
+
84
+ function useMotion(on: boolean, reduce: boolean | undefined, speed: string | undefined) {
85
+ useEffect(() => {
86
+ if (on) setForceReduce(reduce === true);
87
+ }, [on, reduce]);
88
+ useEffect(() => {
89
+ if (on) setSpeed(SPEEDS[speed ?? ''] ?? 1);
90
+ }, [on, speed]);
91
+ // Leaving a page that had the motion tools puts motion back as the person's own settings have it.
92
+ useEffect(
93
+ () => () => {
94
+ if (!on) return;
95
+ setForceReduce(false);
96
+ setSpeed(1);
97
+ },
98
+ [on],
99
+ );
100
+ }
@@ -0,0 +1,85 @@
1
+ import { useSyncExternalStore } from 'react';
2
+ import { type ControlAudience, type ControlKind, type Marks, NO_MARKS, withMark } from '../core/controls.ts';
3
+ import { useClientView } from './prefs';
4
+
5
+ // Who is looking at this prototype's controls, and what Studio marked on them.
6
+ // The hub sets it before the prototype renders (shell/controls.ts); the dials
7
+ // and the picker read it. Until it is set, the page is a Client's with nothing
8
+ // marked: the narrowest view, so a failed read never shows more.
9
+
10
+ type Save = (kind: ControlKind, id: string, audience: ControlAudience) => Promise<unknown>;
11
+
12
+ type Controls = {
13
+ /** The signed-in person is Studio. Client view narrows it (kit/prefs.ts). */
14
+ studio: boolean;
15
+ marks: Marks;
16
+ /** How a mark is stored. Null where nothing stores one: an export, or a preview with no review API. */
17
+ save: Save | null;
18
+ /** The last mark that did not save, said beside the panel until the next one does. */
19
+ failed: string | null;
20
+ };
21
+
22
+ let state: Controls = { studio: false, marks: NO_MARKS, save: null, failed: null };
23
+ const listeners = new Set<() => void>();
24
+
25
+ const set = (patch: Partial<Controls>) => {
26
+ state = { ...state, ...patch };
27
+ for (const fn of listeners) fn();
28
+ };
29
+ const subscribe = (fn: () => void) => {
30
+ listeners.add(fn);
31
+ return () => listeners.delete(fn);
32
+ };
33
+
34
+ /** The hub's answer for this page. */
35
+ export const setControls = (next: Pick<Controls, 'studio' | 'marks' | 'save'>) =>
36
+ set({ ...next, failed: null });
37
+
38
+ /**
39
+ * What the controls read: `studio` is Studio outside Client view, who gets
40
+ * every dial and variant; `canMark` is whether a mark can be stored here.
41
+ */
42
+ export function useControls() {
43
+ const s = useSyncExternalStore(subscribe, () => state);
44
+ const clientView = useClientView();
45
+ const studio = s.studio && !clientView;
46
+ return {
47
+ studio,
48
+ canMark: studio && s.save !== null,
49
+ marks: s.marks,
50
+ failed: s.failed,
51
+ /** A Studio person, in Client view or not: who the way in and out of Client view is for. */
52
+ person: s.studio,
53
+ };
54
+ }
55
+
56
+ /** Whether the signed-in person is Studio, whatever view they are in. For code outside React. */
57
+ export const isStudioPerson = () => state.studio;
58
+
59
+ const WORD: Record<ControlAudience, string> = { client: 'client-facing', internal: 'internal' };
60
+
61
+ /**
62
+ * Studio's switch on one dial or variant. The mark shows at once; a save that
63
+ * fails puts back that one control and says so.
64
+ */
65
+ export async function markControl(kind: ControlKind, id: string, audience: ControlAudience) {
66
+ const { save, marks } = state;
67
+ if (!save) return;
68
+ const before = kind === 'dial' ? marks.dials[id] : marks.variants.includes(id) ? 'client' : 'internal';
69
+ set({ marks: withMark(marks, kind, id, audience), failed: null });
70
+ try {
71
+ await save(kind, id, audience);
72
+ } catch (error) {
73
+ set({
74
+ marks: undo(state.marks, kind, id, before),
75
+ failed: `Could not mark it ${WORD[audience]}. ${(error as Error).message}`,
76
+ });
77
+ }
78
+ }
79
+
80
+ /** The marks with one control back as it was: a dial nobody had marked goes back to having no mark. */
81
+ function undo(marks: Marks, kind: ControlKind, id: string, before: ControlAudience | undefined): Marks {
82
+ if (before) return withMark(marks, kind, id, before);
83
+ const { [id]: _gone, ...dials } = marks.dials;
84
+ return { ...marks, dials };
85
+ }
package/kit/dials.css CHANGED
@@ -31,6 +31,10 @@
31
31
  /* The panel's last rows, All prototypes and the walkthrough: drawn as DialKit's
32
32
  own buttons so they read as part of the panel. The walkthrough's arrow says new tab. */
33
33
  .dial-link {
34
+ width: 100%;
35
+ border: 0;
36
+ text-align: left;
37
+ cursor: pointer;
34
38
  display: flex;
35
39
  align-items: center;
36
40
  justify-content: space-between;
@@ -97,3 +101,58 @@
97
101
  margin-top: 4px;
98
102
  border-top: 1px solid var(--dial-border);
99
103
  }
104
+
105
+ /* Who a dial is for (kit/dials.tsx). Studio's eye sits in a slot each row gives
106
+ up at its right end; DialKit sizes a slider by an inline width, so its slot
107
+ is a max-width. The eye is drawn over the slot from outside the row. */
108
+ :root[data-dial-marking] .dialkit-root :is(.dialkit-select-row, .dialkit-labeled-control, .dialkit-text-control, .dialkit-color-control)[data-dial-eye] { margin-right: 32px; }
109
+ :root[data-dial-marking] .dialkit-root .dialkit-slider[data-dial-eye] { max-width: calc(100% - 32px); }
110
+ .dial-eye {
111
+ position: fixed;
112
+ z-index: 2147483647;
113
+ width: 28px;
114
+ height: 28px;
115
+ margin: -14px 0 0 2px;
116
+ display: grid;
117
+ place-items: center;
118
+ border: 0;
119
+ border-radius: 50%;
120
+ background: transparent;
121
+ color: oklch(1 0 0 / 0.32);
122
+ cursor: pointer;
123
+ transition: color var(--dur-hover) var(--ease-hover), background-color var(--dur-hover) var(--ease-hover), transform var(--dur-press-out) var(--ease-press);
124
+ }
125
+ /* 28px drawn, 40px to hit; rows are 42px apart, so two never overlap. */
126
+ .dial-eye::before { content: ''; position: absolute; inset: -6px -2px; }
127
+ .dial-eye[aria-pressed="true"] { color: oklch(1 0 0); }
128
+ @media (hover: hover) and (pointer: fine) {
129
+ .dial-eye:hover { background: oklch(1 0 0 / 0.08); color: oklch(1 0 0 / 0.7); }
130
+ .dial-eye[aria-pressed="true"]:hover { color: oklch(1 0 0); }
131
+ }
132
+ .dial-eye:active { transform: scale(0.94); }
133
+ .dial-eye:focus-visible { outline: 2px solid var(--dial-focus-ring, oklch(1 0 0 / 0.5)); outline-offset: -2px; }
134
+ :root[data-motion="reduce"] .dial-eye:active { transform: none; }
135
+ /* A select's open list covers the rows under it; the eyes step aside. */
136
+ body:has(.dialkit-select-dropdown) .dial-eye { visibility: hidden; }
137
+ /* A mark that did not save, in the hint's material, under the panel's corner. */
138
+ .dial-eye-failed {
139
+ position: fixed;
140
+ z-index: 2147483647;
141
+ right: 16px;
142
+ bottom: 16px;
143
+ max-width: 280px;
144
+ margin: 0;
145
+ padding: 8px 12px;
146
+ border-radius: 8px;
147
+ background: var(--harness-bg);
148
+ color: var(--harness-fg);
149
+ border: 1px solid var(--harness-border);
150
+ box-shadow: var(--harness-shadow);
151
+ font: 500 12px/16px var(--sys-font);
152
+ text-wrap: pretty;
153
+ }
154
+ /* A panel with no dial for the person looking: DialKit still draws its header. */
155
+ .dialkit-root .dialkit-folder-section[data-dial-empty] { display: none; }
156
+ /* Copy parameters and Save version are for whoever tunes. A Client's panel has dials only;
157
+ hidden unless the page is marked Studio's, so a page that never says shows neither. */
158
+ :root:not([data-dial-studio]) .dialkit-root :is(.dialkit-panel-section-toolbar-clip, .dialkit-versions-host) { display: none; }