diff --git a/deno.json b/deno.json index b162910..d92e480 100644 --- a/deno.json +++ b/deno.json @@ -24,7 +24,7 @@ ] }, "compilerOptions": { - "jsx": "precompile", + "jsx": "react-jsx", "jsxImportSource": "@july/snarl", "lib": ["deno.ns", "dom", "dom.iterable"] }, diff --git a/src/layout.tsx b/src/layout.tsx new file mode 100644 index 0000000..dac9297 --- /dev/null +++ b/src/layout.tsx @@ -0,0 +1,39 @@ +import { Context } from "@july/snarl"; +import { JsxElement } from "@july/snarl/jsx-runtime"; + +export interface LayoutProps { + children?: JsxElement | JsxElement[]; +} + +function flatten(arr: any[]): any[] { + return arr.flatMap((x) => Array.isArray(x) ? flatten(x) : x); +} + +export function Layout(props: LayoutProps = {}) { + const children = flatten(props.children ? (Array.isArray(props.children) ? props.children : [props.children]) : []); + const head: JsxElement[] = [], body: JsxElement[] = [], main: JsxElement[] = []; + + for (const child of children) { + if (child?.tag === "head") { + head.push(...child.props?.children ?? []); + } else if (child?.tag === "body") { + body.push(...child.props?.children ?? []); + } else { + main.push(child); + } + } + + return ( + +
+ + + {head.map((node) => <>{node}>)} + + + {main.map((node, i) => <>{node}>)} + {body.map((node, i) => <>{node}>)} + + + ); +}