@lexriver/dome 1.5.6 → 1.5.7
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/out/DomeRouter.d.ts +5 -0
- package/out/DomeRouter.js +27 -27
- package/package.json +1 -1
- package/src/DomeRouter.ts +29 -27
package/out/DomeRouter.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export declare module DomeRouter {
|
|
|
8
8
|
function goForward(): void;
|
|
9
9
|
function changeUrl(url: string): void;
|
|
10
10
|
function getCurrentUrl(): string;
|
|
11
|
+
/**
|
|
12
|
+
* get previous page url navigated by router
|
|
13
|
+
* @param previousPageIndex 0=previousPage, 1=previousPage-1, etc
|
|
14
|
+
*/
|
|
15
|
+
function getPreviousPageUrl(previousPageIndex?: number): string | undefined;
|
|
11
16
|
function resolveUrl(url?: string): void;
|
|
12
17
|
function onRoute(route: string, exactMatch: boolean, action: RouteAction): void;
|
|
13
18
|
function onNotFound(action: () => void): void;
|
package/out/DomeRouter.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { DomeManipulator } from "./DomeManipulator";
|
|
2
2
|
const filename = '[DomeRouter]';
|
|
3
|
-
// interface HistoryUrl{
|
|
4
|
-
// url:string
|
|
5
|
-
// scroll:number
|
|
6
|
-
// }
|
|
7
3
|
export var DomeRouter;
|
|
8
4
|
(function (DomeRouter) {
|
|
9
|
-
|
|
5
|
+
const historyUrls = [];
|
|
10
6
|
const scrollPositionByUrl = new Map();
|
|
11
7
|
DomeRouter.maxHistoryUrlsCount = 20;
|
|
12
8
|
const allRoutes = [];
|
|
@@ -30,10 +26,12 @@ export var DomeRouter;
|
|
|
30
26
|
scrollPositionByUrl.set(getCurrentUrl(), DomeManipulator.getCurrentScrollPosition());
|
|
31
27
|
}
|
|
32
28
|
function navigate(url) {
|
|
29
|
+
addUrlToHistory(getCurrentUrl());
|
|
33
30
|
saveScrollPositionForCurrentUrl();
|
|
34
31
|
window.history.pushState(null, '', url);
|
|
35
32
|
executeAsync(url, 0);
|
|
36
33
|
DomeManipulator.scrollToTop();
|
|
34
|
+
// historyUrls.push()
|
|
37
35
|
}
|
|
38
36
|
DomeRouter.navigate = navigate;
|
|
39
37
|
function goBack() {
|
|
@@ -51,33 +49,35 @@ export var DomeRouter;
|
|
|
51
49
|
// }
|
|
52
50
|
}
|
|
53
51
|
DomeRouter.changeUrl = changeUrl;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
function addUrlToHistory(url) {
|
|
53
|
+
historyUrls.push({ url, scroll: 0 });
|
|
54
|
+
while (historyUrls.length > DomeRouter.maxHistoryUrlsCount) {
|
|
55
|
+
historyUrls.shift();
|
|
56
|
+
}
|
|
57
|
+
// save scroll position to previous url
|
|
58
|
+
if (historyUrls.length > 1) {
|
|
59
|
+
historyUrls[historyUrls.length - 2].scroll = DomeManipulator.getCurrentScrollPosition();
|
|
60
|
+
}
|
|
61
|
+
console.log('adding url to history', url);
|
|
62
|
+
console.log('historyUrls=', historyUrls);
|
|
63
|
+
}
|
|
66
64
|
function getCurrentUrl() {
|
|
67
65
|
return window.location.pathname;
|
|
68
66
|
// return historyUrls.length>0?historyUrls[historyUrls.length-1]:window.location.pathname
|
|
69
67
|
}
|
|
70
68
|
DomeRouter.getCurrentUrl = getCurrentUrl;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
/**
|
|
70
|
+
* get previous page url navigated by router
|
|
71
|
+
* @param previousPageIndex 0=previousPage, 1=previousPage-1, etc
|
|
72
|
+
*/
|
|
73
|
+
function getPreviousPageUrl(previousPageIndex = 0) {
|
|
74
|
+
//if(historyUrls.length==0) return undefined
|
|
75
|
+
let index = historyUrls.length - 2 - previousPageIndex;
|
|
76
|
+
if (index >= 0 && index < historyUrls.length)
|
|
77
|
+
return historyUrls[index].url;
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
DomeRouter.getPreviousPageUrl = getPreviousPageUrl;
|
|
81
81
|
// export function reloadCurrentPage(addToHistory:boolean = false){
|
|
82
82
|
// const url = window.location.pathname
|
|
83
83
|
// if(addToHistory) addUrlToHistory(url)
|
package/package.json
CHANGED
package/src/DomeRouter.ts
CHANGED
|
@@ -14,13 +14,13 @@ interface Route{
|
|
|
14
14
|
action:RouteAction
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
interface HistoryUrl{
|
|
18
|
+
url:string
|
|
19
|
+
scroll:number
|
|
20
|
+
}
|
|
21
21
|
|
|
22
22
|
export module DomeRouter {
|
|
23
|
-
|
|
23
|
+
const historyUrls:HistoryUrl[] = []
|
|
24
24
|
const scrollPositionByUrl = new Map<string, number>()
|
|
25
25
|
export let maxHistoryUrlsCount:number = 20
|
|
26
26
|
const allRoutes:Route[] = []
|
|
@@ -50,10 +50,12 @@ export module DomeRouter {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export function navigate(url:string){
|
|
53
|
+
addUrlToHistory(getCurrentUrl())
|
|
53
54
|
saveScrollPositionForCurrentUrl()
|
|
54
55
|
window.history.pushState(null, '', url)
|
|
55
56
|
executeAsync(url, 0)
|
|
56
57
|
DomeManipulator.scrollToTop()
|
|
58
|
+
// historyUrls.push()
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
export function goBack(){
|
|
@@ -71,20 +73,20 @@ export module DomeRouter {
|
|
|
71
73
|
// }
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
function addUrlToHistory(url:string){
|
|
77
|
+
historyUrls.push({url, scroll: 0})
|
|
78
|
+
while(historyUrls.length>maxHistoryUrlsCount){
|
|
79
|
+
historyUrls.shift()
|
|
80
|
+
}
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
// save scroll position to previous url
|
|
83
|
+
if(historyUrls.length>1){
|
|
84
|
+
historyUrls[historyUrls.length-2].scroll = DomeManipulator.getCurrentScrollPosition()
|
|
85
|
+
}
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
console.log('adding url to history', url)
|
|
88
|
+
console.log('historyUrls=', historyUrls)
|
|
89
|
+
}
|
|
88
90
|
|
|
89
91
|
|
|
90
92
|
|
|
@@ -93,16 +95,16 @@ export module DomeRouter {
|
|
|
93
95
|
// return historyUrls.length>0?historyUrls[historyUrls.length-1]:window.location.pathname
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
/**
|
|
99
|
+
* get previous page url navigated by router
|
|
100
|
+
* @param previousPageIndex 0=previousPage, 1=previousPage-1, etc
|
|
101
|
+
*/
|
|
102
|
+
export function getPreviousPageUrl(previousPageIndex:number=0):string|undefined{
|
|
103
|
+
//if(historyUrls.length==0) return undefined
|
|
104
|
+
let index = historyUrls.length-2-previousPageIndex
|
|
105
|
+
if(index >= 0 && index < historyUrls.length) return historyUrls[index].url
|
|
106
|
+
return undefined
|
|
107
|
+
}
|
|
106
108
|
|
|
107
109
|
// export function reloadCurrentPage(addToHistory:boolean = false){
|
|
108
110
|
// const url = window.location.pathname
|