Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add monaco light theme #121

Merged
merged 7 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" class="dark">
<html lang="en">
sxzz marked this conversation as resolved.
Show resolved Hide resolved
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"monaco-editor-core": "^0.38.0",
"monaco-editor-textmate": "^4.0.0",
"monaco-textmate": "^3.0.1",
"monaco-volar": "^0.3.1",
"monaco-volar": "^0.4.0",
"onigasm": "^2.2.5",
"path-browserify": "^1.0.1",
"prettier": "^2.8.8",
Expand Down
19 changes: 4 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/Repl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { EditorComponentType } from './editor/types'
import EditorContainer from './editor/EditorContainer.vue'

export interface Props {
theme: 'dark' | 'light'
editor: EditorComponentType
store?: Store
autoResize?: boolean
Expand All @@ -28,6 +29,7 @@ export interface Props {
}

const props = withDefaults(defineProps<Props>(), {
theme: 'light',
store: () => new ReplStore(),
autoResize: true,
showCompileOutput: true,
Expand Down Expand Up @@ -75,7 +77,7 @@ provide('import-map', toRef(props, 'showImportMap'))
provide('tsconfig', toRef(props, 'showTsConfig'))
provide('clear-console', toRef(props, 'clearConsole'))
provide('preview-options', props.previewOptions)

provide('theme', toRef(props, 'theme'))
/**
* Reload the preview iframe
*/
Expand Down
11 changes: 10 additions & 1 deletion src/monaco/Monaco.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getOrCreateModel } from './utils'
import { loadGrammars, loadTheme } from 'monaco-volar'
import { Store } from '../store'
import type { PreviewMode } from '../editor/types'
import { Ref } from "vue/dist/vue";

const props = withDefaults(
defineProps<{
Expand All @@ -41,6 +42,7 @@ initMonaco(store)

const lang = computed(() => (props.mode === 'css' ? 'css' : 'javascript'))

const replTheme = inject('theme') as Ref<'dark' | 'light'>
onMounted(async () => {
const theme = await loadTheme(monaco.editor)
ready.value = true
Expand All @@ -55,7 +57,7 @@ onMounted(async () => {
? { value: props.value, language: lang.value }
: { model: null }),
fontSize: 13,
theme,
theme: replTheme.value === 'light' ? theme.light : theme.dark,
readOnly: props.readonly,
automaticLayout: true,
scrollBeyondLastLine: false,
Expand Down Expand Up @@ -140,6 +142,13 @@ onMounted(async () => {
file.selection = selection
}
})

// update theme
watch(() => replTheme.value, (n) => {
editorInstance.updateOptions({
theme: n === 'light' ? theme.light : theme.dark,
})
})
})

onBeforeUnmount(() => {
Expand Down