add helper

This commit is contained in:
2024-01-24 11:50:18 +08:00
parent a3d70af23c
commit 98fd6081a0
4 changed files with 66 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ import { useDark } from "@vueuse/core"
import { Codemirror } from "vue-codemirror"
import { cpp } from "@codemirror/lang-cpp"
import { python } from "@codemirror/lang-python"
import { EditorState } from "@codemirror/state"
import { EditorView } from "@codemirror/view"
import { LANGUAGE } from "../types"
import { oneDark } from "../themes/oneDark"
@@ -35,7 +36,7 @@ const styleTheme = EditorView.baseTheme({
outline: "none",
},
})
const emit = defineEmits(["update:modelValue"])
const emit = defineEmits(["update:modelValue", "ready"])
watch(
() => props.modelValue,
@@ -54,6 +55,14 @@ const lang = computed(() => {
function onChange(v: string) {
emit("update:modelValue", v)
}
function onReady(payload: {
view: EditorView
state: EditorState
container: HTMLDivElement
}) {
emit("ready", payload.view)
}
</script>
<template>
<n-flex align="center" class="header" v-if="props.label">
@@ -72,6 +81,7 @@ function onChange(v: string) {
fontSize: props.fontSize + 'px',
}"
@change="onChange"
@ready="onReady"
/>
</template>
<style scoped>