@breautek/router 3.0.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breautek/router",
3
- "version": "3.0.0",
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
- "changelog": "auto-changelog --output CHANGELOG.md -p --release-summary --ignore-commit-pattern chore",
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": ">=16.9.0 <17.0.0",
38
- "react-dom": ">=16.9.0 <17.0.0"
35
+ "react": "16.x || 17.x || 18.x",
36
+ "react-dom": "16.x || 17.x || 18.x"
39
37
  },
40
38
  "devDependencies": {
41
- "@babel/core": "7.18.5",
42
- "@babel/plugin-syntax-dynamic-import": "7.8.3",
43
- "@babel/preset-env": "7.18.2",
44
- "@babel/preset-react": "7.17.12",
45
- "@babel/preset-typescript": "7.17.12",
46
- "@babel/register": "7.17.7",
47
- "@rollup/plugin-babel": "5.3.1",
48
- "@rollup/plugin-commonjs": "22.0.0",
49
- "@rollup/plugin-json": "4.1.0",
50
- "@rollup/plugin-node-resolve": "13.3.0",
51
- "@types/enzyme": "3.10.12",
52
- "@types/enzyme-adapter-react-16": "1.0.6",
53
- "@types/jest": "27.5.1",
54
- "@types/react": "16.14.4",
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": "27.5.1",
69
- "node-sass": "7.0.1",
70
- "react": "16.14.0",
71
- "react-dom": "16.14.0",
72
- "regenerator-runtime": "0.13.9",
73
- "rollup": "2.75.7",
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.2.12",
76
- "rollup-plugin-typescript2": "0.32.1",
77
- "ts-jest": "27.1.3",
78
- "ts-node": "10.8.1",
79
- "typedoc": "0.22.17",
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
  }
@@ -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; //this.getLocation();
23
+ this.$lastFiredLocation = null;
24
24
 
25
25
  window.addEventListener('popstate', (ev: PopStateEvent) => {
26
26
  let location = this.getLocation();
@@ -1,6 +1,4 @@
1
1
 
2
- import "regenerator-runtime/runtime";
3
-
4
2
  import {URLParser, IURLParams} from './URLParser';
5
3
  import {cloneElement} from 'react';
6
4
  import {IComponentProps, IRouteProps} from './Route';
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();
@@ -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
  /**
@@ -119,6 +119,7 @@ export class URLStrategy extends RouterStrategy {
119
119
  else {
120
120
  window.history.pushState({}, null, this.$base + url);
121
121
  }
122
+
122
123
  this._fireURLChange(this.getLocation());
123
124
  }
124
125
  }
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
  /**
package/src/api.ts CHANGED
@@ -1,6 +1,4 @@
1
1
 
2
- import "regenerator-runtime/runtime";
3
-
4
2
  export * from './Router';
5
3
  export * from './DefaultStrategy';
6
4
  export * from './HashStrategy';