@milesroxas/design-hub 0.8.1 → 0.10.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 (78) hide show
  1. package/README.md +7 -2
  2. package/core/controls.test.ts +176 -0
  3. package/core/controls.ts +195 -0
  4. package/core/prototype.test.ts +83 -0
  5. package/core/prototype.ts +84 -0
  6. package/core/review/model.ts +32 -0
  7. package/core/review/policy.test.ts +4 -2
  8. package/core/review/policy.ts +4 -2
  9. package/core/review/service.test.ts +223 -4
  10. package/core/review/service.ts +111 -2
  11. package/core/review/store.ts +13 -0
  12. package/dist/core/controls.d.ts +55 -0
  13. package/dist/core/controls.js +174 -0
  14. package/dist/core/prototype.d.ts +35 -0
  15. package/dist/core/prototype.js +84 -0
  16. package/dist/core/review/model.d.ts +13 -0
  17. package/dist/core/review/model.js +27 -0
  18. package/dist/core/review/policy.d.ts +1 -1
  19. package/dist/core/review/policy.js +1 -0
  20. package/dist/core/review/service.d.ts +50 -1
  21. package/dist/core/review/service.js +97 -3
  22. package/dist/core/review/store.d.ts +13 -0
  23. package/dist/core/review/store.js +13 -0
  24. package/dist/scripts/guard.d.ts +11 -0
  25. package/dist/scripts/guard.js +44 -0
  26. package/dist/scripts/lib/cdp.js +6 -1
  27. package/dist/scripts/lib/export-smoke.d.ts +18 -0
  28. package/dist/scripts/lib/export-smoke.js +73 -0
  29. package/dist/scripts/lib/rules.d.ts +1 -0
  30. package/dist/scripts/lib/rules.js +1 -0
  31. package/dist/scripts/new.js +5 -2
  32. package/dist/scripts/release-check.d.ts +5 -3
  33. package/dist/scripts/release-check.js +17 -4
  34. package/dist/scripts/share.d.ts +2 -2
  35. package/dist/server/api.js +21 -0
  36. package/dist/server/session.d.ts +5 -1
  37. package/dist/server/session.js +39 -21
  38. package/dist/vercel/proxy.js +44 -8
  39. package/dist/vite/boundary.d.ts +93 -0
  40. package/dist/vite/boundary.js +218 -0
  41. package/dist/vite/css-boundary.d.ts +39 -0
  42. package/dist/vite/css-boundary.js +167 -0
  43. package/dist/vite/kit.js +15 -6
  44. package/dist/vite/leaks.d.ts +37 -0
  45. package/dist/vite/leaks.js +331 -0
  46. package/dist/vite/plugin.js +2 -1
  47. package/dist/vite/registry.d.ts +15 -4
  48. package/dist/vite/registry.js +531 -27
  49. package/dist/vite/settle.d.ts +27 -0
  50. package/dist/vite/settle.js +185 -0
  51. package/kit/Artboard.tsx +21 -8
  52. package/kit/Space.tsx +4 -3
  53. package/kit/Variants.tsx +193 -65
  54. package/kit/ViewTools.tsx +77 -11
  55. package/kit/audience.ts +85 -0
  56. package/kit/dials.css +59 -0
  57. package/kit/dials.tsx +272 -35
  58. package/kit/harness.css +34 -0
  59. package/kit/prefs.ts +23 -1
  60. package/package.json +5 -4
  61. package/shell/ClientViewNote.tsx +46 -0
  62. package/shell/Guide.tsx +17 -2
  63. package/shell/Index.tsx +257 -25
  64. package/shell/audience.test.ts +63 -0
  65. package/shell/audience.ts +47 -0
  66. package/shell/controls.ts +26 -0
  67. package/shell/hub.ts +36 -0
  68. package/shell/main.tsx +51 -5
  69. package/shell/registry.ts +28 -7
  70. package/shell/registry.virtual.d.ts +12 -4
  71. package/shell/review/client.ts +16 -4
  72. package/shell/review/review.css +2 -2
  73. package/shell/shell.css +54 -3
  74. package/shell/system.css +5 -0
  75. package/skills/miles-brand/SKILL.md +11 -1
  76. package/skills/miles-deploy/SKILL.md +19 -0
  77. package/skills/miles-new-feature/SKILL.md +1 -1
  78. package/skills/miles-prototype/SKILL.md +48 -2
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; }
package/kit/dials.tsx CHANGED
@@ -10,9 +10,21 @@ import {
10
10
  } from 'dialkit';
