Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@cashscript/utils": "^0.12.0",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@monaco-editor/react": "^3.6.2",
"@monaco-editor/react": "^4.7.0",
"bootstrap": "^5.3.7",
"cashc": "^0.12.0",
"cashscript": "^0.12.0",
Expand All @@ -30,6 +30,7 @@
"@types/react-dom": "18.0.11",
"eslint": "^9.36.0",
"eslint-config-next": "^15.5.4",
"monaco-editor": "^0.52.2",
"typescript": "^5.9.3"
}
}
25 changes: 18 additions & 7 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { useState } from 'react'
import { ControlledEditor } from '@monaco-editor/react'
import React, { useState, useEffect } from 'react'
import MonacoEditor, { loader } from '@monaco-editor/react'
import { Button } from 'react-bootstrap'
import { ColumnFlex } from './shared'
import { setupCashScriptLanguage, CASHSCRIPT_LANGUAGE_ID } from '@/editor/cashscript'
import type * as Monaco from 'monaco-editor'

interface Props {
code: string
Expand All @@ -11,8 +13,17 @@ interface Props {

const Editor: React.FC<Props> = ({ code, setCode, compile }) => {
const [isEditorReady, setIsEditorReady] = useState(false)
const [isLanguageReady, setIsLanguageReady] = useState(false)

function handleEditorDidMount() {
// Initialize CashScript language support
useEffect(() => {
loader.init().then((monacoInstance: typeof Monaco) => {
setupCashScriptLanguage(monacoInstance)
setIsLanguageReady(true)
})
}, [])

function handleEditorMount() {
setIsEditorReady(true)
}

Expand All @@ -21,12 +32,12 @@ const Editor: React.FC<Props> = ({ code, setCode, compile }) => {
id="editor"
style={{ flex: 3, margin: '16px', border: '2px solid black', background: 'white' }}
>
<ControlledEditor
language="sol"
<MonacoEditor
language={isLanguageReady ? CASHSCRIPT_LANGUAGE_ID : 'plaintext'}
value={code}
theme="light"
onChange={(ev: any, code?: string) => setCode(code?? "") }
editorDidMount={handleEditorDidMount}
onChange={(value) => setCode(value ?? "")}
onMount={handleEditorMount}
/>
<Button
variant="secondary"
Expand Down
Loading