@hitgrab/finder 0.0.26-alpha → 0.1.3-alpha

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.
Files changed (82) hide show
  1. package/README.md +7 -1106
  2. package/dist/core/__tests__/test-types.d.ts +2 -2
  3. package/dist/core/core-constants.d.ts +39 -0
  4. package/dist/core/effect-book.d.ts +12 -0
  5. package/dist/core/{events/event-emitter.d.ts → event-emitter.d.ts} +3 -2
  6. package/dist/core/filters.d.ts +28 -0
  7. package/dist/core/finder-core-implementation.d.ts +44 -0
  8. package/dist/core/finder-core.d.ts +63 -74
  9. package/dist/core/finder-error.d.ts +3 -0
  10. package/dist/core/group-by.d.ts +23 -0
  11. package/dist/core/{pagination/pagination.d.ts → pagination.d.ts} +5 -4
  12. package/dist/core/rule-book.d.ts +14 -0
  13. package/dist/core/search/calculate-character-match-indexes.d.ts +1 -0
  14. package/dist/core/search/calculate-string-match-segments.d.ts +9 -0
  15. package/dist/core/search/search-score.d.ts +4 -0
  16. package/dist/core/search/search-string-transform.d.ts +8 -0
  17. package/dist/core/search/{haystack.d.ts → string-match-haystack.d.ts} +3 -3
  18. package/dist/core/search.d.ts +18 -0
  19. package/dist/core/sort-by.d.ts +23 -0
  20. package/dist/core/tester.d.ts +8 -0
  21. package/dist/core/types/core-types.d.ts +93 -0
  22. package/dist/core/types/effect-types.d.ts +20 -0
  23. package/dist/core/types/event-types.d.ts +44 -0
  24. package/dist/core/types/rule-types.d.ts +104 -0
  25. package/dist/core/types/string-match-types.d.ts +10 -0
  26. package/dist/core/utils/rule-type-enforcers.d.ts +12 -6
  27. package/dist/core/utils/rule-utils.d.ts +5 -10
  28. package/dist/index.d.ts +8 -14
  29. package/dist/index.js +3321 -3595
  30. package/dist/index.umd.cjs +30 -30
  31. package/dist/react/components/finder-content-empty.d.ts +6 -0
  32. package/dist/react/components/finder-content-groups.d.ts +7 -0
  33. package/dist/react/components/finder-content-items.d.ts +7 -0
  34. package/dist/react/components/finder-content-loading.d.ts +6 -0
  35. package/dist/react/components/finder-content-no-matches.d.ts +6 -0
  36. package/dist/react/components/finder-content.d.ts +20 -8
  37. package/dist/react/components/finder-search-term-haystack.d.ts +8 -0
  38. package/dist/react/components/finder.d.ts +7 -1
  39. package/dist/react/components/string-match.d.ts +12 -0
  40. package/dist/react/hooks/use-finder-ref.d.ts +1 -1
  41. package/dist/react/hooks/use-finder.d.ts +1 -5
  42. package/dist/react/providers/finder-core-context.d.ts +3 -0
  43. package/dist/react/types/react-types.d.ts +15 -16
  44. package/package.json +11 -7
  45. package/dist/core/__tests__/selected-items.test.d.ts +0 -1
  46. package/dist/core/filters/filters-interface.d.ts +0 -32
  47. package/dist/core/filters/filters.d.ts +0 -29
  48. package/dist/core/group-by/group-by-interface.d.ts +0 -21
  49. package/dist/core/group-by/group-by.d.ts +0 -20
  50. package/dist/core/layout/layout-interface.d.ts +0 -19
  51. package/dist/core/layout/layout.d.ts +0 -21
  52. package/dist/core/meta/meta-interface.d.ts +0 -18
  53. package/dist/core/meta/meta.d.ts +0 -16
  54. package/dist/core/pagination/pagination-interface.d.ts +0 -23
  55. package/dist/core/plugins/plugin-mediator.d.ts +0 -14
  56. package/dist/core/plugins/plugin-super-class.d.ts +0 -8
  57. package/dist/core/search/algorithms/sequential-characters.d.ts +0 -2
  58. package/dist/core/search/algorithms/sequential-string.d.ts +0 -2
  59. package/dist/core/search/algorithms/unordered-characters.d.ts +0 -2
  60. package/dist/core/search/result-segments/result-segment-types.d.ts +0 -18
  61. package/dist/core/search/result-segments/search-result-segments.d.ts +0 -17
  62. package/dist/core/search/search-interface.d.ts +0 -14
  63. package/dist/core/search/search.d.ts +0 -16
  64. package/dist/core/selected-items/selected-items-interface.d.ts +0 -22
  65. package/dist/core/selected-items/selected-items.d.ts +0 -23
  66. package/dist/core/sort-by/sort-by-interface.d.ts +0 -23
  67. package/dist/core/sort-by/sort-by.d.ts +0 -18
  68. package/dist/core/types/internal-types.d.ts +0 -15
  69. package/dist/core/utils/finder-utils.d.ts +0 -3
  70. package/dist/core/utils/string-compare-utils.d.ts +0 -13
  71. package/dist/react/components/finder-empty.d.ts +0 -6
  72. package/dist/react/components/finder-groups.d.ts +0 -7
  73. package/dist/react/components/finder-items.d.ts +0 -7
  74. package/dist/react/components/finder-loading.d.ts +0 -6
  75. package/dist/react/components/finder-no-matches.d.ts +0 -6
  76. package/dist/react/components/finder-search-term.d.ts +0 -7
  77. package/dist/react/hooks/use-finder-context.d.ts +0 -2
  78. package/dist/react/providers/finder-context.d.ts +0 -3
  79. package/dist/types.d.ts +0 -221
  80. /package/dist/core/__tests__/{layout.test.d.ts → effects.test.d.ts} +0 -0
  81. /package/dist/core/__tests__/{plugins.test.d.ts → events.test.d.ts} +0 -0
  82. /package/dist/core/{debounce-callback-registry/debounce-callback-registry.d.ts → debounce-callback-registry.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
- export type MockObjectItem = {
1
+ export interface MockObjectItem {
2
2
  type: string;
3
3
  name: string;
4
4
  price: number;
5
5
  daysUntilExpiryDate: string;
6
- };
6
+ }
@@ -0,0 +1,39 @@
1
+ export declare const EVENTS: {
2
+ readonly INIT: "init";
3
+ readonly FIRST_USER_INTERACTION: "firstUserInteraction";
4
+ readonly READY: "ready";
5
+ readonly CHANGE: "change";
6
+ readonly SET_ITEMS: "setItems";
7
+ readonly SET_IS_LOADING: "setIsLoading";
8
+ readonly SET_IS_DISABLED: "setIsDisabled";
9
+ readonly SET_CONTEXT: "setContext";
10
+ readonly SET_SEARCH_TERM: "setSearchTerm";
11
+ readonly RESET_SEARCH_TERM: "resetSearchTerm";
12
+ readonly SET_FILTER: "setFilter";
13
+ readonly SET_SORT_BY: "setSortBy";
14
+ readonly SET_SORT_BY_DIRECTION: "setSortDirection";
15
+ readonly SET_GROUP_BY: "setGroupBy";
16
+ readonly SET_GROUP_SORT_BY_DIRECTION: "setGroupBySortDirection";
17
+ readonly SET_PAGE: "setPage";
18
+ readonly SET_NUM_ITEMS_PER_PAGE: "setNumItemsPerPage";
19
+ };
20
+ export declare const EVENT_SOURCE: {
21
+ readonly CORE: "core";
22
+ readonly SEARCH: "search";
23
+ readonly FILTERS: "filters";
24
+ readonly GROUP_BY: "groupBy";
25
+ readonly SORT_BY: "sortBy";
26
+ readonly PAGINATION: "pagination";
27
+ };
28
+ export declare const ERRORS: {
29
+ RULE_NOT_FOUND: string;
30
+ WRONG_RULE_TYPE_FOR_MIXIN: string;
31
+ NO_SEARCH_RULE_SET: string;
32
+ TOGGLING_OPTION_ON_RULE_WITH_NO_OPTIONS: string;
33
+ TOGGLING_OPTION_ON_RULE_WITH_SINGLE_VALUE: string;
34
+ TOGGLING_OPTION_THAT_DOES_NOT_EXIST: string;
35
+ TESTING_OPTIONS_ON_RULE_WITH_NO_OPTIONS: string;
36
+ INVALID_RULE_WITHOUT_ID: string;
37
+ INVALID_RULE_SHAPE: string;
38
+ INVALID_RULE_DUPLICATE: string;
39
+ };
@@ -0,0 +1,12 @@
1
+ import { FinderCore } from "./finder-core";
2
+ import { HydratedRuleEffect, HydratedSearchEffect, RuleEffect, SearchEffect } from "./types/effect-types";
3
+ import { FinderRule } from "./types/rule-types";
4
+ export declare class EffectBook<FItem, FContext> {
5
+ #private;
6
+ searchEffects: HydratedSearchEffect[];
7
+ ruleEffects: HydratedRuleEffect[];
8
+ constructor(effects: (RuleEffect | SearchEffect)[], items: FItem[], context: FContext);
9
+ hydrateDefinitions(items: FItem[], context: FContext): void;
10
+ processRule(rule: FinderRule, instance: FinderCore): void;
11
+ processSearchTerm(searchTerm: string, instance: FinderCore): void;
12
+ }
@@ -1,11 +1,12 @@
1
- import { EventCallback } from "../types/internal-types";
1
+ import { EventCallback } from "./types/core-types";
2
2
  /**
3
3
  * A barebones event emitter
4
4
  */
5
5
  export declare class EventEmitter<EventNames extends string> {
6
6
  #private;
7
7
  on(event: EventNames, callback: EventCallback): void;
8
- off(event: EventNames, callback: EventCallback): void;
8
+ off(event: EventNames, callback?: EventCallback): void;
9
9
  emit(event: EventNames, payload?: any): void;
10
10
  silently(callback: CallableFunction): void;
11
+ isSilent(): boolean;
11
12
  }
@@ -0,0 +1,28 @@
1
+ import { FilterRuleUnion, FilterTestOptions, FilterTestRuleOptions, FilterTestRuleOptionsOptions, HydratedFilterRule } from "./types/rule-types";
2
+ import { MixinInjectedDependencies, SerializedFiltersMixin } from "./types/core-types";
3
+ interface InitialValues {
4
+ initialFilters: Record<string, any> | undefined;
5
+ }
6
+ type FilterRuleIdentifier = string | FilterRuleUnion | HydratedFilterRule;
7
+ declare class FiltersMixin {
8
+ #private;
9
+ constructor({ initialFilters }: InitialValues, deps: MixinInjectedDependencies);
10
+ set<FValue>(identifier: FilterRuleIdentifier, incomingFilterValue: FValue | FValue[]): void;
11
+ get rules(): HydratedFilterRule<unknown, any, any>[];
12
+ get activeRules(): HydratedFilterRule<unknown, any, any>[];
13
+ get(identifier: FilterRuleIdentifier): any;
14
+ has(identifier: FilterRuleIdentifier, optionValue?: any): boolean;
15
+ getRule(identifier: FilterRuleIdentifier): HydratedFilterRule<any, any, any>;
16
+ delete(identifier: FilterRuleIdentifier): void;
17
+ isRuleActive(identifier: FilterRuleIdentifier): boolean;
18
+ toggle(identifier: FilterRuleIdentifier, optionValue?: any): void;
19
+ test(options: FilterTestOptions): any[];
20
+ testRule({ rule: identifier, value, ...options }: FilterTestRuleOptions): any[];
21
+ testRuleOptions({ rule: identifier, ...options }: FilterTestRuleOptionsOptions): Map<any, any>;
22
+ getValues(): Record<string, any>;
23
+ getRawValues(): Record<string, any>;
24
+ serialize(): SerializedFiltersMixin;
25
+ static process<FItem>(options: SerializedFiltersMixin, items: FItem[], context?: any): FItem[];
26
+ static isRuleActive(rule: FilterRuleUnion | HydratedFilterRule, value: any): boolean;
27
+ }
28
+ export { FiltersMixin };
@@ -0,0 +1,44 @@
1
+ import { SearchMixin } from "./search";
2
+ import { FiltersMixin } from "./filters";
3
+ import { SortByMixin } from "./sort-by";
4
+ import { GroupByMixin } from "./group-by";
5
+ import { PaginationMixin } from "./pagination";
6
+ import { FinderCore } from "./finder-core";
7
+ import { FinderConstructorOptions, SnapshotSerializedMixins, EventCallback } from "./types/core-types";
8
+ import { FinderEventName } from "./types/event-types";
9
+ import { FinderRule } from "./types/rule-types";
10
+ declare class FinderCoreImplementation<FItem, FContext> {
11
+ #private;
12
+ isReady: boolean;
13
+ isLoading: boolean;
14
+ disabled: boolean;
15
+ updatedAt: number;
16
+ search: SearchMixin<FItem>;
17
+ filters: FiltersMixin;
18
+ sortBy: SortByMixin<FItem>;
19
+ groupBy: GroupByMixin<FItem, FContext>;
20
+ pagination: PaginationMixin<FItem>;
21
+ context: FContext;
22
+ getInstanceFn: () => FinderCore;
23
+ constructor(items: FItem[] | null | undefined, { rules, effects, initialSearchTerm, initialSortBy, initialSortDirection, initialGroupBy, initialFilters, context, page, numItemsPerPage, isLoading, disabled, requireGroup, ignoreSortByRulesWhileSearchRuleIsActive, onInit, onReady, onFirstUserInteraction, onChange, }: FinderConstructorOptions<FItem, FContext>, getInstanceFn: () => FinderCore);
24
+ emitFirstUserInteraction(): void;
25
+ get items(): FItem[];
26
+ get matches(): import("./types/core-types").ResultSnapshot<FItem>;
27
+ test(mixins: SnapshotSerializedMixins, isAdditive?: boolean): FItem[];
28
+ get isEmpty(): boolean;
29
+ get hasMatches(): boolean;
30
+ get events(): {
31
+ on: (event: FinderEventName, callback: EventCallback) => void;
32
+ off: (event: FinderEventName, callback: EventCallback) => void;
33
+ silently: (callback: EventCallback) => void;
34
+ isSilent: () => boolean;
35
+ };
36
+ getRule(identifier: string | FinderRule<FItem>): FinderRule<FItem>;
37
+ get state(): "loading" | "empty" | "groups" | "items" | "noMatches";
38
+ setItems(items: FItem[] | null | undefined): void;
39
+ setIsLoading(value?: boolean): void;
40
+ setIsDisabled(value?: boolean): void;
41
+ setRules(definitions: FinderRule<FItem, FContext>[]): void;
42
+ setContext(context: FContext): void;
43
+ }
44
+ export { FinderCoreImplementation };
@@ -1,108 +1,97 @@
1
- import { MatchesSnapshot, FinderConstructorOptions, FinderEventName } from "../types";
2
- import { PluginMediator } from "./plugins/plugin-mediator";
3
- import { EventCallback } from "./types/internal-types";
4
- declare class FinderCore<FItem> {
1
+ import { FinderConstructorOptions, SnapshotSerializedMixins } from "./types/core-types";
2
+ import { FinderRule } from "./types/rule-types";
3
+ /**
4
+ * This thin wrapper around FinderCoreImplementation defines the mixin interfaces and hides private methods.
5
+ */
6
+ declare class FinderCore<FItem = any, FContext = any> {
5
7
  #private;
6
- isReady: boolean;
7
- isLoading: boolean;
8
- disabled: boolean;
9
- updatedAt?: number;
10
- plugins: PluginMediator<FItem>;
11
- constructor(items: FItem[] | null | undefined, { rules, initialSearchTerm, initialSortBy, initialSortDirection, initialGroupBy, initialFilters, initialSelectedItems, initialMeta, page, numItemsPerPage, isLoading, disabled, requireGroup, maxSelectedItems, layoutVariants, initialLayout, plugins, onInit, onReady, onFirstUserInteraction, onChange, }: FinderConstructorOptions<FItem>);
12
- emitFirstUserInteraction(): void;
8
+ constructor(items: FItem[] | null | undefined, options: FinderConstructorOptions<FItem>);
13
9
  get items(): FItem[];
14
- get matches(): MatchesSnapshot<FItem>;
10
+ get context(): FContext;
11
+ get isReady(): boolean;
15
12
  get isEmpty(): boolean;
13
+ get hasMatches(): boolean;
14
+ get isLoading(): boolean;
15
+ get disabled(): boolean;
16
+ get state(): "loading" | "empty" | "groups" | "items" | "noMatches";
17
+ get updatedAt(): number;
18
+ get events(): {
19
+ on: (event: import("./types/event-types").FinderEventName, callback: import("./types/core-types").EventCallback) => void;
20
+ off: (event: import("./types/event-types").FinderEventName, callback: import("./types/core-types").EventCallback) => void;
21
+ silently: (callback: import("./types/core-types").EventCallback) => void;
22
+ isSilent: () => boolean;
23
+ };
24
+ /**
25
+ * Mixin interfaces
26
+ */
27
+ get matches(): import("./types/core-types").ResultSnapshot<FItem>;
16
28
  get search(): {
17
- setSearchTerm: (incomingSearchTerm: string) => void;
18
- reset: () => void;
19
29
  searchTerm: string;
20
- activeRule: import("..").SearchRule<unknown> | undefined;
21
30
  hasSearchTerm: boolean;
31
+ hasSearchRule: boolean;
32
+ setSearchTerm: (incomingSearchTerm: string) => void;
33
+ reset: () => void;
34
+ test: (searchTerm: string, isAdditive?: boolean) => FItem[];
22
35
  };
23
36
  get filters(): {
24
- toggle: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule) => void;
25
- toggleOption: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule, optionValue: import("..").FilterOption | any) => void;
26
- set: <FItem_1, FValue>(identifier: string | import("..").FilterRuleUnion<FItem_1, FValue> | import("..").HydratedFilterRule<FItem_1, FValue>, incomingFilterValue: FValue | FValue[]) => void;
27
- delete: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule) => void;
28
- test: (options: import("../types").FilterTestOptions) => any[];
29
- testRule: ({ rule: identifier, value, ...options }: import("../types").FilterTestRuleOptions) => any[];
30
- testRuleOptions: ({ rule: identifier, ...options }: import("../types").FilterTestRuleOptionsOptions) => Map<any, any>;
31
- filters: Record<string, any>;
37
+ values: Record<string, any>;
32
38
  raw: Record<string, any>;
33
- activeRules: import("..").HydratedFilterRule<any, any>[];
34
- rules: import("..").HydratedFilterRule<any, any>[];
35
- isActive: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule) => boolean;
36
- get: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule) => any;
37
- has: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule, optionValue?: import("..").FilterOption | any) => any;
38
- getRule: <FItem_1 = any, FValue = any>(identifier: string | import("..").FilterRuleUnion<FItem_1, FValue> | import("..").HydratedFilterRule<FItem_1, FValue>) => import("..").HydratedFilterRule<FItem_1, FValue>;
39
+ activeRules: import("..").HydratedFilterRule<unknown, any, any>[];
40
+ rules: import("..").HydratedFilterRule<unknown, any, any>[];
41
+ isActive: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => boolean;
42
+ get: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => any;
43
+ has: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue?: any) => boolean;
44
+ getRule: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => import("..").HydratedFilterRule<any, any, any>;
45
+ toggle: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue?: any) => void;
46
+ set: <FValue>(identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, incomingFilterValue: FValue | FValue[]) => void;
47
+ delete: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => void;
48
+ test: (options: import("./types/rule-types").FilterTestOptions) => any[];
49
+ testRule: ({ rule: identifier, value, ...options }: import("./types/rule-types").FilterTestRuleOptions) => any[];
50
+ testRuleOptions: ({ rule: identifier, ...options }: import("./types/rule-types").FilterTestRuleOptionsOptions) => Map<any, any>;
39
51
  };
