Skip to content

Commit c2c0fd5

Browse files
committed
packages updated
1 parent 535aeaa commit c2c0fd5

File tree

18 files changed

+417
-373
lines changed

18 files changed

+417
-373
lines changed

dist.es2015/context.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from 'react';
2+
export interface Params {
3+
[key: string]: string;
4+
}
5+
export interface PathMatch {
6+
match?: RegExpExecArray | null;
7+
params?: Params;
8+
nextPath?: string;
9+
}
10+
export interface RouterContext {
11+
match?: (path: string) => PathMatch;
12+
navigate?: (path: string, data?: any, replace?: boolean) => void;
13+
getCurrentPath?: () => string;
14+
}
15+
export interface RouteContext {
16+
path?: string;
17+
params?: Params;
18+
matches?: PathMatch[];
19+
error?: Error;
20+
}
21+
export declare const RouteContext: React.Context<RouteContext>;
22+
export declare const RouterContext: React.Context<RouterContext>;

dist.es2015/context.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import * as React from 'react';
2-
export var RouteContext = React.createContext({});
3-
export var RouterContext = React.createContext({});
1+
import * as React from 'react';
2+
export var RouteContext = React.createContext({});
3+
export var RouterContext = React.createContext({});

dist.es2015/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './route';
2+
export { default as Route } from './route';
3+
export * from './router';
4+
export { default as Router } from './router';
5+
export * from './context';

dist.es2015/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * from './route';
2-
export { default as Route } from './route';
3-
export * from './router';
4-
export { default as Router } from './router';
5-
export * from './context';
1+
export * from './route';
2+
export { default as Route } from './route';
3+
export * from './router';
4+
export { default as Router } from './router';
5+
export * from './context';

dist.es2015/route.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as React from 'react';
2+
import { FallbackProps } from 'react-error-boundary';
3+
import { RouteContext } from './context';
4+
export interface RouteProps extends React.PropsWithChildren {
5+
path?: string;
6+
error?: React.ComponentType<FallbackProps>;
7+
}
8+
export default function Route({ children, path, error }: RouteProps): React.FunctionComponentElement<React.ProviderProps<RouteContext>> | null;

dist.es2015/route.js

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
var __assign = (this && this.__assign) || function () {
2-
__assign = Object.assign || function(t) {
3-
for (var s, i = 1, n = arguments.length; i < n; i++) {
4-
s = arguments[i];
5-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6-
t[p] = s[p];
7-
}
8-
return t;
9-
};
10-
return __assign.apply(this, arguments);
11-
};
12-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14-
if (ar || !(i in from)) {
15-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16-
ar[i] = from[i];
17-
}
18-
}
19-
return to.concat(ar || Array.prototype.slice.call(from));
20-
};
21-
import * as React from 'react';
22-
import { ErrorBoundary } from 'react-error-boundary';
23-
import { RouteContext, RouterContext } from './context';
24-
export default function Route(_a) {
25-
var _b;
26-
var children = _a.children, path = _a.path, error = _a.error;
27-
var router = React.useContext(RouterContext);
28-
var route = React.useContext(RouteContext);
29-
if (!router.match) {
30-
throw new Error('Route requires a match function in the Router context');
31-
}
32-
var routeParams = {};
33-
var routePath = (route.path || '') + (path || '');
34-
if (path) {
35-
var _c = router.match(routePath), match = _c.match, params = _c.params, nextPath = _c.nextPath;
36-
if (!match) {
37-
return null;
38-
}
39-
routeParams = params;
40-
routePath = nextPath;
41-
if (!route.matches) {
42-
route.matches = [];
43-
}
44-
route.matches.push({ match: match, params: params, nextPath: nextPath });
45-
}
46-
else {
47-
if (((_b = route.matches) === null || _b === void 0 ? void 0 : _b.length) || route.error) {
48-
return null;
49-
}
50-
}
51-
var childRoute = __assign(__assign({}, route), { path: routePath, params: routeParams, matches: [] });
52-
var props = { value: childRoute };
53-
if (Array.isArray(children)) {
54-
if (error) {
55-
return React.createElement(RouteContext.Provider, props, React.createElement.apply(React, __spreadArray([ErrorBoundary, { FallbackComponent: error }], children, false)));
56-
}
57-
return React.createElement.apply(React, __spreadArray([RouteContext.Provider, props], children, false));
58-
}
59-
if (error) {
60-
return React.createElement(RouteContext.Provider, props, React.createElement(ErrorBoundary, { FallbackComponent: error }, children));
61-
}
62-
return React.createElement(RouteContext.Provider, props, children);
63-
}
1+
var __assign = (this && this.__assign) || function () {
2+
__assign = Object.assign || function(t) {
3+
for (var s, i = 1, n = arguments.length; i < n; i++) {
4+
s = arguments[i];
5+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6+
t[p] = s[p];
7+
}
8+
return t;
9+
};
10+
return __assign.apply(this, arguments);
11+
};
12+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14+
if (ar || !(i in from)) {
15+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16+
ar[i] = from[i];
17+
}
18+
}
19+
return to.concat(ar || Array.prototype.slice.call(from));
20+
};
21+
import * as React from 'react';
22+
import { ErrorBoundary } from 'react-error-boundary';
23+
import { RouteContext, RouterContext } from './context';
24+
export default function Route(_a) {
25+
var _b;
26+
var children = _a.children, path = _a.path, error = _a.error;
27+
var router = React.useContext(RouterContext);
28+
var route = React.useContext(RouteContext);
29+
if (!router.match) {
30+
throw new Error('Route requires a match function in the Router context');
31+
}
32+
var routeParams = {};
33+
var routePath = (route.path || '') + (path || '');
34+
if (path) {
35+
var _c = router.match(routePath), match = _c.match, params = _c.params, nextPath = _c.nextPath;
36+
if (!match) {
37+
return null;
38+
}
39+
routeParams = params;
40+
routePath = nextPath;
41+
if (!route.matches) {
42+
route.matches = [];
43+
}
44+
route.matches.push({ match: match, params: params, nextPath: nextPath });
45+
}
46+
else {
47+
if (((_b = route.matches) === null || _b === void 0 ? void 0 : _b.length) || route.error) {
48+
return null;
49+
}
50+
}
51+
var childRoute = __assign(__assign({}, route), { path: routePath, params: routeParams, matches: [] });
52+
var props = { value: childRoute };
53+
if (Array.isArray(children)) {
54+
if (error) {
55+
return React.createElement(RouteContext.Provider, props, React.createElement.apply(React, __spreadArray([ErrorBoundary, { FallbackComponent: error }], children, false)));
56+
}
57+
return React.createElement.apply(React, __spreadArray([RouteContext.Provider, props], children, false));
58+
}
59+
if (error) {
60+
return React.createElement(RouteContext.Provider, props, React.createElement(ErrorBoundary, { FallbackComponent: error }, children));
61+
}
62+
return React.createElement(RouteContext.Provider, props, children);
63+
}

