diff options
Diffstat (limited to 'src/frontend')
-rw-r--r-- | src/frontend/h.ts | 5 | ||||
-rw-r--r-- | src/frontend/render/preact.ts | 28 | ||||
-rw-r--r-- | src/frontend/render/svelte.ts | 4 | ||||
-rw-r--r-- | src/frontend/render/vue.ts | 8 |
4 files changed, 22 insertions, 23 deletions
diff --git a/src/frontend/h.ts b/src/frontend/h.ts index 3ba0541e8..77ecf857b 100644 --- a/src/frontend/h.ts +++ b/src/frontend/h.ts @@ -3,8 +3,7 @@ export type HChild = string | undefined | (() => string); export type HMXComponent = (props: HProps, ...children: Array<HChild>) => string; export type HTag = string | HMXComponent; -const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', - 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']); +const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']); function* _h(tag: string, attrs: HProps, children: Array<HChild>) { yield `<${tag}`; @@ -17,7 +16,7 @@ function* _h(tag: string, attrs: HProps, children: Array<HChild>) { yield '>'; // Void tags have no children. - if(voidTags.has(tag)) { + if (voidTags.has(tag)) { return; } diff --git a/src/frontend/render/preact.ts b/src/frontend/render/preact.ts index eb588209c..3b9e1e6d8 100644 --- a/src/frontend/render/preact.ts +++ b/src/frontend/render/preact.ts @@ -3,25 +3,25 @@ import { h } from 'preact'; import type { Component } from 'preact'; export function __preact_static(PreactComponent: Component) { - return (attrs: Record<string, any>, ...children: any): string => { - let html = render( - h( - PreactComponent as any, // Preact's types seem wrong... - attrs, - children - ) - ); - return html; - }; + return (attrs: Record<string, any>, ...children: any): string => { + let html = render( + h( + PreactComponent as any, // Preact's types seem wrong... + attrs, + children + ) + ); + return html; + }; } export function __preact_dynamic(PreactComponent: Component, importUrl: string, preactUrl: string) { - const placeholderId = `placeholder_${String(Math.random())}`; - return (attrs: Record<string, string>, ...children: any) => { - return `<div id="${placeholderId}"></div><script type="module"> + const placeholderId = `placeholder_${String(Math.random())}`; + return (attrs: Record<string, string>, ...children: any) => { + return `<div id="${placeholderId}"></div><script type="module"> import {h, render} from '${preactUrl}'; import Component from '${importUrl}'; render(h(Component, ${JSON.stringify(attrs)}), document.getElementById('${placeholderId}')); </script>`; - }; + }; } diff --git a/src/frontend/render/svelte.ts b/src/frontend/render/svelte.ts index ffdf70254..51cb778db 100644 --- a/src/frontend/render/svelte.ts +++ b/src/frontend/render/svelte.ts @@ -4,7 +4,7 @@ export function __svelte_static(SvelteComponent: Component) { return (attrs: Record<string, any>, ...children: any): string => { // TODO include head and css stuff too... const { html } = SvelteComponent.render(attrs); - + return html; }; } @@ -12,7 +12,7 @@ export function __svelte_static(SvelteComponent: Component) { export function __svelte_dynamic(SvelteComponent: Component, importUrl: string) { const placeholderId = `placeholder_${String(Math.random())}`; return (attrs: Record<string, string>, ...children: any) => { - return `<div id="${placeholderId}"></div><script type="module"> + return `<div id="${placeholderId}"></div><script type="module"> import Component from '${importUrl}'; new Component({ diff --git a/src/frontend/render/vue.ts b/src/frontend/render/vue.ts index f83c1665a..6b89aa11e 100644 --- a/src/frontend/render/vue.ts +++ b/src/frontend/render/vue.ts @@ -7,11 +7,11 @@ export function __vue_static(VueComponent: Component) { return async (attrs: Record<string, any>, ...children: any): Promise<string> => { const app = createSSRApp({ components: { - VueComponent + VueComponent, }, render() { return createElement(VueComponent as any, attrs); - } + }, }); const html = await renderToString(app); @@ -23,7 +23,7 @@ export function __vue_static(VueComponent: Component) { export function __vue_dynamic(VueComponent: Component, importUrl: string, vueUrl: string) { const placeholderId = `placeholder_${String(Math.random())}`; return (attrs: Record<string, string>, ...children: any) => { - return `<div id="${placeholderId}"></div><script type="module"> + return `<div id="${placeholderId}"></div><script type="module"> import Component from '${importUrl}'; import {createApp, h as createElement} from '${vueUrl}'; @@ -36,4 +36,4 @@ export function __vue_dynamic(VueComponent: Component, importUrl: string, vueUrl createApp(App).mount(document.getElementById('${placeholderId}')); </script>`; }; -}
\ No newline at end of file +} |