@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.
@@ -0,0 +1,32 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ import { RefObject } from 'react';
4
+
5
+ declare const validKeyEventTypes: readonly [
6
+ "keydown",
7
+ "keyup",
8
+ "keypress"
9
+ ];
10
+ export type KeyEventType = (typeof validKeyEventTypes)[number];
11
+ export interface BaseKeyOptions {
12
+ enabled?: boolean;
13
+ target?: RefObject<HTMLElement | null> | Window;
14
+ preventDefault?: boolean;
15
+ stopPropagation?: boolean;
16
+ ignoreWhenFocusedInInputs?: boolean;
17
+ ctrlKey?: boolean;
18
+ shiftKey?: boolean;
19
+ altKey?: boolean;
20
+ metaKey?: boolean;
21
+ }
22
+ export type KeyOptions = BaseKeyOptions & ({
23
+ eventType?: "keydown" | "keypress";
24
+ preventRepeat?: boolean;
25
+ } | {
26
+ eventType: "keyup";
27
+ preventRepeat?: never;
28
+ });
29
+ export type UseKeyReturn = void;
30
+ export declare function useKey(key: string, handler: (e: KeyboardEvent) => void, { enabled, preventDefault, stopPropagation, eventType, preventRepeat, ignoreWhenFocusedInInputs, ctrlKey, shiftKey, altKey, metaKey, target, }?: KeyOptions): UseKeyReturn;
31
+
32
+ export {};
package/dist/events.js ADDED
@@ -0,0 +1,2 @@
1
+ import { t as e } from "./events2.js";
2
+ export { e as useKey };
@@ -0,0 +1,54 @@
1
+ import { useEffect as e, useLayoutEffect as t, useRef as n } from "react";
2
+ //#region src/events/useKey/constants.ts
3
+ var r = [
4
+ "keydown",
5
+ "keyup",
6
+ "keypress"
7
+ ];
8
+ //#endregion
9
+ //#region src/events/useKey/useKey.ts
10
+ function i(i, a, { enabled: o = !0, preventDefault: s = !0, stopPropagation: c = !0, eventType: l = "keydown", preventRepeat: u = !1, ignoreWhenFocusedInInputs: d = !0, ctrlKey: f = !1, shiftKey: p = !1, altKey: m = !1, metaKey: h = !1, target: g = window } = {}) {
11
+ let _ = n(a), v = n(o), y = n(!1);
12
+ t(() => {
13
+ _.current = a;
14
+ }, [a]), e(() => {
15
+ v.current = o;
16
+ }, [o]), e(() => {
17
+ let e = g && "current" in g ? g.current : g;
18
+ if (!e) return;
19
+ let t = i.toLowerCase(), n = r.includes(l) ? l : "keydown", a = u && n !== "keyup";
20
+ function o() {
21
+ y.current = !1;
22
+ }
23
+ function b(e) {
24
+ if (!(e instanceof KeyboardEvent)) return;
25
+ let n = e.key.toLowerCase();
26
+ (n === t || f && n === "control" || p && n === "shift" || m && n === "alt" || h && n === "meta") && (y.current = !1);
27
+ }
28
+ function x(e) {
29
+ if (!(e instanceof KeyboardEvent) || !v.current) return;
30
+ let n = e.target;
31
+ if (!(d && n instanceof HTMLElement && (n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement || n instanceof HTMLSelectElement || n.isContentEditable)) && e.ctrlKey === f && e.shiftKey === p && e.altKey === m && e.metaKey === h && t === e.key.toLowerCase()) {
32
+ if (a && y.current) return;
33
+ y.current = !0, _.current(e), s && e.preventDefault(), c && e.stopPropagation();
34
+ }
35
+ }
36
+ return e.addEventListener(n, x), a && (e.addEventListener("keyup", b), window.addEventListener("blur", o)), () => {
37
+ e.removeEventListener(n, x), a && (e.removeEventListener("keyup", b), window.removeEventListener("blur", o));
38
+ };
39
+ }, [
40
+ i,
41
+ s,
42
+ c,
43
+ l,
44
+ u,
45
+ d,
46
+ f,
47
+ p,
48
+ m,
49
+ h,
50
+ g
51
+ ]);
52
+ }
53
+ //#endregion
54
+ export { i as t };
package/dist/index.d.ts CHANGED
@@ -3,22 +3,57 @@
3
3
  import React$1 from 'react';
