@hitgrab/finder 0.1.17-alpha → 0.1.18-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__/json.test.d.ts +1 -0
- package/dist/core/core-constants.d.ts +4 -0
- package/dist/core/debounce-callback-registry.d.ts +2 -2
- package/dist/core/effect-book.d.ts +2 -2
- package/dist/core/filters.d.ts +10 -9
- package/dist/core/finder-core-implementation.d.ts +5 -4
- package/dist/core/finder-core.d.ts +25 -23
- package/dist/core/group-by.d.ts +10 -8
- package/dist/core/rule-book/boolean-filter-handler.d.ts +11 -0
- package/dist/core/rule-book/filter-handler.d.ts +29 -0
- package/dist/core/{filter-utils/multiple-filter.d.ts → rule-book/multiple-filter-handler.d.ts} +3 -2
- package/dist/core/rule-book/rule-book.d.ts +14 -0
- package/dist/core/rule-book/single-filter-handler.d.ts +11 -0
- package/dist/core/search.d.ts +1 -1
- package/dist/core/sort-by.d.ts +5 -5
- package/dist/core/types/core-types.d.ts +9 -12
- package/dist/core/types/effect-types.d.ts +5 -5
- package/dist/core/types/event-types.d.ts +2 -2
- package/dist/core/types/rule-types.d.ts +25 -29
- package/dist/core/utils/rule-type-enforcers.d.ts +10 -7
- package/dist/core/utils/rule-utils.d.ts +13 -8
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2084 -1992
- package/dist/index.umd.cjs +13 -13
- package/dist/react/components/finder.d.ts +1 -1
- package/package.json +1 -1
- package/dist/core/filter-utils/boolean-filter.d.ts +0 -10
- package/dist/core/filter-utils/filter-factory.d.ts +0 -18
- package/dist/core/filter-utils/single-filter.d.ts +0 -10
- package/dist/core/rule-book.d.ts +0 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -10,6 +10,7 @@ export declare const EVENTS: {
|
|
|
10
10
|
readonly SET_SEARCH_TERM: "setSearchTerm";
|
|
11
11
|
readonly RESET_SEARCH_TERM: "resetSearchTerm";
|
|
12
12
|
readonly SET_FILTER: "setFilter";
|
|
13
|
+
readonly RESET_FILTERS: "resetFilters";
|
|
13
14
|
readonly SET_SORT_BY: "setSortBy";
|
|
14
15
|
readonly SET_SORT_BY_DIRECTION: "setSortDirection";
|
|
15
16
|
readonly SET_GROUP_BY: "setGroupBy";
|
|
@@ -30,6 +31,8 @@ export declare const ERRORS: {
|
|
|
30
31
|
RULE_NOT_FOUND: string;
|
|
31
32
|
WRONG_RULE_TYPE_FOR_MIXIN: string;
|
|
32
33
|
NO_SEARCH_RULE_SET: string;
|
|
34
|
+
INVALID_SEARCH_TERM_TYPE: string;
|
|
35
|
+
NO_MATCHING_OPTION_FOUND_WITH_STRICT_OPTIONS: string;
|
|
33
36
|
SETTING_MULTIPLE_FILTER_WITHOUT_ARRAY: string;
|
|
34
37
|
ADDING_OPTION_TO_MULTIPLE_FILTER_WITHOUT_OPTION_VALUE: string;
|
|
35
38
|
DELETING_OPTION_VALUE_FROM_NON_MULTIPLE_FILTER: string;
|
|
@@ -39,6 +42,7 @@ export declare const ERRORS: {
|
|
|
39
42
|
TOGGLING_OPTION_ON_RULE_WITH_SINGLE_VALUE: string;
|
|
40
43
|
TOGGLING_OPTION_THAT_DOES_NOT_EXIST: string;
|
|
41
44
|
TOGGLING_OPTION_WITHOUT_PASSING_OPTION: string;
|
|
45
|
+
TOGGLING_BOOLEAN_FILTER_WITH_UNUSED_VALUE: string;
|
|
42
46
|
TESTING_OPTIONS_ON_RULE_WITH_NO_OPTIONS: string;
|
|
43
47
|
INVALID_RULE_WITHOUT_ID: string;
|
|
44
48
|
INVALID_RULE_SHAPE: string;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare function DebounceCallbackRegistry(): (rule:
|
|
1
|
+
import { RuleDefinition } from "./types/rule-types";
|
|
2
|
+
declare function DebounceCallbackRegistry(): (rule: RuleDefinition, callback: () => void) => any;
|
|
3
3
|
export { DebounceCallbackRegistry };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { FinderCore } from "./finder-core";
|
|
2
2
|
import { HydratedRuleEffect, HydratedSearchEffect, RuleEffect, SearchEffect } from "./types/effect-types";
|
|
3
|
-
import {
|
|
3
|
+
import { RuleDefinition } from "./types/rule-types";
|
|
4
4
|
export declare class EffectBook<FItem, FContext> {
|
|
5
5
|
#private;
|
|
6
6
|
searchEffects: HydratedSearchEffect[];
|
|
7
7
|
ruleEffects: HydratedRuleEffect[];
|
|
8
8
|
constructor(effects: (RuleEffect | SearchEffect)[], items: FItem[], context: FContext);
|
|
9
9
|
hydrateDefinitions(items: FItem[], context: FContext): void;
|
|
10
|
-
processRule(rule:
|
|
10
|
+
processRule(rule: RuleDefinition, instance: FinderCore): void;
|
|
11
11
|
processSearchTerm(searchTerm: string, instance: FinderCore): void;
|
|
12
12
|
}
|
package/dist/core/filters.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyFilterRuleDefinition, FilterOption, FilterTestOptions, FilterTestRuleOptions } from "./types/rule-types";
|
|
2
2
|
import { MixinInjectedDependencies, SerializedFiltersMixin } from "./types/core-types";
|
|
3
3
|
interface InitialValues {
|
|
4
4
|
initialFilters: Record<string, any> | undefined;
|
|
5
5
|
}
|
|
6
|
-
type FilterRuleIdentifier = string |
|
|
6
|
+
type FilterRuleIdentifier<FValue = any> = string | AnyFilterRuleDefinition<any, FValue>;
|
|
7
7
|
declare class FiltersMixin {
|
|
8
8
|
#private;
|
|
9
9
|
constructor({ initialFilters }: InitialValues, deps: MixinInjectedDependencies);
|
|
10
|
-
set<FValue>(identifier: FilterRuleIdentifier
|
|
11
|
-
get rules():
|
|
12
|
-
get activeRules():
|
|
10
|
+
set<FValue>(identifier: FilterRuleIdentifier<FValue>, value?: FValue | FValue[]): void;
|
|
11
|
+
get rules(): import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>[];
|
|
12
|
+
get activeRules(): import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>[];
|
|
13
13
|
get(identifier: FilterRuleIdentifier): any;
|
|
14
14
|
has(identifier: FilterRuleIdentifier, optionValue?: any): boolean;
|
|
15
|
-
getRule(identifier: FilterRuleIdentifier):
|
|
16
|
-
add(identifier: FilterRuleIdentifier
|
|
17
|
-
delete(identifier: FilterRuleIdentifier
|
|
15
|
+
getRule(identifier: FilterRuleIdentifier): import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>;
|
|
16
|
+
add<FValue>(identifier: FilterRuleIdentifier<FValue>, optionValue?: FValue | FilterOption<FValue>): void;
|
|
17
|
+
delete<FValue>(identifier: FilterRuleIdentifier<FValue>, optionValue?: FValue | FilterOption<FValue>): void;
|
|
18
|
+
toggle<FValue>(identifier: FilterRuleIdentifier<FValue>, optionValue?: FValue | FilterOption<FValue>): void;
|
|
19
|
+
reset(): void;
|
|
18
20
|
isRuleActive(identifier: FilterRuleIdentifier): boolean;
|
|
19
|
-
toggle(identifier: FilterRuleIdentifier, optionValue?: any): void;
|
|
20
21
|
test(options: FilterTestOptions): any[];
|
|
21
22
|
testRule({ rule: identifier, value, ...options }: FilterTestRuleOptions): any[];
|
|
22
23
|
testRuleOptions(identifier: FilterRuleIdentifier, isAdditive?: boolean): Map<any, any>;
|
|
@@ -6,7 +6,7 @@ import { PaginationMixin } from "./pagination";
|
|
|
6
6
|
import { FinderCore } from "./finder-core";
|
|
7
7
|
import { FinderConstructorOptions, SnapshotSerializedMixins, EventCallback } from "./types/core-types";
|
|
8
8
|
import { FinderEventName } from "./types/event-types";
|
|
9
|
-
import {
|
|
9
|
+
import { RuleDefinition } from "./types/rule-types";
|
|
10
10
|
declare class FinderCoreImplementation<FItem, FContext = any> {
|
|
11
11
|
#private;
|
|
12
12
|
isReady: boolean;
|
|
@@ -20,7 +20,7 @@ declare class FinderCoreImplementation<FItem, FContext = any> {
|
|
|
20
20
|
pagination: PaginationMixin<FItem>;
|
|
21
21
|
context: FContext;
|
|
22
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);
|
|
23
|
+
constructor(items: FItem[] | null | undefined, { rules, effects, initialSearchTerm, initialSortBy, initialSortDirection, initialGroupBy, initialGroupBySortDirection, initialFilters, context, page, numItemsPerPage, isLoading, disabled, requireGroup, ignoreSortByRulesWhileSearchRuleIsActive, onInit, onReady, onFirstUserInteraction, onChange, }: FinderConstructorOptions<FItem, FContext>, getInstanceFn: () => FinderCore);
|
|
24
24
|
emitFirstUserInteraction(): void;
|
|
25
25
|
get items(): FItem[];
|
|
26
26
|
get matches(): import("./types/core-types").ResultSnapshot<FItem>;
|
|
@@ -33,12 +33,13 @@ declare class FinderCoreImplementation<FItem, FContext = any> {
|
|
|
33
33
|
silently: (callback: EventCallback) => void;
|
|
34
34
|
isSilent: () => boolean;
|
|
35
35
|
};
|
|
36
|
-
getRule(identifier: string |
|
|
36
|
+
getRule(identifier: string | RuleDefinition<FItem>): RuleDefinition;
|
|
37
37
|
get state(): "loading" | "empty" | "groups" | "items" | "noMatches";
|
|
38
38
|
setItems(items: FItem[] | null | undefined): void;
|
|
39
39
|
setIsLoading(value?: boolean): void;
|
|
40
40
|
setIsDisabled(value?: boolean): void;
|
|
41
|
-
setRules(definitions:
|
|
41
|
+
setRules(definitions: RuleDefinition<FItem, FContext>[]): void;
|
|
42
42
|
setContext(context: FContext): void;
|
|
43
|
+
toJSON(): Omit<FinderConstructorOptions<FItem>, "rules">;
|
|
43
44
|
}
|
|
44
45
|
export { FinderCoreImplementation };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FinderConstructorOptions, SnapshotSerializedMixins } from "./types/core-types";
|
|
2
|
-
import {
|
|
2
|
+
import { RuleDefinition } from "./types/rule-types";
|
|
3
3
|
/**
|
|
4
4
|
* This thin wrapper around FinderCoreImplementation defines the mixin interfaces and hides private methods.
|
|
5
5
|
*/
|
|
@@ -26,7 +26,7 @@ declare class FinderCore<FItem = any, FContext = any> {
|
|
|
26
26
|
*/
|
|
27
27
|
get matches(): import("./types/core-types").ResultSnapshot<FItem>;
|
|
28
28
|
get search(): {
|
|
29
|
-
rule: import("..").
|
|
29
|
+
rule: import("..").SearchRuleDefinition<unknown, any> | undefined;
|
|
30
30
|
searchTerm: string;
|
|
31
31
|
hasSearchTerm: boolean;
|
|
32
32
|
hasSearchRule: boolean;
|
|
@@ -37,38 +37,39 @@ declare class FinderCore<FItem = any, FContext = any> {
|
|
|
37
37
|
get filters(): {
|
|
38
38
|
values: Record<string, any>;
|
|
39
39
|
raw: Record<string, any>;
|
|
40
|
-
activeRules: import("
|
|
41
|
-
rules: import("
|
|
42
|
-
isActive: (identifier: string | import("..").
|
|
43
|
-
get: (identifier: string | import("..").
|
|
44
|
-
add: (identifier: string | import("..").
|
|
45
|
-
has: (identifier: string | import("..").
|
|
46
|
-
getRule: (identifier: string | import("..").
|
|
47
|
-
toggle: (identifier: string | import("..").
|
|
48
|
-
set: <FValue>(identifier: string | import("..").
|
|
49
|
-
delete: (identifier: string | import("..").
|
|
40
|
+
activeRules: import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>[];
|
|
41
|
+
rules: import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>[];
|
|
42
|
+
isActive: (identifier: string | import("..").AnyFilterRuleDefinition<any, any>) => boolean;
|
|
43
|
+
get: (identifier: string | import("..").AnyFilterRuleDefinition<any, any>) => any;
|
|
44
|
+
add: <FValue>(identifier: string | import("..").AnyFilterRuleDefinition<any, FValue>, optionValue?: FValue | import("..").FilterOption<FValue>) => void;
|
|
45
|
+
has: (identifier: string | import("..").AnyFilterRuleDefinition<any, any>, optionValue?: any) => boolean;
|
|
46
|
+
getRule: (identifier: string | import("..").AnyFilterRuleDefinition<any, any>) => import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>;
|
|
47
|
+
toggle: <FValue>(identifier: string | import("..").AnyFilterRuleDefinition<any, FValue>, optionValue?: FValue | import("..").FilterOption<FValue>) => void;
|
|
48
|
+
set: <FValue>(identifier: string | import("..").AnyFilterRuleDefinition<any, FValue>, value?: FValue | FValue[]) => void;
|
|
49
|
+
delete: <FValue>(identifier: string | import("..").AnyFilterRuleDefinition<any, FValue>, optionValue?: FValue | import("..").FilterOption<FValue>) => void;
|
|
50
|
+
reset: () => void;
|
|
50
51
|
test: (options: import("./types/rule-types").FilterTestOptions) => any[];
|
|
51
52
|
testRule: ({ rule: identifier, value, ...options }: import("./types/rule-types").FilterTestRuleOptions) => any[];
|
|
52
|
-
testRuleOptions: (identifier: string | import("..").
|
|
53
|
+
testRuleOptions: (identifier: string | import("..").AnyFilterRuleDefinition<any, any>, isAdditive?: boolean) => Map<any, any>;
|
|
53
54
|
};
|
|
54
55
|
get sortBy(): {
|
|
55
|
-
activeRule: import("..").
|
|
56
|
+
activeRule: import("..").SortByRuleDefinition<unknown, any> | undefined;
|
|
56
57
|
sortDirection: import("..").SortDirection;
|
|
57
58
|
userHasSetSortDirection: boolean;
|
|
58
|
-
rules: import("..").
|
|
59
|
-
set: (identifier?: string | import("..").
|
|
59
|
+
rules: import("..").SortByRuleDefinition<unknown, any>[];
|
|
60
|
+
set: (identifier?: string | import("..").SortByRuleDefinition, incomingSortDirection?: import("..").SortDirection) => void;
|
|
60
61
|
setSortDirection: (incomingSortDirection?: import("..").SortDirection) => void;
|
|
61
62
|
cycleSortDirection: () => void;
|
|
62
63
|
toggleSortDirection: () => void;
|
|
63
64
|
reset: () => void;
|
|
64
65
|
};
|
|
65
66
|
get groupBy(): {
|
|
66
|
-
activeRule: import("..").
|
|
67
|
+
activeRule: import("..").GroupByRuleDefinition<unknown, any> | undefined;
|
|
67
68
|
requireGroup: boolean;
|
|
68
|
-
rules: import("..").
|
|
69
|
-
|
|
70
|
-
set: (identifier?: string | import("..").
|
|
71
|
-
toggle: (identifier: import("..").
|
|
69
|
+
rules: import("..").GroupByRuleDefinition<unknown, any>[];
|
|
70
|
+
groupBySortDirection: import("..").SortDirection | undefined;
|
|
71
|
+
set: (identifier?: string | import("..").GroupByRuleDefinition<any, any>) => void;
|
|
72
|
+
toggle: (identifier: string | import("..").GroupByRuleDefinition<any, any>) => void;
|
|
72
73
|
setGroupSortDirection: (direction?: import("..").SortDirection) => void;
|
|
73
74
|
reset: () => void;
|
|
74
75
|
};
|
|
@@ -88,12 +89,13 @@ declare class FinderCore<FItem = any, FContext = any> {
|
|
|
88
89
|
setItems(items: FItem[] | null | undefined): void;
|
|
89
90
|
setIsLoading(value?: boolean): void;
|
|
90
91
|
setIsDisabled(value?: boolean): void;
|
|
91
|
-
setRules(definitions:
|
|
92
|
+
setRules(definitions: RuleDefinition<FItem>[]): void;
|
|
92
93
|
setContext(context: FContext): void;
|
|
93
94
|
/**
|
|
94
95
|
* Utils
|
|
95
96
|
*/
|
|
96
97
|
test(mixins: SnapshotSerializedMixins, isAdditive?: boolean): FItem[];
|
|
97
|
-
getRule(identifier: string |
|
|
98
|
+
getRule<T extends RuleDefinition<FItem>>(identifier: string | RuleDefinition<FItem>): T | undefined;
|
|
99
|
+
toJSON(): Omit<FinderConstructorOptions<FItem, any>, "rules">;
|
|
98
100
|
}
|
|
99
101
|
export { FinderCore };
|
package/dist/core/group-by.d.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GroupByRuleDefinition } from "./types/rule-types";
|
|
2
2
|
import { FinderResultGroup, MixinInjectedDependencies, SerializedGroupByMixin, SortDirection } from "./types/core-types";
|
|
3
3
|
interface InitialValues {
|
|
4
4
|
initialGroupBy: string | undefined;
|
|
5
|
+
initialGroupBySortDirection?: SortDirection;
|
|
5
6
|
requireGroup: boolean;
|
|
6
7
|
}
|
|
8
|
+
type GroupByRuleIdentifier = string | GroupByRuleDefinition;
|
|
7
9
|
declare class GroupByMixin<FItem, FContext> {
|
|
8
10
|
#private;
|
|
9
11
|
requireGroup: boolean;
|
|
10
|
-
constructor({ initialGroupBy, requireGroup }: InitialValues, deps: MixinInjectedDependencies<FItem, FContext>);
|
|
11
|
-
getRule(identifier:
|
|
12
|
-
get rules():
|
|
13
|
-
get activeRule():
|
|
12
|
+
constructor({ initialGroupBy, initialGroupBySortDirection, requireGroup }: InitialValues, deps: MixinInjectedDependencies<FItem, FContext>);
|
|
13
|
+
getRule(identifier: GroupByRuleIdentifier): GroupByRuleDefinition<any, any>;
|
|
14
|
+
get rules(): GroupByRuleDefinition<unknown, any>[];
|
|
15
|
+
get activeRule(): GroupByRuleDefinition<unknown, any> | undefined;
|
|
14
16
|
get hasGroupByRule(): boolean;
|
|
15
|
-
get
|
|
16
|
-
set(identifier?:
|
|
17
|
+
get groupBySortDirection(): SortDirection | undefined;
|
|
18
|
+
set(identifier?: GroupByRuleIdentifier): void;
|
|
17
19
|
setGroupSortDirection(direction?: SortDirection): void;
|
|
18
|
-
toggle(identifier:
|
|
20
|
+
toggle(identifier: GroupByRuleIdentifier): void;
|
|
19
21
|
reset(): void;
|
|
20
22
|
serialize(): SerializedGroupByMixin;
|
|
21
23
|
static process<FItem>(options: SerializedGroupByMixin, items: FItem[], context: unknown): FinderResultGroup<FItem>[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FilterRuleWithBooleanValue, HydratedFilterRuleDefinition } from "../types/rule-types";
|
|
2
|
+
export declare function BooleanFilterHandler(definition: HydratedFilterRuleDefinition & FilterRuleWithBooleanValue): {
|
|
3
|
+
validate(value: unknown): boolean;
|
|
4
|
+
parse(value: unknown): boolean;
|
|
5
|
+
has(value: unknown): boolean;
|
|
6
|
+
toggle(value: unknown, optionValue?: any): boolean;
|
|
7
|
+
add(value: unknown, optionValue: any): never;
|
|
8
|
+
delete(value: unknown, optionValue?: any): undefined;
|
|
9
|
+
isActive(value: unknown): boolean;
|
|
10
|
+
isMatch(item: unknown, value: unknown, context: unknown): boolean;
|
|
11
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { HydratedFilterRuleDefinition } from "../types/rule-types";
|
|
2
|
+
export declare function makeFilterHandler(definition: HydratedFilterRuleDefinition): {
|
|
3
|
+
validate(value: unknown): boolean;
|
|
4
|
+
parse(value: unknown): boolean;
|
|
5
|
+
has(value: unknown): boolean;
|
|
6
|
+
toggle(value: unknown, optionValue?: any): boolean;
|
|
7
|
+
add(value: unknown, optionValue: any): never;
|
|
8
|
+
delete(value: unknown, optionValue?: any): undefined;
|
|
9
|
+
isActive(value: unknown): boolean;
|
|
10
|
+
isMatch(item: unknown, value: unknown, context: unknown): boolean;
|
|
11
|
+
} | {
|
|
12
|
+
validate(value: unknown): boolean;
|
|
13
|
+
parse(value: unknown): any[];
|
|
14
|
+
has(value: unknown, optionValue?: any): boolean;
|
|
15
|
+
toggle(value: unknown, optionValue?: any): any[];
|
|
16
|
+
add(value: unknown, optionValue: any): any[];
|
|
17
|
+
delete(value: unknown, optionValue?: any): any[] | undefined;
|
|
18
|
+
isActive(value: unknown): boolean;
|
|
19
|
+
isMatch(item: any, value: unknown, context: unknown): boolean;
|
|
20
|
+
} | {
|
|
21
|
+
validate(value: unknown): boolean;
|
|
22
|
+
parse(value: unknown): any;
|
|
23
|
+
has(value: unknown): value is {} | null;
|
|
24
|
+
toggle(value: unknown, optionValue?: any): never;
|
|
25
|
+
add(value: unknown, optionValue: any): never;
|
|
26
|
+
delete(value: unknown, optionValue?: any): undefined;
|
|
27
|
+
isActive(value: unknown): boolean;
|
|
28
|
+
isMatch(item: unknown, value: unknown, context: unknown): boolean;
|
|
29
|
+
};
|
package/dist/core/{filter-utils/multiple-filter.d.ts → rule-book/multiple-filter-handler.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function
|
|
1
|
+
import { FilterRuleWithMultipleValues, HydratedFilterRuleDefinition } from "../types/rule-types";
|
|
2
|
+
export declare function MultipleFilterHandler(definition: HydratedFilterRuleDefinition & FilterRuleWithMultipleValues): {
|
|
3
3
|
validate(value: unknown): boolean;
|
|
4
4
|
parse(value: unknown): any[];
|
|
5
5
|
has(value: unknown, optionValue?: any): boolean;
|
|
@@ -7,4 +7,5 @@ export declare function MultipleFilter(rule: HydratedFilterRule): {
|
|
|
7
7
|
add(value: unknown, optionValue: any): any[];
|
|
8
8
|
delete(value: unknown, optionValue?: any): any[] | undefined;
|
|
9
9
|
isActive(value: unknown): boolean;
|
|
10
|
+
isMatch(item: any, value: unknown, context: unknown): boolean;
|
|
10
11
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RuleDefinition } from "../types/rule-types";
|
|
2
|
+
/**
|
|
3
|
+
* Stores rule definitions and hydrated rules class objects
|
|
4
|
+
*/
|
|
5
|
+
export declare class RuleBook<FItem, FContext> {
|
|
6
|
+
#private;
|
|
7
|
+
rules: RuleDefinition[];
|
|
8
|
+
constructor(definitions: RuleDefinition<FItem>[], items: FItem[], context: FContext);
|
|
9
|
+
hydrateDefinitions(items: FItem[], context: FContext): void;
|
|
10
|
+
getRule(identifier: string | RuleDefinition): RuleDefinition;
|
|
11
|
+
getDefinitions(): RuleDefinition<FItem>[];
|
|
12
|
+
setRules(definitions: RuleDefinition<FItem>[]): void;
|
|
13
|
+
static validateDefinitions(definitions: RuleDefinition[]): boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FilterRuleWithSingleValue, HydratedFilterRuleDefinition } from "../types/rule-types";
|
|
2
|
+
export declare function SingleFilterHandler(definition: HydratedFilterRuleDefinition & FilterRuleWithSingleValue): {
|
|
3
|
+
validate(value: unknown): boolean;
|
|
4
|
+
parse(value: unknown): any;
|
|
5
|
+
has(value: unknown): value is {} | null;
|
|
6
|
+
toggle(value: unknown, optionValue?: any): never;
|
|
7
|
+
add(value: unknown, optionValue: any): never;
|
|
8
|
+
delete(value: unknown, optionValue?: any): undefined;
|
|
9
|
+
isActive(value: unknown): boolean;
|
|
10
|
+
isMatch(item: unknown, value: unknown, context: unknown): boolean;
|
|
11
|
+
};
|
package/dist/core/search.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ 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("..").SearchRuleDefinition<unknown, any> | undefined;
|
|
10
10
|
get hasSearchRule(): boolean;
|
|
11
11
|
get hasSearchTerm(): boolean;
|
|
12
12
|
setSearchTerm(value: string): void;
|
package/dist/core/sort-by.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SortByRuleDefinition } from "./types/rule-types";
|
|
2
2
|
import { MixinInjectedDependencies, SerializedSortByMixin, SortDirection } from "./types/core-types";
|
|
3
3
|
interface InitialValues {
|
|
4
4
|
initialSortBy: string | undefined;
|
|
@@ -7,15 +7,15 @@ interface InitialValues {
|
|
|
7
7
|
declare class SortByMixin<FItem> {
|
|
8
8
|
#private;
|
|
9
9
|
constructor({ initialSortBy, initialSortDirection }: InitialValues, deps: MixinInjectedDependencies<FItem>);
|
|
10
|
-
getRule(identifier: string |
|
|
11
|
-
get rules():
|
|
12
|
-
get activeRule():
|
|
10
|
+
getRule(identifier: string | SortByRuleDefinition): SortByRuleDefinition<any, any>;
|
|
11
|
+
get rules(): SortByRuleDefinition<unknown, any>[];
|
|
12
|
+
get activeRule(): SortByRuleDefinition<unknown, any> | undefined;
|
|
13
13
|
get sortDirection(): SortDirection;
|
|
14
14
|
get userHasSetSortDirection(): boolean;
|
|
15
15
|
setSortDirection(incomingSortDirection?: SortDirection): void;
|
|
16
16
|
cycleSortDirection(): void;
|
|
17
17
|
toggleSortDirection(): void;
|
|
18
|
-
set(identifier?: string |
|
|
18
|
+
set(identifier?: string | SortByRuleDefinition, incomingSortDirection?: SortDirection): void;
|
|
19
19
|
reset(): void;
|
|
20
20
|
serialize(): SerializedSortByMixin;
|
|
21
21
|
static process<FItem>(options: SerializedSortByMixin, items: FItem[], context: unknown): FItem[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DebounceCallbackRegistry } from "../debounce-callback-registry";
|
|
2
|
-
import { RuleBook } from "../rule-book";
|
|
2
|
+
import { RuleBook } from "../rule-book/rule-book";
|
|
3
3
|
import { RuleEffect, SearchEffect } from "./effect-types";
|
|
4
4
|
import { FinderOnChangeCallback, FinderOnFirstUserInteractCallback, FinderOnInitCallback, FinderOnReadyCallback, FinderTouchCallback } from "./event-types";
|
|
5
|
-
import {
|
|
5
|
+
import { RuleDefinition, GroupByRuleDefinition, SearchRuleDefinition, SortByRuleDefinition, HydratedFilterRuleDefinition } from "./rule-types";
|
|
6
6
|
export interface FinderConstructorOptions<FItem, FContext = any> {
|
|
7
|
-
rules:
|
|
7
|
+
rules: RuleDefinition<FItem>[];
|
|
8
8
|
effects?: (RuleEffect | SearchEffect)[];
|
|
9
9
|
context?: FContext;
|
|
10
10
|
isLoading?: boolean;
|
|
@@ -13,6 +13,7 @@ export interface FinderConstructorOptions<FItem, FContext = any> {
|
|
|
13
13
|
initialSortBy?: string;
|
|
14
14
|
initialSortDirection?: SortDirection;
|
|
15
15
|
initialGroupBy?: string;
|
|
16
|
+
initialGroupBySortDirection?: SortDirection;
|
|
16
17
|
initialFilters?: Record<string, any>;
|
|
17
18
|
ignoreSortByRulesWhileSearchRuleIsActive?: boolean;
|
|
18
19
|
requireGroup?: boolean;
|
|
@@ -59,14 +60,14 @@ export interface SnapshotSerializedMixins {
|
|
|
59
60
|
}
|
|
60
61
|
export interface SerializedSearchMixin {
|
|
61
62
|
searchTerm: string;
|
|
62
|
-
rule?:
|
|
63
|
+
rule?: SearchRuleDefinition;
|
|
63
64
|
}
|
|
64
65
|
export interface SerializedFiltersMixin {
|
|
65
|
-
rules:
|
|
66
|
+
rules: HydratedFilterRuleDefinition[];
|
|
66
67
|
values: Record<string, any>;
|
|
67
68
|
}
|
|
68
69
|
export interface SerializedSortByMixin {
|
|
69
|
-
rule?:
|
|
70
|
+
rule?: SortByRuleDefinition;
|
|
70
71
|
sortDirection?: SortDirection;
|
|
71
72
|
}
|
|
72
73
|
export interface SerializedPaginationMixin {
|
|
@@ -74,12 +75,8 @@ export interface SerializedPaginationMixin {
|
|
|
74
75
|
numItemsPerPage?: number;
|
|
75
76
|
}
|
|
76
77
|
export interface SerializedGroupByMixin {
|
|
77
|
-
rule?:
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
export interface SearchScore {
|
|
81
|
-
percentOfHaystackMatched: number;
|
|
82
|
-
longestSequentialSequence: number;
|
|
78
|
+
rule?: GroupByRuleDefinition;
|
|
79
|
+
groupBySortDirection?: SortDirection;
|
|
83
80
|
}
|
|
84
81
|
export interface PaginationMixinInterface {
|
|
85
82
|
page: number;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { FinderCore } from "../finder-core";
|
|
2
|
-
import {
|
|
2
|
+
import { RuleDefinition } from "./rule-types";
|
|
3
3
|
export interface RuleEffect<FItem = any, FContext = any> {
|
|
4
|
-
rules: string |
|
|
5
|
-
onChange: (instance: FinderCore<FItem, FContext>, rule:
|
|
4
|
+
rules: string | RuleDefinition<FItem> | (string | RuleDefinition<FItem>)[] | ((items: FItem[], context: FContext) => string | RuleDefinition<FItem> | (string | RuleDefinition<FItem>)[]);
|
|
5
|
+
onChange: (instance: FinderCore<FItem, FContext>, rule: RuleDefinition<FItem>) => void;
|
|
6
6
|
}
|
|
7
7
|
export interface HydratedRuleEffect<FItem = any, FContext = any> {
|
|
8
|
-
rules: (string |
|
|
9
|
-
onChange: (instance: FinderCore<FItem, FContext>, rule:
|
|
8
|
+
rules: (string | RuleDefinition<FItem>)[];
|
|
9
|
+
onChange: (instance: FinderCore<FItem, FContext>, rule: RuleDefinition<FItem>) => void;
|
|
10
10
|
_isHydrated: true;
|
|
11
11
|
}
|
|
12
12
|
export interface SearchEffect<FItem = any, FContext = any> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EVENT_SOURCE, EVENTS } from "../core-constants";
|
|
2
2
|
import { FinderCore } from "../finder-core";
|
|
3
|
-
import {
|
|
3
|
+
import { RuleDefinition } from "./rule-types";
|
|
4
4
|
export type FinderTouchSource = (typeof EVENT_SOURCE)[keyof typeof EVENT_SOURCE];
|
|
5
5
|
interface FinderSharedEventProps {
|
|
6
6
|
source: string;
|
|
@@ -34,7 +34,7 @@ export interface FinderTouchEvent {
|
|
|
34
34
|
event: FinderEventName;
|
|
35
35
|
current: any;
|
|
36
36
|
initial: any;
|
|
37
|
-
rule?:
|
|
37
|
+
rule?: RuleDefinition;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* External type that consumers will receive
|
|
@@ -3,71 +3,67 @@ import { FinderResultGroup, SortDirection } from "./core-types";
|
|
|
3
3
|
* Select a property from the item to sort by.
|
|
4
4
|
*/
|
|
5
5
|
export type FinderPropertySelector<FItem, FContext = any> = (item: FItem, context: FContext) => string | number;
|
|
6
|
-
interface
|
|
6
|
+
interface Rule {
|
|
7
7
|
id: string;
|
|
8
8
|
debounceMilliseconds?: number;
|
|
9
9
|
label?: string;
|
|
10
10
|
hidden?: boolean;
|
|
11
11
|
}
|
|
12
|
-
export type
|
|
13
|
-
export
|
|
14
|
-
export interface SearchRule<FItem = any, FContext = any> extends Omit<RuleBase, "id"> {
|
|
12
|
+
export type RuleDefinition<FItem = any, FContext = any> = SearchRuleDefinition<FItem, FContext> | FilterRuleDefinition<FItem, FContext> | SortByRuleDefinition<FItem, FContext> | GroupByRuleDefinition<FItem, FContext>;
|
|
13
|
+
export interface SearchRuleDefinition<FItem = any, FContext = any> extends Omit<Rule, "id"> {
|
|
15
14
|
id?: string;
|
|
16
15
|
searchFn?: (item: FItem, context: FContext) => string | string[];
|
|
17
16
|
}
|
|
18
|
-
export interface FilterOptionGeneratorFnOptions<FItem, FContext = any> {
|
|
19
|
-
items: FItem[];
|
|
20
|
-
context: FContext;
|
|
21
|
-
}
|
|
22
17
|
/**
|
|
23
18
|
* Describes the display of a filter or sort option.
|
|
24
19
|
*/
|
|
25
20
|
export interface FilterOption<FValue = any> {
|
|
26
|
-
label
|
|
21
|
+
label?: string;
|
|
27
22
|
value: FValue;
|
|
28
23
|
disabled?: boolean;
|
|
29
24
|
}
|
|
30
|
-
export interface
|
|
31
|
-
|
|
25
|
+
export interface FilterRuleDefinition<FItem = any, FValue = any, FContext = any> extends Rule {
|
|
26
|
+
filterFn: (item: FItem, value: FValue, context: FContext) => boolean;
|
|
32
27
|
required?: boolean;
|
|
28
|
+
strictOptions?: boolean;
|
|
29
|
+
multiple?: boolean;
|
|
30
|
+
boolean?: boolean;
|
|
31
|
+
options?: FilterOption<FValue>[] | ((options: {
|
|
32
|
+
items: FItem[];
|
|
33
|
+
context: FContext;
|
|
34
|
+
}) => FilterOption<FValue>[]);
|
|
33
35
|
}
|
|
34
|
-
export
|
|
36
|
+
export type AnyFilterRuleDefinition<FItem = any, FValue = any> = Omit<FilterRuleDefinition<FItem, FValue>, "options">;
|
|
37
|
+
export interface FilterRuleWithBooleanValue<FItem = any, FValue = boolean, FContext = any> extends FilterRuleDefinition<FItem, FValue, FContext> {
|
|
35
38
|
multiple?: false;
|
|
36
39
|
boolean: true;
|
|
37
|
-
filterFn: (item: FItem, value: boolean, context: FContext) => boolean;
|
|
38
40
|
defaultValue?: boolean;
|
|
41
|
+
options?: never;
|
|
39
42
|
}
|
|
40
|
-
export interface FilterRuleWithSingleValue<FItem, FValue, FContext = any> extends
|
|
43
|
+
export interface FilterRuleWithSingleValue<FItem = any, FValue = any, FContext = any> extends FilterRuleDefinition<FItem, FValue, FContext> {
|
|
41
44
|
multiple?: false;
|
|
42
45
|
boolean?: false;
|
|
43
|
-
filterFn: (item: FItem, value: FValue, context: FContext) => boolean;
|
|
44
46
|
defaultValue?: FValue;
|
|
45
47
|
}
|
|
46
|
-
export interface FilterRuleWithMultipleValues<FItem, FValue, FContext = any> extends
|
|
48
|
+
export interface FilterRuleWithMultipleValues<FItem = any, FValue = any, FContext = any> extends FilterRuleDefinition<FItem, FValue, FContext> {
|
|
47
49
|
multiple: true;
|
|
48
50
|
boolean?: false;
|
|
49
|
-
filterFn: (item: FItem, value: FValue[], context: FContext) => boolean;
|
|
50
51
|
defaultValue?: FValue[];
|
|
51
52
|
}
|
|
52
|
-
export type FilterRuleUnion<FItem = any, FValue = any> = FilterRuleWithBooleanValue<FItem> | FilterRuleWithSingleValue<FItem, FValue> | FilterRuleWithMultipleValues<FItem, FValue>;
|
|
53
53
|
/**
|
|
54
54
|
* A hydrated filter has rendered any option generator functions, and narrowed ambiguous properties from FilterRule.
|
|
55
55
|
*/
|
|
56
|
-
export interface
|
|
56
|
+
export interface HydratedFilterRuleDefinition<FItem = any, FValue = any, FContext = any> extends FilterRuleDefinition<FItem, FValue, FContext> {
|
|
57
57
|
options?: FilterOption<FValue>[];
|
|
58
|
-
required: boolean;
|
|
59
|
-
boolean: boolean;
|
|
60
|
-
hidden: boolean;
|
|
61
58
|
multiple: boolean;
|
|
62
|
-
|
|
63
|
-
defaultValue?: boolean | FValue | FValue[];
|
|
59
|
+
boolean: boolean;
|
|
64
60
|
_isHydrated: true;
|
|
65
61
|
}
|
|
66
|
-
export interface
|
|
62
|
+
export interface SortByRuleDefinition<FItem = any, FContext = any> extends Rule {
|
|
67
63
|
sortFn: FinderPropertySelector<FItem, FContext> | FinderPropertySelector<FItem, FContext>[];
|
|
68
64
|
defaultSortDirection?: SortDirection;
|
|
69
65
|
}
|
|
70
|
-
export interface
|
|
66
|
+
export interface GroupByRuleDefinition<FItem = any, FContext = any> extends Rule {
|
|
71
67
|
groupFn: FinderPropertySelector<FItem, FContext>;
|
|
72
68
|
sortGroupFn?: FinderPropertySelector<FinderResultGroup<FItem>, FContext>;
|
|
73
69
|
defaultGroupSortDirection?: SortDirection;
|
|
@@ -77,16 +73,16 @@ export interface GroupByRule<FItem = any, FContext = any> extends RuleBase {
|
|
|
77
73
|
};
|
|
78
74
|
}
|
|
79
75
|
export interface SearchTestOptions {
|
|
80
|
-
rule:
|
|
76
|
+
rule: SearchRuleDefinition[];
|
|
81
77
|
searchTerm: string;
|
|
82
78
|
}
|
|
83
79
|
export interface FilterTestOptions {
|
|
84
|
-
rules:
|
|
80
|
+
rules: HydratedFilterRuleDefinition[];
|
|
85
81
|
values?: Record<string, any>;
|
|
86
82
|
isAdditive?: boolean;
|
|
87
83
|
}
|
|
88
84
|
export interface FilterTestRuleOptions {
|
|
89
|
-
rule: string |
|
|
85
|
+
rule: string | AnyFilterRuleDefinition;
|
|
90
86
|
value: any;
|
|
91
87
|
isAdditive?: boolean;
|
|
92
88
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { FinderCore } from "../finder-core";
|
|
2
2
|
import { RuleEffect, SearchEffect } from "../types/effect-types";
|
|
3
|
-
import { FilterRuleWithBooleanValue, FilterRuleWithMultipleValues, FilterRuleWithSingleValue,
|
|
3
|
+
import { FilterRuleWithBooleanValue, FilterRuleWithMultipleValues, FilterRuleWithSingleValue, RuleDefinition, GroupByRuleDefinition, SearchRuleDefinition, SortByRuleDefinition, AnyFilterRuleDefinition } from "../types/rule-types";
|
|
4
4
|
/**
|
|
5
5
|
* Enforce structure for an array of rule of mixed types.
|
|
6
6
|
*/
|
|
7
|
-
export declare function finderRuleset<FItem, FContext = any>(rules:
|
|
8
|
-
export declare function searchRule<FItem, FContext = any>(rule:
|
|
7
|
+
export declare function finderRuleset<FItem, FContext = any>(rules: RuleDefinition<FItem, FContext>[]): RuleDefinition<FItem, FContext>[];
|
|
8
|
+
export declare function searchRule<FItem, FContext = any>(rule: SearchRuleDefinition<FItem, FContext>): SearchRuleDefinition<FItem, FContext>;
|
|
9
9
|
export declare function filterRule<FItem, FValue = any, FContext = any, T = FilterRuleWithMultipleValues<FItem, FValue, FContext>>(rule: T): FilterRuleWithMultipleValues<FItem, FValue>;
|
|
10
|
-
export declare function filterRule<FItem, FValue =
|
|
10
|
+
export declare function filterRule<FItem, FValue = boolean, FContext = any, T = FilterRuleWithBooleanValue<FItem, FValue, FContext>>(rule: T): FilterRuleWithBooleanValue<FItem, FValue>;
|
|
11
11
|
export declare function filterRule<FItem, FValue = any, FContext = any, T = FilterRuleWithSingleValue<FItem, FValue, FContext>>(rule: T): FilterRuleWithSingleValue<FItem, FValue>;
|
|
12
|
-
export declare function sortByRule<FItem, FContext = any>(rule:
|
|
13
|
-
export declare function groupByRule<FItem, FContext = any>(rule:
|
|
14
|
-
export declare function ruleEffect<FItem, FContext = any>(rules: string |
|
|
12
|
+
export declare function sortByRule<FItem, FContext = any>(rule: SortByRuleDefinition<FItem, FContext>): SortByRuleDefinition<FItem, FContext>;
|
|
13
|
+
export declare function groupByRule<FItem, FContext = any>(rule: GroupByRuleDefinition<FItem, FContext>): GroupByRuleDefinition<FItem, FContext>;
|
|
14
|
+
export declare function ruleEffect<FItem, FContext = any>(rules: string | RuleDefinition<FItem> | (string | RuleDefinition<FItem>)[] | ((items: FItem[], context: FContext) => string | RuleDefinition<FItem> | (string | RuleDefinition<FItem>)[]), onChange: (instance: FinderCore<FItem, FContext>, rule: RuleDefinition) => void): RuleEffect<FItem, FContext>;
|
|
15
15
|
export declare function searchEffect<FItem, FContext = any>(haystack: string | string[] | ((items: FItem[], context: FContext) => string | string[]), onChange: (instance: FinderCore<FItem, FContext>, searchTerm: string) => void): SearchEffect<FItem, FContext>;
|
|
16
|
+
export declare function transformFilterToSingleValue<FItem, FValue, FContext = any>(filter: AnyFilterRuleDefinition<FItem, FValue>): FilterRuleWithMultipleValues<FItem, FValue, FContext>;
|
|
17
|
+
export declare function transformFilterToBoolean<FItem, FValue, FContext = any>(filter: AnyFilterRuleDefinition<FItem, FValue>): FilterRuleWithBooleanValue<FItem, boolean, FContext>;
|
|
18
|
+
export declare function transformFilterToMultiple<FItem, FValue, FContext = any>(filter: AnyFilterRuleDefinition<FItem, FValue>): FilterRuleWithMultipleValues<FItem, FValue, FContext>;
|