Second frontend, written in Next.JS + Typescript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
21 KiB

4 years ago
  1. {"ast":null,"code":"\"use strict\";\n\nvar __importDefault = this && this.__importDefault || function (mod) {\n return mod && mod.__esModule ? mod : {\n \"default\": mod\n };\n};\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nconst url_1 = require(\"url\");\n\nconst mitt_1 = __importDefault(require(\"../mitt\"));\n\nconst utils_1 = require(\"../utils\");\n\nconst is_dynamic_1 = require(\"./utils/is-dynamic\");\n\nconst route_matcher_1 = require(\"./utils/route-matcher\");\n\nconst route_regex_1 = require(\"./utils/route-regex\");\n\nconst basePath = process.env.__NEXT_ROUTER_BASEPATH || '';\n\nfunction addBasePath(path) {\n return path.indexOf(basePath) !== 0 ? basePath + path : path;\n}\n\nexports.addBasePath = addBasePath;\n\nfunction delBasePath(path) {\n return path.indexOf(basePath) === 0 ? path.substr(basePath.length) || '/' : path;\n}\n\nfunction toRoute(path) {\n return path.replace(/\\/$/, '') || '/';\n}\n\nconst prepareRoute = path => toRoute(!path || path === '/' ? '/index' : path);\n\nfunction fetchNextData(pathname, query, isServerRender, cb) {\n let attempts = isServerRender ? 3 : 1;\n\n function getResponse() {\n return fetch(utils_1.formatWithValidation({\n // @ts-ignore __NEXT_DATA__\n pathname: `/_next/data/${__NEXT_DATA__.buildId}${pathname}.json`,\n query\n }), {\n // Cookies are required to be present for Next.js' SSG \"Preview Mode\".\n // Cookies may also be required for `getServerSideProps`.\n //\n // > `fetch` wont send cookies, unless you set the credentials init\n // > option.\n // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch\n //\n // > For maximum browser compatibility when it comes to sending &\n // > receiving cookies, always supply the `credentials: 'same-origin'`\n // > option instead of relying on the default.\n // https://github.com/github/fetch#caveats\n credentials: 'same-origin'\n }).then(res => {\n if (!res.ok) {\n if (--attempts > 0 && res.status >= 500) {\n return getResponse();\n }\n\n throw new Error(`Failed to load static props`);\n }\n\n return res.json();\n });\n }\n\n return getResponse().then(data => {\n return cb ? cb(data) : data;\n }).catch(err => {\n // We should only trigger a server-side transition if this was caused\n // on a client-side transition. Otherwise, we'd get into an infinite\n // loop.\n if (!isServerRender) {\n ;\n err.code = 'PAGE_LOAD_ERROR';\n }\n\n throw err;\n });\n}\n\nclass Router {\n constructor(pathname, query, as, {\n initialProps,\n pageLoader,\n App,\n wrapApp,\n Component,\n err,\n subscription,\n isFallback\n }) {\n // Static Data Cache\n this.sdc = {};\n\n this.onPopState = e => {\n if (!e.state) {\n // We get state as undefined for two reasons.\n // 1. With older safari (< 8) and older chrome (< 34)\n // 2. When the URL changed with #\n //\n // In the both cases, we don't need to proceed and change the route.\n // (as it's already changed)\n // But we can simply replace the state with the new changes.\n // Actually, for (1) we don't need to nothing. But it's hard to detect that event.\n // So, doing the following for (1) does no harm.\n const {\n pathname,\n query\n } = this;\n this.changeState('replaceState', utils_1.formatWithValidation({\n pathname,\n query\n }), utils_1.getURL());\n return;\n } // Make sure we don't re-render on initial load,\n // can be caused by navigating back from an external site\n\n\n if (e.state && this.isSsr && e.state.as === this.asPath && url_1.parse(e.state.url).pathname === this.pathname) {\n return;\n } // If the downstream application returns falsy, return.\n // They will then be responsible for handling the event.\n\n\n if (this._bps && !this._bps(e.state)) {\n