@tscircuit/schematic-viewer 2.0.56 → 2.0.57

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.
Files changed (69) hide show
  1. package/dist/index.js +4 -1
  2. package/dist/index.js.map +1 -1
  3. package/package.json +4 -1
  4. package/.github/workflows/bun-formatcheck.yml +0 -26
  5. package/.github/workflows/bun-pver-release.yml +0 -59
  6. package/.github/workflows/bun-typecheck.yml +0 -26
  7. package/.github/workflows/on-merge-inform-release-tracker.yml +0 -24
  8. package/CLAUDE.md +0 -1
  9. package/biome.json +0 -56
  10. package/bun.lockb +0 -0
  11. package/cosmos.config.json +0 -3
  12. package/cosmos.decorator.tsx +0 -3
  13. package/docs/circuit-to-svg-metadata.md +0 -151
  14. package/docs/dragndrop-spec.md +0 -39
  15. package/examples/example1-resistor-and-capacitor.fixture.tsx +0 -16
  16. package/examples/example10-groups-view-schematic-groups.fixture.tsx +0 -76
  17. package/examples/example11-automatic-grouping-view-schematic-groups.fixture.tsx +0 -109
  18. package/examples/example12-spice-boost-converter.fixture.tsx +0 -78
  19. package/examples/example13-disablegroups.fixture.tsx +0 -30
  20. package/examples/example14-schematic-component-click.fixture.tsx +0 -46
  21. package/examples/example15-analog-simulation-viewer.fixture.tsx +0 -145
  22. package/examples/example16-no-analog-simulation.fixture.tsx +0 -13
  23. package/examples/example17-schematic-ports.fixture.tsx +0 -49
  24. package/examples/example18-live-toggle.fixture.tsx +0 -60
  25. package/examples/example2-small-circuit.fixture.tsx +0 -48
  26. package/examples/example3-small-circuit-without-debug-grid.fixture.tsx +0 -44
  27. package/examples/example4-reset-edit-events.fixture.tsx +0 -57
  28. package/examples/example5-circuit-json-rerender.fixture.tsx +0 -110
  29. package/examples/example6-click-to-interact.fixture.tsx +0 -36
  30. package/examples/example7-schematic-viewer-fix-snapping.fixture.tsx +0 -123
  31. package/examples/example8-color-overrides.fixture.tsx +0 -52
  32. package/examples/example9-spice-rc-charging-voltage-divider.fixture.tsx +0 -77
  33. package/index.html +0 -12
  34. package/lib/components/AnalogSimulationViewer.tsx +0 -300
  35. package/lib/components/ControlledSchematicViewer.tsx +0 -40
  36. package/lib/components/EditIcon.tsx +0 -46
  37. package/lib/components/GridIcon.tsx +0 -45
  38. package/lib/components/MouseTracker.tsx +0 -257
  39. package/lib/components/SchematicComponentMouseTarget.tsx +0 -189
  40. package/lib/components/SchematicPortMouseTarget.tsx +0 -224
  41. package/lib/components/SchematicViewer.tsx +0 -583
  42. package/lib/components/SpiceIcon.tsx +0 -14
  43. package/lib/components/SpicePlot.tsx +0 -221
  44. package/lib/components/SpiceSimulationIcon.tsx +0 -32
  45. package/lib/components/SpiceSimulationOverlay.tsx +0 -250
  46. package/lib/components/ViewMenu.tsx +0 -218
  47. package/lib/components/ViewMenuIcon.tsx +0 -47
  48. package/lib/dev/render-to-circuit-json.ts +0 -8
  49. package/lib/hooks/use-resize-handling.ts +0 -35
  50. package/lib/hooks/useChangeSchematicComponentLocationsInSvg.ts +0 -117
  51. package/lib/hooks/useChangeSchematicTracesForMovedComponents.ts +0 -121
  52. package/lib/hooks/useComponentDragging.ts +0 -251
  53. package/lib/hooks/useLocalStorage.ts +0 -63
  54. package/lib/hooks/useMouseEventsOverBoundingBox.ts +0 -74
  55. package/lib/hooks/useSchematicGroupsOverlay.ts +0 -364
  56. package/lib/hooks/useSpiceSimulation.ts +0 -149
  57. package/lib/index.ts +0 -4
  58. package/lib/types/edit-events.ts +0 -16
  59. package/lib/types/eecircuit-engine.d.ts +0 -147
  60. package/lib/utils/debug.ts +0 -9
  61. package/lib/utils/get-component-offset-due-to-events.ts +0 -43
  62. package/lib/utils/spice-utils.ts +0 -128
  63. package/lib/utils/z-index-map.ts +0 -11
  64. package/lib/workers/spice-simulation.worker.ts +0 -51
  65. package/scripts/build-worker-blob-url.ts +0 -55
  66. package/src/main.tsx +0 -21
  67. package/tsconfig.json +0 -33
  68. package/tsup-webworker.config.ts +0 -13
  69. package/vite.config.js +0 -15
