react-router 0.0.0-experimental-c7dd3d3a → 0.0.0-experimental-e53172d16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +1 -10
  3. package/dist/index.d.ts +37 -16
  4. package/dist/index.js +9809 -1087
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/components.d.ts +13 -2
  7. package/dist/lib/context.d.ts +2 -2
  8. package/dist/lib/dom/dom.d.ts +104 -0
  9. package/dist/lib/dom/global.d.ts +36 -0
  10. package/dist/lib/dom/lib.d.ts +304 -0
  11. package/dist/lib/dom/server.d.ts +32 -0
  12. package/dist/lib/dom/ssr/browser.d.ts +3 -0
  13. package/dist/lib/dom/ssr/components.d.ts +61 -0
  14. package/dist/lib/dom/ssr/create-remix-stub.d.ts +56 -0
  15. package/dist/lib/dom/ssr/data.d.ts +16 -0
  16. package/dist/lib/dom/ssr/errorBoundaries.d.ts +33 -0
  17. package/dist/lib/dom/ssr/errors.d.ts +2 -0
  18. package/dist/lib/dom/ssr/fallback.d.ts +2 -0
  19. package/dist/lib/dom/ssr/invariant.d.ts +2 -0
  20. package/dist/lib/dom/ssr/links.d.ts +127 -0
  21. package/dist/lib/dom/ssr/markup.d.ts +5 -0
  22. package/dist/lib/dom/ssr/routeModules.d.ts +141 -0
  23. package/dist/lib/dom/ssr/routes.d.ts +32 -0
  24. package/dist/lib/dom/ssr/server.d.ts +13 -0
  25. package/dist/lib/dom/ssr/single-fetch.d.ts +36 -0
  26. package/dist/lib/hooks.d.ts +3 -3
  27. package/dist/lib/router/history.d.ts +250 -0
  28. package/dist/lib/router/index.d.ts +9 -0
  29. package/dist/lib/router/router.d.ts +512 -0
  30. package/dist/lib/router/utils.d.ts +520 -0
  31. package/dist/main.js +1 -1
  32. package/dist/react-router.development.js +10495 -1126
  33. package/dist/react-router.development.js.map +1 -1
  34. package/dist/react-router.production.min.js +2 -2
  35. package/dist/react-router.production.min.js.map +1 -1
  36. package/dist/umd/react-router.development.js +10876 -1287
  37. package/dist/umd/react-router.development.js.map +1 -1
  38. package/dist/umd/react-router.production.min.js +2 -2
  39. package/dist/umd/react-router.production.min.js.map +1 -1
  40. package/package.json +12 -5
