@jamsrui/composite 0.0.2 → 0.0.3
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/dist/chunk-64PWNUHT.mjs +1 -0
- package/dist/chunk-GBJJHHP3.mjs +1 -0
- package/dist/chunk-KMTLZKGV.mjs +1 -0
- package/dist/chunk-LLIALS5H.mjs +1 -0
- package/dist/chunk-Y5V5AJRK.mjs +1 -0
- package/dist/composite-context.mjs +1 -1
- package/dist/composite-item.mjs +1 -1
- package/dist/composite.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/use-composite-item.mjs +1 -1
- package/dist/use-composite.mjs +1 -1
- package/package.json +3 -4
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createContext as t,use as o}from"react";var s=t(null),r=()=>{let e=o(s);if(!e)throw new Error("useCompositeContext must be used within a Composite");return e};export{s as a,r as b};
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +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};
|
|
@@ -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),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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a,b}from"./chunk-GBJJHHP3.mjs";export{a as CompositeContext,b as useCompositeContext};
|
package/dist/composite-item.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a}from"./chunk-KMTLZKGV.mjs";import"./chunk-Y5V5AJRK.mjs";import"./chunk-GBJJHHP3.mjs";export{a as CompositeItem};
|
package/dist/composite.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a}from"./chunk-LLIALS5H.mjs";import"./chunk-GBJJHHP3.mjs";import"./chunk-64PWNUHT.mjs";export{a as Composite};
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{
|
|
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 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a}from"./chunk-Y5V5AJRK.mjs";import"./chunk-GBJJHHP3.mjs";export{a as useCompositeItem};
|
package/dist/use-composite.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a}from"./chunk-64PWNUHT.mjs";export{a as useComposite};
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamsrui/composite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"react": ">=19"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@jamsrui/utils": "^0.0.
|
|
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.",
|