@adonisjs/inertia 4.0.0-next.1 → 4.0.0-next.11

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.
Files changed (36) hide show
  1. package/build/debug-CBMTuPUm.js +3 -0
  2. package/build/factories/main.js +59 -172
  3. package/build/headers-DafWEpBh.js +11 -0
  4. package/build/index.js +5 -24
  5. package/build/inertia-D5A2KtfR.js +57 -0
  6. package/build/inertia_manager-Di3J3hSG.js +403 -0
  7. package/build/providers/inertia_provider.d.ts +2 -2
  8. package/build/providers/inertia_provider.js +25 -79
  9. package/build/src/client/helpers.d.ts +27 -0
  10. package/build/src/client/helpers.js +13 -0
  11. package/build/src/client/react/context.d.ts +24 -0
  12. package/build/src/client/react/index.d.ts +3 -0
  13. package/build/src/client/react/index.js +29 -0
  14. package/build/src/client/react/link.d.ts +64 -0
  15. package/build/src/client/react/router.d.ts +33 -0
  16. package/build/src/client/vite.d.ts +3 -1
  17. package/build/src/client/vite.js +16 -29
  18. package/build/src/define_config.d.ts +1 -0
  19. package/build/src/index_pages.d.ts +27 -0
  20. package/build/src/inertia.d.ts +15 -7
  21. package/build/src/inertia_manager.d.ts +1 -0
  22. package/build/src/inertia_middleware.d.ts +6 -3
  23. package/build/src/inertia_middleware.js +45 -111
  24. package/build/src/plugins/edge/plugin.js +49 -81
  25. package/build/src/plugins/japa/api_client.js +44 -59
  26. package/build/src/props.d.ts +16 -9
  27. package/build/src/server_renderer.d.ts +2 -2
  28. package/build/src/types.d.ts +17 -28
  29. package/build/src/types.js +1 -0
  30. package/build/tests/types/react.spec.d.ts +65 -0
  31. package/package.json +47 -25
  32. package/build/chunk-4EZ2J6OA.js +0 -7
  33. package/build/chunk-74S2VAL7.js +0 -761
  34. package/build/chunk-DISC5OYC.js +0 -46
  35. package/build/chunk-MLKGABMK.js +0 -9
  36. package/build/chunk-PDP56GPP.js +0 -75
@@ -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
+ };
@@ -21,6 +21,8 @@ export type InertiaPluginOptions = {
21
21
  output?: string;
22
22
  } | {
23
23
  enabled: false;
24
+ entrypoint?: string;
25
+ output?: string;
24
26
  };
25
27
  };