11
11
  import 'dialkit/styles.css';
12
12
  import './dials.css';
13
- import { type RefObject, useLayoutEffect } from 'react';
13
+ import { type RefObject, useEffect, useLayoutEffect, useState } from 'react';
14
14
  import { createRoot } from 'react-dom/client';
15
+ import {
16
+ type ControlAudience,
17
+ dialAudience,
18
+ dialId,
19
+ keepDials,
20
+ readConfig,
21
+ withDefaults,
22
+ } from '../core/controls.ts';
23
+ import { isStudioPerson, markControl, useControls } from './audience';
15
24
  import { type IconName, iconMarkup } from './Icon';
25
+ import { isClientView, setClientView } from './prefs';
26
+
27
+ export { client } from '../core/controls.ts';
16
28
 
17
29
  // What the panel calls itself. DialKit hard-codes its own name as the root
18
30
  // title; the prototypes say what the thing is instead.
@@ -45,17 +57,21 @@ export function ensureDialRoot() {
45
57
  // DialKit hides its panel in production builds unless told otherwise; the
46
58
  // deployed prototypes are for tuning, so the dials ship with them.
47
59
  createRoot(host).render(
48
- <DialRoot
49
- position={parked ? 'top-left' : 'top-right'}
50
- theme="dark"
51
- defaultOpen={open}
52
- productionEnabled
53
- />,
60
+ <>
61
+ <DialRoot
62
+ position={parked ? 'top-left' : 'top-right'}
63
+ theme="dark"
64
+ defaultOpen={open}
65
+ productionEnabled
66
+ />
67
+ <DialEyes />
68
+ </>,
54
69
  );
55
70
  // DialKit portals the panel to <body>; it appears once the first panel registers.
56
71
  const settle = (root: HTMLElement) => {
57
72
  retitle(root);
58
73
  placeLinks(root);
74
+ tagEmpty(root);
59
75
  new MutationObserver((records) => {
60
76
  for (const { type, target } of records) {
61
77
  // DialKit keeps the panel's scroll offset when it collapses, which pushes the trigger icon off-centre.
@@ -65,6 +81,7 @@ export function ensureDialRoot() {
65
81
  }
66
82
  retitle(root);
67
83
  placeLinks(root);
84
+ tagEmpty(root);
68
85
  }).observe(root, { subtree: true, childList: true, attributeFilter: ['data-collapsed'] });
69
86
  };
70
87
  const found = document.body.querySelector<HTMLElement>('.dialkit-root');
@@ -92,30 +109,65 @@ function retitle(root: HTMLElement) {
92
109
  if (title && title.textContent !== DIALS_TITLE) title.textContent = DIALS_TITLE;
93
110
  }
94
111
 
95
- type PanelLink = { key: string; href: string; label: string; icon: IconName; newTab?: boolean };
112
+ type PanelLink = {
113
+ key: string;
114
+ label: string;
115
+ icon: IconName;
116
+ href?: string;
117
+ newTab?: boolean;
118
+ /** A row that does something here instead of going somewhere. */
119
+ act?: () => void;
120
+ };
121
+
122
+ // Studio's way into Client view and back: the page as a client gets it, beside
123
+ // the dials it changes. The page loads again, so the comments, the dials and
124
+ // the prototype itself all start as a client's would.
125
+ function clientViewRow(): PanelLink {
126
+ const on = isClientView();
127
+ return {
128
+ key: 'client-view',
129
+ label: on ? 'Leave Client view' : 'Client view',
130
+ icon: 'briefcase-01',
131
+ act: () => {
132
+ setClientView(!on);
133
+ location.reload();
134
+ },
135
+ };
136
+ }
96
137
 
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.
138
+ // The panel's last rows, under every group: Client view for Studio, the hub's
139
+ // list of every prototype, then the feature's walkthrough when it has one,
140
+ // which stays the very last.
99
141
  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
- ];
142
+ const rows: PanelLink[] = isStudioPerson() ? [clientViewRow()] : [];
143
+ rows.push({ key: 'home', href: '/', label: 'All prototypes', icon: 'grid-01' });
144
+ if (guide)
145
+ rows.push({
146
+ key: 'guide',
147
+ href: guide,
148
+ label: 'Open the walkthrough',
149
+ icon: 'arrow-up-right',
150
+ newTab: true,
151
+ });
152
+ return rows;
106
153
  }
