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