@stacksjs/stx 0.2.303 → 0.2.305
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/api-client.d.ts +26 -0
- package/dist/api-client.js +22 -0
- package/dist/api-handler.d.ts +6 -0
- package/dist/api-handler.js +3 -0
- package/dist/app-shell.js +11 -2
- package/dist/application-layers.d.ts +30 -0
- package/dist/application-layers.js +202 -0
- package/dist/build.js +9 -1
- package/dist/{chunk-rdg1n42s.js → chunk-00rtz7nw.js} +2 -2
- package/dist/chunk-02hm88m5.js +2 -0
- package/dist/chunk-044mychj.js +2 -0
- package/dist/{chunk-7eea1cse.js → chunk-09zjty4k.js} +1 -1
- package/dist/{chunk-7nfn7nj9.js → chunk-0gz0rhvs.js} +1 -1
- package/dist/chunk-113y4ywy.js +2 -0
- package/dist/{chunk-jsfch50r.js → chunk-1c2j4eby.js} +1 -1
- package/dist/{chunk-2m6x8tcx.js → chunk-1jbjrc0w.js} +2 -2
- package/dist/{chunk-m6wz1hf5.js → chunk-2h94c5hm.js} +2 -2
- package/dist/{chunk-mjpqz66q.js → chunk-2ver2s2y.js} +1 -1
- package/dist/chunk-3eervtf9.js +2 -0
- package/dist/{chunk-2rp09y5j.js → chunk-4evbx7sz.js} +1 -1
- package/dist/chunk-4jgr954p.js +2 -0
- package/dist/chunk-4mrhxtn3.js +18 -0
- package/dist/chunk-57ea6ye2.js +2 -0
- package/dist/{chunk-7eg7ep8f.js → chunk-5tefa8qb.js} +2 -2
- package/dist/{chunk-683tfkz4.js → chunk-64djh88a.js} +1 -1
- package/dist/{chunk-btrmvj2y.js → chunk-695fkras.js} +1 -1
- package/dist/{chunk-y7dcdjav.js → chunk-6zt2y7q3.js} +2 -2
- package/dist/chunk-7gqbr8nr.js +2 -0
- package/dist/{chunk-x4prtyjs.js → chunk-7kw3grq5.js} +1 -1
- package/dist/chunk-7m4yhzhb.js +6 -0
- package/dist/{chunk-7jebw3ea.js → chunk-7skk34dh.js} +2 -2
- package/dist/chunk-8ee62a9q.js +2 -0
- package/dist/{chunk-jj6yp7gm.js → chunk-8jam44my.js} +1 -1
- package/dist/chunk-8z0n5mtg.js +2 -0
- package/dist/chunk-92zzryxw.js +2 -0
- package/dist/{chunk-3bc8bqw2.js → chunk-9368t9jm.js} +1 -1
- package/dist/{chunk-3jwmcf4k.js → chunk-9c835qjn.js} +1 -1
- package/dist/chunk-9nf3hgvq.js +7 -0
- package/dist/chunk-a87jqtmd.js +2 -0
- package/dist/{chunk-5d9cy7a0.js → chunk-awj7yy37.js} +1 -1
- package/dist/chunk-b4xwbh8a.js +2 -0
- package/dist/{chunk-1evf3bdg.js → chunk-bd9wrcq1.js} +205 -19
- package/dist/chunk-bezqaxqt.js +2 -0
- package/dist/chunk-bk95q0bw.js +12 -0
- package/dist/{chunk-q25mr70f.js → chunk-c131k3mt.js} +1 -1
- package/dist/chunk-c1ae6afc.js +30 -0
- package/dist/{chunk-6btbgxh1.js → chunk-c79nfdyj.js} +1 -1
- package/dist/{chunk-cfgpk6bh.js → chunk-cbgh359m.js} +1 -1
- package/dist/{chunk-weqpt9nt.js → chunk-cr8v8k53.js} +1 -1
- package/dist/{chunk-p3wwm6k4.js → chunk-d19tvdvv.js} +1 -1
- package/dist/{chunk-nb1zdh1y.js → chunk-d3srvh3q.js} +1 -1
- package/dist/{chunk-rqrfq305.js → chunk-d57gb0v2.js} +1 -1
- package/dist/{chunk-1xyhk1wr.js → chunk-d5cqnwdd.js} +1 -1
- package/dist/chunk-dgpjxmhs.js +2 -0
- package/dist/chunk-dvvx1wny.js +3 -0
- package/dist/chunk-eans1ct0.js +43 -0
- package/dist/{chunk-ctz53mbz.js → chunk-ej8mv2k6.js} +1 -1
- package/dist/{chunk-zn6xcc0a.js → chunk-ek8cgwcg.js} +2 -2
- package/dist/{chunk-dv3z80gt.js → chunk-env6knrs.js} +1 -1
- package/dist/chunk-er848s6f.js +2 -0
- package/dist/{chunk-rf10fkrf.js → chunk-ess2pgt5.js} +1 -1
- package/dist/chunk-f1cgyd2h.js +3 -0
- package/dist/{chunk-hp3rjwnb.js → chunk-f325jzsk.js} +2 -2
- package/dist/{chunk-0tbgvp70.js → chunk-fczfdsab.js} +21 -5
- package/dist/chunk-fg0nf7cv.js +3754 -0
- package/dist/{chunk-xdq52pwj.js → chunk-fp7ms6e7.js} +1 -1
- package/dist/{chunk-qg6pg6ze.js → chunk-fqq5k9ve.js} +1 -1
- package/dist/{chunk-5t0w4h6z.js → chunk-g912mb7x.js} +1 -1
- package/dist/chunk-g97atepq.js +2 -0
- package/dist/{chunk-wj25qt72.js → chunk-gbwhbasw.js} +1 -1
- package/dist/chunk-gecmqs6p.js +17 -0
- package/dist/{chunk-cratkhhb.js → chunk-ghw5p1yk.js} +1 -1
- package/dist/{chunk-f0g2q51j.js → chunk-gssbag3e.js} +1 -1
- package/dist/{chunk-c9vhtjtr.js → chunk-gt8ja700.js} +2 -2
- package/dist/chunk-hftqr8ej.js +2 -0
- package/dist/{chunk-ftvmk1nj.js → chunk-hg2afckn.js} +1 -1
- package/dist/{chunk-hhnzd03k.js → chunk-hrcxfvh1.js} +1 -1
- package/dist/chunk-hzav4hyd.js +2 -0
- package/dist/{chunk-29gjwajm.js → chunk-jfzfrmzy.js} +1 -1
- package/dist/{chunk-ddqkj56r.js → chunk-jp2f8yzw.js} +1 -1
- package/dist/{chunk-ry3a2674.js → chunk-jsg1rthc.js} +1 -1
- package/dist/chunk-jxxv18a0.js +5 -0
- package/dist/{chunk-95t0k8cz.js → chunk-k23r03qj.js} +1 -1
- package/dist/{chunk-6b4k8fay.js → chunk-kxavsh3m.js} +1 -1
- package/dist/{chunk-4tffxxpd.js → chunk-m31n9pkr.js} +1 -1
- package/dist/{chunk-fj6fbqgb.js → chunk-m3a20mmb.js} +1 -1
- package/dist/chunk-m537zgay.js +2 -0
- package/dist/chunk-m8n0s4tk.js +28 -0
- package/dist/{chunk-j21csh4j.js → chunk-mbmqpaq1.js} +1 -1
- package/dist/{chunk-whm6bybj.js → chunk-mv5fdcwc.js} +3 -3
- package/dist/{chunk-y9nyqcha.js → chunk-mwh3ymwc.js} +1 -1
- package/dist/{chunk-51g95yts.js → chunk-mygq61f5.js} +2 -2
- package/dist/chunk-n99ajrwv.js +2 -0
- package/dist/chunk-ncrfrp95.js +2 -0
- package/dist/chunk-nqq7y7m9.js +3 -0
- package/dist/chunk-nws8fbde.js +2 -0
- package/dist/{chunk-q6xfyasj.js → chunk-pcvayb2f.js} +1 -1
- package/dist/chunk-phcvbqzn.js +2 -0
- package/dist/{chunk-nvxv2wxv.js → chunk-ppyz9623.js} +1 -1
- package/dist/{chunk-jb2r696a.js → chunk-qev11kg8.js} +1 -1
- package/dist/{chunk-6njgsr6w.js → chunk-qeyw5za9.js} +1 -1
- package/dist/chunk-qpzxgkc5.js +2 -0
- package/dist/chunk-qt2dmyq5.js +2 -0
- package/dist/chunk-r2k2sewg.js +2 -0
- package/dist/chunk-r808fpme.js +2 -0
- package/dist/chunk-rrankpmj.js +3 -0
- package/dist/chunk-rvyfyc43.js +2 -0
- package/dist/{chunk-3p0zgfgz.js → chunk-rzevgemj.js} +2 -2
- package/dist/{chunk-f62fh1fw.js → chunk-s3dnk3gc.js} +2 -2
- package/dist/{chunk-aa6kt84c.js → chunk-sart9ehj.js} +1 -1
- package/dist/chunk-sen2cxqm.js +2 -0
- package/dist/{chunk-jptkc64r.js → chunk-t3qb9s6s.js} +2 -2
- package/dist/{chunk-w8yac9xp.js → chunk-t41aaehf.js} +1 -1
- package/dist/{chunk-qjkzpd68.js → chunk-t51mwjyq.js} +1 -1
- package/dist/chunk-t8fqjb25.js +19 -0
- package/dist/{chunk-c6b5nqct.js → chunk-ta398s3d.js} +287 -352
- package/dist/chunk-tc6gqeha.js +2 -0
- package/dist/chunk-tt4r8q4v.js +2 -0
- package/dist/chunk-twbw18vs.js +2 -0
- package/dist/{chunk-6rzwef28.js → chunk-vd5xvsnv.js} +1 -1
- package/dist/chunk-w6d91maa.js +4 -0
- package/dist/{chunk-dcxtrqfy.js → chunk-wfffa8zm.js} +1 -1
- package/dist/chunk-wjdfhfj6.js +2 -0
- package/dist/chunk-wnamjw6n.js +3 -0
- package/dist/{chunk-22p0ezj6.js → chunk-wx13qmaw.js} +1 -1
- package/dist/chunk-x10mrzgp.js +2 -0
- package/dist/chunk-xd5ahrtn.js +2 -0
- package/dist/chunk-xsfwcj6x.js +2 -0
- package/dist/{chunk-91007tan.js → chunk-xwxdwqn9.js} +1 -1
- package/dist/{chunk-634gaa9d.js → chunk-xz3evxqp.js} +1 -1
- package/dist/chunk-xzgvcrnz.js +2 -0
- package/dist/{chunk-v8474ah4.js → chunk-y4nzmkea.js} +1 -1
- package/dist/{chunk-6w8fa3b8.js → chunk-ya5m5vbn.js} +1 -1
- package/dist/chunk-yd7jyyr7.js +2 -0
- package/dist/{chunk-ew6tr7b1.js → chunk-ydgdq45a.js} +2 -2
- package/dist/{chunk-ps20v1ah.js → chunk-ym3r8ktq.js} +1 -1
- package/dist/chunk-yyyxt326.js +2 -0
- package/dist/{chunk-yfwyvh02.js → chunk-ze44hhxb.js} +2 -2
- package/dist/{chunk-mdf3jbe6.js → chunk-zhcs8m2a.js} +2 -2
- package/dist/{chunk-f9d27v49.js → chunk-zs5y7xnt.js} +1 -1
- package/dist/chunk-zs95z9tf.js +2 -0
- package/dist/cli.js +14 -14
- package/dist/client-script-bundler.js +22 -11
- package/dist/component-contract-checks.d.ts +19 -0
- package/dist/component-contract-checks.js +147 -0
- package/dist/component-contract.d.ts +20 -0
- package/dist/component-contract.js +108 -0
- package/dist/component-model.d.ts +29 -0
- package/dist/component-model.js +59 -0
- package/dist/component-registry.js +7 -64
- package/dist/component-renderer.d.ts +1 -26
- package/dist/component-renderer.js +4 -239
- package/dist/component-resolution.d.ts +21 -0
- package/dist/component-resolution.js +118 -0
- package/dist/component-tags.d.ts +9 -0
- package/dist/component-tags.js +174 -0
- package/dist/composable-loader.d.ts +2 -13
- package/dist/composable-loader.js +15 -26
- package/dist/composables/index.d.ts +1 -0
- package/dist/composables/index.js +1 -0
- package/dist/composables/use-fetch.d.ts +117 -42
- package/dist/composables/use-fetch.js +47 -4
- package/dist/composition-api.d.ts +43 -19
- package/dist/config.d.ts +1 -1
- package/dist/config.js +46 -4
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/database.js +1 -1
- package/dist/dev-server/serve-app.js +57 -17
- package/dist/dev-server/serve-file.js +8 -1
- package/dist/expressions.js +1 -1
- package/dist/imported-signals.js +1 -1
- package/dist/includes.js +27 -3
- package/dist/index.d.ts +11 -0
- package/dist/index.js +7 -0
- package/dist/manifest.d.ts +6 -0
- package/dist/misc-directives.d.ts +2 -0
- package/dist/misc-directives.js +39 -1
- package/dist/process.js +18 -1
- package/dist/production-builder.d.ts +4 -0
- package/dist/production-builder.js +47 -8
- package/dist/production-server.d.ts +4 -1
- package/dist/production-server.js +119 -71
- package/dist/pwa.js +2 -2
- package/dist/render.js +9 -2
- package/dist/route-response-cache.d.ts +7 -0
- package/dist/route-response-cache.js +72 -0
- package/dist/route-rules.d.ts +17 -0
- package/dist/route-rules.js +40 -0
- package/dist/router.d.ts +1 -0
- package/dist/runtime-config-loader.d.ts +5 -0
- package/dist/runtime-config-loader.js +42 -0
- package/dist/runtime-config-server.d.ts +26 -0
- package/dist/runtime-config-server.js +77 -0
- package/dist/runtime-config-types.d.ts +2 -0
- package/dist/runtime-config-types.js +0 -0
- package/dist/runtime-config.d.ts +5 -0
- package/dist/runtime-config.js +9 -0
- package/dist/runtime-globals.js +3 -0
- package/dist/serve.js +32 -10
- package/dist/server-api.d.ts +27 -0
- package/dist/server-api.js +181 -0
- package/dist/server-data.d.ts +17 -0
- package/dist/server-data.js +40 -0
- package/dist/signal-processing.js +2 -2
- package/dist/signals.js +138 -15
- package/dist/ssg.js +2 -2
- package/dist/stx-virtual-ts.d.ts +6 -0
- package/dist/stx-virtual-ts.js +31 -7
- package/dist/stx.d.ts +28 -0
- package/dist/template-compiler.d.ts +1 -0
- package/dist/template-compiler.js +1 -1
- package/dist/template-hydrator.js +15 -4
- package/dist/typecheck.d.ts +1 -0
- package/dist/typecheck.js +4 -3
- package/dist/types/config-types.d.ts +17 -0
- package/dist/utils.js +15 -5
- package/dist/variable-extractor.d.ts +1 -1
- package/dist/variable-extractor.js +12 -1
- package/dist/visual-testing.js +1 -1
- package/dist/vue-template.js +19 -41
- package/package.json +5 -5
- package/stx.d.ts +28 -0
- package/dist/chunk-0p44z42s.js +0 -2
- package/dist/chunk-2jd9bxmf.js +0 -2
- package/dist/chunk-2yp8ang5.js +0 -2
- package/dist/chunk-35x7s4cr.js +0 -2
- package/dist/chunk-3bqz5zre.js +0 -2
- package/dist/chunk-48p0k8y7.js +0 -2
- package/dist/chunk-4b625drg.js +0 -2
- package/dist/chunk-593kby1d.js +0 -2
- package/dist/chunk-5nac67r4.js +0 -18
- package/dist/chunk-70cf5h11.js +0 -2
- package/dist/chunk-78akhaws.js +0 -2
- package/dist/chunk-9a4q74r6.js +0 -2
- package/dist/chunk-9f5329rv.js +0 -2
- package/dist/chunk-9rv7akqq.js +0 -30
- package/dist/chunk-apjy1a72.js +0 -12
- package/dist/chunk-b3p3bzax.js +0 -3
- package/dist/chunk-c5hk1fxt.js +0 -2
- package/dist/chunk-c9rs5g1s.js +0 -2
- package/dist/chunk-dkd0bg8g.js +0 -2
- package/dist/chunk-dxhtry04.js +0 -2
- package/dist/chunk-ehp6fez3.js +0 -2
- package/dist/chunk-em3jb1dn.js +0 -4
- package/dist/chunk-ev4djb0p.js +0 -2
- package/dist/chunk-frejnjh9.js +0 -2
- package/dist/chunk-fvcr26a0.js +0 -22
- package/dist/chunk-g6ttsdz1.js +0 -2
- package/dist/chunk-gd73rpks.js +0 -2
- package/dist/chunk-ggwnrdqz.js +0 -17
- package/dist/chunk-h3t6fjba.js +0 -2
- package/dist/chunk-jc57j887.js +0 -2
- package/dist/chunk-jw248h1d.js +0 -2
- package/dist/chunk-k5xtf38q.js +0 -3
- package/dist/chunk-m78y5qys.js +0 -19
- package/dist/chunk-mc4rtf5d.js +0 -2
- package/dist/chunk-mx2wcb15.js +0 -2
- package/dist/chunk-p4w3wjbv.js +0 -2
- package/dist/chunk-pm3k8dyk.js +0 -2
- package/dist/chunk-qr59yfq9.js +0 -2
- package/dist/chunk-qsmdvy1z.js +0 -2
- package/dist/chunk-rsxmjfxq.js +0 -3754
- package/dist/chunk-s4sp78fn.js +0 -2
- package/dist/chunk-v2fp9vkh.js +0 -2
- package/dist/chunk-vwnnbzsp.js +0 -2
- package/dist/chunk-w0g99tx9.js +0 -2
- package/dist/chunk-x2pk87q2.js +0 -3
- package/dist/chunk-xn0asg46.js +0 -2
- package/dist/chunk-xwmw1wtk.js +0 -2
- package/dist/chunk-zdx9s3z0.js +0 -28
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const pkgStxIndexCache = new Map;
|
|
4
|
+
export function buildStxIndex(pkgDir, cache = !0) {
|
|
5
|
+
const cached = pkgStxIndexCache.get(pkgDir);
|
|
6
|
+
if (cache && cached)
|
|
7
|
+
return cached;
|
|
8
|
+
const index = new Map, roots = [path.join(pkgDir, "src"), path.join(pkgDir, "dist"), pkgDir];
|
|
9
|
+
function walk(dir, depth) {
|
|
10
|
+
if (depth > 6)
|
|
11
|
+
return;
|
|
12
|
+
let entries;
|
|
13
|
+
try {
|
|
14
|
+
entries = fs.readdirSync(dir, { withFileTypes: !0 });
|
|
15
|
+
} catch {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
const full = path.join(dir, entry.name);
|
|
20
|
+
if (entry.isDirectory()) {
|
|
21
|
+
if (entry.name === "node_modules" || entry.name.startsWith("."))
|
|
22
|
+
continue;
|
|
23
|
+
walk(full, depth + 1);
|
|
24
|
+
} else if (entry.isFile() && entry.name.endsWith(".stx")) {
|
|
25
|
+
const base = entry.name.slice(0, -4);
|
|
26
|
+
if (!index.has(base))
|
|
27
|
+
index.set(base, full);
|
|
28
|
+
const lower = base.toLowerCase();
|
|
29
|
+
if (!index.has(lower))
|
|
30
|
+
index.set(lower, full);
|
|
31
|
+
const kebab = base.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
32
|
+
if (!index.has(kebab))
|
|
33
|
+
index.set(kebab, full);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const root of roots) {
|
|
38
|
+
walk(root, 0);
|
|
39
|
+
if (index.size > 0)
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
if (cache)
|
|
43
|
+
pkgStxIndexCache.set(pkgDir, index);
|
|
44
|
+
return index;
|
|
45
|
+
}
|
|
46
|
+
export function resolvePackageDir(spec, fromDir) {
|
|
47
|
+
if (spec.startsWith(".") || spec.startsWith("/"))
|
|
48
|
+
return null;
|
|
49
|
+
let dir = fromDir;
|
|
50
|
+
while (!0) {
|
|
51
|
+
const candidate = path.join(dir, "node_modules", spec);
|
|
52
|
+
try {
|
|
53
|
+
if (fs.statSync(candidate).isDirectory())
|
|
54
|
+
return candidate;
|
|
55
|
+
} catch {}
|
|
56
|
+
const parent = path.dirname(dir);
|
|
57
|
+
if (parent === dir)
|
|
58
|
+
return null;
|
|
59
|
+
dir = parent;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function componentImportCandidates(componentPath, filePath, options = {}) {
|
|
63
|
+
return [
|
|
64
|
+
path.resolve(path.dirname(filePath), `${componentPath}.stx`),
|
|
65
|
+
path.resolve(path.dirname(filePath), componentPath),
|
|
66
|
+
path.resolve(options.componentsDir || "components", `${componentPath}.stx`),
|
|
67
|
+
path.resolve(options.componentsDir || "components", componentPath),
|
|
68
|
+
componentPath.endsWith(".stx") ? componentPath : `${componentPath}.stx`
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
function variants(name) {
|
|
72
|
+
const base = name.endsWith(".stx") ? name.slice(0, -4) : name, pascal = base.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(""), kebab = base.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
73
|
+
return [base, pascal, kebab];
|
|
74
|
+
}
|
|
75
|
+
export function importedComponentPath(name, context) {
|
|
76
|
+
const [base, pascal, kebab] = variants(name);
|
|
77
|
+
for (const candidate of [base, base.toLowerCase(), pascal, kebab]) {
|
|
78
|
+
const imported = context?.__importedComponents?.get(candidate);
|
|
79
|
+
if (imported !== void 0)
|
|
80
|
+
return imported;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function* componentFileCandidates(name, fromFile, options = {}, context) {
|
|
84
|
+
const names = variants(name);
|
|
85
|
+
if (names[0].startsWith("./") || names[0].startsWith("../")) {
|
|
86
|
+
yield path.resolve(path.dirname(fromFile), `${names[0]}.stx`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const files = [...new Set(names.map((base) => `${base}.stx`))], projectRoot = options.projectRoot || process.cwd(), directories = [
|
|
90
|
+
...context?.__originalFilePath ? [path.join(path.dirname(context.__originalFilePath), "components")] : [],
|
|
91
|
+
...options.componentsDir ? [options.componentsDir] : [],
|
|
92
|
+
path.join(path.dirname(fromFile), "components"),
|
|
93
|
+
path.resolve(projectRoot, "src/components"),
|
|
94
|
+
path.resolve(projectRoot, "components"),
|
|
95
|
+
...import.meta.dir ? [path.resolve(import.meta.dir, "components")] : []
|
|
96
|
+
];
|
|
97
|
+
for (const directory of new Set(directories)) {
|
|
98
|
+
for (const file of files)
|
|
99
|
+
yield path.join(directory, file);
|
|
100
|
+
try {
|
|
101
|
+
for (const entry of fs.readdirSync(directory, { withFileTypes: !0 }))
|
|
102
|
+
if (entry.isDirectory())
|
|
103
|
+
for (const file of files)
|
|
104
|
+
yield path.join(directory, entry.name, file);
|
|
105
|
+
} catch {}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export function resolveComponentFileSync(name, fromFile, options = {}, context) {
|
|
109
|
+
const imported = importedComponentPath(name, context);
|
|
110
|
+
if (imported !== void 0)
|
|
111
|
+
return imported;
|
|
112
|
+
for (const candidate of componentFileCandidates(name, fromFile, options, context))
|
|
113
|
+
try {
|
|
114
|
+
if (fs.statSync(candidate, { throwIfNoEntry: !1 })?.isFile())
|
|
115
|
+
return candidate;
|
|
116
|
+
} catch {}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const htmlTags: Set<string>;
|
|
2
|
+
/**
|
|
3
|
+
* Whether `tagName` certainly reaches the page as the element it names, by the
|
|
4
|
+
* three passes of `processComponents` below. A component tag is replaced by
|
|
5
|
+
* the component's markup, and attributes stamped on the tag do not survive it.
|
|
6
|
+
* A kebab-case tag is a component when a file of that name exists, which this
|
|
7
|
+
* cannot know, so it never counts as certain.
|
|
8
|
+
*/
|
|
9
|
+
export declare function rendersAsElement(tagName: string): boolean;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
export const htmlTags = new Set([
|
|
2
|
+
"a",
|
|
3
|
+
"abbr",
|
|
4
|
+
"address",
|
|
5
|
+
"area",
|
|
6
|
+
"article",
|
|
7
|
+
"aside",
|
|
8
|
+
"audio",
|
|
9
|
+
"b",
|
|
10
|
+
"base",
|
|
11
|
+
"bdi",
|
|
12
|
+
"bdo",
|
|
13
|
+
"blockquote",
|
|
14
|
+
"body",
|
|
15
|
+
"br",
|
|
16
|
+
"button",
|
|
17
|
+
"canvas",
|
|
18
|
+
"caption",
|
|
19
|
+
"cite",
|
|
20
|
+
"code",
|
|
21
|
+
"col",
|
|
22
|
+
"colgroup",
|
|
23
|
+
"component",
|
|
24
|
+
"data",
|
|
25
|
+
"datalist",
|
|
26
|
+
"dd",
|
|
27
|
+
"del",
|
|
28
|
+
"details",
|
|
29
|
+
"dfn",
|
|
30
|
+
"dialog",
|
|
31
|
+
"div",
|
|
32
|
+
"dl",
|
|
33
|
+
"dt",
|
|
34
|
+
"em",
|
|
35
|
+
"embed",
|
|
36
|
+
"fieldset",
|
|
37
|
+
"figcaption",
|
|
38
|
+
"figure",
|
|
39
|
+
"footer",
|
|
40
|
+
"form",
|
|
41
|
+
"h1",
|
|
42
|
+
"h2",
|
|
43
|
+
"h3",
|
|
44
|
+
"h4",
|
|
45
|
+
"h5",
|
|
46
|
+
"h6",
|
|
47
|
+
"head",
|
|
48
|
+
"header",
|
|
49
|
+
"hgroup",
|
|
50
|
+
"hr",
|
|
51
|
+
"html",
|
|
52
|
+
"i",
|
|
53
|
+
"iframe",
|
|
54
|
+
"img",
|
|
55
|
+
"input",
|
|
56
|
+
"ins",
|
|
57
|
+
"kbd",
|
|
58
|
+
"label",
|
|
59
|
+
"legend",
|
|
60
|
+
"li",
|
|
61
|
+
"link",
|
|
62
|
+
"main",
|
|
63
|
+
"map",
|
|
64
|
+
"mark",
|
|
65
|
+
"menu",
|
|
66
|
+
"meta",
|
|
67
|
+
"meter",
|
|
68
|
+
"nav",
|
|
69
|
+
"noscript",
|
|
70
|
+
"object",
|
|
71
|
+
"ol",
|
|
72
|
+
"optgroup",
|
|
73
|
+
"option",
|
|
74
|
+
"output",
|
|
75
|
+
"p",
|
|
76
|
+
"param",
|
|
77
|
+
"picture",
|
|
78
|
+
"pre",
|
|
79
|
+
"progress",
|
|
80
|
+
"q",
|
|
81
|
+
"rp",
|
|
82
|
+
"rt",
|
|
83
|
+
"ruby",
|
|
84
|
+
"s",
|
|
85
|
+
"samp",
|
|
86
|
+
"script",
|
|
87
|
+
"section",
|
|
88
|
+
"select",
|
|
89
|
+
"slot",
|
|
90
|
+
"small",
|
|
91
|
+
"source",
|
|
92
|
+
"span",
|
|
93
|
+
"strong",
|
|
94
|
+
"style",
|
|
95
|
+
"sub",
|
|
96
|
+
"summary",
|
|
97
|
+
"sup",
|
|
98
|
+
"svg",
|
|
99
|
+
"table",
|
|
100
|
+
"tbody",
|
|
101
|
+
"td",
|
|
102
|
+
"template",
|
|
103
|
+
"textarea",
|
|
104
|
+
"tfoot",
|
|
105
|
+
"th",
|
|
106
|
+
"thead",
|
|
107
|
+
"time",
|
|
108
|
+
"title",
|
|
109
|
+
"tr",
|
|
110
|
+
"track",
|
|
111
|
+
"u",
|
|
112
|
+
"ul",
|
|
113
|
+
"var",
|
|
114
|
+
"video",
|
|
115
|
+
"wbr",
|
|
116
|
+
"path",
|
|
117
|
+
"circle",
|
|
118
|
+
"rect",
|
|
119
|
+
"line",
|
|
120
|
+
"polygon",
|
|
121
|
+
"polyline",
|
|
122
|
+
"ellipse",
|
|
123
|
+
"text",
|
|
124
|
+
"tspan",
|
|
125
|
+
"textPath",
|
|
126
|
+
"g",
|
|
127
|
+
"defs",
|
|
128
|
+
"use",
|
|
129
|
+
"symbol",
|
|
130
|
+
"image",
|
|
131
|
+
"clipPath",
|
|
132
|
+
"mask",
|
|
133
|
+
"pattern",
|
|
134
|
+
"marker",
|
|
135
|
+
"linearGradient",
|
|
136
|
+
"radialGradient",
|
|
137
|
+
"stop",
|
|
138
|
+
"filter",
|
|
139
|
+
"feBlend",
|
|
140
|
+
"feColorMatrix",
|
|
141
|
+
"feComponentTransfer",
|
|
142
|
+
"feComposite",
|
|
143
|
+
"feConvolveMatrix",
|
|
144
|
+
"feDiffuseLighting",
|
|
145
|
+
"feDisplacementMap",
|
|
146
|
+
"feDropShadow",
|
|
147
|
+
"feFlood",
|
|
148
|
+
"feGaussianBlur",
|
|
149
|
+
"feImage",
|
|
150
|
+
"feMerge",
|
|
151
|
+
"feMergeNode",
|
|
152
|
+
"feMorphology",
|
|
153
|
+
"feOffset",
|
|
154
|
+
"feSpecularLighting",
|
|
155
|
+
"feTile",
|
|
156
|
+
"feTurbulence",
|
|
157
|
+
"foreignObject",
|
|
158
|
+
"animate",
|
|
159
|
+
"animateMotion",
|
|
160
|
+
"animateTransform",
|
|
161
|
+
"set",
|
|
162
|
+
"mpath",
|
|
163
|
+
"desc",
|
|
164
|
+
"metadata",
|
|
165
|
+
"switch",
|
|
166
|
+
"view"
|
|
167
|
+
]);
|
|
168
|
+
export function rendersAsElement(tagName) {
|
|
169
|
+
if (tagName.includes("-") || tagName === "component")
|
|
170
|
+
return !1;
|
|
171
|
+
if (/^[A-Z]/.test(tagName))
|
|
172
|
+
return !/[a-z]/.test(tagName) && [...htmlTags].some((tag) => tag.toLowerCase() === tagName.toLowerCase());
|
|
173
|
+
return htmlTags.has(tagName) || /[A-Z]/.test(tagName);
|
|
174
|
+
}
|
|
@@ -29,24 +29,13 @@ export interface ComposableModule {
|
|
|
29
29
|
/** Exported binding names, excluding `default`. */
|
|
30
30
|
names: string[];
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
* Every composable file in the resolved directory, with its exported names.
|
|
34
|
-
*
|
|
35
|
-
* Shared by the two consumers that need the names without the bundle: the
|
|
36
|
-
* typechecker, which has to declare them or an app's own composables read as
|
|
37
|
-
* undefined (#1934), and the per-page pruning that decides which of them a page
|
|
38
|
-
* actually references (#1936).
|
|
39
|
-
*
|
|
40
|
-
* Returns an empty array when there is no composables directory, which is the
|
|
41
|
-
* common case and not an error.
|
|
42
|
-
*/
|
|
43
|
-
export declare function listComposableModules(composablesDir?: string): Promise<ComposableModule[]>;
|
|
32
|
+
export declare function listComposableModules(composablesDir?: string | string[]): Promise<ComposableModule[]>;
|
|
44
33
|
/**
|
|
45
34
|
* @param pageSource - the rendered page, used to drop composables it cannot
|
|
46
35
|
* reach. Omit to emit every composable, which is what a caller with no page in
|
|
47
36
|
* hand needs.
|
|
48
37
|
*/
|
|
49
|
-
export declare function getComposableScript(composablesDir?: string, pageSource?: string,
|
|
38
|
+
export declare function getComposableScript(composablesDir?: string | string[], pageSource?: string,
|
|
50
39
|
/**
|
|
51
40
|
* Text that is not (yet) part of `pageSource` but will ship with the page --
|
|
52
41
|
* the store bundle and the framework-composable bundle, which are collected
|
|
@@ -37,21 +37,22 @@ async function probeDefaultDirs() {
|
|
|
37
37
|
}
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
return [];
|
|
44
|
-
const files = [];
|
|
45
|
-
try {
|
|
40
|
+
async function composableSources(input) {
|
|
41
|
+
const dirs = Array.isArray(input) ? input : input ? [path.resolve(input)] : (await loadStxConfig())._layerComposableDirs ?? [await resolveComposablesDir()].filter((dir) => !!dir), selected = new Map;
|
|
42
|
+
for (const dir of dirs) {
|
|
46
43
|
const glob = new Bun.Glob("**/*.ts");
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
try {
|
|
45
|
+
for await (const file of glob.scan({ cwd: dir, absolute: !0 })) {
|
|
46
|
+
const relative = path.relative(dir, file);
|
|
47
|
+
if (!isSkippedFile(file) && !selected.has(relative))
|
|
48
|
+
selected.set(relative, file);
|
|
49
|
+
}
|
|
50
|
+
} catch {}
|
|
52
51
|
}
|
|
53
|
-
files.sort();
|
|
54
|
-
|
|
52
|
+
return { key: dirs.join("\x00"), files: [...selected.values()].sort() };
|
|
53
|
+
}
|
|
54
|
+
export async function listComposableModules(composablesDir) {
|
|
55
|
+
const { files } = await composableSources(composablesDir), transpiler = getSharedTranspiler({ loader: "ts", target: "browser", define: getPublicEnvDefine() }), modules = [];
|
|
55
56
|
for (const file of files)
|
|
56
57
|
try {
|
|
57
58
|
const code = await Bun.file(file).text(), names = transpiler.scan(code).exports.filter((name) => name !== "default");
|
|
@@ -92,21 +93,9 @@ function selectReachable(modules, codeByFile, pageSources) {
|
|
|
92
93
|
return selected;
|
|
93
94
|
}
|
|
94
95
|
export async function getComposableScript(composablesDir, pageSource, extraSources) {
|
|
95
|
-
const resolvedDir = await
|
|
96
|
+
const { key: resolvedDir, files: composableFiles } = await composableSources(composablesDir);
|
|
96
97
|
if (!resolvedDir)
|
|
97
98
|
return null;
|
|
98
|
-
const composableFiles = [];
|
|
99
|
-
try {
|
|
100
|
-
const glob = new Bun.Glob("**/*.ts");
|
|
101
|
-
for await (const file of glob.scan({ cwd: resolvedDir, absolute: !0 })) {
|
|
102
|
-
if (isSkippedFile(file))
|
|
103
|
-
continue;
|
|
104
|
-
composableFiles.push(file);
|
|
105
|
-
}
|
|
106
|
-
} catch {
|
|
107
|
-
writeSigned(_cachedComposableScripts, resolvedDir, "", "");
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
99
|
const signature = sourceSignature(composableFiles);
|
|
111
100
|
if (composableFiles.length === 0) {
|
|
112
101
|
writeSigned(_cachedComposableScripts, resolvedDir, signature, "");
|
|
@@ -1,5 +1,111 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* useFetch — reactive data fetching (module-import path).
|
|
3
|
+
*
|
|
4
|
+
* stx ships two `useFetch` implementations:
|
|
5
|
+
*
|
|
6
|
+
* 1. This one (signals-api / module-import path) — used by tests,
|
|
7
|
+
* SSR-side tooling, and any code that imports from `'stx'` or
|
|
8
|
+
* `'@stacksjs/stx/composables'` directly.
|
|
9
|
+
* 2. The runtime template literal inside `packages/stx/src/signals.ts`
|
|
10
|
+
* (search for `function useFetch`), injected into client pages and
|
|
11
|
+
* exposed at `window.stx.useFetch`.
|
|
12
|
+
*
|
|
13
|
+
* Pre-stacksjs/stx#1726 these returned different shapes (composable used
|
|
14
|
+
* a Vue-style `{ get, subscribe, refresh, execute, abort }` ref;
|
|
15
|
+
* runtime returned Signal-shaped `{ data, loading, error, refetch }`).
|
|
16
|
+
* That meant the same code crashed on one path or the other depending
|
|
17
|
+
* on which entry point the bundler resolved. Now both return the
|
|
18
|
+
* Signal shape — `data`, `loading`, `error` are signals; `refetch` is
|
|
19
|
+
* a function. The composable additionally exposes `abort`, `status`,
|
|
20
|
+
* `statusText` and accepts the richer options set (retry, cache,
|
|
21
|
+
* refetchOnFocus, etc.) — these are supersets the runtime doesn't
|
|
22
|
+
* implement, available to module-import consumers only.
|
|
23
|
+
*
|
|
24
|
+
* Parity tests in `test/composables/use-fetch-parity.test.ts` pin the
|
|
25
|
+
* shared shape across both impls; do not change one side without the
|
|
26
|
+
* other.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const { data, loading, error, refetch } = useFetch('/api/users')
|
|
31
|
+
* // data() — current value (null while loading)
|
|
32
|
+
* // loading() — boolean signal
|
|
33
|
+
* // error() — Error | null signal
|
|
34
|
+
* // refetch() — trigger a new request
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
2
37
|
import type { Signal } from '../signals-api';
|
|
38
|
+
/** @internal Closure-free: also embedded in the generated browser runtime. */
|
|
39
|
+
export declare function readHydratedData(key?: string, hydrate?: boolean, transform?: (data: any) => unknown): {
|
|
40
|
+
data: unknown;
|
|
41
|
+
error?: Error;
|
|
42
|
+
} | undefined;
|
|
43
|
+
/** Forget a hydration snapshot; existing signals change only on explicit refresh. */
|
|
44
|
+
export declare function clearServerData(key?: string): void;
|
|
45
|
+
export interface FetchOptions<T = unknown> extends Omit<RequestInit, 'body'> {
|
|
46
|
+
/** Request body (will be JSON stringified if object) */
|
|
47
|
+
body?: BodyInit | Record<string, unknown> | null;
|
|
48
|
+
/** Base URL to prepend */
|
|
49
|
+
baseURL?: string;
|
|
50
|
+
/** Query parameters */
|
|
51
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
52
|
+
/** Fetch immediately on creation (default: true) */
|
|
53
|
+
immediate?: boolean;
|
|
54
|
+
/** Transform response data */
|
|
55
|
+
transform?: (data: unknown) => T;
|
|
56
|
+
/** Custom response parser (default: json) */
|
|
57
|
+
parseResponse?: (response: Response) => Promise<unknown>;
|
|
58
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
59
|
+
timeout?: number;
|
|
60
|
+
/** Retry count on failure (default: 0) */
|
|
61
|
+
retry?: number;
|
|
62
|
+
/** Retry delay in milliseconds (default: 1000) */
|
|
63
|
+
retryDelay?: number;
|
|
64
|
+
/** Cache key for deduplication */
|
|
65
|
+
key?: string;
|
|
66
|
+
/** Reuse matching useServerData data for the initial load (default: true). */
|
|
67
|
+
hydrate?: boolean;
|
|
68
|
+
/** Cache time in milliseconds (0 = no cache) */
|
|
69
|
+
cacheTime?: number;
|
|
70
|
+
/** Refetch on document visibility change (default: false) */
|
|
71
|
+
refetchOnFocus?: boolean;
|
|
72
|
+
/** Refetch interval in milliseconds */
|
|
73
|
+
refetchInterval?: number;
|
|
74
|
+
/** Initial value while loading (matches runtime's `initialData`) */
|
|
75
|
+
initialData?: T | null;
|
|
76
|
+
}
|
|
77
|
+
/** How one run of the request should behave. */
|
|
78
|
+
export interface RefetchOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Refresh without touching `loading` or clearing the current error.
|
|
81
|
+
*
|
|
82
|
+
* A poll refreshes data that is already on screen, so driving the first-load
|
|
83
|
+
* state from it puts a spinner over a populated view on every tick. Bind
|
|
84
|
+
* `isFetching` for a subtle in-flight indicator instead (stacksjs/stx#1929).
|
|
85
|
+
*/
|
|
86
|
+
background?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/** Signal-shaped fetch result. Matches the runtime's `useFetch` return. */
|
|
89
|
+
export interface FetchRef<T> {
|
|
90
|
+
/** Current data, or `initialData`/null while loading. */
|
|
91
|
+
data: Signal<T | null>;
|
|
92
|
+
/** True while a first-load request is in flight. A background one leaves it alone. */
|
|
93
|
+
loading: Signal<boolean>;
|
|
94
|
+
/** True while ANY request is in flight, background ones included. */
|
|
95
|
+
isFetching: Signal<boolean>;
|
|
96
|
+
/** The most recent error, or null. */
|
|
97
|
+
error: Signal<Error | null>;
|
|
98
|
+
/** HTTP status code of the most recent response, or null. */
|
|
99
|
+
status: Signal<number | null>;
|
|
100
|
+
/** HTTP status text of the most recent response, or null. */
|
|
101
|
+
statusText: Signal<string | null>;
|
|
102
|
+
/** Trigger a new request. */
|
|
103
|
+
refetch: (_options?: RefetchOptions) => Promise<void>;
|
|
104
|
+
/** Same as refetch — kept for runtime-parity callers. */
|
|
105
|
+
execute: () => Promise<void>;
|
|
106
|
+
/** Abort the in-flight request. */
|
|
107
|
+
abort: () => void;
|
|
108
|
+
}
|
|
3
109
|
/**
|
|
4
110
|
* Reactive fetch with loading/error states. Returns Signal-shaped state.
|
|
5
111
|
*/
|
|
@@ -8,52 +114,21 @@ export declare function useFetch<T = unknown>(url: string | (() => string), opti
|
|
|
8
114
|
* Generic async data fetcher. Same Signal shape as `useFetch`.
|
|
9
115
|
*/
|
|
10
116
|
export declare function useAsyncData<T>(fetcher: () => Promise<T>, options?: {
|
|
11
|
-
immediate?: boolean
|
|
12
|
-
transform?: (data: T) => T
|
|
13
|
-
initialData?: T | null
|
|
14
|
-
key?: string
|
|
15
|
-
|
|
16
|
-
|
|
117
|
+
immediate?: boolean;
|
|
118
|
+
transform?: (data: T) => T;
|
|
119
|
+
initialData?: T | null;
|
|
120
|
+
key?: string;
|
|
121
|
+
hydrate?: boolean;
|
|
122
|
+
cacheTime?: number;
|
|
123
|
+
}): FetchRef<T>;
|
|
17
124
|
/**
|
|
18
125
|
* POST request helper. Returns the fetch state plus an execute(body) helper.
|
|
19
126
|
*/
|
|
20
127
|
export declare function usePost<T = unknown, B = unknown>(url: string, options?: Omit<FetchOptions<T>, 'method' | 'body'>): {
|
|
21
|
-
execute: (body?: B) => Promise<T | null
|
|
22
|
-
state: FetchRef<T
|
|
23
|
-
|
|
128
|
+
execute: (body?: B) => Promise<T | null>;
|
|
129
|
+
state: FetchRef<T>;
|
|
130
|
+
};
|
|
24
131
|
/** Clear fetch cache (one key or all). */
|
|
25
132
|
export declare function clearFetchCache(key?: string): void;
|
|
26
133
|
/** Prefetch data into cache. */
|
|
27
134
|
export declare function prefetch<T>(url: string, options?: FetchOptions<T>): Promise<void>;
|
|
28
|
-
export declare interface FetchOptions<T = unknown> extends Omit<RequestInit, 'body'> {
|
|
29
|
-
body?: BodyInit | Record<string, unknown> | null
|
|
30
|
-
baseURL?: string
|
|
31
|
-
query?: Record<string, string | number | boolean | undefined>
|
|
32
|
-
immediate?: boolean
|
|
33
|
-
transform?: (data: unknown) => T
|
|
34
|
-
parseResponse?: (response: Response) => Promise<unknown>
|
|
35
|
-
timeout?: number
|
|
36
|
-
retry?: number
|
|
37
|
-
retryDelay?: number
|
|
38
|
-
key?: string
|
|
39
|
-
cacheTime?: number
|
|
40
|
-
refetchOnFocus?: boolean
|
|
41
|
-
refetchInterval?: number
|
|
42
|
-
initialData?: T | null
|
|
43
|
-
}
|
|
44
|
-
/** How one run of the request should behave. */
|
|
45
|
-
export declare interface RefetchOptions {
|
|
46
|
-
background?: boolean
|
|
47
|
-
}
|
|
48
|
-
/** Signal-shaped fetch result. Matches the runtime's `useFetch` return. */
|
|
49
|
-
export declare interface FetchRef<T> {
|
|
50
|
-
data: Signal<T | null>
|
|
51
|
-
loading: Signal<boolean>
|
|
52
|
-
isFetching: Signal<boolean>
|
|
53
|
-
error: Signal<Error | null>
|
|
54
|
-
status: Signal<number | null>
|
|
55
|
-
statusText: Signal<string | null>
|
|
56
|
-
refetch: (_options?: RefetchOptions) => Promise<void>
|
|
57
|
-
execute: () => Promise<void>
|
|
58
|
-
abort: () => void
|
|
59
|
-
}
|
|
@@ -1,4 +1,44 @@
|
|
|
1
1
|
import { state } from "../signals-api.js";
|
|
2
|
+
export function readHydratedData(key, hydrate = !0, transform) {
|
|
3
|
+
if (!hydrate || !key || typeof window > "u")
|
|
4
|
+
return;
|
|
5
|
+
const host = window;
|
|
6
|
+
if (!host.__STX_DATA__) {
|
|
7
|
+
const tag = document.querySelector("script[data-stx-server-data]");
|
|
8
|
+
try {
|
|
9
|
+
const parsed = JSON.parse(tag?.textContent || "{}");
|
|
10
|
+
host.__STX_DATA__ = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
11
|
+
} catch {
|
|
12
|
+
host.__STX_DATA__ = {};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const values = host.__STX_DATA__;
|
|
16
|
+
if (values && Object.prototype.hasOwnProperty.call(values, key))
|
|
17
|
+
try {
|
|
18
|
+
return { data: transform ? transform(values[key]) : values[key] };
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return { data: null, error: error instanceof Error ? error : Error(String(error)) };
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
export function clearServerData(key) {
|
|
25
|
+
if (typeof window > "u")
|
|
26
|
+
return;
|
|
27
|
+
const host = window;
|
|
28
|
+
if (key === void 0)
|
|
29
|
+
host.__STX_DATA__ = {};
|
|
30
|
+
else {
|
|
31
|
+
if (!host.__STX_DATA__)
|
|
32
|
+
try {
|
|
33
|
+
const parsed = JSON.parse(document.querySelector("script[data-stx-server-data]")?.textContent || "{}");
|
|
34
|
+
host.__STX_DATA__ = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
35
|
+
} catch {
|
|
36
|
+
host.__STX_DATA__ = {};
|
|
37
|
+
}
|
|
38
|
+
if (host.__STX_DATA__)
|
|
39
|
+
delete host.__STX_DATA__[key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
2
42
|
const fetchCache = new Map;
|
|
3
43
|
function buildURL(url, baseURL, query) {
|
|
4
44
|
let fullURL = baseURL ? `${baseURL.replace(/\/$/, "")}/${url.replace(/^\//, "")}` : url;
|
|
@@ -22,6 +62,7 @@ export function useFetch(url, options = {}) {
|
|
|
22
62
|
retry = 0,
|
|
23
63
|
retryDelay = 1000,
|
|
24
64
|
key,
|
|
65
|
+
hydrate = !0,
|
|
25
66
|
cacheTime = 0,
|
|
26
67
|
refetchOnFocus = !1,
|
|
27
68
|
refetchInterval,
|
|
@@ -30,7 +71,7 @@ export function useFetch(url, options = {}) {
|
|
|
30
71
|
query,
|
|
31
72
|
body,
|
|
32
73
|
...fetchOptions
|
|
33
|
-
} = options, data = state(
|
|
74
|
+
} = options, hydrated = readHydratedData(key, hydrate, transform), hydratedValue = hydrated ? hydrated.data : initialData, data = state(hydratedValue), loading = state(!1), isFetching = state(!1), error = state(hydrated?.error ?? null), status = state(null), statusText = state(null);
|
|
34
75
|
let abortController = null, focusHandler = null, intervalId = null;
|
|
35
76
|
const getURL = () => {
|
|
36
77
|
const rawURL = typeof url === "function" ? url() : url;
|
|
@@ -149,7 +190,8 @@ export function useFetch(url, options = {}) {
|
|
|
149
190
|
intervalId = setInterval(() => void doFetch(0, !0), refetchInterval);
|
|
150
191
|
};
|
|
151
192
|
if (immediate) {
|
|
152
|
-
|
|
193
|
+
if (!hydrated)
|
|
194
|
+
doFetch();
|
|
153
195
|
setupRefetchOnFocus();
|
|
154
196
|
setupRefetchInterval();
|
|
155
197
|
}
|
|
@@ -186,8 +228,9 @@ export function useAsyncData(fetcher, options = {}) {
|
|
|
186
228
|
transform,
|
|
187
229
|
initialData = null,
|
|
188
230
|
key,
|
|
231
|
+
hydrate = !0,
|
|
189
232
|
cacheTime = 0
|
|
190
|
-
} = options, data = state(
|
|
233
|
+
} = options, hydrated = readHydratedData(key, hydrate, transform), hydratedValue = hydrated ? hydrated.data : initialData, data = state(hydratedValue), loading = state(!1), isFetching = state(!1), error = state(hydrated?.error ?? null), status = state(null), statusText = state(null), getCacheKey = () => key || fetcher.toString(), getFromCache = () => {
|
|
191
234
|
if (cacheTime <= 0)
|
|
192
235
|
return null;
|
|
193
236
|
const cached = fetchCache.get(getCacheKey());
|
|
@@ -229,7 +272,7 @@ export function useAsyncData(fetcher, options = {}) {
|
|
|
229
272
|
isFetching.set(!1);
|
|
230
273
|
}
|
|
231
274
|
};
|
|
232
|
-
if (immediate)
|
|
275
|
+
if (immediate && !hydrated)
|
|
233
276
|
doFetch();
|
|
234
277
|
return {
|
|
235
278
|
data,
|