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