unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
5 lines (4 loc) ⢠27.7 kB
JavaScript
import{s as p,bk as w,e as B,j as o,W,y as q,D as Q,dC as L,B as S,dG as ne,au as me,di as fe,ax as pe,C as I,aI as ge,ay as xe,aH as Y,b_ as U,bA as be,eu as ye,bp as ve,iM as Ce,L as oe,el as je,at as R,ga as P,r as m,em as D,aE as Te,G as Ee,H as Se,as as J,fk as we,aw as _,ea as Ie,eC as ke,al as O,am as Ae,cu as ie,bc as Oe,b5 as re,h as Me,w as Re,b0 as ze,i as De,aJ as le,iN as M,dQ as _e,hM as X,dP as Ne,T as F,e4 as Le,F as Pe,f3 as Fe,e1 as Be,f4 as We,gO as Ue,ca as $e,bh as ae,bj as ce,bi as He,iO as Ge,A as Ke,bB as Ve,bd as qe,dZ as Qe}from"./index-DEkgmbaI.js";import{u as Ye}from"./useApiTokens-DuYwQsyc.js";const Je=p("div")(({theme:n})=>({display:"grid",gridTemplateColumns:"auto auto 1fr",gridAutoRows:"min-content",alignItems:"center",gap:n.spacing(1),marginTop:n.spacing(1.5)})),T=S,Xe=()=>{const{uiConfig:n}=w(),{setToastData:r}=B(),e=i=>()=>{ne(i),r({type:"success",text:"Copied to clipboard"})},s=`${n.unleashUrl}/api/`,t=`${n.unleashUrl}/api/frontend/`;return o.jsxs(W,{severity:"info",children:[o.jsxs("p",{children:["Read the"," ",o.jsx("a",{href:"https://docs.getunleash.io/reference/sdks",target:"_blank",rel:"noreferrer",children:"SDK overview"})," ","to connect Unleash to your application. Please note it can take up to ",o.jsx("strong",{children:"1 minute"})," before a new API key is activated."]}),o.jsxs(Je,{children:[o.jsx(T,{children:o.jsx("strong",{children:"CLIENT API URL: "})}),o.jsx(T,{children:o.jsx("pre",{style:{display:"inline"},children:s})}),o.jsx(T,{children:o.jsx(q,{title:"Copy URL",arrow:!0,children:o.jsx(Q,{onClick:e(s),size:"small",children:o.jsx(L,{})})})}),o.jsx(T,{children:o.jsx("strong",{children:"FRONTEND API URL: "})}),o.jsx(T,{children:o.jsx("pre",{style:{display:"inline"},children:t})}),o.jsx(T,{children:o.jsx(q,{title:"Copy URL",arrow:!0,children:o.jsx(Q,{onClick:e(t),size:"small",children:o.jsx(L,{})})})})]})]})},Ze=["Icon","createdAt","seenAt"],et=["Icon","project","seenAt"],$t=({compact:n=!1,setHiddenColumns:r,columns:e,loading:s,rows:t,headerGroups:i,globalFilter:l,prepareRow:a})=>{const c=me(fe.breakpoints.down("xl"));return pe([{condition:c,columns:Ze},{condition:n,columns:et}],r,e),o.jsxs(o.Fragment,{children:[o.jsx(I,{condition:t.length>0,show:o.jsx(S,{sx:{mb:4},children:o.jsx(Xe,{})})}),o.jsx(S,{sx:{overflowX:"auto"},children:o.jsx(ge,{value:l,children:o.jsx(xe,{rows:t,headerGroups:i,prepareRow:a})})}),o.jsx(I,{condition:t.length===0&&!s,show:o.jsx(I,{condition:(l==null?void 0:l.length)>0,show:o.jsxs(Y,{children:["No tokens found matching ā",l,"ā"]}),elseShow:o.jsx(Y,{children:o.jsxs("span",{children:["No tokens available. Read ",o.jsx(U,{href:"https://docs.getunleash.io/how-to/api",target:"_blank",rel:"noreferrer",children:"API How-to guides"})," "," to learn more."]})})})})]})},tt=(n,r)=>{const e=r>=n;return{limitReached:e,limitMessage:e?`You have reached the limit of ${n} API tokens`:void 0}},Ht=({path:n,permission:r,project:e})=>{const s=be(),{tokens:t,loading:i}=Ye(),{uiConfig:l}=w(),{limitReached:a,limitMessage:c}=tt(l.resourceLimits.apiTokens,t.length);return o.jsx(ye,{Icon:ve,onClick:()=>s(n),"data-testid":Ce,permission:r,projectId:e,maxWidth:"700px",disabled:i||a,tooltipProps:{title:c},children:"New API token"})},st=p(oe)(({theme:n})=>({textDecoration:"none",color:n.palette.links,"&:hover, &:focus":{textDecoration:"underline"}})),nt=p("div")({display:"flex",alignItems:"center"}),ot=({projects:n,project:r})=>{const{searchQuery:e}=je(),s=n&&Array.isArray(n)&&n.length>1?n:[];if(s.length>0)return o.jsx(R,{children:o.jsx(P,{title:s.map((t,i)=>o.jsxs(m.Fragment,{children:[i>0&&", ",!t||t==="*"?o.jsx(D,{search:e,children:"*"}):o.jsx(st,{to:`/projects/${t}`,children:o.jsx(D,{search:e,children:t})})]},t)),placement:"bottom-start",arrow:!0,tabIndex:0,children:o.jsxs("span",{children:[`${s.length}`," projects"]})})});if(s.length===1&&s[0]!=="*"||r&&r!=="*"){const t=r||s[0];return o.jsx(Te,{to:`/projects/${t}`,title:t})}return o.jsx(R,{children:o.jsx(P,{title:"ALL current and future projects.",placement:"bottom",arrow:!0,children:o.jsx(nt,{children:o.jsx(D,{search:e,children:"*"})})})})};var $={},it=Se;Object.defineProperty($,"__esModule",{value:!0});var de=$.default=void 0,rt=it(Ee()),lt=o,at=(0,rt.default)((0,lt.jsx)("path",{d:"M21 10h-8.35C11.83 7.67 9.61 6 7 6c-3.31 0-6 2.69-6 6s2.69 6 6 6c2.61 0 4.83-1.67 5.65-4H13l2 2 2-2 2 2 4-4.04L21 10zM7 15c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z"}),"Key");de=$.default=at;const ct=({secret:n,project:r,projects:e})=>{const s=n!=null&&n.includes(":")?"v2":"v1",t=n==null?void 0:n.startsWith("*:"),i=e&&(e==null?void 0:e.length)>1||(e==null?void 0:e.length)===1&&e[0]!=="*"||r&&r!=="*";return s==="v2"&&!t&&!i},dt=({...n})=>ct(n)?o.jsx(J,{icon:o.jsx(P,{title:o.jsxs("p",{children:["This is an orphaned token. All of its original projects have been deleted and it now has access to all current and future projects. You should stop using this token and delete it. Read more in"," ",o.jsx(U,{target:"_blank",rel:"noopener noreferrer",href:"https://github.com/Unleash/unleash/releases/tag/v6.1.0",children:"release notes"}),"."]}),placement:"bottom-start",arrow:!0,children:o.jsx(we,{"aria-label":"Orphaned token",color:"warning","data-testid":"orphaned-token-icon"})})}):o.jsx(J,{icon:o.jsx(de,{color:"disabled"})}),Gt=(n,r)=>{const e=m.useMemo(()=>({sortBy:[{id:"createdAt",desc:!0}]}),[]),s=m.useMemo(()=>[{id:"Icon",Cell:u=>o.jsx(dt,{secret:u.row.original.secret,project:u.row.original.project,projects:u.row.original.projects}),disableSortBy:!0,disableGlobalFilter:!0,width:50},{Header:"Token name",accessor:"tokenName",Cell:_,minWidth:35},{Header:"Type",accessor:"type",Cell:({value:u})=>o.jsx(_,{value:Z[u.toLowerCase()].label,subtitle:Z[u.toLowerCase()].title,subtitleTooltip:!0}),width:180},{Header:"Project",accessor:"project",Cell:u=>o.jsx(ot,{project:u.row.original.project,projects:u.row.original.projects}),width:160},{Header:"Environment",accessor:"environment",Cell:_,width:120},{Header:"Created",accessor:"createdAt",Cell:Ie,width:150,disableGlobalFilter:!0},{Header:"Last seen",accessor:"seenAt",Cell:ke,width:140,disableGlobalFilter:!0},{Header:"Actions",width:120,id:"Actions",align:"center",disableSortBy:!0,disableGlobalFilter:!0,Cell:r}],[]),{getTableProps:t,getTableBodyProps:i,headerGroups:l,rows:a,prepareRow:c,state:d,setGlobalFilter:h,setHiddenColumns:y}=O.useTable({columns:s,data:n,initialState:e,sortTypes:Ae,autoResetHiddenColumns:!1,disableSortRemove:!0},O.useGlobalFilter,O.useSortBy,O.useFlexLayout);return{getTableProps:t,getTableBodyProps:i,headerGroups:l,rows:a,prepareRow:c,state:d,setGlobalFilter:h,setHiddenColumns:y,columns:s}},Z={client:{label:"CLIENT",title:"Connect server-side SDK or Unleash Proxy/Edge"},frontend:{label:"FRONTEND",title:"Connect web and mobile SDK"},admin:{label:"ADMIN",title:"Full access for managing Unleash"}},Kt=({token:n,project:r,permission:e,track:s})=>{const{setToastData:t}=B(),i=l=>{ne(l)&&(t({type:"success",text:"Token copied to clipboard"}),s&&typeof s=="function"&&s())};return o.jsx(ie,{permission:e,projectId:r,tooltipProps:{title:"Copy token",arrow:!0},onClick:()=>i(n.secret),size:"large",children:o.jsx(L,{})})},ht=p("ul")({marginBottom:0}),Vt=({token:n,permission:r,onRemove:e,project:s})=>{const[t,i]=m.useState(!1),{setToastData:l,setToastApiError:a}=B(),c=async()=>{try{await e(),i(!1),l({type:"success",text:"API token removed"})}catch(d){a(Me(d))}};return o.jsxs(o.Fragment,{children:[o.jsx(ie,{permission:r,projectId:s,tooltipProps:{title:"Delete token",arrow:!0},onClick:()=>i(!0),size:"large",children:o.jsx(Oe,{})}),o.jsx(re,{open:t,onClick:c,onClose:()=>i(!1),title:"Confirm deletion",children:o.jsxs("div",{children:["Are you sure you want to delete the following API token?",o.jsx("br",{}),o.jsxs(ht,{children:[o.jsxs("li",{children:[o.jsx("strong",{children:"name"}),":"," ",o.jsx("code",{children:n.tokenName})]}),o.jsxs("li",{children:[o.jsx("strong",{children:"type"}),": ",o.jsx("code",{children:n.type})]}),o.jsxs("li",{children:[o.jsx("strong",{children:"environment"}),":"," ",o.jsx("code",{children:n.environment})]})]})]})})]})},ut=p("div")(()=>({maxWidth:"400px"})),mt=p("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ft=p(Re)(({theme:n})=>({width:"100%",marginBottom:n.spacing(2)})),pt=p(ze)(({theme:n})=>({marginBottom:n.spacing(2),minWidth:"400px",[n.breakpoints.down("sm")]:{minWidth:"379px"}})),he=p("p")(({theme:n})=>({marginBottom:n.spacing(1)})),gt=p("label")(({theme:n})=>({marginBottom:n.spacing(1)})),xt=p(De)(({theme:n})=>({marginLeft:n.spacing(3)})),bt=p(S)({marginTop:"auto",display:"flex",justifyContent:"flex-end"}),qt=({children:n,actions:r,handleSubmit:e,handleCancel:s})=>{var l;const{uiConfig:t}=w(),i=!!((l=t==null?void 0:t.flags)!=null&&l.UNLEASH_CLOUD);return o.jsxs(mt,{onSubmit:e,children:[o.jsx(I,{condition:i,show:o.jsxs(W,{severity:"info",sx:{mb:4},children:["Please be aware of our"," ",o.jsx(U,{href:"https://www.getunleash.io/fair-use-policy",children:"fair use policy"}),"."]})}),n,o.jsxs(bt,{children:[r,o.jsx(xt,{onClick:s,children:"Cancel"})]})]})};var x=(n=>(n.ADMIN="ADMIN",n.CLIENT="CLIENT",n.FRONTEND="FRONTEND",n))(x||{});const Qt=n=>{var G,K;const{environments:r}=le(),{uiConfig:e}=w(),s=(G=r==null?void 0:r.find(f=>f.enabled))==null?void 0:G.name,t=M(_e),i=M(X,n),l=[{key:x.CLIENT,label:`Server-side SDK (${x.CLIENT})`,title:"Connect server-side SDK or Unleash Proxy/Edge",enabled:t||i}],a=M(Ne),c=M(X,n);e.flags.embedProxyFrontend&&l.splice(1,0,{key:x.FRONTEND,label:`Client-side SDK (${x.FRONTEND})`,title:"Connect web and mobile SDK directly to Unleash",enabled:a||c});const d=(K=l.find(f=>f.enabled))==null?void 0:K.key,[h,y]=m.useState(""),[u,v]=m.useState(d||x.CLIENT),[g,C]=m.useState([n||"*"]),[j,b]=m.useState(g),[k,A]=m.useState(),[H,z]=m.useState({});return m.useEffect(()=>{A(u==="ADMIN"?"*":s)},[u,s]),{username:h,type:u,apiTokenTypes:l,projects:g,environment:k,setUsername:y,setTokenType:f=>{f==="ADMIN"?(v(x.ADMIN),b(g),C(["*"]),A("*")):(v(f),C(j),A(s))},setProjects:C,setEnvironment:A,getApiTokenPayload:()=>({username:h,type:u,environment:k,projects:g}),isValid:()=>{const f={};return h||(f.username="Username is required"),g.length===0&&(f.projects="At least one project is required"),z(f),Object.keys(f).length===0},clearErrors:f=>{if(f){const V={...H};delete V[f],z(V)}else z({})},errors:H}},Yt=({open:n,setOpen:r,closeConfirm:e,token:s,type:t})=>o.jsxs(re,{open:n,setOpen:r,onClick:e,primaryButtonText:"Close",title:"New token created",children:[o.jsx(F,{variant:"body1",children:"Your new token has been created successfully."}),o.jsx(Le,{token:s}),o.jsx(I,{condition:t===x.FRONTEND,show:o.jsxs(W,{sx:{mt:2},severity:"info",children:["By default, all ",x.FRONTEND," tokens may be used from any CORS origin. If you'd like to configure a strict set of origins, please use the"," ",o.jsx(oe,{to:"/admin/cors",target:"_blank",rel:"noreferrer",children:"CORS origins configuration page"}),"."]})})]}),Jt=({username:n,setUsername:r,errors:e,clearErrors:s})=>o.jsxs(o.Fragment,{children:[o.jsx(he,{children:"What would you like to call this token?"}),o.jsx(ft,{value:n,name:"username",onChange:t=>r(t.target.value),label:"Token name",error:e.username!==void 0,errorText:e.username,onFocus:()=>s("username"),autoFocus:!0})]}),Xt=({type:n,setType:r,apiTokenTypes:e})=>o.jsx(ut,{children:o.jsxs(Pe,{sx:{mb:2,width:"100%"},children:[o.jsx(gt,{id:"token-type",children:"What do you want to connect?"}),o.jsx(Fe,{"aria-labelledby":"token-type",defaultValue:"CLIENT",name:"radio-buttons-group",value:n,onChange:(s,t)=>r(t),children:e.map(({key:s,label:t,title:i,enabled:l})=>o.jsx(Be,{value:s,sx:{mb:1},disabled:!l,control:o.jsx(We,{sx:{ml:.75,alignSelf:"flex-start"}}),label:o.jsx(S,{children:o.jsxs(S,{children:[o.jsx(F,{children:t}),o.jsx(F,{variant:"body2",color:"text.secondary",children:i})]})})},s))})]})}),Zt=({type:n,environment:r,setEnvironment:e})=>{const{environments:s}=le(),t=n===x.ADMIN?[{key:"*",label:"ALL"}]:s.map(i=>({key:i.name,label:`${i.name.concat(i.enabled?"":" - deprecated")}`,title:i.name,disabled:!1}));return o.jsxs(o.Fragment,{children:[o.jsx(he,{children:"Which environment should the token have access to?"}),o.jsx(pt,{disabled:n===x.ADMIN,options:t,value:r,onChange:e,label:"Environment",id:"api_key_environment",name:"environment",IconComponent:Ue,fullWidth:!0})]})},yt=n=>n.map(r=>({...r.user,joinedAt:new Date(r.joinedAt),createdBy:r.createdBy})),es=n=>{const{data:r,error:e,mutate:s}=$e(ae(`api/admin/groups/${n}`),vt);return m.useMemo(()=>({group:r&&{...r,users:yt((r==null?void 0:r.users)??[])},loading:!e&&!r,refetchGroup:()=>s(),error:e}),[r,e,s])},vt=n=>fetch(n).then(ce("Group")).then(r=>r.json()),ts=()=>{const{isEnterprise:n}=w(),{data:r,error:e,mutate:s}=He(n(),{serviceAccounts:[],rootRoles:[]},ae("api/admin/service-account"),Ct);return m.useMemo(()=>({serviceAccounts:(r==null?void 0:r.serviceAccounts)??[],roles:(r==null?void 0:r.rootRoles)??[],loading:!e&&!r,refetch:()=>s(),error:e}),[r,e,s])},Ct=n=>fetch(n).then(ce("Service Accounts")).then(r=>r.json());function E(n,r,e){let s=e.initialDeps??[],t;return()=>{var i,l,a,c;let d;e.key&&((i=e.debug)!=null&&i.call(e))&&(d=Date.now());const h=n();if(!(h.length!==s.length||h.some((v,g)=>s[g]!==v)))return t;s=h;let u;if(e.key&&((l=e.debug)!=null&&l.call(e))&&(u=Date.now()),t=r(...h),e.key&&((a=e.debug)!=null&&a.call(e))){const v=Math.round((Date.now()-d)*100)/100,g=Math.round((Date.now()-u)*100)/100,C=g/16,j=(b,k)=>{for(b=String(b);b.length<k;)b=" "+b;return b};console.info(`%cā± ${j(g,5)} /${j(v,5)} ms`,`
font-size: .6rem;
font-weight: bold;
color: hsl(${Math.max(0,Math.min(120-120*C,120))}deg 100% 31%);`,e==null?void 0:e.key)}return(c=e==null?void 0:e.onChange)==null||c.call(e,t),t}}function N(n,r){if(n===void 0)throw new Error("Unexpected undefined");return n}const jt=(n,r)=>Math.abs(n-r)<1,Tt=(n,r,e)=>{let s;return function(...t){n.clearTimeout(s),s=n.setTimeout(()=>r.apply(this,t),e)}},Et=n=>n,St=n=>{const r=Math.max(n.startIndex-n.overscan,0),e=Math.min(n.endIndex+n.overscan,n.count-1),s=[];for(let t=r;t<=e;t++)s.push(t);return s},wt=(n,r)=>{const e=n.scrollElement;if(!e)return;const s=n.targetWindow;if(!s)return;const t=l=>{const{width:a,height:c}=l;r({width:Math.round(a),height:Math.round(c)})};if(t(e.getBoundingClientRect()),!s.ResizeObserver)return()=>{};const i=new s.ResizeObserver(l=>{const a=()=>{const c=l[0];if(c!=null&&c.borderBoxSize){const d=c.borderBoxSize[0];if(d){t({width:d.inlineSize,height:d.blockSize});return}}t(e.getBoundingClientRect())};n.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()});return i.observe(e,{box:"border-box"}),()=>{i.unobserve(e)}},ee={passive:!0},te=typeof window>"u"?!0:"onscrollend"in window,It=(n,r)=>{const e=n.scrollElement;if(!e)return;const s=n.targetWindow;if(!s)return;let t=0;const i=n.options.useScrollendEvent&&te?()=>{}:Tt(s,()=>{r(t,!1)},n.options.isScrollingResetDelay),l=h=>()=>{const{horizontal:y,isRtl:u}=n.options;t=y?e.scrollLeft*(u&&-1||1):e.scrollTop,i(),r(t,h)},a=l(!0),c=l(!1);c(),e.addEventListener("scroll",a,ee);const d=n.options.useScrollendEvent&&te;return d&&e.addEventListener("scrollend",c,ee),()=>{e.removeEventListener("scroll",a),d&&e.removeEventListener("scrollend",c)}},kt=(n,r,e)=>{if(r!=null&&r.borderBoxSize){const s=r.borderBoxSize[0];if(s)return Math.round(s[e.options.horizontal?"inlineSize":"blockSize"])}return Math.round(n.getBoundingClientRect()[e.options.horizontal?"width":"height"])},At=(n,{adjustments:r=0,behavior:e},s)=>{var t,i;const l=n+r;(i=(t=s.scrollElement)==null?void 0:t.scrollTo)==null||i.call(t,{[s.options.horizontal?"left":"top"]:l,behavior:e})};class Ot{constructor(r){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollToIndexTimeoutId=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.pendingMeasuredCacheIndexes=[],this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let e=null;const s=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(t=>{t.forEach(i=>{const l=()=>{this._measureElement(i.target,i)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()})}));return{disconnect:()=>{var t;(t=s())==null||t.disconnect(),e=null},observe:t=>{var i;return(i=s())==null?void 0:i.observe(t,{box:"border-box"})},unobserve:t=>{var i;return(i=s())==null?void 0:i.unobserve(t)}}})(),this.range=null,this.setOptions=e=>{Object.entries(e).forEach(([s,t])=>{typeof t>"u"&&delete e[s]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Et,rangeExtractor:St,onChange:()=>{},measureElement:kt,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!0,useAnimationFrameWithResizeObserver:!1,...e}},this.notify=e=>{var s,t;(t=(s=this.options).onChange)==null||t.call(s,this,e)},this.maybeNotify=E(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var e;const s=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==s){if(this.cleanup(),!s){this.maybeNotify();return}this.scrollElement=s,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((e=this.scrollElement)==null?void 0:e.window)??null,this.elementsCache.forEach(t=>{this.observer.observe(t)}),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0}),this.unsubs.push(this.options.observeElementRect(this,t=>{this.scrollRect=t,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(t,i)=>{this.scrollAdjustments=0,this.scrollDirection=i?this.getScrollOffset()<t?"forward":"backward":null,this.scrollOffset=t,this.isScrolling=i,this.maybeNotify()}))}},this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,s)=>{const t=new Map,i=new Map;for(let l=s-1;l>=0;l--){const a=e[l];if(t.has(a.lane))continue;const c=i.get(a.lane);if(c==null||a.end>c.end?i.set(a.lane,a):a.end<c.end&&t.set(a.lane,!0),t.size===this.options.lanes)break}return i.size===this.options.lanes?Array.from(i.values()).sort((l,a)=>l.end===a.end?l.index-a.index:l.end-a.end)[0]:void 0},this.getMeasurementOptions=E(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled],(e,s,t,i,l)=>(this.pendingMeasuredCacheIndexes=[],{count:e,paddingStart:s,scrollMargin:t,getItemKey:i,enabled:l}),{key:!1}),this.getMeasurements=E(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:e,paddingStart:s,scrollMargin:t,getItemKey:i,enabled:l},a)=>{if(!l)return this.measurementsCache=[],this.itemSizeCache.clear(),[];this.measurementsCache.length===0&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(h=>{this.itemSizeCache.set(h.key,h.size)}));const c=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const d=this.measurementsCache.slice(0,c);for(let h=c;h<e;h++){const y=i(h),u=this.options.lanes===1?d[h-1]:this.getFurthestMeasurement(d,h),v=u?u.end+this.options.gap:s+t,g=a.get(y),C=typeof g=="number"?g:this.options.estimateSize(h),j=v+C,b=u?u.lane:h%this.options.lanes;d[h]={index:h,start:v,size:C,end:j,key:y,lane:b}}return this.measurementsCache=d,d},{key:!1,debug:()=>this.options.debug}),this.calculateRange=E(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,s,t,i)=>this.range=e.length>0&&s>0?Mt({measurements:e,outerSize:s,scrollOffset:t,lanes:i}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=E(()=>{let e=null,s=null;const t=this.calculateRange();return t&&(e=t.startIndex,s=t.endIndex),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,s]},(e,s,t,i,l)=>i===null||l===null?[]:e({startIndex:i,endIndex:l,overscan:s,count:t}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{const s=this.options.indexAttribute,t=e.getAttribute(s);return t?parseInt(t,10):(console.warn(`Missing attribute name '${s}={index}' on measured element.`),-1)},this._measureElement=(e,s)=>{const t=this.indexFromElement(e),i=this.measurementsCache[t];if(!i)return;const l=i.key,a=this.elementsCache.get(l);a!==e&&(a&&this.observer.unobserve(a),this.observer.observe(e),this.elementsCache.set(l,e)),e.isConnected&&this.resizeItem(t,this.options.measureElement(e,s,this))},this.resizeItem=(e,s)=>{const t=this.measurementsCache[e];if(!t)return;const i=this.itemSizeCache.get(t.key)??t.size,l=s-i;l!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(t,l,this):t.start<this.getScrollOffset()+this.scrollAdjustments)&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=l,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(t.index),this.itemSizeCache=new Map(this.itemSizeCache.set(t.key,s)),this.notify(!1))},this.measureElement=e=>{if(!e){this.elementsCache.forEach((s,t)=>{s.isConnected||(this.observer.unobserve(s),this.elementsCache.delete(t))});return}this._measureElement(e,void 0)},this.getVirtualItems=E(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,s)=>{const t=[];for(let i=0,l=e.length;i<l;i++){const a=e[i],c=s[a];t.push(c)}return t},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{const s=this.getMeasurements();if(s.length!==0)return N(s[ue(0,s.length-1,t=>N(s[t]).start,e)])},this.getOffsetForAlignment=(e,s,t=0)=>{const i=this.getSize(),l=this.getScrollOffset();s==="auto"&&(s=e>=l+i?"end":"start"),s==="center"?e+=(t-i)/2:s==="end"&&(e-=i);const a=this.options.horizontal?"scrollWidth":"scrollHeight",d=(this.scrollElement?"document"in this.scrollElement?this.scrollElement.document.documentElement[a]:this.scrollElement[a]:0)-i;return Math.max(Math.min(d,e),0)},this.getOffsetForIndex=(e,s="auto")=>{e=Math.max(0,Math.min(e,this.options.count-1));const t=this.measurementsCache[e];if(!t)return;const i=this.getSize(),l=this.getScrollOffset();if(s==="auto")if(t.end>=l+i-this.options.scrollPaddingEnd)s="end";else if(t.start<=l+this.options.scrollPaddingStart)s="start";else return[l,s];const a=s==="end"?t.end+this.options.scrollPaddingEnd:t.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,s,t.size),s]},this.isDynamicMode=()=>this.elementsCache.size>0,this.cancelScrollToIndex=()=>{this.scrollToIndexTimeoutId!==null&&this.targetWindow&&(this.targetWindow.clearTimeout(this.scrollToIndexTimeoutId),this.scrollToIndexTimeoutId=null)},this.scrollToOffset=(e,{align:s="start",behavior:t}={})=>{this.cancelScrollToIndex(),t==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(e,s),{adjustments:void 0,behavior:t})},this.scrollToIndex=(e,{align:s="auto",behavior:t}={})=>{e=Math.max(0,Math.min(e,this.options.count-1)),this.cancelScrollToIndex(),t==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");const i=this.getOffsetForIndex(e,s);if(!i)return;const[l,a]=i;this._scrollToOffset(l,{adjustments:void 0,behavior:t}),t!=="smooth"&&this.isDynamicMode()&&this.targetWindow&&(this.scrollToIndexTimeoutId=this.targetWindow.setTimeout(()=>{if(this.scrollToIndexTimeoutId=null,this.elementsCache.has(this.options.getItemKey(e))){const[d]=N(this.getOffsetForIndex(e,a));jt(d,this.getScrollOffset())||this.scrollToIndex(e,{align:a,behavior:t})}else this.scrollToIndex(e,{align:a,behavior:t})}))},this.scrollBy=(e,{behavior:s}={})=>{this.cancelScrollToIndex(),s==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+e,{adjustments:void 0,behavior:s})},this.getTotalSize=()=>{var e;const s=this.getMeasurements();let t;return s.length===0?t=this.options.paddingStart:t=this.options.lanes===1?((e=s[s.length-1])==null?void 0:e.end)??0:Math.max(...s.slice(-this.options.lanes).map(i=>i.end)),Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(e,{adjustments:s,behavior:t})=>{this.options.scrollToFn(e,{behavior:t,adjustments:s},this)},this.measure=()=>{this.itemSizeCache=new Map,this.notify(!1)},this.setOptions(r)}}const ue=(n,r,e,s)=>{for(;n<=r;){const t=(n+r)/2|0,i=e(t);if(i<s)n=t+1;else if(i>s)r=t-1;else return t}return n>0?n-1:0};function Mt({measurements:n,outerSize:r,scrollOffset:e,lanes:s}){const t=n.length-1;let l=ue(0,t,c=>n[c].start,e),a=l;for(;a<t&&n[a].end<e+r;)a++;return s>1&&(l=Math.max(0,l-l%s),a=Math.min(t,a+(s-1-a%s))),{startIndex:l,endIndex:a}}const se=typeof document<"u"?m.useLayoutEffect:m.useEffect;function Rt(n){const r=m.useReducer(()=>({}),{})[1],e={...n,onChange:(t,i)=>{var l;i?Ge.flushSync(r):r(),(l=n.onChange)==null||l.call(n,t,i)}},[s]=m.useState(()=>new Ot(e));return s.setOptions(e),se(()=>s._didMount(),[]),se(()=>s._willUpdate()),s}function zt(n){return Rt({observeElementRect:wt,observeElementOffset:It,scrollToFn:At,...n})}const Dt=m.forwardRef(function(r,e){const{children:s,...t}=r,i=m.useRef(null),l=m.Children.toArray(s),a=zt({count:m.Children.count(s),getScrollElement:()=>i.current,estimateSize:()=>56,overscan:3});return o.jsx("div",{ref:e,children:o.jsx("div",{ref:i,...t,children:o.jsx("ul",{style:{height:`${a.getTotalSize()}px`,width:"100%",position:"relative"},children:a.getVirtualItems().map(c=>{const d=l[c.index];if(!d)return null;const h={position:"absolute",left:0,width:"100%",top:`${c.start}px`};return m.cloneElement(d,{ref:a.measureElement,key:c.key,"data-index":c.index,style:h})})})})})});function ss(n){const{virtualThreshold:r=250,getOptionLabel:e,className:s,...t}=n,i=n.options.length>r,l={...t,getOptionLabel:e,disableListWrap:!0,...i&&{ListboxComponent:Dt,groupBy:void 0}};return o.jsx(Ke,{...l})}const _t=p("div")(({theme:n})=>({display:"flex",flexDirection:"column",gap:n.spacing(.5),"& > *:not(:last-child)":{borderBottom:`1px solid ${n.palette.divider}`,paddingBottom:n.spacing(1)}})),Nt=p(Ve)(()=>({display:"block"})),ns=({role:n,roles:r,value:e})=>{const{isEnterprise:s}=w();if(s()){const t=r||[n];return o.jsx(R,{children:o.jsx(qe,{tooltip:o.jsx(_t,{children:t.map(i=>o.jsx(Qe,{roleId:i,tooltip:!0},i))}),children:o.jsx(Nt,{children:e})})})}return o.jsx(R,{children:e})};export{$t as A,Ht as C,Zt as E,Vt as R,he as S,x as T,Kt as a,Qt as b,qt as c,Jt as d,Xt as e,Yt as f,ts as g,ss as h,es as i,ns as j,de as k,yt as m,Gt as u};