@@ -0,0 +1,520 @@
1
+ import type { Location, Path, To } from "./history";
2
+ /**
3
+ * Map of routeId -> data returned from a loader/action/error
4
+ */
5
+ export interface RouteData {
6
+ [routeId: string]: any;
7
+ }
8
+ export declare enum ResultType {
9
+ data = "data",
10
+ deferred = "deferred",
11
+ redirect = "redirect",
12
+ error = "error"
13
+ }
14
+ /**
15
+ * Successful result from a loader or action
16
+ */
17
+ export interface SuccessResult {
18
+ type: ResultType.data;
19
+ data: unknown;
20
+ statusCode?: number;
21
+ headers?: Headers;
22
+ }
23
+ /**
24
+ * Successful defer() result from a loader or action
25
+ */
26
+ export interface DeferredResult {
27
+ type: ResultType.deferred;
28
+ deferredData: DeferredData;
29
+ statusCode?: number;
30
+ headers?: Headers;
31
+ }
32
+ /**
33
+ * Redirect result from a loader or action
34
+ */
35
+ export interface RedirectResult {
36
+ type: ResultType.redirect;
37
+ response: Response;
38
+ }
39
+ /**
40
+ * Unsuccessful result from a loader or action
41
+ */
42
+ export interface ErrorResult {
43
+ type: ResultType.error;
44
+ error: unknown;
45
+ statusCode?: number;
46
+ headers?: Headers;
47
+ }
48
+ /**
49
+ * Result from a loader or action - potentially successful or unsuccessful
50
+ */
51
+ export type DataResult = SuccessResult | DeferredResult | RedirectResult | ErrorResult;
52
+ /**
53
+ * Result from a loader or action called via dataStrategy
54
+ */
55
+ export interface HandlerResult {
56
+ type: "data" | "error";
57
+ result: unknown;
58
+ status?: number;
59
+ }
60
+ type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
61
+ type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
62
+ /**
63
+ * Users can specify either lowercase or uppercase form methods on `<Form>`,
64
+ * useSubmit(), `<fetcher.Form>`, etc.
65
+ */
66
+ export type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
67
+ /**
68
+ * Active navigation/fetcher form methods are exposed in lowercase on the
69
+ * RouterState
70
+ */
71
+ export type FormMethod = LowerCaseFormMethod;
72
+ export type MutationFormMethod = Exclude<FormMethod, "get">;
73
+ /**
74
+ * In v7, active navigation/fetcher form methods are exposed in uppercase on the
75
+ * RouterState. This is to align with the normalization done via fetch().
76
+ */
77
+ export type V7_FormMethod = UpperCaseFormMethod;
78
+ export type V7_MutationFormMethod = Exclude<V7_FormMethod, "GET">;
79
+ export type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
80
+ type JsonObject = {
81
+ [Key in string]: JsonValue;
82
+ } & {
83
+ [Key in string]?: JsonValue | undefined;
84
+ };
85
+ type JsonArray = JsonValue[] | readonly JsonValue[];
86
+ type JsonPrimitive = string | number | boolean | null;
87
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
88
+ /**
89
+ * @private
90
+ * Internal interface to pass around for action submissions, not intended for
91
+ * external consumption
92
+ */
93
+ export type Submission = {
94
+ formMethod: FormMethod | V7_FormMethod;
95
+ formAction: string;
96
+ formEncType: FormEncType;
97
+ formData: FormData;
98
+ json: undefined;
99
+ text: undefined;
100
+ } | {
101
+ formMethod: FormMethod | V7_FormMethod;
102
+ formAction: string;
103
+ formEncType: FormEncType;
104
+ formData: undefined;
105
+ json: JsonValue;
106
+ text: undefined;
107
+ } | {
108
+ formMethod: FormMethod | V7_FormMethod;
109
+ formAction: string;
110
+ formEncType: FormEncType;
111
+ formData: undefined;
112
+ json: undefined;
113
+ text: string;
114
+ };
115
+ /**
116
+ * @private
117
+ * Arguments passed to route loader/action functions. Same for now but we keep
118
+ * this as a private implementation detail in case they diverge in the future.
119
+ */
120
+ interface DataFunctionArgs<Context> {
121
+ request: Request;
122
+ params: Params;
123
+ context?: Context;
124
+ }
125
+ /**
126
+ * Arguments passed to loader functions
127
+ */
128
+ export interface LoaderFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
129
+ }
130
+ /**
131
+ * Arguments passed to action functions
132
+ */
133
+ export interface ActionFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
134
+ }
135
+ /**
136
+ * Loaders and actions can return anything except `undefined` (`null` is a
137
+ * valid return value if there is no data to return). Responses are preferred
138
+ * and will ease any future migration to Remix
139
+ */
140
+ type DataFunctionValue = Response | NonNullable<unknown> | null;
141
+ type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
142
+ /**
143
+ * Route loader function signature
144
+ */
145
+ export type LoaderFunction<Context = any> = {
146
+ (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
147
+ } & {
148
+ hydrate?: boolean;
149
+ };
150
+ /**
151
+ * Route action function signature
152
+ */
153
+ export interface ActionFunction<Context = any> {
154
+ (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
155
+ }
156
+ /**
157
+ * Arguments passed to shouldRevalidate function
158
+ */
159
+ export interface ShouldRevalidateFunctionArgs {
160
+ currentUrl: URL;
161
+ currentParams: AgnosticDataRouteMatch["params"];
162
+ nextUrl: URL;
163
+ nextParams: AgnosticDataRouteMatch["params"];
164
+ formMethod?: Submission["formMethod"];
165
+ formAction?: Submission["formAction"];
166
+ formEncType?: Submission["formEncType"];
167
+ text?: Submission["text"];
168
+ formData?: Submission["formData"];
169
+ json?: Submission["json"];
170
+ unstable_actionStatus?: number;
171
+ actionResult?: any;
172
+ defaultShouldRevalidate: boolean;
173
+ }
174
+ /**
175
+ * Route shouldRevalidate function signature. This runs after any submission
176
+ * (navigation or fetcher), so we flatten the navigation/fetcher submission
177
+ * onto the arguments. It shouldn't matter whether it came from a navigation
178
+ * or a fetcher, what really matters is the URLs and the formData since loaders
179
+ * have to re-run based on the data models that were potentially mutated.
180
+ */
181
+ export interface ShouldRevalidateFunction {
182
+ (args: ShouldRevalidateFunctionArgs): boolean;
183
+ }
184
+ /**
185
+ * Function provided by the framework-aware layers to set `hasErrorBoundary`
186
+ * from the framework-aware `errorElement` prop
187
+ *
188
+ * @deprecated Use `mapRouteProperties` instead
189
+ */
190
+ export interface DetectErrorBoundaryFunction {
191
+ (route: AgnosticRouteObject): boolean;
192
+ }
193
+ export interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
194
+ shouldLoad: boolean;
195
+ resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => Promise<HandlerResult>) => Promise<HandlerResult>;
196
+ }
197
+ export interface DataStrategyFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
198
+ matches: DataStrategyMatch[];
199
+ }
200
+ export interface DataStrategyFunction {
201
+ (args: DataStrategyFunctionArgs): Promise<HandlerResult[]>;
202
+ }
203
+ /**
204
+ * Function provided by the framework-aware layers to set any framework-specific
205
+ * properties from framework-agnostic properties
206
+ */
207
+ export interface MapRoutePropertiesFunction {
208
+ (route: AgnosticRouteObject): {
209
+ hasErrorBoundary: boolean;
210
+ } & Record<string, any>;
211
+ }
212
+ /**
213
+ * Keys we cannot change from within a lazy() function. We spread all other keys
214
+ * onto the route. Either they're meaningful to the router, or they'll get
215
+ * ignored.
216
+ */
217
+ export type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
218
+ export declare const immutableRouteKeys: Set<ImmutableRouteKey>;
219
+ type RequireOne<T, Key = keyof T> = Exclude<{
220
+ [K in keyof T]: K extends Key ? Omit<T, K> & Required<Pick<T, K>> : never;
221
+ }[keyof T], undefined>;
222
+ /**
223
+ * lazy() function to load a route definition, which can add non-matching
224
+ * related properties to a route
225
+ */
226
+ export interface LazyRouteFunction<R extends AgnosticRouteObject> {
227
+ (): Promise<RequireOne<Omit<R, ImmutableRouteKey>>>;
228
+ }
229
+ /**
230
+ * Base RouteObject with common props shared by all types of routes
231
+ */
232
+ type AgnosticBaseRouteObject = {
233
+ caseSensitive?: boolean;
234
+ path?: string;
235
+ id?: string;
236
+ loader?: LoaderFunction | boolean;
237
+ action?: ActionFunction | boolean;
238
+ hasErrorBoundary?: boolean;
239
+ shouldRevalidate?: ShouldRevalidateFunction;
240
+ handle?: any;
241
+ lazy?: LazyRouteFunction<AgnosticBaseRouteObject>;
242
+ };
243
+ /**
244
+ * Index routes must not have children
245
+ */
246
+ export type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
247
+ children?: undefined;
248
+ index: true;
249
+ };
250
+ /**
251
+ * Non-index routes may have children, but cannot have index
252
+ */
253
+ export type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
254
+ children?: AgnosticRouteObject[];
255
+ index?: false;
256
+ };
257
+ /**
258
+ * A route object represents a logical route, with (optionally) its child
259
+ * routes organized in a tree-like structure.
260
+ */
261
+ export type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
262
+ export type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
263
+ id: string;
264
+ };
265
+ export type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
266
+ children?: AgnosticDataRouteObject[];
267
+ id: string;
268
+ };
269
+ /**
270
+ * A data route object, which is just a RouteObject with a required unique ID
271
+ */
272
+ export type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
273
+ export type RouteManifest = Record<string, AgnosticDataRouteObject | undefined>;
274
+ type _PathParam<Path extends string> = Path extends `${infer L}/${infer R}` ? _PathParam<L> | _PathParam<R> : Path extends `:${infer Param}` ? Param extends `${infer Optional}?` ? Optional : Param : never;
275
+ /**
276
+ * Examples:
277
+ * "/a/b/*" -> "*"
278
+ * ":a" -> "a"
279
+ * "/a/:b" -> "b"
280
+ * "/a/blahblahblah:b" -> "b"
281
+ * "/:a/:b" -> "a" | "b"
282
+ * "/:a/b/:c/*" -> "a" | "c" | "*"
283
+ */
284
+ export type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
285
+ export type ParamParseKey<Segment extends string> = [
286
+ PathParam<Segment>
287
+ ] extends [never] ? string : PathParam<Segment>;
288
+ /**
289
+ * The parameters that were parsed from the URL path.
290
+ */
291
+ export type Params<Key extends string = string> = {
292
+ readonly [key in Key]: string | undefined;
293
+ };
294
+ /**
295
+ * A RouteMatch contains info about how a route matched a URL.
296
+ */
297
+ export interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
298
+ /**
299
+ * The names and values of dynamic parameters in the URL.
300
+ */
301
+ params: Params<ParamKey>;
302
+ /**
303
+ * The portion of the URL pathname that was matched.
304
+ */
305
+ pathname: string;
306
+ /**
307
+ * The portion of the URL pathname that was matched before child routes.
308
+ */
309
+ pathnameBase: string;
310
+ /**
311
+ * The route object that was used to match.
312
+ */
313
+ route: RouteObjectType;
314
+ }
315
+ export interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
316
+ }
317
+ export declare function convertRoutesToDataRoutes(routes: AgnosticRouteObject[], mapRouteProperties: MapRoutePropertiesFunction, parentPath?: number[], manifest?: RouteManifest): AgnosticDataRouteObject[];
318
+ /**
319
+ * Matches the given routes to a location and returns the match data.
320
+ *
321
+ * @see https://reactrouter.com/utils/match-routes
322
+ */
323
+ export declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
324
+ export interface UIMatch<Data = unknown, Handle = unknown> {
325
+ id: string;
326
+ pathname: string;
327
+ params: AgnosticRouteMatch["params"];
328
+ data: Data;
329
+ handle: Handle;
330
+ }
331
+ export declare function convertRouteMatchToUiMatch(match: AgnosticDataRouteMatch, loaderData: RouteData): UIMatch;
332
+ /**
333
+ * Returns a path with params interpolated.
334
+ *
335
+ * @see https://reactrouter.com/utils/generate-path
336
+ */
337
+ export declare function generatePath<Path extends string>(originalPath: Path, params?: {
338
+ [key in PathParam<Path>]: string | null;
339
+ }): string;
340
+ /**
341
+ * A PathPattern is used to match on some portion of a URL pathname.
342
+ */
343
+ export interface PathPattern<Path extends string = string> {
344
+ /**
345
+ * A string to match against a URL pathname. May contain `:id`-style segments
346
+ * to indicate placeholders for dynamic parameters. May also end with `/*` to
347
+ * indicate matching the rest of the URL pathname.
348
+ */
349
+ path: Path;
350
+ /**
351
+ * Should be `true` if the static portions of the `path` should be matched in
352
+ * the same case.
353
+ */
354
+ caseSensitive?: boolean;
355
+ /**
356
+ * Should be `true` if this pattern should match the entire URL pathname.
357
+ */
358
+ end?: boolean;
359
+ }
360
+ /**
361
+ * A PathMatch contains info about how a PathPattern matched on a URL pathname.
362
+ */
363
+ export interface PathMatch<ParamKey extends string = string> {
364
+ /**
365
+ * The names and values of dynamic parameters in the URL.
366
+ */
367
+ params: Params<ParamKey>;
368
+ /**
369
+ * The portion of the URL pathname that was matched.
370
+ */
371
+ pathname: string;
372
+ /**
373
+ * The portion of the URL pathname that was matched before child routes.
374
+ */
375
+ pathnameBase: string;
376
+ /**
377
+ * The pattern that was used to match.
378
+ */
379
+ pattern: PathPattern;
380
+ }
381
+ /**
382
+ * Performs pattern matching on a URL pathname and returns information about
383
+ * the match.
384
+ *
385
+ * @see https://reactrouter.com/utils/match-path
386
+ */
387
+ export declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
388
+ /**
389
+ * @private
390
+ */
391
+ export declare function stripBasename(pathname: string, basename: string): string | null;
392
+ /**
393
+ * Returns a resolved path object relative to the given pathname.
394
+ *
395
+ * @see https://reactrouter.com/utils/resolve-path
396
+ */
397
+ export declare function resolvePath(to: To, fromPathname?: string): Path;
398
+ /**
399
+ * @private
400
+ *
401
+ * When processing relative navigation we want to ignore ancestor routes that
402
+ * do not contribute to the path, such that index/pathless layout routes don't
403
+ * interfere.
404
+ *
405
+ * For example, when moving a route element into an index route and/or a
406
+ * pathless layout route, relative link behavior contained within should stay
407
+ * the same. Both of the following examples should link back to the root:
408
+ *
409
+ * <Route path="/">
410
+ * <Route path="accounts" element={<Link to=".."}>
411
+ * </Route>
412
+ *
413
+ * <Route path="/">
414
+ * <Route path="accounts">
415
+ * <Route element={<AccountsLayout />}> // <-- Does not contribute
416
+ * <Route index element={<Link to=".."} /> // <-- Does not contribute
417
+ * </Route
418
+ * </Route>
419
+ * </Route>
420
+ */
421
+ export declare function getPathContributingMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[]): T[];
422
+ export declare function getResolveToMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[], v7_relativeSplatPath: boolean): string[];
423
+ /**
424
+ * @private
425
+ */
426
+ export declare function resolveTo(toArg: To, routePathnames: string[], locationPathname: string, isPathRelative?: boolean): Path;
427
+ /**
428
+ * @private
429
+ */
430
+ export declare function getToPathname(to: To): string | undefined;
431
+ /**
432
+ * @private
433
+ */
434
+ export declare const joinPaths: (paths: string[]) => string;
435
+ /**
436
+ * @private
437
+ */
438
+ export declare const normalizePathname: (pathname: string) => string;
439
+ /**
440
+ * @private
441
+ */
442
+ export declare const normalizeSearch: (search: string) => string;
443
+ /**
444
+ * @private
445
+ */
446
+ export declare const normalizeHash: (hash: string) => string;
447
+ export type JsonFunction = <Data>(data: Data, init?: number | ResponseInit) => Response;
448
+ /**
449
+ * This is a shortcut for creating `application/json` responses. Converts `data`
450
+ * to JSON and sets the `Content-Type` header.
451
+ */
452
+ export declare const json: JsonFunction;
453
+ export interface TrackedPromise extends Promise<any> {
454
+ _tracked?: boolean;
455
+ _data?: any;
456
+ _error?: any;
457
+ }
458
+ export declare class AbortedDeferredError extends Error {
459
+ }
460
+ export declare class DeferredData {
461
+ private pendingKeysSet;
462
+ private controller;
463
+ private abortPromise;
464
+ private unlistenAbortSignal;
465
+ private subscribers;
466
+ data: Record<string, unknown>;
467
+ init?: ResponseInit;
468
+ deferredKeys: string[];
469
+ constructor(data: Record<string, unknown>, responseInit?: ResponseInit);
470
+ private trackPromise;
471
+ private onSettle;
472
+ private emit;
473
+ subscribe(fn: (aborted: boolean, settledKey?: string) => void): () => boolean;
474
+ cancel(): void;
475
+ resolveData(signal: AbortSignal): Promise<boolean>;
476
+ get done(): boolean;
477
+ get unwrappedData(): {};
478
+ get pendingKeys(): string[];
479
+ }
480
+ export type DeferFunction = (data: Record<string, unknown>, init?: number | ResponseInit) => DeferredData;
481
+ export declare const defer: DeferFunction;
482
+ export type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
483
+ /**
484
+ * A redirect response. Sets the status code and the `Location` header.
485
+ * Defaults to "302 Found".
486
+ */
487
+ export declare const redirect: RedirectFunction;
488
+ /**
489
+ * A redirect response that will force a document reload to the new location.
490
+ * Sets the status code and the `Location` header.
491
+ * Defaults to "302 Found".
492
+ */
493
+ export declare const redirectDocument: RedirectFunction;
494
+ export type ErrorResponse = {
495
+ status: number;
496
+ statusText: string;
497
+ data: any;
498
+ };
499
+ /**
500
+ * @private
501
+ * Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
502
+ *
503
+ * We don't export the class for public use since it's an implementation
504
+ * detail, but we export the interface above so folks can build their own
505
+ * abstractions around instances via isRouteErrorResponse()
506
+ */
507
+ export declare class ErrorResponseImpl implements ErrorResponse {
508
+ status: number;
509
+ statusText: string;
510
+ data: any;
511
+ private error?;
512
+ private internal;
513
+ constructor(status: number, statusText: string | undefined, data: any, internal?: boolean);
514
+ }
515
+ /**
516
+ * Check if the given error is an ErrorResponse generated from a 4xx/5xx
517
+ * Response thrown from an action/loader
518
+ */
519
+ export declare function isRouteErrorResponse(error: any): error is ErrorResponse;
520
+ export {};
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v0.0.0-experimental-c7dd3d3a
2
+ * React Router v0.0.0-experimental-e53172d16
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *