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