@kazurolabs/psql-explorer 0.3.0 → 0.3.1

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.
Files changed (32) hide show
  1. package/RELEASES.md +8 -0
  2. package/dist/explorer/explain.js +29 -12
  3. package/dist/explorer/rows.js +79 -6
  4. package/dist/explorer/session.js +8 -1
  5. package/dist/web/server.js +2 -2
  6. package/package.json +2 -1
  7. package/web/dist/assets/{button-ClA70PLR.js → button-BiFx4Lyw.js} +1 -1
  8. package/web/dist/assets/{code-xml-CXkpHeU9.js → code-xml-CPEjNFOw.js} +1 -1
  9. package/web/dist/assets/{compare-view-DKl5l_Jw.js → compare-view-COQ3yE76.js} +1 -1
  10. package/web/dist/assets/{copy-CCXzeW-s.js → copy-C2N9tUYJ.js} +1 -1
  11. package/web/dist/assets/{cypher-view-Pd0WFH8F.js → cypher-view-BzyL4mNU.js} +1 -1
  12. package/web/dist/assets/{design-view-CIHSmH4u.js → design-view-BPm7dSTY.js} +1 -1
  13. package/web/dist/assets/{erd-view-CV7mFGAN.js → erd-view-DqGDws2_.js} +1 -1
  14. package/web/dist/assets/{format-sql-BLj5_RDZ.js → format-sql-CoddYUOF.js} +1 -1
  15. package/web/dist/assets/{graph-force-yBLyErpS.js → graph-force-ChCGXQUt.js} +1 -1
  16. package/web/dist/assets/{graph-link-OCo_s0zO.js → graph-link-C8P9s_0W.js} +1 -1
  17. package/web/dist/assets/{graph-view-sM1OlByf.js → graph-view-BpoUrUCP.js} +1 -1
  18. package/web/dist/assets/{index-CDcnUacl.js → index-CpHnjRLv.js} +3 -3
  19. package/web/dist/assets/{key-round-Cv_7QeED.js → key-round-JiGCgCWS.js} +1 -1
  20. package/web/dist/assets/{loader-circle-BK_GMdvN.js → loader-circle-BxDJOoJO.js} +1 -1
  21. package/web/dist/assets/{query-builder-view-ChNFb51g.js → query-builder-view-CtRexMEX.js} +1 -1
  22. package/web/dist/assets/{rotate-ccw-CdCaf7Q6.js → rotate-ccw-CwdA-J3t.js} +1 -1
  23. package/web/dist/assets/{route-DO6IZ7of.js → route-7eu-iAqD.js} +1 -1
  24. package/web/dist/assets/{seed-view-DFNB8WHE.js → seed-view-BIkBTiU6.js} +1 -1
  25. package/web/dist/assets/{shield-alert-CMS-3j4U.js → shield-alert-keJIAND5.js} +1 -1
  26. package/web/dist/assets/{sliders-horizontal-Dg51yc-C.js → sliders-horizontal-DKtL_ql7.js} +1 -1
  27. package/web/dist/assets/sql-tabs-DUSXdYCr.js +2 -0
  28. package/web/dist/assets/{table-DfMz2f8M.js → table-Drc_n1gF.js} +1 -1
  29. package/web/dist/assets/{triangle-alert-COGnHCD1.js → triangle-alert-C5nF69rW.js} +1 -1
  30. package/web/dist/assets/{zone-D9dXk8tn.js → zone-CHDOrDBF.js} +1 -1
  31. package/web/dist/index.html +8 -8
  32. package/web/dist/assets/sql-tabs-B4jt6bQj.js +0 -2
