@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
@@ -0,0 +1,104 @@
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 type HydratedFinderRule<FItem = any, FContext = any> = SearchRule<FItem, FContext> | HydratedFilterRule<FItem, FContext> | SortByRule<FItem, FContext> | GroupByRule<FItem, FContext>;
8
+ export interface SearchRule<FItem = any, FContext = any> {
9
+ id?: string;
10
+ label?: string;
11
+ hidden?: boolean;
12
+ debounceMilliseconds?: number;
13
+ searchFn?: (item: FItem, context?: FContext) => string | string[];
14
+ }
15
+ export interface FilterOptionGeneratorFnOptions<FItem, FContext = any> {
16
+ items: FItem[];
17
+ context?: FContext;
18
+ }
19
+ /**
20
+ * Describes the display of a filter or sort option.
21
+ */
22
+ export interface FilterOption<FValue = any> {
23
+ label: string;
24
+ value: FValue;
25
+ disabled?: boolean;
26
+ }
27
+ export interface FilterRule<FItem = any, FValue = any, FContext = any> {
28
+ id: string;
29
+ options?: FilterOption<FValue>[] | ((options: FilterOptionGeneratorFnOptions<FItem, FContext>) => FilterOption<FValue>[]);
30
+ required?: boolean;
31
+ label?: string;
32
+ hidden?: boolean;
33
+ debounceMilliseconds?: number;
34
+ }
35
+ export interface FilterRuleWithBooleanValue<FItem, FContext = any> extends FilterRule<FItem> {
36
+ multiple?: false;
37
+ boolean: true;
38
+ filterFn: (item: FItem, value: boolean, context?: FContext) => boolean;
39
+ defaultValue?: boolean;
40
+ }
41
+ export interface FilterRuleWithSingleValue<FItem, FValue, FContext = any> extends FilterRule<FItem, FValue, FContext> {
42
+ multiple?: false;
43
+ boolean?: false;
44
+ filterFn: (item: FItem, value: FValue, context?: FContext) => boolean;
45
+ defaultValue?: FValue;
46
+ }
47
+ export interface FilterRuleWithMultipleValues<FItem, FValue, FContext = any> extends FilterRule<FItem, FValue, FContext> {
48
+ multiple: true;
49
+ boolean?: false;
50
+ filterFn: (item: FItem, value: FValue[], context?: FContext) => boolean;
51
+ defaultValue?: FValue[];
52
+ }
53
+ export type FilterRuleUnion<FItem = any, FValue = any> = FilterRuleWithBooleanValue<FItem> | FilterRuleWithSingleValue<FItem, FValue> | FilterRuleWithMultipleValues<FItem, FValue>;
54
+ /**
55
+ * A hydrated filter has rendered any option generator functions, and narrowed ambiguous properties from FilterRule.
56
+ */
57
+ export interface HydratedFilterRule<FItem = any, FValue = any, FContext = any> extends Omit<FilterRule<FItem, FValue>, "options"> {
58
+ options?: FilterOption<FValue>[];
59
+ required: boolean;
60
+ boolean: boolean;
61
+ hidden: boolean;
62
+ multiple: boolean;
63
+ filterFn: ((item: FItem, value: FValue, context?: FContext) => boolean) | ((item: FItem, value: FValue[], context?: FContext) => boolean);
64
+ defaultValue?: boolean | FValue | FValue[];
65
+ _isHydrated: true;
66
+ }
67
+ export interface SortByRule<FItem = any, FContext = any> {
68
+ id: string;
69
+ sortFn: FinderPropertySelector<FItem, FContext> | FinderPropertySelector<FItem, FContext>[];
70
+ defaultSortDirection?: SortDirection;
71
+ label?: string;
72
+ hidden?: boolean;
73
+ }
74
+ export interface GroupByRule<FItem = any, FContext = any> {
75
+ id: string;
76
+ groupFn: FinderPropertySelector<FItem, FContext>;
77
+ sortGroupFn?: FinderPropertySelector<FinderResultGroup<FItem>, FContext>;
78
+ defaultGroupSortDirection?: SortDirection;
79
+ sticky?: {
80
+ header?: string | string[];
81
+ footer?: string | string[];
82
+ };
83
+ label?: string;
84
+ hidden?: boolean;
85
+ }
86
+ export interface SearchTestOptions {
87
+ rule: SearchRule[];
88
+ searchTerm: string;
89
+ }
90
+ export interface FilterTestOptions {
91
+ rules: HydratedFilterRule[];
92
+ values?: Record<string, any>;
93
+ isAdditive?: boolean;
94
+ }
95
+ export interface FilterTestRuleOptions {
96
+ rule: string | FilterRuleUnion | HydratedFilterRule;
97
+ value: any;
98
+ isAdditive?: boolean;
99
+ }
100
+ export interface FilterTestRuleOptionsOptions {
101
+ rule: string | FilterRuleUnion | HydratedFilterRule;
102
+ isAdditive?: boolean;
103
+ mergeExistingValue?: boolean;
104
+ }
@@ -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,9 +1,15 @@
1
- import { SearchRule, SortByRule, GroupByRule, FilterRuleUnion } from "../../types";
1
+ import { FinderCore } from "../finder-core";
2
+ import { RuleEffect, SearchEffect } from "../types/effect-types";
3
+ import { FilterRuleWithBooleanValue, FilterRuleWithMultipleValues, FilterRuleWithSingleValue, 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 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>;
7
+ export declare function finderRuleset<FItem>(rules: FinderRule<FItem>[]): FinderRule<FItem>[];
8
+ export declare function searchRule<FItem>(rule: SearchRule<FItem>): SearchRule<FItem, 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>;
12
+ export declare function sortByRule<FItem>(rule: SortByRule<FItem>): SortByRule<FItem, any>;
13
+ export declare function groupByRule<FItem>(rule: GroupByRule<FItem>): GroupByRule<FItem, any>;
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>;
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>;
@@ -1,14 +1,9 @@
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;
8
- export declare function isFilterOption(data: unknown): data is FilterOption;
9
- export declare function getRuleType(rule: FinderRule): "search" | "filter" | "sortBy" | "groupBy";
1
+ import { RuleEffect, SearchEffect } from "../types/effect-types";
2
+ import { FilterRuleUnion, GroupByRule, HydratedFilterRule, SearchRule, SortByRule } from "../types/rule-types";
10
3
  export declare function isSortByRule<FItem>(rule: unknown): rule is SortByRule<FItem>;
11
4
  export declare function isSearchRule<FItem>(rule: unknown): rule is SearchRule<FItem>;
12
- export declare function isFilterUnionRule<FItem>(rule: unknown): rule is FilterRuleUnion<FItem>;
5
+ export declare function isFilterRule<FItem>(rule: unknown): rule is FilterRuleUnion<FItem>;
13
6
  export declare function isHydratedFilterRule<FItem>(rule: unknown): rule is HydratedFilterRule<FItem>;
14
7
  export declare function isGroupByRule<FItem>(rule: unknown): rule is GroupByRule<FItem>;
8
+ export declare function isRuleEffect<FItem>(data: unknown): data is RuleEffect<FItem>;
9
+ export declare function isSearchEffect<FItem>(data: unknown): data is SearchEffect<FItem>;
package/dist/index.d.ts CHANGED
@@ -1,20 +1,14 @@
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 { FinderConstructorOptions, FinderResultGroup, SortDirection } from "./core/types/core-types";
2
+ export { finderRuleset, searchRule, filterRule, sortByRule, groupByRule, ruleEffect, searchEffect } from "./core/utils/rule-type-enforcers";
3
+ export type { FinderRule, SearchRule, SortByRule, GroupByRule, FilterRule, HydratedFilterRule, FilterRuleUnion, FilterOption } from "./core/types/rule-types";
4
+ export type { RuleEffect, SearchEffect } from "./core/types/effect-types";
5
+ export type { FinderEvent, FinderInitEvent, FinderReadyEvent, FinderFirstUserInteractionEvent, FinderChangeEvent } from "./core/types/event-types";
6
+ export type { StringMatchSegment } from "./core/types/string-match-types";
6
7
  /**
7
8
  * React hooks and components
8
9
  */
9
10
  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
11
  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
12
  export { useFinderRef } from "./react/hooks/use-finder-ref";
20
- export type { FinderProps, FinderContentComponentProps, FinderGroupsComponentProps, FinderItemsComponentProps } from "./react/types/react-types";
13
+ export { StringMatch } from "./react/components/string-match";
14
+ export type { FinderProps, FinderContentProps, FinderContentGroupProps, FinderContentItemProps, StringMatchSegmentProps } from "./react/types/react-types";