@hitgrab/finder 0.0.26-alpha → 0.1.0-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 (67) hide show
  1. package/README.md +7 -1106
  2. package/dist/core/effect-book/effect-book.d.ts +8 -0
  3. package/dist/core/events/event-emitter.d.ts +2 -1
  4. package/dist/core/filters/filters-interface.d.ts +13 -14
  5. package/dist/core/filters/filters.d.ts +15 -16
  6. package/dist/core/finder-core.d.ts +29 -51
  7. package/dist/core/group-by/group-by-interface.d.ts +7 -7
  8. package/dist/core/group-by/group-by.d.ts +12 -10
  9. package/dist/core/pagination/pagination.d.ts +5 -4
  10. package/dist/core/rule-book/rule-book.d.ts +14 -0
  11. package/dist/core/search/algorithms/sequential-characters.d.ts +1 -2
  12. package/dist/core/search/algorithms/sequential-string.d.ts +1 -2
  13. package/dist/core/search/{haystack.d.ts → result-segments/result-segment-haystack.d.ts} +1 -1
  14. package/dist/core/search/result-segments/result-segment-types.d.ts +2 -3
  15. package/dist/core/search/result-segments/search-result-segments.d.ts +3 -11
  16. package/dist/core/search/search-interface.d.ts +3 -2
  17. package/dist/core/search/search-score.d.ts +4 -0
  18. package/dist/core/search/search-string-transform.d.ts +8 -0
  19. package/dist/core/search/search.d.ts +7 -5
  20. package/dist/core/sort-by/sort-by-interface.d.ts +5 -5
  21. package/dist/core/sort-by/sort-by.d.ts +6 -5
  22. package/dist/core/tester/tester.d.ts +8 -0
  23. package/dist/core/types/core-types.d.ts +92 -0
  24. package/dist/core/types/effect-types.d.ts +22 -0
  25. package/dist/core/types/event-types.d.ts +43 -0
  26. package/dist/core/types/rule-types.d.ts +108 -0
  27. package/dist/core/utils/rule-type-enforcers.d.ts +9 -5
  28. package/dist/core/utils/rule-utils.d.ts +5 -8
  29. package/dist/index.d.ts +6 -14
  30. package/dist/index.js +3204 -3547
  31. package/dist/index.umd.cjs +30 -30
  32. package/dist/react/components/finder-content-empty.d.ts +6 -0
  33. package/dist/react/components/finder-content-groups.d.ts +7 -0
  34. package/dist/react/components/finder-content-items.d.ts +7 -0
  35. package/dist/react/components/finder-content-loading.d.ts +6 -0
  36. package/dist/react/components/finder-content-no-matches.d.ts +6 -0
  37. package/dist/react/components/finder-content.d.ts +20 -8
  38. package/dist/react/components/finder-search-term.d.ts +2 -1
  39. package/dist/react/components/finder.d.ts +7 -1
  40. package/dist/react/hooks/use-finder-constructor.d.ts +7 -0
  41. package/dist/react/hooks/use-finder-ref.d.ts +1 -1
  42. package/dist/react/hooks/use-finder.d.ts +1 -5
  43. package/dist/react/providers/finder-core-context.d.ts +3 -0
  44. package/dist/react/types/react-types.d.ts +9 -13
  45. package/package.json +4 -1
  46. package/dist/core/__tests__/selected-items.test.d.ts +0 -1
  47. package/dist/core/layout/layout-interface.d.ts +0 -19
  48. package/dist/core/layout/layout.d.ts +0 -21
  49. package/dist/core/meta/meta-interface.d.ts +0 -18
  50. package/dist/core/meta/meta.d.ts +0 -16
  51. package/dist/core/plugins/plugin-mediator.d.ts +0 -14
  52. package/dist/core/plugins/plugin-super-class.d.ts +0 -8
  53. package/dist/core/search/algorithms/unordered-characters.d.ts +0 -2
  54. package/dist/core/selected-items/selected-items-interface.d.ts +0 -22
  55. package/dist/core/selected-items/selected-items.d.ts +0 -23
  56. package/dist/core/types/internal-types.d.ts +0 -15
  57. package/dist/core/utils/string-compare-utils.d.ts +0 -13
  58. package/dist/react/components/finder-empty.d.ts +0 -6
  59. package/dist/react/components/finder-groups.d.ts +0 -7
  60. package/dist/react/components/finder-items.d.ts +0 -7
  61. package/dist/react/components/finder-loading.d.ts +0 -6
  62. package/dist/react/components/finder-no-matches.d.ts +0 -6
  63. package/dist/react/hooks/use-finder-context.d.ts +0 -2
  64. package/dist/react/providers/finder-context.d.ts +0 -3
  65. package/dist/types.d.ts +0 -221
  66. /package/dist/core/__tests__/{layout.test.d.ts → effects.test.d.ts} +0 -0
  67. /package/dist/core/__tests__/{plugins.test.d.ts → events.test.d.ts} +0 -0
