From c08937edf3333e39046684b892bd926bdddcd13a Mon Sep 17 00:00:00 2001 From: Rainer Simon Date: Fri, 11 Jun 2021 11:07:15 +0200 Subject: [PATCH] Plugin API enhancement - hooks now supported! --- src/editor/widgets/index.jsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/editor/widgets/index.jsx b/src/editor/widgets/index.jsx index 9777b15..f598bdf 100644 --- a/src/editor/widgets/index.jsx +++ b/src/editor/widgets/index.jsx @@ -3,6 +3,13 @@ import CommentWidget from './comment/CommentWidget' import TagWidget from './tag/TagWidget'; import WrappedWidget from './WrappedWidget'; +/** + * We'll add React to the global window, so that + * plugins can use it without re-bundling. Also, + * without this, hooks won't work! + */ +window.React = React; + /** Standard widgets included by default **/ const BUILTIN_WIDGETS = { COMMENT: CommentWidget, @@ -18,7 +25,7 @@ export const DEFAULT_WIDGETS = [ const isReactComponent = component => { const isClassComponent = component => - typeof component === 'function' && !!component.prototype.isReactComponent; + typeof component === 'function' && !!component.prototype?.isReactComponent; const isFunctionComponent = component => // There's no good way to match function components (they are just functions), but @@ -27,7 +34,8 @@ const isReactComponent = component => { // - return pe("div",{ typeof component === 'function' && ( String(component).match(/return .+\(['|"].+['|"],\s*\{/g) || - String(component).match(/return .+preact_compat/) + String(component).match(/return .+preact_compat/) || + String(component).match(/return .+\.createElement/g) ); return isClassComponent(component) || isFunctionComponent(component);