@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
package/dist/stx-virtual-ts.js
CHANGED
|
@@ -2,6 +2,7 @@ import { BROWSER_CORE_IMPORTS } from "./browser-core-imports.js";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { stripCommentsAndLiterals } from "./strip-literals.js";
|
|
4
4
|
import { STX_RUNTIME_GLOBALS } from "./runtime-globals.js";
|
|
5
|
+
import { componentContractChecks } from "./component-contract-checks.js";
|
|
5
6
|
const SCRIPT_RE = /<script(\s[^>]*)?>([\s\S]*?)<\/script>/gi;
|
|
6
7
|
function blankCommentContents(source) {
|
|
7
8
|
const blank = (match) => match.replace(/[^\n]/g, " ");
|
|
@@ -570,7 +571,14 @@ export function absolutizeRelativeSpecifiers(code, originDir) {
|
|
|
570
571
|
}
|
|
571
572
|
export function buildVirtualTypeScript(source, options = {}) {
|
|
572
573
|
const blocks = extractScriptBlocks(source), sourceLines = source.split(`
|
|
573
|
-
`), lines = Array.from({ length: sourceLines.length }, () => ""), lineMap = new Map
|
|
574
|
+
`), lines = Array.from({ length: sourceLines.length }, () => ""), lineMap = new Map, components = options.filePath && options.templateExpressions !== !1 ? componentContractChecks(source, maskNonTemplateRegions(source), {
|
|
575
|
+
filePath: options.filePath,
|
|
576
|
+
componentsDir: options.componentsDir,
|
|
577
|
+
projectRoot: options.projectRoot,
|
|
578
|
+
readComponent: options.readComponent,
|
|
579
|
+
scriptCode: (text, file) => extractScriptBlocks(text).map((block) => absolutizeRelativeSpecifiers(block.code, path.dirname(file))).join(`
|
|
580
|
+
`)
|
|
581
|
+
}) : void 0;
|
|
574
582
|
for (const block of blocks)
|
|
575
583
|
absolutizeRelativeSpecifiers(block.code, options.originDir ?? "").split(`
|
|
576
584
|
`).forEach((text, i) => {
|
|
@@ -579,9 +587,12 @@ export function buildVirtualTypeScript(source, options = {}) {
|
|
|
579
587
|
lines[index] = text;
|
|
580
588
|
});
|
|
581
589
|
const append = (text, origin) => {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
590
|
+
for (const [index, line] of text.split(`
|
|
591
|
+
`).entries()) {
|
|
592
|
+
lines.push(line);
|
|
593
|
+
if (origin)
|
|
594
|
+
lineMap.set(lines.length, index === 0 ? origin : { ...origin, line: origin.line + index, column: 1, prefixLength: 0 });
|
|
595
|
+
}
|
|
585
596
|
};
|
|
586
597
|
if (options.globals !== !1) {
|
|
587
598
|
append("");
|
|
@@ -607,7 +618,20 @@ export function buildVirtualTypeScript(source, options = {}) {
|
|
|
607
618
|
}
|
|
608
619
|
}
|
|
609
620
|
if (options.templateExpressions !== !1) {
|
|
610
|
-
|
|
621
|
+
if (components?.declarations)
|
|
622
|
+
for (const line of components.declarations.split(`
|
|
623
|
+
`))
|
|
624
|
+
append(line);
|
|
625
|
+
const statements = extractTemplateExpressions(source).map((expression) => {
|
|
626
|
+
const payload = components?.events.get(expression.offset ?? -1);
|
|
627
|
+
if (payload) {
|
|
628
|
+
expression.anchor = !0;
|
|
629
|
+
const code = expression.code.trim(), assignment = /^([\w$]+)\s*=\s*([^=][\s\S]*)$/.exec(code), body = assignment ? `void ((${assignment[2]}) satisfies __StxAssignedValue<typeof ${assignment[1]}>)` : /^[\w$]+(?:\.[\w$]+)*$/.test(code) ? `${code}($event)` : code, prefix = `;(($event: ${payload}): void => { `;
|
|
630
|
+
return { expression, statement: { text: `${prefix}${body} });`, prefixLength: prefix.length } };
|
|
631
|
+
}
|
|
632
|
+
return { expression, statement: expressionStatement(expression) };
|
|
633
|
+
}).filter((entry) => entry.statement !== null);
|
|
634
|
+
statements.push(...components?.checks || []);
|
|
611
635
|
if (statements.length > 0) {
|
|
612
636
|
const maskedSource = maskNonTemplateRegions(source), shadowed = [...new Set(blocks.flatMap((block) => collectBlockDeclarations(block.code)))].filter((name) => /^[A-Z_$][\w$]*$/i.test(name));
|
|
613
637
|
let indent = 0;
|
|
@@ -633,7 +657,7 @@ export function buildVirtualTypeScript(source, options = {}) {
|
|
|
633
657
|
}
|
|
634
658
|
append("export {}");
|
|
635
659
|
return { text: lines.join(`
|
|
636
|
-
`), lineMap, sourceLineCount: sourceLines.length };
|
|
660
|
+
`), lineMap, sourceLineCount: sourceLines.length, componentDependencies: components?.dependencies };
|
|
637
661
|
}
|
|
638
662
|
export function lineStarts(text) {
|
|
639
663
|
const starts = [0];
|
|
@@ -661,7 +685,7 @@ export function resolvePosition(virtual, line, column) {
|
|
|
661
685
|
const mapped = virtual.lineMap.get(line);
|
|
662
686
|
if (!mapped)
|
|
663
687
|
return line <= virtual.sourceLineCount ? { line, column } : null;
|
|
664
|
-
const within = Math.max(0, column - 1 - (mapped.prefixLength ?? 0));
|
|
688
|
+
const within = mapped.expression?.anchor ? 0 : Math.max(0, column - 1 - (mapped.prefixLength ?? 0));
|
|
665
689
|
return {
|
|
666
690
|
line: mapped.line,
|
|
667
691
|
column: mapped.column + within,
|
package/dist/stx.d.ts
CHANGED
|
@@ -116,6 +116,21 @@ declare function useReactiveProp<T = unknown>(
|
|
|
116
116
|
_defaultValue?: T,
|
|
117
117
|
_options?: { parse?: (_value: string) => T },
|
|
118
118
|
): StxSignal<T>
|
|
119
|
+
interface StxModelOptions<T> {
|
|
120
|
+
default?: T
|
|
121
|
+
parse?: (value: string) => T
|
|
122
|
+
get?: (value: T) => T
|
|
123
|
+
set?: (value: T, modifiers: Readonly<Record<string, boolean>>) => T
|
|
124
|
+
}
|
|
125
|
+
interface StxModelSignal<T> extends StxSignal<T> {
|
|
126
|
+
readonly modifiers: Readonly<Record<string, boolean>>
|
|
127
|
+
input(value: T): void
|
|
128
|
+
change(value: T): void
|
|
129
|
+
}
|
|
130
|
+
declare function useModel<T>(options: StxModelOptions<T> & { default: T }): StxModelSignal<T>
|
|
131
|
+
declare function useModel<T>(name: string, options: StxModelOptions<T> & { default: T }): StxModelSignal<T>
|
|
132
|
+
declare function useModel<T = unknown>(name?: string, options?: StxModelOptions<T>): StxModelSignal<T | undefined>
|
|
133
|
+
declare function useModel<T = unknown>(options?: StxModelOptions<T>): StxModelSignal<T | undefined>
|
|
119
134
|
/**
|
|
120
135
|
* A template ref. Read it however the surrounding code reads things: `ref()`
|
|
121
136
|
* like every other stx accessor, or `ref.current` / `ref.value` for the
|
|
@@ -268,6 +283,10 @@ interface StxMutationResult<T> {
|
|
|
268
283
|
}
|
|
269
284
|
|
|
270
285
|
declare function useFetch<T = any>(_url: string, _options?: any): StxFetchResult<T>
|
|
286
|
+
/** Server-only, keyed JSON data exposed to this render's client hydration. */
|
|
287
|
+
declare function useServerData<T>(_key: string, _loader: () => T | Promise<T>): Promise<T>
|
|
288
|
+
/** Clear a hydration snapshot without changing existing signals. */
|
|
289
|
+
declare function clearServerData(_key?: string): void
|
|
271
290
|
declare function useQuery<T = any>(_url: string, _options?: any): StxQueryResult<T>
|
|
272
291
|
declare function useMutation<T = any>(_url: string, _options?: any): StxMutationResult<T>
|
|
273
292
|
|
|
@@ -314,6 +333,13 @@ declare function configureFetch(_config: {
|
|
|
314
333
|
onRequest?: (_ctx: StxFetchRequestContext) => void | Promise<void>
|
|
315
334
|
onResponse?: (_ctx: StxFetchResponseContext) => void | Promise<void>
|
|
316
335
|
onResponseError?: (_ctx: StxFetchErrorContext) => void | Response | Promise<void | Response>
|
|
336
|
+
/**
|
|
337
|
+
* Double-submit CSRF. By default every same-origin POST/PUT/PATCH/DELETE
|
|
338
|
+
* repeats the `X-CSRF-Token` cookie in an `X-CSRF-Token` header, which is
|
|
339
|
+
* what a Stacks server checks. Rename either side, or pass `false` to stop.
|
|
340
|
+
* Unlike the hooks, this persists across calls that do not mention it.
|
|
341
|
+
*/
|
|
342
|
+
csrf?: false | { cookie?: string, header?: string }
|
|
317
343
|
}): void
|
|
318
344
|
|
|
319
345
|
declare function useOptimistic<T = any, A = any>(
|
|
@@ -826,6 +852,7 @@ interface StxRuntimeRegistry {
|
|
|
826
852
|
|
|
827
853
|
// Composables
|
|
828
854
|
useFetch: typeof useFetch
|
|
855
|
+
clearServerData: typeof clearServerData
|
|
829
856
|
useRef: typeof useRef
|
|
830
857
|
useQuery: typeof useQuery
|
|
831
858
|
useMutation: typeof useMutation
|
|
@@ -872,6 +899,7 @@ interface StxRuntimeRegistry {
|
|
|
872
899
|
useClickOutside: typeof useClickOutside
|
|
873
900
|
useFocus: typeof useFocus
|
|
874
901
|
useAsync: typeof useAsync
|
|
902
|
+
useModel: typeof useModel
|
|
875
903
|
useLocalStorage: typeof useLocalStorage
|
|
876
904
|
useSessionStorage: typeof useSessionStorage
|
|
877
905
|
useEventListener: typeof useEventListener
|
|
@@ -10,6 +10,7 @@ import { type PlaceholderMap } from './placeholder';
|
|
|
10
10
|
* @param options - Additional compilation options
|
|
11
11
|
*/
|
|
12
12
|
export declare function compileTemplate(filePath: string, route: string, options?: {
|
|
13
|
+
configDir?: string
|
|
13
14
|
componentsDir?: string
|
|
14
15
|
partialsDir?: string
|
|
15
16
|
layoutsDir?: string
|
|
@@ -31,7 +31,7 @@ export async function compileTemplate(filePath, route, options = {}) {
|
|
|
31
31
|
resetPlaceholders();
|
|
32
32
|
let projectConfig = {};
|
|
33
33
|
try {
|
|
34
|
-
projectConfig = await loadStxConfig();
|
|
34
|
+
projectConfig = await loadStxConfig(options.configDir);
|
|
35
35
|
} catch {}
|
|
36
36
|
const serverScriptContent = [], scriptRegex = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
37
37
|
let scriptMatch;
|
|
@@ -3,6 +3,7 @@ import { evaluateExpression, escapeHtmlValue } from "./expressions.js";
|
|
|
3
3
|
import { replacePlaceholders, hasPlaceholders } from "./placeholder.js";
|
|
4
4
|
import { runPageAction } from "./page-action.js";
|
|
5
5
|
import { readResponseHeaders, readResponseStatus } from "./page-response.js";
|
|
6
|
+
import { serverDataTag } from "./server-data.js";
|
|
6
7
|
export async function hydrateTemplate(compiled, requestContext = {}) {
|
|
7
8
|
return (await runHydration(compiled, requestContext)).html;
|
|
8
9
|
}
|
|
@@ -37,6 +38,8 @@ async function runHydration(compiled, requestContext) {
|
|
|
37
38
|
try {
|
|
38
39
|
await extractVariables(scriptContent, context, compiled.sourceFile);
|
|
39
40
|
} catch (error) {
|
|
41
|
+
if (requestContext.__stx_strict_hydration)
|
|
42
|
+
throw error;
|
|
40
43
|
console.warn(`[stx] Server script error in ${compiled.sourceFile}:`, error);
|
|
41
44
|
}
|
|
42
45
|
const action = await runPageAction(context, {
|
|
@@ -44,11 +47,17 @@ async function runHydration(compiled, requestContext) {
|
|
|
44
47
|
method: requestContext.method,
|
|
45
48
|
params: requestContext.params ?? {},
|
|
46
49
|
cookies: requestContext.cookies ?? {}
|
|
47
|
-
})
|
|
50
|
+
}), withServerData = (html) => {
|
|
51
|
+
const clean = html.replace(/<script\b[^>]*\bdata-stx-server-data\b[^>]*>[\s\S]*?<\/script>/gi, ""), tag = serverDataTag(context);
|
|
52
|
+
if (!tag)
|
|
53
|
+
return clean;
|
|
54
|
+
const head = clean.indexOf("</head>");
|
|
55
|
+
return head < 0 ? tag + clean : clean.slice(0, head) + tag + clean.slice(head);
|
|
56
|
+
};
|
|
48
57
|
if (action.redirect)
|
|
49
58
|
return { html: compiled.html, context, redirect: action.redirect, cookies: action.cookies };
|
|
50
59
|
if (!hasPlaceholders(compiled.html))
|
|
51
|
-
return { html: compiled.html, context, cookies: action.cookies };
|
|
60
|
+
return { html: withServerData(compiled.html), context, cookies: action.cookies };
|
|
52
61
|
const values = new Map;
|
|
53
62
|
for (const [token, info] of Object.entries(compiled.placeholders))
|
|
54
63
|
if (info.expression)
|
|
@@ -58,10 +67,12 @@ async function runHydration(compiled, requestContext) {
|
|
|
58
67
|
values.set(token, value !== void 0 && value !== null ? String(value) : "");
|
|
59
68
|
else
|
|
60
69
|
values.set(token, value !== void 0 && value !== null ? escapeHtmlValue(String(value)) : "");
|
|
61
|
-
} catch {
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (requestContext.__stx_strict_hydration)
|
|
72
|
+
throw error;
|
|
62
73
|
values.set(token, "");
|
|
63
74
|
}
|
|
64
|
-
return { html: replacePlaceholders(compiled.html, values), context, cookies: action.cookies };
|
|
75
|
+
return { html: withServerData(replacePlaceholders(compiled.html, values)), context, cookies: action.cookies };
|
|
65
76
|
}
|
|
66
77
|
export async function hydrateFragment(compiled, requestContext = {}) {
|
|
67
78
|
if (!compiled.hasServerScripts && !hasPlaceholders(compiled.fragment))
|
package/dist/typecheck.d.ts
CHANGED
package/dist/typecheck.js
CHANGED
|
@@ -4,6 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { listComposableModules } from "./composable-loader.js";
|
|
5
5
|
import { STX_RUNTIME_GLOBALS } from "./runtime-globals.js";
|
|
6
6
|
import { stateDir } from "./state-dir.js";
|
|
7
|
+
import { loadStxConfig } from "./config.js";
|
|
7
8
|
import {
|
|
8
9
|
absolutizeRelativeSpecifiers,
|
|
9
10
|
buildVirtualTypeScript,
|
|
@@ -189,7 +190,7 @@ function readProjectPathAliases(startDir) {
|
|
|
189
190
|
return { paths: absolute };
|
|
190
191
|
}
|
|
191
192
|
export async function typecheckStxFiles(files, options = {}) {
|
|
192
|
-
const checkClient = options.client !== !1, checkServer = options.server !== !1, checkTemplates = options.templates !== !1, virtualFiles = new Map, scrapedByFile = new Map, checkedFiles = [];
|
|
193
|
+
const checkClient = options.client !== !1, checkServer = options.server !== !1, checkTemplates = options.templates !== !1, componentsDir = options.componentsDir ?? (checkTemplates ? (await loadStxConfig()).componentsDir : void 0), virtualFiles = new Map, scrapedByFile = new Map, checkedFiles = [];
|
|
193
194
|
let blockCount = 0, expressionCount = 0;
|
|
194
195
|
const runtimeTypes = findRuntimeTypeDeclarations();
|
|
195
196
|
for (const file of files) {
|
|
@@ -204,7 +205,7 @@ export async function typecheckStxFiles(files, options = {}) {
|
|
|
204
205
|
if (names.length > 0)
|
|
205
206
|
scrapedByFile.set(file, { names, line: clientBlocks[0].startLine, kind: clientBlocks[0].kind });
|
|
206
207
|
}
|
|
207
|
-
const originDir = path.dirname(path.resolve(file)), templateBuffer = checkTemplates ? buildVirtualTypeScript(source, { runtimeGlobals: !runtimeTypes, originDir }) : null, expressions = templateBuffer ? [...templateBuffer.lineMap.values()].filter((m) => m.expression).length : 0;
|
|
208
|
+
const originDir = path.dirname(path.resolve(file)), templateBuffer = checkTemplates ? buildVirtualTypeScript(source, { runtimeGlobals: !runtimeTypes, originDir, filePath: path.resolve(file), componentsDir }) : null, expressions = templateBuffer ? [...templateBuffer.lineMap.values()].filter((m) => m.expression).length : 0;
|
|
208
209
|
if (blocks.length === 0 && expressions === 0)
|
|
209
210
|
continue;
|
|
210
211
|
checkedFiles.push(file);
|
|
@@ -286,7 +287,7 @@ export async function typecheckStxFiles(files, options = {}) {
|
|
|
286
287
|
const ambientBasenames = new Set(ambient.map((lib) => lib.split("/").pop()));
|
|
287
288
|
let ambientDiagnostics = 0;
|
|
288
289
|
const unparseable = new Set, parseTscOutput = (text) => {
|
|
289
|
-
for (const rawLine of text.split(`
|
|
290
|
+
for (const rawLine of text.replace(/\n[\t ]+([^\n]*)/g, " $1").split(`
|
|
290
291
|
`)) {
|
|
291
292
|
const m = rawLine.match(TSC_LINE_RE);
|
|
292
293
|
if (!m)
|
|
@@ -8,6 +8,8 @@ import type { PwaConfig } from './pwa-types';
|
|
|
8
8
|
import type { CspConfig } from './csp-types';
|
|
9
9
|
import type { HeatmapConfig } from '../heatmap';
|
|
10
10
|
import type { MediaConfig } from '../media/types';
|
|
11
|
+
import type { RouteRules } from '../route-rules';
|
|
12
|
+
import type { ServerApiOptions } from '../server-api';
|
|
11
13
|
/**
|
|
12
14
|
* Internationalization (i18n) configuration
|
|
13
15
|
*/
|
|
@@ -842,6 +844,21 @@ export interface StxConfig {
|
|
|
842
844
|
* Handlers receive the standard Request and return a Response.
|
|
843
845
|
*/
|
|
844
846
|
apiRoutes?: Record<string, (request: Request) => Response | Promise<Response>>;
|
|
847
|
+
/** Per-route production rendering and anonymous origin-cache policies. */
|
|
848
|
+
routeRules?: RouteRules;
|
|
849
|
+
/** Opt-in file-based API endpoints, relative to the config/project directory. */
|
|
850
|
+
serverApi?: boolean | ServerApiOptions;
|
|
851
|
+
/** Deployment-time values. Only public is serialized for browsers. */
|
|
852
|
+
runtimeConfig?: import('../runtime-config-server').RuntimeConfigDefaults;
|
|
853
|
+
/** Local paths or installed application-layer packages, highest priority first. */
|
|
854
|
+
extends?: string[];
|
|
855
|
+
/** @internal Resolved application-layer provenance and resource search roots. */
|
|
856
|
+
_layerGraph?: import('../application-layers').ApplicationLayerGraph;
|
|
857
|
+
_layerPageDirs?: string[];
|
|
858
|
+
_layerComponentDirs?: string[];
|
|
859
|
+
_layerLayoutDirs?: string[];
|
|
860
|
+
_layerPartialDirs?: string[];
|
|
861
|
+
_layerComposableDirs?: string[];
|
|
845
862
|
/**
|
|
846
863
|
* Client-side router configuration
|
|
847
864
|
*/
|
package/dist/utils.js
CHANGED
|
@@ -20,6 +20,7 @@ import { processScopedStyles } from "./style-scoping.js";
|
|
|
20
20
|
import { findSfcTemplateBlock } from "./sfc-template.js";
|
|
21
21
|
import { importOnce } from "./lazy-module.js";
|
|
22
22
|
import { stashScriptElements } from "./html-masking.js";
|
|
23
|
+
import { markProjectedRefs } from "./misc-directives.js";
|
|
23
24
|
export {
|
|
24
25
|
extractDirectiveNames,
|
|
25
26
|
getPositionInfo,
|
|
@@ -421,6 +422,8 @@ export async function userComponentFileExists(componentPath, componentsDir, pare
|
|
|
421
422
|
push(path.resolve(configuredRoot, "src/components"));
|
|
422
423
|
push(path.resolve(configuredRoot, "components"));
|
|
423
424
|
}
|
|
425
|
+
for (const dir of options._layerComponentDirs ?? [])
|
|
426
|
+
push(dir);
|
|
424
427
|
const pluginDirs = options._pluginComponentDirs;
|
|
425
428
|
if (Array.isArray(pluginDirs))
|
|
426
429
|
for (const dir of pluginDirs)
|
|
@@ -456,7 +459,7 @@ export function slotContentHasExpressions(slotContent) {
|
|
|
456
459
|
return /\{\{[\s\S]*?\}\}|\{!![\s\S]*?!!\}/.test(withoutScripts);
|
|
457
460
|
}
|
|
458
461
|
export function componentClientSignalNames(scripts) {
|
|
459
|
-
const names = new Set, declaration = /\b(?:const|let|var)\s+([a-zA-Z_$][\w$]*)\s*=\s*(?:state|derived|computed|ref|reactive|signal|useReactiveProp|useLocalStorage|useSessionStorage|useCookie|useDebouncedValue)\s*(?:<[^>]*>)?\s*\(/g;
|
|
462
|
+
const names = new Set, declaration = /\b(?:const|let|var)\s+([a-zA-Z_$][\w$]*)\s*=\s*(?:state|derived|computed|ref|reactive|signal|useModel|useReactiveProp|useLocalStorage|useSessionStorage|useCookie|useDebouncedValue)\s*(?:<[^>]*>)?\s*\(/g;
|
|
460
463
|
for (const script of scripts) {
|
|
461
464
|
let match;
|
|
462
465
|
while ((match = declaration.exec(script)) !== null)
|
|
@@ -499,6 +502,7 @@ export async function renderComponentWithSlot(componentPath, props, slotContent,
|
|
|
499
502
|
`${kebabToPascal(baseName)}.stx`,
|
|
500
503
|
`${pascalToKebab(baseName)}.stx`
|
|
501
504
|
], uniqueVariants = [...new Set(fileVariants)], originalFilePath = parentContext.__originalFilePath, searchDirs = [];
|
|
505
|
+
searchDirs.push(...options._layerComponentDirs ?? []);
|
|
502
506
|
if (originalFilePath) {
|
|
503
507
|
const originalDir = path.join(path.dirname(originalFilePath), "components");
|
|
504
508
|
searchDirs.push(originalDir);
|
|
@@ -627,6 +631,7 @@ ${triedPaths.map((p) => ` - ${p}`).join(`
|
|
|
627
631
|
"__importedComponents",
|
|
628
632
|
COMPONENT_CLIENT_FACTORIES_CONTEXT_KEY,
|
|
629
633
|
"__stx_client_signal_names",
|
|
634
|
+
"__stx_runtime_config",
|
|
630
635
|
"__stxServeContext",
|
|
631
636
|
"__stx_scope_seq"
|
|
632
637
|
]), filteredParentContext = {};
|
|
@@ -678,6 +683,7 @@ ${triedPaths.map((p) => ` - ${p}`).join(`
|
|
|
678
683
|
slot: slotContent,
|
|
679
684
|
buildMode: options.buildMode ?? "",
|
|
680
685
|
skipEventDirectives: options.skipEventDirectives === !0,
|
|
686
|
+
layers: options._layerGraph?.layers.map((layer) => layer.configFile),
|
|
681
687
|
uid: componentUid
|
|
682
688
|
});
|
|
683
689
|
if (serializedInput !== null) {
|
|
@@ -745,9 +751,12 @@ ${triedPaths.map((p) => ` - ${p}`).join(`
|
|
|
745
751
|
}
|
|
746
752
|
if (slotContent && templateContent.includes("{{ text || slot }}"))
|
|
747
753
|
templateContent = templateContent.replace(/\{\{\s*text\s*\|\|\s*slot\s*\}\}/g, () => slotContent);
|
|
748
|
-
const { applySlots } = await importOnce("stx/slots", () => import("./slots.js")), { defaultSlot, namedSlots } = parsedSlotContent
|
|
749
|
-
|
|
750
|
-
|
|
754
|
+
const { applySlots } = await importOnce("stx/slots", () => import("./slots.js")), { defaultSlot, namedSlots } = parsedSlotContent, hasSignalScripts = clientScripts.some((s) => /\b(?:state|derived|effect|ref|useRef|reactive|computed|watch|watchEffect|useModel|useReactiveProp|defineProps|withDefaults|defineEmits|defineExpose|defineSlots)\s*(?:<[^<>()]*>)?\s*\(/.test(s)), projectRefs = (content) => hasSignalScripts ? markProjectedRefs(content, componentUid) : content, projectedSlots = new Map([...namedSlots].map(([name, slot]) => [name, {
|
|
755
|
+
...slot,
|
|
756
|
+
content: projectRefs(slot.content)
|
|
757
|
+
}]));
|
|
758
|
+
templateContent = await applySlots(templateContent, projectRefs(defaultSlot), projectedSlots, componentContext);
|
|
759
|
+
const clientSignalNames = componentClientSignalNames(clientScripts), inheritedClientSignalNames = Array.isArray(componentContext.__stx_client_signal_names) ? componentContext.__stx_client_signal_names : [];
|
|
751
760
|
if (clientSignalNames.length > 0 || inheritedClientSignalNames.length > 0)
|
|
752
761
|
componentContext.__stx_client_signal_names = [...new Set([...inheritedClientSignalNames, ...clientSignalNames])];
|
|
753
762
|
const componentOptions = {
|
|
@@ -857,7 +866,7 @@ export async function resolveTemplatePath(templatePath, currentFilePath, options
|
|
|
857
866
|
const safeUnderCwd = assertInsideRoot(result, process.cwd());
|
|
858
867
|
if (safeUnderCwd)
|
|
859
868
|
return safeUnderCwd;
|
|
860
|
-
const trustedDirs = [options.root, options.layoutsDir, options.fallbackLayoutsDir, options.componentsDir, options.partialsDir, options.pagesDir].filter((d) => typeof d === "string" && d.length > 0);
|
|
869
|
+
const trustedDirs = [options.root, options.layoutsDir, options.fallbackLayoutsDir, options.componentsDir, options.partialsDir, options.pagesDir, ...options._layerLayoutDirs ?? []].filter((d) => typeof d === "string" && d.length > 0);
|
|
861
870
|
for (const dir of trustedDirs) {
|
|
862
871
|
const resolvedDir = path.isAbsolute(dir) ? dir : path.resolve(process.cwd(), dir);
|
|
863
872
|
if (assertInsideRoot(result, resolvedDir))
|
|
@@ -902,6 +911,7 @@ async function resolveTemplatePathInner(templatePath, currentFilePath, options,
|
|
|
902
911
|
}
|
|
903
912
|
}
|
|
904
913
|
const layoutSearchDirs = [];
|
|
914
|
+
layoutSearchDirs.push(...options._layerLayoutDirs ?? []);
|
|
905
915
|
if (options.layoutsDir)
|
|
906
916
|
layoutSearchDirs.push(path.isAbsolute(options.layoutsDir) ? options.layoutsDir : path.resolve(process.cwd(), options.layoutsDir));
|
|
907
917
|
let searchDir = path.resolve(dirPath);
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* generated `await import('stx')` rejected and the shadowing binding was never
|
|
20
20
|
* created. The failure needed a real install to appear.
|
|
21
21
|
*/
|
|
22
|
-
export declare const STX_ENGINE_BINDING_NAMES: readonly ['module', 'exports', 'require', 'props', '$props', 'defineProps', 'withDefaults', 'defineClientPayload', 'state', 'derived', 'effect', 'batch', 'onMount', 'onDestroy', 'definePageMeta', 'useRoute', 'useRouter', 'useHead', 'useSeoMeta', 'setResponseStatus', 'setResponseHeader', 'notFound', 'ref', 'reactive', 'computed', 'watch', 'onMounted', 'onUnmounted', 'nextTick', 'defineEmits', 'defineExpose', 'defineSlots', 'provide', 'inject', 'useColorMode', 'useDark', 'useMediaQuery', 'useScrollLock', 'usePreferredDark', 'usePreferredLight', 'usePreferredReducedMotion', 'usePreferredContrast', 'window', 'document', 'console', 'confirm', 'alert', 'fetch', 'params'];
|
|
22
|
+
export declare const STX_ENGINE_BINDING_NAMES: readonly ['module', 'exports', 'require', 'props', '$props', 'defineProps', 'withDefaults', 'defineClientPayload', 'useServerData', 'useRuntimeConfig', 'useServerRuntimeConfig', 'state', 'derived', 'effect', 'batch', 'onMount', 'onDestroy', 'definePageMeta', 'useRoute', 'useRouter', 'useHead', 'useSeoMeta', 'setResponseStatus', 'setResponseHeader', 'notFound', 'ref', 'reactive', 'computed', 'watch', 'onMounted', 'onUnmounted', 'nextTick', 'defineEmits', 'defineExpose', 'defineSlots', 'provide', 'inject', 'useColorMode', 'useDark', 'useMediaQuery', 'useScrollLock', 'usePreferredDark', 'usePreferredLight', 'usePreferredReducedMotion', 'usePreferredContrast', 'window', 'document', 'console', 'confirm', 'alert', 'fetch', 'params'];
|
|
23
23
|
/**
|
|
24
24
|
* Strip TypeScript-specific syntax to make it executable as JavaScript
|
|
25
25
|
*
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
var {require}=import.meta;import path from "node:path";
|
|
2
2
|
import process from "node:process";
|
|
3
|
+
import { useServerData, withServerData } from "./server-data.js";
|
|
4
|
+
import { prepareRuntimeConfig } from "./runtime-config-loader.js";
|
|
5
|
+
import { currentRuntimeConfig, resolveRuntimeConfig, useRuntimeConfig, useServerRuntimeConfig, withRuntimeConfig } from "./runtime-config-server.js";
|
|
3
6
|
import { getSharedTranspiler } from "./utils.js";
|
|
4
7
|
export const STX_ENGINE_BINDING_NAMES = [
|
|
5
8
|
"module",
|
|
@@ -10,6 +13,9 @@ export const STX_ENGINE_BINDING_NAMES = [
|
|
|
10
13
|
"defineProps",
|
|
11
14
|
"withDefaults",
|
|
12
15
|
"defineClientPayload",
|
|
16
|
+
"useServerData",
|
|
17
|
+
"useRuntimeConfig",
|
|
18
|
+
"useServerRuntimeConfig",
|
|
13
19
|
"state",
|
|
14
20
|
"derived",
|
|
15
21
|
"effect",
|
|
@@ -525,7 +531,10 @@ export async function extractVariables(scriptContent, context, filePath, options
|
|
|
525
531
|
scriptFn = Function(...scriptParams, scriptBody);
|
|
526
532
|
compiledServerScripts.set(compileKey, scriptFn);
|
|
527
533
|
}
|
|
528
|
-
const
|
|
534
|
+
const hostRuntimeConfig = context.__stx_options?.runtimeConfig;
|
|
535
|
+
if (hostRuntimeConfig || /\buse(?:Server)?RuntimeConfig\b/.test(jsContent))
|
|
536
|
+
await prepareRuntimeConfig(context, filePath, hostRuntimeConfig);
|
|
537
|
+
const result = await withRuntimeConfig(context.__stx_runtime_config ?? currentRuntimeConfig() ?? resolveRuntimeConfig(), () => withServerData(context, () => scriptFn(module, exports, requireFn, propsObj, $props, defineProps, withDefaults, defineClientPayload, useServerData, useRuntimeConfig, useServerRuntimeConfig, state, derived, effect, batch, onMount, onDestroy, definePageMeta, useRoute, useRouter, useHead, useSeoMeta, responseApi.setResponseStatus, responseApi.setResponseHeader, responseApi.notFound, ref, reactive, computed, watch, onMounted, onUnmounted, nextTick, defineEmits, defineExpose, defineSlots, provide, inject, useColorMode, useDark, useMediaQuery, useScrollLock, usePreferredDark, usePreferredLight, usePreferredReducedMotion, usePreferredContrast, windowProxy, mockDocument, mockConsole, mockWindow.confirm, mockWindow.alert, mockWindow.fetch, paramsObj, ...propArgValues, ...scriptContextValues)));
|
|
529
538
|
if (options.preserveExisting) {
|
|
530
539
|
for (const [key, value] of Object.entries(result))
|
|
531
540
|
if (!(key in context) || context[key] === void 0)
|
|
@@ -536,6 +545,8 @@ export async function extractVariables(scriptContent, context, filePath, options
|
|
|
536
545
|
if (!(key in context))
|
|
537
546
|
context[key] = value;
|
|
538
547
|
} catch (primaryError) {
|
|
548
|
+
if (context.__stx_strict_hydration)
|
|
549
|
+
throw primaryError;
|
|
539
550
|
const msg = primaryError instanceof Error ? primaryError.message : String(primaryError);
|
|
540
551
|
if (isModuleResolutionFailure(msg))
|
|
541
552
|
console.warn(`[stx] server <script> in ${filePath ?? "<unknown>"} imports a module that does not resolve, so every variable in that script is undefined. Cause: ${msg}`);
|
package/dist/visual-testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-
|
|
2
|
+
import"./chunk-jp2f8yzw.js";import B from"fs";import $ from"path";import k from"crypto";var V=[{name:"mobile",width:375,height:667,isMobile:!0,hasTouch:!0},{name:"tablet",width:768,height:1024,isMobile:!0,hasTouch:!0},{name:"desktop",width:1280,height:800,isMobile:!1,hasTouch:!1},{name:"wide",width:1920,height:1080,isMobile:!1,hasTouch:!1}];function J(N={}){let Y={snapshotDir:N.snapshotDir||"__snapshots__",screenshotDir:N.screenshotDir||"__screenshots__",updateSnapshots:N.updateSnapshots||process.env.UPDATE_SNAPSHOTS==="true",threshold:N.threshold??0.01,viewports:N.viewports||V,generateDiff:N.generateDiff??!0,diffDir:N.diffDir||"__diffs__",compare:N.compare||b,ci:N.ci??process.env.CI==="true",retries:N.retries??(N.ci?3:1)};return{async snapshot(M,X){let q=$.join(Y.snapshotDir,`${X}.html`),G=C(M),Q=K(G);if(await Bun.file(q).exists()){let W=await Bun.file(q).text(),Z=K(C(W));if(Q===Z)return{passed:!0,snapshotPath:q,message:"Snapshot matches"};if(Y.updateSnapshots)return await B.promises.mkdir($.dirname(q),{recursive:!0}),await Bun.write(q,G),{passed:!0,snapshotPath:q,message:"Snapshot updated"};let F=$.join(Y.diffDir,`${X}.actual.html`),U=$.join(Y.diffDir,`${X}.diff.html`);return await B.promises.mkdir(Y.diffDir,{recursive:!0}),await Bun.write(F,G),await Bun.write(U,I(W,G)),{passed:!1,snapshotPath:q,actualPath:F,diffPath:U,message:"Snapshot does not match"}}return await B.promises.mkdir($.dirname(q),{recursive:!0}),await Bun.write(q,G),{passed:!0,snapshotPath:q,message:"New snapshot created"}},async snapshotJson(M,X){let q=$.join(Y.snapshotDir,`${X}.json`),G=JSON.stringify(M,null,2);if(await Bun.file(q).exists()){let Q=await Bun.file(q).text();if(G===Q)return{passed:!0,snapshotPath:q};if(Y.updateSnapshots)return await Bun.write(q,G),{passed:!0,snapshotPath:q,message:"Snapshot updated"};return{passed:!1,snapshotPath:q,message:`JSON snapshot mismatch:
|
|
3
3
|
${z(Q,G)}`}}return await B.promises.mkdir($.dirname(q),{recursive:!0}),await Bun.write(q,G),{passed:!0,snapshotPath:q,message:"New snapshot created"}},matchInlineSnapshot(M,X){let q=C(M);if(X===void 0)return{passed:!0,expected:q};let G=C(X);return{passed:q===G,expected:q}},getConfig(){return Y}}}function D(N={}){let Y=J(N),M=Y.getConfig();return{async compareScreenshots(X,q,G="desktop"){let Q=$.join(M.screenshotDir,G,`${X}.png`),W=$.join(M.diffDir,G,`${X}.actual.png`),Z=$.join(M.diffDir,G,`${X}.diff.png`);if(await Bun.file(Q).exists()){let F=await Bun.file(Q).arrayBuffer(),U=Buffer.from(F),_=await M.compare(q,U);if(_.match||_.diffPercentage<=M.threshold)return{viewport:G,passed:!0,baselinePath:Q};if(M.updateSnapshots)return await B.promises.mkdir($.dirname(Q),{recursive:!0}),await Bun.write(Q,q),{viewport:G,passed:!0,baselinePath:Q};if(await B.promises.mkdir($.dirname(W),{recursive:!0}),await Bun.write(W,q),_.diffImage&&M.generateDiff)await Bun.write(Z,_.diffImage);return{viewport:G,passed:!1,baselinePath:Q,actualPath:W,diffPath:M.generateDiff?Z:void 0,diffPercentage:_.diffPercentage}}return await B.promises.mkdir($.dirname(Q),{recursive:!0}),await Bun.write(Q,q),{viewport:G,passed:!0,baselinePath:Q}},async testViewports(X,q,G=M.viewports){let Q=[];for(let W of G){let Z=null;for(let F=0;F<M.retries;F++)try{let U=await q(W),_=await this.compareScreenshots(X,U,W.name);Q.push(_),Z=null;break}catch(U){if(Z=U,F<M.retries-1)await new Promise((_)=>setTimeout(_,100*(F+1)))}if(Z)Q.push({viewport:W.name,passed:!1,baselinePath:"",diffPercentage:100})}return Q},getSnapshotTester(){return Y}}}function L(N={}){let M=D(N).getSnapshotTester(),X=new Map;return{addStory(q){X.set(`${q.component}/${q.name}`,q)},addStories(q){for(let G of q)this.addStory(G)},getStories(){return Array.from(X.values())},getStoriesForComponent(q){return Array.from(X.values()).filter((G)=>G.component===q)},async testStory(q){let G=X.get(q);if(!G)return{name:q,passed:!1,duration:0,snapshots:[],screenshots:[],errors:[Error(`Story not found: ${q}`)]};let Q=Date.now(),W={name:q,passed:!0,duration:0,snapshots:[],screenshots:[],errors:[]};try{let Z=await G.render(),F=await M.snapshot(Z,q.replace(/\//g,"-"));if(W.snapshots.push(F),!F.passed)W.passed=!1}catch(Z){W.passed=!1,W.errors.push(Z)}return W.duration=Date.now()-Q,W},async testAllStories(){let q=[];for(let G of X.keys()){let Q=await this.testStory(G);q.push(Q)}return q},async generateStoryIndex(){let q={};for(let G of X.values()){if(!q[G.component])q[G.component]=[];q[G.component].push({name:G.name,args:G.args})}return JSON.stringify(q,null,2)}}}async function S(N,Y={}){let M={outputDir:Y.outputDir||"visual-test-report",format:Y.format||"html",title:Y.title||"Visual Test Report",includeScreenshots:Y.includeScreenshots??!0};await B.promises.mkdir(M.outputDir,{recursive:!0});let X=N.length,q=N.filter((F)=>F.passed).length,G=X-q,Q=N.reduce((F,U)=>F+U.duration,0);if(M.format==="json"){let F={title:M.title,summary:{total:X,passed:q,failed:G,duration:Q},results:N,generatedAt:new Date().toISOString()},U=$.join(M.outputDir,"report.json");return await Bun.write(U,JSON.stringify(F,null,2)),U}if(M.format==="markdown"){let F=`# ${M.title}
|
|
4
4
|
|
|
5
5
|
`;F+=`## Summary
|
package/dist/vue-template.js
CHANGED
|
@@ -330,50 +330,28 @@ function transformVModel(html) {
|
|
|
330
330
|
const tag = findNextOpenTag(result, searchFrom);
|
|
331
331
|
if (!tag)
|
|
332
332
|
break;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
result = result.slice(0, range.outerStart) + newElement + result.slice(range.outerEnd);
|
|
350
|
-
searchFrom = range.outerStart + newElement.length;
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
const modelValue = extractDirectiveValue(tag.attrs, "v-model");
|
|
354
|
-
if (modelValue === null) {
|
|
333
|
+
const isNative = NATIVE_ELEMENTS.has(tag.tag), newAttrs = tag.attrs.replace(/([^\s=]+)(?:\s*=\s*("[^"]*"|'[^']*'|[^\s]+))?/g, (attribute, name, value) => {
|
|
334
|
+
const model = /^v-model(?::([a-zA-Z_][a-zA-Z0-9_]*))?((?:\.[a-zA-Z]+)*)$/.exec(name);
|
|
335
|
+
if (!model || !value || !/^["']/.test(value))
|
|
336
|
+
return attribute;
|
|
337
|
+
const prop = model[1] || "modelValue", suffix = model[2];
|
|
338
|
+
if (isNative && !model[1])
|
|
339
|
+
return `@model${suffix}=${value}`;
|
|
340
|
+
const quote = value[0], expression = value.slice(1, -1);
|
|
341
|
+
let binding = `:${prop}=${value} @update:${prop}=${quote}${expression} = $event${quote}`;
|
|
342
|
+
if (suffix) {
|
|
343
|
+
const modifierProp = model[1] ? `${prop}Modifiers` : "modelModifiers", modifiers = suffix.slice(1).split(".").map((modifier) => `${modifier}: true`).join(", ");
|
|
344
|
+
binding += ` :${modifierProp}="{ ${modifiers} }"`;
|
|
345
|
+
}
|
|
346
|
+
return binding;
|
|
347
|
+
});
|
|
348
|
+
if (newAttrs === tag.attrs) {
|
|
355
349
|
searchFrom = tag.end;
|
|
356
350
|
continue;
|
|
357
351
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
start: 0,
|
|
362
|
-
end: tag.end - tag.start
|
|
363
|
-
}, newAttrs);
|
|
364
|
-
result = result.slice(0, range.outerStart) + newElement + result.slice(range.outerEnd);
|
|
365
|
-
searchFrom = range.outerStart + newElement.length;
|
|
366
|
-
} else {
|
|
367
|
-
let newAttrs = tag.attrs.replace(/\s*v-model="[^"]*"/g, "");
|
|
368
|
-
newAttrs += ` :modelValue="${modelValue}" @update:modelValue="${modelValue} = $event"`;
|
|
369
|
-
const range = getElementRange(result, tag), element = result.slice(range.outerStart, range.outerEnd), newElement = replaceTagAttrs(element, {
|
|
370
|
-
...tag,
|
|
371
|
-
start: 0,
|
|
372
|
-
end: tag.end - tag.start
|
|
373
|
-
}, newAttrs);
|
|
374
|
-
result = result.slice(0, range.outerStart) + newElement + result.slice(range.outerEnd);
|
|
375
|
-
searchFrom = range.outerStart + newElement.length;
|
|
376
|
-
}
|
|
352
|
+
const opening = replaceTagAttrs(tag.full, { ...tag, start: 0, end: tag.full.length }, newAttrs);
|
|
353
|
+
result = result.slice(0, tag.start) + opening + result.slice(tag.end);
|
|
354
|
+
searchFrom = tag.start + opening.length;
|
|
377
355
|
}
|
|
378
356
|
return result;
|
|
379
357
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.305",
|
|
5
5
|
"description": "A performant UI Framework. Powered by Bun.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -117,12 +117,12 @@
|
|
|
117
117
|
"dependencies": {
|
|
118
118
|
"@stacksjs/ts-css": "^0.3.2",
|
|
119
119
|
"@stacksjs/clapp": "^0.2.14",
|
|
120
|
-
"@stacksjs/desktop": "0.2.
|
|
121
|
-
"@stacksjs/sanitizer": "0.2.
|
|
120
|
+
"@stacksjs/desktop": "0.2.305",
|
|
121
|
+
"@stacksjs/sanitizer": "0.2.305",
|
|
122
122
|
"@stacksjs/ts-i18n": "^0.1.11",
|
|
123
|
-
"bun-plugin-stx": "0.2.
|
|
123
|
+
"bun-plugin-stx": "0.2.305",
|
|
124
124
|
"bunfig": "^0.15.17",
|
|
125
|
-
"stx-router": "0.2.
|
|
125
|
+
"stx-router": "0.2.305",
|
|
126
126
|
"ts-broadcasting": "^0.0.9",
|
|
127
127
|
"ts-images": "^0.2.18",
|
|
128
128
|
"ts-syntax-highlighter": "^0.2.1"
|
package/stx.d.ts
CHANGED
|
@@ -116,6 +116,21 @@ declare function useReactiveProp<T = unknown>(
|
|
|
116
116
|
_defaultValue?: T,
|
|
117
117
|
_options?: { parse?: (_value: string) => T },
|
|
118
118
|
): StxSignal<T>
|
|
119
|
+
interface StxModelOptions<T> {
|
|
120
|
+
default?: T
|
|
121
|
+
parse?: (value: string) => T
|
|
122
|
+
get?: (value: T) => T
|
|
123
|
+
set?: (value: T, modifiers: Readonly<Record<string, boolean>>) => T
|
|
124
|
+
}
|
|
125
|
+
interface StxModelSignal<T> extends StxSignal<T> {
|
|
126
|
+
readonly modifiers: Readonly<Record<string, boolean>>
|
|
127
|
+
input(value: T): void
|
|
128
|
+
change(value: T): void
|
|
129
|
+
}
|
|
130
|
+
declare function useModel<T>(options: StxModelOptions<T> & { default: T }): StxModelSignal<T>
|
|
131
|
+
declare function useModel<T>(name: string, options: StxModelOptions<T> & { default: T }): StxModelSignal<T>
|
|
132
|
+
declare function useModel<T = unknown>(name?: string, options?: StxModelOptions<T>): StxModelSignal<T | undefined>
|
|
133
|
+
declare function useModel<T = unknown>(options?: StxModelOptions<T>): StxModelSignal<T | undefined>
|
|
119
134
|
/**
|
|
120
135
|
* A template ref. Read it however the surrounding code reads things: `ref()`
|
|
121
136
|
* like every other stx accessor, or `ref.current` / `ref.value` for the
|
|
@@ -268,6 +283,10 @@ interface StxMutationResult<T> {
|
|
|
268
283
|
}
|
|
269
284
|
|
|
270
285
|
declare function useFetch<T = any>(_url: string, _options?: any): StxFetchResult<T>
|
|
286
|
+
/** Server-only, keyed JSON data exposed to this render's client hydration. */
|
|
287
|
+
declare function useServerData<T>(_key: string, _loader: () => T | Promise<T>): Promise<T>
|
|
288
|
+
/** Clear a hydration snapshot without changing existing signals. */
|
|
289
|
+
declare function clearServerData(_key?: string): void
|
|
271
290
|
declare function useQuery<T = any>(_url: string, _options?: any): StxQueryResult<T>
|
|
272
291
|
declare function useMutation<T = any>(_url: string, _options?: any): StxMutationResult<T>
|
|
273
292
|
|
|
@@ -314,6 +333,13 @@ declare function configureFetch(_config: {
|
|
|
314
333
|
onRequest?: (_ctx: StxFetchRequestContext) => void | Promise<void>
|
|
315
334
|
onResponse?: (_ctx: StxFetchResponseContext) => void | Promise<void>
|
|
316
335
|
onResponseError?: (_ctx: StxFetchErrorContext) => void | Response | Promise<void | Response>
|
|
336
|
+
/**
|
|
337
|
+
* Double-submit CSRF. By default every same-origin POST/PUT/PATCH/DELETE
|
|
338
|
+
* repeats the `X-CSRF-Token` cookie in an `X-CSRF-Token` header, which is
|
|
339
|
+
* what a Stacks server checks. Rename either side, or pass `false` to stop.
|
|
340
|
+
* Unlike the hooks, this persists across calls that do not mention it.
|
|
341
|
+
*/
|
|
342
|
+
csrf?: false | { cookie?: string, header?: string }
|
|
317
343
|
}): void
|
|
318
344
|
|
|
319
345
|
declare function useOptimistic<T = any, A = any>(
|
|
@@ -826,6 +852,7 @@ interface StxRuntimeRegistry {
|
|
|
826
852
|
|
|
827
853
|
// Composables
|
|
828
854
|
useFetch: typeof useFetch
|
|
855
|
+
clearServerData: typeof clearServerData
|
|
829
856
|
useRef: typeof useRef
|
|
830
857
|
useQuery: typeof useQuery
|
|
831
858
|
useMutation: typeof useMutation
|
|
@@ -872,6 +899,7 @@ interface StxRuntimeRegistry {
|
|
|
872
899
|
useClickOutside: typeof useClickOutside
|
|
873
900
|
useFocus: typeof useFocus
|
|
874
901
|
useAsync: typeof useAsync
|
|
902
|
+
useModel: typeof useModel
|
|
875
903
|
useLocalStorage: typeof useLocalStorage
|
|
876
904
|
useSessionStorage: typeof useSessionStorage
|
|
877
905
|
useEventListener: typeof useEventListener
|
package/dist/chunk-0p44z42s.js
DELETED
package/dist/chunk-2jd9bxmf.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{Ep as b,Fp as c,Gp as d,Hp as e,eo as a}from"./chunk-rsxmjfxq.js";import"./chunk-m6wz1hf5.js";import"./chunk-dcxtrqfy.js";import"./chunk-jj6yp7gm.js";import"./chunk-qjkzpd68.js";import"./chunk-2rp09y5j.js";import"./chunk-whm6bybj.js";import"./chunk-q25mr70f.js";import"./chunk-jsfch50r.js";import"./chunk-6b4k8fay.js";import"./chunk-jb2r696a.js";import"./chunk-k5xtf38q.js";import"./chunk-0tbgvp70.js";import"./chunk-xdq52pwj.js";import"./chunk-ddqkj56r.js";export{d as validateClientScript,c as processOnceDirective,b as processJsonDirective,e as processDirectives,a as injectRouterScript};
|
package/dist/chunk-2yp8ang5.js
DELETED
package/dist/chunk-35x7s4cr.js
DELETED