@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/src/client/model.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Product-owned navigation and artifact identity. No shadow project database. */
|
|
2
|
+
import { COPY } from './copy.js'
|
|
2
3
|
|
|
3
4
|
/** The five persistent product destinations. DFM and mechanical are out of scope. */
|
|
4
5
|
export type HardwareDestination = 'schematic' | 'pcb' | 'bom' | '3d' | 'order'
|
|
@@ -16,12 +17,20 @@ export const DESTINATIONS: readonly HardwareDestination[] = Object.freeze([
|
|
|
16
17
|
'schematic', 'pcb', 'bom', '3d', 'order',
|
|
17
18
|
])
|
|
18
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Visible destination labels, in `DESTINATIONS` order.
|
|
22
|
+
*
|
|
23
|
+
* Read from the copy module rather than written here: the same strings are
|
|
24
|
+
* rendered from the navigation row and the viewer strip, and the two must never
|
|
25
|
+
* disagree. Keys stay in destination order because the navigation maps over
|
|
26
|
+
* `DESTINATIONS`, not over this object.
|
|
27
|
+
*/
|
|
19
28
|
export const DESTINATION_LABELS: Readonly<Record<HardwareDestination, string>> = Object.freeze({
|
|
20
|
-
schematic:
|
|
21
|
-
pcb:
|
|
22
|
-
bom:
|
|
23
|
-
'3d': '
|
|
24
|
-
order:
|
|
29
|
+
schematic: COPY.destinations.schematic,
|
|
30
|
+
pcb: COPY.destinations.pcb,
|
|
31
|
+
bom: COPY.destinations.bom,
|
|
32
|
+
'3d': COPY.destinations['3d'],
|
|
33
|
+
order: COPY.destinations.order,
|
|
25
34
|
})
|
|
26
35
|
|
|
27
36
|
/** Which native application a destination can open, if any. */
|
package/src/client/order.tsx
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { createElement, useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react'
|
|
10
10
|
import { isAbortError } from './ecad.js'
|
|
11
|
+
import { COPY } from './copy.js'
|
|
11
12
|
import {
|
|
12
|
-
loadOrderConfig, openOrderUrl, placeOrder, prepareFabrication,
|
|
13
|
+
loadOrderConfig, messageOf, openOrderUrl, placeOrder, prepareFabrication,
|
|
13
14
|
type FabricationProjection, type OrderConfigInfo, type PlacedOrder,
|
|
14
15
|
} from './transport.js'
|
|
15
16
|
import {
|
|
@@ -38,18 +39,14 @@ function formatBytes(bytes: number): string {
|
|
|
38
39
|
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
function describe(error: unknown): string {
|
|
42
|
-
return error instanceof Error ? error.message : String(error)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
42
|
function specRows(facts: FabricationProjection['facts']): { label: string; value: string }[] {
|
|
46
43
|
return [
|
|
47
|
-
{ label:
|
|
48
|
-
{ label:
|
|
49
|
-
{ label:
|
|
50
|
-
{ label:
|
|
51
|
-
{ label:
|
|
52
|
-
{ label:
|
|
44
|
+
{ label: COPY.order.layers, value: COPY.order.layersValue(facts.layers) },
|
|
45
|
+
{ label: COPY.order.outline, value: `${facts.widthMm.toFixed(1)} × ${facts.heightMm.toFixed(1)} mm` },
|
|
46
|
+
{ label: COPY.order.thickness, value: `${facts.thicknessMm.toFixed(2)} mm` },
|
|
47
|
+
{ label: COPY.order.minTrace, value: facts.minTrackMm === undefined ? COPY.order.defaultValue : `${facts.minTrackMm.toFixed(2)} mm` },
|
|
48
|
+
{ label: COPY.order.minDrill, value: facts.minViaDrillMm === undefined ? COPY.order.defaultValue : `${facts.minViaDrillMm.toFixed(2)} mm` },
|
|
49
|
+
{ label: COPY.order.outerCopper, value: COPY.order.copperValue(facts.outerOz ?? 1) },
|
|
53
50
|
]
|
|
54
51
|
}
|
|
55
52
|
|
|
@@ -126,7 +123,7 @@ function workflowCard(input: {
|
|
|
126
123
|
'data-hardware-order-action': input.tag.toLowerCase(),
|
|
127
124
|
onClick: input.onAction,
|
|
128
125
|
},
|
|
129
|
-
input.busy ?
|
|
126
|
+
input.busy ? COPY.order.submitting : input.action,
|
|
130
127
|
),
|
|
131
128
|
)
|
|
132
129
|
}
|
|
@@ -154,7 +151,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
154
151
|
useEffect(() => {
|
|
155
152
|
loadOrderConfig()
|
|
156
153
|
.then((value) => { if (live.current) setConfig(value) })
|
|
157
|
-
.catch((error: unknown) => { if (live.current) setMessage(
|
|
154
|
+
.catch((error: unknown) => { if (live.current) setMessage(messageOf(error)) })
|
|
158
155
|
}, [])
|
|
159
156
|
|
|
160
157
|
// Preparing the package is local: gerbers, drill files and CSVs come from the
|
|
@@ -172,7 +169,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
172
169
|
.then((value) => { if (!controller.signal.aborted) setPrepared(value) })
|
|
173
170
|
.catch((error: unknown) => {
|
|
174
171
|
if (controller.signal.aborted || isAbortError(error)) return
|
|
175
|
-
setMessage(
|
|
172
|
+
setMessage(messageOf(error))
|
|
176
173
|
})
|
|
177
174
|
.finally(() => { if (!controller.signal.aborted) setPreparing(false) })
|
|
178
175
|
return () => { controller.abort() }
|
|
@@ -197,7 +194,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
197
194
|
setConfirming(undefined)
|
|
198
195
|
setAcknowledged(false)
|
|
199
196
|
} catch (error) {
|
|
200
|
-
setMessage(
|
|
197
|
+
setMessage(messageOf(error))
|
|
201
198
|
} finally {
|
|
202
199
|
setPlacing(undefined)
|
|
203
200
|
}
|
|
@@ -222,7 +219,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
222
219
|
await openOrderUrl(placed.orderUrl)
|
|
223
220
|
setPlaced({ ...placed, launched: true, status: 'launched' })
|
|
224
221
|
} catch (error) {
|
|
225
|
-
setMessage(
|
|
222
|
+
setMessage(messageOf(error))
|
|
226
223
|
} finally {
|
|
227
224
|
setReopening(false)
|
|
228
225
|
}
|
|
@@ -242,13 +239,13 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
242
239
|
'h3',
|
|
243
240
|
{ style: { margin: 0, fontSize: 13, fontWeight: 600, color: C.text, display: 'flex', alignItems: 'center', gap: 6 } },
|
|
244
241
|
createElement('span', { style: dotStyle(C.accent) }),
|
|
245
|
-
|
|
242
|
+
COPY.order.title,
|
|
246
243
|
),
|
|
247
244
|
preparing
|
|
248
|
-
? createElement('span', { style: pillStyle('info') },
|
|
245
|
+
? createElement('span', { style: pillStyle('info') }, COPY.order.packaging)
|
|
249
246
|
: prepared !== undefined
|
|
250
|
-
? createElement('span', { style: pillStyle('ok') },
|
|
251
|
-
: createElement('span', { style: pillStyle(configured ? 'muted' : 'warn') }, configured ?
|
|
247
|
+
? createElement('span', { style: pillStyle('ok') }, COPY.order.packageReady)
|
|
248
|
+
: createElement('span', { style: pillStyle(configured ? 'muted' : 'warn') }, configured ? COPY.order.packagePending : COPY.viewer.kicadMissing),
|
|
252
249
|
),
|
|
253
250
|
createElement('p', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10.5 } }, boardTitle),
|
|
254
251
|
)
|
|
@@ -257,14 +254,14 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
257
254
|
'div',
|
|
258
255
|
{ style: cardStyle() },
|
|
259
256
|
createElement('div', { style: SPREAD },
|
|
260
|
-
createElement('span', { style: SECTION_TITLE },
|
|
257
|
+
createElement('span', { style: SECTION_TITLE }, COPY.order.packageCard),
|
|
261
258
|
prepared === undefined
|
|
262
259
|
? null
|
|
263
|
-
: createElement('span', { style: pillStyle('muted') },
|
|
260
|
+
: createElement('span', { style: pillStyle('muted') }, COPY.order.packageFiles(prepared.archive.files.length, zipSize ?? '')),
|
|
264
261
|
),
|
|
265
262
|
prepared === undefined
|
|
266
263
|
? createElement('p', { style: MUTED },
|
|
267
|
-
preparing ?
|
|
264
|
+
preparing ? COPY.order.packageRunning : COPY.order.packageNotPrepared)
|
|
268
265
|
: createElement(
|
|
269
266
|
'div',
|
|
270
267
|
{
|
|
@@ -284,47 +281,47 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
284
281
|
const pcbCard = workflowCard({
|
|
285
282
|
tag: 'PCB',
|
|
286
283
|
tagColor: C.ok,
|
|
287
|
-
title:
|
|
284
|
+
title: COPY.order.pcbTitle,
|
|
288
285
|
subtitle: prepared === undefined
|
|
289
|
-
?
|
|
290
|
-
:
|
|
286
|
+
? COPY.order.pcbSubtitle
|
|
287
|
+
: COPY.order.pcbSummary(prepared.archive.zipName, prepared.archive.files.length, zipSize ?? ''),
|
|
291
288
|
details: specs.length === 0
|
|
292
|
-
? [{ label:
|
|
289
|
+
? [{ label: COPY.order.boardFile, value: boardTitle }]
|
|
293
290
|
: specs,
|
|
294
|
-
action:
|
|
291
|
+
action: COPY.order.pcbAction,
|
|
295
292
|
onAction: () => { setAcknowledged(false); setConfirming('pcb') },
|
|
296
293
|
busy: placing === 'pcb',
|
|
297
294
|
...(configured && prepared !== undefined
|
|
298
|
-
? tokenReady ? {} : { blocked:
|
|
299
|
-
: { blocked: configured ?
|
|
295
|
+
? tokenReady ? {} : { blocked: COPY.order.signInToOrder }
|
|
296
|
+
: { blocked: configured ? COPY.order.waitingForPackage : COPY.order.configureToPackage }),
|
|
300
297
|
})
|
|
301
298
|
|
|
302
299
|
const smtCard = workflowCard({
|
|
303
300
|
tag: 'PCBA',
|
|
304
301
|
tagColor: C.info,
|
|
305
|
-
title:
|
|
302
|
+
title: COPY.order.smtTitle,
|
|
306
303
|
subtitle: assembly === undefined
|
|
307
|
-
?
|
|
308
|
-
:
|
|
304
|
+
? COPY.order.smtSubtitle
|
|
305
|
+
: COPY.order.smtSummary(assembly.positions, assembly.bomLines, formatBytes(assembly.bomBytes + assembly.positionsBytes)),
|
|
309
306
|
details: [
|
|
310
|
-
{ label:
|
|
311
|
-
{ label:
|
|
312
|
-
{ label:
|
|
307
|
+
{ label: COPY.order.placements, value: assembly === undefined ? '—' : String(assembly.positions) },
|
|
308
|
+
{ label: COPY.order.bomLines, value: assembly === undefined ? '—' : String(assembly.bomLines) },
|
|
309
|
+
{ label: COPY.order.credential, value: tokenReady ? COPY.order.signedIn : COPY.order.signedOut },
|
|
313
310
|
],
|
|
314
|
-
action:
|
|
311
|
+
action: COPY.order.smtAction,
|
|
315
312
|
onAction: () => { setAcknowledged(false); setConfirming('smt') },
|
|
316
313
|
busy: placing === 'smt',
|
|
317
314
|
...(assembly === undefined
|
|
318
|
-
? { blocked:
|
|
315
|
+
? { blocked: COPY.order.selectRootSchematic }
|
|
319
316
|
: tokenReady
|
|
320
317
|
? {}
|
|
321
|
-
: { blocked:
|
|
318
|
+
: { blocked: COPY.order.signInToOrderSmt }),
|
|
322
319
|
})
|
|
323
320
|
|
|
324
321
|
const agentHint = createElement(
|
|
325
322
|
'div',
|
|
326
323
|
{ style: { ...ROW, gap: 4, paddingTop: 2 } },
|
|
327
|
-
createElement('span', { style: { fontSize: 10, color: C.text3 } },
|
|
324
|
+
createElement('span', { style: { fontSize: 10, color: C.text3 } }, COPY.order.agentEntryPoints),
|
|
328
325
|
...['quote_pcb', 'place_pcb_order', 'quote_smt', 'place_smt_order'].map(name => createElement(
|
|
329
326
|
'span', { key: name, style: { ...pillStyle('muted'), fontSize: 9.5 } }, name,
|
|
330
327
|
)),
|
|
@@ -334,17 +331,23 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
334
331
|
'div',
|
|
335
332
|
{ style: cardStyle({ borderColor: 'rgba(52,211,153,0.4)' }), 'data-hardware-order-result': placed.kind },
|
|
336
333
|
createElement('div', { style: SPREAD },
|
|
337
|
-
createElement('span', { style: SECTION_TITLE },
|
|
334
|
+
createElement('span', { style: SECTION_TITLE },
|
|
335
|
+
placed.kind === 'pcb' ? COPY.order.resultTitlePcb : COPY.order.resultTitleSmt),
|
|
338
336
|
createElement('span', { style: pillStyle(placed.launched ? 'ok' : 'muted') },
|
|
339
|
-
placed.launched ?
|
|
337
|
+
placed.launched ? COPY.order.resultLaunched : COPY.order.resultReady),
|
|
340
338
|
),
|
|
341
|
-
|
|
339
|
+
// The host sends its own English sentence in `placed.message`; the visible
|
|
340
|
+
// copy is derived here so the panel speaks one language. The host string is
|
|
341
|
+
// kept on the object for tooling, not rendered.
|
|
342
|
+
createElement('p', { style: MUTED },
|
|
343
|
+
placed.launched
|
|
344
|
+
? COPY.order.resultLaunchedMessage(placed.kind === 'pcb' ? 'PCB' : '贴片')
|
|
345
|
+
: COPY.order.resultReadyMessage(placed.kind === 'pcb' ? 'PCB' : '贴片')),
|
|
342
346
|
createElement('a', {
|
|
343
347
|
style: LINK, href: placed.orderUrl, target: '_blank', rel: 'noreferrer noopener',
|
|
344
348
|
'data-hardware-order-url': true,
|
|
345
349
|
}, placed.orderUrl),
|
|
346
|
-
createElement('p', { style: { ...MUTED, fontSize: 10 } },
|
|
347
|
-
'Same page KiCad shows in its order webview, opened in your default browser.'),
|
|
350
|
+
createElement('p', { style: { ...MUTED, fontSize: 10 } }, COPY.order.resultNote),
|
|
348
351
|
createElement('div', { style: ROW },
|
|
349
352
|
createElement('button', {
|
|
350
353
|
type: 'button',
|
|
@@ -352,9 +355,9 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
352
355
|
disabled: reopening,
|
|
353
356
|
'data-hardware-order-reopen': true,
|
|
354
357
|
onClick: () => { void reopen() },
|
|
355
|
-
}, reopening ?
|
|
358
|
+
}, reopening ? COPY.order.opening : COPY.order.openInBrowser),
|
|
356
359
|
createElement('button', { type: 'button', style: buttonStyle('secondary'), onClick: () => { void copy() } },
|
|
357
|
-
copied ?
|
|
360
|
+
copied ? COPY.order.copied : COPY.order.copyUrl),
|
|
358
361
|
createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } },
|
|
359
362
|
`${placed.archive.zipName} · ${formatBytes(placed.archive.zipBytes)}`),
|
|
360
363
|
),
|
|
@@ -362,7 +365,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
362
365
|
|
|
363
366
|
const dialog = confirming === undefined ? null : createElement(
|
|
364
367
|
'div',
|
|
365
|
-
{ style: DIALOG_BACKDROP, role: 'dialog', 'aria-modal': true, 'aria-label':
|
|
368
|
+
{ style: DIALOG_BACKDROP, role: 'dialog', 'aria-modal': true, 'aria-label': COPY.order.confirmAria, 'data-hardware-order-confirm': confirming },
|
|
366
369
|
createElement(
|
|
367
370
|
'div',
|
|
368
371
|
{ style: DIALOG },
|
|
@@ -370,21 +373,20 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
370
373
|
'div',
|
|
371
374
|
{ style: { display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
372
375
|
createElement('h4', { style: { margin: 0, fontSize: 13, fontWeight: 600 } },
|
|
373
|
-
confirming === 'pcb' ?
|
|
374
|
-
createElement('p', { style: MUTED },
|
|
375
|
-
'This sends the files below to the Huaqiu order service. The order is created there and its page opens in your default browser; payment still happens on that page.'),
|
|
376
|
+
confirming === 'pcb' ? COPY.order.confirmTitlePcb : COPY.order.confirmTitleSmt),
|
|
377
|
+
createElement('p', { style: MUTED }, COPY.order.confirmBody),
|
|
376
378
|
),
|
|
377
379
|
createElement(
|
|
378
380
|
'ul',
|
|
379
381
|
{ style: { margin: 0, paddingLeft: 16, fontSize: 11, color: C.text2, lineHeight: 1.7 } },
|
|
380
|
-
createElement('li', null,
|
|
382
|
+
createElement('li', null, COPY.order.confirmZip(prepared?.archive.zipName ?? 'board.zip', zipSize ?? '—')),
|
|
381
383
|
...(confirming === 'smt'
|
|
382
384
|
? [
|
|
383
|
-
createElement('li', { key: 'pos' },
|
|
384
|
-
createElement('li', { key: 'bom' },
|
|
385
|
+
createElement('li', { key: 'pos' }, COPY.order.confirmPositions(assembly === undefined ? '—' : formatBytes(assembly.positionsBytes))),
|
|
386
|
+
createElement('li', { key: 'bom' }, COPY.order.confirmBom(assembly === undefined ? '—' : formatBytes(assembly.bomBytes))),
|
|
385
387
|
]
|
|
386
388
|
: []),
|
|
387
|
-
createElement('li', { key: 'host' }, createElement('span', { style: MONO_TEXT }, config?.baseUrl
|
|
389
|
+
createElement('li', { key: 'host' }, createElement('span', { style: MONO_TEXT }, COPY.order.confirmHost(config?.baseUrl))),
|
|
388
390
|
),
|
|
389
391
|
createElement(
|
|
390
392
|
'label',
|
|
@@ -395,7 +397,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
395
397
|
onChange: (event: { currentTarget: HTMLInputElement }) => { setAcknowledged(event.currentTarget.checked) },
|
|
396
398
|
'data-hardware-order-ack': true,
|
|
397
399
|
}),
|
|
398
|
-
|
|
400
|
+
COPY.order.confirmAck,
|
|
399
401
|
),
|
|
400
402
|
createElement(
|
|
401
403
|
'div',
|
|
@@ -403,14 +405,14 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
403
405
|
createElement('button', {
|
|
404
406
|
type: 'button', style: buttonStyle('quiet'),
|
|
405
407
|
onClick: () => { setConfirming(undefined); setAcknowledged(false) },
|
|
406
|
-
},
|
|
408
|
+
}, COPY.order.cancel),
|
|
407
409
|
createElement('button', {
|
|
408
410
|
type: 'button',
|
|
409
411
|
style: { ...buttonStyle('primary'), ...disabled(!acknowledged || placing !== undefined) },
|
|
410
412
|
disabled: !acknowledged || placing !== undefined,
|
|
411
413
|
'data-hardware-order-confirm-submit': true,
|
|
412
414
|
onClick: () => { void submit(confirming) },
|
|
413
|
-
}, placing === undefined ?
|
|
415
|
+
}, placing === undefined ? COPY.order.uploadAndOpen : COPY.order.uploading),
|
|
414
416
|
),
|
|
415
417
|
),
|
|
416
418
|
)
|
|
@@ -431,7 +433,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
431
433
|
createElement(
|
|
432
434
|
'div',
|
|
433
435
|
{ style: { ...SPREAD, ...cardStyle({ flexDirection: 'row', alignItems: 'center' }) } },
|
|
434
|
-
createElement('span', { style: { fontSize: 11, color: C.text2 } },
|
|
436
|
+
createElement('span', { style: { fontSize: 11, color: C.text2 } }, COPY.order.batch),
|
|
435
437
|
createElement(
|
|
436
438
|
'select',
|
|
437
439
|
{
|
|
@@ -439,9 +441,9 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
|
439
441
|
'data-hardware-order-quantity': true,
|
|
440
442
|
onChange: (event: { currentTarget: HTMLSelectElement }) => { setQuantity(Number(event.currentTarget.value)) },
|
|
441
443
|
},
|
|
442
|
-
...QUANTITIES.map(count => createElement('option', { key: count, value: count },
|
|
444
|
+
...QUANTITIES.map(count => createElement('option', { key: count, value: count }, COPY.order.batchUnits(count))),
|
|
443
445
|
),
|
|
444
|
-
createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } },
|
|
446
|
+
createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } }, COPY.order.quoteBasis(quantity)),
|
|
445
447
|
),
|
|
446
448
|
packageCard,
|
|
447
449
|
resultCard,
|
package/src/client/preview.tsx
CHANGED
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
import { createElement, useEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react'
|
|
10
10
|
import { isAbortError, mountEcad } from './ecad.js'
|
|
11
11
|
import { mountGlb } from './glb.js'
|
|
12
|
-
import { loadBom, prepareBoardGlb, type BomProjection } from './transport.js'
|
|
12
|
+
import { loadBom, messageOf, prepareBoardGlb, type BomProjection } from './transport.js'
|
|
13
13
|
import { OrderPanel } from './order.js'
|
|
14
|
+
import { COPY } from './copy.js'
|
|
14
15
|
import {
|
|
15
16
|
C, cardStyle, dotStyle, MONO, MONO_TEXT, pillStyle, R, SECTION_TITLE,
|
|
16
17
|
} from './theme.js'
|
|
@@ -51,16 +52,12 @@ const SCRIPT: CSSProperties = {
|
|
|
51
52
|
|
|
52
53
|
type Status = 'loading' | 'ready' | 'error'
|
|
53
54
|
|
|
54
|
-
function describe(error: unknown): string {
|
|
55
|
-
return error instanceof Error ? error.message : String(error)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
55
|
function shortRevision(revision: string | undefined): string {
|
|
59
56
|
return revision === undefined ? '' : revision.slice(0, 10)
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
function statusLine(status: Status, message?: string, hint?: string): ReactNode {
|
|
63
|
-
const text = message ?? (status === 'loading' ?
|
|
60
|
+
const text = message ?? (status === 'loading' ? COPY.preview.loading : '')
|
|
64
61
|
return createElement(
|
|
65
62
|
'div',
|
|
66
63
|
{ style: CENTER, role: 'status', 'data-hardware-stage': status },
|
|
@@ -71,7 +68,7 @@ function statusLine(status: Status, message?: string, hint?: string): ReactNode
|
|
|
71
68
|
borderTopColor: C.info, animation: 'dsh-hw-spin 900ms linear infinite',
|
|
72
69
|
},
|
|
73
70
|
})
|
|
74
|
-
: createElement('span', { style: { ...pillStyle('warn'), fontFamily: MONO } },
|
|
71
|
+
: createElement('span', { style: { ...pillStyle('warn'), fontFamily: MONO } }, COPY.preview.unavailable),
|
|
75
72
|
createElement('p', { style: CENTER_TEXT }, text),
|
|
76
73
|
hint === undefined ? null : createElement('p', { style: { ...CENTER_TEXT, fontSize: 10, color: C.text3 } }, hint),
|
|
77
74
|
)
|
|
@@ -133,7 +130,7 @@ function EcadStage({ kind, path, revision, session, cwd }: {
|
|
|
133
130
|
.catch((error: unknown) => {
|
|
134
131
|
if (!live || isAbortError(error)) return
|
|
135
132
|
setStatus('error')
|
|
136
|
-
setMessage(
|
|
133
|
+
setMessage(messageOf(error))
|
|
137
134
|
})
|
|
138
135
|
return () => {
|
|
139
136
|
live = false
|
|
@@ -150,15 +147,15 @@ function EcadStage({ kind, path, revision, session, cwd }: {
|
|
|
150
147
|
attrs: { 'data-hardware-ecad': kind },
|
|
151
148
|
topRight: status === 'ready'
|
|
152
149
|
? [
|
|
153
|
-
createElement('span', { key: 'kind', style: { ...pillStyle('muted'), fontSize: 9.5 } }, kind === 'schematic' ?
|
|
150
|
+
createElement('span', { key: 'kind', style: { ...pillStyle('muted'), fontSize: 9.5 } }, kind === 'schematic' ? COPY.preview.kindSchematic : COPY.preview.kindBoard),
|
|
154
151
|
sourceRevision === undefined
|
|
155
152
|
? null
|
|
156
|
-
: createElement('span', { key: 'rev', style: { ...pillStyle('muted'), fontSize: 9.5 } },
|
|
153
|
+
: createElement('span', { key: 'rev', style: { ...pillStyle('muted'), fontSize: 9.5 } }, COPY.preview.revision(shortRevision(sourceRevision))),
|
|
157
154
|
]
|
|
158
155
|
: undefined,
|
|
159
156
|
overlay: status === 'ready'
|
|
160
157
|
? [createElement('span', { key: 'dot', style: dotStyle(kind === 'schematic' ? C.info : C.ok, 6) }),
|
|
161
|
-
|
|
158
|
+
COPY.preview.ecadOverlay]
|
|
162
159
|
: undefined,
|
|
163
160
|
},
|
|
164
161
|
createElement(
|
|
@@ -166,7 +163,7 @@ function EcadStage({ kind, path, revision, session, cwd }: {
|
|
|
166
163
|
{ style: { position: 'relative', flex: '1 1 0', minHeight: 160 } },
|
|
167
164
|
...(status === 'ready'
|
|
168
165
|
? []
|
|
169
|
-
: [statusLine(status, message, status === 'error' ?
|
|
166
|
+
: [statusLine(status, message, status === 'error' ? COPY.preview.ecadHint : undefined)]),
|
|
170
167
|
createElement('div', { key: 'canvas', ref: container, style: { position: 'absolute', inset: 0 } }),
|
|
171
168
|
),
|
|
172
169
|
)
|
|
@@ -190,21 +187,21 @@ function GlbStage({ boardPath, cwd, session, configured }: {
|
|
|
190
187
|
if (element === null) return
|
|
191
188
|
if (!configured) {
|
|
192
189
|
setStatus('error')
|
|
193
|
-
setMessage(
|
|
190
|
+
setMessage(COPY.preview.kicadNotConfigured)
|
|
194
191
|
return
|
|
195
192
|
}
|
|
196
193
|
const controller = new AbortController()
|
|
197
194
|
let live = true
|
|
198
195
|
let mounted: { dispose(): void } | undefined
|
|
199
196
|
setStatus('loading')
|
|
200
|
-
setMessage(
|
|
197
|
+
setMessage(COPY.preview.glbExporting)
|
|
201
198
|
element.replaceChildren()
|
|
202
199
|
const run = async (): Promise<void> => {
|
|
203
200
|
const glb = await prepareBoardGlb(boardPath, cwd, controller.signal, session)
|
|
204
201
|
if (!live) return
|
|
205
202
|
setRevision(glb.revision)
|
|
206
203
|
setCached(glb.cached)
|
|
207
|
-
setMessage(
|
|
204
|
+
setMessage(COPY.preview.glbLoading)
|
|
208
205
|
mounted = await mountGlb(glb.url, element, { signal: controller.signal })
|
|
209
206
|
if (!live) {
|
|
210
207
|
mounted.dispose()
|
|
@@ -216,7 +213,7 @@ function GlbStage({ boardPath, cwd, session, configured }: {
|
|
|
216
213
|
run().catch((error: unknown) => {
|
|
217
214
|
if (!live || isAbortError(error)) return
|
|
218
215
|
setStatus('error')
|
|
219
|
-
setMessage(
|
|
216
|
+
setMessage(messageOf(error))
|
|
220
217
|
})
|
|
221
218
|
return () => {
|
|
222
219
|
live = false
|
|
@@ -233,11 +230,11 @@ function GlbStage({ boardPath, cwd, session, configured }: {
|
|
|
233
230
|
attrs: { 'data-hardware-glb': true },
|
|
234
231
|
topRight: status === 'ready'
|
|
235
232
|
? [
|
|
236
|
-
createElement('span', { key: 'mode', style: pillStyle('muted', { fontSize: 9.5 }) }, cached ?
|
|
237
|
-
createElement('span', { key: 'rev', style: pillStyle('muted', { fontSize: 9.5 }) },
|
|
233
|
+
createElement('span', { key: 'mode', style: pillStyle('muted', { fontSize: 9.5 }) }, cached ? COPY.preview.glbCached : COPY.preview.glbGenerated),
|
|
234
|
+
createElement('span', { key: 'rev', style: pillStyle('muted', { fontSize: 9.5 }) }, COPY.preview.revision(shortRevision(revision))),
|
|
238
235
|
]
|
|
239
236
|
: undefined,
|
|
240
|
-
overlay: status === 'ready' ?
|
|
237
|
+
overlay: status === 'ready' ? COPY.preview.glbOverlay : 'kicad-cli pcb export glb',
|
|
241
238
|
},
|
|
242
239
|
createElement(
|
|
243
240
|
'div',
|
|
@@ -268,7 +265,7 @@ function BomStage({ schematicPath, session, cwd, configured }: {
|
|
|
268
265
|
useEffect(() => {
|
|
269
266
|
if (!configured) {
|
|
270
267
|
setStatus('error')
|
|
271
|
-
setMessage(
|
|
268
|
+
setMessage(COPY.preview.kicadNotConfigured)
|
|
272
269
|
return
|
|
273
270
|
}
|
|
274
271
|
const controller = new AbortController()
|
|
@@ -287,7 +284,7 @@ function BomStage({ schematicPath, session, cwd, configured }: {
|
|
|
287
284
|
.catch((error: unknown) => {
|
|
288
285
|
if (!live || isAbortError(error)) return
|
|
289
286
|
setStatus('error')
|
|
290
|
-
setMessage(
|
|
287
|
+
setMessage(messageOf(error))
|
|
291
288
|
})
|
|
292
289
|
return () => { live = false; controller.abort() }
|
|
293
290
|
}, [schematicPath, session, cwd, configured])
|
|
@@ -300,7 +297,7 @@ function BomStage({ schematicPath, session, cwd, configured }: {
|
|
|
300
297
|
status,
|
|
301
298
|
message,
|
|
302
299
|
status === 'error' && !configured
|
|
303
|
-
?
|
|
300
|
+
? COPY.preview.bomHint
|
|
304
301
|
: undefined,
|
|
305
302
|
)),
|
|
306
303
|
)
|
|
@@ -316,10 +313,10 @@ function BomStage({ schematicPath, session, cwd, configured }: {
|
|
|
316
313
|
createElement(
|
|
317
314
|
'div',
|
|
318
315
|
{ style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, padding: '8px 10px', borderBottom: `1px solid ${C.border}` } },
|
|
319
|
-
createElement('span', { style: SECTION_TITLE },
|
|
316
|
+
createElement('span', { style: SECTION_TITLE }, COPY.preview.bomTitle(bom.rows.length)),
|
|
320
317
|
createElement('div', { style: { display: 'flex', gap: 4, alignItems: 'center' } },
|
|
321
|
-
createElement('span', { style: pillStyle('muted') },
|
|
322
|
-
createElement('span', { style: pillStyle('muted') },
|
|
318
|
+
createElement('span', { style: pillStyle('muted') }, COPY.preview.bomPlacements(total)),
|
|
319
|
+
createElement('span', { style: pillStyle('muted') }, COPY.preview.revision(shortRevision(bom.revision))),
|
|
323
320
|
),
|
|
324
321
|
),
|
|
325
322
|
createElement(
|
|
@@ -329,7 +326,7 @@ function BomStage({ schematicPath, session, cwd, configured }: {
|
|
|
329
326
|
'table',
|
|
330
327
|
{ style: TABLE },
|
|
331
328
|
createElement('thead', {}, createElement('tr', {},
|
|
332
|
-
...
|
|
329
|
+
...COPY.preview.bomColumns.map(label =>
|
|
333
330
|
createElement('th', { key: label, style: TH }, label)))),
|
|
334
331
|
createElement('tbody', {},
|
|
335
332
|
...bom.rows.map((row, index) => createElement('tr', {
|
package/src/client/transport.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Same-origin calls to the `@huaqiu/hardware-artifacts` Host routes. */
|
|
2
|
+
import { describeHostError } from './copy.js'
|
|
2
3
|
import type {
|
|
3
4
|
DiscoveryInfo, HardwareProjectInfo, InstallationsInfo, NativeApplication,
|
|
4
5
|
} from './model.js'
|
|
@@ -12,16 +13,37 @@ interface Envelope<T> {
|
|
|
12
13
|
readonly [key: string]: unknown
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* One failed call → one `Error` whose message is already user-facing zh_CN.
|
|
18
|
+
*
|
|
19
|
+
* The route envelope carries a stable `code`, so the sentence is chosen here
|
|
20
|
+
* instead of at every render site (the panel, the stages and the settings
|
|
21
|
+
* section all show `error.message`). The code stays on the error object for
|
|
22
|
+
* callers that branch on it. Host detail survives inside the message only when
|
|
23
|
+
* {@link describeHostError} judges it technical rather than prose.
|
|
24
|
+
*/
|
|
15
25
|
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
|
16
26
|
const response = await fetch(`${PREFIX}${path}`, init)
|
|
17
27
|
const body = await response.json().catch(() => undefined) as Envelope<T> | undefined
|
|
18
28
|
if (!response.ok || body?.ok === false) {
|
|
29
|
+
const code = body?.error?.code
|
|
19
30
|
const detail = body?.error?.message ?? `HTTP ${response.status}`
|
|
20
|
-
|
|
31
|
+
const error = new Error(describeHostError(code, detail))
|
|
32
|
+
throw code === undefined ? error : Object.assign(error, { code })
|
|
21
33
|
}
|
|
22
34
|
return body as T
|
|
23
35
|
}
|
|
24
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Readable text of a thrown value.
|
|
39
|
+
*
|
|
40
|
+
* `String(new Error('x'))` is `"Error: x"`, which is why every message the UI
|
|
41
|
+
* renders goes through here instead of `String(error)`.
|
|
42
|
+
*/
|
|
43
|
+
export function messageOf(error: unknown): string {
|
|
44
|
+
return error instanceof Error ? error.message : String(error)
|
|
45
|
+
}
|
|
46
|
+
|
|
25
47
|
function query(cwd: string | undefined, project?: string, session?: string): string {
|
|
26
48
|
const params = new URLSearchParams()
|
|
27
49
|
if (cwd !== undefined && cwd !== '') params.set('cwd', cwd)
|