Skip to content

Commit 562a542

Browse files
committed
style: fix linter issues
1 parent 34593d0 commit 562a542

28 files changed

+961
-858
lines changed

src/autocomplete.ts

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Utils } from "./utils";
2-
import { Dropdown, DropdownOptions } from "./dropdown";
3-
import { Component, BaseOptions, InitElements, MElement } from "./component";
1+
import { Utils } from './utils';
2+
import { Dropdown, DropdownOptions } from './dropdown';
3+
import { Component, BaseOptions, InitElements, MElement } from './component';
44

55
export interface AutocompleteData {
66
/**
@@ -82,9 +82,10 @@ const _defaults: AutocompleteOptions = {
8282
onSearch: (text: string, autocomplete: Autocomplete) => {
8383
const normSearch = text.toLocaleLowerCase();
8484
autocomplete.setMenuItems(
85-
autocomplete.options.data.filter((option) =>
86-
option.id.toString().toLocaleLowerCase().includes(normSearch)
87-
|| option.text?.toLocaleLowerCase().includes(normSearch)
85+
autocomplete.options.data.filter(
86+
(option) =>
87+
option.id.toString().toLocaleLowerCase().includes(normSearch) ||
88+
option.text?.toLocaleLowerCase().includes(normSearch)
8889
)
8990
);
9091
},
@@ -101,7 +102,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
101102
/** Index of the current selected option. */
102103
activeIndex: number;
103104
private oldVal: string;
104-
private $active: HTMLElement|null;
105+
private $active: HTMLElement | null;
105106
private _mousedown: boolean;
106107
container: HTMLElement;
107108
/** Instance of the dropdown plugin for this autocomplete. */
@@ -112,7 +113,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
112113

113114
constructor(el: HTMLInputElement, options: Partial<AutocompleteOptions>) {
114115
super(el, options, Autocomplete);
115-
(this.el as any).M_Autocomplete = this;
116+
this.el['M_Autocomplete'] = this;
116117

117118
this.options = {
118119
...Autocomplete.defaults,
@@ -122,7 +123,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
122123
this.isOpen = false;
123124
this.count = 0;
124125
this.activeIndex = -1;
125-
this.oldVal = "";
126+
this.oldVal = '';
126127
this.selectedValues = [];
127128
this.menuItems = this.options.data || [];
128129
this.$active = null;
@@ -146,24 +147,30 @@ export class Autocomplete extends Component<AutocompleteOptions> {
146147
* @param els HTML elements.
147148
* @param options Component options.
148149
*/
149-
static init(els: InitElements<HTMLInputElement | MElement>, options?: Partial<AutocompleteOptions>): Autocomplete[];
150+
static init(
151+
els: InitElements<HTMLInputElement | MElement>,
152+
options?: Partial<AutocompleteOptions>
153+
): Autocomplete[];
150154
/**
151155
* Initializes instances of Autocomplete.
152156
* @param els HTML elements.
153157
* @param options Component options.
154158
*/
155-
static init(els: HTMLInputElement | InitElements<HTMLInputElement | MElement>, options: Partial<AutocompleteOptions> = {}): Autocomplete | Autocomplete[] {
159+
static init(
160+
els: HTMLInputElement | InitElements<HTMLInputElement | MElement>,
161+
options: Partial<AutocompleteOptions> = {}
162+
): Autocomplete | Autocomplete[] {
156163
return super.init(els, options, Autocomplete);
157164
}
158165

159166
static getInstance(el: HTMLElement): Autocomplete {
160-
return (el as any).M_Autocomplete;
167+
return el['M_Autocomplete'];
161168
}
162169

163170
destroy() {
164171
this._removeEventHandlers();
165172
this._removeDropdown();
166-
(this.el as any).M_Autocomplete = undefined;
173+
this.el['M_Autocomplete'] = undefined;
167174
}
168175

169176
_setupEventHandlers() {
@@ -172,16 +179,10 @@ export class Autocomplete extends Component<AutocompleteOptions> {
172179
this.el.addEventListener('focus', this._handleInputFocus);
173180
this.el.addEventListener('keydown', this._handleInputKeydown);
174181
this.el.addEventListener('click', this._handleInputClick);
175-
this.container.addEventListener(
176-
'mousedown',
177-
this._handleContainerMousedownAndTouchstart
178-
);
182+
this.container.addEventListener('mousedown', this._handleContainerMousedownAndTouchstart);
179183
this.container.addEventListener('mouseup', this._handleContainerMouseupAndTouchend);
180184
if (typeof window.ontouchstart !== 'undefined') {
181-
this.container.addEventListener(
182-
'touchstart',
183-
this._handleContainerMousedownAndTouchstart
184-
);
185+
this.container.addEventListener('touchstart', this._handleContainerMousedownAndTouchstart);
185186
this.container.addEventListener('touchend', this._handleContainerMouseupAndTouchend);
186187
}
187188
}
@@ -192,21 +193,12 @@ export class Autocomplete extends Component<AutocompleteOptions> {
192193
this.el.removeEventListener('focus', this._handleInputFocus);
193194
this.el.removeEventListener('keydown', this._handleInputKeydown);
194195
this.el.removeEventListener('click', this._handleInputClick);
195-
this.container.removeEventListener(
196-
'mousedown',
197-
this._handleContainerMousedownAndTouchstart
198-
);
196+
this.container.removeEventListener('mousedown', this._handleContainerMousedownAndTouchstart);
199197
this.container.removeEventListener('mouseup', this._handleContainerMouseupAndTouchend);
200198

201199
if (typeof window.ontouchstart !== 'undefined') {
202-
this.container.removeEventListener(
203-
'touchstart',
204-
this._handleContainerMousedownAndTouchstart
205-
);
206-
this.container.removeEventListener(
207-
'touchend',
208-
this._handleContainerMouseupAndTouchend
209-
);
200+
this.container.removeEventListener('touchstart', this._handleContainerMousedownAndTouchstart);
201+
this.container.removeEventListener('touchend', this._handleContainerMouseupAndTouchend);
210202
}
211203
}
212204

@@ -217,7 +209,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
217209
this.container.classList.add('autocomplete-content', 'dropdown-content');
218210
this.el.setAttribute('data-target', this.container.id);
219211

220-
this.menuItems.forEach(menuItem => {
212+
this.menuItems.forEach((menuItem) => {
221213
const itemElement = this._createDropdownItem(menuItem);
222214
this.container.append(itemElement);
223215
});
@@ -269,17 +261,22 @@ export class Autocomplete extends Component<AutocompleteOptions> {
269261
this.close();
270262
this._resetAutocomplete();
271263
}
272-
}
264+
};
273265

274266
_handleInputKeyup = (e: KeyboardEvent) => {
275267
if (e.type === 'keyup') Autocomplete._keydown = false;
276268
this.count = 0;
277269
const actualValue = this.el.value.toLocaleLowerCase();
278270
// Don't capture enter or arrow key usage.
279-
if (Utils.keys.ENTER.includes(e.key) || Utils.keys.ARROW_UP.includes(e.key) || Utils.keys.ARROW_DOWN.includes(e.key)) return;
271+
if (
272+
Utils.keys.ENTER.includes(e.key) ||
273+
Utils.keys.ARROW_UP.includes(e.key) ||
274+
Utils.keys.ARROW_DOWN.includes(e.key)
275+
)
276+
return;
280277
// Check if the input isn't empty
281278
// Check if focus triggered by tab
282-
if (this.oldVal !== actualValue && (Utils.tabPressed)) {
279+
if (this.oldVal !== actualValue && Utils.tabPressed) {
283280
this.open();
284281
}
285282
this._inputChangeDetection(actualValue);
@@ -289,7 +286,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
289286
this.count = 0;
290287
const actualValue = this.el.value.toLocaleLowerCase();
291288
this._inputChangeDetection(actualValue);
292-
}
289+
};
293290

294291
_inputChangeDetection = (value: string) => {
295292
// Value has changed!
@@ -322,7 +319,8 @@ export class Autocomplete extends Component<AutocompleteOptions> {
322319
if (Utils.keys.ARROW_UP.includes(e.key) || Utils.keys.ARROW_DOWN.includes(e.key)) {
323320
e.preventDefault();
324321
if (Utils.keys.ARROW_UP.includes(e.key) && this.activeIndex > 0) this.activeIndex--;
325-
if (Utils.keys.ARROW_DOWN.includes(e.key) && this.activeIndex < numItems - 1) this.activeIndex++;
322+
if (Utils.keys.ARROW_DOWN.includes(e.key) && this.activeIndex < numItems - 1)
323+
this.activeIndex++;
326324
this.$active?.classList.remove('active');
327325
if (this.activeIndex >= 0) {
328326
this.$active = this.container.querySelectorAll('li')[this.activeIndex];
@@ -335,19 +333,19 @@ export class Autocomplete extends Component<AutocompleteOptions> {
335333
});
336334
}
337335
}
338-
}
336+
};
339337

340338
_handleInputClick = () => {
341339
this.open();
342-
}
340+
};
343341

344342
_handleContainerMousedownAndTouchstart = () => {
345343
this._mousedown = true;
346-
}
344+
};
347345

348346
_handleContainerMouseupAndTouchend = () => {
349347
this._mousedown = false;
350-
}
348+
};
351349

352350
_resetCurrentElementPosition() {
353351
this.activeIndex = -1;
@@ -420,7 +418,10 @@ export class Autocomplete extends Component<AutocompleteOptions> {
420418
item.appendChild(itemText);
421419
item.querySelector('.item-text').appendChild(div);
422420
// Description
423-
if (typeof entry.description === 'string' || (typeof entry.description === 'number' && !isNaN(entry.description))) {
421+
if (
422+
typeof entry.description === 'string' ||
423+
(typeof entry.description === 'number' && !isNaN(entry.description))
424+
) {
424425
const description = document.createElement('small');
425426
description.setAttribute(
426427
'style',
@@ -455,9 +456,8 @@ export class Autocomplete extends Component<AutocompleteOptions> {
455456
}
456457

457458
_setStatusLoading() {
458-
this.el.parentElement.querySelector(
459-
'.status-info'
460-
).innerHTML = `<div style="height:100%;width:50px;"><svg version="1.1" id="L4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100" enable-background="new 0 0 0 0" xml:space="preserve">
459+
this.el.parentElement.querySelector('.status-info').innerHTML =
460+
`<div style="height:100%;width:50px;"><svg version="1.1" id="L4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100" enable-background="new 0 0 0 0" xml:space="preserve">
461461
<circle fill="#888c" stroke="none" cx="6" cy="50" r="6"><animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.1"/></circle>
462462
<circle fill="#888c" stroke="none" cx="26" cy="50" r="6"><animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.2"/></circle>
463463
<circle fill="#888c" stroke="none" cx="46" cy="50" r="6"><animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.3"/></circle>
@@ -467,7 +467,8 @@ export class Autocomplete extends Component<AutocompleteOptions> {
467467
_updateSelectedInfo() {
468468
const statusElement = this.el.parentElement.querySelector('.status-info');
469469
if (statusElement) {
470-
if (this.options.isMultiSelect) statusElement.innerHTML = this.selectedValues.length.toString();
470+
if (this.options.isMultiSelect)
471+
statusElement.innerHTML = this.selectedValues.length.toString();
471472
else statusElement.innerHTML = '';
472473
}
473474
}
@@ -501,16 +502,15 @@ export class Autocomplete extends Component<AutocompleteOptions> {
501502
setTimeout(() => {
502503
this.dropdown.open();
503504
}, 0); // TODO: why?
504-
}
505-
else this.dropdown.recalculateDimensions(); // Recalculate dropdown when its already open
506-
}
505+
} else this.dropdown.recalculateDimensions(); // Recalculate dropdown when its already open
506+
};
507507

508508
/**
509509
* Hide autocomplete.
510510
*/
511511
close = () => {
512512
this.dropdown.close();
513-
}
513+
};
514514

515515
/**
516516
* Updates the visible or selectable items shown in the menu.
@@ -543,10 +543,10 @@ export class Autocomplete extends Component<AutocompleteOptions> {
543543
const entry = this.menuItems.find((item) => item.id == id);
544544
if (!entry) return;
545545
// Toggle Checkbox
546-
const li = this.container.querySelector('li[data-id="'+id+'"]');
546+
const li = this.container.querySelector('li[data-id="' + id + '"]');
547547
if (!li) return;
548548
if (this.options.isMultiSelect) {
549-
const checkbox = <HTMLInputElement|null>li.querySelector('input[type="checkbox"]');
549+
const checkbox = <HTMLInputElement | null>li.querySelector('input[type="checkbox"]');
550550
checkbox.checked = !checkbox.checked;
551551
if (checkbox.checked) this.selectedValues.push(entry);
552552
else

0 commit comments

Comments
 (0)