26
28
  /**
@@ -52,7 +54,7 @@ export type InertiaPluginOptions = {
52
54
  * inertia({
53
55
  * ssr: {
54
56
  * enabled: true,
55
- * entrypoint: 'inertia/app/ssr.ts',
57
+ * entrypoint: 'inertia/ssr.tsx',
56
58
  * output: 'build/ssr'
57
59
  * }
58
60
  * })
@@ -1,31 +1,18 @@
1
- import "../../chunk-MLKGABMK.js";
2
-
3
- // src/client/vite.ts
4
1
  function inertia(options) {
5
- return {
6
- name: "vite-plugin-inertia",
7
- config: (_, { command }) => {
8
- if (command === "build") {
9
- process.env.NODE_ENV = "production";
10
- }
11
- return {
12
- builder: {},
13
- build: { outDir: "build/public/assets" },
14
- environments: {
15
- ...options?.ssr?.enabled && {
16
- ssr: {
17
- build: {
18
- ssr: true,
19
- outDir: options.ssr.output || "build/ssr",
20
- rollupOptions: { input: options.ssr.entrypoint }
21
- }
22
- }
23
- }
24
- }
25
- };
26
- }
27
- };
2
+ return {
3
+ name: "vite-plugin-inertia",
4
+ config: (_, { command }) => {
5
+ if (command === "build") process.env.NODE_ENV = "production";
6
+ return {
7
+ builder: {},
8
+ build: { outDir: "build/public/assets" },
9
+ environments: { ...options?.ssr?.enabled && { ssr: { build: {
10
+ ssr: true,
11
+ outDir: options.ssr.output || "build/ssr",
12
+ rollupOptions: { input: options.ssr.entrypoint }
13
+ } } } }
14
+ };
15
+ }
16
+ };
28
17
  }
29
- export {
30
- inertia as default
31
- };
18
+ export { inertia as default };
@@ -6,6 +6,7 @@ import type { InertiaConfig, InertiaConfigInput } from './types.js';
6
6
  * to create a complete Inertia configuration object.
7
7
  *
8
8
  * @param config - User configuration input to override defaults
9
+ * @returns Complete Inertia configuration object with defaults applied
9
10
  *
10
11
  * @example
11
12
  * ```js
@@ -1,5 +1,32 @@
1
+ /**
2
+ * Creates an AdonisJS assembler hook to automatically generate TypeScript definitions
3
+ * for Inertia.js pages based on the specified framework.
4
+ *
5
+ * This function scans page components in the 'inertia/pages' directory and generates
6
+ * type definitions that map page names to their component props.
7
+ *
8
+ * @param config - Configuration object specifying the frontend framework
9
+ * @param config.framework - The frontend framework ('vue3' or 'react')
10
+ * @returns Assembler hook object with run method for generating page types
11
+ *
12
+ * @example
13
+ * ```js
14
+ * // In your adonisrc.ts file
15
+ * export default defineConfig({
16
+ * assembler: {
17
+ * onBuildStarting: [indexPages({ framework: 'vue3' })]
18
+ * }
19
+ * })
20
+ * ```
21
+ */
1
22
  export declare const indexPages: (config: {
2
23
  framework: "vue3" | "react";
3
24
  }) => {
25
+ /**
26
+ * Executes the page indexing process to generate TypeScript definitions.
27
+ *
28
+ * @param _ - Unused first parameter (assembler context)
29
+ * @param indexGenerator - The index generator instance used to register the pages type generation
30
+ */
4
31
  run(_: import("@adonisjs/assembler").DevServer | import("@adonisjs/assembler").TestRunner | import("@adonisjs/assembler").Bundler, indexGenerator: import("@adonisjs/assembler/index_generator").IndexGenerator): void;
5
32
  };
@@ -1,8 +1,9 @@
1
1
  import { type Vite } from '@adonisjs/vite';
2
2
  import type { HttpContext } from '@adonisjs/core/http';
3
3
  import { type ServerRenderer } from './server_renderer.js';
4
- import type { PageProps, PageObject, AsPageProps, RequestInfo, InertiaConfig, ComponentProps } from './types.js';
4
+ import type { PageProps, PageObject, AsPageProps, RequestInfo, InertiaConfig, ComponentProps, SharedProps } from './types.js';
5
5
  import { defer, merge, always, optional, deepMerge } from './props.ts';
6
+ import { type AsyncOrSync } from '@poppinss/utils/types';
6
7
  /**
7
8
  * Main class used to interact with Inertia
8
9
  *
@@ -23,7 +24,7 @@ import { defer, merge, always, optional, deepMerge } from './props.ts';
23
24
  * inertia.location('/dashboard')
24
25
  * ```
25
26
  */
