@jamsrui/composite 0.0.9 → 0.0.11

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{createContext as t,use as o}from"react";const s=t(null),r=()=>{const e=o(s);if(!e)throw new Error("useCompositeContext must be used within a Composite");return e};export{s as CompositeContext,r as useCompositeContext};
1
+ "use client";import{createContext as t,use as o}from"react";const s=t(null),n=()=>{const e=o(s);if(!e)throw new Error("useCompositeContext must be used within a Composite");return e};export{s as CompositeContext,n as useCompositeContext};
@@ -1 +1 @@
1
- import{cloneElement as s}from"react";import{useCompositeItem as m}from"./use-composite-item.mjs";const c=e=>{const{children:t,...o}=e,r=m(o);return s(t,r.props)};export{c as CompositeItem};
1
+ "use client";import{cloneElement as r}from"react";import{useCompositeItem as m}from"./use-composite-item.mjs";const c=e=>{const{children:t,...o}=e,s=m(o);return r(t,s.props)};export{c as CompositeItem};
@@ -1 +1 @@
1
- import{jsx as i}from"react/jsx-runtime";import{CompositeContext as r}from"./composite-context.mjs";import{useComposite as p}from"./use-composite.mjs";const m=o=>{const{children:t}=o,e=p(o);return i(r,{value:e,children:t})};export{m as Composite};
1
+ "use client";import{jsx as i}from"react/jsx-runtime";import{CompositeContext as r}from"./composite-context.mjs";import{useComposite as p}from"./use-composite.mjs";const c=o=>{const{children:t}=o,e=p(o);return i(r,{value:e,children:t})};export{c as Composite};
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- "use client";import{Composite as t}from"./composite.mjs";import{CompositeItem as p}from"./composite-item.mjs";import{useComposite as s}from"./use-composite.mjs";import{useCompositeItem as f}from"./use-composite-item.mjs";export{t as Composite,p as CompositeItem,s as useComposite,f as useCompositeItem};
1
+ import{Composite as m}from"./composite.mjs";import{CompositeItem as p}from"./composite-item.mjs";import{useComposite as s}from"./use-composite.mjs";import{useCompositeItem as i}from"./use-composite-item.mjs";export{m as Composite,p as CompositeItem,s as useComposite,i as useCompositeItem};
@@ -1 +1 @@
1
- import{useCallback as a,useEffect as w,useId as D,useMemo as g,useRef as h,useState as C}from"react";import{dataAttr as P}from"@jamsrui/utils";import{useCompositeContext as R}from"./composite-context.mjs";const M=v=>{const{id:x,isDisabled:m=!1}=v,e=R(),I=D(),u=h(null),[y,A]=C(-1),s=x??I;w(()=>{const{index:t}=e.registerItem({id:s,ref:u.current,isDisabled:m});return A(t),()=>e.unregisterItem(s)},[e,m,s]);const r=y,l=r===e.activeIndex,i=a(t=>{const n=e.items.current[t]?.ref;e.virtual||n?.focus()},[e.items,e.virtual]),d=a(t=>{if(e.virtual)return;const n=e.dir==="rtl",c=e.orientation==="horizontal"||e.orientation==="both",p=e.orientation==="vertical"||e.orientation==="both";let 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]),b=g(()=>e.virtual?{tabIndex:-1,"aria-selected":P(l)}:{tabIndex:l?0:-1,onKeyDown:d,onFocus:f},[e.virtual,l,f,d]),k=a(t=>{u.current=t},[]);return{props:{...b,id:s,"data-index":r,ref:k},index:r}};export{M as useCompositeItem};
1
+ "use client";import{useCallback as a,useEffect as w,useId as D,useMemo as g,useRef as h,useState as C}from"react";import{dataAttr as P}from"@jamsrui/utils";import{useCompositeContext as R}from"./composite-context.mjs";const M=v=>{const{id:x,isDisabled:u=!1}=v,e=R(),I=D(),m=h(null),[y,A]=C(-1),s=x??I;w(()=>{const{index:t}=e.registerItem({id:s,ref:m.current,isDisabled:u});return A(t),()=>e.unregisterItem(s)},[e,u,s]);const r=y,l=r===e.activeIndex,i=a(t=>{const n=e.items.current[t]?.ref;e.virtual||n?.focus()},[e.items,e.virtual]),d=a(t=>{if(e.virtual)return;const n=e.dir==="rtl",c=e.orientation==="horizontal"||e.orientation==="both",p=e.orientation==="vertical"||e.orientation==="both";let 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]),b=g(()=>e.virtual?{tabIndex:-1,"aria-selected":P(l)}:{tabIndex:l?0:-1,onKeyDown:d,onFocus:f},[e.virtual,l,f,d]),k=a(t=>{m.current=t},[]);return{props:{...b,id:s,"data-index":r,ref:k},index:r}};export{M as useCompositeItem};
@@ -1 +1 @@
1
- import{useCallback as l,useMemo as I,useRef as k,useState as C}from"react";import{isDisabledElement as w}from"@jamsrui/utils";const H=y=>{const{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=>{const 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)=>{const 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;const o=p==="rtl",t=c==="horizontal"||c==="both",n=c==="vertical"||c==="both";let 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 useComposite};
1
+ "use client";import{useCallback as l,useMemo as I,useRef as k,useState as C}from"react";import{isDisabledElement as w}from"@jamsrui/utils";const H=y=>{const{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=>{const 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)=>{const 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;const o=p==="rtl",t=c==="horizontal"||c==="both",n=c==="vertical"||c==="both";let 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 useComposite};
package/dist/utils.mjs CHANGED
@@ -0,0 +1 @@
1
+ "use client";
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@jamsrui/composite",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "peerDependencies": {
5
5
  "react": ">=19"
6
6
  },
7
7
  "dependencies": {
8
- "@jamsrui/utils": "^0.0.16"
8
+ "@jamsrui/utils": "^0.0.18"
9
9
  },
10
10
  "exports": {
11
11
  ".": {