From c37011eeddd28cba4a6cb3aca6535dfd98b223ff Mon Sep 17 00:00:00 2001 From: "moxey.eth" Date: Tue, 13 Feb 2024 09:16:29 +1100 Subject: [PATCH] wip --- src/jsx/jsx-dev-runtime/index.ts | 25 ++++++++++++++++++++++++- src/jsx/jsx-runtime/index.ts | 9 ++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/jsx/jsx-dev-runtime/index.ts b/src/jsx/jsx-dev-runtime/index.ts index dd9b7aa7..a6e123ac 100644 --- a/src/jsx/jsx-dev-runtime/index.ts +++ b/src/jsx/jsx-dev-runtime/index.ts @@ -1 +1,24 @@ -export * from 'hono/jsx/jsx-dev-runtime' +import { type JSXNode, jsx } from 'hono/jsx' +import type { HtmlEscapedString } from 'hono/utils/html' +export { Fragment } from 'hono/jsx' + +export function jsxDEV( + tag: string | Function, + props: Record, + key?: string, +): JSXNode { + let node: JSXNode + if (!props || !('children' in props)) { + node = jsx(tag, props, ...[]) + } else { + const children = props.children as string | HtmlEscapedString + // biome-ignore lint/performance/noDelete: + // biome-ignore lint/complexity/useLiteralKeys: + delete props['children'] + node = Array.isArray(children) + ? jsx(tag, props, ...children) + : jsx(tag, props, ...[children]) + } + node.key = key + return node +} diff --git a/src/jsx/jsx-runtime/index.ts b/src/jsx/jsx-runtime/index.ts index d50577b7..b04b6d23 100644 --- a/src/jsx/jsx-runtime/index.ts +++ b/src/jsx/jsx-runtime/index.ts @@ -1 +1,8 @@ -export * from 'hono/jsx/jsx-runtime' +export { jsxDEV as jsx, Fragment } from '../jsx-dev-runtime/index.js' +export { jsxDEV as jsxs } from '../jsx-dev-runtime/index.js' + +import { html, raw } from 'hono/html' +export { html as jsxTemplate } +export const jsxAttr = (name: string, value: string) => + raw(`${name}="${html`${value}`}"`) +export const jsxEscape = (value: string) => value