@breautek/router 3.0.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.legacy.md +206 -0
- package/CHANGELOG.md +11 -197
- package/dist/router.js +985 -1808
- package/dist/src/DefaultStrategy.d.ts +5 -5
- package/dist/src/HashStrategy.d.ts +28 -28
- package/dist/src/IOnNoRoute.d.ts +4 -4
- package/dist/src/IRouterStrategyClass.d.ts +8 -8
- package/dist/src/IViewStylesheet.d.ts +4 -4
- package/dist/src/Route.d.ts +33 -33
- package/dist/src/RouteMatcher.d.ts +30 -31
- package/dist/src/Router.d.ts +89 -85
- package/dist/src/RouterStrategy.d.ts +138 -117
- package/dist/src/TransitionSlide.d.ts +17 -17
- package/dist/src/TransitionStrategy.d.ts +21 -21
- package/dist/src/URLParser.d.ts +39 -39
- package/dist/src/URLStrategy.d.ts +32 -32
- package/dist/src/View.d.ts +48 -49
- package/dist/src/api.d.ts +13 -14
- package/package.json +30 -46
- package/src/HashStrategy.ts +1 -1
- package/src/RouteMatcher.ts +0 -2
- package/src/Router.tsx +5 -2
- package/src/RouterStrategy.ts +53 -0
- package/src/URLStrategy.ts +1 -0
- package/src/View.tsx +3 -3
- package/src/api.ts +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@breautek/router",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "An alternate react router.",
|
|
5
5
|
"main": "dist/router.js",
|
|
6
6
|
"types": "dist/src/api.d.ts",
|
|
@@ -11,12 +11,10 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "jest",
|
|
13
13
|
"lint": "eslint --ext .ts,.tsx '?(src|spec)/**/*.?(ts|tsx)' --cache",
|
|
14
|
-
"build": "rollup -c rollup.config.js",
|
|
14
|
+
"build": "rollup -c rollup.config.js --bundleConfigAsCjs",
|
|
15
15
|
"publish-beta": "npm publish --tag beta",
|
|
16
16
|
"prepublishOnly": "npm run build",
|
|
17
|
-
"
|
|
18
|
-
"docs": "typedoc --excludePrivate --includeVersion -readme ./README.md --out ./docs ./src/api.ts",
|
|
19
|
-
"version": "npm run-script build && npm run-script docs && npm run changelog && git add CHANGELOG.md docs && git commit -m 'chore: changelog'",
|
|
17
|
+
"version": "npm run-script build",
|
|
20
18
|
"postversion": "git push && git push --tags"
|
|
21
19
|
},
|
|
22
20
|
"repository": {
|
|
@@ -34,50 +32,36 @@
|
|
|
34
32
|
"license": "MIT",
|
|
35
33
|
"homepage": "https://github.com/breautek/router",
|
|
36
34
|
"peerDependencies": {
|
|
37
|
-
"react": "
|
|
38
|
-
"react-dom": "
|
|
35
|
+
"react": "16.x || 17.x || 18.x",
|
|
36
|
+
"react-dom": "16.x || 17.x || 18.x"
|
|
39
37
|
},
|
|
40
38
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"@types/react-dom": "16.9.11",
|
|
56
|
-
"@types/react-test-renderer": "17.0.1",
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "5.29.0",
|
|
58
|
-
"@typescript-eslint/parser": "5.29.0",
|
|
59
|
-
"ajv": "8.11.0",
|
|
60
|
-
"auto-changelog": "2.4.0",
|
|
61
|
-
"babel-jest": "27.5.1",
|
|
62
|
-
"enzyme": "3.11.0",
|
|
63
|
-
"enzyme-adapter-react-16": "1.15.6",
|
|
64
|
-
"eslint": "8.18.0",
|
|
65
|
-
"eslint-plugin-react": "7.30.0",
|
|
66
|
-
"glob": "8.0.3",
|
|
39
|
+
"@rollup/plugin-commonjs": "25.0.3",
|
|
40
|
+
"@rollup/plugin-json": "6.0.0",
|
|
41
|
+
"@rollup/plugin-node-resolve": "15.1.0",
|
|
42
|
+
"@testing-library/jest-dom": "5.16.5",
|
|
43
|
+
"@testing-library/react": "14.0.0",
|
|
44
|
+
"@types/jest": "29.5.3",
|
|
45
|
+
"@types/react": "18.2.15",
|
|
46
|
+
"@types/react-dom": "18.2.7",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "6.1.0",
|
|
48
|
+
"@typescript-eslint/parser": "6.1.0",
|
|
49
|
+
"ajv": "8.12.0",
|
|
50
|
+
"eslint": "8.45.0",
|
|
51
|
+
"eslint-plugin-react": "7.32.2",
|
|
52
|
+
"glob": "10.3.3",
|
|
67
53
|
"ignore-styles": "5.0.1",
|
|
68
|
-
"jest": "
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"react
|
|
72
|
-
"
|
|
73
|
-
"rollup": "
|
|
54
|
+
"jest": "29.6.1",
|
|
55
|
+
"jest-environment-jsdom": "29.6.1",
|
|
56
|
+
"node-sass": "9.0.0",
|
|
57
|
+
"react": "18.2.0",
|
|
58
|
+
"react-dom": "18.2.0",
|
|
59
|
+
"rollup": "3.26.3",
|
|
74
60
|
"rollup-plugin-progress": "1.1.2",
|
|
75
|
-
"rollup-plugin-sass": "1.
|
|
76
|
-
"rollup-plugin-typescript2": "0.
|
|
77
|
-
"ts-jest": "
|
|
78
|
-
"ts-node": "10.
|
|
79
|
-
"
|
|
80
|
-
"typedoc-plugin-markdown": "3.12.1",
|
|
81
|
-
"typescript": "4.6.4"
|
|
61
|
+
"rollup-plugin-sass": "1.12.19",
|
|
62
|
+
"rollup-plugin-typescript2": "0.35.0",
|
|
63
|
+
"ts-jest": "29.1.1",
|
|
64
|
+
"ts-node": "10.9.1",
|
|
65
|
+
"typescript": "5.1.6"
|
|
82
66
|
}
|
|
83
67
|
}
|
package/src/HashStrategy.ts
CHANGED
|
@@ -20,7 +20,7 @@ export class HashStrategy extends RouterStrategy {
|
|
|
20
20
|
this.$base = '#';
|
|
21
21
|
this.$stack = [];
|
|
22
22
|
this.$position = -1;
|
|
23
|
-
this.$lastFiredLocation = null;
|
|
23
|
+
this.$lastFiredLocation = null;
|
|
24
24
|
|
|
25
25
|
window.addEventListener('popstate', (ev: PopStateEvent) => {
|
|
26
26
|
let location = this.getLocation();
|
package/src/RouteMatcher.ts
CHANGED
package/src/Router.tsx
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
import "regenerator-runtime/runtime";
|
|
3
|
-
|
|
4
2
|
import * as React from 'react';
|
|
5
3
|
|
|
6
4
|
import {DefaultStrategy} from './DefaultStrategy';
|
|
@@ -13,6 +11,7 @@ import { Route } from "./Route";
|
|
|
13
11
|
export interface IRouterProps {
|
|
14
12
|
strategy?: IRouterStrategyClass;
|
|
15
13
|
component: React.ComponentClass<any>;
|
|
14
|
+
children?: React.ReactNode;
|
|
16
15
|
onNoRoute?: IOnNoRoute;
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -275,6 +274,10 @@ export class Router<TRouterProps extends IRouterProps = IRouterProps> extends Re
|
|
|
275
274
|
}
|
|
276
275
|
}
|
|
277
276
|
|
|
277
|
+
/**
|
|
278
|
+
* @deprecated Use Router.getInstance() instead.
|
|
279
|
+
* @returns {RouterStrategy}
|
|
280
|
+
*/
|
|
278
281
|
export let getRouter = (): RouterStrategy => {
|
|
279
282
|
console.warn('getRouter() is deprecated. use Router.getInstance() instead.');
|
|
280
283
|
return Router.getInstance();
|
package/src/RouterStrategy.ts
CHANGED
|
@@ -1,16 +1,69 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import { Router } from './Router';
|
|
3
|
+
import {View} from './View';
|
|
3
4
|
|
|
4
5
|
export const EVENT_URL_CHANGE: string = 'urlchange';
|
|
5
6
|
|
|
6
7
|
export type URLChangeCallback = (url: string) => void;
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Invoked when the view's componentDidMount/componentWillUnmount fires.
|
|
11
|
+
*/
|
|
12
|
+
export type ViewMountChangeCallback = (view: View) => void;
|
|
13
|
+
|
|
8
14
|
export abstract class RouterStrategy extends EventEmitter {
|
|
9
15
|
private $router: Router;
|
|
10
16
|
|
|
17
|
+
private $viewMountListeners: ViewMountChangeCallback[];
|
|
18
|
+
private $viewUnmountListneners: ViewMountChangeCallback[];
|
|
19
|
+
|
|
11
20
|
public constructor(router: Router) {
|
|
12
21
|
super();
|
|
13
22
|
this.$router = router;
|
|
23
|
+
this.$viewMountListeners = [];
|
|
24
|
+
this.$viewUnmountListneners = [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public addViewMountCallback(cb: ViewMountChangeCallback): void {
|
|
28
|
+
this.$viewMountListeners.push(cb);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public removeViewMountCallback(cb: ViewMountChangeCallback): void {
|
|
32
|
+
let idx: number = this.$viewMountListeners.indexOf(cb);
|
|
33
|
+
if (idx > -1) {
|
|
34
|
+
this.$viewMountListeners.splice(idx, 1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public addViewUnmountCallback(cb: ViewMountChangeCallback): void {
|
|
39
|
+
this.$viewUnmountListneners.push(cb);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public removeViewUnmountCallback(cb: ViewMountChangeCallback): void {
|
|
43
|
+
let idx: number = this.$viewUnmountListneners.indexOf(cb);
|
|
44
|
+
if (idx > -1) {
|
|
45
|
+
this.$viewUnmountListneners.splice(idx, 1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
* @param view
|
|
52
|
+
*/
|
|
53
|
+
public __onViewMount(view: View): void {
|
|
54
|
+
for (let i: number = 0; i < this.$viewMountListeners.length; i++) {
|
|
55
|
+
this.$viewMountListeners[i](view);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
* @param view
|
|
62
|
+
*/
|
|
63
|
+
public __onViewUnmount(view: View): void {
|
|
64
|
+
for (let i: number = 0; i < this.$viewUnmountListneners.length; i++) {
|
|
65
|
+
this.$viewUnmountListneners[i](view);
|
|
66
|
+
}
|
|
14
67
|
}
|
|
15
68
|
|
|
16
69
|
/**
|
package/src/URLStrategy.ts
CHANGED
package/src/View.tsx
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import "regenerator-runtime/runtime";
|
|
3
|
-
|
|
4
2
|
import * as React from 'react';
|
|
5
|
-
|
|
6
3
|
import { RouterStrategy } from './RouterStrategy';
|
|
7
4
|
import { TransitionStrategy } from './TransitionStrategy';
|
|
8
5
|
import { IViewStylesheet } from './IViewStylesheet';
|
|
@@ -52,6 +49,8 @@ export abstract class View<TPageProps extends IViewProps = IViewProps> extends R
|
|
|
52
49
|
if (stylesheet) {
|
|
53
50
|
stylesheet.use();
|
|
54
51
|
}
|
|
52
|
+
|
|
53
|
+
this.props.router.__onViewMount(this);
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
/**
|
|
@@ -62,6 +61,7 @@ export abstract class View<TPageProps extends IViewProps = IViewProps> extends R
|
|
|
62
61
|
if (stylesheet) {
|
|
63
62
|
stylesheet.unuse();
|
|
64
63
|
}
|
|
64
|
+
this.props.router.__onViewUnmount(this);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|