@constela/server 7.0.0 → 8.0.1
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 +17 -4
- 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";
|
|
@@ -425,12 +428,14 @@ function renderText(node, ctx) {
|
|
|
425
428
|
async function renderIf(node, ctx) {
|
|
426
429
|
const condition = evaluate(node.condition, ctx);
|
|
427
430
|
if (condition) {
|
|
428
|
-
|
|
431
|
+
const content = await renderNode(node.then, ctx);
|
|
432
|
+
return `<!--if:then-->${content}`;
|
|
429
433
|
}
|
|
430
434
|
if (node.else) {
|
|
431
|
-
|
|
435
|
+
const content = await renderNode(node.else, ctx);
|
|
436
|
+
return `<!--if:else-->${content}`;
|
|
432
437
|
}
|
|
433
|
-
return "";
|
|
438
|
+
return "<!--if:none-->";
|
|
434
439
|
}
|
|
435
440
|
async function renderEach(node, ctx) {
|
|
436
441
|
const items = evaluate(node.items, ctx);
|
|
@@ -491,7 +496,15 @@ async function renderLocalState(node, ctx) {
|
|
|
491
496
|
async function renderToString(program, options) {
|
|
492
497
|
const state = /* @__PURE__ */ new Map();
|
|
493
498
|
for (const [name, field] of Object.entries(program.state)) {
|
|
494
|
-
|
|
499
|
+
const overrideValue = options?.stateOverrides?.[name];
|
|
500
|
+
if (overrideValue !== void 0) {
|
|
501
|
+
state.set(name, overrideValue);
|
|
502
|
+
} else if (isCookieInitialExpr(field.initial)) {
|
|
503
|
+
const cookieValue = options?.cookies?.[field.initial.key];
|
|
504
|
+
state.set(name, cookieValue !== void 0 ? cookieValue : field.initial.default);
|
|
505
|
+
} else {
|
|
506
|
+
state.set(name, field.initial);
|
|
507
|
+
}
|
|
495
508
|
}
|
|
496
509
|
const ctx = {
|
|
497
510
|
state,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
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.11.
|
|
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.11.
|
|
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",
|