@remix-run/router 1.6.3 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/dist/history.d.ts +6 -6
- package/dist/router.cjs.js +378 -234
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +69 -41
- package/dist/router.js +365 -229
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +378 -234
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/dist/utils.d.ts +54 -28
- package/package.json +1 -1
- package/router.ts +501 -277
- package/utils.ts +44 -20
package/dist/router.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { History, Location, Path, To } from "./history";
|
|
2
2
|
import { Action as HistoryAction } from "./history";
|
|
3
|
-
import type { DeferredData, AgnosticDataRouteMatch, AgnosticDataRouteObject, FormEncType,
|
|
3
|
+
import type { DeferredData, AgnosticDataRouteMatch, AgnosticDataRouteObject, FormEncType, DetectErrorBoundaryFunction, RouteData, AgnosticRouteObject, Submission, AgnosticRouteMatch, HTMLFormMethod, MapRoutePropertiesFunction } from "./utils";
|
|
4
4
|
/**
|
|
5
5
|
* A Router instance manages all navigation and data loading/mutations
|
|
6
6
|
*/
|
|
@@ -81,7 +81,7 @@ export interface Router {
|
|
|
81
81
|
* @param href href to fetch
|
|
82
82
|
* @param opts Fetcher options, (method, submission, etc.)
|
|
83
83
|
*/
|
|
84
|
-
fetch(key: string, routeId: string, href: string | null, opts?:
|
|
84
|
+
fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): void;
|
|
85
85
|
/**
|
|
86
86
|
* @internal
|
|
87
87
|
* PRIVATE - DO NOT USE
|
|
@@ -234,7 +234,7 @@ export interface RouterState {
|
|
|
234
234
|
/**
|
|
235
235
|
* Data that can be passed into hydrate a Router from SSR
|
|
236
236
|
*/
|
|
237
|
-
export
|
|
237
|
+
export type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
|
|
238
238
|
/**
|
|
239
239
|
* Future flags to toggle new feature behavior
|
|
240
240
|
*/
|
|
@@ -313,38 +313,54 @@ export interface GetScrollRestorationKeyFunction {
|
|
|
313
313
|
export interface GetScrollPositionFunction {
|
|
314
314
|
(): number;
|
|
315
315
|
}
|
|
316
|
-
export
|
|
317
|
-
|
|
318
|
-
replace?: boolean;
|
|
319
|
-
state?: any;
|
|
316
|
+
export type RelativeRoutingType = "route" | "path";
|
|
317
|
+
type BaseNavigateOrFetchOptions = {
|
|
320
318
|
preventScrollReset?: boolean;
|
|
321
319
|
relative?: RelativeRoutingType;
|
|
320
|
+
};
|
|
321
|
+
type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
|
|
322
|
+
replace?: boolean;
|
|
323
|
+
state?: any;
|
|
322
324
|
fromRouteId?: string;
|
|
323
325
|
};
|
|
326
|
+
type BaseSubmissionOptions = {
|
|
327
|
+
formMethod?: HTMLFormMethod;
|
|
328
|
+
formEncType?: FormEncType;
|
|
329
|
+
} & ({
|
|
330
|
+
formData: FormData;
|
|
331
|
+
body?: undefined;
|
|
332
|
+
} | {
|
|
333
|
+
formData?: undefined;
|
|
334
|
+
body: any;
|
|
335
|
+
});
|
|
324
336
|
/**
|
|
325
|
-
* Options for a navigate() call for a
|
|
337
|
+
* Options for a navigate() call for a normal (non-submission) navigation
|
|
326
338
|
*/
|
|
327
|
-
|
|
339
|
+
type LinkNavigateOptions = BaseNavigateOptions;
|
|
328
340
|
/**
|
|
329
|
-
* Options for a navigate() call for a
|
|
341
|
+
* Options for a navigate() call for a submission navigation
|
|
330
342
|
*/
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
343
|
+
type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
|
|
344
|
+
/**
|
|
345
|
+
* Options to pass to navigate() for a navigation
|
|
346
|
+
*/
|
|
347
|
+
export type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
|
|
348
|
+
/**
|
|
349
|
+
* Options for a fetch() load
|
|
350
|
+
*/
|
|
351
|
+
type LoadFetchOptions = BaseNavigateOrFetchOptions;
|
|
336
352
|
/**
|
|
337
|
-
* Options
|
|
353
|
+
* Options for a fetch() submission
|
|
338
354
|
*/
|
|
339
|
-
|
|
355
|
+
type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
|
|
340
356
|
/**
|
|
341
357
|
* Options to pass to fetch()
|
|
342
358
|
*/
|
|
343
|
-
export
|
|
359
|
+
export type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
|
|
344
360
|
/**
|
|
345
361
|
* Potential states for state.navigation
|
|
346
362
|
*/
|
|
347
|
-
export
|
|
363
|
+
export type NavigationStates = {
|
|
348
364
|
Idle: {
|
|
349
365
|
state: "idle";
|
|
350
366
|
location: undefined;
|
|
@@ -352,59 +368,71 @@ export declare type NavigationStates = {
|
|
|
352
368
|
formAction: undefined;
|
|
353
369
|
formEncType: undefined;
|
|
354
370
|
formData: undefined;
|
|
371
|
+
json: undefined;
|
|
372
|
+
text: undefined;
|
|
355
373
|
};
|
|
356
374
|
Loading: {
|
|
357
375
|
state: "loading";
|
|
358
376
|
location: Location;
|
|
359
|
-
formMethod:
|
|
360
|
-
formAction:
|
|
361
|
-
formEncType:
|
|
362
|
-
formData:
|
|
377
|
+
formMethod: Submission["formMethod"] | undefined;
|
|
378
|
+
formAction: Submission["formAction"] | undefined;
|
|
379
|
+
formEncType: Submission["formEncType"] | undefined;
|
|
380
|
+
formData: Submission["formData"] | undefined;
|
|
381
|
+
json: Submission["json"] | undefined;
|
|
382
|
+
text: Submission["text"] | undefined;
|
|
363
383
|
};
|
|
364
384
|
Submitting: {
|
|
365
385
|
state: "submitting";
|
|
366
386
|
location: Location;
|
|
367
|
-
formMethod:
|
|
368
|
-
formAction:
|
|
369
|
-
formEncType:
|
|
370
|
-
formData:
|
|
387
|
+
formMethod: Submission["formMethod"];
|
|
388
|
+
formAction: Submission["formAction"];
|
|
389
|
+
formEncType: Submission["formEncType"];
|
|
390
|
+
formData: Submission["formData"];
|
|
391
|
+
json: Submission["json"];
|
|
392
|
+
text: Submission["text"];
|
|
371
393
|
};
|
|
372
394
|
};
|
|
373
|
-
export
|
|
374
|
-
export
|
|
395
|
+
export type Navigation = NavigationStates[keyof NavigationStates];
|
|
396
|
+
export type RevalidationState = "idle" | "loading";
|
|
375
397
|
/**
|
|
376
398
|
* Potential states for fetchers
|
|
377
399
|
*/
|
|
378
|
-
|
|
400
|
+
type FetcherStates<TData = any> = {
|
|
379
401
|
Idle: {
|
|
380
402
|
state: "idle";
|
|
381
403
|
formMethod: undefined;
|
|
382
404
|
formAction: undefined;
|
|
383
405
|
formEncType: undefined;
|
|
406
|
+
text: undefined;
|
|
384
407
|
formData: undefined;
|
|
408
|
+
json: undefined;
|
|
385
409
|
data: TData | undefined;
|
|
386
410
|
" _hasFetcherDoneAnything "?: boolean;
|
|
387
411
|
};
|
|
388
412
|
Loading: {
|
|
389
413
|
state: "loading";
|
|
390
|
-
formMethod:
|
|
391
|
-
formAction:
|
|
392
|
-
formEncType:
|
|
393
|
-
|
|
414
|
+
formMethod: Submission["formMethod"] | undefined;
|
|
415
|
+
formAction: Submission["formAction"] | undefined;
|
|
416
|
+
formEncType: Submission["formEncType"] | undefined;
|
|
417
|
+
text: Submission["text"] | undefined;
|
|
418
|
+
formData: Submission["formData"] | undefined;
|
|
419
|
+
json: Submission["json"] | undefined;
|
|
394
420
|
data: TData | undefined;
|
|
395
421
|
" _hasFetcherDoneAnything "?: boolean;
|
|
396
422
|
};
|
|
397
423
|
Submitting: {
|
|
398
424
|
state: "submitting";
|
|
399
|
-
formMethod:
|
|
400
|
-
formAction:
|
|
401
|
-
formEncType:
|
|
402
|
-
|
|
425
|
+
formMethod: Submission["formMethod"];
|
|
426
|
+
formAction: Submission["formAction"];
|
|
427
|
+
formEncType: Submission["formEncType"];
|
|
428
|
+
text: Submission["text"];
|
|
429
|
+
formData: Submission["formData"];
|
|
430
|
+
json: Submission["json"];
|
|
403
431
|
data: TData | undefined;
|
|
404
432
|
" _hasFetcherDoneAnything "?: boolean;
|
|
405
433
|
};
|
|
406
434
|
};
|
|
407
|
-
export
|
|
435
|
+
export type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
|
|
408
436
|
interface BlockerBlocked {
|
|
409
437
|
state: "blocked";
|
|
410
438
|
reset(): void;
|
|
@@ -423,8 +451,8 @@ interface BlockerProceeding {
|
|
|
423
451
|
proceed: undefined;
|
|
424
452
|
location: Location;
|
|
425
453
|
}
|
|
426
|
-
export
|
|
427
|
-
export
|
|
454
|
+
export type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
|
|
455
|
+
export type BlockerFunction = (args: {
|
|
428
456
|
currentLocation: Location;
|
|
429
457
|
nextLocation: Location;
|
|
430
458
|
historyAction: HistoryAction;
|