@@ -0,0 +1,22 @@
1
+ import { FinderCore } from "../finder-core";
2
+ import { FinderRule } from "./rule-types";
3
+ export interface RuleEffect<FItem = any, FContext = any> {
4
+ rules: string | FinderRule<FItem> | (string | FinderRule<FItem>)[] | ((items: FItem[], context: FContext) => string | FinderRule<FItem> | (string | FinderRule<FItem>)[]);
5
+ onChange: (instance: FinderCore<FItem, FContext>) => void;
6
+ }
7
+ export interface HydratedRuleEffect<FItem = any, FContext = any> {
8
+ rules: (string | FinderRule<FItem>)[];
9
+ onChange: (instance: FinderCore<FItem, FContext>) => void;
10
+ _isHydrated: true;
11
+ }
12
+ export interface SearchEffect<FItem = any, FContext = any> {
13
+ haystack: string | string[] | ((items: FItem[], context: FContext) => string | string[]);
14
+ onChange: (instance: FinderCore<FItem, FContext>) => void;
15
+ exact?: boolean;
16
+ }
17
+ export interface HydratedSearchEffect<FItem = any, FContext = any> {
18
+ haystack: string[];
19
+ onChange: (instance: FinderCore<FItem, FContext>) => void;
20
+ exact: boolean;
21
+ _isHydrated: true;
22
+ }
@@ -0,0 +1,43 @@
1
+ import { FinderSnapshot } from "./core-types";
2
+ import { FinderRule } from "./rule-types";
3
+ export type FinderTouchSource = "core" | "filters" | "groupBy" | "pagination" | "search" | "sortBy";
4
+ interface FinderSharedEventProps {
5
+ source: string;
6
+ event: FinderEventName;
7
+ snapshot: FinderSnapshot<any>;
8
+ timestamp: number;
9
+ }
10
+ export interface FinderInitEvent extends FinderSharedEventProps {
11
+ source: "core";
12
+ event: "init";
13
+ }
14
+ export interface FinderFirstUserInteractionEvent extends FinderSharedEventProps {
15
+ source: "core";
16
+ event: "firstUserInteraction";
17
+ }
18
+ export interface FinderReadyEvent extends FinderSharedEventProps {
19
+ source: "core";
20
+ event: "ready";
21
+ }
22
+ export type FinderEvent = FinderInitEvent | FinderFirstUserInteractionEvent | FinderReadyEvent | FinderChangeEvent;
23
+ export type FinderOnInitCallback = (event: FinderInitEvent) => void;
24
+ export type FinderOnReadyCallback = (event: FinderReadyEvent) => void;
25
+ export type FinderOnFirstUserInteractCallback = (event: FinderFirstUserInteractionEvent) => void;
26
+ export type FinderOnChangeCallback = (event: FinderChangeEvent) => void;
27
+ export type FinderTouchCallback = (event: FinderTouchEvent) => void;
28
+ /**
29
+ * Internal communication between mixins and core
30
+ */
31
+ export interface FinderTouchEvent {
32
+ source: FinderTouchSource;
33
+ event: FinderEventName;
34
+ current: any;
35
+ initial: any;
36
+ rule?: FinderRule;
37
+ }
38
+ /**
39
+ * External type that consumers will receive
40
+ */
41
+ export type FinderChangeEvent = FinderTouchEvent & FinderSharedEventProps;
42
+ export type FinderEventName = "init" | "firstUserInteraction" | "ready" | "change" | "change.core" | "change.core.setIsLoading" | "change.core.setIsDisabled" | "change.core.setItems" | "change.core.syncContext" | `change.filters` | "change.filters.set" | `change.groupBy` | "change.groupBy.set" | "change.groupBy.setGroupIdSortDirection" | "change.pagination" | "change.pagination.setPage" | "change.pagination.setNumItemsPerPage" | "change.search" | "change.search.setSearchTerm" | "change.search.reset" | "change.sortBy" | "change.sortBy.set" | "change.sortBy.setSortDirection";
43
+ export {};
@@ -0,0 +1,108 @@
1
+ import { FinderResultGroup, SortDirection } from "./core-types";
2
+ /**
3
+ * Select a property from the item to sort by.
4
+ */
5
+ export type FinderPropertySelector<FItem, FContext = any> = (item: FItem, context?: FContext) => string | number;
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 interface SearchRule<FItem = any, FContext = any> {
8
+ id?: string;
9
+ label?: string;
10
+ hidden?: boolean;
11
+ debounceMilliseconds?: number;
12
+ searchFn?: (item: FItem, context?: FContext) => string | string[];
13
+ }
14
+ export interface FilterOptionGeneratorFnOptions<FItem, FContext = any> {
15
+ items: FItem[];
16
+ context?: FContext;
17
+ }
18
+ /**
19
+ * Describes the display of a filter or sort option.
20
+ */
21
+ export interface FilterOption<FValue = any> {
22
+ label: string;
23
+ value: FValue;
24
+ disabled?: boolean;
25
+ }
26
+ export interface FilterRule<FItem = any, FValue = any, FContext = any> {
27
+ id: string;
28
+ options?: FilterOption<FValue>[] | ((options: FilterOptionGeneratorFnOptions<FItem, FContext>) => FilterOption<FValue>[]);
29
+ required?: boolean;
30
+ label?: string;
31
+ hidden?: boolean;
32
+ debounceMilliseconds?: number;
33
+ multiple?: boolean;
34
+ boolean?: boolean;
35
+ filterFn: CallableFunction;
36
+ defaultValue?: any;
37
+ }
38
+ interface FilterRuleWithBooleanValue<FItem, FValue = boolean, FContext = any> extends FilterRule<FItem, FValue> {
39
+ multiple?: false;
40
+ boolean: true;
41
+ filterFn: (item: FItem, value: FValue, context?: FContext) => boolean;
42
+ defaultValue?: boolean;
43
+ }
44
+ interface FilterRuleWithScalarValue<FItem, FValue, FContext = any> extends FilterRule<FItem, FValue, FContext> {
45
+ multiple?: false;
46
+ boolean?: false;
47
+ filterFn: (item: FItem, value: FValue, context?: FContext) => boolean;
48
+ defaultValue?: FValue;
49
+ }
50
+ interface FilterRuleWithMultipleValues<FItem, FValue, FContext = any> extends FilterRule<FItem, FValue, FContext> {
51
+ multiple: true;
52
+ boolean?: false;
53
+ filterFn: (item: FItem, value: FValue[], context?: FContext) => boolean;
54
+ defaultValue?: FValue[];
55
+ }
56
+ export type FilterRuleUnion<FItem = any, FValue = any> = FilterRuleWithBooleanValue<FItem> | FilterRuleWithScalarValue<FItem, FValue> | FilterRuleWithMultipleValues<FItem, FValue>;
57
+ /**
58
+ * A hydrated filter has rendered any option generator functions, and narrowed ambiguous properties from FilterRule.
59
+ */
60
+ export interface HydratedFilterRule<FItem = any, FValue = any, FContext = any> extends Omit<FilterRule<FItem, FValue>, "options"> {
61
+ options?: FilterOption<FValue>[];
62
+ required: boolean;
63
+ boolean: boolean;
64
+ hidden: boolean;
65
+ multiple: boolean;
66
+ filterFn: ((item: FItem, value: FValue, context?: FContext) => boolean) | ((item: FItem, value: FValue[], context?: FContext) => boolean);
67
+ defaultValue?: boolean | FValue | FValue[];
68
+ _isHydrated: true;
69
+ }
70
+ export interface SortByRule<FItem = any, FContext = any> {
71
+ id: string;
72
+ sortFn: FinderPropertySelector<FItem, FContext> | FinderPropertySelector<FItem, FContext>[];
73
+ defaultSortDirection?: SortDirection;
74
+ label?: string;
75
+ hidden?: boolean;
76
+ }
77
+ export interface GroupByRule<FItem = any, FContext = any> {
78
+ id: string;
79
+ groupFn: FinderPropertySelector<FItem, FContext>;
80
+ sortGroupIdFn?: FinderPropertySelector<FinderResultGroup<FItem>, FContext>;
81
+ groupIdSortDirection?: SortDirection;
82
+ sticky?: {
83
+ header?: string | string[];
84
+ footer?: string | string[];
85
+ };
86
+ label?: string;
87
+ hidden?: boolean;
88
+ }
89
+ export interface SearchTestOptions {
90
+ rule: SearchRule[];
91
+ searchTerm: string;
92
+ }
93
+ export interface FilterTestOptions {
94
+ rules: HydratedFilterRule[];
95
+ values?: Record<string, any>;
96
+ isAdditive?: boolean;
97
+ }
98
+ export interface FilterTestRuleOptions {
99
+ rule: string | FilterRuleUnion | HydratedFilterRule;
100
+ value: any;
101
+ isAdditive?: boolean;
102
+ }
103
+ export interface FilterTestRuleOptionsOptions {
104
+ rule: string | FilterRuleUnion | HydratedFilterRule;
105
+ isAdditive?: boolean;
106
+ mergeExistingValue?: boolean;
107
+ }
108
+ export {};
@@ -1,9 +1,13 @@
1
- import { SearchRule, SortByRule, GroupByRule, FilterRuleUnion } from "../../types";
1
+ import { FinderCore } from "../finder-core";
2
+ import { RuleEffect, SearchEffect } from "../types/effect-types";
3
+ import { FilterRuleUnion, FinderRule, GroupByRule, SearchRule, SortByRule } from "../types/rule-types";
2
4
  /**
3
5
  * Enforce structure for an array of rule of mixed types.
4
6
  */
