Skip to content

Commit

Permalink
fix code editor scrolling (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar authored Oct 11, 2024
1 parent 8be8e80 commit 4f9539d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/components/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const CodeEditor = ({
ata(`
import React from "@types/react/jsx-runtime"
import { Circuit } from "@tscircuit/core"
import type { CommonLayoutProps } from "@tscircuit/props"
${code}
`)

Expand Down Expand Up @@ -140,5 +141,14 @@ ${code}
return <div className="font-mono whitespace-pre-wrap text-xs">{code}</div>
}

return <div ref={editorRef} style={{ height: "640px", width: "100%" }} />
return (
<div
ref={editorRef}
style={{
height: "640px",
width: "100%",
overflow: "auto",
}}
/>
)
}
10 changes: 7 additions & 3 deletions src/hooks/use-run-tsx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,17 @@ export const useRunTsx = ({

const module = evalCompiledJs(compiledJs!)

if (Object.keys(module.exports).length > 1) {
const componentExportKeys = Object.keys(module.exports).filter(
(key) => !key.startsWith("use"),
)

if (componentExportKeys.length > 1) {
throw new Error(
`Too many exports, only export one thing. You exported: ${JSON.stringify(Object.keys(module.exports))}`,
`Too many exports, only export one component. You exported: ${JSON.stringify(Object.keys(module.exports))}`,
)
}

const primaryKey = Object.keys(module.exports)[0]
const primaryKey = componentExportKeys[0]

const UserElm = (props: any) =>
React.createElement(module.exports[primaryKey], props)
Expand Down

0 comments on commit 4f9539d

Please sign in to comment.