4
4
  import { CSSProperties, RefObject } from 'react';
5
5
 
6
- export interface FuzzyHighlighterProps {
7
- text: string;
8
- query: string;
9
- className?: string;
10
- caseSensitive?: boolean;
6
+ declare const validKeyEventTypes: readonly [
7
+ "keydown",
8
+ "keyup",
9
+ "keypress"
10
+ ];
11
+ export type KeyEventType = (typeof validKeyEventTypes)[number];
12
+ export interface BaseKeyOptions {
13
+ enabled?: boolean;
14
+ target?: React$1.RefObject<HTMLElement | null> | Window;
15
+ preventDefault?: boolean;
16
+ stopPropagation?: boolean;
17
+ ignoreWhenFocusedInInputs?: boolean;
18
+ ctrlKey?: boolean;
19
+ shiftKey?: boolean;
20
+ altKey?: boolean;
21
+ metaKey?: boolean;
11
22
  }
12
- export declare function FuzzyHighlighter({ text, query, className, caseSensitive, }: FuzzyHighlighterProps): React$1.JSX.Element;
13
- export interface ModalLayoutProps {
14
- modalId: string;
15
- children: React$1.ReactNode;
16
- wrapperClassName?: string;
17
- wrapperStyle?: React$1.CSSProperties;
18
- containerClassName?: string;
19
- containerStyle?: React$1.CSSProperties;
23
+ export type KeyOptions = BaseKeyOptions & ({
24
+ eventType?: "keydown" | "keypress";
25
+ preventRepeat?: boolean;
26
+ } | {
27
+ eventType: "keyup";
28
+ preventRepeat?: never;
29
+ });
30
+ export type UseKeyReturn = void;
31
+ export declare function useKey(key: string, handler: (e: KeyboardEvent) => void, { enabled, preventDefault, stopPropagation, eventType, preventRepeat, ignoreWhenFocusedInInputs, ctrlKey, shiftKey, altKey, metaKey, target, }?: KeyOptions): UseKeyReturn;
32
+ export interface DebounceOptions {
33
+ maxWait?: number;
34
+ leading?: boolean;
35
+ trailing?: boolean;
20
36
  }
21
- export declare function ModalLayout({ modalId, children, wrapperClassName, wrapperStyle, containerClassName, containerStyle, }: ModalLayoutProps): import("react").ReactPortal | null;
37
+ export interface UseDebounceReturn<Args extends any[]> {
38
+ debouncedFunc: (...args: Args) => void;
39
+ cancel: () => void;
40
+ flush: () => void;
41
+ isPending: boolean;
42
+ }
43
+ export declare function useDebounce<Args extends any[]>(func: (...args: Args) => void, delay: number, options?: DebounceOptions): UseDebounceReturn<Args>;
44
+ export type UseDebouncedValueReturn<T> = T;
45
+ export declare function useDebouncedValue<T>(value: T, delay: number, options?: DebounceOptions): UseDebouncedValueReturn<T>;
46
+ export interface ThrottleOptions {
47
+ leading?: boolean;
48
+ trailing?: boolean;
49
+ }
50
+ export interface UseThrottleReturn<Args extends any[]> {
51
+ throttledFunc: (...args: Args) => void;
52
+ cancel: () => void;
53
+ flush: () => void;
54
+ isPending: boolean;
55
+ }
56
+ export declare function useThrottle<Args extends any[]>(func: (...args: Args) => void, delay: number, options?: ThrottleOptions): UseThrottleReturn<Args>;
22
57
  export type FilterType = "text" | "number" | "boolean" | "date" | "select" | "multiselect" | "custom";
23
58
  export type TextOperator = "contains" | "equals" | "startsWith" | "endsWith" | "notContains";
24
59
  export type NumberOperator = "equals" | "greaterThan" | "lessThan" | "greaterThanOrEqual" | "lessThanOrEqual" | "between";
@@ -141,24 +176,6 @@ export declare function useGrouping<T = unknown>({ items, initialGroupBy, }: {
141
176
  items: T[];
142
177
  initialGroupBy?: string;
143
178
  }): UseGroupingReturn<T>;
144
- export interface UsePaginationReturn<T> {
145
- pageItems: T[];
146
- pageSize: number;
147
- pageIndex: number;
148
- totalPages: number;
149
- canPrevious: boolean;
150
- canNext: boolean;
151
- nextPage: () => void;
152
- previousPage: () => void;
153
- goToFirstPage: () => void;
154
- goToLastPage: () => void;
155
- goToPage: (newPageIndex: number) => void;
156
- changePageSize: (newPageSize: number) => void;
157
- resetPageIndex: () => void;
158
- resetPageSize: () => void;
159
- resetPagination: () => void;
160
- }
161
- export declare function usePagination<T>(data: T[], initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
162
179
  export type SelectionId = string | number;
163
180
  export interface UseMultipleSelectionReturn<T> {
164
181
  selectedIds: SelectionId[];
@@ -184,17 +201,6 @@ export declare function useMultipleSelection<T = unknown>({ items, field, initia
184
201
  field?: string;
185
202
  initialSelectedIds?: SelectionId[];
186
203
  }): UseMultipleSelectionReturn<T>;
187
- type SelectionId$1 = string | number;
188
- export interface UseSingleSelectionReturn {
189
- selectedId: SelectionId$1 | undefined;
190
- hasSelection: boolean;
191
- select: (id: SelectionId$1) => void;
192
- deselect: () => void;
193
- toggle: (id: SelectionId$1) => void;
194
- isSelected: (id: SelectionId$1) => boolean;
195
- resetSelection: () => void;
196
- }
197
- export declare function useSingleSelection(initialSelectedId?: SelectionId$1): UseSingleSelectionReturn;
198
204
  export interface UseOrderReturn<T> {
199
205
  orderedItems: T[];
200
206
  moveUp: (index: number) => void;
@@ -209,30 +215,35 @@ export interface UseOrderReturn<T> {
209
215
  replaceOrder: (newOrderedItems: T[]) => void;
210
216
  }
211
217
  export declare function useOrder<T>(initialItems: T[]): UseOrderReturn<T>;
212
- export type PinId = string | number;
213
- export interface UsePinReturn<T> {
214
- pinnedIds: PinId[];
215
- pinnedItems: T[];
216
- unpinnedItems: T[];
217
- pinnedCount: number;
218
- hasPins: boolean;
219
- isAtMaxLimit: boolean;
220
- pin: (itemOrId: PinId | T) => void;
221
- unpin: (itemOrId: PinId | T) => void;
222
- togglePin: (itemOrId: PinId | T) => void;
223
- isPinned: (itemOrId: PinId | T) => boolean;
224
- clearPins: () => void;
225
- resetPins: () => void;
226
- replacePins: (newPinnedItems: PinId[] | T[]) => void;
227
- pinMultiple: (newItems: PinId[] | T[]) => void;
228
- unpinMultiple: (itemsToRemove: PinId[] | T[]) => void;
218
+ export interface UsePaginationReturn<T> {
219
+ pageItems: T[];
220
+ pageSize: number;
221
+ pageIndex: number;
222
+ totalPages: number;
223
+ canPrevious: boolean;
224
+ canNext: boolean;
225
+ nextPage: () => void;
226
+ previousPage: () => void;
227
+ goToFirstPage: () => void;
228
+ goToLastPage: () => void;
229
+ goToPage: (newPageIndex: number) => void;
230
+ changePageSize: (newPageSize: number) => void;
231
+ resetPageIndex: () => void;
232
+ resetPageSize: () => void;
233
+ resetPagination: () => void;
229
234
  }
230
- export declare function usePin<T = unknown>({ items, field, initialPinnedIds, maxPins, }: {
231
- items: T[];
232
- field?: string;
233
- initialPinnedIds?: PinId[];
234
- maxPins?: number;
235
- }): UsePinReturn<T>;
235
+ export declare function usePagination<T>(data: T[], initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
236
+ type SelectionId$1 = string | number;
237
+ export interface UseSingleSelectionReturn {
238
+ selectedId: SelectionId$1 | undefined;
239
+ hasSelection: boolean;
240
+ select: (id: SelectionId$1) => void;
241
+ deselect: () => void;
242
+ toggle: (id: SelectionId$1) => void;
243
+ isSelected: (id: SelectionId$1) => boolean;
244
+ resetSelection: () => void;
245
+ }
246
+ export declare function useSingleSelection(initialSelectedId?: SelectionId$1): UseSingleSelectionReturn;
236
247
  export type SortType = "numeric" | "alphabetical" | "alphanumeric" | "boolean" | "date" | "basic" | "custom";
237
248
  export interface BaseSortOptions {
238
249
  desc?: boolean;
@@ -274,6 +285,41 @@ export interface UseSortReturn<T> {
274
285
  getSortIndex: (id: string) => number | undefined;
275
286
  }
276
287
  export declare function useSort<T>(data: T[], initialSorts?: SortState): UseSortReturn<T>;
288
+ export interface FuzzyHighlighterProps {
289
+ text: string;
290
+ query: string;
291
+ className?: string;
292
+ caseSensitive?: boolean;
293
+ }
294
+ export declare function FuzzyHighlighter({ text, query, className, caseSensitive, }: FuzzyHighlighterProps): React$1.JSX.Element;
295
+ export interface ModalLayoutProps {
296
+ modalId: string;
297
+ children: React$1.ReactNode;
298
+ wrapperClassName?: string;
299
+ wrapperStyle?: React$1.CSSProperties;
300
+ containerClassName?: string;
301
+ containerStyle?: React$1.CSSProperties;
302
+ }
303
+ export declare function ModalLayout({ modalId, children, wrapperClassName, wrapperStyle, containerClassName, containerStyle, }: ModalLayoutProps): import("react").ReactPortal | null;
304
+ export type ExpansionId = string | number;
305
+ export interface UseExpansionReturn<T> {
306
+ expandedIds: ExpansionId[];
307
+ expandedItems: T[];
308
+ isExpanded: (itemOrId: ExpansionId | T) => boolean;
309
+ expand: (itemOrId: ExpansionId | T) => void;
310
+ collapse: (itemOrId: ExpansionId | T) => void;
311
+ toggle: (itemOrId: ExpansionId | T) => void;
312
+ expandAll: () => void;
313
+ collapseAll: () => void;
314
+ resetExpansion: () => void;
315
+ replaceExpansion: (newExpandedItems: ExpansionId[] | T[]) => void;
316
+ }
317
+ export declare function useExpansion<T = unknown>({ items, field, initialExpandedIds, multiple, }?: {
318
+ items?: T[];
319
+ field?: string;
320
+ initialExpandedIds?: ExpansionId[];
321
+ multiple?: boolean;
322
+ }): UseExpansionReturn<T>;
277
323
  export interface UseModalStateReturn<TData> {
278
324
  isOpen: boolean;
279
325
  id: string | null;
@@ -288,6 +334,30 @@ export type UseModalReturn<TData> = UseModalStateReturn<TData> & UseModalActions
288
334
  export declare function useModalState<TData = unknown>(): UseModalStateReturn<TData>;
289
335
  export declare function useModalActions(): UseModalActionsReturn;
290
336
  export declare function useModal<TData = unknown>(): UseModalReturn<TData>;
337
+ export type PinId = string | number;
338
+ export interface UsePinReturn<T> {
339
+ pinnedIds: PinId[];
340
+ pinnedItems: T[];
341
+ unpinnedItems: T[];
342
+ pinnedCount: number;
343
+ hasPins: boolean;
344
+ isAtMaxLimit: boolean;
345
+ pin: (itemOrId: PinId | T) => void;
346
+ unpin: (itemOrId: PinId | T) => void;
347
+ togglePin: (itemOrId: PinId | T) => void;
348
+ isPinned: (itemOrId: PinId | T) => boolean;
349
+ clearPins: () => void;
350
+ resetPins: () => void;
351
+ replacePins: (newPinnedItems: PinId[] | T[]) => void;
352
+ pinMultiple: (newItems: PinId[] | T[]) => void;
353
+ unpinMultiple: (itemsToRemove: PinId[] | T[]) => void;
354
+ }
355
+ export declare function usePin<T = unknown>({ items, field, initialPinnedIds, maxPins, }: {
356
+ items: T[];
357
+ field?: string;
358
+ initialPinnedIds?: PinId[];
359
+ maxPins?: number;
360
+ }): UsePinReturn<T>;
291
361
  export type VisibilityId = number | string;
292
362
  export interface UseVisibilityReturn<T> {
293
363
  visibleIds: VisibilityId[];
@@ -301,63 +371,12 @@ export interface UseVisibilityReturn<T> {
301
371
  showAll: (itemsArray?: VisibilityId[] | T[]) => void;
302
372
  hideAll: (itemsArray?: VisibilityId[] | T[]) => void;
303
373
  resetVisibility: () => void;
304
- replaceVisibility: (newItems: VisibilityId[] | T[]) => void;
374
+ replaceVisibility: (newVisibleItems: VisibilityId[] | T[]) => void;
305
375
  }
306
376
  export declare function useVisibility<T = unknown>({ items, field, initialVisibleIds, }: {
307
377
  items: T[];
308
378
  field?: string;
309
379
  initialVisibleIds?: VisibilityId[];
310
380
  }): UseVisibilityReturn<T>;
311
- export interface DebounceOptions {
312
- maxWait?: number;
313
- leading?: boolean;
314
- trailing?: boolean;
315
- }
316
- export interface UseDebounceReturn<Args extends any[]> {
317
- debouncedFunc: (...args: Args) => void;
318
- cancel: () => void;
319
- flush: () => void;
320
- isPending: boolean;
321
- }
322
- export declare function useDebounce<Args extends any[]>(func: (...args: Args) => void, delay: number, options?: DebounceOptions): UseDebounceReturn<Args>;
323
- export type UseDebouncedValueReturn<T> = T;
324
- export declare function useDebouncedValue<T>(value: T, delay: number, options?: DebounceOptions): UseDebouncedValueReturn<T>;
325
- export interface ThrottleOptions {
326
- leading?: boolean;
327
- trailing?: boolean;
328
- }
329
- export interface UseThrottleReturn<Args extends any[]> {
330
- throttledFunc: (...args: Args) => void;
331
- cancel: () => void;
332
- flush: () => void;
333
- isPending: boolean;
334
- }
335
- export declare function useThrottle<Args extends any[]>(func: (...args: Args) => void, delay: number, options?: ThrottleOptions): UseThrottleReturn<Args>;
336
- declare const validKeyEventTypes: readonly [
337
- "keydown",
338
- "keyup",
339
- "keypress"
340
- ];
341
- export type KeyEventType = (typeof validKeyEventTypes)[number];
342
- export interface BaseKeyOptions {
343
- enabled?: boolean;
344
- target?: React$1.RefObject<HTMLElement | null> | Window;
345
- preventDefault?: boolean;
346
- stopPropagation?: boolean;
347
- ignoreWhenFocusedInInputs?: boolean;
348
- ctrlKey?: boolean;
349
- shiftKey?: boolean;
350
- altKey?: boolean;
351
- metaKey?: boolean;
352
- }
353
- export type KeyOptions = BaseKeyOptions & ({
354
- eventType?: "keydown" | "keypress";
355
- preventRepeat?: boolean;
356
- } | {
357
- eventType: "keyup";
358
- preventRepeat?: never;
359
- });
360
- export type UseKeyReturn = void;
361
- export declare function useKey(key: string, handler: (e: KeyboardEvent) => void, { enabled, preventDefault, stopPropagation, eventType, preventRepeat, ignoreWhenFocusedInInputs, ctrlKey, shiftKey, altKey, metaKey, target, }?: KeyOptions): UseKeyReturn;
362
381
 
363
382
  export {};