5
- export declare function finderRuleset<FItem>(rules: (SearchRule<FItem> | FilterRuleUnion<FItem, any> | SortByRule<FItem> | GroupByRule<FItem>)[]): (SearchRule<FItem> | FilterRuleUnion<FItem, any> | SortByRule<FItem> | GroupByRule<FItem>)[];
6
- export declare function searchRule<FItem>(rule: SearchRule<FItem>): SearchRule<FItem>;
7
+ export declare function finderRuleset<FItem>(rules: FinderRule<FItem>[]): FinderRule<FItem>[];
8
+ export declare function searchRule<FItem>(rule: SearchRule<FItem>): SearchRule<FItem, any>;
7
9
  export declare function filterRule<FItem, FValue = any>(rule: FilterRuleUnion<FItem, FValue>): FilterRuleUnion<FItem, FValue>;
8
- export declare function sortByRule<FItem>(rule: SortByRule<FItem>): SortByRule<FItem>;
9
- export declare function groupByRule<FItem>(rule: GroupByRule<FItem>): GroupByRule<FItem>;
10
+ export declare function sortByRule<FItem>(rule: SortByRule<FItem>): SortByRule<FItem, any>;
11
+ export declare function groupByRule<FItem>(rule: GroupByRule<FItem>): GroupByRule<FItem, any>;
12
+ 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, exact?: boolean): SearchEffect<FItem, FContext>;
@@ -1,14 +1,11 @@
1
- import { FilterOption, FinderRule, GroupByRule, HydratedFilterRule, SearchRule, SortByRule, MetaInterface, FilterRuleUnion } from "../../types";
2
- /**
3
- * Make sure the passed ruleset contains only well-configured rules.
4
- */
5
- export declare function isValidRuleset(rules?: FinderRule[]): rules is FinderRule[];
6
- export declare function getRuleFromIdentifier<T extends FinderRule>(identifier: FinderRule | string | undefined, rules: T[]): T | undefined;
7
- export declare function getFilterOptionFromIdentifier<FItem>(optionOrOptionValue: FilterOption | any, options: FilterOption[] | ((items: FItem[], meta: MetaInterface) => FilterOption[]) | undefined, items: FItem[], meta: MetaInterface): any;
1
+ import { RuleEffect, SearchEffect } from "../types/effect-types";
2
+ import { FilterOption, FilterRuleUnion, GroupByRule, HydratedFilterRule, SearchRule, SortByRule } from "../types/rule-types";
3
+ export declare function getFilterOptionFromIdentifier<FItem, FContext>(optionOrOptionValue: FilterOption | any, options: FilterOption[] | ((items: FItem[], context?: FContext) => FilterOption[]) | undefined, items: FItem[], context?: FContext): any;
8
4
  export declare function isFilterOption(data: unknown): data is FilterOption;
