editor: move linked props check to widget base class to ensure clone and matrix apply it
This commit is contained in:
parent
96cf36a47a
commit
64df539051
4 changed files with 31 additions and 22 deletions
|
|
@ -16,30 +16,14 @@ function updateWidget(widget, options={}) {
|
|||
|
||||
if (options.changedProps) {
|
||||
// alternate routine for small edits
|
||||
var propNames = options.changedProps,
|
||||
propValues = propNames.map(x => widget.props[x]),
|
||||
linkedProps = []
|
||||
|
||||
Object.values(widget.nestedLinkedProps).forEach(l => linkedProps = linkedProps.concat(l))
|
||||
Object.values(widget.linkedProps).forEach(l => linkedProps = linkedProps.concat(l))
|
||||
Object.values(widget.linkedPropsValue).forEach(l => linkedProps = linkedProps.concat(l))
|
||||
Object.values(widget.oscReceivers).forEach(r => linkedProps = linkedProps.concat(r.propNames))
|
||||
var propNames = options.changedProps
|
||||
|
||||
if (
|
||||
// if non dynamic props have changed, skip this and use rebuild routine
|
||||
!propNames.some(n => !widget.isDynamicProp(n))
|
||||
) {
|
||||
|
||||
var edited = widget.updateProps(options.changedProps, null) || widget
|
||||
|
||||
if (
|
||||
// if prop/osc listeners have changed (@{} / OSC{})
|
||||
// refresh the widget's props cache and update linked props bindings
|
||||
propValues.some(x => typeof x === 'string' && x.match(/OSC\{|@\{/))
|
||||
|| propNames.some(n => linkedProps.includes(n))
|
||||
) {
|
||||
widget.createPropsCache()
|
||||
}
|
||||
var edited = widget.updateProps(options.changedProps, null, {fromEditor: true}) || widget
|
||||
|
||||
if (editor.selectedWidgets.includes(widget) && !options.preventSelect) {
|
||||
editor.select(edited)
|
||||
|
|
|
|||
|
|
@ -268,6 +268,27 @@ class Widget extends EventEmitter {
|
|||
|
||||
getSplit() {}
|
||||
|
||||
checkLinkedProps(propNames) {
|
||||
|
||||
// Dynamic props cache check
|
||||
var linkedProps = []
|
||||
|
||||
Object.values(this.nestedLinkedProps).forEach(l => linkedProps = linkedProps.concat(l))
|
||||
Object.values(this.linkedProps).forEach(l => linkedProps = linkedProps.concat(l))
|
||||
Object.values(this.linkedPropsValue).forEach(l => linkedProps = linkedProps.concat(l))
|
||||
Object.values(this.oscReceivers).forEach(r => linkedProps = linkedProps.concat(r.propNames))
|
||||
|
||||
if (
|
||||
// if prop/osc listeners have changed (@{} / OSC{})
|
||||
// refresh the widget's props cache and update linked props bindings
|
||||
propNames.map(x => this.props[x]).some(x => typeof x === 'string' && x.match(/OSC\{|@\{/))
|
||||
|| propNames.some(n => linkedProps.includes(n))
|
||||
) {
|
||||
this.createPropsCache()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
createPropsCache() {
|
||||
|
||||
// @{props} links lists
|
||||
|
|
@ -656,6 +677,10 @@ class Widget extends EventEmitter {
|
|||
|
||||
} else if (changedProps.length) {
|
||||
|
||||
if (options && options.fromEditor) {
|
||||
this.checkLinkedProps(propNames)
|
||||
}
|
||||
|
||||
for (var i in changedProps) {
|
||||
|
||||
this.onPropChanged(changedProps[i].propName, options, changedProps[i].oldPropValue)
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class Clone extends Container {
|
|||
|
||||
if (e.widget === this.cloneTarget || this.cloneTarget.contains(e.widget)) {
|
||||
|
||||
this.updateClone()
|
||||
this.updateClone(e.options)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ class Clone extends Container {
|
|||
|
||||
}
|
||||
|
||||
updateClone() {
|
||||
updateClone(options) {
|
||||
|
||||
if (this.cloneLock) return
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ class Clone extends Container {
|
|||
|
||||
} else {
|
||||
|
||||
widget.updateProps(changedProps, this)
|
||||
widget.updateProps(changedProps, this, options)
|
||||
this.updateContainer(true)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class Matrix extends _matrix_base {
|
|||
if (typeof data === 'object' && data !== null) {
|
||||
Object.assign(this.children[i].props, data)
|
||||
}
|
||||
this.children[i].updateProps(Object.keys(data), this)
|
||||
this.children[i].updateProps(Object.keys(data), this, options)
|
||||
// this.children[i] might have been recreated
|
||||
this.children[i].container.classList.add('not-editable')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue