clear-react-router 2.2.3 → 2.2.4

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 (44) hide show
  1. package/package.json +1 -1
  2. package/dist/components/Link.d.ts +0 -23
  3. package/dist/components/Router.d.ts +0 -2
  4. package/dist/components/Spinner.d.ts +0 -1
  5. package/dist/config/routerConfig.d.ts +0 -18
  6. package/dist/constants.d.ts +0 -5
  7. package/dist/create.d.ts +0 -10
  8. package/dist/creators/createRouter.d.ts +0 -2
  9. package/dist/creators/createRouterInstance.d.ts +0 -2
  10. package/dist/hooks/useAction.d.ts +0 -4
  11. package/dist/hooks/useApplyCustomAnimation.d.ts +0 -1
  12. package/dist/hooks/useBlocker.d.ts +0 -13
  13. package/dist/hooks/useInvalidate.d.ts +0 -1
  14. package/dist/hooks/useIsDataLoading.d.ts +0 -1
  15. package/dist/hooks/useIsRoutePending.d.ts +0 -1
  16. package/dist/hooks/useLoaderState.d.ts +0 -1
  17. package/dist/hooks/useLocation.d.ts +0 -1
  18. package/dist/hooks/useNavigate.d.ts +0 -1
  19. package/dist/hooks/useNavigation.d.ts +0 -1
  20. package/dist/hooks/useParams.d.ts +0 -1
  21. package/dist/hooks/usePreserveScroll.d.ts +0 -2
  22. package/dist/hooks/useReload.d.ts +0 -1
  23. package/dist/hooks/useRouterContext.d.ts +0 -4
  24. package/dist/hooks/useSearch.d.ts +0 -1
  25. package/dist/hooks/useSearchParams.d.ts +0 -10
  26. package/dist/hooks/useSetInitialContext.d.ts +0 -2
  27. package/dist/hooks/useSetRouterConfig.d.ts +0 -2
  28. package/dist/hooks/useSubmitAction.d.ts +0 -17
  29. package/dist/index.d.ts +0 -16
  30. package/dist/index.js +0 -1168
  31. package/dist/instance.d.ts +0 -1
  32. package/dist/runtime/invalidate.d.ts +0 -2
  33. package/dist/runtime/navigate.d.ts +0 -2
  34. package/dist/runtime/prefetch.d.ts +0 -2
  35. package/dist/runtime/revalidateCache.d.ts +0 -2
  36. package/dist/types.d.ts +0 -180
  37. package/dist/utils/commitNavigation.d.ts +0 -1
  38. package/dist/utils/commitState.d.ts +0 -8
  39. package/dist/utils/createLazyComponent.d.ts +0 -9
  40. package/dist/utils/findRoute.d.ts +0 -2
  41. package/dist/utils/isCacheItemFresh.d.ts +0 -2
  42. package/dist/utils/lazy.d.ts +0 -5
  43. package/dist/utils/renderElement.d.ts +0 -2
  44. package/dist/utils/utils.d.ts +0 -18
