@himanshu-sorathiya/react-kit 1.0.16 → 1.0.18
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/events.d.ts +32 -0
- package/dist/events.js +2 -0
- package/dist/events2.js +54 -0
- package/dist/index.d.ts +137 -118
- package/dist/index.js +5 -1004
- package/dist/performance.d.ts +29 -0
- package/dist/performance.js +2 -0
- package/dist/performance2.js +77 -0
- package/dist/state.d.ts +235 -0
- package/dist/state.js +2 -0
- package/dist/state2.js +645 -0
- package/dist/ui.d.ts +100 -0
- package/dist/ui.js +2 -0
- package/dist/ui2.js +287 -0
- package/dist/utils.js +8 -0
- package/package.json +18 -2
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export interface DebounceOptions {
|
|
4
|
+
maxWait?: number;
|
|
5
|
+
leading?: boolean;
|
|
6
|
+
trailing?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface UseDebounceReturn<Args extends any[]> {
|
|
9
|
+
debouncedFunc: (...args: Args) => void;
|
|
10
|
+
cancel: () => void;
|
|
11
|
+
flush: () => void;
|
|
12
|
+
isPending: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function useDebounce<Args extends any[]>(func: (...args: Args) => void, delay: number, options?: DebounceOptions): UseDebounceReturn<Args>;
|
|
15
|
+
export type UseDebouncedValueReturn<T> = T;
|
|
16
|
+
export declare function useDebouncedValue<T>(value: T, delay: number, options?: DebounceOptions): UseDebouncedValueReturn<T>;
|
|
17
|
+
export interface ThrottleOptions {
|
|
18
|
+
leading?: boolean;
|
|
19
|
+
trailing?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface UseThrottleReturn<Args extends any[]> {
|
|
22
|
+
throttledFunc: (...args: Args) => void;
|
|
23
|
+
cancel: () => void;
|
|
24
|
+
flush: () => void;
|
|
25
|
+
isPending: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare function useThrottle<Args extends any[]>(func: (...args: Args) => void, delay: number, options?: ThrottleOptions): UseThrottleReturn<Args>;
|
|
28
|
+
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useCallback as e, useEffect as t, useRef as n, useState as r } from "react";
|
|
2
|
+
//#region src/performance/useDebounce/useDebounce.ts
|
|
3
|
+
function i(i, a, o = {}) {
|
|
4
|
+
let [s, c] = r(!1), l = o.maxWait, u = !!o.leading, d = !u && o.trailing === !1 ? !0 : o.trailing ?? !u, f = n(i), p = n(null), m = n(-1), h = n(-1), g = n(null);
|
|
5
|
+
t(() => {
|
|
6
|
+
f.current = i;
|
|
7
|
+
}, [i]);
|
|
8
|
+
let _ = e(() => {
|
|
9
|
+
p.current &&= (clearTimeout(p.current), null), m.current = -1, h.current = -1, g.current = null, c(!1);
|
|
10
|
+
}, []), v = e(() => {
|
|
11
|
+
p.current && g.current && (clearTimeout(p.current), p.current = null, f.current(...g.current), m.current = Date.now(), h.current = -1, g.current = null, c(!1));
|
|
12
|
+
}, []);
|
|
13
|
+
return t(() => () => {
|
|
14
|
+
_();
|
|
15
|
+
}, [_]), {
|
|
16
|
+
debouncedFunc: e((...e) => {
|
|
17
|
+
c(!0), h.current = Date.now(), g.current = e, m.current === -1 && (m.current = Date.now(), u === !0 && f.current(...e)), l !== void 0 && Date.now() - m.current >= l ? (p.current && clearTimeout(p.current), f.current(...e), m.current = -1, c(!1)) : (p.current && clearTimeout(p.current), p.current = setTimeout(() => {
|
|
18
|
+
h.current !== m.current && d !== !1 && f.current(...e), m.current = -1, c(!1);
|
|
19
|
+
}, a));
|
|
20
|
+
}, [
|
|
21
|
+
a,
|
|
22
|
+
l,
|
|
23
|
+
d,
|
|
24
|
+
u
|
|
25
|
+
]),
|
|
26
|
+
cancel: _,
|
|
27
|
+
flush: v,
|
|
28
|
+
isPending: s
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/performance/useDebounce/useDebouncedValue.ts
|
|
33
|
+
function a(e, n, a = {}) {
|
|
34
|
+
let [o, s] = r(e), { debouncedFunc: c } = i((e) => {
|
|
35
|
+
s(e);
|
|
36
|
+
}, n, a);
|
|
37
|
+
return t(() => {
|
|
38
|
+
c(e);
|
|
39
|
+
}, [e, c]), o;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/performance/useThrottle/useThrottle.ts
|
|
43
|
+
function o(i, a, o = {}) {
|
|
44
|
+
let [s, c] = r(!1), l = o.leading ?? !0, u = o.trailing ?? !0, d = n(i), f = n(null), p = n(-1), m = n(null);
|
|
45
|
+
t(() => {
|
|
46
|
+
d.current = i;
|
|
47
|
+
}, [i]);
|
|
48
|
+
let h = e(() => {
|
|
49
|
+
f.current &&= (clearTimeout(f.current), null), p.current = -1, m.current = null, c(!1);
|
|
50
|
+
}, []), g = e(() => {
|
|
51
|
+
m.current && (f.current &&= (clearTimeout(f.current), null), d.current(...m.current), p.current = l ? Date.now() : -1, m.current = null, c(!1));
|
|
52
|
+
}, [l]);
|
|
53
|
+
return t(() => () => {
|
|
54
|
+
h();
|
|
55
|
+
}, [h]), {
|
|
56
|
+
throttledFunc: e((...e) => {
|
|
57
|
+
c(!0);
|
|
58
|
+
let t = Date.now();
|
|
59
|
+
if (m.current = e, p.current === -1 ? l : t - p.current >= a) f.current &&= (clearTimeout(f.current), null), d.current(...e), p.current = t, m.current = null, c(!1);
|
|
60
|
+
else if (!f.current) {
|
|
61
|
+
let e = a - (p.current === -1 ? 0 : t - p.current);
|
|
62
|
+
f.current = setTimeout(() => {
|
|
63
|
+
u && m.current ? (d.current(...m.current), p.current = l ? Date.now() : -1) : p.current = -1, m.current = null, f.current = null, c(!1);
|
|
64
|
+
}, e);
|
|
65
|
+
}
|
|
66
|
+
}, [
|
|
67
|
+
a,
|
|
68
|
+
l,
|
|
69
|
+
u
|
|
70
|
+
]),
|
|
71
|
+
cancel: h,
|
|
72
|
+
flush: g,
|
|
73
|
+
isPending: s
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { a as n, i as r, o as t };
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export type FilterType = "text" | "number" | "boolean" | "date" | "select" | "multiselect" | "custom";
|
|
4
|
+
export type TextOperator = "contains" | "equals" | "startsWith" | "endsWith" | "notContains";
|
|
5
|
+
export type NumberOperator = "equals" | "greaterThan" | "lessThan" | "greaterThanOrEqual" | "lessThanOrEqual" | "between";
|
|
6
|
+
export type BooleanOperator = "equals";
|
|
7
|
+
export type DateOperator = "equals" | "before" | "after" | "between";
|
|
8
|
+
export type SelectOperator = "equals" | "notEquals";
|
|
9
|
+
export type MultiselectOperator = "in" | "notIn" | "intersects";
|
|
10
|
+
export type CustomOperator = "custom";
|
|
11
|
+
export interface FilterOptions<T = unknown> {
|
|
12
|
+
caseSensitive?: boolean;
|
|
13
|
+
compare?: (itemValue: unknown, filterValue: unknown, item: T) => boolean;
|
|
14
|
+
}
|
|
15
|
+
export type BaseFilterConfig<T> = FilterOptions<T> & {
|
|
16
|
+
id: string;
|
|
17
|
+
field: string;
|
|
18
|
+
isActive?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type FilterConfig<T = unknown> = BaseFilterConfig<T> & ({
|
|
21
|
+
type: "text";
|
|
22
|
+
operator: TextOperator;
|
|
23
|
+
value: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: "number";
|
|
26
|
+
operator: "between";
|
|
27
|
+
value: {
|
|
28
|
+
min: number;
|
|
29
|
+
max: number;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
type: "number";
|
|
33
|
+
operator: Exclude<NumberOperator, "between">;
|
|
34
|
+
value: number;
|
|
35
|
+
} | {
|
|
36
|
+
type: "boolean";
|
|
37
|
+
operator: BooleanOperator;
|
|
38
|
+
value: boolean;
|
|
39
|
+
} | {
|
|
40
|
+
type: "date";
|
|
41
|
+
operator: "between";
|
|
42
|
+
value: {
|
|
43
|
+
min: string | number | Date;
|
|
44
|
+
max: string | number | Date;
|
|
45
|
+
};
|
|
46
|
+
} | {
|
|
47
|
+
type: "date";
|
|
48
|
+
operator: Exclude<DateOperator, "between">;
|
|
49
|
+
value: string | number | Date;
|
|
50
|
+
} | {
|
|
51
|
+
type: "select";
|
|
52
|
+
operator: SelectOperator;
|
|
53
|
+
value: string | number;
|
|
54
|
+
} | {
|
|
55
|
+
type: "multiselect";
|
|
56
|
+
operator: MultiselectOperator;
|
|
57
|
+
value: (string | number)[];
|
|
58
|
+
} | {
|
|
59
|
+
type: "custom";
|
|
60
|
+
operator: CustomOperator;
|
|
61
|
+
value: unknown;
|
|
62
|
+
});
|
|
63
|
+
export type FilterState<T> = FilterConfig<T>[];
|
|
64
|
+
export interface UseFilterReturn<T> {
|
|
65
|
+
filteredItems: T[];
|
|
66
|
+
filters: FilterState<T>;
|
|
67
|
+
upsertFilter: (filter: FilterConfig<T>) => void;
|
|
68
|
+
removeFilter: (id: string | string[]) => void;
|
|
69
|
+
clearFilters: () => void;
|
|
70
|
+
resetFilters: () => void;
|
|
71
|
+
replaceFilters: (filters: FilterConfig<T>[]) => void;
|
|
72
|
+
toggleFilter: (filter: FilterConfig<T>) => void;
|
|
73
|
+
updateFilterConfig: (id: string, partialConfig: Partial<Omit<FilterConfig<T>, "id">>) => void;
|
|
74
|
+
getFilterValue: (id: string) => unknown;
|
|
75
|
+
updateFilterValue: (id: string, value: unknown) => void;
|
|
76
|
+
isFilterActive: (id: string) => boolean;
|
|
77
|
+
}
|
|
78
|
+
export declare function useFilter<T>(data: T[], initialFilters?: FilterState<T>): UseFilterReturn<T>;
|
|
79
|
+
export interface FuzzySearchOptions {
|
|
80
|
+
threshold?: number;
|
|
81
|
+
caseSensitive?: boolean;
|
|
82
|
+
matchStrategy?: "any" | "all";
|
|
83
|
+
exactPhraseBonus?: boolean;
|
|
84
|
+
}
|
|
85
|
+
export interface IndexedToken {
|
|
86
|
+
text: string;
|
|
87
|
+
weight: number;
|
|
88
|
+
}
|
|
89
|
+
export interface FlatIndexedItem<T> {
|
|
90
|
+
item: T;
|
|
91
|
+
index: number;
|
|
92
|
+
tokens: IndexedToken[];
|
|
93
|
+
combinedFlatText: string;
|
|
94
|
+
}
|
|
95
|
+
export interface ScoredItem<T> {
|
|
96
|
+
item: T;
|
|
97
|
+
score: number;
|
|
98
|
+
index: number;
|
|
99
|
+
}
|
|
100
|
+
export type UseFuzzySearchFields<T> = {
|
|
101
|
+
field: Extract<keyof T, string>;
|
|
102
|
+
weight: number;
|
|
103
|
+
}[];
|
|
104
|
+
export type UseFuzzySearchReturn<T> = T[];
|
|
105
|
+
export declare function useFuzzySearch<T>(data: T[], query: string, fields: UseFuzzySearchFields<T>, options?: FuzzySearchOptions): UseFuzzySearchReturn<T>;
|
|
106
|
+
export interface Group<T> {
|
|
107
|
+
key: string;
|
|
108
|
+
items: T[];
|
|
109
|
+
}
|
|
110
|
+
export interface UseGroupingReturn<T> {
|
|
111
|
+
groupedRecord: Record<string, T[]>;
|
|
112
|
+
groupedArray: Group<T>[];
|
|
113
|
+
groupKeys: string[];
|
|
114
|
+
totalGroups: number;
|
|
115
|
+
activeGroupBy: string | undefined;
|
|
116
|
+
changeGroupBy: (newField: string) => void;
|
|
117
|
+
clearGrouping: () => void;
|
|
118
|
+
resetGrouping: () => void;
|
|
119
|
+
getGroupItems: (groupKey: string) => T[];
|
|
120
|
+
}
|
|
121
|
+
export declare function useGrouping<T = unknown>({ items, initialGroupBy, }: {
|
|
122
|
+
items: T[];
|
|
123
|
+
initialGroupBy?: string;
|
|
124
|
+
}): UseGroupingReturn<T>;
|
|
125
|
+
export type SelectionId = string | number;
|
|
126
|
+
export interface UseMultipleSelectionReturn<T> {
|
|
127
|
+
selectedIds: SelectionId[];
|
|
128
|
+
selectedCount: number;
|
|
129
|
+
selectedItems: T[];
|
|
130
|
+
isEmpty: boolean;
|
|
131
|
+
select: (item: SelectionId | T) => void;
|
|
132
|
+
deselect: (item: SelectionId | T) => void;
|
|
133
|
+
toggle: (item: SelectionId | T) => void;
|
|
134
|
+
isSelected: (item: SelectionId | T) => boolean;
|
|
135
|
+
resetSelection: () => void;
|
|
136
|
+
replaceSelection: (newSelectedItems: SelectionId[] | T[]) => void;
|
|
137
|
+
selectAll: () => void;
|
|
138
|
+
deselectAll: () => void;
|
|
139
|
+
toggleAll: () => void;
|
|
140
|
+
invertSelection: () => void;
|
|
141
|
+
selectMultiple: (newItems: SelectionId[] | T[]) => void;
|
|
142
|
+
deselectMultiple: (itemsToRemove: SelectionId[] | T[]) => void;
|
|
143
|
+
retainOnly: (itemsToRetain: SelectionId[] | T[]) => void;
|
|
144
|
+
}
|
|
145
|
+
export declare function useMultipleSelection<T = unknown>({ items, field, initialSelectedIds, }: {
|
|
146
|
+
items: T[];
|
|
147
|
+
field?: string;
|
|
148
|
+
initialSelectedIds?: SelectionId[];
|
|
149
|
+
}): UseMultipleSelectionReturn<T>;
|
|
150
|
+
export interface UseOrderReturn<T> {
|
|
151
|
+
orderedItems: T[];
|
|
152
|
+
moveUp: (index: number) => void;
|
|
153
|
+
moveDown: (index: number) => void;
|
|
154
|
+
canMoveUp: (index: number) => boolean;
|
|
155
|
+
canMoveDown: (index: number) => boolean;
|
|
156
|
+
moveToTop: (index: number) => void;
|
|
157
|
+
moveToBottom: (index: number) => void;
|
|
158
|
+
move: (fromIndex: number, toIndex: number) => void;
|
|
159
|
+
swap: (indexA: number, indexB: number) => void;
|
|
160
|
+
resetOrder: () => void;
|
|
161
|
+
replaceOrder: (newOrderedItems: T[]) => void;
|
|
162
|
+
}
|
|
163
|
+
export declare function useOrder<T>(initialItems: T[]): UseOrderReturn<T>;
|
|
164
|
+
export interface UsePaginationReturn<T> {
|
|
165
|
+
pageItems: T[];
|
|
166
|
+
pageSize: number;
|
|
167
|
+
pageIndex: number;
|
|
168
|
+
totalPages: number;
|
|
169
|
+
canPrevious: boolean;
|
|
170
|
+
canNext: boolean;
|
|
171
|
+
nextPage: () => void;
|
|
172
|
+
previousPage: () => void;
|
|
173
|
+
goToFirstPage: () => void;
|
|
174
|
+
goToLastPage: () => void;
|
|
175
|
+
goToPage: (newPageIndex: number) => void;
|
|
176
|
+
changePageSize: (newPageSize: number) => void;
|
|
177
|
+
resetPageIndex: () => void;
|
|
178
|
+
resetPageSize: () => void;
|
|
179
|
+
resetPagination: () => void;
|
|
180
|
+
}
|
|
181
|
+
export declare function usePagination<T>(data: T[], initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
182
|
+
type SelectionId$1 = string | number;
|
|
183
|
+
export interface UseSingleSelectionReturn {
|
|
184
|
+
selectedId: SelectionId$1 | undefined;
|
|
185
|
+
hasSelection: boolean;
|
|
186
|
+
select: (id: SelectionId$1) => void;
|
|
187
|
+
deselect: () => void;
|
|
188
|
+
toggle: (id: SelectionId$1) => void;
|
|
189
|
+
isSelected: (id: SelectionId$1) => boolean;
|
|
190
|
+
resetSelection: () => void;
|
|
191
|
+
}
|
|
192
|
+
export declare function useSingleSelection(initialSelectedId?: SelectionId$1): UseSingleSelectionReturn;
|
|
193
|
+
export type SortType = "numeric" | "alphabetical" | "alphanumeric" | "boolean" | "date" | "basic" | "custom";
|
|
194
|
+
export interface BaseSortOptions {
|
|
195
|
+
desc?: boolean;
|
|
196
|
+
disableSortRemoval?: boolean;
|
|
197
|
+
invertSorting?: boolean;
|
|
198
|
+
sortUndefined?: "first" | "last" | -1 | 1;
|
|
199
|
+
}
|
|
200
|
+
export interface BaseSortConfig extends BaseSortOptions {
|
|
201
|
+
id: string;
|
|
202
|
+
field?: string;
|
|
203
|
+
}
|
|
204
|
+
export type SortConfig = BaseSortConfig & ({
|
|
205
|
+
type: "numeric" | "boolean" | "date" | "basic";
|
|
206
|
+
} | {
|
|
207
|
+
type: "alphabetical" | "alphanumeric";
|
|
208
|
+
caseSensitive?: boolean;
|
|
209
|
+
} | {
|
|
210
|
+
type: "custom";
|
|
211
|
+
compare: (a: unknown, b: unknown) => number;
|
|
212
|
+
});
|
|
213
|
+
export type SortState = SortConfig[];
|
|
214
|
+
export type SortOptionsForType<T extends SortType> = Omit<Extract<SortConfig, {
|
|
215
|
+
type: T;
|
|
216
|
+
}>, "id" | "type" | "field">;
|
|
217
|
+
export interface UseSortReturn<T> {
|
|
218
|
+
sortedItems: T[];
|
|
219
|
+
sorts: SortState;
|
|
220
|
+
upsertSorts: (sort: SortConfig) => void;
|
|
221
|
+
removeSort: (id: string | string[]) => void;
|
|
222
|
+
clearSorts: () => void;
|
|
223
|
+
resetSorts: () => void;
|
|
224
|
+
replaceSorts: (sorts: SortState) => void;
|
|
225
|
+
toggleSort: <TType extends SortType>(id: string, type: TType, options?: SortOptionsForType<TType> & {
|
|
226
|
+
multi?: boolean;
|
|
227
|
+
field?: string;
|
|
228
|
+
}) => void;
|
|
229
|
+
getSortDirection: (id: string) => "asc" | "desc" | undefined;
|
|
230
|
+
getNextSortingOrder: (id: string) => "asc" | "desc" | "none";
|
|
231
|
+
getSortIndex: (id: string) => number | undefined;
|
|
232
|
+
}
|
|
233
|
+
export declare function useSort<T>(data: T[], initialSorts?: SortState): UseSortReturn<T>;
|
|
234
|
+
|
|
235
|
+
export {};
|
package/dist/state.js
ADDED