@breautek/router 5.0.0-beta.0 → 5.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/dist/router.js CHANGED
@@ -375,19 +375,17 @@ class RouteMatcher {
375
375
  }
376
376
  let props = {
377
377
  url: url,
378
- base: base + componentToRender.props.url,
379
- matcher: this,
378
+ __base: base + componentToRender.props.url,
379
+ __matcher: this,
380
380
  component: componentToRender.props.component,
381
381
  entryTransition: componentToRender.props.entryTransition,
382
382
  exitTransition: componentToRender.props.exitTransition,
383
- componentProps: {
384
- url: url,
385
- router: this.$strategy
386
- }
383
+ componentProps: componentToRender.props.componentProps,
384
+ __componentProps: Object.assign(Object.assign({}, componentToRender.props.componentProps), { url: url, router: this.$strategy })
387
385
  };
388
386
  if (params) {
389
387
  for (let i in params) {
390
- props.componentProps[i] = params[i];
388
+ props.__componentProps[i] = params[i];
391
389
  }
392
390
  }
393
391
  return React.cloneElement(componentToRender, props);
@@ -502,7 +500,7 @@ class Router extends React__namespace.Component {
502
500
  // currentRoute must be rendered as an array; because, exiting and incoming is rendered as an array.
503
501
  // if currentRoute is not rendered as an array, a bug happens where the exiting screen is reloaded
504
502
  // calling the constructor again.
505
- return React__namespace.createElement(Root, { router: this.getRouterStrategy(), url: this.state.url }, [currentRoute]);
503
+ return React__namespace.createElement(Root, Object.assign({}, this.props.componentProps, { router: this.getRouterStrategy(), url: this.state.url }), [currentRoute]);
506
504
  }
507
505
  else {
508
506
  return currentRoute;
@@ -604,14 +602,6 @@ class Router extends React__namespace.Component {
604
602
  return null;
605
603
  }
606
604
  }
607
- /**
608
- * @deprecated Use Router.getInstance() instead.
609
- * @returns {RouterStrategy}
610
- */
611
- let getRouter = () => {
612
- console.warn('getRouter() is deprecated. use Router.getInstance() instead.');
613
- return Router.getInstance();
614
- };
615
605
 
616
606
  /**
617
607
  * @notice Using the URLStrategy requires some backend configuration
@@ -759,6 +749,7 @@ class View extends React__namespace.Component {
759
749
  constructor(props) {
760
750
  super(props);
761
751
  this.$node = null;
752
+ this.state = this._initState();
762
753
  }
763
754
  /**
764
755
  * Return the CSS class on this view
@@ -842,15 +833,15 @@ class Route extends React__namespace.Component {
842
833
  }
843
834
  $getComponentsToRender(component) {
844
835
  let url = component.props.url;
845
- let base = component.props.base || '';
836
+ let base = component.props.__base || '';
846
837
  // eslint-disable-next-line @typescript-eslint/naming-convention
847
838
  let ViewComponent = component.props.component;
848
839
  let child;
849
- let routeComponent = component.props.matcher.match(url, this.$getChildren(component), base);
840
+ let routeComponent = component.props.__matcher.match(url, this.$getChildren(component), base);
850
841
  if (routeComponent) {
851
842
  child = this.$getComponentsToRender(routeComponent);
852
843
  }
853
- return (React__namespace.createElement(ViewComponent, Object.assign({}, component.props.componentProps, { ref: (node) => {
844
+ return (React__namespace.createElement(ViewComponent, Object.assign({}, component.props.componentProps, component.props.__componentProps, { ref: (node) => {
854
845
  if (node) {
855
846
  if (node instanceof View) {
856
847
  this.$node = node;
@@ -1019,7 +1010,7 @@ class TransitionSlide extends TransitionStrategy {
1019
1010
  }
1020
1011
  }
1021
1012
 
1022
- var version = "5.0.0-beta.0";
1013
+ var version = "5.0.0";
1023
1014
  var packageInfo = {
1024
1015
  version: version};
1025
1016
 
@@ -1036,6 +1027,5 @@ exports.TransitionSlide = TransitionSlide;
1036
1027
  exports.TransitionStrategy = TransitionStrategy;
1037
1028
  exports.URLStrategy = URLStrategy;
1038
1029
  exports.View = View;
1039
- exports.getRouter = getRouter;
1040
1030
  exports.version = VERSION;
1041
1031
  //# sourceMappingURL=router.js.map
@@ -3,26 +3,27 @@ import { View } from './View';
3
3
  import { RouteMatcher } from './RouteMatcher';
4
4
  import { RouterStrategy } from './RouterStrategy';
5
5
  import { TransitionStrategy } from './TransitionStrategy';
6
- export interface IRouteProps<T extends IComponentProps = IComponentProps> {
6
+ export interface IRouteProps<TUserProps = any, TInternalProps extends IComponentProps = IComponentProps> {
7
7
  url: string;
8
8
  component: React.ComponentClass<any>;
9
9
  index?: boolean;
10
10
  entryTransition?: TransitionStrategy;
11
11
  exitTransition?: TransitionStrategy;
12
12
  children?: React.ReactElement<IRouteProps> | React.ReactElement<IRouteProps>[];
13
+ componentProps?: TUserProps;
13
14
  ref?: React.Ref<Route>;
14
15
  /**
15
16
  * @internal
16
17
  */