40
52
  get sortBy(): {
53
+ activeRule: import("..").SortByRule<unknown, any> | undefined;
54
+ sortDirection: import("..").SortDirection;
55
+ userHasSetSortDirection: boolean;
56
+ rules: import("..").SortByRule<unknown, any>[];
41
57
  set: (identifier?: string | import("..").SortByRule, incomingSortDirection?: import("..").SortDirection) => void;
42
58
  setSortDirection: (incomingSortDirection?: import("..").SortDirection) => void;
43
59
  cycleSortDirection: () => void;
44
60
  toggleSortDirection: () => void;
45
- reset(): void;
46
- activeRule: import("..").SortByRule<unknown> | undefined;
47
- sortDirection: import("..").SortDirection;
48
- userHasSetSortDirection: boolean;
49
- rules: import("..").SortByRule<unknown>[];
61
+ reset: () => void;
50
62
  };
51
63
  get groupBy(): {
52
- set: (identifier?: import("..").GroupByRule | string) => void;
53
- toggle: (identifier: import("..").GroupByRule | string) => void;
54
- setGroupIdSortDirection: (direction?: import("..").SortDirection) => void;
55
- reset: () => void;
56
- activeRule: import("..").GroupByRule<unknown> | undefined;
64
+ activeRule: import("..").GroupByRule<unknown, any> | undefined;
57
65
  requireGroup: boolean;
58
- rules: import("..").GroupByRule<unknown>[];
66
+ rules: import("..").GroupByRule<unknown, any>[];
59
67
  groupIdSortDirection: import("..").SortDirection | undefined;
60
- };
61
- get meta(): {
62
- set: (metaIdentifier: any, value: any) => void;
63
- delete: (metaIdentifier: any) => void;
68
+ set: (identifier?: string | import("..").GroupByRule) => void;
69
+ toggle: (identifier: import("..").GroupByRule | string) => void;
70
+ setGroupSortDirection: (direction?: import("..").SortDirection) => void;
64
71
  reset: () => void;
65
- value: Record<string, any>;
66
- get: (metaIdentifier: any) => any;
67
- has: (metaIdentifier: any) => boolean;
68
72
  };
