Browse Source

More refactor of files to classes

pull/4234/head
Artur Arseniev 5 years ago
parent
commit
0a602fc145
  1. 15
      src/index.js
  2. 2
      src/rich_text_editor/index.js
  3. 2
      src/rich_text_editor/model/RichTextEditor.js
  4. 5
      src/selector_manager/index.js
  5. 8
      src/selector_manager/model/Selector.js
  6. 11
      src/selector_manager/model/Selectors.js
  7. 4
      src/selector_manager/model/State.js
  8. 36
      src/selector_manager/view/ClassTagView.js
  9. 88
      src/selector_manager/view/ClassTagsView.js
  10. 2
      src/storage_manager/index.js
  11. 2
      src/storage_manager/model/LocalStorage.js
  12. 2
      src/storage_manager/model/RemoteStorage.js
  13. 5
      src/style_manager/index.js
  14. 4
      src/style_manager/model/Layer.js
  15. 2
      src/style_manager/model/Layers.js
  16. 4
      src/style_manager/model/Property.js
  17. 4
      src/style_manager/model/PropertyNumber.js
  18. 4
      src/style_manager/model/PropertySelect.js
  19. 2
      src/style_manager/model/PropertyStack.js
  20. 4
      src/style_manager/model/Sector.js
  21. 2
      src/style_manager/model/Sectors.js
  22. 2
      src/style_manager/view/LayerView.js
  23. 2
      src/style_manager/view/LayersView.js
  24. 4
      src/style_manager/view/PropertiesView.js
  25. 2
      src/style_manager/view/PropertyColorView.js
  26. 4
      src/style_manager/view/PropertyView.js
  27. 4
      src/style_manager/view/SectorView.js
  28. 4
      src/style_manager/view/SectorsView.js
  29. 2
      src/trait_manager/index.js
  30. 2
      src/trait_manager/model/Trait.js
  31. 2
      src/trait_manager/model/Traits.js
  32. 2
      src/trait_manager/view/TraitColorView.js
  33. 4
      src/trait_manager/view/TraitNumberView.js
  34. 2
      src/trait_manager/view/TraitsView.js
  35. 2
      src/utils/ColorPicker.js
  36. 26
      src/utils/Dragger.js
  37. 20
      src/utils/Droppable.js
  38. 39
      src/utils/Resizer.js
  39. 34
      src/utils/extender.js
  40. 4
      src/utils/fetch.js

15
src/index.js

@ -1,8 +1,8 @@
import { isElement, isFunction } from 'underscore'; import { isElement, isFunction } from 'underscore';
import $ from 'utils/cash-dom'; import $ from './utils/cash-dom';
import Editor from './editor'; import Editor from './editor';
import polyfills from 'utils/polyfills'; import polyfills from './utils/polyfills';
import { getGlobal } from 'utils/mixins'; import { getGlobal } from './utils/mixins';
import PluginManager from './plugin_manager'; import PluginManager from './plugin_manager';
polyfills(); polyfills();
@ -17,7 +17,7 @@ const defaultConfig = {
plugins: [], plugins: [],
// Custom options for plugins // Custom options for plugins
pluginsOpts: {} pluginsOpts: {},
}; };
export default { export default {
@ -51,8 +51,7 @@ export default {
const els = config.container; const els = config.container;
if (!els && !headless) throw new Error("'container' is required"); if (!els && !headless) throw new Error("'container' is required");
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();
@ -74,7 +73,7 @@ export default {
} else { } else {
em.logWarning(`Plugin ${pluginId} not found`, { em.logWarning(`Plugin ${pluginId} not found`, {
context: 'plugins', context: 'plugins',
plugin: pluginId plugin: pluginId,
}); });
} }
}); });
@ -87,5 +86,5 @@ export default {
editors.push(editor); editors.push(editor);
return editor; return editor;
} },
}; };

2
src/rich_text_editor/index.js

@ -36,8 +36,8 @@
* @module RichTextEditor * @module RichTextEditor
*/ */
import { on, hasWin } from '../utils/mixins';
import RichTextEditor from './model/RichTextEditor'; import RichTextEditor from './model/RichTextEditor';
import { on, hasWin } from 'utils/mixins';
import defaults from './config/config'; import defaults from './config/config';
const eventsUp = 'change:canvasOffset frame:scroll component:update'; const eventsUp = 'change:canvasOffset frame:scroll component:update';

2
src/rich_text_editor/model/RichTextEditor.js

@ -2,7 +2,7 @@
// and adapted to the GrapesJS's need // and adapted to the GrapesJS's need
import { isString } from 'underscore'; import { isString } from 'underscore';
import { on, off, getPointerEvent, getModel } from 'utils/mixins'; import { on, off, getPointerEvent, getModel } from '../../utils/mixins';
const RTE_KEY = '_rte'; const RTE_KEY = '_rte';

5
src/selector_manager/index.js

@ -73,9 +73,8 @@
*/ */
import { isString, debounce, isObject, isArray } from 'underscore'; import { isString, debounce, isObject, isArray } from 'underscore';
import { isComponent, isRule } from 'utils/mixins'; import { isComponent, isRule } from '../utils/mixins';
import { Model, Collection } from 'common'; import { Model, Collection, Module } from '../common';
import Module from 'common/module';
import defaults from './config/config'; import defaults from './config/config';
import Selector from './model/Selector'; import Selector from './model/Selector';
import Selectors from './model/Selectors'; import Selectors from './model/Selectors';

8
src/selector_manager/model/Selector.js

@ -1,5 +1,5 @@
import { Model } from 'common';
import { result, forEach, keys } from 'underscore'; import { result, forEach, keys } from 'underscore';
import { Model } from '../../common';
const TYPE_CLASS = 1; const TYPE_CLASS = 1;
const TYPE_ID = 2; const TYPE_ID = 2;
@ -22,7 +22,7 @@ export default class Selector extends Model {
active: true, active: true,
private: false, private: false,
protected: false, protected: false,
_undo: true _undo: true,
}; };
} }
@ -39,9 +39,7 @@ export default class Selector extends Model {
const namePreEsc = this.get('name'); const namePreEsc = this.get('name');
const { escapeName } = config; const { escapeName } = config;
const nameEsc = escapeName const nameEsc = escapeName ? escapeName(namePreEsc) : Selector.escapeName(namePreEsc);
? escapeName(namePreEsc)
: Selector.escapeName(namePreEsc);
this.set('name', nameEsc); this.set('name', nameEsc);
this.em = config.em; this.em = config.em;
} }

