react-animated-select 0.2.7 → 0.2.9
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/index.cjs.js +9 -9
- package/dist/index.es.js +481 -473
- package/package.json +1 -1
- package/src/options.jsx +2 -2
- package/src/select.jsx +2 -0
- package/src/useSelectLogic.jsx +131 -181
package/dist/index.cjs.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const o=require("react"),pe=require("react-transition-group");var
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const o=require("react"),pe=require("react-transition-group");var te={exports:{}},Q={};var ue;function je(){if(ue)return Q;ue=1;var t=Symbol.for("react.transitional.element"),s=Symbol.for("react.fragment");function l(a,b,c){var x=null;if(c!==void 0&&(x=""+c),b.key!==void 0&&(x=""+b.key),"key"in b){c={};for(var _ in b)_!=="key"&&(c[_]=b[_])}else c=b;return b=c.ref,{$$typeof:t,type:a,key:x,ref:b!==void 0?b:null,props:c}}return Q.Fragment=s,Q.jsx=l,Q.jsxs=l,Q}var ee={};var fe;function ke(){return fe||(fe=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===n?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case w:return"Fragment";case F:return"Profiler";case v:return"StrictMode";case k:return"Suspense";case W:return"SuspenseList";case J:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case d:return"Portal";case f:return e.displayName||"Context";case P:return(e._context.displayName||"Context")+".Consumer";case H:var u=e.render;return e=e.displayName,e||(e=u.displayName||u.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case K:return u=e.displayName||null,u!==null?u:t(e.type)||"Memo";case I:u=e._payload,e=e._init;try{return t(e(u))}catch{}}return null}function s(e){return""+e}function l(e){try{s(e);var u=!1}catch{u=!0}if(u){u=console;var y=u.error,T=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return y.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",T),s(e)}}function a(e){if(e===w)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===I)return"<...>";try{var u=t(e);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function b(){var e=h.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function x(e){if($.call(e,"key")){var u=Object.getOwnPropertyDescriptor(e,"key").get;if(u&&u.isReactWarning)return!1}return e.key!==void 0}function _(e,u){function y(){i||(i=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",u))}y.isReactWarning=!0,Object.defineProperty(e,"key",{get:y,configurable:!0})}function m(){var e=t(this.type);return g[e]||(g[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function j(e,u,y,T,q,B){var S=y.ref;return e={$$typeof:N,type:e,key:u,props:y,_owner:T},(S!==void 0?S:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:m}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:B}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function M(e,u,y,T,q,B){var S=u.children;if(S!==void 0)if(T)if(V(S)){for(T=0;T<S.length;T++)O(S[T]);Object.freeze&&Object.freeze(S)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else O(S);if($.call(u,"key")){S=t(e);var z=Object.keys(u).filter(function(re){return re!=="key"});T=0<z.length?"{key: someKey, "+z.join(": ..., ")+": ...}":"{key: someKey}",Y[S+T]||(z=0<z.length?"{"+z.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,T,j,z,j),E[j+T]=!0)}if(j=null,g!==void 0&&(i(g),j=""+g),y(c)&&(i(c.key),j=""+c.key),"key"in c){g={};for(var B in c)B!=="key"&&(g[B]=c[B])}else g=c;return j&&R(g,typeof e=="function"?e.displayName||e.name||"Unknown":e),k(e,j,g,b(),U,X)}function I(e){A(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===_&&(e._payload.status==="fulfilled"?A(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function A(e){return typeof e=="object"&&e!==null&&e.$$typeof===P}var C=o,P=Symbol.for("react.transitional.element"),f=Symbol.for("react.portal"),w=Symbol.for("react.fragment"),x=Symbol.for("react.strict_mode"),N=Symbol.for("react.profiler"),$=Symbol.for("react.consumer"),d=Symbol.for("react.context"),W=Symbol.for("react.forward_ref"),F=Symbol.for("react.suspense"),Y=Symbol.for("react.suspense_list"),G=Symbol.for("react.memo"),_=Symbol.for("react.lazy"),V=Symbol.for("react.activity"),L=Symbol.for("react.client.reference"),S=C.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,H=Object.prototype.hasOwnProperty,K=Array.isArray,O=console.createTask?console.createTask:function(){return null};C={react_stack_bottom_frame:function(e){return e()}};var r,h={},n=C.react_stack_bottom_frame.bind(C,a)(),l=O(u(a)),E={};ee.Fragment=w,ee.jsx=function(e,c,g){var T=1e4>S.recentlyCreatedOwnerStacks++;return D(e,c,g,!1,T?Error("react-stack-top-frame"):n,T?O(u(e)):l)},ee.jsxs=function(e,c,g){var T=1e4>S.recentlyCreatedOwnerStacks++;return D(e,c,g,!0,T?Error("react-stack-top-frame"):n,T?O(u(e)):l)}})()),ee}var de;function _e(){return de||(de=1,process.env.NODE_ENV==="production"?re.exports=ke():re.exports=Te()),re.exports}var m=_e();const Re=({className:t="",...s})=>m.jsx("svg",{className:t,role:"button","aria-label":"Clear selection",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512",width:"1em",height:"1em",fill:"currentColor",...s,children:m.jsx("path",{d:"M310.6 361.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L160 301.3 54.6 406.6c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L114.7 256 9.4 150.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 210.7 265.4 105.4c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3L205.3 256l105.3 105.4z"})}),Se=({className:t="",...s})=>m.jsx("svg",{className:t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",width:"1em",height:"1em",fill:"currentColor",...s,children:m.jsx("path",{d:"M34.9 289.5l175.9-175.8c9.4-9.4 24.6-9.4 33.9 0L420.1 289.5c15.1 15.1 4.4 41-17 41H51.9c-21.4 0-32.1-25.9-17-41z"})}),he=o.createContext(null);function $e({disabled:t,isOpen:s,setIsOpen:i,options:u,selectOption:b,selected:a}){const y=o.useRef(!1),R=o.useRef(0),[v,k]=o.useState(-1);o.useEffect(()=>{const f=()=>{R.current=Date.now()};return window.addEventListener("focus",f),()=>window.removeEventListener("focus",f)},[]),o.useEffect(()=>{if(s){let f=-1;if(a){const w=u.findIndex(x=>x.id===a.id&&!x.disabled);w>=0&&(f=w)}f===-1&&(f=u.findIndex(w=>!w.disabled)),k(f)}else k(-1)},[s,a,u]);const D=o.useCallback(f=>{f.currentTarget.contains(f.relatedTarget)||i(!1)},[i]),I=o.useCallback(()=>{t||document.hidden||Date.now()-R.current<100||s||(i(!0),y.current=!0,setTimeout(()=>{y.current=!1},200))},[t,s,i]),A=o.useCallback(f=>{t||f.target.closest(".rac-select-cancel")||y.current||i(!s)},[t,s,i]),C=(f,w)=>{if(u.every($=>$.disabled))return-1;let x=f,N=0;do x+=w,x<0&&(x=u.length-1),x>=u.length&&(x=0),N++;while(u[x]?.disabled&&N<=u.length);return x},P=o.useCallback(f=>{if(!t)switch(f.key){case"Enter":case" ":f.preventDefault(),s?v!==-1&&u[v]&&b(u[v],f):i(!0);break;case"Escape":f.preventDefault(),i(!1);break;case"ArrowDown":f.preventDefault(),s?k(w=>C(w,1)):i(!0);break;case"ArrowUp":f.preventDefault(),s?k(w=>C(w,-1)):i(!0);break;case"Tab":s&&i(!1);break}},[t,s,i,v,u,b]);return o.useMemo(()=>({handleBlur:D,handleFocus:I,handleToggle:A,handleKeyDown:P,highlightedIndex:v,setHighlightedIndex:k}),[D,I,A,P,v,k])}function Ae({options:t=[],jsxOptions:s=[],value:i,defaultValue:u=void 0,onChange:b,disabled:a=!1,loading:y=!1,error:R=!1,placeholder:v="Choose option",emptyText:k="No options",disabledText:D="Disabled",loadingText:I="Loading",errorText:A="Failed to load",disabledOption:C="Disabled option",emptyOption:P="Empty option",invalidOption:f="Invalid option",setVisibility:w}){const x=o.useId(),N=i!==void 0,[$,d]=o.useState(u),W=N?i:$,F=r=>!r||typeof r!="object"||Array.isArray(r)?!1:"id"in r||"value"in r||"name"in r||"label"in r||"disabled"in r,Y=o.useMemo(()=>{if(!t)return[];const r=[],h=(n,l,E)=>{let e=E?.id??E?.value;if(e==null&&(e=l??n),typeof l=="number"&&l===0){r.push({key:"0",value:0,userId:0,label:"0",original:E});return}if(typeof l=="boolean"){r.push({key:`bool-${r.length}`,value:l,userId:e,label:String(l),type:"boolean",original:E});return}if(l===""||l===null||l===void 0){r.push({key:`empty-${r.length}`,value:null,userId:e??`empty-${r.length}`,disabled:!0,label:P,original:E});return}if(typeof l=="function"){r.push({key:`invalid-${r.length}`,value:null,userId:e??`invalid-${r.length}`,disabled:!0,label:f,original:E});return}l&&typeof l=="object"&&!Array.isArray(l)?r.push({key:l.id??l.value??l.name??n,value:l,userId:e,disabled:!!l.disabled,label:l.name??l.label??n,original:E}):r.push({key:n,value:l,userId:e,label:String(l??n),original:E})};if(Array.isArray(t))for(const n of t){if(n&&typeof n=="object"&&!Array.isArray(n)&&Object.keys(n).length==1&&n.disabled==!0){r.push({key:`disabled-${r.length}`,value:null,userId:null,disabled:!0,label:C,original:n});continue}if(F(n)){const l=n.id??(typeof n.value!="object"?n.value:n.label??n.name??n.value);r.push({key:n.id??n.value??n.name??`opt-${r.length}`,value:n.value??n.id??n,userId:l,disabled:!!n.disabled,label:n.name??n.label??String(n.id??n.value),original:n})}else if(n&&typeof n=="object")for(const[l,E]of Object.entries(n))h(l,E,E);else h(n,n,n)}else if(typeof t=="object")for(const[n,l]of Object.entries(t))h(n,l,l);return r.map((n,l)=>({id:`${x}-opt-${l}`,userId:n.userId,name:String(n.label),raw:n.value,original:n.original,disabled:n.disabled,type:typeof n.value=="boolean"?"boolean":"normal"}))},[t,x]),G=o.useMemo(()=>s.map((r,h)=>({id:`jsx-${x.replace(/:/g,"")}-${r.id}-${h}`,userId:r.id,value:r.value,raw:r.value,original:r.value,name:r.label,jsx:r.jsx,disabled:r.disabled,className:r.className,type:typeof r.value=="boolean"?"boolean":"normal"})),[s,x]),_=o.useMemo(()=>[...Y,...G],[Y,G]),V=_.length>0,L=o.useMemo(()=>!R&&!y&&!a&&V,[R,y,a,V]),S=o.useMemo(()=>{if(!N)return null;if($){const r=_.find(h=>h.id===$);if(r&&r.userId===i)return $}return _.find(r=>r.userId===i)?.id??null},[N,i,_,$]),H=o.useMemo(()=>{const r=N?S:$;return r?_.find(h=>h.id===r)??null:null},[N,S,$,_]),K=o.useCallback((r,h)=>{if(r.disabled){h.stopPropagation(),h.preventDefault();return}d(r.id),b?.(r?.original,r?.userId),w(!1)},[b,w]),O=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),d(null),b?.(null,null)},[b]);return{normalizedOptions:_,selected:H,selectOption:K,clear:O,hasOptions:V,active:L,selectedValue:W,placeholder:v,emptyText:k,disabledText:D,loadingText:I,errorText:A,disabledOption:C,emptyOption:P,invalidOption:f,disabled:a,loading:y,error:R}}const oe=(t,s="invalid-option",i="")=>{const u=i?i.replace(/:/g,""):"";if(typeof t!="string"||!t.trim())return u?`${s}-${u}`:`${s}-${Math.random().toString(36).slice(2,8)}`;const b=t.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").replace(/\s+/g,"-").replace(/[^\p{L}\p{N}-]+/gu,"").toLowerCase();return b?b||`${s}-${Math.random().toString(36).slice(2,8)}`:u?`${s}-${u}`:`${s}-${Math.random().toString(36).slice(2,8)}`};function Ce({visibility:t,children:s,selectRef:i,onAnimationDone:u,unmount:b=!0,duration:a,easing:y,offset:R,animateOpacity:v}){const k=o.useRef(null),[D,I]=o.useState(0);o.useEffect(()=>{if(!i?.current)return;I(i.current.offsetHeight);const W=new ResizeObserver(F=>{for(let Y of F)I(Y.target.offsetHeight)});return W.observe(i.current),()=>W.disconnect()},[i]);const A=`height ${a}ms ${y}${v?`, opacity ${a}ms ${y}`:""}`,C={position:"absolute",top:`calc(100% + ${R}px)`,left:"0",width:"100%",overflow:"hidden",marginTop:"2px",zIndex:"1",height:t?"auto":"0px",opacity:t?1:0,pointerEvents:t?"all":"none",visibility:D?"visible":"hidden"},P=o.useCallback(()=>{const d=k.current;d&&(d.style.height="0px",v&&(d.style.opacity="0"),d.style.transition="")},[v]),f=o.useCallback(()=>{const d=k.current;d&&(d.style.transition=A,d.style.height=`${d.scrollHeight}px`,v&&(d.style.opacity="1"))},[A,v]),w=o.useCallback(()=>{const d=k.current;d&&(d.style.height="auto",d.style.transition="",u&&u())},[u]),x=o.useCallback(()=>{const d=k.current;d&&(d.style.height=`${d.scrollHeight}px`,v&&(d.style.opacity="1"),d.offsetHeight,d.style.transition=A)},[A,v]),N=o.useCallback(()=>{const d=k.current;d&&(d.style.height="0px",v&&(d.style.opacity="0"))},[v]),$=o.useCallback(()=>{const d=k.current;d&&(d.style.transition="")},[]);return m.jsx(pe.CSSTransition,{in:t,timeout:a,classNames:"rac-options",unmountOnExit:b,nodeRef:k,onEnter:P,onEntering:f,onEntered:w,onExit:x,onExiting:N,onExited:$,children:m.jsx("div",{ref:k,className:"rac-options",style:C,children:s})})}const Ne=o.memo(Ce,(t,s)=>t.visibility===s.visibility&&t.duration===s.duration&&t.easing===s.easing&&t.offset===s.offset&&t.animateOpacity===s.animateOpacity&&t.selectRef===s.selectRef&&t.children===s.children);function ne({visibility:t,children:s,duration:i=300,unmount:u,style:b}){const a=o.useRef(null);return m.jsx(pe.CSSTransition,{in:t,timeout:i,classNames:"rac-slide-left",unmountOnExit:!0,nodeRef:a,onEnter:()=>a.current.style.width="0px",onEntering:()=>a.current.style.width=a.current.scrollWidth+"px",onEntered:()=>a.current.style.width="auto",onExit:()=>a.current.style.width=a.current.scrollWidth+"px",onExiting:()=>a.current.style.width="0px",onExited:()=>u?.(),children:m.jsx("div",{ref:a,style:{...b,overflow:"hidden",transition:`width ${i}ms ease`},children:s})})}const be=(t,s)=>{if(!t)return null;if(typeof t=="string")return m.jsx("img",{src:t,...s,alt:""});if(o.isValidElement(t))return o.cloneElement(t,s);if(typeof t=="function"||typeof t=="object"&&t.$$typeof){const i=t;return m.jsx(i,{...s})}return null},Oe=o.forwardRef(({unmount:t,children:s,renderedDropdown:i,visibility:u,ownBehavior:b=!1,alwaysOpen:a=!1,duration:y=300,easing:R="ease-out",offset:v=2,animateOpacity:k=!0,style:D={},className:I="",ArrowIcon:A=Se,ClearIcon:C=Re,...P},f)=>{const w=o.useId(),x=o.useMemo(()=>w.replace(/:/g,""),[w]),[N,$]=o.useState([]),d=o.useCallback(p=>{$(M=>[...M,p])},[]),W=o.useCallback(p=>{$(M=>M.filter(q=>q.id!==p))},[]),F=o.useRef(null);o.useEffect(()=>{f&&(typeof f=="function"?f(F.current):f.current=F.current)},[f]),o.useImperativeHandle(f,()=>F.current);const[Y,G]=o.useState(!1),_=o.useMemo(()=>a?!0:b?!!u:Y,[a,b,u,Y]),V=o.useCallback(p=>{a||b||G(M=>typeof p=="function"?p(M):p)},[a,b]),{normalizedOptions:L,selected:S,selectOption:H,clear:K,hasOptions:O,active:r,selectedValue:h,disabled:n,loading:l,error:E,placeholder:e,invalidOption:c,options:g,value:T,defaultValue:U,isControlled:X,emptyText:j,disabledText:z,loadingText:B,errorText:te}=Ae({...P,setVisibility:V,jsxOptions:N}),{handleBlur:ge,handleFocus:me,handleToggle:ye,handleKeyDown:xe,highlightedIndex:Z,setHighlightedIndex:Ee}=$e({disabled:n,isOpen:_,setIsOpen:V,options:L,selectOption:H,selected:S}),[le,ie]=o.useState(!1);o.useEffect(()=>{_||ie(!1)},[_]),o.useEffect(()=>{(E||n||l||!O)&&V(!1)},[E,n,l,O]),o.useEffect(()=>{if(_&&le&&Z!==-1){const p=L[Z];if(p){const M=`opt-${x}-${oe(p.id)}`,q=document.getElementById(M);q&&q.scrollIntoView({block:"nearest"})}}},[Z,_,le,L,x]);const ae=h!=null&&!(Array.isArray(h)&&h.length===0)&&!(typeof h=="object"&&Object.keys(h).length===0),ce=o.useMemo(()=>{if(E)return te;if(l)return B;if(n)return z;if(S)return S.jsx??S.name;if(ae){const p=L.find(M=>M.raw===h);return p?p.name:typeof h=="object"&&h!==null?h.name??h.label??"Selected Object":String(h)}return O?e:j},[n,l,E,O,S,h,e,te,B,z,j]),ve=`${x}-listbox`,we=o.useMemo(()=>L?.map((p,M)=>{const q=`opt-${x}-${oe(p.id)}`;let J="rac-select-option";return p.className&&(J+=` ${p.className}`),S?.id===p.id&&(J+=" rac-selected"),M===Z&&(J+=" rac-highlighted"),p.disabled&&(J+=" rac-disabled-option"),typeof p.raw=="boolean"&&(J+=p.raw?" rac-true-option":" rac-false-option"),p.name==c&&(J+=" rac-invalid-option"),m.jsx("div",{className:J,onClick:je=>H(p,je),onMouseEnter:()=>!p.disabled&&Ee(M),id:q,role:"option","aria-selected":S?.id===p.id,"aria-disabled":p.disabled,children:p.jsx??p.name},p.id)}),[L,H,x,S,Z]);return o.useEffect(()=>{process.env.NODE_ENV!=="production"&&(g&&typeof g!="object"&&console.error(`%c[Select Library]:%c Invalid prop %coptions%c.
|
|
7
|
-
Expected %cArray%c or %cObject%c, but received %c${typeof
|
|
8
|
-
`,"color: #ff4d4f; font-weight: bold;","color: default;","color: #1890ff; font-weight: bold;","color: default;","color: #52c41a; font-weight: bold;","color: default;","color: #52c41a; font-weight: bold;","color: default;","color: #ff4d4f; font-weight: bold;","color: default;"),
|
|
9
|
-
`,"color: #faad14; font-weight: bold;","color: default;"))},[
|
|
10
|
-
${
|
|
11
|
-
${!
|
|
12
|
-
${
|
|
13
|
-
${
|
|
6
|
+
<%s key={someKey} {...props} />`,T,S,z,S),Y[S+T]=!0)}if(S=null,y!==void 0&&(l(y),S=""+y),x(u)&&(l(u.key),S=""+u.key),"key"in u){y={};for(var X in u)X!=="key"&&(y[X]=u[X])}else y=u;return S&&_(y,typeof e=="function"?e.displayName||e.name||"Unknown":e),j(e,S,y,b(),q,B)}function O(e){C(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===I&&(e._payload.status==="fulfilled"?C(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function C(e){return typeof e=="object"&&e!==null&&e.$$typeof===N}var A=o,N=Symbol.for("react.transitional.element"),d=Symbol.for("react.portal"),w=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),F=Symbol.for("react.profiler"),P=Symbol.for("react.consumer"),f=Symbol.for("react.context"),H=Symbol.for("react.forward_ref"),k=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),K=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),J=Symbol.for("react.activity"),n=Symbol.for("react.client.reference"),h=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,$=Object.prototype.hasOwnProperty,V=Array.isArray,r=console.createTask?console.createTask:function(){return null};A={react_stack_bottom_frame:function(e){return e()}};var i,g={},R=A.react_stack_bottom_frame.bind(A,c)(),L=r(a(c)),Y={};ee.Fragment=w,ee.jsx=function(e,u,y){var T=1e4>h.recentlyCreatedOwnerStacks++;return M(e,u,y,!1,T?Error("react-stack-top-frame"):R,T?r(a(e)):L)},ee.jsxs=function(e,u,y){var T=1e4>h.recentlyCreatedOwnerStacks++;return M(e,u,y,!0,T?Error("react-stack-top-frame"):R,T?r(a(e)):L)}})()),ee}var de;function Te(){return de||(de=1,process.env.NODE_ENV==="production"?te.exports=je():te.exports=ke()),te.exports}var E=Te();const _e=({className:t="",...s})=>E.jsx("svg",{className:t,role:"button","aria-label":"Clear selection",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512",width:"1em",height:"1em",fill:"currentColor",...s,children:E.jsx("path",{d:"M310.6 361.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L160 301.3 54.6 406.6c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L114.7 256 9.4 150.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 210.7 265.4 105.4c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3L205.3 256l105.3 105.4z"})}),Re=({className:t="",...s})=>E.jsx("svg",{className:t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",width:"1em",height:"1em",fill:"currentColor",...s,children:E.jsx("path",{d:"M34.9 289.5l175.9-175.8c9.4-9.4 24.6-9.4 33.9 0L420.1 289.5c15.1 15.1 4.4 41-17 41H51.9c-21.4 0-32.1-25.9-17-41z"})}),he=o.createContext(null);function $e({disabled:t,isOpen:s,setIsOpen:l,options:a,selectOption:b,selected:c}){const x=o.useRef(!1),_=o.useRef(0),[m,j]=o.useState(-1);o.useEffect(()=>{const d=()=>{_.current=Date.now()};return window.addEventListener("focus",d),()=>window.removeEventListener("focus",d)},[]),o.useEffect(()=>{if(s){let d=-1;if(c){const w=a.findIndex(v=>v.id===c.id&&!v.disabled);w>=0&&(d=w)}d===-1&&(d=a.findIndex(w=>!w.disabled)),j(d)}else j(-1)},[s,c,a]);const M=o.useCallback(d=>{d.currentTarget.contains(d.relatedTarget)||l(!1)},[l]),O=o.useCallback(()=>{t||document.hidden||Date.now()-_.current<100||s||(l(!0),x.current=!0,setTimeout(()=>{x.current=!1},200))},[t,s,l]),C=o.useCallback(d=>{t||d.target.closest(".rac-select-cancel")||x.current||l(!s)},[t,s,l]),A=(d,w)=>{if(a.every(P=>P.disabled))return-1;let v=d,F=0;do v+=w,v<0&&(v=a.length-1),v>=a.length&&(v=0),F++;while(a[v]?.disabled&&F<=a.length);return v},N=o.useCallback(d=>{if(!t)switch(d.key){case"Enter":case" ":d.preventDefault(),s?m!==-1&&a[m]&&b(a[m],d):l(!0);break;case"Escape":d.preventDefault(),l(!1);break;case"ArrowDown":d.preventDefault(),s?j(w=>A(w,1)):l(!0);break;case"ArrowUp":d.preventDefault(),s?j(w=>A(w,-1)):l(!0);break;case"Tab":s&&l(!1);break}},[t,s,l,m,a,b]);return o.useMemo(()=>({handleBlur:M,handleFocus:O,handleToggle:C,handleKeyDown:N,highlightedIndex:m,setHighlightedIndex:j}),[M,O,C,N,m,j])}function Ae({options:t=[],jsxOptions:s=[],value:l,defaultValue:a=void 0,onChange:b,disabled:c=!1,loading:x=!1,error:_=!1,placeholder:m="Choose option",emptyText:j="No options",disabledText:M="Disabled",loadingText:O="Loading",errorText:C="Failed to load",disabledOption:A="Disabled option",emptyOption:N="Empty option",invalidOption:d="Invalid option",setVisibility:w}){const v=o.useId(),F=l!==void 0,[P,f]=o.useState(null),H=n=>!n||typeof n!="object"||Array.isArray(n)?!1:"id"in n||"value"in n||"name"in n||"label"in n||"disabled"in n,k=o.useMemo(()=>{const n=[],h=(r,i,g)=>{let R=g?.id??g?.value??i??r;if(typeof i=="function"){n.push({key:`invalid-${n.length}`,value:i,userId:null,disabled:!0,isInvalid:!0,label:d,original:g});return}if(i===""){n.push({key:`empty-str-${n.length}`,value:"",userId:null,disabled:!0,label:N,original:g});return}if(i==null){n.push({key:`empty-${n.length}`,value:null,userId:null,disabled:!0,label:N,original:g});return}if(typeof i=="number"||typeof i=="boolean"){n.push({key:`${typeof i}-${i}-${n.length}`,value:i,userId:R,label:String(i),original:g});return}i&&typeof i=="object"&&!Array.isArray(i)?n.push({key:i.id??i.value??i.name??r??`obj-${n.length}`,value:i,userId:R,disabled:!!i.disabled,label:i.name??i.label??String(r),original:g}):n.push({key:r??`opt-${n.length}`,value:i,userId:R,label:String(i??r),original:g})};Array.isArray(t)?t.forEach((r,i)=>{if(r&&typeof r=="object"&&Object.keys(r).length===1&&r.disabled===!0)n.push({key:`dis-${i}`,value:null,userId:null,disabled:!0,label:A,original:r});else if(H(r)){const g=r.id??(typeof r.value!="object"?r.value:r.label??r.name??r.value);n.push({key:r.id??r.value??r.name??`opt-${i}`,value:r.value!==void 0?r.value:r.id!==void 0?r.id:r,userId:g,disabled:!!r.disabled,label:r.name??r.label??String(r.id??r.value),original:r})}else r&&typeof r=="object"&&!Array.isArray(r)?Object.entries(r).forEach(([g,R])=>h(g,R,R)):h(r,r,r)}):typeof t=="object"&&t!==null&&Object.entries(t).forEach(([r,i])=>h(r,i,i));const $=n.map((r,i)=>({id:`${v}-opt-${i}`,userId:r.userId,name:String(r.label),raw:r.value,original:r.original,disabled:r.disabled,isInvalid:r.isInvalid,type:typeof r.value=="boolean"?"boolean":"normal"})),V=s.map((r,i)=>({...r,id:`jsx-${v.replace(/:/g,"")}-${r.id}-${i}`,userId:r.id,raw:r.value,original:r.value,name:r.label,type:typeof r.value=="boolean"?"boolean":"normal"}));return[...$,...V]},[t,s,v,N,A]),W=o.useCallback(n=>{if(n==null)return null;const h=k.find($=>$.original===n||$.raw===n);if(h)return h.id;if(typeof n=="object")try{const $=JSON.stringify(n),V=k.find(r=>r.original&&typeof r.original=="object"&&JSON.stringify(r.original)===$);if(V)return V.id}catch{}return k.find($=>$.userId===n)?.id??null},[k]);o.useEffect(()=>{const n=F?l:a,h=k.find(V=>V.id===P);h&&(h.original===n||h.raw===n||h.userId===n)||f(W(n))},[l,a,F,k,W]);const K=o.useMemo(()=>k.find(n=>n.id===P)??null,[P,k]),I=o.useCallback((n,h)=>{if(n.disabled){h?.stopPropagation(),h?.preventDefault();return}f(n.id),b?.(n.original,n.userId),w(!1)},[b,w]),J=o.useCallback(n=>{n.preventDefault(),n.stopPropagation(),f(null),b?.(null,null)},[b]);return{normalizedOptions:k,selected:K,selectOption:I,clear:J,hasOptions:k.length>0,active:!_&&!x&&!c&&k.length>0,selectedValue:l??a,placeholder:m,emptyText:j,disabledText:M,loadingText:O,errorText:C,disabledOption:A,emptyOption:N,invalidOption:d,disabled:c,loading:x,error:_}}const oe=(t,s="invalid-option",l="")=>{const a=l?l.replace(/:/g,""):"";if(typeof t!="string"||!t.trim())return a?`${s}-${a}`:`${s}-${Math.random().toString(36).slice(2,8)}`;const b=t.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").replace(/\s+/g,"-").replace(/[^\p{L}\p{N}-]+/gu,"").toLowerCase();return b?b||`${s}-${Math.random().toString(36).slice(2,8)}`:a?`${s}-${a}`:`${s}-${Math.random().toString(36).slice(2,8)}`};function Ce({visibility:t,children:s,selectRef:l,onAnimationDone:a,unmount:b=!0,duration:c,easing:x,offset:_,animateOpacity:m}){const j=o.useRef(null),[M,O]=o.useState(0);o.useEffect(()=>{if(!l?.current)return;O(l.current.offsetHeight);const H=new ResizeObserver(k=>{for(let W of k)O(W.target.offsetHeight)});return H.observe(l.current),()=>H.disconnect()},[l]);const C=`height ${c}ms ${x}${m?`, opacity ${c}ms ${x}`:""}`,A={position:"absolute",top:`calc(100% + ${_}px)`,left:"0",width:"100%",overflow:"hidden",marginTop:"2px",zIndex:"1",height:t?"auto":"0px",opacity:m?t?1:0:1,pointerEvents:t?"all":"none",visibility:M?"visible":"hidden"},N=o.useCallback(()=>{const f=j.current;f&&(f.style.height="0px",m&&(f.style.opacity="0"),f.style.transition="")},[m]),d=o.useCallback(()=>{const f=j.current;f&&(f.style.transition=C,f.style.height=`${f.scrollHeight}px`,m&&(f.style.opacity="1"))},[C,m]),w=o.useCallback(()=>{const f=j.current;f&&(f.style.height="auto",f.style.transition="",a&&a())},[a]),v=o.useCallback(()=>{const f=j.current;f&&(f.style.height=`${f.scrollHeight}px`,m&&(f.style.opacity="1"),f.offsetHeight,f.style.transition=C)},[C,m]),F=o.useCallback(()=>{const f=j.current;f&&(f.style.height="0px",m&&(f.style.opacity="0"))},[m]),P=o.useCallback(()=>{const f=j.current;f&&(f.style.transition="")},[]);return E.jsx(pe.CSSTransition,{in:t,timeout:c,classNames:"rac-options",unmountOnExit:b,nodeRef:j,onEnter:N,onEntering:d,onEntered:w,onExit:v,onExiting:F,onExited:P,children:E.jsx("div",{ref:j,className:"rac-options",style:A,children:s})})}const Ne=o.memo(Ce,(t,s)=>t.visibility===s.visibility&&t.duration===s.duration&&t.easing===s.easing&&t.offset===s.offset&&t.animateOpacity===s.animateOpacity&&t.selectRef===s.selectRef&&t.children===s.children);function ne({visibility:t,children:s,duration:l=300,unmount:a,style:b}){const c=o.useRef(null);return E.jsx(pe.CSSTransition,{in:t,timeout:l,classNames:"rac-slide-left",unmountOnExit:!0,nodeRef:c,onEnter:()=>c.current.style.width="0px",onEntering:()=>c.current.style.width=c.current.scrollWidth+"px",onEntered:()=>c.current.style.width="auto",onExit:()=>c.current.style.width=c.current.scrollWidth+"px",onExiting:()=>c.current.style.width="0px",onExited:()=>a?.(),children:E.jsx("div",{ref:c,style:{...b,overflow:"hidden",transition:`width ${l}ms ease`},children:s})})}const be=(t,s)=>{if(!t)return null;if(typeof t=="string")return E.jsx("img",{src:t,...s,alt:""});if(o.isValidElement(t))return o.cloneElement(t,s);if(typeof t=="function"||typeof t=="object"&&t.$$typeof){const l=t;return E.jsx(l,{...s})}return null},Ie=o.forwardRef(({unmount:t,children:s,renderedDropdown:l,visibility:a,ownBehavior:b=!1,alwaysOpen:c=!1,duration:x=300,easing:_="ease-out",offset:m=2,animateOpacity:j=!0,style:M={},className:O="",ArrowIcon:C=Re,ClearIcon:A=_e,...N},d)=>{const w=o.useId(),v=o.useMemo(()=>w.replace(/:/g,""),[w]),[F,P]=o.useState([]),f=o.useCallback(p=>{P(D=>[...D,p])},[]),H=o.useCallback(p=>{P(D=>D.filter(G=>G.id!==p))},[]),k=o.useRef(null);o.useEffect(()=>{d&&(typeof d=="function"?d(k.current):d.current=k.current)},[d]),o.useImperativeHandle(d,()=>k.current);const[W,K]=o.useState(!1),I=o.useMemo(()=>c?!0:b?!!a:W,[c,b,a,W]),J=o.useCallback(p=>{c||b||K(D=>typeof p=="function"?p(D):p)},[c,b]),{normalizedOptions:n,selected:h,selectOption:$,clear:V,hasOptions:r,active:i,selectedValue:g,disabled:R,loading:L,error:Y,placeholder:e,invalidOption:u,options:y,value:T,defaultValue:q,isControlled:B,emptyText:S,disabledText:z,loadingText:X,errorText:re}=Ae({...N,setVisibility:J,jsxOptions:F}),{handleBlur:ge,handleFocus:ye,handleToggle:Ee,handleKeyDown:xe,highlightedIndex:Z,setHighlightedIndex:ve}=$e({disabled:R,isOpen:I,setIsOpen:J,options:n,selectOption:$,selected:h}),[le,ae]=o.useState(!1);o.useEffect(()=>{I||ae(!1)},[I]),o.useEffect(()=>{(Y||R||L||!r)&&J(!1)},[Y,R,L,r]),o.useEffect(()=>{if(I&&le&&Z!==-1){const p=n[Z];if(p){const D=`opt-${v}-${oe(p.id)}`,G=document.getElementById(D);G&&G.scrollIntoView({block:"nearest"})}}},[Z,I,le,n,v]);const ie=g!=null&&!(Array.isArray(g)&&g.length===0)&&!(typeof g=="object"&&Object.keys(g).length===0),ce=o.useMemo(()=>{if(Y)return re;if(L)return X;if(R)return z;if(h)return h.jsx??h.name;if(ie){const p=n.find(D=>D.raw===g);return p?p.name:typeof g=="object"&&g!==null?g.name??g.label??"Selected Object":String(g)}return r?e:S},[R,L,Y,r,h,g,e,re,X,z,S]),me=`${v}-listbox`,we=o.useMemo(()=>n?.map((p,D)=>{const G=`opt-${v}-${oe(p.id)}`;let U="rac-select-option";return p.className&&(U+=` ${p.className}`),h?.id===p.id&&(U+=" rac-selected"),D===Z&&(U+=" rac-highlighted"),p.disabled&&(U+=" rac-disabled-option"),p.isInvalid&&(U+=" rac-invalid-option"),typeof p.raw=="boolean"&&(U+=p.raw?" rac-true-option":" rac-false-option"),p.name==u&&(U+=" rac-invalid-option"),E.jsx("div",{className:U,onClick:Se=>$(p,Se),onMouseEnter:()=>!p.disabled&&ve(D),id:G,role:"option","aria-selected":h?.id===p.id,"aria-disabled":p.disabled,children:p.jsx??p.name},p.id)}),[n,$,v,h,Z]);return o.useEffect(()=>{process.env.NODE_ENV!=="production"&&(y&&typeof y!="object"&&console.error(`%c[Select Library]:%c Invalid prop %coptions%c.
|
|
7
|
+
Expected %cArray%c or %cObject%c, but received %c${typeof y}%c.
|
|
8
|
+
`,"color: #ff4d4f; font-weight: bold;","color: default;","color: #1890ff; font-weight: bold;","color: default;","color: #52c41a; font-weight: bold;","color: default;","color: #52c41a; font-weight: bold;","color: default;","color: #ff4d4f; font-weight: bold;","color: default;"),B&&q!==void 0&&console.warn(`%c[Select Library]:%c .
|
|
9
|
+
`,"color: #faad14; font-weight: bold;","color: default;"))},[y,T,q,B]),E.jsxs(he.Provider,{value:{registerOption:f,unregisterOption:H},children:[s,l,E.jsxs("div",{style:{"--rac-duration":`${x}ms`,...M},className:`rac-select
|
|
10
|
+
${O}
|
|
11
|
+
${!r||R?"rac-disabled-style":""}
|
|
12
|
+
${L?"rac-loading-style":""}
|
|
13
|
+
${Y?"rac-error-style":""}`,tabIndex:i?0:-1,ref:k,role:"combobox","aria-haspopup":"listbox","aria-expanded":I,"aria-controls":me,"aria-label":e,"aria-disabled":R||!r,...i&&{onBlur:ge,onFocus:ye,onClick:Ee,onKeyDown:xe},children:[E.jsxs("div",{className:`rac-select-title ${!Y&&!L&&h?.type=="boolean"?h.raw?"rac-true-option":"rac-false-option":""}`,children:[E.jsx("span",{className:"rac-title-text",children:ce},ce),E.jsx(ne,{visibility:L&&!Y,duration:x,children:E.jsxs("span",{className:"rac-loading-dots",children:[E.jsx("i",{}),E.jsx("i",{}),E.jsx("i",{})]})})]}),E.jsxs("div",{className:"rac-select-buttons",children:[E.jsx(ne,{visibility:ie&&r&&!R&&!L&&!Y,duration:x,style:{display:"grid"},children:be(A,{className:"rac-select-cancel",onClick:p=>V(p)})}),E.jsx(ne,{visibility:i,duration:x,style:{display:"grid"},children:E.jsx("span",{className:`rac-select-arrow-wrapper ${I?"--open":""}`,children:be(C,{className:"rac-select-arrow-wrapper"})})})]}),E.jsx(Ne,{visibility:I,selectRef:k,onAnimationDone:()=>ae(!0),unmount:t,duration:x,easing:_,offset:m,animateOpacity:j,children:E.jsx("div",{className:"rac-select-list",role:"listbox","aria-label":"Options",children:we})})]})]})}),se=t=>t?typeof t=="string"||typeof t=="number"?String(t):Array.isArray(t)?t.map(se).join(" ").replace(/\s+/g," ").trim():o.isValidElement(t)?se(t.props.children):"":"";function Oe({value:t,id:s,className:l,children:a,disabled:b}){const c=o.useContext(he);return o.useEffect(()=>{if(!c)return;const x=se(a),_={id:String(s??oe(String(x))),value:t!==void 0?t:x,label:typeof a=="string"?a:String(t??s),jsx:a,className:l,disabled:!!b};return c.registerOption(_),()=>c.unregisterOption(_.id)},[s,t,a,l,b]),null}exports.Option=Oe;exports.Select=Ie;
|