@creative-web-solution/front-library 7.1.17 → 7.1.19

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,14 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## 7.1.19
5
+
6
+ * [DragSlider] Fix variable init in goToItem
7
+
8
+ ## 7.1.18
9
+
10
+ * [DragSlider] Expose some properties + allow item index in goToItem function
11
+
4
12
  ## 7.1.17
5
13
 
6
14
  * [DragSlider] Rework + add refresh function
@@ -39,10 +39,22 @@ export default class DragSlider {
39
39
  #debouncedOnResize;
40
40
 
41
41
 
42
+ get count(): number {
43
+ return this.#$items?.length ?? 0;
44
+ }
45
+
46
+ get currentSnapItem(): FLib.DragSlider.Item | undefined {
47
+ return this.#currentSnapItem;
48
+ }
49
+
42
50
  get isActive(): boolean {
43
51
  return this.#isDraggingActive;
44
52
  }
45
53
 
54
+ get items(): NodeList | undefined {
55
+ return this.#$items;
56
+ }
57
+
46
58
 
47
59
  constructor( $slider: HTMLElement, options: Partial<FLib.DragSlider.Options> ) {
48
60
 
@@ -257,13 +269,13 @@ export default class DragSlider {
257
269
 
258
270
 
259
271
  #getClosestItem = ( xPos: number ): { snapItem: FLib.DragSlider.Item, snapToEnd: boolean } => {
260
- let lastDelta, snapItem, snapToEnd = false;
272
+ let lastDelta, snapItem;
261
273
 
262
274
  const absXPos = Math.abs( xPos );
263
275
 
264
276
  for ( const item of this.#itemArray ) {
265
277
  const IS_LAST_DELTA = typeof lastDelta !== 'undefined';
266
- let newDelta = Math.abs( absXPos - item.info.left + this.#siteOffsetLeft );
278
+ const newDelta = Math.abs( absXPos - item.info.left + this.#siteOffsetLeft );
267
279
 
268
280
  if ( !IS_LAST_DELTA || newDelta <= lastDelta ) {
269
281
  lastDelta = newDelta;
@@ -273,7 +285,7 @@ export default class DragSlider {
273
285
 
274
286
  return {
275
287
  snapItem,
276
- snapToEnd
288
+ snapToEnd: false
277
289
  };
278
290
  }
279
291
 
@@ -453,18 +465,33 @@ export default class DragSlider {
453
465
  }
454
466
 
455
467
 
456
- goToItem( $block: HTMLElement ): gsap.core.Tween | void {
468
+ goToItem( blockOrIndex: HTMLElement | number ): gsap.core.Tween | void {
457
469
 
458
470
  if ( !this.#isDraggingActive ) {
459
471
  return;
460
472
  }
461
473
 
474
+ let $block;
475
+
476
+ if (typeof blockOrIndex === 'number') {
477
+ $block = this.#$items?.[blockOrIndex] as HTMLElement;
478
+ }
479
+ else {
480
+ $block = blockOrIndex;
481
+ }
482
+
483
+ if ( !$block ) {
484
+ return;
485
+ }
486
+
462
487
  const ITEM = this.#itemMap.get( $block );
463
488
 
464
489
  if ( !ITEM ) {
465
490
  return;
466
491
  }
467
492
 
493
+ this.#currentSnapItem = ITEM;
494
+
468
495
  this.#options.onSnap?.( {
469
496
  "item": ITEM,
470
497
  "xPos": this.#deltaMove.x,
@@ -494,8 +521,10 @@ export default class DragSlider {
494
521
  } );
495
522
  }
496
523
 
497
- refresh = () => {
524
+ refresh = (): this => {
498
525
  this.#onResize();
526
+
527
+ return this;
499
528
  }
500
529
 
501
530
  init = (): this => {
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 7.1.17
3
+ @version: 7.1.19
4
4
 
5
5
 
6
6
  ## Use
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.17",
5
+ "version": "7.1.19",
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": [],