@jamsrui/composite 0.0.3 → 0.0.5

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{useCallback as l,useMemo as I,useRef as k,useState as C}from"react";import{isDisabledElement as w}from"@jamsrui/utils";var H=y=>{let{dir:p="ltr",loop:m=!0,orientation:c="vertical",virtual:f=!1}=y,r=k([]),[a,u]=C(0),R=k(null),x=l(e=>(r.current.push({...e,isDisabled:e.isDisabled||(e.ref?w(e.ref):!1)}),{index:r.current.length-1}),[]),h=l(e=>{let o=r.current.findIndex(t=>t.id===e);o>=0&&r.current.splice(o,1),u(t=>Math.max(0,Math.min(r.current.length-1,t)))},[]),D=l(e=>r.current.findIndex(o=>o.id===e),[]),s=l((e,o)=>{let t=r.current.length;if(t===0)return-1;let n=e;for(let i=0;i<t;i++){if(n=n+o,m)n=(n+t)%t;else if(n<0||n>=t)return e;if(!r.current[n]?.isDisabled)return n}return e},[m]),d=l(e=>s(e,-1),[s]),v=l(e=>s(e,1),[s]),b=l(()=>s(-1,1),[s]),g=l(()=>s(r.current.length,-1),[s]),A=e=>{if(!f)return;let o=p==="rtl",t=c==="horizontal"||c==="both",n=c==="vertical"||c==="both",i=a;e.key==="ArrowRight"&&t&&!o||e.key==="ArrowDown"&&n||e.key==="ArrowLeft"&&t&&o?(e.preventDefault(),i=v(a),u(i)):e.key==="ArrowLeft"&&t&&!o||e.key==="ArrowUp"&&n||e.key==="ArrowRight"&&t&&o?(e.preventDefault(),i=d(a),u(i)):e.key==="Home"||e.key==="PageUp"?(e.preventDefault(),i=b(),u(i)):(e.key==="End"||e.key==="PageDown")&&(e.preventDefault(),i=g(),u(i))},E=r.current[a]?.id;return I(()=>({registerItem:x,unregisterItem:h,getIndex:D,items:r,activeIndex:a,setActiveIndex:u,movePrev:d,moveNext:v,moveFirst:b,moveLast:g,orientation:c,dir:p,loop:m,virtual:f}),[x,h,D,a,d,v,b,g,c,p,m,f])};export{H as a};
@@ -1 +1 @@
1
- import{a as t}from"./chunk-GBJJHHP3.mjs";import{a as e}from"./chunk-64PWNUHT.mjs";import{jsx as i}from"react/jsx-runtime";var m=o=>{let{children:r}=o,p=e(o);return i(t,{value:p,children:r})};export{m as a};
1
+ import{a as t}from"./chunk-GBJJHHP3.mjs";import{a as e}from"./chunk-2IUMBEBR.mjs";import{jsx as i}from"react/jsx-runtime";var m=o=>{let{children:r}=o,p=e(o);return i(t,{value:p,children:r})};export{m as a};
@@ -0,0 +1 @@
1
+ import{b as v}from"./chunk-GBJJHHP3.mjs";import{useCallback as a,useEffect as D,useId as g,useMemo as h,useRef as C,useState as P}from"react";import{dataAttr as R}from"@jamsrui/utils";var M=x=>{let{id:I,isDisabled:m=!1}=x,e=v(),y=g(),u=C(null),[A,b]=P(-1),s=I??y;D(()=>{let{index:t}=e.registerItem({id:s,ref:u.current,isDisabled:m});return b(t),()=>e.unregisterItem(s)},[e,m,s]);let r=A,l=r===e.activeIndex,i=a(t=>{let n=e.items.current[t]?.ref;e.virtual||n?.focus()},[e.items,e.virtual]),d=a(t=>{if(e.virtual)return;let n=e.dir==="rtl",c=e.orientation==="horizontal"||e.orientation==="both",p=e.orientation==="vertical"||e.orientation==="both",o=r;t.key==="ArrowRight"&&c&&!n||t.key==="ArrowDown"&&p||t.key==="ArrowLeft"&&c&&n?(t.preventDefault(),o=e.moveNext(r),e.setActiveIndex(o),i(o)):t.key==="ArrowLeft"&&c&&!n||t.key==="ArrowUp"&&p||t.key==="ArrowRight"&&c&&n?(t.preventDefault(),o=e.movePrev(r),e.setActiveIndex(o),i(o)):t.key==="Home"||t.key==="PageUp"?(t.preventDefault(),o=e.moveFirst(),e.setActiveIndex(o),i(o)):(t.key==="End"||t.key==="PageDown")&&(t.preventDefault(),o=e.moveLast(),e.setActiveIndex(o),i(o))},[e,i,r]),f=a(()=>{e.setActiveIndex(r)},[e,r]),k=h(()=>e.virtual?{tabIndex:-1,"aria-selected":R(l)}:{tabIndex:l?0:-1,onKeyDown:d,onFocus:f},[e.virtual,l,f,d]),w=a(t=>{u.current=t},[]);return{props:{...k,id:s,"data-index":r,ref:w},index:r}};export{M as a};
@@ -1 +1 @@
1
- import{a as e}from"./chunk-Y5V5AJRK.mjs";import{cloneElement as m}from"react";var c=t=>{let{children:o,...r}=t,s=e(r);return m(o,s.props)};export{c as a};
1
+ import{a as e}from"./chunk-SY7CR4GH.mjs";import{cloneElement as m}from"react";var c=t=>{let{children:o,...r}=t,s=e(r);return m(o,s.props)};export{c as a};
@@ -1 +1 @@
1
- import{a}from"./chunk-KMTLZKGV.mjs";import"./chunk-Y5V5AJRK.mjs";import"./chunk-GBJJHHP3.mjs";export{a as CompositeItem};
1
+ import{a}from"./chunk-YAVZRYP2.mjs";import"./chunk-SY7CR4GH.mjs";import"./chunk-GBJJHHP3.mjs";export{a as CompositeItem};
@@ -1 +1 @@
1
- import{a}from"./chunk-LLIALS5H.mjs";import"./chunk-GBJJHHP3.mjs";import"./chunk-64PWNUHT.mjs";export{a as Composite};
1
+ import{a}from"./chunk-RYHBF2TQ.mjs";import"./chunk-GBJJHHP3.mjs";import"./chunk-2IUMBEBR.mjs";export{a as Composite};
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- "use client";import{a as e}from"./chunk-KMTLZKGV.mjs";import{a as m}from"./chunk-LLIALS5H.mjs";import{a as o}from"./chunk-Y5V5AJRK.mjs";import"./chunk-GBJJHHP3.mjs";import{a as t}from"./chunk-64PWNUHT.mjs";export{m as Composite,e as CompositeItem,t as useComposite,o as useCompositeItem};
1
+ "use client";import{a as e}from"./chunk-YAVZRYP2.mjs";import{a as m}from"./chunk-RYHBF2TQ.mjs";import{a as o}from"./chunk-SY7CR4GH.mjs";import"./chunk-GBJJHHP3.mjs";import{a as t}from"./chunk-2IUMBEBR.mjs";export{m as Composite,e as CompositeItem,t as useComposite,o as useCompositeItem};
@@ -1 +1 @@
1
- import{a}from"./chunk-Y5V5AJRK.mjs";import"./chunk-GBJJHHP3.mjs";export{a as useCompositeItem};
1
+ import{a}from"./chunk-SY7CR4GH.mjs";import"./chunk-GBJJHHP3.mjs";export{a as useCompositeItem};
@@ -1 +1 @@
1
- import{a}from"./chunk-64PWNUHT.mjs";export{a as useComposite};
1
+ import{a}from"./chunk-2IUMBEBR.mjs";export{a as useComposite};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@jamsrui/composite",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "peerDependencies": {
5
5
  "react": ">=19"
