@creative-web-solution/front-library 7.1.33 → 7.1.35

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,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 7.1.35
4
+
5
+ * [Accordion]: Rework
6
+
7
+ ## 7.1.34
8
+
9
+ * [DragSlider]: Add new params to onChangeState callback
10
+
3
11
  ## 7.1.33
4
12
 
5
13
  * [DragSlider]: Update delta computing
@@ -1,17 +1,19 @@
1
- import { on, off } from '../../Events/EventsManager';
2
1
  import { next } from '../../DOM/Traversing';
3
2
 
4
3
 
5
4
  /**
6
5
  * Tab of an accordion
7
6
  */
8
- export default class Tab implements FLib.Accordion.Tab {
7
+ export default class Tab {
9
8
  #isOpen: boolean;
10
9
  #originalOpenedState: boolean;
11
10
  #$TAB_PANNEL: HTMLElement | null;
12
11
  #options;
13
12
  #$TAB;
14
13
 
14
+ get isOpen(): boolean {
15
+ return this.#isOpen;
16
+ }
15
17
 
16
18
  constructor( $TAB: HTMLElement, options: FLib.Accordion.TabOptions ) {
17
19
  this.#options = options;
@@ -22,10 +24,6 @@ export default class Tab implements FLib.Accordion.Tab {
22
24
 
23
25
  this.#isOpen = this.#originalOpenedState = $TAB.getAttribute( 'aria-expanded' ) === 'true';
24
26
 
25
- on( $TAB, {
26
- "eventsName": "click",
27
- "callback": this.#toggleTab
28
- } );
29
27
 
30
28
  if ( this.#isOpen ) {
31
29
  this.#openTab( true );
@@ -51,40 +49,28 @@ export default class Tab implements FLib.Accordion.Tab {
51
49
  }
52
50
  } );
53
51
 
54
- if ( this.#options.onOpenTab ) {
55
- this.#options.onOpenTab( this );
56
- }
57
52
  this.#isOpen = true;
58
53
  this.#changeTabState();
59
54
  }
60
55
 
61
-
62
56
  #closeTab = ( autoClose?: boolean ): void => {
63
57
  this.#options.animations
64
58
  .close( this.#$TAB, this.#$TAB_PANNEL )
65
59
  .then( () => {
66
- if ( this.#options.onClose ) {
67
- this.#options.onClose( this.#$TAB, this.#$TAB_PANNEL, autoClose );
68
- }
60
+ this.#options.onClose?.( this.#$TAB, this.#$TAB_PANNEL, autoClose );
69
61
  } );
70
62
 
71
63
  this.#isOpen = false;
72
64
  this.#changeTabState();
73
65
  }
74
66
 
75
-
76
- #toggleTab = ( e: Event ): void => {
77
- e.preventDefault();
78
-
79
- if( this.#isOpen && ( !this.#options.atLeastOneOpen || this.#options.allowMultipleTab ) ) {
80
- this.#closeTab();
81
- }
82
- else if( !this.#isOpen ) {
83
- this.#openTab();
67
+ open(): this {
68
+ if( !this.#isOpen ) {
69
+ this.#openTab( false );
84
70
  }
71
+ return this;
85
72
  }
86
73
 
87
-
88
74
  close( autoClose?: boolean ): this {
89
75
  if( this.#isOpen ) {
90
76
  this.#closeTab( autoClose );
@@ -97,11 +83,6 @@ export default class Tab implements FLib.Accordion.Tab {
97
83
  destroy(): this {
98
84
  this.#options.animations.destroy( this.#$TAB, this.#$TAB_PANNEL );
99
85
 
100
- off( this.#$TAB, {
101
- "eventsName": "click",
102
- "callback": this.#toggleTab
103
- } );
104
-
105
86
  this.#$TAB.setAttribute( 'aria-expanded', this.#originalOpenedState ? 'true' : 'false' );
106
87
 
107
88
  return this;
@@ -1,5 +1,6 @@
1
1
  import { aClass, rClass } from '../../DOM/Class';
2
2
  import { extend } from '../../Helpers/Extend';
3
+ import { on, off } from '../../Events/EventsManager';
3
4
  import Tab from './Tab';
4
5
 
5
6
 
@@ -84,11 +85,12 @@ const DEFAULT_OPTIONS = {
84
85
  * Set aria-expanded to "true" on the tab you want open at start
85
86
  */
86
87
  export default class Accordion {
88
+ #$accordionWrapper: HTMLElement;
87
89
  #options: FLib.Accordion.Options;
88
90
  #$tabs: NodeListOf<HTMLElement>;
89
- #tablist: FLib.Accordion.Tab[];
91
+ #tablist = new Map<HTMLElement, Tab>();
90
92
  #status: string;
91
- #lastOpenedTab: FLib.Accordion.Tab | null = null;
93
+ #lastOpenedTabs = new Set<Tab>();
92
94
 
93
95
 
94
96
  #STATUS_ON = 'STATUS_ON';
@@ -96,26 +98,16 @@ export default class Accordion {
96
98
 
97
99
 
98
100
  constructor( $accordionWrapper: HTMLElement, userOptions: FLib.Accordion.OptionsInit ) {
101
+ this.#$accordionWrapper = $accordionWrapper;
99
102
 
100
103
  this.#options = extend( DEFAULT_OPTIONS, userOptions );
101
104
 
102
105
  this.#$tabs = $accordionWrapper.querySelectorAll( this.#options.tabSelector );
103
- this.#tablist = [];
104
106
  this.#status = this.#STATUS_OFF;
105
107
 
106
108
  this.#on();
107
109
  }
108
110
 
109
-
110
- #onOpenTab = ( tab: FLib.Accordion.Tab ): void => {
111
- if ( this.#lastOpenedTab ) {
112
- this.#lastOpenedTab.close( true );
113
- }
114
-
115
- this.#lastOpenedTab = tab;
116
- }
117
-
118
-
119
111
  #on = (): void => {
120
112
  if( this.#status === this.#STATUS_ON ){
121
113
  return;
@@ -124,12 +116,17 @@ export default class Accordion {
124
116
  this.#status = this.#STATUS_ON;
125
117
 
126
118
  this.#$tabs.forEach( ( $tab, index ) => {
127
- this.#tablist.push( new Tab( $tab, {
119
+ this.#tablist.set($tab, new Tab( $tab, {
128
120
  ...this.#options,
129
121
  index,
130
- "onOpenTab": this.#options.allowMultipleTab ? undefined : this.#onOpenTab
131
122
  } ) );
132
123
  } );
124
+
125
+ on( this.#$accordionWrapper, {
126
+ "eventsName": "click",
127
+ "selector": this.#options.tabSelector,
128
+ "callback": this.#toggleTab
129
+ } );
133
130
  }
134
131
 
135
132
 
@@ -144,9 +141,65 @@ export default class Accordion {
144
141
  tab.destroy();
145
142
  } );
146
143
 
147
- this.#tablist.length = 0;
144
+ this.#tablist.clear();
145
+
146
+ off( this.#$accordionWrapper, {
147
+ "eventsName": "click",
148
+ "callback": this.#toggleTab
149
+ } );
148
150
  }
