@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,18 +0,0 @@
1
- import { SortByRule, SortDirection } from "../../types";
2
- import { MixinInjectedDependencies } from "../types/internal-types";
3
- type 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
- get rules(): SortByRule<unknown>[];
11
- get activeRule(): SortByRule<unknown> | undefined;
12
- get sortDirection(): SortDirection;
13
- get userHasSetSortDirection(): boolean;
14
- setSortDirection(incomingSortDirection?: SortDirection): void;
15
- set(identifier?: string | SortByRule, incomingSortDirection?: SortDirection): void;
16
- process(items: FItem[]): FItem[];
17
- }
18
- export { SortByMixin };
@@ -1,15 +0,0 @@
1
- /**
2
- * These internal types are not intended for public consumption.
3
- */
4
- import { FinderRule, FinderTouchCallback, MetaInterface } from "../../types";
5
- import { DebounceCallbackRegistry } from "../debounce-callback-registry/debounce-callback-registry";
6
- export interface MixinInjectedDependencies<FItem = any> {
7
- isLoading: () => boolean;
8
- isDisabled: () => boolean;
9
- getRules: () => FinderRule[];
10
- touch: FinderTouchCallback;
11
- getMeta: () => MetaInterface;
12
- getItems: () => FItem[];
13
- debouncer: DebounceCallbackRegistry;
14
- }
15
- export type EventCallback = (payload?: any) => void;
@@ -1,3 +0,0 @@
1
- export declare function clamp(value: number, min: number, max: number): number;
2
- export declare function simpleUniqBy<T>(data: T[], key: string): T[];
3
- export declare function range(start: number, end: number): number[];
@@ -1,13 +0,0 @@
1
- /**
2
- * Case-insensitive sequential string comparison with line breaks and white spaces removed.
3
- * If the method receive an optional aliases array, each of those aliases will be compared as well.
4
- */
5
- export declare function finderStringCompare(haystack: string, needle: string, aliases?: string[] | null): boolean;
6
- /**
7
- * Compare if the same characters are all represented in a string.
8
- */
9
- export declare function finderCharacterCompare(haystack: string, needle: string, aliases?: string[] | null): boolean;
10
- /**
11
- * Compare if the same characters are represented sequentially in a string.
12
- */
13
- export declare function finderSequentialCharacterCompare(haystack: string, needle: string, aliases?: string[] | null): boolean;
@@ -1,6 +0,0 @@
1
- import { FinderBaseRenderProp } from "../types/react-types";
2
- interface FinderEmptyProps {
3
- children: FinderBaseRenderProp;
4
- }
5
- declare function FinderEmpty({ children: renderProp }: FinderEmptyProps): Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
6
- export { FinderEmpty };
@@ -1,7 +0,0 @@
1
- import { ElementType } from "react";
2
- import { FinderGroupsComponentProps } from "../types/react-types";
3
- interface FinderGroupsProps<FItem = any> {
4
- children: ElementType<FinderGroupsComponentProps<FItem>>;
5
- }
6
- declare function FinderGroups<FItem>({ children: renderProp }: FinderGroupsProps<FItem>): import("react/jsx-runtime").JSX.Element | null;
7
- export { FinderGroups };
@@ -1,7 +0,0 @@
1
- import { ElementType } from "react";
2
- import { FinderItemsComponentProps } from "../types/react-types";
3
- interface FinderItemsProps<FItem = any> {
4
- children: ElementType<FinderItemsComponentProps<FItem>>;
5
- }
6
- declare function FinderItems<FItem>({ children: renderProp }: FinderItemsProps<FItem>): import("react/jsx-runtime").JSX.Element | null;
7
- export { FinderItems };
@@ -1,6 +0,0 @@
1
- import { FinderBaseRenderProp } from "../types/react-types";
2
- interface FinderLoadingProps {
3
- children: FinderBaseRenderProp;
4
- }
5
- declare function FinderLoading({ children: renderProp }: FinderLoadingProps): Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
6
- export { FinderLoading };
@@ -1,6 +0,0 @@
1
- import { FinderBaseRenderProp } from "../types/react-types";
2
- interface FinderNoMatchesProps {
3
- children: FinderBaseRenderProp;
4
- }
5
- declare function FinderNoMatches({ children: renderProp }: FinderNoMatchesProps): Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
6
- export { FinderNoMatches };
@@ -1,7 +0,0 @@
1
- import { ElementType } from "react";
2
- interface FinderSearchTermProps {
3
- children: string;
4
- Component?: ElementType;
5
- }
6
- declare function FinderSearchTerm({ Component, children }: FinderSearchTermProps): string | import("react/jsx-runtime").JSX.Element;
7
- export { FinderSearchTerm };
@@ -1,2 +0,0 @@
1
- declare function useFinderContext(): import("../../core/finder-core").FinderCore<any>;
2
- export { useFinderContext };
@@ -1,3 +0,0 @@
1
- import { FinderCore } from "../../core/finder-core";
2
- declare const FinderContext: import("react").Context<[FinderCore<any>, number | undefined] | null>;
3
- export { FinderContext };
package/dist/types.d.ts DELETED
@@ -1,221 +0,0 @@
1
- /**
2
- * Public types that are necessary to use the library.
3
- */
4
- import { readonlyFiltersInterface } from "./core/filters/filters-interface";
5
- import { readonlyGroupByInterface } from "./core/group-by/group-by-interface";
6
- import { metaInterface, readonlyMetaInterface } from "./core/meta/meta-interface";
7
- import { readonlySearchInterface } from "./core/search/search-interface";
8
- import { readonlySelectedItemsInterface } from "./core/selected-items/selected-items-interface";
9
- import { readonlySortByInterface } from "./core/sort-by/sort-by-interface";
10
- import { readonlyLayoutInterface } from "./core/layout/layout-interface";
11
- import { FinderCore } from "./core/finder-core";
12
- export type MetaInterface = ReturnType<typeof metaInterface>;
13
- export interface FinderConstructorOptions<FItem> {
14
- rules?: FinderRule<FItem>[];
15
- initialSearchTerm?: string;
16
- initialSortBy?: string;
17
- initialSortDirection?: SortDirection;
18
- initialGroupBy?: string;
19
- initialFilters?: Record<string, any>;
20
- initialMeta?: Record<string, any>;
21
- initialSelectedItems?: FItem[];
22
- maxSelectedItems?: number;
23
- isLoading?: boolean;
24
- disabled?: boolean;
25
- page?: number;
26
- numItemsPerPage?: number;
27
- requireGroup?: boolean;
28
- plugins?: (FinderPluginInterface | FinderPluginFn<FinderPluginInterface>)[];
29
- layoutVariants?: LayoutVariant[];
30
- initialLayout?: string;
31
- onInit?: FinderOnInitCallback;
32
- onReady?: FinderOnReadyCallback;
33
- onFirstUserInteraction?: FinderOnFirstUserInteractCallback;
34
- onChange?: FinderOnChangeCallback;
35
- }
36
- export interface FinderResultGroup<FItem> {
37
- id: string;
38
- items: FItem[];
39
- }
40
- export type FinderRule<FItem = any> = SearchRule<FItem> | FilterRuleUnion<FItem> | HydratedFilterRule<FItem> | SortByRule<FItem> | GroupByRule<FItem>;
41
- export interface SearchRuleSharedProps {
42
- id?: string;
43
- label?: string;
44
- hidden?: boolean;
45
- debounceMilliseconds?: number;
46
- searchFn?: unknown;
47
- searchTermFn?: unknown;
48
- }
49
- export interface SearchRuleSimple<FItem = any> extends SearchRuleSharedProps {
50
- searchFn?: never;
51
- searchTermFn: (item: FItem, meta: MetaInterface) => string | string[];
52
- }
53
- export interface SearchRuleAdvanced<FItem = any> extends SearchRuleSharedProps {
54
- searchTermFn?: never;
55
- searchFn: (item: FItem, searchTerm: string, meta: MetaInterface) => boolean;
56
- }
57
- export type SearchRule<FItem = any> = SearchRuleAdvanced<FItem> | SearchRuleSimple<FItem>;
58
- export interface FilterOptionGeneratorFnOptions<FItem> {
59
- items: FItem[];
60
- meta: MetaInterface;
61
- }
62
- export interface FilterRule<FItem = any, FValue = any> {
63
- id: string;
64
- options?: FilterOption<FValue>[] | ((options: FilterOptionGeneratorFnOptions<FItem>) => FilterOption<FValue>[]);
65
- required?: boolean;
66
- label?: string;
67
- hidden?: boolean;
68
- debounceMilliseconds?: number;
69
- multiple?: boolean;
70
- isBoolean?: boolean;
71
- filterFn: CallableFunction;
72
- defaultValue?: any;
73
- }
74
- interface FilterRuleWithBooleanValue<FItem, FValue = boolean> extends FilterRule<FItem, FValue> {
75
- multiple?: false;
76
- isBoolean: true;
77
- filterFn: (item: FItem, value: FValue, meta: MetaInterface) => boolean;
78
- defaultValue?: boolean;
79
- }
80
- interface FilterRuleWithScalarValue<FItem, FValue> extends FilterRule<FItem, FValue> {
81
- multiple?: false;
82
- isBoolean?: false;
83
- filterFn: (item: FItem, value: FValue, meta: MetaInterface) => boolean;
84
- defaultValue?: FValue;
85
- }
86
- interface FilterRuleWithMultipleValues<FItem, FValue> extends FilterRule<FItem, FValue> {
87
- multiple: true;
88
- isBoolean?: false;
89
- filterFn: (item: FItem, value: FValue[], meta: MetaInterface) => boolean;
90
- defaultValue?: FValue[];
91
- }
92
- export type FilterRuleUnion<FItem = any, FValue = any> = FilterRuleWithBooleanValue<FItem> | FilterRuleWithScalarValue<FItem, FValue> | FilterRuleWithMultipleValues<FItem, FValue>;
93
- /**
94
- * A hydrated filter has rendered any option generator functions, and narrowed uncertain properties from FilterRule.
95
- */
96
- export interface HydratedFilterRule<FItem = any, FValue = any> extends Omit<FilterRule<FItem, FValue>, "options" | "required" | "isBoolean" | "hidden"> {
97
- options?: FilterOption<FValue>[];
98
- required: boolean;
99
- isBoolean: boolean;
100
- hidden: boolean;
101
- multiple: boolean;
102
- filterFn: ((item: FItem, value: FValue, meta: MetaInterface) => boolean) | ((item: FItem, value: FValue[], meta: MetaInterface) => boolean);
103
- defaultValue?: boolean | FValue | FValue[];
104
- _isHydrated: true;
105
- }
106
- export interface GroupByRule<FItem = any> {
107
- id: string;
108
- groupFn: FinderPropertySelector<FItem>;
109
- sortGroupIdFn?: FinderPropertySelector<FinderResultGroup<FItem>>;
110
- groupIdSortDirection?: SortDirection;
111
- sticky?: {
112
- header?: string | string[];
113
- footer?: string | string[];
114
- };
115
- label?: string;
116
- hidden?: boolean;
117
- }
118
- export interface SortByRule<FItem = any> {
119
- id: string;
120
- sortFn: FinderPropertySelector<FItem> | FinderPropertySelector<FItem>[];
121
- defaultSortDirection?: SortDirection;
122
- label?: string;
123
- hidden?: boolean;
124
- }
125
- export type SortDirection = "asc" | "desc" | ("asc" | "desc")[];
126
- /**
127
- * Select a property from the item to sort by.
128
- */
129
- export type FinderPropertySelector<FItem> = (item: FItem, meta: MetaInterface) => string | number;
130
- /**
131
- * Describes the display of a filter or sort option.
132
- */
133
- export interface FilterOption<FValue = any> {
134
- label: string;
135
- value: FValue;
136
- disabled?: boolean;
137
- }
138
- export interface MatchesSnapshot<FItem> {
139
- items?: FItem[];
140
- groups?: FinderResultGroup<FItem>[];
141
- numMatchedItems: number;
142
- numTotalItems: number;
143
- hasGroupByRule: boolean;
144
- }
145
- export interface FilterTestOptions {
146
- rules?: HydratedFilterRule[];
147
- values?: any;
148
- meta?: MetaInterface;
149
- isAdditive?: boolean;
150
- }
151
- export interface FilterTestRuleOptions {
152
- rule: string | FilterRuleUnion | HydratedFilterRule;
153
- value: any;
154
- meta?: MetaInterface;
155
- isAdditive?: boolean;
156
- }
157
- export interface FilterTestRuleOptionsOptions {
158
- rule: string | FilterRuleUnion | HydratedFilterRule;
159
- meta?: MetaInterface;
160
- isAdditive?: boolean;
161
- mergeExistingValue?: boolean;
162
- }
163
- export interface FinderSnapshot<FItem> {
164
- search: ReturnType<typeof readonlySearchInterface<FItem>>;
165
- filters: ReturnType<typeof readonlyFiltersInterface>;
166
- sortBy: ReturnType<typeof readonlySortByInterface<FItem>>;
167
- groupBy: ReturnType<typeof readonlyGroupByInterface<FItem>>;
168
- selectedItems: ReturnType<typeof readonlySelectedItemsInterface<FItem>>;
169
- layout: ReturnType<typeof readonlyLayoutInterface>;
170
- meta: ReturnType<typeof readonlyMetaInterface<FItem>>;
171
- updatedAt: number | undefined;
172
- }
173
- export type FinderTouchSource = "core" | "filters" | "groupBy" | "meta" | "pagination" | "search" | "selectedItems" | "sortBy" | "plugin" | "layout";
174
- type FinderSharedEventProps = {
175
- source: string;
176
- event: FinderEventName;
177
- snapshot: FinderSnapshot<any>;
178
- timestamp: number;
179
- };
180
- export interface FinderInitEvent extends FinderSharedEventProps {
181
- source: "core";
182
- event: "init";
183
- }
184
- export interface FinderFirstUserInteractionEvent extends FinderSharedEventProps {
185
- source: "core";
186
- event: "firstUserInteraction";
187
- }
188
- export interface FinderReadyEvent extends FinderSharedEventProps {
189
- source: "core";
190
- event: "ready";
191
- }
192
- export type FinderEvent = FinderInitEvent | FinderFirstUserInteractionEvent | FinderReadyEvent | FinderChangeEvent;
193
- export type FinderOnInitCallback = (event: FinderInitEvent) => void;
194
- export type FinderOnReadyCallback = (event: FinderReadyEvent) => void;
195
- export type FinderOnFirstUserInteractCallback = (event: FinderFirstUserInteractionEvent) => void;
196
- export type FinderOnChangeCallback = (event: FinderChangeEvent) => void;
197
- export type FinderTouchCallback = (event: FinderTouchEvent) => void;
198
- /**
199
- * Internal communication between mixins and core
200
- */
201
- export interface FinderTouchEvent {
202
- source: FinderTouchSource;
203
- event: FinderEventName;
204
- current: any;
205
- initial: any;
206
- }
207
- /**
208
- * External type that consumers will receive
209
- */
210
- export type FinderChangeEvent = FinderTouchEvent & FinderSharedEventProps;
211
- export type FinderEventName = "init" | "firstUserInteraction" | "ready" | "change" | "change.core" | "change.core.setIsLoading" | "change.core.setIsDisabled" | "change.core.setItems" | "change.layout" | "change.layout.set" | "change.layout.reset" | `change.filters` | "change.filters.set" | `change.groupBy` | "change.groupBy.set" | "change.groupBy.setGroupIdSortDirection" | "change.meta" | "change.meta.set" | "change.meta.delete" | "change.meta.reset" | "change.pagination" | "change.pagination.setPage" | "change.pagination.setNumItemsPerPage" | `change.plugin` | `change.plugin.${string}` | "change.search" | "change.search.setSearchTerm" | "change.search.reset" | "change.selectedItems" | "change.selectedItems.setMaxSelectedItems" | "change.selectedItems.set" | "change.selectedItems.select" | "change.selectedItems.toggle" | "change.selectedItems.delete" | "change.selectedItems.reset" | "change.sortBy" | "change.sortBy.set" | "change.sortBy.setSortDirection";
212
- export type FinderPluginFn<T extends FinderPluginInterface> = (...args: any[]) => T;
213
- export interface FinderPluginInterface<FItem = any> {
214
- id: string;
215
- register: (finder: FinderCore<FItem>, touch: FinderTouchCallback) => void;
216
- [k: string]: any;
217
- }
218
- export interface LayoutVariant {
219
- id: string;
220
- }
221
- export {};