107
154
 
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';
155
+ function makeLink({ key, href, label, icon, newTab, act }: PanelLink) {
156
+ const row = document.createElement(act ? 'button' : 'a');
157
+ row.className = 'dial-link';
158
+ row.dataset.dialLink = key;
159
+ if (row instanceof HTMLButtonElement) {
160
+ row.type = 'button';
161
+ row.addEventListener('click', () => act?.());
162
+ } else {
163
+ row.href = href ?? '/';
164
+ if (newTab) {
165
+ row.target = '_blank';
166
+ row.rel = 'noopener';
167
+ }
116
168
  }
117
- link.innerHTML = `<span>${label}</span>${iconMarkup(icon, 16)}`;
118
- return link;
169
+ row.innerHTML = `<span>${label}</span>${iconMarkup(icon, 16)}`;
170
+ return row;
119
171
  }
120
172
 
121
173
  // DialKit remounts the content on open and adds groups as panels register, so
@@ -125,7 +177,7 @@ function placeLinks(root: HTMLElement) {
125
177
  const content = root.querySelector('.dialkit-folder-root > .dialkit-folder-content');
126
178
  if (!content) return;
127
179
  const rows = panelLinks().map(
128
- (l) => content.querySelector<HTMLAnchorElement>(`:scope > [data-dial-link="${l.key}"]`) ?? makeLink(l),
180
+ (l) => content.querySelector<HTMLElement>(`:scope > [data-dial-link="${l.key}"]`) ?? makeLink(l),
129
181
  );
130
182
  const tail = Array.from(content.children).slice(-rows.length);
131
183
  if (rows.every((row, i) => tail[i] === row)) return;
@@ -183,7 +235,7 @@ const rowLabel = (row: HTMLElement) =>
183
235
  row.getAttribute('aria-label') ??
184
236
  (
185
237
  row.querySelector('.dialkit-labeled-control-label')?.firstChild ??
186
- row.querySelector('.dialkit-select-label') ??
238
+ row.querySelector('.dialkit-select-label, .dialkit-text-label, .dialkit-color-label') ??
187
239
  row
188
240
  ).textContent?.trim() ??
189
241
  '';
@@ -263,19 +315,204 @@ function installHints() {
263
315
  document.addEventListener('scroll', hide, true);
264
316
  }
265
317
 
266
- export function useDials<T extends DialConfig>(name: string, config: T, options?: DialOptions<T>) {
318
+ // Who a dial is for (core/controls.ts). Every dial is internal until marked
319
+ // client-facing: with `client(...)` where it is declared, or by Studio's eye
320
+ // beside its row, which is stored per site and overrules the code. Studio's
321
+ // panel has every dial. A Client's has only the client-facing ones: the others
322
+ // are never handed to DialKit, and code reads their defaults.
323
+
324
+ type Panel = {
325
+ /** Each dial's id by the label path its row shows, as the hints key theirs. */
326
+ byLabel: Record<string, string>;
327
+ inCode: Record<string, ControlAudience>;
328
+ /** Nothing in it for the person looking, so its header leaves the panel. */
329
+ empty: boolean;
330
+ };
331
+ const panels = new Map<string, Panel>();
332
+
333
+ function labelIds(
334
+ panel: string,
335
+ cfg: DialConfig,
336
+ into: Record<string, string>,
337
+ labels = '',
338
+ path: string[] = [],
339
+ ) {
340
+ for (const [k, v] of Object.entries(cfg)) {
341
+ if (k === '_collapsed') continue;
342
+ const label = labels + (actionLabel(v) ?? labelOf(k));
343
+ if (v && typeof v === 'object' && !Array.isArray(v) && !('type' in v))
344
+ labelIds(panel, v as DialConfig, into, label + PATH_SEP, [...path, k]);
345
+ else into[label] = dialId(panel, [...path, k]);
346
+ }
347
+ }
348
+
349
+ /**
350
+ * A panel's config as DialKit takes it (`all`), the part of it the person
351
+ * looking gets (`shown`), and DialKit's own options. Registers the hints too.
352
+ */
353
+ function usePanel<T extends DialConfig>(name: string, config: T, options?: DialOptions<T>) {
267
354
  useLayoutEffect(ensureDialRoot, []);
355
+ const { studio, marks } = useControls();
268
356
  const { hints: h, ...rest } = options ?? {};
269
- registerHints(name, config, h as Record<string, unknown> | undefined);
270
- return useDialKit(name, config, rest);
357
+ const { config: all, dials } = readConfig(name, config);
358
+ const inCode = Object.fromEntries(dials.map((d) => [d.id, d.inCode]));
359
+ const shown = studio
360
+ ? all
361
+ : keepDials(name, all, (id) => dialAudience(marks, id, inCode[id] ?? 'internal') === 'client');
362
+ const byLabel: Record<string, string> = {};
363
+ labelIds(name, all as DialConfig, byLabel);
364
+ panels.set(name, { byLabel, inCode, empty: Object.keys(shown).length === 0 });
365
+ registerHints(name, all as DialConfig, h as Record<string, unknown> | undefined);
366
+ /** What the prototype reads: DialKit's values, with the default of every dial it was not given. */
367
+ const read = (values: unknown) => (studio ? values : withDefaults(all, values as Record<string, unknown>));
368
+ return { shown: shown as T, rest, read };
369
+ }
370
+
371
+ // DialKit draws a header for a panel with no dials in it.
372
+ function tagEmpty(root: HTMLElement) {
373
+ for (const section of root.querySelectorAll<HTMLElement>('.dialkit-folder-section')) {
374
+ const title = section
375
+ .querySelector(':scope > .dialkit-folder-header .dialkit-folder-title')
376
+ ?.textContent?.trim();
377
+ const empty = !!title && !!panels.get(title)?.empty;
378
+ if (empty !== 'dialEmpty' in section.dataset) section.toggleAttribute('data-dial-empty', empty);
379
+ }
380
+ }
381
+
382
+ export function useDials<T extends DialConfig>(name: string, config: T, options?: DialOptions<T>) {
383
+ const { shown, rest, read } = usePanel(name, config, options);
384
+ return read(useDialKit(name, shown, rest)) as ReturnType<typeof useDialKit<T>>;
271
385
  }
272
386
 
273
387
  // The same panel with its controller, for dials that code also sets (every toggle at once).
274
388
  export function useDialsController<T extends DialConfig>(name: string, config: T, options?: DialOptions<T>) {
275
- useLayoutEffect(ensureDialRoot, []);
276
- const { hints: h, ...rest } = options ?? {};
277
- registerHints(name, config, h as Record<string, unknown> | undefined);
278
- return useDialKitController(name, config, rest);
389
+ const { shown, rest, read } = usePanel(name, config, options);
390
+ const controller = useDialKitController(name, shown, rest);
391
+ return { ...controller, values: read(controller.values) } as ReturnType<typeof useDialKitController<T>>;
392
+ }
393
+
394
+ // Studio's eye beside each dial: one click marks it client-facing or internal.
395
+ // DialKit has no slot in a row, so the row gives up 32px at its right end
396
+ // (kit/dials.css) and the eye is drawn over that slot, from outside the row:
397
+ // a click on it never reaches a slider's drag.
398
+
399
+ const EYE_ROWS =
400
+ '.dialkit-slider, .dialkit-labeled-control, .dialkit-select-row, .dialkit-text-control, .dialkit-color-control';
401
+ /** The panel's own sticky header, which a row scrolls under. */
402
+ const PANEL_HEAD = 48;
403
+
404
+ type Spot = { id: string; label: string; top: number; left: number };
405
+
406
+ function spotOf(row: HTMLElement, clip: DOMRect): Spot | null {
407
+ if (row.parentElement?.closest(EYE_ROWS)) return null;
408
+ const { path, panel } = rowPlace(row);
409
+ const label = rowLabel(row);
410
+ const id = panel ? panels.get(panel)?.byLabel[[...path, label].join(PATH_SEP)] : undefined;
411
+ if (!id) return null;
412
+ if (!('dialEye' in row.dataset)) row.dataset.dialEye = '';
413
+ const r = row.getBoundingClientRect();
414
+ const mid = r.top + r.height / 2;
415
+ if (r.height === 0 || mid < clip.top + PANEL_HEAD || mid > clip.bottom - 8) return null;
416
+ return { id, label, top: Math.round(mid), left: Math.round(r.right) };
417
+ }
418
+
419
+ function eyeSpots(): Spot[] {
420
+ const clip = document.querySelector('.dialkit-root .dialkit-panel-inner')?.getBoundingClientRect();
421
+ if (!clip) return [];
422
+ const rows = document.querySelectorAll<HTMLElement>(`.dialkit-root :is(${EYE_ROWS})`);
423
+ return [...rows].flatMap((row) => spotOf(row, clip) ?? []);
424
+ }
425
+
426
+ /** Where each eye sits, followed every frame while Studio can mark: the panel scrolls, folds and is dragged. */
427
+ function useEyeSpots(on: boolean) {
428
+ const [spots, setSpots] = useState<Spot[]>([]);
429
+ useEffect(() => {
430
+ if (!on) return setSpots([]);
431
+ document.documentElement.dataset.dialMarking = '';
432
+ let frame = 0;
433
+ let last = '';
434
+ const tick = () => {
435
+ const next = eyeSpots();
436
+ const sig = JSON.stringify(next);
437
+ if (sig !== last) setSpots(next);
438
+ last = sig;
439
+ frame = requestAnimationFrame(tick);
440
+ };
441
+ tick();
442
+ return () => {
443
+ cancelAnimationFrame(frame);
444
+ delete document.documentElement.dataset.dialMarking;
445
+ };
446
+ }, [on]);
447
+ return spots;
448
+ }
449
+
450
+ const EYE =
451
+ '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';
452
+
453
+ function EyeIcon({ off }: { off: boolean }) {
454
+ return (
455
+ <svg
456
+ width="16"
457
+ height="16"
458
+ viewBox="0 0 24 24"
459
+ fill="none"
460
+ stroke="currentColor"
461
+ strokeWidth="2"
462
+ strokeLinecap="round"
463
+ strokeLinejoin="round"
464
+ aria-hidden="true"
465
+ >
466
+ <path d={EYE} />
467
+ <circle cx="12" cy="12" r="3" />
468
+ {off ? <path d="M4 4l16 16" /> : null}
469
+ </svg>
470
+ );
471
+ }
472
+
473
+ function inCodeOf(id: string): ControlAudience {
474
+ for (const p of panels.values()) if (id in p.inCode) return p.inCode[id];
475
+ return 'internal';
476
+ }
477
+
478
+ function DialEyes() {
479
+ const { studio, canMark, marks, failed } = useControls();
480
+ const spots = useEyeSpots(canMark);
481
+ // DialKit's own tools (Copy parameters, Save version) are Studio's: the panel shows them only under this mark.
482
+ useEffect(() => {
483
+ document.documentElement.toggleAttribute('data-dial-studio', studio);
484
+ }, [studio]);
485
+ if (!canMark) return null;
486
+ return (
487
+ <div data-harness="dial-eyes">
488
+ {spots.map((s) => {
489
+ const on = dialAudience(marks, s.id, inCodeOf(s.id)) === 'client';
490
+ return (
491
+ <button
492
+ key={s.id}
493
+ type="button"
494
+ className="dial-eye"
495
+ style={{ top: s.top, left: s.left }}
496
+ aria-pressed={on}
497
+ aria-label={`Client-facing: ${s.label}`}
498
+ title={
499
+ on
500
+ ? 'Clients get this dial. Click to keep it internal.'
501
+ : 'Internal. Click to give it to clients.'
502
+ }
503
+ onClick={() => void markControl('dial', s.id, on ? 'internal' : 'client')}
504
+ >
505
+ <EyeIcon off={!on} />
506
+ </button>
507
+ );
508
+ })}
509
+ {failed ? (
510
+ <p className="dial-eye-failed" role="alert">
511
+ {failed}
512
+ </p>
513
+ ) : null}
514
+ </div>
515
+ );
279
516
  }
280
517
 
281
518
  // Dial values as CSS variables on an element: `--key`, a folder's as `--folder-key`,
package/kit/harness.css CHANGED
@@ -97,3 +97,37 @@
97
97
  bottom: auto;
98
98
  top: 24px;
99
99
  }
100
+
101
+ /* Who a variant is for (kit/Variants.tsx). In Studio's picker a dot says a
102
+ client gets this one; the eye turns clicks into marks, and the note says so. */
103
+ .proto-picker-item { gap: 6px; }
104
+ .proto-picker-dot {
105
+ width: 6px;
106
+ height: 6px;
107
+ border-radius: 50%;
108
+ box-shadow: inset 0 0 0 1px oklch(1 0 0 / 0.35);
109
+ transition: background-color 120ms cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 120ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
110
+ }
111
+ [data-theirs] > .proto-picker-dot { background: oklch(0.72 0.17 150); box-shadow: none; }
112
+ .proto-picker-item[aria-pressed="false"] { color: oklch(1 0 0 / 0.45); }
113
+ .proto-picker-item[aria-pressed="true"] { color: oklch(1 0 0); }
114
+ .proto-picker-choose { padding: 0 10px; border-radius: 999px; }
115
+ .proto-picker-choose[aria-pressed="true"] { background: oklch(1 0 0 / 0.12); }
116
+ .proto-picker-note {
117
+ position: fixed;
118
+ left: 50%;
119
+ bottom: 72px;
120
+ z-index: 2147483647;
121
+ transform: translateX(-50%);
122
+ margin: 0;
123
+ padding: 4px 12px;
124
+ border-radius: 999px;
125
+ background: oklch(0.145 0 0 / 0.82);
126
+ -webkit-backdrop-filter: blur(12px) saturate(1.4);
127
+ backdrop-filter: blur(12px) saturate(1.4);
128
+ color: oklch(1 0 0 / 0.85);
129
+ font: 500 13px/20px var(--sys-font);
130
+ white-space: nowrap;
131
+ -webkit-font-smoothing: antialiased;
132
+ }
133
+ .proto-picker-note[data-position="top"] { bottom: auto; top: 72px; }