TvBox/all/lib/ui_packages_ref-selector_RefSelector_tsx-d5cdb50eb045.js

2 lines
19 KiB
JavaScript
Raw Permalink Normal View History

2025-07-03 20:15:22 +08:00
"use strict";(globalThis.webpackChunk=globalThis.webpackChunk||[]).push([["ui_packages_ref-selector_RefSelector_tsx"],{99707:(e,t,a)=>{a.d(t,{_:()=>o,d:()=>SearchIndex});var r=a(85351),n=a(7479);function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}let{getItem:s,setItem:l,removeItem:c}=(0,r.A)("localStorage",{throwQuotaErrorsOnSet:!0}),o={Branch:"branch",Tag:"tag"};let SearchIndex=class SearchIndex{render(){this.selector.render()}async fetchData(){try{if(!this.isLoading||this.fetchInProgress)return;if(!this.bootstrapFromLocalStorage()){this.fetchInProgress=!0,this.fetchFailed=!1;let e=await fetch(`${this.refEndpoint}?type=${this.refType}`,{headers:{Accept:"application/json"}});await this.processResponse(e)}this.isLoading=!1,this.fetchInProgress=!1,this.render()}catch{this.fetchInProgress=!1,this.fetchFailed=!0}}async processResponse(e){if(this.emitStats(e),!e.ok){this.fetchFailed=!0;return}let t=e.clone(),a=await e.json();this.knownItems=a.refs,this.cacheKey=a.cacheKey,this.flushToLocalStorage(await t.text())}emitStats(e){if(!e.ok)return void(0,n.i)({incrementKey:"REF_SELECTOR_BOOT_FAILED"},!0);switch(e.status){case 200:(0,n.i)({incrementKey:"REF_SELECTOR_BOOTED_FROM_UNCACHED_HTTP"});break;case 304:(0,n.i)({incrementKey:"REF_SELECTOR_BOOTED_FROM_HTTP_CACHE"});break;default:(0,n.i)({incrementKey:"REF_SELECTOR_UNEXPECTED_RESPONSE"})}}search(e){let t;if(this.searchTerm=e,""===e){this.currentSearchResult=this.knownItems;return}let a=[],r=[];for(let n of(this.exactMatchFound=!1,this.knownItems))if(!((t=n.indexOf(e))<0)){if(0===t){e===n?(r.unshift(n),this.exactMatchFound=!0):r.push(n);continue}a.push(n)}this.currentSearchResult=[...r,...a]}bootstrapFromLocalStorage(){let e=s(this.localStorageKey);if(!e)return!1;let t=JSON.parse(e);return t.cacheKey===this.cacheKey&&"refs"in t?(this.knownItems=t.refs,this.isLoading=!1,(0,n.i)({incrementKey:"REF_SELECTOR_BOOTED_FROM_LOCALSTORAGE"}),!0):(c(this.localStorageKey),!1)}async flushToLocalStorage(e){try{l(this.localStorageKey,e)}catch(t){if(t.message.toLowerCase().includes("quota")){this.clearSiblingLocalStorage(),(0,n.i)({incrementKey:"REF_SELECTOR_LOCALSTORAGE_OVERFLOWED"});try{l(this.localStorageKey,e)}catch(e){e.message.toLowerCase().includes("quota")&&(0,n.i)({incrementKey:"REF_SELECTOR_LOCALSTORAGE_GAVE_UP"})}}else throw t}}clearSiblingLocalStorage(){for(let e of Object.keys(localStorage))e.startsWith(SearchIndex.LocalStoragePrefix)&&c(e)}clearLocalStorage(){c(this.localStorageKey)}get localStorageKey(){return`${SearchIndex.LocalStoragePrefix}:${this.nameWithOwner}:${this.refType}`}constructor(e,t,a,r,n){i(this,"refType",void 0),i(this,"selector",void 0),i(this,"knownItems",[]),i(this,"currentSearchResult",[]),i(this,"exactMatchFound",!1),i(this,"searchTerm",""),i(this,"refEndpoint",void 0),i(this,"cacheKey",void 0),i(this,"nameWithOwner",void 0),i(this,"isLoading",!0),i(this,"fetchInProgress",!1),i(this,"fetchFailed",!1),this.refType=e,this.selector=t,this.refEndpoint=a,this.cacheKey=r,this.nameWithOwner=n}};i(SearchIndex,"LocalStoragePrefix","ref-selector")},79637:(e,t,a)=>{a.d(t,{F:()=>o});var r,n=a(74848),i=a(75177),s=a(15385),l=a(96540),c=a(20627);function o({items:e,itemHeight:t,sx:a,renderItem:r,makeKey:i,ariaControls:s,shouldUseActionList:o=!1,className:u}){let f=(0,l.useRef)(null),m=(0,c.Te)({count:e.length,getScrollElement:(0,l.useCallback)(()=>f.current,[]),estimateSize:(0,l.useCallback)(()=>t,[t])});return(0,n.jsx)(h,{ref:f,sx:a,virtualizer:m,id:s,shouldUseActionList:o,className:u,children:m.getVirtualItems().map((t,a)=>(0,n.jsx)(d,{virtualRow:t,children:r(e[t.index],a)},i(e[t.index])))})}let h=l.forwardRef(function({children:e,sx:t,virtualizer:a,id:r,shouldUseActionList:l,className:c},o){return(0,n.jsx)(i.A,{ref:o,sx:t,id:r,className:c,children:l?(0,n.jsx)(s.l,{id:r,role:"menu",style:{height:a.getTotalSize(),width:"100%",position:"relative"},selectionVariant:"single",children:e}):(0,n.jsx)("ul",{role:"menu",style:{height:a.getTotalSize(),width:"100%",position:"relative"},id:r,children:e})})});function
//# sourceMappingURL=ui_packages_ref-selector_RefSelector_tsx-d308e32470e0.js.map