From 5cb41f3368c78e085bb07bd7bb6f9aaf20da8aa3 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Tue, 30 Dec 2025 13:57:51 +0000 Subject: [PATCH] fix(dees-editor-bare): make Monaco editor follow domtools theme and clean up theme subscription on disconnect --- changelog.md | 7 ++++++ ts_web/00_commitinfo_data.ts | 2 +- .../dees-editor-bare/dees-editor-bare.ts | 24 ++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 38536d3..0d10423 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-12-30 - 3.12.2 - fix(dees-editor-bare) +make Monaco editor follow domtools theme and clean up theme subscription on disconnect + +- Set initial Monaco theme from domtools.themeManager.goBrightBoolean instead of hardcoded 'vs-dark' +- Subscribe to domtools.themeManager.themeObservable to update editor theme dynamically +- Add monacoThemeSubscription property and unsubscribe in disconnectedCallback to avoid memory leaks + ## 2025-12-30 - 3.12.1 - fix(modal) fix modal editor layout to prevent overlap by adding relative positioning and reducing height diff --git a/ts_web/00_commitinfo_data.ts b/ts_web/00_commitinfo_data.ts index 85dfc21..6b23de7 100644 --- a/ts_web/00_commitinfo_data.ts +++ b/ts_web/00_commitinfo_data.ts @@ -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.' } diff --git a/ts_web/elements/00group-editor/dees-editor-bare/dees-editor-bare.ts b/ts_web/elements/00group-editor/dees-editor-bare/dees-editor-bare.ts index 036381c..1809d4e 100644 --- a/ts_web/elements/00group-editor/dees-editor-bare/dees-editor-bare.ts +++ b/ts_web/elements/00group-editor/dees-editor-bare/dees-editor-bare.ts @@ -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 { + await super.disconnectedCallback(); + if (this.monacoThemeSubscription) { + this.monacoThemeSubscription.unsubscribe(); + this.monacoThemeSubscription = null; + } + } }