diff --git a/src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.js b/src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.ts similarity index 88% rename from src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.js rename to src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.ts index 3f9152c1b..c22036fc4 100644 --- a/src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.js +++ b/src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.ts @@ -64,6 +64,9 @@ const TPL = `\ * The ribbon item is active by default for text notes, as long as they are not in read-only mode. */ export default class ClassicEditorToolbar extends NoteContextAwareWidget { + + private observer: MutationObserver; + constructor() { super(); this.observer = new MutationObserver((e) => this.#onDropdownStateChanged(e)); @@ -83,7 +86,7 @@ export default class ClassicEditorToolbar extends NoteContextAwareWidget { if (utils.isMobile()) { // The virtual keyboard obscures the editing toolbar so we have to reposition by calculating the height of the keyboard. - window.visualViewport.addEventListener("resize", () => this.#adjustPosition()); + window.visualViewport?.addEventListener("resize", () => this.#adjustPosition()); window.addEventListener("scroll", () => this.#adjustPosition()); // Observe when a dropdown is expanded to apply a style that allows the dropdown to be visible, since we can't have the element both visible and the toolbar scrollable. @@ -95,13 +98,13 @@ export default class ClassicEditorToolbar extends NoteContextAwareWidget { } } - #onDropdownStateChanged(e) { - const dropdownActive = e.map((e) => e.target.ariaExpanded === "true").reduce((acc, e) => acc && e); + #onDropdownStateChanged(e: MutationRecord[]) { + const dropdownActive = e.map((e) => (e.target as any).ariaExpanded === "true").reduce((acc, e) => acc && e); this.$widget[0].classList.toggle("dropdown-active", dropdownActive); } #adjustPosition() { - let bottom = window.innerHeight - window.visualViewport.height; + let bottom = window.innerHeight - (window.visualViewport?.height || 0); if (bottom === 0) { // The keyboard is not visible, align it to the launcher bar instead. @@ -125,11 +128,11 @@ export default class ClassicEditorToolbar extends NoteContextAwareWidget { return false; } - if (this.note.type !== "text") { + if (!this.note || this.note.type !== "text") { return false; } - if (await this.noteContext.isReadOnly()) { + if (await this.noteContext?.isReadOnly()) { return false; }