import{E as Q,z as B,A as U,B as V,j as i,R as $}from"./cm-1.0.63-CSIRHMXC.js";import{r as E,R as J}from"./redux-1.0.63-Df-eBzJn.js";import{E as X,F as Y,G as Z,H as _,M as A}from"./index-1.0.63-oIDff4nA.js";import{l as I}from"./lib-1.0.63-DJZPtMem.js";import{c as ee}from"./cmJs-1.0.63-CzmnAR2E.js";import{j as re}from"./cmJson-1.0.63-CyZ2MfFg.js";import{h as te}from"./cmHtml-1.0.63-BoYNtd6o.js";import{s as ne,M as H}from"./cmSql-1.0.63-OKh4Zrzn.js";import{B as v}from"./Spinner-1.0.63-zcgIyS7Z.js";import{F as oe}from"./FormControlLabel-1.0.63-DpYUdUm6.js";import{S as ie}from"./Switch-1.0.63-m0NqOO9s.js";import{I as N}from"./iconBase-1.0.63-CFvHhC4t.js";import{D as ae,a as se,b as le}from"./DialogContent-1.0.63-B3W-DlSe.js";import{D as fe}from"./ConfirmDialog-1.0.63-eXgm3P8b.js";import{B as S}from"./cjs-1.0.63-4A2xol4v.js";import"./vendor-1.0.63-CN03Eozo.js";import"./Typography-1.0.63-mecuj_Wl.js";import"./ButtonBase-1.0.63-CF10PFMS.js";import"./useEnhancedEffect-1.0.63-DnR0ZFqV.js";import"./ThemeProvider-1.0.63-Cq0KMgkh.js";import"./Modal-1.0.63-fMXTbfks.js";import"./notistack-1.0.63-B49ULGrj.js";import"./loglevel-1.0.63-BZ7XahX3.js";import"./lodash-1.0.63-hMxolcpJ.js";import"./moment-1.0.63-C5S46NFB.js";import"./rehyperaw-1.0.63-AkovKNCK.js";import"./markdown-1.0.63-BJvkzZkj.js";import"./Select-1.0.63-BMejr8a7.js";import"./Menu-1.0.63-DLh4HkF0.js";import"./createSvgIcon-1.0.63-DWL3J-DK.js";import"./SwitchBase-1.0.63-Br-lbcZ1.js";import"./AdminTheme-1.0.63-DhJ0rrw5.js";/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var T=function(){return T=Object.assign||function(o){for(var e,n=1,a=arguments.length;n<a;n++)for(var t in e=arguments[n])Object.prototype.hasOwnProperty.call(e,t)&&(o[t]=e[t]);return o},T.apply(this,arguments)};function F(o,e,n){if(n||arguments.length===2)for(var a,t=0,l=e.length;t<l;t++)!a&&t in e||(a||(a=Array.prototype.slice.call(e,0,t)),a[t]=e[t]);return o.concat(a||Array.prototype.slice.call(e))}var c=function(o){return/^-?\d+$/.test(o)},O=function(o,e,n){n===void 0&&(n={from:void 0,to:void 0});var a=o.map(function(r){if(r.from=c(r.from)?r.from:void 0,r.to=c(r.to)?r.to:void 0,c(r.from)&&c(r.to)){var d=T({},r);r.from=Math.min(d.from,d.to),r.to=Math.max(d.from,d.to)}return r}),t={from:c(e==null?void 0:e.from)?e==null?void 0:e.from:void 0,to:c(e==null?void 0:e.to)?e==null?void 0:e.to:void 0};if(c(t.from)&&c(t.to)){var l=T({},t);t.from=Math.min(l.from,l.to),t.to=Math.max(l.from,l.to)}var s={from:c(n==null?void 0:n.from)?n==null?void 0:n.from:void 0,to:c(n==null?void 0:n.to)?n==null?void 0:n.to:void 0};if(c(s.from)&&c(s.to)){var u=T({},s);s.from=Math.min(u.from,u.to),s.to=Math.max(u.from,u.to)}var f=F(F([],a.map(function(r){return r.from}),!0),[t==null?void 0:t.from,s==null?void 0:s.from],!1).filter(function(r){return r!==void 0}),h=F(F([],a.map(function(r){return r.to}),!0),[t==null?void 0:t.to,s==null?void 0:s.to],!1).filter(function(r){return r!==void 0}),m=F(F([],f,!0),h,!0),b=0,p=0;m.length>0&&(b=Math.max.apply(Math,m),p=Math.min.apply(Math,m));var C=Math.abs(b),k=Math.abs(p),g=Math.max(C,k)+1,y=-g;return a=a.map(function(r){return r.from=c(r.from)?r.from:y,r.to=c(r.to)?r.to:g,r}),t={from:c(t.from)?t.from:y,to:c(t.to)?t.to:g},s={from:c(s.from)?s.from:y,to:c(s.to)?s.to:g},a=a.slice().sort(function(r,d){var M=r.to-r.from,j=d.to-d.from;if(r.from>d.from)return 1;if(r.from===d.from){if(r.from+M>d.from+j)return-1;if(r.from+M===d.from+j)return 0;if(r.from+M<d.from+j)return 1}return-1}),P(a,t,[],s).map(function(r){return{from:r.from===y?void 0:r.from,to:r.to===g?void 0:r.to}})},P=function(o,e,n,a){var t=n;if(e===null||o.length===0)return e===null||n.some(function(f){return f.from===(e==null?void 0:e.from)&&f.to===(e==null?void 0:e.to)})||t.push(e),(t=t.filter(function(f){return f.from<=a.to&&f.to>=a.from})).map(function(f){return function(h,m){return{from:h.from<m.from?m.from:h.from,to:h.to>m.to?m.to:h.to}}(f,a)});var l=e.to-e.from;if(e.from>=o[0].from&&e.from<=o[0].to)e.from+l<=o[0].to?e=null:e.from=o[0].to+1;else if(e.from<o[0].from&&e.from+l>=o[0].from){var s=e.to,u={from:e.from,to:o[0].from-1};n.push(u),s>o[0].to?e.from=o[0].to+1:e=null}return o.shift(),P(o,e,n,a)},de=function(o){return U.transactionFilter.of(function(e){if(e.isUserEvent("delete.selection")&&!e.isUserEvent("delete.selection.smart")){var n=e.startState.selection.ranges.map(function(t){return{from:t.from,to:t.to}});if(n.length>0){var a=o(e.startState);return O(a,n[0],{from:0,to:e.startState.doc.line(e.startState.doc.lines).to}).map(function(t){return e.startState.update({changes:{from:t.from,to:t.to},annotations:B.userEvent.of("".concat(e.annotation(B.userEvent),".smart"))})})}}return e})},ue=function(o){return U.changeFilter.of(function(e){var n,a,t,l;try{for(var s=o(e.startState),u=o(e.state),f=0;f<s.length;f++){var h=(n=s[f].from)!==null&&n!==void 0?n:0,m=(a=s[f].to)!==null&&a!==void 0?a:e.startState.doc.line(e.startState.doc.lines).to,b=(t=u[f].from)!==null&&t!==void 0?t:0,p=(l=u[f].to)!==null&&l!==void 0?l:e.state.doc.line(e.state.doc.lines).to;if(e.startState.sliceDoc(h,m)!==e.state.sliceDoc(b,p))return!1}}catch{return!1}return!0})},me=function(o){return Q.domEventHandlers({paste:function(e,n){var a=(e.clipboardData||window.clipboardData).getData("Text"),t=n.state.selection.ranges.map(function(u){return{from:u.from,to:u.to}});if(t.length>0){var l=o(n.state),s=O(l,t[0],{from:0,to:n.state.doc.line(n.state.doc.lines).to});s.length>0&&n.dispatch({changes:{from:s[0].from,to:s[0].to,insert:a},annotations:B.userEvent.of("input.paste.smart")})}return!0}})},z=function(o){return[me(o),de(o),ue(o)]};const K=({code:o,codeBefore:e="",codeAfter:n="",setCode:a,doPaste:t=!1,pasteValue:l=null,extension:s="js",isReadOnly:u=!1,initialHeight:f="200px",sqlSchema:h=void 0,saveCode:m=void 0,setFullScreen:b,fullScreen:p})=>{const C=E.useRef({});let k="",g="";try{k=localStorage.getItem("ppCodeEditorTheme"),g=localStorage.getItem("ppCodeEditorLineNumbers")}catch(x){I.debug(x)}const[y,r]=E.useState(!0),[d,M]=E.useState(g==="true"),[j,D]=E.useState(k==="dark"?"dark":"light");E.useEffect(()=>{var x,w;if(l!==null&&((x=C.current)==null?void 0:x.view)!==void 0){const R=C.current.view.state.selection.main.head;I.debug("cursorPosition",R),a(o.substring(0,R)+l+o.substring(R)),(w=C.current)==null||w.view.focus()}},[l,t]);const L=x=>{const w=[];return e!==""&&w.push({from:void 0,to:x.doc.line(1).to}),n!==""&&w.push({from:x.doc.line(x.doc.lines).from,to:void 0}),I.debug(w),w},G=J.useCallback(()=>(m&&m(),!0),[]),W=V.of([{key:"ctrl-s",run:G}]),q=()=>{switch(s){case"js":return[ee(),z(L)];case"sql":return[h!==void 0?ne({dialect:H,schema:h}):H,W];case"json":return[re(),z(L)];case"html":return[te(),z(L)]}};return i.jsxs(v,{sx:{fontSize:"14px",margin:"1px",borderRadius:"4px",boxShadow:y?"rgba(0, 0, 0, 1) 0px 0px 0px 1px, rgba(0, 0, 0, 1) 0px 0px 0px, rgba(0, 0, 0, 1) 0px 1px 1px":"rgba(0, 0, 0, 0.1) 0px 0px 0px 1px, rgba(0, 0, 0, 0) 0px 0px 0px, rgba(0, 0, 0, 0.3) 0px 1px 1px",overflow:"auto",...!p&&{"& .cm-editor":{resize:"vertical",overflow:"auto !important"}},"& .cm-editor.cm-focused":{outline:"none"},...u&&{"& .cm-editor":{opacity:"0.6"}}},children:[i.jsxs(v,{sx:{borderBottom:"1px solid #ddd",display:"grid",gridTemplateColumns:"1fr 1fr 1fr",justifyContent:"space-between",alignItems:"center",fontSize:"11px"},children:[i.jsx(v,{children:i.jsx(oe,{className:"pp-line-numbers unselectable",control:i.jsx(ie,{checked:d,size:"small",disableRipple:!0,onChange:x=>{try{localStorage.setItem("ppCodeEditorLineNumbers",String(!d))}catch(w){I.debug(w)}M(!d),x.stopPropagation()},sx:{"& :hover":{backgroundColor:"unset"}}}),label:"line numbers",labelPlacement:"end",sx:{marginLeft:"1px","& span.MuiFormControlLabel-label":{fontSize:"11px"},"&.pp-line-numbers .MuiSwitch-switchBase":{padding:"4px !important"}}})}),i.jsxs(v,{sx:{display:"flex",justifyContent:"center",alignItems:"center",fontSize:"11px"},children:[i.jsx(N,{size:"small",color:"primary",disableRipple:!0,onClick:()=>{b(!p)},sx:{marginLeft:"-8px"},children:p?i.jsx(X,{}):i.jsx(Y,{})}),i.jsx(v,{className:"unselectable",sx:{display:"inline-block",cursor:"pointer"},onClick:()=>{b(!p)},children:"full-screen editor"})]}),i.jsxs(v,{sx:{display:"flex",justifyContent:"end",alignContent:"center"},children:[i.jsxs(v,{className:"unselectable",sx:{display:"flex",alignSelf:"center",cursor:"pointer"},onClick:()=>{if(j==="light"){try{localStorage.setItem("ppCodeEditorTheme","dark")}catch(x){I.debug(x)}D("dark")}else{try{localStorage.setItem("ppCodeEditorTheme","light")}catch(x){I.debug(x)}D("light")}},children:[j," mode"]}),i.jsx(N,{size:"small",color:"primary",disableRipple:!0,onClick:()=>{D(j==="light"?"dark":"light")},children:j==="dark"?i.jsx(Z,{}):i.jsx(_,{})})]})]}),i.jsx($,{ref:C,value:e+o+n,onChange:x=>{a(x.substring(e.length,x.length-n.length))},onFocus:()=>{r(!0)},onBlur:()=>{r(!1)},extensions:q(),autoFocus:!0,height:p?s==="sql"?"calc(calc(var(--ppViewHeight, 1vh) * 100) - 260px)":"calc(calc(var(--ppViewHeight, 1vh) * 100) - 300px)":f,theme:j,basicSetup:{lineNumbers:d,foldGutter:!1},readOnly:u})]})},ce=({code:o,codeBefore:e="",codeAfter:n="",setCode:a,doPaste:t=!1,pasteValue:l=null,dialogTitle:s,buttonApply:u,buttonDelete:f,buttonOk:h,buttonCancel:m,buttonEditorOk:b,extension:p="js",isReadOnly:C=!1,initialHeight:k="200px",sqlSchema:g=void 0,saveCode:y=void 0,setFullScreen:r,fullScreen:d})=>i.jsxs(ae,{open:!0,"aria-labelledby":"code-dialog",sx:{"& .MuiPaper-root":{width:"calc(100vw - 100px)",maxWidth:"calc(100vw - 100px)",height:"calc(calc(var(--ppViewHeight, 1vh) * 100) - 100px)",maxHeight:"calc(calc(var(--ppViewHeight, 1vh) * 100) - 100px)",margin:"50px"},"& .MuiBackdrop-root.MuiModal-backdrop":{backgroundColor:"rgba(0, 0, 0, 0.7)"}},children:[i.jsxs(fe,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",alignItems:"center"},children:[i.jsx(v,{sx:{marginLeft:"10px"},children:"Code Editor"}),i.jsx(v,{sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:s}),i.jsx(v,{sx:{display:"flex",justifyContent:"end",alignItems:"center"},children:i.jsx(N,{onClick:()=>{r(!1)},children:i.jsx(A,{})})})]}),i.jsx(se,{sx:{padding:"20px"},children:i.jsx(K,{code:o,codeBefore:e,codeAfter:n,setCode:a,doPaste:t,pasteValue:l,extension:p,isReadOnly:C,initialHeight:k,sqlSchema:g,saveCode:y,setFullScreen:r,fullScreen:d})}),i.jsxs(le,{sx:{padding:"0 20px 20px 20px",display:"grid",gridTemplateColumns:"auto auto",justifyContent:"space-between",alignItems:"center"},children:[i.jsx(v,{sx:{display:"flex",alignItems:"center",fontWeight:"bold"},children:p.toUpperCase()}),u!==void 0&&h!==void 0&&m!==void 0&&i.jsxs(v,{sx:{display:"grid",gridTemplateColumns:"100px 100px 100px",justifyContent:"end",alignItems:"center",gap:"20px"},children:[i.jsx(S,{variant:"outlined",onClick:()=>{u()},children:"Update"}),i.jsx(S,{variant:"contained",onClick:()=>{h()},children:"OK"}),i.jsx(S,{variant:"contained",onClick:()=>{m()},children:"Cancel"})]}),u!==void 0&&f!==void 0&&b!==void 0&&i.jsxs(v,{sx:{display:"grid",gridTemplateColumns:"100px 100px 100px 100px",justifyContent:"end",alignItems:"center",gap:"10px"},children:[i.jsx(S,{variant:"outlined",onClick:()=>{u()},children:"Update"}),i.jsx(S,{variant:"outlined",onClick:()=>{f()},children:"Delete"}),i.jsx(S,{variant:"contained",onClick:()=>{b(),r(!1)},children:"OK"}),i.jsx(S,{variant:"contained",onClick:()=>{r(!1)},children:"Cancel"})]})]})]}),Ve=({code:o,codeBefore:e="",codeAfter:n="",setCode:a,doPaste:t=!1,pasteValue:l=null,dialogTitle:s,buttonApply:u,buttonDelete:f,buttonOk:h,buttonCancel:m,buttonEditorOk:b,extension:p="js",isReadOnly:C=!1,initialHeight:k="200px",sqlSchema:g=void 0,saveCode:y=void 0,setFullScreenExternally:r,fullScreenExternally:d=void 0})=>{I.debug(o,e,n,t,l,s,p);const[M,j]=E.useState(!1);return E.useEffect(()=>{d!==void 0&&j(d)},[d]),E.useEffect(()=>{r&&r(M)},[M]),i.jsx(i.Fragment,{children:M?i.jsx(ce,{code:o,codeBefore:e,codeAfter:n,setCode:a,doPaste:t,pasteValue:l,dialogTitle:s,buttonApply:u,buttonDelete:f,buttonOk:h,buttonCancel:m,buttonEditorOk:b,extension:p,isReadOnly:C,initialHeight:k,sqlSchema:g,saveCode:y,setFullScreen:j,fullScreen:M}):i.jsx(K,{code:o,codeBefore:e,codeAfter:n,setCode:a,doPaste:t,pasteValue:l,extension:p,isReadOnly:C,initialHeight:k,sqlSchema:g,saveCode:y,setFullScreen:j,fullScreen:M})})};export{Ve as default};
