@ecopages/kitajs 0.2.0-alpha.1 → 0.2.0-alpha.11
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 +28 -20
- package/src/kitajs.plugin.d.ts +2 -1
- package/src/kitajs.plugin.js +7 -1
- 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 direct `ctx.render()` flows and mixed-integration Kita boundaries to resolve through the marker pipeline.
|
|
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.11",
|
|
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.11",
|
|
21
21
|
"@kitajs/html": "^4.1.0",
|
|
22
22
|
"@kitajs/ts-html-plugin": "^4.0.1"
|
|
23
23
|
}
|
package/src/kitajs-renderer.js
CHANGED
|
@@ -36,7 +36,8 @@ class KitaRenderer extends IntegrationRenderer {
|
|
|
36
36
|
}) {
|
|
37
37
|
try {
|
|
38
38
|
const pageContent = await Page({ params, query, ...props, locals: pageLocals });
|
|
39
|
-
const
|
|
39
|
+
const pageHtml = String(pageContent);
|
|
40
|
+
const children = Layout && typeof Layout === "function" ? await Layout({ children: pageHtml, locals }) : pageHtml;
|
|
40
41
|
const body = await HtmlTemplate({
|
|
41
42
|
metadata,
|
|
42
43
|
pageProps: props ?? {},
|
|
@@ -50,31 +51,38 @@ class KitaRenderer extends IntegrationRenderer {
|
|
|
50
51
|
async renderToResponse(view, props, ctx) {
|
|
51
52
|
try {
|
|
52
53
|
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({
|
|
54
|
+
const HtmlTemplate = ctx.partial ? void 0 : await this.getHtmlTemplate();
|
|
55
|
+
const metadata = ctx.partial || !HtmlTemplate ? void 0 : view.metadata ? await view.metadata({
|
|
61
56
|
params: {},
|
|
62
57
|
query: {},
|
|
63
58
|
props,
|
|
64
59
|
appConfig: this.appConfig
|
|
65
60
|
}) : this.appConfig.defaultMetadata;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
if (!ctx.partial) {
|
|
62
|
+
await this.prepareViewDependencies(view, Layout);
|
|
63
|
+
}
|
|
64
|
+
const viewFn = view;
|
|
65
|
+
const renderExecution = await this.captureHtmlRender(async () => {
|
|
66
|
+
const pageContent = await viewFn(props);
|
|
67
|
+
const pageHtml = String(pageContent);
|
|
68
|
+
if (ctx.partial) {
|
|
69
|
+
return pageHtml;
|
|
70
|
+
}
|
|
71
|
+
const children = Layout ? await Layout({ children: pageHtml }) : pageHtml;
|
|
72
|
+
return this.DOC_TYPE + await HtmlTemplate({
|
|
73
|
+
metadata: metadata ?? this.appConfig.defaultMetadata,
|
|
74
|
+
pageProps: props ?? {},
|
|
75
|
+
children: children ?? ""
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
const componentsToResolve = ctx.partial ? [view] : [HtmlTemplate, Layout, view].filter(Boolean);
|
|
79
|
+
const body = await this.finalizeCapturedHtmlRender({
|
|
80
|
+
html: renderExecution.html,
|
|
81
|
+
componentsToResolve,
|
|
82
|
+
graphContext: renderExecution.graphContext,
|
|
83
|
+
partial: ctx.partial
|
|
71
84
|
});
|
|
72
|
-
|
|
73
|
-
new Response(html, {
|
|
74
|
-
headers: { "Content-Type": "text/html" }
|
|
75
|
-
})
|
|
76
|
-
);
|
|
77
|
-
return this.createHtmlResponse(transformedResponse.body ?? "", ctx);
|
|
85
|
+
return this.createHtmlResponse(body, ctx);
|
|
78
86
|
} catch (error) {
|
|
79
87
|
throw this.createRenderError("Error rendering view", error);
|
|
80
88
|
}
|
package/src/kitajs.plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IntegrationPlugin, type IntegrationPluginConfig } from '@ecopages/core/plugins/integration-plugin';
|
|
1
|
+
import { IntegrationPlugin, type ComponentBoundaryPolicyInput, type IntegrationPluginConfig } from '@ecopages/core/plugins/integration-plugin';
|
|
2
2
|
import { KitaRenderer } from './kitajs-renderer.js';
|
|
3
3
|
/**
|
|
4
4
|
* The name of the Kita.js plugin
|
|
@@ -11,6 +11,7 @@ export declare const PLUGIN_NAME = "kitajs";
|
|
|
11
11
|
export declare class KitaHtmlPlugin extends IntegrationPlugin {
|
|
12
12
|
renderer: typeof KitaRenderer;
|
|
13
13
|
constructor(options?: Omit<IntegrationPluginConfig, 'name'>);
|
|
14
|
+
shouldDeferComponentBoundary(input: ComponentBoundaryPolicyInput): boolean;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Factory function to create a Kita.js plugin instance.
|
package/src/kitajs.plugin.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
IntegrationPlugin
|
|
3
|
+
} from "@ecopages/core/plugins/integration-plugin";
|
|
2
4
|
import { KitaRenderer } from "./kitajs-renderer.js";
|
|
3
5
|
const PLUGIN_NAME = "kitajs";
|
|
4
6
|
class KitaHtmlPlugin extends IntegrationPlugin {
|
|
@@ -7,9 +9,13 @@ class KitaHtmlPlugin extends IntegrationPlugin {
|
|
|
7
9
|
super({
|
|
8
10
|
name: PLUGIN_NAME,
|
|
9
11
|
extensions: [".kita.tsx"],
|
|
12
|
+
jsxImportSource: "@kitajs/html",
|
|
10
13
|
...options
|
|
11
14
|
});
|
|
12
15
|
}
|
|
16
|
+
shouldDeferComponentBoundary(input) {
|
|
17
|
+
return input.targetIntegration === this.name && input.currentIntegration !== this.name;
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
20
|
function kitajsPlugin(options) {
|
|
15
21
|
return new KitaHtmlPlugin(options);
|
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
|
-
}
|