"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),l=o.n(s),r=o(86993),a=o(39662),c=o(30709);const h=(0,c.css)({td:{padding:0}}),d=[{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:"Ctrl/Cmd+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:"↑",description:"Cycle backwards through command history."},{key:"↓",description:"Cycle forwards through command history."}];function p(){return n().createElement(c.Table,{data:d,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,{className:h,key:t.key},n().createElement(c.Cell,null,n().createElement(c.Body,{weight:"medium"},t.key)),n().createElement(c.Cell,null,n().createElement(c.Description,null,t.description)))}))}const m=`v${o(74841).i8}`,g=(0,c.css)({marginTop:c.spacing[2],maxHeight:"50vh",overflow:"auto"}),u=(0,c.css)({marginTop:c.spacing[4]});function y(e){let{hideInfoModal:t,show:o}=e;const s=(0,i.useCallback)((()=>{t()}),[t]);return n().createElement(c.InfoModal,{open:o,title:`mongosh ${m}`,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:u},"Keyboard Shortcuts"),n().createElement("div",{className:g},n().createElement(p,null)))}y.propTypes={hideInfoModal:l().func.isRequired,show:l().bool.isRequired};const f=y,b=(0,c.css)({height:c.spacing[5],display:"flex",color:c.palette.gray.light1}),k=(0,c.css)({borderTop:`1px solid ${c.palette.gray.dark2}`}),S=(0,c.css)({flexGrow:1,display:"flex",alignItems:"center"}),C=c.palette.gray.light1,E=c.palette.gray.base,w=c.palette.gray.light2,v=c.keyframes`
  0% { color: ${C}; }
  10% { color: ${E}; }
  20% { color: ${w}; }
  30% { color: ${E}; }
  40% { color: ${w}; }
  50% { color: ${E}; }
  60% { color: ${w}; }
  70% { color: ${E}; }
  80% { color: ${w}; }
  100% { color: ${C}; }
`,x=(0,c.css)({background:"none",border:"none",cursor:"pointer",color:C,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:`${v} 2s linear`,"&:hover":{color:c.palette.gray.light3}}),O=(0,c.css)({display:"flex",paddingTop:c.spacing[1]/2,paddingRight:c.spacing[2]}),I=(0,c.css)({marginRight:c.spacing[2]}),M=(0,c.css)({color:c.palette.green.light2,marginLeft:c.spacing[2]}),H=(0,c.css)({borderTopColor:c.palette.green.light2});class R extends i.Component{static propTypes={darkMode:l().bool,isExpanded:l().bool.isRequired,isOperationInProgress:l().bool.isRequired,onShellToggleClicked:l().func.isRequired,showInfoModal:l().func.isRequired};componentDidMount(){document.addEventListener("keydown",this.handleKeyboardToggle.bind(this))}componentWillUnmount(){document.removeEventListener("keydown",this.handleKeyboardToggle.bind(this))}handleKeyboardToggle(e){let{ctrlKey:t,key:o}=e;t&&"`"===o&&this.props.onShellToggleClicked()}render(){const{darkMode:e,isExpanded:t,isOperationInProgress:o,onShellToggleClicked:i,showInfoModal:s}=this.props;return n().createElement("div",{className:(0,c.cx)(b,e&&k)},n().createElement("div",{className:S},n().createElement("button",{type:"button","data-testid":"shell-expand-button",className:x,"aria-label":t?"Close Shell":"Open Shell",onClick:i,"aria-pressed":t},">_MONGOSH",!t&&o&&n().createElement("span",{className:M},n().createElement(c.SpinLoader,{size:"12px",className:H})," Command in progress…"))),n().createElement("div",{className:O},t&&n().createElement(c.IconButton,{"data-testid":"shell-info-button",className:I,variant:"dark","aria-label":"Shell Info","aria-haspopup":"dialog",onClick:s},n().createElement(c.Icon,{glyph:"InfoWithCircle",size:"small"})),n().createElement(c.IconButton,{variant:"dark","aria-label":t?"Close Shell":"Open Shell",onClick:i,"aria-pressed":t},n().createElement(c.Icon,{glyph:t?"ChevronDown":"ChevronUp",size:"small"}))))}}const T=(0,c.withDarkMode)(R),{Shell:$}=o(72519),P=(0,c.css)({backgroundColor:c.palette.gray.dark3,display:"flex",flexBasis:"auto",position:"relative",flexDirection:"column",width:"100vw"},(0,c.getScrollbarStyles)(!0)),D=(0,c.css)({flexGrow:1,display:"none",overflow:"auto",borderTop:`1px solid ${c.palette.gray.dark2}`}),N=(0,c.css)({display:"flex"}),B=100;function L(){return Math.max(240,window.innerHeight-100)}class q extends i.Component{static propTypes={emitShellPluginOpened:l().func,runtime:l().object,shellOutput:l().array,historyStorage:l().object,enableShell:l().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<B&&o>B&&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>B?{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 l=e>B,r=l?function(e){const t=L();return Math.min(t,Math.max(B,e))}(e):32;return n().createElement(i.Fragment,null,n().createElement(f,{show:s,hideInfoModal:this.hideInfoModal.bind(this)}),n().createElement("div",{"data-testid":"shell-section",className:P,style:{height:r},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:L(),title:"MongoDB Shell"}),n().createElement(T,{isExpanded:l,onShellToggleClicked:()=>l?this.updateHeight(32):this.updateHeight(t),isOperationInProgress:o,showInfoModal:()=>this.setState({showInfoModal:!0})}),n().createElement("div",{"data-testid":"shell-content",className:(0,c.cx)(D,l&&N)},n().createElement($,{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,r.$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()))}}]);