Add jdd_html helper function for rendering a page with one or more JDDs in it
This commit is contained in:
parent
140fb13b6a
commit
1668b92793
32
src/back/jdd-html.tsx
Normal file
32
src/back/jdd-html.tsx
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { JDD, type RawJDDocument } from "@sealcode/jdd";
|
||||||
|
import html from "./html.js";
|
||||||
|
import { makeJDDContext } from "./jdd-context.js";
|
||||||
|
import { registry } from "./jdd-components/registry.js";
|
||||||
|
import { tempstream } from "tempstream";
|
||||||
|
|
||||||
|
export type JDDHtmlArgs = Omit<Parameters<typeof html>["0"], "body"> & {
|
||||||
|
raw_jdds: RawJDDocument[];
|
||||||
|
construct_body: (built_jdd_html: JSX.Element) => JSX.Element;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function jdd_html(args: JDDHtmlArgs) {
|
||||||
|
const jdd_context = makeJDDContext(args.ctx);
|
||||||
|
const jdds = await Promise.all(
|
||||||
|
args.raw_jdds.map((raw_jdd) => JDD.fromStorage(registry, jdd_context, raw_jdd))
|
||||||
|
);
|
||||||
|
const css_clumps = Array.from(
|
||||||
|
new Set([
|
||||||
|
...(args?.css_clumps || []),
|
||||||
|
...jdds.map((jdd) => jdd.getAllCSSClumps()).flat(),
|
||||||
|
]).values()
|
||||||
|
);
|
||||||
|
let built_jdd_html = tempstream``;
|
||||||
|
for (const jdd of jdds) {
|
||||||
|
built_jdd_html = tempstream`${built_jdd_html}${jdd.render()}`;
|
||||||
|
}
|
||||||
|
return html({
|
||||||
|
css_clumps,
|
||||||
|
...args,
|
||||||
|
body: args.construct_body(built_jdd_html),
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user