|
|
@ -1,14 +1,5 @@ |
|
|
import Backbone from 'backbone'; |
|
|
import Backbone from 'backbone'; |
|
|
import { |
|
|
import { isEmpty, isArray, isString, each, includes, extend, flatten, debounce } from 'underscore'; |
|
|
isEmpty, |
|
|
|
|
|
isArray, |
|
|
|
|
|
isString, |
|
|
|
|
|
each, |
|
|
|
|
|
includes, |
|
|
|
|
|
extend, |
|
|
|
|
|
flatten, |
|
|
|
|
|
debounce |
|
|
|
|
|
} from 'underscore'; |
|
|
|
|
|
import Component, { keySymbol, keySymbols } from './Component'; |
|
|
import Component, { keySymbol, keySymbols } from './Component'; |
|
|
|
|
|
|
|
|
const getIdsToKeep = (prev, res = []) => { |
|
|
const getIdsToKeep = (prev, res = []) => { |
|
|
@ -28,6 +19,21 @@ const getNewIds = (items, res = []) => { |
|
|
return res; |
|
|
return res; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const getComponentsFromDefs = (items, all = {}) => { |
|
|
|
|
|
return items.map(item => { |
|
|
|
|
|
const id = item.attributes?.id; |
|
|
|
|
|
let result = item; |
|
|
|
|
|
|
|
|
|
|
|
if (id && all[id]) { |
|
|
|
|
|
result = all[id]; |
|
|
|
|
|
} else if (isArray(result.components)) { |
|
|
|
|
|
result.components = getComponentsFromDefs(result.components, all); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
export default Backbone.Collection.extend({ |
|
|
export default Backbone.Collection.extend({ |
|
|
initialize(models, opt = {}) { |
|
|
initialize(models, opt = {}) { |
|
|
this.opt = opt; |
|
|
this.opt = opt; |
|
|
@ -50,6 +56,23 @@ export default Backbone.Collection.extend({ |
|
|
models.each(model => this.onAdd(model)); |
|
|
models.each(model => this.onAdd(model)); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
resetFromString(input = '', opts = {}) { |
|
|
|
|
|
opts.keepIds = getIdsToKeep(this); |
|
|
|
|
|
const { domc } = this; |
|
|
|
|
|
const allByID = domc ? domc.allById() : {}; |
|
|
|
|
|
const parsed = this.parseString(input, opts); |
|
|
|
|
|
const cmps = isArray(parsed) ? parsed : [parsed]; |
|
|
|
|
|
console.log({ |
|
|
|
|
|
len: this.length, |
|
|
|
|
|
input, |
|
|
|
|
|
cmps, |
|
|
|
|
|
allByID, |
|
|
|
|
|
newCmp: getComponentsFromDefs(cmps, allByID), |
|
|
|
|
|
keepIds: opts.keepIds, |
|
|
|
|
|
}); |
|
|
|
|
|
this.reset(cmps, opts); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
removeChildren(removed, coll, opts = {}) { |
|
|
removeChildren(removed, coll, opts = {}) { |
|
|
// Removing a parent component can cause this function
|
|
|
// Removing a parent component can cause this function
|
|
|
// to be called with an already removed child element
|
|
|
// to be called with an already removed child element
|
|
|
@ -83,7 +106,7 @@ export default Backbone.Collection.extend({ |
|
|
|
|
|
|
|
|
if (!removed.opt.temporary) { |
|
|
if (!removed.opt.temporary) { |
|
|
em.get('Commands').run('core:component-style-clear', { |
|
|
em.get('Commands').run('core:component-style-clear', { |
|
|
target: removed |
|
|
target: removed, |
|
|
}); |
|
|
}); |
|
|
removed.removed(); |
|
|
removed.removed(); |
|
|
removed.trigger('removed'); |
|
|
removed.trigger('removed'); |
|
|
@ -128,7 +151,7 @@ export default Backbone.Collection.extend({ |
|
|
attrs.type && |
|
|
attrs.type && |
|
|
em.logWarning(`Component type '${attrs.type}' not found`, { |
|
|
em.logWarning(`Component type '${attrs.type}' not found`, { |
|
|
attrs, |
|
|
attrs, |
|
|
options |
|
|
options, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -146,7 +169,7 @@ export default Backbone.Collection.extend({ |
|
|
const { at, ...optsToPass } = opt; |
|
|
const { at, ...optsToPass } = opt; |
|
|
cssc.addCollection(parsed.css, { |
|
|
cssc.addCollection(parsed.css, { |
|
|
...optsToPass, |
|
|
...optsToPass, |
|
|
extend: 1 |
|
|
extend: 1, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -170,9 +193,7 @@ export default Backbone.Collection.extend({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const isMult = isArray(models); |
|
|
const isMult = isArray(models); |
|
|
models = (isMult ? models : [models]) |
|
|
models = (isMult ? models : [models]).filter(i => i).map(model => this.processDef(model)); |
|
|
.filter(i => i) |
|
|
|
|
|
.map(model => this.processDef(model)); |
|
|
|
|
|
models = isMult ? flatten(models, 1) : models[0]; |
|
|
models = isMult ? flatten(models, 1) : models[0]; |
|
|
|
|
|
|
|
|
const result = Backbone.Collection.prototype.add.apply(this, [models, opt]); |
|
|
const result = Backbone.Collection.prototype.add.apply(this, [models, opt]); |
|
|
@ -239,14 +260,7 @@ export default Backbone.Collection.extend({ |
|
|
const avoidInline = em && em.getConfig('avoidInlineStyle'); |
|
|
const avoidInline = em && em.getConfig('avoidInlineStyle'); |
|
|
domc && domc.Component.ensureInList(model); |
|
|
domc && domc.Component.ensureInList(model); |
|
|
|
|
|
|
|
|
if ( |
|
|
if (!isEmpty(style) && !avoidInline && em && em.get && em.getConfig('forceClass') && !opts.temporary) { |
|
|
!isEmpty(style) && |
|
|
|
|
|
!avoidInline && |
|
|
|
|
|
em && |
|
|
|
|
|
em.get && |
|
|
|
|
|
em.getConfig('forceClass') && |
|
|
|
|
|
!opts.temporary |
|
|
|
|
|
) { |
|
|
|
|
|
const name = model.cid; |
|
|
const name = model.cid; |
|
|
const rule = em.get('CssComposer').setClassRule(name, style); |
|
|
const rule = em.get('CssComposer').setClassRule(name, style); |
|
|
model.setStyle({}); |
|
|
model.setStyle({}); |
|
|
@ -257,7 +271,7 @@ export default Backbone.Collection.extend({ |
|
|
this.__onAddEnd(); |
|
|
this.__onAddEnd(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
__onAddEnd: debounce(function() { |
|
|
__onAddEnd: debounce(function () { |
|
|
// TODO to check symbols on load, probably this might be removed as symbols
|
|
|
// TODO to check symbols on load, probably this might be removed as symbols
|
|
|
// are always recovered from the model
|
|
|
// are always recovered from the model
|
|
|
// const { domc } = this;
|
|
|
// const { domc } = this;
|
|
|
@ -283,5 +297,5 @@ export default Backbone.Collection.extend({ |
|
|
// });
|
|
|
// });
|
|
|
// };
|
|
|
// };
|
|
|
// onAll(toCheck);
|
|
|
// onAll(toCheck);
|
|
|
}) |
|
|
}), |
|
|
}); |
|
|
}); |
|
|
|