fix: admin/html: script elements were working only in top and bottom sections #186

Massimo Melina committed Apr 1, 2023 at 20:35 UTC 7a6bbb698dcd9a7fc58f916fc02bbc022407e735
1 file changed +7 -8
frontend/src/components.ts
+7 -8
@@ -47,23 +47,22 @@ export function Select({ onChange, value, options, ...props }:SelectProps) {
47 }
48
49 export function Html({ code, ...rest }:{ code:string } & HTMLAttributes<any>) {
50 - const o = useMemo(() => ({ __html: code }), [code])
51 - if (!code)
52 - return null
53 - return h('span', { ...rest, dangerouslySetInnerHTML: o })
50 + return !code ? null : h('span', { ...rest, ref(x) {
51 + if (x)
52 + x.append(document.createRange().createContextualFragment(code))
53 + } })
54 }
55
56 export function CustomCode({ name, props }: any) {
57 - const code = useMemo(() => {
57 + return h(Fragment, {}, useMemo(() => {
58 const ret = hfsEvent(name, props)
59 .filter(x => x === 0 || x)
60 .map((x, key) => isValidElement(x) ? h(Fragment, { key }, x)
61 : typeof x === 'string' ? h(Html, { key, code: x })
62 - : h('div', { key }, x))
62 + : h('span', { key }, x))
63 const html = (window as any).HFS.customHtml[name]
64 if (html && html.trim())
65 ret.push(h(Html, { key: 'x', code: html }))
66 return ret
67 - }, props ? Object.values(props) : [])
68 - return h(Fragment, { children: code })
67 + }, props ? Object.values(props) : []))
68 }
\ No newline at end of file