From f008f7934fd30935b3a388a5f539a1e1eb778d13 Mon Sep 17 00:00:00 2001 From: Marissa Huysentruyt Date: Tue, 14 Oct 2025 12:02:11 -0400 Subject: [PATCH 1/6] chore: use this.panels instead of DOM querying --- src/core/ExtensionManager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/ExtensionManager.js b/src/core/ExtensionManager.js index 049017c..a58f0a3 100644 --- a/src/core/ExtensionManager.js +++ b/src/core/ExtensionManager.js @@ -66,7 +66,7 @@ class ExtensionManager { this.lastToggleTime = now; try { - const existingPanelInDOM = document.querySelector('.cv-panel--welcome'); + const existingPanelInDOM = this.panels.get('.cv-panel--welcome'); if (existingPanelInDOM) { existingPanelInDOM.classList.remove('cv-panel--visible'); @@ -87,7 +87,7 @@ class ExtensionManager { cleanupOrphanedPanels() { // Remove any orphaned panels from DOM - const orphanedPanels = document.querySelectorAll('.cv-panel'); + const orphanedPanels = this.panels.get('.cv-panel'); orphanedPanels.forEach(panel => { panel.remove(); }); @@ -134,7 +134,7 @@ class ExtensionManager { this.panels.clear(); // Also remove any orphaned panels from DOM - const existingPanels = document.querySelectorAll('.cv-panel'); + const existingPanels = this.panels.get('.cv-panel'); existingPanels.forEach(panel => { panel.remove(); }); From 27692507928770e9f5bb177572c42cadd3f60e3a Mon Sep 17 00:00:00 2001 From: Marissa Huysentruyt Date: Tue, 14 Oct 2025 13:37:48 -0400 Subject: [PATCH 2/6] chore: remove debounce functionality - removes isToggling and lastToggleTime --- src/core/ExtensionManager.js | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/core/ExtensionManager.js b/src/core/ExtensionManager.js index a58f0a3..9de3f84 100644 --- a/src/core/ExtensionManager.js +++ b/src/core/ExtensionManager.js @@ -7,8 +7,9 @@ class ExtensionManager { this.browserAPI = browserAPI || (typeof browser !== 'undefined' ? browser : chrome); this.panels = new Map(); this.initialized = false; - this.isToggling = false; - this.lastToggleTime = 0; + + // TODO: Set the other panel types in the panels map + this.panels.set('welcome', new Panel('welcome', {}, this.browserAPI)); } async initialize() { @@ -26,6 +27,8 @@ class ExtensionManager { }); } + await this.loadCoreCSS(); + this.initialized = true; } @@ -52,19 +55,6 @@ class ExtensionManager { async togglePanel(panelType) { - const now = Date.now(); - - if (now - this.lastToggleTime < 500) { - return; - } - - if (this.isToggling) { - return; - } - - this.isToggling = true; - this.lastToggleTime = now; - try { const existingPanelInDOM = this.panels.get('.cv-panel--welcome'); @@ -77,11 +67,9 @@ class ExtensionManager { } else { await this.openPanel(panelType); } - } finally { - - setTimeout(() => { - this.isToggling = false; - }, 100); + } + catch (error) { + console.error('Error in togglePanel():', error); } } From 333ba63bab08d521f0797970e55abe7080d4b4fc Mon Sep 17 00:00:00 2001 From: Marissa Huysentruyt Date: Tue, 14 Oct 2025 14:24:35 -0400 Subject: [PATCH 3/6] refactor: togglePanel uses panel map --- src/core/ExtensionManager.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/core/ExtensionManager.js b/src/core/ExtensionManager.js index 9de3f84..556aba7 100644 --- a/src/core/ExtensionManager.js +++ b/src/core/ExtensionManager.js @@ -56,15 +56,20 @@ class ExtensionManager { async togglePanel(panelType) { try { - const existingPanelInDOM = this.panels.get('.cv-panel--welcome'); - - if (existingPanelInDOM) { - existingPanelInDOM.classList.remove('cv-panel--visible'); - // exit animation completes and then remove panel from DOM - setTimeout(() => { - existingPanelInDOM.remove(); - }, 300); + const existingPanelInDOM = this.panels.get(panelType); + + if (existingPanelInDOM && existingPanelInDOM.isVisible) { + // Panel exists and is visible -> hide it + await existingPanelInDOM.hide(); + } else if (existingPanelInDOM && !existingPanelInDOM.isVisible) { + // Panel exists but hidden -> ensure it's initialized and show it + if (!existingPanelInDOM.container || !existingPanelInDOM.container.parentNode) { + // Re-initialize if container is missing or not in DOM + await existingPanelInDOM.initialize(); + } + await existingPanelInDOM.show(); } else { + // Panel doesn't exist -> create and open it await this.openPanel(panelType); } } From 27140b23d6375eb00fcb01f608a1e3e8e4689b38 Mon Sep 17 00:00:00 2001 From: Marissa Huysentruyt Date: Tue, 21 Oct 2025 13:15:32 -0400 Subject: [PATCH 4/6] refactor: cleanupOrphanedPanels calls - add cleanUpOrphanedPanels() to initialization - add cleanupOrphanedPanels() to closeAllPanels() --- src/core/ExtensionManager.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/ExtensionManager.js b/src/core/ExtensionManager.js index 556aba7..7bc2a06 100644 --- a/src/core/ExtensionManager.js +++ b/src/core/ExtensionManager.js @@ -29,6 +29,8 @@ class ExtensionManager { await this.loadCoreCSS(); + this.cleanupOrphanedPanels(); + this.initialized = true; } @@ -79,8 +81,8 @@ class ExtensionManager { } cleanupOrphanedPanels() { - // Remove any orphaned panels from DOM - const orphanedPanels = this.panels.get('.cv-panel'); + // Remove any orphaned panels from DOM that aren't tracked in our map + const orphanedPanels = document.querySelectorAll('.cv-panel'); orphanedPanels.forEach(panel => { panel.remove(); }); @@ -124,13 +126,12 @@ class ExtensionManager { panel.hideImmediate(); } } + + // Clear the panels map this.panels.clear(); // Also remove any orphaned panels from DOM - const existingPanels = this.panels.get('.cv-panel'); - existingPanels.forEach(panel => { - panel.remove(); - }); + this.cleanupOrphanedPanels(); } // TODO: Assessment workflow methods will be added later From ab560d235442cfa3b1e542409e92a55f7f5c4a42 Mon Sep 17 00:00:00 2001 From: Marissa Huysentruyt Date: Tue, 21 Oct 2025 13:33:46 -0400 Subject: [PATCH 5/6] refactor: use existing functions in togglePanel --- src/core/ExtensionManager.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/core/ExtensionManager.js b/src/core/ExtensionManager.js index 7bc2a06..e528176 100644 --- a/src/core/ExtensionManager.js +++ b/src/core/ExtensionManager.js @@ -58,20 +58,13 @@ class ExtensionManager { async togglePanel(panelType) { try { - const existingPanelInDOM = this.panels.get(panelType); - - if (existingPanelInDOM && existingPanelInDOM.isVisible) { - // Panel exists and is visible -> hide it - await existingPanelInDOM.hide(); - } else if (existingPanelInDOM && !existingPanelInDOM.isVisible) { - // Panel exists but hidden -> ensure it's initialized and show it - if (!existingPanelInDOM.container || !existingPanelInDOM.container.parentNode) { - // Re-initialize if container is missing or not in DOM - await existingPanelInDOM.initialize(); - } - await existingPanelInDOM.show(); + const panel = this.panels.get(panelType); + + if (panel && panel.isVisible) { + // Panel is visible -> close it + this.closePanel(panelType); } else { - // Panel doesn't exist -> create and open it + // Panel doesn't exist or is hidden -> open it await this.openPanel(panelType); } } From c024251eb10154d3fad46a9575c41885eeb40c02 Mon Sep 17 00:00:00 2001 From: dustin-jw Date: Tue, 4 Nov 2025 11:27:46 -0700 Subject: [PATCH 6/6] style: formatting and removing redundant comments --- src/core/ExtensionManager.js | 38 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/core/ExtensionManager.js b/src/core/ExtensionManager.js index e528176..58de51d 100644 --- a/src/core/ExtensionManager.js +++ b/src/core/ExtensionManager.js @@ -1,7 +1,5 @@ -// Import Panel class import { Panel } from './Panel.js'; -// Core extension management class class ExtensionManager { constructor(browserAPI = null) { this.browserAPI = browserAPI || (typeof browser !== 'undefined' ? browser : chrome); @@ -47,7 +45,6 @@ class ExtensionManager { await this.openPanel(message.panelType || 'welcome', message.data); break; default: - break; } } catch (error) { @@ -55,28 +52,40 @@ class ExtensionManager { } } + async loadCoreCSS() { + if (document.getElementById('carbon-visualizer-core-css')) return; + + try { + const cssUrl = this.browserAPI.runtime.getURL('src/styles/core.css'); + const response = await fetch(cssUrl); + const css = await response.text(); + + const style = document.createElement('style'); + style.id = 'carbon-visualizer-core-css'; + style.textContent = css; + document.head.appendChild(style); + } catch (error) { + console.error(error); + } + } async togglePanel(panelType) { try { const panel = this.panels.get(panelType); if (panel && panel.isVisible) { - // Panel is visible -> close it this.closePanel(panelType); } else { - // Panel doesn't exist or is hidden -> open it await this.openPanel(panelType); } - } - catch (error) { + } catch (error) { console.error('Error in togglePanel():', error); } } cleanupOrphanedPanels() { - // Remove any orphaned panels from DOM that aren't tracked in our map const orphanedPanels = document.querySelectorAll('.cv-panel'); - orphanedPanels.forEach(panel => { + orphanedPanels.forEach((panel) => { panel.remove(); }); @@ -91,7 +100,7 @@ class ExtensionManager { async openPanel(panelType, data = {}) { let panel = this.panels.get(panelType); - // Always create a fresh panel to avoid state issues + // Create a new panel if one does not already exist if (!panel) { panel = new Panel(panelType, data, this.browserAPI); this.panels.set(panelType, panel); @@ -99,8 +108,6 @@ class ExtensionManager { // Always reinitialize to ensure clean state await panel.initialize(); - - // Show the panel await panel.show(); } @@ -108,22 +115,18 @@ class ExtensionManager { const panel = this.panels.get(panelType); if (panel) { panel.hide(); - // Don't delete from map - keep for reuse } } closeAllPanels() { - // Hide all tracked panels immediately for (const [type, panel] of this.panels) { if (panel && panel.container) { panel.hideImmediate(); } } - // Clear the panels map + // Clear the panels map and remove orphaned panels from DOM this.panels.clear(); - - // Also remove any orphaned panels from DOM this.cleanupOrphanedPanels(); } @@ -133,5 +136,4 @@ class ExtensionManager { // async showResults(assessmentData) { ... } } -// Export the class for dynamic imports export { ExtensionManager };