widget: reuse hash upon recreation
widget: fix js locals reuse tree: use hash instead of id to determine expanded containers
This commit is contained in:
parent
4b06accab8
commit
70462e4c24
4 changed files with 19 additions and 14 deletions
|
|
@ -100,6 +100,7 @@ function updateWidget(widget, options={}) {
|
|||
parentNode: widget.parentNode,
|
||||
reCreateOptions: options.reCreateOptions,
|
||||
locals: widget.parsersLocalScope,
|
||||
hash: widget.hash,
|
||||
children: children,
|
||||
index: index
|
||||
})
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ var Parser = class Parser {
|
|||
tab,
|
||||
reCreateOptions,
|
||||
children,
|
||||
index
|
||||
index,
|
||||
hash,
|
||||
locals
|
||||
} = options
|
||||
|
||||
var props = data
|
||||
|
|
@ -76,12 +78,13 @@ var Parser = class Parser {
|
|||
|
||||
// create widget
|
||||
var widget = new this.widgets[props.type]({
|
||||
container:true,
|
||||
props,
|
||||
parent,
|
||||
parentNode,
|
||||
reCreateOptions,
|
||||
children
|
||||
children,
|
||||
hash,
|
||||
locals,
|
||||
})
|
||||
|
||||
widgetManager.addWidget(widget)
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@ var UiWidget = require('./ui-widget'),
|
|||
doubleClick = require('../events/double-click'),
|
||||
Sortable = require('sortablejs'),
|
||||
morph = require('nanomorph'),
|
||||
Panel, Matrix, Keyboard, widgetManager
|
||||
Root, Panel, Matrix, Keyboard, widgetManager
|
||||
|
||||
class UiTree extends UiWidget {
|
||||
|
||||
constructor(options) {
|
||||
|
||||
Root = require('../widgets/containers/root')
|
||||
Panel = require('../widgets/containers/panel')
|
||||
Matrix = require('../widgets/containers/matrix')
|
||||
Keyboard = require('../widgets/containers/keyboard')
|
||||
|
|
@ -21,16 +22,17 @@ class UiTree extends UiWidget {
|
|||
this.dragDummy = html`<span></span>`
|
||||
|
||||
|
||||
this.expanded = {root: true}
|
||||
this.expanded = {}
|
||||
|
||||
this.container.addEventListener('fast-click', (event)=>{
|
||||
|
||||
var node = event.target
|
||||
if (node.classList.contains('toggle')) {
|
||||
var exp = node.parentNode.classList.toggle('expanded')
|
||||
if (exp) {
|
||||
this.expanded[node.parentNode.getAttribute('data-id')] = true
|
||||
this.expanded[node.parentNode.getAttribute('data-widget')] = true
|
||||
} else {
|
||||
delete this.expanded[node.parentNode.getAttribute('data-id')]
|
||||
delete this.expanded[node.parentNode.getAttribute('data-widget')]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,9 +45,9 @@ class UiTree extends UiWidget {
|
|||
if (node.classList.contains('container')) {
|
||||
var exp = node.classList.toggle('expanded')
|
||||
if (exp) {
|
||||
this.expanded[node.getAttribute('data-id')] = true
|
||||
this.expanded[node.getAttribute('data-widget')] = true
|
||||
} else {
|
||||
delete this.expanded[node.getAttribute('data-id')]
|
||||
delete this.expanded[node.getAttribute('data-widget')]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +130,7 @@ class UiTree extends UiWidget {
|
|||
while (parent !== this.list) {
|
||||
if (parent.classList.contains('container')) {
|
||||
parent.classList.add('expanded')
|
||||
this.expanded[parent.getAttribute('data-id')] = true
|
||||
this.expanded[parent.getAttribute('data-widget')] = true
|
||||
}
|
||||
parent = parent.parentNode
|
||||
}
|
||||
|
|
@ -162,14 +164,13 @@ class UiTree extends UiWidget {
|
|||
var selected = selectedWidgets.includes(widget),
|
||||
id = widget.getProp('id'),
|
||||
node = html`<li class="${selected ? 'editing' : ''} ${!widget.getProp('visible') ? 'invisible' : ''}"
|
||||
data-widget="${widget.hash}"
|
||||
data-id="${id}"">
|
||||
data-widget="${widget.hash}">
|
||||
${id}</li>`
|
||||
|
||||
if (widget instanceof Panel && !(widget instanceof Matrix || widget instanceof Keyboard)) {
|
||||
node.insertBefore(html`<span class="toggle no-widget-select"></span>`, node.childNodes[0])
|
||||
node.classList.add('container')
|
||||
if (this.expanded[id]) node.classList.add('expanded')
|
||||
if (this.expanded[widget.hash] || widget instanceof Root) node.classList.add('expanded')
|
||||
var sublist = node.appendChild(html`<ol style="--depth:${++depth};"></ol>`)
|
||||
for (let child of widget.children) {
|
||||
if (child) sublist.appendChild(this.parseWidgets(child, selectedWidgets, depth))
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ class Widget extends EventEmitter {
|
|||
this.errors = {}
|
||||
this.parent = options.root ? widgetManager : options.parent
|
||||
this.parentNode = options.parentNode
|
||||
this.hash = nanoid('abcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXYZ', 10)
|
||||
this.hash = options.hash || nanoid('abcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXYZ', 10)
|
||||
this.children = []
|
||||
this.reCreateOptions = options.reCreateOptions
|
||||
this.removed = false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue