@dataramen/cli 0.0.5-4.beta-2 → 0.0.5-4.beta-3

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.
@@ -234,4 +234,4 @@ to {
234
234
  Licensed under the MIT License (MIT), see
235
235
  http://jedwatson.github.io/classnames
236
236
  */var Fy;function Y6(){return Fy||(Fy=1,function(n){(function(){var l={}.hasOwnProperty;function r(){for(var u="",d=0;d<arguments.length;d++){var m=arguments[d];m&&(u=o(u,s(m)))}return u}function s(u){if(typeof u=="string"||typeof u=="number")return u;if(typeof u!="object")return"";if(Array.isArray(u))return r.apply(null,u);if(u.toString!==Object.prototype.toString&&!u.toString.toString().includes("[native code]"))return u.toString();var d="";for(var m in u)l.call(u,m)&&u[m]&&(d=o(d,m));return d}function o(u,d){return d?u?u+" "+d:u+d:u}n.exports?(r.default=r,n.exports=r):window.classNames=r})()}(sd)),sd.exports}var K6=Y6();const Od=gu(K6);var Gy={};const V6="react-tooltip-core-styles",F6="react-tooltip-base-styles",Xy={core:!1,base:!1};function Zy({css:n,id:l=F6,type:r="base",ref:s}){var o,u;if(!n||typeof document>"u"||Xy[r]||r==="core"&&typeof process<"u"&&(!((o=process==null?void 0:Gy)===null||o===void 0)&&o.REACT_TOOLTIP_DISABLE_CORE_STYLES)||r!=="base"&&typeof process<"u"&&(!((u=process==null?void 0:Gy)===null||u===void 0)&&u.REACT_TOOLTIP_DISABLE_BASE_STYLES))return;r==="core"&&(l=V6),s||(s={});const{insertAt:d}=s;if(document.getElementById(l))return;const m=document.head||document.getElementsByTagName("head")[0],y=document.createElement("style");y.id=l,y.type="text/css",d==="top"&&m.firstChild?m.insertBefore(y,m.firstChild):m.appendChild(y),y.styleSheet?y.styleSheet.cssText=n:y.appendChild(document.createTextNode(n)),Xy[r]=!0}const Py=async({elementReference:n=null,tooltipReference:l=null,tooltipArrowReference:r=null,place:s="top",offset:o=10,strategy:u="absolute",middlewares:d=[B6(Number(o)),Q6({fallbackAxisSideDirection:"start"}),H6({padding:5})],border:m,arrowSize:y=8})=>{if(!n)return{tooltipStyles:{},tooltipArrowStyles:{},place:s};if(l===null)return{tooltipStyles:{},tooltipArrowStyles:{},place:s};const p=d;return r?(p.push($6({element:r,padding:5})),Vy(n,l,{placement:s,strategy:u,middleware:p}).then(({x:v,y:b,placement:E,middlewareData:C})=>{var w,N;const j={left:`${v}px`,top:`${b}px`,border:m},{x:_,y:T}=(w=C.arrow)!==null&&w!==void 0?w:{x:0,y:0},O=(N={top:"bottom",right:"left",bottom:"top",left:"right"}[E.split("-")[0]])!==null&&N!==void 0?N:"bottom",Q=m&&{borderBottom:m,borderRight:m};let K=0;if(m){const H=`${m}`.match(/(\d+)px/);K=H!=null&&H[1]?Number(H[1]):1}return{tooltipStyles:j,tooltipArrowStyles:{left:_!=null?`${_}px`:"",top:T!=null?`${T}px`:"",right:"",bottom:"",...Q,[O]:`-${y/2+K}px`},place:E}})):Vy(n,l,{placement:"bottom",strategy:u,middleware:p}).then(({x:v,y:b,placement:E})=>({tooltipStyles:{left:`${v}px`,top:`${b}px`},tooltipArrowStyles:{},place:E}))},Jy=(n,l)=>!("CSS"in window&&"supports"in window.CSS)||window.CSS.supports(n,l),Iy=(n,l,r)=>{let s=null;const o=function(...u){const d=()=>{s=null};!s&&(n.apply(this,u),s=setTimeout(d,l))};return o.cancel=()=>{s&&(clearTimeout(s),s=null)},o},Wy=n=>n!==null&&!Array.isArray(n)&&typeof n=="object",Dd=(n,l)=>{if(n===l)return!0;if(Array.isArray(n)&&Array.isArray(l))return n.length===l.length&&n.every((o,u)=>Dd(o,l[u]));if(Array.isArray(n)!==Array.isArray(l))return!1;if(!Wy(n)||!Wy(l))return n===l;const r=Object.keys(n),s=Object.keys(l);return r.length===s.length&&r.every(o=>Dd(n[o],l[o]))},G6=n=>{if(!(n instanceof HTMLElement||n instanceof SVGElement))return!1;const l=getComputedStyle(n);return["overflow","overflow-x","overflow-y"].some(r=>{const s=l.getPropertyValue(r);return s==="auto"||s==="scroll"})},ev=n=>{if(!n)return null;let l=n.parentElement;for(;l;){if(G6(l))return l;l=l.parentElement}return document.scrollingElement||document.documentElement},X6=typeof window<"u"?x.useLayoutEffect:x.useEffect,Tn=n=>{n.current&&(clearTimeout(n.current),n.current=null)},Z6="DEFAULT_TOOLTIP_ID",P6={anchorRefs:new Set,activeAnchor:{current:null},attach:()=>{},detach:()=>{},setActiveAnchor:()=>{}},J6=x.createContext({getTooltipData:()=>P6});function Y1(n=Z6){return x.useContext(J6).getTooltipData(n)}var ki={tooltip:"core-styles-module_tooltip__3vRRp",fixed:"core-styles-module_fixed__pcSol",arrow:"core-styles-module_arrow__cvMwQ",noArrow:"core-styles-module_noArrow__xock6",clickable:"core-styles-module_clickable__ZuTTB",show:"core-styles-module_show__Nt9eE",closing:"core-styles-module_closing__sGnxF"},rd={tooltip:"styles-module_tooltip__mnnfp",arrow:"styles-module_arrow__K0L3T",dark:"styles-module_dark__xNqje",light:"styles-module_light__Z6W-X",success:"styles-module_success__A2AKt",warning:"styles-module_warning__SCK0X",error:"styles-module_error__JvumD",info:"styles-module_info__BWdHW"};const I6=({forwardRef:n,id:l,className:r,classNameArrow:s,variant:o="dark",anchorId:u,anchorSelect:d,place:m="top",offset:y=10,events:p=["hover"],openOnClick:v=!1,positionStrategy:b="absolute",middlewares:E,wrapper:C,delayShow:w=0,delayHide:N=0,float:j=!1,hidden:_=!1,noArrow:T=!1,clickable:O=!1,closeOnEsc:Q=!1,closeOnScroll:K=!1,closeOnResize:H=!1,openEvents:G,closeEvents:Z,globalCloseEvents:te,imperativeModeOnly:pe,style:Oe,position:be,afterShow:Ue,afterHide:ye,disableTooltip:Se,content:k,contentWrapperRef:X,isOpen:J,defaultIsOpen:ue=!1,setIsOpen:R,activeAnchor:$,setActiveAnchor:W,border:I,opacity:se,arrowColor:Ce,arrowSize:ce=8,role:St="tooltip"})=>{var qe;const Ze=x.useRef(null),Qn=x.useRef(null),Nt=x.useRef(null),hn=x.useRef(null),oa=x.useRef(null),[mn,ls]=x.useState({tooltipStyles:{},tooltipArrowStyles:{},place:m}),[zt,kt]=x.useState(!1),[ua,$n]=x.useState(!1),[Ge,Yn]=x.useState(null),bl=x.useRef(!1),La=x.useRef(null),{anchorRefs:xl,setActiveAnchor:Il}=Y1(l),pn=x.useRef(!1),[tt,Kt]=x.useState([]),it=x.useRef(!1),Ua=v||p.includes("click"),is=Ua||(G==null?void 0:G.click)||(G==null?void 0:G.dblclick)||(G==null?void 0:G.mousedown),qa=G?{...G}:{mouseover:!0,focus:!0,mouseenter:!1,click:!1,dblclick:!1,mousedown:!1};!G&&Ua&&Object.assign(qa,{mouseenter:!1,focus:!1,mouseover:!1,click:!0});const yn=Z?{...Z}:{mouseout:!0,blur:!0,mouseleave:!1,click:!1,dblclick:!1,mouseup:!1};!Z&&Ua&&Object.assign(yn,{mouseleave:!1,blur:!1,mouseout:!1});const At=te?{...te}:{escape:Q||!1,scroll:K||!1,resize:H||!1,clickOutsideAnchor:is||!1};pe&&(Object.assign(qa,{mouseover:!1,focus:!1,mouseenter:!1,click:!1,dblclick:!1,mousedown:!1}),Object.assign(yn,{mouseout:!1,blur:!1,mouseleave:!1,click:!1,dblclick:!1,mouseup:!1}),Object.assign(At,{escape:!1,scroll:!1,resize:!1,clickOutsideAnchor:!1})),X6(()=>(it.current=!0,()=>{it.current=!1}),[]);const He=P=>{it.current&&(P&&$n(!0),setTimeout(()=>{it.current&&(R==null||R(P),J===void 0&&kt(P))},10))};x.useEffect(()=>{if(J===void 0)return()=>null;J&&$n(!0);const P=setTimeout(()=>{kt(J)},10);return()=>{clearTimeout(P)}},[J]),x.useEffect(()=>{if(zt!==bl.current)if(Tn(oa),bl.current=zt,zt)Ue==null||Ue();else{const P=(ne=>{const de=ne.match(/^([\d.]+)(ms|s)$/);if(!de)return 0;const[,Ie,vt]=de;return Number(Ie)*(vt==="ms"?1:1e3)})(getComputedStyle(document.body).getPropertyValue("--rt-transition-show-delay"));oa.current=setTimeout(()=>{$n(!1),Yn(null),ye==null||ye()},P+25)}},[zt]);const ca=P=>{ls(ne=>Dd(ne,P)?ne:P)},On=(P=w)=>{Tn(Nt),ua?He(!0):Nt.current=setTimeout(()=>{He(!0)},P)},za=(P=N)=>{Tn(hn),hn.current=setTimeout(()=>{pn.current||He(!1)},P)},ka=P=>{var ne;if(!P)return;const de=(ne=P.currentTarget)!==null&&ne!==void 0?ne:P.target;if(!(de!=null&&de.isConnected))return W(null),void Il({current:null});w?On():He(!0),W(de),Il({current:de}),Tn(hn)},fa=()=>{O?za(N||100):N?za():He(!1),Tn(Nt)},Kn=({x:P,y:ne})=>{var de;const Ie={getBoundingClientRect:()=>({x:P,y:ne,width:0,height:0,top:ne,left:P,right:P,bottom:ne})};Py({place:(de=Ge==null?void 0:Ge.place)!==null&&de!==void 0?de:m,offset:y,elementReference:Ie,tooltipReference:Ze.current,tooltipArrowReference:Qn.current,strategy:b,middlewares:E,border:I,arrowSize:ce}).then(vt=>{ca(vt)})},vn=P=>{if(!P)return;const ne=P,de={x:ne.clientX,y:ne.clientY};Kn(de),La.current=de},Sl=P=>{var ne;if(!zt)return;const de=P.target;de.isConnected&&(!((ne=Ze.current)===null||ne===void 0)&&ne.contains(de)||[document.querySelector(`[id='${u}']`),...tt].some(Ie=>Ie==null?void 0:Ie.contains(de))||(He(!1),Tn(Nt)))},wl=Iy(ka,50),st=Iy(fa,50),Tt=P=>{st.cancel(),wl(P)},oe=()=>{wl.cancel(),st()},_e=x.useCallback(()=>{var P,ne;const de=(P=Ge==null?void 0:Ge.position)!==null&&P!==void 0?P:be;de?Kn(de):j?La.current&&Kn(La.current):$!=null&&$.isConnected&&Py({place:(ne=Ge==null?void 0:Ge.place)!==null&&ne!==void 0?ne:m,offset:y,elementReference:$,tooltipReference:Ze.current,tooltipArrowReference:Qn.current,strategy:b,middlewares:E,border:I,arrowSize:ce}).then(Ie=>{it.current&&ca(Ie)})},[zt,$,k,Oe,m,Ge==null?void 0:Ge.place,y,b,be,Ge==null?void 0:Ge.position,j,ce]);x.useEffect(()=>{var P,ne;const de=new Set(xl);tt.forEach(Me=>{Se!=null&&Se(Me)||de.add({current:Me})});const Ie=document.querySelector(`[id='${u}']`);Ie&&!(Se!=null&&Se(Ie))&&de.add({current:Ie});const vt=()=>{He(!1)},gn=ev($),en=ev(Ze.current);At.scroll&&(window.addEventListener("scroll",vt),gn==null||gn.addEventListener("scroll",vt),en==null||en.addEventListener("scroll",vt));let rt=null;At.resize?window.addEventListener("resize",vt):$&&Ze.current&&(rt=k6($,Ze.current,_e,{ancestorResize:!0,elementResize:!0,layoutShift:!0}));const Ot=Me=>{Me.key==="Escape"&&He(!1)};At.escape&&window.addEventListener("keydown",Ot),At.clickOutsideAnchor&&window.addEventListener("click",Sl);const De=[],tn=Me=>!!(Me!=null&&Me.target&&($!=null&&$.contains(Me.target))),El=Me=>{zt&&tn(Me)||ka(Me)},Ba=Me=>{zt&&tn(Me)&&fa()},ot=["mouseover","mouseout","mouseenter","mouseleave","focus","blur"],ss=["click","dblclick","mousedown","mouseup"];Object.entries(qa).forEach(([Me,bn])=>{bn&&(ot.includes(Me)?De.push({event:Me,listener:Tt}):ss.includes(Me)&&De.push({event:Me,listener:El}))}),Object.entries(yn).forEach(([Me,bn])=>{bn&&(ot.includes(Me)?De.push({event:Me,listener:oe}):ss.includes(Me)&&De.push({event:Me,listener:Ba}))}),j&&De.push({event:"pointermove",listener:vn});const rs=()=>{pn.current=!0},Vn=()=>{pn.current=!1,fa()},da=O&&(yn.mouseout||yn.mouseleave);return da&&((P=Ze.current)===null||P===void 0||P.addEventListener("mouseover",rs),(ne=Ze.current)===null||ne===void 0||ne.addEventListener("mouseout",Vn)),De.forEach(({event:Me,listener:bn})=>{de.forEach(Wl=>{var Cl;(Cl=Wl.current)===null||Cl===void 0||Cl.addEventListener(Me,bn)})}),()=>{var Me,bn;At.scroll&&(window.removeEventListener("scroll",vt),gn==null||gn.removeEventListener("scroll",vt),en==null||en.removeEventListener("scroll",vt)),At.resize?window.removeEventListener("resize",vt):rt==null||rt(),At.clickOutsideAnchor&&window.removeEventListener("click",Sl),At.escape&&window.removeEventListener("keydown",Ot),da&&((Me=Ze.current)===null||Me===void 0||Me.removeEventListener("mouseover",rs),(bn=Ze.current)===null||bn===void 0||bn.removeEventListener("mouseout",Vn)),De.forEach(({event:Wl,listener:Cl})=>{de.forEach(ei=>{var Ha;(Ha=ei.current)===null||Ha===void 0||Ha.removeEventListener(Wl,Cl)})})}},[$,_e,ua,xl,tt,G,Z,te,Ua,w,N]),x.useEffect(()=>{var P,ne;let de=(ne=(P=Ge==null?void 0:Ge.anchorSelect)!==null&&P!==void 0?P:d)!==null&&ne!==void 0?ne:"";!de&&l&&(de=`[data-tooltip-id='${l.replace(/'/g,"\\'")}']`);const Ie=new MutationObserver(vt=>{const gn=[],en=[];vt.forEach(rt=>{if(rt.type==="attributes"&&rt.attributeName==="data-tooltip-id"&&(rt.target.getAttribute("data-tooltip-id")===l?gn.push(rt.target):rt.oldValue===l&&en.push(rt.target)),rt.type==="childList"){if($){const Ot=[...rt.removedNodes].filter(De=>De.nodeType===1);if(de)try{en.push(...Ot.filter(De=>De.matches(de))),en.push(...Ot.flatMap(De=>[...De.querySelectorAll(de)]))}catch{}Ot.some(De=>{var tn;return!!(!((tn=De==null?void 0:De.contains)===null||tn===void 0)&&tn.call(De,$))&&($n(!1),He(!1),W(null),Tn(Nt),Tn(hn),!0)})}if(de)try{const Ot=[...rt.addedNodes].filter(De=>De.nodeType===1);gn.push(...Ot.filter(De=>De.matches(de))),gn.push(...Ot.flatMap(De=>[...De.querySelectorAll(de)]))}catch{}}}),(gn.length||en.length)&&Kt(rt=>[...rt.filter(Ot=>!en.includes(Ot)),...gn])});return Ie.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-tooltip-id"],attributeOldValue:!0}),()=>{Ie.disconnect()}},[l,d,Ge==null?void 0:Ge.anchorSelect,$]),x.useEffect(()=>{_e()},[_e]),x.useEffect(()=>{if(!(X!=null&&X.current))return()=>null;const P=new ResizeObserver(()=>{setTimeout(()=>_e())});return P.observe(X.current),()=>{P.disconnect()}},[k,X==null?void 0:X.current]),x.useEffect(()=>{var P;const ne=document.querySelector(`[id='${u}']`),de=[...tt,ne];$&&de.includes($)||W((P=tt[0])!==null&&P!==void 0?P:ne)},[u,tt,$]),x.useEffect(()=>(ue&&He(!0),()=>{Tn(Nt),Tn(hn)}),[]),x.useEffect(()=>{var P;let ne=(P=Ge==null?void 0:Ge.anchorSelect)!==null&&P!==void 0?P:d;if(!ne&&l&&(ne=`[data-tooltip-id='${l.replace(/'/g,"\\'")}']`),ne)try{const de=Array.from(document.querySelectorAll(ne));Kt(de)}catch{Kt([])}},[l,d,Ge==null?void 0:Ge.anchorSelect]),x.useEffect(()=>{Nt.current&&(Tn(Nt),On(w))},[w]);const Bt=(qe=Ge==null?void 0:Ge.content)!==null&&qe!==void 0?qe:k,Rt=zt&&Object.keys(mn.tooltipStyles).length>0;return x.useImperativeHandle(n,()=>({open:P=>{if(P!=null&&P.anchorSelect)try{document.querySelector(P.anchorSelect)}catch{return void console.warn(`[react-tooltip] "${P.anchorSelect}" is not a valid CSS selector`)}Yn(P??null),P!=null&&P.delay?On(P.delay):He(!0)},close:P=>{P!=null&&P.delay?za(P.delay):He(!1)},activeAnchor:$,place:mn.place,isOpen:!!(ua&&!_&&Bt&&Rt)})),ua&&!_&&Bt?Ve.createElement(C,{id:l,role:St,className:Od("react-tooltip",ki.tooltip,rd.tooltip,rd[o],r,`react-tooltip__place-${mn.place}`,ki[Rt?"show":"closing"],Rt?"react-tooltip__show":"react-tooltip__closing",b==="fixed"&&ki.fixed,O&&ki.clickable),onTransitionEnd:P=>{Tn(oa),zt||P.propertyName!=="opacity"||($n(!1),Yn(null),ye==null||ye())},style:{...Oe,...mn.tooltipStyles,opacity:se!==void 0&&Rt?se:void 0},ref:Ze},Bt,Ve.createElement(C,{className:Od("react-tooltip-arrow",ki.arrow,rd.arrow,s,T&&ki.noArrow),style:{...mn.tooltipArrowStyles,background:Ce?`linear-gradient(to right bottom, transparent 50%, ${Ce} 50%)`:void 0,"--rt-arrow-size":`${ce}px`},ref:Qn})):null},W6=({content:n})=>Ve.createElement("span",{dangerouslySetInnerHTML:{__html:n}}),fh=Ve.forwardRef(({id:n,anchorId:l,anchorSelect:r,content:s,html:o,render:u,className:d,classNameArrow:m,variant:y="dark",place:p="top",offset:v=10,wrapper:b="div",children:E=null,events:C=["hover"],openOnClick:w=!1,positionStrategy:N="absolute",middlewares:j,delayShow:_=0,delayHide:T=0,float:O=!1,hidden:Q=!1,noArrow:K=!1,clickable:H=!1,closeOnEsc:G=!1,closeOnScroll:Z=!1,closeOnResize:te=!1,openEvents:pe,closeEvents:Oe,globalCloseEvents:be,imperativeModeOnly:Ue=!1,style:ye,position:Se,isOpen:k,defaultIsOpen:X=!1,disableStyleInjection:J=!1,border:ue,opacity:R,arrowColor:$,arrowSize:W,setIsOpen:I,afterShow:se,afterHide:Ce,disableTooltip:ce,role:St="tooltip"},qe)=>{const[Ze,Qn]=x.useState(s),[Nt,hn]=x.useState(o),[oa,mn]=x.useState(p),[ls,zt]=x.useState(y),[kt,ua]=x.useState(v),[$n,Ge]=x.useState(_),[Yn,bl]=x.useState(T),[La,xl]=x.useState(O),[Il,pn]=x.useState(Q),[tt,Kt]=x.useState(b),[it,Ua]=x.useState(C),[is,qa]=x.useState(N),[yn,At]=x.useState(null),[He,ca]=x.useState(null),On=x.useRef(J),{anchorRefs:za,activeAnchor:ka}=Y1(n),fa=st=>st==null?void 0:st.getAttributeNames().reduce((Tt,oe)=>{var _e;return oe.startsWith("data-tooltip-")&&(Tt[oe.replace(/^data-tooltip-/,"")]=(_e=st==null?void 0:st.getAttribute(oe))!==null&&_e!==void 0?_e:null),Tt},{}),Kn=st=>{const Tt={place:oe=>{var _e;mn((_e=oe)!==null&&_e!==void 0?_e:p)},content:oe=>{Qn(oe??s)},html:oe=>{hn(oe??o)},variant:oe=>{var _e;zt((_e=oe)!==null&&_e!==void 0?_e:y)},offset:oe=>{ua(oe===null?v:Number(oe))},wrapper:oe=>{var _e;Kt((_e=oe)!==null&&_e!==void 0?_e:b)},events:oe=>{const _e=oe==null?void 0:oe.split(" ");Ua(_e??C)},"position-strategy":oe=>{var _e;qa((_e=oe)!==null&&_e!==void 0?_e:N)},"delay-show":oe=>{Ge(oe===null?_:Number(oe))},"delay-hide":oe=>{bl(oe===null?T:Number(oe))},float:oe=>{xl(oe===null?O:oe==="true")},hidden:oe=>{pn(oe===null?Q:oe==="true")},"class-name":oe=>{At(oe)}};Object.values(Tt).forEach(oe=>oe(null)),Object.entries(st).forEach(([oe,_e])=>{var Bt;(Bt=Tt[oe])===null||Bt===void 0||Bt.call(Tt,_e)})};x.useEffect(()=>{Qn(s)},[s]),x.useEffect(()=>{hn(o)},[o]),x.useEffect(()=>{mn(p)},[p]),x.useEffect(()=>{zt(y)},[y]),x.useEffect(()=>{ua(v)},[v]),x.useEffect(()=>{Ge(_)},[_]),x.useEffect(()=>{bl(T)},[T]),x.useEffect(()=>{xl(O)},[O]),x.useEffect(()=>{pn(Q)},[Q]),x.useEffect(()=>{qa(N)},[N]),x.useEffect(()=>{On.current!==J&&console.warn("[react-tooltip] Do not change `disableStyleInjection` dynamically.")},[J]),x.useEffect(()=>{typeof window<"u"&&window.dispatchEvent(new CustomEvent("react-tooltip-inject-styles",{detail:{disableCore:J==="core",disableBase:J}}))},[]),x.useEffect(()=>{var st;const Tt=new Set(za);let oe=r;if(!oe&&n&&(oe=`[data-tooltip-id='${n.replace(/'/g,"\\'")}']`),oe)try{document.querySelectorAll(oe).forEach(ne=>{Tt.add({current:ne})})}catch{console.warn(`[react-tooltip] "${oe}" is not a valid CSS selector`)}const _e=document.querySelector(`[id='${l}']`);if(_e&&Tt.add({current:_e}),!Tt.size)return()=>null;const Bt=(st=He??_e)!==null&&st!==void 0?st:ka.current,Rt=new MutationObserver(ne=>{ne.forEach(de=>{var Ie;if(!Bt||de.type!=="attributes"||!(!((Ie=de.attributeName)===null||Ie===void 0)&&Ie.startsWith("data-tooltip-")))return;const vt=fa(Bt);Kn(vt)})}),P={attributes:!0,childList:!1,subtree:!1};if(Bt){const ne=fa(Bt);Kn(ne),Rt.observe(Bt,P)}return()=>{Rt.disconnect()}},[za,ka,He,l,r]),x.useEffect(()=>{ye!=null&&ye.border&&console.warn("[react-tooltip] Do not set `style.border`. Use `border` prop instead."),ue&&!Jy("border",`${ue}`)&&console.warn(`[react-tooltip] "${ue}" is not a valid \`border\`.`),ye!=null&&ye.opacity&&console.warn("[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead."),R&&!Jy("opacity",`${R}`)&&console.warn(`[react-tooltip] "${R}" is not a valid \`opacity\`.`)},[]);let vn=E;const Sl=x.useRef(null);if(u){const st=u({content:(He==null?void 0:He.getAttribute("data-tooltip-content"))||Ze||null,activeAnchor:He});vn=st?Ve.createElement("div",{ref:Sl,className:"react-tooltip-content-wrapper"},st):null}else Ze&&(vn=Ze);Nt&&(vn=Ve.createElement(W6,{content:Nt}));const wl={forwardRef:qe,id:n,anchorId:l,anchorSelect:r,className:Od(d,yn),classNameArrow:m,content:vn,contentWrapperRef:Sl,place:oa,variant:ls,offset:kt,wrapper:tt,events:it,openOnClick:w,positionStrategy:is,middlewares:j,delayShow:$n,delayHide:Yn,float:La,hidden:Il,noArrow:K,clickable:H,closeOnEsc:G,closeOnScroll:Z,closeOnResize:te,openEvents:pe,closeEvents:Oe,globalCloseEvents:be,imperativeModeOnly:Ue,style:ye,position:Se,isOpen:k,defaultIsOpen:X,border:ue,opacity:R,arrowColor:$,arrowSize:W,setIsOpen:I,afterShow:se,afterHide:Ce,disableTooltip:ce,activeAnchor:He,setActiveAnchor:st=>ca(st),role:St};return Ve.createElement(I6,{...wl})});typeof window<"u"&&window.addEventListener("react-tooltip-inject-styles",n=>{n.detail.disableCore||Zy({css:":root{--rt-color-white:#fff;--rt-color-dark:#222;--rt-color-success:#8dc572;--rt-color-error:#be6464;--rt-color-warning:#f0ad4e;--rt-color-info:#337ab7;--rt-opacity:0.9;--rt-transition-show-delay:0.15s;--rt-transition-closing-delay:0.15s;--rt-arrow-size:8px}.core-styles-module_tooltip__3vRRp{position:absolute;top:0;left:0;pointer-events:none;opacity:0;will-change:opacity}.core-styles-module_fixed__pcSol{position:fixed}.core-styles-module_arrow__cvMwQ{position:absolute;background:inherit;z-index:-1}.core-styles-module_noArrow__xock6{display:none}.core-styles-module_clickable__ZuTTB{pointer-events:auto}.core-styles-module_show__Nt9eE{opacity:var(--rt-opacity);transition:opacity var(--rt-transition-show-delay)ease-out}.core-styles-module_closing__sGnxF{opacity:0;transition:opacity var(--rt-transition-closing-delay)ease-in}",type:"core"}),n.detail.disableBase||Zy({css:`
237
- .styles-module_tooltip__mnnfp{padding:8px 16px;border-radius:3px;font-size:90%;width:max-content}.styles-module_arrow__K0L3T{width:var(--rt-arrow-size);height:var(--rt-arrow-size)}[class*='react-tooltip__place-top']>.styles-module_arrow__K0L3T{transform:rotate(45deg)}[class*='react-tooltip__place-right']>.styles-module_arrow__K0L3T{transform:rotate(135deg)}[class*='react-tooltip__place-bottom']>.styles-module_arrow__K0L3T{transform:rotate(225deg)}[class*='react-tooltip__place-left']>.styles-module_arrow__K0L3T{transform:rotate(315deg)}.styles-module_dark__xNqje{background:var(--rt-color-dark);color:var(--rt-color-white)}.styles-module_light__Z6W-X{background-color:var(--rt-color-white);color:var(--rt-color-dark)}.styles-module_success__A2AKt{background-color:var(--rt-color-success);color:var(--rt-color-white)}.styles-module_warning__SCK0X{background-color:var(--rt-color-warning);color:var(--rt-color-white)}.styles-module_error__JvumD{background-color:var(--rt-color-error);color:var(--rt-color-white)}.styles-module_info__BWdHW{background-color:var(--rt-color-info);color:var(--rt-color-white)}`,type:"base"})});const e_=n=>x.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},x.createElement("path",{d:"M320 146s24.36-12-64-12a160 160 0 10160 160",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeMiterlimit:10,strokeWidth:32}),x.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M256 58l80 80-80 80"})),t_=n=>x.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},x.createElement("rect",{x:128,y:128,width:336,height:336,rx:57,ry:57,fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:32}),x.createElement("path",{d:"M383.5 128l.5-24a56.16 56.16 0 00-56-56H112a64.19 64.19 0 00-64 64v216a56.16 56.16 0 0056 56h24M296 216v160M376 296H216",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32})),n_=n=>x.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},x.createElement("circle",{cx:128,cy:256,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),x.createElement("circle",{cx:384,cy:112,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),x.createElement("circle",{cx:384,cy:400,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),x.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M169.83 279.53l172.34 96.94M342.17 135.53l-172.34 96.94"})),K1=["shift","alt","meta","mod","ctrl","control"],a_={esc:"escape",return:"enter",left:"arrowleft",right:"arrowright",up:"arrowup",down:"arrowdown",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",OSLeft:"meta",OSRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function hl(n){return(a_[n.trim()]||n.trim()).toLowerCase().replace(/key|digit|numpad/,"")}function V1(n){return K1.includes(n)}function od(n,l=","){return n.toLowerCase().split(l)}function ud(n,l="+",r=">",s=!1,o){let u=[],d=!1;n=n.trim(),n.includes(r)?(d=!0,u=n.toLocaleLowerCase().split(r).map(p=>hl(p))):u=n.toLocaleLowerCase().split(l).map(p=>hl(p));const m={alt:u.includes("alt"),ctrl:u.includes("ctrl")||u.includes("control"),shift:u.includes("shift"),meta:u.includes("meta"),mod:u.includes("mod"),useKey:s},y=u.filter(p=>!K1.includes(p));return{...m,keys:y,description:o,isSequence:d,hotkey:n}}typeof document<"u"&&(document.addEventListener("keydown",n=>{n.code!==void 0&&F1([hl(n.code)])}),document.addEventListener("keyup",n=>{n.code!==void 0&&G1([hl(n.code)])})),typeof window<"u"&&(window.addEventListener("blur",()=>{Ra.clear()}),window.addEventListener("contextmenu",()=>{setTimeout(()=>{Ra.clear()},0)}));const Ra=new Set;function dh(n){return Array.isArray(n)}function l_(n,l=","){return(dh(n)?n:n.split(l)).every(r=>Ra.has(r.trim().toLowerCase()))}function F1(n){const l=Array.isArray(n)?n:[n];Ra.has("meta")&&Ra.forEach(r=>!V1(r)&&Ra.delete(r.toLowerCase())),l.forEach(r=>Ra.add(r.toLowerCase()))}function G1(n){const l=Array.isArray(n)?n:[n];n==="meta"?Ra.clear():l.forEach(r=>Ra.delete(r.toLowerCase()))}function i_(n,l,r){(typeof r=="function"&&r(n,l)||r===!0)&&n.preventDefault()}function s_(n,l,r){return typeof r=="function"?r(n,l):r===!0||r===void 0}const r_=["input","textarea","select","searchbox","slider","spinbutton","menuitem","menuitemcheckbox","menuitemradio","option","radio","textbox"];function o_(n){return X1(n,r_)}function X1(n,l=!1){const{target:r,composed:s}=n;let o,u;return u_(r)&&s?(o=n.composedPath()[0]&&n.composedPath()[0].tagName,u=n.composedPath()[0]&&n.composedPath()[0].role):(o=r&&r.tagName,u=r&&r.role),dh(l)?!!(o&&l&&l.some(d=>d.toLowerCase()===o.toLowerCase()||d===u)):!!(o&&l&&l)}function u_(n){return!!n.tagName&&!n.tagName.startsWith("-")&&n.tagName.includes("-")}function c_(n,l){return n.length===0&&l?(console.warn('A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'),!0):l?n.some(r=>l.includes(r))||n.includes("*"):!0}const f_=(n,l,r=!1)=>{const{alt:s,meta:o,mod:u,shift:d,ctrl:m,keys:y,useKey:p}=l,{code:v,key:b,ctrlKey:E,metaKey:C,shiftKey:w,altKey:N}=n,j=hl(v);if(p&&(y==null?void 0:y.length)===1&&y.includes(b))return!0;if(!(y!=null&&y.includes(j))&&!["ctrl","control","unknown","meta","alt","shift","os"].includes(j))return!1;if(!r){if(s!==N&&j!=="alt"||d!==w&&j!=="shift")return!1;if(u){if(!C&&!E)return!1}else if(o!==C&&j!=="meta"&&j!=="os"||m!==E&&j!=="ctrl"&&j!=="control")return!1}return y&&y.length===1&&y.includes(j)?!0:y?l_(y):!y},d_=x.createContext(void 0),h_=()=>x.useContext(d_);function Z1(n,l){return n&&l&&typeof n=="object"&&typeof l=="object"?Object.keys(n).length===Object.keys(l).length&&Object.keys(n).reduce((r,s)=>r&&Z1(n[s],l[s]),!0):n===l}const m_=x.createContext({hotkeys:[],activeScopes:[],toggleScope:()=>{},enableScope:()=>{},disableScope:()=>{}}),p_=()=>x.useContext(m_);function y_(n){const l=x.useRef(void 0);return Z1(l.current,n)||(l.current=n),l.current}const tv=n=>{n.stopPropagation(),n.preventDefault(),n.stopImmediatePropagation()},v_=typeof window<"u"?x.useLayoutEffect:x.useEffect;function $t(n,l,r,s){const o=x.useRef(null),u=x.useRef(!1),d=Array.isArray(r)?Array.isArray(s)?void 0:s:r,m=dh(n)?n.join(d==null?void 0:d.delimiter):n,y=Array.isArray(r)?r:Array.isArray(s)?s:void 0,p=x.useCallback(l,y??[]),v=x.useRef(p);y?v.current=p:v.current=l;const b=y_(d),{activeScopes:E}=p_(),C=h_();return v_(()=>{if((b==null?void 0:b.enabled)===!1||!c_(E,b==null?void 0:b.scopes))return;let w=[],N;const j=(Q,K=!1)=>{var H;if(!(o_(Q)&&!X1(Q,b==null?void 0:b.enableOnFormTags))){if(o.current!==null){const G=o.current.getRootNode();if((G instanceof Document||G instanceof ShadowRoot)&&G.activeElement!==o.current&&!o.current.contains(G.activeElement)){tv(Q);return}}(H=Q.target)!=null&&H.isContentEditable&&!(b!=null&&b.enableOnContentEditable)||od(m,b==null?void 0:b.delimiter).forEach(G=>{var te,pe,Oe,be;if(G.includes((b==null?void 0:b.splitKey)??"+")&&G.includes((b==null?void 0:b.sequenceSplitKey)??">")){console.warn(`Hotkey ${G} contains both ${(b==null?void 0:b.splitKey)??"+"} and ${(b==null?void 0:b.sequenceSplitKey)??">"} which is not supported.`);return}const Z=ud(G,b==null?void 0:b.splitKey,b==null?void 0:b.sequenceSplitKey,b==null?void 0:b.useKey,b==null?void 0:b.description);if(Z.isSequence){N=setTimeout(()=>{w=[]},(b==null?void 0:b.sequenceTimeoutMs)??1e3);const Ue=Z.useKey?Q.key:hl(Q.code);if(V1(Ue.toLowerCase()))return;w.push(Ue);const ye=(te=Z.keys)==null?void 0:te[w.length-1];if(Ue!==ye){w=[],N&&clearTimeout(N);return}w.length===((pe=Z.keys)==null?void 0:pe.length)&&(v.current(Q,Z),N&&clearTimeout(N),w=[])}else if(f_(Q,Z,b==null?void 0:b.ignoreModifiers)||(Oe=Z.keys)!=null&&Oe.includes("*")){if((be=b==null?void 0:b.ignoreEventWhen)!=null&&be.call(b,Q)||K&&u.current)return;if(i_(Q,Z,b==null?void 0:b.preventDefault),!s_(Q,Z,b==null?void 0:b.enabled)){tv(Q);return}v.current(Q,Z),K||(u.current=!0)}})}},_=Q=>{Q.code!==void 0&&(F1(hl(Q.code)),((b==null?void 0:b.keydown)===void 0&&(b==null?void 0:b.keyup)!==!0||b!=null&&b.keydown)&&j(Q))},T=Q=>{Q.code!==void 0&&(G1(hl(Q.code)),u.current=!1,b!=null&&b.keyup&&j(Q,!0))},O=o.current||(d==null?void 0:d.document)||document;return O.addEventListener("keyup",T,d==null?void 0:d.eventListenerOptions),O.addEventListener("keydown",_,d==null?void 0:d.eventListenerOptions),C&&od(m,b==null?void 0:b.delimiter).forEach(Q=>C.addHotkey(ud(Q,b==null?void 0:b.splitKey,b==null?void 0:b.sequenceSplitKey,b==null?void 0:b.useKey,b==null?void 0:b.description))),()=>{O.removeEventListener("keyup",T,d==null?void 0:d.eventListenerOptions),O.removeEventListener("keydown",_,d==null?void 0:d.eventListenerOptions),C&&od(m,b==null?void 0:b.delimiter).forEach(Q=>C.removeHotkey(ud(Q,b==null?void 0:b.splitKey,b==null?void 0:b.sequenceSplitKey,b==null?void 0:b.useKey,b==null?void 0:b.description))),w=[],N&&clearTimeout(N)}},[m,b,E]),o}function g_(){return h.jsxs("div",{className:"flex items-center bg-white border-b border-gray-200 overflow-auto no-scrollbar",children:[h.jsx(b_,{}),h.jsx(S_,{})]})}function b_(){const{dataSourceId:n,name:l}=x.useContext(ia),{data:r}=Tu(n),{data:s}=x.useContext(sa),o=_r(Zt.EDITOR),u=i6(),{rename:d}=O1(),m=()=>{var v,b;(v=s==null?void 0:s.result.columns)!=null&&v[0].table&&Id({table:(b=s==null?void 0:s.result.columns)==null?void 0:b[0].table,dataSourceId:n})},y=async()=>{const v=await Nr("Query name",l);!v||!(s!=null&&s.result.queryHistoryId)||u.mutate({name:v,queryId:s.result.queryHistoryId})},p=()=>d(l);return $t("s",y),$t("r",p),h.jsxs("div",{className:ae.tableConfig,children:[h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Manage filters",onClick:()=>Un("filters"),className:le(ae.tableAction,ae.blue),children:[h.jsx("span",{children:"Filter"}),h.jsx("span",{className:"hotkey",children:"F"})]}),h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Join tables",onClick:()=>Un("joins"),className:le(ae.tableAction,ae.blue),children:[h.jsx("span",{children:"Join"}),h.jsx("span",{className:"hotkey",children:"J"})]}),h.jsx(w_,{}),h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Clone in a new tab",onClick:p,className:le(ae.tableAction,ae.blue),children:[h.jsx("span",{children:"Rename"}),h.jsx("span",{className:"hotkey",children:"R"})]}),h.jsxs("button",{"data-tooltip-id":"explorer-more-actions",className:le(ae.tableAction,ae.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"More actions"}),h.jsx(mr,{width:16,height:16,className:"rotate-90"})]}),h.jsxs(fh,{id:"explorer-more-actions",className:"z-10 shadow-md flex flex-col",clickable:!0,variant:"light",opacity:1,children:[h.jsxs("button",{onClick:()=>Un("columns"),className:le(ae.tableAction,ae.modal,ae.blue,"justify-between"),children:[h.jsx("span",{children:"Columns"}),h.jsx("span",{className:"hotkey",children:"C"})]}),h.jsxs("button",{onClick:()=>Un("groupBy"),className:le(ae.tableAction,ae.modal,ae.blue,"justify-between"),children:[h.jsx("span",{children:"Group by"}),h.jsx("span",{className:"hotkey",children:"G"})]}),h.jsxs("button",{onClick:()=>Un("aggregate"),className:le(ae.tableAction,ae.modal,ae.blue,"justify-between"),children:[h.jsx("span",{children:"Aggregate"}),h.jsx("span",{className:"hotkey",children:"A"})]}),h.jsxs("button",{onClick:ah,className:le(ae.tableAction,ae.modal,ae.blue,"justify-between"),children:[h.jsx("span",{children:"Query editor"}),h.jsx("span",{className:"hotkey",children:"E"})]}),o&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-0.5 my-2 bg-gray-100"}),h.jsxs("button",{onClick:y,className:le(ae.tableAction,ae.modal,ae.blue),children:[h.jsx("span",{children:"Save query"}),h.jsx("span",{className:"hotkey",children:"S"})]}),(r==null?void 0:r.allowInsert)===!0&&h.jsx("button",{onClick:m,className:le(ae.tableAction,ae.modal,ae.blue),children:"Insert new row"})]})]})]})}const x_=[5,10,20,50,100,200];function S_(){const{page:n,size:l,setPage:r,setSize:s}=l6(),{data:o,refetch:u}=x.useContext(sa),{name:d}=x.useContext(ia),{state:m}=x.useContext(mt),y=ns(),p=qt(),v=n*l,b=()=>{y.mutateAsync({name:d,opts:m}).then(N=>{p(`${Fe.workbench.path}/tab/${N.id}`)})},E=()=>{if(o!=null&&o.result.queryHistoryId){const N=new URL(window.location.href);N.pathname=Fe.share.path,N.searchParams.set("shareId",o.result.queryHistoryId),navigator.clipboard.writeText(N.toString()),It.success("Share link copied to clipboard")}};$t("e",ah),$t("d",b);const C=()=>{n>0&&r(n-1)},w=()=>{console.log(o==null?void 0:o.result.hasMore),o!=null&&o.result.hasMore&&r(n+1)};return h.jsxs("div",{className:ae.tableConfig,children:[h.jsxs("span",{className:ae.paginationIndicator,"data-tooltip-id":"rows-num",children:[v+1," - ",v+l]}),h.jsx("span",{"data-tooltip-content":"Previous page","data-tooltip-id":"default",className:le(ae.tableAction,ae.blue),onClick:C,role:"button",children:h.jsx(mr,{width:16,height:16,className:"rotate-180"})}),h.jsx("span",{"data-tooltip-content":"Next page","data-tooltip-id":"default",className:le(ae.tableAction,ae.blue),onClick:w,role:"button",children:h.jsx(mr,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Refresh data","data-tooltip-id":"default",className:le(ae.tableAction,ae.blue),onClick:()=>u(),role:"button",children:h.jsx(e_,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Share query","data-tooltip-id":"default",className:le(ae.tableAction,ae.blue),onClick:E,role:"button",children:h.jsx(n_,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Duplicate tab","data-tooltip-id":"default",className:le(ae.tableAction,ae.blue),onClick:b,role:"button",children:h.jsx(t_,{width:16,height:16})}),h.jsx(fh,{id:"rows-num",className:"z-10 shadow-md flex",clickable:!0,variant:"light",opacity:1,children:x_.map(N=>h.jsx("button",{onClick:()=>s(N,!0),className:le(ae.tableAction,ae.blue),children:h.jsx("span",{children:N})},N))})]})}function w_(){const{state:n,setState:l}=x.useContext(mt),r=()=>{l(o=>({...o,searchAll:void 0}))},s=()=>{Nr("Search all text values for",n.searchAll||"",{type:"info",message:"This will search all text values using LIKE operator (numbers, dates and other non string values are not searched)."}).then(o=>{o!==void 0&&l(u=>({...u,searchAll:o.length>0?o:void 0}))})};return $t("k",s),n.searchAll?h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Remove search all filter",onClick:r,className:le(ae.tableAction,ae.red),children:h.jsxs("span",{className:"truncate px-1",children:["❌ ",n.searchAll]})}):h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Search text in all columns",onClick:s,className:le(ae.tableAction,ae.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"Search text"}),h.jsx("span",{className:"hotkey",children:"K"})]})}const E_="_drop-container_nlwiv_2",C_="_item_nlwiv_2",nv={dropContainer:E_,item:C_},Md=({dataSourceId:n,focusId:l,placeholder:r="Column",onChange:s,value:o,autoFocus:u,allowTables:d})=>{const{data:m}=es(n),y=x.useRef(null),p=x.useMemo(()=>{if(!m)return[];let _=m;return d&&(_=m.filter(T=>d.includes(T.tableName))),_.flatMap(T=>T.columns.map(O=>({value:T.tableName+"."+O.name,label:O.name,table:T.tableName,searchValue:O.name.toLowerCase()})))},[m,d]),v=x.useMemo(()=>{const _=o.toLowerCase()||"",T=[];for(let O=0;O<p.length&&T.length<10;O++)p[O].searchValue.includes(_)&&T.push(p[O]);return T},[p,o]),[b,E]=x.useState(!1),[C,w]=x.useState(0),N=_=>{var T;if(_.key==="ArrowDown")_.preventDefault(),w(O=>(O+1)%v.length);else if(_.key==="ArrowUp")_.preventDefault(),w(O=>(O-1+v.length)%v.length);else if(_.key==="Enter"&&C>=0&&C<v.length){_.preventDefault();const O=v[C].value;E(!1);const Q=p.findIndex(K=>K.value===O)>-1;s(((T=v[C])==null?void 0:T.value)||O,Q,!0)}};x.useEffect(()=>{var T;const _=(T=y.current)==null?void 0:T.querySelector('[data-is-active="true"]');_&&_.scrollIntoView({behavior:"smooth",block:"nearest"})},[C]);const j=_=>{const T=_.currentTarget.value,O=p.findIndex(Q=>Q.value===T)>-1;s(T,O,!1)};return h.jsxs("div",{className:"relative",onFocus:()=>E(!0),onBlur:()=>E(!1),children:[h.jsx("input",{autoFocus:u,onKeyDown:N,value:o,onChange:j,className:"input w-full",placeholder:r,"data-focus":l}),b&&v.length>0&&h.jsx("div",{className:nv.dropContainer,ref:y,tabIndex:-1,children:v.map((_,T)=>h.jsxs("div",{className:nv.item,"data-is-active":C===T,onMouseDownCapture:O=>{O.preventDefault(),E(!1),s(_.value,!0,!0)},children:[h.jsx("span",{className:"text-xs font-semibold truncate",children:_.table}),h.jsx("p",{className:"truncate text-sm",children:_.label})]},T))})]})},__="_drop-container_yz4ri_2",j_="_item_yz4ri_2",av={dropContainer:__,item:j_};function N_(n){return p4.includes(n)?d4:y4.includes(n)?f4:v4.includes(n)?h4:Gd}const A_=({value:n,onChange:l,autoFocus:r,focusId:s,colType:o})=>{const u=x.useMemo(()=>{const E=n.toLowerCase()||"";return N_(o||"").filter(C=>C.label.includes(E))},[n,o]),d=x.useRef(null),[m,y]=x.useState(!1),[p,v]=x.useState(0),b=E=>{var C;E.key==="ArrowDown"?(E.preventDefault(),v(w=>(w+1)%u.length)):E.key==="ArrowUp"?(E.preventDefault(),v(w=>(w-1+u.length)%u.length)):E.key==="Enter"&&(p>=0&&p<u.length?(E.preventDefault(),y(!1),l(((C=u[p])==null?void 0:C.label)||"",!0)):l(n,!0))};return x.useEffect(()=>{var C;const E=(C=d.current)==null?void 0:C.querySelector('[data-is-active="true"]');E&&E.scrollIntoView({behavior:"smooth",block:"nearest"})},[p]),h.jsxs("div",{className:"relative",children:[h.jsx("input",{onKeyDown:b,value:n,onChange:E=>l(E.target.value,!1),className:"input w-full",placeholder:"Operator",autoFocus:r,onFocus:()=>y(!0),onBlur:()=>y(!1),"data-focus":s}),m&&u.length>0&&h.jsx("ul",{className:av.dropContainer,ref:d,tabIndex:-1,children:u.map((E,C)=>h.jsx("li",{className:av.item,"data-is-active":p===C,onMouseDownCapture:w=>{w.preventDefault(),y(!1),l(E.label,!0)},children:E.label},C))})]})},T_="_actions_1ejit_2",R_="_filter-actions_1ejit_2",P1={actions:T_,filterActions:R_},O_=["=","<",">",">=","<>","!=","<="];function D_(n){for(let l=0;l<n.length;l++){const r=n[l];if(!r.operator.length&&!r.value.length&&!r.column.length)continue;if(!r.column.includes("."))return It.error(`Filter #${l+1} has invalid column value`),!1;const s=Zd[r.operator];if(!s)return It.error(`Filter #${l+1} has invalid operator`),!1;if(r.isColumnRef&&!O_.includes(s))return It.error(`Filter #${l+1} cannot reference another column because it uses '${r.operator}' operator`),!1}return!0}function M_(n){const l=[];return n.forEach(r=>{if(!r.operator.length||!r.column.length||r.operator!=="is null"&&r.operator!=="is not null"&&!r.value.length)return;const s=Zd[r.operator];l.push({id:r.id,value:r.isColumnRef?[{value:r.value,isColumn:!0}]:m4(s,r.value),operator:s,column:r.column,isEnabled:r.isEnabled,connector:"AND"})}),l}function L_(n){let l="";if(n.value)for(let r=0;r<n.value.length;r++)l+=n.value[r].value,r<n.value.length-1&&(l+=", ");return l}const U_=({filter:n,dataSourceId:l,allowedTables:r,inspections:s,autoFocus:o,onChangeColumn:u,onChangeOperator:d,onChangeValue:m,onRemoveFilter:y,triggerIsEnabled:p,onIsColumnChange:v})=>{const b=x.useMemo(()=>{if(!s)return"";let E=null;for(const C of s)for(const w of C.columns)C.tableName+"."+w.name===n.column&&(E=w);return E!=null&&E.type?E.type:""},[n.column,s]);return h.jsxs("div",{className:"flex gap-2 items-center",children:[h.jsx("label",{children:h.jsx("input",{type:"checkbox",checked:n.isEnabled!==!1,onClick:()=>p(n.id)})}),h.jsx("label",{className:"w-full",children:h.jsx(Md,{dataSourceId:l,onChange:E=>u(n.id,E),value:n.column,allowTables:r,focusId:"column",autoFocus:o})}),h.jsx("label",{children:h.jsx(A_,{onChange:E=>d(n.id,E),focusId:"operator",colType:b,value:n.operator})}),b1(Zd[n.operator])&&h.jsx("label",{className:"w-full",children:n.isColumnRef?h.jsx(Md,{dataSourceId:l,onChange:E=>m(n.id,E),value:n.value,allowTables:r,focusId:"value",placeholder:"Search column"}):h.jsx("input",{className:"input w-full",placeholder:"Filter value",value:n.value,onChange:E=>m(n.id,E.currentTarget.value),"data-focus":"value"})}),h.jsxs("div",{className:P1.filterActions,children:[h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"If enabled, the value will reference another column instead of being raw string",className:le("p-0.5 cursor-pointer rounded-lg border",n.isColumnRef?"bg-blue-50 border-blue-200":"bg-white border-white"),onClick:()=>v(n.id,!n.isColumnRef),children:"🏷️"}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove filter",className:"p-0.5 text-sm cursor-pointer",onClick:()=>y(n.id),children:h.jsx(Hn,{width:20,height:20,className:"text-red-600"})})]})]})},q_=()=>{const{state:n}=x.useContext(mt),{setFilters:l}=A1(),r=Du(j=>j.filters),{data:s}=es(n.dataSourceId),o=x.useMemo(()=>[n.table,...n.joins.map(j=>j.table)],[n.table,n.joins]),[u,d]=x.useState([]),m=(j,_)=>{d(T=>[...T.map(O=>O.id===j?{...O,column:_}:O)])},y=(j,_)=>{d(T=>[...T.map(O=>O.id===j?{...O,operator:_}:O)])},p=(j,_)=>{d(T=>[...T.map(O=>O.id===j?{...O,value:_}:O)])},v=()=>{d(j=>[...j,{id:ml(),value:"",column:"",operator:"",isColumnRef:!1,isEnabled:!0}])},b=(j,_)=>{d(T=>[...T.map(O=>O.id===j?{...O,isColumnRef:_}:O)])},E=j=>{d(_=>_.filter(T=>T.id!==j))},C=()=>Mu("filters"),w=()=>{D_(u)&&(l(M_(u)),C())},N=j=>{d(_=>_.map(T=>T.id===j?{...T,isEnabled:!T.isEnabled}:T))};return x.useEffect(()=>{r&&d(()=>{const j=n.filters.map(_=>{var T,O;return{id:_.id,value:L_(_),column:_.column,operator:Xd[_.operator],isColumnRef:!!((O=(T=_.value)==null?void 0:T[0])!=null&&O.isColumn),isEnabled:_.isEnabled}});return j.push({id:ml(),value:"",column:"",operator:"",isColumnRef:!1,isEnabled:!0}),j})},[r]),$t("f",()=>{mu("filters")}),$t("ctrl+f",()=>{alert("Save filters")}),h.jsxs(dn,{isVisible:r,onClose:C,portal:!0,onClosed:()=>d([]),children:[h.jsx(la,{onClick:C}),h.jsx("h2",{className:"text-lg font-semibold",children:"Filters"}),h.jsxs("div",{className:"flex gap-4 flex-col w-full lg:w-lg my-4",children:[u.length<1&&h.jsx("p",{className:"p-1 text-center rounded-lg bg-gray-50 border border-gray-200",children:"No filters"}),u.map((j,_)=>h.jsx(U_,{filter:j,dataSourceId:n.dataSourceId,allowedTables:o,inspections:s||[],onChangeColumn:m,onChangeOperator:y,onChangeValue:p,onRemoveFilter:E,onIsColumnChange:b,triggerIsEnabled:N,autoFocus:_===u.length-1},j.id))]}),h.jsxs("div",{className:P1.actions,children:[h.jsx("button",{className:"button tertiary",onClick:v,children:"Add filter"}),h.jsx("button",{className:"button primary",onClick:w,children:"Apply filters"})]})]})},z_="_card_11ywf_2",k_="_cards-list_11ywf_2",B_="_join-modal_11ywf_2",H_="_close-button_11ywf_2",Fo={card:z_,cardsList:k_,joinModal:B_,closeButton:H_},Q_=()=>{const{isFetching:n}=x.useContext(sa),l=Du(p=>p.joins),{toggle:r,joins:s}=T1(),{availableJoins:o}=x.useContext(ia),[u,d]=x.useState(""),m=x.useMemo(()=>{const p=u.toLowerCase();return o.filter(v=>v.on.toTable.toLowerCase().includes(p))},[o,u]),y=()=>Mu("joins");return $t("j",()=>{o.length>0?Un("joins"):It.error("No available tables to join")}),h.jsxs(dn,{isVisible:l,onClose:y,portal:!0,children:[h.jsx(la,{onClick:y}),h.jsxs("div",{className:Fo.joinModal,children:[h.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Join table"}),s.length>0&&h.jsx("div",{className:Fo.cardsList,children:s.map((p,v)=>h.jsxs("div",{className:Fo.card,children:[h.jsxs("p",{className:"text-sm truncate",children:[p.table," on ",p.on]}),v===s.length-1&&h.jsx("button",{className:Fo.closeButton,onClick:()=>r(p),disabled:n,children:h.jsx(Hn,{width:20,height:20})})]},p.table+p.on))}),o.length>0?h.jsx("input",{className:"input w-full",placeholder:"Filter",autoFocus:!0,onChange:p=>d(p.target.value),value:u,disabled:n}):h.jsx(Ut,{variant:"warning",children:h.jsx("p",{className:"text-sm truncate",children:"No more tables to join"})}),h.jsx("div",{className:`flex flex-col mt-2 overflow-y-auto ${n?"opacity-40":""}`,children:m.map(p=>h.jsx(N1,{hook:p,onClick:()=>{n||(r({table:p.on.toTable,type:"LEFT",on:p.where}),d(""))}},p.where))})]})]})};function $_(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}function lv(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}const Y_="_container_1p3j3_2",K_="_column-label_1p3j3_2",V_="_not-active_1p3j3_2",au={container:Y_,columnLabel:K_,notActive:V_};function F_(n){if(!n)return[];const l={};return n.forEach(r=>{l[r.table]?l[r.table].push({value:r.full,ogColumn:r.column,label:fl(r.column),type:r.type}):l[r.table]=[{value:r.full,ogColumn:r.column,label:fl(r.column),type:r.type}],g4[r.type]&&["YEAR","MONTH","DAY"].forEach(s=>{l[r.table].push({value:s+" "+r.full,ogColumn:r.column,label:s+" "+fl(r.column),type:"number",nested:!0})})}),Object.entries(l).reduce((r,[s,o])=>(r.push({name:fl(s),columns:o}),r),[])}function G_(n,l){const r=l.toLowerCase();return n.map(s=>{const o=s.columns.filter(u=>u.label.toLowerCase().includes(r)||u.ogColumn.toLowerCase().includes(r));return{...s,columns:o}}).filter(s=>s.columns.length>0)}const X_=({column:n,selected:l,onCheck:r})=>h.jsxs("label",{className:le(au.columnLabel,l?au.active:au.notActive,n.nested&&"pl-5!"),children:[h.jsx("input",{type:"checkbox",checked:l[n.value],name:n.value,onChange:r}),h.jsxs("p",{className:"flex justify-between w-full",children:[h.jsx("span",{"data-tooltip-content":n.value,"data-tooltip-id":"default",children:n.label}),h.jsx("span",{className:"text-blue-600",children:n.type})]})]},n.value),Z_={columns:"c",groupBy:"g"},iv=({mode:n})=>{const l=Du(_=>_[n]),{allColumns:r}=x.useContext(ia),{state:s,setState:o}=x.useContext(mt),[u,d]=x.useState({}),[m,y]=x.useState(""),p=x.useMemo(()=>F_(r),[r]),v=s.aggregations.length>0||s.groupBy.length>0,b=x.useMemo(()=>m?G_(p,m):p,[m,p]),E=_=>{d(T=>({...T,[_.target.name]:_.target.checked}))},C=_=>{const T=_.target.checked;d(O=>{for(const Q of r)O[Q.full]=T;return{...O}})},w=()=>{Mu(n)},N=()=>{const _=[];for(const[T,O]of Object.entries(u))if(O){const[Q,K]=T.split(" ");_.push({value:K||Q,fn:K?Q:void 0})}o(T=>({...T,[n]:_})),w()},j=x.useMemo(()=>{for(const _ of r)if(!u[_.full])return!1;return!0},[u,r]);return $t(Z_[n],()=>{n==="columns"?v?It.error("Columns are ignored when there is at least one aggregation or group by"):mu("columns"):mu("groupBy")}),x.useEffect(()=>{if(!l){d({});return}d(()=>$_(s[n].map(_=>_.fn?_.fn+" "+_.value:_.value)))},[l,d]),h.jsxs(dn,{isVisible:l,onClose:w,portal:!0,children:[h.jsx(la,{onClick:w}),h.jsxs("div",{className:au.container,children:[h.jsx("h2",{className:"text-lg font-semibold",children:n==="groupBy"?"Group by":"Show columns"}),h.jsx("input",{autoFocus:!0,className:"input my-2",placeholder:"Filter",value:m,onChange:_=>y(_.target.value)}),h.jsx("div",{className:"overflow-y-auto",children:b.map(_=>h.jsxs("div",{className:"my-2",children:[h.jsxs("p",{className:"font-semibold sticky top-0 bg-white p-1 z-1",children:["📄 ",_.name]}),_.columns.map(T=>h.jsx(X_,{column:T,selected:u,onCheck:E},T.value))]},_.name))}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsxs("label",{className:"button tertiary flex gap-2 items-center",children:[h.jsx("input",{type:"checkbox",checked:j,onChange:C}),h.jsx("span",{children:"Select all"})]}),h.jsx("span",{className:"flex-1"}),h.jsx("button",{className:"button tertiary",onClick:w,children:"Cancel"}),h.jsx("button",{className:"button primary",onClick:N,children:"Apply"})]})]})]})},P_="_options-container_1uxvv_2",J_={optionsContainer:P_},cd="COUNT all",I_=n=>n.distinct?[n.fn,"DISTINCT",n.value].join(" "):[n.fn,n.value].join(" "),W_=()=>{const n=Du(w=>w.aggregate),{dataSourceId:l}=x.useContext(ia),{setState:r,state:s}=x.useContext(mt),{data:o}=x.useContext(sa),[u,d]=x.useState({fn:"",col:""}),m=w=>d({...u,fn:w.currentTarget.value}),y=w=>d({...u,col:w}),p=()=>Mu("aggregate"),v=()=>{const w=u.fn===cd?{value:"*",fn:"COUNT"}:{fn:u.fn,value:u.col,distinct:u.fn==="COUNT"};r(N=>({...N,aggregations:[...N.aggregations,w]}))},b=u.fn===cd,E=b?!1:!u.col||!u.fn,C=w=>{const N=In(w);r(j=>({...j,aggregations:j.aggregations.filter(_=>_.fn!==w.fn||_.value!==w.value),orderBy:j.orderBy.filter(_=>_.column!==N)}))};return $t("a",()=>{mu("aggregate")}),h.jsxs(dn,{isVisible:n,onClose:p,backdropClose:!0,portal:!0,children:[h.jsx(la,{onClick:p}),h.jsxs("div",{children:[h.jsx("h2",{className:"text-lg font-semibold",children:"Aggregate"}),pl(s.aggregations.length,0)&&h.jsx("div",{className:"flex flex-col gap-1 mt-4",children:s.aggregations.map((w,N)=>h.jsxs("p",{className:"p-2 rounded-md bg-gray-50 flex items-center justify-between",children:[h.jsx("span",{children:I_(w)}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove aggregation",className:"p-0.5 text-sm cursor-pointer",onClick:()=>C(w),children:h.jsx(Hn,{width:20,height:20,className:"text-red-600"})})]},N))}),h.jsxs("div",{className:J_.optionsContainer,children:[h.jsxs("label",{className:le(b&&"col-span-2"),children:[h.jsx("p",{className:"font-semibold text-xs",children:"Function"}),h.jsxs("select",{className:"input w-full",value:u.fn,onChange:m,autoFocus:!0,children:[h.jsx("option",{value:"",disabled:!0,children:"Select function"}),h.jsx("option",{value:cd,children:"Count all rows"}),h.jsx("option",{value:"COUNT",children:"Count"}),h.jsx("option",{value:"SUM",children:"Sum"}),h.jsx("option",{value:"MAX",children:"Max"}),h.jsx("option",{value:"MIN",children:"Min"}),h.jsx("option",{value:"AVG",children:"Avg"})]})]}),!b&&h.jsxs("label",{children:[h.jsx("p",{className:"font-semibold text-xs",children:"Column"}),h.jsx(Md,{dataSourceId:l,allowTables:(o==null?void 0:o.result.tables)||[],onChange:y,value:u.col})]}),h.jsx("button",{className:"button primary",disabled:E,onClick:v,children:"Add"})]})]})]})},ej=({options:n,updater:l,name:r,tabId:s})=>{const o=S4(n,l),u=N4(s,o.state),d=x4(u.data,o.state.dataSourceId,r,s);return h.jsx(ia,{value:d,children:h.jsx(mt,{value:o,children:h.jsxs(sa,{value:u,children:[h.jsx(g_,{}),h.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[h.jsx("div",{className:"flex-1 overflow-auto pb-24 lg:pb-12 no-scrollbar",children:h.jsx(RC,{})}),h.jsx(q_,{}),h.jsx(Q_,{}),h.jsx(iv,{mode:"columns"}),h.jsx(iv,{mode:"groupBy"}),h.jsx(W_,{}),h.jsx(n6,{})]})]})})})},J1=()=>h.jsxs("div",{role:"status",children:[h.jsxs("svg",{"aria-hidden":"true",className:"w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600",viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[h.jsx("path",{d:"M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",fill:"currentColor"}),h.jsx("path",{d:"M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",fill:"currentFill"})]}),h.jsx("span",{className:"sr-only",children:"Loading..."})]}),tj=({id:n})=>{const{data:l}=E4(n),r=x.useCallback(s=>{if(!l)return;const o=s($i(l.opts));ft.setQueryData(["workbench-tabs",l.id],{...l,opts:{...l.opts,...o}})},[l]);return l?h.jsx(ej,{updater:r,options:l.opts,name:l.name,tabId:l.id}):h.jsx("div",{className:"flex-1 flex justify-center items-center",children:h.jsx(J1,{})})},nj=()=>{const{id:n}=Zx(),l=qt(),{data:r}=Jd(),s=C4(),o=nh(Ou.laptop),u=y=>{if(y===n&&r){if(r.length===1)return l(Fe.home.path);if(r.length>1){const p=r.find(v=>v.id!==y);if(p)return l(`/workbench/tab/${p.id}`)}}},d=y=>{y.stopPropagation(),y.preventDefault();const p=y.currentTarget.getAttribute("data-tab-id");p&&(s.mutate(p),u(p))},m=y=>{if(y.button===1){const p=y.currentTarget.dataset.tabId;s.mutate(p),u(p)}};return $t("ctrl+w",()=>{n&&(s.mutate(n),u(n))},{preventDefault:!0}),h.jsxs("div",{className:"h-screen max-h-screen bg-(--bg) flex flex-col",children:[n&&h.jsx(tj,{id:n}),h.jsx("div",{className:le(sr.tabs,"no-scrollbar",!o&&sr.mobile),children:r==null?void 0:r.map(y=>h.jsxs("div",{onClick:()=>l(`${Fe.workbench.path}/tab/${y.id}`),className:le(sr.tab,y.id===n&&sr.active),"data-tab-id":y.id,"data-tooltip-id":"tab","data-tooltip-content":y.name,onAuxClick:m,children:[h.jsxs("span",{className:"truncate w-full",children:["🛠️ ",y.name]}),h.jsx("button",{"data-tab-id":y.id,className:sr.closeButton,onClick:d,children:h.jsx(Hn,{width:20,height:20})})]},y.id))})]})},aj="_root_18j2i_2",lj="_down_18j2i_2",ij="_chevron_18j2i_2",sj="_table-name-container_18j2i_2",rj="_link_18j2i_2",oj="_table-name_18j2i_2",uj="_ul_18j2i_2",cj="_column-type_18j2i_2",Ta={root:aj,down:lj,chevron:ij,tableNameContainer:sj,link:rj,tableName:oj,ul:uj,columnType:cj},[NN,fj]=fn(!1),I1=()=>fj(!1),dj=new Intl.DateTimeFormat("en",{dateStyle:"full",timeStyle:"long"});function hj(n,l){if(l&&n.toLowerCase().includes(l))return"bg-yellow-200"}const mj=({insp:n,filter:l,expanded:r})=>{const s=x.useMemo(()=>r?n.columns:l.length<1?[]:n.columns.filter(o=>o.name.toLowerCase().includes(l)),[n,l,r]);return h.jsx("ul",{className:Ta.ul,children:s.map(o=>h.jsx(h.Fragment,{children:h.jsxs("li",{children:[o.isPrimary?"🔐":"🏷️"," ",h.jsx("span",{className:hj(o.name,l),children:o.name})," ",h.jsxs("span",{className:Ta.columnType,children:["[",o.type,"]"]}),o.ref&&h.jsxs("span",{children:[" ➡️ ",h.jsx("span",{className:Ta.columnType,children:o.ref.table}),".",o.ref.field]})]},o.name+o.type)}))},n.id)};function pj({id:n}){const{data:l}=Tu(n),{data:r}=es(n),s=qt(),o=W3(),u=y1(),d=e4(),m=ns(),y=x.useMemo(()=>l!=null&&l.lastInspected?dj.format(new Date(l.lastInspected)):"--",[l]),[p,v]=x.useState({}),[b,E]=x.useState(""),[C,w]=x.useState("table"),N=_r(Zt.EDITOR),j=b.toLowerCase(),_=x.useMemo(()=>{if(!j||!r)return r||[];const Z=[];for(const te of r){if(te.tableName.toLowerCase().includes(j)){Z.push(te);continue}C!=="table"&&te.columns.findIndex(pe=>pe.name.toLowerCase().includes(j))>=0&&Z.push(te)}return Z},[j,r,C]),T=Z=>{v(te=>({...te,[Z]:!te[Z]}))},O=Z=>{m.mutateAsync({name:Z,opts:$i({table:Z,dataSourceId:n})}).then(te=>{Yi(void 0),I1(),s(`${Fe.workbench.path}/tab/${te.id}`)})},Q=()=>{u.mutate(n)},K=async()=>{const Z=await Nr("Enter name",l==null?void 0:l.name);Z&&o.mutate({id:n,dataSource:{name:Z}})},H=async()=>{await w1("Are you sure you want to delete this data source?")&&(d.mutate(n),Yi(void 0))},G=C==="column";return h.jsxs("div",{className:Ta.root,children:[h.jsxs("h3",{className:"page-head flex gap-2",children:[l&&h.jsx(Ru,{size:32,type:l.dbType}),h.jsx("span",{className:"truncate",children:l==null?void 0:l.name})]}),h.jsx("p",{className:"mt-2 text-xs text-gray-800",children:"Last DB inspection"}),h.jsx("p",{className:"text-sm font-semibold",children:y}),N&&h.jsxs("div",{className:"mt-2 flex gap-2",children:[h.jsx("button",{disabled:u.isLoading,onClick:Q,className:"button tertiary flex items-center gap-1",children:"Refresh schema"}),h.jsx("button",{disabled:u.isLoading,onClick:K,className:"button tertiary",children:"Rename"}),h.jsx("button",{disabled:u.isLoading,onClick:H,className:"button tertiary",children:"Delete"})]}),h.jsxs("div",{className:"flex gap-2 items-center mb-2 mt-4",children:[h.jsxs("select",{className:"input",value:C,onChange:Z=>w(Z.currentTarget.value),children:[h.jsx("option",{value:"table",children:"Table"}),h.jsx("option",{value:"column",children:"Column"})]}),h.jsx("input",{className:"input flex-1 bg-gray-50",placeholder:G?"Search column":"Search table",value:b,onChange:Z=>E(Z.target.value),autoFocus:!0})]}),h.jsx("div",{className:"overflow-y-auto",children:_==null?void 0:_.map(Z=>h.jsxs("div",{children:[h.jsxs("div",{className:Ta.tableNameContainer,children:[h.jsx("button",{className:le(Ta.chevron,p[Z.id]&&Ta.down),onClick:()=>T(Z.id),children:h.jsx(mr,{width:16,height:16})}),h.jsx("button",{className:le(Ta.tableName,"flex-1"),onClick:()=>T(Z.id),children:Z.tableName}),h.jsx("button",{className:Ta.link,onClick:()=>O(Z.tableName),children:"↗️"})]}),(p[Z.id]||b.length>0)&&h.jsx(mj,{insp:Z,filter:G?j:"",expanded:p[Z.id]})]},Z.id))})]})}const yj=()=>{const n=W4(),[l,r]=x.useState(void 0);x.useEffect(()=>{n&&r(n)},[n]);const s=()=>Yi(void 0);return h.jsx(R1,{isVisible:n!=null,onClose:s,onClosed:()=>r(void 0),backdropClose:!0,children:l&&h.jsx(pj,{id:l})})};function vj(n,l=500){const[r,s]=x.useState(n);return x.useEffect(()=>{const o=setTimeout(()=>s(n),l);return()=>clearTimeout(o)},[n,l]),r}const gj="_search_aq9jy_2",bj="_entry_aq9jy_2",xj="_ds_aq9jy_2",Sj="_ds-container_aq9jy_2",wj="_ds-entry_aq9jy_2",Ej="_enabled_aq9jy_2",Bi={search:gj,entry:bj,ds:xj,dsContainer:Sj,dsEntry:wj,enabled:Ej};function Cj(n,l,r){try{const s=r.getItem(n);if(s)return JSON.parse(s)}catch(s){console.warn("Failed to restore tabs",s)}return l}const _j=({storage:n=localStorage,localStorageKey:l,initialData:r})=>{const s=fn(Cj(l,r,n));return s[2].subscribe(o=>{n.setItem(l,JSON.stringify(o))}),s},[jj,Nj]=_j({initialData:[],localStorageKey:"selected-data-sources-v1"}),Aj=n=>Nj(l=>{const r=l.indexOf(n);return r>-1?(l.splice(r,1),[...l]):[...l,n]}),Tj={table:"📄",query:"📖",tab:"🛠️"},Rj=({onTable:n,onQuery:l,onWorkbenchTab:r,autoFocus:s})=>{const[o,u]=x.useState(""),[d,m]=x.useState(-1),y=vj(o,200),p=jj(),{data:v}=aa(),{data:b}=Fd({teamId:v==null?void 0:v.teamId}),E=x.useMemo(()=>{const T=[],O=lv(p);if(!b||b.length===0)return[];for(const Q of b)O[Q.id]&&T.push(Q.id);return T},[p,b]),{data:C}=X3(y,{teamId:v==null?void 0:v.teamId,selectedDataSources:E}),w=T=>{T.type==="table"?n(T.name,T.dataSourceId):T.type==="query"?l(T.id,T.dataSourceId):T.type==="tab"&&r(T.id,T.dataSourceId)},N=T=>{var O;C&&(T.key==="ArrowDown"?(T.preventDefault(),m(Q=>(Q+1)%C.length)):T.key==="ArrowUp"?(T.preventDefault(),m(Q=>(Q-1+C.length)%C.length)):T.key==="Enter"&&d>=0&&(O=C[d])!=null&&O.name&&(T.preventDefault(),w(C[d])))},j=T=>{const O=T.currentTarget.dataset.tableId,Q=C==null?void 0:C.find(K=>K.id===O);Q&&w(Q)},_=x.useMemo(()=>lv(p),[p]);return h.jsxs("div",{className:"overflow-hidden flex flex-col w-full lg:w-lg",children:[pl(b==null?void 0:b.length,0)&&h.jsx("div",{className:Bi.dsContainer,children:b.map(T=>h.jsxs("button",{className:le(Bi.dsEntry,_[T.id]&&Bi.enabled),onClick:()=>Aj(T.id),children:[h.jsx(Ru,{size:24,type:T.dbType}),"2",h.jsx("span",{children:T.name})]},T.id))}),h.jsx("input",{className:Bi.search,placeholder:"Search table or saved query to start from",value:o,onChange:T=>u(T.target.value),onKeyDown:N,autoFocus:s}),pl(C==null?void 0:C.length,0)&&h.jsx("div",{className:"overflow-y-auto max-h-full mt-2",children:C.map((T,O)=>h.jsxs("button",{className:Bi.entry,"data-is-active":d===O,"data-table-id":T.id,onClick:j,children:[h.jsxs("p",{className:"font-semibold",children:[Tj[T.type]," ",T.name]}),h.jsxs("p",{className:Bi.ds,children:["📦 ",T.dataSourceName]})]},T.id))})]})},Oj=()=>{const n=T4(),l=(u,d)=>{n==null||n.onConfirm("table",u,d)},r=(u,d)=>{n==null||n.onConfirm("query",u,d)},s=(u,d)=>{n==null||n.onConfirm("tab",u,d)},o=()=>{n==null||n.onCancel()};return h.jsxs(dn,{isVisible:!!n,onClose:o,children:[h.jsx(la,{onClick:o}),h.jsx(Rj,{autoFocus:!0,onTable:l,onQuery:r,onWorkbenchTab:s})]})},Dj=()=>{const n=Cr("Hotkey"),l=qt(),{pathname:r}=Yt(),{data:s}=aa(),{data:o}=Jd(),u=r===Fe.home.path;$t("n",()=>{s&&n()}),$t("w",()=>{s&&(o&&o.length>0?l(`${Fe.workbench.path}/tab/${o[0].id}`):n())},{enabled:u}),$t("h",()=>{l(Fe.home.path)},{enabled:!u})},Mj=()=>{const n=Yt();x.useEffect(()=>{},[n.pathname])},[Lj,W1]=fn(!1),fd=()=>W1(!1),eg=()=>W1(!0),Uj=({repeatPassword:n,password:l})=>l.length<1?null:l.length<8?h.jsx(Ut,{variant:"warning",children:"New password should be at least 8 characters long"}):l!==n?h.jsx(Ut,{variant:"warning",children:"Repeat password should match new password"}):null,qj=()=>{const n=Lj(),{data:l}=aa(),{mutateAsync:r,isLoading:s}=t4(),o=qt(),[{password:u,repeatPassword:d},{change:m,touched:y,reset:p}]=jr({password:"",repeatPassword:""}),v=()=>{o("/"),Er.logout().then(()=>{fd()})},b=()=>{r({password:u}).then(()=>{p(),It.success("Password successfully updated!")})},E=u.length<8||u!==d||s,C=y.includes("password");return h.jsxs(dn,{isVisible:n,onClose:fd,children:[h.jsx(la,{onClick:fd}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col gap-2",children:[h.jsx(S1,{children:"Account settings"}),h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Username"}),h.jsx("input",{className:"input w-full",readOnly:!0,disabled:!0,value:l==null?void 0:l.username})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Change password"}),h.jsx("input",{className:"input w-full",type:"password",name:"newPassword",autoComplete:"new-password",value:u,onChange:m("password")})]}),h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Repeat password"}),h.jsx("input",{className:"input w-full",type:"password",value:d,onChange:m("repeatPassword")})]})]}),C&&h.jsx(Uj,{password:u,repeatPassword:d}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsx("button",{className:"button tertiary",disabled:E,onClick:b,children:"Update password"}),h.jsx("button",{className:"button danger",onClick:v,children:"Log out"})]})]})]})},[zj,tg]=fn(!1),ng=()=>tg(!0),sv=()=>tg(!1),kj=n=>Wt({queryKey:["team-users"],queryFn:async()=>{const{data:l}=await Re.get("/teams/"+n+"/users");return l.data},enabled:!!n}),Bj=()=>jt({mutationFn:async({role:n,teamId:l,userId:r})=>(await Re.patch("/teams/"+l+"/user-role",{role:n,userId:r}),!0),onSuccess:()=>{ft.invalidateQueries({queryKey:["team-users"]})}}),Hj=()=>jt({mutationFn:async({teamId:n,userId:l})=>(await Re.delete("/teams/"+n,{params:{userId:l}}),!0),onSuccess:()=>{ft.invalidateQueries({queryKey:["team-users"]})}}),Qj="_user-entry_o8n68_2",$j="_select-container_o8n68_2",rv={userEntry:Qj,selectContainer:$j},Yj=()=>{const n=zj(),{data:l}=aa(),{data:r}=kj(l==null?void 0:l.teamId),{mutate:s,isLoading:o}=n4(),{mutate:u,isLoading:d}=Bj(),{mutate:m,isLoading:y}=Hj(),[p,{change:v,reset:b}]=jr({password:"",username:""}),E=()=>{s({username:p.username,password:p.password,teamId:(l==null?void 0:l.teamId)||""}),b()},C=(_,T)=>{u({teamId:l.teamId,role:T,userId:_})},w=_=>{w1("Are you sure you want to remove this user?").then(T=>{T&&m({userId:_,teamId:l.teamId})})},N=_r(Zt.ADMIN),j=o||d||y;return h.jsxs(dn,{isVisible:n,onClose:sv,backdropClose:!0,children:[h.jsx(la,{onClick:sv}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col overflow-hidden",children:[h.jsx(S1,{children:"Manage users"}),pl(r==null?void 0:r.length,0)&&h.jsx("div",{className:"mt-4 overflow-y-auto flex-1",children:r.map(_=>h.jsxs("div",{className:rv.userEntry,children:[h.jsx("div",{className:rv.selectContainer,children:h.jsxs("select",{value:_.role,disabled:!N||j,onChange:T=>C(_.id,T.currentTarget.value),children:[h.jsx("option",{value:Zt.OWNER,children:"Owner"}),h.jsx("option",{value:Zt.ADMIN,children:"Admin"}),h.jsx("option",{value:Zt.EDITOR,children:"Editor"}),h.jsx("option",{value:Zt.READ_ONLY,children:"Reader"})]})}),h.jsx("p",{className:"flex-1 mx-2",children:_.name}),N&&h.jsx("button",{className:"p-1 cursor-pointer text-red-500 text-sm",onClick:()=>w(_.id),children:"❌"})]},_.id))}),N&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold",children:"Create new user"}),h.jsxs("div",{className:"flex flex-col lg:flex-row gap-2 lg:items-center mt-2",children:[h.jsx("input",{className:"input flex-1",onChange:v("username"),value:p.username,placeholder:"Username",disabled:j}),h.jsx("input",{className:"input",onChange:v("password"),value:p.password,type:"password",name:"newPassword",autoComplete:"new-password",placeholder:"Password",disabled:j}),h.jsx("button",{className:"button primary",onClick:E,disabled:j,children:"Create user"})]}),h.jsx("p",{className:"text-xs mt-1 text-gray-600",children:"You should create default password for the new account. The user should change it after the first login."})]})]})]})},Kj=()=>{const[n,l]=x.useState(""),[r,s]=x.useState(""),[o,u]=x.useState(),[d,m]=x.useState(!1),y=qt(),p=v=>{v.preventDefault(),u(void 0),Er.login({password:r,username:n}).then(()=>{y("/",{replace:!0})}).catch(u)};return h.jsx("div",{className:"page-container bg-(--bg) h-screen",children:h.jsx("div",{className:"page-content items-center",children:h.jsxs("form",{className:"flex flex-col gap-2 w-full lg:w-lg",onSubmit:p,children:[h.jsx("p",{className:"font-semibold text-xl min-w-md",children:"Login"}),o&&h.jsx(Ut,{variant:"danger",children:"Failed to login. Please verify your credentials"}),h.jsx("input",{value:n,onChange:v=>l(v.currentTarget.value),className:"input",placeholder:"User name"}),h.jsx("input",{value:r,onChange:v=>s(v.currentTarget.value),className:"input",type:"password",placeholder:"Password"}),h.jsx("button",{type:"submit",className:"button primary",children:"Login"}),d?h.jsxs(Ut,{className:"w-full border border-blue-500",children:[h.jsx("p",{children:"If this is your first login, the default credentials are:"}),h.jsxs("ul",{className:"mt-2",children:[h.jsxs("li",{children:["Username: ",h.jsx("strong",{children:"admin"})]}),h.jsxs("li",{children:["Password: ",h.jsx("strong",{children:"admin"})]})]}),h.jsx("p",{className:"mt-2",children:"Please make sure to change the default password to a secure one."})]}):h.jsx("button",{className:"button tertiary",onClick:()=>m(!0),children:"First login?"})]})})})},Vj=()=>{const n=qt(),{pathname:l}=Yt(),{data:r,isLoading:s}=v1();x.useEffect(()=>{!r&&!s&&l!==Fe.login.path&&n(Fe.login.path)},[r,s,n,l])},Fj=()=>{const[n]=H2(),l=qt(),r=ns(),s=n.get("shareId");return x.useEffect(()=>{s&&r.mutateAsync({queryId:s}).then(o=>{l(`${Fe.workbench.path}/tab/${o.id}`,{replace:!0})})},[s]),h.jsxs("div",{className:"page-container flex items-center justify-center h-screen",children:[r.isLoading&&h.jsxs("div",{className:"flex items-center flex-col gap-2",children:[h.jsx(J1,{}),h.jsx("p",{children:"Fetching query information"})]}),r.isError&&h.jsx(Ut,{variant:"danger",children:"Failed to load query information"})]})};function Gj(){return Dj(),Mj(),Vj(),h.jsxs(h.Fragment,{children:[h.jsxs(c2,{children:[h.jsx(or,{path:Fe.home.path,element:h.jsx(iE,{})}),h.jsx(or,{path:`${Fe.workbench.path}/tab/:id`,element:h.jsx(nj,{})}),h.jsx(or,{path:Fe.login.path,element:h.jsx(Kj,{})}),h.jsx(or,{path:Fe.share.path,element:h.jsx(Fj,{})})]}),h.jsx(vE,{}),h.jsx(NE,{}),h.jsx(HE,{}),h.jsx(yj,{}),h.jsx(Oj,{}),h.jsx(qj,{}),h.jsx(Yj,{}),h.jsx(UE,{}),h.jsx(RE,{})]})}const Xj="_desktop-layout_2r7hd_2",Zj="_mobile-layout_2r7hd_2",Pj="_nav_2r7hd_2",Jj="_main_2r7hd_2",Ij="_header_2r7hd_2",Fi={desktopLayout:Xj,mobileLayout:Zj,nav:Pj,main:Jj,header:Ij},Wj="_container_rgr97_2",eN="_menu_rgr97_2",hh={container:Wj,menu:eN},tN=({name:n,id:l,onRename:r,onDelete:s,onOpen:o})=>{const u=_1();return h.jsxs("button",{className:hh.menu,onContextMenu:u.open,onClick:()=>o(l),children:[h.jsx(j1,{handler:u,children:h.jsxs("div",{className:"context-menu-container",children:[h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),u.close(),r(l)},className:"context-menu-item",children:"✏️ Rename"}),h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),u.close(),s(l)},className:"context-menu-item",children:"🗑️ Delete"})]})}),h.jsxs("span",{children:["📖 ",n]})]})},nN=({dataSource:n,index:l})=>{const r=()=>{Yi(n.id)};return $t(l.toString(),()=>{Yi(s=>{if(s!==n.id)return n.id})}),h.jsxs("button",{className:hh.menu,onClick:r,children:[h.jsx(Ru,{size:20,type:n.dbType}),h.jsx("p",{className:"truncate flex-1 text-left mx-1.5",children:n.name}),h.jsx("span",{className:"hotkey",children:l})]})},aN=()=>{const n=qt(),{data:l}=aa(),{data:r}=V3(l==null?void 0:l.teamId),{data:s}=F3(l==null?void 0:l.teamId),o=ns(),u=r6(),d=s6(),m=v=>{o.mutateAsync({queryId:v}).then(b=>{n(`${Fe.workbench.path}/tab/${b.id}`)})},y=async v=>{const b=s==null?void 0:s.find(C=>C.id===v),E=await Nr("New name?",b==null?void 0:b.name);E&&u.mutate({id:v,payload:{name:E}})},p=v=>{var E;const b=(E=s==null?void 0:s.find(C=>C.id===v))==null?void 0:E.savedQueryId;b&&d.mutate(b)};return h.jsx("div",{className:hh.container,children:h.jsxs("div",{className:"flex-1 overflow-y-auto",children:[pl(r==null?void 0:r.length,0)&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold text-sm text-gray-600 mb-2",children:"DATA SOURCES"}),r.map((v,b)=>h.jsx(nN,{dataSource:v,index:b+1},v.id))]}),pl(s==null?void 0:s.length,0)&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold text-sm text-gray-600 mb-2",children:"SAVED QUERIES"}),s.map(v=>h.jsx(tN,{onDelete:p,onRename:y,onOpen:m,name:v.name,id:v.id},v.savedQueryId))]})]})})},lN=()=>{const n=qt(),{pathname:l}=Yt(),{data:r}=aa(),s=Cr("Desktop nav"),o=()=>{I1(),l!==Fe.home.path&&n(Fe.home.path)};return h.jsxs("nav",{className:Fi.nav,children:[r&&h.jsxs("div",{className:Fi.header,children:[h.jsxs("button",{onClick:o,className:"flex justify-between items-center",children:[h.jsx("span",{children:"🏠 Home"}),h.jsx("span",{className:"hotkey",children:"H"})]}),h.jsxs("button",{onClick:s,className:"flex justify-between items-center",children:[h.jsx("span",{children:"🔎 New query"}),h.jsx("span",{className:"hotkey",children:"N"})]}),h.jsxs("button",{onClick:eg,children:["🪪 ",r.username]}),h.jsx("button",{onClick:ng,children:"👥 Manage users"})]}),h.jsx(aN,{})]})},iN="_root_10pne_2",sN={root:iN},rN=()=>{const{pathname:n}=Yt(),l=qt(),r=Cr("Mobile nav"),s=()=>{n!==Fe.home.path&&l(Fe.home.path)};return h.jsxs("div",{className:sN.root,children:[h.jsxs("button",{onClick:s,children:[h.jsx("p",{children:"🏠"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Home"})]}),h.jsxs("button",{onClick:r,children:[h.jsx("p",{children:"🔎"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"New query"})]}),h.jsxs("button",{onClick:eg,children:[h.jsx("p",{children:"🪪"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Account"})]}),h.jsxs("button",{onClick:ng,children:[h.jsx("p",{children:"👥"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Users"})]})]})},oN=({children:n,isLogin:l})=>h.jsxs("div",{className:Fi.desktopLayout,children:[h.jsx(fh,{id:"default",className:"z-100"}),!l&&h.jsx(lN,{}),h.jsx("main",{className:Fi.main,children:n})]}),uN=({children:n,isLogin:l})=>h.jsxs("div",{className:Fi.mobileLayout,children:[h.jsx("main",{className:Fi.main,children:n}),!l&&h.jsx(rN,{})]}),cN=({children:n})=>{const l=nh(Ou.laptop),{pathname:r}=Yt(),s=r===Fe.login.path;return l?h.jsx(oN,{isLogin:s,children:n}):h.jsx(uN,{isLogin:s,children:n})};gx.createRoot(document.getElementById("root")).render(h.jsxs(Ve.StrictMode,{children:[h.jsx($3,{}),h.jsx(yS,{client:ft,children:h.jsx(U2,{children:h.jsx(cN,{children:h.jsx(Gj,{})})})})]}));
237
+ .styles-module_tooltip__mnnfp{padding:8px 16px;border-radius:3px;font-size:90%;width:max-content}.styles-module_arrow__K0L3T{width:var(--rt-arrow-size);height:var(--rt-arrow-size)}[class*='react-tooltip__place-top']>.styles-module_arrow__K0L3T{transform:rotate(45deg)}[class*='react-tooltip__place-right']>.styles-module_arrow__K0L3T{transform:rotate(135deg)}[class*='react-tooltip__place-bottom']>.styles-module_arrow__K0L3T{transform:rotate(225deg)}[class*='react-tooltip__place-left']>.styles-module_arrow__K0L3T{transform:rotate(315deg)}.styles-module_dark__xNqje{background:var(--rt-color-dark);color:var(--rt-color-white)}.styles-module_light__Z6W-X{background-color:var(--rt-color-white);color:var(--rt-color-dark)}.styles-module_success__A2AKt{background-color:var(--rt-color-success);color:var(--rt-color-white)}.styles-module_warning__SCK0X{background-color:var(--rt-color-warning);color:var(--rt-color-white)}.styles-module_error__JvumD{background-color:var(--rt-color-error);color:var(--rt-color-white)}.styles-module_info__BWdHW{background-color:var(--rt-color-info);color:var(--rt-color-white)}`,type:"base"})});const e_=n=>x.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},x.createElement("path",{d:"M320 146s24.36-12-64-12a160 160 0 10160 160",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeMiterlimit:10,strokeWidth:32}),x.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M256 58l80 80-80 80"})),t_=n=>x.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},x.createElement("rect",{x:128,y:128,width:336,height:336,rx:57,ry:57,fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:32}),x.createElement("path",{d:"M383.5 128l.5-24a56.16 56.16 0 00-56-56H112a64.19 64.19 0 00-64 64v216a56.16 56.16 0 0056 56h24M296 216v160M376 296H216",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32})),n_=n=>x.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"ionicon",viewBox:"0 0 512 512",...n},x.createElement("circle",{cx:128,cy:256,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),x.createElement("circle",{cx:384,cy:112,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),x.createElement("circle",{cx:384,cy:400,r:48,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32}),x.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:32,d:"M169.83 279.53l172.34 96.94M342.17 135.53l-172.34 96.94"})),K1=["shift","alt","meta","mod","ctrl","control"],a_={esc:"escape",return:"enter",left:"arrowleft",right:"arrowright",up:"arrowup",down:"arrowdown",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",OSLeft:"meta",OSRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function hl(n){return(a_[n.trim()]||n.trim()).toLowerCase().replace(/key|digit|numpad/,"")}function V1(n){return K1.includes(n)}function od(n,l=","){return n.toLowerCase().split(l)}function ud(n,l="+",r=">",s=!1,o){let u=[],d=!1;n=n.trim(),n.includes(r)?(d=!0,u=n.toLocaleLowerCase().split(r).map(p=>hl(p))):u=n.toLocaleLowerCase().split(l).map(p=>hl(p));const m={alt:u.includes("alt"),ctrl:u.includes("ctrl")||u.includes("control"),shift:u.includes("shift"),meta:u.includes("meta"),mod:u.includes("mod"),useKey:s},y=u.filter(p=>!K1.includes(p));return{...m,keys:y,description:o,isSequence:d,hotkey:n}}typeof document<"u"&&(document.addEventListener("keydown",n=>{n.code!==void 0&&F1([hl(n.code)])}),document.addEventListener("keyup",n=>{n.code!==void 0&&G1([hl(n.code)])})),typeof window<"u"&&(window.addEventListener("blur",()=>{Ra.clear()}),window.addEventListener("contextmenu",()=>{setTimeout(()=>{Ra.clear()},0)}));const Ra=new Set;function dh(n){return Array.isArray(n)}function l_(n,l=","){return(dh(n)?n:n.split(l)).every(r=>Ra.has(r.trim().toLowerCase()))}function F1(n){const l=Array.isArray(n)?n:[n];Ra.has("meta")&&Ra.forEach(r=>!V1(r)&&Ra.delete(r.toLowerCase())),l.forEach(r=>Ra.add(r.toLowerCase()))}function G1(n){const l=Array.isArray(n)?n:[n];n==="meta"?Ra.clear():l.forEach(r=>Ra.delete(r.toLowerCase()))}function i_(n,l,r){(typeof r=="function"&&r(n,l)||r===!0)&&n.preventDefault()}function s_(n,l,r){return typeof r=="function"?r(n,l):r===!0||r===void 0}const r_=["input","textarea","select","searchbox","slider","spinbutton","menuitem","menuitemcheckbox","menuitemradio","option","radio","textbox"];function o_(n){return X1(n,r_)}function X1(n,l=!1){const{target:r,composed:s}=n;let o,u;return u_(r)&&s?(o=n.composedPath()[0]&&n.composedPath()[0].tagName,u=n.composedPath()[0]&&n.composedPath()[0].role):(o=r&&r.tagName,u=r&&r.role),dh(l)?!!(o&&l&&l.some(d=>d.toLowerCase()===o.toLowerCase()||d===u)):!!(o&&l&&l)}function u_(n){return!!n.tagName&&!n.tagName.startsWith("-")&&n.tagName.includes("-")}function c_(n,l){return n.length===0&&l?(console.warn('A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'),!0):l?n.some(r=>l.includes(r))||n.includes("*"):!0}const f_=(n,l,r=!1)=>{const{alt:s,meta:o,mod:u,shift:d,ctrl:m,keys:y,useKey:p}=l,{code:v,key:b,ctrlKey:E,metaKey:C,shiftKey:w,altKey:N}=n,j=hl(v);if(p&&(y==null?void 0:y.length)===1&&y.includes(b))return!0;if(!(y!=null&&y.includes(j))&&!["ctrl","control","unknown","meta","alt","shift","os"].includes(j))return!1;if(!r){if(s!==N&&j!=="alt"||d!==w&&j!=="shift")return!1;if(u){if(!C&&!E)return!1}else if(o!==C&&j!=="meta"&&j!=="os"||m!==E&&j!=="ctrl"&&j!=="control")return!1}return y&&y.length===1&&y.includes(j)?!0:y?l_(y):!y},d_=x.createContext(void 0),h_=()=>x.useContext(d_);function Z1(n,l){return n&&l&&typeof n=="object"&&typeof l=="object"?Object.keys(n).length===Object.keys(l).length&&Object.keys(n).reduce((r,s)=>r&&Z1(n[s],l[s]),!0):n===l}const m_=x.createContext({hotkeys:[],activeScopes:[],toggleScope:()=>{},enableScope:()=>{},disableScope:()=>{}}),p_=()=>x.useContext(m_);function y_(n){const l=x.useRef(void 0);return Z1(l.current,n)||(l.current=n),l.current}const tv=n=>{n.stopPropagation(),n.preventDefault(),n.stopImmediatePropagation()},v_=typeof window<"u"?x.useLayoutEffect:x.useEffect;function $t(n,l,r,s){const o=x.useRef(null),u=x.useRef(!1),d=Array.isArray(r)?Array.isArray(s)?void 0:s:r,m=dh(n)?n.join(d==null?void 0:d.delimiter):n,y=Array.isArray(r)?r:Array.isArray(s)?s:void 0,p=x.useCallback(l,y??[]),v=x.useRef(p);y?v.current=p:v.current=l;const b=y_(d),{activeScopes:E}=p_(),C=h_();return v_(()=>{if((b==null?void 0:b.enabled)===!1||!c_(E,b==null?void 0:b.scopes))return;let w=[],N;const j=(Q,K=!1)=>{var H;if(!(o_(Q)&&!X1(Q,b==null?void 0:b.enableOnFormTags))){if(o.current!==null){const G=o.current.getRootNode();if((G instanceof Document||G instanceof ShadowRoot)&&G.activeElement!==o.current&&!o.current.contains(G.activeElement)){tv(Q);return}}(H=Q.target)!=null&&H.isContentEditable&&!(b!=null&&b.enableOnContentEditable)||od(m,b==null?void 0:b.delimiter).forEach(G=>{var te,pe,Oe,be;if(G.includes((b==null?void 0:b.splitKey)??"+")&&G.includes((b==null?void 0:b.sequenceSplitKey)??">")){console.warn(`Hotkey ${G} contains both ${(b==null?void 0:b.splitKey)??"+"} and ${(b==null?void 0:b.sequenceSplitKey)??">"} which is not supported.`);return}const Z=ud(G,b==null?void 0:b.splitKey,b==null?void 0:b.sequenceSplitKey,b==null?void 0:b.useKey,b==null?void 0:b.description);if(Z.isSequence){N=setTimeout(()=>{w=[]},(b==null?void 0:b.sequenceTimeoutMs)??1e3);const Ue=Z.useKey?Q.key:hl(Q.code);if(V1(Ue.toLowerCase()))return;w.push(Ue);const ye=(te=Z.keys)==null?void 0:te[w.length-1];if(Ue!==ye){w=[],N&&clearTimeout(N);return}w.length===((pe=Z.keys)==null?void 0:pe.length)&&(v.current(Q,Z),N&&clearTimeout(N),w=[])}else if(f_(Q,Z,b==null?void 0:b.ignoreModifiers)||(Oe=Z.keys)!=null&&Oe.includes("*")){if((be=b==null?void 0:b.ignoreEventWhen)!=null&&be.call(b,Q)||K&&u.current)return;if(i_(Q,Z,b==null?void 0:b.preventDefault),!s_(Q,Z,b==null?void 0:b.enabled)){tv(Q);return}v.current(Q,Z),K||(u.current=!0)}})}},_=Q=>{Q.code!==void 0&&(F1(hl(Q.code)),((b==null?void 0:b.keydown)===void 0&&(b==null?void 0:b.keyup)!==!0||b!=null&&b.keydown)&&j(Q))},T=Q=>{Q.code!==void 0&&(G1(hl(Q.code)),u.current=!1,b!=null&&b.keyup&&j(Q,!0))},O=o.current||(d==null?void 0:d.document)||document;return O.addEventListener("keyup",T,d==null?void 0:d.eventListenerOptions),O.addEventListener("keydown",_,d==null?void 0:d.eventListenerOptions),C&&od(m,b==null?void 0:b.delimiter).forEach(Q=>C.addHotkey(ud(Q,b==null?void 0:b.splitKey,b==null?void 0:b.sequenceSplitKey,b==null?void 0:b.useKey,b==null?void 0:b.description))),()=>{O.removeEventListener("keyup",T,d==null?void 0:d.eventListenerOptions),O.removeEventListener("keydown",_,d==null?void 0:d.eventListenerOptions),C&&od(m,b==null?void 0:b.delimiter).forEach(Q=>C.removeHotkey(ud(Q,b==null?void 0:b.splitKey,b==null?void 0:b.sequenceSplitKey,b==null?void 0:b.useKey,b==null?void 0:b.description))),w=[],N&&clearTimeout(N)}},[m,b,E]),o}function g_(){return h.jsxs("div",{className:"flex items-center bg-white border-b border-gray-200 overflow-auto no-scrollbar",children:[h.jsx(b_,{}),h.jsx(S_,{})]})}function b_(){const{dataSourceId:n,name:l}=x.useContext(ia),{data:r}=Tu(n),{data:s}=x.useContext(sa),o=_r(Zt.EDITOR),u=i6(),{rename:d}=O1(),m=()=>{var v,b;(v=s==null?void 0:s.result.columns)!=null&&v[0].table&&Id({table:(b=s==null?void 0:s.result.columns)==null?void 0:b[0].table,dataSourceId:n})},y=async()=>{const v=await Nr("Query name",l);!v||!(s!=null&&s.result.queryHistoryId)||u.mutate({name:v,queryId:s.result.queryHistoryId})},p=()=>d(l);return $t("s",y),$t("r",p),h.jsxs("div",{className:ae.tableConfig,children:[h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Manage filters",onClick:()=>Un("filters"),className:le(ae.tableAction,ae.blue),children:[h.jsx("span",{children:"Filter"}),h.jsx("span",{className:"hotkey",children:"F"})]}),h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Join tables",onClick:()=>Un("joins"),className:le(ae.tableAction,ae.blue),children:[h.jsx("span",{children:"Join"}),h.jsx("span",{className:"hotkey",children:"J"})]}),h.jsx(w_,{}),h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Clone in a new tab",onClick:p,className:le(ae.tableAction,ae.blue),children:[h.jsx("span",{children:"Rename"}),h.jsx("span",{className:"hotkey",children:"R"})]}),h.jsxs("button",{"data-tooltip-id":"explorer-more-actions",className:le(ae.tableAction,ae.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"More actions"}),h.jsx(mr,{width:16,height:16,className:"rotate-90"})]}),h.jsxs(fh,{id:"explorer-more-actions",className:"z-10 shadow-md flex flex-col",clickable:!0,variant:"light",opacity:1,children:[h.jsxs("button",{onClick:()=>Un("columns"),className:le(ae.tableAction,ae.modal,ae.blue,"justify-between"),children:[h.jsx("span",{children:"Columns"}),h.jsx("span",{className:"hotkey",children:"C"})]}),h.jsxs("button",{onClick:()=>Un("groupBy"),className:le(ae.tableAction,ae.modal,ae.blue,"justify-between"),children:[h.jsx("span",{children:"Group by"}),h.jsx("span",{className:"hotkey",children:"G"})]}),h.jsxs("button",{onClick:()=>Un("aggregate"),className:le(ae.tableAction,ae.modal,ae.blue,"justify-between"),children:[h.jsx("span",{children:"Aggregate"}),h.jsx("span",{className:"hotkey",children:"A"})]}),h.jsxs("button",{onClick:ah,className:le(ae.tableAction,ae.modal,ae.blue,"justify-between"),children:[h.jsx("span",{children:"Query editor"}),h.jsx("span",{className:"hotkey",children:"E"})]}),o&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-0.5 my-2 bg-gray-100"}),h.jsxs("button",{onClick:y,className:le(ae.tableAction,ae.modal,ae.blue),children:[h.jsx("span",{children:"Save query"}),h.jsx("span",{className:"hotkey",children:"S"})]}),(r==null?void 0:r.allowInsert)===!0&&h.jsx("button",{onClick:m,className:le(ae.tableAction,ae.modal,ae.blue),children:"Insert new row"})]})]})]})}const x_=[5,10,20,50,100,200];function S_(){const{page:n,size:l,setPage:r,setSize:s}=l6(),{data:o,refetch:u}=x.useContext(sa),{name:d}=x.useContext(ia),{state:m}=x.useContext(mt),y=ns(),p=qt(),v=n*l,b=()=>{y.mutateAsync({name:d,opts:m}).then(N=>{p(`${Fe.workbench.path}/tab/${N.id}`)})},E=()=>{if(o!=null&&o.result.queryHistoryId){const N=new URL(window.location.href);N.pathname=Fe.share.path,N.searchParams.set("shareId",o.result.queryHistoryId),navigator.clipboard.writeText(N.toString()),It.success("Share link copied to clipboard")}};$t("e",ah),$t("d",b);const C=()=>{n>0&&r(n-1)},w=()=>{console.log(o==null?void 0:o.result.hasMore),o!=null&&o.result.hasMore&&r(n+1)};return h.jsxs("div",{className:ae.tableConfig,children:[h.jsxs("span",{className:ae.paginationIndicator,"data-tooltip-id":"rows-num",children:[v+1," - ",v+l]}),h.jsx("span",{"data-tooltip-content":"Previous page","data-tooltip-id":"default",className:le(ae.tableAction,ae.blue),onClick:C,role:"button",children:h.jsx(mr,{width:16,height:16,className:"rotate-180"})}),h.jsx("span",{"data-tooltip-content":"Next page","data-tooltip-id":"default",className:le(ae.tableAction,ae.blue),onClick:w,role:"button",children:h.jsx(mr,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Refresh data","data-tooltip-id":"default",className:le(ae.tableAction,ae.blue),onClick:()=>u(),role:"button",children:h.jsx(e_,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Share query","data-tooltip-id":"default",className:le(ae.tableAction,ae.blue),onClick:E,role:"button",children:h.jsx(n_,{width:16,height:16})}),h.jsx("span",{"data-tooltip-content":"Duplicate tab","data-tooltip-id":"default",className:le(ae.tableAction,ae.blue),onClick:b,role:"button",children:h.jsx(t_,{width:16,height:16})}),h.jsx(fh,{id:"rows-num",className:"z-10 shadow-md flex",clickable:!0,variant:"light",opacity:1,children:x_.map(N=>h.jsx("button",{onClick:()=>s(N,!0),className:le(ae.tableAction,ae.blue),children:h.jsx("span",{children:N})},N))})]})}function w_(){const{state:n,setState:l}=x.useContext(mt),r=()=>{l(o=>({...o,searchAll:void 0}))},s=()=>{Nr("Search all text values for",n.searchAll||"",{type:"info",message:"This will search all text values using LIKE operator (numbers, dates and other non string values are not searched)."}).then(o=>{o!==void 0&&l(u=>({...u,searchAll:o.length>0?o:void 0}))})};return $t("k",s),n.searchAll?h.jsx("button",{"data-tooltip-id":"default","data-tooltip-content":"Remove search all filter",onClick:r,className:le(ae.tableAction,ae.red),children:h.jsxs("span",{className:"truncate px-1",children:["❌ ",n.searchAll]})}):h.jsxs("button",{"data-tooltip-id":"default","data-tooltip-content":"Search text in all columns",onClick:s,className:le(ae.tableAction,ae.blue),children:[h.jsx("span",{className:"whitespace-nowrap",children:"Search text"}),h.jsx("span",{className:"hotkey",children:"K"})]})}const E_="_drop-container_nlwiv_2",C_="_item_nlwiv_2",nv={dropContainer:E_,item:C_},Md=({dataSourceId:n,focusId:l,placeholder:r="Column",onChange:s,value:o,autoFocus:u,allowTables:d})=>{const{data:m}=es(n),y=x.useRef(null),p=x.useMemo(()=>{if(!m)return[];let _=m;return d&&(_=m.filter(T=>d.includes(T.tableName))),_.flatMap(T=>T.columns.map(O=>({value:T.tableName+"."+O.name,label:O.name,table:T.tableName,searchValue:O.name.toLowerCase()})))},[m,d]),v=x.useMemo(()=>{const _=o.toLowerCase()||"",T=[];for(let O=0;O<p.length&&T.length<10;O++)p[O].searchValue.includes(_)&&T.push(p[O]);return T},[p,o]),[b,E]=x.useState(!1),[C,w]=x.useState(0),N=_=>{var T;if(_.key==="ArrowDown")_.preventDefault(),w(O=>(O+1)%v.length);else if(_.key==="ArrowUp")_.preventDefault(),w(O=>(O-1+v.length)%v.length);else if(_.key==="Enter"&&C>=0&&C<v.length){_.preventDefault();const O=v[C].value;E(!1);const Q=p.findIndex(K=>K.value===O)>-1;s(((T=v[C])==null?void 0:T.value)||O,Q,!0)}};x.useEffect(()=>{var T;const _=(T=y.current)==null?void 0:T.querySelector('[data-is-active="true"]');_&&_.scrollIntoView({behavior:"smooth",block:"nearest"})},[C]);const j=_=>{const T=_.currentTarget.value,O=p.findIndex(Q=>Q.value===T)>-1;s(T,O,!1)};return h.jsxs("div",{className:"relative",onFocus:()=>E(!0),onBlur:()=>E(!1),children:[h.jsx("input",{autoFocus:u,onKeyDown:N,value:o,onChange:j,className:"input w-full",placeholder:r,"data-focus":l}),b&&v.length>0&&h.jsx("div",{className:nv.dropContainer,ref:y,tabIndex:-1,children:v.map((_,T)=>h.jsxs("div",{className:nv.item,"data-is-active":C===T,onMouseDownCapture:O=>{O.preventDefault(),E(!1),s(_.value,!0,!0)},children:[h.jsx("span",{className:"text-xs font-semibold truncate",children:_.table}),h.jsx("p",{className:"truncate text-sm",children:_.label})]},T))})]})},__="_drop-container_yz4ri_2",j_="_item_yz4ri_2",av={dropContainer:__,item:j_};function N_(n){return p4.includes(n)?d4:y4.includes(n)?f4:v4.includes(n)?h4:Gd}const A_=({value:n,onChange:l,autoFocus:r,focusId:s,colType:o})=>{const u=x.useMemo(()=>{const E=n.toLowerCase()||"";return N_(o||"").filter(C=>C.label.includes(E))},[n,o]),d=x.useRef(null),[m,y]=x.useState(!1),[p,v]=x.useState(0),b=E=>{var C;E.key==="ArrowDown"?(E.preventDefault(),v(w=>(w+1)%u.length)):E.key==="ArrowUp"?(E.preventDefault(),v(w=>(w-1+u.length)%u.length)):E.key==="Enter"&&(p>=0&&p<u.length?(E.preventDefault(),y(!1),l(((C=u[p])==null?void 0:C.label)||"",!0)):l(n,!0))};return x.useEffect(()=>{var C;const E=(C=d.current)==null?void 0:C.querySelector('[data-is-active="true"]');E&&E.scrollIntoView({behavior:"smooth",block:"nearest"})},[p]),h.jsxs("div",{className:"relative",children:[h.jsx("input",{onKeyDown:b,value:n,onChange:E=>l(E.target.value,!1),className:"input w-full",placeholder:"Operator",autoFocus:r,onFocus:()=>y(!0),onBlur:()=>y(!1),"data-focus":s}),m&&u.length>0&&h.jsx("ul",{className:av.dropContainer,ref:d,tabIndex:-1,children:u.map((E,C)=>h.jsx("li",{className:av.item,"data-is-active":p===C,onMouseDownCapture:w=>{w.preventDefault(),y(!1),l(E.label,!0)},children:E.label},C))})]})},T_="_actions_1ejit_2",R_="_filter-actions_1ejit_2",P1={actions:T_,filterActions:R_},O_=["=","<",">",">=","<>","!=","<="];function D_(n){for(let l=0;l<n.length;l++){const r=n[l];if(!r.operator.length&&!r.value.length&&!r.column.length)continue;if(!r.column.includes("."))return It.error(`Filter #${l+1} has invalid column value`),!1;const s=Zd[r.operator];if(!s)return It.error(`Filter #${l+1} has invalid operator`),!1;if(r.isColumnRef&&!O_.includes(s))return It.error(`Filter #${l+1} cannot reference another column because it uses '${r.operator}' operator`),!1}return!0}function M_(n){const l=[];return n.forEach(r=>{if(!r.operator.length||!r.column.length||r.operator!=="is null"&&r.operator!=="is not null"&&!r.value.length)return;const s=Zd[r.operator];l.push({id:r.id,value:r.isColumnRef?[{value:r.value,isColumn:!0}]:m4(s,r.value),operator:s,column:r.column,isEnabled:r.isEnabled,connector:"AND"})}),l}function L_(n){let l="";if(n.value)for(let r=0;r<n.value.length;r++)l+=n.value[r].value,r<n.value.length-1&&(l+=", ");return l}const U_=({filter:n,dataSourceId:l,allowedTables:r,inspections:s,autoFocus:o,onChangeColumn:u,onChangeOperator:d,onChangeValue:m,onRemoveFilter:y,triggerIsEnabled:p,onIsColumnChange:v})=>{const b=x.useMemo(()=>{if(!s)return"";let E=null;for(const C of s)for(const w of C.columns)C.tableName+"."+w.name===n.column&&(E=w);return E!=null&&E.type?E.type:""},[n.column,s]);return h.jsxs("div",{className:"flex gap-2 items-center",children:[h.jsx("label",{children:h.jsx("input",{type:"checkbox",checked:n.isEnabled!==!1,onClick:()=>p(n.id)})}),h.jsx("label",{className:"w-full",children:h.jsx(Md,{dataSourceId:l,onChange:E=>u(n.id,E),value:n.column,allowTables:r,focusId:"column",autoFocus:o})}),h.jsx("label",{children:h.jsx(A_,{onChange:E=>d(n.id,E),focusId:"operator",colType:b,value:n.operator})}),b1(Zd[n.operator])&&h.jsx("label",{className:"w-full",children:n.isColumnRef?h.jsx(Md,{dataSourceId:l,onChange:E=>m(n.id,E),value:n.value,allowTables:r,focusId:"value",placeholder:"Search column"}):h.jsx("input",{className:"input w-full",placeholder:"Filter value",value:n.value,onChange:E=>m(n.id,E.currentTarget.value),"data-focus":"value"})}),h.jsxs("div",{className:P1.filterActions,children:[h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"If enabled, the value will reference another column instead of being raw string",className:le("p-0.5 cursor-pointer rounded-lg border",n.isColumnRef?"bg-blue-50 border-blue-200":"bg-white border-white"),onClick:()=>v(n.id,!n.isColumnRef),children:"🏷️"}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove filter",className:"p-0.5 text-sm cursor-pointer",onClick:()=>y(n.id),children:h.jsx(Hn,{width:20,height:20,className:"text-red-600"})})]})]})},q_=()=>{const{state:n}=x.useContext(mt),{setFilters:l}=A1(),r=Du(j=>j.filters),{data:s}=es(n.dataSourceId),o=x.useMemo(()=>[n.table,...n.joins.map(j=>j.table)],[n.table,n.joins]),[u,d]=x.useState([]),m=(j,_)=>{d(T=>[...T.map(O=>O.id===j?{...O,column:_}:O)])},y=(j,_)=>{d(T=>[...T.map(O=>O.id===j?{...O,operator:_}:O)])},p=(j,_)=>{d(T=>[...T.map(O=>O.id===j?{...O,value:_}:O)])},v=()=>{d(j=>[...j,{id:ml(),value:"",column:"",operator:"",isColumnRef:!1,isEnabled:!0}])},b=(j,_)=>{d(T=>[...T.map(O=>O.id===j?{...O,isColumnRef:_}:O)])},E=j=>{d(_=>_.filter(T=>T.id!==j))},C=()=>Mu("filters"),w=()=>{D_(u)&&(l(M_(u)),C())},N=j=>{d(_=>_.map(T=>T.id===j?{...T,isEnabled:!T.isEnabled}:T))};return x.useEffect(()=>{r&&d(()=>{const j=n.filters.map(_=>{var T,O;return{id:_.id,value:L_(_),column:_.column,operator:Xd[_.operator],isColumnRef:!!((O=(T=_.value)==null?void 0:T[0])!=null&&O.isColumn),isEnabled:_.isEnabled}});return j.push({id:ml(),value:"",column:"",operator:"",isColumnRef:!1,isEnabled:!0}),j})},[r]),$t("f",()=>{mu("filters")}),$t("ctrl+f",()=>{alert("Save filters")}),h.jsxs(dn,{isVisible:r,onClose:C,portal:!0,onClosed:()=>d([]),children:[h.jsx(la,{onClick:C}),h.jsx("h2",{className:"text-lg font-semibold",children:"Filters"}),h.jsxs("div",{className:"flex gap-4 flex-col w-full lg:w-lg my-4",children:[u.length<1&&h.jsx("p",{className:"p-1 text-center rounded-lg bg-gray-50 border border-gray-200",children:"No filters"}),u.map((j,_)=>h.jsx(U_,{filter:j,dataSourceId:n.dataSourceId,allowedTables:o,inspections:s||[],onChangeColumn:m,onChangeOperator:y,onChangeValue:p,onRemoveFilter:E,onIsColumnChange:b,triggerIsEnabled:N,autoFocus:_===u.length-1},j.id))]}),h.jsxs("div",{className:P1.actions,children:[h.jsx("button",{className:"button tertiary",onClick:v,children:"Add filter"}),h.jsx("button",{className:"button primary",onClick:w,children:"Apply filters"})]})]})},z_="_card_11ywf_2",k_="_cards-list_11ywf_2",B_="_join-modal_11ywf_2",H_="_close-button_11ywf_2",Fo={card:z_,cardsList:k_,joinModal:B_,closeButton:H_},Q_=()=>{const{isFetching:n}=x.useContext(sa),l=Du(p=>p.joins),{toggle:r,joins:s}=T1(),{availableJoins:o}=x.useContext(ia),[u,d]=x.useState(""),m=x.useMemo(()=>{const p=u.toLowerCase();return o.filter(v=>v.on.toTable.toLowerCase().includes(p))},[o,u]),y=()=>Mu("joins");return $t("j",()=>{o.length>0?Un("joins"):It.error("No available tables to join")}),h.jsxs(dn,{isVisible:l,onClose:y,portal:!0,children:[h.jsx(la,{onClick:y}),h.jsxs("div",{className:Fo.joinModal,children:[h.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Join table"}),s.length>0&&h.jsx("div",{className:Fo.cardsList,children:s.map((p,v)=>h.jsxs("div",{className:Fo.card,children:[h.jsxs("p",{className:"text-sm truncate",children:[p.table," on ",p.on]}),v===s.length-1&&h.jsx("button",{className:Fo.closeButton,onClick:()=>r(p),disabled:n,children:h.jsx(Hn,{width:20,height:20})})]},p.table+p.on))}),o.length>0?h.jsx("input",{className:"input w-full",placeholder:"Filter",autoFocus:!0,onChange:p=>d(p.target.value),value:u,disabled:n}):h.jsx(Ut,{variant:"warning",children:h.jsx("p",{className:"text-sm truncate",children:"No more tables to join"})}),h.jsx("div",{className:`flex flex-col mt-2 overflow-y-auto ${n?"opacity-40":""}`,children:m.map(p=>h.jsx(N1,{hook:p,onClick:()=>{n||(r({table:p.on.toTable,type:"LEFT",on:p.where}),d(""))}},p.where))})]})]})};function $_(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}function lv(n){return n.reduce((l,r)=>(l[r]=!0,l),{})}const Y_="_container_1p3j3_2",K_="_column-label_1p3j3_2",V_="_not-active_1p3j3_2",au={container:Y_,columnLabel:K_,notActive:V_};function F_(n){if(!n)return[];const l={};return n.forEach(r=>{l[r.table]?l[r.table].push({value:r.full,ogColumn:r.column,label:fl(r.column),type:r.type}):l[r.table]=[{value:r.full,ogColumn:r.column,label:fl(r.column),type:r.type}],g4[r.type]&&["YEAR","MONTH","DAY"].forEach(s=>{l[r.table].push({value:s+" "+r.full,ogColumn:r.column,label:s+" "+fl(r.column),type:"number",nested:!0})})}),Object.entries(l).reduce((r,[s,o])=>(r.push({name:fl(s),columns:o}),r),[])}function G_(n,l){const r=l.toLowerCase();return n.map(s=>{const o=s.columns.filter(u=>u.label.toLowerCase().includes(r)||u.ogColumn.toLowerCase().includes(r));return{...s,columns:o}}).filter(s=>s.columns.length>0)}const X_=({column:n,selected:l,onCheck:r})=>h.jsxs("label",{className:le(au.columnLabel,l?au.active:au.notActive,n.nested&&"pl-5!"),children:[h.jsx("input",{type:"checkbox",checked:l[n.value],name:n.value,onChange:r}),h.jsxs("p",{className:"flex justify-between w-full",children:[h.jsx("span",{"data-tooltip-content":n.value,"data-tooltip-id":"default",children:n.label}),h.jsx("span",{className:"text-blue-600",children:n.type})]})]},n.value),Z_={columns:"c",groupBy:"g"},iv=({mode:n})=>{const l=Du(_=>_[n]),{allColumns:r}=x.useContext(ia),{state:s,setState:o}=x.useContext(mt),[u,d]=x.useState({}),[m,y]=x.useState(""),p=x.useMemo(()=>F_(r),[r]),v=s.aggregations.length>0||s.groupBy.length>0,b=x.useMemo(()=>m?G_(p,m):p,[m,p]),E=_=>{d(T=>({...T,[_.target.name]:_.target.checked}))},C=_=>{const T=_.target.checked;d(O=>{for(const Q of r)O[Q.full]=T;return{...O}})},w=()=>{Mu(n)},N=()=>{const _=[];for(const[T,O]of Object.entries(u))if(O){const[Q,K]=T.split(" ");_.push({value:K||Q,fn:K?Q:void 0})}o(T=>({...T,[n]:_})),w()},j=x.useMemo(()=>{for(const _ of r)if(!u[_.full])return!1;return!0},[u,r]);return $t(Z_[n],()=>{n==="columns"?v?It.error("Columns are ignored when there is at least one aggregation or group by"):mu("columns"):mu("groupBy")}),x.useEffect(()=>{if(!l){d({});return}d(()=>$_(s[n].map(_=>_.fn?_.fn+" "+_.value:_.value)))},[l,d]),h.jsxs(dn,{isVisible:l,onClose:w,portal:!0,children:[h.jsx(la,{onClick:w}),h.jsxs("div",{className:au.container,children:[h.jsx("h2",{className:"text-lg font-semibold",children:n==="groupBy"?"Group by":"Show columns"}),h.jsx("input",{autoFocus:!0,className:"input my-2",placeholder:"Filter",value:m,onChange:_=>y(_.target.value)}),h.jsx("div",{className:"overflow-y-auto",children:b.map(_=>h.jsxs("div",{className:"my-2",children:[h.jsxs("p",{className:"font-semibold sticky top-0 bg-white p-1 z-1",children:["📄 ",_.name]}),_.columns.map(T=>h.jsx(X_,{column:T,selected:u,onCheck:E},T.value))]},_.name))}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsxs("label",{className:"button tertiary flex gap-2 items-center",children:[h.jsx("input",{type:"checkbox",checked:j,onChange:C}),h.jsx("span",{children:"Select all"})]}),h.jsx("span",{className:"flex-1"}),h.jsx("button",{className:"button tertiary",onClick:w,children:"Cancel"}),h.jsx("button",{className:"button primary",onClick:N,children:"Apply"})]})]})]})},P_="_options-container_1uxvv_2",J_={optionsContainer:P_},cd="COUNT all",I_=n=>n.distinct?[n.fn,"DISTINCT",n.value].join(" "):[n.fn,n.value].join(" "),W_=()=>{const n=Du(w=>w.aggregate),{dataSourceId:l}=x.useContext(ia),{setState:r,state:s}=x.useContext(mt),{data:o}=x.useContext(sa),[u,d]=x.useState({fn:"",col:""}),m=w=>d({...u,fn:w.currentTarget.value}),y=w=>d({...u,col:w}),p=()=>Mu("aggregate"),v=()=>{const w=u.fn===cd?{value:"*",fn:"COUNT"}:{fn:u.fn,value:u.col,distinct:u.fn==="COUNT"};r(N=>({...N,aggregations:[...N.aggregations,w]}))},b=u.fn===cd,E=b?!1:!u.col||!u.fn,C=w=>{const N=In(w);r(j=>({...j,aggregations:j.aggregations.filter(_=>_.fn!==w.fn||_.value!==w.value),orderBy:j.orderBy.filter(_=>_.column!==N)}))};return $t("a",()=>{mu("aggregate")}),h.jsxs(dn,{isVisible:n,onClose:p,backdropClose:!0,portal:!0,children:[h.jsx(la,{onClick:p}),h.jsxs("div",{children:[h.jsx("h2",{className:"text-lg font-semibold",children:"Aggregate"}),pl(s.aggregations.length,0)&&h.jsx("div",{className:"flex flex-col gap-1 mt-4",children:s.aggregations.map((w,N)=>h.jsxs("p",{className:"p-2 rounded-md bg-gray-50 flex items-center justify-between",children:[h.jsx("span",{children:I_(w)}),h.jsx("button",{tabIndex:-1,"data-tooltip-id":"default","data-tooltip-content":"Remove aggregation",className:"p-0.5 text-sm cursor-pointer",onClick:()=>C(w),children:h.jsx(Hn,{width:20,height:20,className:"text-red-600"})})]},N))}),h.jsxs("div",{className:J_.optionsContainer,children:[h.jsxs("label",{className:le(b&&"col-span-2"),children:[h.jsx("p",{className:"font-semibold text-xs",children:"Function"}),h.jsxs("select",{className:"input w-full",value:u.fn,onChange:m,autoFocus:!0,children:[h.jsx("option",{value:"",disabled:!0,children:"Select function"}),h.jsx("option",{value:cd,children:"Count all rows"}),h.jsx("option",{value:"COUNT",children:"Count"}),h.jsx("option",{value:"SUM",children:"Sum"}),h.jsx("option",{value:"MAX",children:"Max"}),h.jsx("option",{value:"MIN",children:"Min"}),h.jsx("option",{value:"AVG",children:"Avg"})]})]}),!b&&h.jsxs("label",{children:[h.jsx("p",{className:"font-semibold text-xs",children:"Column"}),h.jsx(Md,{dataSourceId:l,allowTables:(o==null?void 0:o.result.tables)||[],onChange:y,value:u.col})]}),h.jsx("button",{className:"button primary",disabled:E,onClick:v,children:"Add"})]})]})]})},ej=({options:n,updater:l,name:r,tabId:s})=>{const o=S4(n,l),u=N4(s,o.state),d=x4(u.data,o.state.dataSourceId,r,s);return h.jsx(ia,{value:d,children:h.jsx(mt,{value:o,children:h.jsxs(sa,{value:u,children:[h.jsx(g_,{}),h.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[h.jsx("div",{className:"flex-1 overflow-auto pb-24 lg:pb-12 no-scrollbar",children:h.jsx(RC,{})}),h.jsx(q_,{}),h.jsx(Q_,{}),h.jsx(iv,{mode:"columns"}),h.jsx(iv,{mode:"groupBy"}),h.jsx(W_,{}),h.jsx(n6,{})]})]})})})},J1=()=>h.jsxs("div",{role:"status",children:[h.jsxs("svg",{"aria-hidden":"true",className:"w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600",viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[h.jsx("path",{d:"M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",fill:"currentColor"}),h.jsx("path",{d:"M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",fill:"currentFill"})]}),h.jsx("span",{className:"sr-only",children:"Loading..."})]}),tj=({id:n})=>{const{data:l}=E4(n),r=x.useCallback(s=>{if(!l)return;const o=s($i(l.opts));ft.setQueryData(["workbench-tabs",l.id],{...l,opts:{...l.opts,...o}})},[l]);return l?h.jsx(ej,{updater:r,options:l.opts,name:l.name,tabId:l.id}):h.jsx("div",{className:"flex-1 flex justify-center items-center",children:h.jsx(J1,{})})},nj=()=>{const{id:n}=Zx(),l=qt(),{data:r}=Jd(),s=C4(),o=nh(Ou.laptop),u=y=>{if(y===n&&r){if(r.length===1)return l(Fe.home.path);if(r.length>1){const p=r.find(v=>v.id!==y);if(p)return l(`/workbench/tab/${p.id}`)}}},d=y=>{y.stopPropagation(),y.preventDefault();const p=y.currentTarget.getAttribute("data-tab-id");p&&(s.mutate(p),u(p))},m=y=>{if(y.button===1){const p=y.currentTarget.dataset.tabId;s.mutate(p),u(p)}};return $t("ctrl+w",()=>{n&&(s.mutate(n),u(n))},{preventDefault:!0}),h.jsxs("div",{className:"h-screen max-h-screen bg-(--bg) flex flex-col",children:[n&&h.jsx(tj,{id:n}),h.jsx("div",{className:le(sr.tabs,"no-scrollbar",!o&&sr.mobile),children:r==null?void 0:r.map(y=>h.jsxs("div",{onClick:()=>l(`${Fe.workbench.path}/tab/${y.id}`),className:le(sr.tab,y.id===n&&sr.active),"data-tab-id":y.id,"data-tooltip-id":"tab","data-tooltip-content":y.name,onAuxClick:m,children:[h.jsxs("span",{className:"truncate w-full",children:["🛠️ ",y.name]}),h.jsx("button",{"data-tab-id":y.id,className:sr.closeButton,onClick:d,children:h.jsx(Hn,{width:20,height:20})})]},y.id))})]})},aj="_root_18j2i_2",lj="_down_18j2i_2",ij="_chevron_18j2i_2",sj="_table-name-container_18j2i_2",rj="_link_18j2i_2",oj="_table-name_18j2i_2",uj="_ul_18j2i_2",cj="_column-type_18j2i_2",Ta={root:aj,down:lj,chevron:ij,tableNameContainer:sj,link:rj,tableName:oj,ul:uj,columnType:cj},[NN,fj]=fn(!1),I1=()=>fj(!1),dj=new Intl.DateTimeFormat("en",{dateStyle:"full",timeStyle:"long"});function hj(n,l){if(l&&n.toLowerCase().includes(l))return"bg-yellow-200"}const mj=({insp:n,filter:l,expanded:r})=>{const s=x.useMemo(()=>r?n.columns:l.length<1?[]:n.columns.filter(o=>o.name.toLowerCase().includes(l)),[n,l,r]);return h.jsx("ul",{className:Ta.ul,children:s.map(o=>h.jsx(h.Fragment,{children:h.jsxs("li",{children:[o.isPrimary?"🔐":"🏷️"," ",h.jsx("span",{className:hj(o.name,l),children:o.name})," ",h.jsxs("span",{className:Ta.columnType,children:["[",o.type,"]"]}),o.ref&&h.jsxs("span",{children:[" ➡️ ",h.jsx("span",{className:Ta.columnType,children:o.ref.table}),".",o.ref.field]})]},o.name+o.type)}))},n.id)};function pj({id:n}){const{data:l}=Tu(n),{data:r}=es(n),s=qt(),o=W3(),u=y1(),d=e4(),m=ns(),y=x.useMemo(()=>l!=null&&l.lastInspected?dj.format(new Date(l.lastInspected)):"--",[l]),[p,v]=x.useState({}),[b,E]=x.useState(""),[C,w]=x.useState("table"),N=_r(Zt.EDITOR),j=b.toLowerCase(),_=x.useMemo(()=>{if(!j||!r)return r||[];const Z=[];for(const te of r){if(te.tableName.toLowerCase().includes(j)){Z.push(te);continue}C!=="table"&&te.columns.findIndex(pe=>pe.name.toLowerCase().includes(j))>=0&&Z.push(te)}return Z},[j,r,C]),T=Z=>{v(te=>({...te,[Z]:!te[Z]}))},O=Z=>{m.mutateAsync({name:Z,opts:$i({table:Z,dataSourceId:n})}).then(te=>{Yi(void 0),I1(),s(`${Fe.workbench.path}/tab/${te.id}`)})},Q=()=>{u.mutate(n)},K=async()=>{const Z=await Nr("Enter name",l==null?void 0:l.name);Z&&o.mutate({id:n,dataSource:{name:Z}})},H=async()=>{await w1("Are you sure you want to delete this data source?")&&(d.mutate(n),Yi(void 0))},G=C==="column";return h.jsxs("div",{className:Ta.root,children:[h.jsxs("h3",{className:"page-head flex gap-2",children:[l&&h.jsx(Ru,{size:32,type:l.dbType}),h.jsx("span",{className:"truncate",children:l==null?void 0:l.name})]}),h.jsx("p",{className:"mt-2 text-xs text-gray-800",children:"Last DB inspection"}),h.jsx("p",{className:"text-sm font-semibold",children:y}),N&&h.jsxs("div",{className:"mt-2 flex gap-2",children:[h.jsx("button",{disabled:u.isLoading,onClick:Q,className:"button tertiary flex items-center gap-1",children:"Refresh schema"}),h.jsx("button",{disabled:u.isLoading,onClick:K,className:"button tertiary",children:"Rename"}),h.jsx("button",{disabled:u.isLoading,onClick:H,className:"button tertiary",children:"Delete"})]}),h.jsxs("div",{className:"flex gap-2 items-center mb-2 mt-4",children:[h.jsxs("select",{className:"input",value:C,onChange:Z=>w(Z.currentTarget.value),children:[h.jsx("option",{value:"table",children:"Table"}),h.jsx("option",{value:"column",children:"Column"})]}),h.jsx("input",{className:"input flex-1 bg-gray-50",placeholder:G?"Search column":"Search table",value:b,onChange:Z=>E(Z.target.value),autoFocus:!0})]}),h.jsx("div",{className:"overflow-y-auto",children:_==null?void 0:_.map(Z=>h.jsxs("div",{children:[h.jsxs("div",{className:Ta.tableNameContainer,children:[h.jsx("button",{className:le(Ta.chevron,p[Z.id]&&Ta.down),onClick:()=>T(Z.id),children:h.jsx(mr,{width:16,height:16})}),h.jsx("button",{className:le(Ta.tableName,"flex-1"),onClick:()=>T(Z.id),children:Z.tableName}),h.jsx("button",{className:Ta.link,onClick:()=>O(Z.tableName),children:"↗️"})]}),(p[Z.id]||b.length>0)&&h.jsx(mj,{insp:Z,filter:G?j:"",expanded:p[Z.id]})]},Z.id))})]})}const yj=()=>{const n=W4(),[l,r]=x.useState(void 0);x.useEffect(()=>{n&&r(n)},[n]);const s=()=>Yi(void 0);return h.jsx(R1,{isVisible:n!=null,onClose:s,onClosed:()=>r(void 0),backdropClose:!0,children:l&&h.jsx(pj,{id:l})})};function vj(n,l=500){const[r,s]=x.useState(n);return x.useEffect(()=>{const o=setTimeout(()=>s(n),l);return()=>clearTimeout(o)},[n,l]),r}const gj="_search_aq9jy_2",bj="_entry_aq9jy_2",xj="_ds_aq9jy_2",Sj="_ds-container_aq9jy_2",wj="_ds-entry_aq9jy_2",Ej="_enabled_aq9jy_2",Bi={search:gj,entry:bj,ds:xj,dsContainer:Sj,dsEntry:wj,enabled:Ej};function Cj(n,l,r){try{const s=r.getItem(n);if(s)return JSON.parse(s)}catch(s){console.warn("Failed to restore tabs",s)}return l}const _j=({storage:n=localStorage,localStorageKey:l,initialData:r})=>{const s=fn(Cj(l,r,n));return s[2].subscribe(o=>{n.setItem(l,JSON.stringify(o))}),s},[jj,Nj]=_j({initialData:[],localStorageKey:"selected-data-sources-v1"}),Aj=n=>Nj(l=>{const r=l.indexOf(n);return r>-1?(l.splice(r,1),[...l]):[...l,n]}),Tj={table:"📄",query:"📖",tab:"🛠️"},Rj=({onTable:n,onQuery:l,onWorkbenchTab:r,autoFocus:s})=>{const[o,u]=x.useState(""),[d,m]=x.useState(-1),y=vj(o,200),p=jj(),{data:v}=aa(),{data:b}=Fd({teamId:v==null?void 0:v.teamId}),E=x.useMemo(()=>{const T=[],O=lv(p);if(!b||b.length===0)return[];for(const Q of b)O[Q.id]&&T.push(Q.id);return T},[p,b]),{data:C}=X3(y,{teamId:v==null?void 0:v.teamId,selectedDataSources:E}),w=T=>{T.type==="table"?n(T.name,T.dataSourceId):T.type==="query"?l(T.id,T.dataSourceId):T.type==="tab"&&r(T.id,T.dataSourceId)},N=T=>{var O;C&&(T.key==="ArrowDown"?(T.preventDefault(),m(Q=>(Q+1)%C.length)):T.key==="ArrowUp"?(T.preventDefault(),m(Q=>(Q-1+C.length)%C.length)):T.key==="Enter"&&d>=0&&(O=C[d])!=null&&O.name&&(T.preventDefault(),w(C[d])))},j=T=>{const O=T.currentTarget.dataset.tableId,Q=C==null?void 0:C.find(K=>K.id===O);Q&&w(Q)},_=x.useMemo(()=>lv(p),[p]);return h.jsxs("div",{className:"overflow-hidden flex flex-col w-full lg:w-lg",children:[pl(b==null?void 0:b.length,0)&&h.jsx("div",{className:Bi.dsContainer,children:b.map(T=>h.jsxs("button",{className:le(Bi.dsEntry,_[T.id]&&Bi.enabled),onClick:()=>Aj(T.id),children:[h.jsx(Ru,{size:24,type:T.dbType}),h.jsx("span",{children:T.name})]},T.id))}),h.jsx("input",{className:Bi.search,placeholder:"Search table or saved query to start from",value:o,onChange:T=>u(T.target.value),onKeyDown:N,autoFocus:s}),pl(C==null?void 0:C.length,0)&&h.jsx("div",{className:"overflow-y-auto max-h-full mt-2",children:C.map((T,O)=>h.jsxs("button",{className:Bi.entry,"data-is-active":d===O,"data-table-id":T.id,onClick:j,children:[h.jsxs("p",{className:"font-semibold",children:[Tj[T.type]," ",T.name]}),h.jsxs("p",{className:Bi.ds,children:["📦 ",T.dataSourceName]})]},T.id))})]})},Oj=()=>{const n=T4(),l=(u,d)=>{n==null||n.onConfirm("table",u,d)},r=(u,d)=>{n==null||n.onConfirm("query",u,d)},s=(u,d)=>{n==null||n.onConfirm("tab",u,d)},o=()=>{n==null||n.onCancel()};return h.jsxs(dn,{isVisible:!!n,onClose:o,children:[h.jsx(la,{onClick:o}),h.jsx(Rj,{autoFocus:!0,onTable:l,onQuery:r,onWorkbenchTab:s})]})},Dj=()=>{const n=Cr("Hotkey"),l=qt(),{pathname:r}=Yt(),{data:s}=aa(),{data:o}=Jd(),u=r===Fe.home.path;$t("n",()=>{s&&n()}),$t("w",()=>{s&&(o&&o.length>0?l(`${Fe.workbench.path}/tab/${o[0].id}`):n())},{enabled:u}),$t("h",()=>{l(Fe.home.path)},{enabled:!u})},Mj=()=>{const n=Yt();x.useEffect(()=>{},[n.pathname])},[Lj,W1]=fn(!1),fd=()=>W1(!1),eg=()=>W1(!0),Uj=({repeatPassword:n,password:l})=>l.length<1?null:l.length<8?h.jsx(Ut,{variant:"warning",children:"New password should be at least 8 characters long"}):l!==n?h.jsx(Ut,{variant:"warning",children:"Repeat password should match new password"}):null,qj=()=>{const n=Lj(),{data:l}=aa(),{mutateAsync:r,isLoading:s}=t4(),o=qt(),[{password:u,repeatPassword:d},{change:m,touched:y,reset:p}]=jr({password:"",repeatPassword:""}),v=()=>{o("/"),Er.logout().then(()=>{fd()})},b=()=>{r({password:u}).then(()=>{p(),It.success("Password successfully updated!")})},E=u.length<8||u!==d||s,C=y.includes("password");return h.jsxs(dn,{isVisible:n,onClose:fd,children:[h.jsx(la,{onClick:fd}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col gap-2",children:[h.jsx(S1,{children:"Account settings"}),h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Username"}),h.jsx("input",{className:"input w-full",readOnly:!0,disabled:!0,value:l==null?void 0:l.username})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Change password"}),h.jsx("input",{className:"input w-full",type:"password",name:"newPassword",autoComplete:"new-password",value:u,onChange:m("password")})]}),h.jsxs("label",{children:[h.jsx("p",{className:"text-xs font-semibold mb-1",children:"Repeat password"}),h.jsx("input",{className:"input w-full",type:"password",value:d,onChange:m("repeatPassword")})]})]}),C&&h.jsx(Uj,{password:u,repeatPassword:d}),h.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[h.jsx("button",{className:"button tertiary",disabled:E,onClick:b,children:"Update password"}),h.jsx("button",{className:"button danger",onClick:v,children:"Log out"})]})]})]})},[zj,tg]=fn(!1),ng=()=>tg(!0),sv=()=>tg(!1),kj=n=>Wt({queryKey:["team-users"],queryFn:async()=>{const{data:l}=await Re.get("/teams/"+n+"/users");return l.data},enabled:!!n}),Bj=()=>jt({mutationFn:async({role:n,teamId:l,userId:r})=>(await Re.patch("/teams/"+l+"/user-role",{role:n,userId:r}),!0),onSuccess:()=>{ft.invalidateQueries({queryKey:["team-users"]})}}),Hj=()=>jt({mutationFn:async({teamId:n,userId:l})=>(await Re.delete("/teams/"+n,{params:{userId:l}}),!0),onSuccess:()=>{ft.invalidateQueries({queryKey:["team-users"]})}}),Qj="_user-entry_o8n68_2",$j="_select-container_o8n68_2",rv={userEntry:Qj,selectContainer:$j},Yj=()=>{const n=zj(),{data:l}=aa(),{data:r}=kj(l==null?void 0:l.teamId),{mutate:s,isLoading:o}=n4(),{mutate:u,isLoading:d}=Bj(),{mutate:m,isLoading:y}=Hj(),[p,{change:v,reset:b}]=jr({password:"",username:""}),E=()=>{s({username:p.username,password:p.password,teamId:(l==null?void 0:l.teamId)||""}),b()},C=(_,T)=>{u({teamId:l.teamId,role:T,userId:_})},w=_=>{w1("Are you sure you want to remove this user?").then(T=>{T&&m({userId:_,teamId:l.teamId})})},N=_r(Zt.ADMIN),j=o||d||y;return h.jsxs(dn,{isVisible:n,onClose:sv,backdropClose:!0,children:[h.jsx(la,{onClick:sv}),h.jsxs("div",{className:"w-full lg:w-lg flex flex-col overflow-hidden",children:[h.jsx(S1,{children:"Manage users"}),pl(r==null?void 0:r.length,0)&&h.jsx("div",{className:"mt-4 overflow-y-auto flex-1",children:r.map(_=>h.jsxs("div",{className:rv.userEntry,children:[h.jsx("div",{className:rv.selectContainer,children:h.jsxs("select",{value:_.role,disabled:!N||j,onChange:T=>C(_.id,T.currentTarget.value),children:[h.jsx("option",{value:Zt.OWNER,children:"Owner"}),h.jsx("option",{value:Zt.ADMIN,children:"Admin"}),h.jsx("option",{value:Zt.EDITOR,children:"Editor"}),h.jsx("option",{value:Zt.READ_ONLY,children:"Reader"})]})}),h.jsx("p",{className:"flex-1 mx-2",children:_.name}),N&&h.jsx("button",{className:"p-1 cursor-pointer text-red-500 text-sm",onClick:()=>w(_.id),children:"❌"})]},_.id))}),N&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold",children:"Create new user"}),h.jsxs("div",{className:"flex flex-col lg:flex-row gap-2 lg:items-center mt-2",children:[h.jsx("input",{className:"input flex-1",onChange:v("username"),value:p.username,placeholder:"Username",disabled:j}),h.jsx("input",{className:"input",onChange:v("password"),value:p.password,type:"password",name:"newPassword",autoComplete:"new-password",placeholder:"Password",disabled:j}),h.jsx("button",{className:"button primary",onClick:E,disabled:j,children:"Create user"})]}),h.jsx("p",{className:"text-xs mt-1 text-gray-600",children:"You should create default password for the new account. The user should change it after the first login."})]})]})]})},Kj=()=>{const[n,l]=x.useState(""),[r,s]=x.useState(""),[o,u]=x.useState(),[d,m]=x.useState(!1),y=qt(),p=v=>{v.preventDefault(),u(void 0),Er.login({password:r,username:n}).then(()=>{y("/",{replace:!0})}).catch(u)};return h.jsx("div",{className:"page-container bg-(--bg) h-screen",children:h.jsx("div",{className:"page-content items-center",children:h.jsxs("form",{className:"flex flex-col gap-2 w-full lg:w-lg",onSubmit:p,children:[h.jsx("p",{className:"font-semibold text-xl min-w-md",children:"Login"}),o&&h.jsx(Ut,{variant:"danger",children:"Failed to login. Please verify your credentials"}),h.jsx("input",{value:n,onChange:v=>l(v.currentTarget.value),className:"input",placeholder:"User name"}),h.jsx("input",{value:r,onChange:v=>s(v.currentTarget.value),className:"input",type:"password",placeholder:"Password"}),h.jsx("button",{type:"submit",className:"button primary",children:"Login"}),d?h.jsxs(Ut,{className:"w-full border border-blue-500",children:[h.jsx("p",{children:"If this is your first login, the default credentials are:"}),h.jsxs("ul",{className:"mt-2",children:[h.jsxs("li",{children:["Username: ",h.jsx("strong",{children:"admin"})]}),h.jsxs("li",{children:["Password: ",h.jsx("strong",{children:"admin"})]})]}),h.jsx("p",{className:"mt-2",children:"Please make sure to change the default password to a secure one."})]}):h.jsx("button",{className:"button tertiary",onClick:()=>m(!0),children:"First login?"})]})})})},Vj=()=>{const n=qt(),{pathname:l}=Yt(),{data:r,isLoading:s}=v1();x.useEffect(()=>{!r&&!s&&l!==Fe.login.path&&n(Fe.login.path)},[r,s,n,l])},Fj=()=>{const[n]=H2(),l=qt(),r=ns(),s=n.get("shareId");return x.useEffect(()=>{s&&r.mutateAsync({queryId:s}).then(o=>{l(`${Fe.workbench.path}/tab/${o.id}`,{replace:!0})})},[s]),h.jsxs("div",{className:"page-container flex items-center justify-center h-screen",children:[r.isLoading&&h.jsxs("div",{className:"flex items-center flex-col gap-2",children:[h.jsx(J1,{}),h.jsx("p",{children:"Fetching query information"})]}),r.isError&&h.jsx(Ut,{variant:"danger",children:"Failed to load query information"})]})};function Gj(){return Dj(),Mj(),Vj(),h.jsxs(h.Fragment,{children:[h.jsxs(c2,{children:[h.jsx(or,{path:Fe.home.path,element:h.jsx(iE,{})}),h.jsx(or,{path:`${Fe.workbench.path}/tab/:id`,element:h.jsx(nj,{})}),h.jsx(or,{path:Fe.login.path,element:h.jsx(Kj,{})}),h.jsx(or,{path:Fe.share.path,element:h.jsx(Fj,{})})]}),h.jsx(vE,{}),h.jsx(NE,{}),h.jsx(HE,{}),h.jsx(yj,{}),h.jsx(Oj,{}),h.jsx(qj,{}),h.jsx(Yj,{}),h.jsx(UE,{}),h.jsx(RE,{})]})}const Xj="_desktop-layout_2r7hd_2",Zj="_mobile-layout_2r7hd_2",Pj="_nav_2r7hd_2",Jj="_main_2r7hd_2",Ij="_header_2r7hd_2",Fi={desktopLayout:Xj,mobileLayout:Zj,nav:Pj,main:Jj,header:Ij},Wj="_container_rgr97_2",eN="_menu_rgr97_2",hh={container:Wj,menu:eN},tN=({name:n,id:l,onRename:r,onDelete:s,onOpen:o})=>{const u=_1();return h.jsxs("button",{className:hh.menu,onContextMenu:u.open,onClick:()=>o(l),children:[h.jsx(j1,{handler:u,children:h.jsxs("div",{className:"context-menu-container",children:[h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),u.close(),r(l)},className:"context-menu-item",children:"✏️ Rename"}),h.jsx("button",{onClick:d=>{d.preventDefault(),d.stopPropagation(),u.close(),s(l)},className:"context-menu-item",children:"🗑️ Delete"})]})}),h.jsxs("span",{children:["📖 ",n]})]})},nN=({dataSource:n,index:l})=>{const r=()=>{Yi(n.id)};return $t(l.toString(),()=>{Yi(s=>{if(s!==n.id)return n.id})}),h.jsxs("button",{className:hh.menu,onClick:r,children:[h.jsx(Ru,{size:20,type:n.dbType}),h.jsx("p",{className:"truncate flex-1 text-left mx-1.5",children:n.name}),h.jsx("span",{className:"hotkey",children:l})]})},aN=()=>{const n=qt(),{data:l}=aa(),{data:r}=V3(l==null?void 0:l.teamId),{data:s}=F3(l==null?void 0:l.teamId),o=ns(),u=r6(),d=s6(),m=v=>{o.mutateAsync({queryId:v}).then(b=>{n(`${Fe.workbench.path}/tab/${b.id}`)})},y=async v=>{const b=s==null?void 0:s.find(C=>C.id===v),E=await Nr("New name?",b==null?void 0:b.name);E&&u.mutate({id:v,payload:{name:E}})},p=v=>{var E;const b=(E=s==null?void 0:s.find(C=>C.id===v))==null?void 0:E.savedQueryId;b&&d.mutate(b)};return h.jsx("div",{className:hh.container,children:h.jsxs("div",{className:"flex-1 overflow-y-auto",children:[pl(r==null?void 0:r.length,0)&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold text-sm text-gray-600 mb-2",children:"DATA SOURCES"}),r.map((v,b)=>h.jsx(nN,{dataSource:v,index:b+1},v.id))]}),pl(s==null?void 0:s.length,0)&&h.jsxs("div",{className:"mt-4",children:[h.jsx("p",{className:"font-semibold text-sm text-gray-600 mb-2",children:"SAVED QUERIES"}),s.map(v=>h.jsx(tN,{onDelete:p,onRename:y,onOpen:m,name:v.name,id:v.id},v.savedQueryId))]})]})})},lN=()=>{const n=qt(),{pathname:l}=Yt(),{data:r}=aa(),s=Cr("Desktop nav"),o=()=>{I1(),l!==Fe.home.path&&n(Fe.home.path)};return h.jsxs("nav",{className:Fi.nav,children:[r&&h.jsxs("div",{className:Fi.header,children:[h.jsxs("button",{onClick:o,className:"flex justify-between items-center",children:[h.jsx("span",{children:"🏠 Home"}),h.jsx("span",{className:"hotkey",children:"H"})]}),h.jsxs("button",{onClick:s,className:"flex justify-between items-center",children:[h.jsx("span",{children:"🔎 New query"}),h.jsx("span",{className:"hotkey",children:"N"})]}),h.jsxs("button",{onClick:eg,children:["🪪 ",r.username]}),h.jsx("button",{onClick:ng,children:"👥 Manage users"})]}),h.jsx(aN,{})]})},iN="_root_10pne_2",sN={root:iN},rN=()=>{const{pathname:n}=Yt(),l=qt(),r=Cr("Mobile nav"),s=()=>{n!==Fe.home.path&&l(Fe.home.path)};return h.jsxs("div",{className:sN.root,children:[h.jsxs("button",{onClick:s,children:[h.jsx("p",{children:"🏠"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Home"})]}),h.jsxs("button",{onClick:r,children:[h.jsx("p",{children:"🔎"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"New query"})]}),h.jsxs("button",{onClick:eg,children:[h.jsx("p",{children:"🪪"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Account"})]}),h.jsxs("button",{onClick:ng,children:[h.jsx("p",{children:"👥"}),h.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Users"})]})]})},oN=({children:n,isLogin:l})=>h.jsxs("div",{className:Fi.desktopLayout,children:[h.jsx(fh,{id:"default",className:"z-100"}),!l&&h.jsx(lN,{}),h.jsx("main",{className:Fi.main,children:n})]}),uN=({children:n,isLogin:l})=>h.jsxs("div",{className:Fi.mobileLayout,children:[h.jsx("main",{className:Fi.main,children:n}),!l&&h.jsx(rN,{})]}),cN=({children:n})=>{const l=nh(Ou.laptop),{pathname:r}=Yt(),s=r===Fe.login.path;return l?h.jsx(oN,{isLogin:s,children:n}):h.jsx(uN,{isLogin:s,children:n})};gx.createRoot(document.getElementById("root")).render(h.jsxs(Ve.StrictMode,{children:[h.jsx($3,{}),h.jsx(yS,{client:ft,children:h.jsx(U2,{children:h.jsx(cN,{children:h.jsx(Gj,{})})})})]}));
@@ -7,7 +7,7 @@
7
7
  <title>DataRamen | Lightweight GUI for MySQL & PostgreSQL</title>
8
8
  <meta name="description" content="Designed for speed, DataRamen makes navigating MySQL and PostgreSQL data effortless with a clean, high-performance interface." />
9
9
  <meta name="robots" content="noindex, nofollow">
10
- <script type="module" crossorigin src="/assets/index-DUxATqfw.js"></script>
10
+ <script type="module" crossorigin src="/assets/index-LSlJZCLU.js"></script>
11
11
  <link rel="stylesheet" crossorigin href="/assets/index-D70wG5MQ.css">
12
12
  </head>
13
13
  <body>
package/dist/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@dataramen/server","version":"0.0.77.beta-2","license":"MIT","main":"code/server.js","dependencies":{"@fastify/cors":"^11.0.1","@fastify/static":"^8.2.0","@fastify/cookie":"^11.0.2","dotenv":"^16.5.0","fast-glob":"^3.3.3","fastify":"^5.3.2","mysql2":"^3.14.1","pg":"^8.15.6","sqlite3":"^5.1.7","typeorm":"^0.3.23","bcryptjs":"^3.0.2","jose":"^6.0.12","reflect-metadata":"^0.2.2","qs":"^6.14.0"},"devDependencies":{"fs-extra":"^11.3.0","open":"^10.2.0","yargs":"^18.0.0","yocto-spinner":"^1.0.0"}}
1
+ {"name":"@dataramen/server","version":"0.0.77.beta-3","license":"MIT","main":"code/server.js","dependencies":{"@fastify/cors":"^11.0.1","@fastify/static":"^8.2.0","@fastify/cookie":"^11.0.2","dotenv":"^16.5.0","fast-glob":"^3.3.3","fastify":"^5.3.2","mysql2":"^3.14.1","pg":"^8.15.6","sqlite3":"^5.1.7","typeorm":"^0.3.23","bcryptjs":"^3.0.2","jose":"^6.0.12","reflect-metadata":"^0.2.2","qs":"^6.14.0"},"devDependencies":{"fs-extra":"^11.3.0","open":"^10.2.0","yargs":"^18.0.0","yocto-spinner":"^1.0.0"}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataramen/cli",
3
- "version": "0.0.54.beta-2",
3
+ "version": "0.0.54.beta-3",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "dataramen": "bin/run.js"