@creative-web-solution/front-library 7.0.7 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/DOM/Class.ts +10 -12
  3. package/DOM/DocumentSize.ts +3 -1
  4. package/DOM/Filter.ts +0 -2
  5. package/DOM/Index.ts +1 -3
  6. package/DOM/Manipulation.ts +0 -3
  7. package/DOM/Matrix.ts +12 -12
  8. package/DOM/Offset.ts +4 -5
  9. package/DOM/OuterSize.ts +12 -12
  10. package/DOM/PageToDOM.ts +2 -2
  11. package/DOM/Position.ts +3 -3
  12. package/DOM/Size.ts +3 -7
  13. package/DOM/StrToDOM.ts +0 -1
  14. package/DOM/Styles.ts +3 -12
  15. package/DOM/Traversing.ts +0 -6
  16. package/DOM/WindowScroll.ts +3 -1
  17. package/DOM/WindowSize.ts +3 -1
  18. package/DOM/Wrap.ts +0 -1
  19. package/Events/DeviceOrientation.ts +27 -31
  20. package/Events/EventsManager.ts +10 -25
  21. package/Events/Gesture.ts +36 -37
  22. package/Events/HistoryController.ts +11 -17
  23. package/Events/ImageLoad.ts +35 -19
  24. package/Events/IntersectObserver.ts +15 -19
  25. package/Events/KeyboardHandler.ts +10 -8
  26. package/Events/MediaQueriesEvents.ts +53 -51
  27. package/Events/OnAnimationEnd.ts +2 -3
  28. package/Events/OnTransitionEnd.ts +3 -3
  29. package/Events/PubSub.ts +5 -8
  30. package/Events/TouchHover.ts +18 -21
  31. package/Events/WindowEvents.ts +26 -30
  32. package/Helpers/Colors.ts +7 -23
  33. package/Helpers/Cookie.ts +5 -12
  34. package/Helpers/Coordinates.ts +0 -7
  35. package/Helpers/Debounce.ts +3 -7
  36. package/Helpers/Defer.ts +1 -1
  37. package/Helpers/GetValue.ts +0 -2
  38. package/Helpers/Insert.ts +0 -1
  39. package/Helpers/Sequential.ts +0 -2
  40. package/Helpers/Slice.ts +0 -3
  41. package/Helpers/Throttle.ts +0 -1
  42. package/Helpers/TransitionHelpers.ts +8 -6
  43. package/Helpers/Type.ts +1 -14
  44. package/Helpers/Unique.ts +3 -3
  45. package/Helpers/UrlParser.ts +13 -22
  46. package/Helpers/Wait.ts +1 -1
  47. package/Modules/Accordion/Tab.ts +18 -16
  48. package/Modules/Accordion/index.ts +24 -16
  49. package/Modules/Autocomplete.ts +95 -101
  50. package/Modules/DragSlider.ts +72 -63
  51. package/Modules/GlobalState.ts +60 -53
  52. package/Modules/LoadGMap.ts +4 -7
  53. package/Modules/Notifications/Notification.ts +28 -32
  54. package/Modules/Notifications/index.ts +43 -36
  55. package/Modules/Popin/Popin.ts +100 -110
  56. package/Modules/Popin/PopinAccessibility.ts +8 -8
  57. package/Modules/Popin/PopinBackground.ts +11 -11
  58. package/Modules/Popin/PopinController.ts +23 -29
  59. package/Modules/Popin/Tools.ts +18 -19
  60. package/Modules/QuickTemplate.ts +4 -6
  61. package/Modules/ScrollSnap.ts +110 -104
  62. package/Modules/SkinCheckbox.ts +51 -37
  63. package/Modules/SkinFile.ts +62 -52
  64. package/Modules/SkinRadio.ts +62 -42
  65. package/Modules/SkinSelect.ts +116 -100
  66. package/Modules/Slider/Slide.ts +49 -52
  67. package/Modules/Slider/Slider.ts +100 -136
  68. package/Modules/Slider/SliderControls.ts +60 -59
  69. package/Modules/Tabs/Tab.ts +27 -23
  70. package/Modules/Tabs/index.ts +35 -25
  71. package/Modules/Validator/Date.ts +2 -1
  72. package/Modules/Validator/Equals.ts +1 -1
  73. package/Modules/Validator/Internal/Input.ts +370 -0
  74. package/Modules/Validator/Internal/InputValidator.ts +99 -0
  75. package/Modules/Validator/Internal/ValidatorFunctionsController.ts +58 -0
  76. package/Modules/Validator/Max.ts +1 -1
  77. package/Modules/Validator/Min.ts +1 -1
  78. package/Modules/Validator/MultiRequired.ts +5 -5
  79. package/Modules/Validator/Number.ts +1 -0
  80. package/Modules/Validator/Pattern.ts +1 -1
  81. package/Modules/Validator/Recaptcha.ts +1 -0
  82. package/Modules/Validator/Required.ts +3 -2
  83. package/Modules/Validator/ServerCheck.ts +23 -15
  84. package/Modules/Validator/Tools/GetQueryFromForm.ts +1 -6
  85. package/Modules/Validator/Tools/IsDate.ts +2 -3
  86. package/Modules/Validator/Tools/IsEmail.ts +2 -5
  87. package/Modules/Validator/Tools/IsEmpty.ts +0 -2
  88. package/Modules/Validator/Tools/IsNumber.ts +0 -2
  89. package/Modules/Validator/Tools/IsUrl.ts +1 -3
  90. package/Modules/Validator/Tools/Label.ts +5 -15
  91. package/Modules/Validator/Tools/RadioButton.ts +4 -10
  92. package/Modules/Validator/Url.ts +1 -0
  93. package/Modules/Validator/index.ts +36 -36
  94. package/Modules/YouTubePlayer.ts +18 -16
  95. package/README.md +1 -1
  96. package/Types/Accordion.d.ts +36 -0
  97. package/Types/Autocomplete.d.ts +95 -0
  98. package/Types/DOM.d.ts +69 -0
  99. package/Types/DragSlider.d.ts +56 -0
  100. package/Types/EventsHelpers.d.ts +390 -0
  101. package/Types/GLImageTransition.d.ts +47 -43
  102. package/Types/GlobalState.d.ts +9 -0
  103. package/Types/Helpers.d.ts +30 -0
  104. package/Types/Notifications.d.ts +48 -44
  105. package/Types/Popin.d.ts +95 -0
  106. package/Types/ScrollSnap.d.ts +66 -0
  107. package/Types/SkinCheckbox.d.ts +26 -0
  108. package/Types/SkinFile.d.ts +38 -0
  109. package/Types/SkinRadio.d.ts +28 -0
  110. package/Types/SkinSelect.d.ts +59 -0
  111. package/Types/Slider.d.ts +106 -0
  112. package/Types/Tabs.d.ts +26 -0
  113. package/Types/Validator.d.ts +72 -0
  114. package/Types/YouTubePlayer.d.ts +27 -0
  115. package/Types/index.d.ts +22 -21
  116. package/WebGL/GLImageTransition/GLImageTransition.ts +83 -80
  117. package/WebGL/GLImageTransition/Presets/Cellular.ts +11 -11
  118. package/WebGL/GLImageTransition/Presets/Fade.ts +2 -3
  119. package/WebGL/GLImageTransition/Presets/HorizontalMovingGrid.ts +9 -9
  120. package/WebGL/GLImageTransition/Presets/PresetSample.ts +11 -9
  121. package/WebGL/GLImageTransition/Presets/Solarisation.ts +7 -12
  122. package/package.json +1 -1
  123. package/Modules/Template.ts +0 -209
  124. package/Types/AccordionTypes.d.ts +0 -29
  125. package/Types/AutocompleteTypes.d.ts +0 -85
  126. package/Types/DOMTypes.d.ts +0 -62
  127. package/Types/DragSliderTypes.d.ts +0 -52
  128. package/Types/EventsHelpersTypes.d.ts +0 -370
  129. package/Types/GlobalStateTypes.d.ts +0 -5
  130. package/Types/HelpersTypes.d.ts +0 -23
  131. package/Types/MediaPreloaderTypes.d.ts +0 -12
  132. package/Types/PopinTypes.d.ts +0 -83
  133. package/Types/ScrollSnapTypes.d.ts +0 -62
  134. package/Types/SkinCheckboxTypes.d.ts +0 -23
  135. package/Types/SkinFileTypes.d.ts +0 -34
  136. package/Types/SkinRadioTypes.d.ts +0 -24
  137. package/Types/SkinSelectTypes.d.ts +0 -48
  138. package/Types/SliderTypes.d.ts +0 -97
  139. package/Types/TabsTypes.d.ts +0 -22
  140. package/Types/ValidatorTypes.d.ts +0 -61
  141. package/Types/YouTubePlayerTypes.d.ts +0 -23
