(window["webpackJsonpCompassShellPlugin"] = window["webpackJsonpCompassShellPlugin"] || []).push([[2],{

/***/ 474:
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// EXPORTS
__webpack_require__.d(__webpack_exports__, "CompassShell", function() { return /* reexport */ compass_shell_CompassShell; });

// EXTERNAL MODULE: external "react"
var external_react_ = __webpack_require__(2);
var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);

// EXTERNAL MODULE: /data/mci/6d31fc76e9f877c8998fe66b704cee62/src/node_modules/prop-types/index.js
var prop_types = __webpack_require__(245);
var prop_types_default = /*#__PURE__*/__webpack_require__.n(prop_types);

// EXTERNAL MODULE: /data/mci/6d31fc76e9f877c8998fe66b704cee62/src/node_modules/react-redux/es/index.js + 26 modules
var es = __webpack_require__(128);

// EXTERNAL MODULE: external "compass-preferences-model"
var external_compass_preferences_model_ = __webpack_require__(243);

// EXTERNAL MODULE: /data/mci/6d31fc76e9f877c8998fe66b704cee62/src/node_modules/@mongosh/browser-repl/lib/mongosh-browser-repl.js
var mongosh_browser_repl = __webpack_require__(282);

// EXTERNAL MODULE: external "@mongodb-js/compass-components"
var compass_components_ = __webpack_require__(242);

// CONCATENATED MODULE: ./src/components/shell-info-modal/keyboard-shortcuts-table.jsx


const rowStyles = Object(compass_components_["css"])({
  td: {
    padding: 0
  }
});
const hotkeys = [{
  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: '\u2191',
  description: 'Cycle backwards through command history.'
}, {
  key: '\u2193',
  description: 'Cycle forwards through command history.'
}];
function KeyboardShortcutsTable() {
  return /*#__PURE__*/external_react_default.a.createElement(compass_components_["Table"], {
    data: hotkeys,
    columns: [/*#__PURE__*/external_react_default.a.createElement(compass_components_["TableHeader"], {
      key: 'name',
      label: "Key"
    }), /*#__PURE__*/external_react_default.a.createElement(compass_components_["TableHeader"], {
      key: 'value',
      label: "Description"
    })]
  }, ({
    datum
  }) => /*#__PURE__*/external_react_default.a.createElement(compass_components_["Row"], {
    className: rowStyles,
    key: datum.key
  }, /*#__PURE__*/external_react_default.a.createElement(compass_components_["Cell"], null, /*#__PURE__*/external_react_default.a.createElement(compass_components_["Body"], {
    weight: "medium"
  }, datum.key)), /*#__PURE__*/external_react_default.a.createElement(compass_components_["Cell"], null, /*#__PURE__*/external_react_default.a.createElement(compass_components_["Description"], null, datum.description))));
}

// CONCATENATED MODULE: ./src/components/shell-info-modal/shell-info-modal.jsx




const mongoshVersion = `v${__webpack_require__(470).version}`;
const shortcutsTableContainerStyles = Object(compass_components_["css"])({
  marginTop: compass_components_["spacing"][2],
  maxHeight: '50vh',
  overflow: 'auto'
});
const shortcutsTitleStyles = Object(compass_components_["css"])({
  marginTop: compass_components_["spacing"][4]
});
function ShellInfoModal({
  hideInfoModal,
  show
}) {
  const onClose = Object(external_react_["useCallback"])(() => {
    hideInfoModal();
  }, [hideInfoModal]);
  return /*#__PURE__*/external_react_default.a.createElement(compass_components_["InfoModal"], {
    open: show,
    title: `mongosh ${mongoshVersion}`,
    trackingId: "shell_info_modal",
    "data-testid": "shell-info-modal",
    onClose: onClose
  }, /*#__PURE__*/external_react_default.a.createElement(compass_components_["Banner"], null, "For more information please visit the\xA0", /*#__PURE__*/external_react_default.a.createElement(compass_components_["Link"], {
    id: "mongosh-info-link",
    href: "https://docs.mongodb.com/compass/beta/embedded-shell/",
    target: "_blank"
  }, "MongoDB Shell Documentation"), "."), /*#__PURE__*/external_react_default.a.createElement(compass_components_["Subtitle"], {
    className: shortcutsTitleStyles
  }, "Keyboard Shortcuts"), /*#__PURE__*/external_react_default.a.createElement("div", {
    className: shortcutsTableContainerStyles
  }, /*#__PURE__*/external_react_default.a.createElement(KeyboardShortcutsTable, null)));
}
ShellInfoModal.propTypes = {
  hideInfoModal: prop_types_default.a.func.isRequired,
  show: prop_types_default.a.bool.isRequired
};
/* harmony default export */ var shell_info_modal = (ShellInfoModal);
// CONCATENATED MODULE: ./src/components/shell-info-modal/index.js

/* harmony default export */ var components_shell_info_modal = (shell_info_modal);
// CONCATENATED MODULE: ./src/components/shell-header/shell-header.jsx
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }




const shellHeaderStyles = Object(compass_components_["css"])({
  height: compass_components_["spacing"][5],
  display: 'flex',
  color: compass_components_["palette"].gray.light1
});
const shellHeaderLeftStyles = Object(compass_components_["css"])({
  flexGrow: 1,
  display: 'flex',
  alignItems: 'center'
});
const shellHeaderDefaultColor = compass_components_["palette"].gray.light1;
const shellHeaderFlashColorDark = compass_components_["palette"].gray.base;
const shellHeaderFlashColorLight = compass_components_["palette"].gray.light2;
const shellLoaderFlash = compass_components_["keyframes"]`
  0% { color: ${shellHeaderDefaultColor}; }
  10% { color: ${shellHeaderFlashColorDark}; }
  20% { color: ${shellHeaderFlashColorLight}; }
  30% { color: ${shellHeaderFlashColorDark}; }
  40% { color: ${shellHeaderFlashColorLight}; }
  50% { color: ${shellHeaderFlashColorDark}; }
  60% { color: ${shellHeaderFlashColorLight}; }
  70% { color: ${shellHeaderFlashColorDark}; }
  80% { color: ${shellHeaderFlashColorLight}; }
  100% { color: ${shellHeaderDefaultColor}; }
`;
const shellHeaderToggleStyles = Object(compass_components_["css"])({
  background: 'none',
  border: 'none',
  cursor: 'pointer',
  color: shellHeaderDefaultColor,
  padding: `0px ${compass_components_["spacing"][2]}px`,
  height: '100%',
  display: 'flex',
  verticalAlign: 'middle',
  flexDirection: 'row',
  alignItems: 'center',
  margin: 'auto 0',
  fontWeight: 'bold',
  fontSize: compass_components_["spacing"][2] * 1.5,
  lineHeight: `${compass_components_["spacing"][5]}px`,
  transition: 'all 200ms',
  userSelect: 'none',
  textTransform: 'uppercase',
  animation: `${shellLoaderFlash} 2s linear`,
  '&:hover': {
    color: compass_components_["palette"].gray.light3
  }
});
const shellHeaderRightStyles = Object(compass_components_["css"])({
  display: 'flex',
  paddingTop: compass_components_["spacing"][1] / 2,
  paddingRight: compass_components_["spacing"][2]
});
const infoButtonStyles = Object(compass_components_["css"])({
  marginRight: compass_components_["spacing"][2]
});
const operationInProgressStyles = Object(compass_components_["css"])({
  color: compass_components_["palette"].green.light2,
  marginLeft: compass_components_["spacing"][2]
});
class shell_header_ShellHeader extends external_react_["Component"] {
  componentDidMount() {
    document.addEventListener('keydown', this.handleKeyboardToggle.bind(this));
  }
  componentWillUnmount() {
    document.removeEventListener('keydown', this.handleKeyboardToggle.bind(this));
  }
  handleKeyboardToggle({
    ctrlKey,
    key
  }) {
    if (ctrlKey && key === '`') {
      this.props.onShellToggleClicked();
    }
  }

  /**
   * Render ShellHeader component.
   *
   * @returns {React.Component} The rendered component.
   */
  render() {
    const {
      isExpanded,
      isOperationInProgress,
      onShellToggleClicked,
      showInfoModal
    } = this.props;
    return /*#__PURE__*/external_react_default.a.createElement("div", {
      className: shellHeaderStyles
    }, /*#__PURE__*/external_react_default.a.createElement("div", {
      className: shellHeaderLeftStyles
    }, /*#__PURE__*/external_react_default.a.createElement("button", {
      type: "button",
      "data-testid": "shell-expand-button",
      className: shellHeaderToggleStyles,
      "aria-label": isExpanded ? 'Close Shell' : 'Open Shell',
      onClick: onShellToggleClicked,
      "aria-pressed": isExpanded
    }, ">_MONGOSH", !isExpanded && isOperationInProgress && /*#__PURE__*/external_react_default.a.createElement("span", {
      className: operationInProgressStyles
    }, /*#__PURE__*/external_react_default.a.createElement(mongosh_browser_repl["ShellLoader"], {
      size: "12px"
    }), "\xA0Command in progress\u2026"))), /*#__PURE__*/external_react_default.a.createElement("div", {
      className: shellHeaderRightStyles
    }, isExpanded && /*#__PURE__*/external_react_default.a.createElement(compass_components_["IconButton"], {
      "data-testid": "shell-info-button",
      className: infoButtonStyles,
      variant: "dark",
      "aria-label": "Shell Info",
      "aria-haspopup": "dialog",
      onClick: showInfoModal
    }, /*#__PURE__*/external_react_default.a.createElement(compass_components_["Icon"], {
      glyph: "InfoWithCircle",
      size: "small"
    })), /*#__PURE__*/external_react_default.a.createElement(compass_components_["IconButton"], {
      variant: "dark",
      "aria-label": isExpanded ? 'Close Shell' : 'Open Shell',
      onClick: onShellToggleClicked,
      "aria-pressed": isExpanded
    }, /*#__PURE__*/external_react_default.a.createElement(compass_components_["Icon"], {
      glyph: isExpanded ? 'ChevronDown' : 'ChevronUp',
      size: "small"
    }))));
  }
}
_defineProperty(shell_header_ShellHeader, "propTypes", {
  isExpanded: prop_types_default.a.bool.isRequired,
  isOperationInProgress: prop_types_default.a.bool.isRequired,
  onShellToggleClicked: prop_types_default.a.func.isRequired,
  showInfoModal: prop_types_default.a.func.isRequired
});
/* harmony default export */ var shell_header = (shell_header_ShellHeader);
// CONCATENATED MODULE: ./src/components/shell-header/index.js

/* harmony default export */ var components_shell_header = (shell_header);

// CONCATENATED MODULE: ./src/components/compass-shell/compass-shell.jsx
function compass_shell_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }








