fix all ESlint errors

This commit is contained in:
Robin Scholtes 2023-08-14 14:30:25 +12:00
parent daac91d970
commit eb53667919
8 changed files with 100 additions and 78 deletions

View file

@ -2,15 +2,16 @@ import {COperationList} from "./c-operation-list.mjs";
/** /**
* c(ustom element)-category-li ( list item ) * c(ustom element)-category-li ( list item )
* */
export class CCategoryLi extends HTMLElement {
/**
* @param {App} app - The main view object for CyberChef * @param {App} app - The main view object for CyberChef
* @param {CatConf} category - The category and operations to be populated. * @param {CatConf} category - The category and operations to be populated.
* @param {Object.<string, OpConf>} operations - The list of operation configuration objects. * @param {Object.<string, OpConf>} operations - The list of operation configuration objects.
* @param {Boolean} isExpanded - expand the category by default on init or not * @param {Boolean} isExpanded - expand the category by default on init or not
* @param {Boolean} includeOpLiStarIcon - Include the left side 'star' icon to each of the c-category-li > * @param {Boolean} includeOpLiStarIcon - Include the left side 'star' icon to each of the c-category-li >
* c-operation-list > c-operation-li list items in this category * c-operation-list > c-operation-li list items in this category
* */ */
export class CCategoryLi extends HTMLElement {
constructor( constructor(
app, app,
category, category,
@ -69,7 +70,7 @@ export class CCategoryLi extends HTMLElement {
this.includeOpLiStarIcon, this.includeOpLiStarIcon,
false, false,
true true
) );
opList.build(); opList.build();
@ -85,7 +86,7 @@ export class CCategoryLi extends HTMLElement {
li.classList.add("category"); li.classList.add("category");
return li; return li;
}; }
/** /**
* Build the anchor element * Build the anchor element
@ -118,7 +119,7 @@ export class CCategoryLi extends HTMLElement {
} }
return a; return a;
}; }
/** /**
* Build the collapsable panel that contains the op-list for this category * Build the collapsable panel that contains the op-list for this category
@ -137,7 +138,7 @@ export class CCategoryLi extends HTMLElement {
} }
return div; return div;
}; }
/** /**
* If this category is Favourites, build and return the star icon button * If this category is Favourites, build and return the star icon button

View file

@ -2,15 +2,21 @@ import {CCategoryLi} from "./c-category-li.mjs";
/** /**
* c(ustom element)-category-list * c(ustom element)-category-list
* */
export class CCategoryList extends HTMLElement {
/**
* @param {App} app - The main view object for CyberChef * @param {App} app - The main view object for CyberChef
* @param {CatConf[]} categories - The list of categories and operations to be populated. * @param {CatConf[]} categories - The list of categories and operations to be populated.
* @param {Object.<string, OpConf>} operations - A list of operation configuration objects. * @param {Object.<string, OpConf>} operations - A list of operation configuration objects.
* @param {Boolean} includeOpLiStarIcon - Include the left side 'star' icon to each of the c-category-li > * @param {Boolean} includeOpLiStarIcon - Include the left side 'star' icon to each of the c-category-li >
* c-operation-list > c-operation-li list items in this c-category-list * c-operation-list > c-operation-li list items in this c-category-list
**/ */
export class CCategoryList extends HTMLElement { constructor(
constructor(app, categories, operations, includeOpLiStarIcon) { app,
categories,
operations,
includeOpLiStarIcon
) {
super(); super();
this.app = app; this.app = app;

View file

@ -6,13 +6,18 @@ import HTMLIngredient from "../HTMLIngredient.mjs";
* Note: This is the #recipe-list list item component, not to be confused with HTMLIngredient which make up the smaller * Note: This is the #recipe-list list item component, not to be confused with HTMLIngredient which make up the smaller
* components of this list item. It would be good to eventually fuse that code into this component or alternatively, to * components of this list item. It would be good to eventually fuse that code into this component or alternatively, to
* turn that into a separate native web component . * turn that into a separate native web component .
* */
export class CIngredientLi extends HTMLElement {
/**
* @param {App} app - The main view object for CyberChef * @param {App} app - The main view object for CyberChef
* @param {string} name - The operation ( or aka ingredient- in this context ) name * @param {string} name - The operation ( or aka ingredient- in this context ) name
* @param {object[]} args - The args properties of the operation ( see operation config file ) * @param {object[]} args - The args properties of the operation ( see operation config file )
* */ */
export class CIngredientLi extends HTMLElement { constructor(
constructor(app, name, args = []) { app,
name,
args = []
) {
super(); super();
this.app = app; this.app = app;
@ -38,7 +43,6 @@ export class CIngredientLi extends HTMLElement {
/** /**
* Handle double click * Handle double click
*
* @param {Event} e * @param {Event} e
*/ */
handleDoubleClick(e) { handleDoubleClick(e) {
@ -64,7 +68,7 @@ export class CIngredientLi extends HTMLElement {
ingredientDiv.classList.add("ingredients"); ingredientDiv.classList.add("ingredients");
li.appendChild(titleDiv); li.appendChild(titleDiv);
li.appendChild(ingredientDiv) li.appendChild(ingredientDiv);
for (let i = 0; i < this.args.length; i++) { for (let i = 0; i < this.args.length; i++) {
ingredientDiv.innerHTML += (this.args[i].toHtml()); ingredientDiv.innerHTML += (this.args[i].toHtml());

View file

@ -2,7 +2,9 @@ import url from "url";
/** /**
* c(ustom element)-operation-li ( list item ) * c(ustom element)-operation-li ( list item )
* */
export class COperationLi extends HTMLElement {
/**
* @param {App} app - The main view object for CyberChef * @param {App} app - The main view object for CyberChef
* @param {string} name - The name of the operation * @param {string} name - The name of the operation
* @param {Object} icon - { class: string, innerText: string } - The optional and customizable icon displayed on the * @param {Object} icon - { class: string, innerText: string } - The optional and customizable icon displayed on the
@ -11,7 +13,6 @@ import url from "url";
* @param {[number[]]} charIndicesToHighlight - optional array of indices that indicate characters to highlight (bold) * @param {[number[]]} charIndicesToHighlight - optional array of indices that indicate characters to highlight (bold)
* in the operation name, for instance when the user searches for an operation by typing * in the operation name, for instance when the user searches for an operation by typing
*/ */
export class COperationLi extends HTMLElement {
constructor( constructor(
app, app,
name, name,
@ -134,12 +135,12 @@ export class COperationLi extends HTMLElement {
$(".popover").on("mouseleave", function () { $(".popover").on("mouseleave", function () {
$(_this).popover("hide"); $(_this).popover("hide");
}); });
}).on("mouseleave", function () { })
.on("mouseleave", function () {
const _this = this; const _this = this;
setTimeout(function() { setTimeout(function() {
// Determine if the popover associated with this element is being hovered over // Determine if the popover associated with this element is being hovered over
if ($(_this).data("bs.popover") && if ($(_this).data("bs.popover") && ($(_this).data("bs.popover").tip && !$($(_this).data("bs.popover").tip).is(":hover"))) {
($(_this).data("bs.popover").tip && !$($(_this).data("bs.popover").tip).is(":hover"))) {
$(_this).popover("hide"); $(_this).popover("hide");
} }
}, 50); }, 50);
@ -270,7 +271,7 @@ export class COperationLi extends HTMLElement {
* or simply sets the name in the span element * or simply sets the name in the span element
*/ */
buildOperationName() { buildOperationName() {
const span = document.createElement('span'); const span = document.createElement("span");
if (this.charIndicesToHighlight.length) { if (this.charIndicesToHighlight.length) {
let opName = "", let opName = "",

View file

@ -3,15 +3,17 @@ import Sortable from "sortablejs";
/** /**
* c(ustom element)-operation-list * c(ustom element)-operation-list
*
* @param {App} app - The main view object for CyberChef
* @param {[string, number[]]} operations - A list of operation names and indexes of characters to highlight
* @param {Boolean} includeOpLiStarIcon - Include the left side 'star' icon to each of the c-category-li >
* c-operation-list > c-operation-li list items in this c-category-list
*
* @param {Object} icon ( { class: string, innerText: string } ). check-icon by default
*/ */
export class COperationList extends HTMLElement { export class COperationList extends HTMLElement {
/**
* @param {App} app - The main view object for CyberChef
* @param {[string, number[]]} operations - A list of operation names and indexes of characters to highlight
* @param {Boolean} includeStarIcon - Include the left side 'star' icon to each of the c-category-li >
* c-operation-list > c-operation-li list items in this c-category-list
* @param {Boolean} isSortable - List items may be sorted ( reordered ). False by default
* @param {Boolean} isCloneable - List items are cloneable to a target list. True by default
* @param {Object} icon ( { class: string, innerText: string } ). 'check-icon' by default
*/
constructor( constructor(
app, app,
operations, operations,
@ -50,19 +52,19 @@ export class COperationList extends HTMLElement {
); );
ul.appendChild(cOpLi); ul.appendChild(cOpLi);
})) }));
if (this.isSortable) { if (this.isSortable) {
this.createSortableList(ul); this.createSortableList(ul);
} else if (!this.app.isMobileView() && this.isCloneable) { } else if (!this.app.isMobileView() && this.isCloneable) {
this.createCloneableList(ul, "recipe", "rec-list"); // target name and id can be component params if needed to make it reusable this.createCloneableList(ul, "recipe", "rec-list");
} }
this.append(ul); this.append(ul);
} }
/** /**
* Create a sortable ( not cloneable ) list * Create a sortable ( but not cloneable ) list
* *
* @param { HTMLElement } ul * @param { HTMLElement } ul
* */ * */

View file

@ -6,7 +6,6 @@
import {fuzzyMatch, calcMatchRanges} from "../../core/lib/FuzzyMatch.mjs"; import {fuzzyMatch, calcMatchRanges} from "../../core/lib/FuzzyMatch.mjs";
import {COperationList} from "../components/c-operation-list.mjs"; import {COperationList} from "../components/c-operation-list.mjs";
import {COperationLi} from "../components/c-operation-li.mjs";
/** /**
* Waiter to handle events related to the operations. * Waiter to handle events related to the operations.
@ -205,7 +204,7 @@ class OperationsWaiter {
class: "remove-icon", class: "remove-icon",
innerText: "delete" innerText: "delete"
}, },
) );
opList.build(); opList.build();
div.appendChild(opList); div.appendChild(opList);

View file

@ -34,9 +34,18 @@ class RecipeWaiter {
initDragAndDrop() { initDragAndDrop() {
const recList = document.getElementById("rec-list"); const recList = document.getElementById("rec-list");
let swapThreshold = this.app.isMobileView() ? 0.60 : 0.10; let swapThreshold, animation, delay;
let animation = this.app.isMobileView() ? 400 : 200;
let delay = this.app.isMobileView() ? 200 : 0; // tweak these values for better user experiences per device type and UI
if (this.app.isMobileView()) {
swapThreshold = 0.60;
animation = 400;
delay = 200;
} else {
swapThreshold = 0.10;
animation = 200;
delay = 0;
}
// Recipe list // Recipe list
Sortable.create(recList, { Sortable.create(recList, {
@ -365,7 +374,7 @@ class RecipeWaiter {
* @param {string} name - The name of the operation to add * @param {string} name - The name of the operation to add
*/ */
addOperation(name) { addOperation(name) {
let item = this.buildRecipeOperation(name); const item = this.buildRecipeOperation(name);
document.getElementById("rec-list").appendChild(item); document.getElementById("rec-list").appendChild(item);
$(item).find("[data-toggle='tooltip']").tooltip(); $(item).find("[data-toggle='tooltip']").tooltip();