api-client/components/smart/CodeMirror.vue

63 lines
1.1 KiB
Vue
Raw Normal View History

2021-08-30 18:33:07 +00:00
<template>
<div ref="editor" class="w-full block"></div>
</template>
2021-08-31 05:17:00 +00:00
<script setup lang="ts">
import "codemirror/mode/javascript/javascript"
2021-08-30 18:33:07 +00:00
import { ref, watch } from "@nuxtjs/composition-api"
import { useCodemirror } from "~/helpers/editor/codemirror"
2021-09-01 11:11:14 +00:00
import { LinterDefinition } from "~/helpers/editor/linting/linter"
const props = withDefaults(
defineProps<{
value: string
mode: string
placeholder: string
wrap: boolean
linter: LinterDefinition | null
}>(),
{
linter: null as any,
}
)
2021-08-31 05:17:00 +00:00
const emit = defineEmits<{
(e: "input", value: string): void
}>()
const value = ref(props.value)
2021-08-31 05:17:00 +00:00
watch(
() => props.value,
(val) => (value.value = val)
2021-08-31 05:17:00 +00:00
)
watch(value, (val) => emit("input", val))
2021-08-31 05:17:00 +00:00
const editor = ref<any | null>(null)
useCodemirror(editor, value, {
2021-09-01 11:11:14 +00:00
extendedEditorConfig: {
mode: props.mode,
placeholder: props.placeholder,
lineWrapping: props.wrap,
2021-09-01 11:11:14 +00:00
},
linter: props.linter,
2021-08-31 05:17:00 +00:00
})
2021-08-30 18:33:07 +00:00
</script>
2021-08-31 05:17:00 +00:00
<style lang="scss" scoped>
2021-08-30 18:33:07 +00:00
.CodeMirror {
@apply block;
@apply border-b;
@apply border-dividerLight;
@apply w-full;
2021-08-31 05:17:00 +00:00
@apply h-auto;
@apply font-mono;
2021-08-31 05:17:00 +00:00
}
.CodeMirror-scroll {
@apply min-h-32;
2021-08-30 18:33:07 +00:00
}
</style>