CodeEditor.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <PrismEditor v-model="code" max-h-xl class="form-design-editor" :highlight="(code:any)=>{return highlight(code,languages[language])}" :readonly="readonly" line-numbers />
  3. </template>
  4. <script lang="ts" setup>
  5. import { PrismEditor } from 'vue-prism-editor'
  6. import 'vue-prism-editor/dist/prismeditor.min.css'
  7. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  8. // @ts-expect-error
  9. import { highlight, languages } from 'prismjs/components/prism-core'
  10. import 'prismjs/components/prism-clike'
  11. import 'prismjs/components/prism-json'
  12. import 'prismjs/themes/prism-tomorrow.css'
  13. const { language = 'json', modelValue = '', readonly = false } = defineProps<{
  14. modelValue: string
  15. language?: string
  16. readonly?: boolean
  17. }>()
  18. const emit = defineEmits(['update:modelValue'])
  19. const code = $computed<string>({
  20. get() { return modelValue },
  21. set(val) { emit('update:modelValue', val) },
  22. })
  23. </script>
  24. <style lang="scss">
  25. .form-design-editor {
  26. box-sizing: border-box;
  27. padding: 10px;
  28. /* you must provide font-family font-size line-height. Example: */
  29. font-family: "Fira code", "Fira Mono", Consolas, Menlo, Courier, monospace;
  30. font-size: 14px;
  31. line-height: 1.5;
  32. color: #ccc;
  33. /* we dont use `language-` classes anymore so thats why we need to add background and text color manually */
  34. background: #2d2d2d;
  35. /* optional class for removing the outline */
  36. .prism-editor__textarea:focus {
  37. outline: none;
  38. }
  39. .prism-editor__line-numbers {
  40. user-select: none;
  41. }
  42. }
  43. </style>