rails_modal_manager 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 736e63cc3f81769e168c0945753f8cc1f2f4a8e840fb18a6768f10a76e80f7cc
4
- data.tar.gz: 8d4cd784e878b2ff7fd5baca62d25c8b9fbd0aefc53caae82f86710805a2f4b5
3
+ metadata.gz: 9ddfd329fb8f4ef8eff88d5d5d3284dcf02c9739d153252c0647e118433bb446
4
+ data.tar.gz: 37ae27aab69556b2d49037873677753002898892fad7ec3aec7671b1d08a25fa
5
5
  SHA512:
6
- metadata.gz: 235e07f2e6e39617031bf18115bbf775345488aa369331acf2803cd12a0607464b2b4e2507c807957665e85b67731850ee7f84db37b034b00e53cd83773e950f
7
- data.tar.gz: b9aca2397fdeb003b14ba3f368f76cb60aed7744486534df7fb81de688730b0c5c58144c297a30bb90df98166229b05cb745ef8ef7e00a88db3972b3d68e8c7c
6
+ metadata.gz: 2871ebeb6b3dc8ff22beef165fb488b0c4acd8cb674faa8167c6b41d464cbd121ddb2ab17b811e28faf893a10b19f34a918139369eb4ab88f5346931bcb41c94
7
+ data.tar.gz: 10008b13adf85eea1729b346e228059ada4a849958dc08ea8f04c787f4cd4d930bcf938e5323fdc57ae55d5f9e2795bd5ed98436b5c267d89b7280ce24423db9
@@ -345,6 +345,9 @@ export default class extends Controller {
345
345
  const modal = this.element
346
346
  const overlay = this.getOverlay()
347
347
 
348
+ // Reset sidebar and submenu to first item before hiding
349
+ this.resetSidebarAndSubmenu()
350
+
348
351
  modal.classList.remove('rmm-active')
349
352
  if (overlay) overlay.classList.remove('rmm-active')
350
353
 
@@ -359,6 +362,38 @@ export default class extends Controller {
359
362
  }, this.animationDurationValue)
360
363
  }
361
364
 
365
+ /**
366
+ * Reset sidebar and submenu controllers to first item
367
+ * Called when modal is closed to ensure clean state on next open
368
+ */
369
+ resetSidebarAndSubmenu() {
370
+ const modal = this.element
371
+
372
+ // Reset sidebar controller
373
+ const sidebarElement = modal.querySelector('[data-controller*="rmm-sidebar"]')
374
+ if (sidebarElement) {
375
+ const sidebarController = this.application.getControllerForElementAndIdentifier(
376
+ sidebarElement,
377
+ 'rmm-sidebar'
378
+ )
379
+ if (sidebarController && typeof sidebarController.resetToFirst === 'function') {
380
+ sidebarController.resetToFirst()
381
+ }
382
+ }
383
+
384
+ // Reset all submenu controllers
385
+ const submenuElements = modal.querySelectorAll('[data-controller*="rmm-submenu"]')
386
+ submenuElements.forEach(submenuElement => {
387
+ const submenuController = this.application.getControllerForElementAndIdentifier(
388
+ submenuElement,
389
+ 'rmm-submenu'
390
+ )
391
+ if (submenuController && typeof submenuController.resetToFirst === 'function') {
392
+ submenuController.resetToFirst()
393
+ }
394
+ })
395
+ }
396
+
362
397
  // ============================================
363
398
  // Styles
364
399
  // ============================================
@@ -40,14 +40,10 @@ export default class extends Controller {
40
40
  this.element.classList.add('rmm-sidebar-collapsed')
41
41
  }
42
42
 
43
- // Find initial active item and restore its state
43
+ // Find initial active item
44
44
  const activeItem = this.element.querySelector('.rmm-sidebar-item.rmm-active')
45
45
  if (activeItem) {
46
46
  this.currentItemId = activeItem.dataset.itemId
47
- // Restore panel and submenu state for the active item
48
- // This ensures content is properly displayed when modal is reopened
49
- this.switchPanel(activeItem)
50
- this.switchSubmenuGroup(activeItem)
51
47
  }
52
48
 
53
49
  // Listen for toggle event from header button
@@ -205,4 +201,28 @@ export default class extends Controller {
205
201
  this.collapsedValue = true
206
202
  this.element.classList.add('rmm-sidebar-collapsed')
207
203
  }
204
+
205
+ /**
206
+ * Reset sidebar to first item
207
+ * Called by modal controller when modal is closed
208
+ */
209
+ resetToFirst() {
210
+ const firstItem = this.element.querySelector('.rmm-sidebar-item')
211
+ if (!firstItem) return
212
+
213
+ // Remove active from all items
214
+ this.element.querySelectorAll('.rmm-sidebar-item').forEach(el => {
215
+ el.classList.remove('rmm-active')
216
+ })
217
+
218
+ // Add active to first item
219
+ firstItem.classList.add('rmm-active')
220
+ this.currentItemId = firstItem.dataset.itemId
221
+
222
+ // Switch content panel
223
+ this.switchPanel(firstItem)
224
+
225
+ // Switch submenu group
226
+ this.switchSubmenuGroup(firstItem)
227
+ }
208
228
  }
@@ -45,17 +45,10 @@ export default class extends Controller {
45
45
  this.ajaxCache = new Map()
46
46
  this.currentItemId = null
47
47
 
48
- // Find initial active item and restore its state
48
+ // Find initial active item
49
49
  const activeItem = this.element.querySelector('.rmm-submenu-item.rmm-active')
50
50
  if (activeItem) {
51
51
  this.currentItemId = activeItem.dataset.itemId
52
- // Restore panel state for the active item
53
- // This ensures content is properly displayed when modal is reopened
54
- if (this.loadModeValue === 'ajax') {
55
- this.loadAjaxContent(activeItem)
56
- } else {
57
- this.switchPanel(activeItem)
58
- }
59
52
  }
60
53
  }
61
54
 
@@ -235,4 +228,32 @@ export default class extends Controller {
235
228
  }
236
229
  }
237
230
  }
231
+
232
+ /**
233
+ * Reset submenu to first item
234
+ * Called by modal controller when modal is closed
235
+ */
236
+ resetToFirst() {
237
+ const firstItem = this.element.querySelector('.rmm-submenu-item')
238
+ if (!firstItem) return
239
+
240
+ // Remove active from all items
241
+ this.element.querySelectorAll('.rmm-submenu-item').forEach(el => {
242
+ el.classList.remove('rmm-active')
243
+ })
244
+
245
+ // Add active to first item
246
+ firstItem.classList.add('rmm-active')
247
+ this.currentItemId = firstItem.dataset.itemId
248
+
249
+ // Switch panel
250
+ if (this.loadModeValue === 'ajax') {
251
+ this.loadAjaxContent(firstItem)
252
+ } else {
253
+ this.switchPanel(firstItem)
254
+ }
255
+
256
+ // Clear AJAX cache
257
+ this.ajaxCache.clear()
258
+ }
238
259
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsModalManager
4
- VERSION = "1.0.15"
4
+ VERSION = "1.0.16"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_modal_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - reshacs