@firtoz/router-toolkit 5.5.0 → 5.5.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/router-toolkit",
3
- "version": "5.5.0",
3
+ "version": "5.5.1",
4
4
  "description": "Type-safe React Router 7 framework mode helpers with enhanced fetching, form submission, and state management",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -69,6 +69,12 @@ type SubmitJsonOptions = {
69
69
  /** Optional serializable payload for FormData submissions (for display in operations list; FormData/File are not stored in state). */
70
70
  export type FormDataSubmittedData = Record<string, unknown>;
71
71
 
72
+ /** Options for submitFormData (e.g. Accept: application/json so the action returns JSON instead of redirecting). */
73
+ export type SubmitFormDataOptions = {
74
+ headers?: HeadersInit;
75
+ method?: "POST" | "PUT" | "PATCH" | "DELETE";
76
+ };
77
+
72
78
  /**
73
79
  * Submits JSON to the action URL via fetch and returns the parsed JSON.
74
80
  */
@@ -93,18 +99,17 @@ async function submitJsonToAction<T>(
93
99
 
94
100
  /**
95
101
  * Submits FormData to the action URL. No Content-Type header — browser sets multipart/form-data with boundary.
102
+ * Optional headers (e.g. Accept: application/json) let the action return JSON instead of redirecting.
96
103
  */
97
104
  async function submitFormDataToAction<T>(
98
105
  actionUrl: string,
99
106
  formData: FormData,
100
- options: {
101
- method?: "POST" | "PUT" | "PATCH" | "DELETE";
102
- fetchFn?: typeof fetch;
103
- },
107
+ options: SubmitFormDataOptions & { fetchFn?: typeof fetch },
104
108
  ): Promise<T> {
105
- const { method = "POST", fetchFn = fetch } = options;
109
+ const { method = "POST", headers, fetchFn = fetch } = options;
106
110
  const res = await fetchFn(actionUrl, {
107
111
  method,
112
+ ...(headers && { headers }),
108
113
  body: formData,
109
114
  });
110
115
  if (!res.ok) {
@@ -145,6 +150,7 @@ export function useConcurrentDynamicSubmitter<TInfo extends RouteModule>(
145
150
  submitFormData: (
146
151
  formData: FormData,
147
152
  submittedData?: FormDataSubmittedData,
153
+ options?: SubmitFormDataOptions,
148
154
  ) => SubmitJsonResult<ActionResult<TInfo>>;
149
155
  } {
150
156
  const actionUrl = useMemo(() => {
@@ -211,6 +217,7 @@ export function useConcurrentDynamicSubmitter<TInfo extends RouteModule>(
211
217
  (
212
218
  formData: FormData,
213
219
  submittedData: FormDataSubmittedData = {},
220
+ options: SubmitFormDataOptions = {},
214
221
  ): SubmitJsonResult<ActionResult<TInfo>> => {
215
222
  const id = `op-${++nextIdRef.current}`;
216
223
  setOperations((prev) => ({
@@ -221,7 +228,7 @@ export function useConcurrentDynamicSubmitter<TInfo extends RouteModule>(
221
228
  const promise = submitFormDataToAction<ActionResult<TInfo>>(
222
229
  actionUrl,
223
230
  formData,
224
- { method: "POST" },
231
+ options,
225
232
  )
226
233
  .then((responseData) => {
227
234
  setOperations((prev) => ({