package/dist/index.js DELETED
@@ -1,1168 +0,0 @@
1
- import { Suspense, lazy as lazy$1, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
2
- //#region \0rolldown/runtime.js
3
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
4
- //#endregion
5
- //#region create.ts
6
- var create = (initialState) => {
7
- let state = initialState;
8
- const subscribers = /* @__PURE__ */ new Set();
9
- const getState = () => state;
10
- const setState = (action) => {
11
- const prevState = state;
12
- const nextState = typeof action === "function" ? action(state) : action;
13
- if (!Object.is(state, nextState)) {
14
- state = nextState;
15
- subscribers.forEach((listener) => listener(state, prevState));
16
- }
17
- };
18
- const subscribe = (listener) => {
19
- subscribers.add(listener);
20
- return () => subscribers.delete(listener);
21
- };
22
- return {
23
- subscribe,
24
- getState,
25
- setState
26
- };
27
- };
28
- var useGlobalState = ({ subscribe, getState, setState }) => {
29
- return [useSyncExternalStore(subscribe, getState), setState];
30
- };
31
- //#endregion
32
- //#region utils/commitState.ts
33
- var createCommitState = ({ loaderState, routeItemDataState }) => ({ routeItem, loaderStateValue, location }) => {
34
- const isError = loaderStateValue.loaderError || loaderStateValue.beforeLoadError;
35
- routeItemDataState.setState({
36
- routeItem,
37
- location,
38
- status: isError ? "error" : "active"
39
- });
40
- loaderState.setState(loaderStateValue);
41
- if ((location.search ? `${location.pathname}${location.search}` : location.pathname) === window.location.pathname + window.location.search) return;
42
- history.pushState(null, "", `${location.pathname}${location.search}`);
43
- };
44
- //#endregion
45
- //#region constants.ts
46
- var EMPTY_LOADER_STATE = {};
47
- var WINDOW_TOP = "__window_top__";
48
- var WINDOW_LEFT = "__window_left__";
49
- //#endregion
50
- //#region \0@oxc-project+runtime@0.132.0/helpers/typeof.js
51
- function _typeof(o) {
52
- "@babel/helpers - typeof";
53
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
54
- return typeof o;
55
- } : function(o) {
56
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
57
- }, _typeof(o);
58
- }
59
- //#endregion
60
- //#region \0@oxc-project+runtime@0.132.0/helpers/toPrimitive.js
61
- function toPrimitive(t, r) {
62
- if ("object" != _typeof(t) || !t) return t;
63
- var e = t[Symbol.toPrimitive];
64
- if (void 0 !== e) {
65
- var i = e.call(t, r || "default");
66
- if ("object" != _typeof(i)) return i;
67
- throw new TypeError("@@toPrimitive must return a primitive value.");
68
- }
69
- return ("string" === r ? String : Number)(t);
70
- }
71
- //#endregion
72
- //#region \0@oxc-project+runtime@0.132.0/helpers/toPropertyKey.js
73
- function toPropertyKey(t) {
74
- var i = toPrimitive(t, "string");
75
- return "symbol" == _typeof(i) ? i : i + "";
76
- }
77
- //#endregion
78
- //#region \0@oxc-project+runtime@0.132.0/helpers/defineProperty.js
79
- function _defineProperty(e, r, t) {
80
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
81
- value: t,
82
- enumerable: !0,
83
- configurable: !0,
84
- writable: !0
85
- }) : e[r] = t, e;
86
- }
87
- //#endregion
88
- //#region config/routerConfig.ts
89
- var RouterConfig = class {
90
- constructor() {
91
- _defineProperty(this, "routes", []);
92
- _defineProperty(this, "maxCacheSize", 0);
93
- _defineProperty(this, "defaultPrefetch", "hover");
94
- _defineProperty(this, "isAnimated", false);
95
- _defineProperty(this, "revalidateOnFocus", false);
96
- _defineProperty(this, "revalidateOnReconnect", false);
97
- _defineProperty(this, "defaultHoverPrefetchDelay", 150);
98
- _defineProperty(this, "defaultBeforeLoad", void 0);
99
- _defineProperty(this, "defaultAfterLoad", void 0);
100
- _defineProperty(this, "defaultRetry", void 0);
101
- _defineProperty(this, "defaultStaleTime", void 0);
102
- _defineProperty(this, "defaultMinLoaderDuration", void 0);
103
- }
104
- configure(config) {
105
- Object.assign(this, config);
106
- }
107
- };
108
- var routerConfig = new RouterConfig();
109
- //#endregion
110
- //#region utils/commitNavigation.ts
111
- var commitNavigation = (callback, isCommited) => {
112
- if (!routerConfig.isAnimated || isCommited) return callback();
113
- try {
114
- const transition = document.startViewTransition(callback);
115
- transition.ready.catch(() => {});
116
- transition.finished.catch(() => {});
117
- } catch {
118
- callback();
119
- }
120
- };
121
- //#endregion
122
- //#region utils/isCacheItemFresh.ts
123
- var createIsCacheItemFresh = (loaderMap) => (path) => {
124
- const item = loaderMap.get(path);
125
- if (item === void 0) return false;
126
- const resolvedStaleTime = item.staleTime ?? routerConfig.defaultStaleTime;
127
- if (resolvedStaleTime === void 0) return true;
128
- return Date.now() - item.timestamp <= resolvedStaleTime;
129
- };
130
- //#endregion
131
- //#region utils/utils.ts
132
- var getParams = (location, routeItem) => {
133
- if (!routeItem) return {};
134
- const pathnameSegments = location.pathname.split("/");
135
- return routeItem.pattern.split("/").reduce((acc, segment, index) => {
136
- if (segment.startsWith(":")) acc[segment.slice(1)] = pathnameSegments[index];
137
- return acc;
138
- }, {});
139
- };
140
- var parseWindowLocation = (location) => ({
141
- pathname: location.pathname,
142
- search: location.search
143
- });
144
- var comparePaths = (route, pathname) => {
145
- const pattern = route.pattern.split("/").filter(Boolean);
146
- const current = pathname.split("/").filter(Boolean);
147
- return pattern.length === current.length ? pattern.every((segment, index) => segment.startsWith(":") || segment === current[index]) : false;
148
- };
149
- var isMobile = () => {
150
- const hasCoarsePointer = window.matchMedia("(pointer: coarse)").matches;
151
- const isSmallScreen = window.matchMedia("(max-width: 768px)").matches;
152
- return hasCoarsePointer && isSmallScreen;
153
- };
154
- var sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms));
155
- var getPartialLoaderArgs = (contextState, location, routeItem) => {
156
- return {
157
- params: getParams(location, routeItem),
158
- context: contextState.getState(),
159
- setContext: contextState.setState,
160
- searchParams: Object.fromEntries(new URLSearchParams(location.search).entries()),
161
- location
162
- };
163
- };
164
- var isVerticalScroll = (el) => !!el && el.scrollHeight > el.clientHeight;
165
- var updateScrollMap = (routeItemDataState, scrollMapState) => {
166
- const { routeItem, location: { pathname } } = routeItemDataState.getState();
167
- scrollMapState.setState((prevState) => {
168
- if (Array.isArray(routeItem?.scrollRestoration)) return {
169
- ...prevState,
170
- [pathname]: routeItem.scrollRestoration.map((key) => {
171
- const el = document.getElementById(key);
172
- return [key, isVerticalScroll(el) ? el?.scrollTop || 0 : el?.scrollLeft || 0];
173
- })
174
- };
175
- const scrollingElement = document.scrollingElement;
176
- const top = scrollingElement?.scrollTop ?? 0;
177
- const left = scrollingElement?.scrollLeft ?? 0;
178
- const entries = [];
179
- if (top) entries.push([WINDOW_TOP, top]);
180
- if (left) entries.push([WINDOW_LEFT, left]);
181
- if (!entries.length) return prevState;
182
- const prevEntries = prevState[pathname];
183
- if (prevEntries && JSON.stringify(prevEntries) === JSON.stringify(entries)) return prevState;
184
- return {
185
- ...prevState,
186
- [pathname]: entries
187
- };
188
- });
189
- };
190
- var restoreScroll = (scrollMap, pathname, behavior) => {
191
- scrollMap[pathname].forEach(([key, scrollPosition]) => {
192
- if (key === "__window_top__" || key === "__window_left__") {
193
- requestAnimationFrame(() => {
194
- window.scrollTo({
195
- [key === "__window_top__" ? "top" : "left"]: scrollPosition,
196
- behavior
197
- });
198
- });
199
- return;
200
- }
201
- const element = document.getElementById(key);
202
- if (!element) return;
203
- const axis = isVerticalScroll(element) ? "top" : "left";
204
- requestAnimationFrame(() => {
205
- element.scrollTo({
206
- [axis]: scrollPosition,
207
- behavior
208
- });
209
- });
210
- });
211
- };
212
- var formatSearchObject = (searchObject) => {
213
- const params = new URLSearchParams();
214
- Object.entries(searchObject).forEach(([key, value]) => {
215
- if (value !== void 0 && value !== null) params.set(key, String(value));
216
- });
217
- const result = params.toString();
218
- return result ? `?${result}` : "";
219
- };
220
- var findRoute = (pathname, includeAll) => {
221
- if (includeAll) return routerConfig.routes.find((el) => el.path === "*" || comparePaths(el, pathname));
222
- return routerConfig.routes.find((el) => comparePaths(el, pathname));
223
- };
224
- //#endregion
225
- //#region runtime/navigate.ts
226
- var createNavigate = (routerState, revalidateCache) => {
227
- let navigationSeq = 0;
228
- let interval = 0;
229
- let abortController = null;
230
- const { loaderState, contextState, loaderMap, routeItemDataState, scrollMapState, blockerState, blockedTargetState } = routerState;
231
- const commitState = createCommitState(routerState);
232
- const isCacheItemFresh = createIsCacheItemFresh(loaderMap);
233
- const createSignal = () => {
234
- abortController?.abort();
235
- abortController = new AbortController();
236
- return abortController.signal;
237
- };
238
- const getPath = (nextLocation) => `${nextLocation.pathname}${nextLocation.search}`;
239
- const routeResolve = (location) => {
240
- const nextItem = findRoute(location.pathname, true);
241
- return {
242
- nextItem,
243
- params: getParams(location, nextItem)
244
- };
245
- };
246
- const beforeLoad = async (routeItem, nextLocation) => {
247
- const { defaultBeforeLoad } = routerConfig;
248
- const runBeforeLoad = async (loaderFn) => {
249
- const redirect = async (redirected) => {
250
- const { location } = routeItemDataState.getState();
251
- const prevLocation = {
252
- pathname: location.pathname,
253
- search: location.search
254
- };
255
- return await navigate(typeof redirected === "string" ? {
256
- pathname: redirected,
257
- prevLocation
258
- } : {
259
- ...redirected,
260
- prevLocation
261
- });
262
- };
263
- try {
264
- await loaderFn({
265
- redirect,
266
- ...getPartialLoaderArgs(contextState, nextLocation, routeItem)
267
- });
268
- return null;
269
- } catch (error) {
270
- return error;
271
- }
272
- };
273
- let error = null;
274
- if (defaultBeforeLoad) error = await runBeforeLoad(defaultBeforeLoad);
275
- if (routeItem?.beforeLoad && !error) error = await runBeforeLoad(routeItem?.beforeLoad);
276
- return error;
277
- };
278
- const createGcTimeout = () => {
279
- const { routeItem, location } = routeItemDataState.getState();
280
- if (!routeItem?.gcTime) return;
281
- const path = `${location.pathname}${location.search}`;
282
- const currentLoaderEntry = loaderMap.get(path);
283
- if (!currentLoaderEntry) return;
284
- if (currentLoaderEntry.gcTimeout) window.clearTimeout(currentLoaderEntry?.gcTimeout);
285
- const gcTimeout = window.setTimeout(() => loaderMap.delete(path), routeItem.gcTime);
286
- loaderMap.set(path, {
287
- ...currentLoaderEntry,
288
- gcTimeout
289
- });
290
- };
291
- const prepareNavigation = (routeItem, location, hasError) => {
292
- updateScrollMap(routeItemDataState, scrollMapState);
293
- createGcTimeout();
294
- if (hasError) return;
295
- const path = getPath(location);
296
- if (routeItem?.optimistic && loaderMap.has(path)) {
297
- commitNavigation(() => routeItemDataState.setState({
298
- routeItem,
299
- location,
300
- status: "optimistic"
301
- }));
302
- const currentLoaderState = loaderMap.get(path)?.state;
303
- if (currentLoaderState) loaderState.setState(currentLoaderState);
304
- return;
305
- }
306
- if (routeItem?.loader && !isCacheItemFresh(path)) commitNavigation(() => routeItemDataState.setState({
307
- routeItem,
308
- location,
309
- status: "pending"
310
- }));
311
- };
312
- const polling = (routeItem, nextLocation) => {
313
- if (!routeItem?.pollingInterval) return;
314
- const signal = createSignal();
315
- interval = window.setInterval(() => revalidateCache({
316
- routeItem,
317
- location: nextLocation,
318
- signal
319
- }), routeItem.pollingInterval);
320
- };
321
- const getLoaderDurationPromise = (routeItem, nextLocation) => {
322
- const minLoaderDuration = routeItem?.minLoaderDuration ?? routerConfig.defaultMinLoaderDuration ?? 0;
323
- return minLoaderDuration && !isCacheItemFresh(getPath(nextLocation)) ? sleep(minLoaderDuration) : Promise.resolve();
324
- };
325
- const loader = async (routeItem, nextLocation, seq) => {
326
- if (!routeItem?.loader) return;
327
- window.clearInterval(interval);
328
- const signal = createSignal();
329
- const [result] = await Promise.all([revalidateCache({
330
- routeItem,
331
- location: nextLocation,
332
- signal
333
- }), getLoaderDurationPromise(routeItem, nextLocation)]);
334
- if (seq !== navigationSeq) return;
335
- polling(routeItem, nextLocation);
336
- return result;
337
- };
338
- const afterLoad = async (routeItem, params) => {
339
- const { defaultAfterLoad } = routerConfig;
340
- const searchParams = Object.fromEntries(new URLSearchParams(location.search).entries());
341
- const args = {
342
- context: contextState.getState(),
343
- params,
344
- searchParams
345
- };
346
- if (routeItem?.afterLoad) await routeItem.afterLoad(args);
347
- if (defaultAfterLoad) await defaultAfterLoad(args);
348
- };
349
- const checkBlocked = (nextLocation) => {
350
- if (blockerState.getState() === "charged") {
351
- blockerState.setState("blocked");
352
- blockedTargetState.setState(nextLocation);
353
- return true;
354
- }
355
- return false;
356
- };
357
- const clearCurrentGcTimeout = (routeItem, location) => {
358
- const path = `${location.pathname}${location.search}`;
359
- if (!routeItem?.gcTime) return;
360
- const currentLoaderEntry = loaderMap.get(path);
361
- if (!currentLoaderEntry?.gcTimeout) return;
362
- window.clearTimeout(currentLoaderEntry.gcTimeout);
363
- loaderMap.set(path, {
364
- ...currentLoaderEntry,
365
- gcTimeout: void 0
366
- });
367
- };
368
- const navigate = async (rawLocation) => {
369
- const nextLocation = {
370
- ...rawLocation,
371
- search: rawLocation.search ?? ""
372
- };
373
- if (checkBlocked(nextLocation)) return;
374
- navigationSeq = navigationSeq + 1;
375
- const seq = navigationSeq;
376
- const { nextItem, params } = routeResolve(nextLocation);
377
- const beforeLoadError = await beforeLoad(nextItem, nextLocation);
378
- if (seq !== navigationSeq) return;
379
- prepareNavigation(nextItem, nextLocation, !!beforeLoadError);
380
- const result = beforeLoadError ? {
381
- data: null,
382
- error: null,
383
- beforeLoadError
384
- } : await loader(nextItem, nextLocation, seq);
385
- if (seq !== navigationSeq) return;
386
- const loaderStateValue = {
387
- data: result?.data,
388
- loaderError: result?.error ?? null,
389
- beforeLoadError
390
- };
391
- commitNavigation(() => commitState({
392
- location: nextLocation,
393
- routeItem: nextItem,
394
- loaderStateValue
395
- }));
396
- clearCurrentGcTimeout(nextItem, nextLocation);
397
- afterLoad(nextItem, params);
398
- };
399
- return navigate;
400
- };
401
- //#endregion
402
- //#region runtime/invalidate.ts
403
- var separatePathname = (text) => text.split("?")[0];
404
- var createInvalidate = ({ routeItemDataState, loaderState, loaderMap }, revalidateCache) => {
405
- const invalidatePath = async (routeItem, pathname, options) => {
406
- const routePathname = routeItemDataState.getState().location.pathname;
407
- if (!options?.staleOnly) loaderMap.delete(pathname);
408
- const [path, search = ""] = pathname.split("?");
409
- const result = await revalidateCache({
410
- routeItem,
411
- location: {
412
- pathname: path,
413
- search
414
- }
415
- });
416
- if (result && path === routePathname) loaderState.setState({
417
- data: result.data,
418
- loaderError: result.error,
419
- beforeLoadError: null
420
- });
421
- return {
422
- path: pathname,
423
- ...result
424
- };
425
- };
426
- const invalidateItem = async (pathname, options) => {
427
- const routeItem = findRoute(separatePathname(pathname));
428
- if (!routeItem) return [];
429
- const pathnameSet = /* @__PURE__ */ new Set();
430
- for (const [key] of loaderMap) if (comparePaths(routeItem, separatePathname(key))) pathnameSet.add(key);
431
- if (options?.force) pathnameSet.add(pathname);
432
- const currentResults = await Promise.all([...pathnameSet].map((pathname) => invalidatePath(routeItem, pathname, options)));
433
- if (!options?.withChildren || !routeItem.children?.length) return currentResults;
434
- const [parentPath] = pathname.split("?");
435
- const childResults = await Promise.all(routeItem.children.map((child) => invalidateItem(`${parentPath}${child.path}`, options)));
436
- return [...currentResults, ...childResults.flat()];
437
- };
438
- return async (pathList, options) => {
439
- const { pathname, search } = routeItemDataState.getState().location;
440
- const routePathname = `${pathname}${search}`;
441
- const pathnameList = Array.isArray(pathList) ? pathList : pathList ? [pathList] : [routePathname];
442
- return (await Promise.all(pathnameList.map((pathname) => invalidateItem(pathname, options)))).flat();
443
- };
444
- };
445
- //#endregion
446
- //#region runtime/prefetch.ts
447
- var createPrefetch = ({ routeItemDataState }, revalidateCache) => async (location) => {
448
- const item = findRoute(location.pathname);
449
- if (item) {
450
- const currentLocation = routeItemDataState.getState().location;
451
- if (location.pathname === currentLocation.pathname && location.search === currentLocation.search) return;
452
- await item.preloadElement?.();
453
- await revalidateCache({
454
- routeItem: item,
455
- location
456
- });
457
- }
458
- };
459
- //#endregion
460
- //#region runtime/revalidateCache.ts
461
- var isObjectRetry = (arg) => typeof arg === "object";
462
- var createRetry = (arg) => {
463
- if (arg === void 0) return null;
464
- return {
465
- count: isObjectRetry(arg) ? arg.count : arg,
466
- delay: isObjectRetry(arg) ? arg.delay : 0
467
- };
468
- };
469
- var getRetry = (routeItem) => {
470
- const routeRetry = createRetry(routeItem?.retry);
471
- const globalRetry = createRetry(routerConfig.defaultRetry);
472
- if (!routeRetry && !globalRetry) return null;
473
- return {
474
- count: routeRetry ? routeRetry.count : globalRetry?.count || 0,
475
- delay: routeRetry ? routeRetry.delay : globalRetry?.delay || 0
476
- };
477
- };
478
- var createRevalidateCache = (routerState) => {
479
- const { loaderMap, loadingPromises, contextState } = routerState;
480
- const evict = () => {
481
- if (loaderMap.size <= routerConfig.maxCacheSize) return;
482
- const oldestKey = loaderMap.keys().next().value;
483
- if (oldestKey) loaderMap.delete(oldestKey);
484
- };
485
- const moveItemToLastPosition = (path) => {
486
- const item = loaderMap.get(path);
487
- if (item) {
488
- loaderMap.delete(path);
489
- loaderMap.set(path, item);
490
- }
491
- return item;
492
- };
493
- const revalidateCache = async ({ routeItem, location, signal }, retried = 0) => {
494
- if (!routeItem?.loader) return;
495
- const isCacheItemFresh = createIsCacheItemFresh(loaderMap);
496
- const { pathname, search = "" } = location;
497
- const path = `${pathname}${search}`;
498
- if (loadingPromises.has(path)) {
499
- moveItemToLastPosition(path);
500
- return loadingPromises.get(path);
501
- }
502
- if (isCacheItemFresh(path)) {
503
- const item = moveItemToLastPosition(path);
504
- if (!item?.state) return void 0;
505
- return item.state.loaderError ? {
506
- data: null,
507
- error: item.state.loaderError
508
- } : {
509
- data: item.state.data,
510
- error: null
511
- };
512
- }
513
- const promise = (async () => {
514
- if (!routeItem?.loader) return;
515
- const effectiveSignal = signal ?? new AbortController().signal;
516
- try {
517
- const result = await routeItem?.loader({
518
- ...getPartialLoaderArgs(contextState, location, routeItem),
519
- signal: effectiveSignal
520
- });
521
- loaderMap.set(path, {
522
- state: {
523
- data: result,
524
- beforeLoadError: null,
525
- loaderError: null
526
- },
527
- timestamp: Date.now(),
528
- staleTime: routeItem.staleTime
529
- });
530
- evict();
531
- return {
532
- data: result,
533
- error: null
534
- };
535
- } catch (error) {
536
- if (effectiveSignal.aborted) return {
537
- data: null,
538
- error: null
539
- };
540
- const retry = getRetry(routeItem);
541
- if (retry && retry.count > retried) {
542
- loadingPromises.delete(path);
543
- if (retry.delay) await sleep(retry.delay);
544
- await revalidateCache({
545
- routeItem,
546
- location,
547
- signal
548
- }, retried + 1);
549
- return {
550
- data: null,
551
- error
552
- };
553
- } else return {
554
- data: null,
555
- error
556
- };
557
- } finally {
558
- loadingPromises.delete(path);
559
- }
560
- })();
561
- loadingPromises.set(path, promise);
562
- return promise;
563
- };
564
- return revalidateCache;
565
- };
566
- //#endregion
567
- //#region creators/createRouterInstance.ts
568
- var createRouterInstance = () => {
569
- const routerState = {
570
- routeItemDataState: create({
571
- routeItem: void 0,
572
- location: {},
573
- status: "idle"
574
- }),
575
- scrollMapState: create({}),
576
- contextState: create({}),
577
- blockerState: create("unblocked"),
578
- loaderState: create(EMPTY_LOADER_STATE),
579
- blockedTargetState: create(null),
580
- loaderMap: /* @__PURE__ */ new Map(),
581
- loadingPromises: /* @__PURE__ */ new Map()
582
- };
583
- const revalidateCache = createRevalidateCache(routerState);
584
- const navigate = createNavigate(routerState, revalidateCache);
585
- const invalidate = createInvalidate(routerState, revalidateCache);
586
- const prefetch = createPrefetch(routerState, revalidateCache);
587
- const getCurrentAction = (actionKey) => {
588
- const { routeItem, location } = routerState.routeItemDataState.getState();
589
- if (!routeItem) throw new Error("Route not found");
590
- if (!routeItem.actions) throw new Error("Route action creator not found");
591
- const context = routerState.contextState.getState();
592
- const setContext = routerState.contextState.setState;
593
- const params = getParams(location, routeItem);
594
- const searchParams = Object.fromEntries(new URLSearchParams(location.search).entries());
595
- const action = routeItem.actions({
596
- context,
597
- setContext,
598
- params,
599
- location,
600
- searchParams
601
- })[actionKey];
602
- if (!action) throw new Error(`Action "${actionKey}" not found`);
603
- return action;
604
- };
605
- return {
606
- state: routerState,
607
- runtime: {
608
- navigate,
609
- invalidate,
610
- prefetch
611
- },
612
- hooks: {
613
- useBlockerState: () => useGlobalState(routerState.blockerState),
614
- useRouteItemData: () => useGlobalState(routerState.routeItemDataState),
615
- useScrollMap: () => useGlobalState(routerState.scrollMapState),
616
- useContextState: () => useGlobalState(routerState.contextState),
617
- useLoaderState: () => useGlobalState(routerState.loaderState)[0],
618
- useParams: () => {
619
- const { routeItem, location } = routerState.routeItemDataState.getState();
620
- return getParams(location, routeItem);
621
- },
622
- useNavigate: () => async (arg) => {
623
- const { location } = routerState.routeItemDataState.getState();
624
- const prevLocation = {
625
- pathname: location.pathname,
626
- search: location.search
627
- };
628
- if (arg === -1) return history.go(arg);
629
- if (typeof arg === "string") {
630
- const [pathname, search = ""] = arg.split("?");
631
- if (pathname !== location.pathname || search !== location.search) await navigate({
632
- pathname,
633
- search,
634
- prevLocation
635
- });
636
- return;
637
- }
638
- const search = typeof arg.search === "object" ? formatSearchObject(arg.search) : arg.search;
639
- await navigate({
640
- ...arg,
641
- search,
642
- prevLocation
643
- });
644
- },
645
- useAction: (action, options = {}) => {
646
- const currentAction = getCurrentAction(action);
647
- return async (input) => {
648
- try {
649
- const data = await currentAction(input);
650
- await invalidate();
651
- options.onSuccess?.(data);
652
- return {
653
- data,
654
- error: null
655
- };
656
- } catch (error) {
657
- options.onError?.(error);
658
- return {
659
- data: null,
660
- error
661
- };
662
- }
663
- };
664
- },
665
- useRestoreScroll: (restorationBehavior) => {
666
- const { routeItem, location: { pathname } } = routerState.routeItemDataState.getState();
667
- const scrollMap = routerState.scrollMapState.getState();
668
- if (!routeItem || routeItem.scrollRestoration === false || !scrollMap[pathname]) return;
669
- return () => restoreScroll(scrollMap, pathname, routeItem.scrollRestorationBehavior ?? restorationBehavior);
670
- }
671
- }
672
- };
673
- };
674
- //#endregion
675
- //#region instance.ts
676
- var router = createRouterInstance();
677
- //#endregion
678
- //#region hooks/useNavigation.ts
679
- var useNavigation = () => {
680
- const { navigate } = router.runtime;
681
- const { blockerState, routeItemDataState } = router.state;
682
- useEffect(() => {
683
- const handler = async (event) => {
684
- const newLocation = parseWindowLocation(event.target.location);
685
- const { location } = routeItemDataState.getState();
686
- const prevLocation = {
687
- pathname: location.pathname,
688
- search: location.search
689
- };
690
- if (blockerState.getState() === "charged") history.pushState(null, "", routeItemDataState.getState().location.pathname);
691
- await navigate({
692
- ...newLocation,
693
- prevLocation
694
- });
695
- };
696
- window.addEventListener("popstate", handler);
697
- return () => window.removeEventListener("popstate", handler);
698
- }, [
699
- navigate,
700
- blockerState,
701
- routeItemDataState
702
- ]);
703
- useEffect(() => {
704
- navigate(parseWindowLocation(window.location));
705
- }, [navigate]);
706
- };
707
- //#endregion
708
- //#region hooks/useApplyCustomAnimation.ts
709
- var useApplyCustomAnimation = (animationDuration) => {
710
- useEffect(() => {
711
- const style = document.createElement("style");
712
- style.id = "spinner-style";
713
- style.textContent = `
714
- @keyframes cr-spin {
715
- 0% { transform: rotate(0deg); }
716
- 100% { transform: rotate(360deg); }
717
- }
718
-
719
- .cr-spinner {
720
- position: fixed;
721
- top: 5px;
722
- left: 5px;
723
- z-index: 9999;
724
- width: 1rem;
725
- height: 1rem;
726
- border: 2px solid gray;
727
- border-bottom-color: transparent;
728
- border-radius: 50%;
729
- animation: cr-spin 1s linear infinite;
730
- }
731
- `;
732
- document.head.appendChild(style);
733
- return () => style.remove();
734
- }, []);
735
- useEffect(() => {
736
- if (!animationDuration) return;
737
- const style = document.createElement("style");
738
- style.id = "dynamic-view-transition-duration-style";
739
- style.textContent = `::view-transition-group(page) { animation-duration: ${animationDuration}ms; }`;
740
- document.head.appendChild(style);
741
- return () => style.remove();
742
- }, [animationDuration]);
743
- };
744
- //#endregion
745
- //#region hooks/usePreserveScroll.ts
746
- var usePreserveScroll = (restorationBehavior) => {
747
- const { useRestoreScroll } = router.hooks;
748
- const restoreScroll = useRestoreScroll(restorationBehavior);
749
- useEffect(() => {
750
- restoreScroll?.();
751
- }, [restoreScroll]);
752
- };
753
- //#endregion
754
- //#region hooks/useSetRouterConfig.ts
755
- var useSetRouterConfig = (routerProps) => {
756
- useLayoutEffect(() => routerConfig.configure(routerProps), [routerProps]);
757
- };
758
- //#endregion
759
- //#region hooks/useSetInitialContext.ts
760
- var useSetInitialContext = (initialContext) => {
761
- const [, setContext] = router.hooks.useContextState();
762
- useEffect(() => {
763
- if (initialContext) setContext(initialContext);
764
- }, [initialContext, setContext]);
765
- };
766
- //#endregion
767
- //#region hooks/useReload.ts
768
- var useReload = () => {
769
- const { invalidate } = router.runtime;
770
- useEffect(() => {
771
- if (!routerConfig.revalidateOnFocus) return;
772
- const handler = () => {
773
- if (document.visibilityState === "visible") invalidate("", { staleOnly: true });
774
- };
775
- document.addEventListener("visibilitychange", handler);
776
- return () => document.removeEventListener("visibilitychange", handler);
777
- }, [invalidate]);
778
- useEffect(() => {
779
- if (!routerConfig.revalidateOnReconnect) return;
780
- const handler = () => invalidate("", { staleOnly: true });
781
- window.addEventListener("online", handler);
782
- return () => window.removeEventListener("online", handler);
783
- }, [invalidate]);
784
- };
785
- //#endregion
786
- //#region ../../node_modules/react/cjs/react-jsx-runtime.production.js
787
- /**
788
- * @license React
789
- * react-jsx-runtime.production.js
790
- *
791
- * Copyright (c) Meta Platforms, Inc. and affiliates.
792
- *
793
- * This source code is licensed under the MIT license found in the
794
- * LICENSE file in the root directory of this source tree.
795
- */
796
- var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((exports) => {
797
- var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
798
- function jsxProd(type, config, maybeKey) {
799
- var key = null;
800
- void 0 !== maybeKey && (key = "" + maybeKey);
801
- void 0 !== config.key && (key = "" + config.key);
802
- if ("key" in config) {
803
- maybeKey = {};
804
- for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]);
805
- } else maybeKey = config;
806
- config = maybeKey.ref;
807
- return {
808
- $$typeof: REACT_ELEMENT_TYPE,
809
- type,
810
- key,
811
- ref: void 0 !== config ? config : null,
812
- props: maybeKey
813
- };
814
- }
815
- exports.jsx = jsxProd;
816
- exports.jsxs = jsxProd;
817
- }));
818
- //#endregion
819
- //#region components/Spinner.tsx
820
- var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
821
- module.exports = require_react_jsx_runtime_production();
822
- })))();
823
- var Spinner = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "cr-spinner" });
824
- //#endregion
825
- //#region utils/renderElement.tsx
826
- var renderElement = (Component) => {
827
- if (!Component) return null;
828
- return typeof Component === "function" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) : Component;
829
- };
830
- //#endregion
831
- //#region components/Router.tsx
832
- var EmptyBoundary = ({ children }) => children;
833
- var IS_MOBILE = isMobile();
834
- var MOBILE_CACHE_SIZE = 60;
835
- var DESKTOP_CACHE_SIZE = 150;
836
- var Router = ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration, defaultLoaderFallback, defaultErrorElement, defaultRetry, defaultStaleTime, context: initialContext, isAnimated = false, optimisticSpinner = true, defaultMinLoaderDuration = 0, revalidateOnFocus = false, revalidateOnReconnect = false, maxCacheSize = IS_MOBILE ? MOBILE_CACHE_SIZE : DESKTOP_CACHE_SIZE, defaultPrefetch = IS_MOBILE ? "viewport" : "hover", defaultHoverPrefetchDelay = 150, defaultScrollRestorationBehavior = "auto", errorBoundary: ErrorBoundary = EmptyBoundary }) => {
837
- const { useRouteItemData } = router.hooks;
838
- const [{ routeItem, status, location }] = useRouteItemData();
839
- const isError = status === "error";
840
- const isLoading = status === "pending";
841
- const isOptimistic = status === "optimistic";
842
- useNavigation();
843
- useSetRouterConfig({
844
- routes,
845
- isAnimated,
846
- defaultPrefetch,
847
- defaultHoverPrefetchDelay,
848
- defaultBeforeLoad,
849
- defaultAfterLoad,
850
- defaultRetry,
851
- defaultStaleTime,
852
- defaultMinLoaderDuration,
853
- maxCacheSize,
854
- revalidateOnFocus,
855
- revalidateOnReconnect
856
- });
857
- useApplyCustomAnimation(animationDuration);
858
- useSetInitialContext(initialContext);
859
- usePreserveScroll(defaultScrollRestorationBehavior);
860
- useReload();
861
- if (isLoading && !isError) return renderElement(routeItem?.loaderFallback || defaultLoaderFallback);
862
- if (!routeItem) return null;
863
- if (isError) return renderElement(routeItem.errorElement || defaultErrorElement);
864
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
865
- style: { viewTransitionName: "page" },
866
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, { children: renderElement(routeItem.element) }, location.pathname), optimisticSpinner && isOptimistic && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {})]
867
- });
868
- };
869
- //#endregion
870
- //#region hooks/useIsRoutePending.ts
871
- var useIsRoutePending = (routePath) => {
872
- const { useRouteItemData } = router.hooks;
873
- const [routeItemData] = useRouteItemData();
874
- return routeItemData.status === "pending" && routeItemData?.location.pathname === routePath;
875
- };
876
- //#endregion
877
- //#region hooks/useNavigate.ts
878
- var useNavigate = router.hooks.useNavigate;
879
- //#endregion
880
- //#region hooks/useLocation.ts
881
- var useLocation = () => {
882
- const [routeItemData] = router.hooks.useRouteItemData();
883
- return routeItemData.location;
884
- };
885
- //#endregion
886
- //#region components/Link.tsx
887
- var defaultAs = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { ...props });
888
- var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPrefetch, hoverPrefetchDelay, className, style, beforeNavigate, exact = false, activeClassName = "active-link", pendingClassName = "pending-link" }) => {
889
- const isPending = useIsRoutePending(to);
890
- const { pathname } = useLocation();
891
- const navigate = useNavigate();
892
- const timeout = useRef(0);
893
- const elementRef = useRef(null);
894
- const { defaultPrefetch: configPrefetch, defaultHoverPrefetchDelay: configPrefetchDelay } = routerConfig;
895
- const prefetch = linkPrefetch || configPrefetch;
896
- const prefetchDelay = hoverPrefetchDelay ?? configPrefetchDelay;
897
- const searchString = typeof search === "object" ? formatSearchObject(search) : search;
898
- const location = useMemo(() => ({
899
- pathname: to,
900
- search: searchString,
901
- state
902
- }), [
903
- searchString,
904
- state,
905
- to
906
- ]);
907
- const onMouseEnter = useCallback(() => {
908
- if (prefetch !== "hover" || !prefetchDelay) return;
909
- if (timeout.current) clearTimeout(timeout.current);
910
- timeout.current = window.setTimeout(() => router.runtime.prefetch(location), prefetchDelay);
911
- }, [
912
- prefetch,
913
- prefetchDelay,
914
- location
915
- ]);
916
- const onMouseLeave = useCallback(() => {
917
- if (prefetch !== "hover" || !prefetchDelay) return;
918
- if (timeout.current) {
919
- clearTimeout(timeout.current);
920
- timeout.current = 0;
921
- }
922
- }, [prefetch, prefetchDelay]);
923
- useEffect(() => {
924
- if (prefetch !== "render") return;
925
- (async () => {
926
- await router.runtime.prefetch(location);
927
- })();
928
- }, [prefetch, location]);
929
- useEffect(() => {
930
- if (prefetch !== "viewport") return;
931
- const element = elementRef.current;
932
- if (!element) return;
933
- const observer = new IntersectionObserver(async ([entry]) => {
934
- if (!entry.isIntersecting) return;
935
- await router.runtime.prefetch(location);
936
- observer.disconnect();
937
- });
938
- observer.observe(element);
939
- return () => observer.disconnect();
940
- }, [prefetch, location]);
941
- useEffect(() => () => {
942
- if (timeout.current) clearTimeout(timeout.current);
943
- }, []);
944
- const isActive = to === "/" ? pathname === "/" : exact ? pathname === to : pathname === to || pathname?.startsWith(`${to}/`);
945
- const normalizedClassName = typeof className === "function" ? className({
946
- isActive,
947
- isPending
948
- }) : className;
949
- const normalizedStyle = typeof style === "function" ? style({
950
- isActive,
951
- isPending
952
- }) : style;
953
- const resultClassName = [
954
- isActive && activeClassName,
955
- isPending && pendingClassName,
956
- normalizedClassName
957
- ].filter(Boolean).join(" ");
958
- const clickHandler = async (event) => {
959
- if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
960
- event.preventDefault();
961
- await beforeNavigate?.();
962
- await navigate(location);
963
- };
964
- return as({
965
- ref: elementRef,
966
- href: to,
967
- style: normalizedStyle,
968
- className: resultClassName,
969
- onClick: clickHandler,
970
- onMouseEnter,
971
- onMouseLeave,
972
- children
973
- }, {
974
- isActive,
975
- isPending
976
- });
977
- };
978
- //#endregion
979
- //#region hooks/useParams.ts
980
- var useParams = router.hooks.useParams;
981
- //#endregion
982
- //#region hooks/useLoaderState.ts
983
- var useLoaderState = router.hooks.useLoaderState;
984
- //#endregion
985
- //#region hooks/useInvalidate.ts
986
- var useInvalidate = () => router.runtime.invalidate;
987
- //#endregion
988
- //#region hooks/useBlocker.ts
989
- var useBlocker = (blockerFn) => {
990
- const { hooks: { useBlockerState, useContextState }, runtime: { navigate }, state: { blockedTargetState } } = router;
991
- const [nextLocation, setNextLocation] = useGlobalState(blockedTargetState);
992
- const [blockerState, setBlockerState] = useBlockerState();
993
- const [context] = useContextState();
994
- const location = useLocation();
995
- const shouldBlock = blockerFn(useMemo(() => ({
996
- location,
997
- nextLocation,
998
- context
999
- }), [
1000
- context,
1001
- location,
1002
- nextLocation
1003
- ]));
1004
- useEffect(() => setBlockerState(shouldBlock ? "charged" : "unblocked"), [setBlockerState, shouldBlock]);
1005
- return {
1006
- state: blockerState,
1007
- process: useCallback(async () => {
1008
- if (nextLocation) await navigate(nextLocation);
1009
- setBlockerState("unblocked");
1010
- setNextLocation(null);
1011
- }, [
1012
- navigate,
1013
- nextLocation,
1014
- setBlockerState,
1015
- setNextLocation
1016
- ]),
1017
- reset: useCallback(() => {
1018
- setBlockerState("charged");
1019
- setNextLocation(null);
1020
- }, [setBlockerState, setNextLocation])
1021
- };
1022
- };
1023
- //#endregion
1024
- //#region hooks/useAction.ts
1025
- var useAction = router.hooks.useAction;
1026
- //#endregion
1027
- //#region hooks/useIsDataLoading.ts
1028
- var useIsDataLoading = () => {
1029
- const { useRouteItemData } = router.hooks;
1030
- const [routeData] = useRouteItemData();
1031
- return routeData.status === "pending";
1032
- };
1033
- //#endregion
1034
- //#region hooks/useRouterContext.ts
1035
- var useRouterContext = () => {
1036
- const [context, setContext] = router.hooks.useContextState();
1037
- return {
1038
- context,
1039
- setContext
1040
- };
1041
- };
1042
- //#endregion
1043
- //#region hooks/useSearch.ts
1044
- var notify = () => {
1045
- window.dispatchEvent(new Event("locationChange"));
1046
- };
1047
- var patchHistory = () => {
1048
- const push = history.pushState;
1049
- const replace = history.replaceState;
1050
- history.pushState = function(...args) {
1051
- const result = push.apply(this, args);
1052
- notify();
1053
- return result;
1054
- };
1055
- history.replaceState = function(...args) {
1056
- const result = replace.apply(this, args);
1057
- notify();
1058
- return result;
1059
- };
1060
- window.addEventListener("popstate", notify);
1061
- };
1062
- var subscribe = (onChange) => {
1063
- window.addEventListener("locationChange", onChange);
1064
- return () => window.removeEventListener("locationChange", onChange);
1065
- };
1066
- var getSnapshot = () => window.location.search;
1067
- var useSearch = () => {
1068
- useEffect(patchHistory, []);
1069
- return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
1070
- };
1071
- //#endregion
1072
- //#region hooks/useSearchParams.ts
1073
- var useSearchParams = () => {
1074
- const search = useSearch();
1075
- const searchString = search ? search.replace("?", "") : window.location.pathname.split("?")?.[1] ?? "";
1076
- const searchParams = useMemo(() => new URLSearchParams(searchString), [searchString]);
1077
- const getSearchParams = useCallback((param) => {
1078
- const allValues = searchParams.getAll(param);
1079
- return allValues.length > 1 ? allValues : allValues[0] ?? "";
1080
- }, [searchParams]);
1081
- const navigateWithSearchParams = useCallback((params) => {
1082
- const newSearch = params.toString();
1083
- const { pathname } = window.location;
1084
- const search = newSearch ? `?${newSearch}` : "";
1085
- history.replaceState(null, "", pathname + search);
1086
- }, []);
1087
- return {
1088
- searchParams,
1089
- getSearchParams,
1090
- setSearchParams: useCallback((param, value) => {
1091
- const currentParams = new URLSearchParams(search);
1092
- if (typeof param === "string" && value !== void 0) {
1093
- currentParams.delete(param);
1094
- (Array.isArray(value) ? value : [value]).forEach((v) => currentParams.append(param, v));
1095
- navigateWithSearchParams(currentParams);
1096
- } else if (typeof param === "function") navigateWithSearchParams(param(currentParams));
1097
- else throw new Error("useSearchParams first argument must be either function or string");
1098
- }, [navigateWithSearchParams, search])
1099
- };
1100
- };
1101
- //#endregion
1102
- //#region hooks/useSubmitAction.ts
1103
- var useSubmitAction = (action, options) => {
1104
- const currentAction = router.hooks.useAction(action, options);
1105
- const [data, setData] = useState();
1106
- const [error, setError] = useState(null);
1107
- const [isSubmitting, setIsSubmitting] = useState(false);
1108
- const submit = useCallback(async (data) => {
1109
- setIsSubmitting(true);
1110
- const result = await currentAction(data);
1111
- setIsSubmitting(false);
1112
- setData(result.data);
1113
- setError(result.error);
1114
- return result;
1115
- }, [currentAction]);
1116
- return {
1117
- submit,
1118
- onSubmit: useCallback(async (evt) => {
1119
- evt.preventDefault();
1120
- const target = evt.target;
1121
- const { error } = await submit(Object.fromEntries(new FormData(target)));
1122
- if (!(options?.autoReset === false) && !error) target.reset();
1123
- }, [options?.autoReset, submit]),
1124
- data,
1125
- error,
1126
- isSubmitting
1127
- };
1128
- };
1129
- //#endregion
1130
- //#region utils/createLazyComponent.tsx
1131
- var createLazyComponent = (importFn, fallback) => {
1132
- const load = () => importFn().then((module) => ({ default: module.default || module }));
1133
- const LazyComp = lazy$1(load);
1134
- const Component = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Suspense, {
1135
- fallback: typeof fallback === "function" ? fallback() : fallback || null,
1136
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazyComp, {})
1137
- });
1138
- return {
1139
- Component,
1140
- preloadElement: load
1141
- };
1142
- };
1143
- //#endregion
1144
- //#region types.ts
1145
- var LAZY_MARKER = Symbol("clear-router-lazy");
1146
- //#endregion
1147
- //#region creators/createRouter.ts
1148
- var isLazy = (el) => typeof el.element === "object" && el.element !== null && LAZY_MARKER in el.element;
1149
- var parseClientRouteItem = (el, parentPattern = "") => {
1150
- const pattern = `${parentPattern}/${el.path}`.replace(/\/+/g, "/");
1151
- const preloadElement = isLazy(el) ? createLazyComponent(el.element.importFn, el.fallback).preloadElement : void 0;
1152
- const resolvedElement = isLazy(el) ? createLazyComponent(el.element.importFn, el.fallback).Component : el.element;
1153
- return [{
1154
- ...el,
1155
- pattern,
1156
- element: resolvedElement,
1157
- preloadElement
1158
- }, ...el.children?.flatMap((child) => parseClientRouteItem(child, pattern)) ?? []];
1159
- };
1160
- var createRouter = (clientList) => clientList.flatMap((el) => parseClientRouteItem(el));
1161
- //#endregion
1162
- //#region utils/lazy.ts
1163
- var lazy = (importFn) => ({
1164
- [LAZY_MARKER]: true,
1165
- importFn
1166
- });
1167
- //#endregion
1168
- export { Link, Router, createRouter, lazy, useAction, useBlocker, useInvalidate, useIsDataLoading, useLoaderState, useLocation, useNavigate, useParams, useRouterContext, useSearchParams, useSubmitAction };