@jamsrui/hooks 0.0.9 → 0.0.10

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.
@@ -0,0 +1 @@
1
+ import{useEffect as a,useRef as i,useState as l}from"react";var f=u=>{let{isDisabled:s}=u,t=i(null),[c,n]=l(!1);return a(()=>{let e=t.current;if(s||!e)return;let r=()=>{n(!0)},o=()=>{n(!1)};return e.addEventListener("focus",r),e.addEventListener("blur",o),()=>{e.removeEventListener("focus",r),e.removeEventListener("blur",o)}},[s]),s?{ref:t,isFocused:!1}:{ref:t,isFocused:c}};export{f as a};
@@ -0,0 +1 @@
1
+ import{useCallback as t,useEffect as p,useRef as m,useState as E}from"react";function k(f={}){let{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;let e=()=>{n&&r(!1)};return window.addEventListener("pointerup",e),window.addEventListener("contextmenu",e),()=>{window.removeEventListener("pointerup",e),window.removeEventListener("contextmenu",e)}},[n,s]),p(()=>{let 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 a};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-MMYWZJVT.mjs";import{cloneElement as g}from"react";import{mergeProps as m}from"@jamsrui/utils";import{jsx as n}from"react/jsx-runtime";function R(r){return function(e){return r==="button"?n("button",{type:"button",...e}):r==="img"?n("img",{alt:"",...e}):n(r,{...e})}}var N=(r,o)=>{let{props:e}=o,s=Array.isArray(e)?e:[e],p=m(...s),{render:c,...i}=p,t=c??R(r)({}),f=a([t.props.ref,...s.map(l=>l.ref)]),u=m(t.props,i);return g(t,{...u,ref:f})};export{N as a};
@@ -0,0 +1 @@
1
+ import{useEffect as c,useRef as f,useState as T}from"react";var E=a=>{let{enterDelay:s=0,exitDelay:r=0,isDisabled:u}=a??{},[v,n]=T(!1),i=f(null);return c(()=>{let e=i.current;if(!e||u)return n(!1),()=>{};let t=null,o=null,l=()=>{o&&clearTimeout(o),t=setTimeout(()=>{n(!0)},s)},m=()=>{t&&clearTimeout(t),o=setTimeout(()=>{n(!1)},r)};return e.addEventListener("mouseenter",l),e.addEventListener("mouseleave",m),()=>{t&&clearTimeout(t),o&&clearTimeout(o),e.removeEventListener("mouseenter",l),e.removeEventListener("mouseleave",m)}},[s,r,u]),{ref:i,isHovered:v}};export{E as a};
@@ -0,0 +1 @@
1
+ import{useCallback as o,useMemo as f,useRef as i}from"react";function R(t){let u=i(void 0),a=o(e=>{let r=t.map(n=>{if(n!=null){if(typeof n=="function"){let c=n,l=c(e);return typeof l=="function"?l:()=>{c(null)}}return n.current=e,()=>{n.current=null}}});return()=>{r.forEach(n=>n?.())}},t);return f(()=>t.every(e=>e==null)?null:e=>{u.current&&(u.current(),u.current=void 0),e!=null&&(u.current=a(e))},t)}export{R as a};
@@ -0,0 +1,3 @@
1
+ import{useCallback as f,useEffect as i,useRef as l,useState as h}from"react";function p({controlled:t,default:o,name:n,state:r="value"}){let{current:e}=l(t!==void 0),[c,u]=h(o),d=e?t:c;if(process.env.NODE_ENV!=="production"){i(()=>{e!==(t!==void 0)&&console.error([`Base UI: A component is changing the ${e?"":"un"}controlled ${r} state of ${n} to be ${e?"un":""}controlled.`,"Elements should not switch from uncontrolled to controlled (or vice versa).",`Decide between using a controlled or uncontrolled ${n} element for the lifetime of the component.`,"The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.","More info: https://fb.me/react-controlled-components"].join(`
2
+ `))},[r,n,t]);let{current:s}=l(o);i(()=>{!e&&!Object.is(s,o)&&console.error([`Base UI: A component is changing the default ${r} state of an uncontrolled ${n} after being initialized. To suppress this warning opt to use a controlled ${n}.`].join(`
3
+ `))},[JSON.stringify(o)])}let a=f(s=>{e||u(s)},[]);return[d,a]}export{p as a};
@@ -0,0 +1 @@
1
+ import{useEffect as t,useMemo as u,useRef as f}from"react";function a(e){let n=f(e);return t(()=>{n.current=e}),u(()=>((...r)=>n.current?.(...r)),[])}export{a};
@@ -0,0 +1 @@
1
+ import{useEffect as s,useState as i}from"react";var a=768;function r(){let[o,n]=i(void 0);return s(()=>{let e=window.matchMedia(`(max-width: ${a-1}px)`),t=()=>n(e.matches);return e.addEventListener("change",t),n(e.matches),()=>e.removeEventListener("change",t)},[]),!!o}export{r as a};
@@ -0,0 +1 @@
1
+ import{useEffect as u,useRef as c,useState as f}from"react";var p=l=>{let{isDisabled:e,isFormControl:s}=l??{},t=c(null),[a,b]=f(!1);return u(()=>{let i=t.current;if(!i||e||!s)return()=>{};let r=i.closest("fieldset");if(!r)return()=>{};let o=()=>{let d=r.disabled;b(d)};o();let n=new MutationObserver(o);return n.observe(r,{attributes:!0,attributeFilter:["disabled"]}),()=>n.disconnect()},[s,e]),e||!s?{ref:t,isDisabled:e}:{ref:t,isDisabled:a}};export{p as a};
@@ -0,0 +1 @@
1
+ import{useEffect as E,useRef as m,useState as f}from"react";var L=(c={})=>{let{isDisabled:l=!1}=c,[v,o]=f(!1),r=m(null);return E(()=>{let s=!1,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);let 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 a};
@@ -0,0 +1 @@
1
+ import{a as r}from"./chunk-QWVP4CUR.mjs";import{useCallback as i,useEffect as d,useRef as S,useState as p}from"react";function C({defaultProp:c,onChange:o}){let t=p(c),[e]=t,n=S(e),a=r(o);return d(()=>{n.current!==e&&(a(e),n.current=e)},[e,n,a]),t}function R({defaultProp:c,onChange:o,prop:t}){let[e,n]=C({defaultProp:c,onChange:o}),a=t!==void 0,T=a?t:e,l=r(o),f=i(s=>{if(a){let u=typeof s=="function"?s(t):s;u!==t&&l(u)}else n(s)},[a,t,n,l]);return[T,f]}export{R as a};
@@ -0,0 +1 @@
1
+ import{useCallback as o,useState as r}from"react";var p=s=>{let[n,e]=r(s??!1),t=o(()=>e(!0),[]),l=o(()=>e(!1),[]);return{onToggle:o(()=>e(c=>!c),[]),isOpen:n,setIsOpen:e,onOpen:t,onClose:l}};export{p as a};
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{useControlled as r}from"./use-controlled";import{useControlledState as t}from"./use-controlled-state";import{useIsDisabled as f}from"./use-disabled";import{useDisclosure as p}from"./use-disclosure";import{useFocus as l}from"./use-focus";import{useFocusVisible as d}from"./use-focus-visible";import{useHover as b}from"./use-hover";import{useMergeRefs as a}from"./use-merge-refs";import{useIsMobile as D}from"./use-mobile";import{usePress as I}from"./use-press";import{useRenderElement as R}from"./use-render-element";export{r as useControlled,t as useControlledState,p as useDisclosure,l as useFocus,d as useFocusVisible,b as useHover,f as useIsDisabled,D as useIsMobile,a as useMergeRefs,I as usePress,R as useRenderElement};
1
+ import{a as f}from"./chunk-LDFOT2HS.mjs";import{a as p}from"./chunk-SVC2SW73.mjs";import{a as x}from"./chunk-5RZGO2OJ.mjs";import{a as l}from"./chunk-HHBFW4KD.mjs";import{a as m}from"./chunk-MMYWZJVT.mjs";import{a as o}from"./chunk-XWDKDHVA.mjs";import"./chunk-QWVP4CUR.mjs";import{a as e}from"./chunk-P3NRDKDG.mjs";import{a as r}from"./chunk-TBOAIC2E.mjs";import{a as s}from"./chunk-ZTJ3FIEN.mjs";import{a as u}from"./chunk-V2C6L4C3.mjs";import{a as t}from"./chunk-3X65K33M.mjs";export{e as useControlled,o as useControlledState,s as useDisclosure,t as useFocus,u as useFocusVisible,f as useHover,r as useIsDisabled,p as useIsMobile,m as useMergeRefs,x as usePress,l as useRenderElement};
@@ -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{a}from"./chunk-QWVP4CUR.mjs";export{a as useCallbackRef};
@@ -1 +1 @@
1
- import{useCallback as i,useEffect as d,useRef as S,useState as p}from"react";import{useCallbackRef as u}from"./use-callback-ref";function C({defaultProp:c,onChange:o}){const t=p(c),[e]=t,n=S(e),a=u(o);return d(()=>{n.current!==e&&(a(e),n.current=e)},[e,n,a]),t}function R({defaultProp:c,onChange:o,prop:t}){const[e,n]=C({defaultProp:c,onChange:o}),a=t!==void 0,T=a?t:e,r=u(o),f=i(s=>{if(a){const l=typeof s=="function"?s(t):s;l!==t&&r(l)}else n(s)},[a,t,n,r]);return[T,f]}export{R as useControlledState};
1
+ import{a}from"./chunk-XWDKDHVA.mjs";import"./chunk-QWVP4CUR.mjs";export{a as useControlledState};
@@ -1,3 +1 @@
1
- import{useCallback as f,useEffect as i,useRef as l,useState as h}from"react";function p({controlled:t,default:o,name:n,state:r="value"}){const{current:e}=l(t!==void 0),[c,u]=h(o),d=e?t:c;if(process.env.NODE_ENV!=="production"){i(()=>{e!==(t!==void 0)&&console.error([`Base UI: A component is changing the ${e?"":"un"}controlled ${r} state of ${n} to be ${e?"un":""}controlled.`,"Elements should not switch from uncontrolled to controlled (or vice versa).",`Decide between using a controlled or uncontrolled ${n} element for the lifetime of the component.`,"The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.","More info: https://fb.me/react-controlled-components"].join(`
2
- `))},[r,n,t]);const{current:s}=l(o);i(()=>{!e&&!Object.is(s,o)&&console.error([`Base UI: A component is changing the default ${r} state of an uncontrolled ${n} after being initialized. To suppress this warning opt to use a controlled ${n}.`].join(`
3
- `))},[JSON.stringify(o)])}const a=f(s=>{e||u(s)},[]);return[d,a]}export{p as useControlled};
1
+ import{a}from"./chunk-P3NRDKDG.mjs";export{a as useControlled};
@@ -1 +1 @@
1
- import{useEffect as u,useRef as c,useState as f}from"react";const p=l=>{const{isDisabled:e,isFormControl:s}=l??{},t=c(null),[a,b]=f(!1);return u(()=>{const i=t.current;if(!i||e||!s)return()=>{};const r=i.closest("fieldset");if(!r)return()=>{};const o=()=>{const d=r.disabled;b(d)};o();const n=new MutationObserver(o);return n.observe(r,{attributes:!0,attributeFilter:["disabled"]}),()=>n.disconnect()},[s,e]),e||!s?{ref:t,isDisabled:e}:{ref:t,isDisabled:a}};export{p as useIsDisabled};
1
+ import{a}from"./chunk-TBOAIC2E.mjs";export{a as useIsDisabled};
@@ -1 +1 @@
1
- import{useCallback as o,useState as r}from"react";const p=s=>{const[n,e]=r(s??!1),t=o(()=>e(!0),[]),l=o(()=>e(!1),[]);return{onToggle:o(()=>e(c=>!c),[]),isOpen:n,setIsOpen:e,onOpen:t,onClose:l}};export{p as useDisclosure};
1
+ import{a}from"./chunk-ZTJ3FIEN.mjs";export{a as useDisclosure};
@@ -1 +1 @@
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};
1
+ import{a}from"./chunk-V2C6L4C3.mjs";export{a as useFocusVisible};
@@ -1 +1 @@
1
- import{useEffect as a,useRef as i,useState as l}from"react";const f=u=>{const{isDisabled:s}=u,t=i(null),[c,n]=l(!1);return a(()=>{const e=t.current;if(s||!e)return;const r=()=>{n(!0)},o=()=>{n(!1)};return e.addEventListener("focus",r),e.addEventListener("blur",o),()=>{e.removeEventListener("focus",r),e.removeEventListener("blur",o)}},[s]),s?{ref:t,isFocused:!1}:{ref:t,isFocused:c}};export{f as useFocus};
1
+ import{a}from"./chunk-3X65K33M.mjs";export{a as useFocus};
@@ -1 +1 @@
1
- import{useEffect as c,useRef as f,useState as T}from"react";const E=a=>{const{enterDelay:s=0,exitDelay:r=0,isDisabled:u}=a??{},[v,n]=T(!1),i=f(null);return c(()=>{const e=i.current;if(!e||u)return n(!1),()=>{};let t=null,o=null;const l=()=>{o&&clearTimeout(o),t=setTimeout(()=>{n(!0)},s)},m=()=>{t&&clearTimeout(t),o=setTimeout(()=>{n(!1)},r)};return e.addEventListener("mouseenter",l),e.addEventListener("mouseleave",m),()=>{t&&clearTimeout(t),o&&clearTimeout(o),e.removeEventListener("mouseenter",l),e.removeEventListener("mouseleave",m)}},[s,r,u]),{ref:i,isHovered:v}};export{E as useHover};
1
+ import{a}from"./chunk-LDFOT2HS.mjs";export{a as useHover};
@@ -1 +1 @@
1
- import{useCallback as o,useMemo as f,useRef as i}from"react";function R(t){const u=i(void 0),a=o(e=>{const r=t.map(n=>{if(n!=null){if(typeof n=="function"){const c=n,l=c(e);return typeof l=="function"?l:()=>{c(null)}}return n.current=e,()=>{n.current=null}}});return()=>{r.forEach(n=>n?.())}},t);return f(()=>t.every(e=>e==null)?null:e=>{u.current&&(u.current(),u.current=void 0),e!=null&&(u.current=a(e))},t)}export{R as useMergeRefs};
1
+ import{a}from"./chunk-MMYWZJVT.mjs";export{a as useMergeRefs};
@@ -1 +1 @@
1
- import{useEffect as s,useState as i}from"react";const a=768;function r(){const[o,n]=i(void 0);return s(()=>{const e=window.matchMedia(`(max-width: ${a-1}px)`),t=()=>n(e.matches);return e.addEventListener("change",t),n(e.matches),()=>e.removeEventListener("change",t)},[]),!!o}export{r as useIsMobile};
1
+ import{a}from"./chunk-SVC2SW73.mjs";export{a as useIsMobile};
@@ -1 +1 @@
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};
1
+ import{a}from"./chunk-5RZGO2OJ.mjs";export{a as usePress};
@@ -1 +1 @@
1
- import{jsx as n}from"react/jsx-runtime";import{cloneElement as l}from"react";import{mergeProps as a}from"@jamsrui/utils";import{useMergeRefs as g}from"./use-merge-refs";function R(r){return function(e){return r==="button"?n("button",{type:"button",...e}):r==="img"?n("img",{alt:"",...e}):n(r,{...e})}}const N=(r,o)=>{const{props:e}=o,s=Array.isArray(e)?e:[e],m=a(...s),{render:p,...c}=m,t=p??R(r)({}),i=g([t.props.ref,...s.map(u=>u.ref)]),f=a(t.props,c);return l(t,{...f,ref:i})};export{N as useRenderElement};
1
+ import{a}from"./chunk-HHBFW4KD.mjs";import"./chunk-MMYWZJVT.mjs";export{a as useRenderElement};
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@jamsrui/hooks",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "peerDependencies": {
5
5
  "react": ">=19"
6
6
  },
7
7
  "dependencies": {
8
- "@jamsrui/utils": "^0.0.9"
8
+ "@jamsrui/utils": "^0.0.10"
9
9
  },
10
10
  "exports": {
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.js"
13
+ "import": "./dist/index.mjs"
15
14
  }
16
15
  },
17
16
  "description": "A modern and beautiful Next.js UI components library.",