|
|
@ -1,30 +1,31 @@ |
|
|
import { isUndefined, isString, bindAll } from 'underscore'; |
|
|
import { isUndefined, isString, bindAll } from 'underscore'; |
|
|
import { getModel, isEscKey, isEnterKey } from 'utils/mixins'; |
|
|
import { View } from '../../common'; |
|
|
import Backbone from 'backbone'; |
|
|
import { getModel, isEscKey, isEnterKey } from '../../utils/mixins'; |
|
|
import ComponentView from 'dom_components/view/ComponentView'; |
|
|
import ComponentView from '../../dom_components/view/ComponentView'; |
|
|
import { eventDrag } from 'dom_components/model/Component'; |
|
|
import { eventDrag } from '../../dom_components/model/Component'; |
|
|
|
|
|
|
|
|
const inputProp = 'contentEditable'; |
|
|
const inputProp = 'contentEditable'; |
|
|
const styleOpts = { mediaText: '' }; |
|
|
const styleOpts = { mediaText: '' }; |
|
|
const $ = Backbone.$; |
|
|
|
|
|
const isStyleHidden = (style = {}) => { |
|
|
const isStyleHidden = (style = {}) => { |
|
|
return (style.display || '').trim().indexOf('none') === 0; |
|
|
return (style.display || '').trim().indexOf('none') === 0; |
|
|
}; |
|
|
}; |
|
|
let ItemsView; |
|
|
let ItemsView; |
|
|
|
|
|
|
|
|
export default Backbone.View.extend({ |
|
|
export default class ItemView extends View { |
|
|
events: { |
|
|
events() { |
|
|
'mousedown [data-toggle-move]': 'startSort', |
|
|
return { |
|
|
'touchstart [data-toggle-move]': 'startSort', |
|
|
'mousedown [data-toggle-move]': 'startSort', |
|
|
'click [data-toggle-visible]': 'toggleVisibility', |
|
|
'touchstart [data-toggle-move]': 'startSort', |
|
|
'click [data-toggle-open]': 'toggleOpening', |
|
|
'click [data-toggle-visible]': 'toggleVisibility', |
|
|
'click [data-toggle-select]': 'handleSelect', |
|
|
'click [data-toggle-open]': 'toggleOpening', |
|
|
'mouseover [data-toggle-select]': 'handleHover', |
|
|
'click [data-toggle-select]': 'handleSelect', |
|
|
'mouseout [data-toggle-select]': 'handleHoverOut', |
|
|
'mouseover [data-toggle-select]': 'handleHover', |
|
|
'dblclick [data-name]': 'handleEdit', |
|
|
'mouseout [data-toggle-select]': 'handleHoverOut', |
|
|
'keydown [data-name]': 'handleEditKey', |
|
|
'dblclick [data-name]': 'handleEdit', |
|
|
'focusout [data-name]': 'handleEditEnd', |
|
|
'keydown [data-name]': 'handleEditKey', |
|
|
}, |
|
|
'focusout [data-name]': 'handleEditEnd', |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
template(model) { |
|
|
template(model) { |
|
|
const { pfx, ppfx, config, clsNoEdit } = this; |
|
|
const { pfx, ppfx, config, clsNoEdit } = this; |
|
|
@ -61,7 +62,7 @@ export default Backbone.View.extend({ |
|
|
<i class="fa fa-arrows"></i> |
|
|
<i class="fa fa-arrows"></i> |
|
|
</div> |
|
|
</div> |
|
|
<div class="${this.clsChildren}"></div>`; |
|
|
<div class="${this.clsChildren}"></div>`; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
initialize(o = {}) { |
|
|
initialize(o = {}) { |
|
|
bindAll(this, '__render'); |
|
|
bindAll(this, '__render'); |
|
|
@ -109,11 +110,11 @@ export default Backbone.View.extend({ |
|
|
render: this.__render, |
|
|
render: this.__render, |
|
|
listenTo: this.listenTo, |
|
|
listenTo: this.listenTo, |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
updateName() { |
|
|
updateName() { |
|
|
this.getInputName().innerText = this.model.getName(); |
|
|
this.getInputName().innerText = this.model.getName(); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
getVisibilityEl() { |
|
|
getVisibilityEl() { |
|
|
if (!this.eyeEl) { |
|
|
if (!this.eyeEl) { |
|
|
@ -121,7 +122,7 @@ export default Backbone.View.extend({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return this.eyeEl; |
|
|
return this.eyeEl; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
updateVisibility() { |
|
|
updateVisibility() { |
|
|
const pfx = this.pfx; |
|
|
const pfx = this.pfx; |
|
|
@ -132,7 +133,7 @@ export default Backbone.View.extend({ |
|
|
const method = hidden ? 'addClass' : 'removeClass'; |
|
|
const method = hidden ? 'addClass' : 'removeClass'; |
|
|
this.$el[method](hClass); |
|
|
this.$el[method](hClass); |
|
|
this.getVisibilityEl()[method](hideIcon); |
|
|
this.getVisibilityEl()[method](hideIcon); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Toggle visibility |
|
|
* Toggle visibility |
|
|
@ -163,7 +164,7 @@ export default Backbone.View.extend({ |
|
|
|
|
|
|
|
|
model.setStyle(style, styleOpts); |
|
|
model.setStyle(style, styleOpts); |
|
|
em && em.trigger('component:toggled'); // Updates Style Manager #2938
|
|
|
em && em.trigger('component:toggled'); // Updates Style Manager #2938
|
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Handle the edit of the component name |
|
|
* Handle the edit of the component name |
|
|
@ -177,12 +178,12 @@ export default Backbone.View.extend({ |
|
|
document.execCommand('selectAll', false, null); |
|
|
document.execCommand('selectAll', false, null); |
|
|
em && em.setEditing(1); |
|
|
em && em.setEditing(1); |
|
|
$el.find(`.${this.inputNameCls}`).removeClass(clsNoEdit).addClass(clsEdit); |
|
|
$el.find(`.${this.inputNameCls}`).removeClass(clsNoEdit).addClass(clsEdit); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
handleEditKey(ev) { |
|
|
handleEditKey(ev) { |
|
|
ev.stopPropagation(); |
|
|
ev.stopPropagation(); |
|
|
(isEscKey(ev) || isEnterKey(ev)) && this.handleEditEnd(ev); |
|
|
(isEscKey(ev) || isEnterKey(ev)) && this.handleEditEnd(ev); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Handle with the end of editing of the component name |
|
|
* Handle with the end of editing of the component name |
|
|
@ -197,11 +198,11 @@ export default Backbone.View.extend({ |
|
|
this.setName(name, { component: this.model, propName: 'custom-name' }); |
|
|
this.setName(name, { component: this.model, propName: 'custom-name' }); |
|
|
em && em.setEditing(0); |
|
|
em && em.setEditing(0); |
|
|
$el.find(`.${this.inputNameCls}`).addClass(clsNoEdit).removeClass(clsEdit); |
|
|
$el.find(`.${this.inputNameCls}`).addClass(clsNoEdit).removeClass(clsEdit); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
setName(name, { propName }) { |
|
|
setName(name, { propName }) { |
|
|
this.model.set(propName, name); |
|
|
this.model.set(propName, name); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Get the input containing the name of the component |
|
|
* Get the input containing the name of the component |
|
|
@ -212,7 +213,7 @@ export default Backbone.View.extend({ |
|
|
this.inputName = this.el.querySelector(`.${this.inputNameCls}`); |
|
|
this.inputName = this.el.querySelector(`.${this.inputNameCls}`); |
|
|
} |
|
|
} |
|
|
return this.inputName; |
|
|
return this.inputName; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Update item opening |
|
|
* Update item opening |
|
|
@ -233,7 +234,7 @@ export default Backbone.View.extend({ |
|
|
this.getCaret().removeClass(chvDown); |
|
|
this.getCaret().removeClass(chvDown); |
|
|
delete opened[model.cid]; |
|
|
delete opened[model.cid]; |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Toggle item opening |
|
|
* Toggle item opening |
|
|
@ -248,7 +249,7 @@ export default Backbone.View.extend({ |
|
|
if (!model.get('components').length) return; |
|
|
if (!model.get('components').length) return; |
|
|
|
|
|
|
|
|
model.set('open', !model.get('open')); |
|
|
model.set('open', !model.get('open')); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Handle component selection |
|
|
* Handle component selection |
|
|
@ -262,7 +263,7 @@ export default Backbone.View.extend({ |
|
|
const scroll = config.scrollCanvas; |
|
|
const scroll = config.scrollCanvas; |
|
|
scroll && model.views.forEach(view => view.scrollIntoView(scroll)); |
|
|
scroll && model.views.forEach(view => view.scrollIntoView(scroll)); |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Handle component selection |
|
|
* Handle component selection |
|
|
@ -271,13 +272,13 @@ export default Backbone.View.extend({ |
|
|
e.stopPropagation(); |
|
|
e.stopPropagation(); |
|
|
const { em, config, model } = this; |
|
|
const { em, config, model } = this; |
|
|
em && config.showHover && em.setHovered(model, { fromLayers: 1 }); |
|
|
em && config.showHover && em.setHovered(model, { fromLayers: 1 }); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
handleHoverOut(ev) { |
|
|
handleHoverOut(ev) { |
|
|
ev.stopPropagation(); |
|
|
ev.stopPropagation(); |
|
|
const { em, config } = this; |
|
|
const { em, config } = this; |
|
|
em && config.showHover && em.setHovered(0, { fromLayers: 1 }); |
|
|
em && config.showHover && em.setHovered(0, { fromLayers: 1 }); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Delegate to sorter |
|
|
* Delegate to sorter |
|
|
@ -294,7 +295,7 @@ export default Backbone.View.extend({ |
|
|
sorter.onMoveClb = data => em.trigger(eventDrag, data); |
|
|
sorter.onMoveClb = data => em.trigger(eventDrag, data); |
|
|
sorter.startSort(e.target); |
|
|
sorter.startSort(e.target); |
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Freeze item |
|
|
* Freeze item |
|
|
@ -303,7 +304,7 @@ export default Backbone.View.extend({ |
|
|
freeze() { |
|
|
freeze() { |
|
|
this.$el.addClass(this.pfx + 'opac50'); |
|
|
this.$el.addClass(this.pfx + 'opac50'); |
|
|
this.model.set('open', 0); |
|
|
this.model.set('open', 0); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Unfreeze item |
|
|
* Unfreeze item |
|
|
@ -311,7 +312,7 @@ export default Backbone.View.extend({ |
|
|
* */ |
|
|
* */ |
|
|
unfreeze() { |
|
|
unfreeze() { |
|
|
this.$el.removeClass(this.pfx + 'opac50'); |
|
|
this.$el.removeClass(this.pfx + 'opac50'); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Update item on status change |
|
|
* Update item on status change |
|
|
@ -324,7 +325,7 @@ export default Backbone.View.extend({ |
|
|
noExtHl: 1, |
|
|
noExtHl: 1, |
|
|
}, |
|
|
}, |
|
|
]); |
|
|
]); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Check if component is visible |
|
|
* Check if component is visible |
|
|
@ -333,7 +334,7 @@ export default Backbone.View.extend({ |
|
|
* */ |
|
|
* */ |
|
|
isVisible() { |
|
|
isVisible() { |
|
|
return !isStyleHidden(this.model.getStyle()); |
|
|
return !isStyleHidden(this.model.getStyle()); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Update item aspect after children changes |
|
|
* Update item aspect after children changes |
|
|
@ -354,7 +355,7 @@ export default Backbone.View.extend({ |
|
|
title[count ? 'removeClass' : 'addClass'](clsNoChild); |
|
|
title[count ? 'removeClass' : 'addClass'](clsNoChild); |
|
|
if (cnt) cnt.innerHTML = count || ''; |
|
|
if (cnt) cnt.innerHTML = count || ''; |
|
|
!count && model.set('open', 0); |
|
|
!count && model.set('open', 0); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Count children inside model |
|
|
* Count children inside model |
|
|
@ -371,7 +372,7 @@ export default Backbone.View.extend({ |
|
|
count++; |
|
|
count++; |
|
|
}, this); |
|
|
}, this); |
|
|
return count; |
|
|
return count; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
getCaret() { |
|
|
getCaret() { |
|
|
if (!this.caret || !this.caret.length) { |
|
|
if (!this.caret || !this.caret.length) { |
|
|
@ -380,33 +381,33 @@ export default Backbone.View.extend({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return this.caret; |
|
|
return this.caret; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
setRoot(el) { |
|
|
setRoot(el) { |
|
|
el = isString(el) ? this.em.getWrapper().find(el)[0] : el; |
|
|
el = isString(el) ? this.em.getWrapper().find(el)[0] : el; |
|
|
const model = getModel(el, $); |
|
|
const model = getModel(el); |
|
|
if (!model) return; |
|
|
if (!model) return; |
|
|
this.stopListening(); |
|
|
this.stopListening(); |
|
|
this.model = model; |
|
|
this.model = model; |
|
|
this.initialize(this.opt); |
|
|
this.initialize(this.opt); |
|
|
this._rendered && this.render(); |
|
|
this._rendered && this.render(); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
updateLayerable() { |
|
|
updateLayerable() { |
|
|
const { parentView } = this; |
|
|
const { parentView } = this; |
|
|
const toRerender = parentView || this; |
|
|
const toRerender = parentView || this; |
|
|
toRerender.render(); |
|
|
toRerender.render(); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
__clearItems() { |
|
|
__clearItems() { |
|
|
const { items } = this; |
|
|
const { items } = this; |
|
|
items && items.remove(); |
|
|
items && items.remove(); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
remove() { |
|
|
remove() { |
|
|
Backbone.View.prototype.remove.apply(this, arguments); |
|
|
View.prototype.remove.apply(this, arguments); |
|
|
this.__clearItems(); |
|
|
this.__clearItems(); |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
const { model, config, pfx, ppfx, opt } = this; |
|
|
const { model, config, pfx, ppfx, opt } = this; |
|
|
@ -454,7 +455,7 @@ export default Backbone.View.extend({ |
|
|
this.__render(); |
|
|
this.__render(); |
|
|
this._rendered = 1; |
|
|
this._rendered = 1; |
|
|
return this; |
|
|
return this; |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
__render() { |
|
|
__render() { |
|
|
const { model, config, el } = this; |
|
|
const { model, config, el } = this; |
|
|
@ -462,5 +463,5 @@ export default Backbone.View.extend({ |
|
|
const opt = { component: model, el }; |
|
|
const opt = { component: model, el }; |
|
|
onRender.bind(this)(opt); |
|
|
onRender.bind(this)(opt); |
|
|
this.em.trigger('layer:render', opt); |
|
|
this.em.trigger('layer:render', opt); |
|
|
}, |
|
|
} |
|
|
}); |
|
|
} |
|
|
|