@hadoku/task-ui-components 0.0.0-stage → 4.20.3

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 (169) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +917 -2
  3. package/dist/app-header.css +288 -0
  4. package/dist/bento.css +143 -0
  5. package/dist/button.css +227 -0
  6. package/dist/components/AppHeader.d.ts +61 -0
  7. package/dist/components/AppHeader.d.ts.map +1 -0
  8. package/dist/components/AppHeader.js +23 -0
  9. package/dist/components/AppHeader.js.map +1 -0
  10. package/dist/components/BentoCard.d.ts +23 -0
  11. package/dist/components/BentoCard.d.ts.map +1 -0
  12. package/dist/components/BentoCard.js +49 -0
  13. package/dist/components/BentoCard.js.map +1 -0
  14. package/dist/components/BentoGrid.d.ts +24 -0
  15. package/dist/components/BentoGrid.d.ts.map +1 -0
  16. package/dist/components/BentoGrid.js +22 -0
  17. package/dist/components/BentoGrid.js.map +1 -0
  18. package/dist/components/Button.d.ts +28 -0
  19. package/dist/components/Button.d.ts.map +1 -0
  20. package/dist/components/Button.js +51 -0
  21. package/dist/components/Button.js.map +1 -0
  22. package/dist/components/ConnectedSettings.d.ts +53 -0
  23. package/dist/components/ConnectedSettings.d.ts.map +1 -0
  24. package/dist/components/ConnectedSettings.js +302 -0
  25. package/dist/components/ConnectedSettings.js.map +1 -0
  26. package/dist/components/ConnectedThemePicker.d.ts +52 -0
  27. package/dist/components/ConnectedThemePicker.d.ts.map +1 -0
  28. package/dist/components/ConnectedThemePicker.js +32 -0
  29. package/dist/components/ConnectedThemePicker.js.map +1 -0
  30. package/dist/components/ContextMenu.d.ts +22 -0
  31. package/dist/components/ContextMenu.d.ts.map +1 -0
  32. package/dist/components/ContextMenu.js +23 -0
  33. package/dist/components/ContextMenu.js.map +1 -0
  34. package/dist/components/HadokuThemePicker.d.ts +27 -0
  35. package/dist/components/HadokuThemePicker.d.ts.map +1 -0
  36. package/dist/components/HadokuThemePicker.js +19 -0
  37. package/dist/components/HadokuThemePicker.js.map +1 -0
  38. package/dist/components/LoadingSkeleton.d.ts +14 -0
  39. package/dist/components/LoadingSkeleton.d.ts.map +1 -0
  40. package/dist/components/LoadingSkeleton.js +62 -0
  41. package/dist/components/LoadingSkeleton.js.map +1 -0
  42. package/dist/components/Modal.d.ts +39 -0
  43. package/dist/components/Modal.d.ts.map +1 -0
  44. package/dist/components/Modal.js +106 -0
  45. package/dist/components/Modal.js.map +1 -0
  46. package/dist/components/NumberInput.d.ts +26 -0
  47. package/dist/components/NumberInput.d.ts.map +1 -0
  48. package/dist/components/NumberInput.js +131 -0
  49. package/dist/components/NumberInput.js.map +1 -0
  50. package/dist/components/Select.d.ts +52 -0
  51. package/dist/components/Select.d.ts.map +1 -0
  52. package/dist/components/Select.js +281 -0
  53. package/dist/components/Select.js.map +1 -0
  54. package/dist/components/SettingsModal.d.ts +69 -0
  55. package/dist/components/SettingsModal.d.ts.map +1 -0
  56. package/dist/components/SettingsModal.js +141 -0
  57. package/dist/components/SettingsModal.js.map +1 -0
  58. package/dist/components/ThemeIcons.d.ts +26 -0
  59. package/dist/components/ThemeIcons.d.ts.map +1 -0
  60. package/dist/components/ThemeIcons.js +74 -0
  61. package/dist/components/ThemeIcons.js.map +1 -0
  62. package/dist/components/ThemePicker.d.ts +28 -0
  63. package/dist/components/ThemePicker.d.ts.map +1 -0
  64. package/dist/components/ThemePicker.js +101 -0
  65. package/dist/components/ThemePicker.js.map +1 -0
  66. package/dist/components/Toast.d.ts +13 -0
  67. package/dist/components/Toast.d.ts.map +1 -0
  68. package/dist/components/Toast.js +70 -0
  69. package/dist/components/Toast.js.map +1 -0
  70. package/dist/components/Toaster.d.ts +19 -0
  71. package/dist/components/Toaster.d.ts.map +1 -0
  72. package/dist/components/Toaster.js +19 -0
  73. package/dist/components/Toaster.js.map +1 -0
  74. package/dist/components/Tooltip.d.ts +49 -0
  75. package/dist/components/Tooltip.d.ts.map +1 -0
  76. package/dist/components/Tooltip.js +143 -0
  77. package/dist/components/Tooltip.js.map +1 -0
  78. package/dist/context-menu.css +11 -0
  79. package/dist/controls.css +137 -0
  80. package/dist/hooks/useReducedMotion.d.ts +7 -0
  81. package/dist/hooks/useReducedMotion.d.ts.map +1 -0
  82. package/dist/hooks/useReducedMotion.js +25 -0
  83. package/dist/hooks/useReducedMotion.js.map +1 -0
  84. package/dist/hooks/useToast.d.ts +18 -0
  85. package/dist/hooks/useToast.d.ts.map +1 -0
  86. package/dist/hooks/useToast.js +28 -0
  87. package/dist/hooks/useToast.js.map +1 -0
  88. package/dist/icon-btn.css +64 -0
  89. package/dist/index.d.ts +49 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +72 -0
  92. package/dist/index.js.map +1 -0
  93. package/dist/lib/menuPlacement.d.ts +16 -0
  94. package/dist/lib/menuPlacement.d.ts.map +1 -0
  95. package/dist/lib/menuPlacement.js +19 -0
  96. package/dist/lib/menuPlacement.js.map +1 -0
  97. package/dist/lib/selectMenus.d.ts +30 -0
  98. package/dist/lib/selectMenus.d.ts.map +1 -0
  99. package/dist/lib/selectMenus.js +236 -0
  100. package/dist/lib/selectMenus.js.map +1 -0
  101. package/dist/lib/settingsClient.d.ts +120 -0
  102. package/dist/lib/settingsClient.d.ts.map +1 -0
  103. package/dist/lib/settingsClient.js +140 -0
  104. package/dist/lib/settingsClient.js.map +1 -0
  105. package/dist/lib/themeScope.d.ts +19 -0
  106. package/dist/lib/themeScope.d.ts.map +1 -0
  107. package/dist/lib/themeScope.js +10 -0
  108. package/dist/lib/themeScope.js.map +1 -0
  109. package/dist/lib/titleTooltips.d.ts +38 -0
  110. package/dist/lib/titleTooltips.d.ts.map +1 -0
  111. package/dist/lib/titleTooltips.js +166 -0
  112. package/dist/lib/titleTooltips.js.map +1 -0
  113. package/dist/lib/tooltipPlacement.d.ts +14 -0
  114. package/dist/lib/tooltipPlacement.d.ts.map +1 -0
  115. package/dist/lib/tooltipPlacement.js +34 -0
  116. package/dist/lib/tooltipPlacement.js.map +1 -0
  117. package/dist/modal.css +129 -0
  118. package/dist/number-input.css +131 -0
  119. package/dist/scrollbar.css +165 -0
  120. package/dist/select.css +251 -0
  121. package/dist/styles.css +1866 -0
  122. package/dist/task-ui-components.css +1866 -0
  123. package/dist/theme-picker.css +219 -0
  124. package/dist/toaster.css +159 -0
  125. package/dist/tooltip.css +103 -0
  126. package/dist/types/index.d.ts +37 -0
  127. package/dist/types/index.d.ts.map +1 -0
  128. package/package.json +60 -4
  129. package/src/app-header.css +288 -0
  130. package/src/bento.css +143 -0
  131. package/src/button.css +227 -0
  132. package/src/components/AppHeader.tsx +87 -0
  133. package/src/components/BentoCard.tsx +72 -0
  134. package/src/components/BentoGrid.tsx +48 -0
  135. package/src/components/Button.tsx +81 -0
  136. package/src/components/ConnectedSettings.tsx +465 -0
  137. package/src/components/ConnectedThemePicker.tsx +79 -0
  138. package/src/components/ContextMenu.tsx +48 -0
  139. package/src/components/HadokuThemePicker.tsx +39 -0
  140. package/src/components/LoadingSkeleton.tsx +84 -0
  141. package/src/components/Modal.tsx +171 -0
  142. package/src/components/NumberInput.tsx +161 -0
  143. package/src/components/Select.tsx +359 -0
  144. package/src/components/SettingsModal.tsx +235 -0
  145. package/src/components/ThemeIcons.tsx +127 -0
  146. package/src/components/ThemePicker.tsx +149 -0
  147. package/src/components/Toast.tsx +92 -0
  148. package/src/components/Toaster.tsx +43 -0
  149. package/src/components/Tooltip.tsx +212 -0
  150. package/src/context-menu.css +11 -0
  151. package/src/controls.css +137 -0
  152. package/src/hooks/useReducedMotion.ts +36 -0
  153. package/src/hooks/useToast.ts +57 -0
  154. package/src/icon-btn.css +64 -0
  155. package/src/index.ts +140 -0
  156. package/src/lib/menuPlacement.ts +31 -0
  157. package/src/lib/selectMenus.ts +303 -0
  158. package/src/lib/settingsClient.ts +377 -0
  159. package/src/lib/themeScope.ts +23 -0
  160. package/src/lib/titleTooltips.ts +236 -0
  161. package/src/lib/tooltipPlacement.ts +59 -0
  162. package/src/modal.css +129 -0
  163. package/src/number-input.css +131 -0
  164. package/src/scrollbar.css +165 -0
  165. package/src/select.css +251 -0
  166. package/src/theme-picker.css +219 -0
  167. package/src/toaster.css +159 -0
  168. package/src/tooltip.css +103 -0
  169. package/src/types/index.ts +43 -0
