stx-router 0.2.331 → 0.2.333
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.
- package/dist/client.js +28 -6
- 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
|
-
|
|
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.
|
|
@@ -1000,6 +1010,16 @@ else {
|
|
|
1000
1010
|
}
|
|
1001
1011
|
return '';
|
|
1002
1012
|
});
|
|
1013
|
+
// A <style> inside a script is a string the script owns \u2014 a web
|
|
1014
|
+
// component's shadow-DOM CSS, typically \u2014 not a page style. Lifted into
|
|
1015
|
+
// <head> it restyles the whole document (its bare button rule shrank
|
|
1016
|
+
// every button on the page) and the component loses it. Hold scripts
|
|
1017
|
+
// aside while the fragment's own styles are collected.
|
|
1018
|
+
var heldScripts=[];
|
|
1019
|
+
cleanFrag=cleanFrag.replace(new RegExp('<scr'+'ipt\\\\b[^>]*>[\\\\s\\\\S]*?<\\\\/scr'+'ipt>','gi'),function(m){
|
|
1020
|
+
heldScripts.push(m);
|
|
1021
|
+
return '<!--stx-held-script-'+(heldScripts.length-1)+'-->';
|
|
1022
|
+
});
|
|
1003
1023
|
cleanFrag=cleanFrag.replace(new RegExp('<sty'+'le\\\\b([^>]*)>([\\\\s\\\\S]*?)<\\\\/sty'+'le>','gi'),function(m,attrs,css){
|
|
1004
1024
|
if(attrs.indexOf('data-css')!==-1){
|
|
1005
1025
|
fragCss=css;
|
|
@@ -1014,6 +1034,7 @@ else {
|
|
|
1014
1034
|
if(hrefMatch&&hrefMatch[2])fragCssHrefs.push(hrefMatch[2]);
|
|
1015
1035
|
return '';
|
|
1016
1036
|
});
|
|
1037
|
+
cleanFrag=cleanFrag.replace(new RegExp('<!--stx-held-script-(\\\\d+)-->','g'),function(m,i){return heldScripts[Number(i)]});
|
|
1017
1038
|
// Remove old page styles (not css \u2014 that gets merged)
|
|
1018
1039
|
document.querySelectorAll('style[data-stx-page]').forEach(function(s){s.remove()});
|
|
1019
1040
|
// Merge css CSS from fragment into existing css style
|
|
@@ -1065,7 +1086,7 @@ else {
|
|
|
1065
1086
|
// after the content it serves: a component that imports a package ran
|
|
1066
1087
|
// ahead of it and threw "is not registered on this page". The full
|
|
1067
1088
|
// document path orders them the same way (registryFirst, below).
|
|
1068
|
-
function fragOrder(entry){return entry.registry?0:entry.setupName?2
|
|
1089
|
+
function fragOrder(entry){return entry.registry?0:entry.composables?1:entry.setupName?3:2}
|
|
1069
1090
|
fragScripts.sort(function(a,b){return fragOrder(a)-fragOrder(b)});
|
|
1070
1091
|
function runFragScripts(){
|
|
1071
1092
|
fragScripts.forEach(function(entry){
|
|
@@ -1345,7 +1366,7 @@ else {
|
|
|
1345
1366
|
var slot='document-'+(++routedBodyScriptId);
|
|
1346
1367
|
var setupName=generatedSetupName(text);
|
|
1347
1368
|
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)});
|
|
1369
|
+
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
1370
|
s.textContent='';
|
|
1350
1371
|
s.setAttribute('type','application/stx-pending');
|
|
1351
1372
|
s.setAttribute('data-stx-route-script',slot);
|
|
@@ -1427,7 +1448,7 @@ else {
|
|
|
1427
1448
|
|
|
1428
1449
|
var scripts=routedBodyScripts.slice();
|
|
1429
1450
|
function addScript(text, runAlways, slot, owner){
|
|
1430
|
-
scripts.push({text:text,runAlways:!!runAlways,slot:slot||'',owner:owner||'',registry:REGISTRY_TEXT.test(text)});
|
|
1451
|
+
scripts.push({text:text,runAlways:!!runAlways,slot:slot||'',owner:owner||'',registry:REGISTRY_TEXT.test(text),composables:COMPOSABLES_TEXT.test(text)});
|
|
1431
1452
|
}
|
|
1432
1453
|
if(isLayoutChange){
|
|
1433
1454
|
// Also collect setup functions from <head>, and the page's module
|
|
@@ -1443,7 +1464,7 @@ else {
|
|
|
1443
1464
|
if(s.hasAttribute('src'))return;
|
|
1444
1465
|
if(!text.trim())return;
|
|
1445
1466
|
if(isSignalsRuntimeScript(s,text))return;
|
|
1446
|
-
if(isModuleRegistryScript(s))addScript(text,true,'','');
|
|
1467
|
+
if(isModuleRegistryScript(s)||isComposablesScript(s))addScript(text,true,'','');
|
|
1447
1468
|
else if(text.indexOf('__stx_setup_')!==-1)addScript(text,true);
|
|
1448
1469
|
});
|
|
1449
1470
|
} else {
|
|
@@ -1497,7 +1518,8 @@ else {
|
|
|
1497
1518
|
// so without this a component in the page body could run ahead of the
|
|
1498
1519
|
// registry it imports from. Stable: the order within each group holds.
|
|
1499
1520
|
var registryFirst=scripts.filter(function(e){return e.registry});
|
|
1500
|
-
|
|
1521
|
+
var composablesNext=scripts.filter(function(e){return !e.registry&&e.composables});
|
|
1522
|
+
if(registryFirst.length||composablesNext.length)scripts=registryFirst.concat(composablesNext,scripts.filter(function(e){return !e.registry&&!e.composables}));
|
|
1501
1523
|
|
|
1502
1524
|
// Push history state (before active link updates so location.pathname is current)
|
|
1503
1525
|
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.
|
|
4
|
+
"version": "0.2.333",
|
|
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",
|