@breautek/router 3.0.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.legacy.md +206 -0
- package/CHANGELOG.md +11 -197
- package/dist/router.js +987 -1808
- package/dist/src/DefaultStrategy.d.ts +5 -5
- package/dist/src/HashStrategy.d.ts +28 -28
- package/dist/src/IOnNoRoute.d.ts +4 -4
- package/dist/src/IRouterStrategyClass.d.ts +8 -8
- package/dist/src/IViewStylesheet.d.ts +4 -4
- package/dist/src/Route.d.ts +33 -33
- package/dist/src/RouteMatcher.d.ts +30 -31
- package/dist/src/Router.d.ts +89 -85
- package/dist/src/RouterStrategy.d.ts +138 -117
- package/dist/src/TransitionSlide.d.ts +17 -17
- package/dist/src/TransitionStrategy.d.ts +21 -21
- package/dist/src/URLParser.d.ts +39 -39
- package/dist/src/URLStrategy.d.ts +32 -32
- package/dist/src/View.d.ts +44 -49
- package/dist/src/api.d.ts +13 -14
- package/package.json +30 -46
- package/src/HashStrategy.ts +1 -1
- package/src/RouteMatcher.ts +0 -2
- package/src/Router.tsx +5 -2
- package/src/RouterStrategy.ts +53 -0
- package/src/URLStrategy.ts +1 -0
- package/src/View.tsx +14 -9
- package/src/api.ts +0 -2
package/dist/router.js
CHANGED
|
@@ -13,788 +13,711 @@ function ___$insertStyle(css) {
|
|
|
13
13
|
return css;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
17
|
-
|
|
18
16
|
var React = require('react');
|
|
19
17
|
var events = require('events');
|
|
20
18
|
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
function _interopNamespaceDefault(e) {
|
|
20
|
+
var n = Object.create(null);
|
|
21
|
+
if (e) {
|
|
22
|
+
Object.keys(e).forEach(function (k) {
|
|
23
|
+
if (k !== 'default') {
|
|
24
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
25
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return e[k]; }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
31
30
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
n["default"] = e;
|
|
36
|
-
return Object.freeze(n);
|
|
31
|
+
}
|
|
32
|
+
n.default = e;
|
|
33
|
+
return Object.freeze(n);
|
|
37
34
|
}
|
|
38
35
|
|
|
39
|
-
var React__namespace = /*#__PURE__*/
|
|
36
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
const EVENT_URL_CHANGE = 'urlchange';
|
|
39
|
+
class RouterStrategy extends events.EventEmitter {
|
|
40
|
+
constructor(router) {
|
|
41
|
+
super();
|
|
42
|
+
this.$router = router;
|
|
43
|
+
this.$viewMountListeners = [];
|
|
44
|
+
this.$viewUnmountListneners = [];
|
|
45
|
+
}
|
|
46
|
+
addViewMountCallback(cb) {
|
|
47
|
+
this.$viewMountListeners.push(cb);
|
|
48
|
+
}
|
|
49
|
+
removeViewMountCallback(cb) {
|
|
50
|
+
let idx = this.$viewMountListeners.indexOf(cb);
|
|
51
|
+
if (idx > -1) {
|
|
52
|
+
this.$viewMountListeners.splice(idx, 1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
addViewUnmountCallback(cb) {
|
|
56
|
+
this.$viewUnmountListneners.push(cb);
|
|
57
|
+
}
|
|
58
|
+
removeViewUnmountCallback(cb) {
|
|
59
|
+
let idx = this.$viewUnmountListneners.indexOf(cb);
|
|
60
|
+
if (idx > -1) {
|
|
61
|
+
this.$viewUnmountListneners.splice(idx, 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
* @param view
|
|
67
|
+
*/
|
|
68
|
+
__onViewMount(view) {
|
|
69
|
+
for (let i = 0; i < this.$viewMountListeners.length; i++) {
|
|
70
|
+
this.$viewMountListeners[i](view);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
* @param view
|
|
76
|
+
*/
|
|
77
|
+
__onViewUnmount(view) {
|
|
78
|
+
for (let i = 0; i < this.$viewUnmountListneners.length; i++) {
|
|
79
|
+
this.$viewUnmountListneners[i](view);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Gets the router
|
|
84
|
+
*/
|
|
85
|
+
getRouter() {
|
|
86
|
+
return this.$router;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Sets the browser title
|
|
90
|
+
*
|
|
91
|
+
* @param {string} title
|
|
92
|
+
*/
|
|
93
|
+
setTitle(title) {
|
|
94
|
+
let head = document.head.getElementsByTagName('title')[0];
|
|
95
|
+
if (!head) {
|
|
96
|
+
head = document.createElement('title');
|
|
97
|
+
document.head.appendChild(head);
|
|
98
|
+
}
|
|
99
|
+
if (!title) {
|
|
100
|
+
title = '';
|
|
101
|
+
}
|
|
102
|
+
head.innerText = title.toString();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Listen for URL change events
|
|
106
|
+
*
|
|
107
|
+
* @param callback
|
|
108
|
+
*/
|
|
109
|
+
addURLChangeCallback(callback) {
|
|
110
|
+
this.on(EVENT_URL_CHANGE, callback);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Removes an existing listener
|
|
114
|
+
*
|
|
115
|
+
* @param callback
|
|
116
|
+
*/
|
|
117
|
+
removeURLChangeCallback(callback) {
|
|
118
|
+
this.off(EVENT_URL_CHANGE, callback);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* navigate the history forward one entry. This is an alias for [go(1)]{@link go}
|
|
122
|
+
*/
|
|
123
|
+
forward() {
|
|
124
|
+
this.go(1);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Navigate the history back one entry. This is an alias for [go(-1)]{@link go}
|
|
128
|
+
*/
|
|
129
|
+
back() {
|
|
130
|
+
this.go(-1);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns true if can go back 1 entry.
|
|
134
|
+
* This is the same as calling [canGo(-1)]{@link canGo}
|
|
135
|
+
*/
|
|
136
|
+
canBack() {
|
|
137
|
+
return this.canGo(-1);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns true if can go forward 1 entry.
|
|
141
|
+
* This is the same as calling [canGo(1)]{@link canGo}
|
|
142
|
+
*/
|
|
143
|
+
canForward() {
|
|
144
|
+
return this.canGo(1);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Returns the URL one entry forward.
|
|
148
|
+
* This is the same as calling [peek(1)]{@link peek}
|
|
149
|
+
*/
|
|
150
|
+
peekForward() {
|
|
151
|
+
return this.peek(1);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns the URL one entry back.
|
|
155
|
+
* This is the same as calling [peek(-1)]{@link peek}
|
|
156
|
+
*/
|
|
157
|
+
peekBack() {
|
|
158
|
+
return this.peek(-1);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Fires the {@link EVENT_URL_CHANGE} event
|
|
162
|
+
* @param url
|
|
163
|
+
*/
|
|
164
|
+
_fireURLChange(url) {
|
|
165
|
+
this.emit(EVENT_URL_CHANGE, url);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
42
168
|
|
|
43
169
|
/**
|
|
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
|
-
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
140
|
-
// This environment has a native %IteratorPrototype%; use it instead
|
|
141
|
-
// of the polyfill.
|
|
142
|
-
IteratorPrototype = NativeIteratorPrototype;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
var Gp = GeneratorFunctionPrototype.prototype =
|
|
146
|
-
Generator.prototype = Object.create(IteratorPrototype);
|
|
147
|
-
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
148
|
-
define(Gp, "constructor", GeneratorFunctionPrototype);
|
|
149
|
-
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
|
|
150
|
-
GeneratorFunction.displayName = define(
|
|
151
|
-
GeneratorFunctionPrototype,
|
|
152
|
-
toStringTagSymbol,
|
|
153
|
-
"GeneratorFunction"
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
// Helper for defining the .next, .throw, and .return methods of the
|
|
157
|
-
// Iterator interface in terms of a single ._invoke method.
|
|
158
|
-
function defineIteratorMethods(prototype) {
|
|
159
|
-
["next", "throw", "return"].forEach(function(method) {
|
|
160
|
-
define(prototype, method, function(arg) {
|
|
161
|
-
return this._invoke(method, arg);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
exports.isGeneratorFunction = function(genFun) {
|
|
167
|
-
var ctor = typeof genFun === "function" && genFun.constructor;
|
|
168
|
-
return ctor
|
|
169
|
-
? ctor === GeneratorFunction ||
|
|
170
|
-
// For the native GeneratorFunction constructor, the best we can
|
|
171
|
-
// do is to check its .name property.
|
|
172
|
-
(ctor.displayName || ctor.name) === "GeneratorFunction"
|
|
173
|
-
: false;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
exports.mark = function(genFun) {
|
|
177
|
-
if (Object.setPrototypeOf) {
|
|
178
|
-
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
179
|
-
} else {
|
|
180
|
-
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
181
|
-
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
182
|
-
}
|
|
183
|
-
genFun.prototype = Object.create(Gp);
|
|
184
|
-
return genFun;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
// Within the body of any async function, `await x` is transformed to
|
|
188
|
-
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
|
|
189
|
-
// `hasOwn.call(value, "__await")` to determine if the yielded value is
|
|
190
|
-
// meant to be awaited.
|
|
191
|
-
exports.awrap = function(arg) {
|
|
192
|
-
return { __await: arg };
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
196
|
-
function invoke(method, arg, resolve, reject) {
|
|
197
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
198
|
-
if (record.type === "throw") {
|
|
199
|
-
reject(record.arg);
|
|
200
|
-
} else {
|
|
201
|
-
var result = record.arg;
|
|
202
|
-
var value = result.value;
|
|
203
|
-
if (value &&
|
|
204
|
-
typeof value === "object" &&
|
|
205
|
-
hasOwn.call(value, "__await")) {
|
|
206
|
-
return PromiseImpl.resolve(value.__await).then(function(value) {
|
|
207
|
-
invoke("next", value, resolve, reject);
|
|
208
|
-
}, function(err) {
|
|
209
|
-
invoke("throw", err, resolve, reject);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return PromiseImpl.resolve(value).then(function(unwrapped) {
|
|
214
|
-
// When a yielded Promise is resolved, its final value becomes
|
|
215
|
-
// the .value of the Promise<{value,done}> result for the
|
|
216
|
-
// current iteration.
|
|
217
|
-
result.value = unwrapped;
|
|
218
|
-
resolve(result);
|
|
219
|
-
}, function(error) {
|
|
220
|
-
// If a rejected Promise was yielded, throw the rejection back
|
|
221
|
-
// into the async generator function so it can be handled there.
|
|
222
|
-
return invoke("throw", error, resolve, reject);
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
var previousPromise;
|
|
228
|
-
|
|
229
|
-
function enqueue(method, arg) {
|
|
230
|
-
function callInvokeWithMethodAndArg() {
|
|
231
|
-
return new PromiseImpl(function(resolve, reject) {
|
|
232
|
-
invoke(method, arg, resolve, reject);
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return previousPromise =
|
|
237
|
-
// If enqueue has been called before, then we want to wait until
|
|
238
|
-
// all previous Promises have been resolved before calling invoke,
|
|
239
|
-
// so that results are always delivered in the correct order. If
|
|
240
|
-
// enqueue has not been called before, then it is important to
|
|
241
|
-
// call invoke immediately, without waiting on a callback to fire,
|
|
242
|
-
// so that the async generator function has the opportunity to do
|
|
243
|
-
// any necessary setup in a predictable way. This predictability
|
|
244
|
-
// is why the Promise constructor synchronously invokes its
|
|
245
|
-
// executor callback, and why async functions synchronously
|
|
246
|
-
// execute code before the first await. Since we implement simple
|
|
247
|
-
// async functions in terms of async generators, it is especially
|
|
248
|
-
// important to get this right, even though it requires care.
|
|
249
|
-
previousPromise ? previousPromise.then(
|
|
250
|
-
callInvokeWithMethodAndArg,
|
|
251
|
-
// Avoid propagating failures to Promises returned by later
|
|
252
|
-
// invocations of the iterator.
|
|
253
|
-
callInvokeWithMethodAndArg
|
|
254
|
-
) : callInvokeWithMethodAndArg();
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Define the unified helper method that is used to implement .next,
|
|
258
|
-
// .throw, and .return (see defineIteratorMethods).
|
|
259
|
-
this._invoke = enqueue;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
defineIteratorMethods(AsyncIterator.prototype);
|
|
263
|
-
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
264
|
-
return this;
|
|
265
|
-
});
|
|
266
|
-
exports.AsyncIterator = AsyncIterator;
|
|
267
|
-
|
|
268
|
-
// Note that simple async functions are implemented on top of
|
|
269
|
-
// AsyncIterator objects; they just return a Promise for the value of
|
|
270
|
-
// the final result produced by the iterator.
|
|
271
|
-
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
272
|
-
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
273
|
-
|
|
274
|
-
var iter = new AsyncIterator(
|
|
275
|
-
wrap(innerFn, outerFn, self, tryLocsList),
|
|
276
|
-
PromiseImpl
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
return exports.isGeneratorFunction(outerFn)
|
|
280
|
-
? iter // If outerFn is a generator, return the full iterator.
|
|
281
|
-
: iter.next().then(function(result) {
|
|
282
|
-
return result.done ? result.value : iter.next();
|
|
283
|
-
});
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
287
|
-
var state = GenStateSuspendedStart;
|
|
288
|
-
|
|
289
|
-
return function invoke(method, arg) {
|
|
290
|
-
if (state === GenStateExecuting) {
|
|
291
|
-
throw new Error("Generator is already running");
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (state === GenStateCompleted) {
|
|
295
|
-
if (method === "throw") {
|
|
296
|
-
throw arg;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// Be forgiving, per 25.3.3.3.3 of the spec:
|
|
300
|
-
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
|
|
301
|
-
return doneResult();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
context.method = method;
|
|
305
|
-
context.arg = arg;
|
|
306
|
-
|
|
307
|
-
while (true) {
|
|
308
|
-
var delegate = context.delegate;
|
|
309
|
-
if (delegate) {
|
|
310
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
311
|
-
if (delegateResult) {
|
|
312
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
313
|
-
return delegateResult;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
if (context.method === "next") {
|
|
318
|
-
// Setting context._sent for legacy support of Babel's
|
|
319
|
-
// function.sent implementation.
|
|
320
|
-
context.sent = context._sent = context.arg;
|
|
321
|
-
|
|
322
|
-
} else if (context.method === "throw") {
|
|
323
|
-
if (state === GenStateSuspendedStart) {
|
|
324
|
-
state = GenStateCompleted;
|
|
325
|
-
throw context.arg;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
context.dispatchException(context.arg);
|
|
329
|
-
|
|
330
|
-
} else if (context.method === "return") {
|
|
331
|
-
context.abrupt("return", context.arg);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
state = GenStateExecuting;
|
|
335
|
-
|
|
336
|
-
var record = tryCatch(innerFn, self, context);
|
|
337
|
-
if (record.type === "normal") {
|
|
338
|
-
// If an exception is thrown from innerFn, we leave state ===
|
|
339
|
-
// GenStateExecuting and loop back for another invocation.
|
|
340
|
-
state = context.done
|
|
341
|
-
? GenStateCompleted
|
|
342
|
-
: GenStateSuspendedYield;
|
|
343
|
-
|
|
344
|
-
if (record.arg === ContinueSentinel) {
|
|
345
|
-
continue;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
return {
|
|
349
|
-
value: record.arg,
|
|
350
|
-
done: context.done
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
} else if (record.type === "throw") {
|
|
354
|
-
state = GenStateCompleted;
|
|
355
|
-
// Dispatch the exception by looping back around to the
|
|
356
|
-
// context.dispatchException(context.arg) call above.
|
|
357
|
-
context.method = "throw";
|
|
358
|
-
context.arg = record.arg;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// Call delegate.iterator[context.method](context.arg) and handle the
|
|
365
|
-
// result, either by returning a { value, done } result from the
|
|
366
|
-
// delegate iterator, or by modifying context.method and context.arg,
|
|
367
|
-
// setting context.delegate to null, and returning the ContinueSentinel.
|
|
368
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
369
|
-
var method = delegate.iterator[context.method];
|
|
370
|
-
if (method === undefined$1) {
|
|
371
|
-
// A .throw or .return when the delegate iterator has no .throw
|
|
372
|
-
// method always terminates the yield* loop.
|
|
373
|
-
context.delegate = null;
|
|
374
|
-
|
|
375
|
-
if (context.method === "throw") {
|
|
376
|
-
// Note: ["return"] must be used for ES3 parsing compatibility.
|
|
377
|
-
if (delegate.iterator["return"]) {
|
|
378
|
-
// If the delegate iterator has a return method, give it a
|
|
379
|
-
// chance to clean up.
|
|
380
|
-
context.method = "return";
|
|
381
|
-
context.arg = undefined$1;
|
|
382
|
-
maybeInvokeDelegate(delegate, context);
|
|
383
|
-
|
|
384
|
-
if (context.method === "throw") {
|
|
385
|
-
// If maybeInvokeDelegate(context) changed context.method from
|
|
386
|
-
// "return" to "throw", let that override the TypeError below.
|
|
387
|
-
return ContinueSentinel;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
context.method = "throw";
|
|
392
|
-
context.arg = new TypeError(
|
|
393
|
-
"The iterator does not provide a 'throw' method");
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
return ContinueSentinel;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
400
|
-
|
|
401
|
-
if (record.type === "throw") {
|
|
402
|
-
context.method = "throw";
|
|
403
|
-
context.arg = record.arg;
|
|
404
|
-
context.delegate = null;
|
|
405
|
-
return ContinueSentinel;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
var info = record.arg;
|
|
409
|
-
|
|
410
|
-
if (! info) {
|
|
411
|
-
context.method = "throw";
|
|
412
|
-
context.arg = new TypeError("iterator result is not an object");
|
|
413
|
-
context.delegate = null;
|
|
414
|
-
return ContinueSentinel;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
if (info.done) {
|
|
418
|
-
// Assign the result of the finished delegate to the temporary
|
|
419
|
-
// variable specified by delegate.resultName (see delegateYield).
|
|
420
|
-
context[delegate.resultName] = info.value;
|
|
421
|
-
|
|
422
|
-
// Resume execution at the desired location (see delegateYield).
|
|
423
|
-
context.next = delegate.nextLoc;
|
|
424
|
-
|
|
425
|
-
// If context.method was "throw" but the delegate handled the
|
|
426
|
-
// exception, let the outer generator proceed normally. If
|
|
427
|
-
// context.method was "next", forget context.arg since it has been
|
|
428
|
-
// "consumed" by the delegate iterator. If context.method was
|
|
429
|
-
// "return", allow the original .return call to continue in the
|
|
430
|
-
// outer generator.
|
|
431
|
-
if (context.method !== "return") {
|
|
432
|
-
context.method = "next";
|
|
433
|
-
context.arg = undefined$1;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
} else {
|
|
437
|
-
// Re-yield the result returned by the delegate method.
|
|
438
|
-
return info;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// The delegate iterator is finished, so forget it and continue with
|
|
442
|
-
// the outer generator.
|
|
443
|
-
context.delegate = null;
|
|
444
|
-
return ContinueSentinel;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// Define Generator.prototype.{next,throw,return} in terms of the
|
|
448
|
-
// unified ._invoke helper method.
|
|
449
|
-
defineIteratorMethods(Gp);
|
|
450
|
-
|
|
451
|
-
define(Gp, toStringTagSymbol, "Generator");
|
|
452
|
-
|
|
453
|
-
// A Generator should always return itself as the iterator object when the
|
|
454
|
-
// @@iterator function is called on it. Some browsers' implementations of the
|
|
455
|
-
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
456
|
-
// object to not be returned from this call. This ensures that doesn't happen.
|
|
457
|
-
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
458
|
-
define(Gp, iteratorSymbol, function() {
|
|
459
|
-
return this;
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
define(Gp, "toString", function() {
|
|
463
|
-
return "[object Generator]";
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
function pushTryEntry(locs) {
|
|
467
|
-
var entry = { tryLoc: locs[0] };
|
|
468
|
-
|
|
469
|
-
if (1 in locs) {
|
|
470
|
-
entry.catchLoc = locs[1];
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
if (2 in locs) {
|
|
474
|
-
entry.finallyLoc = locs[2];
|
|
475
|
-
entry.afterLoc = locs[3];
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
this.tryEntries.push(entry);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function resetTryEntry(entry) {
|
|
482
|
-
var record = entry.completion || {};
|
|
483
|
-
record.type = "normal";
|
|
484
|
-
delete record.arg;
|
|
485
|
-
entry.completion = record;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
function Context(tryLocsList) {
|
|
489
|
-
// The root entry object (effectively a try statement without a catch
|
|
490
|
-
// or a finally block) gives us a place to store values thrown from
|
|
491
|
-
// locations where there is no enclosing try statement.
|
|
492
|
-
this.tryEntries = [{ tryLoc: "root" }];
|
|
493
|
-
tryLocsList.forEach(pushTryEntry, this);
|
|
494
|
-
this.reset(true);
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
exports.keys = function(object) {
|
|
498
|
-
var keys = [];
|
|
499
|
-
for (var key in object) {
|
|
500
|
-
keys.push(key);
|
|
501
|
-
}
|
|
502
|
-
keys.reverse();
|
|
503
|
-
|
|
504
|
-
// Rather than returning an object with a next method, we keep
|
|
505
|
-
// things simple and return the next function itself.
|
|
506
|
-
return function next() {
|
|
507
|
-
while (keys.length) {
|
|
508
|
-
var key = keys.pop();
|
|
509
|
-
if (key in object) {
|
|
510
|
-
next.value = key;
|
|
511
|
-
next.done = false;
|
|
512
|
-
return next;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// To avoid creating an additional object, we just hang the .value
|
|
517
|
-
// and .done properties off the next function object itself. This
|
|
518
|
-
// also ensures that the minifier will not anonymize the function.
|
|
519
|
-
next.done = true;
|
|
520
|
-
return next;
|
|
521
|
-
};
|
|
522
|
-
};
|
|
523
|
-
|
|
524
|
-
function values(iterable) {
|
|
525
|
-
if (iterable) {
|
|
526
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
527
|
-
if (iteratorMethod) {
|
|
528
|
-
return iteratorMethod.call(iterable);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
if (typeof iterable.next === "function") {
|
|
532
|
-
return iterable;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
if (!isNaN(iterable.length)) {
|
|
536
|
-
var i = -1, next = function next() {
|
|
537
|
-
while (++i < iterable.length) {
|
|
538
|
-
if (hasOwn.call(iterable, i)) {
|
|
539
|
-
next.value = iterable[i];
|
|
540
|
-
next.done = false;
|
|
541
|
-
return next;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
next.value = undefined$1;
|
|
546
|
-
next.done = true;
|
|
547
|
-
|
|
548
|
-
return next;
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
return next.next = next;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// Return an iterator with no values.
|
|
556
|
-
return { next: doneResult };
|
|
557
|
-
}
|
|
558
|
-
exports.values = values;
|
|
559
|
-
|
|
560
|
-
function doneResult() {
|
|
561
|
-
return { value: undefined$1, done: true };
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
Context.prototype = {
|
|
565
|
-
constructor: Context,
|
|
566
|
-
|
|
567
|
-
reset: function(skipTempReset) {
|
|
568
|
-
this.prev = 0;
|
|
569
|
-
this.next = 0;
|
|
570
|
-
// Resetting context._sent for legacy support of Babel's
|
|
571
|
-
// function.sent implementation.
|
|
572
|
-
this.sent = this._sent = undefined$1;
|
|
573
|
-
this.done = false;
|
|
574
|
-
this.delegate = null;
|
|
575
|
-
|
|
576
|
-
this.method = "next";
|
|
577
|
-
this.arg = undefined$1;
|
|
578
|
-
|
|
579
|
-
this.tryEntries.forEach(resetTryEntry);
|
|
580
|
-
|
|
581
|
-
if (!skipTempReset) {
|
|
582
|
-
for (var name in this) {
|
|
583
|
-
// Not sure about the optimal order of these conditions:
|
|
584
|
-
if (name.charAt(0) === "t" &&
|
|
585
|
-
hasOwn.call(this, name) &&
|
|
586
|
-
!isNaN(+name.slice(1))) {
|
|
587
|
-
this[name] = undefined$1;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
},
|
|
592
|
-
|
|
593
|
-
stop: function() {
|
|
594
|
-
this.done = true;
|
|
595
|
-
|
|
596
|
-
var rootEntry = this.tryEntries[0];
|
|
597
|
-
var rootRecord = rootEntry.completion;
|
|
598
|
-
if (rootRecord.type === "throw") {
|
|
599
|
-
throw rootRecord.arg;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
return this.rval;
|
|
603
|
-
},
|
|
604
|
-
|
|
605
|
-
dispatchException: function(exception) {
|
|
606
|
-
if (this.done) {
|
|
607
|
-
throw exception;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
var context = this;
|
|
611
|
-
function handle(loc, caught) {
|
|
612
|
-
record.type = "throw";
|
|
613
|
-
record.arg = exception;
|
|
614
|
-
context.next = loc;
|
|
615
|
-
|
|
616
|
-
if (caught) {
|
|
617
|
-
// If the dispatched exception was caught by a catch block,
|
|
618
|
-
// then let that catch block handle the exception normally.
|
|
619
|
-
context.method = "next";
|
|
620
|
-
context.arg = undefined$1;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
return !! caught;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
627
|
-
var entry = this.tryEntries[i];
|
|
628
|
-
var record = entry.completion;
|
|
629
|
-
|
|
630
|
-
if (entry.tryLoc === "root") {
|
|
631
|
-
// Exception thrown outside of any try block that could handle
|
|
632
|
-
// it, so set the completion value of the entire function to
|
|
633
|
-
// throw the exception.
|
|
634
|
-
return handle("end");
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
if (entry.tryLoc <= this.prev) {
|
|
638
|
-
var hasCatch = hasOwn.call(entry, "catchLoc");
|
|
639
|
-
var hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
640
|
-
|
|
641
|
-
if (hasCatch && hasFinally) {
|
|
642
|
-
if (this.prev < entry.catchLoc) {
|
|
643
|
-
return handle(entry.catchLoc, true);
|
|
644
|
-
} else if (this.prev < entry.finallyLoc) {
|
|
645
|
-
return handle(entry.finallyLoc);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
} else if (hasCatch) {
|
|
649
|
-
if (this.prev < entry.catchLoc) {
|
|
650
|
-
return handle(entry.catchLoc, true);
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
} else if (hasFinally) {
|
|
654
|
-
if (this.prev < entry.finallyLoc) {
|
|
655
|
-
return handle(entry.finallyLoc);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
} else {
|
|
659
|
-
throw new Error("try statement without catch or finally");
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
},
|
|
664
|
-
|
|
665
|
-
abrupt: function(type, arg) {
|
|
666
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
667
|
-
var entry = this.tryEntries[i];
|
|
668
|
-
if (entry.tryLoc <= this.prev &&
|
|
669
|
-
hasOwn.call(entry, "finallyLoc") &&
|
|
670
|
-
this.prev < entry.finallyLoc) {
|
|
671
|
-
var finallyEntry = entry;
|
|
672
|
-
break;
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
if (finallyEntry &&
|
|
677
|
-
(type === "break" ||
|
|
678
|
-
type === "continue") &&
|
|
679
|
-
finallyEntry.tryLoc <= arg &&
|
|
680
|
-
arg <= finallyEntry.finallyLoc) {
|
|
681
|
-
// Ignore the finally entry if control is not jumping to a
|
|
682
|
-
// location outside the try/catch block.
|
|
683
|
-
finallyEntry = null;
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
var record = finallyEntry ? finallyEntry.completion : {};
|
|
687
|
-
record.type = type;
|
|
688
|
-
record.arg = arg;
|
|
689
|
-
|
|
690
|
-
if (finallyEntry) {
|
|
691
|
-
this.method = "next";
|
|
692
|
-
this.next = finallyEntry.finallyLoc;
|
|
693
|
-
return ContinueSentinel;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
return this.complete(record);
|
|
697
|
-
},
|
|
698
|
-
|
|
699
|
-
complete: function(record, afterLoc) {
|
|
700
|
-
if (record.type === "throw") {
|
|
701
|
-
throw record.arg;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
if (record.type === "break" ||
|
|
705
|
-
record.type === "continue") {
|
|
706
|
-
this.next = record.arg;
|
|
707
|
-
} else if (record.type === "return") {
|
|
708
|
-
this.rval = this.arg = record.arg;
|
|
709
|
-
this.method = "return";
|
|
710
|
-
this.next = "end";
|
|
711
|
-
} else if (record.type === "normal" && afterLoc) {
|
|
712
|
-
this.next = afterLoc;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
return ContinueSentinel;
|
|
716
|
-
},
|
|
717
|
-
|
|
718
|
-
finish: function(finallyLoc) {
|
|
719
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
720
|
-
var entry = this.tryEntries[i];
|
|
721
|
-
if (entry.finallyLoc === finallyLoc) {
|
|
722
|
-
this.complete(entry.completion, entry.afterLoc);
|
|
723
|
-
resetTryEntry(entry);
|
|
724
|
-
return ContinueSentinel;
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
},
|
|
728
|
-
|
|
729
|
-
"catch": function(tryLoc) {
|
|
730
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
731
|
-
var entry = this.tryEntries[i];
|
|
732
|
-
if (entry.tryLoc === tryLoc) {
|
|
733
|
-
var record = entry.completion;
|
|
734
|
-
if (record.type === "throw") {
|
|
735
|
-
var thrown = record.arg;
|
|
736
|
-
resetTryEntry(entry);
|
|
737
|
-
}
|
|
738
|
-
return thrown;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
// The context.catch method must only be called with a location
|
|
743
|
-
// argument that corresponds to a known catch block.
|
|
744
|
-
throw new Error("illegal catch attempt");
|
|
745
|
-
},
|
|
746
|
-
|
|
747
|
-
delegateYield: function(iterable, resultName, nextLoc) {
|
|
748
|
-
this.delegate = {
|
|
749
|
-
iterator: values(iterable),
|
|
750
|
-
resultName: resultName,
|
|
751
|
-
nextLoc: nextLoc
|
|
752
|
-
};
|
|
170
|
+
A {@link RouterStrategy} that manages a history stack using inline pound symbols `#`.
|
|
171
|
+
URLs will have a starting point `/#/`, as a default base.
|
|
172
|
+
|
|
173
|
+
For example, if you [pushState("mylink")]{@link pushState}, the url
|
|
174
|
+
`/#/mylink` will be produced.
|
|
175
|
+
*/
|
|
176
|
+
class HashStrategy extends RouterStrategy {
|
|
177
|
+
constructor(router) {
|
|
178
|
+
super(router);
|
|
179
|
+
this.$base = '#';
|
|
180
|
+
this.$stack = [];
|
|
181
|
+
this.$position = -1;
|
|
182
|
+
this.$lastFiredLocation = null;
|
|
183
|
+
window.addEventListener('popstate', (ev) => {
|
|
184
|
+
let location = this.getLocation();
|
|
185
|
+
if (this.$lastFiredLocation !== location) {
|
|
186
|
+
this._fireURLChange(location);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
window.addEventListener('hashchange', (e) => {
|
|
190
|
+
let location = this.getLocation();
|
|
191
|
+
if (this.$lastFiredLocation !== location) {
|
|
192
|
+
this._fireURLChange(location);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
this.$init();
|
|
196
|
+
}
|
|
197
|
+
$init() {
|
|
198
|
+
this.pushState(this.getLocation());
|
|
199
|
+
}
|
|
200
|
+
getLocation() {
|
|
201
|
+
return window.location.hash.replace('#', '');
|
|
202
|
+
}
|
|
203
|
+
getLocationAt(position) {
|
|
204
|
+
return this.$stack[this.$position + position];
|
|
205
|
+
}
|
|
206
|
+
getHistoryLength() {
|
|
207
|
+
return this.$stack.length;
|
|
208
|
+
}
|
|
209
|
+
getScrollRestoration() {
|
|
210
|
+
return window.history.scrollRestoration;
|
|
211
|
+
}
|
|
212
|
+
canGo(to) {
|
|
213
|
+
return this.$stack[this.$position + to] !== undefined;
|
|
214
|
+
}
|
|
215
|
+
peek(to) {
|
|
216
|
+
return this.$stack[this.$position + to];
|
|
217
|
+
}
|
|
218
|
+
go(to) {
|
|
219
|
+
if (!this.canGo(to)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.$position += to;
|
|
223
|
+
let url = this.$stack[this.$position];
|
|
224
|
+
this.$navigate(url);
|
|
225
|
+
}
|
|
226
|
+
pushState(url, state) {
|
|
227
|
+
if (url === this.getLocation()) {
|
|
228
|
+
//We are already here, so do nothing.
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (this.$stack.length === 0) {
|
|
232
|
+
this.$stack[++this.$position] = this.getLocation();
|
|
233
|
+
}
|
|
234
|
+
this.$stack[++this.$position] = url;
|
|
235
|
+
//clear everything after position.
|
|
236
|
+
this.$stack = this.$stack.slice(0, this.$position + 1);
|
|
237
|
+
this.$navigate(url);
|
|
238
|
+
}
|
|
239
|
+
replaceState(url, state) {
|
|
240
|
+
if (url === this.getLocation()) {
|
|
241
|
+
//We are already here, so do nothing.
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (this.$position === -1) {
|
|
245
|
+
this.pushState(url, state);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
this.$stack[this.$position] = url;
|
|
249
|
+
this.$navigate(url);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
clear() {
|
|
253
|
+
this.$stack = [];
|
|
254
|
+
this.$position = -1;
|
|
255
|
+
}
|
|
256
|
+
$navigate(url) {
|
|
257
|
+
window.location.hash = this.$base + url;
|
|
258
|
+
this._fireURLChange(this.getLocation());
|
|
259
|
+
}
|
|
260
|
+
_fireURLChange(url) {
|
|
261
|
+
this.$lastFiredLocation = url;
|
|
262
|
+
super._fireURLChange(url);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
753
265
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
266
|
+
/**
|
|
267
|
+
Alias for {@link HashStrategy}
|
|
268
|
+
*/
|
|
269
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
270
|
+
let DefaultStrategy = HashStrategy;
|
|
759
271
|
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
272
|
+
/**
|
|
273
|
+
* Parses the URL for router paths and url-based variables.
|
|
274
|
+
*/
|
|
275
|
+
class URLParser {
|
|
276
|
+
/**
|
|
277
|
+
*
|
|
278
|
+
* @param {string} pattern The URL pattern
|
|
279
|
+
* @param {boolean} allowPartialMatch If true, the pattern will match again urls that contains the pattern,
|
|
280
|
+
* even if it isn't an exact match.
|
|
281
|
+
* Defaults to false.
|
|
282
|
+
*/
|
|
283
|
+
constructor(pattern, allowPartialMatch = false) {
|
|
284
|
+
this.$allowPartialMatch = allowPartialMatch;
|
|
285
|
+
this.$pattern = this.$stripURL(pattern);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Parses the URL and returns the url parameters.
|
|
289
|
+
* Returns null the url does not match the pattern
|
|
290
|
+
*
|
|
291
|
+
* @param {string} url The url to test
|
|
292
|
+
*/
|
|
293
|
+
parse(url) {
|
|
294
|
+
url = this.$stripURL(url);
|
|
295
|
+
let parts = this.$getParts(url);
|
|
296
|
+
let patternParts = this.$getParts(this.$pattern);
|
|
297
|
+
if ((!this.$allowPartialMatch && parts.length !== patternParts.length) || url === '') {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
let params = {};
|
|
301
|
+
for (let i = 0; i < patternParts.length; i++) {
|
|
302
|
+
let pPart = patternParts[i];
|
|
303
|
+
let uPart = parts[i];
|
|
304
|
+
if (uPart) {
|
|
305
|
+
if (pPart.charAt(0) === ':') {
|
|
306
|
+
params[pPart.slice(1)] = uPart;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
if (pPart !== uPart) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return params;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Strips the url for parsing, removing leading and trailing forward slashes.
|
|
322
|
+
*
|
|
323
|
+
* @private
|
|
324
|
+
* @param {string} url URL to strip
|
|
325
|
+
*/
|
|
326
|
+
$stripURL(url) {
|
|
327
|
+
while (url.charAt(0) === '/') {
|
|
328
|
+
url = url.slice(1);
|
|
329
|
+
}
|
|
330
|
+
while (url.charAt(url.length - 1) === '/') {
|
|
331
|
+
url = url.slice(0, url.length - 1);
|
|
332
|
+
}
|
|
333
|
+
return url;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Splits the url into an array of URL parts, separated by the forward slash
|
|
337
|
+
*
|
|
338
|
+
* @private
|
|
339
|
+
* @param {string} url URL to split
|
|
340
|
+
*/
|
|
341
|
+
$getParts(url) {
|
|
342
|
+
url = this.$stripURL(url);
|
|
343
|
+
return url.split('/');
|
|
344
|
+
}
|
|
345
|
+
}
|
|
763
346
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
347
|
+
/**
|
|
348
|
+
* This class is reponsible for determing which route to render
|
|
349
|
+
* based on the URL and the route url patterns.
|
|
350
|
+
*/
|
|
351
|
+
class RouteMatcher {
|
|
352
|
+
constructor(routerStrategy) {
|
|
353
|
+
this.$strategy = routerStrategy;
|
|
354
|
+
}
|
|
355
|
+
$defaultNoRouteFunction(indexRoute, routes) {
|
|
356
|
+
return indexRoute;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Matches the url to the appropriate renderable route
|
|
360
|
+
*
|
|
361
|
+
* @param url
|
|
362
|
+
* @param children
|
|
363
|
+
* @param base
|
|
364
|
+
* @param indexRoute
|
|
365
|
+
* @param onNoRoute
|
|
366
|
+
*/
|
|
367
|
+
match(url, children, base, indexRoute, onNoRoute) {
|
|
368
|
+
let componentToRender = null;
|
|
369
|
+
let params = null;
|
|
370
|
+
for (let i = 0; i < children.length; i++) {
|
|
371
|
+
let route = children[i];
|
|
372
|
+
let shouldAllowPartialMatching = !!route.props.children;
|
|
373
|
+
let parser = new URLParser(base + route.props.url, shouldAllowPartialMatching);
|
|
374
|
+
params = parser.parse(url);
|
|
375
|
+
if (params) {
|
|
376
|
+
componentToRender = route;
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (!componentToRender) {
|
|
381
|
+
componentToRender = (onNoRoute ? onNoRoute : this.$defaultNoRouteFunction)(indexRoute, children);
|
|
382
|
+
}
|
|
383
|
+
if (!componentToRender) {
|
|
384
|
+
if (!base) {
|
|
385
|
+
console.warn('No routes matched, and no index route available.');
|
|
386
|
+
}
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
let props = {
|
|
390
|
+
url: url,
|
|
391
|
+
base: base + componentToRender.props.url,
|
|
392
|
+
matcher: this,
|
|
393
|
+
component: componentToRender.props.component,
|
|
394
|
+
entryTransition: componentToRender.props.entryTransition,
|
|
395
|
+
exitTransition: componentToRender.props.exitTransition,
|
|
396
|
+
componentProps: {
|
|
397
|
+
url: url,
|
|
398
|
+
router: this.$strategy
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
if (params) {
|
|
402
|
+
for (let i in params) {
|
|
403
|
+
props.componentProps[i] = params[i];
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return React.cloneElement(componentToRender, props);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
769
409
|
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
410
|
+
class Router extends React__namespace.Component {
|
|
411
|
+
constructor(props) {
|
|
412
|
+
super(props);
|
|
413
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
414
|
+
let Strategy;
|
|
415
|
+
if (!props.strategy) {
|
|
416
|
+
Strategy = DefaultStrategy;
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
Strategy = props.strategy;
|
|
420
|
+
}
|
|
421
|
+
let strategy = new Strategy(this);
|
|
422
|
+
this.state = {
|
|
423
|
+
strategy: strategy,
|
|
424
|
+
url: strategy.getLocation(),
|
|
425
|
+
shouldTransition: false
|
|
426
|
+
};
|
|
427
|
+
this.$lastRenderedRoute = null;
|
|
428
|
+
this.$onURLChange = this.$onURLChange.bind(this);
|
|
429
|
+
this.$matcher = new RouteMatcher(strategy);
|
|
430
|
+
}
|
|
431
|
+
static getInstance() {
|
|
432
|
+
if (!Router.$instance) {
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
return Router.$instance.getRouterStrategy();
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Gets the current routing strategy
|
|
439
|
+
*/
|
|
440
|
+
getRouterStrategy() {
|
|
441
|
+
return this.state.strategy;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* @ignore
|
|
445
|
+
*/
|
|
446
|
+
$onURLChange(url) {
|
|
447
|
+
if (url !== this.state.url) {
|
|
448
|
+
this.setState({
|
|
449
|
+
url: url,
|
|
450
|
+
shouldTransition: true
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
componentDidMount() {
|
|
455
|
+
Router.$instance = this;
|
|
456
|
+
this.state.strategy.addURLChangeCallback(this.$onURLChange);
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* @ignore
|
|
460
|
+
*/
|
|
461
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
462
|
+
if (nextProps.strategy && (this.state.strategy instanceof nextProps.strategy)) {
|
|
463
|
+
this.state.strategy.removeURLChangeCallback(this.$onURLChange);
|
|
464
|
+
let strat = new nextProps.strategy(this);
|
|
465
|
+
strat.addURLChangeCallback(this.$onURLChange);
|
|
466
|
+
this.setState({
|
|
467
|
+
strategy: strat
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* @ignore
|
|
473
|
+
*/
|
|
474
|
+
componentWillUnmount() {
|
|
475
|
+
Router.$instance = null;
|
|
476
|
+
this.state.strategy.removeURLChangeCallback(this.$onURLChange);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* @ignore
|
|
480
|
+
*/
|
|
481
|
+
render() {
|
|
482
|
+
let currentRoute = this.$matcher.match(this.state.url || '/', this.$getChildren(), '', this.$getIndexRoute(), this.props.onNoRoute);
|
|
483
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
484
|
+
let Root = null;
|
|
485
|
+
if (this.props.component) {
|
|
486
|
+
Root = this.props.component;
|
|
487
|
+
}
|
|
488
|
+
if (this.state.shouldTransition && (currentRoute.props.entryTransition || (this.$lastRenderedRoute &&
|
|
489
|
+
this.$lastRenderedRoute.props.exitTransition))) {
|
|
490
|
+
this.$awaitingTransition = true;
|
|
491
|
+
let exiting = null;
|
|
492
|
+
if (this.$lastRenderedRoute) {
|
|
493
|
+
exiting = React__namespace.cloneElement(this.$lastRenderedRoute, {
|
|
494
|
+
ref: (route) => {
|
|
495
|
+
this.$exitingRoute = route;
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
// Incoming will always be safe to render, hence no defensive checks
|
|
500
|
+
let incoming = React__namespace.cloneElement(currentRoute, {
|
|
501
|
+
ref: (route) => {
|
|
502
|
+
this.$incomingRoute = route;
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
if (Root) {
|
|
506
|
+
return React__namespace.createElement(Root, { router: this.getRouterStrategy(), url: this.state.url }, [exiting, incoming]);
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
return [exiting, incoming];
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
else {
|
|
513
|
+
this.$lastRenderedRoute = currentRoute;
|
|
514
|
+
if (Root) {
|
|
515
|
+
// currentRoute must be rendered as an array; because, exiting and incoming is rendered as an array.
|
|
516
|
+
// if currentRoute is not rendered as an array, a bug happens where the exiting screen is reloaded
|
|
517
|
+
// calling the constructor again.
|
|
518
|
+
return React__namespace.createElement(Root, { router: this.getRouterStrategy(), url: this.state.url }, [currentRoute]);
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
return currentRoute;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* @ignore
|
|
527
|
+
*/
|
|
528
|
+
componentDidUpdate() {
|
|
529
|
+
if (this.$awaitingTransition) {
|
|
530
|
+
this.$awaitingTransition = false;
|
|
531
|
+
let exitTransitionPromise = null;
|
|
532
|
+
if (this.$exitingRoute && this.$exitingRoute.props.exitTransition) {
|
|
533
|
+
exitTransitionPromise = this.$exitingRoute.props.exitTransition.execute(this.$incomingRoute.getView(), this.$exitingRoute.getView());
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
exitTransitionPromise = Promise.resolve();
|
|
537
|
+
}
|
|
538
|
+
exitTransitionPromise.then(() => {
|
|
539
|
+
let entryTransitionPromise = null;
|
|
540
|
+
if (this.$incomingRoute.props.entryTransition) {
|
|
541
|
+
entryTransitionPromise = this.$incomingRoute.props.entryTransition.execute(this.$incomingRoute.getView(), this.$exitingRoute.getView());
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
entryTransitionPromise = Promise.resolve();
|
|
545
|
+
}
|
|
546
|
+
return entryTransitionPromise;
|
|
547
|
+
}).catch((error) => {
|
|
548
|
+
console.error(error);
|
|
549
|
+
}).then(() => {
|
|
550
|
+
this.$incomingRoute = null;
|
|
551
|
+
this.$exitingRoute = null;
|
|
552
|
+
this.setState({ shouldTransition: false });
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Gets the number of history entries. Note this does not count the browser history.
|
|
558
|
+
* Only the history kept track during the life-cycle of the app.
|
|
559
|
+
*/
|
|
560
|
+
getHistoryLength() {
|
|
561
|
+
return this.state.strategy.getHistoryLength();
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Gets the scroll restoration mode
|
|
565
|
+
*/
|
|
566
|
+
getScrollRestoration() {
|
|
567
|
+
return this.state.strategy.getScrollRestoration();
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
*
|
|
571
|
+
* @param to An integer, positive means go forward, negative means go backwards. E.g:
|
|
572
|
+
* `1` move forward one step
|
|
573
|
+
* `-1` move backward one step
|
|
574
|
+
* `0` navigate to the current page (This is essentially a no-op)
|
|
575
|
+
*/
|
|
576
|
+
go(to) {
|
|
577
|
+
this.state.strategy.go(to);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Go back one step. This is an alias for [pushState(-1)]{@link go}.
|
|
581
|
+
*/
|
|
582
|
+
back() {
|
|
583
|
+
this.state.strategy.go(-1);
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Go forward one step. This is an alias for [pushState(1)]{@link go}.
|
|
587
|
+
*/
|
|
588
|
+
forward() {
|
|
589
|
+
this.state.strategy.go(1);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Gets the potential routes
|
|
593
|
+
*/
|
|
594
|
+
$getChildren() {
|
|
595
|
+
let children = null;
|
|
596
|
+
if (this.props.children instanceof Array) {
|
|
597
|
+
children = this.props.children;
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
children = [this.props.children];
|
|
601
|
+
}
|
|
602
|
+
return children;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Finds the index route. Returns null if there are no indexed routes.
|
|
606
|
+
*/
|
|
607
|
+
$getIndexRoute() {
|
|
608
|
+
let children = this.$getChildren();
|
|
609
|
+
for (let i = 0; i < children.length; i++) {
|
|
610
|
+
let child = children[i];
|
|
611
|
+
if (child.props.index) {
|
|
612
|
+
return child;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* @deprecated Use Router.getInstance() instead.
|
|
620
|
+
* @returns {RouterStrategy}
|
|
621
|
+
*/
|
|
622
|
+
let getRouter = () => {
|
|
623
|
+
console.warn('getRouter() is deprecated. use Router.getInstance() instead.');
|
|
624
|
+
return Router.getInstance();
|
|
625
|
+
};
|
|
777
626
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
627
|
+
/**
|
|
628
|
+
* @notice Using the URLStrategy requires some backend configuration
|
|
629
|
+
* to route URLs back to application.
|
|
630
|
+
*
|
|
631
|
+
* To make this easier, by default these URLs are prefixed with
|
|
632
|
+
* `/r/` to easily differentiate between URLs that needs to be re-routed back
|
|
633
|
+
* to the application vs other resources such as images.
|
|
634
|
+
*/
|
|
635
|
+
class URLStrategy extends RouterStrategy {
|
|
636
|
+
/**
|
|
637
|
+
*
|
|
638
|
+
* @param {Router} router
|
|
639
|
+
*/
|
|
640
|
+
constructor(router) {
|
|
641
|
+
super(router);
|
|
642
|
+
this.$base = window.location.origin + '/r';
|
|
643
|
+
this.$stack = [];
|
|
644
|
+
this.$position = -1;
|
|
645
|
+
window.addEventListener('popstate', () => {
|
|
646
|
+
this._fireURLChange(this.getLocation());
|
|
647
|
+
});
|
|
648
|
+
this.$init();
|
|
649
|
+
}
|
|
650
|
+
$init() {
|
|
651
|
+
this.pushState(this.getLocation());
|
|
652
|
+
}
|
|
653
|
+
getLocation() {
|
|
654
|
+
return window.location.pathname.replace('/r', '');
|
|
655
|
+
}
|
|
656
|
+
getLocationAt(position) {
|
|
657
|
+
return this.$stack[this.$position + position];
|
|
658
|
+
}
|
|
659
|
+
getHistoryLength() {
|
|
660
|
+
return window.history.length;
|
|
661
|
+
}
|
|
662
|
+
getScrollRestoration() {
|
|
663
|
+
return window.history.scrollRestoration;
|
|
664
|
+
}
|
|
665
|
+
peek(to) {
|
|
666
|
+
return this.$stack[this.$position + to];
|
|
667
|
+
}
|
|
668
|
+
canGo(to) {
|
|
669
|
+
return this.$stack[this.$position + to] !== undefined;
|
|
670
|
+
}
|
|
671
|
+
go(to) {
|
|
672
|
+
if (!this.canGo(to)) {
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
this.$position += to;
|
|
676
|
+
this.$navigate(this.$stack[this.$position]);
|
|
677
|
+
}
|
|
678
|
+
pushState(url, state) {
|
|
679
|
+
if (state) {
|
|
680
|
+
console.warn('Warning: The state parameter is not implemented yet.');
|
|
681
|
+
}
|
|
682
|
+
if (url === this.getLocation()) {
|
|
683
|
+
//We are already here, so do nothing.
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
this.$stack[++this.$position] = url;
|
|
687
|
+
//clear everything after position.
|
|
688
|
+
this.$stack = this.$stack.slice(0, this.$position + 1);
|
|
689
|
+
this.$navigate(url);
|
|
690
|
+
}
|
|
691
|
+
replaceState(url, state) {
|
|
692
|
+
if (state) {
|
|
693
|
+
console.warn('Warning: The state parameter is not implemented yet.');
|
|
694
|
+
}
|
|
695
|
+
if (url === this.getLocation()) {
|
|
696
|
+
//We are already here, so do nothing.
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
if (this.$position === -1) {
|
|
700
|
+
this.pushState(url, state);
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
this.$stack[this.$position] = url;
|
|
704
|
+
this.$navigate(url);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
clear() {
|
|
708
|
+
this.$stack = [];
|
|
709
|
+
this.$position = -1;
|
|
710
|
+
}
|
|
711
|
+
$navigate(url, replace = false) {
|
|
712
|
+
if (replace) {
|
|
713
|
+
window.history.replaceState({}, null, this.$base + url);
|
|
714
|
+
}
|
|
715
|
+
else {
|
|
716
|
+
window.history.pushState({}, null, this.$base + url);
|
|
717
|
+
}
|
|
718
|
+
this._fireURLChange(this.getLocation());
|
|
719
|
+
}
|
|
720
|
+
}
|
|
798
721
|
|
|
799
722
|
/******************************************************************************
|
|
800
723
|
Copyright (c) Microsoft Corporation.
|
|
@@ -810,33 +733,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
810
733
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
811
734
|
PERFORMANCE OF THIS SOFTWARE.
|
|
812
735
|
***************************************************************************** */
|
|
813
|
-
/* global Reflect, Promise */
|
|
814
|
-
|
|
815
|
-
var extendStatics = function(d, b) {
|
|
816
|
-
extendStatics = Object.setPrototypeOf ||
|
|
817
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
818
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
819
|
-
return extendStatics(d, b);
|
|
820
|
-
};
|
|
821
|
-
|
|
822
|
-
function __extends(d, b) {
|
|
823
|
-
if (typeof b !== "function" && b !== null)
|
|
824
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
825
|
-
extendStatics(d, b);
|
|
826
|
-
function __() { this.constructor = d; }
|
|
827
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
828
|
-
}
|
|
736
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
829
737
|
|
|
830
|
-
var __assign = function() {
|
|
831
|
-
__assign = Object.assign || function __assign(t) {
|
|
832
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
833
|
-
s = arguments[i];
|
|
834
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
835
|
-
}
|
|
836
|
-
return t;
|
|
837
|
-
};
|
|
838
|
-
return __assign.apply(this, arguments);
|
|
839
|
-
};
|
|
840
738
|
|
|
841
739
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
842
740
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -848,983 +746,280 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
848
746
|
});
|
|
849
747
|
}
|
|
850
748
|
|
|
851
|
-
function
|
|
852
|
-
var
|
|
853
|
-
return
|
|
854
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
855
|
-
function step(op) {
|
|
856
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
857
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
858
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
859
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
860
|
-
switch (op[0]) {
|
|
861
|
-
case 0: case 1: t = op; break;
|
|
862
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
863
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
864
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
865
|
-
default:
|
|
866
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
867
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
868
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
869
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
870
|
-
if (t[2]) _.ops.pop();
|
|
871
|
-
_.trys.pop(); continue;
|
|
872
|
-
}
|
|
873
|
-
op = body.call(thisArg, _);
|
|
874
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
875
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
var EVENT_URL_CHANGE = 'urlchange';
|
|
880
|
-
var RouterStrategy = /** @class */ (function (_super) {
|
|
881
|
-
__extends(RouterStrategy, _super);
|
|
882
|
-
function RouterStrategy(router) {
|
|
883
|
-
var _this = _super.call(this) || this;
|
|
884
|
-
_this.$router = router;
|
|
885
|
-
return _this;
|
|
886
|
-
}
|
|
887
|
-
/**
|
|
888
|
-
* Gets the router
|
|
889
|
-
*/
|
|
890
|
-
RouterStrategy.prototype.getRouter = function () {
|
|
891
|
-
return this.$router;
|
|
892
|
-
};
|
|
893
|
-
/**
|
|
894
|
-
* Sets the browser title
|
|
895
|
-
*
|
|
896
|
-
* @param {string} title
|
|
897
|
-
*/
|
|
898
|
-
RouterStrategy.prototype.setTitle = function (title) {
|
|
899
|
-
var head = document.head.getElementsByTagName('title')[0];
|
|
900
|
-
if (!head) {
|
|
901
|
-
head = document.createElement('title');
|
|
902
|
-
document.head.appendChild(head);
|
|
903
|
-
}
|
|
904
|
-
if (!title) {
|
|
905
|
-
title = '';
|
|
906
|
-
}
|
|
907
|
-
head.innerText = title.toString();
|
|
908
|
-
};
|
|
909
|
-
/**
|
|
910
|
-
* Listen for URL change events
|
|
911
|
-
*
|
|
912
|
-
* @param callback
|
|
913
|
-
*/
|
|
914
|
-
RouterStrategy.prototype.addURLChangeCallback = function (callback) {
|
|
915
|
-
this.on(EVENT_URL_CHANGE, callback);
|
|
916
|
-
};
|
|
917
|
-
/**
|
|
918
|
-
* Removes an existing listener
|
|
919
|
-
*
|
|
920
|
-
* @param callback
|
|
921
|
-
*/
|
|
922
|
-
RouterStrategy.prototype.removeURLChangeCallback = function (callback) {
|
|
923
|
-
this.off(EVENT_URL_CHANGE, callback);
|
|
924
|
-
};
|
|
925
|
-
/**
|
|
926
|
-
* navigate the history forward one entry. This is an alias for [go(1)]{@link go}
|
|
927
|
-
*/
|
|
928
|
-
RouterStrategy.prototype.forward = function () {
|
|
929
|
-
this.go(1);
|
|
930
|
-
};
|
|
931
|
-
/**
|
|
932
|
-
* Navigate the history back one entry. This is an alias for [go(-1)]{@link go}
|
|
933
|
-
*/
|
|
934
|
-
RouterStrategy.prototype.back = function () {
|
|
935
|
-
this.go(-1);
|
|
936
|
-
};
|
|
937
|
-
/**
|
|
938
|
-
* Returns true if can go back 1 entry.
|
|
939
|
-
* This is the same as calling [canGo(-1)]{@link canGo}
|
|
940
|
-
*/
|
|
941
|
-
RouterStrategy.prototype.canBack = function () {
|
|
942
|
-
return this.canGo(-1);
|
|
943
|
-
};
|
|
944
|
-
/**
|
|
945
|
-
* Returns true if can go forward 1 entry.
|
|
946
|
-
* This is the same as calling [canGo(1)]{@link canGo}
|
|
947
|
-
*/
|
|
948
|
-
RouterStrategy.prototype.canForward = function () {
|
|
949
|
-
return this.canGo(1);
|
|
950
|
-
};
|
|
951
|
-
/**
|
|
952
|
-
* Returns the URL one entry forward.
|
|
953
|
-
* This is the same as calling [peek(1)]{@link peek}
|
|
954
|
-
*/
|
|
955
|
-
RouterStrategy.prototype.peekForward = function () {
|
|
956
|
-
return this.peek(1);
|
|
957
|
-
};
|
|
958
|
-
/**
|
|
959
|
-
* Returns the URL one entry back.
|
|
960
|
-
* This is the same as calling [peek(-1)]{@link peek}
|
|
961
|
-
*/
|
|
962
|
-
RouterStrategy.prototype.peekBack = function () {
|
|
963
|
-
return this.peek(-1);
|
|
964
|
-
};
|
|
965
|
-
/**
|
|
966
|
-
* Fires the {@link EVENT_URL_CHANGE} event
|
|
967
|
-
* @param url
|
|
968
|
-
*/
|
|
969
|
-
RouterStrategy.prototype._fireURLChange = function (url) {
|
|
970
|
-
this.emit(EVENT_URL_CHANGE, url);
|
|
971
|
-
};
|
|
972
|
-
return RouterStrategy;
|
|
973
|
-
}(events.EventEmitter));
|
|
974
|
-
|
|
975
|
-
/**
|
|
976
|
-
A {@link RouterStrategy} that manages a history stack using inline pound symbols `#`.
|
|
977
|
-
URLs will have a starting point `/#/`, as a default base.
|
|
978
|
-
|
|
979
|
-
For example, if you [pushState("mylink")]{@link pushState}, the url
|
|
980
|
-
`/#/mylink` will be produced.
|
|
981
|
-
*/
|
|
982
|
-
var HashStrategy = /** @class */ (function (_super) {
|
|
983
|
-
__extends(HashStrategy, _super);
|
|
984
|
-
function HashStrategy(router) {
|
|
985
|
-
var _this = _super.call(this, router) || this;
|
|
986
|
-
_this.$base = '#';
|
|
987
|
-
_this.$stack = [];
|
|
988
|
-
_this.$position = -1;
|
|
989
|
-
_this.$lastFiredLocation = null; //this.getLocation();
|
|
990
|
-
window.addEventListener('popstate', function (ev) {
|
|
991
|
-
var location = _this.getLocation();
|
|
992
|
-
if (_this.$lastFiredLocation !== location) {
|
|
993
|
-
_this._fireURLChange(location);
|
|
994
|
-
}
|
|
995
|
-
});
|
|
996
|
-
window.addEventListener('hashchange', function (e) {
|
|
997
|
-
var location = _this.getLocation();
|
|
998
|
-
if (_this.$lastFiredLocation !== location) {
|
|
999
|
-
_this._fireURLChange(location);
|
|
1000
|
-
}
|
|
1001
|
-
});
|
|
1002
|
-
_this.$init();
|
|
1003
|
-
return _this;
|
|
1004
|
-
}
|
|
1005
|
-
HashStrategy.prototype.$init = function () {
|
|
1006
|
-
this.pushState(this.getLocation());
|
|
1007
|
-
};
|
|
1008
|
-
HashStrategy.prototype.getLocation = function () {
|
|
1009
|
-
return window.location.hash.replace('#', '');
|
|
1010
|
-
};
|
|
1011
|
-
HashStrategy.prototype.getLocationAt = function (position) {
|
|
1012
|
-
return this.$stack[this.$position + position];
|
|
1013
|
-
};
|
|
1014
|
-
HashStrategy.prototype.getHistoryLength = function () {
|
|
1015
|
-
return this.$stack.length;
|
|
1016
|
-
};
|
|
1017
|
-
HashStrategy.prototype.getScrollRestoration = function () {
|
|
1018
|
-
return window.history.scrollRestoration;
|
|
1019
|
-
};
|
|
1020
|
-
HashStrategy.prototype.canGo = function (to) {
|
|
1021
|
-
return this.$stack[this.$position + to] !== undefined;
|
|
1022
|
-
};
|
|
1023
|
-
HashStrategy.prototype.peek = function (to) {
|
|
1024
|
-
return this.$stack[this.$position + to];
|
|
1025
|
-
};
|
|
1026
|
-
HashStrategy.prototype.go = function (to) {
|
|
1027
|
-
if (!this.canGo(to)) {
|
|
1028
|
-
return;
|
|
1029
|
-
}
|
|
1030
|
-
this.$position += to;
|
|
1031
|
-
var url = this.$stack[this.$position];
|
|
1032
|
-
this.$navigate(url);
|
|
1033
|
-
};
|
|
1034
|
-
HashStrategy.prototype.pushState = function (url, state) {
|
|
1035
|
-
if (url === this.getLocation()) {
|
|
1036
|
-
//We are already here, so do nothing.
|
|
1037
|
-
return;
|
|
1038
|
-
}
|
|
1039
|
-
if (this.$stack.length === 0) {
|
|
1040
|
-
this.$stack[++this.$position] = this.getLocation();
|
|
1041
|
-
}
|
|
1042
|
-
this.$stack[++this.$position] = url;
|
|
1043
|
-
//clear everything after position.
|
|
1044
|
-
this.$stack = this.$stack.slice(0, this.$position + 1);
|
|
1045
|
-
this.$navigate(url);
|
|
1046
|
-
};
|
|
1047
|
-
HashStrategy.prototype.replaceState = function (url, state) {
|
|
1048
|
-
if (url === this.getLocation()) {
|
|
1049
|
-
//We are already here, so do nothing.
|
|
1050
|
-
return;
|
|
1051
|
-
}
|
|
1052
|
-
if (this.$position === -1) {
|
|
1053
|
-
this.pushState(url, state);
|
|
1054
|
-
}
|
|
1055
|
-
else {
|
|
1056
|
-
this.$stack[this.$position] = url;
|
|
1057
|
-
this.$navigate(url);
|
|
1058
|
-
}
|
|
1059
|
-
};
|
|
1060
|
-
HashStrategy.prototype.clear = function () {
|
|
1061
|
-
this.$stack = [];
|
|
1062
|
-
this.$position = -1;
|
|
1063
|
-
};
|
|
1064
|
-
HashStrategy.prototype.$navigate = function (url) {
|
|
1065
|
-
window.location.hash = this.$base + url;
|
|
1066
|
-
this._fireURLChange(this.getLocation());
|
|
1067
|
-
};
|
|
1068
|
-
HashStrategy.prototype._fireURLChange = function (url) {
|
|
1069
|
-
this.$lastFiredLocation = url;
|
|
1070
|
-
_super.prototype._fireURLChange.call(this, url);
|
|
1071
|
-
};
|
|
1072
|
-
return HashStrategy;
|
|
1073
|
-
}(RouterStrategy));
|
|
1074
|
-
|
|
1075
|
-
/**
|
|
1076
|
-
Alias for {@link HashStrategy}
|
|
1077
|
-
*/
|
|
1078
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1079
|
-
var DefaultStrategy = HashStrategy;
|
|
1080
|
-
|
|
1081
|
-
/**
|
|
1082
|
-
* Parses the URL for router paths and url-based variables.
|
|
1083
|
-
*/
|
|
1084
|
-
var URLParser = /** @class */ (function () {
|
|
1085
|
-
/**
|
|
1086
|
-
*
|
|
1087
|
-
* @param {string} pattern The URL pattern
|
|
1088
|
-
* @param {boolean} allowPartialMatch If true, the pattern will match again urls that contains the pattern,
|
|
1089
|
-
* even if it isn't an exact match.
|
|
1090
|
-
* Defaults to false.
|
|
1091
|
-
*/
|
|
1092
|
-
function URLParser(pattern, allowPartialMatch) {
|
|
1093
|
-
if (allowPartialMatch === void 0) { allowPartialMatch = false; }
|
|
1094
|
-
this.$allowPartialMatch = allowPartialMatch;
|
|
1095
|
-
this.$pattern = this.$stripURL(pattern);
|
|
1096
|
-
}
|
|
1097
|
-
/**
|
|
1098
|
-
* Parses the URL and returns the url parameters.
|
|
1099
|
-
* Returns null the url does not match the pattern
|
|
1100
|
-
*
|
|
1101
|
-
* @param {string} url The url to test
|
|
1102
|
-
*/
|
|
1103
|
-
URLParser.prototype.parse = function (url) {
|
|
1104
|
-
url = this.$stripURL(url);
|
|
1105
|
-
var parts = this.$getParts(url);
|
|
1106
|
-
var patternParts = this.$getParts(this.$pattern);
|
|
1107
|
-
if ((!this.$allowPartialMatch && parts.length !== patternParts.length) || url === '') {
|
|
1108
|
-
return null;
|
|
1109
|
-
}
|
|
1110
|
-
var params = {};
|
|
1111
|
-
for (var i = 0; i < patternParts.length; i++) {
|
|
1112
|
-
var pPart = patternParts[i];
|
|
1113
|
-
var uPart = parts[i];
|
|
1114
|
-
if (uPart) {
|
|
1115
|
-
if (pPart.charAt(0) === ':') {
|
|
1116
|
-
params[pPart.slice(1)] = uPart;
|
|
1117
|
-
}
|
|
1118
|
-
else {
|
|
1119
|
-
if (pPart !== uPart) {
|
|
1120
|
-
return null;
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
else {
|
|
1125
|
-
break;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
return params;
|
|
1129
|
-
};
|
|
1130
|
-
/**
|
|
1131
|
-
* Strips the url for parsing, removing leading and trailing forward slashes.
|
|
1132
|
-
*
|
|
1133
|
-
* @private
|
|
1134
|
-
* @param {string} url URL to strip
|
|
1135
|
-
*/
|
|
1136
|
-
URLParser.prototype.$stripURL = function (url) {
|
|
1137
|
-
while (url.charAt(0) === '/') {
|
|
1138
|
-
url = url.slice(1);
|
|
1139
|
-
}
|
|
1140
|
-
while (url.charAt(url.length - 1) === '/') {
|
|
1141
|
-
url = url.slice(0, url.length - 1);
|
|
1142
|
-
}
|
|
1143
|
-
return url;
|
|
1144
|
-
};
|
|
1145
|
-
/**
|
|
1146
|
-
* Splits the url into an array of URL parts, separated by the forward slash
|
|
1147
|
-
*
|
|
1148
|
-
* @private
|
|
1149
|
-
* @param {string} url URL to split
|
|
1150
|
-
*/
|
|
1151
|
-
URLParser.prototype.$getParts = function (url) {
|
|
1152
|
-
url = this.$stripURL(url);
|
|
1153
|
-
return url.split('/');
|
|
1154
|
-
};
|
|
1155
|
-
return URLParser;
|
|
1156
|
-
}());
|
|
1157
|
-
|
|
1158
|
-
/**
|
|
1159
|
-
* This class is reponsible for determing which route to render
|
|
1160
|
-
* based on the URL and the route url patterns.
|
|
1161
|
-
*/
|
|
1162
|
-
var RouteMatcher = /** @class */ (function () {
|
|
1163
|
-
function RouteMatcher(routerStrategy) {
|
|
1164
|
-
this.$strategy = routerStrategy;
|
|
1165
|
-
}
|
|
1166
|
-
RouteMatcher.prototype.$defaultNoRouteFunction = function (indexRoute, routes) {
|
|
1167
|
-
return indexRoute;
|
|
1168
|
-
};
|
|
1169
|
-
/**
|
|
1170
|
-
* Matches the url to the appropriate renderable route
|
|
1171
|
-
*
|
|
1172
|
-
* @param url
|
|
1173
|
-
* @param children
|
|
1174
|
-
* @param base
|
|
1175
|
-
* @param indexRoute
|
|
1176
|
-
* @param onNoRoute
|
|
1177
|
-
*/
|
|
1178
|
-
RouteMatcher.prototype.match = function (url, children, base, indexRoute, onNoRoute) {
|
|
1179
|
-
var componentToRender = null;
|
|
1180
|
-
var params = null;
|
|
1181
|
-
for (var i = 0; i < children.length; i++) {
|
|
1182
|
-
var route = children[i];
|
|
1183
|
-
var shouldAllowPartialMatching = !!route.props.children;
|
|
1184
|
-
var parser = new URLParser(base + route.props.url, shouldAllowPartialMatching);
|
|
1185
|
-
params = parser.parse(url);
|
|
1186
|
-
if (params) {
|
|
1187
|
-
componentToRender = route;
|
|
1188
|
-
break;
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
if (!componentToRender) {
|
|
1192
|
-
componentToRender = (onNoRoute ? onNoRoute : this.$defaultNoRouteFunction)(indexRoute, children);
|
|
1193
|
-
}
|
|
1194
|
-
if (!componentToRender) {
|
|
1195
|
-
if (!base) {
|
|
1196
|
-
console.warn('No routes matched, and no index route available.');
|
|
1197
|
-
}
|
|
1198
|
-
return null;
|
|
1199
|
-
}
|
|
1200
|
-
var props = {
|
|
1201
|
-
url: url,
|
|
1202
|
-
base: base + componentToRender.props.url,
|
|
1203
|
-
matcher: this,
|
|
1204
|
-
component: componentToRender.props.component,
|
|
1205
|
-
entryTransition: componentToRender.props.entryTransition,
|
|
1206
|
-
exitTransition: componentToRender.props.exitTransition,
|
|
1207
|
-
componentProps: {
|
|
1208
|
-
url: url,
|
|
1209
|
-
router: this.$strategy
|
|
1210
|
-
}
|
|
1211
|
-
};
|
|
1212
|
-
if (params) {
|
|
1213
|
-
for (var i in params) {
|
|
1214
|
-
props.componentProps[i] = params[i];
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
return React.cloneElement(componentToRender, props);
|
|
1218
|
-
};
|
|
1219
|
-
return RouteMatcher;
|
|
1220
|
-
}());
|
|
1221
|
-
|
|
1222
|
-
var Router = /** @class */ (function (_super) {
|
|
1223
|
-
__extends(Router, _super);
|
|
1224
|
-
function Router(props) {
|
|
1225
|
-
var _this = _super.call(this, props) || this;
|
|
1226
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1227
|
-
var Strategy;
|
|
1228
|
-
if (!props.strategy) {
|
|
1229
|
-
Strategy = DefaultStrategy;
|
|
1230
|
-
}
|
|
1231
|
-
else {
|
|
1232
|
-
Strategy = props.strategy;
|
|
1233
|
-
}
|
|
1234
|
-
var strategy = new Strategy(_this);
|
|
1235
|
-
_this.state = {
|
|
1236
|
-
strategy: strategy,
|
|
1237
|
-
url: strategy.getLocation(),
|
|
1238
|
-
shouldTransition: false
|
|
1239
|
-
};
|
|
1240
|
-
_this.$lastRenderedRoute = null;
|
|
1241
|
-
_this.$onURLChange = _this.$onURLChange.bind(_this);
|
|
1242
|
-
_this.$matcher = new RouteMatcher(strategy);
|
|
1243
|
-
return _this;
|
|
1244
|
-
}
|
|
1245
|
-
Router.getInstance = function () {
|
|
1246
|
-
if (!Router.$instance) {
|
|
1247
|
-
return null;
|
|
1248
|
-
}
|
|
1249
|
-
return Router.$instance.getRouterStrategy();
|
|
1250
|
-
};
|
|
1251
|
-
/**
|
|
1252
|
-
* Gets the current routing strategy
|
|
1253
|
-
*/
|
|
1254
|
-
Router.prototype.getRouterStrategy = function () {
|
|
1255
|
-
return this.state.strategy;
|
|
1256
|
-
};
|
|
1257
|
-
/**
|
|
1258
|
-
* @ignore
|
|
1259
|
-
*/
|
|
1260
|
-
Router.prototype.$onURLChange = function (url) {
|
|
1261
|
-
if (url !== this.state.url) {
|
|
1262
|
-
this.setState({
|
|
1263
|
-
url: url,
|
|
1264
|
-
shouldTransition: true
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
};
|
|
1268
|
-
Router.prototype.componentDidMount = function () {
|
|
1269
|
-
Router.$instance = this;
|
|
1270
|
-
this.state.strategy.addURLChangeCallback(this.$onURLChange);
|
|
1271
|
-
};
|
|
1272
|
-
/**
|
|
1273
|
-
* @ignore
|
|
1274
|
-
*/
|
|
1275
|
-
Router.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
|
|
1276
|
-
if (nextProps.strategy && (this.state.strategy instanceof nextProps.strategy)) {
|
|
1277
|
-
this.state.strategy.removeURLChangeCallback(this.$onURLChange);
|
|
1278
|
-
var strat = new nextProps.strategy(this);
|
|
1279
|
-
strat.addURLChangeCallback(this.$onURLChange);
|
|
1280
|
-
this.setState({
|
|
1281
|
-
strategy: strat
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
|
-
};
|
|
1285
|
-
/**
|
|
1286
|
-
* @ignore
|
|
1287
|
-
*/
|
|
1288
|
-
Router.prototype.componentWillUnmount = function () {
|
|
1289
|
-
Router.$instance = null;
|
|
1290
|
-
this.state.strategy.removeURLChangeCallback(this.$onURLChange);
|
|
1291
|
-
};
|
|
1292
|
-
/**
|
|
1293
|
-
* @ignore
|
|
1294
|
-
*/
|
|
1295
|
-
Router.prototype.render = function () {
|
|
1296
|
-
var _this = this;
|
|
1297
|
-
var currentRoute = this.$matcher.match(this.state.url || '/', this.$getChildren(), '', this.$getIndexRoute(), this.props.onNoRoute);
|
|
1298
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1299
|
-
var Root = null;
|
|
1300
|
-
if (this.props.component) {
|
|
1301
|
-
Root = this.props.component;
|
|
1302
|
-
}
|
|
1303
|
-
if (this.state.shouldTransition && (currentRoute.props.entryTransition || (this.$lastRenderedRoute &&
|
|
1304
|
-
this.$lastRenderedRoute.props.exitTransition))) {
|
|
1305
|
-
this.$awaitingTransition = true;
|
|
1306
|
-
var exiting = null;
|
|
1307
|
-
if (this.$lastRenderedRoute) {
|
|
1308
|
-
exiting = React__namespace.cloneElement(this.$lastRenderedRoute, {
|
|
1309
|
-
ref: function (route) {
|
|
1310
|
-
_this.$exitingRoute = route;
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
// Incoming will always be safe to render, hence no defensive checks
|
|
1315
|
-
var incoming = React__namespace.cloneElement(currentRoute, {
|
|
1316
|
-
ref: function (route) {
|
|
1317
|
-
_this.$incomingRoute = route;
|
|
1318
|
-
}
|
|
1319
|
-
});
|
|
1320
|
-
if (Root) {
|
|
1321
|
-
return React__namespace.createElement(Root, { router: this.getRouterStrategy(), url: this.state.url }, [exiting, incoming]);
|
|
1322
|
-
}
|
|
1323
|
-
else {
|
|
1324
|
-
return [exiting, incoming];
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
else {
|
|
1328
|
-
this.$lastRenderedRoute = currentRoute;
|
|
1329
|
-
if (Root) {
|
|
1330
|
-
// currentRoute must be rendered as an array; because, exiting and incoming is rendered as an array.
|
|
1331
|
-
// if currentRoute is not rendered as an array, a bug happens where the exiting screen is reloaded
|
|
1332
|
-
// calling the constructor again.
|
|
1333
|
-
return React__namespace.createElement(Root, { router: this.getRouterStrategy(), url: this.state.url }, [currentRoute]);
|
|
1334
|
-
}
|
|
1335
|
-
else {
|
|
1336
|
-
return currentRoute;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
};
|
|
1340
|
-
/**
|
|
1341
|
-
* @ignore
|
|
1342
|
-
*/
|
|
1343
|
-
Router.prototype.componentDidUpdate = function () {
|
|
1344
|
-
var _this = this;
|
|
1345
|
-
if (this.$awaitingTransition) {
|
|
1346
|
-
this.$awaitingTransition = false;
|
|
1347
|
-
var exitTransitionPromise = null;
|
|
1348
|
-
if (this.$exitingRoute && this.$exitingRoute.props.exitTransition) {
|
|
1349
|
-
exitTransitionPromise = this.$exitingRoute.props.exitTransition.execute(this.$incomingRoute.getView(), this.$exitingRoute.getView());
|
|
1350
|
-
}
|
|
1351
|
-
else {
|
|
1352
|
-
exitTransitionPromise = Promise.resolve();
|
|
1353
|
-
}
|
|
1354
|
-
exitTransitionPromise.then(function () {
|
|
1355
|
-
var entryTransitionPromise = null;
|
|
1356
|
-
if (_this.$incomingRoute.props.entryTransition) {
|
|
1357
|
-
entryTransitionPromise = _this.$incomingRoute.props.entryTransition.execute(_this.$incomingRoute.getView(), _this.$exitingRoute.getView());
|
|
1358
|
-
}
|
|
1359
|
-
else {
|
|
1360
|
-
entryTransitionPromise = Promise.resolve();
|
|
1361
|
-
}
|
|
1362
|
-
return entryTransitionPromise;
|
|
1363
|
-
})["catch"](function (error) {
|
|
1364
|
-
console.error(error);
|
|
1365
|
-
}).then(function () {
|
|
1366
|
-
_this.$incomingRoute = null;
|
|
1367
|
-
_this.$exitingRoute = null;
|
|
1368
|
-
_this.setState({ shouldTransition: false });
|
|
1369
|
-
});
|
|
1370
|
-
}
|
|
1371
|
-
};
|
|
1372
|
-
/**
|
|
1373
|
-
* Gets the number of history entries. Note this does not count the browser history.
|
|
1374
|
-
* Only the history kept track during the life-cycle of the app.
|
|
1375
|
-
*/
|
|
1376
|
-
Router.prototype.getHistoryLength = function () {
|
|
1377
|
-
return this.state.strategy.getHistoryLength();
|
|
1378
|
-
};
|
|
1379
|
-
/**
|
|
1380
|
-
* Gets the scroll restoration mode
|
|
1381
|
-
*/
|
|
1382
|
-
Router.prototype.getScrollRestoration = function () {
|
|
1383
|
-
return this.state.strategy.getScrollRestoration();
|
|
1384
|
-
};
|
|
1385
|
-
/**
|
|
1386
|
-
*
|
|
1387
|
-
* @param to An integer, positive means go forward, negative means go backwards. E.g:
|
|
1388
|
-
* `1` move forward one step
|
|
1389
|
-
* `-1` move backward one step
|
|
1390
|
-
* `0` navigate to the current page (This is essentially a no-op)
|
|
1391
|
-
*/
|
|
1392
|
-
Router.prototype.go = function (to) {
|
|
1393
|
-
this.state.strategy.go(to);
|
|
1394
|
-
};
|
|
1395
|
-
/**
|
|
1396
|
-
* Go back one step. This is an alias for [pushState(-1)]{@link go}.
|
|
1397
|
-
*/
|
|
1398
|
-
Router.prototype.back = function () {
|
|
1399
|
-
this.state.strategy.go(-1);
|
|
1400
|
-
};
|
|
1401
|
-
/**
|
|
1402
|
-
* Go forward one step. This is an alias for [pushState(1)]{@link go}.
|
|
1403
|
-
*/
|
|
1404
|
-
Router.prototype.forward = function () {
|
|
1405
|
-
this.state.strategy.go(1);
|
|
1406
|
-
};
|
|
1407
|
-
/**
|
|
1408
|
-
* Gets the potential routes
|
|
1409
|
-
*/
|
|
1410
|
-
Router.prototype.$getChildren = function () {
|
|
1411
|
-
var children = null;
|
|
1412
|
-
if (this.props.children instanceof Array) {
|
|
1413
|
-
children = this.props.children;
|
|
1414
|
-
}
|
|
1415
|
-
else {
|
|
1416
|
-
children = [this.props.children];
|
|
1417
|
-
}
|
|
1418
|
-
return children;
|
|
1419
|
-
};
|
|
1420
|
-
/**
|
|
1421
|
-
* Finds the index route. Returns null if there are no indexed routes.
|
|
1422
|
-
*/
|
|
1423
|
-
Router.prototype.$getIndexRoute = function () {
|
|
1424
|
-
var children = this.$getChildren();
|
|
1425
|
-
for (var i = 0; i < children.length; i++) {
|
|
1426
|
-
var child = children[i];
|
|
1427
|
-
if (child.props.index) {
|
|
1428
|
-
return child;
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
return null;
|
|
1432
|
-
};
|
|
1433
|
-
return Router;
|
|
1434
|
-
}(React__namespace.Component));
|
|
1435
|
-
var getRouter = function () {
|
|
1436
|
-
console.warn('getRouter() is deprecated. use Router.getInstance() instead.');
|
|
1437
|
-
return Router.getInstance();
|
|
749
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
750
|
+
var e = new Error(message);
|
|
751
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1438
752
|
};
|
|
1439
753
|
|
|
1440
|
-
/**
|
|
1441
|
-
* @notice Using the URLStrategy requires some backend configuration
|
|
1442
|
-
* to route URLs back to application.
|
|
1443
|
-
*
|
|
1444
|
-
* To make this easier, by default these URLs are prefixed with
|
|
1445
|
-
* `/r/` to easily differentiate between URLs that needs to be re-routed back
|
|
1446
|
-
* to the application vs other resources such as images.
|
|
1447
|
-
*/
|
|
1448
|
-
var URLStrategy = /** @class */ (function (_super) {
|
|
1449
|
-
__extends(URLStrategy, _super);
|
|
1450
|
-
/**
|
|
1451
|
-
*
|
|
1452
|
-
* @param {Router} router
|
|
1453
|
-
*/
|
|
1454
|
-
function URLStrategy(router) {
|
|
1455
|
-
var _this = _super.call(this, router) || this;
|
|
1456
|
-
_this.$base = window.location.origin + '/r';
|
|
1457
|
-
_this.$stack = [];
|
|
1458
|
-
_this.$position = -1;
|
|
1459
|
-
window.addEventListener('popstate', function () {
|
|
1460
|
-
_this._fireURLChange(_this.getLocation());
|
|
1461
|
-
});
|
|
1462
|
-
_this.$init();
|
|
1463
|
-
return _this;
|
|
1464
|
-
}
|
|
1465
|
-
URLStrategy.prototype.$init = function () {
|
|
1466
|
-
this.pushState(this.getLocation());
|
|
1467
|
-
};
|
|
1468
|
-
URLStrategy.prototype.getLocation = function () {
|
|
1469
|
-
return window.location.pathname.replace('/r', '');
|
|
1470
|
-
};
|
|
1471
|
-
URLStrategy.prototype.getLocationAt = function (position) {
|
|
1472
|
-
return this.$stack[this.$position + position];
|
|
1473
|
-
};
|
|
1474
|
-
URLStrategy.prototype.getHistoryLength = function () {
|
|
1475
|
-
return window.history.length;
|
|
1476
|
-
};
|
|
1477
|
-
URLStrategy.prototype.getScrollRestoration = function () {
|
|
1478
|
-
return window.history.scrollRestoration;
|
|
1479
|
-
};
|
|
1480
|
-
URLStrategy.prototype.peek = function (to) {
|
|
1481
|
-
return this.$stack[this.$position + to];
|
|
1482
|
-
};
|
|
1483
|
-
URLStrategy.prototype.canGo = function (to) {
|
|
1484
|
-
return this.$stack[this.$position + to] !== undefined;
|
|
1485
|
-
};
|
|
1486
|
-
URLStrategy.prototype.go = function (to) {
|
|
1487
|
-
if (!this.canGo(to)) {
|
|
1488
|
-
return;
|
|
1489
|
-
}
|
|
1490
|
-
this.$position += to;
|
|
1491
|
-
this.$navigate(this.$stack[this.$position]);
|
|
1492
|
-
};
|
|
1493
|
-
URLStrategy.prototype.pushState = function (url, state) {
|
|
1494
|
-
if (state) {
|
|
1495
|
-
console.warn('Warning: The state parameter is not implemented yet.');
|
|
1496
|
-
}
|
|
1497
|
-
if (url === this.getLocation()) {
|
|
1498
|
-
//We are already here, so do nothing.
|
|
1499
|
-
return;
|
|
1500
|
-
}
|
|
1501
|
-
this.$stack[++this.$position] = url;
|
|
1502
|
-
//clear everything after position.
|
|
1503
|
-
this.$stack = this.$stack.slice(0, this.$position + 1);
|
|
1504
|
-
this.$navigate(url);
|
|
1505
|
-
};
|
|
1506
|
-
URLStrategy.prototype.replaceState = function (url, state) {
|
|
1507
|
-
if (state) {
|
|
1508
|
-
console.warn('Warning: The state parameter is not implemented yet.');
|
|
1509
|
-
}
|
|
1510
|
-
if (url === this.getLocation()) {
|
|
1511
|
-
//We are already here, so do nothing.
|
|
1512
|
-
return;
|
|
1513
|
-
}
|
|
1514
|
-
if (this.$position === -1) {
|
|
1515
|
-
this.pushState(url, state);
|
|
1516
|
-
}
|
|
1517
|
-
else {
|
|
1518
|
-
this.$stack[this.$position] = url;
|
|
1519
|
-
this.$navigate(url);
|
|
1520
|
-
}
|
|
1521
|
-
};
|
|
1522
|
-
URLStrategy.prototype.clear = function () {
|
|
1523
|
-
this.$stack = [];
|
|
1524
|
-
this.$position = -1;
|
|
1525
|
-
};
|
|
1526
|
-
URLStrategy.prototype.$navigate = function (url, replace) {
|
|
1527
|
-
if (replace === void 0) { replace = false; }
|
|
1528
|
-
if (replace) {
|
|
1529
|
-
window.history.replaceState({}, null, this.$base + url);
|
|
1530
|
-
}
|
|
1531
|
-
else {
|
|
1532
|
-
window.history.pushState({}, null, this.$base + url);
|
|
1533
|
-
}
|
|
1534
|
-
this._fireURLChange(this.getLocation());
|
|
1535
|
-
};
|
|
1536
|
-
return URLStrategy;
|
|
1537
|
-
}(RouterStrategy));
|
|
1538
|
-
|
|
1539
754
|
___$insertStyle(".View {\n position: static;\n top: 0px;\n left: 0px;\n width: 100%;\n height: 100%;\n z-index: 1;\n}");
|
|
1540
755
|
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
if (stylesheet) {
|
|
1582
|
-
stylesheet.unuse();
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
*
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
};
|
|
1613
|
-
return View;
|
|
1614
|
-
}(React__namespace.Component));
|
|
756
|
+
class View extends React__namespace.Component {
|
|
757
|
+
/**
|
|
758
|
+
* @param props See [IViewProps]
|
|
759
|
+
*/
|
|
760
|
+
constructor(props) {
|
|
761
|
+
super(props);
|
|
762
|
+
this.$node = null;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Return the CSS class on this view
|
|
766
|
+
*/
|
|
767
|
+
getCSSClass() {
|
|
768
|
+
return '';
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Override to return a webpack API style stylesheet
|
|
772
|
+
*/
|
|
773
|
+
getViewStylesheet() {
|
|
774
|
+
return null;
|
|
775
|
+
}
|
|
776
|
+
_getViewBodyClass() {
|
|
777
|
+
return this.constructor.name;
|
|
778
|
+
}
|
|
779
|
+
componentDidMount() {
|
|
780
|
+
this.getTitle().then((title) => {
|
|
781
|
+
this.props.router.setTitle(title);
|
|
782
|
+
});
|
|
783
|
+
document.body.classList.add(this.$getViewBodyClass());
|
|
784
|
+
let stylesheet = this.getViewStylesheet();
|
|
785
|
+
if (stylesheet) {
|
|
786
|
+
stylesheet.use();
|
|
787
|
+
}
|
|
788
|
+
this.props.router.__onViewMount(this);
|
|
789
|
+
}
|
|
790
|
+
$getViewBodyClass() {
|
|
791
|
+
return `${this._getViewBodyClass()}-body`;
|
|
792
|
+
}
|
|
793
|
+
componentWillUnmount() {
|
|
794
|
+
document.body.classList.remove(this.$getViewBodyClass());
|
|
795
|
+
let stylesheet = this.getViewStylesheet();
|
|
796
|
+
if (stylesheet) {
|
|
797
|
+
stylesheet.unuse();
|
|
798
|
+
}
|
|
799
|
+
this.props.router.__onViewUnmount(this);
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Gets the underlying HTML node for this View
|
|
803
|
+
*/
|
|
804
|
+
getNode() {
|
|
805
|
+
return this.$node;
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Get the title of this view
|
|
809
|
+
*/
|
|
810
|
+
getTitle() {
|
|
811
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
812
|
+
return null;
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Get the inline styles for this view.
|
|
817
|
+
* Use React style notation.
|
|
818
|
+
*/
|
|
819
|
+
getViewStyles() {
|
|
820
|
+
return {};
|
|
821
|
+
}
|
|
822
|
+
render() {
|
|
823
|
+
let cssClass = this.getCSSClass();
|
|
824
|
+
return (React__namespace.createElement("div", { className: `View${cssClass ? ' ' + cssClass : ''}`, ref: (n) => { this.$node = n; }, style: this.getViewStyles() }, this._renderView()));
|
|
825
|
+
}
|
|
826
|
+
}
|
|
1615
827
|
|
|
1616
|
-
/**
|
|
1617
|
-
* This class represents a route that renders a {@link View} component
|
|
1618
|
-
*/
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
if (!component) {
|
|
1660
|
-
|
|
1661
|
-
}
|
|
1662
|
-
if (
|
|
1663
|
-
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
children = component.props.children;
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
return children;
|
|
1672
|
-
};
|
|
1673
|
-
return Route;
|
|
1674
|
-
}(React__namespace.Component));
|
|
828
|
+
/**
|
|
829
|
+
* This class represents a route that renders a {@link View} component
|
|
830
|
+
*/
|
|
831
|
+
class Route extends React__namespace.Component {
|
|
832
|
+
constructor(props) {
|
|
833
|
+
super(props);
|
|
834
|
+
this.render;
|
|
835
|
+
}
|
|
836
|
+
render() {
|
|
837
|
+
return this.$getComponentsToRender(this);
|
|
838
|
+
}
|
|
839
|
+
getView() {
|
|
840
|
+
return this.$node;
|
|
841
|
+
}
|
|
842
|
+
$getComponentsToRender(component) {
|
|
843
|
+
let url = component.props.url;
|
|
844
|
+
let base = component.props.base || '';
|
|
845
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
846
|
+
let ViewComponent = component.props.component;
|
|
847
|
+
let child;
|
|
848
|
+
let routeComponent = component.props.matcher.match(url, this.$getChildren(component), base);
|
|
849
|
+
if (routeComponent) {
|
|
850
|
+
child = this.$getComponentsToRender(routeComponent);
|
|
851
|
+
}
|
|
852
|
+
return (React__namespace.createElement(ViewComponent, Object.assign({}, component.props.componentProps, { ref: (node) => {
|
|
853
|
+
if (node) {
|
|
854
|
+
if (node instanceof View) {
|
|
855
|
+
this.$node = node;
|
|
856
|
+
}
|
|
857
|
+
else {
|
|
858
|
+
throw new Error('Routed components should be a View, but got ' + Object.getPrototypeOf(node).constructor.name + ' instead.');
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
else {
|
|
862
|
+
this.$node = null;
|
|
863
|
+
}
|
|
864
|
+
} }), child));
|
|
865
|
+
}
|
|
866
|
+
$getChildren(component) {
|
|
867
|
+
let children = null;
|
|
868
|
+
if (!component) {
|
|
869
|
+
component = this;
|
|
870
|
+
}
|
|
871
|
+
if (!component.props.children) {
|
|
872
|
+
return [];
|
|
873
|
+
}
|
|
874
|
+
if (component.props.children instanceof Array) {
|
|
875
|
+
children = component.props.children;
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
878
|
+
children = [component.props.children];
|
|
879
|
+
}
|
|
880
|
+
return children;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
1675
883
|
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
*
|
|
1681
|
-
*
|
|
1682
|
-
*
|
|
1683
|
-
*
|
|
1684
|
-
* The `
|
|
1685
|
-
*
|
|
1686
|
-
*
|
|
1687
|
-
*
|
|
1688
|
-
*
|
|
1689
|
-
*
|
|
1690
|
-
*
|
|
1691
|
-
* @param {View}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
case 1:
|
|
1700
|
-
_a.sent();
|
|
1701
|
-
return [2 /*return*/];
|
|
1702
|
-
}
|
|
1703
|
-
});
|
|
1704
|
-
});
|
|
1705
|
-
};
|
|
1706
|
-
return TransitionStrategy;
|
|
1707
|
-
}());
|
|
884
|
+
class TransitionStrategy {
|
|
885
|
+
constructor() { }
|
|
886
|
+
/**
|
|
887
|
+
* Invoked when the transition should begin.
|
|
888
|
+
* The promise should only resolve once the transition
|
|
889
|
+
* has ran to completion.
|
|
890
|
+
*
|
|
891
|
+
* The `incomingView` is the view that the user is navigating to.
|
|
892
|
+
* The `exitingView` is te view that the user is currently on, and is leaving.
|
|
893
|
+
*
|
|
894
|
+
* Both views will be rendered and are free to be manipulated in anyway that is desired,
|
|
895
|
+
* however, the incomingView should be positioned in it's natural position by the end
|
|
896
|
+
* of the transition to avoid "snapping" behaviour.
|
|
897
|
+
*
|
|
898
|
+
* @param {View} incomingView
|
|
899
|
+
* @param {View} exitingView
|
|
900
|
+
*/
|
|
901
|
+
execute(incomingView, exitingView) {
|
|
902
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
903
|
+
yield this._execute(incomingView, exitingView);
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
}
|
|
1708
907
|
|
|
1709
|
-
exports.TransitionSlideDirection = void 0;
|
|
1710
|
-
(function (TransitionSlideDirection) {
|
|
1711
|
-
TransitionSlideDirection[TransitionSlideDirection["LEFT"] = 1] = "LEFT";
|
|
1712
|
-
TransitionSlideDirection[TransitionSlideDirection["RIGHT"] = 2] = "RIGHT";
|
|
1713
|
-
TransitionSlideDirection[TransitionSlideDirection["UP"] = 3] = "UP";
|
|
1714
|
-
TransitionSlideDirection[TransitionSlideDirection["DOWN"] = 4] = "DOWN";
|
|
1715
|
-
})(exports.TransitionSlideDirection || (exports.TransitionSlideDirection = {}));
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
incomingNode.style.
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
exitingNode.style.
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
incomingNode.
|
|
1764
|
-
incomingNode.style.
|
|
1765
|
-
incomingNode.style.
|
|
1766
|
-
incomingNode.style.
|
|
1767
|
-
incomingNode.style.
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
exitingNode.style.
|
|
1772
|
-
exitingNode.style.
|
|
1773
|
-
exitingNode.style.
|
|
1774
|
-
exitingNode.style.
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
case exports.TransitionSlideDirection.
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
return
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
return 'ease-in-out';
|
|
1822
|
-
};
|
|
1823
|
-
return TransitionSlide;
|
|
1824
|
-
}(TransitionStrategy));
|
|
908
|
+
exports.TransitionSlideDirection = void 0;
|
|
909
|
+
(function (TransitionSlideDirection) {
|
|
910
|
+
TransitionSlideDirection[TransitionSlideDirection["LEFT"] = 1] = "LEFT";
|
|
911
|
+
TransitionSlideDirection[TransitionSlideDirection["RIGHT"] = 2] = "RIGHT";
|
|
912
|
+
TransitionSlideDirection[TransitionSlideDirection["UP"] = 3] = "UP";
|
|
913
|
+
TransitionSlideDirection[TransitionSlideDirection["DOWN"] = 4] = "DOWN";
|
|
914
|
+
})(exports.TransitionSlideDirection || (exports.TransitionSlideDirection = {}));
|
|
915
|
+
class TransitionSlide extends TransitionStrategy {
|
|
916
|
+
constructor(slideDirection, slideSpeed) {
|
|
917
|
+
super();
|
|
918
|
+
this.$slideDirection = slideDirection || exports.TransitionSlideDirection.LEFT;
|
|
919
|
+
this.$slideSpeed = slideSpeed || 0.25;
|
|
920
|
+
}
|
|
921
|
+
_execute(incoming, exiting) {
|
|
922
|
+
return new Promise((resolve, reject) => {
|
|
923
|
+
let incomingNode = incoming.getNode();
|
|
924
|
+
let exitingNode = exiting.getNode();
|
|
925
|
+
//First set initial transition CSS
|
|
926
|
+
incomingNode.style.willChange = 'transform';
|
|
927
|
+
incomingNode.style.transform = 'translate3d(0,0,0)';
|
|
928
|
+
incomingNode.style.pointerEvents = 'none';
|
|
929
|
+
incomingNode.style.zIndex = '1';
|
|
930
|
+
exitingNode.style.willChange = 'transform';
|
|
931
|
+
exitingNode.style.transform = 'translate3d(0,0,0)';
|
|
932
|
+
exitingNode.style.pointerEvents = 'none';
|
|
933
|
+
exitingNode.style.zIndex = '2';
|
|
934
|
+
switch (this.$slideDirection) {
|
|
935
|
+
case exports.TransitionSlideDirection.LEFT:
|
|
936
|
+
incomingNode.style.left = '100%';
|
|
937
|
+
exitingNode.style.left = '0%';
|
|
938
|
+
break;
|
|
939
|
+
case exports.TransitionSlideDirection.RIGHT:
|
|
940
|
+
incomingNode.style.left = '-100%';
|
|
941
|
+
exitingNode.style.left = '0%';
|
|
942
|
+
break;
|
|
943
|
+
case exports.TransitionSlideDirection.UP:
|
|
944
|
+
incomingNode.style.top = '100%';
|
|
945
|
+
exitingNode.style.top = '0%';
|
|
946
|
+
break;
|
|
947
|
+
case exports.TransitionSlideDirection.DOWN:
|
|
948
|
+
incomingNode.style.top = '-100%';
|
|
949
|
+
exitingNode.style.top = '0%';
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
//Set the appropriate transition string
|
|
953
|
+
let transitionString = this.$getTransitionString(this.$slideDirection);
|
|
954
|
+
incomingNode.style.transition = transitionString;
|
|
955
|
+
exitingNode.style.transition = transitionString;
|
|
956
|
+
//Add transition listener
|
|
957
|
+
let onTransitionEnd = () => {
|
|
958
|
+
//cleanup
|
|
959
|
+
incomingNode.removeEventListener('transitionend', onTransitionEnd);
|
|
960
|
+
incomingNode.style.willChange = '';
|
|
961
|
+
incomingNode.style.transform = '';
|
|
962
|
+
incomingNode.style.pointerEvents = '';
|
|
963
|
+
incomingNode.style.transition = '';
|
|
964
|
+
incomingNode.style.top = '0px';
|
|
965
|
+
incomingNode.style.left = '0px';
|
|
966
|
+
incomingNode.style.zIndex = '';
|
|
967
|
+
exitingNode.style.willChange = '';
|
|
968
|
+
exitingNode.style.transform = '';
|
|
969
|
+
exitingNode.style.pointerEvents = '';
|
|
970
|
+
exitingNode.style.transition = '';
|
|
971
|
+
exitingNode.style.top = '0px';
|
|
972
|
+
exitingNode.style.left = '0px';
|
|
973
|
+
exitingNode.style.zIndex = '';
|
|
974
|
+
//And we're done
|
|
975
|
+
resolve();
|
|
976
|
+
};
|
|
977
|
+
incomingNode.addEventListener('transitionend', onTransitionEnd);
|
|
978
|
+
//Apply transition logic
|
|
979
|
+
setTimeout(() => {
|
|
980
|
+
switch (this.$slideDirection) {
|
|
981
|
+
case exports.TransitionSlideDirection.LEFT:
|
|
982
|
+
incomingNode.style.left = '0%';
|
|
983
|
+
exitingNode.style.left = '-100%';
|
|
984
|
+
break;
|
|
985
|
+
case exports.TransitionSlideDirection.RIGHT:
|
|
986
|
+
incomingNode.style.left = '0%';
|
|
987
|
+
exitingNode.style.left = '100%';
|
|
988
|
+
break;
|
|
989
|
+
case exports.TransitionSlideDirection.UP:
|
|
990
|
+
incomingNode.style.top = '0%';
|
|
991
|
+
exitingNode.style.top = '-100%';
|
|
992
|
+
break;
|
|
993
|
+
case exports.TransitionSlideDirection.DOWN:
|
|
994
|
+
incomingNode.style.top = '0%';
|
|
995
|
+
exitingNode.style.top = '100%';
|
|
996
|
+
break;
|
|
997
|
+
}
|
|
998
|
+
}, 1);
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
$getTransitionString(direction) {
|
|
1002
|
+
let dir = null;
|
|
1003
|
+
let speed = `${this.$slideSpeed}s`;
|
|
1004
|
+
switch (direction) {
|
|
1005
|
+
case exports.TransitionSlideDirection.LEFT:
|
|
1006
|
+
case exports.TransitionSlideDirection.RIGHT:
|
|
1007
|
+
dir = 'left';
|
|
1008
|
+
break;
|
|
1009
|
+
case exports.TransitionSlideDirection.UP:
|
|
1010
|
+
case exports.TransitionSlideDirection.DOWN:
|
|
1011
|
+
dir = 'top';
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
return `${dir} ${speed} ${this.$getSlideStyle()}`;
|
|
1015
|
+
}
|
|
1016
|
+
$getSlideStyle() {
|
|
1017
|
+
return 'ease-in-out';
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1825
1020
|
|
|
1826
1021
|
var name = "@breautek/router";
|
|
1827
|
-
var version = "
|
|
1022
|
+
var version = "4.1.0";
|
|
1828
1023
|
var description = "An alternate react router.";
|
|
1829
1024
|
var main = "dist/router.js";
|
|
1830
1025
|
var types = "dist/src/api.d.ts";
|
|
@@ -1835,12 +1030,10 @@ var publishConfig = {
|
|
|
1835
1030
|
var scripts = {
|
|
1836
1031
|
test: "jest",
|
|
1837
1032
|
lint: "eslint --ext .ts,.tsx '?(src|spec)/**/*.?(ts|tsx)' --cache",
|
|
1838
|
-
build: "rollup -c rollup.config.js",
|
|
1033
|
+
build: "rollup -c rollup.config.js --bundleConfigAsCjs",
|
|
1839
1034
|
"publish-beta": "npm publish --tag beta",
|
|
1840
1035
|
prepublishOnly: "npm run build",
|
|
1841
|
-
|
|
1842
|
-
docs: "typedoc --excludePrivate --includeVersion -readme ./README.md --out ./docs ./src/api.ts",
|
|
1843
|
-
version: "npm run-script build && npm run-script docs && npm run changelog && git add CHANGELOG.md docs && git commit -m 'chore: changelog'",
|
|
1036
|
+
version: "npm run-script build",
|
|
1844
1037
|
postversion: "git push && git push --tags"
|
|
1845
1038
|
};
|
|
1846
1039
|
var repository = {
|
|
@@ -1858,51 +1051,37 @@ var author = "norman@normanbreau.com";
|
|
|
1858
1051
|
var license = "MIT";
|
|
1859
1052
|
var homepage = "https://github.com/breautek/router";
|
|
1860
1053
|
var peerDependencies = {
|
|
1861
|
-
react: "
|
|
1862
|
-
"react-dom": "
|
|
1054
|
+
react: "16.x || 17.x || 18.x",
|
|
1055
|
+
"react-dom": "16.x || 17.x || 18.x"
|
|
1863
1056
|
};
|
|
1864
1057
|
var devDependencies = {
|
|
1865
|
-
"@
|
|
1866
|
-
"@
|
|
1867
|
-
"@
|
|
1868
|
-
"@
|
|
1869
|
-
"@
|
|
1870
|
-
"@
|
|
1871
|
-
"@
|
|
1872
|
-
"@
|
|
1873
|
-
"@
|
|
1874
|
-
"@
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
"
|
|
1878
|
-
|
|
1879
|
-
"@types/react-dom": "16.9.11",
|
|
1880
|
-
"@types/react-test-renderer": "17.0.1",
|
|
1881
|
-
"@typescript-eslint/eslint-plugin": "5.29.0",
|
|
1882
|
-
"@typescript-eslint/parser": "5.29.0",
|
|
1883
|
-
ajv: "8.11.0",
|
|
1884
|
-
"auto-changelog": "2.4.0",
|
|
1885
|
-
"babel-jest": "27.5.1",
|
|
1886
|
-
enzyme: "3.11.0",
|
|
1887
|
-
"enzyme-adapter-react-16": "1.15.6",
|
|
1888
|
-
eslint: "8.18.0",
|
|
1889
|
-
"eslint-plugin-react": "7.30.0",
|
|
1890
|
-
glob: "8.0.3",
|
|
1058
|
+
"@rollup/plugin-commonjs": "25.0.7",
|
|
1059
|
+
"@rollup/plugin-json": "6.0.1",
|
|
1060
|
+
"@rollup/plugin-node-resolve": "15.2.3",
|
|
1061
|
+
"@testing-library/jest-dom": "6.1.4",
|
|
1062
|
+
"@testing-library/react": "14.0.0",
|
|
1063
|
+
"@types/jest": "29.5.6",
|
|
1064
|
+
"@types/react": "18.2.33",
|
|
1065
|
+
"@types/react-dom": "18.2.14",
|
|
1066
|
+
"@typescript-eslint/eslint-plugin": "6.9.0",
|
|
1067
|
+
"@typescript-eslint/parser": "6.9.0",
|
|
1068
|
+
ajv: "8.12.0",
|
|
1069
|
+
eslint: "8.52.0",
|
|
1070
|
+
"eslint-plugin-react": "7.33.2",
|
|
1071
|
+
glob: "10.3.10",
|
|
1891
1072
|
"ignore-styles": "5.0.1",
|
|
1892
|
-
jest: "
|
|
1893
|
-
"
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
"
|
|
1897
|
-
rollup: "
|
|
1073
|
+
jest: "29.7.0",
|
|
1074
|
+
"jest-environment-jsdom": "29.7.0",
|
|
1075
|
+
"node-sass": "9.0.0",
|
|
1076
|
+
react: "18.2.0",
|
|
1077
|
+
"react-dom": "18.2.0",
|
|
1078
|
+
rollup: "4.1.4",
|
|
1898
1079
|
"rollup-plugin-progress": "1.1.2",
|
|
1899
|
-
"rollup-plugin-sass": "1.
|
|
1900
|
-
"rollup-plugin-typescript2": "0.
|
|
1901
|
-
"ts-jest": "
|
|
1902
|
-
"ts-node": "10.
|
|
1903
|
-
|
|
1904
|
-
"typedoc-plugin-markdown": "3.12.1",
|
|
1905
|
-
typescript: "4.6.4"
|
|
1080
|
+
"rollup-plugin-sass": "1.12.21",
|
|
1081
|
+
"rollup-plugin-typescript2": "0.36.0",
|
|
1082
|
+
"ts-jest": "29.1.1",
|
|
1083
|
+
"ts-node": "10.9.1",
|
|
1084
|
+
typescript: "5.2.2"
|
|
1906
1085
|
};
|
|
1907
1086
|
var packageInfo = {
|
|
1908
1087
|
name: name,
|
|
@@ -1922,7 +1101,7 @@ var packageInfo = {
|
|
|
1922
1101
|
devDependencies: devDependencies
|
|
1923
1102
|
};
|
|
1924
1103
|
|
|
1925
|
-
|
|
1104
|
+
const VERSION = packageInfo.version;
|
|
1926
1105
|
|
|
1927
1106
|
exports.DefaultStrategy = DefaultStrategy;
|
|
1928
1107
|
exports.EVENT_URL_CHANGE = EVENT_URL_CHANGE;
|