69
73
  get pagination(): {
70
- setPage: (value: number) => void;
71
- setNumItemsPerPage: (value?: number) => void;
72
74
  page: number;
73
75
  offset: number;
74
76
  numItemsPerPage: number | undefined;
75
77
  numTotalItems: number;
76
78
  lastPage: number | undefined;
77
79
  isPaginated: boolean;
80
+ setPage: (value: number) => void;
81
+ setNumItemsPerPage: (value?: number) => void;
78
82
  };
79
- get selectedItems(): {
80
- setMaxSelectedItems: (value?: number) => void;
81
- select: (item: FItem) => void;
82
- selectOnly: (item: FItem) => void;
83
- delete: (item: FItem) => void;
84
- toggle: (item: FItem) => void;
85
- toggleOnly: (item: FItem) => void;
86
- reset: () => void;
87
- items: FItem[];
88
- maxSelectedItems: number | undefined;
89
- isSelected: (item: FItem) => boolean;
90
- };
91
- get layout(): {
92
- set: (identifier: string | import("..").LayoutVariant | undefined) => void;
93
- reset: () => void;
94
- variants: import("..").LayoutVariant[];
95
- activeLayout: import("..").LayoutVariant | undefined;
96
- raw: import("..").LayoutVariant | undefined;
97
- is: (identifier: string | import("..").LayoutVariant | undefined) => boolean;
98
- };
99
- get events(): {
100
- on: (event: FinderEventName, callback: EventCallback) => void;
101
- off: (event: FinderEventName, callback: EventCallback) => void;
102
- };
103
- get state(): "loading" | "empty" | "groups" | "items" | "noMatches";
83
+ /**
84
+ * Mutators
85
+ */
104
86
  setItems(items: FItem[] | null | undefined): void;
