bun-plugin-stx 0.2.51 → 0.2.54
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.
|
@@ -738,6 +738,10 @@ function getRouterScript() {
|
|
|
738
738
|
return false;
|
|
739
739
|
}
|
|
740
740
|
|
|
741
|
+
function shouldUseFragmentResponse(){
|
|
742
|
+
return containerSel==='main'||containerSel==='[data-stx-content]';
|
|
743
|
+
}
|
|
744
|
+
|
|
741
745
|
function navigate(url,pushState,force){
|
|
742
746
|
log('[router] navigate() called:',url,'isNavigating:',isNavigating);
|
|
743
747
|
if(isNavigating)return;
|
|
@@ -791,10 +795,13 @@ function getRouterScript() {
|
|
|
791
795
|
}
|
|
792
796
|
else {
|
|
793
797
|
if(force&&cache[targetPath])delete cache[targetPath];
|
|
794
|
-
// First fetch as fragment (SPA mode)
|
|
795
|
-
|
|
798
|
+
// First fetch as fragment (SPA mode) when the configured container is
|
|
799
|
+
// the page content. Custom app-shell containers need full documents so
|
|
800
|
+
// the router does not inject a <main> fragment into the wrong element.
|
|
801
|
+
var wantsFragment=shouldUseFragmentResponse();
|
|
802
|
+
fetch(url,{headers:wantsFragment?{'X-STX-Router':'true','Accept':'text/html'}:{'Accept':'text/html'}}).then(function(r){
|
|
796
803
|
if(!r.ok)throw new Error(r.status);
|
|
797
|
-
var isFragment=r.headers.get('X-STX-Fragment')==='true';
|
|
804
|
+
var isFragment=wantsFragment&&r.headers.get('X-STX-Fragment')==='true';
|
|
798
805
|
var newLayout=r.headers.get('X-STX-Layout')||'';
|
|
799
806
|
var newGroup=r.headers.get('X-STX-Layout-Group')||'';
|
|
800
807
|
// Layout change? Fetch the FULL page (no X-STX-Router header) and do full document swap
|
|
@@ -1032,6 +1039,9 @@ else {
|
|
|
1032
1039
|
document.querySelectorAll('script[data-stx-page]').forEach(function(s){s.remove()});
|
|
1033
1040
|
|
|
1034
1041
|
var scripts=[];
|
|
1042
|
+
function addScript(text, runAlways){
|
|
1043
|
+
scripts.push({text:text,runAlways:!!runAlways});
|
|
1044
|
+
}
|
|
1035
1045
|
if(isLayoutChange){
|
|
1036
1046
|
// Layout change: collect ALL scripts from the new document body
|
|
1037
1047
|
// (layout scripts, component mounts, setup functions \u2014 everything)
|
|
@@ -1044,7 +1054,7 @@ else {
|
|
|
1044
1054
|
// Skip the signals runtime IIFE \u2014 it's already loaded
|
|
1045
1055
|
if(text.indexOf("'use strict';var cloakStyle")!==-1)return;
|
|
1046
1056
|
if(text.indexOf('__stxRouter')!==-1)return;
|
|
1047
|
-
|
|
1057
|
+
addScript(text,true);
|
|
1048
1058
|
});
|
|
1049
1059
|
}
|
|
1050
1060
|
// Also collect setup functions from <head>
|
|
@@ -1052,7 +1062,7 @@ else {
|
|
|
1052
1062
|
var text=s.textContent||'';
|
|
1053
1063
|
if(s.hasAttribute('src'))return;
|
|
1054
1064
|
if(!text.trim())return;
|
|
1055
|
-
if(text.indexOf('__stx_setup_')!==-1)
|
|
1065
|
+
if(text.indexOf('__stx_setup_')!==-1)addScript(text,true);
|
|
1056
1066
|
});
|
|
1057
1067
|
} else {
|
|
1058
1068
|
// Same layout: collect scripts from the container
|
|
@@ -1060,26 +1070,27 @@ else {
|
|
|
1060
1070
|
var text=s.textContent||'';
|
|
1061
1071
|
if(s.hasAttribute('src'))return;
|
|
1062
1072
|
if(!text.trim())return;
|
|
1063
|
-
|
|
1073
|
+
addScript(text,true);
|
|
1064
1074
|
});
|
|
1065
|
-
// Collect
|
|
1075
|
+
// Collect page scripts from <head> AND <body> (outside container).
|
|
1066
1076
|
// SSG builds place the setup function in <body> before <main>, not
|
|
1067
1077
|
// in <head>. Without this, SPA navigation on static sites never
|
|
1068
1078
|
// runs the setup and reactive data stays empty.
|
|
1069
1079
|
var seenSetups={};
|
|
1070
|
-
scripts.forEach(function(
|
|
1080
|
+
scripts.forEach(function(entry){var t=entry.text;if(t.indexOf('__stx_setup_')!==-1)seenSetups[t.substring(0,80)]=1});
|
|
1071
1081
|
doc.querySelectorAll('script').forEach(function(s){
|
|
1072
1082
|
var text=s.textContent||'';
|
|
1073
1083
|
if(s.hasAttribute('src'))return;
|
|
1074
1084
|
if(!text.trim())return;
|
|
1075
|
-
if(text.indexOf('__stx_setup_')===-1)return;
|
|
1076
1085
|
// Skip signals runtime and router (they contain __stx_setup references but aren't setup functions)
|
|
1077
1086
|
if(text.indexOf("'use strict';var cloakStyle")!==-1)return;
|
|
1078
1087
|
if(text.indexOf('__stxRouter')!==-1)return;
|
|
1088
|
+
if(newContent.contains(s))return;
|
|
1089
|
+
if(text.indexOf('__stx_setup_')===-1&&!s.hasAttribute('data-stx-scoped')&&!s.hasAttribute('data-stx-page'))return;
|
|
1079
1090
|
var key=text.substring(0,80);
|
|
1080
1091
|
if(seenSetups[key])return;
|
|
1081
1092
|
seenSetups[key]=1;
|
|
1082
|
-
|
|
1093
|
+
addScript(text,true);
|
|
1083
1094
|
});
|
|
1084
1095
|
}
|
|
1085
1096
|
|
|
@@ -1109,7 +1120,9 @@ else {
|
|
|
1109
1120
|
|
|
1110
1121
|
// Execute page scripts FIRST \u2014 they define setup functions and set _latestSetup
|
|
1111
1122
|
function execScripts(){
|
|
1112
|
-
scripts.forEach(function(
|
|
1123
|
+
scripts.forEach(function(entry){
|
|
1124
|
+
var text=typeof entry==='string'?entry:entry.text;
|
|
1125
|
+
var runAlways=typeof entry==='string'?false:entry.runAlways;
|
|
1113
1126
|
// Skip scripts that were already executed (layout-level partials
|
|
1114
1127
|
// like theme.stx). Their top-level const/function declarations
|
|
1115
1128
|
// would throw "Identifier has already been declared" on re-execution.
|
|
@@ -1119,7 +1132,7 @@ else {
|
|
|
1119
1132
|
var h=hashScript(text);
|
|
1120
1133
|
var isSetup=text.indexOf('__stx_setup_')!==-1;
|
|
1121
1134
|
var hasImport=text.indexOf('import ')!==-1;
|
|
1122
|
-
if(!isSetup&&executedScriptHashes[h])return;
|
|
1135
|
+
if(!runAlways&&!isSetup&&executedScriptHashes[h])return;
|
|
1123
1136
|
executedScriptHashes[h]=1;
|
|
1124
1137
|
// Wrap scripts with import statements as modules (Bug 3 fix)
|
|
1125
1138
|
var ns=document.createElement('script');
|
|
@@ -1213,8 +1226,9 @@ else {
|
|
|
1213
1226
|
var key=cacheKey(href);
|
|
1214
1227
|
if(cache[key]||prefetching[key])return;
|
|
1215
1228
|
prefetching[key]=true;
|
|
1216
|
-
|
|
1217
|
-
|
|
1229
|
+
var wantsFragment=shouldUseFragmentResponse();
|
|
1230
|
+
fetch(href,{headers:wantsFragment?{'X-STX-Router':'true','Accept':'text/html'}:{'Accept':'text/html'}}).then(function(r){
|
|
1231
|
+
var isFrag=wantsFragment&&r.headers.get('X-STX-Fragment')==='true';
|
|
1218
1232
|
var pLayout=r.headers.get('X-STX-Layout')||'';
|
|
1219
1233
|
var pGroup=r.headers.get('X-STX-Layout-Group')||'';
|
|
1220
1234
|
return r.text().then(function(html){return{html:isFrag?'<!--stx-fragment-->'+html:html,layout:pLayout,layoutGroup:pGroup}});
|
|
@@ -1315,7 +1329,8 @@ else {
|
|
|
1315
1329
|
prefetch:function(url){
|
|
1316
1330
|
var key=cacheKey(url);
|
|
1317
1331
|
if(!cache[key]){
|
|
1318
|
-
|
|
1332
|
+
var wantsFragment=shouldUseFragmentResponse();
|
|
1333
|
+
fetch(url,{headers:wantsFragment?{'X-STX-Router':'true'}:{'Accept':'text/html'}}).then(function(r){var isFrag=wantsFragment&&r.headers.get('X-STX-Fragment')==='true';var pLayout=r.headers.get('X-STX-Layout')||'';var pGroup=r.headers.get('X-STX-Layout-Group')||'';return r.text().then(function(html){return{html:isFrag?'<!--stx-fragment-->'+html:html,layout:pLayout,layoutGroup:pGroup}})}).then(function(result){cache[key]=result.html;layoutCache[key]=result.layout;layoutGroupCache[key]=result.layoutGroup}).catch(function(){});
|
|
1319
1334
|
}
|
|
1320
1335
|
},
|
|
1321
1336
|
clearCache:function(){for(var k in cache)delete cache[k];for(var lk in layoutCache)delete layoutCache[lk];for(var gk in layoutGroupCache)delete layoutGroupCache[gk]},
|
package/dist/serve.js
CHANGED
|
@@ -8959,7 +8959,7 @@ After installing: bun add bun-plugin-stx`);
|
|
|
8959
8959
|
pageMiddlewarePatterns.length = 0;
|
|
8960
8960
|
await Promise.all(files.map((f) => detectPageMiddleware(f)));
|
|
8961
8961
|
try {
|
|
8962
|
-
const { Router } = await import("./chunk-
|
|
8962
|
+
const { Router } = await import("./chunk-nznv3e0m.js");
|
|
8963
8963
|
const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
|
|
8964
8964
|
const router = new Router(process19.cwd(), { pagesDirs });
|
|
8965
8965
|
console.log(`[stx] Generated ${router.routes.length} routes \u2192 .stx/routes.ts`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-plugin-stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.54",
|
|
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",
|
|
@@ -61,19 +61,19 @@
|
|
|
61
61
|
],
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "bun --bun build.ts",
|
|
64
|
-
"lint": "
|
|
65
|
-
"lint:fix": "
|
|
66
|
-
"fresh": "
|
|
67
|
-
"changelog": "
|
|
64
|
+
"lint": "bun x --bun pickier lint",
|
|
65
|
+
"lint:fix": "bun x --bun pickier lint --fix",
|
|
66
|
+
"fresh": "bun x rimraf node_modules/ bun.lock && bun i",
|
|
67
|
+
"changelog": "bun x changelogen --output CHANGELOG.md",
|
|
68
68
|
"prepublishOnly": "bun run build",
|
|
69
|
-
"release": "bun run changelog &&
|
|
69
|
+
"release": "bun run changelog && bun x bumpp package.json --all",
|
|
70
70
|
"test": "bun test --preload ../../test-utils/happy-dom.ts",
|
|
71
71
|
"test:watch": "bun test --watch --preload ../../test-utils/happy-dom.ts",
|
|
72
72
|
"test:coverage": "bun test --coverage --preload ../../test-utils/happy-dom.ts",
|
|
73
73
|
"typecheck": "bun tsc --noEmit"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@stacksjs/stx": "0.2.
|
|
77
|
-
"stx-router": "0.2.
|
|
76
|
+
"@stacksjs/stx": "0.2.54",
|
|
77
|
+
"stx-router": "0.2.53"
|
|
78
78
|
}
|
|
79
79
|
}
|