17
- base?: string;
18
+ __base?: string;
18
19
  /**
19
20
  * @internal
20
21
  */
21
- componentProps?: T;
22
+ __componentProps?: TInternalProps;
22
23
  /**
23
24
  * @internal
24
25
  */
25
- matcher?: RouteMatcher;
26
+ __matcher?: RouteMatcher;
26
27
  }
27
28
  export interface IComponentProps {
28
29
  url: string;
@@ -2,9 +2,10 @@ import * as React from 'react';
2
2
  import { RouterStrategy } from './RouterStrategy';
3
3
  import { IRouterStrategyClass } from './IRouterStrategyClass';
4
4
  import { IOnNoRoute } from './IOnNoRoute';
5
- export interface IRouterProps {
5
+ export interface IRouterProps<T = any> {
6
6
  strategy?: IRouterStrategyClass;
7
7
  component: React.ComponentClass<any>;
8
+ componentProps?: T;
8
9
  children?: React.ReactNode;
9
10
  onNoRoute?: IOnNoRoute;
10
11
  }
@@ -13,7 +14,7 @@ export interface IRouterState {
13
14
  url: string;
14
15
  shouldTransition: boolean;
15
16
  }
16
- export declare class Router<TRouterProps extends IRouterProps = IRouterProps> extends React.Component<TRouterProps, IRouterState> {
17
+ export declare class Router<TUserProps = any, TRouterProps extends IRouterProps<TUserProps> = IRouterProps<TUserProps>> extends React.Component<TRouterProps, IRouterState> {
17
18
  state: IRouterState;
18
19
  private $lastRenderedRoute;
19
20
  private $matcher;
@@ -82,8 +83,3 @@ export declare class Router<TRouterProps extends IRouterProps = IRouterProps> ex
82
83
  */
83
84
  private $getIndexRoute;
84
85
  }
85
- /**
86
- * @deprecated Use Router.getInstance() instead.
87
- * @returns {RouterStrategy}
88
- */
89
- export declare let getRouter: () => RouterStrategy;
@@ -8,12 +8,17 @@ export interface IViewProps {
8
8
  entryTransition?: TransitionStrategy;
9
9
  exitTransition?: TransitionStrategy;
10
10
  }
11
- export declare abstract class View<TPageProps extends IViewProps = IViewProps> extends React.Component<TPageProps> {
11
+ export interface IViewState {
12
+ }
13
+ export interface IViewSnapshotState {
14
+ }
15
+ export declare abstract class View<TPageProps extends IViewProps = IViewProps, TPageState extends IViewState = IViewState, TPageSnapshotState extends IViewSnapshotState = IViewSnapshotState> extends React.Component<TPageProps, TPageState, TPageSnapshotState> {
12
16
  private $node;
13
17
  /**
14
18
  * @param props See [IViewProps]
15
19
  */
16
20
  constructor(props: TPageProps);
21
+ protected abstract _initState(): TPageState;
17
22
  /**
18
23
  * Return the CSS class on this view
19
24
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breautek/router",
3
- "version": "5.0.0-beta.0",
3
+ "version": "5.0.0",
4
4
  "description": "An alternate react router.",
5
5
  "main": "dist/router.js",
6
6
  "types": "dist/src/api.d.ts",
@@ -37,31 +37,32 @@
37
37
  "react-dom": "16.x || 17.x || 18.x || 19.x"
38
38
  },
39
39
  "devDependencies": {
40
- "@jest/types": "30.0.5",
41
- "@rollup/plugin-commonjs": "28.0.6",
40
+ "@jest/types": "30.2.0",
41
+ "@rollup/plugin-commonjs": "29.0.0",
42
42
  "@rollup/plugin-json": "6.1.0",
43
- "@rollup/plugin-node-resolve": "16.0.1",
44
- "@testing-library/jest-dom": "6.6.3",
45
- "@testing-library/react": "16.3.0",
46
- "@totalpave/eslint-plugin": "7.0.14",
43
+ "@rollup/plugin-node-resolve": "16.0.3",
44
+ "@testing-library/dom": "10.4.1",
45
+ "@testing-library/jest-dom": "6.9.1",
46
+ "@testing-library/react": "16.3.2",
47
+ "@totalpave/eslint-plugin": "7.0.17",
47
48
  "@types/jest": "30.0.0",
48
- "@types/react": "19.1.8",
49
- "@types/react-dom": "19.1.6",
49
+ "@types/react": "19.2.10",
50
+ "@types/react-dom": "19.2.3",
50
51
  "ajv": "8.17.1",
51
- "glob": "11.0.3",
52
+ "glob": "13.0.1",
52
53
  "ignore-styles": "5.0.1",
53
- "jest": "30.0.5",
54
- "jest-environment-jsdom": "30.0.5",
55
- "react": "19.1.0",
56
- "react-dom": "19.1.0",
57
- "rollup": "4.45.1",
54
+ "jest": "30.2.0",
55
+ "jest-environment-jsdom": "30.2.0",
56
+ "react": "19.2.4",
57
+ "react-dom": "19.2.4",
58
+ "rollup": "4.57.1",
58
59
  "rollup-plugin-progress": "1.1.2",
59
60
  "rollup-plugin-sass": "1.15.3",
60
61
  "rollup-plugin-typescript2": "0.36.0",
61
- "sass": "1.89.2",
62
- "ts-jest": "29.4.0",
62
+ "sass": "1.97.3",
63
+ "ts-jest": "29.4.6",
63
64
  "ts-node": "10.9.2",
64
- "typescript": "5.8.3"
65
+ "typescript": "5.9.3"
65
66
  },
66
67
  "dependencies": {
67
68
  "@types/events": "3.0.3",
package/src/Route.tsx CHANGED
@@ -5,30 +5,30 @@ import { RouteMatcher } from './RouteMatcher';
5
5
  import { RouterStrategy } from './RouterStrategy';
6
6
  import { TransitionStrategy } from './TransitionStrategy';
7
7
 
8
- export interface IRouteProps<T extends IComponentProps = IComponentProps> {
8
+ export interface IRouteProps<TUserProps = any, TInternalProps extends IComponentProps = IComponentProps> {
9
9
  url: string;
10
10
  component: React.ComponentClass<any>;
11
11
  index?: boolean;
12
12
  entryTransition?: TransitionStrategy;
13
13
  exitTransition?: TransitionStrategy;
14
14
  children?: React.ReactElement<IRouteProps> | React.ReactElement<IRouteProps>[];
15
-
15
+ componentProps?: TUserProps;
16
16
  ref?: React.Ref<Route>;
17
17
 
18
18
  /**
19
19
  * @internal
20
20
  */
21
- base?: string;
21
+ __base?: string;
22
22
 
23
23
  /**
24
24
  * @internal
25
25
  */
26
- componentProps?: T;
26
+ __componentProps?: TInternalProps;
27
27
 
28
28
  /**
29
29
  * @internal
30
30
  */
31
- matcher?: RouteMatcher;
31
+ __matcher?: RouteMatcher;
32
32
  }
33
33
 
34
34
  export interface IComponentProps {
@@ -64,20 +64,23 @@ export class Route<TComponentProps extends IComponentProps = IComponentProps, TR
64
64
 
65
65
  private $getComponentsToRender(component: React.ReactElement<IRouteProps> | React.Component<IRouteProps>): React.ReactNode {
66
66
  let url: string = component.props.url;
67
- let base: string = component.props.base || '';
67
+ let base: string = component.props.__base || '';
68
68
 
69
69
  // eslint-disable-next-line @typescript-eslint/naming-convention
70
70
  let ViewComponent: React.ElementType = component.props.component;
71
71
  let child: React.ReactNode;
72
72
 
73
- let routeComponent: React.ReactElement<IRouteProps> = component.props.matcher.match(url, this.$getChildren(component), base);
73
+ let routeComponent: React.ReactElement<IRouteProps> = component.props.__matcher.match(url, this.$getChildren(component), base);
74
74
  if (routeComponent) {
75
75
  child = this.$getComponentsToRender(routeComponent);
76
76
  }
77
77
 
78
78
  return (
79
79
  <ViewComponent
80
- {...component.props.componentProps as any}
80
+ {...{
81
+ ...component.props.componentProps,
82
+ ...component.props.__componentProps
83
+ }}
81
84
  ref={(node: React.Component) => {
82
85
  if (node) {
83
86
  if (node instanceof View) {
@@ -63,14 +63,16 @@ export class RouteMatcher {
63
63
  return null;
64
64
  }
65
65
 
66
- let props: IRouteProps<IComponentProps> = {
66
+ let props: IRouteProps<any, IComponentProps> = {
67
67
  url : url,
68
- base: base + componentToRender.props.url,
69
- matcher: this,
68
+ __base: base + componentToRender.props.url,
69
+ __matcher: this,
70
70
  component: componentToRender.props.component,
71
71
  entryTransition: componentToRender.props.entryTransition,
72
72
  exitTransition: componentToRender.props.exitTransition,
73
- componentProps: {
73
+ componentProps: componentToRender.props.componentProps,
74
+ __componentProps: {
75
+ ...componentToRender.props.componentProps,
74
76
  url : url,
75
77
  router: this.$strategy
76
78
  }
@@ -78,7 +80,7 @@ export class RouteMatcher {
78
80
 
79
81
  if (params) {
80
82
  for (let i in params) {
81
- props.componentProps[i] = params[i];
83
+ props.__componentProps[i] = params[i];
82
84
  }
83
85
  }
84
86
 
package/src/Router.tsx CHANGED
@@ -8,9 +8,10 @@ import { IRouterStrategyClass } from './IRouterStrategyClass';
8
8
  import {IOnNoRoute} from './IOnNoRoute';
9
9
  import { IRouteProps, Route } from "./Route";
10
10
 
11
- export interface IRouterProps {
11
+ export interface IRouterProps<T = any> {
12
12
  strategy?: IRouterStrategyClass;
13
13
  component: React.ComponentClass<any>;
14
+ componentProps?: T;
14
15
  children?: React.ReactNode;
15
16
  onNoRoute?: IOnNoRoute;
16
17
  }
@@ -21,7 +22,7 @@ export interface IRouterState {
21
22
  shouldTransition: boolean;
22
23
  }
23
24
 
24
- export class Router<TRouterProps extends IRouterProps = IRouterProps> extends React.Component<TRouterProps, IRouterState> {
25
+ export class Router<TUserProps = any, TRouterProps extends IRouterProps<TUserProps> = IRouterProps<TUserProps>> extends React.Component<TRouterProps, IRouterState> {
25
26
  public state: IRouterState;
26
27
 
27
28
  private $lastRenderedRoute: any;
@@ -161,7 +162,7 @@ export class Router<TRouterProps extends IRouterProps = IRouterProps> extends Re
161
162
  // currentRoute must be rendered as an array; because, exiting and incoming is rendered as an array.
162
163
  // if currentRoute is not rendered as an array, a bug happens where the exiting screen is reloaded
163
164
  // calling the constructor again.
164
- return <Root router={this.getRouterStrategy()} url={this.state.url}>{[ currentRoute ]}</Root>;
165
+ return <Root {...this.props.componentProps} router={this.getRouterStrategy()} url={this.state.url}>{[ currentRoute ]}</Root>;
165
166
  }
166
167
  else {
167
168
  return currentRoute;
@@ -275,12 +276,3 @@ export class Router<TRouterProps extends IRouterProps = IRouterProps> extends Re
275
276
  return null;
276
277
  }
277
278
  }
278
-
279
- /**
280
- * @deprecated Use Router.getInstance() instead.
281
- * @returns {RouterStrategy}
282
- */
283
- export let getRouter = (): RouterStrategy => {
284
- console.warn('getRouter() is deprecated. use Router.getInstance() instead.');
285
- return Router.getInstance();
286
- }
package/src/View.tsx CHANGED
@@ -12,7 +12,11 @@ export interface IViewProps {
12
12
  exitTransition?: TransitionStrategy;
13
13
  }
14
14
 
15
- export abstract class View<TPageProps extends IViewProps = IViewProps> extends React.Component<TPageProps> {
15
+ export interface IViewState {}
16
+
17
+ export interface IViewSnapshotState {}
18
+
19
+ export abstract class View<TPageProps extends IViewProps = IViewProps, TPageState extends IViewState = IViewState, TPageSnapshotState extends IViewSnapshotState = IViewSnapshotState> extends React.Component<TPageProps, TPageState, TPageSnapshotState> {
16
20
  private $node: HTMLDivElement;
17
21
 
18
22
  /**
@@ -21,8 +25,11 @@ export abstract class View<TPageProps extends IViewProps = IViewProps> extends R
21
25
  public constructor(props: TPageProps) {
22
26
  super(props);
23
27
  this.$node = null;
28
+ this.state = this._initState();
24
29
  }
25
30
 
31
+ protected abstract _initState(): TPageState;
32
+
26
33
  /**
27
34
  * Return the CSS class on this view
28
35
  */