Browse Source

Add Frame class

pull/3563/head
Artur Arseniev 5 years ago
parent
commit
fddec44567
  1. 70
      src/canvas/model/Frame.js

70
src/canvas/model/Frame.js

@ -5,20 +5,22 @@ import { isComponent, isObject } from 'utils/mixins';
const keyAutoW = '__aw'; const keyAutoW = '__aw';
const keyAutoH = '__ah'; const keyAutoH = '__ah';
export default Model.extend({ export default class Frame extends Model {
defaults: () => ({ defaults() {
x: 0, return {
y: 0, x: 0,
changesCount: 0, y: 0,
attributes: {}, changesCount: 0,
width: null, attributes: {},
height: null, width: null,
head: [], height: null,
component: '', head: [],
styles: '', component: '',
_undo: true, styles: '',
_undoexc: ['changesCount'] _undo: true,
}), _undoexc: ['changesCount']
};
}
initialize(props, opts = {}) { initialize(props, opts = {}) {
const { config } = opts; const { config } = opts;
@ -67,51 +69,51 @@ export default Model.extend({
!props.width && this.set(keyAutoW, 1); !props.width && this.set(keyAutoW, 1);
!props.height && this.set(keyAutoH, 1); !props.height && this.set(keyAutoH, 1);
}, }
onRemove() { onRemove() {
this.getComponent().remove({ root: 1 }); this.getComponent().remove({ root: 1 });
}, }
changesUp: debounce(function(opt = {}) { changesUp(opt = {}) {
if (opt.temporary || opt.noCount || opt.avoidStore) { if (opt.temporary || opt.noCount || opt.avoidStore) {
return; return;
} }
this.set('changesCount', this.get('changesCount') + 1); this.set('changesCount', this.get('changesCount') + 1);
}), }
getComponent() { getComponent() {
return this.get('component'); return this.get('component');
}, }
getStyles() { getStyles() {
return this.get('styles'); return this.get('styles');
}, }
disable() { disable() {
this.trigger('disable'); this.trigger('disable');
}, }
remove() { remove() {
this.view = 0; this.view = 0;
const coll = this.collection; const coll = this.collection;
return coll && coll.remove(this); return coll && coll.remove(this);
}, }
getHead() { getHead() {
const head = this.get('head') || []; const head = this.get('head') || [];
return [...head]; return [...head];
}, }
setHead(value) { setHead(value) {
return this.set('head', [...value]); return this.set('head', [...value]);
}, }
addHeadItem(item) { addHeadItem(item) {
const head = this.getHead(); const head = this.getHead();
head.push(item); head.push(item);
this.setHead(head); this.setHead(head);
}, }
getHeadByAttr(attr, value, tag) { getHeadByAttr(attr, value, tag) {
const head = this.getHead(); const head = this.getHead();
@ -121,7 +123,7 @@ export default Model.extend({
item.attributes[attr] == value && item.attributes[attr] == value &&
(!tag || tag === item.tag) (!tag || tag === item.tag)
)[0]; )[0];
}, }
removeHeadByAttr(attr, value, tag) { removeHeadByAttr(attr, value, tag) {
const head = this.getHead(); const head = this.getHead();
@ -132,7 +134,7 @@ export default Model.extend({
head.splice(index, 1); head.splice(index, 1);
this.setHead(head); this.setHead(head);
} }
}, }
addLink(href) { addLink(href) {
const tag = 'link'; const tag = 'link';
@ -144,11 +146,11 @@ export default Model.extend({
rel: 'stylesheet' rel: 'stylesheet'
} }
}); });
}, }
removeLink(href) { removeLink(href) {
this.removeHeadByAttr('href', href, 'link'); this.removeHeadByAttr('href', href, 'link');
}, }
addScript(src) { addScript(src) {
const tag = 'script'; const tag = 'script';
@ -157,20 +159,20 @@ export default Model.extend({
tag, tag,
attributes: { src } attributes: { src }
}); });
}, }
removeScript(src) { removeScript(src) {
this.removeHeadByAttr('src', src, 'script'); this.removeHeadByAttr('src', src, 'script');
}, }
getPage() { getPage() {
const coll = this.collection; const coll = this.collection;
return coll && coll.page; return coll && coll.page;
}, }
_emitUpdated(data = {}) { _emitUpdated(data = {}) {
this.em.trigger('frame:updated', { frame: this, ...data }); this.em.trigger('frame:updated', { frame: this, ...data });
}, }
toJSON(opts = {}) { toJSON(opts = {}) {
const obj = Model.prototype.toJSON.call(this, opts); const obj = Model.prototype.toJSON.call(this, opts);
@ -206,4 +208,4 @@ export default Model.extend({
return obj; return obj;
} }
}); }

Loading…
Cancel
Save