-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathnavigo.js
1350 lines (1122 loc) · 49.4 KB
/
navigo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("Navigo", [], factory);
else if(typeof exports === 'object')
exports["Navigo"] = factory();
else
root["Navigo"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/Q.ts":
/*!******************!*\
!*** ./src/Q.ts ***!
\******************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ Q; }
/* harmony export */ });
function Q(funcs, c, done) {
var context = c || {};
var idx = 0;
(function next() {
if (!funcs[idx]) {
if (done) {
done(context);
}
return;
}
if (Array.isArray(funcs[idx])) {
funcs.splice.apply(funcs, [idx, 1].concat(funcs[idx][0](context) ? funcs[idx][1] : funcs[idx][2]));
next();
} else {
// console.log(funcs[idx].name + " / " + JSON.stringify(context));
// console.log(funcs[idx].name);
funcs[idx](context, function (moveForward) {
if (typeof moveForward === "undefined" || moveForward === true) {
idx += 1;
next();
} else if (done) {
done(context);
}
});
}
})();
}
Q.if = function (condition, one, two) {
if (!Array.isArray(one)) one = [one];
if (!Array.isArray(two)) two = [two];
return [condition, one, two];
};
/***/ }),
/***/ "./src/constants.ts":
/*!**************************!*\
!*** ./src/constants.ts ***!
\**************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "PARAMETER_REGEXP": function() { return /* binding */ PARAMETER_REGEXP; },
/* harmony export */ "REPLACE_VARIABLE_REGEXP": function() { return /* binding */ REPLACE_VARIABLE_REGEXP; },
/* harmony export */ "WILDCARD_REGEXP": function() { return /* binding */ WILDCARD_REGEXP; },
/* harmony export */ "REPLACE_WILDCARD": function() { return /* binding */ REPLACE_WILDCARD; },
/* harmony export */ "NOT_SURE_REGEXP": function() { return /* binding */ NOT_SURE_REGEXP; },
/* harmony export */ "REPLACE_NOT_SURE": function() { return /* binding */ REPLACE_NOT_SURE; },
/* harmony export */ "START_BY_SLASH_REGEXP": function() { return /* binding */ START_BY_SLASH_REGEXP; },
/* harmony export */ "MATCH_REGEXP_FLAGS": function() { return /* binding */ MATCH_REGEXP_FLAGS; }
/* harmony export */ });
var PARAMETER_REGEXP = /([:*])(\w+)/g;
var REPLACE_VARIABLE_REGEXP = "([^/]+)";
var WILDCARD_REGEXP = /\*/g;
var REPLACE_WILDCARD = "?(?:.*)";
var NOT_SURE_REGEXP = /\/\?/g;
var REPLACE_NOT_SURE = "/?([^/]+|)";
var START_BY_SLASH_REGEXP = "(?:/^|^)";
var MATCH_REGEXP_FLAGS = "";
/***/ }),
/***/ "./src/index.ts":
/*!**********************!*\
!*** ./src/index.ts ***!
\**********************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ Navigo; }
/* harmony export */ });
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
/* harmony import */ var _Q__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Q */ "./src/Q.ts");
/* harmony import */ var _middlewares_setLocationPath__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./middlewares/setLocationPath */ "./src/middlewares/setLocationPath.ts");
/* harmony import */ var _middlewares_matchPathToRegisteredRoutes__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./middlewares/matchPathToRegisteredRoutes */ "./src/middlewares/matchPathToRegisteredRoutes.ts");
/* harmony import */ var _middlewares_checkForDeprecationMethods__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./middlewares/checkForDeprecationMethods */ "./src/middlewares/checkForDeprecationMethods.ts");
/* harmony import */ var _middlewares_checkForForceOp__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./middlewares/checkForForceOp */ "./src/middlewares/checkForForceOp.ts");
/* harmony import */ var _middlewares_updateBrowserURL__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./middlewares/updateBrowserURL */ "./src/middlewares/updateBrowserURL.ts");
/* harmony import */ var _middlewares_processMatches__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./middlewares/processMatches */ "./src/middlewares/processMatches.ts");
/* harmony import */ var _middlewares_waitingList__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./middlewares/waitingList */ "./src/middlewares/waitingList.ts");
/* harmony import */ var _lifecycles__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./lifecycles */ "./src/lifecycles.ts");
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var DEFAULT_LINK_SELECTOR = "[data-navigo]";
function Navigo(appRoute, options) {
var DEFAULT_RESOLVE_OPTIONS = options || {
strategy: "ONE",
hash: false,
noMatchWarning: false,
linksSelector: DEFAULT_LINK_SELECTOR
};
var self = this;
var root = "/";
var current = null;
var routes = [];
var destroyed = false;
var genericHooks;
var isPushStateAvailable = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.pushStateAvailable)();
var isWindowAvailable = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.windowAvailable)();
if (!appRoute) {
console.warn('Navigo requires a root path in its constructor. If not provided will use "/" as default.');
} else {
root = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(appRoute);
}
function _checkForAHash(url) {
if (url.indexOf("#") >= 0) {
if (DEFAULT_RESOLVE_OPTIONS.hash === true) {
url = url.split("#")[1] || "/";
} else {
url = url.split("#")[0];
}
}
return url;
}
function composePathWithRoot(path) {
return (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(root + "/" + (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(path));
}
function createRoute(path, handler, hooks, name) {
path = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.isString)(path) ? composePathWithRoot(path) : path;
return {
name: name || (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(String(path)),
path: path,
handler: handler,
hooks: (0,_utils__WEBPACK_IMPORTED_MODULE_0__.accumulateHooks)(hooks)
};
} // public APIs
function on(path, handler, hooks) {
var _this = this;
if (typeof path === "object" && !(path instanceof RegExp)) {
Object.keys(path).forEach(function (p) {
if (typeof path[p] === "function") {
_this.on(p, path[p]);
} else {
var _path$p = path[p],
_handler = _path$p.uses,
name = _path$p.as,
_hooks = _path$p.hooks;
routes.push(createRoute(p, _handler, [genericHooks, _hooks], name));
}
});
return this;
} else if (typeof path === "function") {
hooks = handler;
handler = path;
path = root;
}
routes.push(createRoute(path, handler, [genericHooks, hooks]));
return this;
}
function resolve(to, options) {
if (self.__dirty) {
self.__waiting.push(function () {
return self.resolve(to, options);
});
return;
} else {
self.__dirty = true;
}
to = to ? (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(root) + "/" + (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(to) : undefined; // console.log("-- resolve --> " + to, self.__dirty);
var context = {
instance: self,
to: to,
currentLocationPath: to,
navigateOptions: {},
resolveOptions: _extends({}, DEFAULT_RESOLVE_OPTIONS, options)
};
(0,_Q__WEBPACK_IMPORTED_MODULE_1__.default)([_middlewares_setLocationPath__WEBPACK_IMPORTED_MODULE_2__.default, _middlewares_matchPathToRegisteredRoutes__WEBPACK_IMPORTED_MODULE_3__.default, _Q__WEBPACK_IMPORTED_MODULE_1__.default.if(function (_ref) {
var matches = _ref.matches;
return matches && matches.length > 0;
}, _middlewares_processMatches__WEBPACK_IMPORTED_MODULE_7__.default, _lifecycles__WEBPACK_IMPORTED_MODULE_9__.notFoundLifeCycle)], context, _middlewares_waitingList__WEBPACK_IMPORTED_MODULE_8__.default);
return context.matches ? context.matches : false;
}
function navigate(to, navigateOptions) {
// console.log("-- navigate --> " + to, self.__dirty);
if (self.__dirty) {
self.__waiting.push(function () {
return self.navigate(to, navigateOptions);
});
return;
} else {
self.__dirty = true;
}
to = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(root) + "/" + (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(to);
var context = {
instance: self,
to: to,
navigateOptions: navigateOptions || {},
resolveOptions: navigateOptions && navigateOptions.resolveOptions ? navigateOptions.resolveOptions : DEFAULT_RESOLVE_OPTIONS,
currentLocationPath: _checkForAHash(to)
};
(0,_Q__WEBPACK_IMPORTED_MODULE_1__.default)([_middlewares_checkForDeprecationMethods__WEBPACK_IMPORTED_MODULE_4__.default, _middlewares_checkForForceOp__WEBPACK_IMPORTED_MODULE_5__.default, _middlewares_matchPathToRegisteredRoutes__WEBPACK_IMPORTED_MODULE_3__.default, _Q__WEBPACK_IMPORTED_MODULE_1__.default.if(function (_ref2) {
var matches = _ref2.matches;
return matches && matches.length > 0;
}, _middlewares_processMatches__WEBPACK_IMPORTED_MODULE_7__.default, _lifecycles__WEBPACK_IMPORTED_MODULE_9__.notFoundLifeCycle), _middlewares_updateBrowserURL__WEBPACK_IMPORTED_MODULE_6__.default, _middlewares_waitingList__WEBPACK_IMPORTED_MODULE_8__.default], context, _middlewares_waitingList__WEBPACK_IMPORTED_MODULE_8__.default);
}
function navigateByName(name, data, options) {
var url = generate(name, data);
if (url !== null) {
navigate(url.replace(new RegExp("^/?" + root), ""), options);
return true;
}
return false;
}
function off(what) {
this.routes = routes = routes.filter(function (r) {
if ((0,_utils__WEBPACK_IMPORTED_MODULE_0__.isString)(what)) {
return (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(r.path) !== (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(what);
} else if ((0,_utils__WEBPACK_IMPORTED_MODULE_0__.isFunction)(what)) {
return what !== r.handler;
}
return String(r.path) !== String(what);
});
return this;
}
function listen() {
if (isPushStateAvailable) {
this.__popstateListener = function () {
if (!self.__freezeListening) {
resolve();
}
};
window.addEventListener("popstate", this.__popstateListener);
}
}
function destroy() {
this.routes = routes = [];
if (isPushStateAvailable) {
window.removeEventListener("popstate", this.__popstateListener);
}
this.destroyed = destroyed = true;
}
function notFound(handler, hooks) {
self._notFoundRoute = createRoute("*", handler, [genericHooks, hooks], "__NOT_FOUND__");
return this;
}
function updatePageLinks() {
if (!isWindowAvailable) return;
findLinks().forEach(function (link) {
if ("false" === link.getAttribute("data-navigo") || "_blank" === link.getAttribute("target")) {
if (link.hasListenerAttached) {
link.removeEventListener("click", link.navigoHandler);
}
return;
}
if (!link.hasListenerAttached) {
link.hasListenerAttached = true;
link.navigoHandler = function (e) {
if ((e.ctrlKey || e.metaKey) && e.target.tagName.toLowerCase() === "a") {
return false;
}
var location = link.getAttribute("href");
if (typeof location === "undefined" || location === null) {
return false;
} // handling absolute paths
if (location.match(/^(http|https)/) && typeof URL !== "undefined") {
try {
var u = new URL(location);
location = u.pathname + u.search;
} catch (err) {}
}
var options = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.parseNavigateOptions)(link.getAttribute("data-navigo-options"));
if (!destroyed) {
e.preventDefault();
e.stopPropagation();
self.navigate((0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(location), options);
}
};
link.addEventListener("click", link.navigoHandler);
}
});
return self;
}
function findLinks() {
if (isWindowAvailable) {
return [].slice.call(document.querySelectorAll(DEFAULT_RESOLVE_OPTIONS.linksSelector || DEFAULT_LINK_SELECTOR));
}
return [];
}
function link(path) {
return "/" + root + "/" + (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(path);
}
function setGenericHooks(hooks) {
genericHooks = hooks;
return this;
}
function lastResolved() {
return current;
}
function generate(name, data, options) {
var route = routes.find(function (r) {
return r.name === name;
});
var result = null;
if (route) {
result = route.path;
if (data) {
for (var key in data) {
result = result.replace(":" + key, data[key]);
}
}
result = !result.match(/^\//) ? "/" + result : result;
}
if (result && options && !options.includeRoot) {
result = result.replace(new RegExp("^/" + root), "");
}
return result;
}
function getLinkPath(link) {
return link.getAttribute("href");
}
function pathToMatchObject(path) {
var _extractGETParameters = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.extractGETParameters)((0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(path)),
url = _extractGETParameters[0],
queryString = _extractGETParameters[1];
var params = queryString === "" ? null : (0,_utils__WEBPACK_IMPORTED_MODULE_0__.parseQuery)(queryString);
var hashString = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.extractHashFromURL)(path);
var route = createRoute(url, function () {}, [genericHooks], url);
return {
url: url,
queryString: queryString,
hashString: hashString,
route: route,
data: null,
params: params
};
}
function getCurrentLocation() {
return pathToMatchObject((0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)((0,_utils__WEBPACK_IMPORTED_MODULE_0__.getCurrentEnvURL)(root)).replace(new RegExp("^" + root), ""));
}
function directMatchWithRegisteredRoutes(path) {
var context = {
instance: self,
currentLocationPath: path,
to: path,
navigateOptions: {},
resolveOptions: DEFAULT_RESOLVE_OPTIONS
};
(0,_middlewares_matchPathToRegisteredRoutes__WEBPACK_IMPORTED_MODULE_3__.default)(context, function () {});
return context.matches ? context.matches : false;
}
function directMatchWithLocation(path, currentLocation, annotatePathWithRoot) {
if (typeof currentLocation !== "undefined" && (typeof annotatePathWithRoot === "undefined" || annotatePathWithRoot)) {
currentLocation = composePathWithRoot(currentLocation);
}
var context = {
instance: self,
to: currentLocation,
currentLocationPath: currentLocation
};
(0,_middlewares_setLocationPath__WEBPACK_IMPORTED_MODULE_2__.default)(context, function () {});
if (typeof path === "string") {
path = typeof annotatePathWithRoot === "undefined" || annotatePathWithRoot ? composePathWithRoot(path) : path;
}
var match = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.matchRoute)(context, {
name: String(path),
path: path,
handler: function handler() {},
hooks: {}
});
return match ? match : false;
}
function addHook(type, route, func) {
if (typeof route === "string") {
route = getRoute(route);
}
if (route) {
if (!route.hooks[type]) route.hooks[type] = [];
route.hooks[type].push(func);
return function () {
route.hooks[type] = route.hooks[type].filter(function (f) {
return f !== func;
});
};
} else {
console.warn("Route doesn't exists: " + route);
}
return function () {};
}
function getRoute(nameOrHandler) {
if (typeof nameOrHandler === "string") {
return routes.find(function (r) {
return r.name === composePathWithRoot(nameOrHandler);
});
}
return routes.find(function (r) {
return r.handler === nameOrHandler;
});
}
function __markAsClean(context) {
context.instance.__dirty = false;
if (context.instance.__waiting.length > 0) {
context.instance.__waiting.shift()();
}
}
this.root = root;
this.routes = routes;
this.destroyed = destroyed;
this.current = current;
this.__freezeListening = false;
this.__waiting = [];
this.__dirty = false;
this.__markAsClean = __markAsClean;
this.on = on;
this.off = off;
this.resolve = resolve;
this.navigate = navigate;
this.navigateByName = navigateByName;
this.destroy = destroy;
this.notFound = notFound;
this.updatePageLinks = updatePageLinks;
this.link = link;
this.hooks = setGenericHooks;
this.extractGETParameters = function (url) {
return (0,_utils__WEBPACK_IMPORTED_MODULE_0__.extractGETParameters)(_checkForAHash(url));
};
this.lastResolved = lastResolved;
this.generate = generate;
this.getLinkPath = getLinkPath;
this.match = directMatchWithRegisteredRoutes;
this.matchLocation = directMatchWithLocation;
this.getCurrentLocation = getCurrentLocation;
this.addBeforeHook = addHook.bind(this, "before");
this.addAfterHook = addHook.bind(this, "after");
this.addAlreadyHook = addHook.bind(this, "already");
this.addLeaveHook = addHook.bind(this, "leave");
this.getRoute = getRoute;
this._pathToMatchObject = pathToMatchObject;
this._clean = _utils__WEBPACK_IMPORTED_MODULE_0__.clean;
this._checkForAHash = _checkForAHash;
this._setCurrent = function (c) {
return current = self.current = c;
};
listen.call(this);
updatePageLinks.call(this);
}
/***/ }),
/***/ "./src/lifecycles.ts":
/*!***************************!*\
!*** ./src/lifecycles.ts ***!
\***************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "foundLifecycle": function() { return /* binding */ foundLifecycle; },
/* harmony export */ "notFoundLifeCycle": function() { return /* binding */ notFoundLifeCycle; }
/* harmony export */ });
/* harmony import */ var _Q__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Q */ "./src/Q.ts");
/* harmony import */ var _middlewares_checkForLeaveHook__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./middlewares/checkForLeaveHook */ "./src/middlewares/checkForLeaveHook.ts");
/* harmony import */ var _middlewares_checkForBeforeHook__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./middlewares/checkForBeforeHook */ "./src/middlewares/checkForBeforeHook.ts");
/* harmony import */ var _middlewares_callHandler__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./middlewares/callHandler */ "./src/middlewares/callHandler.ts");
/* harmony import */ var _middlewares_checkForAfterHook__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./middlewares/checkForAfterHook */ "./src/middlewares/checkForAfterHook.ts");
/* harmony import */ var _middlewares_checkForAlreadyHook__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./middlewares/checkForAlreadyHook */ "./src/middlewares/checkForAlreadyHook.ts");
/* harmony import */ var _middlewares_checkForNotFoundHandler__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./middlewares/checkForNotFoundHandler */ "./src/middlewares/checkForNotFoundHandler.ts");
/* harmony import */ var _middlewares_errorOut__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./middlewares/errorOut */ "./src/middlewares/errorOut.ts");
/* harmony import */ var _middlewares_flushCurrent__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./middlewares/flushCurrent */ "./src/middlewares/flushCurrent.ts");
/* harmony import */ var _middlewares_updateState__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./middlewares/updateState */ "./src/middlewares/updateState.ts");
var foundLifecycle = [_middlewares_checkForAlreadyHook__WEBPACK_IMPORTED_MODULE_5__.default, _middlewares_checkForBeforeHook__WEBPACK_IMPORTED_MODULE_2__.default, _middlewares_callHandler__WEBPACK_IMPORTED_MODULE_3__.default, _middlewares_checkForAfterHook__WEBPACK_IMPORTED_MODULE_4__.default];
var notFoundLifeCycle = [_middlewares_checkForLeaveHook__WEBPACK_IMPORTED_MODULE_1__.default, _middlewares_checkForNotFoundHandler__WEBPACK_IMPORTED_MODULE_6__.default, _Q__WEBPACK_IMPORTED_MODULE_0__.default.if(function (_ref) {
var notFoundHandled = _ref.notFoundHandled;
return notFoundHandled;
}, foundLifecycle.concat([_middlewares_updateState__WEBPACK_IMPORTED_MODULE_9__.default]), [_middlewares_errorOut__WEBPACK_IMPORTED_MODULE_7__.default, _middlewares_flushCurrent__WEBPACK_IMPORTED_MODULE_8__.default])];
/***/ }),
/***/ "./src/middlewares/callHandler.ts":
/*!****************************************!*\
!*** ./src/middlewares/callHandler.ts ***!
\****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ callHandler; }
/* harmony export */ });
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
function callHandler(context, done) {
if ((0,_utils__WEBPACK_IMPORTED_MODULE_0__.undefinedOrTrue)(context.navigateOptions, "callHandler")) {
context.match.route.handler(context.match);
}
context.instance.updatePageLinks();
done();
}
/***/ }),
/***/ "./src/middlewares/checkForAfterHook.ts":
/*!**********************************************!*\
!*** ./src/middlewares/checkForAfterHook.ts ***!
\**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ checkForAfterHook; }
/* harmony export */ });
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
function checkForAfterHook(context, done) {
if (context.match.route.hooks && context.match.route.hooks.after && (0,_utils__WEBPACK_IMPORTED_MODULE_0__.undefinedOrTrue)(context.navigateOptions, "callHooks")) {
context.match.route.hooks.after.forEach(function (f) {
return f(context.match);
});
}
done();
}
/***/ }),
/***/ "./src/middlewares/checkForAlreadyHook.ts":
/*!************************************************!*\
!*** ./src/middlewares/checkForAlreadyHook.ts ***!
\************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ checkForAlreadyHook; }
/* harmony export */ });
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
function checkForAlreadyHook(context, done) {
var current = context.instance.lastResolved();
if (current && current[0] && current[0].route === context.match.route && current[0].url === context.match.url && current[0].queryString === context.match.queryString) {
current.forEach(function (c) {
if (c.route.hooks && c.route.hooks.already) {
if ((0,_utils__WEBPACK_IMPORTED_MODULE_0__.undefinedOrTrue)(context.navigateOptions, "callHooks")) {
c.route.hooks.already.forEach(function (f) {
return f(context.match);
});
}
}
});
done(false);
return;
}
done();
}
/***/ }),
/***/ "./src/middlewares/checkForBeforeHook.ts":
/*!***********************************************!*\
!*** ./src/middlewares/checkForBeforeHook.ts ***!
\***********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ checkForBeforeHook; }
/* harmony export */ });
/* harmony import */ var _Q__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Q */ "./src/Q.ts");
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
function checkForBeforeHook(context, done) {
if (context.match.route.hooks && context.match.route.hooks.before && (0,_utils__WEBPACK_IMPORTED_MODULE_1__.undefinedOrTrue)(context.navigateOptions, "callHooks")) {
(0,_Q__WEBPACK_IMPORTED_MODULE_0__.default)(context.match.route.hooks.before.map(function (f) {
// just so we match the Q interface
return function beforeHookInternal(_, d) {
return f(function (shouldStop) {
if (shouldStop === false) {
context.instance.__markAsClean(context);
} else {
d();
}
}, context.match);
};
}).concat([function () {
return done();
}]));
} else {
done();
}
}
/***/ }),
/***/ "./src/middlewares/checkForDeprecationMethods.ts":
/*!*******************************************************!*\
!*** ./src/middlewares/checkForDeprecationMethods.ts ***!
\*******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ checkForDeprecationMethods; }
/* harmony export */ });
function checkForDeprecationMethods(context, done) {
if (context.navigateOptions) {
if (typeof context.navigateOptions["shouldResolve"] !== "undefined") {
console.warn("\"shouldResolve\" is deprecated. Please check the documentation.");
}
if (typeof context.navigateOptions["silent"] !== "undefined") {
console.warn("\"silent\" is deprecated. Please check the documentation.");
}
}
done();
}
/***/ }),
/***/ "./src/middlewares/checkForForceOp.ts":
/*!********************************************!*\
!*** ./src/middlewares/checkForForceOp.ts ***!
\********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ checkForForceOp; }
/* harmony export */ });
function checkForForceOp(context, done) {
if (context.navigateOptions.force === true) {
context.instance._setCurrent([context.instance._pathToMatchObject(context.to)]);
done(false);
} else {
done();
}
}
/***/ }),
/***/ "./src/middlewares/checkForLeaveHook.ts":
/*!**********************************************!*\
!*** ./src/middlewares/checkForLeaveHook.ts ***!
\**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ checkForLeaveHook; }
/* harmony export */ });
/* harmony import */ var _Q__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Q */ "./src/Q.ts");
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
function checkForLeaveHook(context, done) {
var instance = context.instance;
if (!instance.lastResolved()) {
done();
return;
}
(0,_Q__WEBPACK_IMPORTED_MODULE_0__.default)(instance.lastResolved().map(function (oldMatch) {
return function (_, leaveLoopDone) {
// no leave hook
if (!oldMatch.route.hooks || !oldMatch.route.hooks.leave) {
leaveLoopDone();
return;
}
var runHook = false;
var newLocationVSOldMatch = context.instance.matchLocation(oldMatch.route.path, context.currentLocationPath, false);
if (oldMatch.route.path !== "*") {
runHook = !newLocationVSOldMatch;
} else {
var someOfTheLastOnesMatch = context.matches ? context.matches.find(function (match) {
return oldMatch.route.path === match.route.path;
}) : false;
runHook = !someOfTheLastOnesMatch;
}
if ((0,_utils__WEBPACK_IMPORTED_MODULE_1__.undefinedOrTrue)(context.navigateOptions, "callHooks") && runHook) {
(0,_Q__WEBPACK_IMPORTED_MODULE_0__.default)(oldMatch.route.hooks.leave.map(function (f) {
// just so we match the Q interface
return function (_, d) {
return f(function (shouldStop) {
if (shouldStop === false) {
context.instance.__markAsClean(context);
} else {
d();
}
}, context.matches && context.matches.length > 0 ? context.matches.length === 1 ? context.matches[0] : context.matches : undefined);
};
}).concat([function () {
return leaveLoopDone();
}]));
return;
} else {
leaveLoopDone();
}
};
}), {}, function () {
return done();
});
}
/***/ }),
/***/ "./src/middlewares/checkForNotFoundHandler.ts":
/*!****************************************************!*\
!*** ./src/middlewares/checkForNotFoundHandler.ts ***!
\****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ checkForNotFoundHandler; }
/* harmony export */ });
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
function checkForNotFoundHandler(context, done) {
var notFoundRoute = context.instance._notFoundRoute;
if (notFoundRoute) {
context.notFoundHandled = true;
var _extractGETParameters = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.extractGETParameters)(context.currentLocationPath),
url = _extractGETParameters[0],
queryString = _extractGETParameters[1];
var hashString = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.extractHashFromURL)(context.to);
notFoundRoute.path = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.clean)(url);
var notFoundMatch = {
url: notFoundRoute.path,
queryString: queryString,
hashString: hashString,
data: null,
route: notFoundRoute,
params: queryString !== "" ? (0,_utils__WEBPACK_IMPORTED_MODULE_0__.parseQuery)(queryString) : null
};
context.matches = [notFoundMatch];
context.match = notFoundMatch;
}
done();
}
/***/ }),
/***/ "./src/middlewares/errorOut.ts":
/*!*************************************!*\
!*** ./src/middlewares/errorOut.ts ***!
\*************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ errorOut; }
/* harmony export */ });
function errorOut(context, done) {
if (!context.resolveOptions || context.resolveOptions.noMatchWarning === false || typeof context.resolveOptions.noMatchWarning === "undefined") console.warn("Navigo: \"" + context.currentLocationPath + "\" didn't match any of the registered routes.");
done();
}
/***/ }),
/***/ "./src/middlewares/flushCurrent.ts":
/*!*****************************************!*\
!*** ./src/middlewares/flushCurrent.ts ***!
\*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ flushCurrent; }
/* harmony export */ });
function flushCurrent(context, done) {
context.instance._setCurrent(null);
done();
}
/***/ }),
/***/ "./src/middlewares/matchPathToRegisteredRoutes.ts":
/*!********************************************************!*\
!*** ./src/middlewares/matchPathToRegisteredRoutes.ts ***!
\********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ matchPathToRegisteredRoutes; }
/* harmony export */ });
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
function matchPathToRegisteredRoutes(context, done) {
for (var i = 0; i < context.instance.routes.length; i++) {
var route = context.instance.routes[i];
var match = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.matchRoute)(context, route);
if (match) {
if (!context.matches) context.matches = [];
context.matches.push(match);
if (context.resolveOptions.strategy === "ONE") {
done();
return;
}
}
}
done();
}
/***/ }),
/***/ "./src/middlewares/processMatches.ts":
/*!*******************************************!*\
!*** ./src/middlewares/processMatches.ts ***!
\*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ processMatches; }
/* harmony export */ });
/* harmony import */ var _Q__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Q */ "./src/Q.ts");
/* harmony import */ var _lifecycles__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../lifecycles */ "./src/lifecycles.ts");
/* harmony import */ var _updateState__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./updateState */ "./src/middlewares/updateState.ts");
/* harmony import */ var _checkForLeaveHook__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./checkForLeaveHook */ "./src/middlewares/checkForLeaveHook.ts");
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function processMatches(context, done) {
var idx = 0;
function nextMatch() {
if (idx === context.matches.length) {
(0,_updateState__WEBPACK_IMPORTED_MODULE_2__.default)(context, done);
return;
}
(0,_Q__WEBPACK_IMPORTED_MODULE_0__.default)(_lifecycles__WEBPACK_IMPORTED_MODULE_1__.foundLifecycle, _extends({}, context, {
match: context.matches[idx]
}), function end() {
idx += 1;
nextMatch();
});
}
(0,_checkForLeaveHook__WEBPACK_IMPORTED_MODULE_3__.default)(context, nextMatch);
}
/***/ }),
/***/ "./src/middlewares/setLocationPath.ts":
/*!********************************************!*\
!*** ./src/middlewares/setLocationPath.ts ***!
\********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ setLocationPath; }
/* harmony export */ });
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./src/utils.ts");
function setLocationPath(context, done) {
if (typeof context.currentLocationPath === "undefined") {
context.currentLocationPath = context.to = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.getCurrentEnvURL)(context.instance.root);
}
context.currentLocationPath = context.instance._checkForAHash(context.currentLocationPath);
done();
}
/***/ }),
/***/ "./src/middlewares/updateBrowserURL.ts":
/*!*********************************************!*\
!*** ./src/middlewares/updateBrowserURL.ts ***!
\*********************************************/