dom.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import type { FormEncType, HTMLFormMethod, RelativeRoutingType } from "@remix-run/router";
  2. export declare const defaultMethod: HTMLFormMethod;
  3. export declare function isHtmlElement(object: any): object is HTMLElement;
  4. export declare function isButtonElement(object: any): object is HTMLButtonElement;
  5. export declare function isFormElement(object: any): object is HTMLFormElement;
  6. export declare function isInputElement(object: any): object is HTMLInputElement;
  7. type LimitedMouseEvent = Pick<MouseEvent, "button" | "metaKey" | "altKey" | "ctrlKey" | "shiftKey">;
  8. export declare function shouldProcessLinkClick(event: LimitedMouseEvent, target?: string): boolean;
  9. export type ParamKeyValuePair = [string, string];
  10. export type URLSearchParamsInit = string | ParamKeyValuePair[] | Record<string, string | string[]> | URLSearchParams;
  11. /**
  12. * Creates a URLSearchParams object using the given initializer.
  13. *
  14. * This is identical to `new URLSearchParams(init)` except it also
  15. * supports arrays as values in the object form of the initializer
  16. * instead of just strings. This is convenient when you need multiple
  17. * values for a given key, but don't want to use an array initializer.
  18. *
  19. * For example, instead of:
  20. *
  21. * let searchParams = new URLSearchParams([
  22. * ['sort', 'name'],
  23. * ['sort', 'price']
  24. * ]);
  25. *
  26. * you can do:
  27. *
  28. * let searchParams = createSearchParams({
  29. * sort: ['name', 'price']
  30. * });
  31. */
  32. export declare function createSearchParams(init?: URLSearchParamsInit): URLSearchParams;
  33. export declare function getSearchParamsForLocation(locationSearch: string, defaultSearchParams: URLSearchParams | null): URLSearchParams;
  34. type JsonObject = {
  35. [Key in string]: JsonValue;
  36. } & {
  37. [Key in string]?: JsonValue | undefined;
  38. };
  39. type JsonArray = JsonValue[] | readonly JsonValue[];
  40. type JsonPrimitive = string | number | boolean | null;
  41. type JsonValue = JsonPrimitive | JsonObject | JsonArray;
  42. export type SubmitTarget = HTMLFormElement | HTMLButtonElement | HTMLInputElement | FormData | URLSearchParams | JsonValue | null;
  43. /**
  44. * Submit options shared by both navigations and fetchers
  45. */
  46. interface SharedSubmitOptions {
  47. /**
  48. * The HTTP method used to submit the form. Overrides `<form method>`.
  49. * Defaults to "GET".
  50. */
  51. method?: HTMLFormMethod;
  52. /**
  53. * The action URL path used to submit the form. Overrides `<form action>`.
  54. * Defaults to the path of the current route.
  55. */
  56. action?: string;
  57. /**
  58. * The encoding used to submit the form. Overrides `<form encType>`.
  59. * Defaults to "application/x-www-form-urlencoded".
  60. */
  61. encType?: FormEncType;
  62. /**
  63. * Determines whether the form action is relative to the route hierarchy or
  64. * the pathname. Use this if you want to opt out of navigating the route
  65. * hierarchy and want to instead route based on /-delimited URL segments
  66. */
  67. relative?: RelativeRoutingType;
  68. /**
  69. * In browser-based environments, prevent resetting scroll after this
  70. * navigation when using the <ScrollRestoration> component
  71. */
  72. preventScrollReset?: boolean;
  73. /**
  74. * Enable flushSync for this submission's state updates
  75. */
  76. flushSync?: boolean;
  77. }
  78. /**
  79. * Submit options available to fetchers
  80. */
  81. export interface FetcherSubmitOptions extends SharedSubmitOptions {
  82. }
  83. /**
  84. * Submit options available to navigations
  85. */
  86. export interface SubmitOptions extends FetcherSubmitOptions {
  87. /**
  88. * Set `true` to replace the current entry in the browser's history stack
  89. * instead of creating a new one (i.e. stay on "the same page"). Defaults
  90. * to `false`.
  91. */
  92. replace?: boolean;
  93. /**
  94. * State object to add to the history stack entry for this navigation
  95. */
  96. state?: any;
  97. /**
  98. * Indicate a specific fetcherKey to use when using navigate=false
  99. */
  100. fetcherKey?: string;
  101. /**
  102. * navigate=false will use a fetcher instead of a navigation
  103. */
  104. navigate?: boolean;
  105. /**
  106. * Enable view transitions on this submission navigation
  107. */
  108. viewTransition?: boolean;
  109. }
  110. export declare function getFormSubmissionInfo(target: SubmitTarget, basename: string): {
  111. action: string | null;
  112. method: string;
  113. encType: string;
  114. formData: FormData | undefined;
  115. body: any;
  116. };
  117. export {};