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 all 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 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 @@ -8,6 +8,7 @@ import {
inject,
watch,
computed,
type Ref,
} from 'vue'
import * as monaco from 'monaco-editor-core'
import { initMonaco } from './env'
Expand Down Expand Up @@ -41,6 +42,7 @@ initMonaco(store)

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

const replTheme = inject<Ref<'dark' | 'light'>>('theme')!
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, (n) => {
editorInstance.updateOptions({
theme: n === 'light' ? theme.light : theme.dark,
})
})
})

onBeforeUnmount(() => {
Expand Down
1 change: 1 addition & 0 deletions test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const App = {
return () =>
h(Repl, {
store,
theme: 'dark',
editor: MonacoEditor as any as EditorComponentType,
// layout: 'vertical',
ssr: true,
Expand Down