@@ -8,9 +8,7 @@ import type * as MonacoTypes from "monaco-editor/esm/vs/editor/editor.api";
88import { configureMonacoYaml } from "monaco-yaml" ;
99import React , { useMemo , useRef } from "react" ;
1010
11- import { RpcApi } from "@/app/store/wshclientapi" ;
12- import { TabRpcClient } from "@/app/store/wshrpcutil" ;
13- import { boundNumber , makeConnRoute } from "@/util/util" ;
11+ import { boundNumber } from "@/util/util" ;
1412import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker" ;
1513import cssWorker from "monaco-editor/esm/vs/language/css/css.worker?worker" ;
1614import htmlWorker from "monaco-editor/esm/vs/language/html/html.worker?worker" ;
@@ -19,7 +17,6 @@ import tsWorker from "monaco-editor/esm/vs/language/typescript/ts.worker?worker"
1917import { SchemaEndpoints , getSchemaEndpointInfo } from "./schemaendpoints" ;
2018import ymlWorker from "./yamlworker?worker" ;
2119
22-
2320// there is a global monaco variable (TODO get the correct TS type)
2421declare var monaco : Monaco ;
2522
@@ -109,23 +106,21 @@ function defaultEditorOptions(): MonacoTypes.editor.IEditorOptions {
109106interface CodeEditorProps {
110107 blockId : string ;
111108 text : string ;
112- filename : string ;
113- fileinfo : FileInfo ;
109+ readonly : boolean ;
114110 language ?: string ;
115- meta ?: MetaType ;
116111 onChange ?: ( text : string ) => void ;
117112 onMount ?: ( monacoPtr : MonacoTypes . editor . IStandaloneCodeEditor , monaco : Monaco ) => ( ) => void ;
118113}
119114
120- export function CodeEditor ( { blockId, text, language, filename , fileinfo , meta , onChange, onMount } : CodeEditorProps ) {
115+ export function CodeEditor ( { blockId, text, language, readonly , onChange, onMount } : CodeEditorProps ) {
121116 const divRef = useRef < HTMLDivElement > ( null ) ;
122117 const unmountRef = useRef < ( ) => void > ( null ) ;
123118 const minimapEnabled = useOverrideConfigAtom ( blockId , "editor:minimapenabled" ) ?? false ;
124119 const stickyScrollEnabled = useOverrideConfigAtom ( blockId , "editor:stickyscrollenabled" ) ?? false ;
125120 const wordWrap = useOverrideConfigAtom ( blockId , "editor:wordwrap" ) ?? false ;
126121 const fontSize = boundNumber ( useOverrideConfigAtom ( blockId , "editor:fontsize" ) , 6 , 64 ) ;
127122 const theme = "wave-theme-dark" ;
128- const [ absPath , setAbsPath ] = React . useState ( "" ) ;
123+ const editorPath = useRef ( crypto . randomUUID ( ) ) . current ;
129124
130125 React . useEffect ( ( ) => {
131126 return ( ) => {
@@ -136,24 +131,6 @@ export function CodeEditor({ blockId, text, language, filename, fileinfo, meta,
136131 } ;
137132 } , [ ] ) ;
138133
139- React . useEffect ( ( ) => {
140- const inner = async ( ) => {
141- try {
142- const fileInfo = await RpcApi . RemoteFileJoinCommand ( TabRpcClient , [ filename ] , {
143- route : makeConnRoute ( meta . connection ?? "" ) ,
144- } ) ;
145- setAbsPath ( fileInfo . path ) ;
146- } catch ( e ) {
147- setAbsPath ( filename ) ;
148- }
149- } ;
150- inner ( ) ;
151- } , [ filename ] ) ;
152-
153- React . useEffect ( ( ) => {
154- console . log ( "abspath is" , absPath ) ;
155- } , [ absPath ] ) ;
156-
157134 function handleEditorChange ( text : string , ev : MonacoTypes . editor . IModelContentChangedEvent ) {
158135 if ( onChange ) {
159136 onChange ( text ) ;
@@ -168,13 +145,13 @@ export function CodeEditor({ blockId, text, language, filename, fileinfo, meta,
168145
169146 const editorOpts = useMemo ( ( ) => {
170147 const opts = defaultEditorOptions ( ) ;
171- opts . readOnly = fileinfo . readonly ;
148+ opts . readOnly = readonly ;
172149 opts . minimap . enabled = minimapEnabled ;
173150 opts . stickyScroll . enabled = stickyScrollEnabled ;
174151 opts . wordWrap = wordWrap ? "on" : "off" ;
175152 opts . fontSize = fontSize ;
176153 return opts ;
177- } , [ minimapEnabled , stickyScrollEnabled , wordWrap , fontSize , fileinfo . readonly ] ) ;
154+ } , [ minimapEnabled , stickyScrollEnabled , wordWrap , fontSize , readonly ] ) ;
178155
179156 return (
180157 < div className = "flex flex-col w-full h-full overflow-hidden items-center justify-center" >
@@ -185,7 +162,7 @@ export function CodeEditor({ blockId, text, language, filename, fileinfo, meta,
185162 options = { editorOpts }
186163 onChange = { handleEditorChange }
187164 onMount = { handleEditorOnMount }
188- path = { absPath }
165+ path = { editorPath }
189166 language = { language }
190167 />
191168 </ div >
0 commit comments