@adonisjs/inertia 4.0.0-next.15 → 4.0.0-next.16

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.
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import type { UserRegistry, InferRoutes } from '@tuyau/core/types';
3
+ import { AreAllOptional } from '@poppinss/utils/types';
4
+ import { Form as InertiaForm } from '@inertiajs/react';
5
+ type Routes = InferRoutes<UserRegistry>;
6
+ /**
7
+ * Get parameter tuple type for a route
8
+ */
9
+ type ExtractParamsTuple<Route extends keyof Routes> = Routes[Route]['types']['paramsTuple'];
10
+ /**
11
+ * Get parameter object type for a route
12
+ */
13
+ type ExtractParamsObject<Route extends keyof Routes> = Routes[Route]['types']['params'];
14
+ /**
15
+ * Get params format for a route
16
+ */
17
+ type RouteParamsFormats<Route extends keyof Routes> = ExtractParamsObject<Route> extends Record<string, never> ? never : ExtractParamsTuple<Route> | ExtractParamsObject<Route>;
18
+ /**
19
+ * Parameters required for route navigation with proper type safety.
20
+ */
21
+ export type FormParams<Route extends keyof Routes> = {
22
+ route: Route;
23
+ } & (RouteParamsFormats<Route> extends never ? {
24
+ params?: never;
25
+ } : AreAllOptional<ExtractParamsObject<Route>> extends true ? {
26
+ params?: RouteParamsFormats<Route>;
27
+ } : {
28
+ params: RouteParamsFormats<Route>;
29
+ });
30
+ /**
31
+ * Props for the Form component extending InertiaForm props
32
+ * with route-specific type safety and parameter validation.
33
+ */
34
+ type FormProps<Route extends keyof Routes> = Omit<React.ComponentPropsWithoutRef<typeof InertiaForm>, 'action' | 'method'> & FormParams<Route>;
35
+ /**
36
+ * Internal Form component implementation with forward ref support.
37
+ * Resolves route parameters and generates the appropriate URL and HTTP method
38
+ * for Inertia form submission.
39
+ */
40
+ declare function FormInner<Route extends keyof Routes>(props: FormProps<Route>, ref?: React.ForwardedRef<React.ElementRef<typeof InertiaForm>>): React.JSX.Element;
41
+ /**
42
+ * Type-safe Form component for Inertia.js form submissions.
43
+ *
44
+ * Provides compile-time route validation and automatic parameter type checking
45
+ * based on your application's route definitions. Automatically resolves the
46
+ * correct URL and HTTP method for each route.
47
+ *
48
+ * @example
49
+ * ```tsx
50
+ * // Form to a route without parameters
51
+ * <Form route="users.store">
52
+ * {({ processing }) => (
53
+ * <>
54
+ * <input type="text" name="name" />
55
+ * <button type="submit" disabled={processing}>Create</button>
56
+ * </>
57
+ * )}
58
+ * </Form>
59
+ *
60
+ * // Form to a route with required parameters
61
+ * <Form route="users.update" params={{ id: 1 }}>
62
+ * {({ errors }) => (
63
+ * <>
64
+ * <input type="text" name="name" />
65
+ * {errors.name && <div>{errors.name}</div>}
66
+ * <button type="submit">Update</button>
67
+ * </>
68
+ * )}
69
+ * </Form>
70
+ * ```
71
+ */
72
+ export declare const Form: <Route extends keyof Routes>(props: FormProps<Route> & {
73
+ ref?: React.Ref<React.ElementRef<typeof InertiaForm>>;
74
+ }) => ReturnType<typeof FormInner>;
75
+ export {};
@@ -1,3 +1,4 @@
1
1
  export * from './context.tsx';
2
2
  export * from './router.ts';
3
3
  export * from './link.tsx';
4
+ export * from './form.tsx';
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { Link as Link$1, router } from "@inertiajs/react";
2
+ import { Form as Form$1, Link as Link$1, router } from "@inertiajs/react";
3
3
  const TuyauContext = React.createContext(null);
4
4
  function TuyauProvider(props) {
5
5
  return <TuyauContext.Provider value={props.client}>{props.children}</TuyauContext.Provider>;
@@ -21,9 +21,18 @@ function useRouter() {
21
21
  } };
22
22
  }
23
23
  function LinkInner(props, ref) {
24
- const { route, params, ...linkProps } = props;
24
+ const { route: _route, params, ...linkProps } = props;
25
25
  const routeInfo = useTuyau().getRoute(props.route, { params });
26
26
  return <Link$1 {...linkProps} href={routeInfo.url} method={routeInfo.methods[0].toLowerCase()} ref={ref} />;
27
27
  }
28
28
  const Link = React.forwardRef(LinkInner);
29
- export { Link, TuyauProvider, useRouter, useTuyau };
29
+ function FormInner(props, ref) {
30
+ const { route: _route, params, ...formProps } = props;
31
+ const routeInfo = useTuyau().getRoute(props.route, { params });
32
+ return <Form$1 {...formProps} action={{
33
+ url: routeInfo.url,
34
+ method: routeInfo.methods[0].toLowerCase()
35
+ }} ref={ref} />;
36
+ }
37
+ const Form = React.forwardRef(FormInner);
38
+ export { Form, Link, TuyauProvider, useRouter, useTuyau };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/inertia",
3
3
  "description": "Official Inertia.js adapter for AdonisJS",
4
- "version": "4.0.0-next.15",
4
+ "version": "4.0.0-next.16",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -45,11 +45,11 @@
45
45
  "devDependencies": {
46
46
  "@adonisjs/assembler": "^8.0.0-next.27",
47
47
  "@adonisjs/core": "^7.0.0-next.16",
48
- "@adonisjs/eslint-config": "^3.0.0-next.5",
48
+ "@adonisjs/eslint-config": "^3.0.0-next.6",
49
49
  "@adonisjs/prettier-config": "^1.4.5",
50
50
  "@adonisjs/session": "^8.0.0-next.1",
51
51
  "@adonisjs/tsconfig": "^2.0.0-next.3",
52
- "@adonisjs/vite": "^5.1.0-next.0",
52
+ "@adonisjs/vite": "^5.1.0-next.2",
53
53
  "@inertiajs/react": "^2.3.4",
54
54
  "@japa/api-client": "^3.1.1",
55
55
  "@japa/assert": "4.2.0",
@@ -60,7 +60,7 @@
60
60
  "@japa/snapshot": "^2.0.10",
61
61
  "@poppinss/ts-exec": "^1.4.1",
62
62
  "@release-it/conventional-changelog": "^10.0.4",
63
- "@tuyau/core": "^1.0.0-beta.7",
63
+ "@tuyau/core": "^1.0.0-beta.9",
64
64
  "@types/node": "^25.0.3",
65
65
  "@types/react": "^19.2.7",
66
66
  "@types/supertest": "^6.0.3",