22import FileSelector from ' ./FileSelector.vue'
33import Message from ' ../Message.vue'
44import { debounce } from ' ../utils'
5- import { inject , ref , watch } from ' vue'
5+ import { inject , ref , useTemplateRef , watch } from ' vue'
66import ToggleButton from ' ./ToggleButton.vue'
7- import { type EditorComponentType , injectKeyProps } from ' ../types'
7+ import {
8+ type EditorComponentType ,
9+ type EditorMethods ,
10+ injectKeyProps ,
11+ } from ' ../types'
812
913const SHOW_ERROR_KEY = ' repl_show_error'
1014
@@ -14,6 +18,7 @@ const props = defineProps<{
1418
1519const { store, autoSave, editorOptions } = inject (injectKeyProps )!
1620const showMessage = ref (getItem ())
21+ const editorRef = useTemplateRef <EditorMethods >(' editor' )
1722
1823const onChange = debounce ((code : string ) => {
1924 store .value .activeFile .code = code
@@ -25,18 +30,25 @@ function setItem() {
2530
2631function getItem() {
2732 const item = localStorage .getItem (SHOW_ERROR_KEY )
28- return ! ( item === ' false' )
33+ return item !== ' false'
2934}
3035
3136watch (showMessage , () => {
3237 setItem ()
3338})
39+
40+ defineExpose ({
41+ getEditorIns: (() =>
42+ editorRef .value ?.getEditorIns ?.()) as EditorMethods [' getEditorIns' ],
43+ getMonacoEditor : () => editorRef .value ?.getMonacoEditor ?.(),
44+ })
3445 </script >
3546
3647<template >
3748 <FileSelector />
3849 <div class =" editor-container" >
3950 <props .editorComponent
51+ ref =" editor"
4052 :value =" store.activeFile.code"
4153 :filename =" store.activeFile.filename"
4254 @change =" onChange"
0 commit comments