{"ast":null,"code":"import _Reflect$construct from \"@babel/runtime-corejs2/core-js/reflect/construct\";\nimport _regeneratorRuntime from \"@babel/runtime-corejs2/regenerator\";\nimport _asyncToGenerator from \"@babel/runtime-corejs2/helpers/asyncToGenerator\";\nimport _classCallCheck from \"@babel/runtime-corejs2/helpers/classCallCheck\";\nimport _createClass from \"@babel/runtime-corejs2/helpers/createClass\";\nimport _inherits from \"@babel/runtime-corejs2/helpers/inherits\";\nimport _possibleConstructorReturn from \"@babel/runtime-corejs2/helpers/possibleConstructorReturn\";\nimport _getPrototypeOf from \"@babel/runtime-corejs2/helpers/getPrototypeOf\";\nimport _JSXStyle from \"styled-jsx/style\";\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(_Reflect$construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nimport * as React from \"react\";\nimport { getJSON } from \"../shims/ajax\";\nimport Header from \"../components/header\";\nimport BrowseHeader from \"../components/browse-header\";\nimport Body from \"../components/body\";\nimport { Entry } from \"../components/contents\";\n\nvar ViewPage = /*#__PURE__*/function (_React$Component) {\n  _inherits(ViewPage, _React$Component);\n\n  var _super = _createSuper(ViewPage);\n\n  _createClass(ViewPage, null, [{\n    key: \"getInitialProps\",\n    value: function () {\n      var _getInitialProps = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(context) {\n        var req, query, config, viewPath, BASE_PATH, port, url, xhr;\n        return _regeneratorRuntime.wrap(function _callee$(_context) {\n          while (1) {\n            switch (_context.prev = _context.next) {\n              case 0:\n                req = context.req;\n                query = context.query; // Later, we'll use this to fill in the notebook\n                // file data from the server side (or fallback to /api/contents)\n                // For now, leaving \"server\": boolean to assist in debugging\n                // during the refactor\n                // The best choice will be to rely only on client side for now\n                // I'm sure\n\n                config = {};\n                config.commuterExecuteLink = process.env.COMMUTER_EXECUTE_LINK;\n                viewPath = query.viewPath || \"/\";\n\n                if (req) {\n                  // Server side, communicate with our local API\n                  port = process.env.COMMUTER_PORT || 4000;\n                  BASE_PATH = \"http://127.0.0.1:\".concat(port, \"/\");\n                } else {\n                  BASE_PATH = \"/\";\n                }\n\n                url = \"\".concat(BASE_PATH, \"api/contents/\").concat(viewPath);\n                _context.next = 9;\n                return getJSON(url).toPromise();\n\n              case 9:\n                xhr = _context.sent;\n                return _context.abrupt(\"return\", {\n                  contents: xhr.response,\n                  statusCode: xhr.status,\n                  viewPath: viewPath,\n                  serverConfig: config\n                });\n\n              case 11:\n              case \"end\":\n                return _context.stop();\n            }\n          }\n        }, _callee);\n      }));\n\n      function getInitialProps(_x) {\n        return _getInitialProps.apply(this, arguments);\n      }\n\n      return getInitialProps;\n    }()\n  }]);\n\n  function ViewPage(props) {\n    var _this;\n\n    _classCallCheck(this, ViewPage);\n\n    _this = _super.call(this, props);\n    var config = {};\n\n    if (props.serverConfig) {\n      _this.state = {\n        config: props.serverConfig\n      };\n    } else {\n      var configScriptElement = document.getElementById(\"serverConfig\");\n\n      if (configScriptElement !== null) {\n        config = JSON.parse(configScriptElement.textContent);\n      }\n\n      _this.state = {\n        config: config\n      };\n    }\n\n    return _this;\n  }\n\n  _createClass(ViewPage, [{\n    key: \"render\",\n    value: function render() {\n      if (this.props.statusCode !== 200) {\n        return \"Nothing found for \".concat(this.props.viewPath);\n      }\n\n      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Header, null), /*#__PURE__*/React.createElement(BrowseHeader, {\n        basepath: \"/view\",\n        path: this.props.viewPath,\n        type: this.props.contents.type,\n        commuterExecuteLink: this.state.config.commuterExecuteLink\n      }), /*#__PURE__*/React.createElement(Body, null, /*#__PURE__*/React.createElement(\"div\", {\n        className: \"jsx-3508813217\" + \" \" + \"entry\"\n      }, /*#__PURE__*/React.createElement(Entry, {\n        entry: this.props.contents,\n        pathname: this.props.viewPath,\n        basepath: \"/view\"\n      }), /*#__PURE__*/React.createElement(_JSXStyle, {\n        id: \"3508813217\"\n      }, [\".jsx-3508813217{margin-top:2rem;padding-left:2rem;padding-right:2rem;}\"]))));\n    }\n  }]);\n\n  return ViewPage;\n}(React.Component);\n\nexport default ViewPage;","map":null,"metadata":{},"sourceType":"module"}