Skip to content

Commit

Permalink
initial runframe implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Dec 11, 2024
1 parent a3b217b commit 504a580
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
Binary file modified bun.lockb
Binary file not shown.
14 changes: 14 additions & 0 deletions examples/runframe1-basic.fixture.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { RunFrame } from "lib/components/RunFrame"

export default () => (
<RunFrame
fsMap={{
"main.tsx": `
circuit.add(
<resistor resistance="1k" />
)
`,
}}
entrypoint="main.tsx"
/>
)
56 changes: 54 additions & 2 deletions lib/components/RunFrame.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
export const RunFrame = () => {
return <div>hello</div>
import { createCircuitWebWorker } from "@tscircuit/eval-webworker"
import { CircuitJsonPreview } from "./CircuitJsonPreview"
import { useEffect, useState } from "react"

interface Props {
/**
* Map of filenames to file contents that will be available in the worker
*/
fsMap: { [filename: string]: string }

/**
* The entry point file that will be executed first
*/
entrypoint: string

/**
* Called when the circuit JSON changes
*/
onCircuitJsonChange?: (circuitJson: any) => void

/**
* Called when rendering is finished
*/
onRenderingFinished?: (params: { circuitJson: any }) => void

/**
* Called for each render event
*/
onRenderEvent?: (event: any) => void

/**
* Called when an error occurs
*/
onError?: (error: Error) => void
}

export const RunFrame = (props: Props) => {
const [circuitJson, setCircuitJson] = useState<any>(null)

useEffect(() => {
async function runWorker() {
const worker = await createCircuitWebWorker({})
const $finished = worker.executeWithFsMap({
entrypoint: props.entrypoint,
fsMap: props.fsMap,
})
setCircuitJson(await worker.getCircuitJson())
await $finished
setCircuitJson(await worker.getCircuitJson())
}
runWorker()
}, [props.fsMap])

return <CircuitJsonPreview circuitJson={circuitJson} />
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
"@radix-ui/react-icons": "^1.3.2",
"@radix-ui/react-tabs": "^1.1.1",
"@tscircuit/3d-viewer": "^0.0.46",
"@tscircuit/eval-webworker": "^0.0.4",
"@tscircuit/eval-webworker": "^0.0.8",
"@tscircuit/pcb-viewer": "^1.10.21",
"@tscircuit/schematic-viewer": "2.0.3",
"comlink": "^4.4.2",
"cssnano": "^7.0.6",
"lucide-react": "^0.468.0",
"react-cosmos-plugin-vite": "^6.2.0",
Expand Down

0 comments on commit 504a580

Please sign in to comment.