@@ -69,8 +69,8 @@ const PREVENT_DEFAULT_KEY_LIST = [ "Up", "ArrowUp", "Down", "ArrowDown", "Enter"
69
69
  * @see extra/modules/autocomplete.md for details.
70
70
  */
71
71
  export default class Autocomplete {
72
- #options: AutocompleteOptionsType;
73
- #cacheQuery: { [ key: string ]: AutocompleteItemType[] };
72
+ #options: FLib.Autocomplete.Options;
73
+ #cacheQuery: Record<string, FLib.Autocomplete.Item[]>;
74
74
  #timeoutId;
75
75
  #$layer: HTMLElement;
76
76
  #$list;
@@ -83,20 +83,20 @@ export default class Autocomplete {
83
83
  #url;
84
84
  #hideTimeoutId;
85
85
  #$field;
86
- #className: AutocompleteClassnameType;
86
+ #className: FLib.Autocomplete.Classname;
87
87
  #$panelWrapper;
88
- #l10n: AutocompleteL10NType;
88
+ #l10n: FLib.Autocomplete.L10N;
89
89
  #currentQuery;
90
90
  #requestAbortController;
91
91
  #isDisabled;
92
92
 
93
93
 
94
- get isDisable() {
94
+ get isDisable(): boolean {
95
95
  return this.#isDisabled || this.#$field.disabled
96
96
  }
97
97
 
98
98
 
99
- constructor( userOptions: AutocompleteOptionsType ) {
99
+ constructor( userOptions: FLib.Autocomplete.OptionsInit ) {
100
100
  if ( !( "AbortController" in window ) ) {
101
101
  throw 'This plugin uses fecth and AbortController. You may need to add a polyfill for this browser.';
102
102
  }
@@ -111,13 +111,13 @@ export default class Autocomplete {
111
111
  this.#url = this.#options.url;
112
112
  this.#$field = this.#options.$searchField;
113
113
  this.#$panelWrapper = this.#options.$panelWrapper;
114
- this.#className = this.#options.className!;
115
- this.#l10n = this.#options.l10n!;
114
+ this.#className = this.#options.className;
115
+ this.#l10n = this.#options.l10n;
116
116
 
117
117
  this.#tplSuggestion = `<ul role="listbox" class="${ this.#className.list }">{LIST}</ul>`;
118
118
 
119
119
  this.#$layer = document.createElement( 'DIV' );
120
- this.#$layer.classList.add( this.#className.layer! );
120
+ this.#$layer.classList.add( this.#className.layer as string );
121
121
 
122
122
  append( this.#$layer, this.#$panelWrapper );
123
123
 
@@ -148,7 +148,7 @@ export default class Autocomplete {
148
148
  *
149
149
  * @param newOption - Same options as constructor
150
150
  */
151
- setOptions( _newOption: AutocompleteOptionsType ): this {
151
+ setOptions( _newOption: FLib.Autocomplete.Options ): this {
152
152
  this.#options = extend( this.#options, _newOption );
153
153
 
154
154
  return this;
@@ -158,10 +158,10 @@ export default class Autocomplete {
158
158
  /**
159
159
  * Display the result list
160
160
  */
161
- private show() {
162
- let topVal, parentFieldOffset, fieldHeight, wrapperHeight, wrapperStyle;
161
+ #show = (): void => {
162
+ let topVal, parentFieldOffset, fieldHeight, wrapperHeight;
163
163
 
164
- wrapperStyle = this.#$layer.style;
164
+ const wrapperStyle = this.#$layer.style;
165
165
 
166
166
  if ( !this.#options.cssPositionning ) {
167
167
  parentFieldOffset = offset( this.#$field.parentNode );
@@ -194,7 +194,7 @@ export default class Autocomplete {
194
194
  /**
195
195
  * Hide the result list
196
196
  */
197
- private hide() {
197
+ #hide = (): void => {
198
198
  clearTimeout( this.#hideTimeoutId );
199
199
  gestureOff( document.body, '__AutocompleteTapOutside' );
200
200
 
@@ -205,12 +205,12 @@ export default class Autocomplete {
205
205
  }
206
206
 
207
207
 
208
- #clickOutsideHandler = ( e, $target: HTMLElement ) => {
209
- let $parent = $target.closest( this.#className.layer! );
208
+ #clickOutsideHandler = ( e: Event, $target: HTMLElement ): void => {
209
+ const $parent = $target.closest( this.#className.layer as string );
210
210
 
211
211
  if ( !$parent && $target !== this.#$field ) {
212
212
  this.#hideTimeoutId = setTimeout( () => {
213
- this.hide();
213
+ this.#hide();
214
214
  }, 500 );
215
215
  }
216
216
  }
@@ -220,10 +220,9 @@ export default class Autocomplete {
220
220
  * Create the results list
221
221
  *
222
222
  * @param _list - Array of result
223
- * @param _query
224
223
  */
225
- private set( _list: AutocompleteItemType[], _query: string ): this {
226
- let html, reQuery;
224
+ #set = ( _list: FLib.Autocomplete.Item[], _query: string ): this => {
225
+ let html;
227
226
 
228
227
  this.#currentResults = _list;
229
228
  this.#currentQuery = _query;
@@ -231,7 +230,7 @@ export default class Autocomplete {
231
230
  html = [];
232
231
  this.#hasResults = true;
233
232
 
234
- reQuery = new RegExp(`(${ _query
233
+ const reQuery = new RegExp(`(${ _query
235
234
  .replace( /a/gi, '[aàâä]' )
236
235
  .replace( /c/gi, '[cç]' )
237
236
  .replace( /e/gi, '[eéèêë]' )
@@ -241,7 +240,7 @@ export default class Autocomplete {
241
240
  .replace( /y/gi, '[y]')})`, 'gi' );
242
241
 
243
242
  html = _list.map( ( item, i ) => {
244
- this.#options.renderMark!(
243
+ this.#options.renderMark?.(
245
244
  {
246
245
  "resultItem": item,
247
246
  reQuery,
@@ -251,7 +250,7 @@ export default class Autocomplete {
251
250
  "cssClass": this.#className
252
251
  }
253
252
  );
254
- return this.#options.render!( {
253
+ return this.#options.render( {
255
254
  "resultItem": item,
256
255
  "index": i,
257
256
  "query": _query,
@@ -260,13 +259,13 @@ export default class Autocomplete {
260
259
  } );
261
260
  } );
262
261
 
263
- this.#$layer.innerHTML = this.#options.renderList!( {
262
+ this.#$layer.innerHTML = this.#options.renderList( {
264
263
  "resultList": html,
265
264
  "query": _query,
266
265
  "cssClass": this.#className
267
266
  } );
268
267
 
269
- this.#$list = this.#$layer.querySelector( this.#className.list! );
268
+ this.#$list = this.#$layer.querySelector( this.#className.list );
270
269
 
271
270
  this.#selectionLocked = false;
272
271
  this.#nbResults = _list.length;
@@ -281,7 +280,7 @@ export default class Autocomplete {
281
280
  *
282
281
  * @param _list - Array of result
283
282
  */
284
- private setAll( _list: AutocompleteItemType[] ): this {
283
+ #setAll = ( _list: FLib.Autocomplete.Item[] ): this => {
285
284
  let html;
286
285
 
287
286
  this.#currentResults = _list;
@@ -291,7 +290,7 @@ export default class Autocomplete {
291
290
  this.#hasResults = true;
292
291
 
293
292
  html = _list.map( ( item, i ) => {
294
- this.#options.renderMark!(
293
+ this.#options.renderMark(
295
294
  {
296
295
  "resultItem": item,
297
296
  "index": i,
@@ -300,7 +299,7 @@ export default class Autocomplete {
300
299
  "cssClass": this.#className
301
300
  }
302
301
  );
303
- return this.#options.render!( {
302
+ return this.#options.render( {
304
303
  "resultItem": item,
305
304
  "index": i,
306
305
  "query": "",
@@ -309,13 +308,13 @@ export default class Autocomplete {
309
308
  } );
310
309
  } );
311
310
 
312
- this.#$layer.innerHTML = this.#options.renderList!( {
311
+ this.#$layer.innerHTML = this.#options.renderList( {
313
312
  "resultList": html,
314
313
  "cssClass": this.#className,
315
314
  "query": ""
316
315
  } );
317
316
 
318
- this.#$list = this.#$layer.querySelector( this.#className.list! );
317
+ this.#$list = this.#$layer.querySelector( this.#className.list );
319
318
 
320
319
  this.#selectionLocked = false;
321
320
  this.#nbResults = _list.length;
@@ -327,14 +326,12 @@ export default class Autocomplete {
327
326
 
328
327
  /**
329
328
  * Display error message (like "No results")
330
- *
331
- * @param errorMsg
332
329
  */
333
- private setError( errorMsg?: string ) {
334
- let html: string[] = [];
330
+ #setError = ( errorMsg?: string ): void => {
331
+ const html: string[] = [];
335
332
 
336
- html.push( this.#options.renderError!( {
337
- "errorMsg": errorMsg || this.#l10n.noResult!,
333
+ html.push( this.#options.renderError( {
334
+ "errorMsg": errorMsg || this.#l10n.noResult,
338
335
  "query": this.#currentQuery,
339
336
  "cssClass": this.#className
340
337
  } ) );
@@ -352,7 +349,7 @@ export default class Autocomplete {
352
349
  *
353
350
  * @param selectedIndex - Index of the selected item
354
351
  */
355
- private select( _selectedIndex?: number ) {
352
+ #select = ( _selectedIndex?: number ): void => {
356
353
  if ( this.#selectionLocked ) {
357
354
  return;
358
355
  }
@@ -370,7 +367,7 @@ export default class Autocomplete {
370
367
  );
371
368
  }
372
369
 
373
- this.hide();
370
+ this.#hide();
374
371
 
375
372
  if ( this.#options.onSelect ) {
376
373
  this.#options.onSelect.call(
@@ -387,11 +384,10 @@ export default class Autocomplete {
387
384
 
388
385
  /**
389
386
  * Highlight the choosen item
390
- * @ignore
391
387
  *
392
388
  * @param _index - Index of the item to hover
393
389
  */
394
- private hover( _index: number ) {
390
+ #hover = ( _index: number ): void => {
395
391
  let $item, itemPos, top, itemHeight;
396
392
 
397
393
  if ( this.#selectionLocked ) {
@@ -419,7 +415,7 @@ export default class Autocomplete {
419
415
  top = this.#$list.scrollTop;
420
416
 
421
417
  if ( itemPos.top + itemHeight > this.#options.maxHeight + top) {
422
- this.#$list.scrollTop = itemPos.top - this.#options.maxHeight! + itemHeight;
418
+ this.#$list.scrollTop = itemPos.top - this.#options.maxHeight + itemHeight;
423
419
  }
424
420
  else if ( top > 0 && itemPos.top < top ) {
425
421
  this.#$list.scrollTop = itemPos.top;
@@ -431,51 +427,49 @@ export default class Autocomplete {
431
427
  /**
432
428
  * Highlight the next item
433
429
  */
434
- private hoverNext() {
435
- this.hover( this.#selectedIndex + 1 < this.#nbResults ? this.#selectedIndex + 1 : 0 );
430
+ #hoverNext = (): void => {
431
+ this.#hover( this.#selectedIndex + 1 < this.#nbResults ? this.#selectedIndex + 1 : 0 );
436
432
  }
437
433
 
438
434
 
439
435
  /**
440
436
  * Highlight the previous item
441
437
  */
442
- private hoverPrevious() {
443
- this.hover( this.#selectedIndex - 1 >= 0 ? this.#selectedIndex - 1 : this.#nbResults - 1 );
438
+ #hoverPrevious = (): void => {
439
+ this.#hover( this.#selectedIndex - 1 >= 0 ? this.#selectedIndex - 1 : this.#nbResults - 1 );
444
440
  }
445
441
 
446
442
 
447
443
  /**
448
444
  * Load the results list
449
- *
450
- * @param _query
451
445
  */
452
- private load( _query: string ) {
446
+ #load = ( _query: string ): void => {
453
447
  this.#currentResults = [];
454
448
 
455
449
  this.#hasResults = false;
456
450
 
457
451
  if (!!this.#cacheQuery[ _query ] && this.#options.useCache ) {
458
- this.set( this.#cacheQuery[ _query ], _query );
459
- this.show();
452
+ this.#set( this.#cacheQuery[ _query ], _query );
453
+ this.#show();
460
454
  }
461
455
  else if ( this.#options.source ) {
462
456
  this.#options.source( _query, results => {
463
457
  this.#cacheQuery[ _query ] = results;
464
458
 
465
459
  if ( results.length ) {
466
- this.set( results, _query );
460
+ this.#set( results, _query );
467
461
  }
468
462
  else {
469
- this.setError( this.#l10n.noResult );
463
+ this.#setError( this.#l10n.noResult );
470
464
  }
471
465
 
472
- this.show();
466
+ this.#show();
473
467
  } );
474
468
 
475
469
  return;
476
470
  }
477
471
  else {
478
- let params, myHeaders, newUrl;
472
+ let params;
479
473
 
480
474
  if ( this.#requestAbortController ) {
481
475
  this.#requestAbortController.abort();
@@ -483,15 +477,15 @@ export default class Autocomplete {
483
477
 
484
478
  this.#requestAbortController = new AbortController();
485
479
 
486
- params = this.#options.queryParams!( _query );
480
+ params = this.#options.queryParams( _query );
487
481
 
488
482
  params = Object.keys( params ).reduce( ( result, key, index ) => {
489
483
  return (index > 0 ? result + '&' : '') + key + '=' + params[ key ];
490
484
  }, '' );
491
485
 
492
- newUrl = [ this.#url, this.#url.indexOf( '?' ) > -1 ? '&' : '?', params ].join('');
486
+ const newUrl = [ this.#url, this.#url.indexOf( '?' ) > -1 ? '&' : '?', params ].join('');
493
487
 
494
- myHeaders = new Headers();
488
+ const myHeaders = new Headers();
495
489
  myHeaders.append( 'X-Requested-With', 'XMLHttpRequest' );
496
490
 
497
491
  fetch( newUrl, {
@@ -503,75 +497,73 @@ export default class Autocomplete {
503
497
  return response;
504
498
  }
505
499
  else {
506
- let error = new Error( response.statusText );
507
- throw error;
500
+ throw new Error( response.statusText );
508
501
  }
509
502
  })
510
503
  .then( function( response ) {
511
504
  return response.json();
512
505
  } )
513
506
  .then( _data => {
514
- let normalizedData = this.#options.normalize!( _data );
507
+ const normalizedData = this.#options.normalize( _data );
515
508
 
516
509
  if (
517
510
  normalizedData.success &&
518
511
  normalizedData.results.length > 0
519
512
  ) {
520
- this.set( normalizedData.results, _query);
513
+ this.#set( normalizedData.results, _query);
521
514
  this.#cacheQuery[ _query ] = normalizedData.results;
522
515
  }
523
516
  else if ( !normalizedData.results.length ) {
524
- this.setError( this.#l10n.noResult );
517
+ this.#setError( this.#l10n.noResult );
525
518
  }
526
519
  else {
527
- this.setError( this.#l10n.error ) ;
520
+ this.#setError( this.#l10n.error ) ;
528
521
  }
529
522
  } )
530
523
  .catch( () => {
531
- this.setError();
524
+ this.#setError();
532
525
  } )
533
526
  .finally(() => {
534
- this.show();
527
+ this.#show();
535
528
  this.#requestAbortController = null;
536
529
  } );
537
530
  }
538
531
  }
539
532
 
540
533
 
541
- #onKeydown = ( e: KeyboardEvent ) => {
534
+ #onKeydown = ( e: KeyboardEvent ): void => {
542
535
  if ( PREVENT_DEFAULT_KEY_LIST.includes( e.key ) ) {
543
536
  e.preventDefault();
544
537
  }
545
538
  }
546
539
 
547
540
 
548
- #onKeyup = ( e: KeyboardEvent ) => {
549
- let query;
541
+ #onKeyup = ( e: KeyboardEvent ): void => {
550
542
 
551
543
  if ( this.isDisable ) {
552
544
  return;
553
545
  }
554
546
 
555
- query = ( e.target as HTMLInputElement ).value;
547
+ const query = ( e.target as HTMLInputElement ).value;
556
548
 
557
549
  switch ( e.key ) {
558
550
  case "Up":
559
551
  case "ArrowUp":
560
- this.hoverPrevious();
552
+ this.#hoverPrevious();
561
553
  break;
562
554
 
563
555
  case "Down":
564
556
  case "ArrowDown":
565
- this.hoverNext();
557
+ this.#hoverNext();
566
558
  break;
567
559
 
568
560
  case "Enter":
569
- this.select();
561
+ this.#select();
570
562
  break;
571
563
 
572
564
  case "Esc":
573
565
  case "Escape":
574
- this.hide();
566
+ this.#hide();
575
567
  // if ( this.#options.results ) {
576
568
  // this.#options.results.hide();
577
569
  // }
@@ -596,13 +588,13 @@ export default class Autocomplete {
596
588
  default:
597
589
  clearTimeout( this.#timeoutId );
598
590
 
599
- if ( query.trim().length >= this.#options.minchar! ) {
591
+ if ( query.trim().length >= this.#options.minchar ) {
600
592
  this.#timeoutId = setTimeout( () => {
601
- this.load( query );
593
+ this.#load( query );
602
594
  }, 800 );
603
595
  }
604
596
  else {
605
- this.hide();
597
+ this.#hide();
606
598
  if ( this.#requestAbortController ) {
607
599
  this.#requestAbortController.abort();
608
600
  }
@@ -612,30 +604,30 @@ export default class Autocomplete {
612
604
  }
613
605
 
614
606
 
615
- #onFocus = () => {
607
+ #onFocus = (): void => {
616
608
  clearTimeout( this.#hideTimeoutId );
617
609
  }
618
610
 
619
611
 
620
- #onTapField = () => {
612
+ #onTapField = (): void => {
621
613
  if ( this.isDisable ) {
622
614
  return;
623
615
  }
624
616
 
625
617
  if ( this.#hasResults ) {
626
618
  this.#selectionLocked = false;
627
- this.show();
619
+ this.#show();
628
620
  }
629
621
  }
630
622
 
631
623
 
632
- #onTapLinks = ( e, $target: HTMLElement ) => {
624
+ #onTapLinks = ( e: Event, $target: HTMLElement ): void => {
633
625
  if ( this.isDisable ) {
634
626
  return;
635
627
  }
636
628
 
637
629
  const idx = $target.getAttribute( 'data-idx' );
638
- this.select( Number( idx ) );
630
+ this.#select( Number( idx ) );
639
631
  }
640
632
 
641
633
 
@@ -648,19 +640,19 @@ export default class Autocomplete {
648
640
  return this;
649
641
  }
650
642
 
651
- this.#options.source( null, ( results: AutocompleteItemType[] ) => {
643
+ this.#options.source( null, ( results: FLib.Autocomplete.Item[] ) => {
652
644
  if ( results.length ) {
653
- this.setAll( results );
645
+ this.#setAll( results );
654
646
  }
655
647
  else {
656
- this.setError( this.#l10n.noResult );
648
+ this.#setError( this.#l10n.noResult );
657
649
  }
658
650
 
659
- this.show();
651
+ this.#show();
660
652
  } );
661
653
 
662
654
  return this;
663
- };
655
+ }
664
656
 
665
657
 
666
658
  /**
@@ -672,29 +664,25 @@ export default class Autocomplete {
672
664
  this.#$field.classList.add( this.#className.disable );
673
665
 
674
666
  return this;
675
- };
667
+ }
676
668
 
677
669
 
678
670
  /**
679
671
  * Enable the autocomplete
680
- *
681
- * @returns {Autocomplete}
682
672
  */
683
- enable() {
673
+ enable(): this {
684
674
  this.#isDisabled = false;
685
675
  this.#$field.disabled = false;
686
676
  this.#$field.classList.remove( this.#className.disable );
687
677
 
688
678
  return this;
689
- };
679
+ }
690
680
 
691
681
 
692
682
  /**
693
683
  * Destroy the Autocomplete
694
- *
695
- * @returns {Autocomplete}
696
684
  */
697
- clean() {
685
+ clean(): this {
698
686
  this.#$field.removeEventListener( 'keyup', this.#onKeyup );
699
687
  this.#$field.removeEventListener( 'keydown', this.#onKeydown );
700
688
  this.#$field.removeEventListener( 'focus', this.#onFocus );
@@ -715,34 +703,40 @@ export default class Autocomplete {
715
703
  remove( this.#$layer );
716
704
 
717
705
  return this;
718
- };
706
+ }
719
707
 
720
708
 
721
709
  /**
722
710
  * Reset the input field
723
711
  */
724
- resetField() {
712
+ resetField(): this {
725
713
  this.#$field.value = '';
726
- };
714
+
715
+ return this;
716
+ }
727
717
 
728
718
 
729
719
  /**
730
720
  * Reset the results
731
721
  */
732
- resetResults() {
722
+ resetResults(): this {
733
723
  this.#currentQuery = '';
734
724
  this.#currentResults = [];
735
725
  this.#selectedIndex = -1;
736
726
  this.#nbResults = 0;
737
727
  this.#hasResults = false;
738
- };
728
+
729
+ return this;
730
+ }
739
731
 
740
732
 
741
733
  /**
742
734
  * Reset the input field and the results
743
735
  */
744
- reset() {
736
+ reset(): this {
745
737
  this.resetField();
746
738
  this.resetResults();
747
- };
739
+
740
+ return this;
741
+ }
748
742
  }