@tscircuit/schematic-viewer 1.3.0 → 1.4.1
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/README.md +1 -1
- package/biome.json +45 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +734 -688
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
- package/src/Schematic.tsx +141 -65
- package/src/lib/render-context/index.ts +1 -1
- package/src/lib/types/core.ts +14 -49
- package/src/lib/types/source-component.ts +6 -1
- package/src/lib/utils/collect-element-refs.ts +5 -4
- package/src/lib/utils/colors.ts +235 -0
- package/src/lib/utils/direction-to-vec.ts +3 -3
- package/src/schematic-components/SVGPathComponent.tsx +71 -112
- package/src/schematic-components/SchematicChip.tsx +222 -0
- package/src/schematic-components/SchematicComponent.tsx +25 -22
- package/src/schematic-components/SchematicComponentFromSymbol.tsx +46 -0
- package/src/schematic-components/SchematicElement.tsx +0 -28
- package/src/schematic-components/SchematicNetLabel.tsx +3 -0
- package/src/schematic-components/SchematicText.tsx +4 -6
- package/src/schematic-components/SchematicTrace.tsx +4 -3
- package/src/schematic-components/TableViewer.tsx +1 -1
- package/src/schematic-components/index.tsx +6 -14
- package/src/stories/basics/schematic-net-label.stories.tsx +2 -0
- package/src/stories/basics/schematic-net-labels-2.stories.tsx +22 -20
- package/src/stories/bug-connections.stories.tsx +18 -13
- package/src/stories/bug-high-port-numbers.stories.tsx +107 -85
- package/src/stories/bug-one-sided.stories.tsx +17 -15
- package/src/stories/bug-pin-spacing.stories.tsx +19 -17
- package/src/stories/bugs/bug1-y-flip.stories.tsx +7 -5
- package/src/stories/bugs/bug3-scaling-trace.stories.tsx +11 -5
- package/src/stories/bugs/bug4-schematic-line.stories.tsx +0 -1
- package/src/stories/bugs/bug5-diode.stories.tsx +3 -2
- package/src/stories/bugs/bug6-trace-scaling.stories.tsx +5 -41
- package/src/stories/bugs/bug8-autolayout.stories.tsx +20 -29
- package/src/stories/circuit-components/diode.stories.tsx +3 -1
- package/src/stories/circuit-components/resistor.stories.tsx +3 -1
- package/src/stories/led-circuit-react.stories.tsx +35 -48
- package/src/stories/rotated-resistor.stories.tsx +10 -8
- package/src/stories/three-sided-bug.stories.tsx +17 -15
- package/src/pages/led-circuit.tsx +0 -96
- package/src/schematic-components/ProjectComponent.tsx +0 -70
- package/src/schematic-components/SchematicBox.tsx +0 -29
- package/src/schematic-components/SchematicBug.tsx +0 -107
- package/src/schematic-components/SchematicLine.tsx +0 -48
- package/src/schematic-components/SchematicPath.tsx +0 -51
- package/src/schematic-components/SchematicPort.tsx +0 -63
- package/src/schematic-components/SimpleCapacitor.tsx +0 -29
- package/src/schematic-components/SimpleDiode.tsx +0 -42
- package/src/schematic-components/SimpleGround.tsx +0 -30
- package/src/schematic-components/SimpleInductor.tsx +0 -29
- package/src/schematic-components/SimplePowerSource.tsx +0 -43
- package/src/schematic-components/SimpleResistor.tsx +0 -28
- package/src/stories/led-circuit-builder.stories.tsx +0 -104
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/schematic-viewer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "storybook dev -p 6006",
|
|
12
|
+
"format": "biome format . --write",
|
|
12
13
|
"typecheck": "tsc --noEmit",
|
|
13
14
|
"build": "tsup",
|
|
14
15
|
"yalc": "npm run build && yalc push",
|
|
@@ -17,13 +18,12 @@
|
|
|
17
18
|
"chromatic": "npx chromatic --project-token=chpt_d88a6beb0734bbe"
|
|
18
19
|
},
|
|
19
20
|
"peerDependencies": {
|
|
20
|
-
"@tscircuit/builder": "*",
|
|
21
|
-
"@tscircuit/react-fiber": "*",
|
|
22
21
|
"@tscircuit/table-viewer": "*",
|
|
23
22
|
"react": "*"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"@babel/core": "^7.18.9",
|
|
26
|
+
"@biomejs/biome": "^1.8.3",
|
|
27
27
|
"@emotion/react": "^11",
|
|
28
28
|
"@emotion/styled": "^11",
|
|
29
29
|
"@semantic-release/changelog": "^6.0.3",
|
|
@@ -35,8 +35,6 @@
|
|
|
35
35
|
"@storybook/nextjs": "^8.1.3",
|
|
36
36
|
"@storybook/react": "^8.1.3",
|
|
37
37
|
"@storybook/testing-library": "^0.0.14-next.2",
|
|
38
|
-
"@tscircuit/builder": "^1.5.126",
|
|
39
|
-
"@tscircuit/react-fiber": "^1.1.29",
|
|
40
38
|
"@tscircuit/routing": "^1.3.0",
|
|
41
39
|
"@tscircuit/table-viewer": "^0.0.6",
|
|
42
40
|
"@types/node": "^18.6.0",
|
|
@@ -44,7 +42,7 @@
|
|
|
44
42
|
"@vitejs/plugin-react": "^4.3.0",
|
|
45
43
|
"ava": "^4.3.1",
|
|
46
44
|
"chromatic": "^11.5.5",
|
|
47
|
-
"circuit-json": "^0.0.
|
|
45
|
+
"circuit-json": "^0.0.92",
|
|
48
46
|
"esbuild": "^0.20.2",
|
|
49
47
|
"esbuild-register": "^3.5.0",
|
|
50
48
|
"next": "^14.2.3",
|
|
@@ -67,12 +65,15 @@
|
|
|
67
65
|
},
|
|
68
66
|
"dependencies": {
|
|
69
67
|
"@storybook/react-vite": "^8.1.3",
|
|
68
|
+
"@tscircuit/core": "^0.0.132",
|
|
70
69
|
"@tscircuit/layout": "^0.0.25",
|
|
71
70
|
"@tscircuit/props": "^0.0.23",
|
|
72
|
-
"@tscircuit/soup-util": "^0.0.
|
|
71
|
+
"@tscircuit/soup-util": "^0.0.38",
|
|
72
|
+
"circuit-to-svg": "^0.0.54",
|
|
73
73
|
"convert-units": "^2.3.4",
|
|
74
74
|
"react-error-boundary": "^4.0.4",
|
|
75
75
|
"react-supergrid": "^1.0.10",
|
|
76
|
+
"schematic-symbols": "^0.0.78",
|
|
76
77
|
"use-mouse-matrix-transform": "^1.1.12"
|
|
77
78
|
},
|
|
78
79
|
"bugs": {
|
package/src/Schematic.tsx
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
createProjectFromElements,
|
|
5
|
-
findBoundsAndCenter,
|
|
6
|
-
} from "@tscircuit/builder"
|
|
7
|
-
import TscReactFiber, { createRoot } from "@tscircuit/react-fiber"
|
|
8
|
-
import { AnyCircuitElement } from "circuit-json"
|
|
1
|
+
import { useRenderedCircuit } from "@tscircuit/core"
|
|
2
|
+
import { findBoundsAndCenter } from "@tscircuit/soup-util"
|
|
3
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
9
4
|
import { useGlobalStore } from "lib/render-context"
|
|
10
|
-
import { useCallback, useEffect, useState } from "react"
|
|
5
|
+
import React, { useCallback, useEffect, useRef, useState } from "react"
|
|
11
6
|
import { ErrorBoundary as TypedErrorBoundary } from "react-error-boundary"
|
|
12
7
|
import { SuperGrid, toMMSI } from "react-supergrid"
|
|
13
8
|
import useMeasure from "react-use-measure"
|
|
14
9
|
import { ContextProviders } from "schematic-components"
|
|
15
10
|
import { SchematicElement } from "schematic-components/SchematicElement"
|
|
16
|
-
import {
|
|
17
|
-
|
|
11
|
+
import {
|
|
12
|
+
applyToPoint,
|
|
13
|
+
compose,
|
|
14
|
+
inverse,
|
|
15
|
+
Matrix,
|
|
16
|
+
scale,
|
|
17
|
+
translate,
|
|
18
|
+
} from "transformation-matrix"
|
|
18
19
|
import { TableViewer } from "./schematic-components/TableViewer"
|
|
19
20
|
|
|
20
21
|
const ErrorBoundary = TypedErrorBoundary as any
|
|
@@ -34,16 +35,9 @@ const toMMSINeg = (v: number, z: number) =>
|
|
|
34
35
|
|
|
35
36
|
export interface SchematicProps {
|
|
36
37
|
children?: any
|
|
37
|
-
|
|
38
|
-
/** @deprecated use soup */
|
|
39
|
-
elements?: any
|
|
40
|
-
|
|
41
38
|
soup?: AnyCircuitElement[]
|
|
42
|
-
|
|
43
|
-
style?: any
|
|
44
|
-
|
|
39
|
+
style?: React.CSSProperties
|
|
45
40
|
showTable?: boolean
|
|
46
|
-
|
|
47
41
|
_soupPostProcessor?: (soup: AnyCircuitElement[]) => AnyCircuitElement[]
|
|
48
42
|
}
|
|
49
43
|
|
|
@@ -57,28 +51,54 @@ export const Schematic = (props: SchematicProps) => {
|
|
|
57
51
|
|
|
58
52
|
export const SchematicWithoutContext = ({
|
|
59
53
|
children,
|
|
60
|
-
|
|
61
|
-
soup: initialSoup,
|
|
54
|
+
soup,
|
|
62
55
|
style,
|
|
63
56
|
showTable = false,
|
|
64
57
|
_soupPostProcessor,
|
|
65
58
|
}: SchematicProps) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
const {
|
|
60
|
+
circuitJson: circuitJsonFromChildren,
|
|
61
|
+
error: errorFromChildren,
|
|
62
|
+
isLoading,
|
|
63
|
+
} = useRenderedCircuit(children)
|
|
64
|
+
|
|
65
|
+
const [elements, setElements] = useState<AnyCircuitElement[]>([])
|
|
66
|
+
const { setCameraTransform } = useGlobalStore()
|
|
72
67
|
const [boundsRef, bounds] = useMeasure()
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
const containerRef = useRef<HTMLDivElement>(null)
|
|
69
|
+
const transformRef = useRef<Matrix>(compose(translate(0, 0), scale(1, 1)))
|
|
70
|
+
const isDraggingRef = useRef(false)
|
|
71
|
+
const lastMousePosRef = useRef({ x: 0, y: 0 })
|
|
72
|
+
const [, forceUpdate] = useState({})
|
|
73
|
+
|
|
74
|
+
const updateTransform = useCallback(
|
|
75
|
+
(newTransform: Matrix) => {
|
|
76
|
+
transformRef.current = newTransform
|
|
77
|
+
setCameraTransform(newTransform)
|
|
78
|
+
forceUpdate({})
|
|
76
79
|
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
[setCameraTransform],
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
let processedElements: AnyCircuitElement[] = []
|
|
85
|
+
if (circuitJsonFromChildren && (!soup || soup.length === 0)) {
|
|
86
|
+
processedElements = circuitJsonFromChildren as AnyCircuitElement[]
|
|
87
|
+
} else if (soup && soup.length > 0) {
|
|
88
|
+
processedElements = soup
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (processedElements.length > 0) {
|
|
92
|
+
if (_soupPostProcessor) {
|
|
93
|
+
processedElements = _soupPostProcessor(processedElements)
|
|
94
|
+
}
|
|
95
|
+
setElements(processedElements)
|
|
96
|
+
}
|
|
97
|
+
}, [circuitJsonFromChildren, soup, _soupPostProcessor])
|
|
98
|
+
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (elements.length > 0 && containerRef.current) {
|
|
101
|
+
const elmBounds = containerRef.current.getBoundingClientRect()
|
|
82
102
|
|
|
83
103
|
const { center, width, height } = elements.some((e) =>
|
|
84
104
|
e.type.startsWith("schematic_"),
|
|
@@ -93,38 +113,88 @@ export const SchematicWithoutContext = ({
|
|
|
93
113
|
(elmBounds.height ?? 0) / height,
|
|
94
114
|
100,
|
|
95
115
|
)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
scale(scaleFactor, -scaleFactor, 0, 0),
|
|
102
|
-
translate(-center.x, -center.y),
|
|
103
|
-
),
|
|
116
|
+
|
|
117
|
+
const newTransform = compose(
|
|
118
|
+
translate((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
|
|
119
|
+
scale(scaleFactor, -scaleFactor, 0, 0),
|
|
120
|
+
translate(-center.x, -center.y),
|
|
104
121
|
)
|
|
122
|
+
|
|
123
|
+
updateTransform(newTransform)
|
|
124
|
+
}
|
|
125
|
+
}, [elements, bounds.width, bounds.height, updateTransform])
|
|
126
|
+
|
|
127
|
+
const handleMouseDown = useCallback((e: React.MouseEvent) => {
|
|
128
|
+
isDraggingRef.current = true
|
|
129
|
+
lastMousePosRef.current = { x: e.clientX, y: e.clientY }
|
|
130
|
+
}, [])
|
|
131
|
+
|
|
132
|
+
const handleMouseMove = useCallback(
|
|
133
|
+
(e: React.MouseEvent) => {
|
|
134
|
+
if (!isDraggingRef.current) return
|
|
135
|
+
|
|
136
|
+
const dx = e.clientX - lastMousePosRef.current.x
|
|
137
|
+
const dy = e.clientY - lastMousePosRef.current.y
|
|
138
|
+
lastMousePosRef.current = { x: e.clientX, y: e.clientY }
|
|
139
|
+
|
|
140
|
+
const scale = transformRef.current.a // Assuming uniform scaling
|
|
141
|
+
const dragSensitivity = 150 / scale // Adjust this value to change drag speed
|
|
142
|
+
|
|
143
|
+
const newTransform = compose(
|
|
144
|
+
translate(dx * dragSensitivity, dy * dragSensitivity),
|
|
145
|
+
transformRef.current,
|
|
146
|
+
)
|
|
147
|
+
updateTransform(newTransform)
|
|
105
148
|
},
|
|
106
|
-
[
|
|
149
|
+
[updateTransform],
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
const handleMouseUp = useCallback(() => {
|
|
153
|
+
isDraggingRef.current = false
|
|
154
|
+
}, [])
|
|
155
|
+
|
|
156
|
+
const handleWheel = useCallback(
|
|
157
|
+
(e: WheelEvent) => {
|
|
158
|
+
e.preventDefault()
|
|
159
|
+
const scaleMultiplier = Math.pow(0.999, e.deltaY)
|
|
160
|
+
|
|
161
|
+
if (containerRef.current) {
|
|
162
|
+
const rect = containerRef.current.getBoundingClientRect()
|
|
163
|
+
const mouseX = e.clientX - rect.left
|
|
164
|
+
const mouseY = e.clientY - rect.top
|
|
165
|
+
|
|
166
|
+
const inverseTransform = inverse(transformRef.current)
|
|
167
|
+
const transformedPoint = applyToPoint(inverseTransform, {
|
|
168
|
+
x: mouseX,
|
|
169
|
+
y: mouseY,
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
const newTransform = compose(
|
|
173
|
+
transformRef.current,
|
|
174
|
+
translate(transformedPoint.x, transformedPoint.y),
|
|
175
|
+
scale(scaleMultiplier, scaleMultiplier),
|
|
176
|
+
translate(-transformedPoint.x, -transformedPoint.y),
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
updateTransform(newTransform)
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
[updateTransform],
|
|
107
183
|
)
|
|
108
184
|
|
|
109
185
|
useEffect(() => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
186
|
+
const container = containerRef.current
|
|
187
|
+
if (container) {
|
|
188
|
+
container.addEventListener("wheel", handleWheel, { passive: false })
|
|
189
|
+
return () => {
|
|
190
|
+
container.removeEventListener("wheel", handleWheel)
|
|
191
|
+
}
|
|
113
192
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
elements = _soupPostProcessor(elements)
|
|
120
|
-
}
|
|
121
|
-
setElementsAndCamera(elements)
|
|
122
|
-
})
|
|
123
|
-
.catch((e) => {
|
|
124
|
-
console.error("ERROR RENDERING CIRCUIT")
|
|
125
|
-
throw e
|
|
126
|
-
})
|
|
127
|
-
}, [children])
|
|
193
|
+
}, [handleWheel])
|
|
194
|
+
|
|
195
|
+
if (errorFromChildren) {
|
|
196
|
+
return <div>Error: {errorFromChildren.message}</div>
|
|
197
|
+
}
|
|
128
198
|
|
|
129
199
|
return (
|
|
130
200
|
<>
|
|
@@ -136,13 +206,17 @@ export const SchematicWithoutContext = ({
|
|
|
136
206
|
overflow: "hidden",
|
|
137
207
|
position: "relative",
|
|
138
208
|
isolation: "isolate",
|
|
139
|
-
cursor: "grab",
|
|
209
|
+
cursor: isDraggingRef.current ? "grabbing" : "grab",
|
|
140
210
|
...style,
|
|
141
211
|
}}
|
|
142
212
|
ref={(el) => {
|
|
143
|
-
|
|
213
|
+
containerRef.current = el
|
|
144
214
|
boundsRef(el)
|
|
145
215
|
}}
|
|
216
|
+
onMouseDown={handleMouseDown}
|
|
217
|
+
onMouseMove={handleMouseMove}
|
|
218
|
+
onMouseUp={handleMouseUp}
|
|
219
|
+
onMouseLeave={handleMouseUp}
|
|
146
220
|
>
|
|
147
221
|
<SuperGrid
|
|
148
222
|
stringifyCoord={(x, y, z) => {
|
|
@@ -151,7 +225,7 @@ export const SchematicWithoutContext = ({
|
|
|
151
225
|
}}
|
|
152
226
|
width={bounds.width}
|
|
153
227
|
height={bounds.height}
|
|
154
|
-
transform={
|
|
228
|
+
transform={transformRef.current}
|
|
155
229
|
/>
|
|
156
230
|
{elements?.map((elm, i) => (
|
|
157
231
|
<ErrorBoundary key={i} fallbackRender={fallbackRender(elm)}>
|
|
@@ -163,7 +237,9 @@ export const SchematicWithoutContext = ({
|
|
|
163
237
|
</ErrorBoundary>
|
|
164
238
|
))}
|
|
165
239
|
</div>
|
|
166
|
-
{showTable !== false && elements &&
|
|
240
|
+
{showTable !== false && elements && (
|
|
241
|
+
<TableViewer elements={elements as any} />
|
|
242
|
+
)}
|
|
167
243
|
</>
|
|
168
244
|
)
|
|
169
245
|
}
|
package/src/lib/types/core.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { AnySourceComponent, SourceComponent } from "./source-component"
|
|
2
|
+
import {
|
|
3
|
+
Size,
|
|
4
|
+
Point,
|
|
5
|
+
PcbTrace,
|
|
6
|
+
PcbComponent,
|
|
7
|
+
PcbPort,
|
|
8
|
+
SourceGroup,
|
|
9
|
+
} from "circuit-json"
|
|
2
10
|
|
|
3
11
|
export interface SchematicConfig {
|
|
4
12
|
type: "schematic_config"
|
|
5
13
|
}
|
|
6
14
|
|
|
7
|
-
export interface Point {
|
|
8
|
-
x: number
|
|
9
|
-
y: number
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface Size {
|
|
13
|
-
width: number
|
|
14
|
-
height: number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
15
|
export interface SourceConfig {
|
|
18
16
|
type: "source_config"
|
|
19
17
|
}
|
|
@@ -111,32 +109,6 @@ export interface SchematicPort {
|
|
|
111
109
|
facing_direction?: "up" | "down" | "left" | "right"
|
|
112
110
|
}
|
|
113
111
|
|
|
114
|
-
export interface PCBTrace {
|
|
115
|
-
type: "pcb_trace"
|
|
116
|
-
source_trace_id: string
|
|
117
|
-
pcb_trace_id: string
|
|
118
|
-
route: Array<{
|
|
119
|
-
x: number
|
|
120
|
-
y: number
|
|
121
|
-
strokeWidth: number
|
|
122
|
-
cap: "butt" | "round" | "square"
|
|
123
|
-
start_pcb_port_id?: string
|
|
124
|
-
end_pcb_port_id?: string
|
|
125
|
-
}>
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface PCBComponent {
|
|
129
|
-
type: "pcb_component"
|
|
130
|
-
pcb_component_id: string
|
|
131
|
-
source_component_id: string
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export interface PCBPort {
|
|
135
|
-
type: "pcb_port"
|
|
136
|
-
pcb_port_id: string
|
|
137
|
-
source_port_id: string
|
|
138
|
-
}
|
|
139
|
-
|
|
140
112
|
export interface PCBGroup {
|
|
141
113
|
type: "pcb_group"
|
|
142
114
|
source_group_id: string
|
|
@@ -153,13 +125,6 @@ export interface SourceTrace {
|
|
|
153
125
|
connected_source_port_ids: string[]
|
|
154
126
|
}
|
|
155
127
|
|
|
156
|
-
export interface SourceGroup {
|
|
157
|
-
type: "source_group"
|
|
158
|
-
source_group_id: string
|
|
159
|
-
name: string
|
|
160
|
-
children_source_component_ids: string[]
|
|
161
|
-
}
|
|
162
|
-
|
|
163
128
|
export interface SourcePort {
|
|
164
129
|
type: "source_port"
|
|
165
130
|
name: string
|
|
@@ -178,9 +143,9 @@ export interface Project {
|
|
|
178
143
|
schematic_ports: SchematicPort[]
|
|
179
144
|
pcb_config: PCBConfig
|
|
180
145
|
pcb_groups: PCBGroup[]
|
|
181
|
-
pcb_components:
|
|
182
|
-
pcb_traces:
|
|
183
|
-
pcb_ports:
|
|
146
|
+
pcb_components: PcbComponent[]
|
|
147
|
+
pcb_traces: PcbTrace[]
|
|
148
|
+
pcb_ports: PcbPort[]
|
|
184
149
|
source_config: SourceConfig
|
|
185
150
|
source_traces: SourceTrace[]
|
|
186
151
|
source_groups: SourceGroup[]
|
|
@@ -195,11 +160,11 @@ export type AnyElement =
|
|
|
195
160
|
| SourceGroup
|
|
196
161
|
| SourceTrace
|
|
197
162
|
| SourcePort
|
|
198
|
-
|
|
|
199
|
-
|
|
|
163
|
+
| PcbTrace
|
|
164
|
+
| PcbComponent
|
|
200
165
|
| PCBGroup
|
|
201
166
|
| PCBConfig
|
|
202
|
-
|
|
|
167
|
+
| PcbPort
|
|
203
168
|
| SchematicGroup
|
|
204
169
|
| SchematicComponent
|
|
205
170
|
| SchematicTrace
|
|
@@ -38,6 +38,10 @@ export interface SimpleBug extends SourceComponentBase {
|
|
|
38
38
|
manufacturerPartNumber: any
|
|
39
39
|
ftype: "simple_bug"
|
|
40
40
|
}
|
|
41
|
+
export interface SimpleChip extends SourceComponentBase {
|
|
42
|
+
manufacturerPartNumber: any
|
|
43
|
+
ftype: "simple_chip"
|
|
44
|
+
}
|
|
41
45
|
|
|
42
46
|
export interface SimplePowerSource extends SourceComponentBase {
|
|
43
47
|
ftype: "simple_power_source"
|
|
@@ -52,6 +56,7 @@ export type AnySourceComponent =
|
|
|
52
56
|
| SimpleResistor
|
|
53
57
|
| SimpleCapacitor
|
|
54
58
|
| SimpleBug
|
|
59
|
+
| SimpleChip
|
|
55
60
|
| SimpleInductor
|
|
56
61
|
| SimplePowerSource
|
|
57
62
|
| SimpleGround
|
|
@@ -64,5 +69,5 @@ export type SourceComponentFType = Extract<
|
|
|
64
69
|
{ ftype: string }
|
|
65
70
|
>["ftype"]
|
|
66
71
|
export type SourceComponent<
|
|
67
|
-
T extends SourceComponentFType = SourceComponentFType
|
|
72
|
+
T extends SourceComponentFType = SourceComponentFType,
|
|
68
73
|
> = Extract<AnySourceComponent, { ftype: T }>
|
|
@@ -2,19 +2,19 @@ import { AnyCircuitElement, SourcePort } from "circuit-json"
|
|
|
2
2
|
|
|
3
3
|
export const collectElementRefs = (
|
|
4
4
|
elm: AnyCircuitElement,
|
|
5
|
-
allElms: AnyCircuitElement[]
|
|
5
|
+
allElms: AnyCircuitElement[],
|
|
6
6
|
) => {
|
|
7
7
|
const source_port = allElms.find(
|
|
8
8
|
(e) =>
|
|
9
9
|
e.type === "source_port" &&
|
|
10
|
-
e.source_port_id === (elm as any).source_port_id
|
|
10
|
+
e.source_port_id === (elm as any).source_port_id,
|
|
11
11
|
) as SourcePort | null
|
|
12
12
|
const source_component_id: string =
|
|
13
13
|
(elm as any).source_component_id ?? source_port?.source_component_id
|
|
14
14
|
const source_component = allElms.find(
|
|
15
15
|
(e) =>
|
|
16
16
|
e.type === "source_component" &&
|
|
17
|
-
e.source_component_id === source_component_id
|
|
17
|
+
e.source_component_id === source_component_id,
|
|
18
18
|
)
|
|
19
19
|
if (
|
|
20
20
|
[
|
|
@@ -29,7 +29,7 @@ export const collectElementRefs = (
|
|
|
29
29
|
const schematic_children = allElms.filter(
|
|
30
30
|
(e) =>
|
|
31
31
|
"schematic_component_id" in e &&
|
|
32
|
-
e.schematic_component_id === (elm as any).schematic_component_id
|
|
32
|
+
e.schematic_component_id === (elm as any).schematic_component_id,
|
|
33
33
|
)
|
|
34
34
|
|
|
35
35
|
return {
|
|
@@ -38,6 +38,7 @@ export const collectElementRefs = (
|
|
|
38
38
|
source: source_component,
|
|
39
39
|
source_component,
|
|
40
40
|
source_port,
|
|
41
|
+
allElements: allElms,
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
return null
|