@baleada/logic 0.20.17 → 0.20.21

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
@@ -2058,18 +2058,21 @@ class Completeable {
2058
2058
  }
2059
2059
  complete(completion, options = {}) {
2060
2060
  this.completing();
2061
- const { select } = { ...defaultCompleteOptions, ...options }, textBefore = this.getTextBefore(), textAfter = this.getTextAfter(), completedString = textBefore + completion + textAfter, completedSelection = (() => {
2061
+ const { select } = { ...defaultCompleteOptions, ...options }, before = this.getBefore(), after = this.getAfter(), completedString = before + completion + after, completedSelection = (() => {
2062
+ if (isFunction(select)) {
2063
+ return select({ before, completion, after });
2064
+ }
2062
2065
  switch (select) {
2063
2066
  case "completion":
2064
2067
  return {
2065
- start: textBefore.length,
2066
- end: `${textBefore}${completion}`.length,
2068
+ start: before.length,
2069
+ end: `${before}${completion}`.length,
2067
2070
  direction: this.selection.direction
2068
2071
  };
2069
2072
  case "completionEnd":
2070
2073
  return {
2071
- start: `${textBefore}${completion}`.length,
2072
- end: `${textBefore}${completion}`.length,
2074
+ start: `${before}${completion}`.length,
2075
+ end: `${before}${completion}`.length,
2073
2076
  direction: this.selection.direction
2074
2077
  };
2075
2078
  }
@@ -2079,7 +2082,7 @@ class Completeable {
2079
2082
  this.completed();
2080
2083
  return this;
2081
2084
  }
2082
- getTextBefore() {
2085
+ getBefore() {
2083
2086
  switch (this.segmentFrom) {
2084
2087
  case "start":
2085
2088
  return "";
@@ -2089,7 +2092,7 @@ class Completeable {
2089
2092
  return this.string.slice(0, this.dividerIndices.before + 1);
2090
2093
  }
2091
2094
  }
2092
- getTextAfter() {
2095
+ getAfter() {
2093
2096
  switch (this.segmentTo) {
2094
2097
  case "end":
2095
2098
  return "";
@@ -2756,6 +2759,14 @@ class Navigateable {
2756
2759
  return this;
2757
2760
  }
2758
2761
  navigate(location) {
2762
+ this._navigate(location);
2763
+ this.navigated();
2764
+ return this;
2765
+ }
2766
+ navigated() {
2767
+ this.computedStatus = "navigated";
2768
+ }
2769
+ _navigate(location) {
2759
2770
  const ensuredLocation = (() => {
2760
2771
  if (location < 0) {
2761
2772
  return 0;
@@ -2766,11 +2777,6 @@ class Navigateable {
2766
2777
  return location;
2767
2778
  })();
2768
2779
  this.computedLocation = ensuredLocation;
2769
- this.navigated();
2770
- return this;
2771
- }
2772
- navigated() {
2773
- this.computedStatus = "navigated";
2774
2780
  }
2775
2781
  next(options = {}) {
2776
2782
  const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, lastLocation = this.array.length - 1, newLocation = (() => {
@@ -2788,9 +2794,13 @@ class Navigateable {
2788
2794
  return newLocation2;
2789
2795
  })();
2790
2796
  })();
2791
- this.navigate(newLocation);
2797
+ this._navigate(newLocation);
2798
+ this.nexted();
2792
2799
  return this;
2793
2800
  }
2801
+ nexted() {
2802
+ this.computedStatus = "navigated to next";
2803
+ }
2794
2804
  previous(options = {}) {
2795
2805
  const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, newLocation = (() => {
2796
2806
  if (this.location - distance >= 0) {
@@ -2807,22 +2817,38 @@ class Navigateable {
2807
2817
  return newLocation2;
2808
2818
  })();
2809
2819
  })();
2810
- this.navigate(newLocation);
2820
+ this._navigate(newLocation);
2821
+ this.previoused();
2811
2822
  return this;
2812
2823
  }
2824
+ previoused() {
2825
+ this.computedStatus = "navigated to previous";
2826
+ }
2813
2827
  random() {
2814
2828
  const newLocation = Math.floor(Math.random() * this.array.length);
2815
- this.navigate(newLocation);
2829
+ this._navigate(newLocation);
2830
+ this.randomed();
2816
2831
  return this;
2817
2832
  }
2833
+ randomed() {
2834
+ this.computedStatus = "navigated to random";
2835
+ }
2818
2836
  first() {
2819
- this.navigate(0);
2837
+ this._navigate(0);
2838
+ this.firsted();
2820
2839
  return this;
2821
2840
  }
2841
+ firsted() {
2842
+ this.computedStatus = "navigated to first";
2843
+ }
2822
2844
  last() {
2823
- this.navigate(this.array.length - 1);
2845
+ this._navigate(this.array.length - 1);
2846
+ this.lasted();
2824
2847
  return this;
2825
2848
  }
2849
+ lasted() {
2850
+ this.computedStatus = "navigated to last";
2851
+ }
2826
2852
  }
2827
2853
 
2828
2854
  const defaultOptions$1 = {
@@ -2892,7 +2918,7 @@ class Pickable {
2892
2918
  this.omitted();
2893
2919
  return this;
2894
2920
  }
2895
- const omits = ensureIndices(indexOrIndices), filter = createFilter((pick) => !lazyCollections.find((omit) => pick === omit)(omits));
2921
+ const omits = ensureIndices(indexOrIndices), filter = createFilter((pick) => isUndefined(lazyCollections.find((omit) => pick === omit)(omits)));
2896
2922
  this.computedPicks = filter(this.computedPicks);
2897
2923
  this.omitted();
2898
2924
  return this;
package/lib/index.d.ts CHANGED
@@ -157,7 +157,11 @@ declare type CompleteableOptions = {
157
157
  };
158
158
  declare type CompleteableStatus = 'constructing' | 'ready' | 'completing' | 'completed';
159
159
  declare type CompleteOptions = {
160
- select?: 'completion' | 'completionEnd';
160
+ select?: 'completion' | 'completionEnd' | (({ before, completion, after }: {
161
+ before: string;
162
+ completion: string;
163
+ after: string;
164
+ }) => Completeable['selection']);
161
165
  };
162
166
  declare class Completeable {
163
167
  private segmentFrom;
@@ -199,11 +203,9 @@ declare class Completeable {
199
203
  private setDividerIndices;
200
204
  private toPreviousMatch;
201
205
  private toNextMatch;
202
- complete(completion: string, options?: {
203
- select?: 'completion' | 'completionEnd';
204
- }): this;
205
- private getTextBefore;
206
- private getTextAfter;
206
+ complete(completion: string, options?: CompleteOptions): this;
207
+ private getBefore;
208
+ private getAfter;
207
209
  private completing;
208
210
  private completed;
209
211
  }
@@ -701,7 +703,7 @@ declare class Grantable<DescriptorType extends PermissionDescriptor> {
701
703
  declare type NavigateableOptions = {
702
704
  initialLocation?: number;
703
705
  };
704
- declare type NavigateableStatus = 'ready' | 'navigated';
706
+ declare type NavigateableStatus = 'ready' | 'navigated' | 'navigated to next' | 'navigated to previous' | 'navigated to random' | 'navigated to first' | 'navigated to last';
705
707
  declare class Navigateable<Item> {
706
708
  constructor(array: Item[], options?: NavigateableOptions);
707
709
  private computedStatus;
@@ -718,17 +720,23 @@ declare class Navigateable<Item> {
718
720
  setLocation(location: number): this;
719
721
  navigate(location: number): this;
720
722
  private navigated;
723
+ private _navigate;
721
724
  next(options?: {
722
725
  distance?: number;
723
726
  loops?: boolean;
724
727
  }): this;
728
+ private nexted;
725
729
  previous(options?: {
726
730
  distance?: number;
727
731
  loops?: boolean;
728
732
  }): this;
733
+ private previoused;
729
734
  random(): this;
735
+ private randomed;
730
736
  first(): this;
737
+ private firsted;
731
738
  last(): this;
739
+ private lasted;
732
740
  }
733
741
 
734
742
  declare type PickableOptions = {
package/lib/index.js CHANGED
@@ -2047,18 +2047,21 @@ class Completeable {
2047
2047
  }
2048
2048
  complete(completion, options = {}) {
2049
2049
  this.completing();
2050
- const { select } = { ...defaultCompleteOptions, ...options }, textBefore = this.getTextBefore(), textAfter = this.getTextAfter(), completedString = textBefore + completion + textAfter, completedSelection = (() => {
2050
+ const { select } = { ...defaultCompleteOptions, ...options }, before = this.getBefore(), after = this.getAfter(), completedString = before + completion + after, completedSelection = (() => {
2051
+ if (isFunction(select)) {
2052
+ return select({ before, completion, after });
2053
+ }
2051
2054
  switch (select) {
2052
2055
  case "completion":
2053
2056
  return {
2054
- start: textBefore.length,
2055
- end: `${textBefore}${completion}`.length,
2057
+ start: before.length,
2058
+ end: `${before}${completion}`.length,
2056
2059
  direction: this.selection.direction
2057
2060
  };
2058
2061
  case "completionEnd":
2059
2062
  return {
2060
- start: `${textBefore}${completion}`.length,
2061
- end: `${textBefore}${completion}`.length,
2063
+ start: `${before}${completion}`.length,
2064
+ end: `${before}${completion}`.length,
2062
2065
  direction: this.selection.direction
2063
2066
  };
2064
2067
  }
@@ -2068,7 +2071,7 @@ class Completeable {
2068
2071
  this.completed();
2069
2072
  return this;
2070
2073
  }
2071
- getTextBefore() {
2074
+ getBefore() {
2072
2075
  switch (this.segmentFrom) {
2073
2076
  case "start":
2074
2077
  return "";
@@ -2078,7 +2081,7 @@ class Completeable {
2078
2081
  return this.string.slice(0, this.dividerIndices.before + 1);
2079
2082
  }
2080
2083
  }
2081
- getTextAfter() {
2084
+ getAfter() {
2082
2085
  switch (this.segmentTo) {
2083
2086
  case "end":
2084
2087
  return "";
@@ -2745,6 +2748,14 @@ class Navigateable {
2745
2748
  return this;
2746
2749
  }
2747
2750
  navigate(location) {
2751
+ this._navigate(location);
2752
+ this.navigated();
2753
+ return this;
2754
+ }
2755
+ navigated() {
2756
+ this.computedStatus = "navigated";
2757
+ }
2758
+ _navigate(location) {
2748
2759
  const ensuredLocation = (() => {
2749
2760
  if (location < 0) {
2750
2761
  return 0;
@@ -2755,11 +2766,6 @@ class Navigateable {
2755
2766
  return location;
2756
2767
  })();
2757
2768
  this.computedLocation = ensuredLocation;
2758
- this.navigated();
2759
- return this;
2760
- }
2761
- navigated() {
2762
- this.computedStatus = "navigated";
2763
2769
  }
2764
2770
  next(options = {}) {
2765
2771
  const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, lastLocation = this.array.length - 1, newLocation = (() => {
@@ -2777,9 +2783,13 @@ class Navigateable {
2777
2783
  return newLocation2;
2778
2784
  })();
2779
2785
  })();
2780
- this.navigate(newLocation);
2786
+ this._navigate(newLocation);
2787
+ this.nexted();
2781
2788
  return this;
2782
2789
  }
2790
+ nexted() {
2791
+ this.computedStatus = "navigated to next";
2792
+ }
2783
2793
  previous(options = {}) {
2784
2794
  const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, newLocation = (() => {
2785
2795
  if (this.location - distance >= 0) {
@@ -2796,22 +2806,38 @@ class Navigateable {
2796
2806
  return newLocation2;
2797
2807
  })();
2798
2808
  })();
2799
- this.navigate(newLocation);
2809
+ this._navigate(newLocation);
2810
+ this.previoused();
2800
2811
  return this;
2801
2812
  }
2813
+ previoused() {
2814
+ this.computedStatus = "navigated to previous";
2815
+ }
2802
2816
  random() {
2803
2817
  const newLocation = Math.floor(Math.random() * this.array.length);
2804
- this.navigate(newLocation);
2818
+ this._navigate(newLocation);
2819
+ this.randomed();
2805
2820
  return this;
2806
2821
  }
2822
+ randomed() {
2823
+ this.computedStatus = "navigated to random";
2824
+ }
2807
2825
  first() {
2808
- this.navigate(0);
2826
+ this._navigate(0);
2827
+ this.firsted();
2809
2828
  return this;
2810
2829
  }
2830
+ firsted() {
2831
+ this.computedStatus = "navigated to first";
2832
+ }
2811
2833
  last() {
2812
- this.navigate(this.array.length - 1);
2834
+ this._navigate(this.array.length - 1);
2835
+ this.lasted();
2813
2836
  return this;
2814
2837
  }
2838
+ lasted() {
2839
+ this.computedStatus = "navigated to last";
2840
+ }
2815
2841
  }
2816
2842
 
2817
2843
  const defaultOptions$1 = {
@@ -2881,7 +2907,7 @@ class Pickable {
2881
2907
  this.omitted();
2882
2908
  return this;
2883
2909
  }
2884
- const omits = ensureIndices(indexOrIndices), filter = createFilter((pick) => !find((omit) => pick === omit)(omits));
2910
+ const omits = ensureIndices(indexOrIndices), filter = createFilter((pick) => isUndefined(find((omit) => pick === omit)(omits)));
2885
2911
  this.computedPicks = filter(this.computedPicks);
2886
2912
  this.omitted();
2887
2913
  return this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baleada/logic",
3
- "version": "0.20.17",
3
+ "version": "0.20.21",
4
4
  "description": "UI logic for the Baleada toolkit",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",