@stacksjs/stx 0.2.532 → 0.2.533
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,461 @@
|
|
|
1
|
+
export const SIGNALS_STORE_REGISTRY_RUNTIME = ` // \u2500\u2500 Store System \u2500\u2500
|
|
2
|
+
// Pinia-inspired, signals-based. Stores survive SPA navigation.
|
|
3
|
+
|
|
4
|
+
defineStore: function(id, setupOrOptions, storeOptions) {
|
|
5
|
+
console.log('[stx:store] defineStore called:', id, 'type:', typeof setupOrOptions === 'function' ? 'setup' : 'options', 'persist:', !!(storeOptions && storeOptions.persist));
|
|
6
|
+
// Return existing store if already defined.
|
|
7
|
+
//
|
|
8
|
+
// During a store HMR pass the definition is deliberately re-run, so the
|
|
9
|
+
// cached instance must NOT short-circuit it (#1877 ask 4).
|
|
10
|
+
if (window.stx._stores.has(id) && !window.stx.__hmrStoreReplacing) {
|
|
11
|
+
console.log('[stx:store] returning existing store:', id);
|
|
12
|
+
return window.stx._stores.get(id);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Determine setup function
|
|
16
|
+
var setupFn;
|
|
17
|
+
if (typeof setupOrOptions === 'function') {
|
|
18
|
+
// Setup style: defineStore('id', () => { ... })
|
|
19
|
+
setupFn = setupOrOptions;
|
|
20
|
+
} else {
|
|
21
|
+
// Options style: defineStore('id', { state, getters, actions })
|
|
22
|
+
var opts = setupOrOptions;
|
|
23
|
+
setupFn = function() {
|
|
24
|
+
var result = {};
|
|
25
|
+
// Convert state to signals
|
|
26
|
+
var initialState = typeof opts.state === 'function' ? opts.state() : (opts.state || {});
|
|
27
|
+
var stateSignals = {};
|
|
28
|
+
for (var key in initialState) {
|
|
29
|
+
stateSignals[key] = state(initialState[key]);
|
|
30
|
+
result[key] = stateSignals[key];
|
|
31
|
+
}
|
|
32
|
+
// Convert getters to derived signals
|
|
33
|
+
if (opts.getters) {
|
|
34
|
+
for (var gKey in opts.getters) {
|
|
35
|
+
(function(getterKey, getterFn) {
|
|
36
|
+
result[getterKey] = derived(function() {
|
|
37
|
+
// Build state snapshot for getter
|
|
38
|
+
var snapshot = {};
|
|
39
|
+
for (var sk in stateSignals) { snapshot[sk] = stateSignals[sk](); }
|
|
40
|
+
return getterFn(snapshot);
|
|
41
|
+
});
|
|
42
|
+
})(gKey, opts.getters[gKey]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// An action that mutates state in place \u2014 this.list.push(x),
|
|
46
|
+
// this.list[i] = x, delete this.map[k] \u2014 never went through set(),
|
|
47
|
+
// so nothing that read the list re-ran. A detail page upserting the
|
|
48
|
+
// record it had just fetched kept rendering "not found" until some
|
|
49
|
+
// unrelated action happened to reassign the whole list.
|
|
50
|
+
//
|
|
51
|
+
// So an array or plain object read through this comes back as a
|
|
52
|
+
// view that notifies its signal on write. The view is shallow:
|
|
53
|
+
// elements read through it are the raw ones, so identity checks
|
|
54
|
+
// (includes, indexOf, ===) still hold.
|
|
55
|
+
var mutatingArrayMethods = { push: 1, pop: 1, shift: 1, unshift: 1, splice: 1, sort: 1, reverse: 1, fill: 1, copyWithin: 1 };
|
|
56
|
+
var viewRaw = new WeakMap();
|
|
57
|
+
var viewCache = new WeakMap();
|
|
58
|
+
var unwrapView = function(v) {
|
|
59
|
+
return (v && typeof v === 'object' && viewRaw.has(v)) ? viewRaw.get(v) : v;
|
|
60
|
+
};
|
|
61
|
+
var isPlainContainer = function(v) {
|
|
62
|
+
if (!v || typeof v !== 'object') return false;
|
|
63
|
+
if (Array.isArray(v)) return true;
|
|
64
|
+
var proto = Object.getPrototypeOf(v);
|
|
65
|
+
return proto === Object.prototype || proto === null;
|
|
66
|
+
};
|
|
67
|
+
var mutableView = function(sig, raw) {
|
|
68
|
+
var cached = viewCache.get(raw);
|
|
69
|
+
if (cached && cached.sig === sig) return cached.view;
|
|
70
|
+
var view = new Proxy(raw, {
|
|
71
|
+
get: function(target, p) {
|
|
72
|
+
if (Array.isArray(target) && typeof p === 'string' && mutatingArrayMethods[p]) {
|
|
73
|
+
// One notification per call, not one per index it writes.
|
|
74
|
+
return function() {
|
|
75
|
+
var args = Array.prototype.map.call(arguments, unwrapView);
|
|
76
|
+
var out = Array.prototype[p].apply(target, args);
|
|
77
|
+
sig.trigger();
|
|
78
|
+
return out === target ? view : out;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return Reflect.get(target, p, target);
|
|
82
|
+
},
|
|
83
|
+
set: function(target, p, v) {
|
|
84
|
+
target[p] = unwrapView(v);
|
|
85
|
+
sig.trigger();
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
deleteProperty: function(target, p) {
|
|
89
|
+
var had = Object.prototype.hasOwnProperty.call(target, p);
|
|
90
|
+
delete target[p];
|
|
91
|
+
if (had) sig.trigger();
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
viewRaw.set(view, raw);
|
|
96
|
+
viewCache.set(raw, { sig: sig, view: view });
|
|
97
|
+
return view;
|
|
98
|
+
};
|
|
99
|
+
// Bind actions with proxy for this.propName access
|
|
100
|
+
if (opts.actions) {
|
|
101
|
+
for (var aKey in opts.actions) {
|
|
102
|
+
(function(actionKey, actionFn) {
|
|
103
|
+
result[actionKey] = function() {
|
|
104
|
+
var proxy = new Proxy({}, {
|
|
105
|
+
get: function(_, p) {
|
|
106
|
+
if (result[p] && result[p]._isSignal) {
|
|
107
|
+
var current = result[p]();
|
|
108
|
+
return (typeof result[p].trigger === 'function' && isPlainContainer(current))
|
|
109
|
+
? mutableView(result[p], current)
|
|
110
|
+
: current;
|
|
111
|
+
}
|
|
112
|
+
if (result[p]) return result[p];
|
|
113
|
+
return undefined;
|
|
114
|
+
},
|
|
115
|
+
set: function(_, p, v) {
|
|
116
|
+
if (result[p] && result[p]._isSignal) { result[p].set(unwrapView(v)); return true; }
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return actionFn.apply(proxy, arguments);
|
|
121
|
+
};
|
|
122
|
+
})(aKey, opts.actions[aKey]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Run setup with store-safe effect tracking (effects are global, not element-scoped)
|
|
130
|
+
var prevDisposers = activeDisposers;
|
|
131
|
+
activeDisposers = null;
|
|
132
|
+
|
|
133
|
+
var result;
|
|
134
|
+
try {
|
|
135
|
+
result = setupFn();
|
|
136
|
+
} finally {
|
|
137
|
+
activeDisposers = prevDisposers;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Log what the setup returned
|
|
141
|
+
var signalKeys = [];
|
|
142
|
+
var actionKeys = [];
|
|
143
|
+
for (var dk in result) {
|
|
144
|
+
if (result[dk] && result[dk]._isSignal) signalKeys.push(dk);
|
|
145
|
+
else if (typeof result[dk] === 'function') actionKeys.push(dk);
|
|
146
|
+
}
|
|
147
|
+
console.log('[stx:store] setup complete:', id, 'signals:', signalKeys, 'actions:', actionKeys);
|
|
148
|
+
|
|
149
|
+
// Capture initial values for $reset
|
|
150
|
+
var _initialValues = {};
|
|
151
|
+
for (var k in result) {
|
|
152
|
+
if (result[k] && result[k]._isSignal) {
|
|
153
|
+
_initialValues[k] = result[k]();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Store metadata
|
|
158
|
+
result.$id = id;
|
|
159
|
+
result.$reset = function() {
|
|
160
|
+
batch(function() {
|
|
161
|
+
for (var rk in _initialValues) {
|
|
162
|
+
if (result[rk] && result[rk]._isSignal) result[rk].set(_initialValues[rk]);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
result.$patch = function(partial) {
|
|
167
|
+
batch(function() {
|
|
168
|
+
for (var pk in partial) {
|
|
169
|
+
if (result[pk] && result[pk]._isSignal) result[pk].set(partial[pk]);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
result.$subscribe = function(cb) {
|
|
174
|
+
var unsubs = [];
|
|
175
|
+
for (var sk in result) {
|
|
176
|
+
if (result[sk] && result[sk]._isSignal && result[sk].subscribe) {
|
|
177
|
+
unsubs.push(result[sk].subscribe(function() {
|
|
178
|
+
var snapshot = {};
|
|
179
|
+
for (var ssk in result) {
|
|
180
|
+
if (result[ssk] && result[ssk]._isSignal) snapshot[ssk] = result[ssk]();
|
|
181
|
+
}
|
|
182
|
+
cb(snapshot);
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return function() { unsubs.forEach(function(u) { u(); }); };
|
|
187
|
+
};
|
|
188
|
+
result.$dispose = function() {
|
|
189
|
+
window.stx._stores.delete(id);
|
|
190
|
+
if (window.__STX_STORES__) delete window.__STX_STORES__[id];
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// Hydration: restore state from SSR
|
|
194
|
+
var hydrationData = window.__STX_STORE_STATE__ && window.__STX_STORE_STATE__[id];
|
|
195
|
+
if (hydrationData) {
|
|
196
|
+
console.log('[stx:store] hydrating from SSR:', id, Object.keys(hydrationData));
|
|
197
|
+
batch(function() {
|
|
198
|
+
for (var hk in hydrationData) {
|
|
199
|
+
if (result[hk] && result[hk]._isSignal) result[hk].set(hydrationData[hk]);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Persistence
|
|
205
|
+
var persistCfg = storeOptions && storeOptions.persist;
|
|
206
|
+
if (persistCfg) {
|
|
207
|
+
var pOpts = persistCfg === true ? {} : persistCfg;
|
|
208
|
+
var storageKey = pOpts.key || ('stx-store-' + id);
|
|
209
|
+
var pick = pOpts.pick || null;
|
|
210
|
+
|
|
211
|
+
// Three additions, all of which apps previously had to hand-roll outside
|
|
212
|
+
// the store entirely (#1872):
|
|
213
|
+
//
|
|
214
|
+
// keys map a field to its OWN storage key, and optionally its own
|
|
215
|
+
// backend, instead of folding everything into one JSON blob
|
|
216
|
+
// serialize / deserialize \u2014 the codec was hardcoded to JSON, so a
|
|
217
|
+
// persisted string came back quoted. A signed-out token
|
|
218
|
+
// stored as '""' is two characters and TRUTHY, which is a
|
|
219
|
+
// real class of auth bug, and a legacy raw value could not
|
|
220
|
+
// be read at all
|
|
221
|
+
// cookie a backend the SERVER can read. Server-rendered,
|
|
222
|
+
// owner-scoped pages authenticate from a cookie and cannot
|
|
223
|
+
// see localStorage, so this previously meant a second
|
|
224
|
+
// persisted signal plus a hand-written mirroring effect
|
|
225
|
+
var fieldMap = pOpts.keys || null;
|
|
226
|
+
var defaultSerialize = pOpts.serialize || function(value) { return JSON.stringify(value); };
|
|
227
|
+
var defaultDeserialize = pOpts.deserialize || function(raw) { return JSON.parse(raw); };
|
|
228
|
+
|
|
229
|
+
// 'local' and 'localStorage' both accepted; the old code only recognised
|
|
230
|
+
// 'sessionStorage', so 'session' silently fell through to localStorage.
|
|
231
|
+
// Resolved through window when the bare global is absent, so persist also
|
|
232
|
+
// works where the runtime is evaluated outside a page's global scope
|
|
233
|
+
// (component test harnesses, embedded runtimes).
|
|
234
|
+
function _backendFor(kind) {
|
|
235
|
+
if (kind === 'cookie') return 'cookie';
|
|
236
|
+
var scope = typeof window !== 'undefined' ? window : null;
|
|
237
|
+
if (kind === 'session' || kind === 'sessionStorage')
|
|
238
|
+
return typeof sessionStorage !== 'undefined' ? sessionStorage : (scope && scope.sessionStorage);
|
|
239
|
+
return typeof localStorage !== 'undefined' ? localStorage : (scope && scope.localStorage);
|
|
240
|
+
}
|
|
241
|
+
var storageType = _backendFor(pOpts.storage);
|
|
242
|
+
|
|
243
|
+
// Resolved config for a field that has its own key, or null if it belongs
|
|
244
|
+
// in the shared blob.
|
|
245
|
+
function _mappedConfig(field) {
|
|
246
|
+
if (!fieldMap || !Object.prototype.hasOwnProperty.call(fieldMap, field)) return null;
|
|
247
|
+
var cfg = fieldMap[field];
|
|
248
|
+
if (typeof cfg === 'string') cfg = { key: cfg };
|
|
249
|
+
cfg = cfg || {};
|
|
250
|
+
return {
|
|
251
|
+
key: cfg.key || field,
|
|
252
|
+
backend: _backendFor(cfg.storage === undefined ? pOpts.storage : cfg.storage),
|
|
253
|
+
cookieOpts: cfg,
|
|
254
|
+
serialize: cfg.serialize || defaultSerialize,
|
|
255
|
+
deserialize: cfg.deserialize || defaultDeserialize
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// A mapped field owns its key, so it must NOT also be written into the
|
|
260
|
+
// blob \u2014 otherwise it round-trips through two places that can disagree.
|
|
261
|
+
function _inBlob(field) {
|
|
262
|
+
if (pick && pick.indexOf(field) === -1) return false;
|
|
263
|
+
return !_mappedConfig(field);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Read persisted state (overrides hydration)
|
|
267
|
+
try {
|
|
268
|
+
var saved = storageType === 'cookie' ? null : storageType.getItem(storageKey);
|
|
269
|
+
if (saved) {
|
|
270
|
+
var parsed = defaultDeserialize(saved);
|
|
271
|
+
console.log('[stx:store] restoring persisted state:', id, 'key:', storageKey, Object.keys(parsed));
|
|
272
|
+
batch(function() {
|
|
273
|
+
for (var pk in parsed) {
|
|
274
|
+
if (result[pk] && result[pk]._isSignal && _inBlob(pk)) {
|
|
275
|
+
result[pk].set(parsed[pk]);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
} else {
|
|
280
|
+
console.log('[stx:store] no persisted state found:', id, 'key:', storageKey);
|
|
281
|
+
}
|
|
282
|
+
} catch(e) { console.warn('[stx:store] persistence read error:', id, e); }
|
|
283
|
+
|
|
284
|
+
// Per-field persistence: own key, own backend, own codec.
|
|
285
|
+
//
|
|
286
|
+
// The disposer swap is the same trick the blob effect below uses \u2014 these
|
|
287
|
+
// effects must outlive the component that happened to instantiate the
|
|
288
|
+
// store, or persistence would stop the first time that component
|
|
289
|
+
// unmounted.
|
|
290
|
+
var prevFieldDisposers = activeDisposers;
|
|
291
|
+
activeDisposers = null;
|
|
292
|
+
if (fieldMap) {
|
|
293
|
+
for (var fk in fieldMap) {
|
|
294
|
+
if (!Object.prototype.hasOwnProperty.call(fieldMap, fk)) continue;
|
|
295
|
+
if (!result[fk] || !result[fk]._isSignal) {
|
|
296
|
+
console.warn('[stx:store] persist.keys names a field that is not a signal:', id, fk);
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
(function(field, cfg, signal) {
|
|
300
|
+
if (cfg.backend === 'cookie') {
|
|
301
|
+
// useCookie owns path / max-age / SameSite / Secure, so cookie
|
|
302
|
+
// attributes do not have to be reimplemented here. It is a
|
|
303
|
+
// string-valued signal, hence serialize on the way out.
|
|
304
|
+
var cookieSignal = useCookie(cfg.key, cfg.cookieOpts);
|
|
305
|
+
var initialCookie = cookieSignal();
|
|
306
|
+
if (initialCookie !== '' && initialCookie != null) {
|
|
307
|
+
try { signal.set(cfg.deserialize(initialCookie)); }
|
|
308
|
+
catch(e) { console.warn('[stx:store] persist read error:', id, field, e); }
|
|
309
|
+
}
|
|
310
|
+
effect(function() {
|
|
311
|
+
var next = signal();
|
|
312
|
+
try { cookieSignal.set(next == null ? '' : String(cfg.serialize(next))); }
|
|
313
|
+
catch(e) { console.warn('[stx:store] persist write error:', id, field, e); }
|
|
314
|
+
});
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
try {
|
|
318
|
+
var rawValue = cfg.backend.getItem(cfg.key);
|
|
319
|
+
if (rawValue !== null) signal.set(cfg.deserialize(rawValue));
|
|
320
|
+
} catch(e) { console.warn('[stx:store] persist read error:', id, field, e); }
|
|
321
|
+
effect(function() {
|
|
322
|
+
var value = signal();
|
|
323
|
+
try { cfg.backend.setItem(cfg.key, String(cfg.serialize(value))); }
|
|
324
|
+
catch(e) { console.warn('[stx:store] persist write error:', id, field, e); }
|
|
325
|
+
});
|
|
326
|
+
})(fk, _mappedConfig(fk), result[fk]);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
activeDisposers = prevFieldDisposers;
|
|
330
|
+
|
|
331
|
+
// Write on change (debounced)
|
|
332
|
+
var writeTimer = null;
|
|
333
|
+
var prevPersistDisposers = activeDisposers;
|
|
334
|
+
activeDisposers = null;
|
|
335
|
+
effect(function() {
|
|
336
|
+
var snapshot = {};
|
|
337
|
+
var wrote = false;
|
|
338
|
+
for (var wk in result) {
|
|
339
|
+
if (result[wk] && result[wk]._isSignal && _inBlob(wk)) {
|
|
340
|
+
snapshot[wk] = result[wk]();
|
|
341
|
+
wrote = true;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
// With every field mapped to its own key there is no blob left, and
|
|
345
|
+
// writing an empty object would clobber whatever else owns that key.
|
|
346
|
+
if (!wrote || storageType === 'cookie') return;
|
|
347
|
+
if (writeTimer) clearTimeout(writeTimer);
|
|
348
|
+
writeTimer = setTimeout(function() {
|
|
349
|
+
console.log('[stx:store] persisting:', id, 'key:', storageKey, Object.keys(snapshot));
|
|
350
|
+
try { storageType.setItem(storageKey, String(defaultSerialize(snapshot))); } catch(e) { console.warn('[stx:store] persist write error:', id, e); }
|
|
351
|
+
}, 100);
|
|
352
|
+
});
|
|
353
|
+
activeDisposers = prevPersistDisposers;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Marker so the template-scope auto-unwrap proxy knows to recursively
|
|
357
|
+
// unwrap signal-valued properties on this object. Script-level callers
|
|
358
|
+
// still see the bare store (so existing patterns like store.someSignal()
|
|
359
|
+
// keep working); only template expression evaluation auto-unwraps.
|
|
360
|
+
result._isStxStore = true;
|
|
361
|
+
|
|
362
|
+
// Carry state across a hot replacement.
|
|
363
|
+
//
|
|
364
|
+
// The NEW store object is kept rather than patching the old one: a
|
|
365
|
+
// setup-style store's actions close over the signals created in that
|
|
366
|
+
// same run, so keeping the old signals would leave the new actions
|
|
367
|
+
// writing to signals nothing is watching \u2014 an edit that appears to do
|
|
368
|
+
// nothing, which is worse than the reload this replaces. Seeding the new
|
|
369
|
+
// signals with the old values keeps state and behaviour consistent, and
|
|
370
|
+
// the caller re-renders afterwards so components rebind to this object.
|
|
371
|
+
var seed = window.stx.__hmrStoreSeed && window.stx.__hmrStoreSeed[id];
|
|
372
|
+
if (seed) {
|
|
373
|
+
for (var seedKey in seed) {
|
|
374
|
+
var target = result[seedKey];
|
|
375
|
+
if (target && target._isSignal && typeof target.set === 'function' && !target._isDerived) {
|
|
376
|
+
try { target.set(seed[seedKey]); }
|
|
377
|
+
catch (e) { /* shape changed across the edit \u2014 keep the new default */ }
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Register globally
|
|
383
|
+
window.stx._stores.set(id, result);
|
|
384
|
+
window.__STX_STORES__ = window.__STX_STORES__ || {};
|
|
385
|
+
window.__STX_STORES__[id] = result;
|
|
386
|
+
|
|
387
|
+
console.log('[stx:store] registered:', id, 'total stores:', window.stx._stores.size);
|
|
388
|
+
return result;
|
|
389
|
+
},
|
|
390
|
+
|
|
391
|
+
// Replace the store definitions in place, keeping their state \u2014 the
|
|
392
|
+
// acceptHMRUpdate contract (#1877 ask 4). Called by the dev server's HMR
|
|
393
|
+
// client when a file under storesDir changes, instead of reloading the
|
|
394
|
+
// document and throwing away everything the SPA exists to preserve.
|
|
395
|
+
__hmrReplaceStores: function(code) {
|
|
396
|
+
var seed = {};
|
|
397
|
+
window.stx._stores.forEach(function(store, id) {
|
|
398
|
+
var values = {};
|
|
399
|
+
for (var key in store) {
|
|
400
|
+
var value = store[key];
|
|
401
|
+
// Derived values recompute from state, so seeding them would fight
|
|
402
|
+
// their own recomputation.
|
|
403
|
+
if (value && value._isSignal && !value._isDerived) {
|
|
404
|
+
try { values[key] = value.peek ? value.peek() : value(); }
|
|
405
|
+
catch (e) { /* unreadable \u2014 let the new default stand */ }
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
seed[id] = values;
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
window.stx.__hmrStoreSeed = seed;
|
|
412
|
+
window.stx.__hmrStoreReplacing = true;
|
|
413
|
+
var ok = true;
|
|
414
|
+
try {
|
|
415
|
+
// Indirect eval, so the bundle evaluates at global scope the way it
|
|
416
|
+
// does when inlined into the page.
|
|
417
|
+
(0, eval)(code);
|
|
418
|
+
}
|
|
419
|
+
catch (e) {
|
|
420
|
+
ok = false;
|
|
421
|
+
console.error('[stx:hmr] store bundle failed to evaluate:', e);
|
|
422
|
+
}
|
|
423
|
+
finally {
|
|
424
|
+
window.stx.__hmrStoreReplacing = false;
|
|
425
|
+
window.stx.__hmrStoreSeed = null;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (!ok) return false;
|
|
429
|
+
|
|
430
|
+
// Components captured the PREVIOUS store object from useStore(), so
|
|
431
|
+
// re-render the route to rebind them. Still not a document reload: the
|
|
432
|
+
// swap keeps every non-store signal on the page alive.
|
|
433
|
+
if (window.stxRouter && typeof window.stxRouter.refresh === 'function') {
|
|
434
|
+
try { window.stxRouter.refresh(); }
|
|
435
|
+
catch (e) { /* a refresh that cannot run is not worth a reload here */ }
|
|
436
|
+
}
|
|
437
|
+
return true;
|
|
438
|
+
},
|
|
439
|
+
|
|
440
|
+
registerStoresClient: function(stores) {
|
|
441
|
+
window.__STX_STORES__ = window.__STX_STORES__ || {};
|
|
442
|
+
var names = Object.keys(stores || {});
|
|
443
|
+
for (var i = 0; i < names.length; i++) {
|
|
444
|
+
var name = names[i];
|
|
445
|
+
window.__STX_STORES__[name] = stores[name];
|
|
446
|
+
}
|
|
447
|
+
window.dispatchEvent(new CustomEvent('stx:stores-ready', { detail: names }));
|
|
448
|
+
},
|
|
449
|
+
|
|
450
|
+
useStore: function(id) {
|
|
451
|
+
var store = window.stx._stores.get(id);
|
|
452
|
+
if (!store && window.__STX_STORES__) {
|
|
453
|
+
store = window.__STX_STORES__[id];
|
|
454
|
+
}
|
|
455
|
+
if (!store) {
|
|
456
|
+
console.error('[stx:store] Store not found:', id, 'available:', Array.from(window.stx._stores.keys()));
|
|
457
|
+
throw new Error('[stx] Store "' + id + '" not found. Define it with defineStore() first.');
|
|
458
|
+
}
|
|
459
|
+
console.log('[stx:store] useStore:', id);
|
|
460
|
+
return store;
|
|
461
|
+
},`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Reactive style binding for the generated client runtime. */
|
|
2
|
+
export declare const SIGNALS_STYLE_RUNTIME = " function bindStyle(el, expr, passedScope = componentScope, isVisible) {\n // Capture scope at setup time - use passed scope to preserve context\n const capturedScope = { ...globalHelpers, ...passedScope, ...(findElementScope(el) || {}) };\n\n const evalExpr = () => {\n // Mirror bindClass: first try the auto-unwrap proxy (so an expression\n // like { active: count > 5 } reads signals as primitives), then retry\n // with the raw scope so call-syntax expressions like\n // { color: theme() } still work \u2014 the proxy unwraps signals to\n // values, which would make theme() try to call a primitive and\n // throw TypeError.\n try {\n const unwrapScope = createExpressionAutoUnwrapProxy(capturedScope, expr);\n const fn = __stxCompileScoped(capturedScope, [], 'return ' + expr);\n return fn(...__stxArgs(fn, unwrapScope));\n }\ncatch (e1) {\n try {\n const fn2 = __stxCompileScoped(capturedScope, [], 'return ' + expr);\n return fn2(...__stxArgs(fn2, capturedScope));\n }\ncatch (e2) {\n if (!(e2 instanceof ReferenceError) && !(e2 instanceof TypeError)) console.warn('[STX] Style expression error:', expr, e2);\n return {};\n }\n }\n };\n\n effect(() => {\n if (isVisible && !isVisible()) return;\n const value = evalExpr();\n stxHost.setStyle(el, value);\n });\n }\n";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const SIGNALS_STYLE_RUNTIME = ` function bindStyle(el, expr, passedScope = componentScope, isVisible) {
|
|
2
|
+
// Capture scope at setup time - use passed scope to preserve context
|
|
3
|
+
const capturedScope = { ...globalHelpers, ...passedScope, ...(findElementScope(el) || {}) };
|
|
4
|
+
|
|
5
|
+
const evalExpr = () => {
|
|
6
|
+
// Mirror bindClass: first try the auto-unwrap proxy (so an expression
|
|
7
|
+
// like { active: count > 5 } reads signals as primitives), then retry
|
|
8
|
+
// with the raw scope so call-syntax expressions like
|
|
9
|
+
// { color: theme() } still work \u2014 the proxy unwraps signals to
|
|
10
|
+
// values, which would make theme() try to call a primitive and
|
|
11
|
+
// throw TypeError.
|
|
12
|
+
try {
|
|
13
|
+
const unwrapScope = createExpressionAutoUnwrapProxy(capturedScope, expr);
|
|
14
|
+
const fn = __stxCompileScoped(capturedScope, [], 'return ' + expr);
|
|
15
|
+
return fn(...__stxArgs(fn, unwrapScope));
|
|
16
|
+
}
|
|
17
|
+
catch (e1) {
|
|
18
|
+
try {
|
|
19
|
+
const fn2 = __stxCompileScoped(capturedScope, [], 'return ' + expr);
|
|
20
|
+
return fn2(...__stxArgs(fn2, capturedScope));
|
|
21
|
+
}
|
|
22
|
+
catch (e2) {
|
|
23
|
+
if (!(e2 instanceof ReferenceError) && !(e2 instanceof TypeError)) console.warn('[STX] Style expression error:', expr, e2);
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
effect(() => {
|
|
30
|
+
if (isVisible && !isVisible()) return;
|
|
31
|
+
const value = evalExpr();
|
|
32
|
+
stxHost.setStyle(el, value);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Suspense boundary binding for the generated client runtime. */
|
|
2
|
+
export declare const SIGNALS_SUSPENSE_RUNTIME = " // <Suspense> boundary (#1742). Aggregates the loading/error state of every\n // descendant suspense query (useQuery/useFetch with { suspense: true }) for\n // which this is the nearest [data-stx-suspense] ancestor, and toggles three\n // regions accordingly: [data-stx-suspense-fallback] while any query is loading,\n // [data-stx-suspense-error] when one errors, [data-stx-suspense-content]\n // once all resolve. With no suspense queries inside, content shows immediately.\n function bindSuspense(el, scope) {\n if (el.__stx_suspense_bound) return;\n el.__stx_suspense_bound = true;\n\n var fallbackEl = el.querySelector('[data-stx-suspense-fallback]');\n var errorEl = el.querySelector('[data-stx-suspense-error]');\n var contentEl = el.querySelector('[data-stx-suspense-content]') || el;\n\n // Claim the descendant queries this boundary owns. closest() returns the\n // DEEPEST [data-stx-suspense] ancestor, so nested boundaries don't steal\n // each other's queries.\n var claimed = suspenseRegistry().filter(function(entry) {\n return entry.el && el.contains(entry.el) && entry.el.closest('[data-stx-suspense]') === el;\n });\n\n var anyLoading = derived(function() {\n for (var i = 0; i < claimed.length; i++) {\n if (claimed[i].loading && claimed[i].loading()) return true;\n }\n return false;\n });\n var firstError = derived(function() {\n for (var i = 0; i < claimed.length; i++) {\n var err = claimed[i].error ? claimed[i].error() : null;\n if (err) return err;\n }\n return null;\n });\n\n function setHidden(node, hidden) {\n if (!node || node === el) return;\n if (hidden) node.setAttribute('hidden', '');\n else node.removeAttribute('hidden');\n }\n\n effect(function() {\n var err = firstError();\n var loading = anyLoading();\n if (err && errorEl) {\n setHidden(errorEl, false); setHidden(fallbackEl, true); setHidden(contentEl, true);\n } else if (loading) {\n setHidden(fallbackEl, false); setHidden(contentEl, true); setHidden(errorEl, true);\n } else {\n setHidden(contentEl, false); setHidden(fallbackEl, true); setHidden(errorEl, true);\n }\n });\n\n // Bind the content subtree (inline :if / {{ }} / @click etc.). Nested\n // component scopes are still processed independently by the scope loop.\n var contentRoot = (contentEl === el) ? el : contentEl;\n Array.from(contentRoot.childNodes).forEach(function(child) { processElement(child, scope); });\n }\n";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export const SIGNALS_SUSPENSE_RUNTIME = ` // <Suspense> boundary (#1742). Aggregates the loading/error state of every
|
|
2
|
+
// descendant suspense query (useQuery/useFetch with { suspense: true }) for
|
|
3
|
+
// which this is the nearest [data-stx-suspense] ancestor, and toggles three
|
|
4
|
+
// regions accordingly: [data-stx-suspense-fallback] while any query is loading,
|
|
5
|
+
// [data-stx-suspense-error] when one errors, [data-stx-suspense-content]
|
|
6
|
+
// once all resolve. With no suspense queries inside, content shows immediately.
|
|
7
|
+
function bindSuspense(el, scope) {
|
|
8
|
+
if (el.__stx_suspense_bound) return;
|
|
9
|
+
el.__stx_suspense_bound = true;
|
|
10
|
+
|
|
11
|
+
var fallbackEl = el.querySelector('[data-stx-suspense-fallback]');
|
|
12
|
+
var errorEl = el.querySelector('[data-stx-suspense-error]');
|
|
13
|
+
var contentEl = el.querySelector('[data-stx-suspense-content]') || el;
|
|
14
|
+
|
|
15
|
+
// Claim the descendant queries this boundary owns. closest() returns the
|
|
16
|
+
// DEEPEST [data-stx-suspense] ancestor, so nested boundaries don't steal
|
|
17
|
+
// each other's queries.
|
|
18
|
+
var claimed = suspenseRegistry().filter(function(entry) {
|
|
19
|
+
return entry.el && el.contains(entry.el) && entry.el.closest('[data-stx-suspense]') === el;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
var anyLoading = derived(function() {
|
|
23
|
+
for (var i = 0; i < claimed.length; i++) {
|
|
24
|
+
if (claimed[i].loading && claimed[i].loading()) return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
});
|
|
28
|
+
var firstError = derived(function() {
|
|
29
|
+
for (var i = 0; i < claimed.length; i++) {
|
|
30
|
+
var err = claimed[i].error ? claimed[i].error() : null;
|
|
31
|
+
if (err) return err;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
function setHidden(node, hidden) {
|
|
37
|
+
if (!node || node === el) return;
|
|
38
|
+
if (hidden) node.setAttribute('hidden', '');
|
|
39
|
+
else node.removeAttribute('hidden');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
effect(function() {
|
|
43
|
+
var err = firstError();
|
|
44
|
+
var loading = anyLoading();
|
|
45
|
+
if (err && errorEl) {
|
|
46
|
+
setHidden(errorEl, false); setHidden(fallbackEl, true); setHidden(contentEl, true);
|
|
47
|
+
} else if (loading) {
|
|
48
|
+
setHidden(fallbackEl, false); setHidden(contentEl, true); setHidden(errorEl, true);
|
|
49
|
+
} else {
|
|
50
|
+
setHidden(contentEl, false); setHidden(fallbackEl, true); setHidden(errorEl, true);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Bind the content subtree (inline :if / {{ }} / @click etc.). Nested
|
|
55
|
+
// component scopes are still processed independently by the scope loop.
|
|
56
|
+
var contentRoot = (contentEl === el) ? el : contentEl;
|
|
57
|
+
Array.from(contentRoot.childNodes).forEach(function(child) { processElement(child, scope); });
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Timer and utility composables used by the generated client runtime. */
|
|
2
|
+
export declare const SIGNALS_TIMER_RUNTIME = " // ==========================================================================\n // Timer & Utility Composables\n // ==========================================================================\n\n function useDebounce(fn, delay) {\n delay = delay || 250;\n var timer = null;\n var lastArgs = null;\n var debounced = function() {\n lastArgs = Array.prototype.slice.call(arguments);\n if (timer !== null) clearTimeout(timer);\n var args = lastArgs;\n timer = setTimeout(function() {\n timer = null;\n lastArgs = null;\n fn.apply(null, args);\n }, delay);\n };\n debounced.cancel = function() {\n if (timer !== null) { clearTimeout(timer); timer = null; lastArgs = null; }\n };\n debounced.flush = function() {\n if (timer !== null && lastArgs !== null) {\n clearTimeout(timer); timer = null;\n var args = lastArgs; lastArgs = null;\n fn.apply(null, args);\n }\n };\n debounced.pending = function() { return timer !== null; };\n onDestroy(debounced.cancel);\n return debounced;\n }\n\n // VueUse-compatible alias; both names use the same callback contract.\n var useDebounceFn = useDebounce;\n\n function useDebouncedValue(getter, delay) {\n delay = delay || 250;\n var current = getter();\n var listeners = [];\n var timer = null;\n function schedule() {\n if (timer !== null) clearTimeout(timer);\n timer = setTimeout(function() {\n timer = null;\n var next = getter();\n if (next !== current) {\n current = next;\n listeners.forEach(function(fn) { fn(current); });\n }\n }, delay);\n }\n schedule();\n onDestroy(function() { if (timer !== null) clearTimeout(timer); listeners = []; });\n return {\n get value() { return current; },\n subscribe: function(fn) {\n listeners.push(fn);\n return function() { listeners = listeners.filter(function(f) { return f !== fn; }); };\n }\n };\n }\n\n // VueUse-compatible alias; keep the existing value-ref shape.\n var refDebounced = useDebouncedValue;\n\n function useThrottle(fn, limit) {\n limit = limit || 250;\n var timer = null;\n var lastRan = 0;\n var throttled = function() {\n var args = Array.prototype.slice.call(arguments);\n var now = Date.now();\n var remaining = limit - (now - lastRan);\n if (remaining <= 0) {\n if (timer !== null) { clearTimeout(timer); timer = null; }\n lastRan = now;\n fn.apply(null, args);\n }\nelse if (timer === null) {\n timer = setTimeout(function() {\n lastRan = Date.now();\n timer = null;\n fn.apply(null, args);\n }, remaining);\n }\n };\n throttled.cancel = function() {\n if (timer !== null) { clearTimeout(timer); timer = null; }\n };\n onDestroy(throttled.cancel);\n return throttled;\n }\n\n var useThrottleFn = useThrottle;\n\n function useInterval(interval, options, thirdOptions) {\n // Accept the callback-first form too \u2014 useInterval(fn, 1000) is what most\n // callers reach for, and silently ignoring the callback (the previous\n // behaviour) produced a timer that ticked into the void. An options object\n // may follow the interval \u2014 useInterval(fn, 1000, { enabled, whileVisible })\n // \u2014 or replace it \u2014 useInterval(fn, { enabled }) (#1870).\n var callback = null;\n if (typeof interval === 'function') {\n callback = interval;\n if (typeof options === 'number') {\n interval = options;\n options = thirdOptions || {};\n }\n else {\n interval = 1000;\n options = (options && typeof options === 'object') ? options : {};\n }\n }\n interval = interval || 1000;\n options = options || {};\n var count = 0;\n var id = null;\n var running = false;\n var listeners = [];\n // A tick is skipped (not counted, listeners not called) while the timer is\n // gated off: enabled is false / returns false, or whileVisible is set\n // and the document is hidden. This makes \"run only while authorized and\n // visible\" expressible without the caller hand-pausing the timer (#1870).\n function shouldTick() {\n if (options.whileVisible && typeof document !== 'undefined' && document.hidden) return false;\n var en = options.enabled;\n if (typeof en === 'function') return !!en();\n return en !== false;\n }\n function tick() {\n if (!shouldTick()) return;\n count++;\n listeners.forEach(function(fn) { fn(count); });\n }\n function resume() {\n if (running) return;\n running = true;\n id = setInterval(tick, interval);\n if (options.immediate) tick();\n }\n function pause() {\n if (!running) return;\n running = false;\n if (id !== null) { clearInterval(id); id = null; }\n }\n function reset() {\n pause();\n count = 0;\n listeners.forEach(function(fn) { fn(count); });\n resume();\n }\n if (callback) listeners.push(callback);\n resume();\n onDestroy(function() { pause(); listeners = []; });\n return {\n get counter() { return count; },\n pause: pause,\n resume: resume,\n reset: reset,\n subscribe: function(fn) {\n listeners.push(fn);\n return function() { listeners = listeners.filter(function(f) { return f !== fn; }); };\n }\n };\n }\n\n function useTimeout(callback, delay) {\n delay = delay || 1000;\n var timer = null;\n var pending = false;\n var listeners = [];\n function setPending(v) {\n if (v !== pending) {\n pending = v;\n listeners.forEach(function(fn) { fn(pending); });\n }\n }\n function start() {\n stop();\n setPending(true);\n timer = setTimeout(function() {\n timer = null;\n setPending(false);\n callback();\n }, delay);\n }\n function stop() {\n if (timer !== null) { clearTimeout(timer); timer = null; }\n setPending(false);\n }\n start();\n onDestroy(stop);\n return {\n get isPending() { return pending; },\n start: start,\n stop: stop,\n subscribe: function(fn) {\n listeners.push(fn);\n return function() { listeners = listeners.filter(function(f) { return f !== fn; }); };\n }\n };\n }\n\n var useTimeoutFn = useTimeout;\n\n function useToggle(initial) {\n var current = !!initial;\n var listeners = [];\n function notify() { listeners.forEach(function(fn) { fn(current); }); }\n function toggle() { current = !current; notify(); }\n function set(v) { v = !!v; if (v !== current) { current = v; notify(); } }\n var ref = {\n get value() { return current; },\n subscribe: function(fn) {\n listeners.push(fn);\n return function() { listeners = listeners.filter(function(f) { return f !== fn; }); };\n }\n };\n return [ref, toggle, set];\n }\n\n function useCounter(initial, options) {\n initial = initial || 0;\n options = options || {};\n var min = options.min != null ? options.min : -Infinity;\n var max = options.max != null ? options.max : Infinity;\n function clamp(v) { return Math.min(max, Math.max(min, v)); }\n var current = clamp(initial);\n var listeners = [];\n function notify() { listeners.forEach(function(fn) { fn(current); }); }\n return {\n get count() { return current; },\n inc: function(step) { current = clamp(current + (step || 1)); notify(); },\n dec: function(step) { current = clamp(current - (step || 1)); notify(); },\n set: function(v) { current = clamp(v); notify(); },\n reset: function() { current = clamp(initial); notify(); },\n subscribe: function(fn) {\n listeners.push(fn);\n return function() { listeners = listeners.filter(function(f) { return f !== fn; }); };\n }\n };\n }\n\n function useClickOutside(target, handler) {\n function resolveTarget() {\n if (typeof target === 'string') return document.querySelector(target);\n if (target && typeof target === 'object') {\n if ('current' in target) return target.current;\n if ('value' in target) return target.value;\n }\n return target;\n }\n function listener(event) {\n var el = resolveTarget();\n if (!el) return;\n if (el === event.target || el.contains(event.target)) return;\n handler(event);\n }\n document.addEventListener('pointerdown', listener, true);\n function remove() { document.removeEventListener('pointerdown', listener, true); }\n onDestroy(remove);\n return { remove: remove };\n }\n\n function useFocus(target) {\n var focused = false;\n var listeners = [];\n function resolve() {\n return typeof target === 'string' ? document.querySelector(target) : target;\n }\n function setFocused(v) {\n if (v !== focused) {\n focused = v;\n listeners.forEach(function(fn) { fn(focused); });\n }\n }\n var onFocusIn = function() { setFocused(true); };\n var onBlurOut = function() { setFocused(false); };\n var el = resolve();\n if (el) {\n el.addEventListener('focus', onFocusIn);\n el.addEventListener('blur', onBlurOut);\n focused = document.activeElement === el;\n }\n onDestroy(function() {\n var el = resolve();\n if (el) { el.removeEventListener('focus', onFocusIn); el.removeEventListener('blur', onBlurOut); }\n listeners = [];\n });\n return {\n get isFocused() { return focused; },\n focus: function() { var el = resolve(); if (el && el.focus) el.focus(); },\n blur: function() { var el = resolve(); if (el && el.blur) el.blur(); },\n subscribe: function(fn) {\n listeners.push(fn);\n return function() { listeners = listeners.filter(function(f) { return f !== fn; }); };\n }\n };\n }\n\n // Queue work after the current synchronous signal/effect flush and after\n // structural directives finish their deferred subtree hydration. The\n // microtask schedules this timer only after every subscriber has run, so a\n // :if/:for timer created later in the same signal flush runs first and its\n // template refs are available to the callback.\n function nextTick(fn) {\n return Promise.resolve().then(function() {\n return new Promise(function(resolve) {\n setTimeout(function() {\n if (fn) fn();\n resolve();\n }, 0);\n });\n });\n }\n\n // Watch several sources at once, calling back with (newValues, oldValues).\n // Declared and auto-imported but never implemented here (#1804). NOT an alias\n // of $watch, which spreads the values and passes no oldValues \u2014 callers\n // written against the declared contract would silently receive the wrong\n // arguments. Sources may be signals, Vue-style refs, or plain values.\n function watchMultiple(sources, callback, options) {\n options = options || {};\n var read = function() {\n return sources.map(function(s) {\n if (typeof s === 'function') return s();\n if (s && typeof s === 'object' && 'value' in s) return s.value;\n return s;\n });\n };\n var oldValues = read();\n var first = true;\n return effect(function() {\n var newValues = read();\n if (first) {\n first = false;\n if (!options.immediate) return;\n }\n callback(newValues, oldValues);\n oldValues = newValues;\n });\n }\n\n function useAsync(fn, options) {\n options = options || {};\n var asyncState = 'idle';\n var data = null;\n var error = null;\n var listeners = [];\n function notify() {\n var snap = { state: asyncState, data: data, error: error };\n listeners.forEach(function(fn) { fn(snap); });\n }\n function execute() {\n var args = Array.prototype.slice.call(arguments);\n asyncState = 'loading'; error = null; notify();\n return fn.apply(null, args).then(function(result) {\n data = result; asyncState = 'success'; notify(); return data;\n }).catch(function(e) {\n error = e instanceof Error ? e : new Error(String(e));\n asyncState = 'error'; notify(); return null;\n });\n }\n if (options.immediate) execute();\n return {\n get state() { return asyncState; },\n get isLoading() { return asyncState === 'loading'; },\n get error() { return error; },\n get data() { return data; },\n execute: execute,\n subscribe: function(fn) {\n listeners.push(fn);\n return function() { listeners = listeners.filter(function(f) { return f !== fn; }); };\n }\n };\n }\n";
|