11<script setup lang="ts">
2- import { onMounted , ref , shallowRef , watch } from ' vue'
3- import { type DatabasePageItem , type DraftItem , DraftStatus } from ' ../../types'
2+ import { computed , onMounted , ref , shallowRef , watch } from ' vue'
3+ import { ContentFileExtension , type DatabasePageItem , type DraftItem , DraftStatus } from ' ../../types'
44import type { PropType } from ' vue'
55import { generateContentFromDocument , generateDocumentFromContent , pickReservedKeysFromDocument } from ' ../../utils/content'
66import { setupMonaco , setupSuggestion , type Editor } from ' ../../utils/monaco'
@@ -35,6 +35,20 @@ watch(() => props.draftItem.status, (newStatus) => {
3535 }
3636})
3737
38+ const language = computed (() => {
39+ switch (document .value ?.extension ) {
40+ case ContentFileExtension .Markdown :
41+ return ' mdc' ;
42+ case ContentFileExtension .YAML :
43+ case ContentFileExtension .YML :
44+ return ' yaml' ;
45+ case ContentFileExtension .JSON :
46+ return ' javascript' ;
47+ default :
48+ return ' text'
49+ }
50+ })
51+
3852// Trigger on document changes
3953watch (() => document .value ?.id , async () => {
4054 if (document .value ?.body ) {
@@ -48,7 +62,7 @@ onMounted(async () => {
4862
4963 // create a Monaco editor instance
5064 editor .value = monaco .createEditor (editorRef .value , {
51- // theme: ui.colorMode.value === 'light' ? 'vs ' : 'vs -dark',
65+ theme: ui .colorMode .value === ' light' ? ' vitesse-light ' : ' vitesse -dark' ,
5266 lineNumbers: ' off' ,
5367 readOnly: props .readOnly ,
5468 scrollbar: props .readOnly
@@ -89,14 +103,14 @@ onMounted(async () => {
89103 })
90104
91105 // create and attach a model to the editor
92- editor .value .setModel (monaco .editor .createModel (content .value , ' mdc ' ))
106+ editor .value .setModel (monaco .editor .createModel (content .value , language . value ))
93107
94108 // Set the theme based on the color mode
95- // watch(ui.colorMode, () => {
96- // editor.value?.updateOptions({
97- // theme: ui.colorMode.value === 'light' ? 'vs ' : 'vs -dark',
98- // })
99- // })
109+ watch (ui .colorMode , () => {
110+ editor .value ?.updateOptions ({
111+ theme: ui .colorMode .value === ' light' ? ' vitesse-light ' : ' vitesse -dark' ,
112+ })
113+ })
100114})
101115
102116function setContent(document : DatabasePageItem ) {
0 commit comments