@tanstack/router-core 0.0.1-beta.8 → 1.20.3-alpha.1

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