feat: reactive codemirror theme
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
::-webkit-scrollbar-thumb {
|
::-webkit-scrollbar-thumb {
|
||||||
@apply bg-divider bg-clip-content;
|
@apply bg-divider bg-clip-content;
|
||||||
@apply rounded-full;
|
@apply rounded-full;
|
||||||
@apply border-solid border-4 border-transparent;
|
@apply border-solid border-transparent border-4;
|
||||||
@apply hover:(bg-dividerDark bg-clip-content);
|
@apply hover:(bg-dividerDark bg-clip-content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,8 +116,8 @@ a {
|
|||||||
|
|
||||||
&.link {
|
&.link {
|
||||||
@apply items-center;
|
@apply items-center;
|
||||||
@apply px-1 py-0.5;
|
@apply py-0.5 px-1;
|
||||||
@apply -mx-1 -my-0.5;
|
@apply -my-0.5 -mx-1;
|
||||||
@apply text-accent;
|
@apply text-accent;
|
||||||
@apply rounded;
|
@apply rounded;
|
||||||
@apply hover:text-accentDark;
|
@apply hover:text-accentDark;
|
||||||
@@ -198,7 +198,7 @@ hr {
|
|||||||
.textarea {
|
.textarea {
|
||||||
@apply flex;
|
@apply flex;
|
||||||
@apply w-full;
|
@apply w-full;
|
||||||
@apply px-4 py-2;
|
@apply py-2 px-4;
|
||||||
@apply bg-transparent;
|
@apply bg-transparent;
|
||||||
@apply rounded;
|
@apply rounded;
|
||||||
@apply text-secondaryDark;
|
@apply text-secondaryDark;
|
||||||
@@ -293,7 +293,7 @@ input[type="checkbox"] {
|
|||||||
@apply cursor-pointer;
|
@apply cursor-pointer;
|
||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
@apply border-2 border-divider;
|
@apply border-divider border-2;
|
||||||
@apply rounded;
|
@apply rounded;
|
||||||
@apply inline-flex;
|
@apply inline-flex;
|
||||||
@apply items-center;
|
@apply items-center;
|
||||||
@@ -461,6 +461,22 @@ input[type="checkbox"] {
|
|||||||
@apply w-full;
|
@apply w-full;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.CodeMirror {
|
||||||
|
@apply block;
|
||||||
|
@apply border-b;
|
||||||
|
@apply border-dividerLight;
|
||||||
|
@apply w-full;
|
||||||
|
@apply h-auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror * {
|
||||||
|
font-family: "Roboto Mono", monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-scroll {
|
||||||
|
@apply min-h-32;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 767px) {
|
@media (max-width: 767px) {
|
||||||
main {
|
main {
|
||||||
margin-bottom: env(safe-area-inset-bottom);
|
margin-bottom: env(safe-area-inset-bottom);
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ const props = withDefaults(
|
|||||||
defineProps<{
|
defineProps<{
|
||||||
value: string
|
value: string
|
||||||
mode: string
|
mode: string
|
||||||
placeholder: string
|
placeholder?: string
|
||||||
wrap: boolean
|
wrap: boolean
|
||||||
linter: LinterDefinition | null
|
linter: LinterDefinition | null
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
linter: null as any,
|
linter: null as any,
|
||||||
|
placeholder: "",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,18 +46,3 @@ useCodemirror(editor, value, {
|
|||||||
linter: props.linter,
|
linter: props.linter,
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.CodeMirror {
|
|
||||||
@apply block;
|
|
||||||
@apply border-b;
|
|
||||||
@apply border-dividerLight;
|
|
||||||
@apply w-full;
|
|
||||||
@apply h-auto;
|
|
||||||
@apply font-mono;
|
|
||||||
}
|
|
||||||
|
|
||||||
.CodeMirror-scroll {
|
|
||||||
@apply min-h-32;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import CodeMirror from "codemirror"
|
import CodeMirror from "codemirror"
|
||||||
|
|
||||||
import "codemirror/theme/juejin.css"
|
import "codemirror/theme/base16-light.css"
|
||||||
|
import "codemirror/theme/base16-dark.css"
|
||||||
|
import "codemirror/theme/3024-night.css"
|
||||||
|
|
||||||
import "codemirror/lib/codemirror.css"
|
import "codemirror/lib/codemirror.css"
|
||||||
import "codemirror/addon/lint/lint.css"
|
import "codemirror/addon/lint/lint.css"
|
||||||
@@ -20,18 +22,15 @@ import "codemirror/addon/search/searchcursor"
|
|||||||
import "codemirror/addon/search/jump-to-line"
|
import "codemirror/addon/search/jump-to-line"
|
||||||
import "codemirror/addon/dialog/dialog"
|
import "codemirror/addon/dialog/dialog"
|
||||||
|
|
||||||
import { watch, onMounted, ref, Ref } from "@nuxtjs/composition-api"
|
import { watch, onMounted, ref, Ref, useContext } from "@nuxtjs/composition-api"
|
||||||
import { LinterDefinition } from "./linting/linter"
|
import { LinterDefinition } from "./linting/linter"
|
||||||
|
|
||||||
const DEFAULT_THEME = "juejin"
|
|
||||||
|
|
||||||
type CodeMirrorOptions = {
|
type CodeMirrorOptions = {
|
||||||
extendedEditorConfig: Omit<CodeMirror.EditorConfiguration, "value">
|
extendedEditorConfig: Omit<CodeMirror.EditorConfiguration, "value">
|
||||||
linter: LinterDefinition | null
|
linter: LinterDefinition | null
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_EDITOR_CONFIG: CodeMirror.EditorConfiguration = {
|
const DEFAULT_EDITOR_CONFIG: CodeMirror.EditorConfiguration = {
|
||||||
theme: DEFAULT_THEME,
|
|
||||||
autoRefresh: true,
|
autoRefresh: true,
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
foldGutter: true,
|
foldGutter: true,
|
||||||
@@ -81,6 +80,7 @@ export function useCodemirror(
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
cm.value = CodeMirror(el.value!, DEFAULT_EDITOR_CONFIG)
|
cm.value = CodeMirror(el.value!, DEFAULT_EDITOR_CONFIG)
|
||||||
|
|
||||||
|
setTheme()
|
||||||
updateEditorConfig()
|
updateEditorConfig()
|
||||||
updateLinterConfig()
|
updateLinterConfig()
|
||||||
|
|
||||||
@@ -92,6 +92,28 @@ export function useCodemirror(
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const setTheme = () => {
|
||||||
|
const { $colorMode } = useContext() as any
|
||||||
|
if (cm.value) {
|
||||||
|
cm.value?.setOption("theme", getThemeName($colorMode.value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getThemeName = (mode: string) => {
|
||||||
|
switch (mode) {
|
||||||
|
case "system":
|
||||||
|
return "default"
|
||||||
|
case "light":
|
||||||
|
return "base16-light"
|
||||||
|
case "dark":
|
||||||
|
return "base16-dark"
|
||||||
|
case "black":
|
||||||
|
return "3024-night"
|
||||||
|
default:
|
||||||
|
return "default"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If the editor properties are reactive, watch for updates
|
// If the editor properties are reactive, watch for updates
|
||||||
watch(() => options.extendedEditorConfig, updateEditorConfig, {
|
watch(() => options.extendedEditorConfig, updateEditorConfig, {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user