Comparing version 0.1.1 to 0.1.2
@@ -1,2 +0,2 @@ | ||
import { Hydrate, CreateElement } from '../types.js'; | ||
import { Hydrate, CreateElement, CreateChildren } from '../types.js'; | ||
@@ -6,2 +6,6 @@ type ClientOptions = { | ||
createElement?: CreateElement; | ||
/** | ||
* Create "children" attribute of a component from a list of child nodes | ||
*/ | ||
createChildren?: CreateChildren; | ||
ISLAND_FILES?: Record<string, () => Promise<unknown>>; | ||
@@ -8,0 +12,0 @@ island_root?: string; |
import { render } from "hono/jsx/dom"; | ||
import { jsx as jsxFn } from "hono/jsx/dom/jsx-runtime"; | ||
import { COMPONENT_NAME, DATA_SERIALIZED_PROPS } from "../constants.js"; | ||
import { COMPONENT_NAME, DATA_HONO_TEMPLATE, DATA_SERIALIZED_PROPS } from "../constants.js"; | ||
const createClient = async (options) => { | ||
@@ -20,2 +20,13 @@ const FILES = options?.ISLAND_FILES ?? import.meta.glob("/app/islands/**/[a-zA-Z0-9[-]+.(tsx|ts)"); | ||
const createElement = options?.createElement ?? jsxFn; | ||
const maybeTemplate = element.childNodes[element.childNodes.length - 1]; | ||
if (maybeTemplate?.nodeName === "TEMPLATE" && maybeTemplate?.attributes.getNamedItem(DATA_HONO_TEMPLATE) !== null) { | ||
let createChildren = options?.createChildren; | ||
if (!createChildren) { | ||
const { buildCreateChildrenFn } = await import("./runtime"); | ||
createChildren = buildCreateChildrenFn(createElement); | ||
} | ||
props.children = await createChildren( | ||
maybeTemplate.content.childNodes | ||
); | ||
} | ||
const newElem = await createElement(Component, props); | ||
@@ -22,0 +33,0 @@ await hydrate(newElem, element); |
declare const COMPONENT_NAME = "component-name"; | ||
declare const DATA_SERIALIZED_PROPS = "data-serialized-props"; | ||
declare const DATA_HONO_TEMPLATE = "data-hono-template"; | ||
declare const IMPORTING_ISLANDS_ID: "__importing_islands"; | ||
export { COMPONENT_NAME, DATA_SERIALIZED_PROPS, IMPORTING_ISLANDS_ID }; | ||
export { COMPONENT_NAME, DATA_HONO_TEMPLATE, DATA_SERIALIZED_PROPS, IMPORTING_ISLANDS_ID }; |
const COMPONENT_NAME = "component-name"; | ||
const DATA_SERIALIZED_PROPS = "data-serialized-props"; | ||
const DATA_HONO_TEMPLATE = "data-hono-template"; | ||
const IMPORTING_ISLANDS_ID = "__importing_islands"; | ||
export { | ||
COMPONENT_NAME, | ||
DATA_HONO_TEMPLATE, | ||
DATA_SERIALIZED_PROPS, | ||
IMPORTING_ISLANDS_ID | ||
}; |
@@ -6,2 +6,3 @@ import { FC } from 'hono/jsx'; | ||
src: string; | ||
async?: boolean; | ||
prod?: boolean; | ||
@@ -8,0 +9,0 @@ manifest?: Manifest; |
@@ -21,3 +21,10 @@ import { Fragment, jsx } from "hono/jsx/jsx-runtime"; | ||
if (scriptInManifest) { | ||
return /* @__PURE__ */ jsx(HasIslands, { children: /* @__PURE__ */ jsx("script", { type: "module", src: `/${scriptInManifest.file}` }) }); | ||
return /* @__PURE__ */ jsx(HasIslands, { children: /* @__PURE__ */ jsx( | ||
"script", | ||
{ | ||
type: "module", | ||
async: !!options.async, | ||
src: `/${scriptInManifest.file}` | ||
} | ||
) }); | ||
} | ||
@@ -27,3 +34,3 @@ } | ||
} else { | ||
return /* @__PURE__ */ jsx("script", { type: "module", src }); | ||
return /* @__PURE__ */ jsx("script", { type: "module", async: !!options.async, src }); | ||
} | ||
@@ -30,0 +37,0 @@ }; |
@@ -90,3 +90,3 @@ import { Hono } from "hono"; | ||
subApp.get(path, (c) => { | ||
return c.render(routeDefault(), route); | ||
return c.render(routeDefault(c), route); | ||
}); | ||
@@ -93,0 +93,0 @@ } |
/** JSX */ | ||
type CreateElement = (type: any, props: any) => Node | Promise<Node>; | ||
type Hydrate = (children: Node, parent: Element) => void | Promise<void>; | ||
type CreateChildren = (childNodes: NodeListOf<ChildNode>) => Node[] | Promise<Node[]>; | ||
export type { CreateElement, Hydrate }; | ||
export type { CreateChildren, CreateElement, Hydrate }; |
const filePathToPath = (filePath) => { | ||
filePath = filePath.replace(/\.tsx?$/g, "").replace(/\.mdx$/g, "").replace(/^\/?index/, "/").replace(/\/index/, "").replace(/\[\.{3}.+\]/, "*").replace(/\[(.+)\]/, ":$1"); | ||
filePath = filePath.replace(/\.tsx?$/g, "").replace(/\.mdx$/g, "").replace(/^\/?index$/, "/").replace(/\/index$/, "").replace(/\[\.{3}.+\]/, "*").replace(/\[(.+?)\]/g, ":$1"); | ||
return /^\//.test(filePath) ? filePath : "/" + filePath; | ||
@@ -4,0 +4,0 @@ }; |
@@ -27,3 +27,3 @@ import fs from "fs/promises"; | ||
} from "@babel/types"; | ||
import { COMPONENT_NAME, DATA_SERIALIZED_PROPS } from "../constants.js"; | ||
import { COMPONENT_NAME, DATA_HONO_TEMPLATE, DATA_SERIALIZED_PROPS } from "../constants.js"; | ||
function addSSRCheck(funcName, componentName, isAsync = false) { | ||
@@ -34,3 +34,15 @@ const isSSR = memberExpression( | ||
); | ||
const serializedProps = callExpression(identifier("JSON.stringify"), [identifier("props")]); | ||
const serializedProps = callExpression(identifier("JSON.stringify"), [ | ||
callExpression(memberExpression(identifier("Object"), identifier("fromEntries")), [ | ||
callExpression( | ||
memberExpression( | ||
callExpression(memberExpression(identifier("Object"), identifier("entries")), [ | ||
identifier("props") | ||
]), | ||
identifier("filter") | ||
), | ||
[identifier('([key]) => key !== "children"')] | ||
) | ||
]) | ||
]); | ||
const ssrElement = jsxElement( | ||
@@ -55,2 +67,17 @@ jsxOpeningElement( | ||
[] | ||
), | ||
jsxExpressionContainer( | ||
conditionalExpression( | ||
memberExpression(identifier("props"), identifier("children")), | ||
jsxElement( | ||
jsxOpeningElement( | ||
jsxIdentifier("template"), | ||
[jsxAttribute(jsxIdentifier(DATA_HONO_TEMPLATE), stringLiteral(""))], | ||
false | ||
), | ||
jsxClosingElement(jsxIdentifier("template")), | ||
[jsxExpressionContainer(memberExpression(identifier("props"), identifier("children")))] | ||
), | ||
identifier("null") | ||
) | ||
) | ||
@@ -57,0 +84,0 @@ ] |
{ | ||
"name": "honox", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"main": "dist/index.js", | ||
@@ -116,3 +116,3 @@ "type": "module", | ||
"glob": "^10.3.10", | ||
"hono": "^4.0.1", | ||
"hono": "^4.0.3", | ||
"np": "7.7.0", | ||
@@ -119,0 +119,0 @@ "prettier": "^3.1.1", |
@@ -160,3 +160,3 @@ # HonoX | ||
```tsx | ||
export default function Home() { | ||
export default function Home(_c: Context) { | ||
return <h1>Welcome!</h1> | ||
@@ -163,0 +163,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64540
47
965