Skip to content

Commit ead9667

Browse files
baiwusanyu-csxzz
andauthored
feat: add monaco light theme (#121)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
1 parent 189115b commit ead9667

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"monaco-editor-core": "^0.38.0",
6666
"monaco-editor-textmate": "^4.0.0",
6767
"monaco-textmate": "^3.0.1",
68-
"monaco-volar": "^0.3.1",
68+
"monaco-volar": "^0.4.0",
6969
"onigasm": "^2.2.5",
7070
"path-browserify": "^1.0.1",
7171
"prettier": "^2.8.8",

pnpm-lock.yaml

Lines changed: 4 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Repl.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { EditorComponentType } from './editor/types'
77
import EditorContainer from './editor/EditorContainer.vue'
88
99
export interface Props {
10+
theme?: 'dark' | 'light'
1011
editor: EditorComponentType
1112
store?: Store
1213
autoResize?: boolean
@@ -28,6 +29,7 @@ export interface Props {
2829
}
2930
3031
const props = withDefaults(defineProps<Props>(), {
32+
theme: 'light',
3133
store: () => new ReplStore(),
3234
autoResize: true,
3335
showCompileOutput: true,
@@ -75,7 +77,7 @@ provide('import-map', toRef(props, 'showImportMap'))
7577
provide('tsconfig', toRef(props, 'showTsConfig'))
7678
provide('clear-console', toRef(props, 'clearConsole'))
7779
provide('preview-options', props.previewOptions)
78-
80+
provide('theme', toRef(props, 'theme'))
7981
/**
8082
* Reload the preview iframe
8183
*/

src/monaco/Monaco.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
inject,
99
watch,
1010
computed,
11+
type Ref,
1112
} from 'vue'
1213
import * as monaco from 'monaco-editor-core'
1314
import { initMonaco } from './env'
@@ -41,6 +42,7 @@ initMonaco(store)
4142
4243
const lang = computed(() => (props.mode === 'css' ? 'css' : 'javascript'))
4344
45+
const replTheme = inject<Ref<'dark' | 'light'>>('theme')!
4446
onMounted(async () => {
4547
const theme = await loadTheme(monaco.editor)
4648
ready.value = true
@@ -55,7 +57,7 @@ onMounted(async () => {
5557
? { value: props.value, language: lang.value }
5658
: { model: null }),
5759
fontSize: 13,
58-
theme,
60+
theme: replTheme.value === 'light' ? theme.light : theme.dark,
5961
readOnly: props.readonly,
6062
automaticLayout: true,
6163
scrollBeyondLastLine: false,
@@ -140,6 +142,13 @@ onMounted(async () => {
140142
file.selection = selection
141143
}
142144
})
145+
146+
// update theme
147+
watch(replTheme, (n) => {
148+
editorInstance.updateOptions({
149+
theme: n === 'light' ? theme.light : theme.dark,
150+
})
151+
})
143152
})
144153
145154
onBeforeUnmount(() => {

test/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const App = {
4242
return () =>
4343
h(Repl, {
4444
store,
45+
theme: 'dark',
4546
editor: MonacoEditor as any as EditorComponentType,
4647
// layout: 'vertical',
4748
ssr: true,

0 commit comments

Comments
 (0)