6
6
  },
7
7
  "dependencies": {
8
- "@jamsrui/utils": "^0.0.10"
8
+ "@jamsrui/utils": "^0.0.12"
9
9
  },
10
10
  "exports": {
11
11
  ".": {
@@ -1 +0,0 @@
1
- import{useCallback as l,useMemo as C,useRef as k,useState as w}from"react";import{isDisabledElement as R}from"@jamsrui/utils";var H=y=>{let{dir:p="ltr",loop:m=!0,orientation:a="vertical",virtual:f=!1}=y,o=k([]),[c,u]=w(0),I=k(null);console.log({rootRef:I,items:o,activeIndex:c});let x=l(e=>(o.current.push({...e,isDisabled:e.isDisabled||(e.ref?R(e.ref):!1)}),{index:o.current.length-1}),[]),h=l(e=>{let r=o.current.findIndex(t=>t.id===e);r>=0&&o.current.splice(r,1),u(t=>Math.max(0,Math.min(o.current.length-1,t)))},[]),D=l(e=>o.current.findIndex(r=>r.id===e),[]),s=l((e,r)=>{let t=o.current.length;if(t===0)return-1;let n=e;for(let i=0;i<t;i++){if(n=n+r,m)n=(n+t)%t;else if(n<0||n>=t)return e;if(!o.current[n]?.isDisabled)return n}return e},[m]),d=l(e=>s(e,-1),[s]),v=l(e=>s(e,1),[s]),b=l(()=>s(-1,1),[s]),g=l(()=>s(o.current.length,-1),[s]),A=e=>{if(!f)return;let r=p==="rtl",t=a==="horizontal"||a==="both",n=a==="vertical"||a==="both",i=c;e.key==="ArrowRight"&&t&&!r||e.key==="ArrowDown"&&n||e.key==="ArrowLeft"&&t&&r?(e.preventDefault(),i=v(c),u(i)):e.key==="ArrowLeft"&&t&&!r||e.key==="ArrowUp"&&n||e.key==="ArrowRight"&&t&&r?(e.preventDefault(),i=d(c),u(i)):e.key==="Home"||e.key==="PageUp"?(e.preventDefault(),i=b(),u(i)):(e.key==="End"||e.key==="PageDown")&&(e.preventDefault(),i=g(),u(i))},E=o.current[c]?.id;return C(()=>({registerItem:x,unregisterItem:h,getIndex:D,items:o,activeIndex:c,setActiveIndex:u,movePrev:d,moveNext:v,moveFirst:b,moveLast:g,orientation:a,dir:p,loop:m,virtual:f}),[x,h,D,c,d,v,b,g,a,p,m,f])};export{H as a};
@@ -1 +0,0 @@
1
- import{b as v}from"./chunk-GBJJHHP3.mjs";import{useCallback as a,useEffect as D,useId as g,useMemo as h,useRef as C,useState as P}from"react";import{dataAttr as R}from"@jamsrui/utils";var M=x=>{let{id:I,isDisabled:m=!1}=x,e=v(),y=g(),u=C(null),[A,b]=P(-1),i=I??y;D(()=>{let{index:t}=e.registerItem({id:i,ref:u.current,isDisabled:m});return b(t),()=>e.unregisterItem(i)},[e,m,i]);let r=A,l=r===e.activeIndex,s=a(t=>{let n=e.items.current[t]?.ref;e.virtual||n?.focus()},[e.items,e.virtual]),d=a(t=>{if(e.virtual)return;let n=e.dir==="rtl",c=e.orientation==="horizontal"||e.orientation==="both",p=e.orientation==="vertical"||e.orientation==="both",o=r;t.key==="ArrowRight"&&c&&!n||t.key==="ArrowDown"&&p||t.key==="ArrowLeft"&&c&&n?(t.preventDefault(),o=e.moveNext(r),console.log(o),e.setActiveIndex(o),s(o)):t.key==="ArrowLeft"&&c&&!n||t.key==="ArrowUp"&&p||t.key==="ArrowRight"&&c&&n?(t.preventDefault(),o=e.movePrev(r),e.setActiveIndex(o),s(o)):t.key==="Home"||t.key==="PageUp"?(t.preventDefault(),o=e.moveFirst(),e.setActiveIndex(o),s(o)):(t.key==="End"||t.key==="PageDown")&&(t.preventDefault(),o=e.moveLast(),e.setActiveIndex(o),s(o))},[e,s,r]),f=a(()=>{e.setActiveIndex(r)},[e,r]),k=h(()=>e.virtual?{tabIndex:-1,"aria-selected":R(l)}:{tabIndex:l?0:-1,onKeyDown:d,onFocus:f},[e.virtual,l,f,d]),w=a(t=>{u.current=t},[]);return{props:{...k,id:i,"data-index":r,ref:w},index:r}};export{M as a};