@jamsrui/hooks 0.0.7 → 0.0.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffect as t,useMemo as u,useRef as f}from"react";function a(e){const n=f(e);return t(()=>{n.current=e}),u(()=>(...r)=>n.current?.(...r),[])}export{a as useCallbackRef};
|
|
1
|
+
import{useEffect as t,useMemo as u,useRef as f}from"react";function a(e){const n=f(e);return t(()=>{n.current=e}),u(()=>((...r)=>n.current?.(...r)),[])}export{a as useCallbackRef};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffect as E,useRef as
|
|
1
|
+
import{useEffect as E,useRef as m,useState as f}from"react";const L=(c={})=>{const{isDisabled:l=!1}=c,[v,o]=f(!1),r=m(null);return E(()=>{let s=!1;const i=t=>{["Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","Enter"," "].includes(t.key)&&(s=!0)},n=()=>{s=!1},d=()=>{o(s)},u=()=>{o(!1)},a=t=>{(t.key==="Enter"||t.key===" ")&&o(!0)};document.addEventListener("keydown",i),document.addEventListener("mousedown",n),document.addEventListener("touchstart",n);const e=r.current;return e&&(e.addEventListener("focus",d),e.addEventListener("blur",u),e.addEventListener("keydown",a)),()=>{document.removeEventListener("keydown",i),document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n),e&&(e.removeEventListener("focus",d),e.removeEventListener("blur",u),e.removeEventListener("keydown",a))}},[l]),{ref:r,isFocusVisible:v}};export{L as useFocusVisible};
|
package/dist/use-press.d.mts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
declare function usePress(props?: {
|
|
4
|
+
isDisabled?: boolean;
|
|
5
|
+
}): {
|
|
2
6
|
isPressed: boolean;
|
|
3
|
-
|
|
7
|
+
ref: react.RefObject<HTMLElement | null>;
|
|
8
|
+
isPressing: boolean;
|
|
4
9
|
};
|
|
5
10
|
declare namespace usePress {
|
|
6
11
|
interface UsePressProps {
|
package/dist/use-press.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as t,useEffect as p,useRef as m,useState as E}from"react";function k(f={}){const{isDisabled:s=!1}=f,v=m(null),[n,r]=E(!1),[L,o]=E(!1),w=n&&L,i=t(()=>{r(!0),o(!0)},[]),a=t(()=>{n&&o(!1)},[n]),d=t(()=>{n&&o(!0)},[n]),l=t(()=>{n&&r(!1)},[n]),c=t(e=>{(e.target instanceof HTMLInputElement?[" "]:["Enter"," "]).includes(e.key)&&(r(!0),o(!0))},[]),u=t(e=>{(e.key==="Enter"||e.key===" ")&&n&&r(!1)},[n]);return p(()=>{if(s)return;const e=()=>{n&&r(!1)};return window.addEventListener("pointerup",e),window.addEventListener("contextmenu",e),()=>{window.removeEventListener("pointerup",e),window.removeEventListener("contextmenu",e)}},[n,s]),p(()=>{const e=v.current;if(!(!e||s))return e.addEventListener("pointerdown",i),e.addEventListener("pointerenter",d),e.addEventListener("pointerleave",a),e.addEventListener("keydown",c),e.addEventListener("keyup",u),e.addEventListener("pointercancel",l),()=>{e.removeEventListener("pointerdown",i),e.removeEventListener("pointerenter",d),e.removeEventListener("pointerleave",a),e.removeEventListener("keydown",c),e.removeEventListener("keyup",u),e.removeEventListener("pointercancel",l)}},[i,d,a,c,u,l,s]),{isPressed:w,ref:v,isPressing:n}}export{k as usePress};
|
package/package.json
CHANGED