diff --git a/src/editor/widgets/index.jsx b/src/editor/widgets/index.jsx index d528f1b..ffa8508 100644 --- a/src/editor/widgets/index.jsx +++ b/src/editor/widgets/index.jsx @@ -59,22 +59,32 @@ const isReactComponent = component => { */ export const getWidget = arg => { - const instantiate = (widget, config) => { + const instantiate = (widget, config, type) => { + // Check if user forced explicit type if (typeof widget === 'string' || widget instanceof String) { + // Built-in return React.createElement(BUILTIN_WIDGETS[widget], config); - } else if (isReactComponent(widget)) { - return React.createElement(widget, config); - } else if (typeof widget === 'function' || widget instanceof Function) { - return - } else { - throw `${widget} is not a valid plugin` + } else { + // Plugin + if (type?.toLowerCase() === 'react') { + return React.createElement(widget, config); + } else { + // Auto-detect + if (isReactComponent(widget)) { + return React.createElement(widget, config); + } else if (typeof widget === 'function' || widget instanceof Function) { + return + } else { + throw `${widget} is not a valid plugin` + } + } } } // First, check 'top-level' vs. 'nested object' case if (arg.widget) { - const { widget, ...config } = arg; - return instantiate(widget, config); + const { widget, type, ...config } = arg; + return instantiate(widget, config, type); } else { // No object with args -> instantiate arg directly return instantiate(arg);