@huaqiu/dsh-hardware-ui 0.7.14 → 0.7.15
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.
- package/lib/client.js +421 -142
- package/lib/client.js.map +1 -1
- package/package.json +1 -1
- package/src/client/components.tsx +44 -38
- package/src/client/copy.ts +346 -0
- package/src/client/ecad.ts +2 -1
- package/src/client/index.ts +7 -4
- package/src/client/model.ts +14 -5
- package/src/client/order.tsx +63 -61
- package/src/client/preview.tsx +23 -26
- package/src/client/transport.ts +23 -1
- package/src/client/wizard.tsx +26 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaqiu/dsh-hardware-ui",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Hardware Engineering product UI for DSH: five-destination engineering navigation, right-panel artifact viewer, CAD installation settings and contextual native-application actions.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,6 +22,8 @@ import {
|
|
|
22
22
|
} from './model.js'
|
|
23
23
|
import { HardwarePreview } from './preview.js'
|
|
24
24
|
import { OnboardingWizard } from './wizard.js'
|
|
25
|
+
import { COPY, issueText } from './copy.js'
|
|
26
|
+
import { messageOf } from './transport.js'
|
|
25
27
|
import {
|
|
26
28
|
buttonStyle, C, cardStyle, disabled, DOT_COLORS, dotStyle, INPUT, MUTED, MONO, MONO_TEXT,
|
|
27
29
|
pillStyle, R, SECTION_TITLE,
|
|
@@ -153,7 +155,7 @@ export function EngineeringNav(props: HardwareProps): ReactNode {
|
|
|
153
155
|
let live = true
|
|
154
156
|
discover(cwd, undefined, sessionId)
|
|
155
157
|
.then((discovery) => { if (live) actions.setDiscovery(discovery) })
|
|
156
|
-
.catch((error: unknown) => { if (live) actions.setNotice(
|
|
158
|
+
.catch((error: unknown) => { if (live) actions.setNotice(COPY.viewer.discoveryFailed(messageOf(error))) })
|
|
157
159
|
return () => { live = false }
|
|
158
160
|
}, [cwd, sessionId, discover, actions])
|
|
159
161
|
|
|
@@ -204,17 +206,17 @@ function missingReason(state: HardwareState, destination: HardwareDestination):
|
|
|
204
206
|
const discovery = state.discovery
|
|
205
207
|
if (discovery === undefined) return undefined
|
|
206
208
|
if (discovery.issue?.code === 'selection-required' && (discovery.projects?.length ?? 0) > 1) {
|
|
207
|
-
return
|
|
209
|
+
return COPY.discovery.selectionRequiredCount(discovery.projects?.length ?? 0)
|
|
208
210
|
}
|
|
209
|
-
if (discovery.selected === undefined) return
|
|
211
|
+
if (discovery.selected === undefined) return COPY.discovery.noProjectSelected
|
|
210
212
|
if (destination === 'schematic' || destination === 'bom') {
|
|
211
|
-
if (discovery.selected.schematic === undefined) return
|
|
213
|
+
if (discovery.selected.schematic === undefined) return COPY.discovery.noSchematic
|
|
212
214
|
}
|
|
213
215
|
if (destination === 'pcb' || destination === '3d') {
|
|
214
|
-
if ((discovery.selected.boards?.length ?? 0) === 0) return
|
|
216
|
+
if ((discovery.selected.boards?.length ?? 0) === 0) return COPY.discovery.noBoard
|
|
215
217
|
}
|
|
216
218
|
if (destination === 'order') {
|
|
217
|
-
if ((discovery.selected.boards?.length ?? 0) === 0) return
|
|
219
|
+
if ((discovery.selected.boards?.length ?? 0) === 0) return COPY.discovery.noBoardToOrder
|
|
218
220
|
}
|
|
219
221
|
return undefined
|
|
220
222
|
}
|
|
@@ -238,19 +240,19 @@ function nativeAction(
|
|
|
238
240
|
disabled: !canOpen,
|
|
239
241
|
'data-hardware-native-open': true,
|
|
240
242
|
title: canOpen
|
|
241
|
-
?
|
|
242
|
-
: configured ?
|
|
243
|
+
? COPY.viewer.openInKicadTitle(artifact.path)
|
|
244
|
+
: configured ? COPY.viewer.selectArtifactFirst : COPY.viewer.configureKicad,
|
|
243
245
|
onClick: () => {
|
|
244
246
|
if (artifact === undefined) return
|
|
245
247
|
openNative({
|
|
246
248
|
application,
|
|
247
249
|
artifactPath: artifact.path,
|
|
248
250
|
kind: active === '3d' ? 'pcb-3d' : active === 'bom' ? 'bom' : artifact.kind,
|
|
249
|
-
}).catch((error: unknown) => { notice(
|
|
251
|
+
}).catch((error: unknown) => { notice(messageOf(error)) })
|
|
250
252
|
},
|
|
251
253
|
},
|
|
252
254
|
createElement('span', { style: dotStyle(configured ? C.ok : C.text3, 6) }),
|
|
253
|
-
|
|
255
|
+
COPY.viewer.openInKicad,
|
|
254
256
|
)
|
|
255
257
|
}
|
|
256
258
|
|
|
@@ -298,7 +300,7 @@ export function HardwareViewerBody(props: HardwareProps): ReactNode {
|
|
|
298
300
|
let live = true
|
|
299
301
|
discover(cwd, params?.projectPath, sessionId)
|
|
300
302
|
.then((result) => { if (live) actions.setDiscovery(result, params?.path !== undefined) })
|
|
301
|
-
.catch((error: unknown) => { if (live) actions.setNotice(
|
|
303
|
+
.catch((error: unknown) => { if (live) actions.setNotice(COPY.viewer.discoveryFailed(messageOf(error))) })
|
|
302
304
|
return () => { live = false }
|
|
303
305
|
}, [cwd, sessionId, params?.projectPath, actions, discover])
|
|
304
306
|
|
|
@@ -306,7 +308,7 @@ export function HardwareViewerBody(props: HardwareProps): ReactNode {
|
|
|
306
308
|
let live = true
|
|
307
309
|
installations()
|
|
308
310
|
.then((result) => { if (live) actions.setInstallations(result) })
|
|
309
|
-
.catch((error: unknown) => { if (live) actions.setNotice(
|
|
311
|
+
.catch((error: unknown) => { if (live) actions.setNotice(COPY.viewer.installationFailed(messageOf(error))) })
|
|
310
312
|
return () => { live = false }
|
|
311
313
|
}, [actions, installations])
|
|
312
314
|
|
|
@@ -343,14 +345,14 @@ export function HardwareViewerBody(props: HardwareProps): ReactNode {
|
|
|
343
345
|
'div',
|
|
344
346
|
{ style: META },
|
|
345
347
|
createElement('span', { style: META_PATH, title: artifact?.path ?? '' },
|
|
346
|
-
artifact === undefined ?
|
|
348
|
+
artifact === undefined ? COPY.viewer.noArtifact : artifact.path),
|
|
347
349
|
createElement(
|
|
348
350
|
'span',
|
|
349
351
|
{ style: { display: 'flex', alignItems: 'center', gap: 4, flex: '0 0 auto' } },
|
|
350
352
|
...(selectedProject === undefined ? [] : [createElement('span', { key: 'project', style: pillStyle('muted') }, selectedProject.name)]),
|
|
351
353
|
...(kicadConfigured
|
|
352
|
-
? [createElement('span', { key: 'kicad', style: pillStyle('ok') },
|
|
353
|
-
: [createElement('span', { key: 'kicad', style: pillStyle('warn'), title: installed?.kicad?.error ?? '' },
|
|
354
|
+
? [createElement('span', { key: 'kicad', style: pillStyle('ok') }, COPY.viewer.kicadVersion(installed?.kicad?.version ?? '').trim())]
|
|
355
|
+
: [createElement('span', { key: 'kicad', style: pillStyle('warn'), title: installed?.kicad?.error ?? '' }, COPY.viewer.kicadMissing)]),
|
|
354
356
|
),
|
|
355
357
|
)
|
|
356
358
|
|
|
@@ -360,16 +362,16 @@ export function HardwareViewerBody(props: HardwareProps): ReactNode {
|
|
|
360
362
|
selectors.push(createElement(
|
|
361
363
|
'select',
|
|
362
364
|
{
|
|
363
|
-
key: 'project', style: selectStyle, value: projectPath ?? '', 'aria-label':
|
|
365
|
+
key: 'project', style: selectStyle, value: projectPath ?? '', 'aria-label': COPY.viewer.projectField,
|
|
364
366
|
onChange: (event: ChangeEvent<HTMLSelectElement>) => {
|
|
365
367
|
const path = event.currentTarget.value
|
|
366
368
|
actions.selectProject(path)
|
|
367
369
|
discover(cwd, path, sessionId)
|
|
368
370
|
.then(result => actions.setDiscovery(result))
|
|
369
|
-
.catch((error: unknown) => actions.setNotice(
|
|
371
|
+
.catch((error: unknown) => actions.setNotice(messageOf(error)))
|
|
370
372
|
},
|
|
371
373
|
},
|
|
372
|
-
option('',
|
|
374
|
+
option('', COPY.viewer.selectProject),
|
|
373
375
|
...(discovery?.projects ?? []).map(project => option(project.path, project.name)),
|
|
374
376
|
))
|
|
375
377
|
}
|
|
@@ -380,7 +382,7 @@ export function HardwareViewerBody(props: HardwareProps): ReactNode {
|
|
|
380
382
|
selectors.push(createElement(
|
|
381
383
|
'select',
|
|
382
384
|
{
|
|
383
|
-
key: 'sheet', style: selectStyle, value: schematicPath ?? '', 'aria-label':
|
|
385
|
+
key: 'sheet', style: selectStyle, value: schematicPath ?? '', 'aria-label': COPY.viewer.schematicSheetField,
|
|
384
386
|
onChange: (event: ChangeEvent<HTMLSelectElement>) => {
|
|
385
387
|
const path = event.currentTarget.value
|
|
386
388
|
actions.selectArtifact(path, 'schematic')
|
|
@@ -396,7 +398,7 @@ export function HardwareViewerBody(props: HardwareProps): ReactNode {
|
|
|
396
398
|
selectors.push(createElement(
|
|
397
399
|
'select',
|
|
398
400
|
{
|
|
399
|
-
key: 'board', style: selectStyle, value: pcbPath ?? '', 'aria-label':
|
|
401
|
+
key: 'board', style: selectStyle, value: pcbPath ?? '', 'aria-label': COPY.viewer.boardField,
|
|
400
402
|
onChange: (event: ChangeEvent<HTMLSelectElement>) => {
|
|
401
403
|
const path = event.currentTarget.value
|
|
402
404
|
actions.selectArtifact(path, 'pcb')
|
|
@@ -417,7 +419,11 @@ export function HardwareViewerBody(props: HardwareProps): ReactNode {
|
|
|
417
419
|
: [createElement('span', { key: 'notice', role: 'status', style: { ...MUTED, color: C.warn } }, noticeText)]),
|
|
418
420
|
...(discovery?.issue === undefined || discovery.issue.code === 'selection-required'
|
|
419
421
|
? []
|
|
420
|
-
: [createElement('span', { key: 'issue', role: 'status', style: MUTED },
|
|
422
|
+
: [createElement('span', { key: 'issue', role: 'status', style: MUTED },
|
|
423
|
+
issueText(discovery.issue, {
|
|
424
|
+
...(discovery.cwd === undefined ? {} : { cwd: discovery.cwd }),
|
|
425
|
+
...(discovery.projects === undefined ? {} : { count: discovery.projects.length }),
|
|
426
|
+
}))]),
|
|
421
427
|
)
|
|
422
428
|
|
|
423
429
|
return createElement(
|
|
@@ -448,7 +454,7 @@ export function HardwareViewerBody(props: HardwareProps): ReactNode {
|
|
|
448
454
|
style: cardStyle({ alignItems: 'center', justifyContent: 'center', flex: '1 1 0', gap: 6 }),
|
|
449
455
|
'data-hardware-state': 'missing',
|
|
450
456
|
},
|
|
451
|
-
createElement('span', { style: pillStyle('warn') },
|
|
457
|
+
createElement('span', { style: pillStyle('warn') }, COPY.viewer.nothingToShow),
|
|
452
458
|
createElement('p', { role: 'status', style: { ...MUTED, textAlign: 'center', maxWidth: 320 } }, reason))]),
|
|
453
459
|
),
|
|
454
460
|
)
|
|
@@ -488,11 +494,12 @@ export function HardwareSettingsSection(props: HardwareProps): ReactNode {
|
|
|
488
494
|
const refreshed = await installations()
|
|
489
495
|
actions.setInstallations(refreshed)
|
|
490
496
|
const state = application === 'kicad' ? refreshed.kicad : refreshed.solidcraft
|
|
497
|
+
const applicationName = application === 'kicad' ? 'KiCad' : 'SolidCraft'
|
|
491
498
|
setMessage(state?.configured === true
|
|
492
|
-
?
|
|
493
|
-
:
|
|
499
|
+
? COPY.settings.savedAndValidated(applicationName)
|
|
500
|
+
: COPY.settings.savedButInvalid(applicationName, state?.error ?? COPY.settings.notDetected))
|
|
494
501
|
} catch (error) {
|
|
495
|
-
setMessage(
|
|
502
|
+
setMessage(messageOf(error))
|
|
496
503
|
} finally {
|
|
497
504
|
setBusy(undefined)
|
|
498
505
|
}
|
|
@@ -537,7 +544,7 @@ export function HardwareSettingsSection(props: HardwareProps): ReactNode {
|
|
|
537
544
|
createElement('p', { style: MUTED }, input.blurb),
|
|
538
545
|
createElement('input', {
|
|
539
546
|
style: INPUT, value: input.value, placeholder: input.placeholder, spellCheck: false,
|
|
540
|
-
'aria-label':
|
|
547
|
+
'aria-label': COPY.settings.pathField(input.title),
|
|
541
548
|
onChange: (event: ChangeEvent<HTMLInputElement>) => input.onChange(event.currentTarget.value),
|
|
542
549
|
}),
|
|
543
550
|
createElement(
|
|
@@ -547,7 +554,7 @@ export function HardwareSettingsSection(props: HardwareProps): ReactNode {
|
|
|
547
554
|
type: 'button', style: { ...buttonStyle('secondary'), ...disabled(busy !== undefined) },
|
|
548
555
|
disabled: busy !== undefined,
|
|
549
556
|
onClick: () => { void save(input.key, input.value) },
|
|
550
|
-
}, busy === input.key ?
|
|
557
|
+
}, busy === input.key ? COPY.settings.validating : COPY.settings.validate),
|
|
551
558
|
input.detail === undefined
|
|
552
559
|
? null
|
|
553
560
|
: createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10, maxWidth: 240, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, input.detail),
|
|
@@ -557,19 +564,18 @@ export function HardwareSettingsSection(props: HardwareProps): ReactNode {
|
|
|
557
564
|
return createElement(
|
|
558
565
|
'div',
|
|
559
566
|
{ style: { display: 'flex', flexDirection: 'column', gap: 10 }, 'data-hardware-settings': true },
|
|
560
|
-
createElement('h2', { style: { margin: 0, fontSize: 15, fontWeight: 600 } },
|
|
561
|
-
createElement('p', { style: MUTED },
|
|
562
|
-
'Local EDA and MCAD executables used for previews, fabrication packaging, one-click native open, and the agent environment context.'),
|
|
567
|
+
createElement('h2', { style: { margin: 0, fontSize: 15, fontWeight: 600 } }, COPY.settings.title),
|
|
568
|
+
createElement('p', { style: MUTED }, COPY.settings.lead),
|
|
563
569
|
installationCard({
|
|
564
570
|
key: 'kicad',
|
|
565
571
|
letter: 'Ki',
|
|
566
572
|
color: C.info,
|
|
567
|
-
title:
|
|
568
|
-
blurb:
|
|
573
|
+
title: COPY.settings.kicadTitle,
|
|
574
|
+
blurb: COPY.settings.kicadBlurb,
|
|
569
575
|
value: kicadRoot,
|
|
570
|
-
placeholder:
|
|
576
|
+
placeholder: COPY.settings.kicadPlaceholder,
|
|
571
577
|
ok: kicad?.configured === true,
|
|
572
|
-
status: kicad?.configured ? `v${kicad.version ?? '?'}` :
|
|
578
|
+
status: kicad?.configured ? `v${kicad.version ?? '?'}` : COPY.settings.notConfigured,
|
|
573
579
|
...(kicad?.cli === undefined ? {} : { detail: kicad.cli }),
|
|
574
580
|
onChange: setKicadRoot,
|
|
575
581
|
}),
|
|
@@ -577,12 +583,12 @@ export function HardwareSettingsSection(props: HardwareProps): ReactNode {
|
|
|
577
583
|
key: 'solidcraft',
|
|
578
584
|
letter: 'Sc',
|
|
579
585
|
color: C.warn,
|
|
580
|
-
title:
|
|
581
|
-
blurb:
|
|
586
|
+
title: COPY.settings.solidcraftTitle,
|
|
587
|
+
blurb: COPY.settings.solidcraftBlurb,
|
|
582
588
|
value: solidcraftRoot,
|
|
583
|
-
placeholder:
|
|
589
|
+
placeholder: COPY.settings.solidcraftPlaceholder,
|
|
584
590
|
ok: solidcraft?.configured === true,
|
|
585
|
-
status: solidcraft?.configured ?
|
|
591
|
+
status: solidcraft?.configured ? COPY.settings.configured : COPY.settings.notConfigured,
|
|
586
592
|
...(solidcraft?.executable === undefined ? {} : { detail: solidcraft.executable }),
|
|
587
593
|
onChange: setSolidcraftRoot,
|
|
588
594
|
}),
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* zh_CN copy for every user-visible string of the Hardware Engineering product
|
|
3
|
+
* UI (browser half).
|
|
4
|
+
*
|
|
5
|
+
* Why one module instead of strings at the call sites: the same sentence is
|
|
6
|
+
* rendered from up to three seats (navigation row, viewer body, settings
|
|
7
|
+
* section), and a literal that drifts between them reads as two different
|
|
8
|
+
* products. One dictionary also makes "is this text translated?" a mechanical
|
|
9
|
+
* question — grep for a Chinese character outside this file and the answer is
|
|
10
|
+
* no.
|
|
11
|
+
*
|
|
12
|
+
* Why not DSH's own locale service: `ctx.locale.register(ns, { zh, en })` plus a
|
|
13
|
+
* `locale: 'ns'` slot registration would put a typed, reactive `t` seat on the
|
|
14
|
+
* component props, and it is the right answer for a bilingual plugin. It cannot
|
|
15
|
+
* express zh-only: the typed overload takes
|
|
16
|
+
* `Record<BuiltInLocaleId, LocaleDictOf<N>>` — both baseline locales are
|
|
17
|
+
* required — and the untyped single-locale arm leaves an en-active host falling
|
|
18
|
+
* back to the raw key (`FALLBACK_LOCALE = 'en'`, and a namespace registered only
|
|
19
|
+
* for `zh` is not in `en`'s chain). The sibling packages hit the same wall and
|
|
20
|
+
* self-contained for the same reason (`dsh-auth/src/client/i18n.ts`,
|
|
21
|
+
* `dsh-tool-plugin-update/src/client/copy.ts`).
|
|
22
|
+
*
|
|
23
|
+
* Why one module instead of strings at the call sites: the same sentence is
|
|
24
|
+
* rendered from up to three seats (navigation row, viewer body, settings
|
|
25
|
+
* section), and a literal that drifts between them reads as two different
|
|
26
|
+
* products. One dictionary also makes "is this text translated?" a mechanical
|
|
27
|
+
* question — grep for a Chinese character outside this file and the answer is
|
|
28
|
+
* no.
|
|
29
|
+
*
|
|
30
|
+
* Adding a language later is mechanical: turn `COPY` into `{ zh, en }` with
|
|
31
|
+
* `en: Record<CopyKeys, string>` (the `dsh-auth` shape, so a missing key is a
|
|
32
|
+
* COMPILE error), pick by `<html lang>`, and — if the second language is real —
|
|
33
|
+
* move the dictionary into `ctx.locale.register` and declare `locale:` on the
|
|
34
|
+
* slots to get the framework's reactive `t` seat instead. Nothing that renders
|
|
35
|
+
* would move, because every render site already reads through this module.
|
|
36
|
+
*
|
|
37
|
+
* Wording rules that hold across the file:
|
|
38
|
+
* - Commands, file names, extension names, and host paths are NOT translated
|
|
39
|
+
* (`kicad-cli`, `.kicad_pcb`, `Settings → Hardware Engineering` becomes
|
|
40
|
+
* 「设置 → 硬件工程」 only because the host section label is translated too).
|
|
41
|
+
* - Host-origin text is never re-spelled here: {@link describeHostError} maps
|
|
42
|
+
* a stable host `code` to a sentence and appends the host detail where it
|
|
43
|
+
* is technical output (kicad-cli stderr) rather than prose.
|
|
44
|
+
* - Interpolation is a function, not `{placeholder}` templates: a function
|
|
45
|
+
* cannot be rendered with its placeholders unfilled by accident.
|
|
46
|
+
*
|
|
47
|
+
* @module
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/** The only locale this bundle ships. See the module note above. */
|
|
51
|
+
export const LOCALE = 'zh_CN' as const
|
|
52
|
+
|
|
53
|
+
export const COPY = {
|
|
54
|
+
/** Product name — tab title, settings section label, wizard title. */
|
|
55
|
+
product: {
|
|
56
|
+
name: '硬件工程',
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/** The five persistent destinations, in `DESTINATIONS` order. */
|
|
60
|
+
destinations: {
|
|
61
|
+
schematic: '原理图',
|
|
62
|
+
pcb: 'PCB',
|
|
63
|
+
bom: 'BOM',
|
|
64
|
+
'3d': '3D 模型',
|
|
65
|
+
order: '下单',
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
/** Navigation row + viewer strip. */
|
|
69
|
+
viewer: {
|
|
70
|
+
discoveryFailed: (detail: string) => `产物扫描失败:${detail}`,
|
|
71
|
+
installationFailed: (detail: string) => `安装检查失败:${detail}`,
|
|
72
|
+
noArtifact: '未选择产物',
|
|
73
|
+
kicadMissing: '未找到 KiCad',
|
|
74
|
+
kicadVersion: (version: string) => `KiCad ${version}`,
|
|
75
|
+
openInKicad: '用 KiCad 打开',
|
|
76
|
+
openInKicadTitle: (path: string) => `在 KiCad 中打开 ${path}`,
|
|
77
|
+
selectArtifactFirst: '请先选择一个产物',
|
|
78
|
+
configureKicad: '请在「设置 → 硬件工程」中配置 KiCad',
|
|
79
|
+
nothingToShow: '暂无可显示内容',
|
|
80
|
+
selectProject: '选择工程…',
|
|
81
|
+
// aria labels / titles (screen-reader text is visible text too)
|
|
82
|
+
projectField: '工程',
|
|
83
|
+
schematicSheetField: '原理图页',
|
|
84
|
+
boardField: '板文件',
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Discovery outcomes. These are the panel's OWN sentences for a host state —
|
|
89
|
+
* the host also sends a `message`, but re-deriving it here keeps the copy in
|
|
90
|
+
* one place and lets the count/cwd be woven in. {@link issueText} bridges the
|
|
91
|
+
* two: known codes get translated, unknown ones fall back to the host text.
|
|
92
|
+
*/
|
|
93
|
+
discovery: {
|
|
94
|
+
selectionRequiredCount: (count: number) => `发现 ${count} 个硬件工程,请明确选择一个。`,
|
|
95
|
+
selectionRequiredArtifact: '该工程包含多个可选产物,请明确选择一个。',
|
|
96
|
+
noProjectSelected: '尚未选择硬件工程。请打开或选择一个硬件工程。',
|
|
97
|
+
noSchematic: '该工程没有可用的根原理图。',
|
|
98
|
+
noBoard: '该工程没有可用的 .kicad_pcb 板文件。',
|
|
99
|
+
noBoardToOrder: '请先选择板文件,再报价或下单制板。',
|
|
100
|
+
// Host `issue.code` vocabulary.
|
|
101
|
+
noProject: (cwd: string) => (cwd === '' ? '未找到 .kicad_pro 工程文件' : `${cwd} 下未找到 .kicad_pro 工程文件`),
|
|
102
|
+
missingProject: (path: string) => `工程文件不存在:${path}`,
|
|
103
|
+
badManifest: (detail: string) => `配置文件 .hardware-engineering.json 无效:${detail}`,
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/** schematic / pcb / 3d / bom stages. */
|
|
107
|
+
preview: {
|
|
108
|
+
loading: '正在加载已保存的产物…',
|
|
109
|
+
unavailable: '不可用',
|
|
110
|
+
kindSchematic: '原理图',
|
|
111
|
+
kindBoard: 'PCB',
|
|
112
|
+
revision: (revision: string) => `版本 ${revision}`,
|
|
113
|
+
ecadHint: '仅预览已保存的文件;文件必须存在且可解析。',
|
|
114
|
+
ecadKindMismatch: (expected: string, actual: string) =>
|
|
115
|
+
`宿主返回的产物类型(${actual})与预览类型(${expected})不一致。`,
|
|
116
|
+
ecadOverlay: '已保存文件 · 滚轮缩放,拖拽平移',
|
|
117
|
+
kicadNotConfigured: 'KiCad 尚未配置。',
|
|
118
|
+
glbExporting: '正在用 kicad-cli 导出 PCB 的 GLB…',
|
|
119
|
+
glbLoading: '正在加载 3D 模型…',
|
|
120
|
+
glbCached: '缓存',
|
|
121
|
+
glbGenerated: '已生成',
|
|
122
|
+
glbOverlay: '拖拽旋转 · 滚轮缩放',
|
|
123
|
+
bomHint: 'BOM 行来自 kicad-cli sch export bom。请在「设置 → 硬件工程」中配置 KiCad。',
|
|
124
|
+
bomTitle: (lines: number) => `物料清单 · ${String(lines)} 行`,
|
|
125
|
+
bomPlacements: (count: number) => `${String(count)} 个元件位`,
|
|
126
|
+
bomColumns: ['位号', '数量', '值', '封装', '备注'] as const,
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/** Order Placing destination. */
|
|
130
|
+
order: {
|
|
131
|
+
title: '制板与贴片',
|
|
132
|
+
packaging: '打包中…',
|
|
133
|
+
packageReady: '打包完成',
|
|
134
|
+
packagePending: '尚未打包',
|
|
135
|
+
packageRunning: '正在运行 kicad-cli 导出 Gerber 与钻孔…',
|
|
136
|
+
packageNotPrepared: '尚未打包。',
|
|
137
|
+
packageCard: '制板文件包',
|
|
138
|
+
packageFiles: (files: number, size: string) => `${String(files)} 个文件 · ${size}`,
|
|
139
|
+
|
|
140
|
+
pcbTitle: '裸板制板',
|
|
141
|
+
pcbSubtitle: '通过华秋制板服务对选中的板文件报价并下单。',
|
|
142
|
+
pcbSummary: (zip: string, files: number, size: string) =>
|
|
143
|
+
`${zip} · ${String(files)} 个 Gerber/钻孔文件 · ${size}`,
|
|
144
|
+
pcbAction: '提交 PCB 订单',
|
|
145
|
+
|
|
146
|
+
smtTitle: '整包贴片',
|
|
147
|
+
smtSubtitle: '需要工程根原理图以生成 BOM 与元件坐标。',
|
|
148
|
+
smtSummary: (placements: number, lines: number, size: string) =>
|
|
149
|
+
`${String(placements)} 个贴片点位 · ${String(lines)} 行 BOM · ${size}`,
|
|
150
|
+
smtAction: '提交贴片订单',
|
|
151
|
+
|
|
152
|
+
boardFile: '板文件',
|
|
153
|
+
placements: '贴片点位',
|
|
154
|
+
bomLines: 'BOM 行数',
|
|
155
|
+
credential: '登录凭据',
|
|
156
|
+
signedIn: '华秋登录',
|
|
157
|
+
signedOut: '未登录',
|
|
158
|
+
|
|
159
|
+
signInToOrder: '请先登录华秋账号再下单——订单页将以你的账号打开。',
|
|
160
|
+
signInToOrderSmt: '请先登录华秋账号再下单贴片——订单页将以你的账号打开。',
|
|
161
|
+
waitingForPackage: '正在等待制板文件包。',
|
|
162
|
+
configureToPackage: '请配置 KiCad 以打包板文件。',
|
|
163
|
+
selectRootSchematic: '请选择根原理图,以便生成 BOM 与坐标。',
|
|
164
|
+
|
|
165
|
+
// Board facts (values keep their units, which are not prose).
|
|
166
|
+
layers: '层数',
|
|
167
|
+
layersValue: (layers: number) => `${String(layers)} 层`,
|
|
168
|
+
outline: '外形尺寸',
|
|
169
|
+
thickness: '板厚',
|
|
170
|
+
minTrace: '最小线宽',
|
|
171
|
+
minDrill: '最小钻孔',
|
|
172
|
+
outerCopper: '外层铜厚',
|
|
173
|
+
defaultValue: '默认',
|
|
174
|
+
copperValue: (oz: number | string) => `${String(oz)} oz`,
|
|
175
|
+
|
|
176
|
+
agentEntryPoints: 'Agent 入口',
|
|
177
|
+
submitting: '提交中…',
|
|
178
|
+
|
|
179
|
+
resultTitlePcb: 'PCB 订单已创建',
|
|
180
|
+
resultTitleSmt: '贴片订单已创建',
|
|
181
|
+
resultLaunched: '已在浏览器打开',
|
|
182
|
+
resultReady: '待打开',
|
|
183
|
+
resultNote: '与 KiCad 在下单窗口中展示的是同一个页面,已在你的默认浏览器中打开。',
|
|
184
|
+
resultLaunchedMessage: (kind: string) => `已在默认浏览器中打开「${kind}」订单页。`,
|
|
185
|
+
resultReadyMessage: (kind: string) => `「${kind}」订单页已就绪,打开链接即可继续。`,
|
|
186
|
+
openInBrowser: '在浏览器打开',
|
|
187
|
+
opening: '正在打开…',
|
|
188
|
+
copyUrl: '复制链接',
|
|
189
|
+
copied: '已复制',
|
|
190
|
+
|
|
191
|
+
confirmAria: '确认下单上传',
|
|
192
|
+
confirmTitlePcb: '上传板文件并创建 PCB 订单?',
|
|
193
|
+
confirmTitleSmt: '上传贴片文件包?',
|
|
194
|
+
confirmBody: '以下文件将发送到华秋下单服务。订单在那里创建,其页面会在你的默认浏览器中打开;付款仍在该页面完成。',
|
|
195
|
+
confirmZip: (zip: string, size: string) => `${zip} — Gerber 与钻孔文件(${size})`,
|
|
196
|
+
confirmPositions: (size: string) => `元件坐标(${size})`,
|
|
197
|
+
confirmBom: (size: string) => `贴片 BOM(${size})`,
|
|
198
|
+
confirmHost: (baseUrl: string | undefined) => baseUrl ?? '已配置的下单服务',
|
|
199
|
+
confirmAck: '我了解这些板文件将离开本机。',
|
|
200
|
+
cancel: '取消',
|
|
201
|
+
uploadAndOpen: '上传并打开订单页',
|
|
202
|
+
uploading: '正在上传…',
|
|
203
|
+
|
|
204
|
+
batch: '生产数量',
|
|
205
|
+
batchUnits: (count: number) => `${String(count)} 片`,
|
|
206
|
+
quoteBasis: (count: number) => `报价基准 · ${String(count)} 片`,
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
/** First-run setup wizard. */
|
|
210
|
+
wizard: {
|
|
211
|
+
steps: ['欢迎', 'KiCad', 'SolidCraft'] as const,
|
|
212
|
+
stepCounter: (index: number, total: number, label: string) =>
|
|
213
|
+
`${String(index)}/${String(total)} · ${label}`,
|
|
214
|
+
aria: '硬件工程初始化',
|
|
215
|
+
|
|
216
|
+
welcomeTitle: '配置你的硬件工具链',
|
|
217
|
+
welcomeKicker: '仅需一次 · 可跳过',
|
|
218
|
+
welcomeLead: '硬件工程可预览 KiCad 工程、导出 PCB 三维模型、打包制板文件并调用本地程序打开文件。只需指定一次本地安装位置。',
|
|
219
|
+
welcomeUsesTitle: '使用到的组件',
|
|
220
|
+
welcomeUses: 'kicad-cli 负责预览、BOM、GLB 与 Gerber/钻孔打包。SolidCraft 仅作为环境上下文提供给 Agent。',
|
|
221
|
+
welcomeLocal: '只使用本机的可执行文件。不会上传任何内容,也不会替你安装任何东西。',
|
|
222
|
+
|
|
223
|
+
kicadTitle: 'KiCad 安装位置',
|
|
224
|
+
kicadOptional: '可选',
|
|
225
|
+
kicadLead: '填写 KiCad 安装目录或 kicad-cli 路径。它用于 .kicad_sch / .kicad_pcb 预览、PCB 的 GLB 导出、制板文件打包,以及「用 KiCad 打开」。',
|
|
226
|
+
kicadPlaceholder: 'C:\\Program Files\\KiCad\\8.0\\ 或 /usr/bin/kicad-cli',
|
|
227
|
+
kicadSkipHint: '留空即跳过。之后可在「设置 → 硬件工程」中配置。',
|
|
228
|
+
|
|
229
|
+
solidcraftTitle: 'SolidCraft 安装位置',
|
|
230
|
+
solidcraftLead: '本 POC 中 SolidCraft 仅作为环境上下文提供给 Agent——不启动本地程序,也不做结构预览。',
|
|
231
|
+
solidcraftPlaceholder: 'C:\\Program Files\\SolidCraft\\bin\\SolidCraft.exe',
|
|
232
|
+
|
|
233
|
+
skip: '跳过设置',
|
|
234
|
+
back: '上一步',
|
|
235
|
+
next: '下一步',
|
|
236
|
+
finish: '完成',
|
|
237
|
+
saving: '保存中…',
|
|
238
|
+
footerNote: '随时可在「设置 → 硬件工程」中修改。',
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
/** Settings section (the two CAD installation roots). */
|
|
242
|
+
settings: {
|
|
243
|
+
title: '硬件工程',
|
|
244
|
+
lead: '用于预览、制板打包、一键调用本地程序以及 Agent 环境上下文的本地 EDA / MCAD 可执行文件。',
|
|
245
|
+
kicadTitle: 'KiCad EDA 套件',
|
|
246
|
+
kicadBlurb: '可填 KiCad 安装目录或 kicad-cli 路径。用于 .kicad_sch / .kicad_pcb 预览、GLB 导出、BOM、Gerber 打包与本地打开。',
|
|
247
|
+
kicadPlaceholder: 'C:\\Program Files\\KiCad\\8.0\\ 或 /usr/bin/kicad-cli',
|
|
248
|
+
solidcraftTitle: 'SolidCraft 三维 CAD',
|
|
249
|
+
solidcraftBlurb: '本 POC 中仅用于 Agent 环境上下文。不启动本地程序,也不做结构预览;「3D 模型」页签渲染的是所选 PCB。',
|
|
250
|
+
solidcraftPlaceholder: 'C:\\Program Files\\SolidCraft\\bin\\SolidCraft.exe',
|
|
251
|
+
pathField: (title: string) => `${title}路径`,
|
|
252
|
+
validate: '校验并保存',
|
|
253
|
+
validating: '校验中…',
|
|
254
|
+
configured: '已配置',
|
|
255
|
+
notConfigured: '未配置',
|
|
256
|
+
notDetected: '未检测到',
|
|
257
|
+
savedAndValidated: (application: string) => `${application} 校验通过并已保存。`,
|
|
258
|
+
savedButInvalid: (application: string, detail: string) => `${application} 已保存,但校验失败:${detail}`,
|
|
259
|
+
hostSettingsUnavailable: '宿主未提供设置服务,无法保存。',
|
|
260
|
+
hostRejected: (application: string) => `宿主拒绝了${application}的设置。`,
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Host error sentences, keyed by the stable `code` in the route envelope
|
|
265
|
+
* (`packages/hardware-artifacts/src/routes.ts`). A code missing here is not a
|
|
266
|
+
* bug in the UI: the host detail is then shown verbatim, which is the right
|
|
267
|
+
* answer for an unmodelled failure.
|
|
268
|
+
*/
|
|
269
|
+
errors: {
|
|
270
|
+
unauthorized: '没有权限访问该产物:它不在当前会话的工作区授权范围内。',
|
|
271
|
+
forbidden: '没有权限执行该操作。',
|
|
272
|
+
'missing-artifact': '该产物不存在。',
|
|
273
|
+
'unsupported-artifact': '不支持该产物类型。',
|
|
274
|
+
'invalid-identity': '产物路径无效。',
|
|
275
|
+
'missing-executable': '已配置的 KiCad 中没有可打开该产物的程序。',
|
|
276
|
+
'not-configured': '尚未配置 KiCad。请在「设置 → 硬件工程」中填写安装位置。',
|
|
277
|
+
'too-large': '产物超过可预览的大小上限。',
|
|
278
|
+
'export-timeout': 'kicad-cli 执行超时。',
|
|
279
|
+
'export-failed': 'kicad-cli 导出失败。',
|
|
280
|
+
'stale-revision': '文件已变化,请刷新后重试。',
|
|
281
|
+
'invalid-request': '请求参数不完整。',
|
|
282
|
+
'invalid-application': '不支持该本地程序。',
|
|
283
|
+
'confirmation-required': '下单需要先在上传确认框中确认。',
|
|
284
|
+
'invalid-order-url': '订单链接无效,已拒绝打开。',
|
|
285
|
+
'order-unreachable': '无法连接下单服务。',
|
|
286
|
+
'order-rejected': '下单服务未能返回可用的订单页。',
|
|
287
|
+
'not-found': '未找到该接口。',
|
|
288
|
+
internal: '服务内部错误。',
|
|
289
|
+
},
|
|
290
|
+
} as const
|
|
291
|
+
|
|
292
|
+
export type HardwareCopy = typeof COPY
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Codes whose host detail is a technical tail worth keeping next to the
|
|
296
|
+
* translated sentence: kicad-cli stderr, an HTTP failure, a backend payload.
|
|
297
|
+
* For the rest the detail merely restates the sentence in English.
|
|
298
|
+
*/
|
|
299
|
+
const KEEPS_DETAIL = new Set([
|
|
300
|
+
'export-failed',
|
|
301
|
+
'order-unreachable',
|
|
302
|
+
'order-rejected',
|
|
303
|
+
'invalid-order-url',
|
|
304
|
+
'internal',
|
|
305
|
+
])
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* One host error → one zh_CN sentence.
|
|
309
|
+
*
|
|
310
|
+
* `detail` is the host's own message. Unknown codes keep it untouched, so an
|
|
311
|
+
* unmodelled failure still says something specific instead of collapsing into
|
|
312
|
+
* a generic "出错了".
|
|
313
|
+
*/
|
|
314
|
+
export function describeHostError(code: string | undefined, detail: string): string {
|
|
315
|
+
if (code === undefined) return detail
|
|
316
|
+
const sentence = (COPY.errors as Record<string, string | undefined>)[code]
|
|
317
|
+
if (sentence === undefined) return detail
|
|
318
|
+
return KEEPS_DETAIL.has(code) && detail !== '' ? `${sentence}(${detail})` : sentence
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Translate one discovery `issue` without losing the host's specifics.
|
|
323
|
+
*
|
|
324
|
+
* The count and the workspace come from the discovery result, not from the
|
|
325
|
+
* host sentence, so the wording does not depend on how the host phrased it.
|
|
326
|
+
*/
|
|
327
|
+
export function issueText(
|
|
328
|
+
issue: { readonly code: string; readonly message: string },
|
|
329
|
+
context: { readonly cwd?: string; readonly count?: number } = {},
|
|
330
|
+
): string {
|
|
331
|
+
switch (issue.code) {
|
|
332
|
+
case 'selection-required':
|
|
333
|
+
return context.count !== undefined && context.count > 1
|
|
334
|
+
? COPY.discovery.selectionRequiredCount(context.count)
|
|
335
|
+
: COPY.discovery.selectionRequiredArtifact
|
|
336
|
+
case 'no-project':
|
|
337
|
+
return COPY.discovery.noProject(context.cwd ?? '')
|
|
338
|
+
case 'missing-project':
|
|
339
|
+
// Host text is `${path} does not exist`; the path is the useful half.
|
|
340
|
+
return COPY.discovery.missingProject(issue.message.replace(/\s+does not exist\s*$/u, ''))
|
|
341
|
+
case 'bad-manifest':
|
|
342
|
+
return COPY.discovery.badManifest(issue.message.replace(/^invalid \.hardware-engineering\.json:\s*/u, ''))
|
|
343
|
+
default:
|
|
344
|
+
return issue.message
|
|
345
|
+
}
|
|
346
|
+
}
|
package/src/client/ecad.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { BoardParser, SchematicParser } from '@huaqiu/kicad-sexpr-parser'
|
|
10
10
|
import { renderPcb, renderSchematic } from '@huaqiu/ecad-renderer'
|
|
11
11
|
import { loadArtifactSource, type ArtifactSource } from './transport.js'
|
|
12
|
+
import { COPY } from './copy.js'
|
|
12
13
|
|
|
13
14
|
export type EcadKind = 'schematic' | 'pcb'
|
|
14
15
|
export interface MountedEcad {
|
|
@@ -46,7 +47,7 @@ export async function mountEcad(
|
|
|
46
47
|
})
|
|
47
48
|
if (options.signal.aborted) throw aborted(options.signal)
|
|
48
49
|
if (source.kind !== undefined && source.kind !== kind) {
|
|
49
|
-
throw new Error(
|
|
50
|
+
throw new Error(COPY.preview.ecadKindMismatch(kind, source.kind))
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
// The renderer owns the backing resolution but not the CSS size, and it fits
|
package/src/client/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
ViewerNavigationParams,
|
|
20
20
|
} from './model.js'
|
|
21
21
|
import { createHardwareStore } from './store.js'
|
|
22
|
+
import { COPY } from './copy.js'
|
|
22
23
|
import { loadInstallations, loadProjects, openArtifact } from './transport.js'
|
|
23
24
|
|
|
24
25
|
/** Real Cordis service names this browser plugin waits for. */
|
|
@@ -101,10 +102,12 @@ export function apply(ctx: ClientContext): void {
|
|
|
101
102
|
},
|
|
102
103
|
async saveInstallation(application, root) {
|
|
103
104
|
const form = ctx.configForms?.get<HardwareInstallationConfig>(HARDWARE_CONFIG_ENTRY)
|
|
104
|
-
if (form === undefined) throw new Error(
|
|
105
|
+
if (form === undefined) throw new Error(COPY.settings.hostSettingsUnavailable)
|
|
105
106
|
const field = application === 'kicad' ? 'kicadRoot' : 'solidcraftRoot'
|
|
106
107
|
const accepted = await form.set(field, root)
|
|
107
|
-
if (!accepted)
|
|
108
|
+
if (!accepted) {
|
|
109
|
+
throw new Error(COPY.settings.hostRejected(application === 'kicad' ? 'KiCad' : 'SolidCraft'))
|
|
110
|
+
}
|
|
108
111
|
},
|
|
109
112
|
configForm() {
|
|
110
113
|
return ctx.configForms?.get<HardwareInstallationConfig>(HARDWARE_CONFIG_ENTRY)
|
|
@@ -136,7 +139,7 @@ export function apply(ctx: ClientContext): void {
|
|
|
136
139
|
id: HARDWARE_TAB_ID,
|
|
137
140
|
kind: HARDWARE_TAB_KIND,
|
|
138
141
|
keepMounted: true,
|
|
139
|
-
title: () =>
|
|
142
|
+
title: () => COPY.product.name,
|
|
140
143
|
}) ?? (() => {}), 'hardware-ui: right-panel tab type')
|
|
141
144
|
|
|
142
145
|
const slots = ctx.slots
|
|
@@ -159,7 +162,7 @@ export function apply(ctx: ClientContext): void {
|
|
|
159
162
|
name: 'settings.section',
|
|
160
163
|
id: HARDWARE_SETTINGS_ID,
|
|
161
164
|
order: 85,
|
|
162
|
-
label: () =>
|
|
165
|
+
label: () => COPY.product.name,
|
|
163
166
|
store: rootStore,
|
|
164
167
|
inject: () => controller,
|
|
165
168
|
}, HardwareSettingsSection)), 'hardware-ui: CAD installation settings')
|