Browse Source

Update plugin loading for headless option

pull/3980/head
Artur Arseniev 4 years ago
parent
commit
a7c42bb977
  1. 2
      .eslintrc
  2. 7
      src/index.js
  3. 9
      src/utils/mixins.js

2
.eslintrc

@ -4,7 +4,7 @@
"node": true
},
"parserOptions": {
"ecmaVersion": 2018,
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {

7
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) {

9
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 : {};

Loading…
Cancel
Save