149
151
 
152
+ #toggleTab = ( e: Event, $target: HTMLElement ): void => {
153
+ e.preventDefault();
154
+
155
+ const tab = this.#tablist.get($target);
156
+
157
+ if (!tab) {
158
+ return;
159
+ }
160
+
161
+ if (tab.isOpen) {
162
+ this.closeTab(tab)
163
+ return;
164
+ }
165
+
166
+ this.openTab(tab)
167
+ }
168
+
169
+ closeTab(tab: Tab): this {
170
+ if (this.#options.atLeastOneOpen && this.#lastOpenedTabs.size < 2) {
171
+ return this;
172
+ }
173
+
174
+ tab.close(false);
175
+ this.#lastOpenedTabs.delete(tab);
176
+
177
+ return this;
178
+ }
179
+
180
+ openTab(tab: Tab): this {
181
+ if (!this.#options.allowMultipleTab && this.#lastOpenedTabs.size > 0) {
182
+ this.#lastOpenedTabs.forEach(tab => {
183
+ tab.close(true);
184
+ });
185
+ this.#lastOpenedTabs.clear();
186
+ }
187
+
188
+ tab.open();
189
+ this.#lastOpenedTabs.add(tab);
190
+
191
+ return this;
192
+ }
193
+
194
+ openTabByElement($tab: HTMLElement): this {
195
+ const tab = this.#tablist.get($tab);
196
+
197
+ if (tab) {
198
+ this.openTab(tab);
199
+ }
200
+
201
+ return this;
202
+ }
150
203
 
151
204
  /**
152
205
  * Remove all events, css class, ...
@@ -186,7 +186,7 @@ export default class DragSlider {
186
186
  );
187
187
 
188
188
  if (prevIsDraggingActive !== this.#isDraggingActive) {
189
- this.#options.onChangeState?.(this.#isDraggingActive);
189
+ this.#options.onChangeState?.(this.#isDraggingActive, this.#getCallbackOptions(this.#deltaMove.x));
190
190
  }
191
191
 
192
192
  this.#itemArray.length = 0;
@@ -216,14 +216,6 @@ export default class DragSlider {
216
216
 
217
217
  if (!flag) {
218
218
  this.#itemArray.push(DATA);
219
- // this.#itemArray.push({
220
- // ...DATA,
221
- // "info": {
222
- // ...ITEM_OFFSET,
223
- // "left": ABS_LIST_DELTA + this.#siteOffsetLeft,
224
- // "x": ABS_LIST_DELTA + this.#siteOffsetLeft
225
- // }
226
- // });
227
219
  }
228
220
  flag = true;
229
221
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 7.1.33
3
+ @version: 7.1.35
4
4
 
5
5
 
6
6
  ## Use
@@ -1,11 +1,6 @@
1
1
  declare namespace FLib {
2
2
  namespace Accordion {
3
3
 
4
- interface Tab {
5
- close( autoClose?: boolean ): this;
6
- destroy(): this;
7
- }
8
-
9
4
  type AnimationFunction = ( $tab: HTMLElement, $panel: HTMLElement ) => Promise<void>;
10
5
  type Callback = ( $tab: HTMLElement, $panel: HTMLElement ) => void;
11
6
  type CloseCallback = ( $tab: HTMLElement, $panel: HTMLElement, autoclose: boolean ) => void;
@@ -34,7 +29,6 @@ declare namespace FLib {
34
29
  }
35
30
 
36
31
  interface TabOptions extends Options {
37
- onOpenTab?: ( tab: Tab ) => void;
38
32
  index: number;
39
33
  }
40
34
  }
@@ -43,7 +43,7 @@ declare namespace FLib {
43
43
  onMouseEnter?: Callback;
44
44
  onMouseLeave?: Callback;
45
45
  onInit?: Callback;
46
- onChangeState?: ( isDragging: boolean ) => void;
46
+ onChangeState?: ( isActive: boolean, options: CallbackParam ) => void;
47
47
  /**
48
48
  * In px.
49
49
  * @defaultValue 40
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.33",
5
+ "version": "7.1.35",
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": [],