@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
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. */
|
|
@@ -56,6 +65,7 @@ export interface HardwareProjectInfo {
|
|
|
56
65
|
export interface InstallationsInfo {
|
|
57
66
|
readonly kicad?: {
|
|
58
67
|
readonly configured: boolean
|
|
68
|
+
readonly root?: string
|
|
59
69
|
readonly version?: string
|
|
60
70
|
readonly cli?: string
|
|
61
71
|
readonly pcbEditor?: string
|
|
@@ -64,6 +74,7 @@ export interface InstallationsInfo {
|
|
|
64
74
|
}
|
|
65
75
|
readonly solidcraft?: {
|
|
66
76
|
readonly configured: boolean
|
|
77
|
+
readonly root?: string
|
|
67
78
|
readonly executable?: string
|
|
68
79
|
readonly error?: string
|
|
69
80
|
}
|
|
@@ -93,9 +104,11 @@ export interface HardwareState {
|
|
|
93
104
|
export interface HardwareActions {
|
|
94
105
|
setActive(destination: HardwareDestination): void
|
|
95
106
|
setWorkspaceRoot(root: string): void
|
|
96
|
-
setDiscovery(discovery: DiscoveryInfo): void
|
|
107
|
+
setDiscovery(discovery: DiscoveryInfo, preserveSelection?: boolean): void
|
|
97
108
|
selectProject(path: string): void
|
|
98
109
|
selectArtifact(path: string, kind: 'schematic' | 'pcb'): void
|
|
110
|
+
/** Adopt one `sidebar.right.openTab` navigation into viewer state. */
|
|
111
|
+
applyNavigation(params: ViewerNavigationParams): void
|
|
99
112
|
setInstallations(installations: InstallationsInfo): void
|
|
100
113
|
setNotice(notice?: string): void
|
|
101
114
|
refresh(): void
|
|
@@ -110,6 +123,8 @@ export interface ConfigFormLike<T> {
|
|
|
110
123
|
export interface HardwareInstallationConfig {
|
|
111
124
|
readonly kicadRoot?: string
|
|
112
125
|
readonly solidcraftRoot?: string
|
|
126
|
+
/** Set once the first-run setup wizard has been completed or skipped. */
|
|
127
|
+
readonly onboardingComplete?: boolean
|
|
113
128
|
}
|
|
114
129
|
|
|
115
130
|
/** Parameters carried by one `sidebar.right.openTab` navigation. */
|
|
@@ -126,16 +141,35 @@ export interface ViewerNavigationParams {
|
|
|
126
141
|
readonly navigationRevision: number
|
|
127
142
|
}
|
|
128
143
|
|
|
129
|
-
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
144
|
+
/**
|
|
145
|
+
* The product's business face, delivered verbatim to every registered
|
|
146
|
+
* component.
|
|
147
|
+
*
|
|
148
|
+
* It deliberately has no `hooks` member: DSH rebinds a `hooks` compartment into
|
|
149
|
+
* `use<Name>` selector hooks over observables, so a plain function bundle there
|
|
150
|
+
* would arrive as a broken selector instead of the object the component reads.
|
|
151
|
+
* Each member is an ordinary function; state writes stay in the component's own
|
|
152
|
+
* `actions`, so no shared mutable action capture is needed.
|
|
153
|
+
*/
|
|
154
|
+
export interface HardwareController {
|
|
155
|
+
/**
|
|
156
|
+
* Host-side artifact discovery for one workspace root.
|
|
157
|
+
*
|
|
158
|
+
* `session` scopes the result: the host remembers discovery per session, so
|
|
159
|
+
* two viewers in different workspaces never overwrite each other's roots.
|
|
160
|
+
*/
|
|
161
|
+
discover(cwd?: string, project?: string, session?: string): Promise<DiscoveryInfo>
|
|
162
|
+
/** Host-side installation validation. */
|
|
163
|
+
installations(): Promise<InstallationsInfo>
|
|
134
164
|
saveInstallation(application: 'kicad' | 'solidcraft', root: string): Promise<void>
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
165
|
+
/** The host-backed configuration form, when the settings service is mounted. */
|
|
166
|
+
configForm(): ConfigFormLike<HardwareInstallationConfig> | undefined
|
|
167
|
+
/** Open or retarget the product viewer tab. */
|
|
168
|
+
openDestination(destination: HardwareDestination, path?: string): void
|
|
169
|
+
/** Launch the exact artifact in its configured native application. */
|
|
170
|
+
openNative(request: {
|
|
171
|
+
application: NativeApplication
|
|
172
|
+
artifactPath: string
|
|
173
|
+
kind: string
|
|
174
|
+
}): Promise<void>
|
|
141
175
|
}
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order Placing destination.
|
|
3
|
+
*
|
|
4
|
+
* The panel never prices anything and never keeps its own order backend. It
|
|
5
|
+
* prepares the fabrication package with `kicad-cli` through the host, shows
|
|
6
|
+
* exactly what would be uploaded, and submits only after the user confirms in
|
|
7
|
+
* a dialog. The URL shown afterwards is the backend's own URL, passed through.
|
|
8
|
+
*/
|
|
9
|
+
import { createElement, useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react'
|
|
10
|
+
import { isAbortError } from './ecad.js'
|
|
11
|
+
import { COPY } from './copy.js'
|
|
12
|
+
import {
|
|
13
|
+
loadOrderConfig, messageOf, openOrderUrl, placeOrder, prepareFabrication,
|
|
14
|
+
type FabricationProjection, type OrderConfigInfo, type PlacedOrder,
|
|
15
|
+
} from './transport.js'
|
|
16
|
+
import {
|
|
17
|
+
buttonStyle, C, cardStyle, disabled, dotStyle, MUTED, MONO, MONO_TEXT, pillStyle, R, SECTION_TITLE, SELECT,
|
|
18
|
+
} from './theme.js'
|
|
19
|
+
|
|
20
|
+
export interface OrderPanelProps {
|
|
21
|
+
readonly boardPath: string
|
|
22
|
+
readonly boardTitle: string
|
|
23
|
+
readonly schematicPath?: string
|
|
24
|
+
/**
|
|
25
|
+
* Workspace root of the session showing this panel. It is the authorization
|
|
26
|
+
* base the host re-checks; the project file is not, and never was.
|
|
27
|
+
*/
|
|
28
|
+
readonly workspaceRoot?: string
|
|
29
|
+
/** DSH session the panel belongs to; the host authorizes against its workspace. */
|
|
30
|
+
readonly session?: string
|
|
31
|
+
readonly configured: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const QUANTITIES = [5, 20, 100] as const
|
|
35
|
+
|
|
36
|
+
function formatBytes(bytes: number): string {
|
|
37
|
+
if (bytes < 1024) return `${String(bytes)} B`
|
|
38
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
|
|
39
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function specRows(facts: FabricationProjection['facts']): { label: string; value: string }[] {
|
|
43
|
+
return [
|
|
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) },
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const SPEC_GRID: CSSProperties = {
|
|
54
|
+
display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(88px, 1fr))', gap: 6,
|
|
55
|
+
}
|
|
56
|
+
const SPEC_CELL: CSSProperties = {
|
|
57
|
+
border: `1px solid ${C.borderSoft}`, borderRadius: R.md, background: C.base,
|
|
58
|
+
padding: '5px 7px', display: 'flex', flexDirection: 'column', gap: 1, minWidth: 0,
|
|
59
|
+
}
|
|
60
|
+
const SPEC_LABEL: CSSProperties = { fontSize: 9.5, color: C.text3, letterSpacing: 0.2 }
|
|
61
|
+
const SPEC_VALUE: CSSProperties = { fontSize: 11, ...MONO_TEXT, color: C.text, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }
|
|
62
|
+
const ROW: CSSProperties = { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap', minWidth: 0 }
|
|
63
|
+
const SPREAD: CSSProperties = { ...ROW, justifyContent: 'space-between' }
|
|
64
|
+
const TAG: CSSProperties = {
|
|
65
|
+
fontSize: 9.5, fontWeight: 600, letterSpacing: 0.6, padding: '1px 5px', borderRadius: R.sm,
|
|
66
|
+
border: '1px solid currentColor', fontFamily: MONO,
|
|
67
|
+
}
|
|
68
|
+
const LINK: CSSProperties = {
|
|
69
|
+
color: C.info, fontSize: 11, fontFamily: MONO, wordBreak: 'break-all', textDecoration: 'underline',
|
|
70
|
+
textUnderlineOffset: 2,
|
|
71
|
+
}
|
|
72
|
+
const DIALOG_BACKDROP: CSSProperties = {
|
|
73
|
+
position: 'absolute', inset: 0, background: 'rgba(0,0,0,0.55)', backdropFilter: 'blur(2px)',
|
|
74
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 14, zIndex: 20,
|
|
75
|
+
}
|
|
76
|
+
const DIALOG: CSSProperties = {
|
|
77
|
+
width: '100%', maxWidth: 420, maxHeight: '90%', overflow: 'auto', background: C.card,
|
|
78
|
+
border: `1px solid ${C.border}`, borderRadius: R.lg, boxShadow: '0 24px 60px rgba(0,0,0,0.45)',
|
|
79
|
+
padding: 14, display: 'flex', flexDirection: 'column', gap: 10,
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** One workflow card: what it will do, what it needs, and its action. */
|
|
83
|
+
function workflowCard(input: {
|
|
84
|
+
readonly tag: string
|
|
85
|
+
readonly tagColor: string
|
|
86
|
+
readonly title: string
|
|
87
|
+
readonly subtitle: string
|
|
88
|
+
readonly details: readonly { label: string; value: string }[]
|
|
89
|
+
readonly action: string
|
|
90
|
+
readonly onAction: () => void
|
|
91
|
+
readonly busy: boolean
|
|
92
|
+
readonly blocked?: string
|
|
93
|
+
}): ReactNode {
|
|
94
|
+
const blocked = input.blocked !== undefined
|
|
95
|
+
return createElement(
|
|
96
|
+
'div',
|
|
97
|
+
{ style: cardStyle({ gap: 9 }), 'data-hardware-order-card': input.tag.toLowerCase() },
|
|
98
|
+
createElement(
|
|
99
|
+
'div',
|
|
100
|
+
{ style: { ...ROW, gap: 7 } },
|
|
101
|
+
createElement('span', { style: { ...TAG, color: input.tagColor } }, input.tag),
|
|
102
|
+
createElement('span', { style: { fontSize: 12, fontWeight: 600, color: C.text, minWidth: 0 } }, input.title),
|
|
103
|
+
),
|
|
104
|
+
createElement('p', { style: MUTED }, input.subtitle),
|
|
105
|
+
createElement(
|
|
106
|
+
'div',
|
|
107
|
+
{ style: SPEC_GRID },
|
|
108
|
+
...input.details.map(detail => createElement(
|
|
109
|
+
'div',
|
|
110
|
+
{ key: detail.label, style: SPEC_CELL },
|
|
111
|
+
createElement('span', { style: SPEC_LABEL }, detail.label),
|
|
112
|
+
createElement('span', { style: SPEC_VALUE, title: detail.value }, detail.value),
|
|
113
|
+
)),
|
|
114
|
+
),
|
|
115
|
+
blocked
|
|
116
|
+
? createElement('p', { style: { ...MUTED, color: C.warn } }, input.blocked ?? '')
|
|
117
|
+
: null,
|
|
118
|
+
createElement(
|
|
119
|
+
'button',
|
|
120
|
+
{
|
|
121
|
+
type: 'button', style: { ...buttonStyle('primary'), width: '100%', ...disabled(blocked || input.busy) },
|
|
122
|
+
disabled: blocked || input.busy,
|
|
123
|
+
'data-hardware-order-action': input.tag.toLowerCase(),
|
|
124
|
+
onClick: input.onAction,
|
|
125
|
+
},
|
|
126
|
+
input.busy ? COPY.order.submitting : input.action,
|
|
127
|
+
),
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function OrderPanel(props: OrderPanelProps): ReactNode {
|
|
132
|
+
const { boardPath, boardTitle, schematicPath, workspaceRoot, session, configured } = props
|
|
133
|
+
const [config, setConfig] = useState<OrderConfigInfo>()
|
|
134
|
+
const [prepared, setPrepared] = useState<FabricationProjection>()
|
|
135
|
+
const [preparing, setPreparing] = useState(false)
|
|
136
|
+
const [message, setMessage] = useState<string>()
|
|
137
|
+
const [quantity, setQuantity] = useState<number>(20)
|
|
138
|
+
const [confirming, setConfirming] = useState<'pcb' | 'smt'>()
|
|
139
|
+
const [acknowledged, setAcknowledged] = useState(false)
|
|
140
|
+
const [placing, setPlacing] = useState<'pcb' | 'smt'>()
|
|
141
|
+
const [placed, setPlaced] = useState<PlacedOrder>()
|
|
142
|
+
const [copied, setCopied] = useState(false)
|
|
143
|
+
const [reopening, setReopening] = useState(false)
|
|
144
|
+
const live = useRef(true)
|
|
145
|
+
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
live.current = true
|
|
148
|
+
return () => { live.current = false }
|
|
149
|
+
}, [])
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
loadOrderConfig()
|
|
153
|
+
.then((value) => { if (live.current) setConfig(value) })
|
|
154
|
+
.catch((error: unknown) => { if (live.current) setMessage(messageOf(error)) })
|
|
155
|
+
}, [])
|
|
156
|
+
|
|
157
|
+
// Preparing the package is local: gerbers, drill files and CSVs come from the
|
|
158
|
+
// saved board. Nothing leaves the machine until the user confirms an order.
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (!configured) {
|
|
161
|
+
setPrepared(undefined)
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
const controller = new AbortController()
|
|
165
|
+
setPreparing(true)
|
|
166
|
+
setMessage(undefined)
|
|
167
|
+
setPlaced(undefined)
|
|
168
|
+
prepareFabrication(boardPath, schematicPath, workspaceRoot, controller.signal, session)
|
|
169
|
+
.then((value) => { if (!controller.signal.aborted) setPrepared(value) })
|
|
170
|
+
.catch((error: unknown) => {
|
|
171
|
+
if (controller.signal.aborted || isAbortError(error)) return
|
|
172
|
+
setMessage(messageOf(error))
|
|
173
|
+
})
|
|
174
|
+
.finally(() => { if (!controller.signal.aborted) setPreparing(false) })
|
|
175
|
+
return () => { controller.abort() }
|
|
176
|
+
}, [boardPath, schematicPath, workspaceRoot, session, configured])
|
|
177
|
+
|
|
178
|
+
const facts = prepared?.facts
|
|
179
|
+
const specs = useMemo(() => (facts === undefined ? [] : specRows(facts)), [facts])
|
|
180
|
+
|
|
181
|
+
const submit = async (kind: 'pcb' | 'smt'): Promise<void> => {
|
|
182
|
+
setPlacing(kind)
|
|
183
|
+
setMessage(undefined)
|
|
184
|
+
try {
|
|
185
|
+
const result = await placeOrder(kind, {
|
|
186
|
+
path: boardPath,
|
|
187
|
+
...(schematicPath === undefined ? {} : { schematic: schematicPath }),
|
|
188
|
+
...(workspaceRoot === undefined ? {} : { cwd: workspaceRoot }),
|
|
189
|
+
...(session === undefined ? {} : { session }),
|
|
190
|
+
quantity,
|
|
191
|
+
confirm: true,
|
|
192
|
+
}, undefined)
|
|
193
|
+
setPlaced(result)
|
|
194
|
+
setConfirming(undefined)
|
|
195
|
+
setAcknowledged(false)
|
|
196
|
+
} catch (error) {
|
|
197
|
+
setMessage(messageOf(error))
|
|
198
|
+
} finally {
|
|
199
|
+
setPlacing(undefined)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const copy = async (): Promise<void> => {
|
|
204
|
+
if (placed === undefined) return
|
|
205
|
+
try {
|
|
206
|
+
await navigator.clipboard.writeText(placed.orderUrl)
|
|
207
|
+
setCopied(true)
|
|
208
|
+
setTimeout(() => { setCopied(false) }, 1600)
|
|
209
|
+
} catch {
|
|
210
|
+
setCopied(false)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const reopen = async (): Promise<void> => {
|
|
215
|
+
if (placed === undefined) return
|
|
216
|
+
setReopening(true)
|
|
217
|
+
setMessage(undefined)
|
|
218
|
+
try {
|
|
219
|
+
await openOrderUrl(placed.orderUrl)
|
|
220
|
+
setPlaced({ ...placed, launched: true, status: 'launched' })
|
|
221
|
+
} catch (error) {
|
|
222
|
+
setMessage(messageOf(error))
|
|
223
|
+
} finally {
|
|
224
|
+
setReopening(false)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const zipSize = prepared === undefined ? undefined : formatBytes(prepared.archive.zipBytes)
|
|
229
|
+
const assembly = prepared?.assembly
|
|
230
|
+
const tokenReady = config?.hasToken ?? false
|
|
231
|
+
|
|
232
|
+
const header = createElement(
|
|
233
|
+
'div',
|
|
234
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
235
|
+
createElement(
|
|
236
|
+
'div',
|
|
237
|
+
{ style: SPREAD },
|
|
238
|
+
createElement(
|
|
239
|
+
'h3',
|
|
240
|
+
{ style: { margin: 0, fontSize: 13, fontWeight: 600, color: C.text, display: 'flex', alignItems: 'center', gap: 6 } },
|
|
241
|
+
createElement('span', { style: dotStyle(C.accent) }),
|
|
242
|
+
COPY.order.title,
|
|
243
|
+
),
|
|
244
|
+
preparing
|
|
245
|
+
? createElement('span', { style: pillStyle('info') }, COPY.order.packaging)
|
|
246
|
+
: prepared !== undefined
|
|
247
|
+
? createElement('span', { style: pillStyle('ok') }, COPY.order.packageReady)
|
|
248
|
+
: createElement('span', { style: pillStyle(configured ? 'muted' : 'warn') }, configured ? COPY.order.packagePending : COPY.viewer.kicadMissing),
|
|
249
|
+
),
|
|
250
|
+
createElement('p', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10.5 } }, boardTitle),
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
const packageCard = createElement(
|
|
254
|
+
'div',
|
|
255
|
+
{ style: cardStyle() },
|
|
256
|
+
createElement('div', { style: SPREAD },
|
|
257
|
+
createElement('span', { style: SECTION_TITLE }, COPY.order.packageCard),
|
|
258
|
+
prepared === undefined
|
|
259
|
+
? null
|
|
260
|
+
: createElement('span', { style: pillStyle('muted') }, COPY.order.packageFiles(prepared.archive.files.length, zipSize ?? '')),
|
|
261
|
+
),
|
|
262
|
+
prepared === undefined
|
|
263
|
+
? createElement('p', { style: MUTED },
|
|
264
|
+
preparing ? COPY.order.packageRunning : COPY.order.packageNotPrepared)
|
|
265
|
+
: createElement(
|
|
266
|
+
'div',
|
|
267
|
+
{
|
|
268
|
+
style: {
|
|
269
|
+
display: 'flex', flexWrap: 'wrap', gap: 4, maxHeight: 74, overflow: 'auto',
|
|
270
|
+
border: `1px solid ${C.borderSoft}`, borderRadius: R.md, padding: 6, background: C.base,
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
...prepared.archive.files.map(file => createElement(
|
|
274
|
+
'span',
|
|
275
|
+
{ key: file.name, style: { ...pillStyle('muted'), fontSize: 9.5, padding: '0 5px' }, title: `${file.name} · ${formatBytes(file.bytes)}` },
|
|
276
|
+
file.name,
|
|
277
|
+
)),
|
|
278
|
+
),
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
const pcbCard = workflowCard({
|
|
282
|
+
tag: 'PCB',
|
|
283
|
+
tagColor: C.ok,
|
|
284
|
+
title: COPY.order.pcbTitle,
|
|
285
|
+
subtitle: prepared === undefined
|
|
286
|
+
? COPY.order.pcbSubtitle
|
|
287
|
+
: COPY.order.pcbSummary(prepared.archive.zipName, prepared.archive.files.length, zipSize ?? ''),
|
|
288
|
+
details: specs.length === 0
|
|
289
|
+
? [{ label: COPY.order.boardFile, value: boardTitle }]
|
|
290
|
+
: specs,
|
|
291
|
+
action: COPY.order.pcbAction,
|
|
292
|
+
onAction: () => { setAcknowledged(false); setConfirming('pcb') },
|
|
293
|
+
busy: placing === 'pcb',
|
|
294
|
+
...(configured && prepared !== undefined
|
|
295
|
+
? tokenReady ? {} : { blocked: COPY.order.signInToOrder }
|
|
296
|
+
: { blocked: configured ? COPY.order.waitingForPackage : COPY.order.configureToPackage }),
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
const smtCard = workflowCard({
|
|
300
|
+
tag: 'PCBA',
|
|
301
|
+
tagColor: C.info,
|
|
302
|
+
title: COPY.order.smtTitle,
|
|
303
|
+
subtitle: assembly === undefined
|
|
304
|
+
? COPY.order.smtSubtitle
|
|
305
|
+
: COPY.order.smtSummary(assembly.positions, assembly.bomLines, formatBytes(assembly.bomBytes + assembly.positionsBytes)),
|
|
306
|
+
details: [
|
|
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 },
|
|
310
|
+
],
|
|
311
|
+
action: COPY.order.smtAction,
|
|
312
|
+
onAction: () => { setAcknowledged(false); setConfirming('smt') },
|
|
313
|
+
busy: placing === 'smt',
|
|
314
|
+
...(assembly === undefined
|
|
315
|
+
? { blocked: COPY.order.selectRootSchematic }
|
|
316
|
+
: tokenReady
|
|
317
|
+
? {}
|
|
318
|
+
: { blocked: COPY.order.signInToOrderSmt }),
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
const agentHint = createElement(
|
|
322
|
+
'div',
|
|
323
|
+
{ style: { ...ROW, gap: 4, paddingTop: 2 } },
|
|
324
|
+
createElement('span', { style: { fontSize: 10, color: C.text3 } }, COPY.order.agentEntryPoints),
|
|
325
|
+
...['quote_pcb', 'place_pcb_order', 'quote_smt', 'place_smt_order'].map(name => createElement(
|
|
326
|
+
'span', { key: name, style: { ...pillStyle('muted'), fontSize: 9.5 } }, name,
|
|
327
|
+
)),
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
const resultCard = placed === undefined ? null : createElement(
|
|
331
|
+
'div',
|
|
332
|
+
{ style: cardStyle({ borderColor: 'rgba(52,211,153,0.4)' }), 'data-hardware-order-result': placed.kind },
|
|
333
|
+
createElement('div', { style: SPREAD },
|
|
334
|
+
createElement('span', { style: SECTION_TITLE },
|
|
335
|
+
placed.kind === 'pcb' ? COPY.order.resultTitlePcb : COPY.order.resultTitleSmt),
|
|
336
|
+
createElement('span', { style: pillStyle(placed.launched ? 'ok' : 'muted') },
|
|
337
|
+
placed.launched ? COPY.order.resultLaunched : COPY.order.resultReady),
|
|
338
|
+
),
|
|
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' : '贴片')),
|
|
346
|
+
createElement('a', {
|
|
347
|
+
style: LINK, href: placed.orderUrl, target: '_blank', rel: 'noreferrer noopener',
|
|
348
|
+
'data-hardware-order-url': true,
|
|
349
|
+
}, placed.orderUrl),
|
|
350
|
+
createElement('p', { style: { ...MUTED, fontSize: 10 } }, COPY.order.resultNote),
|
|
351
|
+
createElement('div', { style: ROW },
|
|
352
|
+
createElement('button', {
|
|
353
|
+
type: 'button',
|
|
354
|
+
style: { ...buttonStyle('primary'), ...disabled(reopening) },
|
|
355
|
+
disabled: reopening,
|
|
356
|
+
'data-hardware-order-reopen': true,
|
|
357
|
+
onClick: () => { void reopen() },
|
|
358
|
+
}, reopening ? COPY.order.opening : COPY.order.openInBrowser),
|
|
359
|
+
createElement('button', { type: 'button', style: buttonStyle('secondary'), onClick: () => { void copy() } },
|
|
360
|
+
copied ? COPY.order.copied : COPY.order.copyUrl),
|
|
361
|
+
createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } },
|
|
362
|
+
`${placed.archive.zipName} · ${formatBytes(placed.archive.zipBytes)}`),
|
|
363
|
+
),
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
const dialog = confirming === undefined ? null : createElement(
|
|
367
|
+
'div',
|
|
368
|
+
{ style: DIALOG_BACKDROP, role: 'dialog', 'aria-modal': true, 'aria-label': COPY.order.confirmAria, 'data-hardware-order-confirm': confirming },
|
|
369
|
+
createElement(
|
|
370
|
+
'div',
|
|
371
|
+
{ style: DIALOG },
|
|
372
|
+
createElement(
|
|
373
|
+
'div',
|
|
374
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
375
|
+
createElement('h4', { style: { margin: 0, fontSize: 13, fontWeight: 600 } },
|
|
376
|
+
confirming === 'pcb' ? COPY.order.confirmTitlePcb : COPY.order.confirmTitleSmt),
|
|
377
|
+
createElement('p', { style: MUTED }, COPY.order.confirmBody),
|
|
378
|
+
),
|
|
379
|
+
createElement(
|
|
380
|
+
'ul',
|
|
381
|
+
{ style: { margin: 0, paddingLeft: 16, fontSize: 11, color: C.text2, lineHeight: 1.7 } },
|
|
382
|
+
createElement('li', null, COPY.order.confirmZip(prepared?.archive.zipName ?? 'board.zip', zipSize ?? '—')),
|
|
383
|
+
...(confirming === 'smt'
|
|
384
|
+
? [
|
|
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))),
|
|
387
|
+
]
|
|
388
|
+
: []),
|
|
389
|
+
createElement('li', { key: 'host' }, createElement('span', { style: MONO_TEXT }, COPY.order.confirmHost(config?.baseUrl))),
|
|
390
|
+
),
|
|
391
|
+
createElement(
|
|
392
|
+
'label',
|
|
393
|
+
{ style: { ...ROW, alignItems: 'flex-start', fontSize: 11, color: C.text2, cursor: 'pointer' } },
|
|
394
|
+
createElement('input', {
|
|
395
|
+
type: 'checkbox', checked: acknowledged,
|
|
396
|
+
style: { marginTop: 2, accentColor: C.accent },
|
|
397
|
+
onChange: (event: { currentTarget: HTMLInputElement }) => { setAcknowledged(event.currentTarget.checked) },
|
|
398
|
+
'data-hardware-order-ack': true,
|
|
399
|
+
}),
|
|
400
|
+
COPY.order.confirmAck,
|
|
401
|
+
),
|
|
402
|
+
createElement(
|
|
403
|
+
'div',
|
|
404
|
+
{ style: { ...ROW, justifyContent: 'flex-end' } },
|
|
405
|
+
createElement('button', {
|
|
406
|
+
type: 'button', style: buttonStyle('quiet'),
|
|
407
|
+
onClick: () => { setConfirming(undefined); setAcknowledged(false) },
|
|
408
|
+
}, COPY.order.cancel),
|
|
409
|
+
createElement('button', {
|
|
410
|
+
type: 'button',
|
|
411
|
+
style: { ...buttonStyle('primary'), ...disabled(!acknowledged || placing !== undefined) },
|
|
412
|
+
disabled: !acknowledged || placing !== undefined,
|
|
413
|
+
'data-hardware-order-confirm-submit': true,
|
|
414
|
+
onClick: () => { void submit(confirming) },
|
|
415
|
+
}, placing === undefined ? COPY.order.uploadAndOpen : COPY.order.uploading),
|
|
416
|
+
),
|
|
417
|
+
),
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
return createElement(
|
|
421
|
+
'div',
|
|
422
|
+
{ style: { position: 'relative', display: 'flex', flexDirection: 'column', gap: 10, minHeight: 0 }, 'data-hardware-order': true },
|
|
423
|
+
header,
|
|
424
|
+
...(message === undefined ? [] : [createElement('p', {
|
|
425
|
+
key: 'message', role: 'status', style: { ...MUTED, color: C.warn, borderLeft: `2px solid ${C.warn}`, paddingLeft: 8 },
|
|
426
|
+
}, message)]),
|
|
427
|
+
createElement(
|
|
428
|
+
'div',
|
|
429
|
+
{ style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(250px, 1fr))', gap: 10 } },
|
|
430
|
+
pcbCard,
|
|
431
|
+
smtCard,
|
|
432
|
+
),
|
|
433
|
+
createElement(
|
|
434
|
+
'div',
|
|
435
|
+
{ style: { ...SPREAD, ...cardStyle({ flexDirection: 'row', alignItems: 'center' }) } },
|
|
436
|
+
createElement('span', { style: { fontSize: 11, color: C.text2 } }, COPY.order.batch),
|
|
437
|
+
createElement(
|
|
438
|
+
'select',
|
|
439
|
+
{
|
|
440
|
+
style: { ...SELECT, width: 'auto' }, value: quantity,
|
|
441
|
+
'data-hardware-order-quantity': true,
|
|
442
|
+
onChange: (event: { currentTarget: HTMLSelectElement }) => { setQuantity(Number(event.currentTarget.value)) },
|
|
443
|
+
},
|
|
444
|
+
...QUANTITIES.map(count => createElement('option', { key: count, value: count }, COPY.order.batchUnits(count))),
|
|
445
|
+
),
|
|
446
|
+
createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } }, COPY.order.quoteBasis(quantity)),
|
|
447
|
+
),
|
|
448
|
+
packageCard,
|
|
449
|
+
resultCard,
|
|
450
|
+
agentHint,
|
|
451
|
+
dialog,
|
|
452
|
+
)
|
|
453
|
+
}
|