@huaqiu/dsh-hardware-ui 0.7.18 → 0.7.20

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,797 @@
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 DraftCheck, 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
+ /**
140
+ * The wizard's badge, which is about **readiness**, not configuration.
141
+ *
142
+ * The prototype reads `✓ Ready (v10.0.7)`. The wizard is the first-run surface,
143
+ * so it must light up as soon as the user has a tool it can actually use —
144
+ * whether that came from a saved root, a path the Host just validated, or an
145
+ * executable discovery already checked. Only when none of those hold does it fall
146
+ * back to the state pill (`Not configured`, a running download, a failure), which
147
+ * is also what it shows while a job is in flight.
148
+ */
149
+ export function wizardPill(
150
+ tool: ToolStatus,
151
+ job: InstallJob | undefined,
152
+ check: DraftCheck | undefined,
153
+ ): { readonly text: string; readonly tone: 'ok' | 'warn' | 'info' | 'muted' | 'accent' } {
154
+ const statePill = statusPill(tool, job)
155
+ if (job !== undefined && job.tool === tool.tool && (jobRunning(job) || job.phase === 'failed')) return statePill
156
+ const detected = tool.discovery?.selected
157
+ // A saved root *with* a resolved version is a usable tool, whatever transitory
158
+ // state the Host happens to report (`validating`, a stale `missing`): the wizard
159
+ // must not tell a user with a working KiCad that it is unconfigured.
160
+ const saved = tool.installPath !== undefined && tool.version !== undefined && tool.state !== 'invalid'
161
+ const ready = tool.state === 'configured' || saved || check?.state === 'valid' || detected?.valid === true
162
+ if (!ready) return statePill
163
+ const version = tool.state === 'configured' || saved
164
+ ? tool.version
165
+ : check?.state === 'valid'
166
+ ? check.version
167
+ : detected?.version
168
+ return {
169
+ text: version === undefined ? COPY.wizard.readyDetected : COPY.wizard.ready(version),
170
+ tone: 'ok',
171
+ }
172
+ }
173
+
174
+ /** One line of verdict text beside the validate button; never a filesystem path. */
175
+ function textVerdict(text: string, color: string): ReactNode {
176
+ return createElement('span', {
177
+ style: {
178
+ ...MONO_TEXT, fontSize: 11, color, maxWidth: 260,
179
+ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
180
+ },
181
+ title: text,
182
+ }, text)
183
+ }
184
+
185
+ /** One line describing what discovery found, or that it is still looking. */
186
+ export function discoveryLine(tool: ToolStatus): { readonly text: string; readonly tone: 'muted' | 'ok' | 'warn' } | undefined {
187
+ const discovery = tool.discovery
188
+ if (discovery.state === 'running') return { text: COPY.toolchain.discovering, tone: 'muted' }
189
+ if (discovery.state === 'failed') return { text: discovery.error ?? COPY.toolchain.notDetected, tone: 'warn' }
190
+ const selected = discovery.selected
191
+ if (selected !== undefined && selected.valid && tool.state !== 'configured') {
192
+ return { text: COPY.toolchain.detected(selected.path, selected.version ?? '?'), tone: 'ok' }
193
+ }
194
+ if (selected !== undefined && !selected.valid) {
195
+ return { text: COPY.toolchain.detectedInvalid(selected.path, selected.error ?? COPY.toolchain.notDetected), tone: 'warn' }
196
+ }
197
+ return undefined
198
+ }
199
+
200
+ /**
201
+ * The 6px track. `flex: 0 0 auto` matters: this sits in a column flex box whose
202
+ * height is content-driven, and a growing item there collapses to zero height —
203
+ * which is exactly how the bar was invisible while the percentage next to it kept
204
+ * counting up.
205
+ */
206
+ const PROGRESS_TRACK: CSSProperties = {
207
+ position: 'relative', height: 6, minHeight: 6, flex: '0 0 auto', borderRadius: 999,
208
+ background: 'rgba(0,0,0,0.5)', overflow: 'hidden',
209
+ }
210
+
211
+ /** Inline download progress: label + percent on one line, bar underneath (§7.4). */
212
+ function Progress(props: { readonly job: InstallJob; readonly color: string }): ReactNode {
213
+ const percent = jobPercent(props.job) ?? 0
214
+ return createElement(
215
+ 'div',
216
+ { style: { display: 'flex', flexDirection: 'column', gap: 6, paddingTop: 8, borderTop: `1px solid ${C.borderSoft}` } },
217
+ createElement(
218
+ 'div',
219
+ { style: { display: 'flex', justifyContent: 'space-between', gap: 8, fontSize: 11, fontFamily: MONO, color: props.color } },
220
+ createElement('span', { style: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
221
+ props.job.message === '' ? COPY.toolchain.downloading : props.job.message),
222
+ createElement('span', { style: { flex: '0 0 auto' } }, `${percent}%`),
223
+ ),
224
+ createElement(
225
+ 'div',
226
+ { style: PROGRESS_TRACK, role: 'progressbar', 'aria-valuenow': percent, 'aria-valuemin': 0, 'aria-valuemax': 100 },
227
+ createElement('div', {
228
+ style: { position: 'absolute', inset: 0, width: `${percent}%`, background: props.color, transition: 'width 150ms ease' },
229
+ }),
230
+ ),
231
+ )
232
+ }
233
+
234
+ /**
235
+ * One installation card.
236
+ *
237
+ * `variant: 'wizard'` reproduces the first-run prototype card (chip, "Select
238
+ * Local File...", "Don't have KiCad? … Download from HuaQiu Server");
239
+ * `variant: 'settings'` reproduces the Settings card (longer description,
240
+ * "Browse...", a verdict line beside the validate button, and an inline download
241
+ * link). Both read the same Host status, so neither can claim something the other
242
+ * denies.
243
+ *
244
+ * The executable picker is rendered **by the card that opened it**, not by an
245
+ * overlay seat: the shell's overlay layer paints below the settings modal, so a
246
+ * picker hosted there would end up behind the very dialog that asked for it.
247
+ */
248
+ export function ToolchainCard(props: {
249
+ readonly tool: ToolchainId
250
+ readonly controller: ToolchainController
251
+ readonly snapshot: ToolchainSnapshot
252
+ readonly variant: 'wizard' | 'settings'
253
+ }): ReactNode {
254
+ const { controller, snapshot, variant, tool: id } = props
255
+ const meta = TOOL_META[id]
256
+ const tool = snapshot.status?.[id]
257
+ // Each tool owns its own job: two downloads in flight are two bars, not one.
258
+ const job = snapshot.jobs[id]
259
+ const draft = snapshot.drafts[id]
260
+ const saving = snapshot.saving === id
261
+ const running = jobRunning(job)
262
+ const check = snapshot.checks[id]
263
+ const pill = tool === undefined
264
+ ? { text: COPY.toolchain.statusValidating, tone: 'muted' as const }
265
+ : variant === 'wizard' ? wizardPill(tool, job, check) : statusPill(tool, job)
266
+ const entry = tool?.download
267
+ const busy = running || saving
268
+
269
+ const onSave = (): void => { void controller.save(id, controller.getSnapshot().drafts[id]) }
270
+
271
+ // Header: badge + name (+ CLI name) + chip, status pill on the right.
272
+ const header = createElement(
273
+ 'div',
274
+ { style: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 8, minWidth: 0 } },
275
+ createElement(
276
+ 'div',
277
+ { style: { display: 'flex', alignItems: 'center', gap: 10, minWidth: 0 } },
278
+ createElement(LetterBadge, { letter: meta.letter, color: meta.color, size: variant === 'wizard' ? 28 : 24 }),
279
+ createElement(
280
+ 'div',
281
+ { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } },
282
+ createElement(
283
+ 'div',
284
+ { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
285
+ createElement('span', { style: { fontSize: 13, fontWeight: 600, color: C.text } }, meta.name()),
286
+ ...(meta.code === undefined
287
+ ? []
288
+ : [createElement('code', { key: 'code', style: { fontSize: 11, fontFamily: MONO, color: meta.accent } }, `(${meta.code})`)]),
289
+ variant === 'wizard'
290
+ ? createElement(Chip, { text: id === 'kicad' ? COPY.wizard.kicadChip : COPY.wizard.solidcraftChip })
291
+ : null,
292
+ ),
293
+ variant === 'wizard'
294
+ ? createElement('span', { style: { fontSize: 11, color: C.text3 } },
295
+ id === 'kicad' ? COPY.wizard.kicadBlurb : COPY.wizard.solidcraftBlurb)
296
+ : null,
297
+ ),
298
+ ),
299
+ createElement('span', { style: pillStyle(pill.tone), 'data-hardware-toolchain-pill': id }, pill.text),
300
+ )
301
+
302
+ const description = variant === 'settings'
303
+ ? createElement('p', { style: { ...MUTED, lineHeight: 1.6 } },
304
+ id === 'kicad' ? COPY.settings.kicadBlurb : COPY.settings.solidcraftBlurb)
305
+ : null
306
+
307
+ // Path row: the placeholder is the prototype's own example path for the
308
+ // wizard, and its "paste or browse" hint in Settings.
309
+ const pathRow = createElement(
310
+ 'div',
311
+ { style: { display: 'flex', gap: 8, minWidth: 0 } },
312
+ createElement('input', {
313
+ style: { ...INPUT, flex: 1, minWidth: 0, fontFamily: MONO, fontSize: 11 },
314
+ value: draft, spellCheck: false, disabled: busy,
315
+ placeholder: id === 'kicad'
316
+ ? (variant === 'wizard' ? COPY.wizard.kicadPlaceholder : COPY.settings.kicadPlaceholder)
317
+ : (variant === 'wizard' ? COPY.wizard.solidcraftPlaceholder : COPY.settings.solidcraftPlaceholder),
318
+ 'aria-label': COPY.settings.pathField(meta.short),
319
+ onChange: (event: { currentTarget: { value: string } }) => controller.setDraft(id, event.currentTarget.value),
320
+ onKeyDown: (event: { key: string }) => { if (event.key === 'Enter') onSave() },
321
+ }),
322
+ createElement('button', {
323
+ type: 'button',
324
+ style: { ...buttonStyle('secondary', { display: 'flex', alignItems: 'center', gap: 6, flex: '0 0 auto' }), ...disabled(busy) },
325
+ disabled: busy,
326
+ title: COPY.toolchain.browseTitle,
327
+ onClick: () => { controller.openPicker(id) },
328
+ },
329
+ createElement(Icon, { path: TOOLCHAIN_ICONS.folder, color: '#FBBF24' }),
330
+ variant === 'wizard' ? COPY.wizard.selectFile : COPY.toolchain.browse),
331
+ )
332
+
333
+ // Verdict beside the validate button, in the prototype's muted mono voice.
334
+ //
335
+ // It reports what the Host knows — except while the field holds an edit the Host
336
+ // has never seen, where saying "awaiting executable path" beside a filled input
337
+ // would be plainly false.
338
+ //
339
+ // The *path* is never printed here. A card that just wrote its configuration
340
+ // says so with a success badge that fades by itself; the full executable path
341
+ // (which the Host resolves, not the user) is the one thing nobody asked to read,
342
+ // and it used to sit in place of the verdict and read as a permanent "saved"
343
+ // even before anything was saved.
344
+ const savedRoot = tool?.installPath ?? ''
345
+ const dirty = draft.trim() !== '' && draft.trim() !== savedRoot
346
+ const confirmation = snapshot.confirmed[id]
347
+
348
+ const verdict = (() => {
349
+ if (confirmation !== undefined) {
350
+ return createElement('span', {
351
+ style: { ...pillStyle('ok'), display: 'inline-flex', alignItems: 'center', gap: 6, whiteSpace: 'nowrap' },
352
+ role: 'status',
353
+ 'data-hardware-toolchain-confirmed': id,
354
+ },
355
+ createElement('span', { style: dotStyle(C.ok, 6) }),
356
+ confirmation.version === undefined
357
+ ? COPY.settings.statusSavedPlain
358
+ : COPY.settings.statusSavedBadge(confirmation.version))
359
+ }
360
+ if (dirty && check?.state === 'invalid') {
361
+ return textVerdict(check.error ?? COPY.toolchain.statusInvalid, C.warn)
362
+ }
363
+ if (dirty && check?.state === 'pending') return textVerdict(COPY.toolchain.statusValidating, C.text3)
364
+ if (dirty) return textVerdict(COPY.settings.statusUnsaved, C.text3)
365
+ if (tool?.state === 'configured') return null
366
+ return textVerdict(tool?.error ?? COPY.settings.statusAwaiting, tool?.error === undefined ? C.text3 : C.warn)
367
+ })()
368
+
369
+ const validateRow = createElement(
370
+ 'div',
371
+ { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap', minWidth: 0 } },
372
+ createElement('button', {
373
+ type: 'button',
374
+ style: { ...buttonStyle('secondary'), ...disabled(busy) },
375
+ disabled: busy,
376
+ onClick: onSave,
377
+ }, saving ? COPY.settings.validating : COPY.settings.validate),
378
+ variant === 'settings' ? verdict : null,
379
+ )
380
+
381
+ /** Download affordance: a plugin job first, the vendor page as the honest fallback. */
382
+ const download = entry === undefined && tool !== undefined
383
+ ? officialFallback(id, snapshot)
384
+ : createElement('a', {
385
+ href: entry?.url ?? snapshot.status?.official[id] ?? '#',
386
+ target: '_blank',
387
+ rel: 'noreferrer noopener',
388
+ style: {
389
+ display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 11, fontWeight: 500,
390
+ color: meta.accent, textDecoration: 'none', padding: '4px 8px', borderRadius: R.sm, whiteSpace: 'nowrap',
391
+ },
392
+ onClick: (event?: { preventDefault?: () => void }) => {
393
+ // A download is a plugin-owned job (progress, checksum, promotion) rather
394
+ // than a browser transfer; href stays as the fallback if the click fails.
395
+ if (entry === undefined) return
396
+ event?.preventDefault?.()
397
+ void controller.install(id)
398
+ },
399
+ },
400
+ createElement(Icon, { path: TOOLCHAIN_ICONS.download, color: meta.accent }),
401
+ variant === 'settings'
402
+ ? COPY.settings.download(id, entry?.version ?? '?')
403
+ : COPY.wizard.serverDownload)
404
+
405
+ // The prototype's wizard card carries no per-card validate button: the modal
406
+ // footer's `Save & Get Started` validates and saves both tools at once.
407
+ const actionRow = variant === 'settings'
408
+ ? createElement(
409
+ 'div',
410
+ { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, flexWrap: 'wrap' } },
411
+ validateRow,
412
+ download,
413
+ )
414
+ : null
415
+
416
+ // The wizard puts the download in its own bordered bar, as the prototype does.
417
+ const downloadBar = variant === 'wizard'
418
+ ? createElement(
419
+ 'div',
420
+ {
421
+ style: {
422
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8,
423
+ paddingTop: 8, borderTop: `1px solid ${C.borderSoft}`, fontSize: 11, color: C.text3,
424
+ },
425
+ },
426
+ createElement(
427
+ 'div',
428
+ { style: { display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 } },
429
+ createElement(Icon, { path: TOOLCHAIN_ICONS.download, color: C.text3 }),
430
+ createElement('span', { style: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
431
+ COPY.wizard.dontHave(meta.short)),
432
+ createElement('span', { style: { ...MONO_TEXT, fontSize: 11, color: C.text2, whiteSpace: 'nowrap' } },
433
+ entry === undefined ? COPY.toolchain.notDetected : `v${entry.version} (Win x64)`),
434
+ ),
435
+ download,
436
+ )
437
+ : null
438
+
439
+ const card = createElement(
440
+ 'div',
441
+ {
442
+ style: cardStyle({ gap: variant === 'wizard' ? 10 : 12, padding: variant === 'wizard' ? 14 : 16 }),
443
+ 'data-hardware-toolchain-card': id,
444
+ 'data-variant': variant,
445
+ // The input's own verdict, exposed for support and for the UI walk that has
446
+ // to prove the wizard only lights up for a path the Host accepted.
447
+ 'data-hardware-toolchain-check': check?.state ?? 'none',
448
+ },
449
+ header,
450
+ ...(description === null ? [] : [description]),
451
+ pathRow,
452
+ ...(actionRow === null ? [] : [actionRow]),
453
+ ...(downloadBar === null ? [] : [downloadBar]),
454
+ ...(running && job !== undefined ? [Progress({ job, color: meta.bar })] : []),
455
+ )
456
+
457
+ const picker = snapshot.picker === undefined || snapshot.picker.tool !== id
458
+ ? null
459
+ : createElement(ExecutablePicker, { controller, picker: snapshot.picker })
460
+ return picker === null ? card : createElement(Fragment, null, card, picker)
461
+ }
462
+
463
+ /** §9.2: no in-app build for this platform means the vendor page, never a fake button. */
464
+ function officialFallback(tool: ToolchainId, snapshot: ToolchainSnapshot): ReactNode {
465
+ return createElement('a', {
466
+ href: snapshot.status?.official?.[tool] ?? '#',
467
+ target: '_blank',
468
+ rel: 'noreferrer noopener',
469
+ style: { fontSize: 11, color: C.info, textDecoration: 'none', whiteSpace: 'nowrap' },
470
+ }, COPY.toolchain.official)
471
+ }
472
+
473
+ /** Colour of one notice tone, for the overlay's dot and border. */
474
+ function toastTone(tone: 'ok' | 'warn' | 'error' | 'info'): { readonly color: string; readonly background: string } {
475
+ switch (tone) {
476
+ case 'ok': return { color: C.ok, background: C.okSoft }
477
+ case 'warn': return { color: C.warn, background: C.warnSoft }
478
+ case 'error': return { color: C.accent, background: C.accentSoft }
479
+ default: return { color: C.info, background: C.infoSoft }
480
+ }
481
+ }
482
+
483
+ /**
484
+ * The executable picker (prototype §"SIMULATED OS SYSTEM FILE EXPLORER DIALOG").
485
+ *
486
+ * Browse no longer jumps straight into the OS dialog: it opens this list of the
487
+ * executables discovery already found, lets the user pick one, and offers the
488
+ * real OS chooser as the "Open Native OS Picker ↗" link in the breadcrumb bar —
489
+ * exactly the prototype's shape. Rows that failed validation stay visible (so the
490
+ * reason is readable) but cannot be selected: the picker never offers a path the
491
+ * Host would reject.
492
+ */
493
+ function ExecutablePicker(props: {
494
+ readonly controller: ToolchainController
495
+ readonly picker: NonNullable<ToolchainSnapshot['picker']>
496
+ }): ReactNode {
497
+ const { controller, picker } = props
498
+ const meta = TOOL_META[picker.tool]
499
+ const tool = controller.getSnapshot().status?.[picker.tool]
500
+ const executable = picker.tool === 'kicad' ? 'kicad-cli' : 'SolidCraft'
501
+
502
+ // Breadcrumb: the folder of the highlighted row when there is one, otherwise the
503
+ // configured root's, otherwise the prototype's neutral root.
504
+ const chosenDir = (() => {
505
+ const path = picker.chosen ?? tool?.installPath
506
+ if (path === undefined) return undefined
507
+ const cut = Math.max(path.lastIndexOf('\\'), path.lastIndexOf('/'))
508
+ return cut > 0 ? path.slice(0, cut) : undefined
509
+ })()
510
+
511
+ const hint = tool === undefined
512
+ ? COPY.toolchain.checking
513
+ : picker.candidates.length === 0
514
+ ? (discoveryLine(tool)?.text ?? COPY.toolchain.notDetected)
515
+ : COPY.toolchain.pickerHint
516
+
517
+ const row = (candidate: NonNullable<ToolStatus['discovery']['candidates']>[number], index: number): ReactNode => {
518
+ const selected = picker.chosen === candidate.path
519
+ const name = candidate.path.slice(Math.max(candidate.path.lastIndexOf('\\'), candidate.path.lastIndexOf('/')) + 1)
520
+ return createElement(
521
+ 'div',
522
+ {
523
+ key: `${candidate.path}-${index}`,
524
+ role: 'button',
525
+ tabIndex: candidate.valid ? 0 : -1,
526
+ 'aria-disabled': !candidate.valid,
527
+ 'data-picker-row': candidate.path,
528
+ onClick: candidate.valid ? () => controller.choosePick(candidate.path) : undefined,
529
+ style: {
530
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12,
531
+ padding: '10px 12px', borderRadius: R.sm, cursor: candidate.valid ? 'pointer' : 'default',
532
+ border: `1px solid ${selected ? 'rgba(59,130,246,0.5)' : 'transparent'}`,
533
+ background: selected ? 'rgba(37,99,235,0.20)' : 'transparent',
534
+ opacity: candidate.valid ? 1 : 0.55,
535
+ },
536
+ },
537
+ createElement(
538
+ 'div',
539
+ { style: { display: 'flex', alignItems: 'center', gap: 10, minWidth: 0 } },
540
+ createElement(
541
+ 'span',
542
+ {
543
+ style: {
544
+ width: 32, height: 32, borderRadius: 8, flex: '0 0 auto',
545
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
546
+ background: `${meta.color}33`, color: meta.accent,
547
+ },
548
+ },
549
+ createElement(Icon, { path: TOOLCHAIN_ICONS.file, size: 16 }),
550
+ ),
551
+ createElement(
552
+ 'div',
553
+ { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } },
554
+ createElement(
555
+ 'div',
556
+ { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
557
+ createElement('span', { style: { fontSize: 12, fontWeight: 600, color: C.text } }, name),
558
+ createElement(Chip, { text: COPY.toolchain.pickerOrigin(candidate.origin) }),
559
+ ),
560
+ createElement('span', {
561
+ style: {
562
+ ...MONO_TEXT, fontSize: 11, color: C.text3,
563
+ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
564
+ },
565
+ title: candidate.path,
566
+ }, candidate.path),
567
+ ),
568
+ ),
569
+ createElement(
570
+ 'div',
571
+ { style: { textAlign: 'right', flex: '0 0 auto' } },
572
+ candidate.valid
573
+ ? createElement('div', { style: { ...MONO_TEXT, fontSize: 11, color: C.ok } }, `v${candidate.version ?? '?'}`)
574
+ : null,
575
+ candidate.valid
576
+ ? createElement('div', { style: { fontSize: 10, color: C.text3 } }, COPY.toolchain.pickerValid)
577
+ : createElement('div', {
578
+ title: candidate.error ?? COPY.toolchain.pickerInvalid,
579
+ style: {
580
+ fontSize: 10, color: C.warn, maxWidth: 172,
581
+ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
582
+ },
583
+ }, candidate.error ?? COPY.toolchain.pickerInvalid),
584
+ ),
585
+ )
586
+ }
587
+
588
+ const openDisabled = picker.chosen === undefined || picker.nativePending
589
+
590
+ return createElement(
591
+ 'div',
592
+ {
593
+ style: {
594
+ position: 'fixed', inset: 0, zIndex: 2200, display: 'flex', alignItems: 'center',
595
+ justifyContent: 'center', padding: 16,
596
+ // The picker opens *inside* a modal that already dims the page (`rgba(0,0,0,0.75)`).
597
+ // Two stacked 0.75 scrims multiply to ~0.94 black, which reads as "the lights
598
+ // went out" rather than "a dialog is on top" — so this layer only adds a light
599
+ // veil, enough to separate the panel from the settings card behind it.
600
+ background: 'rgba(0,0,0,0.32)',
601
+ pointerEvents: 'auto',
602
+ },
603
+ role: 'dialog',
604
+ 'aria-modal': true,
605
+ 'aria-label': COPY.toolchain.pickerTitle(executable),
606
+ 'data-hardware-toolchain-picker': picker.tool,
607
+ onClick: (event: { target: unknown; currentTarget: unknown }) => {
608
+ if (event.target === event.currentTarget) controller.closePicker()
609
+ },
610
+ },
611
+ createElement(
612
+ 'div',
613
+ {
614
+ style: {
615
+ display: 'flex', flexDirection: 'column', width: 512, maxWidth: '100%', maxHeight: '85vh',
616
+ background: '#202022', border: '1px solid rgba(255,255,255,0.15)', borderRadius: R.md,
617
+ boxShadow: '0 24px 64px rgba(0,0,0,0.5)', overflow: 'hidden',
618
+ },
619
+ },
620
+ // OS-style title bar.
621
+ createElement(
622
+ 'div',
623
+ {
624
+ style: {
625
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8,
626
+ padding: '12px 16px', background: '#2B2B2E', borderBottom: `1px solid ${C.borderSoft}`,
627
+ },
628
+ },
629
+ createElement(
630
+ 'div',
631
+ { style: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0, fontSize: 12, fontWeight: 500, color: C.text2 } },
632
+ createElement(Icon, { path: TOOLCHAIN_ICONS.folder, color: '#FBBF24', size: 16 }),
633
+ createElement('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
634
+ COPY.toolchain.pickerTitle(executable)),
635
+ ),
636
+ createElement('button', {
637
+ type: 'button',
638
+ style: { ...buttonStyle('quiet', { padding: 4 }), flex: '0 0 auto' },
639
+ title: COPY.toolchain.pickerCancel,
640
+ 'aria-label': COPY.toolchain.pickerCancel,
641
+ onClick: () => controller.closePicker(),
642
+ }, createElement(Icon, { path: TOOLCHAIN_ICONS.close, size: 16 })),
643
+ ),
644
+
645
+ // Breadcrumb + the real OS chooser link.
646
+ createElement(
647
+ 'div',
648
+ {
649
+ style: {
650
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8,
651
+ padding: '8px 16px', background: '#18181A', borderBottom: `1px solid ${C.borderSoft}`,
652
+ ...MONO_TEXT, fontSize: 11, color: C.text3,
653
+ },
654
+ },
655
+ createElement('span', {
656
+ style: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
657
+ title: chosenDir ?? '',
658
+ }, chosenDir ?? COPY.toolchain.pickerRoot),
659
+ createElement('button', {
660
+ type: 'button',
661
+ style: {
662
+ ...buttonStyle('quiet', { padding: 0, flex: '0 0 auto' }),
663
+ color: C.info, fontWeight: 500, textDecoration: 'underline', fontSize: 11,
664
+ },
665
+ onClick: () => { void controller.nativePick() },
666
+ }, picker.nativePending ? COPY.toolchain.pickerNativeWaiting : COPY.toolchain.pickerNative),
667
+ ),
668
+
669
+ // Rows. The prototype caps the list at max-h-60 (240px); rows here carry a
670
+ // little more text than the mock, so the cap is 288px to keep the same number
671
+ // of rows visible before the list starts scrolling.
672
+ createElement(
673
+ 'div',
674
+ { style: { display: 'flex', flexDirection: 'column', gap: 2, padding: 10, overflowY: 'auto', maxHeight: 288 } },
675
+ picker.candidates.length === 0
676
+ ? [createElement('p', { key: 'hint', style: { ...MUTED, fontSize: 11, padding: '6px 4px', margin: 0 } }, hint)]
677
+ : picker.candidates.map(row),
678
+ ),
679
+
680
+ // Selected file + Cancel / Open.
681
+ createElement(
682
+ 'div',
683
+ {
684
+ style: {
685
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 10,
686
+ padding: '12px 16px', background: '#18181A', borderTop: `1px solid ${C.borderSoft}`,
687
+ },
688
+ },
689
+ createElement('div', {
690
+ title: picker.chosen ?? '',
691
+ style: {
692
+ ...MONO_TEXT, flex: 1, minWidth: 0, fontSize: 11, color: picker.chosen === undefined ? C.text3 : C.text2,
693
+ background: '#121212', border: `1px solid ${C.borderSoft}`, borderRadius: 4, padding: '6px 10px',
694
+ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
695
+ },
696
+ }, picker.chosen ?? COPY.toolchain.pickerNoSelection),
697
+ createElement(
698
+ 'div',
699
+ { style: { display: 'flex', alignItems: 'center', gap: 8, flex: '0 0 auto' } },
700
+ createElement('button', {
701
+ type: 'button',
702
+ style: buttonStyle('quiet'),
703
+ onClick: () => controller.closePicker(),
704
+ }, COPY.toolchain.pickerCancel),
705
+ createElement('button', {
706
+ type: 'button',
707
+ // Prototype's OS dialog confirms in system blue, not in HuaQiu red: it is
708
+ // the OS's action, not ours.
709
+ style: {
710
+ padding: '6px 14px', borderRadius: R.sm, border: 'none', cursor: 'pointer',
711
+ background: '#2563EB', color: '#fff', fontSize: 12, fontWeight: 500,
712
+ font: 'inherit', ...disabled(openDisabled),
713
+ },
714
+ disabled: openDisabled,
715
+ onClick: () => controller.confirmPick(),
716
+ }, COPY.toolchain.pickerOpen),
717
+ ),
718
+ ),
719
+ ),
720
+ )
721
+ }
722
+
723
+ /**
724
+ * `shell.overlay` occupant: the product's own notices (§11).
725
+ *
726
+ * The overlay is a click-through root layer, so the stack is pinned bottom-right
727
+ * and only the cards accept pointer events. Nothing here is modal: an ordinary
728
+ * failure must never trap the user.
729
+ */
730
+ export function ToolchainToastHost(props: { readonly controller: ToolchainController }): ReactNode {
731
+ const snapshot = useToolchain(props.controller)
732
+ if (snapshot.toasts.length === 0) return null
733
+ return createElement(
734
+ 'div',
735
+ { style: { position: 'fixed', inset: 0, zIndex: 2400, pointerEvents: 'none' }, 'data-hardware-toolchain-toasts': true },
736
+ createElement(
737
+ 'div',
738
+ {
739
+ style: {
740
+ position: 'fixed', right: 16, bottom: 16, display: 'flex', flexDirection: 'column',
741
+ gap: 6, maxWidth: 320,
742
+ },
743
+ },
744
+ ...snapshot.toasts.map(toast => {
745
+ const tone = toastTone(toast.tone)
746
+ return createElement(
747
+ 'div',
748
+ {
749
+ key: toast.id,
750
+ role: 'status',
751
+ style: {
752
+ pointerEvents: 'auto', display: 'flex', alignItems: 'flex-start', gap: 8,
753
+ padding: '8px 10px', borderRadius: R.md, border: `1px solid ${tone.color}44`,
754
+ background: C.card, boxShadow: '0 8px 24px rgba(0,0,0,0.28)', fontSize: 11, lineHeight: 1.5, color: C.text,
755
+ },
756
+ },
757
+ createElement('span', { style: { ...dotStyle(tone.color, 6), marginTop: 4 } }),
758
+ createElement('span', { style: { flex: 1, minWidth: 0 } }, toast.text),
759
+ createElement('button', {
760
+ type: 'button',
761
+ 'aria-label': 'Dismiss',
762
+ onClick: () => props.controller.dismiss(toast.id),
763
+ style: { ...buttonStyle('quiet', { padding: '0 2px', fontSize: 11 }), color: C.text3 },
764
+ }, '×'),
765
+ )
766
+ }),
767
+ ),
768
+ )
769
+ }
770
+
771
+ /**
772
+ * `sidebar.footer.action` occupant: one quiet dot while setup is incomplete.
773
+ *
774
+ * Deliberately not a badge on the settings toggle — that seat is single and owned
775
+ * by the desktop-update indicator — and deliberately inert: the plugin owns no
776
+ * seat that can open Settings, so a button here would promise navigation it
777
+ * cannot deliver.
778
+ */
779
+ export function ToolchainIndicator(props: { readonly controller: ToolchainController }): ReactNode {
780
+ const snapshot = useToolchain(props.controller)
781
+ if (snapshot.status === undefined || !setupIncomplete(snapshot.status)) return null
782
+ const label = COPY.toolchain.indicator(setupSummary(snapshot.status))
783
+ return createElement(
784
+ 'div',
785
+ {
786
+ title: label,
787
+ 'aria-label': label,
788
+ style: {
789
+ display: 'flex', alignItems: 'center', gap: 5, padding: '3px 6px', borderRadius: R.sm,
790
+ color: C.warn, fontSize: 10, fontFamily: MONO,
791
+ },
792
+ 'data-hardware-toolchain-indicator': true,
793
+ },
794
+ createElement('span', { style: { ...dotStyle(C.warn, 6), boxShadow: '0 0 0 3px rgba(251,191,36,0.16)' } }),
795
+ createElement('span', { style: { whiteSpace: 'nowrap' } }, COPY.toolchain.pending),
796
+ )
797
+ }