@huaqiu/dsh-hardware-ui 0.7.18 → 0.7.19
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 +9583 -627
- package/lib/client.js.map +1 -1
- package/lib/index.d.mts +35 -14
- package/lib/index.mjs +118 -10
- package/package.json +7 -3
- package/src/client/brand.ts +17 -0
- package/src/client/components.tsx +26 -133
- package/src/client/copy.ts +372 -243
- package/src/client/document/EcadBody.tsx +212 -0
- package/src/client/document/StepBody.tsx +124 -0
- package/src/client/document/contract.ts +156 -0
- package/src/client/document/copy.ts +49 -0
- package/src/client/document/index.ts +134 -0
- package/src/client/document/mount.ts +261 -0
- package/src/client/document/occt.d.ts +54 -0
- package/src/client/document/paths.ts +122 -0
- package/src/client/document/sheets.ts +83 -0
- package/src/client/document/step.ts +255 -0
- package/src/client/index.ts +172 -4
- package/src/client/locales.ts +604 -0
- package/src/client/model.ts +18 -9
- package/src/client/order-page.ts +44 -0
- package/src/client/order-tab.tsx +117 -0
- package/src/client/order-watcher.ts +121 -0
- package/src/client/order.tsx +9 -9
- package/src/client/toolchain-view.tsx +724 -0
- package/src/client/toolchain.ts +620 -0
- package/src/client/transport.ts +83 -4
- package/src/client/wizard.tsx +312 -261
- package/src/index.ts +126 -10
- package/src/shared/occt-asset.ts +21 -0
package/lib/index.d.mts
CHANGED
|
@@ -1,24 +1,45 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
1
2
|
//#region src/index.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Node half of `@huaqiu/dsh-hardware-ui`.
|
|
4
|
-
*
|
|
5
|
-
* All product UI is browser-side. This entry exists so the package is a normal
|
|
6
|
-
* installable plugin in the DSH bundle; it intentionally provides no service
|
|
7
|
-
* and injects nothing. Host operations live in `@huaqiu/hardware-artifacts`.
|
|
8
|
-
*/
|
|
9
3
|
declare const name = "@huaqiu/dsh-hardware-ui";
|
|
10
|
-
/** Browser-only plugin: the node Loader seat intentionally does nothing. */
|
|
11
|
-
declare function apply(): void;
|
|
12
4
|
/** The tab kind owned by this product UI. */
|
|
13
5
|
declare const HARDWARE_TAB_KIND = "hardware-engineering";
|
|
14
6
|
/**
|
|
15
|
-
* Slots this product UI occupies
|
|
7
|
+
* Slots this product UI occupies, plus the DSH seats it depends on.
|
|
16
8
|
*
|
|
17
9
|
* `conversation.session.header.corner` is DSH's own expand button (we occupy
|
|
18
|
-
* nothing there); it is listed because the product depends on it. The
|
|
19
|
-
*
|
|
20
|
-
*
|
|
10
|
+
* nothing there); it is listed because the product depends on it. The document
|
|
11
|
+
* seats are contributed by the browser half through DSH's document-preview
|
|
12
|
+
* registry, not by taking over the MDI.
|
|
13
|
+
*/
|
|
14
|
+
declare const HARDWARE_UI_SLOTS: readonly ["conversation.session.header.corner", "sidebar.right.pane.tab", "sidebar.right.tab.document", "settings.section", "settings.onboarding", "shell.overlay", "sidebar.footer.action"];
|
|
15
|
+
/** Structural view of the Host route seat; declared locally to keep this half dependency-free. */
|
|
16
|
+
interface RouteSeat {
|
|
17
|
+
register(route: {
|
|
18
|
+
kind: 'exact' | 'prefix';
|
|
19
|
+
path: string;
|
|
20
|
+
handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
|
|
21
|
+
}): () => void;
|
|
22
|
+
}
|
|
23
|
+
interface HostLike {
|
|
24
|
+
effect?(fn: () => (() => void) | void, label?: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Cordis's nested injection. `webServer` is a *dependency*, not a precondition:
|
|
27
|
+
* reading `ctx.webServer` directly would make the whole product UI absent on a
|
|
28
|
+
* Host without an HTTP server, so it is acquired here and the rest of the
|
|
29
|
+
* plugin never learns whether it exists.
|
|
30
|
+
*/
|
|
31
|
+
inject?(dependencies: readonly string[], callback: (scope: HostLike & {
|
|
32
|
+
readonly webServer: RouteSeat;
|
|
33
|
+
}) => void): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Node half entry.
|
|
37
|
+
*
|
|
38
|
+
* Registers the reader route when the Host serves HTTP; on a Host without one
|
|
39
|
+
* (Electron file:// + IPC) this intentionally does nothing and the STEP body
|
|
40
|
+
* reports the reader as unavailable.
|
|
41
|
+
* @param ctx - Host context; the web server is acquired through nested injection.
|
|
21
42
|
*/
|
|
22
|
-
declare
|
|
43
|
+
declare function apply(ctx: HostLike): void;
|
|
23
44
|
//#endregion
|
|
24
45
|
export { HARDWARE_TAB_KIND, HARDWARE_UI_SLOTS, apply, name };
|
package/lib/index.mjs
CHANGED
|
@@ -1,28 +1,136 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/shared/occt-asset.ts
|
|
5
|
+
/**
|
|
6
|
+
* Route and file name of the packaged STEP reader, shared by both halves.
|
|
7
|
+
*
|
|
8
|
+
* The browser half must fetch the `.wasm` from a same-origin URL and the Node
|
|
9
|
+
* half is the only side that can read the installed package's `dist` directory,
|
|
10
|
+
* so the two must agree on exactly one string. Sharing it here is cheaper than
|
|
11
|
+
* a protocol and impossible to drift: a change breaks both bundles or neither.
|
|
12
|
+
*
|
|
13
|
+
* Why a plugin route rather than a CDN or an inline base64 blob: the ordering
|
|
14
|
+
* spec requires the preview to work with no network access (§7.4, §12.3), and
|
|
15
|
+
* base64-inlining 7.6 MB into the client bundle would parse on every DSH start
|
|
16
|
+
* whether or not a STEP document is ever opened.
|
|
17
|
+
*
|
|
18
|
+
* @module @huaqiu/dsh-hardware-ui/shared/occt-asset
|
|
19
|
+
*/
|
|
20
|
+
/** Absolute route the Host serves the reader wasm from; also the browser's fetch URL. */
|
|
21
|
+
const OCCT_WASM_ROUTE = "/hardware-ui/assets/occt-import-js.wasm";
|
|
22
|
+
/** File name inside the installed `occt-import-js` package. */
|
|
23
|
+
const OCCT_WASM_FILE = "occt-import-js.wasm";
|
|
24
|
+
//#endregion
|
|
1
25
|
//#region src/index.ts
|
|
2
26
|
/**
|
|
3
27
|
* Node half of `@huaqiu/dsh-hardware-ui`.
|
|
4
28
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
29
|
+
* It does exactly one thing: serve the packaged STEP reader's WebAssembly
|
|
30
|
+
* module to the browser half, from this plugin's own files, over the Host's
|
|
31
|
+
* existing HTTP server. Everything else this product does is browser-side.
|
|
32
|
+
*
|
|
33
|
+
* Why this route exists at all. The client bundle is a single classic script
|
|
34
|
+
* loaded by DSH's module loader; it has no `import.meta.url` and no asset route
|
|
35
|
+
* of its own, so a 7.6 MB `.wasm` beside it has no URL the renderer can fetch.
|
|
36
|
+
* The alternatives were worse: base64-inlining the module into `client.js` would
|
|
37
|
+
* make every DSH start parse 10 MB of text whether or not a STEP file is ever
|
|
38
|
+
* opened, and fetching from a CDN is forbidden outright — the preview must work
|
|
39
|
+
* with no network (`docs/tasks/…full-impl-code-spec.md` §7.4, §12.3).
|
|
40
|
+
*
|
|
41
|
+
* The served bytes are a build artefact of a declared dependency, not workspace
|
|
42
|
+
* content: the request carries no path parameter, the file is resolved once at
|
|
43
|
+
* load through Node's own module resolution, and the response is immutable. No
|
|
44
|
+
* user-controlled string ever reaches a filesystem call here, which is why this
|
|
45
|
+
* is not the "second filesystem server" the spec rules out.
|
|
46
|
+
*
|
|
47
|
+
* When the Host has no HTTP server (Electron file:// + IPC), nothing is
|
|
48
|
+
* registered and the STEP body reports the reader as unavailable in-document —
|
|
49
|
+
* a degraded viewer, never a broken app.
|
|
50
|
+
*
|
|
51
|
+
* @module @huaqiu/dsh-hardware-ui
|
|
8
52
|
*/
|
|
9
53
|
const name = "@huaqiu/dsh-hardware-ui";
|
|
10
|
-
/** Browser-only plugin: the node Loader seat intentionally does nothing. */
|
|
11
|
-
function apply() {}
|
|
12
54
|
/** The tab kind owned by this product UI. */
|
|
13
55
|
const HARDWARE_TAB_KIND = "hardware-engineering";
|
|
14
56
|
/**
|
|
15
|
-
* Slots this product UI occupies
|
|
57
|
+
* Slots this product UI occupies, plus the DSH seats it depends on.
|
|
16
58
|
*
|
|
17
59
|
* `conversation.session.header.corner` is DSH's own expand button (we occupy
|
|
18
|
-
* nothing there); it is listed because the product depends on it. The
|
|
19
|
-
*
|
|
20
|
-
*
|
|
60
|
+
* nothing there); it is listed because the product depends on it. The document
|
|
61
|
+
* seats are contributed by the browser half through DSH's document-preview
|
|
62
|
+
* registry, not by taking over the MDI.
|
|
21
63
|
*/
|
|
22
64
|
const HARDWARE_UI_SLOTS = Object.freeze([
|
|
23
65
|
"conversation.session.header.corner",
|
|
24
66
|
"sidebar.right.pane.tab",
|
|
25
|
-
"
|
|
67
|
+
"sidebar.right.tab.document",
|
|
68
|
+
"settings.section",
|
|
69
|
+
"settings.onboarding",
|
|
70
|
+
"shell.overlay",
|
|
71
|
+
"sidebar.footer.action"
|
|
26
72
|
]);
|
|
73
|
+
/** Resolved absolute path of the packaged reader, or undefined when the dependency is missing. */
|
|
74
|
+
function wasmFile() {
|
|
75
|
+
try {
|
|
76
|
+
const require = createRequire(import.meta.url);
|
|
77
|
+
return path.join(path.dirname(require.resolve("occt-import-js/package.json")), "dist", OCCT_WASM_FILE);
|
|
78
|
+
} catch {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Bytes are read once per process: the file cannot change while the app runs. */
|
|
83
|
+
let cached;
|
|
84
|
+
function wasmBytes() {
|
|
85
|
+
if (cached !== void 0) return cached;
|
|
86
|
+
const file = wasmFile();
|
|
87
|
+
if (file === void 0) return void 0;
|
|
88
|
+
try {
|
|
89
|
+
cached = readFileSync(file);
|
|
90
|
+
return cached;
|
|
91
|
+
} catch {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Node half entry.
|
|
97
|
+
*
|
|
98
|
+
* Registers the reader route when the Host serves HTTP; on a Host without one
|
|
99
|
+
* (Electron file:// + IPC) this intentionally does nothing and the STEP body
|
|
100
|
+
* reports the reader as unavailable.
|
|
101
|
+
* @param ctx - Host context; the web server is acquired through nested injection.
|
|
102
|
+
*/
|
|
103
|
+
function apply(ctx) {
|
|
104
|
+
if (ctx.inject === void 0) return;
|
|
105
|
+
ctx.inject(["webServer"], (scope) => {
|
|
106
|
+
const server = scope.webServer;
|
|
107
|
+
const install = () => server.register({
|
|
108
|
+
kind: "exact",
|
|
109
|
+
path: OCCT_WASM_ROUTE,
|
|
110
|
+
handler: (req, res) => {
|
|
111
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
112
|
+
res.writeHead(405, { allow: "GET, HEAD" });
|
|
113
|
+
res.end();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const bytes = wasmBytes();
|
|
117
|
+
if (bytes === void 0) {
|
|
118
|
+
res.writeHead(404, { "content-type": "text/plain; charset=utf-8" });
|
|
119
|
+
res.end("occt-import-js.wasm is not installed");
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
res.writeHead(200, {
|
|
123
|
+
"content-type": "application/wasm",
|
|
124
|
+
"content-length": String(bytes.byteLength),
|
|
125
|
+
"cache-control": "private, max-age=86400"
|
|
126
|
+
});
|
|
127
|
+
if (req.method === "HEAD") res.end();
|
|
128
|
+
else res.end(bytes);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
if (scope.effect !== void 0) scope.effect(install, "hardware-ui: STEP reader asset");
|
|
132
|
+
else install();
|
|
133
|
+
});
|
|
134
|
+
}
|
|
27
135
|
//#endregion
|
|
28
136
|
export { HARDWARE_TAB_KIND, HARDWARE_UI_SLOTS, apply, name };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaqiu/dsh-hardware-ui",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Hardware Engineering product UI for DSH: five-destination engineering navigation, right-panel artifact viewer, CAD installation settings and contextual native-application actions.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"client": {
|
|
25
25
|
"platform": "web",
|
|
26
26
|
"inject": [
|
|
27
|
+
"@deepseek-ai/dsh-client-locale",
|
|
27
28
|
"@deepseek-ai/dsh-client-ui-slots"
|
|
28
29
|
]
|
|
29
30
|
}
|
|
@@ -36,14 +37,14 @@
|
|
|
36
37
|
"react": "^18"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
40
|
+
"@deepseek-ai/cordis": "^4.0.2",
|
|
39
41
|
"@huaqiu/ecad-renderer": "0.2.6",
|
|
40
42
|
"@huaqiu/kicad-sexpr-parser": "0.1.3",
|
|
41
|
-
"three": "^0.185.1",
|
|
42
|
-
"@deepseek-ai/cordis": "^4.0.2",
|
|
43
43
|
"@types/react": "~18.3.1",
|
|
44
44
|
"@types/three": "^0.185.4",
|
|
45
45
|
"react": "^18.3.1",
|
|
46
46
|
"react-dom": "^18.3.1",
|
|
47
|
+
"three": "^0.185.1",
|
|
47
48
|
"tsdown": "^0.22.14",
|
|
48
49
|
"typescript": "^5.9.0",
|
|
49
50
|
"vitest": "^4.1.0"
|
|
@@ -57,6 +58,9 @@
|
|
|
57
58
|
"publishConfig": {
|
|
58
59
|
"access": "public"
|
|
59
60
|
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"occt-import-js": "0.0.23"
|
|
63
|
+
},
|
|
60
64
|
"scripts": {
|
|
61
65
|
"typecheck": "tsc --noEmit",
|
|
62
66
|
"build": "tsdown",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HuaQiu brand mark, byte-for-byte `assets/huaqiu.svg` (repo root).
|
|
3
|
+
*
|
|
4
|
+
* The client bundle cannot fetch repository assets or add runtime dependencies
|
|
5
|
+
* (its `inject` list is fixed and `@deepseek-ai/*` is never bundled), so the file
|
|
6
|
+
* travels as a base64 data URI: one string constant, no build-side asset pipeline,
|
|
7
|
+
* and the rendered mark is the vendor file itself rather than a redrawn lookalike.
|
|
8
|
+
*
|
|
9
|
+
* `test/brand.test.ts` decodes this back to text and compares it with the asset on
|
|
10
|
+
* disk, so a re-exported logo that is not re-encoded here fails the suite instead of
|
|
11
|
+
* silently drifting.
|
|
12
|
+
*/
|
|
13
|
+
export const HUAQIU_LOGO_SVG_BASE64 =
|
|
14
|
+
'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI1LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IuWbvuWxgl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIKCSB2aWV3Qm94PSIwIDAgNTAgNTAiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDUwIDUwOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+CjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+Cgkuc3Qwe2ZpbGw6I0NDMDAwMDt9Cjwvc3R5bGU+CjxnPgoJPHBhdGggY2xhc3M9InN0MCIgZD0iTTM4LjMsMEgxMS45QzUuNSwwLDAuMSw1LjMsMC4xLDExLjh2MjYuM0MwLjEsNDQuNiw1LjQsNTAsMTEuOSw1MGgyNi4zYzAuMSwwLDAuMywwLDAuNiwwCgkJYy0xLjUtMS41LTIuMi0zLjMtMi4yLTUuNWMwLTAuNiwwLTEuMiwwLjEtMS43SDEyLjFjLTIuNSwwLTQuNC0yLTQuNC00LjRWMTEuOGMwLTIuNSwyLTQuNCw0LjQtNC40aDI2LjNjMi41LDAsNC40LDIsNC40LDQuNHYyNC43CgkJYzAuNi0wLjEsMS4yLTAuMSwxLjctMC4xYzIuMiwwLDQuMSwwLjksNS41LDIuMmMwLTAuMSwwLTAuMywwLTAuNFYxMS44QzUwLDUuMyw0NC44LDAsMzguMywweiIvPgoJPHBhdGggY2xhc3M9InN0MCIgZD0iTTQ0LjUsMzguOWMtMy4xLDAtNS41LDIuNS01LjUsNS41czIuNSw1LjUsNS41LDUuNWMzLjEsMCw1LjUtMi41LDUuNS01LjVDNDkuOSw0MS4yLDQ3LjYsMzguOSw0NC41LDM4Ljl6Ii8+Cgk8cG9seWdvbiBjbGFzcz0ic3QwIiBwb2ludHM9IjM3LjgsMzcuNyAzNy44LDEyLjMgMzAuNSwxMi4zIDMwLjUsMjEuMyAxOS44LDIxLjMgMTkuOCwxMi4zIDEyLjMsMTIuMyAxMi4zLDM3LjcgMTkuOCwzNy43IAoJCTE5LjgsMjguNiAzMC41LDI4LjYgMzAuNSwzNy43IAkiLz4KPC9nPgo8L3N2Zz4K'
|
|
15
|
+
|
|
16
|
+
/** The mark as an `<img src>`; carries its own viewBox, so it scales to any size. */
|
|
17
|
+
export const HUAQIU_LOGO_SRC = `data:image/svg+xml;base64,${HUAQIU_LOGO_SVG_BASE64}`
|
|
@@ -21,7 +21,8 @@ import {
|
|
|
21
21
|
type ViewerNavigationParams,
|
|
22
22
|
} from './model.js'
|
|
23
23
|
import { HardwarePreview } from './preview.js'
|
|
24
|
-
import {
|
|
24
|
+
import { ToolchainCard, useToolchain } from './toolchain-view.js'
|
|
25
|
+
import type { ToolchainController } from './toolchain.js'
|
|
25
26
|
import { COPY, issueText } from './copy.js'
|
|
26
27
|
import { messageOf } from './transport.js'
|
|
27
28
|
import {
|
|
@@ -58,7 +59,16 @@ export interface SlotProps {
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/** Full component props: slot props plus the controller's verbatim members. */
|
|
61
|
-
export type HardwareProps = SlotProps & HardwareController
|
|
62
|
+
export type HardwareProps = SlotProps & HardwareController & {
|
|
63
|
+
/**
|
|
64
|
+
* The shared toolchain controller (§10.5).
|
|
65
|
+
*
|
|
66
|
+
* Delivered to every seat rather than created per surface: the wizard step,
|
|
67
|
+
* the Settings section, the notice overlay and the sidebar dot all read this
|
|
68
|
+
* one object, so none of them can hold a second, divergent idea of "configured".
|
|
69
|
+
*/
|
|
70
|
+
readonly toolchain: ToolchainController
|
|
71
|
+
}
|
|
62
72
|
|
|
63
73
|
const EMPTY_TAB: TabInfo = { tab: { id: '', navigation: {} } }
|
|
64
74
|
const useEmptyTab = (): TabInfo => EMPTY_TAB
|
|
@@ -434,144 +444,27 @@ export function HardwareViewerBody(props: HardwareProps): ReactNode {
|
|
|
434
444
|
style: { ...MUTED, color: C.text2, fontSize: 10.5, lineHeight: 1.6, textAlign: 'center', maxWidth: 360 },
|
|
435
445
|
}, missing.guidance)]))]),
|
|
436
446
|
),
|
|
437
|
-
// The first-run wizard rides the panel rather than the conversation header:
|
|
438
|
-
// this page is the product, and it is what the expand button opens.
|
|
439
|
-
createElement(OnboardingWizard, props),
|
|
440
447
|
)
|
|
441
448
|
}
|
|
442
449
|
|
|
443
|
-
/** Settings section: the two
|
|
450
|
+
/** Settings section: the two toolchain cards, read from the shared controller. */
|
|
444
451
|
export function HardwareSettingsSection(props: HardwareProps): ReactNode {
|
|
445
|
-
const {
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
const snapshot = useSyncExternalStore<{ value?: HardwareInstallationConfig }>(
|
|
450
|
-
form === undefined ? () => () => {} : listener => form.subscribe(listener),
|
|
451
|
-
form === undefined ? () => empty : () => form.getSnapshot(),
|
|
452
|
-
form === undefined ? () => empty : () => form.getSnapshot(),
|
|
453
|
-
)
|
|
454
|
-
const [kicadRoot, setKicadRoot] = useState(snapshot.value?.kicadRoot ?? '')
|
|
455
|
-
const [solidcraftRoot, setSolidcraftRoot] = useState(snapshot.value?.solidcraftRoot ?? '')
|
|
456
|
-
const [message, setMessage] = useState('')
|
|
457
|
-
const [busy, setBusy] = useState<'kicad' | 'solidcraft' | undefined>()
|
|
458
|
-
|
|
459
|
-
useEffect(() => { setKicadRoot(snapshot.value?.kicadRoot ?? '') }, [snapshot.value?.kicadRoot])
|
|
460
|
-
useEffect(() => { setSolidcraftRoot(snapshot.value?.solidcraftRoot ?? '') }, [snapshot.value?.solidcraftRoot])
|
|
461
|
-
|
|
462
|
-
useEffect(() => {
|
|
463
|
-
let live = true
|
|
464
|
-
installations()
|
|
465
|
-
.then((result) => { if (live) actions.setInstallations(result) })
|
|
466
|
-
.catch(() => { /* the wizard and viewer surface the same failure */ })
|
|
467
|
-
return () => { live = false }
|
|
468
|
-
}, [actions, installations])
|
|
469
|
-
|
|
470
|
-
const save = async (application: 'kicad' | 'solidcraft', root: string): Promise<void> => {
|
|
471
|
-
setBusy(application)
|
|
472
|
-
try {
|
|
473
|
-
await saveInstallation(application, root)
|
|
474
|
-
const refreshed = await installations()
|
|
475
|
-
actions.setInstallations(refreshed)
|
|
476
|
-
const state = application === 'kicad' ? refreshed.kicad : refreshed.solidcraft
|
|
477
|
-
const applicationName = application === 'kicad' ? 'KiCad' : 'SolidCraft'
|
|
478
|
-
setMessage(state?.configured === true
|
|
479
|
-
? COPY.settings.savedAndValidated(applicationName)
|
|
480
|
-
: COPY.settings.savedButInvalid(applicationName, state?.error ?? COPY.settings.notDetected))
|
|
481
|
-
} catch (error) {
|
|
482
|
-
setMessage(messageOf(error))
|
|
483
|
-
} finally {
|
|
484
|
-
setBusy(undefined)
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
const kicad = installed?.kicad
|
|
489
|
-
const solidcraft = installed?.solidcraft
|
|
490
|
-
|
|
491
|
-
const installationCard = (input: {
|
|
492
|
-
key: 'kicad' | 'solidcraft'
|
|
493
|
-
letter: string
|
|
494
|
-
color: string
|
|
495
|
-
title: string
|
|
496
|
-
blurb: string
|
|
497
|
-
value: string
|
|
498
|
-
placeholder: string
|
|
499
|
-
ok: boolean
|
|
500
|
-
status: string
|
|
501
|
-
detail?: string
|
|
502
|
-
onChange: (value: string) => void
|
|
503
|
-
}): ReactNode => createElement(
|
|
452
|
+
const { toolchain } = props
|
|
453
|
+
const snapshot = useToolchain(toolchain)
|
|
454
|
+
useEffect(() => { toolchain.start() }, [toolchain])
|
|
455
|
+
return createElement(
|
|
504
456
|
'div',
|
|
505
|
-
{
|
|
506
|
-
createElement(
|
|
507
|
-
'div',
|
|
508
|
-
{ style: { ...ROW, justifyContent: 'space-between', gap: 8 } },
|
|
509
|
-
createElement(
|
|
510
|
-
'div',
|
|
511
|
-
{ style: { ...ROW, gap: 7 } },
|
|
512
|
-
createElement('span', {
|
|
513
|
-
style: {
|
|
514
|
-
width: 22, height: 22, borderRadius: R.sm, display: 'flex', alignItems: 'center',
|
|
515
|
-
justifyContent: 'center', fontSize: 10, fontWeight: 700, fontFamily: MONO,
|
|
516
|
-
color: input.color, background: `color-mix(in srgb, ${input.color} 18%, transparent)`,
|
|
517
|
-
border: `1px solid color-mix(in srgb, ${input.color} 40%, transparent)`,
|
|
518
|
-
},
|
|
519
|
-
}, input.letter),
|
|
520
|
-
createElement('span', { style: { fontSize: 12, fontWeight: 600 } }, input.title),
|
|
521
|
-
),
|
|
522
|
-
createElement('span', { style: pillStyle(input.ok ? 'ok' : 'warn') }, input.status),
|
|
523
|
-
),
|
|
524
|
-
createElement('p', { style: MUTED }, input.blurb),
|
|
525
|
-
createElement('input', {
|
|
526
|
-
style: INPUT, value: input.value, placeholder: input.placeholder, spellCheck: false,
|
|
527
|
-
'aria-label': COPY.settings.pathField(input.title),
|
|
528
|
-
onChange: (event: ChangeEvent<HTMLInputElement>) => input.onChange(event.currentTarget.value),
|
|
529
|
-
}),
|
|
457
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 14 }, 'data-hardware-settings': true },
|
|
530
458
|
createElement(
|
|
531
459
|
'div',
|
|
532
|
-
{ style: {
|
|
533
|
-
createElement('
|
|
534
|
-
|
|
535
|
-
disabled: busy !== undefined,
|
|
536
|
-
onClick: () => { void save(input.key, input.value) },
|
|
537
|
-
}, busy === input.key ? COPY.settings.validating : COPY.settings.validate),
|
|
538
|
-
input.detail === undefined
|
|
539
|
-
? null
|
|
540
|
-
: createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10, maxWidth: 240, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, input.detail),
|
|
460
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
461
|
+
createElement('h3', { style: { margin: 0, fontSize: 14, fontWeight: 600, color: C.text } }, COPY.settings.title),
|
|
462
|
+
createElement('p', { style: { ...MUTED, margin: 0, lineHeight: 1.6 } }, COPY.settings.lead),
|
|
541
463
|
),
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
createElement('h2', { style: { margin: 0, fontSize: 15, fontWeight: 600 } }, COPY.settings.title),
|
|
548
|
-
createElement('p', { style: MUTED }, COPY.settings.lead),
|
|
549
|
-
installationCard({
|
|
550
|
-
key: 'kicad',
|
|
551
|
-
letter: 'Ki',
|
|
552
|
-
color: C.info,
|
|
553
|
-
title: COPY.settings.kicadTitle,
|
|
554
|
-
blurb: COPY.settings.kicadBlurb,
|
|
555
|
-
value: kicadRoot,
|
|
556
|
-
placeholder: COPY.settings.kicadPlaceholder,
|
|
557
|
-
ok: kicad?.configured === true,
|
|
558
|
-
status: kicad?.configured ? `v${kicad.version ?? '?'}` : COPY.settings.notConfigured,
|
|
559
|
-
...(kicad?.cli === undefined ? {} : { detail: kicad.cli }),
|
|
560
|
-
onChange: setKicadRoot,
|
|
561
|
-
}),
|
|
562
|
-
installationCard({
|
|
563
|
-
key: 'solidcraft',
|
|
564
|
-
letter: 'Sc',
|
|
565
|
-
color: C.warn,
|
|
566
|
-
title: COPY.settings.solidcraftTitle,
|
|
567
|
-
blurb: COPY.settings.solidcraftBlurb,
|
|
568
|
-
value: solidcraftRoot,
|
|
569
|
-
placeholder: COPY.settings.solidcraftPlaceholder,
|
|
570
|
-
ok: solidcraft?.configured === true,
|
|
571
|
-
status: solidcraft?.configured ? COPY.settings.configured : COPY.settings.notConfigured,
|
|
572
|
-
...(solidcraft?.executable === undefined ? {} : { detail: solidcraft.executable }),
|
|
573
|
-
onChange: setSolidcraftRoot,
|
|
574
|
-
}),
|
|
575
|
-
...(message === '' ? [] : [createElement('p', { role: 'status', style: { ...MUTED, color: C.text2 } }, message)]),
|
|
464
|
+
createElement(ToolchainCard, { tool: 'kicad', controller: toolchain, snapshot, variant: 'settings' }),
|
|
465
|
+
createElement(ToolchainCard, { tool: 'solidcraft', controller: toolchain, snapshot, variant: 'settings' }),
|
|
466
|
+
...(snapshot.error === undefined ? [] : [
|
|
467
|
+
createElement('p', { key: 'error', role: 'status', style: { ...MUTED, color: C.accent } }, snapshot.error),
|
|
468
|
+
]),
|
|
576
469
|
)
|
|
577
470
|
}
|