@@ -0,0 +1,2 @@
1
+ import{$ as e,G as t,H as n,K as r,Q as i,V as a,W as o,X as s,Y as c,Z as l,_ as u,a as d,at as f,ct as p,d as m,et as h,f as g,h as _,i as v,it as y,l as b,m as x,n as S,nt as C,ot as w,rt as T,tt as E,u as D,v as O,y as k}from"./route-7eu-iAqD.js";import{i as A,n as j,o as M,r as N,u as P}from"./graph-link-C8P9s_0W.js";import{A as F,I,L as ee,M as L,N as R,P as z,R as B,S as V,_ as te,a as H,b as U,c as W,j as ne,n as G,o as re,r as ie,s as K,t as q,v as ae,x as oe,z as se}from"./button-BiFx4Lyw.js";import{a as ce,d as le,i as ue,n as de,o as fe,t as pe,u as me}from"./zone-CHDOrDBF.js";import{t as he}from"./copy-C2N9tUYJ.js";import{t as ge}from"./key-round-JiGCgCWS.js";import{t as _e}from"./loader-circle-BxDJOoJO.js";import{t as ve}from"./shield-alert-keJIAND5.js";import{t as ye}from"./sliders-horizontal-DKtL_ql7.js";import{a as be,i as xe,n as Se,o as Ce,r as we,t as Te}from"./table-Drc_n1gF.js";import{$ as Ee,$t as De,A as Oe,At as ke,B as Ae,Bt as J,C as je,Ct as Me,D as Ne,E as Pe,Et as Fe,F as Ie,Ft as Le,H as Re,Ht as ze,I as Be,It as Ve,J as He,Jt as Ue,K as We,Kt as Ge,L as Ke,Lt as qe,M as Je,N as Ye,Nt as Xe,O as Ze,Ot as Qe,P as $e,Q as et,Qt as tt,R as nt,Rt as rt,S as it,St as at,T as ot,Tt as st,Ut as ct,V as lt,Vt as ut,W as dt,Wt as ft,Xt as pt,Z as mt,Zt as ht,_ as gt,_t,a as vt,at as yt,b as bt,bt as xt,c as St,cn as Ct,ct as wt,d as Tt,dt as Et,et as Dt,f as Ot,ft as kt,g as At,gt as jt,h as Mt,ht as Nt,i as Pt,in as Ft,it as It,j as Lt,jt as Rt,k as zt,kt as Bt,l as Vt,lt as Ht,m as Ut,mt as Wt,n as Gt,nn as Kt,nt as qt,o as Jt,ot as Yt,p as Xt,pt as Zt,q as Qt,qt as $t,r as en,rt as tn,s as nn,sn as rn,st as an,t as on,tt as sn,u as cn,ut as ln,v as un,vt as dn,w as fn,wt as pn,x as mn,xt as hn,y as gn,yt as Y,z as _n}from"./index-CpHnjRLv.js";import{t as vn}from"./format-sql-CoddYUOF.js";var yn={name:`box`,size:24,node:[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]};yn.node;var bn=f(yn),xn={name:`braces`,size:24,node:[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]],aliases:[`curly-braces`]};xn.node;var Sn=f(xn),Cn={name:`circle-alert`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]],aliases:[`alert-circle`]};Cn.node;var wn=f(Cn),Tn={name:`circle-check`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 9-5.5 5.5L8 12`,key:`xofnsj`}]],aliases:[`check-circle-2`]};Tn.node;var En=f(Tn),Dn={name:`ellipsis`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]],aliases:[`more-horizontal`]};Dn.node;var On=f(Dn),kn={name:`folder-tree`,size:24,node:[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]};kn.node;var An=f(kn),jn={name:`globe`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]};jn.node;var Mn=f(jn),Nn={name:`list-checks`,size:24,node:[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]};Nn.node;var Pn=f(Nn),Fn={name:`pin`,size:24,node:[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]};Fn.node;var In=f(Fn),Ln={name:`pin-off`,size:24,node:[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]};Ln.node;var Rn=f(Ln),zn={name:`rotate-ccw-clock`,size:24,node:[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]],aliases:[`history`]};zn.node;var Bn=f(zn),Vn={name:`save`,size:24,node:[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]};Vn.node;var Hn=f(Vn),Un={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};Un.node;var Wn=f(Un),Gn={name:`text-align-start`,size:24,node:[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]],aliases:[`text`,`align-left`]};Gn.node;var Kn=f(Gn),qn={name:`type`,size:24,node:[[`path`,{d:`M12 4v16`,key:`1654pz`}],[`path`,{d:`M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2`,key:`e0r10z`}],[`path`,{d:`M9 20h6`,key:`s66wpe`}]]};qn.node;var Jn=f(qn),Yn={name:`workflow`,size:24,node:[[`rect`,{width:`8`,height:`8`,x:`3`,y:`3`,rx:`2`,key:`by2w9f`}],[`path`,{d:`M7 11v4a2 2 0 0 0 2 2h4`,key:`xkn7yn`}],[`rect`,{width:`8`,height:`8`,x:`13`,y:`13`,rx:`2`,key:`1cgmvn`}]]};Yn.node;var Xn=f(Yn);function Zn(e,t){return t!=null&&!Ht(t)?0:typeof e==`function`?e():e}function Qn(e,t,n){let r=Zn(e,n);return typeof r==`number`?r:r?.[t]}function $n(e){return typeof e==`function`?e():e}function er(e,t){return t||e===`click`||e===`mousedown`}function tr(e){return e?.includes(`mouse`)&&e!==`mousedown`}function nr(e){let{popupStore:t,treatPopupAsFloatingElement:n=!1,floatingRootContext:r,floatingId:i,nested:a,onOpenChange:o}=e,s=t.useState(`open`),c=t.useState(`activeTriggerElement`),l=t.useState(n?`popupElement`:`positionerElement`),u=o;return t.useSyncedValue(`floatingId`,i),K(()=>{let e={open:s,floatingId:i,referenceElement:c,floatingElement:l};U(c)&&(e.domReferenceElement=c),r.state.positionReference===r.state.referenceElement&&(e.positionReference=c),r.update(e)},[s,i,c,l,r]),r.context.onOpenChange=u,r.context.nested=a,r}function rr(e,t,n=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new Tt({open:!1,transitionStatus:void 0,floatingElement:null,referenceElement:null,triggerElements:e,floatingId:t,syncOnly:!0,nested:n,onOpenChange:void 0}),floatingId:t,triggerCount:0,preventUnmountingOnClose:!1,payload:void 0,activeTriggerId:null,activeTriggerElement:null,openedWithoutTrigger:!1,triggerIdProp:void 0,popupElement:null,positionerElement:null,activeTriggerProps:R,inactiveTriggerProps:R,popupProps:R}}var ir=e=>e.triggerIdProp??e.activeTriggerId,ar=e=>e.openProp??e.open,or=e=>(e.popupElement?.id??e.floatingId)||void 0;function sr(e,t){return t!==void 0&&ar(e)&&ir(e)===t}function cr(e,t){return sr(e,t)?!0:t!==void 0&&ar(e)&&ir(e)==null&&!e.openedWithoutTrigger&&e.triggerCount===1}var lr={open:ar,mounted:e=>e.mounted,transitionStatus:e=>ar(e)&&!e.mounted?`starting`:e.transitionStatus,floatingRootContext:e=>e.floatingRootContext,triggerCount:e=>e.triggerCount,preventUnmountingOnClose:e=>e.preventUnmountingOnClose,payload:e=>e.payload,activeTriggerId:ir,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:or,isTriggerActive:(e,t)=>t!==void 0&&ir(e)===t,isOpenedByTrigger:(e,t)=>sr(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&ir(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>cr(e,t)?or(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement},X=p(w(),1),ur=Yt();function dr(e){let t=X.useCallback(t=>e===void 0?z:e.subscribeStore(t),[e]),n=X.useCallback(()=>e===void 0?void 0:e.store,[e]);return(0,ur.useSyncExternalStore)(t,n,()=>e?.serverStore)}var fr=at&&hn;function pr(e,t={}){let{enabled:n=!0,delay:r}=t,{events:i,dataRef:a}=e.context,o=X.useRef(!1),s=X.useRef(null),c=X.useRef(!0),l=Be();X.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=ae(t);function i(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&oe(t)&&t===_t(ct(t))&&(o.current=!0,s.current=t)}function a(){c.current=!0}function l(){c.current=!1}return nt(Ke(r,`blur`,i),fr&&Ke(r,`keydown`,a,!0),fr&&Ke(r,`pointerdown`,l,!0))},[e,n]),X.useEffect(()=>{if(!n)return;function t(t){if(t.reason===`trigger-press`||t.reason===`escape-key`){let t=e.select(`domReferenceElement`);U(t)&&(s.current=t,o.current=!0)}}return i.on(`openchange`,t),()=>{i.off(`openchange`,t)}},[i,n,e]);let u=X.useMemo(()=>{function t(){o.current=!1,s.current=null}return{onMouseLeave(){t()},onFocus(n){let i=n.currentTarget;if(o.current){if(s.current===i)return;t()}let a=xt(n.nativeEvent);if(U(a)){if(fr&&!n.relatedTarget){if(!c.current&&!Zt(a))return}else if(!Wt(a))return}let u=kt(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:f}=n;e.select(`open`)&&u||!r?e.setOpen(!0,J(qe,d,f)):l.start(r,()=>{o.current||e.setOpen(!0,J(qe,d,f))})},onBlur(n){t();let r=n.relatedTarget,i=n.nativeEvent,o=U(r)&&r.hasAttribute(Ye(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;l.start(0,()=>{let t=e.select(`domReferenceElement`),n=_t(ct(t));!r&&n===t||Y(a.current.floatingContext?.refs.floating.current,n)||Y(t,n)||o||kt(r??n,e.context.triggerElements)||e.setOpen(!1,J(qe,i))})}}},[a,r,e,l]);return X.useMemo(()=>n?{reference:u,trigger:u}:{},[n,u])}var mr=class e{pointerType=void 0;interactedInside=!1;handler=void 0;blockMouseMove=!0;performedPointerEventsMutation=!1;pointerEventsScopeElement=null;pointerEventsReferenceElement=null;pointerEventsFloatingElement=null;restTimeoutPending=!1;openChangeTimeout=new Ie;restTimeout=new Ie;handleCloseOptions=void 0;static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},hr=new WeakMap;function gr(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&hr.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),hr.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function _r(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=hr.get(n);a&&a!==e&&gr(a),gr(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,hr.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function vr(e){let t=e.context.dataRef.current,n=ee(()=>t.hoverInteractionState??mr.create()).current;return t.hoverInteractionState||=n,It(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function yr(e,t={}){let{enabled:n=!0,closeDelay:r=0,nodeId:i}=t,a=e.useState(`open`),o=e.useState(`floatingElement`),s=e.useState(`domReferenceElement`),{dataRef:c}=e.context,l=Ze(),u=Ne(),d=vr(e),f=Be(),p=W(()=>er(c.current.openEvent?.type,d.interactedInside)),m=W(()=>tr(c.current.openEvent?.type)),h=W(()=>{gr(d)});K(()=>{a||(d.pointerType=void 0,d.restTimeoutPending=!1,d.interactedInside=!1,h())},[a,d,h]),X.useEffect(()=>h,[h]),K(()=>{if(n&&a&&d.handleCloseOptions?.blockPointerEvents&&m()&&U(s)&&o){let e=s,t=o,n=ct(o),r=l?.nodesRef.current.find(e=>e.id===u)?.context?.elements.floating;r&&(r.style.pointerEvents=``);let i=d.pointerEventsScopeElement===t?null:d.pointerEventsScopeElement,a=r===t?null:r,c=d.handleCloseOptions?.getScope?.()??i??a??dn(e,`[data-rootownerid]`)??n.body;return _r(d,{scopeElement:c,referenceElement:e,floatingElement:t}),()=>{h()}}},[n,a,s,o,d,m,l,u,h]),X.useEffect(()=>{if(!n)return;function t(){return!!(l&&u&&ln(l.nodesRef.current,u).length>0)}function a(t){let n=Qn(r,`close`,d.pointerType),i=()=>{e.setOpen(!1,J(rt,t)),l?.events.emit(`floating.closed`,t)};n?d.openChangeTimeout.start(n,i):(d.openChangeTimeout.clear(),i())}function s(e){let t=xt(e);Et(t)?d.interactedInside=dn(t,`[aria-haspopup]`)!=null:d.interactedInside=!1}function g(){d.openChangeTimeout.clear(),f.clear(),l?.events.off(`floating.closed`,v),h()}function _(n){if(t()&&l){l.events.on(`floating.closed`,v);return}if(kt(n.relatedTarget,e.context.triggerElements))return;let r=c.current.floatingContext?.nodeId??i,o=n.relatedTarget;l&&r&&U(o)&&ln(l.nodesRef.current,r,!1).some(e=>Y(e.context?.elements.floating,o))||(d.handler?d.handler(n):(h(),m()&&!p()&&a(n)))}function v(n){l&&u&&!t()&&f.start(0,()=>{l.events.off(`floating.closed`,v),e.setOpen(!1,J(rt,n)),l.events.emit(`floating.closed`,n)})}let y=o;return nt(y&&Ke(y,`mouseenter`,g),y&&Ke(y,`mouseleave`,_),y&&Ke(y,`pointerdown`,s,!0),()=>{l?.events.off(`floating.closed`,v)})},[n,o,e,c,r,i,m,p,h,d,l,u,f])}var br=p(Ct(),1),xr={current:null};function Sr(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=xr,externalTree:l,isActiveTrigger:u=!0,getHandleCloseContext:d,isClosing:f,shouldOpen:p,guardStaleOpen:m=!1}=t,{dataRef:h,events:g}=e.context,_=Ze(l),v=vr(e),y=X.useRef(!1),b=Re(i),x=Re(r),S=Re(o),C=Re(n),w=Re(p),T=Re(f),E=W(()=>er(h.current.openEvent?.type,v.interactedInside)),D=W(()=>w.current?.()!==!1),O=W((t,n,r)=>{let i=e.context.triggerElements;if(i.hasElement(n))return!t||!Y(t,n);if(!U(r))return!1;let a=r;return i.hasMatchingElement(e=>Y(e,a))&&(!t||!Y(t,a))}),k=W(()=>{v.handler&&=(ct(e.select(`domReferenceElement`)).removeEventListener(`mousemove`,v.handler),void 0)}),A=W(()=>{gr(v)});return u&&(v.handleCloseOptions=i?.__options),X.useEffect(()=>k,[k]),X.useEffect(()=>{if(!n)return;function e(e){e.open?y.current=!1:(y.current=e.reason===rt,k(),v.openChangeTimeout.clear(),v.restTimeout.clear(),v.blockMouseMove=!0,v.restTimeoutPending=!1)}return g.on(`openchange`,e),()=>{g.off(`openchange`,e)}},[n,g,v,k]),X.useEffect(()=>{if(!n)return;function t(t,n=!0){let r=Qn(x.current,`close`,v.pointerType);r?v.openChangeTimeout.start(r,()=>{e.setOpen(!1,J(rt,t)),_?.events.emit(`floating.closed`,t)}):n&&(v.openChangeTimeout.clear(),e.setOpen(!1,J(rt,t)),_?.events.emit(`floating.closed`,t))}let r=c.current??(u?e.select(`domReferenceElement`):null);if(!U(r))return;function i(t){if(v.openChangeTimeout.clear(),v.blockMouseMove=!1,a&&!Ht(v.pointerType))return;let n=$n(S.current),r=Qn(x.current,`open`,v.pointerType),i=xt(t),o=t.currentTarget??null,s=e.select(`domReferenceElement`),c=o;if(U(i)&&!e.context.triggerElements.hasElement(i)){for(let t of e.context.triggerElements.elements())if(Y(t,i)){c=t;break}}U(o)&&U(s)&&!e.context.triggerElements.hasElement(o)&&Y(o,s)&&(c=s);let l=c!=null&&O(s,c,i),u=e.select(`open`),d=T.current?.()??e.select(`transitionStatus`)===`ending`,f=!u&&d&&y.current,p=!l&&U(c)&&U(s)&&Y(s,c)&&f,m=n>0&&!r,h=l&&(u||f)||p,g=!u||l;h?D()&&e.setOpen(!0,J(rt,t,c)):m||(r?v.openChangeTimeout.start(r,()=>{g&&D()&&e.setOpen(!0,J(rt,t,c))}):g&&D()&&e.setOpen(!0,J(rt,t,c)))}function o(n){if(E()){A();return}k();let r=e.select(`domReferenceElement`),i=ct(r);v.restTimeout.clear(),v.restTimeoutPending=!1;let a=h.current.floatingContext??d?.();if(!kt(n.relatedTarget,e.context.triggerElements)){if(b.current&&a){e.select(`open`)||v.openChangeTimeout.clear();let r=c.current;v.handler=b.current({...a,tree:_,x:n.clientX,y:n.clientY,onClose(){A(),k(),C.current&&!E()&&r===e.select(`domReferenceElement`)&&t(n,!0)}}),i.addEventListener(`mousemove`,v.handler),v.handler(n)}else v.pointerType===`touch`&&Y(e.select(`floatingElement`),n.relatedTarget)||t(n)}}function l(e){Y(r,e.relatedTarget)||(v.openChangeTimeout.clear(),v.restTimeout.clear(),v.restTimeoutPending=!1)}let f=m?Ke(r,`mouseout`,l):void 0;return s?nt(Ke(r,`mousemove`,i,{once:!0}),Ke(r,`mouseenter`,i),Ke(r,`mouseleave`,o),f):nt(Ke(r,`mouseenter`,i),Ke(r,`mouseleave`,o),f)},[k,A,h,x,e,n,b,v,u,O,E,a,s,S,c,_,C,d,T,D,m]),X.useMemo(()=>{if(!n)return;function t(e){v.pointerType=e.pointerType}return{onPointerDown:t,onPointerEnter:t,onMouseMove(t){let{nativeEvent:n}=t,r=t.currentTarget,i=e.select(`domReferenceElement`),o=e.select(`open`),s=O(i,r,t.target);if(a&&!Ht(v.pointerType))return;if(o&&s&&v.handleCloseOptions?.blockPointerEvents){let t=e.select(`floatingElement`);if(t){let e=v.handleCloseOptions?.getScope?.()??r.ownerDocument.body;_r(v,{scopeElement:e,referenceElement:r,floatingElement:t})}}let c=$n(S.current);if(o&&!s||c===0||!s&&v.restTimeoutPending&&t.movementX**2+t.movementY**2<2)return;v.restTimeout.clear();function l(){if(v.restTimeoutPending=!1,E())return;let t=e.select(`open`);!v.blockMouseMove&&(!t||s)&&D()&&e.setOpen(!0,J(rt,n,r))}v.pointerType===`touch`?br.flushSync(()=>{l()}):s&&o?l():(v.restTimeoutPending=!0,v.restTimeout.start(c,l))}}},[n,v,E,O,a,e,S,D])}var Cr=.1,wr=Cr*Cr,Z=.5;function Tr(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function Er(e,t,n,r,i,a,o,s,c,l){let u=!1;return Tr(e,t,n,r,i,a)&&(u=!u),Tr(e,t,i,a,o,s)&&(u=!u),Tr(e,t,o,s,c,l)&&(u=!u),Tr(e,t,c,l,n,r)&&(u=!u),u}function Dr(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function Or(e,t,n,r,i,a){return e>=Math.min(n,i)&&e<=Math.max(n,i)&&t>=Math.min(r,a)&&t<=Math.max(r,a)}function kr(e={}){let{blockPointerEvents:t=!1}=e,n=new Ie,r=({x:e,y:t,placement:r,elements:i,onClose:a,nodeId:o,tree:s})=>{let c=r?.split(`-`)[0],l=!1,u=null,d=null,f=typeof performance<`u`?performance.now():0;function p(e,t){let n=performance.now(),r=n-f;if(u===null||d===null||r===0)return u=e,d=t,f=n,!1;let i=e-u,a=t-d,o=i*i+a*a,s=r*r*wr;return u=e,d=t,f=n,o<s}function m(){n.clear(),a()}return function(r){n.clear();let a=i.domReference,u=i.floating;if(!a||!u||c==null||e==null||t==null)return;let{clientX:d,clientY:f}=r,h=xt(r),g=r.type===`mouseleave`,_=Y(u,h),v=Y(a,h);if(_&&(l=!0,!g))return;if(v&&(l=!1,!g)){l=!0;return}if(g&&U(r.relatedTarget)&&Y(u,r.relatedTarget))return;function y(){return!!(s&&ln(s.nodesRef.current,o).length>0)}function b(){y()||m()}if(y())return;let x=a.getBoundingClientRect(),S=u.getBoundingClientRect(),C=e>S.right-S.width/2,w=t>S.bottom-S.height/2,T=S.width>x.width,E=S.height>x.height,D=(T?x:S).left,O=(T?x:S).right,k=(E?x:S).top,A=(E?x:S).bottom;if(c===`top`&&t>=x.bottom-1||c===`bottom`&&t<=x.top+1||c===`left`&&e>=x.right-1||c===`right`&&e<=x.left+1){b();return}let j=!1;switch(c){case`top`:j=Or(d,f,D,x.top+1,O,S.bottom-1);break;case`bottom`:j=Or(d,f,D,S.top+1,O,x.bottom-1);break;case`left`:j=Or(d,f,S.right-1,A,x.left+1,k);break;case`right`:j=Or(d,f,x.right-1,A,S.left+1,k)}if(j)return;if(l&&!Dr(d,f,x)||!g&&p(d,f)){b();return}let M=!1;switch(c){case`top`:{let n=T?Z/2:Z*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t+Z+1,o=C||T?S.bottom-Z:S.top,s=C?T?S.bottom-Z:S.top:S.bottom-Z;M=Er(d,f,r,a,i,a,S.left,o,S.right,s);break}case`bottom`:{let n=T?Z/2:Z*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t-Z,o=C||T?S.top+Z:S.bottom,s=C?T?S.top+Z:S.bottom:S.top+Z;M=Er(d,f,r,a,i,a,S.left,o,S.right,s);break}case`left`:{let n=E?Z/2:Z*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e+Z+1,o=w||E?S.right-Z:S.left,s=w?E?S.right-Z:S.left:S.right-Z;M=Er(d,f,o,S.top,s,S.bottom,a,r,a,i);break}case`right`:{let n=E?Z/2:Z*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e-Z,o=w||E?S.left+Z:S.right,s=w?E?S.left+Z:S.right:S.left+Z;M=Er(d,f,a,r,a,i,o,S.top,s,S.bottom);break}}M?l||n.start(40,b):b()}};return r.__options={...e,blockPointerEvents:t},r}var Q=T(),Ar=[`statement_timeout`,`work_mem`,`search_path`,`role`,`enable_seqscan`,`enable_nestloop`,`random_page_cost`,`app.tenant_id`];function jr(e){let[t,n]=(0,X.useState)(()=>E(e));return{rows:t,change:t=>{n(t),C(e,h(t))},count:h(t).length}}function Mr({rows:e,change:t}){return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{className:`basis-full space-y-2 border p-3`,role:`group`,"aria-label":`Session settings`,children:[(0,Q.jsx)(`datalist`,{id:`guc-names`,children:Ar.map(e=>(0,Q.jsx)(`option`,{value:e},e))}),e.map((n,r)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{className:`border-input bg-card w-56 border px-2 py-1 font-mono text-sm`,list:`guc-names`,placeholder:`name, e.g. statement_timeout`,"aria-label":`Setting name`,value:n.name,onChange:n=>t(e.map((e,t)=>t===r?{...e,name:n.target.value}:e))}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`=`}),(0,Q.jsx)(`input`,{className:`border-input bg-card w-56 border px-2 py-1 font-mono text-sm`,placeholder:`value, e.g. 5s`,"aria-label":`Setting value`,value:n.value,onChange:n=>t(e.map((e,t)=>t===r?{...e,value:n.target.value}:e))}),(0,Q.jsx)(q,{variant:`outline`,"aria-label":`Remove setting`,onClick:()=>t(e.filter((e,t)=>t!==r)),children:(0,Q.jsx)($t,{className:`size-4`})})]},r)),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(q,{variant:`outline`,onClick:()=>t([...e,{name:``,value:``}]),children:[(0,Q.jsx)(tt,{className:`size-4`}),` Add setting`]}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Set with set_config for the whole session before Run, Explain and export; remembered per environment in this browser.`})]})]})})}var Nr=`border-input bg-background rounded-lg border px-2 py-1 text-sm`,Pr=e=>e.trim().replace(/\s+/g,` `);function Fr({environment:t,sql:n,refresh:r,onPick:i}){let[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)([]),[l,u]=(0,X.useState)([]),[d,f]=(0,X.useState)(),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(0);(0,X.useEffect)(()=>{let n=!0,r=window.setTimeout(()=>{Promise.all([e.history(t,a),e.saved(t)]).then(([e,t])=>{n&&(c(e),u(t),f(void 0))},e=>n&&f(e.message))},200);return()=>{n=!1,window.clearTimeout(r)}},[t,a,r,_]);let y=e=>e.then(()=>v(e=>e+1),e=>f(e.message)),b=a.trim().toLowerCase(),x=(0,X.useMemo)(()=>l.filter(e=>!b||e.name.toLowerCase().includes(b)||e.folder.toLowerCase().includes(b)||e.sql.toLowerCase().includes(b)),[l,b]),S=(0,X.useMemo)(()=>{let e=new Map;for(let t of x)e.set(t.folder,[...e.get(t.folder)??[],t]);return[...e]},[x]),C=[...new Set(l.map(e=>e.folder).filter(Boolean))];return(0,Q.jsxs)(`section`,{"aria-label":`History and saved queries`,className:`border-input mb-4 border p-3`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`search`,"aria-label":`Search history and saved queries`,placeholder:`Search history and saved queries`,value:a,onChange:e=>o(e.target.value),className:`${Nr} w-72`}),(0,Q.jsx)(`input`,{"aria-label":`Name for the query`,placeholder:`Name`,value:p,maxLength:80,onChange:e=>m(e.target.value),className:`${Nr} w-40`}),(0,Q.jsx)(`input`,{"aria-label":`Folder for the query`,placeholder:`Folder`,value:h,list:`query-folders`,maxLength:60,onChange:e=>g(e.target.value),className:`${Nr} w-36`}),(0,Q.jsx)(`datalist`,{id:`query-folders`,children:C.map(e=>(0,Q.jsx)(`option`,{value:e},e))}),(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,disabled:!n.trim(),onClick:()=>{y(e.saveQuery(t,{sql:n,name:p,folder:h})),m(``)},children:[(0,Q.jsx)(Hn,{}),` Save current query`]})]}),d&&(0,Q.jsx)(`p`,{className:`text-destructive mb-2 text-sm`,children:d}),(0,Q.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`mb-1 text-sm font-medium`,children:`Saved`}),S.length===0&&(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:b?`No saved query matches.`:`Nothing saved yet. Name the query above and save it, or pin one from the history.`}),S.map(([n,r])=>(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(n||S.length>1)&&(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs font-medium uppercase`,children:n||`No folder`}),(0,Q.jsx)(`ul`,{className:`text-sm`,children:r.map(n=>(0,Q.jsxs)(`li`,{className:`group flex items-center gap-2 py-0.5`,children:[(0,Q.jsx)(`button`,{type:`button`,title:n.sql,onClick:()=>i(n.sql,n.name),className:`hover:text-accent-text min-w-0 flex-1 truncate text-left`,children:n.name}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":n.pinned?`Unpin ${n.name}`:`Pin ${n.name}`,title:n.pinned?`Unpin`:`Pin to the top`,onClick:()=>y(e.updateSaved(t,n.id,{pinned:!n.pinned})),className:n.pinned?`text-accent-text`:`text-muted-foreground hover:text-foreground`,children:n.pinned?(0,Q.jsx)(In,{className:`size-3.5`}):(0,Q.jsx)(Rn,{className:`size-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Delete ${n.name}`,title:`Delete`,onClick:()=>y(e.deleteSaved(t,n.id)),className:`text-muted-foreground hover:text-destructive`,children:(0,Q.jsx)(Ue,{className:`size-3.5`})})]},n.id))})]},n))]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`mb-1 text-sm font-medium`,children:`History`}),s.length===0&&(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:b?`No statement in the history matches.`:`No statements run yet.`}),(0,Q.jsx)(`ul`,{className:`max-h-72 overflow-auto text-sm`,children:s.map(n=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-2 py-0.5`,children:[(0,Q.jsx)(`button`,{type:`button`,title:n.sql,onClick:()=>i(n.sql),className:`hover:text-accent-text min-w-0 flex-1 truncate text-left font-mono text-xs`,children:Pr(n.sql)}),(0,Q.jsxs)(`span`,{className:`shrink-0 text-xs ${n.error?`text-destructive`:`text-muted-foreground`}`,title:n.error??void 0,children:[n.error?`failed`:et(n.durationMs),` · `,mt(n.at)]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Pin to saved queries`,title:`Pin to saved queries`,onClick:()=>y(e.saveQuery(t,{sql:n.sql,pinned:!0})),className:`text-muted-foreground hover:text-foreground`,children:(0,Q.jsx)(In,{className:`size-3.5`})})]},n.id))})]})]})]})}var Ir=X.createContext(void 0);function Lr(e){let t=X.useContext(Ir);if(t===void 0&&!e)throw Error(re(33));return t}var Rr=X.createContext(void 0);function zr(e){let t=X.useContext(Rr);if(t===void 0&&!e)throw Error(re(36));return t}var Br=X.createContext(void 0);function Vr(e=!0){let t=X.useContext(Br);if(t===void 0&&!e)throw Error(re(25));return t}var Hr=X.createContext(null);function Ur(e=`root`){let t=X.useContext(Hr),n=X.useContext(Rr);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var Wr={visible:!0,ref:null};function Gr(){return Wr}function Kr(e,t,n=`root`){let r=Ur(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??Gr)({label:e.label,children:e.children,render:e.render}),a=I(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}function qr(e){e.preventDefault()}function Jr(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=zr(),u=Vr(!0),d=c.type===`submenu-trigger`,f=d?l.parentVirtualFocus:l.virtualFocus,p=(d&&l.parent.type===`menu`?l.parent.store:l.store).useState(`webkitAriaSelected`,n),{events:m}=a.useState(`floatingTreeRoot`),h=a.useState(`open`),g=u!==void 0,_=!f&&h&&n?0:-1;return X.useMemo(()=>({id:r,role:`menuitem`,tabIndex:_,"aria-selected":p,onMouseDown:f?qr:void 0,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&m.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&m.emit(`close`,{domEvent:e.nativeEvent,reason:ke})},onMouseUp(e){if(u){let t=u.initialCursorPointRef.current;if(u.initialCursorPointRef.current=null,g&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||g&&!at&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&ie(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var Yr={type:`regular-item`};function Xr(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:l}=e,u=X.useRef(null),{getButtonProps:d,buttonRef:f}=G({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=Jr({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=X.useCallback(e=>B(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=I(u,f);return X.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var Zr=X.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,{store:d}=zr(),f=pn({guess:!0,label:a}),p=st(i),m=d.useState(`disabled`),h=d.useState(`isActive`,f.index),g=d.useState(`floatingNodeId`),_=d.useState(`itemProps`),v=s||m,{getItemProps:y,itemRef:b}=Xr({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:Yr});return ne(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),Qr=X.forwardRef(function(e,t){let n=Kr(e,t);return n.visible?(0,Q.jsx)(Zr,{...e,ref:n.ref}):null}),$r=X.createContext(void 0);function ei(){return X.useContext($r)}function ti(e,t){let n=F(e.render);if(X.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function ni(e,t,n){let r=ti(e,t),i=r===t?void 0:r;return[r,X.useCallback(e=>n?.(e?i:void 0),[i,n])]}function ri(e,t,n){let r=F(e.render),i=X.isValidElement(r)?r.props:void 0,a=e[`aria-label`]??i?.[`aria-label`],o=e[`aria-labelledby`]??i?.[`aria-labelledby`];return o==null&&!a&&(o=t?t.id||void 0:n||void 0),o}var ii=X.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,id:o,initialFocus:s,...c}=e,{store:l,defaultFloatingId:u,setRenderedFloatingId:d,virtualFocus:f,orientation:p}=zr(),m=ei(),{side:h,align:g}=Lr(),_=on(!0)!=null,v=l.useState(`open`),y=l.useState(`transitionStatus`),b=l.useState(`popupProps`),x=l.useState(`mounted`),S=l.useState(`instantType`),C=l.useState(`activeTriggerElement`),w=l.useState(`parent`),T=l.useState(`lastOpenChangeReason`),E=l.useState(`rootId`),D=l.useState(`floatingRootContext`),O=l.useState(`floatingTreeRoot`),k=l.useState(`closeDelay`),A=l.useState(`hoverEnabled`),j=l.useState(`disabled`),M=l.useState(`openMethod`),N=l.useState(`activeTriggerId`),P=l.useState(`listElement`),[F,I]=ni(e,u,d),ee=ri(e,C,N),L=w.type===`menu`?m:void 0,R=w.type===`context-menu`,z=s??w.type!==`menu`;s===void 0&&P&&w.type!==`menu`&&(z=()=>l.state.activeIndex===null&&P),qt({open:v,ref:l.context.popupRef,onComplete(){v&&l.context.onOpenChangeComplete?.(!0)}}),X.useEffect(()=>{function e(e){l.setOpen(!1,J(e.reason,e.domEvent))}return O.events.on(`close`,e),()=>{O.events.off(`close`,e)}},[O.events,l]),yr(D,{enabled:A&&!j&&!R&&w.type!==`menubar`,closeDelay:k});let B=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:V,handleFocus:te}=(X.useContext(Hr)?.useParentHandoff??oi)(l,w,v,f),H={transitionStatus:y,side:h,align:g,open:v,nested:w.type===`menu`,instant:S},U=ne(`div`,e,{state:H,ref:[t,l.context.popupRef,B,I],stateAttributesMapping:Nt,props:[b,{id:F,...P?{role:`presentation`}:{role:`menu`,"aria-orientation":p===`horizontal`?`horizontal`:void 0,"aria-labelledby":ee},onKeyDown(e){L?.onPopupKeyDown?.(e),_&&sn.has(e.key)&&e.stopPropagation()},onFocus:te},Pt(y),c,{"data-rootownerid":E}]}),W=w.type===void 0||R;(C||w.type===`menubar`&&T!==`outside-press`)&&(W=!0);let G=L?.getReturnElement??V;return(0,Q.jsx)(je,{context:D,openInteractionType:M,modal:R,disabled:!x,returnFocus:a??G??W,explicitReturnFocus:a===void 0&&G?!1:void 0,initialFocus:z,restoreFocus:!0,getInsideElements:w.type===void 0?()=>[l.context.beforeTriggerFocusGuardRef.current]:void 0,externalTree:w.type===`menubar`?void 0:O,previousFocusableElement:C,nextFocusableElement:w.type===void 0?l.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:U})}),ai={parentVirtualFocusRef:void 0,handleFocus:void 0};function oi(){return ai}var si=X.forwardRef(function(e,t){let n=Ur()?.Popup??ii;return(0,Q.jsx)(n,{...e,ref:t})}),ci=X.createContext(void 0);function li(){let e=X.useContext(ci);if(e===void 0)throw Error(re(32));return e}var ui=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=zr();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,Q.jsx)(ci.Provider,{value:n,children:(0,Q.jsx)(Oe,{ref:t,...r,portalOwnerRole:o})})});function di(e){let{store:t,domReference:n,positionerElement:r,open:i}=e,a=X.useRef(null),o=X.useRef(null),s=tn(r);K(()=>{i||(o.current?.abort(),o.current=null,t.state.instantType===`trigger-change`&&t.set(`instantType`,void 0))},[i,t]),K(()=>{let e=n,r=a.current;if(e&&(a.current=e),!r||!e||e===r||!t.select(`open`))return;t.set(`instantType`,void 0);let i=new AbortController;return o.current=i,s(()=>{t.select(`open`)&&t.set(`instantType`,`trigger-change`)},i.signal),()=>{i.abort()}},[n,s,t])}var fi=X.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:f=5,sticky:p=!1,disableAnchorTracking:m=!1,collisionAvoidance:h=Lt,style:g,..._}=e,{store:v,virtualFocus:y,syncHighlightedItem:b}=zr(),x=li(),S=Vr(!0),C=v.useState(`parent`),w=v.useState(`floatingRootContext`),T=v.useState(`floatingTreeRoot`),E=v.useState(`mounted`),D=v.useState(`open`),O=v.useState(`modal`),k=v.useState(`openMethod`),A=v.useState(`activeTriggerElement`),j=v.useState(`transitionStatus`),M=v.useState(`positionerElement`),N=v.useState(`instantType`),P=v.useState(`adaptiveOrigin`),F=v.useState(`lastOpenChangeReason`),I=v.useState(`floatingNodeId`),ee=v.useState(`floatingParentNodeId`),L=w.useState(`domReferenceElement`),R=n,z=c,B=l,V=s,te=h;C.type===`context-menu`&&(R=n??C.context?.anchor,V??=`start`,!o&&V!==`center`&&(B=e.alignOffset??2,z=e.sideOffset??-5));let H=o,U=V;C.type===`menu`?(H??=`inline-end`,U??=`start`,te=e.collisionAvoidance??Je):C.type===`menubar`&&(H??=C.context.orientation===`vertical`?`inline-end`:`bottom`,U??=`start`);let W=C.type===`context-menu`,ne=Jt({anchor:R,floatingRootContext:w,positionMethod:S?`fixed`:r,mounted:E,side:H,sideOffset:z,align:U,alignOffset:B,arrowPadding:W?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:I,keepMounted:x,disableAnchorTracking:m,collisionAvoidance:te,shift:W?{crossAxis:!(`side`in te&&te.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:T,adaptiveOrigin:P,lazyFlip:y?`placement`:!1});X.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===I&&v.set(`hoverEnabled`,!1),e.nodeId!==I&&e.parentNodeId===v.select(`floatingParentNodeId`)&&v.setOpen(!1,J(Ve)))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[v,T.events,I]),X.useEffect(()=>{if(v.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==v.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;v.setOpen(!1,J(t))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[T.events,v]);let G=Be();X.useEffect(()=>{D||G.clear()},[D,G]),X.useEffect(()=>{function e(e){if(D&&e.nodeId===v.select(`floatingParentNodeId`)){if(e.target&&A&&A!==e.target){let e=v.select(`closeDelay`);e>0?G.isStarted()||G.start(e,()=>{v.setOpen(!1,J(Ve))}):v.setOpen(!1,J(Ve))}else G.clear()}}return T.events.on(`itemhover`,e),()=>{T.events.off(`itemhover`,e)}},[T.events,D,A,v,G]),X.useEffect(()=>{let e={open:D,nodeId:I,parentNodeId:ee,reason:v.select(`lastOpenChangeReason`)};T.events.emit(`menuopenchange`,e)},[T.events,D,v,I,ee]),di({store:v,domReference:L,positionerElement:M,open:D});let re={open:D,side:ne.side,align:ne.align,anchorHidden:ne.anchorHidden,nested:C.type===`menu`,instant:N},ie=C.type===`menubar`&&C.context.modal;Gt(D&&(ie||O&&F!==`trigger-hover`),k===`touch`,M,A);let K=en(e,re,{styles:ne.positionerStyles,transitionStatus:j,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!E,inert:!D}),q=E&&C.type!==`menu`&&(C.type!==`menubar`&&O&&F!==`trigger-hover`||C.type===`menubar`&&C.context.modal),ae=null;return C.type===`menubar`?ae=C.context.contentElement:C.type===void 0&&(ae=A),(0,Q.jsxs)(Ir.Provider,{value:ne,children:[q&&(0,Q.jsx)(vt,{ref:C.type===`context-menu`||C.type===`nested-context-menu`?C.context.internalBackdropRef:null,inert:yt(!D),cutout:ae}),(0,Q.jsx)(fn,{id:I,children:(0,Q.jsx)(ze,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,onMapChange:b,children:K})})]})}),pi=X.createContext(null);function mi(e){let t=X.useContext(pi);if(t===null&&!e)throw Error(re(5));return t}function hi(e){return e==null?Xe:e.type.startsWith(`key`)?Rt:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?Le:Xe}var gi={...lr,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,keyboardOpen:e=>e.keyboardOpen,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,listElement:e=>e.listElement,triggerControlsId:(e,t)=>{let n=lr.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>hn&&e.inputFocused&&t?!0:void 0,highlightedItemId:e=>e.highlightedItem?.id||void 0,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType===`trigger-change`&&!lr.open(e)?void 0:e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},_i=class extends _n{constructor(e,t,n=!1){let r=new Ot,i=yi(r,t,n,e);super(i,vi(r),gi),this.observe(`parent`,e=>{e.type===`menu`?this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef:e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef)})}subscribeToParentMenu(){let e=this.state.parent;if(e.type!==`menu`)return;let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);return e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}setActiveIndex(e,t,n){if(this.state.activeIndex!==e){let r=(e===null?void 0:this.context.itemDomElements.current[e])===this.context.reportedItem;this.context.highlightReason=r?`none`:t,this.context.highlightEvent=r?void 0:n}this.set(`activeIndex`,e)}highlightItem(e,t,n){let r=this.context.itemDomElements.current.indexOf(e);r>-1&&this.setActiveIndex(r,t,n)}};function vi(e){return{positionerRef:X.createRef(),popupRef:X.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},highlightReason:`none`,highlightEvent:void 0,reportedItem:void 0,allowMouseUpTriggerRef:{current:!1},virtualFocusRef:void 0,triggerFocusTargetRef:X.createRef(),beforeTriggerFocusGuardRef:X.createRef(),beforeContentFocusGuardRef:X.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function yi(e,t,n=!1,r){return{...rr(e,t,n),disabled:!1,modal:!0,openMethod:null,keyboardOpen:!1,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,listElement:null,filterTriggerProps:R,inputProps:R,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new zt,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:R,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var bi=X.createContext(null);function xi(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function Si(e,t){return e===`list-navigation`||xi(e,t)}var Ci=Ae(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,onItemHighlighted:a,defaultOpen:o=!1,disabled:s=!1,modal:c,loopFocus:l=!0,orientation:u=`vertical`,actionsRef:d,closeParentOnEsc:f=!1,handle:p,triggerId:m,defaultTriggerId:h=null,highlightItemOnHover:g=!0,isSubmenu:_=!1,virtualFocus:v=!1,virtualFocusRef:y,allowEscape:b=!0,resetOnPointerLeave:x=!0}=e,S=Vr(!0),C=zr(!0),w=mi(!0),T=C?.store,E=C?.virtualFocus??!1,D=X.useMemo(()=>_&&T?{type:`menu`,store:T}:w?{type:`menubar`,context:w}:S&&!T?{type:`context-menu`,context:S}:{type:void 0},[S,T,w,_]),O=st(),k=st(),[A,j]=X.useState(void 0),M=(A??k)||void 0,N=Ne(),P=D.type===`menu`?D.store:void 0,F=(n??o)&&P?.state.transitionStatus===`starting`,I=ee(()=>F?P?.state.instantType:void 0).current,z=ee(()=>{let e=new _i({open:o,openProp:n,activeTriggerId:h,triggerIdProp:m,parent:D,disabled:s,highlightItemOnHover:g,modal:D.type===void 0?c:void 0,rootId:O,instantType:I},M,N!=null);return e.context.virtualFocusRef=y,e}).current;z.useControlledProp(`openProp`,n),z.useControlledProp(`triggerIdProp`,m),z.useContextCallback(`onOpenChangeComplete`,i);let V=z.useState(`floatingTreeRoot`),te=Pe(V),H=z.useState(`open`),U=z.useState(`activeTriggerElement`),ne=z.useState(`positionerElement`),G=z.useState(`hoverEnabled`),re=z.useState(`disabled`),ie=z.useState(`lastOpenChangeReason`),q=z.useState(`parent`),ae=z.useState(`activeIndex`),oe=z.useState(`keyboardOpen`),se=z.useState(`payload`),ce=z.useState(`floatingParentNodeId`),le=X.useRef(null),ue=X.useRef(q.type!==`context-menu`),de=Be(),fe=X.useRef(!0),pe=Be(),me=ce!=null,{openMethod:he,triggerProps:ge}=St(H);z.useSyncedValues({disabled:s,highlightItemOnHover:g,modal:q.type===void 0?c:void 0,openMethod:he,rootId:O}),gt(z);let{forceUnmount:_e,transitionStatus:ve}=un(H,z,()=>{z.set(`allowMouseEnter`,!1)},F),ye=tn(z.context.popupRef);X.useEffect(()=>{if(I===void 0)return;let e=()=>{z.state.instantType===I&&z.set(`instantType`,void 0)};if(!H){e();return}if(ve!==void 0)return;if(z.context.popupRef.current==null){e();return}let t=new AbortController;return ye(e,t.signal),()=>{t.abort()}},[I,H,ve,ye,z]),K(()=>{S&&!C?z.update({parent:{type:`context-menu`,context:S},floatingNodeId:te,floatingParentNodeId:N}):(C||!z.select(`activeTriggerElement`))&&z.update({floatingNodeId:te,floatingParentNodeId:N})},[S,C,te,N,U,z]),X.useEffect(()=>{H||(le.current=null),q.type===`context-menu`&&(H?de.start(500,()=>{ue.current=!0}):(de.clear(),ue.current=!1))},[de,H,q.type]),K(()=>{!H&&!G&&z.set(`hoverEnabled`,!0)},[H,G,z]);let be=W((e,t)=>{let n=t.reason;if(!e&&!z.select(`open`)||H===e&&t.trigger===U&&ie===n)return;let i=Mt(t);if(!e&&t.trigger==null&&(t.trigger=U??void 0),r?.(e,t),t.isCanceled)return;z.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!fe.current)return;e&&n===`trigger-focus`?(fe.current=!1,pe.start(300,()=>{fe.current=!0})):(fe.current=!0,pe.clear());let o=!e&&(n===`escape-key`||n==null);le.current=t.event;let s=At(z.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&Si(n,a),s.instantType=q.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:xi(n,a)?`click`:o?`dismiss`:void 0,z.update(s)}),xe=nr({popupStore:z,floatingRootContext:z.state.floatingRootContext,floatingId:M,nested:N!=null,onOpenChange:be}),Se=xe.context.events;K(()=>{let e=({open:e,eventDetails:t})=>be(e,t);return Se.on(`setOpen`,e),()=>{Se?.off(`setOpen`,e)}},[Se,be]),K(()=>z.subscribeToParentMenu(),[z]);let Ce=X.useCallback(()=>{z.setOpen(!1,J(Bt))},[z]);X.useImperativeHandle(d,()=>({unmount:_e,close:Ce}),[_e,Ce]);let we;q.type===`context-menu`&&(we=q.context),X.useImperativeHandle(we?.positionerRef,()=>ne,[ne]),X.useImperativeHandle(we?.actionsRef,()=>({setOpen:be}),[be]);let Te=mn(xe,{enabled:!re,bubbles:{escapeKey:f&&q.type===`menu`},outsidePress(){return q.type!==`context-menu`||le.current?.type===`contextmenu`||ue.current},externalTree:me?V:void 0}),Ee=Dt(),De=cn(xe,{enabled:!re,listRef:z.context.itemDomElements,activeIndex:ae,virtual:v,nested:q.type===`menubar`||!v&&q.type!==void 0,parentOrientation:q.type===`menubar`?q.context.orientation:void 0,loopFocus:l,focusItemOnOpen:v?oe:void 0,allowEscape:v&&l&&b,orientation:u,triggerOrientation:v?`vertical`:u,rtl:Ee===`rtl`,disabledIndices:L,onNavigate(e,t){z.setActiveIndex(e,hi(t),t?.nativeEvent)},openOnArrowKeyDown:q.type!==`context-menu`&&!(v&&_),externalTree:!v&&me?V:void 0,nestedReturnFocusRef:P?.context.virtualFocusRef,focusItemOnHover:g,resetOnPointerLeave:x}),Oe=X.useCallback(e=>{z.context.typingRef.current=e},[z]),ke=Vt(xe,{enabled:!re&&!v,listRef:z.context.itemLabels,elementsRef:z.context.itemDomElements,activeIndex:ae,resetMs:500,onMatch:(e,t)=>{H&&e!==ae&&z.setActiveIndex(e,Rt,t.nativeEvent)},onTyping:Oe}),Ae=W(a),je=X.useRef(-1),Me=W(()=>{let e=z.state.activeIndex,t=e===null?void 0:z.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(je.current===n&&z.context.reportedItem===t)return;je.current=n,z.context.reportedItem=t,v&&z.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=z.context;z.context.highlightReason=Xe,z.context.highlightEvent=void 0,a&&Ae(t,ut(r,i,{label:t===void 0?void 0:z.context.itemLabels.current[n]??void 0}))});K(()=>{Me()},[ae,Me]);let Fe=X.useMemo(()=>{if(!v)return De.reference;if(!De.trigger)return R;let{onFocus:e,...t}=De.trigger;return t},[v,De.reference,De.trigger]);z.useSyncedValue(`inputProps`,v?De.reference??R:R);let Ie=X.useMemo(()=>{let e=B(ke.reference,Fe,Te.reference,{onMouseMove(){z.set(`allowMouseEnter`,!0)}},ge);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=H,e},[z,ke.reference,Fe,Te.reference,ge,H]),Le=X.useMemo(()=>{let e=B(De.trigger,Te.trigger,ge);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[De.trigger,Te.trigger,ge]);ee(()=>(z.update({inactiveTriggerProps:Le}),null));let Re=X.useMemo(()=>B(Xt,{onMouseMove(){z.set(`allowMouseEnter`,!0),q.type===`menu`&&z.set(`hoverEnabled`,!1)},onClick(){z.select(`hoverEnabled`)&&z.set(`hoverEnabled`,!1)},onKeyDown(e){let t=z.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},ke.floating,De.floating,Te.floating),[q.type,z,ke.floating,De.floating,Te.floating]),ze=De.item??R;gn(z,{floatingRootContext:xe,activeTriggerProps:Ie,inactiveTriggerProps:Le,popupProps:Re,itemProps:ze});let Ve=X.useMemo(()=>({store:z,parent:D,orientation:u,loopFocus:l,allowEscape:b,defaultFloatingId:k,setRenderedFloatingId:j,virtualFocus:v,parentVirtualFocus:E,syncHighlightedItem:Me}),[z,D,u,l,b,k,v,E,Me]),He=typeof t==`function`?t({payload:se}):t,Ue=(0,Q.jsxs)(Rr.Provider,{value:Ve,children:[p&&(0,Q.jsx)(Ut,{handle:p,store:z}),He]});return(q.type===void 0||q.type===`context-menu`)&&(Ue=(0,Q.jsx)(ot,{externalTree:V,children:Ue})),Ue});function wi(e){let t=X.useContext(bi);if(t===null)return(0,Q.jsx)(Ci,{...e});let n=t.Root;return(0,Q.jsx)(bi.Provider,{value:null,children:(0,Q.jsx)(n,{...t.options,...e})})}function Ti(e){let{render:t,className:n,style:r,state:i=R,props:a=L,refs:o=L,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=Me({metadata:s});return ne(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function Ei(e){if(oe(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!V(e))return Ei(te(e))}function Di(e,t){function n(n,r,i){let a=n.currentTarget;br.flushSync(()=>{e.setOpen(!1,J(Qe,n.nativeEvent,a))}),an(a.isConnected?a:t.current,r,i)?.focus()}function r(t){n(t,-1,e.select(`positionerElement`))}function i(t){let r=e.select(`positionerElement`);r&&wt(t,r)?e.context.beforeContentFocusGuardRef.current?.focus():n(t,1,r)}return{handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function Oi(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,i=X.useRef(!1);return X.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(i.current=!0,ct(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:R,[t,n,r])}var ki=lt(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,id:s,openOnHover:c,delay:l=100,closeDelay:u=0,handle:d,payload:f,...p}=e,m=zr(!0),h=dr(d)??m?.store;if(!h)throw Error(re(85));let g=st(s),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerControlsId`,g),x=X.useRef(null),S=ji(),C=H(!0),w=Ze(),T=X.useMemo(()=>w??new zt,[w]),E=Pe(T),D=Ne(),{registerTrigger:O,isMountedByThisTrigger:k}=bt(g,x,h,{payload:f,closeDelay:u,parent:S,floatingTreeRoot:T,floatingNodeId:E,floatingParentNodeId:D,keyboardEventRelay:C?.relayKeyboardEvent}),A=S.type===`menubar`,j=h.useState(`disabled`),M=a||j||A&&S.context.disabled,{getButtonProps:N,buttonRef:P}=G({disabled:M,native:o});X.useEffect(()=>{!y&&S.type===void 0&&(h.context.allowMouseUpTriggerRef.current=!1)},[h,y,S.type]);let F=X.useRef(null),I=Be(),ee=W(e=>{if(!F.current)return;I.clear(),h.context.allowMouseUpTriggerRef.current=!1;let t=e.target;Y(F.current,t)||Y(h.select(`positionerElement`),t)||t===F.current||t!=null&&Ei(t)===h.select(`rootId`)||nn(e,F.current)||T.events.emit(`close`,{domEvent:e,reason:Fe})});X.useEffect(()=>{let e=ct(F.current);if(y&&h.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,ee,{once:!0}),()=>{e.removeEventListener(`mouseup`,ee)}},[y,ee,h]);let L=A&&S.context.hasSubmenuOpen,z=Sr(v,{enabled:(c??L)&&!M&&(!A||L&&!k),handleClose:kr({blockPointerEvents:!A}),mouseOnly:!0,move:!1,restMs:S.type===void 0?l:void 0,delay:{close:u},triggerElementRef:x,externalTree:T,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`}),V=Ai(y,h.select(`lastOpenChangeReason`)),te=it(v,{enabled:!M,event:y&&A?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:S.type===void 0&&V}),U=pr(v,{enabled:!M&&L}),ie=Oi({open:y,enabled:A,mouseDownAction:`open`}),K=X.useMemo(()=>B(U.reference,te.reference),[U.reference,te.reference]),q=h.useState(`triggerProps`,k),ae=h.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:oe,handleFocusTargetFocus:se}=Di(h,x),ce={disabled:M,open:y},le=[F,t,P,O,x],ue=[K,z??R,q,{"aria-haspopup":`menu`,"aria-controls":b,id:g,onMouseDown:e=>{h.select(`open`)||(I.start(200,()=>{h.context.allowMouseUpTriggerRef.current=!0}),ct(e.currentTarget).addEventListener(`mouseup`,ee,{once:!0}))}},ae,A?{role:`menuitem`}:{},ie,p,N],de=ne(`button`,e,{enabled:!A,stateAttributesMapping:jt,state:ce,ref:le,props:ue});return A?(0,Q.jsx)(Ti,{tag:`button`,render:n,className:r,style:i,state:ce,refs:le,props:ue,stateAttributesMapping:jt}):y?(0,Q.jsxs)(X.Fragment,{children:[(0,Q.jsx)($e,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:oe},`${g}-pre-focus-guard`),(0,Q.jsx)(X.Fragment,{children:de},g),(0,Q.jsx)($e,{ref:h.context.triggerFocusTargetRef,onFocus:se},`${g}-post-focus-guard`)]}):(0,Q.jsx)(X.Fragment,{children:de},g)});function Ai(e,t){let n=Be(),[r,i]=X.useState(!1);return K(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function ji(){let e=mi(!0);return X.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var Mi=X.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return ne(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})}),Ni=wi;function Pi(e){return(0,Q.jsx)(ki,{"data-slot":`dropdown-menu-trigger`,...e})}function Fi({className:e,align:t=`end`,sideOffset:n=4,...r}){return(0,Q.jsx)(ui,{children:(0,Q.jsx)(fi,{align:t,sideOffset:n,className:`isolate z-50`,children:(0,Q.jsx)(si,{"data-slot":`dropdown-menu-content`,className:y(`min-w-44 origin-(--transform-origin) overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-none data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...r})})})}function Ii({className:e,...t}){return(0,Q.jsx)(Qr,{"data-slot":`dropdown-menu-item`,className:y(`relative flex w-full cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...t})}function Li({className:e,...t}){return(0,Q.jsx)(Mi,{"data-slot":`dropdown-menu-separator`,className:y(`-mx-1 my-1 h-px bg-border`,e),...t})}var $=(e,t)=>{let n=e[t];if(typeof n!=`string`)return;let r=e.Alias;return typeof r==`string`?n.replace(RegExp(`\\b${r.replace(/\W/g,`\\$&`)}\\.`,`g`),``):n},Ri=(e,t)=>{let n=e[t];return Array.isArray(n)?n.map(String).join(`, `):void 0},zi=e=>`${Math.round(e).toLocaleString()} ${e===1?`row`:`rows`}`,Bi=e=>{let t=$(e,`Relation Name`);if(!t)return;let n=$(e,`Schema`);return n?`${n}.${t}`:t},Vi=e=>{let t=$(e,`Relation Name`);if(!t)return`a table`;let n=$(e,`Schema`);return`the ${n&&n!==`public`?`${n}.`:``}${t} table`},Hi=(e,t)=>t?` ${e} ${t.replace(/^\((.*)\)$/,`$1`)}.`:``,Ui={Inner:`only the pairs that match`,Left:`every row from the first side, with matches from the second where there are any`,Right:`every row from the second side, with matches from the first where there are any`,Full:`every row from both sides, matched where possible`,Semi:`the rows of the first side that have a match`,Anti:`the rows of the first side that have no match`};function Wi(e){let{title:t,...n}=Gi(e),r=Bi(e);return{title:t,phrase:r&&/Scan$/.test(e[`Node Type`])&&e[`Node Type`]!==`Bitmap Index Scan`?`${t.toLowerCase()} ${e[`Node Type`]===`Seq Scan`?`of`:`in`} ${r}`:t.toLowerCase(),...n}}function Gi(e){let t=e[`Node Type`],n=`Postgres expects about ${zi(e[`Plan Rows`])}.`,r=Hi(`Keeps only rows where`,$(e,`Filter`)),i=$(e,`Index Name`);switch(t){case`Seq Scan`:return{title:`Read every row`,detail:`Reads ${Vi(e)} from start to finish, one row after another.${r} ${n}`,hint:e[`Plan Rows`]>1e4?`Reading a big table in full is slow. An index on the filtered column can help.`:void 0};case`Index Scan`:case`Index Only Scan`:return{title:`Look rows up by index`,detail:`Jumps straight to the matching rows of ${Vi(e)} using the ${i} index${t===`Index Only Scan`?`, without touching the table itself`:``}.${Hi(`Matches rows where`,$(e,`Index Cond`))}${r} ${n}`};case`Bitmap Index Scan`:return{title:`Find matches in an index`,detail:`Collects the places of matching rows from the ${i} index.${Hi(`Matches rows where`,$(e,`Index Cond`))}`};case`Bitmap Heap Scan`:return{title:`Fetch the matching rows`,detail:`Reads ${Vi(e)} at the places the index found, in disk order.${Hi(`Re-checks that`,$(e,`Recheck Cond`))}${r} ${n}`};case`Nested Loop`:return{title:`Match rows one by one`,detail:`For each row of the first input, looks for matching rows in the second. Gives ${Ui[$(e,`Join Type`)??`Inner`]??`the matches`}.${Hi(`Join on`,$(e,`Join Filter`))} ${n}`,hint:`Fast when the first input is small. Slow when both inputs are large.`};case`Hash Join`:return{title:`Match rows with a lookup table`,detail:`Builds an in-memory lookup of one input, then checks each row of the other against it. Gives ${Ui[$(e,`Join Type`)??`Inner`]??`the matches`}.${Hi(`Join on`,$(e,`Hash Cond`))} ${n}`};case`Merge Join`:return{title:`Match two sorted lists`,detail:`Walks down both inputs in order and pairs up rows that match. Gives ${Ui[$(e,`Join Type`)??`Inner`]??`the matches`}.${Hi(`Join on`,$(e,`Merge Cond`))} ${n}`};case`Hash`:return{title:`Build a lookup table`,detail:`Holds the rows below in memory so the join can find them quickly.`};case`Sort`:return{title:`Sort the rows`,detail:`Puts the rows in order by ${Ri(e,`Sort Key`)??`the requested columns`}. ${n}`,hint:`Sorting a lot of rows takes memory and time. An index in the same order can avoid it.`};case`Incremental Sort`:return{title:`Finish sorting the rows`,detail:`The rows already come sorted by part of ${Ri(e,`Sort Key`)??`the order`}, so only the rest needs sorting.`};case`Aggregate`:case`HashAggregate`:case`GroupAggregate`:{let t=Ri(e,`Group Key`);return{title:t?`Group and summarise`:`Summarise all rows`,detail:t?`Groups the rows by ${t} and works out the totals, counts or averages for each group. ${n}`:`Combines all rows into a single result, such as a count or a total. ${n}`}}case`Limit`:return{title:`Stop early`,detail:`Takes only the first ${zi(e[`Plan Rows`])} and ignores the rest.`};case`Unique`:return{title:`Remove duplicates`,detail:`Drops rows that repeat the one before them.`};case`Materialize`:return{title:`Remember the rows`,detail:`Keeps the rows in memory so they can be read again without redoing the work.`};case`Gather`:case`Gather Merge`:return{title:`Combine parallel workers`,detail:`Several workers each handled part of the data. This step collects their results.`};case`Append`:case`Merge Append`:return{title:`Stack results together`,detail:`Joins the results of the steps below into one list, as UNION or partitions do.`};case`Result`:return{title:`Compute a value`,detail:`Works out a result without reading any table.`};case`Subquery Scan`:return{title:`Read a subquery`,detail:`Reads the output of a subquery as if it were a table.`};case`CTE Scan`:return{title:`Read a WITH query`,detail:`Reads the result of the WITH query ${$(e,`CTE Name`)??``}.`};case`Function Scan`:return{title:`Call a function`,detail:`Reads the rows the function ${$(e,`Function Name`)??``} returns.`};case`Values Scan`:return{title:`Read listed values`,detail:`Reads the values written out in the query.`};case`ModifyTable`:{let t=$(e,`Operation`)??`Change`;return{title:`${t} rows`,detail:`${t===`Insert`?`Adds rows to`:t===`Update`?`Changes rows in`:t===`Delete`?`Removes rows from`:`Changes`} ${Vi(e)}. Nothing was changed: explaining only plans the work.`}}default:return{title:String(t),detail:`A ${String(t)} step. ${n}`}}}function Ki(e){let t=(e.Plans??[]).map(Ki),n=t.reduce((e,t)=>e+t.node[`Total Cost`],0);return{node:e,...Wi(e),ownCost:Math.max(e[`Total Cost`]-n,0),children:t}}function qi(e){return e.children.reduce((e,t)=>{let n=qi(t);return n.ownCost>e.ownCost?n:e},e)}function Ji(e){let t=[],n=e=>{e.children.forEach(n),e.title!==`Build a lookup table`&&t.push(e.phrase)};return n(e),`Postgres will ${t.join(`, then `)}, and expects ${zi(e.node[`Plan Rows`])} back.`}var Yi=1e4,Xi=`"[^"]+"|[a-z_][a-z0-9_$]*`,Zi=`(?:::[a-z ]+?)?`,Qi=/\b(?:lower|upper|coalesce|date|date_trunc|to_char|btrim|trim|substr|substring|left|right|abs|round)\(|::date\b/i,$i=e=>/^[a-z_][a-z0-9_$]*$/.test(e)?e:`"${e.replaceAll(`"`,`""`)}"`,ea=e=>{let t=$(e,`Relation Name`);if(!t)return;let n=$(e,`Schema`);return{name:t,sql:n?`${$i(n)}.${$i(t)}`:$i(t)}},ta=(e,t,n,r=``)=>{let i=ea(e);if(i)return`CREATE INDEX ${`${i.name}_${t.join(`_`)}_idx`.replace(/\W+/g,`_`).slice(0,63)} ON ${i.sql}${r} (${n});`};function na(e){let t=[],n=RegExp(`[\\s(](${Xi})\\)?${Zi}\\s*(=|<>|<=|>=|<|>)\\s`,`gi`);for(let r of e.matchAll(n))t.some(e=>e.column===r[1])||t.push({column:r[1],equal:r[2]===`=`});return[...t.filter(e=>e.equal),...t.filter(e=>!e.equal)].map(e=>e.column).slice(0,3)}var ra=e=>[e,...e.children.flatMap(ra)],ia=e=>/Scan$/.test(e.node[`Node Type`]);function aa(e){let t=e.children.findLast(e=>e.node[`Node Type`]===`Seq Scan`),n=t?.node.Alias,r=$(e.node,`Join Filter`);if(!t||typeof n!=`string`||!r)return;let i=RegExp(`\\b${n.replace(/\W/g,`\\$&`)}\\.(${Xi})`,`i`).exec(r);return i?ta(t.node,[i[1]],i[1]):void 0}function oa(e){let t=ra(e).filter(e=>ia(e)&&e.node[`Relation Name`]),n=e.node[`Sort Key`];if(t.length!==1||!Array.isArray(n))return;let r=t[0].node.Alias,i=n.map(e=>String(e).replace(RegExp(`^${String(r).replace(/\W/g,`\\$&`)}\\.`),``)),a=RegExp(`^(${Xi})( (?:ASC|DESC))?( NULLS (?:FIRST|LAST))?$`,`i`);if(i.every(e=>a.test(e)))return ta(t[0].node,i.map(e=>e.split(` `)[0].replaceAll(`"`,``)),i.join(`, `))}function sa(e){let t=[],n=ra(e),r=e.node[`Total Cost`];for(let e of n){let{node:n}=e,i=n[`Node Type`],a=Bi(n),o=$(n,`Filter`),s=n[`Total Cost`]>1e3&&(n[`Plan Rows`]>Yi||e.ownCost>r*.3),c=o&&RegExp(`[\\s(](${Xi})\\)?${Zi}\\s*~~\\*?\\s*'%`,`i`).exec(o),l=o&&!Qi.test(o)?na(o):[];if(i===`Seq Scan`&&o&&e.ownCost>1e3&&(l.length>0||!Qi.test(o)&&!c)&&t.push({step:e,title:`Add an index on ${a}`,detail:`${a} is read in full to keep only the rows where ${o.replace(/^\((.*)\)$/,`$1`)}. An index on the column that condition tests would let Postgres go straight to those rows.`,sql:l.length>0?ta(n,l,l.join(`, `)):void 0}),i===`Seq Scan`&&!o&&n[`Plan Rows`]>Yi&&t.push({step:e,title:`Read less of ${a}`,detail:`All of ${a} (about ${zi(n[`Plan Rows`])}) is read. If you do not need every row, add a WHERE or a LIMIT.`}),i===`Nested Loop`&&e.children.some(e=>e.node[`Node Type`]===`Seq Scan`)&&e.children.every(e=>e.node[`Plan Rows`]>100)&&t.push({step:e,title:`Index the join column`,detail:`Rows are matched one by one while one side is read in full for each row of the other. An index on the join column of the inner table would avoid that.`,sql:aa(e)}),i===`Sort`&&s&&t.push({step:e,title:`Avoid the sort`,detail:`Sorting ${zi(n[`Plan Rows`])} by ${Ri(n,`Sort Key`)??`the order`} is a large share of the work. An index in that order, or a LIMIT, would avoid sorting them all.`,sql:oa(e)}),o&&Qi.test(o)&&ia(e)&&e.ownCost>1e3){let r=RegExp(`\\b(lower|upper)\\(\\(?(${Xi})\\)?${Zi}\\)`,`i`).exec(o);t.push({step:e,title:`Match the index to the expression`,detail:`The condition ${o.replace(/^\((.*)\)$/,`$1`)} wraps the column in a function or cast, which stops a plain index being used. Index the same expression, or compare the bare column.`,sql:r?ta(n,[r[1].toLowerCase(),r[2]],`${r[1].toLowerCase()}(${r[2]})`):void 0})}if(c&&ia(e)&&e.ownCost>1e3){let r=ta(n,[c[1],`trgm`],`${c[1]} gin_trgm_ops`,` USING gin`);t.push({step:e,title:`Avoid a leading wildcard`,detail:`A LIKE pattern that starts with % cannot use a normal index. A trigram index (pg_trgm) can, or the pattern can be anchored at the start.`,sql:r&&`CREATE EXTENSION IF NOT EXISTS pg_trgm;\n${r}`})}}return e.node[`Node Type`]!==`Limit`&&e.node[`Plan Rows`]>Yi&&!/^(Insert|Update|Delete)/.test($(e.node,`Operation`)??``)&&t.push({step:e,title:`Return fewer rows`,detail:`The query returns about ${zi(e.node[`Plan Rows`])}. If you only need some of them, add a WHERE or a LIMIT.`}),e.node[`Plan Width`]>200&&t.push({step:e,title:`Select only the columns you need`,detail:`Each row is about ${e.node[`Plan Width`]} bytes wide. Naming the columns you need instead of using * moves less data.`}),t}var ca=(e,t)=>{let n=e[t];return typeof n==`number`?n:void 0},la=e=>ca(e,`Actual Loops`)!==void 0,ua=e=>(ca(e,`Actual Total Time`)??0)*(ca(e,`Actual Loops`)??0);function da(e){let{node:t}=e,n=ca(t,`Actual Loops`);if(n===void 0)return;let r=ua(t),i=e.children.reduce((e,t)=>e+ua(t.node),0),a=t[`Plan Rows`]*Math.max(n,1),o=(ca(t,`Actual Rows`)??0)*n,s=Math.max(a,o,1)/Math.max(Math.min(a,o),1);return{totalMs:r,ownMs:Math.max(r-i,0),estimatedRows:a,actualRows:o,loops:n,misestimate:s,direction:o>=a?`more`:`fewer`,hitBlocks:ca(t,`Shared Hit Blocks`),readBlocks:ca(t,`Shared Read Blocks`)}}var fa=10,pa=100,ma=100;function ha(e,t){let{node:n}=e,r=[],i=n[`Node Type`],a=da(e),o=Bi(n);if(i===`Seq Scan`&&o){let e=(ca(n,`Rows Removed by Filter`)??0)*(a?.loops??1),i=t?.($(n,`Schema`),$(n,`Relation Name`)??``)??(a?a.actualRows+e:n[`Plan Rows`]);i>=Yi&&r.push({level:i>=Yi*100?`bad`:`warn`,label:`big seq scan`,detail:`Reads all of ${o} (about ${zi(i)}${a&&a.loops>1&&n[`Parallel Aware`]!==!0?`, ${a.loops} times`:``}). An index on the columns it filters or joins on would let Postgres read only the rows it needs.`})}if(a&&a.loops===0)r.push({level:`warn`,label:`never ran`,detail:`This step was never executed: the steps above it did not need its rows.`});else if(a&&a.misestimate>=fa&&Math.max(a.estimatedRows,a.actualRows)>=ma){let e=Math.round(a.misestimate).toLocaleString();r.push({level:a.misestimate>=pa?`bad`:`warn`,label:`${e}× ${a.direction}`,detail:`Postgres expected ${zi(a.estimatedRows)} but got ${zi(a.actualRows)}, ${e} times ${a.direction}. A plan built on a wrong guess picks the wrong joins and scans.${o?` If ${o} changed a lot lately, ANALYZE ${o} refreshes its statistics; if columns are correlated, CREATE STATISTICS can help.`:``}`})}if(a){let e=(ca(n,`Rows Removed by Filter`)??0)*a.loops;e>=Yi&&e>a.actualRows*10&&r.push({level:`warn`,label:`filtered out`,detail:`Read ${zi(e+a.actualRows)} to keep ${zi(a.actualRows)}: ${zi(e)} were thrown away by the filter. An index on the filtered column would skip them.`})}$(n,`Sort Space Type`)===`Disk`&&r.push({level:`bad`,label:`sort on disk`,detail:`The sort did not fit in work_mem and used ${ca(n,`Sort Space Used`)??`?`} kB on disk. Raising work_mem for this query, or sorting fewer rows, keeps it in memory.`});let s=ca(n,`Hash Batches`);return s!==void 0&&s>1&&r.push({level:`warn`,label:`hash on disk`,detail:`The lookup table did not fit in work_mem and was split into ${s} batches on disk. Raising work_mem keeps it in memory.`}),r}function ga(e){let t=$(e,`Join Type`),n=t&&t!==`Inner`?`${e[`Node Type`]} (${t})`:e[`Node Type`],r=Bi(e),i=$(e,`Alias`),a=$(e,`Index Name`),o=a?` using ${a}`:``;return r?{type:n,target:`${r}${i&&i!==$(e,`Relation Name`)?` ${i}`:``}${o}`}:a?{type:n,target:o.trim()}:{type:n,target:$(e,`CTE Name`)??$(e,`Function Name`)??$(e,`Subplan Name`)}}function _a(e){return[`Index Cond`,`Recheck Cond`,`Filter`,`Join Filter`,`Hash Cond`,`Merge Cond`,`Sort Key`,`Group Key`,`Output`].flatMap(t=>{let n=Array.isArray(e[t])?Ri(e,t):$(e,t);return n?[[t,n]]:[]})}var va=`psqlx1:`,ya=e=>{let t=``;for(let n of new TextEncoder().encode(e))t+=String.fromCharCode(n);return btoa(t).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replaceAll(`=`,``)},ba=e=>{let t=atob(e.replaceAll(`-`,`+`).replaceAll(`_`,`/`));return new TextDecoder().decode(Uint8Array.from(t,e=>e.charCodeAt(0)))};function xa({sql:e,name:t}){return va+ya(JSON.stringify(t?{q:e,n:t}:{q:e}))}function Sa(e){let t=e.trim();if(t.startsWith(va))try{let{q:e,n}=JSON.parse(ba(t.slice(7)));return typeof e!=`string`||!e.trim()?void 0:{sql:e,...typeof n==`string`&&n.trim()?{name:n.trim().slice(0,40)}:{}}}catch{return}}var Ca=20,wa=200,Ta=(e,t)=>`psql-explorer:sql:${e}${t===`1`?``:`:${t}`}`;function Ea(e,t){try{window.localStorage.removeItem(Ta(e,t))}catch{}}function Da(e,t){try{return window.localStorage.getItem(Ta(e,t))??``}catch{return``}}function Oa(e,t,n){try{window.localStorage.setItem(Ta(e,t),n)}catch{}}function ka({zone:e,onChange:t}){let n=(0,X.useMemo)(()=>i(),[]),a=r();return(0,Q.jsxs)(`label`,{className:`text-muted-foreground flex items-center gap-1 text-xs`,title:`Days, months, ... of a timestamp with time zone are cut in this zone. A timestamp without time zone is used as it is.`,children:[(0,Q.jsx)(Mn,{className:`size-3.5`}),` Time zone`,(0,Q.jsxs)(`select`,{className:`border-input bg-card text-foreground max-w-44 border px-1 py-1`,value:e,onChange:e=>t(e.target.value),children:[(0,Q.jsx)(`option`,{value:``,children:`Database session`}),a&&(0,Q.jsxs)(`option`,{value:a,children:[`Browser (`,a,`)`]}),n.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))]})]})}function Aa({table:e,highlight:t}){let n=e.columns.slice(0,Ca);for(let e of t??[])n.includes(e)||n.push(e);return(0,Q.jsxs)(`div`,{className:`w-80`,children:[(0,Q.jsxs)(`div`,{className:`bg-sidebar flex items-center gap-2 px-3 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-accent-text font-bold`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:e.schema}),e.kind!==`table`&&(0,Q.jsx)(Ge,{variant:`outline`,children:e.kind})]}),e.comment&&(0,Q.jsx)(`p`,{className:`text-muted-foreground border-border border-b px-3 py-1 text-xs`,children:e.comment}),(0,Q.jsxs)(`ul`,{className:`py-1 text-xs`,children:[n.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-2 px-3 py-0.5 ${t?.includes(e)?`bg-accent text-accent-foreground`:``}`,children:[(0,Q.jsx)(`span`,{className:`w-3.5 shrink-0`,children:e.primaryKey?(0,Q.jsx)(ge,{className:`size-3.5`}):e.references?(0,Q.jsx)(Kt,{className:`size-3.5`}):null}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.name}),e.default!==null&&(0,Q.jsxs)(`span`,{className:`text-muted-foreground/80 truncate font-mono`,title:`Default: ${e.default}`,children:[`= `,e.default]}),(0,Q.jsx)(`span`,{className:`text-muted-foreground ml-auto shrink-0 pl-2`,children:e.references?`→ ${e.references.table}`:`${e.type}${e.nullable?``:` !`}`})]},e.name)),e.columns.length>n.length&&(0,Q.jsxs)(`li`,{className:`text-muted-foreground px-3 py-0.5`,children:[`+`,e.columns.length-n.length,` more`]})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground border-border border-t px-3 py-1 text-xs`,children:`! not null · key = primary key · link = foreign key · = default`})]})}function ja({table:e,column:t}){let n=[[`Type`,t.type],[`Nullable`,t.nullable?`yes`:`no (NOT NULL)`]];t.default!==null&&n.push([`Default`,t.default]);let r=[t.primaryKey&&`primary key`,t.unique&&`unique`].filter(Boolean);if(r.length>0&&n.push([`Key`,r.join(`, `)]),t.references){let{schema:e,table:r,column:i}=t.references;n.push([`References`,`${e}.${r}(${i})`])}return(0,Q.jsxs)(`div`,{className:`w-80 px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-baseline gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-accent-text font-bold`,children:t.name}),(0,Q.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[e.schema,`.`,e.name]})]}),(0,Q.jsx)(`dl`,{className:`grid grid-cols-[max-content_1fr] gap-x-3 gap-y-0.5 text-xs`,children:n.map(([e,t])=>(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,Q.jsx)(`dd`,{className:`break-all`,children:t})]},e))}),t.comment&&(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-2 text-xs`,children:t.comment})]})}function Ma({help:e}){return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[e.functions.slice(0,4).map(t=>{let n=O(t.signature);return(0,Q.jsxs)(`div`,{className:`whitespace-nowrap`,children:[(0,Q.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[t.name,`(`]}),n.map((t,n)=>(0,Q.jsxs)(`span`,{children:[n>0&&(0,Q.jsx)(`span`,{className:`text-muted-foreground/70`,children:`, `}),(0,Q.jsx)(`span`,{className:n===e.index?`text-foreground font-bold`:`text-muted-foreground/70`,children:t})]},n)),(0,Q.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[`)`,t.returns?` → ${t.returns}`:``]})]},`${t.schema}.${t.args}`)}),e.functions.length>4&&(0,Q.jsxs)(`div`,{className:`text-muted-foreground/70`,children:[`+`,e.functions.length-4,` more variants`]})]})}function Na({functions:e}){return(0,Q.jsx)(`div`,{className:`w-96 max-w-full px-3 py-2`,children:e.map(e=>(0,Q.jsxs)(`div`,{className:`mb-2 last:mb-0`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-baseline gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-accent-text font-bold`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:e.schema}),e.kind!==`function`&&(0,Q.jsx)(Ge,{variant:`outline`,children:e.kind})]}),(0,Q.jsxs)(`dl`,{className:`grid grid-cols-[max-content_1fr] gap-x-3 gap-y-0.5 text-xs`,children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Parameters`}),(0,Q.jsx)(`dd`,{className:`break-words`,children:e.signature||`none`}),e.returns&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Returns`}),(0,Q.jsx)(`dd`,{className:`break-words`,children:e.returns})]}),(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Language`}),(0,Q.jsx)(`dd`,{children:e.language})]}),e.comment&&(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:e.comment})]},`${e.schema}.${e.name}(${e.args})`))})}function Pa({hover:e}){let t=(0,X.useRef)(null),[n,r]=(0,X.useState)({left:e.x,top:e.y+16});(0,X.useEffect)(()=>{let n=t.current?.getBoundingClientRect();if(!n)return;let i=Math.max(8,Math.min(e.x,window.innerWidth-n.width-8)),a=e.y+16,o=a+n.height>window.innerHeight-8?Math.max(8,e.y-n.height-8):a;r({left:i,top:o})},[e]);let{annotation:i}=e;return(0,Q.jsx)(`div`,{ref:t,role:`tooltip`,style:n,className:`bg-popover text-popover-foreground border-border pointer-events-none fixed z-50 max-h-[70vh] overflow-hidden border shadow-lg`,children:`functions`in i?(0,Q.jsx)(Na,{functions:i.functions}):i.columns?.length===1?(0,Q.jsx)(ja,{table:i.table,column:i.columns[0]}):(0,Q.jsx)(Aa,{table:i.table,highlight:i.columns})})}function Fa(e,t){if(!e)return;let n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=t;for(let e=n.nextNode();e;e=n.nextNode()){let t=e.textContent?.length??0;if(r<=t){let t=document.createRange();t.setStart(e,r),t.setEnd(e,r);let n=t.getClientRects()[0]??t.getBoundingClientRect();return n.height>0?n:void 0}r-=t}}var Ia=`font-mono text-sm leading-6`,La=`p-3`;function Ra({value:e,onChange:t,onRun:n,onFormat:r,onCursor:i,catalog:a,functions:s,zone:c}){let l=(0,X.useRef)(null),[d,f]=(0,X.useState)(),p=(0,X.useRef)(null),[h,v]=(0,X.useState)(0),[y,x]=(0,X.useState)(),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[E,O]=(0,X.useState)(0),A=(0,X.useRef)(void 0),j=(0,X.useRef)(void 0),M=(0,X.useMemo)(()=>[...b(e,a),...D(e,s)].sort((e,t)=>e.start-t.start),[e,a,s]),N=(0,X.useMemo)(()=>{let t=[],n=0,r=k(e);for(let e of r){let r=M.find(t=>t.start===e.start),i=r?M.indexOf(r):-1,a=He(e);i>=0&&(a+=` text-accent-text underline decoration-dotted underline-offset-4`),t.push((0,Q.jsx)(`span`,{"data-known":i>=0?i:void 0,className:a,children:e.text},n++))}return t.push(`
2
+ `),t},[e,M]),P=(0,X.useMemo)(()=>S?m(e,h,a,w,c,s):void 0,[S,e,h,a,w,c,s]),F=n=>{if(!P)return;let r=e.slice(0,P.from)+n.insert+e.slice(P.to),i=P.from+n.insert.length;t(r),C(!1),T(!1),v(i),requestAnimationFrame(()=>p.current?.setSelectionRange(i,i))},[I,ee]=(0,X.useState)(),[L,R]=(0,X.useState)(1);(0,X.useLayoutEffect)(()=>{let e=p.current;if(!e)return;let t=()=>e.clientWidth>0&&ee(e.clientWidth);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]),(0,X.useLayoutEffect)(()=>{l.current&&R(Math.round((l.current.offsetHeight-24)/24))},[e,I]),(0,X.useLayoutEffect)(()=>{p.current&&p.current.clientWidth>0&&ee(p.current.clientWidth)},[L]);let[z,B]=(0,X.useState)();(0,X.useLayoutEffect)(()=>{let e=p.current;if(!P||!e)return B(void 0);let t=Fa(l.current,P.from),n=e.getBoundingClientRect(),r=t?t.left:n.left+12,i=t?t.bottom:n.top+12+24;B({left:Math.max(8,Math.min(r,window.innerWidth-360)),top:i})},[P,e,I]);let V=(0,X.useMemo)(()=>y===void 0?void 0:u(e,y,s),[y,e,s]),[te,H]=(0,X.useState)();(0,X.useLayoutEffect)(()=>{let e=V&&y!==void 0?Fa(l.current,y):void 0;H(e?{left:Math.max(8,Math.min(e.left,window.innerWidth-400)),top:e.top-6}:void 0)},[V,y,e,I]);let U=`calc(${Math.min(Math.max(L,8),24)} * 1.5rem + 1.5rem)`,W=()=>{window.clearTimeout(A.current),j.current=void 0,f(void 0)};return(0,X.useEffect)(()=>()=>window.clearTimeout(A.current),[]),(0,Q.jsxs)(`div`,{className:`border-input bg-card focus-within:border-ring relative overflow-hidden border`,style:{height:U},children:[(0,Q.jsx)(`pre`,{ref:l,"aria-hidden":!0,className:`${Ia} ${La} pointer-events-none absolute top-0 left-0 m-0 whitespace-pre-wrap`,style:{width:I??`100%`,overflowWrap:`break-word`},children:N}),(0,Q.jsx)(`textarea`,{"aria-label":`SQL`,spellCheck:!1,value:e,placeholder:`SELECT * FROM ...`,ref:p,onChange:n=>{W();let r=n.target.value,o=n.target.selectionStart,s=r.length===e.length+1&&o===n.target.selectionEnd?_(r,o,a):void 0;s&&(r=s.sql,o=s.caret,requestAnimationFrame(()=>p.current?.setSelectionRange(o,o))),t(r),i(n.target.selectionStart,n.target.selectionEnd),O(0),v(o),T(!1),C(n.target.selectionStart===n.target.selectionEnd)},onSelect:e=>{i(e.currentTarget.selectionStart,e.currentTarget.selectionEnd);let{selectionStart:t,selectionEnd:n}=e.currentTarget;x(t===n?t:void 0)},onBlur:()=>(C(!1),T(!1),x(void 0)),onMouseDown:()=>(C(!1),T(!1)),onKeyUp:e=>{e.key.startsWith(`Arrow`)&&!P&&v(e.currentTarget.selectionStart)},onScroll:e=>{W(),l.current&&(l.current.style.transform=`translate(${-e.currentTarget.scrollLeft}px, ${-e.currentTarget.scrollTop}px)`)},onKeyDown:a=>{if(P&&!a.metaKey&&!a.ctrlKey){let e=P.items.length;if(a.key===`ArrowDown`||a.key===`ArrowUp`){a.preventDefault(),O((E+(a.key===`ArrowDown`?1:e-1))%e);return}if(a.key===`Enter`||a.key===`Tab`){a.preventDefault(),F(P.items[E]);return}if(a.key===`Escape`){a.preventDefault(),C(!1);return}}if(a.key===`Tab`&&!a.metaKey&&!a.ctrlKey&&!a.altKey){a.preventDefault();let{selectionStart:n,selectionEnd:r}=a.currentTarget,o=g(e,n,r,a.shiftKey);t(o.sql),i(o.from,o.to),requestAnimationFrame(()=>p.current?.setSelectionRange(o.from,o.to))}else if(a.key===` `&&a.ctrlKey)a.preventDefault(),v(a.currentTarget.selectionStart),T(!0),C(!0);else{if(a.key===`Enter`&&(a.metaKey||a.ctrlKey)){a.preventDefault();let{selectionStart:t,selectionEnd:r}=a.currentTarget;n(o(e,t,r))}(a.key===`f`||a.key===`F`)&&a.shiftKey&&(a.metaKey||a.ctrlKey)&&(a.preventDefault(),r(a.currentTarget.selectionStart,a.currentTarget.selectionEnd))}},onMouseMove:e=>{let{clientX:t,clientY:n}=e,r;for(let e of l.current?.querySelectorAll(`[data-known]`)??[])if([...e.getClientRects()].some(e=>t>=e.left&&t<=e.right&&n>=e.top&&n<=e.bottom)){r=M[Number(e.dataset.known)];break}r!==j.current&&(W(),r&&(j.current=r,A.current=window.setTimeout(()=>f({x:t,y:n,annotation:r}),wa)))},onMouseLeave:W,className:`${Ia} ${La} absolute inset-0 size-full resize-none overflow-x-hidden overflow-y-auto bg-transparent whitespace-pre-wrap text-transparent caret-current outline-none selection:bg-primary/30 placeholder:text-muted-foreground`,style:{color:`transparent`,caretColor:`var(--foreground)`,overflowWrap:`break-word`}}),P&&z&&(0,Q.jsx)(`ul`,{role:`listbox`,style:z,className:`bg-popover text-popover-foreground border-border fixed z-40 max-h-60 min-w-56 overflow-auto border text-xs shadow-lg`,children:P.items.map((e,t)=>{let n=e.related?Kt:e.fits?se:{column:rn,table:bn,schema:An,keyword:Jn,condition:Kt,function:Sn,type:ht}[e.kind];return(0,Q.jsxs)(`li`,{role:`option`,"aria-selected":t===E,ref:e=>{t===E&&e?.scrollIntoView({block:`nearest`})},onMouseDown:t=>{t.preventDefault(),F(e)},className:`flex cursor-pointer items-center gap-2 px-2 py-1 ${t===E?`bg-accent text-accent-foreground`:``}`,children:[(0,Q.jsx)(n,{className:`size-3.5 shrink-0 ${e.related||e.fits?`text-primary`:`text-muted-foreground`}`}),(0,Q.jsx)(`span`,{className:e.kind===`keyword`?`text-primary`:``,children:e.label}),(0,Q.jsx)(`span`,{className:`text-muted-foreground ml-auto pl-4 whitespace-nowrap`,children:e.detail})]},`${e.kind}:${e.label}:${e.detail??``}`)})}),V&&te&&!d&&(0,Q.jsx)(`div`,{role:`status`,style:{left:te.left,top:te.top,transform:`translateY(-100%)`},className:`bg-popover border-border pointer-events-none fixed z-30 max-w-[min(90vw,48rem)] overflow-hidden border px-2 py-1 font-mono text-xs shadow-md`,children:(0,Q.jsx)(Ma,{help:V})}),d&&(0,Q.jsx)(Pa,{hover:d})]})}var za=100,Ba=(e,t)=>`${t+1}. ${e.text.replace(/--[^\n]*|\/\*[\s\S]*?\*\//g,` `).trim().split(/\s+/).slice(0,2).join(` `)}`;function Va({text:e,name:t,type:n,onGroup:r,zone:i}){let a=l(n);return a?(0,Q.jsxs)(`select`,{"aria-label":`Group by part of ${t}`,title:`Group the result by a part of ${t}`,className:`text-muted-foreground border-input bg-card ml-2 max-w-24 border px-0.5 text-xs font-normal`,value:``,onChange:o=>{let l=c(a).find(e=>e.id===o.target.value);if(!l)return;let u=s({statement:e,column:t,type:n,bucket:l,zone:i});u&&r(u)},children:[(0,Q.jsx)(`option`,{value:``,children:`Group…`}),c(a).map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.label},e.id))]}):null}function Ha({environment:e,text:t,result:n,catalog:r,picked:i}){let a=(0,X.useMemo)(()=>N(b(t,r).map(e=>e.table),n.columns,r),[t,n.columns,r]),[o,s]=(0,X.useState)(``),c=a.find(e=>`${e.schema}.${e.name}`===o)??a[0];if(!c)return null;let l=A(c,n.columns,n.rows.filter((e,t)=>i.has(t))),u=l.length>0?j(e,c,l):void 0;return(0,Q.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2 text-xs`,children:[(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[i.size,` selected as rows of`]}),(0,Q.jsx)(`select`,{"aria-label":`Graph table`,value:`${c.schema}.${c.name}`,onChange:e=>s(e.target.value),className:`border-input bg-background rounded-lg border px-2 py-1`,children:a.map(e=>(0,Q.jsx)(`option`,{children:`${e.schema}.${e.name}`},`${e.schema}.${e.name}`))}),u?(0,Q.jsxs)(`a`,{href:u,className:`border-input hover:text-accent-text flex items-center gap-1 rounded-lg border px-2 py-1`,children:[(0,Q.jsx)(P,{className:`size-3.5`}),` Graph `,l.length,` `,l.length===1?`row`:`rows`]}):(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[`their `,c.columns.filter(e=>e.primaryKey).map(e=>e.name).join(`, `),` is NULL`]})]})}function Ua({environment:t,text:n,result:r,page:i,running:a,onPage:o,onGroup:s,zone:c,catalog:l}){let u=i*za,[d,f]=(0,X.useState)(),p=d?.result===r?d.rows:new Set,m=e=>f({result:r,rows:e}),h=(0,X.useMemo)(()=>N([],r.columns,l).length>0,[r.columns,l]),g=r.columns.length===0?`${r.command}${r.rowCount===null?``:` ${r.rowCount}`}`:r.rows.length===0?i>0?`no more rows`:`0 rows`:`rows ${u+1}-${u+r.rows.length}${r.truncated?``:` (${u+r.rows.length} in all)`}`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`p`,{className:`text-muted-foreground mb-2 text-xs`,children:[g,` in `,et(r.durationMs),r.columns.length>0&&Ee(r.rows.length,r.durationMs)&&` (${Ee(r.rows.length,r.durationMs)})`]}),r.columns.length>0&&(0,Q.jsx)(ce,{data:r,fetchAll:()=>e.exportSql(t,n),filename:`query-result`}),r.columns.length>0&&(0,Q.jsx)(M,{data:r,fetchAll:()=>e.exportSql(t,n),filename:`query-result`},n),h&&p.size>0&&(0,Q.jsx)(Ha,{environment:t,text:n,result:r,catalog:l,picked:p}),r.columns.length>0&&(0,Q.jsxs)(Te,{children:[(0,Q.jsx)(be,{children:(0,Q.jsxs)(Ce,{children:[h&&(0,Q.jsx)(xe,{className:`w-8`,children:(0,Q.jsx)(`input`,{type:`checkbox`,"aria-label":`Select all rows`,title:`Select rows to draw them as a graph`,checked:p.size===r.rows.length&&r.rows.length>0,onChange:e=>m(e.target.checked?new Set(r.rows.keys()):new Set)})}),r.columns.map((e,t)=>(0,Q.jsxs)(xe,{title:e.type,children:[e.name,(0,Q.jsx)(Va,{text:n,name:e.name,type:e.type,onGroup:s,zone:c})]},t))]})}),(0,Q.jsx)(Se,{children:r.rows.map((e,t)=>(0,Q.jsxs)(Ce,{children:[h&&(0,Q.jsx)(we,{children:(0,Q.jsx)(`input`,{type:`checkbox`,"aria-label":`Select row ${u+t+1}`,checked:p.has(t),onChange:e=>{let n=new Set(p);e.target.checked?n.add(t):n.delete(t),m(n)}})}),e.map((e,t)=>(0,Q.jsx)(we,{children:e===null?(0,Q.jsx)(`span`,{className:`text-muted-foreground italic`,children:`NULL`}):(0,Q.jsx)(fe,{value:e,type:r.columns[t].type,zone:c})},t))]},t))})]}),r.columns.length>0&&(i>0||r.truncated)&&(0,Q.jsx)(`div`,{className:`text-muted-foreground mt-3 flex items-center gap-4 text-xs`,children:(0,Q.jsx)(ue,{page:i,hasMore:r.truncated,disabled:a,onPage:o})})]})}function Wa({step:e,total:t,worst:n,numbers:r}){let i=t>0?e.ownCost/t:0,a=Math.round(i*100),o=e===n&&i>=.3;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`rounded-md border p-3 ${o?`border-primary`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`bg-muted text-muted-foreground flex size-5 shrink-0 items-center justify-center rounded-full text-xs`,children:r.get(e)}),(0,Q.jsx)(`span`,{className:`font-medium`,children:e.title}),o&&(0,Q.jsx)(Ge,{children:`Most of the work`}),(0,Q.jsxs)(`span`,{className:`text-muted-foreground ml-auto text-xs whitespace-nowrap`,children:[a<1?`<1`:a,`% of the effort`]})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-2 text-sm`,children:e.detail}),e.hint&&(0,Q.jsxs)(`p`,{className:`mt-1 text-sm`,children:[`💡 `,e.hint]}),(0,Q.jsx)(`div`,{className:`bg-muted mt-2 h-1.5 overflow-hidden rounded-full`,children:(0,Q.jsx)(`div`,{className:`bg-primary h-full`,style:{width:`${Math.max(i*100,1)}%`}})})]}),e.children.length>0&&(0,Q.jsxs)(`div`,{className:`mt-2 ml-4 space-y-2 border-l-2 pl-4`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Gets its rows from:`}),e.children.map((e,i)=>(0,Q.jsx)(Wa,{step:e,total:t,worst:n,numbers:r},i))]})]})}var Ga=e=>e<1?`${e.toFixed(2)} ms`:e<1e3?`${e.toFixed(1)} ms`:`${(e/1e3).toFixed(2)} s`,Ka=e=>Math.round(e).toLocaleString();function qa({share:e,className:t=`bg-primary`}){return(0,Q.jsx)(`div`,{className:`bg-muted h-1.5 w-full overflow-hidden rounded-full`,children:(0,Q.jsx)(`div`,{className:`h-full ${t}`,style:{width:`${Math.min(Math.max(e*100,+(e>0)),100)}%`}})})}function Ja({root:e,numbers:t,suggestions:n,tableRows:r}){let i=la(e.node),a=e.node[`Total Cost`],o=da(e)?.totalMs??0,[s,c]=(0,X.useState)(()=>new Set),[l,u]=(0,X.useState)(()=>new Set),d=(e,t)=>{let n=new Set(e);return n.delete(t)||n.add(t),n},f=[],p=(e,t)=>{f.push({step:e,depth:t}),s.has(e)||e.children.forEach(e=>p(e,t+1))};p(e,0);let m=i?`minmax(18rem,1fr) 7rem 7rem 9rem 3.5rem`:`minmax(18rem,1fr) 7rem 8rem`;return(0,Q.jsxs)(`div`,{role:`tree`,"aria-label":`Plan`,className:`overflow-x-auto rounded-md border text-sm`,children:[(0,Q.jsxs)(`div`,{className:`text-muted-foreground bg-muted/40 grid gap-3 border-b px-3 py-1.5 text-xs`,style:{gridTemplateColumns:m},children:[(0,Q.jsx)(`span`,{children:`Step`}),(0,Q.jsx)(`span`,{title:`This step's own share of the planner's cost`,children:`Cost`}),i&&(0,Q.jsx)(`span`,{title:`Time in this step alone, over all its loops`,children:`Time`}),(0,Q.jsx)(`span`,{children:i?`Rows: expected → actual`:`Rows expected`}),i&&(0,Q.jsx)(`span`,{className:`text-right`,children:`Loops`})]}),f.map(({step:e,depth:f})=>{let p=da(e),h=ha(e,r),g=ga(e.node),_=n.filter(t=>t.step===e),v=l.has(e),y=h.some(e=>e.level===`bad`),b=h.find(e=>e.label.endsWith(`more`)||e.label.endsWith(`fewer`));return(0,Q.jsxs)(`div`,{role:`treeitem`,"aria-level":f+1,"aria-expanded":e.children.length>0?!s.has(e):void 0,className:`border-b last:border-b-0`,children:[(0,Q.jsxs)(`div`,{className:`hover:bg-muted/40 grid cursor-pointer items-center gap-3 px-3 py-1.5 ${y?`bg-destructive/5`:``}`,style:{gridTemplateColumns:m},onClick:()=>u(d(l,e)),children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,style:{paddingLeft:`${f*1.25}rem`},children:[e.children.length>0?(0,Q.jsx)(`button`,{type:`button`,"aria-label":s.has(e)?`Show the steps below`:`Hide the steps below`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:t=>{t.stopPropagation(),c(d(s,e))},children:s.has(e)?(0,Q.jsx)(me,{className:`size-4`}):(0,Q.jsx)(le,{className:`size-4`})}):(0,Q.jsx)(`span`,{className:`w-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`bg-muted text-muted-foreground flex size-5 shrink-0 items-center justify-center rounded-full text-xs`,children:t.get(e)}),(0,Q.jsx)(`span`,{className:`font-medium whitespace-nowrap`,children:g.type}),g.target&&(0,Q.jsx)(`span`,{className:`text-muted-foreground min-w-0 truncate font-mono text-xs`,title:g.target,children:g.target}),h.map(e=>(0,Q.jsx)(Ge,{variant:e.level===`bad`?`destructive`:`outline`,title:e.detail,children:e.label},e.label)),_.length>0&&(0,Q.jsxs)(Ge,{variant:`secondary`,title:_.map(e=>e.title).join(`; `),children:[`💡 `,_.length]})]}),(0,Q.jsxs)(`div`,{title:`cost ${String(e.node[`Startup Cost`]??0)}..${e.node[`Total Cost`]}, ${Math.round(e.ownCost)} of it this step's own`,children:[(0,Q.jsx)(qa,{share:a>0?e.ownCost/a:0}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs tabular-nums`,children:Math.round(e.node[`Total Cost`]).toLocaleString()})]}),i&&(0,Q.jsxs)(`div`,{title:p?`${Ga(p.totalMs)} with the steps below it`:void 0,children:[(0,Q.jsx)(qa,{share:p&&o>0?p.ownMs/o:0,className:`bg-chart-2`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs tabular-nums`,children:p?Ga(p.ownMs):`-`})]}),(0,Q.jsx)(`span`,{className:`tabular-nums`,children:p?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[Ka(p.estimatedRows),` → `]}),(0,Q.jsx)(`span`,{className:b?b.level===`bad`?`text-destructive font-semibold`:`font-semibold`:``,children:Ka(p.actualRows)})]}):`~${Ka(e.node[`Plan Rows`])}`}),i&&(0,Q.jsx)(`span`,{className:`text-muted-foreground text-right tabular-nums`,children:p?.loops.toLocaleString()??`-`})]}),v&&(0,Q.jsxs)(`div`,{className:`bg-muted/20 space-y-2 px-3 py-2`,style:{paddingLeft:`${f*1.25+3.25}rem`},children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e.detail}),_a(e.node).length>0&&(0,Q.jsx)(`dl`,{className:`grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 font-mono text-xs`,children:_a(e.node).map(([e,t])=>(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,Q.jsx)(`dd`,{className:`break-all`,children:t})]},e))}),p&&(p.hitBlocks!==void 0||p.readBlocks!==void 0)&&(0,Q.jsxs)(`p`,{className:`text-muted-foreground text-xs`,children:[`Buffers: `,(p.hitBlocks??0).toLocaleString(),` pages from memory, `,(p.readBlocks??0).toLocaleString(),` read in.`]}),h.map(e=>(0,Q.jsxs)(`p`,{className:e.level===`bad`?`text-destructive`:``,children:[`⚠ `,e.detail]},e.label)),e.hint&&(0,Q.jsxs)(`p`,{children:[`💡 `,e.hint]}),_.map((e,t)=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`p`,{children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[e.title,`.`]}),` `,(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.detail})]}),e.sql&&(0,Q.jsx)(We,{sql:e.sql})]},t))]})]},t.get(e))})]})}function Ya({plan:e,analyzed:t,tableRows:n}){let r=(0,X.useMemo)(()=>Ki(e),[e]),[i,a]=(0,X.useState)(`tree`),o=(0,X.useMemo)(()=>{let e=new Map,t=n=>{n.children.forEach(t),e.set(n,e.size+1)};return t(r),e},[r]),s=(0,X.useMemo)(()=>sa(r),[r]);return(0,Q.jsxs)(`div`,{className:`mb-6`,children:[(0,Q.jsx)(`p`,{className:`mb-1 text-sm`,children:Ji(r)}),t?(0,Q.jsxs)(`p`,{className:`text-muted-foreground mb-3 text-xs`,children:[`Measured by running the query`,t.executionMs!==null&&(0,Q.jsxs)(Q.Fragment,{children:[` in `,(0,Q.jsx)(`strong`,{className:`text-foreground`,children:Ga(t.executionMs)})]}),t.planningMs!==null&&(0,Q.jsxs)(Q.Fragment,{children:[` (planning took `,Ga(t.planningMs),`)`]}),`, inside a transaction that was rolled back. Times are per step without the steps below it; rows are over all loops. Click a step for details.`]}):(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-3 text-xs`,children:`This is a plan, not a result: the query was not run, and the numbers are the planner's estimates. Use Explain analyze to measure it. Read the numbered steps from 1 upwards; click one for details.`}),(0,Q.jsx)(`div`,{role:`tablist`,"aria-label":`Plan view`,className:`mb-3 flex gap-1`,children:[`tree`,`words`].map(e=>(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":i===e,onClick:()=>a(e),className:`border px-2 py-1 text-xs ${i===e?`border-primary bg-accent text-accent-foreground`:`border-border text-muted-foreground`}`,children:e===`tree`?`Tree`:`In words`},e))}),i===`tree`?(0,Q.jsx)(Ja,{root:r,numbers:o,suggestions:s,tableRows:n}):(0,Q.jsx)(Wa,{step:r,total:r.node[`Total Cost`],worst:qi(r),numbers:o}),(0,Q.jsx)(`h3`,{className:`mt-5 mb-2 text-sm font-medium`,children:`Ways to make it faster`}),s.length===0?(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`None. Nothing in this plan stands out, so there is no change I would make.`}):(0,Q.jsx)(`ul`,{className:`space-y-2`,children:s.map((e,t)=>(0,Q.jsxs)(`li`,{className:`rounded-md border p-3 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e.title}),(0,Q.jsxs)(`span`,{className:`text-muted-foreground ml-2 text-xs`,children:[`(step `,o.get(e.step),`)`]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-1`,children:e.detail}),e.sql&&(0,Q.jsx)(We,{sql:e.sql})]},t))}),s.some(e=>e.sql)&&(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-2 text-xs`,children:`An index speeds up reads but makes writes a little slower and takes space, so try it on a copy of the data first.`})]})}function Xa(){let[e]=(0,X.useState)(()=>performance.now()),[t,n]=(0,X.useState)(e);return(0,X.useEffect)(()=>{let e=window.setInterval(()=>n(performance.now()),100);return()=>window.clearInterval(e)},[]),(0,Q.jsxs)(`span`,{role:`timer`,className:`text-muted-foreground w-16 text-sm tabular-nums`,children:[((t-e)/1e3).toFixed(1),` s`]})}function Za({label:e,done:t,icon:n,text:r,disabled:i}){let[a,o]=(0,X.useState)(!1);return(0,Q.jsxs)(Ii,{closeOnClick:!1,disabled:i,onClick:()=>navigator.clipboard.writeText(r()).then(()=>{o(!0),window.setTimeout(()=>o(!1),1500)},()=>{}),children:[a?(0,Q.jsx)(se,{}):(0,Q.jsx)(n,{}),` `,a?t:e]})}function Qa({environment:r,tab:i,name:s,active:c,protectedEnv:l,readOnly:u,write:f,statement:p}){let[m,h]=(0,X.useState)(()=>Da(r,i)),[g,_]=(0,X.useState)(pe),[y,b]=(0,X.useState)(!1),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(!1),D=jr(r),[O,k]=(0,X.useState)(0),A=(0,X.useRef)(void 0),[j,M]=(0,X.useState)(!1),[N,P]=(0,X.useState)(),F=(0,X.useRef)(void 0),[I,ee]=(0,X.useState)({}),[L,R]=(0,X.useState)(),[z,B]=(0,X.useState)(),{data:V}=ft(()=>e.catalog(r),r),{data:te}=ft(()=>e.functions(r),r),H=(0,X.useMemo)(()=>{let e=new Map((V??[]).map(e=>[`${e.schema}.${e.name}`,e.estimatedRows]));return(t,n)=>t?e.get(`${t}.${n}`)??void 0:void 0},[V]);(0,X.useEffect)(()=>Oa(r,i,m),[r,i,m]);let[U,W]=(0,X.useState)({text:``,page:0}),ne=e=>{c&&v(window.location.hash).sql&&d({environment:r,sql:!0,statement:e})},G=(t,n)=>{let i=new AbortController;A.current=i,b(!0),ne({text:t,run:!0,page:n}),e.run(r,t,n*za,za,i.signal).then(e=>{dt(r,t,`public`,e.command),W({text:t,page:n}),B({result:e})},e=>B(i.signal.aborted?{error:`Cancelled.`}:{error:e.message})).finally(()=>{A.current===i&&(A.current=void 0),b(!1),k(e=>e+1)})},re=()=>A.current?.abort();(0,X.useEffect)(()=>()=>A.current?.abort(),[]);let ie=(t,n=!1)=>{M(!0),ne({text:t,explain:!0,...n?{analyze:n}:{}}),(n?e.explainAnalyze(r,t).then(({plan:e,...t})=>B({plan:e,analyzed:t})):e.explain(r,t).then(({plan:e})=>B({plan:e}))).catch(e=>B({error:e.message})).finally(()=>M(!1))};(0,X.useEffect)(()=>{p&&(h(p.text),B(void 0),R(void 0),P(p.explain||p.run?p:void 0))},[r,p?.text,p?.explain,p?.analyze,p?.run,p?.page]);let K=(0,X.useMemo)(()=>n(m),[m]),ae=(0,X.useMemo)(()=>x(m,V??[]),[m,V]),[oe,se]=(0,X.useState)({}),ce=(0,X.useMemo)(()=>t(m),[m]),ue=e=>{let t=n(e).filter(e=>!I[e.name]?.trim());if(t.length>0)B({error:`Give a value for ${t.map(e=>e.name).join(`, `)}.`});else return a(e,I)},fe=()=>{let e=F.current??{from:m.length,to:m.length};return o(m,Math.min(e.from,m.length),Math.min(e.to,m.length))},me=e=>{let t=(e??fe()).trim();if(!t||y)return;let n=ue(t);n!==void 0&&(R(void 0),G(n,0))},ge=async()=>{if(y||ce.length===0)return;let t=[];for(let e of ce){let n=ue(e.text);if(n===void 0)return;t.push(n)}let n=t.map(e=>({text:e,page:0,status:`waiting`})),i=(e,t)=>R(n=>n&&{...n,entries:n.entries.map((n,r)=>r===e?{...n,...t}:n)}),a=new AbortController;A.current=a,b(!0),B(void 0),R({entries:n,shown:0});try{for(let n=0;n<t.length;n++){i(n,{status:`running`}),R(e=>e&&{...e,shown:n});try{let o=await e.run(r,t[n],0,za,a.signal);dt(r,t[n],`public`,o.command),i(n,{status:`done`,result:o})}catch(e){i(n,{status:`failed`,error:a.signal.aborted?`Cancelled.`:e.message});for(let e=n+1;e<t.length;e++)i(e,{status:`skipped`});break}}}finally{A.current===a&&(A.current=void 0),b(!1),k(e=>e+1)}},be=(t,n)=>{let i=L?.entries[t];if(!i||y)return;let a=new AbortController;A.current=a,b(!0),e.run(r,i.text,n*za,za,a.signal).then(e=>R(r=>r&&{...r,entries:r.entries.map((r,i)=>i===t?{...r,page:n,result:e,error:void 0}:r)}),e=>R(n=>n&&{...n,entries:n.entries.map((n,r)=>r===t?{...n,status:`failed`,error:a.signal.aborted?`Cancelled.`:e.message}:n)})).finally(()=>{A.current===a&&(A.current=void 0),b(!1)})},xe=(e,t)=>{let n=F.current,r=e??n?.from??0,i=t??n?.to??0;if(r!==i){let e=Math.min(r,i),t=Math.max(r,i);h(m.slice(0,e)+vn(m.slice(e,t)).trimEnd()+m.slice(t))}else h(vn(m));F.current=void 0},Se=e=>{h(e),me(e)},Ce=e=>{_(e),de(e)},we=e=>S(e)||window.confirm(`Explain analyze runs the statement to measure it. It runs inside a transaction that is rolled back, so changed rows are not kept, but sequences still advance and triggers still fire. Run it?`),Te=(e=!1)=>{let t=fe().trim();if(!t||j)return;let n=ue(t);n!==void 0&&(!e||we(n))&&(R(void 0),ie(n,e))},Ee=()=>{if(!N||y||j)return;let e=N.text.trim();if(N.explain){if(N.analyze&&!we(e))return;P(void 0),ie(e,N.analyze)}else P(void 0),G(e,N.page??0)},Oe=N?.explain?N.analyze?`Explain analyze`:`Explain`:`Run`;return(0,Q.jsxs)(Q.Fragment,{children:[l&&(0,Q.jsxs)(`div`,{className:`mb-2 flex items-stretch gap-3`,children:[(0,Q.jsxs)(`div`,{role:`alert`,className:`flex flex-1 items-center gap-2 rounded-lg border px-3 py-2 text-sm ${f.enabled?`border-destructive bg-destructive text-white animate-pulse`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:[(0,Q.jsx)(ve,{className:`size-4 shrink-0`}),f.enabled?(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:`WRITE MODE:`}),` you are connected to protected database`,` `,(0,Q.jsx)(`strong`,{children:r}),` and what you run can change or delete live data.`]}):(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:r}),` is a protected database. These queries run against live data`,u?`, but the session is read only so nothing can be changed`:``,`.`]})]}),f.available&&(0,Q.jsx)(Qt,{write:f})]}),f.error&&(0,Q.jsx)(`p`,{className:`text-destructive mb-2 text-sm`,children:f.error}),(0,Q.jsx)(Ra,{value:m,onChange:h,onRun:me,onFormat:xe,onCursor:(e,t)=>F.current={from:e,to:t},catalog:V??[],functions:te??[],zone:g||void 0}),K.length>0&&(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3`,role:`group`,"aria-label":`Parameters`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Parameters`}),K.map(e=>{let t=oe[e.name]?void 0:ae[e.name],n=t===`date`?`date`:t?`datetime-local`:void 0;return(0,Q.jsxs)(`label`,{className:`flex items-center gap-1 font-mono text-xs`,children:[e.name,(0,Q.jsx)(`input`,{"aria-label":`Value for ${e.name}`,type:n??`text`,step:n===`datetime-local`?1:void 0,value:n===`datetime-local`?(I[e.name]??``).replace(` `,`T`):I[e.name]??``,onChange:t=>ee({...I,[e.name]:n===`datetime-local`?t.target.value.replace(`T`,` `):t.target.value}),className:`border-input bg-card border px-1 py-0.5 ${n?`w-auto`:`w-32`}`,placeholder:`value`}),ae[e.name]&&(0,Q.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground underline`,onClick:()=>{se({...oe,[e.name]:!oe[e.name]}),ee({...I,[e.name]:``})},children:oe[e.name]?`picker`:`type`})]},e.name)}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Numbers, true, false and null go in as they are, anything else as text; put it in 'quotes' to keep a number as text.`})]}),N&&N.text===m&&(0,Q.jsxs)(`div`,{role:`status`,className:`border-input bg-card mt-3 flex flex-wrap items-center gap-3 rounded-lg border px-3 py-2 text-sm`,children:[(0,Q.jsx)(wn,{className:`text-muted-foreground size-4 shrink-0`}),(0,Q.jsxs)(`span`,{className:`flex-1`,children:[`This link asks to `,Oe.toLowerCase(),` the statement above on `,(0,Q.jsx)(`strong`,{children:r}),`. Nothing has been sent yet: read it first.`]}),(0,Q.jsxs)(q,{size:`sm`,onClick:Ee,disabled:y||j,children:[N.explain?(0,Q.jsx)(Xn,{className:`size-4`}):(0,Q.jsx)(De,{className:`size-4`}),` `,Oe]}),(0,Q.jsx)(q,{size:`sm`,variant:`ghost`,onClick:()=>P(void 0),children:`Dismiss`})]}),(0,Q.jsxs)(`div`,{className:`mt-3 mb-6 flex flex-wrap items-center gap-3`,children:[y?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(q,{variant:`destructive`,onClick:re,children:[(0,Q.jsx)(Wn,{className:`size-4`}),` Cancel`]}),(0,Q.jsx)(Xa,{})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(q,{onClick:()=>me(),disabled:!m.trim(),children:[(0,Q.jsx)(De,{className:`size-4`}),` `,ce.length>1?`Run statement`:`Run`]}),(0,Q.jsxs)(q,{variant:`outline`,onClick:ge,disabled:ce.length===0,children:[(0,Q.jsx)(Pn,{className:`size-4`}),` Run all`,ce.length>1?` (${ce.length})`:``]})]}),(0,Q.jsxs)(Ni,{children:[(0,Q.jsxs)(Pi,{render:(0,Q.jsx)(q,{variant:`outline`}),children:[(0,Q.jsx)(On,{className:`size-4`}),` More `,(0,Q.jsx)(le,{className:`size-4`})]}),(0,Q.jsxs)(Fi,{children:[(0,Q.jsxs)(Ii,{onClick:()=>Te(),disabled:j||!m.trim(),children:[(0,Q.jsx)(Xn,{}),` `,j?`Explaining...`:`Explain`]}),(0,Q.jsxs)(Ii,{onClick:()=>Te(!0),disabled:j||!m.trim(),title:`Run the statement (rolled back afterwards) to measure the time and rows of each step`,children:[(0,Q.jsx)(Ft,{}),` Explain analyze`]}),(0,Q.jsxs)(Ii,{onClick:()=>xe(),disabled:!m.trim(),title:`Format the selection, or all of the text (Cmd/Ctrl + Shift + F)`,children:[(0,Q.jsx)(Kn,{}),` Format`]}),(0,Q.jsxs)(Ii,{onClick:()=>w(!C),children:[(0,Q.jsx)(Bn,{}),` `,C?`Hide history`:`History`]}),(0,Q.jsxs)(Ii,{onClick:()=>E(!T),title:`Settings (GUCs) set on the session before each statement runs`,children:[(0,Q.jsx)(ye,{}),` Settings`,D.count>0?` (${D.count})`:``]}),(0,Q.jsx)(Li,{}),(0,Q.jsx)(Za,{label:`Copy`,done:`Copied`,icon:he,text:()=>m,disabled:!m.trim()}),(0,Q.jsx)(Za,{label:`Share`,done:`Share code copied`,icon:pt,text:()=>xa({sql:m,name:s}),disabled:!m.trim()}),(0,Q.jsx)(Li,{}),(0,Q.jsx)(`div`,{className:`px-1.5 py-1`,onKeyDown:e=>e.stopPropagation(),children:(0,Q.jsx)(ka,{zone:g,onChange:Ce})})]})]}),T&&(0,Q.jsx)(Mr,{rows:D.rows,change:D.change}),(0,Q.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[`⌘/Ctrl + Enter runs the selection, or the statement the cursor is in; ⌘/Ctrl + Shift + F formats. Ctrl + Space completes. Paste a share code anywhere on this page to open it in a new tab.`,` `,!V&&`Loading tables for hints...`]})]}),C&&(0,Q.jsx)(Fr,{environment:r,sql:m,refresh:O,onPick:e=>{h(e),B(void 0)}}),z?.error&&(0,Q.jsx)(`pre`,{className:`text-destructive text-sm whitespace-pre-wrap`,children:z.error}),L&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{role:`tablist`,"aria-label":`Statements`,className:`mb-3 flex flex-wrap gap-1`,children:L.entries.map((e,t)=>(0,Q.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":L.shown===t,onClick:()=>R({...L,shown:t}),className:`flex items-center gap-1 border px-2 py-1 text-xs ${L.shown===t?`border-primary bg-accent text-accent-foreground`:`border-border text-muted-foreground`}`,children:[e.status===`running`?(0,Q.jsx)(_e,{className:`size-3.5 animate-spin`}):e.status===`done`?(0,Q.jsx)(En,{className:`size-3.5`}):e.status===`failed`?(0,Q.jsx)(wn,{className:`text-destructive size-3.5`}):null,Ba(e,t)]},t))}),(()=>{let e=L.entries[L.shown];return e?(0,Q.jsxs)(`div`,{role:`tabpanel`,children:[(0,Q.jsx)(`pre`,{className:`text-muted-foreground mb-2 max-h-24 overflow-auto text-xs whitespace-pre-wrap`,children:e.text}),e.status===`waiting`&&(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Waiting for the statements before it.`}),e.status===`running`&&(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Running...`}),e.status===`skipped`&&(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Not run: an earlier statement failed.`}),e.error&&(0,Q.jsx)(`pre`,{className:`text-destructive text-sm whitespace-pre-wrap`,children:e.error}),e.result&&(0,Q.jsx)(Ua,{environment:r,text:e.text,result:e.result,page:e.page,running:y,onPage:e=>be(L.shown,e),onGroup:Se,zone:g||void 0,catalog:V??[]})]}):null})()]}),z?.plan&&(0,Q.jsx)(Ya,{plan:z.plan,analyzed:z.analyzed,tableRows:H}),z?.result&&(0,Q.jsx)(Ua,{environment:r,text:U.text,result:z.result,page:U.page,running:y,onPage:e=>G(U.text,e),onGroup:Se,zone:g||void 0,catalog:V??[]})]})}var $a=e=>`psql-explorer:sql-tabs:${e}`;function eo(e){try{let t=JSON.parse(window.localStorage.getItem($a(e))??`null`);if(t&&Array.isArray(t.tabs)&&t.tabs.length>0)return t}catch{}return{tabs:[{id:`1`}],active:`1`,next:2}}function to({environment:e,statement:t,visible:n,...r}){let[i,a]=(0,X.useState)(()=>eo(e)),[o,s]=(0,X.useState)(),[c,l]=(0,X.useState)(),u=(0,X.useRef)(i.active);u.current=i.active,(0,X.useEffect)(()=>{try{window.localStorage.setItem($a(e),JSON.stringify(i))}catch{}},[e,i]),(0,X.useEffect)(()=>{t&&l(u.current)},[t?.text,t?.explain,t?.analyze,t?.run,t?.page]);let d=t=>{a(n=>{let r=String(n.next);return Oa(e,r,t.sql),{tabs:[...n.tabs,{id:r,name:t.name}],active:r,next:n.next+1}})};(0,X.useEffect)(()=>{if(!n)return;let e=e=>{let t=Sa(e.clipboardData?.getData(`text`)??``);t&&(e.preventDefault(),d(t))};return document.addEventListener(`paste`,e,!0),()=>document.removeEventListener(`paste`,e,!0)},[n,e]);let f=e=>e.name||`Query ${e.id}`,p=()=>a(e=>{let t=String(e.next);return{tabs:[...e.tabs,{id:t}],active:t,next:e.next+1}}),m=t=>{Ea(e,t),a(e=>{let n=e.tabs.filter(e=>e.id!==t);if(n.length===0)return{tabs:[{id:String(e.next)}],active:String(e.next),next:e.next+1};let r=e.tabs.findIndex(e=>e.id===t);return{...e,tabs:n,active:e.active===t?n[Math.min(r,n.length-1)].id:e.active}})},h=(e,t)=>{a(n=>({...n,tabs:n.tabs.map(n=>n.id===e?{...n,name:t.trim()||void 0}:n)})),s(void 0)};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`tablist`,"aria-label":`Queries`,className:`mb-3 flex flex-wrap items-center gap-1`,children:[i.tabs.map(e=>{let t=e.id===i.active;return(0,Q.jsxs)(`div`,{className:`flex items-center border text-sm ${t?`border-primary text-accent-text`:`border-input text-muted-foreground hover:text-foreground`}`,children:[o===e.id?(0,Q.jsx)(`input`,{autoFocus:!0,"aria-label":`Tab name`,defaultValue:e.name??``,placeholder:`Query ${e.id}`,maxLength:40,onFocus:e=>e.currentTarget.select(),onBlur:t=>h(e.id,t.currentTarget.value),onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&s(void 0)},className:`bg-transparent w-32 px-2 py-1 outline-none`}):(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":t,title:`Double-click to rename`,onClick:()=>a(t=>({...t,active:e.id})),onDoubleClick:()=>s(e.id),className:`max-w-48 truncate px-2 py-1`,children:f(e)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Close ${f(e)}`,onClick:()=>m(e.id),className:`hover:text-destructive px-1 py-1`,children:(0,Q.jsx)($t,{className:`size-3`})})]},e.id)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`New query tab`,title:`New query tab`,onClick:p,className:`text-muted-foreground hover:text-foreground border-input border p-1.5`,children:(0,Q.jsx)(tt,{className:`size-4`})})]}),i.tabs.map(n=>(0,Q.jsx)(`div`,{role:`tabpanel`,hidden:n.id!==i.active,children:(0,Q.jsx)(Qa,{environment:e,tab:n.id,name:n.name,active:n.id===i.active,statement:n.id===c?t:void 0,...r})},n.id))]})}export{to as SqlTabs};
@@ -1 +1 @@
1
- import{it as e,ot as t,rt as n}from"./route-DO6IZ7of.js";t();var r=n();function i({className:t,...n}){return(0,r.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,r.jsx)(`table`,{"data-slot":`table`,className:e(`w-full caption-bottom text-sm`,t),...n})})}function a({className:t,...n}){return(0,r.jsx)(`thead`,{"data-slot":`table-header`,className:e(`[&_tr]:border-b`,t),...n})}function o({className:t,...n}){return(0,r.jsx)(`tbody`,{"data-slot":`table-body`,className:e(`[&_tr:last-child]:border-0`,t),...n})}function s({className:t,...n}){return(0,r.jsx)(`tr`,{"data-slot":`table-row`,className:e(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,t),...n})}function c({className:t,...n}){return(0,r.jsx)(`th`,{"data-slot":`table-head`,className:e(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0`,t),...n})}function l({className:t,...n}){return(0,r.jsx)(`td`,{"data-slot":`table-cell`,className:e(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0`,t),...n})}export{a,c as i,o as n,s as o,l as r,i as t};
1
+ import{it as e,ot as t,rt as n}from"./route-7eu-iAqD.js";t();var r=n();function i({className:t,...n}){return(0,r.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,r.jsx)(`table`,{"data-slot":`table`,className:e(`w-full caption-bottom text-sm`,t),...n})})}function a({className:t,...n}){return(0,r.jsx)(`thead`,{"data-slot":`table-header`,className:e(`[&_tr]:border-b`,t),...n})}function o({className:t,...n}){return(0,r.jsx)(`tbody`,{"data-slot":`table-body`,className:e(`[&_tr:last-child]:border-0`,t),...n})}function s({className:t,...n}){return(0,r.jsx)(`tr`,{"data-slot":`table-row`,className:e(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,t),...n})}function c({className:t,...n}){return(0,r.jsx)(`th`,{"data-slot":`table-head`,className:e(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0`,t),...n})}function l({className:t,...n}){return(0,r.jsx)(`td`,{"data-slot":`table-cell`,className:e(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0`,t),...n})}export{a,c as i,o as n,s as o,l as r,i as t};
@@ -1 +1 @@
1
- import{at as e}from"./route-DO6IZ7of.js";var t={name:`triangle-alert`,size:24,node:[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`alert-triangle`]};t.node;var n=e(t);export{n as t};
1
+ import{at as e}from"./route-7eu-iAqD.js";var t={name:`triangle-alert`,size:24,node:[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`alert-triangle`]};t.node;var n=e(t);export{n as t};
@@ -1,4 +1,4 @@
1
- import{Z as e,at as t,ct as n,ot as r,rt as i}from"./route-DO6IZ7of.js";import{t as a,z as o}from"./button-ClA70PLR.js";import{t as s}from"./copy-CCXzeW-s.js";var c={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};c.node;var l=t(c),u={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};u.node;var d=t(u),f={name:`download`,size:24,node:[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]};f.node;var p=t(f),m={name:`external-link`,size:24,node:[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]};m.node;var h=t(m),g=n(r(),1);function _(t){let n=t.toLowerCase();return e(n)===`timestamptz`?`timestamptz`:n.endsWith(`[]`)||n.startsWith(`_`)?`array`:n===`bytea`?`bytea`:/^(public\.)?"?(geometry|geography)"?(\(.*\))?$/.test(n)?`geometry`:/multirange$/.test(n)?`multirange`:/range$/.test(n)?`range`:`text`}function v(e){let t=/^(\d{4,})-(\d\d)-(\d\d)[ T](\d\d):(\d\d):(\d\d)(?:\.(\d+))?([+-]\d\d)(?::?(\d\d))?(?::?(\d\d))?$/.exec(e);if(!t)return;let[,n,r,i,a,o,s,c,l,u,d]=t,f=(l.startsWith(`-`)?-1:1)*(Math.abs(Number(l))*3600+Number(u??0)*60+Number(d??0)),p=Number(((c??`0`)+`00`).slice(0,3)),m=Date.UTC(Number(n),Number(r)-1,Number(i),Number(a),Number(o),Number(s),p);if(!Number.isNaN(m))return new Date(m-f*1e3)}function y(e,t){let n=v(e);if(n)try{let r=new Intl.DateTimeFormat(`en-GB`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hourCycle:`h23`,timeZoneName:`short`}).formatToParts(n),i=e=>r.find(t=>t.type===e)?.value??``,a=/\.(\d+)/.exec(e)?.[1];return`${i(`year`)}-${i(`month`)}-${i(`day`)} ${i(`hour`)}:${i(`minute`)}:${i(`second`)}${a?`.${a}`:``} ${i(`timeZoneName`)}`}catch{return}}function b(e){let t=e.replace(/^\[[^\]=]*\]=/,``),n=0,r=()=>{if(t[n]!==`{`)return;n++;let e=[];if(t[n]===`}`)return n++,e;for(;;){let i=t[n];if(i===`{`){let t=r();if(!t)return;e.push(t)}else if(i===`"`){n++;let r=``;for(;n<t.length&&t[n]!==`"`;)t[n]===`\\`&&n++,r+=t[n++]??``;if(t[n]!==`"`)return;n++,e.push(r)}else{let r=``;for(;n<t.length&&t[n]!==`,`&&t[n]!==`}`;)r+=t[n++];e.push(r===`NULL`?null:r)}if(t[n]===`,`)n++;else if(t[n]===`}`)return n++,e;else return}},i=r();return i&&n===t.length?i:void 0}function x(e){let t=0,n=1,r=(e,i)=>{n=Math.max(n,i);for(let n of e)Array.isArray(n)?r(n,i+1):t++};return r(e,1),{count:t,depth:n}}function S(e){if(e===`empty`)return{empty:!0};let t=/^([[(])(.*)([\])])$/s.exec(e);if(!t)return;let n=t[2],r=[],i=``,a=!1;for(let e=0;e<n.length;e++){let t=n[e];a?t===`"`&&n[e+1]===`"`?(i+=`"`,e++):t===`\\`?i+=n[++e]??``:t===`"`?a=!1:i+=t:t===`"`?a=!0:t===`,`&&r.length===0?(r.push(i),i=``):i+=t}if(r.push(i),r.length!==2)return;let[o,s]=r;return{empty:!1,lower:o===``?null:{value:o,inclusive:t[1]===`[`},upper:s===``?null:{value:s,inclusive:t[3]===`]`}}}function ee(e){let t=/^\{(.*)\}$/s.exec(e);if(!t)return;if(t[1]===``)return[];let n=[],r=0,i=!1,a=``;for(let e of t[1])e===`"`&&(i=!i),i||e!==`[`&&e!==`(`||r++,i||e!==`]`&&e!==`)`||r--,!i&&r===0&&e===`,`?(n.push(a),a=``):a+=e;n.push(a);let o=n.map(S);return o.every(e=>e)?o:void 0}function C(e){if(e.empty)return`empty`;let{lower:t,upper:n}=e;if(!t&&!n)return`everything`;let r=t?`${t.value} ${t.inclusive?`≤`:`<`} `:``;return n?`${r}x ${n.inclusive?`≤`:`<`} ${n.value}`:`x ${t.inclusive?`≥`:`>`} ${t.value}`}function te(e){if(!/^\\x([0-9a-fA-F]{2})*$/.test(e))return;let t=e.slice(2),n=new Uint8Array(t.length/2);for(let e=0;e<n.length;e++)n[e]=parseInt(t.slice(e*2,e*2+2),16);return n}function ne(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return`\\x${t}`}var w=20971520;async function T(e,t){if(e.size>20971520)throw Error(`${e.name} is ${M(e.size)}; the limit is ${M(w)}`);if(_(t)===`bytea`)return ne(new Uint8Array(await e.arrayBuffer()));let n=await e.text();if(n.includes(`\0`))throw Error(`${e.name} is not text, so it cannot go in a ${t} column`);return n}var E=(e,t,n)=>n.every((n,r)=>e[t+r]===n);function D(e){if(E(e,0,[137,80,78,71,13,10,26,10]))return`image/png`;if(E(e,0,[255,216,255]))return`image/jpeg`;if(E(e,0,[71,73,70,56]))return`image/gif`;if(E(e,0,[82,73,70,70])&&E(e,8,[87,69,66,80]))return`image/webp`;if(E(e,0,[66,77]))return`image/bmp`}var re={"image/jpeg":`jpg`},O=e=>[...e].map(e=>e.charCodeAt(0)),ie=[{bytes:O(`%PDF-`),type:{mime:`application/pdf`,extension:`pdf`}},{bytes:[80,75,3,4],type:{mime:`application/zip`,extension:`zip`}},{bytes:[31,139,8],type:{mime:`application/gzip`,extension:`gz`}},{bytes:O(`BZh`),type:{mime:`application/x-bzip2`,extension:`bz2`}},{bytes:[253,...O(`7zXZ`),0],type:{mime:`application/x-xz`,extension:`xz`}},{bytes:[55,122,188,175,39,28],type:{mime:`application/x-7z-compressed`,extension:`7z`}},{bytes:[...O(`Rar!`),26,7],type:{mime:`application/vnd.rar`,extension:`rar`}},{at:257,bytes:O(`ustar`),type:{mime:`application/x-tar`,extension:`tar`}},{bytes:[...O(`SQLite format 3`),0],type:{mime:`application/vnd.sqlite3`,extension:`sqlite`}},{bytes:[0,0,1,0],type:{mime:`image/x-icon`,extension:`ico`}},{bytes:[...O(`II`),42,0],type:{mime:`image/tiff`,extension:`tiff`}},{bytes:[...O(`MM`),0,42],type:{mime:`image/tiff`,extension:`tiff`}},{at:4,bytes:O(`ftyp`),type:{mime:`video/mp4`,extension:`mp4`}},{bytes:O(`OggS`),type:{mime:`audio/ogg`,extension:`ogg`}},{bytes:O(`fLaC`),type:{mime:`audio/flac`,extension:`flac`}},{bytes:O(`ID3`),type:{mime:`audio/mpeg`,extension:`mp3`}},{bytes:[255,251],type:{mime:`audio/mpeg`,extension:`mp3`}},{bytes:[26,69,223,163],type:{mime:`video/webm`,extension:`webm`}},{bytes:O(`wOF2`),type:{mime:`font/woff2`,extension:`woff2`}}];function k(e){let t=D(e);if(t)return{mime:t,extension:re[t]??t.replace(`image/`,``)};if(E(e,0,O(`RIFF`))&&E(e,8,O(`WAVE`)))return{mime:`audio/wav`,extension:`wav`};let n=ie.find(({at:t=0,bytes:n})=>E(e,t,n));if(n)return n.type;if(e.length>0){let t;try{t=new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{}if(t!==void 0&&!/[\u0000-\u0008\u000e-\u001f]/.test(t))try{return JSON.parse(t),{mime:`application/json`,extension:`json`}}catch{return{mime:`text/plain`,extension:`txt`}}}return{mime:`application/octet-stream`,extension:`bin`}}function A(e,t,n=!1){return`${e}.${t.extension}${n?`.gz`:``}`}async function j(e){let t=new Blob([e]).stream().pipeThrough(new CompressionStream(`gzip`));return new Uint8Array(await new Response(t).arrayBuffer())}function M(e){return e<1024?`${e} byte${e===1?``:`s`}`:e<1048576?`${(e/1024).toFixed(1)} kB`:`${(e/1024/1024).toFixed(1)} MB`}function N(e,t=32){let n=[...e.slice(0,t)].map(e=>e.toString(16).padStart(2,`0`)).join(` `);return e.length>t?`${n} …`:n}var ae=[``,`Point`,`LineString`,`Polygon`,`MultiPoint`,`MultiLineString`,`MultiPolygon`,`GeometryCollection`];function oe(e){if(!/^([0-9a-fA-F]{2}){5,}$/.test(e)||e.length>2e6)return;let t=new Uint8Array(e.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);let n=new DataView(t.buffer),r=0,i;try{let e=()=>{let t=n.getUint8(r++)===1,a=n.getUint32(r,t);r+=4;let o=!!(a&2147483648)||(a&65535)>=1e3,s=!!(a&1073741824);if(a&536870912){let e=n.getInt32(r,t);r+=4,i??=e}let c=(a&65535)%1e3,l=()=>{let e=n.getFloat64(r,t);return r+=8,e},u=()=>{let e=l(),t=l();return o&&l(),s&&l(),[e,t]},d=()=>{let e=n.getUint32(r,t);if(r+=4,e>1e6)throw RangeError(`too many`);return e},f=()=>Array.from({length:d()},u);switch(c){case 1:return{type:`Point`,points:[u()]};case 2:return{type:`LineString`,points:f()};case 3:return{type:`Polygon`,rings:Array.from({length:d()},f)};case 4:case 5:case 6:case 7:return{type:c===7?`Collection`:`Multi`,name:ae[c],parts:Array.from({length:d()},e)};default:throw RangeError(`unknown geometry`)}},a=e();return r===t.length?{srid:i,shape:a}:void 0}catch{return}}var P=e=>e.type===`Multi`||e.type===`Collection`?e.name:e.type;function F(e){return e.type===`Point`||e.type===`LineString`?e.points:e.type===`Polygon`?e.rings.flat():e.parts.flatMap(F)}function I(e){let t=F(e);if(t.length===0)return;let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let[e,o]of t)n=Math.min(n,e),r=Math.min(r,o),i=Math.max(i,e),a=Math.max(a,o);return[n,r,i,a]}function L(e){let{shape:t,srid:n}=e,r=n?` · SRID ${n}`:``;if(t.type===`Point`)return`Point (${t.points[0].map(e=>+e.toFixed(6)).join(` `)})${r}`;let i=F(t).length;return`${P(t)}, ${i} point${i===1?``:`s`}${r}`}function se(e){if(e.srid!==4326)return;let t=I(e.shape);if(!t)return;let[n,r,i,a]=t,o=(n+i)/2,s=(r+a)/2;if(!(Math.abs(o)>180||Math.abs(s)>90))return`https://www.openstreetmap.org/?mlat=${s}&mlon=${o}#map=15/${s}/${o}`}var R=i(),z=80;function B({items:e}){return(0,R.jsx)(`ol`,{className:`list-decimal space-y-0.5 pl-5 text-xs`,children:e.map((e,t)=>Array.isArray(e)?(0,R.jsx)(`li`,{children:(0,R.jsx)(B,{items:e})},t):(0,R.jsx)(`li`,{className:e===null?`text-muted-foreground italic`:`break-all`,children:e===null?`NULL`:e},t))})}var V=(e,t,n)=>{let r=e=>`${e[0]},${-e[1]}`;if(e.type===`Point`)return e.points.map((e,r)=>(0,R.jsx)(`circle`,{cx:e[0],cy:-e[1],r:n,className:`fill-primary`,"data-point":!0},`${t}${r}`));if(e.type===`LineString`)return(0,R.jsx)(`polyline`,{points:e.points.map(r).join(` `),fill:`none`,className:`stroke-primary`,strokeWidth:2,vectorEffect:`non-scaling-stroke`},t);if(e.type===`Polygon`){let n=e.rings.map(e=>`M${e.map(r).join(`L`)}Z`).join(``);return(0,R.jsx)(`path`,{d:n,fillRule:`evenodd`,className:`fill-primary/20 stroke-primary`,strokeWidth:2,vectorEffect:`non-scaling-stroke`},t)}return e.parts.map((e,r)=>V(e,`${t}.${r}`,n))};function H({geometry:e}){let t=I(e.shape);if(!t)return(0,R.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Empty geometry.`});let[n,r,i,a]=t,o=Math.max(i-n,a-r)*.1||1;n-=o,r-=o,i+=o,a+=o;let s=se(e),c=e.shape.type===`Point`;return(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`svg`,{role:`img`,"aria-label":`${P(e.shape)} preview`,viewBox:`${n} ${-a} ${i-n} ${a-r}`,preserveAspectRatio:`xMidYMid meet`,className:`bg-muted h-48 w-72`,children:(0,R.jsx)(`g`,{children:V(e.shape,`g`,o*.2)})}),(0,R.jsxs)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:[L(e),!c&&t&&` · x ${+t[0].toFixed(6)} to ${+t[2].toFixed(6)}, y ${+t[1].toFixed(6)} to ${+t[3].toFixed(6)}`]}),s&&(0,R.jsxs)(`a`,{href:s,target:`_blank`,rel:`noreferrer`,className:`text-accent-text inline-flex items-center gap-1 text-xs hover:underline`,onClick:e=>e.stopPropagation(),children:[`Open on OpenStreetMap `,(0,R.jsx)(h,{className:`size-3`})]})]})}function U(e,t){let[n,r]=(0,g.useState)();return(0,g.useEffect)(()=>{if(!e||!t)return r(void 0);let n=URL.createObjectURL(new Blob([e],{type:t}));return r(n),()=>URL.revokeObjectURL(n)},[e,t]),n}function W({bytes:e,file:t,url:n,name:r,size:i}){let[a,o]=(0,g.useState)(!1),s=`text-accent-text inline-flex items-center gap-1 text-xs hover:underline`,c=async()=>{o(!0);try{let n=await j(e),i=URL.createObjectURL(new Blob([n],{type:`application/gzip`})),a=document.createElement(`a`);a.href=i,a.download=A(r,t,!0),a.click(),URL.revokeObjectURL(i)}finally{o(!1)}};return(0,R.jsxs)(`span`,{className:`flex items-center gap-3`,children:[(0,R.jsxs)(`a`,{href:n,download:A(r,t),onClick:e=>e.stopPropagation(),className:s,children:[(0,R.jsx)(p,{className:`size-3`}),` Download `,i,` (.`,t.extension,`)`]}),t.extension!==`gz`&&(0,R.jsxs)(`button`,{type:`button`,disabled:a,onClick:e=>{e.stopPropagation(),c()},className:s,children:[(0,R.jsx)(p,{className:`size-3`}),` `,a?`Compressing...`:`as .gz`]})]})}function G(e,t,n,r){let i=_(t),a=(0,g.useMemo)(()=>i===`bytea`?te(e):void 0,[i,e]),o=(0,g.useMemo)(()=>a?D(a):void 0,[a]),s=U(o?a:void 0,o),c=(0,g.useMemo)(()=>a?k(a):void 0,[a]),l=U(a,c?.mime),u=(0,g.useMemo)(()=>i===`geometry`?oe(e):void 0,[i,e]);if(i===`timestamptz`&&n){let t=y(e,n);if(t)return{summary:t,title:`${e} (as the database wrote it)`}}if(i===`array`){let t=b(e);if(t){let{count:n,depth:r}=x(t),i=`${n} item${n===1?``:`s`}${r>1?`, ${r} levels`:``}`;return{summary:`${e}`,title:i,detail:n>0?(0,R.jsx)(B,{items:t}):void 0}}}if(i===`range`){let t=S(e);if(t)return{summary:C(t),title:e}}if(i===`multirange`){let t=ee(e);if(t)return{summary:t.map(C).join(` or `)||`empty`,title:e}}if(i===`geometry`&&u)return{summary:L(u),title:e.length>80?`${e.slice(0,80)}…`:e,detail:(0,R.jsx)(H,{geometry:u})};if(i===`bytea`&&a){let e=M(a.length),t=a&&c&&l&&(0,R.jsx)(W,{bytes:a,file:c,url:l,name:r,size:e});return o&&s?{summary:`${o.replace(`image/`,``).toUpperCase()} image, ${e}`,thumbnail:s,detail:(0,R.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,R.jsx)(`img`,{src:s,alt:`${o} image, ${e}`,className:`bg-muted max-h-64 max-w-72 object-contain`}),t]})}:{summary:`${e}: ${N(a,12)}`,title:`${e}`,detail:(0,R.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,R.jsx)(`pre`,{className:`max-w-96 text-xs break-all whitespace-pre-wrap`,children:N(a,256)}),t]})}}let d=e.length>z||e.includes(`
1
+ import{Z as e,at as t,ct as n,ot as r,rt as i}from"./route-7eu-iAqD.js";import{t as a,z as o}from"./button-BiFx4Lyw.js";import{t as s}from"./copy-C2N9tUYJ.js";var c={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};c.node;var l=t(c),u={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};u.node;var d=t(u),f={name:`download`,size:24,node:[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]};f.node;var p=t(f),m={name:`external-link`,size:24,node:[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]};m.node;var h=t(m),g=n(r(),1);function _(t){let n=t.toLowerCase();return e(n)===`timestamptz`?`timestamptz`:n.endsWith(`[]`)||n.startsWith(`_`)?`array`:n===`bytea`?`bytea`:/^(public\.)?"?(geometry|geography)"?(\(.*\))?$/.test(n)?`geometry`:/multirange$/.test(n)?`multirange`:/range$/.test(n)?`range`:`text`}function v(e){let t=/^(\d{4,})-(\d\d)-(\d\d)[ T](\d\d):(\d\d):(\d\d)(?:\.(\d+))?([+-]\d\d)(?::?(\d\d))?(?::?(\d\d))?$/.exec(e);if(!t)return;let[,n,r,i,a,o,s,c,l,u,d]=t,f=(l.startsWith(`-`)?-1:1)*(Math.abs(Number(l))*3600+Number(u??0)*60+Number(d??0)),p=Number(((c??`0`)+`00`).slice(0,3)),m=Date.UTC(Number(n),Number(r)-1,Number(i),Number(a),Number(o),Number(s),p);if(!Number.isNaN(m))return new Date(m-f*1e3)}function y(e,t){let n=v(e);if(n)try{let r=new Intl.DateTimeFormat(`en-GB`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hourCycle:`h23`,timeZoneName:`short`}).formatToParts(n),i=e=>r.find(t=>t.type===e)?.value??``,a=/\.(\d+)/.exec(e)?.[1];return`${i(`year`)}-${i(`month`)}-${i(`day`)} ${i(`hour`)}:${i(`minute`)}:${i(`second`)}${a?`.${a}`:``} ${i(`timeZoneName`)}`}catch{return}}function b(e){let t=e.replace(/^\[[^\]=]*\]=/,``),n=0,r=()=>{if(t[n]!==`{`)return;n++;let e=[];if(t[n]===`}`)return n++,e;for(;;){let i=t[n];if(i===`{`){let t=r();if(!t)return;e.push(t)}else if(i===`"`){n++;let r=``;for(;n<t.length&&t[n]!==`"`;)t[n]===`\\`&&n++,r+=t[n++]??``;if(t[n]!==`"`)return;n++,e.push(r)}else{let r=``;for(;n<t.length&&t[n]!==`,`&&t[n]!==`}`;)r+=t[n++];e.push(r===`NULL`?null:r)}if(t[n]===`,`)n++;else if(t[n]===`}`)return n++,e;else return}},i=r();return i&&n===t.length?i:void 0}function x(e){let t=0,n=1,r=(e,i)=>{n=Math.max(n,i);for(let n of e)Array.isArray(n)?r(n,i+1):t++};return r(e,1),{count:t,depth:n}}function S(e){if(e===`empty`)return{empty:!0};let t=/^([[(])(.*)([\])])$/s.exec(e);if(!t)return;let n=t[2],r=[],i=``,a=!1;for(let e=0;e<n.length;e++){let t=n[e];a?t===`"`&&n[e+1]===`"`?(i+=`"`,e++):t===`\\`?i+=n[++e]??``:t===`"`?a=!1:i+=t:t===`"`?a=!0:t===`,`&&r.length===0?(r.push(i),i=``):i+=t}if(r.push(i),r.length!==2)return;let[o,s]=r;return{empty:!1,lower:o===``?null:{value:o,inclusive:t[1]===`[`},upper:s===``?null:{value:s,inclusive:t[3]===`]`}}}function ee(e){let t=/^\{(.*)\}$/s.exec(e);if(!t)return;if(t[1]===``)return[];let n=[],r=0,i=!1,a=``;for(let e of t[1])e===`"`&&(i=!i),i||e!==`[`&&e!==`(`||r++,i||e!==`]`&&e!==`)`||r--,!i&&r===0&&e===`,`?(n.push(a),a=``):a+=e;n.push(a);let o=n.map(S);return o.every(e=>e)?o:void 0}function C(e){if(e.empty)return`empty`;let{lower:t,upper:n}=e;if(!t&&!n)return`everything`;let r=t?`${t.value} ${t.inclusive?`≤`:`<`} `:``;return n?`${r}x ${n.inclusive?`≤`:`<`} ${n.value}`:`x ${t.inclusive?`≥`:`>`} ${t.value}`}function te(e){if(!/^\\x([0-9a-fA-F]{2})*$/.test(e))return;let t=e.slice(2),n=new Uint8Array(t.length/2);for(let e=0;e<n.length;e++)n[e]=parseInt(t.slice(e*2,e*2+2),16);return n}function ne(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return`\\x${t}`}var w=20971520;async function T(e,t){if(e.size>20971520)throw Error(`${e.name} is ${M(e.size)}; the limit is ${M(w)}`);if(_(t)===`bytea`)return ne(new Uint8Array(await e.arrayBuffer()));let n=await e.text();if(n.includes(`\0`))throw Error(`${e.name} is not text, so it cannot go in a ${t} column`);return n}var E=(e,t,n)=>n.every((n,r)=>e[t+r]===n);function D(e){if(E(e,0,[137,80,78,71,13,10,26,10]))return`image/png`;if(E(e,0,[255,216,255]))return`image/jpeg`;if(E(e,0,[71,73,70,56]))return`image/gif`;if(E(e,0,[82,73,70,70])&&E(e,8,[87,69,66,80]))return`image/webp`;if(E(e,0,[66,77]))return`image/bmp`}var re={"image/jpeg":`jpg`},O=e=>[...e].map(e=>e.charCodeAt(0)),ie=[{bytes:O(`%PDF-`),type:{mime:`application/pdf`,extension:`pdf`}},{bytes:[80,75,3,4],type:{mime:`application/zip`,extension:`zip`}},{bytes:[31,139,8],type:{mime:`application/gzip`,extension:`gz`}},{bytes:O(`BZh`),type:{mime:`application/x-bzip2`,extension:`bz2`}},{bytes:[253,...O(`7zXZ`),0],type:{mime:`application/x-xz`,extension:`xz`}},{bytes:[55,122,188,175,39,28],type:{mime:`application/x-7z-compressed`,extension:`7z`}},{bytes:[...O(`Rar!`),26,7],type:{mime:`application/vnd.rar`,extension:`rar`}},{at:257,bytes:O(`ustar`),type:{mime:`application/x-tar`,extension:`tar`}},{bytes:[...O(`SQLite format 3`),0],type:{mime:`application/vnd.sqlite3`,extension:`sqlite`}},{bytes:[0,0,1,0],type:{mime:`image/x-icon`,extension:`ico`}},{bytes:[...O(`II`),42,0],type:{mime:`image/tiff`,extension:`tiff`}},{bytes:[...O(`MM`),0,42],type:{mime:`image/tiff`,extension:`tiff`}},{at:4,bytes:O(`ftyp`),type:{mime:`video/mp4`,extension:`mp4`}},{bytes:O(`OggS`),type:{mime:`audio/ogg`,extension:`ogg`}},{bytes:O(`fLaC`),type:{mime:`audio/flac`,extension:`flac`}},{bytes:O(`ID3`),type:{mime:`audio/mpeg`,extension:`mp3`}},{bytes:[255,251],type:{mime:`audio/mpeg`,extension:`mp3`}},{bytes:[26,69,223,163],type:{mime:`video/webm`,extension:`webm`}},{bytes:O(`wOF2`),type:{mime:`font/woff2`,extension:`woff2`}}];function k(e){let t=D(e);if(t)return{mime:t,extension:re[t]??t.replace(`image/`,``)};if(E(e,0,O(`RIFF`))&&E(e,8,O(`WAVE`)))return{mime:`audio/wav`,extension:`wav`};let n=ie.find(({at:t=0,bytes:n})=>E(e,t,n));if(n)return n.type;if(e.length>0){let t;try{t=new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{}if(t!==void 0&&!/[\u0000-\u0008\u000e-\u001f]/.test(t))try{return JSON.parse(t),{mime:`application/json`,extension:`json`}}catch{return{mime:`text/plain`,extension:`txt`}}}return{mime:`application/octet-stream`,extension:`bin`}}function A(e,t,n=!1){return`${e}.${t.extension}${n?`.gz`:``}`}async function j(e){let t=new Blob([e]).stream().pipeThrough(new CompressionStream(`gzip`));return new Uint8Array(await new Response(t).arrayBuffer())}function M(e){return e<1024?`${e} byte${e===1?``:`s`}`:e<1048576?`${(e/1024).toFixed(1)} kB`:`${(e/1024/1024).toFixed(1)} MB`}function N(e,t=32){let n=[...e.slice(0,t)].map(e=>e.toString(16).padStart(2,`0`)).join(` `);return e.length>t?`${n} …`:n}var ae=[``,`Point`,`LineString`,`Polygon`,`MultiPoint`,`MultiLineString`,`MultiPolygon`,`GeometryCollection`];function oe(e){if(!/^([0-9a-fA-F]{2}){5,}$/.test(e)||e.length>2e6)return;let t=new Uint8Array(e.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);let n=new DataView(t.buffer),r=0,i;try{let e=()=>{let t=n.getUint8(r++)===1,a=n.getUint32(r,t);r+=4;let o=!!(a&2147483648)||(a&65535)>=1e3,s=!!(a&1073741824);if(a&536870912){let e=n.getInt32(r,t);r+=4,i??=e}let c=(a&65535)%1e3,l=()=>{let e=n.getFloat64(r,t);return r+=8,e},u=()=>{let e=l(),t=l();return o&&l(),s&&l(),[e,t]},d=()=>{let e=n.getUint32(r,t);if(r+=4,e>1e6)throw RangeError(`too many`);return e},f=()=>Array.from({length:d()},u);switch(c){case 1:return{type:`Point`,points:[u()]};case 2:return{type:`LineString`,points:f()};case 3:return{type:`Polygon`,rings:Array.from({length:d()},f)};case 4:case 5:case 6:case 7:return{type:c===7?`Collection`:`Multi`,name:ae[c],parts:Array.from({length:d()},e)};default:throw RangeError(`unknown geometry`)}},a=e();return r===t.length?{srid:i,shape:a}:void 0}catch{return}}var P=e=>e.type===`Multi`||e.type===`Collection`?e.name:e.type;function F(e){return e.type===`Point`||e.type===`LineString`?e.points:e.type===`Polygon`?e.rings.flat():e.parts.flatMap(F)}function I(e){let t=F(e);if(t.length===0)return;let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let[e,o]of t)n=Math.min(n,e),r=Math.min(r,o),i=Math.max(i,e),a=Math.max(a,o);return[n,r,i,a]}function L(e){let{shape:t,srid:n}=e,r=n?` · SRID ${n}`:``;if(t.type===`Point`)return`Point (${t.points[0].map(e=>+e.toFixed(6)).join(` `)})${r}`;let i=F(t).length;return`${P(t)}, ${i} point${i===1?``:`s`}${r}`}function se(e){if(e.srid!==4326)return;let t=I(e.shape);if(!t)return;let[n,r,i,a]=t,o=(n+i)/2,s=(r+a)/2;if(!(Math.abs(o)>180||Math.abs(s)>90))return`https://www.openstreetmap.org/?mlat=${s}&mlon=${o}#map=15/${s}/${o}`}var R=i(),z=80;function B({items:e}){return(0,R.jsx)(`ol`,{className:`list-decimal space-y-0.5 pl-5 text-xs`,children:e.map((e,t)=>Array.isArray(e)?(0,R.jsx)(`li`,{children:(0,R.jsx)(B,{items:e})},t):(0,R.jsx)(`li`,{className:e===null?`text-muted-foreground italic`:`break-all`,children:e===null?`NULL`:e},t))})}var V=(e,t,n)=>{let r=e=>`${e[0]},${-e[1]}`;if(e.type===`Point`)return e.points.map((e,r)=>(0,R.jsx)(`circle`,{cx:e[0],cy:-e[1],r:n,className:`fill-primary`,"data-point":!0},`${t}${r}`));if(e.type===`LineString`)return(0,R.jsx)(`polyline`,{points:e.points.map(r).join(` `),fill:`none`,className:`stroke-primary`,strokeWidth:2,vectorEffect:`non-scaling-stroke`},t);if(e.type===`Polygon`){let n=e.rings.map(e=>`M${e.map(r).join(`L`)}Z`).join(``);return(0,R.jsx)(`path`,{d:n,fillRule:`evenodd`,className:`fill-primary/20 stroke-primary`,strokeWidth:2,vectorEffect:`non-scaling-stroke`},t)}return e.parts.map((e,r)=>V(e,`${t}.${r}`,n))};function H({geometry:e}){let t=I(e.shape);if(!t)return(0,R.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Empty geometry.`});let[n,r,i,a]=t,o=Math.max(i-n,a-r)*.1||1;n-=o,r-=o,i+=o,a+=o;let s=se(e),c=e.shape.type===`Point`;return(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`svg`,{role:`img`,"aria-label":`${P(e.shape)} preview`,viewBox:`${n} ${-a} ${i-n} ${a-r}`,preserveAspectRatio:`xMidYMid meet`,className:`bg-muted h-48 w-72`,children:(0,R.jsx)(`g`,{children:V(e.shape,`g`,o*.2)})}),(0,R.jsxs)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:[L(e),!c&&t&&` · x ${+t[0].toFixed(6)} to ${+t[2].toFixed(6)}, y ${+t[1].toFixed(6)} to ${+t[3].toFixed(6)}`]}),s&&(0,R.jsxs)(`a`,{href:s,target:`_blank`,rel:`noreferrer`,className:`text-accent-text inline-flex items-center gap-1 text-xs hover:underline`,onClick:e=>e.stopPropagation(),children:[`Open on OpenStreetMap `,(0,R.jsx)(h,{className:`size-3`})]})]})}function U(e,t){let[n,r]=(0,g.useState)();return(0,g.useEffect)(()=>{if(!e||!t)return r(void 0);let n=URL.createObjectURL(new Blob([e],{type:t}));return r(n),()=>URL.revokeObjectURL(n)},[e,t]),n}function W({bytes:e,file:t,url:n,name:r,size:i}){let[a,o]=(0,g.useState)(!1),s=`text-accent-text inline-flex items-center gap-1 text-xs hover:underline`,c=async()=>{o(!0);try{let n=await j(e),i=URL.createObjectURL(new Blob([n],{type:`application/gzip`})),a=document.createElement(`a`);a.href=i,a.download=A(r,t,!0),a.click(),URL.revokeObjectURL(i)}finally{o(!1)}};return(0,R.jsxs)(`span`,{className:`flex items-center gap-3`,children:[(0,R.jsxs)(`a`,{href:n,download:A(r,t),onClick:e=>e.stopPropagation(),className:s,children:[(0,R.jsx)(p,{className:`size-3`}),` Download `,i,` (.`,t.extension,`)`]}),t.extension!==`gz`&&(0,R.jsxs)(`button`,{type:`button`,disabled:a,onClick:e=>{e.stopPropagation(),c()},className:s,children:[(0,R.jsx)(p,{className:`size-3`}),` `,a?`Compressing...`:`as .gz`]})]})}function G(e,t,n,r){let i=_(t),a=(0,g.useMemo)(()=>i===`bytea`?te(e):void 0,[i,e]),o=(0,g.useMemo)(()=>a?D(a):void 0,[a]),s=U(o?a:void 0,o),c=(0,g.useMemo)(()=>a?k(a):void 0,[a]),l=U(a,c?.mime),u=(0,g.useMemo)(()=>i===`geometry`?oe(e):void 0,[i,e]);if(i===`timestamptz`&&n){let t=y(e,n);if(t)return{summary:t,title:`${e} (as the database wrote it)`}}if(i===`array`){let t=b(e);if(t){let{count:n,depth:r}=x(t),i=`${n} item${n===1?``:`s`}${r>1?`, ${r} levels`:``}`;return{summary:`${e}`,title:i,detail:n>0?(0,R.jsx)(B,{items:t}):void 0}}}if(i===`range`){let t=S(e);if(t)return{summary:C(t),title:e}}if(i===`multirange`){let t=ee(e);if(t)return{summary:t.map(C).join(` or `)||`empty`,title:e}}if(i===`geometry`&&u)return{summary:L(u),title:e.length>80?`${e.slice(0,80)}…`:e,detail:(0,R.jsx)(H,{geometry:u})};if(i===`bytea`&&a){let e=M(a.length),t=a&&c&&l&&(0,R.jsx)(W,{bytes:a,file:c,url:l,name:r,size:e});return o&&s?{summary:`${o.replace(`image/`,``).toUpperCase()} image, ${e}`,thumbnail:s,detail:(0,R.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,R.jsx)(`img`,{src:s,alt:`${o} image, ${e}`,className:`bg-muted max-h-64 max-w-72 object-contain`}),t]})}:{summary:`${e}: ${N(a,12)}`,title:`${e}`,detail:(0,R.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,R.jsx)(`pre`,{className:`max-w-96 text-xs break-all whitespace-pre-wrap`,children:N(a,256)}),t]})}}let d=e.length>z||e.includes(`
2
2
  `);return{summary:e,title:d?void 0:e,detail:d?(0,R.jsx)(`span`,{className:`block max-w-[32rem] text-sm break-words whitespace-pre-wrap`,children:e}):void 0}}function ce({value:e,type:t,zone:n,name:r=`download`,open:i=!1,children:a}){let o=G(e,t,n,r),[s,c]=(0,g.useState)(!1),u=i||s;return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`span`,{className:`flex max-w-80 items-center gap-1`,children:[o.thumbnail&&(0,R.jsx)(`img`,{src:o.thumbnail,alt:``,className:`size-5 shrink-0 object-cover`}),(0,R.jsx)(`span`,{className:`block min-w-0 truncate`,title:o.title??e,children:a??o.summary}),o.detail&&!i&&(0,R.jsx)(`button`,{type:`button`,"aria-expanded":s,"aria-label":s?`Show less`:`Show more`,title:s?`Show less`:`Show more`,onClick:e=>{e.stopPropagation(),c(!s)},className:`text-muted-foreground hover:text-foreground shrink-0`,children:s?(0,R.jsx)(l,{className:`size-3.5`}):(0,R.jsx)(d,{className:`size-3.5`})})]}),u&&o.detail&&(0,R.jsx)(`div`,{className:`mt-1 whitespace-normal`,children:o.detail})]})}var K={csv:{label:`CSV`,extension:`csv`,mime:`text/csv`},json:{label:`JSON`,extension:`json`,mime:`application/json`},sql:{label:`SQL INSERTs`,extension:`sql`,mime:`application/sql`}},q=e=>/[",\r\n]/.test(e)?`"${e.replaceAll(`"`,`""`)}"`:e;function le({columns:e,rows:t}){return[e.map(e=>q(e.name)).join(`,`),...t.map(e=>e.map(e=>e===null?``:q(e)).join(`,`))].map(e=>`${e}\r\n`).join(``)}var ue=new Set([`smallint`,`integer`,`real`,`double precision`,`oid`]);function de(e,t){if(e===null)return null;if(ue.has(t)){let t=Number(e);return Number.isFinite(t)?t:e}if(t===`boolean`)return e===`t`;if(t===`json`||t===`jsonb`)try{return JSON.parse(e)}catch{return e}return e}function fe({columns:e,rows:t}){let n=t.map(t=>Object.fromEntries(e.map((e,n)=>[e.name,de(t[n]??null,e.type)])));return`${JSON.stringify(n,null,2)}\n`}var J=e=>`"${e.replaceAll(`"`,`""`)}"`,pe=e=>e.split(`.`).map(e=>J(e.replace(/^"(.*)"$/,`$1`))).join(`.`),me=/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/,he=/^(smallint|integer|bigint|numeric|real|double precision|oid)/;function ge(e,t){return e===null?`NULL`:he.test(t)&&me.test(e)?e:t===`boolean`?e===`t`?`true`:`false`:`'${e.replaceAll(`'`,`''`)}'`}var Y=100;function X({columns:e,rows:t},n){if(t.length===0)return`-- no rows
3
3
  `;let r=`INSERT INTO ${pe(n)} (${e.map(e=>J(e.name)).join(`, `)}) VALUES\n`,i=[];for(let n=0;n<t.length;n+=Y){let a=t.slice(n,n+Y).map(t=>` (${e.map((e,n)=>ge(t[n]??null,e.type)).join(`, `)})`);i.push(`${r}${a.join(`,
4
4
  `)};\n`)}return i.join(`
@@ -10,14 +10,14 @@
10
10
  } catch {}
11
11
  </script>
12
12
  <title>psql-explorer</title>
13
- <script type="module" crossorigin src="/assets/index-CDcnUacl.js"></script>
14
- <link rel="modulepreload" crossorigin href="/assets/route-DO6IZ7of.js">
15
- <link rel="modulepreload" crossorigin href="/assets/code-xml-CXkpHeU9.js">
16
- <link rel="modulepreload" crossorigin href="/assets/button-ClA70PLR.js">
17
- <link rel="modulepreload" crossorigin href="/assets/copy-CCXzeW-s.js">
18
- <link rel="modulepreload" crossorigin href="/assets/zone-D9dXk8tn.js">
19
- <link rel="modulepreload" crossorigin href="/assets/table-DfMz2f8M.js">
20
- <link rel="modulepreload" crossorigin href="/assets/graph-link-OCo_s0zO.js">
13
+ <script type="module" crossorigin src="/assets/index-CpHnjRLv.js"></script>
14
+ <link rel="modulepreload" crossorigin href="/assets/route-7eu-iAqD.js">
15
+ <link rel="modulepreload" crossorigin href="/assets/code-xml-CPEjNFOw.js">
16
+ <link rel="modulepreload" crossorigin href="/assets/button-BiFx4Lyw.js">
17
+ <link rel="modulepreload" crossorigin href="/assets/copy-C2N9tUYJ.js">
18
+ <link rel="modulepreload" crossorigin href="/assets/zone-CHDOrDBF.js">
19
+ <link rel="modulepreload" crossorigin href="/assets/table-Drc_n1gF.js">
20
+ <link rel="modulepreload" crossorigin href="/assets/graph-link-C8P9s_0W.js">
21
21
  <link rel="stylesheet" crossorigin href="/assets/index-OzJqnJWG.css">
22
22
  </head>
23
23
  <body>