@tanstack/router-core 0.0.1-beta.5 → 0.0.1-beta.50
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/LICENSE +21 -0
- package/build/cjs/actions.js +94 -0
- package/build/cjs/actions.js.map +1 -0
- package/build/cjs/history.js +163 -0
- package/build/cjs/history.js.map +1 -0
- package/build/cjs/{packages/router-core/src/index.js → index.js} +26 -11
- package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
- package/build/cjs/interop.js +175 -0
- package/build/cjs/interop.js.map +1 -0
- package/build/cjs/{packages/router-core/src/path.js → path.js} +23 -48
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/route.js +33 -0
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +13 -18
- package/build/cjs/routeConfig.js.map +1 -0
- package/build/cjs/routeMatch.js +237 -0
- package/build/cjs/routeMatch.js.map +1 -0
- package/build/cjs/router.js +821 -0
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +10 -12
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/store.js +54 -0
- package/build/cjs/store.js.map +1 -0
- package/build/cjs/utils.js +47 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +1384 -2059
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +248 -193
- package/build/types/index.d.ts +385 -317
- package/build/umd/index.development.js +1486 -2142
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +6 -4
- package/src/actions.ts +157 -0
- package/src/frameworks.ts +2 -2
- package/src/history.ts +199 -0
- package/src/index.ts +4 -7
- package/src/interop.ts +169 -0
- package/src/link.ts +87 -44
- package/src/path.ts +12 -8
- package/src/route.ts +36 -229
- package/src/routeConfig.ts +99 -102
- package/src/routeInfo.ts +28 -25
- package/src/routeMatch.ts +294 -322
- package/src/router.ts +1047 -884
- package/src/store.ts +52 -0
- package/src/utils.ts +14 -72
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js +0 -161
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js +0 -797
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js +0 -118
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
|
@@ -1,797 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* router-core
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
|
|
16
|
-
var index = require('../../../node_modules/history/index.js');
|
|
17
|
-
var tinyInvariant = require('../../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js');
|
|
18
|
-
var path = require('./path.js');
|
|
19
|
-
var route = require('./route.js');
|
|
20
|
-
var routeMatch = require('./routeMatch.js');
|
|
21
|
-
var searchParams = require('./searchParams.js');
|
|
22
|
-
var utils = require('./utils.js');
|
|
23
|
-
|
|
24
|
-
var _window$document;
|
|
25
|
-
// Detect if we're in the DOM
|
|
26
|
-
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
|
|
27
|
-
|
|
28
|
-
const createDefaultHistory = () => isServer ? index.createMemoryHistory() : index.createBrowserHistory();
|
|
29
|
-
|
|
30
|
-
function createRouter(userOptions) {
|
|
31
|
-
var _userOptions$stringif, _userOptions$parseSea;
|
|
32
|
-
|
|
33
|
-
const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
|
|
34
|
-
|
|
35
|
-
const originalOptions = _rollupPluginBabelHelpers["extends"]({
|
|
36
|
-
defaultLoaderGcMaxAge: 5 * 60 * 1000,
|
|
37
|
-
defaultLoaderMaxAge: 0,
|
|
38
|
-
defaultPreloadMaxAge: 2000,
|
|
39
|
-
defaultPreloadDelay: 50
|
|
40
|
-
}, userOptions, {
|
|
41
|
-
stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : searchParams.defaultStringifySearch,
|
|
42
|
-
parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : searchParams.defaultParseSearch
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
let router = {
|
|
46
|
-
history,
|
|
47
|
-
options: originalOptions,
|
|
48
|
-
listeners: [],
|
|
49
|
-
removeActionQueue: [],
|
|
50
|
-
// Resolved after construction
|
|
51
|
-
basepath: '',
|
|
52
|
-
routeTree: undefined,
|
|
53
|
-
routesById: {},
|
|
54
|
-
location: undefined,
|
|
55
|
-
allRouteInfo: undefined,
|
|
56
|
-
//
|
|
57
|
-
navigationPromise: Promise.resolve(),
|
|
58
|
-
resolveNavigation: () => {},
|
|
59
|
-
matchCache: {},
|
|
60
|
-
state: {
|
|
61
|
-
status: 'idle',
|
|
62
|
-
location: null,
|
|
63
|
-
matches: [],
|
|
64
|
-
actions: {},
|
|
65
|
-
loaders: {},
|
|
66
|
-
lastUpdated: Date.now(),
|
|
67
|
-
isFetching: false,
|
|
68
|
-
isPreloading: false
|
|
69
|
-
},
|
|
70
|
-
startedLoadingAt: Date.now(),
|
|
71
|
-
subscribe: listener => {
|
|
72
|
-
router.listeners.push(listener);
|
|
73
|
-
return () => {
|
|
74
|
-
router.listeners = router.listeners.filter(x => x !== listener);
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
getRoute: id => {
|
|
78
|
-
return router.routesById[id];
|
|
79
|
-
},
|
|
80
|
-
notify: () => {
|
|
81
|
-
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
82
|
-
isFetching: router.state.status === 'loading' || router.state.matches.some(d => d.isFetching),
|
|
83
|
-
isPreloading: Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId))
|
|
84
|
-
});
|
|
85
|
-
route.cascadeLoaderData(router.state.matches);
|
|
86
|
-
router.listeners.forEach(listener => listener(router));
|
|
87
|
-
},
|
|
88
|
-
mount: () => {
|
|
89
|
-
const next = router.__.buildLocation({
|
|
90
|
-
to: '.',
|
|
91
|
-
search: true,
|
|
92
|
-
hash: true
|
|
93
|
-
}); // If the current location isn't updated, trigger a navigation
|
|
94
|
-
// to the current location. Otherwise, load the current location.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (next.href !== router.location.href) {
|
|
98
|
-
router.__.commitLocation(next, true);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
router.loadLocation();
|
|
102
|
-
const unsub = router.history.listen(event => {
|
|
103
|
-
console.log(event.location);
|
|
104
|
-
router.loadLocation(router.__.parseLocation(event.location, router.location));
|
|
105
|
-
}); // addEventListener does not exist in React Native, but window does
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
107
|
-
|
|
108
|
-
if (!isServer && window.addEventListener) {
|
|
109
|
-
// Listen to visibillitychange and focus
|
|
110
|
-
window.addEventListener('visibilitychange', router.onFocus, false);
|
|
111
|
-
window.addEventListener('focus', router.onFocus, false);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return () => {
|
|
115
|
-
unsub(); // Be sure to unsubscribe if a new handler is set
|
|
116
|
-
|
|
117
|
-
window.removeEventListener('visibilitychange', router.onFocus);
|
|
118
|
-
window.removeEventListener('focus', router.onFocus);
|
|
119
|
-
};
|
|
120
|
-
},
|
|
121
|
-
onFocus: () => {
|
|
122
|
-
router.loadLocation();
|
|
123
|
-
},
|
|
124
|
-
update: opts => {
|
|
125
|
-
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
126
|
-
|
|
127
|
-
if (!router.location || newHistory) {
|
|
128
|
-
if (opts != null && opts.history) {
|
|
129
|
-
router.history = opts.history;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
router.location = router.__.parseLocation(router.history.location);
|
|
133
|
-
router.state.location = router.location;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
Object.assign(router.options, opts);
|
|
137
|
-
const {
|
|
138
|
-
basepath,
|
|
139
|
-
routeConfig
|
|
140
|
-
} = router.options;
|
|
141
|
-
router.basepath = path.cleanPath("/" + (basepath != null ? basepath : ''));
|
|
142
|
-
|
|
143
|
-
if (routeConfig) {
|
|
144
|
-
router.routesById = {};
|
|
145
|
-
router.routeTree = router.__.buildRouteTree(routeConfig);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return router;
|
|
149
|
-
},
|
|
150
|
-
cancelMatches: () => {
|
|
151
|
-
var _router$state$pending, _router$state$pending2;
|
|
152
|
-
[...router.state.matches, ...((_router$state$pending = (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches) != null ? _router$state$pending : [])].forEach(match => {
|
|
153
|
-
match.cancel();
|
|
154
|
-
});
|
|
155
|
-
},
|
|
156
|
-
loadLocation: async next => {
|
|
157
|
-
const id = Math.random();
|
|
158
|
-
router.startedLoadingAt = id;
|
|
159
|
-
|
|
160
|
-
if (next) {
|
|
161
|
-
// Ingest the new location
|
|
162
|
-
router.location = next;
|
|
163
|
-
} // Clear out old actions
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
router.removeActionQueue.forEach(_ref => {
|
|
167
|
-
let {
|
|
168
|
-
action,
|
|
169
|
-
actionState
|
|
170
|
-
} = _ref;
|
|
171
|
-
|
|
172
|
-
if (router.state.currentAction === actionState) {
|
|
173
|
-
router.state.currentAction = undefined;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (action.current === actionState) {
|
|
177
|
-
action.current = undefined;
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
router.removeActionQueue = []; // Cancel any pending matches
|
|
181
|
-
|
|
182
|
-
router.cancelMatches(); // Match the routes
|
|
183
|
-
|
|
184
|
-
const matches = router.matchRoutes(router.location.pathname, {
|
|
185
|
-
strictParseParams: true
|
|
186
|
-
});
|
|
187
|
-
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
188
|
-
pending: {
|
|
189
|
-
matches: matches,
|
|
190
|
-
location: router.location
|
|
191
|
-
},
|
|
192
|
-
status: 'loading'
|
|
193
|
-
});
|
|
194
|
-
router.notify(); // Load the matches
|
|
195
|
-
|
|
196
|
-
await router.loadMatches(matches, {
|
|
197
|
-
withPending: true
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
if (router.startedLoadingAt !== id) {
|
|
201
|
-
// Ignore side-effects of match loading
|
|
202
|
-
return router.navigationPromise;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const previousMatches = router.state.matches;
|
|
206
|
-
const exiting = [],
|
|
207
|
-
staying = [];
|
|
208
|
-
previousMatches.forEach(d => {
|
|
209
|
-
if (matches.find(dd => dd.matchId === d.matchId)) {
|
|
210
|
-
staying.push(d);
|
|
211
|
-
} else {
|
|
212
|
-
exiting.push(d);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
const now = Date.now();
|
|
216
|
-
exiting.forEach(d => {
|
|
217
|
-
var _ref2, _d$options$loaderGcMa, _ref3, _d$options$loaderMaxA;
|
|
218
|
-
|
|
219
|
-
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
220
|
-
params: d.params,
|
|
221
|
-
search: d.routeSearch
|
|
222
|
-
}); // Clear idle error states when match leaves
|
|
223
|
-
|
|
224
|
-
if (d.status === 'error' && !d.isFetching) {
|
|
225
|
-
d.status = 'idle';
|
|
226
|
-
d.error = undefined;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const gc = Math.max((_ref2 = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref2 : 0, (_ref3 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0);
|
|
230
|
-
|
|
231
|
-
if (gc > 0) {
|
|
232
|
-
router.matchCache[d.matchId] = {
|
|
233
|
-
gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
|
|
234
|
-
match: d
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
staying.forEach(d => {
|
|
239
|
-
d.options.onTransition == null ? void 0 : d.options.onTransition({
|
|
240
|
-
params: d.params,
|
|
241
|
-
search: d.routeSearch
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
const entering = matches.filter(d => {
|
|
245
|
-
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
246
|
-
});
|
|
247
|
-
entering.forEach(d => {
|
|
248
|
-
d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
|
|
249
|
-
params: d.params,
|
|
250
|
-
search: d.search
|
|
251
|
-
});
|
|
252
|
-
delete router.matchCache[d.matchId];
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
if (matches.some(d => d.status === 'loading')) {
|
|
256
|
-
router.notify();
|
|
257
|
-
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (router.startedLoadingAt !== id) {
|
|
261
|
-
// Ignore side-effects of match loading
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
266
|
-
location: router.location,
|
|
267
|
-
matches,
|
|
268
|
-
pending: undefined,
|
|
269
|
-
status: 'idle'
|
|
270
|
-
});
|
|
271
|
-
router.notify();
|
|
272
|
-
router.resolveNavigation();
|
|
273
|
-
},
|
|
274
|
-
cleanMatchCache: () => {
|
|
275
|
-
const now = Date.now();
|
|
276
|
-
Object.keys(router.matchCache).forEach(matchId => {
|
|
277
|
-
const entry = router.matchCache[matchId]; // Don't remove loading matches
|
|
278
|
-
|
|
279
|
-
if (entry.match.status === 'loading') {
|
|
280
|
-
return;
|
|
281
|
-
} // Do not remove successful matches that are still valid
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (entry.gc > 0 && entry.gc > now) {
|
|
285
|
-
return;
|
|
286
|
-
} // Everything else gets removed
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
delete router.matchCache[matchId];
|
|
290
|
-
});
|
|
291
|
-
},
|
|
292
|
-
loadRoute: async function loadRoute(navigateOpts) {
|
|
293
|
-
if (navigateOpts === void 0) {
|
|
294
|
-
navigateOpts = router.location;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const next = router.buildNext(navigateOpts);
|
|
298
|
-
const matches = router.matchRoutes(next.pathname, {
|
|
299
|
-
strictParseParams: true
|
|
300
|
-
});
|
|
301
|
-
await router.loadMatches(matches);
|
|
302
|
-
return matches;
|
|
303
|
-
},
|
|
304
|
-
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
305
|
-
var _ref4, _ref5, _loaderOpts$maxAge, _ref6, _ref7, _loaderOpts$gcMaxAge;
|
|
306
|
-
|
|
307
|
-
if (navigateOpts === void 0) {
|
|
308
|
-
navigateOpts = router.location;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const next = router.buildNext(navigateOpts);
|
|
312
|
-
const matches = router.matchRoutes(next.pathname, {
|
|
313
|
-
strictParseParams: true
|
|
314
|
-
});
|
|
315
|
-
await router.loadMatches(matches, {
|
|
316
|
-
preload: true,
|
|
317
|
-
maxAge: (_ref4 = (_ref5 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref5 : router.options.defaultLoaderMaxAge) != null ? _ref4 : 0,
|
|
318
|
-
gcMaxAge: (_ref6 = (_ref7 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0
|
|
319
|
-
});
|
|
320
|
-
return matches;
|
|
321
|
-
},
|
|
322
|
-
matchRoutes: (pathname, opts) => {
|
|
323
|
-
var _router$state$pending3, _router$state$pending4;
|
|
324
|
-
|
|
325
|
-
router.cleanMatchCache();
|
|
326
|
-
const matches = [];
|
|
327
|
-
|
|
328
|
-
if (!router.routeTree) {
|
|
329
|
-
return matches;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const existingMatches = [...router.state.matches, ...((_router$state$pending3 = (_router$state$pending4 = router.state.pending) == null ? void 0 : _router$state$pending4.matches) != null ? _router$state$pending3 : [])];
|
|
333
|
-
|
|
334
|
-
const recurse = async routes => {
|
|
335
|
-
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
336
|
-
|
|
337
|
-
const parentMatch = utils.last(matches);
|
|
338
|
-
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
339
|
-
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
340
|
-
let foundRoutes = [];
|
|
341
|
-
|
|
342
|
-
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
343
|
-
routes.some(route => {
|
|
344
|
-
var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
|
|
345
|
-
|
|
346
|
-
if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
|
|
347
|
-
return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
|
|
351
|
-
const matchParams = path.matchPathname(pathname, {
|
|
352
|
-
to: route.fullPath,
|
|
353
|
-
fuzzy,
|
|
354
|
-
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
if (matchParams) {
|
|
358
|
-
let parsedParams;
|
|
359
|
-
|
|
360
|
-
try {
|
|
361
|
-
var _route$options$parseP;
|
|
362
|
-
|
|
363
|
-
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
364
|
-
} catch (err) {
|
|
365
|
-
if (opts != null && opts.strictParseParams) {
|
|
366
|
-
throw err;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
params = _rollupPluginBabelHelpers["extends"]({}, params, parsedParams);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (!!matchParams) {
|
|
374
|
-
foundRoutes = [...parentRoutes, route];
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return !!foundRoutes.length;
|
|
378
|
-
});
|
|
379
|
-
return !!foundRoutes.length;
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
findMatchInRoutes([], filteredRoutes);
|
|
383
|
-
|
|
384
|
-
if (!foundRoutes.length) {
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
foundRoutes.forEach(foundRoute => {
|
|
389
|
-
var _router$matchCache$ma;
|
|
390
|
-
|
|
391
|
-
const interpolatedPath = path.interpolatePath(foundRoute.routePath, params);
|
|
392
|
-
const matchId = path.interpolatePath(foundRoute.routeId, params, true);
|
|
393
|
-
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || routeMatch.createRouteMatch(router, foundRoute, {
|
|
394
|
-
matchId,
|
|
395
|
-
params,
|
|
396
|
-
pathname: path.joinPaths([pathname, interpolatedPath])
|
|
397
|
-
});
|
|
398
|
-
matches.push(match);
|
|
399
|
-
});
|
|
400
|
-
const foundRoute = utils.last(foundRoutes);
|
|
401
|
-
|
|
402
|
-
if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
|
|
403
|
-
recurse(foundRoute.childRoutes);
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
recurse([router.routeTree]);
|
|
408
|
-
route.cascadeLoaderData(matches);
|
|
409
|
-
return matches;
|
|
410
|
-
},
|
|
411
|
-
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
412
|
-
const matchPromises = resolvedMatches.map(async match => {
|
|
413
|
-
// Validate the match (loads search params etc)
|
|
414
|
-
match.__.validate();
|
|
415
|
-
|
|
416
|
-
match.load(loaderOpts);
|
|
417
|
-
|
|
418
|
-
if (match.status === 'loading') {
|
|
419
|
-
// If requested, start the pending timers
|
|
420
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending(); // Wait for the first sign of activity from the match
|
|
421
|
-
// This might be completion, error, or a pending state
|
|
422
|
-
|
|
423
|
-
await match.__.loadPromise;
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
router.notify();
|
|
427
|
-
await Promise.all(matchPromises);
|
|
428
|
-
},
|
|
429
|
-
invalidateRoute: opts => {
|
|
430
|
-
var _router$state$pending5, _router$state$pending6;
|
|
431
|
-
|
|
432
|
-
const next = router.buildNext(opts);
|
|
433
|
-
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
434
|
-
[...router.state.matches, ...((_router$state$pending5 = (_router$state$pending6 = router.state.pending) == null ? void 0 : _router$state$pending6.matches) != null ? _router$state$pending5 : [])].forEach(match => {
|
|
435
|
-
if (unloadedMatchIds.includes(match.matchId)) {
|
|
436
|
-
match.invalidate();
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
},
|
|
440
|
-
reload: () => router.__.navigate({
|
|
441
|
-
fromCurrent: true,
|
|
442
|
-
replace: true,
|
|
443
|
-
search: true
|
|
444
|
-
}),
|
|
445
|
-
resolvePath: (from, path$1) => {
|
|
446
|
-
return path.resolvePath(router.basepath, from, path.cleanPath(path$1));
|
|
447
|
-
},
|
|
448
|
-
matchRoute: (location, opts) => {
|
|
449
|
-
var _location$from;
|
|
450
|
-
|
|
451
|
-
// const location = router.buildNext(opts)
|
|
452
|
-
location = _rollupPluginBabelHelpers["extends"]({}, location, {
|
|
453
|
-
to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
|
|
454
|
-
});
|
|
455
|
-
const next = router.buildNext(location);
|
|
456
|
-
|
|
457
|
-
if (opts != null && opts.pending) {
|
|
458
|
-
var _router$state$pending7;
|
|
459
|
-
|
|
460
|
-
if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
|
|
461
|
-
return false;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
return !!path.matchPathname(router.state.pending.location.pathname, _rollupPluginBabelHelpers["extends"]({}, opts, {
|
|
465
|
-
to: next.pathname
|
|
466
|
-
}));
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return !!path.matchPathname(router.state.location.pathname, _rollupPluginBabelHelpers["extends"]({}, opts, {
|
|
470
|
-
to: next.pathname
|
|
471
|
-
}));
|
|
472
|
-
},
|
|
473
|
-
navigate: async _ref8 => {
|
|
474
|
-
let {
|
|
475
|
-
from,
|
|
476
|
-
to = '.',
|
|
477
|
-
search,
|
|
478
|
-
hash,
|
|
479
|
-
replace,
|
|
480
|
-
params
|
|
481
|
-
} = _ref8;
|
|
482
|
-
// If this link simply reloads the current route,
|
|
483
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
484
|
-
// If this `to` is a valid external URL, return
|
|
485
|
-
// null for LinkUtils
|
|
486
|
-
const toString = String(to);
|
|
487
|
-
const fromString = String(from);
|
|
488
|
-
let isExternal;
|
|
489
|
-
|
|
490
|
-
try {
|
|
491
|
-
new URL("" + toString);
|
|
492
|
-
isExternal = true;
|
|
493
|
-
} catch (e) {}
|
|
494
|
-
|
|
495
|
-
tinyInvariant["default"](!isExternal, 'Attempting to navigate to external url with router.navigate!');
|
|
496
|
-
return router.__.navigate({
|
|
497
|
-
from: fromString,
|
|
498
|
-
to: toString,
|
|
499
|
-
search,
|
|
500
|
-
hash,
|
|
501
|
-
replace,
|
|
502
|
-
params
|
|
503
|
-
});
|
|
504
|
-
},
|
|
505
|
-
buildLink: _ref9 => {
|
|
506
|
-
var _preload, _ref10;
|
|
507
|
-
|
|
508
|
-
let {
|
|
509
|
-
from,
|
|
510
|
-
to = '.',
|
|
511
|
-
search,
|
|
512
|
-
params,
|
|
513
|
-
hash,
|
|
514
|
-
target,
|
|
515
|
-
replace,
|
|
516
|
-
activeOptions,
|
|
517
|
-
preload,
|
|
518
|
-
preloadMaxAge: userPreloadMaxAge,
|
|
519
|
-
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
520
|
-
preloadDelay: userPreloadDelay,
|
|
521
|
-
disabled
|
|
522
|
-
} = _ref9;
|
|
523
|
-
|
|
524
|
-
// If this link simply reloads the current route,
|
|
525
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
526
|
-
// If this `to` is a valid external URL, return
|
|
527
|
-
// null for LinkUtils
|
|
528
|
-
try {
|
|
529
|
-
new URL("" + to);
|
|
530
|
-
return {
|
|
531
|
-
type: 'external',
|
|
532
|
-
href: to
|
|
533
|
-
};
|
|
534
|
-
} catch (e) {}
|
|
535
|
-
|
|
536
|
-
const nextOpts = {
|
|
537
|
-
from,
|
|
538
|
-
to,
|
|
539
|
-
search,
|
|
540
|
-
params,
|
|
541
|
-
hash,
|
|
542
|
-
replace
|
|
543
|
-
};
|
|
544
|
-
const next = router.buildNext(nextOpts);
|
|
545
|
-
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
546
|
-
const preloadDelay = (_ref10 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref10 : 0; // Compare path/hash for matches
|
|
547
|
-
|
|
548
|
-
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
549
|
-
const currentPathSplit = router.state.location.pathname.split('/');
|
|
550
|
-
const nextPathSplit = next.pathname.split('/');
|
|
551
|
-
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
552
|
-
const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
|
|
553
|
-
|
|
554
|
-
const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
|
|
555
|
-
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
|
|
556
|
-
|
|
557
|
-
const isActive = pathTest && hashTest; // The click handler
|
|
558
|
-
|
|
559
|
-
const handleClick = e => {
|
|
560
|
-
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
561
|
-
e.preventDefault();
|
|
562
|
-
|
|
563
|
-
if (pathIsEqual && !search && !hash) {
|
|
564
|
-
router.invalidateRoute(nextOpts);
|
|
565
|
-
} // All is well? Navigate!)
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
router.__.navigate(nextOpts);
|
|
569
|
-
}
|
|
570
|
-
}; // The click handler
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
const handleFocus = e => {
|
|
574
|
-
if (preload) {
|
|
575
|
-
router.preloadRoute(nextOpts, {
|
|
576
|
-
maxAge: userPreloadMaxAge,
|
|
577
|
-
gcMaxAge: userPreloadGcMaxAge
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
const handleEnter = e => {
|
|
583
|
-
const target = e.target || {};
|
|
584
|
-
|
|
585
|
-
if (preload) {
|
|
586
|
-
if (target.preloadTimeout) {
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
target.preloadTimeout = setTimeout(() => {
|
|
591
|
-
target.preloadTimeout = null;
|
|
592
|
-
router.preloadRoute(nextOpts, {
|
|
593
|
-
maxAge: userPreloadMaxAge,
|
|
594
|
-
gcMaxAge: userPreloadGcMaxAge
|
|
595
|
-
});
|
|
596
|
-
}, preloadDelay);
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
const handleLeave = e => {
|
|
601
|
-
const target = e.target || {};
|
|
602
|
-
|
|
603
|
-
if (target.preloadTimeout) {
|
|
604
|
-
clearTimeout(target.preloadTimeout);
|
|
605
|
-
target.preloadTimeout = null;
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
|
|
609
|
-
return {
|
|
610
|
-
type: 'internal',
|
|
611
|
-
next,
|
|
612
|
-
handleFocus,
|
|
613
|
-
handleClick,
|
|
614
|
-
handleEnter,
|
|
615
|
-
handleLeave,
|
|
616
|
-
isActive,
|
|
617
|
-
disabled
|
|
618
|
-
};
|
|
619
|
-
},
|
|
620
|
-
buildNext: opts => {
|
|
621
|
-
const next = router.__.buildLocation(opts);
|
|
622
|
-
|
|
623
|
-
const matches = router.matchRoutes(next.pathname);
|
|
624
|
-
|
|
625
|
-
const __preSearchFilters = matches.map(match => {
|
|
626
|
-
var _match$options$preSea;
|
|
627
|
-
|
|
628
|
-
return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
|
|
629
|
-
}).flat().filter(Boolean);
|
|
630
|
-
|
|
631
|
-
const __postSearchFilters = matches.map(match => {
|
|
632
|
-
var _match$options$postSe;
|
|
633
|
-
|
|
634
|
-
return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
|
|
635
|
-
}).flat().filter(Boolean);
|
|
636
|
-
|
|
637
|
-
return router.__.buildLocation(_rollupPluginBabelHelpers["extends"]({}, opts, {
|
|
638
|
-
__preSearchFilters,
|
|
639
|
-
__postSearchFilters
|
|
640
|
-
}));
|
|
641
|
-
},
|
|
642
|
-
__: {
|
|
643
|
-
buildRouteTree: rootRouteConfig => {
|
|
644
|
-
const recurseRoutes = (routeConfigs, parent) => {
|
|
645
|
-
return routeConfigs.map(routeConfig => {
|
|
646
|
-
const routeOptions = routeConfig.options;
|
|
647
|
-
const route$1 = route.createRoute(routeConfig, routeOptions, parent, router); // {
|
|
648
|
-
// pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
|
|
649
|
-
// pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
|
|
650
|
-
// }
|
|
651
|
-
|
|
652
|
-
const existingRoute = router.routesById[route$1.routeId];
|
|
653
|
-
|
|
654
|
-
if (existingRoute) {
|
|
655
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
656
|
-
console.warn("Duplicate routes found with id: " + String(route$1.routeId), router.routesById, route$1);
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
throw new Error();
|
|
660
|
-
}
|
|
661
|
-
router.routesById[route$1.routeId] = route$1;
|
|
662
|
-
const children = routeConfig.children;
|
|
663
|
-
route$1.childRoutes = children != null && children.length ? recurseRoutes(children, route$1) : undefined;
|
|
664
|
-
return route$1;
|
|
665
|
-
});
|
|
666
|
-
};
|
|
667
|
-
|
|
668
|
-
const routes = recurseRoutes([rootRouteConfig]);
|
|
669
|
-
return routes[0];
|
|
670
|
-
},
|
|
671
|
-
parseLocation: (location, previousLocation) => {
|
|
672
|
-
var _location$hash$split$;
|
|
673
|
-
|
|
674
|
-
const parsedSearch = router.options.parseSearch(location.search);
|
|
675
|
-
return {
|
|
676
|
-
pathname: location.pathname,
|
|
677
|
-
searchStr: location.search,
|
|
678
|
-
search: utils.replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
|
|
679
|
-
hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
|
|
680
|
-
href: "" + location.pathname + location.search + location.hash,
|
|
681
|
-
state: location.state,
|
|
682
|
-
key: location.key
|
|
683
|
-
};
|
|
684
|
-
},
|
|
685
|
-
navigate: location => {
|
|
686
|
-
const next = router.buildNext(location);
|
|
687
|
-
return router.__.commitLocation(next, location.replace);
|
|
688
|
-
},
|
|
689
|
-
buildLocation: function buildLocation(dest) {
|
|
690
|
-
var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
|
|
691
|
-
|
|
692
|
-
if (dest === void 0) {
|
|
693
|
-
dest = {};
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
// const resolvedFrom: Location = {
|
|
697
|
-
// ...router.location,
|
|
698
|
-
const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
|
|
699
|
-
|
|
700
|
-
let pathname = path.resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
|
|
701
|
-
|
|
702
|
-
const fromMatches = router.matchRoutes(router.location.pathname, {
|
|
703
|
-
strictParseParams: true
|
|
704
|
-
});
|
|
705
|
-
const toMatches = router.matchRoutes(pathname);
|
|
706
|
-
|
|
707
|
-
const prevParams = _rollupPluginBabelHelpers["extends"]({}, (_last = utils.last(fromMatches)) == null ? void 0 : _last.params);
|
|
708
|
-
|
|
709
|
-
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : utils.functionalUpdate(dest.params, prevParams);
|
|
710
|
-
|
|
711
|
-
if (nextParams) {
|
|
712
|
-
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
713
|
-
Object.assign({}, nextParams, fn(nextParams));
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
pathname = path.interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
|
|
718
|
-
|
|
719
|
-
const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search; // Then the link/navigate function
|
|
720
|
-
|
|
721
|
-
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
722
|
-
: dest.search ? (_functionalUpdate = utils.functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
|
|
723
|
-
: (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
|
|
724
|
-
: {}; // Then post filters
|
|
725
|
-
|
|
726
|
-
const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
727
|
-
const search = utils.replaceEqualDeep(router.location.search, postFilteredSearch);
|
|
728
|
-
const searchStr = router.options.stringifySearch(search);
|
|
729
|
-
let hash = dest.hash === true ? router.location.hash : utils.functionalUpdate(dest.hash, router.location.hash);
|
|
730
|
-
hash = hash ? "#" + hash : '';
|
|
731
|
-
return {
|
|
732
|
-
pathname,
|
|
733
|
-
search,
|
|
734
|
-
searchStr,
|
|
735
|
-
state: router.location.state,
|
|
736
|
-
hash,
|
|
737
|
-
href: "" + pathname + searchStr + hash,
|
|
738
|
-
key: dest.key
|
|
739
|
-
};
|
|
740
|
-
},
|
|
741
|
-
commitLocation: (next, replace) => {
|
|
742
|
-
const id = '' + Date.now() + Math.random();
|
|
743
|
-
if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
|
|
744
|
-
let nextAction = 'replace';
|
|
745
|
-
|
|
746
|
-
if (!replace) {
|
|
747
|
-
nextAction = 'push';
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
const isSameUrl = router.__.parseLocation(history.location).href === next.href;
|
|
751
|
-
|
|
752
|
-
if (isSameUrl && !next.key) {
|
|
753
|
-
nextAction = 'replace';
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
if (nextAction === 'replace') {
|
|
757
|
-
history.replace({
|
|
758
|
-
pathname: next.pathname,
|
|
759
|
-
hash: next.hash,
|
|
760
|
-
search: next.searchStr
|
|
761
|
-
}, {
|
|
762
|
-
id
|
|
763
|
-
});
|
|
764
|
-
} else {
|
|
765
|
-
history.push({
|
|
766
|
-
pathname: next.pathname,
|
|
767
|
-
hash: next.hash,
|
|
768
|
-
search: next.searchStr
|
|
769
|
-
}, {
|
|
770
|
-
id
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
router.navigationPromise = new Promise(resolve => {
|
|
775
|
-
const previousNavigationResolve = router.resolveNavigation;
|
|
776
|
-
|
|
777
|
-
router.resolveNavigation = () => {
|
|
778
|
-
previousNavigationResolve();
|
|
779
|
-
resolve();
|
|
780
|
-
};
|
|
781
|
-
});
|
|
782
|
-
return router.navigationPromise;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
};
|
|
786
|
-
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
787
|
-
|
|
788
|
-
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
789
|
-
return router;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
function isCtrlEvent(e) {
|
|
793
|
-
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
exports.createRouter = createRouter;
|
|
797
|
-
//# sourceMappingURL=router.js.map
|