@huaqiu/dsh-hardware-ui 0.7.13 → 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 +3096 -725
- package/lib/client.js.map +1 -1
- package/package.json +3 -3
- package/src/client/components.tsx +472 -192
- package/src/client/copy.ts +346 -0
- package/src/client/ecad.ts +35 -6
- package/src/client/index.ts +56 -75
- package/src/client/model.ts +51 -17
- package/src/client/order.tsx +453 -0
- package/src/client/preview.tsx +259 -115
- package/src/client/store.ts +41 -8
- package/src/client/theme.ts +158 -0
- package/src/client/transport.ts +175 -13
- package/src/client/wizard.tsx +322 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Design tokens for the Hardware Engineering surfaces.
|
|
3
|
+
*
|
|
4
|
+
* Structure and geometry follow the product prototype (layered dark panels,
|
|
5
|
+
* 12px cards, 11px type, mono numerals, a red primary action); the colours are
|
|
6
|
+
* DSH alias tokens with the prototype values as fallbacks, so the panel stays
|
|
7
|
+
* legible in the light theme instead of hard-coding a dark palette.
|
|
8
|
+
*/
|
|
9
|
+
import type { CSSProperties } from 'react'
|
|
10
|
+
|
|
11
|
+
export const MONO = 'ui-monospace, "JetBrains Mono", SFMono-Regular, Menlo, monospace'
|
|
12
|
+
|
|
13
|
+
export const C = {
|
|
14
|
+
base: 'var(--dsw-alias-bg-base, #161618)',
|
|
15
|
+
panel: 'var(--dsw-alias-bg-layer-1, #1d1d20)',
|
|
16
|
+
card: 'var(--dsw-alias-bg-layer-2, #202024)',
|
|
17
|
+
raised: 'var(--dsw-alias-bg-layer-3, #2a2a2e)',
|
|
18
|
+
border: 'var(--dsw-alias-border-l2, rgba(127,127,127,0.24))',
|
|
19
|
+
borderSoft: 'var(--dsw-alias-border-l1, rgba(127,127,127,0.14))',
|
|
20
|
+
text: 'var(--dsw-alias-label-primary, #ececee)',
|
|
21
|
+
text2: 'var(--dsw-alias-label-secondary, #a1a1aa)',
|
|
22
|
+
text3: 'var(--dsw-alias-label-tertiary, #71717a)',
|
|
23
|
+
accent: '#e1251b',
|
|
24
|
+
accentHover: '#c41e15',
|
|
25
|
+
accentSoft: 'rgba(225, 37, 27, 0.15)',
|
|
26
|
+
ok: '#34d399',
|
|
27
|
+
okSoft: 'rgba(52, 211, 153, 0.14)',
|
|
28
|
+
warn: '#fbbf24',
|
|
29
|
+
warnSoft: 'rgba(251, 191, 36, 0.14)',
|
|
30
|
+
info: '#38bdf8',
|
|
31
|
+
infoSoft: 'rgba(56, 189, 248, 0.14)',
|
|
32
|
+
violet: '#a78bfa',
|
|
33
|
+
pink: '#f472b6',
|
|
34
|
+
} as const
|
|
35
|
+
|
|
36
|
+
export const R = { sm: 6, md: 8, lg: 12, pill: 999 } as const
|
|
37
|
+
|
|
38
|
+
export const DOT_COLORS = {
|
|
39
|
+
schematic: C.info,
|
|
40
|
+
pcb: C.ok,
|
|
41
|
+
bom: C.pink,
|
|
42
|
+
'3d': C.warn,
|
|
43
|
+
order: C.accent,
|
|
44
|
+
} as const
|
|
45
|
+
|
|
46
|
+
export function cardStyle(extra?: CSSProperties): CSSProperties {
|
|
47
|
+
return {
|
|
48
|
+
border: `1px solid ${C.border}`,
|
|
49
|
+
borderRadius: R.lg,
|
|
50
|
+
background: C.card,
|
|
51
|
+
padding: 12,
|
|
52
|
+
display: 'flex',
|
|
53
|
+
flexDirection: 'column',
|
|
54
|
+
gap: 8,
|
|
55
|
+
minWidth: 0,
|
|
56
|
+
...extra,
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const SECTION_TITLE: CSSProperties = {
|
|
61
|
+
margin: 0,
|
|
62
|
+
fontSize: 11,
|
|
63
|
+
fontWeight: 600,
|
|
64
|
+
letterSpacing: 0.2,
|
|
65
|
+
color: C.text2,
|
|
66
|
+
textTransform: 'uppercase',
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const MUTED: CSSProperties = { margin: 0, fontSize: 11, lineHeight: 1.55, color: C.text3 }
|
|
70
|
+
|
|
71
|
+
export const MONO_TEXT: CSSProperties = { fontFamily: MONO, fontVariantNumeric: 'tabular-nums' }
|
|
72
|
+
|
|
73
|
+
export function dotStyle(color: string, size = 7): CSSProperties {
|
|
74
|
+
return { width: size, height: size, borderRadius: R.pill, background: color, flex: '0 0 auto' }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function pillStyle(tone: 'ok' | 'warn' | 'info' | 'muted' | 'accent' = 'muted', extra?: CSSProperties): CSSProperties {
|
|
78
|
+
const tones = {
|
|
79
|
+
ok: { color: C.ok, background: C.okSoft, border: 'rgba(52, 211, 153, 0.28)' },
|
|
80
|
+
warn: { color: C.warn, background: C.warnSoft, border: 'rgba(251, 191, 36, 0.28)' },
|
|
81
|
+
info: { color: C.info, background: C.infoSoft, border: 'rgba(56, 189, 248, 0.28)' },
|
|
82
|
+
accent: { color: C.accent, background: C.accentSoft, border: 'rgba(225, 37, 27, 0.32)' },
|
|
83
|
+
muted: { color: C.text3, background: 'transparent', border: C.border },
|
|
84
|
+
} as const
|
|
85
|
+
const tone_ = tones[tone]
|
|
86
|
+
return {
|
|
87
|
+
display: 'inline-flex',
|
|
88
|
+
alignItems: 'center',
|
|
89
|
+
gap: 4,
|
|
90
|
+
padding: '1px 7px',
|
|
91
|
+
borderRadius: R.pill,
|
|
92
|
+
border: `1px solid ${tone_.border}`,
|
|
93
|
+
background: tone_.background,
|
|
94
|
+
color: tone_.color,
|
|
95
|
+
fontSize: 10,
|
|
96
|
+
lineHeight: 1.6,
|
|
97
|
+
whiteSpace: 'nowrap',
|
|
98
|
+
fontFamily: MONO,
|
|
99
|
+
...extra,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function buttonStyle(kind: 'primary' | 'secondary' | 'quiet' = 'secondary', extra?: CSSProperties): CSSProperties {
|
|
104
|
+
const base: CSSProperties = {
|
|
105
|
+
display: 'inline-flex',
|
|
106
|
+
alignItems: 'center',
|
|
107
|
+
justifyContent: 'center',
|
|
108
|
+
gap: 6,
|
|
109
|
+
padding: '5px 10px',
|
|
110
|
+
borderRadius: R.md,
|
|
111
|
+
font: 'inherit',
|
|
112
|
+
fontSize: 11,
|
|
113
|
+
fontWeight: 500,
|
|
114
|
+
lineHeight: 1.4,
|
|
115
|
+
cursor: 'pointer',
|
|
116
|
+
whiteSpace: 'nowrap',
|
|
117
|
+
transition: 'background 120ms ease, border-color 120ms ease, opacity 120ms ease',
|
|
118
|
+
}
|
|
119
|
+
if (kind === 'primary') {
|
|
120
|
+
return {
|
|
121
|
+
...base,
|
|
122
|
+
border: '1px solid transparent',
|
|
123
|
+
background: C.accent,
|
|
124
|
+
color: '#fff',
|
|
125
|
+
boxShadow: '0 6px 16px rgba(225, 37, 27, 0.22)',
|
|
126
|
+
...extra,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (kind === 'quiet') {
|
|
130
|
+
return { ...base, border: '1px solid transparent', background: 'transparent', color: C.text2, ...extra }
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
...base,
|
|
134
|
+
border: `1px solid ${C.border}`,
|
|
135
|
+
background: C.raised,
|
|
136
|
+
color: C.text,
|
|
137
|
+
...extra,
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const INPUT: CSSProperties = {
|
|
142
|
+
width: '100%',
|
|
143
|
+
boxSizing: 'border-box',
|
|
144
|
+
padding: '5px 8px',
|
|
145
|
+
borderRadius: R.md,
|
|
146
|
+
border: `1px solid ${C.border}`,
|
|
147
|
+
background: C.base,
|
|
148
|
+
color: C.text,
|
|
149
|
+
font: 'inherit',
|
|
150
|
+
fontSize: 11,
|
|
151
|
+
fontFamily: MONO,
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export const SELECT: CSSProperties = { ...INPUT, cursor: 'pointer' }
|
|
155
|
+
|
|
156
|
+
export function disabled(active: boolean): CSSProperties {
|
|
157
|
+
return active ? { opacity: 0.45, cursor: 'not-allowed', boxShadow: 'none' } : {}
|
|
158
|
+
}
|
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,26 +13,48 @@ 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
|
|
|
25
|
-
|
|
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
|
+
|
|
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)
|
|
28
50
|
if (project !== undefined && project !== '') params.set('project', project)
|
|
51
|
+
if (session !== undefined && session !== '') params.set('session', session)
|
|
29
52
|
const text = params.toString()
|
|
30
53
|
return text === '' ? '' : `?${text}`
|
|
31
54
|
}
|
|
32
55
|
|
|
33
|
-
export async function loadProjects(cwd?: string, project?: string): Promise<DiscoveryInfo> {
|
|
34
|
-
const body = await request<DiscoveryInfo>(`/projects${query(cwd, project)}`)
|
|
56
|
+
export async function loadProjects(cwd?: string, project?: string, session?: string): Promise<DiscoveryInfo> {
|
|
57
|
+
const body = await request<DiscoveryInfo>(`/projects${query(cwd, project, session)}`)
|
|
35
58
|
const fallback: DiscoveryInfo = {
|
|
36
59
|
cwd: body.cwd,
|
|
37
60
|
projects: Array.isArray(body.projects) ? body.projects : [],
|
|
@@ -54,6 +77,7 @@ export async function openArtifact(requestBody: {
|
|
|
54
77
|
artifactPath: string
|
|
55
78
|
kind: string
|
|
56
79
|
projectPath?: string
|
|
80
|
+
session?: string
|
|
57
81
|
}): Promise<void> {
|
|
58
82
|
await request('/open', {
|
|
59
83
|
method: 'POST',
|
|
@@ -74,12 +98,21 @@ export interface ArtifactSource {
|
|
|
74
98
|
|
|
75
99
|
export async function loadArtifactSource(
|
|
76
100
|
artifactPath: string,
|
|
77
|
-
|
|
78
|
-
|
|
101
|
+
options: {
|
|
102
|
+
readonly signal?: AbortSignal
|
|
103
|
+
readonly expectedRevision?: string
|
|
104
|
+
readonly session?: string
|
|
105
|
+
/** Workspace root the panel already discovered; the host adds it to the session's own. */
|
|
106
|
+
readonly cwd?: string
|
|
107
|
+
} = {},
|
|
79
108
|
): Promise<ArtifactSource> {
|
|
80
109
|
const params = new URLSearchParams({ path: artifactPath })
|
|
81
|
-
if (expectedRevision !== undefined && expectedRevision !== '')
|
|
82
|
-
|
|
110
|
+
if (options.expectedRevision !== undefined && options.expectedRevision !== '') {
|
|
111
|
+
params.set('revision', options.expectedRevision)
|
|
112
|
+
}
|
|
113
|
+
if (options.session !== undefined && options.session !== '') params.set('session', options.session)
|
|
114
|
+
if (options.cwd !== undefined && options.cwd !== '') params.set('cwd', options.cwd)
|
|
115
|
+
return request<ArtifactSource>(`/source?${params.toString()}`, options.signal === undefined ? {} : { signal: options.signal })
|
|
83
116
|
}
|
|
84
117
|
|
|
85
118
|
/** Generated PCB GLB for one authorized `.kicad_pcb`. */
|
|
@@ -111,12 +144,19 @@ export interface BomProjection {
|
|
|
111
144
|
readonly source: string
|
|
112
145
|
}
|
|
113
146
|
|
|
114
|
-
export async function loadBom(
|
|
147
|
+
export async function loadBom(
|
|
148
|
+
artifactPath: string,
|
|
149
|
+
options: { readonly session?: string; readonly cwd?: string; readonly signal?: AbortSignal } = {},
|
|
150
|
+
): Promise<BomProjection> {
|
|
115
151
|
return request<BomProjection>('/bom', {
|
|
116
152
|
method: 'POST',
|
|
117
153
|
headers: { 'content-type': 'application/json' },
|
|
118
|
-
body: JSON.stringify({
|
|
119
|
-
|
|
154
|
+
body: JSON.stringify({
|
|
155
|
+
path: artifactPath,
|
|
156
|
+
...(options.session === undefined ? {} : { session: options.session }),
|
|
157
|
+
...(options.cwd === undefined ? {} : { cwd: options.cwd }),
|
|
158
|
+
}),
|
|
159
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
120
160
|
})
|
|
121
161
|
}
|
|
122
162
|
|
|
@@ -125,11 +165,133 @@ export async function prepareBoardGlb(
|
|
|
125
165
|
artifactPath: string,
|
|
126
166
|
cwd?: string,
|
|
127
167
|
signal?: AbortSignal,
|
|
168
|
+
session?: string,
|
|
128
169
|
): Promise<GlbArtifact & { readonly url: string }> {
|
|
129
170
|
return request<GlbArtifact & { readonly url: string }>('/glb', {
|
|
130
171
|
method: 'POST',
|
|
131
172
|
headers: { 'content-type': 'application/json' },
|
|
132
|
-
body: JSON.stringify({
|
|
133
|
-
|
|
173
|
+
body: JSON.stringify({
|
|
174
|
+
path: artifactPath,
|
|
175
|
+
...(cwd === undefined ? {} : { cwd }),
|
|
176
|
+
...(session === undefined ? {} : { session }),
|
|
177
|
+
}),
|
|
178
|
+
...(signal === undefined ? {} : { signal }),
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** What the Order destination may do, as the host sees it. */
|
|
183
|
+
export interface OrderConfigInfo {
|
|
184
|
+
readonly configured: boolean
|
|
185
|
+
readonly baseUrl: string
|
|
186
|
+
/** A signed-in Huaqiu session or an explicitly configured token. */
|
|
187
|
+
readonly hasToken: boolean
|
|
188
|
+
readonly provider: string
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export async function loadOrderConfig(): Promise<OrderConfigInfo> {
|
|
192
|
+
return request<OrderConfigInfo>('/order')
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface BoardFactsInfo {
|
|
196
|
+
readonly layers: number
|
|
197
|
+
readonly widthMm: number
|
|
198
|
+
readonly heightMm: number
|
|
199
|
+
readonly thicknessMm: number
|
|
200
|
+
readonly minTrackMm?: number
|
|
201
|
+
readonly minViaDrillMm?: number
|
|
202
|
+
readonly outerOz?: number
|
|
203
|
+
readonly innerOz?: number
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface PackageInfo {
|
|
207
|
+
readonly zipName: string
|
|
208
|
+
readonly zipBytes: number
|
|
209
|
+
readonly files: readonly { readonly name: string; readonly bytes: number }[]
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** A fabrication package prepared on the host; nothing has been uploaded. */
|
|
213
|
+
export interface FabricationProjection {
|
|
214
|
+
readonly boardPath: string
|
|
215
|
+
readonly revision: string
|
|
216
|
+
readonly generatedAt: string
|
|
217
|
+
readonly facts: BoardFactsInfo
|
|
218
|
+
readonly archive: PackageInfo
|
|
219
|
+
readonly assembly?: {
|
|
220
|
+
readonly positions: number
|
|
221
|
+
readonly bomLines: number
|
|
222
|
+
readonly positionsBytes: number
|
|
223
|
+
readonly bomBytes: number
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export async function prepareFabrication(
|
|
228
|
+
boardPath: string,
|
|
229
|
+
schematicPath?: string,
|
|
230
|
+
cwd?: string,
|
|
231
|
+
signal?: AbortSignal,
|
|
232
|
+
session?: string,
|
|
233
|
+
): Promise<FabricationProjection> {
|
|
234
|
+
return request<FabricationProjection>('/fabrication', {
|
|
235
|
+
method: 'POST',
|
|
236
|
+
headers: { 'content-type': 'application/json' },
|
|
237
|
+
body: JSON.stringify({
|
|
238
|
+
path: boardPath,
|
|
239
|
+
...(schematicPath === undefined ? {} : { schematic: schematicPath }),
|
|
240
|
+
...(cwd === undefined ? {} : { cwd }),
|
|
241
|
+
...(session === undefined ? {} : { session }),
|
|
242
|
+
}),
|
|
243
|
+
...(signal === undefined ? {} : { signal }),
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** One placed order, as returned by the host after the backend answered. */
|
|
248
|
+
export interface PlacedOrder {
|
|
249
|
+
readonly kind: 'pcb' | 'smt'
|
|
250
|
+
/** The exact URL KiCad's own action loads in its order webview. */
|
|
251
|
+
readonly orderUrl: string
|
|
252
|
+
/** The backend's raw URL, before KiCad's query parameters were added. */
|
|
253
|
+
readonly responseUrl: string
|
|
254
|
+
readonly launched: boolean
|
|
255
|
+
readonly launcher?: string
|
|
256
|
+
readonly status: 'launched' | 'ready'
|
|
257
|
+
readonly message: string
|
|
258
|
+
readonly endpoint: string
|
|
259
|
+
readonly archive: PackageInfo
|
|
260
|
+
readonly assembly?: FabricationProjection['assembly']
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Submit one order. `confirm` is what the host requires; the panel sets it only
|
|
265
|
+
* after the user confirms the upload in the dialog. The host opens the order
|
|
266
|
+
* page in the default browser unless `launch` is false.
|
|
267
|
+
*/
|
|
268
|
+
export async function placeOrder(
|
|
269
|
+
kind: 'pcb' | 'smt',
|
|
270
|
+
requestBody: {
|
|
271
|
+
path: string
|
|
272
|
+
schematic?: string
|
|
273
|
+
/** Workspace root, never the project file; the host authorizes against it. */
|
|
274
|
+
cwd?: string
|
|
275
|
+
session?: string
|
|
276
|
+
quantity?: number
|
|
277
|
+
confirm: boolean
|
|
278
|
+
launch?: boolean
|
|
279
|
+
},
|
|
280
|
+
signal?: AbortSignal,
|
|
281
|
+
): Promise<PlacedOrder> {
|
|
282
|
+
return request<PlacedOrder>(`/order/${kind}`, {
|
|
283
|
+
method: 'POST',
|
|
284
|
+
headers: { 'content-type': 'application/json' },
|
|
285
|
+
body: JSON.stringify(requestBody),
|
|
286
|
+
...(signal === undefined ? {} : { signal }),
|
|
287
|
+
})
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Hand an already-created order page back to the OS default browser. */
|
|
291
|
+
export async function openOrderUrl(url: string): Promise<{ readonly launched: boolean; readonly command: string }> {
|
|
292
|
+
return request<{ readonly launched: boolean; readonly command: string }>('/order/open', {
|
|
293
|
+
method: 'POST',
|
|
294
|
+
headers: { 'content-type': 'application/json' },
|
|
295
|
+
body: JSON.stringify({ url }),
|
|
134
296
|
})
|
|
135
297
|
}
|