import { RefProps, VNode } from 'lupine.web'; // load async html /* { return ; }} > */ export type HtmlLoadHookProps = { getRef?: () => RefProps; render?: (html: string | VNode) => void; }; export type HtmlLoadProps = { html: () => Promise>; initialHtml?: string | VNode; hook?: HtmlLoadHookProps; }; export const HtmlLoad = (props: HtmlLoadProps) => { const ref: RefProps = { onLoad: async (el: Element) => { const dom = await props.html(); await ref.mountInnerComponent!(dom); }, }; if (props.hook) { props.hook.getRef = () => ref; props.hook.render = (html: string | VNode) => { ref.mountInnerComponent!(html); }; } return { type: 'Fragment', props: { ref: ref, children: props.initialHtml || '', }, html: [], }; };