@hitgrab/finder 0.1.0-alpha → 0.1.4-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.
- package/dist/core/__tests__/test-types.d.ts +2 -2
- package/dist/core/core-constants.d.ts +39 -0
- package/dist/core/effect-book.d.ts +12 -0
- package/dist/core/{events/event-emitter.d.ts → event-emitter.d.ts} +2 -2
- package/dist/core/filters.d.ts +28 -0
- package/dist/core/finder-core-implementation.d.ts +44 -0
- package/dist/core/finder-core.d.ts +56 -45
- package/dist/core/finder-error.d.ts +3 -0
- package/dist/core/{group-by/group-by.d.ts → group-by.d.ts} +6 -5
- package/dist/core/{pagination/pagination.d.ts → pagination.d.ts} +1 -1
- package/dist/core/{rule-book/rule-book.d.ts → rule-book.d.ts} +3 -3
- package/dist/core/search/calculate-character-match-indexes.d.ts +1 -0
- package/dist/core/search/{result-segments/search-result-segments.d.ts → calculate-string-match-segments.d.ts} +3 -3
- package/dist/core/search/{result-segments/result-segment-haystack.d.ts → string-match-haystack.d.ts} +3 -3
- package/dist/core/{search/search.d.ts → search.d.ts} +5 -5
- package/dist/core/{sort-by/sort-by.d.ts → sort-by.d.ts} +9 -5
- package/dist/core/{tester/tester.d.ts → tester.d.ts} +1 -1
- package/dist/core/types/core-types.d.ts +16 -15
- package/dist/core/types/effect-types.d.ts +0 -2
- package/dist/core/types/event-types.d.ts +5 -4
- package/dist/core/types/rule-types.d.ts +8 -12
- package/dist/core/types/string-match-types.d.ts +10 -0
- package/dist/core/utils/rule-type-enforcers.d.ts +5 -3
- package/dist/core/utils/rule-utils.d.ts +2 -4
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3265 -3196
- package/dist/index.umd.cjs +19 -19
- package/dist/react/components/finder-search-term-haystack.d.ts +8 -0
- package/dist/react/components/finder.d.ts +2 -2
- package/dist/react/components/string-match.d.ts +12 -0
- package/dist/react/types/react-types.d.ts +8 -5
- package/package.json +11 -10
- package/dist/core/effect-book/effect-book.d.ts +0 -8
- package/dist/core/filters/filters-interface.d.ts +0 -31
- package/dist/core/filters/filters.d.ts +0 -28
- package/dist/core/group-by/group-by-interface.d.ts +0 -21
- package/dist/core/pagination/pagination-interface.d.ts +0 -23
- package/dist/core/search/algorithms/sequential-characters.d.ts +0 -1
- package/dist/core/search/algorithms/sequential-string.d.ts +0 -1
- package/dist/core/search/result-segments/result-segment-types.d.ts +0 -17
- package/dist/core/search/search-interface.d.ts +0 -15
- package/dist/core/sort-by/sort-by-interface.d.ts +0 -23
- package/dist/core/utils/finder-utils.d.ts +0 -3
- package/dist/react/components/finder-search-term.d.ts +0 -8
- package/dist/react/hooks/use-finder-constructor.d.ts +0 -7
- /package/dist/core/{debounce-callback-registry/debounce-callback-registry.d.ts → debounce-callback-registry.d.ts} +0 -0
|
@@ -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,11 @@
|
|
|
1
|
-
import { EventCallback } from "
|
|
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
|
|
8
|
+
off(event: EventNames, callback?: EventCallback): void;
|
|
9
9
|
emit(event: EventNames, payload?: any): void;
|
|
10
10
|
silently(callback: CallableFunction): void;
|
|
11
11
|
isSilent(): boolean;
|
|
@@ -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,86 +1,97 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FinderConstructorOptions, SnapshotSerializedMixins } from "./types/core-types";
|
|
2
2
|
import { FinderRule } from "./types/rule-types";
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
disabled: boolean;
|
|
9
|
-
updatedAt?: number;
|
|
10
|
-
context: FContext;
|
|
11
|
-
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>);
|
|
12
|
-
emitFirstUserInteraction(): void;
|
|
8
|
+
constructor(items: FItem[] | null | undefined, options: FinderConstructorOptions<FItem>);
|
|
13
9
|
get items(): FItem[];
|
|
14
|
-
get
|
|
15
|
-
|
|
10
|
+
get context(): FContext;
|
|
11
|
+
get isReady(): boolean;
|
|
16
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>;
|
|
17
28
|
get search(): {
|
|
18
|
-
setSearchTerm: (incomingSearchTerm: string) => void;
|
|
19
|
-
reset: () => void;
|
|
20
|
-
test: (searchTerm: string, isAdditive?: boolean) => FItem[];
|
|
21
29
|
searchTerm: string;
|
|
22
30
|
hasSearchTerm: boolean;
|
|
23
31
|
hasSearchRule: boolean;
|
|
32
|
+
setSearchTerm: (incomingSearchTerm: string) => void;
|
|
33
|
+
reset: () => void;
|
|
34
|
+
test: (searchTerm: string, isAdditive?: boolean) => FItem[];
|
|
24
35
|
};
|
|
25
36
|
get filters(): {
|
|
26
|
-
toggle: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule, optionValue?: import("..").FilterOption | any) => void;
|
|
27
|
-
set: <FItem_1, FValue>(identifier: string | import("..").FilterRuleUnion<FItem_1, FValue> | import("..").HydratedFilterRule<FItem_1, FValue, any>, incomingFilterValue: FValue | FValue[]) => void;
|
|
28
|
-
delete: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule) => void;
|
|
29
|
-
test: (options: import("./types/rule-types").FilterTestOptions) => any[];
|
|
30
|
-
testRule: ({ rule: identifier, value, ...options }: import("./types/rule-types").FilterTestRuleOptions) => any[];
|
|
31
|
-
testRuleOptions: ({ rule: identifier, ...options }: import("./types/rule-types").FilterTestRuleOptionsOptions) => Map<any, any>;
|
|
32
37
|
values: Record<string, any>;
|
|
33
38
|
raw: Record<string, any>;
|
|
34
39
|
activeRules: import("..").HydratedFilterRule<unknown, any, any>[];
|
|
35
40
|
rules: import("..").HydratedFilterRule<unknown, any, any>[];
|
|
36
|
-
isActive: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule) => boolean;
|
|
37
|
-
get: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule) => any;
|
|
38
|
-
has: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule, optionValue?:
|
|
39
|
-
getRule: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule) => import("..").HydratedFilterRule<any, 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>;
|
|
40
51
|
};
|
|
41
52
|
get sortBy(): {
|
|
42
|
-
set: (identifier?: string | import("..").SortByRule, incomingSortDirection?: import("..").SortDirection) => void;
|
|
43
|
-
setSortDirection: (incomingSortDirection?: import("..").SortDirection) => void;
|
|
44
|
-
cycleSortDirection: () => void;
|
|
45
|
-
toggleSortDirection: () => void;
|
|
46
|
-
reset(): void;
|
|
47
53
|
activeRule: import("..").SortByRule<unknown, any> | undefined;
|
|
48
54
|
sortDirection: import("..").SortDirection;
|
|
49
55
|
userHasSetSortDirection: boolean;
|
|
50
56
|
rules: import("..").SortByRule<unknown, any>[];
|
|
57
|
+
set: (identifier?: string | import("..").SortByRule, incomingSortDirection?: import("..").SortDirection) => void;
|
|
58
|
+
setSortDirection: (incomingSortDirection?: import("..").SortDirection) => void;
|
|
59
|
+
cycleSortDirection: () => void;
|
|
60
|
+
toggleSortDirection: () => void;
|
|
61
|
+
reset: () => void;
|
|
51
62
|
};
|
|
52
63
|
get groupBy(): {
|
|
53
|
-
set: (identifier?: string | import("..").GroupByRule) => void;
|
|
54
|
-
toggle: (identifier: import("..").GroupByRule | string) => void;
|
|
55
|
-
setGroupIdSortDirection: (direction?: import("..").SortDirection) => void;
|
|
56
|
-
reset: () => void;
|
|
57
64
|
activeRule: import("..").GroupByRule<unknown, any> | undefined;
|
|
58
65
|
requireGroup: boolean;
|
|
59
66
|
rules: import("..").GroupByRule<unknown, any>[];
|
|
60
67
|
groupIdSortDirection: import("..").SortDirection | undefined;
|
|
68
|
+
set: (identifier?: string | import("..").GroupByRule) => void;
|
|
69
|
+
toggle: (identifier: import("..").GroupByRule | string) => void;
|
|
70
|
+
setGroupSortDirection: (direction?: import("..").SortDirection) => void;
|
|
71
|
+
reset: () => void;
|
|
61
72
|
};
|
|
62
73
|
get pagination(): {
|
|
63
|
-
setPage: (value: number) => void;
|
|
64
|
-
setNumItemsPerPage: (value?: number) => void;
|
|
65
74
|
page: number;
|
|
66
75
|
offset: number;
|
|
67
76
|
numItemsPerPage: number | undefined;
|
|
68
77
|
numTotalItems: number;
|
|
69
78
|
lastPage: number | undefined;
|
|
70
79
|
isPaginated: boolean;
|
|
80
|
+
setPage: (value: number) => void;
|
|
81
|
+
setNumItemsPerPage: (value?: number) => void;
|
|
71
82
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
silently: (callback: EventCallback) => void;
|
|
76
|
-
isSilent: () => boolean;
|
|
77
|
-
};
|
|
78
|
-
getRule<Rule>(identifier: string | FinderRule<FItem>): Rule;
|
|
79
|
-
get state(): "loading" | "empty" | "groups" | "items" | "noMatches";
|
|
83
|
+
/**
|
|
84
|
+
* Mutators
|
|
85
|
+
*/
|
|
80
86
|
setItems(items: FItem[] | null | undefined): void;
|
|
81
87
|
setIsLoading(value?: boolean): void;
|
|
82
88
|
setIsDisabled(value?: boolean): void;
|
|
83
|
-
setRules(definitions: FinderRule<FItem
|
|
89
|
+
setRules(definitions: FinderRule<FItem>[]): void;
|
|
84
90
|
setContext(context: FContext): void;
|
|
91
|
+
/**
|
|
92
|
+
* Utils
|
|
93
|
+
*/
|
|
94
|
+
test(mixins: SnapshotSerializedMixins, isAdditive?: boolean): FItem[];
|
|
95
|
+
getRule(identifier: string | FinderRule<FItem>): FinderRule<FItem>;
|
|
85
96
|
}
|
|
86
97
|
export { FinderCore };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GroupByRule } from "
|
|
2
|
-
import { FinderResultGroup, MixinInjectedDependencies, SerializedGroupByMixin, SortDirection } from "
|
|
1
|
+
import { GroupByRule } from "./types/rule-types";
|
|
2
|
+
import { FinderResultGroup, MixinInjectedDependencies, SerializedGroupByMixin, SortDirection } from "./types/core-types";
|
|
3
3
|
interface InitialValues {
|
|
4
4
|
initialGroupBy: string | undefined;
|
|
5
5
|
requireGroup: boolean;
|
|
@@ -7,16 +7,17 @@ interface InitialValues {
|
|
|
7
7
|
declare class GroupByMixin<FItem, FContext> {
|
|
8
8
|
#private;
|
|
9
9
|
requireGroup: boolean;
|
|
10
|
-
groupIdSortDirection?: SortDirection;
|
|
11
10
|
constructor({ initialGroupBy, requireGroup }: InitialValues, deps: MixinInjectedDependencies<FItem, FContext>);
|
|
11
|
+
getRule(identifier: string | GroupByRule): GroupByRule<unknown, any>;
|
|
12
12
|
get rules(): GroupByRule<unknown, any>[];
|
|
13
13
|
get activeRule(): GroupByRule<unknown, any> | undefined;
|
|
14
14
|
get hasGroupByRule(): boolean;
|
|
15
|
+
get groupSortDirection(): SortDirection | undefined;
|
|
15
16
|
set(identifier?: string | GroupByRule): void;
|
|
16
|
-
|
|
17
|
+
setGroupSortDirection(direction?: SortDirection): void;
|
|
17
18
|
toggle(identifier: GroupByRule | string): void;
|
|
18
19
|
reset(): void;
|
|
19
20
|
serialize(): SerializedGroupByMixin;
|
|
20
|
-
static process<FItem
|
|
21
|
+
static process<FItem>(options: SerializedGroupByMixin, items: FItem[], context?: unknown): FinderResultGroup<FItem>[];
|
|
21
22
|
}
|
|
22
23
|
export { GroupByMixin };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MixinInjectedDependencies, SerializedPaginationMixin } from "
|
|
1
|
+
import { MixinInjectedDependencies, SerializedPaginationMixin } from "./types/core-types";
|
|
2
2
|
interface InitialValues {
|
|
3
3
|
page: number | undefined;
|
|
4
4
|
numItemsPerPage: number | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FinderRule } from "
|
|
1
|
+
import { FinderRule } from "./types/rule-types";
|
|
2
2
|
/**
|
|
3
3
|
* Stores rule definitions and hydrated rules
|
|
4
4
|
*/
|
|
@@ -6,8 +6,8 @@ export declare class RuleBook<FItem, FContext> {
|
|
|
6
6
|
#private;
|
|
7
7
|
rules: FinderRule<FItem>[];
|
|
8
8
|
constructor(definitions: FinderRule<FItem>[], items: FItem[], context: FContext);
|
|
9
|
-
hydrateDefinitions
|
|
10
|
-
getRule
|
|
9
|
+
hydrateDefinitions(items: FItem[], context: FContext): void;
|
|
10
|
+
getRule(identifier: string | FinderRule): FinderRule<FItem>;
|
|
11
11
|
getDefinitions(): FinderRule<FItem>[];
|
|
12
12
|
setRules(definitions: FinderRule<FItem>[]): void;
|
|
13
13
|
static validateDefinitions(definitions: FinderRule[]): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function calculateCharacterMatchIndexes(haystack: string, needle: string): number[] | undefined;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StringMatchSegment } from "../types/string-match-types";
|
|
2
2
|
/**
|
|
3
3
|
* Helper function to determine which specfic characters are matched inside a string.
|
|
4
4
|
*/
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function calculateStringMatchSegments(haystack: string | string[], needle: string): StringMatchSegment[] | undefined;
|
|
6
6
|
/**
|
|
7
7
|
* Determine if a characterIndexFn would return a result for a haystack.
|
|
8
8
|
*/
|
|
9
|
-
export declare function hasCharacterIndexMatches(haystack: string | string[], needle: string
|
|
9
|
+
export declare function hasCharacterIndexMatches(haystack: string | string[], needle: string): boolean;
|
package/dist/core/search/{result-segments/result-segment-haystack.d.ts → string-match-haystack.d.ts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare class
|
|
1
|
+
export declare class StringMatchHaystack {
|
|
2
2
|
#private;
|
|
3
3
|
source: string;
|
|
4
4
|
transformed: string;
|
|
@@ -9,7 +9,7 @@ export declare class ResultSegmentHaystack {
|
|
|
9
9
|
*/
|
|
10
10
|
static composeTransformedHaystackSegments(haystack: string): {
|
|
11
11
|
value: string;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
index: number;
|
|
13
|
+
length: number;
|
|
14
14
|
}[];
|
|
15
15
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { MixinInjectedDependencies, SerializedSearchMixin } from "
|
|
2
|
-
|
|
1
|
+
import { MixinInjectedDependencies, SerializedSearchMixin } from "./types/core-types";
|
|
2
|
+
interface InitialValues {
|
|
3
3
|
initialSearchTerm: string | undefined;
|
|
4
|
-
}
|
|
4
|
+
}
|
|
5
5
|
declare class SearchMixin<FItem> {
|
|
6
6
|
#private;
|
|
7
7
|
searchTerm: string;
|
|
8
8
|
constructor({ initialSearchTerm }: InitialValues, deps: MixinInjectedDependencies<FItem>);
|
|
9
|
-
get rule(): import("
|
|
9
|
+
get rule(): import("..").SearchRule<unknown, any> | undefined;
|
|
10
10
|
get hasSearchRule(): boolean;
|
|
11
11
|
get hasSearchTerm(): boolean;
|
|
12
12
|
setSearchTerm(incomingSearchTerm: string): void;
|
|
13
13
|
reset(): void;
|
|
14
14
|
serialize(): SerializedSearchMixin;
|
|
15
15
|
test(searchTerm: string, isAdditive?: boolean): FItem[];
|
|
16
|
-
static process<FItem
|
|
16
|
+
static process<FItem>(options: SerializedSearchMixin, items: FItem[], context?: unknown): FItem[];
|
|
17
17
|
}
|
|
18
18
|
export { SearchMixin };
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import { SortByRule } from "
|
|
2
|
-
import { MixinInjectedDependencies, SerializedSortByMixin, SortDirection } from "
|
|
3
|
-
|
|
1
|
+
import { SortByRule } from "./types/rule-types";
|
|
2
|
+
import { MixinInjectedDependencies, SerializedSortByMixin, SortDirection } from "./types/core-types";
|
|
3
|
+
interface InitialValues {
|
|
4
4
|
initialSortBy: string | undefined;
|
|
5
5
|
initialSortDirection?: SortDirection;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
7
|
declare class SortByMixin<FItem> {
|
|
8
8
|
#private;
|
|
9
9
|
constructor({ initialSortBy, initialSortDirection }: InitialValues, deps: MixinInjectedDependencies<FItem>);
|
|
10
|
+
getRule(identifier: string | SortByRule): SortByRule<unknown, any>;
|
|
10
11
|
get rules(): SortByRule<unknown, any>[];
|
|
11
12
|
get activeRule(): SortByRule<unknown, any> | undefined;
|
|
12
13
|
get sortDirection(): SortDirection;
|
|
13
14
|
get userHasSetSortDirection(): boolean;
|
|
14
15
|
setSortDirection(incomingSortDirection?: SortDirection): void;
|
|
16
|
+
cycleSortDirection(): void;
|
|
17
|
+
toggleSortDirection(): void;
|
|
15
18
|
set(identifier?: string | SortByRule, incomingSortDirection?: SortDirection): void;
|
|
19
|
+
reset(): void;
|
|
16
20
|
serialize(): SerializedSortByMixin;
|
|
17
|
-
static process<FItem
|
|
21
|
+
static process<FItem>(options: SerializedSortByMixin, items: FItem[], context: unknown): FItem[];
|
|
18
22
|
}
|
|
19
23
|
export { SortByMixin };
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { DebounceCallbackRegistry } from "../debounce-callback-registry
|
|
2
|
-
import {
|
|
3
|
-
import { readonlyGroupByInterface } from "../group-by/group-by-interface";
|
|
4
|
-
import { RuleBook } from "../rule-book/rule-book";
|
|
5
|
-
import { readonlySearchInterface } from "../search/search-interface";
|
|
6
|
-
import { readonlySortByInterface } from "../sort-by/sort-by-interface";
|
|
1
|
+
import { DebounceCallbackRegistry } from "../debounce-callback-registry";
|
|
2
|
+
import { RuleBook } from "../rule-book";
|
|
7
3
|
import { RuleEffect, SearchEffect } from "./effect-types";
|
|
8
4
|
import { FinderOnChangeCallback, FinderOnFirstUserInteractCallback, FinderOnInitCallback, FinderOnReadyCallback, FinderTouchCallback } from "./event-types";
|
|
9
5
|
import { FinderRule, GroupByRule, HydratedFilterRule, SearchRule, SortByRule } from "./rule-types";
|
|
@@ -39,20 +35,11 @@ export interface ResultSnapshot<FItem> {
|
|
|
39
35
|
numTotalItems: number;
|
|
40
36
|
hasGroupByRule: boolean;
|
|
41
37
|
}
|
|
42
|
-
export interface FinderSnapshot<FItem, FContext = any> {
|
|
43
|
-
search: ReturnType<typeof readonlySearchInterface<FItem>>;
|
|
44
|
-
filters: ReturnType<typeof readonlyFiltersInterface>;
|
|
45
|
-
sortBy: ReturnType<typeof readonlySortByInterface<FItem>>;
|
|
46
|
-
groupBy: ReturnType<typeof readonlyGroupByInterface<FItem, FContext>>;
|
|
47
|
-
context?: FContext;
|
|
48
|
-
updatedAt?: number;
|
|
49
|
-
}
|
|
50
38
|
export interface MixinInjectedDependencies<FItem = any, FContext = any> {
|
|
51
39
|
isLoading: () => boolean;
|
|
52
40
|
isDisabled: () => boolean;
|
|
53
41
|
getRuleBook: () => RuleBook<FItem, FContext>;
|
|
54
42
|
touch: FinderTouchCallback;
|
|
55
|
-
getContext: () => any;
|
|
56
43
|
getItems: () => FItem[];
|
|
57
44
|
test: (serializedMixins: SnapshotSerializedMixins, isAdditive?: boolean) => FItem[];
|
|
58
45
|
debouncer: DebounceCallbackRegistry;
|
|
@@ -90,3 +77,17 @@ export interface SerializedGroupByMixin {
|
|
|
90
77
|
rule?: GroupByRule;
|
|
91
78
|
sortDirection?: SortDirection;
|
|
92
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
|
+
}
|
|
@@ -12,11 +12,9 @@ export interface HydratedRuleEffect<FItem = any, FContext = any> {
|
|
|
12
12
|
export interface SearchEffect<FItem = any, FContext = any> {
|
|
13
13
|
haystack: string | string[] | ((items: FItem[], context: FContext) => string | string[]);
|
|
14
14
|
onChange: (instance: FinderCore<FItem, FContext>) => void;
|
|
15
|
-
exact?: boolean;
|
|
16
15
|
}
|
|
17
16
|
export interface HydratedSearchEffect<FItem = any, FContext = any> {
|
|
18
17
|
haystack: string[];
|
|
19
18
|
onChange: (instance: FinderCore<FItem, FContext>) => void;
|
|
20
|
-
exact: boolean;
|
|
21
19
|
_isHydrated: true;
|
|
22
20
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EVENT_SOURCE, EVENTS } from "../core-constants";
|
|
2
|
+
import { FinderCore } from "../finder-core";
|
|
2
3
|
import { FinderRule } from "./rule-types";
|
|
3
|
-
export type FinderTouchSource =
|
|
4
|
+
export type FinderTouchSource = (typeof EVENT_SOURCE)[keyof typeof EVENT_SOURCE];
|
|
4
5
|
interface FinderSharedEventProps {
|
|
5
6
|
source: string;
|
|
6
7
|
event: FinderEventName;
|
|
7
|
-
snapshot: FinderSnapshot<any>;
|
|
8
8
|
timestamp: number;
|
|
9
|
+
instance: FinderCore;
|
|
9
10
|
}
|
|
10
11
|
export interface FinderInitEvent extends FinderSharedEventProps {
|
|
11
12
|
source: "core";
|
|
@@ -39,5 +40,5 @@ export interface FinderTouchEvent {
|
|
|
39
40
|
* External type that consumers will receive
|
|
40
41
|
*/
|
|
41
42
|
export type FinderChangeEvent = FinderTouchEvent & FinderSharedEventProps;
|
|
42
|
-
export type FinderEventName =
|
|
43
|
+
export type FinderEventName = (typeof EVENTS)[keyof typeof EVENTS];
|
|
43
44
|
export {};
|
|
@@ -4,6 +4,7 @@ import { FinderResultGroup, SortDirection } from "./core-types";
|
|
|
4
4
|
*/
|
|
5
5
|
export type FinderPropertySelector<FItem, FContext = any> = (item: FItem, context?: FContext) => string | number;
|
|
6
6
|
export type FinderRule<FItem = any, FContext = any> = SearchRule<FItem, FContext> | FilterRuleUnion<FItem, FContext> | HydratedFilterRule<FItem, FContext> | SortByRule<FItem, FContext> | GroupByRule<FItem, FContext>;
|
|
7
|
+
export type HydratedFinderRule<FItem = any, FContext = any> = SearchRule<FItem, FContext> | HydratedFilterRule<FItem, FContext> | SortByRule<FItem, FContext> | GroupByRule<FItem, FContext>;
|
|
7
8
|
export interface SearchRule<FItem = any, FContext = any> {
|
|
8
9
|
id?: string;
|
|
9
10
|
label?: string;
|
|
@@ -30,30 +31,26 @@ export interface FilterRule<FItem = any, FValue = any, FContext = any> {
|
|
|
30
31
|
label?: string;
|
|
31
32
|
hidden?: boolean;
|
|
32
33
|
debounceMilliseconds?: number;
|
|
33
|
-
multiple?: boolean;
|
|
34
|
-
boolean?: boolean;
|
|
35
|
-
filterFn: CallableFunction;
|
|
36
|
-
defaultValue?: any;
|
|
37
34
|
}
|
|
38
|
-
interface FilterRuleWithBooleanValue<FItem,
|
|
35
|
+
export interface FilterRuleWithBooleanValue<FItem, FContext = any> extends FilterRule<FItem> {
|
|
39
36
|
multiple?: false;
|
|
40
37
|
boolean: true;
|
|
41
|
-
filterFn: (item: FItem, value:
|
|
38
|
+
filterFn: (item: FItem, value: boolean, context?: FContext) => boolean;
|
|
42
39
|
defaultValue?: boolean;
|
|
43
40
|
}
|
|
44
|
-
interface
|
|
41
|
+
export interface FilterRuleWithSingleValue<FItem, FValue, FContext = any> extends FilterRule<FItem, FValue, FContext> {
|
|
45
42
|
multiple?: false;
|
|
46
43
|
boolean?: false;
|
|
47
44
|
filterFn: (item: FItem, value: FValue, context?: FContext) => boolean;
|
|
48
45
|
defaultValue?: FValue;
|
|
49
46
|
}
|
|
50
|
-
interface FilterRuleWithMultipleValues<FItem, FValue, FContext = any> extends FilterRule<FItem, FValue, FContext> {
|
|
47
|
+
export interface FilterRuleWithMultipleValues<FItem, FValue, FContext = any> extends FilterRule<FItem, FValue, FContext> {
|
|
51
48
|
multiple: true;
|
|
52
49
|
boolean?: false;
|
|
53
50
|
filterFn: (item: FItem, value: FValue[], context?: FContext) => boolean;
|
|
54
51
|
defaultValue?: FValue[];
|
|
55
52
|
}
|
|
56
|
-
export type FilterRuleUnion<FItem = any, FValue = any> = FilterRuleWithBooleanValue<FItem> |
|
|
53
|
+
export type FilterRuleUnion<FItem = any, FValue = any> = FilterRuleWithBooleanValue<FItem> | FilterRuleWithSingleValue<FItem, FValue> | FilterRuleWithMultipleValues<FItem, FValue>;
|
|
57
54
|
/**
|
|
58
55
|
* A hydrated filter has rendered any option generator functions, and narrowed ambiguous properties from FilterRule.
|
|
59
56
|
*/
|
|
@@ -77,8 +74,8 @@ export interface SortByRule<FItem = any, FContext = any> {
|
|
|
77
74
|
export interface GroupByRule<FItem = any, FContext = any> {
|
|
78
75
|
id: string;
|
|
79
76
|
groupFn: FinderPropertySelector<FItem, FContext>;
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
sortGroupFn?: FinderPropertySelector<FinderResultGroup<FItem>, FContext>;
|
|
78
|
+
defaultGroupSortDirection?: SortDirection;
|
|
82
79
|
sticky?: {
|
|
83
80
|
header?: string | string[];
|
|
84
81
|
footer?: string | string[];
|
|
@@ -105,4 +102,3 @@ export interface FilterTestRuleOptionsOptions {
|
|
|
105
102
|
isAdditive?: boolean;
|
|
106
103
|
mergeExistingValue?: boolean;
|
|
107
104
|
}
|
|
108
|
-
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These values all point to the transformed haystack.
|
|
3
|
+
*/
|
|
4
|
+
export interface StringMatchSegment {
|
|
5
|
+
index: number;
|
|
6
|
+
length: number;
|
|
7
|
+
is_match: boolean;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
export type SearchCharacterIndexFn = (haystack: string, needle: string) => number[] | undefined;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { FinderCore } from "../finder-core";
|
|
2
2
|
import { RuleEffect, SearchEffect } from "../types/effect-types";
|
|
3
|
-
import {
|
|
3
|
+
import { FilterRuleWithBooleanValue, FilterRuleWithMultipleValues, FilterRuleWithSingleValue, FinderRule, GroupByRule, SearchRule, SortByRule } from "../types/rule-types";
|
|
4
4
|
/**
|
|
5
5
|
* Enforce structure for an array of rule of mixed types.
|
|
6
6
|
*/
|
|
7
7
|
export declare function finderRuleset<FItem>(rules: FinderRule<FItem>[]): FinderRule<FItem>[];
|
|
8
8
|
export declare function searchRule<FItem>(rule: SearchRule<FItem>): SearchRule<FItem, any>;
|
|
9
|
-
export declare function filterRule<FItem, FValue = any
|
|
9
|
+
export declare function filterRule<FItem, FValue = any, T = FilterRuleWithMultipleValues<FItem, FValue>>(rule: T): FilterRuleWithMultipleValues<FItem, FValue>;
|
|
10
|
+
export declare function filterRule<FItem, FValue = any, T = FilterRuleWithBooleanValue<FItem, FValue>>(rule: T): FilterRuleWithBooleanValue<FItem, FValue>;
|
|
11
|
+
export declare function filterRule<FItem, FValue = any, T = FilterRuleWithSingleValue<FItem, FValue>>(rule: T): FilterRuleWithSingleValue<FItem, FValue>;
|
|
10
12
|
export declare function sortByRule<FItem>(rule: SortByRule<FItem>): SortByRule<FItem, any>;
|
|
11
13
|
export declare function groupByRule<FItem>(rule: GroupByRule<FItem>): GroupByRule<FItem, any>;
|
|
12
14
|
export declare function ruleEffect<FItem, FContext = any>(rules: string | FinderRule<FItem> | (string | FinderRule<FItem>)[] | ((items: FItem[], context: FContext) => string | FinderRule<FItem> | (string | FinderRule<FItem>)[]), onChange: (instance: FinderCore<FItem, FContext>) => void): RuleEffect<FItem, FContext>;
|
|
13
|
-
export declare function searchEffect<FItem, FContext = any>(haystack: string | string[] | ((items: FItem[], context: FContext) => string | string[]), onChange: (instance: FinderCore<FItem, FContext>) => void
|
|
15
|
+
export declare function searchEffect<FItem, FContext = any>(haystack: string | string[] | ((items: FItem[], context: FContext) => string | string[]), onChange: (instance: FinderCore<FItem, FContext>) => void): SearchEffect<FItem, FContext>;
|