Skip to content

Commit

Permalink
Update plugin loading for headless option
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Nov 18, 2021
1 parent b0e5a84 commit a7c42bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"node": true
},
"parserOptions": {
"ecmaVersion": 2018,
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/utils/mixins.js
Original file line number Diff line number Diff line change
@@ -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 : {};
Expand Down

0 comments on commit a7c42bb

Please sign in to comment.