@baleada/logic 0.20.26 → 0.20.27

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/lib/index.cjs CHANGED
@@ -2719,6 +2719,7 @@ class Grantable {
2719
2719
  const defaultOptions$2 = {
2720
2720
  initialLocation: 0
2721
2721
  };
2722
+ const defaultNavigateOptions = { allows: "possible" };
2722
2723
  const defaultNextAndPreviousOptions = {
2723
2724
  distance: 1,
2724
2725
  loops: true
@@ -2758,28 +2759,36 @@ class Navigateable {
2758
2759
  this.navigate(location);
2759
2760
  return this;
2760
2761
  }
2761
- navigate(location) {
2762
- this._navigate(location);
2762
+ navigate(location, options = {}) {
2763
+ const { allows } = { ...defaultNavigateOptions, ...options };
2764
+ this._navigate(location, { allows });
2763
2765
  this.navigated();
2764
2766
  return this;
2765
2767
  }
2766
2768
  navigated() {
2767
2769
  this.computedStatus = "navigated";
2768
2770
  }
2769
- _navigate(location) {
2771
+ _navigate(location, options = {}) {
2772
+ const { allows } = { ...defaultNavigateOptions, ...options };
2770
2773
  const ensuredLocation = (() => {
2771
- if (location < 0) {
2772
- return 0;
2773
- }
2774
- if (location > this.array.length - 1) {
2775
- return Math.max(this.array.length - 1, 0);
2774
+ if (allows === "possible") {
2775
+ if (location < 0 && allows === "possible") {
2776
+ return 0;
2777
+ }
2778
+ if (location > this.array.length - 1) {
2779
+ return Math.max(this.array.length - 1, 0);
2780
+ }
2776
2781
  }
2777
2782
  return location;
2778
2783
  })();
2779
2784
  this.computedLocation = ensuredLocation;
2780
2785
  }
2781
2786
  next(options = {}) {
2782
- const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, lastLocation = this.array.length - 1, newLocation = (() => {
2787
+ const { distance, loops, allows } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
2788
+ if (allows === "any") {
2789
+ return this.location + distance;
2790
+ }
2791
+ const lastLocation = this.array.length - 1;
2783
2792
  if (this.location + distance <= lastLocation) {
2784
2793
  return this.location + distance;
2785
2794
  }
@@ -2794,7 +2803,7 @@ class Navigateable {
2794
2803
  return newLocation2;
2795
2804
  })();
2796
2805
  })();
2797
- this._navigate(newLocation);
2806
+ this._navigate(newLocation, { allows });
2798
2807
  this.nexted();
2799
2808
  return this;
2800
2809
  }
@@ -2802,7 +2811,10 @@ class Navigateable {
2802
2811
  this.computedStatus = "navigated to next";
2803
2812
  }
2804
2813
  previous(options = {}) {
2805
- const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, newLocation = (() => {
2814
+ const { distance, loops, allows } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
2815
+ if (allows === "any") {
2816
+ return this.location - distance;
2817
+ }
2806
2818
  if (this.location - distance >= 0) {
2807
2819
  return this.location - distance;
2808
2820
  }
@@ -2817,7 +2829,7 @@ class Navigateable {
2817
2829
  return newLocation2;
2818
2830
  })();
2819
2831
  })();
2820
- this._navigate(newLocation);
2832
+ this._navigate(newLocation, { allows });
2821
2833
  this.previoused();
2822
2834
  return this;
2823
2835
  }
package/lib/index.d.ts CHANGED
@@ -704,6 +704,13 @@ declare type NavigateableOptions = {
704
704
  initialLocation?: number;
705
705
  };
706
706
  declare type NavigateableStatus = 'ready' | 'navigated' | 'navigated to next' | 'navigated to previous' | 'navigated to random' | 'navigated to first' | 'navigated to last';
707
+ declare type NavigateOptions = {
708
+ allows?: 'possible' | 'any';
709
+ };
710
+ declare type NextAndPreviousOptions = {
711
+ distance?: number;
712
+ loops?: boolean;
713
+ };
707
714
  declare class Navigateable<Item> {
708
715
  constructor(array: Item[], options?: NavigateableOptions);
709
716
  private computedStatus;
@@ -718,18 +725,12 @@ declare class Navigateable<Item> {
718
725
  get item(): Item;
719
726
  setArray(array: Item[]): this;
720
727
  setLocation(location: number): this;
721
- navigate(location: number): this;
728
+ navigate(location: number, options?: NavigateOptions): this;
722
729
  private navigated;
723
730
  private _navigate;
724
- next(options?: {
725
- distance?: number;
726
- loops?: boolean;
727
- }): this;
731
+ next(options?: NextAndPreviousOptions & NavigateOptions): this;
728
732
  private nexted;
729
- previous(options?: {
730
- distance?: number;
731
- loops?: boolean;
732
- }): this;
733
+ previous(options?: NextAndPreviousOptions & NavigateOptions): this;
733
734
  private previoused;
734
735
  random(): this;
735
736
  private randomed;
package/lib/index.js CHANGED
@@ -2708,6 +2708,7 @@ class Grantable {
2708
2708
  const defaultOptions$2 = {
2709
2709
  initialLocation: 0
2710
2710
  };
2711
+ const defaultNavigateOptions = { allows: "possible" };
2711
2712
  const defaultNextAndPreviousOptions = {
2712
2713
  distance: 1,
2713
2714
  loops: true
@@ -2747,28 +2748,36 @@ class Navigateable {
2747
2748
  this.navigate(location);
2748
2749
  return this;
2749
2750
  }
2750
- navigate(location) {
2751
- this._navigate(location);
2751
+ navigate(location, options = {}) {
2752
+ const { allows } = { ...defaultNavigateOptions, ...options };
2753
+ this._navigate(location, { allows });
2752
2754
  this.navigated();
2753
2755
  return this;
2754
2756
  }
2755
2757
  navigated() {
2756
2758
  this.computedStatus = "navigated";
2757
2759
  }
2758
- _navigate(location) {
2760
+ _navigate(location, options = {}) {
2761
+ const { allows } = { ...defaultNavigateOptions, ...options };
2759
2762
  const ensuredLocation = (() => {
2760
- if (location < 0) {
2761
- return 0;
2762
- }
2763
- if (location > this.array.length - 1) {
2764
- return Math.max(this.array.length - 1, 0);
2763
+ if (allows === "possible") {
2764
+ if (location < 0 && allows === "possible") {
2765
+ return 0;
2766
+ }
2767
+ if (location > this.array.length - 1) {
2768
+ return Math.max(this.array.length - 1, 0);
2769
+ }
2765
2770
  }
2766
2771
  return location;
2767
2772
  })();
2768
2773
  this.computedLocation = ensuredLocation;
2769
2774
  }
2770
2775
  next(options = {}) {
2771
- const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, lastLocation = this.array.length - 1, newLocation = (() => {
2776
+ const { distance, loops, allows } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
2777
+ if (allows === "any") {
2778
+ return this.location + distance;
2779
+ }
2780
+ const lastLocation = this.array.length - 1;
2772
2781
  if (this.location + distance <= lastLocation) {
2773
2782
  return this.location + distance;
2774
2783
  }
@@ -2783,7 +2792,7 @@ class Navigateable {
2783
2792
  return newLocation2;
2784
2793
  })();
2785
2794
  })();
2786
- this._navigate(newLocation);
2795
+ this._navigate(newLocation, { allows });
2787
2796
  this.nexted();
2788
2797
  return this;
2789
2798
  }
@@ -2791,7 +2800,10 @@ class Navigateable {
2791
2800
  this.computedStatus = "navigated to next";
2792
2801
  }
2793
2802
  previous(options = {}) {
2794
- const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, newLocation = (() => {
2803
+ const { distance, loops, allows } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
2804
+ if (allows === "any") {
2805
+ return this.location - distance;
2806
+ }
2795
2807
  if (this.location - distance >= 0) {
2796
2808
  return this.location - distance;
2797
2809
  }
@@ -2806,7 +2818,7 @@ class Navigateable {
2806
2818
  return newLocation2;
2807
2819
  })();
2808
2820
  })();
2809
- this._navigate(newLocation);
2821
+ this._navigate(newLocation, { allows });
2810
2822
  this.previoused();
2811
2823
  return this;
2812
2824
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baleada/logic",
3
- "version": "0.20.26",
3
+ "version": "0.20.27",
4
4
  "description": "UI logic for the Baleada toolkit",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",
@@ -66,7 +66,7 @@
66
66
  "@types/resize-observer-browser": "^0.1.5",
67
67
  "bezier-easing": "^2.1.0",
68
68
  "dompurify": "^2.2.6",
69
- "fast-fuzzy": "^1.11.0",
69
+ "fast-fuzzy": "^1.11.1",
70
70
  "lazy-collections": "^0.8.0",
71
71
  "perfect-freehand": "^1.0.4",
72
72
  "polygon-clipping": "^0.15.3"