@jamsrui/hooks 0.0.19 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,12 +2,11 @@
2
2
 
3
3
  **A comprehensive React UI component library designed for developers, with Tailwind CSS integration for seamless styling.**
4
4
 
5
-
6
5
  ## 📖 **Overview**
7
6
 
8
7
  [JamsrUI](https://jamsr-ui.jamsrworld.com) is designed to help developers build modern, fast and visually appealing web applications with ease.
9
8
 
10
- ## 🚀 Getting Started
9
+ ## 🚀 Getting Started
11
10
 
12
11
  Boost & Build your websites using [JamsrUI](https://jamsr-ui.jamsrworld.com).
13
12
 
@@ -37,4 +36,3 @@ We welcome contributions from developers of all skill levels!
37
36
  ## ⭐ Support the Project
38
37
 
39
38
  If you find **JamsrUI** helpful, consider giving it a ⭐ on [GitHub](https://github.com/jamsrworld/jamsr-ui).
40
-
@@ -1 +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};
1
+ import{useCallback as t,useEffect as p,useRef as m,useState as E}from"react";function k(f={}){let{isDisabled:r=!1}=f,v=m(null),[n,s]=E(!1),[L,o]=E(!1),w=n&&L,i=t(()=>{s(!0),o(!0)},[]),a=t(()=>{n&&o(!1)},[n]),d=t(()=>{n&&o(!0)},[n]),l=t(()=>{n&&s(!1)},[n]),c=t(e=>{(e.target instanceof HTMLInputElement?[" "]:["Enter"," "]).includes(e.key)&&(s(!0),o(!0))},[]),u=t(e=>{(e.key==="Enter"||e.key===" ")&&n&&s(!1)},[n]);return p(()=>{if(r)return;let e=()=>{n&&s(!1)};return window.addEventListener("pointerup",e),window.addEventListener("contextmenu",e),()=>{window.removeEventListener("pointerup",e),window.removeEventListener("contextmenu",e)}},[n,r]),p(()=>{let e=v.current;if(!(!e||r))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,r]),{isPressed:w,ref:v,isPressing:n}}export{k as a};
@@ -1 +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};
1
+ import{a}from"./chunk-ZOLXXGJR.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{useRef as d}from"react";var m=()=>{let t=0,o=new Map,n=new Set,r={version:t,items:o},s=!1,u=()=>r,c=e=>(n.add(e),()=>n.delete(e)),l=()=>{s||(s=!0,queueMicrotask(()=>{s=!1,t++,r.version=t,r.items=o,n.forEach(e=>e())}))};return{getSnapshot:u,subscribe:c,register:(e,a)=>{let i=o.get(e);i&&i.textValue===a.textValue&&i.disabled===a.disabled||(o.set(e,{value:e,...a}),l())},unregister:e=>{o.has(e)&&(o.delete(e),l())},getItems:()=>o}},V=()=>{let t=d(null);return t.current||(t.current=m()),t.current};export{V as a};
@@ -0,0 +1 @@
1
+ import{useCallback as o,useMemo as f,useRef as i}from"react";function R(t){let c=i(void 0),l=o(e=>{let a=t.map(n=>{if(n!=null){if(typeof n=="function"){let u=n,r=u(e);return typeof r=="function"?r:()=>{u(null)}}return n.current=e,()=>{n.current=null}}});return()=>{a.forEach(n=>n?.())}},t);return f(()=>t.every(e=>e==null)?null:e=>{c.current&&(c.current(),c.current=void 0),e!=null&&(c.current=l(e))},t)}export{R as a};
package/dist/index.d.mts CHANGED
@@ -9,5 +9,6 @@ export { useMergeRefs } from './use-merge-refs.mjs';
9
9
  export { useIsMobile } from './use-mobile.mjs';
10
10
  export { usePress } from './use-press.mjs';
11
11
  export { useRenderElement } from './use-render-element.mjs';
12
+ export { useCollection } from './use-collection.mjs';
12
13
  import 'react';
13
14
  import '@jamsrui/utils';
package/dist/index.mjs CHANGED
@@ -1 +1 @@
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-IAG6BMWI.mjs";import"./chunk-LDFAOKBY.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
+ import{a as t}from"./chunk-3X65K33M.mjs";import{a as f}from"./chunk-LDFOT2HS.mjs";import{a as p}from"./chunk-SVC2SW73.mjs";import{a as x}from"./chunk-6UYDT3T3.mjs";import{a as l}from"./chunk-GBWZONDV.mjs";import{a as m}from"./chunk-ZOLXXGJR.mjs";import{a as i}from"./chunk-MDYZ5Q34.mjs";import{a as o}from"./chunk-IAG6BMWI.mjs";import"./chunk-LDFAOKBY.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";export{i as useCollection,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};
@@ -0,0 +1,28 @@
1
+ type Value = any;
2
+ interface ItemData {
3
+ value: Value;
4
+ textValue: string;
5
+ disabled: boolean;
6
+ ref: React.RefObject<HTMLDivElement | null>;
7
+ }
8
+ interface CollectionSnapshot {
9
+ version: number;
10
+ items: Map<Value, ItemData>;
11
+ }
12
+ interface ItemContextValue {
13
+ value: Value;
14
+ disabled: boolean;
15
+ isSelected: boolean;
16
+ isHighlighted: boolean;
17
+ textId: string;
18
+ }
19
+ interface CollectionStore {
20
+ getSnapshot: () => CollectionSnapshot;
21
+ subscribe: (listener: () => void) => () => void;
22
+ register: (value: Value, data: Omit<ItemData, "value">) => void;
23
+ unregister: (value: Value) => void;
24
+ getItems: () => Map<Value, ItemData>;
25
+ }
26
+ declare const useCollection: () => CollectionStore;
27
+
28
+ export { type CollectionSnapshot, type CollectionStore, type ItemContextValue, type ItemData, useCollection };
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-MDYZ5Q34.mjs";export{a as useCollection};
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Merges an array of refs into a single memoized callback ref or `null`.
3
3
  */
4
- declare function useMergeRefs<Instance>(refs: Array<React.Ref<Instance> | undefined>): null | React.RefCallback<Instance>;
4
+ declare function useMergeRefs<Instance>(refs: Array<React.Ref<Instance> | undefined>): null | React.Ref<Instance>;
5
5
 
6
6
  export { useMergeRefs };
@@ -1 +1 @@
1
- import{a}from"./chunk-MMYWZJVT.mjs";export{a as useMergeRefs};
1
+ import{a}from"./chunk-ZOLXXGJR.mjs";export{a as useMergeRefs};
@@ -1,10 +1,10 @@
1
1
  import * as react from 'react';
2
2
 
3
- declare function usePress(props?: {
3
+ declare function usePress<T extends HTMLElement>(props?: {
4
4
  isDisabled?: boolean;
5
5
  }): {
6
6
  isPressed: boolean;
7
- ref: react.RefObject<HTMLElement | null>;
7
+ ref: react.RefObject<T | null>;
8
8
  isPressing: boolean;
9
9
  };
10
10
  declare namespace usePress {
@@ -1 +1 @@
1
- import{a}from"./chunk-5RZGO2OJ.mjs";export{a as usePress};
1
+ import{a}from"./chunk-6UYDT3T3.mjs";export{a as usePress};
@@ -1 +1 @@
1
- import{a}from"./chunk-HHBFW4KD.mjs";import"./chunk-MMYWZJVT.mjs";export{a as useRenderElement};
1
+ import{a}from"./chunk-GBWZONDV.mjs";import"./chunk-ZOLXXGJR.mjs";export{a as useRenderElement};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@jamsrui/hooks",
3
- "version": "0.0.19",
3
+ "version": "0.1.0",
4
4
  "peerDependencies": {
5
5
  "react": ">=19"
6
6
  },
7
7
  "dependencies": {
8
- "@jamsrui/utils": "^0.0.19"
8
+ "@jamsrui/utils": "^0.1.0"
9
9
  },
10
10
  "exports": {
11
11
  ".": {
@@ -1 +0,0 @@
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};