@himanshu-sorathiya/react-kit 1.0.21 → 1.0.22
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 +30 -0
- package/dist/events.js +2 -2
- package/dist/events2.js +72 -30
- package/dist/index.d.ts +30 -0
- package/dist/index.js +5 -5
- package/package.json +1 -1
package/dist/events.d.ts
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
import { RefObject } from 'react';
|
|
4
4
|
|
|
5
|
+
export type ClickOutsideEvent = MouseEvent | TouchEvent | PointerEvent | Event;
|
|
6
|
+
export type ClickOutsideTarget = HTMLElement | null;
|
|
7
|
+
export type ClickOutsideTargetRef = RefObject<ClickOutsideTarget> | ClickOutsideTarget;
|
|
8
|
+
export interface UseClickOutsideOptions {
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
eventType?: string | string[];
|
|
11
|
+
}
|
|
12
|
+
export type UseClickOutsideReturn = void;
|
|
13
|
+
export declare function useClickOutside(target: ClickOutsideTargetRef | ClickOutsideTargetRef[], handler: (event: ClickOutsideEvent) => void, options?: UseClickOutsideOptions): UseClickOutsideReturn;
|
|
14
|
+
export type TargetType = EventTarget;
|
|
15
|
+
export type TargetRef<T extends TargetType> = RefObject<T | null> | T | null;
|
|
16
|
+
export interface UseEventListenerOptions<T extends TargetType> extends AddEventListenerOptions {
|
|
17
|
+
target?: TargetRef<T>;
|
|
18
|
+
}
|
|
19
|
+
export type UseEventListenerReturn = void;
|
|
20
|
+
export declare function useEventListener<K extends keyof WindowEventMap>(eventName: K | K[], handler: (event: WindowEventMap[K]) => void, options?: UseEventListenerOptions<Window> & {
|
|
21
|
+
target?: Window | null | undefined;
|
|
22
|
+
}): UseEventListenerReturn;
|
|
23
|
+
export declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K | K[], handler: (event: DocumentEventMap[K]) => void, options: UseEventListenerOptions<Document> & {
|
|
24
|
+
target: Document | RefObject<Document | null> | null;
|
|
25
|
+
}): UseEventListenerReturn;
|
|
26
|
+
export declare function useEventListener<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLElement>(eventName: K | K[], handler: (event: HTMLElementEventMap[K]) => void, options: UseEventListenerOptions<T> & {
|
|
27
|
+
target: T | RefObject<T | null> | null;
|
|
28
|
+
}): UseEventListenerReturn;
|
|
29
|
+
export declare function useEventListener<K extends keyof SVGElementEventMap, T extends SVGElement = SVGElement>(eventName: K | K[], handler: (event: SVGElementEventMap[K]) => void, options: UseEventListenerOptions<T> & {
|
|
30
|
+
target: T | RefObject<T | null> | null;
|
|
31
|
+
}): UseEventListenerReturn;
|
|
32
|
+
export declare function useEventListener<K extends string, T extends TargetType = TargetType>(eventName: K | K[], handler: (event: Event) => void, options: UseEventListenerOptions<T> & {
|
|
33
|
+
target: T | RefObject<T | null> | null;
|
|
34
|
+
}): UseEventListenerReturn;
|
|
5
35
|
declare const validKeyEventTypes: readonly [
|
|
6
36
|
"keydown",
|
|
7
37
|
"keyup",
|
package/dist/events.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { e as useKey };
|
|
1
|
+
import { n as e, r as t, t as n } from "./events2.js";
|
|
2
|
+
export { e as useClickOutside, t as useEventListener, n as useKey };
|
package/dist/events2.js
CHANGED
|
@@ -1,45 +1,87 @@
|
|
|
1
1
|
import { useEffect as e, useLayoutEffect as t, useRef as n } from "react";
|
|
2
|
+
//#region src/events/useEventListener/useEventListener.ts
|
|
3
|
+
var r = typeof window < "u" ? t : e;
|
|
4
|
+
function i(t, i, a = {}) {
|
|
5
|
+
let { target: o, capture: s = !1, passive: c = !1, once: l = !1 } = a, u = o === void 0 ? typeof window > "u" ? null : window : o, d = n(i);
|
|
6
|
+
r(() => {
|
|
7
|
+
d.current = i;
|
|
8
|
+
}, [i]), e(() => {
|
|
9
|
+
let e = u && "current" in u ? u.current : u;
|
|
10
|
+
if (!e?.addEventListener) return;
|
|
11
|
+
let n = Array.isArray(t) ? t : [t], r = (e) => d.current(e);
|
|
12
|
+
return n.forEach((t) => {
|
|
13
|
+
e.addEventListener(t, r, {
|
|
14
|
+
capture: s,
|
|
15
|
+
passive: c,
|
|
16
|
+
once: l
|
|
17
|
+
});
|
|
18
|
+
}), () => {
|
|
19
|
+
n.forEach((t) => {
|
|
20
|
+
e.removeEventListener(t, r, { capture: s });
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}, [
|
|
24
|
+
Array.isArray(t) ? t.join(",") : t,
|
|
25
|
+
u,
|
|
26
|
+
s,
|
|
27
|
+
c,
|
|
28
|
+
l
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/events/useClickOutside/useClickOutside.ts
|
|
33
|
+
var a = typeof window < "u" ? t : e;
|
|
34
|
+
function o(e, t, r = {}) {
|
|
35
|
+
let { enabled: o = !0, eventType: s = ["mousedown", "touchstart"] } = r, c = n(t);
|
|
36
|
+
a(() => {
|
|
37
|
+
c.current = t;
|
|
38
|
+
}, [t]), i(s, (t) => {
|
|
39
|
+
o && (Array.isArray(e) ? e : [e]).every((e) => {
|
|
40
|
+
let n = e && "current" in e ? e.current : e;
|
|
41
|
+
return n && !n.contains(t.target);
|
|
42
|
+
}) && c.current(t);
|
|
43
|
+
}, { target: typeof document > "u" ? null : document });
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
2
46
|
//#region src/events/useKey/constants.ts
|
|
3
|
-
var
|
|
47
|
+
var s = [
|
|
4
48
|
"keydown",
|
|
5
49
|
"keyup",
|
|
6
50
|
"keypress"
|
|
7
|
-
];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}, [
|
|
15
|
-
|
|
16
|
-
}, [o]), e(() => {
|
|
17
|
-
let e = g && "current" in g ? g.current : g;
|
|
51
|
+
], c = typeof window < "u" ? t : e;
|
|
52
|
+
function l(t, r, { enabled: i = !0, preventDefault: a = !0, stopPropagation: o = !0, eventType: l = "keydown", preventRepeat: u = !1, ignoreWhenFocusedInInputs: d = !0, ctrlKey: f = !1, shiftKey: p = !1, altKey: m = !1, metaKey: h = !1, target: g } = {}) {
|
|
53
|
+
let _ = g === void 0 ? typeof window > "u" ? null : window : g, v = n(r), y = n(i), b = n(!1);
|
|
54
|
+
c(() => {
|
|
55
|
+
v.current = r;
|
|
56
|
+
}, [r]), e(() => {
|
|
57
|
+
y.current = i;
|
|
58
|
+
}, [i]), e(() => {
|
|
59
|
+
let e = _ && "current" in _ ? _.current : _;
|
|
18
60
|
if (!e) return;
|
|
19
|
-
let
|
|
20
|
-
function
|
|
21
|
-
|
|
61
|
+
let n = String(t || "").toLowerCase(), r = s.includes(l) ? l : "keydown", i = u && r !== "keyup";
|
|
62
|
+
function c() {
|
|
63
|
+
b.current = !1;
|
|
22
64
|
}
|
|
23
|
-
function
|
|
65
|
+
function g(e) {
|
|
24
66
|
if (!(e instanceof KeyboardEvent)) return;
|
|
25
|
-
let
|
|
26
|
-
(
|
|
67
|
+
let t = e.key.toLowerCase();
|
|
68
|
+
(t === n || f && t === "control" || p && t === "shift" || m && t === "alt" || h && t === "meta") && (b.current = !1);
|
|
27
69
|
}
|
|
28
70
|
function x(e) {
|
|
29
|
-
if (!(e instanceof KeyboardEvent) || !
|
|
30
|
-
let
|
|
31
|
-
if (!(d &&
|
|
32
|
-
if (
|
|
33
|
-
|
|
71
|
+
if (!(e instanceof KeyboardEvent) || !y.current) return;
|
|
72
|
+
let t = e.target;
|
|
73
|
+
if (!(d && t instanceof HTMLElement && (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement || t.isContentEditable)) && e.ctrlKey === f && e.shiftKey === p && e.altKey === m && e.metaKey === h && n === e.key.toLowerCase()) {
|
|
74
|
+
if (i && b.current) return;
|
|
75
|
+
b.current = !0, v.current(e), a && e.preventDefault(), o && e.stopPropagation();
|
|
34
76
|
}
|
|
35
77
|
}
|
|
36
|
-
return e.addEventListener(
|
|
37
|
-
e.removeEventListener(
|
|
78
|
+
return e.addEventListener(r, x), i && (e.addEventListener("keyup", g), window.addEventListener("blur", c)), () => {
|
|
79
|
+
e.removeEventListener(r, x), i && (e.removeEventListener("keyup", g), window.removeEventListener("blur", c));
|
|
38
80
|
};
|
|
39
81
|
}, [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
82
|
+
t,
|
|
83
|
+
a,
|
|
84
|
+
o,
|
|
43
85
|
l,
|
|
44
86
|
u,
|
|
45
87
|
d,
|
|
@@ -47,8 +89,8 @@ function i(i, a, { enabled: o = !0, preventDefault: s = !0, stopPropagation: c =
|
|
|
47
89
|
p,
|
|
48
90
|
m,
|
|
49
91
|
h,
|
|
50
|
-
|
|
92
|
+
_
|
|
51
93
|
]);
|
|
52
94
|
}
|
|
53
95
|
//#endregion
|
|
54
|
-
export { i as t };
|
|
96
|
+
export { o as n, i as r, l as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -181,6 +181,36 @@ export declare function isAM(date: DateInput): boolean;
|
|
|
181
181
|
export declare function isPM(date: DateInput): boolean;
|
|
182
182
|
export declare function isLeapYear(yearOrDate: number | Date): boolean;
|
|
183
183
|
export declare function isInLeapYear(date: DateInput): boolean;
|
|
184
|
+
export type ClickOutsideEvent = MouseEvent | TouchEvent | PointerEvent | Event;
|
|
185
|
+
export type ClickOutsideTarget = HTMLElement | null;
|
|
186
|
+
export type ClickOutsideTargetRef = React$1.RefObject<ClickOutsideTarget> | ClickOutsideTarget;
|
|
187
|
+
export interface UseClickOutsideOptions {
|
|
188
|
+
enabled?: boolean;
|
|
189
|
+
eventType?: string | string[];
|
|
190
|
+
}
|
|
191
|
+
export type UseClickOutsideReturn = void;
|
|
192
|
+
export declare function useClickOutside(target: ClickOutsideTargetRef | ClickOutsideTargetRef[], handler: (event: ClickOutsideEvent) => void, options?: UseClickOutsideOptions): UseClickOutsideReturn;
|
|
193
|
+
export type TargetType = EventTarget;
|
|
194
|
+
export type TargetRef<T extends TargetType> = React$1.RefObject<T | null> | T | null;
|
|
195
|
+
export interface UseEventListenerOptions<T extends TargetType> extends AddEventListenerOptions {
|
|
196
|
+
target?: TargetRef<T>;
|
|
197
|
+
}
|
|
198
|
+
export type UseEventListenerReturn = void;
|
|
199
|
+
export declare function useEventListener<K extends keyof WindowEventMap>(eventName: K | K[], handler: (event: WindowEventMap[K]) => void, options?: UseEventListenerOptions<Window> & {
|
|
200
|
+
target?: Window | null | undefined;
|
|
201
|
+
}): UseEventListenerReturn;
|
|
202
|
+
export declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K | K[], handler: (event: DocumentEventMap[K]) => void, options: UseEventListenerOptions<Document> & {
|
|
203
|
+
target: Document | React$1.RefObject<Document | null> | null;
|
|
204
|
+
}): UseEventListenerReturn;
|
|
205
|
+
export declare function useEventListener<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLElement>(eventName: K | K[], handler: (event: HTMLElementEventMap[K]) => void, options: UseEventListenerOptions<T> & {
|
|
206
|
+
target: T | React$1.RefObject<T | null> | null;
|
|
207
|
+
}): UseEventListenerReturn;
|
|
208
|
+
export declare function useEventListener<K extends keyof SVGElementEventMap, T extends SVGElement = SVGElement>(eventName: K | K[], handler: (event: SVGElementEventMap[K]) => void, options: UseEventListenerOptions<T> & {
|
|
209
|
+
target: T | React$1.RefObject<T | null> | null;
|
|
210
|
+
}): UseEventListenerReturn;
|
|
211
|
+
export declare function useEventListener<K extends string, T extends TargetType = TargetType>(eventName: K | K[], handler: (event: Event) => void, options: UseEventListenerOptions<T> & {
|
|
212
|
+
target: T | React$1.RefObject<T | null> | null;
|
|
213
|
+
}): UseEventListenerReturn;
|
|
184
214
|
declare const validKeyEventTypes: readonly [
|
|
185
215
|
"keydown",
|
|
186
216
|
"keyup",
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { addBusinessDays as e, addDays as t, addHours as n, addMilliseconds as r, addMinutes as i, addMonths as a, addSeconds as o, addWeeks as s, addYears as c, clampDate as l, closestTo as u, createDate as d, differenceInBusinessDays as f, differenceInDays as p, differenceInHours as m, differenceInMilliseconds as h, differenceInMinutes as g, differenceInMonths as _, differenceInSeconds as v, differenceInWeeks as y, differenceInYears as b, durationToMilliseconds as x, eachDayOfInterval as S, eachMonthOfInterval as C, eachYearOfInterval as w, endOfDay as T, endOfHour as E, endOfMinute as D, endOfMonth as O, endOfQuarter as k, endOfWeek as A, endOfYear as j, format as M, formatDate as N, formatDuration as P, formatISO as F, formatISO9075 as I, formatRFC2822 as L, formatRFC3339 as R, formatRelativeTime as z, fromUnixTime as B, getDate as V, getDayOfWeek as H, getDayOfYear as U, getDaysInMonth as W, getHours as G, getISOWeek as K, getMilliseconds as q, getMinutes as J, getMonth as Y, getQuarter as X, getSeconds as Z, getTimestamp as Q, getYear as $, intervalToDuration as ee, isAM as te, isAfter as ne, isBefore as re, isDate as ie, isEqual as ae, isFirstDayOfMonth as oe, isFuture as se, isInLeapYear as ce, isLastDayOfMonth as le, isLeapYear as ue, isOverlapping as de, isPM as fe, isPast as pe, isSameDay as me, isSameHour as he, isSameMinute as ge, isSameMonth as _e, isSameQuarter as ve, isSameSecond as ye, isSameTime as be, isSameWeek as xe, isSameYear as Se, isThisMonth as Ce, isThisWeek as we, isThisYear as Te, isToday as Ee, isTomorrow as De, isValid as Oe, isWeekday as ke, isWeekend as Ae, isWithinRange as je, isYesterday as Me, max as Ne, min as Pe, parseISO as Fe, roundToNearestMinutes as Ie, setDate as Le, setHours as Re, setISOWeek as ze, setMilliseconds as Be, setMinutes as Ve, setMonth as He, setSeconds as Ue, setYear as We, startOfDay as Ge, startOfHour as Ke, startOfMinute as qe, startOfMonth as Je, startOfQuarter as Ye, startOfWeek as Xe, startOfYear as Ze, subDays as Qe, subHours as $e, subMilliseconds as et, subMinutes as tt, subMonths as nt, subSeconds as rt, subWeeks as it, subYears as at, toDate as ot, toISOString as st, toUnixTime as ct } from "./datetime.js";
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
4
|
-
import { a as
|
|
5
|
-
import { a as
|
|
6
|
-
export {
|
|
2
|
+
import { n as lt, r as ut, t as dt } from "./events2.js";
|
|
3
|
+
import { a as ft, c as pt, i as mt, l as ht, n as gt, o as _t, r as vt, s as yt, t as bt, u as xt } from "./performance2.js";
|
|
4
|
+
import { a as St, c as Ct, i as wt, n as Tt, o as Et, r as Dt, s as Ot, t as kt } from "./state2.js";
|
|
5
|
+
import { a as At, c as jt, i as Mt, n as Nt, o as Pt, r as Ft, s as It, t as Lt } from "./ui2.js";
|
|
6
|
+
export { jt as FuzzyHighlighter, Mt as ModalLayout, e as addBusinessDays, t as addDays, n as addHours, r as addMilliseconds, i as addMinutes, a as addMonths, o as addSeconds, s as addWeeks, c as addYears, l as clampDate, u as closestTo, d as createDate, f as differenceInBusinessDays, p as differenceInDays, m as differenceInHours, h as differenceInMilliseconds, g as differenceInMinutes, _ as differenceInMonths, v as differenceInSeconds, y as differenceInWeeks, b as differenceInYears, x as durationToMilliseconds, S as eachDayOfInterval, C as eachMonthOfInterval, w as eachYearOfInterval, T as endOfDay, E as endOfHour, D as endOfMinute, O as endOfMonth, k as endOfQuarter, A as endOfWeek, j as endOfYear, M as format, N as formatDate, P as formatDuration, F as formatISO, I as formatISO9075, L as formatRFC2822, R as formatRFC3339, z as formatRelativeTime, B as fromUnixTime, V as getDate, H as getDayOfWeek, U as getDayOfYear, W as getDaysInMonth, G as getHours, K as getISOWeek, q as getMilliseconds, J as getMinutes, Y as getMonth, X as getQuarter, Z as getSeconds, Q as getTimestamp, $ as getYear, ee as intervalToDuration, te as isAM, ne as isAfter, re as isBefore, ie as isDate, ae as isEqual, oe as isFirstDayOfMonth, se as isFuture, ce as isInLeapYear, le as isLastDayOfMonth, ue as isLeapYear, de as isOverlapping, fe as isPM, pe as isPast, me as isSameDay, he as isSameHour, ge as isSameMinute, _e as isSameMonth, ve as isSameQuarter, ye as isSameSecond, be as isSameTime, xe as isSameWeek, Se as isSameYear, Ce as isThisMonth, we as isThisWeek, Te as isThisYear, Ee as isToday, De as isTomorrow, Oe as isValid, ke as isWeekday, Ae as isWeekend, je as isWithinRange, Me as isYesterday, Ne as max, Pe as min, Fe as parseISO, Ie as roundToNearestMinutes, Le as setDate, Re as setHours, ze as setISOWeek, Be as setMilliseconds, Ve as setMinutes, He as setMonth, Ue as setSeconds, We as setYear, Ge as startOfDay, Ke as startOfHour, qe as startOfMinute, Je as startOfMonth, Ye as startOfQuarter, Xe as startOfWeek, Ze as startOfYear, Qe as subDays, $e as subHours, et as subMilliseconds, tt as subMinutes, nt as subMonths, rt as subSeconds, it as subWeeks, at as subYears, ot as toDate, st as toISOString, ct as toUnixTime, lt as useClickOutside, xt as useDebounce, ht as useDebouncedCallback, pt as useDebouncedState, yt as useDebouncedValue, ut as useEventListener, Ft as useExpansion, Ct as useFilter, Ot as useFuzzySearch, Et as useGrouping, dt as useKey, At as useModal, Pt as useModalActions, It as useModalState, St as useMultipleSelection, wt as useOrder, Dt as usePagination, Nt as usePin, _t as useRateLimit, ft as useRateLimitedCallback, Tt as useSingleSelection, kt as useSort, mt as useThrottle, vt as useThrottledCallback, gt as useThrottledState, bt as useThrottledValue, Lt as useVisibility };
|