likec4 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/__app__/index.html +0 -1
- package/__app__/react/likec4.tsx +11 -8
- package/__app__/src/chunks/-index-overview-C9eO_hFX.js +309 -0
- package/__app__/src/chunks/-view-lazy-data-CI4xD57c.js +9 -0
- package/__app__/src/chunks/index-KI-kE60c.js +465 -0
- package/__app__/src/chunks/likec4-CusAw_j6.js +6106 -0
- package/__app__/src/chunks/main-DY2KbFcO.js +24136 -0
- package/__app__/src/chunks/mantine-B_6mKFFA.js +13671 -0
- package/__app__/src/chunks/tanstack-router-BBWuTKWO.js +2373 -0
- package/__app__/src/icons.js +6 -6
- package/__app__/src/main.js +1 -1
- package/__app__/src/style.css +1 -1
- package/__app__/webcomponent/webcomponent.js +21699 -21851
- package/dist/chunks/prompt.mjs +35 -35
- package/dist/cli/index.mjs +91 -88
- package/dist/index.d.mts +410 -2388
- package/dist/index.d.ts +410 -2388
- package/dist/index.mjs +1 -1
- package/dist/model/index.d.mts +258 -0
- package/dist/model/index.d.ts +258 -0
- package/dist/model/index.mjs +1 -0
- package/dist/shared/likec4.CbSUX9bc.mjs +1853 -0
- package/dist/shared/likec4.DCwaTTuF.d.mts +1625 -0
- package/dist/shared/likec4.DCwaTTuF.d.ts +1625 -0
- package/dist/shared/likec4.LktBLTET.mjs +9 -0
- package/package.json +65 -62
- package/react/index.d.ts +150 -918
- package/react/index.js +39830 -0
- package/react/style.css +1 -1
- package/__app__/src/chunks/-index-overview-CBnvpD1d.js +0 -309
- package/__app__/src/chunks/-view-lazy-data-WZmbIsHq.js +0 -9
- package/__app__/src/chunks/index-CIsxIzOH.js +0 -465
- package/__app__/src/chunks/likec4-DslTxitT.js +0 -6109
- package/__app__/src/chunks/main-ByUdz_Be.js +0 -24285
- package/__app__/src/chunks/mantine-oFa3ZrEq.js +0 -13658
- package/__app__/src/chunks/tanstack-router-BWjXKr0n.js +0 -2373
- package/dist/shared/likec4.lgHXhASw.mjs +0 -1832
- package/react/index.mjs +0 -41515
|
@@ -1,2373 +0,0 @@
|
|
|
1
|
-
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { flushSync } from "react-dom";
|
|
4
|
-
import { w as withSelectorExports } from "./likec4-DslTxitT.js";
|
|
5
|
-
const pushStateEvent = "pushstate", popStateEvent = "popstate", beforeUnloadEvent = "beforeunload", beforeUnloadListener = (event) => (event.preventDefault(), event.returnValue = ""), stopBlocking = () => {
|
|
6
|
-
removeEventListener(beforeUnloadEvent, beforeUnloadListener, {
|
|
7
|
-
capture: !0
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
function createHistory(opts) {
|
|
11
|
-
let location = opts.getLocation();
|
|
12
|
-
const subscribers = /* @__PURE__ */ new Set();
|
|
13
|
-
let blockers = [];
|
|
14
|
-
const notify = () => {
|
|
15
|
-
location = opts.getLocation(), subscribers.forEach((subscriber) => subscriber());
|
|
16
|
-
}, tryNavigation = async (task, navigateOpts) => {
|
|
17
|
-
var _a;
|
|
18
|
-
if (!(navigateOpts?.ignoreBlocker ?? !1) && typeof document < "u" && blockers.length) {
|
|
19
|
-
for (const blocker of blockers)
|
|
20
|
-
if (!await blocker()) {
|
|
21
|
-
(_a = opts.onBlocked) == null || _a.call(opts, notify);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
task();
|
|
26
|
-
};
|
|
27
|
-
return {
|
|
28
|
-
get location() {
|
|
29
|
-
return location;
|
|
30
|
-
},
|
|
31
|
-
subscribers,
|
|
32
|
-
subscribe: (cb) => (subscribers.add(cb), () => {
|
|
33
|
-
subscribers.delete(cb);
|
|
34
|
-
}),
|
|
35
|
-
push: (path, state, navigateOpts) => {
|
|
36
|
-
state = assignKey(state), tryNavigation(() => {
|
|
37
|
-
opts.pushState(path, state), notify();
|
|
38
|
-
}, navigateOpts);
|
|
39
|
-
},
|
|
40
|
-
replace: (path, state, navigateOpts) => {
|
|
41
|
-
state = assignKey(state), tryNavigation(() => {
|
|
42
|
-
opts.replaceState(path, state), notify();
|
|
43
|
-
}, navigateOpts);
|
|
44
|
-
},
|
|
45
|
-
go: (index, navigateOpts) => {
|
|
46
|
-
tryNavigation(() => {
|
|
47
|
-
opts.go(index), notify();
|
|
48
|
-
}, navigateOpts);
|
|
49
|
-
},
|
|
50
|
-
back: (navigateOpts) => {
|
|
51
|
-
tryNavigation(() => {
|
|
52
|
-
opts.back(), notify();
|
|
53
|
-
}, navigateOpts);
|
|
54
|
-
},
|
|
55
|
-
forward: (navigateOpts) => {
|
|
56
|
-
tryNavigation(() => {
|
|
57
|
-
opts.forward(), notify();
|
|
58
|
-
}, navigateOpts);
|
|
59
|
-
},
|
|
60
|
-
createHref: (str) => opts.createHref(str),
|
|
61
|
-
block: (blocker) => (blockers.push(blocker), blockers.length === 1 && addEventListener(beforeUnloadEvent, beforeUnloadListener, {
|
|
62
|
-
capture: !0
|
|
63
|
-
}), () => {
|
|
64
|
-
blockers = blockers.filter((b) => b !== blocker), blockers.length || stopBlocking();
|
|
65
|
-
}),
|
|
66
|
-
flush: () => {
|
|
67
|
-
var _a;
|
|
68
|
-
return (_a = opts.flush) == null ? void 0 : _a.call(opts);
|
|
69
|
-
},
|
|
70
|
-
destroy: () => {
|
|
71
|
-
var _a;
|
|
72
|
-
return (_a = opts.destroy) == null ? void 0 : _a.call(opts);
|
|
73
|
-
},
|
|
74
|
-
notify
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function assignKey(state) {
|
|
78
|
-
return state || (state = {}), {
|
|
79
|
-
...state,
|
|
80
|
-
key: createRandomKey()
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function createBrowserHistory(opts) {
|
|
84
|
-
const win = opts?.window ?? (typeof document < "u" ? window : void 0), originalPushState = win.history.pushState, originalReplaceState = win.history.replaceState, createHref = opts?.createHref ?? ((path) => path), parseLocation = opts?.parseLocation ?? (() => parseHref(
|
|
85
|
-
`${win.location.pathname}${win.location.search}${win.location.hash}`,
|
|
86
|
-
win.history.state
|
|
87
|
-
));
|
|
88
|
-
let currentLocation = parseLocation(), rollbackLocation;
|
|
89
|
-
const getLocation = () => currentLocation;
|
|
90
|
-
let next, scheduled;
|
|
91
|
-
const flush = () => {
|
|
92
|
-
if (!next)
|
|
93
|
-
return;
|
|
94
|
-
(next.isPush ? originalPushState : originalReplaceState).call(win.history, next.state, "", next.href), next = void 0, scheduled = void 0, rollbackLocation = void 0;
|
|
95
|
-
}, queueHistoryAction = (type, destHref, state) => {
|
|
96
|
-
const href = createHref(destHref);
|
|
97
|
-
scheduled || (rollbackLocation = currentLocation), currentLocation = parseHref(destHref, state), next = {
|
|
98
|
-
href,
|
|
99
|
-
state,
|
|
100
|
-
isPush: next?.isPush || type === "push"
|
|
101
|
-
}, scheduled || (scheduled = Promise.resolve().then(() => flush()));
|
|
102
|
-
}, onPushPop = () => {
|
|
103
|
-
currentLocation = parseLocation(), history.notify();
|
|
104
|
-
}, history = createHistory({
|
|
105
|
-
getLocation,
|
|
106
|
-
pushState: (href, state) => queueHistoryAction("push", href, state),
|
|
107
|
-
replaceState: (href, state) => queueHistoryAction("replace", href, state),
|
|
108
|
-
back: () => win.history.back(),
|
|
109
|
-
forward: () => win.history.forward(),
|
|
110
|
-
go: (n) => win.history.go(n),
|
|
111
|
-
createHref: (href) => createHref(href),
|
|
112
|
-
flush,
|
|
113
|
-
destroy: () => {
|
|
114
|
-
win.history.pushState = originalPushState, win.history.replaceState = originalReplaceState, win.removeEventListener(pushStateEvent, onPushPop), win.removeEventListener(popStateEvent, onPushPop);
|
|
115
|
-
},
|
|
116
|
-
onBlocked: (onUpdate) => {
|
|
117
|
-
rollbackLocation && currentLocation !== rollbackLocation && (currentLocation = rollbackLocation, onUpdate());
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
return win.addEventListener(pushStateEvent, onPushPop), win.addEventListener(popStateEvent, onPushPop), win.history.pushState = function(...args) {
|
|
121
|
-
const res = originalPushState.apply(win.history, args);
|
|
122
|
-
return onPushPop(), res;
|
|
123
|
-
}, win.history.replaceState = function(...args) {
|
|
124
|
-
const res = originalReplaceState.apply(win.history, args);
|
|
125
|
-
return onPushPop(), res;
|
|
126
|
-
}, history;
|
|
127
|
-
}
|
|
128
|
-
function createHashHistory(opts) {
|
|
129
|
-
const win = typeof document < "u" ? window : void 0;
|
|
130
|
-
return createBrowserHistory({
|
|
131
|
-
window: win,
|
|
132
|
-
parseLocation: () => {
|
|
133
|
-
const hashHref = win.location.hash.split("#").slice(1).join("#") ?? "/";
|
|
134
|
-
return parseHref(hashHref, win.history.state);
|
|
135
|
-
},
|
|
136
|
-
createHref: (href) => `${win.location.pathname}${win.location.search}#${href}`
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
function createMemoryHistory(opts = {
|
|
140
|
-
initialEntries: ["/"]
|
|
141
|
-
}) {
|
|
142
|
-
const entries = opts.initialEntries;
|
|
143
|
-
let index = opts.initialIndex ?? entries.length - 1, currentState = {
|
|
144
|
-
key: createRandomKey()
|
|
145
|
-
};
|
|
146
|
-
return createHistory({
|
|
147
|
-
getLocation: () => parseHref(entries[index], currentState),
|
|
148
|
-
pushState: (path, state) => {
|
|
149
|
-
currentState = state, entries.splice, index < entries.length - 1 && entries.splice(index + 1), entries.push(path), index = Math.max(entries.length - 1, 0);
|
|
150
|
-
},
|
|
151
|
-
replaceState: (path, state) => {
|
|
152
|
-
currentState = state, entries[index] = path;
|
|
153
|
-
},
|
|
154
|
-
back: () => {
|
|
155
|
-
currentState = assignKey(currentState), index = Math.max(index - 1, 0);
|
|
156
|
-
},
|
|
157
|
-
forward: () => {
|
|
158
|
-
currentState = assignKey(currentState), index = Math.min(index + 1, entries.length - 1);
|
|
159
|
-
},
|
|
160
|
-
go: (n) => {
|
|
161
|
-
currentState = assignKey(currentState), index = Math.min(Math.max(index + n, 0), entries.length - 1);
|
|
162
|
-
},
|
|
163
|
-
createHref: (path) => path
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
function parseHref(href, state) {
|
|
167
|
-
const hashIndex = href.indexOf("#"), searchIndex = href.indexOf("?");
|
|
168
|
-
return {
|
|
169
|
-
href,
|
|
170
|
-
pathname: href.substring(
|
|
171
|
-
0,
|
|
172
|
-
hashIndex > 0 ? searchIndex > 0 ? Math.min(hashIndex, searchIndex) : hashIndex : searchIndex > 0 ? searchIndex : href.length
|
|
173
|
-
),
|
|
174
|
-
hash: hashIndex > -1 ? href.substring(hashIndex) : "",
|
|
175
|
-
search: searchIndex > -1 ? href.slice(searchIndex, hashIndex === -1 ? void 0 : hashIndex) : "",
|
|
176
|
-
state: state || {}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function createRandomKey() {
|
|
180
|
-
return (Math.random() + 1).toString(36).substring(7);
|
|
181
|
-
}
|
|
182
|
-
var isProduction$1 = !0, prefix = "Invariant failed";
|
|
183
|
-
function invariant(condition, message) {
|
|
184
|
-
if (!condition) {
|
|
185
|
-
if (isProduction$1)
|
|
186
|
-
throw new Error(prefix);
|
|
187
|
-
var provided = typeof message == "function" ? message() : message, value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
188
|
-
throw new Error(value);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
var isProduction = !0;
|
|
192
|
-
function warning(condition, message) {
|
|
193
|
-
if (!isProduction) {
|
|
194
|
-
if (condition)
|
|
195
|
-
return;
|
|
196
|
-
var text = "Warning: " + message;
|
|
197
|
-
typeof console < "u" && console.warn(text);
|
|
198
|
-
try {
|
|
199
|
-
throw Error(text);
|
|
200
|
-
} catch {
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
const routerContext = React.createContext(null);
|
|
205
|
-
function getRouterContext() {
|
|
206
|
-
return typeof document > "u" ? routerContext : window.__TSR_ROUTER_CONTEXT__ ? window.__TSR_ROUTER_CONTEXT__ : (window.__TSR_ROUTER_CONTEXT__ = routerContext, routerContext);
|
|
207
|
-
}
|
|
208
|
-
function useRouter(opts) {
|
|
209
|
-
const value = React.useContext(getRouterContext());
|
|
210
|
-
return warning(
|
|
211
|
-
!((opts?.warn ?? !0) && !value),
|
|
212
|
-
"useRouter must be used inside a <RouterProvider> component!"
|
|
213
|
-
), value;
|
|
214
|
-
}
|
|
215
|
-
class Store {
|
|
216
|
-
constructor(initialState, options) {
|
|
217
|
-
this.listeners = /* @__PURE__ */ new Set(), this._batching = !1, this._flushing = 0, this.subscribe = (listener) => {
|
|
218
|
-
var _a, _b;
|
|
219
|
-
this.listeners.add(listener);
|
|
220
|
-
const unsub = (_b = (_a = this.options) == null ? void 0 : _a.onSubscribe) == null ? void 0 : _b.call(_a, listener, this);
|
|
221
|
-
return () => {
|
|
222
|
-
this.listeners.delete(listener), unsub?.();
|
|
223
|
-
};
|
|
224
|
-
}, this.setState = (updater) => {
|
|
225
|
-
var _a, _b, _c;
|
|
226
|
-
const previous = this.state;
|
|
227
|
-
this.state = (_a = this.options) != null && _a.updateFn ? this.options.updateFn(previous)(updater) : updater(previous), (_c = (_b = this.options) == null ? void 0 : _b.onUpdate) == null || _c.call(_b), this._flush();
|
|
228
|
-
}, this._flush = () => {
|
|
229
|
-
if (this._batching) return;
|
|
230
|
-
const flushId = ++this._flushing;
|
|
231
|
-
this.listeners.forEach((listener) => {
|
|
232
|
-
this._flushing === flushId && listener();
|
|
233
|
-
});
|
|
234
|
-
}, this.batch = (cb) => {
|
|
235
|
-
if (this._batching) return cb();
|
|
236
|
-
this._batching = !0, cb(), this._batching = !1, this._flush();
|
|
237
|
-
}, this.state = initialState, this.options = options;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
function useStore(store, selector = (d) => d) {
|
|
241
|
-
return withSelectorExports.useSyncExternalStoreWithSelector(
|
|
242
|
-
store.subscribe,
|
|
243
|
-
() => store.state,
|
|
244
|
-
() => store.state,
|
|
245
|
-
selector,
|
|
246
|
-
shallow
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
function shallow(objA, objB) {
|
|
250
|
-
if (Object.is(objA, objB))
|
|
251
|
-
return !0;
|
|
252
|
-
if (typeof objA != "object" || objA === null || typeof objB != "object" || objB === null)
|
|
253
|
-
return !1;
|
|
254
|
-
const keysA = Object.keys(objA);
|
|
255
|
-
if (keysA.length !== Object.keys(objB).length)
|
|
256
|
-
return !1;
|
|
257
|
-
for (let i = 0; i < keysA.length; i++)
|
|
258
|
-
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]]))
|
|
259
|
-
return !1;
|
|
260
|
-
return !0;
|
|
261
|
-
}
|
|
262
|
-
const rootRouteId = "__root__";
|
|
263
|
-
function encode(obj, pfx) {
|
|
264
|
-
let k, i, tmp, str = "";
|
|
265
|
-
for (k in obj)
|
|
266
|
-
if ((tmp = obj[k]) !== void 0)
|
|
267
|
-
if (Array.isArray(tmp))
|
|
268
|
-
for (i = 0; i < tmp.length; i++)
|
|
269
|
-
str && (str += "&"), str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp[i]);
|
|
270
|
-
else
|
|
271
|
-
str && (str += "&"), str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp);
|
|
272
|
-
return "" + str;
|
|
273
|
-
}
|
|
274
|
-
function toValue(mix) {
|
|
275
|
-
if (!mix) return "";
|
|
276
|
-
const str = decodeURIComponent(mix);
|
|
277
|
-
return str === "false" ? !1 : str === "true" ? !0 : +str * 0 === 0 && +str + "" === str ? +str : str;
|
|
278
|
-
}
|
|
279
|
-
function decode(str, pfx) {
|
|
280
|
-
let tmp, k;
|
|
281
|
-
const out = {}, arr = str.split("&");
|
|
282
|
-
for (; tmp = arr.shift(); ) {
|
|
283
|
-
const equalIndex = tmp.indexOf("=");
|
|
284
|
-
if (equalIndex !== -1) {
|
|
285
|
-
k = tmp.slice(0, equalIndex);
|
|
286
|
-
const value = tmp.slice(equalIndex + 1);
|
|
287
|
-
out[k] !== void 0 ? out[k] = [].concat(out[k], toValue(value)) : out[k] = toValue(value);
|
|
288
|
-
} else
|
|
289
|
-
k = tmp, out[k] = "";
|
|
290
|
-
}
|
|
291
|
-
return out;
|
|
292
|
-
}
|
|
293
|
-
const defaultParseSearch = parseSearchWith(JSON.parse), defaultStringifySearch = stringifySearchWith(
|
|
294
|
-
JSON.stringify,
|
|
295
|
-
JSON.parse
|
|
296
|
-
);
|
|
297
|
-
function parseSearchWith(parser) {
|
|
298
|
-
return (searchStr) => {
|
|
299
|
-
searchStr.substring(0, 1) === "?" && (searchStr = searchStr.substring(1));
|
|
300
|
-
const query = decode(searchStr);
|
|
301
|
-
for (const key in query) {
|
|
302
|
-
const value = query[key];
|
|
303
|
-
if (typeof value == "string")
|
|
304
|
-
try {
|
|
305
|
-
query[key] = parser(value);
|
|
306
|
-
} catch {
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return query;
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
function stringifySearchWith(stringify, parser) {
|
|
313
|
-
function stringifyValue(val) {
|
|
314
|
-
if (typeof val == "object" && val !== null)
|
|
315
|
-
try {
|
|
316
|
-
return stringify(val);
|
|
317
|
-
} catch {
|
|
318
|
-
}
|
|
319
|
-
else if (typeof val == "string" && typeof parser == "function")
|
|
320
|
-
try {
|
|
321
|
-
return parser(val), stringify(val);
|
|
322
|
-
} catch {
|
|
323
|
-
}
|
|
324
|
-
return val;
|
|
325
|
-
}
|
|
326
|
-
return (search) => {
|
|
327
|
-
search = { ...search }, Object.keys(search).forEach((key) => {
|
|
328
|
-
const val = search[key];
|
|
329
|
-
typeof val > "u" || val === void 0 ? delete search[key] : search[key] = stringifyValue(val);
|
|
330
|
-
});
|
|
331
|
-
const searchStr = encode(search).toString();
|
|
332
|
-
return searchStr ? `?${searchStr}` : "";
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
function last(arr) {
|
|
336
|
-
return arr[arr.length - 1];
|
|
337
|
-
}
|
|
338
|
-
function isFunction(d) {
|
|
339
|
-
return typeof d == "function";
|
|
340
|
-
}
|
|
341
|
-
function functionalUpdate(updater, previous) {
|
|
342
|
-
return isFunction(updater) ? updater(previous) : updater;
|
|
343
|
-
}
|
|
344
|
-
function pick(parent, keys) {
|
|
345
|
-
return keys.reduce((obj, key) => (obj[key] = parent[key], obj), {});
|
|
346
|
-
}
|
|
347
|
-
function replaceEqualDeep(prev, _next) {
|
|
348
|
-
if (prev === _next)
|
|
349
|
-
return prev;
|
|
350
|
-
const next = _next, array = isPlainArray(prev) && isPlainArray(next);
|
|
351
|
-
if (array || isPlainObject(prev) && isPlainObject(next)) {
|
|
352
|
-
const prevItems = array ? prev : Object.keys(prev), prevSize = prevItems.length, nextItems = array ? next : Object.keys(next), nextSize = nextItems.length, copy = array ? [] : {};
|
|
353
|
-
let equalItems = 0;
|
|
354
|
-
for (let i = 0; i < nextSize; i++) {
|
|
355
|
-
const key = array ? i : nextItems[i];
|
|
356
|
-
(!array && prevItems.includes(key) || array) && prev[key] === void 0 && next[key] === void 0 ? (copy[key] = void 0, equalItems++) : (copy[key] = replaceEqualDeep(prev[key], next[key]), copy[key] === prev[key] && prev[key] !== void 0 && equalItems++);
|
|
357
|
-
}
|
|
358
|
-
return prevSize === nextSize && equalItems === prevSize ? prev : copy;
|
|
359
|
-
}
|
|
360
|
-
return next;
|
|
361
|
-
}
|
|
362
|
-
function isPlainObject(o) {
|
|
363
|
-
if (!hasObjectPrototype(o))
|
|
364
|
-
return !1;
|
|
365
|
-
const ctor = o.constructor;
|
|
366
|
-
if (typeof ctor > "u")
|
|
367
|
-
return !0;
|
|
368
|
-
const prot = ctor.prototype;
|
|
369
|
-
return !(!hasObjectPrototype(prot) || !prot.hasOwnProperty("isPrototypeOf"));
|
|
370
|
-
}
|
|
371
|
-
function hasObjectPrototype(o) {
|
|
372
|
-
return Object.prototype.toString.call(o) === "[object Object]";
|
|
373
|
-
}
|
|
374
|
-
function isPlainArray(value) {
|
|
375
|
-
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
376
|
-
}
|
|
377
|
-
function deepEqual(a, b, partial = !1) {
|
|
378
|
-
if (a === b)
|
|
379
|
-
return !0;
|
|
380
|
-
if (typeof a != typeof b)
|
|
381
|
-
return !1;
|
|
382
|
-
if (isPlainObject(a) && isPlainObject(b)) {
|
|
383
|
-
const aKeys = Object.keys(a).filter((key) => a[key] !== void 0), bKeys = Object.keys(b).filter((key) => b[key] !== void 0);
|
|
384
|
-
return !partial && aKeys.length !== bKeys.length ? !1 : !bKeys.some(
|
|
385
|
-
(key) => !(key in a) || !deepEqual(a[key], b[key], partial)
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
return Array.isArray(a) && Array.isArray(b) ? a.length !== b.length ? !1 : !a.some((item, index) => !deepEqual(item, b[index], partial)) : !1;
|
|
389
|
-
}
|
|
390
|
-
const useLayoutEffect$1 = typeof window < "u" ? React.useLayoutEffect : React.useEffect;
|
|
391
|
-
function createControlledPromise(onResolve) {
|
|
392
|
-
let resolveLoadPromise, rejectLoadPromise;
|
|
393
|
-
const controlledPromise = new Promise((resolve, reject) => {
|
|
394
|
-
resolveLoadPromise = resolve, rejectLoadPromise = reject;
|
|
395
|
-
});
|
|
396
|
-
return controlledPromise.status = "pending", controlledPromise.resolve = (value) => {
|
|
397
|
-
controlledPromise.status = "resolved", controlledPromise.value = value, resolveLoadPromise(value), onResolve?.(value);
|
|
398
|
-
}, controlledPromise.reject = (e) => {
|
|
399
|
-
controlledPromise.status = "rejected", rejectLoadPromise(e);
|
|
400
|
-
}, controlledPromise;
|
|
401
|
-
}
|
|
402
|
-
function usePrevious(value) {
|
|
403
|
-
const ref = React.useRef({
|
|
404
|
-
value,
|
|
405
|
-
prev: null
|
|
406
|
-
}), current = ref.current.value;
|
|
407
|
-
return value !== current && (ref.current = {
|
|
408
|
-
value,
|
|
409
|
-
prev: current
|
|
410
|
-
}), ref.current.prev;
|
|
411
|
-
}
|
|
412
|
-
function joinPaths(paths) {
|
|
413
|
-
return cleanPath(
|
|
414
|
-
paths.filter((val) => val !== void 0).join("/")
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
function cleanPath(path) {
|
|
418
|
-
return path.replace(/\/{2,}/g, "/");
|
|
419
|
-
}
|
|
420
|
-
function trimPathLeft(path) {
|
|
421
|
-
return path === "/" ? path : path.replace(/^\/{1,}/, "");
|
|
422
|
-
}
|
|
423
|
-
function trimPathRight(path) {
|
|
424
|
-
return path === "/" ? path : path.replace(/\/{1,}$/, "");
|
|
425
|
-
}
|
|
426
|
-
function trimPath(path) {
|
|
427
|
-
return trimPathRight(trimPathLeft(path));
|
|
428
|
-
}
|
|
429
|
-
function removeTrailingSlash(value, basepath) {
|
|
430
|
-
return value.endsWith("/") && value !== "/" && value !== `${basepath}/` ? value.slice(0, -1) : value;
|
|
431
|
-
}
|
|
432
|
-
function exactPathTest(pathName1, pathName2, basepath) {
|
|
433
|
-
return removeTrailingSlash(pathName1, basepath) === removeTrailingSlash(pathName2, basepath);
|
|
434
|
-
}
|
|
435
|
-
function resolvePath({
|
|
436
|
-
basepath,
|
|
437
|
-
base,
|
|
438
|
-
to,
|
|
439
|
-
trailingSlash = "never"
|
|
440
|
-
}) {
|
|
441
|
-
var _a, _b;
|
|
442
|
-
base = removeBasepath(basepath, base), to = removeBasepath(basepath, to);
|
|
443
|
-
let baseSegments = parsePathname(base);
|
|
444
|
-
const toSegments = parsePathname(to);
|
|
445
|
-
baseSegments.length > 1 && ((_a = last(baseSegments)) == null ? void 0 : _a.value) === "/" && baseSegments.pop(), toSegments.forEach((toSegment, index) => {
|
|
446
|
-
toSegment.value === "/" ? index ? index === toSegments.length - 1 && baseSegments.push(toSegment) : baseSegments = [toSegment] : toSegment.value === ".." ? baseSegments.pop() : toSegment.value === "." || baseSegments.push(toSegment);
|
|
447
|
-
}), baseSegments.length > 1 && (((_b = last(baseSegments)) == null ? void 0 : _b.value) === "/" ? trailingSlash === "never" && baseSegments.pop() : trailingSlash === "always" && baseSegments.push({ type: "pathname", value: "/" }));
|
|
448
|
-
const joined = joinPaths([basepath, ...baseSegments.map((d) => d.value)]);
|
|
449
|
-
return cleanPath(joined);
|
|
450
|
-
}
|
|
451
|
-
function parsePathname(pathname) {
|
|
452
|
-
if (!pathname)
|
|
453
|
-
return [];
|
|
454
|
-
pathname = cleanPath(pathname);
|
|
455
|
-
const segments = [];
|
|
456
|
-
if (pathname.slice(0, 1) === "/" && (pathname = pathname.substring(1), segments.push({
|
|
457
|
-
type: "pathname",
|
|
458
|
-
value: "/"
|
|
459
|
-
})), !pathname)
|
|
460
|
-
return segments;
|
|
461
|
-
const split = pathname.split("/").filter(Boolean);
|
|
462
|
-
return segments.push(
|
|
463
|
-
...split.map((part) => part === "$" || part === "*" ? {
|
|
464
|
-
type: "wildcard",
|
|
465
|
-
value: part
|
|
466
|
-
} : part.charAt(0) === "$" ? {
|
|
467
|
-
type: "param",
|
|
468
|
-
value: part
|
|
469
|
-
} : {
|
|
470
|
-
type: "pathname",
|
|
471
|
-
value: decodeURIComponent(part)
|
|
472
|
-
})
|
|
473
|
-
), pathname.slice(-1) === "/" && (pathname = pathname.substring(1), segments.push({
|
|
474
|
-
type: "pathname",
|
|
475
|
-
value: "/"
|
|
476
|
-
})), segments;
|
|
477
|
-
}
|
|
478
|
-
function interpolatePath({
|
|
479
|
-
path,
|
|
480
|
-
params,
|
|
481
|
-
leaveWildcards,
|
|
482
|
-
leaveParams
|
|
483
|
-
}) {
|
|
484
|
-
const interpolatedPathSegments = parsePathname(path), encodedParams = {};
|
|
485
|
-
for (const [key, value] of Object.entries(params)) {
|
|
486
|
-
const isValueString = typeof value == "string";
|
|
487
|
-
["*", "_splat"].includes(key) ? encodedParams[key] = isValueString ? encodeURI(value) : value : encodedParams[key] = isValueString ? encodeURIComponent(value) : value;
|
|
488
|
-
}
|
|
489
|
-
return joinPaths(
|
|
490
|
-
interpolatedPathSegments.map((segment) => {
|
|
491
|
-
if (segment.type === "wildcard") {
|
|
492
|
-
const value = encodedParams._splat;
|
|
493
|
-
return leaveWildcards ? `${segment.value}${value ?? ""}` : value;
|
|
494
|
-
}
|
|
495
|
-
if (segment.type === "param") {
|
|
496
|
-
if (leaveParams) {
|
|
497
|
-
const value = encodedParams[segment.value];
|
|
498
|
-
return `${segment.value}${value ?? ""}`;
|
|
499
|
-
}
|
|
500
|
-
return encodedParams[segment.value.substring(1)] ?? "undefined";
|
|
501
|
-
}
|
|
502
|
-
return segment.value;
|
|
503
|
-
})
|
|
504
|
-
);
|
|
505
|
-
}
|
|
506
|
-
function matchPathname(basepath, currentPathname, matchLocation) {
|
|
507
|
-
const pathParams = matchByPath(basepath, currentPathname, matchLocation);
|
|
508
|
-
if (!(matchLocation.to && !pathParams))
|
|
509
|
-
return pathParams ?? {};
|
|
510
|
-
}
|
|
511
|
-
function removeBasepath(basepath, pathname) {
|
|
512
|
-
switch (!0) {
|
|
513
|
-
case basepath === "/":
|
|
514
|
-
return pathname;
|
|
515
|
-
case pathname === basepath:
|
|
516
|
-
return "";
|
|
517
|
-
case pathname.length < basepath.length:
|
|
518
|
-
return pathname;
|
|
519
|
-
case pathname[basepath.length] !== "/":
|
|
520
|
-
return pathname;
|
|
521
|
-
case pathname.startsWith(basepath):
|
|
522
|
-
return pathname.slice(basepath.length);
|
|
523
|
-
default:
|
|
524
|
-
return pathname;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
function matchByPath(basepath, from, matchLocation) {
|
|
528
|
-
from = removeBasepath(basepath, from);
|
|
529
|
-
const to = removeBasepath(basepath, `${matchLocation.to ?? "$"}`), baseSegments = parsePathname(from), routeSegments = parsePathname(to);
|
|
530
|
-
from.startsWith("/") || baseSegments.unshift({
|
|
531
|
-
type: "pathname",
|
|
532
|
-
value: "/"
|
|
533
|
-
}), to.startsWith("/") || routeSegments.unshift({
|
|
534
|
-
type: "pathname",
|
|
535
|
-
value: "/"
|
|
536
|
-
});
|
|
537
|
-
const params = {};
|
|
538
|
-
return (() => {
|
|
539
|
-
for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
|
|
540
|
-
const baseSegment = baseSegments[i], routeSegment = routeSegments[i], isLastBaseSegment = i >= baseSegments.length - 1, isLastRouteSegment = i >= routeSegments.length - 1;
|
|
541
|
-
if (routeSegment) {
|
|
542
|
-
if (routeSegment.type === "wildcard") {
|
|
543
|
-
if (baseSegment?.value) {
|
|
544
|
-
const _splat = decodeURI(
|
|
545
|
-
joinPaths(baseSegments.slice(i).map((d) => d.value))
|
|
546
|
-
);
|
|
547
|
-
return params["*"] = _splat, params._splat = _splat, !0;
|
|
548
|
-
}
|
|
549
|
-
return !1;
|
|
550
|
-
}
|
|
551
|
-
if (routeSegment.type === "pathname") {
|
|
552
|
-
if (routeSegment.value === "/" && !baseSegment?.value)
|
|
553
|
-
return !0;
|
|
554
|
-
if (baseSegment) {
|
|
555
|
-
if (matchLocation.caseSensitive) {
|
|
556
|
-
if (routeSegment.value !== baseSegment.value)
|
|
557
|
-
return !1;
|
|
558
|
-
} else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase())
|
|
559
|
-
return !1;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
if (!baseSegment)
|
|
563
|
-
return !1;
|
|
564
|
-
if (routeSegment.type === "param") {
|
|
565
|
-
if (baseSegment.value === "/")
|
|
566
|
-
return !1;
|
|
567
|
-
baseSegment.value.charAt(0) !== "$" && (params[routeSegment.value.substring(1)] = decodeURIComponent(
|
|
568
|
-
baseSegment.value
|
|
569
|
-
));
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
if (!isLastBaseSegment && isLastRouteSegment)
|
|
573
|
-
return params["**"] = joinPaths(baseSegments.slice(i + 1).map((d) => d.value)), !!matchLocation.fuzzy && routeSegment?.value !== "/";
|
|
574
|
-
}
|
|
575
|
-
return !0;
|
|
576
|
-
})() ? params : void 0;
|
|
577
|
-
}
|
|
578
|
-
function isRedirect(obj) {
|
|
579
|
-
return !!obj?.isRedirect;
|
|
580
|
-
}
|
|
581
|
-
function isResolvedRedirect(obj) {
|
|
582
|
-
return !!obj?.isRedirect && obj.href;
|
|
583
|
-
}
|
|
584
|
-
function CatchBoundary(props) {
|
|
585
|
-
const errorComponent = props.errorComponent ?? ErrorComponent;
|
|
586
|
-
return /* @__PURE__ */ jsx(
|
|
587
|
-
CatchBoundaryImpl,
|
|
588
|
-
{
|
|
589
|
-
getResetKey: props.getResetKey,
|
|
590
|
-
onCatch: props.onCatch,
|
|
591
|
-
children: ({ error, reset }) => error ? React.createElement(errorComponent, {
|
|
592
|
-
error,
|
|
593
|
-
reset
|
|
594
|
-
}) : props.children
|
|
595
|
-
}
|
|
596
|
-
);
|
|
597
|
-
}
|
|
598
|
-
class CatchBoundaryImpl extends React.Component {
|
|
599
|
-
constructor() {
|
|
600
|
-
super(...arguments), this.state = { error: null };
|
|
601
|
-
}
|
|
602
|
-
static getDerivedStateFromProps(props) {
|
|
603
|
-
return { resetKey: props.getResetKey() };
|
|
604
|
-
}
|
|
605
|
-
static getDerivedStateFromError(error) {
|
|
606
|
-
return { error };
|
|
607
|
-
}
|
|
608
|
-
reset() {
|
|
609
|
-
this.setState({ error: null });
|
|
610
|
-
}
|
|
611
|
-
componentDidUpdate(prevProps, prevState) {
|
|
612
|
-
prevState.error && prevState.resetKey !== this.state.resetKey && this.reset();
|
|
613
|
-
}
|
|
614
|
-
componentDidCatch(error, errorInfo) {
|
|
615
|
-
this.props.onCatch && this.props.onCatch(error, errorInfo);
|
|
616
|
-
}
|
|
617
|
-
render() {
|
|
618
|
-
return this.props.children({
|
|
619
|
-
error: this.state.resetKey !== this.props.getResetKey() ? null : this.state.error,
|
|
620
|
-
reset: () => {
|
|
621
|
-
this.reset();
|
|
622
|
-
}
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
function ErrorComponent({ error }) {
|
|
627
|
-
const [show, setShow] = React.useState(!1);
|
|
628
|
-
return /* @__PURE__ */ jsxs("div", { style: { padding: ".5rem", maxWidth: "100%" }, children: [
|
|
629
|
-
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: ".5rem" }, children: [
|
|
630
|
-
/* @__PURE__ */ jsx("strong", { style: { fontSize: "1rem" }, children: "Something went wrong!" }),
|
|
631
|
-
/* @__PURE__ */ jsx(
|
|
632
|
-
"button",
|
|
633
|
-
{
|
|
634
|
-
style: {
|
|
635
|
-
appearance: "none",
|
|
636
|
-
fontSize: ".6em",
|
|
637
|
-
border: "1px solid currentColor",
|
|
638
|
-
padding: ".1rem .2rem",
|
|
639
|
-
fontWeight: "bold",
|
|
640
|
-
borderRadius: ".25rem"
|
|
641
|
-
},
|
|
642
|
-
onClick: () => setShow((d) => !d),
|
|
643
|
-
children: show ? "Hide Error" : "Show Error"
|
|
644
|
-
}
|
|
645
|
-
)
|
|
646
|
-
] }),
|
|
647
|
-
/* @__PURE__ */ jsx("div", { style: { height: ".25rem" } }),
|
|
648
|
-
show ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
|
|
649
|
-
"pre",
|
|
650
|
-
{
|
|
651
|
-
style: {
|
|
652
|
-
fontSize: ".7em",
|
|
653
|
-
border: "1px solid red",
|
|
654
|
-
borderRadius: ".25rem",
|
|
655
|
-
padding: ".3rem",
|
|
656
|
-
color: "red",
|
|
657
|
-
overflow: "auto"
|
|
658
|
-
},
|
|
659
|
-
children: error.message ? /* @__PURE__ */ jsx("code", { children: error.message }) : null
|
|
660
|
-
}
|
|
661
|
-
) }) : null
|
|
662
|
-
] });
|
|
663
|
-
}
|
|
664
|
-
function useRouterState(opts) {
|
|
665
|
-
const contextRouter = useRouter({
|
|
666
|
-
warn: opts?.router === void 0
|
|
667
|
-
});
|
|
668
|
-
return useStore((opts?.router || contextRouter).__store, opts?.select);
|
|
669
|
-
}
|
|
670
|
-
function notFound(options = {}) {
|
|
671
|
-
if (options.isNotFound = !0, options.throw) throw options;
|
|
672
|
-
return options;
|
|
673
|
-
}
|
|
674
|
-
function isNotFound(obj) {
|
|
675
|
-
return !!obj?.isNotFound;
|
|
676
|
-
}
|
|
677
|
-
function CatchNotFound(props) {
|
|
678
|
-
const resetKey = useRouterState({
|
|
679
|
-
select: (s) => `not-found-${s.location.pathname}-${s.status}`
|
|
680
|
-
});
|
|
681
|
-
return /* @__PURE__ */ jsx(
|
|
682
|
-
CatchBoundary,
|
|
683
|
-
{
|
|
684
|
-
getResetKey: () => resetKey,
|
|
685
|
-
onCatch: (error, errorInfo) => {
|
|
686
|
-
var _a;
|
|
687
|
-
if (isNotFound(error))
|
|
688
|
-
(_a = props.onCatch) == null || _a.call(props, error, errorInfo);
|
|
689
|
-
else
|
|
690
|
-
throw error;
|
|
691
|
-
},
|
|
692
|
-
errorComponent: ({ error }) => {
|
|
693
|
-
var _a;
|
|
694
|
-
return (_a = props.fallback) == null ? void 0 : _a.call(props, error);
|
|
695
|
-
},
|
|
696
|
-
children: props.children
|
|
697
|
-
}
|
|
698
|
-
);
|
|
699
|
-
}
|
|
700
|
-
function DefaultGlobalNotFound() {
|
|
701
|
-
return /* @__PURE__ */ jsx("p", { children: "Not Found" });
|
|
702
|
-
}
|
|
703
|
-
const componentTypes = [
|
|
704
|
-
"component",
|
|
705
|
-
"errorComponent",
|
|
706
|
-
"pendingComponent",
|
|
707
|
-
"notFoundComponent"
|
|
708
|
-
];
|
|
709
|
-
function createRouter(options) {
|
|
710
|
-
return new Router(options);
|
|
711
|
-
}
|
|
712
|
-
class Router {
|
|
713
|
-
/**
|
|
714
|
-
* @deprecated Use the `createRouter` function instead
|
|
715
|
-
*/
|
|
716
|
-
constructor(options) {
|
|
717
|
-
this.tempLocationKey = `${Math.round(
|
|
718
|
-
Math.random() * 1e7
|
|
719
|
-
)}`, this.resetNextScroll = !0, this.shouldViewTransition = void 0, this.subscribers = /* @__PURE__ */ new Set(), this.startReactTransition = (fn) => fn(), this.update = (newOptions) => {
|
|
720
|
-
newOptions.notFoundRoute && console.warn(
|
|
721
|
-
"The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/guide/not-found-errors#migrating-from-notfoundroute for more info."
|
|
722
|
-
);
|
|
723
|
-
const previousOptions = this.options;
|
|
724
|
-
this.options = {
|
|
725
|
-
...this.options,
|
|
726
|
-
...newOptions
|
|
727
|
-
}, this.isServer = this.options.isServer ?? typeof document > "u", (!this.basepath || newOptions.basepath && newOptions.basepath !== previousOptions.basepath) && (newOptions.basepath === void 0 || newOptions.basepath === "" || newOptions.basepath === "/" ? this.basepath = "/" : this.basepath = `/${trimPath(newOptions.basepath)}`), // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
728
|
-
(!this.history || this.options.history && this.options.history !== this.history) && (this.history = this.options.history ?? (this.isServer ? createMemoryHistory({
|
|
729
|
-
initialEntries: [this.basepath || "/"]
|
|
730
|
-
}) : createBrowserHistory()), this.latestLocation = this.parseLocation()), this.options.routeTree !== this.routeTree && (this.routeTree = this.options.routeTree, this.buildRouteTree()), this.__store || (this.__store = new Store(getInitialRouterState(this.latestLocation), {
|
|
731
|
-
onUpdate: () => {
|
|
732
|
-
this.__store.state = {
|
|
733
|
-
...this.state,
|
|
734
|
-
cachedMatches: this.state.cachedMatches.filter(
|
|
735
|
-
(d) => !["redirected"].includes(d.status)
|
|
736
|
-
)
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
}));
|
|
740
|
-
}, this.buildRouteTree = () => {
|
|
741
|
-
this.routesById = {}, this.routesByPath = {};
|
|
742
|
-
const notFoundRoute = this.options.notFoundRoute;
|
|
743
|
-
notFoundRoute && (notFoundRoute.init({ originalIndex: 99999999999 }), this.routesById[notFoundRoute.id] = notFoundRoute);
|
|
744
|
-
const recurseRoutes = (childRoutes) => {
|
|
745
|
-
childRoutes.forEach((childRoute, i) => {
|
|
746
|
-
childRoute.init({ originalIndex: i });
|
|
747
|
-
const existingRoute = this.routesById[childRoute.id];
|
|
748
|
-
if (invariant(
|
|
749
|
-
!existingRoute,
|
|
750
|
-
`Duplicate routes found with id: ${String(childRoute.id)}`
|
|
751
|
-
), this.routesById[childRoute.id] = childRoute, !childRoute.isRoot && childRoute.path) {
|
|
752
|
-
const trimmedFullPath = trimPathRight(childRoute.fullPath);
|
|
753
|
-
(!this.routesByPath[trimmedFullPath] || childRoute.fullPath.endsWith("/")) && (this.routesByPath[trimmedFullPath] = childRoute);
|
|
754
|
-
}
|
|
755
|
-
const children = childRoute.children;
|
|
756
|
-
children?.length && recurseRoutes(children);
|
|
757
|
-
});
|
|
758
|
-
};
|
|
759
|
-
recurseRoutes([this.routeTree]);
|
|
760
|
-
const scoredRoutes = [];
|
|
761
|
-
Object.values(this.routesById).forEach((d, i) => {
|
|
762
|
-
var _a;
|
|
763
|
-
if (d.isRoot || !d.path)
|
|
764
|
-
return;
|
|
765
|
-
const trimmed = trimPathLeft(d.fullPath), parsed = parsePathname(trimmed);
|
|
766
|
-
for (; parsed.length > 1 && ((_a = parsed[0]) == null ? void 0 : _a.value) === "/"; )
|
|
767
|
-
parsed.shift();
|
|
768
|
-
const scores = parsed.map((segment) => segment.value === "/" ? 0.75 : segment.type === "param" ? 0.5 : segment.type === "wildcard" ? 0.25 : 1);
|
|
769
|
-
scoredRoutes.push({ child: d, trimmed, parsed, index: i, scores });
|
|
770
|
-
}), this.flatRoutes = scoredRoutes.sort((a, b) => {
|
|
771
|
-
const minLength = Math.min(a.scores.length, b.scores.length);
|
|
772
|
-
for (let i = 0; i < minLength; i++)
|
|
773
|
-
if (a.scores[i] !== b.scores[i])
|
|
774
|
-
return b.scores[i] - a.scores[i];
|
|
775
|
-
if (a.scores.length !== b.scores.length)
|
|
776
|
-
return b.scores.length - a.scores.length;
|
|
777
|
-
for (let i = 0; i < minLength; i++)
|
|
778
|
-
if (a.parsed[i].value !== b.parsed[i].value)
|
|
779
|
-
return a.parsed[i].value > b.parsed[i].value ? 1 : -1;
|
|
780
|
-
return a.index - b.index;
|
|
781
|
-
}).map((d, i) => (d.child.rank = i, d.child));
|
|
782
|
-
}, this.subscribe = (eventType, fn) => {
|
|
783
|
-
const listener = {
|
|
784
|
-
eventType,
|
|
785
|
-
fn
|
|
786
|
-
};
|
|
787
|
-
return this.subscribers.add(listener), () => {
|
|
788
|
-
this.subscribers.delete(listener);
|
|
789
|
-
};
|
|
790
|
-
}, this.emit = (routerEvent) => {
|
|
791
|
-
this.subscribers.forEach((listener) => {
|
|
792
|
-
listener.eventType === routerEvent.type && listener.fn(routerEvent);
|
|
793
|
-
});
|
|
794
|
-
}, this.parseLocation = (previousLocation) => {
|
|
795
|
-
const parse = ({
|
|
796
|
-
pathname,
|
|
797
|
-
search,
|
|
798
|
-
hash,
|
|
799
|
-
state
|
|
800
|
-
}) => {
|
|
801
|
-
const parsedSearch = this.options.parseSearch(search), searchStr = this.options.stringifySearch(parsedSearch);
|
|
802
|
-
return {
|
|
803
|
-
pathname,
|
|
804
|
-
searchStr,
|
|
805
|
-
search: replaceEqualDeep(previousLocation?.search, parsedSearch),
|
|
806
|
-
hash: hash.split("#").reverse()[0] ?? "",
|
|
807
|
-
href: `${pathname}${searchStr}${hash}`,
|
|
808
|
-
state: replaceEqualDeep(previousLocation?.state, state)
|
|
809
|
-
};
|
|
810
|
-
}, location = parse(this.history.location), { __tempLocation, __tempKey } = location.state;
|
|
811
|
-
if (__tempLocation && (!__tempKey || __tempKey === this.tempLocationKey)) {
|
|
812
|
-
const parsedTempLocation = parse(__tempLocation);
|
|
813
|
-
return parsedTempLocation.state.key = location.state.key, delete parsedTempLocation.state.__tempLocation, {
|
|
814
|
-
...parsedTempLocation,
|
|
815
|
-
maskedLocation: location
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
return location;
|
|
819
|
-
}, this.resolvePathWithBase = (from, path) => resolvePath({
|
|
820
|
-
basepath: this.basepath,
|
|
821
|
-
base: from,
|
|
822
|
-
to: cleanPath(path),
|
|
823
|
-
trailingSlash: this.options.trailingSlash
|
|
824
|
-
}), this.matchRoutes = (pathname, locationSearch, opts) => {
|
|
825
|
-
let routeParams = {};
|
|
826
|
-
const foundRoute = this.flatRoutes.find((route) => {
|
|
827
|
-
const matchedParams = matchPathname(
|
|
828
|
-
this.basepath,
|
|
829
|
-
trimPathRight(pathname),
|
|
830
|
-
{
|
|
831
|
-
to: route.fullPath,
|
|
832
|
-
caseSensitive: route.options.caseSensitive ?? this.options.caseSensitive,
|
|
833
|
-
fuzzy: !0
|
|
834
|
-
}
|
|
835
|
-
);
|
|
836
|
-
return matchedParams ? (routeParams = matchedParams, !0) : !1;
|
|
837
|
-
});
|
|
838
|
-
let routeCursor = foundRoute || this.routesById[rootRouteId];
|
|
839
|
-
const matchedRoutes = [routeCursor];
|
|
840
|
-
let isGlobalNotFound = !1;
|
|
841
|
-
for (// If we found a route, and it's not an index route and we have left over path
|
|
842
|
-
(foundRoute ? foundRoute.path !== "/" && routeParams["**"] : (
|
|
843
|
-
// Or if we didn't find a route and we have left over path
|
|
844
|
-
trimPathRight(pathname)
|
|
845
|
-
)) && (this.options.notFoundRoute ? matchedRoutes.push(this.options.notFoundRoute) : isGlobalNotFound = !0); routeCursor.parentRoute; )
|
|
846
|
-
routeCursor = routeCursor.parentRoute, matchedRoutes.unshift(routeCursor);
|
|
847
|
-
const globalNotFoundRouteId = (() => {
|
|
848
|
-
if (isGlobalNotFound) {
|
|
849
|
-
if (this.options.notFoundMode !== "root")
|
|
850
|
-
for (let i = matchedRoutes.length - 1; i >= 0; i--) {
|
|
851
|
-
const route = matchedRoutes[i];
|
|
852
|
-
if (route.children)
|
|
853
|
-
return route.id;
|
|
854
|
-
}
|
|
855
|
-
return rootRouteId;
|
|
856
|
-
}
|
|
857
|
-
})(), parseErrors = matchedRoutes.map((route) => {
|
|
858
|
-
var _a;
|
|
859
|
-
let parsedParamsError;
|
|
860
|
-
const parseParams = ((_a = route.options.params) == null ? void 0 : _a.parse) ?? route.options.parseParams;
|
|
861
|
-
if (parseParams)
|
|
862
|
-
try {
|
|
863
|
-
const parsedParams = parseParams(routeParams);
|
|
864
|
-
Object.assign(routeParams, parsedParams);
|
|
865
|
-
} catch (err) {
|
|
866
|
-
if (parsedParamsError = new PathParamError(err.message, {
|
|
867
|
-
cause: err
|
|
868
|
-
}), opts?.throwOnError)
|
|
869
|
-
throw parsedParamsError;
|
|
870
|
-
return parsedParamsError;
|
|
871
|
-
}
|
|
872
|
-
}), matches = [];
|
|
873
|
-
return matchedRoutes.forEach((route, index) => {
|
|
874
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
875
|
-
const parentMatch = matches[index - 1], [preMatchSearch, searchError] = (() => {
|
|
876
|
-
const parentSearch = parentMatch?.search ?? locationSearch;
|
|
877
|
-
try {
|
|
878
|
-
const validator = typeof route.options.validateSearch == "object" ? route.options.validateSearch.parse : route.options.validateSearch, search = validator?.(parentSearch) ?? {};
|
|
879
|
-
return [
|
|
880
|
-
{
|
|
881
|
-
...parentSearch,
|
|
882
|
-
...search
|
|
883
|
-
},
|
|
884
|
-
void 0
|
|
885
|
-
];
|
|
886
|
-
} catch (err) {
|
|
887
|
-
const searchParamError = new SearchParamError(err.message, {
|
|
888
|
-
cause: err
|
|
889
|
-
});
|
|
890
|
-
if (opts?.throwOnError)
|
|
891
|
-
throw searchParamError;
|
|
892
|
-
return [parentSearch, searchParamError];
|
|
893
|
-
}
|
|
894
|
-
})(), loaderDeps = ((_b = (_a = route.options).loaderDeps) == null ? void 0 : _b.call(_a, {
|
|
895
|
-
search: preMatchSearch
|
|
896
|
-
})) ?? "", loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "", interpolatedPath = interpolatePath({
|
|
897
|
-
path: route.fullPath,
|
|
898
|
-
params: routeParams
|
|
899
|
-
}), matchId = interpolatePath({
|
|
900
|
-
path: route.id,
|
|
901
|
-
params: routeParams,
|
|
902
|
-
leaveWildcards: !0
|
|
903
|
-
}) + loaderDepsHash, existingMatch = this.getMatch(matchId), cause = this.state.matches.find((d) => d.id === matchId) ? "stay" : "enter";
|
|
904
|
-
let match;
|
|
905
|
-
if (existingMatch)
|
|
906
|
-
match = {
|
|
907
|
-
...existingMatch,
|
|
908
|
-
cause,
|
|
909
|
-
params: routeParams
|
|
910
|
-
};
|
|
911
|
-
else {
|
|
912
|
-
const status = route.options.loader || route.options.beforeLoad || route.lazyFn ? "pending" : "success";
|
|
913
|
-
match = {
|
|
914
|
-
id: matchId,
|
|
915
|
-
index,
|
|
916
|
-
routeId: route.id,
|
|
917
|
-
params: routeParams,
|
|
918
|
-
pathname: joinPaths([this.basepath, interpolatedPath]),
|
|
919
|
-
updatedAt: Date.now(),
|
|
920
|
-
search: {},
|
|
921
|
-
searchError: void 0,
|
|
922
|
-
status,
|
|
923
|
-
isFetching: !1,
|
|
924
|
-
error: void 0,
|
|
925
|
-
paramsError: parseErrors[index],
|
|
926
|
-
routeContext: void 0,
|
|
927
|
-
context: void 0,
|
|
928
|
-
abortController: new AbortController(),
|
|
929
|
-
fetchCount: 0,
|
|
930
|
-
cause,
|
|
931
|
-
loaderDeps,
|
|
932
|
-
invalid: !1,
|
|
933
|
-
preload: !1,
|
|
934
|
-
links: (_d = (_c = route.options).links) == null ? void 0 : _d.call(_c),
|
|
935
|
-
scripts: (_f = (_e = route.options).scripts) == null ? void 0 : _f.call(_e),
|
|
936
|
-
staticData: route.options.staticData || {},
|
|
937
|
-
loadPromise: createControlledPromise()
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
match.status === "success" && (match.meta = (_h = (_g = route.options).meta) == null ? void 0 : _h.call(_g, {
|
|
941
|
-
matches,
|
|
942
|
-
match,
|
|
943
|
-
params: match.params,
|
|
944
|
-
loaderData: match.loaderData
|
|
945
|
-
}), match.headers = (_j = (_i = route.options).headers) == null ? void 0 : _j.call(_i, {
|
|
946
|
-
loaderData: match.loaderData
|
|
947
|
-
})), opts?.preload || (match.globalNotFound = globalNotFoundRouteId === route.id), match.search = replaceEqualDeep(match.search, preMatchSearch), match.searchError = searchError, matches.push(match);
|
|
948
|
-
}), matches;
|
|
949
|
-
}, this.cancelMatch = (id) => {
|
|
950
|
-
const match = this.getMatch(id);
|
|
951
|
-
match && (match.abortController.abort(), clearTimeout(match.pendingTimeout));
|
|
952
|
-
}, this.cancelMatches = () => {
|
|
953
|
-
var _a;
|
|
954
|
-
(_a = this.state.pendingMatches) == null || _a.forEach((match) => {
|
|
955
|
-
this.cancelMatch(match.id);
|
|
956
|
-
});
|
|
957
|
-
}, this.buildLocation = (opts) => {
|
|
958
|
-
const build = (dest = {}, matches) => {
|
|
959
|
-
var _a, _b, _c;
|
|
960
|
-
const fromMatches = dest._fromLocation != null ? this.matchRoutes(
|
|
961
|
-
dest._fromLocation.pathname,
|
|
962
|
-
dest.fromSearch || dest._fromLocation.search
|
|
963
|
-
) : this.state.matches, fromMatch = dest.from != null ? fromMatches.find(
|
|
964
|
-
(d) => matchPathname(this.basepath, trimPathRight(d.pathname), {
|
|
965
|
-
to: dest.from,
|
|
966
|
-
caseSensitive: !1,
|
|
967
|
-
fuzzy: !1
|
|
968
|
-
})
|
|
969
|
-
) : void 0, fromPath = fromMatch?.pathname || this.latestLocation.pathname;
|
|
970
|
-
invariant(
|
|
971
|
-
dest.from == null || fromMatch != null,
|
|
972
|
-
"Could not find match for from: " + dest.from
|
|
973
|
-
);
|
|
974
|
-
const fromSearch = ((_a = last(fromMatches)) == null ? void 0 : _a.search) || this.latestLocation.search, stayingMatches = matches?.filter(
|
|
975
|
-
(d) => fromMatches.find((e) => e.routeId === d.routeId)
|
|
976
|
-
), fromRouteByFromPathRouteId = this.routesById[(_b = stayingMatches?.find((d) => d.pathname === fromPath)) == null ? void 0 : _b.routeId];
|
|
977
|
-
let pathname = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(
|
|
978
|
-
fromPath,
|
|
979
|
-
fromRouteByFromPathRouteId?.to ?? fromPath
|
|
980
|
-
);
|
|
981
|
-
const prevParams = { ...(_c = last(fromMatches)) == null ? void 0 : _c.params };
|
|
982
|
-
let nextParams = (dest.params ?? !0) === !0 ? prevParams : { ...prevParams, ...functionalUpdate(dest.params, prevParams) };
|
|
983
|
-
Object.keys(nextParams).length > 0 && matches?.map((d) => {
|
|
984
|
-
var _a2;
|
|
985
|
-
const route = this.looseRoutesById[d.routeId];
|
|
986
|
-
return ((_a2 = route?.options.params) == null ? void 0 : _a2.stringify) ?? route.options.stringifyParams;
|
|
987
|
-
}).filter(Boolean).forEach((fn) => {
|
|
988
|
-
nextParams = { ...nextParams, ...fn(nextParams) };
|
|
989
|
-
}), pathname = interpolatePath({
|
|
990
|
-
path: pathname,
|
|
991
|
-
params: nextParams ?? {},
|
|
992
|
-
leaveWildcards: !1,
|
|
993
|
-
leaveParams: opts.leaveParams
|
|
994
|
-
});
|
|
995
|
-
const preSearchFilters = stayingMatches?.map(
|
|
996
|
-
(match) => this.looseRoutesById[match.routeId].options.preSearchFilters ?? []
|
|
997
|
-
).flat().filter(Boolean) ?? [], postSearchFilters = stayingMatches?.map(
|
|
998
|
-
(match) => this.looseRoutesById[match.routeId].options.postSearchFilters ?? []
|
|
999
|
-
).flat().filter(Boolean) ?? [], preFilteredSearch = preSearchFilters.length ? preSearchFilters.reduce((prev, next) => next(prev), fromSearch) : fromSearch, destSearch = dest.search === !0 ? preFilteredSearch : dest.search ? functionalUpdate(dest.search, preFilteredSearch) : preSearchFilters.length ? preFilteredSearch : {}, postFilteredSearch = postSearchFilters.length ? postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch, search = replaceEqualDeep(fromSearch, postFilteredSearch), searchStr = this.options.stringifySearch(search), hash = dest.hash === !0 ? this.latestLocation.hash : dest.hash ? functionalUpdate(dest.hash, this.latestLocation.hash) : void 0, hashStr = hash ? `#${hash}` : "";
|
|
1000
|
-
let nextState = dest.state === !0 ? this.latestLocation.state : dest.state ? functionalUpdate(dest.state, this.latestLocation.state) : {};
|
|
1001
|
-
return nextState = replaceEqualDeep(this.latestLocation.state, nextState), {
|
|
1002
|
-
pathname,
|
|
1003
|
-
search,
|
|
1004
|
-
searchStr,
|
|
1005
|
-
state: nextState,
|
|
1006
|
-
hash: hash ?? "",
|
|
1007
|
-
href: `${pathname}${searchStr}${hashStr}`,
|
|
1008
|
-
unmaskOnReload: dest.unmaskOnReload
|
|
1009
|
-
};
|
|
1010
|
-
}, buildWithMatches = (dest = {}, maskedDest) => {
|
|
1011
|
-
var _a;
|
|
1012
|
-
const next = build(dest);
|
|
1013
|
-
let maskedNext = maskedDest ? build(maskedDest) : void 0;
|
|
1014
|
-
if (!maskedNext) {
|
|
1015
|
-
let params = {};
|
|
1016
|
-
const foundMask = (_a = this.options.routeMasks) == null ? void 0 : _a.find((d) => {
|
|
1017
|
-
const match = matchPathname(this.basepath, next.pathname, {
|
|
1018
|
-
to: d.from,
|
|
1019
|
-
caseSensitive: !1,
|
|
1020
|
-
fuzzy: !1
|
|
1021
|
-
});
|
|
1022
|
-
return match ? (params = match, !0) : !1;
|
|
1023
|
-
});
|
|
1024
|
-
if (foundMask) {
|
|
1025
|
-
const { from, ...maskProps } = foundMask;
|
|
1026
|
-
maskedDest = {
|
|
1027
|
-
...pick(opts, ["from"]),
|
|
1028
|
-
...maskProps,
|
|
1029
|
-
params
|
|
1030
|
-
}, maskedNext = build(maskedDest);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
const nextMatches = this.matchRoutes(next.pathname, next.search), maskedMatches = maskedNext ? this.matchRoutes(maskedNext.pathname, maskedNext.search) : void 0, maskedFinal = maskedNext ? build(maskedDest, maskedMatches) : void 0, final = build(dest, nextMatches);
|
|
1034
|
-
return maskedFinal && (final.maskedLocation = maskedFinal), final;
|
|
1035
|
-
};
|
|
1036
|
-
return opts.mask ? buildWithMatches(opts, {
|
|
1037
|
-
...pick(opts, ["from"]),
|
|
1038
|
-
...opts.mask
|
|
1039
|
-
}) : buildWithMatches(opts);
|
|
1040
|
-
}, this.commitLocation = ({
|
|
1041
|
-
viewTransition,
|
|
1042
|
-
ignoreBlocker,
|
|
1043
|
-
...next
|
|
1044
|
-
}) => {
|
|
1045
|
-
const isSameState = () => {
|
|
1046
|
-
next.state.key = this.latestLocation.state.key;
|
|
1047
|
-
const isEqual = deepEqual(next.state, this.latestLocation.state);
|
|
1048
|
-
return delete next.state.key, isEqual;
|
|
1049
|
-
}, isSameUrl = this.latestLocation.href === next.href, previousCommitPromise = this.commitLocationPromise;
|
|
1050
|
-
if (this.commitLocationPromise = createControlledPromise(() => {
|
|
1051
|
-
previousCommitPromise?.resolve();
|
|
1052
|
-
}), isSameUrl && isSameState())
|
|
1053
|
-
this.load();
|
|
1054
|
-
else {
|
|
1055
|
-
let { maskedLocation, ...nextHistory } = next;
|
|
1056
|
-
maskedLocation && (nextHistory = {
|
|
1057
|
-
...maskedLocation,
|
|
1058
|
-
state: {
|
|
1059
|
-
...maskedLocation.state,
|
|
1060
|
-
__tempKey: void 0,
|
|
1061
|
-
__tempLocation: {
|
|
1062
|
-
...nextHistory,
|
|
1063
|
-
search: nextHistory.searchStr,
|
|
1064
|
-
state: {
|
|
1065
|
-
...nextHistory.state,
|
|
1066
|
-
__tempKey: void 0,
|
|
1067
|
-
__tempLocation: void 0,
|
|
1068
|
-
key: void 0
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
}, (nextHistory.unmaskOnReload ?? this.options.unmaskOnReload ?? !1) && (nextHistory.state.__tempKey = this.tempLocationKey)), this.shouldViewTransition = viewTransition, this.history[next.replace ? "replace" : "push"](
|
|
1073
|
-
nextHistory.href,
|
|
1074
|
-
nextHistory.state,
|
|
1075
|
-
{ ignoreBlocker }
|
|
1076
|
-
);
|
|
1077
|
-
}
|
|
1078
|
-
return this.resetNextScroll = next.resetScroll ?? !0, this.history.subscribers.size || this.load(), this.commitLocationPromise;
|
|
1079
|
-
}, this.buildAndCommitLocation = ({
|
|
1080
|
-
replace,
|
|
1081
|
-
resetScroll,
|
|
1082
|
-
viewTransition,
|
|
1083
|
-
ignoreBlocker,
|
|
1084
|
-
...rest
|
|
1085
|
-
} = {}) => {
|
|
1086
|
-
const location = this.buildLocation(rest);
|
|
1087
|
-
return this.commitLocation({
|
|
1088
|
-
...location,
|
|
1089
|
-
viewTransition,
|
|
1090
|
-
replace,
|
|
1091
|
-
resetScroll,
|
|
1092
|
-
ignoreBlocker
|
|
1093
|
-
});
|
|
1094
|
-
}, this.navigate = ({ from, to, __isRedirect, ...rest }) => {
|
|
1095
|
-
const toString = String(to);
|
|
1096
|
-
let isExternal;
|
|
1097
|
-
try {
|
|
1098
|
-
new URL(`${toString}`), isExternal = !0;
|
|
1099
|
-
} catch {
|
|
1100
|
-
}
|
|
1101
|
-
return invariant(
|
|
1102
|
-
!isExternal,
|
|
1103
|
-
"Attempting to navigate to external url with router.navigate!"
|
|
1104
|
-
), this.buildAndCommitLocation({
|
|
1105
|
-
...rest,
|
|
1106
|
-
from,
|
|
1107
|
-
to
|
|
1108
|
-
// to: toString,
|
|
1109
|
-
});
|
|
1110
|
-
}, this.load = async () => {
|
|
1111
|
-
this.latestLocation = this.parseLocation(this.latestLocation), this.__store.setState((s) => ({
|
|
1112
|
-
...s,
|
|
1113
|
-
loadedAt: Date.now()
|
|
1114
|
-
}));
|
|
1115
|
-
let redirect, notFound2;
|
|
1116
|
-
const loadPromise = new Promise((resolve) => {
|
|
1117
|
-
this.startReactTransition(async () => {
|
|
1118
|
-
var _a;
|
|
1119
|
-
try {
|
|
1120
|
-
const next = this.latestLocation, prevLocation = this.state.resolvedLocation, pathDidChange = prevLocation.href !== next.href;
|
|
1121
|
-
this.cancelMatches();
|
|
1122
|
-
let pendingMatches;
|
|
1123
|
-
this.__store.batch(() => {
|
|
1124
|
-
pendingMatches = this.matchRoutes(next.pathname, next.search), this.__store.setState((s) => ({
|
|
1125
|
-
...s,
|
|
1126
|
-
status: "pending",
|
|
1127
|
-
isLoading: !0,
|
|
1128
|
-
location: next,
|
|
1129
|
-
pendingMatches,
|
|
1130
|
-
// If a cached moved to pendingMatches, remove it from cachedMatches
|
|
1131
|
-
cachedMatches: s.cachedMatches.filter((d) => !pendingMatches.find((e) => e.id === d.id))
|
|
1132
|
-
}));
|
|
1133
|
-
}), this.state.redirect || this.emit({
|
|
1134
|
-
type: "onBeforeNavigate",
|
|
1135
|
-
fromLocation: prevLocation,
|
|
1136
|
-
toLocation: next,
|
|
1137
|
-
pathChanged: pathDidChange
|
|
1138
|
-
}), this.emit({
|
|
1139
|
-
type: "onBeforeLoad",
|
|
1140
|
-
fromLocation: prevLocation,
|
|
1141
|
-
toLocation: next,
|
|
1142
|
-
pathChanged: pathDidChange
|
|
1143
|
-
}), await this.loadMatches({
|
|
1144
|
-
matches: pendingMatches,
|
|
1145
|
-
location: next,
|
|
1146
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1147
|
-
onReady: async () => {
|
|
1148
|
-
this.startViewTransition(async () => {
|
|
1149
|
-
let exitingMatches, enteringMatches, stayingMatches;
|
|
1150
|
-
this.__store.batch(() => {
|
|
1151
|
-
this.__store.setState((s) => {
|
|
1152
|
-
const previousMatches = s.matches, newMatches = s.pendingMatches || s.matches;
|
|
1153
|
-
return exitingMatches = previousMatches.filter(
|
|
1154
|
-
(match) => !newMatches.find((d) => d.id === match.id)
|
|
1155
|
-
), enteringMatches = newMatches.filter(
|
|
1156
|
-
(match) => !previousMatches.find((d) => d.id === match.id)
|
|
1157
|
-
), stayingMatches = previousMatches.filter(
|
|
1158
|
-
(match) => newMatches.find((d) => d.id === match.id)
|
|
1159
|
-
), {
|
|
1160
|
-
...s,
|
|
1161
|
-
isLoading: !1,
|
|
1162
|
-
matches: newMatches,
|
|
1163
|
-
pendingMatches: void 0,
|
|
1164
|
-
cachedMatches: [
|
|
1165
|
-
...s.cachedMatches,
|
|
1166
|
-
...exitingMatches.filter((d) => d.status !== "error")
|
|
1167
|
-
]
|
|
1168
|
-
};
|
|
1169
|
-
}), this.cleanCache();
|
|
1170
|
-
}), [
|
|
1171
|
-
[exitingMatches, "onLeave"],
|
|
1172
|
-
[enteringMatches, "onEnter"],
|
|
1173
|
-
[stayingMatches, "onStay"]
|
|
1174
|
-
].forEach(([matches, hook]) => {
|
|
1175
|
-
matches.forEach((match) => {
|
|
1176
|
-
var _a2, _b;
|
|
1177
|
-
(_b = (_a2 = this.looseRoutesById[match.routeId].options)[hook]) == null || _b.call(_a2, match);
|
|
1178
|
-
});
|
|
1179
|
-
});
|
|
1180
|
-
});
|
|
1181
|
-
}
|
|
1182
|
-
});
|
|
1183
|
-
} catch (err) {
|
|
1184
|
-
isResolvedRedirect(err) ? (redirect = err, this.isServer || this.navigate({ ...err, replace: !0, __isRedirect: !0 })) : isNotFound(err) && (notFound2 = err), this.__store.setState((s) => ({
|
|
1185
|
-
...s,
|
|
1186
|
-
statusCode: redirect ? redirect.statusCode : notFound2 ? 404 : s.matches.some((d) => d.status === "error") ? 500 : 200,
|
|
1187
|
-
redirect
|
|
1188
|
-
}));
|
|
1189
|
-
}
|
|
1190
|
-
this.latestLoadPromise === loadPromise && ((_a = this.commitLocationPromise) == null || _a.resolve(), this.latestLoadPromise = void 0, this.commitLocationPromise = void 0), resolve();
|
|
1191
|
-
});
|
|
1192
|
-
});
|
|
1193
|
-
for (this.latestLoadPromise = loadPromise, await loadPromise; this.latestLoadPromise && loadPromise !== this.latestLoadPromise; )
|
|
1194
|
-
await this.latestLoadPromise;
|
|
1195
|
-
}, this.startViewTransition = (fn) => {
|
|
1196
|
-
var _a, _b;
|
|
1197
|
-
const shouldViewTransition = this.shouldViewTransition ?? this.options.defaultViewTransition;
|
|
1198
|
-
delete this.shouldViewTransition, (_b = (_a = shouldViewTransition && typeof document < "u" ? document : void 0) == null ? void 0 : _a.startViewTransition) != null && _b.call(_a, fn) || fn();
|
|
1199
|
-
}, this.updateMatch = (id, updater) => {
|
|
1200
|
-
var _a;
|
|
1201
|
-
let updated;
|
|
1202
|
-
const isPending = (_a = this.state.pendingMatches) == null ? void 0 : _a.find((d) => d.id === id), isMatched = this.state.matches.find((d) => d.id === id), matchesKey = isPending ? "pendingMatches" : isMatched ? "matches" : "cachedMatches";
|
|
1203
|
-
return this.__store.setState((s) => {
|
|
1204
|
-
var _a2;
|
|
1205
|
-
return {
|
|
1206
|
-
...s,
|
|
1207
|
-
[matchesKey]: (_a2 = s[matchesKey]) == null ? void 0 : _a2.map(
|
|
1208
|
-
(d) => d.id === id ? updated = updater(d) : d
|
|
1209
|
-
)
|
|
1210
|
-
};
|
|
1211
|
-
}), updated;
|
|
1212
|
-
}, this.getMatch = (matchId) => [
|
|
1213
|
-
...this.state.cachedMatches,
|
|
1214
|
-
...this.state.pendingMatches ?? [],
|
|
1215
|
-
...this.state.matches
|
|
1216
|
-
].find((d) => d.id === matchId), this.loadMatches = async ({
|
|
1217
|
-
location,
|
|
1218
|
-
matches,
|
|
1219
|
-
preload,
|
|
1220
|
-
onReady,
|
|
1221
|
-
updateMatch = this.updateMatch
|
|
1222
|
-
}) => {
|
|
1223
|
-
let firstBadMatchIndex, rendered = !1;
|
|
1224
|
-
const triggerOnReady = async () => {
|
|
1225
|
-
rendered || (rendered = !0, await onReady?.());
|
|
1226
|
-
};
|
|
1227
|
-
!this.isServer && !this.state.matches.length && triggerOnReady();
|
|
1228
|
-
const handleRedirectAndNotFound = (match, err) => {
|
|
1229
|
-
var _a, _b, _c;
|
|
1230
|
-
if (isResolvedRedirect(err)) throw err;
|
|
1231
|
-
if (isRedirect(err) || isNotFound(err)) {
|
|
1232
|
-
if (updateMatch(match.id, (prev) => ({
|
|
1233
|
-
...prev,
|
|
1234
|
-
status: isRedirect(err) ? "redirected" : isNotFound(err) ? "notFound" : "error",
|
|
1235
|
-
isFetching: !1,
|
|
1236
|
-
error: err,
|
|
1237
|
-
beforeLoadPromise: void 0,
|
|
1238
|
-
loaderPromise: void 0
|
|
1239
|
-
})), err.routeId || (err.routeId = match.routeId), (_a = match.beforeLoadPromise) == null || _a.resolve(), (_b = match.loaderPromise) == null || _b.resolve(), (_c = match.loadPromise) == null || _c.resolve(), isRedirect(err))
|
|
1240
|
-
throw rendered = !0, err = this.resolveRedirect({ ...err, _fromLocation: location }), err;
|
|
1241
|
-
if (isNotFound(err))
|
|
1242
|
-
throw this._handleNotFound(matches, err, {
|
|
1243
|
-
updateMatch
|
|
1244
|
-
}), err;
|
|
1245
|
-
}
|
|
1246
|
-
};
|
|
1247
|
-
try {
|
|
1248
|
-
await new Promise((resolveAll, rejectAll) => {
|
|
1249
|
-
(async () => {
|
|
1250
|
-
var _a, _b, _c;
|
|
1251
|
-
try {
|
|
1252
|
-
const handleSerialError = (index, err, routerCode) => {
|
|
1253
|
-
var _a2, _b2;
|
|
1254
|
-
const { id: matchId, routeId } = matches[index], route = this.looseRoutesById[routeId];
|
|
1255
|
-
if (err instanceof Promise)
|
|
1256
|
-
throw err;
|
|
1257
|
-
err.routerCode = routerCode, firstBadMatchIndex = firstBadMatchIndex ?? index, handleRedirectAndNotFound(this.getMatch(matchId), err);
|
|
1258
|
-
try {
|
|
1259
|
-
(_b2 = (_a2 = route.options).onError) == null || _b2.call(_a2, err);
|
|
1260
|
-
} catch (errorHandlerErr) {
|
|
1261
|
-
err = errorHandlerErr, handleRedirectAndNotFound(this.getMatch(matchId), err);
|
|
1262
|
-
}
|
|
1263
|
-
updateMatch(matchId, (prev) => {
|
|
1264
|
-
var _a3;
|
|
1265
|
-
return (_a3 = prev.beforeLoadPromise) == null || _a3.resolve(), {
|
|
1266
|
-
...prev,
|
|
1267
|
-
error: err,
|
|
1268
|
-
status: "error",
|
|
1269
|
-
isFetching: !1,
|
|
1270
|
-
updatedAt: Date.now(),
|
|
1271
|
-
abortController: new AbortController(),
|
|
1272
|
-
beforeLoadPromise: void 0
|
|
1273
|
-
};
|
|
1274
|
-
});
|
|
1275
|
-
};
|
|
1276
|
-
for (const [index, { id: matchId, routeId }] of matches.entries()) {
|
|
1277
|
-
const existingMatch = this.getMatch(matchId);
|
|
1278
|
-
if (
|
|
1279
|
-
// If we are in the middle of a load, either of these will be present
|
|
1280
|
-
// (not to be confused with `loadPromise`, which is always defined)
|
|
1281
|
-
existingMatch.beforeLoadPromise || existingMatch.loaderPromise
|
|
1282
|
-
)
|
|
1283
|
-
await existingMatch.beforeLoadPromise;
|
|
1284
|
-
else {
|
|
1285
|
-
try {
|
|
1286
|
-
updateMatch(matchId, (prev) => ({
|
|
1287
|
-
...prev,
|
|
1288
|
-
loadPromise: createControlledPromise(() => {
|
|
1289
|
-
var _a2;
|
|
1290
|
-
(_a2 = prev.loadPromise) == null || _a2.resolve();
|
|
1291
|
-
}),
|
|
1292
|
-
beforeLoadPromise: createControlledPromise()
|
|
1293
|
-
}));
|
|
1294
|
-
const route = this.looseRoutesById[routeId], abortController = new AbortController(), parentMatchId = (_a = matches[index - 1]) == null ? void 0 : _a.id, getParentContext = () => parentMatchId ? this.getMatch(parentMatchId).context ?? this.options.context ?? {} : this.options.context ?? {}, pendingMs = route.options.pendingMs ?? this.options.defaultPendingMs, shouldPending = !!(onReady && !this.isServer && !preload && (route.options.loader || route.options.beforeLoad) && typeof pendingMs == "number" && pendingMs !== 1 / 0 && (route.options.pendingComponent ?? this.options.defaultPendingComponent));
|
|
1295
|
-
let pendingTimeout;
|
|
1296
|
-
shouldPending && (pendingTimeout = setTimeout(() => {
|
|
1297
|
-
try {
|
|
1298
|
-
triggerOnReady();
|
|
1299
|
-
} catch {
|
|
1300
|
-
}
|
|
1301
|
-
}, pendingMs));
|
|
1302
|
-
const { paramsError, searchError } = this.getMatch(matchId);
|
|
1303
|
-
paramsError && handleSerialError(index, paramsError, "PARSE_PARAMS"), searchError && handleSerialError(index, searchError, "VALIDATE_SEARCH");
|
|
1304
|
-
const parentContext = getParentContext();
|
|
1305
|
-
updateMatch(matchId, (prev) => ({
|
|
1306
|
-
...prev,
|
|
1307
|
-
isFetching: "beforeLoad",
|
|
1308
|
-
fetchCount: prev.fetchCount + 1,
|
|
1309
|
-
routeContext: replaceEqualDeep(
|
|
1310
|
-
prev.routeContext,
|
|
1311
|
-
parentContext
|
|
1312
|
-
),
|
|
1313
|
-
context: replaceEqualDeep(prev.context, parentContext),
|
|
1314
|
-
abortController,
|
|
1315
|
-
pendingTimeout
|
|
1316
|
-
}));
|
|
1317
|
-
const { search, params, routeContext, cause } = this.getMatch(matchId), beforeLoadFnContext = {
|
|
1318
|
-
search,
|
|
1319
|
-
abortController,
|
|
1320
|
-
params,
|
|
1321
|
-
preload: !!preload,
|
|
1322
|
-
context: routeContext,
|
|
1323
|
-
location,
|
|
1324
|
-
navigate: (opts) => this.navigate({ ...opts, _fromLocation: location }),
|
|
1325
|
-
buildLocation: this.buildLocation,
|
|
1326
|
-
cause: preload ? "preload" : cause
|
|
1327
|
-
}, beforeLoadContext = await ((_c = (_b = route.options).beforeLoad) == null ? void 0 : _c.call(_b, beforeLoadFnContext)) ?? {};
|
|
1328
|
-
(isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) && handleSerialError(index, beforeLoadContext, "BEFORE_LOAD"), updateMatch(matchId, (prev) => {
|
|
1329
|
-
const routeContext2 = {
|
|
1330
|
-
...prev.routeContext,
|
|
1331
|
-
...beforeLoadContext
|
|
1332
|
-
};
|
|
1333
|
-
return {
|
|
1334
|
-
...prev,
|
|
1335
|
-
routeContext: replaceEqualDeep(
|
|
1336
|
-
prev.routeContext,
|
|
1337
|
-
routeContext2
|
|
1338
|
-
),
|
|
1339
|
-
context: replaceEqualDeep(prev.context, routeContext2),
|
|
1340
|
-
abortController
|
|
1341
|
-
};
|
|
1342
|
-
});
|
|
1343
|
-
} catch (err) {
|
|
1344
|
-
handleSerialError(index, err, "BEFORE_LOAD");
|
|
1345
|
-
}
|
|
1346
|
-
updateMatch(matchId, (prev) => {
|
|
1347
|
-
var _a2;
|
|
1348
|
-
return (_a2 = prev.beforeLoadPromise) == null || _a2.resolve(), {
|
|
1349
|
-
...prev,
|
|
1350
|
-
beforeLoadPromise: void 0,
|
|
1351
|
-
isFetching: !1
|
|
1352
|
-
};
|
|
1353
|
-
});
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
const validResolvedMatches = matches.slice(0, firstBadMatchIndex), matchPromises = [];
|
|
1357
|
-
validResolvedMatches.forEach(({ id: matchId, routeId }, index) => {
|
|
1358
|
-
matchPromises.push(
|
|
1359
|
-
(async () => {
|
|
1360
|
-
const { loaderPromise: prevLoaderPromise } = this.getMatch(matchId);
|
|
1361
|
-
if (prevLoaderPromise)
|
|
1362
|
-
await prevLoaderPromise;
|
|
1363
|
-
else {
|
|
1364
|
-
const parentMatchPromise = matchPromises[index - 1], route = this.looseRoutesById[routeId], getLoaderContext = () => {
|
|
1365
|
-
const {
|
|
1366
|
-
params,
|
|
1367
|
-
loaderDeps,
|
|
1368
|
-
abortController,
|
|
1369
|
-
context,
|
|
1370
|
-
cause
|
|
1371
|
-
} = this.getMatch(matchId);
|
|
1372
|
-
return {
|
|
1373
|
-
params,
|
|
1374
|
-
deps: loaderDeps,
|
|
1375
|
-
preload: !!preload,
|
|
1376
|
-
parentMatchPromise,
|
|
1377
|
-
abortController,
|
|
1378
|
-
context,
|
|
1379
|
-
location,
|
|
1380
|
-
navigate: (opts) => this.navigate({ ...opts, _fromLocation: location }),
|
|
1381
|
-
cause: preload ? "preload" : cause,
|
|
1382
|
-
route
|
|
1383
|
-
};
|
|
1384
|
-
}, age = Date.now() - this.getMatch(matchId).updatedAt, staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? this.options.defaultStaleTime ?? 0, shouldReloadOption = route.options.shouldReload, shouldReload = typeof shouldReloadOption == "function" ? shouldReloadOption(getLoaderContext()) : shouldReloadOption;
|
|
1385
|
-
updateMatch(matchId, (prev) => ({
|
|
1386
|
-
...prev,
|
|
1387
|
-
loaderPromise: createControlledPromise(),
|
|
1388
|
-
preload: !!preload && !this.state.matches.find((d) => d.id === matchId)
|
|
1389
|
-
}));
|
|
1390
|
-
const runLoader = async () => {
|
|
1391
|
-
var _a2, _b2, _c2, _d, _e, _f, _g, _h;
|
|
1392
|
-
try {
|
|
1393
|
-
const potentialPendingMinPromise = async () => {
|
|
1394
|
-
const latestMatch = this.getMatch(matchId);
|
|
1395
|
-
latestMatch.minPendingPromise && await latestMatch.minPendingPromise;
|
|
1396
|
-
};
|
|
1397
|
-
try {
|
|
1398
|
-
route._lazyPromise = route._lazyPromise || (route.lazyFn ? route.lazyFn().then((lazyRoute) => {
|
|
1399
|
-
Object.assign(
|
|
1400
|
-
route.options,
|
|
1401
|
-
lazyRoute.options
|
|
1402
|
-
);
|
|
1403
|
-
}) : Promise.resolve());
|
|
1404
|
-
const componentsPromise = this.getMatch(matchId).componentsPromise || route._lazyPromise.then(
|
|
1405
|
-
() => Promise.all(
|
|
1406
|
-
componentTypes.map(async (type) => {
|
|
1407
|
-
const component = route.options[type];
|
|
1408
|
-
component?.preload && await component.preload();
|
|
1409
|
-
})
|
|
1410
|
-
)
|
|
1411
|
-
);
|
|
1412
|
-
updateMatch(matchId, (prev) => ({
|
|
1413
|
-
...prev,
|
|
1414
|
-
isFetching: "loader",
|
|
1415
|
-
componentsPromise
|
|
1416
|
-
})), await route._lazyPromise;
|
|
1417
|
-
let loaderData = await ((_b2 = (_a2 = route.options).loader) == null ? void 0 : _b2.call(_a2, getLoaderContext()));
|
|
1418
|
-
this.serializeLoaderData && (loaderData = this.serializeLoaderData(loaderData, {
|
|
1419
|
-
router: this,
|
|
1420
|
-
match: this.getMatch(matchId)
|
|
1421
|
-
})), handleRedirectAndNotFound(
|
|
1422
|
-
this.getMatch(matchId),
|
|
1423
|
-
loaderData
|
|
1424
|
-
), await potentialPendingMinPromise();
|
|
1425
|
-
const meta = (_d = (_c2 = route.options).meta) == null ? void 0 : _d.call(_c2, {
|
|
1426
|
-
matches,
|
|
1427
|
-
match: this.getMatch(matchId),
|
|
1428
|
-
params: this.getMatch(matchId).params,
|
|
1429
|
-
loaderData
|
|
1430
|
-
}), headers = (_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, {
|
|
1431
|
-
loaderData
|
|
1432
|
-
});
|
|
1433
|
-
updateMatch(matchId, (prev) => ({
|
|
1434
|
-
...prev,
|
|
1435
|
-
error: void 0,
|
|
1436
|
-
status: "success",
|
|
1437
|
-
isFetching: !1,
|
|
1438
|
-
updatedAt: Date.now(),
|
|
1439
|
-
loaderData,
|
|
1440
|
-
meta,
|
|
1441
|
-
headers
|
|
1442
|
-
}));
|
|
1443
|
-
} catch (e) {
|
|
1444
|
-
let error = e;
|
|
1445
|
-
await potentialPendingMinPromise(), handleRedirectAndNotFound(this.getMatch(matchId), e);
|
|
1446
|
-
try {
|
|
1447
|
-
(_h = (_g = route.options).onError) == null || _h.call(_g, e);
|
|
1448
|
-
} catch (onErrorError) {
|
|
1449
|
-
error = onErrorError, handleRedirectAndNotFound(
|
|
1450
|
-
this.getMatch(matchId),
|
|
1451
|
-
onErrorError
|
|
1452
|
-
);
|
|
1453
|
-
}
|
|
1454
|
-
updateMatch(matchId, (prev) => ({
|
|
1455
|
-
...prev,
|
|
1456
|
-
error,
|
|
1457
|
-
status: "error",
|
|
1458
|
-
isFetching: !1
|
|
1459
|
-
}));
|
|
1460
|
-
}
|
|
1461
|
-
await this.getMatch(matchId).componentsPromise;
|
|
1462
|
-
} catch (err) {
|
|
1463
|
-
handleRedirectAndNotFound(this.getMatch(matchId), err);
|
|
1464
|
-
}
|
|
1465
|
-
}, { status, invalid } = this.getMatch(matchId);
|
|
1466
|
-
status === "success" && (invalid || (shouldReload ?? age > staleAge)) ? (async () => {
|
|
1467
|
-
try {
|
|
1468
|
-
await runLoader();
|
|
1469
|
-
} catch {
|
|
1470
|
-
}
|
|
1471
|
-
})() : status !== "success" && await runLoader();
|
|
1472
|
-
const { loaderPromise, loadPromise } = this.getMatch(matchId);
|
|
1473
|
-
loaderPromise?.resolve(), loadPromise?.resolve();
|
|
1474
|
-
}
|
|
1475
|
-
updateMatch(matchId, (prev) => ({
|
|
1476
|
-
...prev,
|
|
1477
|
-
isFetching: !1,
|
|
1478
|
-
loaderPromise: void 0
|
|
1479
|
-
}));
|
|
1480
|
-
})()
|
|
1481
|
-
);
|
|
1482
|
-
}), await Promise.all(matchPromises), resolveAll();
|
|
1483
|
-
} catch (err) {
|
|
1484
|
-
rejectAll(err);
|
|
1485
|
-
}
|
|
1486
|
-
})();
|
|
1487
|
-
}), await triggerOnReady();
|
|
1488
|
-
} catch (err) {
|
|
1489
|
-
if (isRedirect(err) || isNotFound(err))
|
|
1490
|
-
throw isNotFound(err) && !preload && await triggerOnReady(), err;
|
|
1491
|
-
}
|
|
1492
|
-
return matches;
|
|
1493
|
-
}, this.invalidate = () => {
|
|
1494
|
-
const invalidate = (d) => ({
|
|
1495
|
-
...d,
|
|
1496
|
-
invalid: !0,
|
|
1497
|
-
...d.status === "error" ? { status: "pending", error: void 0 } : {}
|
|
1498
|
-
});
|
|
1499
|
-
return this.__store.setState((s) => {
|
|
1500
|
-
var _a;
|
|
1501
|
-
return {
|
|
1502
|
-
...s,
|
|
1503
|
-
matches: s.matches.map(invalidate),
|
|
1504
|
-
cachedMatches: s.cachedMatches.map(invalidate),
|
|
1505
|
-
pendingMatches: (_a = s.pendingMatches) == null ? void 0 : _a.map(invalidate)
|
|
1506
|
-
};
|
|
1507
|
-
}), this.load();
|
|
1508
|
-
}, this.resolveRedirect = (err) => {
|
|
1509
|
-
const redirect = err;
|
|
1510
|
-
return redirect.href || (redirect.href = this.buildLocation(redirect).href), redirect;
|
|
1511
|
-
}, this.cleanCache = () => {
|
|
1512
|
-
this.__store.setState((s) => ({
|
|
1513
|
-
...s,
|
|
1514
|
-
cachedMatches: s.cachedMatches.filter((d) => {
|
|
1515
|
-
const route = this.looseRoutesById[d.routeId];
|
|
1516
|
-
if (!route.options.loader)
|
|
1517
|
-
return !1;
|
|
1518
|
-
const gcTime = (d.preload ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime : route.options.gcTime ?? this.options.defaultGcTime) ?? 5 * 60 * 1e3;
|
|
1519
|
-
return d.status !== "error" && Date.now() - d.updatedAt < gcTime;
|
|
1520
|
-
})
|
|
1521
|
-
}));
|
|
1522
|
-
}, this.preloadRoute = async (opts) => {
|
|
1523
|
-
const next = this.buildLocation(opts);
|
|
1524
|
-
let matches = this.matchRoutes(next.pathname, next.search, {
|
|
1525
|
-
throwOnError: !0,
|
|
1526
|
-
preload: !0
|
|
1527
|
-
});
|
|
1528
|
-
const loadedMatchIds = Object.fromEntries(
|
|
1529
|
-
[
|
|
1530
|
-
...this.state.matches,
|
|
1531
|
-
...this.state.pendingMatches ?? [],
|
|
1532
|
-
...this.state.cachedMatches
|
|
1533
|
-
].map((d) => [d.id, !0])
|
|
1534
|
-
);
|
|
1535
|
-
this.__store.batch(() => {
|
|
1536
|
-
matches.forEach((match) => {
|
|
1537
|
-
loadedMatchIds[match.id] || this.__store.setState((s) => ({
|
|
1538
|
-
...s,
|
|
1539
|
-
cachedMatches: [...s.cachedMatches, match]
|
|
1540
|
-
}));
|
|
1541
|
-
});
|
|
1542
|
-
});
|
|
1543
|
-
const activeMatchIds = new Set(
|
|
1544
|
-
[...this.state.matches, ...this.state.pendingMatches ?? []].map(
|
|
1545
|
-
(d) => d.id
|
|
1546
|
-
)
|
|
1547
|
-
);
|
|
1548
|
-
try {
|
|
1549
|
-
return matches = await this.loadMatches({
|
|
1550
|
-
matches,
|
|
1551
|
-
location: next,
|
|
1552
|
-
preload: !0,
|
|
1553
|
-
updateMatch: (id, updater) => {
|
|
1554
|
-
activeMatchIds.has(id) ? matches = matches.map((d) => d.id === id ? updater(d) : d) : this.updateMatch(id, updater);
|
|
1555
|
-
}
|
|
1556
|
-
}), matches;
|
|
1557
|
-
} catch (err) {
|
|
1558
|
-
if (isRedirect(err))
|
|
1559
|
-
return await this.preloadRoute({
|
|
1560
|
-
...err,
|
|
1561
|
-
_fromLocation: next
|
|
1562
|
-
});
|
|
1563
|
-
console.error(err);
|
|
1564
|
-
return;
|
|
1565
|
-
}
|
|
1566
|
-
}, this.matchRoute = (location, opts) => {
|
|
1567
|
-
const matchLocation = {
|
|
1568
|
-
...location,
|
|
1569
|
-
to: location.to ? this.resolvePathWithBase(location.from || "", location.to) : void 0,
|
|
1570
|
-
params: location.params || {},
|
|
1571
|
-
leaveParams: !0
|
|
1572
|
-
}, next = this.buildLocation(matchLocation);
|
|
1573
|
-
if (opts?.pending && this.state.status !== "pending")
|
|
1574
|
-
return !1;
|
|
1575
|
-
const baseLocation = (opts?.pending === void 0 ? !this.state.isLoading : opts.pending) ? this.latestLocation : this.state.resolvedLocation, match = matchPathname(this.basepath, baseLocation.pathname, {
|
|
1576
|
-
...opts,
|
|
1577
|
-
to: next.pathname
|
|
1578
|
-
});
|
|
1579
|
-
return !match || location.params && !deepEqual(match, location.params, !0) ? !1 : match && (opts?.includeSearch ?? !0) ? deepEqual(baseLocation.search, next.search, !0) ? match : !1 : match;
|
|
1580
|
-
}, this.dehydrate = () => {
|
|
1581
|
-
var _a;
|
|
1582
|
-
const pickError = ((_a = this.options.errorSerializer) == null ? void 0 : _a.serialize) ?? defaultSerializeError;
|
|
1583
|
-
return {
|
|
1584
|
-
state: {
|
|
1585
|
-
dehydratedMatches: this.state.matches.map((d) => ({
|
|
1586
|
-
...pick(d, ["id", "status", "updatedAt"]),
|
|
1587
|
-
// If an error occurs server-side during SSRing,
|
|
1588
|
-
// send a small subset of the error to the client
|
|
1589
|
-
error: d.error ? {
|
|
1590
|
-
data: pickError(d.error),
|
|
1591
|
-
__isServerError: !0
|
|
1592
|
-
} : void 0
|
|
1593
|
-
// NOTE: We don't send the loader data here, because
|
|
1594
|
-
// there is a potential that it needs to be streamed.
|
|
1595
|
-
// Instead, we render it next to the route match in the HTML
|
|
1596
|
-
// which gives us the potential to stream it via suspense.
|
|
1597
|
-
}))
|
|
1598
|
-
},
|
|
1599
|
-
manifest: this.manifest
|
|
1600
|
-
};
|
|
1601
|
-
}, this.hydrate = () => {
|
|
1602
|
-
var _a, _b, _c;
|
|
1603
|
-
let ctx;
|
|
1604
|
-
typeof document < "u" && (ctx = this.options.transformer.parse((_a = window.__TSR__) == null ? void 0 : _a.dehydrated)), invariant(
|
|
1605
|
-
ctx,
|
|
1606
|
-
"Expected to find a dehydrated data on window.__TSR__.dehydrated... but we did not. Please file an issue!"
|
|
1607
|
-
), this.dehydratedData = ctx.payload, (_c = (_b = this.options).hydrate) == null || _c.call(_b, ctx.payload);
|
|
1608
|
-
const dehydratedState = ctx.router.state, matches = this.matchRoutes(
|
|
1609
|
-
this.state.location.pathname,
|
|
1610
|
-
this.state.location.search
|
|
1611
|
-
).map((match) => {
|
|
1612
|
-
const dehydratedMatch = dehydratedState.dehydratedMatches.find(
|
|
1613
|
-
(d) => d.id === match.id
|
|
1614
|
-
);
|
|
1615
|
-
return invariant(
|
|
1616
|
-
dehydratedMatch,
|
|
1617
|
-
`Could not find a client-side match for dehydrated match with id: ${match.id}!`
|
|
1618
|
-
), {
|
|
1619
|
-
...match,
|
|
1620
|
-
...dehydratedMatch
|
|
1621
|
-
};
|
|
1622
|
-
});
|
|
1623
|
-
this.__store.setState((s) => ({
|
|
1624
|
-
...s,
|
|
1625
|
-
matches
|
|
1626
|
-
})), this.manifest = ctx.router.manifest;
|
|
1627
|
-
}, this.injectedHtml = [], this.injectHtml = (html) => {
|
|
1628
|
-
const cb = () => (this.injectedHtml = this.injectedHtml.filter((d) => d !== cb), html);
|
|
1629
|
-
this.injectedHtml.push(cb);
|
|
1630
|
-
}, this.streamedKeys = /* @__PURE__ */ new Set(), this.getStreamedValue = (key) => {
|
|
1631
|
-
var _a;
|
|
1632
|
-
if (this.isServer)
|
|
1633
|
-
return;
|
|
1634
|
-
const streamedValue = (_a = window.__TSR__) == null ? void 0 : _a.streamedValues[key];
|
|
1635
|
-
if (streamedValue)
|
|
1636
|
-
return streamedValue.parsed || (streamedValue.parsed = this.options.transformer.parse(streamedValue.value)), streamedValue.parsed;
|
|
1637
|
-
}, this.streamValue = (key, value) => {
|
|
1638
|
-
var _a;
|
|
1639
|
-
warning(
|
|
1640
|
-
!this.streamedKeys.has(key),
|
|
1641
|
-
"Key has already been streamed: " + key
|
|
1642
|
-
), this.streamedKeys.add(key);
|
|
1643
|
-
const children = `__TSR__.streamedValues['${key}'] = { value: ${(_a = this.serializer) == null ? void 0 : _a.call(this, this.options.transformer.stringify(value))}}`;
|
|
1644
|
-
this.injectHtml(
|
|
1645
|
-
`<script class='tsr-once'>${children}; __TSR__.cleanScripts()<\/script>`
|
|
1646
|
-
);
|
|
1647
|
-
}, this._handleNotFound = (matches, err, {
|
|
1648
|
-
updateMatch = this.updateMatch
|
|
1649
|
-
} = {}) => {
|
|
1650
|
-
const matchesByRouteId = Object.fromEntries(
|
|
1651
|
-
matches.map((match2) => [match2.routeId, match2])
|
|
1652
|
-
);
|
|
1653
|
-
let routeCursor = (err.global ? this.looseRoutesById[rootRouteId] : this.looseRoutesById[err.routeId]) || this.looseRoutesById[rootRouteId];
|
|
1654
|
-
for (; !routeCursor.options.notFoundComponent && !this.options.defaultNotFoundComponent && routeCursor.id !== rootRouteId; )
|
|
1655
|
-
routeCursor = routeCursor.parentRoute, invariant(
|
|
1656
|
-
routeCursor,
|
|
1657
|
-
"Found invalid route tree while trying to find not-found handler."
|
|
1658
|
-
);
|
|
1659
|
-
const match = matchesByRouteId[routeCursor.id];
|
|
1660
|
-
invariant(match, "Could not find match for route: " + routeCursor.id), updateMatch(match.id, (prev) => ({
|
|
1661
|
-
...prev,
|
|
1662
|
-
status: "notFound",
|
|
1663
|
-
error: err,
|
|
1664
|
-
isFetching: !1
|
|
1665
|
-
})), err.routerCode === "BEFORE_LOAD" && routeCursor.parentRoute && (err.routeId = routeCursor.parentRoute.id, this._handleNotFound(matches, err, {
|
|
1666
|
-
updateMatch
|
|
1667
|
-
}));
|
|
1668
|
-
}, this.hasNotFoundMatch = () => this.__store.state.matches.some(
|
|
1669
|
-
(d) => d.status === "notFound" || d.globalNotFound
|
|
1670
|
-
), this.update({
|
|
1671
|
-
defaultPreloadDelay: 50,
|
|
1672
|
-
defaultPendingMs: 1e3,
|
|
1673
|
-
defaultPendingMinMs: 500,
|
|
1674
|
-
context: void 0,
|
|
1675
|
-
...options,
|
|
1676
|
-
stringifySearch: options.stringifySearch ?? defaultStringifySearch,
|
|
1677
|
-
parseSearch: options.parseSearch ?? defaultParseSearch
|
|
1678
|
-
}), typeof document < "u" && (window.__TSR__ROUTER__ = this);
|
|
1679
|
-
}
|
|
1680
|
-
get state() {
|
|
1681
|
-
return this.__store.state;
|
|
1682
|
-
}
|
|
1683
|
-
get looseRoutesById() {
|
|
1684
|
-
return this.routesById;
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
class SearchParamError extends Error {
|
|
1688
|
-
}
|
|
1689
|
-
class PathParamError extends Error {
|
|
1690
|
-
}
|
|
1691
|
-
function getInitialRouterState(location) {
|
|
1692
|
-
return {
|
|
1693
|
-
loadedAt: 0,
|
|
1694
|
-
isLoading: !1,
|
|
1695
|
-
isTransitioning: !1,
|
|
1696
|
-
status: "idle",
|
|
1697
|
-
resolvedLocation: { ...location },
|
|
1698
|
-
location,
|
|
1699
|
-
matches: [],
|
|
1700
|
-
pendingMatches: [],
|
|
1701
|
-
cachedMatches: [],
|
|
1702
|
-
statusCode: 200
|
|
1703
|
-
};
|
|
1704
|
-
}
|
|
1705
|
-
function defaultSerializeError(err) {
|
|
1706
|
-
return err instanceof Error ? {
|
|
1707
|
-
name: err.name,
|
|
1708
|
-
message: err.message
|
|
1709
|
-
} : {
|
|
1710
|
-
data: err
|
|
1711
|
-
};
|
|
1712
|
-
}
|
|
1713
|
-
function isServerSideError(error) {
|
|
1714
|
-
return !(typeof error == "object" && error && "data" in error) || !("__isServerError" in error && error.__isServerError) || !(typeof error.data == "object" && error.data) ? !1 : error.__isServerError === !0;
|
|
1715
|
-
}
|
|
1716
|
-
function defaultDeserializeError(serializedData) {
|
|
1717
|
-
if ("name" in serializedData && "message" in serializedData) {
|
|
1718
|
-
const error = new Error(serializedData.message);
|
|
1719
|
-
return error.name = serializedData.name, error;
|
|
1720
|
-
}
|
|
1721
|
-
return serializedData.data;
|
|
1722
|
-
}
|
|
1723
|
-
const matchContext = React.createContext(void 0);
|
|
1724
|
-
function useMatch(opts) {
|
|
1725
|
-
const nearestMatchId = React.useContext(matchContext);
|
|
1726
|
-
return useRouterState({
|
|
1727
|
-
select: (state) => {
|
|
1728
|
-
const match = state.matches.find(
|
|
1729
|
-
(d) => opts.from ? opts.from === d.routeId : d.id === nearestMatchId
|
|
1730
|
-
);
|
|
1731
|
-
if (invariant(
|
|
1732
|
-
!((opts.shouldThrow ?? !0) && !match),
|
|
1733
|
-
`Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`
|
|
1734
|
-
), match !== void 0)
|
|
1735
|
-
return opts.select ? opts.select(match) : match;
|
|
1736
|
-
}
|
|
1737
|
-
});
|
|
1738
|
-
}
|
|
1739
|
-
function useLoaderDeps(opts) {
|
|
1740
|
-
return useMatch({
|
|
1741
|
-
...opts,
|
|
1742
|
-
select: (s) => typeof opts.select == "function" ? opts.select(s.loaderDeps) : s.loaderDeps
|
|
1743
|
-
});
|
|
1744
|
-
}
|
|
1745
|
-
function useLoaderData(opts) {
|
|
1746
|
-
return useMatch({
|
|
1747
|
-
...opts,
|
|
1748
|
-
select: (s) => typeof opts.select == "function" ? opts.select(s.loaderData) : s.loaderData
|
|
1749
|
-
});
|
|
1750
|
-
}
|
|
1751
|
-
function useParams(opts) {
|
|
1752
|
-
return useMatch({
|
|
1753
|
-
...opts,
|
|
1754
|
-
select: (match) => opts.select ? opts.select(match.params) : match.params
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
function useSearch(opts) {
|
|
1758
|
-
return useMatch({
|
|
1759
|
-
...opts,
|
|
1760
|
-
select: (match) => opts.select ? opts.select(match.search) : match.search
|
|
1761
|
-
});
|
|
1762
|
-
}
|
|
1763
|
-
function useNavigate(_defaultOpts) {
|
|
1764
|
-
const router = useRouter();
|
|
1765
|
-
return React.useCallback(
|
|
1766
|
-
(options) => router.navigate({
|
|
1767
|
-
...options
|
|
1768
|
-
}),
|
|
1769
|
-
[router]
|
|
1770
|
-
);
|
|
1771
|
-
}
|
|
1772
|
-
class Route {
|
|
1773
|
-
/**
|
|
1774
|
-
* @deprecated Use the `createRoute` function instead.
|
|
1775
|
-
*/
|
|
1776
|
-
constructor(options) {
|
|
1777
|
-
this.init = (opts) => {
|
|
1778
|
-
var _a, _b;
|
|
1779
|
-
this.originalIndex = opts.originalIndex;
|
|
1780
|
-
const options2 = this.options, isRoot = !options2?.path && !options2?.id;
|
|
1781
|
-
this.parentRoute = (_b = (_a = this.options) == null ? void 0 : _a.getParentRoute) == null ? void 0 : _b.call(_a), isRoot ? this.path = rootRouteId : invariant(
|
|
1782
|
-
this.parentRoute,
|
|
1783
|
-
"Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance."
|
|
1784
|
-
);
|
|
1785
|
-
let path = isRoot ? rootRouteId : options2.path;
|
|
1786
|
-
path && path !== "/" && (path = trimPathLeft(path));
|
|
1787
|
-
const customId = options2?.id || path;
|
|
1788
|
-
let id = isRoot ? rootRouteId : joinPaths([
|
|
1789
|
-
this.parentRoute.id === rootRouteId ? "" : this.parentRoute.id,
|
|
1790
|
-
customId
|
|
1791
|
-
]);
|
|
1792
|
-
path === rootRouteId && (path = "/"), id !== rootRouteId && (id = joinPaths(["/", id]));
|
|
1793
|
-
const fullPath = id === rootRouteId ? "/" : joinPaths([this.parentRoute.fullPath, path]);
|
|
1794
|
-
this.path = path, this.id = id, this.fullPath = fullPath, this.to = fullPath;
|
|
1795
|
-
}, this.updateLoader = (options2) => (Object.assign(this.options, options2), this), this.update = (options2) => (Object.assign(this.options, options2), this), this.lazy = (lazyFn) => (this.lazyFn = lazyFn, this), this.useMatch = (opts) => useMatch({ ...opts, from: this.id }), this.useRouteContext = (opts) => useMatch({
|
|
1796
|
-
...opts,
|
|
1797
|
-
from: this.id,
|
|
1798
|
-
select: (d) => opts?.select ? opts.select(d.context) : d.context
|
|
1799
|
-
}), this.useSearch = (opts) => useSearch({ ...opts, from: this.id }), this.useParams = (opts) => useParams({ ...opts, from: this.id }), this.useLoaderDeps = (opts) => useLoaderDeps({ ...opts, from: this.id }), this.useLoaderData = (opts) => useLoaderData({ ...opts, from: this.id }), this.useNavigate = () => useNavigate({ from: this.id }), this.options = options || {}, this.isRoot = !options?.getParentRoute, invariant(
|
|
1800
|
-
!(options?.id && options?.path),
|
|
1801
|
-
"Route cannot have both an 'id' and a 'path' option."
|
|
1802
|
-
), this.$$typeof = Symbol.for("react.memo");
|
|
1803
|
-
}
|
|
1804
|
-
addChildren(children) {
|
|
1805
|
-
return this.children = Array.isArray(children) ? children : Object.values(children), this;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
function createRoute(options) {
|
|
1809
|
-
return new Route(options);
|
|
1810
|
-
}
|
|
1811
|
-
function createRootRouteWithContext() {
|
|
1812
|
-
return (options) => createRootRoute(options);
|
|
1813
|
-
}
|
|
1814
|
-
class RootRoute extends Route {
|
|
1815
|
-
/**
|
|
1816
|
-
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
1817
|
-
*/
|
|
1818
|
-
constructor(options) {
|
|
1819
|
-
super(options);
|
|
1820
|
-
}
|
|
1821
|
-
addChildren(children) {
|
|
1822
|
-
return super.addChildren(children);
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
function createRootRoute(options) {
|
|
1826
|
-
return new RootRoute(options);
|
|
1827
|
-
}
|
|
1828
|
-
function createFileRoute(path) {
|
|
1829
|
-
return new FileRoute(path, {
|
|
1830
|
-
silent: !0
|
|
1831
|
-
}).createRoute;
|
|
1832
|
-
}
|
|
1833
|
-
class FileRoute {
|
|
1834
|
-
constructor(path, _opts) {
|
|
1835
|
-
this.path = path, this.createRoute = (options) => {
|
|
1836
|
-
warning(
|
|
1837
|
-
this.silent,
|
|
1838
|
-
"FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead."
|
|
1839
|
-
);
|
|
1840
|
-
const route = createRoute(options);
|
|
1841
|
-
return route.isRoot = !1, route;
|
|
1842
|
-
}, this.silent = _opts?.silent;
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
const preloadWarning = "Error preloading route! ☝️";
|
|
1846
|
-
function useLinkProps(options) {
|
|
1847
|
-
const router = useRouter(), [isTransitioning, setIsTransitioning] = React.useState(!1), {
|
|
1848
|
-
// custom props
|
|
1849
|
-
activeProps = () => ({ className: "active" }),
|
|
1850
|
-
inactiveProps = () => ({}),
|
|
1851
|
-
activeOptions,
|
|
1852
|
-
hash,
|
|
1853
|
-
search,
|
|
1854
|
-
params,
|
|
1855
|
-
to,
|
|
1856
|
-
state,
|
|
1857
|
-
mask,
|
|
1858
|
-
preload: userPreload,
|
|
1859
|
-
preloadDelay: userPreloadDelay,
|
|
1860
|
-
replace,
|
|
1861
|
-
startTransition,
|
|
1862
|
-
resetScroll,
|
|
1863
|
-
viewTransition,
|
|
1864
|
-
// element props
|
|
1865
|
-
children,
|
|
1866
|
-
target,
|
|
1867
|
-
disabled,
|
|
1868
|
-
style,
|
|
1869
|
-
className,
|
|
1870
|
-
onClick,
|
|
1871
|
-
onFocus,
|
|
1872
|
-
onMouseEnter,
|
|
1873
|
-
onMouseLeave,
|
|
1874
|
-
onTouchStart,
|
|
1875
|
-
ignoreBlocker,
|
|
1876
|
-
...rest
|
|
1877
|
-
} = options;
|
|
1878
|
-
let type = "internal";
|
|
1879
|
-
try {
|
|
1880
|
-
new URL(`${to}`), type = "external";
|
|
1881
|
-
} catch {
|
|
1882
|
-
}
|
|
1883
|
-
const next = router.buildLocation(options), preload = userPreload ?? router.options.defaultPreload, preloadDelay = userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0, isActive = useRouterState({
|
|
1884
|
-
select: (s) => {
|
|
1885
|
-
const currentPathSplit = removeTrailingSlash(
|
|
1886
|
-
s.location.pathname,
|
|
1887
|
-
router.basepath
|
|
1888
|
-
).split("/"), pathIsFuzzyEqual = removeTrailingSlash(
|
|
1889
|
-
next.pathname,
|
|
1890
|
-
router.basepath
|
|
1891
|
-
).split("/").every(
|
|
1892
|
-
(d, i) => d === currentPathSplit[i]
|
|
1893
|
-
), pathTest = activeOptions?.exact ? exactPathTest(s.location.pathname, next.pathname, router.basepath) : pathIsFuzzyEqual, hashTest = activeOptions?.includeHash ? s.location.hash === next.hash : !0, searchTest = activeOptions?.includeSearch ?? !0 ? deepEqual(s.location.search, next.search, !activeOptions?.exact) : !0;
|
|
1894
|
-
return pathTest && hashTest && searchTest;
|
|
1895
|
-
}
|
|
1896
|
-
});
|
|
1897
|
-
if (type === "external")
|
|
1898
|
-
return {
|
|
1899
|
-
...rest,
|
|
1900
|
-
type,
|
|
1901
|
-
href: to,
|
|
1902
|
-
...children && { children },
|
|
1903
|
-
...target && { target },
|
|
1904
|
-
...disabled && { disabled },
|
|
1905
|
-
...style && { style },
|
|
1906
|
-
...className && { className },
|
|
1907
|
-
...onClick && { onClick },
|
|
1908
|
-
...onFocus && { onFocus },
|
|
1909
|
-
...onMouseEnter && { onMouseEnter },
|
|
1910
|
-
...onMouseLeave && { onMouseLeave },
|
|
1911
|
-
...onTouchStart && { onTouchStart }
|
|
1912
|
-
};
|
|
1913
|
-
const handleClick = (e) => {
|
|
1914
|
-
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === "_self") && e.button === 0) {
|
|
1915
|
-
e.preventDefault(), flushSync(() => {
|
|
1916
|
-
setIsTransitioning(!0);
|
|
1917
|
-
});
|
|
1918
|
-
const unsub = router.subscribe("onResolved", () => {
|
|
1919
|
-
unsub(), setIsTransitioning(!1);
|
|
1920
|
-
});
|
|
1921
|
-
router.commitLocation({
|
|
1922
|
-
...next,
|
|
1923
|
-
replace,
|
|
1924
|
-
resetScroll,
|
|
1925
|
-
startTransition,
|
|
1926
|
-
viewTransition,
|
|
1927
|
-
ignoreBlocker
|
|
1928
|
-
});
|
|
1929
|
-
}
|
|
1930
|
-
}, doPreload = () => {
|
|
1931
|
-
router.preloadRoute(options).catch((err) => {
|
|
1932
|
-
console.warn(err), console.warn(preloadWarning);
|
|
1933
|
-
});
|
|
1934
|
-
}, handleFocus = (e) => {
|
|
1935
|
-
disabled || preload && doPreload();
|
|
1936
|
-
}, handleTouchStart = handleFocus, handleEnter = (e) => {
|
|
1937
|
-
if (disabled) return;
|
|
1938
|
-
const eventTarget = e.target || {};
|
|
1939
|
-
if (preload) {
|
|
1940
|
-
if (eventTarget.preloadTimeout)
|
|
1941
|
-
return;
|
|
1942
|
-
eventTarget.preloadTimeout = setTimeout(() => {
|
|
1943
|
-
eventTarget.preloadTimeout = null, doPreload();
|
|
1944
|
-
}, preloadDelay);
|
|
1945
|
-
}
|
|
1946
|
-
}, handleLeave = (e) => {
|
|
1947
|
-
if (disabled) return;
|
|
1948
|
-
const eventTarget = e.target || {};
|
|
1949
|
-
eventTarget.preloadTimeout && (clearTimeout(eventTarget.preloadTimeout), eventTarget.preloadTimeout = null);
|
|
1950
|
-
}, composeHandlers = (handlers) => (e) => {
|
|
1951
|
-
var _a;
|
|
1952
|
-
(_a = e.persist) == null || _a.call(e), handlers.filter(Boolean).forEach((handler) => {
|
|
1953
|
-
e.defaultPrevented || handler(e);
|
|
1954
|
-
});
|
|
1955
|
-
}, resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {}, resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}), resolvedClassName = [
|
|
1956
|
-
className,
|
|
1957
|
-
resolvedActiveProps.className,
|
|
1958
|
-
resolvedInactiveProps.className
|
|
1959
|
-
].filter(Boolean).join(" "), resolvedStyle = {
|
|
1960
|
-
...style,
|
|
1961
|
-
...resolvedActiveProps.style,
|
|
1962
|
-
...resolvedInactiveProps.style
|
|
1963
|
-
};
|
|
1964
|
-
return {
|
|
1965
|
-
...resolvedActiveProps,
|
|
1966
|
-
...resolvedInactiveProps,
|
|
1967
|
-
...rest,
|
|
1968
|
-
href: disabled ? void 0 : next.maskedLocation ? router.history.createHref(next.maskedLocation.href) : router.history.createHref(next.href),
|
|
1969
|
-
onClick: composeHandlers([onClick, handleClick]),
|
|
1970
|
-
onFocus: composeHandlers([onFocus, handleFocus]),
|
|
1971
|
-
onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
|
|
1972
|
-
onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
|
|
1973
|
-
onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),
|
|
1974
|
-
disabled: !!disabled,
|
|
1975
|
-
target,
|
|
1976
|
-
...Object.keys(resolvedStyle).length && { style: resolvedStyle },
|
|
1977
|
-
...resolvedClassName && { className: resolvedClassName },
|
|
1978
|
-
...disabled && {
|
|
1979
|
-
role: "link",
|
|
1980
|
-
"aria-disabled": !0
|
|
1981
|
-
},
|
|
1982
|
-
...isActive && { "data-status": "active", "aria-current": "page" },
|
|
1983
|
-
...isTransitioning && { "data-transitioning": "transitioning" }
|
|
1984
|
-
};
|
|
1985
|
-
}
|
|
1986
|
-
const Link = React.forwardRef((props, ref) => {
|
|
1987
|
-
const { _asChild, ...rest } = props, { type, ...linkProps } = useLinkProps(rest), children = typeof rest.children == "function" ? rest.children({
|
|
1988
|
-
isActive: linkProps["data-status"] === "active"
|
|
1989
|
-
}) : rest.children;
|
|
1990
|
-
return typeof _asChild > "u" && delete linkProps.disabled, React.createElement(
|
|
1991
|
-
_asChild || "a",
|
|
1992
|
-
{
|
|
1993
|
-
...linkProps,
|
|
1994
|
-
ref
|
|
1995
|
-
},
|
|
1996
|
-
children
|
|
1997
|
-
);
|
|
1998
|
-
});
|
|
1999
|
-
function isCtrlEvent(e) {
|
|
2000
|
-
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2001
|
-
}
|
|
2002
|
-
function Transitioner() {
|
|
2003
|
-
const router = useRouter(), mountLoadForRouter = React.useRef({ router, mounted: !1 }), routerState = useRouterState({
|
|
2004
|
-
select: (s) => pick(s, ["isLoading", "location", "resolvedLocation", "isTransitioning"])
|
|
2005
|
-
}), [isTransitioning, startReactTransition_] = React.useTransition(), hasPendingMatches = useRouterState({
|
|
2006
|
-
select: (s) => s.matches.some((d) => d.status === "pending")
|
|
2007
|
-
}), previousIsLoading = usePrevious(routerState.isLoading), isAnyPending = routerState.isLoading || isTransitioning || hasPendingMatches, previousIsAnyPending = usePrevious(isAnyPending);
|
|
2008
|
-
return router.isServer || (router.startReactTransition = startReactTransition_), React.useEffect(() => {
|
|
2009
|
-
const unsub = router.history.subscribe(router.load), nextLocation = router.buildLocation({
|
|
2010
|
-
to: router.latestLocation.pathname,
|
|
2011
|
-
search: !0,
|
|
2012
|
-
params: !0,
|
|
2013
|
-
hash: !0,
|
|
2014
|
-
state: !0
|
|
2015
|
-
});
|
|
2016
|
-
return trimPathRight(router.latestLocation.href) !== trimPathRight(nextLocation.href) && router.commitLocation({ ...nextLocation, replace: !0 }), () => {
|
|
2017
|
-
unsub();
|
|
2018
|
-
};
|
|
2019
|
-
}, [router, router.history]), useLayoutEffect$1(() => {
|
|
2020
|
-
var _a;
|
|
2021
|
-
if ((_a = window.__TSR__) != null && _a.dehydrated || mountLoadForRouter.current.router === router && mountLoadForRouter.current.mounted)
|
|
2022
|
-
return;
|
|
2023
|
-
mountLoadForRouter.current = { router, mounted: !0 }, (async () => {
|
|
2024
|
-
try {
|
|
2025
|
-
await router.load();
|
|
2026
|
-
} catch (err) {
|
|
2027
|
-
console.error(err);
|
|
2028
|
-
}
|
|
2029
|
-
})();
|
|
2030
|
-
}, [router]), useLayoutEffect$1(() => {
|
|
2031
|
-
if (previousIsLoading && !routerState.isLoading) {
|
|
2032
|
-
const toLocation = router.state.location, fromLocation = router.state.resolvedLocation, pathChanged = fromLocation.href !== toLocation.href;
|
|
2033
|
-
router.emit({
|
|
2034
|
-
type: "onLoad",
|
|
2035
|
-
// When the new URL has committed, when the new matches have been loaded into state.matches
|
|
2036
|
-
fromLocation,
|
|
2037
|
-
toLocation,
|
|
2038
|
-
pathChanged
|
|
2039
|
-
});
|
|
2040
|
-
}
|
|
2041
|
-
}, [previousIsLoading, router, routerState.isLoading]), useLayoutEffect$1(() => {
|
|
2042
|
-
if (previousIsAnyPending && !isAnyPending) {
|
|
2043
|
-
const toLocation = router.state.location, fromLocation = router.state.resolvedLocation, pathChanged = fromLocation.href !== toLocation.href;
|
|
2044
|
-
if (router.emit({
|
|
2045
|
-
type: "onResolved",
|
|
2046
|
-
fromLocation,
|
|
2047
|
-
toLocation,
|
|
2048
|
-
pathChanged
|
|
2049
|
-
}), router.__store.setState((s) => ({
|
|
2050
|
-
...s,
|
|
2051
|
-
status: "idle",
|
|
2052
|
-
resolvedLocation: s.location
|
|
2053
|
-
})), document.querySelector && router.state.location.hash !== "") {
|
|
2054
|
-
const el = document.getElementById(router.state.location.hash);
|
|
2055
|
-
el && el.scrollIntoView();
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
}, [isAnyPending, previousIsAnyPending, router]), null;
|
|
2059
|
-
}
|
|
2060
|
-
function SafeFragment(props) {
|
|
2061
|
-
return /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
2062
|
-
}
|
|
2063
|
-
function renderRouteNotFound(router, route, data) {
|
|
2064
|
-
return route.options.notFoundComponent ? /* @__PURE__ */ jsx(route.options.notFoundComponent, { data }) : router.options.defaultNotFoundComponent ? /* @__PURE__ */ jsx(router.options.defaultNotFoundComponent, { data }) : /* @__PURE__ */ jsx(DefaultGlobalNotFound, {});
|
|
2065
|
-
}
|
|
2066
|
-
function Match({ matchId }) {
|
|
2067
|
-
var _a, _b;
|
|
2068
|
-
const router = useRouter(), routeId = useRouterState({
|
|
2069
|
-
select: (s) => {
|
|
2070
|
-
var _a2;
|
|
2071
|
-
return (_a2 = s.matches.find((d) => d.id === matchId)) == null ? void 0 : _a2.routeId;
|
|
2072
|
-
}
|
|
2073
|
-
});
|
|
2074
|
-
invariant(
|
|
2075
|
-
routeId,
|
|
2076
|
-
`Could not find routeId for matchId "${matchId}". Please file an issue!`
|
|
2077
|
-
);
|
|
2078
|
-
const route = router.routesById[routeId], PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent, pendingElement = PendingComponent ? /* @__PURE__ */ jsx(PendingComponent, {}) : null, routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent, routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch, routeNotFoundComponent = route.isRoot ? (
|
|
2079
|
-
// If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component
|
|
2080
|
-
route.options.notFoundComponent ?? ((_a = router.options.notFoundRoute) == null ? void 0 : _a.options.component)
|
|
2081
|
-
) : route.options.notFoundComponent, ResolvedSuspenseBoundary = (
|
|
2082
|
-
// If we're on the root route, allow forcefully wrapping in suspense
|
|
2083
|
-
(!route.isRoot || route.options.wrapInSuspense) && (route.options.wrapInSuspense ?? PendingComponent ?? ((_b = route.options.errorComponent) == null ? void 0 : _b.preload)) ? React.Suspense : SafeFragment
|
|
2084
|
-
), ResolvedCatchBoundary = routeErrorComponent ? CatchBoundary : SafeFragment, ResolvedNotFoundBoundary = routeNotFoundComponent ? CatchNotFound : SafeFragment, resetKey = useRouterState({
|
|
2085
|
-
select: (s) => s.loadedAt
|
|
2086
|
-
});
|
|
2087
|
-
return /* @__PURE__ */ jsx(matchContext.Provider, { value: matchId, children: /* @__PURE__ */ jsx(ResolvedSuspenseBoundary, { fallback: pendingElement, children: /* @__PURE__ */ jsx(
|
|
2088
|
-
ResolvedCatchBoundary,
|
|
2089
|
-
{
|
|
2090
|
-
getResetKey: () => resetKey,
|
|
2091
|
-
errorComponent: routeErrorComponent || ErrorComponent,
|
|
2092
|
-
onCatch: (error, errorInfo) => {
|
|
2093
|
-
if (isNotFound(error)) throw error;
|
|
2094
|
-
warning(!1, `Error in route match: ${matchId}`), routeOnCatch?.(error, errorInfo);
|
|
2095
|
-
},
|
|
2096
|
-
children: /* @__PURE__ */ jsx(
|
|
2097
|
-
ResolvedNotFoundBoundary,
|
|
2098
|
-
{
|
|
2099
|
-
fallback: (error) => {
|
|
2100
|
-
if (!routeNotFoundComponent || error.routeId && error.routeId !== routeId || !error.routeId && !route.isRoot)
|
|
2101
|
-
throw error;
|
|
2102
|
-
return React.createElement(routeNotFoundComponent, error);
|
|
2103
|
-
},
|
|
2104
|
-
children: /* @__PURE__ */ jsx(MatchInner, { matchId })
|
|
2105
|
-
}
|
|
2106
|
-
)
|
|
2107
|
-
}
|
|
2108
|
-
) }) });
|
|
2109
|
-
}
|
|
2110
|
-
function MatchInner({ matchId }) {
|
|
2111
|
-
var _a, _b;
|
|
2112
|
-
const router = useRouter(), routeId = useRouterState({
|
|
2113
|
-
select: (s) => {
|
|
2114
|
-
var _a2;
|
|
2115
|
-
return (_a2 = s.matches.find((d) => d.id === matchId)) == null ? void 0 : _a2.routeId;
|
|
2116
|
-
}
|
|
2117
|
-
}), route = router.routesById[routeId], matchIndex = useRouterState({
|
|
2118
|
-
select: (s) => s.matches.findIndex((d) => d.id === matchId)
|
|
2119
|
-
}), match = useRouterState({
|
|
2120
|
-
select: (s) => {
|
|
2121
|
-
const match2 = s.matches[matchIndex];
|
|
2122
|
-
return pick(match2, [
|
|
2123
|
-
"id",
|
|
2124
|
-
"status",
|
|
2125
|
-
"error",
|
|
2126
|
-
"loadPromise",
|
|
2127
|
-
"minPendingPromise"
|
|
2128
|
-
]);
|
|
2129
|
-
}
|
|
2130
|
-
}), RouteErrorComponent = (route.options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent;
|
|
2131
|
-
if (match.status === "notFound") {
|
|
2132
|
-
let error;
|
|
2133
|
-
return isServerSideError(match.error) ? error = (((_a = router.options.errorSerializer) == null ? void 0 : _a.deserialize) ?? defaultDeserializeError)(match.error.data) : error = match.error, invariant(isNotFound(error), "Expected a notFound error"), renderRouteNotFound(router, route, error);
|
|
2134
|
-
}
|
|
2135
|
-
if (match.status === "redirected")
|
|
2136
|
-
throw invariant(isRedirect(match.error), "Expected a redirect error"), match.loadPromise;
|
|
2137
|
-
if (match.status === "error") {
|
|
2138
|
-
if (router.isServer)
|
|
2139
|
-
return /* @__PURE__ */ jsx(
|
|
2140
|
-
RouteErrorComponent,
|
|
2141
|
-
{
|
|
2142
|
-
error: match.error,
|
|
2143
|
-
info: {
|
|
2144
|
-
componentStack: ""
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
);
|
|
2148
|
-
throw isServerSideError(match.error) ? (((_b = router.options.errorSerializer) == null ? void 0 : _b.deserialize) ?? defaultDeserializeError)(match.error.data) : match.error;
|
|
2149
|
-
}
|
|
2150
|
-
if (match.status === "pending") {
|
|
2151
|
-
const pendingMinMs = route.options.pendingMinMs ?? router.options.defaultPendingMinMs;
|
|
2152
|
-
if (pendingMinMs && !match.minPendingPromise && !router.isServer) {
|
|
2153
|
-
const minPendingPromise = createControlledPromise();
|
|
2154
|
-
Promise.resolve().then(() => {
|
|
2155
|
-
router.updateMatch(match.id, (prev) => ({
|
|
2156
|
-
...prev,
|
|
2157
|
-
minPendingPromise
|
|
2158
|
-
}));
|
|
2159
|
-
}), setTimeout(() => {
|
|
2160
|
-
minPendingPromise.resolve(), router.updateMatch(match.id, (prev) => ({
|
|
2161
|
-
...prev,
|
|
2162
|
-
minPendingPromise: void 0
|
|
2163
|
-
}));
|
|
2164
|
-
}, pendingMinMs);
|
|
2165
|
-
}
|
|
2166
|
-
throw match.loadPromise;
|
|
2167
|
-
}
|
|
2168
|
-
const Comp = route.options.component ?? router.options.defaultComponent;
|
|
2169
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2170
|
-
Comp ? /* @__PURE__ */ jsx(Comp, {}) : /* @__PURE__ */ jsx(Outlet, {}),
|
|
2171
|
-
router.AfterEachMatch ? /* @__PURE__ */ jsx(router.AfterEachMatch, { match, matchIndex }) : null
|
|
2172
|
-
] });
|
|
2173
|
-
}
|
|
2174
|
-
const Outlet = React.memo(function() {
|
|
2175
|
-
const router = useRouter(), matchId = React.useContext(matchContext), routeId = useRouterState({
|
|
2176
|
-
select: (s) => {
|
|
2177
|
-
var _a;
|
|
2178
|
-
return (_a = s.matches.find((d) => d.id === matchId)) == null ? void 0 : _a.routeId;
|
|
2179
|
-
}
|
|
2180
|
-
}), route = router.routesById[routeId], { parentGlobalNotFound } = useRouterState({
|
|
2181
|
-
select: (s) => {
|
|
2182
|
-
const parentMatch = s.matches.find((d) => d.id === matchId);
|
|
2183
|
-
return invariant(
|
|
2184
|
-
parentMatch,
|
|
2185
|
-
`Could not find parent match for matchId "${matchId}"`
|
|
2186
|
-
), {
|
|
2187
|
-
parentGlobalNotFound: parentMatch.globalNotFound
|
|
2188
|
-
};
|
|
2189
|
-
}
|
|
2190
|
-
}), childMatchId = useRouterState({
|
|
2191
|
-
select: (s) => {
|
|
2192
|
-
var _a;
|
|
2193
|
-
const matches = s.matches, index = matches.findIndex((d) => d.id === matchId);
|
|
2194
|
-
return (_a = matches[index + 1]) == null ? void 0 : _a.id;
|
|
2195
|
-
}
|
|
2196
|
-
});
|
|
2197
|
-
if (parentGlobalNotFound)
|
|
2198
|
-
return renderRouteNotFound(router, route, void 0);
|
|
2199
|
-
if (!childMatchId)
|
|
2200
|
-
return null;
|
|
2201
|
-
const nextMatch = /* @__PURE__ */ jsx(Match, { matchId: childMatchId }), pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsx(router.options.defaultPendingComponent, {}) : null;
|
|
2202
|
-
return matchId === rootRouteId ? /* @__PURE__ */ jsx(React.Suspense, { fallback: pendingElement, children: nextMatch }) : nextMatch;
|
|
2203
|
-
});
|
|
2204
|
-
function Matches() {
|
|
2205
|
-
const router = useRouter(), pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsx(router.options.defaultPendingComponent, {}) : null, ResolvedSuspense = router.state.matches.length ? SafeFragment : React.Suspense, inner = /* @__PURE__ */ jsxs(ResolvedSuspense, { fallback: pendingElement, children: [
|
|
2206
|
-
/* @__PURE__ */ jsx(Transitioner, {}),
|
|
2207
|
-
/* @__PURE__ */ jsx(MatchesInner, {})
|
|
2208
|
-
] });
|
|
2209
|
-
return router.options.InnerWrap ? /* @__PURE__ */ jsx(router.options.InnerWrap, { children: inner }) : inner;
|
|
2210
|
-
}
|
|
2211
|
-
function MatchesInner() {
|
|
2212
|
-
const matchId = useRouterState({
|
|
2213
|
-
select: (s) => {
|
|
2214
|
-
var _a;
|
|
2215
|
-
return (_a = s.matches[0]) == null ? void 0 : _a.id;
|
|
2216
|
-
}
|
|
2217
|
-
}), resetKey = useRouterState({
|
|
2218
|
-
select: (s) => s.loadedAt
|
|
2219
|
-
});
|
|
2220
|
-
return /* @__PURE__ */ jsx(matchContext.Provider, { value: matchId, children: /* @__PURE__ */ jsx(
|
|
2221
|
-
CatchBoundary,
|
|
2222
|
-
{
|
|
2223
|
-
getResetKey: () => resetKey,
|
|
2224
|
-
errorComponent: ErrorComponent,
|
|
2225
|
-
onCatch: (error) => {
|
|
2226
|
-
warning(
|
|
2227
|
-
!1,
|
|
2228
|
-
"The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!"
|
|
2229
|
-
), warning(!1, error.message || error.toString());
|
|
2230
|
-
},
|
|
2231
|
-
children: matchId ? /* @__PURE__ */ jsx(Match, { matchId }) : null
|
|
2232
|
-
}
|
|
2233
|
-
) });
|
|
2234
|
-
}
|
|
2235
|
-
function RouterContextProvider({
|
|
2236
|
-
router,
|
|
2237
|
-
children,
|
|
2238
|
-
...rest
|
|
2239
|
-
}) {
|
|
2240
|
-
router.update({
|
|
2241
|
-
...router.options,
|
|
2242
|
-
...rest,
|
|
2243
|
-
context: {
|
|
2244
|
-
...router.options.context,
|
|
2245
|
-
...rest.context
|
|
2246
|
-
}
|
|
2247
|
-
});
|
|
2248
|
-
const routerContext2 = getRouterContext(), provider = /* @__PURE__ */ jsx(routerContext2.Provider, { value: router, children });
|
|
2249
|
-
return router.options.Wrap ? /* @__PURE__ */ jsx(router.options.Wrap, { children: provider }) : provider;
|
|
2250
|
-
}
|
|
2251
|
-
function RouterProvider({ router, ...rest }) {
|
|
2252
|
-
return /* @__PURE__ */ jsx(RouterContextProvider, { router, ...rest, children: /* @__PURE__ */ jsx(Matches, {}) });
|
|
2253
|
-
}
|
|
2254
|
-
const useLayoutEffect = typeof window < "u" ? React.useLayoutEffect : React.useEffect, windowKey = "window", delimiter = "___";
|
|
2255
|
-
let weakScrolledElements = /* @__PURE__ */ new WeakSet();
|
|
2256
|
-
const sessionsStorage = typeof window < "u" && window.sessionStorage, cache = sessionsStorage ? (() => {
|
|
2257
|
-
const storageKey = "tsr-scroll-restoration-v2";
|
|
2258
|
-
return {
|
|
2259
|
-
state: JSON.parse(
|
|
2260
|
-
window.sessionStorage.getItem(storageKey) || "null"
|
|
2261
|
-
) || { cached: {}, next: {} },
|
|
2262
|
-
set: (updater) => {
|
|
2263
|
-
cache.state = functionalUpdate(updater, cache.state), window.sessionStorage.setItem(storageKey, JSON.stringify(cache.state));
|
|
2264
|
-
}
|
|
2265
|
-
};
|
|
2266
|
-
})() : void 0, defaultGetKey = (location) => location.state.key || location.href;
|
|
2267
|
-
function useScrollRestoration(options) {
|
|
2268
|
-
const router = useRouter();
|
|
2269
|
-
useLayoutEffect(() => {
|
|
2270
|
-
const getKey = options?.getKey || defaultGetKey, { history } = window;
|
|
2271
|
-
history.scrollRestoration = "manual";
|
|
2272
|
-
const onScroll = (event) => {
|
|
2273
|
-
if (weakScrolledElements.has(event.target)) return;
|
|
2274
|
-
weakScrolledElements.add(event.target);
|
|
2275
|
-
let elementSelector = "";
|
|
2276
|
-
if (event.target === document || event.target === window)
|
|
2277
|
-
elementSelector = windowKey;
|
|
2278
|
-
else {
|
|
2279
|
-
const attrId = event.target.getAttribute(
|
|
2280
|
-
"data-scroll-restoration-id"
|
|
2281
|
-
);
|
|
2282
|
-
attrId ? elementSelector = `[data-scroll-restoration-id="${attrId}"]` : elementSelector = getCssSelector(event.target);
|
|
2283
|
-
}
|
|
2284
|
-
cache.state.next[elementSelector] || cache.set((c) => ({
|
|
2285
|
-
...c,
|
|
2286
|
-
next: {
|
|
2287
|
-
...c.next,
|
|
2288
|
-
[elementSelector]: {
|
|
2289
|
-
scrollX: NaN,
|
|
2290
|
-
scrollY: NaN
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
}));
|
|
2294
|
-
};
|
|
2295
|
-
typeof document < "u" && document.addEventListener("scroll", onScroll, !0);
|
|
2296
|
-
const unsubOnBeforeLoad = router.subscribe("onBeforeLoad", (event) => {
|
|
2297
|
-
if (event.pathChanged) {
|
|
2298
|
-
const restoreKey = getKey(event.fromLocation);
|
|
2299
|
-
for (const elementSelector in cache.state.next) {
|
|
2300
|
-
const entry = cache.state.next[elementSelector];
|
|
2301
|
-
if (elementSelector === windowKey)
|
|
2302
|
-
entry.scrollX = window.scrollX || 0, entry.scrollY = window.scrollY || 0;
|
|
2303
|
-
else if (elementSelector) {
|
|
2304
|
-
const element = document.querySelector(elementSelector);
|
|
2305
|
-
entry.scrollX = element?.scrollLeft || 0, entry.scrollY = element?.scrollTop || 0;
|
|
2306
|
-
}
|
|
2307
|
-
cache.set((c) => {
|
|
2308
|
-
const next = { ...c.next };
|
|
2309
|
-
return delete next[elementSelector], {
|
|
2310
|
-
...c,
|
|
2311
|
-
next,
|
|
2312
|
-
cached: {
|
|
2313
|
-
...c.cached,
|
|
2314
|
-
[[restoreKey, elementSelector].join(delimiter)]: entry
|
|
2315
|
-
}
|
|
2316
|
-
};
|
|
2317
|
-
});
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
}), unsubOnResolved = router.subscribe("onResolved", (event) => {
|
|
2321
|
-
if (event.pathChanged) {
|
|
2322
|
-
if (!router.resetNextScroll)
|
|
2323
|
-
return;
|
|
2324
|
-
router.resetNextScroll = !0;
|
|
2325
|
-
const restoreKey = getKey(event.toLocation);
|
|
2326
|
-
let windowRestored = !1;
|
|
2327
|
-
for (const cacheKey in cache.state.cached) {
|
|
2328
|
-
const entry = cache.state.cached[cacheKey], [key, elementSelector] = cacheKey.split(delimiter);
|
|
2329
|
-
if (key === restoreKey) {
|
|
2330
|
-
if (elementSelector === windowKey)
|
|
2331
|
-
windowRestored = !0, window.scrollTo(entry.scrollX, entry.scrollY);
|
|
2332
|
-
else if (elementSelector) {
|
|
2333
|
-
const element = document.querySelector(elementSelector);
|
|
2334
|
-
element && (element.scrollLeft = entry.scrollX, element.scrollTop = entry.scrollY);
|
|
2335
|
-
}
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
windowRestored || window.scrollTo(0, 0), cache.set((c) => ({ ...c, next: {} })), weakScrolledElements = /* @__PURE__ */ new WeakSet();
|
|
2339
|
-
}
|
|
2340
|
-
});
|
|
2341
|
-
return () => {
|
|
2342
|
-
document.removeEventListener("scroll", onScroll), unsubOnBeforeLoad(), unsubOnResolved();
|
|
2343
|
-
};
|
|
2344
|
-
}, [options?.getKey, router]);
|
|
2345
|
-
}
|
|
2346
|
-
function ScrollRestoration(props) {
|
|
2347
|
-
return useScrollRestoration(props), null;
|
|
2348
|
-
}
|
|
2349
|
-
function getCssSelector(el) {
|
|
2350
|
-
const path = [];
|
|
2351
|
-
let parent;
|
|
2352
|
-
for (; parent = el.parentNode; )
|
|
2353
|
-
path.unshift(
|
|
2354
|
-
`${el.tagName}:nth-child(${[].indexOf.call(parent.children, el) + 1})`
|
|
2355
|
-
), el = parent;
|
|
2356
|
-
return `${path.join(" > ")}`.toLowerCase();
|
|
2357
|
-
}
|
|
2358
|
-
export {
|
|
2359
|
-
Link as L,
|
|
2360
|
-
Outlet as O,
|
|
2361
|
-
RouterProvider as R,
|
|
2362
|
-
ScrollRestoration as S,
|
|
2363
|
-
createFileRoute as a,
|
|
2364
|
-
useParams as b,
|
|
2365
|
-
createRootRouteWithContext as c,
|
|
2366
|
-
useRouterState as d,
|
|
2367
|
-
createRouter as e,
|
|
2368
|
-
createHashHistory as f,
|
|
2369
|
-
createBrowserHistory as g,
|
|
2370
|
-
isNotFound as i,
|
|
2371
|
-
notFound as n,
|
|
2372
|
-
useRouter as u
|
|
2373
|
-
};
|