bun-plugin-stx 0.2.325 → 0.2.327

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.
@@ -1699,8 +1699,7 @@ else {
1699
1699
  // Remove old page scripts
1700
1700
  document.querySelectorAll('script[data-stx-page]').forEach(function(s){s.remove()});
1701
1701
  if(pushState!==false)writeHistory(pushState,url+(hash||''));
1702
- updateNav();
1703
- updateActiveLinks();
1702
+ refreshCurrentLinks();
1704
1703
  if(o.scrollToTop&&!hash)window.scrollTo({top:0,behavior:'instant'});
1705
1704
  else if(hash){var el=document.querySelector(hash);if(el)el.scrollIntoView({behavior:'smooth'})}
1706
1705
  window.dispatchEvent(new CustomEvent('stx:navigate',{detail:{url:url}}));
@@ -2150,8 +2149,7 @@ else {
2150
2149
  if(pushState!==false)writeHistory(pushState,url+(hash||''));
2151
2150
 
2152
2151
  // Update active nav links
2153
- updateNav();
2154
- updateActiveLinks();
2152
+ refreshCurrentLinks();
2155
2153
 
2156
2154
  // Scroll
2157
2155
  if(o.scrollToTop&&!hash)window.scrollTo({top:0,behavior:'instant'});
@@ -2559,7 +2557,14 @@ else {
2559
2557
  // Null for links the router does not own (another origin, a bare #fragment,
2560
2558
  // anything unparseable), which are left exactly as the server rendered them.
2561
2559
  function normPath(p){return p.length>1&&p.charAt(p.length-1)==='/'?p.slice(0,-1):p}
2562
- function linkState(href){
2560
+ // Paths beyond the link's own that make it current: a tab bar's Calendar
2561
+ // tab stays lit on a workout opened from it (data-stx-active-match, a
2562
+ // space-separated list of path prefixes).
2563
+ function matchesAny(list,cur){
2564
+ if(!list)return false;
2565
+ return list.split(/\\s+/).some(function(p){p=normPath(p);return p&&(cur===p||cur.indexOf(p+'/')===0)});
2566
+ }
2567
+ function linkState(href,also){
2563
2568
  if(!href||href.charAt(0)==='#')return null;
2564
2569
  var u;
2565
2570
  try{u=new URL(href,location.href)}catch(e){return null}
@@ -2571,27 +2576,39 @@ else {
2571
2576
  // point at this path, exactly one is.
2572
2577
  var have=new URLSearchParams(location.search),q=true;
2573
2578
  u.searchParams.forEach(function(v,k){if(have.getAll(k).indexOf(v)===-1)q=false});
2579
+ var matched=matchesAny(also,cur);
2574
2580
  return {
2575
2581
  exact:q&&path===cur,
2576
- active:q&&(path==='/'?cur==='/':(cur===path||cur.indexOf(path+'/')===0))
2582
+ active:q&&(path==='/'?cur==='/':(cur===path||cur.indexOf(path+'/')===0))||matched,
2583
+ matched:matched
2577
2584
  };
2578
2585
  }
2579
2586
 
2580
2587
  function updateNav(){
2581
2588
  document.querySelectorAll('nav a[href], #mobileNav a[href], [data-stx-nav] a[href]').forEach(function(a){
2582
2589
  if(!a.hasAttribute('data-stx-link'))return;
2583
- var st=linkState(a.getAttribute('href'));
2590
+ var st=linkState(a.getAttribute('href'),a.getAttribute('data-stx-active-match'));
2584
2591
  if(!st)return;
2585
2592
  var ac=a.getAttribute('data-stx-active-class')||'active';
2586
- if(st.exact)ac.split(' ').forEach(function(cls){if(cls)a.classList.add(cls)});else ac.split(' ').forEach(function(cls){if(cls)a.classList.remove(cls)});
2593
+ 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)});
2587
2594
  });
2588
2595
  }
2589
2596
 
2597
+ // Both passes, always in this order. A link inside a <nav> is current only on
2598
+ // its own page (or one it names in data-stx-active-match), so updateNav has
2599
+ // the last word. Navigation used to run them the other way round, which lit
2600
+ // a nav's parent links by prefix after an in-app navigation but not after a
2601
+ // full load of the same URL.
2602
+ function refreshCurrentLinks(){
2603
+ updateActiveLinks();
2604
+ updateNav();
2605
+ }
2606
+
2590
2607
  function updateActiveLinks(){
2591
2608
  // Update active classes on <stx-link> elements (and legacy data-stx-link)
2592
2609
  var links=document.querySelectorAll('[data-stx-link]');
2593
2610
  links.forEach(function(link){
2594
- var st=linkState(link.getAttribute('to')||link.getAttribute('href')||'');
2611
+ var st=linkState(link.getAttribute('to')||link.getAttribute('href')||'',link.getAttribute('data-stx-active-match'));
2595
2612
  if(!st)return;
2596
2613
  var ac=link.getAttribute('active-class')||link.getAttribute('data-stx-active-class')||'active';
2597
2614
  var eac=link.getAttribute('exact-active-class')||link.getAttribute('data-stx-exact-active-class')||'exact-active';
@@ -2722,8 +2739,7 @@ else {
2722
2739
  function init(){
2723
2740
  injectStyles();
2724
2741
  injectViewTransitionCSS();
2725
- updateActiveLinks();
2726
- updateNav();
2742
+ refreshCurrentLinks();
2727
2743
  }
2728
2744
 
2729
2745
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',init);else init();
package/dist/serve.js CHANGED
@@ -9791,7 +9791,7 @@ function __stxOverlay(errs){
9791
9791
  rebuildDiscoveredPagePaths(kept);
9792
9792
  await indexPageMiddleware(kept);
9793
9793
  try {
9794
- const { Router } = await import("./chunk-37vp8yms.js");
9794
+ const { Router } = await import("./chunk-y6mw5qdq.js");
9795
9795
  const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
9796
9796
  const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName(), exclude: options.exclude });
9797
9797
  if (!options.quiet)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.325",
4
+ "version": "0.2.327",
5
5
  "description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",