@ecopages/kitajs 0.2.0-alpha.9 → 0.2.0-beta.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/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # @ecopages/kitajs
2
2
 
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.
3
+ Integration plugin for [KitaJS](https://kitajs.org/html/) HTML in Ecopages. Use it when Kita should own `.kita.tsx` routes, page shells, and document shells in HTML-first apps.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- bunx jsr add @ecopages/kitajs
8
+ bun add @ecopages/kitajs @kitajs/html @kitajs/ts-html-plugin
9
9
  ```
10
10
 
11
+ `@kitajs/html` and `@kitajs/ts-html-plugin` are required peer dependencies for this package.
12
+
11
13
  ## Usage
12
14
 
13
15
  Import and register the `kitajsPlugin` in your `eco.config.ts`.
@@ -23,3 +25,19 @@ const config = await new ConfigBuilder()
23
25
 
24
26
  export default config;
25
27
  ```
28
+
29
+ ## What This Integration Owns
30
+
31
+ - `.kita.tsx` route files.
32
+ - Page, layout, and document shells rendered by `@kitajs/html`.
33
+ - HTML-first outer shells that host nested foreign subtrees from other integrations.
34
+
35
+ ## Mixed Rendering
36
+
37
+ Kita works well as the outer renderer in mixed apps. When a Kita-owned page encounters a nested foreign child from another integration, Ecopages resolves that foreign subtree with its owning renderer and inserts the resulting HTML back into the Kita shell.
38
+
39
+ Important:
40
+
41
+ - Components that may render foreign children must declare those children in `config.dependencies.components`.
42
+ - Ecopages validates mixed-renderer ownership from declared dependencies during render preparation instead of inferring every foreign child from rendered HTML.
43
+ - Kita remains an HTML-first outer shell. Same-integration Kita children do not go through a separate universal child serialization contract.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/kitajs",
3
- "version": "0.2.0-alpha.9",
3
+ "version": "0.2.0-beta.1",
4
4
  "description": "Kitajs plugin for Ecopages",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -11,13 +11,27 @@
11
11
  "main": "./src/kitajs.plugin.js",
12
12
  "types": "./src/kitajs.plugin.d.ts",
13
13
  "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "default": "./src/kitajs.plugin.js",
17
+ "types": "./src/kitajs.plugin.d.ts"
18
+ },
19
+ "./eco-embed": {
20
+ "default": "./src/eco-embed.js",
21
+ "types": "./src/eco-embed.d.ts"
22
+ },
23
+ "./eco-embed.ts": {
24
+ "default": "./src/eco-embed.js",
25
+ "types": "./src/eco-embed.d.ts"
26
+ }
27
+ },
14
28
  "repository": {
15
29
  "type": "git",
16
30
  "url": "https://github.com/ecopages/ecopages.git",
17
31
  "directory": "packages/integrations/kitajs"
18
32
  },
19
33
  "peerDependencies": {
20
- "@ecopages/core": "0.2.0-alpha.9",
34
+ "@ecopages/core": "0.2.0-beta.1",
21
35
  "@kitajs/html": "^4.1.0",
22
36
  "@kitajs/ts-html-plugin": "^4.0.1"
23
37
  }
@@ -0,0 +1,10 @@
1
+ import type { EcoComponent, EcoEmbedProps as CoreEcoEmbedProps, EcoPagesElement } from '@ecopages/core';
2
+ /**
3
+ * Props for the Kita-owned `EcoEmbed` adapter.
4
+ */
5
+ export type EcoEmbedProps<TComponent extends EcoComponent> = CoreEcoEmbedProps<TComponent>;
6
+ /**
7
+ * Renders a foreign or same-integration eco component from a Kita JSX file
8
+ * without forcing inline mixed-JSX authoring.
9
+ */
10
+ export declare function EcoEmbed<TComponent extends EcoComponent>({ component, props, children, }: EcoEmbedProps<TComponent>): EcoPagesElement;
@@ -0,0 +1,11 @@
1
+ import { eco } from "@ecopages/core";
2
+ function EcoEmbed({
3
+ component,
4
+ props,
5
+ children
6
+ }) {
7
+ return eco.embed(component, props, children);
8
+ }
9
+ export {
10
+ EcoEmbed
11
+ };
@@ -10,8 +10,9 @@ import { IntegrationRenderer, type RenderToResponseContext } from '@ecopages/cor
10
10
  */
