|
|
|
@ -179,7 +179,7 @@ const Component = Backbone.Model.extend(Styleable).extend( |
|
|
|
...(this.defaults.attributes || {}), |
|
|
|
...(this.get('attributes') || {}) |
|
|
|
}); |
|
|
|
this.ccid = Component.createId(this); |
|
|
|
this.ccid = Component.createId(this, opt); |
|
|
|
this.initClasses(); |
|
|
|
this.initTraits(); |
|
|
|
this.initComponents(); |
|
|
|
@ -1290,13 +1290,13 @@ const Component = Backbone.Model.extend(Styleable).extend( |
|
|
|
* @return {string} |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
createId(model) { |
|
|
|
createId(model, opts = {}) { |
|
|
|
const list = Component.getList(model); |
|
|
|
let { id } = model.get('attributes'); |
|
|
|
let nextId; |
|
|
|
|
|
|
|
if (id) { |
|
|
|
nextId = Component.getIncrementId(id, list); |
|
|
|
nextId = Component.getIncrementId(id, list, opts); |
|
|
|
model.setId(nextId); |
|
|
|
} else { |
|
|
|
nextId = Component.getNewId(list); |
|
|
|
@ -1320,13 +1320,16 @@ const Component = Backbone.Model.extend(Styleable).extend( |
|
|
|
return newId; |
|
|
|
}, |
|
|
|
|
|
|
|
getIncrementId(id, list) { |
|
|
|
getIncrementId(id, list, opts = {}) { |
|
|
|
const { keepIds = [] } = opts; |
|
|
|
let counter = 1; |
|
|
|
let newId = id; |
|
|
|
|
|
|
|
while (list[newId]) { |
|
|
|
counter++; |
|
|
|
newId = `${id}-${counter}`; |
|
|
|
if (keepIds.indexOf(id) < 0) { |
|
|
|
while (list[newId]) { |
|
|
|
counter++; |
|
|
|
newId = `${id}-${counter}`; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return newId; |
|
|
|
@ -1347,14 +1350,15 @@ const Component = Backbone.Model.extend(Styleable).extend( |
|
|
|
* (are not Components/CSSRules yet), for duplicated id and fixes them |
|
|
|
* This method is used in Components.js just after the parsing |
|
|
|
*/ |
|
|
|
checkId(components, styles = [], list = {}) { |
|
|
|
checkId(components, styles = [], list = {}, opts = {}) { |
|
|
|
const comps = isArray(components) ? components : [components]; |
|
|
|
const { keepIds = [] } = opts; |
|
|
|
comps.forEach(comp => { |
|
|
|
const { attributes = {}, components } = comp; |
|
|
|
const { id } = attributes; |
|
|
|
|
|
|
|
// Check if we have collisions with current components
|
|
|
|
if (id && list[id]) { |
|
|
|
if (id && list[id] && keepIds.indexOf(id) < 0) { |
|
|
|
const newId = Component.getIncrementId(id, list); |
|
|
|
attributes.id = newId; |
|
|
|
// Update passed styles
|
|
|
|
@ -1367,7 +1371,7 @@ const Component = Backbone.Model.extend(Styleable).extend( |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
components && Component.checkId(components, styles, list); |
|
|
|
components && Component.checkId(components, styles, list, opts); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|