@stryke/hooks 0.4.35 → 0.4.37
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/CHANGELOG.md +18 -0
- package/dist/_virtual/rolldown_runtime.cjs +1 -0
- package/dist/env/src/runtime-checks.cjs +1 -0
- package/dist/env/src/runtime-checks.mjs +2 -0
- package/dist/env/src/runtime-checks.mjs.map +1 -0
- package/dist/helpers/src/debounce.cjs +1 -0
- package/dist/helpers/src/debounce.d.cts +7 -0
- package/dist/helpers/src/debounce.d.cts.map +1 -0
- package/dist/helpers/src/debounce.d.mts +7 -0
- package/dist/helpers/src/debounce.d.mts.map +1 -0
- package/dist/helpers/src/debounce.mjs +2 -0
- package/dist/helpers/src/debounce.mjs.map +1 -0
- package/dist/helpers/src/throttle.cjs +1 -0
- package/dist/helpers/src/throttle.mjs +2 -0
- package/dist/helpers/src/throttle.mjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +17 -17
- package/dist/index.d.mts +17 -17
- package/dist/index.mjs +1 -1
- package/dist/type-checks/src/get-object-tag.cjs +1 -0
- package/dist/type-checks/src/get-object-tag.mjs +2 -0
- package/dist/type-checks/src/get-object-tag.mjs.map +1 -0
- package/dist/type-checks/src/is-equal.cjs +1 -0
- package/dist/type-checks/src/is-equal.mjs +2 -0
- package/dist/type-checks/src/is-equal.mjs.map +1 -0
- package/dist/type-checks/src/is-function.cjs +1 -0
- package/dist/type-checks/src/is-function.mjs +2 -0
- package/dist/type-checks/src/is-function.mjs.map +1 -0
- package/dist/types/src/base.cjs +1 -0
- package/dist/types/src/base.d.cts +35 -0
- package/dist/types/src/base.d.cts.map +1 -0
- package/dist/types/src/base.d.mts +35 -0
- package/dist/types/src/base.d.mts.map +1 -0
- package/dist/types/src/base.mjs +2 -0
- package/dist/types/src/base.mjs.map +1 -0
- package/dist/{navigator-DUOlrD-4.d.mts → types/src/navigator.d.cts} +2 -2
- package/dist/types/src/navigator.d.cts.map +1 -0
- package/dist/{navigator-CY6InfsZ.d.cts → types/src/navigator.d.mts} +2 -2
- package/dist/types/src/navigator.d.mts.map +1 -0
- package/dist/use-battery.cjs +1 -1
- package/dist/use-battery.d.cts +11 -2
- package/dist/use-battery.d.cts.map +1 -0
- package/dist/use-battery.d.mts +11 -2
- package/dist/use-battery.d.mts.map +1 -0
- package/dist/use-battery.mjs +2 -1
- package/dist/use-battery.mjs.map +1 -0
- package/dist/use-callback-ref.cjs +1 -1
- package/dist/use-callback-ref.d.cts +9 -2
- package/dist/use-callback-ref.d.cts.map +1 -0
- package/dist/use-callback-ref.d.mts +9 -2
- package/dist/use-callback-ref.d.mts.map +1 -0
- package/dist/use-callback-ref.mjs +2 -1
- package/dist/use-callback-ref.mjs.map +1 -0
- package/dist/use-callback-stable.cjs +1 -1
- package/dist/use-callback-stable.d.cts +25 -2
- package/dist/use-callback-stable.d.cts.map +1 -0
- package/dist/use-callback-stable.d.mts +25 -2
- package/dist/use-callback-stable.d.mts.map +1 -0
- package/dist/use-callback-stable.mjs +2 -1
- package/dist/use-callback-stable.mjs.map +1 -0
- package/dist/use-click-away.cjs +1 -1
- package/dist/use-click-away.d.cts +14 -2
- package/dist/use-click-away.d.cts.map +1 -0
- package/dist/use-click-away.d.mts +14 -2
- package/dist/use-click-away.d.mts.map +1 -0
- package/dist/use-click-away.mjs +2 -1
- package/dist/use-click-away.mjs.map +1 -0
- package/dist/use-compose-refs.cjs +1 -1
- package/dist/use-compose-refs.d.cts +31 -2
- package/dist/use-compose-refs.d.cts.map +1 -0
- package/dist/use-compose-refs.d.mts +31 -2
- package/dist/use-compose-refs.d.mts.map +1 -0
- package/dist/use-compose-refs.mjs +2 -1
- package/dist/use-compose-refs.mjs.map +1 -0
- package/dist/use-copy-to-clipboard.cjs +1 -1
- package/dist/use-copy-to-clipboard.d.cts +10 -2
- package/dist/use-copy-to-clipboard.d.cts.map +1 -0
- package/dist/use-copy-to-clipboard.d.mts +10 -2
- package/dist/use-copy-to-clipboard.d.mts.map +1 -0
- package/dist/use-copy-to-clipboard.mjs +2 -1
- package/dist/use-copy-to-clipboard.mjs.map +1 -0
- package/dist/use-debounce.cjs +1 -1
- package/dist/use-debounce.d.cts +14 -2
- package/dist/use-debounce.d.cts.map +1 -0
- package/dist/use-debounce.d.mts +14 -2
- package/dist/use-debounce.d.mts.map +1 -0
- package/dist/use-debounce.mjs +2 -1
- package/dist/use-debounce.mjs.map +1 -0
- package/dist/use-did-finish-ssr.cjs +1 -1
- package/dist/use-did-finish-ssr.d.cts +10 -2
- package/dist/use-did-finish-ssr.d.cts.map +1 -0
- package/dist/use-did-finish-ssr.d.mts +10 -2
- package/dist/use-did-finish-ssr.d.mts.map +1 -0
- package/dist/use-did-finish-ssr.mjs +2 -1
- package/dist/use-did-finish-ssr.mjs.map +1 -0
- package/dist/use-escape-keydown.cjs +1 -1
- package/dist/use-escape-keydown.d.cts +8 -2
- package/dist/use-escape-keydown.d.cts.map +1 -0
- package/dist/use-escape-keydown.d.mts +8 -2
- package/dist/use-escape-keydown.d.mts.map +1 -0
- package/dist/use-escape-keydown.mjs +2 -1
- package/dist/use-escape-keydown.mjs.map +1 -0
- package/dist/use-event.cjs +1 -1
- package/dist/use-event.d.cts +12 -2
- package/dist/use-event.d.cts.map +1 -0
- package/dist/use-event.d.mts +12 -2
- package/dist/use-event.d.mts.map +1 -0
- package/dist/use-event.mjs +2 -1
- package/dist/use-event.mjs.map +1 -0
- package/dist/use-hover.cjs +1 -1
- package/dist/use-hover.d.cts +10 -2
- package/dist/use-hover.d.cts.map +1 -0
- package/dist/use-hover.d.mts +10 -2
- package/dist/use-hover.d.mts.map +1 -0
- package/dist/use-hover.mjs +2 -1
- package/dist/use-hover.mjs.map +1 -0
- package/dist/use-idle.cjs +1 -1
- package/dist/use-idle.d.cts +11 -2
- package/dist/use-idle.d.cts.map +1 -0
- package/dist/use-idle.d.mts +11 -2
- package/dist/use-idle.d.mts.map +1 -0
- package/dist/use-idle.mjs +2 -1
- package/dist/use-idle.mjs.map +1 -0
- package/dist/use-isomorphic-layout-effect.cjs +1 -1
- package/dist/use-isomorphic-layout-effect.d.cts +13 -2
- package/dist/use-isomorphic-layout-effect.d.cts.map +1 -0
- package/dist/use-isomorphic-layout-effect.d.mts +13 -2
- package/dist/use-isomorphic-layout-effect.d.mts.map +1 -0
- package/dist/use-isomorphic-layout-effect.mjs +2 -1
- package/dist/use-isomorphic-layout-effect.mjs.map +1 -0
- package/dist/use-keyboard-visible.cjs +1 -1
- package/dist/use-keyboard-visible.d.cts +5 -2
- package/dist/use-keyboard-visible.d.cts.map +1 -0
- package/dist/use-keyboard-visible.d.mts +5 -2
- package/dist/use-keyboard-visible.d.mts.map +1 -0
- package/dist/use-keyboard-visible.mjs +2 -1
- package/dist/use-keyboard-visible.mjs.map +1 -0
- package/dist/use-memo-stable.cjs +1 -1
- package/dist/use-memo-stable.d.cts +19 -2
- package/dist/use-memo-stable.d.cts.map +1 -0
- package/dist/use-memo-stable.d.mts +19 -2
- package/dist/use-memo-stable.d.mts.map +1 -0
- package/dist/use-memo-stable.mjs +2 -1
- package/dist/use-memo-stable.mjs.map +1 -0
- package/dist/use-network-state.cjs +1 -1
- package/dist/use-network-state.d.cts +20 -2
- package/dist/use-network-state.d.cts.map +1 -0
- package/dist/use-network-state.d.mts +20 -2
- package/dist/use-network-state.d.mts.map +1 -0
- package/dist/use-network-state.mjs +2 -1
- package/dist/use-network-state.mjs.map +1 -0
- package/dist/use-previous.cjs +1 -1
- package/dist/use-previous.d.cts +5 -2
- package/dist/use-previous.d.cts.map +1 -0
- package/dist/use-previous.d.mts +5 -2
- package/dist/use-previous.d.mts.map +1 -0
- package/dist/use-previous.mjs +2 -1
- package/dist/use-previous.mjs.map +1 -0
- package/package.json +7 -7
- package/dist/is-function-BhD7GXOO.cjs +0 -1
- package/dist/is-function-md4Ym3I0.mjs +0 -2
- package/dist/is-function-md4Ym3I0.mjs.map +0 -1
- package/dist/navigator-CY6InfsZ.d.cts.map +0 -1
- package/dist/navigator-DUOlrD-4.d.mts.map +0 -1
- package/dist/use-battery-BkRIfbJz.d.mts +0 -11
- package/dist/use-battery-BkRIfbJz.d.mts.map +0 -1
- package/dist/use-battery-DZZDx003.cjs +0 -1
- package/dist/use-battery-DaA7I4_x.mjs +0 -2
- package/dist/use-battery-DaA7I4_x.mjs.map +0 -1
- package/dist/use-battery-DpuF7GMz.d.cts +0 -11
- package/dist/use-battery-DpuF7GMz.d.cts.map +0 -1
- package/dist/use-callback-ref-B-95d49K.d.mts +0 -9
- package/dist/use-callback-ref-B-95d49K.d.mts.map +0 -1
- package/dist/use-callback-ref-CloM-Kqk.cjs +0 -1
- package/dist/use-callback-ref-ctiFnQn4.d.cts +0 -9
- package/dist/use-callback-ref-ctiFnQn4.d.cts.map +0 -1
- package/dist/use-callback-ref-otlhGzUu.mjs +0 -2
- package/dist/use-callback-ref-otlhGzUu.mjs.map +0 -1
- package/dist/use-callback-stable-C3QZzhdC.mjs +0 -2
- package/dist/use-callback-stable-C3QZzhdC.mjs.map +0 -1
- package/dist/use-callback-stable-C5X8ySnU.d.mts +0 -55
- package/dist/use-callback-stable-C5X8ySnU.d.mts.map +0 -1
- package/dist/use-callback-stable-CvXmYtWT.cjs +0 -1
- package/dist/use-callback-stable-D_wCU4yv.d.cts +0 -55
- package/dist/use-callback-stable-D_wCU4yv.d.cts.map +0 -1
- package/dist/use-click-away-Bpl7sh5j.cjs +0 -1
- package/dist/use-click-away-D-DKaD9B.mjs +0 -2
- package/dist/use-click-away-D-DKaD9B.mjs.map +0 -1
- package/dist/use-click-away-DG8ULjSN.d.cts +0 -14
- package/dist/use-click-away-DG8ULjSN.d.cts.map +0 -1
- package/dist/use-click-away-kc61inYs.d.mts +0 -14
- package/dist/use-click-away-kc61inYs.d.mts.map +0 -1
- package/dist/use-compose-refs-BUwJN8zY.cjs +0 -1
- package/dist/use-compose-refs-BysZtFy1.mjs +0 -2
- package/dist/use-compose-refs-BysZtFy1.mjs.map +0 -1
- package/dist/use-compose-refs-D1nHM35F.d.cts +0 -31
- package/dist/use-compose-refs-D1nHM35F.d.cts.map +0 -1
- package/dist/use-compose-refs-Dy3epP6l.d.mts +0 -31
- package/dist/use-compose-refs-Dy3epP6l.d.mts.map +0 -1
- package/dist/use-copy-to-clipboard-Cls03hBs.mjs +0 -2
- package/dist/use-copy-to-clipboard-Cls03hBs.mjs.map +0 -1
- package/dist/use-copy-to-clipboard-D3QmuRQ2.d.mts +0 -10
- package/dist/use-copy-to-clipboard-D3QmuRQ2.d.mts.map +0 -1
- package/dist/use-copy-to-clipboard-DFTtZkv7.cjs +0 -1
- package/dist/use-copy-to-clipboard-DzccpceW.d.cts +0 -10
- package/dist/use-copy-to-clipboard-DzccpceW.d.cts.map +0 -1
- package/dist/use-debounce-B07BBb1-.d.mts +0 -17
- package/dist/use-debounce-B07BBb1-.d.mts.map +0 -1
- package/dist/use-debounce-Bh6vyN-1.d.cts +0 -17
- package/dist/use-debounce-Bh6vyN-1.d.cts.map +0 -1
- package/dist/use-debounce-Cto2Ny5z.mjs +0 -2
- package/dist/use-debounce-Cto2Ny5z.mjs.map +0 -1
- package/dist/use-debounce-DWeScEkQ.cjs +0 -1
- package/dist/use-did-finish-ssr-B6M_wlP4.mjs +0 -2
- package/dist/use-did-finish-ssr-B6M_wlP4.mjs.map +0 -1
- package/dist/use-did-finish-ssr-BbXffDj5.cjs +0 -1
- package/dist/use-did-finish-ssr-CBz5xeHc.d.mts +0 -10
- package/dist/use-did-finish-ssr-CBz5xeHc.d.mts.map +0 -1
- package/dist/use-did-finish-ssr-D3CpAwOz.d.cts +0 -10
- package/dist/use-did-finish-ssr-D3CpAwOz.d.cts.map +0 -1
- package/dist/use-escape-keydown-BsJYLp1N.d.cts +0 -8
- package/dist/use-escape-keydown-BsJYLp1N.d.cts.map +0 -1
- package/dist/use-escape-keydown-CFy25Wk6.mjs +0 -2
- package/dist/use-escape-keydown-CFy25Wk6.mjs.map +0 -1
- package/dist/use-escape-keydown-DgPvPpzz.d.mts +0 -8
- package/dist/use-escape-keydown-DgPvPpzz.d.mts.map +0 -1
- package/dist/use-escape-keydown-ITaT9SqI.cjs +0 -1
- package/dist/use-event-CBTGhPhg.mjs +0 -2
- package/dist/use-event-CBTGhPhg.mjs.map +0 -1
- package/dist/use-event-DG39UVbo.cjs +0 -1
- package/dist/use-event-DHFCg8sl.d.cts +0 -12
- package/dist/use-event-DHFCg8sl.d.cts.map +0 -1
- package/dist/use-event-DQyUWk4T.d.mts +0 -12
- package/dist/use-event-DQyUWk4T.d.mts.map +0 -1
- package/dist/use-hover-CPJ3UcMM.d.mts +0 -10
- package/dist/use-hover-CPJ3UcMM.d.mts.map +0 -1
- package/dist/use-hover-DCP1g7QG.mjs +0 -2
- package/dist/use-hover-DCP1g7QG.mjs.map +0 -1
- package/dist/use-hover-DeFTY9RX.d.cts +0 -10
- package/dist/use-hover-DeFTY9RX.d.cts.map +0 -1
- package/dist/use-hover-SNRrnUoI.cjs +0 -1
- package/dist/use-idle-Car_0ThE.d.cts +0 -11
- package/dist/use-idle-Car_0ThE.d.cts.map +0 -1
- package/dist/use-idle-CrCoMyLz.cjs +0 -1
- package/dist/use-idle-DrgoS1jh.mjs +0 -2
- package/dist/use-idle-DrgoS1jh.mjs.map +0 -1
- package/dist/use-idle-DwhHMDDp.d.mts +0 -11
- package/dist/use-idle-DwhHMDDp.d.mts.map +0 -1
- package/dist/use-isomorphic-layout-effect-Br2hUBEM.cjs +0 -1
- package/dist/use-isomorphic-layout-effect-CwRlvm9E.d.cts +0 -13
- package/dist/use-isomorphic-layout-effect-CwRlvm9E.d.cts.map +0 -1
- package/dist/use-isomorphic-layout-effect-D7uazny2.mjs +0 -2
- package/dist/use-isomorphic-layout-effect-D7uazny2.mjs.map +0 -1
- package/dist/use-isomorphic-layout-effect-IWX2e-IS.d.mts +0 -13
- package/dist/use-isomorphic-layout-effect-IWX2e-IS.d.mts.map +0 -1
- package/dist/use-keyboard-visible-83MQ2ogF.mjs +0 -2
- package/dist/use-keyboard-visible-83MQ2ogF.mjs.map +0 -1
- package/dist/use-keyboard-visible-BHYBoMGb.cjs +0 -1
- package/dist/use-keyboard-visible-BPIMSGQ1.d.cts +0 -5
- package/dist/use-keyboard-visible-BPIMSGQ1.d.cts.map +0 -1
- package/dist/use-keyboard-visible-iH9veUTt.d.mts +0 -5
- package/dist/use-keyboard-visible-iH9veUTt.d.mts.map +0 -1
- package/dist/use-memo-stable-Aqx3eZTS.d.mts +0 -19
- package/dist/use-memo-stable-Aqx3eZTS.d.mts.map +0 -1
- package/dist/use-memo-stable-DKI3Fj07.mjs +0 -2
- package/dist/use-memo-stable-DKI3Fj07.mjs.map +0 -1
- package/dist/use-memo-stable-DKW_L41q.cjs +0 -1
- package/dist/use-memo-stable-i9UN2iWi.d.cts +0 -19
- package/dist/use-memo-stable-i9UN2iWi.d.cts.map +0 -1
- package/dist/use-network-state-Bce55hBv.cjs +0 -1
- package/dist/use-network-state-CtGu_gfo.mjs +0 -2
- package/dist/use-network-state-CtGu_gfo.mjs.map +0 -1
- package/dist/use-network-state-DPhNT5_N.d.mts +0 -20
- package/dist/use-network-state-DPhNT5_N.d.mts.map +0 -1
- package/dist/use-network-state-DQegmILl.d.cts +0 -20
- package/dist/use-network-state-DQegmILl.d.cts.map +0 -1
- package/dist/use-previous-BNZSuZUn.cjs +0 -1
- package/dist/use-previous-BvOs-yn-.d.cts +0 -5
- package/dist/use-previous-BvOs-yn-.d.cts.map +0 -1
- package/dist/use-previous-ChmuSO8b.d.mts +0 -5
- package/dist/use-previous-ChmuSO8b.d.mts.map +0 -1
- package/dist/use-previous-vtWmTmEN.mjs +0 -2
- package/dist/use-previous-vtWmTmEN.mjs.map +0 -1
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { AnyFunction } from "./types/src/base.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/use-callback-stable.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Forked from use-memo-one by Alex Reardon
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* `useMemo` and `useCallback` cache the most recent result. However, this cache can be destroyed by React when it wants to.
|
|
10
|
+
*
|
|
11
|
+
* `useMemoStable` and `useCallbackStable` are concurrent mode safe alternatives to `useMemo` and `useCallback` that do provide semantic guarantee. What this means is that you will always get the same reference for a memoized value so long as there is no input change.
|
|
12
|
+
*
|
|
13
|
+
* Using `useMemoStable` and `useCallbackStable` will consume more memory than useMemo and `useCallback` in order to provide a stable cache. React can release the cache of `useMemo` and `useCallback`, but `useMemoStable` will not release the cache until it is garbage collected.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* You may rely on useMemo as a performance optimization, not as a semantic guarantee. In the future, React may choose to “forget” some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without `useMemo` — and then add it to optimize performance.
|
|
17
|
+
*
|
|
18
|
+
* @param callback - The callback function to memoize
|
|
19
|
+
* @param inputs - The inputs to watch for changes
|
|
20
|
+
* @returns The memoized callback function
|
|
21
|
+
*/
|
|
22
|
+
declare function useCallbackStable<TCallback extends AnyFunction = AnyFunction>(callback: TCallback, inputs?: any[]): TCallback;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { useCallbackStable };
|
|
25
|
+
//# sourceMappingURL=use-callback-stable.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-callback-stable.d.mts","names":[],"sources":["../src/use-callback-stable.ts"],"sourcesContent":[],"mappings":";;;;;;AAuCA;;;;;;;;;;;;;;;iBAAgB,oCAAoC,cAAc,uBACtD,4BAET"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{useMemoStable as e}from"./use-memo-stable.mjs";function t(t,n){return e(()=>t,n)}export{t as useCallbackStable};
|
|
2
|
+
//# sourceMappingURL=use-callback-stable.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-callback-stable.mjs","names":[],"sources":["../src/use-callback-stable.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { AnyFunction } from \"@stryke/types/base\";\nimport { useMemoStable } from \"./use-memo-stable\";\n\n/**\n * Forked from use-memo-one by Alex Reardon\n */\n\n/**\n * `useMemo` and `useCallback` cache the most recent result. However, this cache can be destroyed by React when it wants to.\n *\n * `useMemoStable` and `useCallbackStable` are concurrent mode safe alternatives to `useMemo` and `useCallback` that do provide semantic guarantee. What this means is that you will always get the same reference for a memoized value so long as there is no input change.\n *\n * Using `useMemoStable` and `useCallbackStable` will consume more memory than useMemo and `useCallback` in order to provide a stable cache. React can release the cache of `useMemo` and `useCallback`, but `useMemoStable` will not release the cache until it is garbage collected.\n *\n * @remarks\n * You may rely on useMemo as a performance optimization, not as a semantic guarantee. In the future, React may choose to “forget” some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without `useMemo` — and then add it to optimize performance.\n *\n * @param callback - The callback function to memoize\n * @param inputs - The inputs to watch for changes\n * @returns The memoized callback function\n */\nexport function useCallbackStable<TCallback extends AnyFunction = AnyFunction>(\n callback: TCallback,\n inputs?: any[]\n): TCallback {\n return useMemoStable(() => callback, inputs);\n}\n"],"mappings":"sDAuCA,SAAgB,EACd,EACA,EACW,CACX,OAAO,MAAoB,EAAU,EAAO"}
|
package/dist/use-click-away.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`react`);function n(e){let n=(0,t.useRef)(null),r=(0,t.useRef)(e);return(0,t.useLayoutEffect)(()=>{r.current=e}),(0,t.useEffect)(()=>{let e=e=>{let t=n.current;t&&!t.contains(e.target)&&r.current(e)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[]),n}exports.useClickAway=n;
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as react0 from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/use-click-away.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Listens for when a click is away from the element
|
|
7
|
+
*
|
|
8
|
+
* @param cb - Callback function
|
|
9
|
+
* @returns A Ref object
|
|
10
|
+
*/
|
|
11
|
+
declare function useClickAway(cb: any): react0.RefObject<HTMLElement | null>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { useClickAway };
|
|
14
|
+
//# sourceMappingURL=use-click-away.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-click-away.d.cts","names":[],"sources":["../src/use-click-away.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0BA;;;iBAAgB,YAAA,WAAoB,MAAA,CAAA,UAAA"}
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as react0 from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/use-click-away.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Listens for when a click is away from the element
|
|
7
|
+
*
|
|
8
|
+
* @param cb - Callback function
|
|
9
|
+
* @returns A Ref object
|
|
10
|
+
*/
|
|
11
|
+
declare function useClickAway(cb: any): react0.RefObject<HTMLElement | null>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { useClickAway };
|
|
14
|
+
//# sourceMappingURL=use-click-away.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-click-away.d.mts","names":[],"sources":["../src/use-click-away.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0BA;;;iBAAgB,YAAA,WAAoB,MAAA,CAAA,UAAA"}
|
package/dist/use-click-away.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{t as
|
|
1
|
+
import{useEffect as e,useLayoutEffect as t,useRef as n}from"react";function r(r){let i=n(null),a=n(r);return t(()=>{a.current=r}),e(()=>{let e=e=>{let t=i.current;t&&!t.contains(e.target)&&a.current(e)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[]),i}export{r as useClickAway};
|
|
2
|
+
//# sourceMappingURL=use-click-away.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-click-away.mjs","names":[],"sources":["../src/use-click-away.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useEffect, useLayoutEffect, useRef } from \"react\";\n\n/**\n * Listens for when a click is away from the element\n *\n * @param cb - Callback function\n * @returns A Ref object\n */\nexport function useClickAway(cb: any) {\n const ref = useRef<HTMLElement | null>(null);\n const refCb = useRef(cb);\n\n useLayoutEffect(() => {\n refCb.current = cb;\n });\n\n useEffect(() => {\n const handler = (e: { target: any }) => {\n const element = ref.current;\n if (element && !element.contains(e.target)) {\n // eslint-disable-next-line ts/no-unsafe-call\n refCb.current(e);\n }\n };\n\n document.addEventListener(\"mousedown\", handler);\n document.addEventListener(\"touchstart\", handler);\n\n return () => {\n document.removeEventListener(\"mousedown\", handler);\n document.removeEventListener(\"touchstart\", handler);\n };\n }, []);\n\n return ref;\n}\n"],"mappings":"mEA0BA,SAAgB,EAAa,EAAS,CACpC,IAAM,EAAM,EAA2B,KAAK,CACtC,EAAQ,EAAO,EAAG,CAwBxB,OAtBA,MAAsB,CACpB,EAAM,QAAU,GAChB,CAEF,MAAgB,CACd,IAAM,EAAW,GAAuB,CACtC,IAAM,EAAU,EAAI,QAChB,GAAW,CAAC,EAAQ,SAAS,EAAE,OAAO,EAExC,EAAM,QAAQ,EAAE,EAOpB,OAHA,SAAS,iBAAiB,YAAa,EAAQ,CAC/C,SAAS,iBAAiB,aAAc,EAAQ,KAEnC,CACX,SAAS,oBAAoB,YAAa,EAAQ,CAClD,SAAS,oBAAoB,aAAc,EAAQ,GAEpD,EAAE,CAAC,CAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./type-checks/src/is-function.cjs`);let n=require(`react`);function r(e,n){e&&(t.isFunction(e)?e(n):e.current=n)}function i(...e){return t=>{for(let n of e)r(n,t)}}function a(...e){return(0,n.useCallback)(i(...e),e)}exports.composeRefs=i,exports.setRef=r,exports.useComposedRefs=a;
|
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Ref } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/use-compose-refs.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Set a given ref to a given value
|
|
7
|
+
* This utility takes care of different types of refs: callback refs and RefObject(s)
|
|
8
|
+
*
|
|
9
|
+
* @param ref - The ref to set
|
|
10
|
+
* @param value - The value to set the ref to
|
|
11
|
+
*/
|
|
12
|
+
declare function setRef<T>(ref: Ref<T> | undefined, value: T): void;
|
|
13
|
+
/**
|
|
14
|
+
* A utility to compose multiple refs together
|
|
15
|
+
* Accepts callback refs and RefObject(s)
|
|
16
|
+
*
|
|
17
|
+
* @param refs - The refs to compose
|
|
18
|
+
* @returns A function that sets all refs to a given value
|
|
19
|
+
*/
|
|
20
|
+
declare function composeRefs<T>(...refs: Ref<T>[]): (node: T) => void;
|
|
21
|
+
/**
|
|
22
|
+
* A custom hook that composes multiple refs
|
|
23
|
+
* Accepts callback refs and RefObject(s)
|
|
24
|
+
*
|
|
25
|
+
* @param refs - The refs to compose
|
|
26
|
+
* @returns A function that sets all refs to a given value
|
|
27
|
+
*/
|
|
28
|
+
declare function useComposedRefs<T>(...refs: Ref<T>[]): (node: T) => void;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { composeRefs, setRef, useComposedRefs };
|
|
31
|
+
//# sourceMappingURL=use-compose-refs.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-compose-refs.d.cts","names":[],"sources":["../src/use-compose-refs.ts"],"sourcesContent":[],"mappings":";;;;;;AAgCA;;;;;AAiBgB,iBAjBA,MAiBW,CAAA,CAAA,CAAA,CAAA,GAAA,EAjBI,GAiBJ,CAjBQ,CAiBR,CAAA,GAAA,SAAA,EAAA,KAAA,EAjB+B,CAiB/B,CAAA,EAAA,IAAA;;;;;AAe3B;;;AAAoD,iBAfpC,WAeoC,CAAA,CAAA,CAAA,CAAA,GAAA,IAAA,EAfZ,GAeY,CAfR,CAeQ,CAAA,EAAA,CAAA,EAAA,CAAA,IAAA,EAdpC,CAcoC,EAAA,GAAA,IAAA;;;;;;;;iBAApC,4BAA4B,IAAI,cAAI"}
|
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Ref } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/use-compose-refs.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Set a given ref to a given value
|
|
7
|
+
* This utility takes care of different types of refs: callback refs and RefObject(s)
|
|
8
|
+
*
|
|
9
|
+
* @param ref - The ref to set
|
|
10
|
+
* @param value - The value to set the ref to
|
|
11
|
+
*/
|
|
12
|
+
declare function setRef<T>(ref: Ref<T> | undefined, value: T): void;
|
|
13
|
+
/**
|
|
14
|
+
* A utility to compose multiple refs together
|
|
15
|
+
* Accepts callback refs and RefObject(s)
|
|
16
|
+
*
|
|
17
|
+
* @param refs - The refs to compose
|
|
18
|
+
* @returns A function that sets all refs to a given value
|
|
19
|
+
*/
|
|
20
|
+
declare function composeRefs<T>(...refs: Ref<T>[]): (node: T) => void;
|
|
21
|
+
/**
|
|
22
|
+
* A custom hook that composes multiple refs
|
|
23
|
+
* Accepts callback refs and RefObject(s)
|
|
24
|
+
*
|
|
25
|
+
* @param refs - The refs to compose
|
|
26
|
+
* @returns A function that sets all refs to a given value
|
|
27
|
+
*/
|
|
28
|
+
declare function useComposedRefs<T>(...refs: Ref<T>[]): (node: T) => void;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { composeRefs, setRef, useComposedRefs };
|
|
31
|
+
//# sourceMappingURL=use-compose-refs.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-compose-refs.d.mts","names":[],"sources":["../src/use-compose-refs.ts"],"sourcesContent":[],"mappings":";;;;;;AAgCA;;;;;AAiBgB,iBAjBA,MAiBW,CAAA,CAAA,CAAA,CAAA,GAAA,EAjBI,GAiBJ,CAjBQ,CAiBR,CAAA,GAAA,SAAA,EAAA,KAAA,EAjB+B,CAiB/B,CAAA,EAAA,IAAA;;;;;AAe3B;;;AAAoD,iBAfpC,WAeoC,CAAA,CAAA,CAAA,CAAA,GAAA,IAAA,EAfZ,GAeY,CAfR,CAeQ,CAAA,EAAA,CAAA,EAAA,CAAA,IAAA,EAdpC,CAcoC,EAAA,GAAA,IAAA;;;;;;;;iBAApC,4BAA4B,IAAI,cAAI"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{isFunction as e}from"./type-checks/src/is-function.mjs";import{useCallback as t}from"react";function n(t,n){t&&(e(t)?t(n):t.current=n)}function r(...e){return t=>{for(let r of e)n(r,t)}}function i(...e){return t(r(...e),e)}export{r as composeRefs,n as setRef,i as useComposedRefs};
|
|
2
|
+
//# sourceMappingURL=use-compose-refs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-compose-refs.mjs","names":[],"sources":["../src/use-compose-refs.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport type { Ref, RefObject } from \"react\";\nimport { useCallback } from \"react\";\n\n// from radix\n// https://raw.githubusercontent.com/radix-ui/primitives/main/packages/react/compose-refs/src/composeRefs.tsx\n\n/**\n * Set a given ref to a given value\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n *\n * @param ref - The ref to set\n * @param value - The value to set the ref to\n */\nexport function setRef<T>(ref: Ref<T> | undefined, value: T) {\n if (ref) {\n if (isFunction(ref)) {\n ref(value);\n } else {\n (ref as RefObject<T>).current = value;\n }\n }\n}\n\n/**\n * A utility to compose multiple refs together\n * Accepts callback refs and RefObject(s)\n *\n * @param refs - The refs to compose\n * @returns A function that sets all refs to a given value\n */\nexport function composeRefs<T>(...refs: Ref<T>[]) {\n return (node: T) => {\n for (const ref of refs) {\n setRef(ref, node);\n }\n };\n}\n\n/**\n * A custom hook that composes multiple refs\n * Accepts callback refs and RefObject(s)\n *\n * @param refs - The refs to compose\n * @returns A function that sets all refs to a given value\n */\nexport function useComposedRefs<T>(...refs: Ref<T>[]) {\n return useCallback(composeRefs(...refs), refs);\n}\n"],"mappings":"mGAgCA,SAAgB,EAAU,EAAyB,EAAU,CACvD,IACE,EAAW,EAAI,CACjB,EAAI,EAAM,CAET,EAAqB,QAAU,GAYtC,SAAgB,EAAe,GAAG,EAAgB,CAChD,MAAQ,IAAY,CAClB,IAAK,IAAM,KAAO,EAChB,EAAO,EAAK,EAAK,EAYvB,SAAgB,EAAmB,GAAG,EAAgB,CACpD,OAAO,EAAY,EAAY,GAAG,EAAK,CAAE,EAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./types/src/base.cjs`);let n=require(`react`);function r(e){let t=document.createElement(`textarea`);t.value=e,document.body.append(t),t.select(),document.execCommand(`copy`),t.remove()}function i(){let[e,i]=(0,n.useState)(null);return[e,(0,n.useCallback)(async e=>{await(async()=>{try{if(navigator?.clipboard?.writeText)await navigator.clipboard.writeText(e??t.EMPTY_STRING),i(e??t.EMPTY_STRING);else throw Error(`writeText not supported`)}catch{r(e??t.EMPTY_STRING),i(e??t.EMPTY_STRING)}})()},[])]}exports.useCopyToClipboard=i;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-copy-to-clipboard.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Copies a value to the clipboard
|
|
4
|
+
*
|
|
5
|
+
* @returns A tuple with the copied value and a function to copy a value to the clipboard
|
|
6
|
+
*/
|
|
7
|
+
declare function useCopyToClipboard(): (string | ((value: string | null) => Promise<void>) | null)[];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { useCopyToClipboard };
|
|
10
|
+
//# sourceMappingURL=use-copy-to-clipboard.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-copy-to-clipboard.d.cts","names":[],"sources":["../src/use-copy-to-clipboard.ts"],"sourcesContent":[],"mappings":";;AAmCA;;;;iBAAgB,kBAAA,CAAA,wCAGiD"}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-copy-to-clipboard.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Copies a value to the clipboard
|
|
4
|
+
*
|
|
5
|
+
* @returns A tuple with the copied value and a function to copy a value to the clipboard
|
|
6
|
+
*/
|
|
7
|
+
declare function useCopyToClipboard(): (string | ((value: string | null) => Promise<void>) | null)[];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { useCopyToClipboard };
|
|
10
|
+
//# sourceMappingURL=use-copy-to-clipboard.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-copy-to-clipboard.d.mts","names":[],"sources":["../src/use-copy-to-clipboard.ts"],"sourcesContent":[],"mappings":";;AAmCA;;;;iBAAgB,kBAAA,CAAA,wCAGiD"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{EMPTY_STRING as e}from"./types/src/base.mjs";import{useCallback as t,useState as n}from"react";function r(e){let t=document.createElement(`textarea`);t.value=e,document.body.append(t),t.select(),document.execCommand(`copy`),t.remove()}function i(){let[i,a]=n(null);return[i,t(async t=>{await(async()=>{try{if(navigator?.clipboard?.writeText)await navigator.clipboard.writeText(t??e),a(t??e);else throw Error(`writeText not supported`)}catch{r(t??e),a(t??e)}})()},[])]}export{i as useCopyToClipboard};
|
|
2
|
+
//# sourceMappingURL=use-copy-to-clipboard.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-copy-to-clipboard.mjs","names":[],"sources":["../src/use-copy-to-clipboard.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { EMPTY_STRING } from \"@stryke/types/base\";\nimport { useCallback, useState } from \"react\";\n\nfunction oldSchoolCopy(text: string) {\n const tempTextArea = document.createElement(\"textarea\");\n tempTextArea.value = text;\n document.body.append(tempTextArea);\n tempTextArea.select();\n document.execCommand(\"copy\");\n tempTextArea.remove();\n}\n\n/**\n * Copies a value to the clipboard\n *\n * @returns A tuple with the copied value and a function to copy a value to the clipboard\n */\nexport function useCopyToClipboard() {\n const [state, setState] = useState<string | null>(null);\n\n const copyToClipboard = useCallback(async (value: string | null) => {\n const handleCopy = async () => {\n try {\n if (navigator?.clipboard?.writeText) {\n await navigator.clipboard.writeText(value ?? EMPTY_STRING);\n setState(value ?? EMPTY_STRING);\n } else {\n throw new Error(\"writeText not supported\");\n }\n } catch {\n oldSchoolCopy(value ?? EMPTY_STRING);\n setState(value ?? EMPTY_STRING);\n }\n };\n\n await handleCopy();\n }, []);\n\n return [state, copyToClipboard];\n}\n"],"mappings":"sGAqBA,SAAS,EAAc,EAAc,CACnC,IAAM,EAAe,SAAS,cAAc,WAAW,CACvD,EAAa,MAAQ,EACrB,SAAS,KAAK,OAAO,EAAa,CAClC,EAAa,QAAQ,CACrB,SAAS,YAAY,OAAO,CAC5B,EAAa,QAAQ,CAQvB,SAAgB,GAAqB,CACnC,GAAM,CAAC,EAAO,GAAY,EAAwB,KAAK,CAoBvD,MAAO,CAAC,EAlBgB,EAAY,KAAO,IAAyB,CAelE,MAdmB,SAAY,CAC7B,GAAI,CACF,GAAI,WAAW,WAAW,UACxB,MAAM,UAAU,UAAU,UAAU,GAAS,EAAa,CAC1D,EAAS,GAAS,EAAa,MAE/B,MAAU,MAAM,0BAA0B,MAEtC,CACN,EAAc,GAAS,EAAa,CACpC,EAAS,GAAS,EAAa,KAIjB,EACjB,EAAE,CAAC,CAEyB"}
|
package/dist/use-debounce.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./helpers/src/debounce.cjs`);let n=require(`react`);function r(e,r,i={}){let a=(0,n.useRef)(null);return(0,n.useEffect)(()=>()=>{a.current?.cancel()},[]),(0,n.useMemo)(()=>(a.current=t.debounce(e,r,i),a.current),[e,i,r])}function i(e,t=0){let[r,i]=(0,n.useState)(e);return(0,n.useEffect)(()=>{let n=setTimeout(()=>{i(t=>t===e?t:e)},t);return()=>{clearTimeout(n)}},[t,e]),r}exports.useDebounce=r,exports.useDebounceValue=i;
|
package/dist/use-debounce.d.cts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { DebounceOptions } from "./helpers/src/debounce.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/use-debounce.d.ts
|
|
4
|
+
declare function useDebounce<A extends (...args: any) => any | undefined | null, DebouncedFn extends A & {
|
|
5
|
+
cancel: () => void;
|
|
6
|
+
}>(fn: A, wait: number, options?: DebounceOptions): DebouncedFn;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a value once it stops changing after "amt" time.
|
|
9
|
+
* Note: you may need to memo or this will keep re-rendering
|
|
10
|
+
*/
|
|
11
|
+
declare function useDebounceValue<A>(val: A, amt?: number): A;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { useDebounce, useDebounceValue };
|
|
14
|
+
//# sourceMappingURL=use-debounce.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-debounce.d.cts","names":[],"sources":["../src/use-debounce.ts"],"sourcesContent":[],"mappings":";;;iBAuDgB,oFAEM;;AAFtB,CAAA,CAAA,CAAA,EAAgB,EAKV,CALU,EAAA,IAAA,EAAA,MAAW,EAAA,OAAA,CAAA,EAKK,eALL,CAAA,EAK4B,WAL5B;;;;;AAKuC,iBAmBlD,gBAnBkD,CAAA,CAAA,CAAA,CAAA,GAAA,EAmBzB,CAnByB,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAmBZ,CAnBY"}
|
package/dist/use-debounce.d.mts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { DebounceOptions } from "./helpers/src/debounce.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/use-debounce.d.ts
|
|
4
|
+
declare function useDebounce<A extends (...args: any) => any | undefined | null, DebouncedFn extends A & {
|
|
5
|
+
cancel: () => void;
|
|
6
|
+
}>(fn: A, wait: number, options?: DebounceOptions): DebouncedFn;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a value once it stops changing after "amt" time.
|
|
9
|
+
* Note: you may need to memo or this will keep re-rendering
|
|
10
|
+
*/
|
|
11
|
+
declare function useDebounceValue<A>(val: A, amt?: number): A;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { useDebounce, useDebounceValue };
|
|
14
|
+
//# sourceMappingURL=use-debounce.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-debounce.d.mts","names":[],"sources":["../src/use-debounce.ts"],"sourcesContent":[],"mappings":";;;iBAuDgB,oFAEM;;AAFtB,CAAA,CAAA,CAAA,EAAgB,EAKV,CALU,EAAA,IAAA,EAAA,MAAW,EAAA,OAAA,CAAA,EAKK,eALL,CAAA,EAK4B,WAL5B;;;;;AAKuC,iBAmBlD,gBAnBkD,CAAA,CAAA,CAAA,CAAA,GAAA,EAmBzB,CAnByB,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAmBZ,CAnBY"}
|
package/dist/use-debounce.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{debounce as e}from"./helpers/src/debounce.mjs";import{useEffect as t,useMemo as n,useRef as r,useState as i}from"react";function a(i,a,o={}){let s=r(null);return t(()=>()=>{s.current?.cancel()},[]),n(()=>(s.current=e(i,a,o),s.current),[i,o,a])}function o(e,n=0){let[r,a]=i(e);return t(()=>{let t=setTimeout(()=>{a(t=>t===e?t:e)},n);return()=>{clearTimeout(t)}},[n,e]),r}export{a as useDebounce,o as useDebounceValue};
|
|
2
|
+
//# sourceMappingURL=use-debounce.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-debounce.mjs","names":[],"sources":["../src/use-debounce.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { DebounceOptions } from \"@stryke/helpers/debounce\";\nimport { debounce } from \"@stryke/helpers/debounce\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\n\n// export function debounce<A extends Function>(\n// func: A,\n// wait?: number,\n// leading?: boolean\n// ): A & {\n// cancel: () => void;\n// } {\n// let timeout: any;\n// let isCancelled = false;\n\n// function debounced(this: any) {\n// isCancelled = false;\n// const args = arguments;\n// if (leading && !timeout) {\n// func.apply(this, args);\n// }\n// clearTimeout(timeout);\n// timeout = setTimeout(() => {\n// timeout = null;\n// if (!(leading || isCancelled)) {\n// func.apply(this, args);\n// }\n// isCancelled = false;\n// }, wait);\n// }\n\n// debounced.cancel = () => {\n// isCancelled = true;\n// };\n\n// return debounced as any;\n// }\n\nexport function useDebounce<\n A extends (...args: any) => any | undefined | null,\n DebouncedFn extends A & {\n cancel: () => void;\n }\n>(fn: A, wait: number, options: DebounceOptions = {}): DebouncedFn {\n const dbEffect = useRef<DebouncedFn | null>(null);\n\n useEffect(() => {\n return () => {\n dbEffect.current?.cancel();\n };\n }, []);\n\n return useMemo(() => {\n dbEffect.current = debounce(fn, wait, options) as unknown as DebouncedFn;\n return dbEffect.current;\n }, [fn, options, wait]);\n}\n\n/**\n * Returns a value once it stops changing after \"amt\" time.\n * Note: you may need to memo or this will keep re-rendering\n */\nexport function useDebounceValue<A>(val: A, amt = 0): A {\n const [state, setState] = useState(val);\n\n useEffect(() => {\n const tm = setTimeout(() => {\n setState(prev => {\n if (prev === val) return prev;\n return val;\n });\n }, amt);\n\n return () => {\n clearTimeout(tm);\n };\n }, [amt, val]);\n\n return state;\n}\n"],"mappings":"+HAuDA,SAAgB,EAKd,EAAO,EAAc,EAA2B,EAAE,CAAe,CACjE,IAAM,EAAW,EAA2B,KAAK,CAQjD,OANA,UACe,CACX,EAAS,SAAS,QAAQ,EAE3B,EAAE,CAAC,CAEC,OACL,EAAS,QAAU,EAAS,EAAI,EAAM,EAAQ,CACvC,EAAS,SACf,CAAC,EAAI,EAAS,EAAK,CAAC,CAOzB,SAAgB,EAAoB,EAAQ,EAAM,EAAM,CACtD,GAAM,CAAC,EAAO,GAAY,EAAS,EAAI,CAevC,OAbA,MAAgB,CACd,IAAM,EAAK,eAAiB,CAC1B,EAAS,GACH,IAAS,EAAY,EAClB,EACP,EACD,EAAI,CAEP,UAAa,CACX,aAAa,EAAG,GAEjB,CAAC,EAAK,EAAI,CAAC,CAEP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./type-checks/src/is-function.cjs`);let n=require(`react`);const r=()=>{},i=()=>r;function a(e,t){if(process.env.TAMAGUI_TARGET===`native`)return e??!0;if(t?.sync)return(0,n.useSyncExternalStore)(i,()=>e??!0,()=>!1);let[r,a]=(0,n.useState)(e);return(0,n.useEffect)(()=>{a(e??!0)},[e]),r??!1}function o(e){return a(e,{sync:!0})}function s(e){return a()?t.isFunction(e)?e():e:void 0}exports.useClientValue=s,exports.useDidFinishSSR=a,exports.useDidFinishSSRSync=o;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-did-finish-ssr.d.ts
|
|
2
|
+
declare function useDidFinishSSR<A = boolean>(value?: A, options?: {
|
|
3
|
+
sync?: boolean;
|
|
4
|
+
}): A | false;
|
|
5
|
+
declare function useDidFinishSSRSync<A = boolean>(value?: A): A | false;
|
|
6
|
+
type FunctionOrValue<Value> = Value extends (() => infer X) ? X : Value;
|
|
7
|
+
declare function useClientValue<Value>(value?: Value): FunctionOrValue<Value> | undefined;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { useClientValue, useDidFinishSSR, useDidFinishSSRSync };
|
|
10
|
+
//# sourceMappingURL=use-did-finish-ssr.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-did-finish-ssr.d.cts","names":[],"sources":["../src/use-did-finish-ssr.ts"],"sourcesContent":[],"mappings":";iBAwBgB,qCACN,UAwBV;EAzBgB,IAAA,CAAA,EAAA,OAAA;AAyBhB,CAAA,CAAA,EApBG,CAoBa,GAAA,KAAA;AAMX,iBANW,mBAMc,CAAA,IAAkC,OAAK,CAAA,CAAA,KAAA,CAAA,EANZ,CAMY,CAAA,EANR,CAMQ,GAAA,KAAA;AAErE,KAFK,eAEW,CAAc,KAAA,CAAA,GAFA,KAEA,UAAA,GAAA,GAAA,KAAA,EAAA,IAAA,CAAA,GAFkC,KAElC;AACpB,iBADM,cACN,CAAA,KAAA,CAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EACP,eADO,CACS,KADT,CAAA,GAAA,SAAA"}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-did-finish-ssr.d.ts
|
|
2
|
+
declare function useDidFinishSSR<A = boolean>(value?: A, options?: {
|
|
3
|
+
sync?: boolean;
|
|
4
|
+
}): A | false;
|
|
5
|
+
declare function useDidFinishSSRSync<A = boolean>(value?: A): A | false;
|
|
6
|
+
type FunctionOrValue<Value> = Value extends (() => infer X) ? X : Value;
|
|
7
|
+
declare function useClientValue<Value>(value?: Value): FunctionOrValue<Value> | undefined;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { useClientValue, useDidFinishSSR, useDidFinishSSRSync };
|
|
10
|
+
//# sourceMappingURL=use-did-finish-ssr.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-did-finish-ssr.d.mts","names":[],"sources":["../src/use-did-finish-ssr.ts"],"sourcesContent":[],"mappings":";iBAwBgB,qCACN,UAwBV;EAzBgB,IAAA,CAAA,EAAA,OAAA;AAyBhB,CAAA,CAAA,EApBG,CAoBa,GAAA,KAAA;AAMX,iBANW,mBAMc,CAAA,IAAkC,OAAK,CAAA,CAAA,KAAA,CAAA,EANZ,CAMY,CAAA,EANR,CAMQ,GAAA,KAAA;AAErE,KAFK,eAEW,CAAc,KAAA,CAAA,GAFA,KAEA,UAAA,GAAA,GAAA,KAAA,EAAA,IAAA,CAAA,GAFkC,KAElC;AACpB,iBADM,cACN,CAAA,KAAA,CAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EACP,eADO,CACS,KADT,CAAA,GAAA,SAAA"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{isFunction as e}from"./type-checks/src/is-function.mjs";import{useEffect as t,useState as n,useSyncExternalStore as r}from"react";const i=()=>{},a=()=>i;function o(e,i){if(process.env.TAMAGUI_TARGET===`native`)return e??!0;if(i?.sync)return r(a,()=>e??!0,()=>!1);let[o,s]=n(e);return t(()=>{s(e??!0)},[e]),o??!1}function s(e){return o(e,{sync:!0})}function c(t){return o()?e(t)?t():t:void 0}export{c as useClientValue,o as useDidFinishSSR,s as useDidFinishSSRSync};
|
|
2
|
+
//# sourceMappingURL=use-did-finish-ssr.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-did-finish-ssr.mjs","names":[],"sources":["../src/use-did-finish-ssr.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { useEffect, useState, useSyncExternalStore } from \"react\";\n\nconst emptyFn = () => {};\nconst emptyFnFn = () => emptyFn;\n\nexport function useDidFinishSSR<A = boolean>(\n value?: A,\n options?: {\n sync?: boolean;\n }\n): A | false {\n if (process.env.TAMAGUI_TARGET === \"native\") {\n return (value ?? true) as false | A;\n }\n\n if (options?.sync) {\n return useSyncExternalStore(\n emptyFnFn,\n () => value ?? true,\n () => false as any\n );\n }\n\n const [cur, setCur] = useState<any>(value);\n useEffect(() => {\n setCur(value ?? true);\n }, [value]);\n return cur ?? false;\n}\n\nexport function useDidFinishSSRSync<A = boolean>(value?: A): A | false {\n return useDidFinishSSR(value, {\n sync: true\n });\n}\n\ntype FunctionOrValue<Value> = Value extends () => infer X ? X : Value;\n\nexport function useClientValue<Value>(\n value?: Value\n): FunctionOrValue<Value> | undefined {\n const done = useDidFinishSSR();\n\n return done\n ? isFunction(value)\n ? value()\n : (value as FunctionOrValue<Value>)\n : undefined;\n}\n"],"mappings":"yIAqBA,MAAM,MAAgB,GAChB,MAAkB,EAExB,SAAgB,EACd,EACA,EAGW,CACX,GAAI,QAAQ,IAAI,iBAAmB,SACjC,OAAQ,GAAS,GAGnB,GAAI,GAAS,KACX,OAAO,EACL,MACM,GAAS,OACT,GACP,CAGH,GAAM,CAAC,EAAK,GAAU,EAAc,EAAM,CAI1C,OAHA,MAAgB,CACd,EAAO,GAAS,GAAK,EACpB,CAAC,EAAM,CAAC,CACJ,GAAO,GAGhB,SAAgB,EAAiC,EAAsB,CACrE,OAAO,EAAgB,EAAO,CAC5B,KAAM,GACP,CAAC,CAKJ,SAAgB,EACd,EACoC,CAGpC,OAFa,GAAiB,CAG1B,EAAW,EAAM,CACf,GAAO,CACN,EACH,IAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./use-callback-ref
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./use-callback-ref.cjs`);let n=require(`react`);function r(e,r=globalThis?.document){let i=t.useCallbackRef(e);(0,n.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i(e)};return r.addEventListener(`keydown`,e),()=>{r.removeEventListener(`keydown`,e)}},[i,r])}exports.useEscapeKeydown=r;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-escape-keydown.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Listens for when the escape key is down
|
|
4
|
+
*/
|
|
5
|
+
declare function useEscapeKeydown(onEscapeKeyDownProp?: (event: KeyboardEvent) => void, ownerDocument?: Document): void;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { useEscapeKeydown };
|
|
8
|
+
//# sourceMappingURL=use-escape-keydown.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-escape-keydown.d.cts","names":[],"sources":["../src/use-escape-keydown.ts"],"sourcesContent":[],"mappings":";;AAwBA;;iBAAgB,gBAAA,+BACgB,wCACf"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-escape-keydown.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Listens for when the escape key is down
|
|
4
|
+
*/
|
|
5
|
+
declare function useEscapeKeydown(onEscapeKeyDownProp?: (event: KeyboardEvent) => void, ownerDocument?: Document): void;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { useEscapeKeydown };
|
|
8
|
+
//# sourceMappingURL=use-escape-keydown.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-escape-keydown.d.mts","names":[],"sources":["../src/use-escape-keydown.ts"],"sourcesContent":[],"mappings":";;AAwBA;;iBAAgB,gBAAA,+BACgB,wCACf"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import"./use-callback-ref
|
|
1
|
+
import{useCallbackRef as e}from"./use-callback-ref.mjs";import{useEffect as t}from"react";function n(n,r=globalThis?.document){let i=e(n);t(()=>{let e=e=>{e.key===`Escape`&&i(e)};return r.addEventListener(`keydown`,e),()=>{r.removeEventListener(`keydown`,e)}},[i,r])}export{n as useEscapeKeydown};
|
|
2
|
+
//# sourceMappingURL=use-escape-keydown.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-escape-keydown.mjs","names":[],"sources":["../src/use-escape-keydown.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useEffect } from \"react\";\nimport { useCallbackRef } from \"./use-callback-ref\";\n\n/**\n * Listens for when the escape key is down\n */\nexport function useEscapeKeydown(\n onEscapeKeyDownProp?: (event: KeyboardEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);\n\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n onEscapeKeyDown(event);\n }\n };\n\n ownerDocument.addEventListener(\"keydown\", handleKeyDown);\n\n return () => {\n ownerDocument.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [onEscapeKeyDown, ownerDocument]);\n}\n"],"mappings":"0FAwBA,SAAgB,EACd,EACA,EAA0B,YAAY,SACtC,CACA,IAAM,EAAkB,EAAe,EAAoB,CAE3D,MAAgB,CACd,IAAM,EAAiB,GAAyB,CAC1C,EAAM,MAAQ,UAChB,EAAgB,EAAM,EAM1B,OAFA,EAAc,iBAAiB,UAAW,EAAc,KAE3C,CACX,EAAc,oBAAoB,UAAW,EAAc,GAE5D,CAAC,EAAiB,EAAc,CAAC"}
|
package/dist/use-event.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./use-isomorphic-layout-effect
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./use-isomorphic-layout-effect.cjs`);let n=require(`react`);const r=()=>{throw Error(`Cannot call an event handler while rendering.`)};function i(e){return a(e,r,!0)}function a(e,r,i){let a=(0,n.useRef)(r??e);return t.useIsomorphicLayoutEffect(()=>{a.current=e}),(0,n.useCallback)(i?(...e)=>a.current?.apply(null,e):()=>a.current,[])}exports.useEvent=i;
|
package/dist/use-event.d.cts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-event.d.ts
|
|
2
|
+
type AnyFunction = (...args: any[]) => any;
|
|
3
|
+
/**
|
|
4
|
+
* The function returns a memoized event handler.
|
|
5
|
+
*
|
|
6
|
+
* @param callback - The event handler to memoize.
|
|
7
|
+
* @returns A memoized event handler.
|
|
8
|
+
*/
|
|
9
|
+
declare function useEvent<T extends AnyFunction>(callback?: T): T;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { useEvent };
|
|
12
|
+
//# sourceMappingURL=use-event.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-event.d.cts","names":[],"sources":["../src/use-event.ts"],"sourcesContent":[],"mappings":";KAqBK,WAAA;;AAYL;;;;;iBAAgB,mBAAmB,wBAAwB,IAAI"}
|
package/dist/use-event.d.mts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-event.d.ts
|
|
2
|
+
type AnyFunction = (...args: any[]) => any;
|
|
3
|
+
/**
|
|
4
|
+
* The function returns a memoized event handler.
|
|
5
|
+
*
|
|
6
|
+
* @param callback - The event handler to memoize.
|
|
7
|
+
* @returns A memoized event handler.
|
|
8
|
+
*/
|
|
9
|
+
declare function useEvent<T extends AnyFunction>(callback?: T): T;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { useEvent };
|
|
12
|
+
//# sourceMappingURL=use-event.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-event.d.mts","names":[],"sources":["../src/use-event.ts"],"sourcesContent":[],"mappings":";KAqBK,WAAA;;AAYL;;;;;iBAAgB,mBAAmB,wBAAwB,IAAI"}
|
package/dist/use-event.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import"./use-isomorphic-layout-effect
|
|
1
|
+
import{useIsomorphicLayoutEffect as e}from"./use-isomorphic-layout-effect.mjs";import{useCallback as t,useRef as n}from"react";const r=()=>{throw Error(`Cannot call an event handler while rendering.`)};function i(e){return a(e,r,!0)}function a(r,i,a){let o=n(i??r);return e(()=>{o.current=r}),t(a?(...e)=>o.current?.apply(null,e):()=>o.current,[])}export{i as useEvent};
|
|
2
|
+
//# sourceMappingURL=use-event.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-event.mjs","names":[],"sources":["../src/use-event.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useCallback, useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./use-isomorphic-layout-effect\";\n\ntype AnyFunction = (...args: any[]) => any;\n\nconst defaultValue = () => {\n throw new Error(\"Cannot call an event handler while rendering.\");\n};\n\n/**\n * The function returns a memoized event handler.\n *\n * @param callback - The event handler to memoize.\n * @returns A memoized event handler.\n */\nexport function useEvent<T extends AnyFunction>(callback?: T): T {\n return useGet(callback, defaultValue, true) as T;\n}\n\n// keeps a reference to the current value easily\nfunction useGet<A>(\n currentValue: A,\n initialValue?: any,\n forwardToFunction?: boolean\n): () => A {\n const curRef = useRef<any>(initialValue ?? currentValue);\n useIsomorphicLayoutEffect(() => {\n curRef.current = currentValue;\n });\n\n return useCallback(\n forwardToFunction\n ? // eslint-disable-next-line ts/no-unsafe-call\n (...args) => curRef.current?.apply(null, args)\n : () => curRef.current,\n []\n );\n}\n"],"mappings":"+HAuBA,MAAM,MAAqB,CACzB,MAAU,MAAM,gDAAgD,EASlE,SAAgB,EAAgC,EAAiB,CAC/D,OAAO,EAAO,EAAU,EAAc,GAAK,CAI7C,SAAS,EACP,EACA,EACA,EACS,CACT,IAAM,EAAS,EAAY,GAAgB,EAAa,CAKxD,OAJA,MAAgC,CAC9B,EAAO,QAAU,GACjB,CAEK,EACL,GAEK,GAAG,IAAS,EAAO,SAAS,MAAM,KAAM,EAAK,KACxC,EAAO,QACjB,EAAE,CACH"}
|
package/dist/use-hover.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`react`);const n=()=>{let[e,n]=(0,t.useState)(!1),r=(0,t.useRef)(null),i=(0,t.useCallback)(()=>{n(!0)},[]),a=(0,t.useCallback)(()=>{n(!1)},[]);return[(0,t.useCallback)(e=>{r.current?.nodeType===Node.ELEMENT_NODE&&(r.current.removeEventListener(`mouseenter`,i),r.current.removeEventListener(`mouseleave`,a)),e?.nodeType===Node.ELEMENT_NODE&&(e.addEventListener(`mouseenter`,i),e.addEventListener(`mouseleave`,a)),r.current=e},[i,a]),e]};exports.useHover=n;
|
package/dist/use-hover.d.cts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-hover.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A hook that returns tuple containing a ref and a boolean indicating if the element (referenced by the ref) is being hovered.
|
|
4
|
+
*
|
|
5
|
+
* @returns A tuple containing a ref and a boolean indicating if the element is being hovered
|
|
6
|
+
*/
|
|
7
|
+
declare const useHover: () => [(node: HTMLElement) => void, boolean];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { useHover };
|
|
10
|
+
//# sourceMappingURL=use-hover.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-hover.d.cts","names":[],"sources":["../src/use-hover.ts"],"sourcesContent":[],"mappings":";;AAyBA;;;;cAAa,wBAAuB"}
|
package/dist/use-hover.d.mts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-hover.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A hook that returns tuple containing a ref and a boolean indicating if the element (referenced by the ref) is being hovered.
|
|
4
|
+
*
|
|
5
|
+
* @returns A tuple containing a ref and a boolean indicating if the element is being hovered
|
|
6
|
+
*/
|
|
7
|
+
declare const useHover: () => [(node: HTMLElement) => void, boolean];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { useHover };
|
|
10
|
+
//# sourceMappingURL=use-hover.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-hover.d.mts","names":[],"sources":["../src/use-hover.ts"],"sourcesContent":[],"mappings":";;AAyBA;;;;cAAa,wBAAuB"}
|
package/dist/use-hover.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{t as
|
|
1
|
+
import{useCallback as e,useRef as t,useState as n}from"react";const r=()=>{let[r,i]=n(!1),a=t(null),o=e(()=>{i(!0)},[]),s=e(()=>{i(!1)},[]);return[e(e=>{a.current?.nodeType===Node.ELEMENT_NODE&&(a.current.removeEventListener(`mouseenter`,o),a.current.removeEventListener(`mouseleave`,s)),e?.nodeType===Node.ELEMENT_NODE&&(e.addEventListener(`mouseenter`,o),e.addEventListener(`mouseleave`,s)),a.current=e},[o,s]),r]};export{r as useHover};
|
|
2
|
+
//# sourceMappingURL=use-hover.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-hover.mjs","names":[],"sources":["../src/use-hover.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useCallback, useRef, useState } from \"react\";\n\n/**\n * A hook that returns tuple containing a ref and a boolean indicating if the element (referenced by the ref) is being hovered.\n *\n * @returns A tuple containing a ref and a boolean indicating if the element is being hovered\n */\nexport const useHover = (): [(node: HTMLElement) => void, boolean] => {\n const [hovering, setHovering] = useState(false);\n const previousNode = useRef<HTMLElement | null>(null);\n\n const handleMouseEnter = useCallback(() => {\n setHovering(true);\n }, []);\n const handleMouseLeave = useCallback(() => {\n setHovering(false);\n }, []);\n\n const customRef = useCallback(\n (node: HTMLElement) => {\n if (previousNode.current?.nodeType === Node.ELEMENT_NODE) {\n previousNode.current.removeEventListener(\n \"mouseenter\",\n handleMouseEnter\n );\n previousNode.current.removeEventListener(\n \"mouseleave\",\n handleMouseLeave\n );\n }\n\n if (node?.nodeType === Node.ELEMENT_NODE) {\n node.addEventListener(\"mouseenter\", handleMouseEnter);\n node.addEventListener(\"mouseleave\", handleMouseLeave);\n }\n\n previousNode.current = node;\n },\n [handleMouseEnter, handleMouseLeave]\n );\n\n return [customRef, hovering];\n};\n"],"mappings":"8DAyBA,MAAa,MAAyD,CACpE,GAAM,CAAC,EAAU,GAAe,EAAS,GAAM,CACzC,EAAe,EAA2B,KAAK,CAE/C,EAAmB,MAAkB,CACzC,EAAY,GAAK,EAChB,EAAE,CAAC,CACA,EAAmB,MAAkB,CACzC,EAAY,GAAM,EACjB,EAAE,CAAC,CAyBN,MAAO,CAvBW,EACf,GAAsB,CACjB,EAAa,SAAS,WAAa,KAAK,eAC1C,EAAa,QAAQ,oBACnB,aACA,EACD,CACD,EAAa,QAAQ,oBACnB,aACA,EACD,EAGC,GAAM,WAAa,KAAK,eAC1B,EAAK,iBAAiB,aAAc,EAAiB,CACrD,EAAK,iBAAiB,aAAc,EAAiB,EAGvD,EAAa,QAAU,GAEzB,CAAC,EAAkB,EAAiB,CACrC,CAEkB,EAAS"}
|
package/dist/use-idle.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./helpers/src/throttle.cjs`);let n=require(`react`);const r=(e=1e3*60)=>{let[r,i]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{let n=-1,r=()=>{i(!0)},a=t.throttle(()=>{i(!1),clearTimeout(n),n=setTimeout(r,e)},500),o=()=>{document.hidden||a()};return n=setTimeout(r,e),addEventListener(`mousemove`,a),addEventListener(`mousedown`,a),window.addEventListener(`resize`,a),addEventListener(`keydown`,a),addEventListener(`touchstart`,a),window.addEventListener(`wheel`,a),document.addEventListener(`visibilitychange`,o),()=>{removeEventListener(`mousemove`,a),removeEventListener(`mousedown`,a),window.removeEventListener(`resize`,a),removeEventListener(`keydown`,a),removeEventListener(`touchstart`,a),window.removeEventListener(`wheel`,a),document.removeEventListener(`visibilitychange`,o),clearTimeout(n)}},[e]),r};exports.useIdle=r;
|
package/dist/use-idle.d.cts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-idle.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A hook that returns a boolean indicating if the user is idle.
|
|
4
|
+
*
|
|
5
|
+
* @param ms - The number of milliseconds to wait before considering the user as idle
|
|
6
|
+
* @returns A boolean indicating if the user is idle
|
|
7
|
+
*/
|
|
8
|
+
declare const useIdle: (ms?: number) => boolean;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { useIdle };
|
|
11
|
+
//# sourceMappingURL=use-idle.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-idle.d.cts","names":[],"sources":["../src/use-idle.ts"],"sourcesContent":[],"mappings":";;AA2BA;;;;;cAAa"}
|
package/dist/use-idle.d.mts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/use-idle.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A hook that returns a boolean indicating if the user is idle.
|
|
4
|
+
*
|
|
5
|
+
* @param ms - The number of milliseconds to wait before considering the user as idle
|
|
6
|
+
* @returns A boolean indicating if the user is idle
|
|
7
|
+
*/
|
|
8
|
+
declare const useIdle: (ms?: number) => boolean;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { useIdle };
|
|
11
|
+
//# sourceMappingURL=use-idle.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-idle.d.mts","names":[],"sources":["../src/use-idle.ts"],"sourcesContent":[],"mappings":";;AA2BA;;;;;cAAa"}
|