@cyber-harbour/ui 2.2.19 → 2.2.20

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.mjs CHANGED
@@ -169,7 +169,7 @@ self.onmessage = async (e) => {
169
169
  }
170
170
  }
171
171
  };
172
- `,dt=null,ut=null;function Wt(){if(!dt){let r=new Blob([Pn],{type:"application/javascript"});ut=URL.createObjectURL(r),dt=new Worker(ut);}return dt}a(Wt,"getSearchWorker");function zr(){dt?.terminate(),dt=null,ut&&(URL.revokeObjectURL(ut),ut=null);}a(zr,"terminateSearchWorker");function _r(r,o){let[n,a]=useState(""),[u,s]=useState("idle"),[g,w]=useState(null),[x,L]=useState({searched:0,total:0,found:0}),R=useRef(null),f=useCallback(t=>{if(!r||o===0)return;if(!t.trim()){w(null),s("idle"),L({searched:0,total:0,found:0});return}s("searching"),L({searched:0,total:o,found:0});let I=Wt();I.onmessage=k=>{let{type:N}=k.data;N==="progress"&&L({searched:k.data.searched,total:k.data.total,found:k.data.found}),N==="done"&&(w(k.data.matchedIndices),s("done")),N==="cancelled"&&s("idle"),N==="error"&&(s("idle"),console.error("Search worker error:",k.data.message));},I.postMessage({type:"cancel"}),I.postMessage({type:"search",sessionId:r,query:t,chunkCount:o,chunkSize:1e3});},[r,o]),z=useCallback(t=>{a(t),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{f(t);},300);},[f]),j=useCallback(()=>{a(""),w(null),s("idle"),L({searched:0,total:0,found:0}),Wt().postMessage({type:"cancel"});},[]);return useEffect(()=>()=>{R.current&&clearTimeout(R.current),zr();},[]),{query:n,onQueryChange:z,clearSearch:j,searchState:u,matchedIndices:g,searchProgress:x}}a(_r,"useCsvSearch");var An={loading:"Loading...",rows:"rows",retry:"Retry",searchPlaceholder:"Search...",searchFound:"found",searching:"Searching..."};function jn(r,o,n){let a=1/0,u=-1/0,s=Math.min(n,r.length-1);for(let g=o;g<=s;g++){let w=r[g];w<a&&(a=w),w>u&&(u=w);}return {min:a,max:u}}a(jn,"getMinMax");function Fn(r,o,n){let a=Math.min(100,n),u=r.map(()=>[]);for(let s=0;s<a;s++){let g=o(s);if(g)for(let w=0;w<r.length;w++){let x=g[r[w]]??"";u[w].push(x.length);}}return r.map((s,g)=>{let w=s.length*9,x=u[g];if(x.length===0)return Math.min(Math.max(150,w+24),800);x.sort((j,t)=>j-t);let L=Math.floor(x.length*.9),f=x[L]*7.5+24,z=Math.max(w+24,f);return Math.min(Math.max(50,z),800)})}a(Fn,"estimateColumnWidths");var Yt=a(r=>{let{state:o,headers:n,totalRows:a$1,getRow:u,error:s,progress:g,prefetchRange:w,sessionId:x,chunkCount:L,pinChunks:R}=Ir(r),f={...An,...r.labels},{query:z$1,onQueryChange:j,clearSearch:t,searchState:I,matchedIndices:k}=_r(x,L),N=k!==null,C=N?k.length:a$1,[M,D]=useState([]),W=useRef(null),Y=useRef(null),Z=useRef(false),oe=useRef(false);useEffect(()=>{oe.current=false,Z.current=false,D([]);},[x]),useEffect(()=>{if(n.length===0||Z.current||oe.current||a$1===0)return;let $=u(0);!$||!n.some(A=>$[A]!==void 0)||(oe.current=true,D(Fn(n,u,a$1)));},[n,a$1,u]),useEffect(()=>()=>Y.current?.(),[]);let me=useCallback(($,A)=>{$.preventDefault(),Z.current=true;let K=$.clientX,B=M[A]??150;W.current={index:A,startX:K,startWidth:B};let Q=a(ee=>{if(!W.current)return;let q=ee.clientX-K,ne=Math.max(50,B+q);D(ie=>{let ue=[...ie];return ue[A]=ne,ue});},"onMouseMove"),ae=a(()=>{W.current=null,Y.current=null,document.removeEventListener("mousemove",Q),document.removeEventListener("mouseup",ae);},"onMouseUp");Y.current=ae,document.addEventListener("mousemove",Q),document.addEventListener("mouseup",ae);},[M]),be=M.reduce(($,A)=>$+A,0),de=useCallback(()=>jsx(Hn,{children:n.map(($,A)=>jsxs(Wn,{style:{width:M[A]},children:[$,jsx($n,{onMouseDown:K=>me(K,A)})]},A))}),[n,M,me]),Re=useCallback($=>{if(N&&k){let A=1/0,K=-1/0,B=new Set,Q=Math.min($.endIndex,k.length-1);for(let ae=$.startIndex;ae<=Q;ae++){let ee=k[ae];ee<A&&(A=ee),ee>K&&(K=ee),B.add(Math.floor(ee/1e3));}R(Array.from(B)),A!==1/0&&w(A,K);}else R([]),w($.startIndex,$.endIndex);},[w,R,N,k]),ve=useCallback($=>{let A=N&&k?k[$]:$,K=u(A);return K?n.map((B,Q)=>jsx(Fr,{style:{width:M[Q]},children:K[B]??""},Q)):n.map((B,Q)=>jsx(Fr,{style:{width:M[Q]},children:jsx(qn,{})},Q))},[u,n,M,N,k]);return useEffect(()=>{if(C>0)if(N&&k){let{min:$,max:A}=jn(k,0,50);$!==1/0&&w($,A);}else w(0,50);},[C,N,k,w]),o==="idle"||o==="loading"||o==="streaming"?jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-3",children:[jsx("div",{className:"h-10 w-10 rounded-full border-2 border-gray-200 dark:border-neutral-700 animate-spin border-s-transparent"}),o==="streaming"&&a$1>0&&jsxs(_a,{variant:"body",color:"text.lighter",style:{fontSize:12},children:[f.loading," ",a$1.toLocaleString()," ",f.rows,g>0?` (${Math.round(g*100)}%)`:""]})]}):jsxs("div",{className:"h-full w-full flex flex-col",children:[jsxs("div",{className:"flex items-center justify-between px-4 py-2 gap-3",children:[jsx(_a,{variant:"body",color:"text.lighter",style:{fontSize:12,whiteSpace:"nowrap"},children:`${C.toLocaleString()} ${N?f.searchFound:f.rows}${N?` / ${a$1.toLocaleString()}`:""}`}),jsxs(Un,{children:[jsx(Zn,{type:"text",value:z$1,onChange:$=>j($.target.value),placeholder:f.searchPlaceholder}),I==="searching"?jsx(Gn,{children:jsx(Jn,{})}):z$1?jsx(Vn,{onClick:t,type:"button",children:"\u2715"}):null]})]}),o==="partial_error"&&jsxs(rb,{className:"flex items-center justify-between mx-4 mb-2 px-3 py-2 rounded bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-900",children:[jsx(_a,{variant:"body",className:"text-red-600 dark:text-red-400",style:{fontSize:12},children:s}),r.onRetry&&jsx(z,{onClick:()=>r.onRetry(s??""),variant:"outlined",size:"small",children:f.retry})]}),jsx("div",{className:"flex-1 min-h-0",children:n.length>0&&jsx(TableVirtuoso,{totalCount:C,increaseViewportBy:300,fixedHeaderContent:de,itemContent:ve,rangeChanged:Re,style:{height:"100%"},components:{Table:a(({style:$,context:A,...K})=>jsx(Bn,{style:{...$,minWidth:"100%",width:be},...K}),"Table"),TableHead:On,TableRow:a(({context:$,...A})=>jsx(Xn,{...A}),"TableRow")}},N?"filtered":"all")})]})},"CsvDriver"),Bn=styled.table(({theme:r})=>`
172
+ `,dt=null,ut=null;function Wt(){if(!dt){let r=new Blob([Pn],{type:"application/javascript"});ut=URL.createObjectURL(r),dt=new Worker(ut);}return dt}a(Wt,"getSearchWorker");function zr(){dt?.terminate(),dt=null,ut&&(URL.revokeObjectURL(ut),ut=null);}a(zr,"terminateSearchWorker");function _r(r,o){let[n,a]=useState(""),[u,s]=useState("idle"),[g,w]=useState(null),[x,L]=useState({searched:0,total:0,found:0}),R=useRef(null),f=useCallback(t=>{if(!r||o===0)return;if(!t.trim()){w(null),s("idle"),L({searched:0,total:0,found:0});return}s("searching"),L({searched:0,total:o,found:0});let I=Wt();I.onmessage=k=>{let{type:N}=k.data;N==="progress"&&L({searched:k.data.searched,total:k.data.total,found:k.data.found}),N==="done"&&(w(k.data.matchedIndices),s("done")),N==="cancelled"&&s("idle"),N==="error"&&(s("idle"),console.error("Search worker error:",k.data.message));},I.postMessage({type:"cancel"}),I.postMessage({type:"search",sessionId:r,query:t,chunkCount:o,chunkSize:1e3});},[r,o]),z=useCallback(t=>{a(t),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{f(t);},300);},[f]),j=useCallback(()=>{a(""),w(null),s("idle"),L({searched:0,total:0,found:0}),Wt().postMessage({type:"cancel"});},[]);return useEffect(()=>()=>{R.current&&clearTimeout(R.current),zr();},[]),{query:n,onQueryChange:z,clearSearch:j,searchState:u,matchedIndices:g,searchProgress:x}}a(_r,"useCsvSearch");var An={loading:"Loading...",rows:"rows",retry:"Retry",searchPlaceholder:"Search...",searchFound:"found",searching:"Searching..."};function jn(r,o,n){let a=1/0,u=-1/0,s=Math.min(n,r.length-1);for(let g=o;g<=s;g++){let w=r[g];w<a&&(a=w),w>u&&(u=w);}return {min:a,max:u}}a(jn,"getMinMax");function Fn(r,o,n){let a=Math.min(100,n),u=r.map(()=>[]);for(let s=0;s<a;s++){let g=o(s);if(g)for(let w=0;w<r.length;w++){let x=g[r[w]]??"";u[w].push(x.length);}}return r.map((s,g)=>{let w=s.length*9,x=u[g];if(x.length===0)return Math.min(Math.max(150,w+24),800);x.sort((j,t)=>j-t);let L=Math.floor(x.length*.9),f=x[L]*7.5+24,z=Math.max(w+24,f);return Math.min(Math.max(50,z),800)})}a(Fn,"estimateColumnWidths");var Yt=a(r=>{let{state:o,headers:n,totalRows:a$1,getRow:u,error:s,progress:g,prefetchRange:w,sessionId:x,chunkCount:L,pinChunks:R}=Ir(r),f={...An,...r.labels},{query:z$1,onQueryChange:j,clearSearch:t,searchState:I,matchedIndices:k}=_r(x,L),N=k!==null,C=N?k.length:a$1,[M,D]=useState([]),W=useRef(null),Y=useRef(null),Z=useRef(false),oe=useRef(false);useEffect(()=>{oe.current=false,Z.current=false,D([]);},[x]),useEffect(()=>{if(n.length===0||Z.current||oe.current||a$1===0)return;let $=u(0);!$||!n.some(A=>$[A]!==void 0)||(oe.current=true,D(Fn(n,u,a$1)));},[n,a$1,u]),useEffect(()=>()=>Y.current?.(),[]);let me=useCallback(($,A)=>{$.preventDefault(),Z.current=true;let K=$.clientX,B=M[A]??150;W.current={index:A,startX:K,startWidth:B};let Q=a(ee=>{if(!W.current)return;let q=ee.clientX-K,ne=Math.max(50,B+q);D(ie=>{let ue=[...ie];return ue[A]=ne,ue});},"onMouseMove"),ae=a(()=>{W.current=null,Y.current=null,document.removeEventListener("mousemove",Q),document.removeEventListener("mouseup",ae);},"onMouseUp");Y.current=ae,document.addEventListener("mousemove",Q),document.addEventListener("mouseup",ae);},[M]),be=M.reduce(($,A)=>$+A,0),de=useCallback(()=>jsx(Hn,{children:n.map(($,A)=>jsxs(Wn,{style:{width:M[A]},children:[$,jsx($n,{onMouseDown:K=>me(K,A)})]},A))}),[n,M,me]),Re=useCallback($=>{if(N&&k){let A=1/0,K=-1/0,B=new Set,Q=Math.min($.endIndex,k.length-1);for(let ae=$.startIndex;ae<=Q;ae++){let ee=k[ae];ee<A&&(A=ee),ee>K&&(K=ee),B.add(Math.floor(ee/1e3));}R(Array.from(B)),A!==1/0&&w(A,K);}else R([]),w($.startIndex,$.endIndex);},[w,R,N,k]),ve=useCallback($=>{let A=N&&k?k[$]:$,K=u(A);return K?n.map((B,Q)=>jsx(Fr,{style:{width:M[Q]},children:K[B]??""},Q)):n.map((B,Q)=>jsx(Fr,{style:{width:M[Q]},children:jsx(qn,{})},Q))},[u,n,M,N,k]);return useEffect(()=>{if(C>0)if(N&&k){let{min:$,max:A}=jn(k,0,50);$!==1/0&&w($,A);}else w(0,50);},[C,N,k,w]),o==="idle"||o==="loading"||o==="streaming"?jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-3",children:[jsx("div",{className:"h-10 w-10 rounded-full border-2 border-gray-200 dark:border-neutral-700 animate-spin border-s-transparent"}),o==="streaming"&&a$1>0&&jsxs(_a,{variant:"body",color:"text.lighter",style:{fontSize:12},children:[f.loading," ",a$1.toLocaleString()," ",f.rows,g>0?` (${Math.round(g*100)}%)`:""]})]}):jsxs("div",{className:"h-full w-full flex flex-col",children:[jsxs("div",{className:"flex items-center justify-between px-8.5 py-2 gap-2 flex-wrap",children:[jsx(_a,{variant:"body",color:"text.lighter",style:{fontSize:12,whiteSpace:"nowrap"},children:`${C.toLocaleString()} ${N?f.searchFound:f.rows}${N?` / ${a$1.toLocaleString()}`:""}`}),jsxs(Un,{children:[jsx(Zn,{type:"text",value:z$1,onChange:$=>j($.target.value),placeholder:f.searchPlaceholder}),I==="searching"?jsx(Gn,{children:jsx(Jn,{})}):z$1?jsx(Vn,{onClick:t,type:"button",children:"\u2715"}):null]})]}),o==="partial_error"&&jsxs(rb,{className:"flex items-center justify-between mx-4 mb-2 px-3 py-2 rounded bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-900",children:[jsx(_a,{variant:"body",className:"text-red-600 dark:text-red-400",style:{fontSize:12},children:s}),r.onRetry&&jsx(z,{onClick:()=>r.onRetry(s??""),variant:"outlined",size:"small",children:f.retry})]}),jsx("div",{className:"flex-1 min-h-0",children:n.length>0&&jsx(TableVirtuoso,{totalCount:C,increaseViewportBy:300,fixedHeaderContent:de,itemContent:ve,rangeChanged:Re,style:{height:"100%"},components:{Table:a(({style:$,context:A,...K})=>jsx(Bn,{style:{...$,minWidth:"100%",width:be},...K}),"Table"),TableHead:On,TableRow:a(({context:$,...A})=>jsx(Xn,{...A}),"TableRow")}},N?"filtered":"all")})]})},"CsvDriver"),Bn=styled.table(({theme:r})=>`
173
173
  border-collapse: separate;
174
174
  border-spacing: 0;
175
175
  table-layout: fixed;