@inventreedb/ui 0.11.1 → 0.11.3
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/CHANGELOG.md +17 -0
- package/dist/.vite/manifest.json +86 -0
- package/dist/components/Boundary.js +16 -7
- package/dist/components/Boundary.js.map +1 -1
- package/dist/components/StylishText.d.ts +6 -0
- package/dist/components/StylishText.js +36 -0
- package/dist/components/StylishText.js.map +1 -0
- package/dist/components/nav/DetailDrawer.css.d.ts +1 -0
- package/dist/components/nav/DetailDrawer.css.js +6 -0
- package/dist/components/nav/DetailDrawer.css.js.map +1 -0
- package/dist/components/nav/DetailDrawer.d.ts +21 -0
- package/dist/components/nav/DetailDrawer.js +65 -0
- package/dist/components/nav/DetailDrawer.js.map +1 -0
- package/dist/enums/ApiEndpoints.d.ts +1 -0
- package/dist/enums/ApiEndpoints.js +1 -0
- package/dist/enums/ApiEndpoints.js.map +1 -1
- package/dist/enums/ModelType.d.ts +9 -0
- package/dist/enums/ModelType.js.map +1 -1
- package/dist/enums/Roles.d.ts +1 -0
- package/dist/enums/Roles.js +1 -0
- package/dist/enums/Roles.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/node_modules/@remix-run/router/dist/router.js +448 -0
- package/dist/node_modules/@remix-run/router/dist/router.js.map +1 -0
- package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconChevronLeft.js +8 -0
- package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconChevronLeft.js.map +1 -0
- package/dist/node_modules/react-router/dist/index.js +704 -0
- package/dist/node_modules/react-router/dist/index.js.map +1 -0
- package/dist/node_modules/react-router-dom/dist/index.js +526 -0
- package/dist/node_modules/react-router-dom/dist/index.js.map +1 -0
- package/dist/node_modules/zustand/esm/react/shallow.js +13 -0
- package/dist/node_modules/zustand/esm/react/shallow.js.map +1 -0
- package/dist/node_modules/zustand/esm/vanilla/shallow.js +57 -0
- package/dist/node_modules/zustand/esm/vanilla/shallow.js.map +1 -0
- package/dist/states/LocalLibState.d.ts +17 -0
- package/dist/states/LocalLibState.js +16 -0
- package/dist/states/LocalLibState.js.map +1 -0
- package/dist/types/Forms.d.ts +11 -6
- package/dist/types/Plugins.js +1 -1
- package/dist/types/Tables.d.ts +6 -0
- package/dist/ui.css +4 -0
- package/lib/components/Boundary.tsx +6 -3
- package/lib/components/StylishText.tsx +46 -0
- package/lib/components/nav/DetailDrawer.css.ts +6 -0
- package/lib/components/nav/DetailDrawer.tsx +108 -0
- package/lib/enums/ApiEndpoints.tsx +1 -0
- package/lib/enums/ModelType.tsx +13 -0
- package/lib/enums/Roles.tsx +1 -0
- package/lib/index.ts +15 -0
- package/lib/states/LocalLibState.tsx +23 -0
- package/lib/types/Forms.tsx +11 -6
- package/lib/types/Tables.tsx +8 -0
- package/package.json +4 -2
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
import { UNSAFE_invariant as invariant, joinPaths, parsePath, matchRoutes, UNSAFE_warning as warning, Action, UNSAFE_getResolveToMatches as getResolveToMatches, resolveTo, isRouteErrorResponse, AbortedDeferredError } from "../../@remix-run/router/dist/router.js";
|
|
2
|
+
import { createPath, matchPath, resolvePath } from "../../@remix-run/router/dist/router.js";
|
|
3
|
+
const React = window["React"];
|
|
4
|
+
function _extends() {
|
|
5
|
+
_extends = Object.assign ? Object.assign.bind() : function(target) {
|
|
6
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
7
|
+
var source = arguments[i];
|
|
8
|
+
for (var key in source) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
10
|
+
target[key] = source[key];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
return _extends.apply(this, arguments);
|
|
17
|
+
}
|
|
18
|
+
const DataRouterContext = /* @__PURE__ */ React.createContext(null);
|
|
19
|
+
if (process.env.NODE_ENV !== "production") {
|
|
20
|
+
DataRouterContext.displayName = "DataRouter";
|
|
21
|
+
}
|
|
22
|
+
const DataRouterStateContext = /* @__PURE__ */ React.createContext(null);
|
|
23
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24
|
+
DataRouterStateContext.displayName = "DataRouterState";
|
|
25
|
+
}
|
|
26
|
+
const AwaitContext = /* @__PURE__ */ React.createContext(null);
|
|
27
|
+
if (process.env.NODE_ENV !== "production") {
|
|
28
|
+
AwaitContext.displayName = "Await";
|
|
29
|
+
}
|
|
30
|
+
const NavigationContext = /* @__PURE__ */ React.createContext(null);
|
|
31
|
+
if (process.env.NODE_ENV !== "production") {
|
|
32
|
+
NavigationContext.displayName = "Navigation";
|
|
33
|
+
}
|
|
34
|
+
const LocationContext = /* @__PURE__ */ React.createContext(null);
|
|
35
|
+
if (process.env.NODE_ENV !== "production") {
|
|
36
|
+
LocationContext.displayName = "Location";
|
|
37
|
+
}
|
|
38
|
+
const RouteContext = /* @__PURE__ */ React.createContext({
|
|
39
|
+
outlet: null,
|
|
40
|
+
matches: [],
|
|
41
|
+
isDataRoute: false
|
|
42
|
+
});
|
|
43
|
+
if (process.env.NODE_ENV !== "production") {
|
|
44
|
+
RouteContext.displayName = "Route";
|
|
45
|
+
}
|
|
46
|
+
const RouteErrorContext = /* @__PURE__ */ React.createContext(null);
|
|
47
|
+
if (process.env.NODE_ENV !== "production") {
|
|
48
|
+
RouteErrorContext.displayName = "RouteError";
|
|
49
|
+
}
|
|
50
|
+
function useHref(to, _temp) {
|
|
51
|
+
let {
|
|
52
|
+
relative
|
|
53
|
+
} = _temp === void 0 ? {} : _temp;
|
|
54
|
+
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(
|
|
55
|
+
false,
|
|
56
|
+
// TODO: This error is probably because they somehow have 2 versions of the
|
|
57
|
+
// router loaded. We can help them understand how to avoid that.
|
|
58
|
+
"useHref() may be used only in the context of a <Router> component."
|
|
59
|
+
) : invariant(false) : void 0;
|
|
60
|
+
let {
|
|
61
|
+
basename,
|
|
62
|
+
navigator
|
|
63
|
+
} = React.useContext(NavigationContext);
|
|
64
|
+
let {
|
|
65
|
+
hash,
|
|
66
|
+
pathname,
|
|
67
|
+
search
|
|
68
|
+
} = useResolvedPath(to, {
|
|
69
|
+
relative
|
|
70
|
+
});
|
|
71
|
+
let joinedPathname = pathname;
|
|
72
|
+
if (basename !== "/") {
|
|
73
|
+
joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
|
|
74
|
+
}
|
|
75
|
+
return navigator.createHref({
|
|
76
|
+
pathname: joinedPathname,
|
|
77
|
+
search,
|
|
78
|
+
hash
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function useInRouterContext() {
|
|
82
|
+
return React.useContext(LocationContext) != null;
|
|
83
|
+
}
|
|
84
|
+
function useLocation() {
|
|
85
|
+
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(
|
|
86
|
+
false,
|
|
87
|
+
// TODO: This error is probably because they somehow have 2 versions of the
|
|
88
|
+
// router loaded. We can help them understand how to avoid that.
|
|
89
|
+
"useLocation() may be used only in the context of a <Router> component."
|
|
90
|
+
) : invariant(false) : void 0;
|
|
91
|
+
return React.useContext(LocationContext).location;
|
|
92
|
+
}
|
|
93
|
+
const navigateEffectWarning = "You should call navigate() in a React.useEffect(), not when your component is first rendered.";
|
|
94
|
+
function useIsomorphicLayoutEffect(cb) {
|
|
95
|
+
let isStatic = React.useContext(NavigationContext).static;
|
|
96
|
+
if (!isStatic) {
|
|
97
|
+
React.useLayoutEffect(cb);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function useNavigate() {
|
|
101
|
+
let {
|
|
102
|
+
isDataRoute
|
|
103
|
+
} = React.useContext(RouteContext);
|
|
104
|
+
return isDataRoute ? useNavigateStable() : useNavigateUnstable();
|
|
105
|
+
}
|
|
106
|
+
function useNavigateUnstable() {
|
|
107
|
+
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(
|
|
108
|
+
false,
|
|
109
|
+
// TODO: This error is probably because they somehow have 2 versions of the
|
|
110
|
+
// router loaded. We can help them understand how to avoid that.
|
|
111
|
+
"useNavigate() may be used only in the context of a <Router> component."
|
|
112
|
+
) : invariant(false) : void 0;
|
|
113
|
+
let dataRouterContext = React.useContext(DataRouterContext);
|
|
114
|
+
let {
|
|
115
|
+
basename,
|
|
116
|
+
future,
|
|
117
|
+
navigator
|
|
118
|
+
} = React.useContext(NavigationContext);
|
|
119
|
+
let {
|
|
120
|
+
matches
|
|
121
|
+
} = React.useContext(RouteContext);
|
|
122
|
+
let {
|
|
123
|
+
pathname: locationPathname
|
|
124
|
+
} = useLocation();
|
|
125
|
+
let routePathnamesJson = JSON.stringify(getResolveToMatches(matches, future.v7_relativeSplatPath));
|
|
126
|
+
let activeRef = React.useRef(false);
|
|
127
|
+
useIsomorphicLayoutEffect(() => {
|
|
128
|
+
activeRef.current = true;
|
|
129
|
+
});
|
|
130
|
+
let navigate = React.useCallback(function(to, options) {
|
|
131
|
+
if (options === void 0) {
|
|
132
|
+
options = {};
|
|
133
|
+
}
|
|
134
|
+
process.env.NODE_ENV !== "production" ? warning(activeRef.current, navigateEffectWarning) : void 0;
|
|
135
|
+
if (!activeRef.current) return;
|
|
136
|
+
if (typeof to === "number") {
|
|
137
|
+
navigator.go(to);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let path = resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, options.relative === "path");
|
|
141
|
+
if (dataRouterContext == null && basename !== "/") {
|
|
142
|
+
path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
|
143
|
+
}
|
|
144
|
+
(!!options.replace ? navigator.replace : navigator.push)(path, options.state, options);
|
|
145
|
+
}, [basename, navigator, routePathnamesJson, locationPathname, dataRouterContext]);
|
|
146
|
+
return navigate;
|
|
147
|
+
}
|
|
148
|
+
function useParams() {
|
|
149
|
+
let {
|
|
150
|
+
matches
|
|
151
|
+
} = React.useContext(RouteContext);
|
|
152
|
+
let routeMatch = matches[matches.length - 1];
|
|
153
|
+
return routeMatch ? routeMatch.params : {};
|
|
154
|
+
}
|
|
155
|
+
function useResolvedPath(to, _temp2) {
|
|
156
|
+
let {
|
|
157
|
+
relative
|
|
158
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
159
|
+
let {
|
|
160
|
+
future
|
|
161
|
+
} = React.useContext(NavigationContext);
|
|
162
|
+
let {
|
|
163
|
+
matches
|
|
164
|
+
} = React.useContext(RouteContext);
|
|
165
|
+
let {
|
|
166
|
+
pathname: locationPathname
|
|
167
|
+
} = useLocation();
|
|
168
|
+
let routePathnamesJson = JSON.stringify(getResolveToMatches(matches, future.v7_relativeSplatPath));
|
|
169
|
+
return React.useMemo(() => resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, relative === "path"), [to, routePathnamesJson, locationPathname, relative]);
|
|
170
|
+
}
|
|
171
|
+
function useRoutes(routes, locationArg) {
|
|
172
|
+
return useRoutesImpl(routes, locationArg);
|
|
173
|
+
}
|
|
174
|
+
function useRoutesImpl(routes, locationArg, dataRouterState, future) {
|
|
175
|
+
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(
|
|
176
|
+
false,
|
|
177
|
+
// TODO: This error is probably because they somehow have 2 versions of the
|
|
178
|
+
// router loaded. We can help them understand how to avoid that.
|
|
179
|
+
"useRoutes() may be used only in the context of a <Router> component."
|
|
180
|
+
) : invariant(false) : void 0;
|
|
181
|
+
let {
|
|
182
|
+
navigator
|
|
183
|
+
} = React.useContext(NavigationContext);
|
|
184
|
+
let {
|
|
185
|
+
matches: parentMatches
|
|
186
|
+
} = React.useContext(RouteContext);
|
|
187
|
+
let routeMatch = parentMatches[parentMatches.length - 1];
|
|
188
|
+
let parentParams = routeMatch ? routeMatch.params : {};
|
|
189
|
+
let parentPathname = routeMatch ? routeMatch.pathname : "/";
|
|
190
|
+
let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
|
|
191
|
+
let parentRoute = routeMatch && routeMatch.route;
|
|
192
|
+
if (process.env.NODE_ENV !== "production") {
|
|
193
|
+
let parentPath = parentRoute && parentRoute.path || "";
|
|
194
|
+
warningOnce(parentPathname, !parentRoute || parentPath.endsWith("*"), "You rendered descendant <Routes> (or called `useRoutes()`) at " + ('"' + parentPathname + '" (under <Route path="' + parentPath + '">) but the ') + `parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
|
|
195
|
+
|
|
196
|
+
` + ('Please change the parent <Route path="' + parentPath + '"> to <Route ') + ('path="' + (parentPath === "/" ? "*" : parentPath + "/*") + '">.'));
|
|
197
|
+
}
|
|
198
|
+
let locationFromContext = useLocation();
|
|
199
|
+
let location;
|
|
200
|
+
if (locationArg) {
|
|
201
|
+
var _parsedLocationArg$pa;
|
|
202
|
+
let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
|
203
|
+
!(parentPathnameBase === "/" || ((_parsedLocationArg$pa = parsedLocationArg.pathname) == null ? void 0 : _parsedLocationArg$pa.startsWith(parentPathnameBase))) ? process.env.NODE_ENV !== "production" ? invariant(false, "When overriding the location using `<Routes location>` or `useRoutes(routes, location)`, the location pathname must begin with the portion of the URL pathname that was " + ('matched by all parent routes. The current pathname base is "' + parentPathnameBase + '" ') + ('but pathname "' + parsedLocationArg.pathname + '" was given in the `location` prop.')) : invariant(false) : void 0;
|
|
204
|
+
location = parsedLocationArg;
|
|
205
|
+
} else {
|
|
206
|
+
location = locationFromContext;
|
|
207
|
+
}
|
|
208
|
+
let pathname = location.pathname || "/";
|
|
209
|
+
let remainingPathname = pathname;
|
|
210
|
+
if (parentPathnameBase !== "/") {
|
|
211
|
+
let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
|
|
212
|
+
let segments = pathname.replace(/^\//, "").split("/");
|
|
213
|
+
remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
|
|
214
|
+
}
|
|
215
|
+
let matches = matchRoutes(routes, {
|
|
216
|
+
pathname: remainingPathname
|
|
217
|
+
});
|
|
218
|
+
if (process.env.NODE_ENV !== "production") {
|
|
219
|
+
process.env.NODE_ENV !== "production" ? warning(parentRoute || matches != null, 'No routes matched location "' + location.pathname + location.search + location.hash + '" ') : void 0;
|
|
220
|
+
process.env.NODE_ENV !== "production" ? warning(matches == null || matches[matches.length - 1].route.element !== void 0 || matches[matches.length - 1].route.Component !== void 0 || matches[matches.length - 1].route.lazy !== void 0, 'Matched leaf route at location "' + location.pathname + location.search + location.hash + '" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.') : void 0;
|
|
221
|
+
}
|
|
222
|
+
let renderedMatches = _renderMatches(matches && matches.map((match) => Object.assign({}, match, {
|
|
223
|
+
params: Object.assign({}, parentParams, match.params),
|
|
224
|
+
pathname: joinPaths([
|
|
225
|
+
parentPathnameBase,
|
|
226
|
+
// Re-encode pathnames that were decoded inside matchRoutes
|
|
227
|
+
navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname
|
|
228
|
+
]),
|
|
229
|
+
pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([
|
|
230
|
+
parentPathnameBase,
|
|
231
|
+
// Re-encode pathnames that were decoded inside matchRoutes
|
|
232
|
+
navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase
|
|
233
|
+
])
|
|
234
|
+
})), parentMatches, dataRouterState, future);
|
|
235
|
+
if (locationArg && renderedMatches) {
|
|
236
|
+
return /* @__PURE__ */ React.createElement(LocationContext.Provider, {
|
|
237
|
+
value: {
|
|
238
|
+
location: _extends({
|
|
239
|
+
pathname: "/",
|
|
240
|
+
search: "",
|
|
241
|
+
hash: "",
|
|
242
|
+
state: null,
|
|
243
|
+
key: "default"
|
|
244
|
+
}, location),
|
|
245
|
+
navigationType: Action.Pop
|
|
246
|
+
}
|
|
247
|
+
}, renderedMatches);
|
|
248
|
+
}
|
|
249
|
+
return renderedMatches;
|
|
250
|
+
}
|
|
251
|
+
function DefaultErrorComponent() {
|
|
252
|
+
let error = useRouteError();
|
|
253
|
+
let message = isRouteErrorResponse(error) ? error.status + " " + error.statusText : error instanceof Error ? error.message : JSON.stringify(error);
|
|
254
|
+
let stack = error instanceof Error ? error.stack : null;
|
|
255
|
+
let lightgrey = "rgba(200,200,200, 0.5)";
|
|
256
|
+
let preStyles = {
|
|
257
|
+
padding: "0.5rem",
|
|
258
|
+
backgroundColor: lightgrey
|
|
259
|
+
};
|
|
260
|
+
let codeStyles = {
|
|
261
|
+
padding: "2px 4px",
|
|
262
|
+
backgroundColor: lightgrey
|
|
263
|
+
};
|
|
264
|
+
let devInfo = null;
|
|
265
|
+
if (process.env.NODE_ENV !== "production") {
|
|
266
|
+
console.error("Error handled by React Router default ErrorBoundary:", error);
|
|
267
|
+
devInfo = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, "💿 Hey developer 👋"), /* @__PURE__ */ React.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ React.createElement("code", {
|
|
268
|
+
style: codeStyles
|
|
269
|
+
}, "ErrorBoundary"), " or", " ", /* @__PURE__ */ React.createElement("code", {
|
|
270
|
+
style: codeStyles
|
|
271
|
+
}, "errorElement"), " prop on your route."));
|
|
272
|
+
}
|
|
273
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ React.createElement("h3", {
|
|
274
|
+
style: {
|
|
275
|
+
fontStyle: "italic"
|
|
276
|
+
}
|
|
277
|
+
}, message), stack ? /* @__PURE__ */ React.createElement("pre", {
|
|
278
|
+
style: preStyles
|
|
279
|
+
}, stack) : null, devInfo);
|
|
280
|
+
}
|
|
281
|
+
const defaultErrorElement = /* @__PURE__ */ React.createElement(DefaultErrorComponent, null);
|
|
282
|
+
class RenderErrorBoundary extends React.Component {
|
|
283
|
+
constructor(props) {
|
|
284
|
+
super(props);
|
|
285
|
+
this.state = {
|
|
286
|
+
location: props.location,
|
|
287
|
+
revalidation: props.revalidation,
|
|
288
|
+
error: props.error
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
static getDerivedStateFromError(error) {
|
|
292
|
+
return {
|
|
293
|
+
error
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
static getDerivedStateFromProps(props, state) {
|
|
297
|
+
if (state.location !== props.location || state.revalidation !== "idle" && props.revalidation === "idle") {
|
|
298
|
+
return {
|
|
299
|
+
error: props.error,
|
|
300
|
+
location: props.location,
|
|
301
|
+
revalidation: props.revalidation
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
error: props.error !== void 0 ? props.error : state.error,
|
|
306
|
+
location: state.location,
|
|
307
|
+
revalidation: props.revalidation || state.revalidation
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
componentDidCatch(error, errorInfo) {
|
|
311
|
+
console.error("React Router caught the following error during render", error, errorInfo);
|
|
312
|
+
}
|
|
313
|
+
render() {
|
|
314
|
+
return this.state.error !== void 0 ? /* @__PURE__ */ React.createElement(RouteContext.Provider, {
|
|
315
|
+
value: this.props.routeContext
|
|
316
|
+
}, /* @__PURE__ */ React.createElement(RouteErrorContext.Provider, {
|
|
317
|
+
value: this.state.error,
|
|
318
|
+
children: this.props.component
|
|
319
|
+
})) : this.props.children;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function RenderedRoute(_ref) {
|
|
323
|
+
let {
|
|
324
|
+
routeContext,
|
|
325
|
+
match,
|
|
326
|
+
children
|
|
327
|
+
} = _ref;
|
|
328
|
+
let dataRouterContext = React.useContext(DataRouterContext);
|
|
329
|
+
if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
|
|
330
|
+
dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
|
|
331
|
+
}
|
|
332
|
+
return /* @__PURE__ */ React.createElement(RouteContext.Provider, {
|
|
333
|
+
value: routeContext
|
|
334
|
+
}, children);
|
|
335
|
+
}
|
|
336
|
+
function _renderMatches(matches, parentMatches, dataRouterState, future) {
|
|
337
|
+
var _dataRouterState;
|
|
338
|
+
if (parentMatches === void 0) {
|
|
339
|
+
parentMatches = [];
|
|
340
|
+
}
|
|
341
|
+
if (dataRouterState === void 0) {
|
|
342
|
+
dataRouterState = null;
|
|
343
|
+
}
|
|
344
|
+
if (future === void 0) {
|
|
345
|
+
future = null;
|
|
346
|
+
}
|
|
347
|
+
if (matches == null) {
|
|
348
|
+
var _future;
|
|
349
|
+
if (!dataRouterState) {
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
if (dataRouterState.errors) {
|
|
353
|
+
matches = dataRouterState.matches;
|
|
354
|
+
} else if ((_future = future) != null && _future.v7_partialHydration && parentMatches.length === 0 && !dataRouterState.initialized && dataRouterState.matches.length > 0) {
|
|
355
|
+
matches = dataRouterState.matches;
|
|
356
|
+
} else {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
let renderedMatches = matches;
|
|
361
|
+
let errors = (_dataRouterState = dataRouterState) == null ? void 0 : _dataRouterState.errors;
|
|
362
|
+
if (errors != null) {
|
|
363
|
+
let errorIndex = renderedMatches.findIndex((m) => m.route.id && (errors == null ? void 0 : errors[m.route.id]) !== void 0);
|
|
364
|
+
!(errorIndex >= 0) ? process.env.NODE_ENV !== "production" ? invariant(false, "Could not find a matching route for errors on route IDs: " + Object.keys(errors).join(",")) : invariant(false) : void 0;
|
|
365
|
+
renderedMatches = renderedMatches.slice(0, Math.min(renderedMatches.length, errorIndex + 1));
|
|
366
|
+
}
|
|
367
|
+
let renderFallback = false;
|
|
368
|
+
let fallbackIndex = -1;
|
|
369
|
+
if (dataRouterState && future && future.v7_partialHydration) {
|
|
370
|
+
for (let i = 0; i < renderedMatches.length; i++) {
|
|
371
|
+
let match = renderedMatches[i];
|
|
372
|
+
if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
|
|
373
|
+
fallbackIndex = i;
|
|
374
|
+
}
|
|
375
|
+
if (match.route.id) {
|
|
376
|
+
let {
|
|
377
|
+
loaderData,
|
|
378
|
+
errors: errors2
|
|
379
|
+
} = dataRouterState;
|
|
380
|
+
let needsToRunLoader = match.route.loader && loaderData[match.route.id] === void 0 && (!errors2 || errors2[match.route.id] === void 0);
|
|
381
|
+
if (match.route.lazy || needsToRunLoader) {
|
|
382
|
+
renderFallback = true;
|
|
383
|
+
if (fallbackIndex >= 0) {
|
|
384
|
+
renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
|
|
385
|
+
} else {
|
|
386
|
+
renderedMatches = [renderedMatches[0]];
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return renderedMatches.reduceRight((outlet, match, index) => {
|
|
394
|
+
let error;
|
|
395
|
+
let shouldRenderHydrateFallback = false;
|
|
396
|
+
let errorElement = null;
|
|
397
|
+
let hydrateFallbackElement = null;
|
|
398
|
+
if (dataRouterState) {
|
|
399
|
+
error = errors && match.route.id ? errors[match.route.id] : void 0;
|
|
400
|
+
errorElement = match.route.errorElement || defaultErrorElement;
|
|
401
|
+
if (renderFallback) {
|
|
402
|
+
if (fallbackIndex < 0 && index === 0) {
|
|
403
|
+
warningOnce("route-fallback", false, "No `HydrateFallback` element provided to render during initial hydration");
|
|
404
|
+
shouldRenderHydrateFallback = true;
|
|
405
|
+
hydrateFallbackElement = null;
|
|
406
|
+
} else if (fallbackIndex === index) {
|
|
407
|
+
shouldRenderHydrateFallback = true;
|
|
408
|
+
hydrateFallbackElement = match.route.hydrateFallbackElement || null;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
let matches2 = parentMatches.concat(renderedMatches.slice(0, index + 1));
|
|
413
|
+
let getChildren = () => {
|
|
414
|
+
let children;
|
|
415
|
+
if (error) {
|
|
416
|
+
children = errorElement;
|
|
417
|
+
} else if (shouldRenderHydrateFallback) {
|
|
418
|
+
children = hydrateFallbackElement;
|
|
419
|
+
} else if (match.route.Component) {
|
|
420
|
+
children = /* @__PURE__ */ React.createElement(match.route.Component, null);
|
|
421
|
+
} else if (match.route.element) {
|
|
422
|
+
children = match.route.element;
|
|
423
|
+
} else {
|
|
424
|
+
children = outlet;
|
|
425
|
+
}
|
|
426
|
+
return /* @__PURE__ */ React.createElement(RenderedRoute, {
|
|
427
|
+
match,
|
|
428
|
+
routeContext: {
|
|
429
|
+
outlet,
|
|
430
|
+
matches: matches2,
|
|
431
|
+
isDataRoute: dataRouterState != null
|
|
432
|
+
},
|
|
433
|
+
children
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? /* @__PURE__ */ React.createElement(RenderErrorBoundary, {
|
|
437
|
+
location: dataRouterState.location,
|
|
438
|
+
revalidation: dataRouterState.revalidation,
|
|
439
|
+
component: errorElement,
|
|
440
|
+
error,
|
|
441
|
+
children: getChildren(),
|
|
442
|
+
routeContext: {
|
|
443
|
+
outlet: null,
|
|
444
|
+
matches: matches2,
|
|
445
|
+
isDataRoute: true
|
|
446
|
+
}
|
|
447
|
+
}) : getChildren();
|
|
448
|
+
}, null);
|
|
449
|
+
}
|
|
450
|
+
var DataRouterHook = /* @__PURE__ */ (function(DataRouterHook2) {
|
|
451
|
+
DataRouterHook2["UseBlocker"] = "useBlocker";
|
|
452
|
+
DataRouterHook2["UseRevalidator"] = "useRevalidator";
|
|
453
|
+
DataRouterHook2["UseNavigateStable"] = "useNavigate";
|
|
454
|
+
return DataRouterHook2;
|
|
455
|
+
})(DataRouterHook || {});
|
|
456
|
+
var DataRouterStateHook = /* @__PURE__ */ (function(DataRouterStateHook2) {
|
|
457
|
+
DataRouterStateHook2["UseBlocker"] = "useBlocker";
|
|
458
|
+
DataRouterStateHook2["UseLoaderData"] = "useLoaderData";
|
|
459
|
+
DataRouterStateHook2["UseActionData"] = "useActionData";
|
|
460
|
+
DataRouterStateHook2["UseRouteError"] = "useRouteError";
|
|
461
|
+
DataRouterStateHook2["UseNavigation"] = "useNavigation";
|
|
462
|
+
DataRouterStateHook2["UseRouteLoaderData"] = "useRouteLoaderData";
|
|
463
|
+
DataRouterStateHook2["UseMatches"] = "useMatches";
|
|
464
|
+
DataRouterStateHook2["UseRevalidator"] = "useRevalidator";
|
|
465
|
+
DataRouterStateHook2["UseNavigateStable"] = "useNavigate";
|
|
466
|
+
DataRouterStateHook2["UseRouteId"] = "useRouteId";
|
|
467
|
+
return DataRouterStateHook2;
|
|
468
|
+
})(DataRouterStateHook || {});
|
|
469
|
+
function getDataRouterConsoleError(hookName) {
|
|
470
|
+
return hookName + " must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router.";
|
|
471
|
+
}
|
|
472
|
+
function useDataRouterContext(hookName) {
|
|
473
|
+
let ctx = React.useContext(DataRouterContext);
|
|
474
|
+
!ctx ? process.env.NODE_ENV !== "production" ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0;
|
|
475
|
+
return ctx;
|
|
476
|
+
}
|
|
477
|
+
function useDataRouterState(hookName) {
|
|
478
|
+
let state = React.useContext(DataRouterStateContext);
|
|
479
|
+
!state ? process.env.NODE_ENV !== "production" ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0;
|
|
480
|
+
return state;
|
|
481
|
+
}
|
|
482
|
+
function useRouteContext(hookName) {
|
|
483
|
+
let route = React.useContext(RouteContext);
|
|
484
|
+
!route ? process.env.NODE_ENV !== "production" ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0;
|
|
485
|
+
return route;
|
|
486
|
+
}
|
|
487
|
+
function useCurrentRouteId(hookName) {
|
|
488
|
+
let route = useRouteContext(hookName);
|
|
489
|
+
let thisRoute = route.matches[route.matches.length - 1];
|
|
490
|
+
!thisRoute.route.id ? process.env.NODE_ENV !== "production" ? invariant(false, hookName + ' can only be used on routes that contain a unique "id"') : invariant(false) : void 0;
|
|
491
|
+
return thisRoute.route.id;
|
|
492
|
+
}
|
|
493
|
+
function useRouteId() {
|
|
494
|
+
return useCurrentRouteId(DataRouterStateHook.UseRouteId);
|
|
495
|
+
}
|
|
496
|
+
function useRouteError() {
|
|
497
|
+
var _state$errors;
|
|
498
|
+
let error = React.useContext(RouteErrorContext);
|
|
499
|
+
let state = useDataRouterState(DataRouterStateHook.UseRouteError);
|
|
500
|
+
let routeId = useCurrentRouteId(DataRouterStateHook.UseRouteError);
|
|
501
|
+
if (error !== void 0) {
|
|
502
|
+
return error;
|
|
503
|
+
}
|
|
504
|
+
return (_state$errors = state.errors) == null ? void 0 : _state$errors[routeId];
|
|
505
|
+
}
|
|
506
|
+
function useNavigateStable() {
|
|
507
|
+
let {
|
|
508
|
+
router
|
|
509
|
+
} = useDataRouterContext(DataRouterHook.UseNavigateStable);
|
|
510
|
+
let id = useCurrentRouteId(DataRouterStateHook.UseNavigateStable);
|
|
511
|
+
let activeRef = React.useRef(false);
|
|
512
|
+
useIsomorphicLayoutEffect(() => {
|
|
513
|
+
activeRef.current = true;
|
|
514
|
+
});
|
|
515
|
+
let navigate = React.useCallback(function(to, options) {
|
|
516
|
+
if (options === void 0) {
|
|
517
|
+
options = {};
|
|
518
|
+
}
|
|
519
|
+
process.env.NODE_ENV !== "production" ? warning(activeRef.current, navigateEffectWarning) : void 0;
|
|
520
|
+
if (!activeRef.current) return;
|
|
521
|
+
if (typeof to === "number") {
|
|
522
|
+
router.navigate(to);
|
|
523
|
+
} else {
|
|
524
|
+
router.navigate(to, _extends({
|
|
525
|
+
fromRouteId: id
|
|
526
|
+
}, options));
|
|
527
|
+
}
|
|
528
|
+
}, [router, id]);
|
|
529
|
+
return navigate;
|
|
530
|
+
}
|
|
531
|
+
const alreadyWarned$1 = {};
|
|
532
|
+
function warningOnce(key, cond, message) {
|
|
533
|
+
if (!cond && !alreadyWarned$1[key]) {
|
|
534
|
+
alreadyWarned$1[key] = true;
|
|
535
|
+
process.env.NODE_ENV !== "production" ? warning(false, message) : void 0;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
const START_TRANSITION = "startTransition";
|
|
539
|
+
React[START_TRANSITION];
|
|
540
|
+
function Route(_props) {
|
|
541
|
+
process.env.NODE_ENV !== "production" ? invariant(false, "A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.") : invariant(false);
|
|
542
|
+
}
|
|
543
|
+
function Routes(_ref6) {
|
|
544
|
+
let {
|
|
545
|
+
children,
|
|
546
|
+
location
|
|
547
|
+
} = _ref6;
|
|
548
|
+
return useRoutes(createRoutesFromChildren(children), location);
|
|
549
|
+
}
|
|
550
|
+
var AwaitRenderStatus = /* @__PURE__ */ (function(AwaitRenderStatus2) {
|
|
551
|
+
AwaitRenderStatus2[AwaitRenderStatus2["pending"] = 0] = "pending";
|
|
552
|
+
AwaitRenderStatus2[AwaitRenderStatus2["success"] = 1] = "success";
|
|
553
|
+
AwaitRenderStatus2[AwaitRenderStatus2["error"] = 2] = "error";
|
|
554
|
+
return AwaitRenderStatus2;
|
|
555
|
+
})(AwaitRenderStatus || {});
|
|
556
|
+
const neverSettledPromise = new Promise(() => {
|
|
557
|
+
});
|
|
558
|
+
class AwaitErrorBoundary extends React.Component {
|
|
559
|
+
constructor(props) {
|
|
560
|
+
super(props);
|
|
561
|
+
this.state = {
|
|
562
|
+
error: null
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
static getDerivedStateFromError(error) {
|
|
566
|
+
return {
|
|
567
|
+
error
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
componentDidCatch(error, errorInfo) {
|
|
571
|
+
console.error("<Await> caught the following error during render", error, errorInfo);
|
|
572
|
+
}
|
|
573
|
+
render() {
|
|
574
|
+
let {
|
|
575
|
+
children,
|
|
576
|
+
errorElement,
|
|
577
|
+
resolve
|
|
578
|
+
} = this.props;
|
|
579
|
+
let promise = null;
|
|
580
|
+
let status = AwaitRenderStatus.pending;
|
|
581
|
+
if (!(resolve instanceof Promise)) {
|
|
582
|
+
status = AwaitRenderStatus.success;
|
|
583
|
+
promise = Promise.resolve();
|
|
584
|
+
Object.defineProperty(promise, "_tracked", {
|
|
585
|
+
get: () => true
|
|
586
|
+
});
|
|
587
|
+
Object.defineProperty(promise, "_data", {
|
|
588
|
+
get: () => resolve
|
|
589
|
+
});
|
|
590
|
+
} else if (this.state.error) {
|
|
591
|
+
status = AwaitRenderStatus.error;
|
|
592
|
+
let renderError = this.state.error;
|
|
593
|
+
promise = Promise.reject().catch(() => {
|
|
594
|
+
});
|
|
595
|
+
Object.defineProperty(promise, "_tracked", {
|
|
596
|
+
get: () => true
|
|
597
|
+
});
|
|
598
|
+
Object.defineProperty(promise, "_error", {
|
|
599
|
+
get: () => renderError
|
|
600
|
+
});
|
|
601
|
+
} else if (resolve._tracked) {
|
|
602
|
+
promise = resolve;
|
|
603
|
+
status = "_error" in promise ? AwaitRenderStatus.error : "_data" in promise ? AwaitRenderStatus.success : AwaitRenderStatus.pending;
|
|
604
|
+
} else {
|
|
605
|
+
status = AwaitRenderStatus.pending;
|
|
606
|
+
Object.defineProperty(resolve, "_tracked", {
|
|
607
|
+
get: () => true
|
|
608
|
+
});
|
|
609
|
+
promise = resolve.then((data) => Object.defineProperty(resolve, "_data", {
|
|
610
|
+
get: () => data
|
|
611
|
+
}), (error) => Object.defineProperty(resolve, "_error", {
|
|
612
|
+
get: () => error
|
|
613
|
+
}));
|
|
614
|
+
}
|
|
615
|
+
if (status === AwaitRenderStatus.error && promise._error instanceof AbortedDeferredError) {
|
|
616
|
+
throw neverSettledPromise;
|
|
617
|
+
}
|
|
618
|
+
if (status === AwaitRenderStatus.error && !errorElement) {
|
|
619
|
+
throw promise._error;
|
|
620
|
+
}
|
|
621
|
+
if (status === AwaitRenderStatus.error) {
|
|
622
|
+
return /* @__PURE__ */ React.createElement(AwaitContext.Provider, {
|
|
623
|
+
value: promise,
|
|
624
|
+
children: errorElement
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
if (status === AwaitRenderStatus.success) {
|
|
628
|
+
return /* @__PURE__ */ React.createElement(AwaitContext.Provider, {
|
|
629
|
+
value: promise,
|
|
630
|
+
children
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
throw promise;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
function createRoutesFromChildren(children, parentPath) {
|
|
637
|
+
if (parentPath === void 0) {
|
|
638
|
+
parentPath = [];
|
|
639
|
+
}
|
|
640
|
+
let routes = [];
|
|
641
|
+
React.Children.forEach(children, (element, index) => {
|
|
642
|
+
if (!/* @__PURE__ */ React.isValidElement(element)) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
let treePath = [...parentPath, index];
|
|
646
|
+
if (element.type === React.Fragment) {
|
|
647
|
+
routes.push.apply(routes, createRoutesFromChildren(element.props.children, treePath));
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
!(element.type === Route) ? process.env.NODE_ENV !== "production" ? invariant(false, "[" + (typeof element.type === "string" ? element.type : element.type.name) + "] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>") : invariant(false) : void 0;
|
|
651
|
+
!(!element.props.index || !element.props.children) ? process.env.NODE_ENV !== "production" ? invariant(false, "An index route cannot have child routes.") : invariant(false) : void 0;
|
|
652
|
+
let route = {
|
|
653
|
+
id: element.props.id || treePath.join("-"),
|
|
654
|
+
caseSensitive: element.props.caseSensitive,
|
|
655
|
+
element: element.props.element,
|
|
656
|
+
Component: element.props.Component,
|
|
657
|
+
index: element.props.index,
|
|
658
|
+
path: element.props.path,
|
|
659
|
+
loader: element.props.loader,
|
|
660
|
+
action: element.props.action,
|
|
661
|
+
errorElement: element.props.errorElement,
|
|
662
|
+
ErrorBoundary: element.props.ErrorBoundary,
|
|
663
|
+
hasErrorBoundary: element.props.ErrorBoundary != null || element.props.errorElement != null,
|
|
664
|
+
shouldRevalidate: element.props.shouldRevalidate,
|
|
665
|
+
handle: element.props.handle,
|
|
666
|
+
lazy: element.props.lazy
|
|
667
|
+
};
|
|
668
|
+
if (element.props.children) {
|
|
669
|
+
route.children = createRoutesFromChildren(element.props.children, treePath);
|
|
670
|
+
}
|
|
671
|
+
routes.push(route);
|
|
672
|
+
});
|
|
673
|
+
return routes;
|
|
674
|
+
}
|
|
675
|
+
export {
|
|
676
|
+
AbortedDeferredError,
|
|
677
|
+
Action as NavigationType,
|
|
678
|
+
Route,
|
|
679
|
+
Routes,
|
|
680
|
+
DataRouterContext as UNSAFE_DataRouterContext,
|
|
681
|
+
DataRouterStateContext as UNSAFE_DataRouterStateContext,
|
|
682
|
+
LocationContext as UNSAFE_LocationContext,
|
|
683
|
+
NavigationContext as UNSAFE_NavigationContext,
|
|
684
|
+
RouteContext as UNSAFE_RouteContext,
|
|
685
|
+
useRouteId as UNSAFE_useRouteId,
|
|
686
|
+
useRoutesImpl as UNSAFE_useRoutesImpl,
|
|
687
|
+
createPath,
|
|
688
|
+
createRoutesFromChildren,
|
|
689
|
+
createRoutesFromChildren as createRoutesFromElements,
|
|
690
|
+
isRouteErrorResponse,
|
|
691
|
+
matchPath,
|
|
692
|
+
matchRoutes,
|
|
693
|
+
parsePath,
|
|
694
|
+
resolvePath,
|
|
695
|
+
useHref,
|
|
696
|
+
useInRouterContext,
|
|
697
|
+
useLocation,
|
|
698
|
+
useNavigate,
|
|
699
|
+
useParams,
|
|
700
|
+
useResolvedPath,
|
|
701
|
+
useRouteError,
|
|
702
|
+
useRoutes
|
|
703
|
+
};
|
|
704
|
+
//# sourceMappingURL=index.js.map
|