planche 0.8.11 → 0.8.13

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 (61) hide show
  1. package/README.md +3 -3
  2. package/app/assets/{BoonIczC.js → 8RmjiG1u.js} +1 -1
  3. package/app/assets/{DDmrJxdV.js → 9kM6GVHV.js} +1 -1
  4. package/app/assets/{BkIkgVK5.js → B1pia_Rg.js} +1 -1
  5. package/app/assets/{dqPw_4zA.js → B2csuorb.js} +1 -1
  6. package/app/assets/{DC8XCjJ3.js → BCmzDvBt.js} +1 -1
  7. package/app/assets/{dMlgA_r1.js → BO_H_8D-.js} +1 -1
  8. package/app/assets/{DY8yZMtt.js → BRc4Nt6e.js} +1 -1
  9. package/app/assets/{DiCNtfbc.js → BW4K9UH-.js} +1 -1
  10. package/app/assets/{Bww-OO8A.js → Bajzqc8D.js} +1 -1
  11. package/app/assets/{Cg4DfVr4.js → BgkATqP8.js} +1 -1
  12. package/app/assets/{BKoh-tKR.js → Bhquh17w.js} +3 -3
  13. package/app/assets/{DCuKrXll.js → Bjm-okwb.js} +1 -1
  14. package/app/assets/{Cb_gZQwZ.js → Bs-p2SdN.js} +1 -1
  15. package/app/assets/{1XwwL8xu.js → C0bzfYFC.js} +1 -1
  16. package/app/assets/{G6EbcZKg.js → CEtGUZGE.js} +1 -1
  17. package/app/assets/{CaoceGhm.js → CF6jyexg.js} +1 -1
  18. package/app/assets/{CXb-qrUO.js → CMoC9sLj.js} +1 -1
  19. package/app/assets/{74sUdCiu.js → COfwwXGO.js} +1 -1
  20. package/app/assets/{Dd9quIZg.js → CS2mpWDL.js} +1 -1
  21. package/app/assets/{Bjbi6j5C.js → CUK2WAdf.js} +1 -1
  22. package/app/assets/{B02VTWSP.js → CVpOAP2j.js} +1 -1
  23. package/app/assets/{DjDcAaBy.js → CVpzA8TC.js} +1 -1
  24. package/app/assets/CZoj-eMm.js +1 -0
  25. package/app/assets/{BV4aY7xt.js → CbmIWIww.js} +1 -1
  26. package/app/assets/{DYKigfsA.js → CeXMO4BR.js} +1 -1
  27. package/app/assets/{DL6u_OmT.js → CiFkP-9S.js} +1 -1
  28. package/app/assets/{DBHRzz66.js → CjoKIEBz.js} +1 -1
  29. package/app/assets/{FO_fYT6n.js → CpSudzcZ.js} +1 -1
  30. package/app/assets/{muV45VDO.js → CqK9ewb_.js} +1 -1
  31. package/app/assets/{DtKWPQKC.js → CrT26gRf.js} +1 -1
  32. package/app/assets/{BAZqI8g_.js → D0jMUNSI.js} +1 -1
  33. package/app/assets/{DP94Ond0.js → D6kbK-ng.js} +1 -1
  34. package/app/assets/{B49XtolG.js → DEEGN6UG.js} +1 -1
  35. package/app/assets/{BrxJJ0qg.js → DIJgEIiP.js} +1 -1
  36. package/app/assets/{Ct8S8lM5.js → DMRY-PmY.js} +1 -1
  37. package/app/assets/DPdwSUSw.js +1 -0
  38. package/app/assets/{DOiUgfE9.js → DSmKDd5u.js} +1 -1
  39. package/app/assets/{DXi92TWa.js → DTDWV2fP.js} +1 -1
  40. package/app/assets/{D6kPbvGu.js → DW8BZVdB.js} +1 -1
  41. package/app/assets/{DF-Cqqnq.js → DWMVPRon.js} +1 -1
  42. package/app/assets/{CYMzEa4j.js → DbqogdCK.js} +1 -1
  43. package/app/assets/{D-CUfQgE.js → Dc12Sye0.js} +1 -1
  44. package/app/assets/{BaO3ulMH.js → DkPnEF-y.js} +1 -1
  45. package/app/assets/{CFY8MOYy.js → DzVnJu74.js} +1 -1
  46. package/app/assets/{Bcc7p7-f.js → OjAiMU9J.js} +2 -2
  47. package/app/assets/{B3rETkrt.js → SFsWRs4-.js} +1 -1
  48. package/app/assets/{CpZOnYKF.js → bgQ-QVd7.js} +1 -1
  49. package/app/assets/{COQ4mwLg.js → fI8KJgQa.js} +1 -1
  50. package/app/assets/{CgVpdrxb.js → hrOpaTVU.js} +1 -1
  51. package/app/assets/{C0O3rJzW.js → pjlgs2cl.js} +1 -1
  52. package/app/assets/{Dht5Mpyb.js → pneb1la9.js} +1 -1
  53. package/app/assets/{C8Rd1hEG.js → qXWuX5B-.js} +1 -1
  54. package/app/assets/{B5mLj_uo.js → useqs8Jk.js} +1 -1
  55. package/app/assets/{dNkI1CY7.js → y4cmNs6-.js} +1 -1
  56. package/app/assets/{CGUOv71O.js → y664aOTm.js} +1 -1
  57. package/app/index.html +18 -18
  58. package/dist/index.js +3 -2
  59. package/package.json +1 -1
  60. package/app/assets/3z4eHGF-.js +0 -1
  61. package/app/assets/CdUXbAKF.js +0 -1