@@ -1,36 +0,0 @@
1
- import { ControlledSchematicViewer } from "lib/components/ControlledSchematicViewer"
2
- import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
3
-
4
- export default () => (
5
- <div style={{ position: "relative", height: "100%" }}>
6
- <div
7
- style={{
8
- position: "absolute",
9
- top: "16px",
10
- right: "64px",
11
- zIndex: 1001,
12
- backgroundColor: "#fff",
13
- padding: "12px",
14
- borderRadius: "4px",
15
- border: "1px solid #ccc",
16
- boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
17
- fontSize: "14px",
18
- fontFamily: "sans-serif",
19
- }}
20
- >
21
- This example demonstrates the clickToInteractEnabled feature
22
- </div>
23
- <ControlledSchematicViewer
24
- circuitJson={renderToCircuitJson(
25
- <board width="10mm" height="10mm">
26
- <resistor name="R1" resistance={1000} schX={-2} />
27
- <capacitor name="C1" capacitance="1uF" schX={2} />
28
- <trace from=".R1 .pin2" to=".C1 .pin1" />
29
- </board>,
30
- )}
31
- containerStyle={{ height: "100%" }}
32
- debugGrid
33
- clickToInteractEnabled={true}
34
- />
35
- </div>
36
- )
@@ -1,123 +0,0 @@
1
- import { applyEditEventsToManualEditsFile } from "@tscircuit/core"
2
- import type { CircuitJson } from "circuit-json"
3
- import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
4
- import { SchematicViewer } from "lib/index"
5
- import type { ManualEditEvent } from "lib/types/edit-events"
6
- import { useEffect, useState } from "react"
7
- import type { ManualEditsFile } from "@tscircuit/props"
8
-
9
- export default () => {
10
- const [editEvents, setEditEvents] = useState<ManualEditEvent[]>([])
11
- const [circuitJson, setCircuitJson] = useState<CircuitJson | null>(null)
12
- const [manualEdits, setManualEdits] = useState<ManualEditsFile>({
13
- schematic_placements: [
14
- {
15
- center: {
16
- x: 2,
17
- y: 3,
18
- },
19
- relative_to: "group_center",
20
- selector: "C1",
21
- },
22
- ],
23
- })
24
-
25
- const rerenderCircuitJson = () => {
26
- setCircuitJson(
27
- renderToCircuitJson(
28
- <board width="10mm" height="10mm" manualEdits={manualEdits}>
29
- <resistor name="R1" resistance={1000} />
30
- <capacitor name="C1" capacitance="1uF" />
31
- <trace from=".R1 .pin2" to=".C1 .pin1" />
32
- </board>,
33
- ) as any,
34
- )
35
- }
36
-
37
- useEffect(() => {
38
- rerenderCircuitJson()
39
- }, [])
40
-
41
- useEffect(() => {
42
- // Apply edit events to manual edits for persistence between renders
43
- const updatedManualEdits = applyEditEventsToManualEditsFile({
44
- circuitJson: circuitJson ?? ([] as any),
45
- editEvents,
46
- manualEditsFile: manualEdits,
47
- })
48
- setManualEdits(updatedManualEdits)
49
- }, [editEvents, circuitJson])
50
-
51
- return (
52
- <div style={{ position: "relative", height: "100%" }}>
53
- <button
54
- type="button"
55
- onClick={rerenderCircuitJson}
56
- style={{
57
- position: "absolute",
58
- top: "16px",
59
- right: "64px",
60
- zIndex: 1001,
61
- backgroundColor: "#f44336",
62
- color: "#fff",
63
- padding: "8px",
64
- borderRadius: "4px",
65
- cursor: "pointer",
66
- border: "none",
67
- boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
68
- }}
69
- >
70
- Rerender Circuit JSON
71
- </button>
72
- <button
73
- type="button"
74
- onClick={() => {
75
- setEditEvents([])
76
- }}
77
- style={{
78
- position: "absolute",
79
- top: "16px",
80
- right: "220px",
81
- zIndex: 1001,
82
- backgroundColor: "#2196f3",
83
- color: "#fff",
84
- padding: "8px",
85
- borderRadius: "4px",
86
- cursor: "pointer",
87
- border: "none",
88
- boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
89
- }}
90
- >
91
- Reset Edits
92
- </button>
93
- <pre
94
- style={{
95
- position: "absolute",
96
- top: "64px",
97
- right: "64px",
98
- zIndex: 1001,
99
- backgroundColor: "#fff",
100
- padding: "12px",
101
- borderRadius: "4px",
102
- border: "1px solid #ccc",
103
- boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
104
- maxHeight: "300px",
105
- overflowY: "auto",
106
- fontSize: "12px",
107
- fontFamily: "monospace",
108
- }}
109
- >
110
- {JSON.stringify(editEvents, null, 2)}
111
- </pre>
112
- <SchematicViewer
113
- onEditEvent={(event) => {
114
- setEditEvents((prev) => [...prev, event])
115
- }}
116
- circuitJson={circuitJson ?? []}
117
- containerStyle={{ height: "100%" }}
118
- debugGrid
119
- editingEnabled
120
- />
121
- </div>
122
- )
123
- }
@@ -1,52 +0,0 @@
1
- import { SchematicViewer } from "lib/components/SchematicViewer"
2
- import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
3
-
4
- export default () => (
5
- <SchematicViewer
6
- circuitJson={renderToCircuitJson(
7
- <board width="10mm" height="10mm">
8
- <resistor name="R1" resistance={1000} schX={-2} />
9
- <capacitor name="C1" capacitance="1uF" schX={2} schY={2} />
10
- <capacitor
11
- name="C2"
12
- schRotation={90}
13
- capacitance="1uF"
14
- schX={0}
15
- schY={-4}
16
- />
17
- <chip
18
- name="U1"
19
- pinLabels={{
20
- pin1: "D0",
21
- pin2: "D1",
22
- pin3: "D2",
23
- pin4: "GND",
24
- pin5: "D3",
25
- pin6: "EN",
26
- pin7: "D4",
27
- pin8: "VCC",
28
- }}
29
- footprint="soic8"
30
- schX={0}
31
- schY={-1.5}
32
- />
33
-
34
- <trace from=".R1 .pin2" to=".C1 .pin1" />
35
- <trace from=".C1 .pin2" to=".U1 .pin4" />
36
- <trace from=".U1 .pin8" to=".C2 .pin1" />
37
- <trace from=".C2 .pin2" to=".R1 .pin1" />
38
- <trace from=".U1 .pin1" to=".U1 .pin5" />
39
- </board>,
40
- )}
41
- editingEnabled
42
- containerStyle={{ height: "100%" }}
43
- debugGrid
44
- debug
45
- colorOverrides={{
46
- schematic: {
47
- background: "transparent",
48
- component_body: "#FFFFFF",
49
- },
50
- }}
51
- />
52
- )
@@ -1,77 +0,0 @@
1
- import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
2
- import { SchematicViewer } from "lib/index"
3
- import type { CircuitJson } from "circuit-json"
4
- import { sel } from "tscircuit"
5
-
6
- const circuit = (
7
- <board width={16} height={16}>
8
- <chip
9
- name="V1"
10
- footprint="sot23"
11
- pinLabels={{
12
- pin1: "VOUT",
13
- pin2: "GND",
14
- }}
15
- pinAttributes={{
16
- VOUT: { providesPower: true, providesVoltage: 5 },
17
- GND: { providesGround: true },
18
- }}
19
- connections={{
20
- pin3: "net.NC",
21
- }}
22
- />
23
-
24
- <resistor
25
- name="R1"
26
- resistance="1k"
27
- footprint="0402"
28
- pcbX={4}
29
- pcbY={4}
30
- schX={-2}
31
- schY={2}
32
- />
33
- <resistor
34
- name="R2"
35
- resistance="2k"
36
- footprint="0402"
37
- pcbX={-4}
38
- pcbY={-4}
39
- schX={0}
40
- schY={4}
41
- />
42
- <capacitor
43
- name="C1"
44
- capacitance="10uF"
45
- footprint="0402"
46
- pcbX={0}
47
- pcbY={-2}
48
- schX={0}
49
- schY={2}
50
- />
51
-
52
- <trace from={"net.VOUT"} to={sel.R1.pin1} />
53
- <trace from={".V1 > .VOUT"} to={"net.VOUT"} />
54
- <trace from={sel.R1.pin2} to={sel.R2.pin1} />
55
- <trace from={sel.R2.pin2} to={"net.GND"} />
56
- <trace from={"net.GND"} to={".V1 > .GND"} />
57
-
58
- <trace from={sel.C1.pin1} to={sel.R1.pin2} />
59
- <trace from={sel.C1.pin2} to={"net.GND"} />
60
- </board>
61
- )
62
-
63
- export default () => {
64
- const circuitJson = renderToCircuitJson(circuit) as CircuitJson
65
-
66
- return (
67
- <div style={{ position: "relative", height: "100%" }}>
68
- <SchematicViewer
69
- circuitJson={circuitJson}
70
- containerStyle={{ height: "100%" }}
71
- debugGrid
72
- editingEnabled
73
- spiceSimulationEnabled
74
- />
75
- </div>
76
- )
77
- }
package/index.html DELETED
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>@tscircuit/schematic-viewer</title>
7
- </head>
8
- <body>
9
- <div id="root"></div>
10
- <script type="module" src="/src/main.tsx"></script>
11
- </body>
12
- </html>
@@ -1,300 +0,0 @@
1
- import {
2
- convertCircuitJsonToSchematicSimulationSvg,
3
- type ColorOverrides,
4
- } from "circuit-to-svg"
5
- import { useEffect, useState, useMemo, useRef } from "react"
6
- import { useResizeHandling } from "../hooks/use-resize-handling"
7
- import { useMouseMatrixTransform } from "use-mouse-matrix-transform"
8
- import { toString as transformToString } from "transformation-matrix"
9
- import type { CircuitJson } from "circuit-json"
10
-
11
- interface Props {
12
- circuitJson: CircuitJson
13
- containerStyle?: React.CSSProperties
14
- colorOverrides?: ColorOverrides
15
- width?: number
16
- height?: number
17
- className?: string
18
- }
19
-
20
- export const AnalogSimulationViewer = ({
21
- circuitJson: inputCircuitJson,
22
- containerStyle,
23
- colorOverrides,
24
- width,
25
- height,
26
- className,
27
- }: Props) => {
28
- const [circuitJson, setCircuitJson] = useState<CircuitJson | null>(null)
29
- const [isLoading, setIsLoading] = useState(true)
30
- const [error, setError] = useState<string | null>(null)
31
- const [svgObjectUrl, setSvgObjectUrl] = useState<string | null>(null)
32
- const containerRef = useRef<HTMLDivElement>(null)
33
- const imgRef = useRef<HTMLImageElement>(null)
34
-
35
- const { containerWidth, containerHeight } = useResizeHandling(
36
- containerRef as React.RefObject<HTMLElement>,
37
- )
38
-
39
- const [isDragging, setIsDragging] = useState(false)
40
-
41
- const {
42
- ref: transformRef,
43
- cancelDrag: _cancelDrag,
44
- transform: _svgToScreenProjection,
45
- } = useMouseMatrixTransform({
46
- onSetTransform(transform) {
47
- if (imgRef.current) {
48
- imgRef.current.style.transform = transformToString(transform)
49
- }
50
- },
51
- })
52
-
53
- const effectiveWidth = width || containerWidth || 1000
54
- const effectiveHeight = height || containerHeight || 600
55
-
56
- // Set CircuitJSON from props
57
- useEffect(() => {
58
- setIsLoading(true)
59
- setError(null)
60
- setCircuitJson(inputCircuitJson)
61
- setIsLoading(false)
62
- }, [inputCircuitJson])
63
-
64
- // Find simulation experiment ID from circuit JSON
65
- const simulationExperimentId = useMemo(() => {
66
- if (!circuitJson) return null
67
- const simulationElement = circuitJson.find(
68
- (el) => el.type === "simulation_experiment",
69
- )
70
- return simulationElement?.simulation_experiment_id || null
71
- }, [circuitJson])
72
-
73
- // Find simulation graph IDs from circuit JSON
74
- const simulationGraphIds = useMemo(() => {
75
- if (!circuitJson) return []
76
- return circuitJson
77
- .filter((el) => el.type === "simulation_transient_voltage_graph")
78
- .map((el) => el.simulation_transient_voltage_graph_id)
79
- }, [circuitJson])
80
-
81
- // Generate SVG from CircuitJSON
82
- const simulationSvg = useMemo(() => {
83
- if (
84
- !circuitJson ||
85
- !effectiveWidth ||
86
- !effectiveHeight ||
87
- !simulationExperimentId
88
- )
89
- return ""
90
-
91
- try {
92
- return convertCircuitJsonToSchematicSimulationSvg({
93
- circuitJson,
94
- simulation_experiment_id: simulationExperimentId,
95
- simulation_transient_voltage_graph_ids: simulationGraphIds,
96
- width: effectiveWidth,
97
- height: effectiveHeight,
98
- schematicOptions: { colorOverrides },
99
- })
100
- } catch (fallbackErr) {
101
- console.error("Failed to generate fallback schematic SVG:", fallbackErr)
102
- return ""
103
- }
104
- }, [
105
- circuitJson,
106
- effectiveWidth,
107
- effectiveHeight,
108
- colorOverrides,
109
- simulationExperimentId,
110
- simulationGraphIds,
111
- ])
112
-
113
- // Create/revoke object URL whenever the SVG changes
114
- useEffect(() => {
115
- if (!simulationSvg) {
116
- setSvgObjectUrl(null)
117
- return
118
- }
119
-
120
- try {
121
- const blob = new Blob([simulationSvg], { type: "image/svg+xml" })
122
- const url = URL.createObjectURL(blob)
123
- setSvgObjectUrl(url)
124
- return () => {
125
- URL.revokeObjectURL(url)
126
- }
127
- } catch (error) {
128
- console.error("Failed to create SVG object URL:", error)
129
- setSvgObjectUrl(null)
130
- }
131
- }, [simulationSvg])
132
-
133
- const containerBackgroundColor = useMemo(() => {
134
- if (!simulationSvg) return "transparent"
135
- const match = simulationSvg.match(
136
- /<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i,
137
- )
138
- return match?.[1] ?? "transparent"
139
- }, [simulationSvg])
140
-
141
- const handleMouseDown = (_e: React.MouseEvent) => {
142
- setIsDragging(true)
143
- }
144
-
145
- const handleTouchStart = (_e: React.TouchEvent) => {
146
- setIsDragging(true)
147
- }
148
-
149
- useEffect(() => {
150
- const handleMouseUp = () => {
151
- setIsDragging(false)
152
- }
153
-
154
- const handleTouchEnd = () => {
155
- setIsDragging(false)
156
- }
157
-
158
- window.addEventListener("mouseup", handleMouseUp)
159
- window.addEventListener("touchend", handleTouchEnd)
160
-
161
- return () => {
162
- window.removeEventListener("mouseup", handleMouseUp)
163
- window.removeEventListener("touchend", handleTouchEnd)
164
- }
165
- }, [])
166
-
167
- if (isLoading) {
168
- return (
169
- <div
170
- style={{
171
- display: "flex",
172
- alignItems: "center",
173
- justifyContent: "center",
174
- backgroundColor: "#f5f5f5",
175
- minHeight: "300px",
176
- fontFamily: "sans-serif",
177
- fontSize: "16px",
178
- color: "#666",
179
- ...containerStyle,
180
- }}
181
- className={className}
182
- >
183
- Loading circuit...
184
- </div>
185
- )
186
- }
187
-
188
- if (error) {
189
- return (
190
- <div
191
- style={{
192
- display: "flex",
193
- alignItems: "center",
194
- justifyContent: "center",
195
- backgroundColor: "#fef2f2",
196
- minHeight: "300px",
197
- fontFamily: "sans-serif",
198
- fontSize: "16px",
199
- color: "#dc2626",
200
- ...containerStyle,
201
- }}
202
- className={className}
203
- >
204
- <div style={{ textAlign: "center", padding: "20px" }}>
205
- <div style={{ fontWeight: "bold", marginBottom: "8px" }}>
206
- Circuit Conversion Error
207
- </div>
208
- <div style={{ fontSize: "14px" }}>{error}</div>
209
- </div>
210
- </div>
211
- )
212
- }
213
-
214
- if (!simulationSvg) {
215
- return (
216
- <div
217
- style={{
218
- display: "flex",
219
- flexDirection: "column",
220
- alignItems: "center",
221
- justifyContent: "center",
222
- backgroundColor: "#f8fafc",
223
- minHeight: "300px",
224
- fontFamily: "sans-serif",
225
- gap: "12px",
226
- ...containerStyle,
227
- }}
228
- className={className}
229
- >
230
- <div style={{ fontSize: "16px", color: "#475569", fontWeight: 500 }}>
231
- No Simulation Found
232
- </div>
233
- <div style={{ fontSize: "14px", color: "#64748b" }}>
234
- Use{" "}
235
- <code
236
- style={{
237
- backgroundColor: "#e2e8f0",
238
- padding: "2px 6px",
239
- borderRadius: "4px",
240
- fontFamily: "monospace",
241
- fontSize: "13px",
242
- }}
243
- >
244
- {"<analogsimulation />"}
245
- </code>{" "}
246
- to create simulations
247
- </div>
248
- </div>
249
- )
250
- }
251
-
252
- return (
253
- <div
254
- ref={(node) => {
255
- containerRef.current = node
256
- transformRef.current = node
257
- }}
258
- style={{
259
- position: "relative",
260
- backgroundColor: containerBackgroundColor,
261
- overflow: "hidden",
262
- minHeight: "300px",
263
- cursor: isDragging ? "grabbing" : "grab",
264
- ...containerStyle,
265
- }}
266
- className={className}
267
- onMouseDown={handleMouseDown}
268
- onTouchStart={handleTouchStart}
269
- >
270
- {svgObjectUrl ? (
271
- <img
272
- ref={imgRef}
273
- src={svgObjectUrl}
274
- alt="Circuit Simulation"
275
- style={{
276
- transformOrigin: "0 0",
277
- width: "100%",
278
- height: "100%",
279
- display: "block",
280
- objectFit: "contain",
281
- }}
282
- />
283
- ) : (
284
- <div
285
- style={{
286
- display: "flex",
287
- alignItems: "center",
288
- justifyContent: "center",
289
- height: "100%",
290
- minHeight: "300px",
291
- color: "#666",
292
- fontFamily: "sans-serif",
293
- }}
294
- >
295
- Failed to render SVG
296
- </div>
297
- )}
298
- </div>
299
- )
300
- }
@@ -1,40 +0,0 @@
1
- import { useState } from "react"
2
- import { SchematicViewer } from "./SchematicViewer"
3
- import type { ManualEditEvent } from "@tscircuit/props"
4
-
5
- export const ControlledSchematicViewer = ({
6
- circuitJson,
7
- containerStyle,
8
- debugGrid = false,
9
- editingEnabled = false,
10
- debug = false,
11
- clickToInteractEnabled = false,
12
- onSchematicComponentClicked,
13
- }: {
14
- circuitJson: any[]
15
- containerStyle?: React.CSSProperties
16
- debugGrid?: boolean
17
- editingEnabled?: boolean
18
- debug?: boolean
19
- clickToInteractEnabled?: boolean
20
- onSchematicComponentClicked?: (options: {
21
- schematicComponentId: string
22
- event: MouseEvent
23
- }) => void
24
- }) => {
25
- const [editEvents, setEditEvents] = useState<ManualEditEvent[]>([])
26
-
27
- return (
28
- <SchematicViewer
29
- circuitJson={circuitJson}
30
- editEvents={editEvents}
31
- onEditEvent={(event) => setEditEvents([...editEvents, event])}
32
- containerStyle={containerStyle}
33
- debugGrid={debugGrid}
34
- editingEnabled={editingEnabled}
35
- debug={debug}
36
- clickToInteractEnabled={clickToInteractEnabled}
37
- onSchematicComponentClicked={onSchematicComponentClicked}
38
- />
39
- )
40
- }
@@ -1,46 +0,0 @@
1
- import { zIndexMap } from "../utils/z-index-map"
2
-
3
- export const EditIcon = ({
4
- onClick,
5
- active,
6
- }: { onClick: () => void; active: boolean }) => {
7
- const handleInteraction = (e: React.MouseEvent | React.TouchEvent) => {
8
- e.preventDefault()
9
- onClick()
10
- }
11
-
12
- return (
13
- <div
14
- onClick={handleInteraction}
15
- onTouchEnd={handleInteraction}
16
- title={active ? "Disable edit mode" : "Enable edit mode"}
17
- style={{
18
- position: "absolute",
19
- top: "16px",
20
- right: "64px",
21
- backgroundColor: active ? "#4CAF50" : "#fff",
22
- color: active ? "#fff" : "#000",
23
- padding: "8px",
24
- borderRadius: "4px",
25
- cursor: "pointer",
26
- boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
27
- display: "flex",
28
- alignItems: "center",
29
- gap: "4px",
30
- zIndex: zIndexMap.schematicEditIcon,
31
- }}
32
- >
33
- <svg
34
- width="16"
35
- height="16"
36
- viewBox="0 0 24 24"
37
- fill="none"
38
- stroke="currentColor"
39
- strokeWidth="2"
40
- >
41
- <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
42
- <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" />
43
- </svg>
44
- </div>
45
- )
46
- }