stx-router 0.2.374 → 0.2.376

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.
Files changed (2) hide show
  1. package/dist/client.js +27 -6
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -2148,13 +2148,34 @@ else {
2148
2148
  };
2149
2149
  }
2150
2150
 
2151
+ // A nav marked data-stx-sticky-active is a tab bar: each tab owns the
2152
+ // screens opened from it, as on iOS. On a page that is none of its links'
2153
+ // own, the link that was current stays current (a workout opened from
2154
+ // Today keeps Today lit), and data-stx-active-match only decides a page
2155
+ // reached with nothing current yet, such as a cold start on a deep link.
2156
+ // data-stx-nav-current remembers which link that was, because
2157
+ // updateActiveLinks has already rewritten the classes by now.
2151
2158
  function updateNav(){
2152
- qsa('nav a[href], #mobileNav a[href], [data-stx-nav] a[href]').forEach(function(a){
2153
- if(!a.hasAttribute('data-stx-link'))return;
2154
- var st=linkState(a.getAttribute('href'),a.getAttribute('data-stx-active-match'));
2155
- if(!st)return;
2156
- var ac=a.getAttribute('data-stx-active-class')||'active';
2157
- if(st.exact||st.matched)ac.split(' ').forEach(function(cls){if(cls)a.classList.add(cls)});else ac.split(' ').forEach(function(cls){if(cls)a.classList.remove(cls)});
2159
+ var done=new Set();
2160
+ qsa('nav, #mobileNav, [data-stx-nav]').forEach(function(nav){
2161
+ var states=[];
2162
+ Array.prototype.forEach.call(nav.querySelectorAll('a[href]'),function(a){
2163
+ if(done.has(a)||!a.hasAttribute('data-stx-link'))return;
2164
+ done.add(a);
2165
+ var st=linkState(a.getAttribute('href'),a.getAttribute('data-stx-active-match'));
2166
+ if(st)states.push({a:a,st:st});
2167
+ });
2168
+ var kept=null;
2169
+ if(nav.hasAttribute('data-stx-sticky-active')&&!states.some(function(x){return x.st.exact})){
2170
+ kept=states.filter(function(x){return x.a.hasAttribute('data-stx-nav-current')})[0]||null;
2171
+ }
2172
+ states.forEach(function(x){
2173
+ var a=x.a,st=x.st;
2174
+ var on=kept?a===kept.a:(st.exact||st.matched);
2175
+ var ac=a.getAttribute('data-stx-active-class')||'active';
2176
+ ac.split(' ').forEach(function(cls){if(cls){if(on)a.classList.add(cls);else a.classList.remove(cls)}});
2177
+ if(on)a.setAttribute('data-stx-nav-current','');else a.removeAttribute('data-stx-nav-current');
2178
+ });
2158
2179
  });
2159
2180
  }
2160
2181
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stx-router",
3
3
  "type": "module",
4
- "version": "0.2.374",
4
+ "version": "0.2.376",
5
5
  "description": "File-based router for STX — .stx template discovery, nested layouts, typed route params, middleware, and client-side SPA navigation.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",