@huaqiu/dsh-hardware-ui 0.7.18 → 0.7.19

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.
@@ -0,0 +1,724 @@
1
+ /**
2
+ * The toolchain surfaces that are not the wizard itself: the install card, the
3
+ * transient notice overlay, and the quiet sidebar indicator.
4
+ *
5
+ * Layout and wording follow `docs/prototype/huaqiu_eda_hardware_toolchain_ux_prototype.html`
6
+ * (a letter badge + status pill per card, one path row with `Select Local File`,
7
+ * the download bar, and an inline progress block). One component serves both the
8
+ * wizard and Settings — a text or a fix lands in both places at once (§10.5) —
9
+ * with `variant` selecting the few strings the prototype differentiates.
10
+ *
11
+ * Everything here is a projection of {@link ToolchainController}: no component
12
+ * keeps its own copy of "configured" or of a path. Styling is self-drawn from
13
+ * `theme.ts`; this bundle declares no runtime dependency beyond `react`, `slots`
14
+ * and `locale`.
15
+ *
16
+ * @module @huaqiu/dsh-hardware-ui/client/toolchain-view
17
+ */
18
+ import { createElement, Fragment, useSyncExternalStore, type CSSProperties, type ReactNode } from 'react'
19
+ import { COPY } from './copy.js'
20
+ import {
21
+ jobPercent, jobRunning, setupIncomplete, setupSummary,
22
+ type InstallJob, type ToolStatus, type ToolchainController, type ToolchainId,
23
+ type ToolchainSnapshot,
24
+ } from './toolchain.js'
25
+ import {
26
+ buttonStyle, C, cardStyle, disabled, dotStyle, INPUT, MONO, MONO_TEXT, MUTED, pillStyle, R,
27
+ } from './theme.js'
28
+
29
+ /** Keeping the controller's snapshot subscribed is one call; every surface uses it. */
30
+ export function useToolchain(controller: ToolchainController): ToolchainSnapshot {
31
+ return useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot)
32
+ }
33
+
34
+ /** Product identity of one tool, with the prototype's badge colour. */
35
+ const TOOL_META = {
36
+ kicad: {
37
+ name: (): string => COPY.wizard.kicadTitle,
38
+ short: 'KiCad',
39
+ letter: 'Ki',
40
+ color: '#2563EB',
41
+ accent: '#60A5FA',
42
+ bar: '#3B82F6',
43
+ /** The prototype shows the CLI name beside the title for KiCad only. */
44
+ code: 'kicad-cli' as string | undefined,
45
+ },
46
+ solidcraft: {
47
+ name: (): string => COPY.wizard.solidcraftTitle,
48
+ short: 'SolidCraft',
49
+ letter: 'Sc',
50
+ color: '#B45309',
51
+ accent: '#FBBF24',
52
+ bar: '#F59E0B',
53
+ code: undefined as string | undefined,
54
+ },
55
+ } as const
56
+
57
+ /** Stroke props shared by every glyph in this surface. */
58
+ const STROKE = { fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round' } as const
59
+
60
+ /**
61
+ * One small line icon.
62
+ *
63
+ * The prototype uses inline SVGs; taking an icon dependency for five glyphs would
64
+ * be the tail wagging the dog, so they are drawn from path data here.
65
+ */
66
+ function Icon(props: { readonly path: string; readonly size?: number; readonly color?: string; readonly extra?: string }): ReactNode {
67
+ return createElement(
68
+ 'svg',
69
+ {
70
+ viewBox: '0 0 24 24', width: props.size ?? 14, height: props.size ?? 14, 'aria-hidden': true,
71
+ style: { flex: '0 0 auto', color: props.color ?? 'inherit' },
72
+ },
73
+ createElement('path', { d: props.path, ...STROKE }),
74
+ ...(props.extra === undefined ? [] : [createElement('path', { d: props.extra, ...STROKE })]),
75
+ )
76
+ }
77
+
78
+ /** Glyph paths: folder, download, info, gear, close. */
79
+ export const TOOLCHAIN_ICONS = {
80
+ folder: 'M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V7z',
81
+ download: 'M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4M7 10l5 5 5-5M12 15V3',
82
+ info: 'M12 16v-4M12 8h.01',
83
+ gear: 'M12 3v2M12 19v2M3 12h2M19 12h2M6.4 6.4l1.4 1.4M16.2 16.2l1.4 1.4M17.6 6.4l-1.4 1.4M7.8 16.2L6.4 17.6',
84
+ close: 'M6 18L18 6M6 6l12 12',
85
+ /** Executable row in the picker (prototype's document glyph). */
86
+ file: 'M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z',
87
+ } as const
88
+
89
+ /** Small square letter badge ("Ki" / "Sc") in the prototype's tool colour. */
90
+ function LetterBadge(props: { readonly letter: string; readonly color: string; readonly size: number }): ReactNode {
91
+ return createElement('span', {
92
+ style: {
93
+ width: props.size, height: props.size, borderRadius: props.size >= 28 ? 8 : 6,
94
+ display: 'flex', alignItems: 'center', justifyContent: 'center', flex: '0 0 auto',
95
+ background: props.color, color: '#fff', fontWeight: 700,
96
+ fontSize: props.size >= 28 ? 12 : 11, fontFamily: MONO,
97
+ },
98
+ }, props.letter)
99
+ }
100
+
101
+ /** Muted chip for "Required for PCB/Sch" / "Optional • MCAD". */
102
+ function Chip(props: { readonly text: string }): ReactNode {
103
+ return createElement('span', {
104
+ style: {
105
+ fontSize: 10, padding: '2px 6px', borderRadius: 4, background: 'rgba(255,255,255,0.08)',
106
+ color: C.text2, whiteSpace: 'nowrap',
107
+ },
108
+ }, props.text)
109
+ }
110
+
111
+ /**
112
+ * Tone of the status pill for one tool, from its authoritative state (§10.3).
113
+ *
114
+ * Green only ever follows a successful validation; a running job reports
115
+ * progress; a failure is red.
116
+ */
117
+ export function statusPill(
118
+ tool: ToolStatus,
119
+ job: InstallJob | undefined,
120
+ ): { readonly text: string; readonly tone: 'ok' | 'warn' | 'info' | 'muted' | 'accent' } {
121
+ if (job !== undefined && job.tool === tool.tool && jobRunning(job)) {
122
+ const percent = jobPercent(job)
123
+ if (job.phase === 'download') {
124
+ return { text: COPY.toolchain.statusDownloading(`${percent ?? 0}%`), tone: 'info' }
125
+ }
126
+ return { text: COPY.toolchain.statusExtracting, tone: 'info' }
127
+ }
128
+ if (job !== undefined && job.tool === tool.tool && job.phase === 'failed') {
129
+ return { text: COPY.toolchain.statusFailed, tone: 'accent' }
130
+ }
131
+ switch (tool.state) {
132
+ case 'configured': return { text: `v${tool.version ?? '?'}`, tone: 'ok' }
133
+ case 'invalid': return { text: COPY.toolchain.statusInvalid, tone: 'accent' }
134
+ case 'validating': return { text: COPY.toolchain.statusValidating, tone: 'muted' }
135
+ default: return { text: COPY.toolchain.statusNotConfigured, tone: 'warn' }
136
+ }
137
+ }
138
+
139
+ /** One line describing what discovery found, or that it is still looking. */
140
+ export function discoveryLine(tool: ToolStatus): { readonly text: string; readonly tone: 'muted' | 'ok' | 'warn' } | undefined {
141
+ const discovery = tool.discovery
142
+ if (discovery.state === 'running') return { text: COPY.toolchain.discovering, tone: 'muted' }
143
+ if (discovery.state === 'failed') return { text: discovery.error ?? COPY.toolchain.notDetected, tone: 'warn' }
144
+ const selected = discovery.selected
145
+ if (selected !== undefined && selected.valid && tool.state !== 'configured') {
146
+ return { text: COPY.toolchain.detected(selected.path, selected.version ?? '?'), tone: 'ok' }
147
+ }
148
+ if (selected !== undefined && !selected.valid) {
149
+ return { text: COPY.toolchain.detectedInvalid(selected.path, selected.error ?? COPY.toolchain.notDetected), tone: 'warn' }
150
+ }
151
+ return undefined
152
+ }
153
+
154
+ /**
155
+ * The 6px track. `flex: 0 0 auto` matters: this sits in a column flex box whose
156
+ * height is content-driven, and a growing item there collapses to zero height —
157
+ * which is exactly how the bar was invisible while the percentage next to it kept
158
+ * counting up.
159
+ */
160
+ const PROGRESS_TRACK: CSSProperties = {
161
+ position: 'relative', height: 6, minHeight: 6, flex: '0 0 auto', borderRadius: 999,
162
+ background: 'rgba(0,0,0,0.5)', overflow: 'hidden',
163
+ }
164
+
165
+ /** Inline download progress: label + percent on one line, bar underneath (§7.4). */
166
+ function Progress(props: { readonly job: InstallJob; readonly color: string }): ReactNode {
167
+ const percent = jobPercent(props.job) ?? 0
168
+ return createElement(
169
+ 'div',
170
+ { style: { display: 'flex', flexDirection: 'column', gap: 6, paddingTop: 8, borderTop: `1px solid ${C.borderSoft}` } },
171
+ createElement(
172
+ 'div',
173
+ { style: { display: 'flex', justifyContent: 'space-between', gap: 8, fontSize: 11, fontFamily: MONO, color: props.color } },
174
+ createElement('span', { style: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
175
+ props.job.message === '' ? COPY.toolchain.downloading : props.job.message),
176
+ createElement('span', { style: { flex: '0 0 auto' } }, `${percent}%`),
177
+ ),
178
+ createElement(
179
+ 'div',
180
+ { style: PROGRESS_TRACK, role: 'progressbar', 'aria-valuenow': percent, 'aria-valuemin': 0, 'aria-valuemax': 100 },
181
+ createElement('div', {
182
+ style: { position: 'absolute', inset: 0, width: `${percent}%`, background: props.color, transition: 'width 150ms ease' },
183
+ }),
184
+ ),
185
+ )
186
+ }
187
+
188
+ /**
189
+ * One installation card.
190
+ *
191
+ * `variant: 'wizard'` reproduces the first-run prototype card (chip, "Select
192
+ * Local File...", "Don't have KiCad? … Download from HuaQiu Server");
193
+ * `variant: 'settings'` reproduces the Settings card (longer description,
194
+ * "Browse...", a verdict line beside the validate button, and an inline download
195
+ * link). Both read the same Host status, so neither can claim something the other
196
+ * denies.
197
+ *
198
+ * The executable picker is rendered **by the card that opened it**, not by an
199
+ * overlay seat: the shell's overlay layer paints below the settings modal, so a
200
+ * picker hosted there would end up behind the very dialog that asked for it.
201
+ */
202
+ export function ToolchainCard(props: {
203
+ readonly tool: ToolchainId
204
+ readonly controller: ToolchainController
205
+ readonly snapshot: ToolchainSnapshot
206
+ readonly variant: 'wizard' | 'settings'
207
+ }): ReactNode {
208
+ const { controller, snapshot, variant, tool: id } = props
209
+ const meta = TOOL_META[id]
210
+ const tool = snapshot.status?.[id]
211
+ // Each tool owns its own job: two downloads in flight are two bars, not one.
212
+ const job = snapshot.jobs[id]
213
+ const draft = snapshot.drafts[id]
214
+ const saving = snapshot.saving === id
215
+ const running = jobRunning(job)
216
+ const pill = tool === undefined
217
+ ? { text: COPY.toolchain.statusValidating, tone: 'muted' as const }
218
+ : statusPill(tool, job)
219
+ const entry = tool?.download
220
+ const busy = running || saving
221
+
222
+ const onSave = (): void => { void controller.save(id, controller.getSnapshot().drafts[id]) }
223
+
224
+ // Header: badge + name (+ CLI name) + chip, status pill on the right.
225
+ const header = createElement(
226
+ 'div',
227
+ { style: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 8, minWidth: 0 } },
228
+ createElement(
229
+ 'div',
230
+ { style: { display: 'flex', alignItems: 'center', gap: 10, minWidth: 0 } },
231
+ createElement(LetterBadge, { letter: meta.letter, color: meta.color, size: variant === 'wizard' ? 28 : 24 }),
232
+ createElement(
233
+ 'div',
234
+ { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } },
235
+ createElement(
236
+ 'div',
237
+ { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
238
+ createElement('span', { style: { fontSize: 13, fontWeight: 600, color: C.text } }, meta.name()),
239
+ ...(meta.code === undefined
240
+ ? []
241
+ : [createElement('code', { key: 'code', style: { fontSize: 11, fontFamily: MONO, color: meta.accent } }, `(${meta.code})`)]),
242
+ variant === 'wizard'
243
+ ? createElement(Chip, { text: id === 'kicad' ? COPY.wizard.kicadChip : COPY.wizard.solidcraftChip })
244
+ : null,
245
+ ),
246
+ variant === 'wizard'
247
+ ? createElement('span', { style: { fontSize: 11, color: C.text3 } },
248
+ id === 'kicad' ? COPY.wizard.kicadBlurb : COPY.wizard.solidcraftBlurb)
249
+ : null,
250
+ ),
251
+ ),
252
+ createElement('span', { style: pillStyle(pill.tone) }, pill.text),
253
+ )
254
+
255
+ const description = variant === 'settings'
256
+ ? createElement('p', { style: { ...MUTED, lineHeight: 1.6 } },
257
+ id === 'kicad' ? COPY.settings.kicadBlurb : COPY.settings.solidcraftBlurb)
258
+ : null
259
+
260
+ // Path row: the placeholder is the prototype's own example path for the
261
+ // wizard, and its "paste or browse" hint in Settings.
262
+ const pathRow = createElement(
263
+ 'div',
264
+ { style: { display: 'flex', gap: 8, minWidth: 0 } },
265
+ createElement('input', {
266
+ style: { ...INPUT, flex: 1, minWidth: 0, fontFamily: MONO, fontSize: 11 },
267
+ value: draft, spellCheck: false, disabled: busy,
268
+ placeholder: id === 'kicad'
269
+ ? (variant === 'wizard' ? COPY.wizard.kicadPlaceholder : COPY.settings.kicadPlaceholder)
270
+ : (variant === 'wizard' ? COPY.wizard.solidcraftPlaceholder : COPY.settings.solidcraftPlaceholder),
271
+ 'aria-label': COPY.settings.pathField(meta.short),
272
+ onChange: (event: { currentTarget: { value: string } }) => controller.setDraft(id, event.currentTarget.value),
273
+ onKeyDown: (event: { key: string }) => { if (event.key === 'Enter') onSave() },
274
+ }),
275
+ createElement('button', {
276
+ type: 'button',
277
+ style: { ...buttonStyle('secondary', { display: 'flex', alignItems: 'center', gap: 6, flex: '0 0 auto' }), ...disabled(busy) },
278
+ disabled: busy,
279
+ title: COPY.toolchain.browseTitle,
280
+ onClick: () => { controller.openPicker(id) },
281
+ },
282
+ createElement(Icon, { path: TOOLCHAIN_ICONS.folder, color: '#FBBF24' }),
283
+ variant === 'wizard' ? COPY.wizard.selectFile : COPY.toolchain.browse),
284
+ )
285
+
286
+ // Verdict beside the validate button, in the prototype's muted mono voice.
287
+ //
288
+ // It reports what the Host knows — except while the field holds an edit the Host
289
+ // has never seen, where saying "awaiting executable path" beside a filled input
290
+ // would be plainly false.
291
+ const savedRoot = tool?.installPath ?? ''
292
+ const dirty = draft.trim() !== '' && draft.trim() !== savedRoot
293
+ const statusText = dirty
294
+ ? COPY.settings.statusUnsaved
295
+ : tool?.state === 'configured'
296
+ ? (tool.cliPath ?? COPY.settings.statusVerified)
297
+ : tool?.error ?? COPY.settings.statusAwaiting
298
+
299
+ const validateRow = createElement(
300
+ 'div',
301
+ { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap', minWidth: 0 } },
302
+ createElement('button', {
303
+ type: 'button',
304
+ style: { ...buttonStyle('secondary'), ...disabled(busy) },
305
+ disabled: busy,
306
+ onClick: onSave,
307
+ }, saving ? COPY.settings.validating : COPY.settings.validate),
308
+ variant === 'settings'
309
+ ? createElement('span', {
310
+ style: { ...MONO_TEXT, fontSize: 11, maxWidth: 260, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
311
+ title: statusText,
312
+ }, statusText)
313
+ : null,
314
+ )
315
+
316
+ /** Download affordance: a plugin job first, the vendor page as the honest fallback. */
317
+ const download = entry === undefined && tool !== undefined
318
+ ? officialFallback(id, snapshot)
319
+ : createElement('a', {
320
+ href: entry?.url ?? snapshot.status?.official[id] ?? '#',
321
+ target: '_blank',
322
+ rel: 'noreferrer noopener',
323
+ style: {
324
+ display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 11, fontWeight: 500,
325
+ color: meta.accent, textDecoration: 'none', padding: '4px 8px', borderRadius: R.sm, whiteSpace: 'nowrap',
326
+ },
327
+ onClick: (event?: { preventDefault?: () => void }) => {
328
+ // A download is a plugin-owned job (progress, checksum, promotion) rather
329
+ // than a browser transfer; href stays as the fallback if the click fails.
330
+ if (entry === undefined) return
331
+ event?.preventDefault?.()
332
+ void controller.install(id)
333
+ },
334
+ },
335
+ createElement(Icon, { path: TOOLCHAIN_ICONS.download, color: meta.accent }),
336
+ variant === 'settings'
337
+ ? COPY.settings.download(id, entry?.version ?? '?')
338
+ : COPY.wizard.serverDownload)
339
+
340
+ // The prototype's wizard card carries no per-card validate button: the modal
341
+ // footer's `Save & Get Started` validates and saves both tools at once.
342
+ const actionRow = variant === 'settings'
343
+ ? createElement(
344
+ 'div',
345
+ { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, flexWrap: 'wrap' } },
346
+ validateRow,
347
+ download,
348
+ )
349
+ : null
350
+
351
+ // The wizard puts the download in its own bordered bar, as the prototype does.
352
+ const downloadBar = variant === 'wizard'
353
+ ? createElement(
354
+ 'div',
355
+ {
356
+ style: {
357
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8,
358
+ paddingTop: 8, borderTop: `1px solid ${C.borderSoft}`, fontSize: 11, color: C.text3,
359
+ },
360
+ },
361
+ createElement(
362
+ 'div',
363
+ { style: { display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 } },
364
+ createElement(Icon, { path: TOOLCHAIN_ICONS.download, color: C.text3 }),
365
+ createElement('span', { style: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
366
+ COPY.wizard.dontHave(meta.short)),
367
+ createElement('span', { style: { ...MONO_TEXT, fontSize: 11, color: C.text2, whiteSpace: 'nowrap' } },
368
+ entry === undefined ? COPY.toolchain.notDetected : `v${entry.version} (Win x64)`),
369
+ ),
370
+ download,
371
+ )
372
+ : null
373
+
374
+ const card = createElement(
375
+ 'div',
376
+ {
377
+ style: cardStyle({ gap: variant === 'wizard' ? 10 : 12, padding: variant === 'wizard' ? 14 : 16 }),
378
+ 'data-hardware-toolchain-card': id,
379
+ 'data-variant': variant,
380
+ },
381
+ header,
382
+ ...(description === null ? [] : [description]),
383
+ pathRow,
384
+ ...(actionRow === null ? [] : [actionRow]),
385
+ ...(downloadBar === null ? [] : [downloadBar]),
386
+ ...(running && job !== undefined ? [Progress({ job, color: meta.bar })] : []),
387
+ )
388
+
389
+ const picker = snapshot.picker === undefined || snapshot.picker.tool !== id
390
+ ? null
391
+ : createElement(ExecutablePicker, { controller, picker: snapshot.picker })
392
+ return picker === null ? card : createElement(Fragment, null, card, picker)
393
+ }
394
+
395
+ /** §9.2: no in-app build for this platform means the vendor page, never a fake button. */
396
+ function officialFallback(tool: ToolchainId, snapshot: ToolchainSnapshot): ReactNode {
397
+ return createElement('a', {
398
+ href: snapshot.status?.official[tool] ?? '#',
399
+ target: '_blank',
400
+ rel: 'noreferrer noopener',
401
+ style: { fontSize: 11, color: C.info, textDecoration: 'none', whiteSpace: 'nowrap' },
402
+ }, COPY.toolchain.official)
403
+ }
404
+
405
+ /** Colour of one notice tone, for the overlay's dot and border. */
406
+ function toastTone(tone: 'ok' | 'warn' | 'error' | 'info'): { readonly color: string; readonly background: string } {
407
+ switch (tone) {
408
+ case 'ok': return { color: C.ok, background: C.okSoft }
409
+ case 'warn': return { color: C.warn, background: C.warnSoft }
410
+ case 'error': return { color: C.accent, background: C.accentSoft }
411
+ default: return { color: C.info, background: C.infoSoft }
412
+ }
413
+ }
414
+
415
+ /**
416
+ * The executable picker (prototype §"SIMULATED OS SYSTEM FILE EXPLORER DIALOG").
417
+ *
418
+ * Browse no longer jumps straight into the OS dialog: it opens this list of the
419
+ * executables discovery already found, lets the user pick one, and offers the
420
+ * real OS chooser as the "Open Native OS Picker ↗" link in the breadcrumb bar —
421
+ * exactly the prototype's shape. Rows that failed validation stay visible (so the
422
+ * reason is readable) but cannot be selected: the picker never offers a path the
423
+ * Host would reject.
424
+ */
425
+ function ExecutablePicker(props: {
426
+ readonly controller: ToolchainController
427
+ readonly picker: NonNullable<ToolchainSnapshot['picker']>
428
+ }): ReactNode {
429
+ const { controller, picker } = props
430
+ const meta = TOOL_META[picker.tool]
431
+ const tool = controller.getSnapshot().status?.[picker.tool]
432
+ const executable = picker.tool === 'kicad' ? 'kicad-cli' : 'SolidCraft'
433
+
434
+ // Breadcrumb: the folder of the highlighted row when there is one, otherwise the
435
+ // configured root's, otherwise the prototype's neutral root.
436
+ const chosenDir = (() => {
437
+ const path = picker.chosen ?? tool?.installPath
438
+ if (path === undefined) return undefined
439
+ const cut = Math.max(path.lastIndexOf('\\'), path.lastIndexOf('/'))
440
+ return cut > 0 ? path.slice(0, cut) : undefined
441
+ })()
442
+
443
+ const hint = tool === undefined
444
+ ? COPY.toolchain.checking
445
+ : picker.candidates.length === 0
446
+ ? (discoveryLine(tool)?.text ?? COPY.toolchain.notDetected)
447
+ : COPY.toolchain.pickerHint
448
+
449
+ const row = (candidate: NonNullable<ToolStatus['discovery']['candidates']>[number], index: number): ReactNode => {
450
+ const selected = picker.chosen === candidate.path
451
+ const name = candidate.path.slice(Math.max(candidate.path.lastIndexOf('\\'), candidate.path.lastIndexOf('/')) + 1)
452
+ return createElement(
453
+ 'div',
454
+ {
455
+ key: `${candidate.path}-${index}`,
456
+ role: 'button',
457
+ tabIndex: candidate.valid ? 0 : -1,
458
+ 'aria-disabled': !candidate.valid,
459
+ 'data-picker-row': candidate.path,
460
+ onClick: candidate.valid ? () => controller.choosePick(candidate.path) : undefined,
461
+ style: {
462
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12,
463
+ padding: '10px 12px', borderRadius: R.sm, cursor: candidate.valid ? 'pointer' : 'default',
464
+ border: `1px solid ${selected ? 'rgba(59,130,246,0.5)' : 'transparent'}`,
465
+ background: selected ? 'rgba(37,99,235,0.20)' : 'transparent',
466
+ opacity: candidate.valid ? 1 : 0.55,
467
+ },
468
+ },
469
+ createElement(
470
+ 'div',
471
+ { style: { display: 'flex', alignItems: 'center', gap: 10, minWidth: 0 } },
472
+ createElement(
473
+ 'span',
474
+ {
475
+ style: {
476
+ width: 32, height: 32, borderRadius: 8, flex: '0 0 auto',
477
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
478
+ background: `${meta.color}33`, color: meta.accent,
479
+ },
480
+ },
481
+ createElement(Icon, { path: TOOLCHAIN_ICONS.file, size: 16 }),
482
+ ),
483
+ createElement(
484
+ 'div',
485
+ { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } },
486
+ createElement(
487
+ 'div',
488
+ { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
489
+ createElement('span', { style: { fontSize: 12, fontWeight: 600, color: C.text } }, name),
490
+ createElement(Chip, { text: COPY.toolchain.pickerOrigin(candidate.origin) }),
491
+ ),
492
+ createElement('span', {
493
+ style: {
494
+ ...MONO_TEXT, fontSize: 11, color: C.text3,
495
+ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
496
+ },
497
+ title: candidate.path,
498
+ }, candidate.path),
499
+ ),
500
+ ),
501
+ createElement(
502
+ 'div',
503
+ { style: { textAlign: 'right', flex: '0 0 auto' } },
504
+ candidate.valid
505
+ ? createElement('div', { style: { ...MONO_TEXT, fontSize: 11, color: C.ok } }, `v${candidate.version ?? '?'}`)
506
+ : null,
507
+ candidate.valid
508
+ ? createElement('div', { style: { fontSize: 10, color: C.text3 } }, COPY.toolchain.pickerValid)
509
+ : createElement('div', {
510
+ title: candidate.error ?? COPY.toolchain.pickerInvalid,
511
+ style: {
512
+ fontSize: 10, color: C.warn, maxWidth: 172,
513
+ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
514
+ },
515
+ }, candidate.error ?? COPY.toolchain.pickerInvalid),
516
+ ),
517
+ )
518
+ }
519
+
520
+ const openDisabled = picker.chosen === undefined || picker.nativePending
521
+
522
+ return createElement(
523
+ 'div',
524
+ {
525
+ style: {
526
+ position: 'fixed', inset: 0, zIndex: 2200, display: 'flex', alignItems: 'center',
527
+ justifyContent: 'center', padding: 16, background: 'rgba(0,0,0,0.75)',
528
+ pointerEvents: 'auto',
529
+ },
530
+ role: 'dialog',
531
+ 'aria-modal': true,
532
+ 'aria-label': COPY.toolchain.pickerTitle(executable),
533
+ 'data-hardware-toolchain-picker': picker.tool,
534
+ onClick: (event: { target: unknown; currentTarget: unknown }) => {
535
+ if (event.target === event.currentTarget) controller.closePicker()
536
+ },
537
+ },
538
+ createElement(
539
+ 'div',
540
+ {
541
+ style: {
542
+ display: 'flex', flexDirection: 'column', width: 512, maxWidth: '100%', maxHeight: '85vh',
543
+ background: '#202022', border: '1px solid rgba(255,255,255,0.15)', borderRadius: R.md,
544
+ boxShadow: '0 24px 64px rgba(0,0,0,0.5)', overflow: 'hidden',
545
+ },
546
+ },
547
+ // OS-style title bar.
548
+ createElement(
549
+ 'div',
550
+ {
551
+ style: {
552
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8,
553
+ padding: '12px 16px', background: '#2B2B2E', borderBottom: `1px solid ${C.borderSoft}`,
554
+ },
555
+ },
556
+ createElement(
557
+ 'div',
558
+ { style: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0, fontSize: 12, fontWeight: 500, color: C.text2 } },
559
+ createElement(Icon, { path: TOOLCHAIN_ICONS.folder, color: '#FBBF24', size: 16 }),
560
+ createElement('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
561
+ COPY.toolchain.pickerTitle(executable)),
562
+ ),
563
+ createElement('button', {
564
+ type: 'button',
565
+ style: { ...buttonStyle('quiet', { padding: 4 }), flex: '0 0 auto' },
566
+ title: COPY.toolchain.pickerCancel,
567
+ 'aria-label': COPY.toolchain.pickerCancel,
568
+ onClick: () => controller.closePicker(),
569
+ }, createElement(Icon, { path: TOOLCHAIN_ICONS.close, size: 16 })),
570
+ ),
571
+
572
+ // Breadcrumb + the real OS chooser link.
573
+ createElement(
574
+ 'div',
575
+ {
576
+ style: {
577
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8,
578
+ padding: '8px 16px', background: '#18181A', borderBottom: `1px solid ${C.borderSoft}`,
579
+ ...MONO_TEXT, fontSize: 11, color: C.text3,
580
+ },
581
+ },
582
+ createElement('span', {
583
+ style: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
584
+ title: chosenDir ?? '',
585
+ }, chosenDir ?? COPY.toolchain.pickerRoot),
586
+ createElement('button', {
587
+ type: 'button',
588
+ style: {
589
+ ...buttonStyle('quiet', { padding: 0, flex: '0 0 auto' }),
590
+ color: C.info, fontWeight: 500, textDecoration: 'underline', fontSize: 11,
591
+ },
592
+ onClick: () => { void controller.nativePick() },
593
+ }, picker.nativePending ? COPY.toolchain.pickerNativeWaiting : COPY.toolchain.pickerNative),
594
+ ),
595
+
596
+ // Rows. The prototype caps the list at max-h-60 (240px); rows here carry a
597
+ // little more text than the mock, so the cap is 288px to keep the same number
598
+ // of rows visible before the list starts scrolling.
599
+ createElement(
600
+ 'div',
601
+ { style: { display: 'flex', flexDirection: 'column', gap: 2, padding: 10, overflowY: 'auto', maxHeight: 288 } },
602
+ picker.candidates.length === 0
603
+ ? [createElement('p', { key: 'hint', style: { ...MUTED, fontSize: 11, padding: '6px 4px', margin: 0 } }, hint)]
604
+ : picker.candidates.map(row),
605
+ ),
606
+
607
+ // Selected file + Cancel / Open.
608
+ createElement(
609
+ 'div',
610
+ {
611
+ style: {
612
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 10,
613
+ padding: '12px 16px', background: '#18181A', borderTop: `1px solid ${C.borderSoft}`,
614
+ },
615
+ },
616
+ createElement('div', {
617
+ title: picker.chosen ?? '',
618
+ style: {
619
+ ...MONO_TEXT, flex: 1, minWidth: 0, fontSize: 11, color: picker.chosen === undefined ? C.text3 : C.text2,
620
+ background: '#121212', border: `1px solid ${C.borderSoft}`, borderRadius: 4, padding: '6px 10px',
621
+ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
622
+ },
623
+ }, picker.chosen ?? COPY.toolchain.pickerNoSelection),
624
+ createElement(
625
+ 'div',
626
+ { style: { display: 'flex', alignItems: 'center', gap: 8, flex: '0 0 auto' } },
627
+ createElement('button', {
628
+ type: 'button',
629
+ style: buttonStyle('quiet'),
630
+ onClick: () => controller.closePicker(),
631
+ }, COPY.toolchain.pickerCancel),
632
+ createElement('button', {
633
+ type: 'button',
634
+ // Prototype's OS dialog confirms in system blue, not in HuaQiu red: it is
635
+ // the OS's action, not ours.
636
+ style: {
637
+ padding: '6px 14px', borderRadius: R.sm, border: 'none', cursor: 'pointer',
638
+ background: '#2563EB', color: '#fff', fontSize: 12, fontWeight: 500,
639
+ font: 'inherit', ...disabled(openDisabled),
640
+ },
641
+ disabled: openDisabled,
642
+ onClick: () => controller.confirmPick(),
643
+ }, COPY.toolchain.pickerOpen),
644
+ ),
645
+ ),
646
+ ),
647
+ )
648
+ }
649
+
650
+ /**
651
+ * `shell.overlay` occupant: the product's own notices (§11).
652
+ *
653
+ * The overlay is a click-through root layer, so the stack is pinned bottom-right
654
+ * and only the cards accept pointer events. Nothing here is modal: an ordinary
655
+ * failure must never trap the user.
656
+ */
657
+ export function ToolchainToastHost(props: { readonly controller: ToolchainController }): ReactNode {
658
+ const snapshot = useToolchain(props.controller)
659
+ if (snapshot.toasts.length === 0) return null
660
+ return createElement(
661
+ 'div',
662
+ { style: { position: 'fixed', inset: 0, zIndex: 2100, pointerEvents: 'none' }, 'data-hardware-toolchain-toasts': true },
663
+ createElement(
664
+ 'div',
665
+ {
666
+ style: {
667
+ position: 'fixed', right: 16, bottom: 16, display: 'flex', flexDirection: 'column',
668
+ gap: 6, maxWidth: 320,
669
+ },
670
+ },
671
+ ...snapshot.toasts.map(toast => {
672
+ const tone = toastTone(toast.tone)
673
+ return createElement(
674
+ 'div',
675
+ {
676
+ key: toast.id,
677
+ role: 'status',
678
+ style: {
679
+ pointerEvents: 'auto', display: 'flex', alignItems: 'flex-start', gap: 8,
680
+ padding: '8px 10px', borderRadius: R.md, border: `1px solid ${tone.color}44`,
681
+ background: C.card, boxShadow: '0 8px 24px rgba(0,0,0,0.28)', fontSize: 11, lineHeight: 1.5, color: C.text,
682
+ },
683
+ },
684
+ createElement('span', { style: { ...dotStyle(tone.color, 6), marginTop: 4 } }),
685
+ createElement('span', { style: { flex: 1, minWidth: 0 } }, toast.text),
686
+ createElement('button', {
687
+ type: 'button',
688
+ 'aria-label': 'Dismiss',
689
+ onClick: () => props.controller.dismiss(toast.id),
690
+ style: { ...buttonStyle('quiet', { padding: '0 2px', fontSize: 11 }), color: C.text3 },
691
+ }, '×'),
692
+ )
693
+ }),
694
+ ),
695
+ )
696
+ }
697
+
698
+ /**
699
+ * `sidebar.footer.action` occupant: one quiet dot while setup is incomplete.
700
+ *
701
+ * Deliberately not a badge on the settings toggle — that seat is single and owned
702
+ * by the desktop-update indicator — and deliberately inert: the plugin owns no
703
+ * seat that can open Settings, so a button here would promise navigation it
704
+ * cannot deliver.
705
+ */
706
+ export function ToolchainIndicator(props: { readonly controller: ToolchainController }): ReactNode {
707
+ const snapshot = useToolchain(props.controller)
708
+ if (snapshot.status === undefined || !setupIncomplete(snapshot.status)) return null
709
+ const label = COPY.toolchain.indicator(setupSummary(snapshot.status))
710
+ return createElement(
711
+ 'div',
712
+ {
713
+ title: label,
714
+ 'aria-label': label,
715
+ style: {
716
+ display: 'flex', alignItems: 'center', gap: 5, padding: '3px 6px', borderRadius: R.sm,
717
+ color: C.warn, fontSize: 10, fontFamily: MONO,
718
+ },
719
+ 'data-hardware-toolchain-indicator': true,
720
+ },
721
+ createElement('span', { style: { ...dotStyle(C.warn, 6), boxShadow: '0 0 0 3px rgba(251,191,36,0.16)' } }),
722
+ createElement('span', { style: { whiteSpace: 'nowrap' } }, COPY.toolchain.pending),
723
+ )
724
+ }