Browse Source

Fix headless

pull/3905/head
Artur Arseniev 5 years ago
parent
commit
8b415b4e97
  1. 1
      package.json
  2. 4
      src/domain_abstract/ui/InputColor.js
  3. 4
      src/editor/index.js
  4. 5
      src/editor/model/Editor.js
  5. 8
      src/index.js
  6. 8
      test/setup.js
  7. 2
      test/specs/commands/index.js
  8. 1
      test/specs/dom_components/model/Component.js
  9. 1
      test/specs/style_manager/view/PropertyColorView.js
  10. 1
      test/specs/style_manager/view/PropertyIntegerView.js
  11. 1
      test/specs/style_manager/view/PropertyRadioView.js
  12. 1
      test/specs/style_manager/view/PropertySelectView.js
  13. 1
      test/specs/style_manager/view/PropertyView.js
  14. 1
      test/specs/utils/Sorter.js
  15. 15
      webpack.config.js

1
package.json

@ -38,7 +38,6 @@
"prettier": "^1.18.2", "prettier": "^1.18.2",
"sass": "^1.42.1", "sass": "^1.42.1",
"sinon": "^7.5.0", "sinon": "^7.5.0",
"string-replace-loader": "^2.2.0",
"vuepress": "^1.8.2", "vuepress": "^1.8.2",
"whatwg-fetch": "^3.6.2" "whatwg-fetch": "^3.6.2"
}, },

4
src/domain_abstract/ui/InputColor.js

