repl icon indicating copy to clipboard operation
repl copied to clipboard

feat(repl): `getEditorInstance`, `getMonacoEditor` (expose)

Open wangcch opened this issue 4 months ago • 2 comments

close https://github.com/vuejs/repl/issues/335

Repl methods getEditorInstance: get monaco/codemirror editor instance getMonacoEditor: get editor from monaco-editor-core

export interface EditorMethods {
  getEditorIns<T extends 'monaco' | 'codemirror' = 'monaco'>():
    | (T extends 'codemirror'
        ? CodeMirror.Editor
        : monaco.editor.IStandaloneCodeEditor)
    | undefined
  getMonacoEditor?(): typeof monaco.editor | undefined
}

usage

onMounted(() => {
  const editor = repl.value?.getEditorInstance<'monaco'>()
  const monacoEditor = repl.value?.getMonacoEditor()

  monacoEditor?.defineTheme('my-dark', {
    base: 'vs-dark',
    inherit: true,
    rules: [],
    colors: {
      'editor.background': '#ff0000',
    },
  })

  editor?.updateOptions({
    theme: 'my-dark',
  })
})
<script setup lang="ts">
const repl = useTemplateRef('repl')
</script>

<template>
  <Repl ref="repl" />
</template>
const repl = ref<InstanceType<typeof Repl>>()

wangcch avatar Sep 12 '25 09:09 wangcch

@wangcch is attempting to deploy a commit to the vuejs Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Sep 12 '25 09:09 vercel[bot]

Open in StackBlitz

npm i https://pkg.pr.new/@vue/repl@364

commit: d0c2d2d

pkg-pr-new[bot] avatar Sep 12 '25 09:09 pkg-pr-new[bot]