11
11
  export declare class KitaRenderer extends IntegrationRenderer<EcoPagesElement> {
12
12
  name: string;
13
+ private isFunctionComponent;
13
14
  /**
14
- * Renders a Kita component boundary for component-level orchestration.
15
+ * Renders a Kita-owned foreign subtree for component-level orchestration.
15
16
  *
16
17
  * Includes component-scoped dependency assets when declared.
17
18
  */
@@ -1,27 +1,20 @@
1
1
  import { IntegrationRenderer } from "@ecopages/core/route-renderer/integration-renderer";
2
- import { PLUGIN_NAME } from "./kitajs.plugin.js";
2
+ import { KITAJS_PLUGIN_NAME } from "./kitajs.constants.js";
3
3
  class KitaRenderer extends IntegrationRenderer {
4
- name = PLUGIN_NAME;
4
+ name = KITAJS_PLUGIN_NAME;
5
+ isFunctionComponent(component) {
6
+ return typeof component === "function";
7
+ }
5
8
  /**
6
- * Renders a Kita component boundary for component-level orchestration.
9
+ * Renders a Kita-owned foreign subtree for component-level orchestration.
7
10
  *
8
11
  * Includes component-scoped dependency assets when declared.
9
12
  */
10
13
  async renderComponent(input) {
11
- const component = input.component;
12
- const props = input.children === void 0 ? input.props : { ...input.props, children: input.children };
13
- const content = await component(props);
14
- const html = String(content);
15
- const hasDependencies = Boolean(input.component.config?.dependencies);
16
- const canResolveAssets = typeof this.assetProcessingService?.processDependencies === "function";
17
- const assets = hasDependencies && canResolveAssets ? await this.processComponentDependencies([input.component]) : void 0;
18
- return {
19
- html,
20
- canAttachAttributes: true,
21
- rootTag: this.getRootTagName(html),
22
- integrationName: this.name,
23
- assets
24
- };
14
+ if (!this.isFunctionComponent(input.component)) {
15
+ throw new TypeError("Kita renderer expected a callable component.");
16
+ }
17
+ return this.renderStringComponentWithQueuedForeignSubtrees(input, input.component);
25
18
  }
26
19
  async render({
27
20
  params,
@@ -35,52 +28,31 @@ class KitaRenderer extends IntegrationRenderer {
35
28
  HtmlTemplate
36
29
  }) {
37
30
  try {
38
- const pageContent = await Page({ params, query, ...props, locals: pageLocals });
39
- const children = Layout && typeof Layout === "function" ? await Layout({ children: pageContent, locals }) : pageContent;
40
- const body = await HtmlTemplate({
31
+ return await this.renderPageWithDocumentShell({
32
+ page: {
33
+ component: Page,
34
+ props: { params, query, ...props, locals: pageLocals }
35
+ },
36
+ layout: Layout ? {
37
+ component: Layout,
38
+ props: locals ? { locals } : {}
39
+ } : void 0,
40
+ htmlTemplate: HtmlTemplate,
41
41
  metadata,
42
- pageProps: props ?? {},
43
- children
42
+ pageProps: props ?? {}
44
43
  });
45
- return this.DOC_TYPE + body;
46
44
  } catch (error) {
47
45
  throw this.createRenderError("Error rendering page", error);
48
46
  }
49
47
  }
50
48
  async renderToResponse(view, props, ctx) {
51
49
  try {
52
- const Layout = view.config?.layout;
53
- const HtmlTemplate = ctx.partial ? void 0 : await this.getHtmlTemplate();
54
- const metadata = ctx.partial || !HtmlTemplate ? void 0 : view.metadata ? await view.metadata({
55
- params: {},
56
- query: {},
50
+ return await this.renderViewWithDocumentShell({
51
+ view,
57
52
  props,
58
- appConfig: this.appConfig
59
- }) : this.appConfig.defaultMetadata;
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
53
+ ctx,
54
+ layout: view.config?.layout
82
55
  });
83
- return this.createHtmlResponse(body, ctx);
84
56
  } catch (error) {
85
57
  throw this.createRenderError("Error rendering view", error);
86
58
  }
@@ -0,0 +1 @@
1
+ export declare const KITAJS_PLUGIN_NAME = "kitajs";
@@ -0,0 +1,4 @@
1
+ const KITAJS_PLUGIN_NAME = "kitajs";
2
+ export {
3
+ KITAJS_PLUGIN_NAME
4
+ };
@@ -1,12 +1,14 @@
1
1
  import { IntegrationPlugin } from "@ecopages/core/plugins/integration-plugin";
2
2
  import { KitaRenderer } from "./kitajs-renderer.js";
3
- const PLUGIN_NAME = "kitajs";
3
+ import { KITAJS_PLUGIN_NAME } from "./kitajs.constants.js";
4
+ const PLUGIN_NAME = KITAJS_PLUGIN_NAME;
4
5
  class KitaHtmlPlugin extends IntegrationPlugin {
5
6
  renderer = KitaRenderer;
6
7
  constructor(options) {
7
8
  super({
8
9
  name: PLUGIN_NAME,
9
10
  extensions: [".kita.tsx"],
11
+ jsxImportSource: "@kitajs/html",
10
12
  ...options
11
13
  });
12
14
  }
package/CHANGELOG.md DELETED
@@ -1,23 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to `@ecopages/kitajs` are documented here.
4
-
5
- > **Note:** Changelog tracking begins at version `0.2.0`. Changes prior to this release are not recorded here but are available in the git history.
6
-
7
- ## [UNRELEASED] — TBD
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
-
13
- ### Features
14
-
15
- - Aligned KitaJS with the unified orchestration pipeline.
16
-
17
- ### Refactoring
18
-
19
- - Tightened Kita component typing and cleaned up ambient module declarations.
20
-
21
- ### Tests
22
-
23
- - Updated integration coverage for the orchestration pipeline and Node and esbuild compatibility.
@@ -1,141 +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
- const HtmlTemplate = ctx.partial ? undefined : await this.getHtmlTemplate();
91
- const metadata =
92
- ctx.partial || !HtmlTemplate
93
- ? undefined
94
- : view.metadata
95
- ? await view.metadata({
96
- params: {},
97
- query: {},
98
- props: props as Record<string, unknown>,
99
- appConfig: this.appConfig,
100
- })
101
- : this.appConfig.defaultMetadata;
102
-
103
- if (!ctx.partial) {
104
- await this.prepareViewDependencies(view, Layout as EcoComponent | undefined);
105
- }
106
-
107
- const viewFn = view as KitaViewFn<P>;
108
- const renderExecution = await this.captureHtmlRender(async () => {
109
- const pageContent = await viewFn(props);
110
-
111
- if (ctx.partial) {
112
- return pageContent;
113
- }
114
-
115
- const children = Layout ? await Layout({ children: pageContent }) : pageContent;
116
- return (
117
- this.DOC_TYPE +
118
- (await HtmlTemplate!({
119
- metadata: metadata ?? this.appConfig.defaultMetadata,
120
- pageProps: (props as Record<string, unknown>) ?? {},
121
- children: children ?? '',
122
- }))
123
- );
124
- });
125
-
126
- const componentsToResolve = ctx.partial
127
- ? [view]
128
- : ([HtmlTemplate, Layout, view].filter(Boolean) as EcoComponent[]);
129
- const body = await this.finalizeCapturedHtmlRender({
130
- html: renderExecution.html,
131
- componentsToResolve,
132
- graphContext: renderExecution.graphContext,
133
- partial: ctx.partial,
134
- });
135
-
136
- return this.createHtmlResponse(body, ctx);
137
- } catch (error) {
138
- throw this.createRenderError('Error rendering view', error);
139
- }
140
- }
141
- }
@@ -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
- }