105
87
  setIsLoading(value?: boolean): void;
106
88
  setIsDisabled(value?: boolean): void;
89
+ setRules(definitions: FinderRule<FItem>[]): void;
90
+ setContext(context: FContext): void;
91
+ /**
92
+ * Utils
93
+ */
94
+ test(mixins: SnapshotSerializedMixins, isAdditive?: boolean): FItem[];
95
+ getRule(identifier: string | FinderRule<FItem>): FinderRule<FItem>;
107
96
  }
108
97
  export { FinderCore };
@@ -0,0 +1,3 @@
1
+ export declare class FinderError extends Error {
2
+ constructor(message: string, options?: any);
3
+ }
@@ -0,0 +1,23 @@
1
+ import { GroupByRule } from "./types/rule-types";
2
+ import { FinderResultGroup, MixinInjectedDependencies, SerializedGroupByMixin, SortDirection } from "./types/core-types";
3
+ interface InitialValues {
4
+ initialGroupBy: string | undefined;
5
+ requireGroup: boolean;
6
+ }
7
+ declare class GroupByMixin<FItem, FContext> {
8
+ #private;
9
+ requireGroup: boolean;
10
+ constructor({ initialGroupBy, requireGroup }: InitialValues, deps: MixinInjectedDependencies<FItem, FContext>);
11
+ getRule(identifier: string | GroupByRule): GroupByRule<unknown, any>;
12
+ get rules(): GroupByRule<unknown, any>[];
13
+ get activeRule(): GroupByRule<unknown, any> | undefined;
14
+ get hasGroupByRule(): boolean;
15
+ get groupSortDirection(): SortDirection | undefined;
16
+ set(identifier?: string | GroupByRule): void;
17
+ setGroupSortDirection(direction?: SortDirection): void;
18
+ toggle(identifier: GroupByRule | string): void;
19
+ reset(): void;
20
+ serialize(): SerializedGroupByMixin;
21
+ static process<FItem>(options: SerializedGroupByMixin, items: FItem[], context?: unknown): FinderResultGroup<FItem>[];
22
+ }
23
+ export { GroupByMixin };
@@ -1,8 +1,8 @@
1
- import { MixinInjectedDependencies } from "../types/internal-types";
2
- type InitialValues = {
1
+ import { MixinInjectedDependencies, SerializedPaginationMixin } from "./types/core-types";
2
+ interface InitialValues {
3
3
  page: number | undefined;
4
4
  numItemsPerPage: number | undefined;
5
- };
5
+ }
6
6
  declare class PaginationMixin<FItem> {
7
7
  #private;
8
8
  numItemsPerPage?: number;
@@ -13,6 +13,7 @@ declare class PaginationMixin<FItem> {
13
13
  get numTotalItems(): number;
14
14
  get page(): number;
15
15
  get offset(): number;
16
- process(items: FItem[]): FItem[];
16
+ serialize(): SerializedPaginationMixin;
17
+ static process<FItem>(options: SerializedPaginationMixin, items: FItem[]): FItem[];
17
18
  }
18
19
  export { PaginationMixin };
@@ -0,0 +1,14 @@
1
+ import { FinderRule } from "./types/rule-types";
2
+ /**
3
+ * Stores rule definitions and hydrated rules
4
+ */
5
+ export declare class RuleBook<FItem, FContext> {
6
+ #private;
7
+ rules: FinderRule<FItem>[];
8
+ constructor(definitions: FinderRule<FItem>[], items: FItem[], context: FContext);
9
+ hydrateDefinitions(items: FItem[], context: FContext): void;
10
+ getRule(identifier: string | FinderRule): FinderRule<FItem>;
11
+ getDefinitions(): FinderRule<FItem>[];
12
+ setRules(definitions: FinderRule<FItem>[]): void;
13
+ static validateDefinitions(definitions: FinderRule[]): boolean;
14
+ }
@@ -0,0 +1 @@
1
+ export declare function calculateCharacterMatchIndexes(haystack: string, needle: string): number[] | undefined;
@@ -0,0 +1,9 @@
1
+ import { StringMatchSegment } from "../types/string-match-types";
2
+ /**
3
+ * Helper function to determine which specfic characters are matched inside a string.
4
+ */
5
+ export declare function calculateStringMatchSegments(haystack: string | string[], needle: string): StringMatchSegment[] | undefined;
6
+ /**
7
+ * Determine if a characterIndexFn would return a result for a haystack.
8
+ */
9
+ export declare function hasCharacterIndexMatches(haystack: string | string[], needle: string): boolean;
@@ -0,0 +1,4 @@
1
+ export declare function calculateSearchScore(indexes: number[], haystack: string): {
2
+ percentOfHaystackMatched: number;
3
+ longestSequentialSequence: number;
4
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Ensure haystacks and needles are formatted consistently.
3
+ *
4
+ * Transforming includes:
5
+ * 1. Convert to lowercase.
6
+ * 2. Strip all non-word and non-digit characters.
7
+ */
8
+ export declare function transformStringForComparison(value: string): string;
@@ -1,4 +1,4 @@
1
- export declare class Haystack {
1
+ export declare class StringMatchHaystack {
2
2
  #private;
3
3
  source: string;
4
4
  transformed: string;
@@ -9,7 +9,7 @@ export declare class Haystack {
9
9
  */
10
10
  static composeTransformedHaystackSegments(haystack: string): {
11
11
  value: string;
12
- start: number;
13
- end: number;
12
+ index: number;
13
+ length: number;
14
14
  }[];
15
15
  }
@@ -0,0 +1,18 @@
1
+ import { MixinInjectedDependencies, SerializedSearchMixin } from "./types/core-types";
2
+ interface InitialValues {
3
+ initialSearchTerm: string | undefined;
4
+ }
5
+ declare class SearchMixin<FItem> {
6
+ #private;
7
+ searchTerm: string;
8
+ constructor({ initialSearchTerm }: InitialValues, deps: MixinInjectedDependencies<FItem>);
9
+ get rule(): import("..").SearchRule<unknown, any> | undefined;
10
+ get hasSearchRule(): boolean;
11
+ get hasSearchTerm(): boolean;
12
+ setSearchTerm(incomingSearchTerm: string): void;
13
+ reset(): void;
14
+ serialize(): SerializedSearchMixin;
15
+ test(searchTerm: string, isAdditive?: boolean): FItem[];
16
+ static process<FItem>(options: SerializedSearchMixin, items: FItem[], context?: unknown): FItem[];
17
+ }
18
+ export { SearchMixin };
@@ -0,0 +1,23 @@
1
+ import { SortByRule } from "./types/rule-types";
2
+ import { MixinInjectedDependencies, SerializedSortByMixin, SortDirection } from "./types/core-types";
3
+ interface InitialValues {
4
+ initialSortBy: string | undefined;
5
+ initialSortDirection?: SortDirection;
6
+ }
7
+ declare class SortByMixin<FItem> {
8
+ #private;
9
+ constructor({ initialSortBy, initialSortDirection }: InitialValues, deps: MixinInjectedDependencies<FItem>);
10
+ getRule(identifier: string | SortByRule): SortByRule<unknown, any>;
11
+ get rules(): SortByRule<unknown, any>[];
12
+ get activeRule(): SortByRule<unknown, any> | undefined;
13
+ get sortDirection(): SortDirection;
14
+ get userHasSetSortDirection(): boolean;
15
+ setSortDirection(incomingSortDirection?: SortDirection): void;
16
+ cycleSortDirection(): void;
17
+ toggleSortDirection(): void;
18
+ set(identifier?: string | SortByRule, incomingSortDirection?: SortDirection): void;
19
+ reset(): void;
20
+ serialize(): SerializedSortByMixin;
21
+ static process<FItem>(options: SerializedSortByMixin, items: FItem[], context: unknown): FItem[];
22
+ }
23
+ export { SortByMixin };
@@ -0,0 +1,8 @@
1
+ import { ResultSnapshot, SnapshotOptions } from "./types/core-types";
2
+ export declare class Tester<FItem, FContext> {
3
+ snapshot: ResultSnapshot<FItem>;
4
+ isStale: boolean;
5
+ setIsStale(value: boolean): void;
6
+ takeSnapshot({ items, context, mixins }: SnapshotOptions<FItem, FContext>): void;
7
+ static test<FItem, FContext>({ mixins, items, context }: SnapshotOptions<FItem, FContext>): FItem[];
8
+ }
@@ -0,0 +1,93 @@
1
+ import { DebounceCallbackRegistry } from "../debounce-callback-registry";
2
+ import { RuleBook } from "../rule-book";
3
+ import { RuleEffect, SearchEffect } from "./effect-types";
4
+ import { FinderOnChangeCallback, FinderOnFirstUserInteractCallback, FinderOnInitCallback, FinderOnReadyCallback, FinderTouchCallback } from "./event-types";
5
+ import { FinderRule, GroupByRule, HydratedFilterRule, SearchRule, SortByRule } from "./rule-types";
6
+ export interface FinderConstructorOptions<FItem, FContext = any> {
7
+ rules: FinderRule<FItem>[];
8
+ effects?: (RuleEffect | SearchEffect)[];
9
+ context?: FContext;
10
+ isLoading?: boolean;
11
+ disabled?: boolean;
12
+ initialSearchTerm?: string;
13
+ initialSortBy?: string;
14
+ initialSortDirection?: SortDirection;
15
+ initialGroupBy?: string;
16
+ initialFilters?: Record<string, any>;
17
+ ignoreSortByRulesWhileSearchRuleIsActive?: boolean;
18
+ requireGroup?: boolean;
19
+ page?: number;
20
+ numItemsPerPage?: number;
21
+ onInit?: FinderOnInitCallback;
22
+ onReady?: FinderOnReadyCallback;
23
+ onFirstUserInteraction?: FinderOnFirstUserInteractCallback;
24
+ onChange?: FinderOnChangeCallback;
25
+ }
26
+ export interface FinderResultGroup<FItem> {
27
+ id: string;
28
+ items: FItem[];
29
+ }
30
+ export type SortDirection = "asc" | "desc" | ("asc" | "desc")[];
31
+ export interface ResultSnapshot<FItem> {
32
+ items?: FItem[];
33
+ groups?: FinderResultGroup<FItem>[];
34
+ numMatchedItems: number;
35
+ numTotalItems: number;
36
+ hasGroupByRule: boolean;
37
+ }
38
+ export interface MixinInjectedDependencies<FItem = any, FContext = any> {
39
+ isLoading: () => boolean;
40
+ isDisabled: () => boolean;
41
+ getRuleBook: () => RuleBook<FItem, FContext>;
42
+ touch: FinderTouchCallback;
43
+ getItems: () => FItem[];
44
+ test: (serializedMixins: SnapshotSerializedMixins, isAdditive?: boolean) => FItem[];
45
+ debouncer: DebounceCallbackRegistry;
46
+ }
47
+ export type EventCallback = (payload?: any) => void;
48
+ export interface SnapshotOptions<FItem, FContext> {
49
+ items: FItem[];
50
+ context: FContext;
51
+ mixins: SnapshotSerializedMixins;
52
+ }
53
+ export interface SnapshotSerializedMixins {
54
+ search?: SerializedSearchMixin;
55
+ filters?: SerializedFiltersMixin;
56
+ sortBy?: SerializedSortByMixin;
57
+ pagination?: SerializedPaginationMixin;
58
+ groupBy?: SerializedGroupByMixin;
59
+ }
60
+ export interface SerializedSearchMixin {
61
+ searchTerm: string;
62
+ rule?: SearchRule;
63
+ }
64
+ export interface SerializedFiltersMixin {
65
+ rules: HydratedFilterRule[];
66
+ values: Record<string, any>;
67
+ }
68
+ export interface SerializedSortByMixin {
69
+ rule?: SortByRule;
70
+ sortDirection?: SortDirection;
71
+ }
72
+ export interface SerializedPaginationMixin {
73
+ page: number;
74
+ numItemsPerPage?: number;
75
+ }
76
+ export interface SerializedGroupByMixin {
77
+ rule?: GroupByRule;
78
+ sortDirection?: SortDirection;
79
+ }
80
+ export interface SearchScore {
81
+ percentOfHaystackMatched: number;
82
+ longestSequentialSequence: number;
83
+ }
84
+ export interface PaginationMixinInterface {
85
+ page: number;
86
+ offset: number;
87
+ numItemsPerPage: number | undefined;
88
+ numTotalItems: number;
89
+ lastPage: number | undefined;
90
+ isPaginated: boolean;
91
+ setPage: (value: number) => void;
92
+ setNumItemsPerPage: (value: number) => void;
93
+ }
@@ -0,0 +1,20 @@
1
+ import { FinderCore } from "../finder-core";
2
+ import { FinderRule } from "./rule-types";
3
+ export interface RuleEffect<FItem = any, FContext = any> {
4
+ rules: string | FinderRule<FItem> | (string | FinderRule<FItem>)[] | ((items: FItem[], context: FContext) => string | FinderRule<FItem> | (string | FinderRule<FItem>)[]);
5
+ onChange: (instance: FinderCore<FItem, FContext>) => void;
6
+ }
7
+ export interface HydratedRuleEffect<FItem = any, FContext = any> {
8
+ rules: (string | FinderRule<FItem>)[];
9
+ onChange: (instance: FinderCore<FItem, FContext>) => void;
10
+ _isHydrated: true;
11
+ }
12
+ export interface SearchEffect<FItem = any, FContext = any> {
13
+ haystack: string | string[] | ((items: FItem[], context: FContext) => string | string[]);
14
+ onChange: (instance: FinderCore<FItem, FContext>) => void;
15
+ }
16
+ export interface HydratedSearchEffect<FItem = any, FContext = any> {
17
+ haystack: string[];
18
+ onChange: (instance: FinderCore<FItem, FContext>) => void;
19
+ _isHydrated: true;
20
+ }
@@ -0,0 +1,44 @@
1
+ import { EVENT_SOURCE, EVENTS } from "../core-constants";
2
+ import { FinderCore } from "../finder-core";
3
+ import { FinderRule } from "./rule-types";
4
+ export type FinderTouchSource = (typeof EVENT_SOURCE)[keyof typeof EVENT_SOURCE];
5
+ interface FinderSharedEventProps {
6
+ source: string;
7
+ event: FinderEventName;
8
+ timestamp: number;
9
+ instance: FinderCore;
10
+ }
11
+ export interface FinderInitEvent extends FinderSharedEventProps {
12
+ source: "core";
13
+ event: "init";
14
+ }
15
+ export interface FinderFirstUserInteractionEvent extends FinderSharedEventProps {
16
+ source: "core";
17
+ event: "firstUserInteraction";
18
+ }
19
+ export interface FinderReadyEvent extends FinderSharedEventProps {
20
+ source: "core";
21
+ event: "ready";
22
+ }
23
+ export type FinderEvent = FinderInitEvent | FinderFirstUserInteractionEvent | FinderReadyEvent | FinderChangeEvent;
24
+ export type FinderOnInitCallback = (event: FinderInitEvent) => void;
25
+ export type FinderOnReadyCallback = (event: FinderReadyEvent) => void;
26
+ export type FinderOnFirstUserInteractCallback = (event: FinderFirstUserInteractionEvent) => void;
27
+ export type FinderOnChangeCallback = (event: FinderChangeEvent) => void;
28
+ export type FinderTouchCallback = (event: FinderTouchEvent) => void;
29
+ /**
30
+ * Internal communication between mixins and core
31
+ */
32
+ export interface FinderTouchEvent {
33
+ source: FinderTouchSource;
34
+ event: FinderEventName;
35
+ current: any;
36
+ initial: any;
37
+ rule?: FinderRule;
38
+ }
39
+ /**
40
+ * External type that consumers will receive
41
+ */
42
+ export type FinderChangeEvent = FinderTouchEvent & FinderSharedEventProps;
43
+ export type FinderEventName = (typeof EVENTS)[keyof typeof EVENTS];
44
+ export {};