@@ -0,0 +1,465 @@
1
+ /**
2
+ * ConnectedSettings — the unified per-user settings control for the hadoku
3
+ * ecosystem: a gear button that opens a popout housing everything that is a
4
+ * property of the PERSON (not the app):
5
+ * - current access tier (read-only, friendly label)
6
+ * - display name (inline edit → POST /session/name)
7
+ * - global content-visibility level (tiered pill → PUT /prefs/api/v1/content-level)
8
+ * - switch key (an inline sign-in form, on the site's own sign-in client)
9
+ *
10
+ * "Connected" (parallel to ConnectedThemePicker): it self-wires to the
11
+ * hadoku.me edge-router via same-origin fetches (see lib/settingsClient), so
12
+ * dropping `<ConnectedSettings />` into any app under hadoku.me needs zero
13
+ * props. Identity is resolved via whoami() unless the host passes `userType` /
14
+ * `name` (avoids a redundant fetch when the app already knows).
15
+ *
16
+ * All of that is resolved AT MOUNT via `prefetchSettings()`, never on
17
+ * gear-click — opening the popout must cost zero requests. See the effect
18
+ * below, and `e2e/settings-prefetch.spec.ts` in hadoku-task, which fails if the
19
+ * fetch moves back behind the click.
20
+ *
21
+ * Mirrors ThemePicker's controlled-popout pattern: owns its own `open` state +
22
+ * a full-viewport overlay for click-outside dismiss. The content pill renders
23
+ * `maxLevel` segments (friend ⇒ 3, admin ⇒ 4) and is hidden for public callers.
24
+ * maxLevel comes from the server so the tier ceiling is never trusted from the
25
+ * client.
26
+ */
27
+ import React, { useCallback, useEffect, useRef, useState } from 'react'
28
+ import { SettingsIcon } from './ThemeIcons'
29
+ import {
30
+ prefetchSettings,
31
+ setContentLevel,
32
+ setDisplayName,
33
+ loadSignIn,
34
+ switchKeyHref,
35
+ type ContentLevelState,
36
+ type Tier
37
+ } from '../lib/settingsClient'
38
+ import '../app-header.css'
39
+
40
+ export interface ConnectedSettingsProps {
41
+ /** Caller's tier. Omit to self-resolve via whoami().
42
+ *
43
+ * This exists for apps that CANNOT reach `/session/whoami` — conjure sits
44
+ * behind a path-prefixed shim that serves nothing outside `/conjure`, so
45
+ * whoami 404s and the tier would fall back to guest. It is an identity
46
+ * hint, not a way to present a different tier than the edge assigns: every
47
+ * gate that matters is enforced server-side off the edge-stamped tier. */
48
+ userType?: Tier
49
+ /** Display name. Omit to self-resolve via whoami(). Same rationale. */
50
+ name?: string | null
51
+ /** Notify the host (e.g. a "Signed in as …" label) of a rename. */
52
+ onNameChange?: (name: string | null) => void
53
+ /** App-specific settings rendered as a final section in the same popout, so
54
+ * an app with its own preferences keeps ONE unified gear instead of a second
55
+ * control. Shown under an "App preferences" divider.
56
+ *
57
+ * This slot is deliberately unconstrained — put whatever the app needs in
58
+ * it. The constraint is only that it lands AFTER the four canonical rows and
59
+ * cannot change them. */
60
+ children?: React.ReactNode
61
+ }
62
+
63
+ /** Rejection sink for fire-and-forget settings actions. The client helpers
64
+ * already resolve to null on failure (state reflects it), so this only trips
65
+ * on truly unexpected throws — log rather than swallow silently. */
66
+ function reportErr(err: unknown) {
67
+ // task-ui-components v2 dropped its logger; keep the package dependency-free.
68
+ console.error('[ConnectedSettings] action failed', (err as Error)?.message ?? err)
69
+ }
70
+
71
+ const TIER_LABEL: Record<Tier, string> = {
72
+ admin: 'Administrator',
73
+ wife: 'Wife',
74
+ service: 'Service',
75
+ friend: 'Friend',
76
+ public: 'Guest'
77
+ }
78
+
79
+ export function ConnectedSettings({
80
+ userType: userTypeProp,
81
+ name: nameProp,
82
+ onNameChange,
83
+ children
84
+ }: ConnectedSettingsProps) {
85
+ const [open, setOpen] = useState(false)
86
+ const rootRef = useRef<HTMLDivElement>(null)
87
+
88
+ // Identity — from props if supplied, else resolved lazily via whoami().
89
+ const [userType, setUserType] = useState<Tier>(userTypeProp ?? 'public')
90
+ const [resolvedName, setResolvedName] = useState<string | null>(nameProp ?? null)
91
+
92
+ // Name editing
93
+ const [nameDraft, setNameDraft] = useState(resolvedName ?? '')
94
+ const [editingName, setEditingName] = useState(false)
95
+ const [nameSaving, setNameSaving] = useState(false)
96
+ const [displayName, setLocalName] = useState<string | null>(resolvedName)
97
+
98
+ // Key swap. The draft lives only in this state and the input: it is never
99
+ // logged, stored or sent anywhere but the site's sign-in client.
100
+ const [keyFormOpen, setKeyFormOpen] = useState(false)
101
+ const [keyDraft, setKeyDraft] = useState('')
102
+ const [keyBusy, setKeyBusy] = useState(false)
103
+ const [keyError, setKeyError] = useState<string | null>(null)
104
+
105
+ // Content level
106
+ const [content, setContent] = useState<ContentLevelState | null>(null)
107
+ const [levelSaving, setLevelSaving] = useState(false)
108
+
109
+ // One flag for the whole prefetch, not one per request — the panel body
110
+ // reveals when everything has settled, so nothing pops in a beat late. In
111
+ // practice the user never sees it: the prefetch starts at mount and is long
112
+ // done by the time the gear is clicked. It only shows if they click within
113
+ // the first moments of the page.
114
+ const [resolving, setResolving] = useState(true)
115
+
116
+ // Everyone who is SIGNED IN, expressed as "not public" rather than as a list
117
+ // of tiers. The list form (`=== 'admin' || === 'friend' || === 'service'`)
118
+ // is an exact-match allowlist: it silently excluded `wife` the moment that
119
+ // tier existed, which is the failure the rank model is meant to prevent.
120
+ // There is no rank helper in this bundle, but "above public" needs none.
121
+ const showContentPill = userType !== 'public'
122
+
123
+ // Keep local identity in sync when the host controls it via props.
124
+ useEffect(() => {
125
+ if (userTypeProp !== undefined) setUserType(userTypeProp)
126
+ }, [userTypeProp])
127
+ useEffect(() => {
128
+ if (nameProp !== undefined) {
129
+ setResolvedName(nameProp)
130
+ setLocalName(nameProp)
131
+ setNameDraft(nameProp ?? '')
132
+ }
133
+ }, [nameProp])
134
+
135
+ // Resolve everything the panel shows AT MOUNT — not on open.
136
+ //
137
+ // This used to be gated on `open`, which made the gear the trigger for
138
+ // whoami + content-level (167ms / 186ms on prod, concurrent) — a round trip
139
+ // the user waited out with the panel already on screen and blank. Nothing
140
+ // about that data depends on the click:
141
+ // it's the signed-in user's own identity, settled at boot and unchanged for
142
+ // the life of the page. So it rides along with the app's boot traffic, and
143
+ // clicking the gear costs zero requests. `e2e/settings-prefetch.spec.ts` in
144
+ // hadoku-task pins that.
145
+ //
146
+ // The client memoises across callers, so mounting this in several places (or
147
+ // remounting it) does not multiply requests, and on hadoku.me the identity
148
+ // half is free — it awaits the whoami the shell already had in flight.
149
+ useEffect(() => {
150
+ let live = true
151
+ prefetchSettings({ userType: userTypeProp, name: nameProp })
152
+ .then(({ identity, content: state }) => {
153
+ if (!live) return
154
+ // Props stay authoritative: the host passed them because it can see an
155
+ // identity this component can't resolve for itself.
156
+ if (userTypeProp === undefined) {
157
+ setUserType(identity.userType)
158
+ setResolvedName(identity.name)
159
+ setLocalName(identity.name)
160
+ setNameDraft(identity.name ?? '')
161
+ }
162
+ if (state) setContent(state)
163
+ })
164
+ .catch(reportErr)
165
+ .finally(() => {
166
+ if (live) setResolving(false)
167
+ })
168
+ return () => {
169
+ live = false
170
+ }
171
+ // Hints are read once, on the first mount that gets there — the prefetch is
172
+ // page-scoped and a later prop change cannot un-issue it. Identity changes
173
+ // arrive through the sync effects above, and a key swap reloads the page.
174
+ // eslint-disable-next-line react-hooks/exhaustive-deps
175
+ }, [])
176
+
177
+ // Escape closes.
178
+ useEffect(() => {
179
+ if (!open) return
180
+ const onKey = (e: KeyboardEvent) => {
181
+ if (e.key === 'Escape') setOpen(false)
182
+ }
183
+ window.addEventListener('keydown', onKey)
184
+ return () => window.removeEventListener('keydown', onKey)
185
+ }, [open])
186
+
187
+ const saveName = useCallback(async () => {
188
+ const trimmed = nameDraft.trim()
189
+ if (!trimmed || trimmed === displayName) {
190
+ setEditingName(false)
191
+ return
192
+ }
193
+ setNameSaving(true)
194
+ const stored = await setDisplayName(trimmed)
195
+ setNameSaving(false)
196
+ if (stored !== null) {
197
+ setLocalName(stored)
198
+ setNameDraft(stored)
199
+ onNameChange?.(stored)
200
+ }
201
+ setEditingName(false)
202
+ }, [nameDraft, displayName, onNameChange])
203
+
204
+ // Open the form AND start loading the site's sign-in client, which begins its
205
+ // fingerprint collection as it evaluates — so it is ready by submit. Where the
206
+ // client cannot load at all (not on hadoku.me), the page-level /auth flow is
207
+ // the only way to sign in, so go there.
208
+ const openKeyForm = useCallback(() => {
209
+ setKeyFormOpen(true)
210
+ setKeyError(null)
211
+ loadSignIn()
212
+ .then(signIn => {
213
+ if (!signIn) window.location.assign(switchKeyHref())
214
+ })
215
+ .catch(reportErr)
216
+ }, [])
217
+
218
+ const submitKey = useCallback(async () => {
219
+ setKeyBusy(true)
220
+ setKeyError(null)
221
+ const signIn = await loadSignIn()
222
+ if (!signIn) {
223
+ window.location.assign(switchKeyHref())
224
+ return
225
+ }
226
+ try {
227
+ await signIn(keyDraft)
228
+ } catch (err) {
229
+ // A refused key is an inline error, never a redirect.
230
+ setKeyError((err as Error)?.message || 'Invalid key')
231
+ setKeyBusy(false)
232
+ return
233
+ }
234
+ // The page now acts for a different identity: everything must re-mount.
235
+ // Busy stays on through the reload so the form can't be resubmitted.
236
+ window.location.reload()
237
+ }, [keyDraft])
238
+
239
+ const pickLevel = useCallback(
240
+ async (level: number) => {
241
+ if (!content || level === content.level || levelSaving) return
242
+ const prev = content
243
+ setContent({ ...content, level }) // optimistic
244
+ setLevelSaving(true)
245
+ const result = await setContentLevel(level)
246
+ setLevelSaving(false)
247
+ setContent(result ?? prev) // adopt server truth, or revert
248
+ },
249
+ [content, levelSaving]
250
+ )
251
+
252
+ // No caller-supplied class on the root. The four rows below are the
253
+ // platform's, not the app's, and a className here is enough to restyle or
254
+ // hide any of them — which is the drift this component exists to prevent.
255
+ // Apps extend via `children`, never by reaching into this markup.
256
+ return (
257
+ <div className="settings-popout" ref={rootRef}>
258
+ <button
259
+ type="button"
260
+ className="app-header__icon-btn settings-toggle-btn"
261
+ aria-label="User settings"
262
+ aria-expanded={open}
263
+ onClick={() => setOpen(v => !v)}
264
+ >
265
+ <SettingsIcon />
266
+ </button>
267
+
268
+ {open && <div className="settings-popout__overlay" onClick={() => setOpen(false)} />}
269
+
270
+ {open && (
271
+ <div className="settings-popout__panel" role="dialog" aria-label="User settings">
272
+ <div className="settings-popout__header">Settings</div>
273
+
274
+ {/* Access tier. While resolving, the state still says 'public' —
275
+ rendering "Guest" there would be a wrong answer that corrects
276
+ itself a moment later, which reads exactly like the lag this
277
+ placeholder exists to remove. */}
278
+ <section className="settings-popout__row">
279
+ <span className="settings-popout__label">Access tier</span>
280
+ {resolving ? (
281
+ <span className="settings-popout__value">…</span>
282
+ ) : (
283
+ <span className={`settings-popout__tier settings-popout__tier--${userType}`}>
284
+ {TIER_LABEL[userType]}
285
+ </span>
286
+ )}
287
+ </section>
288
+
289
+ {/* Display name */}
290
+ <section className="settings-popout__row">
291
+ <span className="settings-popout__label">Display name</span>
292
+ {resolving ? (
293
+ <span className="settings-popout__value">…</span>
294
+ ) : editingName ? (
295
+ <span className="settings-popout__inline">
296
+ <input
297
+ className="settings-popout__input"
298
+ value={nameDraft}
299
+ maxLength={64}
300
+ autoFocus
301
+ disabled={nameSaving}
302
+ onChange={e => setNameDraft(e.target.value)}
303
+ onKeyDown={e => {
304
+ if (e.key === 'Enter') {
305
+ saveName().catch(reportErr)
306
+ }
307
+ if (e.key === 'Escape') {
308
+ setEditingName(false)
309
+ setNameDraft(displayName ?? '')
310
+ }
311
+ }}
312
+ />
313
+ <button
314
+ type="button"
315
+ className="settings-popout__btn settings-popout__btn--primary"
316
+ disabled={nameSaving}
317
+ onClick={() => {
318
+ saveName().catch(reportErr)
319
+ }}
320
+ >
321
+ {nameSaving ? '…' : 'Save'}
322
+ </button>
323
+ </span>
324
+ ) : (
325
+ <span className="settings-popout__inline">
326
+ <span className="settings-popout__value">{displayName || 'Unnamed'}</span>
327
+ <button
328
+ type="button"
329
+ className="settings-popout__btn"
330
+ onClick={() => {
331
+ setNameDraft(displayName ?? '')
332
+ setEditingName(true)
333
+ }}
334
+ >
335
+ Edit
336
+ </button>
337
+ </span>
338
+ )}
339
+ </section>
340
+
341
+ {/* Content visibility level. Held back until the first-open fetch
342
+ settles, so it lands in the same paint as the tier and name
343
+ rather than a round trip behind them. `content` is fetched
344
+ concurrently with whoami(), so by then it is already here. */}
345
+ {!resolving && showContentPill && (
346
+ <section className="settings-popout__row settings-popout__row--stack">
347
+ <span className="settings-popout__label">Content visibility</span>
348
+ {content ? (
349
+ <>
350
+ <div
351
+ className="settings-popout__pill"
352
+ role="radiogroup"
353
+ aria-label="Content visibility level"
354
+ >
355
+ {Array.from({ length: content.maxLevel }, (_, i) => i + 1).map(lvl => (
356
+ <button
357
+ key={lvl}
358
+ type="button"
359
+ role="radio"
360
+ aria-checked={lvl === content.level}
361
+ aria-label={`Level ${lvl}`}
362
+ className={`settings-popout__seg${
363
+ lvl <= content.level ? ' settings-popout__seg--filled' : ''
364
+ }`}
365
+ disabled={levelSaving}
366
+ onClick={() => {
367
+ pickLevel(lvl).catch(reportErr)
368
+ }}
369
+ >
370
+ {lvl}
371
+ </button>
372
+ ))}
373
+ </div>
374
+ <span className="settings-popout__hint">
375
+ Higher levels reveal more mature content across apps. Level 1 is
376
+ safe-for-everyone.
377
+ </span>
378
+ </>
379
+ ) : (
380
+ // Not "Loading…" — the fetch has already settled by the time
381
+ // this section renders at all, so a null here means it failed.
382
+ <span className="settings-popout__hint">Currently unavailable.</span>
383
+ )}
384
+ </section>
385
+ )}
386
+
387
+ {/* Switch key. Signs in inline through the SITE's sign-in client
388
+ (the /auth page's own code path), never a post of ours. A real
389
+ <form> with a username + current-password pair, so password
390
+ managers offer and save the key. */}
391
+ {keyFormOpen ? (
392
+ <section className="settings-popout__row settings-popout__row--stack">
393
+ <form
394
+ className="settings-popout__key-form"
395
+ onSubmit={e => {
396
+ e.preventDefault()
397
+ submitKey().catch(reportErr)
398
+ }}
399
+ >
400
+ <input
401
+ type="text"
402
+ name="username"
403
+ autoComplete="username"
404
+ value="hadoku"
405
+ readOnly
406
+ hidden
407
+ />
408
+ <label className="settings-popout__label" htmlFor="settings-popout-key">
409
+ Access key
410
+ </label>
411
+ <span className="settings-popout__inline">
412
+ <input
413
+ id="settings-popout-key"
414
+ className="settings-popout__input"
415
+ type="password"
416
+ name="password"
417
+ autoComplete="current-password"
418
+ autoCapitalize="none"
419
+ spellCheck={false}
420
+ autoFocus
421
+ value={keyDraft}
422
+ disabled={keyBusy}
423
+ aria-invalid={keyError !== null}
424
+ aria-describedby={keyError ? 'settings-popout-key-error' : undefined}
425
+ onChange={e => setKeyDraft(e.target.value)}
426
+ />
427
+ <button
428
+ type="submit"
429
+ className="settings-popout__btn settings-popout__btn--primary"
430
+ disabled={keyBusy}
431
+ >
432
+ {keyBusy ? 'Signing in…' : 'Sign in'}
433
+ </button>
434
+ </span>
435
+ {keyError && (
436
+ <span
437
+ id="settings-popout-key-error"
438
+ className="settings-popout__error"
439
+ role="alert"
440
+ >
441
+ {keyError}
442
+ </span>
443
+ )}
444
+ </form>
445
+ </section>
446
+ ) : (
447
+ <section className="settings-popout__row">
448
+ <span className="settings-popout__label">Access key</span>
449
+ <button type="button" className="settings-popout__btn" onClick={openKeyForm}>
450
+ Switch key
451
+ </button>
452
+ </section>
453
+ )}
454
+
455
+ {/* App-specific settings (optional) — same popout, one gear. */}
456
+ {children && (
457
+ <section className="settings-popout__row settings-popout__row--stack settings-popout__app">
458
+ {children}
459
+ </section>
460
+ )}
461
+ </div>
462
+ )}
463
+ </div>
464
+ )
465
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * ConnectedThemePicker - Stateful theme picker component
3
+ * A convenience wrapper around ThemePicker with built-in state management
4
+ */
5
+
6
+ import React from 'react'
7
+ import { ThemePicker } from './ThemePicker'
8
+ import type { ThemeFamily, DropdownPlacement } from '../types'
9
+
10
+ export interface ConnectedThemePickerProps {
11
+ /** Available theme families */
12
+ themeFamilies: ThemeFamily[]
13
+ /** Current active theme */
14
+ currentTheme: string
15
+ /** Callback when theme is changed */
16
+ onThemeChange: (theme: string) => void
17
+ /** Optional: Function to get icon for current theme (for toggle button) */
18
+ getThemeIcon?: (theme: string) => React.ReactNode
19
+ /** Optional: CSS class name for the container */
20
+ className?: string
21
+ /** Optional callback when settings icon is clicked */
22
+ onSettingsClick?: () => void
23
+ /** Optional: Direction the dropdown opens. Defaults to 'auto' (edge detection) */
24
+ dropdownPlacement?: DropdownPlacement
25
+ }
26
+
27
+ /**
28
+ * ConnectedThemePicker - A stateful theme picker with built-in open/close state management
29
+ *
30
+ * This component manages its own isOpen state, making it easier to use than the base ThemePicker.
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * import { ConnectedThemePicker } from '@wolffm/task-ui-components'
35
+ * import { THEME_FAMILIES, THEME_ICON_MAP } from '@wolffm/themes'
36
+ * import '@wolffm/task-ui-components/theme-picker.css'
37
+ *
38
+ * function App() {
39
+ * const { theme, setTheme } = useTheme()
40
+ *
41
+ * return (
42
+ * <ConnectedThemePicker
43
+ * themeFamilies={THEME_FAMILIES}
44
+ * currentTheme={theme}
45
+ * onThemeChange={setTheme}
46
+ * getThemeIcon={(theme) => {
47
+ * const Icon = THEME_ICON_MAP[theme]
48
+ * return Icon ? <Icon /> : null
49
+ * }}
50
+ * />
51
+ * )
52
+ * }
53
+ * ```
54
+ */
55
+ export function ConnectedThemePicker({
56
+ themeFamilies,
57
+ currentTheme,
58
+ onThemeChange,
59
+ getThemeIcon,
60
+ className,
61
+ onSettingsClick,
62
+ dropdownPlacement
63
+ }: ConnectedThemePickerProps) {
64
+ const [isOpen, setIsOpen] = React.useState(false)
65
+
66
+ return (
67
+ <ThemePicker
68
+ currentTheme={currentTheme}
69
+ isOpen={isOpen}
70
+ themeFamilies={themeFamilies}
71
+ onThemeChange={onThemeChange}
72
+ onToggle={() => setIsOpen(!isOpen)}
73
+ getThemeIcon={getThemeIcon}
74
+ className={className}
75
+ onSettingsClick={onSettingsClick}
76
+ dropdownPlacement={dropdownPlacement}
77
+ />
78
+ )
79
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * ContextMenu Component
3
+ * Generic context menu with position-based rendering
4
+ */
5
+
6
+ import React from 'react'
7
+ import '../context-menu.css'
8
+
9
+ export interface ContextMenuItem {
10
+ /** ReactNode, not string, so callers can put an <Icon> beside the text. */
11
+ label: React.ReactNode
12
+ onClick: () => void | Promise<void>
13
+ isDanger?: boolean
14
+ disabled?: boolean
15
+ }
16
+
17
+ export interface ContextMenuProps {
18
+ isOpen: boolean
19
+ x: number
20
+ y: number
21
+ items: ContextMenuItem[]
22
+ className?: string
23
+ }
24
+
25
+ export function ContextMenu({ isOpen, x, y, items, className = 'context-menu' }: ContextMenuProps) {
26
+ if (!isOpen) return null
27
+
28
+ // Use CSS custom properties for dynamic positioning
29
+ const style = {
30
+ '--context-menu-x': `${x}px`,
31
+ '--context-menu-y': `${y}px`
32
+ } as React.CSSProperties
33
+
34
+ return (
35
+ <div className={className} style={style}>
36
+ {items.map((item, index) => (
37
+ <button
38
+ key={index}
39
+ className={`context-menu-item ${item.isDanger ? 'context-menu-item--danger' : ''}`}
40
+ onClick={item.onClick}
41
+ disabled={item.disabled}
42
+ >
43
+ {item.label}
44
+ </button>
45
+ ))}
46
+ </div>
47
+ )
48
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * HadokuThemePicker — the platform theme picker, placeable anywhere, and
3
+ * configurable nowhere.
4
+ *
5
+ * WHY THIS EXISTS
6
+ * ---------------
7
+ * Locking the picker inside AppHeader made it uniform, but it also made it
8
+ * unreachable for an app that has no header row. watchpart2 is that app: its
9
+ * UI is an overlay on a video surface, and its picker lives in the chat panel's
10
+ * button strip. Under a header-only API its only options were to grow a header
11
+ * it does not want, or keep hand-rolling — and hand-rolling is what this whole
12
+ * effort removes.
13
+ *
14
+ * So the enforcement is not "you may not PLACE the picker", it is "you may not
15
+ * CONFIGURE it". This component takes no props at all. There is no themeFamilies
16
+ * to pass a different list to, no getThemeIcon to slip a debug logger into, no
17
+ * className to restyle it with, no isOpen to manage differently — those props
18
+ * are exactly how the old ConnectedThemePicker drifted. Everything comes from
19
+ * <HadokuThemeRoot>.
20
+ *
21
+ * AppHeader renders this internally. An app with no header renders it directly.
22
+ * Both get the identical control, because there is no way to ask for a
23
+ * different one.
24
+ */
25
+ import React from 'react'
26
+ import { ConnectedThemePicker } from './ConnectedThemePicker'
27
+ import { useHadokuTheme } from '@wolffm/themes'
28
+
29
+ export function HadokuThemePicker() {
30
+ const t = useHadokuTheme()
31
+ return (
32
+ <ConnectedThemePicker
33
+ themeFamilies={t.themeFamilies}
34
+ currentTheme={t.theme}
35
+ onThemeChange={t.setTheme}
36
+ getThemeIcon={t.getThemeIcon}
37
+ />
38
+ )
39
+ }