fix(dees-editor-bare): make Monaco editor follow domtools theme and clean up theme subscription on disconnect

This commit is contained in:
2025-12-30 13:57:51 +00:00
parent 9972029643
commit 5cb41f3368
3 changed files with 31 additions and 2 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@design.estate/dees-catalog',
version: '3.12.1',
version: '3.12.2',
description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
}

View File

@@ -46,6 +46,8 @@ export class DeesEditorBare extends DeesElement {
})
accessor wordWrap: monaco.editor.IStandaloneEditorConstructionOptions['wordWrap'] = 'off';
private monacoThemeSubscription: domtools.plugins.smartrx.rxjs.Subscription | null = null;
constructor() {
super();
domtools.DomTools.setupDomTools();
@@ -102,15 +104,27 @@ export class DeesEditorBare extends DeesElement {
paths: { vs: `${monacoCdnBase}/min/vs` },
});
(window as any).require(['vs/editor/editor.main'], async () => {
// Get current theme from domtools
const domtoolsInstance = await this.domtoolsPromise;
const isBright = domtoolsInstance.themeManager.goBrightBoolean;
const initialTheme = isBright ? 'vs' : 'vs-dark';
const editor = ((window as any).monaco.editor as typeof monaco.editor).create(container, {
value: this.content,
language: this.language,
theme: 'vs-dark',
theme: initialTheme,
useShadowDOM: true,
fontSize: 16,
automaticLayout: true,
wordWrap: this.wordWrap
});
// Subscribe to theme changes
this.monacoThemeSubscription = domtoolsInstance.themeManager.themeObservable.subscribe((goBright: boolean) => {
const newTheme = goBright ? 'vs' : 'vs-dark';
editor.updateOptions({ theme: newTheme });
});
this.editorDeferred.resolve(editor);
});
const css = await (
@@ -128,4 +142,12 @@ export class DeesEditorBare extends DeesElement {
});
this.contentSubject.next(editor.getValue());
}
public async disconnectedCallback(): Promise<void> {
await super.disconnectedCallback();
if (this.monacoThemeSubscription) {
this.monacoThemeSubscription.unsubscribe();
this.monacoThemeSubscription = null;
}
}
}