release: WRNexusJS 0.2.46

This commit is contained in:
2026-07-15 20:09:47 +05:30
parent 8a8328a308
commit 973d580bc5
58 changed files with 453 additions and 147 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/ai", "name": "@wrnexus/ai",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "Zero-dependency Claude (Anthropic) client for WrNexus apps.", "description": "Zero-dependency Claude (Anthropic) client for WrNexus apps.",
"license": "MIT", "license": "MIT",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/authz", "name": "@wrnexus/authz",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/authz — part of the WrNexus framework.", "description": "@wrnexus/authz — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+11 -11
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/cli", "name": "@wrnexus/cli",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/cli — part of the WrNexus framework.", "description": "@wrnexus/cli — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
@@ -28,16 +28,16 @@
"wrnexus": "./dist/index.js" "wrnexus": "./dist/index.js"
}, },
"dependencies": { "dependencies": {
"@wrnexus/core": "^0.2.45", "@wrnexus/core": "^0.2.46",
"@wrnexus/router": "^0.2.45", "@wrnexus/router": "^0.2.46",
"@wrnexus/csr": "^0.2.45", "@wrnexus/csr": "^0.2.46",
"@wrnexus/compiler": "^0.2.45", "@wrnexus/compiler": "^0.2.46",
"@wrnexus/styles": "^0.2.45", "@wrnexus/styles": "^0.2.46",
"@wrnexus/dev-server": "^0.2.45", "@wrnexus/dev-server": "^0.2.46",
"@wrnexus/ui": "^0.2.45", "@wrnexus/ui": "^0.2.46",
"@wrnexus/validation": "^0.2.45", "@wrnexus/validation": "^0.2.46",
"@wrnexus/i18n": "^0.2.45", "@wrnexus/i18n": "^0.2.46",
"@wrnexus/db": "^0.2.45" "@wrnexus/db": "^0.2.46"
}, },
"files": [ "files": [
"dist" "dist"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/compiler", "name": "@wrnexus/compiler",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/compiler — part of the WrNexus framework.", "description": "@wrnexus/compiler — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/core", "name": "@wrnexus/core",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/core — part of the WrNexus framework.", "description": "@wrnexus/core — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/csr", "name": "@wrnexus/csr",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/csr — part of the WrNexus framework.", "description": "@wrnexus/csr — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
@@ -21,7 +21,7 @@
} }
}, },
"dependencies": { "dependencies": {
"@wrnexus/core": "^0.2.45" "@wrnexus/core": "^0.2.46"
}, },
"files": [ "files": [
"dist" "dist"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/db", "name": "@wrnexus/db",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/db — part of the WrNexus framework.", "description": "@wrnexus/db — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+13 -13
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/dev-server", "name": "@wrnexus/dev-server",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/dev-server — part of the WrNexus framework.", "description": "@wrnexus/dev-server — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
@@ -25,18 +25,18 @@
} }
}, },
"dependencies": { "dependencies": {
"@wrnexus/core": "^0.2.45", "@wrnexus/core": "^0.2.46",
"@wrnexus/router": "^0.2.45", "@wrnexus/router": "^0.2.46",
"@wrnexus/ssr": "^0.2.45", "@wrnexus/ssr": "^0.2.46",
"@wrnexus/csr": "^0.2.45", "@wrnexus/csr": "^0.2.46",
"@wrnexus/compiler": "^0.2.45", "@wrnexus/compiler": "^0.2.46",
"@wrnexus/styles": "^0.2.45", "@wrnexus/styles": "^0.2.46",
"@wrnexus/ui": "^0.2.45", "@wrnexus/ui": "^0.2.46",
"@wrnexus/validation": "^0.2.45", "@wrnexus/validation": "^0.2.46",
"@wrnexus/i18n": "^0.2.45", "@wrnexus/i18n": "^0.2.46",
"@wrnexus/db": "^0.2.45", "@wrnexus/db": "^0.2.46",
"@wrnexus/pubsub": "^0.2.45", "@wrnexus/pubsub": "^0.2.46",
"@wrnexus/uploader": "^0.2.45" "@wrnexus/uploader": "^0.2.46"
}, },
"files": [ "files": [
"dist" "dist"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/encryption", "name": "@wrnexus/encryption",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/encryption — part of the WrNexus framework.", "description": "@wrnexus/encryption — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/helpers", "name": "@wrnexus/helpers",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "Safe convenience helpers for WrNexus request contexts and common application flows.", "description": "Safe convenience helpers for WrNexus request contexts and common application flows.",
"license": "MIT", "license": "MIT",
@@ -21,7 +21,7 @@
} }
}, },
"dependencies": { "dependencies": {
"@wrnexus/core": "^0.2.45" "@wrnexus/core": "^0.2.46"
}, },
"files": [ "files": [
"dist" "dist"
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/i18n", "name": "@wrnexus/i18n",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/i18n — part of the WrNexus framework.", "description": "@wrnexus/i18n — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
@@ -21,7 +21,7 @@
} }
}, },
"dependencies": { "dependencies": {
"@wrnexus/core": "^0.2.45" "@wrnexus/core": "^0.2.46"
}, },
"files": [ "files": [
"dist" "dist"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/jwt", "name": "@wrnexus/jwt",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/jwt — part of the WrNexus framework.", "description": "@wrnexus/jwt — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/mobile", "name": "@wrnexus/mobile",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/mobile — part of the WrNexus framework.", "description": "@wrnexus/mobile — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
@@ -21,7 +21,7 @@
} }
}, },
"dependencies": { "dependencies": {
"@wrnexus/native": "^0.2.45" "@wrnexus/native": "^0.2.46"
}, },
"files": [ "files": [
"dist" "dist"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/native", "name": "@wrnexus/native",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/native — part of the WrNexus framework.", "description": "@wrnexus/native — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/oauth", "name": "@wrnexus/oauth",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/oauth — part of the WrNexus framework.", "description": "@wrnexus/oauth — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/pubsub", "name": "@wrnexus/pubsub",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/pubsub — part of the WrNexus framework.", "description": "@wrnexus/pubsub — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/queue", "name": "@wrnexus/queue",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/queue — part of the WrNexus framework.", "description": "@wrnexus/queue — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/reactive", "name": "@wrnexus/reactive",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/reactive — part of the WrNexus framework.", "description": "@wrnexus/reactive — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+3 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/router", "name": "@wrnexus/router",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/router — part of the WrNexus framework.", "description": "@wrnexus/router — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
@@ -21,8 +21,8 @@
} }
}, },
"dependencies": { "dependencies": {
"@wrnexus/compiler": "^0.2.45", "@wrnexus/compiler": "^0.2.46",
"@wrnexus/core": "^0.2.45" "@wrnexus/core": "^0.2.46"
}, },
"files": [ "files": [
"dist" "dist"
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/ssr", "name": "@wrnexus/ssr",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/ssr — part of the WrNexus framework.", "description": "@wrnexus/ssr — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
@@ -21,7 +21,7 @@
} }
}, },
"dependencies": { "dependencies": {
"@wrnexus/core": "^0.2.45" "@wrnexus/core": "^0.2.46"
}, },
"files": [ "files": [
"dist" "dist"
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/styles", "name": "@wrnexus/styles",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/styles — part of the WrNexus framework.", "description": "@wrnexus/styles — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
@@ -21,7 +21,7 @@
} }
}, },
"dependencies": { "dependencies": {
"@wrnexus/uploader": "^0.2.45" "@wrnexus/uploader": "^0.2.46"
}, },
"files": [ "files": [
"dist" "dist"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/test", "name": "@wrnexus/test",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/test — part of the WrNexus framework.", "description": "@wrnexus/test — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/tracking", "name": "@wrnexus/tracking",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/tracking — part of the WrNexus framework.", "description": "@wrnexus/tracking — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/ui", "name": "@wrnexus/ui",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/ui — part of the WrNexus framework.", "description": "@wrnexus/ui — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
@@ -22,7 +22,7 @@
"./ui.css": "./ui.css" "./ui.css": "./ui.css"
}, },
"dependencies": { "dependencies": {
"@wrnexus/core": "^0.2.45" "@wrnexus/core": "^0.2.46"
}, },
"files": [ "files": [
"dist", "dist",
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/uploader", "name": "@wrnexus/uploader",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/uploader — part of the WrNexus framework.", "description": "@wrnexus/uploader — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
@@ -21,7 +21,7 @@
} }
}, },
"dependencies": { "dependencies": {
"@wrnexus/core": "^0.2.45" "@wrnexus/core": "^0.2.46"
}, },
"files": [ "files": [
"dist" "dist"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/validation", "name": "@wrnexus/validation",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"description": "@wrnexus/validation — part of the WrNexus framework.", "description": "@wrnexus/validation — part of the WrNexus framework.",
"license": "MIT", "license": "MIT",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/ai", "name": "@wrnexus/ai",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"description": "Zero-dependency Claude (Anthropic) client for WrNexus apps.", "description": "Zero-dependency Claude (Anthropic) client for WrNexus apps.",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/authz", "name": "@wrnexus/authz",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/cli", "name": "@wrnexus/cli",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+9
View File
@@ -483,6 +483,15 @@ const MIGRATIONS: Migration[] = [
// No generated application files require automatic migration. // No generated application files require automatic migration.
}, },
}, },
{
version: "0.2.46",
id: "conditions-bug",
description:
"Adds server-rendered component each/if blocks and fixes dynamic component rendering.",
apply() {
// No generated application files require automatic migration.
},
},
]; ];
/** Release tooling uses this to require an explicit migration entry per version. */ /** Release tooling uses this to require an explicit migration entry per version. */
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/compiler", "name": "@wrnexus/compiler",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+53 -14
View File
@@ -1303,7 +1303,9 @@ function generateComponent(ast: PageAst): string {
const scopeLine = const scopeLine =
needsScope && scopeKeys.length > 0 needsScope && scopeKeys.length > 0
? ` const __scope = __wrnexusScopeDecl({ ${scopeKeys.map((k) => `${JSON.stringify(k)}: ${nameRefs.get(k)}`).join(", ")} });\n` ? ` const __scope = __wrnexusScopeDecl({ ${scopeKeys
.map((key) => `${JSON.stringify(key)}: ${nameRefs.get(key)}`)
.join(", ")} });\n`
: needsScope : needsScope
? ` const __scope = "";\n` ? ` const __scope = "";\n`
: ""; : "";
@@ -1419,19 +1421,56 @@ function __wireRaw(v: any): string {
}`); }`);
if (needsScope) { if (needsScope) {
out.push(`function __wrnexusScopeDecl(obj: Record<string, any>): string { out.push(`function __wrnexusSerializeScopeValue(value: any): string {
const lit = (v: any) => if (value === undefined) {
typeof v === "number" || typeof v === "boolean" return "undefined";
? String(v) }
: "'" + String(v).replace(/\\\\/g, "\\\\\\\\").replace(/'/g, "\\\\'").replace(/\\n/g, "\\\\n") + "'";
return Object.keys(obj) if (value === null) {
.map((k) => k + ": " + lit(obj[k])) return "null";
.join(", ") }
.replace(/&/g, "&amp;")
.replace(/"/g, "&quot;") if (typeof value === "number") {
.replace(/</g, "&lt;") return Number.isFinite(value)
.replace(/>/g, "&gt;"); ? String(value)
}`); : "null";
}
if (typeof value === "boolean") {
return value ? "true" : "false";
}
if (typeof value === "string") {
return JSON.stringify(value);
}
try {
const serialized = JSON.stringify(value);
return serialized === undefined
? "undefined"
: serialized;
} catch {
return "null";
}
}
function __wrnexusScopeDecl(obj: Record<string, any>): string {
return Object.keys(obj)
.map(
(key) =>
key +
": " +
__wrnexusSerializeScopeValue(
obj[key],
),
)
.join(", ")
.replace(/&/g, "&amp;")
.replace(/"/g, "&quot;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}`);
} }
const serverFunctionSource = serverFunctions ? `${serverFunctions}\n` : ""; const serverFunctionSource = serverFunctions ? `${serverFunctions}\n` : "";
+9 -1
View File
@@ -98,10 +98,18 @@ test("stateful component: state text baked into a reactive data-text span, prop
); );
const render = mod.render as (p: Record<string, string>) => string; const render = mod.render as (p: Record<string, string>) => string;
const out = render({ start: "10", label: "Score" }); const out = render({ start: "10", label: "Score" });
expect(out).toContain("data-scope=\"start: 10, label: 'Score', count: 10\""); expect(out).toContain('data-scope="start: 10, label: &quot;Score&quot;, count: 10"');
expect(out).toContain('data-on-click="count++"'); expect(out).toContain('data-on-click="count++"');
// label baked as static text; count baked as its initial value AND kept live. // label baked as static text; count baked as its initial value AND kept live.
expect(out).toContain('Score: <span data-text="count">10</span>'); expect(out).toContain('Score: <span data-text="count">10</span>');
expect(out).toContain('data-scope="');
expect(out).toContain("start: 10");
expect(out).toContain("label: &quot;Score&quot;");
expect(out).toContain("count: 10");
}); });
test("prop type coercion follows the default value's type", async () => { test("prop type coercion follows the default value's type", async () => {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/core", "name": "@wrnexus/core",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/csr", "name": "@wrnexus/csr",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+251 -47
View File
@@ -43,6 +43,34 @@ export const REACTIVE_RUNTIME = String.raw`
}); });
} }
function decodeScopePayload(value) {
var binary = window.atob(value);
var bytes =
new Uint8Array(binary.length);
for (
var index = 0;
index < binary.length;
index++
) {
bytes[index] =
binary.charCodeAt(index);
}
var decoded =
new TextDecoder(
"utf-8",
).decode(bytes);
var parsed =
JSON.parse(decoded);
return parsed &&
typeof parsed === "object"
? parsed
: {};
}
function decodeBehaviorPayload(value) { function decodeBehaviorPayload(value) {
var binary = window.atob(value); var binary = window.atob(value);
var bytes = new Uint8Array(binary.length); var bytes = new Uint8Array(binary.length);
@@ -310,11 +338,43 @@ export const REACTIVE_RUNTIME = String.raw`
} }
function setupScope(el) { function setupScope(el) {
if (el.__wrnexusScope) return; // idempotent: safe to call again after an HMR morph if (el.__wrnexusScope) return;
el.__wrnexusScope = true; el.__wrnexusScope = true;
el.__wrnexusHydrated = true; // marks the subtree as client-owned for the HMR morph el.__wrnexusHydrated = true;
var decl = el.getAttribute("data-scope") || "";
var initial = parseScopeDecl(decl); var encodedScope =
el.getAttribute(
"data-wrn-scope",
);
var initial;
if (encodedScope) {
try {
initial =
decodeScopePayload(
encodedScope,
);
} catch (error) {
console.error(
"[wrnexus] failed to decode scope payload",
error,
);
initial = {};
}
} else {
var declaration =
el.getAttribute(
"data-scope",
) || "";
initial =
parseScopeDecl(
declaration,
);
}
var signals = {}; var signals = {};
Object.keys(initial).forEach(function (k) { signals[k] = signal(initial[k]); }); Object.keys(initial).forEach(function (k) { signals[k] = signal(initial[k]); });
@@ -374,11 +434,17 @@ export const REACTIVE_RUNTIME = String.raw`
binary.charCodeAt(index); binary.charCodeAt(index);
} }
return JSON.parse( var value =
new TextDecoder( JSON.parse(
"utf-8", new TextDecoder(
).decode(bytes), "utf-8",
); ).decode(bytes),
);
return value &&
typeof value === "object"
? value
: {};
} catch (error) { } catch (error) {
console.error( console.error(
"[wrnexus] failed to decode loop locals", "[wrnexus] failed to decode loop locals",
@@ -572,7 +638,13 @@ export const REACTIVE_RUNTIME = String.raw`
// so an outer scope never clobbers an inner one's values. // so an outer scope never clobbers an inner one's values.
function owns(node) { function owns(node) {
var host = node.nodeType === 1 ? node : node.parentNode; var host = node.nodeType === 1 ? node : node.parentNode;
return !!host && host.closest && host.closest("[data-scope]") === el; return (
!!host &&
host.closest &&
host.closest(
"[data-scope], [data-wrn-scope]",
) === el
);
} }
// --- data-for list rendering ------------------------------------------- // --- data-for list rendering -------------------------------------------
@@ -925,34 +997,128 @@ export const REACTIVE_RUNTIME = String.raw`
} }
} }
Array.prototype.slice.call(el.querySelectorAll("[data-for]")).forEach(function (tpl) { Array.prototype.slice
if (!tpl.parentNode || !owns(tpl)) return; .call(
var spec = parseFor(tpl.getAttribute("data-for")); el.querySelectorAll(
if (!spec) return; "[data-for]",
tpl.removeAttribute("data-for"); ),
var parent = tpl.parentNode; )
var marker = document.createComment("wire-for"); .forEach(function (tpl) {
parent.insertBefore(marker, tpl); if (
!tpl.parentNode ||
!owns(tpl)
) {
return;
}
var spec =
parseFor(
tpl.getAttribute(
"data-for",
),
);
if (!spec) {
return;
}
var template =
tpl.cloneNode(true);
template.removeAttribute(
"data-for",
);
var parent =
tpl.parentNode;
var marker =
document.createComment(
"wrn-for",
);
parent.insertBefore(
marker,
tpl,
);
parent.removeChild(tpl); parent.removeChild(tpl);
var clones = []; var clones = [];
reactive(function () { reactive(function () {
var list = evalExpr(spec.list); var list =
if (!list || typeof list.length !== "number") list = []; evalExpr(spec.list);
for (var c = 0; c < clones.length; c++) {
if (clones[c].parentNode) clones[c].parentNode.removeChild(clones[c]); if (!Array.isArray(list)) {
console.error(
"[wrnexus] data-for expected an array for '" +
spec.list +
"', received",
list,
);
list = [];
} }
for (
var cloneIndex = 0;
cloneIndex <
clones.length;
cloneIndex++
) {
var existingClone =
clones[cloneIndex];
if (
existingClone.parentNode
) {
existingClone.parentNode
.removeChild(
existingClone,
);
}
}
clones = []; clones = [];
var frag = document.createDocumentFragment();
for (var i = 0; i < list.length; i++) { var fragment =
var clone = tpl.cloneNode(true); document.createDocumentFragment();
for (
var itemIndex = 0;
itemIndex < list.length;
itemIndex++
) {
var clone =
template.cloneNode(true);
var locals = {}; var locals = {};
locals[spec.item] = list[i];
if (spec.index) locals[spec.index] = i; locals[spec.item] =
hydrateItem(clone, locals); list[itemIndex];
frag.appendChild(clone);
if (spec.index) {
locals[spec.index] =
itemIndex;
}
hydrateItem(
clone,
locals,
);
fragment.appendChild(
clone,
);
clones.push(clone); clones.push(clone);
} }
parent.insertBefore(frag, marker.nextSibling);
parent.insertBefore(
fragment,
marker.nextSibling,
);
}); });
}); });
@@ -1009,11 +1175,14 @@ export const REACTIVE_RUNTIME = String.raw`
expression, expression,
decodeLoopLocals(node), decodeLoopLocals(node),
); );
} catch (e) { } catch (error) {
enabled = false; enabled = false;
} }
node.classList.toggle(className, enabled); node.classList.toggle(
className,
enabled,
);
}); });
}); });
}); });
@@ -1076,7 +1245,7 @@ export const REACTIVE_RUNTIME = String.raw`
try { try {
raw = evalExpr( raw = evalExpr(
exact[1].trim(), exact[1].trim(),
locals, decodeLoopLocals(node),
); );
} catch (error) { } catch (error) {
return; return;
@@ -1090,10 +1259,10 @@ export const REACTIVE_RUNTIME = String.raw`
) { ) {
try { try {
var value = var value =
evalExpr( evalExpr(
expression.trim(), expression.trim(),
locals, decodeLoopLocals(node),
); );
return value == null return value == null
? "" ? ""
@@ -1125,7 +1294,18 @@ export const REACTIVE_RUNTIME = String.raw`
reactive(function () { reactive(function () {
node.nodeValue = tpl.replace(/\{\{\s*([^}]+?)\s*\}\}|\{([^{}]+)\}/g, function (_, doubleExpr, singleExpr) { node.nodeValue = tpl.replace(/\{\{\s*([^}]+?)\s*\}\}|\{([^{}]+)\}/g, function (_, doubleExpr, singleExpr) {
var expr = doubleExpr || singleExpr; var expr = doubleExpr || singleExpr;
try { return String(evalExpr(expr.trim())); } catch (err) { return ""; } try {
var value = evalExpr(
expr.trim(),
decodeLoopLocals(
node.parentNode,
),
);
return value == null
? ""
: String(value);
} catch (err) { return ""; }
}); });
}); });
})(textNode, template); })(textNode, template);
@@ -1152,16 +1332,24 @@ export const REACTIVE_RUNTIME = String.raw`
var stmt = attr.value; var stmt = attr.value;
var listener = function (event) { var listener = function (event) {
try { var locals =
var locals = decodeLoopLocals(node);
decodeLoopLocals(node);
locals.event = event; locals.event = event;
locals.$event = event; locals.$event = event;
runStmt(stmt, locals); try {
runStmt(
stmt,
locals,
);
} catch (error) { } catch (error) {
console.error("[wrnexus] handler error in '" + stmt + "'", error); console.error(
"[wrnexus] handler error in '" +
stmt +
"'",
error,
);
} }
}; };
@@ -1276,8 +1464,24 @@ export const REACTIVE_RUNTIME = String.raw`
function hydrateScopes(root) { function hydrateScopes(root) {
var host = root || document; var host = root || document;
if (host.nodeType === 1 && host.matches && host.matches("[data-scope]")) setupScope(host);
if (host.querySelectorAll) host.querySelectorAll("[data-scope]").forEach(setupScope); var scopeSelector =
"[data-scope], [data-wrn-scope]";
if (
host.nodeType === 1 &&
host.matches &&
host.matches(scopeSelector)
) {
setupScope(host);
}
if (host.querySelectorAll) {
host
.querySelectorAll(scopeSelector)
.forEach(setupScope);
}
ensureBehaviorObserver(); ensureBehaviorObserver();
} }
+46
View File
@@ -1,6 +1,7 @@
import { test, expect, beforeEach } from "bun:test"; import { test, expect, beforeEach } from "bun:test";
import { Window } from "happy-dom"; import { Window } from "happy-dom";
import { REACTIVE_RUNTIME } from "../src/reactive-runtime.ts"; import { REACTIVE_RUNTIME } from "../src/reactive-runtime.ts";
import { mountHtml } from "@wrnexus/test";
// Fresh DOM per test, with the runtime's globals bound. // Fresh DOM per test, with the runtime's globals bound.
function mount(html: string): Window { function mount(html: string): Window {
@@ -164,3 +165,48 @@ test("independent signals in one scope update correctly (dependency tracking)",
click("bb"); click("bb");
expect([ta(), tb()]).toEqual(["2", "101"]); expect([ta(), tb()]).toEqual(["2", "101"]);
}); });
test("data-for preserves arrays of objects from encoded component scope", () => {
const items = [
{
question: "One",
answer: "First",
},
{
question: "Two",
answer: "Second",
},
{
question: "Three",
answer: "Third",
},
{
question: "Four",
answer: "Fourth",
},
];
const encoded = Buffer.from(
JSON.stringify({
items,
}),
"utf8",
).toString("base64");
const dom = mountHtml(`
<div data-wrn-scope="${encoded}">
<article data-for="item, index in items">
<span>{index + 1}</span>
<strong>{item.question}</strong>
</article>
</div>
`);
expect(dom.querySelectorAll("article")).toHaveLength(4);
expect(dom.querySelectorAll("strong").map((element) => element.textContent)).toEqual([
"One",
"Two",
"Three",
"Four",
]);
});
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/db", "name": "@wrnexus/db",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/dev-server", "name": "@wrnexus/dev-server",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/encryption", "name": "@wrnexus/encryption",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/helpers", "name": "@wrnexus/helpers",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"description": "Safe convenience helpers for WrNexus request contexts and common application flows.", "description": "Safe convenience helpers for WrNexus request contexts and common application flows.",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/i18n", "name": "@wrnexus/i18n",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/jwt", "name": "@wrnexus/jwt",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/mobile", "name": "@wrnexus/mobile",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/native", "name": "@wrnexus/native",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/oauth", "name": "@wrnexus/oauth",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/pubsub", "name": "@wrnexus/pubsub",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/queue", "name": "@wrnexus/queue",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/reactive", "name": "@wrnexus/reactive",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/router", "name": "@wrnexus/router",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/ssr", "name": "@wrnexus/ssr",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/styles", "name": "@wrnexus/styles",
"version": "0.2.45", "version": "0.2.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/test", "name": "@wrnexus/test",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/tracking", "name": "@wrnexus/tracking",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/ui", "name": "@wrnexus/ui",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/uploader", "name": "@wrnexus/uploader",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/validation", "name": "@wrnexus/validation",
"version": "0.2.45", "version": "0.2.46",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+1 -1
View File
@@ -1,7 +1,7 @@
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path"; import { join } from "node:path";
const version = "0.2.45"; const version = "0.2.46";
const dependencyGroups = [ const dependencyGroups = [
"dependencies", "dependencies",