@baleada/logic 0.20.25 → 0.20.29

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 = { allow: "possible" };
2722
2723
  const defaultNextAndPreviousOptions = {
2723
2724
  distance: 1,
2724
2725
  loops: true
@@ -2758,28 +2759,33 @@ 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 { allow } = { ...defaultNavigateOptions, ...options };
2764
+ this._navigate(location, { allow });
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 { allow } = { ...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 (allow === "possible") {
2775
+ if (location < 0 && allow === "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 } = { ...defaultNextAndPreviousOptions, ...options }, newLocation = (() => {
2788
+ const lastLocation = this.array.length - 1;
2783
2789
  if (this.location + distance <= lastLocation) {
2784
2790
  return this.location + distance;
2785
2791
  }
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
+ allow?: '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): this;
728
732
  private nexted;
729
- previous(options?: {
730
- distance?: number;
731
- loops?: boolean;
732
- }): this;
733
+ previous(options?: NextAndPreviousOptions): 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 = { allow: "possible" };
2711
2712
  const defaultNextAndPreviousOptions = {
2712
2713
  distance: 1,
2713
2714
  loops: true
@@ -2747,28 +2748,33 @@ 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 { allow } = { ...defaultNavigateOptions, ...options };
2753
+ this._navigate(location, { allow });
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 { allow } = { ...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 (allow === "possible") {
2764
+ if (location < 0 && allow === "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 } = { ...defaultNextAndPreviousOptions, ...options }, newLocation = (() => {
2777
+ const lastLocation = this.array.length - 1;
2772
2778
  if (this.location + distance <= lastLocation) {
2773
2779
  return this.location + distance;
2774
2780
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baleada/logic",
3
- "version": "0.20.25",
3
+ "version": "0.20.29",
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.10.8",
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"