@alfadocs/ui-kit 0.57.0 → 0.58.0
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/agent-catalog.json +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +99 -77
- package/dist/hooks/use-countdown.d.ts +34 -0
- package/package.json +1 -1
package/dist/agent-catalog.json
CHANGED
package/dist/hooks/index.d.ts
CHANGED
|
@@ -19,4 +19,5 @@ export { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect';
|
|
|
19
19
|
export { useWebOtp, type UseWebOtpOptions } from './use-web-otp';
|
|
20
20
|
export { useEdgeResize, type UseEdgeResizeOptions, type UseEdgeResizeReturn, type EdgeResizeSeparatorProps, } from './use-edge-resize';
|
|
21
21
|
export { useSigningSession, type SigningField, type SigningFieldBase, type UseSigningSessionReturn, } from './use-signing-session';
|
|
22
|
+
export { useCountdown, type UseCountdownOptions, type UseCountdownReturn, } from './use-countdown';
|
|
22
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { u as
|
|
2
|
-
import { u as
|
|
3
|
-
import { u as
|
|
4
|
-
import { u as
|
|
5
|
-
import { u as
|
|
6
|
-
import { A as
|
|
7
|
-
import { u as
|
|
8
|
-
import { u as
|
|
9
|
-
import { u as
|
|
10
|
-
import { useState as
|
|
11
|
-
import { u as
|
|
12
|
-
import { u as
|
|
13
|
-
import { u as
|
|
14
|
-
import { u as
|
|
15
|
-
import { u as
|
|
16
|
-
function
|
|
17
|
-
const [
|
|
18
|
-
return
|
|
19
|
-
if (
|
|
20
|
-
|
|
1
|
+
import { u as L } from "../_chunks/use-prefers-reduced-motion-BMwIQRjB.js";
|
|
2
|
+
import { u as F } from "../_chunks/use-media-query-CcAx5SMM.js";
|
|
3
|
+
import { u as R, a as _ } from "../_chunks/use-signing-session-CyOZWinp.js";
|
|
4
|
+
import { u as w } from "../_chunks/use-count-up-BLLetaZ8.js";
|
|
5
|
+
import { u as K } from "../_chunks/use-locale-BkCIHujH.js";
|
|
6
|
+
import { A as H, T as Y, a as q, r as B, t as G, u as P } from "../_chunks/use-theme-CAuo6EYT.js";
|
|
7
|
+
import { u as V } from "../_chunks/use-controllable-state-BiY4xTzM.js";
|
|
8
|
+
import { u as z } from "../_chunks/use-copy-to-clipboard-Cyfc_dlv.js";
|
|
9
|
+
import { u as W } from "../_chunks/use-debounced-callback-BisrB-Fq.js";
|
|
10
|
+
import { useState as b, useRef as E, useEffect as m, useCallback as x } from "react";
|
|
11
|
+
import { u as N, a as X } from "../_chunks/use-direction-Dp8h70PP.js";
|
|
12
|
+
import { u as $ } from "../_chunks/use-persistent-state-i23OWy6G.js";
|
|
13
|
+
import { u as te } from "../_chunks/use-isomorphic-layout-effect-BGfaCOP1.js";
|
|
14
|
+
import { u as ne } from "../_chunks/use-web-otp-D_utzp6S.js";
|
|
15
|
+
import { u as ue } from "../_chunks/use-edge-resize-ZnGG7gyO.js";
|
|
16
|
+
function C(e, u) {
|
|
17
|
+
const [r, i] = b(e), n = E(null);
|
|
18
|
+
return m(() => {
|
|
19
|
+
if (u <= 0) {
|
|
20
|
+
n.current !== null && (clearTimeout(n.current), n.current = null), i(e);
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
const s = setTimeout(() => {
|
|
24
|
-
i(e),
|
|
25
|
-
},
|
|
26
|
-
return
|
|
27
|
-
}, [e,
|
|
24
|
+
i(e), n.current = null;
|
|
25
|
+
}, u);
|
|
26
|
+
return n.current = s, () => clearTimeout(s);
|
|
27
|
+
}, [e, u]), r;
|
|
28
28
|
}
|
|
29
|
-
const
|
|
29
|
+
const S = [
|
|
30
30
|
"a[href]",
|
|
31
31
|
"button:not([disabled])",
|
|
32
32
|
'input:not([disabled]):not([type="hidden"])',
|
|
@@ -37,74 +37,96 @@ const T = [
|
|
|
37
37
|
"audio[controls]",
|
|
38
38
|
"video[controls]"
|
|
39
39
|
].join(",");
|
|
40
|
-
function
|
|
40
|
+
function T(e) {
|
|
41
41
|
return Array.from(
|
|
42
|
-
e.querySelectorAll(
|
|
43
|
-
).filter((
|
|
44
|
-
if (
|
|
45
|
-
let
|
|
46
|
-
for (;
|
|
47
|
-
if (
|
|
48
|
-
|
|
42
|
+
e.querySelectorAll(S)
|
|
43
|
+
).filter((u) => {
|
|
44
|
+
if (u.hidden) return !1;
|
|
45
|
+
let r = u;
|
|
46
|
+
for (; r; ) {
|
|
47
|
+
if (r.hasAttribute("inert") || r.getAttribute("aria-hidden") === "true") return !1;
|
|
48
|
+
r = r.parentElement;
|
|
49
49
|
}
|
|
50
50
|
return !0;
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
const { enabled:
|
|
55
|
-
|
|
56
|
-
if (!
|
|
57
|
-
const
|
|
58
|
-
if (!
|
|
53
|
+
function v(e, u = {}) {
|
|
54
|
+
const { enabled: r = !0, autoFocus: i = !0, restoreFocus: n = !0 } = u, s = E(null);
|
|
55
|
+
m(() => {
|
|
56
|
+
if (!r) return;
|
|
57
|
+
const o = e.current;
|
|
58
|
+
if (!o) return;
|
|
59
59
|
if (s.current = typeof document < "u" && document.activeElement instanceof HTMLElement ? document.activeElement : null, i) {
|
|
60
|
-
const
|
|
61
|
-
|
|
60
|
+
const a = T(o)[0] ?? (o.tabIndex >= -1 ? o : null);
|
|
61
|
+
a == null || a.focus();
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
if (
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
|
|
63
|
+
function l(t) {
|
|
64
|
+
if (t.key !== "Tab") return;
|
|
65
|
+
const a = e.current;
|
|
66
|
+
if (!a) return;
|
|
67
|
+
const f = T(a);
|
|
68
|
+
if (f.length === 0) {
|
|
69
|
+
t.preventDefault();
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
|
-
const
|
|
73
|
-
|
|
72
|
+
const c = f[0], d = f[f.length - 1], p = document.activeElement;
|
|
73
|
+
t.shiftKey ? (p === c || !a.contains(p)) && (t.preventDefault(), d.focus()) : (p === d || !a.contains(p)) && (t.preventDefault(), c.focus());
|
|
74
74
|
}
|
|
75
|
-
return
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
75
|
+
return o.addEventListener("keydown", l), () => {
|
|
76
|
+
if (o.removeEventListener("keydown", l), n && s.current) {
|
|
77
|
+
const t = s.current;
|
|
78
78
|
requestAnimationFrame(() => {
|
|
79
|
-
|
|
79
|
+
t.isConnected && t.focus();
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
-
}, [
|
|
83
|
+
}, [r, i, n, e]);
|
|
84
|
+
}
|
|
85
|
+
function g(e, u = {}) {
|
|
86
|
+
const { autoStart: r = !0, onElapsed: i } = u, [n, s] = b(e), [o, l] = b(r), t = E(i);
|
|
87
|
+
m(() => {
|
|
88
|
+
t.current = i;
|
|
89
|
+
}, [i]);
|
|
90
|
+
const a = x(() => {
|
|
91
|
+
s(e), l(!0);
|
|
92
|
+
}, [e]), f = x(() => {
|
|
93
|
+
s(e), l(!1);
|
|
94
|
+
}, [e]);
|
|
95
|
+
return m(() => {
|
|
96
|
+
if (!o) return;
|
|
97
|
+
const c = setInterval(() => {
|
|
98
|
+
s((d) => Math.max(0, d - 1));
|
|
99
|
+
}, 1e3);
|
|
100
|
+
return () => clearInterval(c);
|
|
101
|
+
}, [o]), m(() => {
|
|
102
|
+
var c;
|
|
103
|
+
o && n <= 0 && (l(!1), (c = t.current) == null || c.call(t));
|
|
104
|
+
}, [o, n]), { remaining: n, isRunning: o, start: a, reset: f };
|
|
84
105
|
}
|
|
85
106
|
export {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
H as ACCESSIBILITY_STORAGE_KEY,
|
|
108
|
+
Y as THEME_CLASS,
|
|
109
|
+
q as THEME_STORAGE_KEY,
|
|
110
|
+
B as resolveTheme,
|
|
111
|
+
G as themeClassList,
|
|
112
|
+
V as useControllableState,
|
|
113
|
+
z as useCopyToClipboard,
|
|
114
|
+
w as useCountUp,
|
|
115
|
+
g as useCountdown,
|
|
116
|
+
W as useDebouncedCallback,
|
|
117
|
+
C as useDebouncedValue,
|
|
118
|
+
N as useDirection,
|
|
119
|
+
X as useDocumentDirection,
|
|
120
|
+
ue as useEdgeResize,
|
|
121
|
+
v as useFocusTrap,
|
|
122
|
+
te as useIsomorphicLayoutEffect,
|
|
123
|
+
K as useLocale,
|
|
124
|
+
F as useMediaQuery,
|
|
125
|
+
$ as usePersistentState,
|
|
126
|
+
L as usePrefersReducedMotion,
|
|
127
|
+
R as useScrollToFirstError,
|
|
106
128
|
_ as useSigningSession,
|
|
107
|
-
|
|
108
|
-
|
|
129
|
+
P as useTheme,
|
|
130
|
+
ne as useWebOtp
|
|
109
131
|
};
|
|
110
132
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface UseCountdownOptions {
|
|
2
|
+
/** Begin counting down on mount. Default `true`. */
|
|
3
|
+
autoStart?: boolean;
|
|
4
|
+
/** Called exactly once when the countdown reaches zero. */
|
|
5
|
+
onElapsed?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface UseCountdownReturn {
|
|
8
|
+
/** Whole seconds remaining; counts down to 0. */
|
|
9
|
+
remaining: number;
|
|
10
|
+
/** Whether the countdown is actively ticking. */
|
|
11
|
+
isRunning: boolean;
|
|
12
|
+
/** (Re)start from the full duration. */
|
|
13
|
+
start: () => void;
|
|
14
|
+
/** Stop and reset to the full duration without firing `onElapsed`. */
|
|
15
|
+
reset: () => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A pure, render-friendly seconds countdown. It owns no side effects — when
|
|
19
|
+
* it reaches zero it calls `onElapsed` and the CONSUMER decides what to do
|
|
20
|
+
* (close the tab, redirect, …). Same "no I/O" contract as `useSigningSession`.
|
|
21
|
+
*
|
|
22
|
+
* `onElapsed` is read through a ref, so changing the callback doesn't restart
|
|
23
|
+
* the timer. SSR-safe: the timer only ticks inside an effect (client-only).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const { remaining } = useCountdown(10, {
|
|
27
|
+
* onElapsed: () => {
|
|
28
|
+
* window.close(); // best-effort — blocked for user-opened tabs
|
|
29
|
+
* window.location.assign('https://www.alfadocs.com'); // fallback
|
|
30
|
+
* },
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
33
|
+
export declare function useCountdown(seconds: number, options?: UseCountdownOptions): UseCountdownReturn;
|
|
34
|
+
//# sourceMappingURL=use-countdown.d.ts.map
|
package/package.json
CHANGED