feat: implement reactive theming
This commit is contained in:
@@ -49,6 +49,7 @@ import { isJSONContentType } from "../utils/contenttypes"
|
|||||||
import { Completer } from "./completion"
|
import { Completer } from "./completion"
|
||||||
import { LinterDefinition } from "./linting/linter"
|
import { LinterDefinition } from "./linting/linter"
|
||||||
import baseTheme from "./themes/baseTheme"
|
import baseTheme from "./themes/baseTheme"
|
||||||
|
import { HoppBgColor } from "~/newstore/settings"
|
||||||
|
|
||||||
type CodeMirrorOptions = {
|
type CodeMirrorOptions = {
|
||||||
extendedEditorConfig: Omit<CodeMirror.EditorConfiguration, "value">
|
extendedEditorConfig: Omit<CodeMirror.EditorConfiguration, "value">
|
||||||
@@ -320,13 +321,24 @@ const getEditorLanguage = (
|
|||||||
O.getOrElseW(() => [])
|
O.getOrElseW(() => [])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const getThemeExt = (mode: HoppBgColor) => {
|
||||||
|
// TODO: Implement more themes here
|
||||||
|
switch (mode) {
|
||||||
|
default:
|
||||||
|
return baseTheme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function useNewCodemirror(
|
export function useNewCodemirror(
|
||||||
el: Ref<any | null>,
|
el: Ref<any | null>,
|
||||||
value: Ref<string>,
|
value: Ref<string>,
|
||||||
options: CodeMirrorOptions
|
options: CodeMirrorOptions
|
||||||
): { cursor: Ref<{ line: number; ch: number }> } {
|
): { cursor: Ref<{ line: number; ch: number }> } {
|
||||||
|
const { $colorMode } = useContext() as any
|
||||||
|
|
||||||
const language = new Compartment()
|
const language = new Compartment()
|
||||||
const lineWrapping = new Compartment()
|
const lineWrapping = new Compartment()
|
||||||
|
const theming = new Compartment()
|
||||||
|
|
||||||
const cachedCursor = ref({
|
const cachedCursor = ref({
|
||||||
line: 0,
|
line: 0,
|
||||||
@@ -342,7 +354,7 @@ export function useNewCodemirror(
|
|||||||
doc: value.value,
|
doc: value.value,
|
||||||
extensions: [
|
extensions: [
|
||||||
basicSetup,
|
basicSetup,
|
||||||
baseTheme,
|
theming.of(getThemeExt($colorMode.value)),
|
||||||
ViewPlugin.fromClass(
|
ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
update(update: ViewUpdate) {
|
update(update: ViewUpdate) {
|
||||||
@@ -453,6 +465,15 @@ export function useNewCodemirror(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => $colorMode.value,
|
||||||
|
(newVal) => {
|
||||||
|
dispatch({
|
||||||
|
effects: theming.reconfigure(getThemeExt(newVal)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
watch(el, (newEl) => {
|
watch(el, (newEl) => {
|
||||||
if (view.value) {
|
if (view.value) {
|
||||||
view.value.destroy()
|
view.value.destroy()
|
||||||
|
|||||||
Reference in New Issue
Block a user