26
- export declare class Inertia<Pages extends Record<string, ComponentProps>> {
27
+ export declare class Inertia<Pages> {
27
28
  #private;
28
29
  protected ctx: HttpContext;
29
30
  protected config: InertiaConfig;
@@ -104,6 +105,9 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
104
105
  *
105
106
  * Parses various Inertia headers to determine request type and props filtering.
106
107
  *
108
+ * @param reCompute - Whether to recompute the request info instead of using cached version
109
+ * @returns The request information object containing Inertia-specific data
110
+ *
107
111
  * @example
108
112
  * ```js
109
113
  * const info = inertia.requestInfo()
@@ -117,6 +121,8 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
117
121
  * Compute and cache the assets version
118
122
  *
119
123
  * Uses Vite manifest hash when available, otherwise defaults to '1'.
124
+ *
125
+ * @returns The computed version string for asset versioning
120
126
  */
121
127
  getVersion(): string;
122
128
  /**
@@ -125,6 +131,7 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
125
131
  * Checks global SSR settings and component-specific configuration.
126
132
  *
127
133
  * @param component - The component name to check
134
+ * @returns Promise resolving to true if SSR is enabled for the component
128
135
  *
129
136
  * @example
130
137
  * ```js
@@ -143,6 +150,7 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
143
150
  * in every page render alongside page-specific props.
144
151
  *
145
152
  * @param sharedState - Props to share across all pages
153
+ * @returns The Inertia instance for method chaining
146
154
  *
147
155
  * @example
148
156
  * ```js
@@ -158,7 +166,7 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
158
166
  * .share({ permissions: userPermissions })
159
167
  * ```
160
168
  */
161
- share(sharedState: PageProps): this;
169
+ share(sharedState: PageProps | (() => AsyncOrSync<PageProps>)): this;
162
170
  /**
163
171
  * Build a page object with processed props and metadata
164
172
  *
@@ -166,6 +174,7 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
166
174
  *
167
175
  * @param page - The page component name
168
176
  * @param pageProps - Props to pass to the page component
177
+ * @returns Promise resolving to the complete page object
169
178
  *
170
179
  * @example
171
180
  * ```js
@@ -175,7 +184,7 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
175
184
  * })
176
185
  * ```
177
186
  */
178
- page<Page extends keyof Pages & string>(page: Page, pageProps: AsPageProps<Pages[Page]>): Promise<PageObject<Pages[Page]>>;
187
+ page<Page extends keyof Pages & string>(page: Page, pageProps: Pages[Page] extends ComponentProps ? AsPageProps<Omit<Pages[Page], keyof SharedProps>> : never): Promise<PageObject<Pages[Page]>>;
179
188
  /**
180
189
  * Render a page using Inertia
181
190
  *
@@ -187,8 +196,7 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
187
196
  * @param page - The page component name to render
188
197
  * @param pageProps - Props to pass to the page component
189
198
  * @param viewProps - Additional props to pass to the root view template
190
- *
191
- * @returns PageObject for Inertia requests, HTML string for initial page loads
199
+ * @returns Promise resolving to PageObject for Inertia requests, HTML string for initial page loads
192
200
  *
193
201
  * @example
194
202
  * ```js
@@ -202,7 +210,7 @@ export declare class Inertia<Pages extends Record<string, ComponentProps>> {
202
210
  * const html = await inertia.render('Home', { welcome: 'Hello World' })
203
211
  * ```
204
212
  */
205
- render<Page extends keyof Pages & string>(page: Page, pageProps: AsPageProps<Pages[Page]>, viewProps?: Record<string, any>): Promise<string | PageObject<Pages[Page]>>;
213
+ render<Page extends keyof Pages & string>(page: Page, pageProps: Pages[Page] extends ComponentProps ? AsPageProps<Omit<Pages[Page], keyof SharedProps>> : never, viewProps?: Record<string, any>): Promise<string | PageObject<Pages[Page]>>;
206
214
  /**
207
215
  * Clear the browser history on the next navigation
208
216
  *
@@ -35,6 +35,7 @@ export declare class InertiaManager {
35
35
  * Creates a new Inertia instance for a specific HTTP request
36
36
  *
37
37
  * @param ctx - HTTP context for the current request
38
+ * @returns A new Inertia instance configured for the given request
38
39
  *
39
40
  * @example
40
41
  * ```js
@@ -1,9 +1,9 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import { type Inertia } from './inertia.js';
3
- import type { ComponentProps, InertiaPages, PageProps } from './types.js';
3
+ import type { InertiaPages, PageProps } from './types.js';
4
4
  declare module '@adonisjs/core/http' {
5
5
  interface HttpContext {
6
- inertia: Inertia<InertiaPages extends Record<string, ComponentProps> ? InertiaPages : never>;
6
+ inertia: Inertia<InertiaPages>;
7
7
  }
8
8
  }
9
9
  /**
@@ -51,8 +51,11 @@ export default abstract class BaseInertiaMiddleware {
51
51
  * This method should return an object containing data that will be
52
52
  * available to all Inertia pages as props.
53
53
  *
54
+ * @param ctx - The HTTP context object
55
+ * @returns Props to share across all pages
56
+ *
54
57
  * @example
55
- * ```ts
58
+ * ```js
56
59
  * async share() {
57
60
  * return {
58
61
  * user: ctx.auth?.user,
@@ -1,113 +1,47 @@
1
- import {
2
- InertiaManager
3
- } from "../chunk-74S2VAL7.js";
4
- import {
5
- InertiaHeaders
6
- } from "../chunk-DISC5OYC.js";
7
- import {
8
- debug_default
9
- } from "../chunk-4EZ2J6OA.js";
10
- import "../chunk-MLKGABMK.js";
11
-
12
- // src/inertia_middleware.ts
13
- var MUTATION_METHODS = ["PUT", "PATCH", "DELETE"];
1
+ import { t as InertiaManager } from "../inertia_manager-Di3J3hSG.js";
2
+ import { t as InertiaHeaders } from "../headers-DafWEpBh.js";
3
+ import { t as debug_default } from "../debug-CBMTuPUm.js";
4
+ const MUTATION_METHODS = [
5
+ "PUT",
6
+ "PATCH",
7
+ "DELETE"
8
+ ];
14
9
  var BaseInertiaMiddleware = class {
15
- /**
16
- * Extract validation errors from the session and format them for Inertia
17
- *
18
- * Retrieves validation errors from the session flash messages and formats
19
- * them according to Inertia's error bag conventions. Supports both simple
20
- * error objects and error bags for multi-form scenarios.
21
- *
22
- * @param ctx - The HTTP context containing session data
23
- * @returns Formatted validation errors, either as a simple object or error bags
24
- *
25
- * @example
26
- * ```js
27
- * const errors = middleware.getValidationErrors(ctx)
28
- * // Returns: { email: 'Email is required', password: 'Password too short' }
29
- * // Or with error bags: { login: { email: 'Email is required' } }
30
- * ```
31
- */
32
- getValidationErrors(ctx) {
33
- if (!ctx.session) {
34
- return {};
35
- }
36
- const inputErrors = ctx.session.flashMessages.get("inputErrorsBag");
37
- const errors = Object.entries(inputErrors).reduce(
38
- (result, [field, messages]) => {
39
- result[field] = Array.isArray(messages) ? messages[0] : messages;
40
- return result;
41
- },
42
- {}
43
- );
44
- const errorBag = ctx.request.header(InertiaHeaders.ErrorBag);
45
- if (errorBag) {
46
- return { [errorBag]: errors };
47
- }
48
- return errors;
49
- }
50
- /**
51
- * Initialize the Inertia instance for the current request
52
- *
53
- * This method creates an Inertia instance and attaches it to the
54
- * HTTP context, making it available throughout the request lifecycle.
55
- *
56
- * @param ctx - The HTTP context object
57
- *
58
- * @example
59
- * ```ts
60
- * await middleware.init(ctx)
61
- * ```
62
- */
63
- async init(ctx) {
64
- debug_default("initiating inertia");
65
- const inertiaContainer = await ctx.containerResolver.make(InertiaManager);
66
- ctx.inertia = inertiaContainer.createForRequest(ctx);
67
- if (this.share) {
68
- ctx.inertia.share(await this.share(ctx));
69
- }
70
- }
71
- /**
72
- * Clean up and finalize the Inertia response
73
- *
74
- * This method handles the final processing of Inertia requests including:
75
- * - Setting appropriate response headers
76
- * - Handling redirects for mutation methods (PUT/PATCH/DELETE)
77
- * - Managing asset versioning conflicts
78
- *
79
- * @param ctx - The HTTP context object
80
- *
81
- * @example
82
- * ```ts
83
- * await middleware.dispose(ctx)
84
- * ```
85
- */
86
- dispose(ctx) {
87
- const requestInfo = ctx.inertia.requestInfo();
88
- if (!requestInfo.isInertiaRequest) {
89
- return;
90
- }
91
- debug_default("disposing as inertia request");
92
- ctx.response.header("Vary", InertiaHeaders.Inertia);
93
- const method = ctx.request.method();
94
- if (ctx.response.getStatus() === 302 && MUTATION_METHODS.includes(method)) {
95
- debug_default("upgrading response status from 302 to 303");
96
- ctx.response.status(303);
97
- }
98
- const version = ctx.inertia.getVersion();
99
- const clientVersion = requestInfo.version ?? "";
100
- if (method === "GET" && clientVersion !== version) {
101
- debug_default("version mis-match. Reloading page");
102
- if (ctx.session) {
103
- ctx.session.reflash();
104
- }
105
- ctx.response.removeHeader(InertiaHeaders.Inertia);
106
- ctx.response.header(InertiaHeaders.Location, ctx.request.url(true));
107
- ctx.response.status(409);
108
- }
109
- }
110
- };
111
- export {
112
- BaseInertiaMiddleware as default
10
+ getValidationErrors(ctx) {
11
+ if (!ctx.session) return {};
12
+ const inputErrors = ctx.session.flashMessages.get("inputErrorsBag", {});
13
+ const errors = Object.entries(inputErrors).reduce((result, [field, messages]) => {
14
+ result[field] = Array.isArray(messages) ? messages[0] : messages;
15
+ return result;
16
+ }, {});
17
+ const errorBag = ctx.request.header(InertiaHeaders.ErrorBag);
18
+ if (errorBag) return { [errorBag]: errors };
19
+ return errors;
20
+ }
21
+ async init(ctx) {
22
+ debug_default("initiating inertia");
23
+ ctx.inertia = (await ctx.containerResolver.make(InertiaManager)).createForRequest(ctx);
24
+ if (this.share) ctx.inertia.share(() => this.share(ctx));
25
+ }
26
+ dispose(ctx) {
27
+ const requestInfo = ctx.inertia.requestInfo();
28
+ if (!requestInfo.isInertiaRequest) return;
29
+ debug_default("disposing as inertia request");
30
+ ctx.response.header("Vary", InertiaHeaders.Inertia);
31
+ const method = ctx.request.method();
32
+ if (ctx.response.getStatus() === 302 && MUTATION_METHODS.includes(method)) {
33
+ debug_default("upgrading response status from 302 to 303");
34
+ ctx.response.status(303);
35
+ }
36
+ const version = ctx.inertia.getVersion();
37
+ const clientVersion = requestInfo.version ?? "";
38
+ if (method === "GET" && clientVersion !== version) {
39
+ debug_default("version mis-match. Reloading page");
40
+ if (ctx.session) ctx.session.reflash();
41
+ ctx.response.removeHeader(InertiaHeaders.Inertia);
42
+ ctx.response.header(InertiaHeaders.Location, ctx.request.url(true));
43
+ ctx.response.status(409);
44
+ }
45
+ }
113
46
  };
47
+ export { BaseInertiaMiddleware as default };
@@ -1,88 +1,56 @@
1
- import {
2
- debug_default
3
- } from "../../../chunk-4EZ2J6OA.js";
4
- import "../../../chunk-MLKGABMK.js";
5
-
6
- // src/plugins/edge/plugin.ts
1
+ import { t as debug_default } from "../../../debug-CBMTuPUm.js";
7
2
  import { encode } from "html-entities";
8
-
9
- // src/plugins/edge/tags.ts
10
3
  import { EdgeError } from "edge-error";
11
-
12
- // src/plugins/edge/utils.ts
13
4
  function isSubsetOf(expression, expressions, errorCallback) {
14
- if (!expressions.includes(expression.type)) {
15
- errorCallback();
16
- }
5
+ if (!expressions.includes(expression.type)) errorCallback();
17
6
  }
18
-
19
- // src/plugins/edge/tags.ts
20
- var inertiaTag = {
21
- block: false,
22
- tagName: "inertia",
23
- seekable: true,
24
- compile(parser, buffer, { filename, loc, properties }) {
25
- if (properties.jsArg.trim() === "") {
26
- buffer.writeExpression(`out += state.inertia(state.page)`, filename, loc.start.line);
27
- return;
28
- }
29
- properties.jsArg = `(${properties.jsArg})`;
30
- const parsed = parser.utils.transformAst(
31
- parser.utils.generateAST(properties.jsArg, loc, filename),
32
- filename,
33
- parser
34
- );
35
- isSubsetOf(parsed, ["ObjectExpression"], () => {
36
- const { line, col } = parser.utils.getExpressionLoc(parsed);
37
- throw new EdgeError(
38
- `"${properties.jsArg}" is not a valid argument for @inertia`,
39
- "E_UNALLOWED_EXPRESSION",
40
- { line, col, filename }
41
- );
42
- });
43
- const attributes = parser.utils.stringify(parsed);
44
- buffer.outputExpression(
45
- `state.inertia(state.page, ${attributes})`,
46
- filename,
47
- loc.start.line,
48
- false
49
- );
50
- }
7
+ const inertiaTag = {
8
+ block: false,
9
+ tagName: "inertia",
10
+ seekable: true,
11
+ compile(parser, buffer, { filename, loc, properties }) {
12
+ if (properties.jsArg.trim() === "") {
13
+ buffer.writeExpression(`out += state.inertia(state.page)`, filename, loc.start.line);
14
+ return;
15
+ }
16
+ properties.jsArg = `(${properties.jsArg})`;
17
+ const parsed = parser.utils.transformAst(parser.utils.generateAST(properties.jsArg, loc, filename), filename, parser);
18
+ isSubsetOf(parsed, ["ObjectExpression"], () => {
19
+ const { line, col } = parser.utils.getExpressionLoc(parsed);
20
+ throw new EdgeError(`"${properties.jsArg}" is not a valid argument for @inertia`, "E_UNALLOWED_EXPRESSION", {
21
+ line,
22
+ col,
23
+ filename
24
+ });
25
+ });
26
+ const attributes = parser.utils.stringify(parsed);
27
+ buffer.outputExpression(`state.inertia(state.page, ${attributes})`, filename, loc.start.line, false);
28
+ }
51
29
  };
52
- var inertiaHeadTag = {
53
- block: false,
54
- tagName: "inertiaHead",
55
- seekable: false,
56
- compile(_, buffer, { filename, loc }) {
57
- buffer.outputExpression("state.inertiaHead(state.page)", filename, loc.start.line, false);
58
- }
30
+ const inertiaHeadTag = {
31
+ block: false,
32
+ tagName: "inertiaHead",
33
+ seekable: false,
34
+ compile(_, buffer, { filename, loc }) {
35
+ buffer.outputExpression("state.inertiaHead(state.page)", filename, loc.start.line, false);
36
+ }
59
37
  };
60
-
61
- // src/plugins/edge/plugin.ts
62
- var edgePluginInertia = () => {
63
- return (edge) => {
64
- debug_default("sharing globals and inertia tags with edge");
65
- edge.global(
66
- "inertia",
67
- (page = {}, attributes = {}) => {
68
- if (page.ssrBody) {
69
- return page.ssrBody;
70
- }
71
- const className = attributes?.class ? ` class="${attributes.class}"` : "";
72
- const id = attributes?.id ? ` id="${attributes.id}"` : ' id="app"';
73
- const tag = attributes?.as || "div";
74
- const dataPage = encode(JSON.stringify(page));
75
- return `<${tag}${id}${className} data-page="${dataPage}"></${tag}>`;
76
- }
77
- );
78
- edge.global("inertiaHead", (page) => {
79
- const { ssrHead = [] } = page || {};
80
- return ssrHead.join("\n");
81
- });
82
- edge.registerTag(inertiaHeadTag);
83
- edge.registerTag(inertiaTag);
84
- };
85
- };
86
- export {
87
- edgePluginInertia
38
+ const edgePluginInertia = () => {
39
+ return (edge) => {
40
+ debug_default("sharing globals and inertia tags with edge");
41
+ edge.global("inertia", (page = {}, attributes = {}) => {
42
+ if (page.ssrBody) return page.ssrBody;
43
+ const className = attributes?.class ? ` class="${attributes.class}"` : "";
44
+ const id = attributes?.id ? ` id="${attributes.id}"` : " id=\"app\"";
45
+ const tag = attributes?.as || "div";
46
+ return `<${tag}${id}${className} data-page="${encode(JSON.stringify(page))}"></${tag}>`;
47
+ });
48
+ edge.global("inertiaHead", (page) => {
49
+ const { ssrHead = [] } = page || {};
50
+ return ssrHead.join("\n");
51
+ });
52
+ edge.registerTag(inertiaHeadTag);
53
+ edge.registerTag(inertiaTag);
54
+ };
88
55
  };
56
+ export { edgePluginInertia };