Build 576754stable
Module 540637
4,364 characters · in no known chunkDependencies
Source Raw
function(e,t,n){"use strict";n.d(t,{l:()=>R,q:()=>N});var i=n(627968),r=n(64700),a=n(503698),s=n.n(a),l=n(887129),o=n(602034),d=n(837381),c=n(661531),u=n(658675),_=n(820081),E=n(475825),A=n(289873),h=n(834730),I=n(992251),f=n(801461),p=n(767216),T=n(729232);let m=c.A.modules.select.OPTION_HEIGHT.resolve(),g=m+4;function S(e){return null!=e.description&&""!==e.description}function N(e){let t,{id:n,tabIndex:a=0,required:c=!1,disabled:u=!1,selectionMode:_="single",items:p,groups:N=[],defaultSelectedItems:O,selectedItems:L,onSelectionChange:D,activeDescendantIndex:y,shouldFocusWrap:v=!1,renderListItem:b,renderEmptyState:M,maxVisibleItems:P=5,loading:U=!1,onBlur:w,onFocus:G,typeahead:x=!1}=e,k=r.useId(),F=n??k,V=r.useRef(null),B=r.useMemo(()=>p.map((e,t)=>({...e,index:t})),[p]),[H,j]=r.useState(O??[]),W=null!=L,Y=W?L:H,K=(0,l.Ay)({id:F,defaultFocused:null!=y?(0,f.ZN)(F,y):void 0,async scrollToEnd(){},async scrollToStart(){},isEnabled:!u,wrap:v,preserveFocusPosition:!1,useVirtualFocus:-1===a});r.useEffect(()=>{requestAnimationFrame(()=>{if(null!=y){let[e,t]=(0,f.LE)(N,y);V.current?.scrollToIndex({section:e,row:t})}})},[F,y,N]);let{activeIndex:$,handleKeyDown:z}=R(x,B);r.useEffect(()=>{if(null!=$&&x&&-1!==a){let e=(0,o.t$)(F,(0,f.ZN)(F,$)),t=document.querySelector((0,o.Mz)(e));t?.focus()}},[$,B,x,F,a]);let q=r.useCallback((e,t)=>S(B[(0,f.rp)(N,e,t)])?g:m,[B,N]),Z=r.useCallback(e=>{if(!0===c&&1===Y.length&&Y.includes(e))return;let t=(0,f.qH)(_,Y,e);W||j(t),D?.(t)},[c,Y,D,W,_]),X=r.useCallback((e,t)=>{let{label:n,description:r}=e,a=S(e);return(0,i.jsxs)("div",{className:T.uN,"data-has-description":a||void 0,children:[(0,i.jsx)(h.E,{variant:"text-md/medium",color:"currentColor",className:T.vF,children:n}),a&&(0,i.jsx)(h.E,{id:t,variant:"text-sm/normal",color:"text-subtle",lineClamp:1,className:T.vL,children:r})]})},[]);if(U)t=(0,i.jsx)("div",{className:T.vG,"aria-busy":!0,children:(0,i.jsx)(A.y,{type:A.t.PULSING_ELLIPSIS,className:T.S,itemClassName:T.Ci})});else if(B.length>0){let e=N.length>0;t=(0,i.jsx)(E.Ei,{ref:V,style:{height:null!=P?`${B.slice(0,P).reduce((e,t)=>e+(S(t)?g:m),0)+26*function(e,t){let n=0,i=0;for(let r of e)i<t&&n++,i+=r.count;return n}(N,P)}px`:"100%"},role:void 0,tabIndex:a,rowHeight:q,sections:e?N.map(e=>e.count):[B.length],sectionHeight:26*!!e,renderSection:e?e=>{let{section:t}=e;return(0,i.jsx)(h.E,{"aria-hidden":!0,variant:"text-sm/semibold",color:"text-muted",className:T.SG,children:N[t].label},`section-${t}`)}:()=>null,wrapSection:e?(e,t)=>(0,i.jsx)("div",{role:"group","aria-label":N[e].label,children:t},`section-group-${e}`):void 0,renderRow:e=>{let{rowIndex:t}=e,n=B[t],r=(0,f.ZN)(F,t),s=null==b&&S(n)?`${r}-desc`:void 0,l=0!==Y.length&&null!=Y.find(e=>e.id===n.id);return(0,i.jsx)(C,{...n,id:r,descriptionId:s,tabIndex:a,selectionMode:_,selected:l,disabled:u||n.disabled,focused:t===y,onClick:()=>{u||n.disabled||Z(n)},children:b?.(n,s)??X(n,s)},n.index)}})}else t=M?.()??(0,i.jsx)(I.o,{});return(0,i.jsx)(d.hD,{navigator:K,children:(0,i.jsx)(d.PR,{children:e=>{let{ref:n,onKeyDown:r,...l}=e;return(0,i.jsx)("div",{onBlur:w,onFocus:G,"aria-busy":U,ref:n,onKeyDown:e=>{r?.(e),z(e)},...l,role:"listbox",tabIndex:a,"aria-multiselectable":"multiple"===_,className:s()(T.cu,{[T.E1]:B.length>P}),"data-mana-component":"listbox",children:t})}})})}function C(e){let{children:t,id:n,descriptionId:r,tabIndex:a,selected:l,disabled:o,focused:c,selectionMode:E,onClick:A}=e,h=(0,d.rm)(n);return(0,i.jsxs)("div",{...h,id:n,className:s()(T.Vu,p.nM),role:"option",tabIndex:-1===a?-1:h.tabIndex,onClick:A,"aria-disabled":o,"aria-selected":l,"aria-describedby":r,"data-focus-visible":c,"data-marquee-active":c,children:[t,(0,i.jsx)("div",{className:T.Dt,"aria-hidden":!0,children:"multiple"===E?(0,i.jsx)(u.P,{checked:l}):l?(0,i.jsx)(_.B,{color:"currentColor",size:"refresh_sm"}):null})]})}function R(e,t){let[n,i]=r.useState(""),a=r.useMemo(()=>e?t.map(e=>null!=e.label&&"function"==typeof e.label.toLowerCase?e.label.toLowerCase():""):[],[t,e]),s=r.useCallback(e=>{e.metaKey||e.ctrlKey||e.altKey||e.shiftKey||e.key.length>1||i(t=>t+e.key)},[]),l=r.useRef(null);return r.useEffect(()=>(l.current=setTimeout(()=>{i("")},750),()=>{clearTimeout(l.current)}),[n]),{activeIndex:r.useMemo(()=>{if(""===n||!e)return null;let t=a.findIndex(e=>e.startsWith(n.toLowerCase()));return t>=0?t:null},[a,n,e]),handleKeyDown:s}}}