@huaqiu/dsh-hardware-ui 0.7.13 → 0.7.14
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 +2791 -699
- package/lib/client.js.map +1 -1
- package/package.json +3 -3
- package/src/client/components.tsx +460 -186
- package/src/client/ecad.ts +33 -5
- package/src/client/index.ts +49 -71
- package/src/client/model.ts +37 -12
- package/src/client/order.tsx +451 -0
- package/src/client/preview.tsx +257 -110
- package/src/client/store.ts +41 -8
- package/src/client/theme.ts +158 -0
- package/src/client/transport.ts +152 -12
- package/src/client/wizard.tsx +326 -0
package/src/client/ecad.ts
CHANGED
|
@@ -37,28 +37,56 @@ export async function mountEcad(
|
|
|
37
37
|
kind: EcadKind,
|
|
38
38
|
artifactPath: string,
|
|
39
39
|
container: HTMLElement,
|
|
40
|
-
options: { readonly signal: AbortSignal; readonly revision?: string },
|
|
40
|
+
options: { readonly signal: AbortSignal; readonly revision?: string; readonly session?: string },
|
|
41
41
|
): Promise<MountedEcad> {
|
|
42
|
-
const source = await loadArtifactSource(artifactPath,
|
|
42
|
+
const source = await loadArtifactSource(artifactPath, {
|
|
43
|
+
signal: options.signal,
|
|
44
|
+
...(options.revision === undefined ? {} : { expectedRevision: options.revision }),
|
|
45
|
+
...(options.session === undefined ? {} : { session: options.session }),
|
|
46
|
+
})
|
|
43
47
|
if (options.signal.aborted) throw aborted(options.signal)
|
|
44
48
|
if (source.kind !== undefined && source.kind !== kind) {
|
|
45
49
|
throw new Error(`host returned a ${source.kind} artifact for a ${kind} preview`)
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
// The renderer owns the backing resolution but not the CSS size, and it fits
|
|
53
|
+
// the view to the canvas during `load()`. Supplying our own already-sized
|
|
54
|
+
// canvas is therefore the only way the first fit matches the panel instead of
|
|
55
|
+
// the renderer's 300x150 default.
|
|
56
|
+
const canvas = document.createElement('canvas')
|
|
57
|
+
canvas.style.cssText = 'position:absolute;inset:0;display:block;width:100%;height:100%;outline:none'
|
|
58
|
+
container.append(canvas)
|
|
59
|
+
|
|
48
60
|
let rendered
|
|
49
61
|
if (kind === 'schematic') {
|
|
50
|
-
rendered = await renderSchematic(new SchematicParser().parse(source.text), { container, interactive: true })
|
|
62
|
+
rendered = await renderSchematic(new SchematicParser().parse(source.text), { canvas, container, interactive: true })
|
|
51
63
|
} else {
|
|
52
|
-
rendered = await renderPcb(new BoardParser().parse(source.text), { container, interactive: true })
|
|
64
|
+
rendered = await renderPcb(new BoardParser().parse(source.text), { canvas, container, interactive: true })
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
if (options.signal.aborted) {
|
|
56
68
|
rendered.dispose()
|
|
69
|
+
canvas.remove()
|
|
57
70
|
throw aborted(options.signal)
|
|
58
71
|
}
|
|
59
72
|
|
|
73
|
+
// The viewer fits once during `load()`, before React has finished laying the
|
|
74
|
+
// viewer tab out. Re-fit on the next painted frame so the first view matches
|
|
75
|
+
// the panel it is actually in rather than the pre-layout canvas. Only at
|
|
76
|
+
// mount: a later resize must not undo the user's own pan/zoom.
|
|
77
|
+
const viewer = rendered.viewer as { zoom_fit_top_item?: () => void }
|
|
78
|
+
if (typeof viewer.zoom_fit_top_item === 'function') {
|
|
79
|
+
await new Promise<void>((resolve) => {
|
|
80
|
+
requestAnimationFrame(() => { requestAnimationFrame(() => { resolve() }) })
|
|
81
|
+
})
|
|
82
|
+
if (!options.signal.aborted) viewer.zoom_fit_top_item()
|
|
83
|
+
}
|
|
84
|
+
|
|
60
85
|
return {
|
|
61
|
-
dispose: () => {
|
|
86
|
+
dispose: () => {
|
|
87
|
+
rendered.dispose()
|
|
88
|
+
canvas.remove()
|
|
89
|
+
},
|
|
62
90
|
sourceRevision: source.revision,
|
|
63
91
|
source,
|
|
64
92
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -5,11 +5,18 @@
|
|
|
5
5
|
* `keepMounted` right-panel tab body, and one settings section. Native open
|
|
6
6
|
* lives inside the viewer with the resolved artifact in scope, so no
|
|
7
7
|
* conversation-level action is registered.
|
|
8
|
+
*
|
|
9
|
+
* Two store handles, not one: DSH pins a handle to a single slot scope, and
|
|
10
|
+
* `conversation.header.leading`/`settings.section` are `root` while
|
|
11
|
+
* `sidebar.right.pane.tab` is `session`. Mounting one handle in both scopes is
|
|
12
|
+
* rejected at load time ("one handle, one scope"). The two halves therefore
|
|
13
|
+
* coordinate the only way the slot contract allows — through the tab
|
|
14
|
+
* parameters and their navigation revision.
|
|
8
15
|
*/
|
|
9
16
|
import { EngineeringNav, HardwareSettingsSection, HardwareViewerBody } from './components.js'
|
|
10
17
|
import type {
|
|
11
|
-
ConfigFormLike,
|
|
12
|
-
|
|
18
|
+
ConfigFormLike, HardwareController, HardwareDestination, HardwareInstallationConfig,
|
|
19
|
+
ViewerNavigationParams,
|
|
13
20
|
} from './model.js'
|
|
14
21
|
import { createHardwareStore } from './store.js'
|
|
15
22
|
import { loadInstallations, loadProjects, openArtifact } from './transport.js'
|
|
@@ -20,6 +27,8 @@ export const inject = ['slots', 'sidebarRight', 'sidebarRightTabs', 'configForms
|
|
|
20
27
|
export const HARDWARE_SETTINGS_ID = 'hardware-engineering'
|
|
21
28
|
export const HARDWARE_TAB_ID = '@huaqiu/dsh-hardware-ui'
|
|
22
29
|
export const HARDWARE_TAB_KIND = 'hardware-engineering'
|
|
30
|
+
/** Host plugin row id whose volatile config backs the product settings page. */
|
|
31
|
+
export const HARDWARE_CONFIG_ENTRY = 'hardware-artifacts'
|
|
23
32
|
|
|
24
33
|
interface SlotSpec {
|
|
25
34
|
name: string
|
|
@@ -73,84 +82,53 @@ function nativeKindFor(destination: HardwareDestination, path: string): string {
|
|
|
73
82
|
|
|
74
83
|
/** Install all product UI contributions on a DSH client context. */
|
|
75
84
|
export function apply(ctx: ClientContext): void {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
// Root scope: product chrome (navigation + settings) shares one instance.
|
|
86
|
+
const rootStore = createHardwareStore()
|
|
87
|
+
// Session scope: each viewer owns its own selection/discovery state.
|
|
88
|
+
const viewerStore = createHardwareStore()
|
|
89
|
+
let navigation = 0
|
|
79
90
|
const effect = (fn: () => (() => void) | void, label: string): void => {
|
|
80
91
|
if (ctx.effect !== undefined) ctx.effect(fn, label)
|
|
81
92
|
else fn()
|
|
82
93
|
}
|
|
83
94
|
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
&& typeof (candidate as HardwareActions).setActive === 'function') {
|
|
88
|
-
actions = candidate as HardwareActions
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return { hooks: injected }
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const injected: HardwareInjected = {
|
|
95
|
-
async refreshDiscovery(cwd, project) {
|
|
96
|
-
try {
|
|
97
|
-
const result = await loadProjects(cwd, project)
|
|
98
|
-
actions?.setDiscovery(result)
|
|
99
|
-
if (result.issue?.code === 'bad-manifest') actions?.setNotice(result.issue.message)
|
|
100
|
-
} catch (error) {
|
|
101
|
-
actions?.setNotice(`Artifact discovery failed: ${String(error)}`)
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
openDestination(destination: HardwareDestination, path) {
|
|
105
|
-
revision += 1
|
|
106
|
-
const kind = path === undefined ? undefined : kindForPath(path)
|
|
107
|
-
try {
|
|
108
|
-
ctx.sidebarRight?.openTab(HARDWARE_TAB_KIND, {
|
|
109
|
-
params: {
|
|
110
|
-
destination,
|
|
111
|
-
...(path === undefined ? {} : { path }),
|
|
112
|
-
...(kind === undefined ? {} : { kind }),
|
|
113
|
-
navigationRevision: revision,
|
|
114
|
-
},
|
|
115
|
-
revealIfOpened: true,
|
|
116
|
-
})
|
|
117
|
-
} catch (error) {
|
|
118
|
-
actions?.setNotice(`Open viewer failed: ${String(error)}`)
|
|
119
|
-
}
|
|
95
|
+
const controller: HardwareController = {
|
|
96
|
+
discover(cwd, project, session) {
|
|
97
|
+
return loadProjects(cwd, project, session)
|
|
120
98
|
},
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
actions?.setNotice('Select an artifact before opening it in KiCad.')
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
const destination = store.create().getSnapshot().activeDestination
|
|
127
|
-
try {
|
|
128
|
-
await openArtifact({
|
|
129
|
-
application: application ?? 'kicad',
|
|
130
|
-
artifactPath,
|
|
131
|
-
kind: nativeKindFor(destination, artifactPath),
|
|
132
|
-
})
|
|
133
|
-
} catch (error) {
|
|
134
|
-
actions?.setNotice(`Native launch failed: ${String(error)}`)
|
|
135
|
-
throw error
|
|
136
|
-
}
|
|
99
|
+
installations() {
|
|
100
|
+
return loadInstallations()
|
|
137
101
|
},
|
|
138
102
|
async saveInstallation(application, root) {
|
|
139
|
-
const form = ctx.configForms?.get<HardwareInstallationConfig>(
|
|
103
|
+
const form = ctx.configForms?.get<HardwareInstallationConfig>(HARDWARE_CONFIG_ENTRY)
|
|
140
104
|
if (form === undefined) throw new Error('host settings are unavailable')
|
|
141
105
|
const field = application === 'kicad' ? 'kicadRoot' : 'solidcraftRoot'
|
|
142
106
|
const accepted = await form.set(field, root)
|
|
143
107
|
if (!accepted) throw new Error(`the host rejected the ${field} setting`)
|
|
144
108
|
},
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
109
|
+
configForm() {
|
|
110
|
+
return ctx.configForms?.get<HardwareInstallationConfig>(HARDWARE_CONFIG_ENTRY)
|
|
111
|
+
},
|
|
112
|
+
openDestination(destination, path) {
|
|
113
|
+
navigation += 1
|
|
114
|
+
const kind = path === undefined ? undefined : kindForPath(path)
|
|
115
|
+
const params: ViewerNavigationParams = {
|
|
116
|
+
destination,
|
|
117
|
+
...(path === undefined ? {} : { path }),
|
|
118
|
+
...(kind === undefined ? {} : { kind }),
|
|
119
|
+
navigationRevision: navigation,
|
|
150
120
|
}
|
|
121
|
+
ctx.sidebarRight?.openTab(HARDWARE_TAB_KIND, {
|
|
122
|
+
params: params as unknown as Readonly<Record<string, unknown>>,
|
|
123
|
+
revealIfOpened: true,
|
|
124
|
+
})
|
|
151
125
|
},
|
|
152
|
-
|
|
153
|
-
|
|
126
|
+
async openNative(request) {
|
|
127
|
+
await openArtifact({
|
|
128
|
+
application: request.application,
|
|
129
|
+
artifactPath: request.artifactPath,
|
|
130
|
+
kind: request.kind,
|
|
131
|
+
})
|
|
154
132
|
},
|
|
155
133
|
}
|
|
156
134
|
|
|
@@ -166,15 +144,15 @@ export function apply(ctx: ClientContext): void {
|
|
|
166
144
|
|
|
167
145
|
effect(() => slots.inject('conversation.header.leading', () => slots.register({
|
|
168
146
|
name: 'conversation.header.leading',
|
|
169
|
-
store,
|
|
170
|
-
inject:
|
|
147
|
+
store: rootStore,
|
|
148
|
+
inject: () => controller,
|
|
171
149
|
}, EngineeringNav)), 'hardware-ui: five-destination navigation')
|
|
172
150
|
|
|
173
151
|
effect(() => slots.inject('sidebar.right.pane.tab', () => slots.register({
|
|
174
152
|
name: 'sidebar.right.pane.tab',
|
|
175
153
|
key: HARDWARE_TAB_ID,
|
|
176
|
-
store,
|
|
177
|
-
inject:
|
|
154
|
+
store: viewerStore,
|
|
155
|
+
inject: () => controller,
|
|
178
156
|
}, HardwareViewerBody)), 'hardware-ui: viewer body')
|
|
179
157
|
|
|
180
158
|
effect(() => slots.inject('settings.section', () => slots.register({
|
|
@@ -182,7 +160,7 @@ export function apply(ctx: ClientContext): void {
|
|
|
182
160
|
id: HARDWARE_SETTINGS_ID,
|
|
183
161
|
order: 85,
|
|
184
162
|
label: () => 'Hardware Engineering',
|
|
185
|
-
store,
|
|
186
|
-
inject:
|
|
163
|
+
store: rootStore,
|
|
164
|
+
inject: () => controller,
|
|
187
165
|
}, HardwareSettingsSection)), 'hardware-ui: CAD installation settings')
|
|
188
166
|
}
|
package/src/client/model.ts
CHANGED
|
@@ -56,6 +56,7 @@ export interface HardwareProjectInfo {
|
|
|
56
56
|
export interface InstallationsInfo {
|
|
57
57
|
readonly kicad?: {
|
|
58
58
|
readonly configured: boolean
|
|
59
|
+
readonly root?: string
|
|
59
60
|
readonly version?: string
|
|
60
61
|
readonly cli?: string
|
|
61
62
|
readonly pcbEditor?: string
|
|
@@ -64,6 +65,7 @@ export interface InstallationsInfo {
|
|
|
64
65
|
}
|
|
65
66
|
readonly solidcraft?: {
|
|
66
67
|
readonly configured: boolean
|
|
68
|
+
readonly root?: string
|
|
67
69
|
readonly executable?: string
|
|
68
70
|
readonly error?: string
|
|
69
71
|
}
|
|
@@ -93,9 +95,11 @@ export interface HardwareState {
|
|
|
93
95
|
export interface HardwareActions {
|
|
94
96
|
setActive(destination: HardwareDestination): void
|
|
95
97
|
setWorkspaceRoot(root: string): void
|
|
96
|
-
setDiscovery(discovery: DiscoveryInfo): void
|
|
98
|
+
setDiscovery(discovery: DiscoveryInfo, preserveSelection?: boolean): void
|
|
97
99
|
selectProject(path: string): void
|
|
98
100
|
selectArtifact(path: string, kind: 'schematic' | 'pcb'): void
|
|
101
|
+
/** Adopt one `sidebar.right.openTab` navigation into viewer state. */
|
|
102
|
+
applyNavigation(params: ViewerNavigationParams): void
|
|
99
103
|
setInstallations(installations: InstallationsInfo): void
|
|
100
104
|
setNotice(notice?: string): void
|
|
101
105
|
refresh(): void
|
|
@@ -110,6 +114,8 @@ export interface ConfigFormLike<T> {
|
|
|
110
114
|
export interface HardwareInstallationConfig {
|
|
111
115
|
readonly kicadRoot?: string
|
|
112
116
|
readonly solidcraftRoot?: string
|
|
117
|
+
/** Set once the first-run setup wizard has been completed or skipped. */
|
|
118
|
+
readonly onboardingComplete?: boolean
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
/** Parameters carried by one `sidebar.right.openTab` navigation. */
|
|
@@ -126,16 +132,35 @@ export interface ViewerNavigationParams {
|
|
|
126
132
|
readonly navigationRevision: number
|
|
127
133
|
}
|
|
128
134
|
|
|
129
|
-
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
/**
|
|
136
|
+
* The product's business face, delivered verbatim to every registered
|
|
137
|
+
* component.
|
|
138
|
+
*
|
|
139
|
+
* It deliberately has no `hooks` member: DSH rebinds a `hooks` compartment into
|
|
140
|
+
* `use<Name>` selector hooks over observables, so a plain function bundle there
|
|
141
|
+
* would arrive as a broken selector instead of the object the component reads.
|
|
142
|
+
* Each member is an ordinary function; state writes stay in the component's own
|
|
143
|
+
* `actions`, so no shared mutable action capture is needed.
|
|
144
|
+
*/
|
|
145
|
+
export interface HardwareController {
|
|
146
|
+
/**
|
|
147
|
+
* Host-side artifact discovery for one workspace root.
|
|
148
|
+
*
|
|
149
|
+
* `session` scopes the result: the host remembers discovery per session, so
|
|
150
|
+
* two viewers in different workspaces never overwrite each other's roots.
|
|
151
|
+
*/
|
|
152
|
+
discover(cwd?: string, project?: string, session?: string): Promise<DiscoveryInfo>
|
|
153
|
+
/** Host-side installation validation. */
|
|
154
|
+
installations(): Promise<InstallationsInfo>
|
|
134
155
|
saveInstallation(application: 'kicad' | 'solidcraft', root: string): Promise<void>
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
156
|
+
/** The host-backed configuration form, when the settings service is mounted. */
|
|
157
|
+
configForm(): ConfigFormLike<HardwareInstallationConfig> | undefined
|
|
158
|
+
/** Open or retarget the product viewer tab. */
|
|
159
|
+
openDestination(destination: HardwareDestination, path?: string): void
|
|
160
|
+
/** Launch the exact artifact in its configured native application. */
|
|
161
|
+
openNative(request: {
|
|
162
|
+
application: NativeApplication
|
|
163
|
+
artifactPath: string
|
|
164
|
+
kind: string
|
|
165
|
+
}): Promise<void>
|
|
141
166
|
}
|