1 line
8.5 KiB
JavaScript
1 line
8.5 KiB
JavaScript
|
|
import{Fn as e,Ln as t,Pn as n,Vn as r,an as i,j as a,k as o,qn as s,sn as c,zn as l}from"./index-BaTxSAlR.js";var u=s(r(),1),d=s(l(),1),f,p,m=Object.defineProperty,h=(e,t)=>m(e,`name`,{value:t,configurable:!0});function g(e){let t=e+`CollectionProvider`,[n,r]=o(t),[a,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),l=h(e=>{let{scope:t,children:n}=e,r=u.useRef(null),i=u.useRef(new Map).current;return(0,d.jsx)(a,{scope:t,itemMap:i,collectionRef:r,children:n})},`CollectionProvider`);l.displayName=t;let f=e+`CollectionSlot`,p=i(f),m=u.forwardRef((e,t)=>{let{scope:n,children:r}=e;return(0,d.jsx)(p,{ref:c(t,s(f,n).collectionRef),children:r})});m.displayName=f;let g=e+`CollectionItemSlot`,_=`data-radix-collection-item`,v=i(g),y=u.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,a=u.useRef(null),o=c(t,a),l=s(g,n);return u.useEffect(()=>(l.itemMap.set(a,{ref:a,...i}),()=>void l.itemMap.delete(a))),(0,d.jsx)(v,{[_]:``,ref:o,children:r})});y.displayName=g;function b(t){let n=s(e+`CollectionConsumer`,t);return u.useCallback(()=>{let e=n.collectionRef.current;if(!e)return[];let t=Array.from(e.querySelectorAll(`[${_}]`));return Array.from(n.itemMap.values()).sort((e,n)=>t.indexOf(e.ref.current)-t.indexOf(n.ref.current))},[n.collectionRef,n.itemMap])}return h(b,`useCollection`),[{Provider:l,Slot:m,ItemSlot:y},b,r]}h(g,`createCollection`);var _=new WeakMap,v=(f=new WeakMap,p=class r extends Map{constructor(e){super(e),t(this,f,void 0),n(f,this,[...super.keys()]),_.set(this,!0)}set(t,n){return _.get(this)&&!this.has(t)&&e(f,this).push(t),super.set(t,n),this}insert(t,n,r){let i=this.has(n),a=i?this.size:this.size+1,o=x(t),s=o>=0?Math.min(o,a-1):Math.max(a+o,0);if(i?e(f,this).indexOf(n)===s:s===this.size)return this.set(n,r),this;let c=e(f,this).filter(e=>e!==n);c.splice(s,0,n);let l=c.map(e=>[e,e===n?r:this.get(e)]);this.clear();for(let[e,t]of l)this.set(e,t);return this}with(e,t,n){let i=new r(this);return i.insert(e,t,n),i}before(t){let n=e(f,this).indexOf(t)-1;if(!(n<0))return this.entryAt(n)}setBefore(t,n,r){let i=e(f,this).indexOf(t);if(i===-1)return this;let a=e(f,this).indexOf(n),o=a!==-1&&a<i?i-1:i;return this.insert(o,n,r)}after(t){let n=e(f,this).indexOf(t);if(n=n===-1||n===this.size-1?-1:n+1,n!==-1)return this.entryAt(n)}setAfter(t,n,r){let i=e(f,this).indexOf(t);if(i===-1)return this;let a=e(f,this).indexOf(n),o=a!==-1&&a<=i?i:i+1;return this.insert(o,n,r)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return n(f,this,[]),super.clear()}delete(t){let n=super.delete(t);return n&&e(f,this).splice(e(f,this).indexOf(t),1),n}deleteAt(e){let t=this.keyAt(e);return t===void 0?!1:this.delete(t)}at(t){let n=y(e(f,this),t);if(n!==void 0)return this.get(n)}entryAt(t){let n=y(e(f,this),t);if(n!==void 0)return[n,this.get(n)]}indexOf(t){return e(f,this).indexOf(t)}keyAt(t){return y(e(f,this),t)}from(e,t){let n=this.indexOf(e);if(n===-1)return;let r=n+t;return r<0&&(r=0),r>=this.size&&(r=this.size-1),this.at(r)}keyFrom(e,t){let n=this.indexOf(e);if(n===-1)return;let r=n+t;return r<0&&(r=0),r>=this.size&&(r=this.size-1),this.keyAt(r)}find(e,t){let n=0;for(let r of this){if(Reflect.apply(e,t,[r,n,this]))return r;n++}}findIndex(e,t){let n=0;for(let r of this){if(Reflect.apply(e,t,[r,n,this]))return n;n++}return-1}filter(e,t){let n=[],i=0;for(let r of this)Reflect.apply(e,t,[r,i,this])&&n.push(r),i++;return new r(n)}map(e,t){let n=[],i=0;for(let r of this)n.push([r[0],Reflect.apply(e,t,[r,i,this])]),i++;return new r(n)}reduce(...e){let[t,n]=e,r=e.length>1;if(!r&&this.size===0)throw TypeError(`Reduce of empty OrderedDict with no initial value`);let i=0,a=n;for(let e of this)a=i===0&&!r?e:Reflect.apply(t,this,[a,e,i,this]),i++;return a}reduceRight(...e){let[t,n]=e,r=e.length>1;if(!r&&this.size===0)throw TypeError(`Reduce of empty OrderedDict with no initial value`);let i=n;for(let e=this.size-1;e>=0;e--){let n=this.entryAt(e);i=e===this.size-1&&!r?n:Reflect.apply(t,this,[i,n,e,this])}return i}sort(e){if(typeof e!=`function`)throw TypeError(`OrderedDict.sort requires a compare function`);let t=[...this.entries()].sort
|