@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/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, FormMethod, DetectErrorBoundaryFunction, RouteData, AgnosticRouteObject, AgnosticRouteMatch, V7_FormMethod, HTMLFormMethod, MapRoutePropertiesFunction } from "./utils";
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?: RouterNavigateOptions): void;
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 declare type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
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 declare type RelativeRoutingType = "route" | "path";
317
- declare type BaseNavigateOptions = {
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 Link navigation
337
+ * Options for a navigate() call for a normal (non-submission) navigation
326
338
  */
327
- declare type LinkNavigateOptions = BaseNavigateOptions;
339
+ type LinkNavigateOptions = BaseNavigateOptions;
328
340
  /**
329
- * Options for a navigate() call for a Form navigation
341
+ * Options for a navigate() call for a submission navigation
330
342
  */
331
- declare type SubmissionNavigateOptions = BaseNavigateOptions & {
332
- formMethod?: HTMLFormMethod;
333
- formEncType?: FormEncType;
334
- formData: FormData;
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 to pass to navigate() for either a Link or Form navigation
353
+ * Options for a fetch() submission
338
354
  */
339
- export declare type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
355
+ type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
340
356
  /**
341
357
  * Options to pass to fetch()
342
358
  */
343
- export declare type RouterFetchOptions = Omit<LinkNavigateOptions, "replace"> | Omit<SubmissionNavigateOptions, "replace">;
359
+ export type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
344
360
  /**
345
361
  * Potential states for state.navigation
346
362
  */
347
- export declare type NavigationStates = {
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: FormMethod | V7_FormMethod | undefined;
360
- formAction: string | undefined;
361
- formEncType: FormEncType | undefined;
362
- formData: FormData | undefined;
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: FormMethod | V7_FormMethod;
368
- formAction: string;
369
- formEncType: FormEncType;
370
- formData: 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 declare type Navigation = NavigationStates[keyof NavigationStates];
374
- export declare type RevalidationState = "idle" | "loading";
395
+ export type Navigation = NavigationStates[keyof NavigationStates];
396
+ export type RevalidationState = "idle" | "loading";
375
397
  /**
376
398
  * Potential states for fetchers
377
399
  */
378
- declare type FetcherStates<TData = any> = {
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: FormMethod | V7_FormMethod | undefined;
391
- formAction: string | undefined;
392
- formEncType: FormEncType | undefined;
393
- formData: FormData | undefined;
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: FormMethod | V7_FormMethod;
400
- formAction: string;
401
- formEncType: FormEncType;
402
- formData: FormData;
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 declare type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
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 declare type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
427
- export declare type BlockerFunction = (args: {
454
+ export type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
455
+ export type BlockerFunction = (args: {
428
456
  currentLocation: Location;
429
457
  nextLocation: Location;
430
458
  historyAction: HistoryAction;