cleanup and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-07-10 18:58:22 +03:00
parent 8efdcbd3eb
commit 0f23ba8a15
7 changed files with 514 additions and 723 deletions

View File

@ -1617,8 +1617,7 @@ module.CropActions = actions.Actions({
.shift() .shift()
crop.focusImage( crop.focusImage(
crop.getImage(this.current, 'after', r) crop.getImage(this.current, 'after', r)
|| crop.getImage(this.current, 'before', r)) || crop.getImage(this.current, 'before', r)) }
}
this.crop(crop, flatten) this.crop(crop, flatten)
}], }],
@ -1723,10 +1722,8 @@ module.CropActions = actions.Actions({
// add gids to current ribbon... // add gids to current ribbon...
gids.forEach(function(gid){ gids.forEach(function(gid){
var i = o.indexOf(gid) var i = o.indexOf(gid)
if(i >= 0){ i >= 0
r[i] = gid && (r[i] = gid) })
}
})
// place... // place...
;(ribbon || reference || mode) ;(ribbon || reference || mode)

View File

@ -287,30 +287,31 @@ var FileSystemLoaderActions = actions.Actions({
//console.log('FOUND INDEXES:', Object.keys(res).length) //console.log('FOUND INDEXES:', Object.keys(res).length)
// skip nested paths... // skip nested paths...
//
// XXX make this optional... // XXX make this optional...
// XXX this is best done BEFORE we load all the // XXX this is best done BEFORE we load all the
// indexes, e.g. in .loadIndex(..) // indexes, e.g. in .loadIndex(..)
var skipped = new Set()
var paths = Object.keys(res) var paths = Object.keys(res)
var skipped = []
paths paths
.sort() .sort()
.forEach(function(p){ .forEach(function(p){
// already removed... // already removed...
if(skipped.indexOf(p) >= 0){ if(skipped.has(p) >= 0){
return return }
}
paths paths
// get all paths that fully contain p... // get all paths that fully contain p...
.filter(function(o){ .filter(function(o){
return o != p && o.indexOf(p) == 0 return o != p
}) && o.indexOf(p) == 0 })
// drop all longer paths... // drop all nested (longer) paths...
.forEach(function(e){ .forEach(function(e){
skipped.push(e) skipped.add(e)
delete res[e] delete res[e] }) })
}) // keep only the valid paths...
}) paths = Object.keys(res)
//console.log('SKIPPING NESTED:', skipped.length) //console.log('SKIPPING NESTED:', skipped.length)
var index var index
@ -325,15 +326,13 @@ var FileSystemLoaderActions = actions.Actions({
// skip empty indexes... // skip empty indexes...
// XXX should we rebuild or list here??? // XXX should we rebuild or list here???
if(res[k].data == null && res[k].images == null){ if(res[k].data == null && res[k].images == null){
continue continue }
}
// build the data from images... // build the data from images...
if(res[k].data == null){ if(res[k].data == null){
res[k].data = { res[k].data = {
order: Object.keys(res[k].images), order: Object.keys(res[k].images),
} } }
}
// prepare to do a full save if format version updated... // prepare to do a full save if format version updated...
if(res[k].data.version != that.data.version){ if(res[k].data.version != that.data.version){
@ -342,8 +341,7 @@ var FileSystemLoaderActions = actions.Actions({
logger && logger.emit('Data version changed:', logger && logger.emit('Data version changed:',
v, '->', that.data.version) v, '->', that.data.version)
force_full_save = true force_full_save = true }
}
var part = that.prepareIndexForLoad(res[k], k) var part = that.prepareIndexForLoad(res[k], k)
@ -391,9 +389,8 @@ var FileSystemLoaderActions = actions.Actions({
loaded: loaded, loaded: loaded,
load: 'loadIndex', load: 'loadIndex',
}) })
if(from_date){ from_date
index.location.from = from_date && (index.location.from = from_date)
}
// this is the critical section, after this point we // this is the critical section, after this point we
// are doing the actual loading.... // are doing the actual loading....
@ -402,8 +399,7 @@ var FileSystemLoaderActions = actions.Actions({
force_full_save force_full_save
// XXX remove as soon as merged index save is done... // XXX remove as soon as merged index save is done...
&& loaded.length == 1 && loaded.length == 1
&& that.markChanged('all') && that.markChanged('all') })
})
}) })
}], }],

File diff suppressed because it is too large Load Diff

View File

