mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
tweaks fixes and cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9740958eed
commit
db078e072a
@ -893,6 +893,7 @@ var BaseBrowserPrototype = {
|
|||||||
var iterateNonIterable = options.iterateAll || options.iterateNonIterable
|
var iterateNonIterable = options.iterateAll || options.iterateNonIterable
|
||||||
var iterateCollapsed = options.iterateAll || options.iterateCollapsed
|
var iterateCollapsed = options.iterateAll || options.iterateCollapsed
|
||||||
var skipNested = !options.iterateAll && options.skipNested
|
var skipNested = !options.iterateAll && options.skipNested
|
||||||
|
var skipInlined = !options.iterateAll && options.skipInlined
|
||||||
var reverse = options.reverse === true ?
|
var reverse = options.reverse === true ?
|
||||||
(options.defaultReverse || 'tree')
|
(options.defaultReverse || 'tree')
|
||||||
: options.reverse
|
: options.reverse
|
||||||
@ -994,6 +995,10 @@ var BaseBrowserPrototype = {
|
|||||||
// leaf...
|
// leaf...
|
||||||
: [false, path.concat([id]), undefined]
|
: [false, path.concat([id]), undefined]
|
||||||
|
|
||||||
|
if(inline && skipInlined){
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
|
||||||
// reverse -> do children...
|
// reverse -> do children...
|
||||||
reverse == 'flat'
|
reverse == 'flat'
|
||||||
&& children
|
&& children
|
||||||
@ -1044,8 +1049,6 @@ var BaseBrowserPrototype = {
|
|||||||
//
|
//
|
||||||
// XXX rename this??
|
// XXX rename this??
|
||||||
text: function(options, context){
|
text: function(options, context){
|
||||||
var that = this
|
|
||||||
|
|
||||||
return this
|
return this
|
||||||
.walk2(
|
.walk2(
|
||||||
function(node, i, path){
|
function(node, i, path){
|
||||||
@ -1202,6 +1205,15 @@ var BaseBrowserPrototype = {
|
|||||||
// 'focused' - get focused items (shorthand to {focused: true})
|
// 'focused' - get focused items (shorthand to {focused: true})
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
// options format:
|
||||||
|
// {
|
||||||
|
// noIdentityCheck: <bool>,
|
||||||
|
//
|
||||||
|
// noQueryCheck: <bool>,
|
||||||
|
//
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// __search_test_generators__ format:
|
// __search_test_generators__ format:
|
||||||
@ -1323,20 +1335,26 @@ var BaseBrowserPrototype = {
|
|||||||
: pattern instanceof Function ?
|
: pattern instanceof Function ?
|
||||||
pattern
|
pattern
|
||||||
// other -> get a compatible test function...
|
// other -> get a compatible test function...
|
||||||
: Object.values(this.__search_test_generators__)
|
: Object.entries(this.__search_test_generators__)
|
||||||
.reduce(function(res, get){
|
.filter(function([key, get]){
|
||||||
|
return !(options.noQueryCheck
|
||||||
|
&& key == 'query') })
|
||||||
|
.reduce(function(res, [_, get]){
|
||||||
return res
|
return res
|
||||||
|| get.call(this.__search_test_generators__, pattern) }, false) )
|
|| get.call(this.__search_test_generators__, pattern) }, false) )
|
||||||
// sanity check...
|
|
||||||
if(!test){
|
|
||||||
throw new Error(`.search(..): unknown pattern type: ${pattern}`) }
|
|
||||||
|
|
||||||
return this.walk2(
|
return this.walk2(
|
||||||
function(elem, i, path, _, stop){
|
function(elem, i, path, _, stop){
|
||||||
// match...
|
// match...
|
||||||
var res = (elem
|
var res = (elem
|
||||||
&& (test === true
|
&& (test === true
|
||||||
|| test.call(this, elem, i, path))) ?
|
// identity check...
|
||||||
|
|| (!options.noIdentityCheck
|
||||||
|
&& pattern === elem)
|
||||||
|
// test...
|
||||||
|
|| (test
|
||||||
|
&& test.call(this, elem, i, path)))) ?
|
||||||
|
// handle the passed items...
|
||||||
[ func ?
|
[ func ?
|
||||||
func.call(this, elem, i, path, stop)
|
func.call(this, elem, i, path, stop)
|
||||||
: elem ]
|
: elem ]
|
||||||
@ -1379,7 +1397,6 @@ var BaseBrowserPrototype = {
|
|||||||
// first result only.
|
// first result only.
|
||||||
//
|
//
|
||||||
// XXX should we be able to get offset values relative to any match?
|
// XXX should we be able to get offset values relative to any match?
|
||||||
// XXX add a callback...
|
|
||||||
// XXX should we use .wald2(..) here???
|
// XXX should we use .wald2(..) here???
|
||||||
// XXX revise return value...
|
// XXX revise return value...
|
||||||
get: function(pattern, options){
|
get: function(pattern, options){
|
||||||
@ -1445,7 +1462,7 @@ var BaseBrowserPrototype = {
|
|||||||
// XXX BROKEN...
|
// XXX BROKEN...
|
||||||
// Sublist map functions...
|
// Sublist map functions...
|
||||||
//
|
//
|
||||||
// XXX NOTE: these will return a sparse array... ???
|
// XXX should these return a sparse array... ???
|
||||||
sublists: function(func, options){
|
sublists: function(func, options){
|
||||||
return this.search({children: true}, func, options) },
|
return this.search({children: true}, func, options) },
|
||||||
// XXX broken, needs support for options.skipInlined ...
|
// XXX broken, needs support for options.skipInlined ...
|
||||||
@ -1463,60 +1480,30 @@ var BaseBrowserPrototype = {
|
|||||||
forEach: function(func, options){
|
forEach: function(func, options){
|
||||||
this.map(...arguments)
|
this.map(...arguments)
|
||||||
return this },
|
return this },
|
||||||
// XXX should we use a recursive .walk(..), .map(..) .filter(..) or
|
filter: function(func, options, context){
|
||||||
// try and make do with what is available in a child???
|
return this.walk2(
|
||||||
filter: function(func, options){
|
function(e, i, p){
|
||||||
return this.walk(function(i, p, e, b){
|
return e && func.call(this, e, i, p) ? [e] : [] },
|
||||||
return e && func.call(this, e, i, p, b) ? [e] : [] }) },
|
'filter',
|
||||||
//return this.map(function(e, i, p, b){
|
function(_, i, p, options, context){
|
||||||
// return func.call(this, e, i, p, b) ? [e] : [] })
|
return [func, options, context] },
|
||||||
//.flat() },
|
options, context) },
|
||||||
reduce: function(){},
|
reduce: function(){},
|
||||||
|
|
||||||
// XXX move these to a more logical spot...
|
positionOf: function(item, options){
|
||||||
// XXX these are almost identical -- reuse???
|
return this.search(item,
|
||||||
|
function(_, i, p){
|
||||||
|
return [i, p] },
|
||||||
|
Object.assign(
|
||||||
|
{
|
||||||
|
firstMatch: true,
|
||||||
|
noQueryCheck: true,
|
||||||
|
},
|
||||||
|
options || {})).concat([[-1, undefined]]).shift() },
|
||||||
indexOf: function(item, options){
|
indexOf: function(item, options){
|
||||||
item = typeof(item) == typeof('str') ?
|
return this.positionOf(item, options)[0] },
|
||||||
item.split(/[\\\/]/g)
|
|
||||||
: item
|
|
||||||
|
|
||||||
var Stop = new Error('.indexOf(..): Result found exception.')
|
|
||||||
|
|
||||||
var i = 0
|
|
||||||
try{
|
|
||||||
this.map(function(e, p){
|
|
||||||
if(item instanceof Array ? item.cmp(p) : (item === e)){
|
|
||||||
throw Stop }
|
|
||||||
i++
|
|
||||||
}, options)
|
|
||||||
|
|
||||||
} catch(e){
|
|
||||||
if(e === Stop){
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
},
|
|
||||||
pathOf: function(item, options){
|
pathOf: function(item, options){
|
||||||
var Stop = new Error('.pathOf(..): Result found exception.')
|
return this.positionOf(item, options)[1] },
|
||||||
|
|
||||||
var path
|
|
||||||
var i = 0
|
|
||||||
try{
|
|
||||||
this.map(function(e, p){
|
|
||||||
path = p
|
|
||||||
if(typeof(item) == typeof(123) ? item == i : (item === e)){
|
|
||||||
throw Stop }
|
|
||||||
i++
|
|
||||||
}, options)
|
|
||||||
|
|
||||||
} catch(e){
|
|
||||||
if(e === Stop){
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined
|
|
||||||
},
|
|
||||||
|
|
||||||
// Like .get(.., {iterateCollapsed: true}) but will expand all the
|
// Like .get(.., {iterateCollapsed: true}) but will expand all the
|
||||||
// path items to reveal the target...
|
// path items to reveal the target...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user