@adonisjs/inertia 3.1.1 → 4.0.0-next.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/README.md +8 -5
- package/build/bin/test.d.ts +1 -0
- package/build/chunk-4EZ2J6OA.js +7 -0
- package/build/chunk-74S2VAL7.js +761 -0
- package/build/chunk-DISC5OYC.js +46 -0
- package/build/chunk-MLKGABMK.js +9 -0
- package/build/chunk-PDP56GPP.js +75 -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/vite.d.ts +63 -0
- package/build/src/{plugins → client}/vite.js +9 -13
- package/build/src/debug.d.ts +22 -0
- package/build/src/define_config.d.ts +29 -0
- package/build/src/headers.d.ts +61 -0
- package/build/src/index_pages.d.ts +5 -0
- package/build/src/inertia.d.ts +253 -0
- package/build/src/inertia_manager.d.ts +46 -0
- package/build/src/inertia_middleware.d.ts +74 -87
- 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 +269 -0
- package/build/src/server_renderer.d.ts +54 -0
- package/build/src/symbols.d.ts +25 -0
- package/build/src/types.d.ts +404 -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/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 +88 -71
- package/build/app.css.stub +0 -13
- package/build/chunk-W7TVEB4V.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
package/build/index.js
CHANGED
|
@@ -1,310 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{ name: "@inertiajs/vue3", isDevDependency: false },
|
|
17
|
-
{ name: "vue", isDevDependency: false },
|
|
18
|
-
{ name: "@vitejs/plugin-vue", isDevDependency: true }
|
|
19
|
-
],
|
|
20
|
-
ssrDependencies: [{ name: "@vue/server-renderer", isDevDependency: false }],
|
|
21
|
-
viteRegister: {
|
|
22
|
-
pluginCall: "vue()",
|
|
23
|
-
importDeclarations: [{ isNamed: false, module: "@vitejs/plugin-vue", identifier: "vue" }]
|
|
24
|
-
},
|
|
25
|
-
ssrEntrypoint: "inertia/app/ssr.ts"
|
|
26
|
-
},
|
|
27
|
-
react: {
|
|
28
|
-
stubFolder: "react",
|
|
29
|
-
appExtension: "tsx",
|
|
30
|
-
componentsExtension: "tsx",
|
|
31
|
-
dependencies: [
|
|
32
|
-
{ name: "@inertiajs/react", isDevDependency: false },
|
|
33
|
-
{ name: "react", isDevDependency: false },
|
|
34
|
-
{ name: "react-dom", isDevDependency: false },
|
|
35
|
-
{ name: "@vitejs/plugin-react", isDevDependency: true },
|
|
36
|
-
{ name: "@types/react", isDevDependency: true },
|
|
37
|
-
{ name: "@types/react-dom", isDevDependency: true }
|
|
38
|
-
],
|
|
39
|
-
viteRegister: {
|
|
40
|
-
pluginCall: "react()",
|
|
41
|
-
importDeclarations: [{ isNamed: false, module: "@vitejs/plugin-react", identifier: "react" }]
|
|
42
|
-
},
|
|
43
|
-
ssrEntrypoint: "inertia/app/ssr.tsx"
|
|
44
|
-
},
|
|
45
|
-
svelte: {
|
|
46
|
-
stubFolder: "svelte",
|
|
47
|
-
appExtension: "ts",
|
|
48
|
-
componentsExtension: "svelte",
|
|
49
|
-
dependencies: [
|
|
50
|
-
{ name: "@inertiajs/svelte", isDevDependency: false },
|
|
51
|
-
{ name: "svelte", isDevDependency: false },
|
|
52
|
-
{ name: "@sveltejs/vite-plugin-svelte", isDevDependency: true }
|
|
53
|
-
],
|
|
54
|
-
viteRegister: {
|
|
55
|
-
pluginCall: "svelte()",
|
|
56
|
-
ssrPluginCall: "svelte({ compilerOptions: { hydratable: true } })",
|
|
57
|
-
importDeclarations: [
|
|
58
|
-
{ isNamed: true, module: "@sveltejs/vite-plugin-svelte", identifier: "svelte" }
|
|
59
|
-
]
|
|
60
|
-
},
|
|
61
|
-
ssrEntrypoint: "inertia/app/ssr.ts"
|
|
62
|
-
},
|
|
63
|
-
solid: {
|
|
64
|
-
stubFolder: "solid",
|
|
65
|
-
appExtension: "tsx",
|
|
66
|
-
componentsExtension: "tsx",
|
|
67
|
-
dependencies: [
|
|
68
|
-
{ name: "solid-js", isDevDependency: false },
|
|
69
|
-
{ name: "inertia-adapter-solid", isDevDependency: false },
|
|
70
|
-
{ name: "vite-plugin-solid", isDevDependency: true },
|
|
71
|
-
{ name: "@solidjs/meta", isDevDependency: false }
|
|
72
|
-
],
|
|
73
|
-
viteRegister: {
|
|
74
|
-
pluginCall: "solid()",
|
|
75
|
-
ssrPluginCall: "solid({ ssr: true })",
|
|
76
|
-
importDeclarations: [{ isNamed: false, module: "vite-plugin-solid", identifier: "solid" }]
|
|
77
|
-
},
|
|
78
|
-
ssrEntrypoint: "inertia/app/ssr.tsx"
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
async function defineExampleRoute(command, codemods) {
|
|
82
|
-
const tsMorph = await codemods.getTsMorphProject();
|
|
83
|
-
const routesFile = tsMorph?.getSourceFile(command.app.makePath("./start/routes.ts"));
|
|
84
|
-
if (!routesFile) {
|
|
85
|
-
return command.logger.warning("Unable to find the routes file");
|
|
86
|
-
}
|
|
87
|
-
const action = command.logger.action("update start/routes.ts file");
|
|
88
|
-
try {
|
|
89
|
-
routesFile?.addStatements((writer) => {
|
|
90
|
-
writer.writeLine(`router.on('/').renderInertia('home')`);
|
|
91
|
-
});
|
|
92
|
-
await tsMorph?.save();
|
|
93
|
-
action.succeeded();
|
|
94
|
-
} catch (error) {
|
|
95
|
-
codemods.emit("error", error);
|
|
96
|
-
action.failed(error.message);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async function configure(command) {
|
|
100
|
-
let adapter = command.parsedFlags.adapter;
|
|
101
|
-
let ssr = command.parsedFlags.ssr;
|
|
102
|
-
let shouldInstallPackages = command.parsedFlags.install;
|
|
103
|
-
let shouldSkipExampleRoute = command.parsedFlags["skip-example-route"];
|
|
104
|
-
if (adapter === void 0) {
|
|
105
|
-
adapter = await command.prompt.choice(
|
|
106
|
-
"Select the Inertia adapter you want to use",
|
|
107
|
-
ADAPTERS.map((adapterName) => string.capitalCase(adapterName)),
|
|
108
|
-
{ name: "adapter", result: (value) => value.toLowerCase() }
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
if (ssr === void 0) {
|
|
112
|
-
ssr = await command.prompt.confirm("Do you want to use server-side rendering?", {
|
|
113
|
-
name: "ssr"
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
if (adapter in ADAPTERS_INFO === false) {
|
|
117
|
-
command.logger.error(
|
|
118
|
-
`The selected adapter "${adapter}" is invalid. Select one from: ${string.sentence(
|
|
119
|
-
Object.keys(ADAPTERS_INFO)
|
|
120
|
-
)}`
|
|
121
|
-
);
|
|
122
|
-
command.exitCode = 1;
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const adapterInfo = ADAPTERS_INFO[adapter];
|
|
126
|
-
const codemods = await command.createCodemods();
|
|
127
|
-
await codemods.updateRcFile((rcFile) => {
|
|
128
|
-
rcFile.addProvider("@adonisjs/inertia/inertia_provider");
|
|
129
|
-
});
|
|
130
|
-
await codemods.registerMiddleware("server", [
|
|
131
|
-
{ path: "@adonisjs/inertia/inertia_middleware", position: "after" }
|
|
132
|
-
]);
|
|
133
|
-
const appExt = adapterInfo.appExtension;
|
|
134
|
-
const stubFolder = adapterInfo.stubFolder;
|
|
135
|
-
const compExt = adapterInfo.componentsExtension;
|
|
136
|
-
await codemods.makeUsingStub(stubsRoot, "config.stub", {
|
|
137
|
-
ssr,
|
|
138
|
-
ssrEntrypoint: adapterInfo.ssrEntrypoint
|
|
139
|
-
});
|
|
140
|
-
await codemods.makeUsingStub(stubsRoot, `app.css.stub`, {});
|
|
141
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/root.edge.stub`, {});
|
|
142
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/tsconfig.json.stub`, {});
|
|
143
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/app.${appExt}.stub`, { ssr });
|
|
144
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/home.${compExt}.stub`, {});
|
|
145
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/errors/not_found.${compExt}.stub`, {});
|
|
146
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/errors/server_error.${compExt}.stub`, {});
|
|
147
|
-
if (ssr) {
|
|
148
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/ssr.${appExt}.stub`, {});
|
|
149
|
-
}
|
|
150
|
-
const inertiaPluginCall = ssr ? `inertia({ ssr: { enabled: true, entrypoint: 'inertia/app/ssr.${appExt}' } })` : `inertia({ ssr: { enabled: false } })`;
|
|
151
|
-
await codemods.registerVitePlugin(inertiaPluginCall, [
|
|
152
|
-
{ isNamed: false, module: "@adonisjs/inertia/client", identifier: "inertia" }
|
|
153
|
-
]);
|
|
154
|
-
await codemods.registerVitePlugin(
|
|
155
|
-
ssr && adapterInfo.viteRegister.ssrPluginCall ? adapterInfo.viteRegister.ssrPluginCall : adapterInfo.viteRegister.pluginCall,
|
|
156
|
-
adapterInfo.viteRegister.importDeclarations
|
|
157
|
-
);
|
|
158
|
-
const adonisjsPluginCall = `adonisjs({ entrypoints: ['inertia/app/app.${appExt}'], reload: ['resources/views/**/*.edge'] })`;
|
|
159
|
-
await codemods.registerVitePlugin(adonisjsPluginCall, [
|
|
160
|
-
{ isNamed: false, module: "@adonisjs/vite/client", identifier: "adonisjs" }
|
|
161
|
-
]);
|
|
162
|
-
if (shouldSkipExampleRoute !== true) {
|
|
163
|
-
await defineExampleRoute(command, codemods);
|
|
164
|
-
}
|
|
165
|
-
const pkgToInstall = adapterInfo.dependencies;
|
|
166
|
-
if (ssr && adapterInfo.ssrDependencies) {
|
|
167
|
-
pkgToInstall.push(...adapterInfo.ssrDependencies);
|
|
168
|
-
}
|
|
169
|
-
if (shouldInstallPackages === void 0) {
|
|
170
|
-
shouldInstallPackages = await command.prompt.confirm(
|
|
171
|
-
`Do you want to install dependencies ${pkgToInstall.map((pkg) => pkg.name).join(", ")}?`,
|
|
172
|
-
{ name: "install" }
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
if (shouldInstallPackages) {
|
|
176
|
-
await codemods.installPackages(pkgToInstall);
|
|
177
|
-
} else {
|
|
178
|
-
await codemods.listPackagesToInstall(pkgToInstall);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// src/define_config.ts
|
|
183
|
-
import { slash } from "@poppinss/utils";
|
|
184
|
-
import { configProvider } from "@adonisjs/core";
|
|
185
|
-
|
|
186
|
-
// src/version_cache.ts
|
|
187
|
-
import { createHash } from "node:crypto";
|
|
188
|
-
import { readFile } from "node:fs/promises";
|
|
189
|
-
var VersionCache = class {
|
|
190
|
-
constructor(appRoot, assetsVersion) {
|
|
191
|
-
this.appRoot = appRoot;
|
|
192
|
-
this.assetsVersion = assetsVersion;
|
|
193
|
-
this.#cachedVersion = assetsVersion;
|
|
194
|
-
}
|
|
195
|
-
#cachedVersion;
|
|
196
|
-
/**
|
|
197
|
-
* Compute the hash of the manifest file and cache it
|
|
198
|
-
*/
|
|
199
|
-
async #getManifestHash() {
|
|
200
|
-
try {
|
|
201
|
-
const manifestPath = new URL("public/assets/.vite/manifest.json", this.appRoot);
|
|
202
|
-
const manifestFile = await readFile(manifestPath, "utf-8");
|
|
203
|
-
this.#cachedVersion = createHash("md5").update(manifestFile).digest("hex");
|
|
204
|
-
return this.#cachedVersion;
|
|
205
|
-
} catch {
|
|
206
|
-
this.#cachedVersion = "1";
|
|
207
|
-
return this.#cachedVersion;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Pre-compute the version
|
|
212
|
-
*/
|
|
213
|
-
async computeVersion() {
|
|
214
|
-
if (!this.assetsVersion) await this.#getManifestHash();
|
|
215
|
-
return this;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Returns the current assets version
|
|
219
|
-
*/
|
|
220
|
-
getVersion() {
|
|
221
|
-
if (!this.#cachedVersion) throw new Error("Version has not been computed yet");
|
|
222
|
-
return this.#cachedVersion;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Set the assets version
|
|
226
|
-
*/
|
|
227
|
-
async setVersion(version) {
|
|
228
|
-
this.#cachedVersion = version;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
// src/files_detector.ts
|
|
233
|
-
import { locatePath } from "locate-path";
|
|
234
|
-
var FilesDetector = class {
|
|
235
|
-
constructor(app) {
|
|
236
|
-
this.app = app;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Try to locate the entrypoint file based
|
|
240
|
-
* on the conventional locations
|
|
241
|
-
*/
|
|
242
|
-
async detectEntrypoint(defaultPath) {
|
|
243
|
-
const possiblesLocations = [
|
|
244
|
-
"./inertia/app/app.ts",
|
|
245
|
-
"./inertia/app/app.tsx",
|
|
246
|
-
"./resources/app.ts",
|
|
247
|
-
"./resources/app.tsx",
|
|
248
|
-
"./resources/app.jsx",
|
|
249
|
-
"./resources/app.js",
|
|
250
|
-
"./inertia/app/app.jsx"
|
|
251
|
-
];
|
|
252
|
-
const path = await locatePath(possiblesLocations, { cwd: this.app.appRoot });
|
|
253
|
-
return this.app.makePath(path || defaultPath);
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Try to locate the SSR entrypoint file based
|
|
257
|
-
* on the conventional locations
|
|
258
|
-
*/
|
|
259
|
-
async detectSsrEntrypoint(defaultPath) {
|
|
260
|
-
const possiblesLocations = [
|
|
261
|
-
"./inertia/app/ssr.ts",
|
|
262
|
-
"./inertia/app/ssr.tsx",
|
|
263
|
-
"./resources/ssr.ts",
|
|
264
|
-
"./resources/ssr.tsx",
|
|
265
|
-
"./resources/ssr.jsx",
|
|
266
|
-
"./resources/ssr.js",
|
|
267
|
-
"./inertia/app/ssr.jsx"
|
|
268
|
-
];
|
|
269
|
-
const path = await locatePath(possiblesLocations, { cwd: this.app.appRoot });
|
|
270
|
-
return this.app.makePath(path || defaultPath);
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Try to locate the SSR bundle file based
|
|
274
|
-
* on the conventional locations
|
|
275
|
-
*/
|
|
276
|
-
async detectSsrBundle(defaultPath) {
|
|
277
|
-
const possiblesLocations = ["./ssr/ssr.js", "./ssr/ssr.mjs"];
|
|
278
|
-
const path = await locatePath(possiblesLocations, { cwd: this.app.appRoot });
|
|
279
|
-
return this.app.makePath(path || defaultPath);
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
// src/define_config.ts
|
|
284
|
-
function defineConfig(config) {
|
|
285
|
-
return configProvider.create(async (app) => {
|
|
286
|
-
const detector = new FilesDetector(app);
|
|
287
|
-
const versionCache = new VersionCache(app.appRoot, config.assetsVersion);
|
|
288
|
-
await versionCache.computeVersion();
|
|
289
|
-
return {
|
|
290
|
-
versionCache,
|
|
291
|
-
rootView: config.rootView ?? "inertia_layout",
|
|
292
|
-
sharedData: config.sharedData || {},
|
|
293
|
-
history: { encrypt: config.history?.encrypt ?? false },
|
|
294
|
-
entrypoint: slash(
|
|
295
|
-
config.entrypoint ?? await detector.detectEntrypoint("inertia/app/app.ts")
|
|
296
|
-
),
|
|
297
|
-
ssr: {
|
|
298
|
-
enabled: config.ssr?.enabled ?? false,
|
|
299
|
-
pages: config.ssr?.pages,
|
|
300
|
-
entrypoint: config.ssr?.entrypoint ?? await detector.detectSsrEntrypoint("inertia/app/ssr.ts"),
|
|
301
|
-
bundle: config.ssr?.bundle ?? await detector.detectSsrBundle("ssr/ssr.js")
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
});
|
|
305
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
defineConfig,
|
|
3
|
+
indexPages
|
|
4
|
+
} from "./chunk-PDP56GPP.js";
|
|
5
|
+
import {
|
|
6
|
+
Inertia,
|
|
7
|
+
InertiaManager,
|
|
8
|
+
ServerRenderer,
|
|
9
|
+
symbols_exports
|
|
10
|
+
} from "./chunk-74S2VAL7.js";
|
|
11
|
+
import {
|
|
12
|
+
InertiaHeaders
|
|
13
|
+
} from "./chunk-DISC5OYC.js";
|
|
14
|
+
import "./chunk-4EZ2J6OA.js";
|
|
15
|
+
import "./chunk-MLKGABMK.js";
|
|
306
16
|
export {
|
|
307
|
-
|
|
17
|
+
Inertia,
|
|
18
|
+
InertiaHeaders,
|
|
19
|
+
InertiaManager,
|
|
20
|
+
ServerRenderer,
|
|
308
21
|
defineConfig,
|
|
309
|
-
|
|
22
|
+
indexPages,
|
|
23
|
+
symbols_exports as symbols
|
|
310
24
|
};
|
|
@@ -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, InertiaPages } 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: AsPageProps<InertiaPages[Page]>, 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-74S2VAL7.js";
|
|
4
|
+
import "../chunk-DISC5OYC.js";
|
|
5
|
+
import "../chunk-4EZ2J6OA.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,63 @@
|
|
|
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
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Inertia plugin for Vite that is tailored for AdonisJS
|
|
28
|
+
*
|
|
29
|
+
* Configures Vite for Inertia.js development with proper build settings,
|
|
30
|
+
* SSR support, and AdonisJS-specific optimizations.
|
|
31
|
+
*
|
|
32
|
+
* @param options - Configuration options for the plugin
|
|
33
|
+
* @returns Vite plugin configuration object
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```js
|
|
37
|
+
* // Basic configuration
|
|
38
|
+
* import inertia from '@adonisjs/inertia/plugins/vite'
|
|
39
|
+
*
|
|
40
|
+
* export default defineConfig({
|
|
41
|
+
* plugins: [inertia()]
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```js
|
|
47
|
+
* // With SSR enabled
|
|
48
|
+
* import inertia from '@adonisjs/inertia/plugins/vite'
|
|
49
|
+
*
|
|
50
|
+
* export default defineConfig({
|
|
51
|
+
* plugins: [
|
|
52
|
+
* inertia({
|
|
53
|
+
* ssr: {
|
|
54
|
+
* enabled: true,
|
|
55
|
+
* entrypoint: 'inertia/app/ssr.ts',
|
|
56
|
+
* output: 'build/ssr'
|
|
57
|
+
* }
|
|
58
|
+
* })
|
|
59
|
+
* ]
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export default function inertia(options?: InertiaPluginOptions): PluginOption;
|
|
@@ -1,23 +1,19 @@
|
|
|
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 (!options?.ssr?.enabled) return {};
|
|
7
8
|
if (command === "build") {
|
|
8
9
|
process.env.NODE_ENV = "production";
|
|
9
10
|
}
|
|
10
11
|
return {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: "build-ssr",
|
|
19
|
-
description: "build inertia server bundle",
|
|
20
|
-
config: {
|
|
12
|
+
builder: {},
|
|
13
|
+
build: { outDir: "build/public/assets" },
|
|
14
|
+
environments: {
|
|
15
|
+
...options?.ssr?.enabled && {
|
|
16
|
+
ssr: {
|
|
21
17
|
build: {
|
|
22
18
|
ssr: true,
|
|
23
19
|
outDir: options.ssr.output || "build/ssr",
|
|
@@ -25,7 +21,7 @@ function inertia(options) {
|
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
|
-
|
|
24
|
+
}
|
|
29
25
|
};
|
|
30
26
|
}
|
|
31
27
|
};
|
|
@@ -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;
|