@@ -1 +1 @@
1
- import{r as e}from"./hePW80VL.js";import{h as t,n,t as r}from"./BkIkgVK5.js";import{l as i,m as a,t as o}from"./C0O3rJzW.js";import{t as s}from"./DC8XCjJ3.js";import{a as c}from"./Dd9quIZg.js";import{n as l}from"./Dht5Mpyb.js";import{l as u,m as d}from"./Bcc7p7-f.js";import{U as f,W as p,c as m,l as h}from"./BKoh-tKR.js";import{a as g,i as _,n as v,o as y,t as b}from"./Cg4DfVr4.js";var x=e(t(),1),S=i();function C(){let{t:e}=a(),{activeDialog:t,closeDialog:i}=n(),C=r(`copy-database`),w=t===`copy-database`,T=C?.database??``,[E,D]=(0,x.useState)(``),[O,k]=(0,x.useState)(`structure_data`),[A,j]=(0,x.useState)(null),[M,N]=(0,x.useState)(null);function P(e){e||(i(),N(null),j(null),D(``),k(`structure_data`))}async function F(){let t=s.getState().activeConnectionId,n=E.trim();if(!t||!n||!T)return;N(null);let r=l(t),i=s.getState().activeConnections.find(e=>e.id===t);if(i?.serverConnectionId)try{j(e(`database.copy.creating`,{database:n})),await u(t,r.getQuery(`CREATE_DATABASE`,n,`utf8mb4`,`utf8mb4_general_ci`));let a=c(i.serverConnectionId),o=await r.introspect.listTables(a,T);for(let[r,i]of o.entries()){j(e(`database.copy.copying`,{table:i.name,index:r+1,total:o.length}));let a={connectionId:t,database:T,table:i.name},s={connectionId:t,database:n,table:i.name},c=await f(a,s);await p({source:a,target:s,mode:O,onConflict:`abort`,createSql:l(t).ddl.createTable(c)})}await d(t),P(!1)}catch(e){N(e instanceof Error?e.message:String(e))}finally{j(null)}}return(0,S.jsx)(b,{open:w,onOpenChange:P,children:(0,S.jsxs)(v,{className:`sm:max-w-[450px]`,children:[(0,S.jsx)(g,{children:(0,S.jsx)(y,{children:e(`database.copy.title`)})}),(0,S.jsxs)(`div`,{className:`space-y-4`,children:[(0,S.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,S.jsx)(m,{children:e(`database.copy.source`)}),(0,S.jsx)(h,{value:T,disabled:!0})]}),(0,S.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,S.jsx)(m,{htmlFor:`target-db-name`,children:e(`database.copy.target`)}),(0,S.jsx)(h,{id:`target-db-name`,value:E,onChange:e=>D(e.target.value),placeholder:e(`database.copy.targetPlaceholder`)})]}),(0,S.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,S.jsx)(m,{children:e(`database.copy.options`)}),(0,S.jsxs)(`div`,{className:`space-y-2`,children:[(0,S.jsxs)(`label`,{className:`flex items-center gap-2 text-sm cursor-pointer`,children:[(0,S.jsx)(`input`,{type:`radio`,name:`copy-option`,value:`structure_data`,checked:O===`structure_data`,onChange:()=>k(`structure_data`)}),e(`database.copy.structureAndData`)]}),(0,S.jsxs)(`label`,{className:`flex items-center gap-2 text-sm cursor-pointer`,children:[(0,S.jsx)(`input`,{type:`radio`,name:`copy-option`,value:`structure_only`,checked:O===`structure_only`,onChange:()=>k(`structure_only`)}),e(`database.copy.structureOnly`)]})]})]})]}),A&&(0,S.jsx)(`p`,{className:`px-1 text-xs text-muted-foreground`,children:A}),M&&(0,S.jsx)(`p`,{className:`px-1 text-xs text-destructive leading-relaxed`,children:M}),(0,S.jsxs)(_,{children:[(0,S.jsx)(o,{variant:`outline`,onClick:()=>P(!1),children:e(`database.copy.cancel`)}),(0,S.jsx)(o,{onClick:()=>void F(),disabled:!E.trim()||A!==null,children:e(`database.copy.copy`)})]})]})})}export{C as CopyDatabaseDialog};
1
+ import{r as e}from"./hePW80VL.js";import{h as t,n,t as r}from"./B1pia_Rg.js";import{l as i,m as a,t as o}from"./pjlgs2cl.js";import{t as s}from"./BCmzDvBt.js";import{a as c}from"./CS2mpWDL.js";import{n as l}from"./pneb1la9.js";import{l as u,m as d}from"./OjAiMU9J.js";import{U as f,W as p,c as m,l as h}from"./Bhquh17w.js";import{a as g,i as _,n as v,o as y,t as b}from"./BgkATqP8.js";var x=e(t(),1),S=i();function C(){let{t:e}=a(),{activeDialog:t,closeDialog:i}=n(),C=r(`copy-database`),w=t===`copy-database`,T=C?.database??``,[E,D]=(0,x.useState)(``),[O,k]=(0,x.useState)(`structure_data`),[A,j]=(0,x.useState)(null),[M,N]=(0,x.useState)(null);function P(e){e||(i(),N(null),j(null),D(``),k(`structure_data`))}async function F(){let t=s.getState().activeConnectionId,n=E.trim();if(!t||!n||!T)return;N(null);let r=l(t),i=s.getState().activeConnections.find(e=>e.id===t);if(i?.serverConnectionId)try{j(e(`database.copy.creating`,{database:n})),await u(t,r.getQuery(`CREATE_DATABASE`,n,`utf8mb4`,`utf8mb4_general_ci`));let a=c(i.serverConnectionId),o=await r.introspect.listTables(a,T);for(let[r,i]of o.entries()){j(e(`database.copy.copying`,{table:i.name,index:r+1,total:o.length}));let a={connectionId:t,database:T,table:i.name},s={connectionId:t,database:n,table:i.name},c=await f(a,s);await p({source:a,target:s,mode:O,onConflict:`abort`,createSql:l(t).ddl.createTable(c)})}await d(t),P(!1)}catch(e){N(e instanceof Error?e.message:String(e))}finally{j(null)}}return(0,S.jsx)(b,{open:w,onOpenChange:P,children:(0,S.jsxs)(v,{className:`sm:max-w-[450px]`,children:[(0,S.jsx)(g,{children:(0,S.jsx)(y,{children:e(`database.copy.title`)})}),(0,S.jsxs)(`div`,{className:`space-y-4`,children:[(0,S.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,S.jsx)(m,{children:e(`database.copy.source`)}),(0,S.jsx)(h,{value:T,disabled:!0})]}),(0,S.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,S.jsx)(m,{htmlFor:`target-db-name`,children:e(`database.copy.target`)}),(0,S.jsx)(h,{id:`target-db-name`,value:E,onChange:e=>D(e.target.value),placeholder:e(`database.copy.targetPlaceholder`)})]}),(0,S.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,S.jsx)(m,{children:e(`database.copy.options`)}),(0,S.jsxs)(`div`,{className:`space-y-2`,children:[(0,S.jsxs)(`label`,{className:`flex items-center gap-2 text-sm cursor-pointer`,children:[(0,S.jsx)(`input`,{type:`radio`,name:`copy-option`,value:`structure_data`,checked:O===`structure_data`,onChange:()=>k(`structure_data`)}),e(`database.copy.structureAndData`)]}),(0,S.jsxs)(`label`,{className:`flex items-center gap-2 text-sm cursor-pointer`,children:[(0,S.jsx)(`input`,{type:`radio`,name:`copy-option`,value:`structure_only`,checked:O===`structure_only`,onChange:()=>k(`structure_only`)}),e(`database.copy.structureOnly`)]})]})]})]}),A&&(0,S.jsx)(`p`,{className:`px-1 text-xs text-muted-foreground`,children:A}),M&&(0,S.jsx)(`p`,{className:`px-1 text-xs text-destructive leading-relaxed`,children:M}),(0,S.jsxs)(_,{children:[(0,S.jsx)(o,{variant:`outline`,onClick:()=>P(!1),children:e(`database.copy.cancel`)}),(0,S.jsx)(o,{onClick:()=>void F(),disabled:!E.trim()||A!==null,children:e(`database.copy.copy`)})]})]})})}export{C as CopyDatabaseDialog};
@@ -0,0 +1 @@
1
+ import{c as e}from"./BCmzDvBt.js";import{y as t}from"./DEEGN6UG.js";function n(n){t(n),e(n)}export{n as t};
@@ -1 +1 @@
1
- import{n as e}from"./BkIkgVK5.js";import{l as t,m as n,t as r}from"./C0O3rJzW.js";import{a as i,i as a,n as o,r as s,t as c}from"./DL6u_OmT.js";import{n as l}from"./DP94Ond0.js";import{c as u,l as d}from"./BKoh-tKR.js";import{a as f,i as p,n as m,o as h,r as g,t as _}from"./Cg4DfVr4.js";import{t as v}from"./BaO3ulMH.js";var y=t();function b(){let t=e(e=>e.activeDialog),b=e(e=>e.closeDialog),x=l(),S=x.update,{t:C}=n();return(0,y.jsx)(_,{open:t===`query-settings`,onOpenChange:e=>{e||b()},children:(0,y.jsxs)(m,{className:`sm:max-w-[560px]`,children:[(0,y.jsxs)(f,{children:[(0,y.jsx)(h,{children:C(`settings.query.title`)}),(0,y.jsx)(g,{children:C(`settings.query.description`)})]}),(0,y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,y.jsx)(v,{id:`s-dryrun`,checked:x.previewAffectedRows,onChange:e=>S({previewAffectedRows:e}),pro:!0,label:`Dry run`,hint:`Before an UPDATE or DELETE runs, read its WHERE (joins included) as a SELECT and show how many rows it would change, with a sample of them, to confirm.`}),(0,y.jsxs)(`div`,{className:`grid grid-cols-[1fr_140px] items-center gap-3 rounded-md border p-3`,children:[(0,y.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,y.jsx)(u,{htmlFor:`s-limit`,className:`text-sm font-medium`,children:`Result row limit`}),(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`LIMIT appended to SELECTs that have none. 0 disables.`})]}),(0,y.jsx)(d,{id:`s-limit`,type:`number`,min:0,step:100,value:x.resultRowLimit,onChange:e=>S({resultRowLimit:Math.max(0,Number(e.target.value)||0)})})]}),(0,y.jsxs)(`div`,{className:`grid grid-cols-[1fr_200px] items-center gap-3 rounded-md border p-3`,children:[(0,y.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,y.jsx)(`span`,{className:`text-sm font-medium`,children:`F9 / Run button executes`}),(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Ctrl+Enter always runs the statement at the cursor; Ctrl+Shift+Enter the whole script.`})]}),(0,y.jsxs)(c,{value:x.executeScope,onValueChange:e=>S({executeScope:e}),children:[(0,y.jsx)(a,{children:(0,y.jsx)(i,{})}),(0,y.jsxs)(o,{children:[(0,y.jsx)(s,{value:`script`,children:`Whole script`}),(0,y.jsx)(s,{value:`statement`,children:`Statement at cursor`})]})]})]})]}),(0,y.jsx)(p,{children:(0,y.jsx)(r,{onClick:b,children:C(`settings.done`)})})]})})}export{b as QuerySettingsDialog};
1
+ import{n as e}from"./B1pia_Rg.js";import{l as t,m as n,t as r}from"./pjlgs2cl.js";import{a as i,i as a,n as o,r as s,t as c}from"./CiFkP-9S.js";import{n as l}from"./D6kbK-ng.js";import{c as u,l as d}from"./Bhquh17w.js";import{a as f,i as p,n as m,o as h,r as g,t as _}from"./BgkATqP8.js";import{t as v}from"./DkPnEF-y.js";var y=t();function b(){let t=e(e=>e.activeDialog),b=e(e=>e.closeDialog),x=l(),S=x.update,{t:C}=n();return(0,y.jsx)(_,{open:t===`query-settings`,onOpenChange:e=>{e||b()},children:(0,y.jsxs)(m,{className:`sm:max-w-[560px]`,children:[(0,y.jsxs)(f,{children:[(0,y.jsx)(h,{children:C(`settings.query.title`)}),(0,y.jsx)(g,{children:C(`settings.query.description`)})]}),(0,y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,y.jsx)(v,{id:`s-dryrun`,checked:x.previewAffectedRows,onChange:e=>S({previewAffectedRows:e}),pro:!0,label:`Dry run`,hint:`Before an UPDATE or DELETE runs, read its WHERE (joins included) as a SELECT and show how many rows it would change, with a sample of them, to confirm.`}),(0,y.jsxs)(`div`,{className:`grid grid-cols-[1fr_140px] items-center gap-3 rounded-md border p-3`,children:[(0,y.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,y.jsx)(u,{htmlFor:`s-limit`,className:`text-sm font-medium`,children:`Result row limit`}),(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`LIMIT appended to SELECTs that have none. 0 disables.`})]}),(0,y.jsx)(d,{id:`s-limit`,type:`number`,min:0,step:100,value:x.resultRowLimit,onChange:e=>S({resultRowLimit:Math.max(0,Number(e.target.value)||0)})})]}),(0,y.jsxs)(`div`,{className:`grid grid-cols-[1fr_200px] items-center gap-3 rounded-md border p-3`,children:[(0,y.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,y.jsx)(`span`,{className:`text-sm font-medium`,children:`F9 / Run button executes`}),(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Ctrl+Enter always runs the statement at the cursor; Ctrl+Shift+Enter the whole script.`})]}),(0,y.jsxs)(c,{value:x.executeScope,onValueChange:e=>S({executeScope:e}),children:[(0,y.jsx)(a,{children:(0,y.jsx)(i,{})}),(0,y.jsxs)(o,{children:[(0,y.jsx)(s,{value:`script`,children:`Whole script`}),(0,y.jsx)(s,{value:`statement`,children:`Statement at cursor`})]})]})]})]}),(0,y.jsx)(p,{children:(0,y.jsx)(r,{onClick:b,children:C(`settings.done`)})})]})})}export{b as QuerySettingsDialog};
@@ -1,2 +1,2 @@
1
- import{r as e}from"./hePW80VL.js";import{h as t,n,t as r}from"./BkIkgVK5.js";import{l as i,m as a,t as o}from"./C0O3rJzW.js";import{a as s,i as c,n as l,r as u,t as d}from"./DL6u_OmT.js";import{t as f}from"./DC8XCjJ3.js";import{a as p}from"./Dd9quIZg.js";import{n as m}from"./Dht5Mpyb.js";import{l as h,p as g}from"./Bcc7p7-f.js";import{$t as _,C as v,D as y,E as b,G as ee,O as te,S as x,T as S,Z as C,b as w,c as T,ct as ne,k as E,l as D,lt as O,st as k,v as A,x as j,y as M}from"./BKoh-tKR.js";import{a as N,i as P,n as F,o as I,t as L}from"./Cg4DfVr4.js";var R=e(t(),1);function z(){return{id:crypto.randomUUID(),field:``,type:`varchar`,length:``,defaultValue:``,pk:!1,notNull:!1,unsigned:!1,autoIncrement:!1,zerofill:!1,comment:``}}function B(){return{id:crypto.randomUUID(),name:``,type:`INDEX`,columns:[]}}function re(){return{engine:`InnoDB`,charset:`utf8mb4`,collation:`utf8mb4_general_ci`,autoIncrement:``,comment:``}}function ie(e,t,n,r,i){return{database:e,name:t,columns:n.map(e=>({name:e.field,type:e.type,length:e.length,defaultValue:e.defaultValue,primaryKey:e.pk,notNull:e.notNull,unsigned:e.unsigned,autoIncrement:e.autoIncrement,zerofill:e.zerofill,comment:e.comment})),indexes:r.map(e=>({name:e.name,type:e.type,columns:[...e.columns]})),options:{...i}}}var V=i(),H=`w-auto min-w-full [&_td]:bg-muted [&_td]:border-r [&_td]:border-border/60 [&_td:last-child]:border-r-0 [&_td]:p-0 [&_td]:h-8 [&_tr:nth-child(even)_td]:bg-muted/60 [&_tr:focus-within_td]:bg-primary/5`,U=`sticky top-0 z-10 bg-catppuccin-crust shadow-[inset_0_-1px_0_var(--border)] [&_th]:h-8 [&_th]:bg-catppuccin-crust [&_th]:font-semibold [&_th]:text-foreground [&_th]:uppercase [&_th]:tracking-wide [&_th]:text-[11px]`,W=`h-8 w-full min-w-0 rounded-none border-0 bg-transparent px-2 text-xs shadow-none ring-0 focus-visible:bg-primary/10 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary dark:bg-transparent`,G=`h-8 w-full min-w-0 rounded-none border-0 bg-transparent px-2 text-xs shadow-none focus-visible:bg-primary/10 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary data-[state=open]:bg-primary/10 dark:bg-transparent dark:hover:bg-transparent`;function ae({columns:e,onChange:t}){let{t:n}=a(),r=k().getDataTypes(),i=(0,R.useCallback)((n,r,i)=>{t(e.map(e=>e.id===n?{...e,[r]:i}:e))},[e,t]);function f(){t([...e,z()])}function p(){e.length>0&&t(e.slice(0,-1))}return(0,V.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,V.jsx)(O,{className:`flex-1`,children:(0,V.jsxs)(A,{className:H,children:[(0,V.jsx)(x,{className:U,children:(0,V.jsxs)(v,{children:[(0,V.jsx)(j,{className:`w-[120px]`,children:n(`table.schema.colField`)}),(0,V.jsx)(j,{className:`w-[120px]`,children:n(`table.schema.colType`)}),(0,V.jsx)(j,{className:`w-[60px]`,children:n(`table.schema.colLength`)}),(0,V.jsx)(j,{className:`w-[100px]`,children:n(`table.schema.colDefault`)}),(0,V.jsx)(j,{className:`w-[40px]`,children:n(`table.schema.colPk`)}),(0,V.jsx)(j,{className:`w-[60px]`,children:n(`table.schema.colNotNull`)}),(0,V.jsx)(j,{className:`w-[60px]`,children:n(`table.schema.colUnsigned`)}),(0,V.jsx)(j,{className:`w-[70px]`,children:n(`table.schema.colAutoIncrement`)}),(0,V.jsx)(j,{className:`w-[60px]`,children:n(`table.schema.colZerofill`)}),(0,V.jsx)(j,{children:n(`table.schema.colComment`)})]})}),(0,V.jsx)(M,{children:e.length===0?(0,V.jsx)(v,{children:(0,V.jsx)(w,{colSpan:10,className:`text-center text-muted-foreground`,children:n(`table.schema.empty`)})}):e.map(e=>(0,V.jsxs)(v,{children:[(0,V.jsx)(w,{children:(0,V.jsx)(D,{className:W,value:e.field,onChange:t=>i(e.id,`field`,t.target.value),placeholder:`column_name`})}),(0,V.jsx)(w,{children:(0,V.jsxs)(d,{value:e.type,onValueChange:t=>i(e.id,`type`,t),children:[(0,V.jsx)(c,{className:G,children:(0,V.jsx)(s,{})}),(0,V.jsx)(l,{children:r.map(e=>(0,V.jsx)(u,{value:e,children:e},e))})]})}),(0,V.jsx)(w,{children:(0,V.jsx)(D,{className:W,value:e.length,onChange:t=>i(e.id,`length`,t.target.value)})}),(0,V.jsx)(w,{children:(0,V.jsx)(D,{className:W,value:e.defaultValue,onChange:t=>i(e.id,`defaultValue`,t.target.value),placeholder:`NULL`})}),(0,V.jsx)(w,{className:`text-center`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:e.pk,onChange:t=>i(e.id,`pk`,t.target.checked)})}),(0,V.jsx)(w,{className:`text-center`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:e.notNull,onChange:t=>i(e.id,`notNull`,t.target.checked)})}),(0,V.jsx)(w,{className:`text-center`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:e.unsigned,onChange:t=>i(e.id,`unsigned`,t.target.checked)})}),(0,V.jsx)(w,{className:`text-center`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:e.autoIncrement,onChange:t=>i(e.id,`autoIncrement`,t.target.checked)})}),(0,V.jsx)(w,{className:`text-center`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:e.zerofill,onChange:t=>i(e.id,`zerofill`,t.target.checked)})}),(0,V.jsx)(w,{children:(0,V.jsx)(D,{className:W,value:e.comment,onChange:t=>i(e.id,`comment`,t.target.value)})})]},e.id))})]})}),(0,V.jsxs)(`div`,{className:`flex gap-2 p-2 border-t`,children:[(0,V.jsx)(o,{size:`sm`,variant:`outline`,onClick:f,children:n(`table.schema.add`)}),(0,V.jsx)(o,{size:`sm`,variant:`outline`,onClick:p,disabled:e.length===0,children:n(`table.schema.remove`)})]})]})}var K=[`PRIMARY`,`UNIQUE`,`INDEX`,`FULLTEXT`];function q({open:e,index:t,availableColumns:n,onSave:r,onClose:i}){let{t:f}=a(),[p,m]=(0,R.useState)(t.name),[h,g]=(0,R.useState)(t.type),[_,v]=(0,R.useState)(t.columns);function y(e){v(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}function b(){r({id:t.id,name:h===`PRIMARY`?`PRIMARY`:p,type:h,columns:_})}return(0,V.jsx)(L,{open:e,onOpenChange:e=>{e||i()},children:(0,V.jsxs)(F,{className:`sm:max-w-[500px]`,children:[(0,V.jsx)(N,{children:(0,V.jsx)(I,{children:t.name?f(`table.index.editTitle`):f(`table.index.addTitle`)})}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`idx-name`,children:f(`table.index.name`)}),(0,V.jsx)(D,{id:`idx-name`,value:h===`PRIMARY`?`PRIMARY`:p,onChange:e=>m(e.target.value),disabled:h===`PRIMARY`,placeholder:f(`table.index.namePlaceholder`)})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`idx-type`,children:f(`table.index.type`)}),(0,V.jsxs)(d,{value:h,onValueChange:e=>g(e),children:[(0,V.jsx)(c,{id:`idx-type`,className:`w-full`,children:(0,V.jsx)(s,{})}),(0,V.jsx)(l,{children:K.map(e=>(0,V.jsx)(u,{value:e,children:e},e))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{children:f(`table.index.columns`)}),(0,V.jsx)(`div`,{className:`border rounded-md p-2 max-h-[200px] overflow-y-auto space-y-1`,children:n.length===0?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:f(`table.index.noColumns`)}):n.map(e=>(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-sm cursor-pointer hover:bg-muted/50 rounded px-1 py-0.5`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:_.includes(e.field),onChange:()=>y(e.field)}),(0,V.jsx)(`span`,{children:e.field||f(`table.index.unnamed`)}),(0,V.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,e.type,`)`]})]},e.id))})]})]}),(0,V.jsxs)(P,{children:[(0,V.jsx)(o,{variant:`outline`,onClick:i,children:f(`table.index.cancel`)}),(0,V.jsx)(o,{onClick:b,disabled:_.length===0,children:f(`table.index.ok`)})]})]})})}function oe({indexes:e,availableColumns:t,onChange:n}){let{t:r}=a(),[i,s]=(0,R.useState)(null),[c,l]=(0,R.useState)(!1);function u(){let e=B();s(e),l(!0)}function d(e){s({...e}),l(!0)}function f(){e.length>0&&n(e.slice(0,-1))}function p(t){e.find(e=>e.id===t.id)?n(e.map(e=>e.id===t.id?t:e)):n([...e,t]),l(!1),s(null)}function m(){l(!1),s(null)}return(0,V.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,V.jsx)(O,{className:`flex-1`,children:(0,V.jsxs)(A,{className:H+` [&_td]:px-2`,children:[(0,V.jsx)(x,{className:U,children:(0,V.jsxs)(v,{children:[(0,V.jsx)(j,{className:`w-[150px]`,children:r(`table.indexes.colName`)}),(0,V.jsx)(j,{className:`w-[120px]`,children:r(`table.indexes.colType`)}),(0,V.jsx)(j,{children:r(`table.indexes.colColumns`)})]})}),(0,V.jsx)(M,{children:e.length===0?(0,V.jsx)(v,{children:(0,V.jsx)(w,{colSpan:3,className:`text-center text-muted-foreground`,children:r(`table.indexes.empty`)})}):e.map(e=>(0,V.jsxs)(v,{className:`cursor-pointer`,onDoubleClick:()=>d(e),children:[(0,V.jsx)(w,{children:e.name}),(0,V.jsx)(w,{children:e.type}),(0,V.jsx)(w,{children:e.columns.join(`, `)})]},e.id))})]})}),(0,V.jsxs)(`div`,{className:`flex gap-2 p-2 border-t`,children:[(0,V.jsx)(o,{size:`sm`,variant:`outline`,onClick:u,children:r(`table.indexes.add`)}),(0,V.jsx)(o,{size:`sm`,variant:`outline`,onClick:f,disabled:e.length===0,children:r(`table.indexes.remove`)})]}),i&&(0,V.jsx)(q,{open:c,index:i,availableColumns:t,onSave:p,onClose:m})]})}var J=[`InnoDB`,`MyISAM`,`MEMORY`,`CSV`,`ARCHIVE`,`BLACKHOLE`,`MRG_MYISAM`,`FEDERATED`,`PERFORMANCE_SCHEMA`],Y=[`utf8mb4`,`utf8`,`latin1`,`ascii`,`binary`,`cp1251`,`euckr`,`gb2312`,`gbk`,`sjis`,`ucs2`,`utf16`,`utf32`],X={utf8mb4:[`utf8mb4_general_ci`,`utf8mb4_unicode_ci`,`utf8mb4_bin`,`utf8mb4_0900_ai_ci`],utf8:[`utf8_general_ci`,`utf8_unicode_ci`,`utf8_bin`],latin1:[`latin1_swedish_ci`,`latin1_general_ci`,`latin1_bin`],ascii:[`ascii_general_ci`,`ascii_bin`],binary:[`binary`],cp1251:[`cp1251_general_ci`,`cp1251_bin`],euckr:[`euckr_korean_ci`,`euckr_bin`],gb2312:[`gb2312_chinese_ci`,`gb2312_bin`],gbk:[`gbk_chinese_ci`,`gbk_bin`],sjis:[`sjis_japanese_ci`,`sjis_bin`],ucs2:[`ucs2_general_ci`,`ucs2_unicode_ci`,`ucs2_bin`],utf16:[`utf16_general_ci`,`utf16_unicode_ci`,`utf16_bin`],utf32:[`utf32_general_ci`,`utf32_unicode_ci`,`utf32_bin`]};function se({properties:e,onChange:t}){let{t:n}=a();function r(n,r){let i={...e,[n]:r};n===`charset`&&(i.collation=X[r]?.[0]??``),t(i)}let i=X[e.charset]??[];return(0,V.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`prop-engine`,children:n(`table.properties.engine`)}),(0,V.jsxs)(d,{value:e.engine,onValueChange:e=>r(`engine`,e),children:[(0,V.jsx)(c,{id:`prop-engine`,className:`w-full`,children:(0,V.jsx)(s,{})}),(0,V.jsx)(l,{children:J.map(e=>(0,V.jsx)(u,{value:e,children:e},e))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`prop-charset`,children:n(`table.properties.charset`)}),(0,V.jsxs)(d,{value:e.charset,onValueChange:e=>r(`charset`,e),children:[(0,V.jsx)(c,{id:`prop-charset`,className:`w-full`,children:(0,V.jsx)(s,{})}),(0,V.jsx)(l,{children:Y.map(e=>(0,V.jsx)(u,{value:e,children:e},e))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`prop-collation`,children:n(`table.properties.collation`)}),(0,V.jsxs)(d,{value:e.collation,onValueChange:e=>r(`collation`,e),children:[(0,V.jsx)(c,{id:`prop-collation`,className:`w-full`,children:(0,V.jsx)(s,{})}),(0,V.jsx)(l,{children:i.map(e=>(0,V.jsx)(u,{value:e,children:e},e))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`prop-auto-incr`,children:n(`table.properties.autoIncrement`)}),(0,V.jsx)(D,{id:`prop-auto-incr`,type:`number`,value:e.autoIncrement,onChange:e=>r(`autoIncrement`,e.target.value),placeholder:n(`table.properties.autoIncrementPlaceholder`)})]})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`prop-comment`,children:n(`table.properties.comment`)}),(0,V.jsx)(D,{id:`prop-comment`,value:e.comment,onChange:e=>r(`comment`,e.target.value)})]})]})}function ce({connectionId:e,database:t,tableName:n,columns:r,indexes:i,properties:a}){let o=C(e=>e.themeId),s=ne(e),c=S(o),l=(0,R.useMemo)(()=>s.ddl.createTable(ie(t,n,r,i,a)),[s,t,n,r,i,a]);return(0,V.jsx)(`div`,{className:`h-[320px]`,children:(0,V.jsx)(_,{height:`100%`,language:`sql`,theme:c,value:l,options:{readOnly:!0,minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:13,lineNumbers:`on`,wordWrap:`on`}})})}function Z(e){return JSON.stringify([e.type,e.length,e.defaultValue,e.pk,e.notNull,e.unsigned,e.autoIncrement,e.zerofill,e.comment])}function Q(e){return{name:e.field,type:e.length?`${e.type}(${e.length})`:e.type,nullable:!e.notNull,key:e.pk?`PRI`:``,defaultValue:e.defaultValue===``?null:e.defaultValue,extra:e.autoIncrement?`auto_increment`:``,comment:e.comment,collation:null}}function $(e){return{name:e.name,type:e.type,columns:[...e.columns]}}function le(e,t){return e.name===t.name&&e.type===t.type&&e.columns.join(`,`)===t.columns.join(`,`)}function ue({engine:e,database:t,table:n,before:r,after:i}){let{ddl:a}=e,o=[],s=[],c=[],l=new Map(r.columns.map(e=>[e.id,e])),u=new Map(i.columns.map(e=>[e.id,e])),d=new Map(r.indexes.map(e=>[e.id,e])),f=new Map(i.indexes.map(e=>[e.id,e])),p=[];for(let[e,r]of d){let i=f.get(e);i?le(r,i)||(o.push(a.dropIndex(t,n,r.name)),p.push(i)):o.push(a.dropIndex(t,n,r.name))}for(let[e,r]of u){let i=l.get(e);if(!i){r.field.trim()&&o.push(a.addColumn(t,n,Q(r)));continue}if(i.field!==r.field&&o.push(a.renameColumn(t,n,i.field,r.field)),Z(i)!==Z(r)){let e=a.alterColumn(t,n,Q(r));e?o.push(e):c.push(r.field)}}for(let[e,r]of l)if(!u.has(e)){let e=a.dropColumn(t,n,r.field);o.push(e),s.push(e)}for(let e of p)o.push(a.createIndex(t,n,$(e)));for(let[e,r]of f)!d.has(e)&&r.columns.length>0&&o.push(a.createIndex(t,n,$(r)));return{statements:o,destructive:s,unsupported:c}}function de(){let{t:e}=a(),{activeDialog:t,closeDialog:i}=n(),s=r(`create-table`,`alter-table`,`duplicate-table-structure`),c=t===`create-table`||t===`alter-table`||t===`duplicate-table-structure`,l=t===`alter-table`,u=t===`duplicate-table-structure`,d=s?.nodeText??``,_=s?.metadata?.database??``,[v,x]=(0,R.useState)(``),[S,C]=(0,R.useState)([z()]),[w,O]=(0,R.useState)([]),[k,A]=(0,R.useState)(re()),[j,M]=(0,R.useState)(!1),[B,H]=(0,R.useState)(!1),[U,W]=(0,R.useState)(null),[G,K]=(0,R.useState)(null),q=s?.connectionId??f.getState().activeConnectionId,J=ne(q);(0,R.useEffect)(()=>{c&&(W(null),K(null),l||u?(x(u?`${d}_copy`:d),Y()):(x(``),C([z()]),O([]),A(re())))},[c,t]);async function Y(){let e=f.getState(),t=s?.connectionId??e.activeConnectionId,n=e.activeConnections.find(e=>e.id===t)?.serverConnectionId;if(!n||!_||!d)return;M(!0);let{introspect:r,capabilities:i}=m(t),a=p(n);try{let e=await r.listColumns(a,_,d),t=[];if(e.length>0){let n=e.map(e=>{let t=e.type,n=t.match(/^(\w+)(?:\(([^)]+)\))?/);return{id:crypto.randomUUID(),field:e.name,type:n?.[1]?.toLowerCase()??t.toLowerCase(),length:n?.[2]??``,defaultValue:e.defaultValue??``,pk:e.key===`PRI`,notNull:!e.nullable,unsigned:t.includes(`unsigned`),autoIncrement:e.extra.includes(`auto_increment`),zerofill:t.includes(`zerofill`),comment:e.comment}});C(n),t=n}let n=await r.listIndexes(a,_,d),o=[];if(n.length>0&&(o=n.map(e=>({id:crypto.randomUUID(),name:e.name,type:e.type===`SPATIAL`?`INDEX`:e.type,columns:[...e.columns]})),O(o)),K({columns:t,indexes:o}),i.tableProperties){let e=await r.getTableInfo(a,_,d);e&&A({engine:e.engine??`InnoDB`,charset:(e.collation??`utf8mb4`).replace(/_.*/,``),collation:e.collation??`utf8mb4_unicode_ci`,autoIncrement:e.autoIncrement??``,comment:e.comment})}}catch(e){console.error(`Failed to load table schema:`,e),W(e instanceof Error?e.message:String(e))}finally{M(!1)}}function X(e){e||i()}async function Z(){let t=s?.connectionId??f.getState().activeConnectionId;if(!t||!v.trim())return;let n=m(t);W(null);let r,a=[];if(l){if(!G)return;let t=ue({engine:n,database:_,table:d,before:G,after:{columns:S,indexes:w}});if(t.unsupported.length>0){W(e(`table.dialog.cannotAlterColumns`,{engine:n.label,columns:t.unsupported.join(`, `)}));return}if(t.statements.length===0){i();return}r=t.statements.join(`
1
+ import{r as e}from"./hePW80VL.js";import{h as t,n,t as r}from"./B1pia_Rg.js";import{l as i,m as a,t as o}from"./pjlgs2cl.js";import{a as s,i as c,n as l,r as u,t as d}from"./CiFkP-9S.js";import{t as f}from"./BCmzDvBt.js";import{a as p}from"./CS2mpWDL.js";import{n as m}from"./pneb1la9.js";import{l as h,p as g}from"./OjAiMU9J.js";import{$t as _,C as v,D as y,E as b,G as ee,O as te,S as x,T as S,Z as C,b as w,c as T,ct as ne,k as E,l as D,lt as O,st as k,v as A,x as j,y as M}from"./Bhquh17w.js";import{a as N,i as P,n as F,o as I,t as L}from"./BgkATqP8.js";var R=e(t(),1);function z(){return{id:crypto.randomUUID(),field:``,type:`varchar`,length:``,defaultValue:``,pk:!1,notNull:!1,unsigned:!1,autoIncrement:!1,zerofill:!1,comment:``}}function B(){return{id:crypto.randomUUID(),name:``,type:`INDEX`,columns:[]}}function re(){return{engine:`InnoDB`,charset:`utf8mb4`,collation:`utf8mb4_general_ci`,autoIncrement:``,comment:``}}function ie(e,t,n,r,i){return{database:e,name:t,columns:n.map(e=>({name:e.field,type:e.type,length:e.length,defaultValue:e.defaultValue,primaryKey:e.pk,notNull:e.notNull,unsigned:e.unsigned,autoIncrement:e.autoIncrement,zerofill:e.zerofill,comment:e.comment})),indexes:r.map(e=>({name:e.name,type:e.type,columns:[...e.columns]})),options:{...i}}}var V=i(),H=`w-auto min-w-full [&_td]:bg-muted [&_td]:border-r [&_td]:border-border/60 [&_td:last-child]:border-r-0 [&_td]:p-0 [&_td]:h-8 [&_tr:nth-child(even)_td]:bg-muted/60 [&_tr:focus-within_td]:bg-primary/5`,U=`sticky top-0 z-10 bg-catppuccin-crust shadow-[inset_0_-1px_0_var(--border)] [&_th]:h-8 [&_th]:bg-catppuccin-crust [&_th]:font-semibold [&_th]:text-foreground [&_th]:uppercase [&_th]:tracking-wide [&_th]:text-[11px]`,W=`h-8 w-full min-w-0 rounded-none border-0 bg-transparent px-2 text-xs shadow-none ring-0 focus-visible:bg-primary/10 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary dark:bg-transparent`,G=`h-8 w-full min-w-0 rounded-none border-0 bg-transparent px-2 text-xs shadow-none focus-visible:bg-primary/10 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary data-[state=open]:bg-primary/10 dark:bg-transparent dark:hover:bg-transparent`;function ae({columns:e,onChange:t}){let{t:n}=a(),r=k().getDataTypes(),i=(0,R.useCallback)((n,r,i)=>{t(e.map(e=>e.id===n?{...e,[r]:i}:e))},[e,t]);function f(){t([...e,z()])}function p(){e.length>0&&t(e.slice(0,-1))}return(0,V.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,V.jsx)(O,{className:`flex-1`,children:(0,V.jsxs)(A,{className:H,children:[(0,V.jsx)(x,{className:U,children:(0,V.jsxs)(v,{children:[(0,V.jsx)(j,{className:`w-[120px]`,children:n(`table.schema.colField`)}),(0,V.jsx)(j,{className:`w-[120px]`,children:n(`table.schema.colType`)}),(0,V.jsx)(j,{className:`w-[60px]`,children:n(`table.schema.colLength`)}),(0,V.jsx)(j,{className:`w-[100px]`,children:n(`table.schema.colDefault`)}),(0,V.jsx)(j,{className:`w-[40px]`,children:n(`table.schema.colPk`)}),(0,V.jsx)(j,{className:`w-[60px]`,children:n(`table.schema.colNotNull`)}),(0,V.jsx)(j,{className:`w-[60px]`,children:n(`table.schema.colUnsigned`)}),(0,V.jsx)(j,{className:`w-[70px]`,children:n(`table.schema.colAutoIncrement`)}),(0,V.jsx)(j,{className:`w-[60px]`,children:n(`table.schema.colZerofill`)}),(0,V.jsx)(j,{children:n(`table.schema.colComment`)})]})}),(0,V.jsx)(M,{children:e.length===0?(0,V.jsx)(v,{children:(0,V.jsx)(w,{colSpan:10,className:`text-center text-muted-foreground`,children:n(`table.schema.empty`)})}):e.map(e=>(0,V.jsxs)(v,{children:[(0,V.jsx)(w,{children:(0,V.jsx)(D,{className:W,value:e.field,onChange:t=>i(e.id,`field`,t.target.value),placeholder:`column_name`})}),(0,V.jsx)(w,{children:(0,V.jsxs)(d,{value:e.type,onValueChange:t=>i(e.id,`type`,t),children:[(0,V.jsx)(c,{className:G,children:(0,V.jsx)(s,{})}),(0,V.jsx)(l,{children:r.map(e=>(0,V.jsx)(u,{value:e,children:e},e))})]})}),(0,V.jsx)(w,{children:(0,V.jsx)(D,{className:W,value:e.length,onChange:t=>i(e.id,`length`,t.target.value)})}),(0,V.jsx)(w,{children:(0,V.jsx)(D,{className:W,value:e.defaultValue,onChange:t=>i(e.id,`defaultValue`,t.target.value),placeholder:`NULL`})}),(0,V.jsx)(w,{className:`text-center`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:e.pk,onChange:t=>i(e.id,`pk`,t.target.checked)})}),(0,V.jsx)(w,{className:`text-center`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:e.notNull,onChange:t=>i(e.id,`notNull`,t.target.checked)})}),(0,V.jsx)(w,{className:`text-center`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:e.unsigned,onChange:t=>i(e.id,`unsigned`,t.target.checked)})}),(0,V.jsx)(w,{className:`text-center`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:e.autoIncrement,onChange:t=>i(e.id,`autoIncrement`,t.target.checked)})}),(0,V.jsx)(w,{className:`text-center`,children:(0,V.jsx)(`input`,{type:`checkbox`,checked:e.zerofill,onChange:t=>i(e.id,`zerofill`,t.target.checked)})}),(0,V.jsx)(w,{children:(0,V.jsx)(D,{className:W,value:e.comment,onChange:t=>i(e.id,`comment`,t.target.value)})})]},e.id))})]})}),(0,V.jsxs)(`div`,{className:`flex gap-2 p-2 border-t`,children:[(0,V.jsx)(o,{size:`sm`,variant:`outline`,onClick:f,children:n(`table.schema.add`)}),(0,V.jsx)(o,{size:`sm`,variant:`outline`,onClick:p,disabled:e.length===0,children:n(`table.schema.remove`)})]})]})}var K=[`PRIMARY`,`UNIQUE`,`INDEX`,`FULLTEXT`];function q({open:e,index:t,availableColumns:n,onSave:r,onClose:i}){let{t:f}=a(),[p,m]=(0,R.useState)(t.name),[h,g]=(0,R.useState)(t.type),[_,v]=(0,R.useState)(t.columns);function y(e){v(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}function b(){r({id:t.id,name:h===`PRIMARY`?`PRIMARY`:p,type:h,columns:_})}return(0,V.jsx)(L,{open:e,onOpenChange:e=>{e||i()},children:(0,V.jsxs)(F,{className:`sm:max-w-[500px]`,children:[(0,V.jsx)(N,{children:(0,V.jsx)(I,{children:t.name?f(`table.index.editTitle`):f(`table.index.addTitle`)})}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`idx-name`,children:f(`table.index.name`)}),(0,V.jsx)(D,{id:`idx-name`,value:h===`PRIMARY`?`PRIMARY`:p,onChange:e=>m(e.target.value),disabled:h===`PRIMARY`,placeholder:f(`table.index.namePlaceholder`)})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`idx-type`,children:f(`table.index.type`)}),(0,V.jsxs)(d,{value:h,onValueChange:e=>g(e),children:[(0,V.jsx)(c,{id:`idx-type`,className:`w-full`,children:(0,V.jsx)(s,{})}),(0,V.jsx)(l,{children:K.map(e=>(0,V.jsx)(u,{value:e,children:e},e))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{children:f(`table.index.columns`)}),(0,V.jsx)(`div`,{className:`border rounded-md p-2 max-h-[200px] overflow-y-auto space-y-1`,children:n.length===0?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:f(`table.index.noColumns`)}):n.map(e=>(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-sm cursor-pointer hover:bg-muted/50 rounded px-1 py-0.5`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:_.includes(e.field),onChange:()=>y(e.field)}),(0,V.jsx)(`span`,{children:e.field||f(`table.index.unnamed`)}),(0,V.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,e.type,`)`]})]},e.id))})]})]}),(0,V.jsxs)(P,{children:[(0,V.jsx)(o,{variant:`outline`,onClick:i,children:f(`table.index.cancel`)}),(0,V.jsx)(o,{onClick:b,disabled:_.length===0,children:f(`table.index.ok`)})]})]})})}function oe({indexes:e,availableColumns:t,onChange:n}){let{t:r}=a(),[i,s]=(0,R.useState)(null),[c,l]=(0,R.useState)(!1);function u(){let e=B();s(e),l(!0)}function d(e){s({...e}),l(!0)}function f(){e.length>0&&n(e.slice(0,-1))}function p(t){e.find(e=>e.id===t.id)?n(e.map(e=>e.id===t.id?t:e)):n([...e,t]),l(!1),s(null)}function m(){l(!1),s(null)}return(0,V.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,V.jsx)(O,{className:`flex-1`,children:(0,V.jsxs)(A,{className:H+` [&_td]:px-2`,children:[(0,V.jsx)(x,{className:U,children:(0,V.jsxs)(v,{children:[(0,V.jsx)(j,{className:`w-[150px]`,children:r(`table.indexes.colName`)}),(0,V.jsx)(j,{className:`w-[120px]`,children:r(`table.indexes.colType`)}),(0,V.jsx)(j,{children:r(`table.indexes.colColumns`)})]})}),(0,V.jsx)(M,{children:e.length===0?(0,V.jsx)(v,{children:(0,V.jsx)(w,{colSpan:3,className:`text-center text-muted-foreground`,children:r(`table.indexes.empty`)})}):e.map(e=>(0,V.jsxs)(v,{className:`cursor-pointer`,onDoubleClick:()=>d(e),children:[(0,V.jsx)(w,{children:e.name}),(0,V.jsx)(w,{children:e.type}),(0,V.jsx)(w,{children:e.columns.join(`, `)})]},e.id))})]})}),(0,V.jsxs)(`div`,{className:`flex gap-2 p-2 border-t`,children:[(0,V.jsx)(o,{size:`sm`,variant:`outline`,onClick:u,children:r(`table.indexes.add`)}),(0,V.jsx)(o,{size:`sm`,variant:`outline`,onClick:f,disabled:e.length===0,children:r(`table.indexes.remove`)})]}),i&&(0,V.jsx)(q,{open:c,index:i,availableColumns:t,onSave:p,onClose:m})]})}var J=[`InnoDB`,`MyISAM`,`MEMORY`,`CSV`,`ARCHIVE`,`BLACKHOLE`,`MRG_MYISAM`,`FEDERATED`,`PERFORMANCE_SCHEMA`],Y=[`utf8mb4`,`utf8`,`latin1`,`ascii`,`binary`,`cp1251`,`euckr`,`gb2312`,`gbk`,`sjis`,`ucs2`,`utf16`,`utf32`],X={utf8mb4:[`utf8mb4_general_ci`,`utf8mb4_unicode_ci`,`utf8mb4_bin`,`utf8mb4_0900_ai_ci`],utf8:[`utf8_general_ci`,`utf8_unicode_ci`,`utf8_bin`],latin1:[`latin1_swedish_ci`,`latin1_general_ci`,`latin1_bin`],ascii:[`ascii_general_ci`,`ascii_bin`],binary:[`binary`],cp1251:[`cp1251_general_ci`,`cp1251_bin`],euckr:[`euckr_korean_ci`,`euckr_bin`],gb2312:[`gb2312_chinese_ci`,`gb2312_bin`],gbk:[`gbk_chinese_ci`,`gbk_bin`],sjis:[`sjis_japanese_ci`,`sjis_bin`],ucs2:[`ucs2_general_ci`,`ucs2_unicode_ci`,`ucs2_bin`],utf16:[`utf16_general_ci`,`utf16_unicode_ci`,`utf16_bin`],utf32:[`utf32_general_ci`,`utf32_unicode_ci`,`utf32_bin`]};function se({properties:e,onChange:t}){let{t:n}=a();function r(n,r){let i={...e,[n]:r};n===`charset`&&(i.collation=X[r]?.[0]??``),t(i)}let i=X[e.charset]??[];return(0,V.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`prop-engine`,children:n(`table.properties.engine`)}),(0,V.jsxs)(d,{value:e.engine,onValueChange:e=>r(`engine`,e),children:[(0,V.jsx)(c,{id:`prop-engine`,className:`w-full`,children:(0,V.jsx)(s,{})}),(0,V.jsx)(l,{children:J.map(e=>(0,V.jsx)(u,{value:e,children:e},e))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`prop-charset`,children:n(`table.properties.charset`)}),(0,V.jsxs)(d,{value:e.charset,onValueChange:e=>r(`charset`,e),children:[(0,V.jsx)(c,{id:`prop-charset`,className:`w-full`,children:(0,V.jsx)(s,{})}),(0,V.jsx)(l,{children:Y.map(e=>(0,V.jsx)(u,{value:e,children:e},e))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`prop-collation`,children:n(`table.properties.collation`)}),(0,V.jsxs)(d,{value:e.collation,onValueChange:e=>r(`collation`,e),children:[(0,V.jsx)(c,{id:`prop-collation`,className:`w-full`,children:(0,V.jsx)(s,{})}),(0,V.jsx)(l,{children:i.map(e=>(0,V.jsx)(u,{value:e,children:e},e))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`prop-auto-incr`,children:n(`table.properties.autoIncrement`)}),(0,V.jsx)(D,{id:`prop-auto-incr`,type:`number`,value:e.autoIncrement,onChange:e=>r(`autoIncrement`,e.target.value),placeholder:n(`table.properties.autoIncrementPlaceholder`)})]})]}),(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(T,{htmlFor:`prop-comment`,children:n(`table.properties.comment`)}),(0,V.jsx)(D,{id:`prop-comment`,value:e.comment,onChange:e=>r(`comment`,e.target.value)})]})]})}function ce({connectionId:e,database:t,tableName:n,columns:r,indexes:i,properties:a}){let o=C(e=>e.themeId),s=ne(e),c=S(o),l=(0,R.useMemo)(()=>s.ddl.createTable(ie(t,n,r,i,a)),[s,t,n,r,i,a]);return(0,V.jsx)(`div`,{className:`h-[320px]`,children:(0,V.jsx)(_,{height:`100%`,language:`sql`,theme:c,value:l,options:{readOnly:!0,minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:13,lineNumbers:`on`,wordWrap:`on`}})})}function Z(e){return JSON.stringify([e.type,e.length,e.defaultValue,e.pk,e.notNull,e.unsigned,e.autoIncrement,e.zerofill,e.comment])}function Q(e){return{name:e.field,type:e.length?`${e.type}(${e.length})`:e.type,nullable:!e.notNull,key:e.pk?`PRI`:``,defaultValue:e.defaultValue===``?null:e.defaultValue,extra:e.autoIncrement?`auto_increment`:``,comment:e.comment,collation:null}}function $(e){return{name:e.name,type:e.type,columns:[...e.columns]}}function le(e,t){return e.name===t.name&&e.type===t.type&&e.columns.join(`,`)===t.columns.join(`,`)}function ue({engine:e,database:t,table:n,before:r,after:i}){let{ddl:a}=e,o=[],s=[],c=[],l=new Map(r.columns.map(e=>[e.id,e])),u=new Map(i.columns.map(e=>[e.id,e])),d=new Map(r.indexes.map(e=>[e.id,e])),f=new Map(i.indexes.map(e=>[e.id,e])),p=[];for(let[e,r]of d){let i=f.get(e);i?le(r,i)||(o.push(a.dropIndex(t,n,r.name)),p.push(i)):o.push(a.dropIndex(t,n,r.name))}for(let[e,r]of u){let i=l.get(e);if(!i){r.field.trim()&&o.push(a.addColumn(t,n,Q(r)));continue}if(i.field!==r.field&&o.push(a.renameColumn(t,n,i.field,r.field)),Z(i)!==Z(r)){let e=a.alterColumn(t,n,Q(r));e?o.push(e):c.push(r.field)}}for(let[e,r]of l)if(!u.has(e)){let e=a.dropColumn(t,n,r.field);o.push(e),s.push(e)}for(let e of p)o.push(a.createIndex(t,n,$(e)));for(let[e,r]of f)!d.has(e)&&r.columns.length>0&&o.push(a.createIndex(t,n,$(r)));return{statements:o,destructive:s,unsupported:c}}function de(){let{t:e}=a(),{activeDialog:t,closeDialog:i}=n(),s=r(`create-table`,`alter-table`,`duplicate-table-structure`),c=t===`create-table`||t===`alter-table`||t===`duplicate-table-structure`,l=t===`alter-table`,u=t===`duplicate-table-structure`,d=s?.nodeText??``,_=s?.metadata?.database??``,[v,x]=(0,R.useState)(``),[S,C]=(0,R.useState)([z()]),[w,O]=(0,R.useState)([]),[k,A]=(0,R.useState)(re()),[j,M]=(0,R.useState)(!1),[B,H]=(0,R.useState)(!1),[U,W]=(0,R.useState)(null),[G,K]=(0,R.useState)(null),q=s?.connectionId??f.getState().activeConnectionId,J=ne(q);(0,R.useEffect)(()=>{c&&(W(null),K(null),l||u?(x(u?`${d}_copy`:d),Y()):(x(``),C([z()]),O([]),A(re())))},[c,t]);async function Y(){let e=f.getState(),t=s?.connectionId??e.activeConnectionId,n=e.activeConnections.find(e=>e.id===t)?.serverConnectionId;if(!n||!_||!d)return;M(!0);let{introspect:r,capabilities:i}=m(t),a=p(n);try{let e=await r.listColumns(a,_,d),t=[];if(e.length>0){let n=e.map(e=>{let t=e.type,n=t.match(/^(\w+)(?:\(([^)]+)\))?/);return{id:crypto.randomUUID(),field:e.name,type:n?.[1]?.toLowerCase()??t.toLowerCase(),length:n?.[2]??``,defaultValue:e.defaultValue??``,pk:e.key===`PRI`,notNull:!e.nullable,unsigned:t.includes(`unsigned`),autoIncrement:e.extra.includes(`auto_increment`),zerofill:t.includes(`zerofill`),comment:e.comment}});C(n),t=n}let n=await r.listIndexes(a,_,d),o=[];if(n.length>0&&(o=n.map(e=>({id:crypto.randomUUID(),name:e.name,type:e.type===`SPATIAL`?`INDEX`:e.type,columns:[...e.columns]})),O(o)),K({columns:t,indexes:o}),i.tableProperties){let e=await r.getTableInfo(a,_,d);e&&A({engine:e.engine??`InnoDB`,charset:(e.collation??`utf8mb4`).replace(/_.*/,``),collation:e.collation??`utf8mb4_unicode_ci`,autoIncrement:e.autoIncrement??``,comment:e.comment})}}catch(e){console.error(`Failed to load table schema:`,e),W(e instanceof Error?e.message:String(e))}finally{M(!1)}}function X(e){e||i()}async function Z(){let t=s?.connectionId??f.getState().activeConnectionId;if(!t||!v.trim())return;let n=m(t);W(null);let r,a=[];if(l){if(!G)return;let t=ue({engine:n,database:_,table:d,before:G,after:{columns:S,indexes:w}});if(t.unsupported.length>0){W(e(`table.dialog.cannotAlterColumns`,{engine:n.label,columns:t.unsupported.join(`, `)}));return}if(t.statements.length===0){i();return}r=t.statements.join(`
2
2
  `),a=t.destructive}else{let e=u?w.map(e=>({...e,name:ee(e.name,d,v.trim())})):w;r=n.ddl.createTable(ie(_,v.trim(),S,e,k))}H(!0);try{await h(t,r,{skipDestructiveConfirm:a.length===0}),await g(t,_),i()}catch(e){W(e instanceof Error?e.message:String(e))}finally{H(!1)}}let Q=e(l?`table.dialog.alterTitle`:u?`table.dialog.duplicateTitle`:`table.dialog.createTitle`),$=e(l?`table.dialog.alter`:`table.dialog.create`);return(0,V.jsx)(L,{open:c,onOpenChange:X,children:(0,V.jsxs)(F,{className:`sm:max-w-[1000px] max-h-[80vh] flex flex-col`,children:[(0,V.jsx)(N,{children:(0,V.jsx)(I,{children:Q})}),(0,V.jsxs)(`div`,{className:`space-y-3 flex-1 overflow-hidden flex flex-col min-h-0`,children:[(0,V.jsxs)(`div`,{className:`space-y-1.5 px-1`,children:[(0,V.jsx)(T,{htmlFor:`table-name`,children:e(`table.dialog.tableName`)}),(0,V.jsx)(D,{id:`table-name`,value:v,onChange:e=>x(e.target.value),placeholder:e(`table.dialog.tableNamePlaceholder`),disabled:l})]}),j?(0,V.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-muted-foreground text-sm`,children:e(`table.dialog.loading`)}):(0,V.jsxs)(b,{defaultValue:`schema`,className:`flex-1 min-h-0 flex flex-col`,children:[(0,V.jsxs)(te,{children:[(0,V.jsx)(E,{value:`schema`,children:e(`table.dialog.tabSchema`)}),(0,V.jsx)(E,{value:`indexes`,children:e(`table.dialog.tabIndexes`)}),J.capabilities.tableProperties&&(0,V.jsx)(E,{value:`properties`,children:e(`table.dialog.tabProperties`)}),(0,V.jsx)(E,{value:`sql`,children:`SQL`})]}),(0,V.jsx)(y,{value:`schema`,className:`flex-1 min-h-0 overflow-auto border rounded-md`,children:(0,V.jsx)(ae,{columns:S,onChange:C})}),(0,V.jsx)(y,{value:`indexes`,className:`flex-1 min-h-0 overflow-auto border rounded-md`,children:(0,V.jsx)(oe,{indexes:w,availableColumns:S,onChange:O})}),(0,V.jsx)(y,{value:`properties`,className:`flex-1 min-h-0 overflow-auto border rounded-md`,children:(0,V.jsx)(se,{properties:k,onChange:A})}),(0,V.jsx)(y,{value:`sql`,className:`flex-1 min-h-0 border rounded-md`,children:(0,V.jsx)(ce,{connectionId:q,database:_,tableName:v,columns:S,indexes:w,properties:k})})]})]}),U&&(0,V.jsx)(`p`,{className:`px-1 text-xs text-destructive leading-relaxed`,children:U}),(0,V.jsxs)(P,{children:[(0,V.jsx)(o,{variant:`outline`,onClick:()=>X(!1),children:e(`table.dialog.cancel`)}),(0,V.jsx)(o,{onClick:()=>void Z(),disabled:j||B||!v.trim(),children:B?e(`table.dialog.applying`):$})]})]})})}export{de as EditSchemaDialog};
