@stacksjs/stx 0.2.302 → 0.2.304
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-02hm88m5.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-jsfch50r.js → chunk-1c2j4eby.js} +1 -1
- package/dist/{chunk-m6wz1hf5.js → chunk-2h94c5hm.js} +2 -2
- package/dist/{chunk-mjpqz66q.js → chunk-2ver2s2y.js} +1 -1
- package/dist/{chunk-2wcd2031.js → chunk-30nbe9hr.js} +2 -2
- package/dist/chunk-39qzhpn6.js +18 -0
- package/dist/chunk-3z6bqqr7.js +2 -0
- package/dist/chunk-43p1qq7g.js +2 -0
- package/dist/{chunk-52rkkkmt.js → chunk-45y8bjrv.js} +287 -352
- package/dist/{chunk-2rp09y5j.js → chunk-4evbx7sz.js} +1 -1
- package/dist/chunk-4jgr954p.js +2 -0
- package/dist/chunk-51j2aqvb.js +2 -0
- package/dist/{chunk-8d15pd4g.js → chunk-54f8bpp6.js} +3 -3
- package/dist/{chunk-cbwp8prr.js → chunk-5k1hznvq.js} +2 -2
- package/dist/chunk-5qfpcgcs.js +2 -0
- package/dist/{chunk-7eg7ep8f.js → chunk-5tefa8qb.js} +2 -2
- package/dist/chunk-5x2fc4vk.js +30 -0
- package/dist/{chunk-683tfkz4.js → chunk-64djh88a.js} +1 -1
- package/dist/{chunk-btrmvj2y.js → chunk-695fkras.js} +1 -1
- package/dist/chunk-6hcc4973.js +2 -0
- package/dist/{chunk-svg37jzs.js → chunk-6vswphz4.js} +2 -2
- package/dist/chunk-7gqbr8nr.js +2 -0
- package/dist/{chunk-x4prtyjs.js → chunk-7kw3grq5.js} +1 -1
- package/dist/{chunk-7jebw3ea.js → chunk-7skk34dh.js} +2 -2
- package/dist/chunk-8215nhej.js +12 -0
- 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-3bc8bqw2.js → chunk-9368t9jm.js} +1 -1
- package/dist/chunk-9499k64n.js +6 -0
- package/dist/chunk-976g5qe5.js +2 -0
- package/dist/{chunk-3jwmcf4k.js → chunk-9c835qjn.js} +1 -1
- package/dist/chunk-9px4y692.js +2 -0
- package/dist/{chunk-38t0fxh0.js → chunk-9vqnrcrw.js} +2 -2
- package/dist/chunk-9wrrr7g3.js +4 -0
- package/dist/{chunk-q0y1yxg3.js → chunk-9xzszvn5.js} +1 -1
- package/dist/chunk-a07chbgj.js +2 -0
- package/dist/{chunk-454kar39.js → chunk-ankp4reb.js} +2 -2
- package/dist/{chunk-5d9cy7a0.js → chunk-awj7yy37.js} +1 -1
- package/dist/chunk-b1hd8kvy.js +2 -0
- package/dist/chunk-b4xwbh8a.js +2 -0
- package/dist/{chunk-d6wq91cw.js → chunk-bd9wrcq1.js} +277 -21
- package/dist/{chunk-q25mr70f.js → chunk-c131k3mt.js} +1 -1
- package/dist/chunk-c3tmzx7q.js +2 -0
- package/dist/{chunk-6btbgxh1.js → chunk-c79nfdyj.js} +1 -1
- package/dist/{chunk-cfgpk6bh.js → chunk-cbgh359m.js} +1 -1
- package/dist/chunk-ckzhp09g.js +2 -0
- 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-ctz53mbz.js → chunk-ej8mv2k6.js} +1 -1
- package/dist/{chunk-dv3z80gt.js → chunk-env6knrs.js} +1 -1
- package/dist/{chunk-rf10fkrf.js → chunk-ess2pgt5.js} +1 -1
- package/dist/chunk-ez28vck6.js +2 -0
- package/dist/{chunk-0tbgvp70.js → chunk-fczfdsab.js} +21 -5
- package/dist/{chunk-xdq52pwj.js → chunk-fp7ms6e7.js} +1 -1
- package/dist/{chunk-qg6pg6ze.js → chunk-fqq5k9ve.js} +1 -1
- package/dist/chunk-fvtv1s5j.js +3 -0
- 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-38e9wgfc.js → chunk-gfc3qye3.js} +2 -2
- 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-hay1rzb0.js +3754 -0
- package/dist/{chunk-q5sw26s7.js → chunk-hg2afckn.js} +1 -1
- package/dist/chunk-hgjjnjas.js +7 -0
- 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-jjq9q9jr.js +2 -0
- 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-kbw2qzqx.js +2 -0
- package/dist/chunk-kdxvraec.js +2 -0
- package/dist/chunk-krfjb7b8.js +2 -0
- 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-j21csh4j.js → chunk-mbmqpaq1.js} +1 -1
- package/dist/{chunk-y9nyqcha.js → chunk-mwh3ymwc.js} +1 -1
- package/dist/{chunk-51g95yts.js → chunk-mygq61f5.js} +2 -2
- 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-nvxv2wxv.js → chunk-ppyz9623.js} +1 -1
- package/dist/chunk-pr14wjkn.js +2 -0
- package/dist/{chunk-jb2r696a.js → chunk-qev11kg8.js} +1 -1
- package/dist/{chunk-6njgsr6w.js → chunk-qeyw5za9.js} +1 -1
- package/dist/chunk-rpfcnq8n.js +2 -0
- package/dist/chunk-rrankpmj.js +3 -0
- package/dist/chunk-rst1rw09.js +2 -0
- package/dist/{chunk-3p0zgfgz.js → chunk-rzevgemj.js} +2 -2
- package/dist/{chunk-aa6kt84c.js → chunk-sart9ehj.js} +1 -1
- package/dist/chunk-sb7ana2z.js +19 -0
- package/dist/chunk-snt2773t.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-tt4r8q4v.js +2 -0
- package/dist/chunk-vd3h9z7e.js +2 -0
- package/dist/{chunk-6rzwef28.js → chunk-vd5xvsnv.js} +1 -1
- package/dist/chunk-wbecqx03.js +2 -0
- package/dist/{chunk-dcxtrqfy.js → chunk-wfffa8zm.js} +1 -1
- package/dist/{chunk-22p0ezj6.js → chunk-wx13qmaw.js} +1 -1
- package/dist/chunk-xd5ahrtn.js +2 -0
- package/dist/{chunk-vh0qr8k9.js → chunk-xganfzgn.js} +2 -2
- package/dist/chunk-xq1swv2e.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-y2kmm6bt.js +43 -0
- package/dist/{chunk-v8474ah4.js → chunk-y4nzmkea.js} +1 -1
- package/dist/chunk-y7wsk78j.js +3 -0
- package/dist/{chunk-6w8fa3b8.js → chunk-ya5m5vbn.js} +1 -1
- package/dist/{chunk-ps20v1ah.js → chunk-ym3r8ktq.js} +1 -1
- package/dist/chunk-yyebm8q4.js +2 -0
- package/dist/chunk-yyyxt326.js +2 -0
- package/dist/chunk-yz16bgs3.js +28 -0
- package/dist/{chunk-em8p71et.js → chunk-z9ezmjwd.js} +2 -2
- package/dist/chunk-zbtfhxhn.js +2 -0
- package/dist/chunk-zggm7kjd.js +17 -0
- package/dist/{chunk-mdf3jbe6.js → chunk-zhcs8m2a.js} +2 -2
- package/dist/{chunk-f9d27v49.js → chunk-zs5y7xnt.js} +1 -1
- 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 +8 -2
- 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 +210 -17
- 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-1na1dvda.js +0 -2
- package/dist/chunk-2yp8ang5.js +0 -2
- package/dist/chunk-35x7s4cr.js +0 -2
- package/dist/chunk-39qnycbc.js +0 -2
- package/dist/chunk-4qj6pq60.js +0 -2
- package/dist/chunk-4r1qdp25.js +0 -19
- package/dist/chunk-4xs545h1.js +0 -2
- package/dist/chunk-70cf5h11.js +0 -2
- package/dist/chunk-7k63nhap.js +0 -28
- package/dist/chunk-7w3dttqh.js +0 -2
- package/dist/chunk-813dt09p.js +0 -2
- package/dist/chunk-9cp3430d.js +0 -2
- package/dist/chunk-ac9vpa5z.js +0 -2
- package/dist/chunk-b26xazrf.js +0 -2
- package/dist/chunk-b2ghmxpj.js +0 -4
- package/dist/chunk-btnky17z.js +0 -12
- package/dist/chunk-c7av0px6.js +0 -2
- package/dist/chunk-cthpzv4p.js +0 -18
- package/dist/chunk-d41b0rqp.js +0 -2
- package/dist/chunk-dkd0bg8g.js +0 -2
- package/dist/chunk-e0s519df.js +0 -2
- package/dist/chunk-ebr2344x.js +0 -3
- package/dist/chunk-ehp6fez3.js +0 -2
- package/dist/chunk-fc5t3cxt.js +0 -2
- package/dist/chunk-g6ttsdz1.js +0 -2
- package/dist/chunk-gd73rpks.js +0 -2
- package/dist/chunk-gv42xz15.js +0 -17
- package/dist/chunk-h3t6fjba.js +0 -2
- package/dist/chunk-h65nep6y.js +0 -2
- package/dist/chunk-h7d01cy7.js +0 -2
- package/dist/chunk-jc57j887.js +0 -2
- package/dist/chunk-k5xtf38q.js +0 -3
- package/dist/chunk-mc4rtf5d.js +0 -2
- package/dist/chunk-me5kq4e6.js +0 -22
- package/dist/chunk-mzf6c0h7.js +0 -2
- package/dist/chunk-n1j7gfe1.js +0 -3
- package/dist/chunk-pczxwdes.js +0 -2
- package/dist/chunk-pq6rabcy.js +0 -3754
- package/dist/chunk-qr59yfq9.js +0 -2
- package/dist/chunk-s454ytp4.js +0 -2
- package/dist/chunk-s4sp78fn.js +0 -2
- package/dist/chunk-shr928nn.js +0 -2
- package/dist/chunk-that7v95.js +0 -2
- package/dist/chunk-vwnnbzsp.js +0 -2
- package/dist/chunk-w63052rn.js +0 -2
- package/dist/chunk-w9kzfesd.js +0 -2
- package/dist/chunk-zwy5e35f.js +0 -30
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { stripCommentsAndLiterals } from "./strip-literals.js";
|
|
2
|
+
function closeAt(masked, start, open, close) {
|
|
3
|
+
let depth = 0;
|
|
4
|
+
for (let i = start;i < masked.length; i++)
|
|
5
|
+
if (masked[i] === open)
|
|
6
|
+
depth++;
|
|
7
|
+
else if (masked[i] === close && !(close === ">" && masked[i - 1] === "=")) {
|
|
8
|
+
if (--depth === 0)
|
|
9
|
+
return i;
|
|
10
|
+
}
|
|
11
|
+
return -1;
|
|
12
|
+
}
|
|
13
|
+
function argumentsOf(source) {
|
|
14
|
+
const masked = stripCommentsAndLiterals(source);
|
|
15
|
+
let depth = 0, start = 0;
|
|
16
|
+
const args = [];
|
|
17
|
+
for (let i = 0;i < masked.length; i++)
|
|
18
|
+
if ("([{".includes(masked[i]))
|
|
19
|
+
depth++;
|
|
20
|
+
else if (")]}".includes(masked[i]))
|
|
21
|
+
depth--;
|
|
22
|
+
else if (masked[i] === "," && depth === 0) {
|
|
23
|
+
args.push(source.slice(start, i).trim());
|
|
24
|
+
start = i + 1;
|
|
25
|
+
}
|
|
26
|
+
args.push(source.slice(start).trim());
|
|
27
|
+
return args;
|
|
28
|
+
}
|
|
29
|
+
function macroCall(code, names) {
|
|
30
|
+
const masked = stripCommentsAndLiterals(code), pattern = new RegExp(`\\b(?:${names.map((name) => name.replace(/[$]/g, "\\$&")).join("|")})\\s*(?=[<(])`, "g");
|
|
31
|
+
for (const match of masked.matchAll(pattern)) {
|
|
32
|
+
let at = match.index + match[0].length, type = "";
|
|
33
|
+
if (masked[at] === "<") {
|
|
34
|
+
const close = closeAt(masked, at, "<", ">");
|
|
35
|
+
if (close < 0)
|
|
36
|
+
continue;
|
|
37
|
+
type = code.slice(at + 1, close);
|
|
38
|
+
at = close + 1;
|
|
39
|
+
while (/\s/.test(masked[at] || "") && at < masked.length)
|
|
40
|
+
at++;
|
|
41
|
+
}
|
|
42
|
+
if (masked[at] !== "(")
|
|
43
|
+
continue;
|
|
44
|
+
const close = closeAt(masked, at, "(", ")");
|
|
45
|
+
if (close >= 0)
|
|
46
|
+
return { type, args: argumentsOf(code.slice(at + 1, close)) };
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
export const COMPONENT_CONTRACT_HELPERS = `
|
|
51
|
+
type __StxCtor<T> = T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends ArrayConstructor ? unknown[] : T extends ObjectConstructor ? object : T extends readonly unknown[] ? __StxCtor<T[number]> : T extends abstract new (...args: any[]) => infer V ? V : unknown;
|
|
52
|
+
type __StxWiden<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T;
|
|
53
|
+
type __StxOption<T> = T extends { type: infer C } ? __StxCtor<C> : T extends { default: infer D } ? D extends (...args: any[]) => infer V ? V : __StxWiden<D> : __StxCtor<T>;
|
|
54
|
+
type __StxRequired<O> = { [K in keyof O]-?: O[K] extends { required: true } ? K : never }[keyof O];
|
|
55
|
+
type __StxDefaulted<O> = { [K in keyof O]-?: O[K] extends { default: unknown } ? K : never }[keyof O];
|
|
56
|
+
type __StxOptions<O> = { [K in Exclude<__StxRequired<O>, __StxDefaulted<O>>]: __StxOption<O[K]> } & { [K in Exclude<keyof O, Exclude<__StxRequired<O>, __StxDefaulted<O>>>]?: __StxOption<O[K]> };
|
|
57
|
+
type __StxDefaults<P, K> = Omit<P, Extract<keyof P, K>> & Partial<Pick<P, Extract<keyof P, K>>>;
|
|
58
|
+
`;
|
|
59
|
+
export function componentContract(code, namespace) {
|
|
60
|
+
const imports = [], aliases = { defineProps: ["defineProps"], defineEmits: ["defineEmits"], withDefaults: ["withDefaults"] }, masked = stripCommentsAndLiterals(code), body = code.replace(/\bimport\s+(?:type\s+)?(\{[^}]*\}|\*\s+as\s+[\w$]+|[\w$]+)\s+from\s*(['"])([^'"]+)\2\s*;?/g, (whole, bindings, _quote, specifier, offset) => {
|
|
61
|
+
if (masked.slice(offset, offset + 6) !== "import")
|
|
62
|
+
return whole;
|
|
63
|
+
if (specifier.endsWith(".stx"))
|
|
64
|
+
return "";
|
|
65
|
+
const id = `${namespace}Import${imports.length}`;
|
|
66
|
+
imports.push(`import * as ${id} from ${JSON.stringify(specifier)};`);
|
|
67
|
+
if (bindings.startsWith("*"))
|
|
68
|
+
return `import ${bindings.replace(/^\*\s+as\s+/, "")} = ${id};`;
|
|
69
|
+
if (!bindings.startsWith("{"))
|
|
70
|
+
return `import ${bindings} = ${id}.default;`;
|
|
71
|
+
return bindings.slice(1, -1).split(",").map((binding) => {
|
|
72
|
+
const [original, local = original] = binding.trim().replace(/^type\s+/, "").split(/\s+as\s+/);
|
|
73
|
+
if (!original)
|
|
74
|
+
return "";
|
|
75
|
+
if (/^(?:stx|@stacksjs\/stx)(?:\/|$)/.test(specifier) && original in aliases)
|
|
76
|
+
aliases[original].push(local);
|
|
77
|
+
return `import ${local} = ${id}.${original};`;
|
|
78
|
+
}).join(`
|
|
79
|
+
`);
|
|
80
|
+
}), props = macroCall(code, aliases.defineProps), emits = macroCall(code, aliases.defineEmits), defaults = macroCall(code, aliases.withDefaults);
|
|
81
|
+
if (!props && !emits)
|
|
82
|
+
return { declarations: "", props: null, events: null };
|
|
83
|
+
const declarations = [];
|
|
84
|
+
let propType = null, eventType = null;
|
|
85
|
+
if (props) {
|
|
86
|
+
declarations.push(`const __options = (${props.args[0] || "{}"}) as const;`);
|
|
87
|
+
declarations.push(`const __defaults = (${defaults?.args[1] || "{}"});`);
|
|
88
|
+
const raw = props.type || "__StxOptions<typeof __options>";
|
|
89
|
+
declarations.push(`export type __StxProps = __StxDefaults<${raw}, keyof typeof __defaults | __StxDefaulted<typeof __options>>;`);
|
|
90
|
+
propType = `${namespace}.__StxProps`;
|
|
91
|
+
}
|
|
92
|
+
if (emits) {
|
|
93
|
+
declarations.push(`const __events = (${emits.args[0] || "[]"}) as const;`);
|
|
94
|
+
declarations.push(`export type __StxEvents = ${emits.type || "Record<(typeof __events)[number], any[]>"};`);
|
|
95
|
+
eventType = `${namespace}.__StxEvents`;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
declarations: `${imports.join(`
|
|
99
|
+
`)}
|
|
100
|
+
namespace ${namespace} {
|
|
101
|
+
${body}
|
|
102
|
+
${declarations.join(`
|
|
103
|
+
`)}
|
|
104
|
+
}`,
|
|
105
|
+
props: propType,
|
|
106
|
+
events: eventType
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Signal } from './signals-api';
|
|
2
|
+
export type ModelModifiers = Readonly<Record<string, boolean>>;
|
|
3
|
+
export interface ModelOptions<T> {
|
|
4
|
+
default?: T;
|
|
5
|
+
parse?: (value: string) => T;
|
|
6
|
+
get?: (value: T) => T;
|
|
7
|
+
set?: (value: T, modifiers: ModelModifiers) => T;
|
|
8
|
+
}
|
|
9
|
+
export interface ModelSignal<T> extends Signal<T> {
|
|
10
|
+
readonly modifiers: ModelModifiers;
|
|
11
|
+
/** Input-event write; deferred when the parent supplied .lazy. */
|
|
12
|
+
input(value: T): void;
|
|
13
|
+
/** Change-event write; used only when the parent supplied .lazy. */
|
|
14
|
+
change(value: T): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Shared by module imports and the generated browser runtime. Keep this
|
|
18
|
+
* function closure-free: the runtime embeds its JavaScript source, with all
|
|
19
|
+
* reactive and lifecycle dependencies supplied explicitly.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createModelSignal<T>(source: Signal<T>, modifiers: () => ModelModifiers, emit: (value: T) => void, options: ModelOptions<T>, cleanup: (fn: () => void) => void): ModelSignal<T>;
|
|
22
|
+
export declare function useModel<T>(options: ModelOptions<T> & {
|
|
23
|
+
default: T;
|
|
24
|
+
}): ModelSignal<T>;
|
|
25
|
+
export declare function useModel<T>(name: string, options: ModelOptions<T> & {
|
|
26
|
+
default: T;
|
|
27
|
+
}): ModelSignal<T>;
|
|
28
|
+
export declare function useModel<T = unknown>(name?: string, options?: ModelOptions<T>): ModelSignal<T | undefined>;
|
|
29
|
+
export declare function useModel<T = unknown>(options?: ModelOptions<T>): ModelSignal<T | undefined>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defineEmits, getCurrentInstance } from "./composition-api.js";
|
|
2
|
+
import { effect, isDerived, isSignal, onDestroy, state } from "./signals-api.js";
|
|
3
|
+
export function createModelSignal(source, modifiers, emit, options, cleanup) {
|
|
4
|
+
let active = !0;
|
|
5
|
+
const subscriptions = new Set, read = (value) => options.get ? options.get(value) : value, model = () => read(source());
|
|
6
|
+
Object.defineProperty(model, "_isSignal", { value: !0 });
|
|
7
|
+
Object.defineProperty(model, "modifiers", { get: modifiers });
|
|
8
|
+
model.set = (value) => {
|
|
9
|
+
if (!active)
|
|
10
|
+
return;
|
|
11
|
+
const flags = modifiers();
|
|
12
|
+
let next = options.set ? options.set(value, flags) : value;
|
|
13
|
+
if (flags.trim && typeof next === "string")
|
|
14
|
+
next = next.trim();
|
|
15
|
+
if (flags.number && typeof next === "string" && next !== "") {
|
|
16
|
+
const number = Number(next);
|
|
17
|
+
if (!Number.isNaN(number))
|
|
18
|
+
next = number;
|
|
19
|
+
}
|
|
20
|
+
if (Object.is(source(), next))
|
|
21
|
+
return;
|
|
22
|
+
source.set(next);
|
|
23
|
+
emit(next);
|
|
24
|
+
};
|
|
25
|
+
model.update = (fn) => model.set(fn(model()));
|
|
26
|
+
model.input = (value) => {
|
|
27
|
+
if (!modifiers().lazy)
|
|
28
|
+
model.set(value);
|
|
29
|
+
};
|
|
30
|
+
model.change = (value) => {
|
|
31
|
+
if (modifiers().lazy)
|
|
32
|
+
model.set(value);
|
|
33
|
+
};
|
|
34
|
+
model.subscribe = (callback) => {
|
|
35
|
+
if (!active)
|
|
36
|
+
return () => {};
|
|
37
|
+
const unsubscribe = source.subscribe((value, previous) => callback(read(value), read(previous)));
|
|
38
|
+
subscriptions.add(unsubscribe);
|
|
39
|
+
return () => {
|
|
40
|
+
unsubscribe();
|
|
41
|
+
subscriptions.delete(unsubscribe);
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(model, "value", { get: model, set: model.set });
|
|
45
|
+
cleanup(() => {
|
|
46
|
+
active = !1;
|
|
47
|
+
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
48
|
+
subscriptions.clear();
|
|
49
|
+
});
|
|
50
|
+
return model;
|
|
51
|
+
}
|
|
52
|
+
export function useModel(nameOrOptions = "modelValue", options = {}) {
|
|
53
|
+
const name = typeof nameOrOptions === "string" ? nameOrOptions : "modelValue", opts = typeof nameOrOptions === "string" ? options : nameOrOptions, props = getCurrentInstance()?.props || {}, emit = defineEmits([`update:${name}`]), modifierName = name === "modelValue" ? "modelModifiers" : `${name}Modifiers`, readProp = (key) => isSignal(props[key]) || isDerived(props[key]) ? props[key]() : props[key], source = state(opts.default), stop = effect(() => {
|
|
54
|
+
const value = readProp(name);
|
|
55
|
+
source.set(value === void 0 ? opts.default : value);
|
|
56
|
+
});
|
|
57
|
+
onDestroy(stop);
|
|
58
|
+
return createModelSignal(source, () => readProp(modifierName) || {}, (value) => emit(`update:${name}`, value), opts, onDestroy);
|
|
59
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import fs from "node:fs";
|
|
1
|
+
import { componentFileCandidates, importedComponentPath } from "./component-resolution.js";
|
|
3
2
|
import { fileExists } from "./utils.js";
|
|
4
3
|
export function kebabToPascal(str) {
|
|
5
4
|
return str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
@@ -22,68 +21,12 @@ export class ComponentRegistry {
|
|
|
22
21
|
return this.builtins.get(name.toLowerCase()) ?? null;
|
|
23
22
|
}
|
|
24
23
|
async resolveFile(name, fromFile, options, parentContext) {
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
pascalToKebab(baseName)
|
|
32
|
-
];
|
|
33
|
-
for (const n of namesToTry)
|
|
34
|
-
if (importedComponents.has(n))
|
|
35
|
-
return importedComponents.get(n);
|
|
36
|
-
}
|
|
37
|
-
const fileVariants = [...new Set([
|
|
38
|
-
`${baseName}.stx`,
|
|
39
|
-
`${kebabToPascal(baseName)}.stx`,
|
|
40
|
-
`${pascalToKebab(baseName)}.stx`
|
|
41
|
-
])];
|
|
42
|
-
if (baseName.startsWith("./") || baseName.startsWith("../")) {
|
|
43
|
-
const resolved = path.resolve(path.dirname(fromFile), `${baseName}.stx`);
|
|
44
|
-
if (await fileExists(resolved))
|
|
45
|
-
return resolved;
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const searchDirs = [], componentsDir = options.componentsDir || "", originalFilePath = parentContext?.__originalFilePath;
|
|
49
|
-
if (originalFilePath)
|
|
50
|
-
searchDirs.push(path.join(path.dirname(originalFilePath), "components"));
|
|
51
|
-
if (componentsDir)
|
|
52
|
-
searchDirs.push(componentsDir);
|
|
53
|
-
const parentRelative = path.join(path.dirname(fromFile), "components");
|
|
54
|
-
if (!searchDirs.includes(parentRelative))
|
|
55
|
-
searchDirs.push(parentRelative);
|
|
56
|
-
const projectRoot = process.cwd(), fallbackDirs = [
|
|
57
|
-
path.resolve(projectRoot, "src/components"),
|
|
58
|
-
path.resolve(projectRoot, "components"),
|
|
59
|
-
path.resolve(import.meta.dir, "components")
|
|
60
|
-
];
|
|
61
|
-
for (const fallback of fallbackDirs)
|
|
62
|
-
if (!searchDirs.includes(fallback))
|
|
63
|
-
searchDirs.push(fallback);
|
|
64
|
-
for (const dir of searchDirs) {
|
|
65
|
-
if (!dir)
|
|
66
|
-
continue;
|
|
67
|
-
for (const variant of fileVariants) {
|
|
68
|
-
const tryPath = path.join(dir, variant);
|
|
69
|
-
if (await fileExists(tryPath))
|
|
70
|
-
return tryPath;
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
if (!fs.statSync(dir, { throwIfNoEntry: !1 })?.isDirectory())
|
|
74
|
-
continue;
|
|
75
|
-
const entries = fs.readdirSync(dir, { withFileTypes: !0 });
|
|
76
|
-
for (const entry of entries)
|
|
77
|
-
if (entry.isDirectory()) {
|
|
78
|
-
const subDir = path.join(dir, entry.name);
|
|
79
|
-
for (const variant of fileVariants) {
|
|
80
|
-
const tryPath = path.join(subDir, variant);
|
|
81
|
-
if (await fileExists(tryPath))
|
|
82
|
-
return tryPath;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
} catch {}
|
|
86
|
-
}
|
|
24
|
+
const imported = importedComponentPath(name, parentContext);
|
|
25
|
+
if (imported !== void 0)
|
|
26
|
+
return imported;
|
|
27
|
+
for (const candidate of componentFileCandidates(name, fromFile, options, parentContext))
|
|
28
|
+
if (await fileExists(candidate))
|
|
29
|
+
return candidate;
|
|
87
30
|
return null;
|
|
88
31
|
}
|
|
89
32
|
}
|
|
@@ -1,31 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified Component Renderer
|
|
3
|
-
*
|
|
4
|
-
* Replaces all existing component processing with a single `processComponents()`
|
|
5
|
-
* entry point. Handles:
|
|
6
|
-
*
|
|
7
|
-
* 1. Built-in components (StxLink, StxImage, StxLoadingIndicator) — resolved
|
|
8
|
-
* via the component registry and rendered directly to HTML.
|
|
9
|
-
* 2. File-based user components — resolved from the filesystem and rendered
|
|
10
|
-
* via `renderComponentWithSlot()`.
|
|
11
|
-
* 3. `@component` directives — `@component('name', { props })...@endcomponent`.
|
|
12
|
-
* 4. `@import` directives — `@import('ComponentName', './path/to/component')`.
|
|
13
|
-
*
|
|
14
|
-
* Props are categorized into static, serverDynamic, clientReactive, and events
|
|
15
|
-
* through `parseComponentProps()` before being passed to the appropriate renderer.
|
|
16
|
-
*
|
|
17
|
-
* @module component-renderer
|
|
18
|
-
*/
|
|
19
1
|
import type { StxOptions } from './types';
|
|
20
2
|
import { freeIdentifiers } from './safe-evaluator';
|
|
21
|
-
|
|
22
|
-
* Whether `tagName` certainly reaches the page as the element it names, by the
|
|
23
|
-
* three passes of `processComponents` below. A component tag is replaced by
|
|
24
|
-
* the component's markup, and attributes stamped on the tag do not survive it.
|
|
25
|
-
* A kebab-case tag is a component when a file of that name exists, which this
|
|
26
|
-
* cannot know, so it never counts as certain.
|
|
27
|
-
*/
|
|
28
|
-
export declare function rendersAsElement(tagName: string): boolean;
|
|
3
|
+
export { rendersAsElement } from './component-tags';
|
|
29
4
|
/**
|
|
30
5
|
* Process ES `import { A, B } from '<spec>'` statements inside `<script>` tags
|
|
31
6
|
* for component tag registration. Registers each named import as a tag pointing
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildStxIndex, componentImportCandidates, resolvePackageDir } from "./component-resolution.js";
|
|
1
2
|
import { registry } from "./component-registry.js";
|
|
2
3
|
import { processConditionals } from "./conditionals.js";
|
|
3
4
|
import { registerBuiltins } from "./builtins/index.js";
|
|
@@ -12,180 +13,8 @@ import { stripCommentsAndLiterals } from "./strip-literals.js";
|
|
|
12
13
|
import fs from "node:fs";
|
|
13
14
|
import path from "node:path";
|
|
14
15
|
let builtinsRegistered = !1;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"abbr",
|
|
18
|
-
"address",
|
|
19
|
-
"area",
|
|
20
|
-
"article",
|
|
21
|
-
"aside",
|
|
22
|
-
"audio",
|
|
23
|
-
"b",
|
|
24
|
-
"base",
|
|
25
|
-
"bdi",
|
|
26
|
-
"bdo",
|
|
27
|
-
"blockquote",
|
|
28
|
-
"body",
|
|
29
|
-
"br",
|
|
30
|
-
"button",
|
|
31
|
-
"canvas",
|
|
32
|
-
"caption",
|
|
33
|
-
"cite",
|
|
34
|
-
"code",
|
|
35
|
-
"col",
|
|
36
|
-
"colgroup",
|
|
37
|
-
"component",
|
|
38
|
-
"data",
|
|
39
|
-
"datalist",
|
|
40
|
-
"dd",
|
|
41
|
-
"del",
|
|
42
|
-
"details",
|
|
43
|
-
"dfn",
|
|
44
|
-
"dialog",
|
|
45
|
-
"div",
|
|
46
|
-
"dl",
|
|
47
|
-
"dt",
|
|
48
|
-
"em",
|
|
49
|
-
"embed",
|
|
50
|
-
"fieldset",
|
|
51
|
-
"figcaption",
|
|
52
|
-
"figure",
|
|
53
|
-
"footer",
|
|
54
|
-
"form",
|
|
55
|
-
"h1",
|
|
56
|
-
"h2",
|
|
57
|
-
"h3",
|
|
58
|
-
"h4",
|
|
59
|
-
"h5",
|
|
60
|
-
"h6",
|
|
61
|
-
"head",
|
|
62
|
-
"header",
|
|
63
|
-
"hgroup",
|
|
64
|
-
"hr",
|
|
65
|
-
"html",
|
|
66
|
-
"i",
|
|
67
|
-
"iframe",
|
|
68
|
-
"img",
|
|
69
|
-
"input",
|
|
70
|
-
"ins",
|
|
71
|
-
"kbd",
|
|
72
|
-
"label",
|
|
73
|
-
"legend",
|
|
74
|
-
"li",
|
|
75
|
-
"link",
|
|
76
|
-
"main",
|
|
77
|
-
"map",
|
|
78
|
-
"mark",
|
|
79
|
-
"menu",
|
|
80
|
-
"meta",
|
|
81
|
-
"meter",
|
|
82
|
-
"nav",
|
|
83
|
-
"noscript",
|
|
84
|
-
"object",
|
|
85
|
-
"ol",
|
|
86
|
-
"optgroup",
|
|
87
|
-
"option",
|
|
88
|
-
"output",
|
|
89
|
-
"p",
|
|
90
|
-
"param",
|
|
91
|
-
"picture",
|
|
92
|
-
"pre",
|
|
93
|
-
"progress",
|
|
94
|
-
"q",
|
|
95
|
-
"rp",
|
|
96
|
-
"rt",
|
|
97
|
-
"ruby",
|
|
98
|
-
"s",
|
|
99
|
-
"samp",
|
|
100
|
-
"script",
|
|
101
|
-
"section",
|
|
102
|
-
"select",
|
|
103
|
-
"slot",
|
|
104
|
-
"small",
|
|
105
|
-
"source",
|
|
106
|
-
"span",
|
|
107
|
-
"strong",
|
|
108
|
-
"style",
|
|
109
|
-
"sub",
|
|
110
|
-
"summary",
|
|
111
|
-
"sup",
|
|
112
|
-
"svg",
|
|
113
|
-
"table",
|
|
114
|
-
"tbody",
|
|
115
|
-
"td",
|
|
116
|
-
"template",
|
|
117
|
-
"textarea",
|
|
118
|
-
"tfoot",
|
|
119
|
-
"th",
|
|
120
|
-
"thead",
|
|
121
|
-
"time",
|
|
122
|
-
"title",
|
|
123
|
-
"tr",
|
|
124
|
-
"track",
|
|
125
|
-
"u",
|
|
126
|
-
"ul",
|
|
127
|
-
"var",
|
|
128
|
-
"video",
|
|
129
|
-
"wbr",
|
|
130
|
-
"path",
|
|
131
|
-
"circle",
|
|
132
|
-
"rect",
|
|
133
|
-
"line",
|
|
134
|
-
"polygon",
|
|
135
|
-
"polyline",
|
|
136
|
-
"ellipse",
|
|
137
|
-
"text",
|
|
138
|
-
"tspan",
|
|
139
|
-
"textPath",
|
|
140
|
-
"g",
|
|
141
|
-
"defs",
|
|
142
|
-
"use",
|
|
143
|
-
"symbol",
|
|
144
|
-
"image",
|
|
145
|
-
"clipPath",
|
|
146
|
-
"mask",
|
|
147
|
-
"pattern",
|
|
148
|
-
"marker",
|
|
149
|
-
"linearGradient",
|
|
150
|
-
"radialGradient",
|
|
151
|
-
"stop",
|
|
152
|
-
"filter",
|
|
153
|
-
"feBlend",
|
|
154
|
-
"feColorMatrix",
|
|
155
|
-
"feComponentTransfer",
|
|
156
|
-
"feComposite",
|
|
157
|
-
"feConvolveMatrix",
|
|
158
|
-
"feDiffuseLighting",
|
|
159
|
-
"feDisplacementMap",
|
|
160
|
-
"feDropShadow",
|
|
161
|
-
"feFlood",
|
|
162
|
-
"feGaussianBlur",
|
|
163
|
-
"feImage",
|
|
164
|
-
"feMerge",
|
|
165
|
-
"feMergeNode",
|
|
166
|
-
"feMorphology",
|
|
167
|
-
"feOffset",
|
|
168
|
-
"feSpecularLighting",
|
|
169
|
-
"feTile",
|
|
170
|
-
"feTurbulence",
|
|
171
|
-
"foreignObject",
|
|
172
|
-
"animate",
|
|
173
|
-
"animateMotion",
|
|
174
|
-
"animateTransform",
|
|
175
|
-
"set",
|
|
176
|
-
"mpath",
|
|
177
|
-
"desc",
|
|
178
|
-
"metadata",
|
|
179
|
-
"switch",
|
|
180
|
-
"view"
|
|
181
|
-
]);
|
|
182
|
-
export function rendersAsElement(tagName) {
|
|
183
|
-
if (tagName.includes("-") || tagName === "component")
|
|
184
|
-
return !1;
|
|
185
|
-
if (/^[A-Z]/.test(tagName))
|
|
186
|
-
return uppercaseHtmlTagSkip(htmlTags)(tagName);
|
|
187
|
-
return htmlTags.has(tagName) || /[A-Z]/.test(tagName);
|
|
188
|
-
}
|
|
16
|
+
import { htmlTags } from "./component-tags.js";
|
|
17
|
+
export { rendersAsElement } from "./component-tags.js";
|
|
189
18
|
function parseComponentProps(rawProps, context, options, deferDynamicToClient = !1) {
|
|
190
19
|
const resolved = {
|
|
191
20
|
static: {},
|
|
@@ -401,64 +230,6 @@ function findUnresolvedBuiltinTags(template) {
|
|
|
401
230
|
}
|
|
402
231
|
return [...unresolved].sort();
|
|
403
232
|
}
|
|
404
|
-
const pkgStxIndexCache = new Map;
|
|
405
|
-
function buildStxIndex(pkgDir) {
|
|
406
|
-
const cached = pkgStxIndexCache.get(pkgDir);
|
|
407
|
-
if (cached)
|
|
408
|
-
return cached;
|
|
409
|
-
const index = new Map, roots = [path.join(pkgDir, "src"), path.join(pkgDir, "dist"), pkgDir];
|
|
410
|
-
function walk(dir, depth) {
|
|
411
|
-
if (depth > 6)
|
|
412
|
-
return;
|
|
413
|
-
let entries;
|
|
414
|
-
try {
|
|
415
|
-
entries = fs.readdirSync(dir, { withFileTypes: !0 });
|
|
416
|
-
} catch {
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
for (const entry of entries) {
|
|
420
|
-
const full = path.join(dir, entry.name);
|
|
421
|
-
if (entry.isDirectory()) {
|
|
422
|
-
if (entry.name === "node_modules" || entry.name.startsWith("."))
|
|
423
|
-
continue;
|
|
424
|
-
walk(full, depth + 1);
|
|
425
|
-
} else if (entry.isFile() && entry.name.endsWith(".stx")) {
|
|
426
|
-
const base = entry.name.slice(0, -4);
|
|
427
|
-
if (!index.has(base))
|
|
428
|
-
index.set(base, full);
|
|
429
|
-
const lower = base.toLowerCase();
|
|
430
|
-
if (!index.has(lower))
|
|
431
|
-
index.set(lower, full);
|
|
432
|
-
const kebab = base.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
433
|
-
if (!index.has(kebab))
|
|
434
|
-
index.set(kebab, full);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
for (const root of roots) {
|
|
439
|
-
walk(root, 0);
|
|
440
|
-
if (index.size > 0)
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
pkgStxIndexCache.set(pkgDir, index);
|
|
444
|
-
return index;
|
|
445
|
-
}
|
|
446
|
-
function resolvePackageDir(spec, fromDir) {
|
|
447
|
-
if (spec.startsWith(".") || spec.startsWith("/"))
|
|
448
|
-
return null;
|
|
449
|
-
let dir = fromDir;
|
|
450
|
-
while (!0) {
|
|
451
|
-
const candidate = path.join(dir, "node_modules", spec);
|
|
452
|
-
try {
|
|
453
|
-
if (fs.statSync(candidate).isDirectory())
|
|
454
|
-
return candidate;
|
|
455
|
-
} catch {}
|
|
456
|
-
const parent = path.dirname(dir);
|
|
457
|
-
if (parent === dir)
|
|
458
|
-
return null;
|
|
459
|
-
dir = parent;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
233
|
|
|
463
234
|
export { freeIdentifiers };
|
|
464
235
|
export async function processESImports(template, context, filePath, options, dependencies) {
|
|
@@ -559,13 +330,7 @@ async function processImports(template, context, filePath, options, dependencies
|
|
|
559
330
|
for (const componentPath of paths) {
|
|
560
331
|
const segments = componentPath.split("/"), baseName = segments[segments.length - 1].replace(/\.stx$/, ""), componentName = baseName.includes("-") ? baseName.split("-").map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("") : baseName.charAt(0).toUpperCase() + baseName.slice(1);
|
|
561
332
|
let resolvedPath = null;
|
|
562
|
-
const possiblePaths =
|
|
563
|
-
path.resolve(path.dirname(filePath), `${componentPath}.stx`),
|
|
564
|
-
path.resolve(path.dirname(filePath), componentPath),
|
|
565
|
-
path.resolve(options.componentsDir || "components", `${componentPath}.stx`),
|
|
566
|
-
path.resolve(options.componentsDir || "components", componentPath),
|
|
567
|
-
componentPath.endsWith(".stx") ? componentPath : `${componentPath}.stx`
|
|
568
|
-
];
|
|
333
|
+
const possiblePaths = componentImportCandidates(componentPath, filePath, options);
|
|
569
334
|
for (const tryPath of possiblePaths)
|
|
570
335
|
try {
|
|
571
336
|
if (await Bun.file(tryPath).exists()) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Shared package component index; editor checks bypass the renderer's cache. */
|
|
2
|
+
export declare function buildStxIndex(pkgDir: string, cache?: boolean): Map<string, string>;
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a module specifier (e.g. '@stacksjs/components' or './foo') to a
|
|
5
|
+
* package directory on disk, walking up node_modules from `fromDir`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolvePackageDir(spec: string, fromDir: string): string | null;
|
|
8
|
+
export interface ComponentLookupOptions {
|
|
9
|
+
componentsDir?: string;
|
|
10
|
+
projectRoot?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ComponentLookupContext {
|
|
13
|
+
__importedComponents?: Map<string, string>;
|
|
14
|
+
__originalFilePath?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function componentImportCandidates(componentPath: string, filePath: string, options?: ComponentLookupOptions): string[];
|
|
17
|
+
export declare function importedComponentPath(name: string, context?: ComponentLookupContext): string | undefined;
|
|
18
|
+
/** The renderer and editor walk exactly the same ordered file candidates. */
|
|
19
|
+
export declare function componentFileCandidates(name: string, fromFile: string, options?: ComponentLookupOptions, context?: ComponentLookupContext): Generator<string>;
|
|
20
|
+
/** Synchronous counterpart for TypeScript's synchronous language-service host. */
|
|
21
|
+
export declare function resolveComponentFileSync(name: string, fromFile: string, options?: ComponentLookupOptions, context?: ComponentLookupContext): string | null;
|