@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,346 @@
|
|
|
1
|
+
export const SIGNALS_IF_RUNTIME = ` const detachedBranches = new Set();
|
|
2
|
+
function resumeDetachedBranches() {
|
|
3
|
+
if (!detachedBranches.size) return;
|
|
4
|
+
Array.from(detachedBranches).forEach(function(resume) {
|
|
5
|
+
if (!resume.el.isConnected) return;
|
|
6
|
+
detachedBranches.delete(resume);
|
|
7
|
+
resume();
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function bindIf(el, passedScope = componentScope, attrName = '@if') {
|
|
12
|
+
// Guard: prevent double-binding on the same element
|
|
13
|
+
if (el.__stx_if_bound) { console.log('[stx] bindIf SKIPPED (already bound):', el.getAttribute(attrName) || '(attr removed)', 'on', el.tagName); return; }
|
|
14
|
+
el.__stx_if_bound = true;
|
|
15
|
+
|
|
16
|
+
const expr = el.getAttribute(attrName);
|
|
17
|
+
let parent = el.parentNode;
|
|
18
|
+
|
|
19
|
+
// Guard: if element has no parent, it's detached - skip processing
|
|
20
|
+
if (!parent) {
|
|
21
|
+
console.warn('[STX] bindIf: element has no parent, skipping');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const placeholder = stxHost.anchor('stx-if');
|
|
26
|
+
// Marks where this branch's rendered content ENDS (stacksjs/stx#1955).
|
|
27
|
+
// Hiding used to remove only the cloned nodes, but a structural directive
|
|
28
|
+
// directly inside the template renders its own output as siblings that are
|
|
29
|
+
// not among those clones -- a <template :for> at the top level of a
|
|
30
|
+
// <template :if> left every row on screen after the branch went false.
|
|
31
|
+
// Only the template branch needs it; the single-element branch owns exactly
|
|
32
|
+
// the node it was bound to.
|
|
33
|
+
let endMarker = null;
|
|
34
|
+
let isInserted = true;
|
|
35
|
+
|
|
36
|
+
// Handle <template> elements specially - clone their content
|
|
37
|
+
const isTemplate = el.tagName === 'TEMPLATE';
|
|
38
|
+
if (!isTemplate) el.__stx_if_visible = state(true);
|
|
39
|
+
const componentSetupSiblings = isTemplate ? [] : findConditionalComponentSetupSiblings(el);
|
|
40
|
+
let currentNodes = isTemplate ? [] : [el, ...componentSetupSiblings];
|
|
41
|
+
|
|
42
|
+
// Capture BOTH element scope AND passedScope NOW before anything changes
|
|
43
|
+
// passedScope may contain @for iteration variables or parent component signals
|
|
44
|
+
const capturedElementScope = findElementScope(el);
|
|
45
|
+
const capturedComponentScope = { ...passedScope };
|
|
46
|
+
|
|
47
|
+
preserveConditionalComponentScopes(el, capturedComponentScope);
|
|
48
|
+
stxHost.insert(parent, placeholder, el);
|
|
49
|
+
el.removeAttribute(attrName);
|
|
50
|
+
|
|
51
|
+
if (isTemplate) {
|
|
52
|
+
// Nothing is cloned until the condition holds: the effect below clones
|
|
53
|
+
// template.content on the first true and binds it then. Every branch
|
|
54
|
+
// used to be cloned and inserted up front and the false ones removed, so
|
|
55
|
+
// a false branch still built its elements - in WebKit a <video> or
|
|
56
|
+
// <audio> sets up a media player as it is created.
|
|
57
|
+
isInserted = false;
|
|
58
|
+
stxHost.remove(el); // Remove the template element itself
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Helper to evaluate with captured scope (auto-unwraps signals).
|
|
62
|
+
// A with-scope resolves only identifiers the expression actually references,
|
|
63
|
+
// so the conditional subscribes narrowly instead of reading every signal
|
|
64
|
+
// in a component scope. That broad subscription made an unrelated ref
|
|
65
|
+
// update re-enter structural removal while the real condition was already
|
|
66
|
+
// removing the same subtree. First try the auto-unwrap proxy (so a bare
|
|
67
|
+
// comparison like count > 5 reads the signal value), then retry with the
|
|
68
|
+
// raw scope so call syntax like count() === 0 still works (#1733).
|
|
69
|
+
const evalExpr = (expression) => {
|
|
70
|
+
// Skip placeholder expressions like __TITLE__ (build-time placeholders)
|
|
71
|
+
if (/^__[A-Z_]+__$/.test(expression.trim())) {
|
|
72
|
+
return expression;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const scope = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };
|
|
76
|
+
const unwrapScope = createExpressionAutoUnwrapProxy(scope, expression);
|
|
77
|
+
const fn = __stxCompileScoped(unwrapScope, [], 'return ' + expression + '');
|
|
78
|
+
return fn(...__stxArgs(fn, unwrapScope));
|
|
79
|
+
}
|
|
80
|
+
catch (e1) {
|
|
81
|
+
try {
|
|
82
|
+
// Retry without the unwrap proxy so call-syntax (signal()) works.
|
|
83
|
+
const scope2 = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };
|
|
84
|
+
const fn2 = __stxCompileScoped(scope2, [], 'return ' + expression + '');
|
|
85
|
+
return fn2(...__stxArgs(fn2, scope2));
|
|
86
|
+
}
|
|
87
|
+
catch (e2) {
|
|
88
|
+
if (!(e2 instanceof ReferenceError) && !(e2 instanceof TypeError)) console.warn('[STX] Expression error:', expression, e2);
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Track if children have been processed
|
|
95
|
+
let childrenProcessed = false;
|
|
96
|
+
|
|
97
|
+
// Helper to process children with captured scope
|
|
98
|
+
const processChildrenWithScope = () => {
|
|
99
|
+
// Build the combined scope for children - no need to modify global componentScope
|
|
100
|
+
// Just pass the scope explicitly to processElement
|
|
101
|
+
const childScope = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
Array.from(el.childNodes).forEach(child => processElement(child, childScope));
|
|
105
|
+
|
|
106
|
+
childrenProcessed = true;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// A <template :if> inserts clones of template.content rather than the
|
|
110
|
+
// template element itself. Those clones still need the normal directive
|
|
111
|
+
// and interpolation pass. Previously the initially-visible branch was
|
|
112
|
+
// inserted and left inert, so bindings such as :text and {{ expression }}
|
|
113
|
+
// leaked into the rendered UI until the condition toggled.
|
|
114
|
+
const processTemplateNodes = (nodes) => {
|
|
115
|
+
const childScope = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };
|
|
116
|
+
// Components compiled inside a <template :if> carry setup scripts in the
|
|
117
|
+
// template content. Browser-cloned scripts are inert, so register their
|
|
118
|
+
// scopes and forwarded props before walking the inserted branch. This is
|
|
119
|
+
// the same component hydration path used by <template :for>.
|
|
120
|
+
hydrateComponentScopes(nodes, childScope);
|
|
121
|
+
nodes.forEach(node => {
|
|
122
|
+
if (!node.__stx_disposers && node.tagName !== 'SCRIPT')
|
|
123
|
+
node.__stx_effect_disposers = trackEffects(function() { processElement(node, childScope); });
|
|
124
|
+
if (node.nodeType === 1) {
|
|
125
|
+
node.removeAttribute('x-cloak');
|
|
126
|
+
node.querySelectorAll('[x-cloak]').forEach(c => c.removeAttribute('x-cloak'));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
resumeDetachedBranches();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// Evaluate the :if expression \u2014 use direct signal read for simple refs,
|
|
133
|
+
// falling back to evalExpr for complex expressions
|
|
134
|
+
const fullScope = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };
|
|
135
|
+
const directSignal = fullScope[expr];
|
|
136
|
+
|
|
137
|
+
effect(() => {
|
|
138
|
+
parent = followPlaceholder(placeholder, parent, currentNodes);
|
|
139
|
+
var value;
|
|
140
|
+
if (directSignal && (directSignal._isSignal || directSignal._isDerived)) {
|
|
141
|
+
value = directSignal();
|
|
142
|
+
console.log('[stx] bindIf effect (direct):', expr, '\u2192', value, 'isInserted:', isInserted);
|
|
143
|
+
} else {
|
|
144
|
+
value = evalExpr(expr);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (isTemplate) {
|
|
148
|
+
if (value && !isInserted) {
|
|
149
|
+
// Re-insert cloned content
|
|
150
|
+
currentNodes = Array.from(el.content.childNodes).map(n => stxHost.clone(n));
|
|
151
|
+
const insertionAnchor = placeholder.nextSibling;
|
|
152
|
+
currentNodes.forEach(node => stxHost.insert(parent, node, insertionAnchor));
|
|
153
|
+
// Bound AFTER the clones, so hiding can remove whatever a nested
|
|
154
|
+
// structural directive rendered as their sibling (#1955).
|
|
155
|
+
if (!endMarker) endMarker = stxHost.anchor('stx-if-end');
|
|
156
|
+
stxHost.insert(parent, endMarker, insertionAnchor);
|
|
157
|
+
processTemplateNodes(currentNodes);
|
|
158
|
+
childrenProcessed = true;
|
|
159
|
+
// Stamp insertion time for click propagation guard
|
|
160
|
+
currentNodes.forEach(function(n) { if (n.nodeType === 1) n.__stx_shown_at = performance.now(); });
|
|
161
|
+
isInserted = true;
|
|
162
|
+
}
|
|
163
|
+
else if (!value && isInserted) {
|
|
164
|
+
// Remove all current nodes. Do NOT disposeSubtreeScopes \u2014 :if is a
|
|
165
|
+
// toggle, not a permanent unmount; see the single-element branch
|
|
166
|
+
// below and #1737. Effects are disposed, though: these clones are never
|
|
167
|
+
// reused, and a re-show clones afresh, so leaving them bound only
|
|
168
|
+
// accumulates work (#1954).
|
|
169
|
+
//
|
|
170
|
+
// Everything between the placeholder and the end marker goes, not
|
|
171
|
+
// just the clones: a nested :for or :if renders siblings of its own
|
|
172
|
+
// that no clone list contains (#1955).
|
|
173
|
+
// Only walk the range when THIS binding inserted the content and
|
|
174
|
+
// left its marker. Without that guard the walk ran to the end of the
|
|
175
|
+
// parent and took a sibling <template :if> with it -- the initial
|
|
176
|
+
// server-rendered state has no marker to stop at.
|
|
177
|
+
if (endMarker && endMarker.parentNode === parent) {
|
|
178
|
+
var leaving = [];
|
|
179
|
+
for (var cursor = placeholder.nextSibling; cursor && cursor !== endMarker; cursor = cursor.nextSibling) leaving.push(cursor);
|
|
180
|
+
suspendSubtreeScopes(leaving);
|
|
181
|
+
var doomed = placeholder.nextSibling;
|
|
182
|
+
while (doomed && doomed !== endMarker) {
|
|
183
|
+
var nextDoomed = doomed.nextSibling;
|
|
184
|
+
disposeSubtreeEffects(doomed);
|
|
185
|
+
stxHost.remove(doomed);
|
|
186
|
+
doomed = nextDoomed;
|
|
187
|
+
}
|
|
188
|
+
stxHost.remove(endMarker);
|
|
189
|
+
}
|
|
190
|
+
suspendSubtreeScopes(currentNodes.filter(node => node.parentNode));
|
|
191
|
+
currentNodes.forEach(node => { disposeSubtreeEffects(node); stxHost.remove(node); });
|
|
192
|
+
currentNodes = [];
|
|
193
|
+
isInserted = false;
|
|
194
|
+
childrenProcessed = false;
|
|
195
|
+
}
|
|
196
|
+
else if (value && isInserted && !childrenProcessed) {
|
|
197
|
+
// Initial template content is cloned before the effect runs. Process
|
|
198
|
+
// it after the condition is confirmed so hidden branches stay inert.
|
|
199
|
+
// Keep hydration synchronous so the outer scope walk cannot bind
|
|
200
|
+
// caller-owned slot expressions first, while peek() prevents child
|
|
201
|
+
// reads from subscribing to this conditional effect.
|
|
202
|
+
childrenProcessed = true;
|
|
203
|
+
peek(function() {
|
|
204
|
+
if (isInserted) processTemplateNodes(currentNodes);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// Native hosts keep a view hierarchy rather than a DOM subtree. Route
|
|
210
|
+
// the conditional through the same visibility contract as :show so a
|
|
211
|
+
// false branch is hidden in the first render and in every loop row;
|
|
212
|
+
// the structural remove/insert below still preserves browser and
|
|
213
|
+
// native lifecycle behaviour when the branch changes.
|
|
214
|
+
if (stxHost.isNative) stxHost.setVisible(el, !!value);
|
|
215
|
+
if (value && !isInserted) {
|
|
216
|
+
console.log('[stx] bindIf INSERTING element for :if=' + expr);
|
|
217
|
+
const insertionAnchor = placeholder.nextSibling;
|
|
218
|
+
currentNodes.forEach(node => stxHost.insert(parent, node, insertionAnchor));
|
|
219
|
+
if (parent && parent.__stx_detached_if) currentNodes.forEach(node => parent.__stx_detached_if.delete(node));
|
|
220
|
+
el.__stx_if_visible.set(true);
|
|
221
|
+
el.__stx_shown_at = performance.now();
|
|
222
|
+
isInserted = true;
|
|
223
|
+
// A previously hydrated parent skips hydrateShownBranch on re-show.
|
|
224
|
+
// Its children may have become visible while it was detached, so
|
|
225
|
+
// resume their pending bindings now that the subtree is connected.
|
|
226
|
+
peek(resumeDetachedBranches);
|
|
227
|
+
// Shown before, so the components in it mounted and were suspended
|
|
228
|
+
// when it hid. They mount again now -- in a microtask, the same
|
|
229
|
+
// moment their first mount ran, and only if still shown by then.
|
|
230
|
+
if (childrenProcessed) {
|
|
231
|
+
queueMicrotask(function() {
|
|
232
|
+
if (isInserted) peek(function() { resumeSubtreeScopes(currentNodes); });
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else if (!value && isInserted) {
|
|
237
|
+
console.log('[stx] bindIf REMOVING element for :if=' + expr, 'el.isConnected:', el.isConnected, 'parent:', parent.tagName);
|
|
238
|
+
el.__stx_if_visible.set(false);
|
|
239
|
+
// Unmounted, not disposed: the components in it release what they
|
|
240
|
+
// hold while their markup is still on the page, and keep their scopes.
|
|
241
|
+
suspendSubtreeScopes(currentNodes);
|
|
242
|
+
// Do NOT disposeSubtreeScopes here. :if is a TOGGLE \u2014 the element is
|
|
243
|
+
// re-shown when the condition flips back \u2014 not a permanent unmount.
|
|
244
|
+
// A nested data-stx-scope inside this subtree is created once by its
|
|
245
|
+
// setup IIFE at page load and stored in window.stx._scopes; deleting
|
|
246
|
+
// it on hide left re-show unable to recreate it, so nested scoped
|
|
247
|
+
// components under reactive conditionals rendered all branches at
|
|
248
|
+
// once (#1737). Permanent disposal stays in bindFor (item removal)
|
|
249
|
+
// and cleanupContainer (SPA navigation). The double-bind guards make
|
|
250
|
+
// re-show idempotent, so toggling doesn't leak.
|
|
251
|
+
currentNodes.forEach(node => stxHost.remove(node));
|
|
252
|
+
// Detached nodes are out of reach of a DOM walk, so an ancestor row or
|
|
253
|
+
// branch removed while this is hidden could not dispose their effects
|
|
254
|
+
// (#1954). Record them on the parent that keeps the placeholder.
|
|
255
|
+
if (parent) {
|
|
256
|
+
if (!parent.__stx_detached_if) parent.__stx_detached_if = new Set();
|
|
257
|
+
currentNodes.forEach(node => parent.__stx_detached_if.add(node));
|
|
258
|
+
}
|
|
259
|
+
isInserted = false;
|
|
260
|
+
console.log('[stx] bindIf REMOVED, el.isConnected:', el.isConnected);
|
|
261
|
+
}
|
|
262
|
+
// Process the entire subtree when element is visible and not yet processed.
|
|
263
|
+
// peek() keeps child effects from subscribing to this bindIf's tracked
|
|
264
|
+
// signals. Use capturedComponentScope (not global componentScope) so
|
|
265
|
+
// iteration variables from an enclosing for-loop remain in scope.
|
|
266
|
+
// Process the element itself, not just children, so sibling directives
|
|
267
|
+
// on the same element (e.g. text binding alongside if) fire too. The if
|
|
268
|
+
// attribute was already removed, so no recursion.
|
|
269
|
+
//
|
|
270
|
+
// Synchronously when the branch is on the page, as the template and
|
|
271
|
+
// if/else-chain branches already are. This pass used to wait for a
|
|
272
|
+
// timer, so every :if (and each :for inside one) filled in a frame
|
|
273
|
+
// after the rest of the page was bound: a screen opened from a tab bar
|
|
274
|
+
// showed its sections arriving one after another.
|
|
275
|
+
if (value && isInserted && !childrenProcessed) {
|
|
276
|
+
childrenProcessed = true;
|
|
277
|
+
// Until this pass runs, the shown subtree still holds literal {{ }}.
|
|
278
|
+
// Flag it so the hydration audit doesn't report those as a binding
|
|
279
|
+
// miss when the pass is deferred (#1773).
|
|
280
|
+
el.__stx_if_pending = true;
|
|
281
|
+
var hydrateShownBranch = function() {
|
|
282
|
+
// Removed with its row, or hidden again, before this ran. Hydrating
|
|
283
|
+
// a detached element now creates effects nothing will dispose
|
|
284
|
+
// (#1954). Leave it unprocessed so the next show schedules the pass.
|
|
285
|
+
if (!el.isConnected) {
|
|
286
|
+
childrenProcessed = false;
|
|
287
|
+
el.__stx_if_pending = false;
|
|
288
|
+
// Hidden by an ancestor rather than by this condition (a page :if
|
|
289
|
+
// around a component whose own :if queued this pass), the branch
|
|
290
|
+
// comes back without this effect running, and a component shown
|
|
291
|
+
// again kept its :for rows as raw markup.
|
|
292
|
+
var resume = function() {
|
|
293
|
+
if (!isInserted || childrenProcessed) return;
|
|
294
|
+
childrenProcessed = true;
|
|
295
|
+
el.__stx_if_pending = true;
|
|
296
|
+
peek(hydrateShownBranch);
|
|
297
|
+
};
|
|
298
|
+
resume.el = el;
|
|
299
|
+
detachedBranches.add(resume);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
var childScope = { ...globalHelpers, ...capturedComponentScope, ...(capturedElementScope || {}) };
|
|
303
|
+
// A false single-element conditional is detached before the
|
|
304
|
+
// DOMContentLoaded component-scope pass. When it becomes visible,
|
|
305
|
+
// hydrate any component roots in the restored subtree first so
|
|
306
|
+
// projected slot bindings and component-local directives receive
|
|
307
|
+
// the same lifecycle as components inserted by template :if.
|
|
308
|
+
var wasTrackedBeforeConditionalHydration = !!el.__stx_disposers;
|
|
309
|
+
hydrateComponentScopes(currentNodes, childScope);
|
|
310
|
+
// Tracked on its own property so an ancestor row or branch removal
|
|
311
|
+
// reaches these effects too (#1954). This runs after the enclosing
|
|
312
|
+
// tracker has closed, so nothing else would collect them.
|
|
313
|
+
if (wasTrackedBeforeConditionalHydration || !el.__stx_disposers)
|
|
314
|
+
el.__stx_if_disposers = trackEffects(function() { processElement(el, childScope); });
|
|
315
|
+
// Remove x-cloak from the inserted subtree \u2014 the initial
|
|
316
|
+
// cloak removal (after processElement on the root) already
|
|
317
|
+
// ran before this deferred processing, so newly-inserted
|
|
318
|
+
// :if children still have x-cloak and stay hidden.
|
|
319
|
+
el.removeAttribute('x-cloak');
|
|
320
|
+
el.querySelectorAll('[x-cloak]').forEach(function(c) { c.removeAttribute('x-cloak'); });
|
|
321
|
+
// Deferred bind complete \u2014 the audit may inspect this subtree now.
|
|
322
|
+
el.__stx_if_pending = false;
|
|
323
|
+
// Branches inside this one that were hidden with it can bind now.
|
|
324
|
+
resumeDetachedBranches();
|
|
325
|
+
};
|
|
326
|
+
// In a microtask, not inside this effect's own run: child effects
|
|
327
|
+
// created while it is running saw the data mid-change (a screen
|
|
328
|
+
// swapping workouts) and recorded expressions that had never
|
|
329
|
+
// evaluated. A microtask still runs before the browser paints, so
|
|
330
|
+
// the branch is bound in the first frame all the same. A branch
|
|
331
|
+
// shown while detached (inside content not on the page yet) waits a
|
|
332
|
+
// macrotask, when it has been placed.
|
|
333
|
+
if (el.isConnected) {
|
|
334
|
+
// A native host sends the insertion as soon as its current
|
|
335
|
+
// mutation turn ends. Hydrating in a later microtask would put the
|
|
336
|
+
// handler registration in a second batch, leaving a same-turn tap
|
|
337
|
+
// with the source expression instead of a native handler id.
|
|
338
|
+
if (stxHost.isNative) peek(hydrateShownBranch);
|
|
339
|
+
else queueMicrotask(function() { peek(hydrateShownBranch); });
|
|
340
|
+
}
|
|
341
|
+
else setTimeout(hydrateShownBranch, 0);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
`;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export function signalsKeptRuntime(createKeptStoreSource, indexedDbBackendSource, createQueryCacheSource, queryTargetMatchesSource) {
|
|
2
|
+
return ` // A value kept between visits, for a phone app between launches: the tab a
|
|
3
|
+
// user opens right after starting the app draws last time's data at once
|
|
4
|
+
// and the fresh answer replaces it. Kept under stx:kept:, in a scope such as
|
|
5
|
+
// the signed-in account, so one person's data is never shown to another. A
|
|
6
|
+
// scope of false, null or '' keeps nothing (a plain state), for a page or a
|
|
7
|
+
// visitor that should not leave data behind; no scope at all uses the one
|
|
8
|
+
// given to setKeptScope. forgetKeptState(scope) removes a scope's values, or
|
|
9
|
+
// every kept value.
|
|
10
|
+
//
|
|
11
|
+
// Stored by the kept store (offline/kept-store.ts): small values in
|
|
12
|
+
// localStorage, readable on the first draw, large ones in IndexedDB, written
|
|
13
|
+
// off the critical path and read back asynchronously. Values kept before it
|
|
14
|
+
// are read where they are.
|
|
15
|
+
var STX_KEPT_PREFIX = 'stx:kept:';
|
|
16
|
+
var __stxKept = (${createKeptStoreSource})(undefined, ${indexedDbBackendSource});
|
|
17
|
+
var __stxQueries = (${createQueryCacheSource})({ state: state, kept: __stxKept, prefix: STX_KEPT_PREFIX, matches: ${queryTargetMatchesSource} });
|
|
18
|
+
function stxKeptPrefix(scope) {
|
|
19
|
+
return STX_KEPT_PREFIX + (scope === undefined || scope === null || scope === '' ? '' : String(scope) + ':');
|
|
20
|
+
}
|
|
21
|
+
function keptState(name, initialValue, options) {
|
|
22
|
+
var scope = options ? options.scope : undefined;
|
|
23
|
+
if (scope === undefined) scope = __stxQueries.scope();
|
|
24
|
+
if (scope === false || scope === null || scope === '') return state(initialValue);
|
|
25
|
+
var key = stxKeptPrefix(scope) + name;
|
|
26
|
+
var hit = __stxKept.peek(key);
|
|
27
|
+
var s = state(hit ? hit.value : initialValue);
|
|
28
|
+
var restored = {};
|
|
29
|
+
var touched = false;
|
|
30
|
+
s.subscribe(function(value) {
|
|
31
|
+
if (value === restored) return;
|
|
32
|
+
touched = true;
|
|
33
|
+
__stxKept.set(key, value);
|
|
34
|
+
});
|
|
35
|
+
// Large values are kept where only an asynchronous read reaches: they
|
|
36
|
+
// arrive a moment later, unless the screen set its own first.
|
|
37
|
+
if (!hit) {
|
|
38
|
+
__stxKept.load(key).then(function(found) {
|
|
39
|
+
if (!found || touched) return;
|
|
40
|
+
restored = found.value;
|
|
41
|
+
s.set(found.value);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return s;
|
|
45
|
+
}
|
|
46
|
+
function forgetKeptState(scope) {
|
|
47
|
+
return __stxKept.forget(stxKeptPrefix(scope));
|
|
48
|
+
}
|
|
49
|
+
// The account kept state and cached queries belong to when they name none.
|
|
50
|
+
function setKeptScope(scope) {
|
|
51
|
+
__stxQueries.setScope(scope);
|
|
52
|
+
}
|
|
53
|
+
// Finish writing what is kept (before signing out, or in a test).
|
|
54
|
+
function flushKeptState() {
|
|
55
|
+
return __stxKept.flush();
|
|
56
|
+
}
|
|
57
|
+
// A query kept per account and refreshed behind: see offline/query-cache.ts.
|
|
58
|
+
function cachedQuery(key, options) {
|
|
59
|
+
return __stxQueries.cachedQuery(key, options);
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Deferred island hydration scheduling for the generated client runtime. */
|
|
2
|
+
export declare const SIGNALS_LAZY_HYDRATION_RUNTIME = " // Lazy hydration: defer processElement for subtrees marked with stx-hydrate.\n // Triggers: \"visible\" (IntersectionObserver), \"idle\" (requestIdleCallback),\n // \"interaction\" (mouseenter/click/focus), \"media:<query>\" (matchMedia).\n function deferHydration(el, trigger, scope) {\n if (el.__stx_hydration_scheduled) return;\n el.__stx_hydration_scheduled = true;\n\n var run = function() {\n if (el.__stx_hydrated) return;\n el.__stx_hydrated = true;\n el.__stx_hydration_cancel = null; // trigger consumed \u2014 nothing left to cancel\n el.removeAttribute('stx-hydrate');\n var sid = el.getAttribute && el.getAttribute('data-stx-scope');\n\n // Everything downstream of the island setup running: merge the now-\n // registered scope, bind the subtree, flush onMount, announce hydration.\n // Factored out so the async chunked path can run it from a <script> load\n // event while the inline path runs it synchronously (#1746).\n var finishHydrate = function() {\n var effectiveScope = scope;\n if (sid) {\n var reg = window.stx._scopes ? window.stx._scopes[sid] : null;\n if (reg) effectiveScope = Object.assign({}, scope || {}, reg);\n }\n // Walk children and process them with the (now scope-merged) context\n Array.from(el.children).forEach(function(child) { processElement(child, effectiveScope); });\n // Also process the element itself (attributes/bindings on the host)\n processAttributesOnly(el, effectiveScope);\n // Fire this scope's onMount now that it has actually hydrated \u2014 the\n // initial mount pass deferred it for stx-hydrate scopes so onMount lands\n // on hydration, not at page load (#1746). Guarded by __mounted so it\n // never double-fires with the eager path.\n var sv = sid && window.stx._scopes ? window.stx._scopes[sid] : null;\n if (sv && sv.__mountCallbacks && !sv.__mounted) {\n sv.__mounted = true;\n runMountCallbacks(sv.__mountCallbacks, scopeDestroySink(sv));\n }\n window.dispatchEvent(new CustomEvent('stx:hydrated', { detail: { el: el, trigger: trigger } }));\n };\n\n // Island (#1746): the component's setup script was emitted inert\n // (type=\"stx/island\") so the browser skipped it at parse. Run it now \u2014 it\n // registers the scope (signals + methods) AND runs any side-effectful\n // setup (e.g. a fetch in the <script client> body) at hydration time.\n var islandScript = sid ? document.querySelector('script[data-stx-island=\"' + sid + '\"]') : null;\n if (islandScript && !islandScript.__stx_ran) {\n islandScript.__stx_ran = true;\n var chunkSrc = islandScript.getAttribute && islandScript.getAttribute('data-stx-src');\n if (chunkSrc) {\n // Chunked island (production build): the IIFE lives in a separate\n // file fetched only now. Load it via a real <script src> (CSP-clean \u2014\n // no eval/new Function) and defer ALL downstream work to its load\n // event, since the scope isn't registered until the chunk executes.\n var s = document.createElement('script');\n s.src = chunkSrc;\n // Subresource Integrity (opt-in at build): pin the chunk's bytes.\n var integ = islandScript.getAttribute('data-stx-integrity');\n if (integ) s.integrity = integ;\n s.onload = finishHydrate;\n s.onerror = function() {\n // Network error / 404: the island can't become interactive. Log,\n // emit an observable event (analytics/monitoring can react), then\n // best-effort finish. The server-rendered HTML stays visible\n // (x-cloak was already removed on arming) \u2014 it just won't wire up.\n console.error('[stx] island chunk load failed:', sid, chunkSrc);\n window.dispatchEvent(new CustomEvent('stx:island-error', { detail: { el: el, scopeId: sid, src: chunkSrc } }));\n finishHydrate();\n };\n document.head.appendChild(s);\n return; // finishHydrate runs from the chunk's load event\n }\n // Inline island (dev / SSR / chunking off): execute synchronously.\n // eslint-disable-next-line no-new-func\n try { (new Function(islandScript.textContent))(); }\n catch (e) { console.error('[stx] island setup error:', sid, e); }\n }\n finishHydrate();\n };\n\n // Record how to cancel a still-pending trigger so SPA navigation can tear it\n // down \u2014 otherwise an unhydrated island's observer/timer/listener leaks and\n // may fire run() on a detached element after the page swapped (#1746).\n // Cleared once run() fires (it guards on __stx_hydrated anyway).\n if (trigger === 'idle') {\n if (typeof requestIdleCallback === 'function') {\n var idleId = requestIdleCallback(run, { timeout: 2000 });\n el.__stx_hydration_cancel = function() { if (typeof cancelIdleCallback === 'function') cancelIdleCallback(idleId); };\n }\n else {\n var idleTimer = setTimeout(run, 200);\n el.__stx_hydration_cancel = function() { clearTimeout(idleTimer); };\n }\n }\n else if (trigger === 'visible') {\n if (typeof IntersectionObserver === 'function') {\n var io = new IntersectionObserver(function(entries) {\n entries.forEach(function(e) {\n if (e.isIntersecting) { io.disconnect(); run(); }\n });\n }, { rootMargin: '50px' });\n io.observe(el);\n el.__stx_hydration_cancel = function() { io.disconnect(); };\n } else {\n run(); // fallback: no IO support, hydrate immediately\n }\n }\n else if (trigger === 'interaction') {\n var events = ['mouseenter', 'click', 'focusin', 'touchstart'];\n var handler = function() {\n events.forEach(function(ev) { el.removeEventListener(ev, handler); });\n run();\n };\n events.forEach(function(ev) { el.addEventListener(ev, handler, { once: true, passive: true }); });\n el.__stx_hydration_cancel = function() { events.forEach(function(ev) { el.removeEventListener(ev, handler); }); };\n }\n else if (trigger && trigger.indexOf('media:') === 0) {\n var query = trigger.slice(6);\n var mql = window.matchMedia(query);\n if (mql.matches) run();\n else {\n var mqHandler = function(e) {\n if (e.matches) { mql.removeEventListener('change', mqHandler); run(); }\n };\n mql.addEventListener('change', mqHandler);\n el.__stx_hydration_cancel = function() { mql.removeEventListener('change', mqHandler); };\n }\n }\n else {\n // Unknown trigger \u2014 hydrate immediately\n run();\n }\n }\n";
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export const SIGNALS_LAZY_HYDRATION_RUNTIME = ` // Lazy hydration: defer processElement for subtrees marked with stx-hydrate.
|
|
2
|
+
// Triggers: "visible" (IntersectionObserver), "idle" (requestIdleCallback),
|
|
3
|
+
// "interaction" (mouseenter/click/focus), "media:<query>" (matchMedia).
|
|
4
|
+
function deferHydration(el, trigger, scope) {
|
|
5
|
+
if (el.__stx_hydration_scheduled) return;
|
|
6
|
+
el.__stx_hydration_scheduled = true;
|
|
7
|
+
|
|
8
|
+
var run = function() {
|
|
9
|
+
if (el.__stx_hydrated) return;
|
|
10
|
+
el.__stx_hydrated = true;
|
|
11
|
+
el.__stx_hydration_cancel = null; // trigger consumed \u2014 nothing left to cancel
|
|
12
|
+
el.removeAttribute('stx-hydrate');
|
|
13
|
+
var sid = el.getAttribute && el.getAttribute('data-stx-scope');
|
|
14
|
+
|
|
15
|
+
// Everything downstream of the island setup running: merge the now-
|
|
16
|
+
// registered scope, bind the subtree, flush onMount, announce hydration.
|
|
17
|
+
// Factored out so the async chunked path can run it from a <script> load
|
|
18
|
+
// event while the inline path runs it synchronously (#1746).
|
|
19
|
+
var finishHydrate = function() {
|
|
20
|
+
var effectiveScope = scope;
|
|
21
|
+
if (sid) {
|
|
22
|
+
var reg = window.stx._scopes ? window.stx._scopes[sid] : null;
|
|
23
|
+
if (reg) effectiveScope = Object.assign({}, scope || {}, reg);
|
|
24
|
+
}
|
|
25
|
+
// Walk children and process them with the (now scope-merged) context
|
|
26
|
+
Array.from(el.children).forEach(function(child) { processElement(child, effectiveScope); });
|
|
27
|
+
// Also process the element itself (attributes/bindings on the host)
|
|
28
|
+
processAttributesOnly(el, effectiveScope);
|
|
29
|
+
// Fire this scope's onMount now that it has actually hydrated \u2014 the
|
|
30
|
+
// initial mount pass deferred it for stx-hydrate scopes so onMount lands
|
|
31
|
+
// on hydration, not at page load (#1746). Guarded by __mounted so it
|
|
32
|
+
// never double-fires with the eager path.
|
|
33
|
+
var sv = sid && window.stx._scopes ? window.stx._scopes[sid] : null;
|
|
34
|
+
if (sv && sv.__mountCallbacks && !sv.__mounted) {
|
|
35
|
+
sv.__mounted = true;
|
|
36
|
+
runMountCallbacks(sv.__mountCallbacks, scopeDestroySink(sv));
|
|
37
|
+
}
|
|
38
|
+
window.dispatchEvent(new CustomEvent('stx:hydrated', { detail: { el: el, trigger: trigger } }));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Island (#1746): the component's setup script was emitted inert
|
|
42
|
+
// (type="stx/island") so the browser skipped it at parse. Run it now \u2014 it
|
|
43
|
+
// registers the scope (signals + methods) AND runs any side-effectful
|
|
44
|
+
// setup (e.g. a fetch in the <script client> body) at hydration time.
|
|
45
|
+
var islandScript = sid ? document.querySelector('script[data-stx-island="' + sid + '"]') : null;
|
|
46
|
+
if (islandScript && !islandScript.__stx_ran) {
|
|
47
|
+
islandScript.__stx_ran = true;
|
|
48
|
+
var chunkSrc = islandScript.getAttribute && islandScript.getAttribute('data-stx-src');
|
|
49
|
+
if (chunkSrc) {
|
|
50
|
+
// Chunked island (production build): the IIFE lives in a separate
|
|
51
|
+
// file fetched only now. Load it via a real <script src> (CSP-clean \u2014
|
|
52
|
+
// no eval/new Function) and defer ALL downstream work to its load
|
|
53
|
+
// event, since the scope isn't registered until the chunk executes.
|
|
54
|
+
var s = document.createElement('script');
|
|
55
|
+
s.src = chunkSrc;
|
|
56
|
+
// Subresource Integrity (opt-in at build): pin the chunk's bytes.
|
|
57
|
+
var integ = islandScript.getAttribute('data-stx-integrity');
|
|
58
|
+
if (integ) s.integrity = integ;
|
|
59
|
+
s.onload = finishHydrate;
|
|
60
|
+
s.onerror = function() {
|
|
61
|
+
// Network error / 404: the island can't become interactive. Log,
|
|
62
|
+
// emit an observable event (analytics/monitoring can react), then
|
|
63
|
+
// best-effort finish. The server-rendered HTML stays visible
|
|
64
|
+
// (x-cloak was already removed on arming) \u2014 it just won't wire up.
|
|
65
|
+
console.error('[stx] island chunk load failed:', sid, chunkSrc);
|
|
66
|
+
window.dispatchEvent(new CustomEvent('stx:island-error', { detail: { el: el, scopeId: sid, src: chunkSrc } }));
|
|
67
|
+
finishHydrate();
|
|
68
|
+
};
|
|
69
|
+
document.head.appendChild(s);
|
|
70
|
+
return; // finishHydrate runs from the chunk's load event
|
|
71
|
+
}
|
|
72
|
+
// Inline island (dev / SSR / chunking off): execute synchronously.
|
|
73
|
+
// eslint-disable-next-line no-new-func
|
|
74
|
+
try { (new Function(islandScript.textContent))(); }
|
|
75
|
+
catch (e) { console.error('[stx] island setup error:', sid, e); }
|
|
76
|
+
}
|
|
77
|
+
finishHydrate();
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Record how to cancel a still-pending trigger so SPA navigation can tear it
|
|
81
|
+
// down \u2014 otherwise an unhydrated island's observer/timer/listener leaks and
|
|
82
|
+
// may fire run() on a detached element after the page swapped (#1746).
|
|
83
|
+
// Cleared once run() fires (it guards on __stx_hydrated anyway).
|
|
84
|
+
if (trigger === 'idle') {
|
|
85
|
+
if (typeof requestIdleCallback === 'function') {
|
|
86
|
+
var idleId = requestIdleCallback(run, { timeout: 2000 });
|
|
87
|
+
el.__stx_hydration_cancel = function() { if (typeof cancelIdleCallback === 'function') cancelIdleCallback(idleId); };
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
var idleTimer = setTimeout(run, 200);
|
|
91
|
+
el.__stx_hydration_cancel = function() { clearTimeout(idleTimer); };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else if (trigger === 'visible') {
|
|
95
|
+
if (typeof IntersectionObserver === 'function') {
|
|
96
|
+
var io = new IntersectionObserver(function(entries) {
|
|
97
|
+
entries.forEach(function(e) {
|
|
98
|
+
if (e.isIntersecting) { io.disconnect(); run(); }
|
|
99
|
+
});
|
|
100
|
+
}, { rootMargin: '50px' });
|
|
101
|
+
io.observe(el);
|
|
102
|
+
el.__stx_hydration_cancel = function() { io.disconnect(); };
|
|
103
|
+
} else {
|
|
104
|
+
run(); // fallback: no IO support, hydrate immediately
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (trigger === 'interaction') {
|
|
108
|
+
var events = ['mouseenter', 'click', 'focusin', 'touchstart'];
|
|
109
|
+
var handler = function() {
|
|
110
|
+
events.forEach(function(ev) { el.removeEventListener(ev, handler); });
|
|
111
|
+
run();
|
|
112
|
+
};
|
|
113
|
+
events.forEach(function(ev) { el.addEventListener(ev, handler, { once: true, passive: true }); });
|
|
114
|
+
el.__stx_hydration_cancel = function() { events.forEach(function(ev) { el.removeEventListener(ev, handler); }); };
|
|
115
|
+
}
|
|
116
|
+
else if (trigger && trigger.indexOf('media:') === 0) {
|
|
117
|
+
var query = trigger.slice(6);
|
|
118
|
+
var mql = window.matchMedia(query);
|
|
119
|
+
if (mql.matches) run();
|
|
120
|
+
else {
|
|
121
|
+
var mqHandler = function(e) {
|
|
122
|
+
if (e.matches) { mql.removeEventListener('change', mqHandler); run(); }
|
|
123
|
+
};
|
|
124
|
+
mql.addEventListener('change', mqHandler);
|
|
125
|
+
el.__stx_hydration_cancel = function() { mql.removeEventListener('change', mqHandler); };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// Unknown trigger \u2014 hydrate immediately
|
|
130
|
+
run();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Lifecycle queues and scope-aware hook ownership for the client runtime. */
|
|
2
|
+
export declare const SIGNALS_LIFECYCLE_RUNTIME = " // ==========================================================================\n // Lifecycle\n // ==========================================================================\n\n const mountCallbacks = [];\n const destroyCallbacks = [];\n\n function currentLifecycleScope() {\n var el = window.__STX_CURRENT_ELEMENT__;\n if (!el || !el.getAttribute || !window.stx || !window.stx._scopes) return null;\n var scopeId = el.getAttribute('data-stx-scope');\n return scopeId ? window.stx._scopes[scopeId] || null : null;\n }\n\n function onMount(fn) {\n var scope = currentLifecycleScope();\n if (scope) {\n scope.__mountCallbacks = scope.__mountCallbacks || [];\n scope.__mountCallbacks.push(fn);\n // Kept apart from the queue, which a flush drains: a component behind an\n // :if mounts again every time it is shown (see suspendSubtreeScopes).\n scope.__mountHooks = scope.__mountHooks || [];\n scope.__mountHooks.push(fn);\n return;\n }\n mountCallbacks.push(fn);\n }\n\n // Where an onDestroy called from inside a running mount callback belongs:\n // the queue runMountCallbacks is parking cleanups on, which is the mounting\n // component's own. Null outside a flush.\n //\n // Without it such a call, typically a composable like useEventListener\n // invoked in onMount, found no current element and went to the global\n // queue, and every stx:load drains that queue. A component that stays on\n // the page across navigations (one the layout renders) lost the listener at\n // the first navigation while its markup stayed bound (#1958).\n var activeDestroySink = null;\n\n function onDestroy(fn) {\n var scope = currentLifecycleScope();\n if (scope) {\n scope.__destroyCallbacks = scope.__destroyCallbacks || [];\n scope.__destroyCallbacks.push(fn);\n // Registered once, at setup, and owed at every unmount -- including each\n // time an :if hides the component (see suspendSubtreeScopes).\n scope.__destroyHooks = scope.__destroyHooks || [];\n scope.__destroyHooks.push(fn);\n return;\n }\n if (activeDestroySink) {\n activeDestroySink.push(fn);\n return;\n }\n destroyCallbacks.push(fn);\n }\n\n // Run mount callbacks and keep whatever teardown they hand back.\n //\n // A mount callback may return its own cleanup \u2014 the shape LifecycleCallback\n // has always declared, and the shape every peer framework uses. Only the two\n // component-factory paths honoured it; the other flush sites called fn() and\n // dropped the result on the floor, so the teardown never ran and nothing said\n // so. A listener or timer registered that way outlived its element and leaked\n // once per re-render (#1857).\n //\n // The sink argument is where a returned cleanup is parked: a scoped flush\n // passes that scope's __destroyCallbacks, a global flush passes the module\n // queue. (No backticks in this comment \u2014 it lives inside a template literal.)\n function runMountCallbacks(list, sink) {\n if (!list || !list.length) return;\n var target = sink || destroyCallbacks;\n // Drain before running. A mount callback fires once, and leaving the queue\n // in place made that untrue: the DOM-ready handler reaches this with the\n // same shared mountCallbacks array twice \u2014 once inside the per-root\n // hydration loop, then again for the global pass \u2014 and only emptied it\n // after the second call. So every onMount on a page with a data-stx root\n // ran twice, and a page with N roots ran them N+1 times. Every request the\n // hook made was duplicated with it.\n // Taking the batch out first also keeps a callback that registers another\n // onMount honest: the new one queues for the next flush instead of being\n // swallowed by the clear or replayed by the next caller.\n var batch = list.splice(0, list.length);\n // An onDestroy registered while the batch runs joins the same queue as a\n // returned cleanup. Saved and restored, so a mount that mounts something\n // else (stx.mount inside onMount) hands the outer sink back afterwards.\n var previousSink = activeDestroySink;\n activeDestroySink = target;\n try {\n for (var i = 0; i < batch.length; i++) {\n try {\n var cleanup = batch[i]();\n if (typeof cleanup === 'function') target.push(cleanup);\n }\n catch (e) { console.error('[stx] onMount error:', e); }\n }\n }\n finally {\n activeDestroySink = previousSink;\n }\n }\n\n // The scope's own teardown queue, created on demand so a scope that never\n // returns a cleanup does not carry an empty array around.\n function scopeDestroySink(scopeVars) {\n if (!scopeVars) return destroyCallbacks;\n scopeVars.__destroyCallbacks = scopeVars.__destroyCallbacks || [];\n return scopeVars.__destroyCallbacks;\n }\n\n // Drain any early mount/destroy calls captured by the pre-initialization shim\n if (window.__stx_early_mounts) { window.__stx_early_mounts.forEach(function(fn) { mountCallbacks.push(fn); }); window.__stx_early_mounts = null; }\n if (window.__stx_early_destroys) { window.__stx_early_destroys.forEach(function(fn) { destroyCallbacks.push(fn); }); window.__stx_early_destroys = null; }\n";
|