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.
 
 
 

1 lines
9.1 KiB

{"ast":null,"code":"\"use strict\";\n\nvar _interopRequireDefault = require(\"@babel/runtime/helpers/interopRequireDefault\");\n\nvar _interopRequireWildcard = require(\"@babel/runtime/helpers/interopRequireWildcard\");\n\nexports.__esModule = true;\nexports.default = void 0;\n\nvar _react = _interopRequireWildcard(require(\"react\"));\n\nvar _url = require(\"url\");\n\nvar _utils = require(\"../next-server/lib/utils\");\n\nvar _router = _interopRequireDefault(require(\"./router\"));\n\nvar _router2 = require(\"../next-server/lib/router/router\");\n\nfunction isLocal(href) {\n var url = (0, _url.parse)(href, false, true);\n var origin = (0, _url.parse)((0, _utils.getLocationOrigin)(), false, true);\n return !url.host || url.protocol === origin.protocol && url.host === origin.host;\n}\n\nfunction memoizedFormatUrl(formatFunc) {\n var lastHref = null;\n var lastAs = null;\n var lastResult = null;\n return (href, as) => {\n if (lastResult && href === lastHref && as === lastAs) {\n return lastResult;\n }\n\n var result = formatFunc(href, as);\n lastHref = href;\n lastAs = as;\n lastResult = result;\n return result;\n };\n}\n\nfunction formatUrl(url) {\n return url && typeof url === 'object' ? (0, _utils.formatWithValidation)(url) : url;\n}\n\nvar observer;\nvar listeners = new Map();\nvar IntersectionObserver = false ? window.IntersectionObserver : null;\nvar prefetched = {};\n\nfunction getObserver() {\n // Return shared instance of IntersectionObserver if already created\n if (observer) {\n return observer;\n } // Only create shared IntersectionObserver if supported in browser\n\n\n if (!IntersectionObserver) {\n return undefined;\n }\n\n return observer = new IntersectionObserver(entries => {\n entries.forEach(entry => {\n if (!listeners.has(entry.target)) {\n return;\n }\n\n var cb = listeners.get(entry.target);\n\n if (entry.isIntersecting || entry.intersectionRatio > 0) {\n observer.unobserve(entry.target);\n listeners.delete(entry.target);\n cb();\n }\n });\n }, {\n rootMargin: '200px'\n });\n}\n\nvar listenToIntersections = (el, cb) => {\n var observer = getObserver();\n\n if (!observer) {\n return () => {};\n }\n\n observer.observe(el);\n listeners.set(el, cb);\n return () => {\n try {\n observer.unobserve(el);\n } catch (err) {\n console.error(err);\n }\n\n listeners.delete(el);\n };\n};\n\nclass Link extends _react.Component {\n constructor(props) {\n super(props);\n this.p = void 0;\n\n this.cleanUpListeners = () => {};\n\n this.formatUrls = memoizedFormatUrl((href, asHref) => {\n return {\n href: (0, _router2.addBasePath)(formatUrl(href)),\n as: asHref ? (0, _router2.addBasePath)(formatUrl(asHref)) : asHref\n };\n });\n\n this.linkClicked = e => {\n var {\n nodeName,\n target\n } = e.currentTarget;\n\n if (nodeName === 'A' && (target && target !== '_self' || e.metaKey || e.ctrlKey || e.shiftKey || e.nativeEvent && e.nativeEvent.which === 2)) {\n // ignore click for new tab / new window behavior\n return;\n }\n\n var {\n href,\n as\n } = this.formatUrls(this.props.href, this.props.as);\n\n if (!isLocal(href)) {\n // ignore click if it's outside our scope (e.g. https://google.com)\n return;\n }\n\n var {\n pathname\n } = window.location;\n href = (0, _url.resolve)(pathname, href);\n as = as ? (0, _url.resolve)(pathname, as) : href;\n e.preventDefault(); // avoid scroll for urls with anchor refs\n\n var {\n scroll\n } = this.props;\n\n if (scroll == null) {\n scroll = as.indexOf('#') < 0;\n } // replace state instead of push if prop is present\n\n\n _router.default[this.props.replace ? 'replace' : 'push'](href, as, {\n shallow: this.props.shallow\n }).then(success => {\n if (!success) return;\n\n if (scroll) {\n window.scrollTo(0, 0);\n document.body.focus();\n }\n });\n };\n\n if (false) {\n if (props.prefetch) {\n console.warn('Next.js auto-prefetches automatically based on viewport. The prefetch attribute is no longer needed. More: https://err.sh/zeit/next.js/prefetch-true-deprecated');\n }\n }\n\n this.p = props.prefetch !== false;\n }\n\n componentWillUnmount() {\n this.cleanUpListeners();\n }\n\n getPaths() {\n var {\n pathname\n } = window.location;\n var {\n href: parsedHref,\n as: parsedAs\n } = this.formatUrls(this.props.href, this.props.as);\n var resolvedHref = (0, _url.resolve)(pathname, parsedHref);\n return [resolvedHref, parsedAs ? (0, _url.resolve)(pathname, parsedAs) : resolvedHref];\n }\n\n handleRef(ref) {\n if (this.p && IntersectionObserver && ref && ref.tagName) {\n this.cleanUpListeners();\n var isPrefetched = prefetched[this.getPaths().join( // Join on an invalid URI character\n '%')];\n\n if (!isPrefetched) {\n this.cleanUpListeners = listenToIntersections(ref, () => {\n this.prefetch();\n });\n }\n }\n } // The function is memoized so that no extra lifecycles are needed\n // as per https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html\n\n\n prefetch(options) {\n if (!this.p || true) return; // Prefetch the JSON page if asked (only in the client)\n\n var paths = this.getPaths(); // We need to handle a prefetch error here since we may be\n // loading with priority which can reject but we don't\n // want to force navigation since this is only a prefetch\n\n _router.default.prefetch(paths[\n /* href */\n 0], paths[\n /* asPath */\n 1], options).catch(err => {\n if (false) {\n // rethrow to show invalid URL errors\n throw err;\n }\n });\n\n prefetched[paths.join( // Join on an invalid URI character\n '%')] = true;\n }\n\n render() {\n var {\n children\n } = this.props;\n var {\n href,\n as\n } = this.formatUrls(this.props.href, this.props.as); // Deprecated. Warning shown by propType check. If the children provided is a string (<Link>example</Link>) we wrap it in an <a> tag\n\n if (typeof children === 'string') {\n children = _react.default.createElement(\"a\", null, children);\n } // This will return the first child, if multiple are provided it will throw an error\n\n\n var child = _react.Children.only(children);\n\n var props = {\n ref: el => {\n this.handleRef(el);\n\n if (child && typeof child === 'object' && child.ref) {\n if (typeof child.ref === 'function') child.ref(el);else if (typeof child.ref === 'object') {\n child.ref.current = el;\n }\n }\n },\n onMouseEnter: e => {\n if (child.props && typeof child.props.onMouseEnter === 'function') {\n child.props.onMouseEnter(e);\n }\n\n this.prefetch({\n priority: true\n });\n },\n onClick: e => {\n if (child.props && typeof child.props.onClick === 'function') {\n child.props.onClick(e);\n }\n\n if (!e.defaultPrevented) {\n this.linkClicked(e);\n }\n }\n }; // If child is an <a> tag and doesn't have a href attribute, or if the 'passHref' property is\n // defined, we specify the current 'href', so that repetition is not needed by the user\n\n if (this.props.passHref || child.type === 'a' && !('href' in child.props)) {\n props.href = as || href;\n } // Add the ending slash to the paths. So, we can serve the\n // \"<page>/index.html\" directly.\n\n\n if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n var rewriteUrlForNextExport = require('../next-server/lib/router/rewrite-url-for-export').rewriteUrlForNextExport;\n\n if (props.href && typeof __NEXT_DATA__ !== 'undefined' && __NEXT_DATA__.nextExport) {\n props.href = rewriteUrlForNextExport(props.href);\n }\n }\n\n return _react.default.cloneElement(child, props);\n }\n\n}\n\nif (false) {\n var warn = (0, _utils.execOnce)(console.error); // This module gets removed by webpack.IgnorePlugin\n\n var PropTypes = require('prop-types');\n\n var exact = require('prop-types-exact'); // @ts-ignore the property is supported, when declaring it on the class it outputs an extra bit of code which is not needed.\n\n\n Link.propTypes = exact({\n href: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,\n as: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),\n prefetch: PropTypes.bool,\n replace: PropTypes.bool,\n shallow: PropTypes.bool,\n passHref: PropTypes.bool,\n scroll: PropTypes.bool,\n children: PropTypes.oneOfType([PropTypes.element, (props, propName) => {\n var value = props[propName];\n\n if (typeof value === 'string') {\n warn(\"Warning: You're using a string directly inside <Link>. This usage has been deprecated. Please add an <a> tag as child of <Link>\");\n }\n\n return null;\n }]).isRequired\n });\n}\n\nvar _default = Link;\nexports.default = _default;","map":null,"metadata":{},"sourceType":"script"}