"use strict";(self.webpackChunkCompassShellPlugin=self.webpackChunkCompassShellPlugin||[]).push([[945],{49945:(e,t,o)=>{o.r(t),o.d(t,{CompassShell:()=>q,default:()=>z});var i=o(99497),n=o.n(i),s=o(13980),r=o.n(s),l=o(86993),a=o(39662),c=o(30709);const h=[{key:"Ctrl+`",description:"Toggle shell."},{key:"Ctrl+A",description:"Moves the cursor to the beginning of the line."},{key:"Ctrl+B",description:"Moves the cursor Backward one character."},{key:"Ctrl+C",description:"Stop currently running command."},{key:"Ctrl+D",description:"Deletes the next character."},{key:"Ctrl+E",description:"Moves the cursor to the end of the line."},{key:"Ctrl+F",description:"Moves the cursor Forward one character."},{key:"Ctrl+H",description:"Erases one character, similar to hitting backspace."},{key:"meta+L",description:"Clears the screen, similar to the clear command."},{key:"Ctrl+T",description:"Swap the last two characters before the cursor."},{key:"Ctrl+U",description:"Changes the line to Uppercase."},{key:"ArrowUp",description:"Cycle backwards through command history."},{key:"ArrowDown",description:"Cycle forwards through command history."}];function p(){return n().createElement(c.Table,{data:h,columns:[n().createElement(c.TableHeader,{key:"name",label:"Key"}),n().createElement(c.TableHeader,{key:"value",label:"Description"})]},(e=>{let{datum:t}=e;return n().createElement(c.Row,{key:t.key},n().createElement(c.Cell,null,n().createElement(c.Body,{weight:"medium"},n().createElement(c.KeyboardShortcut,{hotkey:t.key}))),n().createElement(c.Cell,null,n().createElement(c.Description,null,t.description)))}))}const d=`v${o(74841).i8}`,u=(0,c.css)({marginTop:c.spacing[2],maxHeight:"50vh",overflow:"auto"}),m=(0,c.css)({marginTop:c.spacing[4]});function g(e){let{hideInfoModal:t,show:o}=e;const s=(0,i.useCallback)((()=>{t()}),[t]);return n().createElement(c.InfoModal,{open:o,title:`mongosh ${d}`,trackingId:"shell_info_modal","data-testid":"shell-info-modal",onClose:s},n().createElement(c.Banner,null,"For more information please visit the ",n().createElement(c.Link,{id:"mongosh-info-link",href:"https://docs.mongodb.com/compass/beta/embedded-shell/",target:"_blank"},"MongoDB Shell Documentation"),"."),n().createElement(c.Subtitle,{className:m},"Keyboard Shortcuts"),n().createElement("div",{className:u},n().createElement(p,null)))}g.propTypes={hideInfoModal:r().func.isRequired,show:r().bool.isRequired};const y=g,f=(0,c.css)({height:c.spacing[5],display:"flex",color:c.palette.gray.light1}),b=(0,c.css)({borderTop:`1px solid ${c.palette.gray.dark2}`}),S=(0,c.css)({flexGrow:1,display:"flex",alignItems:"center"}),k=c.palette.gray.light1,E=c.palette.gray.base,C=c.palette.gray.light2,w=c.keyframes`
  0% { color: ${k}; }
  10% { color: ${E}; }
  20% { color: ${C}; }
  30% { color: ${E}; }
  40% { color: ${C}; }
  50% { color: ${E}; }
  60% { color: ${C}; }
  70% { color: ${E}; }
  80% { color: ${C}; }
  100% { color: ${k}; }
`,v=(0,c.css)({background:"none",border:"none",cursor:"pointer",color:k,padding:`0px ${c.spacing[2]}px`,height:"100%",display:"flex",verticalAlign:"middle",flexDirection:"row",alignItems:"center",margin:"auto 0",fontWeight:"bold",fontSize:1.5*c.spacing[2],lineHeight:`${c.spacing[5]}px`,transition:"all 200ms",userSelect:"none",textTransform:"uppercase",animation:`${w} 2s linear`,"&:hover":{color:c.palette.gray.light3}}),O=(0,c.css)({display:"flex",paddingTop:c.spacing[1]/2,paddingRight:c.spacing[2]}),x=(0,c.css)({marginRight:c.spacing[2]}),I=(0,c.css)({color:c.palette.green.light2,marginLeft:c.spacing[2]}),H=(0,c.css)({borderTopColor:c.palette.green.light2}),M=e=>{let{darkMode:t,isExpanded:o,isOperationInProgress:i,onShellToggleClicked:s,showInfoModal:r}=e;return(0,c.useHotkeys)("ctrl + `",s),n().createElement("div",{className:(0,c.cx)(f,t&&b)},n().createElement("div",{className:S},n().createElement("button",{type:"button","data-testid":"shell-expand-button",className:v,"aria-label":o?"Close Shell":"Open Shell",onClick:s,"aria-pressed":o},">_MONGOSH",!o&&i&&n().createElement("span",{className:I},n().createElement(c.SpinLoader,{size:"12px",className:H})," Command in progress…"))),n().createElement("div",{className:O},o&&n().createElement(c.IconButton,{"data-testid":"shell-info-button",className:x,variant:"dark","aria-label":"Shell Info","aria-haspopup":"dialog",onClick:r},n().createElement(c.Icon,{glyph:"InfoWithCircle",size:"small"})),n().createElement(c.IconButton,{variant:"dark","aria-label":o?"Close Shell":"Open Shell",onClick:s,"aria-pressed":o},n().createElement(c.Icon,{glyph:o?"ChevronDown":"ChevronUp",size:"small"}))))};M.propTypes={darkMode:r().bool,isExpanded:r().bool.isRequired,isOperationInProgress:r().bool.isRequired,onShellToggleClicked:r().func.isRequired,showInfoModal:r().func.isRequired};const R=(0,c.withDarkMode)(M),{Shell:T}=o(72519),$=(0,c.css)({backgroundColor:c.palette.gray.dark4,display:"flex",flexBasis:"auto",position:"relative",flexDirection:"column",width:"100vw"},(0,c.getScrollbarStyles)(!0)),P=(0,c.css)({flexGrow:1,display:"none",overflow:"auto",borderTop:`1px solid ${c.palette.gray.dark2}`}),D=(0,c.css)({display:"flex"}),N=100;function B(){return Math.max(240,window.innerHeight-100)}class q extends i.Component{static propTypes={emitShellPluginOpened:r().func,runtime:r().object,shellOutput:r().array,historyStorage:r().object,enableShell:r().bool};static defaultProps={emitShellPluginOpened:()=>{},runtime:null};constructor(e){super(e),this.shellRef=n().createRef(),this.shellOutput=this.props.shellOutput||[],this.state={height:32,prevHeight:240,initialHistory:this.props.historyStorage?null:[],isOperationInProgress:!1,showInfoModal:!1}}componentDidMount(){this.loadHistory(),window.addEventListener("beforeunload",this.terminateRuntime)}componentDidUpdate(e,t){const{height:o}=this.state;t.height<N&&o>N&&this.props.emitShellPluginOpened()}componentWillUnmount(){window.removeEventListener("beforeunload",this.terminateRuntime)}onShellOutputChanged=e=>{this.shellOutput=e};onOperationStarted=()=>{this.setState({isOperationInProgress:!0})};onOperationEnd=()=>{this.setState({isOperationInProgress:!1})};terminateRuntime=()=>{this.props.runtime&&this.props.runtime.terminate()};saveHistory=async e=>{if(this.props.historyStorage)try{await this.props.historyStorage.save(e)}catch(e){console.error(e)}};loadHistory=async()=>{if(this.props.historyStorage)try{const e=await this.props.historyStorage.load();this.setState({initialHistory:e})}catch(e){console.error(e),this.setState({initialHistory:[]})}};updateHeight(e){this.setState(e>N?{height:e,prevHeight:e}:{height:e})}hideInfoModal(){this.setState({showInfoModal:!1})}focusEditor(){this.shellRef.current&&"Range"!==window.getSelection()?.type&&this.shellRef.current.focusEditor()}render(){const{height:e,prevHeight:t,isOperationInProgress:o,showInfoModal:s}=this.state;if(!this.props.enableShell||!this.props.runtime||!this.state.initialHistory)return n().createElement("div",null);const r=e>N,l=r?function(e){const t=B();return Math.min(t,Math.max(N,e))}(e):32;return n().createElement(i.Fragment,null,n().createElement(y,{show:s,hideInfoModal:this.hideInfoModal.bind(this)}),n().createElement("div",{"data-testid":"shell-section",className:$,style:{height:l},id:"content",onClick:this.focusEditor.bind(this)},n().createElement(c.ResizeHandle,{direction:c.ResizeDirection.TOP,onChange:e=>this.updateHeight(e),value:e,minValue:32,maxValue:B(),title:"MongoDB Shell"}),n().createElement(R,{isExpanded:r,onShellToggleClicked:()=>r?this.updateHeight(32):this.updateHeight(t),isOperationInProgress:o,showInfoModal:()=>this.setState({showInfoModal:!0})}),n().createElement("div",{"data-testid":"shell-content",className:(0,c.cx)(P,r&&D)},n().createElement(T,{ref:this.shellRef,runtime:this.props.runtime,initialHistory:this.state.initialHistory,initialOutput:this.shellOutput,onHistoryChanged:this.saveHistory,onOutputChanged:this.onShellOutputChanged,onOperationStarted:this.onOperationStarted,onOperationEnd:this.onOperationEnd}))))}}const z=(0,l.$j)((e=>({emitShellPluginOpened:()=>{e.appRegistry&&e.appRegistry.globalAppRegistry&&e.appRegistry.globalAppRegistry.emit("compass:compass-shell:opened")},runtime:e.runtime?e.runtime.runtime:null})))((0,a.withPreferences)(q,["enableShell"],n()))}}]);