@constela/server 6.0.0 → 8.0.0
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/index.d.ts +2 -0
- package/dist/index.js +23 -1
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/renderer.ts
|
|
2
|
+
import { isCookieInitialExpr } from "@constela/core";
|
|
3
|
+
|
|
1
4
|
// src/markdown.ts
|
|
2
5
|
import { marked } from "marked";
|
|
3
6
|
import markedShiki from "marked-shiki";
|
|
@@ -225,6 +228,9 @@ function evaluate(expr, ctx) {
|
|
|
225
228
|
return val == null ? "" : String(val);
|
|
226
229
|
}).join("");
|
|
227
230
|
}
|
|
231
|
+
case "validity": {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
228
234
|
default: {
|
|
229
235
|
const _exhaustiveCheck = expr;
|
|
230
236
|
throw new Error(`Unknown expression type: ${JSON.stringify(_exhaustiveCheck)}`);
|
|
@@ -371,6 +377,8 @@ async function renderNode(node, ctx) {
|
|
|
371
377
|
return await renderCode(node, ctx);
|
|
372
378
|
case "slot":
|
|
373
379
|
return "";
|
|
380
|
+
case "portal":
|
|
381
|
+
return await renderPortal(node, ctx);
|
|
374
382
|
case "localState":
|
|
375
383
|
return await renderLocalState(node, ctx);
|
|
376
384
|
default: {
|
|
@@ -463,6 +471,12 @@ async function renderCode(node, ctx) {
|
|
|
463
471
|
const copyButton = `<button class="constela-copy-btn absolute right-3 top-3 z-10 flex h-8 w-8 items-center justify-center rounded-md border border-border bg-background/80 opacity-0 transition-opacity hover:bg-muted group-hover:opacity-100" data-copy-target="code" aria-label="Copy code"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg></button>`;
|
|
464
472
|
return `<div class="constela-code" data-code-content="${escapeHtml(content)}"><div class="group relative">${languageBadge}${copyButton}${highlightedCode}</div></div>`;
|
|
465
473
|
}
|
|
474
|
+
async function renderPortal(node, ctx) {
|
|
475
|
+
const childrenHtml = await Promise.all(
|
|
476
|
+
node.children.map((child) => renderNode(child, ctx))
|
|
477
|
+
);
|
|
478
|
+
return `<!--portal:${node.target}-->${childrenHtml.join("")}<!--/portal-->`;
|
|
479
|
+
}
|
|
466
480
|
async function renderLocalState(node, ctx) {
|
|
467
481
|
const localStateValues = {};
|
|
468
482
|
for (const [name, field] of Object.entries(node.state)) {
|
|
@@ -480,7 +494,15 @@ async function renderLocalState(node, ctx) {
|
|
|
480
494
|
async function renderToString(program, options) {
|
|
481
495
|
const state = /* @__PURE__ */ new Map();
|
|
482
496
|
for (const [name, field] of Object.entries(program.state)) {
|
|
483
|
-
|
|
497
|
+
const overrideValue = options?.stateOverrides?.[name];
|
|
498
|
+
if (overrideValue !== void 0) {
|
|
499
|
+
state.set(name, overrideValue);
|
|
500
|
+
} else if (isCookieInitialExpr(field.initial)) {
|
|
501
|
+
const cookieValue = options?.cookies?.[field.initial.key];
|
|
502
|
+
state.set(name, cookieValue !== void 0 ? cookieValue : field.initial.default);
|
|
503
|
+
} else {
|
|
504
|
+
state.set(name, field.initial);
|
|
505
|
+
}
|
|
484
506
|
}
|
|
485
507
|
const ctx = {
|
|
486
508
|
state,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Server-side rendering for Constela UI framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@constela/compiler": "^0.
|
|
18
|
+
"@constela/compiler": "^0.11.1",
|
|
19
|
+
"@constela/core": "^0.12.0"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"isomorphic-dompurify": "^2.35.0",
|
|
@@ -28,14 +29,15 @@
|
|
|
28
29
|
"tsup": "^8.0.0",
|
|
29
30
|
"typescript": "^5.3.0",
|
|
30
31
|
"vitest": "^2.0.0",
|
|
31
|
-
"@constela/compiler": "0.
|
|
32
|
+
"@constela/compiler": "0.11.1",
|
|
33
|
+
"@constela/core": "0.12.0"
|
|
32
34
|
},
|
|
33
35
|
"engines": {
|
|
34
36
|
"node": ">=20.0.0"
|
|
35
37
|
},
|
|
36
38
|
"license": "MIT",
|
|
37
39
|
"scripts": {
|
|
38
|
-
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
40
|
+
"build": "tsup src/index.ts --format esm --dts --clean --external @constela/core",
|
|
39
41
|
"type-check": "tsc --noEmit",
|
|
40
42
|
"test": "vitest run",
|
|
41
43
|
"test:watch": "vitest",
|