(global.webpackChunkCompassShellPlugin=global.webpackChunkCompassShellPlugin||[]).push([[508],{49945:(e,t,o)=>{"use strict";o.r(t),o.d(t,{CompassShell:()=>U,default:()=>B});var i=o(99497),n=o.n(i),r=o(13980),s=o.n(r),a=o(86993),l=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 d(){return n().createElement(c.Table,{data:h,columns:[n().createElement(c.TableHeader,{key:"name",label:"Key"}),n().createElement(c.TableHeader,{key:"value",label:"Description"})]},(({datum:e})=>n().createElement(c.Row,{key:e.key},n().createElement(c.Cell,null,n().createElement(c.Body,{weight:"medium"},n().createElement(c.KeyboardShortcut,{hotkey:e.key}))),n().createElement(c.Cell,null,n().createElement(c.Description,null,e.description)))))}const p=`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({hideInfoModal:e,show:t}){const o=(0,i.useCallback)((()=>{e()}),[e]);return n().createElement(c.InfoModal,{open:t,title:`mongosh ${p}`,trackingId:"shell_info_modal","data-testid":"shell-info-modal",onClose:o},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(d,null)))}g.propTypes={hideInfoModal:s().func.isRequired,show:s().bool.isRequired};const y=g,f=(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}`}),b=(0,c.css)({flexGrow:1,display:"flex",alignItems:"center"}),S=c.palette.gray.light1,E=c.palette.gray.base,w=c.palette.gray.light2,C=c.keyframes`
  0% { color: ${S}; }
  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: ${S}; }
`,v=(0,c.css)({background:"none",border:"none",cursor:"pointer",color:S,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:`${C} 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]}),M=(0,c.css)({color:c.palette.green.light2,marginLeft:c.spacing[2]}),I=({darkMode:e,isExpanded:t,isOperationInProgress:o,onShellToggleClicked:i,showInfoModal:r})=>((0,c.useHotkeys)("ctrl + `",i),n().createElement("div",{className:(0,c.cx)(f,e&&k)},n().createElement("div",{className:b},n().createElement("button",{type:"button","data-testid":"shell-expand-button",className:v,"aria-label":t?"Close Shell":"Open Shell",onClick:i,"aria-pressed":t},">_MONGOSH",!t&&o&&n().createElement("span",{className:M},n().createElement(c.SpinLoader,{darkMode:!0})," Command in progress…"))),n().createElement("div",{className:O},t&&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":t?"Close Shell":"Open Shell",onClick:i,"aria-pressed":t},n().createElement(c.Icon,{glyph:t?"ChevronDown":"ChevronUp",size:"small"})))));I.propTypes={darkMode:s().bool,isExpanded:s().bool.isRequired,isOperationInProgress:s().bool.isRequired,onShellToggleClicked:s().func.isRequired,showInfoModal:s().func.isRequired};const H=(0,c.withDarkMode)(I),{Shell:R}=o(72519),T=(0,c.css)({backgroundColor:c.palette.gray.dark4,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}`}),$=(0,c.css)({display:"flex"}),P=100;function N(){return Math.max(240,window.innerHeight-100)}class U extends i.Component{static propTypes={emitShellPluginOpened:s().func,runtime:s().object,shellOutput:s().array,historyStorage:s().object,enableShell:s().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<P&&o>P&&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>P?{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:r}=this.state;if(!this.props.enableShell||!this.props.runtime||!this.state.initialHistory)return n().createElement("div",null);const s=e>P,a=s?function(e){const t=N();return Math.min(t,Math.max(P,e))}(e):32;return n().createElement(i.Fragment,null,n().createElement(y,{show:r,hideInfoModal:this.hideInfoModal.bind(this)}),n().createElement("div",{"data-testid":"shell-section",className:T,style:{height:a},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:N(),title:"MongoDB Shell"}),n().createElement(H,{isExpanded:s,onShellToggleClicked:()=>s?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,s&&$)},n().createElement(R,{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 B=(0,a.$j)((e=>({emitShellPluginOpened:()=>{e.appRegistry&&e.appRegistry.globalAppRegistry&&e.appRegistry.globalAppRegistry.emit("compass:compass-shell:opened")},runtime:e.runtime?e.runtime.runtime:null})))((0,l.withPreferences)(U,["enableShell"],n()))},54039:e=>{function t(e){return Promise.resolve().then((()=>{var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}))}t.keys=()=>[],t.resolve=t,t.id=54039,e.exports=t},98953:e=>{function t(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=98953,e.exports=t},70648:()=>{}}]);