From feaa55681fc9df2a46e14f296c730b835f8ea3b8 Mon Sep 17 00:00:00 2001
From: Ryo Hilmawan <54142180+CloudHill@users.noreply.github.com>
Date: Mon, 23 Nov 2020 16:34:45 +0700
Subject: [PATCH] add onLoad, onSwitch, and onResize functions to panel
 extensions

---
 mods/side-panel/mod.js | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/mods/side-panel/mod.js b/mods/side-panel/mod.js
index 3dbb711..42f2204 100644
--- a/mods/side-panel/mod.js
+++ b/mods/side-panel/mod.js
@@ -68,6 +68,8 @@ module.exports = {
         if (panelMods.length < 1) return;
         const attempt_interval = setInterval(enhance, 500);
         function enhance() {
+          let curPanelJs;
+
           const frame = document.querySelector('.notion-frame');
           if (!frame) return;
           clearInterval(attempt_interval);
@@ -147,14 +149,18 @@ module.exports = {
           }
 
           function loadContent(mod) {
+            if (curPanelJs && curPanelJs.onSwitch) curPanelJs.onSwitch();
+
             store().last_open = mod.id;
             panel.querySelector('.enhancer-panel--title').innerText = mod.panel.name || mod.name;
             panel.querySelector('.enhancer-panel--icon').innerHTML = mod.panelIcon;
             document.getElementById('enhancer-panel--content').innerHTML = mod.panelHtml;
 
-            if (mod.panelJs)
-              require(mod.panelJs)(store(mod.id))();
-            
+            if (mod.panelJs) {
+              curPanelJs = require(mod.panelJs)(store(mod.id));
+              if (curPanelJs && curPanelJs.onLoad) curPanelJs.onLoad();
+            }
+
             if (mod.panelFullHeight) {
               panel.dataset.fullHeight = mod.panelFullHeight;
             } else panel.dataset.fullHeight = '';
@@ -296,6 +302,10 @@ module.exports = {
               frame.style.paddingRight = 0;
               panel.style.right = width + 'px';
             }
+
+            if (curPanelJs && curPanelJs.onResize) {
+              curPanelJs.onResize();
+            }
           }
 
           function enableResize() {