@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.
@@ -1,117 +1,138 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { Router } from './Router';
4
- export declare const EVENT_URL_CHANGE: string;
5
- export declare type URLChangeCallback = (url: string) => void;
6
- export declare abstract class RouterStrategy extends EventEmitter {
7
- private $router;
8
- constructor(router: Router);
9
- /**
10
- * Gets the router
11
- */
12
- getRouter(): Router;
13
- /**
14
- * Sets the browser title
15
- *
16
- * @param {string} title
17
- */
18
- setTitle(title: string): void;
19
- /**
20
- * Listen for URL change events
21
- *
22
- * @param callback
23
- */
24
- addURLChangeCallback(callback: URLChangeCallback): void;
25
- /**
26
- * Removes an existing listener
27
- *
28
- * @param callback
29
- */
30
- removeURLChangeCallback(callback: URLChangeCallback): void;
31
- /**
32
- * Gets the URL at the given index in the history stack
33
- * @param position index
34
- */
35
- abstract getLocationAt(position: number): string;
36
- /**
37
- * Gets the current location.
38
- * This is the same as calling [peek(0)]{@link peek}
39
- */
40
- abstract getLocation(): string;
41
- /**
42
- * Gets the size of the history stack
43
- */
44
- abstract getHistoryLength(): number;
45
- /**
46
- * Gets the scroll restoration
47
- */
48
- abstract getScrollRestoration(): ScrollRestoration;
49
- /**
50
- * Navigates the history
51
- * @param to Must be an integer.
52
- * Negative numbers go back, if possible.
53
- * Positive goes forward, if possible.
54
- * Zero does nothing.
55
- */
56
- abstract go(to: number): void;
57
- /**
58
- * navigate the history forward one entry. This is an alias for [go(1)]{@link go}
59
- */
60
- forward(): void;
61
- /**
62
- * Navigate the history back one entry. This is an alias for [go(-1)]{@link go}
63
- */
64
- back(): void;
65
- /**
66
- * Returns true, if can be navigated to the given relative index
67
- * @param to Must be an integer
68
- */
69
- abstract canGo(to: number): boolean;
70
- /**
71
- * Returns true if can go back 1 entry.
72
- * This is the same as calling [canGo(-1)]{@link canGo}
73
- */
74
- canBack(): boolean;
75
- /**
76
- * Returns true if can go forward 1 entry.
77
- * This is the same as calling [canGo(1)]{@link canGo}
78
- */
79
- canForward(): boolean;
80
- /**
81
- * Returns the URL stored in the history stack at the given relative index.
82
- * @param to Must be an integer
83
- */
84
- abstract peek(to: number): string;
85
- /**
86
- * Returns the URL one entry forward.
87
- * This is the same as calling [peek(1)]{@link peek}
88
- */
89
- peekForward(): string;
90
- /**
91
- * Returns the URL one entry back.
92
- * This is the same as calling [peek(-1)]{@link peek}
93
- */
94
- peekBack(): string;
95
- /**
96
- * Pushes a new entry into the history stack, navigating to the new location.
97
- * @param url
98
- * @param state
99
- */
100
- abstract pushState(url: string, state?: Record<any, any>): void;
101
- /**
102
- * Replaces the current entry in the history stack with the new location.
103
- * This will navigate the screen to the new location.
104
- * @param url
105
- * @param state
106
- */
107
- abstract replaceState(url: string, state?: Record<any, any>): void;
108
- /**
109
- * Clears the history stack.
110
- */
111
- abstract clear(): void;
112
- /**
113
- * Fires the {@link EVENT_URL_CHANGE} event
114
- * @param url
115
- */
116
- protected _fireURLChange(url: string): void;
117
- }
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { Router } from './Router';
4
+ import { View } from './View';
5
+ export declare const EVENT_URL_CHANGE: string;
6
+ export type URLChangeCallback = (url: string) => void;
7
+ /**
8
+ * Invoked when the view's componentDidMount/componentWillUnmount fires.
9
+ */
10
+ export type ViewMountChangeCallback = (view: View) => void;
11
+ export declare abstract class RouterStrategy extends EventEmitter {
12
+ private $router;
13
+ private $viewMountListeners;
14
+ private $viewUnmountListneners;
15
+ constructor(router: Router);
16
+ addViewMountCallback(cb: ViewMountChangeCallback): void;
17
+ removeViewMountCallback(cb: ViewMountChangeCallback): void;
18
+ addViewUnmountCallback(cb: ViewMountChangeCallback): void;
19
+ removeViewUnmountCallback(cb: ViewMountChangeCallback): void;
20
+ /**
21
+ * @internal
22
+ * @param view
23
+ */
24
+ __onViewMount(view: View): void;
25
+ /**
26
+ * @internal
27
+ * @param view
28
+ */
29
+ __onViewUnmount(view: View): void;
30
+ /**
31
+ * Gets the router
32
+ */
33
+ getRouter(): Router;
34
+ /**
35
+ * Sets the browser title
36
+ *
37
+ * @param {string} title
38
+ */
39
+ setTitle(title: string): void;
40
+ /**
41
+ * Listen for URL change events
42
+ *
43
+ * @param callback
44
+ */
45
+ addURLChangeCallback(callback: URLChangeCallback): void;
46
+ /**
47
+ * Removes an existing listener
48
+ *
49
+ * @param callback
50
+ */
51
+ removeURLChangeCallback(callback: URLChangeCallback): void;
52
+ /**
53
+ * Gets the URL at the given index in the history stack
54
+ * @param position index
55
+ */
56
+ abstract getLocationAt(position: number): string;
57
+ /**
58
+ * Gets the current location.
59
+ * This is the same as calling [peek(0)]{@link peek}
60
+ */
61
+ abstract getLocation(): string;
62
+ /**
63
+ * Gets the size of the history stack
64
+ */
65
+ abstract getHistoryLength(): number;
66
+ /**
67
+ * Gets the scroll restoration
68
+ */
69
+ abstract getScrollRestoration(): ScrollRestoration;
70
+ /**
71
+ * Navigates the history
72
+ * @param to Must be an integer.
73
+ * Negative numbers go back, if possible.
74
+ * Positive goes forward, if possible.
75
+ * Zero does nothing.
76
+ */
77
+ abstract go(to: number): void;
78
+ /**
79
+ * navigate the history forward one entry. This is an alias for [go(1)]{@link go}
80
+ */
81
+ forward(): void;
82
+ /**
83
+ * Navigate the history back one entry. This is an alias for [go(-1)]{@link go}
84
+ */
85
+ back(): void;
86
+ /**
87
+ * Returns true, if can be navigated to the given relative index
88
+ * @param to Must be an integer
89
+ */
90
+ abstract canGo(to: number): boolean;
91
+ /**
92
+ * Returns true if can go back 1 entry.
93
+ * This is the same as calling [canGo(-1)]{@link canGo}
94
+ */
95
+ canBack(): boolean;
96
+ /**
97
+ * Returns true if can go forward 1 entry.
98
+ * This is the same as calling [canGo(1)]{@link canGo}
99
+ */
100
+ canForward(): boolean;
101
+ /**
102
+ * Returns the URL stored in the history stack at the given relative index.
103
+ * @param to Must be an integer
104
+ */
105
+ abstract peek(to: number): string;
106
+ /**
107
+ * Returns the URL one entry forward.
108
+ * This is the same as calling [peek(1)]{@link peek}
109
+ */
110
+ peekForward(): string;
111
+ /**
112
+ * Returns the URL one entry back.
113
+ * This is the same as calling [peek(-1)]{@link peek}
114
+ */
115
+ peekBack(): string;
116
+ /**
117
+ * Pushes a new entry into the history stack, navigating to the new location.
118
+ * @param url
119
+ * @param state
120
+ */
121
+ abstract pushState(url: string, state?: Record<any, any>): void;
122
+ /**
123
+ * Replaces the current entry in the history stack with the new location.
124
+ * This will navigate the screen to the new location.
125
+ * @param url
126
+ * @param state
127
+ */
128
+ abstract replaceState(url: string, state?: Record<any, any>): void;
129
+ /**
130
+ * Clears the history stack.
131
+ */
132
+ abstract clear(): void;
133
+ /**
134
+ * Fires the {@link EVENT_URL_CHANGE} event
135
+ * @param url
136
+ */
137
+ protected _fireURLChange(url: string): void;
138
+ }
@@ -1,17 +1,17 @@
1
- import { TransitionStrategy } from './TransitionStrategy';
2
- import { View } from './View';
3
- export declare enum TransitionSlideDirection {
4
- LEFT = 1,
5
- RIGHT = 2,
6
- UP = 3,
7
- DOWN = 4
8
- }
9
- export declare class TransitionSlide extends TransitionStrategy {
10
- private $slideDirection;
11
- private $slideSpeed;
12
- private $transitionTimeout;
13
- constructor(slideDirection: TransitionSlideDirection, slideSpeed: number);
14
- protected _execute(incoming: View, exiting: View): Promise<void>;
15
- private $getTransitionString;
16
- private $getSlideStyle;
17
- }
1
+ import { TransitionStrategy } from './TransitionStrategy';
2
+ import { View } from './View';
3
+ export declare enum TransitionSlideDirection {
4
+ LEFT = 1,
5
+ RIGHT = 2,
6
+ UP = 3,
7
+ DOWN = 4
8
+ }
9
+ export declare class TransitionSlide extends TransitionStrategy {
10
+ private $slideDirection;
11
+ private $slideSpeed;
12
+ private $transitionTimeout;
13
+ constructor(slideDirection: TransitionSlideDirection, slideSpeed: number);
14
+ protected _execute(incoming: View, exiting: View): Promise<void>;
15
+ private $getTransitionString;
16
+ private $getSlideStyle;
17
+ }
@@ -1,21 +1,21 @@
1
- import { View } from './View';
2
- export declare abstract class TransitionStrategy {
3
- constructor();
4
- /**
5
- * Invoked when the transition should begin.
6
- * The promise should only resolve once the transition
7
- * has ran to completion.
8
- *
9
- * The `incomingView` is the view that the user is navigating to.
10
- * The `exitingView` is te view that the user is currently on, and is leaving.
11
- *
12
- * Both views will be rendered and are free to be manipulated in anyway that is desired,
13
- * however, the incomingView should be positioned in it's natural position by the end
14
- * of the transition to avoid "snapping" behaviour.
15
- *
16
- * @param {View} incomingView
17
- * @param {View} exitingView
18
- */
19
- execute(incomingView: View, exitingView: View): Promise<void>;
20
- protected abstract _execute(incomingView: View, exitingView: View): Promise<void>;
21
- }
1
+ import { View } from './View';
2
+ export declare abstract class TransitionStrategy {
3
+ constructor();
4
+ /**
5
+ * Invoked when the transition should begin.
6
+ * The promise should only resolve once the transition
7
+ * has ran to completion.
8
+ *
9
+ * The `incomingView` is the view that the user is navigating to.
10
+ * The `exitingView` is te view that the user is currently on, and is leaving.
11
+ *
12
+ * Both views will be rendered and are free to be manipulated in anyway that is desired,
13
+ * however, the incomingView should be positioned in it's natural position by the end
14
+ * of the transition to avoid "snapping" behaviour.
15
+ *
16
+ * @param {View} incomingView
17
+ * @param {View} exitingView
18
+ */
19
+ execute(incomingView: View, exitingView: View): Promise<void>;
20
+ protected abstract _execute(incomingView: View, exitingView: View): Promise<void>;
21
+ }
@@ -1,39 +1,39 @@
1
- export interface IURLParams {
2
- [key: string]: string;
3
- }
4
- /**
5
- * Parses the URL for router paths and url-based variables.
6
- */
7
- export declare class URLParser {
8
- private $allowPartialMatch;
9
- private $pattern;
10
- /**
11
- *
12
- * @param {string} pattern The URL pattern
13
- * @param {boolean} allowPartialMatch If true, the pattern will match again urls that contains the pattern,
14
- * even if it isn't an exact match.
15
- * Defaults to false.
16
- */
17
- constructor(pattern: string, allowPartialMatch?: boolean);
18
- /**
19
- * Parses the URL and returns the url parameters.
20
- * Returns null the url does not match the pattern
21
- *
22
- * @param {string} url The url to test
23
- */
24
- parse(url: string): IURLParams;
25
- /**
26
- * Strips the url for parsing, removing leading and trailing forward slashes.
27
- *
28
- * @private
29
- * @param {string} url URL to strip
30
- */
31
- private $stripURL;
32
- /**
33
- * Splits the url into an array of URL parts, separated by the forward slash
34
- *
35
- * @private
36
- * @param {string} url URL to split
37
- */
38
- private $getParts;
39
- }
1
+ export interface IURLParams {
2
+ [key: string]: string;
3
+ }
4
+ /**
5
+ * Parses the URL for router paths and url-based variables.
6
+ */
7
+ export declare class URLParser {
8
+ private $allowPartialMatch;
9
+ private $pattern;
10
+ /**
11
+ *
12
+ * @param {string} pattern The URL pattern
13
+ * @param {boolean} allowPartialMatch If true, the pattern will match again urls that contains the pattern,
14
+ * even if it isn't an exact match.
15
+ * Defaults to false.
16
+ */
17
+ constructor(pattern: string, allowPartialMatch?: boolean);
18
+ /**
19
+ * Parses the URL and returns the url parameters.
20
+ * Returns null the url does not match the pattern
21
+ *
22
+ * @param {string} url The url to test
23
+ */
24
+ parse(url: string): IURLParams;
25
+ /**
26
+ * Strips the url for parsing, removing leading and trailing forward slashes.
27
+ *
28
+ * @private
29
+ * @param {string} url URL to strip
30
+ */
31
+ private $stripURL;
32
+ /**
33
+ * Splits the url into an array of URL parts, separated by the forward slash
34
+ *
35
+ * @private
36
+ * @param {string} url URL to split
37
+ */
38
+ private $getParts;
39
+ }
@@ -1,32 +1,32 @@
1
- import { RouterStrategy } from './RouterStrategy';
2
- import { Router } from './Router';
3
- /**
4
- * @notice Using the URLStrategy requires some backend configuration
5
- * to route URLs back to application.
6
- *
7
- * To make this easier, by default these URLs are prefixed with
8
- * `/r/` to easily differentiate between URLs that needs to be re-routed back
9
- * to the application vs other resources such as images.
10
- */
11
- export declare class URLStrategy extends RouterStrategy {
12
- private $base;
13
- private $stack;
14
- private $position;
15
- /**
16
- *
17
- * @param {Router} router
18
- */
19
- constructor(router: Router);
20
- private $init;
21
- getLocation(): string;
22
- getLocationAt(position: number): string;
23
- getHistoryLength(): number;
24
- getScrollRestoration(): ScrollRestoration;
25
- peek(to: number): string;
26
- canGo(to: number): boolean;
27
- go(to: number): void;
28
- pushState(url: string, state?: Record<any, any>): void;
29
- replaceState(url: string, state?: Record<any, any>): void;
30
- clear(): void;
31
- private $navigate;
32
- }
1
+ import { RouterStrategy } from './RouterStrategy';
2
+ import { Router } from './Router';
3
+ /**
4
+ * @notice Using the URLStrategy requires some backend configuration
5
+ * to route URLs back to application.
6
+ *
7
+ * To make this easier, by default these URLs are prefixed with
8
+ * `/r/` to easily differentiate between URLs that needs to be re-routed back
9
+ * to the application vs other resources such as images.
10
+ */
11
+ export declare class URLStrategy extends RouterStrategy {
12
+ private $base;
13
+ private $stack;
14
+ private $position;
15
+ /**
16
+ *
17
+ * @param {Router} router
18
+ */
19
+ constructor(router: Router);
20
+ private $init;
21
+ getLocation(): string;
22
+ getLocationAt(position: number): string;
23
+ getHistoryLength(): number;
24
+ getScrollRestoration(): ScrollRestoration;
25
+ peek(to: number): string;
26
+ canGo(to: number): boolean;
27
+ go(to: number): void;
28
+ pushState(url: string, state?: Record<any, any>): void;
29
+ replaceState(url: string, state?: Record<any, any>): void;
30
+ clear(): void;
31
+ private $navigate;
32
+ }
@@ -1,49 +1,48 @@
1
- import "regenerator-runtime/runtime";
2
- import * as React from 'react';
3
- import { RouterStrategy } from './RouterStrategy';
4
- import { TransitionStrategy } from './TransitionStrategy';
5
- import { IViewStylesheet } from './IViewStylesheet';
6
- import "./View.scss";
7
- export interface IViewProps {
8
- router: RouterStrategy;
9
- entryTransition?: TransitionStrategy;
10
- exitTransition?: TransitionStrategy;
11
- }
12
- export declare abstract class View<TPageProps extends IViewProps = IViewProps> extends React.Component<TPageProps> {
13
- private $node;
14
- /**
15
- * @param props See [IViewProps]
16
- */
17
- constructor(props: TPageProps);
18
- /**
19
- * Return the CSS class on this view
20
- */
21
- getCSSClass(): string;
22
- /**
23
- * Override to return a webpack API style stylesheet
24
- */
25
- getViewStylesheet(): IViewStylesheet;
26
- /**
27
- * @ignore
28
- */
29
- componentDidMount(): void;
30
- /**
31
- * @ignore
32
- */
33
- componentWillUnmount(): void;
34
- /**
35
- * Gets the underlying HTML node for this View
36
- */
37
- getNode(): HTMLElement;
38
- /**
39
- * Get the title of this view
40
- */
41
- getTitle(): Promise<string>;
42
- /**
43
- * Get the inline styles for this view.
44
- * Use React style notation.
45
- */
46
- getViewStyles(): Record<any, string>;
47
- protected abstract _renderView(): React.ReactNode;
48
- render(): React.ReactNode;
49
- }
1
+ import * as React from 'react';
2
+ import { RouterStrategy } from './RouterStrategy';
3
+ import { TransitionStrategy } from './TransitionStrategy';
4
+ import { IViewStylesheet } from './IViewStylesheet';
5
+ import "./View.scss";
6
+ export interface IViewProps {
7
+ router: RouterStrategy;
8
+ entryTransition?: TransitionStrategy;
9
+ exitTransition?: TransitionStrategy;
10
+ }
11
+ export declare abstract class View<TPageProps extends IViewProps = IViewProps> extends React.Component<TPageProps> {
12
+ private $node;
13
+ /**
14
+ * @param props See [IViewProps]
15
+ */
16
+ constructor(props: TPageProps);
17
+ /**
18
+ * Return the CSS class on this view
19
+ */
20
+ getCSSClass(): string;
21
+ /**
22
+ * Override to return a webpack API style stylesheet
23
+ */
24
+ getViewStylesheet(): IViewStylesheet;
25
+ /**
26
+ * @ignore
27
+ */
28
+ componentDidMount(): void;
29
+ /**
30
+ * @ignore
31
+ */
32
+ componentWillUnmount(): void;
33
+ /**
34
+ * Gets the underlying HTML node for this View
35
+ */
36
+ getNode(): HTMLElement;
37
+ /**
38
+ * Get the title of this view
39
+ */
40
+ getTitle(): Promise<string>;
41
+ /**
42
+ * Get the inline styles for this view.
43
+ * Use React style notation.
44
+ */
45
+ getViewStyles(): Record<any, string>;
46
+ protected abstract _renderView(): React.ReactNode;
47
+ render(): React.ReactNode;
48
+ }
package/dist/src/api.d.ts CHANGED
@@ -1,14 +1,13 @@
1
- import "regenerator-runtime/runtime";
2
- export * from './Router';
3
- export * from './DefaultStrategy';
4
- export * from './HashStrategy';
5
- export * from './URLStrategy';
6
- export * from './Route';
7
- export * from './RouterStrategy';
8
- export * from './RouteMatcher';
9
- export * from './TransitionStrategy';
10
- export * from './TransitionSlide';
11
- export * from './View';
12
- export * from './IViewStylesheet';
13
- declare const VERSION: string;
14
- export { VERSION as version };
1
+ export * from './Router';
2
+ export * from './DefaultStrategy';
3
+ export * from './HashStrategy';
4
+ export * from './URLStrategy';
5
+ export * from './Route';
6
+ export * from './RouterStrategy';
7
+ export * from './RouteMatcher';
8
+ export * from './TransitionStrategy';
9
+ export * from './TransitionSlide';
10
+ export * from './View';
11
+ export * from './IViewStylesheet';
12
+ declare const VERSION: string;
13
+ export { VERSION as version };