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

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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,27 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## 7.1.4
5
+
6
+ * Typescript: Fix tsify and browserify compatibility
7
+ * HistoryController: Remove UrlParser for window.URL
8
+
9
+
10
+ ## 7.1.3
11
+
12
+ * Typescript: Fix some type
13
+
14
+
15
+ ## 7.1.2
16
+
17
+ * Typescript: Fix some type
18
+
19
+
20
+ ## 7.1.1
21
+
22
+ * Validator: Fix error message generation
23
+
24
+
4
25
  ## 7.1.0
5
26
 
6
27
  * Typescript cleanup
@@ -1,5 +1,4 @@
1
1
  import { on } from './EventsManager';
2
- import { UrlParser } from '../Helpers/UrlParser';
3
2
  import { slice } from '../Helpers/Slice';
4
3
 
5
4
 
@@ -33,7 +32,7 @@ export default class HistoryController {
33
32
  #hasPushstate: boolean;
34
33
  #hasPopStateEvent: boolean;
35
34
  #currentState: FLib.Events.History.StateObject;
36
- #registeredFunctionList: (( url: UrlParser, state: any ) => void)[];
35
+ #registeredFunctionList: (( url: URL, state: any ) => void)[];
37
36
 
38
37
 
39
38
  get state(): FLib.Events.History.StateObject {
@@ -53,7 +52,7 @@ export default class HistoryController {
53
52
  this.#defaultTitle = encodeURIComponent( defaultTitle );
54
53
 
55
54
  this.#currentState = {
56
- "url": new UrlParser( window.location.href ),
55
+ "url": new window.URL( window.location.href ),
57
56
  "state": {},
58
57
  "title": this.#defaultTitle
59
58
  };
@@ -69,7 +68,7 @@ export default class HistoryController {
69
68
 
70
69
 
71
70
  // Call each registered function for popstate event
72
- #callRegisteredFunction = ( url: UrlParser, state: any ): void => {
71
+ #callRegisteredFunction = ( url: URL, state: any ): void => {
73
72
  if ( !this.#registeredFunctionList.length ) {
74
73
  return;
75
74
  }
@@ -87,7 +86,7 @@ export default class HistoryController {
87
86
  }
88
87
 
89
88
  this.#currentState = {
90
- "url": new UrlParser( document.location.href ),
89
+ "url": new URL( document.location.href ),
91
90
  state,
92
91
  "title": ""
93
92
  };
@@ -101,15 +100,15 @@ export default class HistoryController {
101
100
  *
102
101
  * @param state - Native browser state object
103
102
  */
104
- pushState( state: any, title: string, url: string | UrlParser ): this {
103
+ pushState( state: any, title: string, url: string | URL ): this {
105
104
  if ( !this.#hasPushstate ) {
106
105
  return this;
107
106
  }
108
107
 
109
- url = url instanceof UrlParser ? url : new UrlParser( url as string );
108
+ url = url instanceof URL ? url : new URL( url as string );
110
109
 
111
110
  this.#currentState = {
112
- "url": url as UrlParser,
111
+ "url": url as URL,
113
112
  state,
114
113
  "title": title ? encodeURIComponent( title ) : this.#defaultTitle
115
114
  };
@@ -118,7 +117,7 @@ export default class HistoryController {
118
117
  window.history.pushState(
119
118
  state,
120
119
  this.#currentState.title,
121
- this.#currentState.url.absolute2
120
+ this.#currentState.url.href
122
121
  );
123
122
  }
124
123
  catch ( e ) {
@@ -137,14 +136,14 @@ export default class HistoryController {
137
136
  return this;
138
137
  }
139
138
 
140
- anchor = anchor.indexOf( '#' ) === -1 ? anchor : anchor.slice( 1 );
139
+ anchor = anchor.indexOf( '#' ) === -1 ? `#${ anchor }` : anchor;
141
140
 
142
141
  try {
143
- this.#currentState.url.setAnchor( anchor );
142
+ this.#currentState.url.hash = anchor.indexOf( '#' ) === -1 ? `#${ anchor }` : anchor;
144
143
  window.history.pushState(
145
144
  this.#currentState.state,
146
145
  this.#currentState.title,
147
- this.#currentState.url.absolute2
146
+ this.#currentState.url.href
148
147
  );
149
148
  }
150
149
  catch ( e ) {
@@ -9,7 +9,7 @@ export function debounce(
9
9
  threshold = 100,
10
10
  immediate = false
11
11
  ): ( ...args: any[] ) => void {
12
- let timeout: ReturnType<typeof setTimeout> | undefined;
12
+ let timeout: any;
13
13
 
14
14
  return function<Type>( this: Type, ...args: any[] ) {
15
15
 
@@ -33,7 +33,7 @@
33
33
  * url.removeAll()
34
34
  * ```
35
35
  */
36
- export class UrlParser {
36
+ export class UrlParser implements FLib.Helpers.UrlParser {
37
37
  /** Complete url without userInfo and anchor. Ex: https://demo.domain.com:1337/section/page.html?param=2 */
38
38
  absolute = '';
39
39
  /** Complete url with anchor but without userInfo. Ex: https://demo.domain.com:1337/section/page.html?param=2#anchor */
@@ -5,7 +5,7 @@ import { next } from '../../DOM/Traversing';
5
5
  /**
6
6
  * Tab of an accordion
7
7
  */
8
- export default class Tab {
8
+ export default class Tab implements FLib.Accordion.Tab {
9
9
  #isOpen: boolean;
10
10
  #originalOpenedState: boolean;
11
11
  #$TAB_PANNEL: HTMLElement | null;
@@ -86,9 +86,9 @@ const DEFAULT_OPTIONS = {
86
86
  export default class Accordion {
87
87
  #options: FLib.Accordion.Options;
88
88
  #$tabs: NodeListOf<HTMLElement>;
89
- #tablist: Tab[];
89
+ #tablist: FLib.Accordion.Tab[];
90
90
  #status: string;
91
- #lastOpenedTab: Tab | null = null;
91
+ #lastOpenedTab: FLib.Accordion.Tab | null = null;
92
92
 
93
93
 
94
94
  #STATUS_ON = 'STATUS_ON';
@@ -107,7 +107,7 @@ export default class Accordion {
107
107
  }
108
108
 
109
109
 
110
- #onOpenTab = ( tab: Tab ): void => {
110
+ #onOpenTab = ( tab: FLib.Accordion.Tab ): void => {
111
111
  if ( this.#lastOpenedTab ) {
112
112
  this.#lastOpenedTab.close( true );
113
113
  }
@@ -127,7 +127,7 @@ export default class Accordion {
127
127
  this.#tablist.push( new Tab( $tab, {
128
128
  ...this.#options,
129
129
  index,
130
- "onOpenTab": this.#options.allowMultipleTab ? null : this.#onOpenTab
130
+ "onOpenTab": this.#options.allowMultipleTab ? undefined : this.#onOpenTab
131
131
  } ) );
132
132
  } );
133
133
  }
@@ -20,17 +20,17 @@ export default class DragSlider {
20
20
  #$slider: HTMLElement;
21
21
  #viewportInfo;
22
22
  #siteOffset;
23
- #listDelta!: number;
24
- #$viewport!: HTMLElement;
25
- #$items!: NodeList;
26
- #$list!: HTMLElement;
27
- #isDragging!: boolean;
28
- #itemMap!: Map<HTMLElement, FLib.DragSlider.Item>;
29
- #firstItem!: FLib.DragSlider.Item;
30
- #currentSnapItem!: FLib.DragSlider.Item;
31
- #hasAlreadyBeenDragged!: boolean;
32
- #startDragCoords!: FLib.Events.Gesture.Coords;
33
- #isInitialized!: boolean;
23
+ #listDelta = 0;
24
+ #$viewport: HTMLElement | undefined;
25
+ #$items: NodeList | undefined;
26
+ #$list: HTMLElement | undefined;
27
+ #isDragging = false;
28
+ #itemMap = new Map<HTMLElement, FLib.DragSlider.Item>();
29
+ #firstItem: FLib.DragSlider.Item | undefined;
30
+ #currentSnapItem: FLib.DragSlider.Item | undefined;
31
+ #hasAlreadyBeenDragged = false;
32
+ #startDragCoords: FLib.Events.Gesture.Coords | undefined;
33
+ #isInitialized = false;
34
34
  #debouncedOnResize;
35
35
 
36
36
 
@@ -40,6 +40,7 @@ export default class DragSlider {
40
40
 
41
41
 
42
42
  constructor( $slider: HTMLElement, options: Partial<FLib.DragSlider.Options> ) {
43
+
43
44
  if ( !options.viewportSelector || !options.listSelector || !options.itemSelector || !options.dragClass ) {
44
45
  throw '[Drag Slider]: Missing at least one of viewportSelector, listSelector, itemSelector, dragClass';
45
46
  }
@@ -80,7 +81,10 @@ export default class DragSlider {
80
81
 
81
82
 
82
83
  #onResize = (): void => {
83
- this.#viewportInfo = offset( this.#$viewport );
84
+ if ( !this.#$items || !this.#$list ) {
85
+ return;
86
+ }
87
+ this.#viewportInfo = offset( this.#$viewport as HTMLElement );
84
88
  this.#siteOffset = parseInt( prop( (this.#$items[ 0 ] as HTMLElement), 'marginLeft' ), 10 );
85
89
  this.#listDelta = this.#viewportInfo.width - this.#$list.scrollWidth;
86
90
 
@@ -105,6 +109,8 @@ export default class DragSlider {
105
109
 
106
110
  this.#itemArray.length = 0;
107
111
 
112
+ const LAST_INDEX = this.#$items.length;
113
+
108
114
  this.#$items.forEach( ( $item: Node, index: number ) => {
109
115
  const $ITEM = $item as HTMLElement;
110
116
  const ITEM_OFFSET = offset( $ITEM, false, this.#$list );
@@ -112,7 +118,7 @@ export default class DragSlider {
112
118
  this.#itemArray.push({
113
119
  index,
114
120
  "isFirst": index === 0,
115
- "isLast": index === this.#$items.length - 1 || ITEM_OFFSET.left > Math.abs( this.#listDelta ),
121
+ "isLast": index === LAST_INDEX - 1 || ITEM_OFFSET.left > Math.abs( this.#listDelta ),
116
122
  "$item": $ITEM,
117
123
  "info": ITEM_OFFSET
118
124
  });
@@ -161,7 +167,7 @@ export default class DragSlider {
161
167
 
162
168
  this.#currentSnapItem = snapItem;
163
169
 
164
- const TWEEN = gsap.to( this.#$list, {
170
+ const TWEEN = gsap.to( this.#$list as HTMLElement, {
165
171
  "duration": 0.3,
166
172
  "x": finalX,
167
173
  "y": 0,
@@ -276,7 +282,7 @@ export default class DragSlider {
276
282
 
277
283
  const ABS_DELTA_X = Math.abs( this.#deltaMove.deltaX );
278
284
 
279
- if ( ABS_DELTA_X >= this.#options.swipeTresholdMin && ABS_DELTA_X < Math.min( this.#firstItem.info.width * this.#options.swipeTresholdSize, this.#options.swipeTresholdMin * 3 ) ) {
285
+ if ( ABS_DELTA_X >= this.#options.swipeTresholdMin && ABS_DELTA_X < Math.min( (this.#firstItem as FLib.DragSlider.Item ).info.width * this.#options.swipeTresholdSize, this.#options.swipeTresholdMin * 3 ) ) {
280
286
  if ( this.#deltaMove.deltaX < 0 ) {
281
287
  snapItem = this.#getFirstNextItem( this.#deltaMove.x );
282
288
  }
@@ -302,7 +308,7 @@ export default class DragSlider {
302
308
  this.#hasAlreadyBeenDragged = true;
303
309
  }
304
310
 
305
- if ( !this.#isDraggingActive ) {
311
+ if ( !this.#isDraggingActive || !this.#$list ) {
306
312
  return;
307
313
  }
308
314
 
@@ -339,8 +345,8 @@ export default class DragSlider {
339
345
  #onMove = ( e: Event, $target: HTMLElement, coords: FLib.Events.Gesture.Coords ): void => {
340
346
  this.#cancelLinkClick();
341
347
 
342
- this.#deltaMove.deltaX = coords.pageX - this.#startDragCoords.pageX;
343
- this.#deltaMove.deltaY = coords.pageY - this.#startDragCoords.pageY;
348
+ this.#deltaMove.deltaX = coords.pageX - ( this.#startDragCoords as FLib.Events.Gesture.Coords ).pageX;
349
+ this.#deltaMove.deltaY = coords.pageY - ( this.#startDragCoords as FLib.Events.Gesture.Coords ).pageY;
344
350
 
345
351
  this.#deltaMove.newX = this.#deltaMove.deltaX + this.#deltaMove.x;
346
352
 
@@ -351,7 +357,7 @@ export default class DragSlider {
351
357
  this.#deltaMove.newX = this.#listDelta;
352
358
  }
353
359
 
354
- gsap.set( this.#$list, {
360
+ gsap.set( this.#$list as HTMLElement, {
355
361
  "x": this.#deltaMove.newX,
356
362
  "y": 0,
357
363
  "z": 0
@@ -424,20 +430,20 @@ export default class DragSlider {
424
430
 
425
431
 
426
432
  next(): gsap.core.Tween | void {
427
- if ( !this.#isDraggingActive || this.#currentSnapItem.isLast ) {
433
+ if ( !this.#isDraggingActive || ( this.#currentSnapItem as FLib.DragSlider.Item ).isLast ) {
428
434
  return;
429
435
  }
430
436
 
431
- return this.#snapToItemAnimation( this.#itemArray[ this.#currentSnapItem.index + 1 ] );
437
+ return this.#snapToItemAnimation( this.#itemArray[ ( this.#currentSnapItem as FLib.DragSlider.Item ).index + 1 ] );
432
438
  }
433
439
 
434
440
 
435
441
  previous(): gsap.core.Tween | void {
436
- if ( !this.#isDraggingActive || this.#currentSnapItem.isFirst ) {
442
+ if ( !this.#isDraggingActive || ( this.#currentSnapItem as FLib.DragSlider.Item ).isFirst ) {
437
443
  return;
438
444
  }
439
445
 
440
- return this.#snapToItemAnimation( this.#itemArray[ this.#currentSnapItem.index - 1 ] );
446
+ return this.#snapToItemAnimation( this.#itemArray[ ( this.#currentSnapItem as FLib.DragSlider.Item ).index - 1 ] );
441
447
  }
442
448
 
443
449
 
@@ -461,7 +467,7 @@ export default class DragSlider {
461
467
  "isAtEnd": this.#deltaMove.x === this.#listDelta
462
468
  } );
463
469
 
464
- return gsap.to( this.#$list, {
470
+ return gsap.to( this.#$list as HTMLElement, {
465
471
  "duration": 0.3,
466
472
  "x": -1 * ITEM.info.left + this.#siteOffset,
467
473
  "y": 0,
@@ -491,8 +497,6 @@ export default class DragSlider {
491
497
  this.#isInitialized = true;
492
498
 
493
499
  if ( !this.#$viewport ) {
494
- this.#itemMap = new Map();
495
-
496
500
  const $VP = this.#$slider.querySelector( this.#options.viewportSelector );
497
501
  if ( !$VP ) {
498
502
  throw `"${ this.#options.viewportSelector }" not found`;
@@ -514,7 +518,7 @@ export default class DragSlider {
514
518
  this.#debouncedOnResize = debounce( this.#onResize );
515
519
  }
516
520
 
517
- if ( !this.#$items.length ) {
521
+ if ( !this.#$items?.length ) {
518
522
  return this;
519
523
  }
520
524
 
@@ -563,7 +567,7 @@ export default class DragSlider {
563
567
  this.#isInitialized = false;
564
568
  this.#hasAlreadyBeenDragged = false;
565
569
 
566
- if ( !this.#$items.length ) {
570
+ if ( !this.#$items?.length ) {
567
571
  return this;
568
572
  }
569
573
 
@@ -572,7 +576,7 @@ export default class DragSlider {
572
576
  "callback": this.#debouncedOnResize
573
577
  } );
574
578
 
575
- gestureOff( this.#$viewport, 'dragSlider' );
579
+ this.#$viewport && gestureOff( this.#$viewport, 'dragSlider' );
576
580
 
577
581
  gestureOff( document.body, 'dragSlider' );
578
582
 
@@ -591,14 +595,15 @@ export default class DragSlider {
591
595
  "callback": this.#onMouseleave
592
596
  } );
593
597
 
598
+ if ( this.#$list ) {
599
+ gsap.killTweensOf( this.#$list );
594
600
 
595
- gsap.killTweensOf( this.#$list );
596
-
597
- gsap.set( this.#$list, {
598
- "clearProps": "all"
599
- } );
601
+ gsap.set( this.#$list, {
602
+ "clearProps": "all"
603
+ } );
604
+ }
600
605
 
601
- rClass( this.#$viewport, this.#options.dragClass );
606
+ this.#$viewport && rClass( this.#$viewport, this.#options.dragClass );
602
607
 
603
608
  rClass( this.#$slider, 'is-active' );
604
609
 
@@ -4,7 +4,7 @@ import Popin from './Popin';
4
4
  import { CLICK_EVENT_NAME } from './Tools';
5
5
 
6
6
 
7
- export default class PopinBackground {
7
+ export default class PopinBackground implements FLib.Popin.Background {
8
8
 
9
9
  #$bgLayer: HTMLElement;
10
10
  #isOpened: boolean;
@@ -14,7 +14,7 @@ import { CLICK_EVENT_NAME, defaultOptions, toggleTabIndex } from './Tools';
14
14
  * let controller = new PopinController( popinOptions );
15
15
  * popin.loadForm( $form );
16
16
  */
17
- export default class PopinController {
17
+ export default class PopinController implements FLib.Popin.Controller {
18
18
  #options: FLib.Popin.Options;
19
19
  #selectors: FLib.Popin.SelectorsOptions;
20
20
  #background: PopinBackground;
@@ -35,12 +35,12 @@ function getPosition( start, end, elapsed, duration ) {
35
35
 
36
36
 
37
37
  class ScrollTo {
38
- #startTime!: number;
38
+ #startTime: number | undefined;
39
39
  #animationFrame;
40
- #duration!: number;
41
- #startPosition!: number;
42
- #snapItem!: FLib.ScrollSnap.Item;
43
- #snapItemType!: FLib.ScrollSnap.SnapType;
40
+ #duration: number | undefined;
41
+ #startPosition: number | undefined;
42
+ #snapItem: FLib.ScrollSnap.Item | undefined;
43
+ #snapItemType: FLib.ScrollSnap.SnapType | undefined;
44
44
  #scrollPropName: FLib.ScrollSnap.ScrollPropertyType;
45
45
  #$element: HTMLElement;
46
46
  #callback: FLib.ScrollSnap.ScrollToCallback;
@@ -54,6 +54,10 @@ class ScrollTo {
54
54
 
55
55
 
56
56
  #step = ( timestamp: number ) => {
57
+ if ( !this.#snapItem ) {
58
+ return;
59
+ }
60
+
57
61
  if ( !this.#startTime ) {
58
62
  this.#startTime = timestamp;
59
63
  }
@@ -69,13 +73,13 @@ class ScrollTo {
69
73
  );
70
74
  }
71
75
 
72
- if ( elapsed < this.#duration ) {
76
+ if ( elapsed < (this.#duration as number) ) {
73
77
  this.#animationFrame = window.requestAnimationFrame( this.#step.bind( this ) );
74
78
  }
75
79
  else {
76
80
  if ( typeof this.#callback === 'function' ) {
77
81
  window.requestAnimationFrame( () => {
78
- this.#callback( this.#snapItem, this.#snapItemType );
82
+ this.#callback( this.#snapItem as FLib.ScrollSnap.Item, this.#snapItemType as FLib.ScrollSnap.SnapType );
79
83
  } );
80
84
  }
81
85
  }
@@ -98,7 +102,7 @@ class ScrollTo {
98
102
  if ( !delta ) {
99
103
  if ( typeof this.#callback === 'function' ) {
100
104
  window.requestAnimationFrame( () => {
101
- this.#callback( this.#snapItem, this.#snapItemType );
105
+ this.#callback( this.#snapItem as FLib.ScrollSnap.Item, this.#snapItemType as FLib.ScrollSnap.SnapType );
102
106
  } );
103
107
  }
104
108
  return;
@@ -14,7 +14,7 @@ const defaultOptions: FLib.SkinCheckbox.Options = {
14
14
  * Skin an HTML input checkbox element.
15
15
  * You can access the skin API in the __skinAPI property of the $checkbox HTMLElement or its wrapper.
16
16
  */
17
- export default class SkinCheckbox {
17
+ export default class SkinCheckbox implements FLib.SkinCheckbox.SkinCheckbox {
18
18
 
19
19
  #$checkbox!: FLib.SkinCheckbox.CustomCheckbox;
20
20
  #options!: FLib.SkinCheckbox.Options;
@@ -21,7 +21,7 @@ const defaultOptions: FLib.SkinFile.Options = {
21
21
  /**
22
22
  * Skin an HTML input file element.
23
23
  */
24
- export default class SkinFile {
24
+ export default class SkinFile implements FLib.SkinFile.SkinFile {
25
25
 
26
26
  #options: FLib.SkinFile.Options;
27
27
  #$parent: FLib.SkinFile.CustomInputFileParent;
@@ -26,7 +26,7 @@ const defaultOptions = {
26
26
  * } );
27
27
  * ```
28
28
  */
29
- export default class SkinRadioButton {
29
+ export default class SkinRadioButton implements FLib.SkinRadio.SkinRadio {
30
30
  #$radio!: FLib.SkinRadio.CustomRadioButton;
31
31
  #options!: FLib.SkinRadio.Options;
32
32
  #$parent!: FLib.SkinRadio.CustomRadioButtonParent;
@@ -37,27 +37,27 @@ const defaultOptions: FLib.SkinSelect.Options = {
37
37
  * Skin an HTML select element. If options.full is set to true, also skin the options list.
38
38
  * You can access the skin API in the __skinAPI property of the $select HTMLElement or its wrapper.
39
39
  */
40
- export default class SkinSelect {
41
- #$select: FLib.SkinSelect.CustomSelect;
42
- #loading!: boolean;
40
+ export default class SkinSelect implements FLib.SkinSelect.SkinSelect {
41
+ #$select!: FLib.SkinSelect.CustomSelect;
42
+ #loading = false;
43
43
  #options!: FLib.SkinSelect.Options;
44
44
  #extraClass!: string;
45
45
  #$parent!: FLib.SkinSelect.CustomSelectParent;
46
46
  #$title!: HTMLElement;
47
- #isListOpened!: boolean;
48
- #$options!: NodeList;
49
- #$lastOption!: HTMLElement | null;
50
- #focusedItemIndex!: number;
51
- #$layer!: HTMLElement;
47
+ #isListOpened = false;
48
+ #$options: NodeList | undefined;
49
+ #$lastOption: HTMLElement | null = null;
50
+ #focusedItemIndex = -1;
51
+ #$layer: HTMLElement | undefined;
52
52
 
53
- constructor( $select: HTMLSelectElement, userOptions?: Partial<FLib.SkinSelect.Options> ) {
53
+ constructor( $select: FLib.SkinSelect.CustomSelect, userOptions?: Partial<FLib.SkinSelect.Options> ) {
54
54
 
55
- this.#$select = $select;
56
-
57
- if ( this.#$select.hasAttribute( 'multiple' ) || this.#$select.__skinAPI ) {
55
+ if ( $select.hasAttribute( 'multiple' ) || $select.__skinAPI ) {
58
56
  return;
59
57
  }
60
58
 
59
+ this.#$select = $select;
60
+
61
61
  this.#loading = false;
62
62
 
63
63
  this.#options = extend( defaultOptions, userOptions );
@@ -420,6 +420,10 @@ export default class SkinSelect {
420
420
 
421
421
 
422
422
  #focusItem = ( index: number ): void => {
423
+ if ( !this.#$options ) {
424
+ return;
425
+ }
426
+
423
427
  if ( index < 0 ) {
424
428
  index = this.#$options.length - 1;
425
429
  }
@@ -4,7 +4,7 @@ import { on, off } from '../../Events/EventsManager';
4
4
  /**
5
5
  * Tab of a tabs list
6
6
  */
7
- export default class Tab {
7
+ export default class Tab implements FLib.Tabs.Tab {
8
8
 
9
9
  #options: FLib.Tabs.TabOptions;
10
10
  #$TAB: HTMLElement;
@@ -98,10 +98,10 @@ export default class Tabs {
98
98
  #options: FLib.Tabs.Options;
99
99
  #$TABS_LIST: HTMLElement;
100
100
  #$TABS: NodeList;
101
- #tablist: Tab[];
101
+ #tablist: FLib.Tabs.Tab[];
102
102
  #status: string;
103
103
  #VERTICAL_MODE: boolean;
104
- #lastOpenedTab: Tab | undefined;
104
+ #lastOpenedTab: FLib.Tabs.Tab | undefined;
105
105
  #keyboard: KeyboardHandler | undefined;
106
106
  #$tabsWrapper: HTMLElement;
107
107
 
@@ -124,7 +124,7 @@ export default class Tabs {
124
124
  }
125
125
 
126
126
 
127
- #onOpenTab = ( tab: Tab ): void => {
127
+ #onOpenTab = ( tab: FLib.Tabs.Tab ): void => {
128
128
  if ( this.#lastOpenedTab ) {
129
129
  this.#lastOpenedTab.close( true );
130
130
  }
@@ -8,7 +8,7 @@ import { getRadioList } from '../Tools/RadioButton';
8
8
  /*
9
9
  * Handle one input
10
10
  */
11
- export default class Input {
11
+ export default class Input implements FLib.Validator.Input {
12
12
  #isRadio: boolean;
13
13
  #inputType: string;
14
14
  #inputId: string;
@@ -123,7 +123,7 @@ export default class Input {
123
123
 
124
124
  if ( this.#hasValidator && options.hasLiveValidation && this.#inputType !== 'hidden' ) {
125
125
  on( this.#isRadio ? this.#$group : $input, {
126
- "eventsName": options.liveValidation?.eventsName[ this.#inputType ],
126
+ "eventsName": options.liveValidation?.eventsName?.[ this.#inputType ] as string,
127
127
  "callback": this.#onLiveValidation
128
128
  } );
129
129
  }
@@ -194,7 +194,7 @@ export default class Input {
194
194
  if ( !validator.isValid() ) {
195
195
  this.#validatorsInErrors.push( validator );
196
196
  }
197
- })
197
+ });
198
198
 
199
199
  return this.#validatorsInErrors;
200
200
  }
@@ -250,9 +250,7 @@ export default class Input {
250
250
  * Return an array of error messages and labels
251
251
  */
252
252
  getErrorMessages( _locale?: { [ key: string ]: string } ): { message: string, label: string, type: string }[] {
253
- if ( !this.#validatorsInErrors ) {
254
- this.getErrors();
255
- }
253
+ this.getErrors();
256
254
 
257
255
  if ( !this.#validatorsInErrors.length ) {
258
256
  return [];
@@ -299,9 +297,7 @@ export default class Input {
299
297
  * Get custom data of all validators
300
298
  */
301
299
  getData(): any[] {
302
- if ( !this.#validatorsInErrors ) {
303
- this.getErrors();
304
- }
300
+ this.getErrors();
305
301
 
306
302
  if ( !this.#validatorsInErrors.length ) {
307
303
  return [];
@@ -5,7 +5,7 @@ import { getValue } from '../../../Helpers/GetValue';
5
5
  * Used to make one validation on one input
6
6
  * Store the state (valid or not) between validations
7
7
  */
8
- export default class InputValidator {
8
+ export default class InputValidator implements FLib.Validator.InputValidator {
9
9
  #$input: HTMLElement;
10
10
  #name: string;
11
11
  #isAsynch: boolean;
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 7.1.0
3
+ @version: 7.1.4
4
4
 
5
5
 
6
6
  ## Use
@@ -1,6 +1,11 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace Accordion {
3
3
 
4
+ interface Tab {
5
+ close( autoClose?: boolean ): this;
6
+ destroy(): this;
7
+ }
8
+
4
9
  type AnimationFunction = ( $tab: HTMLElement, $panel: HTMLElement ) => Promise<void>;
5
10
  type Callback = ( $tab: HTMLElement, $panel: HTMLElement ) => void;
6
11
  type CloseCallback = ( $tab: HTMLElement, $panel: HTMLElement, autoclose: boolean ) => void;
@@ -21,7 +26,7 @@ namespace FLib {
21
26
  onOpenAtStart: Callback;
22
27
  onOpen: Callback;
23
28
  onClose: CloseCallback;
24
- animations: AnimationOptions;
29
+ animations: Partial<AnimationOptions>;
25
30
  }
26
31
 
27
32
  interface OptionsInit extends Partial<Options> {
@@ -29,7 +34,7 @@ namespace FLib {
29
34
  }
30
35
 
31
36
  interface TabOptions extends Options {
32
- onOpenTab: (( tab: Tab ) => void) | null;
37
+ onOpenTab?: ( tab: Tab ) => void;
33
38
  index: number;
34
39
  }
35
40
  }
@@ -1,9 +1,8 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace Autocomplete {
3
3
  type Item = {
4
4
  name: string;
5
- [ key: string ]: any;
6
- }
5
+ } & Record<string, any>
7
6
 
8
7
  type LayerPosition = 'top' | 'bottom';
9
8
 
package/Types/DOM.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace DOM {
3
3
  type ClassInput = Element | Element[] | Node | NodeList;
4
4
 
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace DragSlider {
3
3
  type CallbackParam = {
4
4
  item: any;
@@ -13,7 +13,7 @@ namespace FLib {
13
13
  isFirst: boolean;
14
14
  isLast: boolean;
15
15
  $item: HTMLElement;
16
- info: OffsetType;
16
+ info: FLib.DOM.Offset;
17
17
  }
18
18
 
19
19
  type DeltaMove = {
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace Events {
3
3
 
4
4
  /**
@@ -26,7 +26,7 @@ namespace FLib {
26
26
  interface DataRegistry {
27
27
  $element: Element;
28
28
  eventName: string;
29
- options: OnOptionsType;
29
+ options: OnOptions;
30
30
  delegate?: ( e ) => void;
31
31
  }
32
32
 
@@ -156,7 +156,7 @@ namespace FLib {
156
156
  /** click */
157
157
  click?: Callback;
158
158
  /** touchend on touch device, click on other */
159
- tap?: (( e: Event, $target: HTMLElement, coords: CoordsType, type: string ) => void);
159
+ tap?: (( e: Event, $target: HTMLElement, coords: Coords, type: string ) => void);
160
160
  swipeLeft?: SwipeCallback;
161
161
  swipeRight?: SwipeCallback;
162
162
  swipeUp?: SwipeCallback;
@@ -179,12 +179,12 @@ namespace FLib {
179
179
  */
180
180
  namespace History {
181
181
  type StateObject = {
182
- url: UrlParser;
182
+ url: URL;
183
183
  state: any;
184
184
  title: string;
185
185
  }
186
186
 
187
- type Callback = ( url: UrlParser, state: any ) => void;
187
+ type Callback = ( url: URL, state: any ) => void;
188
188
  }
189
189
 
190
190
 
@@ -378,10 +378,10 @@ namespace FLib {
378
378
 
379
379
 
380
380
  type CallbackParam = {
381
- windowInfo: WindowInfoType,
382
- scrollInfo: ScrollInfoType,
383
- documentInfo: DocumentInfoType,
384
- viewportInfo: ViewportInfoType
381
+ windowInfo: WindowInfo,
382
+ scrollInfo: ScrollInfo,
383
+ documentInfo: DocumentInfo,
384
+ viewportInfo: ViewportInfo
385
385
  }
386
386
 
387
387
  type Callback = ( info: CallbackParam, type: Type, e? ) => void;
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace GLImageTransition {
3
3
  type FitType = 'cover' | 'contains';
4
4
 
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace GlobalState {
3
3
  type Options = {
4
4
  alwaysDispatch: boolean;
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace Helpers {
3
3
  namespace Color {
4
4
  type RenderType = 'obj' | 'hex' | 'rgba';
@@ -26,5 +26,38 @@ namespace FLib {
26
26
  path: string;
27
27
  }
28
28
  }
29
+
30
+ interface UrlParser {
31
+ absolute: string;
32
+ absolute2: string;
33
+ anchor: string;
34
+ authority: string;
35
+ directory: string;
36
+ file: string;
37
+ full: string;
38
+ full2: string;
39
+ host: string;
40
+ location;
41
+ password: string;
42
+ path: string;
43
+ port: string;
44
+ protocol: string;
45
+ query: string;
46
+ queryKey: Record<string, string>;
47
+ relative: string;
48
+ relative2: string;
49
+ source: string;
50
+ user: string;
51
+ userInfo: string;
52
+ isAnchor: boolean;
53
+ isSameDomain: boolean;
54
+
55
+ init( url: string ): void;
56
+ setAnchor( anchor: string ): this;
57
+ getParam( key: string ): string;
58
+ setParam( keys: string | Record<string, string>, value?: string ): this;
59
+ removeParam( keys: string | string[] ): this
60
+ removeAll(): this;
61
+ }
29
62
  }
30
63
  }
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace Notifications {
3
3
  type Type = 'info' | 'success' | 'warning' | 'danger';
4
4
 
@@ -38,8 +38,8 @@ namespace FLib {
38
38
  info: string;
39
39
  };
40
40
  animations: {
41
- show: ( $notification, options ) => Promise
42
- hide: ( $notification, options ) => Promise
41
+ show: ( $notification, options ) => Promise<any>
42
+ hide: ( $notification, options ) => Promise<any>
43
43
  };
44
44
  }
45
45
 
package/Types/Popin.d.ts CHANGED
@@ -1,8 +1,26 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace Popin {
3
3
  type AnimationFunction = ( $element: HTMLElement ) => Promise<void>;
4
4
  type ResponseType = 'arrayBuffer' | 'blob' | 'json' | 'text' | 'formData';
5
5
 
6
+ interface Controller {
7
+ load( url: string, data: RequestInit, type?: FLib.Popin.ResponseType ): Promise<void>
8
+ loadForm( $form: HTMLFormElement ): Promise<void>
9
+ loadLink( $link: HTMLAnchorElement ): Promise<void>
10
+ set( html: string, openFirst?: boolean ): Promise<void>
11
+ clear(): void;
12
+ close(): Promise<void>;
13
+ open(): Promise<void>;
14
+ destroy(): this;
15
+ }
16
+
17
+ interface Background {
18
+ isOpened: boolean;
19
+ open(): Promise<any>;
20
+ close(): Promise<any>;
21
+ destroy(): void;
22
+ }
23
+
6
24
  interface TemplatesOptions {
7
25
  /** @defaultValue `<div class="popin-loader"></div>` */
8
26
  popinLoader: string;
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace ScrollSnap {
3
3
  type SnapType = 'scroll' | 'api';
4
4
 
@@ -1,5 +1,14 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace SkinCheckbox {
3
+ interface SkinCheckbox {
4
+ check(): this;
5
+ uncheck(): this;
6
+ enable(): this;
7
+ disable(): this;
8
+ setInvalid(): this;
9
+ setValid(): this;
10
+ }
11
+
3
12
  type Options = {
4
13
  /** @defaultValue <span class="cb-skin"></span> */
5
14
  wrap: string;
@@ -1,5 +1,12 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace SkinFile {
3
+ interface SkinFile {
4
+ enable(): this;
5
+ disable(): this;
6
+ setInvalid(): this;
7
+ setValid(): this;
8
+ }
9
+
3
10
  type Options = {
4
11
  /** @defaultValue .file-skin */
5
12
  selector: string;
@@ -1,5 +1,14 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace SkinRadio {
3
+ interface SkinRadio {
4
+ check(): this;
5
+ uncheck(): this;
6
+ enable(): this;
7
+ disable(): this;
8
+ setInvalid(): this;
9
+ setValid(): this;
10
+ }
11
+
3
12
  type Options = {
4
13
  /** @defaultValue <span class="rb-skin"></span> */
5
14
  wrap: string;
@@ -1,5 +1,18 @@
1
- namespace FLib {
1
+ declare declare namespace FLib {
2
2
  namespace SkinSelect {
3
+ interface SkinSelect {
4
+ enable(): this;
5
+ disable(): this;
6
+ setInvalid(): this;
7
+ setValid(): this;
8
+ setLoading(): this
9
+ unsetLoading(): this
10
+ updateTitle(): this
11
+ select( optionOrIndex: HTMLElement | number ): this
12
+ updateOptions( optionsArray?: FLib.SkinSelect.OptionArray[] ): this
13
+ }
14
+
15
+
3
16
  type Options = {
4
17
  /**
5
18
  * If true, skin event the option list
package/Types/Slider.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace Slider {
3
3
  type SlideDirection = -1 | 1;
4
4
 
package/Types/Tabs.d.ts CHANGED
@@ -1,25 +1,32 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace Tabs {
3
3
  type AnimationFunction = ( $tab: HTMLElement, $panel: HTMLElement ) => Promise<void>;
4
4
  type Callback = ( $tab: HTMLElement, $panel: HTMLElement, autoClose?: boolean ) => void;
5
5
 
6
+ interface Tab {
7
+ isOpened: boolean;
8
+ index: number;
9
+ close( autoClose?: boolean ): this;
10
+ open( autoOpen?: boolean ): this;
11
+ destroy(): this;
12
+ }
6
13
 
7
14
  type Options = {
8
15
  /** @defaultValue 'li[aria-selected]' */
9
16
  tabSelector: string;
10
- onOpenAtStart?: TabsCallbackType;
11
- onOpen?: TabsCallbackType;
12
- onClose?: TabsCallbackType;
17
+ onOpenAtStart?: Callback;
18
+ onOpen?: Callback;
19
+ onClose?: Callback;
13
20
  animations: {
14
- open: TabsAnimationFunctionType;
15
- close: TabsAnimationFunctionType;
16
- destroy: TabsAnimationFunctionType;
21
+ open: AnimationFunction;
22
+ close: AnimationFunction;
23
+ destroy: AnimationFunction;
17
24
  }
18
25
  }
19
26
 
20
27
 
21
28
  type TabOptions = Options & {
22
- onOpenTab: (( tab: Tab ) => void) | null;
29
+ onOpenTab?: ( tab: Tab ) => void;
23
30
  index: number;
24
31
  }
25
32
  }
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace Validator {
3
3
  type ValidationState = {
4
4
  $input: HTMLElement;
@@ -18,6 +18,33 @@ namespace FLib {
18
18
  validate: ValidateFunction;
19
19
  }
20
20
 
21
+ interface InputValidator {
22
+ $input: HTMLElement;
23
+ name: string;
24
+ isAsynch: boolean;
25
+ extraMessages: string[];
26
+ extraErrorMessages: string[];
27
+ data: any;
28
+ validate( isLiveValidation: boolean ): Promise<void>;
29
+ isValid(): boolean;
30
+ getData(): any;
31
+ }
32
+
33
+ interface Input {
34
+ $input: HTMLElement;
35
+ $label: HTMLElement | undefined;
36
+ hasError: boolean;
37
+ isLiveValidation: boolean;
38
+ $radioGroup: CustomValidatorRadioInput[] | undefined;
39
+ $otherRadioOfGroup: CustomValidatorRadioInput[];
40
+ hasValidator: boolean;
41
+ getErrors(): InputValidator[];
42
+ getErrorMessages( _locale?: { [ key: string ]: string } ): { message: string, label: string, type: string }[];
43
+ isValid(): Promise<void>;
44
+ getData(): any[];
45
+ destroy(): this
46
+ }
47
+
21
48
 
22
49
  type ValidateFunction = ( $input: HTMLElement, value: string | string[], isLiveValidation: boolean, validatorOptions ) => Promise<ValidationState>
23
50
 
@@ -50,15 +77,15 @@ namespace FLib {
50
77
  liveValidation?: {
51
78
  onValidate?: ( input: Input, event ) => void;
52
79
  onInvalidate?: ( input: Input, event ) => void;
53
- eventsName: {
80
+ eventsName?: {
54
81
  /** @defaultValue change */
55
- optin: string;
82
+ optin?: string;
56
83
  /** @defaultValue change */
57
- select: string;
84
+ select?: string;
58
85
  /** @defaultValue input */
59
- inputText: string;
60
- }
61
- eventsHook
86
+ inputText?: string;
87
+ };
88
+ eventsHook?;
62
89
  }
63
90
  }
64
91
 
@@ -1,4 +1,4 @@
1
- namespace FLib {
1
+ declare namespace FLib {
2
2
  namespace YouTubePlayer {
3
3
  type Options = {
4
4
  height: number;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@creative-web-solution/front-library",
3
3
  "title": "Frontend library",
4
4
  "description": "Frontend functions and modules",
5
- "version": "7.1.0",
5
+ "version": "7.1.4",
6
6
  "homepage": "https://github.com/creative-web-solution/front-library",
7
7
  "author": "Creative Web Solution <contact@cws-studio.com> (https://www.cws-studio.com)",
8
8
  "keywords": [],