fixes and some refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-05-26 21:56:49 +03:00
parent 822ffdc5fa
commit 4aec844167

View File

@ -1628,31 +1628,22 @@ var BaseBrowserPrototype = {
// Like .select(.., {iterateCollapsed: true}) but will expand all the // Like .select(.., {iterateCollapsed: true}) but will expand all the
// path items to reveal the target... // path items to reveal the target...
// // XXX should this return the matched item(s), expanded item(s) or this???
// XXX should this return the item or this???
// XXX make .reveal('all'/'*') only do the actual nodes that need expanding...
// ...currently for path 'a/b/c/d' we'll go through:
// 'a/b'
// 'a/b/c'
// 'a/b/c/d'
// XXX need a universal item name/value comparison / getter... // XXX need a universal item name/value comparison / getter...
reveal: function(key, options){ reveal: function(key, options){
var that = this var that = this
var seen = new Set() var seen = new Set()
var nodes = new Set()
return this.search(key, return this.search(key,
function(e, i, path){ function(e, i, path){
return [path, e] }, return [path, e] },
Object.assign( Object.assign(
{ { iterateCollapsed: true },
iterateCollapsed: true,
reverse: 'flat',
},
options || {})) options || {}))
// sort paths long to short... // NOTE: we expand individual items so the order here is not relevant...
//.sort(function(a, b){
// return b[0].length - a[0].length })
.map(function([path, e]){ .map(function([path, e]){
// skip paths we have already seen... // skip paths we have already seen...
// XXX do we actually need this???
if(seen.has(e.id)){ if(seen.has(e.id)){
return e return e
} }
@ -1670,19 +1661,20 @@ var BaseBrowserPrototype = {
// XXX need a universal item name test... // XXX need a universal item name test...
return n == (e.value || e.id) }) return n == (e.value || e.id) })
.pop() .pop()
delete e.collapsed nodes.add(e)
cur = e.children cur = e.children
// browser children...
} else { } else {
// XXX .index feels ugly... nodes.add(cur.index[n])
delete cur.index[n].collapsed
cur = cur.index[n].children cur = cur.index[n].children
} }
}) })
return e return e })
}) // do the actual expansion...
.run(function(){ .run(function(){
that.render() }) }, //return that.expand([...nodes]) }) },
that.expand([...nodes]) }) },
// XXX do we need edit ability here? // XXX do we need edit ability here?
@ -2537,6 +2529,7 @@ var BrowserPrototype = {
}, },
// NOTE: this is the similar to .renderItem(..) // NOTE: this is the similar to .renderItem(..)
// XXX make collapse action overloadable.... // XXX make collapse action overloadable....
// XXX use item.events...
renderNestedHeader: function(item, i, context){ renderNestedHeader: function(item, i, context){
var that = this var that = this
return this.renderItem(item, i, context) return this.renderItem(item, i, context)
@ -2550,10 +2543,9 @@ var BrowserPrototype = {
// collapse action handler... // collapse action handler...
// XXX make this overloadable... // XXX make this overloadable...
// XXX use item.events...
$(this).on('open', function(evt){ $(this).on('open', function(evt){
item.collapsed = !item.collapsed that.toggleCollapse(item) })
that.render(context)
})
}) }, }) },
// //
// Format: // Format: