2021-06-14 12:35:25 +00:00
|
|
|
import { h, Component as BaseComponent } from 'preact';
|
2021-05-26 18:30:22 +00:00
|
|
|
import { renderToString } from 'preact-render-to-string';
|
|
|
|
import StaticHtml from './static-html.js';
|
|
|
|
|
2021-05-28 22:19:40 +00:00
|
|
|
function check(Component, props, children) {
|
2021-06-14 12:36:32 +00:00
|
|
|
if (typeof Component !== 'function') return false;
|
2021-06-14 12:35:25 +00:00
|
|
|
|
2021-06-14 17:24:37 +00:00
|
|
|
if (Component.prototype != null && typeof Component.prototype.render === 'function') {
|
2021-06-14 12:35:25 +00:00
|
|
|
return BaseComponent.isPrototypeOf(Component);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { html } = renderToStaticMarkup(Component, props, children);
|
|
|
|
return Boolean(html);
|
2021-05-26 18:31:27 +00:00
|
|
|
}
|
2021-05-26 18:30:22 +00:00
|
|
|
|
|
|
|
function renderToStaticMarkup(Component, props, children) {
|
2021-05-28 22:19:40 +00:00
|
|
|
const html = renderToString(h(Component, { ...props, children: h(StaticHtml, { value: children }), innerHTML: children }));
|
2021-05-26 18:30:22 +00:00
|
|
|
return { html };
|
|
|
|
}
|
|
|
|
|
2021-05-26 18:31:27 +00:00
|
|
|
export default {
|
|
|
|
check,
|
|
|
|
renderToStaticMarkup,
|
|
|
|
};
|