@ -3,8 +3,8 @@ import { isUndefined } from 'underscore';
import ColorPicker from 'utils/ColorPicker'; import ColorPicker from 'utils/ColorPicker';
import Input from './Input'; import Input from './Input';
const $ = Backbone.$; const { $ } = Backbone;
ColorPicker($); $ && ColorPicker($);
export default Input.extend({ export default Input.extend({
template() { template() {

4
src/editor/index.js

@ -101,13 +101,13 @@
* *
* @module Editor * @module Editor
*/ */
import $ from 'cash-dom';
import defaults from './config/config'; import defaults from './config/config';
import EditorModel from './model/Editor'; import EditorModel from './model/Editor';
import EditorView from './view/EditorView'; import EditorView from './view/EditorView';
import html from 'utils/html'; import html from 'utils/html';
export default (config = {}) => { export default (config = {}, opts = {}) => {
const { $ } = opts;
const c = { const c = {
...defaults, ...defaults,
...config ...config

5
src/editor/model/Editor.js

@ -7,13 +7,15 @@ import {
keys, keys,
bindAll bindAll
} from 'underscore'; } from 'underscore';
import $ from 'cash-dom';
import Backbone from 'backbone'; import Backbone from 'backbone';
import Extender from 'utils/extender'; import Extender from 'utils/extender';
import { getModel, hasWin } from 'utils/mixins'; import { getModel, hasWin } from 'utils/mixins';
import Selected from './Selected'; import Selected from './Selected';
const cash = hasWin() ? require('cash-dom') : null;
const $ = (cash && cash.default) || cash;
Backbone.$ = $; Backbone.$ = $;
const deps = [ const deps = [
require('utils'), require('utils'),
require('i18n'), require('i18n'),
@ -39,7 +41,6 @@ const deps = [
require('block_manager') require('block_manager')
]; ];
const { Collection } = Backbone;
let timedInterval; let timedInterval;
let updateItr; let updateItr;

8
src/index.js

@ -1,13 +1,15 @@
import $ from 'cash-dom';
import Editor from './editor'; import Editor from './editor';
import { isElement, isFunction } from 'underscore'; import { isElement, isFunction } from 'underscore';
import polyfills from 'utils/polyfills'; import polyfills from 'utils/polyfills';
import PluginManager from './plugin_manager'; import PluginManager from './plugin_manager';
import { hasWin } from 'utils/mixins';
polyfills(); polyfills();
const plugins = new PluginManager(); const plugins = new PluginManager();
const editors = []; const editors = [];
const cash = hasWin() ? require('cash-dom') : null;
const $ = (cash && cash.default) || cash;
const defaultConfig = { const defaultConfig = {
// If true renders editor on init // If true renders editor on init
autorender: 1, autorender: 1,
@ -27,7 +29,7 @@ export default {
plugins, plugins,
// Will be replaced on build // Will be replaced on build
version: '<# VERSION #>', version: __GJS_VERSION__,
/** /**
* Initialize the editor with passed options * Initialize the editor with passed options
@ -52,7 +54,7 @@ export default {
config = { ...defaultConfig, ...config, grapesjs: this }; config = { ...defaultConfig, ...config, grapesjs: this };
config.el = config.el =
!headless && (isElement(els) ? els : document.querySelector(els)); !headless && (isElement(els) ? els : document.querySelector(els));
const editor = new Editor(config).init(); const editor = new Editor(config, { $ }).init();
const em = editor.getModel(); const em = editor.getModel();
// Load plugins // Load plugins

8
test/setup.js

@ -1,8 +1,6 @@
import 'whatwg-fetch'; import 'whatwg-fetch';
import _ from 'underscore'; import _ from 'underscore';
import Backbone from 'backbone';
import sinon from 'sinon'; import sinon from 'sinon';
import grapesjs from './../src';
const localStorage = { const localStorage = {
getItem(key) { getItem(key) {
@ -16,9 +14,9 @@ const localStorage = {
} }
}; };
global.Backbone = Backbone;
global._ = _; global._ = _;
global.sinon = sinon; global.sinon = sinon;
global.grapesjs = grapesjs; global.__GJS_VERSION__ = '';
global.$ = Backbone.$; global.grapesjs = require('./../src').default;
global.$ = global.grapesjs.$;
global.localStorage = localStorage; global.localStorage = localStorage;

2
test/specs/commands/index.js

@ -1,7 +1,5 @@
import Backbone from 'backbone'; import Backbone from 'backbone';
import Commands from 'commands'; import Commands from 'commands';
import Models from './model/CommandModels';
import CommandAbstract from './view/CommandAbstract';
describe('Commands', () => { describe('Commands', () => {
describe('Main', () => { describe('Main', () => {

1
test/specs/dom_components/model/Component.js

@ -1,5 +1,4 @@
import Backbone from 'backbone'; import Backbone from 'backbone';
import DomComponents from 'dom_components';
import Component from 'dom_components/model/Component'; import Component from 'dom_components/model/Component';
import ComponentImage from 'dom_components/model/ComponentImage'; import ComponentImage from 'dom_components/model/ComponentImage';
import ComponentText from 'dom_components/model/ComponentText'; import ComponentText from 'dom_components/model/ComponentText';

1
test/specs/style_manager/view/PropertyColorView.js

@ -1,3 +1,4 @@
import Backbone from 'backbone';
import PropertyColorView from 'style_manager/view/PropertyColorView'; import PropertyColorView from 'style_manager/view/PropertyColorView';
import Property from 'style_manager/model/Property'; import Property from 'style_manager/model/Property';
import Component from 'dom_components/model/Component'; import Component from 'dom_components/model/Component';

1
test/specs/style_manager/view/PropertyIntegerView.js

@ -1,3 +1,4 @@
import Backbone from 'backbone';
import PropertyIntegerView from 'style_manager/view/PropertyIntegerView'; import PropertyIntegerView from 'style_manager/view/PropertyIntegerView';
import PropertyInteger from 'style_manager/model/PropertyInteger'; import PropertyInteger from 'style_manager/model/PropertyInteger';
import Component from 'dom_components/model/Component'; import Component from 'dom_components/model/Component';

1
test/specs/style_manager/view/PropertyRadioView.js

@ -1,3 +1,4 @@
import Backbone from 'backbone';
import PropertyRadioView from 'style_manager/view/PropertyRadioView'; import PropertyRadioView from 'style_manager/view/PropertyRadioView';
import Property from 'style_manager/model/Property'; import Property from 'style_manager/model/Property';
import Component from 'dom_components/model/Component'; import Component from 'dom_components/model/Component';

1
test/specs/style_manager/view/PropertySelectView.js

@ -1,3 +1,4 @@
import Backbone from 'backbone';
import PropertySelectView from 'style_manager/view/PropertySelectView'; import PropertySelectView from 'style_manager/view/PropertySelectView';
import Property from 'style_manager/model/PropertyRadio'; import Property from 'style_manager/model/PropertyRadio';
import Editor from 'editor/model/Editor'; import Editor from 'editor/model/Editor';

1
test/specs/style_manager/view/PropertyView.js

@ -1,3 +1,4 @@
import Backbone from 'backbone';
import PropertyView from 'style_manager/view/PropertyView'; import PropertyView from 'style_manager/view/PropertyView';
import Property from 'style_manager/model/Property'; import Property from 'style_manager/model/Property';
import Editor from 'editor/model/Editor'; import Editor from 'editor/model/Editor';

1
test/specs/utils/Sorter.js

@ -1,6 +1,5 @@
import Backbone from 'backbone'; import Backbone from 'backbone';
import Sorter from '../../../src/utils/Sorter.js'; import Sorter from '../../../src/utils/Sorter.js';
import ComponentView from 'dom_components/view/ComponentView';
import ComponentTextView from 'dom_components/view/ComponentTextView'; import ComponentTextView from 'dom_components/view/ComponentTextView';
import Component from 'dom_components/model/Component'; import Component from 'dom_components/model/Component';
const $ = Backbone.$; const $ = Backbone.$;

15
webpack.config.js

@ -1,4 +1,5 @@
import path from 'path'; import path from 'path';
import webpack from 'webpack';
import pkg from './package.json'; import pkg from './package.json';
const rootDir = path.resolve(__dirname); const rootDir = path.resolve(__dirname);
@ -16,14 +17,8 @@ export default ({ config }) => ({
}, },
module: { module: {
rules: [ rules: [
{ // Disable AMD in vendors
test: /\/index\.js$/, { test: /\.js$/, parser: { amd: false } },
loader: 'string-replace-loader',
query: {
search: '<# VERSION #>',
replace: pkg.version
}
},
...config.module.rules, ...config.module.rules,
], ],
}, },
@ -35,4 +30,8 @@ export default ({ config }) => ({
underscore: `${rootDir}/node_modules/underscore`, underscore: `${rootDir}/node_modules/underscore`,
} }
}, },
plugins: [
new webpack.DefinePlugin({ __GJS_VERSION__: `'${pkg.version}'` }),
...config.plugins,
]
}); });
Loading…
Cancel
Save