@stacksjs/stx 0.2.532 → 0.2.534
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/{chunk-y4qks0bd.js → chunk-01343ehq.js} +2 -2
- package/dist/chunk-0e5nasyf.js +2 -0
- package/dist/chunk-13zbt9py.js +2 -0
- package/dist/{chunk-9w2vmfha.js → chunk-1c4t7ncb.js} +2 -2
- package/dist/{chunk-gxfnmjzp.js → chunk-1xgs9gd5.js} +2 -2
- package/dist/{chunk-4gt0r98p.js → chunk-2bvk0qyd.js} +2 -2
- package/dist/{chunk-y7ds4qyb.js → chunk-2h4f37kx.js} +2 -2
- package/dist/{chunk-q6e45gnw.js → chunk-2kvbg3t5.js} +3 -3
- package/dist/{chunk-xdtz2v5r.js → chunk-2n4je46m.js} +2 -2
- package/dist/{chunk-xcfhy5bj.js → chunk-33bzhsyw.js} +2 -2
- package/dist/{chunk-7ybgfk0m.js → chunk-3nk8cnrm.js} +2 -2
- package/dist/{chunk-gsxb0ry9.js → chunk-3r1m3tyr.js} +1 -1
- package/dist/chunk-3zs8yxy0.js +2 -0
- package/dist/{chunk-khwj964t.js → chunk-40hbpz2b.js} +3 -3
- package/dist/chunk-4a7v51vh.js +2 -0
- package/dist/{chunk-xtknewf7.js → chunk-4hyhr5r7.js} +1 -1
- package/dist/{chunk-hp1tnxzb.js → chunk-4pxc3r1p.js} +4 -4
- package/dist/chunk-4qts8zk7.js +2 -0
- package/dist/{chunk-587ehsxn.js → chunk-4r7s3862.js} +2 -2
- package/dist/chunk-4y2av4ev.js +2 -0
- package/dist/chunk-5g498pdp.js +2 -0
- package/dist/chunk-5gq8m2m7.js +2 -0
- package/dist/chunk-5wx323bm.js +2 -0
- package/dist/{chunk-d2r8t40y.js → chunk-66s4nhp7.js} +2 -2
- package/dist/{chunk-d7x6n702.js → chunk-6dtmants.js} +3 -3
- package/dist/chunk-6rcxtdh3.js +2 -0
- package/dist/{chunk-st79dqpz.js → chunk-6sd4zdtg.js} +1 -1
- package/dist/{chunk-zpdq0kx1.js → chunk-6tnh3cyq.js} +1 -1
- package/dist/chunk-6va8wt88.js +2 -0
- package/dist/chunk-7v2j9bmc.js +2 -0
- package/dist/chunk-7zgtdap7.js +2 -0
- package/dist/{chunk-0pebjkzx.js → chunk-843y0pfg.js} +4 -4
- package/dist/{chunk-4xxhprts.js → chunk-8chxczpj.js} +3 -3
- package/dist/{chunk-b7xdk1g4.js → chunk-8m1y1kyr.js} +5 -5
- package/dist/chunk-90kzf313.js +2 -0
- package/dist/{chunk-t6769zcy.js → chunk-93n6yv5x.js} +12 -12
- package/dist/chunk-94rg5s6c.js +2 -0
- package/dist/chunk-9674w2gm.js +2 -0
- package/dist/{chunk-gvw8wh29.js → chunk-9p6bt089.js} +3 -3
- package/dist/{chunk-kg77xs08.js → chunk-bczcm7jk.js} +2 -2
- package/dist/{chunk-rs46hksk.js → chunk-bxsehntq.js} +1 -1
- package/dist/{chunk-vg8thz41.js → chunk-c56qtne1.js} +1 -1
- package/dist/chunk-d1jxmhph.js +2 -0
- package/dist/{chunk-5tj6expd.js → chunk-d7zterbp.js} +2 -2
- package/dist/{chunk-664503e6.js → chunk-d871008z.js} +4 -4
- package/dist/chunk-dekpf1ry.js +2 -0
- package/dist/chunk-epa1c4q4.js +2 -0
- package/dist/{chunk-xb0785wp.js → chunk-f3q84h7b.js} +2 -2
- package/dist/{chunk-g060jncp.js → chunk-fqfqyn48.js} +4 -4
- package/dist/{chunk-g5t10z04.js → chunk-gnx0fzne.js} +60 -60
- package/dist/chunk-gsc5t942.js +2 -0
- package/dist/chunk-gsm1y1kb.js +2 -0
- package/dist/chunk-gxedmh17.js +2 -0
- package/dist/{chunk-9xq5yer8.js → chunk-h4crv0by.js} +1 -1
- package/dist/{chunk-pr5q4wev.js → chunk-hp8g2q2n.js} +1 -1
- package/dist/{chunk-38w14qs7.js → chunk-hvpzy98g.js} +1 -1
- package/dist/chunk-j9c0yam7.js +2 -0
- package/dist/{chunk-12e4a0ab.js → chunk-jbfad9cc.js} +2 -2
- package/dist/chunk-jv3jj612.js +2 -0
- package/dist/chunk-jvqas8y2.js +2 -0
- package/dist/{chunk-rwn3b21z.js → chunk-k3v13vfr.js} +2 -2
- package/dist/chunk-kcs7hyep.js +2 -0
- package/dist/chunk-kvp0at16.js +2 -0
- package/dist/{chunk-31c1g3rt.js → chunk-m011s2ha.js} +3 -3
- package/dist/{chunk-2jk0vceh.js → chunk-m56m95gk.js} +2 -2
- package/dist/{chunk-7s14bthq.js → chunk-m5fw8jq1.js} +2 -2
- package/dist/chunk-m7jmpech.js +2 -0
- package/dist/chunk-m8n9wxba.js +2 -0
- package/dist/{chunk-fyxydww2.js → chunk-mjdyyekx.js} +2 -2
- package/dist/{chunk-ennxrn5g.js → chunk-nd8v4xgb.js} +5 -5
- package/dist/chunk-ngma9vzc.js +2 -0
- package/dist/{chunk-rtk6n3vh.js → chunk-ngxqydsg.js} +3 -3
- package/dist/{chunk-ee4wwr89.js → chunk-nmy4x6dx.js} +4 -4
- package/dist/chunk-pz1mjgsp.js +2 -0
- package/dist/{chunk-er031j13.js → chunk-qfc912e5.js} +2 -2
- package/dist/chunk-qk3ptn6h.js +2 -0
- package/dist/{chunk-03wggzg8.js → chunk-qmza4327.js} +2 -2
- package/dist/{chunk-j8pacd7m.js → chunk-qqr4rn9p.js} +4 -4
- package/dist/chunk-rx4hz615.js +2 -0
- package/dist/chunk-shf0hd05.js +2 -0
- package/dist/{chunk-3vvppnws.js → chunk-sqb6gkzf.js} +8374 -8374
- package/dist/chunk-t1g1sp2z.js +2 -0
- package/dist/{chunk-m2v04c6v.js → chunk-tgc645pa.js} +45 -45
- package/dist/{chunk-2dzd2h15.js → chunk-tkvp3rz0.js} +1 -1
- package/dist/{chunk-458etq5a.js → chunk-tqnh98j7.js} +3 -3
- package/dist/chunk-tr9bjtqx.js +2 -0
- package/dist/{chunk-2y6tzn6d.js → chunk-ty1v368m.js} +2 -2
- package/dist/{chunk-grb3kfya.js → chunk-v4r8nzf3.js} +1 -1
- package/dist/{chunk-p8yh7mgr.js → chunk-v9vvzdag.js} +2 -2
- package/dist/{chunk-0wvsfs4s.js → chunk-vb4xxpa6.js} +2 -2
- package/dist/chunk-vfnerp7h.js +2 -0
- package/dist/{chunk-tkeabv04.js → chunk-vhfwnvmc.js} +5 -5
- package/dist/{chunk-15r72kw7.js → chunk-vjdj0ex3.js} +1 -1
- package/dist/{chunk-9pztpvvk.js → chunk-wh7xn313.js} +1 -1
- package/dist/chunk-wjt46tdp.js +2 -0
- package/dist/chunk-wxy9re1a.js +2 -0
- package/dist/{chunk-kwvexxey.js → chunk-x607yxrc.js} +3 -3
- package/dist/{chunk-3zyvhf4p.js → chunk-xey01yna.js} +1 -1
- package/dist/{chunk-stbsqy7e.js → chunk-xwrbrg1q.js} +1 -1
- package/dist/{chunk-9sqjmd9a.js → chunk-y18yvcjb.js} +5 -5
- package/dist/chunk-ydtnskdv.js +2 -0
- package/dist/{chunk-ky25egh1.js → chunk-yw3cqy43.js} +1 -1
- package/dist/{chunk-1945hk44.js → chunk-z9r3tqyr.js} +1 -1
- package/dist/chunk-zeve89kw.js +2 -0
- package/dist/cli.js +12 -12
- package/dist/client/signals-appearance-runtime.d.ts +2 -0
- package/dist/client/signals-appearance-runtime.js +283 -0
- package/dist/client/signals-authoring-runtime.d.ts +2 -0
- package/dist/client/signals-authoring-runtime.js +187 -0
- package/dist/client/signals-binding-utils-runtime.d.ts +2 -0
- package/dist/client/signals-binding-utils-runtime.js +130 -0
- package/dist/client/signals-bootstrap-runtime.d.ts +4 -0
- package/dist/client/signals-bootstrap-runtime.js +24 -0
- package/dist/client/signals-class-runtime.d.ts +2 -0
- package/dist/client/signals-class-runtime.js +69 -0
- package/dist/client/signals-component-api-runtime.d.ts +1 -0
- package/dist/client/signals-component-api-runtime.js +57 -0
- package/dist/client/signals-component-hydration-runtime.d.ts +2 -0
- package/dist/client/signals-component-hydration-runtime.js +147 -0
- package/dist/client/signals-component-props-runtime.d.ts +2 -0
- package/dist/client/signals-component-props-runtime.js +90 -0
- package/dist/client/signals-conditional-chain-runtime.d.ts +2 -0
- package/dist/client/signals-conditional-chain-runtime.js +39 -0
- package/dist/client/signals-conditional-component-runtime.d.ts +2 -0
- package/dist/client/signals-conditional-component-runtime.js +82 -0
- package/dist/client/signals-container-cleanup-runtime.d.ts +2 -0
- package/dist/client/signals-container-cleanup-runtime.js +42 -0
- package/dist/client/signals-context-runtime.d.ts +2 -0
- package/dist/client/signals-context-runtime.js +48 -0
- package/dist/client/signals-cookie-runtime.d.ts +2 -0
- package/dist/client/signals-cookie-runtime.js +56 -0
- package/dist/client/signals-devtools-runtime.d.ts +2 -0
- package/dist/client/signals-devtools-runtime.js +136 -0
- package/dist/client/signals-dialog-runtime.d.ts +2 -0
- package/dist/client/signals-dialog-runtime.js +195 -0
- package/dist/client/signals-dom-ready-runtime.d.ts +2 -0
- package/dist/client/signals-dom-ready-runtime.js +306 -0
- package/dist/client/signals-drawer-runtime.d.ts +2 -0
- package/dist/client/signals-drawer-runtime.js +39 -0
- package/dist/client/signals-effect-runtime.d.ts +2 -0
- package/dist/client/signals-effect-runtime.js +157 -0
- package/dist/client/signals-event-shorthand-runtime.d.ts +2 -0
- package/dist/client/signals-event-shorthand-runtime.js +88 -0
- package/dist/client/signals-expression-compiler-runtime.d.ts +2 -0
- package/dist/client/signals-expression-compiler-runtime.js +59 -0
- package/dist/client/signals-expression-runtime.d.ts +2 -0
- package/dist/client/signals-expression-runtime.js +67 -0
- package/dist/client/signals-fetch-runtime.d.ts +2 -0
- package/dist/client/signals-fetch-runtime.js +144 -0
- package/dist/client/signals-fetch-transport-runtime.d.ts +2 -0
- package/dist/client/signals-fetch-transport-runtime.js +216 -0
- package/dist/client/signals-for-runtime.d.ts +2 -0
- package/dist/client/signals-for-runtime.js +647 -0
- package/dist/client/signals-globals-runtime.d.ts +2 -0
- package/dist/client/signals-globals-runtime.js +66 -0
- package/dist/client/signals-handler-runtime.d.ts +2 -0
- package/dist/client/signals-handler-runtime.js +80 -0
- package/dist/client/signals-head-runtime.d.ts +2 -0
- package/dist/client/signals-head-runtime.js +92 -0
- package/dist/client/signals-helpers-runtime.d.ts +2 -0
- package/dist/client/signals-helpers-runtime.js +137 -0
- package/dist/client/signals-host-runtime.d.ts +9 -0
- package/dist/client/signals-host-runtime.js +132 -0
- package/dist/client/signals-hydration-audit-runtime.d.ts +2 -0
- package/dist/client/signals-hydration-audit-runtime.js +209 -0
- package/dist/client/signals-hydration-runtime.d.ts +2 -0
- package/dist/client/signals-hydration-runtime.js +52 -0
- package/dist/client/signals-if-chain-runtime.d.ts +2 -0
- package/dist/client/signals-if-chain-runtime.js +283 -0
- package/dist/client/signals-if-runtime.d.ts +2 -0
- package/dist/client/signals-if-runtime.js +346 -0
- package/dist/client/signals-kept-runtime.d.ts +2 -0
- package/dist/client/signals-kept-runtime.js +62 -0
- package/dist/client/signals-lazy-hydration-runtime.d.ts +2 -0
- package/dist/client/signals-lazy-hydration-runtime.js +133 -0
- package/dist/client/signals-lifecycle-runtime.d.ts +2 -0
- package/dist/client/signals-lifecycle-runtime.js +114 -0
- package/dist/client/signals-loop-component-remap-runtime.d.ts +2 -0
- package/dist/client/signals-loop-component-remap-runtime.js +66 -0
- package/dist/client/signals-loop-conditional-runtime.d.ts +2 -0
- package/dist/client/signals-loop-conditional-runtime.js +48 -0
- package/dist/client/signals-loop-row-runtime.d.ts +2 -0
- package/dist/client/signals-loop-row-runtime.js +41 -0
- package/dist/client/signals-manifest-hydration-runtime.d.ts +2 -0
- package/dist/client/signals-manifest-hydration-runtime.js +82 -0
- package/dist/client/signals-model-runtime.d.ts +2 -0
- package/dist/client/signals-model-runtime.js +156 -0
- package/dist/client/signals-mount-runtime.d.ts +1 -0
- package/dist/client/signals-mount-runtime.js +231 -0
- package/dist/client/signals-navigation-runtime.d.ts +2 -0
- package/dist/client/signals-navigation-runtime.js +198 -0
- package/dist/client/signals-optimistic-runtime.d.ts +2 -0
- package/dist/client/signals-optimistic-runtime.js +34 -0
- package/dist/client/signals-overlay-runtime.d.ts +2 -0
- package/dist/client/signals-overlay-runtime.js +352 -0
- package/dist/client/signals-pipe-runtime.d.ts +2 -0
- package/dist/client/signals-pipe-runtime.js +177 -0
- package/dist/client/signals-process-element-runtime.d.ts +1 -0
- package/dist/client/signals-process-element-runtime.js +696 -0
- package/dist/client/signals-proxy-runtime.d.ts +2 -0
- package/dist/client/signals-proxy-runtime.js +78 -0
- package/dist/client/signals-public-api-runtime.d.ts +1 -0
- package/dist/client/signals-public-api-runtime.js +120 -0
- package/dist/client/signals-query-runtime.d.ts +2 -0
- package/dist/client/signals-query-runtime.js +351 -0
- package/dist/client/signals-reactive-core-bootstrap-runtime.d.ts +1 -0
- package/dist/client/signals-reactive-core-bootstrap-runtime.js +30 -0
- package/dist/client/signals-reactive-runtime.d.ts +2 -0
- package/dist/client/signals-reactive-runtime.js +67 -0
- package/dist/client/signals-ref-runtime.d.ts +2 -0
- package/dist/client/signals-ref-runtime.js +33 -0
- package/dist/client/signals-scope-disposal-runtime.d.ts +2 -0
- package/dist/client/signals-scope-disposal-runtime.js +195 -0
- package/dist/client/signals-scope-traversal-runtime.d.ts +2 -0
- package/dist/client/signals-scope-traversal-runtime.js +42 -0
- package/dist/client/signals-show-runtime.d.ts +2 -0
- package/dist/client/signals-show-runtime.js +54 -0
- package/dist/client/signals-spa-load-control-runtime.d.ts +2 -0
- package/dist/client/signals-spa-load-control-runtime.js +42 -0
- package/dist/client/signals-spa-load-runtime.d.ts +2 -0
- package/dist/client/signals-spa-load-runtime.js +187 -0
- package/dist/client/signals-state-runtime.d.ts +2 -0
- package/dist/client/signals-state-runtime.js +125 -0
- package/dist/client/signals-storage-runtime.d.ts +2 -0
- package/dist/client/signals-storage-runtime.js +79 -0
- package/dist/client/signals-store-registry-runtime.d.ts +1 -0
- package/dist/client/signals-store-registry-runtime.js +461 -0
- package/dist/client/signals-style-runtime.d.ts +2 -0
- package/dist/client/signals-style-runtime.js +35 -0
- package/dist/client/signals-suspense-runtime.d.ts +2 -0
- package/dist/client/signals-suspense-runtime.js +59 -0
- package/dist/client/signals-timer-runtime.d.ts +2 -0
- package/dist/client/signals-timer-runtime.js +378 -0
- package/dist/client/signals-toast-runtime.d.ts +2 -0
- package/dist/client/signals-toast-runtime.js +206 -0
- package/dist/client/signals-tooltip-runtime.d.ts +2 -0
- package/dist/client/signals-tooltip-runtime.js +40 -0
- package/dist/client/signals-transition-group-runtime.d.ts +2 -0
- package/dist/client/signals-transition-group-runtime.js +92 -0
- package/dist/client/signals-websocket-runtime.d.ts +2 -0
- package/dist/client/signals-websocket-runtime.js +138 -0
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/pwa.js +3 -3
- package/dist/signals-context-runtime.d.ts +2 -0
- package/dist/signals-drawer-runtime.d.ts +2 -0
- package/dist/signals-host-runtime.d.ts +9 -0
- package/dist/signals-loop-conditional-runtime.d.ts +2 -0
- package/dist/signals-manifest-hydration-runtime.d.ts +2 -0
- package/dist/signals-optimistic-runtime.d.ts +2 -0
- package/dist/signals-overlay-runtime.d.ts +2 -0
- package/dist/signals-scope-disposal-runtime.d.ts +2 -0
- package/dist/signals-spa-load-control-runtime.d.ts +2 -0
- package/dist/signals-storage-runtime.d.ts +2 -0
- package/dist/signals.js +141 -9900
- package/dist/ssg.js +3 -3
- package/package.json +5 -5
- package/dist/chunk-0p9pwd61.js +0 -2
- package/dist/chunk-0zmv31nc.js +0 -2
- package/dist/chunk-28xtazwz.js +0 -2
- package/dist/chunk-2936t942.js +0 -2
- package/dist/chunk-29qwmthc.js +0 -2
- package/dist/chunk-323cxa69.js +0 -2
- package/dist/chunk-375zp0vr.js +0 -2
- package/dist/chunk-3w49r16x.js +0 -2
- package/dist/chunk-8bcvb86w.js +0 -2
- package/dist/chunk-8gmb3k1p.js +0 -2
- package/dist/chunk-a15yzfc6.js +0 -2
- package/dist/chunk-d4155ec5.js +0 -2
- package/dist/chunk-dd31q423.js +0 -2
- package/dist/chunk-f2q5bckn.js +0 -2
- package/dist/chunk-fhx35529.js +0 -2
- package/dist/chunk-h1y5q942.js +0 -2
- package/dist/chunk-h791c7sb.js +0 -2
- package/dist/chunk-h88jcr3k.js +0 -2
- package/dist/chunk-heq5c0gd.js +0 -2
- package/dist/chunk-j3b24e77.js +0 -2
- package/dist/chunk-jpck8nm5.js +0 -2
- package/dist/chunk-m4d99a9r.js +0 -2
- package/dist/chunk-ng2sdph7.js +0 -2
- package/dist/chunk-qs3p7sc6.js +0 -2
- package/dist/chunk-rchwwcxy.js +0 -2
- package/dist/chunk-rk4mttds.js +0 -2
- package/dist/chunk-rma3bv36.js +0 -2
- package/dist/chunk-rp5a91ak.js +0 -2
- package/dist/chunk-sp5x96rn.js +0 -2
- package/dist/chunk-t2mjeezd.js +0 -2
- package/dist/chunk-t61j834x.js +0 -2
- package/dist/chunk-v2vg5jqq.js +0 -2
- package/dist/chunk-vmfw4svt.js +0 -2
- package/dist/chunk-w6ecbk3y.js +0 -2
- package/dist/chunk-wbv6vjhm.js +0 -2
- package/dist/chunk-wfbr3txe.js +0 -2
- package/dist/chunk-wpnv0naj.js +0 -2
- package/dist/chunk-wwny5dk9.js +0 -2
- package/dist/chunk-x55avrcf.js +0 -2
- package/dist/chunk-yts2745t.js +0 -2
- package/dist/chunk-zah67v44.js +0 -2
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
export const SIGNALS_SPA_LOAD_RUNTIME = ` function _handleStxLoad() {
|
|
2
|
+
_stxLoadTimer = null;
|
|
3
|
+
console.log('[stx:load] START. mountQueue:', mountQueue.length, '_latestSetup:', !!window.stx._latestSetup);
|
|
4
|
+
|
|
5
|
+
// Run the outgoing page's destroy callbacks before re-initializing. Taken
|
|
6
|
+
// out of their queue first, so one that registers another lands in the
|
|
7
|
+
// next generation instead of being cleared unrun.
|
|
8
|
+
var departing = departingDestroys !== null ? departingDestroys : destroyCallbacks.splice(0);
|
|
9
|
+
departingDestroys = null;
|
|
10
|
+
departing.forEach(function(fn) {
|
|
11
|
+
try { fn(); }
|
|
12
|
+
catch (e) { console.warn('[stx] destroy callback error:', e); }
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Re-process scoped components in new content
|
|
16
|
+
var routerOpts = window.STX_ROUTER_OPTIONS || window.__stxRouterConfig || {};
|
|
17
|
+
var container = document.querySelector('[data-stx-content]')
|
|
18
|
+
|| (routerOpts.container ? document.querySelector(routerOpts.container) : null)
|
|
19
|
+
|| document.querySelector('main')
|
|
20
|
+
|| document.querySelector('#main-content')
|
|
21
|
+
|| document.body;
|
|
22
|
+
|
|
23
|
+
// Apply new page's SFC setup function. During SPA navigation, re-executed page
|
|
24
|
+
// scripts set window.stx._latestSetup to the new setup function. This takes priority
|
|
25
|
+
// over the stale data-stx attribute on body> (which has the PREVIOUS page's function name).
|
|
26
|
+
var usedLatestSetup = false;
|
|
27
|
+
if (window.stx._latestSetup && typeof window.stx._latestSetup === 'function') {
|
|
28
|
+
try {
|
|
29
|
+
var setupResult = window.stx._latestSetup();
|
|
30
|
+
// Keep _latestSetup for re-fires (HMR, auto-refresh re-navigation)
|
|
31
|
+
// It will be overwritten when a NEW page's script sets it
|
|
32
|
+
usedLatestSetup = true;
|
|
33
|
+
if (typeof setupResult === 'object' && setupResult !== null) {
|
|
34
|
+
console.log('[stx:load] _latestSetup keys:', Object.keys(setupResult).slice(0, 10));
|
|
35
|
+
Object.assign(componentScope, setupResult);
|
|
36
|
+
}
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error('[stx:load] _latestSetup error:', e);
|
|
39
|
+
usedLatestSetup = true; // Don't fall back to stale data-stx
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
console.log('[stx:load] usedLatestSetup:', usedLatestSetup, 'scope keys:', Object.keys(componentScope).slice(0, 10));
|
|
43
|
+
|
|
44
|
+
// Only fall back to [data-stx] attribute lookup if _latestSetup wasn't available.
|
|
45
|
+
// This handles the initial DOMContentLoaded-like case and pages that don't use _latestSetup.
|
|
46
|
+
if (!usedLatestSetup) {
|
|
47
|
+
document.querySelectorAll('[data-stx]').forEach(function(el) {
|
|
48
|
+
var setupName = el.getAttribute('data-stx');
|
|
49
|
+
if (setupName && window[setupName]) {
|
|
50
|
+
var result = window[setupName]();
|
|
51
|
+
if (typeof result === 'object') Object.assign(componentScope, result);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
var spaPageScopeSnapshot = { ...componentScope };
|
|
56
|
+
|
|
57
|
+
// Routed component mount scripts execute after DOMContentLoaded. Queue them
|
|
58
|
+
// until the destination page setup is active so projected props and parent
|
|
59
|
+
// event handlers resolve against the caller, matching initial hydration.
|
|
60
|
+
mountQueue.forEach(function(fn) { fn(); });
|
|
61
|
+
mountQueue = [];
|
|
62
|
+
|
|
63
|
+
// Initialize x-data scopes after SPA fragment swap.
|
|
64
|
+
// On full page load, the reactive bridge <script> calls initScope(). But after SPA
|
|
65
|
+
// navigation, only the HTML fragment is swapped \u2014 the bridge script isn't re-executed.
|
|
66
|
+
// The server renames x-data \u2192 data-stx-xdata so we can read the state expression here.
|
|
67
|
+
if (window.__stx_reactive && window.__stx_reactive.initScope) {
|
|
68
|
+
container.querySelectorAll('[data-stx-xdata]').forEach(function(el) {
|
|
69
|
+
var scopeId = el.getAttribute('data-stx-scope');
|
|
70
|
+
// Skip if scope already registered (e.g. nav scope that persists across navigations)
|
|
71
|
+
if (scopeId && window.stx._scopes && window.stx._scopes[scopeId]) return;
|
|
72
|
+
var xdata = el.getAttribute('data-stx-xdata');
|
|
73
|
+
if (!xdata) return;
|
|
74
|
+
// Assign a scope ID if not already present
|
|
75
|
+
if (!scopeId) {
|
|
76
|
+
scopeId = '__stx_scope_spa_' + (++window.stx._scopeCounter);
|
|
77
|
+
el.setAttribute('data-stx-scope', scopeId);
|
|
78
|
+
}
|
|
79
|
+
// The init expression, which used to be dropped here. A scope
|
|
80
|
+
// re-initialized with its data and none of its setup renders every
|
|
81
|
+
// binding at its initial value and starts nothing - a live region
|
|
82
|
+
// showing its empty state forever, which is indistinguishable from one
|
|
83
|
+
// where nothing has happened yet.
|
|
84
|
+
var xinit = el.getAttribute('data-stx-xinit');
|
|
85
|
+
console.log('[stx:load] initializing x-data scope:', scopeId, xdata.substring(0, 40));
|
|
86
|
+
window.__stx_reactive.initScope(el, xdata, [], {}, xinit || null);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Apply scope from [data-stx-scope] elements and process them.
|
|
91
|
+
// Walk document.body (not just container) so layout-level scopes dropped
|
|
92
|
+
// by a full-body-swap SPA nav (e.g. nav/header/footer when the layout
|
|
93
|
+
// group changes) get bound. The __stx_disposers guard makes the walk
|
|
94
|
+
// idempotent \u2014 persistent layout scopes across same-layout navs are
|
|
95
|
+
// skipped instead of double-disposed. See stacksjs/stx#1697.
|
|
96
|
+
document.body.querySelectorAll('[data-stx-scope]').forEach(function(el) {
|
|
97
|
+
var scopeId = el.getAttribute('data-stx-scope');
|
|
98
|
+
var scopeVars = window.stx._scopes && window.stx._scopes[scopeId];
|
|
99
|
+
// Record the bound element for the orphan sweep (#1775) \u2014 see the
|
|
100
|
+
// DOMContentLoaded walk above for the rationale.
|
|
101
|
+
if (scopeVars) scopeVars.__el = el;
|
|
102
|
+
// Deferred island reached via SPA navigation (#1746): its setup script is
|
|
103
|
+
// inert (type="stx/island"), so the scope isn't registered yet. Arm the
|
|
104
|
+
// hydration trigger (deferHydration) instead of skipping it \u2014 mirrors the
|
|
105
|
+
// initial-load DOMContentLoaded path, which has the same guard. Without
|
|
106
|
+
// this, a client="visible|idle|\u2026" island on a page reached by SPA nav
|
|
107
|
+
// (inline OR chunked) never hydrates.
|
|
108
|
+
if (!scopeVars && el.hasAttribute && el.hasAttribute('stx-hydrate')
|
|
109
|
+
&& !el.__stx_hydration_scheduled
|
|
110
|
+
&& document.querySelector('script[data-stx-island="' + scopeId + '"]')) {
|
|
111
|
+
processElement(el, componentScope);
|
|
112
|
+
el.removeAttribute('x-cloak');
|
|
113
|
+
el.querySelectorAll('[x-cloak]').forEach(function(c) { c.removeAttribute('x-cloak'); });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!scopeVars) return;
|
|
117
|
+
el.__stx_parent_scope = el.__stx_parent_scope
|
|
118
|
+
|| resolveComponentCallerScope(el, spaPageScopeSnapshot);
|
|
119
|
+
bindParentComponentProps(el, el.__stx_parent_scope);
|
|
120
|
+
// Already bound: a layout component that stayed on the page. Its
|
|
121
|
+
// bindings are live and read its own scope, so there is nothing to
|
|
122
|
+
// merge \u2014 and merging it AFTER the destination page's setup let a name
|
|
123
|
+
// the two share take the component's value for the page. The offline
|
|
124
|
+
// banner's connected flag read as a Settings card's "Connected".
|
|
125
|
+
if (el.__stx_disposers) return;
|
|
126
|
+
Object.assign(componentScope, scopeVars);
|
|
127
|
+
var disposeEffects = trackEffects(function() { processElement(el, componentScope); });
|
|
128
|
+
el.__stx_disposers = disposeEffects;
|
|
129
|
+
// A replacement layout's scope can live outside the router container.
|
|
130
|
+
// Reveal it after binding, matching the initial hydration and mount paths.
|
|
131
|
+
el.removeAttribute('x-cloak');
|
|
132
|
+
el.querySelectorAll('[x-cloak]').forEach(function(c) { c.removeAttribute('x-cloak'); });
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// The page's own names win over its components' locals. The walk above
|
|
136
|
+
// merges each component's locals into the scope the container is bound
|
|
137
|
+
// with, so a component declaring a name the page also declares took it
|
|
138
|
+
// over for the whole page: HQ's coach dashboard aliases store signals as
|
|
139
|
+
// loading and roster, a card further down declares its own loading and
|
|
140
|
+
// roster, and reached by the router the page's
|
|
141
|
+
// :if="loading && !roster.length" read the card's and never cleared. A
|
|
142
|
+
// full load binds the page before any component, so it never saw this.
|
|
143
|
+
// A component's own bindings resolve its locals through its scope element,
|
|
144
|
+
// and a name only a component declares stays reachable as before.
|
|
145
|
+
Object.assign(componentScope, spaPageScopeSnapshot);
|
|
146
|
+
|
|
147
|
+
// Process the container content \u2014 bind {{ }}, :attr, @event directives.
|
|
148
|
+
// Run synchronously (not in setTimeout) so componentScope is captured correctly.
|
|
149
|
+
// The DOMContentLoaded path processes body> synchronously \u2014 the SPA path must match.
|
|
150
|
+
console.log('[stx:load] container:', container.tagName, '__stx_scope:', !!container.__stx_scope, 'scope keys:', Object.keys(componentScope).slice(0, 10));
|
|
151
|
+
if (!container.__stx_scope) {
|
|
152
|
+
// Dispose previous effects on the container (from prior navigation)
|
|
153
|
+
if (container.__stx_disposers && typeof container.__stx_disposers === 'function') {
|
|
154
|
+
container.__stx_disposers();
|
|
155
|
+
}
|
|
156
|
+
console.log('[stx:load] processElement on container');
|
|
157
|
+
var disposeEffects = trackEffects(function() { processElement(container, componentScope); });
|
|
158
|
+
container.__stx_disposers = disposeEffects;
|
|
159
|
+
} else {
|
|
160
|
+
console.log('[stx:load] SKIPPED processElement \u2014 container has __stx_scope');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Remove x-cloak
|
|
164
|
+
container.removeAttribute('x-cloak');
|
|
165
|
+
container.querySelectorAll('[x-cloak]').forEach(function(c) { c.removeAttribute('x-cloak'); });
|
|
166
|
+
|
|
167
|
+
// Fire mount callbacks from scoped components. Walk document.body so
|
|
168
|
+
// layout-level scopes added by a full-body swap mount; __mounted guard
|
|
169
|
+
// prevents persistent layout scopes from re-firing their onMount on
|
|
170
|
+
// every same-layout SPA nav. See stacksjs/stx#1697.
|
|
171
|
+
document.body.querySelectorAll('[data-stx-scope]').forEach(function(el) {
|
|
172
|
+
var scopeId = el.getAttribute('data-stx-scope');
|
|
173
|
+
var scopeVars = window.stx._scopes && window.stx._scopes[scopeId];
|
|
174
|
+
if (scopeVars && scopeVars.__mountCallbacks && !scopeVars.__mounted) {
|
|
175
|
+
scopeVars.__mounted = true;
|
|
176
|
+
runMountCallbacks(scopeVars.__mountCallbacks, scopeDestroySink(scopeVars));
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Flush global mountCallbacks (from scripts re-executed after SPA content swap)
|
|
181
|
+
runMountCallbacks(mountCallbacks, destroyCallbacks);
|
|
182
|
+
mountCallbacks.length = 0;
|
|
183
|
+
|
|
184
|
+
// Everything that should have hydrated has now had its chance (#1773).
|
|
185
|
+
auditHydration(container, 'stx:load');
|
|
186
|
+
}
|
|
187
|
+
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** State and derived primitives embedded in the browser signals runtime. */
|
|
2
|
+
export declare const SIGNALS_STATE_RUNTIME = " // ==========================================================================\n // State Signal\n // ==========================================================================\n\n function state(initialValue) {\n let value = initialValue;\n const subscribers = new Set();\n const effects = new Set();\n\n const signal = () => {\n if (activeEffect) {\n effects.add(activeEffect);\n }\n return value;\n };\n\n signal.set = (newValue) => {\n console.log('[stx] signal.set:', value, '->', newValue, 'effects:', effects.size);\n if (!Object.is(newValue, value)) {\n if (__stxDevtoolsTracking) {\n signal._setCount++;\n __stxDevtoolsStats.signalSets++;\n __stxDevtoolsMutations.push({ sid: signal._stxSignalId, prev: __stxShort(value), next: __stxShort(newValue) });\n if (__stxDevtoolsMutations.length > 100) __stxDevtoolsMutations.shift();\n }\n const prev = value;\n value = newValue;\n subscribers.forEach(cb => {\n try { cb(value, prev); }\n catch (e) { console.error('[stx] subscriber error:', e); }\n });\n if (isBatching) {\n effects.forEach(effect => pendingEffects.add(effect));\n }\nelse {\n effects.forEach(effect => effect());\n }\n }\n };\n\n signal.update = (fn) => signal.set(fn(value));\n // Notify as if the value changed, for an array or object mutated in place.\n // set() cannot do it: the value is the same reference, so Object.is skips.\n signal.trigger = () => {\n subscribers.forEach(cb => {\n try { cb(value, value); }\n catch (e) { console.error('[stx] subscriber error:', e); }\n });\n if (isBatching) {\n effects.forEach(effect => pendingEffects.add(effect));\n }\nelse {\n effects.forEach(effect => effect());\n }\n };\n signal.subscribe = (cb) => {\n subscribers.add(cb);\n return () => subscribers.delete(cb);\n };\n signal._isSignal = true;\n signal._effects = effects; // DevTools: the subscriber set (reactive graph)\n signal._setCount = 0; // DevTools: times set() changed the value (when tracking)\n signal._stxSignalId = ++__stxSignalId; // DevTools: stable id for the mutation log\n\n // Vue-compatible .value getter/setter for templates that use signal.value syntax\n Object.defineProperty(signal, 'value', {\n get() { return signal(); },\n set(v) { signal.set(v); },\n configurable: true\n });\n\n return signal;\n }\n\n // ==========================================================================\n // Derived Signal\n // ==========================================================================\n\n function derived(compute) {\n let cached;\n let isDirty = true;\n const effects = new Set();\n\n const markDirty = () => {\n if (!isDirty) {\n isDirty = true;\n if (isBatching) {\n effects.forEach(e => pendingEffects.add(e));\n }\nelse {\n effects.forEach(e => e());\n }\n }\n };\n\n const signal = () => {\n if (activeEffect) effects.add(activeEffect);\n if (isDirty) {\n const prev = activeEffect;\n activeEffect = markDirty;\n effectStack.push(markDirty);\n try {\n cached = compute();\n }\nfinally {\n effectStack.pop();\n activeEffect = prev;\n }\n isDirty = false;\n }\n return cached;\n };\n\n signal._isDerived = true;\n signal._effects = effects; // DevTools: the subscriber set (reactive graph)\n\n // Vue-compatible .value getter for templates that use computed.value syntax\n Object.defineProperty(signal, 'value', {\n get() { return signal(); },\n configurable: true\n });\n\n return signal;\n }\n";
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export const SIGNALS_STATE_RUNTIME = ` // ==========================================================================
|
|
2
|
+
// State Signal
|
|
3
|
+
// ==========================================================================
|
|
4
|
+
|
|
5
|
+
function state(initialValue) {
|
|
6
|
+
let value = initialValue;
|
|
7
|
+
const subscribers = new Set();
|
|
8
|
+
const effects = new Set();
|
|
9
|
+
|
|
10
|
+
const signal = () => {
|
|
11
|
+
if (activeEffect) {
|
|
12
|
+
effects.add(activeEffect);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
signal.set = (newValue) => {
|
|
18
|
+
console.log('[stx] signal.set:', value, '->', newValue, 'effects:', effects.size);
|
|
19
|
+
if (!Object.is(newValue, value)) {
|
|
20
|
+
if (__stxDevtoolsTracking) {
|
|
21
|
+
signal._setCount++;
|
|
22
|
+
__stxDevtoolsStats.signalSets++;
|
|
23
|
+
__stxDevtoolsMutations.push({ sid: signal._stxSignalId, prev: __stxShort(value), next: __stxShort(newValue) });
|
|
24
|
+
if (__stxDevtoolsMutations.length > 100) __stxDevtoolsMutations.shift();
|
|
25
|
+
}
|
|
26
|
+
const prev = value;
|
|
27
|
+
value = newValue;
|
|
28
|
+
subscribers.forEach(cb => {
|
|
29
|
+
try { cb(value, prev); }
|
|
30
|
+
catch (e) { console.error('[stx] subscriber error:', e); }
|
|
31
|
+
});
|
|
32
|
+
if (isBatching) {
|
|
33
|
+
effects.forEach(effect => pendingEffects.add(effect));
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
effects.forEach(effect => effect());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
signal.update = (fn) => signal.set(fn(value));
|
|
42
|
+
// Notify as if the value changed, for an array or object mutated in place.
|
|
43
|
+
// set() cannot do it: the value is the same reference, so Object.is skips.
|
|
44
|
+
signal.trigger = () => {
|
|
45
|
+
subscribers.forEach(cb => {
|
|
46
|
+
try { cb(value, value); }
|
|
47
|
+
catch (e) { console.error('[stx] subscriber error:', e); }
|
|
48
|
+
});
|
|
49
|
+
if (isBatching) {
|
|
50
|
+
effects.forEach(effect => pendingEffects.add(effect));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
effects.forEach(effect => effect());
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
signal.subscribe = (cb) => {
|
|
57
|
+
subscribers.add(cb);
|
|
58
|
+
return () => subscribers.delete(cb);
|
|
59
|
+
};
|
|
60
|
+
signal._isSignal = true;
|
|
61
|
+
signal._effects = effects; // DevTools: the subscriber set (reactive graph)
|
|
62
|
+
signal._setCount = 0; // DevTools: times set() changed the value (when tracking)
|
|
63
|
+
signal._stxSignalId = ++__stxSignalId; // DevTools: stable id for the mutation log
|
|
64
|
+
|
|
65
|
+
// Vue-compatible .value getter/setter for templates that use signal.value syntax
|
|
66
|
+
Object.defineProperty(signal, 'value', {
|
|
67
|
+
get() { return signal(); },
|
|
68
|
+
set(v) { signal.set(v); },
|
|
69
|
+
configurable: true
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return signal;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ==========================================================================
|
|
76
|
+
// Derived Signal
|
|
77
|
+
// ==========================================================================
|
|
78
|
+
|
|
79
|
+
function derived(compute) {
|
|
80
|
+
let cached;
|
|
81
|
+
let isDirty = true;
|
|
82
|
+
const effects = new Set();
|
|
83
|
+
|
|
84
|
+
const markDirty = () => {
|
|
85
|
+
if (!isDirty) {
|
|
86
|
+
isDirty = true;
|
|
87
|
+
if (isBatching) {
|
|
88
|
+
effects.forEach(e => pendingEffects.add(e));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
effects.forEach(e => e());
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const signal = () => {
|
|
97
|
+
if (activeEffect) effects.add(activeEffect);
|
|
98
|
+
if (isDirty) {
|
|
99
|
+
const prev = activeEffect;
|
|
100
|
+
activeEffect = markDirty;
|
|
101
|
+
effectStack.push(markDirty);
|
|
102
|
+
try {
|
|
103
|
+
cached = compute();
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
effectStack.pop();
|
|
107
|
+
activeEffect = prev;
|
|
108
|
+
}
|
|
109
|
+
isDirty = false;
|
|
110
|
+
}
|
|
111
|
+
return cached;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
signal._isDerived = true;
|
|
115
|
+
signal._effects = effects; // DevTools: the subscriber set (reactive graph)
|
|
116
|
+
|
|
117
|
+
// Vue-compatible .value getter for templates that use computed.value syntax
|
|
118
|
+
Object.defineProperty(signal, 'value', {
|
|
119
|
+
get() { return signal(); },
|
|
120
|
+
configurable: true
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return signal;
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Browser storage composables used by the generated client runtime. */
|
|
2
|
+
export declare const SIGNALS_STORAGE_RUNTIME = " // Storage access is guarded end to end (stacksjs/stx#1793). Every one of\n // these can throw, and each throw took down the whole client script for the\n // page rather than just the composable:\n //\n // getItem - SecurityError in a sandboxed iframe or with storage disabled\n // parse - any non-JSON value already sitting at the key\n // setItem - QuotaExceededError, Safari private mode\n //\n // The parse fallback is deliberately LENIENT: a value that isn't JSON is\n // returned as the raw string rather than discarded for defaultValue. A key\n // that previously held a bare 'list' keeps reading back 'list' and is\n // rewritten as JSON on the next set, so migrating an existing key onto this\n // composable no longer needs the key to be renamed. This also matches\n // composables/use-storage.ts, whose default serializer already returns the\n // raw string on parse failure \u2014 the two implementations have to agree.\n function stxParseStored(raw, fallback, key, label) {\n if (raw === null || raw === undefined) return fallback;\n try { return JSON.parse(raw); }\n catch (e) {\n console.warn('[stx] ' + label + ': \"' + key + '\" holds a value that is not JSON (' + String(raw).slice(0, 64) + '); using it as a raw string. Write it with the same composable to store it as JSON.');\n return raw;\n }\n }\n function stxStorageRead(store, key, fallback, label) {\n var raw;\n try { raw = store.getItem(key); }\n catch (e) {\n console.warn('[stx] ' + label + ': cannot read \"' + key + '\" (' + (e && e.message ? e.message : e) + '); using the default.');\n return fallback;\n }\n return stxParseStored(raw, fallback, key, label);\n }\n function stxStorageWrite(store, key, value, label) {\n try { store.setItem(key, JSON.stringify(value)); }\n catch (e) {\n console.warn('[stx] ' + label + ': cannot persist \"' + key + '\" (' + (e && e.message ? e.message : e) + '); the value stays in memory only.');\n }\n }\n\n function useLocalStorage(key, defaultValue) {\n var s = state(stxStorageRead(localStorage, key, defaultValue, 'useLocalStorage'));\n effect(function() {\n stxStorageWrite(localStorage, key, s(), 'useLocalStorage');\n });\n var handler = function(e) {\n // Fires from ANOTHER tab at an arbitrary later time, so an unguarded\n // parse here throws inside a window listener with a stack pointing at\n // the runtime rather than at the consumer.\n // storageArea is also matched so a sessionStorage write to the same key\n // name can't clobber this signal \u2014 useSessionStorage already filtered,\n // this side didn't. Synthetic events (tests) leave storageArea null and\n // are still accepted; real browsers always populate it.\n if (e.key === key && (!e.storageArea || e.storageArea === localStorage))\n s.set(stxParseStored(e.newValue, defaultValue, key, 'useLocalStorage'));\n };\n window.addEventListener('storage', handler);\n onDestroy(function() { window.removeEventListener('storage', handler); });\n return s;\n }\n\n // Mirror of useLocalStorage against sessionStorage. Strict-mode lint\n // already suggests this function name as the replacement for raw\n // window.sessionStorage access; this is the implementation that backs\n // that hint. Same JSON serialization, cross-tab sync via the 'storage'\n // event (filtered to sessionStorage's storageArea \u2014 localStorage events\n // share the same listener but fire from a different area).\n function useSessionStorage(key, defaultValue) {\n var s = state(stxStorageRead(sessionStorage, key, defaultValue, 'useSessionStorage'));\n effect(function() {\n stxStorageWrite(sessionStorage, key, s(), 'useSessionStorage');\n });\n var handler = function(e) {\n if (e.key === key && (!e.storageArea || e.storageArea === sessionStorage))\n s.set(stxParseStored(e.newValue, defaultValue, key, 'useSessionStorage'));\n };\n window.addEventListener('storage', handler);\n onDestroy(function() { window.removeEventListener('storage', handler); });\n return s;\n }";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export const SIGNALS_STORAGE_RUNTIME = ` // Storage access is guarded end to end (stacksjs/stx#1793). Every one of
|
|
2
|
+
// these can throw, and each throw took down the whole client script for the
|
|
3
|
+
// page rather than just the composable:
|
|
4
|
+
//
|
|
5
|
+
// getItem - SecurityError in a sandboxed iframe or with storage disabled
|
|
6
|
+
// parse - any non-JSON value already sitting at the key
|
|
7
|
+
// setItem - QuotaExceededError, Safari private mode
|
|
8
|
+
//
|
|
9
|
+
// The parse fallback is deliberately LENIENT: a value that isn't JSON is
|
|
10
|
+
// returned as the raw string rather than discarded for defaultValue. A key
|
|
11
|
+
// that previously held a bare 'list' keeps reading back 'list' and is
|
|
12
|
+
// rewritten as JSON on the next set, so migrating an existing key onto this
|
|
13
|
+
// composable no longer needs the key to be renamed. This also matches
|
|
14
|
+
// composables/use-storage.ts, whose default serializer already returns the
|
|
15
|
+
// raw string on parse failure \u2014 the two implementations have to agree.
|
|
16
|
+
function stxParseStored(raw, fallback, key, label) {
|
|
17
|
+
if (raw === null || raw === undefined) return fallback;
|
|
18
|
+
try { return JSON.parse(raw); }
|
|
19
|
+
catch (e) {
|
|
20
|
+
console.warn('[stx] ' + label + ': "' + key + '" holds a value that is not JSON (' + String(raw).slice(0, 64) + '); using it as a raw string. Write it with the same composable to store it as JSON.');
|
|
21
|
+
return raw;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function stxStorageRead(store, key, fallback, label) {
|
|
25
|
+
var raw;
|
|
26
|
+
try { raw = store.getItem(key); }
|
|
27
|
+
catch (e) {
|
|
28
|
+
console.warn('[stx] ' + label + ': cannot read "' + key + '" (' + (e && e.message ? e.message : e) + '); using the default.');
|
|
29
|
+
return fallback;
|
|
30
|
+
}
|
|
31
|
+
return stxParseStored(raw, fallback, key, label);
|
|
32
|
+
}
|
|
33
|
+
function stxStorageWrite(store, key, value, label) {
|
|
34
|
+
try { store.setItem(key, JSON.stringify(value)); }
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.warn('[stx] ' + label + ': cannot persist "' + key + '" (' + (e && e.message ? e.message : e) + '); the value stays in memory only.');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function useLocalStorage(key, defaultValue) {
|
|
41
|
+
var s = state(stxStorageRead(localStorage, key, defaultValue, 'useLocalStorage'));
|
|
42
|
+
effect(function() {
|
|
43
|
+
stxStorageWrite(localStorage, key, s(), 'useLocalStorage');
|
|
44
|
+
});
|
|
45
|
+
var handler = function(e) {
|
|
46
|
+
// Fires from ANOTHER tab at an arbitrary later time, so an unguarded
|
|
47
|
+
// parse here throws inside a window listener with a stack pointing at
|
|
48
|
+
// the runtime rather than at the consumer.
|
|
49
|
+
// storageArea is also matched so a sessionStorage write to the same key
|
|
50
|
+
// name can't clobber this signal \u2014 useSessionStorage already filtered,
|
|
51
|
+
// this side didn't. Synthetic events (tests) leave storageArea null and
|
|
52
|
+
// are still accepted; real browsers always populate it.
|
|
53
|
+
if (e.key === key && (!e.storageArea || e.storageArea === localStorage))
|
|
54
|
+
s.set(stxParseStored(e.newValue, defaultValue, key, 'useLocalStorage'));
|
|
55
|
+
};
|
|
56
|
+
window.addEventListener('storage', handler);
|
|
57
|
+
onDestroy(function() { window.removeEventListener('storage', handler); });
|
|
58
|
+
return s;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Mirror of useLocalStorage against sessionStorage. Strict-mode lint
|
|
62
|
+
// already suggests this function name as the replacement for raw
|
|
63
|
+
// window.sessionStorage access; this is the implementation that backs
|
|
64
|
+
// that hint. Same JSON serialization, cross-tab sync via the 'storage'
|
|
65
|
+
// event (filtered to sessionStorage's storageArea \u2014 localStorage events
|
|
66
|
+
// share the same listener but fire from a different area).
|
|
67
|
+
function useSessionStorage(key, defaultValue) {
|
|
68
|
+
var s = state(stxStorageRead(sessionStorage, key, defaultValue, 'useSessionStorage'));
|
|
69
|
+
effect(function() {
|
|
70
|
+
stxStorageWrite(sessionStorage, key, s(), 'useSessionStorage');
|
|
71
|
+
});
|
|
72
|
+
var handler = function(e) {
|
|
73
|
+
if (e.key === key && (!e.storageArea || e.storageArea === sessionStorage))
|
|
74
|
+
s.set(stxParseStored(e.newValue, defaultValue, key, 'useSessionStorage'));
|
|
75
|
+
};
|
|
76
|
+
window.addEventListener('storage', handler);
|
|
77
|
+
onDestroy(function() { window.removeEventListener('storage', handler); });
|
|
78
|
+
return s;
|
|
79
|
+
}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SIGNALS_STORE_REGISTRY_RUNTIME = " // \u2500\u2500 Store System \u2500\u2500\n // Pinia-inspired, signals-based. Stores survive SPA navigation.\n\n defineStore: function(id, setupOrOptions, storeOptions) {\n console.log('[stx:store] defineStore called:', id, 'type:', typeof setupOrOptions === 'function' ? 'setup' : 'options', 'persist:', !!(storeOptions && storeOptions.persist));\n // Return existing store if already defined.\n //\n // During a store HMR pass the definition is deliberately re-run, so the\n // cached instance must NOT short-circuit it (#1877 ask 4).\n if (window.stx._stores.has(id) && !window.stx.__hmrStoreReplacing) {\n console.log('[stx:store] returning existing store:', id);\n return window.stx._stores.get(id);\n }\n\n // Determine setup function\n var setupFn;\n if (typeof setupOrOptions === 'function') {\n // Setup style: defineStore('id', () => { ... })\n setupFn = setupOrOptions;\n } else {\n // Options style: defineStore('id', { state, getters, actions })\n var opts = setupOrOptions;\n setupFn = function() {\n var result = {};\n // Convert state to signals\n var initialState = typeof opts.state === 'function' ? opts.state() : (opts.state || {});\n var stateSignals = {};\n for (var key in initialState) {\n stateSignals[key] = state(initialState[key]);\n result[key] = stateSignals[key];\n }\n // Convert getters to derived signals\n if (opts.getters) {\n for (var gKey in opts.getters) {\n (function(getterKey, getterFn) {\n result[getterKey] = derived(function() {\n // Build state snapshot for getter\n var snapshot = {};\n for (var sk in stateSignals) { snapshot[sk] = stateSignals[sk](); }\n return getterFn(snapshot);\n });\n })(gKey, opts.getters[gKey]);\n }\n }\n // An action that mutates state in place \u2014 this.list.push(x),\n // this.list[i] = x, delete this.map[k] \u2014 never went through set(),\n // so nothing that read the list re-ran. A detail page upserting the\n // record it had just fetched kept rendering \"not found\" until some\n // unrelated action happened to reassign the whole list.\n //\n // So an array or plain object read through this comes back as a\n // view that notifies its signal on write. The view is shallow:\n // elements read through it are the raw ones, so identity checks\n // (includes, indexOf, ===) still hold.\n var mutatingArrayMethods = { push: 1, pop: 1, shift: 1, unshift: 1, splice: 1, sort: 1, reverse: 1, fill: 1, copyWithin: 1 };\n var viewRaw = new WeakMap();\n var viewCache = new WeakMap();\n var unwrapView = function(v) {\n return (v && typeof v === 'object' && viewRaw.has(v)) ? viewRaw.get(v) : v;\n };\n var isPlainContainer = function(v) {\n if (!v || typeof v !== 'object') return false;\n if (Array.isArray(v)) return true;\n var proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n };\n var mutableView = function(sig, raw) {\n var cached = viewCache.get(raw);\n if (cached && cached.sig === sig) return cached.view;\n var view = new Proxy(raw, {\n get: function(target, p) {\n if (Array.isArray(target) && typeof p === 'string' && mutatingArrayMethods[p]) {\n // One notification per call, not one per index it writes.\n return function() {\n var args = Array.prototype.map.call(arguments, unwrapView);\n var out = Array.prototype[p].apply(target, args);\n sig.trigger();\n return out === target ? view : out;\n };\n }\n return Reflect.get(target, p, target);\n },\n set: function(target, p, v) {\n target[p] = unwrapView(v);\n sig.trigger();\n return true;\n },\n deleteProperty: function(target, p) {\n var had = Object.prototype.hasOwnProperty.call(target, p);\n delete target[p];\n if (had) sig.trigger();\n return true;\n }\n });\n viewRaw.set(view, raw);\n viewCache.set(raw, { sig: sig, view: view });\n return view;\n };\n // Bind actions with proxy for this.propName access\n if (opts.actions) {\n for (var aKey in opts.actions) {\n (function(actionKey, actionFn) {\n result[actionKey] = function() {\n var proxy = new Proxy({}, {\n get: function(_, p) {\n if (result[p] && result[p]._isSignal) {\n var current = result[p]();\n return (typeof result[p].trigger === 'function' && isPlainContainer(current))\n ? mutableView(result[p], current)\n : current;\n }\n if (result[p]) return result[p];\n return undefined;\n },\n set: function(_, p, v) {\n if (result[p] && result[p]._isSignal) { result[p].set(unwrapView(v)); return true; }\n return false;\n }\n });\n return actionFn.apply(proxy, arguments);\n };\n })(aKey, opts.actions[aKey]);\n }\n }\n return result;\n };\n }\n\n // Run setup with store-safe effect tracking (effects are global, not element-scoped)\n var prevDisposers = activeDisposers;\n activeDisposers = null;\n\n var result;\n try {\n result = setupFn();\n } finally {\n activeDisposers = prevDisposers;\n }\n\n // Log what the setup returned\n var signalKeys = [];\n var actionKeys = [];\n for (var dk in result) {\n if (result[dk] && result[dk]._isSignal) signalKeys.push(dk);\n else if (typeof result[dk] === 'function') actionKeys.push(dk);\n }\n console.log('[stx:store] setup complete:', id, 'signals:', signalKeys, 'actions:', actionKeys);\n\n // Capture initial values for $reset\n var _initialValues = {};\n for (var k in result) {\n if (result[k] && result[k]._isSignal) {\n _initialValues[k] = result[k]();\n }\n }\n\n // Store metadata\n result.$id = id;\n result.$reset = function() {\n batch(function() {\n for (var rk in _initialValues) {\n if (result[rk] && result[rk]._isSignal) result[rk].set(_initialValues[rk]);\n }\n });\n };\n result.$patch = function(partial) {\n batch(function() {\n for (var pk in partial) {\n if (result[pk] && result[pk]._isSignal) result[pk].set(partial[pk]);\n }\n });\n };\n result.$subscribe = function(cb) {\n var unsubs = [];\n for (var sk in result) {\n if (result[sk] && result[sk]._isSignal && result[sk].subscribe) {\n unsubs.push(result[sk].subscribe(function() {\n var snapshot = {};\n for (var ssk in result) {\n if (result[ssk] && result[ssk]._isSignal) snapshot[ssk] = result[ssk]();\n }\n cb(snapshot);\n }));\n }\n }\n return function() { unsubs.forEach(function(u) { u(); }); };\n };\n result.$dispose = function() {\n window.stx._stores.delete(id);\n if (window.__STX_STORES__) delete window.__STX_STORES__[id];\n };\n\n // Hydration: restore state from SSR\n var hydrationData = window.__STX_STORE_STATE__ && window.__STX_STORE_STATE__[id];\n if (hydrationData) {\n console.log('[stx:store] hydrating from SSR:', id, Object.keys(hydrationData));\n batch(function() {\n for (var hk in hydrationData) {\n if (result[hk] && result[hk]._isSignal) result[hk].set(hydrationData[hk]);\n }\n });\n }\n\n // Persistence\n var persistCfg = storeOptions && storeOptions.persist;\n if (persistCfg) {\n var pOpts = persistCfg === true ? {} : persistCfg;\n var storageKey = pOpts.key || ('stx-store-' + id);\n var pick = pOpts.pick || null;\n\n // Three additions, all of which apps previously had to hand-roll outside\n // the store entirely (#1872):\n //\n // keys map a field to its OWN storage key, and optionally its own\n // backend, instead of folding everything into one JSON blob\n // serialize / deserialize \u2014 the codec was hardcoded to JSON, so a\n // persisted string came back quoted. A signed-out token\n // stored as '\"\"' is two characters and TRUTHY, which is a\n // real class of auth bug, and a legacy raw value could not\n // be read at all\n // cookie a backend the SERVER can read. Server-rendered,\n // owner-scoped pages authenticate from a cookie and cannot\n // see localStorage, so this previously meant a second\n // persisted signal plus a hand-written mirroring effect\n var fieldMap = pOpts.keys || null;\n var defaultSerialize = pOpts.serialize || function(value) { return JSON.stringify(value); };\n var defaultDeserialize = pOpts.deserialize || function(raw) { return JSON.parse(raw); };\n\n // 'local' and 'localStorage' both accepted; the old code only recognised\n // 'sessionStorage', so 'session' silently fell through to localStorage.\n // Resolved through window when the bare global is absent, so persist also\n // works where the runtime is evaluated outside a page's global scope\n // (component test harnesses, embedded runtimes).\n function _backendFor(kind) {\n if (kind === 'cookie') return 'cookie';\n var scope = typeof window !== 'undefined' ? window : null;\n if (kind === 'session' || kind === 'sessionStorage')\n return typeof sessionStorage !== 'undefined' ? sessionStorage : (scope && scope.sessionStorage);\n return typeof localStorage !== 'undefined' ? localStorage : (scope && scope.localStorage);\n }\n var storageType = _backendFor(pOpts.storage);\n\n // Resolved config for a field that has its own key, or null if it belongs\n // in the shared blob.\n function _mappedConfig(field) {\n if (!fieldMap || !Object.prototype.hasOwnProperty.call(fieldMap, field)) return null;\n var cfg = fieldMap[field];\n if (typeof cfg === 'string') cfg = { key: cfg };\n cfg = cfg || {};\n return {\n key: cfg.key || field,\n backend: _backendFor(cfg.storage === undefined ? pOpts.storage : cfg.storage),\n cookieOpts: cfg,\n serialize: cfg.serialize || defaultSerialize,\n deserialize: cfg.deserialize || defaultDeserialize\n };\n }\n\n // A mapped field owns its key, so it must NOT also be written into the\n // blob \u2014 otherwise it round-trips through two places that can disagree.\n function _inBlob(field) {\n if (pick && pick.indexOf(field) === -1) return false;\n return !_mappedConfig(field);\n }\n\n // Read persisted state (overrides hydration)\n try {\n var saved = storageType === 'cookie' ? null : storageType.getItem(storageKey);\n if (saved) {\n var parsed = defaultDeserialize(saved);\n console.log('[stx:store] restoring persisted state:', id, 'key:', storageKey, Object.keys(parsed));\n batch(function() {\n for (var pk in parsed) {\n if (result[pk] && result[pk]._isSignal && _inBlob(pk)) {\n result[pk].set(parsed[pk]);\n }\n }\n });\n } else {\n console.log('[stx:store] no persisted state found:', id, 'key:', storageKey);\n }\n } catch(e) { console.warn('[stx:store] persistence read error:', id, e); }\n\n // Per-field persistence: own key, own backend, own codec.\n //\n // The disposer swap is the same trick the blob effect below uses \u2014 these\n // effects must outlive the component that happened to instantiate the\n // store, or persistence would stop the first time that component\n // unmounted.\n var prevFieldDisposers = activeDisposers;\n activeDisposers = null;\n if (fieldMap) {\n for (var fk in fieldMap) {\n if (!Object.prototype.hasOwnProperty.call(fieldMap, fk)) continue;\n if (!result[fk] || !result[fk]._isSignal) {\n console.warn('[stx:store] persist.keys names a field that is not a signal:', id, fk);\n continue;\n }\n (function(field, cfg, signal) {\n if (cfg.backend === 'cookie') {\n // useCookie owns path / max-age / SameSite / Secure, so cookie\n // attributes do not have to be reimplemented here. It is a\n // string-valued signal, hence serialize on the way out.\n var cookieSignal = useCookie(cfg.key, cfg.cookieOpts);\n var initialCookie = cookieSignal();\n if (initialCookie !== '' && initialCookie != null) {\n try { signal.set(cfg.deserialize(initialCookie)); }\n catch(e) { console.warn('[stx:store] persist read error:', id, field, e); }\n }\n effect(function() {\n var next = signal();\n try { cookieSignal.set(next == null ? '' : String(cfg.serialize(next))); }\n catch(e) { console.warn('[stx:store] persist write error:', id, field, e); }\n });\n return;\n }\n try {\n var rawValue = cfg.backend.getItem(cfg.key);\n if (rawValue !== null) signal.set(cfg.deserialize(rawValue));\n } catch(e) { console.warn('[stx:store] persist read error:', id, field, e); }\n effect(function() {\n var value = signal();\n try { cfg.backend.setItem(cfg.key, String(cfg.serialize(value))); }\n catch(e) { console.warn('[stx:store] persist write error:', id, field, e); }\n });\n })(fk, _mappedConfig(fk), result[fk]);\n }\n }\n activeDisposers = prevFieldDisposers;\n\n // Write on change (debounced)\n var writeTimer = null;\n var prevPersistDisposers = activeDisposers;\n activeDisposers = null;\n effect(function() {\n var snapshot = {};\n var wrote = false;\n for (var wk in result) {\n if (result[wk] && result[wk]._isSignal && _inBlob(wk)) {\n snapshot[wk] = result[wk]();\n wrote = true;\n }\n }\n // With every field mapped to its own key there is no blob left, and\n // writing an empty object would clobber whatever else owns that key.\n if (!wrote || storageType === 'cookie') return;\n if (writeTimer) clearTimeout(writeTimer);\n writeTimer = setTimeout(function() {\n console.log('[stx:store] persisting:', id, 'key:', storageKey, Object.keys(snapshot));\n try { storageType.setItem(storageKey, String(defaultSerialize(snapshot))); } catch(e) { console.warn('[stx:store] persist write error:', id, e); }\n }, 100);\n });\n activeDisposers = prevPersistDisposers;\n }\n\n // Marker so the template-scope auto-unwrap proxy knows to recursively\n // unwrap signal-valued properties on this object. Script-level callers\n // still see the bare store (so existing patterns like store.someSignal()\n // keep working); only template expression evaluation auto-unwraps.\n result._isStxStore = true;\n\n // Carry state across a hot replacement.\n //\n // The NEW store object is kept rather than patching the old one: a\n // setup-style store's actions close over the signals created in that\n // same run, so keeping the old signals would leave the new actions\n // writing to signals nothing is watching \u2014 an edit that appears to do\n // nothing, which is worse than the reload this replaces. Seeding the new\n // signals with the old values keeps state and behaviour consistent, and\n // the caller re-renders afterwards so components rebind to this object.\n var seed = window.stx.__hmrStoreSeed && window.stx.__hmrStoreSeed[id];\n if (seed) {\n for (var seedKey in seed) {\n var target = result[seedKey];\n if (target && target._isSignal && typeof target.set === 'function' && !target._isDerived) {\n try { target.set(seed[seedKey]); }\n catch (e) { /* shape changed across the edit \u2014 keep the new default */ }\n }\n }\n }\n\n // Register globally\n window.stx._stores.set(id, result);\n window.__STX_STORES__ = window.__STX_STORES__ || {};\n window.__STX_STORES__[id] = result;\n\n console.log('[stx:store] registered:', id, 'total stores:', window.stx._stores.size);\n return result;\n },\n\n // Replace the store definitions in place, keeping their state \u2014 the\n // acceptHMRUpdate contract (#1877 ask 4). Called by the dev server's HMR\n // client when a file under storesDir changes, instead of reloading the\n // document and throwing away everything the SPA exists to preserve.\n __hmrReplaceStores: function(code) {\n var seed = {};\n window.stx._stores.forEach(function(store, id) {\n var values = {};\n for (var key in store) {\n var value = store[key];\n // Derived values recompute from state, so seeding them would fight\n // their own recomputation.\n if (value && value._isSignal && !value._isDerived) {\n try { values[key] = value.peek ? value.peek() : value(); }\n catch (e) { /* unreadable \u2014 let the new default stand */ }\n }\n }\n seed[id] = values;\n });\n\n window.stx.__hmrStoreSeed = seed;\n window.stx.__hmrStoreReplacing = true;\n var ok = true;\n try {\n // Indirect eval, so the bundle evaluates at global scope the way it\n // does when inlined into the page.\n (0, eval)(code);\n }\n catch (e) {\n ok = false;\n console.error('[stx:hmr] store bundle failed to evaluate:', e);\n }\n finally {\n window.stx.__hmrStoreReplacing = false;\n window.stx.__hmrStoreSeed = null;\n }\n\n if (!ok) return false;\n\n // Components captured the PREVIOUS store object from useStore(), so\n // re-render the route to rebind them. Still not a document reload: the\n // swap keeps every non-store signal on the page alive.\n if (window.stxRouter && typeof window.stxRouter.refresh === 'function') {\n try { window.stxRouter.refresh(); }\n catch (e) { /* a refresh that cannot run is not worth a reload here */ }\n }\n return true;\n },\n\n registerStoresClient: function(stores) {\n window.__STX_STORES__ = window.__STX_STORES__ || {};\n var names = Object.keys(stores || {});\n for (var i = 0; i < names.length; i++) {\n var name = names[i];\n window.__STX_STORES__[name] = stores[name];\n }\n window.dispatchEvent(new CustomEvent('stx:stores-ready', { detail: names }));\n },\n\n useStore: function(id) {\n var store = window.stx._stores.get(id);\n if (!store && window.__STX_STORES__) {\n store = window.__STX_STORES__[id];\n }\n if (!store) {\n console.error('[stx:store] Store not found:', id, 'available:', Array.from(window.stx._stores.keys()));\n throw new Error('[stx] Store \"' + id + '\" not found. Define it with defineStore() first.');\n }\n console.log('[stx:store] useStore:', id);\n return store;\n },";
|