@breautek/router 3.0.1 → 4.1.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.
@@ -1,5 +1,5 @@
1
- import { IRouterStrategyClass } from './IRouterStrategyClass';
2
- /**
3
- Alias for {@link HashStrategy}
4
- */
5
- export declare let DefaultStrategy: IRouterStrategyClass;
1
+ import { IRouterStrategyClass } from './IRouterStrategyClass';
2
+ /**
3
+ Alias for {@link HashStrategy}
4
+ */
5
+ export declare let DefaultStrategy: IRouterStrategyClass;
@@ -1,29 +1,29 @@
1
- import { RouterStrategy } from './RouterStrategy';
2
- import { Router } from './Router';
3
- /**
4
- A {@link RouterStrategy} that manages a history stack using inline pound symbols `#`.
5
- URLs will have a starting point `/#/`, as a default base.
1
+ import { RouterStrategy } from './RouterStrategy';
2
+ import { Router } from './Router';
3
+ /**
4
+ A {@link RouterStrategy} that manages a history stack using inline pound symbols `#`.
5
+ URLs will have a starting point `/#/`, as a default base.
6
6
 
7
- For example, if you [pushState("mylink")]{@link pushState}, the url
8
- `/#/mylink` will be produced.
9
- */
10
- export declare class HashStrategy extends RouterStrategy {
11
- private $base;
12
- private $stack;
13
- private $position;
14
- private $lastFiredLocation;
15
- constructor(router: Router);
16
- private $init;
17
- getLocation(): string;
18
- getLocationAt(position: number): string;
19
- getHistoryLength(): number;
20
- getScrollRestoration(): ScrollRestoration;
21
- canGo(to: number): boolean;
22
- peek(to: number): string;
23
- go(to: number): void;
24
- pushState(url: string, state?: Record<any, any>): void;
25
- replaceState(url: string, state?: Record<any, any>): void;
26
- clear(): void;
27
- private $navigate;
28
- protected _fireURLChange(url: string): void;
29
- }
7
+ For example, if you [pushState("mylink")]{@link pushState}, the url
8
+ `/#/mylink` will be produced.
9
+ */
10
+ export declare class HashStrategy extends RouterStrategy {
11
+ private $base;
12
+ private $stack;
13
+ private $position;
14
+ private $lastFiredLocation;
15
+ constructor(router: Router);
16
+ private $init;
17
+ getLocation(): string;
18
+ getLocationAt(position: number): string;
19
+ getHistoryLength(): number;
20
+ getScrollRestoration(): ScrollRestoration;
21
+ canGo(to: number): boolean;
22
+ peek(to: number): string;
23
+ go(to: number): void;
24
+ pushState(url: string, state?: Record<any, any>): void;
25
+ replaceState(url: string, state?: Record<any, any>): void;
26
+ clear(): void;
27
+ private $navigate;
28
+ protected _fireURLChange(url: string): void;
29
+ }
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
2
- export interface IOnNoRoute {
3
- (indexRoute: React.ReactElement, routes: Array<React.ReactElement>): React.ReactElement;
4
- }
1
+ import * as React from 'react';
2
+ export interface IOnNoRoute {
3
+ (indexRoute: React.ReactElement, routes: Array<React.ReactElement>): React.ReactElement;
4
+ }
@@ -1,8 +1,8 @@
1
- import { RouterStrategy } from './RouterStrategy';
2
- import { Router } from './Router';
3
- /**
4
- * An interface to generically reference a {@link RouterStrategy} class
5
- */
6
- export interface IRouterStrategyClass {
7
- new (router: Router): RouterStrategy;
8
- }
1
+ import { RouterStrategy } from './RouterStrategy';
2
+ import { Router } from './Router';
3
+ /**
4
+ * An interface to generically reference a {@link RouterStrategy} class
5
+ */
6
+ export interface IRouterStrategyClass {
7
+ new (router: Router): RouterStrategy;
8
+ }
@@ -1,4 +1,4 @@
1
- export interface IViewStylesheet {
2
- use: () => void;
3
- unuse: () => void;
4
- }
1
+ export interface IViewStylesheet {
2
+ use: () => void;
3
+ unuse: () => void;
4
+ }
@@ -1,33 +1,33 @@
1
- import * as React from 'react';
2
- import { View } from './View';
3
- import { RouteMatcher } from './RouteMatcher';
4
- import { RouterStrategy } from './RouterStrategy';
5
- import { TransitionStrategy } from 'TransitionStrategy';
6
- export interface IRouteProps<T> {
7
- url: string;
8
- component: React.ComponentClass<any>;
9
- index?: boolean;
10
- entryTransition?: TransitionStrategy;
11
- exitTransition?: TransitionStrategy;
12
- base?: string;
13
- componentProps?: T;
14
- matcher?: RouteMatcher;
15
- }
16
- export interface IComponentProps {
17
- url: string;
18
- router: RouterStrategy;
19
- [key: string]: any;
20
- }
21
- export interface IRouteState {
22
- }
23
- /**
24
- * This class represents a route that renders a {@link View} component
25
- */
26
- export declare class Route<TComponentProps extends IComponentProps = IComponentProps, TRouteProps extends IRouteProps<TComponentProps> = IRouteProps<TComponentProps>, TRouteState extends IRouteState = IRouteState> extends React.Component<TRouteProps, TRouteState> {
27
- private $node;
28
- constructor(props: TRouteProps);
29
- render(): React.ReactNode;
30
- getView(): View;
31
- private $getComponentsToRender;
32
- private $getChildren;
33
- }
1
+ import * as React from 'react';
2
+ import { View } from './View';
3
+ import { RouteMatcher } from './RouteMatcher';
4
+ import { RouterStrategy } from './RouterStrategy';
5
+ import { TransitionStrategy } from 'TransitionStrategy';
6
+ export interface IRouteProps<T> {
7
+ url: string;
8
+ component: React.ComponentClass<any>;
9
+ index?: boolean;
10
+ entryTransition?: TransitionStrategy;
11
+ exitTransition?: TransitionStrategy;
12
+ base?: string;
13
+ componentProps?: T;
14
+ matcher?: RouteMatcher;
15
+ }
16
+ export interface IComponentProps {
17
+ url: string;
18
+ router: RouterStrategy;
19
+ [key: string]: any;
20
+ }
21
+ export interface IRouteState {
22
+ }
23
+ /**
24
+ * This class represents a route that renders a {@link View} component
25
+ */
26
+ export declare class Route<TComponentProps extends IComponentProps = IComponentProps, TRouteProps extends IRouteProps<TComponentProps> = IRouteProps<TComponentProps>, TRouteState extends IRouteState = IRouteState> extends React.Component<TRouteProps, TRouteState> {
27
+ private $node;
28
+ constructor(props: TRouteProps);
29
+ render(): React.ReactNode;
30
+ getView(): View;
31
+ private $getComponentsToRender;
32
+ private $getChildren;
33
+ }
@@ -1,31 +1,30 @@
1
- /// <reference types="react" />
2
- import "regenerator-runtime/runtime";
3
- import { RouterStrategy } from './RouterStrategy';
4
- /**
5
- * Will be invoked when no routes are found. Default implementation is to simply return the `indexRoute`.
6
- * @param {React.ReactElement} indexRoute The `ReactElement` of a `Route`
7
- * @param {Array<React.ReactElement>} routes An array of `ReactElement` of `Route`
8
- * @returns {React.ReactElement} An `ReactElement` of a `Route`
9
- */
10
- export interface IOnNoRouteFunction {
11
- (indexRoute: React.ReactElement, routes: Array<React.ReactElement>): React.ReactElement;
12
- }
13
- /**
14
- * This class is reponsible for determing which route to render
15
- * based on the URL and the route url patterns.
16
- */
17
- export declare class RouteMatcher {
18
- private $strategy;
19
- constructor(routerStrategy: RouterStrategy);
20
- private $defaultNoRouteFunction;
21
- /**
22
- * Matches the url to the appropriate renderable route
23
- *
24
- * @param url
25
- * @param children
26
- * @param base
27
- * @param indexRoute
28
- * @param onNoRoute
29
- */
30
- match(url: string, children: Array<React.ReactElement>, base: string, indexRoute?: React.ReactElement, onNoRoute?: IOnNoRouteFunction): React.ReactElement;
31
- }
1
+ /// <reference types="react" />
2
+ import { RouterStrategy } from './RouterStrategy';
3
+ /**
4
+ * Will be invoked when no routes are found. Default implementation is to simply return the `indexRoute`.
5
+ * @param {React.ReactElement} indexRoute The `ReactElement` of a `Route`
6
+ * @param {Array<React.ReactElement>} routes An array of `ReactElement` of `Route`
7
+ * @returns {React.ReactElement} An `ReactElement` of a `Route`
8
+ */
9
+ export interface IOnNoRouteFunction {
10
+ (indexRoute: React.ReactElement, routes: Array<React.ReactElement>): React.ReactElement;
11
+ }
12
+ /**
13
+ * This class is reponsible for determing which route to render
14
+ * based on the URL and the route url patterns.
15
+ */
16
+ export declare class RouteMatcher {
17
+ private $strategy;
18
+ constructor(routerStrategy: RouterStrategy);
19
+ private $defaultNoRouteFunction;
20
+ /**
21
+ * Matches the url to the appropriate renderable route
22
+ *
23
+ * @param url
24
+ * @param children
25
+ * @param base
26
+ * @param indexRoute
27
+ * @param onNoRoute
28
+ */
29
+ match(url: string, children: Array<React.ReactElement>, base: string, indexRoute?: React.ReactElement, onNoRoute?: IOnNoRouteFunction): React.ReactElement;
30
+ }
@@ -1,85 +1,89 @@
1
- import "regenerator-runtime/runtime";
2
- import * as React from 'react';
3
- import { RouterStrategy } from './RouterStrategy';
4
- import { IRouterStrategyClass } from './IRouterStrategyClass';
5
- import { IOnNoRoute } from './IOnNoRoute';
6
- export interface IRouterProps {
7
- strategy?: IRouterStrategyClass;
8
- component: React.ComponentClass<any>;
9
- onNoRoute?: IOnNoRoute;
10
- }
11
- export interface IRouterState {
12
- strategy: RouterStrategy;
13
- url: string;
14
- shouldTransition: boolean;
15
- }
16
- export declare class Router<TRouterProps extends IRouterProps = IRouterProps> extends React.Component<TRouterProps, IRouterState> {
17
- state: IRouterState;
18
- private $lastRenderedRoute;
19
- private $matcher;
20
- private $awaitingTransition;
21
- private $incomingRoute;
22
- private $exitingRoute;
23
- private static $instance;
24
- constructor(props: TRouterProps);
25
- static getInstance(): RouterStrategy;
26
- /**
27
- * Gets the current routing strategy
28
- */
29
- getRouterStrategy(): RouterStrategy;
30
- /**
31
- * @ignore
32
- */
33
- private $onURLChange;
34
- componentDidMount(): void;
35
- /**
36
- * @ignore
37
- */
38
- UNSAFE_componentWillReceiveProps(nextProps: TRouterProps): void;
39
- /**
40
- * @ignore
41
- */
42
- componentWillUnmount(): void;
43
- /**
44
- * @ignore
45
- */
46
- render(): React.ReactNode;
47
- /**
48
- * @ignore
49
- */
50
- componentDidUpdate(): void;
51
- /**
52
- * Gets the number of history entries. Note this does not count the browser history.
53
- * Only the history kept track during the life-cycle of the app.
54
- */
55
- getHistoryLength(): number;
56
- /**
57
- * Gets the scroll restoration mode
58
- */
59
- getScrollRestoration(): ScrollRestoration;
60
- /**
61
- *
62
- * @param to An integer, positive means go forward, negative means go backwards. E.g:
63
- * `1` move forward one step
64
- * `-1` move backward one step
65
- * `0` navigate to the current page (This is essentially a no-op)
66
- */
67
- go(to: number): void;
68
- /**
69
- * Go back one step. This is an alias for [pushState(-1)]{@link go}.
70
- */
71
- back(): void;
72
- /**
73
- * Go forward one step. This is an alias for [pushState(1)]{@link go}.
74
- */
75
- forward(): void;
76
- /**
77
- * Gets the potential routes
78
- */
79
- private $getChildren;
80
- /**
81
- * Finds the index route. Returns null if there are no indexed routes.
82
- */
83
- private $getIndexRoute;
84
- }
85
- export declare let getRouter: () => RouterStrategy;
1
+ import * as React from 'react';
2
+ import { RouterStrategy } from './RouterStrategy';
3
+ import { IRouterStrategyClass } from './IRouterStrategyClass';
4
+ import { IOnNoRoute } from './IOnNoRoute';
5
+ export interface IRouterProps {
6
+ strategy?: IRouterStrategyClass;
7
+ component: React.ComponentClass<any>;
8
+ children?: React.ReactNode;
9
+ onNoRoute?: IOnNoRoute;
10
+ }
11
+ export interface IRouterState {
12
+ strategy: RouterStrategy;
13
+ url: string;
14
+ shouldTransition: boolean;
15
+ }
16
+ export declare class Router<TRouterProps extends IRouterProps = IRouterProps> extends React.Component<TRouterProps, IRouterState> {
17
+ state: IRouterState;
18
+ private $lastRenderedRoute;
19
+ private $matcher;
20
+ private $awaitingTransition;
21
+ private $incomingRoute;
22
+ private $exitingRoute;
23
+ private static $instance;
24
+ constructor(props: TRouterProps);
25
+ static getInstance(): RouterStrategy;
26
+ /**
27
+ * Gets the current routing strategy
28
+ */
29
+ getRouterStrategy(): RouterStrategy;
30
+ /**
31
+ * @ignore
32
+ */
33
+ private $onURLChange;
34
+ componentDidMount(): void;
35
+ /**
36
+ * @ignore
37
+ */
38
+ UNSAFE_componentWillReceiveProps(nextProps: TRouterProps): void;
39
+ /**
40
+ * @ignore
41
+ */
42
+ componentWillUnmount(): void;
43
+ /**
44
+ * @ignore
45
+ */
46
+ render(): React.ReactNode;
47
+ /**
48
+ * @ignore
49
+ */
50
+ componentDidUpdate(): void;
51
+ /**
52
+ * Gets the number of history entries. Note this does not count the browser history.
53
+ * Only the history kept track during the life-cycle of the app.
54
+ */
55
+ getHistoryLength(): number;
56
+ /**
57
+ * Gets the scroll restoration mode
58
+ */
59
+ getScrollRestoration(): ScrollRestoration;
60
+ /**
61
+ *
62
+ * @param to An integer, positive means go forward, negative means go backwards. E.g:
63
+ * `1` move forward one step
64
+ * `-1` move backward one step
65
+ * `0` navigate to the current page (This is essentially a no-op)
66
+ */
67
+ go(to: number): void;
68
+ /**
69
+ * Go back one step. This is an alias for [pushState(-1)]{@link go}.
70
+ */
71
+ back(): void;
72
+ /**
73
+ * Go forward one step. This is an alias for [pushState(1)]{@link go}.
74
+ */
75
+ forward(): void;
76
+ /**
77
+ * Gets the potential routes
78
+ */
79
+ private $getChildren;
80
+ /**
81
+ * Finds the index route. Returns null if there are no indexed routes.
82
+ */
83
+ private $getIndexRoute;
84
+ }
85
+ /**
86
+ * @deprecated Use Router.getInstance() instead.
87
+ * @returns {RouterStrategy}
88
+ */
89
+ export declare let getRouter: () => RouterStrategy;