@huaqiu/component-gen-app 0.4.6 → 0.4.7
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/dist/assets/{index-mWkf87i_.js → index-t51t_a62.js} +4 -4
- package/dist/index.html +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +31 -2
- package/package.json +1 -1
- package/src/pages/FootprintGenPage.tsx +5 -1
- package/src/pages/SymbolGenPage.tsx +16 -0
- package/src/ports.ts +1 -0
- package/src/utils/symbol-pins.ts +12 -0
package/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>华秋 Component Gen</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index-
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-t51t_a62.js"></script>
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
|
10
10
|
<div id="root"></div>
|
package/lib/index.d.ts
CHANGED
|
@@ -150,6 +150,7 @@ interface ComponentGenPlacePort {
|
|
|
150
150
|
}
|
|
151
151
|
/** The whole contract the app needs from its host. */
|
|
152
152
|
interface ComponentGenPorts {
|
|
153
|
+
track?(event: string, properties?: Record<string, unknown>): void;
|
|
153
154
|
config(): Promise<ComponentGenConfig>;
|
|
154
155
|
startJob(req: StartJobRequest, signal?: AbortSignal): Promise<JobState>;
|
|
155
156
|
jobEvents(jobId: string, onEvent: (e: JobEvent) => void): () => void;
|
package/lib/index.js
CHANGED
|
@@ -936,6 +936,18 @@ function useJobRunner(ports) {
|
|
|
936
936
|
};
|
|
937
937
|
}
|
|
938
938
|
//#endregion
|
|
939
|
+
//#region src/utils/symbol-pins.ts
|
|
940
|
+
function symbolPinCount(source) {
|
|
941
|
+
const symbols = new SchematicParser().parseLibSymbols(source);
|
|
942
|
+
const numbers = /* @__PURE__ */ new Set();
|
|
943
|
+
const collect = (symbol) => {
|
|
944
|
+
for (const pin of symbol.pins ?? []) numbers.add(pin.number.text);
|
|
945
|
+
for (const child of symbol.children ?? []) collect(child);
|
|
946
|
+
};
|
|
947
|
+
for (const symbol of symbols) collect(symbol);
|
|
948
|
+
return numbers.size;
|
|
949
|
+
}
|
|
950
|
+
//#endregion
|
|
939
951
|
//#region src/pages/SymbolGenPage.tsx
|
|
940
952
|
/**
|
|
941
953
|
* `@huaqiu/component-gen-app` — Symbol generation page.
|
|
@@ -965,6 +977,22 @@ function SymbolGenPage({ ports, t, reopen = null }) {
|
|
|
965
977
|
useEffect(() => {
|
|
966
978
|
ports.config().then(setConfig).catch(() => {});
|
|
967
979
|
}, [ports]);
|
|
980
|
+
useEffect(() => {
|
|
981
|
+
if (runner.phase === "failed") ports.track?.("generate_symbol", {
|
|
982
|
+
success: false,
|
|
983
|
+
err_msg: runner.error
|
|
984
|
+
});
|
|
985
|
+
if (runner.phase === "completed" && !runner.jobId?.startsWith("history:")) {
|
|
986
|
+
const artifact = runner.result.artifact;
|
|
987
|
+
if (typeof artifact?.id === "string") ports.artifactContent(artifact.id).then((source) => {
|
|
988
|
+
ports.track?.("generate_symbol", {
|
|
989
|
+
success: true,
|
|
990
|
+
err_msg: "",
|
|
991
|
+
pin_count: symbolPinCount(source)
|
|
992
|
+
});
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
}, [runner.phase]);
|
|
968
996
|
const maxBytes = config?.limits.imageBytes ?? 4194304;
|
|
969
997
|
const authed = auth.phase === "authenticated";
|
|
970
998
|
const canGenerate = authed && !!imageDataUrl && runner.phase !== "running";
|
|
@@ -1935,11 +1963,12 @@ function FootprintGenPage({ ports, t, reopen = null }) {
|
|
|
1935
1963
|
imageDataUrl,
|
|
1936
1964
|
...hint.trim() ? { packageType: hint.trim() } : {}
|
|
1937
1965
|
}
|
|
1938
|
-
});
|
|
1966
|
+
}).then(() => ports.track?.("generate_footprint", { err_msg: "" })).catch((err) => ports.track?.("generate_footprint", { err_msg: String(err?.message || err) }));
|
|
1939
1967
|
}, [
|
|
1940
1968
|
imageDataUrl,
|
|
1941
1969
|
hint,
|
|
1942
|
-
runner
|
|
1970
|
+
runner,
|
|
1971
|
+
ports
|
|
1943
1972
|
]);
|
|
1944
1973
|
const confirmDimensions = useCallback((values, edited) => {
|
|
1945
1974
|
runner.run({
|
package/package.json
CHANGED
|
@@ -69,7 +69,11 @@ export function FootprintGenPage({ ports, t, reopen = null }: FootprintGenPagePr
|
|
|
69
69
|
...(hint.trim() ? { packageType: hint.trim() } : {}),
|
|
70
70
|
},
|
|
71
71
|
})
|
|
72
|
-
|
|
72
|
+
.then(() => ports.track?.('generate_footprint', { err_msg: '' }))
|
|
73
|
+
.catch((err) => ports.track?.('generate_footprint', {
|
|
74
|
+
err_msg: String((err as Error)?.message || err),
|
|
75
|
+
}))
|
|
76
|
+
}, [imageDataUrl, hint, runner, ports])
|
|
73
77
|
|
|
74
78
|
const confirmDimensions = useCallback((values: DimensionValues, edited: Record<string, boolean>): void => {
|
|
75
79
|
void runner.run({
|
|
@@ -12,6 +12,7 @@ import { UploadInput } from '../components/UploadInput.js'
|
|
|
12
12
|
import { ResultStage } from '../components/ResultStage.js'
|
|
13
13
|
import { useAuthGate } from '../hooks/useAuthGate.js'
|
|
14
14
|
import { useJobRunner } from '../hooks/useJobRunner.js'
|
|
15
|
+
import { symbolPinCount } from '../utils/symbol-pins.js'
|
|
15
16
|
|
|
16
17
|
export interface SymbolGenPageProps {
|
|
17
18
|
ports: ComponentGenPorts
|
|
@@ -54,6 +55,21 @@ export function SymbolGenPage({ ports, t, reopen = null }: SymbolGenPageProps):
|
|
|
54
55
|
ports.config().then(setConfig).catch(() => { /* best effort */ })
|
|
55
56
|
}, [ports])
|
|
56
57
|
|
|
58
|
+
// 神策埋点:生成symbol
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (runner.phase === 'failed') {
|
|
61
|
+
ports.track?.('generate_symbol', { success: false, err_msg: runner.error })
|
|
62
|
+
}
|
|
63
|
+
if (runner.phase === 'completed' && !runner.jobId?.startsWith('history:')) {
|
|
64
|
+
const artifact = runner.result.artifact as { id?: unknown } | undefined
|
|
65
|
+
if (typeof artifact?.id === 'string') {
|
|
66
|
+
void ports.artifactContent(artifact.id).then((source) => {
|
|
67
|
+
ports.track?.('generate_symbol', { success: true, err_msg: '', pin_count: symbolPinCount(source) })
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, [runner.phase])
|
|
72
|
+
|
|
57
73
|
const maxBytes = config?.limits.imageBytes ?? 4 * 1024 * 1024
|
|
58
74
|
const authed = auth.phase === 'authenticated'
|
|
59
75
|
const canGenerate = authed && !!imageDataUrl && runner.phase !== 'running'
|
package/src/ports.ts
CHANGED
|
@@ -149,6 +149,7 @@ export interface ComponentGenPlacePort {
|
|
|
149
149
|
|
|
150
150
|
/** The whole contract the app needs from its host. */
|
|
151
151
|
export interface ComponentGenPorts {
|
|
152
|
+
track?(event: string, properties?: Record<string, unknown>): void
|
|
152
153
|
config(): Promise<ComponentGenConfig>
|
|
153
154
|
startJob(req: StartJobRequest, signal?: AbortSignal): Promise<JobState>
|
|
154
155
|
jobEvents(jobId: string, onEvent: (e: JobEvent) => void): () => void
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SchematicParser, type schematicProto } from '@huaqiu/kicad-sexpr-parser'
|
|
2
|
+
|
|
3
|
+
export function symbolPinCount(source: string): number {
|
|
4
|
+
const symbols = new SchematicParser().parseLibSymbols(source)
|
|
5
|
+
const numbers = new Set<string>()
|
|
6
|
+
const collect = (symbol: schematicProto.I_LibSymbol): void => {
|
|
7
|
+
for (const pin of symbol.pins ?? []) numbers.add(pin.number.text)
|
|
8
|
+
for (const child of symbol.children ?? []) collect(child)
|
|
9
|
+
}
|
|
10
|
+
for (const symbol of symbols) collect(symbol)
|
|
11
|
+
return numbers.size
|
|
12
|
+
}
|