diff --git a/.eslintrc b/.eslintrc index d00afacfb..534a1109a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,7 +4,7 @@ "node": true }, "parserOptions": { - "ecmaVersion": 2018, + "ecmaVersion": 2020, "sourceType": "module" }, "rules": { diff --git a/src/index.js b/src/index.js index 7499251f0..6fa13e930 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import { isElement, isFunction } from 'underscore'; import $ from 'utils/cash-dom'; import Editor from './editor'; import polyfills from 'utils/polyfills'; +import { getGlobal } from 'utils/mixins'; import PluginManager from './plugin_manager'; polyfills(); @@ -57,13 +58,13 @@ export default { // Load plugins config.plugins.forEach(pluginId => { - let plugin = plugins.get(pluginId); + let plugin = isFunction(pluginId) ? pluginId : plugins.get(pluginId); const plgOptions = config.pluginsOpts[pluginId] || {}; // Try to search in global context if (!plugin) { - const wplg = window[pluginId]; - plugin = wplg && wplg.default ? wplg.default : wplg; + const wplg = getGlobal()[pluginId]; + plugin = wplg?.default || wplg; } if (plugin) { diff --git a/src/utils/mixins.js b/src/utils/mixins.js index 80ebc7b7d..56da04885 100644 --- a/src/utils/mixins.js +++ b/src/utils/mixins.js @@ -1,7 +1,16 @@ import { keys, isUndefined, isElement, isArray } from 'underscore'; +export const isDef = value => typeof value !== 'undefined'; + export const hasWin = () => typeof window !== 'undefined'; +export const getGlobal = () => + typeof globalThis !== 'undefined' + ? globalThis + : typeof window !== 'undefined' + ? window + : global; + export const toLowerCase = str => (str || '').toLowerCase(); const elProt = hasWin() ? window.Element.prototype : {};