diff --git a/CHANGELOG.md b/CHANGELOG.md index 79d739d8..3999573b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ - strip: nested strips were inheriting their parent's `spacing` - modal: prevent error when retrieving a child's property - modal: prevent touch event from affecting elements behind the popup when closing it - - clone: some properies in target widget were not applied to the clone + - clone: some properies in target widget were not applied to the clone + - clone: prevent clone from resetting its target value when created - text: vertical centering issues in narrow widgets - dynamic properties: when using a widget's own value to determine its osc settings, these are checked and updated if needed before sending the message - editor diff --git a/src/browser/js/app/widgets/containers/clone.js b/src/browser/js/app/widgets/containers/clone.js index ca6f7206..89807611 100644 --- a/src/browser/js/app/widgets/containers/clone.js +++ b/src/browser/js/app/widgets/containers/clone.js @@ -3,7 +3,7 @@ var Widget = require('../common/widget'), resize = require('../../events/resize'), parser = require('../../parser') -module.exports = class Clone extends Widget { +class Clone extends Widget { static defaults() { @@ -45,7 +45,7 @@ module.exports = class Clone extends Widget { this.cloneClass = [] this.container.classList.add('empty') - + this.getCloneTarget() if (this.cloneTarget) this.createClone() @@ -109,6 +109,7 @@ module.exports = class Clone extends Widget { this.container.classList.remove(...this.cloneClass) this.container.classList.add('clone-container', 'empty') this.cloneClass = [] + if (this.cloneTarget) this.cloneTarget.off(`widget-created.${this.hash}`) } @@ -119,11 +120,21 @@ module.exports = class Clone extends Widget { this.cleanClone() - this.cloneClass = this.cloneTarget.container.classList + this.cloneClass = [...this.cloneTarget.container.classList].filter(i => i !== 'absolute-position' && i !== 'widget') this.container.classList.remove('empty') this.container.classList.add(...this.cloneClass) - parser.parse([{...Widget.deepCopy(this.cloneTarget.props), ...this.getProp('props')}], this.widget, this) + var clone = parser.parse([{...Widget.deepCopy(this.cloneTarget.props), ...this.getProp('props')}], this.widget, this) + + if (clone.getProp('id') === this.cloneTarget.getProp('id')) { + widgetManager.trigger('change.*', [{ + widget: this.cloneTarget, + id: this.cloneTarget.getProp('id'), + linkId: this.cloneTarget.getProp('linkId'), + options: {} + }]) + } + DOM.each(this.widget, '.widget', (el)=>{el.classList.add('not-editable')}) @@ -136,6 +147,23 @@ module.exports = class Clone extends Widget { } + onPropChanged(propName, options, oldPropValue) { + + if (super.onPropChanged(...arguments)) return true + + switch (propName) { + + case 'widgetId': + this.cleanClone() + this.cloneTarget = null + this.getCloneTarget() + if (this.cloneTarget) this.createClone() + return + + } + + } + onRemove(){ if (this.cloneTarget) this.cloneTarget.off(`widget-created.${this.hash}`) @@ -145,3 +173,9 @@ module.exports = class Clone extends Widget { } } + +Clone.dynamicProps = Clone.prototype.constructor.dynamicProps.concat( + 'widgetId' +) + +module.exports = Clone