Ver código fonte

Implemented localStorage Key

Aigars Silkalns 1 dia atrás
pai
commit
e4493360a4

+ 56 - 1
dist/js/adminlte.js

@@ -609,8 +609,10 @@
     const SELECTOR_APP_WRAPPER = '.app-wrapper';
     const SELECTOR_SIDEBAR_EXPAND = `[class*="${CLASS_NAME_SIDEBAR_EXPAND}"]`;
     const SELECTOR_SIDEBAR_TOGGLE = '[data-lte-toggle="sidebar"]';
+    const STORAGE_KEY_SIDEBAR_STATE = 'lte.sidebar.state';
     const Defaults = {
-        sidebarBreakpoint: 992
+        sidebarBreakpoint: 992,
+        enablePersistence: true
     };
     /**
      * Class Definition
@@ -680,9 +682,62 @@
             else {
                 this.collapse();
             }
+            this.saveSidebarState();
+        }
+        /**
+         * Save sidebar state to localStorage
+         */
+        saveSidebarState() {
+            if (!this._config.enablePersistence) {
+                return;
+            }
+            // Check for SSR environment
+            if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
+                return;
+            }
+            try {
+                const state = document.body.classList.contains(CLASS_NAME_SIDEBAR_COLLAPSE)
+                    ? CLASS_NAME_SIDEBAR_COLLAPSE
+                    : CLASS_NAME_SIDEBAR_OPEN;
+                localStorage.setItem(STORAGE_KEY_SIDEBAR_STATE, state);
+            }
+            catch {
+                // localStorage may be unavailable (private browsing, quota exceeded, etc.)
+            }
+        }
+        /**
+         * Load sidebar state from localStorage
+         * Only applies on desktop; mobile always starts collapsed
+         */
+        loadSidebarState() {
+            if (!this._config.enablePersistence) {
+                return;
+            }
+            // Check for SSR environment
+            if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
+                return;
+            }
+            // Don't restore state on mobile - let responsive behavior handle it
+            if (window.innerWidth <= this._config.sidebarBreakpoint) {
+                return;
+            }
+            try {
+                const storedState = localStorage.getItem(STORAGE_KEY_SIDEBAR_STATE);
+                if (storedState === CLASS_NAME_SIDEBAR_COLLAPSE) {
+                    this.collapse();
+                }
+                else if (storedState === CLASS_NAME_SIDEBAR_OPEN) {
+                    this.expand();
+                }
+                // If null (never saved), let default behavior apply
+            }
+            catch {
+                // localStorage may be unavailable
+            }
         }
         init() {
             this.addSidebarBreakPoint();
+            this.loadSidebarState();
         }
     }
     /**

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/js/adminlte.js.map


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/js/adminlte.min.js


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/js/adminlte.min.js.map


+ 56 - 1
src/html/public/js/adminlte.js

@@ -609,8 +609,10 @@
     const SELECTOR_APP_WRAPPER = '.app-wrapper';
     const SELECTOR_SIDEBAR_EXPAND = `[class*="${CLASS_NAME_SIDEBAR_EXPAND}"]`;
     const SELECTOR_SIDEBAR_TOGGLE = '[data-lte-toggle="sidebar"]';
+    const STORAGE_KEY_SIDEBAR_STATE = 'lte.sidebar.state';
     const Defaults = {
-        sidebarBreakpoint: 992
+        sidebarBreakpoint: 992,
+        enablePersistence: true
     };
     /**
      * Class Definition
@@ -680,9 +682,62 @@
             else {
                 this.collapse();
             }
+            this.saveSidebarState();
+        }
+        /**
+         * Save sidebar state to localStorage
+         */
+        saveSidebarState() {
+            if (!this._config.enablePersistence) {
+                return;
+            }
+            // Check for SSR environment
+            if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
+                return;
+            }
+            try {
+                const state = document.body.classList.contains(CLASS_NAME_SIDEBAR_COLLAPSE)
+                    ? CLASS_NAME_SIDEBAR_COLLAPSE
+                    : CLASS_NAME_SIDEBAR_OPEN;
+                localStorage.setItem(STORAGE_KEY_SIDEBAR_STATE, state);
+            }
+            catch {
+                // localStorage may be unavailable (private browsing, quota exceeded, etc.)
+            }
+        }
+        /**
+         * Load sidebar state from localStorage
+         * Only applies on desktop; mobile always starts collapsed
+         */
+        loadSidebarState() {
+            if (!this._config.enablePersistence) {
+                return;
+            }
+            // Check for SSR environment
+            if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
+                return;
+            }
+            // Don't restore state on mobile - let responsive behavior handle it
+            if (window.innerWidth <= this._config.sidebarBreakpoint) {
+                return;
+            }
+            try {
+                const storedState = localStorage.getItem(STORAGE_KEY_SIDEBAR_STATE);
+                if (storedState === CLASS_NAME_SIDEBAR_COLLAPSE) {
+                    this.collapse();
+                }
+                else if (storedState === CLASS_NAME_SIDEBAR_OPEN) {
+                    this.expand();
+                }
+                // If null (never saved), let default behavior apply
+            }
+            catch {
+                // localStorage may be unavailable
+            }
         }
         init() {
             this.addSidebarBreakPoint();
+            this.loadSidebarState();
         }
     }
     /**

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
src/html/public/js/adminlte.js.map


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
src/html/public/js/adminlte.min.js


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
src/html/public/js/adminlte.min.js.map


+ 65 - 2
src/ts/push-menu.ts

@@ -37,12 +37,16 @@ const SELECTOR_APP_WRAPPER = '.app-wrapper'
 const SELECTOR_SIDEBAR_EXPAND = `[class*="${CLASS_NAME_SIDEBAR_EXPAND}"]`
 const SELECTOR_SIDEBAR_TOGGLE = '[data-lte-toggle="sidebar"]'
 
+const STORAGE_KEY_SIDEBAR_STATE = 'lte.sidebar.state'
+
 type Config = {
   sidebarBreakpoint: number;
+  enablePersistence: boolean;
 }
 
-const Defaults = {
-  sidebarBreakpoint: 992
+const Defaults: Config = {
+  sidebarBreakpoint: 992,
+  enablePersistence: true
 }
 
 /**
@@ -128,10 +132,69 @@ class PushMenu {
     } else {
       this.collapse()
     }
+
+    this.saveSidebarState()
+  }
+
+  /**
+   * Save sidebar state to localStorage
+   */
+  saveSidebarState(): void {
+    if (!this._config.enablePersistence) {
+      return
+    }
+
+    // Check for SSR environment
+    if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
+      return
+    }
+
+    try {
+      const state = document.body.classList.contains(CLASS_NAME_SIDEBAR_COLLAPSE)
+        ? CLASS_NAME_SIDEBAR_COLLAPSE
+        : CLASS_NAME_SIDEBAR_OPEN
+      localStorage.setItem(STORAGE_KEY_SIDEBAR_STATE, state)
+    } catch {
+      // localStorage may be unavailable (private browsing, quota exceeded, etc.)
+    }
+  }
+
+  /**
+   * Load sidebar state from localStorage
+   * Only applies on desktop; mobile always starts collapsed
+   */
+  loadSidebarState(): void {
+    if (!this._config.enablePersistence) {
+      return
+    }
+
+    // Check for SSR environment
+    if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
+      return
+    }
+
+    // Don't restore state on mobile - let responsive behavior handle it
+    if (window.innerWidth <= this._config.sidebarBreakpoint) {
+      return
+    }
+
+    try {
+      const storedState = localStorage.getItem(STORAGE_KEY_SIDEBAR_STATE)
+
+      if (storedState === CLASS_NAME_SIDEBAR_COLLAPSE) {
+        this.collapse()
+      } else if (storedState === CLASS_NAME_SIDEBAR_OPEN) {
+        this.expand()
+      }
+      // If null (never saved), let default behavior apply
+    } catch {
+      // localStorage may be unavailable
+    }
   }
 
   init() {
     this.addSidebarBreakPoint()
+    this.loadSidebarState()
   }
 }
 

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff