From 6612a3a550a2c870941b0ba6d2f3f72d334c6a0e Mon Sep 17 00:00:00 2001 From: soulsands <407221377@qq.com> Date: Thu, 6 Apr 2023 20:59:09 +0800 Subject: [PATCH] fix: correct note-map resizing --- src/public/app/widgets/note_map.js | 9 ++++++++- src/public/app/widgets/ribbon_widgets/note_map.js | 13 ++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/public/app/widgets/note_map.js b/src/public/app/widgets/note_map.js index ccd659683..80ccf194c 100644 --- a/src/public/app/widgets/note_map.js +++ b/src/public/app/widgets/note_map.js @@ -55,7 +55,14 @@ export default class NoteMapWidget extends NoteContextAwareWidget { this.$container = this.$widget.find(".note-map-container"); this.$styleResolver = this.$widget.find('.style-resolver'); - window.addEventListener('resize', () => this.setDimensions(), false); + + try { + new ResizeObserver(() => this.setDimensions()).observe(this.$container[0]) + } catch (error) { + window.addEventListener('resize', () => this.setDimensions(), false); + } + + this.$widget.find(".map-type-switcher button").on("click", async e => { const type = $(e.target).closest("button").attr("data-type"); diff --git a/src/public/app/widgets/ribbon_widgets/note_map.js b/src/public/app/widgets/ribbon_widgets/note_map.js index 26405b281..ffcf36e56 100644 --- a/src/public/app/widgets/ribbon_widgets/note_map.js +++ b/src/public/app/widgets/ribbon_widgets/note_map.js @@ -87,8 +87,8 @@ export default class NoteMapRibbonWidget extends NoteContextAwareWidget { this.noteMapWidget.setDimensions(); }); - window.addEventListener('resize', () => { - if (!this.graph) { // no graph has been even rendered + const handleResize = () => { + if (!this.noteMapWidget.graph) { // no graph has been even rendered return; } @@ -98,7 +98,14 @@ export default class NoteMapRibbonWidget extends NoteContextAwareWidget { else if (this.openState === 'small') { this.setSmallSize(); } - }, false); + } + + try { + new ResizeObserver(handleResize).observe(this.$widget[0]) + } catch (error) { + window.addEventListener('resize', handleResize, false); + } + } setSmallSize() {