@trullock/page-manager 0.6.2 → 0.6.6
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 +1 -2
- package/src/index.js +25 -10
- package/tests/dist/index.html +0 -18
- package/tests/dist/main.js +0 -1513
- package/tests/dist/main.js.map +0 -1
- package/tests/dist/page1.htm +0 -4
- package/tests/dist/page2.htm +0 -4
- package/tests/dist/page3.htm +0 -5
- package/tests/dist/page4.htm +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trullock/page-manager",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "Single page app manager",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.js",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@trullock/dollar": "^0.1.6",
|
|
21
20
|
"@trullock/router": "^0.2.5"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
package/src/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var lastNavigationDirection = null;
|
|
|
14
14
|
var goal = null;
|
|
15
15
|
var backData = {};
|
|
16
16
|
var options = {
|
|
17
|
-
fetchPath: route => '/pages/' + route.routeName + '.html',
|
|
17
|
+
fetchPath: route => '/pages/' + (route.pageClass.constructor.htmlName || route.routeName) + '.html',
|
|
18
18
|
fetchPageTemplate: route => {
|
|
19
19
|
return fetch(options.fetchPath(route))
|
|
20
20
|
.then(r => r.text())
|
|
@@ -40,14 +40,29 @@ var options = {
|
|
|
40
40
|
|
|
41
41
|
export const pages = pageHash;
|
|
42
42
|
|
|
43
|
-
export function registerPage(
|
|
43
|
+
export function registerPage(argA, argB, argC) {
|
|
44
|
+
|
|
45
|
+
let namedRoutes = null,
|
|
46
|
+
pageClass = null;
|
|
47
|
+
|
|
48
|
+
if(argC == undefined)
|
|
49
|
+
{
|
|
50
|
+
namedRoutes = argA;
|
|
51
|
+
pageClass = argB;
|
|
52
|
+
} else {
|
|
53
|
+
namedRoutes = {
|
|
54
|
+
[argA]: argB
|
|
55
|
+
};
|
|
56
|
+
pageClass = argC;
|
|
57
|
+
}
|
|
58
|
+
|
|
44
59
|
|
|
45
60
|
for (const [name, route] of Object.entries(namedRoutes)) {
|
|
46
61
|
router.addRoute(name, route, pageClass);
|
|
47
62
|
|
|
48
63
|
pageHash[name] = {
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
url: route,
|
|
65
|
+
pageClass: pageClass
|
|
51
66
|
}
|
|
52
67
|
}
|
|
53
68
|
|
|
@@ -99,7 +114,11 @@ function showPage(url, data, event) {
|
|
|
99
114
|
var route = router.parse(url);
|
|
100
115
|
if (route == null) {
|
|
101
116
|
console.error(`Can't find page: '${url}'`);
|
|
102
|
-
|
|
117
|
+
let page404 = pageHash[options.error404PageName];
|
|
118
|
+
if(!page404)
|
|
119
|
+
return Promise.reject(new PageShowError('/', `Can't find page: '${url}'. Also can't find 404 page: '${options.error404PageName}'`, {}, 'replace'));
|
|
120
|
+
|
|
121
|
+
return Promise.reject(new PageShowError(page404.url, `Can't find page: '${url}'`, {}, 'replace'));
|
|
103
122
|
}
|
|
104
123
|
|
|
105
124
|
data = data || {};
|
|
@@ -282,7 +301,7 @@ export function init(opts) {
|
|
|
282
301
|
showPage(window.location.pathname + window.location.search + window.location.hash, null, { action: 'load', distance: 0 }).catch(e => {
|
|
283
302
|
console.error(e);
|
|
284
303
|
if (e instanceof PageShowError)
|
|
285
|
-
return showPage(e.url, e.data, { action: e.action || 'show' });
|
|
304
|
+
return showPage(e.url, e.data, { action: stackPointer == -1 ? 'load' : e.action || 'show' });
|
|
286
305
|
});
|
|
287
306
|
|
|
288
307
|
function handlePopstate(context, direction, distance) {
|
|
@@ -425,10 +444,6 @@ export function navigate(url, data, checkBeforeUnload) {
|
|
|
425
444
|
doNavigate(url, data);
|
|
426
445
|
}
|
|
427
446
|
|
|
428
|
-
export function update(opts) {
|
|
429
|
-
state[statePointer].data = opts.data;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
447
|
export function replace(url, data) {
|
|
433
448
|
return showPage(url, data, { action: 'replace', distance: 0 });
|
|
434
449
|
}
|
package/tests/dist/index.html
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
<head>
|
|
3
|
-
<script defer src="/main.js"></script></head>
|
|
4
|
-
<body style="height: 100%;">
|
|
5
|
-
<div style="position: fixed; top: 0; background-color: white;">
|
|
6
|
-
<a href="/page1">Page 1</a>
|
|
7
|
-
<a href="/page2">Page 2</a>
|
|
8
|
-
<a href="/page3">Page 3</a>
|
|
9
|
-
<a href="/page4">Page 4</a>
|
|
10
|
-
</div>
|
|
11
|
-
<div id="page-loading">
|
|
12
|
-
Loading
|
|
13
|
-
</div>
|
|
14
|
-
<div>
|
|
15
|
-
<button class="btnStack">Print stack</button>
|
|
16
|
-
</div>
|
|
17
|
-
</body>
|
|
18
|
-
</html>
|