@cyber-harbour/ui 2.1.26-beta.6 → 2.2.0

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,12 +169,13 @@ self.onmessage = async (e) => {
169
169
  }
170
170
  }
171
171
  };
172
- `,et=null,tt=null;function Lt(){if(!et){let r=new Blob([hn],{type:"application/javascript"});tt=URL.createObjectURL(r),et=new Worker(tt);}return et}a(Lt,"getSearchWorker");function Tr(){et?.terminate(),et=null,tt&&(URL.revokeObjectURL(tt),tt=null);}a(Tr,"terminateSearchWorker");function Nr(r,o){let[n,a]=useState(""),[p,u]=useState("idle"),[m,k]=useState(null),[T,C]=useState({searched:0,total:0,found:0}),D=useRef(null),y=useCallback(t=>{if(!r||o===0)return;if(!t.trim()){k(null),u("idle"),C({searched:0,total:0,found:0});return}u("searching"),C({searched:0,total:o,found:0});let L=Lt();L.onmessage=w=>{let{type:d}=w.data;d==="progress"&&C({searched:w.data.searched,total:w.data.total,found:w.data.found}),d==="done"&&(k(w.data.matchedIndices),u("done")),d==="cancelled"&&u("idle"),d==="error"&&(u("idle"),console.error("Search worker error:",w.data.message));},L.postMessage({type:"cancel"}),L.postMessage({type:"search",sessionId:r,query:t,chunkCount:o,chunkSize:1e3});},[r,o]),R=useCallback(t=>{a(t),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{y(t);},300);},[y]),j=useCallback(()=>{a(""),k(null),u("idle"),C({searched:0,total:0,found:0}),Lt().postMessage({type:"cancel"});},[]);return useEffect(()=>()=>{D.current&&clearTimeout(D.current),Tr();},[]),{query:n,onQueryChange:R,clearSearch:j,searchState:p,matchedIndices:m,searchProgress:T}}a(Nr,"useCsvSearch");var xn={loading:"Loading...",rows:"rows",rowsIncomplete:"rows (incomplete)",retry:"Retry",searchPlaceholder:"Search...",searchFound:"found",searching:"Searching..."};function Lr(r,o,n){let a=1/0,p=-1/0,u=Math.min(n,r.length-1);for(let m=o;m<=u;m++){let k=r[m];k<a&&(a=k),k>p&&(p=k);}return {min:a,max:p}}a(Lr,"getMinMax");var Bt=a(r=>{let{state:o,headers:n,totalRows:a$1,getRow:p,error:u,progress:m,prefetchRange:k,sessionId:T,chunkCount:C,pinChunks:D}=Mr(r),y={...xn,...r.labels},{query:R,onQueryChange:j,clearSearch:t,searchState:L,matchedIndices:w}=Nr(T,C),d=w!==null,E=d?w.length:a$1,[S,P]=useState([]),F=useRef(null),$=useRef(null);useEffect(()=>{n.length>0&&S.length!==n.length&&P(n.map(A=>Math.min(Math.max(150,A.length*9),500)));},[n,S.length]),useEffect(()=>()=>$.current?.(),[]);let J=useCallback((A,U)=>{A.preventDefault();let ie=A.clientX,H=S[U]??150;F.current={index:U,startX:ie,startWidth:H};let ne=a(ue=>{if(!F.current)return;let ge=ue.clientX-ie,le=Math.max(50,H+ge);P(ee=>{let te=[...ee];return te[U]=le,te});},"onMouseMove"),B=a(()=>{F.current=null,$.current=null,document.removeEventListener("mousemove",ne),document.removeEventListener("mouseup",B);},"onMouseUp");$.current=B,document.addEventListener("mousemove",ne),document.addEventListener("mouseup",B);},[S]),oe=S.reduce((A,U)=>A+U,0),ye=useCallback(()=>jsx(Dn,{children:n.map((A,U)=>jsxs(Cn,{style:{width:S[U]},children:[A,jsx(Pn,{onMouseDown:ie=>J(ie,U)})]},A))}),[n,S,J]),fe=useCallback(A=>{if(d&&w){let{min:U,max:ie}=Lr(w,A.startIndex,A.endIndex),H=new Set,ne=Math.min(A.endIndex,w.length-1);for(let B=A.startIndex;B<=ne;B++)H.add(Math.floor(w[B]/1e3));D(Array.from(H)),U!==1/0&&k(U,ie);}else D([]),k(A.startIndex,A.endIndex);},[k,D,d,w]),ve=useCallback(A=>{let U=d&&w?w[A]:A,ie=p(U);return ie?n.map(H=>jsx(zr,{style:{width:S[n.indexOf(H)]},children:ie[H]??""},H)):n.map(H=>jsx(zr,{style:{width:S[n.indexOf(H)]},children:jsx(Tn,{})},H))},[p,n,S,d,w]);return useEffect(()=>{if(E>0)if(d&&w){let{min:A,max:U}=Lr(w,0,50);A!==1/0&&k(A,U);}else k(0,50);},[E,d,w,k]),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 animate-spin border-s-transparent"}),o==="streaming"&&a$1>0&&jsxs(Ya,{variant:"body",color:"text.lighter",style:{fontSize:12},children:[y.loading," ",a$1.toLocaleString()," ",y.rows,m>0?` (${Math.round(m*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(Ya,{variant:"body",color:"text.lighter",style:{fontSize:12,whiteSpace:"nowrap"},children:`${E.toLocaleString()} ${d?y.searchFound:y.rows}${d?` / ${a$1.toLocaleString()}`:""}`}),jsxs(Nn,{children:[jsx(Rn,{type:"text",value:R,onChange:A=>j(A.target.value),placeholder:y.searchPlaceholder}),L==="searching"?jsx(En,{children:jsx(Ln,{})}):R?jsx(In,{onClick:t,type:"button",children:"\u2715"}):null]})]}),o==="partial_error"&&jsxs(pb,{className:"flex items-center justify-between mx-4 mb-2 px-3 py-2 rounded bg-red-50 border border-red-200",children:[jsx(Ya,{variant:"body",style:{fontSize:12,color:"#dc2626"},children:u}),r.onRetry&&jsx(z,{onClick:()=>r.onRetry?.(u??""),variant:"outlined",size:"small",children:y.retry})]}),jsx("div",{className:"flex-1 min-h-0",children:n.length>0&&jsx(TableVirtuoso,{totalCount:E,increaseViewportBy:300,fixedHeaderContent:ye,itemContent:ve,rangeChanged:fe,style:{height:"100%"},components:{Table:a(({style:A,context:U,...ie})=>jsx(kn,{style:{...A,width:oe},...ie}),"Table"),TableHead:Sn,TableRow:a(({context:A,...U})=>jsx(Mn,{...U}),"TableRow")}},d?"filtered":"all")})]})},"CsvDriver"),kn=styled.table`
172
+ `,et=null,tt=null;function Lt(){if(!et){let r=new Blob([hn],{type:"application/javascript"});tt=URL.createObjectURL(r),et=new Worker(tt);}return et}a(Lt,"getSearchWorker");function Tr(){et?.terminate(),et=null,tt&&(URL.revokeObjectURL(tt),tt=null);}a(Tr,"terminateSearchWorker");function Nr(r,o){let[n,a]=useState(""),[p,u]=useState("idle"),[m,k]=useState(null),[T,C]=useState({searched:0,total:0,found:0}),D=useRef(null),y=useCallback(t=>{if(!r||o===0)return;if(!t.trim()){k(null),u("idle"),C({searched:0,total:0,found:0});return}u("searching"),C({searched:0,total:o,found:0});let L=Lt();L.onmessage=w=>{let{type:d}=w.data;d==="progress"&&C({searched:w.data.searched,total:w.data.total,found:w.data.found}),d==="done"&&(k(w.data.matchedIndices),u("done")),d==="cancelled"&&u("idle"),d==="error"&&(u("idle"),console.error("Search worker error:",w.data.message));},L.postMessage({type:"cancel"}),L.postMessage({type:"search",sessionId:r,query:t,chunkCount:o,chunkSize:1e3});},[r,o]),R=useCallback(t=>{a(t),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{y(t);},300);},[y]),j=useCallback(()=>{a(""),k(null),u("idle"),C({searched:0,total:0,found:0}),Lt().postMessage({type:"cancel"});},[]);return useEffect(()=>()=>{D.current&&clearTimeout(D.current),Tr();},[]),{query:n,onQueryChange:R,clearSearch:j,searchState:p,matchedIndices:m,searchProgress:T}}a(Nr,"useCsvSearch");var xn={loading:"Loading...",rows:"rows",rowsIncomplete:"rows (incomplete)",retry:"Retry",searchPlaceholder:"Search...",searchFound:"found",searching:"Searching..."};function Lr(r,o,n){let a=1/0,p=-1/0,u=Math.min(n,r.length-1);for(let m=o;m<=u;m++){let k=r[m];k<a&&(a=k),k>p&&(p=k);}return {min:a,max:p}}a(Lr,"getMinMax");var Bt=a(r=>{let{state:o,headers:n,totalRows:a$1,getRow:p,error:u,progress:m,prefetchRange:k,sessionId:T,chunkCount:C,pinChunks:D}=Mr(r),y={...xn,...r.labels},{query:R,onQueryChange:j,clearSearch:t,searchState:L,matchedIndices:w}=Nr(T,C),d=w!==null,E=d?w.length:a$1,[S,P]=useState([]),F=useRef(null),$=useRef(null);useEffect(()=>{n.length>0&&S.length!==n.length&&P(n.map(A=>Math.min(Math.max(150,A.length*9),500)));},[n,S.length]),useEffect(()=>()=>$.current?.(),[]);let J=useCallback((A,U)=>{A.preventDefault();let ie=A.clientX,H=S[U]??150;F.current={index:U,startX:ie,startWidth:H};let ne=a(ue=>{if(!F.current)return;let ge=ue.clientX-ie,le=Math.max(50,H+ge);P(ee=>{let te=[...ee];return te[U]=le,te});},"onMouseMove"),B=a(()=>{F.current=null,$.current=null,document.removeEventListener("mousemove",ne),document.removeEventListener("mouseup",B);},"onMouseUp");$.current=B,document.addEventListener("mousemove",ne),document.addEventListener("mouseup",B);},[S]),oe=S.reduce((A,U)=>A+U,0),ye=useCallback(()=>jsx(Dn,{children:n.map((A,U)=>jsxs(Cn,{style:{width:S[U]},children:[A,jsx(Pn,{onMouseDown:ie=>J(ie,U)})]},A))}),[n,S,J]),fe=useCallback(A=>{if(d&&w){let{min:U,max:ie}=Lr(w,A.startIndex,A.endIndex),H=new Set,ne=Math.min(A.endIndex,w.length-1);for(let B=A.startIndex;B<=ne;B++)H.add(Math.floor(w[B]/1e3));D(Array.from(H)),U!==1/0&&k(U,ie);}else D([]),k(A.startIndex,A.endIndex);},[k,D,d,w]),ve=useCallback(A=>{let U=d&&w?w[A]:A,ie=p(U);return ie?n.map(H=>jsx(zr,{style:{width:S[n.indexOf(H)]},children:ie[H]??""},H)):n.map(H=>jsx(zr,{style:{width:S[n.indexOf(H)]},children:jsx(Tn,{})},H))},[p,n,S,d,w]);return useEffect(()=>{if(E>0)if(d&&w){let{min:A,max:U}=Lr(w,0,50);A!==1/0&&k(A,U);}else k(0,50);},[E,d,w,k]),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 animate-spin border-s-transparent"}),o==="streaming"&&a$1>0&&jsxs(Ya,{variant:"body",color:"text.lighter",style:{fontSize:12},children:[y.loading," ",a$1.toLocaleString()," ",y.rows,m>0?` (${Math.round(m*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(Ya,{variant:"body",color:"text.lighter",style:{fontSize:12,whiteSpace:"nowrap"},children:`${E.toLocaleString()} ${d?y.searchFound:y.rows}${d?` / ${a$1.toLocaleString()}`:""}`}),jsxs(Nn,{children:[jsx(Rn,{type:"text",value:R,onChange:A=>j(A.target.value),placeholder:y.searchPlaceholder}),L==="searching"?jsx(En,{children:jsx(Ln,{})}):R?jsx(In,{onClick:t,type:"button",children:"\u2715"}):null]})]}),o==="partial_error"&&jsxs(pb,{className:"flex items-center justify-between mx-4 mb-2 px-3 py-2 rounded bg-red-50 border border-red-200",children:[jsx(Ya,{variant:"body",style:{fontSize:12,color:"#dc2626"},children:u}),r.onRetry&&jsx(z,{onClick:()=>r.onRetry?.(u??""),variant:"outlined",size:"small",children:y.retry})]}),jsx("div",{className:"flex-1 min-h-0",children:n.length>0&&jsx(TableVirtuoso,{totalCount:E,increaseViewportBy:300,fixedHeaderContent:ye,itemContent:ve,rangeChanged:fe,style:{height:"100%"},components:{Table:a(({style:A,context:U,...ie})=>jsx(kn,{style:{...A,minWidth:"100%",width:oe},...ie}),"Table"),TableHead:Sn,TableRow:a(({context:A,...U})=>jsx(Mn,{...U}),"TableRow")}},d?"filtered":"all")})]})},"CsvDriver"),kn=styled.table(({theme:r})=>`
173
173
  border-collapse: separate;
174
174
  border-spacing: 0;
175
175
  table-layout: fixed;
176
176
  font-size: 13px;
177
- `,Sn=styled.thead(({theme:r})=>`
177
+ background-color: ${r.colors.background};
178
+ `),Sn=styled.thead(({theme:r})=>`
178
179
  background-color: ${r.colors.background};
179
180
  z-index: 1;
180
181
  `),Dn=styled.tr``,Cn=styled.th(({theme:r})=>`