This commit is contained in:
4
node_modules/react-router/modules/HistoryContext.js
generated
vendored
Normal file
4
node_modules/react-router/modules/HistoryContext.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import createNamedContext from "./createNamedContext";
|
||||
|
||||
const historyContext = /*#__PURE__*/ createNamedContext("Router-History");
|
||||
export default historyContext;
|
||||
21
node_modules/react-router/modules/Lifecycle.js
generated
vendored
Normal file
21
node_modules/react-router/modules/Lifecycle.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from "react";
|
||||
|
||||
class Lifecycle extends React.Component {
|
||||
componentDidMount() {
|
||||
if (this.props.onMount) this.props.onMount.call(this, this);
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.onUpdate) this.props.onUpdate.call(this, this, prevProps);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.props.onUnmount) this.props.onUnmount.call(this, this);
|
||||
}
|
||||
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export default Lifecycle;
|
||||
37
node_modules/react-router/modules/MemoryRouter.js
generated
vendored
Normal file
37
node_modules/react-router/modules/MemoryRouter.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { createMemoryHistory as createHistory } from "history";
|
||||
import warning from "tiny-warning";
|
||||
|
||||
import Router from "./Router.js";
|
||||
|
||||
/**
|
||||
* The public API for a <Router> that stores location in memory.
|
||||
*/
|
||||
class MemoryRouter extends React.Component {
|
||||
history = createHistory(this.props);
|
||||
|
||||
render() {
|
||||
return <Router history={this.history} children={this.props.children} />;
|
||||
}
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
MemoryRouter.propTypes = {
|
||||
initialEntries: PropTypes.array,
|
||||
initialIndex: PropTypes.number,
|
||||
getUserConfirmation: PropTypes.func,
|
||||
keyLength: PropTypes.number,
|
||||
children: PropTypes.node
|
||||
};
|
||||
|
||||
MemoryRouter.prototype.componentDidMount = function() {
|
||||
warning(
|
||||
!this.props.history,
|
||||
"<MemoryRouter> ignores the history prop. To use a custom history, " +
|
||||
"use `import { Router }` instead of `import { MemoryRouter as Router }`."
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default MemoryRouter;
|
||||
52
node_modules/react-router/modules/Prompt.js
generated
vendored
Normal file
52
node_modules/react-router/modules/Prompt.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
import Lifecycle from "./Lifecycle.js";
|
||||
import RouterContext from "./RouterContext.js";
|
||||
|
||||
/**
|
||||
* The public API for prompting the user before navigating away from a screen.
|
||||
*/
|
||||
function Prompt({ message, when = true }) {
|
||||
return (
|
||||
<RouterContext.Consumer>
|
||||
{context => {
|
||||
invariant(context, "You should not use <Prompt> outside a <Router>");
|
||||
|
||||
if (!when || context.staticContext) return null;
|
||||
|
||||
const method = context.history.block;
|
||||
|
||||
return (
|
||||
<Lifecycle
|
||||
onMount={self => {
|
||||
self.release = method(message);
|
||||
}}
|
||||
onUpdate={(self, prevProps) => {
|
||||
if (prevProps.message !== message) {
|
||||
self.release();
|
||||
self.release = method(message);
|
||||
}
|
||||
}}
|
||||
onUnmount={self => {
|
||||
self.release();
|
||||
}}
|
||||
message={message}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</RouterContext.Consumer>
|
||||
);
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
const messageType = PropTypes.oneOfType([PropTypes.func, PropTypes.string]);
|
||||
|
||||
Prompt.propTypes = {
|
||||
when: PropTypes.bool,
|
||||
message: messageType.isRequired
|
||||
};
|
||||
}
|
||||
|
||||
export default Prompt;
|
||||
72
node_modules/react-router/modules/Redirect.js
generated
vendored
Normal file
72
node_modules/react-router/modules/Redirect.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { createLocation, locationsAreEqual } from "history";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
import Lifecycle from "./Lifecycle.js";
|
||||
import RouterContext from "./RouterContext.js";
|
||||
import generatePath from "./generatePath.js";
|
||||
|
||||
/**
|
||||
* The public API for navigating programmatically with a component.
|
||||
*/
|
||||
function Redirect({ computedMatch, to, push = false }) {
|
||||
return (
|
||||
<RouterContext.Consumer>
|
||||
{context => {
|
||||
invariant(context, "You should not use <Redirect> outside a <Router>");
|
||||
|
||||
const { history, staticContext } = context;
|
||||
|
||||
const method = push ? history.push : history.replace;
|
||||
const location = createLocation(
|
||||
computedMatch
|
||||
? typeof to === "string"
|
||||
? generatePath(to, computedMatch.params)
|
||||
: {
|
||||
...to,
|
||||
pathname: generatePath(to.pathname, computedMatch.params)
|
||||
}
|
||||
: to
|
||||
);
|
||||
|
||||
// When rendering in a static context,
|
||||
// set the new location immediately.
|
||||
if (staticContext) {
|
||||
method(location);
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Lifecycle
|
||||
onMount={() => {
|
||||
method(location);
|
||||
}}
|
||||
onUpdate={(self, prevProps) => {
|
||||
const prevLocation = createLocation(prevProps.to);
|
||||
if (
|
||||
!locationsAreEqual(prevLocation, {
|
||||
...location,
|
||||
key: prevLocation.key
|
||||
})
|
||||
) {
|
||||
method(location);
|
||||
}
|
||||
}}
|
||||
to={to}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</RouterContext.Consumer>
|
||||
);
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
Redirect.propTypes = {
|
||||
push: PropTypes.bool,
|
||||
from: PropTypes.string,
|
||||
to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired
|
||||
};
|
||||
}
|
||||
|
||||
export default Redirect;
|
||||
140
node_modules/react-router/modules/Route.js
generated
vendored
Normal file
140
node_modules/react-router/modules/Route.js
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
import React from "react";
|
||||
import { isValidElementType } from "react-is";
|
||||
import PropTypes from "prop-types";
|
||||
import invariant from "tiny-invariant";
|
||||
import warning from "tiny-warning";
|
||||
|
||||
import RouterContext from "./RouterContext.js";
|
||||
import matchPath from "./matchPath.js";
|
||||
|
||||
function isEmptyChildren(children) {
|
||||
return React.Children.count(children) === 0;
|
||||
}
|
||||
|
||||
function evalChildrenDev(children, props, path) {
|
||||
const value = children(props);
|
||||
|
||||
warning(
|
||||
value !== undefined,
|
||||
"You returned `undefined` from the `children` function of " +
|
||||
`<Route${path ? ` path="${path}"` : ""}>, but you ` +
|
||||
"should have returned a React element or `null`"
|
||||
);
|
||||
|
||||
return value || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The public API for matching a single path and rendering.
|
||||
*/
|
||||
class Route extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<RouterContext.Consumer>
|
||||
{context => {
|
||||
invariant(context, "You should not use <Route> outside a <Router>");
|
||||
|
||||
const location = this.props.location || context.location;
|
||||
const match = this.props.computedMatch
|
||||
? this.props.computedMatch // <Switch> already computed the match for us
|
||||
: this.props.path
|
||||
? matchPath(location.pathname, this.props)
|
||||
: context.match;
|
||||
|
||||
const props = { ...context, location, match };
|
||||
|
||||
let { children, component, render } = this.props;
|
||||
|
||||
// Preact uses an empty array as children by
|
||||
// default, so use null if that's the case.
|
||||
if (Array.isArray(children) && isEmptyChildren(children)) {
|
||||
children = null;
|
||||
}
|
||||
|
||||
return (
|
||||
<RouterContext.Provider value={props}>
|
||||
{props.match
|
||||
? children
|
||||
? typeof children === "function"
|
||||
? __DEV__
|
||||
? evalChildrenDev(children, props, this.props.path)
|
||||
: children(props)
|
||||
: children
|
||||
: component
|
||||
? React.createElement(component, props)
|
||||
: render
|
||||
? render(props)
|
||||
: null
|
||||
: typeof children === "function"
|
||||
? __DEV__
|
||||
? evalChildrenDev(children, props, this.props.path)
|
||||
: children(props)
|
||||
: null}
|
||||
</RouterContext.Provider>
|
||||
);
|
||||
}}
|
||||
</RouterContext.Consumer>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
Route.propTypes = {
|
||||
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
|
||||
component: (props, propName) => {
|
||||
if (props[propName] && !isValidElementType(props[propName])) {
|
||||
return new Error(
|
||||
`Invalid prop 'component' supplied to 'Route': the prop is not a valid React component`
|
||||
);
|
||||
}
|
||||
},
|
||||
exact: PropTypes.bool,
|
||||
location: PropTypes.object,
|
||||
path: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.arrayOf(PropTypes.string)
|
||||
]),
|
||||
render: PropTypes.func,
|
||||
sensitive: PropTypes.bool,
|
||||
strict: PropTypes.bool
|
||||
};
|
||||
|
||||
Route.prototype.componentDidMount = function() {
|
||||
warning(
|
||||
!(
|
||||
this.props.children &&
|
||||
!isEmptyChildren(this.props.children) &&
|
||||
this.props.component
|
||||
),
|
||||
"You should not use <Route component> and <Route children> in the same route; <Route component> will be ignored"
|
||||
);
|
||||
|
||||
warning(
|
||||
!(
|
||||
this.props.children &&
|
||||
!isEmptyChildren(this.props.children) &&
|
||||
this.props.render
|
||||
),
|
||||
"You should not use <Route render> and <Route children> in the same route; <Route render> will be ignored"
|
||||
);
|
||||
|
||||
warning(
|
||||
!(this.props.component && this.props.render),
|
||||
"You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored"
|
||||
);
|
||||
};
|
||||
|
||||
Route.prototype.componentDidUpdate = function(prevProps) {
|
||||
warning(
|
||||
!(this.props.location && !prevProps.location),
|
||||
'<Route> elements should not change from uncontrolled to controlled (or vice versa). You initially used no "location" prop and then provided one on a subsequent render.'
|
||||
);
|
||||
|
||||
warning(
|
||||
!(!this.props.location && prevProps.location),
|
||||
'<Route> elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.'
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default Route;
|
||||
100
node_modules/react-router/modules/Router.js
generated
vendored
Normal file
100
node_modules/react-router/modules/Router.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import warning from "tiny-warning";
|
||||
|
||||
import HistoryContext from "./HistoryContext.js";
|
||||
import RouterContext from "./RouterContext.js";
|
||||
|
||||
/**
|
||||
* The public API for putting history on context.
|
||||
*/
|
||||
class Router extends React.Component {
|
||||
static computeRootMatch(pathname) {
|
||||
return { path: "/", url: "/", params: {}, isExact: pathname === "/" };
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
location: props.history.location
|
||||
};
|
||||
|
||||
// This is a bit of a hack. We have to start listening for location
|
||||
// changes here in the constructor in case there are any <Redirect>s
|
||||
// on the initial render. If there are, they will replace/push when
|
||||
// they mount and since cDM fires in children before parents, we may
|
||||
// get a new location before the <Router> is mounted.
|
||||
this._isMounted = false;
|
||||
this._pendingLocation = null;
|
||||
|
||||
if (!props.staticContext) {
|
||||
this.unlisten = props.history.listen(location => {
|
||||
this._pendingLocation = location;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this._isMounted = true;
|
||||
|
||||
if (this.unlisten) {
|
||||
// Any pre-mount location changes have been captured at
|
||||
// this point, so unregister the listener.
|
||||
this.unlisten();
|
||||
}
|
||||
if (!this.props.staticContext) {
|
||||
this.unlisten = this.props.history.listen(location => {
|
||||
if (this._isMounted) {
|
||||
this.setState({ location });
|
||||
}
|
||||
});
|
||||
}
|
||||
if (this._pendingLocation) {
|
||||
this.setState({ location: this._pendingLocation });
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.unlisten) {
|
||||
this.unlisten();
|
||||
this._isMounted = false;
|
||||
this._pendingLocation = null;
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<RouterContext.Provider
|
||||
value={{
|
||||
history: this.props.history,
|
||||
location: this.state.location,
|
||||
match: Router.computeRootMatch(this.state.location.pathname),
|
||||
staticContext: this.props.staticContext
|
||||
}}
|
||||
>
|
||||
<HistoryContext.Provider
|
||||
children={this.props.children || null}
|
||||
value={this.props.history}
|
||||
/>
|
||||
</RouterContext.Provider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
Router.propTypes = {
|
||||
children: PropTypes.node,
|
||||
history: PropTypes.object.isRequired,
|
||||
staticContext: PropTypes.object
|
||||
};
|
||||
|
||||
Router.prototype.componentDidUpdate = function(prevProps) {
|
||||
warning(
|
||||
prevProps.history === this.props.history,
|
||||
"You cannot change <Router history>"
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default Router;
|
||||
4
node_modules/react-router/modules/RouterContext.js
generated
vendored
Normal file
4
node_modules/react-router/modules/RouterContext.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import createNamedContext from "./createNamedContext";
|
||||
|
||||
const context = /*#__PURE__*/ createNamedContext("Router");
|
||||
export default context;
|
||||
102
node_modules/react-router/modules/StaticRouter.js
generated
vendored
Normal file
102
node_modules/react-router/modules/StaticRouter.js
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { createLocation, createPath } from "history";
|
||||
import invariant from "tiny-invariant";
|
||||
import warning from "tiny-warning";
|
||||
|
||||
import Router from "./Router.js";
|
||||
|
||||
function addLeadingSlash(path) {
|
||||
return path.charAt(0) === "/" ? path : "/" + path;
|
||||
}
|
||||
|
||||
function addBasename(basename, location) {
|
||||
if (!basename) return location;
|
||||
|
||||
return {
|
||||
...location,
|
||||
pathname: addLeadingSlash(basename) + location.pathname
|
||||
};
|
||||
}
|
||||
|
||||
function stripBasename(basename, location) {
|
||||
if (!basename) return location;
|
||||
|
||||
const base = addLeadingSlash(basename);
|
||||
|
||||
if (location.pathname.indexOf(base) !== 0) return location;
|
||||
|
||||
return {
|
||||
...location,
|
||||
pathname: location.pathname.substr(base.length)
|
||||
};
|
||||
}
|
||||
|
||||
function createURL(location) {
|
||||
return typeof location === "string" ? location : createPath(location);
|
||||
}
|
||||
|
||||
function staticHandler(methodName) {
|
||||
return () => {
|
||||
invariant(false, "You cannot %s with <StaticRouter>", methodName);
|
||||
};
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
/**
|
||||
* The public top-level API for a "static" <Router>, so-called because it
|
||||
* can't actually change the current location. Instead, it just records
|
||||
* location changes in a context object. Useful mainly in testing and
|
||||
* server-rendering scenarios.
|
||||
*/
|
||||
class StaticRouter extends React.Component {
|
||||
navigateTo(location, action) {
|
||||
const { basename = "", context = {} } = this.props;
|
||||
context.action = action;
|
||||
context.location = addBasename(basename, createLocation(location));
|
||||
context.url = createURL(context.location);
|
||||
}
|
||||
|
||||
handlePush = location => this.navigateTo(location, "PUSH");
|
||||
handleReplace = location => this.navigateTo(location, "REPLACE");
|
||||
handleListen = () => noop;
|
||||
handleBlock = () => noop;
|
||||
|
||||
render() {
|
||||
const { basename = "", context = {}, location = "/", ...rest } = this.props;
|
||||
|
||||
const history = {
|
||||
createHref: path => addLeadingSlash(basename + createURL(path)),
|
||||
action: "POP",
|
||||
location: stripBasename(basename, createLocation(location)),
|
||||
push: this.handlePush,
|
||||
replace: this.handleReplace,
|
||||
go: staticHandler("go"),
|
||||
goBack: staticHandler("goBack"),
|
||||
goForward: staticHandler("goForward"),
|
||||
listen: this.handleListen,
|
||||
block: this.handleBlock
|
||||
};
|
||||
|
||||
return <Router {...rest} history={history} staticContext={context} />;
|
||||
}
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
StaticRouter.propTypes = {
|
||||
basename: PropTypes.string,
|
||||
context: PropTypes.object,
|
||||
location: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
|
||||
};
|
||||
|
||||
StaticRouter.prototype.componentDidMount = function() {
|
||||
warning(
|
||||
!this.props.history,
|
||||
"<StaticRouter> ignores the history prop. To use a custom history, " +
|
||||
"use `import { Router }` instead of `import { StaticRouter as Router }`."
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default StaticRouter;
|
||||
67
node_modules/react-router/modules/Switch.js
generated
vendored
Normal file
67
node_modules/react-router/modules/Switch.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import invariant from "tiny-invariant";
|
||||
import warning from "tiny-warning";
|
||||
|
||||
import RouterContext from "./RouterContext.js";
|
||||
import matchPath from "./matchPath.js";
|
||||
|
||||
/**
|
||||
* The public API for rendering the first <Route> that matches.
|
||||
*/
|
||||
class Switch extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<RouterContext.Consumer>
|
||||
{context => {
|
||||
invariant(context, "You should not use <Switch> outside a <Router>");
|
||||
|
||||
const location = this.props.location || context.location;
|
||||
|
||||
let element, match;
|
||||
|
||||
// We use React.Children.forEach instead of React.Children.toArray().find()
|
||||
// here because toArray adds keys to all child elements and we do not want
|
||||
// to trigger an unmount/remount for two <Route>s that render the same
|
||||
// component at different URLs.
|
||||
React.Children.forEach(this.props.children, child => {
|
||||
if (match == null && React.isValidElement(child)) {
|
||||
element = child;
|
||||
|
||||
const path = child.props.path || child.props.from;
|
||||
|
||||
match = path
|
||||
? matchPath(location.pathname, { ...child.props, path })
|
||||
: context.match;
|
||||
}
|
||||
});
|
||||
|
||||
return match
|
||||
? React.cloneElement(element, { location, computedMatch: match })
|
||||
: null;
|
||||
}}
|
||||
</RouterContext.Consumer>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
Switch.propTypes = {
|
||||
children: PropTypes.node,
|
||||
location: PropTypes.object
|
||||
};
|
||||
|
||||
Switch.prototype.componentDidUpdate = function(prevProps) {
|
||||
warning(
|
||||
!(this.props.location && !prevProps.location),
|
||||
'<Switch> elements should not change from uncontrolled to controlled (or vice versa). You initially used no "location" prop and then provided one on a subsequent render.'
|
||||
);
|
||||
|
||||
warning(
|
||||
!(!this.props.location && prevProps.location),
|
||||
'<Switch> elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.'
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default Switch;
|
||||
8
node_modules/react-router/modules/createContext.js
generated
vendored
Normal file
8
node_modules/react-router/modules/createContext.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2019-present StringEpsilon <StringEpsilon@gmail.com>
|
||||
// Copyright (c) 2017-2019 James Kyle <me@thejameskyle.com>
|
||||
// https://github.com/StringEpsilon/mini-create-react-context
|
||||
import React from "react";
|
||||
import createReactContext from "./miniCreateReactContext";
|
||||
|
||||
export default React.createContext || createReactContext;
|
||||
11
node_modules/react-router/modules/createNamedContext.js
generated
vendored
Normal file
11
node_modules/react-router/modules/createNamedContext.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
// TODO: Replace with React.createContext once we can assume React 16+
|
||||
import createContext from "./createContext";
|
||||
|
||||
const createNamedContext = name => {
|
||||
const context = createContext();
|
||||
context.displayName = name;
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
export default createNamedContext;
|
||||
27
node_modules/react-router/modules/generatePath.js
generated
vendored
Normal file
27
node_modules/react-router/modules/generatePath.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import pathToRegexp from "path-to-regexp";
|
||||
|
||||
const cache = {};
|
||||
const cacheLimit = 10000;
|
||||
let cacheCount = 0;
|
||||
|
||||
function compilePath(path) {
|
||||
if (cache[path]) return cache[path];
|
||||
|
||||
const generator = pathToRegexp.compile(path);
|
||||
|
||||
if (cacheCount < cacheLimit) {
|
||||
cache[path] = generator;
|
||||
cacheCount++;
|
||||
}
|
||||
|
||||
return generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public API for generating a URL pathname from a path and parameters.
|
||||
*/
|
||||
function generatePath(path = "/", params = {}) {
|
||||
return path === "/" ? path : compilePath(path)(params, { pretty: true });
|
||||
}
|
||||
|
||||
export default generatePath;
|
||||
55
node_modules/react-router/modules/hooks.js
generated
vendored
Normal file
55
node_modules/react-router/modules/hooks.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import React from "react";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
import RouterContext from "./RouterContext.js";
|
||||
import HistoryContext from "./HistoryContext.js";
|
||||
import matchPath from "./matchPath.js";
|
||||
|
||||
const useContext = React.useContext;
|
||||
|
||||
export function useHistory() {
|
||||
if (__DEV__) {
|
||||
invariant(
|
||||
typeof useContext === "function",
|
||||
"You must use React >= 16.8 in order to use useHistory()"
|
||||
);
|
||||
}
|
||||
|
||||
return useContext(HistoryContext);
|
||||
}
|
||||
|
||||
export function useLocation() {
|
||||
if (__DEV__) {
|
||||
invariant(
|
||||
typeof useContext === "function",
|
||||
"You must use React >= 16.8 in order to use useLocation()"
|
||||
);
|
||||
}
|
||||
|
||||
return useContext(RouterContext).location;
|
||||
}
|
||||
|
||||
export function useParams() {
|
||||
if (__DEV__) {
|
||||
invariant(
|
||||
typeof useContext === "function",
|
||||
"You must use React >= 16.8 in order to use useParams()"
|
||||
);
|
||||
}
|
||||
|
||||
const match = useContext(RouterContext).match;
|
||||
return match ? match.params : {};
|
||||
}
|
||||
|
||||
export function useRouteMatch(path) {
|
||||
if (__DEV__) {
|
||||
invariant(
|
||||
typeof useContext === "function",
|
||||
"You must use React >= 16.8 in order to use useRouteMatch()"
|
||||
);
|
||||
}
|
||||
|
||||
const location = useLocation();
|
||||
const match = useContext(RouterContext).match;
|
||||
return path ? matchPath(location.pathname, path) : match;
|
||||
}
|
||||
38
node_modules/react-router/modules/index.js
generated
vendored
Normal file
38
node_modules/react-router/modules/index.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
if (__DEV__) {
|
||||
if (typeof window !== "undefined") {
|
||||
const global = window;
|
||||
const key = "__react_router_build__";
|
||||
const buildNames = { cjs: "CommonJS", esm: "ES modules", umd: "UMD" };
|
||||
|
||||
if (global[key] && global[key] !== process.env.BUILD_FORMAT) {
|
||||
const initialBuildName = buildNames[global[key]];
|
||||
const secondaryBuildName = buildNames[process.env.BUILD_FORMAT];
|
||||
|
||||
// TODO: Add link to article that explains in detail how to avoid
|
||||
// loading 2 different builds.
|
||||
throw new Error(
|
||||
`You are loading the ${secondaryBuildName} build of React Router ` +
|
||||
`on a page that is already running the ${initialBuildName} ` +
|
||||
`build, so things won't work right.`
|
||||
);
|
||||
}
|
||||
|
||||
global[key] = process.env.BUILD_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
export { default as MemoryRouter } from "./MemoryRouter.js";
|
||||
export { default as Prompt } from "./Prompt.js";
|
||||
export { default as Redirect } from "./Redirect.js";
|
||||
export { default as Route } from "./Route.js";
|
||||
export { default as Router } from "./Router.js";
|
||||
export { default as StaticRouter } from "./StaticRouter.js";
|
||||
export { default as Switch } from "./Switch.js";
|
||||
export { default as generatePath } from "./generatePath.js";
|
||||
export { default as matchPath } from "./matchPath.js";
|
||||
export { default as withRouter } from "./withRouter.js";
|
||||
|
||||
export { default as __HistoryContext } from "./HistoryContext.js";
|
||||
export { default as __RouterContext } from "./RouterContext.js";
|
||||
|
||||
export { useHistory, useLocation, useParams, useRouteMatch } from "./hooks.js";
|
||||
67
node_modules/react-router/modules/matchPath.js
generated
vendored
Normal file
67
node_modules/react-router/modules/matchPath.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
import pathToRegexp from "path-to-regexp";
|
||||
|
||||
const cache = {};
|
||||
const cacheLimit = 10000;
|
||||
let cacheCount = 0;
|
||||
|
||||
function compilePath(path, options) {
|
||||
const cacheKey = `${options.end}${options.strict}${options.sensitive}`;
|
||||
const pathCache = cache[cacheKey] || (cache[cacheKey] = {});
|
||||
|
||||
if (pathCache[path]) return pathCache[path];
|
||||
|
||||
const keys = [];
|
||||
const regexp = pathToRegexp(path, keys, options);
|
||||
const result = { regexp, keys };
|
||||
|
||||
if (cacheCount < cacheLimit) {
|
||||
pathCache[path] = result;
|
||||
cacheCount++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public API for matching a URL pathname to a path.
|
||||
*/
|
||||
function matchPath(pathname, options = {}) {
|
||||
if (typeof options === "string" || Array.isArray(options)) {
|
||||
options = { path: options };
|
||||
}
|
||||
|
||||
const { path, exact = false, strict = false, sensitive = false } = options;
|
||||
|
||||
const paths = [].concat(path);
|
||||
|
||||
return paths.reduce((matched, path) => {
|
||||
if (!path && path !== "") return null;
|
||||
if (matched) return matched;
|
||||
|
||||
const { regexp, keys } = compilePath(path, {
|
||||
end: exact,
|
||||
strict,
|
||||
sensitive
|
||||
});
|
||||
const match = regexp.exec(pathname);
|
||||
|
||||
if (!match) return null;
|
||||
|
||||
const [url, ...values] = match;
|
||||
const isExact = pathname === url;
|
||||
|
||||
if (exact && !isExact) return null;
|
||||
|
||||
return {
|
||||
path, // the path used to match
|
||||
url: path === "/" && url === "" ? "/" : url, // the matched portion of the URL
|
||||
isExact, // whether or not we matched exactly
|
||||
params: keys.reduce((memo, key, index) => {
|
||||
memo[key.name] = values[index];
|
||||
return memo;
|
||||
}, {})
|
||||
};
|
||||
}, null);
|
||||
}
|
||||
|
||||
export default matchPath;
|
||||
175
node_modules/react-router/modules/miniCreateReactContext.js
generated
vendored
Normal file
175
node_modules/react-router/modules/miniCreateReactContext.js
generated
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
// MIT License
|
||||
// Copyright (c) 2019-present StringEpsilon <StringEpsilon@gmail.com>
|
||||
// Copyright (c) 2017-2019 James Kyle <me@thejameskyle.com>
|
||||
// https://github.com/StringEpsilon/mini-create-react-context
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import warning from "tiny-warning";
|
||||
|
||||
const MAX_SIGNED_31_BIT_INT = 1073741823;
|
||||
|
||||
const commonjsGlobal =
|
||||
typeof globalThis !== "undefined" // 'global proper'
|
||||
? // eslint-disable-next-line no-undef
|
||||
globalThis
|
||||
: typeof window !== "undefined"
|
||||
? window // Browser
|
||||
: typeof global !== "undefined"
|
||||
? global // node.js
|
||||
: {};
|
||||
|
||||
function getUniqueId() {
|
||||
let key = "__global_unique_id__";
|
||||
return (commonjsGlobal[key] = (commonjsGlobal[key] || 0) + 1);
|
||||
}
|
||||
|
||||
// Inlined Object.is polyfill.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
||||
function objectIs(x, y) {
|
||||
if (x === y) {
|
||||
return x !== 0 || 1 / x === 1 / y;
|
||||
} else {
|
||||
// eslint-disable-next-line no-self-compare
|
||||
return x !== x && y !== y;
|
||||
}
|
||||
}
|
||||
|
||||
function createEventEmitter(value) {
|
||||
let handlers = [];
|
||||
return {
|
||||
on(handler) {
|
||||
handlers.push(handler);
|
||||
},
|
||||
|
||||
off(handler) {
|
||||
handlers = handlers.filter(h => h !== handler);
|
||||
},
|
||||
|
||||
get() {
|
||||
return value;
|
||||
},
|
||||
|
||||
set(newValue, changedBits) {
|
||||
value = newValue;
|
||||
handlers.forEach(handler => handler(value, changedBits));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function onlyChild(children) {
|
||||
return Array.isArray(children) ? children[0] : children;
|
||||
}
|
||||
|
||||
export default function createReactContext(defaultValue, calculateChangedBits) {
|
||||
const contextProp = "__create-react-context-" + getUniqueId() + "__";
|
||||
|
||||
class Provider extends React.Component {
|
||||
emitter = createEventEmitter(this.props.value);
|
||||
|
||||
static childContextTypes = {
|
||||
[contextProp]: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
getChildContext() {
|
||||
return {
|
||||
[contextProp]: this.emitter
|
||||
};
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (this.props.value !== nextProps.value) {
|
||||
let oldValue = this.props.value;
|
||||
let newValue = nextProps.value;
|
||||
let changedBits;
|
||||
|
||||
if (objectIs(oldValue, newValue)) {
|
||||
changedBits = 0; // No change
|
||||
} else {
|
||||
changedBits =
|
||||
typeof calculateChangedBits === "function"
|
||||
? calculateChangedBits(oldValue, newValue)
|
||||
: MAX_SIGNED_31_BIT_INT;
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
warning(
|
||||
(changedBits & MAX_SIGNED_31_BIT_INT) === changedBits,
|
||||
"calculateChangedBits: Expected the return value to be a " +
|
||||
"31-bit integer. Instead received: " +
|
||||
changedBits
|
||||
);
|
||||
}
|
||||
|
||||
changedBits |= 0;
|
||||
|
||||
if (changedBits !== 0) {
|
||||
this.emitter.set(nextProps.value, changedBits);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
class Consumer extends React.Component {
|
||||
static contextTypes = {
|
||||
[contextProp]: PropTypes.object
|
||||
};
|
||||
|
||||
observedBits;
|
||||
|
||||
state = {
|
||||
value: this.getValue()
|
||||
};
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
let { observedBits } = nextProps;
|
||||
this.observedBits =
|
||||
observedBits === undefined || observedBits === null
|
||||
? MAX_SIGNED_31_BIT_INT // Subscribe to all changes by default
|
||||
: observedBits;
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.context[contextProp]) {
|
||||
this.context[contextProp].on(this.onUpdate);
|
||||
}
|
||||
let { observedBits } = this.props;
|
||||
this.observedBits =
|
||||
observedBits === undefined || observedBits === null
|
||||
? MAX_SIGNED_31_BIT_INT // Subscribe to all changes by default
|
||||
: observedBits;
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.context[contextProp]) {
|
||||
this.context[contextProp].off(this.onUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
getValue() {
|
||||
if (this.context[contextProp]) {
|
||||
return this.context[contextProp].get();
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
onUpdate = (newValue, changedBits) => {
|
||||
const observedBits = this.observedBits | 0;
|
||||
if ((observedBits & changedBits) !== 0) {
|
||||
this.setState({ value: this.getValue() });
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return onlyChild(this.props.children)(this.state.value);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
Provider,
|
||||
Consumer
|
||||
};
|
||||
}
|
||||
51
node_modules/react-router/modules/withRouter.js
generated
vendored
Normal file
51
node_modules/react-router/modules/withRouter.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import hoistStatics from "hoist-non-react-statics";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
import RouterContext from "./RouterContext.js";
|
||||
|
||||
/**
|
||||
* A public higher-order component to access the imperative API
|
||||
*/
|
||||
function withRouter(Component) {
|
||||
const displayName = `withRouter(${Component.displayName || Component.name})`;
|
||||
const C = props => {
|
||||
const { wrappedComponentRef, ...remainingProps } = props;
|
||||
|
||||
return (
|
||||
<RouterContext.Consumer>
|
||||
{context => {
|
||||
invariant(
|
||||
context,
|
||||
`You should not use <${displayName} /> outside a <Router>`
|
||||
);
|
||||
return (
|
||||
<Component
|
||||
{...remainingProps}
|
||||
{...context}
|
||||
ref={wrappedComponentRef}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</RouterContext.Consumer>
|
||||
);
|
||||
};
|
||||
|
||||
C.displayName = displayName;
|
||||
C.WrappedComponent = Component;
|
||||
|
||||
if (__DEV__) {
|
||||
C.propTypes = {
|
||||
wrappedComponentRef: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.object
|
||||
])
|
||||
};
|
||||
}
|
||||
|
||||
return hoistStatics(C, Component);
|
||||
}
|
||||
|
||||
export default withRouter;
|
||||
Reference in New Issue
Block a user