dist.es2015/router.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as React from 'react';
2+
import { RouterContext, PathMatch } from './context';
3+
export interface RouterProps extends React.PropsWithChildren {
4+
navigate?: (path: string, data?: any, replace?: boolean) => void;
5+
match?: (path: string) => PathMatch;
6+
changeEvent?: string;
7+
getCurrentPath?: () => string;
8+
}
9+
export default function Router(props: RouterProps): React.FunctionComponentElement<React.ProviderProps<RouterContext>> | null;

dist.es2015/router.js

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
1-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3-
if (ar || !(i in from)) {
4-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5-
ar[i] = from[i];
6-
}
7-
}
8-
return to.concat(ar || Array.prototype.slice.call(from));
9-
};
10-
import * as React from 'react';
11-
import { tokensToRegexp, parse } from 'path-to-regexp';
12-
import { RouterContext, RouteContext } from './context';
13-
var defChangeEvent = 'popstate';
14-
function defGetCurrentPath() {
15-
return window.location.pathname;
16-
}
17-
function defMatch(path) {
18-
var _a;
19-
var keys = [];
20-
var tokens = parse(path);
21-
var pattern = tokensToRegexp(tokens, keys);
22-
var pathname = defGetCurrentPath();
23-
var match = pattern.exec(pathname);
24-
if (!match) {
25-
return {};
26-
}
27-
var params = {};
28-
for (var i = 1; i < match.length; i++) {
29-
params[keys[i - 1]['name']] = match[i];
30-
}
31-
var nextPath = '';
32-
if (typeof tokens[0] === 'string') {
33-
nextPath = ((_a = tokens[1]) === null || _a === void 0 ? void 0 : _a.prefix) ? tokens[0] + tokens[1].prefix : tokens[0];
34-
}
35-
else {
36-
nextPath = tokens[0].prefix || '';
37-
}
38-
return { match: match, params: params, nextPath: nextPath };
39-
}
40-
function defNavigate(path, data, replace) {
41-
if (replace) {
42-
window.history.replaceState(data, '', path);
43-
}
44-
else {
45-
window.history.pushState(data, '', path);
46-
}
47-
}
48-
export default function Router(props) {
49-
var children = props.children, _a = props.navigate, n = _a === void 0 ? defNavigate : _a, _b = props.match, m = _b === void 0 ? defMatch : _b, _c = props.changeEvent, c = _c === void 0 ? defChangeEvent : _c, _d = props.getCurrentPath, g = _d === void 0 ? defGetCurrentPath : _d;
50-
var _e = React.useState(g()), path = _e[0], setPath = _e[1];
51-
React.useEffect(function () {
52-
if (!c) {
53-
return;
54-
}
55-
var eventHandler = function () { return setPath(g()); };
56-
window.addEventListener(c, eventHandler);
57-
return function () { return window.removeEventListener(c, eventHandler); };
58-
}, [c, g, setPath]);
59-
if (!children) {
60-
return null;
61-
}
62-
var routerProps = {
63-
value: {
64-
match: m,
65-
navigate: function (p, data, replace) {
66-
n(p, data, replace);
67-
setPath(g());
68-
},
69-
getCurrentPath: g,
70-
}
71-
};
72-
var baseRouteProps = { value: {} };
73-
var routeProvider = Array.isArray(children)
74-
? React.createElement.apply(React, __spreadArray([RouteContext.Provider, baseRouteProps], children, false)) : React.createElement(RouteContext.Provider, baseRouteProps, children);
75-
return React.createElement(RouterContext.Provider, routerProps, routeProvider);
76-
}
1+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3+
if (ar || !(i in from)) {
4+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5+
ar[i] = from[i];
6+
}
7+
}
8+
return to.concat(ar || Array.prototype.slice.call(from));
9+
};
10+
import * as React from 'react';
11+
import { tokensToRegexp, parse } from 'path-to-regexp';
12+
import { RouterContext, RouteContext } from './context';
13+
var defChangeEvent = 'popstate';
14+
function defGetCurrentPath() {
15+
return window.location.pathname;
16+
}
17+
function defMatch(path) {
18+
var _a;
19+
var keys = [];
20+
var tokens = parse(path);
21+
var pattern = tokensToRegexp(tokens, keys);
22+
var pathname = defGetCurrentPath();
23+
var match = pattern.exec(pathname);
24+
if (!match) {
25+
return {};
26+
}
27+
var params = {};
28+
for (var i = 1; i < match.length; i++) {
29+
params[keys[i - 1]['name']] = match[i];
30+
}
31+
var nextPath = '';
32+
if (typeof tokens[0] === 'string') {
33+
nextPath = ((_a = tokens[1]) === null || _a === void 0 ? void 0 : _a.prefix) ? tokens[0] + tokens[1].prefix : tokens[0];
34+
}
35+
else {
36+
nextPath = tokens[0].prefix || '';
37+
}
38+
return { match: match, params: params, nextPath: nextPath };
39+
}
40+
function defNavigate(path, data, replace) {
41+
if (replace) {
42+
window.history.replaceState(data, '', path);
43+
}
44+
else {
45+
window.history.pushState(data, '', path);
46+
}
47+
}
48+
export default function Router(props) {
49+
var children = props.children, _a = props.navigate, n = _a === void 0 ? defNavigate : _a, _b = props.match, m = _b === void 0 ? defMatch : _b, _c = props.changeEvent, c = _c === void 0 ? defChangeEvent : _c, _d = props.getCurrentPath, g = _d === void 0 ? defGetCurrentPath : _d;
50+
var _e = React.useState(g()), path = _e[0], setPath = _e[1];
51+
React.useEffect(function () {
52+
if (!c) {
53+
return;
54+
}
55+
var eventHandler = function () { return setPath(g()); };
56+
window.addEventListener(c, eventHandler);
57+
return function () { return window.removeEventListener(c, eventHandler); };
58+
}, [c, g, setPath]);
59+
if (!children) {
60+
return null;
61+
}
62+
var routerProps = {
63+
value: {
64+
match: m,
65+
navigate: function (p, data, replace) {
66+
n(p, data, replace);
67+
setPath(g());
68+
},
69+
getCurrentPath: g,
70+
}
71+
};
72+
var baseRouteProps = { value: {} };
73+
var routeProvider = Array.isArray(children)
74+
? React.createElement.apply(React, __spreadArray([RouteContext.Provider, baseRouteProps], children, false)) : React.createElement(RouteContext.Provider, baseRouteProps, children);
75+
return React.createElement(RouterContext.Provider, routerProps, routeProvider);
76+
}

