@trullock/page-manager 1.2.1 → 1.3.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/package.json +2 -2
- package/src/index.js +116 -59
- package/tests/dist/index.html +20 -0
- package/tests/dist/loading.htm +3 -0
- package/tests/dist/main.js +1648 -0
- package/tests/dist/main.js.map +1 -0
- package/tests/dist/page1.htm +6 -0
- package/tests/dist/page2.htm +6 -0
- package/tests/dist/page3.htm +5 -0
- package/tests/dist/page4.htm +4 -0
- package/tests/dist/page404.htm +3 -0
- package/tests/dist/pageX.htm +4 -0
- package/tests/helpers.js +11 -0
- package/tests/index.html +0 -3
- package/tests/loading.htm +3 -0
- package/tests/lolpack.js +5 -4
- package/tests/page-loading.js +11 -4
- package/tests/page-page1.js +17 -11
- package/tests/page-page2.js +18 -7
- package/tests/page-page3.js +16 -10
- package/tests/page-page4.js +14 -8
- package/tests/page-page404.js +10 -4
- package/tests/page-pageX.js +15 -9
- package/tests/page-show-fail.js +14 -9
- package/tests/page2.htm +3 -1
|
@@ -0,0 +1,1648 @@
|
|
|
1
|
+
/******/ (() => { // webpackBootstrap
|
|
2
|
+
/******/ "use strict";
|
|
3
|
+
/******/ var __webpack_modules__ = ({
|
|
4
|
+
|
|
5
|
+
/***/ "./tests/loading.htm":
|
|
6
|
+
/*!***************************!*\
|
|
7
|
+
!*** ./tests/loading.htm ***!
|
|
8
|
+
\***************************/
|
|
9
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
10
|
+
|
|
11
|
+
__webpack_require__.r(__webpack_exports__);
|
|
12
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
13
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
14
|
+
/* harmony export */ });
|
|
15
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (__webpack_require__.p + "loading.htm");
|
|
16
|
+
|
|
17
|
+
/***/ }),
|
|
18
|
+
|
|
19
|
+
/***/ "./tests/page1.htm":
|
|
20
|
+
/*!*************************!*\
|
|
21
|
+
!*** ./tests/page1.htm ***!
|
|
22
|
+
\*************************/
|
|
23
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
24
|
+
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
28
|
+
/* harmony export */ });
|
|
29
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (__webpack_require__.p + "page1.htm");
|
|
30
|
+
|
|
31
|
+
/***/ }),
|
|
32
|
+
|
|
33
|
+
/***/ "./tests/page2.htm":
|
|
34
|
+
/*!*************************!*\
|
|
35
|
+
!*** ./tests/page2.htm ***!
|
|
36
|
+
\*************************/
|
|
37
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
38
|
+
|
|
39
|
+
__webpack_require__.r(__webpack_exports__);
|
|
40
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
41
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
42
|
+
/* harmony export */ });
|
|
43
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (__webpack_require__.p + "page2.htm");
|
|
44
|
+
|
|
45
|
+
/***/ }),
|
|
46
|
+
|
|
47
|
+
/***/ "./tests/page3.htm":
|
|
48
|
+
/*!*************************!*\
|
|
49
|
+
!*** ./tests/page3.htm ***!
|
|
50
|
+
\*************************/
|
|
51
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
52
|
+
|
|
53
|
+
__webpack_require__.r(__webpack_exports__);
|
|
54
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
55
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
56
|
+
/* harmony export */ });
|
|
57
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (__webpack_require__.p + "page3.htm");
|
|
58
|
+
|
|
59
|
+
/***/ }),
|
|
60
|
+
|
|
61
|
+
/***/ "./tests/page4.htm":
|
|
62
|
+
/*!*************************!*\
|
|
63
|
+
!*** ./tests/page4.htm ***!
|
|
64
|
+
\*************************/
|
|
65
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
66
|
+
|
|
67
|
+
__webpack_require__.r(__webpack_exports__);
|
|
68
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
69
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
70
|
+
/* harmony export */ });
|
|
71
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (__webpack_require__.p + "page4.htm");
|
|
72
|
+
|
|
73
|
+
/***/ }),
|
|
74
|
+
|
|
75
|
+
/***/ "./tests/page404.htm":
|
|
76
|
+
/*!***************************!*\
|
|
77
|
+
!*** ./tests/page404.htm ***!
|
|
78
|
+
\***************************/
|
|
79
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
80
|
+
|
|
81
|
+
__webpack_require__.r(__webpack_exports__);
|
|
82
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
83
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
84
|
+
/* harmony export */ });
|
|
85
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (__webpack_require__.p + "page404.htm");
|
|
86
|
+
|
|
87
|
+
/***/ }),
|
|
88
|
+
|
|
89
|
+
/***/ "./tests/pageX.htm":
|
|
90
|
+
/*!*************************!*\
|
|
91
|
+
!*** ./tests/pageX.htm ***!
|
|
92
|
+
\*************************/
|
|
93
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
94
|
+
|
|
95
|
+
__webpack_require__.r(__webpack_exports__);
|
|
96
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
97
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
98
|
+
/* harmony export */ });
|
|
99
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (__webpack_require__.p + "pageX.htm");
|
|
100
|
+
|
|
101
|
+
/***/ }),
|
|
102
|
+
|
|
103
|
+
/***/ "./node_modules/@trullock/router/src/index.js":
|
|
104
|
+
/*!****************************************************!*\
|
|
105
|
+
!*** ./node_modules/@trullock/router/src/index.js ***!
|
|
106
|
+
\****************************************************/
|
|
107
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
108
|
+
|
|
109
|
+
__webpack_require__.r(__webpack_exports__);
|
|
110
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
111
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
112
|
+
/* harmony export */ });
|
|
113
|
+
/* harmony import */ var _pattern_lexer_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./pattern-lexer.js */ "./node_modules/@trullock/router/src/pattern-lexer.js");
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
function isKind(val, kind)
|
|
117
|
+
{
|
|
118
|
+
return '[object ' + kind + ']' === Object.prototype.toString.call(val);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isRegExp(val)
|
|
122
|
+
{
|
|
123
|
+
return isKind(val, 'RegExp');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function decodeQueryString(queryStr)
|
|
127
|
+
{
|
|
128
|
+
let queryArr = (queryStr || '').replace('?', '').split('&'),
|
|
129
|
+
i = -1,
|
|
130
|
+
obj = {},
|
|
131
|
+
equalIndex, cur, pValue, pName;
|
|
132
|
+
|
|
133
|
+
while ((cur = queryArr[++i]))
|
|
134
|
+
{
|
|
135
|
+
equalIndex = cur.indexOf('=');
|
|
136
|
+
pName = cur.substring(0, equalIndex);
|
|
137
|
+
pValue = decodeURIComponent(cur.substring(equalIndex + 1));
|
|
138
|
+
|
|
139
|
+
if (pName in obj)
|
|
140
|
+
{
|
|
141
|
+
if(isArray(obj[pName]))
|
|
142
|
+
obj[pName].push(pValue);
|
|
143
|
+
else
|
|
144
|
+
obj[pName] = [obj[pName], pValue];
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
else
|
|
148
|
+
{
|
|
149
|
+
obj[pName] = pValue;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return obj;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function Route(name, pattern, data, priority, router) {
|
|
156
|
+
var isRegexPattern = isRegExp(pattern);
|
|
157
|
+
this._name = name;
|
|
158
|
+
this._router = router;
|
|
159
|
+
this._pattern = pattern;
|
|
160
|
+
this._paramsIds = isRegexPattern ? null : router.patternLexer.getParamIds(pattern);
|
|
161
|
+
this._optionalParamsIds = isRegexPattern ? null : router.patternLexer.getOptionalParamsIds(pattern);
|
|
162
|
+
this._matchRegexp = isRegexPattern ? pattern : router.patternLexer.compilePattern(pattern, router.ignoreCase);
|
|
163
|
+
this._data = data;
|
|
164
|
+
this._priority = priority || 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
Route.prototype = {
|
|
168
|
+
|
|
169
|
+
match: function (request) {
|
|
170
|
+
return this._matchRegexp.test(request);
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
_isValidParam: function (request, prop, values) {
|
|
174
|
+
var validationRule = this.rules[prop],
|
|
175
|
+
val = values[prop],
|
|
176
|
+
isValid = false,
|
|
177
|
+
isQuery = (prop.indexOf('?') === 0);
|
|
178
|
+
|
|
179
|
+
if (val == null && this._optionalParamsIds && arrayIndexOf(this._optionalParamsIds, prop) !== -1) {
|
|
180
|
+
isValid = true;
|
|
181
|
+
}
|
|
182
|
+
else if (isRegExp(validationRule)) {
|
|
183
|
+
if (isQuery)
|
|
184
|
+
val = values[prop + '_']; //use raw string
|
|
185
|
+
|
|
186
|
+
isValid = validationRule.test(val);
|
|
187
|
+
}
|
|
188
|
+
else if (isArray(validationRule)) {
|
|
189
|
+
if (isQuery)
|
|
190
|
+
val = values[prop + '_']; //use raw string
|
|
191
|
+
|
|
192
|
+
isValid = this._isValidArrayRule(validationRule, val);
|
|
193
|
+
}
|
|
194
|
+
else if (isFunction(validationRule)) {
|
|
195
|
+
isValid = validationRule(val, request, values);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return isValid; //fail silently if validationRule is from an unsupported type
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
_isValidArrayRule: function (arr, val) {
|
|
202
|
+
if (!this._router.ignoreCase) {
|
|
203
|
+
return arrayIndexOf(arr, val) !== -1;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (typeof val === 'string') {
|
|
207
|
+
val = val.toLowerCase();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
var n = arr.length,
|
|
211
|
+
item,
|
|
212
|
+
compareVal;
|
|
213
|
+
|
|
214
|
+
while (n--) {
|
|
215
|
+
item = arr[n];
|
|
216
|
+
compareVal = (typeof item === 'string') ? item.toLowerCase() : item;
|
|
217
|
+
if (compareVal === val) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
_getParamsObject: function (request) {
|
|
225
|
+
var shouldTypecast = this._router.shouldTypecast,
|
|
226
|
+
values = this._router.patternLexer.getParamValues(request, this._matchRegexp, shouldTypecast),
|
|
227
|
+
o = {},
|
|
228
|
+
n = values.length,
|
|
229
|
+
param, val;
|
|
230
|
+
while (n--) {
|
|
231
|
+
val = values[n];
|
|
232
|
+
if (this._paramsIds) {
|
|
233
|
+
param = this._paramsIds[n];
|
|
234
|
+
if (param.indexOf('?') === 0 && val) {
|
|
235
|
+
val = decodeQueryString(val, shouldTypecast);
|
|
236
|
+
|
|
237
|
+
for(var key in val){
|
|
238
|
+
if(!o[key])
|
|
239
|
+
o[key] = val[key];
|
|
240
|
+
else
|
|
241
|
+
o['?' + key] = val[key];
|
|
242
|
+
}
|
|
243
|
+
o[n] = val;
|
|
244
|
+
}
|
|
245
|
+
else
|
|
246
|
+
o[param] = val;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return o;
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
interpolate: function (replacements) {
|
|
254
|
+
try {
|
|
255
|
+
var str = this._router.patternLexer.interpolate(this._pattern, replacements);
|
|
256
|
+
return str;
|
|
257
|
+
}
|
|
258
|
+
catch(e) {
|
|
259
|
+
throw new Error(`Error interpolating route ${this._pattern} with values ${JSON.stringify(replacements)}\n` + e);
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
toString: function () {
|
|
264
|
+
return '[Route pattern:"' + this._pattern + '", numListeners:' + this.matched.getNumListeners() + ']';
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (new class
|
|
271
|
+
{
|
|
272
|
+
constructor()
|
|
273
|
+
{
|
|
274
|
+
this.routes = [];
|
|
275
|
+
this.routesByName = {};
|
|
276
|
+
this.patternLexer = (0,_pattern_lexer_js__WEBPACK_IMPORTED_MODULE_0__["default"])();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
addRoute (name, pattern, data, priority)
|
|
280
|
+
{
|
|
281
|
+
pattern += pattern.endsWith('/') ? ':?query:' : '/:?query:';
|
|
282
|
+
var route = new Route(name, pattern, data, priority, this);
|
|
283
|
+
|
|
284
|
+
var n = this.routes.length;
|
|
285
|
+
do
|
|
286
|
+
{
|
|
287
|
+
--n;
|
|
288
|
+
} while (this.routes[n] && route._priority <= this.routes[n]._priority);
|
|
289
|
+
|
|
290
|
+
this.routes.splice(n + 1, 0, route);
|
|
291
|
+
|
|
292
|
+
this.routesByName[name] = route;
|
|
293
|
+
Object.defineProperty(this, name, { get: () => pattern });
|
|
294
|
+
|
|
295
|
+
return route;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
interpolate(name, data)
|
|
299
|
+
{
|
|
300
|
+
if(!this.routesByName[name])
|
|
301
|
+
throw new Error(`Cannot find route by name ${name}`);
|
|
302
|
+
|
|
303
|
+
return this.routesByName[name].interpolate(data);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
parse (request)
|
|
307
|
+
{
|
|
308
|
+
var n = this.routes.length;
|
|
309
|
+
var route, hash, path;
|
|
310
|
+
|
|
311
|
+
var index = request.indexOf('#');
|
|
312
|
+
if(index > -1)
|
|
313
|
+
{
|
|
314
|
+
hash = request.substr(index + 1);
|
|
315
|
+
request = request.substr(0, index);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
index = request.indexOf('?');
|
|
319
|
+
if(index > -1)
|
|
320
|
+
path = request.substr(0, index)
|
|
321
|
+
else
|
|
322
|
+
path = request;
|
|
323
|
+
|
|
324
|
+
while (route = this.routes[--n])
|
|
325
|
+
{
|
|
326
|
+
if (route.match(request))
|
|
327
|
+
{
|
|
328
|
+
var params = route._getParamsObject(request);
|
|
329
|
+
params.hash = hash;
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
path: path.toLowerCase(),
|
|
333
|
+
name: route._name,
|
|
334
|
+
pattern: route._pattern,
|
|
335
|
+
data: route._data,
|
|
336
|
+
params: params
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
toString ()
|
|
345
|
+
{
|
|
346
|
+
return '[Router numRoutes:' + this.getNumRoutes() + ']';
|
|
347
|
+
}
|
|
348
|
+
}());
|
|
349
|
+
|
|
350
|
+
/***/ }),
|
|
351
|
+
|
|
352
|
+
/***/ "./node_modules/@trullock/router/src/pattern-lexer.js":
|
|
353
|
+
/*!************************************************************!*\
|
|
354
|
+
!*** ./node_modules/@trullock/router/src/pattern-lexer.js ***!
|
|
355
|
+
\************************************************************/
|
|
356
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
357
|
+
|
|
358
|
+
__webpack_require__.r(__webpack_exports__);
|
|
359
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
360
|
+
/* harmony export */ "default": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)
|
|
361
|
+
/* harmony export */ });
|
|
362
|
+
/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() {
|
|
363
|
+
|
|
364
|
+
var
|
|
365
|
+
//match chars that should be escaped on string regexp
|
|
366
|
+
ESCAPE_CHARS_REGEXP = /[\\.+*?\^$\[\](){}\/'#]/g,
|
|
367
|
+
|
|
368
|
+
//trailing slashes (begin/end of string)
|
|
369
|
+
LOOSE_SLASHES_REGEXP = /^\/|\/$/g,
|
|
370
|
+
LEGACY_SLASHES_REGEXP = /\/$/g,
|
|
371
|
+
|
|
372
|
+
//params - everything between `{ }` or `: :`
|
|
373
|
+
PARAMS_REGEXP = /(?:\{|:)([^}:]+)(?:\}|:)/g,
|
|
374
|
+
|
|
375
|
+
//used to save params during compile (avoid escaping things that
|
|
376
|
+
//shouldn't be escaped).
|
|
377
|
+
TOKENS = {
|
|
378
|
+
'OS': {
|
|
379
|
+
//optional slashes
|
|
380
|
+
//slash between `::` or `}:` or `\w:` or `:{?` or `}{?` or `\w{?`
|
|
381
|
+
rgx: /([:}]|\w(?=\/))\/?(:|(?:\{\?))/g,
|
|
382
|
+
save: '$1{{id}}$2',
|
|
383
|
+
res: '\\/?'
|
|
384
|
+
},
|
|
385
|
+
'RS': {
|
|
386
|
+
//required slashes
|
|
387
|
+
//used to insert slash between `:{` and `}{`
|
|
388
|
+
rgx: /([:}])\/?(\{)/g,
|
|
389
|
+
save: '$1{{id}}$2',
|
|
390
|
+
res: '\\/'
|
|
391
|
+
},
|
|
392
|
+
'RQ': {
|
|
393
|
+
//required query string - everything in between `{? }`
|
|
394
|
+
rgx: /\{\?([^}]+)\}/g,
|
|
395
|
+
//everything from `?` till `#` or end of string
|
|
396
|
+
res: '\\?([^#]+)'
|
|
397
|
+
},
|
|
398
|
+
'OQ': {
|
|
399
|
+
//optional query string - everything in between `:? :`
|
|
400
|
+
rgx: /:\?([^:]+):/g,
|
|
401
|
+
//everything from `?` till `#` or end of string
|
|
402
|
+
res: '(?:\\?([^#]*))?'
|
|
403
|
+
},
|
|
404
|
+
'OR': {
|
|
405
|
+
//optional rest - everything in between `: *:`
|
|
406
|
+
rgx: /:([^:]+)\*:/g,
|
|
407
|
+
res: '(.*)?' // optional group to avoid passing empty string as captured
|
|
408
|
+
},
|
|
409
|
+
'RR': {
|
|
410
|
+
//rest param - everything in between `{ *}`
|
|
411
|
+
rgx: /\{([^}]+)\*\}/g,
|
|
412
|
+
res: '(.+)'
|
|
413
|
+
},
|
|
414
|
+
// required/optional params should come after rest segments
|
|
415
|
+
'RP': {
|
|
416
|
+
//required params - everything between `{ }`
|
|
417
|
+
rgx: /\{([^}]+)\}/g,
|
|
418
|
+
res: '([^\\/?]+)'
|
|
419
|
+
},
|
|
420
|
+
'OP': {
|
|
421
|
+
//optional params - everything between `: :`
|
|
422
|
+
rgx: /:([^:]+):/g,
|
|
423
|
+
res: '([^\\/?]+)?\/?'
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
|
|
427
|
+
LOOSE_SLASH = 1,
|
|
428
|
+
STRICT_SLASH = 2,
|
|
429
|
+
LEGACY_SLASH = 3,
|
|
430
|
+
|
|
431
|
+
_slashMode = LOOSE_SLASH;
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
function precompileTokens() {
|
|
435
|
+
var key, cur;
|
|
436
|
+
for (key in TOKENS) {
|
|
437
|
+
if (TOKENS.hasOwnProperty(key)) {
|
|
438
|
+
cur = TOKENS[key];
|
|
439
|
+
cur.id = '__CR_' + key + '__';
|
|
440
|
+
cur.save = ('save' in cur) ? cur.save.replace('{{id}}', cur.id) : cur.id;
|
|
441
|
+
cur.rRestore = new RegExp(cur.id, 'g');
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
precompileTokens();
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
function captureVals(regex, pattern) {
|
|
449
|
+
var vals = [], match;
|
|
450
|
+
// very important to reset lastIndex since RegExp can have "g" flag
|
|
451
|
+
// and multiple runs might affect the result, specially if matching
|
|
452
|
+
// same string multiple times on IE 7-8
|
|
453
|
+
regex.lastIndex = 0;
|
|
454
|
+
while (match = regex.exec(pattern)) {
|
|
455
|
+
vals.push(match[1]);
|
|
456
|
+
}
|
|
457
|
+
return vals;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function getParamIds(pattern) {
|
|
461
|
+
return captureVals(PARAMS_REGEXP, pattern);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function getOptionalParamsIds(pattern) {
|
|
465
|
+
return captureVals(TOKENS.OP.rgx, pattern);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function compilePattern(pattern, ignoreCase) {
|
|
469
|
+
pattern = pattern || '';
|
|
470
|
+
|
|
471
|
+
if (pattern) {
|
|
472
|
+
if (_slashMode === LOOSE_SLASH) {
|
|
473
|
+
pattern = pattern.replace(LOOSE_SLASHES_REGEXP, '');
|
|
474
|
+
}
|
|
475
|
+
else if (_slashMode === LEGACY_SLASH) {
|
|
476
|
+
pattern = pattern.replace(LEGACY_SLASHES_REGEXP, '');
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
//save tokens
|
|
480
|
+
pattern = replaceTokens(pattern, 'rgx', 'save');
|
|
481
|
+
//regexp escape
|
|
482
|
+
pattern = pattern.replace(ESCAPE_CHARS_REGEXP, '\\$&');
|
|
483
|
+
//restore tokens
|
|
484
|
+
pattern = replaceTokens(pattern, 'rRestore', 'res');
|
|
485
|
+
|
|
486
|
+
if (_slashMode === LOOSE_SLASH) {
|
|
487
|
+
pattern = '\\/?' + pattern;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (_slashMode !== STRICT_SLASH) {
|
|
492
|
+
//single slash is treated as empty and end slash is optional
|
|
493
|
+
pattern += '\\/?';
|
|
494
|
+
}
|
|
495
|
+
return new RegExp('^' + pattern + '$', ignoreCase ? 'i' : '');
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function replaceTokens(pattern, regexpName, replaceName) {
|
|
499
|
+
var cur, key;
|
|
500
|
+
for (key in TOKENS) {
|
|
501
|
+
if (TOKENS.hasOwnProperty(key)) {
|
|
502
|
+
cur = TOKENS[key];
|
|
503
|
+
pattern = pattern.replace(cur[regexpName], cur[replaceName]);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return pattern;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function getParamValues(request, regexp, shouldTypecast) {
|
|
510
|
+
var vals = regexp.exec(request);
|
|
511
|
+
if (vals) {
|
|
512
|
+
vals.shift();
|
|
513
|
+
if (shouldTypecast) {
|
|
514
|
+
vals = typecastArrayValues(vals);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return vals;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function interpolate(pattern, replacements) {
|
|
521
|
+
// default to an empty object because pattern might have just
|
|
522
|
+
// optional arguments
|
|
523
|
+
replacements = replacements || {};
|
|
524
|
+
if (typeof pattern !== 'string') {
|
|
525
|
+
throw new Error('Route pattern should be a string.');
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
var replaceFn = function (match, prop) {
|
|
529
|
+
var val;
|
|
530
|
+
prop = (prop.substr(0, 1) === '?') ? prop.substr(1) : prop;
|
|
531
|
+
if (replacements[prop] != null) {
|
|
532
|
+
if (typeof replacements[prop] === 'object') {
|
|
533
|
+
var queryParts = [], rep;
|
|
534
|
+
for (var key in replacements[prop]) {
|
|
535
|
+
rep = replacements[prop][key];
|
|
536
|
+
if (isArray(rep)) {
|
|
537
|
+
for (var k in rep) {
|
|
538
|
+
if (key.slice(-2) == '[]') {
|
|
539
|
+
queryParts.push(encodeURIComponent(key.slice(0, -2)) + '[]=' + encodeURIComponent(rep[k]));
|
|
540
|
+
} else {
|
|
541
|
+
queryParts.push(encodeURIComponent(key + '=' + rep[k]));
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
queryParts.push(encodeURIComponent(key + '=' + rep));
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
val = '?' + queryParts.join('&');
|
|
550
|
+
} else {
|
|
551
|
+
// make sure value is a string see #gh-54
|
|
552
|
+
val = String(replacements[prop]);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
if (match.indexOf('*') === -1 && val.indexOf('/') !== -1) {
|
|
556
|
+
throw new Error('Invalid value "' + val + '" for segment "' + match + '".');
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
else if (match.indexOf('{') !== -1) {
|
|
560
|
+
throw new Error('The segment ' + match + ' is required.');
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
val = '';
|
|
564
|
+
}
|
|
565
|
+
return val;
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
if (!TOKENS.OS.trail) {
|
|
569
|
+
TOKENS.OS.trail = new RegExp('(?:' + TOKENS.OS.id + ')+$');
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
return pattern
|
|
573
|
+
.replace(TOKENS.OS.rgx, TOKENS.OS.save)
|
|
574
|
+
.replace(PARAMS_REGEXP, replaceFn)
|
|
575
|
+
.replace(TOKENS.OS.trail, '') // remove trailing
|
|
576
|
+
.replace(TOKENS.OS.rRestore, '/'); // add slash between segments
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
//API
|
|
580
|
+
return {
|
|
581
|
+
strict: function () {
|
|
582
|
+
_slashMode = STRICT_SLASH;
|
|
583
|
+
},
|
|
584
|
+
loose: function () {
|
|
585
|
+
_slashMode = LOOSE_SLASH;
|
|
586
|
+
},
|
|
587
|
+
legacy: function () {
|
|
588
|
+
_slashMode = LEGACY_SLASH;
|
|
589
|
+
},
|
|
590
|
+
getParamIds: getParamIds,
|
|
591
|
+
getOptionalParamsIds: getOptionalParamsIds,
|
|
592
|
+
getParamValues: getParamValues,
|
|
593
|
+
compilePattern: compilePattern,
|
|
594
|
+
interpolate: interpolate
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/***/ }),
|
|
600
|
+
|
|
601
|
+
/***/ "./src/index.js":
|
|
602
|
+
/*!**********************!*\
|
|
603
|
+
!*** ./src/index.js ***!
|
|
604
|
+
\**********************/
|
|
605
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
606
|
+
|
|
607
|
+
__webpack_require__.r(__webpack_exports__);
|
|
608
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
609
|
+
/* harmony export */ "PageShowError": () => (/* binding */ PageShowError),
|
|
610
|
+
/* harmony export */ "back": () => (/* binding */ back),
|
|
611
|
+
/* harmony export */ "getPath": () => (/* binding */ getPath),
|
|
612
|
+
/* harmony export */ "init": () => (/* binding */ init),
|
|
613
|
+
/* harmony export */ "navigate": () => (/* binding */ navigate),
|
|
614
|
+
/* harmony export */ "printStack": () => (/* binding */ printStack),
|
|
615
|
+
/* harmony export */ "purgeCache": () => (/* binding */ purgeCache),
|
|
616
|
+
/* harmony export */ "ready": () => (/* binding */ ready),
|
|
617
|
+
/* harmony export */ "refresh": () => (/* binding */ refresh),
|
|
618
|
+
/* harmony export */ "registerPage": () => (/* binding */ registerPage),
|
|
619
|
+
/* harmony export */ "removeHistory": () => (/* binding */ removeHistory),
|
|
620
|
+
/* harmony export */ "replace": () => (/* binding */ replace),
|
|
621
|
+
/* harmony export */ "show": () => (/* binding */ show)
|
|
622
|
+
/* harmony export */ });
|
|
623
|
+
/* harmony import */ var _trullock_router__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @trullock/router */ "./node_modules/@trullock/router/src/index.js");
|
|
624
|
+
|
|
625
|
+
var pageCache = {},
|
|
626
|
+
pageTemplateCache = {},
|
|
627
|
+
stack = [],
|
|
628
|
+
stackPointer = -1;
|
|
629
|
+
var manuallyAdjustingHistory = false;
|
|
630
|
+
var handlingBeforeHide = false;
|
|
631
|
+
var beforeHideNavDirection = null;
|
|
632
|
+
var goal = null;
|
|
633
|
+
var backData = {};
|
|
634
|
+
var options = {
|
|
635
|
+
pageInterrupt: routeResult => null,
|
|
636
|
+
attachMarkup: $html => document.body.appendChild($html),
|
|
637
|
+
prepareMarkup: $html => {},
|
|
638
|
+
loadingPageName: 'loading',
|
|
639
|
+
error404PageName: 'error-404',
|
|
640
|
+
defaultPageName: 'root',
|
|
641
|
+
beforeHide: null
|
|
642
|
+
};
|
|
643
|
+
function registerPage(opts) {
|
|
644
|
+
let loadPageClass = opts.pageClass ? () => opts.pageClass : opts.loadPageClass;
|
|
645
|
+
let namedRoutes = opts.namedRoutes || {
|
|
646
|
+
[opts.name]: opts.route
|
|
647
|
+
};
|
|
648
|
+
let cacheMarkupBy = opts.cacheMarkupBy || 'path';
|
|
649
|
+
let extra = opts.extra || {};
|
|
650
|
+
for (const [name, route] of Object.entries(namedRoutes)) {
|
|
651
|
+
_trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].addRoute(name, route, {
|
|
652
|
+
route,
|
|
653
|
+
loadPageClass,
|
|
654
|
+
loadMarkup: opts.loadMarkup,
|
|
655
|
+
cacheMarkupBy,
|
|
656
|
+
extra
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
function getPath(name, values) {
|
|
661
|
+
let url = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].interpolate(name, values);
|
|
662
|
+
if (values?.hash) url += '#' + values.hash;
|
|
663
|
+
return url;
|
|
664
|
+
}
|
|
665
|
+
function refresh() {
|
|
666
|
+
let frame = stack[stackPointer];
|
|
667
|
+
showPage(frame.data.route.url, frame.data, 'replace');
|
|
668
|
+
}
|
|
669
|
+
function emitUrlChanged(url) {
|
|
670
|
+
window.dispatchEvent(new CustomEvent('page-manager.url-changed', {
|
|
671
|
+
detail: {
|
|
672
|
+
url: url
|
|
673
|
+
},
|
|
674
|
+
bubbles: true
|
|
675
|
+
}));
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// TODO: 404 and error too?
|
|
679
|
+
function initLoading() {
|
|
680
|
+
var url = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].interpolate(options.loadingPageName, {});
|
|
681
|
+
var routeResult = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].parse(url);
|
|
682
|
+
return loadPage(routeResult, {});
|
|
683
|
+
}
|
|
684
|
+
function showLoading() {
|
|
685
|
+
var url = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].interpolate(options.loadingPageName, {});
|
|
686
|
+
var route = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].parse(url);
|
|
687
|
+
var data = {
|
|
688
|
+
route: route,
|
|
689
|
+
scrollY: window.scrollY,
|
|
690
|
+
event: {
|
|
691
|
+
action: 'replace'
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
var page = (pageCache[route.path] || pageCache[route.pattern]).page;
|
|
695
|
+
return Promise.resolve(page.show(data));
|
|
696
|
+
}
|
|
697
|
+
function hideLoading() {
|
|
698
|
+
var url = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].interpolate(options.loadingPageName, {});
|
|
699
|
+
var route = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].parse(url);
|
|
700
|
+
var page = (pageCache[route.path] || pageCache[route.pattern]).page;
|
|
701
|
+
return Promise.resolve(page.hide());
|
|
702
|
+
}
|
|
703
|
+
async function loadPage(routeResult, data) {
|
|
704
|
+
if (!pageTemplateCache[routeResult.pattern]) pageTemplateCache[routeResult.pattern] = await routeResult.data.loadMarkup(routeResult);
|
|
705
|
+
let $template = pageTemplateCache[routeResult.pattern];
|
|
706
|
+
var $html = $template.cloneNode(true);
|
|
707
|
+
options.prepareMarkup($html);
|
|
708
|
+
options.attachMarkup($html);
|
|
709
|
+
routeResult.data.pageClass = await Promise.resolve(routeResult.data.loadPageClass());
|
|
710
|
+
let page = new routeResult.data.pageClass($html);
|
|
711
|
+
await Promise.resolve(page.boot(data));
|
|
712
|
+
let cacheKey = routeResult.data.cacheMarkupBy == 'path' ? routeResult.path : routeResult.pattern;
|
|
713
|
+
pageCache[cacheKey] = {
|
|
714
|
+
$html,
|
|
715
|
+
page
|
|
716
|
+
};
|
|
717
|
+
return page;
|
|
718
|
+
}
|
|
719
|
+
async function showPage(url, data, event) {
|
|
720
|
+
var routeResult = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].parse(url);
|
|
721
|
+
if (routeResult == null) {
|
|
722
|
+
console.error(`Can't find page: '${url}'`);
|
|
723
|
+
let url = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].interpolate(options.error404PageName, {});
|
|
724
|
+
routeResult = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].parse(url);
|
|
725
|
+
}
|
|
726
|
+
data = data || {};
|
|
727
|
+
for (let key in routeResult.params) data[key] = routeResult.params[key];
|
|
728
|
+
data.route = {
|
|
729
|
+
url: url,
|
|
730
|
+
path: routeResult.path,
|
|
731
|
+
name: routeResult.name,
|
|
732
|
+
params: routeResult.params
|
|
733
|
+
};
|
|
734
|
+
data.event = event;
|
|
735
|
+
let interrupt = await Promise.resolve(options.pageInterrupt(routeResult));
|
|
736
|
+
if (interrupt) {
|
|
737
|
+
goal = {
|
|
738
|
+
url,
|
|
739
|
+
data
|
|
740
|
+
};
|
|
741
|
+
return showPage(interrupt.url, null, event);
|
|
742
|
+
}
|
|
743
|
+
await showLoading();
|
|
744
|
+
var getPage = null;
|
|
745
|
+
if (pageCache[routeResult.path]) getPage = pageCache[routeResult.path].page;else if (pageCache[routeResult.pattern]) getPage = pageCache[routeResult.pattern].page;else getPage = loadPage(routeResult, data);
|
|
746
|
+
|
|
747
|
+
// handle initial page
|
|
748
|
+
if (event.action == 'load') {
|
|
749
|
+
const page = await getPage;
|
|
750
|
+
await doShow(page, data);
|
|
751
|
+
await hideLoading();
|
|
752
|
+
|
|
753
|
+
// clean initial load
|
|
754
|
+
if (stackPointer == -1) {
|
|
755
|
+
stack.push({
|
|
756
|
+
uid: 0,
|
|
757
|
+
data,
|
|
758
|
+
page
|
|
759
|
+
});
|
|
760
|
+
stackPointer = 0;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// page refresh
|
|
764
|
+
else {
|
|
765
|
+
stack[stackPointer].page = page;
|
|
766
|
+
stack[stackPointer].data = data;
|
|
767
|
+
}
|
|
768
|
+
return page;
|
|
769
|
+
}
|
|
770
|
+
let currentState = stack[stackPointer];
|
|
771
|
+
if (currentState.data.route.path == routeResult.path) {
|
|
772
|
+
handleHistoryAction(event, url, data, currentState.page);
|
|
773
|
+
const page = await getPage;
|
|
774
|
+
await doUpdate(page, data);
|
|
775
|
+
await hideLoading();
|
|
776
|
+
return page;
|
|
777
|
+
}
|
|
778
|
+
currentState.data.scrollY = window.scrollY;
|
|
779
|
+
const results = await Promise.all([currentState.page.hide(event), getPage]);
|
|
780
|
+
const page = results[1];
|
|
781
|
+
handleHistoryAction(event, url, data, page);
|
|
782
|
+
await doShow(page, data);
|
|
783
|
+
// .catch(e => {
|
|
784
|
+
// // TODO: what case is this?
|
|
785
|
+
// manuallyAdjustingHistory = () => manuallyAdjustingHistory = false;
|
|
786
|
+
// if (event.action == 'back')
|
|
787
|
+
// history.go(1);
|
|
788
|
+
// else if (event.action == 'fwd')
|
|
789
|
+
// history.go(-1);
|
|
790
|
+
// });
|
|
791
|
+
await hideLoading();
|
|
792
|
+
return page;
|
|
793
|
+
}
|
|
794
|
+
async function doShow(page, data) {
|
|
795
|
+
window.scroll(0, 0);
|
|
796
|
+
await Promise.resolve(page.show(data));
|
|
797
|
+
document.title = page.title;
|
|
798
|
+
}
|
|
799
|
+
async function doUpdate(page, data) {
|
|
800
|
+
await Promise.resolve(page.update(data));
|
|
801
|
+
document.title = page.title;
|
|
802
|
+
}
|
|
803
|
+
async function handleHistoryAction(event, url, data, page) {
|
|
804
|
+
if (event.action == 'push') {
|
|
805
|
+
let newUid = stack[stackPointer].uid + 1;
|
|
806
|
+
window.history.pushState({
|
|
807
|
+
uid: newUid
|
|
808
|
+
}, null, url);
|
|
809
|
+
emitUrlChanged(url);
|
|
810
|
+
|
|
811
|
+
// remove future
|
|
812
|
+
stack.splice(stackPointer + 1, stack.length - stackPointer);
|
|
813
|
+
stack.push({
|
|
814
|
+
uid: newUid,
|
|
815
|
+
data,
|
|
816
|
+
page
|
|
817
|
+
});
|
|
818
|
+
stackPointer++;
|
|
819
|
+
} else if (event.action == 'replace') {
|
|
820
|
+
let currentUid = stack[stackPointer].uid;
|
|
821
|
+
window.history.replaceState({
|
|
822
|
+
uid: currentUid
|
|
823
|
+
}, null, url);
|
|
824
|
+
emitUrlChanged(url);
|
|
825
|
+
stack[stackPointer] = {
|
|
826
|
+
uid: currentUid,
|
|
827
|
+
data,
|
|
828
|
+
page
|
|
829
|
+
};
|
|
830
|
+
if (stack[stackPointer].data.route.url == stack[stackPointer - 1]?.data?.route?.url) {
|
|
831
|
+
let statesToKeep = [];
|
|
832
|
+
for (var i = 0; i < stackPointer - 1; i++) statesToKeep.push(stack[i]);
|
|
833
|
+
statesToKeep.push(stack[stackPointer]);
|
|
834
|
+
await modifyHistory(statesToKeep);
|
|
835
|
+
}
|
|
836
|
+
} else if (event.action == 'back') {
|
|
837
|
+
stackPointer -= event.distance;
|
|
838
|
+
} else if (event.action == 'fwd') {
|
|
839
|
+
stackPointer += event.distance;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function doNavigate(url, data) {
|
|
843
|
+
if (url === 'goal') {
|
|
844
|
+
url = goal ? goal.url : data?.fallback || getPath(options.defaultPageName);
|
|
845
|
+
data = goal?.data || {};
|
|
846
|
+
goal = null;
|
|
847
|
+
}
|
|
848
|
+
return showPage(url, data, {
|
|
849
|
+
action: 'push',
|
|
850
|
+
distance: 0
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
function storageAvailable() {
|
|
854
|
+
try {
|
|
855
|
+
var x = '__storage_test__';
|
|
856
|
+
window.sessionStorage.setItem(x, x);
|
|
857
|
+
window.sessionStorage.removeItem(x);
|
|
858
|
+
return true;
|
|
859
|
+
} catch (e) {
|
|
860
|
+
return false;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
async function init(opts) {
|
|
864
|
+
Object.assign(options, opts);
|
|
865
|
+
if (storageAvailable()) {
|
|
866
|
+
let storedStack = window.sessionStorage.getItem("stack");
|
|
867
|
+
if (storedStack) {
|
|
868
|
+
storedStack = JSON.parse(storedStack);
|
|
869
|
+
stack = storedStack.stack;
|
|
870
|
+
stackPointer = storedStack.stackPointer;
|
|
871
|
+
window.sessionStorage.removeItem("stack");
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
await initLoading();
|
|
875
|
+
await showLoading();
|
|
876
|
+
}
|
|
877
|
+
async function ready() {
|
|
878
|
+
// set initial page
|
|
879
|
+
emitUrlChanged(window.location.pathname + window.location.search + window.location.hash);
|
|
880
|
+
showPage(window.location.pathname + window.location.search + window.location.hash, null, {
|
|
881
|
+
action: 'load',
|
|
882
|
+
distance: 0
|
|
883
|
+
}).catch(e => {
|
|
884
|
+
console.error(e);
|
|
885
|
+
if (e instanceof PageShowError) {
|
|
886
|
+
return showPage(e.url, e.data, {
|
|
887
|
+
action: 'load',
|
|
888
|
+
distance: 0
|
|
889
|
+
}).then(async page => {
|
|
890
|
+
if (e.action == 'replace') await handleHistoryAction({
|
|
891
|
+
action: e.action
|
|
892
|
+
}, e.url, e.data, page);
|
|
893
|
+
return page;
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
async function handlePopstate(context, direction, distance) {
|
|
898
|
+
if (manuallyAdjustingHistory) {
|
|
899
|
+
await manuallyAdjustingHistory(context, {
|
|
900
|
+
action: direction,
|
|
901
|
+
distance
|
|
902
|
+
});
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
if (direction == 'back') Object.assign(context.data, backData);
|
|
906
|
+
backData = {};
|
|
907
|
+
emitUrlChanged(context.data.route.url);
|
|
908
|
+
showPage(context.data.route.url, context.data, {
|
|
909
|
+
action: direction,
|
|
910
|
+
distance
|
|
911
|
+
}).catch(e => {
|
|
912
|
+
console.error(e);
|
|
913
|
+
if (e instanceof PageShowError) return showPage(e.url, e.data, {
|
|
914
|
+
action: e.action || 'show'
|
|
915
|
+
});
|
|
916
|
+
}).then(page => {
|
|
917
|
+
// set page as it can be missing in the case of refreshes
|
|
918
|
+
context.page = page;
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
function handleBeforeHidePart1(lastNavDirection) {
|
|
922
|
+
// if we're ignoring beforeHide this navigation
|
|
923
|
+
if (handlingBeforeHide === 'ignore') {
|
|
924
|
+
handlingBeforeHide = false;
|
|
925
|
+
return false;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// if we have a before-unload confirm to show
|
|
929
|
+
if (stack[stackPointer].page.beforeHide && options.beforeHide && handlingBeforeHide === false) {
|
|
930
|
+
beforeHideNavDirection = lastNavDirection;
|
|
931
|
+
var interrupt = stack[stackPointer].page.beforeHide();
|
|
932
|
+
if (interrupt) {
|
|
933
|
+
handlingBeforeHide = 'step1';
|
|
934
|
+
|
|
935
|
+
// do this in a new thread, you cant call history actions from inside a history-aciton-handler
|
|
936
|
+
window.setTimeout(() => {
|
|
937
|
+
// undo the navigation so the URL remains correct whilst we show the confirm dialog
|
|
938
|
+
if (beforeHideNavDirection == 'fwd') history.back();else if (beforeHideNavDirection == 'back') history.forward();
|
|
939
|
+
}, 1);
|
|
940
|
+
return true;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// we've finished beforeHiding
|
|
945
|
+
if (handlingBeforeHide === 'step2') {
|
|
946
|
+
handlingBeforeHide = false;
|
|
947
|
+
beforeHideNavDirection = null;
|
|
948
|
+
}
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
951
|
+
function handleBeforeHidePart2() {
|
|
952
|
+
if (handlingBeforeHide !== 'step1') return false;
|
|
953
|
+
if (manuallyAdjustingHistory) return false;
|
|
954
|
+
|
|
955
|
+
// do the beforeHide action, then...
|
|
956
|
+
options.beforeHide(stack[stackPointer].page.beforeHide()).then(result => {
|
|
957
|
+
// if the user confirmed, redo the original action
|
|
958
|
+
if (result) {
|
|
959
|
+
handlingBeforeHide = 'step2';
|
|
960
|
+
if (beforeHideNavDirection == 'fwd') history.forward();else if (beforeHideNavDirection == 'back') history.back();
|
|
961
|
+
} else {
|
|
962
|
+
handlingBeforeHide = false;
|
|
963
|
+
beforeHideNavDirection = null;
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
return true;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
// listen for browser navigations
|
|
970
|
+
window.addEventListener("popstate", async e => {
|
|
971
|
+
let newUid = e.state?.uid || 0;
|
|
972
|
+
let previousUid = stack[stackPointer].uid;
|
|
973
|
+
let lastNavigationDirection = newUid > previousUid ? 'fwd' : 'back';
|
|
974
|
+
let distance = Math.abs(newUid - previousUid);
|
|
975
|
+
var interrupted = handleBeforeHidePart2();
|
|
976
|
+
if (interrupted) return;
|
|
977
|
+
var interrupted = handleBeforeHidePart1(lastNavigationDirection);
|
|
978
|
+
if (interrupted) return;
|
|
979
|
+
var context = findContext(newUid);
|
|
980
|
+
await handlePopstate(context, lastNavigationDirection, distance);
|
|
981
|
+
});
|
|
982
|
+
if (storageAvailable()) {
|
|
983
|
+
window.addEventListener("beforeunload", () => {
|
|
984
|
+
let stackToSerialize = stack.map(s => ({
|
|
985
|
+
uid: s.uid,
|
|
986
|
+
data: s.data
|
|
987
|
+
}));
|
|
988
|
+
let stackToStore = {
|
|
989
|
+
stack: stackToSerialize,
|
|
990
|
+
stackPointer
|
|
991
|
+
};
|
|
992
|
+
window.sessionStorage.setItem('stack', JSON.stringify(stackToStore));
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
function findContext(uid) {
|
|
997
|
+
for (var i = 0; i < stack.length; i++) {
|
|
998
|
+
if (stack[i].uid == uid) return stack[i];
|
|
999
|
+
}
|
|
1000
|
+
return null;
|
|
1001
|
+
}
|
|
1002
|
+
function expandOnlyHash(url) {
|
|
1003
|
+
if (url.startsWith('#')) {
|
|
1004
|
+
let currentState = stack[stackPointer];
|
|
1005
|
+
let currentUrl = currentState.data.route.url;
|
|
1006
|
+
let hashIndex = currentUrl.indexOf('#');
|
|
1007
|
+
if (hashIndex > -1) return currentUrl.substr(0, hashIndex);
|
|
1008
|
+
return currentUrl + url;
|
|
1009
|
+
}
|
|
1010
|
+
return url;
|
|
1011
|
+
}
|
|
1012
|
+
function navigate(url, data, checkBeforeHide = true) {
|
|
1013
|
+
url = expandOnlyHash(url);
|
|
1014
|
+
if (checkBeforeHide === true && options.beforeHide && stack[stackPointer].page.beforeHide) {
|
|
1015
|
+
var interrupt = stack[stackPointer].page.beforeHide();
|
|
1016
|
+
if (interrupt) {
|
|
1017
|
+
options.beforeHide(interrupt).then(result => {
|
|
1018
|
+
if (result) doNavigate(url, data);
|
|
1019
|
+
});
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
doNavigate(url, data).catch(e => {
|
|
1024
|
+
console.error(e);
|
|
1025
|
+
if (e instanceof PageShowError) return showPage(e.url, e.data, {
|
|
1026
|
+
action: e.action || 'show'
|
|
1027
|
+
});
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
function replace(url, data) {
|
|
1031
|
+
url = expandOnlyHash(url);
|
|
1032
|
+
return showPage(url, data, {
|
|
1033
|
+
action: 'replace',
|
|
1034
|
+
distance: 0
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
function show(url, data) {
|
|
1038
|
+
return showPage(url, data, {
|
|
1039
|
+
action: 'show',
|
|
1040
|
+
distance: 0
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
function back(data, checkBeforeHide) {
|
|
1044
|
+
backData = data || {};
|
|
1045
|
+
handlingBeforeHide = checkBeforeHide === false ? 'ignore' : false;
|
|
1046
|
+
history.go(-1);
|
|
1047
|
+
}
|
|
1048
|
+
function printStack() {
|
|
1049
|
+
console.log("Stack length: " + stack.length);
|
|
1050
|
+
console.log("Stack pointer: " + stackPointer);
|
|
1051
|
+
for (var i = 0; i < stack.length; i++) console.log(stack[i]);
|
|
1052
|
+
}
|
|
1053
|
+
function modifyHistory(statesToKeep) {
|
|
1054
|
+
// BUG: You can't remove the 2nd stack frame. This is because you'd have to go back to -1, to then go forward to 0 (removing frame 1)
|
|
1055
|
+
// For clarity, you can remove (replace) frame 0 (1st), and frame 2+ (3rd+)
|
|
1056
|
+
// As a workaround, we replace the 2nd stack frame, if it is the tail, with the root "/".
|
|
1057
|
+
// This at least hopefully removes any meaning from it, simply taking you "home" rather than to wherever you were likely trying to remove.
|
|
1058
|
+
|
|
1059
|
+
if (statesToKeep.length == stack.length) return Promise.resolve();
|
|
1060
|
+
return new Promise(async (resolve, reject) => {
|
|
1061
|
+
let backsToDo = stackPointer;
|
|
1062
|
+
let currentUid = -1;
|
|
1063
|
+
|
|
1064
|
+
// TODO: handle stack pointer not being at the tail when this process starts
|
|
1065
|
+
|
|
1066
|
+
// see BUG comments at the top of this method
|
|
1067
|
+
let apply2ndFrameHack = statesToKeep.length == 1 && stack.length > 1;
|
|
1068
|
+
let defaultPageRouteResult = null;
|
|
1069
|
+
let defaultPage = null;
|
|
1070
|
+
if (apply2ndFrameHack) {
|
|
1071
|
+
let url = getPath(options.defaultPageName);
|
|
1072
|
+
defaultPageRouteResult = _trullock_router__WEBPACK_IMPORTED_MODULE_0__["default"].parse(url);
|
|
1073
|
+
defaultPage = await loadPage(defaultPageRouteResult, {});
|
|
1074
|
+
}
|
|
1075
|
+
manuallyAdjustingHistory = async _ => {
|
|
1076
|
+
// rewind to the first history position
|
|
1077
|
+
if (backsToDo > 0) {
|
|
1078
|
+
window.setTimeout(() => {
|
|
1079
|
+
// see BUG comments at the top of this method
|
|
1080
|
+
if (apply2ndFrameHack && backsToDo == 1) {
|
|
1081
|
+
window.history.replaceState({
|
|
1082
|
+
uid: stack[1].uid
|
|
1083
|
+
}, defaultPage.title, defaultPageRouteResult.path);
|
|
1084
|
+
document.title = defaultPage.title;
|
|
1085
|
+
}
|
|
1086
|
+
backsToDo--;
|
|
1087
|
+
history.back();
|
|
1088
|
+
}, 1);
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
// reset the stack
|
|
1093
|
+
|
|
1094
|
+
stack = [];
|
|
1095
|
+
for (var k = 0; k < statesToKeep.length; k++) {
|
|
1096
|
+
let currentState = statesToKeep[k];
|
|
1097
|
+
currentState.uid = ++currentUid;
|
|
1098
|
+
if (k == 0) window.history.replaceState({
|
|
1099
|
+
uid: currentState.uid
|
|
1100
|
+
}, currentState.page.title, currentState.data.route.url);else window.history.pushState({
|
|
1101
|
+
uid: currentState.uid
|
|
1102
|
+
}, currentState.page.title, currentState.data.route.url);
|
|
1103
|
+
emitUrlChanged(currentState.data.route.url);
|
|
1104
|
+
|
|
1105
|
+
// TODO: this doesnt seem to work when k=0
|
|
1106
|
+
document.title = currentState.page.title;
|
|
1107
|
+
stack.push(currentState);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// see BUG comments at the top of this method
|
|
1111
|
+
if (apply2ndFrameHack) {
|
|
1112
|
+
stack.push({
|
|
1113
|
+
uid: 1,
|
|
1114
|
+
data: {
|
|
1115
|
+
route: {
|
|
1116
|
+
url: defaultPageRouteResult.path,
|
|
1117
|
+
path: defaultPageRouteResult.path,
|
|
1118
|
+
name: defaultPageRouteResult.name,
|
|
1119
|
+
params: defaultPageRouteResult.params
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
page: defaultPage
|
|
1123
|
+
});
|
|
1124
|
+
stackPointer = 0;
|
|
1125
|
+
} else {
|
|
1126
|
+
stackPointer = stack.length - 1;
|
|
1127
|
+
}
|
|
1128
|
+
manuallyAdjustingHistory = false;
|
|
1129
|
+
resolve();
|
|
1130
|
+
};
|
|
1131
|
+
history.back();
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
function removeHistory(predicate) {
|
|
1135
|
+
let statesToKeep = [];
|
|
1136
|
+
for (var i = 0; i < stack.length; i++) {
|
|
1137
|
+
if (!predicate(stack[i], i)) statesToKeep.push(stack[i]);
|
|
1138
|
+
}
|
|
1139
|
+
return modifyHistory(statesToKeep);
|
|
1140
|
+
}
|
|
1141
|
+
function purgeCache() {
|
|
1142
|
+
for (const key in pageCache) {
|
|
1143
|
+
pageCache[key].page.destroy && pageCache[key].page.destroy();
|
|
1144
|
+
if (!pageCache[key].page.constructor.existingDomSelector) {
|
|
1145
|
+
pageCache[key].$html.remove();
|
|
1146
|
+
delete pageCache[key];
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
class PageShowError extends Error {
|
|
1151
|
+
constructor(url, message, data, action) {
|
|
1152
|
+
super(message || 'Error showing requested page');
|
|
1153
|
+
|
|
1154
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
1155
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, PageShowError);
|
|
1156
|
+
this.name = 'PageShowError';
|
|
1157
|
+
this.url = url;
|
|
1158
|
+
this.data = data;
|
|
1159
|
+
this.action = action;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/***/ }),
|
|
1164
|
+
|
|
1165
|
+
/***/ "./tests/helpers.js":
|
|
1166
|
+
/*!**************************!*\
|
|
1167
|
+
!*** ./tests/helpers.js ***!
|
|
1168
|
+
\**************************/
|
|
1169
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1170
|
+
|
|
1171
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1172
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1173
|
+
/* harmony export */ "loadMarkup": () => (/* binding */ loadMarkup)
|
|
1174
|
+
/* harmony export */ });
|
|
1175
|
+
async function loadMarkup(routeResult) {
|
|
1176
|
+
let url = '/pages/' + routeResult.name + '.htm';
|
|
1177
|
+
let response = await fetch(url);
|
|
1178
|
+
let text = await response.text();
|
|
1179
|
+
const parser = new DOMParser();
|
|
1180
|
+
const doc = parser.parseFromString(text, "text/html");
|
|
1181
|
+
const elem = doc.querySelector('body').firstElementChild;
|
|
1182
|
+
return elem;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
/***/ }),
|
|
1186
|
+
|
|
1187
|
+
/***/ "./tests/page-loading.js":
|
|
1188
|
+
/*!*******************************!*\
|
|
1189
|
+
!*** ./tests/page-loading.js ***!
|
|
1190
|
+
\*******************************/
|
|
1191
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1192
|
+
|
|
1193
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1194
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1195
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
1196
|
+
/* harmony export */ });
|
|
1197
|
+
/* harmony import */ var _loading_htm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./loading.htm */ "./tests/loading.htm");
|
|
1198
|
+
/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./tests/helpers.js");
|
|
1199
|
+
/* harmony import */ var _page_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./page.js */ "./tests/page.js");
|
|
1200
|
+
/* harmony import */ var _trullock_page_manager__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @trullock/page-manager */ "./src/index.js");
|
|
1201
|
+
var _class;
|
|
1202
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1203
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1204
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_trullock_page_manager__WEBPACK_IMPORTED_MODULE_3__.registerPage)({
|
|
1210
|
+
name: 'loading',
|
|
1211
|
+
route: '/loading',
|
|
1212
|
+
loadMarkup: _helpers_js__WEBPACK_IMPORTED_MODULE_1__.loadMarkup,
|
|
1213
|
+
pageClass: (_class = class pageClass extends _page_js__WEBPACK_IMPORTED_MODULE_2__["default"] {
|
|
1214
|
+
constructor($page) {
|
|
1215
|
+
super($page);
|
|
1216
|
+
}
|
|
1217
|
+
}, _defineProperty(_class, "existingDomSelector", '#page-loading'), _class)
|
|
1218
|
+
}));
|
|
1219
|
+
|
|
1220
|
+
/***/ }),
|
|
1221
|
+
|
|
1222
|
+
/***/ "./tests/page-page1.js":
|
|
1223
|
+
/*!*****************************!*\
|
|
1224
|
+
!*** ./tests/page-page1.js ***!
|
|
1225
|
+
\*****************************/
|
|
1226
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1227
|
+
|
|
1228
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1229
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1230
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
1231
|
+
/* harmony export */ });
|
|
1232
|
+
/* harmony import */ var _page1_htm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./page1.htm */ "./tests/page1.htm");
|
|
1233
|
+
/* harmony import */ var _page_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./page.js */ "./tests/page.js");
|
|
1234
|
+
/* harmony import */ var _trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @trullock/page-manager */ "./src/index.js");
|
|
1235
|
+
/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers.js */ "./tests/helpers.js");
|
|
1236
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1237
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1238
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.registerPage)({
|
|
1244
|
+
name: 'page1',
|
|
1245
|
+
route: '/page1',
|
|
1246
|
+
loadMarkup: _helpers_js__WEBPACK_IMPORTED_MODULE_3__.loadMarkup,
|
|
1247
|
+
pageClass: class pageClass extends _page_js__WEBPACK_IMPORTED_MODULE_1__["default"] {
|
|
1248
|
+
constructor($page) {
|
|
1249
|
+
super($page);
|
|
1250
|
+
_defineProperty(this, "title", "Page 1");
|
|
1251
|
+
_defineProperty(this, "type", 'A');
|
|
1252
|
+
$page.querySelector('button').addEventListener('click', e => {
|
|
1253
|
+
(0,_trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.refresh)();
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
update(data) {
|
|
1257
|
+
this.$page.querySelector('.js-time').textContent = new Date().getTime();
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}));
|
|
1261
|
+
|
|
1262
|
+
/***/ }),
|
|
1263
|
+
|
|
1264
|
+
/***/ "./tests/page-page2.js":
|
|
1265
|
+
/*!*****************************!*\
|
|
1266
|
+
!*** ./tests/page-page2.js ***!
|
|
1267
|
+
\*****************************/
|
|
1268
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1269
|
+
|
|
1270
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1271
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1272
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
1273
|
+
/* harmony export */ });
|
|
1274
|
+
/* harmony import */ var _page2_htm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./page2.htm */ "./tests/page2.htm");
|
|
1275
|
+
/* harmony import */ var _page_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./page.js */ "./tests/page.js");
|
|
1276
|
+
/* harmony import */ var _trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @trullock/page-manager */ "./src/index.js");
|
|
1277
|
+
/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers.js */ "./tests/helpers.js");
|
|
1278
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1279
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1280
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1281
|
+
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
|
|
1285
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.registerPage)({
|
|
1286
|
+
name: 'page2',
|
|
1287
|
+
route: '/page2',
|
|
1288
|
+
loadMarkup: _helpers_js__WEBPACK_IMPORTED_MODULE_3__.loadMarkup,
|
|
1289
|
+
pageClass: class pageClass extends _page_js__WEBPACK_IMPORTED_MODULE_1__["default"] {
|
|
1290
|
+
constructor($page) {
|
|
1291
|
+
super($page);
|
|
1292
|
+
_defineProperty(this, "title", "Page 2");
|
|
1293
|
+
_defineProperty(this, "type", 'A');
|
|
1294
|
+
$page.querySelector('button').addEventListener('click', e => {
|
|
1295
|
+
e.preventDefault();
|
|
1296
|
+
(0,_trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.replace)('/page3');
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
}));
|
|
1301
|
+
|
|
1302
|
+
/***/ }),
|
|
1303
|
+
|
|
1304
|
+
/***/ "./tests/page-page3.js":
|
|
1305
|
+
/*!*****************************!*\
|
|
1306
|
+
!*** ./tests/page-page3.js ***!
|
|
1307
|
+
\*****************************/
|
|
1308
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1309
|
+
|
|
1310
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1311
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1312
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
1313
|
+
/* harmony export */ });
|
|
1314
|
+
/* harmony import */ var _page3_htm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./page3.htm */ "./tests/page3.htm");
|
|
1315
|
+
/* harmony import */ var _page_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./page.js */ "./tests/page.js");
|
|
1316
|
+
/* harmony import */ var _trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @trullock/page-manager */ "./src/index.js");
|
|
1317
|
+
/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers.js */ "./tests/helpers.js");
|
|
1318
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1319
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1320
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
|
|
1325
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.registerPage({
|
|
1326
|
+
name: 'page3',
|
|
1327
|
+
route: '/page3',
|
|
1328
|
+
loadMarkup: _helpers_js__WEBPACK_IMPORTED_MODULE_3__.loadMarkup,
|
|
1329
|
+
pageClass: class pageClass extends _page_js__WEBPACK_IMPORTED_MODULE_1__["default"] {
|
|
1330
|
+
constructor($page) {
|
|
1331
|
+
super($page);
|
|
1332
|
+
_defineProperty(this, "title", "Page 3");
|
|
1333
|
+
_defineProperty(this, "beforeHide", () => 'Are you sure?');
|
|
1334
|
+
$page.querySelector('.btnRemove').addEventListener('click', e => {
|
|
1335
|
+
_trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.removeHistory(state => {
|
|
1336
|
+
return state.page.type == 'A';
|
|
1337
|
+
});
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
}));
|
|
1342
|
+
|
|
1343
|
+
/***/ }),
|
|
1344
|
+
|
|
1345
|
+
/***/ "./tests/page-page4.js":
|
|
1346
|
+
/*!*****************************!*\
|
|
1347
|
+
!*** ./tests/page-page4.js ***!
|
|
1348
|
+
\*****************************/
|
|
1349
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1350
|
+
|
|
1351
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1352
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1353
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
1354
|
+
/* harmony export */ });
|
|
1355
|
+
/* harmony import */ var _page4_htm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./page4.htm */ "./tests/page4.htm");
|
|
1356
|
+
/* harmony import */ var _page_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./page.js */ "./tests/page.js");
|
|
1357
|
+
/* harmony import */ var _trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @trullock/page-manager */ "./src/index.js");
|
|
1358
|
+
/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers.js */ "./tests/helpers.js");
|
|
1359
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1360
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1361
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.registerPage)({
|
|
1367
|
+
name: 'page4',
|
|
1368
|
+
route: '/page4',
|
|
1369
|
+
loadMarkup: _helpers_js__WEBPACK_IMPORTED_MODULE_3__.loadMarkup,
|
|
1370
|
+
pageClass: class pageClass extends _page_js__WEBPACK_IMPORTED_MODULE_1__["default"] {
|
|
1371
|
+
constructor($page) {
|
|
1372
|
+
super($page);
|
|
1373
|
+
_defineProperty(this, "title", "Page 4");
|
|
1374
|
+
}
|
|
1375
|
+
show(opts) {
|
|
1376
|
+
throw new _trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.PageShowError('/page1', 'Cant show page4, showing page1 instead', {}, 'replace');
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
}));
|
|
1380
|
+
|
|
1381
|
+
/***/ }),
|
|
1382
|
+
|
|
1383
|
+
/***/ "./tests/page-page404.js":
|
|
1384
|
+
/*!*******************************!*\
|
|
1385
|
+
!*** ./tests/page-page404.js ***!
|
|
1386
|
+
\*******************************/
|
|
1387
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1388
|
+
|
|
1389
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1390
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1391
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
1392
|
+
/* harmony export */ });
|
|
1393
|
+
/* harmony import */ var _page404_htm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./page404.htm */ "./tests/page404.htm");
|
|
1394
|
+
/* harmony import */ var _page_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./page.js */ "./tests/page.js");
|
|
1395
|
+
/* harmony import */ var _trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @trullock/page-manager */ "./src/index.js");
|
|
1396
|
+
/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers.js */ "./tests/helpers.js");
|
|
1397
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1398
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1399
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1400
|
+
|
|
1401
|
+
|
|
1402
|
+
|
|
1403
|
+
|
|
1404
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.registerPage)({
|
|
1405
|
+
name: 'page404',
|
|
1406
|
+
route: '/404',
|
|
1407
|
+
loadMarkup: _helpers_js__WEBPACK_IMPORTED_MODULE_3__.loadMarkup,
|
|
1408
|
+
pageClass: class pageClass extends _page_js__WEBPACK_IMPORTED_MODULE_1__["default"] {
|
|
1409
|
+
constructor($page) {
|
|
1410
|
+
super($page);
|
|
1411
|
+
_defineProperty(this, "title", "Page 404");
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
}));
|
|
1415
|
+
|
|
1416
|
+
/***/ }),
|
|
1417
|
+
|
|
1418
|
+
/***/ "./tests/page-pageX.js":
|
|
1419
|
+
/*!*****************************!*\
|
|
1420
|
+
!*** ./tests/page-pageX.js ***!
|
|
1421
|
+
\*****************************/
|
|
1422
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1423
|
+
|
|
1424
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1425
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1426
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
1427
|
+
/* harmony export */ });
|
|
1428
|
+
/* harmony import */ var _pageX_htm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./pageX.htm */ "./tests/pageX.htm");
|
|
1429
|
+
/* harmony import */ var _page_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./page.js */ "./tests/page.js");
|
|
1430
|
+
/* harmony import */ var _trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @trullock/page-manager */ "./src/index.js");
|
|
1431
|
+
/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers.js */ "./tests/helpers.js");
|
|
1432
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1433
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1434
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1435
|
+
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.registerPage)({
|
|
1440
|
+
name: 'pageX',
|
|
1441
|
+
route: '/page/{x}',
|
|
1442
|
+
loadMarkup: _helpers_js__WEBPACK_IMPORTED_MODULE_3__.loadMarkup,
|
|
1443
|
+
pageClass: class pageClass extends _page_js__WEBPACK_IMPORTED_MODULE_1__["default"] {
|
|
1444
|
+
constructor($page) {
|
|
1445
|
+
super($page);
|
|
1446
|
+
_defineProperty(this, "title", "Page X");
|
|
1447
|
+
}
|
|
1448
|
+
show(opts) {
|
|
1449
|
+
this.$page.querySelector('#PageX').textContent = "Page: " + opts.x;
|
|
1450
|
+
return super.show(opts);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
}));
|
|
1454
|
+
|
|
1455
|
+
/***/ }),
|
|
1456
|
+
|
|
1457
|
+
/***/ "./tests/page-show-fail.js":
|
|
1458
|
+
/*!*********************************!*\
|
|
1459
|
+
!*** ./tests/page-show-fail.js ***!
|
|
1460
|
+
\*********************************/
|
|
1461
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1462
|
+
|
|
1463
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1464
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1465
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
1466
|
+
/* harmony export */ });
|
|
1467
|
+
/* harmony import */ var _page404_htm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./page404.htm */ "./tests/page404.htm");
|
|
1468
|
+
/* harmony import */ var _page_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./page.js */ "./tests/page.js");
|
|
1469
|
+
/* harmony import */ var _trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @trullock/page-manager */ "./src/index.js");
|
|
1470
|
+
/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helpers.js */ "./tests/helpers.js");
|
|
1471
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1472
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
1473
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1474
|
+
// doesnt matter
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.registerPage)({
|
|
1479
|
+
name: 'pageShowFail',
|
|
1480
|
+
route: '/show-fail',
|
|
1481
|
+
loadMarkup: _helpers_js__WEBPACK_IMPORTED_MODULE_3__.loadMarkup,
|
|
1482
|
+
pageClass: class pageClass extends _page_js__WEBPACK_IMPORTED_MODULE_1__["default"] {
|
|
1483
|
+
constructor($page) {
|
|
1484
|
+
super($page);
|
|
1485
|
+
_defineProperty(this, "title", "Page 4");
|
|
1486
|
+
}
|
|
1487
|
+
show(opts) {
|
|
1488
|
+
throw new _trullock_page_manager__WEBPACK_IMPORTED_MODULE_2__.PageShowError('/page1', 'Cant show pageShowFail, showing page1 instead', {}, 'replace');
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
}));
|
|
1492
|
+
|
|
1493
|
+
/***/ }),
|
|
1494
|
+
|
|
1495
|
+
/***/ "./tests/page.js":
|
|
1496
|
+
/*!***********************!*\
|
|
1497
|
+
!*** ./tests/page.js ***!
|
|
1498
|
+
\***********************/
|
|
1499
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
1500
|
+
|
|
1501
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1502
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1503
|
+
/* harmony export */ "cacheMarkupBy": () => (/* binding */ cacheMarkupBy),
|
|
1504
|
+
/* harmony export */ "default": () => (/* binding */ Page)
|
|
1505
|
+
/* harmony export */ });
|
|
1506
|
+
const cacheMarkupBy = 'route';
|
|
1507
|
+
class Page {
|
|
1508
|
+
constructor($page) {
|
|
1509
|
+
this.$page = $page;
|
|
1510
|
+
}
|
|
1511
|
+
get title() {
|
|
1512
|
+
return this.$page.dataset['title'] || 'PageManager';
|
|
1513
|
+
}
|
|
1514
|
+
boot(opts) {
|
|
1515
|
+
return Promise.resolve();
|
|
1516
|
+
}
|
|
1517
|
+
show(opts) {
|
|
1518
|
+
this.$page.style.display = 'block';
|
|
1519
|
+
return Promise.resolve();
|
|
1520
|
+
}
|
|
1521
|
+
update() {
|
|
1522
|
+
return Promise.resolve();
|
|
1523
|
+
}
|
|
1524
|
+
hide() {
|
|
1525
|
+
this.$page.style.display = 'none';
|
|
1526
|
+
return Promise.resolve();
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
/***/ })
|
|
1531
|
+
|
|
1532
|
+
/******/ });
|
|
1533
|
+
/************************************************************************/
|
|
1534
|
+
/******/ // The module cache
|
|
1535
|
+
/******/ var __webpack_module_cache__ = {};
|
|
1536
|
+
/******/
|
|
1537
|
+
/******/ // The require function
|
|
1538
|
+
/******/ function __webpack_require__(moduleId) {
|
|
1539
|
+
/******/ // Check if module is in cache
|
|
1540
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
1541
|
+
/******/ if (cachedModule !== undefined) {
|
|
1542
|
+
/******/ return cachedModule.exports;
|
|
1543
|
+
/******/ }
|
|
1544
|
+
/******/ // Create a new module (and put it into the cache)
|
|
1545
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
1546
|
+
/******/ // no module.id needed
|
|
1547
|
+
/******/ // no module.loaded needed
|
|
1548
|
+
/******/ exports: {}
|
|
1549
|
+
/******/ };
|
|
1550
|
+
/******/
|
|
1551
|
+
/******/ // Execute the module function
|
|
1552
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
1553
|
+
/******/
|
|
1554
|
+
/******/ // Return the exports of the module
|
|
1555
|
+
/******/ return module.exports;
|
|
1556
|
+
/******/ }
|
|
1557
|
+
/******/
|
|
1558
|
+
/************************************************************************/
|
|
1559
|
+
/******/ /* webpack/runtime/define property getters */
|
|
1560
|
+
/******/ (() => {
|
|
1561
|
+
/******/ // define getter functions for harmony exports
|
|
1562
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
1563
|
+
/******/ for(var key in definition) {
|
|
1564
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
1565
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
1566
|
+
/******/ }
|
|
1567
|
+
/******/ }
|
|
1568
|
+
/******/ };
|
|
1569
|
+
/******/ })();
|
|
1570
|
+
/******/
|
|
1571
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
1572
|
+
/******/ (() => {
|
|
1573
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
1574
|
+
/******/ })();
|
|
1575
|
+
/******/
|
|
1576
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
1577
|
+
/******/ (() => {
|
|
1578
|
+
/******/ // define __esModule on exports
|
|
1579
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
1580
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
1581
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1582
|
+
/******/ }
|
|
1583
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
1584
|
+
/******/ };
|
|
1585
|
+
/******/ })();
|
|
1586
|
+
/******/
|
|
1587
|
+
/******/ /* webpack/runtime/publicPath */
|
|
1588
|
+
/******/ (() => {
|
|
1589
|
+
/******/ __webpack_require__.p = "/";
|
|
1590
|
+
/******/ })();
|
|
1591
|
+
/******/
|
|
1592
|
+
/************************************************************************/
|
|
1593
|
+
var __webpack_exports__ = {};
|
|
1594
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
1595
|
+
(() => {
|
|
1596
|
+
/*!**************************!*\
|
|
1597
|
+
!*** ./tests/lolpack.js ***!
|
|
1598
|
+
\**************************/
|
|
1599
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1600
|
+
/* harmony import */ var _src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../src/index.js */ "./src/index.js");
|
|
1601
|
+
/* harmony import */ var _page_loading_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./page-loading.js */ "./tests/page-loading.js");
|
|
1602
|
+
/* harmony import */ var _page_page1_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./page-page1.js */ "./tests/page-page1.js");
|
|
1603
|
+
/* harmony import */ var _page_page2_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./page-page2.js */ "./tests/page-page2.js");
|
|
1604
|
+
/* harmony import */ var _page_page3_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./page-page3.js */ "./tests/page-page3.js");
|
|
1605
|
+
/* harmony import */ var _page_page4_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./page-page4.js */ "./tests/page-page4.js");
|
|
1606
|
+
/* harmony import */ var _page_pageX_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./page-pageX.js */ "./tests/page-pageX.js");
|
|
1607
|
+
/* harmony import */ var _page_page404_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./page-page404.js */ "./tests/page-page404.js");
|
|
1608
|
+
/* harmony import */ var _page_show_fail_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./page-show-fail.js */ "./tests/page-show-fail.js");
|
|
1609
|
+
|
|
1610
|
+
|
|
1611
|
+
|
|
1612
|
+
|
|
1613
|
+
|
|
1614
|
+
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
window.addEventListener('DOMContentLoaded', async function () {
|
|
1619
|
+
await _src_index_js__WEBPACK_IMPORTED_MODULE_0__.init({
|
|
1620
|
+
error404PageName: 'page404',
|
|
1621
|
+
defaultPageName: 'page1',
|
|
1622
|
+
beforeHide: message => new Promise(resolve => {
|
|
1623
|
+
resolve(confirm(message));
|
|
1624
|
+
})
|
|
1625
|
+
});
|
|
1626
|
+
|
|
1627
|
+
// listen for navigations
|
|
1628
|
+
document.addEventListener('click', e => {
|
|
1629
|
+
if (e.ctrlKey || e.metaKey) return;
|
|
1630
|
+
var $a = e.target.matches('a') ? e.target : e.target.closest('a');
|
|
1631
|
+
if (!$a) return;
|
|
1632
|
+
var href = $a.pathname + $a.search + $a.hash;
|
|
1633
|
+
_src_index_js__WEBPACK_IMPORTED_MODULE_0__.navigate(href);
|
|
1634
|
+
e.preventDefault();
|
|
1635
|
+
}, false);
|
|
1636
|
+
document.querySelector('.btnStack').addEventListener('click', e => {
|
|
1637
|
+
_src_index_js__WEBPACK_IMPORTED_MODULE_0__.printStack();
|
|
1638
|
+
});
|
|
1639
|
+
window.addEventListener("page-manager.url-changed", e => {
|
|
1640
|
+
console.log(e.detail.url);
|
|
1641
|
+
});
|
|
1642
|
+
await _src_index_js__WEBPACK_IMPORTED_MODULE_0__.ready();
|
|
1643
|
+
});
|
|
1644
|
+
})();
|
|
1645
|
+
|
|
1646
|
+
/******/ })()
|
|
1647
|
+
;
|
|
1648
|
+
//# sourceMappingURL=main.js.map
|