@stryke/hooks 0.4.7 → 0.4.9

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/README.md CHANGED
@@ -22,7 +22,7 @@ This package is part of Storm Software's **đŸŒŠī¸ Stryke** monorepo. Stryke pac
22
22
 
23
23
  <h3 align="center">đŸ’ģ Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
24
24
 
25
- [![Version](https://img.shields.io/badge/version-0.4.6-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
25
+ [![Version](https://img.shields.io/badge/version-0.4.7-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
26
26
 
27
27
  > [!IMPORTANT] Important
28
28
  > This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be available through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.
@@ -45,6 +45,7 @@ A package containing shared hooks that can be used in any React UI project
45
45
 
46
46
  <!-- START doctoc -->
47
47
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
48
+
48
49
  ## Table of Contents
49
50
 
50
51
  - [Installing](#installing)
@@ -7,20 +7,20 @@ exports.useDebounce = useDebounce;
7
7
  exports.useDebounceValue = useDebounceValue;
8
8
  var _debounce = require("@stryke/helpers/debounce");
9
9
  var _react = require("react");
10
- function useDebounce(e, n, u = {}, r = [e, u, n]) {
11
- const t = (0, _react.useRef)(null);
10
+ function useDebounce(e, n, t = {}) {
11
+ const u = (0, _react.useRef)(null);
12
12
  return (0, _react.useEffect)(() => () => {
13
- t.current?.cancel();
14
- }, []), (0, _react.useMemo)(() => (t.current = (0, _debounce.debounce)(e, n, u), t.current), [e, u, n]);
13
+ u.current?.cancel();
14
+ }, []), (0, _react.useMemo)(() => (u.current = (0, _debounce.debounce)(e, n, t), u.current), [e, t, n]);
15
15
  }
16
16
  function useDebounceValue(e, n = 0) {
17
- const [u, r] = (0, _react.useState)(e);
17
+ const [t, u] = (0, _react.useState)(e);
18
18
  return (0, _react.useEffect)(() => {
19
- const t = setTimeout(() => {
20
- r(c => c === e ? c : e);
19
+ const c = setTimeout(() => {
20
+ u(r => r === e ? r : e);
21
21
  }, n);
22
22
  return () => {
23
- clearTimeout(t);
23
+ clearTimeout(c);
24
24
  };
25
- }, [n, e]), u;
25
+ }, [n, e]), t;
26
26
  }
@@ -1,7 +1,7 @@
1
- import { DebounceOptions } from "@stryke/helpers/debounce";
1
+ import type { DebounceOptions } from "@stryke/helpers/debounce";
2
2
  export declare function useDebounce<A extends (...args: any) => any | undefined | null, DebouncedFn extends A & {
3
3
  cancel: () => void;
4
- }>(fn: A, wait: number, options?: DebounceOptions, mountArgs?: any[]): DebouncedFn;
4
+ }>(fn: A, wait: number, options?: DebounceOptions): DebouncedFn;
5
5
  /**
6
6
  * Returns a value once it stops changing after "amt" time.
7
7
  * Note: you may need to memo or this will keep re-rendering
@@ -1 +1 @@
1
- import{debounce as s}from"@stryke/helpers/debounce";import{useEffect as o,useMemo as b,useRef as d,useState as f}from"react";export function useDebounce(e,n,u={},r=[e,u,n]){const t=d(null);return o(()=>()=>{t.current?.cancel()},[]),b(()=>(t.current=s(e,n,u),t.current),[e,u,n])}export function useDebounceValue(e,n=0){const[u,r]=f(e);return o(()=>{const t=setTimeout(()=>{r(c=>c===e?c:e)},n);return()=>{clearTimeout(t)}},[n,e]),u}
1
+ import{debounce as s}from"@stryke/helpers/debounce";import{useEffect as o,useMemo as b,useRef as d,useState as f}from"react";export function useDebounce(e,n,t={}){const u=d(null);return o(()=>()=>{u.current?.cancel()},[]),b(()=>(u.current=s(e,n,t),u.current),[e,t,n])}export function useDebounceValue(e,n=0){const[t,u]=f(e);return o(()=>{const c=setTimeout(()=>{u(r=>r===e?r:e)},n);return()=>{clearTimeout(c)}},[n,e]),t}
@@ -13,9 +13,9 @@ const a = () => {},
13
13
  function useDidFinishSSR(e, n) {
14
14
  if (process.env.TAMAGUI_TARGET === "native") return e ?? !0;
15
15
  if (n?.sync) return (0, _react.useSyncExternalStore)(c, () => e ?? !0, () => !1);
16
- const [t, r] = (0, _react.useState)(e);
16
+ const [t, u] = (0, _react.useState)(e);
17
17
  return (0, _react.useEffect)(() => {
18
- r(e ?? !0);
18
+ u(e ?? !0);
19
19
  }, [e]), t ?? !1;
20
20
  }
21
21
  function useDidFinishSSRSync(e) {
@@ -1 +1 @@
1
- import{isFunction as u}from"@stryke/type-checks/is-function";import{useEffect as o,useState as s,useSyncExternalStore as i}from"react";const a=()=>{},c=()=>a;export function useDidFinishSSR(e,n){if(process.env.TAMAGUI_TARGET==="native")return e??!0;if(n?.sync)return i(c,()=>e??!0,()=>!1);const[t,r]=s(e);return o(()=>{r(e??!0)},[e]),t??!1}export function useDidFinishSSRSync(e){return useDidFinishSSR(e,{sync:!0})}export function useClientValue(e){return useDidFinishSSR()?u(e)?e():e:void 0}
1
+ import{isFunction as r}from"@stryke/type-checks/is-function";import{useEffect as o,useState as s,useSyncExternalStore as i}from"react";const a=()=>{},c=()=>a;export function useDidFinishSSR(e,n){if(process.env.TAMAGUI_TARGET==="native")return e??!0;if(n?.sync)return i(c,()=>e??!0,()=>!1);const[t,u]=s(e);return o(()=>{u(e??!0)},[e]),t??!1}export function useDidFinishSSRSync(e){return useDidFinishSSR(e,{sync:!0})}export function useClientValue(e){return useDidFinishSSR()?r(e)?e():e:void 0}
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useEvent = useEvent;
7
7
  var _react = require("react");
8
8
  var _useIsomorphicLayoutEffect = require("./use-isomorphic-layout-effect.cjs");
9
- function useEvent(n) {
10
- return s(n, l, !0);
11
- }
12
9
  const l = () => {
13
10
  throw new Error("Cannot call an event handler while rendering.");
14
11
  };
12
+ function useEvent(n) {
13
+ return s(n, l, !0);
14
+ }
15
15
  function s(n, r, t) {
16
16
  const e = (0, _react.useRef)(r ?? n);
17
17
  return (0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
@@ -1 +1 @@
1
- import{useCallback as u,useRef as a}from"react";import{useIsomorphicLayoutEffect as c}from"./use-isomorphic-layout-effect";export function useEvent(n){return s(n,l,!0)}const l=()=>{throw new Error("Cannot call an event handler while rendering.")};function s(n,r,t){const e=a(r??n);return c(()=>{e.current=n}),u(t?(...o)=>e.current?.apply(null,o):()=>e.current,[])}
1
+ import{useCallback as u,useRef as a}from"react";import{useIsomorphicLayoutEffect as c}from"./use-isomorphic-layout-effect";const l=()=>{throw new Error("Cannot call an event handler while rendering.")};export function useEvent(n){return s(n,l,!0)}function s(n,r,t){const e=a(r??n);return c(()=>{e.current=n}),u(t?(...o)=>e.current?.apply(null,o):()=>e.current,[])}
package/dist/use-idle.cjs CHANGED
@@ -6,22 +6,22 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useIdle = void 0;
7
7
  var _throttle = require("@stryke/helpers/throttle");
8
8
  var _react = require("react");
9
- const useIdle = (o = 1e3 * 60) => {
10
- const [l, n] = (0, _react.useState)(!1);
9
+ const useIdle = (n = 1e3 * 60) => {
10
+ const [s, o] = (0, _react.useState)(!1);
11
11
  return (0, _react.useEffect)(() => {
12
12
  let t = -1;
13
13
  const i = () => {
14
- n(!0);
14
+ o(!0);
15
15
  },
16
16
  e = (0, _throttle.throttle)(() => {
17
- n(!1), globalThis.clearTimeout(t), t = globalThis.setTimeout(i, o);
17
+ o(!1), clearTimeout(t), t = setTimeout(i, n);
18
18
  }, 500),
19
- s = () => {
19
+ r = () => {
20
20
  document.hidden || e();
21
21
  };
22
- return t = globalThis.setTimeout(i, o), globalThis.addEventListener("mousemove", e), globalThis.addEventListener("mousedown", e), window.addEventListener("resize", e), globalThis.addEventListener("keydown", e), globalThis.addEventListener("touchstart", e), window.addEventListener("wheel", e), document.addEventListener("visibilitychange", s), () => {
23
- globalThis.removeEventListener("mousemove", e), globalThis.removeEventListener("mousedown", e), window.removeEventListener("resize", e), globalThis.removeEventListener("keydown", e), globalThis.removeEventListener("touchstart", e), window.removeEventListener("wheel", e), document.removeEventListener("visibilitychange", s), globalThis.clearTimeout(t);
22
+ return t = setTimeout(i, n), addEventListener("mousemove", e), addEventListener("mousedown", e), window.addEventListener("resize", e), addEventListener("keydown", e), addEventListener("touchstart", e), window.addEventListener("wheel", e), document.addEventListener("visibilitychange", r), () => {
23
+ removeEventListener("mousemove", e), removeEventListener("mousedown", e), window.removeEventListener("resize", e), removeEventListener("keydown", e), removeEventListener("touchstart", e), window.removeEventListener("wheel", e), document.removeEventListener("visibilitychange", r), clearTimeout(t);
24
24
  };
25
- }, [o]), l;
25
+ }, [n]), s;
26
26
  };
27
27
  exports.useIdle = useIdle;
package/dist/use-idle.mjs CHANGED
@@ -1 +1 @@
1
- import{throttle as r}from"@stryke/helpers/throttle";import{useEffect as d,useState as a}from"react";export const useIdle=(o=1e3*60)=>{const[l,n]=a(!1);return d(()=>{let t=-1;const i=()=>{n(!0)},e=r(()=>{n(!1),globalThis.clearTimeout(t),t=globalThis.setTimeout(i,o)},500),s=()=>{document.hidden||e()};return t=globalThis.setTimeout(i,o),globalThis.addEventListener("mousemove",e),globalThis.addEventListener("mousedown",e),window.addEventListener("resize",e),globalThis.addEventListener("keydown",e),globalThis.addEventListener("touchstart",e),window.addEventListener("wheel",e),document.addEventListener("visibilitychange",s),()=>{globalThis.removeEventListener("mousemove",e),globalThis.removeEventListener("mousedown",e),window.removeEventListener("resize",e),globalThis.removeEventListener("keydown",e),globalThis.removeEventListener("touchstart",e),window.removeEventListener("wheel",e),document.removeEventListener("visibilitychange",s),globalThis.clearTimeout(t)}},[o]),l};
1
+ import{throttle as d}from"@stryke/helpers/throttle";import{useEffect as v,useState as m}from"react";export const useIdle=(n=1e3*60)=>{const[s,o]=m(!1);return v(()=>{let t=-1;const i=()=>{o(!0)},e=d(()=>{o(!1),clearTimeout(t),t=setTimeout(i,n)},500),r=()=>{document.hidden||e()};return t=setTimeout(i,n),addEventListener("mousemove",e),addEventListener("mousedown",e),window.addEventListener("resize",e),addEventListener("keydown",e),addEventListener("touchstart",e),window.addEventListener("wheel",e),document.addEventListener("visibilitychange",r),()=>{removeEventListener("mousemove",e),removeEventListener("mousedown",e),window.removeEventListener("resize",e),removeEventListener("keydown",e),removeEventListener("touchstart",e),window.removeEventListener("wheel",e),document.removeEventListener("visibilitychange",r),clearTimeout(t)}},[n]),s};
@@ -17,11 +17,11 @@ function useMemoStable(t, e) {
17
17
  }))[0],
18
18
  r = (0, _react.useRef)(!0),
19
19
  n = (0, _react.useRef)(u),
20
- s = r.current || !!(e && n.current.inputs && i(e, n.current.inputs)),
21
- a = (0, _react.useMemo)(() => s ? n.current : {
20
+ c = r.current || !!(e && n.current.inputs && i(e, n.current.inputs)),
21
+ a = (0, _react.useMemo)(() => c ? n.current : {
22
22
  inputs: e,
23
23
  result: t()
24
- }, [e, t, s]);
24
+ }, [e, t, c]);
25
25
  return (0, _react.useEffect)(() => {
26
26
  r.current = !1, n.current = a;
27
27
  }, [a]), a.result;
@@ -1 +1 @@
1
- import{useEffect as o,useMemo as l,useRef as c,useState as f}from"react";const i=(t,e)=>{if(t.length!==e.length)return!1;for(const[u,r]of t.entries())if(r!==e[u])return!1;return!0};export function useMemoStable(t,e){const u=f(()=>({inputs:e,result:t()}))[0],r=c(!0),n=c(u),s=r.current||!!(e&&n.current.inputs&&i(e,n.current.inputs)),a=l(()=>s?n.current:{inputs:e,result:t()},[e,t,s]);return o(()=>{r.current=!1,n.current=a},[a]),a.result}
1
+ import{useEffect as o,useMemo as l,useRef as s,useState as f}from"react";const i=(t,e)=>{if(t.length!==e.length)return!1;for(const[u,r]of t.entries())if(r!==e[u])return!1;return!0};export function useMemoStable(t,e){const u=f(()=>({inputs:e,result:t()}))[0],r=s(!0),n=s(u),c=r.current||!!(e&&n.current.inputs&&i(e,n.current.inputs)),a=l(()=>c?n.current:{inputs:e,result:t()},[e,t,c]);return o(()=>{r.current=!1,n.current=a},[a]),a.result}
@@ -9,16 +9,16 @@ var _isEqual = require("@stryke/type-checks/is-equal");
9
9
  var _react = require("react");
10
10
  const i = () => navigator["connection"] || navigator["mozConnection"] || navigator["webkitConnection"];
11
11
  const useNetworkStateSubscribe = e => {
12
- globalThis.addEventListener("online", e, {
12
+ addEventListener("online", e, {
13
13
  passive: !0
14
- }), globalThis.addEventListener("offline", e, {
14
+ }), addEventListener("offline", e, {
15
15
  passive: !0
16
16
  });
17
17
  const t = i();
18
18
  return t && t.addEventListener("change", e, {
19
19
  passive: !0
20
20
  }), () => {
21
- globalThis.removeEventListener("online", e), globalThis.removeEventListener("offline", e), t && t.removeEventListener("change", e);
21
+ removeEventListener("online", e), removeEventListener("offline", e), t && t.removeEventListener("change", e);
22
22
  };
23
23
  };
24
24
  exports.useNetworkStateSubscribe = useNetworkStateSubscribe;
@@ -1 +1 @@
1
- import{isEqual as a}from"@stryke/type-checks/is-equal";import{useRef as s,useSyncExternalStore as c}from"react";const i=()=>navigator["connection"]||navigator["mozConnection"]||navigator["webkitConnection"];export const useNetworkStateSubscribe=e=>{globalThis.addEventListener("online",e,{passive:!0}),globalThis.addEventListener("offline",e,{passive:!0});const t=i();return t&&t.addEventListener("change",e,{passive:!0}),()=>{globalThis.removeEventListener("online",e),globalThis.removeEventListener("offline",e),t&&t.removeEventListener("change",e)}};const v=()=>{throw new Error("useNetworkState is a client-only hook")};export function useNetworkState(){const e=s({});return c(useNetworkStateSubscribe,()=>{const r=navigator.onLine,n=i(),o={online:r,downlink:n?.downlink,downlinkMax:n?.downlinkMax,effectiveType:n?.effectiveType,rtt:n?.rtt,saveData:n?.saveData,type:n?.type};return a(e.current,o)?e.current:(e.current=o,o)},v)}
1
+ import{isEqual as a}from"@stryke/type-checks/is-equal";import{useRef as s,useSyncExternalStore as c}from"react";const i=()=>navigator["connection"]||navigator["mozConnection"]||navigator["webkitConnection"];export const useNetworkStateSubscribe=e=>{addEventListener("online",e,{passive:!0}),addEventListener("offline",e,{passive:!0});const t=i();return t&&t.addEventListener("change",e,{passive:!0}),()=>{removeEventListener("online",e),removeEventListener("offline",e),t&&t.removeEventListener("change",e)}};const v=()=>{throw new Error("useNetworkState is a client-only hook")};export function useNetworkState(){const e=s({});return c(useNetworkStateSubscribe,()=>{const r=navigator.onLine,n=i(),o={online:r,downlink:n?.downlink,downlinkMax:n?.downlinkMax,effectiveType:n?.effectiveType,rtt:n?.rtt,saveData:n?.saveData,type:n?.type};return a(e.current,o)?e.current:(e.current=o,o)},v)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/hooks",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "type": "module",
5
5
  "description": "A package containing shared hooks that can be used in any React UI project",
6
6
  "repository": {
@@ -23,10 +23,10 @@
23
23
  "react": "^19.1.0",
24
24
  "react-dom": "^19.1.0",
25
25
  "react-native": "^0.77.0",
26
- "@stryke/env": "^0.13.0",
27
- "@stryke/helpers": "^0.6.0",
28
- "@stryke/type-checks": "^0.3.3",
29
- "@stryke/types": "^0.8.3"
26
+ "@stryke/env": "^0.15.10",
27
+ "@stryke/helpers": "^0.7.1",
28
+ "@stryke/type-checks": "^0.3.6",
29
+ "@stryke/types": "^0.8.6"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/react": "^19.0.12",
@@ -335,5 +335,6 @@
335
335
  },
336
336
  "main": "./dist/index.cjs",
337
337
  "module": "./dist/index.mjs",
338
- "types": "./dist/index.d.ts"
338
+ "types": "./dist/index.d.ts",
339
+ "gitHead": "57da58e3434302b35f798674d9f18f92ca7f7ac9"
339
340
  }