@weaverse/react 5.4.1 → 5.5.0-beta.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/dist/index.d.mts +46 -1
- package/dist/index.d.ts +46 -1
- package/dist/index.js +2323 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2331 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -7
package/dist/index.js
CHANGED
|
@@ -34,11 +34,15 @@ __export(index_exports, {
|
|
|
34
34
|
WeaverseContextProvider: () => WeaverseContextProvider,
|
|
35
35
|
WeaverseItemContext: () => WeaverseItemContext,
|
|
36
36
|
WeaverseRoot: () => WeaverseRoot,
|
|
37
|
+
createWeaverseDataContext: () => createWeaverseDataContext,
|
|
38
|
+
replaceContentDataConnectors: () => replaceContentDataConnectors,
|
|
39
|
+
replaceContentDataConnectorsDeep: () => replaceContentDataConnectorsDeep,
|
|
37
40
|
useChildInstances: () => useChildInstances,
|
|
38
41
|
useItemInstance: () => useItemInstance,
|
|
39
42
|
useParentInstance: () => useParentInstance,
|
|
40
43
|
useSafeExternalStore: () => useSafeExternalStore,
|
|
41
|
-
useWeaverse: () => useWeaverse
|
|
44
|
+
useWeaverse: () => useWeaverse,
|
|
45
|
+
useWeaverseDataContext: () => useWeaverseDataContext
|
|
42
46
|
});
|
|
43
47
|
module.exports = __toCommonJS(index_exports);
|
|
44
48
|
__reExport(index_exports, require("@weaverse/core"), module.exports);
|
|
@@ -52,6 +56,2288 @@ var WeaverseItemContext = (0, import_react.createContext)({ id: "", parentId: ""
|
|
|
52
56
|
// src/hooks.ts
|
|
53
57
|
var import_core = require("@weaverse/core");
|
|
54
58
|
var import_react2 = require("react");
|
|
59
|
+
|
|
60
|
+
// ../../node_modules/react-router/dist/development/chunk-B7RQU5TL.mjs
|
|
61
|
+
var React = __toESM(require("react"), 1);
|
|
62
|
+
var React2 = __toESM(require("react"), 1);
|
|
63
|
+
var React3 = __toESM(require("react"), 1);
|
|
64
|
+
var React4 = __toESM(require("react"), 1);
|
|
65
|
+
var React9 = __toESM(require("react"), 1);
|
|
66
|
+
var React8 = __toESM(require("react"), 1);
|
|
67
|
+
var React7 = __toESM(require("react"), 1);
|
|
68
|
+
var React6 = __toESM(require("react"), 1);
|
|
69
|
+
var React5 = __toESM(require("react"), 1);
|
|
70
|
+
var React10 = __toESM(require("react"), 1);
|
|
71
|
+
var React11 = __toESM(require("react"), 1);
|
|
72
|
+
var import_meta = {};
|
|
73
|
+
function invariant(value, message) {
|
|
74
|
+
if (value === false || value === null || typeof value === "undefined") {
|
|
75
|
+
throw new Error(message);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function warning(cond, message) {
|
|
79
|
+
if (!cond) {
|
|
80
|
+
if (typeof console !== "undefined") console.warn(message);
|
|
81
|
+
try {
|
|
82
|
+
throw new Error(message);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function createPath({
|
|
88
|
+
pathname = "/",
|
|
89
|
+
search = "",
|
|
90
|
+
hash = ""
|
|
91
|
+
}) {
|
|
92
|
+
if (search && search !== "?")
|
|
93
|
+
pathname += search.charAt(0) === "?" ? search : "?" + search;
|
|
94
|
+
if (hash && hash !== "#")
|
|
95
|
+
pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
|
|
96
|
+
return pathname;
|
|
97
|
+
}
|
|
98
|
+
function parsePath(path) {
|
|
99
|
+
let parsedPath = {};
|
|
100
|
+
if (path) {
|
|
101
|
+
let hashIndex = path.indexOf("#");
|
|
102
|
+
if (hashIndex >= 0) {
|
|
103
|
+
parsedPath.hash = path.substring(hashIndex);
|
|
104
|
+
path = path.substring(0, hashIndex);
|
|
105
|
+
}
|
|
106
|
+
let searchIndex = path.indexOf("?");
|
|
107
|
+
if (searchIndex >= 0) {
|
|
108
|
+
parsedPath.search = path.substring(searchIndex);
|
|
109
|
+
path = path.substring(0, searchIndex);
|
|
110
|
+
}
|
|
111
|
+
if (path) {
|
|
112
|
+
parsedPath.pathname = path;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return parsedPath;
|
|
116
|
+
}
|
|
117
|
+
var _map;
|
|
118
|
+
_map = /* @__PURE__ */ new WeakMap();
|
|
119
|
+
function matchRoutes(routes, locationArg, basename = "/") {
|
|
120
|
+
return matchRoutesImpl(routes, locationArg, basename, false);
|
|
121
|
+
}
|
|
122
|
+
function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
|
|
123
|
+
let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
|
124
|
+
let pathname = stripBasename(location.pathname || "/", basename);
|
|
125
|
+
if (pathname == null) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
let branches = flattenRoutes(routes);
|
|
129
|
+
rankRouteBranches(branches);
|
|
130
|
+
let matches = null;
|
|
131
|
+
for (let i = 0; matches == null && i < branches.length; ++i) {
|
|
132
|
+
let decoded = decodePath(pathname);
|
|
133
|
+
matches = matchRouteBranch(
|
|
134
|
+
branches[i],
|
|
135
|
+
decoded,
|
|
136
|
+
allowPartial
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return matches;
|
|
140
|
+
}
|
|
141
|
+
function convertRouteMatchToUiMatch(match, loaderData) {
|
|
142
|
+
let { route, pathname, params } = match;
|
|
143
|
+
return {
|
|
144
|
+
id: route.id,
|
|
145
|
+
pathname,
|
|
146
|
+
params,
|
|
147
|
+
data: loaderData[route.id],
|
|
148
|
+
loaderData: loaderData[route.id],
|
|
149
|
+
handle: route.handle
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "", _hasParentOptionalSegments = false) {
|
|
153
|
+
let flattenRoute = (route, index, hasParentOptionalSegments = _hasParentOptionalSegments, relativePath) => {
|
|
154
|
+
let meta = {
|
|
155
|
+
relativePath: relativePath === void 0 ? route.path || "" : relativePath,
|
|
156
|
+
caseSensitive: route.caseSensitive === true,
|
|
157
|
+
childrenIndex: index,
|
|
158
|
+
route
|
|
159
|
+
};
|
|
160
|
+
if (meta.relativePath.startsWith("/")) {
|
|
161
|
+
if (!meta.relativePath.startsWith(parentPath) && hasParentOptionalSegments) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
invariant(
|
|
165
|
+
meta.relativePath.startsWith(parentPath),
|
|
166
|
+
`Absolute route path "${meta.relativePath}" nested under path "${parentPath}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`
|
|
167
|
+
);
|
|
168
|
+
meta.relativePath = meta.relativePath.slice(parentPath.length);
|
|
169
|
+
}
|
|
170
|
+
let path = joinPaths([parentPath, meta.relativePath]);
|
|
171
|
+
let routesMeta = parentsMeta.concat(meta);
|
|
172
|
+
if (route.children && route.children.length > 0) {
|
|
173
|
+
invariant(
|
|
174
|
+
// Our types know better, but runtime JS may not!
|
|
175
|
+
// @ts-expect-error
|
|
176
|
+
route.index !== true,
|
|
177
|
+
`Index routes must not have child routes. Please remove all child routes from route path "${path}".`
|
|
178
|
+
);
|
|
179
|
+
flattenRoutes(
|
|
180
|
+
route.children,
|
|
181
|
+
branches,
|
|
182
|
+
routesMeta,
|
|
183
|
+
path,
|
|
184
|
+
hasParentOptionalSegments
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
if (route.path == null && !route.index) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
branches.push({
|
|
191
|
+
path,
|
|
192
|
+
score: computeScore(path, route.index),
|
|
193
|
+
routesMeta
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
routes.forEach((route, index) => {
|
|
197
|
+
if (route.path === "" || !route.path?.includes("?")) {
|
|
198
|
+
flattenRoute(route, index);
|
|
199
|
+
} else {
|
|
200
|
+
for (let exploded of explodeOptionalSegments(route.path)) {
|
|
201
|
+
flattenRoute(route, index, true, exploded);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return branches;
|
|
206
|
+
}
|
|
207
|
+
function explodeOptionalSegments(path) {
|
|
208
|
+
let segments = path.split("/");
|
|
209
|
+
if (segments.length === 0) return [];
|
|
210
|
+
let [first, ...rest] = segments;
|
|
211
|
+
let isOptional = first.endsWith("?");
|
|
212
|
+
let required = first.replace(/\?$/, "");
|
|
213
|
+
if (rest.length === 0) {
|
|
214
|
+
return isOptional ? [required, ""] : [required];
|
|
215
|
+
}
|
|
216
|
+
let restExploded = explodeOptionalSegments(rest.join("/"));
|
|
217
|
+
let result = [];
|
|
218
|
+
result.push(
|
|
219
|
+
...restExploded.map(
|
|
220
|
+
(subpath) => subpath === "" ? required : [required, subpath].join("/")
|
|
221
|
+
)
|
|
222
|
+
);
|
|
223
|
+
if (isOptional) {
|
|
224
|
+
result.push(...restExploded);
|
|
225
|
+
}
|
|
226
|
+
return result.map(
|
|
227
|
+
(exploded) => path.startsWith("/") && exploded === "" ? "/" : exploded
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
function rankRouteBranches(branches) {
|
|
231
|
+
branches.sort(
|
|
232
|
+
(a, b) => a.score !== b.score ? b.score - a.score : compareIndexes(
|
|
233
|
+
a.routesMeta.map((meta) => meta.childrenIndex),
|
|
234
|
+
b.routesMeta.map((meta) => meta.childrenIndex)
|
|
235
|
+
)
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
var paramRe = /^:[\w-]+$/;
|
|
239
|
+
var dynamicSegmentValue = 3;
|
|
240
|
+
var indexRouteValue = 2;
|
|
241
|
+
var emptySegmentValue = 1;
|
|
242
|
+
var staticSegmentValue = 10;
|
|
243
|
+
var splatPenalty = -2;
|
|
244
|
+
var isSplat = (s) => s === "*";
|
|
245
|
+
function computeScore(path, index) {
|
|
246
|
+
let segments = path.split("/");
|
|
247
|
+
let initialScore = segments.length;
|
|
248
|
+
if (segments.some(isSplat)) {
|
|
249
|
+
initialScore += splatPenalty;
|
|
250
|
+
}
|
|
251
|
+
if (index) {
|
|
252
|
+
initialScore += indexRouteValue;
|
|
253
|
+
}
|
|
254
|
+
return segments.filter((s) => !isSplat(s)).reduce(
|
|
255
|
+
(score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue),
|
|
256
|
+
initialScore
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
function compareIndexes(a, b) {
|
|
260
|
+
let siblings = a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]);
|
|
261
|
+
return siblings ? (
|
|
262
|
+
// If two routes are siblings, we should try to match the earlier sibling
|
|
263
|
+
// first. This allows people to have fine-grained control over the matching
|
|
264
|
+
// behavior by simply putting routes with identical paths in the order they
|
|
265
|
+
// want them tried.
|
|
266
|
+
a[a.length - 1] - b[b.length - 1]
|
|
267
|
+
) : (
|
|
268
|
+
// Otherwise, it doesn't really make sense to rank non-siblings by index,
|
|
269
|
+
// so they sort equally.
|
|
270
|
+
0
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
function matchRouteBranch(branch, pathname, allowPartial = false) {
|
|
274
|
+
let { routesMeta } = branch;
|
|
275
|
+
let matchedParams = {};
|
|
276
|
+
let matchedPathname = "/";
|
|
277
|
+
let matches = [];
|
|
278
|
+
for (let i = 0; i < routesMeta.length; ++i) {
|
|
279
|
+
let meta = routesMeta[i];
|
|
280
|
+
let end = i === routesMeta.length - 1;
|
|
281
|
+
let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/";
|
|
282
|
+
let match = matchPath(
|
|
283
|
+
{ path: meta.relativePath, caseSensitive: meta.caseSensitive, end },
|
|
284
|
+
remainingPathname
|
|
285
|
+
);
|
|
286
|
+
let route = meta.route;
|
|
287
|
+
if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) {
|
|
288
|
+
match = matchPath(
|
|
289
|
+
{
|
|
290
|
+
path: meta.relativePath,
|
|
291
|
+
caseSensitive: meta.caseSensitive,
|
|
292
|
+
end: false
|
|
293
|
+
},
|
|
294
|
+
remainingPathname
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
if (!match) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
Object.assign(matchedParams, match.params);
|
|
301
|
+
matches.push({
|
|
302
|
+
// TODO: Can this as be avoided?
|
|
303
|
+
params: matchedParams,
|
|
304
|
+
pathname: joinPaths([matchedPathname, match.pathname]),
|
|
305
|
+
pathnameBase: normalizePathname(
|
|
306
|
+
joinPaths([matchedPathname, match.pathnameBase])
|
|
307
|
+
),
|
|
308
|
+
route
|
|
309
|
+
});
|
|
310
|
+
if (match.pathnameBase !== "/") {
|
|
311
|
+
matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return matches;
|
|
315
|
+
}
|
|
316
|
+
function matchPath(pattern, pathname) {
|
|
317
|
+
if (typeof pattern === "string") {
|
|
318
|
+
pattern = { path: pattern, caseSensitive: false, end: true };
|
|
319
|
+
}
|
|
320
|
+
let [matcher, compiledParams] = compilePath(
|
|
321
|
+
pattern.path,
|
|
322
|
+
pattern.caseSensitive,
|
|
323
|
+
pattern.end
|
|
324
|
+
);
|
|
325
|
+
let match = pathname.match(matcher);
|
|
326
|
+
if (!match) return null;
|
|
327
|
+
let matchedPathname = match[0];
|
|
328
|
+
let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
|
|
329
|
+
let captureGroups = match.slice(1);
|
|
330
|
+
let params = compiledParams.reduce(
|
|
331
|
+
(memo22, { paramName, isOptional }, index) => {
|
|
332
|
+
if (paramName === "*") {
|
|
333
|
+
let splatValue = captureGroups[index] || "";
|
|
334
|
+
pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
|
|
335
|
+
}
|
|
336
|
+
const value = captureGroups[index];
|
|
337
|
+
if (isOptional && !value) {
|
|
338
|
+
memo22[paramName] = void 0;
|
|
339
|
+
} else {
|
|
340
|
+
memo22[paramName] = (value || "").replace(/%2F/g, "/");
|
|
341
|
+
}
|
|
342
|
+
return memo22;
|
|
343
|
+
},
|
|
344
|
+
{}
|
|
345
|
+
);
|
|
346
|
+
return {
|
|
347
|
+
params,
|
|
348
|
+
pathname: matchedPathname,
|
|
349
|
+
pathnameBase,
|
|
350
|
+
pattern
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function compilePath(path, caseSensitive = false, end = true) {
|
|
354
|
+
warning(
|
|
355
|
+
path === "*" || !path.endsWith("*") || path.endsWith("/*"),
|
|
356
|
+
`Route path "${path}" will be treated as if it were "${path.replace(/\*$/, "/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${path.replace(/\*$/, "/*")}".`
|
|
357
|
+
);
|
|
358
|
+
let params = [];
|
|
359
|
+
let regexpSource = "^" + path.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(
|
|
360
|
+
/\/:([\w-]+)(\?)?/g,
|
|
361
|
+
(_, paramName, isOptional) => {
|
|
362
|
+
params.push({ paramName, isOptional: isOptional != null });
|
|
363
|
+
return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
|
|
364
|
+
}
|
|
365
|
+
).replace(/\/([\w-]+)\?(\/|$)/g, "(/$1)?$2");
|
|
366
|
+
if (path.endsWith("*")) {
|
|
367
|
+
params.push({ paramName: "*" });
|
|
368
|
+
regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
|
|
369
|
+
} else if (end) {
|
|
370
|
+
regexpSource += "\\/*$";
|
|
371
|
+
} else if (path !== "" && path !== "/") {
|
|
372
|
+
regexpSource += "(?:(?=\\/|$))";
|
|
373
|
+
} else {
|
|
374
|
+
}
|
|
375
|
+
let matcher = new RegExp(regexpSource, caseSensitive ? void 0 : "i");
|
|
376
|
+
return [matcher, params];
|
|
377
|
+
}
|
|
378
|
+
function decodePath(value) {
|
|
379
|
+
try {
|
|
380
|
+
return value.split("/").map((v) => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
|
|
381
|
+
} catch (error) {
|
|
382
|
+
warning(
|
|
383
|
+
false,
|
|
384
|
+
`The URL path "${value}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${error}).`
|
|
385
|
+
);
|
|
386
|
+
return value;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function stripBasename(pathname, basename) {
|
|
390
|
+
if (basename === "/") return pathname;
|
|
391
|
+
if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length;
|
|
395
|
+
let nextChar = pathname.charAt(startIndex);
|
|
396
|
+
if (nextChar && nextChar !== "/") {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
return pathname.slice(startIndex) || "/";
|
|
400
|
+
}
|
|
401
|
+
function resolvePath(to, fromPathname = "/") {
|
|
402
|
+
let {
|
|
403
|
+
pathname: toPathname,
|
|
404
|
+
search = "",
|
|
405
|
+
hash = ""
|
|
406
|
+
} = typeof to === "string" ? parsePath(to) : to;
|
|
407
|
+
let pathname = toPathname ? toPathname.startsWith("/") ? toPathname : resolvePathname(toPathname, fromPathname) : fromPathname;
|
|
408
|
+
return {
|
|
409
|
+
pathname,
|
|
410
|
+
search: normalizeSearch(search),
|
|
411
|
+
hash: normalizeHash(hash)
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function resolvePathname(relativePath, fromPathname) {
|
|
415
|
+
let segments = fromPathname.replace(/\/+$/, "").split("/");
|
|
416
|
+
let relativeSegments = relativePath.split("/");
|
|
417
|
+
relativeSegments.forEach((segment) => {
|
|
418
|
+
if (segment === "..") {
|
|
419
|
+
if (segments.length > 1) segments.pop();
|
|
420
|
+
} else if (segment !== ".") {
|
|
421
|
+
segments.push(segment);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
return segments.length > 1 ? segments.join("/") : "/";
|
|
425
|
+
}
|
|
426
|
+
function getInvalidPathError(char, field, dest, path) {
|
|
427
|
+
return `Cannot include a '${char}' character in a manually specified \`to.${field}\` field [${JSON.stringify(
|
|
428
|
+
path
|
|
429
|
+
)}]. Please separate it out to the \`to.${dest}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`;
|
|
430
|
+
}
|
|
431
|
+
function getPathContributingMatches(matches) {
|
|
432
|
+
return matches.filter(
|
|
433
|
+
(match, index) => index === 0 || match.route.path && match.route.path.length > 0
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
function getResolveToMatches(matches) {
|
|
437
|
+
let pathMatches = getPathContributingMatches(matches);
|
|
438
|
+
return pathMatches.map(
|
|
439
|
+
(match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
function resolveTo(toArg, routePathnames, locationPathname, isPathRelative = false) {
|
|
443
|
+
let to;
|
|
444
|
+
if (typeof toArg === "string") {
|
|
445
|
+
to = parsePath(toArg);
|
|
446
|
+
} else {
|
|
447
|
+
to = { ...toArg };
|
|
448
|
+
invariant(
|
|
449
|
+
!to.pathname || !to.pathname.includes("?"),
|
|
450
|
+
getInvalidPathError("?", "pathname", "search", to)
|
|
451
|
+
);
|
|
452
|
+
invariant(
|
|
453
|
+
!to.pathname || !to.pathname.includes("#"),
|
|
454
|
+
getInvalidPathError("#", "pathname", "hash", to)
|
|
455
|
+
);
|
|
456
|
+
invariant(
|
|
457
|
+
!to.search || !to.search.includes("#"),
|
|
458
|
+
getInvalidPathError("#", "search", "hash", to)
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
let isEmptyPath = toArg === "" || to.pathname === "";
|
|
462
|
+
let toPathname = isEmptyPath ? "/" : to.pathname;
|
|
463
|
+
let from;
|
|
464
|
+
if (toPathname == null) {
|
|
465
|
+
from = locationPathname;
|
|
466
|
+
} else {
|
|
467
|
+
let routePathnameIndex = routePathnames.length - 1;
|
|
468
|
+
if (!isPathRelative && toPathname.startsWith("..")) {
|
|
469
|
+
let toSegments = toPathname.split("/");
|
|
470
|
+
while (toSegments[0] === "..") {
|
|
471
|
+
toSegments.shift();
|
|
472
|
+
routePathnameIndex -= 1;
|
|
473
|
+
}
|
|
474
|
+
to.pathname = toSegments.join("/");
|
|
475
|
+
}
|
|
476
|
+
from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
|
|
477
|
+
}
|
|
478
|
+
let path = resolvePath(to, from);
|
|
479
|
+
let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/");
|
|
480
|
+
let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/");
|
|
481
|
+
if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) {
|
|
482
|
+
path.pathname += "/";
|
|
483
|
+
}
|
|
484
|
+
return path;
|
|
485
|
+
}
|
|
486
|
+
var joinPaths = (paths) => paths.join("/").replace(/\/\/+/g, "/");
|
|
487
|
+
var normalizePathname = (pathname) => pathname.replace(/\/+$/, "").replace(/^\/*/, "/");
|
|
488
|
+
var normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
|
|
489
|
+
var normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
|
|
490
|
+
function isRouteErrorResponse(error) {
|
|
491
|
+
return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
|
|
492
|
+
}
|
|
493
|
+
var validMutationMethodsArr = [
|
|
494
|
+
"POST",
|
|
495
|
+
"PUT",
|
|
496
|
+
"PATCH",
|
|
497
|
+
"DELETE"
|
|
498
|
+
];
|
|
499
|
+
var validMutationMethods = new Set(
|
|
500
|
+
validMutationMethodsArr
|
|
501
|
+
);
|
|
502
|
+
var validRequestMethodsArr = [
|
|
503
|
+
"GET",
|
|
504
|
+
...validMutationMethodsArr
|
|
505
|
+
];
|
|
506
|
+
var validRequestMethods = new Set(validRequestMethodsArr);
|
|
507
|
+
var ResetLoaderDataSymbol = Symbol("ResetLoaderData");
|
|
508
|
+
var DataRouterContext = React.createContext(null);
|
|
509
|
+
DataRouterContext.displayName = "DataRouter";
|
|
510
|
+
var DataRouterStateContext = React.createContext(null);
|
|
511
|
+
DataRouterStateContext.displayName = "DataRouterState";
|
|
512
|
+
var RSCRouterContext = React.createContext(false);
|
|
513
|
+
var ViewTransitionContext = React.createContext({
|
|
514
|
+
isTransitioning: false
|
|
515
|
+
});
|
|
516
|
+
ViewTransitionContext.displayName = "ViewTransition";
|
|
517
|
+
var FetchersContext = React.createContext(
|
|
518
|
+
/* @__PURE__ */ new Map()
|
|
519
|
+
);
|
|
520
|
+
FetchersContext.displayName = "Fetchers";
|
|
521
|
+
var AwaitContext = React.createContext(null);
|
|
522
|
+
AwaitContext.displayName = "Await";
|
|
523
|
+
var NavigationContext = React.createContext(
|
|
524
|
+
null
|
|
525
|
+
);
|
|
526
|
+
NavigationContext.displayName = "Navigation";
|
|
527
|
+
var LocationContext = React.createContext(
|
|
528
|
+
null
|
|
529
|
+
);
|
|
530
|
+
LocationContext.displayName = "Location";
|
|
531
|
+
var RouteContext = React.createContext({
|
|
532
|
+
outlet: null,
|
|
533
|
+
matches: [],
|
|
534
|
+
isDataRoute: false
|
|
535
|
+
});
|
|
536
|
+
RouteContext.displayName = "Route";
|
|
537
|
+
var RouteErrorContext = React.createContext(null);
|
|
538
|
+
RouteErrorContext.displayName = "RouteError";
|
|
539
|
+
var ENABLE_DEV_WARNINGS = true;
|
|
540
|
+
function useHref(to, { relative } = {}) {
|
|
541
|
+
invariant(
|
|
542
|
+
useInRouterContext(),
|
|
543
|
+
// TODO: This error is probably because they somehow have 2 versions of the
|
|
544
|
+
// router loaded. We can help them understand how to avoid that.
|
|
545
|
+
`useHref() may be used only in the context of a <Router> component.`
|
|
546
|
+
);
|
|
547
|
+
let { basename, navigator } = React2.useContext(NavigationContext);
|
|
548
|
+
let { hash, pathname, search } = useResolvedPath(to, { relative });
|
|
549
|
+
let joinedPathname = pathname;
|
|
550
|
+
if (basename !== "/") {
|
|
551
|
+
joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
|
|
552
|
+
}
|
|
553
|
+
return navigator.createHref({ pathname: joinedPathname, search, hash });
|
|
554
|
+
}
|
|
555
|
+
function useInRouterContext() {
|
|
556
|
+
return React2.useContext(LocationContext) != null;
|
|
557
|
+
}
|
|
558
|
+
function useLocation() {
|
|
559
|
+
invariant(
|
|
560
|
+
useInRouterContext(),
|
|
561
|
+
// TODO: This error is probably because they somehow have 2 versions of the
|
|
562
|
+
// router loaded. We can help them understand how to avoid that.
|
|
563
|
+
`useLocation() may be used only in the context of a <Router> component.`
|
|
564
|
+
);
|
|
565
|
+
return React2.useContext(LocationContext).location;
|
|
566
|
+
}
|
|
567
|
+
var navigateEffectWarning = `You should call navigate() in a React.useEffect(), not when your component is first rendered.`;
|
|
568
|
+
function useIsomorphicLayoutEffect(cb) {
|
|
569
|
+
let isStatic = React2.useContext(NavigationContext).static;
|
|
570
|
+
if (!isStatic) {
|
|
571
|
+
React2.useLayoutEffect(cb);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
function useNavigate() {
|
|
575
|
+
let { isDataRoute } = React2.useContext(RouteContext);
|
|
576
|
+
return isDataRoute ? useNavigateStable() : useNavigateUnstable();
|
|
577
|
+
}
|
|
578
|
+
function useNavigateUnstable() {
|
|
579
|
+
invariant(
|
|
580
|
+
useInRouterContext(),
|
|
581
|
+
// TODO: This error is probably because they somehow have 2 versions of the
|
|
582
|
+
// router loaded. We can help them understand how to avoid that.
|
|
583
|
+
`useNavigate() may be used only in the context of a <Router> component.`
|
|
584
|
+
);
|
|
585
|
+
let dataRouterContext = React2.useContext(DataRouterContext);
|
|
586
|
+
let { basename, navigator } = React2.useContext(NavigationContext);
|
|
587
|
+
let { matches } = React2.useContext(RouteContext);
|
|
588
|
+
let { pathname: locationPathname } = useLocation();
|
|
589
|
+
let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
|
|
590
|
+
let activeRef = React2.useRef(false);
|
|
591
|
+
useIsomorphicLayoutEffect(() => {
|
|
592
|
+
activeRef.current = true;
|
|
593
|
+
});
|
|
594
|
+
let navigate = React2.useCallback(
|
|
595
|
+
(to, options = {}) => {
|
|
596
|
+
warning(activeRef.current, navigateEffectWarning);
|
|
597
|
+
if (!activeRef.current) return;
|
|
598
|
+
if (typeof to === "number") {
|
|
599
|
+
navigator.go(to);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
let path = resolveTo(
|
|
603
|
+
to,
|
|
604
|
+
JSON.parse(routePathnamesJson),
|
|
605
|
+
locationPathname,
|
|
606
|
+
options.relative === "path"
|
|
607
|
+
);
|
|
608
|
+
if (dataRouterContext == null && basename !== "/") {
|
|
609
|
+
path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
|
610
|
+
}
|
|
611
|
+
(!!options.replace ? navigator.replace : navigator.push)(
|
|
612
|
+
path,
|
|
613
|
+
options.state,
|
|
614
|
+
options
|
|
615
|
+
);
|
|
616
|
+
},
|
|
617
|
+
[
|
|
618
|
+
basename,
|
|
619
|
+
navigator,
|
|
620
|
+
routePathnamesJson,
|
|
621
|
+
locationPathname,
|
|
622
|
+
dataRouterContext
|
|
623
|
+
]
|
|
624
|
+
);
|
|
625
|
+
return navigate;
|
|
626
|
+
}
|
|
627
|
+
var OutletContext = React2.createContext(null);
|
|
628
|
+
function useResolvedPath(to, { relative } = {}) {
|
|
629
|
+
let { matches } = React2.useContext(RouteContext);
|
|
630
|
+
let { pathname: locationPathname } = useLocation();
|
|
631
|
+
let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
|
|
632
|
+
return React2.useMemo(
|
|
633
|
+
() => resolveTo(
|
|
634
|
+
to,
|
|
635
|
+
JSON.parse(routePathnamesJson),
|
|
636
|
+
locationPathname,
|
|
637
|
+
relative === "path"
|
|
638
|
+
),
|
|
639
|
+
[to, routePathnamesJson, locationPathname, relative]
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
function useRoutesImpl(routes, locationArg, dataRouterState, unstable_onError, future) {
|
|
643
|
+
invariant(
|
|
644
|
+
useInRouterContext(),
|
|
645
|
+
// TODO: This error is probably because they somehow have 2 versions of the
|
|
646
|
+
// router loaded. We can help them understand how to avoid that.
|
|
647
|
+
`useRoutes() may be used only in the context of a <Router> component.`
|
|
648
|
+
);
|
|
649
|
+
let { navigator } = React2.useContext(NavigationContext);
|
|
650
|
+
let { matches: parentMatches } = React2.useContext(RouteContext);
|
|
651
|
+
let routeMatch = parentMatches[parentMatches.length - 1];
|
|
652
|
+
let parentParams = routeMatch ? routeMatch.params : {};
|
|
653
|
+
let parentPathname = routeMatch ? routeMatch.pathname : "/";
|
|
654
|
+
let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
|
|
655
|
+
let parentRoute = routeMatch && routeMatch.route;
|
|
656
|
+
if (ENABLE_DEV_WARNINGS) {
|
|
657
|
+
let parentPath = parentRoute && parentRoute.path || "";
|
|
658
|
+
warningOnce(
|
|
659
|
+
parentPathname,
|
|
660
|
+
!parentRoute || parentPath.endsWith("*") || parentPath.endsWith("*?"),
|
|
661
|
+
`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${parentPathname}" (under <Route path="${parentPath}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
|
|
662
|
+
|
|
663
|
+
Please change the parent <Route path="${parentPath}"> to <Route path="${parentPath === "/" ? "*" : `${parentPath}/*`}">.`
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
let locationFromContext = useLocation();
|
|
667
|
+
let location;
|
|
668
|
+
if (locationArg) {
|
|
669
|
+
let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
|
670
|
+
invariant(
|
|
671
|
+
parentPathnameBase === "/" || parsedLocationArg.pathname?.startsWith(parentPathnameBase),
|
|
672
|
+
`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${parentPathnameBase}" but pathname "${parsedLocationArg.pathname}" was given in the \`location\` prop.`
|
|
673
|
+
);
|
|
674
|
+
location = parsedLocationArg;
|
|
675
|
+
} else {
|
|
676
|
+
location = locationFromContext;
|
|
677
|
+
}
|
|
678
|
+
let pathname = location.pathname || "/";
|
|
679
|
+
let remainingPathname = pathname;
|
|
680
|
+
if (parentPathnameBase !== "/") {
|
|
681
|
+
let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
|
|
682
|
+
let segments = pathname.replace(/^\//, "").split("/");
|
|
683
|
+
remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
|
|
684
|
+
}
|
|
685
|
+
let matches = matchRoutes(routes, { pathname: remainingPathname });
|
|
686
|
+
if (ENABLE_DEV_WARNINGS) {
|
|
687
|
+
warning(
|
|
688
|
+
parentRoute || matches != null,
|
|
689
|
+
`No routes matched location "${location.pathname}${location.search}${location.hash}" `
|
|
690
|
+
);
|
|
691
|
+
warning(
|
|
692
|
+
matches == null || matches[matches.length - 1].route.element !== void 0 || matches[matches.length - 1].route.Component !== void 0 || matches[matches.length - 1].route.lazy !== void 0,
|
|
693
|
+
`Matched leaf route at location "${location.pathname}${location.search}${location.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
let renderedMatches = _renderMatches(
|
|
697
|
+
matches && matches.map(
|
|
698
|
+
(match) => Object.assign({}, match, {
|
|
699
|
+
params: Object.assign({}, parentParams, match.params),
|
|
700
|
+
pathname: joinPaths([
|
|
701
|
+
parentPathnameBase,
|
|
702
|
+
// Re-encode pathnames that were decoded inside matchRoutes
|
|
703
|
+
navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname
|
|
704
|
+
]),
|
|
705
|
+
pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([
|
|
706
|
+
parentPathnameBase,
|
|
707
|
+
// Re-encode pathnames that were decoded inside matchRoutes
|
|
708
|
+
navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase
|
|
709
|
+
])
|
|
710
|
+
})
|
|
711
|
+
),
|
|
712
|
+
parentMatches,
|
|
713
|
+
dataRouterState,
|
|
714
|
+
unstable_onError,
|
|
715
|
+
future
|
|
716
|
+
);
|
|
717
|
+
if (locationArg && renderedMatches) {
|
|
718
|
+
return /* @__PURE__ */ React2.createElement(
|
|
719
|
+
LocationContext.Provider,
|
|
720
|
+
{
|
|
721
|
+
value: {
|
|
722
|
+
location: {
|
|
723
|
+
pathname: "/",
|
|
724
|
+
search: "",
|
|
725
|
+
hash: "",
|
|
726
|
+
state: null,
|
|
727
|
+
key: "default",
|
|
728
|
+
...location
|
|
729
|
+
},
|
|
730
|
+
navigationType: "POP"
|
|
731
|
+
/* Pop */
|
|
732
|
+
}
|
|
733
|
+
},
|
|
734
|
+
renderedMatches
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
return renderedMatches;
|
|
738
|
+
}
|
|
739
|
+
function DefaultErrorComponent() {
|
|
740
|
+
let error = useRouteError();
|
|
741
|
+
let message = isRouteErrorResponse(error) ? `${error.status} ${error.statusText}` : error instanceof Error ? error.message : JSON.stringify(error);
|
|
742
|
+
let stack = error instanceof Error ? error.stack : null;
|
|
743
|
+
let lightgrey = "rgba(200,200,200, 0.5)";
|
|
744
|
+
let preStyles = { padding: "0.5rem", backgroundColor: lightgrey };
|
|
745
|
+
let codeStyles = { padding: "2px 4px", backgroundColor: lightgrey };
|
|
746
|
+
let devInfo = null;
|
|
747
|
+
if (ENABLE_DEV_WARNINGS) {
|
|
748
|
+
console.error(
|
|
749
|
+
"Error handled by React Router default ErrorBoundary:",
|
|
750
|
+
error
|
|
751
|
+
);
|
|
752
|
+
devInfo = /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("p", null, "\u{1F4BF} Hey developer \u{1F44B}"), /* @__PURE__ */ React2.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ React2.createElement("code", { style: codeStyles }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ React2.createElement("code", { style: codeStyles }, "errorElement"), " prop on your route."));
|
|
753
|
+
}
|
|
754
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ React2.createElement("h3", { style: { fontStyle: "italic" } }, message), stack ? /* @__PURE__ */ React2.createElement("pre", { style: preStyles }, stack) : null, devInfo);
|
|
755
|
+
}
|
|
756
|
+
var defaultErrorElement = /* @__PURE__ */ React2.createElement(DefaultErrorComponent, null);
|
|
757
|
+
var RenderErrorBoundary = class extends React2.Component {
|
|
758
|
+
constructor(props) {
|
|
759
|
+
super(props);
|
|
760
|
+
this.state = {
|
|
761
|
+
location: props.location,
|
|
762
|
+
revalidation: props.revalidation,
|
|
763
|
+
error: props.error
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
static getDerivedStateFromError(error) {
|
|
767
|
+
return { error };
|
|
768
|
+
}
|
|
769
|
+
static getDerivedStateFromProps(props, state) {
|
|
770
|
+
if (state.location !== props.location || state.revalidation !== "idle" && props.revalidation === "idle") {
|
|
771
|
+
return {
|
|
772
|
+
error: props.error,
|
|
773
|
+
location: props.location,
|
|
774
|
+
revalidation: props.revalidation
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
return {
|
|
778
|
+
error: props.error !== void 0 ? props.error : state.error,
|
|
779
|
+
location: state.location,
|
|
780
|
+
revalidation: props.revalidation || state.revalidation
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
componentDidCatch(error, errorInfo) {
|
|
784
|
+
if (this.props.unstable_onError) {
|
|
785
|
+
this.props.unstable_onError(error, errorInfo);
|
|
786
|
+
} else {
|
|
787
|
+
console.error(
|
|
788
|
+
"React Router caught the following error during render",
|
|
789
|
+
error
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
render() {
|
|
794
|
+
return this.state.error !== void 0 ? /* @__PURE__ */ React2.createElement(RouteContext.Provider, { value: this.props.routeContext }, /* @__PURE__ */ React2.createElement(
|
|
795
|
+
RouteErrorContext.Provider,
|
|
796
|
+
{
|
|
797
|
+
value: this.state.error,
|
|
798
|
+
children: this.props.component
|
|
799
|
+
}
|
|
800
|
+
)) : this.props.children;
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
function RenderedRoute({ routeContext, match, children }) {
|
|
804
|
+
let dataRouterContext = React2.useContext(DataRouterContext);
|
|
805
|
+
if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
|
|
806
|
+
dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
|
|
807
|
+
}
|
|
808
|
+
return /* @__PURE__ */ React2.createElement(RouteContext.Provider, { value: routeContext }, children);
|
|
809
|
+
}
|
|
810
|
+
function _renderMatches(matches, parentMatches = [], dataRouterState = null, unstable_onError = null, future = null) {
|
|
811
|
+
if (matches == null) {
|
|
812
|
+
if (!dataRouterState) {
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
if (dataRouterState.errors) {
|
|
816
|
+
matches = dataRouterState.matches;
|
|
817
|
+
} else if (parentMatches.length === 0 && !dataRouterState.initialized && dataRouterState.matches.length > 0) {
|
|
818
|
+
matches = dataRouterState.matches;
|
|
819
|
+
} else {
|
|
820
|
+
return null;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
let renderedMatches = matches;
|
|
824
|
+
let errors = dataRouterState?.errors;
|
|
825
|
+
if (errors != null) {
|
|
826
|
+
let errorIndex = renderedMatches.findIndex(
|
|
827
|
+
(m) => m.route.id && errors?.[m.route.id] !== void 0
|
|
828
|
+
);
|
|
829
|
+
invariant(
|
|
830
|
+
errorIndex >= 0,
|
|
831
|
+
`Could not find a matching route for errors on route IDs: ${Object.keys(
|
|
832
|
+
errors
|
|
833
|
+
).join(",")}`
|
|
834
|
+
);
|
|
835
|
+
renderedMatches = renderedMatches.slice(
|
|
836
|
+
0,
|
|
837
|
+
Math.min(renderedMatches.length, errorIndex + 1)
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
let renderFallback = false;
|
|
841
|
+
let fallbackIndex = -1;
|
|
842
|
+
if (dataRouterState) {
|
|
843
|
+
for (let i = 0; i < renderedMatches.length; i++) {
|
|
844
|
+
let match = renderedMatches[i];
|
|
845
|
+
if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
|
|
846
|
+
fallbackIndex = i;
|
|
847
|
+
}
|
|
848
|
+
if (match.route.id) {
|
|
849
|
+
let { loaderData, errors: errors2 } = dataRouterState;
|
|
850
|
+
let needsToRunLoader = match.route.loader && !loaderData.hasOwnProperty(match.route.id) && (!errors2 || errors2[match.route.id] === void 0);
|
|
851
|
+
if (match.route.lazy || needsToRunLoader) {
|
|
852
|
+
renderFallback = true;
|
|
853
|
+
if (fallbackIndex >= 0) {
|
|
854
|
+
renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
|
|
855
|
+
} else {
|
|
856
|
+
renderedMatches = [renderedMatches[0]];
|
|
857
|
+
}
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
return renderedMatches.reduceRight(
|
|
864
|
+
(outlet, match, index) => {
|
|
865
|
+
let error;
|
|
866
|
+
let shouldRenderHydrateFallback = false;
|
|
867
|
+
let errorElement = null;
|
|
868
|
+
let hydrateFallbackElement = null;
|
|
869
|
+
if (dataRouterState) {
|
|
870
|
+
error = errors && match.route.id ? errors[match.route.id] : void 0;
|
|
871
|
+
errorElement = match.route.errorElement || defaultErrorElement;
|
|
872
|
+
if (renderFallback) {
|
|
873
|
+
if (fallbackIndex < 0 && index === 0) {
|
|
874
|
+
warningOnce(
|
|
875
|
+
"route-fallback",
|
|
876
|
+
false,
|
|
877
|
+
"No `HydrateFallback` element provided to render during initial hydration"
|
|
878
|
+
);
|
|
879
|
+
shouldRenderHydrateFallback = true;
|
|
880
|
+
hydrateFallbackElement = null;
|
|
881
|
+
} else if (fallbackIndex === index) {
|
|
882
|
+
shouldRenderHydrateFallback = true;
|
|
883
|
+
hydrateFallbackElement = match.route.hydrateFallbackElement || null;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
let matches2 = parentMatches.concat(renderedMatches.slice(0, index + 1));
|
|
888
|
+
let getChildren = () => {
|
|
889
|
+
let children;
|
|
890
|
+
if (error) {
|
|
891
|
+
children = errorElement;
|
|
892
|
+
} else if (shouldRenderHydrateFallback) {
|
|
893
|
+
children = hydrateFallbackElement;
|
|
894
|
+
} else if (match.route.Component) {
|
|
895
|
+
children = /* @__PURE__ */ React2.createElement(match.route.Component, null);
|
|
896
|
+
} else if (match.route.element) {
|
|
897
|
+
children = match.route.element;
|
|
898
|
+
} else {
|
|
899
|
+
children = outlet;
|
|
900
|
+
}
|
|
901
|
+
return /* @__PURE__ */ React2.createElement(
|
|
902
|
+
RenderedRoute,
|
|
903
|
+
{
|
|
904
|
+
match,
|
|
905
|
+
routeContext: {
|
|
906
|
+
outlet,
|
|
907
|
+
matches: matches2,
|
|
908
|
+
isDataRoute: dataRouterState != null
|
|
909
|
+
},
|
|
910
|
+
children
|
|
911
|
+
}
|
|
912
|
+
);
|
|
913
|
+
};
|
|
914
|
+
return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? /* @__PURE__ */ React2.createElement(
|
|
915
|
+
RenderErrorBoundary,
|
|
916
|
+
{
|
|
917
|
+
location: dataRouterState.location,
|
|
918
|
+
revalidation: dataRouterState.revalidation,
|
|
919
|
+
component: errorElement,
|
|
920
|
+
error,
|
|
921
|
+
children: getChildren(),
|
|
922
|
+
routeContext: { outlet: null, matches: matches2, isDataRoute: true },
|
|
923
|
+
unstable_onError
|
|
924
|
+
}
|
|
925
|
+
) : getChildren();
|
|
926
|
+
},
|
|
927
|
+
null
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
function getDataRouterConsoleError(hookName) {
|
|
931
|
+
return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
|
|
932
|
+
}
|
|
933
|
+
function useDataRouterContext(hookName) {
|
|
934
|
+
let ctx = React2.useContext(DataRouterContext);
|
|
935
|
+
invariant(ctx, getDataRouterConsoleError(hookName));
|
|
936
|
+
return ctx;
|
|
937
|
+
}
|
|
938
|
+
function useDataRouterState(hookName) {
|
|
939
|
+
let state = React2.useContext(DataRouterStateContext);
|
|
940
|
+
invariant(state, getDataRouterConsoleError(hookName));
|
|
941
|
+
return state;
|
|
942
|
+
}
|
|
943
|
+
function useRouteContext(hookName) {
|
|
944
|
+
let route = React2.useContext(RouteContext);
|
|
945
|
+
invariant(route, getDataRouterConsoleError(hookName));
|
|
946
|
+
return route;
|
|
947
|
+
}
|
|
948
|
+
function useCurrentRouteId(hookName) {
|
|
949
|
+
let route = useRouteContext(hookName);
|
|
950
|
+
let thisRoute = route.matches[route.matches.length - 1];
|
|
951
|
+
invariant(
|
|
952
|
+
thisRoute.route.id,
|
|
953
|
+
`${hookName} can only be used on routes that contain a unique "id"`
|
|
954
|
+
);
|
|
955
|
+
return thisRoute.route.id;
|
|
956
|
+
}
|
|
957
|
+
function useRouteId() {
|
|
958
|
+
return useCurrentRouteId(
|
|
959
|
+
"useRouteId"
|
|
960
|
+
/* UseRouteId */
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
function useNavigation() {
|
|
964
|
+
let state = useDataRouterState(
|
|
965
|
+
"useNavigation"
|
|
966
|
+
/* UseNavigation */
|
|
967
|
+
);
|
|
968
|
+
return state.navigation;
|
|
969
|
+
}
|
|
970
|
+
function useMatches() {
|
|
971
|
+
let { matches, loaderData } = useDataRouterState(
|
|
972
|
+
"useMatches"
|
|
973
|
+
/* UseMatches */
|
|
974
|
+
);
|
|
975
|
+
return React2.useMemo(
|
|
976
|
+
() => matches.map((m) => convertRouteMatchToUiMatch(m, loaderData)),
|
|
977
|
+
[matches, loaderData]
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
function useRouteError() {
|
|
981
|
+
let error = React2.useContext(RouteErrorContext);
|
|
982
|
+
let state = useDataRouterState(
|
|
983
|
+
"useRouteError"
|
|
984
|
+
/* UseRouteError */
|
|
985
|
+
);
|
|
986
|
+
let routeId = useCurrentRouteId(
|
|
987
|
+
"useRouteError"
|
|
988
|
+
/* UseRouteError */
|
|
989
|
+
);
|
|
990
|
+
if (error !== void 0) {
|
|
991
|
+
return error;
|
|
992
|
+
}
|
|
993
|
+
return state.errors?.[routeId];
|
|
994
|
+
}
|
|
995
|
+
function useNavigateStable() {
|
|
996
|
+
let { router } = useDataRouterContext(
|
|
997
|
+
"useNavigate"
|
|
998
|
+
/* UseNavigateStable */
|
|
999
|
+
);
|
|
1000
|
+
let id = useCurrentRouteId(
|
|
1001
|
+
"useNavigate"
|
|
1002
|
+
/* UseNavigateStable */
|
|
1003
|
+
);
|
|
1004
|
+
let activeRef = React2.useRef(false);
|
|
1005
|
+
useIsomorphicLayoutEffect(() => {
|
|
1006
|
+
activeRef.current = true;
|
|
1007
|
+
});
|
|
1008
|
+
let navigate = React2.useCallback(
|
|
1009
|
+
async (to, options = {}) => {
|
|
1010
|
+
warning(activeRef.current, navigateEffectWarning);
|
|
1011
|
+
if (!activeRef.current) return;
|
|
1012
|
+
if (typeof to === "number") {
|
|
1013
|
+
router.navigate(to);
|
|
1014
|
+
} else {
|
|
1015
|
+
await router.navigate(to, { fromRouteId: id, ...options });
|
|
1016
|
+
}
|
|
1017
|
+
},
|
|
1018
|
+
[router, id]
|
|
1019
|
+
);
|
|
1020
|
+
return navigate;
|
|
1021
|
+
}
|
|
1022
|
+
var alreadyWarned = {};
|
|
1023
|
+
function warningOnce(key, cond, message) {
|
|
1024
|
+
if (!cond && !alreadyWarned[key]) {
|
|
1025
|
+
alreadyWarned[key] = true;
|
|
1026
|
+
warning(false, message);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
var MemoizedDataRoutes = React3.memo(DataRoutes);
|
|
1030
|
+
function DataRoutes({
|
|
1031
|
+
routes,
|
|
1032
|
+
future,
|
|
1033
|
+
state,
|
|
1034
|
+
unstable_onError
|
|
1035
|
+
}) {
|
|
1036
|
+
return useRoutesImpl(routes, void 0, state, unstable_onError, future);
|
|
1037
|
+
}
|
|
1038
|
+
function Router({
|
|
1039
|
+
basename: basenameProp = "/",
|
|
1040
|
+
children = null,
|
|
1041
|
+
location: locationProp,
|
|
1042
|
+
navigationType = "POP",
|
|
1043
|
+
navigator,
|
|
1044
|
+
static: staticProp = false
|
|
1045
|
+
}) {
|
|
1046
|
+
invariant(
|
|
1047
|
+
!useInRouterContext(),
|
|
1048
|
+
`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`
|
|
1049
|
+
);
|
|
1050
|
+
let basename = basenameProp.replace(/^\/*/, "/");
|
|
1051
|
+
let navigationContext = React3.useMemo(
|
|
1052
|
+
() => ({
|
|
1053
|
+
basename,
|
|
1054
|
+
navigator,
|
|
1055
|
+
static: staticProp,
|
|
1056
|
+
future: {}
|
|
1057
|
+
}),
|
|
1058
|
+
[basename, navigator, staticProp]
|
|
1059
|
+
);
|
|
1060
|
+
if (typeof locationProp === "string") {
|
|
1061
|
+
locationProp = parsePath(locationProp);
|
|
1062
|
+
}
|
|
1063
|
+
let {
|
|
1064
|
+
pathname = "/",
|
|
1065
|
+
search = "",
|
|
1066
|
+
hash = "",
|
|
1067
|
+
state = null,
|
|
1068
|
+
key = "default"
|
|
1069
|
+
} = locationProp;
|
|
1070
|
+
let locationContext = React3.useMemo(() => {
|
|
1071
|
+
let trailingPathname = stripBasename(pathname, basename);
|
|
1072
|
+
if (trailingPathname == null) {
|
|
1073
|
+
return null;
|
|
1074
|
+
}
|
|
1075
|
+
return {
|
|
1076
|
+
location: {
|
|
1077
|
+
pathname: trailingPathname,
|
|
1078
|
+
search,
|
|
1079
|
+
hash,
|
|
1080
|
+
state,
|
|
1081
|
+
key
|
|
1082
|
+
},
|
|
1083
|
+
navigationType
|
|
1084
|
+
};
|
|
1085
|
+
}, [basename, pathname, search, hash, state, key, navigationType]);
|
|
1086
|
+
warning(
|
|
1087
|
+
locationContext != null,
|
|
1088
|
+
`<Router basename="${basename}"> is not able to match the URL "${pathname}${search}${hash}" because it does not start with the basename, so the <Router> won't render anything.`
|
|
1089
|
+
);
|
|
1090
|
+
if (locationContext == null) {
|
|
1091
|
+
return null;
|
|
1092
|
+
}
|
|
1093
|
+
return /* @__PURE__ */ React3.createElement(NavigationContext.Provider, { value: navigationContext }, /* @__PURE__ */ React3.createElement(LocationContext.Provider, { children, value: locationContext }));
|
|
1094
|
+
}
|
|
1095
|
+
var defaultMethod = "get";
|
|
1096
|
+
var defaultEncType = "application/x-www-form-urlencoded";
|
|
1097
|
+
function isHtmlElement(object) {
|
|
1098
|
+
return object != null && typeof object.tagName === "string";
|
|
1099
|
+
}
|
|
1100
|
+
function isButtonElement(object) {
|
|
1101
|
+
return isHtmlElement(object) && object.tagName.toLowerCase() === "button";
|
|
1102
|
+
}
|
|
1103
|
+
function isFormElement(object) {
|
|
1104
|
+
return isHtmlElement(object) && object.tagName.toLowerCase() === "form";
|
|
1105
|
+
}
|
|
1106
|
+
function isInputElement(object) {
|
|
1107
|
+
return isHtmlElement(object) && object.tagName.toLowerCase() === "input";
|
|
1108
|
+
}
|
|
1109
|
+
function isModifiedEvent(event) {
|
|
1110
|
+
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
|
1111
|
+
}
|
|
1112
|
+
function shouldProcessLinkClick(event, target) {
|
|
1113
|
+
return event.button === 0 && // Ignore everything but left clicks
|
|
1114
|
+
(!target || target === "_self") && // Let browser handle "target=_blank" etc.
|
|
1115
|
+
!isModifiedEvent(event);
|
|
1116
|
+
}
|
|
1117
|
+
var _formDataSupportsSubmitter = null;
|
|
1118
|
+
function isFormDataSubmitterSupported() {
|
|
1119
|
+
if (_formDataSupportsSubmitter === null) {
|
|
1120
|
+
try {
|
|
1121
|
+
new FormData(
|
|
1122
|
+
document.createElement("form"),
|
|
1123
|
+
// @ts-expect-error if FormData supports the submitter parameter, this will throw
|
|
1124
|
+
0
|
|
1125
|
+
);
|
|
1126
|
+
_formDataSupportsSubmitter = false;
|
|
1127
|
+
} catch (e) {
|
|
1128
|
+
_formDataSupportsSubmitter = true;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
return _formDataSupportsSubmitter;
|
|
1132
|
+
}
|
|
1133
|
+
var supportedFormEncTypes = /* @__PURE__ */ new Set([
|
|
1134
|
+
"application/x-www-form-urlencoded",
|
|
1135
|
+
"multipart/form-data",
|
|
1136
|
+
"text/plain"
|
|
1137
|
+
]);
|
|
1138
|
+
function getFormEncType(encType) {
|
|
1139
|
+
if (encType != null && !supportedFormEncTypes.has(encType)) {
|
|
1140
|
+
warning(
|
|
1141
|
+
false,
|
|
1142
|
+
`"${encType}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${defaultEncType}"`
|
|
1143
|
+
);
|
|
1144
|
+
return null;
|
|
1145
|
+
}
|
|
1146
|
+
return encType;
|
|
1147
|
+
}
|
|
1148
|
+
function getFormSubmissionInfo(target, basename) {
|
|
1149
|
+
let method;
|
|
1150
|
+
let action;
|
|
1151
|
+
let encType;
|
|
1152
|
+
let formData;
|
|
1153
|
+
let body;
|
|
1154
|
+
if (isFormElement(target)) {
|
|
1155
|
+
let attr = target.getAttribute("action");
|
|
1156
|
+
action = attr ? stripBasename(attr, basename) : null;
|
|
1157
|
+
method = target.getAttribute("method") || defaultMethod;
|
|
1158
|
+
encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType;
|
|
1159
|
+
formData = new FormData(target);
|
|
1160
|
+
} else if (isButtonElement(target) || isInputElement(target) && (target.type === "submit" || target.type === "image")) {
|
|
1161
|
+
let form = target.form;
|
|
1162
|
+
if (form == null) {
|
|
1163
|
+
throw new Error(
|
|
1164
|
+
`Cannot submit a <button> or <input type="submit"> without a <form>`
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
let attr = target.getAttribute("formaction") || form.getAttribute("action");
|
|
1168
|
+
action = attr ? stripBasename(attr, basename) : null;
|
|
1169
|
+
method = target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod;
|
|
1170
|
+
encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType;
|
|
1171
|
+
formData = new FormData(form, target);
|
|
1172
|
+
if (!isFormDataSubmitterSupported()) {
|
|
1173
|
+
let { name, type, value } = target;
|
|
1174
|
+
if (type === "image") {
|
|
1175
|
+
let prefix = name ? `${name}.` : "";
|
|
1176
|
+
formData.append(`${prefix}x`, "0");
|
|
1177
|
+
formData.append(`${prefix}y`, "0");
|
|
1178
|
+
} else if (name) {
|
|
1179
|
+
formData.append(name, value);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
} else if (isHtmlElement(target)) {
|
|
1183
|
+
throw new Error(
|
|
1184
|
+
`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`
|
|
1185
|
+
);
|
|
1186
|
+
} else {
|
|
1187
|
+
method = defaultMethod;
|
|
1188
|
+
action = null;
|
|
1189
|
+
encType = defaultEncType;
|
|
1190
|
+
body = target;
|
|
1191
|
+
}
|
|
1192
|
+
if (formData && encType === "text/plain") {
|
|
1193
|
+
body = formData;
|
|
1194
|
+
formData = void 0;
|
|
1195
|
+
}
|
|
1196
|
+
return { action, method: method.toLowerCase(), encType, formData, body };
|
|
1197
|
+
}
|
|
1198
|
+
var objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
|
1199
|
+
function invariant2(value, message) {
|
|
1200
|
+
if (value === false || value === null || typeof value === "undefined") {
|
|
1201
|
+
throw new Error(message);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
var SingleFetchRedirectSymbol = Symbol("SingleFetchRedirect");
|
|
1205
|
+
function singleFetchUrl(reqUrl, basename, extension) {
|
|
1206
|
+
let url = typeof reqUrl === "string" ? new URL(
|
|
1207
|
+
reqUrl,
|
|
1208
|
+
// This can be called during the SSR flow via PrefetchPageLinksImpl so
|
|
1209
|
+
// don't assume window is available
|
|
1210
|
+
typeof window === "undefined" ? "server://singlefetch/" : window.location.origin
|
|
1211
|
+
) : reqUrl;
|
|
1212
|
+
if (url.pathname === "/") {
|
|
1213
|
+
url.pathname = `_root.${extension}`;
|
|
1214
|
+
} else if (basename && stripBasename(url.pathname, basename) === "/") {
|
|
1215
|
+
url.pathname = `${basename.replace(/\/$/, "")}/_root.${extension}`;
|
|
1216
|
+
} else {
|
|
1217
|
+
url.pathname = `${url.pathname.replace(/\/$/, "")}.${extension}`;
|
|
1218
|
+
}
|
|
1219
|
+
return url;
|
|
1220
|
+
}
|
|
1221
|
+
async function loadRouteModule(route, routeModulesCache) {
|
|
1222
|
+
if (route.id in routeModulesCache) {
|
|
1223
|
+
return routeModulesCache[route.id];
|
|
1224
|
+
}
|
|
1225
|
+
try {
|
|
1226
|
+
let routeModule = await import(
|
|
1227
|
+
/* @vite-ignore */
|
|
1228
|
+
/* webpackIgnore: true */
|
|
1229
|
+
route.module
|
|
1230
|
+
);
|
|
1231
|
+
routeModulesCache[route.id] = routeModule;
|
|
1232
|
+
return routeModule;
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
console.error(
|
|
1235
|
+
`Error loading route module \`${route.module}\`, reloading page...`
|
|
1236
|
+
);
|
|
1237
|
+
console.error(error);
|
|
1238
|
+
if (window.__reactRouterContext && window.__reactRouterContext.isSpaMode && // @ts-expect-error
|
|
1239
|
+
import_meta.hot) {
|
|
1240
|
+
throw error;
|
|
1241
|
+
}
|
|
1242
|
+
window.location.reload();
|
|
1243
|
+
return new Promise(() => {
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
function isPageLinkDescriptor(object) {
|
|
1248
|
+
return object != null && typeof object.page === "string";
|
|
1249
|
+
}
|
|
1250
|
+
function isHtmlLinkDescriptor(object) {
|
|
1251
|
+
if (object == null) {
|
|
1252
|
+
return false;
|
|
1253
|
+
}
|
|
1254
|
+
if (object.href == null) {
|
|
1255
|
+
return object.rel === "preload" && typeof object.imageSrcSet === "string" && typeof object.imageSizes === "string";
|
|
1256
|
+
}
|
|
1257
|
+
return typeof object.rel === "string" && typeof object.href === "string";
|
|
1258
|
+
}
|
|
1259
|
+
async function getKeyedPrefetchLinks(matches, manifest, routeModules) {
|
|
1260
|
+
let links = await Promise.all(
|
|
1261
|
+
matches.map(async (match) => {
|
|
1262
|
+
let route = manifest.routes[match.route.id];
|
|
1263
|
+
if (route) {
|
|
1264
|
+
let mod = await loadRouteModule(route, routeModules);
|
|
1265
|
+
return mod.links ? mod.links() : [];
|
|
1266
|
+
}
|
|
1267
|
+
return [];
|
|
1268
|
+
})
|
|
1269
|
+
);
|
|
1270
|
+
return dedupeLinkDescriptors(
|
|
1271
|
+
links.flat(1).filter(isHtmlLinkDescriptor).filter((link) => link.rel === "stylesheet" || link.rel === "preload").map(
|
|
1272
|
+
(link) => link.rel === "stylesheet" ? { ...link, rel: "prefetch", as: "style" } : { ...link, rel: "prefetch" }
|
|
1273
|
+
)
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1276
|
+
function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, location, mode) {
|
|
1277
|
+
let isNew = (match, index) => {
|
|
1278
|
+
if (!currentMatches[index]) return true;
|
|
1279
|
+
return match.route.id !== currentMatches[index].route.id;
|
|
1280
|
+
};
|
|
1281
|
+
let matchPathChanged = (match, index) => {
|
|
1282
|
+
return (
|
|
1283
|
+
// param change, /users/123 -> /users/456
|
|
1284
|
+
currentMatches[index].pathname !== match.pathname || // splat param changed, which is not present in match.path
|
|
1285
|
+
// e.g. /files/images/avatar.jpg -> files/finances.xls
|
|
1286
|
+
currentMatches[index].route.path?.endsWith("*") && currentMatches[index].params["*"] !== match.params["*"]
|
|
1287
|
+
);
|
|
1288
|
+
};
|
|
1289
|
+
if (mode === "assets") {
|
|
1290
|
+
return nextMatches.filter(
|
|
1291
|
+
(match, index) => isNew(match, index) || matchPathChanged(match, index)
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
if (mode === "data") {
|
|
1295
|
+
return nextMatches.filter((match, index) => {
|
|
1296
|
+
let manifestRoute = manifest.routes[match.route.id];
|
|
1297
|
+
if (!manifestRoute || !manifestRoute.hasLoader) {
|
|
1298
|
+
return false;
|
|
1299
|
+
}
|
|
1300
|
+
if (isNew(match, index) || matchPathChanged(match, index)) {
|
|
1301
|
+
return true;
|
|
1302
|
+
}
|
|
1303
|
+
if (match.route.shouldRevalidate) {
|
|
1304
|
+
let routeChoice = match.route.shouldRevalidate({
|
|
1305
|
+
currentUrl: new URL(
|
|
1306
|
+
location.pathname + location.search + location.hash,
|
|
1307
|
+
window.origin
|
|
1308
|
+
),
|
|
1309
|
+
currentParams: currentMatches[0]?.params || {},
|
|
1310
|
+
nextUrl: new URL(page, window.origin),
|
|
1311
|
+
nextParams: match.params,
|
|
1312
|
+
defaultShouldRevalidate: true
|
|
1313
|
+
});
|
|
1314
|
+
if (typeof routeChoice === "boolean") {
|
|
1315
|
+
return routeChoice;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
return true;
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
return [];
|
|
1322
|
+
}
|
|
1323
|
+
function getModuleLinkHrefs(matches, manifest, { includeHydrateFallback } = {}) {
|
|
1324
|
+
return dedupeHrefs(
|
|
1325
|
+
matches.map((match) => {
|
|
1326
|
+
let route = manifest.routes[match.route.id];
|
|
1327
|
+
if (!route) return [];
|
|
1328
|
+
let hrefs = [route.module];
|
|
1329
|
+
if (route.clientActionModule) {
|
|
1330
|
+
hrefs = hrefs.concat(route.clientActionModule);
|
|
1331
|
+
}
|
|
1332
|
+
if (route.clientLoaderModule) {
|
|
1333
|
+
hrefs = hrefs.concat(route.clientLoaderModule);
|
|
1334
|
+
}
|
|
1335
|
+
if (includeHydrateFallback && route.hydrateFallbackModule) {
|
|
1336
|
+
hrefs = hrefs.concat(route.hydrateFallbackModule);
|
|
1337
|
+
}
|
|
1338
|
+
if (route.imports) {
|
|
1339
|
+
hrefs = hrefs.concat(route.imports);
|
|
1340
|
+
}
|
|
1341
|
+
return hrefs;
|
|
1342
|
+
}).flat(1)
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
function dedupeHrefs(hrefs) {
|
|
1346
|
+
return [...new Set(hrefs)];
|
|
1347
|
+
}
|
|
1348
|
+
function sortKeys(obj) {
|
|
1349
|
+
let sorted = {};
|
|
1350
|
+
let keys = Object.keys(obj).sort();
|
|
1351
|
+
for (let key of keys) {
|
|
1352
|
+
sorted[key] = obj[key];
|
|
1353
|
+
}
|
|
1354
|
+
return sorted;
|
|
1355
|
+
}
|
|
1356
|
+
function dedupeLinkDescriptors(descriptors, preloads) {
|
|
1357
|
+
let set = /* @__PURE__ */ new Set();
|
|
1358
|
+
let preloadsSet = new Set(preloads);
|
|
1359
|
+
return descriptors.reduce((deduped, descriptor) => {
|
|
1360
|
+
let alreadyModulePreload = preloads && !isPageLinkDescriptor(descriptor) && descriptor.as === "script" && descriptor.href && preloadsSet.has(descriptor.href);
|
|
1361
|
+
if (alreadyModulePreload) {
|
|
1362
|
+
return deduped;
|
|
1363
|
+
}
|
|
1364
|
+
let key = JSON.stringify(sortKeys(descriptor));
|
|
1365
|
+
if (!set.has(key)) {
|
|
1366
|
+
set.add(key);
|
|
1367
|
+
deduped.push({ key, link: descriptor });
|
|
1368
|
+
}
|
|
1369
|
+
return deduped;
|
|
1370
|
+
}, []);
|
|
1371
|
+
}
|
|
1372
|
+
function useDataRouterContext2() {
|
|
1373
|
+
let context = React8.useContext(DataRouterContext);
|
|
1374
|
+
invariant2(
|
|
1375
|
+
context,
|
|
1376
|
+
"You must render this element inside a <DataRouterContext.Provider> element"
|
|
1377
|
+
);
|
|
1378
|
+
return context;
|
|
1379
|
+
}
|
|
1380
|
+
function useDataRouterStateContext() {
|
|
1381
|
+
let context = React8.useContext(DataRouterStateContext);
|
|
1382
|
+
invariant2(
|
|
1383
|
+
context,
|
|
1384
|
+
"You must render this element inside a <DataRouterStateContext.Provider> element"
|
|
1385
|
+
);
|
|
1386
|
+
return context;
|
|
1387
|
+
}
|
|
1388
|
+
var FrameworkContext = React8.createContext(void 0);
|
|
1389
|
+
FrameworkContext.displayName = "FrameworkContext";
|
|
1390
|
+
function useFrameworkContext() {
|
|
1391
|
+
let context = React8.useContext(FrameworkContext);
|
|
1392
|
+
invariant2(
|
|
1393
|
+
context,
|
|
1394
|
+
"You must render this element inside a <HydratedRouter> element"
|
|
1395
|
+
);
|
|
1396
|
+
return context;
|
|
1397
|
+
}
|
|
1398
|
+
function usePrefetchBehavior(prefetch, theirElementProps) {
|
|
1399
|
+
let frameworkContext = React8.useContext(FrameworkContext);
|
|
1400
|
+
let [maybePrefetch, setMaybePrefetch] = React8.useState(false);
|
|
1401
|
+
let [shouldPrefetch, setShouldPrefetch] = React8.useState(false);
|
|
1402
|
+
let { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
|
|
1403
|
+
let ref = React8.useRef(null);
|
|
1404
|
+
React8.useEffect(() => {
|
|
1405
|
+
if (prefetch === "render") {
|
|
1406
|
+
setShouldPrefetch(true);
|
|
1407
|
+
}
|
|
1408
|
+
if (prefetch === "viewport") {
|
|
1409
|
+
let callback = (entries) => {
|
|
1410
|
+
entries.forEach((entry) => {
|
|
1411
|
+
setShouldPrefetch(entry.isIntersecting);
|
|
1412
|
+
});
|
|
1413
|
+
};
|
|
1414
|
+
let observer = new IntersectionObserver(callback, { threshold: 0.5 });
|
|
1415
|
+
if (ref.current) observer.observe(ref.current);
|
|
1416
|
+
return () => {
|
|
1417
|
+
observer.disconnect();
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
}, [prefetch]);
|
|
1421
|
+
React8.useEffect(() => {
|
|
1422
|
+
if (maybePrefetch) {
|
|
1423
|
+
let id = setTimeout(() => {
|
|
1424
|
+
setShouldPrefetch(true);
|
|
1425
|
+
}, 100);
|
|
1426
|
+
return () => {
|
|
1427
|
+
clearTimeout(id);
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
}, [maybePrefetch]);
|
|
1431
|
+
let setIntent = () => {
|
|
1432
|
+
setMaybePrefetch(true);
|
|
1433
|
+
};
|
|
1434
|
+
let cancelIntent = () => {
|
|
1435
|
+
setMaybePrefetch(false);
|
|
1436
|
+
setShouldPrefetch(false);
|
|
1437
|
+
};
|
|
1438
|
+
if (!frameworkContext) {
|
|
1439
|
+
return [false, ref, {}];
|
|
1440
|
+
}
|
|
1441
|
+
if (prefetch !== "intent") {
|
|
1442
|
+
return [shouldPrefetch, ref, {}];
|
|
1443
|
+
}
|
|
1444
|
+
return [
|
|
1445
|
+
shouldPrefetch,
|
|
1446
|
+
ref,
|
|
1447
|
+
{
|
|
1448
|
+
onFocus: composeEventHandlers(onFocus, setIntent),
|
|
1449
|
+
onBlur: composeEventHandlers(onBlur, cancelIntent),
|
|
1450
|
+
onMouseEnter: composeEventHandlers(onMouseEnter, setIntent),
|
|
1451
|
+
onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
|
|
1452
|
+
onTouchStart: composeEventHandlers(onTouchStart, setIntent)
|
|
1453
|
+
}
|
|
1454
|
+
];
|
|
1455
|
+
}
|
|
1456
|
+
function composeEventHandlers(theirHandler, ourHandler) {
|
|
1457
|
+
return (event) => {
|
|
1458
|
+
theirHandler && theirHandler(event);
|
|
1459
|
+
if (!event.defaultPrevented) {
|
|
1460
|
+
ourHandler(event);
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
function PrefetchPageLinks({ page, ...linkProps }) {
|
|
1465
|
+
let { router } = useDataRouterContext2();
|
|
1466
|
+
let matches = React8.useMemo(
|
|
1467
|
+
() => matchRoutes(router.routes, page, router.basename),
|
|
1468
|
+
[router.routes, page, router.basename]
|
|
1469
|
+
);
|
|
1470
|
+
if (!matches) {
|
|
1471
|
+
return null;
|
|
1472
|
+
}
|
|
1473
|
+
return /* @__PURE__ */ React8.createElement(PrefetchPageLinksImpl, { page, matches, ...linkProps });
|
|
1474
|
+
}
|
|
1475
|
+
function useKeyedPrefetchLinks(matches) {
|
|
1476
|
+
let { manifest, routeModules } = useFrameworkContext();
|
|
1477
|
+
let [keyedPrefetchLinks, setKeyedPrefetchLinks] = React8.useState([]);
|
|
1478
|
+
React8.useEffect(() => {
|
|
1479
|
+
let interrupted = false;
|
|
1480
|
+
void getKeyedPrefetchLinks(matches, manifest, routeModules).then(
|
|
1481
|
+
(links) => {
|
|
1482
|
+
if (!interrupted) {
|
|
1483
|
+
setKeyedPrefetchLinks(links);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
);
|
|
1487
|
+
return () => {
|
|
1488
|
+
interrupted = true;
|
|
1489
|
+
};
|
|
1490
|
+
}, [matches, manifest, routeModules]);
|
|
1491
|
+
return keyedPrefetchLinks;
|
|
1492
|
+
}
|
|
1493
|
+
function PrefetchPageLinksImpl({
|
|
1494
|
+
page,
|
|
1495
|
+
matches: nextMatches,
|
|
1496
|
+
...linkProps
|
|
1497
|
+
}) {
|
|
1498
|
+
let location = useLocation();
|
|
1499
|
+
let { manifest, routeModules } = useFrameworkContext();
|
|
1500
|
+
let { basename } = useDataRouterContext2();
|
|
1501
|
+
let { loaderData, matches } = useDataRouterStateContext();
|
|
1502
|
+
let newMatchesForData = React8.useMemo(
|
|
1503
|
+
() => getNewMatchesForLinks(
|
|
1504
|
+
page,
|
|
1505
|
+
nextMatches,
|
|
1506
|
+
matches,
|
|
1507
|
+
manifest,
|
|
1508
|
+
location,
|
|
1509
|
+
"data"
|
|
1510
|
+
),
|
|
1511
|
+
[page, nextMatches, matches, manifest, location]
|
|
1512
|
+
);
|
|
1513
|
+
let newMatchesForAssets = React8.useMemo(
|
|
1514
|
+
() => getNewMatchesForLinks(
|
|
1515
|
+
page,
|
|
1516
|
+
nextMatches,
|
|
1517
|
+
matches,
|
|
1518
|
+
manifest,
|
|
1519
|
+
location,
|
|
1520
|
+
"assets"
|
|
1521
|
+
),
|
|
1522
|
+
[page, nextMatches, matches, manifest, location]
|
|
1523
|
+
);
|
|
1524
|
+
let dataHrefs = React8.useMemo(() => {
|
|
1525
|
+
if (page === location.pathname + location.search + location.hash) {
|
|
1526
|
+
return [];
|
|
1527
|
+
}
|
|
1528
|
+
let routesParams = /* @__PURE__ */ new Set();
|
|
1529
|
+
let foundOptOutRoute = false;
|
|
1530
|
+
nextMatches.forEach((m) => {
|
|
1531
|
+
let manifestRoute = manifest.routes[m.route.id];
|
|
1532
|
+
if (!manifestRoute || !manifestRoute.hasLoader) {
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
if (!newMatchesForData.some((m2) => m2.route.id === m.route.id) && m.route.id in loaderData && routeModules[m.route.id]?.shouldRevalidate) {
|
|
1536
|
+
foundOptOutRoute = true;
|
|
1537
|
+
} else if (manifestRoute.hasClientLoader) {
|
|
1538
|
+
foundOptOutRoute = true;
|
|
1539
|
+
} else {
|
|
1540
|
+
routesParams.add(m.route.id);
|
|
1541
|
+
}
|
|
1542
|
+
});
|
|
1543
|
+
if (routesParams.size === 0) {
|
|
1544
|
+
return [];
|
|
1545
|
+
}
|
|
1546
|
+
let url = singleFetchUrl(page, basename, "data");
|
|
1547
|
+
if (foundOptOutRoute && routesParams.size > 0) {
|
|
1548
|
+
url.searchParams.set(
|
|
1549
|
+
"_routes",
|
|
1550
|
+
nextMatches.filter((m) => routesParams.has(m.route.id)).map((m) => m.route.id).join(",")
|
|
1551
|
+
);
|
|
1552
|
+
}
|
|
1553
|
+
return [url.pathname + url.search];
|
|
1554
|
+
}, [
|
|
1555
|
+
basename,
|
|
1556
|
+
loaderData,
|
|
1557
|
+
location,
|
|
1558
|
+
manifest,
|
|
1559
|
+
newMatchesForData,
|
|
1560
|
+
nextMatches,
|
|
1561
|
+
page,
|
|
1562
|
+
routeModules
|
|
1563
|
+
]);
|
|
1564
|
+
let moduleHrefs = React8.useMemo(
|
|
1565
|
+
() => getModuleLinkHrefs(newMatchesForAssets, manifest),
|
|
1566
|
+
[newMatchesForAssets, manifest]
|
|
1567
|
+
);
|
|
1568
|
+
let keyedPrefetchLinks = useKeyedPrefetchLinks(newMatchesForAssets);
|
|
1569
|
+
return /* @__PURE__ */ React8.createElement(React8.Fragment, null, dataHrefs.map((href) => /* @__PURE__ */ React8.createElement("link", { key: href, rel: "prefetch", as: "fetch", href, ...linkProps })), moduleHrefs.map((href) => /* @__PURE__ */ React8.createElement("link", { key: href, rel: "modulepreload", href, ...linkProps })), keyedPrefetchLinks.map(({ key, link }) => (
|
|
1570
|
+
// these don't spread `linkProps` because they are full link descriptors
|
|
1571
|
+
// already with their own props
|
|
1572
|
+
/* @__PURE__ */ React8.createElement("link", { key, nonce: linkProps.nonce, ...link })
|
|
1573
|
+
)));
|
|
1574
|
+
}
|
|
1575
|
+
function mergeRefs(...refs) {
|
|
1576
|
+
return (value) => {
|
|
1577
|
+
refs.forEach((ref) => {
|
|
1578
|
+
if (typeof ref === "function") {
|
|
1579
|
+
ref(value);
|
|
1580
|
+
} else if (ref != null) {
|
|
1581
|
+
ref.current = value;
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
1587
|
+
try {
|
|
1588
|
+
if (isBrowser) {
|
|
1589
|
+
window.__reactRouterVersion = // @ts-expect-error
|
|
1590
|
+
"7.9.1";
|
|
1591
|
+
}
|
|
1592
|
+
} catch (e) {
|
|
1593
|
+
}
|
|
1594
|
+
function HistoryRouter({
|
|
1595
|
+
basename,
|
|
1596
|
+
children,
|
|
1597
|
+
history
|
|
1598
|
+
}) {
|
|
1599
|
+
let [state, setStateImpl] = React10.useState({
|
|
1600
|
+
action: history.action,
|
|
1601
|
+
location: history.location
|
|
1602
|
+
});
|
|
1603
|
+
let setState = React10.useCallback(
|
|
1604
|
+
(newState) => {
|
|
1605
|
+
React10.startTransition(() => setStateImpl(newState));
|
|
1606
|
+
},
|
|
1607
|
+
[setStateImpl]
|
|
1608
|
+
);
|
|
1609
|
+
React10.useLayoutEffect(() => history.listen(setState), [history, setState]);
|
|
1610
|
+
return /* @__PURE__ */ React10.createElement(
|
|
1611
|
+
Router,
|
|
1612
|
+
{
|
|
1613
|
+
basename,
|
|
1614
|
+
children,
|
|
1615
|
+
location: state.location,
|
|
1616
|
+
navigationType: state.action,
|
|
1617
|
+
navigator: history
|
|
1618
|
+
}
|
|
1619
|
+
);
|
|
1620
|
+
}
|
|
1621
|
+
HistoryRouter.displayName = "unstable_HistoryRouter";
|
|
1622
|
+
var ABSOLUTE_URL_REGEX2 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
|
1623
|
+
var Link = React10.forwardRef(
|
|
1624
|
+
function LinkWithRef({
|
|
1625
|
+
onClick,
|
|
1626
|
+
discover = "render",
|
|
1627
|
+
prefetch = "none",
|
|
1628
|
+
relative,
|
|
1629
|
+
reloadDocument,
|
|
1630
|
+
replace: replace2,
|
|
1631
|
+
state,
|
|
1632
|
+
target,
|
|
1633
|
+
to,
|
|
1634
|
+
preventScrollReset,
|
|
1635
|
+
viewTransition,
|
|
1636
|
+
...rest
|
|
1637
|
+
}, forwardedRef) {
|
|
1638
|
+
let { basename } = React10.useContext(NavigationContext);
|
|
1639
|
+
let isAbsolute = typeof to === "string" && ABSOLUTE_URL_REGEX2.test(to);
|
|
1640
|
+
let absoluteHref;
|
|
1641
|
+
let isExternal = false;
|
|
1642
|
+
if (typeof to === "string" && isAbsolute) {
|
|
1643
|
+
absoluteHref = to;
|
|
1644
|
+
if (isBrowser) {
|
|
1645
|
+
try {
|
|
1646
|
+
let currentUrl = new URL(window.location.href);
|
|
1647
|
+
let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to);
|
|
1648
|
+
let path = stripBasename(targetUrl.pathname, basename);
|
|
1649
|
+
if (targetUrl.origin === currentUrl.origin && path != null) {
|
|
1650
|
+
to = path + targetUrl.search + targetUrl.hash;
|
|
1651
|
+
} else {
|
|
1652
|
+
isExternal = true;
|
|
1653
|
+
}
|
|
1654
|
+
} catch (e) {
|
|
1655
|
+
warning(
|
|
1656
|
+
false,
|
|
1657
|
+
`<Link to="${to}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
let href = useHref(to, { relative });
|
|
1663
|
+
let [shouldPrefetch, prefetchRef, prefetchHandlers] = usePrefetchBehavior(
|
|
1664
|
+
prefetch,
|
|
1665
|
+
rest
|
|
1666
|
+
);
|
|
1667
|
+
let internalOnClick = useLinkClickHandler(to, {
|
|
1668
|
+
replace: replace2,
|
|
1669
|
+
state,
|
|
1670
|
+
target,
|
|
1671
|
+
preventScrollReset,
|
|
1672
|
+
relative,
|
|
1673
|
+
viewTransition
|
|
1674
|
+
});
|
|
1675
|
+
function handleClick(event) {
|
|
1676
|
+
if (onClick) onClick(event);
|
|
1677
|
+
if (!event.defaultPrevented) {
|
|
1678
|
+
internalOnClick(event);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
let link = (
|
|
1682
|
+
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
1683
|
+
/* @__PURE__ */ React10.createElement(
|
|
1684
|
+
"a",
|
|
1685
|
+
{
|
|
1686
|
+
...rest,
|
|
1687
|
+
...prefetchHandlers,
|
|
1688
|
+
href: absoluteHref || href,
|
|
1689
|
+
onClick: isExternal || reloadDocument ? onClick : handleClick,
|
|
1690
|
+
ref: mergeRefs(forwardedRef, prefetchRef),
|
|
1691
|
+
target,
|
|
1692
|
+
"data-discover": !isAbsolute && discover === "render" ? "true" : void 0
|
|
1693
|
+
}
|
|
1694
|
+
)
|
|
1695
|
+
);
|
|
1696
|
+
return shouldPrefetch && !isAbsolute ? /* @__PURE__ */ React10.createElement(React10.Fragment, null, link, /* @__PURE__ */ React10.createElement(PrefetchPageLinks, { page: href })) : link;
|
|
1697
|
+
}
|
|
1698
|
+
);
|
|
1699
|
+
Link.displayName = "Link";
|
|
1700
|
+
var NavLink = React10.forwardRef(
|
|
1701
|
+
function NavLinkWithRef({
|
|
1702
|
+
"aria-current": ariaCurrentProp = "page",
|
|
1703
|
+
caseSensitive = false,
|
|
1704
|
+
className: classNameProp = "",
|
|
1705
|
+
end = false,
|
|
1706
|
+
style: styleProp,
|
|
1707
|
+
to,
|
|
1708
|
+
viewTransition,
|
|
1709
|
+
children,
|
|
1710
|
+
...rest
|
|
1711
|
+
}, ref) {
|
|
1712
|
+
let path = useResolvedPath(to, { relative: rest.relative });
|
|
1713
|
+
let location = useLocation();
|
|
1714
|
+
let routerState = React10.useContext(DataRouterStateContext);
|
|
1715
|
+
let { navigator, basename } = React10.useContext(NavigationContext);
|
|
1716
|
+
let isTransitioning = routerState != null && // Conditional usage is OK here because the usage of a data router is static
|
|
1717
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
1718
|
+
useViewTransitionState(path) && viewTransition === true;
|
|
1719
|
+
let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
|
|
1720
|
+
let locationPathname = location.pathname;
|
|
1721
|
+
let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null;
|
|
1722
|
+
if (!caseSensitive) {
|
|
1723
|
+
locationPathname = locationPathname.toLowerCase();
|
|
1724
|
+
nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null;
|
|
1725
|
+
toPathname = toPathname.toLowerCase();
|
|
1726
|
+
}
|
|
1727
|
+
if (nextLocationPathname && basename) {
|
|
1728
|
+
nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname;
|
|
1729
|
+
}
|
|
1730
|
+
const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
|
|
1731
|
+
let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/";
|
|
1732
|
+
let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(toPathname.length) === "/");
|
|
1733
|
+
let renderProps = {
|
|
1734
|
+
isActive,
|
|
1735
|
+
isPending,
|
|
1736
|
+
isTransitioning
|
|
1737
|
+
};
|
|
1738
|
+
let ariaCurrent = isActive ? ariaCurrentProp : void 0;
|
|
1739
|
+
let className;
|
|
1740
|
+
if (typeof classNameProp === "function") {
|
|
1741
|
+
className = classNameProp(renderProps);
|
|
1742
|
+
} else {
|
|
1743
|
+
className = [
|
|
1744
|
+
classNameProp,
|
|
1745
|
+
isActive ? "active" : null,
|
|
1746
|
+
isPending ? "pending" : null,
|
|
1747
|
+
isTransitioning ? "transitioning" : null
|
|
1748
|
+
].filter(Boolean).join(" ");
|
|
1749
|
+
}
|
|
1750
|
+
let style = typeof styleProp === "function" ? styleProp(renderProps) : styleProp;
|
|
1751
|
+
return /* @__PURE__ */ React10.createElement(
|
|
1752
|
+
Link,
|
|
1753
|
+
{
|
|
1754
|
+
...rest,
|
|
1755
|
+
"aria-current": ariaCurrent,
|
|
1756
|
+
className,
|
|
1757
|
+
ref,
|
|
1758
|
+
style,
|
|
1759
|
+
to,
|
|
1760
|
+
viewTransition
|
|
1761
|
+
},
|
|
1762
|
+
typeof children === "function" ? children(renderProps) : children
|
|
1763
|
+
);
|
|
1764
|
+
}
|
|
1765
|
+
);
|
|
1766
|
+
NavLink.displayName = "NavLink";
|
|
1767
|
+
var Form = React10.forwardRef(
|
|
1768
|
+
({
|
|
1769
|
+
discover = "render",
|
|
1770
|
+
fetcherKey,
|
|
1771
|
+
navigate,
|
|
1772
|
+
reloadDocument,
|
|
1773
|
+
replace: replace2,
|
|
1774
|
+
state,
|
|
1775
|
+
method = defaultMethod,
|
|
1776
|
+
action,
|
|
1777
|
+
onSubmit,
|
|
1778
|
+
relative,
|
|
1779
|
+
preventScrollReset,
|
|
1780
|
+
viewTransition,
|
|
1781
|
+
...props
|
|
1782
|
+
}, forwardedRef) => {
|
|
1783
|
+
let submit = useSubmit();
|
|
1784
|
+
let formAction = useFormAction(action, { relative });
|
|
1785
|
+
let formMethod = method.toLowerCase() === "get" ? "get" : "post";
|
|
1786
|
+
let isAbsolute = typeof action === "string" && ABSOLUTE_URL_REGEX2.test(action);
|
|
1787
|
+
let submitHandler = (event) => {
|
|
1788
|
+
onSubmit && onSubmit(event);
|
|
1789
|
+
if (event.defaultPrevented) return;
|
|
1790
|
+
event.preventDefault();
|
|
1791
|
+
let submitter = event.nativeEvent.submitter;
|
|
1792
|
+
let submitMethod = submitter?.getAttribute("formmethod") || method;
|
|
1793
|
+
submit(submitter || event.currentTarget, {
|
|
1794
|
+
fetcherKey,
|
|
1795
|
+
method: submitMethod,
|
|
1796
|
+
navigate,
|
|
1797
|
+
replace: replace2,
|
|
1798
|
+
state,
|
|
1799
|
+
relative,
|
|
1800
|
+
preventScrollReset,
|
|
1801
|
+
viewTransition
|
|
1802
|
+
});
|
|
1803
|
+
};
|
|
1804
|
+
return /* @__PURE__ */ React10.createElement(
|
|
1805
|
+
"form",
|
|
1806
|
+
{
|
|
1807
|
+
ref: forwardedRef,
|
|
1808
|
+
method: formMethod,
|
|
1809
|
+
action: formAction,
|
|
1810
|
+
onSubmit: reloadDocument ? onSubmit : submitHandler,
|
|
1811
|
+
...props,
|
|
1812
|
+
"data-discover": !isAbsolute && discover === "render" ? "true" : void 0
|
|
1813
|
+
}
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
);
|
|
1817
|
+
Form.displayName = "Form";
|
|
1818
|
+
function ScrollRestoration({
|
|
1819
|
+
getKey,
|
|
1820
|
+
storageKey,
|
|
1821
|
+
...props
|
|
1822
|
+
}) {
|
|
1823
|
+
let remixContext = React10.useContext(FrameworkContext);
|
|
1824
|
+
let { basename } = React10.useContext(NavigationContext);
|
|
1825
|
+
let location = useLocation();
|
|
1826
|
+
let matches = useMatches();
|
|
1827
|
+
useScrollRestoration({ getKey, storageKey });
|
|
1828
|
+
let ssrKey = React10.useMemo(
|
|
1829
|
+
() => {
|
|
1830
|
+
if (!remixContext || !getKey) return null;
|
|
1831
|
+
let userKey = getScrollRestorationKey(
|
|
1832
|
+
location,
|
|
1833
|
+
matches,
|
|
1834
|
+
basename,
|
|
1835
|
+
getKey
|
|
1836
|
+
);
|
|
1837
|
+
return userKey !== location.key ? userKey : null;
|
|
1838
|
+
},
|
|
1839
|
+
// Nah, we only need this the first time for the SSR render
|
|
1840
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1841
|
+
[]
|
|
1842
|
+
);
|
|
1843
|
+
if (!remixContext || remixContext.isSpaMode) {
|
|
1844
|
+
return null;
|
|
1845
|
+
}
|
|
1846
|
+
let restoreScroll = ((storageKey2, restoreKey) => {
|
|
1847
|
+
if (!window.history.state || !window.history.state.key) {
|
|
1848
|
+
let key = Math.random().toString(32).slice(2);
|
|
1849
|
+
window.history.replaceState({ key }, "");
|
|
1850
|
+
}
|
|
1851
|
+
try {
|
|
1852
|
+
let positions = JSON.parse(sessionStorage.getItem(storageKey2) || "{}");
|
|
1853
|
+
let storedY = positions[restoreKey || window.history.state.key];
|
|
1854
|
+
if (typeof storedY === "number") {
|
|
1855
|
+
window.scrollTo(0, storedY);
|
|
1856
|
+
}
|
|
1857
|
+
} catch (error) {
|
|
1858
|
+
console.error(error);
|
|
1859
|
+
sessionStorage.removeItem(storageKey2);
|
|
1860
|
+
}
|
|
1861
|
+
}).toString();
|
|
1862
|
+
return /* @__PURE__ */ React10.createElement(
|
|
1863
|
+
"script",
|
|
1864
|
+
{
|
|
1865
|
+
...props,
|
|
1866
|
+
suppressHydrationWarning: true,
|
|
1867
|
+
dangerouslySetInnerHTML: {
|
|
1868
|
+
__html: `(${restoreScroll})(${JSON.stringify(
|
|
1869
|
+
storageKey || SCROLL_RESTORATION_STORAGE_KEY
|
|
1870
|
+
)}, ${JSON.stringify(ssrKey)})`
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
);
|
|
1874
|
+
}
|
|
1875
|
+
ScrollRestoration.displayName = "ScrollRestoration";
|
|
1876
|
+
function getDataRouterConsoleError2(hookName) {
|
|
1877
|
+
return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
|
|
1878
|
+
}
|
|
1879
|
+
function useDataRouterContext3(hookName) {
|
|
1880
|
+
let ctx = React10.useContext(DataRouterContext);
|
|
1881
|
+
invariant(ctx, getDataRouterConsoleError2(hookName));
|
|
1882
|
+
return ctx;
|
|
1883
|
+
}
|
|
1884
|
+
function useDataRouterState2(hookName) {
|
|
1885
|
+
let state = React10.useContext(DataRouterStateContext);
|
|
1886
|
+
invariant(state, getDataRouterConsoleError2(hookName));
|
|
1887
|
+
return state;
|
|
1888
|
+
}
|
|
1889
|
+
function useLinkClickHandler(to, {
|
|
1890
|
+
target,
|
|
1891
|
+
replace: replaceProp,
|
|
1892
|
+
state,
|
|
1893
|
+
preventScrollReset,
|
|
1894
|
+
relative,
|
|
1895
|
+
viewTransition
|
|
1896
|
+
} = {}) {
|
|
1897
|
+
let navigate = useNavigate();
|
|
1898
|
+
let location = useLocation();
|
|
1899
|
+
let path = useResolvedPath(to, { relative });
|
|
1900
|
+
return React10.useCallback(
|
|
1901
|
+
(event) => {
|
|
1902
|
+
if (shouldProcessLinkClick(event, target)) {
|
|
1903
|
+
event.preventDefault();
|
|
1904
|
+
let replace2 = replaceProp !== void 0 ? replaceProp : createPath(location) === createPath(path);
|
|
1905
|
+
navigate(to, {
|
|
1906
|
+
replace: replace2,
|
|
1907
|
+
state,
|
|
1908
|
+
preventScrollReset,
|
|
1909
|
+
relative,
|
|
1910
|
+
viewTransition
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
},
|
|
1914
|
+
[
|
|
1915
|
+
location,
|
|
1916
|
+
navigate,
|
|
1917
|
+
path,
|
|
1918
|
+
replaceProp,
|
|
1919
|
+
state,
|
|
1920
|
+
target,
|
|
1921
|
+
to,
|
|
1922
|
+
preventScrollReset,
|
|
1923
|
+
relative,
|
|
1924
|
+
viewTransition
|
|
1925
|
+
]
|
|
1926
|
+
);
|
|
1927
|
+
}
|
|
1928
|
+
var fetcherId = 0;
|
|
1929
|
+
var getUniqueFetcherId = () => `__${String(++fetcherId)}__`;
|
|
1930
|
+
function useSubmit() {
|
|
1931
|
+
let { router } = useDataRouterContext3(
|
|
1932
|
+
"useSubmit"
|
|
1933
|
+
/* UseSubmit */
|
|
1934
|
+
);
|
|
1935
|
+
let { basename } = React10.useContext(NavigationContext);
|
|
1936
|
+
let currentRouteId = useRouteId();
|
|
1937
|
+
return React10.useCallback(
|
|
1938
|
+
async (target, options = {}) => {
|
|
1939
|
+
let { action, method, encType, formData, body } = getFormSubmissionInfo(
|
|
1940
|
+
target,
|
|
1941
|
+
basename
|
|
1942
|
+
);
|
|
1943
|
+
if (options.navigate === false) {
|
|
1944
|
+
let key = options.fetcherKey || getUniqueFetcherId();
|
|
1945
|
+
await router.fetch(key, currentRouteId, options.action || action, {
|
|
1946
|
+
preventScrollReset: options.preventScrollReset,
|
|
1947
|
+
formData,
|
|
1948
|
+
body,
|
|
1949
|
+
formMethod: options.method || method,
|
|
1950
|
+
formEncType: options.encType || encType,
|
|
1951
|
+
flushSync: options.flushSync
|
|
1952
|
+
});
|
|
1953
|
+
} else {
|
|
1954
|
+
await router.navigate(options.action || action, {
|
|
1955
|
+
preventScrollReset: options.preventScrollReset,
|
|
1956
|
+
formData,
|
|
1957
|
+
body,
|
|
1958
|
+
formMethod: options.method || method,
|
|
1959
|
+
formEncType: options.encType || encType,
|
|
1960
|
+
replace: options.replace,
|
|
1961
|
+
state: options.state,
|
|
1962
|
+
fromRouteId: currentRouteId,
|
|
1963
|
+
flushSync: options.flushSync,
|
|
1964
|
+
viewTransition: options.viewTransition
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
},
|
|
1968
|
+
[router, basename, currentRouteId]
|
|
1969
|
+
);
|
|
1970
|
+
}
|
|
1971
|
+
function useFormAction(action, { relative } = {}) {
|
|
1972
|
+
let { basename } = React10.useContext(NavigationContext);
|
|
1973
|
+
let routeContext = React10.useContext(RouteContext);
|
|
1974
|
+
invariant(routeContext, "useFormAction must be used inside a RouteContext");
|
|
1975
|
+
let [match] = routeContext.matches.slice(-1);
|
|
1976
|
+
let path = { ...useResolvedPath(action ? action : ".", { relative }) };
|
|
1977
|
+
let location = useLocation();
|
|
1978
|
+
if (action == null) {
|
|
1979
|
+
path.search = location.search;
|
|
1980
|
+
let params = new URLSearchParams(path.search);
|
|
1981
|
+
let indexValues = params.getAll("index");
|
|
1982
|
+
let hasNakedIndexParam = indexValues.some((v) => v === "");
|
|
1983
|
+
if (hasNakedIndexParam) {
|
|
1984
|
+
params.delete("index");
|
|
1985
|
+
indexValues.filter((v) => v).forEach((v) => params.append("index", v));
|
|
1986
|
+
let qs = params.toString();
|
|
1987
|
+
path.search = qs ? `?${qs}` : "";
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
if ((!action || action === ".") && match.route.index) {
|
|
1991
|
+
path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
|
|
1992
|
+
}
|
|
1993
|
+
if (basename !== "/") {
|
|
1994
|
+
path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
|
1995
|
+
}
|
|
1996
|
+
return createPath(path);
|
|
1997
|
+
}
|
|
1998
|
+
var SCROLL_RESTORATION_STORAGE_KEY = "react-router-scroll-positions";
|
|
1999
|
+
var savedScrollPositions = {};
|
|
2000
|
+
function getScrollRestorationKey(location, matches, basename, getKey) {
|
|
2001
|
+
let key = null;
|
|
2002
|
+
if (getKey) {
|
|
2003
|
+
if (basename !== "/") {
|
|
2004
|
+
key = getKey(
|
|
2005
|
+
{
|
|
2006
|
+
...location,
|
|
2007
|
+
pathname: stripBasename(location.pathname, basename) || location.pathname
|
|
2008
|
+
},
|
|
2009
|
+
matches
|
|
2010
|
+
);
|
|
2011
|
+
} else {
|
|
2012
|
+
key = getKey(location, matches);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
if (key == null) {
|
|
2016
|
+
key = location.key;
|
|
2017
|
+
}
|
|
2018
|
+
return key;
|
|
2019
|
+
}
|
|
2020
|
+
function useScrollRestoration({
|
|
2021
|
+
getKey,
|
|
2022
|
+
storageKey
|
|
2023
|
+
} = {}) {
|
|
2024
|
+
let { router } = useDataRouterContext3(
|
|
2025
|
+
"useScrollRestoration"
|
|
2026
|
+
/* UseScrollRestoration */
|
|
2027
|
+
);
|
|
2028
|
+
let { restoreScrollPosition, preventScrollReset } = useDataRouterState2(
|
|
2029
|
+
"useScrollRestoration"
|
|
2030
|
+
/* UseScrollRestoration */
|
|
2031
|
+
);
|
|
2032
|
+
let { basename } = React10.useContext(NavigationContext);
|
|
2033
|
+
let location = useLocation();
|
|
2034
|
+
let matches = useMatches();
|
|
2035
|
+
let navigation = useNavigation();
|
|
2036
|
+
React10.useEffect(() => {
|
|
2037
|
+
window.history.scrollRestoration = "manual";
|
|
2038
|
+
return () => {
|
|
2039
|
+
window.history.scrollRestoration = "auto";
|
|
2040
|
+
};
|
|
2041
|
+
}, []);
|
|
2042
|
+
usePageHide(
|
|
2043
|
+
React10.useCallback(() => {
|
|
2044
|
+
if (navigation.state === "idle") {
|
|
2045
|
+
let key = getScrollRestorationKey(location, matches, basename, getKey);
|
|
2046
|
+
savedScrollPositions[key] = window.scrollY;
|
|
2047
|
+
}
|
|
2048
|
+
try {
|
|
2049
|
+
sessionStorage.setItem(
|
|
2050
|
+
storageKey || SCROLL_RESTORATION_STORAGE_KEY,
|
|
2051
|
+
JSON.stringify(savedScrollPositions)
|
|
2052
|
+
);
|
|
2053
|
+
} catch (error) {
|
|
2054
|
+
warning(
|
|
2055
|
+
false,
|
|
2056
|
+
`Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (${error}).`
|
|
2057
|
+
);
|
|
2058
|
+
}
|
|
2059
|
+
window.history.scrollRestoration = "auto";
|
|
2060
|
+
}, [navigation.state, getKey, basename, location, matches, storageKey])
|
|
2061
|
+
);
|
|
2062
|
+
if (typeof document !== "undefined") {
|
|
2063
|
+
React10.useLayoutEffect(() => {
|
|
2064
|
+
try {
|
|
2065
|
+
let sessionPositions = sessionStorage.getItem(
|
|
2066
|
+
storageKey || SCROLL_RESTORATION_STORAGE_KEY
|
|
2067
|
+
);
|
|
2068
|
+
if (sessionPositions) {
|
|
2069
|
+
savedScrollPositions = JSON.parse(sessionPositions);
|
|
2070
|
+
}
|
|
2071
|
+
} catch (e) {
|
|
2072
|
+
}
|
|
2073
|
+
}, [storageKey]);
|
|
2074
|
+
React10.useLayoutEffect(() => {
|
|
2075
|
+
let disableScrollRestoration = router?.enableScrollRestoration(
|
|
2076
|
+
savedScrollPositions,
|
|
2077
|
+
() => window.scrollY,
|
|
2078
|
+
getKey ? (location2, matches2) => getScrollRestorationKey(location2, matches2, basename, getKey) : void 0
|
|
2079
|
+
);
|
|
2080
|
+
return () => disableScrollRestoration && disableScrollRestoration();
|
|
2081
|
+
}, [router, basename, getKey]);
|
|
2082
|
+
React10.useLayoutEffect(() => {
|
|
2083
|
+
if (restoreScrollPosition === false) {
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
if (typeof restoreScrollPosition === "number") {
|
|
2087
|
+
window.scrollTo(0, restoreScrollPosition);
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
try {
|
|
2091
|
+
if (location.hash) {
|
|
2092
|
+
let el = document.getElementById(
|
|
2093
|
+
decodeURIComponent(location.hash.slice(1))
|
|
2094
|
+
);
|
|
2095
|
+
if (el) {
|
|
2096
|
+
el.scrollIntoView();
|
|
2097
|
+
return;
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
} catch {
|
|
2101
|
+
warning(
|
|
2102
|
+
false,
|
|
2103
|
+
`"${location.hash.slice(
|
|
2104
|
+
1
|
|
2105
|
+
)}" is not a decodable element ID. The view will not scroll to it.`
|
|
2106
|
+
);
|
|
2107
|
+
}
|
|
2108
|
+
if (preventScrollReset === true) {
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
2111
|
+
window.scrollTo(0, 0);
|
|
2112
|
+
}, [location, restoreScrollPosition, preventScrollReset]);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
function usePageHide(callback, options) {
|
|
2116
|
+
let { capture } = options || {};
|
|
2117
|
+
React10.useEffect(() => {
|
|
2118
|
+
let opts = capture != null ? { capture } : void 0;
|
|
2119
|
+
window.addEventListener("pagehide", callback, opts);
|
|
2120
|
+
return () => {
|
|
2121
|
+
window.removeEventListener("pagehide", callback, opts);
|
|
2122
|
+
};
|
|
2123
|
+
}, [callback, capture]);
|
|
2124
|
+
}
|
|
2125
|
+
function useViewTransitionState(to, { relative } = {}) {
|
|
2126
|
+
let vtContext = React10.useContext(ViewTransitionContext);
|
|
2127
|
+
invariant(
|
|
2128
|
+
vtContext != null,
|
|
2129
|
+
"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?"
|
|
2130
|
+
);
|
|
2131
|
+
let { basename } = useDataRouterContext3(
|
|
2132
|
+
"useViewTransitionState"
|
|
2133
|
+
/* useViewTransitionState */
|
|
2134
|
+
);
|
|
2135
|
+
let path = useResolvedPath(to, { relative });
|
|
2136
|
+
if (!vtContext.isTransitioning) {
|
|
2137
|
+
return false;
|
|
2138
|
+
}
|
|
2139
|
+
let currentPath = stripBasename(vtContext.currentLocation.pathname, basename) || vtContext.currentLocation.pathname;
|
|
2140
|
+
let nextPath = stripBasename(vtContext.nextLocation.pathname, basename) || vtContext.nextLocation.pathname;
|
|
2141
|
+
return matchPath(path.pathname, nextPath) != null || matchPath(path.pathname, currentPath) != null;
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
// src/hooks/use-weaverse-data-context.ts
|
|
2145
|
+
function createFlatDataContext(matches) {
|
|
2146
|
+
const context = {};
|
|
2147
|
+
for (const match of matches) {
|
|
2148
|
+
if (match.data && typeof match.data === "object") {
|
|
2149
|
+
context[match.id] = match.data;
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
return context;
|
|
2153
|
+
}
|
|
2154
|
+
function useWeaverseDataContext() {
|
|
2155
|
+
const matches = useMatches();
|
|
2156
|
+
return createFlatDataContext(matches);
|
|
2157
|
+
}
|
|
2158
|
+
function createWeaverseDataContext(matches) {
|
|
2159
|
+
return createFlatDataContext(matches);
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
// src/utils/data-connector.ts
|
|
2163
|
+
var TEMPLATE_REGEX = /\{\{([^}]+)\}\}/g;
|
|
2164
|
+
var ARRAY_INDEX_REGEX = /^(\w+)\[(\d+)\]$/;
|
|
2165
|
+
function isSafePropertyName(key) {
|
|
2166
|
+
return key !== "__proto__" && key !== "constructor" && key !== "prototype";
|
|
2167
|
+
}
|
|
2168
|
+
var templateCache = /* @__PURE__ */ new Map();
|
|
2169
|
+
var MAX_CACHE_SIZE = 100;
|
|
2170
|
+
var fallbackCache = /* @__PURE__ */ new Map();
|
|
2171
|
+
var FALLBACK_CACHE_MAX_SIZE = 50;
|
|
2172
|
+
function getNestedValue(obj, path, visited = /* @__PURE__ */ new WeakSet()) {
|
|
2173
|
+
return path.split(".").reduce((current, key) => {
|
|
2174
|
+
if (!current || typeof current !== "object") {
|
|
2175
|
+
return;
|
|
2176
|
+
}
|
|
2177
|
+
if (visited.has(current)) {
|
|
2178
|
+
console.warn("Circular reference detected in data connector path:", path);
|
|
2179
|
+
return;
|
|
2180
|
+
}
|
|
2181
|
+
visited.add(current);
|
|
2182
|
+
const arrayMatch = key.match(ARRAY_INDEX_REGEX);
|
|
2183
|
+
if (arrayMatch) {
|
|
2184
|
+
const [, arrayKey, index] = arrayMatch;
|
|
2185
|
+
const arrayObj = current[arrayKey];
|
|
2186
|
+
if (Array.isArray(arrayObj)) {
|
|
2187
|
+
const indexNum = Number.parseInt(index, 10);
|
|
2188
|
+
if (indexNum >= 0 && indexNum < arrayObj.length) {
|
|
2189
|
+
return arrayObj[indexNum];
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
if (!isSafePropertyName(key)) {
|
|
2195
|
+
console.warn(`Unsafe property access attempted: ${key}`);
|
|
2196
|
+
return;
|
|
2197
|
+
}
|
|
2198
|
+
return current !== null && key in current ? current[key] : void 0;
|
|
2199
|
+
}, obj);
|
|
2200
|
+
}
|
|
2201
|
+
function sanitizeValue(value) {
|
|
2202
|
+
if (value === null || value === void 0) {
|
|
2203
|
+
return "";
|
|
2204
|
+
}
|
|
2205
|
+
const stringValue = String(value);
|
|
2206
|
+
return stringValue.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'").replace(/\//g, "/");
|
|
2207
|
+
}
|
|
2208
|
+
function createCacheKey(content, data2) {
|
|
2209
|
+
try {
|
|
2210
|
+
const dataStr = JSON.stringify(data2);
|
|
2211
|
+
return `${content}:${dataStr.slice(0, 100)}`;
|
|
2212
|
+
} catch {
|
|
2213
|
+
const keys = Object.keys(data2).sort().join(",");
|
|
2214
|
+
return `${content}:keys:${keys}`;
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
function resolveDataFromContext(path, dataContext) {
|
|
2218
|
+
const trimmedPath = path.trim();
|
|
2219
|
+
const pathParts = trimmedPath.split(".");
|
|
2220
|
+
const potentialRouteKey = pathParts[0];
|
|
2221
|
+
if (dataContext[potentialRouteKey] && typeof dataContext[potentialRouteKey] === "object" && dataContext[potentialRouteKey] !== null) {
|
|
2222
|
+
const remainingPath = pathParts.slice(1).join(".");
|
|
2223
|
+
if (remainingPath) {
|
|
2224
|
+
return getNestedValue(dataContext[potentialRouteKey], remainingPath);
|
|
2225
|
+
}
|
|
2226
|
+
return dataContext[potentialRouteKey];
|
|
2227
|
+
}
|
|
2228
|
+
const cachedResult = fallbackCache.get(trimmedPath);
|
|
2229
|
+
if (cachedResult && dataContext[cachedResult.routeKey]) {
|
|
2230
|
+
const value = getNestedValue(
|
|
2231
|
+
dataContext[cachedResult.routeKey],
|
|
2232
|
+
trimmedPath
|
|
2233
|
+
);
|
|
2234
|
+
if (value !== void 0) {
|
|
2235
|
+
cachedResult.timestamp = Date.now();
|
|
2236
|
+
return value;
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
const priorityRoutes = ["root", "routes/product", "routes/collection"];
|
|
2240
|
+
const allRoutes = [
|
|
2241
|
+
...priorityRoutes,
|
|
2242
|
+
...Object.keys(dataContext).filter((k) => !priorityRoutes.includes(k))
|
|
2243
|
+
];
|
|
2244
|
+
for (const routeKey of allRoutes) {
|
|
2245
|
+
const routeData = dataContext[routeKey];
|
|
2246
|
+
if (routeData && typeof routeData === "object" && routeData !== null) {
|
|
2247
|
+
const value = getNestedValue(routeData, trimmedPath);
|
|
2248
|
+
if (value !== void 0) {
|
|
2249
|
+
if (fallbackCache.size >= FALLBACK_CACHE_MAX_SIZE) {
|
|
2250
|
+
const entries = Array.from(fallbackCache.entries());
|
|
2251
|
+
entries.sort((a, b) => a[1].timestamp - b[1].timestamp);
|
|
2252
|
+
const toRemove = Math.floor(entries.length * 0.25);
|
|
2253
|
+
for (let i = 0; i < toRemove; i++) {
|
|
2254
|
+
fallbackCache.delete(entries[i][0]);
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
fallbackCache.set(trimmedPath, {
|
|
2258
|
+
routeKey,
|
|
2259
|
+
value,
|
|
2260
|
+
timestamp: Date.now()
|
|
2261
|
+
});
|
|
2262
|
+
return value;
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
return getNestedValue(dataContext, trimmedPath);
|
|
2267
|
+
}
|
|
2268
|
+
function replaceContentDataConnectors(content, dataContext) {
|
|
2269
|
+
if (!dataContext || typeof content !== "string") {
|
|
2270
|
+
return content;
|
|
2271
|
+
}
|
|
2272
|
+
try {
|
|
2273
|
+
const cacheKey = createCacheKey(content, dataContext);
|
|
2274
|
+
if (templateCache.has(cacheKey)) {
|
|
2275
|
+
return templateCache.get(cacheKey);
|
|
2276
|
+
}
|
|
2277
|
+
const newContent = content.replace(TEMPLATE_REGEX, (match, path) => {
|
|
2278
|
+
try {
|
|
2279
|
+
const value = resolveDataFromContext(path, dataContext);
|
|
2280
|
+
if (value === void 0 || value === null) {
|
|
2281
|
+
return match;
|
|
2282
|
+
}
|
|
2283
|
+
return sanitizeValue(value);
|
|
2284
|
+
} catch (pathError) {
|
|
2285
|
+
console.warn(
|
|
2286
|
+
`Error resolving data connector path "${path}":`,
|
|
2287
|
+
pathError
|
|
2288
|
+
);
|
|
2289
|
+
return match;
|
|
2290
|
+
}
|
|
2291
|
+
});
|
|
2292
|
+
if (templateCache.size >= MAX_CACHE_SIZE) {
|
|
2293
|
+
const firstKey = templateCache.keys().next().value;
|
|
2294
|
+
templateCache.delete(firstKey);
|
|
2295
|
+
}
|
|
2296
|
+
templateCache.set(cacheKey, newContent);
|
|
2297
|
+
return newContent;
|
|
2298
|
+
} catch (error) {
|
|
2299
|
+
console.warn("Error processing data connectors:", error, { content });
|
|
2300
|
+
return content;
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
function replaceContentDataConnectorsDeep(data2, dataContext, visited = /* @__PURE__ */ new WeakSet()) {
|
|
2304
|
+
if (!dataContext) {
|
|
2305
|
+
return data2;
|
|
2306
|
+
}
|
|
2307
|
+
if (typeof data2 === "string") {
|
|
2308
|
+
return replaceContentDataConnectors(data2, dataContext);
|
|
2309
|
+
}
|
|
2310
|
+
if (typeof data2 !== "object" || data2 === null) {
|
|
2311
|
+
return data2;
|
|
2312
|
+
}
|
|
2313
|
+
if (visited.has(data2)) {
|
|
2314
|
+
console.warn(
|
|
2315
|
+
"Circular reference detected in deep data connector replacement"
|
|
2316
|
+
);
|
|
2317
|
+
return data2;
|
|
2318
|
+
}
|
|
2319
|
+
visited.add(data2);
|
|
2320
|
+
try {
|
|
2321
|
+
if (Array.isArray(data2)) {
|
|
2322
|
+
return data2.map(
|
|
2323
|
+
(item) => replaceContentDataConnectorsDeep(item, dataContext, visited)
|
|
2324
|
+
);
|
|
2325
|
+
}
|
|
2326
|
+
const result = {};
|
|
2327
|
+
for (const [key, value] of Object.entries(data2)) {
|
|
2328
|
+
;
|
|
2329
|
+
result[key] = replaceContentDataConnectorsDeep(value, dataContext, visited);
|
|
2330
|
+
}
|
|
2331
|
+
return result;
|
|
2332
|
+
} catch (error) {
|
|
2333
|
+
console.warn("Error in deep data connector replacement:", error);
|
|
2334
|
+
return data2;
|
|
2335
|
+
} finally {
|
|
2336
|
+
visited.delete(data2);
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2340
|
+
// src/hooks.ts
|
|
55
2341
|
function useWeaverse() {
|
|
56
2342
|
let weaverse = (0, import_react2.useContext)(WeaverseContext);
|
|
57
2343
|
return weaverse;
|
|
@@ -83,7 +2369,7 @@ var useChildInstances = (id) => {
|
|
|
83
2369
|
|
|
84
2370
|
// src/renderer.tsx
|
|
85
2371
|
var import_clsx2 = __toESM(require("clsx"));
|
|
86
|
-
var
|
|
2372
|
+
var React12 = __toESM(require("react"));
|
|
87
2373
|
var import_react3 = require("react");
|
|
88
2374
|
|
|
89
2375
|
// src/utils/css.ts
|
|
@@ -124,18 +2410,18 @@ function generateItemClassName(instance, stitchesInstance) {
|
|
|
124
2410
|
// src/renderer.tsx
|
|
125
2411
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
126
2412
|
var import_react4 = require("react");
|
|
127
|
-
var reactVersion = Number(
|
|
2413
|
+
var reactVersion = Number(React12.version?.split(".")[0]) || 0;
|
|
128
2414
|
var useSafeExternalStore = (subscribe, getSnapshot, getServerSnapshot = getSnapshot) => {
|
|
129
2415
|
if (typeof window === "undefined") {
|
|
130
2416
|
return getServerSnapshot();
|
|
131
2417
|
}
|
|
132
|
-
if (
|
|
133
|
-
return
|
|
2418
|
+
if (React12.useSyncExternalStore) {
|
|
2419
|
+
return React12.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
134
2420
|
}
|
|
135
2421
|
return getSnapshot();
|
|
136
2422
|
};
|
|
137
2423
|
var WeaverseRoot = (0, import_react3.memo)(({ context }) => {
|
|
138
|
-
let
|
|
2424
|
+
let data2 = useSafeExternalStore(
|
|
139
2425
|
context.subscribe,
|
|
140
2426
|
context.getSnapShot,
|
|
141
2427
|
context.getSnapShot
|
|
@@ -153,7 +2439,7 @@ var WeaverseRoot = (0, import_react3.memo)(({ context }) => {
|
|
|
153
2439
|
className: `weaverse-content-root ${themeClass}`,
|
|
154
2440
|
...eventHandlers,
|
|
155
2441
|
"data-weaverse-project-id": context.projectId,
|
|
156
|
-
"data-weaverse-template-id":
|
|
2442
|
+
"data-weaverse-template-id": data2.id,
|
|
157
2443
|
ref: rootRef,
|
|
158
2444
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WeaverseContextProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
159
2445
|
ItemInstance,
|
|
@@ -171,7 +2457,7 @@ WeaverseRoot.displayName = "WeaverseRoot";
|
|
|
171
2457
|
var ItemComponent = (0, import_react3.memo)(({ instance }) => {
|
|
172
2458
|
let context = useWeaverse();
|
|
173
2459
|
let { stitchesInstance, elementRegistry, platformType } = context;
|
|
174
|
-
let
|
|
2460
|
+
let data2 = useSafeExternalStore(
|
|
175
2461
|
instance.subscribe,
|
|
176
2462
|
instance.getSnapShot,
|
|
177
2463
|
instance.getSnapShot
|
|
@@ -189,8 +2475,13 @@ var ItemComponent = (0, import_react3.memo)(({ instance }) => {
|
|
|
189
2475
|
__hidden,
|
|
190
2476
|
// Need to get rid of this `data` property
|
|
191
2477
|
data: _,
|
|
2478
|
+
content,
|
|
192
2479
|
...rest
|
|
193
|
-
} =
|
|
2480
|
+
} = data2;
|
|
2481
|
+
if (content !== void 0 && content !== null) {
|
|
2482
|
+
content = replaceContentDataConnectorsDeep(content, context.dataContext);
|
|
2483
|
+
rest.content = content;
|
|
2484
|
+
}
|
|
194
2485
|
(0, import_react3.useEffect)(() => {
|
|
195
2486
|
if (!instance.ref.current) {
|
|
196
2487
|
Object.assign(instance.ref, {
|
|
@@ -203,14 +2494,14 @@ var ItemComponent = (0, import_react3.memo)(({ instance }) => {
|
|
|
203
2494
|
}
|
|
204
2495
|
let Element = elementRegistry.get(type);
|
|
205
2496
|
if (Element?.Component) {
|
|
206
|
-
let
|
|
207
|
-
|
|
208
|
-
if (
|
|
2497
|
+
let Component4 = Element.Component;
|
|
2498
|
+
Component4.displayName = type;
|
|
2499
|
+
if (Component4.$$typeof === Symbol.for("react.forward_ref") || reactVersion > 18) {
|
|
209
2500
|
rest.ref = instance.ref;
|
|
210
2501
|
}
|
|
211
2502
|
let renderChildren = (children?.length ? children : childIds?.length ? childIds.map((cid) => ({ id: cid })) : []).map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ItemInstance, { id: item.id, parentId: id }, `${item.id}-${index}`));
|
|
212
2503
|
return /* @__PURE__ */ (0, import_react4.createElement)(
|
|
213
|
-
|
|
2504
|
+
Component4,
|
|
214
2505
|
{
|
|
215
2506
|
...rest,
|
|
216
2507
|
children: renderChildren.length ? renderChildren : void 0,
|
|
@@ -249,11 +2540,30 @@ ItemInstance.displayName = "WeaverseInstanceProvider";
|
|
|
249
2540
|
WeaverseContextProvider,
|
|
250
2541
|
WeaverseItemContext,
|
|
251
2542
|
WeaverseRoot,
|
|
2543
|
+
createWeaverseDataContext,
|
|
2544
|
+
replaceContentDataConnectors,
|
|
2545
|
+
replaceContentDataConnectorsDeep,
|
|
252
2546
|
useChildInstances,
|
|
253
2547
|
useItemInstance,
|
|
254
2548
|
useParentInstance,
|
|
255
2549
|
useSafeExternalStore,
|
|
256
2550
|
useWeaverse,
|
|
2551
|
+
useWeaverseDataContext,
|
|
257
2552
|
...require("@weaverse/core")
|
|
258
2553
|
});
|
|
2554
|
+
/*! Bundled license information:
|
|
2555
|
+
|
|
2556
|
+
react-router/dist/development/chunk-B7RQU5TL.mjs:
|
|
2557
|
+
react-router/dist/development/index.mjs:
|
|
2558
|
+
(**
|
|
2559
|
+
* react-router v7.9.1
|
|
2560
|
+
*
|
|
2561
|
+
* Copyright (c) Remix Software Inc.
|
|
2562
|
+
*
|
|
2563
|
+
* This source code is licensed under the MIT license found in the
|
|
2564
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
2565
|
+
*
|
|
2566
|
+
* @license MIT
|
|
2567
|
+
*)
|
|
2568
|
+
*/
|
|
259
2569
|
//# sourceMappingURL=index.js.map
|