@baleada/logic 0.20.24 → 0.20.28
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 +34 -16
- package/lib/index.d.ts +12 -9
- package/lib/index.js +34 -16
- package/package.json +2 -2
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,36 @@ class Navigateable {
|
|
|
2758
2759
|
this.navigate(location);
|
|
2759
2760
|
return this;
|
|
2760
2761
|
}
|
|
2761
|
-
navigate(location) {
|
|
2762
|
-
|
|
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 (
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
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 },
|
|
2787
|
+
const { distance, loops, allow } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
|
|
2788
|
+
if (allow === "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, { allow });
|
|
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, allow } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
|
|
2815
|
+
if (allow === "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, { allow });
|
|
2821
2833
|
this.previoused();
|
|
2822
2834
|
return this;
|
|
2823
2835
|
}
|
|
@@ -2877,10 +2889,10 @@ class Pickable {
|
|
|
2877
2889
|
this.pick(indices);
|
|
2878
2890
|
}
|
|
2879
2891
|
get first() {
|
|
2880
|
-
return
|
|
2892
|
+
return this.computedFirst;
|
|
2881
2893
|
}
|
|
2882
2894
|
get last() {
|
|
2883
|
-
return
|
|
2895
|
+
return this.computedLast;
|
|
2884
2896
|
}
|
|
2885
2897
|
get oldest() {
|
|
2886
2898
|
return this.picks[0];
|
|
@@ -2939,6 +2951,8 @@ class Pickable {
|
|
|
2939
2951
|
return new Pipeable(this.picks).pipe(createSlice({ from: 0, to: this.picks.length - possibleWithoutDuplicates.length }), createConcat(possibleWithoutDuplicates));
|
|
2940
2952
|
}
|
|
2941
2953
|
});
|
|
2954
|
+
this.computedFirst = Math.min(...this.picks);
|
|
2955
|
+
this.computedLast = Math.max(...this.picks);
|
|
2942
2956
|
this.picked();
|
|
2943
2957
|
return this;
|
|
2944
2958
|
}
|
|
@@ -2948,11 +2962,15 @@ class Pickable {
|
|
|
2948
2962
|
omit(indexOrIndices) {
|
|
2949
2963
|
if (isUndefined(indexOrIndices)) {
|
|
2950
2964
|
this.computedPicks = [];
|
|
2965
|
+
this.computedFirst = void 0;
|
|
2966
|
+
this.computedLast = void 0;
|
|
2951
2967
|
this.omitted();
|
|
2952
2968
|
return this;
|
|
2953
2969
|
}
|
|
2954
|
-
const omits = ensureIndices(indexOrIndices)
|
|
2955
|
-
this.computedPicks =
|
|
2970
|
+
const omits = ensureIndices(indexOrIndices);
|
|
2971
|
+
this.computedPicks = createFilter((pick) => isUndefined(lazyCollections.find((omit) => pick === omit)(omits)))(this.computedPicks);
|
|
2972
|
+
this.computedFirst = Math.min(...this.picks);
|
|
2973
|
+
this.computedLast = Math.max(...this.picks);
|
|
2956
2974
|
this.omitted();
|
|
2957
2975
|
return this;
|
|
2958
2976
|
}
|
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 & 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;
|
|
@@ -753,7 +754,9 @@ declare class Pickable<Item> {
|
|
|
753
754
|
private computedPicks;
|
|
754
755
|
get picks(): number[];
|
|
755
756
|
set picks(indices: number[]);
|
|
757
|
+
computedFirst: number;
|
|
756
758
|
get first(): number;
|
|
759
|
+
computedLast: number;
|
|
757
760
|
get last(): number;
|
|
758
761
|
get oldest(): number;
|
|
759
762
|
get newest(): number;
|
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,36 @@ class Navigateable {
|
|
|
2747
2748
|
this.navigate(location);
|
|
2748
2749
|
return this;
|
|
2749
2750
|
}
|
|
2750
|
-
navigate(location) {
|
|
2751
|
-
|
|
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 (
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
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 },
|
|
2776
|
+
const { distance, loops, allow } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
|
|
2777
|
+
if (allow === "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, { allow });
|
|
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, allow } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
|
|
2804
|
+
if (allow === "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, { allow });
|
|
2810
2822
|
this.previoused();
|
|
2811
2823
|
return this;
|
|
2812
2824
|
}
|
|
@@ -2866,10 +2878,10 @@ class Pickable {
|
|
|
2866
2878
|
this.pick(indices);
|
|
2867
2879
|
}
|
|
2868
2880
|
get first() {
|
|
2869
|
-
return
|
|
2881
|
+
return this.computedFirst;
|
|
2870
2882
|
}
|
|
2871
2883
|
get last() {
|
|
2872
|
-
return
|
|
2884
|
+
return this.computedLast;
|
|
2873
2885
|
}
|
|
2874
2886
|
get oldest() {
|
|
2875
2887
|
return this.picks[0];
|
|
@@ -2928,6 +2940,8 @@ class Pickable {
|
|
|
2928
2940
|
return new Pipeable(this.picks).pipe(createSlice({ from: 0, to: this.picks.length - possibleWithoutDuplicates.length }), createConcat(possibleWithoutDuplicates));
|
|
2929
2941
|
}
|
|
2930
2942
|
});
|
|
2943
|
+
this.computedFirst = Math.min(...this.picks);
|
|
2944
|
+
this.computedLast = Math.max(...this.picks);
|
|
2931
2945
|
this.picked();
|
|
2932
2946
|
return this;
|
|
2933
2947
|
}
|
|
@@ -2937,11 +2951,15 @@ class Pickable {
|
|
|
2937
2951
|
omit(indexOrIndices) {
|
|
2938
2952
|
if (isUndefined(indexOrIndices)) {
|
|
2939
2953
|
this.computedPicks = [];
|
|
2954
|
+
this.computedFirst = void 0;
|
|
2955
|
+
this.computedLast = void 0;
|
|
2940
2956
|
this.omitted();
|
|
2941
2957
|
return this;
|
|
2942
2958
|
}
|
|
2943
|
-
const omits = ensureIndices(indexOrIndices)
|
|
2944
|
-
this.computedPicks =
|
|
2959
|
+
const omits = ensureIndices(indexOrIndices);
|
|
2960
|
+
this.computedPicks = createFilter((pick) => isUndefined(find((omit) => pick === omit)(omits)))(this.computedPicks);
|
|
2961
|
+
this.computedFirst = Math.min(...this.picks);
|
|
2962
|
+
this.computedLast = Math.max(...this.picks);
|
|
2945
2963
|
this.omitted();
|
|
2946
2964
|
return this;
|
|
2947
2965
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baleada/logic",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.28",
|
|
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.
|
|
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"
|