@adonisjs/inertia 4.0.0-next.0 → 4.0.0-next.10
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/README.md +8 -5
- package/build/bin/test.d.ts +1 -0
- package/build/chunk-4EZ2J6OA.js +7 -0
- package/build/chunk-5QRJHXXQ.js +91 -0
- package/build/chunk-DISC5OYC.js +46 -0
- package/build/chunk-MLKGABMK.js +9 -0
- package/build/chunk-YQ72YL64.js +813 -0
- package/build/factories/inertia_factory.d.ts +137 -0
- package/build/factories/main.d.ts +1 -0
- package/build/factories/main.js +175 -0
- package/build/index.d.ts +7 -19
- package/build/index.js +21 -307
- package/build/providers/inertia_provider.d.ts +86 -13
- package/build/providers/inertia_provider.js +48 -18
- package/build/src/client/helpers.d.ts +27 -0
- package/build/src/client/helpers.js +30 -0
- package/build/src/client/react/context.d.ts +24 -0
- package/build/src/client/react/index.d.ts +3 -0
- package/build/src/client/react/index.js +72 -0
- package/build/src/client/react/link.d.ts +64 -0
- package/build/src/client/react/router.d.ts +33 -0
- package/build/src/client/vite.d.ts +65 -0
- package/build/src/{plugins → client}/vite.js +6 -2
- package/build/src/debug.d.ts +22 -0
- package/build/src/define_config.d.ts +30 -0
- package/build/src/headers.d.ts +61 -0
- package/build/src/index_pages.d.ts +32 -0
- package/build/src/inertia.d.ts +261 -0
- package/build/src/inertia_manager.d.ts +47 -0
- package/build/src/inertia_middleware.d.ts +76 -86
- package/build/src/inertia_middleware.js +110 -3
- package/build/src/plugins/edge/plugin.d.ts +30 -6
- package/build/src/plugins/edge/plugin.js +13 -9
- package/build/src/plugins/edge/tags.d.ts +47 -0
- package/build/src/plugins/edge/utils.d.ts +26 -0
- package/build/src/plugins/japa/api_client.d.ts +136 -22
- package/build/src/plugins/japa/api_client.js +36 -48
- package/build/src/props.d.ts +276 -0
- package/build/src/server_renderer.d.ts +54 -0
- package/build/src/symbols.d.ts +25 -0
- package/build/src/types.d.ts +400 -4
- package/build/tests/helpers.d.ts +35 -0
- package/build/tests/index_pages.spec.d.ts +1 -0
- package/build/tests/inertia.spec.d.ts +1 -0
- package/build/tests/inertia_page.spec.d.ts +1 -0
- package/build/tests/middleware.spec.d.ts +1 -0
- package/build/tests/plugins/api_client.spec.d.ts +1 -0
- package/build/tests/plugins/edge.plugin.spec.d.ts +1 -0
- package/build/tests/provider.spec.d.ts +1 -0
- package/build/tests/types/react.spec.d.ts +65 -0
- package/build/tests/types/shared_props.spec.d.ts +1 -0
- package/build/tests/types/to_component_props.spec.d.ts +1 -0
- package/build/tests/types/to_page_props.spec.d.ts +1 -0
- package/package.json +99 -71
- package/build/app.css.stub +0 -13
- package/build/chunk-AWCR2NAY.js +0 -412
- package/build/config.stub +0 -33
- package/build/react/app.tsx.stub +0 -38
- package/build/react/errors/not_found.tsx.stub +0 -14
- package/build/react/errors/server_error.tsx.stub +0 -14
- package/build/react/home.tsx.stub +0 -349
- package/build/react/root.edge.stub +0 -76
- package/build/react/ssr.tsx.stub +0 -17
- package/build/react/tsconfig.json.stub +0 -15
- package/build/solid/app.tsx.stub +0 -38
- package/build/solid/errors/not_found.tsx.stub +0 -14
- package/build/solid/errors/server_error.tsx.stub +0 -14
- package/build/solid/home.tsx.stub +0 -358
- package/build/solid/root.edge.stub +0 -73
- package/build/solid/ssr.tsx.stub +0 -19
- package/build/solid/tsconfig.json.stub +0 -16
- package/build/src/helpers.d.ts +0 -12
- package/build/src/helpers.js +0 -14
- package/build/src/plugins/vite.d.ts +0 -26
- package/build/svelte/app.ts.stub +0 -32
- package/build/svelte/errors/not_found.svelte.stub +0 -10
- package/build/svelte/errors/server_error.svelte.stub +0 -14
- package/build/svelte/home.svelte.stub +0 -339
- package/build/svelte/root.edge.stub +0 -75
- package/build/svelte/ssr.ts.stub +0 -19
- package/build/svelte/tsconfig.json.stub +0 -14
- package/build/types-DVqEHBD1.d.ts +0 -240
- package/build/vue/app.ts.stub +0 -41
- package/build/vue/errors/not_found.vue.stub +0 -10
- package/build/vue/errors/server_error.vue.stub +0 -14
- package/build/vue/home.vue.stub +0 -343
- package/build/vue/root.edge.stub +0 -75
- package/build/vue/ssr.ts.stub +0 -22
- package/build/vue/tsconfig.json.stub +0 -16
|
@@ -1,33 +1,106 @@
|
|
|
1
|
-
import { Route } from '@adonisjs/core/http';
|
|
2
|
-
import { ApplicationService } from '@adonisjs/core/types';
|
|
3
|
-
|
|
1
|
+
import { type Route } from '@adonisjs/core/http';
|
|
2
|
+
import type { ApplicationService } from '@adonisjs/core/types';
|
|
3
|
+
import type { AsPageProps, ComponentProps, InertiaPages, SharedProps } from '../src/types.js';
|
|
4
4
|
declare module '@adonisjs/core/http' {
|
|
5
5
|
interface BriskRoute {
|
|
6
6
|
/**
|
|
7
|
-
* Render an inertia page without defining an
|
|
8
|
-
*
|
|
7
|
+
* Render an inertia page without defining an explicit route handler
|
|
8
|
+
*
|
|
9
|
+
* This method allows you to render Inertia pages directly from route definitions
|
|
10
|
+
* without creating separate controller methods.
|
|
11
|
+
*
|
|
12
|
+
* @param component - The name of the Inertia component to render
|
|
13
|
+
* @param props - Props to pass to the component
|
|
14
|
+
* @param viewProps - Additional props to pass to the root view template
|
|
15
|
+
* @returns The route instance for method chaining
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```js
|
|
19
|
+
* // Basic usage
|
|
20
|
+
* router.get('/dashboard', []).renderInertia('Dashboard', {
|
|
21
|
+
* user: auth.user
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* // With view props
|
|
25
|
+
* router.get('/home', []).renderInertia('Home', {
|
|
26
|
+
* posts: posts
|
|
27
|
+
* }, {
|
|
28
|
+
* title: 'Welcome Home'
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
9
31
|
*/
|
|
10
|
-
renderInertia(component:
|
|
32
|
+
renderInertia<Page extends keyof InertiaPages>(component: Page, props: InertiaPages[Page] extends ComponentProps ? AsPageProps<Omit<InertiaPages[Page], keyof SharedProps>> : never, viewProps?: Record<string, any>): Route;
|
|
11
33
|
}
|
|
12
34
|
}
|
|
13
35
|
/**
|
|
14
|
-
* Inertia
|
|
36
|
+
* AdonisJS service provider for Inertia.js integration
|
|
37
|
+
*
|
|
38
|
+
* This provider handles the registration and configuration of Inertia.js
|
|
39
|
+
* within an AdonisJS application. It sets up the middleware, Edge.js plugin,
|
|
40
|
+
* and route macros needed for Inertia functionality.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```js
|
|
44
|
+
* // Automatically registered when package is installed
|
|
45
|
+
* // Configuration in config/inertia.ts:
|
|
46
|
+
*
|
|
47
|
+
* import { defineConfig } from '@adonisjs/inertia'
|
|
48
|
+
*
|
|
49
|
+
* export default defineConfig({
|
|
50
|
+
* rootView: 'inertia_layout',
|
|
51
|
+
* ssr: { enabled: true }
|
|
52
|
+
* })
|
|
53
|
+
* ```
|
|
15
54
|
*/
|
|
16
|
-
|
|
55
|
+
export default class InertiaProvider {
|
|
17
56
|
protected app: ApplicationService;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new InertiaProvider instance
|
|
59
|
+
*
|
|
60
|
+
* @param app - The AdonisJS application service instance
|
|
61
|
+
*/
|
|
18
62
|
constructor(app: ApplicationService);
|
|
19
63
|
/**
|
|
20
|
-
* Registers
|
|
64
|
+
* Registers the Inertia Edge.js plugin when Edge.js is available
|
|
65
|
+
*
|
|
66
|
+
* This method conditionally registers the Edge plugin that provides
|
|
67
|
+
* @inertia and @inertiaHead tags for rendering Inertia pages.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```edge
|
|
71
|
+
* {{-- Templates can then use --}}
|
|
72
|
+
* @inertia(page)
|
|
73
|
+
* @inertiaHead(page)
|
|
74
|
+
* ```
|
|
21
75
|
*/
|
|
22
76
|
protected registerEdgePlugin(): Promise<void>;
|
|
23
77
|
/**
|
|
24
|
-
*
|
|
78
|
+
* Registers the InertiaManager as a singleton in the IoC container
|
|
79
|
+
*
|
|
80
|
+
* This method sets up the core Inertia manager with the application's
|
|
81
|
+
* configuration and Vite integration. The manager handles page rendering,
|
|
82
|
+
* asset management, and SSR functionality.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```js
|
|
86
|
+
* // The manager is automatically available for injection:
|
|
87
|
+
* const inertiaManager = await app.container.make(InertiaManager)
|
|
88
|
+
* ```
|
|
25
89
|
*/
|
|
26
90
|
register(): Promise<void>;
|
|
27
91
|
/**
|
|
28
|
-
*
|
|
92
|
+
* Boot the provider by registering Edge plugin and route macros
|
|
93
|
+
*
|
|
94
|
+
* This method completes the Inertia setup by registering the Edge plugin
|
|
95
|
+
* and adding the renderInertia macro to BriskRoute for convenient route definitions.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```js
|
|
99
|
+
* // Routes can now use the renderInertia macro
|
|
100
|
+
* router.get('/dashboard', []).renderInertia('Dashboard', {
|
|
101
|
+
* user: getCurrentUser()
|
|
102
|
+
* })
|
|
103
|
+
* ```
|
|
29
104
|
*/
|
|
30
105
|
boot(): Promise<void>;
|
|
31
106
|
}
|
|
32
|
-
|
|
33
|
-
export { InertiaProvider as default };
|
|
@@ -1,42 +1,72 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
2
|
+
InertiaManager
|
|
3
|
+
} from "../chunk-YQ72YL64.js";
|
|
4
|
+
import "../chunk-4EZ2J6OA.js";
|
|
5
|
+
import "../chunk-DISC5OYC.js";
|
|
6
|
+
import "../chunk-MLKGABMK.js";
|
|
4
7
|
|
|
5
8
|
// providers/inertia_provider.ts
|
|
6
|
-
import { configProvider } from "@adonisjs/core";
|
|
7
|
-
import { RuntimeException } from "@poppinss/utils";
|
|
8
9
|
import { BriskRoute } from "@adonisjs/core/http";
|
|
9
10
|
var InertiaProvider = class {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new InertiaProvider instance
|
|
13
|
+
*
|
|
14
|
+
* @param app - The AdonisJS application service instance
|
|
15
|
+
*/
|
|
10
16
|
constructor(app) {
|
|
11
17
|
this.app = app;
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
|
-
* Registers
|
|
20
|
+
* Registers the Inertia Edge.js plugin when Edge.js is available
|
|
21
|
+
*
|
|
22
|
+
* This method conditionally registers the Edge plugin that provides
|
|
23
|
+
* @inertia and @inertiaHead tags for rendering Inertia pages.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```edge
|
|
27
|
+
* {{-- Templates can then use --}}
|
|
28
|
+
* @inertia(page)
|
|
29
|
+
* @inertiaHead(page)
|
|
30
|
+
* ```
|
|
15
31
|
*/
|
|
16
32
|
async registerEdgePlugin() {
|
|
17
|
-
if (!this.app.usingEdgeJS) return;
|
|
18
33
|
const edgeExports = await import("edge.js");
|
|
19
34
|
const { edgePluginInertia } = await import("../src/plugins/edge/plugin.js");
|
|
20
35
|
edgeExports.default.use(edgePluginInertia());
|
|
21
36
|
}
|
|
22
37
|
/**
|
|
23
|
-
*
|
|
38
|
+
* Registers the InertiaManager as a singleton in the IoC container
|
|
39
|
+
*
|
|
40
|
+
* This method sets up the core Inertia manager with the application's
|
|
41
|
+
* configuration and Vite integration. The manager handles page rendering,
|
|
42
|
+
* asset management, and SSR functionality.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```js
|
|
46
|
+
* // The manager is automatically available for injection:
|
|
47
|
+
* const inertiaManager = await app.container.make(InertiaManager)
|
|
48
|
+
* ```
|
|
24
49
|
*/
|
|
25
50
|
async register() {
|
|
26
|
-
this.app.container.singleton(
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
if (!config) {
|
|
31
|
-
throw new RuntimeException(
|
|
32
|
-
'Invalid "config/inertia.ts" file. Make sure you are using the "defineConfig" method'
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
return new InertiaMiddleware(config, vite);
|
|
51
|
+
this.app.container.singleton(InertiaManager, async (resolver) => {
|
|
52
|
+
const config = this.app.config.get("inertia", {});
|
|
53
|
+
const vite = await resolver.make("vite");
|
|
54
|
+
return new InertiaManager(config, vite);
|
|
36
55
|
});
|
|
37
56
|
}
|
|
38
57
|
/**
|
|
39
|
-
*
|
|
58
|
+
* Boot the provider by registering Edge plugin and route macros
|
|
59
|
+
*
|
|
60
|
+
* This method completes the Inertia setup by registering the Edge plugin
|
|
61
|
+
* and adding the renderInertia macro to BriskRoute for convenient route definitions.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```js
|
|
65
|
+
* // Routes can now use the renderInertia macro
|
|
66
|
+
* router.get('/dashboard', []).renderInertia('Dashboard', {
|
|
67
|
+
* user: getCurrentUser()
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
40
70
|
*/
|
|
41
71
|
async boot() {
|
|
42
72
|
await this.registerEdgePlugin();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a page component from a given path or array of paths by looking up
|
|
3
|
+
* the component in the provided pages registry. Supports both direct promises
|
|
4
|
+
* and lazy-loaded functions that return promises.
|
|
5
|
+
*
|
|
6
|
+
* @param path - The page path(s) to resolve. Can be a single string or array of strings
|
|
7
|
+
* @param pages - Registry of page components where keys are paths and values are either promises or functions returning promises
|
|
8
|
+
* @param layout - Optional layout component to assign to the resolved page
|
|
9
|
+
* @returns Promise resolving to the page component
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```js
|
|
13
|
+
* // Single path resolution
|
|
14
|
+
* const component = await resolvePageComponent('Home', {
|
|
15
|
+
* 'Home': () => import('./pages/Home.vue'),
|
|
16
|
+
* 'About': () => import('./pages/About.vue')
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* // Multiple path resolution (fallback)
|
|
20
|
+
* const component = await resolvePageComponent(['Dashboard/Admin', 'Dashboard'], {
|
|
21
|
+
* 'Dashboard': () => import('./pages/Dashboard.vue')
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @throws Error When none of the provided paths can be resolved in the pages registry
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>) | T>, layout?: any): Promise<T>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import "../../chunk-MLKGABMK.js";
|
|
2
|
+
|
|
3
|
+
// src/client/helpers.ts
|
|
4
|
+
async function resolvePageComponent(path, pages, layout) {
|
|
5
|
+
for (const p of Array.isArray(path) ? path : [path]) {
|
|
6
|
+
const page = pages[p];
|
|
7
|
+
if (typeof page === "undefined") {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
const resolvedPage = await (typeof page === "function" ? page() : page);
|
|
11
|
+
if (!resolvedPage) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Invalid page exported from "${path}". Make sure to default export a function`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
if ("default" in resolvedPage === false) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Invalid page exported from "${path}". Make sure to default export a function`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (layout && !resolvedPage.default.layout) {
|
|
22
|
+
resolvedPage.default.layout = layout;
|
|
23
|
+
}
|
|
24
|
+
return resolvedPage;
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`Page not found: "${path}"`);
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
resolvePageComponent
|
|
30
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Tuyau } from '@tuyau/core/client';
|
|
3
|
+
import type { AdonisRegistry } from '@tuyau/core/types';
|
|
4
|
+
/**
|
|
5
|
+
* Provider component that makes the Tuyau client available to child components.
|
|
6
|
+
*
|
|
7
|
+
* This component should wrap your entire application or the part of your
|
|
8
|
+
* application that needs access to type-safe routing functionality.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export declare function TuyauProvider<R extends AdonisRegistry>(props: {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
client: Tuyau<R>;
|
|
14
|
+
}): React.JSX.Element;
|
|
15
|
+
/**
|
|
16
|
+
* Hook to access the Tuyau client from any component within a TuyauProvider.
|
|
17
|
+
*
|
|
18
|
+
* Provides type-safe access to route generation and navigation utilities.
|
|
19
|
+
* Must be used within a component tree wrapped by TuyauProvider.
|
|
20
|
+
*
|
|
21
|
+
* @returns The Tuyau client instance with full type safety
|
|
22
|
+
* @throws Error if used outside of a TuyauProvider
|
|
23
|
+
*/
|
|
24
|
+
export declare function useTuyau(): Tuyau<any>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import "../../../chunk-MLKGABMK.js";
|
|
2
|
+
|
|
3
|
+
// src/client/react/context.tsx
|
|
4
|
+
import React from "react";
|
|
5
|
+
var TuyauContext = React.createContext(null);
|
|
6
|
+
function TuyauProvider(props) {
|
|
7
|
+
return /* @__PURE__ */ React.createElement(TuyauContext.Provider, { value: props.client }, props.children);
|
|
8
|
+
}
|
|
9
|
+
function useTuyau() {
|
|
10
|
+
const context = React.useContext(TuyauContext);
|
|
11
|
+
if (!context) throw new Error("You must wrap your app in a TuyauProvider");
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/client/react/router.ts
|
|
16
|
+
import { router as InertiaRouter } from "@inertiajs/react";
|
|
17
|
+
function useRouter() {
|
|
18
|
+
const tuyau = useTuyau();
|
|
19
|
+
return {
|
|
20
|
+
/**
|
|
21
|
+
* Navigate to a route with type-safe parameters and options.
|
|
22
|
+
*
|
|
23
|
+
* Automatically resolves the route URL and HTTP method based on the
|
|
24
|
+
* route definition, then performs the navigation using Inertia's router.
|
|
25
|
+
*
|
|
26
|
+
* @param props - Route navigation parameters including route name and params
|
|
27
|
+
* @param options - Optional Inertia visit options for controlling navigation behavior
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* // Navigate to a simple route
|
|
32
|
+
* router.visit({ route: 'dashboard' })
|
|
33
|
+
*
|
|
34
|
+
* // Navigate with parameters
|
|
35
|
+
* router.visit({ route: 'user.edit', params: { id: userId } })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
visit: (props, options) => {
|
|
39
|
+
const routeInfo = tuyau.getRoute(props.route, { params: props.params });
|
|
40
|
+
const url = routeInfo.url;
|
|
41
|
+
return InertiaRouter.visit(url, {
|
|
42
|
+
...options,
|
|
43
|
+
method: routeInfo.methods[0].toLowerCase()
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/client/react/link.tsx
|
|
50
|
+
import React2 from "react";
|
|
51
|
+
import { Link as InertiaLink } from "@inertiajs/react";
|
|
52
|
+
function LinkInner(props, ref) {
|
|
53
|
+
const { route, params, ...linkProps } = props;
|
|
54
|
+
const tuyau = useTuyau();
|
|
55
|
+
const routeInfo = tuyau.getRoute(props.route, { params });
|
|
56
|
+
return /* @__PURE__ */ React2.createElement(
|
|
57
|
+
InertiaLink,
|
|
58
|
+
{
|
|
59
|
+
...linkProps,
|
|
60
|
+
href: routeInfo.url,
|
|
61
|
+
method: routeInfo.methods[0].toLowerCase(),
|
|
62
|
+
ref
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
var Link = React2.forwardRef(LinkInner);
|
|
67
|
+
export {
|
|
68
|
+
Link,
|
|
69
|
+
TuyauProvider,
|
|
70
|
+
useRouter,
|
|
71
|
+
useTuyau
|
|
72
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { UserRegistry } from '@tuyau/core/types';
|
|
3
|
+
import { Link as InertiaLink } from '@inertiajs/react';
|
|
4
|
+
import { AreAllOptional } from '@poppinss/utils/types';
|
|
5
|
+
/**
|
|
6
|
+
* Get parameter tuple type for a route
|
|
7
|
+
*/
|
|
8
|
+
type ExtractParamsTuple<Route extends keyof UserRegistry> = UserRegistry[Route]['types']['paramsTuple'];
|
|
9
|
+
/**
|
|
10
|
+
* Get parameter object type for a route
|
|
11
|
+
*/
|
|
12
|
+
type ExtractParamsObject<Route extends keyof UserRegistry> = UserRegistry[Route]['types']['params'];
|
|
13
|
+
/**
|
|
14
|
+
* Get params format for a route
|
|
15
|
+
*/
|
|
16
|
+
type RouteParamsFormats<Route extends keyof UserRegistry> = ExtractParamsObject<Route> extends Record<string, never> ? never : ExtractParamsTuple<Route> | ExtractParamsObject<Route>;
|
|
17
|
+
/**
|
|
18
|
+
* Parameters required for route navigation with proper type safety.
|
|
19
|
+
*/
|
|
20
|
+
export type LinkParams<Route extends keyof UserRegistry> = {
|
|
21
|
+
route: Route;
|
|
22
|
+
} & (RouteParamsFormats<Route> extends never ? {
|
|
23
|
+
params?: never;
|
|
24
|
+
} : AreAllOptional<ExtractParamsObject<Route>> extends true ? {
|
|
25
|
+
params?: RouteParamsFormats<Route>;
|
|
26
|
+
} : {
|
|
27
|
+
params: RouteParamsFormats<Route>;
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Props for the Link component extending InertiaLink props
|
|
31
|
+
* with route-specific type safety and parameter validation.
|
|
32
|
+
*/
|
|
33
|
+
type LinkProps<Route extends keyof UserRegistry> = Omit<React.ComponentPropsWithoutRef<typeof InertiaLink>, 'href' | 'method'> & LinkParams<Route>;
|
|
34
|
+
/**
|
|
35
|
+
* Internal Link component implementation with forward ref support.
|
|
36
|
+
* Resolves route parameters and generates the appropriate URL and HTTP method
|
|
37
|
+
* for Inertia navigation.
|
|
38
|
+
*
|
|
39
|
+
* @param props - Link properties including route and parameters
|
|
40
|
+
* @param ref - Forward ref for the underlying InertiaLink component
|
|
41
|
+
*/
|
|
42
|
+
declare function LinkInner<Route extends keyof UserRegistry>(props: LinkProps<Route>, ref?: React.ForwardedRef<React.ElementRef<typeof InertiaLink>>): React.JSX.Element;
|
|
43
|
+
/**
|
|
44
|
+
* Type-safe Link component for Inertia.js navigation.
|
|
45
|
+
*
|
|
46
|
+
* Provides compile-time route validation and automatic parameter type checking
|
|
47
|
+
* based on your application's route definitions. Automatically resolves the
|
|
48
|
+
* correct URL and HTTP method for each route.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* // Link to a route without parameters
|
|
53
|
+
* <Link route="home">Home</Link>
|
|
54
|
+
*
|
|
55
|
+
* // Link to a route with required parameters
|
|
56
|
+
* <Link route="user.show" params={{ id: 1 }}>
|
|
57
|
+
* View User
|
|
58
|
+
* </Link>
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const Link: <Route extends keyof UserRegistry>(props: LinkProps<Route> & {
|
|
62
|
+
ref?: React.Ref<React.ElementRef<typeof InertiaLink>>;
|
|
63
|
+
}) => ReturnType<typeof LinkInner>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { UserRegistry } from '@tuyau/core/types';
|
|
2
|
+
import { router as InertiaRouter } from '@inertiajs/react';
|
|
3
|
+
import type { LinkParams } from './link.tsx';
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook providing type-safe navigation utilities for Inertia.js.
|
|
6
|
+
*
|
|
7
|
+
* Returns an enhanced router object with type-safe navigation methods
|
|
8
|
+
* that automatically resolve route URLs and HTTP methods based on
|
|
9
|
+
* your application's route definitions.
|
|
10
|
+
*
|
|
11
|
+
* @returns Router object with type-safe navigation methods
|
|
12
|
+
*/
|
|
13
|
+
export declare function useRouter(): {
|
|
14
|
+
/**
|
|
15
|
+
* Navigate to a route with type-safe parameters and options.
|
|
16
|
+
*
|
|
17
|
+
* Automatically resolves the route URL and HTTP method based on the
|
|
18
|
+
* route definition, then performs the navigation using Inertia's router.
|
|
19
|
+
*
|
|
20
|
+
* @param props - Route navigation parameters including route name and params
|
|
21
|
+
* @param options - Optional Inertia visit options for controlling navigation behavior
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* // Navigate to a simple route
|
|
26
|
+
* router.visit({ route: 'dashboard' })
|
|
27
|
+
*
|
|
28
|
+
* // Navigate with parameters
|
|
29
|
+
* router.visit({ route: 'user.edit', params: { id: userId } })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
visit: <Route extends keyof UserRegistry>(props: LinkParams<Route>, options?: Parameters<typeof InertiaRouter.visit>[1]) => any;
|
|
33
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the Inertia Vite plugin
|
|
4
|
+
*/
|
|
5
|
+
export type InertiaPluginOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Server-side rendering configuration
|
|
8
|
+
*/
|
|
9
|
+
ssr?: {
|
|
10
|
+
/**
|
|
11
|
+
* Whether or not to enable server-side rendering
|
|
12
|
+
*/
|
|
13
|
+
enabled: true;
|
|
14
|
+
/**
|
|
15
|
+
* The entrypoint for the server-side rendering
|
|
16
|
+
*/
|
|
17
|
+
entrypoint: string;
|
|
18
|
+
/**
|
|
19
|
+
* The output directory for the server-side rendering bundle
|
|
20
|
+
*/
|
|
21
|
+
output?: string;
|
|
22
|
+
} | {
|
|
23
|
+
enabled: false;
|
|
24
|
+
entrypoint?: string;
|
|
25
|
+
output?: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Inertia plugin for Vite that is tailored for AdonisJS
|
|
30
|
+
*
|
|
31
|
+
* Configures Vite for Inertia.js development with proper build settings,
|
|
32
|
+
* SSR support, and AdonisJS-specific optimizations.
|
|
33
|
+
*
|
|
34
|
+
* @param options - Configuration options for the plugin
|
|
35
|
+
* @returns Vite plugin configuration object
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```js
|
|
39
|
+
* // Basic configuration
|
|
40
|
+
* import inertia from '@adonisjs/inertia/plugins/vite'
|
|
41
|
+
*
|
|
42
|
+
* export default defineConfig({
|
|
43
|
+
* plugins: [inertia()]
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```js
|
|
49
|
+
* // With SSR enabled
|
|
50
|
+
* import inertia from '@adonisjs/inertia/plugins/vite'
|
|
51
|
+
*
|
|
52
|
+
* export default defineConfig({
|
|
53
|
+
* plugins: [
|
|
54
|
+
* inertia({
|
|
55
|
+
* ssr: {
|
|
56
|
+
* enabled: true,
|
|
57
|
+
* entrypoint: 'inertia/ssr.tsx',
|
|
58
|
+
* output: 'build/ssr'
|
|
59
|
+
* }
|
|
60
|
+
* })
|
|
61
|
+
* ]
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export default function inertia(options?: InertiaPluginOptions): PluginOption;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import "../../chunk-MLKGABMK.js";
|
|
2
|
+
|
|
3
|
+
// src/client/vite.ts
|
|
2
4
|
function inertia(options) {
|
|
3
5
|
return {
|
|
4
6
|
name: "vite-plugin-inertia",
|
|
5
7
|
config: (_, { command }) => {
|
|
6
|
-
if (command === "build")
|
|
8
|
+
if (command === "build") {
|
|
9
|
+
process.env.NODE_ENV = "production";
|
|
10
|
+
}
|
|
7
11
|
return {
|
|
8
12
|
builder: {},
|
|
9
13
|
build: { outDir: "build/public/assets" },
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug logger for Inertia.js package
|
|
3
|
+
*
|
|
4
|
+
* Provides debugging functionality using Node.js built-in debuglog.
|
|
5
|
+
* Enable debugging by setting the NODE_DEBUG environment variable to 'adonisjs:inertia'.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```js
|
|
9
|
+
* import debug from './debug.js'
|
|
10
|
+
*
|
|
11
|
+
* debug('Processing Inertia request')
|
|
12
|
+
* debug('Component: %s, Props: %o', componentName, props)
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```bash
|
|
17
|
+
* # Enable debugging
|
|
18
|
+
* NODE_DEBUG=adonisjs:inertia node server.js
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const _default: import("util").DebugLogger;
|
|
22
|
+
export default _default;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { InertiaConfig, InertiaConfigInput } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Define the Inertia configuration with default values
|
|
4
|
+
*
|
|
5
|
+
* This function merges user-provided configuration with sensible defaults
|
|
6
|
+
* to create a complete Inertia configuration object.
|
|
7
|
+
*
|
|
8
|
+
* @param config - User configuration input to override defaults
|
|
9
|
+
* @returns Complete Inertia configuration object with defaults applied
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```js
|
|
13
|
+
* const config = defineConfig({
|
|
14
|
+
* rootView: 'layouts/app',
|
|
15
|
+
* ssr: {
|
|
16
|
+
* enabled: true,
|
|
17
|
+
* bundle: 'build/ssr/ssr.js'
|
|
18
|
+
* }
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```js
|
|
24
|
+
* // Minimal configuration
|
|
25
|
+
* const config = defineConfig({
|
|
26
|
+
* rootView: 'app'
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function defineConfig(config: InertiaConfigInput): InertiaConfig;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of possible headers used by Inertia.js for client-server communication.
|
|
3
|
+
* These headers control various aspects of Inertia requests and responses,
|
|
4
|
+
* enabling features like partial reloads, version checking, and error handling.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```javascript
|
|
8
|
+
* // Check if request is an Inertia request
|
|
9
|
+
* const isInertiaRequest = request.header(InertiaHeaders.Inertia) === 'true'
|
|
10
|
+
*
|
|
11
|
+
* // Set version header in response
|
|
12
|
+
* response.header(InertiaHeaders.Version, '1.0.0')
|
|
13
|
+
*
|
|
14
|
+
* // Handle partial data requests
|
|
15
|
+
* if (request.header(InertiaHeaders.PartialOnly)) {
|
|
16
|
+
* const onlyProps = request.header(InertiaHeaders.PartialOnly).split(',')
|
|
17
|
+
* // Return only specified props
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const InertiaHeaders: {
|
|
22
|
+
/**
|
|
23
|
+
* Header to identify Inertia.js requests.
|
|
24
|
+
* Set to 'true' by Inertia.js client to indicate an Inertia request.
|
|
25
|
+
*/
|
|
26
|
+
readonly Inertia: "x-inertia";
|
|
27
|
+
/**
|
|
28
|
+
* Header to drop a prop from the merge and deep merge object.
|
|
29
|
+
*/
|
|
30
|
+
readonly Reset: "x-inertia-reset";
|
|
31
|
+
/**
|
|
32
|
+
* Header containing the current asset version.
|
|
33
|
+
* Used for cache busting - if versions don't match, Inertia performs a full page reload.
|
|
34
|
+
*/
|
|
35
|
+
readonly Version: "x-inertia-version";
|
|
36
|
+
/**
|
|
37
|
+
* Header containing the target URL for redirects.
|
|
38
|
+
* Used when the server wants to redirect to a different URL than the current request.
|
|
39
|
+
*/
|
|
40
|
+
readonly Location: "x-inertia-location";
|
|
41
|
+
/**
|
|
42
|
+
* Header specifying the error bag name for validation errors.
|
|
43
|
+
* Allows multiple forms on the same page to have separate error handling.
|
|
44
|
+
*/
|
|
45
|
+
readonly ErrorBag: "x-inertia-error-bag";
|
|
46
|
+
/**
|
|
47
|
+
* Header containing comma-separated list of props to include in partial data requests.
|
|
48
|
+
* Only the specified props will be returned in the response.
|
|
49
|
+
*/
|
|
50
|
+
readonly PartialOnly: "x-inertia-partial-data";
|
|
51
|
+
/**
|
|
52
|
+
* Header containing comma-separated list of props to exclude in partial data requests.
|
|
53
|
+
* All props except the specified ones will be returned in the response.
|
|
54
|
+
*/
|
|
55
|
+
readonly PartialExcept: "x-inertia-partial-except";
|
|
56
|
+
/**
|
|
57
|
+
* Header specifying the component name for partial reloads.
|
|
58
|
+
* Used to identify which component is being partially reloaded.
|
|
59
|
+
*/
|
|
60
|
+
readonly PartialComponent: "x-inertia-partial-component";
|
|
61
|
+
};
|