feat(sdk, plugins): jsx support

This commit is contained in:
Artemy
2024-05-13 16:35:36 +03:00
parent bdf625bb1f
commit 3cee45b591
11 changed files with 58 additions and 15 deletions

24
packages/sdk/src/jsx.ts Normal file
View File

@ -0,0 +1,24 @@
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace JSX {
export type Element = string;
export interface IntrinsicElements {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[elemName: string]: any;
}
}
export function createElement(
name: string,
props: { [id: string]: string },
...content: string[]
) {
props = props || {};
const propsstr = Object.keys(props)
.map((key) => {
const value = props[key];
if (key === 'className') return `class=${value}`;
else return `${key}=${value}`;
})
.join(' ');
return `<${name} ${propsstr}>${content.join('')}</${name}>`;
}

View File

@ -18,6 +18,8 @@ import {
handlerSchema,
} from './types/handler';
import * as JSX from './jsx';
export {
Engine,
EngineParseError,
@ -32,4 +34,5 @@ export {
HandlerOutput,
Route,
handlerSchema,
JSX,
};

View File

@ -33,7 +33,7 @@ export interface HandlerOutput {
}
export interface EngineOutput {
document: Document;
content: string;
textContent?: string;
title?: string;
lang?: string;