@ -181,10 +181,14 @@ module.calcRelativeRotation = function(from, to){
to = from to = from
from = 0 from = 0
} }
to = to == 'cw' ? 1 to = to == 'cw' ?
: to == 'ccw' ? -1 1
: [0, 90, 180, 270].indexOf(to*1) >= 0 ? to*1 : to == 'ccw' ?
: [-90, -180, -270].indexOf(to*1) >= 0 ? 360+(to*1) -1
: [0, 90, 180, 270].includes(to*1) ?
to*1
: [-90, -180, -270].includes(to*1) ?
360+(to*1)
: null : null
// relative rotation... // relative rotation...
@ -201,8 +205,7 @@ module.calcRelativeRotation = function(from, to){
var res = to var res = to
} }
return res return res }
}
@ -449,8 +452,7 @@ module.ImagesPrototype = {
var i = keys.indexOf('version') var i = keys.indexOf('version')
i >= 0 i >= 0
&& keys.splice(i, 1) && keys.splice(i, 1)
return keys return keys },
},
// Build an image index relative to an attribute... // Build an image index relative to an attribute...
// //
@ -752,16 +754,15 @@ module.ImagesPrototype = {
// //
// NOTE: updating from legacy format... // NOTE: updating from legacy format...
// XXX move this to version conversion... (???) // XXX move this to version conversion... (???)
if(version == null){ version == null
Object.keys(img && img.preview || {}) && Object.keys(img && img.preview || {})
.forEach(function(res){ .forEach(function(res){
var p = img.preview[res] var p = img.preview[res]
img.preview[res] = p.indexOf(k+'%20-%20') >= 0 ? decodeURI(p) : p img.preview[res] =
}) p.includes(k+'%20-%20') ?
} decodeURI(p)
} : p }) }
return this return this },
},
// XXX this is really odd: renaming this to 'toJSON' breaks JavaScript // XXX this is really odd: renaming this to 'toJSON' breaks JavaScript
// making chrome/node just say: "<error>" and a filename... // making chrome/node just say: "<error>" and a filename...
json: function(data){ json: function(data){

View File

@ -2309,7 +2309,7 @@ var RibbonsPrototype = {
// NOTE: this will reuse existing marks... // NOTE: this will reuse existing marks...
toggleImageMark: function(image, cls, action){ toggleImageMark: function(image, cls, action){
var that = this var that = this
if(cls == null || ['toggle', 'on', 'off', '?'].indexOf(cls) >= 0 ){ if(cls == null || ['toggle', 'on', 'off', '?'].includes(cls)){
action = cls action = cls
cls = image cls = image
image = null image = null
@ -2443,7 +2443,7 @@ var RibbonsPrototype = {
// update existing state... // update existing state...
if(set_state == null){ if(set_state == null){
var d = direction var d = direction
if(reference == 'view' && [90, 270].indexOf(that.getImageRotation(img)) > -1){ if(reference == 'view' && [90, 270].includes(that.getImageRotation(img))){
d = direction == 'vertical' ? 'horizontal' : 'vertical' d = direction == 'vertical' ? 'horizontal' : 'vertical'
} }
var state = img.attr('flipped') var state = img.attr('flipped')

View File

@ -715,8 +715,8 @@ var BaseTagsPrototype = {
res = res.unite(tags) res = res.unite(tags)
return res.size != size ? return res.size != size ?
expand(tags, res) expand(tags, res)
: [...res] : [...res] }
}
// Set matching... // Set matching...
// a matches b iff each element of a exists in b. // a matches b iff each element of a exists in b.
// //
@ -724,14 +724,14 @@ var BaseTagsPrototype = {
// NOTE: this matches single tags too... // NOTE: this matches single tags too...
var matchSet = function(a, b){ var matchSet = function(a, b){
a = that.splitSet(a) a = that.splitSet(a)
b = (no_definitions || !definitions) ? b = new Set((no_definitions || !definitions) ?
that.splitSet(b) that.splitSet(b)
: expand(that.splitSet(b)) : expand(that.splitSet(b)))
return a.length <= b.length return a.length <= b.length
// keep only the non-matches -> if at least one exists we fail... // keep only the non-matches -> if at least one exists we fail...
&& a.filter(function(e){ && a.filter(function(e){
return e != '*' return e != '*'
&& b.indexOf(e) < 0 && b.has(e) < 0
&& !(cmp && !(cmp
&& b.filter(cmp.bind(null, e)).length > 0) }) && b.filter(cmp.bind(null, e)).length > 0) })
.length == 0 } .length == 0 }

View File

@ -94,12 +94,10 @@ Array.prototype.toKeys = function(normalize){
return normalize ? return normalize ?
this.reduce(function(r, e, i){ this.reduce(function(r, e, i){
r[normalize(e)] = i r[normalize(e)] = i
return r return r }, {})
}, {})
: this.reduce(function(r, e, i){ : this.reduce(function(r, e, i){
r[e] = i r[e] = i
return r return r }, {}) }
}, {}) }
// Convert an array to a map... // Convert an array to a map...
@ -120,13 +118,11 @@ Array.prototype.toMap = function(normalize){
this this
.reduce(function(m, e, i){ .reduce(function(m, e, i){
m.set(normalize(e), i) m.set(normalize(e), i)
return m return m }, new Map())
}, new Map())
: this : this
.reduce(function(m, e, i){ .reduce(function(m, e, i){
m.set(e, i) m.set(e, i)
return m return m }, new Map()) }
}, new Map()) }
// Return an array with duplicate elements removed... // Return an array with duplicate elements removed...
@ -149,18 +145,13 @@ Array.prototype.tailUnique = function(normalize){
// //
Array.prototype.cmp = function(other){ Array.prototype.cmp = function(other){
if(this === other){ if(this === other){
return true return true }
}
if(this.length != other.length){ if(this.length != other.length){
return false return false }
}
for(var i=0; i<this.length; i++){ for(var i=0; i<this.length; i++){
if(this[i] != other[i]){ if(this[i] != other[i]){
return false return false } }
} return true }
}
return true
}
// Compare two Arrays as sets... // Compare two Arrays as sets...
@ -185,9 +176,7 @@ Array.prototype.sortAs = function(other){
return i < 0 && j < 0 ? 0 return i < 0 && j < 0 ? 0
: i < 0 ? 1 : i < 0 ? 1
: j < 0 ? -1 : j < 0 ? -1
: i - j : i - j }) }
})
}
@ -315,8 +304,7 @@ var quoteRegExp =
RegExp.quoteRegExp = RegExp.quoteRegExp =
module.quoteRegExp = module.quoteRegExp =
function(str){ function(str){
return str.replace(/([\.\\\/\(\)\[\]\$\*\+\-\{\}\@\^\&\?\<\>])/g, '\\$1') return str.replace(/([\.\\\/\(\)\[\]\$\*\+\-\{\}\@\^\&\?\<\>])/g, '\\$1') }
}