Skip to content

Commit a7c42bb

Browse files
committed
Update plugin loading for headless option
1 parent b0e5a84 commit a7c42bb

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"node": true
55
},
66
"parserOptions": {
7-
"ecmaVersion": 2018,
7+
"ecmaVersion": 2020,
88
"sourceType": "module"
99
},
1010
"rules": {

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isElement, isFunction } from 'underscore';
22
import $ from 'utils/cash-dom';
33
import Editor from './editor';
44
import polyfills from 'utils/polyfills';
5+
import { getGlobal } from 'utils/mixins';
56
import PluginManager from './plugin_manager';
67

78
polyfills();
@@ -57,13 +58,13 @@ export default {
5758

5859
// Load plugins
5960
config.plugins.forEach(pluginId => {
60-
let plugin = plugins.get(pluginId);
61+
let plugin = isFunction(pluginId) ? pluginId : plugins.get(pluginId);
6162
const plgOptions = config.pluginsOpts[pluginId] || {};
6263

6364
// Try to search in global context
6465
if (!plugin) {
65-
const wplg = window[pluginId];
66-
plugin = wplg && wplg.default ? wplg.default : wplg;
66+
const wplg = getGlobal()[pluginId];
67+
plugin = wplg?.default || wplg;
6768
}
6869

6970
if (plugin) {

src/utils/mixins.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { keys, isUndefined, isElement, isArray } from 'underscore';
22

3+
export const isDef = value => typeof value !== 'undefined';
4+
35
export const hasWin = () => typeof window !== 'undefined';
46

7+
export const getGlobal = () =>
8+
typeof globalThis !== 'undefined'
9+
? globalThis
10+
: typeof window !== 'undefined'
11+
? window
12+
: global;
13+
514
export const toLowerCase = str => (str || '').toLowerCase();
615

716
const elProt = hasWin() ? window.Element.prototype : {};

0 commit comments

Comments
 (0)