editor: at last a fix that works to avoid data shifting on editor.undo
This commit is contained in:
parent
73d6cee438
commit
4575f4dcbd
2 changed files with 33 additions and 3 deletions
|
|
@ -36,6 +36,33 @@ class Container extends Widget {
|
|||
|
||||
}
|
||||
|
||||
alignChildrenProps() {
|
||||
|
||||
// this is needed after editor.undo to fix data shifting:
|
||||
// say we have children [a, b, c] bound with session data [a, b, c]
|
||||
// we delete one widget [ b, c] the data changes too: [ b, c]
|
||||
// undo first only mutates the data: [a, b, c]
|
||||
// so children have their data mutated too, child 'b' gets data 'a' and so on
|
||||
// each child has to get the data corresponding to its index again.
|
||||
// ...right ? :)
|
||||
var tabs = this.getProp('tabs'),
|
||||
widgets= this.getProp('widgets'),
|
||||
type = tabs && tabs.length ? 'tabs' : widgets && widgets.length ? 'widgets' : null
|
||||
|
||||
if (!type) return
|
||||
|
||||
for (let i in this.children) {
|
||||
if (this.children[i]) {
|
||||
this.children[i].props = this.getProp(type)[i]
|
||||
this.children[i].cachedProps[type] = this.children[i].props[type]
|
||||
if (this.children[i].alignChildrenProps) {
|
||||
this.children[i].alignChildrenProps()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onRemove() {
|
||||
|
||||
super.onRemove()
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ class Panel extends Container {
|
|||
this.wrapper.appendChild(this.children[i].container)
|
||||
this.children[i].parent = this
|
||||
this.children[i].parentNode = this.wrapper
|
||||
this.children[i].props = this.getProp('tabs')[i]
|
||||
} else {
|
||||
parser.parse({
|
||||
data: this.getProp('tabs')[i],
|
||||
|
|
@ -68,6 +67,8 @@ class Panel extends Container {
|
|||
}
|
||||
}
|
||||
|
||||
if (options.children) this.alignChildrenProps()
|
||||
|
||||
this.createNavigation()
|
||||
|
||||
this.navigation.addEventListener('fast-click', (e)=>{
|
||||
|
|
@ -85,13 +86,12 @@ class Panel extends Container {
|
|||
|
||||
} else if (this.getProp('widgets') && this.getProp('widgets').length) {
|
||||
|
||||
this.children = options.children || new Array(this.getProp('widgets').length)
|
||||
this.children = options.children || new Array(this.getProp('widgets').length)
|
||||
for (let i = 0; i < this.children.length; i++) {
|
||||
if (this.children[i]) {
|
||||
this.widget.appendChild(this.children[i].container)
|
||||
this.children[i].parent = this
|
||||
this.children[i].parentNode = this.widget
|
||||
this.children[i].props = this.getProp('widgets')[i]
|
||||
} else {
|
||||
parser.parse({
|
||||
data: this.getProp('widgets')[i],
|
||||
|
|
@ -102,6 +102,9 @@ class Panel extends Container {
|
|||
}
|
||||
}
|
||||
|
||||
if (options.children) this.alignChildrenProps()
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (this.getProp('tabs') && !this.getProp('tabs').length) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue