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

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 +29 -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 +12 -18
  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 +14 -23
  46. package/Helpers/Wait.ts +1 -1
  47. package/Modules/Accordion/Tab.ts +19 -17
  48. package/Modules/Accordion/index.ts +27 -19
  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 +12 -12
  58. package/Modules/Popin/PopinController.ts +24 -30
  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 +52 -38
  63. package/Modules/SkinFile.ts +63 -53
  64. package/Modules/SkinRadio.ts +63 -43
  65. package/Modules/SkinSelect.ts +117 -101
  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 +28 -24
  70. package/Modules/Tabs/index.ts +36 -26
  71. package/Modules/Validator/Date.ts +2 -1
  72. package/Modules/Validator/Equals.ts +1 -1
  73. package/Modules/Validator/Internal/Input.ts +366 -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 +41 -0
  97. package/Types/Autocomplete.d.ts +94 -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 +63 -0
  104. package/Types/Notifications.d.ts +48 -44
  105. package/Types/Popin.d.ts +113 -0
  106. package/Types/ScrollSnap.d.ts +66 -0
  107. package/Types/SkinCheckbox.d.ts +35 -0
  108. package/Types/SkinFile.d.ts +45 -0
  109. package/Types/SkinRadio.d.ts +37 -0
  110. package/Types/SkinSelect.d.ts +72 -0
  111. package/Types/Slider.d.ts +106 -0
  112. package/Types/Tabs.d.ts +33 -0
  113. package/Types/Validator.d.ts +99 -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
@@ -8,18 +8,26 @@ import { addValidator } from './index';
8
8
  * data-servercheck-method="get|post"
9
9
  *
10
10
  * Return JSON format:
11
+ *
12
+ * @example
13
+ * ```json
11
14
  * {
12
- * "isValid": true|false
15
+ * "isValid": true|false
13
16
  * }
17
+ * ```
14
18
  *
15
19
  * Validator parameters:
20
+ *
21
+ * @example
22
+ * ```json
16
23
  * {
17
- * "beforeCall": function( $input, value ),
18
- * "afterCall": function( $input, value ),
19
- * "normalize": fuction( response ){ return { "isValid": true|false } },
20
- * "onFail": function( $input, value ),
21
- * "allowLiveValidation": true|false,
24
+ * "beforeCall": function( $input, value ),
25
+ * "afterCall": function( $input, value ),
26
+ * "normalize": fuction( response ){ return { "isValid": true|false } },
27
+ * "onFail": function( $input, value ),
28
+ * "allowLiveValidation": true|false,
22
29
  * }
30
+ * ```
23
31
  */
24
32
  addValidator(
25
33
  'servercheck',
@@ -27,10 +35,10 @@ addValidator(
27
35
  true,
28
36
  ( $input, value, isLiveValidation, options = {} ) => {
29
37
 
30
- return new Promise<ValidatorValidationState>( resolve => {
31
- let paramName, url, method, data, myHeaders;
38
+ return new Promise<FLib.Validator.ValidationState>( resolve => {
39
+ let url, method;
32
40
 
33
- let { beforeCall, afterCall, normalize, onFail } = options;
41
+ const { beforeCall, afterCall, normalize, onFail } = options;
34
42
 
35
43
  if ( !( "AbortController" in window ) ) {
36
44
  throw 'This plugin uses fecth and AbortController. You may need to add a polyfill for this browser.';
@@ -47,19 +55,19 @@ addValidator(
47
55
  } );
48
56
  }
49
57
 
50
- paramName = $input.getAttribute( 'name' );
58
+ const paramName = $input.getAttribute( 'name' );
51
59
  url = $input.getAttribute( 'data-servercheck' );
52
60
  method = $input.getAttribute( 'data-servercheck-method' ) || 'GET';
53
61
  method = method.toUpperCase();
54
62
 
55
- data = `${ paramName }=${ value }`;
63
+ const data = `${ paramName }=${ value }`;
56
64
 
57
65
  if ( method === 'GET' ) {
58
66
  url = [ url, url.indexOf('?') > -1 ? '&' : '?', data ].join( '' );
59
67
  }
60
68
 
61
69
  // Helper to create state
62
- function state( isValid ): ValidatorValidationState {
70
+ function state( isValid ): FLib.Validator.ValidationState {
63
71
  return {
64
72
  $input,
65
73
  value,
@@ -73,7 +81,7 @@ addValidator(
73
81
  beforeCall( $input, value );
74
82
  }
75
83
 
76
- myHeaders = new Headers();
84
+ const myHeaders = new Headers();
77
85
  myHeaders.append( 'X-Requested-With', 'XMLHttpRequest' );
78
86
 
79
87
  fetch(
@@ -89,9 +97,9 @@ addValidator(
89
97
  return response;
90
98
  }
91
99
  else {
92
- let error = new Error( response.statusText );
93
- /** @ts-expect-error */
100
+ const error: Error & { response? } = new Error( response.statusText );
94
101
  error.response = response;
102
+
95
103
  throw error;
96
104
  }
97
105
  } )
@@ -5,12 +5,7 @@ import { getValue } from '../../../Helpers/GetValue';
5
5
  * Create a query with the fields of a form.
6
6
  * Use a fallback for browser that doesn't support new URLSearchParams( formData ).toString()
7
7
  *
8
- * @function getQueryFromForm
9
- *
10
- * @param $form
11
- * @param [selector='select,input,textarea'] Only used for browser with no native new URLSearchParams( formData ).toString()
12
- *
13
- * @returns {String}
8
+ * @param selector - Only used for browser with no native new URLSearchParams( formData ).toString()
14
9
  */
15
10
  export default function getQueryFromForm( $form: HTMLFormElement, selector = 'select,input,textarea' ): string {
16
11
  let query;
@@ -1,12 +1,11 @@
1
1
  /**
2
2
  * Test if the value is a date
3
3
  *
4
- * @param value
5
- * @param [format="d/m/y"] d for day, m for month and y for year. Only in lowercase. January = 1
4
+ * @param format - d for day, m for month and y for year. Only in lowercase. January = 1
6
5
  *
7
6
  * @see extra/modules/validator.md for details
8
7
  */
9
- export default function isDate( value: string, format: string = 'd/m/y' ): boolean {
8
+ export default function isDate( value: string, format = 'd/m/y' ): boolean {
10
9
  const RE_SEPARATOR = ( /[^dmy]/ ).exec( format );
11
10
 
12
11
  if ( !RE_SEPARATOR ) {
@@ -1,13 +1,10 @@
1
1
  // Regular expression from Symfony
2
- const RE_EMAIL = /^[a-zA-Z0-9.!#$%&\'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/;
3
- const RE_EMAIL_LOOSE = /^.+\@\S+\.\S+$/;
2
+ const RE_EMAIL = /^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/;
3
+ const RE_EMAIL_LOOSE = /^.+@\S+\.\S+$/;
4
4
 
5
5
  /**
6
6
  * Test if the value is an email
7
7
  *
8
- * @param value
9
- * @param [loose]
10
- *
11
8
  * @see extra/modules/validator.md for details
12
9
  */
13
10
  export default function isEmail( value: string, loose?: boolean ): boolean {
@@ -3,8 +3,6 @@ const emptyRe = /(^$)|(^[\s]*$)/i;
3
3
  /**
4
4
  * Test if there is a value
5
5
  *
6
- * @param value
7
- *
8
6
  * @see extra/modules/validator.md for details
9
7
  */
10
8
  export default function isEmpty( value: string | string[] ): boolean {
@@ -3,8 +3,6 @@ const numRe = /^-?[0-9]*(\.[0-9]+)?$/;
3
3
  /**
4
4
  * Test if the value is a number
5
5
  *
6
- * @param value
7
- *
8
6
  * @see extra/modules/validator.md for details
9
7
  */
10
8
  export default function isNumber( value: string ): boolean {
@@ -1,10 +1,8 @@
1
- const urlRe = /^(https?:\/\/)?[\da-z\.\-]+\.[a-z\.]{2,6}[#&+_\?\/\w \.\-=]*$/i;
1
+ const urlRe = /^(https?:\/\/)?[\da-z.-]+\.[a-z.]{2,6}[#&+_?/\w .\-=]*$/i;
2
2
 
3
3
  /**
4
4
  * Test if the value is an url
5
5
  *
6
- * @param value
7
- *
8
6
  * @see extra/modules/validator.md for details
9
7
  */
10
8
  export default function isUrl( value: string ): boolean {
@@ -1,15 +1,10 @@
1
1
  /**
2
- * Get the label of an input
3
- *
4
- * @param $input
5
- * @param [$wrapper=document.body]
2
+ * Return the label, if there is only one, the list of labels if many or null if none
6
3
  *
7
4
  * @see extra/modules/validator.md for details
8
- *
9
- * @return Return the label, if there is only one, the list of labels if many or null if none
10
5
  */
11
6
  export function getLabelElement( $input: HTMLElement, $wrapper: HTMLElement = document.body ): HTMLElement | NodeList | null {
12
- let $labels = $wrapper.querySelectorAll( `label[for="${ $input.id }"]` );
7
+ const $labels = $wrapper.querySelectorAll( `label[for="${ $input.id }"]` );
13
8
 
14
9
  if ( !$labels.length ) {
15
10
  return null;
@@ -23,17 +18,12 @@ export function getLabelElement( $input: HTMLElement, $wrapper: HTMLElement = do
23
18
 
24
19
 
25
20
  /**
26
- * Get the text of a label's input
27
- *
28
- * @param $input
29
- * @param [$wrapper=document.body]
21
+ * Return the label, if there is only one, the list of labels if many or '' if none
30
22
  *
31
23
  * @see extra/modules/validator.md for details
32
- *
33
- * @return Return the label, if there is only one, the list of labels if many or '' if none
34
24
  */
35
25
  export function getLabel( $input: HTMLElement, $wrapper: HTMLElement = document.body ): string | string[] {
36
- let $labels = getLabelElement( $input, $wrapper );
26
+ const $labels = getLabelElement( $input, $wrapper );
37
27
 
38
28
  if ( !$labels ) {
39
29
  return '';
@@ -42,5 +32,5 @@ export function getLabel( $input: HTMLElement, $wrapper: HTMLElement = document.
42
32
  return Array.from( $labels ).map( $label => $label.textContent || '' );
43
33
  }
44
34
 
45
- return $labels.textContent || '';
35
+ return $labels.textContent || '';
46
36
  }
@@ -3,10 +3,8 @@ import { extend } from '../../../Helpers/Extend';
3
3
  /**
4
4
  * Get all radio with the same name
5
5
  *
6
- * @param inputRadioOrInputName
7
- * @param userOptions
8
- * @param [userOptions.selector=input[name="{NAME}"]] - css selector of the elements with a {GROUP_NAME} tag that will be replace by groupName var.
9
- * @param [userOptions.othersOnly=false] - if true, return the list without the element in `inputRadioOrInputName`. If `inputRadioOrInputName` is a string (input name), return all radio
6
+ * @param selector - css selector of the elements with a `{`GROUP_NAME`}` tag that will be replace by groupName var.
7
+ * @param othersOnly - if true, return the list without the element in `inputRadioOrInputName`. If `inputRadioOrInputName` is a string (input name), return all radio
10
8
  *
11
9
  * @see extra/modules/validator.md for details
12
10
  *
@@ -54,16 +52,12 @@ export function getRadioList( inputRadioOrInputName: HTMLElement | string, userO
54
52
 
55
53
 
56
54
  /**
57
- * Get the selected radio button from a list.
58
- *
59
- * @param $iputRadioOrRadioList
55
+ * Return the selected radio button from a group or false
60
56
  *
61
57
  * @see extra/modules/validator.md for details
62
- *
63
- * @return Return the selected radio button from a group or false
64
58
  */
65
59
  export function isRadioListChecked( $iputRadioOrRadioList: HTMLElement[] | HTMLElement | NodeList ): false | HTMLInputElement {
66
- let $list = ( $iputRadioOrRadioList instanceof NodeList || $iputRadioOrRadioList instanceof Array ) ? $iputRadioOrRadioList : getRadioList( $iputRadioOrRadioList );
60
+ const $list = ( $iputRadioOrRadioList instanceof NodeList || $iputRadioOrRadioList instanceof Array ) ? $iputRadioOrRadioList : getRadioList( $iputRadioOrRadioList );
67
61
 
68
62
  for ( const $item of Array.from( $list ) ) {
69
63
  if ( ($item as HTMLInputElement).checked ) {
@@ -1,6 +1,7 @@
1
1
  import isUrl from './Tools/IsUrl';
2
2
  import { addValidator } from './index';
3
3
 
4
+
4
5
  /**
5
6
  * URL validation
6
7
  */
@@ -33,6 +33,7 @@ const defaultOptions = {
33
33
  * @see extra/modules/validator.md for details
34
34
  *
35
35
  * @example
36
+ * ```ts
36
37
  * let validator = new Validator( $form, options )
37
38
  *
38
39
  * on( $form, {
@@ -56,21 +57,22 @@ const defaultOptions = {
56
57
  * );
57
58
  * }
58
59
  * });
60
+ * ```
59
61
  */
60
62
  export default class Validator {
61
- #options: ValidatorOptionsType & { hasLiveValidation: boolean };
63
+ #options: FLib.Validator.Options & { hasLiveValidation: boolean };
62
64
  #inputsList: Input[];
63
- #radioDuplicateHash: { [ key: string ]: boolean };
65
+ #radioDuplicateHash: Record<string, boolean>;
64
66
  #state: string;
65
67
  #$form: HTMLElement;
66
- #validationPromise!: Promise<ValidatorValidationReturnType> | null;
68
+ #validationPromise: Promise<FLib.Validator.ValidationReturnType> | undefined | null;
67
69
 
68
70
 
69
71
  #STATE_IDLE = 'idle';
70
72
  #STATE_VALIDATING = 'validating';
71
73
 
72
74
 
73
- constructor( $form: HTMLElement, userOptions: ValidatorOptionsType = {} ) {
75
+ constructor( $form: HTMLElement, userOptions: Partial<FLib.Validator.Options> = {} ) {
74
76
  this.#$form = $form;
75
77
  this.#options = extend( defaultOptions, userOptions );
76
78
  this.#options.hasLiveValidation = !!this.#options.liveValidation?.onValidate || !!this.#options.liveValidation?.onInvalidate;
@@ -81,13 +83,14 @@ export default class Validator {
81
83
 
82
84
  $form.setAttribute( 'novalidate', 'novalidate' );
83
85
 
84
- this.refresh();
86
+ this.#refresh();
85
87
  }
86
88
 
89
+
87
90
  /*
88
91
  * Filter radio button to validate only one button
89
92
  */
90
- private filterRadioButton( $input: HTMLInputElement ): boolean {
93
+ #filterRadioButton = ( $input: HTMLInputElement ): boolean => {
91
94
  if ( $input.type !== 'radio' ) {
92
95
  return true;
93
96
  }
@@ -105,7 +108,7 @@ export default class Validator {
105
108
  /*
106
109
  * Call the function cleanup of all inputs and empty the list
107
110
  */
108
- private cleanup() {
111
+ #cleanup = (): void => {
109
112
  this.#inputsList.forEach( input => input.destroy() );
110
113
  this.#inputsList.length = 0;
111
114
  this.#radioDuplicateHash = {};
@@ -115,9 +118,9 @@ export default class Validator {
115
118
  /*
116
119
  * Create and add one input to the list
117
120
  */
118
- private addInput( $input: Element ) {
121
+ #addInput = ( $input: HTMLElement ): void => {
119
122
  // Check if this input type
120
- if ( !$input.matches( this.#options.filter! ) && this.filterRadioButton( $input as HTMLInputElement ) ) {
123
+ if ( !$input.matches( this.#options.filter ) && this.#filterRadioButton( $input as HTMLInputElement ) ) {
121
124
  this.#inputsList.push( new Input( $input, this.#options ) );
122
125
  }
123
126
  }
@@ -126,20 +129,20 @@ export default class Validator {
126
129
  /*
127
130
  * Empty and clean the input list and recreate it
128
131
  */
129
- private refresh() {
130
- this.cleanup();
132
+ #refresh = (): void => {
133
+ this.#cleanup();
131
134
 
132
- const $fieldToAdd = this.#$form.querySelectorAll( this.#options.fields! );
135
+ const $fieldToAdd = this.#$form.querySelectorAll( this.#options.fields ) as NodeListOf<HTMLElement>;
133
136
 
134
- $fieldToAdd.forEach( this.addInput.bind( this ) );
137
+ $fieldToAdd.forEach( this.#addInput.bind( this ) );
135
138
  }
136
139
 
137
140
 
138
141
  /*
139
142
  * Validate all fields and return a promise
140
143
  */
141
- private _validate(): Promise<void[]> {
142
- let inputsValid: Promise<void>[] = [];
144
+ #_validate = (): Promise<void[]> => {
145
+ const inputsValid: Promise<void>[] = [];
143
146
 
144
147
  this.#inputsList.forEach( input => {
145
148
  inputsValid.push( input.isValid() );
@@ -149,7 +152,7 @@ export default class Validator {
149
152
  }
150
153
 
151
154
 
152
- private filterInputError( input: Input ): boolean {
155
+ #filterInputError = ( input: Input ): boolean => {
153
156
  return input.hasError;
154
157
  }
155
158
 
@@ -157,25 +160,25 @@ export default class Validator {
157
160
  /*
158
161
  * Call validation and call callback if needed
159
162
  */
160
- private process(): Promise<ValidatorValidationReturnType> {
163
+ #process = (): Promise<FLib.Validator.ValidationReturnType> => {
161
164
  if ( this.#validationPromise ) {
162
165
  return this.#validationPromise;
163
166
  }
164
- this.#validationPromise = new Promise<ValidatorValidationReturnType>( ( resolve, reject ) => {
167
+ this.#validationPromise = new Promise<FLib.Validator.ValidationReturnType>( ( resolve, reject ) => {
165
168
  this.#state = this.#STATE_VALIDATING;
166
169
 
167
- const retObject: ValidatorValidationReturnType = {
170
+ const retObject: FLib.Validator.ValidationReturnType = {
168
171
  "inputs": this.#inputsList,
169
172
  "errors": [],
170
173
  "$form": this.#$form
171
174
  };
172
175
 
173
- this._validate()
176
+ this.#_validate()
174
177
  .then( () => {
175
178
  this.#validationPromise = null;
176
179
  this.#state = this.#STATE_IDLE;
177
180
 
178
- const errors = this.#inputsList.filter( this.filterInputError );
181
+ const errors = this.#inputsList.filter( this.#filterInputError );
179
182
 
180
183
 
181
184
  if ( errors && errors.length ) {
@@ -212,27 +215,27 @@ export default class Validator {
212
215
  /**
213
216
  * Start the validation of all the form
214
217
  */
215
- validate(): Promise<ValidatorValidationReturnType> {
218
+ validate(): Promise<FLib.Validator.ValidationReturnType> {
216
219
  if ( this.#state !== this.#STATE_IDLE ) {
217
- return this.#validationPromise as Promise<ValidatorValidationReturnType>;
220
+ return this.#validationPromise as Promise<FLib.Validator.ValidationReturnType>;
218
221
  }
219
222
 
220
- return this.process();
223
+ return this.#process();
221
224
  }
222
225
 
223
226
 
224
227
  /**
225
228
  * Bind or rebind all inputs
226
229
  */
227
- update() {
228
- this.refresh();
230
+ update(): this {
231
+ this.#refresh();
232
+
233
+ return this
229
234
  }
230
235
 
231
236
 
232
237
  /**
233
238
  * Return the validator object of an input
234
- *
235
- * @param $field
236
239
  */
237
240
  getFieldValidator( $field: HTMLElement ): Input | void {
238
241
 
@@ -241,17 +244,14 @@ export default class Validator {
241
244
  return input;
242
245
  }
243
246
  }
244
-
245
247
  }
246
248
 
247
249
 
248
250
  /**
249
251
  * Validate one field
250
- *
251
- * @param $field
252
252
  */
253
- validateField( $field: HTMLElement ): Promise<ValidatorFieldValidationReturnType | void> {
254
- return new Promise<ValidatorFieldValidationReturnType | void>( ( resolve, reject ) => {
253
+ validateField( $field: HTMLElement ): Promise<FLib.Validator.FieldValidationReturnType | void> {
254
+ return new Promise<FLib.Validator.FieldValidationReturnType | void>( ( resolve, reject ) => {
255
255
  const input = this.getFieldValidator( $field );
256
256
 
257
257
  if ( !input ) {
@@ -260,7 +260,7 @@ export default class Validator {
260
260
 
261
261
  this.#state = this.#STATE_VALIDATING;
262
262
 
263
- const retObject: ValidatorFieldValidationReturnType = {
263
+ const retObject: FLib.Validator.FieldValidationReturnType = {
264
264
  "input": input,
265
265
  "error": null,
266
266
  "$form": this.#$form
@@ -293,7 +293,7 @@ export default class Validator {
293
293
  * @param onlyValidated - If true, remove all fields without validator
294
294
  */
295
295
  getAllFields( onlyValidated: boolean ): HTMLElement[] {
296
- let $fields: HTMLElement[] = [];
296
+ const $fields: HTMLElement[] = [];
297
297
 
298
298
  this.#inputsList.forEach( input => {
299
299
  if ( !onlyValidated || input.hasValidator ) {
@@ -325,7 +325,7 @@ export default class Validator {
325
325
  * Get all inputs (input objects, not DOM elements) with at least one validator
326
326
  */
327
327
  getCheckedInputs(): Input[] {
328
- let inputs: Input[] = [];
328
+ const inputs: Input[] = [];
329
329
 
330
330
  this.#inputsList.forEach( input => {
331
331
  if ( input.hasValidator ) {
@@ -4,7 +4,7 @@ import { extend } from '../Helpers/Extend';
4
4
  let ytAPILoadingPromise;
5
5
 
6
6
 
7
- const defaultOptions = {
7
+ const defaultOptions: Partial<FLib.YouTubePlayer.Options> = {
8
8
  "apiUrl": "//www.youtube.com/iframe_api",
9
9
  "playerVars": {
10
10
  "autoplay": 0,
@@ -22,13 +22,14 @@ const defaultOptions = {
22
22
  * @see extra/modules/youtube.md
23
23
  *
24
24
  * @example
25
+ * ```ts
25
26
  * let YouTubePlayer = new YouTubePlayer( {
26
27
  * "height": 1920,
27
28
  * "width": 1080,
28
29
  * "videoId": "youtube-video-id-here",
29
30
  * "$wrapper": $wrapper,
30
31
  * "apiUrl": "//www.youtube.com/iframe_api",
31
- * "onPlayerStateChange": ( newState ) => {
32
+ * "onPlayerStateChange": ( newState ) =&gt; {
32
33
  * if ( newState.data === YT.PlayerState.ENDED ) {
33
34
  * // Code here for video ended
34
35
  * }
@@ -44,14 +45,15 @@ const defaultOptions = {
44
45
  * }
45
46
  * );
46
47
  *
47
- * YouTubePlayer.load().then( ytPlayerInstance => {} );
48
+ * YouTubePlayer.load().then( ytPlayerInstance =&gt; {} );
49
+ * ```
48
50
  */
49
51
  export default class YouTubePlayer {
50
52
 
51
- #options: YouTubePlayerOptionsType;
53
+ #options: FLib.YouTubePlayer.Options;
52
54
 
53
55
 
54
- constructor( userOptions: YouTubePlayerOptionsType ) {
56
+ constructor( userOptions: Partial<FLib.YouTubePlayer.Options> ) {
55
57
  this.#options = extend( defaultOptions, userOptions );
56
58
 
57
59
  if ( !this.#options.$wrapper ) {
@@ -60,8 +62,8 @@ export default class YouTubePlayer {
60
62
  }
61
63
 
62
64
 
63
- private loadYouTubeAPI() {
64
- let tag, firstScriptTag, _resolve;
65
+ #loadYouTubeAPI = (): Promise<void> => {
66
+ let _resolve;
65
67
 
66
68
  if ( ytAPILoadingPromise ) {
67
69
  return ytAPILoadingPromise;
@@ -75,23 +77,23 @@ export default class YouTubePlayer {
75
77
  _resolve = resolve;
76
78
  } );
77
79
 
78
- (window as YouTubePlayerWindowType).onYouTubeIframeAPIReady = function() {
80
+ (window as FLib.YouTubePlayer.PlayerWindow).onYouTubeIframeAPIReady = function() {
79
81
  _resolve();
80
82
 
81
- (window as YouTubePlayerWindowType).onYouTubeIframeAPIReady = null;
83
+ (window as FLib.YouTubePlayer.PlayerWindow).onYouTubeIframeAPIReady = null;
82
84
  }
83
85
 
84
- tag = document.createElement( 'script' );
85
- tag.src = this.#options.apiUrl;
86
- firstScriptTag = document.getElementsByTagName( 'script' )[ 0 ];
86
+ const tag = document.createElement( 'script' );
87
+ tag.src = this.#options.apiUrl;
88
+ const firstScriptTag = document.getElementsByTagName( 'script' )[ 0 ] as HTMLScriptElement;
87
89
 
88
- firstScriptTag.parentNode.insertBefore( tag, firstScriptTag );
90
+ firstScriptTag.parentNode?.insertBefore( tag, firstScriptTag );
89
91
 
90
92
  return ytAPILoadingPromise;
91
93
  }
92
94
 
93
95
 
94
- private initPlayer( $wrapper: YouTubePlayerWrapper ) {
96
+ #initPlayer = ( $wrapper: FLib.YouTubePlayer.PlayerWrapper ): Promise<YT.Player> => {
95
97
  let _resolve;
96
98
 
97
99
  const promise = new Promise( function( resolve ) {
@@ -126,8 +128,8 @@ export default class YouTubePlayer {
126
128
  * @returns
127
129
  */
128
130
  load(): Promise<YT.Player> {
129
- return this.loadYouTubeAPI().then( () => {
130
- return this.initPlayer( this.#options.$wrapper as YouTubePlayerWrapper );
131
+ return this.#loadYouTubeAPI().then( () => {
132
+ return this.#initPlayer( this.#options.$wrapper as FLib.YouTubePlayer.PlayerWrapper );
131
133
  } );
132
134
  }
133
135
  }
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 7.0.7
3
+ @version: 7.1.3
4
4
 
5
5
 
6
6
  ## Use
@@ -0,0 +1,41 @@
1
+ declare namespace FLib {
2
+ namespace Accordion {
3
+
4
+ interface Tab {
5
+ close( autoClose?: boolean ): this;
6
+ destroy(): this;
7
+ }
8
+
9
+ type AnimationFunction = ( $tab: HTMLElement, $panel: HTMLElement ) => Promise<void>;
10
+ type Callback = ( $tab: HTMLElement, $panel: HTMLElement ) => void;
11
+ type CloseCallback = ( $tab: HTMLElement, $panel: HTMLElement, autoclose: boolean ) => void;
12
+
13
+ interface AnimationOptions {
14
+ open: AnimationFunction;
15
+ close: AnimationFunction;
16
+ destroy: AnimationFunction;
17
+ }
18
+
19
+ interface Options {
20
+ /** @defaultValue 'button[aria-expanded]' */
21
+ tabSelector: string;
22
+ /** @defaultValue false */
23
+ allowMultipleTab: boolean;
24
+ /** @defaultValue false */
25
+ atLeastOneOpen: boolean;
26
+ onOpenAtStart: Callback;
27
+ onOpen: Callback;
28
+ onClose: CloseCallback;
29
+ animations: Partial<AnimationOptions>;
30
+ }
31
+
32
+ interface OptionsInit extends Partial<Options> {
33
+ animations?: Partial<AnimationOptions>;
34
+ }
35
+
36
+ interface TabOptions extends Options {
37
+ onOpenTab?: ( tab: Tab ) => void;
38
+ index: number;
39
+ }
40
+ }
41
+ }