Fixed formatting on menu_view.js

This commit is contained in:
Nathan Byrd 2022-01-23 10:46:09 -06:00
parent 2c2951866b
commit 0f4cecc97d
1 changed files with 194 additions and 194 deletions

View File

@ -23,7 +23,7 @@ function MenuView(options) {
const self = this; const self = this;
if (options.items) { if(options.items) {
this.setItems(options.items); this.setItems(options.items);
} else { } else {
this.items = []; this.items = [];
@ -52,9 +52,9 @@ function MenuView(options) {
}; };
this.getHotKeyItemIndex = function(ch) { this.getHotKeyItemIndex = function(ch) {
if (ch && self.hotKeys) { if(ch && self.hotKeys) {
const keyIndex = self.hotKeys[self.caseInsensitiveHotKeys ? ch.toLowerCase() : ch]; const keyIndex = self.hotKeys[self.caseInsensitiveHotKeys ? ch.toLowerCase() : ch];
if (_.isNumber(keyIndex)) { if(_.isNumber(keyIndex)) {
return keyIndex; return keyIndex;
} }
} }
@ -74,11 +74,11 @@ MenuView.prototype.setTextOverflow = function(overflow) {
} }
MenuView.prototype.hasTextOverflow = function() { MenuView.prototype.hasTextOverflow = function() {
return this.textOverflow !== undefined; return this.textOverflow != undefined;
} }
MenuView.prototype.setItems = function(items) { MenuView.prototype.setItems = function(items) {
if (Array.isArray(items)) { if(Array.isArray(items)) {
this.sorted = false; this.sorted = false;
this.renderCache = {}; this.renderCache = {};
@ -97,7 +97,7 @@ MenuView.prototype.setItems = function(items) {
let stringItem; let stringItem;
this.items = items.map(item => { this.items = items.map(item => {
stringItem = _.isString(item); stringItem = _.isString(item);
if (stringItem) { if(stringItem) {
text = item; text = item;
} else { } else {
text = item.text || ''; text = item.text || '';
@ -105,10 +105,10 @@ MenuView.prototype.setItems = function(items) {
} }
text = this.disablePipe ? text : pipeToAnsi(text, this.client); text = this.disablePipe ? text : pipeToAnsi(text, this.client);
return Object.assign({}, { text }, stringItem ? {} : item); // ensure we have a text member, plus any others return Object.assign({ }, { text }, stringItem ? {} : item); // ensure we have a text member, plus any others
}); });
if (this.complexItems) { if(this.complexItems) {
this.itemFormat = this.itemFormat || '{text}'; this.itemFormat = this.itemFormat || '{text}';
} }
@ -135,25 +135,25 @@ MenuView.prototype.invalidateRenderCache = function() {
}; };
MenuView.prototype.setSort = function(sort) { MenuView.prototype.setSort = function(sort) {
if (this.sorted || !Array.isArray(this.items) || 0 === this.items.length) { if(this.sorted || !Array.isArray(this.items) || 0 === this.items.length) {
return; return;
} }
const key = true === sort ? 'text' : sort; const key = true === sort ? 'text' : sort;
if ('text' !== sort && !this.complexItems) { if('text' !== sort && !this.complexItems) {
return; // need a valid sort key return; // need a valid sort key
} }
this.items.sort((a, b) => { this.items.sort( (a, b) => {
const a1 = a[key]; const a1 = a[key];
const b1 = b[key]; const b1 = b[key];
if (!a1) { if(!a1) {
return -1; return -1;
} }
if (!b1) { if(!b1) {
return 1; return 1;
} }
return a1.localeCompare(b1, { sensitivity: false, numeric: true }); return a1.localeCompare( b1, { sensitivity : false, numeric : true } );
}); });
this.sorted = true; this.sorted = true;
@ -163,11 +163,11 @@ MenuView.prototype.removeItem = function(index) {
this.sorted = false; this.sorted = false;
this.items.splice(index, 1); this.items.splice(index, 1);
if (this.focusItems) { if(this.focusItems) {
this.focusItems.splice(index, 1); this.focusItems.splice(index, 1);
} }
if (this.focusedItemIndex >= index) { if(this.focusedItemIndex >= index) {
this.focusedItemIndex = Math.max(this.focusedItemIndex - 1, 0); this.focusedItemIndex = Math.max(this.focusedItemIndex - 1, 0);
} }
@ -181,17 +181,17 @@ MenuView.prototype.getCount = function() {
}; };
MenuView.prototype.getItems = function() { MenuView.prototype.getItems = function() {
if (this.complexItems) { if(this.complexItems) {
return this.items; return this.items;
} }
return this.items.map(item => { return this.items.map( item => {
return item.text; return item.text;
}); });
}; };
MenuView.prototype.getItem = function(index) { MenuView.prototype.getItem = function(index) {
if (this.complexItems) { if(this.complexItems) {
return this.items[index]; return this.items[index];
} }
@ -228,10 +228,10 @@ MenuView.prototype.setFocusItemIndex = function(index) {
MenuView.prototype.onKeyPress = function(ch, key) { MenuView.prototype.onKeyPress = function(ch, key) {
const itemIndex = this.getHotKeyItemIndex(ch); const itemIndex = this.getHotKeyItemIndex(ch);
if (itemIndex >= 0) { if(itemIndex >= 0) {
this.setFocusItemIndex(itemIndex); this.setFocusItemIndex(itemIndex);
if (true === this.hotKeySubmit) { if(true === this.hotKeySubmit) {
this.emit('action', 'accept'); this.emit('action', 'accept');
} }
} }
@ -242,12 +242,12 @@ MenuView.prototype.onKeyPress = function(ch, key) {
MenuView.prototype.setFocusItems = function(items) { MenuView.prototype.setFocusItems = function(items) {
const self = this; const self = this;
if (items) { if(items) {
this.focusItems = []; this.focusItems = [];
items.forEach(itemText => { items.forEach( itemText => {
this.focusItems.push( this.focusItems.push(
{ {
text: self.disablePipe ? itemText : pipeToAnsi(itemText, self.client) text : self.disablePipe ? itemText : pipeToAnsi(itemText, self.client)
} }
); );
}); });
@ -271,26 +271,26 @@ MenuView.prototype.setItemHorizSpacing = function(itemHorizSpacing) {
}; };
MenuView.prototype.setPropertyValue = function(propName, value) { MenuView.prototype.setPropertyValue = function(propName, value) {
switch (propName) { switch(propName) {
case 'itemSpacing': this.setItemSpacing(value); break; case 'itemSpacing' : this.setItemSpacing(value); break;
case 'itemHorizSpacing': this.setItemHorizSpacing(value); break; case 'itemHorizSpacing' : this.setItemHorizSpacing(value); break;
case 'items': this.setItems(value); break; case 'items' : this.setItems(value); break;
case 'focusItems': this.setFocusItems(value); break; case 'focusItems' : this.setFocusItems(value); break;
case 'hotKeys': this.setHotKeys(value); break; case 'hotKeys' : this.setHotKeys(value); break;
case 'textOverflow': this.setTextOverflow(value); break; case 'textOverflow' : this.setTextOverflow(value); break;
case 'hotKeySubmit': this.hotKeySubmit = value; break; case 'hotKeySubmit' : this.hotKeySubmit = value; break;
case 'justify': this.setJustify(value); break; case 'justify' : this.setJustify(value); break;
case 'fillChar': this.setFillChar(value); break; case 'fillChar' : this.setFillChar(value); break;
case 'focusItemIndex': this.focusedItemIndex = value; break; case 'focusItemIndex' : this.focusedItemIndex = value; break;
case 'itemFormat': case 'itemFormat' :
case 'focusItemFormat': case 'focusItemFormat' :
this[propName] = value; this[propName] = value;
// if there is a cache currently, invalidate it // if there is a cache currently, invalidate it
this.invalidateRenderCache(); this.invalidateRenderCache();
break; break;
case 'sort': this.setSort(value); break; case 'sort' : this.setSort(value); break;
} }
MenuView.super_.prototype.setPropertyValue.call(this, propName, value); MenuView.super_.prototype.setPropertyValue.call(this, propName, value);
@ -305,13 +305,13 @@ MenuView.prototype.setJustify = function(justify) {
this.justify = justify; this.justify = justify;
this.invalidateRenderCache(); this.invalidateRenderCache();
this.positionCacheExpired = true; this.positionCacheExpired = true;
}; }
MenuView.prototype.setHotKeys = function(hotKeys) { MenuView.prototype.setHotKeys = function(hotKeys) {
if (_.isObject(hotKeys)) { if(_.isObject(hotKeys)) {
if (this.caseInsensitiveHotKeys) { if(this.caseInsensitiveHotKeys) {
this.hotKeys = {}; this.hotKeys = {};
for (var key in hotKeys) { for(var key in hotKeys) {
this.hotKeys[key.toLowerCase()] = hotKeys[key]; this.hotKeys[key.toLowerCase()] = hotKeys[key];
} }
} else { } else {