mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 13:57:02 +08:00
fix(editor): init default theme observer value according to data-theme (#9698)
This commit is contained in:
@@ -161,10 +161,17 @@ export class ThemeService extends Extension {
|
||||
export class ThemeObserver {
|
||||
private readonly observer: MutationObserver;
|
||||
|
||||
theme$ = signal(ColorScheme.Light);
|
||||
theme$: Signal<ColorScheme>;
|
||||
|
||||
constructor() {
|
||||
const COLOR_SCHEMES: string[] = Object.values(ColorScheme);
|
||||
// Set initial theme according to the data-theme attribute
|
||||
const initialMode = document.documentElement.dataset.theme;
|
||||
this.theme$ = signal(
|
||||
initialMode && COLOR_SCHEMES.includes(initialMode)
|
||||
? (initialMode as ColorScheme)
|
||||
: ColorScheme.Light
|
||||
);
|
||||
this.observer = new MutationObserver(() => {
|
||||
const mode = document.documentElement.dataset.theme;
|
||||
if (!mode) return;
|
||||
|
||||
Reference in New Issue
Block a user