stx-router 0.2.331 → 0.2.332

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 +17 -6
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -335,6 +335,15 @@ export function getRouterScript() {
335
335
  function isModuleRegistryScript(s){
336
336
  return !!s&&((s.hasAttribute&&s.hasAttribute('data-stx-modules'))||REGISTRY_TEXT.test(s.textContent||''));
337
337
  }
338
+ // The page's composables (resources/functions and friends), published as
339
+ // globals its templates call. Each page ships the ones it reaches, so the
340
+ // next page can need one the first never loaded: it runs right after the
341
+ // registry, before anything that calls into it. Guarded per bundle, so a
342
+ // repeat is a no-op.
343
+ var COMPOSABLES_TEXT=/__stxComposableBundles/;
344
+ function isComposablesScript(s){
345
+ return !!s&&((s.hasAttribute&&s.hasAttribute('data-stx-composables'))||COMPOSABLES_TEXT.test(s.textContent||''));
346
+ }
338
347
  function runsAlways(declared, code){
339
348
  if(declared==='always')return true;
340
349
  if(declared==='once')return false;
@@ -989,7 +998,8 @@ else {
989
998
  var runDecl=(attrs.match(/data-stx-run\\s*=\\s*["']?(always|once)["']?/i)||[])[1];
990
999
  var ownerDecl=(attrs.match(/data-stx-owner\\s*=\\s*["']([^"']+)["']/i)||[])[1]||'';
991
1000
  var registry=/(?:^|\\s)data-stx-modules(?:\\s|=|$)/i.test(attrs)||REGISTRY_TEXT.test(code);
992
- fragScripts.push({text:code,slot:slot,setupName:generatedSetupName(code),scoped:scoped,run:runDecl?runDecl.toLowerCase():'',owner:ownerDecl,registry:registry});
1001
+ var composables=/(?:^|\\s)data-stx-composables(?:\\s|=|$)/i.test(attrs)||COMPOSABLES_TEXT.test(code);
1002
+ fragScripts.push({text:code,slot:slot,setupName:generatedSetupName(code),scoped:scoped,run:runDecl?runDecl.toLowerCase():'',owner:ownerDecl,registry:registry,composables:composables});
993
1003
  // Retain scoped setup code in its inert placeholder. A placeholder
994
1004
  // inside template.content is unreachable through document, so the
995
1005
  // repeated component runtime must execute it for each clone.
@@ -1065,7 +1075,7 @@ else {
1065
1075
  // after the content it serves: a component that imports a package ran
1066
1076
  // ahead of it and threw "is not registered on this page". The full
1067
1077
  // document path orders them the same way (registryFirst, below).
1068
- function fragOrder(entry){return entry.registry?0:entry.setupName?2:1}
1078
+ function fragOrder(entry){return entry.registry?0:entry.composables?1:entry.setupName?3:2}
1069
1079
  fragScripts.sort(function(a,b){return fragOrder(a)-fragOrder(b)});
1070
1080
  function runFragScripts(){
1071
1081
  fragScripts.forEach(function(entry){
@@ -1345,7 +1355,7 @@ else {
1345
1355
  var slot='document-'+(++routedBodyScriptId);
1346
1356
  var setupName=generatedSetupName(text);
1347
1357
  if(setupName)incomingSetupName=setupName;
1348
- routedBodyScripts.push({text:text,runAlways:true,slot:slot,setupName:setupName,run:s.getAttribute('data-stx-run')||'',owner:s.getAttribute('data-stx-owner')||'',registry:isModuleRegistryScript(s)});
1358
+ routedBodyScripts.push({text:text,runAlways:true,slot:slot,setupName:setupName,run:s.getAttribute('data-stx-run')||'',owner:s.getAttribute('data-stx-owner')||'',registry:isModuleRegistryScript(s),composables:isComposablesScript(s)});
1349
1359
  s.textContent='';
1350
1360
  s.setAttribute('type','application/stx-pending');
1351
1361
  s.setAttribute('data-stx-route-script',slot);
@@ -1427,7 +1437,7 @@ else {
1427
1437
 
1428
1438
  var scripts=routedBodyScripts.slice();
1429
1439
  function addScript(text, runAlways, slot, owner){
1430
- scripts.push({text:text,runAlways:!!runAlways,slot:slot||'',owner:owner||'',registry:REGISTRY_TEXT.test(text)});
1440
+ scripts.push({text:text,runAlways:!!runAlways,slot:slot||'',owner:owner||'',registry:REGISTRY_TEXT.test(text),composables:COMPOSABLES_TEXT.test(text)});
1431
1441
  }
1432
1442
  if(isLayoutChange){
1433
1443
  // Also collect setup functions from <head>, and the page's module
@@ -1443,7 +1453,7 @@ else {
1443
1453
  if(s.hasAttribute('src'))return;
1444
1454
  if(!text.trim())return;
1445
1455
  if(isSignalsRuntimeScript(s,text))return;
1446
- if(isModuleRegistryScript(s))addScript(text,true,'','');
1456
+ if(isModuleRegistryScript(s)||isComposablesScript(s))addScript(text,true,'','');
1447
1457
  else if(text.indexOf('__stx_setup_')!==-1)addScript(text,true);
1448
1458
  });
1449
1459
  } else {
@@ -1497,7 +1507,8 @@ else {
1497
1507
  // so without this a component in the page body could run ahead of the
1498
1508
  // registry it imports from. Stable: the order within each group holds.
1499
1509
  var registryFirst=scripts.filter(function(e){return e.registry});
1500
- if(registryFirst.length)scripts=registryFirst.concat(scripts.filter(function(e){return !e.registry}));
1510
+ var composablesNext=scripts.filter(function(e){return !e.registry&&e.composables});
1511
+ if(registryFirst.length||composablesNext.length)scripts=registryFirst.concat(composablesNext,scripts.filter(function(e){return !e.registry&&!e.composables}));
1501
1512
 
1502
1513
  // Push history state (before active link updates so location.pathname is current)
1503
1514
  if(pushState!==false)writeHistory(pushState,url+(hash||''));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stx-router",
3
3
  "type": "module",
4
- "version": "0.2.331",
4
+ "version": "0.2.332",
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",