rails_nexus 2.0.3 → 2.1.0

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: e53768c742936d378f9f25d9a11c7e8e4940f1393e43f89f6f4de66e739c04a0
4
- data.tar.gz: 2fb198abfe108349535f99a67b57d2ef3f1a1563c720537f88b10140433e5dc4
3
+ metadata.gz: 3deddaf8307ffc780ab2c69de90a02a6dc4c8baf8c780af2e107b08ff8798337
4
+ data.tar.gz: 73ab2141acb40a433ca2db21a1dd35b1a2a642ff74a1ad420be2978cfa237821
5
5
  SHA512:
6
- metadata.gz: 7894b8271c99d1ed424e4a27a733e4b9b09df27c58471caf6c136e272ea0d7cfd98c6d847ebfdf27afa8312ee5ac8bcbb7f3ae39bf80980dcb88fa6ae1d3dcb5
7
- data.tar.gz: da25a4ae602de381da422d8db9f910be1bbc7fc918bde6b608e5b6eb837dee458f78370514cc2a95cc6801be98cb97fdb7c47355def55a9199d7f1554b903ba6
6
+ metadata.gz: 7195e03556acf7084d881c264166564a02da3273feff2abbcb6ee56e93b9e5ae2e797309cd82e586ac4310ea083c7fde125e4d492b78268fcefdea19dfac58de
7
+ data.tar.gz: bb61711dba4e993e79ff6fab0185afe29ef4b20021fcf5c2fdc9ca79b11292bfcb005afe35ebb8fc243760e0f5513cb6a7207cefa7c225a7eb37fc43ef545675
@@ -43,16 +43,103 @@
43
43
  // ═══════════════════════════════════════════════════════════════
44
44
 
45
45
  class RailsNexusSidebarController {
46
- static get targets() { return ["drawer", "overlay"] }
46
+ static get targets() { return ["drawer", "overlay", "sidebar", "toggleButton"] }
47
+
48
+ connect() {
49
+ this.handleResize = this.syncButtonState.bind(this)
50
+ window.addEventListener("resize", this.handleResize)
51
+
52
+ if (this.desktop() && this.sidebarHidden() && this.hasSidebarTarget) {
53
+ this.sidebarTarget.classList.add("is-hidden")
54
+ }
55
+
56
+ this.syncButtonState()
57
+ }
58
+
59
+ disconnect() {
60
+ window.removeEventListener("resize", this.handleResize)
61
+ }
47
62
 
48
63
  toggle() {
49
- if (this.hasDrawerTarget) this.drawerTarget.classList.toggle("open")
50
- if (this.hasOverlayTarget) this.overlayTarget.classList.toggle("open")
64
+ if (this.desktop()) {
65
+ if (this.hasSidebarTarget) {
66
+ var hidden = this.sidebarTarget.classList.toggle("is-hidden")
67
+ this.storeSidebarState(hidden)
68
+ }
69
+ } else if (this.hasDrawerTarget) {
70
+ var opening = !this.drawerTarget.classList.contains("open")
71
+ this.drawerTarget.classList.toggle("open", opening)
72
+ if (this.hasOverlayTarget) this.overlayTarget.classList.toggle("open", opening)
73
+ }
74
+
75
+ this.syncButtonState()
51
76
  }
52
77
 
53
78
  close() {
54
79
  if (this.hasDrawerTarget) this.drawerTarget.classList.remove("open")
55
80
  if (this.hasOverlayTarget) this.overlayTarget.classList.remove("open")
81
+ this.syncButtonState()
82
+ }
83
+
84
+ desktop() {
85
+ return window.matchMedia("(min-width: 1024px)").matches
86
+ }
87
+
88
+ sidebarHidden() {
89
+ try {
90
+ return localStorage.getItem("rails_nexus-sidebar-hidden") === "true"
91
+ } catch (_error) {
92
+ return false
93
+ }
94
+ }
95
+
96
+ storeSidebarState(hidden) {
97
+ try {
98
+ localStorage.setItem("rails_nexus-sidebar-hidden", hidden.toString())
99
+ } catch (_error) {
100
+ // The toggle still works when storage is unavailable.
101
+ }
102
+ }
103
+
104
+ syncButtonState() {
105
+ if (!this.hasToggleButtonTarget) return
106
+
107
+ var expanded
108
+ if (this.desktop()) {
109
+ expanded = this.hasSidebarTarget && !this.sidebarTarget.classList.contains("is-hidden")
110
+ } else {
111
+ expanded = this.hasDrawerTarget && this.drawerTarget.classList.contains("open")
112
+ }
113
+
114
+ this.toggleButtonTarget.setAttribute("aria-expanded", expanded.toString())
115
+ this.toggleButtonTarget.setAttribute("aria-label", expanded ? "Hide navigation" : "Show navigation")
116
+ this.toggleButtonTarget.title = expanded ? "Hide navigation" : "Show navigation"
117
+ }
118
+
119
+ closeOtherMenus(event) {
120
+ var currentMenu = event.currentTarget
121
+ if (!currentMenu.open) return
122
+
123
+ var navigation = currentMenu.closest(".rn-sidebar-nav")
124
+ if (!navigation) return
125
+
126
+ navigation.querySelectorAll("details.rn-nav-section[open]").forEach(function(menu) {
127
+ if (menu !== currentMenu) menu.open = false
128
+ })
129
+ }
130
+
131
+ toggleShortcuts(event) {
132
+ var dialog = document.querySelector("[data-rails_nexus-target='shortcutsDialog']")
133
+ if (!dialog) return
134
+
135
+ var isOpening = !dialog.classList.contains("open")
136
+ dialog.classList.toggle("open", isOpening)
137
+ event.currentTarget.setAttribute("aria-expanded", isOpening.toString())
138
+
139
+ if (isOpening) {
140
+ var closeButton = dialog.querySelector("button")
141
+ if (closeButton) closeButton.focus()
142
+ }
56
143
  }
57
144
  }
58
145
 
@@ -277,11 +364,17 @@
277
364
  this.closeShortcuts()
278
365
  } else {
279
366
  this.shortcutsDialogTarget.classList.add("open")
367
+ var button = document.getElementById("rn-shortcuts-button")
368
+ if (button) button.setAttribute("aria-expanded", "true")
280
369
  }
281
370
  }
282
371
 
283
372
  closeShortcuts() {
284
- if (this.hasShortcutsDialogTarget) this.shortcutsDialogTarget.classList.remove("open")
373
+ if (this.hasShortcutsDialogTarget) {
374
+ this.shortcutsDialogTarget.classList.remove("open")
375
+ var button = document.getElementById("rn-shortcuts-button")
376
+ if (button) button.setAttribute("aria-expanded", "false")
377
+ }
285
378
  }
286
379
 
287
380
  // ─── Navigation (prev/next) ───────────────────────────────
@@ -373,11 +466,15 @@
373
466
  // ─── Loading State ────────────────────────────────────────
374
467
 
375
468
  showActivity() {
376
- if (this.hasActivityTarget) this.activityTarget.classList.remove("hidden")
469
+ if (!this.hasActivityTarget) return
470
+ this.activityTarget.hidden = false
471
+ this.activityTarget.classList.remove("hidden")
377
472
  }
378
473
 
379
474
  hideActivity() {
380
- if (this.hasActivityTarget) this.activityTarget.classList.add("hidden")
475
+ if (!this.hasActivityTarget) return
476
+ this.activityTarget.hidden = true
477
+ this.activityTarget.classList.add("hidden")
381
478
  }
382
479
  }
383
480