zudoku 0.3.0-dev.55 → 0.3.0-dev.56
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/config/validators/validate.d.ts +12 -12
- package/dist/lib/components/DeveloperHint.d.ts +5 -0
- package/dist/lib/components/DeveloperHint.js +10 -0
- package/dist/lib/components/DeveloperHint.js.map +1 -0
- package/dist/lib/components/NotFoundPage.js +2 -2
- package/dist/lib/components/NotFoundPage.js.map +1 -1
- package/dist/lib/plugins/api-keys/ProtectedRoute.d.ts +1 -0
- package/dist/lib/plugins/api-keys/ProtectedRoute.js +14 -0
- package/dist/lib/plugins/api-keys/ProtectedRoute.js.map +1 -0
- package/dist/lib/plugins/api-keys/index.js +2 -12
- package/dist/lib/plugins/api-keys/index.js.map +1 -1
- package/dist/lib/plugins/openapi/OperationList.js +2 -2
- package/dist/lib/plugins/openapi/OperationList.js.map +1 -1
- package/dist/lib/plugins/openapi/playground/PlaygroundDialog.js +3 -3
- package/dist/lib/plugins/openapi/playground/PlaygroundDialog.js.map +1 -1
- package/lib/AnchorLink-GNsUeGSX.js +705 -0
- package/lib/{AnchorLink-BaXHjhF-.js.map → AnchorLink-GNsUeGSX.js.map} +1 -1
- package/lib/Button-DpHMZvVs.js +4571 -0
- package/lib/Button-DpHMZvVs.js.map +1 -0
- package/lib/DevPortalProvider-Do9oJqme.js +1081 -0
- package/lib/{DevPortalProvider-GjdO0Xr-.js.map → DevPortalProvider-Do9oJqme.js.map} +1 -1
- package/lib/Markdown-DtLFdxD1.js +15031 -0
- package/lib/Markdown-DtLFdxD1.js.map +1 -0
- package/lib/MdxPage-CbwYRKf5.js +190 -0
- package/lib/{MdxPage-Dlujuj-J.js.map → MdxPage-CbwYRKf5.js.map} +1 -1
- package/lib/OperationList-DpR4KzIJ.js +5570 -0
- package/lib/OperationList-DpR4KzIJ.js.map +1 -0
- package/lib/Route-C1LyvITr.js +13 -0
- package/lib/{Route-CR6TEwVC.js.map → Route-C1LyvITr.js.map} +1 -1
- package/lib/Spinner-Bhbs5aPI.js +182 -0
- package/lib/Spinner-Bhbs5aPI.js.map +1 -0
- package/lib/_commonjsHelpers-BVfed4GL.js +29 -0
- package/lib/_commonjsHelpers-BVfed4GL.js.map +1 -0
- package/lib/assets/index-BPdJm2ty.js +4765 -0
- package/lib/assets/{index-CpIig0AX.js.map → index-BPdJm2ty.js.map} +1 -1
- package/lib/assets/worker-BjPv-hjP.js +14897 -0
- package/lib/assets/{worker-B5k2aBV9.js.map → worker-BjPv-hjP.js.map} +1 -1
- package/lib/context-_fYfJFgk.js +14 -0
- package/lib/{context-BoN_3uxi.js.map → context-_fYfJFgk.js.map} +1 -1
- package/lib/hook-Biq3zYel.js +92 -0
- package/lib/hook-Biq3zYel.js.map +1 -0
- package/lib/{index-Dih8IAqw.js → index-DZ910ttL.js} +83 -103
- package/lib/{index-Dih8IAqw.js.map → index-DZ910ttL.js.map} +1 -1
- package/lib/index-gsAuUwQh.js +418 -0
- package/lib/index-gsAuUwQh.js.map +1 -0
- package/lib/index-pI9JkN46.js +4765 -0
- package/lib/{index-Bn03IPZt.js.map → index-pI9JkN46.js.map} +1 -1
- package/lib/jsx-runtime-CJZJivg2.js +1526 -0
- package/lib/{jsx-runtime-DvZ6OKMM.js.map → jsx-runtime-CJZJivg2.js.map} +1 -1
- package/lib/prism-bash.min-DadFsM4Z.js +7 -0
- package/lib/{prism-bash.min-BtBk0onv.js.map → prism-bash.min-DadFsM4Z.js.map} +1 -1
- package/lib/prism-csharp.min-Yizuc34Y.js +35 -0
- package/lib/{prism-csharp.min-Cv7D49bv.js.map → prism-csharp.min-Yizuc34Y.js.map} +1 -1
- package/lib/prism-java.min-d5iT_mOd.js +7 -0
- package/lib/{prism-java.min-tNK-JX6x.js.map → prism-java.min-d5iT_mOd.js.map} +1 -1
- package/lib/prism-json.min-B1GJqK1k.js +2 -0
- package/lib/{prism-json.min-Cdtv-CME.js.map → prism-json.min-B1GJqK1k.js.map} +1 -1
- package/lib/prism-markup-templating-DZrrEs0A.js +62 -0
- package/lib/{prism-markup-templating-iotg2sCU.js.map → prism-markup-templating-DZrrEs0A.js.map} +1 -1
- package/lib/prism-objectivec.min-BXSWqpJJ.js +2 -0
- package/lib/{prism-objectivec.min-CY4WGixz.js.map → prism-objectivec.min-BXSWqpJJ.js.map} +1 -1
- package/lib/prism-php.min-o7FpoMP_.js +11 -0
- package/lib/{prism-php.min-T6sIVgED.js.map → prism-php.min-o7FpoMP_.js.map} +1 -1
- package/lib/prism-ruby.min-C7LwcKyz.js +10 -0
- package/lib/{prism-ruby.min-B-2KAa4y.js.map → prism-ruby.min-C7LwcKyz.js.map} +1 -1
- package/lib/router-CBw2vqJE.js +2973 -0
- package/lib/{router-ButO1QyY.js.map → router-CBw2vqJE.js.map} +1 -1
- package/lib/slugify-CiPVjteN.js +28 -0
- package/lib/{slugify-CmS97Vy8.js.map → slugify-CiPVjteN.js.map} +1 -1
- package/lib/state-DKdaQzvh.js +288 -0
- package/lib/{state-CmGfNKhR.js.map → state-DKdaQzvh.js.map} +1 -1
- package/lib/urql-DMlBWUKL.js +1592 -0
- package/lib/{urql-DtVKPBx_.js.map → urql-DMlBWUKL.js.map} +1 -1
- package/lib/util-_jwUlTBU.js +41 -0
- package/lib/{util-B5KX4h4M.js.map → util-_jwUlTBU.js.map} +1 -1
- package/lib/zudoku.auth-auth0.js +18 -24
- package/lib/zudoku.auth-auth0.js.map +1 -1
- package/lib/zudoku.auth-clerk.js +34 -43
- package/lib/zudoku.auth-clerk.js.map +1 -1
- package/lib/zudoku.auth-openid.js +734 -1121
- package/lib/zudoku.auth-openid.js.map +1 -1
- package/lib/zudoku.components.js +822 -1076
- package/lib/zudoku.components.js.map +1 -1
- package/lib/zudoku.openapi-worker.js +9691 -13786
- package/lib/zudoku.openapi-worker.js.map +1 -1
- package/lib/zudoku.plugin-api-keys.js +171 -208
- package/lib/zudoku.plugin-api-keys.js.map +1 -1
- package/lib/zudoku.plugin-markdown.js +33 -41
- package/lib/zudoku.plugin-markdown.js.map +1 -1
- package/lib/zudoku.plugin-openapi.js +6 -6
- package/lib/zudoku.plugin-redirect.js +8 -10
- package/lib/zudoku.plugin-redirect.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/components/DeveloperHint.tsx +25 -0
- package/src/lib/components/NotFoundPage.tsx +8 -14
- package/src/lib/plugins/api-keys/ProtectedRoute.tsx +29 -0
- package/src/lib/plugins/api-keys/index.tsx +2 -21
- package/src/lib/plugins/openapi/OperationList.tsx +5 -8
- package/src/lib/plugins/openapi/playground/PlaygroundDialog.tsx +3 -5
- package/lib/AnchorLink-BaXHjhF-.js +0 -989
- package/lib/Combination-BfufJFkX.js +0 -1365
- package/lib/Combination-BfufJFkX.js.map +0 -1
- package/lib/DevPortalProvider-GjdO0Xr-.js +0 -1610
- package/lib/Markdown-B8nPVql1.js +0 -19708
- package/lib/Markdown-B8nPVql1.js.map +0 -1
- package/lib/MdxPage-Dlujuj-J.js +0 -223
- package/lib/OperationList-krPgt6sE.js +0 -8041
- package/lib/OperationList-krPgt6sE.js.map +0 -1
- package/lib/Playground-DOHxca0P.js +0 -539
- package/lib/Playground-DOHxca0P.js.map +0 -1
- package/lib/Route-CR6TEwVC.js +0 -13
- package/lib/Select-Boi_pe3L.js +0 -5298
- package/lib/Select-Boi_pe3L.js.map +0 -1
- package/lib/Spinner-oU0QJmi_.js +0 -16
- package/lib/Spinner-oU0QJmi_.js.map +0 -1
- package/lib/_commonjsHelpers-BxmBWJD2.js +0 -34
- package/lib/_commonjsHelpers-BxmBWJD2.js.map +0 -1
- package/lib/assets/index-CpIig0AX.js +0 -6341
- package/lib/assets/worker-B5k2aBV9.js +0 -18921
- package/lib/context-BoN_3uxi.js +0 -17
- package/lib/hook-CIuFuyBT.js +0 -90
- package/lib/hook-CIuFuyBT.js.map +0 -1
- package/lib/index-BL1P4Gqq.js +0 -280
- package/lib/index-BL1P4Gqq.js.map +0 -1
- package/lib/index-Bn03IPZt.js +0 -6341
- package/lib/index-FprhHF51.js +0 -253
- package/lib/index-FprhHF51.js.map +0 -1
- package/lib/jsx-runtime-DvZ6OKMM.js +0 -2110
- package/lib/mutation-DWY9x2Uc.js +0 -250
- package/lib/mutation-DWY9x2Uc.js.map +0 -1
- package/lib/prism-bash.min-BtBk0onv.js +0 -7
- package/lib/prism-csharp.min-Cv7D49bv.js +0 -30
- package/lib/prism-java.min-tNK-JX6x.js +0 -7
- package/lib/prism-json.min-Cdtv-CME.js +0 -2
- package/lib/prism-markup-templating-iotg2sCU.js +0 -94
- package/lib/prism-objectivec.min-CY4WGixz.js +0 -2
- package/lib/prism-php.min-T6sIVgED.js +0 -11
- package/lib/prism-ruby.min-B-2KAa4y.js +0 -8
- package/lib/router-ButO1QyY.js +0 -4062
- package/lib/slugify-CmS97Vy8.js +0 -50
- package/lib/state-CmGfNKhR.js +0 -436
- package/lib/urql-DtVKPBx_.js +0 -2567
- package/lib/util-B5KX4h4M.js +0 -55
package/lib/router-ButO1QyY.js
DELETED
|
@@ -1,4062 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @remix-run/router v1.17.1
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Remix Software Inc.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
function _extends() {
|
|
12
|
-
_extends = Object.assign ? Object.assign.bind() : function(target) {
|
|
13
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
14
|
-
var source = arguments[i];
|
|
15
|
-
for (var key in source) {
|
|
16
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
17
|
-
target[key] = source[key];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return target;
|
|
22
|
-
};
|
|
23
|
-
return _extends.apply(this, arguments);
|
|
24
|
-
}
|
|
25
|
-
var Action;
|
|
26
|
-
(function(Action2) {
|
|
27
|
-
Action2["Pop"] = "POP";
|
|
28
|
-
Action2["Push"] = "PUSH";
|
|
29
|
-
Action2["Replace"] = "REPLACE";
|
|
30
|
-
})(Action || (Action = {}));
|
|
31
|
-
const PopStateEventType = "popstate";
|
|
32
|
-
function createMemoryHistory(options) {
|
|
33
|
-
if (options === void 0) {
|
|
34
|
-
options = {};
|
|
35
|
-
}
|
|
36
|
-
let {
|
|
37
|
-
initialEntries = ["/"],
|
|
38
|
-
initialIndex,
|
|
39
|
-
v5Compat = false
|
|
40
|
-
} = options;
|
|
41
|
-
let entries;
|
|
42
|
-
entries = initialEntries.map((entry, index2) => createMemoryLocation(entry, typeof entry === "string" ? null : entry.state, index2 === 0 ? "default" : void 0));
|
|
43
|
-
let index = clampIndex(initialIndex == null ? entries.length - 1 : initialIndex);
|
|
44
|
-
let action = Action.Pop;
|
|
45
|
-
let listener = null;
|
|
46
|
-
function clampIndex(n) {
|
|
47
|
-
return Math.min(Math.max(n, 0), entries.length - 1);
|
|
48
|
-
}
|
|
49
|
-
function getCurrentLocation() {
|
|
50
|
-
return entries[index];
|
|
51
|
-
}
|
|
52
|
-
function createMemoryLocation(to, state, key) {
|
|
53
|
-
if (state === void 0) {
|
|
54
|
-
state = null;
|
|
55
|
-
}
|
|
56
|
-
let location = createLocation(entries ? getCurrentLocation().pathname : "/", to, state, key);
|
|
57
|
-
warning(location.pathname.charAt(0) === "/", "relative pathnames are not supported in memory history: " + JSON.stringify(to));
|
|
58
|
-
return location;
|
|
59
|
-
}
|
|
60
|
-
function createHref(to) {
|
|
61
|
-
return typeof to === "string" ? to : createPath(to);
|
|
62
|
-
}
|
|
63
|
-
let history = {
|
|
64
|
-
get index() {
|
|
65
|
-
return index;
|
|
66
|
-
},
|
|
67
|
-
get action() {
|
|
68
|
-
return action;
|
|
69
|
-
},
|
|
70
|
-
get location() {
|
|
71
|
-
return getCurrentLocation();
|
|
72
|
-
},
|
|
73
|
-
createHref,
|
|
74
|
-
createURL(to) {
|
|
75
|
-
return new URL(createHref(to), "http://localhost");
|
|
76
|
-
},
|
|
77
|
-
encodeLocation(to) {
|
|
78
|
-
let path = typeof to === "string" ? parsePath(to) : to;
|
|
79
|
-
return {
|
|
80
|
-
pathname: path.pathname || "",
|
|
81
|
-
search: path.search || "",
|
|
82
|
-
hash: path.hash || ""
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
push(to, state) {
|
|
86
|
-
action = Action.Push;
|
|
87
|
-
let nextLocation = createMemoryLocation(to, state);
|
|
88
|
-
index += 1;
|
|
89
|
-
entries.splice(index, entries.length, nextLocation);
|
|
90
|
-
if (v5Compat && listener) {
|
|
91
|
-
listener({
|
|
92
|
-
action,
|
|
93
|
-
location: nextLocation,
|
|
94
|
-
delta: 1
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
replace(to, state) {
|
|
99
|
-
action = Action.Replace;
|
|
100
|
-
let nextLocation = createMemoryLocation(to, state);
|
|
101
|
-
entries[index] = nextLocation;
|
|
102
|
-
if (v5Compat && listener) {
|
|
103
|
-
listener({
|
|
104
|
-
action,
|
|
105
|
-
location: nextLocation,
|
|
106
|
-
delta: 0
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
go(delta) {
|
|
111
|
-
action = Action.Pop;
|
|
112
|
-
let nextIndex = clampIndex(index + delta);
|
|
113
|
-
let nextLocation = entries[nextIndex];
|
|
114
|
-
index = nextIndex;
|
|
115
|
-
if (listener) {
|
|
116
|
-
listener({
|
|
117
|
-
action,
|
|
118
|
-
location: nextLocation,
|
|
119
|
-
delta
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
listen(fn) {
|
|
124
|
-
listener = fn;
|
|
125
|
-
return () => {
|
|
126
|
-
listener = null;
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
return history;
|
|
131
|
-
}
|
|
132
|
-
function createBrowserHistory(options) {
|
|
133
|
-
if (options === void 0) {
|
|
134
|
-
options = {};
|
|
135
|
-
}
|
|
136
|
-
function createBrowserLocation(window2, globalHistory) {
|
|
137
|
-
let {
|
|
138
|
-
pathname,
|
|
139
|
-
search,
|
|
140
|
-
hash
|
|
141
|
-
} = window2.location;
|
|
142
|
-
return createLocation(
|
|
143
|
-
"",
|
|
144
|
-
{
|
|
145
|
-
pathname,
|
|
146
|
-
search,
|
|
147
|
-
hash
|
|
148
|
-
},
|
|
149
|
-
// state defaults to `null` because `window.history.state` does
|
|
150
|
-
globalHistory.state && globalHistory.state.usr || null,
|
|
151
|
-
globalHistory.state && globalHistory.state.key || "default"
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
function createBrowserHref(window2, to) {
|
|
155
|
-
return typeof to === "string" ? to : createPath(to);
|
|
156
|
-
}
|
|
157
|
-
return getUrlBasedHistory(createBrowserLocation, createBrowserHref, null, options);
|
|
158
|
-
}
|
|
159
|
-
function createHashHistory(options) {
|
|
160
|
-
if (options === void 0) {
|
|
161
|
-
options = {};
|
|
162
|
-
}
|
|
163
|
-
function createHashLocation(window2, globalHistory) {
|
|
164
|
-
let {
|
|
165
|
-
pathname = "/",
|
|
166
|
-
search = "",
|
|
167
|
-
hash = ""
|
|
168
|
-
} = parsePath(window2.location.hash.substr(1));
|
|
169
|
-
if (!pathname.startsWith("/") && !pathname.startsWith(".")) {
|
|
170
|
-
pathname = "/" + pathname;
|
|
171
|
-
}
|
|
172
|
-
return createLocation(
|
|
173
|
-
"",
|
|
174
|
-
{
|
|
175
|
-
pathname,
|
|
176
|
-
search,
|
|
177
|
-
hash
|
|
178
|
-
},
|
|
179
|
-
// state defaults to `null` because `window.history.state` does
|
|
180
|
-
globalHistory.state && globalHistory.state.usr || null,
|
|
181
|
-
globalHistory.state && globalHistory.state.key || "default"
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
function createHashHref(window2, to) {
|
|
185
|
-
let base = window2.document.querySelector("base");
|
|
186
|
-
let href = "";
|
|
187
|
-
if (base && base.getAttribute("href")) {
|
|
188
|
-
let url = window2.location.href;
|
|
189
|
-
let hashIndex = url.indexOf("#");
|
|
190
|
-
href = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
191
|
-
}
|
|
192
|
-
return href + "#" + (typeof to === "string" ? to : createPath(to));
|
|
193
|
-
}
|
|
194
|
-
function validateHashLocation(location, to) {
|
|
195
|
-
warning(location.pathname.charAt(0) === "/", "relative pathnames are not supported in hash history.push(" + JSON.stringify(to) + ")");
|
|
196
|
-
}
|
|
197
|
-
return getUrlBasedHistory(createHashLocation, createHashHref, validateHashLocation, options);
|
|
198
|
-
}
|
|
199
|
-
function invariant(value, message) {
|
|
200
|
-
if (value === false || value === null || typeof value === "undefined") {
|
|
201
|
-
throw new Error(message);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
function warning(cond, message) {
|
|
205
|
-
if (!cond) {
|
|
206
|
-
if (typeof console !== "undefined") console.warn(message);
|
|
207
|
-
try {
|
|
208
|
-
throw new Error(message);
|
|
209
|
-
} catch (e) {
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function createKey() {
|
|
214
|
-
return Math.random().toString(36).substr(2, 8);
|
|
215
|
-
}
|
|
216
|
-
function getHistoryState(location, index) {
|
|
217
|
-
return {
|
|
218
|
-
usr: location.state,
|
|
219
|
-
key: location.key,
|
|
220
|
-
idx: index
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function createLocation(current, to, state, key) {
|
|
224
|
-
if (state === void 0) {
|
|
225
|
-
state = null;
|
|
226
|
-
}
|
|
227
|
-
let location = _extends({
|
|
228
|
-
pathname: typeof current === "string" ? current : current.pathname,
|
|
229
|
-
search: "",
|
|
230
|
-
hash: ""
|
|
231
|
-
}, typeof to === "string" ? parsePath(to) : to, {
|
|
232
|
-
state,
|
|
233
|
-
// TODO: This could be cleaned up. push/replace should probably just take
|
|
234
|
-
// full Locations now and avoid the need to run through this flow at all
|
|
235
|
-
// But that's a pretty big refactor to the current test suite so going to
|
|
236
|
-
// keep as is for the time being and just let any incoming keys take precedence
|
|
237
|
-
key: to && to.key || key || createKey()
|
|
238
|
-
});
|
|
239
|
-
return location;
|
|
240
|
-
}
|
|
241
|
-
function createPath(_ref) {
|
|
242
|
-
let {
|
|
243
|
-
pathname = "/",
|
|
244
|
-
search = "",
|
|
245
|
-
hash = ""
|
|
246
|
-
} = _ref;
|
|
247
|
-
if (search && search !== "?") pathname += search.charAt(0) === "?" ? search : "?" + search;
|
|
248
|
-
if (hash && hash !== "#") pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
|
|
249
|
-
return pathname;
|
|
250
|
-
}
|
|
251
|
-
function parsePath(path) {
|
|
252
|
-
let parsedPath = {};
|
|
253
|
-
if (path) {
|
|
254
|
-
let hashIndex = path.indexOf("#");
|
|
255
|
-
if (hashIndex >= 0) {
|
|
256
|
-
parsedPath.hash = path.substr(hashIndex);
|
|
257
|
-
path = path.substr(0, hashIndex);
|
|
258
|
-
}
|
|
259
|
-
let searchIndex = path.indexOf("?");
|
|
260
|
-
if (searchIndex >= 0) {
|
|
261
|
-
parsedPath.search = path.substr(searchIndex);
|
|
262
|
-
path = path.substr(0, searchIndex);
|
|
263
|
-
}
|
|
264
|
-
if (path) {
|
|
265
|
-
parsedPath.pathname = path;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return parsedPath;
|
|
269
|
-
}
|
|
270
|
-
function getUrlBasedHistory(getLocation, createHref, validateLocation, options) {
|
|
271
|
-
if (options === void 0) {
|
|
272
|
-
options = {};
|
|
273
|
-
}
|
|
274
|
-
let {
|
|
275
|
-
window: window2 = document.defaultView,
|
|
276
|
-
v5Compat = false
|
|
277
|
-
} = options;
|
|
278
|
-
let globalHistory = window2.history;
|
|
279
|
-
let action = Action.Pop;
|
|
280
|
-
let listener = null;
|
|
281
|
-
let index = getIndex();
|
|
282
|
-
if (index == null) {
|
|
283
|
-
index = 0;
|
|
284
|
-
globalHistory.replaceState(_extends({}, globalHistory.state, {
|
|
285
|
-
idx: index
|
|
286
|
-
}), "");
|
|
287
|
-
}
|
|
288
|
-
function getIndex() {
|
|
289
|
-
let state = globalHistory.state || {
|
|
290
|
-
idx: null
|
|
291
|
-
};
|
|
292
|
-
return state.idx;
|
|
293
|
-
}
|
|
294
|
-
function handlePop() {
|
|
295
|
-
action = Action.Pop;
|
|
296
|
-
let nextIndex = getIndex();
|
|
297
|
-
let delta = nextIndex == null ? null : nextIndex - index;
|
|
298
|
-
index = nextIndex;
|
|
299
|
-
if (listener) {
|
|
300
|
-
listener({
|
|
301
|
-
action,
|
|
302
|
-
location: history.location,
|
|
303
|
-
delta
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
function push(to, state) {
|
|
308
|
-
action = Action.Push;
|
|
309
|
-
let location = createLocation(history.location, to, state);
|
|
310
|
-
if (validateLocation) validateLocation(location, to);
|
|
311
|
-
index = getIndex() + 1;
|
|
312
|
-
let historyState = getHistoryState(location, index);
|
|
313
|
-
let url = history.createHref(location);
|
|
314
|
-
try {
|
|
315
|
-
globalHistory.pushState(historyState, "", url);
|
|
316
|
-
} catch (error) {
|
|
317
|
-
if (error instanceof DOMException && error.name === "DataCloneError") {
|
|
318
|
-
throw error;
|
|
319
|
-
}
|
|
320
|
-
window2.location.assign(url);
|
|
321
|
-
}
|
|
322
|
-
if (v5Compat && listener) {
|
|
323
|
-
listener({
|
|
324
|
-
action,
|
|
325
|
-
location: history.location,
|
|
326
|
-
delta: 1
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
function replace(to, state) {
|
|
331
|
-
action = Action.Replace;
|
|
332
|
-
let location = createLocation(history.location, to, state);
|
|
333
|
-
if (validateLocation) validateLocation(location, to);
|
|
334
|
-
index = getIndex();
|
|
335
|
-
let historyState = getHistoryState(location, index);
|
|
336
|
-
let url = history.createHref(location);
|
|
337
|
-
globalHistory.replaceState(historyState, "", url);
|
|
338
|
-
if (v5Compat && listener) {
|
|
339
|
-
listener({
|
|
340
|
-
action,
|
|
341
|
-
location: history.location,
|
|
342
|
-
delta: 0
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
function createURL(to) {
|
|
347
|
-
let base = window2.location.origin !== "null" ? window2.location.origin : window2.location.href;
|
|
348
|
-
let href = typeof to === "string" ? to : createPath(to);
|
|
349
|
-
href = href.replace(/ $/, "%20");
|
|
350
|
-
invariant(base, "No window.location.(origin|href) available to create URL for href: " + href);
|
|
351
|
-
return new URL(href, base);
|
|
352
|
-
}
|
|
353
|
-
let history = {
|
|
354
|
-
get action() {
|
|
355
|
-
return action;
|
|
356
|
-
},
|
|
357
|
-
get location() {
|
|
358
|
-
return getLocation(window2, globalHistory);
|
|
359
|
-
},
|
|
360
|
-
listen(fn) {
|
|
361
|
-
if (listener) {
|
|
362
|
-
throw new Error("A history only accepts one active listener");
|
|
363
|
-
}
|
|
364
|
-
window2.addEventListener(PopStateEventType, handlePop);
|
|
365
|
-
listener = fn;
|
|
366
|
-
return () => {
|
|
367
|
-
window2.removeEventListener(PopStateEventType, handlePop);
|
|
368
|
-
listener = null;
|
|
369
|
-
};
|
|
370
|
-
},
|
|
371
|
-
createHref(to) {
|
|
372
|
-
return createHref(window2, to);
|
|
373
|
-
},
|
|
374
|
-
createURL,
|
|
375
|
-
encodeLocation(to) {
|
|
376
|
-
let url = createURL(to);
|
|
377
|
-
return {
|
|
378
|
-
pathname: url.pathname,
|
|
379
|
-
search: url.search,
|
|
380
|
-
hash: url.hash
|
|
381
|
-
};
|
|
382
|
-
},
|
|
383
|
-
push,
|
|
384
|
-
replace,
|
|
385
|
-
go(n) {
|
|
386
|
-
return globalHistory.go(n);
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
return history;
|
|
390
|
-
}
|
|
391
|
-
var ResultType;
|
|
392
|
-
(function(ResultType2) {
|
|
393
|
-
ResultType2["data"] = "data";
|
|
394
|
-
ResultType2["deferred"] = "deferred";
|
|
395
|
-
ResultType2["redirect"] = "redirect";
|
|
396
|
-
ResultType2["error"] = "error";
|
|
397
|
-
})(ResultType || (ResultType = {}));
|
|
398
|
-
const immutableRouteKeys = /* @__PURE__ */ new Set(["lazy", "caseSensitive", "path", "id", "index", "children"]);
|
|
399
|
-
function isIndexRoute(route) {
|
|
400
|
-
return route.index === true;
|
|
401
|
-
}
|
|
402
|
-
function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath, manifest) {
|
|
403
|
-
if (parentPath === void 0) {
|
|
404
|
-
parentPath = [];
|
|
405
|
-
}
|
|
406
|
-
if (manifest === void 0) {
|
|
407
|
-
manifest = {};
|
|
408
|
-
}
|
|
409
|
-
return routes.map((route, index) => {
|
|
410
|
-
let treePath = [...parentPath, String(index)];
|
|
411
|
-
let id = typeof route.id === "string" ? route.id : treePath.join("-");
|
|
412
|
-
invariant(route.index !== true || !route.children, "Cannot specify children on an index route");
|
|
413
|
-
invariant(!manifest[id], 'Found a route id collision on id "' + id + `". Route id's must be globally unique within Data Router usages`);
|
|
414
|
-
if (isIndexRoute(route)) {
|
|
415
|
-
let indexRoute = _extends({}, route, mapRouteProperties(route), {
|
|
416
|
-
id
|
|
417
|
-
});
|
|
418
|
-
manifest[id] = indexRoute;
|
|
419
|
-
return indexRoute;
|
|
420
|
-
} else {
|
|
421
|
-
let pathOrLayoutRoute = _extends({}, route, mapRouteProperties(route), {
|
|
422
|
-
id,
|
|
423
|
-
children: void 0
|
|
424
|
-
});
|
|
425
|
-
manifest[id] = pathOrLayoutRoute;
|
|
426
|
-
if (route.children) {
|
|
427
|
-
pathOrLayoutRoute.children = convertRoutesToDataRoutes(route.children, mapRouteProperties, treePath, manifest);
|
|
428
|
-
}
|
|
429
|
-
return pathOrLayoutRoute;
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
function matchRoutes(routes, locationArg, basename) {
|
|
434
|
-
if (basename === void 0) {
|
|
435
|
-
basename = "/";
|
|
436
|
-
}
|
|
437
|
-
return matchRoutesImpl(routes, locationArg, basename, false);
|
|
438
|
-
}
|
|
439
|
-
function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
|
|
440
|
-
let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
|
441
|
-
let pathname = stripBasename(location.pathname || "/", basename);
|
|
442
|
-
if (pathname == null) {
|
|
443
|
-
return null;
|
|
444
|
-
}
|
|
445
|
-
let branches = flattenRoutes(routes);
|
|
446
|
-
rankRouteBranches(branches);
|
|
447
|
-
let matches = null;
|
|
448
|
-
for (let i = 0; matches == null && i < branches.length; ++i) {
|
|
449
|
-
let decoded = decodePath(pathname);
|
|
450
|
-
matches = matchRouteBranch(branches[i], decoded, allowPartial);
|
|
451
|
-
}
|
|
452
|
-
return matches;
|
|
453
|
-
}
|
|
454
|
-
function convertRouteMatchToUiMatch(match, loaderData) {
|
|
455
|
-
let {
|
|
456
|
-
route,
|
|
457
|
-
pathname,
|
|
458
|
-
params
|
|
459
|
-
} = match;
|
|
460
|
-
return {
|
|
461
|
-
id: route.id,
|
|
462
|
-
pathname,
|
|
463
|
-
params,
|
|
464
|
-
data: loaderData[route.id],
|
|
465
|
-
handle: route.handle
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
function flattenRoutes(routes, branches, parentsMeta, parentPath) {
|
|
469
|
-
if (branches === void 0) {
|
|
470
|
-
branches = [];
|
|
471
|
-
}
|
|
472
|
-
if (parentsMeta === void 0) {
|
|
473
|
-
parentsMeta = [];
|
|
474
|
-
}
|
|
475
|
-
if (parentPath === void 0) {
|
|
476
|
-
parentPath = "";
|
|
477
|
-
}
|
|
478
|
-
let flattenRoute = (route, index, relativePath) => {
|
|
479
|
-
let meta = {
|
|
480
|
-
relativePath: relativePath === void 0 ? route.path || "" : relativePath,
|
|
481
|
-
caseSensitive: route.caseSensitive === true,
|
|
482
|
-
childrenIndex: index,
|
|
483
|
-
route
|
|
484
|
-
};
|
|
485
|
-
if (meta.relativePath.startsWith("/")) {
|
|
486
|
-
invariant(meta.relativePath.startsWith(parentPath), '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.");
|
|
487
|
-
meta.relativePath = meta.relativePath.slice(parentPath.length);
|
|
488
|
-
}
|
|
489
|
-
let path = joinPaths([parentPath, meta.relativePath]);
|
|
490
|
-
let routesMeta = parentsMeta.concat(meta);
|
|
491
|
-
if (route.children && route.children.length > 0) {
|
|
492
|
-
invariant(
|
|
493
|
-
// Our types know better, but runtime JS may not!
|
|
494
|
-
// @ts-expect-error
|
|
495
|
-
route.index !== true,
|
|
496
|
-
"Index routes must not have child routes. Please remove " + ('all child routes from route path "' + path + '".')
|
|
497
|
-
);
|
|
498
|
-
flattenRoutes(route.children, branches, routesMeta, path);
|
|
499
|
-
}
|
|
500
|
-
if (route.path == null && !route.index) {
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
branches.push({
|
|
504
|
-
path,
|
|
505
|
-
score: computeScore(path, route.index),
|
|
506
|
-
routesMeta
|
|
507
|
-
});
|
|
508
|
-
};
|
|
509
|
-
routes.forEach((route, index) => {
|
|
510
|
-
var _route$path;
|
|
511
|
-
if (route.path === "" || !((_route$path = route.path) != null && _route$path.includes("?"))) {
|
|
512
|
-
flattenRoute(route, index);
|
|
513
|
-
} else {
|
|
514
|
-
for (let exploded of explodeOptionalSegments(route.path)) {
|
|
515
|
-
flattenRoute(route, index, exploded);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
return branches;
|
|
520
|
-
}
|
|
521
|
-
function explodeOptionalSegments(path) {
|
|
522
|
-
let segments = path.split("/");
|
|
523
|
-
if (segments.length === 0) return [];
|
|
524
|
-
let [first, ...rest] = segments;
|
|
525
|
-
let isOptional = first.endsWith("?");
|
|
526
|
-
let required = first.replace(/\?$/, "");
|
|
527
|
-
if (rest.length === 0) {
|
|
528
|
-
return isOptional ? [required, ""] : [required];
|
|
529
|
-
}
|
|
530
|
-
let restExploded = explodeOptionalSegments(rest.join("/"));
|
|
531
|
-
let result = [];
|
|
532
|
-
result.push(...restExploded.map((subpath) => subpath === "" ? required : [required, subpath].join("/")));
|
|
533
|
-
if (isOptional) {
|
|
534
|
-
result.push(...restExploded);
|
|
535
|
-
}
|
|
536
|
-
return result.map((exploded) => path.startsWith("/") && exploded === "" ? "/" : exploded);
|
|
537
|
-
}
|
|
538
|
-
function rankRouteBranches(branches) {
|
|
539
|
-
branches.sort((a, b) => a.score !== b.score ? b.score - a.score : compareIndexes(a.routesMeta.map((meta) => meta.childrenIndex), b.routesMeta.map((meta) => meta.childrenIndex)));
|
|
540
|
-
}
|
|
541
|
-
const paramRe = /^:[\w-]+$/;
|
|
542
|
-
const dynamicSegmentValue = 3;
|
|
543
|
-
const indexRouteValue = 2;
|
|
544
|
-
const emptySegmentValue = 1;
|
|
545
|
-
const staticSegmentValue = 10;
|
|
546
|
-
const splatPenalty = -2;
|
|
547
|
-
const isSplat = (s) => s === "*";
|
|
548
|
-
function computeScore(path, index) {
|
|
549
|
-
let segments = path.split("/");
|
|
550
|
-
let initialScore = segments.length;
|
|
551
|
-
if (segments.some(isSplat)) {
|
|
552
|
-
initialScore += splatPenalty;
|
|
553
|
-
}
|
|
554
|
-
if (index) {
|
|
555
|
-
initialScore += indexRouteValue;
|
|
556
|
-
}
|
|
557
|
-
return segments.filter((s) => !isSplat(s)).reduce((score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue), initialScore);
|
|
558
|
-
}
|
|
559
|
-
function compareIndexes(a, b) {
|
|
560
|
-
let siblings = a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]);
|
|
561
|
-
return siblings ? (
|
|
562
|
-
// If two routes are siblings, we should try to match the earlier sibling
|
|
563
|
-
// first. This allows people to have fine-grained control over the matching
|
|
564
|
-
// behavior by simply putting routes with identical paths in the order they
|
|
565
|
-
// want them tried.
|
|
566
|
-
a[a.length - 1] - b[b.length - 1]
|
|
567
|
-
) : (
|
|
568
|
-
// Otherwise, it doesn't really make sense to rank non-siblings by index,
|
|
569
|
-
// so they sort equally.
|
|
570
|
-
0
|
|
571
|
-
);
|
|
572
|
-
}
|
|
573
|
-
function matchRouteBranch(branch, pathname, allowPartial) {
|
|
574
|
-
if (allowPartial === void 0) {
|
|
575
|
-
allowPartial = false;
|
|
576
|
-
}
|
|
577
|
-
let {
|
|
578
|
-
routesMeta
|
|
579
|
-
} = branch;
|
|
580
|
-
let matchedParams = {};
|
|
581
|
-
let matchedPathname = "/";
|
|
582
|
-
let matches = [];
|
|
583
|
-
for (let i = 0; i < routesMeta.length; ++i) {
|
|
584
|
-
let meta = routesMeta[i];
|
|
585
|
-
let end = i === routesMeta.length - 1;
|
|
586
|
-
let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/";
|
|
587
|
-
let match = matchPath({
|
|
588
|
-
path: meta.relativePath,
|
|
589
|
-
caseSensitive: meta.caseSensitive,
|
|
590
|
-
end
|
|
591
|
-
}, remainingPathname);
|
|
592
|
-
let route = meta.route;
|
|
593
|
-
if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) {
|
|
594
|
-
match = matchPath({
|
|
595
|
-
path: meta.relativePath,
|
|
596
|
-
caseSensitive: meta.caseSensitive,
|
|
597
|
-
end: false
|
|
598
|
-
}, remainingPathname);
|
|
599
|
-
}
|
|
600
|
-
if (!match) {
|
|
601
|
-
return null;
|
|
602
|
-
}
|
|
603
|
-
Object.assign(matchedParams, match.params);
|
|
604
|
-
matches.push({
|
|
605
|
-
// TODO: Can this as be avoided?
|
|
606
|
-
params: matchedParams,
|
|
607
|
-
pathname: joinPaths([matchedPathname, match.pathname]),
|
|
608
|
-
pathnameBase: normalizePathname(joinPaths([matchedPathname, match.pathnameBase])),
|
|
609
|
-
route
|
|
610
|
-
});
|
|
611
|
-
if (match.pathnameBase !== "/") {
|
|
612
|
-
matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
return matches;
|
|
616
|
-
}
|
|
617
|
-
function generatePath(originalPath, params) {
|
|
618
|
-
if (params === void 0) {
|
|
619
|
-
params = {};
|
|
620
|
-
}
|
|
621
|
-
let path = originalPath;
|
|
622
|
-
if (path.endsWith("*") && path !== "*" && !path.endsWith("/*")) {
|
|
623
|
-
warning(false, '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(/\*$/, "/*") + '".'));
|
|
624
|
-
path = path.replace(/\*$/, "/*");
|
|
625
|
-
}
|
|
626
|
-
const prefix = path.startsWith("/") ? "/" : "";
|
|
627
|
-
const stringify = (p) => p == null ? "" : typeof p === "string" ? p : String(p);
|
|
628
|
-
const segments = path.split(/\/+/).map((segment, index, array) => {
|
|
629
|
-
const isLastSegment = index === array.length - 1;
|
|
630
|
-
if (isLastSegment && segment === "*") {
|
|
631
|
-
const star = "*";
|
|
632
|
-
return stringify(params[star]);
|
|
633
|
-
}
|
|
634
|
-
const keyMatch = segment.match(/^:([\w-]+)(\??)$/);
|
|
635
|
-
if (keyMatch) {
|
|
636
|
-
const [, key, optional] = keyMatch;
|
|
637
|
-
let param = params[key];
|
|
638
|
-
invariant(optional === "?" || param != null, 'Missing ":' + key + '" param');
|
|
639
|
-
return stringify(param);
|
|
640
|
-
}
|
|
641
|
-
return segment.replace(/\?$/g, "");
|
|
642
|
-
}).filter((segment) => !!segment);
|
|
643
|
-
return prefix + segments.join("/");
|
|
644
|
-
}
|
|
645
|
-
function matchPath(pattern, pathname) {
|
|
646
|
-
if (typeof pattern === "string") {
|
|
647
|
-
pattern = {
|
|
648
|
-
path: pattern,
|
|
649
|
-
caseSensitive: false,
|
|
650
|
-
end: true
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
let [matcher, compiledParams] = compilePath(pattern.path, pattern.caseSensitive, pattern.end);
|
|
654
|
-
let match = pathname.match(matcher);
|
|
655
|
-
if (!match) return null;
|
|
656
|
-
let matchedPathname = match[0];
|
|
657
|
-
let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
|
|
658
|
-
let captureGroups = match.slice(1);
|
|
659
|
-
let params = compiledParams.reduce((memo, _ref, index) => {
|
|
660
|
-
let {
|
|
661
|
-
paramName,
|
|
662
|
-
isOptional
|
|
663
|
-
} = _ref;
|
|
664
|
-
if (paramName === "*") {
|
|
665
|
-
let splatValue = captureGroups[index] || "";
|
|
666
|
-
pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
|
|
667
|
-
}
|
|
668
|
-
const value = captureGroups[index];
|
|
669
|
-
if (isOptional && !value) {
|
|
670
|
-
memo[paramName] = void 0;
|
|
671
|
-
} else {
|
|
672
|
-
memo[paramName] = (value || "").replace(/%2F/g, "/");
|
|
673
|
-
}
|
|
674
|
-
return memo;
|
|
675
|
-
}, {});
|
|
676
|
-
return {
|
|
677
|
-
params,
|
|
678
|
-
pathname: matchedPathname,
|
|
679
|
-
pathnameBase,
|
|
680
|
-
pattern
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
function compilePath(path, caseSensitive, end) {
|
|
684
|
-
if (caseSensitive === void 0) {
|
|
685
|
-
caseSensitive = false;
|
|
686
|
-
}
|
|
687
|
-
if (end === void 0) {
|
|
688
|
-
end = true;
|
|
689
|
-
}
|
|
690
|
-
warning(path === "*" || !path.endsWith("*") || path.endsWith("/*"), '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(/\*$/, "/*") + '".'));
|
|
691
|
-
let params = [];
|
|
692
|
-
let regexpSource = "^" + path.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(/\/:([\w-]+)(\?)?/g, (_, paramName, isOptional) => {
|
|
693
|
-
params.push({
|
|
694
|
-
paramName,
|
|
695
|
-
isOptional: isOptional != null
|
|
696
|
-
});
|
|
697
|
-
return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
|
|
698
|
-
});
|
|
699
|
-
if (path.endsWith("*")) {
|
|
700
|
-
params.push({
|
|
701
|
-
paramName: "*"
|
|
702
|
-
});
|
|
703
|
-
regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
|
|
704
|
-
} else if (end) {
|
|
705
|
-
regexpSource += "\\/*$";
|
|
706
|
-
} else if (path !== "" && path !== "/") {
|
|
707
|
-
regexpSource += "(?:(?=\\/|$))";
|
|
708
|
-
} else ;
|
|
709
|
-
let matcher = new RegExp(regexpSource, caseSensitive ? void 0 : "i");
|
|
710
|
-
return [matcher, params];
|
|
711
|
-
}
|
|
712
|
-
function decodePath(value) {
|
|
713
|
-
try {
|
|
714
|
-
return value.split("/").map((v) => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
|
|
715
|
-
} catch (error) {
|
|
716
|
-
warning(false, 'The URL path "' + value + '" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent ' + ("encoding (" + error + ")."));
|
|
717
|
-
return value;
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
function stripBasename(pathname, basename) {
|
|
721
|
-
if (basename === "/") return pathname;
|
|
722
|
-
if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
|
|
723
|
-
return null;
|
|
724
|
-
}
|
|
725
|
-
let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length;
|
|
726
|
-
let nextChar = pathname.charAt(startIndex);
|
|
727
|
-
if (nextChar && nextChar !== "/") {
|
|
728
|
-
return null;
|
|
729
|
-
}
|
|
730
|
-
return pathname.slice(startIndex) || "/";
|
|
731
|
-
}
|
|
732
|
-
function resolvePath(to, fromPathname) {
|
|
733
|
-
if (fromPathname === void 0) {
|
|
734
|
-
fromPathname = "/";
|
|
735
|
-
}
|
|
736
|
-
let {
|
|
737
|
-
pathname: toPathname,
|
|
738
|
-
search = "",
|
|
739
|
-
hash = ""
|
|
740
|
-
} = typeof to === "string" ? parsePath(to) : to;
|
|
741
|
-
let pathname = toPathname ? toPathname.startsWith("/") ? toPathname : resolvePathname(toPathname, fromPathname) : fromPathname;
|
|
742
|
-
return {
|
|
743
|
-
pathname,
|
|
744
|
-
search: normalizeSearch(search),
|
|
745
|
-
hash: normalizeHash(hash)
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
function resolvePathname(relativePath, fromPathname) {
|
|
749
|
-
let segments = fromPathname.replace(/\/+$/, "").split("/");
|
|
750
|
-
let relativeSegments = relativePath.split("/");
|
|
751
|
-
relativeSegments.forEach((segment) => {
|
|
752
|
-
if (segment === "..") {
|
|
753
|
-
if (segments.length > 1) segments.pop();
|
|
754
|
-
} else if (segment !== ".") {
|
|
755
|
-
segments.push(segment);
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
return segments.length > 1 ? segments.join("/") : "/";
|
|
759
|
-
}
|
|
760
|
-
function getInvalidPathError(char, field, dest, path) {
|
|
761
|
-
return "Cannot include a '" + char + "' character in a manually specified " + ("`to." + field + "` field [" + JSON.stringify(path) + "]. 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.';
|
|
762
|
-
}
|
|
763
|
-
function getPathContributingMatches(matches) {
|
|
764
|
-
return matches.filter((match, index) => index === 0 || match.route.path && match.route.path.length > 0);
|
|
765
|
-
}
|
|
766
|
-
function getResolveToMatches(matches, v7_relativeSplatPath) {
|
|
767
|
-
let pathMatches = getPathContributingMatches(matches);
|
|
768
|
-
if (v7_relativeSplatPath) {
|
|
769
|
-
return pathMatches.map((match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase);
|
|
770
|
-
}
|
|
771
|
-
return pathMatches.map((match) => match.pathnameBase);
|
|
772
|
-
}
|
|
773
|
-
function resolveTo(toArg, routePathnames, locationPathname, isPathRelative) {
|
|
774
|
-
if (isPathRelative === void 0) {
|
|
775
|
-
isPathRelative = false;
|
|
776
|
-
}
|
|
777
|
-
let to;
|
|
778
|
-
if (typeof toArg === "string") {
|
|
779
|
-
to = parsePath(toArg);
|
|
780
|
-
} else {
|
|
781
|
-
to = _extends({}, toArg);
|
|
782
|
-
invariant(!to.pathname || !to.pathname.includes("?"), getInvalidPathError("?", "pathname", "search", to));
|
|
783
|
-
invariant(!to.pathname || !to.pathname.includes("#"), getInvalidPathError("#", "pathname", "hash", to));
|
|
784
|
-
invariant(!to.search || !to.search.includes("#"), getInvalidPathError("#", "search", "hash", to));
|
|
785
|
-
}
|
|
786
|
-
let isEmptyPath = toArg === "" || to.pathname === "";
|
|
787
|
-
let toPathname = isEmptyPath ? "/" : to.pathname;
|
|
788
|
-
let from;
|
|
789
|
-
if (toPathname == null) {
|
|
790
|
-
from = locationPathname;
|
|
791
|
-
} else {
|
|
792
|
-
let routePathnameIndex = routePathnames.length - 1;
|
|
793
|
-
if (!isPathRelative && toPathname.startsWith("..")) {
|
|
794
|
-
let toSegments = toPathname.split("/");
|
|
795
|
-
while (toSegments[0] === "..") {
|
|
796
|
-
toSegments.shift();
|
|
797
|
-
routePathnameIndex -= 1;
|
|
798
|
-
}
|
|
799
|
-
to.pathname = toSegments.join("/");
|
|
800
|
-
}
|
|
801
|
-
from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
|
|
802
|
-
}
|
|
803
|
-
let path = resolvePath(to, from);
|
|
804
|
-
let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/");
|
|
805
|
-
let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/");
|
|
806
|
-
if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) {
|
|
807
|
-
path.pathname += "/";
|
|
808
|
-
}
|
|
809
|
-
return path;
|
|
810
|
-
}
|
|
811
|
-
function getToPathname(to) {
|
|
812
|
-
return to === "" || to.pathname === "" ? "/" : typeof to === "string" ? parsePath(to).pathname : to.pathname;
|
|
813
|
-
}
|
|
814
|
-
const joinPaths = (paths) => paths.join("/").replace(/\/\/+/g, "/");
|
|
815
|
-
const normalizePathname = (pathname) => pathname.replace(/\/+$/, "").replace(/^\/*/, "/");
|
|
816
|
-
const normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
|
|
817
|
-
const normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
|
|
818
|
-
const json = function json2(data, init) {
|
|
819
|
-
if (init === void 0) {
|
|
820
|
-
init = {};
|
|
821
|
-
}
|
|
822
|
-
let responseInit = typeof init === "number" ? {
|
|
823
|
-
status: init
|
|
824
|
-
} : init;
|
|
825
|
-
let headers = new Headers(responseInit.headers);
|
|
826
|
-
if (!headers.has("Content-Type")) {
|
|
827
|
-
headers.set("Content-Type", "application/json; charset=utf-8");
|
|
828
|
-
}
|
|
829
|
-
return new Response(JSON.stringify(data), _extends({}, responseInit, {
|
|
830
|
-
headers
|
|
831
|
-
}));
|
|
832
|
-
};
|
|
833
|
-
class AbortedDeferredError extends Error {
|
|
834
|
-
}
|
|
835
|
-
class DeferredData {
|
|
836
|
-
constructor(data, responseInit) {
|
|
837
|
-
this.pendingKeysSet = /* @__PURE__ */ new Set();
|
|
838
|
-
this.subscribers = /* @__PURE__ */ new Set();
|
|
839
|
-
this.deferredKeys = [];
|
|
840
|
-
invariant(data && typeof data === "object" && !Array.isArray(data), "defer() only accepts plain objects");
|
|
841
|
-
let reject;
|
|
842
|
-
this.abortPromise = new Promise((_, r) => reject = r);
|
|
843
|
-
this.controller = new AbortController();
|
|
844
|
-
let onAbort = () => reject(new AbortedDeferredError("Deferred data aborted"));
|
|
845
|
-
this.unlistenAbortSignal = () => this.controller.signal.removeEventListener("abort", onAbort);
|
|
846
|
-
this.controller.signal.addEventListener("abort", onAbort);
|
|
847
|
-
this.data = Object.entries(data).reduce((acc, _ref2) => {
|
|
848
|
-
let [key, value] = _ref2;
|
|
849
|
-
return Object.assign(acc, {
|
|
850
|
-
[key]: this.trackPromise(key, value)
|
|
851
|
-
});
|
|
852
|
-
}, {});
|
|
853
|
-
if (this.done) {
|
|
854
|
-
this.unlistenAbortSignal();
|
|
855
|
-
}
|
|
856
|
-
this.init = responseInit;
|
|
857
|
-
}
|
|
858
|
-
trackPromise(key, value) {
|
|
859
|
-
if (!(value instanceof Promise)) {
|
|
860
|
-
return value;
|
|
861
|
-
}
|
|
862
|
-
this.deferredKeys.push(key);
|
|
863
|
-
this.pendingKeysSet.add(key);
|
|
864
|
-
let promise = Promise.race([value, this.abortPromise]).then((data) => this.onSettle(promise, key, void 0, data), (error) => this.onSettle(promise, key, error));
|
|
865
|
-
promise.catch(() => {
|
|
866
|
-
});
|
|
867
|
-
Object.defineProperty(promise, "_tracked", {
|
|
868
|
-
get: () => true
|
|
869
|
-
});
|
|
870
|
-
return promise;
|
|
871
|
-
}
|
|
872
|
-
onSettle(promise, key, error, data) {
|
|
873
|
-
if (this.controller.signal.aborted && error instanceof AbortedDeferredError) {
|
|
874
|
-
this.unlistenAbortSignal();
|
|
875
|
-
Object.defineProperty(promise, "_error", {
|
|
876
|
-
get: () => error
|
|
877
|
-
});
|
|
878
|
-
return Promise.reject(error);
|
|
879
|
-
}
|
|
880
|
-
this.pendingKeysSet.delete(key);
|
|
881
|
-
if (this.done) {
|
|
882
|
-
this.unlistenAbortSignal();
|
|
883
|
-
}
|
|
884
|
-
if (error === void 0 && data === void 0) {
|
|
885
|
-
let undefinedError = new Error('Deferred data for key "' + key + '" resolved/rejected with `undefined`, you must resolve/reject with a value or `null`.');
|
|
886
|
-
Object.defineProperty(promise, "_error", {
|
|
887
|
-
get: () => undefinedError
|
|
888
|
-
});
|
|
889
|
-
this.emit(false, key);
|
|
890
|
-
return Promise.reject(undefinedError);
|
|
891
|
-
}
|
|
892
|
-
if (data === void 0) {
|
|
893
|
-
Object.defineProperty(promise, "_error", {
|
|
894
|
-
get: () => error
|
|
895
|
-
});
|
|
896
|
-
this.emit(false, key);
|
|
897
|
-
return Promise.reject(error);
|
|
898
|
-
}
|
|
899
|
-
Object.defineProperty(promise, "_data", {
|
|
900
|
-
get: () => data
|
|
901
|
-
});
|
|
902
|
-
this.emit(false, key);
|
|
903
|
-
return data;
|
|
904
|
-
}
|
|
905
|
-
emit(aborted, settledKey) {
|
|
906
|
-
this.subscribers.forEach((subscriber) => subscriber(aborted, settledKey));
|
|
907
|
-
}
|
|
908
|
-
subscribe(fn) {
|
|
909
|
-
this.subscribers.add(fn);
|
|
910
|
-
return () => this.subscribers.delete(fn);
|
|
911
|
-
}
|
|
912
|
-
cancel() {
|
|
913
|
-
this.controller.abort();
|
|
914
|
-
this.pendingKeysSet.forEach((v, k) => this.pendingKeysSet.delete(k));
|
|
915
|
-
this.emit(true);
|
|
916
|
-
}
|
|
917
|
-
async resolveData(signal) {
|
|
918
|
-
let aborted = false;
|
|
919
|
-
if (!this.done) {
|
|
920
|
-
let onAbort = () => this.cancel();
|
|
921
|
-
signal.addEventListener("abort", onAbort);
|
|
922
|
-
aborted = await new Promise((resolve) => {
|
|
923
|
-
this.subscribe((aborted2) => {
|
|
924
|
-
signal.removeEventListener("abort", onAbort);
|
|
925
|
-
if (aborted2 || this.done) {
|
|
926
|
-
resolve(aborted2);
|
|
927
|
-
}
|
|
928
|
-
});
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
return aborted;
|
|
932
|
-
}
|
|
933
|
-
get done() {
|
|
934
|
-
return this.pendingKeysSet.size === 0;
|
|
935
|
-
}
|
|
936
|
-
get unwrappedData() {
|
|
937
|
-
invariant(this.data !== null && this.done, "Can only unwrap data on initialized and settled deferreds");
|
|
938
|
-
return Object.entries(this.data).reduce((acc, _ref3) => {
|
|
939
|
-
let [key, value] = _ref3;
|
|
940
|
-
return Object.assign(acc, {
|
|
941
|
-
[key]: unwrapTrackedPromise(value)
|
|
942
|
-
});
|
|
943
|
-
}, {});
|
|
944
|
-
}
|
|
945
|
-
get pendingKeys() {
|
|
946
|
-
return Array.from(this.pendingKeysSet);
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
function isTrackedPromise(value) {
|
|
950
|
-
return value instanceof Promise && value._tracked === true;
|
|
951
|
-
}
|
|
952
|
-
function unwrapTrackedPromise(value) {
|
|
953
|
-
if (!isTrackedPromise(value)) {
|
|
954
|
-
return value;
|
|
955
|
-
}
|
|
956
|
-
if (value._error) {
|
|
957
|
-
throw value._error;
|
|
958
|
-
}
|
|
959
|
-
return value._data;
|
|
960
|
-
}
|
|
961
|
-
const defer = function defer2(data, init) {
|
|
962
|
-
if (init === void 0) {
|
|
963
|
-
init = {};
|
|
964
|
-
}
|
|
965
|
-
let responseInit = typeof init === "number" ? {
|
|
966
|
-
status: init
|
|
967
|
-
} : init;
|
|
968
|
-
return new DeferredData(data, responseInit);
|
|
969
|
-
};
|
|
970
|
-
const redirect = function redirect2(url, init) {
|
|
971
|
-
if (init === void 0) {
|
|
972
|
-
init = 302;
|
|
973
|
-
}
|
|
974
|
-
let responseInit = init;
|
|
975
|
-
if (typeof responseInit === "number") {
|
|
976
|
-
responseInit = {
|
|
977
|
-
status: responseInit
|
|
978
|
-
};
|
|
979
|
-
} else if (typeof responseInit.status === "undefined") {
|
|
980
|
-
responseInit.status = 302;
|
|
981
|
-
}
|
|
982
|
-
let headers = new Headers(responseInit.headers);
|
|
983
|
-
headers.set("Location", url);
|
|
984
|
-
return new Response(null, _extends({}, responseInit, {
|
|
985
|
-
headers
|
|
986
|
-
}));
|
|
987
|
-
};
|
|
988
|
-
const redirectDocument = (url, init) => {
|
|
989
|
-
let response = redirect(url, init);
|
|
990
|
-
response.headers.set("X-Remix-Reload-Document", "true");
|
|
991
|
-
return response;
|
|
992
|
-
};
|
|
993
|
-
class ErrorResponseImpl {
|
|
994
|
-
constructor(status, statusText, data, internal) {
|
|
995
|
-
if (internal === void 0) {
|
|
996
|
-
internal = false;
|
|
997
|
-
}
|
|
998
|
-
this.status = status;
|
|
999
|
-
this.statusText = statusText || "";
|
|
1000
|
-
this.internal = internal;
|
|
1001
|
-
if (data instanceof Error) {
|
|
1002
|
-
this.data = data.toString();
|
|
1003
|
-
this.error = data;
|
|
1004
|
-
} else {
|
|
1005
|
-
this.data = data;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
function isRouteErrorResponse(error) {
|
|
1010
|
-
return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
|
|
1011
|
-
}
|
|
1012
|
-
const validMutationMethodsArr = ["post", "put", "patch", "delete"];
|
|
1013
|
-
const validMutationMethods = new Set(validMutationMethodsArr);
|
|
1014
|
-
const validRequestMethodsArr = ["get", ...validMutationMethodsArr];
|
|
1015
|
-
const validRequestMethods = new Set(validRequestMethodsArr);
|
|
1016
|
-
const redirectStatusCodes = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
1017
|
-
const redirectPreserveMethodStatusCodes = /* @__PURE__ */ new Set([307, 308]);
|
|
1018
|
-
const IDLE_NAVIGATION = {
|
|
1019
|
-
state: "idle",
|
|
1020
|
-
location: void 0,
|
|
1021
|
-
formMethod: void 0,
|
|
1022
|
-
formAction: void 0,
|
|
1023
|
-
formEncType: void 0,
|
|
1024
|
-
formData: void 0,
|
|
1025
|
-
json: void 0,
|
|
1026
|
-
text: void 0
|
|
1027
|
-
};
|
|
1028
|
-
const IDLE_FETCHER = {
|
|
1029
|
-
state: "idle",
|
|
1030
|
-
data: void 0,
|
|
1031
|
-
formMethod: void 0,
|
|
1032
|
-
formAction: void 0,
|
|
1033
|
-
formEncType: void 0,
|
|
1034
|
-
formData: void 0,
|
|
1035
|
-
json: void 0,
|
|
1036
|
-
text: void 0
|
|
1037
|
-
};
|
|
1038
|
-
const IDLE_BLOCKER = {
|
|
1039
|
-
state: "unblocked",
|
|
1040
|
-
proceed: void 0,
|
|
1041
|
-
reset: void 0,
|
|
1042
|
-
location: void 0
|
|
1043
|
-
};
|
|
1044
|
-
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
|
1045
|
-
const defaultMapRouteProperties = (route) => ({
|
|
1046
|
-
hasErrorBoundary: Boolean(route.hasErrorBoundary)
|
|
1047
|
-
});
|
|
1048
|
-
const TRANSITIONS_STORAGE_KEY = "remix-router-transitions";
|
|
1049
|
-
function createRouter(init) {
|
|
1050
|
-
const routerWindow = init.window ? init.window : typeof window !== "undefined" ? window : void 0;
|
|
1051
|
-
const isBrowser = typeof routerWindow !== "undefined" && typeof routerWindow.document !== "undefined" && typeof routerWindow.document.createElement !== "undefined";
|
|
1052
|
-
const isServer = !isBrowser;
|
|
1053
|
-
invariant(init.routes.length > 0, "You must provide a non-empty routes array to createRouter");
|
|
1054
|
-
let mapRouteProperties;
|
|
1055
|
-
if (init.mapRouteProperties) {
|
|
1056
|
-
mapRouteProperties = init.mapRouteProperties;
|
|
1057
|
-
} else if (init.detectErrorBoundary) {
|
|
1058
|
-
let detectErrorBoundary = init.detectErrorBoundary;
|
|
1059
|
-
mapRouteProperties = (route) => ({
|
|
1060
|
-
hasErrorBoundary: detectErrorBoundary(route)
|
|
1061
|
-
});
|
|
1062
|
-
} else {
|
|
1063
|
-
mapRouteProperties = defaultMapRouteProperties;
|
|
1064
|
-
}
|
|
1065
|
-
let manifest = {};
|
|
1066
|
-
let dataRoutes = convertRoutesToDataRoutes(init.routes, mapRouteProperties, void 0, manifest);
|
|
1067
|
-
let inFlightDataRoutes;
|
|
1068
|
-
let basename = init.basename || "/";
|
|
1069
|
-
let dataStrategyImpl = init.unstable_dataStrategy || defaultDataStrategy;
|
|
1070
|
-
let patchRoutesOnMissImpl = init.unstable_patchRoutesOnMiss;
|
|
1071
|
-
let future = _extends({
|
|
1072
|
-
v7_fetcherPersist: false,
|
|
1073
|
-
v7_normalizeFormMethod: false,
|
|
1074
|
-
v7_partialHydration: false,
|
|
1075
|
-
v7_prependBasename: false,
|
|
1076
|
-
v7_relativeSplatPath: false,
|
|
1077
|
-
unstable_skipActionErrorRevalidation: false
|
|
1078
|
-
}, init.future);
|
|
1079
|
-
let unlistenHistory = null;
|
|
1080
|
-
let subscribers = /* @__PURE__ */ new Set();
|
|
1081
|
-
let savedScrollPositions = null;
|
|
1082
|
-
let getScrollRestorationKey = null;
|
|
1083
|
-
let getScrollPosition = null;
|
|
1084
|
-
let initialScrollRestored = init.hydrationData != null;
|
|
1085
|
-
let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
|
|
1086
|
-
let initialErrors = null;
|
|
1087
|
-
if (initialMatches == null && !patchRoutesOnMissImpl) {
|
|
1088
|
-
let error = getInternalRouterError(404, {
|
|
1089
|
-
pathname: init.history.location.pathname
|
|
1090
|
-
});
|
|
1091
|
-
let {
|
|
1092
|
-
matches,
|
|
1093
|
-
route
|
|
1094
|
-
} = getShortCircuitMatches(dataRoutes);
|
|
1095
|
-
initialMatches = matches;
|
|
1096
|
-
initialErrors = {
|
|
1097
|
-
[route.id]: error
|
|
1098
|
-
};
|
|
1099
|
-
}
|
|
1100
|
-
if (initialMatches && patchRoutesOnMissImpl) {
|
|
1101
|
-
let fogOfWar = checkFogOfWar(initialMatches, dataRoutes, init.history.location.pathname);
|
|
1102
|
-
if (fogOfWar.active) {
|
|
1103
|
-
initialMatches = null;
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
let initialized;
|
|
1107
|
-
if (!initialMatches) {
|
|
1108
|
-
initialized = false;
|
|
1109
|
-
initialMatches = [];
|
|
1110
|
-
} else if (initialMatches.some((m) => m.route.lazy)) {
|
|
1111
|
-
initialized = false;
|
|
1112
|
-
} else if (!initialMatches.some((m) => m.route.loader)) {
|
|
1113
|
-
initialized = true;
|
|
1114
|
-
} else if (future.v7_partialHydration) {
|
|
1115
|
-
let loaderData = init.hydrationData ? init.hydrationData.loaderData : null;
|
|
1116
|
-
let errors = init.hydrationData ? init.hydrationData.errors : null;
|
|
1117
|
-
let isRouteInitialized = (m) => {
|
|
1118
|
-
if (!m.route.loader) {
|
|
1119
|
-
return true;
|
|
1120
|
-
}
|
|
1121
|
-
if (typeof m.route.loader === "function" && m.route.loader.hydrate === true) {
|
|
1122
|
-
return false;
|
|
1123
|
-
}
|
|
1124
|
-
return loaderData && loaderData[m.route.id] !== void 0 || errors && errors[m.route.id] !== void 0;
|
|
1125
|
-
};
|
|
1126
|
-
if (errors) {
|
|
1127
|
-
let idx = initialMatches.findIndex((m) => errors[m.route.id] !== void 0);
|
|
1128
|
-
initialized = initialMatches.slice(0, idx + 1).every(isRouteInitialized);
|
|
1129
|
-
} else {
|
|
1130
|
-
initialized = initialMatches.every(isRouteInitialized);
|
|
1131
|
-
}
|
|
1132
|
-
} else {
|
|
1133
|
-
initialized = init.hydrationData != null;
|
|
1134
|
-
}
|
|
1135
|
-
let router2;
|
|
1136
|
-
let state = {
|
|
1137
|
-
historyAction: init.history.action,
|
|
1138
|
-
location: init.history.location,
|
|
1139
|
-
matches: initialMatches,
|
|
1140
|
-
initialized,
|
|
1141
|
-
navigation: IDLE_NAVIGATION,
|
|
1142
|
-
// Don't restore on initial updateState() if we were SSR'd
|
|
1143
|
-
restoreScrollPosition: init.hydrationData != null ? false : null,
|
|
1144
|
-
preventScrollReset: false,
|
|
1145
|
-
revalidation: "idle",
|
|
1146
|
-
loaderData: init.hydrationData && init.hydrationData.loaderData || {},
|
|
1147
|
-
actionData: init.hydrationData && init.hydrationData.actionData || null,
|
|
1148
|
-
errors: init.hydrationData && init.hydrationData.errors || initialErrors,
|
|
1149
|
-
fetchers: /* @__PURE__ */ new Map(),
|
|
1150
|
-
blockers: /* @__PURE__ */ new Map()
|
|
1151
|
-
};
|
|
1152
|
-
let pendingAction = Action.Pop;
|
|
1153
|
-
let pendingPreventScrollReset = false;
|
|
1154
|
-
let pendingNavigationController;
|
|
1155
|
-
let pendingViewTransitionEnabled = false;
|
|
1156
|
-
let appliedViewTransitions = /* @__PURE__ */ new Map();
|
|
1157
|
-
let removePageHideEventListener = null;
|
|
1158
|
-
let isUninterruptedRevalidation = false;
|
|
1159
|
-
let isRevalidationRequired = false;
|
|
1160
|
-
let cancelledDeferredRoutes = [];
|
|
1161
|
-
let cancelledFetcherLoads = [];
|
|
1162
|
-
let fetchControllers = /* @__PURE__ */ new Map();
|
|
1163
|
-
let incrementingLoadId = 0;
|
|
1164
|
-
let pendingNavigationLoadId = -1;
|
|
1165
|
-
let fetchReloadIds = /* @__PURE__ */ new Map();
|
|
1166
|
-
let fetchRedirectIds = /* @__PURE__ */ new Set();
|
|
1167
|
-
let fetchLoadMatches = /* @__PURE__ */ new Map();
|
|
1168
|
-
let activeFetchers = /* @__PURE__ */ new Map();
|
|
1169
|
-
let deletedFetchers = /* @__PURE__ */ new Set();
|
|
1170
|
-
let activeDeferreds = /* @__PURE__ */ new Map();
|
|
1171
|
-
let blockerFunctions = /* @__PURE__ */ new Map();
|
|
1172
|
-
let pendingPatchRoutes = /* @__PURE__ */ new Map();
|
|
1173
|
-
let ignoreNextHistoryUpdate = false;
|
|
1174
|
-
function initialize() {
|
|
1175
|
-
unlistenHistory = init.history.listen((_ref) => {
|
|
1176
|
-
let {
|
|
1177
|
-
action: historyAction,
|
|
1178
|
-
location,
|
|
1179
|
-
delta
|
|
1180
|
-
} = _ref;
|
|
1181
|
-
if (ignoreNextHistoryUpdate) {
|
|
1182
|
-
ignoreNextHistoryUpdate = false;
|
|
1183
|
-
return;
|
|
1184
|
-
}
|
|
1185
|
-
warning(blockerFunctions.size === 0 || delta != null, "You are trying to use a blocker on a POP navigation to a location that was not created by @remix-run/router. This will fail silently in production. This can happen if you are navigating outside the router via `window.history.pushState`/`window.location.hash` instead of using router navigation APIs. This can also happen if you are using createHashRouter and the user manually changes the URL.");
|
|
1186
|
-
let blockerKey = shouldBlockNavigation({
|
|
1187
|
-
currentLocation: state.location,
|
|
1188
|
-
nextLocation: location,
|
|
1189
|
-
historyAction
|
|
1190
|
-
});
|
|
1191
|
-
if (blockerKey && delta != null) {
|
|
1192
|
-
ignoreNextHistoryUpdate = true;
|
|
1193
|
-
init.history.go(delta * -1);
|
|
1194
|
-
updateBlocker(blockerKey, {
|
|
1195
|
-
state: "blocked",
|
|
1196
|
-
location,
|
|
1197
|
-
proceed() {
|
|
1198
|
-
updateBlocker(blockerKey, {
|
|
1199
|
-
state: "proceeding",
|
|
1200
|
-
proceed: void 0,
|
|
1201
|
-
reset: void 0,
|
|
1202
|
-
location
|
|
1203
|
-
});
|
|
1204
|
-
init.history.go(delta);
|
|
1205
|
-
},
|
|
1206
|
-
reset() {
|
|
1207
|
-
let blockers = new Map(state.blockers);
|
|
1208
|
-
blockers.set(blockerKey, IDLE_BLOCKER);
|
|
1209
|
-
updateState({
|
|
1210
|
-
blockers
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
});
|
|
1214
|
-
return;
|
|
1215
|
-
}
|
|
1216
|
-
return startNavigation(historyAction, location);
|
|
1217
|
-
});
|
|
1218
|
-
if (isBrowser) {
|
|
1219
|
-
restoreAppliedTransitions(routerWindow, appliedViewTransitions);
|
|
1220
|
-
let _saveAppliedTransitions = () => persistAppliedTransitions(routerWindow, appliedViewTransitions);
|
|
1221
|
-
routerWindow.addEventListener("pagehide", _saveAppliedTransitions);
|
|
1222
|
-
removePageHideEventListener = () => routerWindow.removeEventListener("pagehide", _saveAppliedTransitions);
|
|
1223
|
-
}
|
|
1224
|
-
if (!state.initialized) {
|
|
1225
|
-
startNavigation(Action.Pop, state.location, {
|
|
1226
|
-
initialHydration: true
|
|
1227
|
-
});
|
|
1228
|
-
}
|
|
1229
|
-
return router2;
|
|
1230
|
-
}
|
|
1231
|
-
function dispose() {
|
|
1232
|
-
if (unlistenHistory) {
|
|
1233
|
-
unlistenHistory();
|
|
1234
|
-
}
|
|
1235
|
-
if (removePageHideEventListener) {
|
|
1236
|
-
removePageHideEventListener();
|
|
1237
|
-
}
|
|
1238
|
-
subscribers.clear();
|
|
1239
|
-
pendingNavigationController && pendingNavigationController.abort();
|
|
1240
|
-
state.fetchers.forEach((_, key) => deleteFetcher(key));
|
|
1241
|
-
state.blockers.forEach((_, key) => deleteBlocker(key));
|
|
1242
|
-
}
|
|
1243
|
-
function subscribe(fn) {
|
|
1244
|
-
subscribers.add(fn);
|
|
1245
|
-
return () => subscribers.delete(fn);
|
|
1246
|
-
}
|
|
1247
|
-
function updateState(newState, opts) {
|
|
1248
|
-
if (opts === void 0) {
|
|
1249
|
-
opts = {};
|
|
1250
|
-
}
|
|
1251
|
-
state = _extends({}, state, newState);
|
|
1252
|
-
let completedFetchers = [];
|
|
1253
|
-
let deletedFetchersKeys = [];
|
|
1254
|
-
if (future.v7_fetcherPersist) {
|
|
1255
|
-
state.fetchers.forEach((fetcher, key) => {
|
|
1256
|
-
if (fetcher.state === "idle") {
|
|
1257
|
-
if (deletedFetchers.has(key)) {
|
|
1258
|
-
deletedFetchersKeys.push(key);
|
|
1259
|
-
} else {
|
|
1260
|
-
completedFetchers.push(key);
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
[...subscribers].forEach((subscriber) => subscriber(state, {
|
|
1266
|
-
deletedFetchers: deletedFetchersKeys,
|
|
1267
|
-
unstable_viewTransitionOpts: opts.viewTransitionOpts,
|
|
1268
|
-
unstable_flushSync: opts.flushSync === true
|
|
1269
|
-
}));
|
|
1270
|
-
if (future.v7_fetcherPersist) {
|
|
1271
|
-
completedFetchers.forEach((key) => state.fetchers.delete(key));
|
|
1272
|
-
deletedFetchersKeys.forEach((key) => deleteFetcher(key));
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
function completeNavigation(location, newState, _temp) {
|
|
1276
|
-
var _location$state, _location$state2;
|
|
1277
|
-
let {
|
|
1278
|
-
flushSync
|
|
1279
|
-
} = _temp === void 0 ? {} : _temp;
|
|
1280
|
-
let isActionReload = state.actionData != null && state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && state.navigation.state === "loading" && ((_location$state = location.state) == null ? void 0 : _location$state._isRedirect) !== true;
|
|
1281
|
-
let actionData;
|
|
1282
|
-
if (newState.actionData) {
|
|
1283
|
-
if (Object.keys(newState.actionData).length > 0) {
|
|
1284
|
-
actionData = newState.actionData;
|
|
1285
|
-
} else {
|
|
1286
|
-
actionData = null;
|
|
1287
|
-
}
|
|
1288
|
-
} else if (isActionReload) {
|
|
1289
|
-
actionData = state.actionData;
|
|
1290
|
-
} else {
|
|
1291
|
-
actionData = null;
|
|
1292
|
-
}
|
|
1293
|
-
let loaderData = newState.loaderData ? mergeLoaderData(state.loaderData, newState.loaderData, newState.matches || [], newState.errors) : state.loaderData;
|
|
1294
|
-
let blockers = state.blockers;
|
|
1295
|
-
if (blockers.size > 0) {
|
|
1296
|
-
blockers = new Map(blockers);
|
|
1297
|
-
blockers.forEach((_, k) => blockers.set(k, IDLE_BLOCKER));
|
|
1298
|
-
}
|
|
1299
|
-
let preventScrollReset = pendingPreventScrollReset === true || state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && ((_location$state2 = location.state) == null ? void 0 : _location$state2._isRedirect) !== true;
|
|
1300
|
-
if (inFlightDataRoutes) {
|
|
1301
|
-
dataRoutes = inFlightDataRoutes;
|
|
1302
|
-
inFlightDataRoutes = void 0;
|
|
1303
|
-
}
|
|
1304
|
-
if (isUninterruptedRevalidation) ;
|
|
1305
|
-
else if (pendingAction === Action.Pop) ;
|
|
1306
|
-
else if (pendingAction === Action.Push) {
|
|
1307
|
-
init.history.push(location, location.state);
|
|
1308
|
-
} else if (pendingAction === Action.Replace) {
|
|
1309
|
-
init.history.replace(location, location.state);
|
|
1310
|
-
}
|
|
1311
|
-
let viewTransitionOpts;
|
|
1312
|
-
if (pendingAction === Action.Pop) {
|
|
1313
|
-
let priorPaths = appliedViewTransitions.get(state.location.pathname);
|
|
1314
|
-
if (priorPaths && priorPaths.has(location.pathname)) {
|
|
1315
|
-
viewTransitionOpts = {
|
|
1316
|
-
currentLocation: state.location,
|
|
1317
|
-
nextLocation: location
|
|
1318
|
-
};
|
|
1319
|
-
} else if (appliedViewTransitions.has(location.pathname)) {
|
|
1320
|
-
viewTransitionOpts = {
|
|
1321
|
-
currentLocation: location,
|
|
1322
|
-
nextLocation: state.location
|
|
1323
|
-
};
|
|
1324
|
-
}
|
|
1325
|
-
} else if (pendingViewTransitionEnabled) {
|
|
1326
|
-
let toPaths = appliedViewTransitions.get(state.location.pathname);
|
|
1327
|
-
if (toPaths) {
|
|
1328
|
-
toPaths.add(location.pathname);
|
|
1329
|
-
} else {
|
|
1330
|
-
toPaths = /* @__PURE__ */ new Set([location.pathname]);
|
|
1331
|
-
appliedViewTransitions.set(state.location.pathname, toPaths);
|
|
1332
|
-
}
|
|
1333
|
-
viewTransitionOpts = {
|
|
1334
|
-
currentLocation: state.location,
|
|
1335
|
-
nextLocation: location
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
|
-
updateState(_extends({}, newState, {
|
|
1339
|
-
actionData,
|
|
1340
|
-
loaderData,
|
|
1341
|
-
historyAction: pendingAction,
|
|
1342
|
-
location,
|
|
1343
|
-
initialized: true,
|
|
1344
|
-
navigation: IDLE_NAVIGATION,
|
|
1345
|
-
revalidation: "idle",
|
|
1346
|
-
restoreScrollPosition: getSavedScrollPosition(location, newState.matches || state.matches),
|
|
1347
|
-
preventScrollReset,
|
|
1348
|
-
blockers
|
|
1349
|
-
}), {
|
|
1350
|
-
viewTransitionOpts,
|
|
1351
|
-
flushSync: flushSync === true
|
|
1352
|
-
});
|
|
1353
|
-
pendingAction = Action.Pop;
|
|
1354
|
-
pendingPreventScrollReset = false;
|
|
1355
|
-
pendingViewTransitionEnabled = false;
|
|
1356
|
-
isUninterruptedRevalidation = false;
|
|
1357
|
-
isRevalidationRequired = false;
|
|
1358
|
-
cancelledDeferredRoutes = [];
|
|
1359
|
-
cancelledFetcherLoads = [];
|
|
1360
|
-
}
|
|
1361
|
-
async function navigate(to, opts) {
|
|
1362
|
-
if (typeof to === "number") {
|
|
1363
|
-
init.history.go(to);
|
|
1364
|
-
return;
|
|
1365
|
-
}
|
|
1366
|
-
let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, to, future.v7_relativeSplatPath, opts == null ? void 0 : opts.fromRouteId, opts == null ? void 0 : opts.relative);
|
|
1367
|
-
let {
|
|
1368
|
-
path,
|
|
1369
|
-
submission,
|
|
1370
|
-
error
|
|
1371
|
-
} = normalizeNavigateOptions(future.v7_normalizeFormMethod, false, normalizedPath, opts);
|
|
1372
|
-
let currentLocation = state.location;
|
|
1373
|
-
let nextLocation = createLocation(state.location, path, opts && opts.state);
|
|
1374
|
-
nextLocation = _extends({}, nextLocation, init.history.encodeLocation(nextLocation));
|
|
1375
|
-
let userReplace = opts && opts.replace != null ? opts.replace : void 0;
|
|
1376
|
-
let historyAction = Action.Push;
|
|
1377
|
-
if (userReplace === true) {
|
|
1378
|
-
historyAction = Action.Replace;
|
|
1379
|
-
} else if (userReplace === false) ;
|
|
1380
|
-
else if (submission != null && isMutationMethod(submission.formMethod) && submission.formAction === state.location.pathname + state.location.search) {
|
|
1381
|
-
historyAction = Action.Replace;
|
|
1382
|
-
}
|
|
1383
|
-
let preventScrollReset = opts && "preventScrollReset" in opts ? opts.preventScrollReset === true : void 0;
|
|
1384
|
-
let flushSync = (opts && opts.unstable_flushSync) === true;
|
|
1385
|
-
let blockerKey = shouldBlockNavigation({
|
|
1386
|
-
currentLocation,
|
|
1387
|
-
nextLocation,
|
|
1388
|
-
historyAction
|
|
1389
|
-
});
|
|
1390
|
-
if (blockerKey) {
|
|
1391
|
-
updateBlocker(blockerKey, {
|
|
1392
|
-
state: "blocked",
|
|
1393
|
-
location: nextLocation,
|
|
1394
|
-
proceed() {
|
|
1395
|
-
updateBlocker(blockerKey, {
|
|
1396
|
-
state: "proceeding",
|
|
1397
|
-
proceed: void 0,
|
|
1398
|
-
reset: void 0,
|
|
1399
|
-
location: nextLocation
|
|
1400
|
-
});
|
|
1401
|
-
navigate(to, opts);
|
|
1402
|
-
},
|
|
1403
|
-
reset() {
|
|
1404
|
-
let blockers = new Map(state.blockers);
|
|
1405
|
-
blockers.set(blockerKey, IDLE_BLOCKER);
|
|
1406
|
-
updateState({
|
|
1407
|
-
blockers
|
|
1408
|
-
});
|
|
1409
|
-
}
|
|
1410
|
-
});
|
|
1411
|
-
return;
|
|
1412
|
-
}
|
|
1413
|
-
return await startNavigation(historyAction, nextLocation, {
|
|
1414
|
-
submission,
|
|
1415
|
-
// Send through the formData serialization error if we have one so we can
|
|
1416
|
-
// render at the right error boundary after we match routes
|
|
1417
|
-
pendingError: error,
|
|
1418
|
-
preventScrollReset,
|
|
1419
|
-
replace: opts && opts.replace,
|
|
1420
|
-
enableViewTransition: opts && opts.unstable_viewTransition,
|
|
1421
|
-
flushSync
|
|
1422
|
-
});
|
|
1423
|
-
}
|
|
1424
|
-
function revalidate() {
|
|
1425
|
-
interruptActiveLoads();
|
|
1426
|
-
updateState({
|
|
1427
|
-
revalidation: "loading"
|
|
1428
|
-
});
|
|
1429
|
-
if (state.navigation.state === "submitting") {
|
|
1430
|
-
return;
|
|
1431
|
-
}
|
|
1432
|
-
if (state.navigation.state === "idle") {
|
|
1433
|
-
startNavigation(state.historyAction, state.location, {
|
|
1434
|
-
startUninterruptedRevalidation: true
|
|
1435
|
-
});
|
|
1436
|
-
return;
|
|
1437
|
-
}
|
|
1438
|
-
startNavigation(pendingAction || state.historyAction, state.navigation.location, {
|
|
1439
|
-
overrideNavigation: state.navigation
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
async function startNavigation(historyAction, location, opts) {
|
|
1443
|
-
pendingNavigationController && pendingNavigationController.abort();
|
|
1444
|
-
pendingNavigationController = null;
|
|
1445
|
-
pendingAction = historyAction;
|
|
1446
|
-
isUninterruptedRevalidation = (opts && opts.startUninterruptedRevalidation) === true;
|
|
1447
|
-
saveScrollPosition(state.location, state.matches);
|
|
1448
|
-
pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1449
|
-
pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
|
|
1450
|
-
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
1451
|
-
let loadingNavigation = opts && opts.overrideNavigation;
|
|
1452
|
-
let matches = matchRoutes(routesToUse, location, basename);
|
|
1453
|
-
let flushSync = (opts && opts.flushSync) === true;
|
|
1454
|
-
let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
|
|
1455
|
-
if (fogOfWar.active && fogOfWar.matches) {
|
|
1456
|
-
matches = fogOfWar.matches;
|
|
1457
|
-
}
|
|
1458
|
-
if (!matches) {
|
|
1459
|
-
let {
|
|
1460
|
-
error,
|
|
1461
|
-
notFoundMatches,
|
|
1462
|
-
route
|
|
1463
|
-
} = handleNavigational404(location.pathname);
|
|
1464
|
-
completeNavigation(location, {
|
|
1465
|
-
matches: notFoundMatches,
|
|
1466
|
-
loaderData: {},
|
|
1467
|
-
errors: {
|
|
1468
|
-
[route.id]: error
|
|
1469
|
-
}
|
|
1470
|
-
}, {
|
|
1471
|
-
flushSync
|
|
1472
|
-
});
|
|
1473
|
-
return;
|
|
1474
|
-
}
|
|
1475
|
-
if (state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
|
|
1476
|
-
completeNavigation(location, {
|
|
1477
|
-
matches
|
|
1478
|
-
}, {
|
|
1479
|
-
flushSync
|
|
1480
|
-
});
|
|
1481
|
-
return;
|
|
1482
|
-
}
|
|
1483
|
-
pendingNavigationController = new AbortController();
|
|
1484
|
-
let request = createClientSideRequest(init.history, location, pendingNavigationController.signal, opts && opts.submission);
|
|
1485
|
-
let pendingActionResult;
|
|
1486
|
-
if (opts && opts.pendingError) {
|
|
1487
|
-
pendingActionResult = [findNearestBoundary(matches).route.id, {
|
|
1488
|
-
type: ResultType.error,
|
|
1489
|
-
error: opts.pendingError
|
|
1490
|
-
}];
|
|
1491
|
-
} else if (opts && opts.submission && isMutationMethod(opts.submission.formMethod)) {
|
|
1492
|
-
let actionResult = await handleAction(request, location, opts.submission, matches, fogOfWar.active, {
|
|
1493
|
-
replace: opts.replace,
|
|
1494
|
-
flushSync
|
|
1495
|
-
});
|
|
1496
|
-
if (actionResult.shortCircuited) {
|
|
1497
|
-
return;
|
|
1498
|
-
}
|
|
1499
|
-
if (actionResult.pendingActionResult) {
|
|
1500
|
-
let [routeId, result] = actionResult.pendingActionResult;
|
|
1501
|
-
if (isErrorResult(result) && isRouteErrorResponse(result.error) && result.error.status === 404) {
|
|
1502
|
-
pendingNavigationController = null;
|
|
1503
|
-
completeNavigation(location, {
|
|
1504
|
-
matches: actionResult.matches,
|
|
1505
|
-
loaderData: {},
|
|
1506
|
-
errors: {
|
|
1507
|
-
[routeId]: result.error
|
|
1508
|
-
}
|
|
1509
|
-
});
|
|
1510
|
-
return;
|
|
1511
|
-
}
|
|
1512
|
-
}
|
|
1513
|
-
matches = actionResult.matches || matches;
|
|
1514
|
-
pendingActionResult = actionResult.pendingActionResult;
|
|
1515
|
-
loadingNavigation = getLoadingNavigation(location, opts.submission);
|
|
1516
|
-
flushSync = false;
|
|
1517
|
-
fogOfWar.active = false;
|
|
1518
|
-
request = createClientSideRequest(init.history, request.url, request.signal);
|
|
1519
|
-
}
|
|
1520
|
-
let {
|
|
1521
|
-
shortCircuited,
|
|
1522
|
-
matches: updatedMatches,
|
|
1523
|
-
loaderData,
|
|
1524
|
-
errors
|
|
1525
|
-
} = await handleLoaders(request, location, matches, fogOfWar.active, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, opts && opts.initialHydration === true, flushSync, pendingActionResult);
|
|
1526
|
-
if (shortCircuited) {
|
|
1527
|
-
return;
|
|
1528
|
-
}
|
|
1529
|
-
pendingNavigationController = null;
|
|
1530
|
-
completeNavigation(location, _extends({
|
|
1531
|
-
matches: updatedMatches || matches
|
|
1532
|
-
}, getActionDataForCommit(pendingActionResult), {
|
|
1533
|
-
loaderData,
|
|
1534
|
-
errors
|
|
1535
|
-
}));
|
|
1536
|
-
}
|
|
1537
|
-
async function handleAction(request, location, submission, matches, isFogOfWar, opts) {
|
|
1538
|
-
if (opts === void 0) {
|
|
1539
|
-
opts = {};
|
|
1540
|
-
}
|
|
1541
|
-
interruptActiveLoads();
|
|
1542
|
-
let navigation = getSubmittingNavigation(location, submission);
|
|
1543
|
-
updateState({
|
|
1544
|
-
navigation
|
|
1545
|
-
}, {
|
|
1546
|
-
flushSync: opts.flushSync === true
|
|
1547
|
-
});
|
|
1548
|
-
if (isFogOfWar) {
|
|
1549
|
-
let discoverResult = await discoverRoutes(matches, location.pathname, request.signal);
|
|
1550
|
-
if (discoverResult.type === "aborted") {
|
|
1551
|
-
return {
|
|
1552
|
-
shortCircuited: true
|
|
1553
|
-
};
|
|
1554
|
-
} else if (discoverResult.type === "error") {
|
|
1555
|
-
let {
|
|
1556
|
-
error,
|
|
1557
|
-
notFoundMatches,
|
|
1558
|
-
route
|
|
1559
|
-
} = handleDiscoverRouteError(location.pathname, discoverResult);
|
|
1560
|
-
return {
|
|
1561
|
-
matches: notFoundMatches,
|
|
1562
|
-
pendingActionResult: [route.id, {
|
|
1563
|
-
type: ResultType.error,
|
|
1564
|
-
error
|
|
1565
|
-
}]
|
|
1566
|
-
};
|
|
1567
|
-
} else if (!discoverResult.matches) {
|
|
1568
|
-
let {
|
|
1569
|
-
notFoundMatches,
|
|
1570
|
-
error,
|
|
1571
|
-
route
|
|
1572
|
-
} = handleNavigational404(location.pathname);
|
|
1573
|
-
return {
|
|
1574
|
-
matches: notFoundMatches,
|
|
1575
|
-
pendingActionResult: [route.id, {
|
|
1576
|
-
type: ResultType.error,
|
|
1577
|
-
error
|
|
1578
|
-
}]
|
|
1579
|
-
};
|
|
1580
|
-
} else {
|
|
1581
|
-
matches = discoverResult.matches;
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
let result;
|
|
1585
|
-
let actionMatch = getTargetMatch(matches, location);
|
|
1586
|
-
if (!actionMatch.route.action && !actionMatch.route.lazy) {
|
|
1587
|
-
result = {
|
|
1588
|
-
type: ResultType.error,
|
|
1589
|
-
error: getInternalRouterError(405, {
|
|
1590
|
-
method: request.method,
|
|
1591
|
-
pathname: location.pathname,
|
|
1592
|
-
routeId: actionMatch.route.id
|
|
1593
|
-
})
|
|
1594
|
-
};
|
|
1595
|
-
} else {
|
|
1596
|
-
let results = await callDataStrategy("action", request, [actionMatch], matches);
|
|
1597
|
-
result = results[0];
|
|
1598
|
-
if (request.signal.aborted) {
|
|
1599
|
-
return {
|
|
1600
|
-
shortCircuited: true
|
|
1601
|
-
};
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
if (isRedirectResult(result)) {
|
|
1605
|
-
let replace;
|
|
1606
|
-
if (opts && opts.replace != null) {
|
|
1607
|
-
replace = opts.replace;
|
|
1608
|
-
} else {
|
|
1609
|
-
let location2 = normalizeRedirectLocation(result.response.headers.get("Location"), new URL(request.url), basename);
|
|
1610
|
-
replace = location2 === state.location.pathname + state.location.search;
|
|
1611
|
-
}
|
|
1612
|
-
await startRedirectNavigation(request, result, {
|
|
1613
|
-
submission,
|
|
1614
|
-
replace
|
|
1615
|
-
});
|
|
1616
|
-
return {
|
|
1617
|
-
shortCircuited: true
|
|
1618
|
-
};
|
|
1619
|
-
}
|
|
1620
|
-
if (isDeferredResult(result)) {
|
|
1621
|
-
throw getInternalRouterError(400, {
|
|
1622
|
-
type: "defer-action"
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
if (isErrorResult(result)) {
|
|
1626
|
-
let boundaryMatch = findNearestBoundary(matches, actionMatch.route.id);
|
|
1627
|
-
if ((opts && opts.replace) !== true) {
|
|
1628
|
-
pendingAction = Action.Push;
|
|
1629
|
-
}
|
|
1630
|
-
return {
|
|
1631
|
-
matches,
|
|
1632
|
-
pendingActionResult: [boundaryMatch.route.id, result]
|
|
1633
|
-
};
|
|
1634
|
-
}
|
|
1635
|
-
return {
|
|
1636
|
-
matches,
|
|
1637
|
-
pendingActionResult: [actionMatch.route.id, result]
|
|
1638
|
-
};
|
|
1639
|
-
}
|
|
1640
|
-
async function handleLoaders(request, location, matches, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace, initialHydration, flushSync, pendingActionResult) {
|
|
1641
|
-
let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
|
|
1642
|
-
let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
|
|
1643
|
-
let shouldUpdateNavigationState = !isUninterruptedRevalidation && (!future.v7_partialHydration || !initialHydration);
|
|
1644
|
-
if (isFogOfWar) {
|
|
1645
|
-
if (shouldUpdateNavigationState) {
|
|
1646
|
-
let actionData = getUpdatedActionData(pendingActionResult);
|
|
1647
|
-
updateState(_extends({
|
|
1648
|
-
navigation: loadingNavigation
|
|
1649
|
-
}, actionData !== void 0 ? {
|
|
1650
|
-
actionData
|
|
1651
|
-
} : {}), {
|
|
1652
|
-
flushSync
|
|
1653
|
-
});
|
|
1654
|
-
}
|
|
1655
|
-
let discoverResult = await discoverRoutes(matches, location.pathname, request.signal);
|
|
1656
|
-
if (discoverResult.type === "aborted") {
|
|
1657
|
-
return {
|
|
1658
|
-
shortCircuited: true
|
|
1659
|
-
};
|
|
1660
|
-
} else if (discoverResult.type === "error") {
|
|
1661
|
-
let {
|
|
1662
|
-
error,
|
|
1663
|
-
notFoundMatches,
|
|
1664
|
-
route
|
|
1665
|
-
} = handleDiscoverRouteError(location.pathname, discoverResult);
|
|
1666
|
-
return {
|
|
1667
|
-
matches: notFoundMatches,
|
|
1668
|
-
loaderData: {},
|
|
1669
|
-
errors: {
|
|
1670
|
-
[route.id]: error
|
|
1671
|
-
}
|
|
1672
|
-
};
|
|
1673
|
-
} else if (!discoverResult.matches) {
|
|
1674
|
-
let {
|
|
1675
|
-
error,
|
|
1676
|
-
notFoundMatches,
|
|
1677
|
-
route
|
|
1678
|
-
} = handleNavigational404(location.pathname);
|
|
1679
|
-
return {
|
|
1680
|
-
matches: notFoundMatches,
|
|
1681
|
-
loaderData: {},
|
|
1682
|
-
errors: {
|
|
1683
|
-
[route.id]: error
|
|
1684
|
-
}
|
|
1685
|
-
};
|
|
1686
|
-
} else {
|
|
1687
|
-
matches = discoverResult.matches;
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
1691
|
-
let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, activeSubmission, location, future.v7_partialHydration && initialHydration === true, future.unstable_skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult);
|
|
1692
|
-
cancelActiveDeferreds((routeId) => !(matches && matches.some((m) => m.route.id === routeId)) || matchesToLoad && matchesToLoad.some((m) => m.route.id === routeId));
|
|
1693
|
-
pendingNavigationLoadId = ++incrementingLoadId;
|
|
1694
|
-
if (matchesToLoad.length === 0 && revalidatingFetchers.length === 0) {
|
|
1695
|
-
let updatedFetchers2 = markFetchRedirectsDone();
|
|
1696
|
-
completeNavigation(location, _extends({
|
|
1697
|
-
matches,
|
|
1698
|
-
loaderData: {},
|
|
1699
|
-
// Commit pending error if we're short circuiting
|
|
1700
|
-
errors: pendingActionResult && isErrorResult(pendingActionResult[1]) ? {
|
|
1701
|
-
[pendingActionResult[0]]: pendingActionResult[1].error
|
|
1702
|
-
} : null
|
|
1703
|
-
}, getActionDataForCommit(pendingActionResult), updatedFetchers2 ? {
|
|
1704
|
-
fetchers: new Map(state.fetchers)
|
|
1705
|
-
} : {}), {
|
|
1706
|
-
flushSync
|
|
1707
|
-
});
|
|
1708
|
-
return {
|
|
1709
|
-
shortCircuited: true
|
|
1710
|
-
};
|
|
1711
|
-
}
|
|
1712
|
-
if (shouldUpdateNavigationState) {
|
|
1713
|
-
let updates = {};
|
|
1714
|
-
if (!isFogOfWar) {
|
|
1715
|
-
updates.navigation = loadingNavigation;
|
|
1716
|
-
let actionData = getUpdatedActionData(pendingActionResult);
|
|
1717
|
-
if (actionData !== void 0) {
|
|
1718
|
-
updates.actionData = actionData;
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
if (revalidatingFetchers.length > 0) {
|
|
1722
|
-
updates.fetchers = getUpdatedRevalidatingFetchers(revalidatingFetchers);
|
|
1723
|
-
}
|
|
1724
|
-
updateState(updates, {
|
|
1725
|
-
flushSync
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
revalidatingFetchers.forEach((rf) => {
|
|
1729
|
-
if (fetchControllers.has(rf.key)) {
|
|
1730
|
-
abortFetcher(rf.key);
|
|
1731
|
-
}
|
|
1732
|
-
if (rf.controller) {
|
|
1733
|
-
fetchControllers.set(rf.key, rf.controller);
|
|
1734
|
-
}
|
|
1735
|
-
});
|
|
1736
|
-
let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach((f) => abortFetcher(f.key));
|
|
1737
|
-
if (pendingNavigationController) {
|
|
1738
|
-
pendingNavigationController.signal.addEventListener("abort", abortPendingFetchRevalidations);
|
|
1739
|
-
}
|
|
1740
|
-
let {
|
|
1741
|
-
loaderResults,
|
|
1742
|
-
fetcherResults
|
|
1743
|
-
} = await callLoadersAndMaybeResolveData(state.matches, matches, matchesToLoad, revalidatingFetchers, request);
|
|
1744
|
-
if (request.signal.aborted) {
|
|
1745
|
-
return {
|
|
1746
|
-
shortCircuited: true
|
|
1747
|
-
};
|
|
1748
|
-
}
|
|
1749
|
-
if (pendingNavigationController) {
|
|
1750
|
-
pendingNavigationController.signal.removeEventListener("abort", abortPendingFetchRevalidations);
|
|
1751
|
-
}
|
|
1752
|
-
revalidatingFetchers.forEach((rf) => fetchControllers.delete(rf.key));
|
|
1753
|
-
let redirect3 = findRedirect([...loaderResults, ...fetcherResults]);
|
|
1754
|
-
if (redirect3) {
|
|
1755
|
-
if (redirect3.idx >= matchesToLoad.length) {
|
|
1756
|
-
let fetcherKey = revalidatingFetchers[redirect3.idx - matchesToLoad.length].key;
|
|
1757
|
-
fetchRedirectIds.add(fetcherKey);
|
|
1758
|
-
}
|
|
1759
|
-
await startRedirectNavigation(request, redirect3.result, {
|
|
1760
|
-
replace
|
|
1761
|
-
});
|
|
1762
|
-
return {
|
|
1763
|
-
shortCircuited: true
|
|
1764
|
-
};
|
|
1765
|
-
}
|
|
1766
|
-
let {
|
|
1767
|
-
loaderData,
|
|
1768
|
-
errors
|
|
1769
|
-
} = processLoaderData(state, matches, matchesToLoad, loaderResults, pendingActionResult, revalidatingFetchers, fetcherResults, activeDeferreds);
|
|
1770
|
-
activeDeferreds.forEach((deferredData, routeId) => {
|
|
1771
|
-
deferredData.subscribe((aborted) => {
|
|
1772
|
-
if (aborted || deferredData.done) {
|
|
1773
|
-
activeDeferreds.delete(routeId);
|
|
1774
|
-
}
|
|
1775
|
-
});
|
|
1776
|
-
});
|
|
1777
|
-
if (future.v7_partialHydration && initialHydration && state.errors) {
|
|
1778
|
-
Object.entries(state.errors).filter((_ref2) => {
|
|
1779
|
-
let [id] = _ref2;
|
|
1780
|
-
return !matchesToLoad.some((m) => m.route.id === id);
|
|
1781
|
-
}).forEach((_ref3) => {
|
|
1782
|
-
let [routeId, error] = _ref3;
|
|
1783
|
-
errors = Object.assign(errors || {}, {
|
|
1784
|
-
[routeId]: error
|
|
1785
|
-
});
|
|
1786
|
-
});
|
|
1787
|
-
}
|
|
1788
|
-
let updatedFetchers = markFetchRedirectsDone();
|
|
1789
|
-
let didAbortFetchLoads = abortStaleFetchLoads(pendingNavigationLoadId);
|
|
1790
|
-
let shouldUpdateFetchers = updatedFetchers || didAbortFetchLoads || revalidatingFetchers.length > 0;
|
|
1791
|
-
return _extends({
|
|
1792
|
-
matches,
|
|
1793
|
-
loaderData,
|
|
1794
|
-
errors
|
|
1795
|
-
}, shouldUpdateFetchers ? {
|
|
1796
|
-
fetchers: new Map(state.fetchers)
|
|
1797
|
-
} : {});
|
|
1798
|
-
}
|
|
1799
|
-
function getUpdatedActionData(pendingActionResult) {
|
|
1800
|
-
if (pendingActionResult && !isErrorResult(pendingActionResult[1])) {
|
|
1801
|
-
return {
|
|
1802
|
-
[pendingActionResult[0]]: pendingActionResult[1].data
|
|
1803
|
-
};
|
|
1804
|
-
} else if (state.actionData) {
|
|
1805
|
-
if (Object.keys(state.actionData).length === 0) {
|
|
1806
|
-
return null;
|
|
1807
|
-
} else {
|
|
1808
|
-
return state.actionData;
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
function getUpdatedRevalidatingFetchers(revalidatingFetchers) {
|
|
1813
|
-
revalidatingFetchers.forEach((rf) => {
|
|
1814
|
-
let fetcher = state.fetchers.get(rf.key);
|
|
1815
|
-
let revalidatingFetcher = getLoadingFetcher(void 0, fetcher ? fetcher.data : void 0);
|
|
1816
|
-
state.fetchers.set(rf.key, revalidatingFetcher);
|
|
1817
|
-
});
|
|
1818
|
-
return new Map(state.fetchers);
|
|
1819
|
-
}
|
|
1820
|
-
function fetch(key, routeId, href, opts) {
|
|
1821
|
-
if (isServer) {
|
|
1822
|
-
throw new Error("router.fetch() was called during the server render, but it shouldn't be. You are likely calling a useFetcher() method in the body of your component. Try moving it to a useEffect or a callback.");
|
|
1823
|
-
}
|
|
1824
|
-
if (fetchControllers.has(key)) abortFetcher(key);
|
|
1825
|
-
let flushSync = (opts && opts.unstable_flushSync) === true;
|
|
1826
|
-
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
1827
|
-
let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, href, future.v7_relativeSplatPath, routeId, opts == null ? void 0 : opts.relative);
|
|
1828
|
-
let matches = matchRoutes(routesToUse, normalizedPath, basename);
|
|
1829
|
-
let fogOfWar = checkFogOfWar(matches, routesToUse, normalizedPath);
|
|
1830
|
-
if (fogOfWar.active && fogOfWar.matches) {
|
|
1831
|
-
matches = fogOfWar.matches;
|
|
1832
|
-
}
|
|
1833
|
-
if (!matches) {
|
|
1834
|
-
setFetcherError(key, routeId, getInternalRouterError(404, {
|
|
1835
|
-
pathname: normalizedPath
|
|
1836
|
-
}), {
|
|
1837
|
-
flushSync
|
|
1838
|
-
});
|
|
1839
|
-
return;
|
|
1840
|
-
}
|
|
1841
|
-
let {
|
|
1842
|
-
path,
|
|
1843
|
-
submission,
|
|
1844
|
-
error
|
|
1845
|
-
} = normalizeNavigateOptions(future.v7_normalizeFormMethod, true, normalizedPath, opts);
|
|
1846
|
-
if (error) {
|
|
1847
|
-
setFetcherError(key, routeId, error, {
|
|
1848
|
-
flushSync
|
|
1849
|
-
});
|
|
1850
|
-
return;
|
|
1851
|
-
}
|
|
1852
|
-
let match = getTargetMatch(matches, path);
|
|
1853
|
-
pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1854
|
-
if (submission && isMutationMethod(submission.formMethod)) {
|
|
1855
|
-
handleFetcherAction(key, routeId, path, match, matches, fogOfWar.active, flushSync, submission);
|
|
1856
|
-
return;
|
|
1857
|
-
}
|
|
1858
|
-
fetchLoadMatches.set(key, {
|
|
1859
|
-
routeId,
|
|
1860
|
-
path
|
|
1861
|
-
});
|
|
1862
|
-
handleFetcherLoader(key, routeId, path, match, matches, fogOfWar.active, flushSync, submission);
|
|
1863
|
-
}
|
|
1864
|
-
async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, submission) {
|
|
1865
|
-
interruptActiveLoads();
|
|
1866
|
-
fetchLoadMatches.delete(key);
|
|
1867
|
-
function detectAndHandle405Error(m) {
|
|
1868
|
-
if (!m.route.action && !m.route.lazy) {
|
|
1869
|
-
let error = getInternalRouterError(405, {
|
|
1870
|
-
method: submission.formMethod,
|
|
1871
|
-
pathname: path,
|
|
1872
|
-
routeId
|
|
1873
|
-
});
|
|
1874
|
-
setFetcherError(key, routeId, error, {
|
|
1875
|
-
flushSync
|
|
1876
|
-
});
|
|
1877
|
-
return true;
|
|
1878
|
-
}
|
|
1879
|
-
return false;
|
|
1880
|
-
}
|
|
1881
|
-
if (!isFogOfWar && detectAndHandle405Error(match)) {
|
|
1882
|
-
return;
|
|
1883
|
-
}
|
|
1884
|
-
let existingFetcher = state.fetchers.get(key);
|
|
1885
|
-
updateFetcherState(key, getSubmittingFetcher(submission, existingFetcher), {
|
|
1886
|
-
flushSync
|
|
1887
|
-
});
|
|
1888
|
-
let abortController = new AbortController();
|
|
1889
|
-
let fetchRequest = createClientSideRequest(init.history, path, abortController.signal, submission);
|
|
1890
|
-
if (isFogOfWar) {
|
|
1891
|
-
let discoverResult = await discoverRoutes(requestMatches, path, fetchRequest.signal);
|
|
1892
|
-
if (discoverResult.type === "aborted") {
|
|
1893
|
-
return;
|
|
1894
|
-
} else if (discoverResult.type === "error") {
|
|
1895
|
-
let {
|
|
1896
|
-
error
|
|
1897
|
-
} = handleDiscoverRouteError(path, discoverResult);
|
|
1898
|
-
setFetcherError(key, routeId, error, {
|
|
1899
|
-
flushSync
|
|
1900
|
-
});
|
|
1901
|
-
return;
|
|
1902
|
-
} else if (!discoverResult.matches) {
|
|
1903
|
-
setFetcherError(key, routeId, getInternalRouterError(404, {
|
|
1904
|
-
pathname: path
|
|
1905
|
-
}), {
|
|
1906
|
-
flushSync
|
|
1907
|
-
});
|
|
1908
|
-
return;
|
|
1909
|
-
} else {
|
|
1910
|
-
requestMatches = discoverResult.matches;
|
|
1911
|
-
match = getTargetMatch(requestMatches, path);
|
|
1912
|
-
if (detectAndHandle405Error(match)) {
|
|
1913
|
-
return;
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
fetchControllers.set(key, abortController);
|
|
1918
|
-
let originatingLoadId = incrementingLoadId;
|
|
1919
|
-
let actionResults = await callDataStrategy("action", fetchRequest, [match], requestMatches);
|
|
1920
|
-
let actionResult = actionResults[0];
|
|
1921
|
-
if (fetchRequest.signal.aborted) {
|
|
1922
|
-
if (fetchControllers.get(key) === abortController) {
|
|
1923
|
-
fetchControllers.delete(key);
|
|
1924
|
-
}
|
|
1925
|
-
return;
|
|
1926
|
-
}
|
|
1927
|
-
if (future.v7_fetcherPersist && deletedFetchers.has(key)) {
|
|
1928
|
-
if (isRedirectResult(actionResult) || isErrorResult(actionResult)) {
|
|
1929
|
-
updateFetcherState(key, getDoneFetcher(void 0));
|
|
1930
|
-
return;
|
|
1931
|
-
}
|
|
1932
|
-
} else {
|
|
1933
|
-
if (isRedirectResult(actionResult)) {
|
|
1934
|
-
fetchControllers.delete(key);
|
|
1935
|
-
if (pendingNavigationLoadId > originatingLoadId) {
|
|
1936
|
-
updateFetcherState(key, getDoneFetcher(void 0));
|
|
1937
|
-
return;
|
|
1938
|
-
} else {
|
|
1939
|
-
fetchRedirectIds.add(key);
|
|
1940
|
-
updateFetcherState(key, getLoadingFetcher(submission));
|
|
1941
|
-
return startRedirectNavigation(fetchRequest, actionResult, {
|
|
1942
|
-
fetcherSubmission: submission
|
|
1943
|
-
});
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
if (isErrorResult(actionResult)) {
|
|
1947
|
-
setFetcherError(key, routeId, actionResult.error);
|
|
1948
|
-
return;
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
if (isDeferredResult(actionResult)) {
|
|
1952
|
-
throw getInternalRouterError(400, {
|
|
1953
|
-
type: "defer-action"
|
|
1954
|
-
});
|
|
1955
|
-
}
|
|
1956
|
-
let nextLocation = state.navigation.location || state.location;
|
|
1957
|
-
let revalidationRequest = createClientSideRequest(init.history, nextLocation, abortController.signal);
|
|
1958
|
-
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
1959
|
-
let matches = state.navigation.state !== "idle" ? matchRoutes(routesToUse, state.navigation.location, basename) : state.matches;
|
|
1960
|
-
invariant(matches, "Didn't find any matches after fetcher action");
|
|
1961
|
-
let loadId = ++incrementingLoadId;
|
|
1962
|
-
fetchReloadIds.set(key, loadId);
|
|
1963
|
-
let loadFetcher = getLoadingFetcher(submission, actionResult.data);
|
|
1964
|
-
state.fetchers.set(key, loadFetcher);
|
|
1965
|
-
let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, submission, nextLocation, false, future.unstable_skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, [match.route.id, actionResult]);
|
|
1966
|
-
revalidatingFetchers.filter((rf) => rf.key !== key).forEach((rf) => {
|
|
1967
|
-
let staleKey = rf.key;
|
|
1968
|
-
let existingFetcher2 = state.fetchers.get(staleKey);
|
|
1969
|
-
let revalidatingFetcher = getLoadingFetcher(void 0, existingFetcher2 ? existingFetcher2.data : void 0);
|
|
1970
|
-
state.fetchers.set(staleKey, revalidatingFetcher);
|
|
1971
|
-
if (fetchControllers.has(staleKey)) {
|
|
1972
|
-
abortFetcher(staleKey);
|
|
1973
|
-
}
|
|
1974
|
-
if (rf.controller) {
|
|
1975
|
-
fetchControllers.set(staleKey, rf.controller);
|
|
1976
|
-
}
|
|
1977
|
-
});
|
|
1978
|
-
updateState({
|
|
1979
|
-
fetchers: new Map(state.fetchers)
|
|
1980
|
-
});
|
|
1981
|
-
let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach((rf) => abortFetcher(rf.key));
|
|
1982
|
-
abortController.signal.addEventListener("abort", abortPendingFetchRevalidations);
|
|
1983
|
-
let {
|
|
1984
|
-
loaderResults,
|
|
1985
|
-
fetcherResults
|
|
1986
|
-
} = await callLoadersAndMaybeResolveData(state.matches, matches, matchesToLoad, revalidatingFetchers, revalidationRequest);
|
|
1987
|
-
if (abortController.signal.aborted) {
|
|
1988
|
-
return;
|
|
1989
|
-
}
|
|
1990
|
-
abortController.signal.removeEventListener("abort", abortPendingFetchRevalidations);
|
|
1991
|
-
fetchReloadIds.delete(key);
|
|
1992
|
-
fetchControllers.delete(key);
|
|
1993
|
-
revalidatingFetchers.forEach((r) => fetchControllers.delete(r.key));
|
|
1994
|
-
let redirect3 = findRedirect([...loaderResults, ...fetcherResults]);
|
|
1995
|
-
if (redirect3) {
|
|
1996
|
-
if (redirect3.idx >= matchesToLoad.length) {
|
|
1997
|
-
let fetcherKey = revalidatingFetchers[redirect3.idx - matchesToLoad.length].key;
|
|
1998
|
-
fetchRedirectIds.add(fetcherKey);
|
|
1999
|
-
}
|
|
2000
|
-
return startRedirectNavigation(revalidationRequest, redirect3.result);
|
|
2001
|
-
}
|
|
2002
|
-
let {
|
|
2003
|
-
loaderData,
|
|
2004
|
-
errors
|
|
2005
|
-
} = processLoaderData(state, state.matches, matchesToLoad, loaderResults, void 0, revalidatingFetchers, fetcherResults, activeDeferreds);
|
|
2006
|
-
if (state.fetchers.has(key)) {
|
|
2007
|
-
let doneFetcher = getDoneFetcher(actionResult.data);
|
|
2008
|
-
state.fetchers.set(key, doneFetcher);
|
|
2009
|
-
}
|
|
2010
|
-
abortStaleFetchLoads(loadId);
|
|
2011
|
-
if (state.navigation.state === "loading" && loadId > pendingNavigationLoadId) {
|
|
2012
|
-
invariant(pendingAction, "Expected pending action");
|
|
2013
|
-
pendingNavigationController && pendingNavigationController.abort();
|
|
2014
|
-
completeNavigation(state.navigation.location, {
|
|
2015
|
-
matches,
|
|
2016
|
-
loaderData,
|
|
2017
|
-
errors,
|
|
2018
|
-
fetchers: new Map(state.fetchers)
|
|
2019
|
-
});
|
|
2020
|
-
} else {
|
|
2021
|
-
updateState({
|
|
2022
|
-
errors,
|
|
2023
|
-
loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors),
|
|
2024
|
-
fetchers: new Map(state.fetchers)
|
|
2025
|
-
});
|
|
2026
|
-
isRevalidationRequired = false;
|
|
2027
|
-
}
|
|
2028
|
-
}
|
|
2029
|
-
async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, submission) {
|
|
2030
|
-
let existingFetcher = state.fetchers.get(key);
|
|
2031
|
-
updateFetcherState(key, getLoadingFetcher(submission, existingFetcher ? existingFetcher.data : void 0), {
|
|
2032
|
-
flushSync
|
|
2033
|
-
});
|
|
2034
|
-
let abortController = new AbortController();
|
|
2035
|
-
let fetchRequest = createClientSideRequest(init.history, path, abortController.signal);
|
|
2036
|
-
if (isFogOfWar) {
|
|
2037
|
-
let discoverResult = await discoverRoutes(matches, path, fetchRequest.signal);
|
|
2038
|
-
if (discoverResult.type === "aborted") {
|
|
2039
|
-
return;
|
|
2040
|
-
} else if (discoverResult.type === "error") {
|
|
2041
|
-
let {
|
|
2042
|
-
error
|
|
2043
|
-
} = handleDiscoverRouteError(path, discoverResult);
|
|
2044
|
-
setFetcherError(key, routeId, error, {
|
|
2045
|
-
flushSync
|
|
2046
|
-
});
|
|
2047
|
-
return;
|
|
2048
|
-
} else if (!discoverResult.matches) {
|
|
2049
|
-
setFetcherError(key, routeId, getInternalRouterError(404, {
|
|
2050
|
-
pathname: path
|
|
2051
|
-
}), {
|
|
2052
|
-
flushSync
|
|
2053
|
-
});
|
|
2054
|
-
return;
|
|
2055
|
-
} else {
|
|
2056
|
-
matches = discoverResult.matches;
|
|
2057
|
-
match = getTargetMatch(matches, path);
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
fetchControllers.set(key, abortController);
|
|
2061
|
-
let originatingLoadId = incrementingLoadId;
|
|
2062
|
-
let results = await callDataStrategy("loader", fetchRequest, [match], matches);
|
|
2063
|
-
let result = results[0];
|
|
2064
|
-
if (isDeferredResult(result)) {
|
|
2065
|
-
result = await resolveDeferredData(result, fetchRequest.signal, true) || result;
|
|
2066
|
-
}
|
|
2067
|
-
if (fetchControllers.get(key) === abortController) {
|
|
2068
|
-
fetchControllers.delete(key);
|
|
2069
|
-
}
|
|
2070
|
-
if (fetchRequest.signal.aborted) {
|
|
2071
|
-
return;
|
|
2072
|
-
}
|
|
2073
|
-
if (deletedFetchers.has(key)) {
|
|
2074
|
-
updateFetcherState(key, getDoneFetcher(void 0));
|
|
2075
|
-
return;
|
|
2076
|
-
}
|
|
2077
|
-
if (isRedirectResult(result)) {
|
|
2078
|
-
if (pendingNavigationLoadId > originatingLoadId) {
|
|
2079
|
-
updateFetcherState(key, getDoneFetcher(void 0));
|
|
2080
|
-
return;
|
|
2081
|
-
} else {
|
|
2082
|
-
fetchRedirectIds.add(key);
|
|
2083
|
-
await startRedirectNavigation(fetchRequest, result);
|
|
2084
|
-
return;
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
if (isErrorResult(result)) {
|
|
2088
|
-
setFetcherError(key, routeId, result.error);
|
|
2089
|
-
return;
|
|
2090
|
-
}
|
|
2091
|
-
invariant(!isDeferredResult(result), "Unhandled fetcher deferred data");
|
|
2092
|
-
updateFetcherState(key, getDoneFetcher(result.data));
|
|
2093
|
-
}
|
|
2094
|
-
async function startRedirectNavigation(request, redirect3, _temp2) {
|
|
2095
|
-
let {
|
|
2096
|
-
submission,
|
|
2097
|
-
fetcherSubmission,
|
|
2098
|
-
replace
|
|
2099
|
-
} = _temp2 === void 0 ? {} : _temp2;
|
|
2100
|
-
if (redirect3.response.headers.has("X-Remix-Revalidate")) {
|
|
2101
|
-
isRevalidationRequired = true;
|
|
2102
|
-
}
|
|
2103
|
-
let location = redirect3.response.headers.get("Location");
|
|
2104
|
-
invariant(location, "Expected a Location header on the redirect Response");
|
|
2105
|
-
location = normalizeRedirectLocation(location, new URL(request.url), basename);
|
|
2106
|
-
let redirectLocation = createLocation(state.location, location, {
|
|
2107
|
-
_isRedirect: true
|
|
2108
|
-
});
|
|
2109
|
-
if (isBrowser) {
|
|
2110
|
-
let isDocumentReload = false;
|
|
2111
|
-
if (redirect3.response.headers.has("X-Remix-Reload-Document")) {
|
|
2112
|
-
isDocumentReload = true;
|
|
2113
|
-
} else if (ABSOLUTE_URL_REGEX.test(location)) {
|
|
2114
|
-
const url = init.history.createURL(location);
|
|
2115
|
-
isDocumentReload = // Hard reload if it's an absolute URL to a new origin
|
|
2116
|
-
url.origin !== routerWindow.location.origin || // Hard reload if it's an absolute URL that does not match our basename
|
|
2117
|
-
stripBasename(url.pathname, basename) == null;
|
|
2118
|
-
}
|
|
2119
|
-
if (isDocumentReload) {
|
|
2120
|
-
if (replace) {
|
|
2121
|
-
routerWindow.location.replace(location);
|
|
2122
|
-
} else {
|
|
2123
|
-
routerWindow.location.assign(location);
|
|
2124
|
-
}
|
|
2125
|
-
return;
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
pendingNavigationController = null;
|
|
2129
|
-
let redirectHistoryAction = replace === true ? Action.Replace : Action.Push;
|
|
2130
|
-
let {
|
|
2131
|
-
formMethod,
|
|
2132
|
-
formAction,
|
|
2133
|
-
formEncType
|
|
2134
|
-
} = state.navigation;
|
|
2135
|
-
if (!submission && !fetcherSubmission && formMethod && formAction && formEncType) {
|
|
2136
|
-
submission = getSubmissionFromNavigation(state.navigation);
|
|
2137
|
-
}
|
|
2138
|
-
let activeSubmission = submission || fetcherSubmission;
|
|
2139
|
-
if (redirectPreserveMethodStatusCodes.has(redirect3.response.status) && activeSubmission && isMutationMethod(activeSubmission.formMethod)) {
|
|
2140
|
-
await startNavigation(redirectHistoryAction, redirectLocation, {
|
|
2141
|
-
submission: _extends({}, activeSubmission, {
|
|
2142
|
-
formAction: location
|
|
2143
|
-
}),
|
|
2144
|
-
// Preserve this flag across redirects
|
|
2145
|
-
preventScrollReset: pendingPreventScrollReset
|
|
2146
|
-
});
|
|
2147
|
-
} else {
|
|
2148
|
-
let overrideNavigation = getLoadingNavigation(redirectLocation, submission);
|
|
2149
|
-
await startNavigation(redirectHistoryAction, redirectLocation, {
|
|
2150
|
-
overrideNavigation,
|
|
2151
|
-
// Send fetcher submissions through for shouldRevalidate
|
|
2152
|
-
fetcherSubmission,
|
|
2153
|
-
// Preserve this flag across redirects
|
|
2154
|
-
preventScrollReset: pendingPreventScrollReset
|
|
2155
|
-
});
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
async function callDataStrategy(type, request, matchesToLoad, matches) {
|
|
2159
|
-
try {
|
|
2160
|
-
let results = await callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLoad, matches, manifest, mapRouteProperties);
|
|
2161
|
-
return await Promise.all(results.map((result, i) => {
|
|
2162
|
-
if (isRedirectHandlerResult(result)) {
|
|
2163
|
-
let response = result.result;
|
|
2164
|
-
return {
|
|
2165
|
-
type: ResultType.redirect,
|
|
2166
|
-
response: normalizeRelativeRoutingRedirectResponse(response, request, matchesToLoad[i].route.id, matches, basename, future.v7_relativeSplatPath)
|
|
2167
|
-
};
|
|
2168
|
-
}
|
|
2169
|
-
return convertHandlerResultToDataResult(result);
|
|
2170
|
-
}));
|
|
2171
|
-
} catch (e) {
|
|
2172
|
-
return matchesToLoad.map(() => ({
|
|
2173
|
-
type: ResultType.error,
|
|
2174
|
-
error: e
|
|
2175
|
-
}));
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
async function callLoadersAndMaybeResolveData(currentMatches, matches, matchesToLoad, fetchersToLoad, request) {
|
|
2179
|
-
let [loaderResults, ...fetcherResults] = await Promise.all([matchesToLoad.length ? callDataStrategy("loader", request, matchesToLoad, matches) : [], ...fetchersToLoad.map((f) => {
|
|
2180
|
-
if (f.matches && f.match && f.controller) {
|
|
2181
|
-
let fetcherRequest = createClientSideRequest(init.history, f.path, f.controller.signal);
|
|
2182
|
-
return callDataStrategy("loader", fetcherRequest, [f.match], f.matches).then((r) => r[0]);
|
|
2183
|
-
} else {
|
|
2184
|
-
return Promise.resolve({
|
|
2185
|
-
type: ResultType.error,
|
|
2186
|
-
error: getInternalRouterError(404, {
|
|
2187
|
-
pathname: f.path
|
|
2188
|
-
})
|
|
2189
|
-
});
|
|
2190
|
-
}
|
|
2191
|
-
})]);
|
|
2192
|
-
await Promise.all([resolveDeferredResults(currentMatches, matchesToLoad, loaderResults, loaderResults.map(() => request.signal), false, state.loaderData), resolveDeferredResults(currentMatches, fetchersToLoad.map((f) => f.match), fetcherResults, fetchersToLoad.map((f) => f.controller ? f.controller.signal : null), true)]);
|
|
2193
|
-
return {
|
|
2194
|
-
loaderResults,
|
|
2195
|
-
fetcherResults
|
|
2196
|
-
};
|
|
2197
|
-
}
|
|
2198
|
-
function interruptActiveLoads() {
|
|
2199
|
-
isRevalidationRequired = true;
|
|
2200
|
-
cancelledDeferredRoutes.push(...cancelActiveDeferreds());
|
|
2201
|
-
fetchLoadMatches.forEach((_, key) => {
|
|
2202
|
-
if (fetchControllers.has(key)) {
|
|
2203
|
-
cancelledFetcherLoads.push(key);
|
|
2204
|
-
abortFetcher(key);
|
|
2205
|
-
}
|
|
2206
|
-
});
|
|
2207
|
-
}
|
|
2208
|
-
function updateFetcherState(key, fetcher, opts) {
|
|
2209
|
-
if (opts === void 0) {
|
|
2210
|
-
opts = {};
|
|
2211
|
-
}
|
|
2212
|
-
state.fetchers.set(key, fetcher);
|
|
2213
|
-
updateState({
|
|
2214
|
-
fetchers: new Map(state.fetchers)
|
|
2215
|
-
}, {
|
|
2216
|
-
flushSync: (opts && opts.flushSync) === true
|
|
2217
|
-
});
|
|
2218
|
-
}
|
|
2219
|
-
function setFetcherError(key, routeId, error, opts) {
|
|
2220
|
-
if (opts === void 0) {
|
|
2221
|
-
opts = {};
|
|
2222
|
-
}
|
|
2223
|
-
let boundaryMatch = findNearestBoundary(state.matches, routeId);
|
|
2224
|
-
deleteFetcher(key);
|
|
2225
|
-
updateState({
|
|
2226
|
-
errors: {
|
|
2227
|
-
[boundaryMatch.route.id]: error
|
|
2228
|
-
},
|
|
2229
|
-
fetchers: new Map(state.fetchers)
|
|
2230
|
-
}, {
|
|
2231
|
-
flushSync: (opts && opts.flushSync) === true
|
|
2232
|
-
});
|
|
2233
|
-
}
|
|
2234
|
-
function getFetcher(key) {
|
|
2235
|
-
if (future.v7_fetcherPersist) {
|
|
2236
|
-
activeFetchers.set(key, (activeFetchers.get(key) || 0) + 1);
|
|
2237
|
-
if (deletedFetchers.has(key)) {
|
|
2238
|
-
deletedFetchers.delete(key);
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
return state.fetchers.get(key) || IDLE_FETCHER;
|
|
2242
|
-
}
|
|
2243
|
-
function deleteFetcher(key) {
|
|
2244
|
-
let fetcher = state.fetchers.get(key);
|
|
2245
|
-
if (fetchControllers.has(key) && !(fetcher && fetcher.state === "loading" && fetchReloadIds.has(key))) {
|
|
2246
|
-
abortFetcher(key);
|
|
2247
|
-
}
|
|
2248
|
-
fetchLoadMatches.delete(key);
|
|
2249
|
-
fetchReloadIds.delete(key);
|
|
2250
|
-
fetchRedirectIds.delete(key);
|
|
2251
|
-
deletedFetchers.delete(key);
|
|
2252
|
-
state.fetchers.delete(key);
|
|
2253
|
-
}
|
|
2254
|
-
function deleteFetcherAndUpdateState(key) {
|
|
2255
|
-
if (future.v7_fetcherPersist) {
|
|
2256
|
-
let count = (activeFetchers.get(key) || 0) - 1;
|
|
2257
|
-
if (count <= 0) {
|
|
2258
|
-
activeFetchers.delete(key);
|
|
2259
|
-
deletedFetchers.add(key);
|
|
2260
|
-
} else {
|
|
2261
|
-
activeFetchers.set(key, count);
|
|
2262
|
-
}
|
|
2263
|
-
} else {
|
|
2264
|
-
deleteFetcher(key);
|
|
2265
|
-
}
|
|
2266
|
-
updateState({
|
|
2267
|
-
fetchers: new Map(state.fetchers)
|
|
2268
|
-
});
|
|
2269
|
-
}
|
|
2270
|
-
function abortFetcher(key) {
|
|
2271
|
-
let controller = fetchControllers.get(key);
|
|
2272
|
-
invariant(controller, "Expected fetch controller: " + key);
|
|
2273
|
-
controller.abort();
|
|
2274
|
-
fetchControllers.delete(key);
|
|
2275
|
-
}
|
|
2276
|
-
function markFetchersDone(keys) {
|
|
2277
|
-
for (let key of keys) {
|
|
2278
|
-
let fetcher = getFetcher(key);
|
|
2279
|
-
let doneFetcher = getDoneFetcher(fetcher.data);
|
|
2280
|
-
state.fetchers.set(key, doneFetcher);
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
function markFetchRedirectsDone() {
|
|
2284
|
-
let doneKeys = [];
|
|
2285
|
-
let updatedFetchers = false;
|
|
2286
|
-
for (let key of fetchRedirectIds) {
|
|
2287
|
-
let fetcher = state.fetchers.get(key);
|
|
2288
|
-
invariant(fetcher, "Expected fetcher: " + key);
|
|
2289
|
-
if (fetcher.state === "loading") {
|
|
2290
|
-
fetchRedirectIds.delete(key);
|
|
2291
|
-
doneKeys.push(key);
|
|
2292
|
-
updatedFetchers = true;
|
|
2293
|
-
}
|
|
2294
|
-
}
|
|
2295
|
-
markFetchersDone(doneKeys);
|
|
2296
|
-
return updatedFetchers;
|
|
2297
|
-
}
|
|
2298
|
-
function abortStaleFetchLoads(landedId) {
|
|
2299
|
-
let yeetedKeys = [];
|
|
2300
|
-
for (let [key, id] of fetchReloadIds) {
|
|
2301
|
-
if (id < landedId) {
|
|
2302
|
-
let fetcher = state.fetchers.get(key);
|
|
2303
|
-
invariant(fetcher, "Expected fetcher: " + key);
|
|
2304
|
-
if (fetcher.state === "loading") {
|
|
2305
|
-
abortFetcher(key);
|
|
2306
|
-
fetchReloadIds.delete(key);
|
|
2307
|
-
yeetedKeys.push(key);
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
}
|
|
2311
|
-
markFetchersDone(yeetedKeys);
|
|
2312
|
-
return yeetedKeys.length > 0;
|
|
2313
|
-
}
|
|
2314
|
-
function getBlocker(key, fn) {
|
|
2315
|
-
let blocker = state.blockers.get(key) || IDLE_BLOCKER;
|
|
2316
|
-
if (blockerFunctions.get(key) !== fn) {
|
|
2317
|
-
blockerFunctions.set(key, fn);
|
|
2318
|
-
}
|
|
2319
|
-
return blocker;
|
|
2320
|
-
}
|
|
2321
|
-
function deleteBlocker(key) {
|
|
2322
|
-
state.blockers.delete(key);
|
|
2323
|
-
blockerFunctions.delete(key);
|
|
2324
|
-
}
|
|
2325
|
-
function updateBlocker(key, newBlocker) {
|
|
2326
|
-
let blocker = state.blockers.get(key) || IDLE_BLOCKER;
|
|
2327
|
-
invariant(blocker.state === "unblocked" && newBlocker.state === "blocked" || blocker.state === "blocked" && newBlocker.state === "blocked" || blocker.state === "blocked" && newBlocker.state === "proceeding" || blocker.state === "blocked" && newBlocker.state === "unblocked" || blocker.state === "proceeding" && newBlocker.state === "unblocked", "Invalid blocker state transition: " + blocker.state + " -> " + newBlocker.state);
|
|
2328
|
-
let blockers = new Map(state.blockers);
|
|
2329
|
-
blockers.set(key, newBlocker);
|
|
2330
|
-
updateState({
|
|
2331
|
-
blockers
|
|
2332
|
-
});
|
|
2333
|
-
}
|
|
2334
|
-
function shouldBlockNavigation(_ref4) {
|
|
2335
|
-
let {
|
|
2336
|
-
currentLocation,
|
|
2337
|
-
nextLocation,
|
|
2338
|
-
historyAction
|
|
2339
|
-
} = _ref4;
|
|
2340
|
-
if (blockerFunctions.size === 0) {
|
|
2341
|
-
return;
|
|
2342
|
-
}
|
|
2343
|
-
if (blockerFunctions.size > 1) {
|
|
2344
|
-
warning(false, "A router only supports one blocker at a time");
|
|
2345
|
-
}
|
|
2346
|
-
let entries = Array.from(blockerFunctions.entries());
|
|
2347
|
-
let [blockerKey, blockerFunction] = entries[entries.length - 1];
|
|
2348
|
-
let blocker = state.blockers.get(blockerKey);
|
|
2349
|
-
if (blocker && blocker.state === "proceeding") {
|
|
2350
|
-
return;
|
|
2351
|
-
}
|
|
2352
|
-
if (blockerFunction({
|
|
2353
|
-
currentLocation,
|
|
2354
|
-
nextLocation,
|
|
2355
|
-
historyAction
|
|
2356
|
-
})) {
|
|
2357
|
-
return blockerKey;
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
function handleNavigational404(pathname) {
|
|
2361
|
-
let error = getInternalRouterError(404, {
|
|
2362
|
-
pathname
|
|
2363
|
-
});
|
|
2364
|
-
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
2365
|
-
let {
|
|
2366
|
-
matches,
|
|
2367
|
-
route
|
|
2368
|
-
} = getShortCircuitMatches(routesToUse);
|
|
2369
|
-
cancelActiveDeferreds();
|
|
2370
|
-
return {
|
|
2371
|
-
notFoundMatches: matches,
|
|
2372
|
-
route,
|
|
2373
|
-
error
|
|
2374
|
-
};
|
|
2375
|
-
}
|
|
2376
|
-
function handleDiscoverRouteError(pathname, discoverResult) {
|
|
2377
|
-
let matches = discoverResult.partialMatches;
|
|
2378
|
-
let route = matches[matches.length - 1].route;
|
|
2379
|
-
let error = getInternalRouterError(400, {
|
|
2380
|
-
type: "route-discovery",
|
|
2381
|
-
routeId: route.id,
|
|
2382
|
-
pathname,
|
|
2383
|
-
message: discoverResult.error != null && "message" in discoverResult.error ? discoverResult.error : String(discoverResult.error)
|
|
2384
|
-
});
|
|
2385
|
-
return {
|
|
2386
|
-
notFoundMatches: matches,
|
|
2387
|
-
route,
|
|
2388
|
-
error
|
|
2389
|
-
};
|
|
2390
|
-
}
|
|
2391
|
-
function cancelActiveDeferreds(predicate) {
|
|
2392
|
-
let cancelledRouteIds = [];
|
|
2393
|
-
activeDeferreds.forEach((dfd, routeId) => {
|
|
2394
|
-
if (!predicate || predicate(routeId)) {
|
|
2395
|
-
dfd.cancel();
|
|
2396
|
-
cancelledRouteIds.push(routeId);
|
|
2397
|
-
activeDeferreds.delete(routeId);
|
|
2398
|
-
}
|
|
2399
|
-
});
|
|
2400
|
-
return cancelledRouteIds;
|
|
2401
|
-
}
|
|
2402
|
-
function enableScrollRestoration(positions, getPosition, getKey) {
|
|
2403
|
-
savedScrollPositions = positions;
|
|
2404
|
-
getScrollPosition = getPosition;
|
|
2405
|
-
getScrollRestorationKey = getKey || null;
|
|
2406
|
-
if (!initialScrollRestored && state.navigation === IDLE_NAVIGATION) {
|
|
2407
|
-
initialScrollRestored = true;
|
|
2408
|
-
let y = getSavedScrollPosition(state.location, state.matches);
|
|
2409
|
-
if (y != null) {
|
|
2410
|
-
updateState({
|
|
2411
|
-
restoreScrollPosition: y
|
|
2412
|
-
});
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
return () => {
|
|
2416
|
-
savedScrollPositions = null;
|
|
2417
|
-
getScrollPosition = null;
|
|
2418
|
-
getScrollRestorationKey = null;
|
|
2419
|
-
};
|
|
2420
|
-
}
|
|
2421
|
-
function getScrollKey(location, matches) {
|
|
2422
|
-
if (getScrollRestorationKey) {
|
|
2423
|
-
let key = getScrollRestorationKey(location, matches.map((m) => convertRouteMatchToUiMatch(m, state.loaderData)));
|
|
2424
|
-
return key || location.key;
|
|
2425
|
-
}
|
|
2426
|
-
return location.key;
|
|
2427
|
-
}
|
|
2428
|
-
function saveScrollPosition(location, matches) {
|
|
2429
|
-
if (savedScrollPositions && getScrollPosition) {
|
|
2430
|
-
let key = getScrollKey(location, matches);
|
|
2431
|
-
savedScrollPositions[key] = getScrollPosition();
|
|
2432
|
-
}
|
|
2433
|
-
}
|
|
2434
|
-
function getSavedScrollPosition(location, matches) {
|
|
2435
|
-
if (savedScrollPositions) {
|
|
2436
|
-
let key = getScrollKey(location, matches);
|
|
2437
|
-
let y = savedScrollPositions[key];
|
|
2438
|
-
if (typeof y === "number") {
|
|
2439
|
-
return y;
|
|
2440
|
-
}
|
|
2441
|
-
}
|
|
2442
|
-
return null;
|
|
2443
|
-
}
|
|
2444
|
-
function checkFogOfWar(matches, routesToUse, pathname) {
|
|
2445
|
-
if (patchRoutesOnMissImpl) {
|
|
2446
|
-
if (!matches) {
|
|
2447
|
-
let fogMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
|
|
2448
|
-
return {
|
|
2449
|
-
active: true,
|
|
2450
|
-
matches: fogMatches || []
|
|
2451
|
-
};
|
|
2452
|
-
} else {
|
|
2453
|
-
let leafRoute = matches[matches.length - 1].route;
|
|
2454
|
-
if (leafRoute.path && (leafRoute.path === "*" || leafRoute.path.endsWith("/*"))) {
|
|
2455
|
-
let partialMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
|
|
2456
|
-
return {
|
|
2457
|
-
active: true,
|
|
2458
|
-
matches: partialMatches
|
|
2459
|
-
};
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
return {
|
|
2464
|
-
active: false,
|
|
2465
|
-
matches: null
|
|
2466
|
-
};
|
|
2467
|
-
}
|
|
2468
|
-
async function discoverRoutes(matches, pathname, signal) {
|
|
2469
|
-
let partialMatches = matches;
|
|
2470
|
-
let route = partialMatches.length > 0 ? partialMatches[partialMatches.length - 1].route : null;
|
|
2471
|
-
while (true) {
|
|
2472
|
-
let isNonHMR = inFlightDataRoutes == null;
|
|
2473
|
-
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
2474
|
-
try {
|
|
2475
|
-
await loadLazyRouteChildren(patchRoutesOnMissImpl, pathname, partialMatches, routesToUse, manifest, mapRouteProperties, pendingPatchRoutes, signal);
|
|
2476
|
-
} catch (e) {
|
|
2477
|
-
return {
|
|
2478
|
-
type: "error",
|
|
2479
|
-
error: e,
|
|
2480
|
-
partialMatches
|
|
2481
|
-
};
|
|
2482
|
-
} finally {
|
|
2483
|
-
if (isNonHMR) {
|
|
2484
|
-
dataRoutes = [...dataRoutes];
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
if (signal.aborted) {
|
|
2488
|
-
return {
|
|
2489
|
-
type: "aborted"
|
|
2490
|
-
};
|
|
2491
|
-
}
|
|
2492
|
-
let newMatches = matchRoutes(routesToUse, pathname, basename);
|
|
2493
|
-
let matchedSplat = false;
|
|
2494
|
-
if (newMatches) {
|
|
2495
|
-
let leafRoute = newMatches[newMatches.length - 1].route;
|
|
2496
|
-
if (leafRoute.index) {
|
|
2497
|
-
return {
|
|
2498
|
-
type: "success",
|
|
2499
|
-
matches: newMatches
|
|
2500
|
-
};
|
|
2501
|
-
}
|
|
2502
|
-
if (leafRoute.path && leafRoute.path.length > 0) {
|
|
2503
|
-
if (leafRoute.path === "*") {
|
|
2504
|
-
matchedSplat = true;
|
|
2505
|
-
} else {
|
|
2506
|
-
return {
|
|
2507
|
-
type: "success",
|
|
2508
|
-
matches: newMatches
|
|
2509
|
-
};
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
}
|
|
2513
|
-
let newPartialMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
|
|
2514
|
-
if (!newPartialMatches || partialMatches.map((m) => m.route.id).join("-") === newPartialMatches.map((m) => m.route.id).join("-")) {
|
|
2515
|
-
return {
|
|
2516
|
-
type: "success",
|
|
2517
|
-
matches: matchedSplat ? newMatches : null
|
|
2518
|
-
};
|
|
2519
|
-
}
|
|
2520
|
-
partialMatches = newPartialMatches;
|
|
2521
|
-
route = partialMatches[partialMatches.length - 1].route;
|
|
2522
|
-
if (route.path === "*") {
|
|
2523
|
-
return {
|
|
2524
|
-
type: "success",
|
|
2525
|
-
matches: partialMatches
|
|
2526
|
-
};
|
|
2527
|
-
}
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
function _internalSetRoutes(newRoutes) {
|
|
2531
|
-
manifest = {};
|
|
2532
|
-
inFlightDataRoutes = convertRoutesToDataRoutes(newRoutes, mapRouteProperties, void 0, manifest);
|
|
2533
|
-
}
|
|
2534
|
-
function patchRoutes(routeId, children) {
|
|
2535
|
-
let isNonHMR = inFlightDataRoutes == null;
|
|
2536
|
-
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
2537
|
-
patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties);
|
|
2538
|
-
if (isNonHMR) {
|
|
2539
|
-
dataRoutes = [...dataRoutes];
|
|
2540
|
-
updateState({});
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
router2 = {
|
|
2544
|
-
get basename() {
|
|
2545
|
-
return basename;
|
|
2546
|
-
},
|
|
2547
|
-
get future() {
|
|
2548
|
-
return future;
|
|
2549
|
-
},
|
|
2550
|
-
get state() {
|
|
2551
|
-
return state;
|
|
2552
|
-
},
|
|
2553
|
-
get routes() {
|
|
2554
|
-
return dataRoutes;
|
|
2555
|
-
},
|
|
2556
|
-
get window() {
|
|
2557
|
-
return routerWindow;
|
|
2558
|
-
},
|
|
2559
|
-
initialize,
|
|
2560
|
-
subscribe,
|
|
2561
|
-
enableScrollRestoration,
|
|
2562
|
-
navigate,
|
|
2563
|
-
fetch,
|
|
2564
|
-
revalidate,
|
|
2565
|
-
// Passthrough to history-aware createHref used by useHref so we get proper
|
|
2566
|
-
// hash-aware URLs in DOM paths
|
|
2567
|
-
createHref: (to) => init.history.createHref(to),
|
|
2568
|
-
encodeLocation: (to) => init.history.encodeLocation(to),
|
|
2569
|
-
getFetcher,
|
|
2570
|
-
deleteFetcher: deleteFetcherAndUpdateState,
|
|
2571
|
-
dispose,
|
|
2572
|
-
getBlocker,
|
|
2573
|
-
deleteBlocker,
|
|
2574
|
-
patchRoutes,
|
|
2575
|
-
_internalFetchControllers: fetchControllers,
|
|
2576
|
-
_internalActiveDeferreds: activeDeferreds,
|
|
2577
|
-
// TODO: Remove setRoutes, it's temporary to avoid dealing with
|
|
2578
|
-
// updating the tree while validating the update algorithm.
|
|
2579
|
-
_internalSetRoutes
|
|
2580
|
-
};
|
|
2581
|
-
return router2;
|
|
2582
|
-
}
|
|
2583
|
-
const UNSAFE_DEFERRED_SYMBOL = Symbol("deferred");
|
|
2584
|
-
function createStaticHandler(routes, opts) {
|
|
2585
|
-
invariant(routes.length > 0, "You must provide a non-empty routes array to createStaticHandler");
|
|
2586
|
-
let manifest = {};
|
|
2587
|
-
let basename = (opts ? opts.basename : null) || "/";
|
|
2588
|
-
let mapRouteProperties;
|
|
2589
|
-
if (opts != null && opts.mapRouteProperties) {
|
|
2590
|
-
mapRouteProperties = opts.mapRouteProperties;
|
|
2591
|
-
} else if (opts != null && opts.detectErrorBoundary) {
|
|
2592
|
-
let detectErrorBoundary = opts.detectErrorBoundary;
|
|
2593
|
-
mapRouteProperties = (route) => ({
|
|
2594
|
-
hasErrorBoundary: detectErrorBoundary(route)
|
|
2595
|
-
});
|
|
2596
|
-
} else {
|
|
2597
|
-
mapRouteProperties = defaultMapRouteProperties;
|
|
2598
|
-
}
|
|
2599
|
-
let future = _extends({
|
|
2600
|
-
v7_relativeSplatPath: false,
|
|
2601
|
-
v7_throwAbortReason: false
|
|
2602
|
-
}, opts ? opts.future : null);
|
|
2603
|
-
let dataRoutes = convertRoutesToDataRoutes(routes, mapRouteProperties, void 0, manifest);
|
|
2604
|
-
async function query(request, _temp3) {
|
|
2605
|
-
let {
|
|
2606
|
-
requestContext,
|
|
2607
|
-
skipLoaderErrorBubbling,
|
|
2608
|
-
unstable_dataStrategy
|
|
2609
|
-
} = _temp3 === void 0 ? {} : _temp3;
|
|
2610
|
-
let url = new URL(request.url);
|
|
2611
|
-
let method = request.method;
|
|
2612
|
-
let location = createLocation("", createPath(url), null, "default");
|
|
2613
|
-
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2614
|
-
if (!isValidMethod(method) && method !== "HEAD") {
|
|
2615
|
-
let error = getInternalRouterError(405, {
|
|
2616
|
-
method
|
|
2617
|
-
});
|
|
2618
|
-
let {
|
|
2619
|
-
matches: methodNotAllowedMatches,
|
|
2620
|
-
route
|
|
2621
|
-
} = getShortCircuitMatches(dataRoutes);
|
|
2622
|
-
return {
|
|
2623
|
-
basename,
|
|
2624
|
-
location,
|
|
2625
|
-
matches: methodNotAllowedMatches,
|
|
2626
|
-
loaderData: {},
|
|
2627
|
-
actionData: null,
|
|
2628
|
-
errors: {
|
|
2629
|
-
[route.id]: error
|
|
2630
|
-
},
|
|
2631
|
-
statusCode: error.status,
|
|
2632
|
-
loaderHeaders: {},
|
|
2633
|
-
actionHeaders: {},
|
|
2634
|
-
activeDeferreds: null
|
|
2635
|
-
};
|
|
2636
|
-
} else if (!matches) {
|
|
2637
|
-
let error = getInternalRouterError(404, {
|
|
2638
|
-
pathname: location.pathname
|
|
2639
|
-
});
|
|
2640
|
-
let {
|
|
2641
|
-
matches: notFoundMatches,
|
|
2642
|
-
route
|
|
2643
|
-
} = getShortCircuitMatches(dataRoutes);
|
|
2644
|
-
return {
|
|
2645
|
-
basename,
|
|
2646
|
-
location,
|
|
2647
|
-
matches: notFoundMatches,
|
|
2648
|
-
loaderData: {},
|
|
2649
|
-
actionData: null,
|
|
2650
|
-
errors: {
|
|
2651
|
-
[route.id]: error
|
|
2652
|
-
},
|
|
2653
|
-
statusCode: error.status,
|
|
2654
|
-
loaderHeaders: {},
|
|
2655
|
-
actionHeaders: {},
|
|
2656
|
-
activeDeferreds: null
|
|
2657
|
-
};
|
|
2658
|
-
}
|
|
2659
|
-
let result = await queryImpl(request, location, matches, requestContext, unstable_dataStrategy || null, skipLoaderErrorBubbling === true, null);
|
|
2660
|
-
if (isResponse(result)) {
|
|
2661
|
-
return result;
|
|
2662
|
-
}
|
|
2663
|
-
return _extends({
|
|
2664
|
-
location,
|
|
2665
|
-
basename
|
|
2666
|
-
}, result);
|
|
2667
|
-
}
|
|
2668
|
-
async function queryRoute(request, _temp4) {
|
|
2669
|
-
let {
|
|
2670
|
-
routeId,
|
|
2671
|
-
requestContext,
|
|
2672
|
-
unstable_dataStrategy
|
|
2673
|
-
} = _temp4 === void 0 ? {} : _temp4;
|
|
2674
|
-
let url = new URL(request.url);
|
|
2675
|
-
let method = request.method;
|
|
2676
|
-
let location = createLocation("", createPath(url), null, "default");
|
|
2677
|
-
let matches = matchRoutes(dataRoutes, location, basename);
|
|
2678
|
-
if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
|
|
2679
|
-
throw getInternalRouterError(405, {
|
|
2680
|
-
method
|
|
2681
|
-
});
|
|
2682
|
-
} else if (!matches) {
|
|
2683
|
-
throw getInternalRouterError(404, {
|
|
2684
|
-
pathname: location.pathname
|
|
2685
|
-
});
|
|
2686
|
-
}
|
|
2687
|
-
let match = routeId ? matches.find((m) => m.route.id === routeId) : getTargetMatch(matches, location);
|
|
2688
|
-
if (routeId && !match) {
|
|
2689
|
-
throw getInternalRouterError(403, {
|
|
2690
|
-
pathname: location.pathname,
|
|
2691
|
-
routeId
|
|
2692
|
-
});
|
|
2693
|
-
} else if (!match) {
|
|
2694
|
-
throw getInternalRouterError(404, {
|
|
2695
|
-
pathname: location.pathname
|
|
2696
|
-
});
|
|
2697
|
-
}
|
|
2698
|
-
let result = await queryImpl(request, location, matches, requestContext, unstable_dataStrategy || null, false, match);
|
|
2699
|
-
if (isResponse(result)) {
|
|
2700
|
-
return result;
|
|
2701
|
-
}
|
|
2702
|
-
let error = result.errors ? Object.values(result.errors)[0] : void 0;
|
|
2703
|
-
if (error !== void 0) {
|
|
2704
|
-
throw error;
|
|
2705
|
-
}
|
|
2706
|
-
if (result.actionData) {
|
|
2707
|
-
return Object.values(result.actionData)[0];
|
|
2708
|
-
}
|
|
2709
|
-
if (result.loaderData) {
|
|
2710
|
-
var _result$activeDeferre;
|
|
2711
|
-
let data = Object.values(result.loaderData)[0];
|
|
2712
|
-
if ((_result$activeDeferre = result.activeDeferreds) != null && _result$activeDeferre[match.route.id]) {
|
|
2713
|
-
data[UNSAFE_DEFERRED_SYMBOL] = result.activeDeferreds[match.route.id];
|
|
2714
|
-
}
|
|
2715
|
-
return data;
|
|
2716
|
-
}
|
|
2717
|
-
return void 0;
|
|
2718
|
-
}
|
|
2719
|
-
async function queryImpl(request, location, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, routeMatch) {
|
|
2720
|
-
invariant(request.signal, "query()/queryRoute() requests must contain an AbortController signal");
|
|
2721
|
-
try {
|
|
2722
|
-
if (isMutationMethod(request.method.toLowerCase())) {
|
|
2723
|
-
let result2 = await submit(request, matches, routeMatch || getTargetMatch(matches, location), requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, routeMatch != null);
|
|
2724
|
-
return result2;
|
|
2725
|
-
}
|
|
2726
|
-
let result = await loadRouteData(request, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, routeMatch);
|
|
2727
|
-
return isResponse(result) ? result : _extends({}, result, {
|
|
2728
|
-
actionData: null,
|
|
2729
|
-
actionHeaders: {}
|
|
2730
|
-
});
|
|
2731
|
-
} catch (e) {
|
|
2732
|
-
if (isHandlerResult(e) && isResponse(e.result)) {
|
|
2733
|
-
if (e.type === ResultType.error) {
|
|
2734
|
-
throw e.result;
|
|
2735
|
-
}
|
|
2736
|
-
return e.result;
|
|
2737
|
-
}
|
|
2738
|
-
if (isRedirectResponse(e)) {
|
|
2739
|
-
return e;
|
|
2740
|
-
}
|
|
2741
|
-
throw e;
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
async function submit(request, matches, actionMatch, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, isRouteRequest) {
|
|
2745
|
-
let result;
|
|
2746
|
-
if (!actionMatch.route.action && !actionMatch.route.lazy) {
|
|
2747
|
-
let error = getInternalRouterError(405, {
|
|
2748
|
-
method: request.method,
|
|
2749
|
-
pathname: new URL(request.url).pathname,
|
|
2750
|
-
routeId: actionMatch.route.id
|
|
2751
|
-
});
|
|
2752
|
-
if (isRouteRequest) {
|
|
2753
|
-
throw error;
|
|
2754
|
-
}
|
|
2755
|
-
result = {
|
|
2756
|
-
type: ResultType.error,
|
|
2757
|
-
error
|
|
2758
|
-
};
|
|
2759
|
-
} else {
|
|
2760
|
-
let results = await callDataStrategy("action", request, [actionMatch], matches, isRouteRequest, requestContext, unstable_dataStrategy);
|
|
2761
|
-
result = results[0];
|
|
2762
|
-
if (request.signal.aborted) {
|
|
2763
|
-
throwStaticHandlerAbortedError(request, isRouteRequest, future);
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2766
|
-
if (isRedirectResult(result)) {
|
|
2767
|
-
throw new Response(null, {
|
|
2768
|
-
status: result.response.status,
|
|
2769
|
-
headers: {
|
|
2770
|
-
Location: result.response.headers.get("Location")
|
|
2771
|
-
}
|
|
2772
|
-
});
|
|
2773
|
-
}
|
|
2774
|
-
if (isDeferredResult(result)) {
|
|
2775
|
-
let error = getInternalRouterError(400, {
|
|
2776
|
-
type: "defer-action"
|
|
2777
|
-
});
|
|
2778
|
-
if (isRouteRequest) {
|
|
2779
|
-
throw error;
|
|
2780
|
-
}
|
|
2781
|
-
result = {
|
|
2782
|
-
type: ResultType.error,
|
|
2783
|
-
error
|
|
2784
|
-
};
|
|
2785
|
-
}
|
|
2786
|
-
if (isRouteRequest) {
|
|
2787
|
-
if (isErrorResult(result)) {
|
|
2788
|
-
throw result.error;
|
|
2789
|
-
}
|
|
2790
|
-
return {
|
|
2791
|
-
matches: [actionMatch],
|
|
2792
|
-
loaderData: {},
|
|
2793
|
-
actionData: {
|
|
2794
|
-
[actionMatch.route.id]: result.data
|
|
2795
|
-
},
|
|
2796
|
-
errors: null,
|
|
2797
|
-
// Note: statusCode + headers are unused here since queryRoute will
|
|
2798
|
-
// return the raw Response or value
|
|
2799
|
-
statusCode: 200,
|
|
2800
|
-
loaderHeaders: {},
|
|
2801
|
-
actionHeaders: {},
|
|
2802
|
-
activeDeferreds: null
|
|
2803
|
-
};
|
|
2804
|
-
}
|
|
2805
|
-
let loaderRequest = new Request(request.url, {
|
|
2806
|
-
headers: request.headers,
|
|
2807
|
-
redirect: request.redirect,
|
|
2808
|
-
signal: request.signal
|
|
2809
|
-
});
|
|
2810
|
-
if (isErrorResult(result)) {
|
|
2811
|
-
let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id);
|
|
2812
|
-
let context2 = await loadRouteData(loaderRequest, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, null, [boundaryMatch.route.id, result]);
|
|
2813
|
-
return _extends({}, context2, {
|
|
2814
|
-
statusCode: isRouteErrorResponse(result.error) ? result.error.status : result.statusCode != null ? result.statusCode : 500,
|
|
2815
|
-
actionData: null,
|
|
2816
|
-
actionHeaders: _extends({}, result.headers ? {
|
|
2817
|
-
[actionMatch.route.id]: result.headers
|
|
2818
|
-
} : {})
|
|
2819
|
-
});
|
|
2820
|
-
}
|
|
2821
|
-
let context = await loadRouteData(loaderRequest, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, null);
|
|
2822
|
-
return _extends({}, context, {
|
|
2823
|
-
actionData: {
|
|
2824
|
-
[actionMatch.route.id]: result.data
|
|
2825
|
-
}
|
|
2826
|
-
}, result.statusCode ? {
|
|
2827
|
-
statusCode: result.statusCode
|
|
2828
|
-
} : {}, {
|
|
2829
|
-
actionHeaders: result.headers ? {
|
|
2830
|
-
[actionMatch.route.id]: result.headers
|
|
2831
|
-
} : {}
|
|
2832
|
-
});
|
|
2833
|
-
}
|
|
2834
|
-
async function loadRouteData(request, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, routeMatch, pendingActionResult) {
|
|
2835
|
-
let isRouteRequest = routeMatch != null;
|
|
2836
|
-
if (isRouteRequest && !(routeMatch != null && routeMatch.route.loader) && !(routeMatch != null && routeMatch.route.lazy)) {
|
|
2837
|
-
throw getInternalRouterError(400, {
|
|
2838
|
-
method: request.method,
|
|
2839
|
-
pathname: new URL(request.url).pathname,
|
|
2840
|
-
routeId: routeMatch == null ? void 0 : routeMatch.route.id
|
|
2841
|
-
});
|
|
2842
|
-
}
|
|
2843
|
-
let requestMatches = routeMatch ? [routeMatch] : pendingActionResult && isErrorResult(pendingActionResult[1]) ? getLoaderMatchesUntilBoundary(matches, pendingActionResult[0]) : matches;
|
|
2844
|
-
let matchesToLoad = requestMatches.filter((m) => m.route.loader || m.route.lazy);
|
|
2845
|
-
if (matchesToLoad.length === 0) {
|
|
2846
|
-
return {
|
|
2847
|
-
matches,
|
|
2848
|
-
// Add a null for all matched routes for proper revalidation on the client
|
|
2849
|
-
loaderData: matches.reduce((acc, m) => Object.assign(acc, {
|
|
2850
|
-
[m.route.id]: null
|
|
2851
|
-
}), {}),
|
|
2852
|
-
errors: pendingActionResult && isErrorResult(pendingActionResult[1]) ? {
|
|
2853
|
-
[pendingActionResult[0]]: pendingActionResult[1].error
|
|
2854
|
-
} : null,
|
|
2855
|
-
statusCode: 200,
|
|
2856
|
-
loaderHeaders: {},
|
|
2857
|
-
activeDeferreds: null
|
|
2858
|
-
};
|
|
2859
|
-
}
|
|
2860
|
-
let results = await callDataStrategy("loader", request, matchesToLoad, matches, isRouteRequest, requestContext, unstable_dataStrategy);
|
|
2861
|
-
if (request.signal.aborted) {
|
|
2862
|
-
throwStaticHandlerAbortedError(request, isRouteRequest, future);
|
|
2863
|
-
}
|
|
2864
|
-
let activeDeferreds = /* @__PURE__ */ new Map();
|
|
2865
|
-
let context = processRouteLoaderData(matches, matchesToLoad, results, pendingActionResult, activeDeferreds, skipLoaderErrorBubbling);
|
|
2866
|
-
let executedLoaders = new Set(matchesToLoad.map((match) => match.route.id));
|
|
2867
|
-
matches.forEach((match) => {
|
|
2868
|
-
if (!executedLoaders.has(match.route.id)) {
|
|
2869
|
-
context.loaderData[match.route.id] = null;
|
|
2870
|
-
}
|
|
2871
|
-
});
|
|
2872
|
-
return _extends({}, context, {
|
|
2873
|
-
matches,
|
|
2874
|
-
activeDeferreds: activeDeferreds.size > 0 ? Object.fromEntries(activeDeferreds.entries()) : null
|
|
2875
|
-
});
|
|
2876
|
-
}
|
|
2877
|
-
async function callDataStrategy(type, request, matchesToLoad, matches, isRouteRequest, requestContext, unstable_dataStrategy) {
|
|
2878
|
-
let results = await callDataStrategyImpl(unstable_dataStrategy || defaultDataStrategy, type, request, matchesToLoad, matches, manifest, mapRouteProperties, requestContext);
|
|
2879
|
-
return await Promise.all(results.map((result, i) => {
|
|
2880
|
-
if (isRedirectHandlerResult(result)) {
|
|
2881
|
-
let response = result.result;
|
|
2882
|
-
throw normalizeRelativeRoutingRedirectResponse(response, request, matchesToLoad[i].route.id, matches, basename, future.v7_relativeSplatPath);
|
|
2883
|
-
}
|
|
2884
|
-
if (isResponse(result.result) && isRouteRequest) {
|
|
2885
|
-
throw result;
|
|
2886
|
-
}
|
|
2887
|
-
return convertHandlerResultToDataResult(result);
|
|
2888
|
-
}));
|
|
2889
|
-
}
|
|
2890
|
-
return {
|
|
2891
|
-
dataRoutes,
|
|
2892
|
-
query,
|
|
2893
|
-
queryRoute
|
|
2894
|
-
};
|
|
2895
|
-
}
|
|
2896
|
-
function getStaticContextFromError(routes, context, error) {
|
|
2897
|
-
let newContext = _extends({}, context, {
|
|
2898
|
-
statusCode: isRouteErrorResponse(error) ? error.status : 500,
|
|
2899
|
-
errors: {
|
|
2900
|
-
[context._deepestRenderedBoundaryId || routes[0].id]: error
|
|
2901
|
-
}
|
|
2902
|
-
});
|
|
2903
|
-
return newContext;
|
|
2904
|
-
}
|
|
2905
|
-
function throwStaticHandlerAbortedError(request, isRouteRequest, future) {
|
|
2906
|
-
if (future.v7_throwAbortReason && request.signal.reason !== void 0) {
|
|
2907
|
-
throw request.signal.reason;
|
|
2908
|
-
}
|
|
2909
|
-
let method = isRouteRequest ? "queryRoute" : "query";
|
|
2910
|
-
throw new Error(method + "() call aborted: " + request.method + " " + request.url);
|
|
2911
|
-
}
|
|
2912
|
-
function isSubmissionNavigation(opts) {
|
|
2913
|
-
return opts != null && ("formData" in opts && opts.formData != null || "body" in opts && opts.body !== void 0);
|
|
2914
|
-
}
|
|
2915
|
-
function normalizeTo(location, matches, basename, prependBasename, to, v7_relativeSplatPath, fromRouteId, relative) {
|
|
2916
|
-
let contextualMatches;
|
|
2917
|
-
let activeRouteMatch;
|
|
2918
|
-
if (fromRouteId) {
|
|
2919
|
-
contextualMatches = [];
|
|
2920
|
-
for (let match of matches) {
|
|
2921
|
-
contextualMatches.push(match);
|
|
2922
|
-
if (match.route.id === fromRouteId) {
|
|
2923
|
-
activeRouteMatch = match;
|
|
2924
|
-
break;
|
|
2925
|
-
}
|
|
2926
|
-
}
|
|
2927
|
-
} else {
|
|
2928
|
-
contextualMatches = matches;
|
|
2929
|
-
activeRouteMatch = matches[matches.length - 1];
|
|
2930
|
-
}
|
|
2931
|
-
let path = resolveTo(to ? to : ".", getResolveToMatches(contextualMatches, v7_relativeSplatPath), stripBasename(location.pathname, basename) || location.pathname, relative === "path");
|
|
2932
|
-
if (to == null) {
|
|
2933
|
-
path.search = location.search;
|
|
2934
|
-
path.hash = location.hash;
|
|
2935
|
-
}
|
|
2936
|
-
if ((to == null || to === "" || to === ".") && activeRouteMatch && activeRouteMatch.route.index && !hasNakedIndexQuery(path.search)) {
|
|
2937
|
-
path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
|
|
2938
|
-
}
|
|
2939
|
-
if (prependBasename && basename !== "/") {
|
|
2940
|
-
path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
|
2941
|
-
}
|
|
2942
|
-
return createPath(path);
|
|
2943
|
-
}
|
|
2944
|
-
function normalizeNavigateOptions(normalizeFormMethod, isFetcher, path, opts) {
|
|
2945
|
-
if (!opts || !isSubmissionNavigation(opts)) {
|
|
2946
|
-
return {
|
|
2947
|
-
path
|
|
2948
|
-
};
|
|
2949
|
-
}
|
|
2950
|
-
if (opts.formMethod && !isValidMethod(opts.formMethod)) {
|
|
2951
|
-
return {
|
|
2952
|
-
path,
|
|
2953
|
-
error: getInternalRouterError(405, {
|
|
2954
|
-
method: opts.formMethod
|
|
2955
|
-
})
|
|
2956
|
-
};
|
|
2957
|
-
}
|
|
2958
|
-
let getInvalidBodyError = () => ({
|
|
2959
|
-
path,
|
|
2960
|
-
error: getInternalRouterError(400, {
|
|
2961
|
-
type: "invalid-body"
|
|
2962
|
-
})
|
|
2963
|
-
});
|
|
2964
|
-
let rawFormMethod = opts.formMethod || "get";
|
|
2965
|
-
let formMethod = normalizeFormMethod ? rawFormMethod.toUpperCase() : rawFormMethod.toLowerCase();
|
|
2966
|
-
let formAction = stripHashFromPath(path);
|
|
2967
|
-
if (opts.body !== void 0) {
|
|
2968
|
-
if (opts.formEncType === "text/plain") {
|
|
2969
|
-
if (!isMutationMethod(formMethod)) {
|
|
2970
|
-
return getInvalidBodyError();
|
|
2971
|
-
}
|
|
2972
|
-
let text = typeof opts.body === "string" ? opts.body : opts.body instanceof FormData || opts.body instanceof URLSearchParams ? (
|
|
2973
|
-
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#plain-text-form-data
|
|
2974
|
-
Array.from(opts.body.entries()).reduce((acc, _ref5) => {
|
|
2975
|
-
let [name, value] = _ref5;
|
|
2976
|
-
return "" + acc + name + "=" + value + "\n";
|
|
2977
|
-
}, "")
|
|
2978
|
-
) : String(opts.body);
|
|
2979
|
-
return {
|
|
2980
|
-
path,
|
|
2981
|
-
submission: {
|
|
2982
|
-
formMethod,
|
|
2983
|
-
formAction,
|
|
2984
|
-
formEncType: opts.formEncType,
|
|
2985
|
-
formData: void 0,
|
|
2986
|
-
json: void 0,
|
|
2987
|
-
text
|
|
2988
|
-
}
|
|
2989
|
-
};
|
|
2990
|
-
} else if (opts.formEncType === "application/json") {
|
|
2991
|
-
if (!isMutationMethod(formMethod)) {
|
|
2992
|
-
return getInvalidBodyError();
|
|
2993
|
-
}
|
|
2994
|
-
try {
|
|
2995
|
-
let json3 = typeof opts.body === "string" ? JSON.parse(opts.body) : opts.body;
|
|
2996
|
-
return {
|
|
2997
|
-
path,
|
|
2998
|
-
submission: {
|
|
2999
|
-
formMethod,
|
|
3000
|
-
formAction,
|
|
3001
|
-
formEncType: opts.formEncType,
|
|
3002
|
-
formData: void 0,
|
|
3003
|
-
json: json3,
|
|
3004
|
-
text: void 0
|
|
3005
|
-
}
|
|
3006
|
-
};
|
|
3007
|
-
} catch (e) {
|
|
3008
|
-
return getInvalidBodyError();
|
|
3009
|
-
}
|
|
3010
|
-
}
|
|
3011
|
-
}
|
|
3012
|
-
invariant(typeof FormData === "function", "FormData is not available in this environment");
|
|
3013
|
-
let searchParams;
|
|
3014
|
-
let formData;
|
|
3015
|
-
if (opts.formData) {
|
|
3016
|
-
searchParams = convertFormDataToSearchParams(opts.formData);
|
|
3017
|
-
formData = opts.formData;
|
|
3018
|
-
} else if (opts.body instanceof FormData) {
|
|
3019
|
-
searchParams = convertFormDataToSearchParams(opts.body);
|
|
3020
|
-
formData = opts.body;
|
|
3021
|
-
} else if (opts.body instanceof URLSearchParams) {
|
|
3022
|
-
searchParams = opts.body;
|
|
3023
|
-
formData = convertSearchParamsToFormData(searchParams);
|
|
3024
|
-
} else if (opts.body == null) {
|
|
3025
|
-
searchParams = new URLSearchParams();
|
|
3026
|
-
formData = new FormData();
|
|
3027
|
-
} else {
|
|
3028
|
-
try {
|
|
3029
|
-
searchParams = new URLSearchParams(opts.body);
|
|
3030
|
-
formData = convertSearchParamsToFormData(searchParams);
|
|
3031
|
-
} catch (e) {
|
|
3032
|
-
return getInvalidBodyError();
|
|
3033
|
-
}
|
|
3034
|
-
}
|
|
3035
|
-
let submission = {
|
|
3036
|
-
formMethod,
|
|
3037
|
-
formAction,
|
|
3038
|
-
formEncType: opts && opts.formEncType || "application/x-www-form-urlencoded",
|
|
3039
|
-
formData,
|
|
3040
|
-
json: void 0,
|
|
3041
|
-
text: void 0
|
|
3042
|
-
};
|
|
3043
|
-
if (isMutationMethod(submission.formMethod)) {
|
|
3044
|
-
return {
|
|
3045
|
-
path,
|
|
3046
|
-
submission
|
|
3047
|
-
};
|
|
3048
|
-
}
|
|
3049
|
-
let parsedPath = parsePath(path);
|
|
3050
|
-
if (isFetcher && parsedPath.search && hasNakedIndexQuery(parsedPath.search)) {
|
|
3051
|
-
searchParams.append("index", "");
|
|
3052
|
-
}
|
|
3053
|
-
parsedPath.search = "?" + searchParams;
|
|
3054
|
-
return {
|
|
3055
|
-
path: createPath(parsedPath),
|
|
3056
|
-
submission
|
|
3057
|
-
};
|
|
3058
|
-
}
|
|
3059
|
-
function getLoaderMatchesUntilBoundary(matches, boundaryId) {
|
|
3060
|
-
let boundaryMatches = matches;
|
|
3061
|
-
if (boundaryId) {
|
|
3062
|
-
let index = matches.findIndex((m) => m.route.id === boundaryId);
|
|
3063
|
-
if (index >= 0) {
|
|
3064
|
-
boundaryMatches = matches.slice(0, index);
|
|
3065
|
-
}
|
|
3066
|
-
}
|
|
3067
|
-
return boundaryMatches;
|
|
3068
|
-
}
|
|
3069
|
-
function getMatchesToLoad(history, state, matches, submission, location, isInitialLoad, skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult) {
|
|
3070
|
-
let actionResult = pendingActionResult ? isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : pendingActionResult[1].data : void 0;
|
|
3071
|
-
let currentUrl = history.createURL(state.location);
|
|
3072
|
-
let nextUrl = history.createURL(location);
|
|
3073
|
-
let boundaryId = pendingActionResult && isErrorResult(pendingActionResult[1]) ? pendingActionResult[0] : void 0;
|
|
3074
|
-
let boundaryMatches = boundaryId ? getLoaderMatchesUntilBoundary(matches, boundaryId) : matches;
|
|
3075
|
-
let actionStatus = pendingActionResult ? pendingActionResult[1].statusCode : void 0;
|
|
3076
|
-
let shouldSkipRevalidation = skipActionErrorRevalidation && actionStatus && actionStatus >= 400;
|
|
3077
|
-
let navigationMatches = boundaryMatches.filter((match, index) => {
|
|
3078
|
-
let {
|
|
3079
|
-
route
|
|
3080
|
-
} = match;
|
|
3081
|
-
if (route.lazy) {
|
|
3082
|
-
return true;
|
|
3083
|
-
}
|
|
3084
|
-
if (route.loader == null) {
|
|
3085
|
-
return false;
|
|
3086
|
-
}
|
|
3087
|
-
if (isInitialLoad) {
|
|
3088
|
-
if (typeof route.loader !== "function" || route.loader.hydrate) {
|
|
3089
|
-
return true;
|
|
3090
|
-
}
|
|
3091
|
-
return state.loaderData[route.id] === void 0 && // Don't re-run if the loader ran and threw an error
|
|
3092
|
-
(!state.errors || state.errors[route.id] === void 0);
|
|
3093
|
-
}
|
|
3094
|
-
if (isNewLoader(state.loaderData, state.matches[index], match) || cancelledDeferredRoutes.some((id) => id === match.route.id)) {
|
|
3095
|
-
return true;
|
|
3096
|
-
}
|
|
3097
|
-
let currentRouteMatch = state.matches[index];
|
|
3098
|
-
let nextRouteMatch = match;
|
|
3099
|
-
return shouldRevalidateLoader(match, _extends({
|
|
3100
|
-
currentUrl,
|
|
3101
|
-
currentParams: currentRouteMatch.params,
|
|
3102
|
-
nextUrl,
|
|
3103
|
-
nextParams: nextRouteMatch.params
|
|
3104
|
-
}, submission, {
|
|
3105
|
-
actionResult,
|
|
3106
|
-
unstable_actionStatus: actionStatus,
|
|
3107
|
-
defaultShouldRevalidate: shouldSkipRevalidation ? false : (
|
|
3108
|
-
// Forced revalidation due to submission, useRevalidator, or X-Remix-Revalidate
|
|
3109
|
-
isRevalidationRequired || currentUrl.pathname + currentUrl.search === nextUrl.pathname + nextUrl.search || // Search params affect all loaders
|
|
3110
|
-
currentUrl.search !== nextUrl.search || isNewRouteInstance(currentRouteMatch, nextRouteMatch)
|
|
3111
|
-
)
|
|
3112
|
-
}));
|
|
3113
|
-
});
|
|
3114
|
-
let revalidatingFetchers = [];
|
|
3115
|
-
fetchLoadMatches.forEach((f, key) => {
|
|
3116
|
-
if (isInitialLoad || !matches.some((m) => m.route.id === f.routeId) || deletedFetchers.has(key)) {
|
|
3117
|
-
return;
|
|
3118
|
-
}
|
|
3119
|
-
let fetcherMatches = matchRoutes(routesToUse, f.path, basename);
|
|
3120
|
-
if (!fetcherMatches) {
|
|
3121
|
-
revalidatingFetchers.push({
|
|
3122
|
-
key,
|
|
3123
|
-
routeId: f.routeId,
|
|
3124
|
-
path: f.path,
|
|
3125
|
-
matches: null,
|
|
3126
|
-
match: null,
|
|
3127
|
-
controller: null
|
|
3128
|
-
});
|
|
3129
|
-
return;
|
|
3130
|
-
}
|
|
3131
|
-
let fetcher = state.fetchers.get(key);
|
|
3132
|
-
let fetcherMatch = getTargetMatch(fetcherMatches, f.path);
|
|
3133
|
-
let shouldRevalidate = false;
|
|
3134
|
-
if (fetchRedirectIds.has(key)) {
|
|
3135
|
-
shouldRevalidate = false;
|
|
3136
|
-
} else if (cancelledFetcherLoads.includes(key)) {
|
|
3137
|
-
shouldRevalidate = true;
|
|
3138
|
-
} else if (fetcher && fetcher.state !== "idle" && fetcher.data === void 0) {
|
|
3139
|
-
shouldRevalidate = isRevalidationRequired;
|
|
3140
|
-
} else {
|
|
3141
|
-
shouldRevalidate = shouldRevalidateLoader(fetcherMatch, _extends({
|
|
3142
|
-
currentUrl,
|
|
3143
|
-
currentParams: state.matches[state.matches.length - 1].params,
|
|
3144
|
-
nextUrl,
|
|
3145
|
-
nextParams: matches[matches.length - 1].params
|
|
3146
|
-
}, submission, {
|
|
3147
|
-
actionResult,
|
|
3148
|
-
unstable_actionStatus: actionStatus,
|
|
3149
|
-
defaultShouldRevalidate: shouldSkipRevalidation ? false : isRevalidationRequired
|
|
3150
|
-
}));
|
|
3151
|
-
}
|
|
3152
|
-
if (shouldRevalidate) {
|
|
3153
|
-
revalidatingFetchers.push({
|
|
3154
|
-
key,
|
|
3155
|
-
routeId: f.routeId,
|
|
3156
|
-
path: f.path,
|
|
3157
|
-
matches: fetcherMatches,
|
|
3158
|
-
match: fetcherMatch,
|
|
3159
|
-
controller: new AbortController()
|
|
3160
|
-
});
|
|
3161
|
-
}
|
|
3162
|
-
});
|
|
3163
|
-
return [navigationMatches, revalidatingFetchers];
|
|
3164
|
-
}
|
|
3165
|
-
function isNewLoader(currentLoaderData, currentMatch, match) {
|
|
3166
|
-
let isNew = (
|
|
3167
|
-
// [a] -> [a, b]
|
|
3168
|
-
!currentMatch || // [a, b] -> [a, c]
|
|
3169
|
-
match.route.id !== currentMatch.route.id
|
|
3170
|
-
);
|
|
3171
|
-
let isMissingData = currentLoaderData[match.route.id] === void 0;
|
|
3172
|
-
return isNew || isMissingData;
|
|
3173
|
-
}
|
|
3174
|
-
function isNewRouteInstance(currentMatch, match) {
|
|
3175
|
-
let currentPath = currentMatch.route.path;
|
|
3176
|
-
return (
|
|
3177
|
-
// param change for this match, /users/123 -> /users/456
|
|
3178
|
-
currentMatch.pathname !== match.pathname || // splat param changed, which is not present in match.path
|
|
3179
|
-
// e.g. /files/images/avatar.jpg -> files/finances.xls
|
|
3180
|
-
currentPath != null && currentPath.endsWith("*") && currentMatch.params["*"] !== match.params["*"]
|
|
3181
|
-
);
|
|
3182
|
-
}
|
|
3183
|
-
function shouldRevalidateLoader(loaderMatch, arg) {
|
|
3184
|
-
if (loaderMatch.route.shouldRevalidate) {
|
|
3185
|
-
let routeChoice = loaderMatch.route.shouldRevalidate(arg);
|
|
3186
|
-
if (typeof routeChoice === "boolean") {
|
|
3187
|
-
return routeChoice;
|
|
3188
|
-
}
|
|
3189
|
-
}
|
|
3190
|
-
return arg.defaultShouldRevalidate;
|
|
3191
|
-
}
|
|
3192
|
-
async function loadLazyRouteChildren(patchRoutesOnMissImpl, path, matches, routes, manifest, mapRouteProperties, pendingRouteChildren, signal) {
|
|
3193
|
-
let key = [path, ...matches.map((m) => m.route.id)].join("-");
|
|
3194
|
-
try {
|
|
3195
|
-
let pending = pendingRouteChildren.get(key);
|
|
3196
|
-
if (!pending) {
|
|
3197
|
-
pending = patchRoutesOnMissImpl({
|
|
3198
|
-
path,
|
|
3199
|
-
matches,
|
|
3200
|
-
patch: (routeId, children) => {
|
|
3201
|
-
if (!signal.aborted) {
|
|
3202
|
-
patchRoutesImpl(routeId, children, routes, manifest, mapRouteProperties);
|
|
3203
|
-
}
|
|
3204
|
-
}
|
|
3205
|
-
});
|
|
3206
|
-
pendingRouteChildren.set(key, pending);
|
|
3207
|
-
}
|
|
3208
|
-
if (pending && isPromise(pending)) {
|
|
3209
|
-
await pending;
|
|
3210
|
-
}
|
|
3211
|
-
} finally {
|
|
3212
|
-
pendingRouteChildren.delete(key);
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties) {
|
|
3216
|
-
if (routeId) {
|
|
3217
|
-
var _route$children;
|
|
3218
|
-
let route = manifest[routeId];
|
|
3219
|
-
invariant(route, "No route found to patch children into: routeId = " + routeId);
|
|
3220
|
-
let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, [routeId, "patch", String(((_route$children = route.children) == null ? void 0 : _route$children.length) || "0")], manifest);
|
|
3221
|
-
if (route.children) {
|
|
3222
|
-
route.children.push(...dataChildren);
|
|
3223
|
-
} else {
|
|
3224
|
-
route.children = dataChildren;
|
|
3225
|
-
}
|
|
3226
|
-
} else {
|
|
3227
|
-
let dataChildren = convertRoutesToDataRoutes(children, mapRouteProperties, ["patch", String(routesToUse.length || "0")], manifest);
|
|
3228
|
-
routesToUse.push(...dataChildren);
|
|
3229
|
-
}
|
|
3230
|
-
}
|
|
3231
|
-
async function loadLazyRouteModule(route, mapRouteProperties, manifest) {
|
|
3232
|
-
if (!route.lazy) {
|
|
3233
|
-
return;
|
|
3234
|
-
}
|
|
3235
|
-
let lazyRoute = await route.lazy();
|
|
3236
|
-
if (!route.lazy) {
|
|
3237
|
-
return;
|
|
3238
|
-
}
|
|
3239
|
-
let routeToUpdate = manifest[route.id];
|
|
3240
|
-
invariant(routeToUpdate, "No route found in manifest");
|
|
3241
|
-
let routeUpdates = {};
|
|
3242
|
-
for (let lazyRouteProperty in lazyRoute) {
|
|
3243
|
-
let staticRouteValue = routeToUpdate[lazyRouteProperty];
|
|
3244
|
-
let isPropertyStaticallyDefined = staticRouteValue !== void 0 && // This property isn't static since it should always be updated based
|
|
3245
|
-
// on the route updates
|
|
3246
|
-
lazyRouteProperty !== "hasErrorBoundary";
|
|
3247
|
-
warning(!isPropertyStaticallyDefined, 'Route "' + routeToUpdate.id + '" has a static property "' + lazyRouteProperty + '" defined but its lazy function is also returning a value for this property. ' + ('The lazy route property "' + lazyRouteProperty + '" will be ignored.'));
|
|
3248
|
-
if (!isPropertyStaticallyDefined && !immutableRouteKeys.has(lazyRouteProperty)) {
|
|
3249
|
-
routeUpdates[lazyRouteProperty] = lazyRoute[lazyRouteProperty];
|
|
3250
|
-
}
|
|
3251
|
-
}
|
|
3252
|
-
Object.assign(routeToUpdate, routeUpdates);
|
|
3253
|
-
Object.assign(routeToUpdate, _extends({}, mapRouteProperties(routeToUpdate), {
|
|
3254
|
-
lazy: void 0
|
|
3255
|
-
}));
|
|
3256
|
-
}
|
|
3257
|
-
function defaultDataStrategy(opts) {
|
|
3258
|
-
return Promise.all(opts.matches.map((m) => m.resolve()));
|
|
3259
|
-
}
|
|
3260
|
-
async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLoad, matches, manifest, mapRouteProperties, requestContext) {
|
|
3261
|
-
let routeIdsToLoad = matchesToLoad.reduce((acc, m) => acc.add(m.route.id), /* @__PURE__ */ new Set());
|
|
3262
|
-
let loadedMatches = /* @__PURE__ */ new Set();
|
|
3263
|
-
let results = await dataStrategyImpl({
|
|
3264
|
-
matches: matches.map((match) => {
|
|
3265
|
-
let shouldLoad = routeIdsToLoad.has(match.route.id);
|
|
3266
|
-
let resolve = (handlerOverride) => {
|
|
3267
|
-
loadedMatches.add(match.route.id);
|
|
3268
|
-
return shouldLoad ? callLoaderOrAction(type, request, match, manifest, mapRouteProperties, handlerOverride, requestContext) : Promise.resolve({
|
|
3269
|
-
type: ResultType.data,
|
|
3270
|
-
result: void 0
|
|
3271
|
-
});
|
|
3272
|
-
};
|
|
3273
|
-
return _extends({}, match, {
|
|
3274
|
-
shouldLoad,
|
|
3275
|
-
resolve
|
|
3276
|
-
});
|
|
3277
|
-
}),
|
|
3278
|
-
request,
|
|
3279
|
-
params: matches[0].params,
|
|
3280
|
-
context: requestContext
|
|
3281
|
-
});
|
|
3282
|
-
matches.forEach((m) => invariant(loadedMatches.has(m.route.id), '`match.resolve()` was not called for route id "' + m.route.id + '". You must call `match.resolve()` on every match passed to `dataStrategy` to ensure all routes are properly loaded.'));
|
|
3283
|
-
return results.filter((_, i) => routeIdsToLoad.has(matches[i].route.id));
|
|
3284
|
-
}
|
|
3285
|
-
async function callLoaderOrAction(type, request, match, manifest, mapRouteProperties, handlerOverride, staticContext) {
|
|
3286
|
-
let result;
|
|
3287
|
-
let onReject;
|
|
3288
|
-
let runHandler = (handler) => {
|
|
3289
|
-
let reject;
|
|
3290
|
-
let abortPromise = new Promise((_, r) => reject = r);
|
|
3291
|
-
onReject = () => reject();
|
|
3292
|
-
request.signal.addEventListener("abort", onReject);
|
|
3293
|
-
let actualHandler = (ctx) => {
|
|
3294
|
-
if (typeof handler !== "function") {
|
|
3295
|
-
return Promise.reject(new Error("You cannot call the handler for a route which defines a boolean " + ('"' + type + '" [routeId: ' + match.route.id + "]")));
|
|
3296
|
-
}
|
|
3297
|
-
return handler({
|
|
3298
|
-
request,
|
|
3299
|
-
params: match.params,
|
|
3300
|
-
context: staticContext
|
|
3301
|
-
}, ...ctx !== void 0 ? [ctx] : []);
|
|
3302
|
-
};
|
|
3303
|
-
let handlerPromise;
|
|
3304
|
-
if (handlerOverride) {
|
|
3305
|
-
handlerPromise = handlerOverride((ctx) => actualHandler(ctx));
|
|
3306
|
-
} else {
|
|
3307
|
-
handlerPromise = (async () => {
|
|
3308
|
-
try {
|
|
3309
|
-
let val = await actualHandler();
|
|
3310
|
-
return {
|
|
3311
|
-
type: "data",
|
|
3312
|
-
result: val
|
|
3313
|
-
};
|
|
3314
|
-
} catch (e) {
|
|
3315
|
-
return {
|
|
3316
|
-
type: "error",
|
|
3317
|
-
result: e
|
|
3318
|
-
};
|
|
3319
|
-
}
|
|
3320
|
-
})();
|
|
3321
|
-
}
|
|
3322
|
-
return Promise.race([handlerPromise, abortPromise]);
|
|
3323
|
-
};
|
|
3324
|
-
try {
|
|
3325
|
-
let handler = match.route[type];
|
|
3326
|
-
if (match.route.lazy) {
|
|
3327
|
-
if (handler) {
|
|
3328
|
-
let handlerError;
|
|
3329
|
-
let [value] = await Promise.all([
|
|
3330
|
-
// If the handler throws, don't let it immediately bubble out,
|
|
3331
|
-
// since we need to let the lazy() execution finish so we know if this
|
|
3332
|
-
// route has a boundary that can handle the error
|
|
3333
|
-
runHandler(handler).catch((e) => {
|
|
3334
|
-
handlerError = e;
|
|
3335
|
-
}),
|
|
3336
|
-
loadLazyRouteModule(match.route, mapRouteProperties, manifest)
|
|
3337
|
-
]);
|
|
3338
|
-
if (handlerError !== void 0) {
|
|
3339
|
-
throw handlerError;
|
|
3340
|
-
}
|
|
3341
|
-
result = value;
|
|
3342
|
-
} else {
|
|
3343
|
-
await loadLazyRouteModule(match.route, mapRouteProperties, manifest);
|
|
3344
|
-
handler = match.route[type];
|
|
3345
|
-
if (handler) {
|
|
3346
|
-
result = await runHandler(handler);
|
|
3347
|
-
} else if (type === "action") {
|
|
3348
|
-
let url = new URL(request.url);
|
|
3349
|
-
let pathname = url.pathname + url.search;
|
|
3350
|
-
throw getInternalRouterError(405, {
|
|
3351
|
-
method: request.method,
|
|
3352
|
-
pathname,
|
|
3353
|
-
routeId: match.route.id
|
|
3354
|
-
});
|
|
3355
|
-
} else {
|
|
3356
|
-
return {
|
|
3357
|
-
type: ResultType.data,
|
|
3358
|
-
result: void 0
|
|
3359
|
-
};
|
|
3360
|
-
}
|
|
3361
|
-
}
|
|
3362
|
-
} else if (!handler) {
|
|
3363
|
-
let url = new URL(request.url);
|
|
3364
|
-
let pathname = url.pathname + url.search;
|
|
3365
|
-
throw getInternalRouterError(404, {
|
|
3366
|
-
pathname
|
|
3367
|
-
});
|
|
3368
|
-
} else {
|
|
3369
|
-
result = await runHandler(handler);
|
|
3370
|
-
}
|
|
3371
|
-
invariant(result.result !== void 0, "You defined " + (type === "action" ? "an action" : "a loader") + " for route " + ('"' + match.route.id + "\" but didn't return anything from your `" + type + "` ") + "function. Please return a value or `null`.");
|
|
3372
|
-
} catch (e) {
|
|
3373
|
-
return {
|
|
3374
|
-
type: ResultType.error,
|
|
3375
|
-
result: e
|
|
3376
|
-
};
|
|
3377
|
-
} finally {
|
|
3378
|
-
if (onReject) {
|
|
3379
|
-
request.signal.removeEventListener("abort", onReject);
|
|
3380
|
-
}
|
|
3381
|
-
}
|
|
3382
|
-
return result;
|
|
3383
|
-
}
|
|
3384
|
-
async function convertHandlerResultToDataResult(handlerResult) {
|
|
3385
|
-
let {
|
|
3386
|
-
result,
|
|
3387
|
-
type,
|
|
3388
|
-
status
|
|
3389
|
-
} = handlerResult;
|
|
3390
|
-
if (isResponse(result)) {
|
|
3391
|
-
let data;
|
|
3392
|
-
try {
|
|
3393
|
-
let contentType = result.headers.get("Content-Type");
|
|
3394
|
-
if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
|
3395
|
-
if (result.body == null) {
|
|
3396
|
-
data = null;
|
|
3397
|
-
} else {
|
|
3398
|
-
data = await result.json();
|
|
3399
|
-
}
|
|
3400
|
-
} else {
|
|
3401
|
-
data = await result.text();
|
|
3402
|
-
}
|
|
3403
|
-
} catch (e) {
|
|
3404
|
-
return {
|
|
3405
|
-
type: ResultType.error,
|
|
3406
|
-
error: e
|
|
3407
|
-
};
|
|
3408
|
-
}
|
|
3409
|
-
if (type === ResultType.error) {
|
|
3410
|
-
return {
|
|
3411
|
-
type: ResultType.error,
|
|
3412
|
-
error: new ErrorResponseImpl(result.status, result.statusText, data),
|
|
3413
|
-
statusCode: result.status,
|
|
3414
|
-
headers: result.headers
|
|
3415
|
-
};
|
|
3416
|
-
}
|
|
3417
|
-
return {
|
|
3418
|
-
type: ResultType.data,
|
|
3419
|
-
data,
|
|
3420
|
-
statusCode: result.status,
|
|
3421
|
-
headers: result.headers
|
|
3422
|
-
};
|
|
3423
|
-
}
|
|
3424
|
-
if (type === ResultType.error) {
|
|
3425
|
-
return {
|
|
3426
|
-
type: ResultType.error,
|
|
3427
|
-
error: result,
|
|
3428
|
-
statusCode: isRouteErrorResponse(result) ? result.status : status
|
|
3429
|
-
};
|
|
3430
|
-
}
|
|
3431
|
-
if (isDeferredData(result)) {
|
|
3432
|
-
var _result$init, _result$init2;
|
|
3433
|
-
return {
|
|
3434
|
-
type: ResultType.deferred,
|
|
3435
|
-
deferredData: result,
|
|
3436
|
-
statusCode: (_result$init = result.init) == null ? void 0 : _result$init.status,
|
|
3437
|
-
headers: ((_result$init2 = result.init) == null ? void 0 : _result$init2.headers) && new Headers(result.init.headers)
|
|
3438
|
-
};
|
|
3439
|
-
}
|
|
3440
|
-
return {
|
|
3441
|
-
type: ResultType.data,
|
|
3442
|
-
data: result,
|
|
3443
|
-
statusCode: status
|
|
3444
|
-
};
|
|
3445
|
-
}
|
|
3446
|
-
function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename, v7_relativeSplatPath) {
|
|
3447
|
-
let location = response.headers.get("Location");
|
|
3448
|
-
invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
|
|
3449
|
-
if (!ABSOLUTE_URL_REGEX.test(location)) {
|
|
3450
|
-
let trimmedMatches = matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1);
|
|
3451
|
-
location = normalizeTo(new URL(request.url), trimmedMatches, basename, true, location, v7_relativeSplatPath);
|
|
3452
|
-
response.headers.set("Location", location);
|
|
3453
|
-
}
|
|
3454
|
-
return response;
|
|
3455
|
-
}
|
|
3456
|
-
function normalizeRedirectLocation(location, currentUrl, basename) {
|
|
3457
|
-
if (ABSOLUTE_URL_REGEX.test(location)) {
|
|
3458
|
-
let normalizedLocation = location;
|
|
3459
|
-
let url = normalizedLocation.startsWith("//") ? new URL(currentUrl.protocol + normalizedLocation) : new URL(normalizedLocation);
|
|
3460
|
-
let isSameBasename = stripBasename(url.pathname, basename) != null;
|
|
3461
|
-
if (url.origin === currentUrl.origin && isSameBasename) {
|
|
3462
|
-
return url.pathname + url.search + url.hash;
|
|
3463
|
-
}
|
|
3464
|
-
}
|
|
3465
|
-
return location;
|
|
3466
|
-
}
|
|
3467
|
-
function createClientSideRequest(history, location, signal, submission) {
|
|
3468
|
-
let url = history.createURL(stripHashFromPath(location)).toString();
|
|
3469
|
-
let init = {
|
|
3470
|
-
signal
|
|
3471
|
-
};
|
|
3472
|
-
if (submission && isMutationMethod(submission.formMethod)) {
|
|
3473
|
-
let {
|
|
3474
|
-
formMethod,
|
|
3475
|
-
formEncType
|
|
3476
|
-
} = submission;
|
|
3477
|
-
init.method = formMethod.toUpperCase();
|
|
3478
|
-
if (formEncType === "application/json") {
|
|
3479
|
-
init.headers = new Headers({
|
|
3480
|
-
"Content-Type": formEncType
|
|
3481
|
-
});
|
|
3482
|
-
init.body = JSON.stringify(submission.json);
|
|
3483
|
-
} else if (formEncType === "text/plain") {
|
|
3484
|
-
init.body = submission.text;
|
|
3485
|
-
} else if (formEncType === "application/x-www-form-urlencoded" && submission.formData) {
|
|
3486
|
-
init.body = convertFormDataToSearchParams(submission.formData);
|
|
3487
|
-
} else {
|
|
3488
|
-
init.body = submission.formData;
|
|
3489
|
-
}
|
|
3490
|
-
}
|
|
3491
|
-
return new Request(url, init);
|
|
3492
|
-
}
|
|
3493
|
-
function convertFormDataToSearchParams(formData) {
|
|
3494
|
-
let searchParams = new URLSearchParams();
|
|
3495
|
-
for (let [key, value] of formData.entries()) {
|
|
3496
|
-
searchParams.append(key, typeof value === "string" ? value : value.name);
|
|
3497
|
-
}
|
|
3498
|
-
return searchParams;
|
|
3499
|
-
}
|
|
3500
|
-
function convertSearchParamsToFormData(searchParams) {
|
|
3501
|
-
let formData = new FormData();
|
|
3502
|
-
for (let [key, value] of searchParams.entries()) {
|
|
3503
|
-
formData.append(key, value);
|
|
3504
|
-
}
|
|
3505
|
-
return formData;
|
|
3506
|
-
}
|
|
3507
|
-
function processRouteLoaderData(matches, matchesToLoad, results, pendingActionResult, activeDeferreds, skipLoaderErrorBubbling) {
|
|
3508
|
-
let loaderData = {};
|
|
3509
|
-
let errors = null;
|
|
3510
|
-
let statusCode;
|
|
3511
|
-
let foundError = false;
|
|
3512
|
-
let loaderHeaders = {};
|
|
3513
|
-
let pendingError = pendingActionResult && isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : void 0;
|
|
3514
|
-
results.forEach((result, index) => {
|
|
3515
|
-
let id = matchesToLoad[index].route.id;
|
|
3516
|
-
invariant(!isRedirectResult(result), "Cannot handle redirect results in processLoaderData");
|
|
3517
|
-
if (isErrorResult(result)) {
|
|
3518
|
-
let error = result.error;
|
|
3519
|
-
if (pendingError !== void 0) {
|
|
3520
|
-
error = pendingError;
|
|
3521
|
-
pendingError = void 0;
|
|
3522
|
-
}
|
|
3523
|
-
errors = errors || {};
|
|
3524
|
-
if (skipLoaderErrorBubbling) {
|
|
3525
|
-
errors[id] = error;
|
|
3526
|
-
} else {
|
|
3527
|
-
let boundaryMatch = findNearestBoundary(matches, id);
|
|
3528
|
-
if (errors[boundaryMatch.route.id] == null) {
|
|
3529
|
-
errors[boundaryMatch.route.id] = error;
|
|
3530
|
-
}
|
|
3531
|
-
}
|
|
3532
|
-
loaderData[id] = void 0;
|
|
3533
|
-
if (!foundError) {
|
|
3534
|
-
foundError = true;
|
|
3535
|
-
statusCode = isRouteErrorResponse(result.error) ? result.error.status : 500;
|
|
3536
|
-
}
|
|
3537
|
-
if (result.headers) {
|
|
3538
|
-
loaderHeaders[id] = result.headers;
|
|
3539
|
-
}
|
|
3540
|
-
} else {
|
|
3541
|
-
if (isDeferredResult(result)) {
|
|
3542
|
-
activeDeferreds.set(id, result.deferredData);
|
|
3543
|
-
loaderData[id] = result.deferredData.data;
|
|
3544
|
-
if (result.statusCode != null && result.statusCode !== 200 && !foundError) {
|
|
3545
|
-
statusCode = result.statusCode;
|
|
3546
|
-
}
|
|
3547
|
-
if (result.headers) {
|
|
3548
|
-
loaderHeaders[id] = result.headers;
|
|
3549
|
-
}
|
|
3550
|
-
} else {
|
|
3551
|
-
loaderData[id] = result.data;
|
|
3552
|
-
if (result.statusCode && result.statusCode !== 200 && !foundError) {
|
|
3553
|
-
statusCode = result.statusCode;
|
|
3554
|
-
}
|
|
3555
|
-
if (result.headers) {
|
|
3556
|
-
loaderHeaders[id] = result.headers;
|
|
3557
|
-
}
|
|
3558
|
-
}
|
|
3559
|
-
}
|
|
3560
|
-
});
|
|
3561
|
-
if (pendingError !== void 0 && pendingActionResult) {
|
|
3562
|
-
errors = {
|
|
3563
|
-
[pendingActionResult[0]]: pendingError
|
|
3564
|
-
};
|
|
3565
|
-
loaderData[pendingActionResult[0]] = void 0;
|
|
3566
|
-
}
|
|
3567
|
-
return {
|
|
3568
|
-
loaderData,
|
|
3569
|
-
errors,
|
|
3570
|
-
statusCode: statusCode || 200,
|
|
3571
|
-
loaderHeaders
|
|
3572
|
-
};
|
|
3573
|
-
}
|
|
3574
|
-
function processLoaderData(state, matches, matchesToLoad, results, pendingActionResult, revalidatingFetchers, fetcherResults, activeDeferreds) {
|
|
3575
|
-
let {
|
|
3576
|
-
loaderData,
|
|
3577
|
-
errors
|
|
3578
|
-
} = processRouteLoaderData(
|
|
3579
|
-
matches,
|
|
3580
|
-
matchesToLoad,
|
|
3581
|
-
results,
|
|
3582
|
-
pendingActionResult,
|
|
3583
|
-
activeDeferreds,
|
|
3584
|
-
false
|
|
3585
|
-
// This method is only called client side so we always want to bubble
|
|
3586
|
-
);
|
|
3587
|
-
for (let index = 0; index < revalidatingFetchers.length; index++) {
|
|
3588
|
-
let {
|
|
3589
|
-
key,
|
|
3590
|
-
match,
|
|
3591
|
-
controller
|
|
3592
|
-
} = revalidatingFetchers[index];
|
|
3593
|
-
invariant(fetcherResults !== void 0 && fetcherResults[index] !== void 0, "Did not find corresponding fetcher result");
|
|
3594
|
-
let result = fetcherResults[index];
|
|
3595
|
-
if (controller && controller.signal.aborted) {
|
|
3596
|
-
continue;
|
|
3597
|
-
} else if (isErrorResult(result)) {
|
|
3598
|
-
let boundaryMatch = findNearestBoundary(state.matches, match == null ? void 0 : match.route.id);
|
|
3599
|
-
if (!(errors && errors[boundaryMatch.route.id])) {
|
|
3600
|
-
errors = _extends({}, errors, {
|
|
3601
|
-
[boundaryMatch.route.id]: result.error
|
|
3602
|
-
});
|
|
3603
|
-
}
|
|
3604
|
-
state.fetchers.delete(key);
|
|
3605
|
-
} else if (isRedirectResult(result)) {
|
|
3606
|
-
invariant(false, "Unhandled fetcher revalidation redirect");
|
|
3607
|
-
} else if (isDeferredResult(result)) {
|
|
3608
|
-
invariant(false, "Unhandled fetcher deferred data");
|
|
3609
|
-
} else {
|
|
3610
|
-
let doneFetcher = getDoneFetcher(result.data);
|
|
3611
|
-
state.fetchers.set(key, doneFetcher);
|
|
3612
|
-
}
|
|
3613
|
-
}
|
|
3614
|
-
return {
|
|
3615
|
-
loaderData,
|
|
3616
|
-
errors
|
|
3617
|
-
};
|
|
3618
|
-
}
|
|
3619
|
-
function mergeLoaderData(loaderData, newLoaderData, matches, errors) {
|
|
3620
|
-
let mergedLoaderData = _extends({}, newLoaderData);
|
|
3621
|
-
for (let match of matches) {
|
|
3622
|
-
let id = match.route.id;
|
|
3623
|
-
if (newLoaderData.hasOwnProperty(id)) {
|
|
3624
|
-
if (newLoaderData[id] !== void 0) {
|
|
3625
|
-
mergedLoaderData[id] = newLoaderData[id];
|
|
3626
|
-
}
|
|
3627
|
-
} else if (loaderData[id] !== void 0 && match.route.loader) {
|
|
3628
|
-
mergedLoaderData[id] = loaderData[id];
|
|
3629
|
-
}
|
|
3630
|
-
if (errors && errors.hasOwnProperty(id)) {
|
|
3631
|
-
break;
|
|
3632
|
-
}
|
|
3633
|
-
}
|
|
3634
|
-
return mergedLoaderData;
|
|
3635
|
-
}
|
|
3636
|
-
function getActionDataForCommit(pendingActionResult) {
|
|
3637
|
-
if (!pendingActionResult) {
|
|
3638
|
-
return {};
|
|
3639
|
-
}
|
|
3640
|
-
return isErrorResult(pendingActionResult[1]) ? {
|
|
3641
|
-
// Clear out prior actionData on errors
|
|
3642
|
-
actionData: {}
|
|
3643
|
-
} : {
|
|
3644
|
-
actionData: {
|
|
3645
|
-
[pendingActionResult[0]]: pendingActionResult[1].data
|
|
3646
|
-
}
|
|
3647
|
-
};
|
|
3648
|
-
}
|
|
3649
|
-
function findNearestBoundary(matches, routeId) {
|
|
3650
|
-
let eligibleMatches = routeId ? matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1) : [...matches];
|
|
3651
|
-
return eligibleMatches.reverse().find((m) => m.route.hasErrorBoundary === true) || matches[0];
|
|
3652
|
-
}
|
|
3653
|
-
function getShortCircuitMatches(routes) {
|
|
3654
|
-
let route = routes.length === 1 ? routes[0] : routes.find((r) => r.index || !r.path || r.path === "/") || {
|
|
3655
|
-
id: "__shim-error-route__"
|
|
3656
|
-
};
|
|
3657
|
-
return {
|
|
3658
|
-
matches: [{
|
|
3659
|
-
params: {},
|
|
3660
|
-
pathname: "",
|
|
3661
|
-
pathnameBase: "",
|
|
3662
|
-
route
|
|
3663
|
-
}],
|
|
3664
|
-
route
|
|
3665
|
-
};
|
|
3666
|
-
}
|
|
3667
|
-
function getInternalRouterError(status, _temp5) {
|
|
3668
|
-
let {
|
|
3669
|
-
pathname,
|
|
3670
|
-
routeId,
|
|
3671
|
-
method,
|
|
3672
|
-
type,
|
|
3673
|
-
message
|
|
3674
|
-
} = _temp5 === void 0 ? {} : _temp5;
|
|
3675
|
-
let statusText = "Unknown Server Error";
|
|
3676
|
-
let errorMessage = "Unknown @remix-run/router error";
|
|
3677
|
-
if (status === 400) {
|
|
3678
|
-
statusText = "Bad Request";
|
|
3679
|
-
if (type === "route-discovery") {
|
|
3680
|
-
errorMessage = 'Unable to match URL "' + pathname + '" - the `children()` function for ' + ("route `" + routeId + "` threw the following error:\n" + message);
|
|
3681
|
-
} else if (method && pathname && routeId) {
|
|
3682
|
-
errorMessage = "You made a " + method + ' request to "' + pathname + '" but ' + ('did not provide a `loader` for route "' + routeId + '", ') + "so there is no way to handle the request.";
|
|
3683
|
-
} else if (type === "defer-action") {
|
|
3684
|
-
errorMessage = "defer() is not supported in actions";
|
|
3685
|
-
} else if (type === "invalid-body") {
|
|
3686
|
-
errorMessage = "Unable to encode submission body";
|
|
3687
|
-
}
|
|
3688
|
-
} else if (status === 403) {
|
|
3689
|
-
statusText = "Forbidden";
|
|
3690
|
-
errorMessage = 'Route "' + routeId + '" does not match URL "' + pathname + '"';
|
|
3691
|
-
} else if (status === 404) {
|
|
3692
|
-
statusText = "Not Found";
|
|
3693
|
-
errorMessage = 'No route matches URL "' + pathname + '"';
|
|
3694
|
-
} else if (status === 405) {
|
|
3695
|
-
statusText = "Method Not Allowed";
|
|
3696
|
-
if (method && pathname && routeId) {
|
|
3697
|
-
errorMessage = "You made a " + method.toUpperCase() + ' request to "' + pathname + '" but ' + ('did not provide an `action` for route "' + routeId + '", ') + "so there is no way to handle the request.";
|
|
3698
|
-
} else if (method) {
|
|
3699
|
-
errorMessage = 'Invalid request method "' + method.toUpperCase() + '"';
|
|
3700
|
-
}
|
|
3701
|
-
}
|
|
3702
|
-
return new ErrorResponseImpl(status || 500, statusText, new Error(errorMessage), true);
|
|
3703
|
-
}
|
|
3704
|
-
function findRedirect(results) {
|
|
3705
|
-
for (let i = results.length - 1; i >= 0; i--) {
|
|
3706
|
-
let result = results[i];
|
|
3707
|
-
if (isRedirectResult(result)) {
|
|
3708
|
-
return {
|
|
3709
|
-
result,
|
|
3710
|
-
idx: i
|
|
3711
|
-
};
|
|
3712
|
-
}
|
|
3713
|
-
}
|
|
3714
|
-
}
|
|
3715
|
-
function stripHashFromPath(path) {
|
|
3716
|
-
let parsedPath = typeof path === "string" ? parsePath(path) : path;
|
|
3717
|
-
return createPath(_extends({}, parsedPath, {
|
|
3718
|
-
hash: ""
|
|
3719
|
-
}));
|
|
3720
|
-
}
|
|
3721
|
-
function isHashChangeOnly(a, b) {
|
|
3722
|
-
if (a.pathname !== b.pathname || a.search !== b.search) {
|
|
3723
|
-
return false;
|
|
3724
|
-
}
|
|
3725
|
-
if (a.hash === "") {
|
|
3726
|
-
return b.hash !== "";
|
|
3727
|
-
} else if (a.hash === b.hash) {
|
|
3728
|
-
return true;
|
|
3729
|
-
} else if (b.hash !== "") {
|
|
3730
|
-
return true;
|
|
3731
|
-
}
|
|
3732
|
-
return false;
|
|
3733
|
-
}
|
|
3734
|
-
function isPromise(val) {
|
|
3735
|
-
return typeof val === "object" && val != null && "then" in val;
|
|
3736
|
-
}
|
|
3737
|
-
function isHandlerResult(result) {
|
|
3738
|
-
return result != null && typeof result === "object" && "type" in result && "result" in result && (result.type === ResultType.data || result.type === ResultType.error);
|
|
3739
|
-
}
|
|
3740
|
-
function isRedirectHandlerResult(result) {
|
|
3741
|
-
return isResponse(result.result) && redirectStatusCodes.has(result.result.status);
|
|
3742
|
-
}
|
|
3743
|
-
function isDeferredResult(result) {
|
|
3744
|
-
return result.type === ResultType.deferred;
|
|
3745
|
-
}
|
|
3746
|
-
function isErrorResult(result) {
|
|
3747
|
-
return result.type === ResultType.error;
|
|
3748
|
-
}
|
|
3749
|
-
function isRedirectResult(result) {
|
|
3750
|
-
return (result && result.type) === ResultType.redirect;
|
|
3751
|
-
}
|
|
3752
|
-
function isDeferredData(value) {
|
|
3753
|
-
let deferred = value;
|
|
3754
|
-
return deferred && typeof deferred === "object" && typeof deferred.data === "object" && typeof deferred.subscribe === "function" && typeof deferred.cancel === "function" && typeof deferred.resolveData === "function";
|
|
3755
|
-
}
|
|
3756
|
-
function isResponse(value) {
|
|
3757
|
-
return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
|
|
3758
|
-
}
|
|
3759
|
-
function isRedirectResponse(result) {
|
|
3760
|
-
if (!isResponse(result)) {
|
|
3761
|
-
return false;
|
|
3762
|
-
}
|
|
3763
|
-
let status = result.status;
|
|
3764
|
-
let location = result.headers.get("Location");
|
|
3765
|
-
return status >= 300 && status <= 399 && location != null;
|
|
3766
|
-
}
|
|
3767
|
-
function isValidMethod(method) {
|
|
3768
|
-
return validRequestMethods.has(method.toLowerCase());
|
|
3769
|
-
}
|
|
3770
|
-
function isMutationMethod(method) {
|
|
3771
|
-
return validMutationMethods.has(method.toLowerCase());
|
|
3772
|
-
}
|
|
3773
|
-
async function resolveDeferredResults(currentMatches, matchesToLoad, results, signals, isFetcher, currentLoaderData) {
|
|
3774
|
-
for (let index = 0; index < results.length; index++) {
|
|
3775
|
-
let result = results[index];
|
|
3776
|
-
let match = matchesToLoad[index];
|
|
3777
|
-
if (!match) {
|
|
3778
|
-
continue;
|
|
3779
|
-
}
|
|
3780
|
-
let currentMatch = currentMatches.find((m) => m.route.id === match.route.id);
|
|
3781
|
-
let isRevalidatingLoader = currentMatch != null && !isNewRouteInstance(currentMatch, match) && (currentLoaderData && currentLoaderData[match.route.id]) !== void 0;
|
|
3782
|
-
if (isDeferredResult(result) && (isFetcher || isRevalidatingLoader)) {
|
|
3783
|
-
let signal = signals[index];
|
|
3784
|
-
invariant(signal, "Expected an AbortSignal for revalidating fetcher deferred result");
|
|
3785
|
-
await resolveDeferredData(result, signal, isFetcher).then((result2) => {
|
|
3786
|
-
if (result2) {
|
|
3787
|
-
results[index] = result2 || results[index];
|
|
3788
|
-
}
|
|
3789
|
-
});
|
|
3790
|
-
}
|
|
3791
|
-
}
|
|
3792
|
-
}
|
|
3793
|
-
async function resolveDeferredData(result, signal, unwrap) {
|
|
3794
|
-
if (unwrap === void 0) {
|
|
3795
|
-
unwrap = false;
|
|
3796
|
-
}
|
|
3797
|
-
let aborted = await result.deferredData.resolveData(signal);
|
|
3798
|
-
if (aborted) {
|
|
3799
|
-
return;
|
|
3800
|
-
}
|
|
3801
|
-
if (unwrap) {
|
|
3802
|
-
try {
|
|
3803
|
-
return {
|
|
3804
|
-
type: ResultType.data,
|
|
3805
|
-
data: result.deferredData.unwrappedData
|
|
3806
|
-
};
|
|
3807
|
-
} catch (e) {
|
|
3808
|
-
return {
|
|
3809
|
-
type: ResultType.error,
|
|
3810
|
-
error: e
|
|
3811
|
-
};
|
|
3812
|
-
}
|
|
3813
|
-
}
|
|
3814
|
-
return {
|
|
3815
|
-
type: ResultType.data,
|
|
3816
|
-
data: result.deferredData.data
|
|
3817
|
-
};
|
|
3818
|
-
}
|
|
3819
|
-
function hasNakedIndexQuery(search) {
|
|
3820
|
-
return new URLSearchParams(search).getAll("index").some((v) => v === "");
|
|
3821
|
-
}
|
|
3822
|
-
function getTargetMatch(matches, location) {
|
|
3823
|
-
let search = typeof location === "string" ? parsePath(location).search : location.search;
|
|
3824
|
-
if (matches[matches.length - 1].route.index && hasNakedIndexQuery(search || "")) {
|
|
3825
|
-
return matches[matches.length - 1];
|
|
3826
|
-
}
|
|
3827
|
-
let pathMatches = getPathContributingMatches(matches);
|
|
3828
|
-
return pathMatches[pathMatches.length - 1];
|
|
3829
|
-
}
|
|
3830
|
-
function getSubmissionFromNavigation(navigation) {
|
|
3831
|
-
let {
|
|
3832
|
-
formMethod,
|
|
3833
|
-
formAction,
|
|
3834
|
-
formEncType,
|
|
3835
|
-
text,
|
|
3836
|
-
formData,
|
|
3837
|
-
json: json3
|
|
3838
|
-
} = navigation;
|
|
3839
|
-
if (!formMethod || !formAction || !formEncType) {
|
|
3840
|
-
return;
|
|
3841
|
-
}
|
|
3842
|
-
if (text != null) {
|
|
3843
|
-
return {
|
|
3844
|
-
formMethod,
|
|
3845
|
-
formAction,
|
|
3846
|
-
formEncType,
|
|
3847
|
-
formData: void 0,
|
|
3848
|
-
json: void 0,
|
|
3849
|
-
text
|
|
3850
|
-
};
|
|
3851
|
-
} else if (formData != null) {
|
|
3852
|
-
return {
|
|
3853
|
-
formMethod,
|
|
3854
|
-
formAction,
|
|
3855
|
-
formEncType,
|
|
3856
|
-
formData,
|
|
3857
|
-
json: void 0,
|
|
3858
|
-
text: void 0
|
|
3859
|
-
};
|
|
3860
|
-
} else if (json3 !== void 0) {
|
|
3861
|
-
return {
|
|
3862
|
-
formMethod,
|
|
3863
|
-
formAction,
|
|
3864
|
-
formEncType,
|
|
3865
|
-
formData: void 0,
|
|
3866
|
-
json: json3,
|
|
3867
|
-
text: void 0
|
|
3868
|
-
};
|
|
3869
|
-
}
|
|
3870
|
-
}
|
|
3871
|
-
function getLoadingNavigation(location, submission) {
|
|
3872
|
-
if (submission) {
|
|
3873
|
-
let navigation = {
|
|
3874
|
-
state: "loading",
|
|
3875
|
-
location,
|
|
3876
|
-
formMethod: submission.formMethod,
|
|
3877
|
-
formAction: submission.formAction,
|
|
3878
|
-
formEncType: submission.formEncType,
|
|
3879
|
-
formData: submission.formData,
|
|
3880
|
-
json: submission.json,
|
|
3881
|
-
text: submission.text
|
|
3882
|
-
};
|
|
3883
|
-
return navigation;
|
|
3884
|
-
} else {
|
|
3885
|
-
let navigation = {
|
|
3886
|
-
state: "loading",
|
|
3887
|
-
location,
|
|
3888
|
-
formMethod: void 0,
|
|
3889
|
-
formAction: void 0,
|
|
3890
|
-
formEncType: void 0,
|
|
3891
|
-
formData: void 0,
|
|
3892
|
-
json: void 0,
|
|
3893
|
-
text: void 0
|
|
3894
|
-
};
|
|
3895
|
-
return navigation;
|
|
3896
|
-
}
|
|
3897
|
-
}
|
|
3898
|
-
function getSubmittingNavigation(location, submission) {
|
|
3899
|
-
let navigation = {
|
|
3900
|
-
state: "submitting",
|
|
3901
|
-
location,
|
|
3902
|
-
formMethod: submission.formMethod,
|
|
3903
|
-
formAction: submission.formAction,
|
|
3904
|
-
formEncType: submission.formEncType,
|
|
3905
|
-
formData: submission.formData,
|
|
3906
|
-
json: submission.json,
|
|
3907
|
-
text: submission.text
|
|
3908
|
-
};
|
|
3909
|
-
return navigation;
|
|
3910
|
-
}
|
|
3911
|
-
function getLoadingFetcher(submission, data) {
|
|
3912
|
-
if (submission) {
|
|
3913
|
-
let fetcher = {
|
|
3914
|
-
state: "loading",
|
|
3915
|
-
formMethod: submission.formMethod,
|
|
3916
|
-
formAction: submission.formAction,
|
|
3917
|
-
formEncType: submission.formEncType,
|
|
3918
|
-
formData: submission.formData,
|
|
3919
|
-
json: submission.json,
|
|
3920
|
-
text: submission.text,
|
|
3921
|
-
data
|
|
3922
|
-
};
|
|
3923
|
-
return fetcher;
|
|
3924
|
-
} else {
|
|
3925
|
-
let fetcher = {
|
|
3926
|
-
state: "loading",
|
|
3927
|
-
formMethod: void 0,
|
|
3928
|
-
formAction: void 0,
|
|
3929
|
-
formEncType: void 0,
|
|
3930
|
-
formData: void 0,
|
|
3931
|
-
json: void 0,
|
|
3932
|
-
text: void 0,
|
|
3933
|
-
data
|
|
3934
|
-
};
|
|
3935
|
-
return fetcher;
|
|
3936
|
-
}
|
|
3937
|
-
}
|
|
3938
|
-
function getSubmittingFetcher(submission, existingFetcher) {
|
|
3939
|
-
let fetcher = {
|
|
3940
|
-
state: "submitting",
|
|
3941
|
-
formMethod: submission.formMethod,
|
|
3942
|
-
formAction: submission.formAction,
|
|
3943
|
-
formEncType: submission.formEncType,
|
|
3944
|
-
formData: submission.formData,
|
|
3945
|
-
json: submission.json,
|
|
3946
|
-
text: submission.text,
|
|
3947
|
-
data: existingFetcher ? existingFetcher.data : void 0
|
|
3948
|
-
};
|
|
3949
|
-
return fetcher;
|
|
3950
|
-
}
|
|
3951
|
-
function getDoneFetcher(data) {
|
|
3952
|
-
let fetcher = {
|
|
3953
|
-
state: "idle",
|
|
3954
|
-
formMethod: void 0,
|
|
3955
|
-
formAction: void 0,
|
|
3956
|
-
formEncType: void 0,
|
|
3957
|
-
formData: void 0,
|
|
3958
|
-
json: void 0,
|
|
3959
|
-
text: void 0,
|
|
3960
|
-
data
|
|
3961
|
-
};
|
|
3962
|
-
return fetcher;
|
|
3963
|
-
}
|
|
3964
|
-
function restoreAppliedTransitions(_window, transitions) {
|
|
3965
|
-
try {
|
|
3966
|
-
let sessionPositions = _window.sessionStorage.getItem(TRANSITIONS_STORAGE_KEY);
|
|
3967
|
-
if (sessionPositions) {
|
|
3968
|
-
let json3 = JSON.parse(sessionPositions);
|
|
3969
|
-
for (let [k, v] of Object.entries(json3 || {})) {
|
|
3970
|
-
if (v && Array.isArray(v)) {
|
|
3971
|
-
transitions.set(k, new Set(v || []));
|
|
3972
|
-
}
|
|
3973
|
-
}
|
|
3974
|
-
}
|
|
3975
|
-
} catch (e) {
|
|
3976
|
-
}
|
|
3977
|
-
}
|
|
3978
|
-
function persistAppliedTransitions(_window, transitions) {
|
|
3979
|
-
if (transitions.size > 0) {
|
|
3980
|
-
let json3 = {};
|
|
3981
|
-
for (let [k, v] of transitions) {
|
|
3982
|
-
json3[k] = [...v];
|
|
3983
|
-
}
|
|
3984
|
-
try {
|
|
3985
|
-
_window.sessionStorage.setItem(TRANSITIONS_STORAGE_KEY, JSON.stringify(json3));
|
|
3986
|
-
} catch (error) {
|
|
3987
|
-
warning(false, "Failed to save applied view transitions in sessionStorage (" + error + ").");
|
|
3988
|
-
}
|
|
3989
|
-
}
|
|
3990
|
-
}
|
|
3991
|
-
const router = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3992
|
-
__proto__: null,
|
|
3993
|
-
AbortedDeferredError,
|
|
3994
|
-
get Action() {
|
|
3995
|
-
return Action;
|
|
3996
|
-
},
|
|
3997
|
-
IDLE_BLOCKER,
|
|
3998
|
-
IDLE_FETCHER,
|
|
3999
|
-
IDLE_NAVIGATION,
|
|
4000
|
-
UNSAFE_DEFERRED_SYMBOL,
|
|
4001
|
-
UNSAFE_DeferredData: DeferredData,
|
|
4002
|
-
UNSAFE_ErrorResponseImpl: ErrorResponseImpl,
|
|
4003
|
-
UNSAFE_convertRouteMatchToUiMatch: convertRouteMatchToUiMatch,
|
|
4004
|
-
UNSAFE_convertRoutesToDataRoutes: convertRoutesToDataRoutes,
|
|
4005
|
-
UNSAFE_getResolveToMatches: getResolveToMatches,
|
|
4006
|
-
UNSAFE_invariant: invariant,
|
|
4007
|
-
UNSAFE_warning: warning,
|
|
4008
|
-
createBrowserHistory,
|
|
4009
|
-
createHashHistory,
|
|
4010
|
-
createMemoryHistory,
|
|
4011
|
-
createPath,
|
|
4012
|
-
createRouter,
|
|
4013
|
-
createStaticHandler,
|
|
4014
|
-
defer,
|
|
4015
|
-
generatePath,
|
|
4016
|
-
getStaticContextFromError,
|
|
4017
|
-
getToPathname,
|
|
4018
|
-
isDeferredData,
|
|
4019
|
-
isRouteErrorResponse,
|
|
4020
|
-
joinPaths,
|
|
4021
|
-
json,
|
|
4022
|
-
matchPath,
|
|
4023
|
-
matchRoutes,
|
|
4024
|
-
normalizePathname,
|
|
4025
|
-
parsePath,
|
|
4026
|
-
redirect,
|
|
4027
|
-
redirectDocument,
|
|
4028
|
-
resolvePath,
|
|
4029
|
-
resolveTo,
|
|
4030
|
-
stripBasename
|
|
4031
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
4032
|
-
export {
|
|
4033
|
-
Action as A,
|
|
4034
|
-
ErrorResponseImpl as E,
|
|
4035
|
-
IDLE_BLOCKER as I,
|
|
4036
|
-
invariant as a,
|
|
4037
|
-
resolveTo as b,
|
|
4038
|
-
matchRoutes as c,
|
|
4039
|
-
convertRouteMatchToUiMatch as d,
|
|
4040
|
-
createMemoryHistory as e,
|
|
4041
|
-
AbortedDeferredError as f,
|
|
4042
|
-
getResolveToMatches as g,
|
|
4043
|
-
createRouter as h,
|
|
4044
|
-
isRouteErrorResponse as i,
|
|
4045
|
-
joinPaths as j,
|
|
4046
|
-
createPath as k,
|
|
4047
|
-
defer as l,
|
|
4048
|
-
matchPath as m,
|
|
4049
|
-
generatePath as n,
|
|
4050
|
-
json as o,
|
|
4051
|
-
parsePath as p,
|
|
4052
|
-
redirect as q,
|
|
4053
|
-
router as r,
|
|
4054
|
-
stripBasename as s,
|
|
4055
|
-
redirectDocument as t,
|
|
4056
|
-
resolvePath as u,
|
|
4057
|
-
createBrowserHistory as v,
|
|
4058
|
-
warning as w,
|
|
4059
|
-
createHashHistory as x,
|
|
4060
|
-
IDLE_FETCHER as y
|
|
4061
|
-
};
|
|
4062
|
-
//# sourceMappingURL=router-ButO1QyY.js.map
|