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

@@ -14,6 +14,7 @@
}, },
"dependencies": { "dependencies": {
"@material-ui/core": "^4.11.0", "@material-ui/core": "^4.11.0",
"@monaco-editor/react": "^4.0.11",
"@redwoodjs/auth": "^0.26.2", "@redwoodjs/auth": "^0.26.2",
"@redwoodjs/forms": "^0.26.2", "@redwoodjs/forms": "^0.26.2",
"@redwoodjs/router": "^0.26.2", "@redwoodjs/router": "^0.26.2",

View File

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

View File

@@ -1,28 +1,20 @@
import { useContext } from 'react' import { useContext } from 'react'
import { IdeContext } from 'src/components/IdeToolbarNew' import { IdeContext } from 'src/components/IdeToolbarNew'
import Editor from '@monaco-editor/react'
const IdeEditor = () => { const IdeEditor = () => {
const { state, dispatch } = useContext(IdeContext) const { state, dispatch } = useContext(IdeContext)
function handleCodeChange(value, _event) {
dispatch({ type: 'updateCode', payload: target.value })
}
return ( return (
<div className="p-8 border-2 m-2"> <Editor
<div>hi I'm editor</div> defaultValue={ state.code }
<div className="pb-2">code:</div> defaultLanguage='javascript'
<input onChange={ handleCodeChange }
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>
) )
} }

View File

@@ -7,6 +7,7 @@ export const IdeContext = createContext()
const IdeToolbarNew = () => { const IdeToolbarNew = () => {
const [state, dispatch] = useIdeState() const [state, dispatch] = useIdeState()
function setIdeType(ide) { dispatch({ type: 'setIdeType', payload: { message: ide } }) } function setIdeType(ide) { dispatch({ type: 'setIdeType', payload: { message: ide } }) }
function handleRender() { dispatch({ type: 'render', payload: { code: state.code } }) }
return ( return (
<IdeContext.Provider value={{ state, dispatch }}> <IdeContext.Provider value={{ state, dispatch }}>
@@ -15,6 +16,7 @@ const IdeToolbarNew = () => {
<nav class="flex"> <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('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={() => 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> </nav>
<IdeContainer /> <IdeContainer />
</div> </div>

View File

@@ -96,3 +96,8 @@ label {
input.error, textarea.error { input.error, textarea.error {
border: 1px solid red; border: 1px solid red;
} }
/* used in IdeContainer component */
#cadhub-ide .mosaic-window.console .mosaic-window-body {
overflow-y: auto;
}

View File

@@ -2102,6 +2102,22 @@
prop-types "^15.7.2" prop-types "^15.7.2"
react-is "^16.8.0" react-is "^16.8.0"
"@monaco-editor/loader@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@monaco-editor/loader/-/loader-1.0.0.tgz#c7ea78ef07cebcae83d92bbfe2bddab563468102"
integrity sha512-CA35bf5Y7wFWfeJZfkLslOxiatln3oTBKkfbdo+TF5H+UdPP96qHvhOUjjd1DeQ2NWsRkVPSnoSYek7NE5B26w==
dependencies:
state-local "^1.0.6"
"@monaco-editor/react@^4.0.11":
version "4.0.11"
resolved "https://registry.yarnpkg.com/@monaco-editor/react/-/react-4.0.11.tgz#e5f9f651988f2f73ac776ffb8391e81d121d5c32"
integrity sha512-IxGpfvCx9p5bTI+T8i7KPbvqsNppUYMT6xA6u65BKmI3/mrlRVFdDyzZTcd+SAAs+5n7n0m/gzAoeglUL+lWDQ==
dependencies:
"@monaco-editor/loader" "^1.0.0"
prop-types "^15.7.2"
state-local "^1.0.7"
"@mrmlnc/readdir-enhanced@^2.2.1": "@mrmlnc/readdir-enhanced@^2.2.1":
version "2.2.1" version "2.2.1"
resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde" resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"
@@ -15484,6 +15500,11 @@ stackframe@^1.1.1:
resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-1.2.0.tgz#52429492d63c62eb989804c11552e3d22e779303" resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-1.2.0.tgz#52429492d63c62eb989804c11552e3d22e779303"
integrity sha512-GrdeshiRmS1YLMYgzF16olf2jJ/IzxXY9lhKOskuVziubpTYcYqyOwYeJKzQkwy7uN0fYSsbsC4RQaXf9LCrYA== integrity sha512-GrdeshiRmS1YLMYgzF16olf2jJ/IzxXY9lhKOskuVziubpTYcYqyOwYeJKzQkwy7uN0fYSsbsC4RQaXf9LCrYA==
state-local@^1.0.6, state-local@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/state-local/-/state-local-1.0.7.tgz#da50211d07f05748d53009bee46307a37db386d5"
integrity sha512-HTEHMNieakEnoe33shBYcZ7NX83ACUjCu8c40iOGEZsngj9zRnkqS9j1pqQPXwobB0ZcVTk27REb7COQ0UR59w==
static-extend@^0.1.1: static-extend@^0.1.1:
version "0.1.2" version "0.1.2"
resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6" resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6"