Added initial Monaco Editor to dev-ide, made console pane scrollable

This commit is contained in:
Frank Noirot
2021-03-10 00:55:14 -05:00
parent 384d8231e8
commit 7410efada0
6 changed files with 42 additions and 21 deletions

View File

@@ -15,10 +15,10 @@ const ELEMENT_MAP = {
const IdeContainer = () => {
const { state, dispatch } = useContext(IdeContext)
return (<div className='h-screen'>
return (<div id='cadhub-ide' className='h-screen'>
<Mosaic
renderTile={ (id, path) => (
<MosaicWindow path={path} title={id}>
<MosaicWindow path={path} title={id} className={id.toLowerCase()}>
{ ELEMENT_MAP[id] }
</MosaicWindow>
)}

View File

@@ -1,28 +1,20 @@
import { useContext } from 'react'
import { IdeContext } from 'src/components/IdeToolbarNew'
import Editor from '@monaco-editor/react'
const IdeEditor = () => {
const { state, dispatch } = useContext(IdeContext)
function handleCodeChange(value, _event) {
dispatch({ type: 'updateCode', payload: target.value })
}
return (
<div className="p-8 border-2 m-2">
<div>hi I'm editor</div>
<div className="pb-2">code:</div>
<input
value={state.code}
className="font-mono"
onChange={({ target }) =>
dispatch({ type: 'updateCode', payload: target.value })
}
/>
<button
onClick={() =>
dispatch({ type: 'render', payload: { code: state.code } })
}
className="m-2 border-2 shadow-md p-2 rounded"
>
Render plz
</button>
</div>
<Editor
defaultValue={ state.code }
defaultLanguage='javascript'
onChange={ handleCodeChange }
/>
)
}

View File

@@ -7,6 +7,7 @@ export const IdeContext = createContext()
const IdeToolbarNew = () => {
const [state, dispatch] = useIdeState()
function setIdeType(ide) { dispatch({ type: 'setIdeType', payload: { message: ide } }) }
function handleRender() { dispatch({ type: 'render', payload: { code: state.code } }) }
return (
<IdeContext.Provider value={{ state, dispatch }}>
@@ -15,6 +16,7 @@ const IdeToolbarNew = () => {
<nav class="flex">
<button onClick={() => setIdeType('openCascade')} class="p-2 br-2 border-2 m-2 bg-blue-200">Switch to OpenCascade</button>
<button onClick={() => setIdeType('openScad')} class="p-2 br-2 border-2 m-2 bg-indigo-200">Switch to OpenSCAD</button>
<button onClick={ handleRender } class="p-2 br-2 border-2 m-2">Render</button>
</nav>
<IdeContainer />
</div>