dist/context.d.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import * as React from 'react';
2-
export interface Params {
3-
[key: string]: string;
4-
}
5-
export interface PathMatch {
6-
match?: RegExpExecArray | null;
7-
params?: Params;
8-
nextPath?: string;
9-
}
10-
export interface RouterContext {
11-
match?: (path: string) => PathMatch;
12-
navigate?: (path: string, data?: any, replace?: boolean) => void;
13-
getCurrentPath?: () => string;
14-
}
15-
export interface RouteContext {
16-
path?: string;
17-
params?: Params;
18-
matches?: PathMatch[];
19-
error?: Error;
20-
}
21-
export declare const RouteContext: React.Context<RouteContext>;
22-
export declare const RouterContext: React.Context<RouterContext>;
1+
import * as React from 'react';
2+
export interface Params {
3+
[key: string]: string;
4+
}
5+
export interface PathMatch {
6+
match?: RegExpExecArray | null;
7+
params?: Params;
8+
nextPath?: string;
9+
}
10+
export interface RouterContext {
11+
match?: (path: string) => PathMatch;
12+
navigate?: (path: string, data?: any, replace?: boolean) => void;
13+
getCurrentPath?: () => string;
14+
}
15+
export interface RouteContext {
16+
path?: string;
17+
params?: Params;
18+
matches?: PathMatch[];
19+
error?: Error;
20+
}
21+
export declare const RouteContext: React.Context<RouteContext>;
22+
export declare const RouterContext: React.Context<RouterContext>;

0 commit comments

Comments
 (0)