9
- export declare function getRuleType(rule: FinderRule): "search" | "filter" | "sortBy" | "groupBy";
10
5
  export declare function isSortByRule<FItem>(rule: unknown): rule is SortByRule<FItem>;
11
6
  export declare function isSearchRule<FItem>(rule: unknown): rule is SearchRule<FItem>;
12
7
  export declare function isFilterUnionRule<FItem>(rule: unknown): rule is FilterRuleUnion<FItem>;
13
8
  export declare function isHydratedFilterRule<FItem>(rule: unknown): rule is HydratedFilterRule<FItem>;
14
9
  export declare function isGroupByRule<FItem>(rule: unknown): rule is GroupByRule<FItem>;
10
+ export declare function isRuleEffect<FItem>(data: unknown): data is RuleEffect<FItem>;
11
+ export declare function isSearchEffect<FItem>(data: unknown): data is SearchEffect<FItem>;
package/dist/index.d.ts CHANGED
@@ -1,20 +1,12 @@
1
- /** Vanilla JS library */
2
- export { FinderPlugin } from "./core/plugins/plugin-super-class";
3
- export { finderRuleset, searchRule, filterRule, sortByRule, groupByRule } from "./core/utils/rule-type-enforcers";
4
- export { finderStringCompare, finderCharacterCompare, finderSequentialCharacterCompare } from "./core/utils/string-compare-utils";
5
- export type { FinderSnapshot, FinderConstructorOptions, FinderRule, SearchRule, FilterRule, HydratedFilterRule, FilterRuleUnion, SortByRule, GroupByRule, FinderResultGroup, FilterOption, SortDirection, FinderEvent, FinderInitEvent, FinderReadyEvent, FinderFirstUserInteractionEvent, FinderChangeEvent, LayoutVariant, FinderPluginFn, FinderPluginInterface, } from "./types";
1
+ export type { FinderSnapshot, FinderConstructorOptions, FinderResultGroup, SortDirection } from "./core/types/core-types";
2
+ export type { FinderRule, SearchRule, SortByRule, GroupByRule, FilterRule, HydratedFilterRule, FilterRuleUnion, FilterOption } from "./core/types/rule-types";
3
+ export { finderRuleset, searchRule, filterRule, sortByRule, groupByRule, ruleEffect, searchEffect } from "./core/utils/rule-type-enforcers";
4
+ export type { RuleEffect, SearchEffect } from "./core/types/effect-types";
5
+ export type { FinderEvent, FinderInitEvent, FinderReadyEvent, FinderFirstUserInteractionEvent, FinderChangeEvent } from "./core/types/event-types";
6
6
  /**
7
7
  * React hooks and components
8
8
  */
9
9
  export { useFinder } from "./react/hooks/use-finder";
10
- export { useFinderContext } from "./react/hooks/use-finder-context";
11
- export { FinderItems } from "./react/components/finder-items";
12
10
  export { Finder } from "./react/components/finder";
13
- export { FinderEmpty } from "./react/components/finder-empty";
14
- export { FinderGroups } from "./react/components/finder-groups";
15
- export { FinderLoading } from "./react/components/finder-loading";
16
- export { FinderNoMatches } from "./react/components/finder-no-matches";
17
- export { FinderContent } from "./react/components/finder-content";
18
- export { FinderSearchTerm } from "./react/components/finder-search-term";
19
11
  export { useFinderRef } from "./react/hooks/use-finder-ref";
20
- export type { FinderProps, FinderContentComponentProps, FinderGroupsComponentProps, FinderItemsComponentProps } from "./react/types/react-types";
12
+ export type { FinderProps, FinderContentProps, FinderContentGroupProps, FinderContentItemProps } from "./react/types/react-types";