@ecopages/kitajs 0.2.0-alpha.1 → 0.2.0-alpha.10
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/CHANGELOG.md +7 -5
- package/README.md +5 -5
- package/package.json +2 -2
- package/src/kitajs-renderer.js +25 -19
- package/src/kitajs-renderer.ts +0 -130
- package/src/kitajs.plugin.ts +0 -32
package/CHANGELOG.md
CHANGED
|
@@ -6,16 +6,18 @@ All notable changes to `@ecopages/kitajs` are documented here.
|
|
|
6
6
|
|
|
7
7
|
## [UNRELEASED] — TBD
|
|
8
8
|
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- Fixed explicit `ctx.render()` flows so deferred cross-integration layout components resolve through the marker pipeline instead of crashing during direct server rendering.
|
|
12
|
+
|
|
9
13
|
### Features
|
|
10
14
|
|
|
11
|
-
- Aligned KitaJS
|
|
15
|
+
- Aligned KitaJS with the unified orchestration pipeline.
|
|
12
16
|
|
|
13
17
|
### Refactoring
|
|
14
18
|
|
|
15
|
-
-
|
|
16
|
-
- Ambient module declarations cleaned up (`5f46ecc5`).
|
|
17
|
-
- Updated test suite for esbuild adapter and Node.js runtime compatibility (`31a44458`).
|
|
19
|
+
- Tightened Kita component typing and cleaned up ambient module declarations.
|
|
18
20
|
|
|
19
21
|
### Tests
|
|
20
22
|
|
|
21
|
-
- Updated integration
|
|
23
|
+
- Updated integration coverage for the orchestration pipeline and Node and esbuild compatibility.
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ecopages/kitajs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Integration plugin for [KitaJS](https://kitajs.org/html/) HTML within the Ecopages framework. It enables the rendering of standard JSX templates for multi-page applications.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
bunx jsr add @ecopages/kitajs
|
|
@@ -10,10 +10,10 @@ bunx jsr add @ecopages/kitajs
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Import and register the `kitajsPlugin` in your `eco.config.ts`.
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { ConfigBuilder } from '@ecopages/core';
|
|
16
|
+
import { ConfigBuilder } from '@ecopages/core/config-builder';
|
|
17
17
|
import { kitajsPlugin } from '@ecopages/kitajs';
|
|
18
18
|
|
|
19
19
|
const config = await new ConfigBuilder()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/kitajs",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.10",
|
|
4
4
|
"description": "Kitajs plugin for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"directory": "packages/integrations/kitajs"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@ecopages/core": "0.2.0-alpha.
|
|
20
|
+
"@ecopages/core": "0.2.0-alpha.10",
|
|
21
21
|
"@kitajs/html": "^4.1.0",
|
|
22
22
|
"@kitajs/ts-html-plugin": "^4.0.1"
|
|
23
23
|
}
|
package/src/kitajs-renderer.js
CHANGED
|
@@ -50,31 +50,37 @@ class KitaRenderer extends IntegrationRenderer {
|
|
|
50
50
|
async renderToResponse(view, props, ctx) {
|
|
51
51
|
try {
|
|
52
52
|
const Layout = view.config?.layout;
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
if (ctx.partial) {
|
|
56
|
-
return this.createHtmlResponse(pageContent, ctx);
|
|
57
|
-
}
|
|
58
|
-
const children = Layout ? await Layout({ children: pageContent }) : pageContent;
|
|
59
|
-
const HtmlTemplate = await this.getHtmlTemplate();
|
|
60
|
-
const metadata = view.metadata ? await view.metadata({
|
|
53
|
+
const HtmlTemplate = ctx.partial ? void 0 : await this.getHtmlTemplate();
|
|
54
|
+
const metadata = ctx.partial || !HtmlTemplate ? void 0 : view.metadata ? await view.metadata({
|
|
61
55
|
params: {},
|
|
62
56
|
query: {},
|
|
63
57
|
props,
|
|
64
58
|
appConfig: this.appConfig
|
|
65
59
|
}) : this.appConfig.defaultMetadata;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
if (!ctx.partial) {
|
|
61
|
+
await this.prepareViewDependencies(view, Layout);
|
|
62
|
+
}
|
|
63
|
+
const viewFn = view;
|
|
64
|
+
const renderExecution = await this.captureHtmlRender(async () => {
|
|
65
|
+
const pageContent = await viewFn(props);
|
|
66
|
+
if (ctx.partial) {
|
|
67
|
+
return pageContent;
|
|
68
|
+
}
|
|
69
|
+
const children = Layout ? await Layout({ children: pageContent }) : pageContent;
|
|
70
|
+
return this.DOC_TYPE + await HtmlTemplate({
|
|
71
|
+
metadata: metadata ?? this.appConfig.defaultMetadata,
|
|
72
|
+
pageProps: props ?? {},
|
|
73
|
+
children: children ?? ""
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
const componentsToResolve = ctx.partial ? [view] : [HtmlTemplate, Layout, view].filter(Boolean);
|
|
77
|
+
const body = await this.finalizeCapturedHtmlRender({
|
|
78
|
+
html: renderExecution.html,
|
|
79
|
+
componentsToResolve,
|
|
80
|
+
graphContext: renderExecution.graphContext,
|
|
81
|
+
partial: ctx.partial
|
|
71
82
|
});
|
|
72
|
-
|
|
73
|
-
new Response(html, {
|
|
74
|
-
headers: { "Content-Type": "text/html" }
|
|
75
|
-
})
|
|
76
|
-
);
|
|
77
|
-
return this.createHtmlResponse(transformedResponse.body ?? "", ctx);
|
|
83
|
+
return this.createHtmlResponse(body, ctx);
|
|
78
84
|
} catch (error) {
|
|
79
85
|
throw this.createRenderError("Error rendering view", error);
|
|
80
86
|
}
|
package/src/kitajs-renderer.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module contains the Kita.js renderer
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
ComponentRenderInput,
|
|
8
|
-
ComponentRenderResult,
|
|
9
|
-
EcoComponent,
|
|
10
|
-
EcoPagesElement,
|
|
11
|
-
IntegrationRendererRenderOptions,
|
|
12
|
-
RouteRendererBody,
|
|
13
|
-
} from '@ecopages/core';
|
|
14
|
-
import { IntegrationRenderer, type RenderToResponseContext } from '@ecopages/core/route-renderer/integration-renderer';
|
|
15
|
-
import { PLUGIN_NAME } from './kitajs.plugin.ts';
|
|
16
|
-
|
|
17
|
-
/** Narrows an EcoComponent to its KitaJS callable signature. */
|
|
18
|
-
type KitaViewFn<P> = (props: P) => Promise<EcoPagesElement> | EcoPagesElement;
|
|
19
|
-
|
|
20
|
-
/** KitaJS layout function signature. */
|
|
21
|
-
type KitaLayoutFn = (props: { children: EcoPagesElement } & Record<string, unknown>) => Promise<EcoPagesElement>;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A renderer for the Kita.js integration.
|
|
25
|
-
* It renders a page using the HtmlTemplate and Page components.
|
|
26
|
-
*/
|
|
27
|
-
export class KitaRenderer extends IntegrationRenderer<EcoPagesElement> {
|
|
28
|
-
name = PLUGIN_NAME;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Renders a Kita component boundary for component-level orchestration.
|
|
32
|
-
*
|
|
33
|
-
* Includes component-scoped dependency assets when declared.
|
|
34
|
-
*/
|
|
35
|
-
override async renderComponent(input: ComponentRenderInput): Promise<ComponentRenderResult> {
|
|
36
|
-
const component = input.component as KitaViewFn<Record<string, unknown>>;
|
|
37
|
-
const props = input.children === undefined ? input.props : { ...input.props, children: input.children };
|
|
38
|
-
const content = await component(props);
|
|
39
|
-
const html = String(content);
|
|
40
|
-
const hasDependencies = Boolean(input.component.config?.dependencies);
|
|
41
|
-
const canResolveAssets = typeof this.assetProcessingService?.processDependencies === 'function';
|
|
42
|
-
const assets =
|
|
43
|
-
hasDependencies && canResolveAssets
|
|
44
|
-
? await this.processComponentDependencies([input.component])
|
|
45
|
-
: undefined;
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
html,
|
|
49
|
-
canAttachAttributes: true,
|
|
50
|
-
rootTag: this.getRootTagName(html),
|
|
51
|
-
integrationName: this.name,
|
|
52
|
-
assets,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async render({
|
|
57
|
-
params,
|
|
58
|
-
query,
|
|
59
|
-
props,
|
|
60
|
-
locals,
|
|
61
|
-
pageLocals,
|
|
62
|
-
metadata,
|
|
63
|
-
Page,
|
|
64
|
-
Layout,
|
|
65
|
-
HtmlTemplate,
|
|
66
|
-
}: IntegrationRendererRenderOptions): Promise<RouteRendererBody> {
|
|
67
|
-
try {
|
|
68
|
-
const pageContent = await Page({ params, query, ...props, locals: pageLocals });
|
|
69
|
-
const children =
|
|
70
|
-
Layout && typeof Layout === 'function' ? await Layout({ children: pageContent, locals }) : pageContent;
|
|
71
|
-
const body = await HtmlTemplate({
|
|
72
|
-
metadata,
|
|
73
|
-
pageProps: props ?? {},
|
|
74
|
-
children,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return this.DOC_TYPE + body;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
throw this.createRenderError('Error rendering page', error);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async renderToResponse<P = Record<string, unknown>>(
|
|
84
|
-
view: EcoComponent<P>,
|
|
85
|
-
props: P,
|
|
86
|
-
ctx: RenderToResponseContext,
|
|
87
|
-
): Promise<Response> {
|
|
88
|
-
try {
|
|
89
|
-
const Layout = view.config?.layout as KitaLayoutFn | undefined;
|
|
90
|
-
|
|
91
|
-
const viewFn = view as KitaViewFn<P>;
|
|
92
|
-
const pageContent = await viewFn(props);
|
|
93
|
-
|
|
94
|
-
if (ctx.partial) {
|
|
95
|
-
return this.createHtmlResponse(pageContent, ctx);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const children = Layout ? await Layout({ children: pageContent }) : pageContent;
|
|
99
|
-
|
|
100
|
-
const HtmlTemplate = await this.getHtmlTemplate();
|
|
101
|
-
const metadata = view.metadata
|
|
102
|
-
? await view.metadata({
|
|
103
|
-
params: {},
|
|
104
|
-
query: {},
|
|
105
|
-
props: props as Record<string, unknown>,
|
|
106
|
-
appConfig: this.appConfig,
|
|
107
|
-
})
|
|
108
|
-
: this.appConfig.defaultMetadata;
|
|
109
|
-
await this.prepareViewDependencies(view, Layout as EcoComponent | undefined);
|
|
110
|
-
|
|
111
|
-
const html =
|
|
112
|
-
this.DOC_TYPE +
|
|
113
|
-
(await HtmlTemplate({
|
|
114
|
-
metadata,
|
|
115
|
-
pageProps: props as Record<string, unknown>,
|
|
116
|
-
children: children ?? '',
|
|
117
|
-
}));
|
|
118
|
-
|
|
119
|
-
const transformedResponse = await this.htmlTransformer.transform(
|
|
120
|
-
new Response(html, {
|
|
121
|
-
headers: { 'Content-Type': 'text/html' },
|
|
122
|
-
}),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
return this.createHtmlResponse(transformedResponse.body ?? '', ctx);
|
|
126
|
-
} catch (error) {
|
|
127
|
-
throw this.createRenderError('Error rendering view', error);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
package/src/kitajs.plugin.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { IntegrationPlugin, type IntegrationPluginConfig } from '@ecopages/core/plugins/integration-plugin';
|
|
2
|
-
import { KitaRenderer } from './kitajs-renderer.ts';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The name of the Kita.js plugin
|
|
6
|
-
*/
|
|
7
|
-
export const PLUGIN_NAME = 'kitajs';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The Kita.js plugin class
|
|
11
|
-
* This plugin provides support for Kita.js components in Ecopages
|
|
12
|
-
*/
|
|
13
|
-
export class KitaHtmlPlugin extends IntegrationPlugin {
|
|
14
|
-
renderer = KitaRenderer;
|
|
15
|
-
|
|
16
|
-
constructor(options?: Omit<IntegrationPluginConfig, 'name'>) {
|
|
17
|
-
super({
|
|
18
|
-
name: PLUGIN_NAME,
|
|
19
|
-
extensions: ['.kita.tsx'],
|
|
20
|
-
...options,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Factory function to create a Kita.js plugin instance.
|
|
27
|
-
* @param options Configuration options for the Kita.js plugin
|
|
28
|
-
* @returns A new KitaHtmlPlugin instance
|
|
29
|
-
*/
|
|
30
|
-
export function kitajsPlugin(options?: Omit<IntegrationPluginConfig, 'name'>): KitaHtmlPlugin {
|
|
31
|
-
return new KitaHtmlPlugin(options);
|
|
32
|
-
}
|