From 641b709703f33be55eb36d4dc4667fcf800caad8 Mon Sep 17 00:00:00 2001 From: july Date: Sun, 1 Mar 2026 10:20:57 -0300 Subject: [PATCH] feat: slot-based layout --- deno.json | 2 +- src/layout.tsx | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/layout.tsx 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})} + + + ); +} -- knotmirror 0.0.1