From 1455d879c11513f0362a5b0c285a7e6a60784c06 Mon Sep 17 00:00:00 2001 From: Rainer Simon Date: Thu, 3 Jun 2021 14:31:37 +0200 Subject: [PATCH] Editor now supports widgets compiled with Preact --- src/editor/widgets/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/editor/widgets/index.js b/src/editor/widgets/index.js index 0394f79..9777b15 100644 --- a/src/editor/widgets/index.js +++ b/src/editor/widgets/index.js @@ -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); }