@@ -1 +1 @@
1
- import{n as e}from"./BkIkgVK5.js";import{l as t,m as n,t as r}from"./C0O3rJzW.js";import{n as i,t as a}from"./DP94Ond0.js";import{a as o,i as s,n as c,o as l,r as u,t as d}from"./Cg4DfVr4.js";import{t as f}from"./BaO3ulMH.js";var p=t();function m(){let t=e(e=>e.activeDialog),m=e(e=>e.closeDialog),h=i(),g=h.update,{t:_}=n();return(0,p.jsx)(d,{open:t===`safety-settings`,onOpenChange:e=>{e||m()},children:(0,p.jsxs)(c,{className:`sm:max-w-[560px]`,children:[(0,p.jsxs)(o,{children:[(0,p.jsx)(l,{children:_(`settings.title`)}),(0,p.jsx)(u,{children:_(`settings.description`)})]}),(0,p.jsxs)(`div`,{className:`grid gap-2`,children:[(0,p.jsx)(f,{id:`s-confirm`,checked:h.confirmDestructive,onChange:e=>g({confirmDestructive:e}),label:`Confirm destructive statements`,hint:`Ask before DROP TABLE/DATABASE, TRUNCATE, DELETE or UPDATE without WHERE, and ALTER … DROP COLUMN.`}),(0,p.jsx)(f,{id:`s-warn`,checked:h.warnInEditor,onChange:e=>g({warnInEditor:e}),label:`Warn in the editor`,hint:`Underline destructive statements and statements a read-only connection would refuse.`}),(0,p.jsx)(f,{id:`s-override`,checked:h.allowReadOnlyOverride,onChange:e=>g({allowReadOnlyOverride:e}),label:`Allow "Run anyway" on read-only connections`,hint:`When off, writes on a read-only connection are refused with no override.`}),(0,p.jsx)(f,{id:`s-preview`,checked:h.previewGridCommit,onChange:e=>g({previewGridCommit:e}),label:`Preview SQL before committing grid edits`,hint:`Show the generated UPDATE statements and ask for confirmation.`})]}),(0,p.jsxs)(s,{children:[(0,p.jsx)(r,{variant:`ghost`,onClick:()=>g(a),children:_(`settings.resetDefaults`)}),(0,p.jsx)(r,{onClick:m,children:_(`settings.done`)})]})]})})}export{m as SafetySettingsDialog};
1
+ import{n as e}from"./B1pia_Rg.js";import{l as t,m as n,t as r}from"./pjlgs2cl.js";import{n as i,t as a}from"./D6kbK-ng.js";import{a as o,i as s,n as c,o as l,r as u,t as d}from"./BgkATqP8.js";import{t as f}from"./DkPnEF-y.js";var p=t();function m(){let t=e(e=>e.activeDialog),m=e(e=>e.closeDialog),h=i(),g=h.update,{t:_}=n();return(0,p.jsx)(d,{open:t===`safety-settings`,onOpenChange:e=>{e||m()},children:(0,p.jsxs)(c,{className:`sm:max-w-[560px]`,children:[(0,p.jsxs)(o,{children:[(0,p.jsx)(l,{children:_(`settings.title`)}),(0,p.jsx)(u,{children:_(`settings.description`)})]}),(0,p.jsxs)(`div`,{className:`grid gap-2`,children:[(0,p.jsx)(f,{id:`s-confirm`,checked:h.confirmDestructive,onChange:e=>g({confirmDestructive:e}),label:`Confirm destructive statements`,hint:`Ask before DROP TABLE/DATABASE, TRUNCATE, DELETE or UPDATE without WHERE, and ALTER … DROP COLUMN.`}),(0,p.jsx)(f,{id:`s-warn`,checked:h.warnInEditor,onChange:e=>g({warnInEditor:e}),label:`Warn in the editor`,hint:`Underline destructive statements and statements a read-only connection would refuse.`}),(0,p.jsx)(f,{id:`s-override`,checked:h.allowReadOnlyOverride,onChange:e=>g({allowReadOnlyOverride:e}),label:`Allow "Run anyway" on read-only connections`,hint:`When off, writes on a read-only connection are refused with no override.`}),(0,p.jsx)(f,{id:`s-preview`,checked:h.previewGridCommit,onChange:e=>g({previewGridCommit:e}),label:`Preview SQL before committing grid edits`,hint:`Show the generated UPDATE statements and ask for confirmation.`})]}),(0,p.jsxs)(s,{children:[(0,p.jsx)(r,{variant:`ghost`,onClick:()=>g(a),children:_(`settings.resetDefaults`)}),(0,p.jsx)(r,{onClick:m,children:_(`settings.done`)})]})]})})}export{m as SafetySettingsDialog};
@@ -1 +1 @@
1
- import{r as e}from"./hePW80VL.js";import{h as t,n}from"./BkIkgVK5.js";import{l as r,m as i,t as a}from"./C0O3rJzW.js";import{a as o,i as s,n as c,r as l,t as u}from"./DL6u_OmT.js";import{t as d}from"./DC8XCjJ3.js";import{c as f,l as p}from"./BKoh-tKR.js";import{a as m,i as h,n as g,o as _,t as v}from"./Cg4DfVr4.js";import{n as y}from"./1XwwL8xu.js";var b=e(t(),1),x=r();function S(){let{t:e}=i(),{activeDialog:t,closeDialog:r,setFooterMessage:S}=n(),C=d(e=>e.activeConnectionId)??``,w=y(e=>e.addUser),[T,E]=(0,b.useState)(``),[D,O]=(0,b.useState)(`%`),[k,A]=(0,b.useState)(``),[j,M]=(0,b.useState)(``),[N,P]=(0,b.useState)(`caching_sha2_password`),F=t===`user-add`;function I(e){e||(L(),r())}function L(){E(``),O(`%`),A(``),M(``),P(`caching_sha2_password`)}function R(){if(!T.trim()){S(e(`user.add.usernameRequired`));return}if(k!==j){S(e(`user.add.passwordMismatch`));return}w(C,{user:T.trim(),host:D.trim()||`%`,privileges:[],maxQuestions:0,maxUpdates:0,maxConnections:0,maxUserConnections:0,plugin:N,authenticationString:``,passwordExpired:!1,accountLocked:!1}),S(e(`user.add.added`,{user:T,host:D})),L(),r()}return(0,x.jsx)(v,{open:F,onOpenChange:I,children:(0,x.jsxs)(g,{className:`sm:max-w-[450px]`,children:[(0,x.jsx)(m,{children:(0,x.jsx)(_,{children:e(`user.add.title`)})}),(0,x.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(f,{htmlFor:`user-add-username`,children:e(`user.add.username`)}),(0,x.jsx)(p,{id:`user-add-username`,value:T,onChange:e=>E(e.target.value),placeholder:e(`user.add.usernamePlaceholder`)})]}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(f,{htmlFor:`user-add-host`,children:e(`user.add.host`)}),(0,x.jsx)(p,{id:`user-add-host`,value:D,onChange:e=>O(e.target.value),placeholder:`%`})]}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(f,{htmlFor:`user-add-password`,children:e(`user.add.password`)}),(0,x.jsx)(p,{id:`user-add-password`,type:`password`,value:k,onChange:e=>A(e.target.value),placeholder:e(`user.add.passwordPlaceholder`)})]}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(f,{htmlFor:`user-add-confirm-password`,children:e(`user.add.confirmPassword`)}),(0,x.jsx)(p,{id:`user-add-confirm-password`,type:`password`,value:j,onChange:e=>M(e.target.value),placeholder:e(`user.add.confirmPasswordPlaceholder`)})]}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(f,{children:e(`user.add.plugin`)}),(0,x.jsxs)(u,{value:N,onValueChange:P,children:[(0,x.jsx)(s,{className:`w-full`,children:(0,x.jsx)(o,{})}),(0,x.jsxs)(c,{children:[(0,x.jsx)(l,{value:`mysql_native_password`,children:`mysql_native_password`}),(0,x.jsx)(l,{value:`caching_sha2_password`,children:`caching_sha2_password`})]})]})]})]}),(0,x.jsxs)(h,{children:[(0,x.jsx)(a,{variant:`outline`,onClick:()=>I(!1),children:e(`user.add.cancel`)}),(0,x.jsx)(a,{onClick:R,children:e(`user.add.add`)})]})]})})}export{S as UserAddDialog};
1
+ import{r as e}from"./hePW80VL.js";import{h as t,n}from"./B1pia_Rg.js";import{l as r,m as i,t as a}from"./pjlgs2cl.js";import{a as o,i as s,n as c,r as l,t as u}from"./CiFkP-9S.js";import{t as d}from"./BCmzDvBt.js";import{c as f,l as p}from"./Bhquh17w.js";import{a as m,i as h,n as g,o as _,t as v}from"./BgkATqP8.js";import{n as y}from"./C0bzfYFC.js";var b=e(t(),1),x=r();function S(){let{t:e}=i(),{activeDialog:t,closeDialog:r,setFooterMessage:S}=n(),C=d(e=>e.activeConnectionId)??``,w=y(e=>e.addUser),[T,E]=(0,b.useState)(``),[D,O]=(0,b.useState)(`%`),[k,A]=(0,b.useState)(``),[j,M]=(0,b.useState)(``),[N,P]=(0,b.useState)(`caching_sha2_password`),F=t===`user-add`;function I(e){e||(L(),r())}function L(){E(``),O(`%`),A(``),M(``),P(`caching_sha2_password`)}function R(){if(!T.trim()){S(e(`user.add.usernameRequired`));return}if(k!==j){S(e(`user.add.passwordMismatch`));return}w(C,{user:T.trim(),host:D.trim()||`%`,privileges:[],maxQuestions:0,maxUpdates:0,maxConnections:0,maxUserConnections:0,plugin:N,authenticationString:``,passwordExpired:!1,accountLocked:!1}),S(e(`user.add.added`,{user:T,host:D})),L(),r()}return(0,x.jsx)(v,{open:F,onOpenChange:I,children:(0,x.jsxs)(g,{className:`sm:max-w-[450px]`,children:[(0,x.jsx)(m,{children:(0,x.jsx)(_,{children:e(`user.add.title`)})}),(0,x.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(f,{htmlFor:`user-add-username`,children:e(`user.add.username`)}),(0,x.jsx)(p,{id:`user-add-username`,value:T,onChange:e=>E(e.target.value),placeholder:e(`user.add.usernamePlaceholder`)})]}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(f,{htmlFor:`user-add-host`,children:e(`user.add.host`)}),(0,x.jsx)(p,{id:`user-add-host`,value:D,onChange:e=>O(e.target.value),placeholder:`%`})]}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(f,{htmlFor:`user-add-password`,children:e(`user.add.password`)}),(0,x.jsx)(p,{id:`user-add-password`,type:`password`,value:k,onChange:e=>A(e.target.value),placeholder:e(`user.add.passwordPlaceholder`)})]}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(f,{htmlFor:`user-add-confirm-password`,children:e(`user.add.confirmPassword`)}),(0,x.jsx)(p,{id:`user-add-confirm-password`,type:`password`,value:j,onChange:e=>M(e.target.value),placeholder:e(`user.add.confirmPasswordPlaceholder`)})]}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(f,{children:e(`user.add.plugin`)}),(0,x.jsxs)(u,{value:N,onValueChange:P,children:[(0,x.jsx)(s,{className:`w-full`,children:(0,x.jsx)(o,{})}),(0,x.jsxs)(c,{children:[(0,x.jsx)(l,{value:`mysql_native_password`,children:`mysql_native_password`}),(0,x.jsx)(l,{value:`caching_sha2_password`,children:`caching_sha2_password`})]})]})]})]}),(0,x.jsxs)(h,{children:[(0,x.jsx)(a,{variant:`outline`,onClick:()=>I(!1),children:e(`user.add.cancel`)}),(0,x.jsx)(a,{onClick:R,children:e(`user.add.add`)})]})]})})}export{S as UserAddDialog};
@@ -1,4 +1,4 @@
1
- import{_ as e}from"./DC8XCjJ3.js";var t=/^(?:-?\d+(?:\.\d+)?|null|true|false|current_(?:timestamp|date|time)(?:\(\d*\))?|now\(\)|b'[01]+'|x'[0-9a-f]*')$/i;function n(e,n){let r=e.trim();return r===``?n(``):t.test(r)||/^'.*'$/s.test(r)||/^".*"$/s.test(r)||r.includes(`(`)||r.includes(`::`)?r:n(r)}function r(e,t,r){let i=t.upperCaseTypes?e.type.toUpperCase():e.type;return e.nullable?t.modify===`mssql`&&(i+=` NULL`):i+=` NOT NULL`,e.defaultValue!==null&&!/auto_increment|identity/i.test(e.extra)&&(i+=` DEFAULT ${n(e.defaultValue,r)}`),t.mysqlAttributes&&(/auto_increment/i.test(e.extra)&&(i+=` AUTO_INCREMENT`),e.comment&&(i+=` COMMENT ${r(e.comment)}`)),i}function i({quoteIdentifier:e,quoteLiteral:t,qualify:i},a){let o=e=>r(e,a,t),s=(t,n)=>a.qualifiedIndexNames?i(t,n):e(n);return{addColumn(t,n,r){let s=`${e(r.name)} ${o(r)}`;return a.addColumn===`ADD (`?`ALTER TABLE ${i(t,n)} ADD (${s});`:`ALTER TABLE ${i(t,n)} ${a.addColumn} ${s};`},alterColumn(r,s,c){let l=i(r,s),u=e(c.name);switch(a.modify){case`mysql`:return`ALTER TABLE ${l} MODIFY COLUMN ${u} ${o(c)};`;case`oracle`:return`ALTER TABLE ${l} MODIFY (${u} ${o(c)});`;case`mssql`:return`ALTER TABLE ${l} ALTER COLUMN ${u} ${c.type}${c.nullable?` NULL`:` NOT NULL`};`;case`postgres`:return`ALTER TABLE ${l}\n ${[`ALTER COLUMN ${u} TYPE ${c.type}`,c.nullable?`ALTER COLUMN ${u} DROP NOT NULL`:`ALTER COLUMN ${u} SET NOT NULL`,c.defaultValue===null||/auto_increment|identity/i.test(c.extra)?`ALTER COLUMN ${u} DROP DEFAULT`:`ALTER COLUMN ${u} SET DEFAULT ${n(c.defaultValue,t)}`].join(`,
1
+ import{_ as e}from"./BCmzDvBt.js";var t=/^(?:-?\d+(?:\.\d+)?|null|true|false|current_(?:timestamp|date|time)(?:\(\d*\))?|now\(\)|b'[01]+'|x'[0-9a-f]*')$/i;function n(e,n){let r=e.trim();return r===``?n(``):t.test(r)||/^'.*'$/s.test(r)||/^".*"$/s.test(r)||r.includes(`(`)||r.includes(`::`)?r:n(r)}function r(e,t,r){let i=t.upperCaseTypes?e.type.toUpperCase():e.type;return e.nullable?t.modify===`mssql`&&(i+=` NULL`):i+=` NOT NULL`,e.defaultValue!==null&&!/auto_increment|identity/i.test(e.extra)&&(i+=` DEFAULT ${n(e.defaultValue,r)}`),t.mysqlAttributes&&(/auto_increment/i.test(e.extra)&&(i+=` AUTO_INCREMENT`),e.comment&&(i+=` COMMENT ${r(e.comment)}`)),i}function i({quoteIdentifier:e,quoteLiteral:t,qualify:i},a){let o=e=>r(e,a,t),s=(t,n)=>a.qualifiedIndexNames?i(t,n):e(n);return{addColumn(t,n,r){let s=`${e(r.name)} ${o(r)}`;return a.addColumn===`ADD (`?`ALTER TABLE ${i(t,n)} ADD (${s});`:`ALTER TABLE ${i(t,n)} ${a.addColumn} ${s};`},alterColumn(r,s,c){let l=i(r,s),u=e(c.name);switch(a.modify){case`mysql`:return`ALTER TABLE ${l} MODIFY COLUMN ${u} ${o(c)};`;case`oracle`:return`ALTER TABLE ${l} MODIFY (${u} ${o(c)});`;case`mssql`:return`ALTER TABLE ${l} ALTER COLUMN ${u} ${c.type}${c.nullable?` NULL`:` NOT NULL`};`;case`postgres`:return`ALTER TABLE ${l}\n ${[`ALTER COLUMN ${u} TYPE ${c.type}`,c.nullable?`ALTER COLUMN ${u} DROP NOT NULL`:`ALTER COLUMN ${u} SET NOT NULL`,c.defaultValue===null||/auto_increment|identity/i.test(c.extra)?`ALTER COLUMN ${u} DROP DEFAULT`:`ALTER COLUMN ${u} SET DEFAULT ${n(c.defaultValue,t)}`].join(`,
2
2
  `)};`;case`none`:return null}},dropColumn(t,n,r){return`ALTER TABLE ${i(t,n)} DROP COLUMN ${e(r)};`},renameColumn(n,r,o,s){return a.renameColumn===`sp_rename`?`EXEC sp_rename ${t(`${n}.${r}.${o}`)}, ${t(s)}, 'COLUMN';`:`ALTER TABLE ${i(n,r)} RENAME COLUMN ${e(o)} TO ${e(s)};`},createIndex(t,n,r){let o=r.columns.map(e).join(`, `);if(r.type===`PRIMARY`)return`ALTER TABLE ${i(t,n)} ADD PRIMARY KEY (${o});`;let c=r.type===`UNIQUE`?`UNIQUE `:r.type===`FULLTEXT`&&a.fulltext?`FULLTEXT `:``,l=a.unqualifiedIndexTarget?e(n):i(t,n);return`CREATE ${c}INDEX ${s(t,r.name)} ON ${l} (${o});`},dropIndex(t,n,r){return a.dropIndexOnTable?`DROP INDEX ${e(r)} ON ${i(t,n)};`:`DROP INDEX ${s(t,r)};`},insertRows(n,r,o,s){let c=i(n,r),l=o.map(e).join(`, `),u=s.map(e=>`(${e.map(t).join(`, `)})`);return a.multiRowInsert?`INSERT INTO ${c} (${l}) VALUES\n${u.join(`,
3
3
  `)};`:`INSERT ALL\n${u.map(e=>` INTO ${c} (${l}) VALUES ${e}`).join(`
4
4
  `)}\nSELECT 1 FROM DUAL;`}}}function a(e,t,n){let r=`${t}:${n.replaceAll(`/`,`⁄`)}`;return e?`${e}/${r}`:r}function o(e,t,n,r,i){return{id:a(e,t,n),type:t,text:n,isLeaf:r,isExpanded:!1,isLoading:!1,children:[],metadata:i}}var s=[{text:`Tables`,type:`TABLE`},{text:`Views`,type:`VIEW`},{text:`Procedures`,type:`PROCEDURE`,capability:`procedures`},{text:`Functions`,type:`FUNCTION`,capability:`functions`},{text:`Triggers`,type:`TRIGGER`,capability:`triggers`},{text:`Events`,type:`EVENT`,capability:`events`}],c=[`Columns`,`Indexes`],l={TABLE:e.TABLE,VIEW:e.VIEW,PROCEDURE:e.PROCEDURE,FUNCTION:e.FUNCTION,TRIGGER:e.TRIGGER,EVENT:e.EVENT};function u(e){return s.find(t=>t.type===e).text}function d(e){return s.filter(t=>!t.capability||e.capabilities[t.capability]).map(e=>e.text)}function f(t,n,r){return d(t).map(t=>o(n,e.FOLDER,t,!1,{...r,countable:!0}))}async function ee({engine:t,run:n},r){let{introspect:i}=t,a=r.metadata?.database??``,s={database:a,catalog:r.metadata?.catalog},c=(e,t,n)=>o(r.id,l[e],t,!0,{...s,...n});switch(r.text){case`Tables`:return(await i.listTables(n,a)).map(t=>o(r.id,e.TABLE,t.name,!1,{...s,table:t.name}));case`Views`:return(await i.listViews(n,a)).map(e=>c(`VIEW`,e));case`Procedures`:return(await i.listProcedures(n,a)).map(e=>c(`PROCEDURE`,e));case`Functions`:return(await i.listFunctions(n,a)).map(e=>c(`FUNCTION`,e));case`Triggers`:return i.listTriggerDetails?(await i.listTriggerDetails(n,a)).map(e=>c(`TRIGGER`,e.name,{table:e.table})):(await i.listTriggers(n,a)).map(e=>c(`TRIGGER`,e));case`Events`:return(await i.listEvents(n,a)).map(e=>c(`EVENT`,e));default:return[]}}function te(t){let n={database:t.metadata?.database,catalog:t.metadata?.catalog,table:t.text};return c.map(r=>o(t.id,e.FOLDER,r,!1,n))}async function p({engine:t,run:n},r){let i=r.metadata?.database??``,a=r.metadata?.table;if(!a)return null;let s={database:i,catalog:r.metadata?.catalog,table:a};switch(r.text){case`Columns`:return(await t.introspect.listColumns(n,i,a)).map(t=>{let n=t.extra?` [${t.extra}]`:``;return o(r.id,e.COLUMN,`${t.name} ${t.type}${n}`,!0,{...s,column:t.name,key:t.key})});case`Indexes`:return(await t.introspect.listIndexes(n,i,a)).map(t=>o(r.id,e.INDEX,`${t.name} (${t.columns.join(`, `)})`,!0,{...s,index:t.name}));default:return null}}async function m(t,n){switch(n.type){case e.FOLDER:return await p(t,n)??ee(t,n);case e.TABLE:return te(n);default:return null}}function h(t,n,r){let i=a(t,e.FOLDER,u(n));return[t,i,a(i,l[n],r)]}var ne={async loadRoot({engine:t,run:n}){return(await t.introspect.listDatabases(n)).map(t=>o(null,e.DATABASE,t,!1,{database:t}))},async loadChildren(t,n){return n.type===e.DATABASE?f(t.engine,n.id,{database:n.text}):await m(t,n)??[]},objectPath(t,n,r){return h(a(null,e.DATABASE,t),n,r)},namespacePath(t){return[a(null,e.DATABASE,t)]}},re=class extends Error{constructor(e,t){super(`${e} does not support ${t}`),this.name=`UnsupportedQueryError`}};function ie(e,t,...n){let r=t.identifierQuote,i=t.identifierQuoteClose??r;return e.replace(/(.?)\{(\d+)\}(.?)/gs,(e,a,o,s)=>{let c=parseInt(o,10);if(c>=n.length)return e;let l=n[c];return a===r&&s===i?`${a}${l.replaceAll(i,i+i)}${s}`:a&&a===s&&t.stringQuotes.includes(a)?`${a}${ae(l,a,t.backslashEscapes)}${s}`:`${a}${l}${s}`})}function ae(e,t,n){let r=n?e.replaceAll(`\\`,`\\\\`):e;return r=r.replaceAll(t,t+t),r}function g(e){return String(e).padStart(2,`0`)}function oe(e){return`${e.getFullYear()}-${g(e.getMonth()+1)}-${g(e.getDate())} ${g(e.getHours())}:${g(e.getMinutes())}:${g(e.getSeconds())}`}var se=/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})/,ce=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),le=e=>`X'${e}'`;function ue(e,t,n=!1,r=le){if(e==null)return`NULL`;if(e instanceof Uint8Array)return r(ce(e));if(typeof e==`number`)return Number.isFinite(e)?String(e):`NULL`;if(typeof e==`bigint`)return e.toString();if(typeof e==`boolean`)return n?e?`TRUE`:`FALSE`:e?`1`:`0`;if(e instanceof Date)return`'${oe(e)}'`;let i;if(typeof e==`object`)try{i=JSON.stringify(e)}catch{i=String(e)}else{i=String(e);let t=i.match(se);t&&(i=`${t[1]} ${t[2]}`)}return`'${ae(i,`'`,t)}'`}function _(e){let t=e.fields.map(e=>e.name);return e.records.map(e=>{let n={};return t.forEach((t,r)=>{n[t]=e[r]}),n})}function v(e,t=``){return e==null?t:String(e)}function y(e){return e==null?null:String(e)}function b(e){if(e==null||e===``)return null;let t=Number(e);return Number.isFinite(t)?t:null}function x(e,t){return e.trim()||t}function S(e){let t=e.identifierQuote,n=e.identifierQuoteClose??t,r=e=>`${t}${e.replaceAll(n,n+n)}${n}`,i=t=>ue(t,e.syntax.backslashEscapes,e.booleanKeywords??!1,e.binaryLiteral),a=(e,t)=>e?`${r(e)}.${r(t)}`:r(t),o={identifierQuote:t,identifierQuoteClose:n,stringQuotes:e.syntax.doubleQuoteIsIdentifier?[`'`]:[`'`,`"`],backslashEscapes:e.syntax.backslashEscapes};return{id:e.id,label:e.label,capabilities:e.capabilities,introspect:e.introspect,explain:e.explain,tree:e.tree??ne,defaultPort:e.defaultPort,syntax:e.syntax,limitClause:(t,n=0)=>e.syntax.limitStyle===`top`?`OFFSET ${n} ROWS FETCH NEXT ${t} ROWS ONLY`:e.syntax.limitStyle===`fetch`?n>0?`OFFSET ${n} ROWS FETCH NEXT ${t} ROWS ONLY`:`FETCH FIRST ${t} ROWS ONLY`:n>0?`LIMIT ${t} OFFSET ${n}`:`LIMIT ${t}`,quoteIdentifier:r,quoteLiteral:i,qualify:a,ddl:e.ddl({quoteIdentifier:r,quoteLiteral:i,qualify:a}),rowIdExpression:e.rowIdExpression,hasQuery(t){return e.queries[t]!==void 0},getQuery(t,...n){let r=e.queries[t];if(r===void 0)throw new re(e.label,t);return ie(r,o,...n)},getDataTypes:()=>e.dataTypes,getDataTypesToJSON:()=>e.dataTypes.map(e=>[e,e]),getFunctions:()=>e.functions,getReservedWords:()=>e.reservedWords}}var de=0,fe=()=>`p${++de}`;function C(e,t={}){return{id:fe(),label:e,rows:null,actualRows:null,cost:null,timeMs:null,details:[],warnings:[],children:[],...t}}function w(e){if(e==null||e===``)return null;let t=typeof e==`number`?e:Number(String(e).replace(/,/g,``));return Number.isFinite(t)?t:null}function T(e){return e==null?``:typeof e==`object`?JSON.stringify(e):String(e)}function E(e){let t=e.replace(/[_-]+/g,` `).trim();return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}var pe=10;function D(e,t){return e===null||t===null||Math.max(e,t)<100?[]:(e===0||t===0?Math.max(e,t):Math.max(e/t,t/e))>pe?[`estimate-off`]:[]}function me(e,t){let n=new Map,r=new Map,i=[],a=[];for(let o of e){let e=t(o);if(e){if(e.id===null){a.push(e.node);continue}n.set(e.id,e.node),r.set(e.id,e.parent),i.push(e.id)}}for(let e of i){let t=n.get(e),i=r.get(e),o=i==null?void 0:n.get(i);o&&o!==t?o.children.push(t):a.push(t)}return a}var he=new Set([`Node Type`,`Plans`,`Plan Rows`,`Total Cost`,`Actual Rows`,`Actual Total Time`,`Relation Name`,`Index Name`,`Actual Loops`,`Startup Cost`,`Actual Startup Time`]);function ge(e){let t=T(e[`Node Type`])||`Node`,n=T(e.Strategy??e[`Join Type`]??e[`Partial Mode`]),r=T(e[`Relation Name`]??e[`Index Name`])||void 0,i=w(e[`Actual Loops`])??1,a=w(e[`Actual Rows`]),o=w(e[`Actual Total Time`]),s=w(e[`Plan Rows`]),c=[];t===`Seq Scan`&&c.push(`full-scan`),T(e[`Sort Method`]).toLowerCase().includes(`external`)&&c.push(`filesort`),c.push(...D(s,a));let l=Object.entries(e).filter(([e,t])=>!he.has(e)&&t!=null&&t!==``).map(([e,t])=>({label:e,value:T(t)})),u=Array.isArray(e.Plans)?e.Plans.map(ge):[];return C(n?`${t} (${n})`:t,{object:r,rows:s,actualRows:a===null?null:a*i,cost:w(e[`Total Cost`]),timeMs:o===null?null:o*i,details:l,warnings:c,children:u})}function O(e){return e.records[0]?.[0]}function _e(e){if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return null}}var ve={supportsAnalyze:!0,statements:(e,t)=>({statement:`EXPLAIN (${t?`ANALYZE, BUFFERS, `:``}FORMAT JSON) ${e}`}),parse:e=>{let t=O(e),n=typeof t==`string`?t:JSON.stringify(t,null,2),r=_e(t),i=Array.isArray(r)?r:r?[r]:[],a=[];for(let e of i){let t=e?.Plan;if(!t||typeof t!=`object`)continue;let n=ge(t),r=w(e[`Planning Time`]),i=w(e[`Execution Time`]);r!==null&&n.details.push({label:`Planning Time`,value:`${r} ms`}),i!==null&&n.details.push({label:`Execution Time`,value:`${i} ms`}),a.push(n)}return{roots:a,raw:n}}},ye=new Set([`table_name`,`access_type`,`key`,`rows_examined_per_scan`,`rows`,`r_rows`,`r_total_time_ms`,`query_cost`,`select_id`,`cost_info`]),be=new Set([`query_block`,`nested_loop`,`ordering_operation`,`grouping_operation`,`duplicates_removal`,`materialized_from_subquery`,`union_result`,`query_specifications`,`attached_subqueries`,`subqueries`,`optimized_away_subqueries`,`select_list_subqueries`,`having_subqueries`,`update_value_subqueries`,`block-nl-join`,`buffer_result`,`filesort`,`temporary_table`,`read_sorted_file`,`range-checked-for-each-record`,`insert_from`,`having_subquery`,`table`]);function k(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xe(e){let t=T(e.table_name)||`table`,n=T(e.access_type),r=T(e.key),i=w(e.rows_examined_per_scan??e.rows),a=w(e.r_rows),o=[];n===`ALL`&&o.push(`full-scan`),!r&&e.possible_keys==null&&n!==`system`&&n!==`const`&&o.push(`no-index`),e.using_filesort===!0&&o.push(`filesort`),e.using_temporary_table===!0&&o.push(`temporary`),o.push(...D(i,a));let s=[],c=[];for(let[t,n]of Object.entries(e))be.has(t)?c.push(...A(t,n)):!ye.has(t)&&n!=null&&n!==``&&s.push({label:E(t),value:T(n)});let l=k(e.cost_info)?w(e.cost_info.prefix_cost??e.cost_info.read_cost):null;return C(n?`${n.toUpperCase()} ${t}`:t,{object:t,rows:i,actualRows:a,cost:l,timeMs:w(e.r_total_time_ms),details:s,warnings:o,children:c})}function A(e,t){if(Array.isArray(t))return t.flatMap(t=>A(e,t));if(!k(t))return[];if(e===`table`||`table_name`in t)return[xe(t)];let n=[],r=[];for(let[e,i]of Object.entries(t))ye.has(e)||(be.has(e)||Array.isArray(i)||k(i)?r.push(...A(e,i)):i!=null&&i!==``&&n.push({label:E(e),value:T(i)}));let i=[];(e===`filesort`||t.using_filesort===!0)&&i.push(`filesort`),(e===`temporary_table`||t.using_temporary_table===!0)&&i.push(`temporary`);let a=w(t.select_id),o=e===`query_block`&&a!==null?`Query block #${a}`:E(e),s=k(t.cost_info)?w(t.cost_info.query_cost):null;return e===`nested_loop`?r:[C(o,{rows:w(t.rows),cost:s,details:n,warnings:i,children:r})]}var Se=/^(\s*)->\s*(.*)$/,Ce=/\s*\(cost=([\d.e+-]+)(?:\.\.[\d.e+-]+)? rows=([\d.e+-]+)\)/,we=/\s*\(actual time=([\d.e+-]+)\.\.([\d.e+-]+) rows=([\d.e+-]+) loops=(\d+)\)/,Te=/\s*\(never executed\)/;function Ee(e){let t=/\bon\s+`?([A-Za-z0-9_$]+)`?/.exec(e),n=/\busing\s+`?([A-Za-z0-9_$]+)`?/.exec(e);return{object:t?.[1],index:n?.[1]}}function De(e,t,n){let r=[];return/^Table scan on /.test(e)&&r.push(`full-scan`),/^Sort[: ]/.test(e)&&r.push(`filesort`),/^(Materialize|Temporary table)/.test(e)&&r.push(`temporary`),r.push(...D(t,n)),r}function Oe(e){let t=[],n=[];for(let r of e.split(`
@@ -1 +1 @@
1
- import{r as e}from"./hePW80VL.js";import{c as t,h as n,n as r,t as i}from"./BkIkgVK5.js";import{l as a,m as o,t as s}from"./C0O3rJzW.js";import{a as c,i as l,n as u,r as d,t as f}from"./DL6u_OmT.js";import{t as p}from"./DC8XCjJ3.js";import{a as m}from"./Dd9quIZg.js";import{n as h}from"./Dht5Mpyb.js";import{t as g}from"./3z4eHGF-.js";import{H as _,_ as v,c as y,g as b,h as x,ot as S}from"./BKoh-tKR.js";import{a as ee,i as te,n as ne,o as C,t as re}from"./Cg4DfVr4.js";var w=e(n(),1),T=a(),ie=e=>e instanceof Error?e.message:String(e),E=e=>e.hostName||e.host||e.file||e.id,D=5e4;function O({id:e,label:t,side:n,onChange:r,connections:i,disabled:a}){let{t:s}=o(),[p,g]=(0,w.useState)([]),[_,v]=(0,w.useState)([]),b=i.find(e=>e.id===n.connectionId);return(0,w.useEffect)(()=>{if(!b?.serverConnectionId)return;let e=!1;return(async()=>{try{let t=await h(b.id).introspect.listDatabases(m(b.serverConnectionId));if(e)return;g(t),t.includes(n.database)||r({connectionId:b.id,database:t[0]??``,table:``})}catch{e||g([])}})(),()=>{e=!0}},[b?.id,b?.serverConnectionId]),(0,w.useEffect)(()=>{if(!b?.serverConnectionId||!n.database)return;let e=!1;return(async()=>{try{let t=await h(b.id).introspect.listTables(m(b.serverConnectionId),n.database);if(e)return;let i=t.map(e=>e.name);v(i),n.table&&!i.includes(n.table)&&r({...n,table:``})}catch{e||v([])}})(),()=>{e=!0}},[b?.id,b?.serverConnectionId,n.database]),(0,T.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3`,children:[(0,T.jsx)(y,{className:`font-medium`,children:t}),(0,T.jsxs)(f,{value:n.connectionId,onValueChange:e=>r({connectionId:e,database:``,table:``}),disabled:a,children:[(0,T.jsx)(l,{id:`${e}-conn`,className:`w-full`,children:(0,T.jsx)(c,{placeholder:s(`database.diff.pickConnection`)})}),(0,T.jsx)(u,{children:i.map(e=>(0,T.jsx)(d,{value:e.id,children:E(e)},e.id))})]}),(0,T.jsxs)(f,{value:n.database,onValueChange:e=>r({...n,database:e,table:``}),disabled:a||p.length===0,children:[(0,T.jsx)(l,{id:`${e}-db`,className:`w-full`,children:(0,T.jsx)(c,{placeholder:s(`database.diff.pickDatabase`)})}),(0,T.jsx)(u,{children:p.map(e=>(0,T.jsx)(d,{value:e,children:e},e))})]}),(0,T.jsxs)(f,{value:n.table,onValueChange:e=>r({...n,table:e}),disabled:a||_.length===0,children:[(0,T.jsx)(l,{id:`${e}-table`,className:`w-full`,children:(0,T.jsx)(c,{placeholder:s(`database.dataDiff.pickTable`)})}),(0,T.jsx)(u,{children:_.map(e=>(0,T.jsx)(d,{value:e,children:e},e))})]})]})}async function k(e,t){let n=await _({connectionId:e.connectionId,database:e.database,table:e.table,limit:D,onProgress:t}),r=[];for await(let e of n.pages)r.push(...e);return{rows:r,columns:n.fields.map(e=>e.name),capped:r.length>=D}}function A({diff:e,row:t,other:n,changed:r}){let{t:i}=o(),a=[...e.keyColumns,...e.compareColumns];return(0,T.jsxs)(`table`,{className:`w-full text-xs font-mono`,children:[(0,T.jsx)(`thead`,{className:`text-muted-foreground`,children:(0,T.jsxs)(`tr`,{children:[(0,T.jsx)(`th`,{className:`text-left font-normal pr-2`,children:i(`database.diff.column`)}),(0,T.jsx)(`th`,{className:`text-left font-normal pr-2`,children:i(`database.diff.source`)}),(0,T.jsx)(`th`,{className:`text-left font-normal`,children:i(`database.diff.target`)})]})}),(0,T.jsx)(`tbody`,{children:a.map(e=>(0,T.jsxs)(`tr`,{className:r?.includes(e)?`text-amber-600 dark:text-amber-400`:``,children:[(0,T.jsx)(`td`,{className:`pr-2 align-top whitespace-nowrap`,children:e}),(0,T.jsx)(`td`,{className:`pr-2 align-top break-all`,children:b(t[e])}),(0,T.jsx)(`td`,{className:`align-top break-all`,children:n?b(n[e]):`—`})]},e))})]})}function j(){let{t:e}=o(),n=r(e=>e.activeDialog),a=r(e=>e.closeDialog),c=i(`data-diff`),l=p(e=>e.activeConnections),u=(0,w.useMemo)(()=>l.filter(e=>e.serverConnectionId),[l]),d=p(e=>e.activeConnectionId),f=n===`data-diff`,[_,y]=(0,w.useState)(()=>c&&u.some(e=>e.id===c.connectionId)?{connectionId:c.connectionId,database:c.database,table:c.table}:{connectionId:d&&u.some(e=>e.id===d)?d:u[0]?.id??``,database:``,table:``}),[E,j]=(0,w.useState)(()=>({connectionId:u.find(e=>e.id!==_.connectionId)?.id??_.connectionId,database:``,table:``})),[M,N]=(0,w.useState)([]),[P,F]=(0,w.useState)(null),[I,L]=(0,w.useState)(!1),[R,z]=(0,w.useState)(`changed`),[B,V]=(0,w.useState)(0),[H,ae]=(0,w.useState)(!1),[U,W]=(0,w.useState)(!1),[G,K]=(0,w.useState)({source:null,target:null}),[q,J]=(0,w.useState)(null),oe=e=>j(e.database&&!e.table&&_.table?{...e,table:_.table}:e),Y=_.connectionId===E.connectionId&&_.database===E.database&&_.table===E.table,se=!!_.table&&!!E.table&&!Y,X=E.connectionId?h(E.connectionId):null;async function ce(){W(!0),J(null),F(null);try{let n=p.getState().activeConnections.find(e=>e.id===_.connectionId);if(!n?.serverConnectionId)throw Error(e(`services.query.notConnected`));let r=await h(_.connectionId).introspect.getPrimaryKeys(m(n.serverConnectionId),_.database,_.table);if(r.length===0)throw Error(e(`database.dataDiff.noPrimaryKey`,{table:_.table}));K({source:{loaded:0,total:null},target:{loaded:0,total:null}});let[i,a]=await Promise.all([k(_,e=>K(t=>({...t,source:e}))),k(E,e=>K(t=>({...t,target:e})))]);if(r.some(e=>!a.columns.includes(e)))throw Error(e(`database.dataDiff.keyMissingInTarget`,{columns:r.join(`, `)}));let o=v(i.rows,a.rows,r,i.columns,a.columns);N(r),L(i.capped||a.capped),F(o),z(o.changed.length>0?`changed`:o.added.length>0?`added`:`removed`),V(0),g(`compare_data`),t(`data_diff`,{source_dbms:h(_.connectionId).id,target_dbms:X?.id??`unknown`,added:o.added.length,changed:o.changed.length,removed:o.removed.length})}catch(e){J(ie(e))}finally{W(!1),K({source:null,target:null})}}let Z=e=>e?e.total===null?e.loaded.toLocaleString():`${e.loaded.toLocaleString()} / ${e.total.toLocaleString()}`:``,Q=(0,w.useMemo)(()=>P&&X?x(P,X,{database:E.database,table:E.table},{includeDeletes:H}):``,[P,X,E.database,E.table,H]);function le(){Q&&(S(E.connectionId,Q,E.database,e(`database.dataDiff.tabTitle`,{table:E.table})),a())}let $=P?R===`added`?P.added:R===`removed`?P.removed:P.changed.map(e=>e.source):[],ue=!!P&&P.added.length+P.changed.length+P.removed.length>0,de=e=>M.map(t=>b(e[t])).join(`, `);return(0,T.jsx)(re,{open:f,onOpenChange:e=>{e||a()},children:(0,T.jsxs)(ne,{className:`sm:max-w-[900px]`,children:[(0,T.jsx)(ee,{children:(0,T.jsx)(C,{children:e(`database.dataDiff.title`)})}),(0,T.jsxs)(`div`,{className:`space-y-3`,children:[(0,T.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,T.jsx)(O,{id:`ddiff-source`,label:e(`database.diff.source`),side:_,onChange:y,connections:u,disabled:U}),(0,T.jsx)(O,{id:`ddiff-target`,label:e(`database.diff.target`),side:E,onChange:oe,connections:u,disabled:U})]}),(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`database.dataDiff.hint`,{cap:D.toLocaleString()})}),Y&&_.table&&(0,T.jsx)(`p`,{className:`text-xs text-destructive`,children:e(`database.dataDiff.sameSide`)}),q&&(0,T.jsx)(`p`,{className:`text-sm text-destructive whitespace-pre-wrap`,children:q}),U&&(G.source||G.target)&&(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`database.dataDiff.loading`,{source:Z(G.source),target:Z(G.target)})}),P&&(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-xs`,children:[(0,T.jsx)(`span`,{className:`text-muted-foreground`,children:e(`database.dataDiff.summary`,{key:M.join(`, `),added:P.added.length,changed:P.changed.length,removed:P.removed.length,identical:P.identical})}),I&&(0,T.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:e(`database.dataDiff.capped`,{cap:D.toLocaleString()})}),(P.sourceOnlyColumns.length>0||P.targetOnlyColumns.length>0)&&(0,T.jsx)(`span`,{className:`text-muted-foreground`,children:e(`database.dataDiff.ignoredColumns`,{columns:[...P.sourceOnlyColumns,...P.targetOnlyColumns].join(`, `)})})]}),(0,T.jsx)(`div`,{className:`flex gap-1 text-xs`,children:[`added`,`changed`,`removed`].map(t=>(0,T.jsx)(`button`,{type:`button`,onClick:()=>{z(t),V(0)},className:`rounded border px-2 py-0.5 ${R===t?`bg-accent`:``}`,children:e(`database.dataDiff.${t}`,{count:t===`added`?P.added.length:t===`removed`?P.removed.length:P.changed.length})},t))}),(0,T.jsxs)(`div`,{className:`grid grid-cols-[240px_1fr] gap-3 h-[280px]`,children:[(0,T.jsxs)(`ul`,{className:`overflow-auto rounded-md border text-sm font-mono`,children:[$.slice(0,2e3).map((e,t)=>(0,T.jsx)(`li`,{className:`px-2 py-1 cursor-pointer ${B===t?`bg-accent`:``}`,onClick:()=>V(t),children:de(e)},t)),$.length===0&&(0,T.jsx)(`li`,{className:`px-2 py-1 text-muted-foreground`,children:e(`database.dataDiff.none`)}),$.length>2e3&&(0,T.jsx)(`li`,{className:`px-2 py-1 text-muted-foreground`,children:e(`database.dataDiff.more`,{count:$.length-2e3})})]}),(0,T.jsx)(`div`,{className:`overflow-auto rounded-md border p-2`,children:$[B]?R===`changed`?(0,T.jsx)(A,{diff:P,row:P.changed[B].source,other:P.changed[B].target,changed:P.changed[B].columns}):R===`removed`?(0,T.jsx)(A,{diff:P,row:{},other:$[B]}):(0,T.jsx)(A,{diff:P,row:$[B]}):(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`database.diff.selectTable`)})})]}),(0,T.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:H,onChange:e=>ae(e.target.checked)}),(0,T.jsx)(`span`,{className:H?`text-destructive`:``,children:e(`database.dataDiff.includeDeletes`)})]})]})]}),(0,T.jsxs)(te,{children:[(0,T.jsx)(s,{variant:`outline`,onClick:a,children:e(`database.diff.close`)}),(0,T.jsx)(s,{variant:`secondary`,onClick:()=>{ce()},disabled:!se||U,children:e(U?`database.diff.comparing`:`database.diff.compare`)}),(0,T.jsx)(s,{onClick:le,disabled:!ue,children:e(`database.diff.openScript`)})]})]})})}export{j as DataDiffDialog};
1
+ import{r as e}from"./hePW80VL.js";import{c as t,h as n,n as r,t as i}from"./B1pia_Rg.js";import{l as a,m as o,t as s}from"./pjlgs2cl.js";import{a as c,i as l,n as u,r as d,t as f}from"./CiFkP-9S.js";import{t as p}from"./BCmzDvBt.js";import{a as m}from"./CS2mpWDL.js";import{n as h}from"./pneb1la9.js";import{t as g}from"./DPdwSUSw.js";import{H as _,_ as v,c as y,g as b,h as x,ot as S}from"./Bhquh17w.js";import{a as ee,i as te,n as ne,o as C,t as re}from"./BgkATqP8.js";var w=e(n(),1),T=a(),ie=e=>e instanceof Error?e.message:String(e),E=e=>e.hostName||e.host||e.file||e.id,D=5e4;function O({id:e,label:t,side:n,onChange:r,connections:i,disabled:a}){let{t:s}=o(),[p,g]=(0,w.useState)([]),[_,v]=(0,w.useState)([]),b=i.find(e=>e.id===n.connectionId);return(0,w.useEffect)(()=>{if(!b?.serverConnectionId)return;let e=!1;return(async()=>{try{let t=await h(b.id).introspect.listDatabases(m(b.serverConnectionId));if(e)return;g(t),t.includes(n.database)||r({connectionId:b.id,database:t[0]??``,table:``})}catch{e||g([])}})(),()=>{e=!0}},[b?.id,b?.serverConnectionId]),(0,w.useEffect)(()=>{if(!b?.serverConnectionId||!n.database)return;let e=!1;return(async()=>{try{let t=await h(b.id).introspect.listTables(m(b.serverConnectionId),n.database);if(e)return;let i=t.map(e=>e.name);v(i),n.table&&!i.includes(n.table)&&r({...n,table:``})}catch{e||v([])}})(),()=>{e=!0}},[b?.id,b?.serverConnectionId,n.database]),(0,T.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3`,children:[(0,T.jsx)(y,{className:`font-medium`,children:t}),(0,T.jsxs)(f,{value:n.connectionId,onValueChange:e=>r({connectionId:e,database:``,table:``}),disabled:a,children:[(0,T.jsx)(l,{id:`${e}-conn`,className:`w-full`,children:(0,T.jsx)(c,{placeholder:s(`database.diff.pickConnection`)})}),(0,T.jsx)(u,{children:i.map(e=>(0,T.jsx)(d,{value:e.id,children:E(e)},e.id))})]}),(0,T.jsxs)(f,{value:n.database,onValueChange:e=>r({...n,database:e,table:``}),disabled:a||p.length===0,children:[(0,T.jsx)(l,{id:`${e}-db`,className:`w-full`,children:(0,T.jsx)(c,{placeholder:s(`database.diff.pickDatabase`)})}),(0,T.jsx)(u,{children:p.map(e=>(0,T.jsx)(d,{value:e,children:e},e))})]}),(0,T.jsxs)(f,{value:n.table,onValueChange:e=>r({...n,table:e}),disabled:a||_.length===0,children:[(0,T.jsx)(l,{id:`${e}-table`,className:`w-full`,children:(0,T.jsx)(c,{placeholder:s(`database.dataDiff.pickTable`)})}),(0,T.jsx)(u,{children:_.map(e=>(0,T.jsx)(d,{value:e,children:e},e))})]})]})}async function k(e,t){let n=await _({connectionId:e.connectionId,database:e.database,table:e.table,limit:D,onProgress:t}),r=[];for await(let e of n.pages)r.push(...e);return{rows:r,columns:n.fields.map(e=>e.name),capped:r.length>=D}}function A({diff:e,row:t,other:n,changed:r}){let{t:i}=o(),a=[...e.keyColumns,...e.compareColumns];return(0,T.jsxs)(`table`,{className:`w-full text-xs font-mono`,children:[(0,T.jsx)(`thead`,{className:`text-muted-foreground`,children:(0,T.jsxs)(`tr`,{children:[(0,T.jsx)(`th`,{className:`text-left font-normal pr-2`,children:i(`database.diff.column`)}),(0,T.jsx)(`th`,{className:`text-left font-normal pr-2`,children:i(`database.diff.source`)}),(0,T.jsx)(`th`,{className:`text-left font-normal`,children:i(`database.diff.target`)})]})}),(0,T.jsx)(`tbody`,{children:a.map(e=>(0,T.jsxs)(`tr`,{className:r?.includes(e)?`text-amber-600 dark:text-amber-400`:``,children:[(0,T.jsx)(`td`,{className:`pr-2 align-top whitespace-nowrap`,children:e}),(0,T.jsx)(`td`,{className:`pr-2 align-top break-all`,children:b(t[e])}),(0,T.jsx)(`td`,{className:`align-top break-all`,children:n?b(n[e]):`—`})]},e))})]})}function j(){let{t:e}=o(),n=r(e=>e.activeDialog),a=r(e=>e.closeDialog),c=i(`data-diff`),l=p(e=>e.activeConnections),u=(0,w.useMemo)(()=>l.filter(e=>e.serverConnectionId),[l]),d=p(e=>e.activeConnectionId),f=n===`data-diff`,[_,y]=(0,w.useState)(()=>c&&u.some(e=>e.id===c.connectionId)?{connectionId:c.connectionId,database:c.database,table:c.table}:{connectionId:d&&u.some(e=>e.id===d)?d:u[0]?.id??``,database:``,table:``}),[E,j]=(0,w.useState)(()=>({connectionId:u.find(e=>e.id!==_.connectionId)?.id??_.connectionId,database:``,table:``})),[M,N]=(0,w.useState)([]),[P,F]=(0,w.useState)(null),[I,L]=(0,w.useState)(!1),[R,z]=(0,w.useState)(`changed`),[B,V]=(0,w.useState)(0),[H,ae]=(0,w.useState)(!1),[U,W]=(0,w.useState)(!1),[G,K]=(0,w.useState)({source:null,target:null}),[q,J]=(0,w.useState)(null),oe=e=>j(e.database&&!e.table&&_.table?{...e,table:_.table}:e),Y=_.connectionId===E.connectionId&&_.database===E.database&&_.table===E.table,se=!!_.table&&!!E.table&&!Y,X=E.connectionId?h(E.connectionId):null;async function ce(){W(!0),J(null),F(null);try{let n=p.getState().activeConnections.find(e=>e.id===_.connectionId);if(!n?.serverConnectionId)throw Error(e(`services.query.notConnected`));let r=await h(_.connectionId).introspect.getPrimaryKeys(m(n.serverConnectionId),_.database,_.table);if(r.length===0)throw Error(e(`database.dataDiff.noPrimaryKey`,{table:_.table}));K({source:{loaded:0,total:null},target:{loaded:0,total:null}});let[i,a]=await Promise.all([k(_,e=>K(t=>({...t,source:e}))),k(E,e=>K(t=>({...t,target:e})))]);if(r.some(e=>!a.columns.includes(e)))throw Error(e(`database.dataDiff.keyMissingInTarget`,{columns:r.join(`, `)}));let o=v(i.rows,a.rows,r,i.columns,a.columns);N(r),L(i.capped||a.capped),F(o),z(o.changed.length>0?`changed`:o.added.length>0?`added`:`removed`),V(0),g(`compare_data`),t(`data_diff`,{source_dbms:h(_.connectionId).id,target_dbms:X?.id??`unknown`,added:o.added.length,changed:o.changed.length,removed:o.removed.length})}catch(e){J(ie(e))}finally{W(!1),K({source:null,target:null})}}let Z=e=>e?e.total===null?e.loaded.toLocaleString():`${e.loaded.toLocaleString()} / ${e.total.toLocaleString()}`:``,Q=(0,w.useMemo)(()=>P&&X?x(P,X,{database:E.database,table:E.table},{includeDeletes:H}):``,[P,X,E.database,E.table,H]);function le(){Q&&(S(E.connectionId,Q,E.database,e(`database.dataDiff.tabTitle`,{table:E.table})),a())}let $=P?R===`added`?P.added:R===`removed`?P.removed:P.changed.map(e=>e.source):[],ue=!!P&&P.added.length+P.changed.length+P.removed.length>0,de=e=>M.map(t=>b(e[t])).join(`, `);return(0,T.jsx)(re,{open:f,onOpenChange:e=>{e||a()},children:(0,T.jsxs)(ne,{className:`sm:max-w-[900px]`,children:[(0,T.jsx)(ee,{children:(0,T.jsx)(C,{children:e(`database.dataDiff.title`)})}),(0,T.jsxs)(`div`,{className:`space-y-3`,children:[(0,T.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,T.jsx)(O,{id:`ddiff-source`,label:e(`database.diff.source`),side:_,onChange:y,connections:u,disabled:U}),(0,T.jsx)(O,{id:`ddiff-target`,label:e(`database.diff.target`),side:E,onChange:oe,connections:u,disabled:U})]}),(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`database.dataDiff.hint`,{cap:D.toLocaleString()})}),Y&&_.table&&(0,T.jsx)(`p`,{className:`text-xs text-destructive`,children:e(`database.dataDiff.sameSide`)}),q&&(0,T.jsx)(`p`,{className:`text-sm text-destructive whitespace-pre-wrap`,children:q}),U&&(G.source||G.target)&&(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`database.dataDiff.loading`,{source:Z(G.source),target:Z(G.target)})}),P&&(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-xs`,children:[(0,T.jsx)(`span`,{className:`text-muted-foreground`,children:e(`database.dataDiff.summary`,{key:M.join(`, `),added:P.added.length,changed:P.changed.length,removed:P.removed.length,identical:P.identical})}),I&&(0,T.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:e(`database.dataDiff.capped`,{cap:D.toLocaleString()})}),(P.sourceOnlyColumns.length>0||P.targetOnlyColumns.length>0)&&(0,T.jsx)(`span`,{className:`text-muted-foreground`,children:e(`database.dataDiff.ignoredColumns`,{columns:[...P.sourceOnlyColumns,...P.targetOnlyColumns].join(`, `)})})]}),(0,T.jsx)(`div`,{className:`flex gap-1 text-xs`,children:[`added`,`changed`,`removed`].map(t=>(0,T.jsx)(`button`,{type:`button`,onClick:()=>{z(t),V(0)},className:`rounded border px-2 py-0.5 ${R===t?`bg-accent`:``}`,children:e(`database.dataDiff.${t}`,{count:t===`added`?P.added.length:t===`removed`?P.removed.length:P.changed.length})},t))}),(0,T.jsxs)(`div`,{className:`grid grid-cols-[240px_1fr] gap-3 h-[280px]`,children:[(0,T.jsxs)(`ul`,{className:`overflow-auto rounded-md border text-sm font-mono`,children:[$.slice(0,2e3).map((e,t)=>(0,T.jsx)(`li`,{className:`px-2 py-1 cursor-pointer ${B===t?`bg-accent`:``}`,onClick:()=>V(t),children:de(e)},t)),$.length===0&&(0,T.jsx)(`li`,{className:`px-2 py-1 text-muted-foreground`,children:e(`database.dataDiff.none`)}),$.length>2e3&&(0,T.jsx)(`li`,{className:`px-2 py-1 text-muted-foreground`,children:e(`database.dataDiff.more`,{count:$.length-2e3})})]}),(0,T.jsx)(`div`,{className:`overflow-auto rounded-md border p-2`,children:$[B]?R===`changed`?(0,T.jsx)(A,{diff:P,row:P.changed[B].source,other:P.changed[B].target,changed:P.changed[B].columns}):R===`removed`?(0,T.jsx)(A,{diff:P,row:{},other:$[B]}):(0,T.jsx)(A,{diff:P,row:$[B]}):(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`database.diff.selectTable`)})})]}),(0,T.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:H,onChange:e=>ae(e.target.checked)}),(0,T.jsx)(`span`,{className:H?`text-destructive`:``,children:e(`database.dataDiff.includeDeletes`)})]})]})]}),(0,T.jsxs)(te,{children:[(0,T.jsx)(s,{variant:`outline`,onClick:a,children:e(`database.diff.close`)}),(0,T.jsx)(s,{variant:`secondary`,onClick:()=>{ce()},disabled:!se||U,children:e(U?`database.diff.comparing`:`database.diff.compare`)}),(0,T.jsx)(s,{onClick:le,disabled:!ue,children:e(`database.diff.openScript`)})]})]})})}export{j as DataDiffDialog};
@@ -1 +1 @@
1
- import{l as e}from"./C0O3rJzW.js";import{z as t}from"./BKoh-tKR.js";var n=e();function r({id:e,checked:r,onChange:i,label:a,hint:o,pro:s}){return(0,n.jsxs)(`label`,{htmlFor:e,className:`flex cursor-pointer items-start gap-3 rounded-md border p-3 hover:bg-accent/40`,children:[(0,n.jsx)(`input`,{id:e,type:`checkbox`,checked:r,onChange:e=>i(e.target.checked),className:`mt-0.5 size-4 accent-primary`}),(0,n.jsxs)(`span`,{className:`grid flex-1 gap-0.5`,children:[(0,n.jsxs)(`span`,{className:`flex items-center text-sm font-medium`,children:[a,s?(0,n.jsx)(t,{}):null]}),(0,n.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o})]})]})}export{r as t};
1
+ import{l as e}from"./pjlgs2cl.js";import{z as t}from"./Bhquh17w.js";var n=e();function r({id:e,checked:r,onChange:i,label:a,hint:o,pro:s}){return(0,n.jsxs)(`label`,{htmlFor:e,className:`flex cursor-pointer items-start gap-3 rounded-md border p-3 hover:bg-accent/40`,children:[(0,n.jsx)(`input`,{id:e,type:`checkbox`,checked:r,onChange:e=>i(e.target.checked),className:`mt-0.5 size-4 accent-primary`}),(0,n.jsxs)(`span`,{className:`grid flex-1 gap-0.5`,children:[(0,n.jsxs)(`span`,{className:`flex items-center text-sm font-medium`,children:[a,s?(0,n.jsx)(t,{}):null]}),(0,n.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o})]})]})}export{r as t};
@@ -1,2 +1,2 @@
1
- import{r as e}from"./hePW80VL.js";import{h as t,n,t as r}from"./BkIkgVK5.js";import{a as i,l as a,m as o,t as s}from"./C0O3rJzW.js";import{t as c}from"./DC8XCjJ3.js";import{n as l}from"./DP94Ond0.js";import{a as u}from"./Dd9quIZg.js";import{l as d,t as f}from"./Bcc7p7-f.js";import{Dt as p,Ft as m,Pt as h,ct as g,d as _,f as v,kt as y,m as b,p as x,zt as S}from"./BKoh-tKR.js";import{a as C,i as w,n as ee,o as T,r as E,t as D}from"./Cg4DfVr4.js";var O=i(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]),k=e(t(),1);function A(e){let t=e.slice(e.indexOf(`(`)+1,e.lastIndexOf(`)`)),n=[],r=/'((?:[^']|'')*)'/g,i;for(;i=r.exec(t);)n.push(i[1].replaceAll(`''`,`'`));return n}function j(e,t={}){let{oracleDate:n=!1}=t,r=e.type.trim(),i=r.toLowerCase(),a=/\bunsigned\b/.test(i);if(/^enum\(/.test(i))return{kind:`enum`,options:A(r)};if(/^set\(/.test(i))return{kind:`set`,options:A(r)};if(/^(tinyint\(1\)|bool|boolean|bit\(1\)|bit)(?![\w(])/.test(i))return{kind:`boolean`};let o=/^number(?:\((\d+|\*)(?:,\s*(-?\d+))?\))?$/.exec(i);if(o)return o[2]&&Number(o[2])>0?{kind:`decimal`}:o[1]?{kind:`integer`}:{kind:`decimal`};if(/^(tinyint|smallint|mediumint|int|integer|bigint|int2|int4|int8|serial|bigserial|smallserial)\b/.test(i))return{kind:`integer`,unsigned:a};if(/^(decimal|numeric|float|double|real|money|float4|float8|double precision)\b/.test(i))return{kind:`decimal`,unsigned:a};if(/^(datetime2|datetime|timestamp|smalldatetime|datetimeoffset)\b/.test(i))return{kind:`datetime`};if(/^date\b/.test(i))return{kind:n?`datetime`:`date`};if(/^(time|timetz)\b/.test(i))return{kind:`time`};if(/^(json|jsonb)\b/.test(i))return{kind:`json`};if(/^(uuid|uniqueidentifier)\b/.test(i))return{kind:`uuid`};if(/^(blob|tinyblob|mediumblob|longblob|binary|varbinary|bytea|raw|image|bfile)\b/.test(i))return{kind:`binary`};if(/^(text|ntext|tinytext|mediumtext|longtext|clob|nclob|long)\b/.test(i)||/^n?(?:var)?char2?\(max\)/.test(i))return{kind:`text`};let s=/^n?(?:var)?char2?(?:acter)?(?:\s+varying)?\((\d+)(?:\s+(?:char|byte))?\)/.exec(i);return s?{kind:`string`,maxLength:Number(s[1])}:{kind:`string`}}var M=/auto_increment|identity|generated/i;function N(e){return M.test(e.extra)||/^(serial|bigserial|smallserial)\b/i.test(e.type)?{mode:`auto`,text:``}:e.defaultValue===null?e.nullable?{mode:`null`,text:``}:{mode:`value`,text:``}:{mode:`default`,text:``}}function P(e){return e==null?{mode:`keep`,text:``}:{mode:`keep`,text:F(e)}}function F(e){if(e==null)return``;if(typeof e==`object`){if(ArrayBuffer.isView(e))return``;if(e instanceof Date)return e.toISOString();try{return JSON.stringify(e,null,2)}catch{return String(e)}}return String(e)}function I(e,t){let n=t.trim();switch(e.kind){case`integer`:{if(!/^[+-]?\d+$/.test(n))return{error:`integer`};if(e.unsigned&&n.startsWith(`-`))return{error:`unsigned`};let t=Number(n);return{value:Number.isSafeInteger(t)?t:BigInt(n)}}case`decimal`:return n===``||Number.isNaN(Number(n))?{error:`number`}:{value:Number(n)};case`boolean`:return{value:n===`true`||n===`1`};case`json`:try{return{value:JSON.parse(n===``?`null`:n)}}catch{return{error:`json`}}case`set`:return{value:n};case`date`:return n&&!/^\d{4}-\d{2}-\d{2}$/.test(n)?{error:`date`}:{value:n};case`datetime`:return n&&!/^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}(:\d{2}(\.\d+)?)?)?([+-]\d{2}:?\d{2}|Z)?$/.test(n)?{error:`datetime`}:{value:n};case`time`:return n&&!/^-?\d{1,3}:\d{2}(:\d{2}(\.\d+)?)?$/.test(n)?{error:`time`}:{value:n};default:return{value:t}}}var L=a(),R={integer:`result.rowForm.invalid.integer`,unsigned:`result.rowForm.invalid.unsigned`,number:`result.rowForm.invalid.number`,json:`result.rowForm.invalid.json`,date:`result.rowForm.invalid.date`,datetime:`result.rowForm.invalid.datetime`,time:`result.rowForm.invalid.time`};function z(e){return String(e).padStart(2,`0`)}function B(e){let t=new Date,n=`${t.getFullYear()}-${z(t.getMonth()+1)}-${z(t.getDate())}`,r=`${z(t.getHours())}:${z(t.getMinutes())}:${z(t.getSeconds())}`;return e===`date`?n:e===`time`?r:`${n} ${r}`}function V(e){let t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e.trim());if(!t)return;let n=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]));return Number.isNaN(n.getTime())?void 0:n}function H({spec:e,state:t,disabled:n,onText:r}){let{t:i}=o(),a=`w-full rounded border bg-background px-2 py-1 text-sm font-mono outline-none focus:ring-1 focus:ring-primary disabled:opacity-50`;switch(e.kind){case`boolean`:return(0,L.jsxs)(`select`,{className:a,value:t.text===`true`||t.text===`1`?`true`:`false`,onChange:e=>r(e.target.value),disabled:n,children:[(0,L.jsx)(`option`,{value:`true`,children:`TRUE`}),(0,L.jsx)(`option`,{value:`false`,children:`FALSE`})]});case`enum`:return(0,L.jsxs)(`select`,{className:a,value:t.text,onChange:e=>r(e.target.value),disabled:n,children:[!e.options?.includes(t.text)&&(0,L.jsx)(`option`,{value:t.text,children:t.text||`—`}),e.options?.map(e=>(0,L.jsx)(`option`,{value:e,children:e},e))]});case`set`:{let i=new Set(t.text.split(`,`).map(e=>e.trim()).filter(Boolean));return(0,L.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 rounded border bg-background px-2 py-1.5`,children:e.options?.map(t=>(0,L.jsxs)(`label`,{className:`flex items-center gap-1 text-xs font-mono`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`accent-primary`,checked:i.has(t),disabled:n,onChange:n=>{let a=new Set(i);n.target.checked?a.add(t):a.delete(t),r(e.options.filter(e=>a.has(e)).join(`,`))}}),t]},t))})}case`integer`:case`decimal`:return(0,L.jsx)(`input`,{className:`${a} tabular-nums`,inputMode:`decimal`,value:t.text,onChange:e=>r(e.target.value),disabled:n,placeholder:e.kind===`integer`?`0`:`0.00`});case`date`:case`datetime`:{let[o,s]=t.text.trim().split(/[ T]/);return(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`input`,{className:`${a} flex-1`,value:t.text,onChange:e=>r(e.target.value),disabled:n,placeholder:e.kind===`date`?`YYYY-MM-DD`:`YYYY-MM-DD HH:MM:SS`}),(0,L.jsxs)(v,{children:[(0,L.jsx)(b,{asChild:!0,children:(0,L.jsx)(`button`,{type:`button`,className:`rounded border bg-background p-1.5 text-muted-foreground hover:text-foreground disabled:opacity-50`,disabled:n,title:i(`result.rowForm.pickDate`),children:(0,L.jsx)(S,{className:`size-3.5`})})}),(0,L.jsx)(x,{className:`w-auto p-0`,align:`end`,children:(0,L.jsx)(_,{mode:`single`,selected:V(o??``),defaultMonth:V(o??``),onSelect:t=>{if(!t)return;let n=`${t.getFullYear()}-${z(t.getMonth()+1)}-${z(t.getDate())}`;r(e.kind===`date`?n:`${n} ${s||`00:00:00`}`)}})})]}),(0,L.jsx)(`button`,{type:`button`,className:`rounded border bg-background px-1.5 py-1 text-[10px] text-muted-foreground hover:text-foreground disabled:opacity-50`,disabled:n,onClick:()=>r(B(e.kind)),title:i(`result.rowForm.now`),children:(0,L.jsx)(h,{className:`size-3.5`})})]})}case`time`:return(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`input`,{className:`${a} flex-1`,value:t.text,onChange:e=>r(e.target.value),disabled:n,placeholder:`HH:MM:SS`}),(0,L.jsx)(`button`,{type:`button`,className:`rounded border bg-background px-1.5 py-1 text-muted-foreground hover:text-foreground disabled:opacity-50`,disabled:n,onClick:()=>r(B(`time`)),title:i(`result.rowForm.now`),children:(0,L.jsx)(h,{className:`size-3.5`})})]});case`json`:{let e=!0;try{t.text.trim()&&JSON.parse(t.text)}catch{e=!1}return(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`textarea`,{className:`${a} min-h-[96px] resize-y text-xs ${e?``:`border-destructive`}`,value:t.text,onChange:e=>r(e.target.value),disabled:n,spellCheck:!1,placeholder:`{}`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground disabled:opacity-50`,disabled:n||!e||!t.text.trim(),onClick:()=>{try{r(JSON.stringify(JSON.parse(t.text),null,2))}catch{}},children:[(0,L.jsx)(O,{className:`size-3`}),i(`result.rowForm.formatJson`)]}),!e&&(0,L.jsx)(`span`,{className:`text-[10px] text-destructive`,children:i(`result.rowForm.invalid.json`)})]})]})}case`text`:return(0,L.jsx)(`textarea`,{className:`${a} min-h-[72px] resize-y`,value:t.text,onChange:e=>r(e.target.value),disabled:n,spellCheck:!1});case`binary`:return(0,L.jsx)(`div`,{className:`rounded border bg-muted/40 px-2 py-1 text-xs italic text-muted-foreground`,children:i(`result.rowForm.binaryUnsupported`)});case`uuid`:return(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`input`,{className:`${a} flex-1`,value:t.text,onChange:e=>r(e.target.value),disabled:n,placeholder:`00000000-0000-0000-0000-000000000000`}),(0,L.jsx)(`button`,{type:`button`,className:`rounded border bg-background px-1.5 py-1 text-muted-foreground hover:text-foreground disabled:opacity-50`,disabled:n,onClick:()=>r(crypto.randomUUID()),title:i(`result.rowForm.generateUuid`),children:(0,L.jsx)(O,{className:`size-3.5`})})]});default:{let i=t.text.length>80||t.text.includes(`
1
+ import{r as e}from"./hePW80VL.js";import{h as t,n,t as r}from"./B1pia_Rg.js";import{a as i,l as a,m as o,t as s}from"./pjlgs2cl.js";import{t as c}from"./BCmzDvBt.js";import{n as l}from"./D6kbK-ng.js";import{a as u}from"./CS2mpWDL.js";import{l as d,t as f}from"./OjAiMU9J.js";import{Dt as p,Ft as m,Pt as h,ct as g,d as _,f as v,kt as y,m as b,p as x,zt as S}from"./Bhquh17w.js";import{a as C,i as w,n as ee,o as T,r as E,t as D}from"./BgkATqP8.js";var O=i(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]),k=e(t(),1);function A(e){let t=e.slice(e.indexOf(`(`)+1,e.lastIndexOf(`)`)),n=[],r=/'((?:[^']|'')*)'/g,i;for(;i=r.exec(t);)n.push(i[1].replaceAll(`''`,`'`));return n}function j(e,t={}){let{oracleDate:n=!1}=t,r=e.type.trim(),i=r.toLowerCase(),a=/\bunsigned\b/.test(i);if(/^enum\(/.test(i))return{kind:`enum`,options:A(r)};if(/^set\(/.test(i))return{kind:`set`,options:A(r)};if(/^(tinyint\(1\)|bool|boolean|bit\(1\)|bit)(?![\w(])/.test(i))return{kind:`boolean`};let o=/^number(?:\((\d+|\*)(?:,\s*(-?\d+))?\))?$/.exec(i);if(o)return o[2]&&Number(o[2])>0?{kind:`decimal`}:o[1]?{kind:`integer`}:{kind:`decimal`};if(/^(tinyint|smallint|mediumint|int|integer|bigint|int2|int4|int8|serial|bigserial|smallserial)\b/.test(i))return{kind:`integer`,unsigned:a};if(/^(decimal|numeric|float|double|real|money|float4|float8|double precision)\b/.test(i))return{kind:`decimal`,unsigned:a};if(/^(datetime2|datetime|timestamp|smalldatetime|datetimeoffset)\b/.test(i))return{kind:`datetime`};if(/^date\b/.test(i))return{kind:n?`datetime`:`date`};if(/^(time|timetz)\b/.test(i))return{kind:`time`};if(/^(json|jsonb)\b/.test(i))return{kind:`json`};if(/^(uuid|uniqueidentifier)\b/.test(i))return{kind:`uuid`};if(/^(blob|tinyblob|mediumblob|longblob|binary|varbinary|bytea|raw|image|bfile)\b/.test(i))return{kind:`binary`};if(/^(text|ntext|tinytext|mediumtext|longtext|clob|nclob|long)\b/.test(i)||/^n?(?:var)?char2?\(max\)/.test(i))return{kind:`text`};let s=/^n?(?:var)?char2?(?:acter)?(?:\s+varying)?\((\d+)(?:\s+(?:char|byte))?\)/.exec(i);return s?{kind:`string`,maxLength:Number(s[1])}:{kind:`string`}}var M=/auto_increment|identity|generated/i;function N(e){return M.test(e.extra)||/^(serial|bigserial|smallserial)\b/i.test(e.type)?{mode:`auto`,text:``}:e.defaultValue===null?e.nullable?{mode:`null`,text:``}:{mode:`value`,text:``}:{mode:`default`,text:``}}function P(e){return e==null?{mode:`keep`,text:``}:{mode:`keep`,text:F(e)}}function F(e){if(e==null)return``;if(typeof e==`object`){if(ArrayBuffer.isView(e))return``;if(e instanceof Date)return e.toISOString();try{return JSON.stringify(e,null,2)}catch{return String(e)}}return String(e)}function I(e,t){let n=t.trim();switch(e.kind){case`integer`:{if(!/^[+-]?\d+$/.test(n))return{error:`integer`};if(e.unsigned&&n.startsWith(`-`))return{error:`unsigned`};let t=Number(n);return{value:Number.isSafeInteger(t)?t:BigInt(n)}}case`decimal`:return n===``||Number.isNaN(Number(n))?{error:`number`}:{value:Number(n)};case`boolean`:return{value:n===`true`||n===`1`};case`json`:try{return{value:JSON.parse(n===``?`null`:n)}}catch{return{error:`json`}}case`set`:return{value:n};case`date`:return n&&!/^\d{4}-\d{2}-\d{2}$/.test(n)?{error:`date`}:{value:n};case`datetime`:return n&&!/^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}(:\d{2}(\.\d+)?)?)?([+-]\d{2}:?\d{2}|Z)?$/.test(n)?{error:`datetime`}:{value:n};case`time`:return n&&!/^-?\d{1,3}:\d{2}(:\d{2}(\.\d+)?)?$/.test(n)?{error:`time`}:{value:n};default:return{value:t}}}var L=a(),R={integer:`result.rowForm.invalid.integer`,unsigned:`result.rowForm.invalid.unsigned`,number:`result.rowForm.invalid.number`,json:`result.rowForm.invalid.json`,date:`result.rowForm.invalid.date`,datetime:`result.rowForm.invalid.datetime`,time:`result.rowForm.invalid.time`};function z(e){return String(e).padStart(2,`0`)}function B(e){let t=new Date,n=`${t.getFullYear()}-${z(t.getMonth()+1)}-${z(t.getDate())}`,r=`${z(t.getHours())}:${z(t.getMinutes())}:${z(t.getSeconds())}`;return e===`date`?n:e===`time`?r:`${n} ${r}`}function V(e){let t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e.trim());if(!t)return;let n=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]));return Number.isNaN(n.getTime())?void 0:n}function H({spec:e,state:t,disabled:n,onText:r}){let{t:i}=o(),a=`w-full rounded border bg-background px-2 py-1 text-sm font-mono outline-none focus:ring-1 focus:ring-primary disabled:opacity-50`;switch(e.kind){case`boolean`:return(0,L.jsxs)(`select`,{className:a,value:t.text===`true`||t.text===`1`?`true`:`false`,onChange:e=>r(e.target.value),disabled:n,children:[(0,L.jsx)(`option`,{value:`true`,children:`TRUE`}),(0,L.jsx)(`option`,{value:`false`,children:`FALSE`})]});case`enum`:return(0,L.jsxs)(`select`,{className:a,value:t.text,onChange:e=>r(e.target.value),disabled:n,children:[!e.options?.includes(t.text)&&(0,L.jsx)(`option`,{value:t.text,children:t.text||`—`}),e.options?.map(e=>(0,L.jsx)(`option`,{value:e,children:e},e))]});case`set`:{let i=new Set(t.text.split(`,`).map(e=>e.trim()).filter(Boolean));return(0,L.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 rounded border bg-background px-2 py-1.5`,children:e.options?.map(t=>(0,L.jsxs)(`label`,{className:`flex items-center gap-1 text-xs font-mono`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`accent-primary`,checked:i.has(t),disabled:n,onChange:n=>{let a=new Set(i);n.target.checked?a.add(t):a.delete(t),r(e.options.filter(e=>a.has(e)).join(`,`))}}),t]},t))})}case`integer`:case`decimal`:return(0,L.jsx)(`input`,{className:`${a} tabular-nums`,inputMode:`decimal`,value:t.text,onChange:e=>r(e.target.value),disabled:n,placeholder:e.kind===`integer`?`0`:`0.00`});case`date`:case`datetime`:{let[o,s]=t.text.trim().split(/[ T]/);return(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`input`,{className:`${a} flex-1`,value:t.text,onChange:e=>r(e.target.value),disabled:n,placeholder:e.kind===`date`?`YYYY-MM-DD`:`YYYY-MM-DD HH:MM:SS`}),(0,L.jsxs)(v,{children:[(0,L.jsx)(b,{asChild:!0,children:(0,L.jsx)(`button`,{type:`button`,className:`rounded border bg-background p-1.5 text-muted-foreground hover:text-foreground disabled:opacity-50`,disabled:n,title:i(`result.rowForm.pickDate`),children:(0,L.jsx)(S,{className:`size-3.5`})})}),(0,L.jsx)(x,{className:`w-auto p-0`,align:`end`,children:(0,L.jsx)(_,{mode:`single`,selected:V(o??``),defaultMonth:V(o??``),onSelect:t=>{if(!t)return;let n=`${t.getFullYear()}-${z(t.getMonth()+1)}-${z(t.getDate())}`;r(e.kind===`date`?n:`${n} ${s||`00:00:00`}`)}})})]}),(0,L.jsx)(`button`,{type:`button`,className:`rounded border bg-background px-1.5 py-1 text-[10px] text-muted-foreground hover:text-foreground disabled:opacity-50`,disabled:n,onClick:()=>r(B(e.kind)),title:i(`result.rowForm.now`),children:(0,L.jsx)(h,{className:`size-3.5`})})]})}case`time`:return(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`input`,{className:`${a} flex-1`,value:t.text,onChange:e=>r(e.target.value),disabled:n,placeholder:`HH:MM:SS`}),(0,L.jsx)(`button`,{type:`button`,className:`rounded border bg-background px-1.5 py-1 text-muted-foreground hover:text-foreground disabled:opacity-50`,disabled:n,onClick:()=>r(B(`time`)),title:i(`result.rowForm.now`),children:(0,L.jsx)(h,{className:`size-3.5`})})]});case`json`:{let e=!0;try{t.text.trim()&&JSON.parse(t.text)}catch{e=!1}return(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`textarea`,{className:`${a} min-h-[96px] resize-y text-xs ${e?``:`border-destructive`}`,value:t.text,onChange:e=>r(e.target.value),disabled:n,spellCheck:!1,placeholder:`{}`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground disabled:opacity-50`,disabled:n||!e||!t.text.trim(),onClick:()=>{try{r(JSON.stringify(JSON.parse(t.text),null,2))}catch{}},children:[(0,L.jsx)(O,{className:`size-3`}),i(`result.rowForm.formatJson`)]}),!e&&(0,L.jsx)(`span`,{className:`text-[10px] text-destructive`,children:i(`result.rowForm.invalid.json`)})]})]})}case`text`:return(0,L.jsx)(`textarea`,{className:`${a} min-h-[72px] resize-y`,value:t.text,onChange:e=>r(e.target.value),disabled:n,spellCheck:!1});case`binary`:return(0,L.jsx)(`div`,{className:`rounded border bg-muted/40 px-2 py-1 text-xs italic text-muted-foreground`,children:i(`result.rowForm.binaryUnsupported`)});case`uuid`:return(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(`input`,{className:`${a} flex-1`,value:t.text,onChange:e=>r(e.target.value),disabled:n,placeholder:`00000000-0000-0000-0000-000000000000`}),(0,L.jsx)(`button`,{type:`button`,className:`rounded border bg-background px-1.5 py-1 text-muted-foreground hover:text-foreground disabled:opacity-50`,disabled:n,onClick:()=>r(crypto.randomUUID()),title:i(`result.rowForm.generateUuid`),children:(0,L.jsx)(O,{className:`size-3.5`})})]});default:{let i=t.text.length>80||t.text.includes(`
2
2
  `);return(0,L.jsxs)(`div`,{className:`space-y-0.5`,children:[i?(0,L.jsx)(`textarea`,{className:`${a} min-h-[56px] resize-y`,value:t.text,onChange:e=>r(e.target.value),disabled:n,spellCheck:!1}):(0,L.jsx)(`input`,{className:a,value:t.text,onChange:e=>r(e.target.value),disabled:n,maxLength:e.maxLength}),e.maxLength&&(0,L.jsxs)(`div`,{className:`text-right text-[10px] tabular-nums ${t.text.length>e.maxLength?`text-destructive`:`text-muted-foreground`}`,children:[t.text.length,`/`,e.maxLength]})]})}}}function U(){let{t:e}=o(),t=r(`row-form`),i=n(e=>e.closeDialog),a=n(e=>e.setFooterMessage),h=g(t?.connectionId??``),_=c(e=>t?e.transactionOpen[t.connectionId]:!1),[v,b]=(0,k.useState)(null),[x,S]=(0,k.useState)(null),[O,A]=(0,k.useState)({}),[M,F]=(0,k.useState)({}),[z,B]=(0,k.useState)(null),[V,U]=(0,k.useState)(!1),W=t?.mode===`edit`;(0,k.useEffect)(()=>{if(!t)return;let e=!1,n=u(t.serverConnectionId);return h.introspect.listColumns(n,t.database,t.table).then(n=>{if(e)return;b(n);let r={};for(let e of n)if(t.mode===`edit`){let n=t.fields.find(t=>t.orgName===e.name);r[e.name]=P(n?t.row?.[n.name]:void 0)}else r[e.name]=N(e);A(r)}).catch(t=>{e||S(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[t?.serverConnectionId,t?.database,t?.table,t?.mode]);let G=(0,k.useMemo)(()=>new Map((v??[]).map(e=>[e.name,j(e,{oracleDate:h.id===`oracle`})])),[v,h.id]),K=(0,k.useCallback)((e,t)=>{A(n=>({...n,[e]:{...n[e],mode:t}})),F(t=>{let n={...t};return delete n[e],n})},[]),q=(0,k.useCallback)((e,t)=>{A(n=>({...n,[e]:{mode:`value`,text:t}})),F(t=>{let n={...t};return delete n[e],n})},[]),J=(0,k.useMemo)(()=>({__default:!0}),[]),Y=(0,k.useCallback)(()=>{if(!v)return null;let t=new Map,n={};for(let r of v){let i=O[r.name],a=G.get(r.name);if(!i||i.mode===`auto`||i.mode===`keep`)continue;if(i.mode===`null`){t.set(r.name,null);continue}if(i.mode==="default"){t.set(r.name,J);continue}let o=I(a,i.text);if(`error`in o){n[r.name]=e(R[o.error]??`result.rowForm.invalid.number`);continue}if(a.maxLength&&typeof o.value==`string`&&o.value.length>a.maxLength){n[r.name]=e(`result.rowForm.invalid.length`,{max:a.maxLength});continue}t.set(r.name,o.value)}return F(n),Object.keys(n).length>0?null:{values:t}},[v,O,G,e,J]),X=(0,k.useCallback)(e=>{if(!t)return null;let n=e=>e===J?`DEFAULT`:h.quoteLiteral(e);if(t.mode===`insert`){let r=[...e];return r.length===0?h.getQuery(`INSERT_DEFAULT_VALUES`,t.database,t.table):h.getQuery(`INSERT_TABLE`,t.database,t.table,r.map(([e])=>h.quoteIdentifier(e)).join(`, `),r.map(([,e])=>n(e)).join(`, `))}return!t.where||e.size===0?null:h.getQuery(`UPDATE_TABLE`,t.database,t.table,[...e].map(([e,t])=>`${h.quoteIdentifier(e)} = ${n(t)}`).join(`, `),t.where)},[t,h,J]),Z=(0,k.useMemo)(()=>{if(!v)return``;let e=new Map;for(let t of v){let n=O[t.name];if(!(!n||n.mode===`auto`||n.mode===`keep`)){if(n.mode===`null`)e.set(t.name,null);else if(n.mode==="default")e.set(t.name,J);else{let r=I(G.get(t.name),n.text);e.set(t.name,`error`in r?n.text:r.value)}}}return X(e)??``},[v,O,G,X,J]),Q=e=>{let n={};for(let[r,i]of e){if(i===J)continue;let e=t?.fields.find(e=>e.orgName===r);n[e?.name??r]=typeof i==`bigint`?i.toString():i}return n},te=()=>{let e=Y();!e||!t||(t.onStage?.(t.mode,Q(e.values)),i())},ne=async()=>{let r=Y();if(!r||!t)return;let o=X(r.values);if(!o){B(e(`result.rowForm.nothingToWrite`));return}U(!0),B(null);try{if(l.getState().previewGridCommit&&!await n.getState().requestDestructiveConfirm({title:e(W?`result.rowForm.confirmUpdateTitle`:`result.rowForm.confirmInsertTitle`,{table:`${t.database}.${t.table}`}),statements:[o],confirmLabel:e(W?`result.rowForm.update`:`result.rowForm.insert`)}))return;await d(t.connectionId,o,{database:t.database,skipDestructiveConfirm:!0}),a(e(W?`result.rowForm.updated`:`result.rowForm.inserted`,{table:`${t.database}.${t.table}`})),t.onCommitted?.(t.mode,Q(r.values)),i()}catch(e){if(e instanceof f)return;B(e instanceof Error?e.message:String(e))}finally{U(!1)}};if(!t)return null;let $=(e,t,n,r)=>(0,L.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 text-[10px] font-medium ${r===t?`bg-primary text-primary-foreground`:`text-muted-foreground hover:bg-muted hover:text-foreground`}`,onClick:()=>K(e,t),children:n});return(0,L.jsx)(D,{open:!0,onOpenChange:e=>{e||i()},children:(0,L.jsxs)(ee,{className:`flex max-h-[90vh] flex-col sm:max-w-[860px]`,children:[(0,L.jsxs)(C,{children:[(0,L.jsx)(T,{children:e(W?`result.rowForm.editTitle`:`result.rowForm.insertTitle`)}),(0,L.jsxs)(E,{className:`font-mono text-xs`,children:[t.database,`.`,t.table]})]}),(0,L.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto rounded-md border`,children:[x&&(0,L.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:x}),!v&&!x&&(0,L.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground`,children:[(0,L.jsx)(p,{className:`size-4 animate-spin`}),e(`result.rowForm.loading`)]}),v&&(0,L.jsxs)(`table`,{className:`w-full border-separate border-spacing-0 text-sm`,children:[(0,L.jsx)(`thead`,{className:`sticky top-0 z-10 bg-background`,children:(0,L.jsxs)(`tr`,{className:`text-left text-[10px] uppercase tracking-wide text-muted-foreground`,children:[(0,L.jsx)(`th`,{className:`w-[38%] border-b px-2 py-1.5 font-medium`,children:e(`result.rowForm.colColumn`)}),(0,L.jsx)(`th`,{className:`border-b px-2 py-1.5 font-medium`,children:e(`result.rowForm.colValue`)})]})}),(0,L.jsx)(`tbody`,{children:v.map(n=>{let r=O[n.name]??{mode:`value`,text:``},i=G.get(n.name),a=r.mode===`auto`,o=M[n.name],s=n.key===`PRI`,c=t.fields.find(e=>e.orgName===n.name),l=!!c&&!!t.row&&t.row[c.name]===null;return(0,L.jsxs)(`tr`,{className:`align-top ${o?`bg-destructive/5`:`hover:bg-muted/30`}`,children:[(0,L.jsxs)(`td`,{className:`border-b border-border/60 px-2 py-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`truncate font-mono text-sm font-medium`,title:n.name,children:n.name}),s&&(0,L.jsxs)(`span`,{className:`flex shrink-0 items-center gap-0.5 rounded border border-catppuccin-yellow/50 px-1 text-[9px] font-semibold text-catppuccin-yellow`,children:[(0,L.jsx)(y,{className:`size-2.5`}),`PK`]})]}),(0,L.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[10px] text-muted-foreground`,children:[(0,L.jsx)(`span`,{className:`rounded bg-muted px-1 py-px font-mono`,children:n.type}),!n.nullable&&(0,L.jsx)(`span`,{children:`NOT NULL`}),n.defaultValue!==null&&(0,L.jsxs)(`span`,{className:`font-mono`,title:e(`result.rowForm.defaultValue`),children:[`= `,n.defaultValue]}),n.extra&&(0,L.jsx)(`span`,{children:n.extra})]}),n.comment&&(0,L.jsx)(`div`,{className:`mt-0.5 text-[10px] text-muted-foreground/80`,children:n.comment})]}),(0,L.jsx)(`td`,{className:`border-b border-border/60 px-2 py-2`,children:(0,L.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[r.mode===`keep`?(0,L.jsx)(`div`,{className:`cursor-text truncate rounded border border-dashed bg-muted/30 px-2 py-1 font-mono text-xs text-muted-foreground`,onClick:()=>K(n.name,`value`),title:e(`result.rowForm.clickToChange`),children:l?(0,L.jsx)(`span`,{className:`italic`,children:`NULL`}):r.text||(0,L.jsx)(`span`,{className:`italic`,children:e(`result.rowForm.empty`)})}):r.mode===`value`?(0,L.jsx)(H,{spec:i,state:r,disabled:!1,onText:e=>q(n.name,e)}):(0,L.jsx)(`div`,{className:`rounded border border-dashed bg-muted/30 px-2 py-1 font-mono text-xs italic text-muted-foreground`,children:r.mode===`null`?`NULL`:r.mode==="default"?`DEFAULT (${n.defaultValue??``})`:e(`result.rowForm.autoHint`)}),o&&(0,L.jsxs)(`div`,{className:`mt-1 flex items-center gap-1 text-[11px] text-destructive`,children:[(0,L.jsx)(m,{className:`size-3`}),o]})]}),(0,L.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 rounded border bg-background p-0.5`,children:[W&&$(n.name,`keep`,e(`result.rowForm.mode.keep`),r.mode),(a||!W&&/auto_increment|identity/i.test(n.extra))&&$(n.name,`auto`,e(`result.rowForm.mode.auto`),r.mode),$(n.name,`value`,e(`result.rowForm.mode.value`),r.mode),n.nullable&&$(n.name,`null`,`NULL`,r.mode),n.defaultValue!==null&&$(n.name,`default`,`DEFAULT`,r.mode)]})]})})]},n.name)})})]})]}),v&&(0,L.jsxs)(`div`,{className:`shrink-0 rounded-md border bg-muted/30`,children:[(0,L.jsx)(`div`,{className:`border-b px-3 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:e(`result.rowForm.preview`)}),(0,L.jsx)(`pre`,{className:`max-h-24 overflow-auto whitespace-pre-wrap break-words px-3 py-2 font-mono text-xs`,children:Z||(0,L.jsx)(`span`,{className:`italic text-muted-foreground`,children:e(`result.rowForm.nothingToWrite`)})})]}),z&&(0,L.jsx)(`div`,{className:`shrink-0 rounded border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:z}),(0,L.jsxs)(w,{className:`items-center`,children:[_&&(0,L.jsx)(`span`,{className:`mr-auto text-[11px] text-catppuccin-yellow`,children:e(`result.rowForm.inTransaction`)}),(0,L.jsx)(s,{variant:`outline`,onClick:()=>i(),disabled:V,children:e(`command.close`)}),t.onStage&&(0,L.jsx)(s,{variant:`outline`,onClick:te,disabled:V||!v,title:e(`result.rowForm.stageHint`),children:e(W?`result.rowForm.stageEdit`:`result.rowForm.stageInsert`)}),(0,L.jsxs)(s,{onClick:()=>void ne(),disabled:V||!v,children:[V&&(0,L.jsx)(p,{className:`mr-1 size-3.5 animate-spin`}),e(W?`result.rowForm.update`:`result.rowForm.insert`)]})]})]})})}export{U as RowFormDialog};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BKoh-tKR.js","assets/hePW80VL.js","assets/BkIkgVK5.js","assets/C0O3rJzW.js","assets/BAZqI8g_.js","assets/CpZOnYKF.js","assets/CaoceGhm.js","assets/G6EbcZKg.js","assets/eFSiW0Lh.js","assets/DC8XCjJ3.js","assets/DP94Ond0.js","assets/B49XtolG.js","assets/Bit0Kfog.js","assets/dMlgA_r1.js","assets/Dd9quIZg.js","assets/CYMzEa4j.js","assets/Dht5Mpyb.js","assets/DAFA-E1-.js","assets/DjDcAaBy.js","assets/DBHRzz66.js","assets/3z4eHGF-.js","assets/Bs5VSn0X.js","assets/KuSp3gJs.css"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./hePW80VL.js";import{c as t,h as n,n as r}from"./BkIkgVK5.js";import{a as i,i as a}from"./BAZqI8g_.js";import{_ as o,g as s,h as c,m as l,p as u,s as d,t as f}from"./DC8XCjJ3.js";import{n as p}from"./DP94Ond0.js";import{D as m}from"./B49XtolG.js";import{t as h}from"./Bit0Kfog.js";import{n as g}from"./dMlgA_r1.js";import{S as _,a as v,c as y}from"./Dd9quIZg.js";import{a as b}from"./CYMzEa4j.js";import{n as x,r as ee}from"./Dht5Mpyb.js";import{i as te}from"./DAFA-E1-.js";import{c as S,d as C,f as w,l as ne,p as re,t as T}from"./DjDcAaBy.js";import{n as E,t as D}from"./DBHRzz66.js";function O(e){return f.getState().activeConnections.find(t=>t.id===e)?.database||D(_.getState().trees[e]??[])}function ie(e,t,n,r){return x(e).tree.objectPath(t,n,r,O(e))}function k(e,t){return x(e).tree.namespacePath(t,O(e))}function A(e,t){for(let n of e){if(n.id===t)return n;let e=A(n.children,t);if(e)return e}return null}async function ae(e,t,n){let r=_.getState;for(let i=0;i<t.length;i++){let a=r().trees[e];if(!a)return!1;let o=A(a,t[i]);if(!o)return!1;if(i===t.length-1)return r().setSelected(e,o.id),!0;o.children.length===0&&!o.isLeaf?await n(e,o):o.isExpanded||r().setExpanded(e,o.id,!0)}return!1}function j(e,t){for(let n of e){if(n.id===t)return n;let e=j(n.children,t);if(e)return e}return null}function M(e,t){let n=_.getState(),r=n.trees[e];if(!r||!t)return;let i=k(e,t),a=null;for(let t of i){let i=j(r,t);if(!i||(a=i,i.isLeaf))break;!i.isExpanded&&i.children.length>0&&n.setExpanded(e,i.id,!0)}!a||a.id!==i[i.length-1]||(n.setSelected(e,a.id),!a.isExpanded&&a.children.length>0&&n.setExpanded(e,a.id,!0))}var N=e(n(),1);function oe(e,t,n){let r=[];function i(e){for(let n of e){if(r.push(n),n.id===t||n.children.length>0&&i(n.children))return!0;r.pop()}return!1}i(e);for(let e=r.length-1;e>=0;e--)if(r[e].type===n)return r[e];return null}function P(e,t){for(let n of e){if(n.id===t)return n;if(n.children.length>0){let e=P(n.children,t);if(e)return e}}return null}var F=h(`schemaTreeLoadingRoots`,()=>new Set);h(`schemaTreeCacheWriter`,()=>{let e={};return _.subscribe(t=>{if(t.trees!==e){for(let[n,r]of Object.entries(t.trees)){if(r===e[n])continue;let t=f.getState().activeConnections.find(e=>e.id===n);t&&u(t)&&c(n,s(t),r)}e=t.trees}})});function I(e){let t=f.getState().activeConnections.find(t=>t.id===e);return t?.serverConnectionId?{engine:x(e),run:v(t.serverConnectionId),database:t.database||void 0}:null}function se(){let{setTree:e,setChildren:t,setNodeMetadata:n,setLoading:a}=_(),c=(0,N.useCallback)(async t=>{let n=I(t);if(n&&!F.has(t)){F.add(t);try{let r=f.getState().activeConnections.find(e=>e.id===t),i=r&&u(r)?await l(t,s(r)):null;e(t,i??await n.engine.tree.loadRoot(n))}catch(n){let a=n instanceof Error?n.message:String(n);console.error(`Failed to load databases:`,n),r.getState().setFooterMessage(i.t(`schema.tree.loadDatabasesFailed`,{message:a})),e(t,[])}finally{F.delete(t)}}},[e]),d=(0,N.useCallback)(async(e,r)=>{if(!_.getState().trees[e])return;let i=I(e);if(i&&!r.isLeaf){a(e,r.id,!0);try{let a=await i.engine.tree.loadChildren(i,r);t(e,r.id,a),Promise.all(a.filter(e=>e.type===o.FOLDER&&e.metadata?.countable).map(async t=>{try{let r=await i.engine.tree.loadChildren(i,t);n(e,t.id,{count:r.length})}catch(e){console.error(`Failed to count ${t.text}:`,e)}}))}catch(t){console.error(`Failed to load children:`,t),a(e,r.id,!1)}}},[t,n,a]);return{loadDatabases:c,loadChildren:d,refreshNode:(0,N.useCallback)(async(e,t)=>{await d(e,t)},[d]),createNode:b,findNode:P,findAncestor:oe}}async function L(e,t){T(e,t);let n=_.getState().trees[e];if(!n||!t)return;let r=I(e);if(!r)return;let i=k(e,t),a=E(n,i[i.length-1]);!a||a.children.length===0||await Promise.all(a.children.filter(e=>e.type===o.FOLDER).map(async t=>{try{let n=await r.engine.tree.loadChildren(r,t),i=_.getState();(t.children.length>0||t.isExpanded)&&i.setChildren(e,t.id,n),t.metadata?.countable&&i.setNodeMetadata(e,t.id,{count:n.length})}catch(e){console.error(`Failed to refresh ${t.text}:`,e)}}))}async function ce(e){T(e);let t=I(e);t&&_.getState().setTree(e,await t.engine.tree.loadRoot(t))}var R=class extends Error{sql;constructor(e,t){super(e),this.name=`QueryError`,this.sql=t}},z=class extends Error{constructor(e=`Cancelled`){super(e),this.name=`ExecutionCancelled`}};function B(e){let t=e.fields??[],n=e.records??[];return{fields:t.map(e=>({name:e.name,type:e.type,orgTable:e.orgTable??e.table??``,orgName:e.orgName??e.name,db:e.db??``})),rows:n.map(e=>{let n={};return t.forEach((t,r)=>{n[t.name]=e[r]}),n}),affectedRows:e.affectedRows??0,insertId:e.insertId??0,message:e.message??(n.length>0?i.t(`services.query.rowsReturned`,{count:n.length}):i.t(`services.query.rowsAffected`,{count:e.affectedRows??0}))}}async function V(e,t,n,r=ee(t),i){let a=new Set(e.fields.map(e=>e.orgTable).filter(Boolean));if(a.size!==1)return e;let o=[...a][0];try{let a=i??await r.introspect.getPrimaryKeys(v(t),n,o);a.length>0&&(e.primaryKeys=a)}catch{}return!e.primaryKeys?.length&&e.fields.some(e=>e.name===`_rowid_`)&&(e.primaryKeys=[m]),e}var H=new Set([`SELECT`,`SHOW`,`EXPLAIN`,`DESCRIBE`,`DESC`,`HELP`,`VALUES`,`TABLE`,`WITH`,`USE`,`SET`,`CHECK`,`CHECKSUM`]);function U(e){return e.kind===`PRAGMA`?!e.sql.includes(`=`):!(!H.has(e.kind)||e.destructive||e.kind===`SELECT`&&C(e,`INTO`))}var W=new Set([`INSERT`,`UPDATE`,`DELETE`,`REPLACE`,`MERGE`,`LOAD`]),le=new Set([`CREATE`,`ALTER`,`DROP`,`TRUNCATE`,`RENAME`,`GRANT`,`REVOKE`,`FLUSH`,`LOCK`,`UNLOCK`]),ue=new Set([`CREATE`,`ALTER`,`DROP`,`RENAME`]);function de(e){return W.has(e.kind)||!!e.destructive?.dataLoss}function G(e,t,n=`limit`){if(t<=0||e.kind!==`SELECT`||e.limit!==null||C(e,`LIMIT`)||C(e,`INTO`)||C(e,`FOR`)||C(e,`LOCK`))return{sql:e.sql,limited:!1};if(n===`top`){if(C(e,`TOP`)||C(e,`OFFSET`))return{sql:e.sql,limited:!1};let n=re(e);return n===-1?{sql:e.sql,limited:!1}:{sql:`${e.sql.slice(0,n)} TOP ${t}${e.sql.slice(n)}`,limited:!0}}return n===`fetch`?C(e,`FETCH`)||/\bROWNUM\b/i.test(e.sql)?{sql:e.sql,limited:!1}:{sql:`${e.sql} FETCH FIRST ${t} ROWS ONLY`,limited:!0}:{sql:`${e.sql} LIMIT ${t}`,limited:!0}}function fe(e,t=0){let n=K();return n<=0?``:e.limitClause(n,t)}function K(){return p.getState().resultRowLimit}function pe(e){let t=e.destructive,n=t.names.length?t.names.join(`, `):i.t(`services.destructive.unknownTarget`);switch(t.action){case`DROP`:return`DROP ${t.objectType} ${n}`;case`TRUNCATE`:return`TRUNCATE ${n}`;case`DELETE_ALL`:return i.t(`services.destructive.deleteAll`,{target:n});case`UPDATE_ALL`:return i.t(`services.destructive.updateAll`,{target:n});case`ALTER_DROP`:return i.t(`services.destructive.alterDrop`,{target:n})}}async function me(e){if(!p.getState().confirmDestructive)return!0;let t=e.filter(e=>e.destructive?.dataLoss);return t.length===0||r.getState().requestDestructiveConfirm({title:i.t(`services.destructive.title`,{count:t.length}),description:i.t(`services.destructive.description`),statements:t.map(pe),confirmLabel:i.t(`services.runAnyway`)})}async function he(e,t){if(!e.readOnly)return;let n=t.filter(e=>!U(e));if(n.length===0)return;let a=`${e.hostName||e.host}`;if(!p.getState().allowReadOnlyOverride)throw new R(i.t(`services.readOnly.refused`,{label:a,count:n.length}));if(!await r.getState().requestDestructiveConfirm({title:i.t(`services.readOnly.title`,{label:a}),description:i.t(`services.readOnly.description`),statements:n.map(e=>e.sql.length>120?e.sql.slice(0,117)+`...`:e.sql),confirmLabel:i.t(`services.runAnyway`)}))throw new z(`Cancelled: connection is read-only.`)}function q(e,t){let n=f.getState(),r=n.activeConnections.find(t=>t.id===e);if(!r?.serverConnectionId)throw new R(i.t(`services.query.notConnected`));if(n.pendingReopen[e])throw new R(i.t(`services.query.fileNotOpen`));return{connId:e,serverConnId:r.serverConnectionId,conn:r,engine:x(e),tabId:t}}async function J(e,t,n){let r=new S(e.engine).statements(t);if(e.conn.scratchpad){let{materializeFederated:t}=await a(async()=>{let{materializeFederated:e}=await import(`./BKoh-tKR.js`).then(e=>e.B);return{materializeFederated:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]));for(let n of r)n.sql=await t(e.connId,n.sql)}if(await he(e.conn,r),!n.skipDestructiveConfirm&&!await me(r))throw new z;return r}async function Y(e,n,a){let{connId:o,serverConnId:s,engine:c,tabId:l}=e,u=n.stmt?.kind??``,d=()=>f.getState();if(e.conn.transactionMode===`manual`&&c.capabilities.transactions&&n.stmt&&de(n.stmt)&&!d().transactionOpen[o]){let e=await y(s,c.getQuery(`START_TRANSACTION`),a||void 0);if(!e.success)throw new R(e.message??i.t(`services.transaction.startFailed`));d().setTransactionOpen(o,!0),r.getState().setFooterMessage(i.t(`services.transaction.started`))}let p=await y(s,n.sql,a||void 0);if(!p.success){let r=p.message??i.t(`services.query.failed`);throw g.getState().recordExecution({connectionId:o,tabId:l,query:n.sql,database:a,executionTime:p.execTime,error:r,kind:u||void 0}),t(`query_execute`,{dbms:e.conn.dbms,kind:u||`unknown`,source:l?`editor`:`app`,success:!1}),new R(r,n.sql)}let m=B(p);return u===`COMMIT`||u===`ROLLBACK`?d().setTransactionOpen(o,!1):u===`START`||u===`BEGIN`?d().setTransactionOpen(o,!0):le.has(u)&&d().transactionOpen[o]&&c.capabilities.implicitCommitDdl&&(d().setTransactionOpen(o,!1),r.getState().setFooterMessage(i.t(`services.transaction.implicitCommit`,{kind:u}))),ue.has(u)&&L(o,a),e.skipHistory||g.getState().recordExecution({connectionId:o,tabId:l,query:n.sql,database:a,executionTime:p.execTime,kind:u||void 0,...m.fields.length>0?{rowCount:m.rows.length}:{affectedRows:m.affectedRows}}),t(`query_execute`,{dbms:e.conn.dbms,kind:u||`unknown`,source:l?`editor`:`app`,success:!0,exec_time_ms:Math.round(p.execTime??0)}),{qr:m,execTime:p.execTime}}async function ge(e,t,n={}){let r=q(e,n.tabId??null);r.skipHistory=n.skipHistory;let a=t.trim();if(!a)throw new R(i.t(`services.query.nothingToExecute`));let o=await J(r,a,n),s=n.database??``;n.previewWrites&&p.getState().previewAffectedRows&&await Q(r,o,s);let c=o.length>0?o.map(e=>({sql:e.sql,stmt:e})):[{sql:a,stmt:null}],l=null;for(let e of c){let{qr:t}=await Y(r,e,s);n.primaryKeys&&t.fields.length>0&&s&&await V(t,r.serverConnId,s,r.engine,Array.isArray(n.primaryKeys)?n.primaryKeys:void 0),l=t}return l}function _e(e,t){return X(e,t)?.sql??null}function X(e,t){let n=g.getState().tabs[e]?.find(e=>e.id===t);if(!n)return null;let r=te(e,t);if(r&&`selection`in r)return{sql:r.selection,start:r.start};let i=r&&`cursorOffset`in r?r.cursorOffset:n.query.length,a=new S(x(e)).statements(n.query);if(a.length===0)return null;let o=a.find(e=>i>=w(e)&&i<=e.end)??[...a].reverse().find(e=>e.end<=i)??a[0];return{sql:o.sql,start:w(o)}}async function ve(e,n,r={}){let o=()=>g.getState(),s=o().tabs[e]?.find(e=>e.id===n);if(!s)return;let c=(r.sql??s.query)?.trim();if(!c)return;let l,u;try{l=q(e,n),u=await J(l,c,{})}catch(t){if(t instanceof z){t.message!==`Cancelled`&&o().setError(e,n,t.message);return}o().setError(e,n,t instanceof Error?t.message:String(t));return}let f=p.getState(),m=new Map;if(f.previewAffectedRows)try{m=await Q(l,u,s.database||``)}catch(e){if(e instanceof z)return;throw e}let h=m.size===1,_=u.length>0?u.map(e=>({...G(e,f.resultRowLimit,l.engine.syntax.limitStyle),stmt:e})):[{sql:c,limited:!1,stmt:null}],v=r.sql?r.sqlOffset??null:0;a(async()=>{let{readStructures:e}=await import(`./BKoh-tKR.js`).then(e=>e.tt);return{readStructures:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])).then(({readStructures:t})=>t(e,n,u.length>0?u.map(e=>({sql:e.sql,start:v===null?null:v+w(e)})):[{sql:c,start:v}])),o().captureRevision(e,n,`execute`),o().setExecuting(e,n,!0),o().setError(e,n,null);let y=[],b=s.database||``;try{for(let r of _){let{qr:a,execTime:s}=await Y(l,r,b);if(a.sql=r.stmt?.sql??r.sql,a.executionTime=s,r.limited&&a.rows.length>=f.resultRowLimit&&(a.limited=!0,a.message=i.t(`services.query.rowsReturnedLimited`,{count:a.rows.length,limit:f.resultRowLimit})),!b&&a.fields.length>0){let t=a.fields.find(e=>e.db)?.db;t&&(b=t,o().setDatabase(e,n,b),M(e,b))}a.fields.length>0&&b&&await V(a,l.serverConnId,b,l.engine);let c=h&&r.stmt?m.get(r.stmt):void 0;c!==void 0&&Number.isFinite(a.affectedRows)&&a.affectedRows!==c&&(a.warning=i.t(`services.query.dryRunMismatch`,{predicted:c,actual:a.affectedRows}),t(`dry_run_mismatch`,{dbms:l.conn.dbms,kind:r.stmt?.kind??`unknown`})),y.push(a)}o().setResults(e,n,y)}catch(t){y.length>0&&o().setResults(e,n,y),o().setError(e,n,t instanceof Error?t.message:String(t),t instanceof R?t.sql:null),t instanceof R&&d(`query_error`)}finally{o().setExecuting(e,n,!1)}}var Z=50;function ye(e,t,n){return e.syntax.limitStyle===`top`?t.replace(/^SELECT\b/i,`SELECT TOP ${n}`):`${t} ${e.limitClause(n)}`}async function Q(e,t,n){let i=new Map;for(let a of t){if(a.kind!==`UPDATE`&&a.kind!==`DELETE`)continue;let t=ne(a);if(!t)continue;let o=null,s=[],c=[],l,u=await y(e.serverConnId,t.count,n||void 0);if(u.success){let r=Number(u.records[0]?.[0]);o=Number.isFinite(r)?r:null;let i=await y(e.serverConnId,t.limited?t.select:ye(e.engine,t.select,Z),n||void 0);i.success?(s=i.fields.map(e=>e.name),c=i.records):l=i.message}else l=u.message;if(!await r.getState().requestDryRun({statement:a.sql,previewSql:t.select,count:o,fields:s,rows:c,truncated:o!==null&&c.length<o,error:l}))throw new z;o!==null&&i.set(a,o)}return i}async function $(e,t){let n=f.getState(),a=n.activeConnections.find(t=>t.id===e);if(!a?.serverConnectionId)return;let o=x(e);try{let e=await y(a.serverConnectionId,o.getQuery(t));if(!e.success)throw new R(e.message??i.t(`services.transaction.commandFailed`,{name:t}));r.getState().setFooterMessage(t===`COMMIT`?i.t(`services.transaction.committed`):i.t(`services.transaction.rolledBack`))}catch(e){r.getState().setFooterMessage(i.t(`services.transaction.commandFailedWith`,{name:t,message:e instanceof Error?e.message:String(e)}))}finally{n.setTransactionOpen(e,!1)}}var be=e=>$(e,`COMMIT`),xe=e=>$(e,`ROLLBACK`);export{ae as _,ve as a,xe as c,K as d,fe as f,M as g,se as h,be as i,ge as l,ce as m,R as n,_e as o,L as p,G as r,U as s,z as t,X as u,ie as v};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Bhquh17w.js","assets/hePW80VL.js","assets/B1pia_Rg.js","assets/pjlgs2cl.js","assets/D0jMUNSI.js","assets/bgQ-QVd7.js","assets/CF6jyexg.js","assets/CEtGUZGE.js","assets/eFSiW0Lh.js","assets/BCmzDvBt.js","assets/D6kbK-ng.js","assets/DEEGN6UG.js","assets/Bit0Kfog.js","assets/BO_H_8D-.js","assets/CS2mpWDL.js","assets/DbqogdCK.js","assets/pneb1la9.js","assets/DAFA-E1-.js","assets/CVpzA8TC.js","assets/CjoKIEBz.js","assets/DPdwSUSw.js","assets/Bs5VSn0X.js","assets/KuSp3gJs.css"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./hePW80VL.js";import{c as t,h as n,n as r}from"./B1pia_Rg.js";import{a as i,i as a}from"./D0jMUNSI.js";import{_ as o,g as s,h as c,m as l,p as u,s as d,t as f}from"./BCmzDvBt.js";import{n as p}from"./D6kbK-ng.js";import{D as m}from"./DEEGN6UG.js";import{t as h}from"./Bit0Kfog.js";import{n as g}from"./BO_H_8D-.js";import{S as _,a as v,c as y}from"./CS2mpWDL.js";import{a as b}from"./DbqogdCK.js";import{n as x,r as ee}from"./pneb1la9.js";import{i as te}from"./DAFA-E1-.js";import{c as S,d as C,f as w,l as ne,p as re,t as T}from"./CVpzA8TC.js";import{n as E,t as D}from"./CjoKIEBz.js";function O(e){return f.getState().activeConnections.find(t=>t.id===e)?.database||D(_.getState().trees[e]??[])}function ie(e,t,n,r){return x(e).tree.objectPath(t,n,r,O(e))}function k(e,t){return x(e).tree.namespacePath(t,O(e))}function A(e,t){for(let n of e){if(n.id===t)return n;let e=A(n.children,t);if(e)return e}return null}async function ae(e,t,n){let r=_.getState;for(let i=0;i<t.length;i++){let a=r().trees[e];if(!a)return!1;let o=A(a,t[i]);if(!o)return!1;if(i===t.length-1)return r().setSelected(e,o.id),!0;o.children.length===0&&!o.isLeaf?await n(e,o):o.isExpanded||r().setExpanded(e,o.id,!0)}return!1}function j(e,t){for(let n of e){if(n.id===t)return n;let e=j(n.children,t);if(e)return e}return null}function M(e,t){let n=_.getState(),r=n.trees[e];if(!r||!t)return;let i=k(e,t),a=null;for(let t of i){let i=j(r,t);if(!i||(a=i,i.isLeaf))break;!i.isExpanded&&i.children.length>0&&n.setExpanded(e,i.id,!0)}!a||a.id!==i[i.length-1]||(n.setSelected(e,a.id),!a.isExpanded&&a.children.length>0&&n.setExpanded(e,a.id,!0))}var N=e(n(),1);function oe(e,t,n){let r=[];function i(e){for(let n of e){if(r.push(n),n.id===t||n.children.length>0&&i(n.children))return!0;r.pop()}return!1}i(e);for(let e=r.length-1;e>=0;e--)if(r[e].type===n)return r[e];return null}function P(e,t){for(let n of e){if(n.id===t)return n;if(n.children.length>0){let e=P(n.children,t);if(e)return e}}return null}var F=h(`schemaTreeLoadingRoots`,()=>new Set);h(`schemaTreeCacheWriter`,()=>{let e={};return _.subscribe(t=>{if(t.trees!==e){for(let[n,r]of Object.entries(t.trees)){if(r===e[n])continue;let t=f.getState().activeConnections.find(e=>e.id===n);t&&u(t)&&c(n,s(t),r)}e=t.trees}})});function I(e){let t=f.getState().activeConnections.find(t=>t.id===e);return t?.serverConnectionId?{engine:x(e),run:v(t.serverConnectionId),database:t.database||void 0}:null}function se(){let{setTree:e,setChildren:t,setNodeMetadata:n,setLoading:a}=_(),c=(0,N.useCallback)(async t=>{let n=I(t);if(n&&!F.has(t)){F.add(t);try{let r=f.getState().activeConnections.find(e=>e.id===t),i=r&&u(r)?await l(t,s(r)):null;e(t,i??await n.engine.tree.loadRoot(n))}catch(n){let a=n instanceof Error?n.message:String(n);console.error(`Failed to load databases:`,n),r.getState().setFooterMessage(i.t(`schema.tree.loadDatabasesFailed`,{message:a})),e(t,[])}finally{F.delete(t)}}},[e]),d=(0,N.useCallback)(async(e,r)=>{if(!_.getState().trees[e])return;let i=I(e);if(i&&!r.isLeaf){a(e,r.id,!0);try{let a=await i.engine.tree.loadChildren(i,r);t(e,r.id,a),Promise.all(a.filter(e=>e.type===o.FOLDER&&e.metadata?.countable).map(async t=>{try{let r=await i.engine.tree.loadChildren(i,t);n(e,t.id,{count:r.length})}catch(e){console.error(`Failed to count ${t.text}:`,e)}}))}catch(t){console.error(`Failed to load children:`,t),a(e,r.id,!1)}}},[t,n,a]);return{loadDatabases:c,loadChildren:d,refreshNode:(0,N.useCallback)(async(e,t)=>{await d(e,t)},[d]),createNode:b,findNode:P,findAncestor:oe}}async function L(e,t){T(e,t);let n=_.getState().trees[e];if(!n||!t)return;let r=I(e);if(!r)return;let i=k(e,t),a=E(n,i[i.length-1]);!a||a.children.length===0||await Promise.all(a.children.filter(e=>e.type===o.FOLDER).map(async t=>{try{let n=await r.engine.tree.loadChildren(r,t),i=_.getState();(t.children.length>0||t.isExpanded)&&i.setChildren(e,t.id,n),t.metadata?.countable&&i.setNodeMetadata(e,t.id,{count:n.length})}catch(e){console.error(`Failed to refresh ${t.text}:`,e)}}))}async function ce(e){T(e);let t=I(e);t&&_.getState().setTree(e,await t.engine.tree.loadRoot(t))}var R=class extends Error{sql;constructor(e,t){super(e),this.name=`QueryError`,this.sql=t}},z=class extends Error{constructor(e=`Cancelled`){super(e),this.name=`ExecutionCancelled`}};function B(e){let t=e.fields??[],n=e.records??[];return{fields:t.map(e=>({name:e.name,type:e.type,orgTable:e.orgTable??e.table??``,orgName:e.orgName??e.name,db:e.db??``})),rows:n.map(e=>{let n={};return t.forEach((t,r)=>{n[t.name]=e[r]}),n}),affectedRows:e.affectedRows??0,insertId:e.insertId??0,message:e.message??(n.length>0?i.t(`services.query.rowsReturned`,{count:n.length}):i.t(`services.query.rowsAffected`,{count:e.affectedRows??0}))}}async function V(e,t,n,r=ee(t),i){let a=new Set(e.fields.map(e=>e.orgTable).filter(Boolean));if(a.size!==1)return e;let o=[...a][0];try{let a=i??await r.introspect.getPrimaryKeys(v(t),n,o);a.length>0&&(e.primaryKeys=a)}catch{}return!e.primaryKeys?.length&&e.fields.some(e=>e.name===`_rowid_`)&&(e.primaryKeys=[m]),e}var H=new Set([`SELECT`,`SHOW`,`EXPLAIN`,`DESCRIBE`,`DESC`,`HELP`,`VALUES`,`TABLE`,`WITH`,`USE`,`SET`,`CHECK`,`CHECKSUM`]);function U(e){return e.kind===`PRAGMA`?!e.sql.includes(`=`):!(!H.has(e.kind)||e.destructive||e.kind===`SELECT`&&C(e,`INTO`))}var W=new Set([`INSERT`,`UPDATE`,`DELETE`,`REPLACE`,`MERGE`,`LOAD`]),le=new Set([`CREATE`,`ALTER`,`DROP`,`TRUNCATE`,`RENAME`,`GRANT`,`REVOKE`,`FLUSH`,`LOCK`,`UNLOCK`]),ue=new Set([`CREATE`,`ALTER`,`DROP`,`RENAME`]);function de(e){return W.has(e.kind)||!!e.destructive?.dataLoss}function G(e,t,n=`limit`){if(t<=0||e.kind!==`SELECT`||e.limit!==null||C(e,`LIMIT`)||C(e,`INTO`)||C(e,`FOR`)||C(e,`LOCK`))return{sql:e.sql,limited:!1};if(n===`top`){if(C(e,`TOP`)||C(e,`OFFSET`))return{sql:e.sql,limited:!1};let n=re(e);return n===-1?{sql:e.sql,limited:!1}:{sql:`${e.sql.slice(0,n)} TOP ${t}${e.sql.slice(n)}`,limited:!0}}return n===`fetch`?C(e,`FETCH`)||/\bROWNUM\b/i.test(e.sql)?{sql:e.sql,limited:!1}:{sql:`${e.sql} FETCH FIRST ${t} ROWS ONLY`,limited:!0}:{sql:`${e.sql} LIMIT ${t}`,limited:!0}}function fe(e,t=0){let n=K();return n<=0?``:e.limitClause(n,t)}function K(){return p.getState().resultRowLimit}function pe(e){let t=e.destructive,n=t.names.length?t.names.join(`, `):i.t(`services.destructive.unknownTarget`);switch(t.action){case`DROP`:return`DROP ${t.objectType} ${n}`;case`TRUNCATE`:return`TRUNCATE ${n}`;case`DELETE_ALL`:return i.t(`services.destructive.deleteAll`,{target:n});case`UPDATE_ALL`:return i.t(`services.destructive.updateAll`,{target:n});case`ALTER_DROP`:return i.t(`services.destructive.alterDrop`,{target:n})}}async function me(e){if(!p.getState().confirmDestructive)return!0;let t=e.filter(e=>e.destructive?.dataLoss);return t.length===0||r.getState().requestDestructiveConfirm({title:i.t(`services.destructive.title`,{count:t.length}),description:i.t(`services.destructive.description`),statements:t.map(pe),confirmLabel:i.t(`services.runAnyway`)})}async function he(e,t){if(!e.readOnly)return;let n=t.filter(e=>!U(e));if(n.length===0)return;let a=`${e.hostName||e.host}`;if(!p.getState().allowReadOnlyOverride)throw new R(i.t(`services.readOnly.refused`,{label:a,count:n.length}));if(!await r.getState().requestDestructiveConfirm({title:i.t(`services.readOnly.title`,{label:a}),description:i.t(`services.readOnly.description`),statements:n.map(e=>e.sql.length>120?e.sql.slice(0,117)+`...`:e.sql),confirmLabel:i.t(`services.runAnyway`)}))throw new z(`Cancelled: connection is read-only.`)}function q(e,t){let n=f.getState(),r=n.activeConnections.find(t=>t.id===e);if(!r?.serverConnectionId)throw new R(i.t(`services.query.notConnected`));if(n.pendingReopen[e])throw new R(i.t(`services.query.fileNotOpen`));return{connId:e,serverConnId:r.serverConnectionId,conn:r,engine:x(e),tabId:t}}async function J(e,t,n){let r=new S(e.engine).statements(t);if(e.conn.scratchpad){let{materializeFederated:t}=await a(async()=>{let{materializeFederated:e}=await import(`./Bhquh17w.js`).then(e=>e.B);return{materializeFederated:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]));for(let n of r)n.sql=await t(e.connId,n.sql)}if(await he(e.conn,r),!n.skipDestructiveConfirm&&!await me(r))throw new z;return r}async function Y(e,n,a){let{connId:o,serverConnId:s,engine:c,tabId:l}=e,u=n.stmt?.kind??``,d=()=>f.getState();if(e.conn.transactionMode===`manual`&&c.capabilities.transactions&&n.stmt&&de(n.stmt)&&!d().transactionOpen[o]){let e=await y(s,c.getQuery(`START_TRANSACTION`),a||void 0);if(!e.success)throw new R(e.message??i.t(`services.transaction.startFailed`));d().setTransactionOpen(o,!0),r.getState().setFooterMessage(i.t(`services.transaction.started`))}let p=await y(s,n.sql,a||void 0);if(!p.success){let r=p.message??i.t(`services.query.failed`);throw g.getState().recordExecution({connectionId:o,tabId:l,query:n.sql,database:a,executionTime:p.execTime,error:r,kind:u||void 0}),t(`query_execute`,{dbms:e.conn.dbms,kind:u||`unknown`,source:l?`editor`:`app`,success:!1}),new R(r,n.sql)}let m=B(p);return u===`COMMIT`||u===`ROLLBACK`?d().setTransactionOpen(o,!1):u===`START`||u===`BEGIN`?d().setTransactionOpen(o,!0):le.has(u)&&d().transactionOpen[o]&&c.capabilities.implicitCommitDdl&&(d().setTransactionOpen(o,!1),r.getState().setFooterMessage(i.t(`services.transaction.implicitCommit`,{kind:u}))),ue.has(u)&&L(o,a),e.skipHistory||g.getState().recordExecution({connectionId:o,tabId:l,query:n.sql,database:a,executionTime:p.execTime,kind:u||void 0,...m.fields.length>0?{rowCount:m.rows.length}:{affectedRows:m.affectedRows}}),t(`query_execute`,{dbms:e.conn.dbms,kind:u||`unknown`,source:l?`editor`:`app`,success:!0,exec_time_ms:Math.round(p.execTime??0)}),{qr:m,execTime:p.execTime}}async function ge(e,t,n={}){let r=q(e,n.tabId??null);r.skipHistory=n.skipHistory;let a=t.trim();if(!a)throw new R(i.t(`services.query.nothingToExecute`));let o=await J(r,a,n),s=n.database??``;n.previewWrites&&p.getState().previewAffectedRows&&await Q(r,o,s);let c=o.length>0?o.map(e=>({sql:e.sql,stmt:e})):[{sql:a,stmt:null}],l=null;for(let e of c){let{qr:t}=await Y(r,e,s);n.primaryKeys&&t.fields.length>0&&s&&await V(t,r.serverConnId,s,r.engine,Array.isArray(n.primaryKeys)?n.primaryKeys:void 0),l=t}return l}function _e(e,t){return X(e,t)?.sql??null}function X(e,t){let n=g.getState().tabs[e]?.find(e=>e.id===t);if(!n)return null;let r=te(e,t);if(r&&`selection`in r)return{sql:r.selection,start:r.start};let i=r&&`cursorOffset`in r?r.cursorOffset:n.query.length,a=new S(x(e)).statements(n.query);if(a.length===0)return null;let o=a.find(e=>i>=w(e)&&i<=e.end)??[...a].reverse().find(e=>e.end<=i)??a[0];return{sql:o.sql,start:w(o)}}async function ve(e,n,r={}){let o=()=>g.getState(),s=o().tabs[e]?.find(e=>e.id===n);if(!s)return;let c=(r.sql??s.query)?.trim();if(!c)return;let l,u;try{l=q(e,n),u=await J(l,c,{})}catch(t){if(t instanceof z){t.message!==`Cancelled`&&o().setError(e,n,t.message);return}o().setError(e,n,t instanceof Error?t.message:String(t));return}let f=p.getState(),m=new Map;if(f.previewAffectedRows)try{m=await Q(l,u,s.database||``)}catch(e){if(e instanceof z)return;throw e}let h=m.size===1,_=u.length>0?u.map(e=>({...G(e,f.resultRowLimit,l.engine.syntax.limitStyle),stmt:e})):[{sql:c,limited:!1,stmt:null}],v=r.sql?r.sqlOffset??null:0;a(async()=>{let{readStructures:e}=await import(`./Bhquh17w.js`).then(e=>e.tt);return{readStructures:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])).then(({readStructures:t})=>t(e,n,u.length>0?u.map(e=>({sql:e.sql,start:v===null?null:v+w(e)})):[{sql:c,start:v}])),o().captureRevision(e,n,`execute`),o().setExecuting(e,n,!0),o().setError(e,n,null);let y=[],b=s.database||``;try{for(let r of _){let{qr:a,execTime:s}=await Y(l,r,b);if(a.sql=r.stmt?.sql??r.sql,a.executionTime=s,r.limited&&a.rows.length>=f.resultRowLimit&&(a.limited=!0,a.message=i.t(`services.query.rowsReturnedLimited`,{count:a.rows.length,limit:f.resultRowLimit})),!b&&a.fields.length>0){let t=a.fields.find(e=>e.db)?.db;t&&(b=t,o().setDatabase(e,n,b),M(e,b))}a.fields.length>0&&b&&await V(a,l.serverConnId,b,l.engine);let c=h&&r.stmt?m.get(r.stmt):void 0;c!==void 0&&Number.isFinite(a.affectedRows)&&a.affectedRows!==c&&(a.warning=i.t(`services.query.dryRunMismatch`,{predicted:c,actual:a.affectedRows}),t(`dry_run_mismatch`,{dbms:l.conn.dbms,kind:r.stmt?.kind??`unknown`})),y.push(a)}o().setResults(e,n,y)}catch(t){y.length>0&&o().setResults(e,n,y),o().setError(e,n,t instanceof Error?t.message:String(t),t instanceof R?t.sql:null),t instanceof R&&d(`query_error`)}finally{o().setExecuting(e,n,!1)}}var Z=50;function ye(e,t,n){return e.syntax.limitStyle===`top`?t.replace(/^SELECT\b/i,`SELECT TOP ${n}`):`${t} ${e.limitClause(n)}`}async function Q(e,t,n){let i=new Map;for(let a of t){if(a.kind!==`UPDATE`&&a.kind!==`DELETE`)continue;let t=ne(a);if(!t)continue;let o=null,s=[],c=[],l,u=await y(e.serverConnId,t.count,n||void 0);if(u.success){let r=Number(u.records[0]?.[0]);o=Number.isFinite(r)?r:null;let i=await y(e.serverConnId,t.limited?t.select:ye(e.engine,t.select,Z),n||void 0);i.success?(s=i.fields.map(e=>e.name),c=i.records):l=i.message}else l=u.message;if(!await r.getState().requestDryRun({statement:a.sql,previewSql:t.select,count:o,fields:s,rows:c,truncated:o!==null&&c.length<o,error:l}))throw new z;o!==null&&i.set(a,o)}return i}async function $(e,t){let n=f.getState(),a=n.activeConnections.find(t=>t.id===e);if(!a?.serverConnectionId)return;let o=x(e);try{let e=await y(a.serverConnectionId,o.getQuery(t));if(!e.success)throw new R(e.message??i.t(`services.transaction.commandFailed`,{name:t}));r.getState().setFooterMessage(t===`COMMIT`?i.t(`services.transaction.committed`):i.t(`services.transaction.rolledBack`))}catch(e){r.getState().setFooterMessage(i.t(`services.transaction.commandFailedWith`,{name:t,message:e instanceof Error?e.message:String(e)}))}finally{n.setTransactionOpen(e,!1)}}var be=e=>$(e,`COMMIT`),xe=e=>$(e,`ROLLBACK`);export{ae as _,ve as a,xe as c,K as d,fe as f,M as g,se as h,be as i,ge as l,ce as m,R as n,_e as o,L as p,G as r,U as s,z as t,X as u,ie as v};
@@ -1 +1 @@
1
- import{r as e}from"./hePW80VL.js";import{h as t,n,t as r}from"./BkIkgVK5.js";import{l as i,m as a,o,p as s,s as c,t as l}from"./C0O3rJzW.js";import{S as u,_ as d,x as f,y as p}from"./CaoceGhm.js";import{a as m,i as h,n as g,r as _,t as v}from"./DL6u_OmT.js";import{T as y,f as ee,t as b}from"./DC8XCjJ3.js";import{E as x,O as S,T as C,a as w,f as T,m as te}from"./B49XtolG.js";import{n as ne}from"./dMlgA_r1.js";import{S as E,d as D,g as re,i as ie,l as O,r as ae}from"./Dd9quIZg.js";import{n as oe,t as k}from"./CYMzEa4j.js";import{A,C as j,Gt as se,I as ce,Jt as M,Kt as N,Lt as le,S as ue,Ut as P,Wt as de,a as fe,b as F,bt as pe,c as me,i as he,j as I,l as L,lt as ge,n as _e,o as R,qt as ve,r as ye,rt as be,s as z,u as B,v as xe,x as V,y as Se,z as H}from"./BKoh-tKR.js";import{a as Ce,i as we,n as Te,o as Ee,t as De}from"./Cg4DfVr4.js";import{t as Oe}from"./CnYBZPf9.js";var U=e(t(),1),W=i(),G=Object.defineProperty,K=(e,t)=>G(e,`name`,{value:t,configurable:!0}),q=`DropdownMenu`,[J,ke]=u(q,[M]),Y=M(),[Ae,je]=J(q),Me=K(e=>{let{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:a,onOpenChange:o,modal:s=!0}=e,c=Y(t),l=U.useRef(null),[u,f]=p({prop:i,defaultProp:a??!1,onChange:o,caller:q});return(0,W.jsx)(Ae,{scope:t,triggerId:d(),triggerRef:l,contentId:d(),open:u,onOpenChange:f,onOpenToggle:U.useCallback(()=>f(e=>!e),[f]),modal:s,children:(0,W.jsx)(ve,{...c,open:u,onOpenChange:f,dir:r,modal:s,children:n})})},`DropdownMenu`),Ne=`DropdownMenuTrigger`,Pe=U.forwardRef(K(function(e,t){let{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,a=je(Ne,n),o=Y(n),l=s(t,a.triggerRef);return(0,W.jsx)(P,{asChild:!0,...o,children:(0,W.jsx)(c.button,{type:`button`,id:a.triggerId,"aria-haspopup":`menu`,"aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":a.open?`open`:`closed`,"data-disabled":r?``:void 0,disabled:r,...i,ref:l,onPointerDown:f(e.onPointerDown,e=>{!r&&e.button===0&&e.ctrlKey===!1&&(a.onOpenToggle(),a.open||e.preventDefault())}),onKeyDown:f(e.onKeyDown,e=>{r||([`Enter`,` `].includes(e.key)&&a.onOpenToggle(),e.key===`ArrowDown`&&a.onOpenChange(!0),[`Enter`,` `,`ArrowDown`].includes(e.key)&&e.preventDefault())})})})},`DropdownMenuTrigger`)),Fe=K(e=>{let{__scopeDropdownMenu:t,...n}=e,r=Y(t);return(0,W.jsx)(N,{...r,...n})},`DropdownMenuPortal`),Ie=`DropdownMenuContent`,Le=U.forwardRef(K(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=je(Ie,n),a=Y(n),o=U.useRef(!1);return(0,W.jsx)(de,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...r,ref:t,onCloseAutoFocus:f(e.onCloseAutoFocus,e=>{o.current||i.triggerRef.current?.focus(),o.current=!1,e.preventDefault()}),onInteractOutside:f(e.onInteractOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0,r=t.button===2||n;(!i.modal||r)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})},`DropdownMenuContent`)),Re=U.forwardRef(K(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=Y(n);return(0,W.jsx)(se,{...i,...r,ref:t})},`DropdownMenuItem`)),ze=Me,Be=Pe,Ve=Fe,He=Le,Ue=Re,We=new Set([`postgres:`,`postgresql:`]);function Ge(e){let t=e.trim().replace(/^psql\s+(['"])?/,``).replace(/['"]$/,``);if(!/^postgres(ql)?:\/\//i.test(t))return null;let n;try{n=new URL(t)}catch{return null}if(!We.has(n.protocol.toLowerCase())||!n.hostname)return null;let r=e=>{try{return decodeURIComponent(e)}catch{return e}},i={host:n.hostname};n.port&&(i.port=Number(n.port)),n.username&&(i.user=r(n.username)),n.password&&(i.pass=r(n.password));let a=r(n.pathname.replace(/^\//,``));return a&&(i.database=a),i}var Ke=new Set([`localhost`,`127.0.0.1`,`[::1]`,`::1`,`0.0.0.0`]);async function qe(e,t){let n;try{let t=new URL(e);if(!Ke.has(t.hostname.toLowerCase()))return[];n=t.origin}catch{return[]}try{let e=await fetch(`${n}/cdn-cgi/local/explorer/api/d1/database`,{signal:t});if(!e.ok)return[];let r=await e.json(),i=new Map;for(let e of r.result??[])e.uuid&&i.set(e.uuid,{name:e.name??e.uuid,id:e.uuid});return[...i.values()]}catch{return[]}}var Je=[`utf8`,`utf8mb4`,`latin1`,`ascii`,`euckr`,`sjis`,`big5`],Ye={enabled:!1,host:``,port:22,user:``,auth:`key`};function X({label:e,htmlFor:t,children:n}){return(0,W.jsxs)(`div`,{className:`grid grid-cols-[120px_minmax(0,1fr)] items-center gap-2`,children:[(0,W.jsx)(me,{htmlFor:t,children:e}),n]})}function Xe({value:e,onChange:t}){let{t:n}=a();function r(n,r){t({...e,[n]:r})}let[i,o]=(0,U.useState)([]),s=e.dbms===`d1`?e.devUrl??``:``;(0,U.useEffect)(()=>{if(!s){o([]);return}let e=new AbortController,t=setTimeout(()=>{qe(s,e.signal).then(o)},300);return()=>{clearTimeout(t),e.abort()}},[s]);let c=e.dbms===`sqlite`,u=e.transport??`browser`,d=c&&u===`browser`,f=x.has(e.dbms),p=e.dbms===`d1`,y=e.dbms===`do`,ee=k.find(t=>t.id===e.dbms)?.capabilities,b=e.ssh??Ye,[C,w]=(0,U.useState)(``),T=C.trim()===``?`empty`:Ge(C)?`applied`:`invalid`,te=e.dbms===`supabase`&&e.port===6543;function ne(n){w(n);let r=Ge(n);r&&t({...e,host:r.host??e.host,port:r.port??k.find(t=>t.id===e.dbms)?.defaultPort??e.port,user:r.user??e.user,pass:r.pass??e.pass,database:r.database??e.database})}function E(n){t({...e,ssh:{...b,...n}})}async function D(e){e&&E({privateKey:await e.text(),privateKeyName:e.name})}return(0,W.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,W.jsx)(X,{label:n(`connection.form.hostName`),htmlFor:`conn-hostName`,children:(0,W.jsx)(L,{id:`conn-hostName`,placeholder:n(`connection.form.hostNamePlaceholder`),value:e.hostName,onChange:e=>r(`hostName`,e.target.value)})}),(0,W.jsx)(X,{label:n(`connection.form.dataSource`),children:(0,W.jsxs)(v,{value:e.dbms,onValueChange:n=>{let r=k.find(e=>e.id===n);if(!r)return;let i=r.id,a=x.has(i)||i===`d1`||i===`do`;w(``),t({...e,dbms:i,transactionMode:r.capabilities.transactions?e.transactionMode:`auto`,port:r.defaultPort??e.port,host:a&&e.host===`localhost`?``:!a&&e.host===``?`localhost`:e.host,user:a||f||p||y?z(i):e.user,devUrl:i===`do`?e.devUrl||`http://localhost:8787`:e.devUrl,database:e.database&&!a&&!f&&!p&&!y?e.database:R(i)??e.database})},children:[(0,W.jsx)(h,{id:`conn-dbms`,className:`w-full`,children:(0,W.jsx)(m,{})}),(0,W.jsx)(g,{children:k.map(e=>(0,W.jsx)(_,{value:e.id,children:(0,W.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(B,{dbms:e.id}),e.label]})},e.id))})]})}),f&&(0,W.jsx)(X,{label:n(`connection.form.connectionString`),htmlFor:`conn-uri`,children:(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(L,{id:`conn-uri`,type:`password`,autoComplete:`new-password`,spellCheck:!1,className:`font-mono text-xs`,placeholder:e.dbms===`neon`?`postgresql://neondb_owner:npg_…@ep-….neon.tech/neondb?sslmode=require`:`postgresql://postgres.[ref]:[password]@aws-0-….pooler.supabase.com:5432/postgres`,value:C,onChange:e=>ne(e.target.value)}),(0,W.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed ${T===`invalid`?`text-destructive`:`text-muted-foreground`}`,children:n(T===`invalid`?`connection.form.connectionStringInvalid`:T===`applied`?`connection.form.connectionStringApplied`:e.dbms===`neon`?`connection.form.neonHint`:`connection.form.supabaseHint`)})]})}),c&&(0,W.jsxs)(X,{label:n(`connection.form.openVia`),children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-sm cursor-pointer`,children:[(0,W.jsx)(`input`,{type:`radio`,name:`transport`,value:`browser`,checked:u===`browser`,onChange:()=>r(`transport`,`browser`),className:`accent-primary`}),n(`connection.form.viaBrowser`)]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-sm cursor-pointer`,children:[(0,W.jsx)(`input`,{type:`radio`,name:`transport`,value:`tunnel`,checked:u===`tunnel`,onChange:()=>r(`transport`,`tunnel`),className:`accent-primary`}),n(`connection.form.viaAgent`)]})]}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(u===`browser`?`connection.form.viaBrowserHint`:`connection.form.viaAgentHint`)})]}),d?(0,W.jsx)(X,{label:n(`connection.form.databaseFile`),children:(0,W.jsxs)(`div`,{className:`min-w-0 text-xs text-muted-foreground leading-relaxed`,children:[e.file?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,W.jsx)(`span`,{className:`min-w-0 break-all text-foreground`,title:e.file,children:e.file}),(0,W.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,className:`h-6 shrink-0 px-2 text-xs`,onClick:()=>{O(e.id),r(`file`,``)},children:n(`connection.form.changeFile`)})]}):(0,W.jsx)(`p`,{children:n(`connection.form.filePickerHint`)}),(0,W.jsx)(`p`,{className:`mt-1`,children:n(`connection.form.fileRememberedHint`)})]})}):null,!d&&(0,W.jsx)(X,{label:n(`connection.form.authToken`),htmlFor:`conn-authToken`,children:(0,W.jsx)(L,{id:`conn-authToken`,type:`password`,autoComplete:`new-password`,placeholder:n(`connection.form.authTokenPlaceholder`),value:e.authToken,onChange:e=>r(`authToken`,e.target.value.trim())})}),d?null:y?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.doDevUrl`),htmlFor:`conn-do-url`,children:(0,W.jsx)(L,{id:`conn-do-url`,className:`font-mono text-xs`,spellCheck:!1,placeholder:`http://localhost:8787`,value:e.devUrl??``,onChange:e=>r(`devUrl`,e.target.value.trim())})}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.doHint`)}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.doLimitsHint`)})]}):p?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.d1DevUrl`),htmlFor:`conn-d1-dev`,children:(0,W.jsx)(L,{id:`conn-d1-dev`,autoComplete:`off`,className:`font-mono text-xs`,spellCheck:!1,placeholder:`http://localhost:8787`,value:e.devUrl??``,onChange:e=>r(`devUrl`,e.target.value.trim())})}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.d1DevUrlHint`)}),(0,W.jsx)(X,{label:n(`connection.form.d1AccountId`),htmlFor:`conn-d1-account`,children:(0,W.jsx)(L,{id:`conn-d1-account`,autoComplete:`off`,className:`font-mono text-xs`,spellCheck:!1,placeholder:`023e105f4ecef8ad9ca31a8372d0c353`,value:e.accountId??``,onChange:e=>r(`accountId`,e.target.value.trim())})}),(0,W.jsx)(X,{label:n(`connection.form.d1DatabaseId`),htmlFor:`conn-d1-database`,children:i.length>0?(0,W.jsxs)(v,{value:e.databaseId??``,onValueChange:e=>r(`databaseId`,e),children:[(0,W.jsx)(h,{id:`conn-d1-database`,children:(0,W.jsx)(m,{placeholder:n(`connection.form.d1PickDatabase`)})}),(0,W.jsx)(g,{children:i.map(e=>(0,W.jsxs)(_,{value:e.id,children:[e.name,` · `,e.id]},e.id))})]}):(0,W.jsx)(L,{id:`conn-d1-database`,autoComplete:`off`,className:`font-mono text-xs`,spellCheck:!1,placeholder:`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,value:e.databaseId??``,onChange:e=>r(`databaseId`,e.target.value.trim())})}),(0,W.jsx)(X,{label:n(`connection.form.d1ApiToken`),htmlFor:`conn-pass`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(L,{id:`conn-pass`,type:`password`,autoComplete:`new-password`,value:e.pass,onChange:e=>r(`pass`,e.target.value.trim())}),(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs whitespace-nowrap cursor-pointer`,title:n(`connection.form.savePasswordHint`),children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:e.savePassword??!0,onChange:e=>r(`savePassword`,e.target.checked)}),n(`connection.form.savePassword`)]})]})}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.d1Hint`)}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.d1LimitsHint`)})]}):c?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.databaseFile`),htmlFor:`conn-file`,children:(0,W.jsx)(L,{id:`conn-file`,placeholder:n(`connection.form.filePathPlaceholder`),value:e.file??``,onChange:e=>r(`file`,e.target.value)})}),(0,W.jsx)(X,{label:n(`connection.form.createIfMissing`),htmlFor:`conn-create`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{id:`conn-create`,type:`checkbox`,checked:e.createIfMissing??!1,onChange:e=>r(`createIfMissing`,e.target.checked),className:`size-4 accent-primary cursor-pointer`}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`connection.form.createIfMissingHint`)})]})})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.host`),htmlFor:`conn-host`,children:(0,W.jsx)(L,{id:`conn-host`,placeholder:e.dbms===`neon`?`ep-….aws.neon.tech`:e.dbms===`supabase`?`aws-0-….pooler.supabase.com`:`localhost`,value:e.host,onChange:e=>r(`host`,e.target.value)})}),(0,W.jsx)(X,{label:n(`connection.form.port`),htmlFor:`conn-port`,children:(0,W.jsx)(L,{id:`conn-port`,type:`number`,value:e.port,onChange:t=>r(`port`,Number(t.target.value)||k.find(t=>t.id===e.dbms)?.defaultPort||3306)})}),te&&(0,W.jsx)(`p`,{className:`col-start-2 rounded-md border border-yellow-500/40 bg-yellow-500/10 px-2 py-1.5 text-xs leading-relaxed text-foreground`,children:n(`connection.form.supabasePoolerWarning`)}),(S(e.dbms)||e.dbms===`mssql`||e.dbms===`oracle`)&&(0,W.jsx)(X,{label:e.dbms===`oracle`?n(`connection.form.serviceName`):n(`connection.form.database`),htmlFor:`conn-database`,children:(0,W.jsx)(L,{id:`conn-database`,placeholder:R(e.dbms),value:e.database??``,onChange:e=>r(`database`,e.target.value.trim())})}),(0,W.jsx)(X,{label:n(`connection.form.user`),htmlFor:`conn-user`,children:(0,W.jsx)(L,{id:`conn-user`,autoComplete:`off`,placeholder:z(e.dbms),value:e.user,onChange:e=>r(`user`,e.target.value)})}),(0,W.jsx)(X,{label:n(`connection.form.password`),htmlFor:`conn-pass`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(L,{id:`conn-pass`,type:`password`,autoComplete:`new-password`,value:e.pass,onChange:e=>r(`pass`,e.target.value)}),(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs whitespace-nowrap cursor-pointer`,title:n(`connection.form.savePasswordHint`),children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:e.savePassword??!0,onChange:e=>r(`savePassword`,e.target.checked)}),n(`connection.form.savePassword`)]})]})}),f&&(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.managedTlsHint`)}),!f&&e.dbms!==`oracle`&&(0,W.jsx)(X,{label:n(`connection.form.tls`),children:(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:e.ssl??!1,onChange:e=>r(`ssl`,e.target.checked),className:`size-4 accent-primary`}),n(`connection.form.tlsEnable`)]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer ${e.ssl?``:`opacity-50`}`,title:n(`connection.form.tlsVerifyHint`),children:[(0,W.jsx)(`input`,{type:`checkbox`,disabled:!e.ssl,checked:e.sslVerify??!1,onChange:e=>r(`sslVerify`,e.target.checked),className:`size-4 accent-primary`}),n(`connection.form.tlsVerify`)]})]})}),!f&&(0,W.jsx)(X,{label:n(`connection.form.charset`),children:(0,W.jsxs)(v,{value:e.charset,onValueChange:e=>r(`charset`,e),children:[(0,W.jsx)(h,{className:`w-full`,children:(0,W.jsx)(m,{})}),(0,W.jsx)(g,{children:Je.map(e=>(0,W.jsx)(_,{value:e,children:e},e))})]})})]}),!c&&!f&&!p&&!y&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`mt-1 flex items-center border-t pt-3 text-xs font-medium text-muted-foreground`,children:[n(`connection.form.ssh`),(0,W.jsx)(H,{className:`ml-2`})]}),(0,W.jsx)(X,{label:n(`connection.form.sshTunnel`),htmlFor:`conn-ssh`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{id:`conn-ssh`,type:`checkbox`,checked:b.enabled,onChange:e=>{(!e.target.checked||ce(`ssh_tunnel`))&&E({enabled:e.target.checked})},className:`size-4 accent-primary cursor-pointer`}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`connection.form.sshTunnelHint`)})]})}),b.enabled&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.sshHost`),htmlFor:`conn-ssh-host`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(L,{id:`conn-ssh-host`,placeholder:n(`connection.form.sshHostPlaceholder`),value:b.host,onChange:e=>E({host:e.target.value.trim()})}),(0,W.jsx)(L,{"aria-label":n(`connection.form.sshPort`),type:`number`,className:`w-24 shrink-0`,value:b.port,onChange:e=>E({port:Number(e.target.value)||22})})]})}),(0,W.jsx)(X,{label:n(`connection.form.sshUser`),htmlFor:`conn-ssh-user`,children:(0,W.jsx)(L,{id:`conn-ssh-user`,placeholder:n(`connection.form.sshUserPlaceholder`),value:b.user,onChange:e=>E({user:e.target.value.trim()})})}),(0,W.jsx)(X,{label:n(`connection.form.sshAuth`),children:(0,W.jsxs)(v,{value:b.auth,onValueChange:e=>E({auth:e}),children:[(0,W.jsx)(h,{className:`w-full`,children:(0,W.jsx)(m,{})}),(0,W.jsxs)(g,{children:[(0,W.jsx)(_,{value:`key`,children:n(`connection.form.sshAuthKey`)}),(0,W.jsx)(_,{value:`password`,children:n(`connection.form.sshAuthPassword`)}),(0,W.jsx)(_,{value:`agent`,children:n(`connection.form.sshAuthAgent`)})]})]})}),b.auth===`password`&&(0,W.jsx)(X,{label:n(`connection.form.sshPassword`),htmlFor:`conn-ssh-pass`,children:(0,W.jsx)(L,{id:`conn-ssh-pass`,type:`password`,autoComplete:`new-password`,value:b.password??``,onChange:e=>E({password:e.target.value})})}),b.auth===`key`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.sshKey`),htmlFor:`conn-ssh-key`,children:(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`input`,{id:`conn-ssh-key`,type:`file`,className:`hidden`,onChange:e=>{D(e.target.files?.[0]),e.target.value=``}}),(0,W.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 shrink-0 px-2 text-xs`,onClick:()=>document.getElementById(`conn-ssh-key`)?.click(),children:b.privateKey?n(`connection.form.changeFile`):n(`connection.form.sshKeyPick`)}),(0,W.jsx)(`span`,{className:`min-w-0 truncate text-xs text-muted-foreground`,title:b.privateKeyName,children:b.privateKey?b.privateKeyName||n(`connection.form.sshKeyLoaded`):n(`connection.form.sshKeyHint`)})]})}),(0,W.jsx)(X,{label:n(`connection.form.sshPassphrase`),htmlFor:`conn-ssh-passphrase`,children:(0,W.jsx)(L,{id:`conn-ssh-passphrase`,type:`password`,autoComplete:`new-password`,placeholder:n(`connection.form.sshPassphrasePlaceholder`),value:b.passphrase??``,onChange:e=>E({passphrase:e.target.value})})})]}),b.auth===`agent`&&(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.sshAuthAgentHint`)}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.sshTargetHint`)}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.sshSecretsHint`)})]})]}),(0,W.jsx)(X,{label:n(`connection.form.autoConnection`),htmlFor:`conn-auto`,children:(0,W.jsx)(`div`,{className:`flex items-center`,children:(0,W.jsx)(`input`,{id:`conn-auto`,type:`checkbox`,checked:e.autoConnection,onChange:e=>r(`autoConnection`,e.target.checked),className:`size-4 accent-primary cursor-pointer`})})}),(0,W.jsx)(`div`,{className:`mt-1 border-t pt-3 text-xs font-medium text-muted-foreground`,children:n(`connection.form.safety`)}),(0,W.jsx)(X,{label:n(`connection.form.environment`),children:(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[A.map(t=>{let n=(e.environmentColor??`none`)===t.id;return(0,W.jsx)(`button`,{type:`button`,title:I(t.id),"aria-label":I(t.id),"aria-pressed":n,onClick:()=>r(`environmentColor`,t.id),className:`size-6 rounded-full border-2 transition-transform ${n?`scale-110 border-foreground`:`border-transparent hover:scale-105`}`,style:{background:t.id===`none`?`repeating-linear-gradient(45deg, transparent, transparent 3px, var(--muted-foreground) 3px, var(--muted-foreground) 4px)`:t.hex}},t.id)}),(0,W.jsx)(`span`,{className:`ml-1 text-xs text-muted-foreground`,children:n(`connection.form.environmentHint`)})]})}),(0,W.jsx)(X,{label:n(`connection.form.readOnly`),htmlFor:`conn-readonly`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{id:`conn-readonly`,type:`checkbox`,checked:e.readOnly??!1,onChange:e=>r(`readOnly`,e.target.checked),className:`size-4 accent-primary cursor-pointer`}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`connection.form.readOnlyHint`)})]})}),ee?.transactions!==!1&&(0,W.jsx)(X,{label:n(`connection.form.transactions`),children:(0,W.jsxs)(v,{value:e.transactionMode??`auto`,onValueChange:e=>r(`transactionMode`,e),children:[(0,W.jsx)(h,{className:`w-full`,children:(0,W.jsx)(m,{})}),(0,W.jsxs)(g,{children:[(0,W.jsx)(_,{value:`auto`,children:n(`connection.form.txAuto`)}),(0,W.jsx)(_,{value:`manual`,children:n(`connection.form.txManual`)})]})]})})]})}var Ze=[`id`,`serverConnectionId`,`sample`,`scratchpad`,`autoConnection`];function Qe(e){return!e.sample&&!e.scratchpad}function $e(e,t,n=new Date){let r=t?e:y(e),i={...r};for(let e of Ze)delete i[e];if(i.pass||delete i.pass,i.authToken||delete i.authToken,r.ssh){let e={...r.ssh};for(let t of[`password`,`passphrase`,`privateKey`])e[t]||delete e[t];i.ssh=e}return{planche:`connection`,version:1,exportedAt:n.toISOString(),secrets:t,connection:i}}function et(e){let t;try{t=JSON.parse(e)}catch{throw Error(`Not a JSON file`)}let n=t;if(!n||n.planche!==`connection`||!n.connection||typeof n.connection!=`object`)throw Error(`Not a Planche connection file`);if(typeof n.connection.dbms!=`string`||!n.connection.dbms)throw Error(`The connection has no database type`);return n}var Z=(e,t=``)=>typeof e==`string`?e:t,Q=e=>typeof e==`boolean`?e:void 0,tt=(e,t)=>typeof e==`number`&&Number.isFinite(e)?e:t,$=e=>e===void 0||e===``?void 0:e;function nt(e){if(!e||typeof e!=`object`)return;let t=e,n=t.auth===`key`||t.auth===`agent`?t.auth:`password`;return{enabled:t.enabled===!0,host:Z(t.host),port:tt(t.port,22),user:Z(t.user),auth:n,password:$(Z(t.password)),privateKey:$(Z(t.privateKey)),privateKeyName:$(Z(t.privateKeyName)),passphrase:$(Z(t.passphrase))}}function rt(e,t,n=crypto.randomUUID()){let r=e.connection,i=Q(r.savePassword),a={id:n,hostName:it(Z(r.hostName),t),host:Z(r.host),user:Z(r.user),pass:Z(r.pass),charset:Z(r.charset,`utf8`),port:tt(r.port,0),dbms:r.dbms,database:$(Z(r.database)),transport:r.transport===`tunnel`||r.transport===`browser`?r.transport:void 0,file:$(Z(r.file)),createIfMissing:Q(r.createIfMissing),ssl:Q(r.ssl),sslVerify:Q(r.sslVerify),accountId:$(Z(r.accountId)),databaseId:$(Z(r.databaseId)),devUrl:$(Z(r.devUrl)),ssh:nt(r.ssh),gatewayProfile:$(Z(r.gatewayProfile)),autoConnection:!1,savePassword:i??!0,authToken:Z(r.authToken),readOnly:Q(r.readOnly),environmentColor:$(Z(r.environmentColor)),transactionMode:$(Z(r.transactionMode))};for(let e of Object.keys(a))a[e]===void 0&&delete a[e];return a}function it(e,t){if(!e||!t.some(t=>t.hostName===e))return e;for(let n=2;;n++){let r=`${e} (${n})`;if(!t.some(e=>e.hostName===r))return r}}async function at(e,t,n=`application/json`){let r=Oe(e);if(typeof window.showSaveFilePicker==`function`)try{let e=await(await window.showSaveFilePicker({suggestedName:r,types:[{accept:{[n]:[`.${r.split(`.`).pop()??`txt`}`]}}]})).createWritable();return await e.write(t),await e.close(),!0}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return!1}let i=URL.createObjectURL(new Blob([t],{type:n})),a=document.createElement(`a`);return a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),!0}function ot(e=`.json,application/json`){return new Promise(t=>{let n=document.createElement(`input`);n.type=`file`,n.accept=e,n.onchange=async()=>{let e=n.files?.[0];t(e?await e.text():null)},n.oncancel=()=>t(null),n.click()})}function st({...e}){return(0,W.jsx)(ze,{"data-slot":`dropdown-menu`,...e})}function ct({...e}){return(0,W.jsx)(Be,{"data-slot":`dropdown-menu-trigger`,...e})}function lt({className:e,sideOffset:t=4,...n}){return(0,W.jsx)(Ve,{children:(0,W.jsx)(He,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:o(`z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...n})})}function ut({className:e,inset:t,variant:n=`default`,...r}){return(0,W.jsx)(Ue,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:o(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!`,e),...r})}function dt(){let{t:e}=a(),{activeDialog:t,closeDialog:i,showMessage:o}=n(),[s,c]=(0,U.useState)(!1),{savedConnections:u,addSavedConnection:d,updateSavedConnection:f,deleteSavedConnection:p,openConnection:m}=b(),h=r(`connect`)?.profileId,[g,_]=(0,U.useState)(()=>h??null),[v,y]=(0,U.useState)(()=>{let e=h?u.find(e=>e.id===h):void 0;return e?{...e}:null}),x=t===`connect`,[S,O]=(0,U.useState)(null),[k,A]=(0,U.useState)(null),se=be(e=>e.url),ce=be(e=>e.token);(0,U.useEffect)(()=>{if(!x)return;let e=!1;return(async()=>{try{let t=await w();if(e||t.state!==`online`||!t.gateway){e||O(null);return}let n=await T();e||(O({name:n.gateway,profiles:n.profiles}),A(null))}catch(t){e||A(t instanceof Error?t.message:String(t))}})(),()=>{e=!0}},[x,se,ce]);function M(t){let r=u.find(e=>e.gatewayProfile===t.name);if(r){P(r);return}let i=ye(t);d(i),P(i),n.getState().setFooterMessage(e(`connection.dialog.gatewayAdded`,{name:t.name}))}function N(e){e||(i(),_(null),y(null))}function P(e){_(e.id),y({...e})}function de(e){y(e),f(e.id,e)}function me(){let e=fe();d(e),_(e.id),y(e)}function I(){g&&(p(g),_(null),y(null))}async function L(t){let r=u.find(e=>e.id===g);if(!r||!Qe(r))return;let i=r.hostName||e(`connection.dialog.unnamed`),a=$e(b.getState().resolveCredentials(r),t);await at(`planche-connection-${i}.json`,JSON.stringify(a,null,2))&&n.getState().setFooterMessage(e(`connection.dialog.exported`,{name:i}))}async function R(){let t=await ot();if(t!==null)try{let r=rt(et(t),b.getState().savedConnections);d(r),_(r.id),y(r),n.getState().setFooterMessage(e(`connection.dialog.imported`,{name:r.hostName||e(`connection.dialog.unnamed`)}))}catch(t){o({tone:`error`,title:e(`connection.dialog.importFailedTitle`),description:t instanceof Error?t.message:String(t)})}}let ve=g!==null&&u.some(e=>e.id===g&&Qe(e)),[z,H]=(0,U.useState)(!1),Oe=ne(e=>e.addQueryTab);function G(t){let n=b.getState().activeConnections.some(e=>e.id===t.id);if(m(t),E.getState().removeTree(t.id),ee(t.id),n){i(),_(null),y(null);return}Oe(t.id,{id:`tab-${Date.now()}`,title:e(`connection.dialog.firstQueryTab`),query:``,database:``,isExecuting:!1,results:[],error:null,executionTime:null}),i(),_(null),y(null)}async function K(t){let r=await ae(t.id,{interactive:!0});if(!r)return;let i={...t,file:r.fileName,serverConnectionId:r.connectionId};f(t.id,{file:r.fileName}),G(i),b.getState().setFileDetached(t.id,r.fileDetached),r.restoredUnsaved?n.getState().setFooterMessage(e(r.diskChanged?`connection.dialog.restoredUnsavedDiskChanged`:`connection.dialog.restoredUnsaved`,{file:r.fileName})):r.wal&&!r.walApplied?n.getState().setFooterMessage(e(`connection.dialog.walPending`,{file:r.fileName})):r.walApplied&&n.getState().setFooterMessage(e(`connection.dialog.walApplied`,{file:r.fileName}))}async function q(t,r){try{return await r(t)}catch(i){let a=te(i);if(!a||!(`ssh`in t)||!t.ssh||!await n.getState().requestDestructiveConfirm({title:e(`connection.dialog.hostKeyTitle`),description:e(`connection.dialog.hostKeyDescription`,a),confirmLabel:e(`connection.dialog.hostKeyAccept`)}))throw i;return r({...t,ssh:{...t.ssh,acceptHostKey:a.fingerprint}})}}async function J(){if(v){H(!0);try{if(D(v)===`browser`){await K(v);return}let t=await q(C(v),e=>ie(e,v.authToken||void 0));t.success?G({...v,serverConnectionId:t.connectionId}):o({tone:`error`,title:e(`connection.dialog.connectFailedTitle`),description:t.message??e(`connection.dialog.unknownError`)})}catch(t){o({tone:`error`,title:e(`connection.dialog.connectFailedTitle`),description:t instanceof Error?t.message:String(t)})}finally{H(!1)}}}async function ke(){if(v){if(D(v)===`browser`){o({tone:`info`,title:e(`connection.dialog.testConnection`),description:e(`connection.dialog.browserTestHint`)});return}c(!0);try{let t=await q(C(v),e=>re(e,v.authToken||void 0));t.success?o({tone:`success`,title:e(`connection.dialog.testSuccess`),description:e(`connection.dialog.testSuccessDescription`)}):o({tone:`error`,title:e(`connection.dialog.testFailedTitle`),description:t.message??e(`connection.dialog.unknownError`)})}catch(t){o({tone:`error`,title:e(`connection.dialog.testFailedTitle`),description:t instanceof Error?t.message:String(t)})}finally{c(!1)}}}return(0,W.jsx)(De,{open:x,onOpenChange:N,children:(0,W.jsxs)(Te,{className:`sm:max-w-[1100px] h-[85vh] max-h-[85vh] flex flex-col`,children:[(0,W.jsx)(Ce,{children:(0,W.jsx)(Ee,{children:e(`connection.dialog.title`)})}),(0,W.jsxs)(`p`,{className:`flex items-start gap-2 rounded-md border border-catppuccin-green/40 bg-catppuccin-green/10 px-3 py-2 text-xs leading-relaxed text-foreground`,children:[(0,W.jsx)(pe,{className:`mt-0.5 size-4 shrink-0 text-catppuccin-green`,"aria-hidden":!0}),(0,W.jsx)(`span`,{children:e(`connection.dialog.privacy`)})]}),(0,W.jsxs)(`div`,{className:`flex flex-1 gap-4 overflow-hidden min-h-0`,children:[(0,W.jsxs)(`div`,{className:`w-[460px] shrink-0 border rounded-md overflow-hidden flex flex-col`,children:[(S||k)&&(0,W.jsxs)(`div`,{className:`border-b p-2 text-xs space-y-1 max-h-40 overflow-auto`,children:[(0,W.jsxs)(`p`,{className:`font-medium`,children:[e(`connection.dialog.gatewayTitle`),S?` — ${S.name}`:``]}),k&&(0,W.jsx)(`p`,{className:`text-destructive`,children:e(`connection.dialog.gatewayLoadFailed`,{error:k})}),S?.profiles.map(t=>(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5 truncate`,children:[(0,W.jsx)(B,{dbms:_e[t.driver],className:`size-3.5`}),(0,W.jsx)(`span`,{className:`truncate`,children:t.name}),(0,W.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,t.readOnly?e(`connection.dialog.gatewayReadOnly`):e(`connection.dialog.gatewayWritable`),`)`]})]}),(0,W.jsx)(l,{size:`sm`,variant:`outline`,className:`h-6 px-2 text-xs`,onClick:()=>M(t),children:e(`connection.dialog.gatewayAdd`)})]},t.name))]}),(0,W.jsx)(ge,{className:`h-full`,children:(0,W.jsxs)(xe,{className:`table-fixed`,children:[(0,W.jsx)(ue,{children:(0,W.jsxs)(j,{children:[(0,W.jsx)(V,{className:`w-[32%]`,children:e(`connection.dialog.colHostName`)}),(0,W.jsx)(V,{className:`w-[40%]`,children:e(`connection.dialog.colTarget`)}),(0,W.jsx)(V,{className:`w-[28%]`,children:e(`connection.dialog.colDbms`)})]})}),(0,W.jsx)(Se,{children:u.length===0?(0,W.jsx)(j,{children:(0,W.jsx)(F,{colSpan:3,className:`text-center text-muted-foreground`,children:e(`connection.dialog.noSaved`)})}):u.map(t=>(0,W.jsxs)(j,{"data-state":g===t.id?`selected`:void 0,className:`cursor-pointer`,onClick:()=>P(t),onDoubleClick:()=>{P(t),J()},children:[(0,W.jsx)(F,{className:`truncate font-medium`,title:t.hostName,children:t.hostName||e(`connection.dialog.unnamed`)}),(0,W.jsx)(F,{className:`truncate`,title:t.dbms===`sqlite`?t.file:t.dbms===`d1`?t.databaseId:t.dbms===`do`?t.devUrl:`${t.user}@${t.host}:${t.port}`,children:t.dbms===`sqlite`?t.file||(D(t)===`browser`?e(`connection.dialog.pickOnConnect`):e(`connection.dialog.noFile`)):t.dbms===`d1`?t.databaseId||`—`:t.dbms===`do`?t.devUrl||`—`:`${t.user}@${t.host}:${t.port}`}),(0,W.jsx)(F,{className:`truncate`,title:oe(t.dbms).label,children:(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(B,{dbms:t.dbms,className:`size-3.5`}),(0,W.jsx)(`span`,{className:`truncate`,children:oe(t.dbms).label})]})})]},t.id))})]})})]}),(0,W.jsx)(`div`,{className:`flex-1 border rounded-md overflow-auto`,children:v?(0,W.jsxs)(W.Fragment,{children:[D(v)!==`browser`&&(0,W.jsx)(`div`,{className:`p-4 pb-0`,children:(0,W.jsx)(he,{})}),v.gatewayProfile?(0,W.jsxs)(`div`,{className:`p-4 space-y-2 text-sm`,children:[(0,W.jsxs)(`p`,{className:`font-medium flex items-center gap-2`,children:[(0,W.jsx)(B,{dbms:v.dbms,className:`size-4`}),v.hostName]}),(0,W.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connection.dialog.gatewayProfileHint`,{name:v.gatewayProfile})}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[v.readOnly?e(`connection.dialog.gatewayReadOnly`):e(`connection.dialog.gatewayWritable`),v.database?` · ${v.database}`:``]})]}):(0,W.jsx)(Xe,{value:v,onChange:de})]}):(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:e(`connection.dialog.selectPrompt`)})})]}),(0,W.jsxs)(we,{className:`sm:justify-between`,children:[(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(l,{variant:`outline`,onClick:me,children:e(`connection.dialog.addNew`)}),(0,W.jsx)(l,{variant:`destructive`,onClick:I,disabled:!g,children:e(`connection.dialog.delete`)}),(0,W.jsxs)(st,{children:[(0,W.jsx)(ct,{asChild:!0,children:(0,W.jsxs)(l,{variant:`outline`,disabled:!ve,children:[e(`connection.dialog.export`),(0,W.jsx)(le,{className:`ml-1 size-3.5`,"aria-hidden":!0})]})}),(0,W.jsxs)(lt,{align:`start`,children:[(0,W.jsx)(ut,{onSelect:()=>void L(!1),children:e(`connection.dialog.exportWithoutSecrets`)}),(0,W.jsx)(ut,{onSelect:()=>void L(!0),children:e(`connection.dialog.exportWithSecrets`)})]})]}),(0,W.jsx)(l,{variant:`outline`,onClick:()=>void R(),children:e(`connection.dialog.import`)})]}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(l,{variant:`outline`,onClick:ke,disabled:!v||s,children:e(`connection.dialog.testConnection`)}),(0,W.jsx)(l,{onClick:J,disabled:!v||z,children:e(`connection.dialog.connect`)}),(0,W.jsx)(l,{variant:`outline`,onClick:()=>N(!1),children:e(`connection.dialog.close`)})]})]})]})})}export{dt as ConnectDialog};
1
+ import{r as e}from"./hePW80VL.js";import{h as t,n,t as r}from"./B1pia_Rg.js";import{l as i,m as a,o,p as s,s as c,t as l}from"./pjlgs2cl.js";import{S as u,_ as d,x as f,y as p}from"./CF6jyexg.js";import{a as m,i as h,n as g,r as _,t as v}from"./CiFkP-9S.js";import{T as y,f as ee,t as b}from"./BCmzDvBt.js";import{E as x,O as S,T as C,a as w,f as T,m as te}from"./DEEGN6UG.js";import{n as ne}from"./BO_H_8D-.js";import{S as E,d as D,g as re,i as ie,l as O,r as ae}from"./CS2mpWDL.js";import{n as oe,t as k}from"./DbqogdCK.js";import{A,C as j,Gt as se,I as ce,Jt as M,Kt as N,Lt as le,S as ue,Ut as P,Wt as de,a as fe,b as F,bt as pe,c as me,i as he,j as I,l as L,lt as ge,n as _e,o as R,qt as ve,r as ye,rt as be,s as z,u as B,v as xe,x as V,y as Se,z as H}from"./Bhquh17w.js";import{a as Ce,i as we,n as Te,o as Ee,t as De}from"./BgkATqP8.js";import{t as Oe}from"./CnYBZPf9.js";var U=e(t(),1),W=i(),G=Object.defineProperty,K=(e,t)=>G(e,`name`,{value:t,configurable:!0}),q=`DropdownMenu`,[J,ke]=u(q,[M]),Y=M(),[Ae,je]=J(q),Me=K(e=>{let{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:a,onOpenChange:o,modal:s=!0}=e,c=Y(t),l=U.useRef(null),[u,f]=p({prop:i,defaultProp:a??!1,onChange:o,caller:q});return(0,W.jsx)(Ae,{scope:t,triggerId:d(),triggerRef:l,contentId:d(),open:u,onOpenChange:f,onOpenToggle:U.useCallback(()=>f(e=>!e),[f]),modal:s,children:(0,W.jsx)(ve,{...c,open:u,onOpenChange:f,dir:r,modal:s,children:n})})},`DropdownMenu`),Ne=`DropdownMenuTrigger`,Pe=U.forwardRef(K(function(e,t){let{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,a=je(Ne,n),o=Y(n),l=s(t,a.triggerRef);return(0,W.jsx)(P,{asChild:!0,...o,children:(0,W.jsx)(c.button,{type:`button`,id:a.triggerId,"aria-haspopup":`menu`,"aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":a.open?`open`:`closed`,"data-disabled":r?``:void 0,disabled:r,...i,ref:l,onPointerDown:f(e.onPointerDown,e=>{!r&&e.button===0&&e.ctrlKey===!1&&(a.onOpenToggle(),a.open||e.preventDefault())}),onKeyDown:f(e.onKeyDown,e=>{r||([`Enter`,` `].includes(e.key)&&a.onOpenToggle(),e.key===`ArrowDown`&&a.onOpenChange(!0),[`Enter`,` `,`ArrowDown`].includes(e.key)&&e.preventDefault())})})})},`DropdownMenuTrigger`)),Fe=K(e=>{let{__scopeDropdownMenu:t,...n}=e,r=Y(t);return(0,W.jsx)(N,{...r,...n})},`DropdownMenuPortal`),Ie=`DropdownMenuContent`,Le=U.forwardRef(K(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=je(Ie,n),a=Y(n),o=U.useRef(!1);return(0,W.jsx)(de,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...r,ref:t,onCloseAutoFocus:f(e.onCloseAutoFocus,e=>{o.current||i.triggerRef.current?.focus(),o.current=!1,e.preventDefault()}),onInteractOutside:f(e.onInteractOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0,r=t.button===2||n;(!i.modal||r)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})},`DropdownMenuContent`)),Re=U.forwardRef(K(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=Y(n);return(0,W.jsx)(se,{...i,...r,ref:t})},`DropdownMenuItem`)),ze=Me,Be=Pe,Ve=Fe,He=Le,Ue=Re,We=new Set([`postgres:`,`postgresql:`]);function Ge(e){let t=e.trim().replace(/^psql\s+(['"])?/,``).replace(/['"]$/,``);if(!/^postgres(ql)?:\/\//i.test(t))return null;let n;try{n=new URL(t)}catch{return null}if(!We.has(n.protocol.toLowerCase())||!n.hostname)return null;let r=e=>{try{return decodeURIComponent(e)}catch{return e}},i={host:n.hostname};n.port&&(i.port=Number(n.port)),n.username&&(i.user=r(n.username)),n.password&&(i.pass=r(n.password));let a=r(n.pathname.replace(/^\//,``));return a&&(i.database=a),i}var Ke=new Set([`localhost`,`127.0.0.1`,`[::1]`,`::1`,`0.0.0.0`]);async function qe(e,t){let n;try{let t=new URL(e);if(!Ke.has(t.hostname.toLowerCase()))return[];n=t.origin}catch{return[]}try{let e=await fetch(`${n}/cdn-cgi/local/explorer/api/d1/database`,{signal:t});if(!e.ok)return[];let r=await e.json(),i=new Map;for(let e of r.result??[])e.uuid&&i.set(e.uuid,{name:e.name??e.uuid,id:e.uuid});return[...i.values()]}catch{return[]}}var Je=[`utf8`,`utf8mb4`,`latin1`,`ascii`,`euckr`,`sjis`,`big5`],Ye={enabled:!1,host:``,port:22,user:``,auth:`key`};function X({label:e,htmlFor:t,children:n}){return(0,W.jsxs)(`div`,{className:`grid grid-cols-[120px_minmax(0,1fr)] items-center gap-2`,children:[(0,W.jsx)(me,{htmlFor:t,children:e}),n]})}function Xe({value:e,onChange:t}){let{t:n}=a();function r(n,r){t({...e,[n]:r})}let[i,o]=(0,U.useState)([]),s=e.dbms===`d1`?e.devUrl??``:``;(0,U.useEffect)(()=>{if(!s){o([]);return}let e=new AbortController,t=setTimeout(()=>{qe(s,e.signal).then(o)},300);return()=>{clearTimeout(t),e.abort()}},[s]);let c=e.dbms===`sqlite`,u=e.transport??`browser`,d=c&&u===`browser`,f=x.has(e.dbms),p=e.dbms===`d1`,y=e.dbms===`do`,ee=k.find(t=>t.id===e.dbms)?.capabilities,b=e.ssh??Ye,[C,w]=(0,U.useState)(``),T=C.trim()===``?`empty`:Ge(C)?`applied`:`invalid`,te=e.dbms===`supabase`&&e.port===6543;function ne(n){w(n);let r=Ge(n);r&&t({...e,host:r.host??e.host,port:r.port??k.find(t=>t.id===e.dbms)?.defaultPort??e.port,user:r.user??e.user,pass:r.pass??e.pass,database:r.database??e.database})}function E(n){t({...e,ssh:{...b,...n}})}async function D(e){e&&E({privateKey:await e.text(),privateKeyName:e.name})}return(0,W.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,W.jsx)(X,{label:n(`connection.form.hostName`),htmlFor:`conn-hostName`,children:(0,W.jsx)(L,{id:`conn-hostName`,placeholder:n(`connection.form.hostNamePlaceholder`),value:e.hostName,onChange:e=>r(`hostName`,e.target.value)})}),(0,W.jsx)(X,{label:n(`connection.form.dataSource`),children:(0,W.jsxs)(v,{value:e.dbms,onValueChange:n=>{let r=k.find(e=>e.id===n);if(!r)return;let i=r.id,a=x.has(i)||i===`d1`||i===`do`;w(``),t({...e,dbms:i,transactionMode:r.capabilities.transactions?e.transactionMode:`auto`,port:r.defaultPort??e.port,host:a&&e.host===`localhost`?``:!a&&e.host===``?`localhost`:e.host,user:a||f||p||y?z(i):e.user,devUrl:i===`do`?e.devUrl||`http://localhost:8787`:e.devUrl,database:e.database&&!a&&!f&&!p&&!y?e.database:R(i)??e.database})},children:[(0,W.jsx)(h,{id:`conn-dbms`,className:`w-full`,children:(0,W.jsx)(m,{})}),(0,W.jsx)(g,{children:k.map(e=>(0,W.jsx)(_,{value:e.id,children:(0,W.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(B,{dbms:e.id}),e.label]})},e.id))})]})}),f&&(0,W.jsx)(X,{label:n(`connection.form.connectionString`),htmlFor:`conn-uri`,children:(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(L,{id:`conn-uri`,type:`password`,autoComplete:`new-password`,spellCheck:!1,className:`font-mono text-xs`,placeholder:e.dbms===`neon`?`postgresql://neondb_owner:npg_…@ep-….neon.tech/neondb?sslmode=require`:`postgresql://postgres.[ref]:[password]@aws-0-….pooler.supabase.com:5432/postgres`,value:C,onChange:e=>ne(e.target.value)}),(0,W.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed ${T===`invalid`?`text-destructive`:`text-muted-foreground`}`,children:n(T===`invalid`?`connection.form.connectionStringInvalid`:T===`applied`?`connection.form.connectionStringApplied`:e.dbms===`neon`?`connection.form.neonHint`:`connection.form.supabaseHint`)})]})}),c&&(0,W.jsxs)(X,{label:n(`connection.form.openVia`),children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-sm cursor-pointer`,children:[(0,W.jsx)(`input`,{type:`radio`,name:`transport`,value:`browser`,checked:u===`browser`,onChange:()=>r(`transport`,`browser`),className:`accent-primary`}),n(`connection.form.viaBrowser`)]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-sm cursor-pointer`,children:[(0,W.jsx)(`input`,{type:`radio`,name:`transport`,value:`tunnel`,checked:u===`tunnel`,onChange:()=>r(`transport`,`tunnel`),className:`accent-primary`}),n(`connection.form.viaAgent`)]})]}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(u===`browser`?`connection.form.viaBrowserHint`:`connection.form.viaAgentHint`)})]}),d?(0,W.jsx)(X,{label:n(`connection.form.databaseFile`),children:(0,W.jsxs)(`div`,{className:`min-w-0 text-xs text-muted-foreground leading-relaxed`,children:[e.file?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,W.jsx)(`span`,{className:`min-w-0 break-all text-foreground`,title:e.file,children:e.file}),(0,W.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,className:`h-6 shrink-0 px-2 text-xs`,onClick:()=>{O(e.id),r(`file`,``)},children:n(`connection.form.changeFile`)})]}):(0,W.jsx)(`p`,{children:n(`connection.form.filePickerHint`)}),(0,W.jsx)(`p`,{className:`mt-1`,children:n(`connection.form.fileRememberedHint`)})]})}):null,!d&&(0,W.jsx)(X,{label:n(`connection.form.authToken`),htmlFor:`conn-authToken`,children:(0,W.jsx)(L,{id:`conn-authToken`,type:`password`,autoComplete:`new-password`,placeholder:n(`connection.form.authTokenPlaceholder`),value:e.authToken,onChange:e=>r(`authToken`,e.target.value.trim())})}),d?null:y?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.doDevUrl`),htmlFor:`conn-do-url`,children:(0,W.jsx)(L,{id:`conn-do-url`,className:`font-mono text-xs`,spellCheck:!1,placeholder:`http://localhost:8787`,value:e.devUrl??``,onChange:e=>r(`devUrl`,e.target.value.trim())})}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.doHint`)}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.doLimitsHint`)})]}):p?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.d1DevUrl`),htmlFor:`conn-d1-dev`,children:(0,W.jsx)(L,{id:`conn-d1-dev`,autoComplete:`off`,className:`font-mono text-xs`,spellCheck:!1,placeholder:`http://localhost:8787`,value:e.devUrl??``,onChange:e=>r(`devUrl`,e.target.value.trim())})}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.d1DevUrlHint`)}),(0,W.jsx)(X,{label:n(`connection.form.d1AccountId`),htmlFor:`conn-d1-account`,children:(0,W.jsx)(L,{id:`conn-d1-account`,autoComplete:`off`,className:`font-mono text-xs`,spellCheck:!1,placeholder:`023e105f4ecef8ad9ca31a8372d0c353`,value:e.accountId??``,onChange:e=>r(`accountId`,e.target.value.trim())})}),(0,W.jsx)(X,{label:n(`connection.form.d1DatabaseId`),htmlFor:`conn-d1-database`,children:i.length>0?(0,W.jsxs)(v,{value:e.databaseId??``,onValueChange:e=>r(`databaseId`,e),children:[(0,W.jsx)(h,{id:`conn-d1-database`,children:(0,W.jsx)(m,{placeholder:n(`connection.form.d1PickDatabase`)})}),(0,W.jsx)(g,{children:i.map(e=>(0,W.jsxs)(_,{value:e.id,children:[e.name,` · `,e.id]},e.id))})]}):(0,W.jsx)(L,{id:`conn-d1-database`,autoComplete:`off`,className:`font-mono text-xs`,spellCheck:!1,placeholder:`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,value:e.databaseId??``,onChange:e=>r(`databaseId`,e.target.value.trim())})}),(0,W.jsx)(X,{label:n(`connection.form.d1ApiToken`),htmlFor:`conn-pass`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(L,{id:`conn-pass`,type:`password`,autoComplete:`new-password`,value:e.pass,onChange:e=>r(`pass`,e.target.value.trim())}),(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs whitespace-nowrap cursor-pointer`,title:n(`connection.form.savePasswordHint`),children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:e.savePassword??!0,onChange:e=>r(`savePassword`,e.target.checked)}),n(`connection.form.savePassword`)]})]})}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.d1Hint`)}),(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.d1LimitsHint`)})]}):c?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.databaseFile`),htmlFor:`conn-file`,children:(0,W.jsx)(L,{id:`conn-file`,placeholder:n(`connection.form.filePathPlaceholder`),value:e.file??``,onChange:e=>r(`file`,e.target.value)})}),(0,W.jsx)(X,{label:n(`connection.form.createIfMissing`),htmlFor:`conn-create`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{id:`conn-create`,type:`checkbox`,checked:e.createIfMissing??!1,onChange:e=>r(`createIfMissing`,e.target.checked),className:`size-4 accent-primary cursor-pointer`}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`connection.form.createIfMissingHint`)})]})})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.host`),htmlFor:`conn-host`,children:(0,W.jsx)(L,{id:`conn-host`,placeholder:e.dbms===`neon`?`ep-….aws.neon.tech`:e.dbms===`supabase`?`aws-0-….pooler.supabase.com`:`localhost`,value:e.host,onChange:e=>r(`host`,e.target.value)})}),(0,W.jsx)(X,{label:n(`connection.form.port`),htmlFor:`conn-port`,children:(0,W.jsx)(L,{id:`conn-port`,type:`number`,value:e.port,onChange:t=>r(`port`,Number(t.target.value)||k.find(t=>t.id===e.dbms)?.defaultPort||3306)})}),te&&(0,W.jsx)(`p`,{className:`col-start-2 rounded-md border border-yellow-500/40 bg-yellow-500/10 px-2 py-1.5 text-xs leading-relaxed text-foreground`,children:n(`connection.form.supabasePoolerWarning`)}),(S(e.dbms)||e.dbms===`mssql`||e.dbms===`oracle`)&&(0,W.jsx)(X,{label:e.dbms===`oracle`?n(`connection.form.serviceName`):n(`connection.form.database`),htmlFor:`conn-database`,children:(0,W.jsx)(L,{id:`conn-database`,placeholder:R(e.dbms),value:e.database??``,onChange:e=>r(`database`,e.target.value.trim())})}),(0,W.jsx)(X,{label:n(`connection.form.user`),htmlFor:`conn-user`,children:(0,W.jsx)(L,{id:`conn-user`,autoComplete:`off`,placeholder:z(e.dbms),value:e.user,onChange:e=>r(`user`,e.target.value)})}),(0,W.jsx)(X,{label:n(`connection.form.password`),htmlFor:`conn-pass`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(L,{id:`conn-pass`,type:`password`,autoComplete:`new-password`,value:e.pass,onChange:e=>r(`pass`,e.target.value)}),(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs whitespace-nowrap cursor-pointer`,title:n(`connection.form.savePasswordHint`),children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:e.savePassword??!0,onChange:e=>r(`savePassword`,e.target.checked)}),n(`connection.form.savePassword`)]})]})}),f&&(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.managedTlsHint`)}),!f&&e.dbms!==`oracle`&&(0,W.jsx)(X,{label:n(`connection.form.tls`),children:(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:e.ssl??!1,onChange:e=>r(`ssl`,e.target.checked),className:`size-4 accent-primary`}),n(`connection.form.tlsEnable`)]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer ${e.ssl?``:`opacity-50`}`,title:n(`connection.form.tlsVerifyHint`),children:[(0,W.jsx)(`input`,{type:`checkbox`,disabled:!e.ssl,checked:e.sslVerify??!1,onChange:e=>r(`sslVerify`,e.target.checked),className:`size-4 accent-primary`}),n(`connection.form.tlsVerify`)]})]})}),!f&&(0,W.jsx)(X,{label:n(`connection.form.charset`),children:(0,W.jsxs)(v,{value:e.charset,onValueChange:e=>r(`charset`,e),children:[(0,W.jsx)(h,{className:`w-full`,children:(0,W.jsx)(m,{})}),(0,W.jsx)(g,{children:Je.map(e=>(0,W.jsx)(_,{value:e,children:e},e))})]})})]}),!c&&!f&&!p&&!y&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`mt-1 flex items-center border-t pt-3 text-xs font-medium text-muted-foreground`,children:[n(`connection.form.ssh`),(0,W.jsx)(H,{className:`ml-2`})]}),(0,W.jsx)(X,{label:n(`connection.form.sshTunnel`),htmlFor:`conn-ssh`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{id:`conn-ssh`,type:`checkbox`,checked:b.enabled,onChange:e=>{(!e.target.checked||ce(`ssh_tunnel`))&&E({enabled:e.target.checked})},className:`size-4 accent-primary cursor-pointer`}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`connection.form.sshTunnelHint`)})]})}),b.enabled&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.sshHost`),htmlFor:`conn-ssh-host`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(L,{id:`conn-ssh-host`,placeholder:n(`connection.form.sshHostPlaceholder`),value:b.host,onChange:e=>E({host:e.target.value.trim()})}),(0,W.jsx)(L,{"aria-label":n(`connection.form.sshPort`),type:`number`,className:`w-24 shrink-0`,value:b.port,onChange:e=>E({port:Number(e.target.value)||22})})]})}),(0,W.jsx)(X,{label:n(`connection.form.sshUser`),htmlFor:`conn-ssh-user`,children:(0,W.jsx)(L,{id:`conn-ssh-user`,placeholder:n(`connection.form.sshUserPlaceholder`),value:b.user,onChange:e=>E({user:e.target.value.trim()})})}),(0,W.jsx)(X,{label:n(`connection.form.sshAuth`),children:(0,W.jsxs)(v,{value:b.auth,onValueChange:e=>E({auth:e}),children:[(0,W.jsx)(h,{className:`w-full`,children:(0,W.jsx)(m,{})}),(0,W.jsxs)(g,{children:[(0,W.jsx)(_,{value:`key`,children:n(`connection.form.sshAuthKey`)}),(0,W.jsx)(_,{value:`password`,children:n(`connection.form.sshAuthPassword`)}),(0,W.jsx)(_,{value:`agent`,children:n(`connection.form.sshAuthAgent`)})]})]})}),b.auth===`password`&&(0,W.jsx)(X,{label:n(`connection.form.sshPassword`),htmlFor:`conn-ssh-pass`,children:(0,W.jsx)(L,{id:`conn-ssh-pass`,type:`password`,autoComplete:`new-password`,value:b.password??``,onChange:e=>E({password:e.target.value})})}),b.auth===`key`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(X,{label:n(`connection.form.sshKey`),htmlFor:`conn-ssh-key`,children:(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`input`,{id:`conn-ssh-key`,type:`file`,className:`hidden`,onChange:e=>{D(e.target.files?.[0]),e.target.value=``}}),(0,W.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 shrink-0 px-2 text-xs`,onClick:()=>document.getElementById(`conn-ssh-key`)?.click(),children:b.privateKey?n(`connection.form.changeFile`):n(`connection.form.sshKeyPick`)}),(0,W.jsx)(`span`,{className:`min-w-0 truncate text-xs text-muted-foreground`,title:b.privateKeyName,children:b.privateKey?b.privateKeyName||n(`connection.form.sshKeyLoaded`):n(`connection.form.sshKeyHint`)})]})}),(0,W.jsx)(X,{label:n(`connection.form.sshPassphrase`),htmlFor:`conn-ssh-passphrase`,children:(0,W.jsx)(L,{id:`conn-ssh-passphrase`,type:`password`,autoComplete:`new-password`,placeholder:n(`connection.form.sshPassphrasePlaceholder`),value:b.passphrase??``,onChange:e=>E({passphrase:e.target.value})})})]}),b.auth===`agent`&&(0,W.jsx)(`p`,{className:`col-start-2 text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.sshAuthAgentHint`)}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.sshTargetHint`)}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:n(`connection.form.sshSecretsHint`)})]})]}),(0,W.jsx)(X,{label:n(`connection.form.autoConnection`),htmlFor:`conn-auto`,children:(0,W.jsx)(`div`,{className:`flex items-center`,children:(0,W.jsx)(`input`,{id:`conn-auto`,type:`checkbox`,checked:e.autoConnection,onChange:e=>r(`autoConnection`,e.target.checked),className:`size-4 accent-primary cursor-pointer`})})}),(0,W.jsx)(`div`,{className:`mt-1 border-t pt-3 text-xs font-medium text-muted-foreground`,children:n(`connection.form.safety`)}),(0,W.jsx)(X,{label:n(`connection.form.environment`),children:(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[A.map(t=>{let n=(e.environmentColor??`none`)===t.id;return(0,W.jsx)(`button`,{type:`button`,title:I(t.id),"aria-label":I(t.id),"aria-pressed":n,onClick:()=>r(`environmentColor`,t.id),className:`size-6 rounded-full border-2 transition-transform ${n?`scale-110 border-foreground`:`border-transparent hover:scale-105`}`,style:{background:t.id===`none`?`repeating-linear-gradient(45deg, transparent, transparent 3px, var(--muted-foreground) 3px, var(--muted-foreground) 4px)`:t.hex}},t.id)}),(0,W.jsx)(`span`,{className:`ml-1 text-xs text-muted-foreground`,children:n(`connection.form.environmentHint`)})]})}),(0,W.jsx)(X,{label:n(`connection.form.readOnly`),htmlFor:`conn-readonly`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{id:`conn-readonly`,type:`checkbox`,checked:e.readOnly??!1,onChange:e=>r(`readOnly`,e.target.checked),className:`size-4 accent-primary cursor-pointer`}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`connection.form.readOnlyHint`)})]})}),ee?.transactions!==!1&&(0,W.jsx)(X,{label:n(`connection.form.transactions`),children:(0,W.jsxs)(v,{value:e.transactionMode??`auto`,onValueChange:e=>r(`transactionMode`,e),children:[(0,W.jsx)(h,{className:`w-full`,children:(0,W.jsx)(m,{})}),(0,W.jsxs)(g,{children:[(0,W.jsx)(_,{value:`auto`,children:n(`connection.form.txAuto`)}),(0,W.jsx)(_,{value:`manual`,children:n(`connection.form.txManual`)})]})]})})]})}var Ze=[`id`,`serverConnectionId`,`sample`,`scratchpad`,`autoConnection`];function Qe(e){return!e.sample&&!e.scratchpad}function $e(e,t,n=new Date){let r=t?e:y(e),i={...r};for(let e of Ze)delete i[e];if(i.pass||delete i.pass,i.authToken||delete i.authToken,r.ssh){let e={...r.ssh};for(let t of[`password`,`passphrase`,`privateKey`])e[t]||delete e[t];i.ssh=e}return{planche:`connection`,version:1,exportedAt:n.toISOString(),secrets:t,connection:i}}function et(e){let t;try{t=JSON.parse(e)}catch{throw Error(`Not a JSON file`)}let n=t;if(!n||n.planche!==`connection`||!n.connection||typeof n.connection!=`object`)throw Error(`Not a Planche connection file`);if(typeof n.connection.dbms!=`string`||!n.connection.dbms)throw Error(`The connection has no database type`);return n}var Z=(e,t=``)=>typeof e==`string`?e:t,Q=e=>typeof e==`boolean`?e:void 0,tt=(e,t)=>typeof e==`number`&&Number.isFinite(e)?e:t,$=e=>e===void 0||e===``?void 0:e;function nt(e){if(!e||typeof e!=`object`)return;let t=e,n=t.auth===`key`||t.auth===`agent`?t.auth:`password`;return{enabled:t.enabled===!0,host:Z(t.host),port:tt(t.port,22),user:Z(t.user),auth:n,password:$(Z(t.password)),privateKey:$(Z(t.privateKey)),privateKeyName:$(Z(t.privateKeyName)),passphrase:$(Z(t.passphrase))}}function rt(e,t,n=crypto.randomUUID()){let r=e.connection,i=Q(r.savePassword),a={id:n,hostName:it(Z(r.hostName),t),host:Z(r.host),user:Z(r.user),pass:Z(r.pass),charset:Z(r.charset,`utf8`),port:tt(r.port,0),dbms:r.dbms,database:$(Z(r.database)),transport:r.transport===`tunnel`||r.transport===`browser`?r.transport:void 0,file:$(Z(r.file)),createIfMissing:Q(r.createIfMissing),ssl:Q(r.ssl),sslVerify:Q(r.sslVerify),accountId:$(Z(r.accountId)),databaseId:$(Z(r.databaseId)),devUrl:$(Z(r.devUrl)),ssh:nt(r.ssh),gatewayProfile:$(Z(r.gatewayProfile)),autoConnection:!1,savePassword:i??!0,authToken:Z(r.authToken),readOnly:Q(r.readOnly),environmentColor:$(Z(r.environmentColor)),transactionMode:$(Z(r.transactionMode))};for(let e of Object.keys(a))a[e]===void 0&&delete a[e];return a}function it(e,t){if(!e||!t.some(t=>t.hostName===e))return e;for(let n=2;;n++){let r=`${e} (${n})`;if(!t.some(e=>e.hostName===r))return r}}async function at(e,t,n=`application/json`){let r=Oe(e);if(typeof window.showSaveFilePicker==`function`)try{let e=await(await window.showSaveFilePicker({suggestedName:r,types:[{accept:{[n]:[`.${r.split(`.`).pop()??`txt`}`]}}]})).createWritable();return await e.write(t),await e.close(),!0}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return!1}let i=URL.createObjectURL(new Blob([t],{type:n})),a=document.createElement(`a`);return a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),!0}function ot(e=`.json,application/json`){return new Promise(t=>{let n=document.createElement(`input`);n.type=`file`,n.accept=e,n.onchange=async()=>{let e=n.files?.[0];t(e?await e.text():null)},n.oncancel=()=>t(null),n.click()})}function st({...e}){return(0,W.jsx)(ze,{"data-slot":`dropdown-menu`,...e})}function ct({...e}){return(0,W.jsx)(Be,{"data-slot":`dropdown-menu-trigger`,...e})}function lt({className:e,sideOffset:t=4,...n}){return(0,W.jsx)(Ve,{children:(0,W.jsx)(He,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:o(`z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...n})})}function ut({className:e,inset:t,variant:n=`default`,...r}){return(0,W.jsx)(Ue,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:o(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!`,e),...r})}function dt(){let{t:e}=a(),{activeDialog:t,closeDialog:i,showMessage:o}=n(),[s,c]=(0,U.useState)(!1),{savedConnections:u,addSavedConnection:d,updateSavedConnection:f,deleteSavedConnection:p,openConnection:m}=b(),h=r(`connect`)?.profileId,[g,_]=(0,U.useState)(()=>h??null),[v,y]=(0,U.useState)(()=>{let e=h?u.find(e=>e.id===h):void 0;return e?{...e}:null}),x=t===`connect`,[S,O]=(0,U.useState)(null),[k,A]=(0,U.useState)(null),se=be(e=>e.url),ce=be(e=>e.token);(0,U.useEffect)(()=>{if(!x)return;let e=!1;return(async()=>{try{let t=await w();if(e||t.state!==`online`||!t.gateway){e||O(null);return}let n=await T();e||(O({name:n.gateway,profiles:n.profiles}),A(null))}catch(t){e||A(t instanceof Error?t.message:String(t))}})(),()=>{e=!0}},[x,se,ce]);function M(t){let r=u.find(e=>e.gatewayProfile===t.name);if(r){P(r);return}let i=ye(t);d(i),P(i),n.getState().setFooterMessage(e(`connection.dialog.gatewayAdded`,{name:t.name}))}function N(e){e||(i(),_(null),y(null))}function P(e){_(e.id),y({...e})}function de(e){y(e),f(e.id,e)}function me(){let e=fe();d(e),_(e.id),y(e)}function I(){g&&(p(g),_(null),y(null))}async function L(t){let r=u.find(e=>e.id===g);if(!r||!Qe(r))return;let i=r.hostName||e(`connection.dialog.unnamed`),a=$e(b.getState().resolveCredentials(r),t);await at(`planche-connection-${i}.json`,JSON.stringify(a,null,2))&&n.getState().setFooterMessage(e(`connection.dialog.exported`,{name:i}))}async function R(){let t=await ot();if(t!==null)try{let r=rt(et(t),b.getState().savedConnections);d(r),_(r.id),y(r),n.getState().setFooterMessage(e(`connection.dialog.imported`,{name:r.hostName||e(`connection.dialog.unnamed`)}))}catch(t){o({tone:`error`,title:e(`connection.dialog.importFailedTitle`),description:t instanceof Error?t.message:String(t)})}}let ve=g!==null&&u.some(e=>e.id===g&&Qe(e)),[z,H]=(0,U.useState)(!1),Oe=ne(e=>e.addQueryTab);function G(t){let n=b.getState().activeConnections.some(e=>e.id===t.id);if(m(t),E.getState().removeTree(t.id),ee(t.id),n){i(),_(null),y(null);return}Oe(t.id,{id:`tab-${Date.now()}`,title:e(`connection.dialog.firstQueryTab`),query:``,database:``,isExecuting:!1,results:[],error:null,executionTime:null}),i(),_(null),y(null)}async function K(t){let r=await ae(t.id,{interactive:!0});if(!r)return;let i={...t,file:r.fileName,serverConnectionId:r.connectionId};f(t.id,{file:r.fileName}),G(i),b.getState().setFileDetached(t.id,r.fileDetached),r.restoredUnsaved?n.getState().setFooterMessage(e(r.diskChanged?`connection.dialog.restoredUnsavedDiskChanged`:`connection.dialog.restoredUnsaved`,{file:r.fileName})):r.wal&&!r.walApplied?n.getState().setFooterMessage(e(`connection.dialog.walPending`,{file:r.fileName})):r.walApplied&&n.getState().setFooterMessage(e(`connection.dialog.walApplied`,{file:r.fileName}))}async function q(t,r){try{return await r(t)}catch(i){let a=te(i);if(!a||!(`ssh`in t)||!t.ssh||!await n.getState().requestDestructiveConfirm({title:e(`connection.dialog.hostKeyTitle`),description:e(`connection.dialog.hostKeyDescription`,a),confirmLabel:e(`connection.dialog.hostKeyAccept`)}))throw i;return r({...t,ssh:{...t.ssh,acceptHostKey:a.fingerprint}})}}async function J(){if(v){H(!0);try{if(D(v)===`browser`){await K(v);return}let t=await q(C(v),e=>ie(e,v.authToken||void 0));t.success?G({...v,serverConnectionId:t.connectionId}):o({tone:`error`,title:e(`connection.dialog.connectFailedTitle`),description:t.message??e(`connection.dialog.unknownError`)})}catch(t){o({tone:`error`,title:e(`connection.dialog.connectFailedTitle`),description:t instanceof Error?t.message:String(t)})}finally{H(!1)}}}async function ke(){if(v){if(D(v)===`browser`){o({tone:`info`,title:e(`connection.dialog.testConnection`),description:e(`connection.dialog.browserTestHint`)});return}c(!0);try{let t=await q(C(v),e=>re(e,v.authToken||void 0));t.success?o({tone:`success`,title:e(`connection.dialog.testSuccess`),description:e(`connection.dialog.testSuccessDescription`)}):o({tone:`error`,title:e(`connection.dialog.testFailedTitle`),description:t.message??e(`connection.dialog.unknownError`)})}catch(t){o({tone:`error`,title:e(`connection.dialog.testFailedTitle`),description:t instanceof Error?t.message:String(t)})}finally{c(!1)}}}return(0,W.jsx)(De,{open:x,onOpenChange:N,children:(0,W.jsxs)(Te,{className:`sm:max-w-[1100px] h-[85vh] max-h-[85vh] flex flex-col`,children:[(0,W.jsx)(Ce,{children:(0,W.jsx)(Ee,{children:e(`connection.dialog.title`)})}),(0,W.jsxs)(`p`,{className:`flex items-start gap-2 rounded-md border border-catppuccin-green/40 bg-catppuccin-green/10 px-3 py-2 text-xs leading-relaxed text-foreground`,children:[(0,W.jsx)(pe,{className:`mt-0.5 size-4 shrink-0 text-catppuccin-green`,"aria-hidden":!0}),(0,W.jsx)(`span`,{children:e(`connection.dialog.privacy`)})]}),(0,W.jsxs)(`div`,{className:`flex flex-1 gap-4 overflow-hidden min-h-0`,children:[(0,W.jsxs)(`div`,{className:`w-[460px] shrink-0 border rounded-md overflow-hidden flex flex-col`,children:[(S||k)&&(0,W.jsxs)(`div`,{className:`border-b p-2 text-xs space-y-1 max-h-40 overflow-auto`,children:[(0,W.jsxs)(`p`,{className:`font-medium`,children:[e(`connection.dialog.gatewayTitle`),S?` — ${S.name}`:``]}),k&&(0,W.jsx)(`p`,{className:`text-destructive`,children:e(`connection.dialog.gatewayLoadFailed`,{error:k})}),S?.profiles.map(t=>(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5 truncate`,children:[(0,W.jsx)(B,{dbms:_e[t.driver],className:`size-3.5`}),(0,W.jsx)(`span`,{className:`truncate`,children:t.name}),(0,W.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,t.readOnly?e(`connection.dialog.gatewayReadOnly`):e(`connection.dialog.gatewayWritable`),`)`]})]}),(0,W.jsx)(l,{size:`sm`,variant:`outline`,className:`h-6 px-2 text-xs`,onClick:()=>M(t),children:e(`connection.dialog.gatewayAdd`)})]},t.name))]}),(0,W.jsx)(ge,{className:`h-full`,children:(0,W.jsxs)(xe,{className:`table-fixed`,children:[(0,W.jsx)(ue,{children:(0,W.jsxs)(j,{children:[(0,W.jsx)(V,{className:`w-[32%]`,children:e(`connection.dialog.colHostName`)}),(0,W.jsx)(V,{className:`w-[40%]`,children:e(`connection.dialog.colTarget`)}),(0,W.jsx)(V,{className:`w-[28%]`,children:e(`connection.dialog.colDbms`)})]})}),(0,W.jsx)(Se,{children:u.length===0?(0,W.jsx)(j,{children:(0,W.jsx)(F,{colSpan:3,className:`text-center text-muted-foreground`,children:e(`connection.dialog.noSaved`)})}):u.map(t=>(0,W.jsxs)(j,{"data-state":g===t.id?`selected`:void 0,className:`cursor-pointer`,onClick:()=>P(t),onDoubleClick:()=>{P(t),J()},children:[(0,W.jsx)(F,{className:`truncate font-medium`,title:t.hostName,children:t.hostName||e(`connection.dialog.unnamed`)}),(0,W.jsx)(F,{className:`truncate`,title:t.dbms===`sqlite`?t.file:t.dbms===`d1`?t.databaseId:t.dbms===`do`?t.devUrl:`${t.user}@${t.host}:${t.port}`,children:t.dbms===`sqlite`?t.file||(D(t)===`browser`?e(`connection.dialog.pickOnConnect`):e(`connection.dialog.noFile`)):t.dbms===`d1`?t.databaseId||`—`:t.dbms===`do`?t.devUrl||`—`:`${t.user}@${t.host}:${t.port}`}),(0,W.jsx)(F,{className:`truncate`,title:oe(t.dbms).label,children:(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(B,{dbms:t.dbms,className:`size-3.5`}),(0,W.jsx)(`span`,{className:`truncate`,children:oe(t.dbms).label})]})})]},t.id))})]})})]}),(0,W.jsx)(`div`,{className:`flex-1 border rounded-md overflow-auto`,children:v?(0,W.jsxs)(W.Fragment,{children:[D(v)!==`browser`&&(0,W.jsx)(`div`,{className:`p-4 pb-0`,children:(0,W.jsx)(he,{})}),v.gatewayProfile?(0,W.jsxs)(`div`,{className:`p-4 space-y-2 text-sm`,children:[(0,W.jsxs)(`p`,{className:`font-medium flex items-center gap-2`,children:[(0,W.jsx)(B,{dbms:v.dbms,className:`size-4`}),v.hostName]}),(0,W.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connection.dialog.gatewayProfileHint`,{name:v.gatewayProfile})}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[v.readOnly?e(`connection.dialog.gatewayReadOnly`):e(`connection.dialog.gatewayWritable`),v.database?` · ${v.database}`:``]})]}):(0,W.jsx)(Xe,{value:v,onChange:de})]}):(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:e(`connection.dialog.selectPrompt`)})})]}),(0,W.jsxs)(we,{className:`sm:justify-between`,children:[(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(l,{variant:`outline`,onClick:me,children:e(`connection.dialog.addNew`)}),(0,W.jsx)(l,{variant:`destructive`,onClick:I,disabled:!g,children:e(`connection.dialog.delete`)}),(0,W.jsxs)(st,{children:[(0,W.jsx)(ct,{asChild:!0,children:(0,W.jsxs)(l,{variant:`outline`,disabled:!ve,children:[e(`connection.dialog.export`),(0,W.jsx)(le,{className:`ml-1 size-3.5`,"aria-hidden":!0})]})}),(0,W.jsxs)(lt,{align:`start`,children:[(0,W.jsx)(ut,{onSelect:()=>void L(!1),children:e(`connection.dialog.exportWithoutSecrets`)}),(0,W.jsx)(ut,{onSelect:()=>void L(!0),children:e(`connection.dialog.exportWithSecrets`)})]})]}),(0,W.jsx)(l,{variant:`outline`,onClick:()=>void R(),children:e(`connection.dialog.import`)})]}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(l,{variant:`outline`,onClick:ke,disabled:!v||s,children:e(`connection.dialog.testConnection`)}),(0,W.jsx)(l,{onClick:J,disabled:!v||z,children:e(`connection.dialog.connect`)}),(0,W.jsx)(l,{variant:`outline`,onClick:()=>N(!1),children:e(`connection.dialog.close`)})]})]})]})})}export{dt as ConnectDialog};