Editor now supports widgets compiled with Preact

This commit is contained in:
Rainer Simon 2021-06-03 14:31:37 +02:00
parent 785036ac43
commit 1455d879c1
1 changed files with 6 additions and 2 deletions

View File

@ -16,6 +16,7 @@ export const DEFAULT_WIDGETS = [
// https://stackoverflow.com/questions/33199959/how-to-detect-a-react-component-vs-a-react-element
const isReactComponent = component => {
const isClassComponent = component =>
typeof component === 'function' && !!component.prototype.isReactComponent;
@ -24,8 +25,11 @@ const isReactComponent = component => {
// this RegEx pattern should catch most minified and unminified variants, e.g.:
// - return React.createElement('div', {
// - return pe("div",{
typeof component === 'function' && String(component).match(/return .+\(['|"].+['|"],\s*\{/g);
typeof component === 'function' && (
String(component).match(/return .+\(['|"].+['|"],\s*\{/g) ||
String(component).match(/return .+preact_compat/)
);
return isClassComponent(component) || isFunctionComponent(component);
}