11
src/selector_manager/model/Selectors.js

@ -1,5 +1,5 @@
import { filter } from 'underscore'; import { filter } from 'underscore';
import { Collection } from 'common'; import { Collection } from '../../common';
import Selector from './Selector'; import Selector from './Selector';
const combine = (tail, curr) => { const combine = (tail, curr) => {
@ -17,16 +17,11 @@ export default class Selectors extends Collection {
} }
getStyleable() { getStyleable() {
return filter( return filter(this.models, item => item.get('active') && !item.get('private'));
this.models,
item => item.get('active') && !item.get('private')
);
} }
getValid({ noDisabled } = {}) { getValid({ noDisabled } = {}) {
return filter(this.models, item => !item.get('private')).filter(item => return filter(this.models, item => !item.get('private')).filter(item => (noDisabled ? item.get('active') : 1));
noDisabled ? item.get('active') : 1
);
} }
getFullString(collection, opts = {}) { getFullString(collection, opts = {}) {

4
src/selector_manager/model/State.js

@ -1,4 +1,4 @@
import { Model } from 'common'; import { Model } from '../../common';
/** /**
* @typedef State * @typedef State
@ -9,7 +9,7 @@ export default class State extends Model {
defaults() { defaults() {
return { return {
name: '', name: '',
label: '' label: '',
}; };
} }

36
src/selector_manager/view/ClassTagView.js

@ -1,8 +1,8 @@
import Backbone from 'backbone'; import { View } from '../../common';
const inputProp = 'contentEditable'; const inputProp = 'contentEditable';
export default Backbone.View.extend({ export default class ClassTagView extends View {
template() { template() {
const { pfx, model, config } = this; const { pfx, model, config } = this;
const label = model.get('label') || ''; const label = model.get('label') || '';
@ -14,14 +14,16 @@ export default Backbone.View.extend({
${config.iconTagRemove} ${config.iconTagRemove}
</span> </span>
`; `;
}, }
events: { events() {
'click [data-tag-remove]': 'removeTag', return {
'click [data-tag-status]': 'changeStatus', 'click [data-tag-remove]': 'removeTag',
'dblclick [data-tag-name]': 'startEditTag', 'click [data-tag-status]': 'changeStatus',
'focusout [data-tag-name]': 'endEditTag' 'dblclick [data-tag-name]': 'startEditTag',
}, 'focusout [data-tag-name]': 'endEditTag',
};
}
initialize(o = {}) { initialize(o = {}) {
const config = o.config || {}; const config = o.config || {};
@ -32,7 +34,7 @@ export default Backbone.View.extend({
this.ppfx = config.pStylePrefix || ''; this.ppfx = config.pStylePrefix || '';
this.em = config.em; this.em = config.em;
this.listenTo(this.model, 'change:active', this.updateStatus); this.listenTo(this.model, 'change:active', this.updateStatus);
}, }
/** /**
* Returns the element which containes the anme of the tag * Returns the element which containes the anme of the tag
@ -44,7 +46,7 @@ export default Backbone.View.extend({
} }
return this.inputEl; return this.inputEl;
}, }
/** /**
* Start editing tag * Start editing tag
@ -56,7 +58,7 @@ export default Backbone.View.extend({
inputEl[inputProp] = true; inputEl[inputProp] = true;
inputEl.focus(); inputEl.focus();
em && em.setEditing(1); em && em.setEditing(1);
}, }
/** /**
* End editing tag. If the class typed already exists the * End editing tag. If the class typed already exists the
@ -81,7 +83,7 @@ export default Backbone.View.extend({
model.set({ name, label }); model.set({ name, label });
} }
} }
}, }
/** /**
* Update status of the tag * Update status of the tag
@ -90,7 +92,7 @@ export default Backbone.View.extend({
changeStatus() { changeStatus() {
const { model } = this; const { model } = this;
model.set('active', !model.get('active')); model.set('active', !model.get('active'));
}, }
/** /**
* Remove tag from the selected component * Remove tag from the selected component
@ -99,7 +101,7 @@ export default Backbone.View.extend({
*/ */
removeTag() { removeTag() {
this.module.removeSelected(this.model); this.module.removeSelected(this.model);
}, }
/** /**
* Update status of the checkbox * Update status of the checkbox
@ -117,7 +119,7 @@ export default Backbone.View.extend({
$chk.html(iconTagOff); $chk.html(iconTagOff);
$el.addClass('opac50'); $el.addClass('opac50');
} }
}, }
render() { render() {
const pfx = this.pfx; const pfx = this.pfx;
@ -127,4 +129,4 @@ export default Backbone.View.extend({
this.updateStatus(); this.updateStatus();
return this; return this;
} }
}); }

88
src/selector_manager/view/ClassTagsView.js

@ -1,9 +1,9 @@
import { isEmpty, isArray, isString, debounce } from 'underscore'; import { isEmpty, isArray, isString, debounce } from 'underscore';
import Backbone from 'backbone'; import { View } from '../../common';
import ClassTagView from './ClassTagView'; import ClassTagView from './ClassTagView';
import html from 'utils/html'; import html from 'utils/html';
export default Backbone.View.extend({ export default class ClassTagsView extends View {
template({ labelInfo, labelHead, iconSync, iconAdd, pfx, ppfx }) { template({ labelInfo, labelHead, iconSync, iconAdd, pfx, ppfx }) {
return ` return `
<div id="${pfx}up" class="${pfx}header"> <div id="${pfx}up" class="${pfx}header">
@ -35,15 +35,17 @@ export default Backbone.View.extend({
<div class="${pfx}label-sel">${labelInfo}:</div> <div class="${pfx}label-sel">${labelInfo}:</div>
<div class="${pfx}sels" data-selected></div> <div class="${pfx}sels" data-selected></div>
</div>`; </div>`;
}, }
events: { events() {
'change [data-states]': 'stateChanged', return {
'click [data-add]': 'startNewTag', 'change [data-states]': 'stateChanged',
'focusout [data-input]': 'endNewTag', 'click [data-add]': 'startNewTag',
'keyup [data-input]': 'onInputKeyUp', 'focusout [data-input]': 'endNewTag',
'click [data-sync-style]': 'syncStyle', 'keyup [data-input]': 'onInputKeyUp',
}, 'click [data-sync-style]': 'syncStyle',
};
}
initialize(o = {}) { initialize(o = {}) {
this.config = o.config || {}; this.config = o.config || {};
@ -59,6 +61,8 @@ export default Backbone.View.extend({
const md = o.module; const md = o.module;
this.module = md; this.module = md;
this.em = em; this.em = em;
this.componentChanged = debounce(this.componentChanged.bind(this));
this.checkSync = debounce(this.checkSync.bind(this));
const toList = 'component:toggled component:update:classes'; const toList = 'component:toggled component:update:classes';
const toListCls = 'component:update:classes change:state'; const toListCls = 'component:update:classes change:state';
this.listenTo(em, toList, this.componentChanged); this.listenTo(em, toList, this.componentChanged);
@ -74,7 +78,7 @@ export default Backbone.View.extend({
debounce(() => this.renderStates()) debounce(() => this.renderStates())
); );
this.delegateEvents(); this.delegateEvents();
}, }
syncStyle() { syncStyle() {
const { em } = this; const { em } = this;
@ -108,7 +112,7 @@ export default Backbone.View.extend({
ruleComponents, ruleComponents,
state, state,
}); });
}, }
/** /**
* Triggered when a tag is removed from collection * Triggered when a tag is removed from collection
@ -117,7 +121,7 @@ export default Backbone.View.extend({
*/ */
tagRemoved(model) { tagRemoved(model) {
this.updateStateVis(); this.updateStateVis();
}, }
/** /**
* Add new model * Add new model
@ -126,7 +130,7 @@ export default Backbone.View.extend({
*/ */
addNew(model) { addNew(model) {
this.addToClasses(model); this.addToClasses(model);
}, }
/** /**
* Start tag creation * Start tag creation
@ -136,7 +140,7 @@ export default Backbone.View.extend({
startNewTag() { startNewTag() {
this.$addBtn.css({ display: 'none' }); this.$addBtn.css({ display: 'none' });
this.$input.show().focus(); this.$input.show().focus();
}, }
/** /**
* End tag creation * End tag creation
@ -146,7 +150,7 @@ export default Backbone.View.extend({
endNewTag() { endNewTag() {
this.$addBtn.css({ display: '' }); this.$addBtn.css({ display: '' });
this.$input.hide().val(''); this.$input.hide().val('');
}, }
/** /**
* Checks what to do on keyup event * Checks what to do on keyup event
@ -160,22 +164,22 @@ export default Backbone.View.extend({
} else if (e.keyCode === 27) { } else if (e.keyCode === 27) {
this.endNewTag(); this.endNewTag();
} }
}, }
checkStates() { checkStates() {
const state = this.em.getState(); const state = this.em.getState();
const statesEl = this.getStates(); const statesEl = this.getStates();
statesEl && statesEl.val(state); statesEl && statesEl.val(state);
}, }
/** /**
* Triggered when component is changed * Triggered when component is changed
* @param {Object} e * @param {Object} e
* @private * @private
*/ */
componentChanged: debounce(function ({ targets } = {}) { componentChanged({ targets } = {}) {
this.updateSelection(targets); this.updateSelection(targets);
}), }
updateSelection(targets) { updateSelection(targets) {
let trgs = targets || this.getTargets(); let trgs = targets || this.getTargets();
@ -191,18 +195,18 @@ export default Backbone.View.extend({
this.updateStateVis(trgs); this.updateStateVis(trgs);
this.module.__trgCustom(); this.module.__trgCustom();
return selectors; return selectors;
}, }
getCommonSelectors({ targets, opts = {} } = {}) { getCommonSelectors({ targets, opts = {} } = {}) {
const trgs = targets || this.getTargets(); const trgs = targets || this.getTargets();
return this.module.__getCommonSelectors(trgs, opts); return this.module.__getCommonSelectors(trgs, opts);
}, }
_commonSelectors(...args) { _commonSelectors(...args) {
return this.module.__common(...args); return this.module.__common(...args);
}, }
checkSync: debounce(function () { checkSync() {
const { $btnSyncEl, config, collection } = this; const { $btnSyncEl, config, collection } = this;
const target = this.getTarget(); const target = this.getTarget();
let hasStyle; let hasStyle;
@ -213,15 +217,15 @@ export default Backbone.View.extend({
} }
$btnSyncEl && $btnSyncEl[hasStyle ? 'show' : 'hide'](); $btnSyncEl && $btnSyncEl[hasStyle ? 'show' : 'hide']();
}), }
getTarget() { getTarget() {
return this.target.getSelected(); return this.target.getSelected();
}, }
getTargets() { getTargets() {
return this.target.getSelectedAll(); return this.target.getSelectedAll();
}, }
/** /**
* Update states visibility. Hides states in case there is no tags * Update states visibility. Hides states in case there is no tags
@ -234,11 +238,11 @@ export default Backbone.View.extend({
const display = this.collection.length || avoidInline ? '' : 'none'; const display = this.collection.length || avoidInline ? '' : 'none';
this.getStatesC().css('display', display); this.getStatesC().css('display', display);
this.updateSelector(target); this.updateSelector(target);
}, }
__handleStateChange() { __handleStateChange() {
this.updateSelector(this.getTargets()); this.updateSelector(this.getTargets());
}, }
/** /**
* Update selector helper * Update selector helper
@ -254,7 +258,7 @@ export default Backbone.View.extend({
trgs.forEach(target => result.push(this.__getName(target))); trgs.forEach(target => result.push(this.__getName(target)));
elSel && (elSel.innerHTML = result.join(', ')); elSel && (elSel.innerHTML = result.join(', '));
this.checkStates(); this.checkStates();
}, }
__getName(target) { __getName(target) {
const { pfx, config, em } = this; const { pfx, config, em } = this;
@ -280,7 +284,7 @@ export default Backbone.View.extend({
} }
return result && `<span class="${pfx}sel">${result}</span>`; return result && `<span class="${pfx}sel">${result}</span>`;
}, }
/** /**
* Triggered when the select with states is changed * Triggered when the select with states is changed
@ -291,7 +295,7 @@ export default Backbone.View.extend({
const { em } = this; const { em } = this;
const { value } = ev.target; const { value } = ev.target;
em.set('state', value); em.set('state', value);
}, }
/** /**
* Add new tag to collection, if possible, and to the component * Add new tag to collection, if possible, and to the component
@ -304,7 +308,7 @@ export default Backbone.View.extend({
this.module.addSelected({ label }); this.module.addSelected({ label });
this.endNewTag(); this.endNewTag();
// this.updateStateVis(); // Check if required // this.updateStateVis(); // Check if required
}, }
/** /**
* Add new object to collection * Add new object to collection
@ -326,7 +330,7 @@ export default Backbone.View.extend({
fragment ? fragment.appendChild(rendered) : classes.append(rendered); fragment ? fragment.appendChild(rendered) : classes.append(rendered);
return rendered; return rendered;
}, }
/** /**
* Render the collection of classes * Render the collection of classes
@ -338,7 +342,7 @@ export default Backbone.View.extend({
classes.empty(); classes.empty();
this.collection.each(model => this.addToClasses(model, frag)); this.collection.each(model => this.addToClasses(model, frag));
classes.append(frag); classes.append(frag);
}, }
/** /**
* Return classes element * Return classes element
@ -347,7 +351,7 @@ export default Backbone.View.extend({
*/ */
getClasses() { getClasses() {
return this.$el.find('[data-selectors]'); return this.$el.find('[data-selectors]');
}, }
/** /**
* Return states element * Return states element
@ -360,7 +364,7 @@ export default Backbone.View.extend({
this.$states = el[0] && el; this.$states = el[0] && el;
} }
return this.$states; return this.$states;
}, }
/** /**
* Return states container element * Return states container element
@ -370,7 +374,7 @@ export default Backbone.View.extend({
getStatesC() { getStatesC() {
if (!this.$statesC) this.$statesC = this.$el.find('#' + this.stateInputC); if (!this.$statesC) this.$statesC = this.$el.find('#' + this.stateInputC);
return this.$statesC; return this.$statesC;
}, }
renderStates() { renderStates() {
const { module, em } = this; const { module, em } = this;
@ -386,7 +390,7 @@ export default Backbone.View.extend({
const statesEl = this.getStates(); const statesEl = this.getStates();
statesEl && statesEl.html(`<option value="">${labelStates}</option>${options}`); statesEl && statesEl.html(`<option value="">${labelStates}</option>${options}`);
this.checkStates(); this.checkStates();
}, }
render() { render() {
const { em, pfx, ppfx, config, $el, el } = this; const { em, pfx, ppfx, config, $el, el } = this;
@ -412,5 +416,5 @@ export default Backbone.View.extend({
this.renderClasses(); this.renderClasses();
$el.attr('class', `${this.className} ${ppfx}one-bg ${ppfx}two-color`); $el.attr('class', `${this.className} ${ppfx}one-bg ${ppfx}two-color`);
return this; return this;
}, }
}); }

2
src/storage_manager/index.js

@ -51,10 +51,10 @@
* @module StorageManager * @module StorageManager
*/ */
import Module from '../common/module';
import defaults from './config/config'; import defaults from './config/config';
import LocalStorage from './model/LocalStorage'; import LocalStorage from './model/LocalStorage';
import RemoteStorage from './model/RemoteStorage'; import RemoteStorage from './model/RemoteStorage';
import Module from 'common/module';
import { isEmpty, isFunction } from 'underscore'; import { isEmpty, isFunction } from 'underscore';
const eventStart = 'storage:start'; const eventStart = 'storage:start';

2
src/storage_manager/model/LocalStorage.js

@ -1,4 +1,4 @@
import { hasWin } from 'utils/mixins'; import { hasWin } from '../../utils/mixins';
export default class LocalStorage { export default class LocalStorage {
async store(data, opts = {}) { async store(data, opts = {}) {

2
src/storage_manager/model/RemoteStorage.js

@ -1,5 +1,5 @@
import fetch from 'utils/fetch';
import { isUndefined, isFunction, isString } from 'underscore'; import { isUndefined, isFunction, isString } from 'underscore';
import fetch from '../../utils/fetch';
export default class RemoteStorage { export default class RemoteStorage {
async store(data, opts = {}) { async store(data, opts = {}) {

5
src/style_manager/index.js

@ -64,9 +64,8 @@
*/ */
import { isUndefined, isArray, isString, debounce, bindAll } from 'underscore'; import { isUndefined, isArray, isString, debounce, bindAll } from 'underscore';
import { isComponent } from 'utils/mixins'; import { isComponent } from '../utils/mixins';
import Module from 'common/module'; import { Model, Module } from '../common';
import { Model } from 'common';
import defaults from './config/config'; import defaults from './config/config';
import Sector from './model/Sector'; import Sector from './model/Sector';
import Sectors from './model/Sectors'; import Sectors from './model/Sectors';

4
src/style_manager/model/Layer.js

@ -1,5 +1,5 @@
import { Model } from 'common'; import { Model } from '../../common';
import { camelCase } from 'utils/mixins'; import { camelCase } from '../../utils/mixins';
export default class Layer extends Model { export default class Layer extends Model {
defaults() { defaults() {

2
src/style_manager/model/Layers.js

@ -1,4 +1,4 @@
import { Collection } from 'common'; import { Collection } from '../../common';
import Layer from './Layer'; import Layer from './Layer';
export default class Layers extends Collection { export default class Layers extends Collection {

4
src/style_manager/model/Property.js

@ -1,6 +1,6 @@
import { Model } from 'common';
import { isUndefined, isString, isArray, result, keys, each, includes } from 'underscore'; import { isUndefined, isString, isArray, result, keys, each, includes } from 'underscore';
import { capitalize, camelCase, hasWin } from 'utils/mixins'; import { Model } from '../../common';
import { capitalize, camelCase, hasWin } from '../../utils/mixins';
/** /**
* @typedef Property * @typedef Property

4
src/style_manager/model/PropertyNumber.js

@ -1,7 +1,7 @@
import { isUndefined } from 'underscore'; import { isUndefined } from 'underscore';
import Property from './Property'; import Property from './Property';
import InputNumber from 'domain_abstract/ui/InputNumber'; import InputNumber from '../../domain_abstract/ui/InputNumber';
import { hasWin } from 'utils/mixins'; import { hasWin } from '../../utils/mixins';
/** /**
* @typedef PropertyNumber * @typedef PropertyNumber

4
src/style_manager/model/PropertySelect.js

@ -1,6 +1,6 @@
import Property from './Property';
import { isDef } from 'utils/mixins';
import { isString } from 'underscore'; import { isString } from 'underscore';
import { isDef } from '../../utils/mixins';
import Property from './Property';
/** /**
* @typedef PropertySelect * @typedef PropertySelect

2
src/style_manager/model/PropertyStack.js

@ -1,8 +1,8 @@
import { keys, isUndefined, isArray, isString, isNumber } from 'underscore'; import { keys, isUndefined, isArray, isString, isNumber } from 'underscore';
import { camelCase } from '../../utils/mixins';
import PropertyComposite, { isNumberType } from './PropertyComposite'; import PropertyComposite, { isNumberType } from './PropertyComposite';
import PropertyBase from './Property'; import PropertyBase from './Property';
import Layers from './Layers'; import Layers from './Layers';
import { camelCase } from 'utils/mixins';
const VALUES_REG = /,(?![^\(]*\))/; const VALUES_REG = /,(?![^\(]*\))/;
const PARTS_REG = /\s(?![^(]*\))/; const PARTS_REG = /\s(?![^(]*\))/;

4
src/style_manager/model/Sector.js

@ -1,5 +1,5 @@
import { Model } from 'common'; import { extend, isString } from 'underscore';
import { extend, isString, isArray } from 'underscore'; import { Model } from '../../common';
import Properties from './Properties'; import Properties from './Properties';
/** /**

2
src/style_manager/model/Sectors.js

@ -1,4 +1,4 @@
import { Collection } from 'common'; import { Collection } from '../../common';
import Sector from './Sector'; import Sector from './Sector';
export default class Sectors extends Collection { export default class Sectors extends Collection {

2
src/style_manager/view/LayerView.js

@ -1,4 +1,4 @@
import { View } from 'backbone'; import { View } from '../../common';
import { keys } from 'underscore'; import { keys } from 'underscore';
export default class LayerView extends View { export default class LayerView extends View {

2
src/style_manager/view/LayersView.js

@ -1,4 +1,4 @@
import { View } from 'common'; import { View } from '../../common';
import LayerView from './LayerView'; import LayerView from './LayerView';
export default class LayersView extends View { export default class LayersView extends View {

4
src/style_manager/view/PropertiesView.js

@ -1,5 +1,5 @@
import { View } from 'common'; import { View } from '../../common';
import { appendAtIndex } from 'utils/dom'; import { appendAtIndex } from '../../utils/dom';
export default class PropertiesView extends View { export default class PropertiesView extends View {
initialize(o) { initialize(o) {

2
src/style_manager/view/PropertyColorView.js

@ -1,5 +1,5 @@
import PropertyNumberView from './PropertyNumberView'; import PropertyNumberView from './PropertyNumberView';
import InputColor from 'domain_abstract/ui/InputColor'; import InputColor from '../../domain_abstract/ui/InputColor';
export default class PropertyColorView extends PropertyNumberView { export default class PropertyColorView extends PropertyNumberView {
setValue(value) { setValue(value) {

4
src/style_manager/view/PropertyView.js

@ -1,6 +1,6 @@
import { View } from 'common';
import { bindAll, isUndefined, debounce } from 'underscore'; import { bindAll, isUndefined, debounce } from 'underscore';
import { isObject } from 'utils/mixins'; import { View } from '../../common';
import { isObject } from '../../utils/mixins';
const clearProp = 'data-clear-style'; const clearProp = 'data-clear-style';

4
src/style_manager/view/SectorView.js

@ -1,5 +1,5 @@
import { View } from 'common'; import { View } from '../../common';
import html from 'utils/html'; import html from '../../utils/html';
import PropertiesView from './PropertiesView'; import PropertiesView from './PropertiesView';
export default class SectorView extends View { export default class SectorView extends View {

4
src/style_manager/view/SectorsView.js

@ -1,5 +1,5 @@
import { View } from 'common'; import { View } from '../../common';
import { appendAtIndex } from 'utils/dom'; import { appendAtIndex } from '../../utils/dom';
import SectorView from './SectorView'; import SectorView from './SectorView';
export default class SectorsView extends View { export default class SectorsView extends View {

2
src/trait_manager/index.js

@ -1,4 +1,5 @@
import { debounce } from 'underscore'; import { debounce } from 'underscore';
import { Model, Module } from '../common';
import defaults from './config/config'; import defaults from './config/config';
import TraitsView from './view/TraitsView'; import TraitsView from './view/TraitsView';
import TraitView from './view/TraitView'; import TraitView from './view/TraitView';
@ -7,7 +8,6 @@ import TraitCheckboxView from './view/TraitCheckboxView';
import TraitNumberView from './view/TraitNumberView'; import TraitNumberView from './view/TraitNumberView';
import TraitColorView from './view/TraitColorView'; import TraitColorView from './view/TraitColorView';
import TraitButtonView from './view/TraitButtonView'; import TraitButtonView from './view/TraitButtonView';
import { Model, Module } from 'common';
export const evAll = 'trait'; export const evAll = 'trait';
export const evPfx = `${evAll}:`; export const evPfx = `${evAll}:`;

2
src/trait_manager/model/Trait.js

@ -1,5 +1,5 @@
import { Model } from 'common';
import { isUndefined } from 'underscore'; import { isUndefined } from 'underscore';
import { Model } from '../../common';
/** /**
* @typedef Trait * @typedef Trait

2
src/trait_manager/model/Traits.js

@ -1,5 +1,5 @@
import { Collection } from 'common';
import { isString, isArray } from 'underscore'; import { isString, isArray } from 'underscore';
import { Collection } from '../../common';
import Trait from './Trait'; import Trait from './Trait';
import TraitFactory from './TraitFactory'; import TraitFactory from './TraitFactory';

2
src/trait_manager/view/TraitColorView.js

@ -1,5 +1,5 @@
import TraitView from './TraitView'; import TraitView from './TraitView';
import InputColor from 'domain_abstract/ui/InputColor'; import InputColor from '../../domain_abstract/ui/InputColor';
export default class TraitColorView extends TraitView { export default class TraitColorView extends TraitView {
templateInput = ''; templateInput = '';

4
src/trait_manager/view/TraitNumberView.js

@ -1,6 +1,6 @@
import TraitView from './TraitView';
import { isUndefined } from 'underscore'; import { isUndefined } from 'underscore';
import InputNumber from 'domain_abstract/ui/InputNumber'; import InputNumber from '../../domain_abstract/ui/InputNumber';
import TraitView from './TraitView';
export default class TraitNumberView extends TraitView { export default class TraitNumberView extends TraitView {
getValueForTarget() { getValueForTarget() {

2
src/trait_manager/view/TraitsView.js

@ -1,4 +1,4 @@
import DomainViews from 'domain_abstract/view/DomainViews'; import DomainViews from '../../domain_abstract/view/DomainViews';
import TraitView from './TraitView'; import TraitView from './TraitView';
export default class TraitsView extends DomainViews { export default class TraitsView extends DomainViews {

2
src/utils/ColorPicker.js

@ -4,7 +4,7 @@
// https://github.com/bgrins/spectrum // https://github.com/bgrins/spectrum
// Author: Brian Grinstead // Author: Brian Grinstead
// License: MIT // License: MIT
import { hasWin } from 'utils/mixins'; import { hasWin } from './mixins';
export default function ($, undefined) { export default function ($, undefined) {
'use strict'; 'use strict';

26
src/utils/Dragger.js

@ -1,5 +1,5 @@
import { bindAll, isFunction, result, isUndefined } from 'underscore'; import { bindAll, isFunction, result, isUndefined } from 'underscore';
import { on, off, isEscKey, getPointerEvent } from 'utils/mixins'; import { on, off, isEscKey, getPointerEvent } from './mixins';
const resetPos = () => ({ x: 0, y: 0 }); const resetPos = () => ({ x: 0, y: 0 });
@ -61,7 +61,7 @@ export default class Dragger {
doc: 0, doc: 0,
// Scale result points, can also be a function // Scale result points, can also be a function
scale: 1 scale: 1,
}; };
bindAll(this, 'drag', 'stop', 'keyHandle', 'handleScroll'); bindAll(this, 'drag', 'stop', 'keyHandle', 'handleScroll');
this.setOptions(opts); this.setOptions(opts);
@ -76,7 +76,7 @@ export default class Dragger {
setOptions(opts = {}) { setOptions(opts = {}) {
this.opts = { this.opts = {
...this.opts, ...this.opts,
...opts ...opts,
}; };
} }
@ -97,7 +97,7 @@ export default class Dragger {
const actualScroll = this.getScrollInfo(); const actualScroll = this.getScrollInfo();
const scrollDiff = { const scrollDiff = {
x: actualScroll.x - lastScroll.x, x: actualScroll.x - lastScroll.x,
y: actualScroll.y - lastScroll.y y: actualScroll.y - lastScroll.y,
}; };
this.move(delta.x + scrollDiff.x, delta.y + scrollDiff.y); this.move(delta.x + scrollDiff.x, delta.y + scrollDiff.y);
this.lastScrollDiff = scrollDiff; this.lastScrollDiff = scrollDiff;
@ -132,12 +132,12 @@ export default class Dragger {
const currentPos = this.getPointerPos(ev); const currentPos = this.getPointerPos(ev);
const glDiff = { const glDiff = {
x: globScrollDiff.x + lastScrollDiff.x, x: globScrollDiff.x + lastScrollDiff.x,
y: globScrollDiff.y + lastScrollDiff.y y: globScrollDiff.y + lastScrollDiff.y,
}; };
this.globScrollDiff = glDiff; this.globScrollDiff = glDiff;
const delta = { const delta = {
x: currentPos.x - startPointer.x + glDiff.x, x: currentPos.x - startPointer.x + glDiff.x,
y: currentPos.y - startPointer.y + glDiff.y y: currentPos.y - startPointer.y + glDiff.y,
}; };
this.lastScrollDiff = resetPos(); this.lastScrollDiff = resetPos();
let { lockedAxis } = this; let { lockedAxis } = this;
@ -226,15 +226,13 @@ export default class Dragger {
return { return {
newDelta, newDelta,
trgX: this.trgX, trgX: this.trgX,
trgY: this.trgY trgY: this.trgY,
}; };
} }
isPointIn(src, trg, { offset } = {}) { isPointIn(src, trg, { offset } = {}) {
const ofst = offset || this.opts.snapOffset; const ofst = offset || this.opts.snapOffset;
return ( return (src >= trg && src <= trg + ofst) || (src <= trg && src >= trg - ofst);
(src >= trg && src <= trg + ofst) || (src <= trg && src >= trg - ofst)
);
} }
setGuideLock(guide, value) { setGuideLock(guide, value) {
@ -290,7 +288,7 @@ export default class Dragger {
this.position = { this.position = {
x: xPos, x: xPos,
y: yPos, y: yPos,
end end,
}; };
isFunction(setPosition) && setPosition(this.position); isFunction(setPosition) && setPosition(this.position);
@ -344,7 +342,7 @@ export default class Dragger {
? getPos(ev) ? getPos(ev)
: { : {
x: pEv.clientX, x: pEv.clientX,
y: pEv.clientY y: pEv.clientY,
}; };
} }
@ -358,7 +356,7 @@ export default class Dragger {
} else if (el) { } else if (el) {
result = { result = {
x: parseFloat(el.style.left), x: parseFloat(el.style.left),
y: parseFloat(el.style.top) y: parseFloat(el.style.top),
}; };
} }
@ -371,7 +369,7 @@ export default class Dragger {
return { return {
y: body ? body.scrollTop : 0, y: body ? body.scrollTop : 0,
x: body ? body.scrollLeft : 0 x: body ? body.scrollLeft : 0,
}; };
} }

20
src/utils/Droppable.js

@ -2,8 +2,8 @@
This class makes the canvas droppable This class makes the canvas droppable
*/ */
import { on, off } from 'utils/mixins';
import { bindAll, indexOf } from 'underscore'; import { bindAll, indexOf } from 'underscore';
import { on, off } from './mixins';
export default class Droppable { export default class Droppable {
constructor(em, rootEl) { constructor(em, rootEl) {
@ -17,13 +17,7 @@ export default class Droppable {
const els = Array.isArray(el) ? el : [el]; const els = Array.isArray(el) ? el : [el];
this.el = el; this.el = el;
this.counter = 0; this.counter = 0;
bindAll( bindAll(this, 'handleDragEnter', 'handleDragOver', 'handleDrop', 'handleDragLeave');
this,
'handleDragEnter',
'handleDragOver',
'handleDrop',
'handleDragLeave'
);
els.forEach(el => this.toggleEffects(el, 1)); els.forEach(el => this.toggleEffects(el, 1));
return this; return this;
@ -52,7 +46,7 @@ export default class Droppable {
}, },
customTarget({ event }) { customTarget({ event }) {
return doc.elementFromPoint(event.clientX, event.clientY); return doc.elementFromPoint(event.clientX, event.clientY);
} },
} }
: null; : null;
method(frameEl, 'pointerenter', this.handleDragEnter); method(frameEl, 'pointerenter', this.handleDragEnter);
@ -123,7 +117,7 @@ export default class Droppable {
} }
this.handleDragEnd(comp, dt); this.handleDragEnd(comp, dt);
target.remove(); target.remove();
} },
}); });
dragStop = cancel => dragger.stop(ev, { cancel }); dragStop = cancel => dragger.stop(ev, { cancel });
dragContent = cnt => (content = cnt); dragContent = cnt => (content = cnt);
@ -141,7 +135,7 @@ export default class Droppable {
pfx: 'gjs-', pfx: 'gjs-',
onEndMove: model => this.handleDragEnd(model, dt), onEndMove: model => this.handleDragEnd(model, dt),
document: this.el.ownerDocument, document: this.el.ownerDocument,
...(this.sortOpts || {}) ...(this.sortOpts || {}),
}); });
sorter.setDropContent(content); sorter.setDropContent(content);
sorter.startSort(); sorter.startSort();
@ -208,7 +202,7 @@ export default class Droppable {
content.push({ content.push({
type, type,
file, file,
attributes: { alt: file.name } attributes: { alt: file.name },
}); });
} }
} }
@ -220,7 +214,7 @@ export default class Droppable {
content = { content = {
type: 'link', type: 'link',
attributes: { href: content }, attributes: { href: content },
content: content content: content,
}; };
} else if (indexOf(types, 'text/json') >= 0) { } else if (indexOf(types, 'text/json') >= 0) {
const json = dt && dt.getData('text/json'); const json = dt && dt.getData('text/json');

39
src/utils/Resizer.js

@ -1,5 +1,5 @@
import { bindAll, defaults, isFunction, each } from 'underscore'; import { bindAll, defaults, isFunction, each } from 'underscore';
import { on, off, normalizeFloat } from 'utils/mixins'; import { on, off, normalizeFloat } from './mixins';
var defaultOpts = { var defaultOpts = {
// Function which returns custom X and Y coordinates of the mouse // Function which returns custom X and Y coordinates of the mouse
@ -66,7 +66,7 @@ var defaultOpts = {
cr: 1, // Center right cr: 1, // Center right
bl: 1, // Bottom left bl: 1, // Bottom left
bc: 1, // Bottom center bc: 1, // Bottom center
br: 1 // Bottom right br: 1, // Bottom right
}; };
var createHandler = (name, opts) => { var createHandler = (name, opts) => {
@ -84,7 +84,7 @@ var getBoundingRect = (el, win) => {
left: rect.left + w.pageXOffset, left: rect.left + w.pageXOffset,
top: rect.top + w.pageYOffset, top: rect.top + w.pageYOffset,
width: rect.width, width: rect.width,
height: rect.height height: rect.height,
}; };
}; };
@ -267,23 +267,23 @@ class Resizer {
t: rect.top, t: rect.top,
l: rect.left, l: rect.left,
w: rect.width, w: rect.width,
h: rect.height h: rect.height,
}; };
this.rectDim = { this.rectDim = {
t: rect.top, t: rect.top,
l: rect.left, l: rect.left,
w: rect.width, w: rect.width,
h: rect.height h: rect.height,
}; };
this.startPos = { this.startPos = {
x: e.clientX, x: e.clientX,
y: e.clientY y: e.clientY,
}; };
this.parentDim = { this.parentDim = {
t: parentRect.top, t: parentRect.top,
l: parentRect.left, l: parentRect.left,
w: parentRect.width, w: parentRect.width,
h: parentRect.height h: parentRect.height,
}; };
// Listen events // Listen events
@ -291,8 +291,7 @@ class Resizer {
on(doc, 'mousemove', this.move); on(doc, 'mousemove', this.move);
on(doc, 'keydown', this.handleKeyDown); on(doc, 'keydown', this.handleKeyDown);
on(doc, 'mouseup', this.stop); on(doc, 'mouseup', this.stop);
isFunction(this.onStart) && isFunction(this.onStart) && this.onStart(e, { docs: doc, config, el, resizer });
this.onStart(e, { docs: doc, config, el, resizer });
this.toggleFrames(1); this.toggleFrames(1);
this.move(e); this.move(e);
} }
@ -308,18 +307,18 @@ class Resizer {
? mouseFetch(e) ? mouseFetch(e)
: { : {
x: e.clientX, x: e.clientX,
y: e.clientY y: e.clientY,
}; };
this.currentPos = currentPos; this.currentPos = currentPos;
this.delta = { this.delta = {
x: currentPos.x - this.startPos.x, x: currentPos.x - this.startPos.x,
y: currentPos.y - this.startPos.y y: currentPos.y - this.startPos.y,
}; };
this.keys = { this.keys = {
shift: e.shiftKey, shift: e.shiftKey,
ctrl: e.ctrlKey, ctrl: e.ctrlKey,
alt: e.altKey alt: e.altKey,
}; };
this.rectDim = this.calc(this); this.rectDim = this.calc(this);
@ -367,7 +366,7 @@ class Resizer {
store, store,
selectedHandler, selectedHandler,
resizer, resizer,
config config,
}); });
} else { } else {
const elStyle = el.style; const elStyle = el.style;
@ -396,8 +395,8 @@ class Resizer {
resizer: this, resizer: this,
opts: { opts: {
...opts, ...opts,
...opt ...opt,
} },
}); });
} }
@ -461,15 +460,13 @@ class Resizer {
const parentH = this.parentDim.h; const parentH = this.parentDim.h;
const unitWidth = this.opts.unitWidth; const unitWidth = this.opts.unitWidth;
const unitHeight = this.opts.unitHeight; const unitHeight = this.opts.unitHeight;
const startW = const startW = unitWidth === '%' ? (startDim.w / 100) * parentW : startDim.w;
unitWidth === '%' ? (startDim.w / 100) * parentW : startDim.w; const startH = unitHeight === '%' ? (startDim.h / 100) * parentH : startDim.h;
const startH =
unitHeight === '%' ? (startDim.h / 100) * parentH : startDim.h;
var box = { var box = {
t: 0, t: 0,
l: 0, l: 0,
w: startW, w: startW,
h: startH h: startH,
}; };
if (!data) return; if (!data) return;
@ -537,5 +534,5 @@ class Resizer {
export default { export default {
init(opts) { init(opts) {
return new Resizer(opts); return new Resizer(opts);
} },
}; };

34
src/utils/extender.js

@ -1,4 +1,4 @@
import { isObject, isString, each, isUndefined } from 'underscore'; import { isObject } from 'underscore';
export default ({ $ }) => { export default ({ $ }) => {
if ($ && $.prototype && $.prototype.constructor.name !== 'jQuery') { if ($ && $.prototype && $.prototype.constructor.name !== 'jQuery') {
@ -6,15 +6,15 @@ export default ({ $ }) => {
// Additional helpers // Additional helpers
fn.hide = function() { fn.hide = function () {
return this.css('display', 'none'); return this.css('display', 'none');
}; };
fn.show = function() { fn.show = function () {
return this.css('display', 'block'); return this.css('display', 'block');
}; };
fn.focus = function() { fn.focus = function () {
const el = this.get(0); const el = this.get(0);
el && el.focus(); el && el.focus();
return this; return this;
@ -53,11 +53,11 @@ export default ({ $ }) => {
// For spectrum compatibility // For spectrum compatibility
fn.bind = function(ev, h) { fn.bind = function (ev, h) {
return this.on(ev, h); return this.on(ev, h);
}; };
fn.unbind = function(ev, h) { fn.unbind = function (ev, h) {
if (isObject(ev)) { if (isObject(ev)) {
for (let name in ev) { for (let name in ev) {
ev.hasOwnProperty(name) && this.off(name, ev[name]); ev.hasOwnProperty(name) && this.off(name, ev[name]);
@ -69,37 +69,37 @@ export default ({ $ }) => {
} }
}; };
fn.click = function(h) { fn.click = function (h) {
return h ? this.on('click', h) : this.trigger('click'); return h ? this.on('click', h) : this.trigger('click');
}; };
fn.change = function(h) { fn.change = function (h) {
return h ? this.on('change', h) : this.trigger('change'); return h ? this.on('change', h) : this.trigger('change');
}; };
fn.keydown = function(h) { fn.keydown = function (h) {
return h ? this.on('keydown', h) : this.trigger('keydown'); return h ? this.on('keydown', h) : this.trigger('keydown');
}; };
fn.delegate = function(selector, events, data, handler) { fn.delegate = function (selector, events, data, handler) {
if (!handler) { if (!handler) {
handler = data; handler = data;
} }
return this.on(events, selector, function(e) { return this.on(events, selector, function (e) {
e.data = data; e.data = data;
handler(e); handler(e);
}); });
}; };
fn.scrollLeft = function() { fn.scrollLeft = function () {
let el = this.get(0); let el = this.get(0);
el = el.nodeType == 9 ? el.defaultView : el; el = el.nodeType == 9 ? el.defaultView : el;
let win = el instanceof Window ? el : null; let win = el instanceof Window ? el : null;
return win ? win.pageXOffset : el.scrollLeft || 0; return win ? win.pageXOffset : el.scrollLeft || 0;
}; };
fn.scrollTop = function() { fn.scrollTop = function () {
let el = this.get(0); let el = this.get(0);
el = el.nodeType == 9 ? el.defaultView : el; el = el.nodeType == 9 ? el.defaultView : el;
let win = el instanceof Window ? el : null; let win = el instanceof Window ? el : null;
@ -107,7 +107,7 @@ export default ({ $ }) => {
}; };
const offset = $.prototype.offset; const offset = $.prototype.offset;
fn.offset = function(coords) { fn.offset = function (coords) {
let top, left; let top, left;
if (coords) { if (coords) {
@ -125,7 +125,7 @@ export default ({ $ }) => {
return offset.call(this); return offset.call(this);
}; };
$.map = function(items, clb) { $.map = function (items, clb) {
const ar = []; const ar = [];
for (var i = 0; i < items.length; i++) { for (var i = 0; i < items.length; i++) {
@ -137,11 +137,11 @@ export default ({ $ }) => {
const indexOf = Array.prototype.indexOf; const indexOf = Array.prototype.indexOf;
$.inArray = function(val, arr, i) { $.inArray = function (val, arr, i) {
return arr == null ? -1 : indexOf.call(arr, val, i); return arr == null ? -1 : indexOf.call(arr, val, i);
}; };
$.Event = function(src, props) { $.Event = function (src, props) {
if (!(this instanceof $.Event)) { if (!(this instanceof $.Event)) {
return new $.Event(src, props); return new $.Event(src, props);
} }

4
src/utils/fetch.js

@ -1,5 +1,5 @@
import Promise from 'promise-polyfill'; import Promise from 'promise-polyfill';
import { hasWin } from 'utils/mixins'; import { hasWin } from './mixins';
if (hasWin()) { if (hasWin()) {
window.Promise = window.Promise || Promise; window.Promise = window.Promise || Promise;
@ -21,7 +21,7 @@ export default typeof fetch == 'function'
res({ res({
status: req.status, status: req.status,
statusText: req.statusText, statusText: req.statusText,
text: () => Promise.resolve(req.responseText) text: () => Promise.resolve(req.responseText),
}); });
req.onerror = rej; req.onerror = rej;

Loading…
Cancel
Save