@tanstack/router-core 0.0.1-alpha.6 → 0.0.1-alpha.7
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/build/cjs/packages/router-core/src/index.js +33 -1456
- package/build/cjs/packages/router-core/src/index.js.map +1 -1
- package/build/cjs/packages/router-core/src/path.js +222 -0
- package/build/cjs/packages/router-core/src/path.js.map +1 -0
- package/build/cjs/packages/router-core/src/qss.js +1 -1
- package/build/cjs/packages/router-core/src/qss.js.map +1 -1
- package/build/cjs/packages/router-core/src/route.js +126 -0
- package/build/cjs/packages/router-core/src/route.js.map +1 -0
- package/build/cjs/packages/router-core/src/routeConfig.js +69 -0
- package/build/cjs/packages/router-core/src/routeConfig.js.map +1 -0
- package/build/cjs/packages/router-core/src/routeMatch.js +260 -0
- package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -0
- package/build/cjs/packages/router-core/src/router.js +787 -0
- package/build/cjs/packages/router-core/src/router.js.map +1 -0
- package/build/cjs/packages/router-core/src/searchParams.js +70 -0
- package/build/cjs/packages/router-core/src/searchParams.js.map +1 -0
- package/build/cjs/packages/router-core/src/utils.js +118 -0
- package/build/cjs/packages/router-core/src/utils.js.map +1 -0
- package/build/esm/index.js +1303 -1242
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +374 -57
- package/build/types/index.d.ts +361 -336
- package/build/umd/index.development.js +1312 -1242
- 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 +2 -3
- package/src/frameworks.ts +13 -0
- package/src/index.ts +15 -3060
- package/src/link.ts +289 -0
- package/src/path.ts +236 -0
- package/src/qss.ts +1 -1
- package/src/route.ts +181 -0
- package/src/routeConfig.ts +523 -0
- package/src/routeInfo.ts +228 -0
- package/src/routeMatch.ts +357 -0
- package/src/router.ts +1182 -0
- package/src/searchParams.ts +54 -0
- package/src/utils.ts +157 -0
|
@@ -12,1470 +12,47 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
-
var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
|
|
16
15
|
var index = require('../../../node_modules/history/index.js');
|
|
17
16
|
var tinyInvariant = require('../../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js');
|
|
17
|
+
var path = require('./path.js');
|
|
18
18
|
var qss = require('./qss.js');
|
|
19
|
+
var route = require('./route.js');
|
|
20
|
+
var routeConfig = require('./routeConfig.js');
|
|
21
|
+
var routeMatch = require('./routeMatch.js');
|
|
22
|
+
var router = require('./router.js');
|
|
23
|
+
var searchParams = require('./searchParams.js');
|
|
24
|
+
var utils = require('./utils.js');
|
|
19
25
|
|
|
20
|
-
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
21
|
-
if (options === void 0) {
|
|
22
|
-
options = {};
|
|
23
|
-
}
|
|
24
26
|
|
|
25
|
-
if (isRoot === void 0) {
|
|
26
|
-
isRoot = true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (isRoot) {
|
|
30
|
-
options.path = rootRouteId;
|
|
31
|
-
} // Strip the root from parentIds
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (parentId === rootRouteId) {
|
|
35
|
-
parentId = '';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
|
|
39
|
-
|
|
40
|
-
if (path && path !== '/') {
|
|
41
|
-
path = trimPath(path);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const routeId = path || options.id;
|
|
45
|
-
let id = joinPaths([parentId, routeId]);
|
|
46
|
-
|
|
47
|
-
if (path === rootRouteId) {
|
|
48
|
-
path = '/';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (id !== rootRouteId) {
|
|
52
|
-
id = joinPaths(['/', id]);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
|
|
56
|
-
return {
|
|
57
|
-
id: id,
|
|
58
|
-
routeId: routeId,
|
|
59
|
-
path: path,
|
|
60
|
-
fullPath: fullPath,
|
|
61
|
-
options: options,
|
|
62
|
-
children,
|
|
63
|
-
addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath)
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
const rootRouteId = '__root__';
|
|
67
|
-
// Source
|
|
68
|
-
// Detect if we're in the DOM
|
|
69
|
-
const isDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement); // This is the default history object if none is defined
|
|
70
|
-
|
|
71
|
-
const createDefaultHistory = () => isDOM ? index.createBrowserHistory() : index.createMemoryHistory();
|
|
72
|
-
|
|
73
|
-
function createRouter(userOptions) {
|
|
74
|
-
var _userOptions$stringif, _userOptions$parseSea;
|
|
75
|
-
|
|
76
|
-
const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
|
|
77
|
-
|
|
78
|
-
const originalOptions = _rollupPluginBabelHelpers["extends"]({}, userOptions, {
|
|
79
|
-
stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
|
|
80
|
-
parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
let router = {
|
|
84
|
-
options: originalOptions,
|
|
85
|
-
listeners: [],
|
|
86
|
-
removeActionQueue: [],
|
|
87
|
-
// Resolved after construction
|
|
88
|
-
basepath: '',
|
|
89
|
-
routeTree: undefined,
|
|
90
|
-
routesById: {},
|
|
91
|
-
location: undefined,
|
|
92
|
-
allRouteInfo: undefined,
|
|
93
|
-
//
|
|
94
|
-
navigationPromise: Promise.resolve(),
|
|
95
|
-
resolveNavigation: () => {},
|
|
96
|
-
preloadCache: {},
|
|
97
|
-
state: {
|
|
98
|
-
status: 'idle',
|
|
99
|
-
location: null,
|
|
100
|
-
matches: [],
|
|
101
|
-
actions: {},
|
|
102
|
-
loaderData: {},
|
|
103
|
-
lastUpdated: Date.now()
|
|
104
|
-
},
|
|
105
|
-
startedLoadingAt: Date.now(),
|
|
106
|
-
subscribe: listener => {
|
|
107
|
-
router.listeners.push(listener);
|
|
108
|
-
return () => {
|
|
109
|
-
router.listeners = router.listeners.filter(x => x !== listener);
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
getRoute: id => {
|
|
113
|
-
return router.routesById[id];
|
|
114
|
-
},
|
|
115
|
-
notify: () => {
|
|
116
|
-
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state);
|
|
117
|
-
router.listeners.forEach(listener => listener());
|
|
118
|
-
},
|
|
119
|
-
mount: () => {
|
|
120
|
-
const next = router.buildLocation({
|
|
121
|
-
to: '.',
|
|
122
|
-
search: true,
|
|
123
|
-
hash: true
|
|
124
|
-
}); // If the current location isn't updated, trigger a navigation
|
|
125
|
-
// to the current location. Otherwise, load the current location.
|
|
126
|
-
|
|
127
|
-
if (next.href !== router.location.href) {
|
|
128
|
-
return router.commitLocation(next, true);
|
|
129
|
-
} else {
|
|
130
|
-
return router.loadLocation();
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
update: opts => {
|
|
134
|
-
Object.assign(router.options, opts);
|
|
135
|
-
const {
|
|
136
|
-
basepath,
|
|
137
|
-
routeConfig
|
|
138
|
-
} = router.options;
|
|
139
|
-
router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
|
|
140
|
-
|
|
141
|
-
if (routeConfig) {
|
|
142
|
-
router.routesById = {};
|
|
143
|
-
router.routeTree = router.buildRouteTree(routeConfig);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return router;
|
|
147
|
-
},
|
|
148
|
-
destroy: history.listen(event => {
|
|
149
|
-
router.loadLocation(router.parseLocation(event.location, router.location));
|
|
150
|
-
}),
|
|
151
|
-
buildRouteTree: rootRouteConfig => {
|
|
152
|
-
const recurseRoutes = (routeConfigs, parent) => {
|
|
153
|
-
return routeConfigs.map(routeConfig => {
|
|
154
|
-
const routeOptions = routeConfig.options;
|
|
155
|
-
const route = createRoute(routeConfig, routeOptions, parent, router); // {
|
|
156
|
-
// pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
|
|
157
|
-
// pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
|
|
158
|
-
// }
|
|
159
|
-
|
|
160
|
-
const existingRoute = router.routesById[route.routeId];
|
|
161
|
-
|
|
162
|
-
if (existingRoute) {
|
|
163
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
164
|
-
console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
throw new Error();
|
|
168
|
-
}
|
|
169
|
-
router.routesById[route.routeId] = route;
|
|
170
|
-
const children = routeConfig.children;
|
|
171
|
-
route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
|
|
172
|
-
return route;
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const routes = recurseRoutes([rootRouteConfig]);
|
|
177
|
-
return routes[0];
|
|
178
|
-
},
|
|
179
|
-
parseLocation: (location, previousLocation) => {
|
|
180
|
-
var _location$hash$split$;
|
|
181
|
-
|
|
182
|
-
const parsedSearch = router.options.parseSearch(location.search);
|
|
183
|
-
return {
|
|
184
|
-
pathname: location.pathname,
|
|
185
|
-
searchStr: location.search,
|
|
186
|
-
search: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
|
|
187
|
-
hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
|
|
188
|
-
href: "" + location.pathname + location.search + location.hash,
|
|
189
|
-
state: location.state,
|
|
190
|
-
key: location.key
|
|
191
|
-
};
|
|
192
|
-
},
|
|
193
|
-
buildLocation: function buildLocation(dest) {
|
|
194
|
-
var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
|
|
195
|
-
|
|
196
|
-
if (dest === void 0) {
|
|
197
|
-
dest = {};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// const resolvedFrom: Location = {
|
|
201
|
-
// ...router.location,
|
|
202
|
-
const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
|
|
203
|
-
|
|
204
|
-
let pathname = _resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
|
|
205
|
-
|
|
206
|
-
const fromMatches = router.matchRoutes(router.location.pathname, {
|
|
207
|
-
strictParseParams: true
|
|
208
|
-
});
|
|
209
|
-
const toMatches = router.matchRoutes(pathname);
|
|
210
|
-
|
|
211
|
-
const prevParams = _rollupPluginBabelHelpers["extends"]({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
|
|
212
|
-
|
|
213
|
-
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
214
|
-
|
|
215
|
-
if (nextParams) {
|
|
216
|
-
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
217
|
-
Object.assign({}, nextParams, fn(nextParams));
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
pathname = interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
|
|
222
|
-
|
|
223
|
-
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
|
|
224
|
-
|
|
225
|
-
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
226
|
-
: dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
|
|
227
|
-
: (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
|
|
228
|
-
: {}; // Then post filters
|
|
229
|
-
|
|
230
|
-
const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
231
|
-
const search = replaceEqualDeep(router.location.search, postFilteredSearch);
|
|
232
|
-
const searchStr = router.options.stringifySearch(search);
|
|
233
|
-
let hash = dest.hash === true ? router.location.hash : functionalUpdate(dest.hash, router.location.hash);
|
|
234
|
-
hash = hash ? "#" + hash : '';
|
|
235
|
-
return {
|
|
236
|
-
pathname,
|
|
237
|
-
search,
|
|
238
|
-
searchStr,
|
|
239
|
-
state: router.location.state,
|
|
240
|
-
hash,
|
|
241
|
-
href: "" + pathname + searchStr + hash,
|
|
242
|
-
key: dest.key
|
|
243
|
-
};
|
|
244
|
-
},
|
|
245
|
-
commitLocation: (next, replace) => {
|
|
246
|
-
const id = '' + Date.now() + Math.random();
|
|
247
|
-
if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
|
|
248
|
-
let nextAction = 'replace';
|
|
249
|
-
|
|
250
|
-
if (!replace) {
|
|
251
|
-
nextAction = 'push';
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const isSameUrl = router.parseLocation(history.location).href === next.href;
|
|
255
|
-
|
|
256
|
-
if (isSameUrl && !next.key) {
|
|
257
|
-
nextAction = 'replace';
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (nextAction === 'replace') {
|
|
261
|
-
history.replace({
|
|
262
|
-
pathname: next.pathname,
|
|
263
|
-
hash: next.hash,
|
|
264
|
-
search: next.searchStr
|
|
265
|
-
}, {
|
|
266
|
-
id
|
|
267
|
-
});
|
|
268
|
-
} else {
|
|
269
|
-
history.push({
|
|
270
|
-
pathname: next.pathname,
|
|
271
|
-
hash: next.hash,
|
|
272
|
-
search: next.searchStr
|
|
273
|
-
}, {
|
|
274
|
-
id
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
router.navigationPromise = new Promise(resolve => {
|
|
279
|
-
const previousNavigationResolve = router.resolveNavigation;
|
|
280
|
-
|
|
281
|
-
router.resolveNavigation = () => {
|
|
282
|
-
previousNavigationResolve();
|
|
283
|
-
resolve();
|
|
284
|
-
};
|
|
285
|
-
});
|
|
286
|
-
return router.navigationPromise;
|
|
287
|
-
},
|
|
288
|
-
buildNext: opts => {
|
|
289
|
-
const next = router.buildLocation(opts);
|
|
290
|
-
const matches = router.matchRoutes(next.pathname);
|
|
291
|
-
|
|
292
|
-
const __preSearchFilters = matches.map(match => {
|
|
293
|
-
var _match$options$preSea;
|
|
294
|
-
|
|
295
|
-
return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
|
|
296
|
-
}).flat().filter(Boolean);
|
|
297
|
-
|
|
298
|
-
const __postSearchFilters = matches.map(match => {
|
|
299
|
-
var _match$options$postSe;
|
|
300
|
-
|
|
301
|
-
return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
|
|
302
|
-
}).flat().filter(Boolean);
|
|
303
|
-
|
|
304
|
-
return router.buildLocation(_rollupPluginBabelHelpers["extends"]({}, opts, {
|
|
305
|
-
__preSearchFilters,
|
|
306
|
-
__postSearchFilters
|
|
307
|
-
}));
|
|
308
|
-
},
|
|
309
|
-
cancelMatches: () => {
|
|
310
|
-
var _router$state$pending, _router$state$pending2;
|
|
311
|
-
[...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 => {
|
|
312
|
-
match.cancel();
|
|
313
|
-
});
|
|
314
|
-
},
|
|
315
|
-
loadLocation: async next => {
|
|
316
|
-
const id = Math.random();
|
|
317
|
-
router.startedLoadingAt = id;
|
|
318
|
-
|
|
319
|
-
if (next) {
|
|
320
|
-
// Ingest the new location
|
|
321
|
-
router.location = next;
|
|
322
|
-
} // Clear out old actions
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
router.removeActionQueue.forEach(_ref => {
|
|
326
|
-
let {
|
|
327
|
-
action,
|
|
328
|
-
actionState
|
|
329
|
-
} = _ref;
|
|
330
|
-
|
|
331
|
-
if (router.state.currentAction === actionState) {
|
|
332
|
-
router.state.currentAction = undefined;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
if (action.current === actionState) {
|
|
336
|
-
action.current = undefined;
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
router.removeActionQueue = []; // Cancel any pending matches
|
|
340
|
-
|
|
341
|
-
router.cancelMatches(); // Match the routes
|
|
342
|
-
|
|
343
|
-
const unloadedMatches = router.matchRoutes(location.pathname, {
|
|
344
|
-
strictParseParams: true
|
|
345
|
-
});
|
|
346
|
-
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
347
|
-
pending: {
|
|
348
|
-
matches: unloadedMatches,
|
|
349
|
-
location: router.location
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
router.notify(); // Load the matches
|
|
353
|
-
|
|
354
|
-
const matches = await router.loadMatches(unloadedMatches, {
|
|
355
|
-
withPending: true
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
if (router.startedLoadingAt !== id) {
|
|
359
|
-
// Ignore side-effects of match loading
|
|
360
|
-
return router.navigationPromise;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const previousMatches = router.state.matches;
|
|
364
|
-
previousMatches.filter(d => {
|
|
365
|
-
return !matches.find(dd => dd.matchId === d.matchId);
|
|
366
|
-
}).forEach(d => {
|
|
367
|
-
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
368
|
-
params: d.params,
|
|
369
|
-
search: d.routeSearch
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
previousMatches.filter(d => {
|
|
373
|
-
return matches.find(dd => dd.matchId === d.matchId);
|
|
374
|
-
}).forEach(d => {
|
|
375
|
-
d.options.onTransition == null ? void 0 : d.options.onTransition({
|
|
376
|
-
params: d.params,
|
|
377
|
-
search: d.routeSearch
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
matches.filter(d => {
|
|
381
|
-
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
382
|
-
}).forEach(d => {
|
|
383
|
-
d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
|
|
384
|
-
params: d.params,
|
|
385
|
-
search: d.search
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
389
|
-
location: router.location,
|
|
390
|
-
matches,
|
|
391
|
-
pending: undefined
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
if (matches.some(d => d.status === 'loading')) {
|
|
395
|
-
router.notify();
|
|
396
|
-
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
if (router.startedLoadingAt !== id) {
|
|
400
|
-
// Ignore side-effects of match loading
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
router.notify();
|
|
405
|
-
router.resolveNavigation();
|
|
406
|
-
},
|
|
407
|
-
cleanPreloadCache: () => {
|
|
408
|
-
const now = Date.now();
|
|
409
|
-
Object.keys(router.preloadCache).forEach(matchId => {
|
|
410
|
-
const entry = router.preloadCache[matchId]; // Don't remove loading matches
|
|
411
|
-
|
|
412
|
-
if (entry.match.status === 'loading') {
|
|
413
|
-
return;
|
|
414
|
-
} // Do not remove successful matches that are still valid
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (entry.match.updatedAt && entry.match.updatedAt + entry.maxAge > now) {
|
|
418
|
-
return;
|
|
419
|
-
} // Everything else gets removed
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
delete router.preloadCache[matchId];
|
|
423
|
-
});
|
|
424
|
-
},
|
|
425
|
-
loadRoute: async function loadRoute(navigateOpts, loaderOpts) {
|
|
426
|
-
if (navigateOpts === void 0) {
|
|
427
|
-
navigateOpts = router.location;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
const next = router.buildNext(navigateOpts);
|
|
431
|
-
const matches = router.matchRoutes(next.pathname, {
|
|
432
|
-
strictParseParams: true
|
|
433
|
-
});
|
|
434
|
-
await router.loadMatches(matches, {
|
|
435
|
-
preload: true,
|
|
436
|
-
maxAge: loaderOpts.maxAge
|
|
437
|
-
});
|
|
438
|
-
return matches;
|
|
439
|
-
},
|
|
440
|
-
matchRoutes: (pathname, opts) => {
|
|
441
|
-
var _router$state$pending3, _router$state$pending4;
|
|
442
|
-
|
|
443
|
-
router.cleanPreloadCache();
|
|
444
|
-
const matches = [];
|
|
445
|
-
|
|
446
|
-
if (!router.routeTree) {
|
|
447
|
-
return matches;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
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 : [])];
|
|
451
|
-
|
|
452
|
-
const recurse = async routes => {
|
|
453
|
-
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
454
|
-
|
|
455
|
-
const parentMatch = last(matches);
|
|
456
|
-
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
457
|
-
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
458
|
-
let foundRoutes = [];
|
|
459
|
-
|
|
460
|
-
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
461
|
-
routes.some(route => {
|
|
462
|
-
var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
|
|
463
|
-
|
|
464
|
-
if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
|
|
465
|
-
return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
|
|
469
|
-
const matchParams = matchPathname(pathname, {
|
|
470
|
-
to: route.fullPath,
|
|
471
|
-
fuzzy,
|
|
472
|
-
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
if (matchParams) {
|
|
476
|
-
let parsedParams;
|
|
477
|
-
|
|
478
|
-
try {
|
|
479
|
-
var _route$options$parseP;
|
|
480
|
-
|
|
481
|
-
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
482
|
-
} catch (err) {
|
|
483
|
-
if (opts != null && opts.strictParseParams) {
|
|
484
|
-
throw err;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
params = _rollupPluginBabelHelpers["extends"]({}, params, parsedParams);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
if (!!matchParams) {
|
|
492
|
-
foundRoutes = [...parentRoutes, route];
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
return !!foundRoutes.length;
|
|
496
|
-
});
|
|
497
|
-
return !!foundRoutes.length;
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
findMatchInRoutes([], filteredRoutes);
|
|
501
|
-
|
|
502
|
-
if (!foundRoutes.length) {
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
foundRoutes.forEach(foundRoute => {
|
|
507
|
-
var _router$preloadCache$;
|
|
508
|
-
|
|
509
|
-
const interpolatedPath = interpolatePath(foundRoute.routePath, params);
|
|
510
|
-
const matchId = interpolatePath(foundRoute.routeId, params, true);
|
|
511
|
-
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, foundRoute, {
|
|
512
|
-
matchId,
|
|
513
|
-
params,
|
|
514
|
-
pathname: joinPaths([pathname, interpolatedPath])
|
|
515
|
-
});
|
|
516
|
-
matches.push(match);
|
|
517
|
-
});
|
|
518
|
-
const foundRoute = last(foundRoutes);
|
|
519
|
-
|
|
520
|
-
if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
|
|
521
|
-
recurse(foundRoute.childRoutes);
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
|
|
525
|
-
recurse([router.routeTree]);
|
|
526
|
-
cascadeLoaderData(matches);
|
|
527
|
-
return matches;
|
|
528
|
-
},
|
|
529
|
-
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
530
|
-
const matchPromises = resolvedMatches.map(async match => {
|
|
531
|
-
// Validate the match (loads search params etc)
|
|
532
|
-
match.__.validate(); // If this is a preload, add it to the preload cache
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
if (loaderOpts != null && loaderOpts.preload) {
|
|
536
|
-
router.preloadCache[match.matchId] = {
|
|
537
|
-
maxAge: loaderOpts == null ? void 0 : loaderOpts.maxAge,
|
|
538
|
-
match
|
|
539
|
-
};
|
|
540
|
-
} // If the match is invalid, errored or idle, trigger it to load
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
if (match.status === 'success' && match.isInvalid || match.status === 'error' || match.status === 'idle') {
|
|
544
|
-
match.load();
|
|
545
|
-
} // If requested, start the pending timers
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending(); // Wait for the first sign of activity from the match
|
|
549
|
-
// This might be completion, error, or a pending state
|
|
550
|
-
|
|
551
|
-
await match.__.loadPromise;
|
|
552
|
-
});
|
|
553
|
-
router.notify();
|
|
554
|
-
await Promise.all(matchPromises);
|
|
555
|
-
return resolvedMatches;
|
|
556
|
-
},
|
|
557
|
-
invalidateRoute: opts => {
|
|
558
|
-
var _router$state$pending5, _router$state$pending6;
|
|
559
|
-
|
|
560
|
-
const next = router.buildNext(opts);
|
|
561
|
-
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
562
|
-
[...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 => {
|
|
563
|
-
if (unloadedMatchIds.includes(match.matchId)) {
|
|
564
|
-
match.invalidate();
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
},
|
|
568
|
-
reload: () => router._navigate({
|
|
569
|
-
fromCurrent: true,
|
|
570
|
-
replace: true,
|
|
571
|
-
search: true
|
|
572
|
-
}),
|
|
573
|
-
resolvePath: (from, path) => {
|
|
574
|
-
return _resolvePath(router.basepath, from, cleanPath(path));
|
|
575
|
-
},
|
|
576
|
-
matchRoute: (location, opts) => {
|
|
577
|
-
var _location$from;
|
|
578
|
-
|
|
579
|
-
// const location = router.buildNext(opts)
|
|
580
|
-
location = _rollupPluginBabelHelpers["extends"]({}, location, {
|
|
581
|
-
to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
|
|
582
|
-
});
|
|
583
|
-
const next = router.buildNext(location);
|
|
584
|
-
|
|
585
|
-
if (opts != null && opts.pending) {
|
|
586
|
-
var _router$state$pending7;
|
|
587
|
-
|
|
588
|
-
if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
|
|
589
|
-
return false;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
return !!matchPathname(router.state.pending.location.pathname, _rollupPluginBabelHelpers["extends"]({}, opts, {
|
|
593
|
-
to: next.pathname
|
|
594
|
-
}));
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
return !!matchPathname(router.state.location.pathname, _rollupPluginBabelHelpers["extends"]({}, opts, {
|
|
598
|
-
to: next.pathname
|
|
599
|
-
}));
|
|
600
|
-
},
|
|
601
|
-
_navigate: location => {
|
|
602
|
-
const next = router.buildNext(location);
|
|
603
|
-
return router.commitLocation(next, location.replace);
|
|
604
|
-
},
|
|
605
|
-
navigate: async _ref2 => {
|
|
606
|
-
let {
|
|
607
|
-
from,
|
|
608
|
-
to = '.',
|
|
609
|
-
search,
|
|
610
|
-
hash,
|
|
611
|
-
replace,
|
|
612
|
-
params
|
|
613
|
-
} = _ref2;
|
|
614
|
-
// If this link simply reloads the current route,
|
|
615
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
616
|
-
// If this `to` is a valid external URL, return
|
|
617
|
-
// null for LinkUtils
|
|
618
|
-
const toString = String(to);
|
|
619
|
-
const fromString = String(from);
|
|
620
|
-
let isExternal;
|
|
621
|
-
|
|
622
|
-
try {
|
|
623
|
-
new URL("" + toString);
|
|
624
|
-
isExternal = true;
|
|
625
|
-
} catch (e) {}
|
|
626
|
-
|
|
627
|
-
tinyInvariant["default"](!isExternal, 'Attempting to navigate to external url with router.navigate!');
|
|
628
|
-
return router._navigate({
|
|
629
|
-
from: fromString,
|
|
630
|
-
to: toString,
|
|
631
|
-
search,
|
|
632
|
-
hash,
|
|
633
|
-
replace,
|
|
634
|
-
params
|
|
635
|
-
});
|
|
636
|
-
},
|
|
637
|
-
buildLink: _ref3 => {
|
|
638
|
-
var _preload, _ref4, _ref5;
|
|
639
|
-
|
|
640
|
-
let {
|
|
641
|
-
from,
|
|
642
|
-
to = '.',
|
|
643
|
-
search,
|
|
644
|
-
params,
|
|
645
|
-
hash,
|
|
646
|
-
target,
|
|
647
|
-
replace,
|
|
648
|
-
activeOptions,
|
|
649
|
-
preload,
|
|
650
|
-
preloadMaxAge: userPreloadMaxAge,
|
|
651
|
-
preloadDelay: userPreloadDelay,
|
|
652
|
-
disabled
|
|
653
|
-
} = _ref3;
|
|
654
|
-
|
|
655
|
-
// If this link simply reloads the current route,
|
|
656
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
657
|
-
// If this `to` is a valid external URL, return
|
|
658
|
-
// null for LinkUtils
|
|
659
|
-
try {
|
|
660
|
-
new URL("" + to);
|
|
661
|
-
return {
|
|
662
|
-
type: 'external',
|
|
663
|
-
href: to
|
|
664
|
-
};
|
|
665
|
-
} catch (e) {}
|
|
666
|
-
|
|
667
|
-
const nextOpts = {
|
|
668
|
-
from,
|
|
669
|
-
to,
|
|
670
|
-
search,
|
|
671
|
-
params,
|
|
672
|
-
hash,
|
|
673
|
-
replace
|
|
674
|
-
};
|
|
675
|
-
const next = router.buildNext(nextOpts);
|
|
676
|
-
preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
|
|
677
|
-
const preloadMaxAge = (_ref4 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref4 : 2000;
|
|
678
|
-
const preloadDelay = (_ref5 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref5 : 50; // Compare path/hash for matches
|
|
679
|
-
|
|
680
|
-
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
681
|
-
const currentPathSplit = router.state.location.pathname.split('/');
|
|
682
|
-
const nextPathSplit = next.pathname.split('/');
|
|
683
|
-
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
684
|
-
const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
|
|
685
|
-
|
|
686
|
-
const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
|
|
687
|
-
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
|
|
688
|
-
|
|
689
|
-
const isActive = pathTest && hashTest; // The click handler
|
|
690
|
-
|
|
691
|
-
const handleClick = e => {
|
|
692
|
-
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
693
|
-
e.preventDefault();
|
|
694
|
-
|
|
695
|
-
if (pathIsEqual && !search && !hash) {
|
|
696
|
-
router.invalidateRoute(nextOpts);
|
|
697
|
-
} // All is well? Navigate!)
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
router._navigate(nextOpts);
|
|
701
|
-
}
|
|
702
|
-
}; // The click handler
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
const handleFocus = e => {
|
|
706
|
-
if (preload && preloadMaxAge > 0) {
|
|
707
|
-
router.loadRoute(nextOpts, {
|
|
708
|
-
maxAge: preloadMaxAge
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
const handleEnter = e => {
|
|
714
|
-
const target = e.target || {};
|
|
715
|
-
|
|
716
|
-
if (preload && preloadMaxAge > 0) {
|
|
717
|
-
if (target.preloadTimeout) {
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
target.preloadTimeout = setTimeout(() => {
|
|
722
|
-
target.preloadTimeout = null;
|
|
723
|
-
router.loadRoute(nextOpts, {
|
|
724
|
-
maxAge: preloadMaxAge
|
|
725
|
-
});
|
|
726
|
-
}, preloadDelay);
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
|
|
730
|
-
const handleLeave = e => {
|
|
731
|
-
const target = e.target || {};
|
|
732
|
-
|
|
733
|
-
if (target.preloadTimeout) {
|
|
734
|
-
clearTimeout(target.preloadTimeout);
|
|
735
|
-
target.preloadTimeout = null;
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
|
|
739
|
-
return {
|
|
740
|
-
type: 'internal',
|
|
741
|
-
next,
|
|
742
|
-
handleFocus,
|
|
743
|
-
handleClick,
|
|
744
|
-
handleEnter,
|
|
745
|
-
handleLeave,
|
|
746
|
-
isActive,
|
|
747
|
-
disabled
|
|
748
|
-
};
|
|
749
|
-
},
|
|
750
|
-
__experimental__createSnapshot: () => {
|
|
751
|
-
return _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
752
|
-
matches: router.state.matches.map(_ref6 => {
|
|
753
|
-
let {
|
|
754
|
-
routeLoaderData: loaderData,
|
|
755
|
-
matchId
|
|
756
|
-
} = _ref6;
|
|
757
|
-
return {
|
|
758
|
-
matchId,
|
|
759
|
-
loaderData
|
|
760
|
-
};
|
|
761
|
-
})
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
};
|
|
765
|
-
router.location = router.parseLocation(history.location); // router.state.location = __experimental__snapshot?.location ?? router.location
|
|
766
|
-
|
|
767
|
-
router.state.location = router.location;
|
|
768
|
-
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
769
|
-
|
|
770
|
-
router.options.createRouter == null ? void 0 : router.options.createRouter(router); // router.mount()
|
|
771
|
-
|
|
772
|
-
return router;
|
|
773
|
-
}
|
|
774
|
-
function createRoute(routeConfig, options, parent, router) {
|
|
775
|
-
// const id = (
|
|
776
|
-
// options.path === rootRouteId
|
|
777
|
-
// ? rootRouteId
|
|
778
|
-
// : joinPaths([
|
|
779
|
-
// parent!.id,
|
|
780
|
-
// `${options.path?.replace(/(.)\/$/, '$1')}`,
|
|
781
|
-
// ]).replace(new RegExp(`^${rootRouteId}`), '')
|
|
782
|
-
// ) as TRouteInfo['id']
|
|
783
|
-
const {
|
|
784
|
-
id,
|
|
785
|
-
routeId,
|
|
786
|
-
path: routePath,
|
|
787
|
-
fullPath
|
|
788
|
-
} = routeConfig;
|
|
789
|
-
|
|
790
|
-
const action = router.state.actions[id] || (() => {
|
|
791
|
-
router.state.actions[id] = {
|
|
792
|
-
pending: [],
|
|
793
|
-
submit: async (submission, actionOpts) => {
|
|
794
|
-
var _actionOpts$invalidat;
|
|
795
|
-
|
|
796
|
-
if (!route) {
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
|
|
801
|
-
const actionState = {
|
|
802
|
-
submittedAt: Date.now(),
|
|
803
|
-
status: 'pending',
|
|
804
|
-
submission
|
|
805
|
-
};
|
|
806
|
-
action.current = actionState;
|
|
807
|
-
action.latest = actionState;
|
|
808
|
-
action.pending.push(actionState);
|
|
809
|
-
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
810
|
-
currentAction: actionState,
|
|
811
|
-
latestAction: actionState
|
|
812
|
-
});
|
|
813
|
-
router.notify();
|
|
814
|
-
|
|
815
|
-
try {
|
|
816
|
-
const res = await (route.options.action == null ? void 0 : route.options.action(submission));
|
|
817
|
-
actionState.data = res;
|
|
818
|
-
|
|
819
|
-
if (invalidate) {
|
|
820
|
-
router.invalidateRoute({
|
|
821
|
-
to: '.',
|
|
822
|
-
fromCurrent: true
|
|
823
|
-
});
|
|
824
|
-
await router.reload();
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
actionState.status = 'success';
|
|
828
|
-
return res;
|
|
829
|
-
} catch (err) {
|
|
830
|
-
console.error(err);
|
|
831
|
-
actionState.error = err;
|
|
832
|
-
actionState.status = 'error';
|
|
833
|
-
} finally {
|
|
834
|
-
action.pending = action.pending.filter(d => d !== actionState);
|
|
835
|
-
router.removeActionQueue.push({
|
|
836
|
-
action,
|
|
837
|
-
actionState
|
|
838
|
-
});
|
|
839
|
-
router.notify();
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
};
|
|
843
|
-
return router.state.actions[id];
|
|
844
|
-
})();
|
|
845
|
-
|
|
846
|
-
let route = {
|
|
847
|
-
routeId: id,
|
|
848
|
-
routeRouteId: routeId,
|
|
849
|
-
routePath,
|
|
850
|
-
fullPath,
|
|
851
|
-
options,
|
|
852
|
-
router,
|
|
853
|
-
childRoutes: undefined,
|
|
854
|
-
parentRoute: parent,
|
|
855
|
-
action,
|
|
856
|
-
buildLink: options => {
|
|
857
|
-
return router.buildLink(_rollupPluginBabelHelpers["extends"]({}, options, {
|
|
858
|
-
from: fullPath
|
|
859
|
-
}));
|
|
860
|
-
},
|
|
861
|
-
navigate: options => {
|
|
862
|
-
return router.navigate(_rollupPluginBabelHelpers["extends"]({}, options, {
|
|
863
|
-
from: fullPath
|
|
864
|
-
}));
|
|
865
|
-
},
|
|
866
|
-
matchRoute: (matchLocation, opts) => {
|
|
867
|
-
return router.matchRoute(_rollupPluginBabelHelpers["extends"]({}, matchLocation, {
|
|
868
|
-
from: fullPath
|
|
869
|
-
}), opts);
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
router.options.createRoute == null ? void 0 : router.options.createRoute({
|
|
873
|
-
router,
|
|
874
|
-
route
|
|
875
|
-
});
|
|
876
|
-
return route;
|
|
877
|
-
}
|
|
878
|
-
function createRouteMatch(router, route, opts) {
|
|
879
|
-
const routeMatch = _rollupPluginBabelHelpers["extends"]({}, route, opts, {
|
|
880
|
-
router,
|
|
881
|
-
routeSearch: {},
|
|
882
|
-
search: {},
|
|
883
|
-
childMatches: [],
|
|
884
|
-
status: 'idle',
|
|
885
|
-
routeLoaderData: {},
|
|
886
|
-
loaderData: {},
|
|
887
|
-
isPending: false,
|
|
888
|
-
isFetching: false,
|
|
889
|
-
isInvalid: false,
|
|
890
|
-
__: {
|
|
891
|
-
abortController: new AbortController(),
|
|
892
|
-
latestId: '',
|
|
893
|
-
resolve: () => {},
|
|
894
|
-
notify: () => {
|
|
895
|
-
routeMatch.__.resolve();
|
|
896
|
-
|
|
897
|
-
routeMatch.router.notify();
|
|
898
|
-
},
|
|
899
|
-
startPending: () => {
|
|
900
|
-
var _routeMatch$options$p, _routeMatch$options$p2;
|
|
901
|
-
|
|
902
|
-
const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
|
|
903
|
-
const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
|
|
904
|
-
|
|
905
|
-
if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
|
|
906
|
-
return;
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
routeMatch.__.pendingTimeout = setTimeout(() => {
|
|
910
|
-
routeMatch.isPending = true;
|
|
911
|
-
|
|
912
|
-
routeMatch.__.resolve();
|
|
913
|
-
|
|
914
|
-
if (typeof pendingMinMs !== 'undefined') {
|
|
915
|
-
routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
|
|
916
|
-
}
|
|
917
|
-
}, pendingMs);
|
|
918
|
-
},
|
|
919
|
-
cancelPending: () => {
|
|
920
|
-
routeMatch.isPending = false;
|
|
921
|
-
clearTimeout(routeMatch.__.pendingTimeout);
|
|
922
|
-
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
923
|
-
delete routeMatch.__.pendingMinPromise;
|
|
924
|
-
},
|
|
925
|
-
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
926
|
-
// routeMatch.parentMatch = parentMatch
|
|
927
|
-
// },
|
|
928
|
-
// addChildMatch: (childMatch: RouteMatch) => {
|
|
929
|
-
// if (
|
|
930
|
-
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
931
|
-
// ) {
|
|
932
|
-
// return
|
|
933
|
-
// }
|
|
934
|
-
// routeMatch.childMatches.push(childMatch)
|
|
935
|
-
// },
|
|
936
|
-
validate: () => {
|
|
937
|
-
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
938
|
-
|
|
939
|
-
// Validate the search params and stabilize them
|
|
940
|
-
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
941
|
-
|
|
942
|
-
try {
|
|
943
|
-
const prevSearch = routeMatch.routeSearch;
|
|
944
|
-
let nextSearch = replaceEqualDeep(prevSearch, routeMatch.options.validateSearch == null ? void 0 : routeMatch.options.validateSearch(parentSearch)); // Invalidate route matches when search param stability changes
|
|
945
|
-
|
|
946
|
-
if (prevSearch !== nextSearch) {
|
|
947
|
-
routeMatch.isInvalid = true;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
routeMatch.routeSearch = nextSearch;
|
|
951
|
-
routeMatch.search = replaceEqualDeep(parentSearch, _rollupPluginBabelHelpers["extends"]({}, parentSearch, nextSearch));
|
|
952
|
-
} catch (err) {
|
|
953
|
-
console.error(err);
|
|
954
|
-
const error = new Error('Invalid search params found', {
|
|
955
|
-
cause: err
|
|
956
|
-
});
|
|
957
|
-
error.code = 'INVALID_SEARCH_PARAMS';
|
|
958
|
-
routeMatch.status = 'error';
|
|
959
|
-
routeMatch.error = error; // Do not proceed with loading the route
|
|
960
|
-
|
|
961
|
-
return;
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
},
|
|
965
|
-
cancel: () => {
|
|
966
|
-
var _routeMatch$__$abortC;
|
|
967
|
-
|
|
968
|
-
(_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
|
|
969
|
-
|
|
970
|
-
routeMatch.__.cancelPending();
|
|
971
|
-
},
|
|
972
|
-
invalidate: () => {
|
|
973
|
-
routeMatch.isInvalid = true;
|
|
974
|
-
},
|
|
975
|
-
load: async () => {
|
|
976
|
-
const id = '' + Date.now() + Math.random();
|
|
977
|
-
routeMatch.__.latestId = id; // If the match was in an error state, set it
|
|
978
|
-
// to a loading state again. Otherwise, keep it
|
|
979
|
-
// as loading or resolved
|
|
980
|
-
|
|
981
|
-
if (routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
982
|
-
routeMatch.status = 'loading';
|
|
983
|
-
} // We started loading the route, so it's no longer invalid
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
routeMatch.isInvalid = false;
|
|
987
|
-
routeMatch.__.loadPromise = new Promise(async resolve => {
|
|
988
|
-
// We are now fetching, even if it's in the background of a
|
|
989
|
-
// resolved state
|
|
990
|
-
routeMatch.isFetching = true;
|
|
991
|
-
routeMatch.__.resolve = resolve;
|
|
992
|
-
|
|
993
|
-
const loaderPromise = (async () => {
|
|
994
|
-
const importer = routeMatch.options.import; // First, run any importers
|
|
995
|
-
|
|
996
|
-
if (importer) {
|
|
997
|
-
routeMatch.__.importPromise = importer({
|
|
998
|
-
params: routeMatch.params // search: routeMatch.search,
|
|
999
|
-
|
|
1000
|
-
}).then(imported => {
|
|
1001
|
-
routeMatch.__ = _rollupPluginBabelHelpers["extends"]({}, routeMatch.__, imported);
|
|
1002
|
-
});
|
|
1003
|
-
} // Wait for the importer to finish before
|
|
1004
|
-
// attempting to load elements and data
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
await routeMatch.__.importPromise; // Next, load the elements and data in parallel
|
|
1008
|
-
|
|
1009
|
-
routeMatch.__.elementsPromise = (async () => {
|
|
1010
|
-
// then run all element and data loaders in parallel
|
|
1011
|
-
// For each element type, potentially load it asynchronously
|
|
1012
|
-
const elementTypes = ['element', 'errorElement', 'catchElement', 'pendingElement'];
|
|
1013
|
-
await Promise.all(elementTypes.map(async type => {
|
|
1014
|
-
const routeElement = routeMatch.options[type];
|
|
1015
|
-
|
|
1016
|
-
if (routeMatch.__[type]) {
|
|
1017
|
-
return;
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
if (typeof routeElement === 'function') {
|
|
1021
|
-
const res = await routeElement(routeMatch);
|
|
1022
|
-
routeMatch.__[type] = res;
|
|
1023
|
-
} else {
|
|
1024
|
-
routeMatch.__[type] = routeMatch.options[type];
|
|
1025
|
-
}
|
|
1026
|
-
}));
|
|
1027
|
-
})();
|
|
1028
|
-
|
|
1029
|
-
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1030
|
-
try {
|
|
1031
|
-
const data = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
|
|
1032
|
-
params: routeMatch.params,
|
|
1033
|
-
search: routeMatch.routeSearch,
|
|
1034
|
-
signal: routeMatch.__.abortController.signal
|
|
1035
|
-
}));
|
|
1036
|
-
|
|
1037
|
-
if (id !== routeMatch.__.latestId) {
|
|
1038
|
-
return routeMatch.__.loaderPromise;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1042
|
-
routeMatch.error = undefined;
|
|
1043
|
-
routeMatch.status = 'success';
|
|
1044
|
-
routeMatch.updatedAt = Date.now();
|
|
1045
|
-
} catch (err) {
|
|
1046
|
-
if (id !== routeMatch.__.latestId) {
|
|
1047
|
-
return routeMatch.__.loaderPromise;
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1051
|
-
console.error(err);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
routeMatch.error = err;
|
|
1055
|
-
routeMatch.status = 'error';
|
|
1056
|
-
routeMatch.updatedAt = Date.now();
|
|
1057
|
-
}
|
|
1058
|
-
});
|
|
1059
|
-
|
|
1060
|
-
try {
|
|
1061
|
-
await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
|
|
1062
|
-
|
|
1063
|
-
if (id !== routeMatch.__.latestId) {
|
|
1064
|
-
return routeMatch.__.loaderPromise;
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
if (routeMatch.__.pendingMinPromise) {
|
|
1068
|
-
await routeMatch.__.pendingMinPromise;
|
|
1069
|
-
delete routeMatch.__.pendingMinPromise;
|
|
1070
|
-
}
|
|
1071
|
-
} finally {
|
|
1072
|
-
if (id !== routeMatch.__.latestId) {
|
|
1073
|
-
return routeMatch.__.loaderPromise;
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
routeMatch.__.cancelPending();
|
|
1077
|
-
|
|
1078
|
-
routeMatch.isPending = false;
|
|
1079
|
-
routeMatch.isFetching = false;
|
|
1080
|
-
|
|
1081
|
-
routeMatch.__.notify();
|
|
1082
|
-
}
|
|
1083
|
-
})();
|
|
1084
|
-
|
|
1085
|
-
routeMatch.__.loaderPromise = loaderPromise;
|
|
1086
|
-
await loaderPromise;
|
|
1087
|
-
|
|
1088
|
-
if (id !== routeMatch.__.latestId) {
|
|
1089
|
-
return routeMatch.__.loaderPromise;
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
delete routeMatch.__.loaderPromise;
|
|
1093
|
-
});
|
|
1094
|
-
return await routeMatch.__.loadPromise;
|
|
1095
|
-
}
|
|
1096
|
-
});
|
|
1097
|
-
|
|
1098
|
-
return routeMatch;
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
function cascadeLoaderData(matches) {
|
|
1102
|
-
matches.forEach((match, index) => {
|
|
1103
|
-
const parent = matches[index - 1];
|
|
1104
|
-
|
|
1105
|
-
if (parent) {
|
|
1106
|
-
match.loaderData = replaceEqualDeep(match.loaderData, _rollupPluginBabelHelpers["extends"]({}, parent.loaderData, match.routeLoaderData));
|
|
1107
|
-
}
|
|
1108
|
-
});
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
function matchPathname(currentPathname, matchLocation) {
|
|
1112
|
-
const pathParams = matchByPath(currentPathname, matchLocation); // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
|
|
1113
|
-
|
|
1114
|
-
if (matchLocation.to && !pathParams) {
|
|
1115
|
-
return;
|
|
1116
|
-
} // if (matchLocation.search && !searchMatched) {
|
|
1117
|
-
// return
|
|
1118
|
-
// }
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
return pathParams != null ? pathParams : {};
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
function interpolatePath(path, params, leaveWildcard) {
|
|
1125
|
-
const interpolatedPathSegments = parsePathname(path);
|
|
1126
|
-
return joinPaths(interpolatedPathSegments.map(segment => {
|
|
1127
|
-
if (segment.value === '*' && !leaveWildcard) {
|
|
1128
|
-
return '';
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
if (segment.type === 'param') {
|
|
1132
|
-
var _segment$value$substr;
|
|
1133
|
-
|
|
1134
|
-
return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
return segment.value;
|
|
1138
|
-
}));
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
function warning(cond, message) {
|
|
1142
|
-
if (cond) {
|
|
1143
|
-
if (typeof console !== 'undefined') console.warn(message);
|
|
1144
|
-
|
|
1145
|
-
try {
|
|
1146
|
-
throw new Error(message);
|
|
1147
|
-
} catch (_unused) {}
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
return true;
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
function isFunction(d) {
|
|
1154
|
-
return typeof d === 'function';
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
function functionalUpdate(updater, previous) {
|
|
1158
|
-
if (isFunction(updater)) {
|
|
1159
|
-
return updater(previous);
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
return updater;
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
function joinPaths(paths) {
|
|
1166
|
-
return cleanPath(paths.filter(Boolean).join('/'));
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
function cleanPath(path) {
|
|
1170
|
-
// remove double slashes
|
|
1171
|
-
return path.replace(/\/{2,}/g, '/');
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
function trimPathLeft(path) {
|
|
1175
|
-
return path === '/' ? path : path.replace(/^\/{1,}/, '');
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
function trimPathRight(path) {
|
|
1179
|
-
return path === '/' ? path : path.replace(/\/{1,}$/, '');
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
function trimPath(path) {
|
|
1183
|
-
return trimPathRight(trimPathLeft(path));
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
function matchByPath(from, matchLocation) {
|
|
1187
|
-
var _matchLocation$to;
|
|
1188
|
-
|
|
1189
|
-
const baseSegments = parsePathname(from);
|
|
1190
|
-
const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
|
|
1191
|
-
const params = {};
|
|
1192
|
-
|
|
1193
|
-
let isMatch = (() => {
|
|
1194
|
-
for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
|
|
1195
|
-
const baseSegment = baseSegments[i];
|
|
1196
|
-
const routeSegment = routeSegments[i];
|
|
1197
|
-
const isLastRouteSegment = i === routeSegments.length - 1;
|
|
1198
|
-
const isLastBaseSegment = i === baseSegments.length - 1;
|
|
1199
|
-
|
|
1200
|
-
if (routeSegment) {
|
|
1201
|
-
if (routeSegment.type === 'wildcard') {
|
|
1202
|
-
if (baseSegment != null && baseSegment.value) {
|
|
1203
|
-
params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
|
|
1204
|
-
return true;
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
return false;
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
if (routeSegment.type === 'pathname') {
|
|
1211
|
-
if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
|
|
1212
|
-
return true;
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
if (baseSegment) {
|
|
1216
|
-
if (matchLocation.caseSensitive) {
|
|
1217
|
-
if (routeSegment.value !== baseSegment.value) {
|
|
1218
|
-
return false;
|
|
1219
|
-
}
|
|
1220
|
-
} else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
|
|
1221
|
-
return false;
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
if (!baseSegment) {
|
|
1227
|
-
return false;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
if (routeSegment.type === 'param') {
|
|
1231
|
-
if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
|
|
1232
|
-
return false;
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
if (!baseSegment.value.startsWith(':')) {
|
|
1236
|
-
params[routeSegment.value.substring(1)] = baseSegment.value;
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
if (isLastRouteSegment && !isLastBaseSegment) {
|
|
1242
|
-
return !!matchLocation.fuzzy;
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
return true;
|
|
1247
|
-
})();
|
|
1248
|
-
|
|
1249
|
-
return isMatch ? params : undefined;
|
|
1250
|
-
} // function matchBySearch(
|
|
1251
|
-
// search: SearchSchema,
|
|
1252
|
-
// matchLocation: MatchLocation,
|
|
1253
|
-
// ) {
|
|
1254
|
-
// return !!(matchLocation.search && matchLocation.search(search))
|
|
1255
|
-
// }
|
|
1256
|
-
|
|
1257
|
-
function parsePathname(pathname) {
|
|
1258
|
-
if (!pathname) {
|
|
1259
|
-
return [];
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
pathname = cleanPath(pathname);
|
|
1263
|
-
const segments = [];
|
|
1264
|
-
|
|
1265
|
-
if (pathname.slice(0, 1) === '/') {
|
|
1266
|
-
pathname = pathname.substring(1);
|
|
1267
|
-
segments.push({
|
|
1268
|
-
type: 'pathname',
|
|
1269
|
-
value: '/'
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
if (!pathname) {
|
|
1274
|
-
return segments;
|
|
1275
|
-
} // Remove empty segments and '.' segments
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
const split = pathname.split('/').filter(Boolean);
|
|
1279
|
-
segments.push(...split.map(part => {
|
|
1280
|
-
if (part.startsWith('*')) {
|
|
1281
|
-
return {
|
|
1282
|
-
type: 'wildcard',
|
|
1283
|
-
value: part
|
|
1284
|
-
};
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
if (part.charAt(0) === ':') {
|
|
1288
|
-
return {
|
|
1289
|
-
type: 'param',
|
|
1290
|
-
value: part
|
|
1291
|
-
};
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
return {
|
|
1295
|
-
type: 'pathname',
|
|
1296
|
-
value: part
|
|
1297
|
-
};
|
|
1298
|
-
}));
|
|
1299
|
-
|
|
1300
|
-
if (pathname.slice(-1) === '/') {
|
|
1301
|
-
pathname = pathname.substring(1);
|
|
1302
|
-
segments.push({
|
|
1303
|
-
type: 'pathname',
|
|
1304
|
-
value: '/'
|
|
1305
|
-
});
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
return segments;
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
function _resolvePath(basepath, base, to) {
|
|
1312
|
-
base = base.replace(new RegExp("^" + basepath), '/');
|
|
1313
|
-
to = to.replace(new RegExp("^" + basepath), '/');
|
|
1314
|
-
let baseSegments = parsePathname(base);
|
|
1315
|
-
const toSegments = parsePathname(to);
|
|
1316
|
-
toSegments.forEach((toSegment, index) => {
|
|
1317
|
-
if (toSegment.value === '/') {
|
|
1318
|
-
if (!index) {
|
|
1319
|
-
// Leading slash
|
|
1320
|
-
baseSegments = [toSegment];
|
|
1321
|
-
} else if (index === toSegments.length - 1) {
|
|
1322
|
-
// Trailing Slash
|
|
1323
|
-
baseSegments.push(toSegment);
|
|
1324
|
-
} else ;
|
|
1325
|
-
} else if (toSegment.value === '..') {
|
|
1326
|
-
var _last2;
|
|
1327
|
-
|
|
1328
|
-
// Extra trailing slash? pop it off
|
|
1329
|
-
if (baseSegments.length > 1 && ((_last2 = last(baseSegments)) == null ? void 0 : _last2.value) === '/') {
|
|
1330
|
-
baseSegments.pop();
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
baseSegments.pop();
|
|
1334
|
-
} else if (toSegment.value === '.') {
|
|
1335
|
-
return;
|
|
1336
|
-
} else {
|
|
1337
|
-
baseSegments.push(toSegment);
|
|
1338
|
-
}
|
|
1339
|
-
});
|
|
1340
|
-
const joined = joinPaths([basepath, ...baseSegments.map(d => d.value)]);
|
|
1341
|
-
return cleanPath(joined);
|
|
1342
|
-
}
|
|
1343
|
-
function replaceEqualDeep(prev, next) {
|
|
1344
|
-
if (prev === next) {
|
|
1345
|
-
return prev;
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
const array = Array.isArray(prev) && Array.isArray(next);
|
|
1349
|
-
|
|
1350
|
-
if (array || isPlainObject(prev) && isPlainObject(next)) {
|
|
1351
|
-
const aSize = array ? prev.length : Object.keys(prev).length;
|
|
1352
|
-
const bItems = array ? next : Object.keys(next);
|
|
1353
|
-
const bSize = bItems.length;
|
|
1354
|
-
const copy = array ? [] : {};
|
|
1355
|
-
let equalItems = 0;
|
|
1356
|
-
|
|
1357
|
-
for (let i = 0; i < bSize; i++) {
|
|
1358
|
-
const key = array ? i : bItems[i];
|
|
1359
|
-
copy[key] = replaceEqualDeep(prev[key], next[key]);
|
|
1360
|
-
|
|
1361
|
-
if (copy[key] === prev[key]) {
|
|
1362
|
-
equalItems++;
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
|
-
return aSize === bSize && equalItems === aSize ? prev : copy;
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
return next;
|
|
1370
|
-
} // Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
1371
|
-
|
|
1372
|
-
function isPlainObject(o) {
|
|
1373
|
-
if (!hasObjectPrototype(o)) {
|
|
1374
|
-
return false;
|
|
1375
|
-
} // If has modified constructor
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
const ctor = o.constructor;
|
|
1379
|
-
|
|
1380
|
-
if (typeof ctor === 'undefined') {
|
|
1381
|
-
return true;
|
|
1382
|
-
} // If has modified prototype
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
const prot = ctor.prototype;
|
|
1386
|
-
|
|
1387
|
-
if (!hasObjectPrototype(prot)) {
|
|
1388
|
-
return false;
|
|
1389
|
-
} // If constructor does not have an Object-specific method
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
1393
|
-
return false;
|
|
1394
|
-
} // Most likely a plain Object
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
return true;
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
function hasObjectPrototype(o) {
|
|
1401
|
-
return Object.prototype.toString.call(o) === '[object Object]';
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
const defaultParseSearch = parseSearchWith(JSON.parse);
|
|
1405
|
-
const defaultStringifySearch = stringifySearchWith(JSON.stringify);
|
|
1406
|
-
function parseSearchWith(parser) {
|
|
1407
|
-
return searchStr => {
|
|
1408
|
-
if (searchStr.substring(0, 1) === '?') {
|
|
1409
|
-
searchStr = searchStr.substring(1);
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
let query = qss.decode(searchStr); // Try to parse any query params that might be json
|
|
1413
|
-
|
|
1414
|
-
for (let key in query) {
|
|
1415
|
-
const value = query[key];
|
|
1416
|
-
|
|
1417
|
-
if (typeof value === 'string') {
|
|
1418
|
-
try {
|
|
1419
|
-
query[key] = parser(value);
|
|
1420
|
-
} catch (err) {//
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
return query;
|
|
1426
|
-
};
|
|
1427
|
-
}
|
|
1428
|
-
function stringifySearchWith(stringify) {
|
|
1429
|
-
return search => {
|
|
1430
|
-
search = _rollupPluginBabelHelpers["extends"]({}, search);
|
|
1431
|
-
|
|
1432
|
-
if (search) {
|
|
1433
|
-
Object.keys(search).forEach(key => {
|
|
1434
|
-
const val = search[key];
|
|
1435
|
-
|
|
1436
|
-
if (typeof val === 'undefined' || val === undefined) {
|
|
1437
|
-
delete search[key];
|
|
1438
|
-
} else if (val && typeof val === 'object' && val !== null) {
|
|
1439
|
-
try {
|
|
1440
|
-
search[key] = stringify(val);
|
|
1441
|
-
} catch (err) {// silent
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
});
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
const searchStr = qss.encode(search).toString();
|
|
1448
|
-
return searchStr ? "?" + searchStr : '';
|
|
1449
|
-
};
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
function isCtrlEvent(e) {
|
|
1453
|
-
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
function last(arr) {
|
|
1457
|
-
return arr[arr.length - 1];
|
|
1458
|
-
}
|
|
1459
27
|
|
|
1460
28
|
exports.createBrowserHistory = index.createBrowserHistory;
|
|
1461
29
|
exports.createHashHistory = index.createHashHistory;
|
|
1462
30
|
exports.createMemoryHistory = index.createMemoryHistory;
|
|
1463
31
|
exports.invariant = tinyInvariant["default"];
|
|
1464
|
-
exports.
|
|
1465
|
-
exports.
|
|
1466
|
-
exports.
|
|
1467
|
-
exports.
|
|
1468
|
-
exports.
|
|
1469
|
-
exports.
|
|
1470
|
-
exports.
|
|
1471
|
-
exports.
|
|
1472
|
-
exports.
|
|
1473
|
-
exports.
|
|
1474
|
-
exports.
|
|
1475
|
-
exports.
|
|
1476
|
-
exports.
|
|
1477
|
-
exports.
|
|
1478
|
-
exports.
|
|
1479
|
-
exports.
|
|
1480
|
-
exports.
|
|
32
|
+
exports.cleanPath = path.cleanPath;
|
|
33
|
+
exports.interpolatePath = path.interpolatePath;
|
|
34
|
+
exports.joinPaths = path.joinPaths;
|
|
35
|
+
exports.matchByPath = path.matchByPath;
|
|
36
|
+
exports.matchPathname = path.matchPathname;
|
|
37
|
+
exports.parsePathname = path.parsePathname;
|
|
38
|
+
exports.resolvePath = path.resolvePath;
|
|
39
|
+
exports.trimPath = path.trimPath;
|
|
40
|
+
exports.trimPathLeft = path.trimPathLeft;
|
|
41
|
+
exports.trimPathRight = path.trimPathRight;
|
|
42
|
+
exports.decode = qss.decode;
|
|
43
|
+
exports.encode = qss.encode;
|
|
44
|
+
exports.cascadeLoaderData = route.cascadeLoaderData;
|
|
45
|
+
exports.createRoute = route.createRoute;
|
|
46
|
+
exports.createRouteConfig = routeConfig.createRouteConfig;
|
|
47
|
+
exports.rootRouteId = routeConfig.rootRouteId;
|
|
48
|
+
exports.createRouteMatch = routeMatch.createRouteMatch;
|
|
49
|
+
exports.createRouter = router.createRouter;
|
|
50
|
+
exports.defaultParseSearch = searchParams.defaultParseSearch;
|
|
51
|
+
exports.defaultStringifySearch = searchParams.defaultStringifySearch;
|
|
52
|
+
exports.parseSearchWith = searchParams.parseSearchWith;
|
|
53
|
+
exports.stringifySearchWith = searchParams.stringifySearchWith;
|
|
54
|
+
exports.functionalUpdate = utils.functionalUpdate;
|
|
55
|
+
exports.last = utils.last;
|
|
56
|
+
exports.replaceEqualDeep = utils.replaceEqualDeep;
|
|
57
|
+
exports.warning = utils.warning;
|
|
1481
58
|
//# sourceMappingURL=index.js.map
|