const compassShellStyles = Object(compass_components_["css"])({
  backgroundColor: compass_components_["palette"].gray.dark3,
  display: 'flex',
  flexBasis: 'auto',
  position: 'relative',
  flexDirection: 'column'
});
const compassShellContainerStyles = Object(compass_components_["css"])({
  flexGrow: 1,
  display: 'none',
  overflow: 'auto',
  borderTop: `1px solid ${compass_components_["palette"].gray.dark2}`,
  '*::-webkit-scrollbar-thumb': {
    background: Object(compass_components_["rgba"])(compass_components_["palette"].gray.light1, 0.5)
  }
});
const compassShellContainerVisibleStyles = Object(compass_components_["css"])({
  display: 'flex'
});
const defaultShellHeightOpened = 240;
const shellHeightClosed = 32;
const shellMinHeightOpened = 100;
function getMaxShellHeight() {
  return Math.max(defaultShellHeightOpened, window.innerHeight - 100);
}

// Apply bounds to the shell height when resizing to ensure it's always
// visible and usable to the user.
function boundShellHeight(attemptedHeight) {
  const maxHeight = getMaxShellHeight();
  return Math.min(maxHeight, Math.max(shellMinHeightOpened, attemptedHeight));
}
class compass_shell_CompassShell extends external_react_["Component"] {
  constructor(props) {
    super(props);
    compass_shell_defineProperty(this, "onShellOutputChanged", output => {
      this.shellOutput = output;
    });
    compass_shell_defineProperty(this, "onOperationStarted", () => {
      this.setState({
        isOperationInProgress: true
      });
    });
    compass_shell_defineProperty(this, "onOperationEnd", () => {
      this.setState({
        isOperationInProgress: false
      });
    });
    compass_shell_defineProperty(this, "terminateRuntime", () => {
      if (this.props.runtime) {
        this.props.runtime.terminate();
      }
    });
    compass_shell_defineProperty(this, "saveHistory", async history => {
      if (!this.props.historyStorage) {
        return;
      }
      try {
        await this.props.historyStorage.save(history);
      } catch (error) {
        // eslint-disable-next-line no-console
        console.error(error);
      }
    });
    compass_shell_defineProperty(this, "loadHistory", async () => {
      if (!this.props.historyStorage) {
        return;
      }
      try {
        const history = await this.props.historyStorage.load();
        this.setState({
          initialHistory: history
        });
      } catch (error) {
        // eslint-disable-next-line no-console
        console.error(error);
        this.setState({
          initialHistory: []
        });
      }
    });
    this.shellRef = /*#__PURE__*/external_react_default.a.createRef();
    this.shellOutput = this.props.shellOutput || [];
    this.state = {
      height: shellHeightClosed,
      prevHeight: defaultShellHeightOpened,
      initialHistory: this.props.historyStorage ? null : [],
      isOperationInProgress: false,
      showInfoModal: false
    };
  }
  componentDidMount() {
    this.loadHistory();
    window.addEventListener('beforeunload', this.terminateRuntime);
  }
  componentDidUpdate(prevProps, prevState) {
    const {
      height
    } = this.state;
    if (prevState.height < shellMinHeightOpened && height > shellMinHeightOpened) {
      this.props.emitShellPluginOpened();
    }
  }
  componentWillUnmount() {
    window.removeEventListener('beforeunload', this.terminateRuntime);
  }
  updateHeight(height) {
    this.setState(height > shellMinHeightOpened ? {
      height,
      // Store the previous height to use when toggling open/close
      // when we resize while the shell is expanded.
      prevHeight: height
    } : {
      height
    });
  }
  hideInfoModal() {
    this.setState({
      showInfoModal: false
    });
  }
  focusEditor() {
    var _window$getSelection;
    if (this.shellRef.current && ((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.type) !== 'Range') {
      this.shellRef.current.focusEditor();
    }
  }

  /**
   * Render CompassShell component.
   *
   * @returns {React.Component} The rendered component.
   */
  render() {
    const {
      height,
      prevHeight,
      isOperationInProgress,
      showInfoModal
    } = this.state;
    if (!this.props.enableShell || !this.props.runtime || !this.state.initialHistory) {
      return /*#__PURE__*/external_react_default.a.createElement("div", null);
    }
    const isExpanded = height > shellMinHeightOpened;
    const renderedHeight = isExpanded ? boundShellHeight(height) : shellHeightClosed;
    return /*#__PURE__*/external_react_default.a.createElement(external_react_["Fragment"], null, /*#__PURE__*/external_react_default.a.createElement(components_shell_info_modal, {
      show: showInfoModal,
      hideInfoModal: this.hideInfoModal.bind(this)
    }), /*#__PURE__*/external_react_default.a.createElement("div", {
      "data-testid": "shell-section",
      className: compassShellStyles,
      style: {
        height: renderedHeight
      },
      id: "content",
      onClick: this.focusEditor.bind(this)
    }, /*#__PURE__*/external_react_default.a.createElement(compass_components_["ResizeHandle"], {
      direction: compass_components_["ResizeDirection"].TOP,
      onChange: newHeight => this.updateHeight(newHeight),
      value: height,
      minValue: shellHeightClosed,
      maxValue: getMaxShellHeight(),
      title: "MongoDB Shell"
    }), /*#__PURE__*/external_react_default.a.createElement(components_shell_header, {
      isExpanded: isExpanded,
      onShellToggleClicked: () => isExpanded ? this.updateHeight(shellHeightClosed) : this.updateHeight(prevHeight),
      isOperationInProgress: isOperationInProgress,
      showInfoModal: () => this.setState({
        showInfoModal: true
      })
    }), /*#__PURE__*/external_react_default.a.createElement("div", {
      "data-testid": "shell-content",
      className: Object(compass_components_["cx"])(compassShellContainerStyles, {
        [compassShellContainerVisibleStyles]: isExpanded
      })
    }, /*#__PURE__*/external_react_default.a.createElement(mongosh_browser_repl["Shell"], {
      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
    }))));
  }
}
compass_shell_defineProperty(compass_shell_CompassShell, "propTypes", {
  emitShellPluginOpened: prop_types_default.a.func,
  runtime: prop_types_default.a.object,
  shellOutput: prop_types_default.a.array,
  historyStorage: prop_types_default.a.object,
  enableShell: prop_types_default.a.bool
});
compass_shell_defineProperty(compass_shell_CompassShell, "defaultProps", {
  emitShellPluginOpened: () => {},
  runtime: null
});
/* harmony default export */ var compass_shell = (Object(es["b" /* connect */])(state => ({
  emitShellPluginOpened: () => {
    if (state.appRegistry && state.appRegistry.globalAppRegistry) {
      state.appRegistry.globalAppRegistry.emit('compass:compass-shell:opened');
    }
  },
  runtime: state.runtime ? state.runtime.runtime : null
}))(Object(external_compass_preferences_model_["withPreferences"])(compass_shell_CompassShell, ['enableShell'], external_react_default.a)));
// CONCATENATED MODULE: ./src/components/compass-shell/index.js

/* harmony default export */ var components_compass_shell = __webpack_exports__["default"] = (compass_shell);


/***/ })

}]);