@nordcraft/ssr 1.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/README.md +5 -0
- package/dist/ToddleApiService.d.ts +23 -0
- package/dist/ToddleApiService.js +54 -0
- package/dist/ToddleApiService.js.map +1 -0
- package/dist/ToddleRoute.d.ts +20 -0
- package/dist/ToddleRoute.js +53 -0
- package/dist/ToddleRoute.js.map +1 -0
- package/dist/components/utils.d.ts +8 -0
- package/dist/components/utils.js +43 -0
- package/dist/components/utils.js.map +1 -0
- package/dist/const.d.ts +1 -0
- package/dist/const.js +18 -0
- package/dist/const.js.map +1 -0
- package/dist/custom-code/codeRefs.d.ts +30 -0
- package/dist/custom-code/codeRefs.js +176 -0
- package/dist/custom-code/codeRefs.js.map +1 -0
- package/dist/rendering/api.d.ts +13 -0
- package/dist/rendering/api.js +2 -0
- package/dist/rendering/api.js.map +1 -0
- package/dist/rendering/attributes.d.ts +15 -0
- package/dist/rendering/attributes.js +76 -0
- package/dist/rendering/attributes.js.map +1 -0
- package/dist/rendering/components.d.ts +21 -0
- package/dist/rendering/components.js +382 -0
- package/dist/rendering/components.js.map +1 -0
- package/dist/rendering/cookies.d.ts +3 -0
- package/dist/rendering/cookies.js +6 -0
- package/dist/rendering/cookies.js.map +1 -0
- package/dist/rendering/equals.d.ts +1 -0
- package/dist/rendering/equals.js +8 -0
- package/dist/rendering/equals.js.map +1 -0
- package/dist/rendering/fonts.d.ts +6 -0
- package/dist/rendering/fonts.js +67 -0
- package/dist/rendering/fonts.js.map +1 -0
- package/dist/rendering/formulaContext.d.ts +38 -0
- package/dist/rendering/formulaContext.js +120 -0
- package/dist/rendering/formulaContext.js.map +1 -0
- package/dist/rendering/head.d.ts +28 -0
- package/dist/rendering/head.js +252 -0
- package/dist/rendering/head.js.map +1 -0
- package/dist/rendering/html.d.ts +12 -0
- package/dist/rendering/html.js +14 -0
- package/dist/rendering/html.js.map +1 -0
- package/dist/rendering/request.d.ts +2 -0
- package/dist/rendering/request.js +11 -0
- package/dist/rendering/request.js.map +1 -0
- package/dist/rendering/speculation.d.ts +9 -0
- package/dist/rendering/speculation.js +22 -0
- package/dist/rendering/speculation.js.map +1 -0
- package/dist/rendering/template.d.ts +10 -0
- package/dist/rendering/template.js +36 -0
- package/dist/rendering/template.js.map +1 -0
- package/dist/rendering/testData.d.ts +2 -0
- package/dist/rendering/testData.js +58 -0
- package/dist/rendering/testData.js.map +1 -0
- package/dist/routing/routing.d.ts +26 -0
- package/dist/routing/routing.js +90 -0
- package/dist/routing/routing.js.map +1 -0
- package/dist/ssr.types.d.ts +101 -0
- package/dist/ssr.types.js +2 -0
- package/dist/ssr.types.js.map +1 -0
- package/dist/utils/headers.d.ts +12 -0
- package/dist/utils/headers.js +22 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/media.d.ts +22 -0
- package/dist/utils/media.js +34 -0
- package/dist/utils/media.js.map +1 -0
- package/dist/utils/nanoid.d.ts +1 -0
- package/dist/utils/nanoid.js +19 -0
- package/dist/utils/nanoid.js.map +1 -0
- package/dist/utils/tags.d.ts +22 -0
- package/dist/utils/tags.js +23 -0
- package/dist/utils/tags.js.map +1 -0
- package/package.json +22 -0
- package/src/ToddleApiService.ts +67 -0
- package/src/ToddleRoute.ts +70 -0
- package/src/components/utils.test.ts +90 -0
- package/src/components/utils.ts +77 -0
- package/src/const.ts +17 -0
- package/src/custom-code/codeRefs.ts +271 -0
- package/src/rendering/api.ts +21 -0
- package/src/rendering/attributes.ts +117 -0
- package/src/rendering/components.ts +579 -0
- package/src/rendering/cookies.ts +10 -0
- package/src/rendering/equals.ts +9 -0
- package/src/rendering/fonts.ts +83 -0
- package/src/rendering/formulaContext.test.ts +57 -0
- package/src/rendering/formulaContext.ts +188 -0
- package/src/rendering/head.ts +391 -0
- package/src/rendering/html.ts +33 -0
- package/src/rendering/request.ts +19 -0
- package/src/rendering/speculation.ts +21 -0
- package/src/rendering/template.test.ts +18 -0
- package/src/rendering/template.ts +63 -0
- package/src/rendering/testData.test.ts +186 -0
- package/src/rendering/testData.ts +69 -0
- package/src/routing/routing.test.ts +97 -0
- package/src/routing/routing.ts +152 -0
- package/src/ssr.types.ts +117 -0
- package/src/utils/headers.ts +23 -0
- package/src/utils/media.test.ts +130 -0
- package/src/utils/media.ts +46 -0
- package/src/utils/nanoid.ts +21 -0
- package/src/utils/tags.ts +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Formula } from '@nordcraft/core/dist/formula/formula';
|
|
2
|
+
import type { GlobalFormulas } from '@nordcraft/core/dist/formula/formulaTypes';
|
|
3
|
+
import type { ApiService } from './ssr.types';
|
|
4
|
+
export declare class ToddleApiService<Handler> {
|
|
5
|
+
private service;
|
|
6
|
+
private globalFormulas;
|
|
7
|
+
constructor({ service, globalFormulas, }: {
|
|
8
|
+
service: ApiService;
|
|
9
|
+
globalFormulas: GlobalFormulas<Handler>;
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Traverse all formulas in the API Service.
|
|
13
|
+
* @returns An iterable that yields the path and formula.
|
|
14
|
+
*/
|
|
15
|
+
formulasInService(): Generator<[(string | number)[], Formula]>;
|
|
16
|
+
get name(): string;
|
|
17
|
+
get baseUrl(): Formula | undefined;
|
|
18
|
+
get docsUrl(): Formula | undefined;
|
|
19
|
+
get apiKey(): Formula | undefined;
|
|
20
|
+
get meta(): Record<string, unknown> | {
|
|
21
|
+
projectUrl?: Formula;
|
|
22
|
+
} | undefined;
|
|
23
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getFormulasInFormula } from '@nordcraft/core/dist/formula/formulaUtils';
|
|
2
|
+
export class ToddleApiService {
|
|
3
|
+
service;
|
|
4
|
+
globalFormulas;
|
|
5
|
+
constructor({ service, globalFormulas, }) {
|
|
6
|
+
this.service = service;
|
|
7
|
+
this.globalFormulas = globalFormulas;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Traverse all formulas in the API Service.
|
|
11
|
+
* @returns An iterable that yields the path and formula.
|
|
12
|
+
*/
|
|
13
|
+
*formulasInService() {
|
|
14
|
+
const globalFormulas = this.globalFormulas;
|
|
15
|
+
yield* getFormulasInFormula({
|
|
16
|
+
formula: this.service.baseUrl,
|
|
17
|
+
globalFormulas,
|
|
18
|
+
path: ['baseUrl'],
|
|
19
|
+
});
|
|
20
|
+
yield* getFormulasInFormula({
|
|
21
|
+
formula: this.service.docsUrl,
|
|
22
|
+
globalFormulas,
|
|
23
|
+
path: ['docsUrl'],
|
|
24
|
+
});
|
|
25
|
+
yield* getFormulasInFormula({
|
|
26
|
+
formula: this.service.apiKey,
|
|
27
|
+
globalFormulas,
|
|
28
|
+
path: ['apiKey'],
|
|
29
|
+
});
|
|
30
|
+
if (this.service.type === 'supabase') {
|
|
31
|
+
yield* getFormulasInFormula({
|
|
32
|
+
formula: this.service.meta?.projectUrl,
|
|
33
|
+
globalFormulas,
|
|
34
|
+
path: ['meta', 'projectUrl'],
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
get name() {
|
|
39
|
+
return this.service.name;
|
|
40
|
+
}
|
|
41
|
+
get baseUrl() {
|
|
42
|
+
return this.service.baseUrl;
|
|
43
|
+
}
|
|
44
|
+
get docsUrl() {
|
|
45
|
+
return this.service.docsUrl;
|
|
46
|
+
}
|
|
47
|
+
get apiKey() {
|
|
48
|
+
return this.service.apiKey;
|
|
49
|
+
}
|
|
50
|
+
get meta() {
|
|
51
|
+
return this.service.meta;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=ToddleApiService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToddleApiService.js","sourceRoot":"","sources":["../src/ToddleApiService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAGhF,MAAM,OAAO,gBAAgB;IACnB,OAAO,CAA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I,CAAC,OAAO,CAAC,MAAM,CAAA;IAC5B,CAAC;IACD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Formula } from '@nordcraft/core/dist/formula/formula';
|
|
2
|
+
import type { GlobalFormulas } from '@nordcraft/core/dist/formula/formulaTypes';
|
|
3
|
+
import type { Route } from './ssr.types';
|
|
4
|
+
export declare class ToddleRoute<Handler> {
|
|
5
|
+
private route;
|
|
6
|
+
private globalFormulas;
|
|
7
|
+
constructor({ route, globalFormulas, }: {
|
|
8
|
+
route: Route;
|
|
9
|
+
globalFormulas: GlobalFormulas<Handler>;
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Traverse all formulas in the route
|
|
13
|
+
* @returns An iterable that yields the path and formula.
|
|
14
|
+
*/
|
|
15
|
+
formulasInRoute(): Generator<[(string | number)[], Formula]>;
|
|
16
|
+
get type(): "rewrite" | "redirect";
|
|
17
|
+
get source(): import("@nordcraft/core/dist/component/component.types").RouteDeclaration;
|
|
18
|
+
get destination(): import("@nordcraft/core/dist/api/apiTypes").ApiBase;
|
|
19
|
+
get status(): import("@nordcraft/core/dist/api/apiTypes").RedirectStatusCode | undefined;
|
|
20
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { getFormulasInFormula } from '@nordcraft/core/dist/formula/formulaUtils';
|
|
2
|
+
export class ToddleRoute {
|
|
3
|
+
route;
|
|
4
|
+
globalFormulas;
|
|
5
|
+
constructor({ route, globalFormulas, }) {
|
|
6
|
+
this.route = route;
|
|
7
|
+
this.globalFormulas = globalFormulas;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Traverse all formulas in the route
|
|
11
|
+
* @returns An iterable that yields the path and formula.
|
|
12
|
+
*/
|
|
13
|
+
*formulasInRoute() {
|
|
14
|
+
const globalFormulas = this.globalFormulas;
|
|
15
|
+
yield* getFormulasInFormula({
|
|
16
|
+
formula: this.route.destination.url,
|
|
17
|
+
globalFormulas,
|
|
18
|
+
path: ['destination', 'url'],
|
|
19
|
+
});
|
|
20
|
+
for (const [key, path] of Object.entries(this.route.destination.path ?? {})) {
|
|
21
|
+
yield* getFormulasInFormula({
|
|
22
|
+
formula: path.formula,
|
|
23
|
+
globalFormulas,
|
|
24
|
+
path: ['destination', 'path', key, 'formula'],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
for (const [key, q] of Object.entries(this.route.destination.queryParams ?? {})) {
|
|
28
|
+
yield* getFormulasInFormula({
|
|
29
|
+
formula: q.formula,
|
|
30
|
+
globalFormulas,
|
|
31
|
+
path: ['destination', 'queryParams', key, 'formula'],
|
|
32
|
+
});
|
|
33
|
+
yield* getFormulasInFormula({
|
|
34
|
+
formula: q.enabled,
|
|
35
|
+
globalFormulas,
|
|
36
|
+
path: ['destination', 'queryParams', key, 'enabled'],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
get type() {
|
|
41
|
+
return this.route.type;
|
|
42
|
+
}
|
|
43
|
+
get source() {
|
|
44
|
+
return this.route.source;
|
|
45
|
+
}
|
|
46
|
+
get destination() {
|
|
47
|
+
return this.route.destination;
|
|
48
|
+
}
|
|
49
|
+
get status() {
|
|
50
|
+
return this.route.type === 'redirect' ? this.route.status : undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=ToddleRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToddleRoute.js","sourceRoot":"","sources":["../src/ToddleRoute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAGhF,MAAM,OAAO,WAAW;IACd,KAAK,CAAO;IACZ,cAAc,CAAyB;IAE/C,YAAY,EACV,KAAK,EACL,cAAc,GAIf;QACC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;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C,IAAI,CAAA;IACxB,CAAC;IACD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;IAC1B,CAAC;IACD,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAA;IAC/B,CAAC;IACD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;IACvE,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Component } from '@nordcraft/core/dist/component/component.types';
|
|
2
|
+
import type { ProjectFiles } from '../ssr.types';
|
|
3
|
+
export declare function takeIncludedComponents({ root, projectComponents, packages, includeRoot, }: {
|
|
4
|
+
projectComponents: ProjectFiles['components'];
|
|
5
|
+
packages: ProjectFiles['packages'];
|
|
6
|
+
root: Component;
|
|
7
|
+
includeRoot?: boolean;
|
|
8
|
+
}): Component[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isDefined } from '@nordcraft/core/dist/utils/util';
|
|
2
|
+
export function takeIncludedComponents({ root, projectComponents, packages = {}, includeRoot = true, }) {
|
|
3
|
+
const components = {
|
|
4
|
+
...projectComponents,
|
|
5
|
+
// Join the project components with all package components
|
|
6
|
+
...Object.fromEntries(Object.values(packages).flatMap((installedPackage) => Object.values(installedPackage.components).map((component) => [
|
|
7
|
+
`${installedPackage.manifest.name}/${component.name}`,
|
|
8
|
+
component,
|
|
9
|
+
]))),
|
|
10
|
+
};
|
|
11
|
+
const includedComponents = [];
|
|
12
|
+
if (includeRoot) {
|
|
13
|
+
includedComponents.push(root);
|
|
14
|
+
}
|
|
15
|
+
includedComponents.push(...takeComponentsIncludedInProject(root, components));
|
|
16
|
+
return includedComponents;
|
|
17
|
+
}
|
|
18
|
+
function takeComponentsIncludedInProject(parent, components) {
|
|
19
|
+
const dependencies = new Map();
|
|
20
|
+
const visitNode = (node, packageName) => {
|
|
21
|
+
if (node.type !== 'component') {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const nodeName = [node.package ?? packageName, node.name]
|
|
25
|
+
.filter(isDefined)
|
|
26
|
+
.join('/');
|
|
27
|
+
if (dependencies.has(nodeName)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const component = components[nodeName];
|
|
31
|
+
if (!isDefined(component)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Only add known/existing dependencies
|
|
35
|
+
if (Object.hasOwn(components, nodeName)) {
|
|
36
|
+
dependencies.set(nodeName, { ...component, name: nodeName });
|
|
37
|
+
}
|
|
38
|
+
Object.values(component.nodes).forEach((node) => visitNode(node, (node.type === 'component' ? node.package : undefined) ?? packageName));
|
|
39
|
+
};
|
|
40
|
+
Object.values(parent.nodes).forEach((node) => visitNode(node, node.type === 'component' ? node.package : undefined));
|
|
41
|
+
return Array.from(dependencies.values());
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/components/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAG3D,MAAM,UAAU,sBAAsB,CAAC,EACrC,IAAI,EACJ,iBAAiB,EACjB,QAAQ,GAAG,EAAE,EACb,WAAW,GAAG,IAAI,GAMnB;IACC,MAAM,UAAU,GAAG;QACjB,GAAG,iBAAiB;QACpB,0DAA0D;QAC1D,GAAG,MAAM,CAAC,WAAW,CACnB,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,gBAAgB,EAAE,EAAE,CACnD,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC;YAC5D,GAAG,gBAA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CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAC9C,SAAS,CACP,IAAI,EACJ,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,WAAW,CACtE,CACF,CAAA;IACH,CAAC,CAAA;IAED,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAC3C,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CACtE,CAAA;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAA;AAC1C,CAAC"}
|
package/dist/const.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VOID_HTML_ELEMENTS: string[];
|
package/dist/const.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// See https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
|
2
|
+
export const VOID_HTML_ELEMENTS = [
|
|
3
|
+
'area',
|
|
4
|
+
'base',
|
|
5
|
+
'br',
|
|
6
|
+
'col',
|
|
7
|
+
'embed',
|
|
8
|
+
'hr',
|
|
9
|
+
'img',
|
|
10
|
+
'input',
|
|
11
|
+
'link',
|
|
12
|
+
'meta',
|
|
13
|
+
'param',
|
|
14
|
+
'source',
|
|
15
|
+
'track',
|
|
16
|
+
'wbr',
|
|
17
|
+
];
|
|
18
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,MAAM;IACN,MAAM;IACN,IAAI;IACJ,KAAK;IACL,OAAO;IACP,IAAI;IACJ,KAAK;IACL,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;IACP,KAAK;CACN,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Component } from '@nordcraft/core/dist/component/component.types';
|
|
2
|
+
import type { PluginFormula } from '@nordcraft/core/dist/formula/formulaTypes';
|
|
3
|
+
import type { PluginAction, ProjectFiles, ToddleProject } from '../ssr.types';
|
|
4
|
+
export declare function takeReferencedFormulasAndActions({ component, files, }: {
|
|
5
|
+
component: Component | undefined;
|
|
6
|
+
files: ProjectFiles;
|
|
7
|
+
}): {
|
|
8
|
+
__PROJECT__: {
|
|
9
|
+
actions: Record<string, PluginAction & {
|
|
10
|
+
packageName?: string;
|
|
11
|
+
}>;
|
|
12
|
+
formulas: Record<string, PluginFormula<string> & {
|
|
13
|
+
packageName?: string;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
[packageName: string]: {
|
|
17
|
+
actions: Record<string, PluginAction & {
|
|
18
|
+
packageName?: string;
|
|
19
|
+
}>;
|
|
20
|
+
formulas: Record<string, PluginFormula<string> & {
|
|
21
|
+
packageName?: string;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare const hasCustomCode: (component: Component, files: ProjectFiles) => boolean;
|
|
26
|
+
export declare const generateCustomCodeFile: ({ code, componentName, projectId, }: {
|
|
27
|
+
code: ReturnType<typeof takeReferencedFormulasAndActions>;
|
|
28
|
+
componentName?: string;
|
|
29
|
+
projectId: ToddleProject["short_id"];
|
|
30
|
+
}) => string;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { ToddleComponent } from '@nordcraft/core/dist/component/ToddleComponent';
|
|
2
|
+
import { isToddleFormula } from '@nordcraft/core/dist/formula/formulaTypes';
|
|
3
|
+
import { filterObject, mapObject } from '@nordcraft/core/dist/utils/collections';
|
|
4
|
+
import { isDefined } from '@nordcraft/core/dist/utils/util';
|
|
5
|
+
export function takeReferencedFormulasAndActions({ component, files, }) {
|
|
6
|
+
// If no entry file is specified or found, return all actions and formulas
|
|
7
|
+
if (!isDefined(component)) {
|
|
8
|
+
return {
|
|
9
|
+
__PROJECT__: {
|
|
10
|
+
actions: {
|
|
11
|
+
...(files.actions ?? {}),
|
|
12
|
+
},
|
|
13
|
+
formulas: {
|
|
14
|
+
...(files.formulas ?? {}),
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
...mapObject(files.packages ?? {}, ([packageName, { actions, formulas }]) => [
|
|
18
|
+
packageName,
|
|
19
|
+
{
|
|
20
|
+
actions: actions ?? {},
|
|
21
|
+
formulas: formulas ?? {},
|
|
22
|
+
},
|
|
23
|
+
]),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// Return only the actions and formulas that are referenced by the entry file
|
|
27
|
+
const actionRefs = new Set();
|
|
28
|
+
const formulaRefs = new Set();
|
|
29
|
+
const toddleComponent = new ToddleComponent({
|
|
30
|
+
component: component,
|
|
31
|
+
getComponent: (name, packageName) => {
|
|
32
|
+
const nodeLookupKey = [packageName, name].filter(isDefined).join('/');
|
|
33
|
+
const component = packageName
|
|
34
|
+
? files.packages?.[packageName]?.components[name]
|
|
35
|
+
: files.components[name];
|
|
36
|
+
if (!component) {
|
|
37
|
+
// eslint-disable-next-line no-console
|
|
38
|
+
console.warn(`Unable to find component "${nodeLookupKey}" in files`);
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return component;
|
|
42
|
+
},
|
|
43
|
+
packageName: undefined,
|
|
44
|
+
globalFormulas: {
|
|
45
|
+
formulas: files.formulas,
|
|
46
|
+
packages: files.packages,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
toddleComponent.actionReferences.forEach((ref) => actionRefs.add(ref));
|
|
50
|
+
toddleComponent.formulaReferences.forEach((ref) => formulaRefs.add(ref));
|
|
51
|
+
toddleComponent.uniqueSubComponents.forEach((c) => {
|
|
52
|
+
c.actionReferences.forEach((ref) => actionRefs.add([c.packageName, ref].filter(isDefined).join('/')));
|
|
53
|
+
c.formulaReferences.forEach((ref) => formulaRefs.add([c.packageName, ref].filter(isDefined).join('/')));
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
...mapObject(
|
|
57
|
+
// Only include packages that have referenced actions or formulas
|
|
58
|
+
filterObject(files.packages ?? {}, ([packageName, { actions, formulas }]) => Object.values(actions ?? {}).some((a) => actionRefs.has(`${packageName}/${a.name}`)) ||
|
|
59
|
+
Object.values(formulas ?? {}).some((f) => formulaRefs.has(`${packageName}/${f.name}`))),
|
|
60
|
+
// Only include the actions and formulas that are referenced
|
|
61
|
+
([packageName, { actions, formulas }]) => [
|
|
62
|
+
packageName,
|
|
63
|
+
{
|
|
64
|
+
actions: filterObject(actions ?? {}, ([_, a]) => typeof a.name === 'string' &&
|
|
65
|
+
actionRefs.has(`${packageName}/${a.name}`)),
|
|
66
|
+
formulas: filterObject(formulas ?? {}, ([_, f]) => typeof f.name === 'string' &&
|
|
67
|
+
formulaRefs.has(`${packageName}/${f.name}`)),
|
|
68
|
+
},
|
|
69
|
+
]),
|
|
70
|
+
__PROJECT__: {
|
|
71
|
+
actions: {
|
|
72
|
+
...Object.fromEntries(Object.entries(files.actions ?? {}).filter(([key]) => actionRefs.has(key))),
|
|
73
|
+
},
|
|
74
|
+
formulas: {
|
|
75
|
+
...Object.fromEntries(Object.entries(files.formulas ?? {}).filter(([key]) => formulaRefs.has(key))),
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export const hasCustomCode = (component, files) => {
|
|
81
|
+
const code = takeReferencedFormulasAndActions({ component, files });
|
|
82
|
+
return Object.values(code).some((c) => Object.keys(c.actions).length > 0 || Object.keys(c.formulas).length > 0);
|
|
83
|
+
};
|
|
84
|
+
export const generateCustomCodeFile = ({ code, componentName, projectId, }) => {
|
|
85
|
+
const v2ActionCode = mapObject(filterObject(code, ([_, c]) => Object.values(c.actions).some((a) => a.version === 2)), ([packageName, c]) => [
|
|
86
|
+
// A small hack to group project actions/formulas under the project short id
|
|
87
|
+
// TS doesn't let us index an object by a generic, hence this hack
|
|
88
|
+
packageName === '__PROJECT__' ? projectId : packageName,
|
|
89
|
+
c,
|
|
90
|
+
]);
|
|
91
|
+
const v2FormulaCode = mapObject(filterObject(code, ([_, c]) => Object.values(c.formulas).some(
|
|
92
|
+
// Ignore legacy code formulas
|
|
93
|
+
(f) => isToddleFormula(f) || f.version === 2)), ([packageName, c]) => [
|
|
94
|
+
// A small hack to group project actions/formulas under the project short id
|
|
95
|
+
// TS doesn't let us index an object by a generic, hence this hack
|
|
96
|
+
packageName === '__PROJECT__' ? projectId : packageName,
|
|
97
|
+
c,
|
|
98
|
+
]);
|
|
99
|
+
return `/*
|
|
100
|
+
* This file is autogenerated by toddle and should not be edited manually.
|
|
101
|
+
*
|
|
102
|
+
* ${typeof componentName === 'string'
|
|
103
|
+
? `Entry file: ${componentName}`
|
|
104
|
+
: 'No entry file specified'}
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
export const project = "${projectId}";
|
|
108
|
+
|
|
109
|
+
export const loadCustomCode = () => {
|
|
110
|
+
${
|
|
111
|
+
// We assume that packages don't have legacy actions/formulas
|
|
112
|
+
// Therefore we only load code from the actual project
|
|
113
|
+
Object.values(code.__PROJECT__.actions)
|
|
114
|
+
.filter((a) => typeof a.name === 'string' && a.version === undefined)
|
|
115
|
+
.map((action) => action.handler)
|
|
116
|
+
.join('\n')}
|
|
117
|
+
${Object.values(code.__PROJECT__.formulas)
|
|
118
|
+
.filter((a) => !isToddleFormula(a) &&
|
|
119
|
+
typeof a.name === 'string' &&
|
|
120
|
+
a.version === undefined)
|
|
121
|
+
.map((formula) => formula.handler)
|
|
122
|
+
.join('\n')}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export const actions = {
|
|
126
|
+
${Object.entries(v2ActionCode)
|
|
127
|
+
.map(([packageName, { actions }]) => `"${packageName}": {
|
|
128
|
+
${Object.values(actions)
|
|
129
|
+
.filter((a) => a.version === 2)
|
|
130
|
+
.map((a) => `"${a.name}": {
|
|
131
|
+
arguments: ${JSON.stringify(a.arguments)},
|
|
132
|
+
handler: (args, ctx) => {
|
|
133
|
+
${a.handler}
|
|
134
|
+
return ${safeFunctionName(a.name)}(args, ctx)
|
|
135
|
+
}
|
|
136
|
+
}`)
|
|
137
|
+
.join(',\n')}
|
|
138
|
+
}`)
|
|
139
|
+
.join(',\n')}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const formulas = {
|
|
143
|
+
${Object.entries(v2FormulaCode)
|
|
144
|
+
.map(([packageName, { formulas }]) => `"${packageName}": {
|
|
145
|
+
${Object.values(formulas)
|
|
146
|
+
.filter((f) => isToddleFormula(f) || f.version === 2)
|
|
147
|
+
.map((f) => isToddleFormula(f)
|
|
148
|
+
? `"${f.name}": {
|
|
149
|
+
arguments: ${JSON.stringify(f.arguments)},
|
|
150
|
+
formula: ${JSON.stringify(f.formula)}
|
|
151
|
+
}`
|
|
152
|
+
: `"${f.name}": {
|
|
153
|
+
arguments: ${JSON.stringify(f.arguments)},
|
|
154
|
+
handler: (args, ctx) => {
|
|
155
|
+
${f.handler}
|
|
156
|
+
return ${safeFunctionName(f.name)}(args, ctx)
|
|
157
|
+
}
|
|
158
|
+
}`)
|
|
159
|
+
.join(',\n')}
|
|
160
|
+
}`)
|
|
161
|
+
.join(',\n')}
|
|
162
|
+
}`;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Removes non-alphanumeric characters except for _ from a function name
|
|
166
|
+
* @param name
|
|
167
|
+
* @returns "safe" function name only containing alphanumeric characters and _, e.g. "myFunction" or "my_function"
|
|
168
|
+
*/
|
|
169
|
+
const safeFunctionName = (name) => {
|
|
170
|
+
return (name
|
|
171
|
+
// Remove any non-alphanumeric characters
|
|
172
|
+
.replaceAll(/[^a-zA-Z0-9_]/g, '')
|
|
173
|
+
// Remove any leading numbers
|
|
174
|
+
.replace(/^[0-9]+/, ''));
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=codeRefs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeRefs.js","sourceRoot":"","sources":["../../src/custom-code/codeRefs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AAMhF,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAA;AAC3E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAA;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAG3D,MAAM,UAAU,gCAAgC,CAAC,EAC/C,SAAS,EACT,KAAK,GAIN;IAUC,0EAA0E;IAC1E,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1B,OAAO;YACL,WAAW,EAAE;gBACX,OAAO,EAAE;oBACP,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;iBACzB;gBACD,QAAQ,EAAE;oBACR,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;iBAC1B;aACF;YACD,GAAG,SAAS,CACV,KAAK,CAAC,QAAQ,IAAI,EAAE,EACpB,CAAC,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;gBACxC,WAAW;gBACX;oBACE,OAAO,EAAE,OAAO,IAAI,EAAE;oBACtB,QAAQ,EAAE,QAAQ,IAAI,EAAE;iBACzB;aACF,CACF;SACF,CAAA;IACH,CAAC;IAED,6EAA6E;IAC7E,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAA;IACpC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAA;IACrC,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC;QAC1C,SAAS,EAAE,SAAS;QACpB,YAAY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AO,KAAK,CAAC,CAAC;SACpD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACT,eAAe,CAAC,CAAC,CAAC;QAChB,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI;mBACH,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;iBAC7B,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;MACpC;QACI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI;mBACH,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;;UAEpC,CAAC,CAAC,OAAO;iBACF,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC;;MAEnC,CACC;SACA,IAAI,CAAC,KAAK,CAAC;IACd,CACC;SACA,IAAI,CAAC,KAAK,CAAC;EACd,CAAA;AACF,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,EAAE;IACxC,OAAO,CACL,IAAI;QACF,yCAAyC;SACxC,UAAU,CAAC,gBAAgB,EAAE,EAAE,CAAC;QACjC,6BAA6B;SAC5B,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAC1B,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiStatus, LegacyApiStatus } from '@nordcraft/core/dist/api/apiTypes';
|
|
2
|
+
import type { ToddleComponent } from '@nordcraft/core/dist/component/ToddleComponent';
|
|
3
|
+
import type { FormulaContext } from '@nordcraft/core/dist/formula/formula';
|
|
4
|
+
export type ApiCache = Record<string, ApiStatus>;
|
|
5
|
+
export type ApiEvaluator = (args: {
|
|
6
|
+
component: ToddleComponent<string>;
|
|
7
|
+
formulaContext: FormulaContext;
|
|
8
|
+
req: Request;
|
|
9
|
+
apiCache: ApiCache;
|
|
10
|
+
updateApiCache: (key: string, value: ApiStatus) => void;
|
|
11
|
+
}) => Promise<Record<string, LegacyApiStatus | (ApiStatus & {
|
|
12
|
+
inputs?: Record<string, unknown>;
|
|
13
|
+
})>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/rendering/api.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Component, ComponentData, ElementNodeModel } from '@nordcraft/core/dist/component/component.types';
|
|
2
|
+
import type { FormulaContext, ToddleEnv } from '@nordcraft/core/dist/formula/formula';
|
|
3
|
+
export declare const escapeAttrValue: (value: any) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Escape a string to valid HTML text similar to how set innerText would work in the browser
|
|
6
|
+
*/
|
|
7
|
+
export declare const toEncodedText: (str: string) => string;
|
|
8
|
+
export declare function getNodeAttrs({ node, data, component, packageName, env, toddle, }: {
|
|
9
|
+
node: Pick<ElementNodeModel, 'attrs' | 'style-variables'>;
|
|
10
|
+
data: ComponentData;
|
|
11
|
+
component: Component;
|
|
12
|
+
packageName: string | undefined;
|
|
13
|
+
env: ToddleEnv;
|
|
14
|
+
toddle: FormulaContext['toddle'];
|
|
15
|
+
}): string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { applyFormula } from '@nordcraft/core/dist/formula/formula';
|
|
2
|
+
import { isDefined, toBoolean } from '@nordcraft/core/dist/utils/util';
|
|
3
|
+
const REGEXP_QUOTE = /"/g;
|
|
4
|
+
const REGEXP_LT = /</g;
|
|
5
|
+
const REGEXP_GT = />/g;
|
|
6
|
+
const validAttrTypes = ['string', 'number', 'boolean'];
|
|
7
|
+
export const escapeAttrValue = (value) => {
|
|
8
|
+
if (!isDefined(value) || !validAttrTypes.includes(typeof value)) {
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
return escapeHtml(escapeQuote(String(value)));
|
|
12
|
+
};
|
|
13
|
+
const escapeQuote = (value) => {
|
|
14
|
+
return value.replace(REGEXP_QUOTE, '"');
|
|
15
|
+
};
|
|
16
|
+
const escapeHtml = (html) => {
|
|
17
|
+
return html.replace(REGEXP_LT, '<').replace(REGEXP_GT, '>');
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Escape a string to valid HTML text similar to how set innerText would work in the browser
|
|
21
|
+
*/
|
|
22
|
+
export const toEncodedText = (str) => {
|
|
23
|
+
return str
|
|
24
|
+
.replaceAll('&', '&')
|
|
25
|
+
.replaceAll('<', '<')
|
|
26
|
+
.replaceAll('>', '>')
|
|
27
|
+
.replaceAll('"', '"')
|
|
28
|
+
.replaceAll("'", ''')
|
|
29
|
+
.replaceAll('\n', '<br />');
|
|
30
|
+
};
|
|
31
|
+
export function getNodeAttrs({ node, data, component, packageName, env, toddle, }) {
|
|
32
|
+
const { style, ...restAttrs } = node.attrs;
|
|
33
|
+
const nodeAttrs = Object.entries(restAttrs).reduce((appliedAttributes, [name, attrValue]) => {
|
|
34
|
+
const value = applyFormula(attrValue, {
|
|
35
|
+
data,
|
|
36
|
+
component,
|
|
37
|
+
package: packageName,
|
|
38
|
+
env,
|
|
39
|
+
toddle,
|
|
40
|
+
});
|
|
41
|
+
if (toBoolean(value)) {
|
|
42
|
+
appliedAttributes.push(`${name}="${escapeAttrValue(value)}"`);
|
|
43
|
+
}
|
|
44
|
+
return appliedAttributes;
|
|
45
|
+
}, []);
|
|
46
|
+
const styleVariables = Object.values(node['style-variables'] ?? {}).map(({ name, formula, unit }) => `--${name}: ${String(applyFormula(formula, {
|
|
47
|
+
data,
|
|
48
|
+
component,
|
|
49
|
+
package: packageName,
|
|
50
|
+
env,
|
|
51
|
+
toddle,
|
|
52
|
+
})) + (unit ?? '')}`);
|
|
53
|
+
// Handle the style-attribute independently to merge with style variables
|
|
54
|
+
const styles = [
|
|
55
|
+
...(style
|
|
56
|
+
? [
|
|
57
|
+
applyFormula(style, {
|
|
58
|
+
data,
|
|
59
|
+
component,
|
|
60
|
+
package: packageName,
|
|
61
|
+
env,
|
|
62
|
+
toddle,
|
|
63
|
+
}),
|
|
64
|
+
]
|
|
65
|
+
: []),
|
|
66
|
+
...styleVariables,
|
|
67
|
+
]
|
|
68
|
+
.filter(Boolean)
|
|
69
|
+
.map(String)
|
|
70
|
+
.join('; ');
|
|
71
|
+
if (styles.length > 0) {
|
|
72
|
+
return [...nodeAttrs, `style="${escapeAttrValue(styles)};"`].join(' ');
|
|
73
|
+
}
|
|
74
|
+
return nodeAttrs.join(' ');
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=attributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../src/rendering/attributes.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAA;AACnE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAEtE,MAAM,YAAY,GAAG,IAAI,CAAA;AACzB,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,SAAS,GAAG,IAAI,CAAA;AAEtB,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;AAEtD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAU,EAAE,EAAE;IAC5C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;QAChE,OAAO,EAAE,CAAA;IACX,CAAC;IACD,OAAO,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC/C,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,EAAE;IACpC,OAAO,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;AAC9C,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE;IAClC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,OAAO,C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,EAAE,IAAI,EAAE,EAAE,EAAE,CAC1B,KAAK,IAAI,KACP,MAAM,CACJ,YAAY,CAAC,OAAO,EAAE;QACpB,IAAI;QACJ,SAAS;QACT,OAAO,EAAE,WAAW;QACpB,GAAG;QACH,MAAM;KACP,CAAC,CACH,GAAG,CAAC,IAAI,IAAI,EAAE,CACjB,EAAE,CACL,CAAA;IAED,yEAAyE;IACzE,MAAM,MAAM,GAAG;QACb,GAAG,CAAC,KAAK;YACP,CAAC,CAAC;gBACE,YAAY,CAAC,KAAK,EAAE;oBAClB,IAAI;oBACJ,SAAS;oBACT,OAAO,EAAE,WAAW;oBACpB,GAAG;oBACH,MAAM;iBACP,CAAC;aACH;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,cAAc;KAClB;SACE,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,MAAM,CAAC;SACX,IAAI,CAAC,IAAI,CAAC,CAAA;IACb,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,SAAS,EAAE,UAAU,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACxE,CAAC;IAED,OAAO,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Component } from '@nordcraft/core/dist/component/component.types';
|
|
2
|
+
import { ToddleComponent } from '@nordcraft/core/dist/component/ToddleComponent';
|
|
3
|
+
import type { FormulaContext, ToddleServerEnv } from '@nordcraft/core/dist/formula/formula';
|
|
4
|
+
import type { ProjectFiles } from '../ssr.types';
|
|
5
|
+
import type { ApiCache, ApiEvaluator } from './api';
|
|
6
|
+
/**
|
|
7
|
+
* Renders a page body for a given ToddleComponent
|
|
8
|
+
*/
|
|
9
|
+
export declare const renderPageBody: ({ component, env, evaluateComponentApis, files, formulaContext, includedComponents, req, projectId, }: {
|
|
10
|
+
component: ToddleComponent<string>;
|
|
11
|
+
env: ToddleServerEnv;
|
|
12
|
+
evaluateComponentApis: ApiEvaluator;
|
|
13
|
+
files: ProjectFiles;
|
|
14
|
+
formulaContext: FormulaContext;
|
|
15
|
+
includedComponents: Component[];
|
|
16
|
+
req: Request;
|
|
17
|
+
projectId: string;
|
|
18
|
+
}) => Promise<{
|
|
19
|
+
html: string;
|
|
20
|
+
apiCache: ApiCache;
|
|
21
|
+
}>;
|