@adonisjs/inertia 1.0.0-2 → 1.0.0-20
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/build/app.css.stub +39 -0
- package/build/chunk-PJEYAPJB.js +254 -0
- package/build/{stubs/config.stub → config.stub} +10 -2
- package/build/index.d.ts +2 -2
- package/build/index.js +214 -36
- package/build/providers/inertia_provider.d.ts +14 -1
- package/build/providers/inertia_provider.js +29 -16
- package/build/react/app.tsx.stub +35 -0
- package/build/react/errors/not_found.tsx.stub +14 -0
- package/build/react/errors/server_error.tsx.stub +14 -0
- package/build/react/home.tsx.stub +21 -0
- package/build/react/root.edge.stub +22 -0
- package/build/react/ssr.tsx.stub +17 -0
- package/build/react/tsconfig.json.stub +15 -0
- package/build/solid/app.tsx.stub +35 -0
- package/build/solid/errors/not_found.tsx.stub +14 -0
- package/build/solid/errors/server_error.tsx.stub +14 -0
- package/build/solid/home.tsx.stub +18 -0
- package/build/solid/root.edge.stub +21 -0
- package/build/solid/ssr.tsx.stub +19 -0
- package/build/solid/tsconfig.json.stub +16 -0
- package/build/src/helpers.d.ts +12 -0
- package/build/src/helpers.js +14 -0
- package/build/src/inertia_middleware.d.ts +12 -9
- package/build/src/inertia_middleware.js +1 -1
- package/build/src/plugins/edge/plugin.js +85 -0
- package/build/src/plugins/{api_client.d.ts → japa/api_client.d.ts} +1 -1
- package/build/src/plugins/{api_client.js → japa/api_client.js} +1 -1
- package/build/src/plugins/vite.d.ts +26 -0
- package/build/src/plugins/vite.js +36 -0
- package/build/src/types.d.ts +42 -2
- package/build/svelte/app.ts.stub +30 -0
- package/build/svelte/errors/not_found.svelte.stub +10 -0
- package/build/svelte/errors/server_error.svelte.stub +14 -0
- package/build/svelte/home.svelte.stub +19 -0
- package/build/svelte/root.edge.stub +21 -0
- package/build/svelte/ssr.ts.stub +15 -0
- package/build/svelte/tsconfig.json.stub +14 -0
- package/build/vue/app.ts.stub +38 -0
- package/build/vue/errors/not_found.vue.stub +10 -0
- package/build/vue/errors/server_error.vue.stub +14 -0
- package/build/vue/home.vue.stub +21 -0
- package/build/vue/root.edge.stub +21 -0
- package/build/vue/ssr.ts.stub +22 -0
- package/build/vue/tsconfig.json.stub +16 -0
- package/package.json +51 -43
- package/build/chunk-GDULL3NT.js +0 -123
- package/build/src/plugins/edge.js +0 -41
- /package/build/src/plugins/{edge.d.ts → edge/plugin.d.ts} +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InertiaMiddleware
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-PJEYAPJB.js";
|
|
4
4
|
|
|
5
5
|
// providers/inertia_provider.ts
|
|
6
6
|
import { configProvider } from "@adonisjs/core";
|
|
7
|
+
import { BriskRoute } from "@adonisjs/core/http";
|
|
7
8
|
import { RuntimeException } from "@poppinss/utils";
|
|
8
9
|
var InertiaProvider = class {
|
|
9
10
|
constructor(app) {
|
|
@@ -13,26 +14,38 @@ var InertiaProvider = class {
|
|
|
13
14
|
* Registers edge plugin when edge is installed
|
|
14
15
|
*/
|
|
15
16
|
async registerEdgePlugin() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
17
|
+
if (!this.app.usingEdgeJS)
|
|
18
|
+
return;
|
|
19
|
+
const edgeExports = await import("edge.js");
|
|
20
|
+
const { edgePluginInertia } = await import("../src/plugins/edge/plugin.js");
|
|
21
|
+
edgeExports.default.use(edgePluginInertia());
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* Register
|
|
24
|
+
* Register inertia middleware
|
|
25
25
|
*/
|
|
26
26
|
async register() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
this.app.container.singleton(InertiaMiddleware, async () => {
|
|
28
|
+
const inertiaConfigProvider = this.app.config.get("inertia");
|
|
29
|
+
const config = await configProvider.resolve(this.app, inertiaConfigProvider);
|
|
30
|
+
const vite = await this.app.container.make("vite");
|
|
31
|
+
if (!config) {
|
|
32
|
+
throw new RuntimeException(
|
|
33
|
+
'Invalid "config/inertia.ts" file. Make sure you are using the "defineConfig" method'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return new InertiaMiddleware(config, vite);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Register edge plugin and brisk route macro
|
|
41
|
+
*/
|
|
42
|
+
async boot() {
|
|
35
43
|
await this.registerEdgePlugin();
|
|
44
|
+
BriskRoute.macro("renderInertia", function(template, props, viewProps) {
|
|
45
|
+
return this.setHandler(({ inertia }) => {
|
|
46
|
+
return inertia.render(template, props, viewProps);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
36
49
|
}
|
|
37
50
|
};
|
|
38
51
|
export {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/app/app.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
import '../css/app.css';
|
|
5
|
+
|
|
6
|
+
{{#if ssr}}
|
|
7
|
+
import { hydrateRoot } from 'react-dom/client'
|
|
8
|
+
{{#else}}
|
|
9
|
+
import { createRoot } from 'react-dom/client';
|
|
10
|
+
{{/if}}
|
|
11
|
+
import { createInertiaApp } from '@inertiajs/react';
|
|
12
|
+
import { resolvePageComponent } from '@adonisjs/inertia/helpers'
|
|
13
|
+
|
|
14
|
+
const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
|
|
15
|
+
|
|
16
|
+
createInertiaApp({
|
|
17
|
+
progress: { color: '#5468FF' },
|
|
18
|
+
|
|
19
|
+
title: (title) => {{ '`${title} - ${appName}`' }},
|
|
20
|
+
|
|
21
|
+
resolve: (name) => {
|
|
22
|
+
return resolvePageComponent(
|
|
23
|
+
{{ '`../pages/${name}.tsx`' }},
|
|
24
|
+
import.meta.glob('../pages/**/*.tsx'),
|
|
25
|
+
)
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
setup({ el, App, props }) {
|
|
29
|
+
{{#if ssr}}
|
|
30
|
+
hydrateRoot(el, <App {...props} />)
|
|
31
|
+
{{#else}}
|
|
32
|
+
createRoot(el).render(<App {...props} />);
|
|
33
|
+
{{/if}}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/errors/not_found.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
export default function NotFound() {
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<div className="container">
|
|
8
|
+
<div className="title">Page not found</div>
|
|
9
|
+
|
|
10
|
+
<span>This page does not exist.</span>
|
|
11
|
+
</div>
|
|
12
|
+
</>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/errors/server_error.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
export default function ServerError(props: { error: any }) {
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<div className="container">
|
|
8
|
+
<div className="title">Server Error</div>
|
|
9
|
+
|
|
10
|
+
<span>{props.error.message}</span>
|
|
11
|
+
</div>
|
|
12
|
+
</>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/home.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
import { Head } from '@inertiajs/react'
|
|
5
|
+
|
|
6
|
+
export default function Home(props: { version: number }) {
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
<Head title="Homepage" />
|
|
10
|
+
|
|
11
|
+
<div className="container">
|
|
12
|
+
<div className="title">AdonisJS {props.version} x Inertia x React</div>
|
|
13
|
+
|
|
14
|
+
<span>
|
|
15
|
+
Learn more about AdonisJS and Inertia.js by visiting the{' '}
|
|
16
|
+
<a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
|
|
17
|
+
</span>
|
|
18
|
+
</div>
|
|
19
|
+
</>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/views/inertia_layout.edge') })
|
|
3
|
+
}}}
|
|
4
|
+
<!DOCTYPE html>
|
|
5
|
+
<html>
|
|
6
|
+
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="utf-8">
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
10
|
+
|
|
11
|
+
<title inertia>AdonisJS x Inertia x React</title>
|
|
12
|
+
|
|
13
|
+
@viteReactRefresh()
|
|
14
|
+
@inertiaHead()
|
|
15
|
+
{{ "@vite(['inertia/app/app.tsx', `inertia/pages/${page.component}.tsx`])" }}
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
@inertia()
|
|
20
|
+
</body>
|
|
21
|
+
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/app/ssr.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
import ReactDOMServer from 'react-dom/server'
|
|
5
|
+
import { createInertiaApp } from '@inertiajs/react'
|
|
6
|
+
|
|
7
|
+
export default function render(page: any) {
|
|
8
|
+
return createInertiaApp({
|
|
9
|
+
page,
|
|
10
|
+
render: ReactDOMServer.renderToString,
|
|
11
|
+
resolve: (name) => {
|
|
12
|
+
const pages = import.meta.glob('../pages/**/*.tsx', { eager: true })
|
|
13
|
+
{{ 'return pages[`../pages/${name}.tsx`]' }}
|
|
14
|
+
},
|
|
15
|
+
setup: ({ App, props }) => <App {...props} />,
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/tsconfig.json') })
|
|
3
|
+
}}}
|
|
4
|
+
{
|
|
5
|
+
"extends": "@adonisjs/tsconfig/tsconfig.client.json",
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"baseUrl": ".",
|
|
8
|
+
"module": "ESNext",
|
|
9
|
+
"jsx": "react-jsx",
|
|
10
|
+
"paths": {
|
|
11
|
+
"~/*": ["./*"],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
"include": ["./**/*.ts", "./**/*.tsx"],
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/app/app.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
import '../css/app.css'
|
|
5
|
+
|
|
6
|
+
{{#if ssr}}
|
|
7
|
+
import { hydrate } from 'solid-js/web';
|
|
8
|
+
{{#else}}
|
|
9
|
+
import { render } from 'solid-js/web'
|
|
10
|
+
{{/if}}
|
|
11
|
+
import { createInertiaApp } from 'inertia-adapter-solid'
|
|
12
|
+
import { resolvePageComponent } from '@adonisjs/inertia/helpers'
|
|
13
|
+
|
|
14
|
+
const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
|
|
15
|
+
|
|
16
|
+
createInertiaApp({
|
|
17
|
+
progress: { color: '#5468FF' },
|
|
18
|
+
|
|
19
|
+
title: (title) => {{ '`${title} - ${appName}`' }},
|
|
20
|
+
|
|
21
|
+
resolve: (name) => {
|
|
22
|
+
return resolvePageComponent(
|
|
23
|
+
{{ '`../pages/${name}.tsx`' }},
|
|
24
|
+
import.meta.glob('../pages/**/*.tsx'),
|
|
25
|
+
)
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
setup({ el, App, props }) {
|
|
29
|
+
{{#if ssr}}
|
|
30
|
+
hydrate(() => <App {...props} />, el)
|
|
31
|
+
{{#else}}
|
|
32
|
+
render(() => <App {...props} />, el)
|
|
33
|
+
{{/if}}
|
|
34
|
+
},
|
|
35
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/errors/not_found.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
export default function NotFound() {
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<div class="container">
|
|
8
|
+
<div class="title">Page not found</div>
|
|
9
|
+
|
|
10
|
+
<span>This page does not exist.</span>
|
|
11
|
+
</div>
|
|
12
|
+
</>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/errors/server_error.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
export default function ServerError(props: { error: any }) {
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<div class="container">
|
|
8
|
+
<div class="title">Server Error</div>
|
|
9
|
+
|
|
10
|
+
<span>{props.error.message}</span>
|
|
11
|
+
</div>
|
|
12
|
+
</>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/home.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
|
|
5
|
+
export default function Home(props: { version: number }) {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
<div class="container">
|
|
9
|
+
<div class="title">AdonisJS {props.version} x Inertia x Solid.js</div>
|
|
10
|
+
|
|
11
|
+
<span>
|
|
12
|
+
Learn more about AdonisJS and Inertia.js by visiting the{' '}
|
|
13
|
+
<a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
|
|
14
|
+
</span>
|
|
15
|
+
</div>
|
|
16
|
+
</>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/views/inertia_layout.edge') })
|
|
3
|
+
}}}
|
|
4
|
+
<!DOCTYPE html>
|
|
5
|
+
<html>
|
|
6
|
+
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="utf-8">
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
10
|
+
|
|
11
|
+
<title inertia>AdonisJS x Inertia x SolidJS</title>
|
|
12
|
+
|
|
13
|
+
@inertiaHead()
|
|
14
|
+
{{ "@vite(['inertia/app/app.tsx', `inertia/pages/${page.component}.tsx`])" }}
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
@inertia()
|
|
19
|
+
</body>
|
|
20
|
+
|
|
21
|
+
</html>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/app/ssr.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
|
|
5
|
+
import { hydrate } from 'solid-js/web'
|
|
6
|
+
import { createInertiaApp } from 'inertia-adapter-solid'
|
|
7
|
+
|
|
8
|
+
export default function render(page: any) {
|
|
9
|
+
return createInertiaApp({
|
|
10
|
+
page,
|
|
11
|
+
resolve: (name) => {
|
|
12
|
+
const pages = import.meta.glob('../pages/**/*.tsx', { eager: true })
|
|
13
|
+
{{ 'return pages[`../pages/${name}.tsx`]' }}
|
|
14
|
+
},
|
|
15
|
+
setup({ el, App, props }) {
|
|
16
|
+
hydrate(() => <App {...props} />, el)
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/tsconfig.json') })
|
|
3
|
+
}}}
|
|
4
|
+
{
|
|
5
|
+
"extends": "@adonisjs/tsconfig/tsconfig.client.json",
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"baseUrl": ".",
|
|
8
|
+
"jsx": "preserve",
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"jsxImportSource": "solid-js",
|
|
11
|
+
"paths": {
|
|
12
|
+
"~/*": ["./*"],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
"include": ["./**/*.ts", "./**/*.tsx"],
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility function to resolve a page component
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* return resolvePageComponent(
|
|
6
|
+
* `./pages/${name}.vue`,
|
|
7
|
+
* import.meta.glob<DefineComponent>("./pages/**\/*.vue")
|
|
8
|
+
* )
|
|
9
|
+
*/
|
|
10
|
+
declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T>;
|
|
11
|
+
|
|
12
|
+
export { resolvePageComponent };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/helpers.ts
|
|
2
|
+
async function resolvePageComponent(path, pages) {
|
|
3
|
+
for (const p of Array.isArray(path) ? path : [path]) {
|
|
4
|
+
const page = pages[p];
|
|
5
|
+
if (typeof page === "undefined") {
|
|
6
|
+
continue;
|
|
7
|
+
}
|
|
8
|
+
return typeof page === "function" ? page() : page;
|
|
9
|
+
}
|
|
10
|
+
throw new Error(`Page not found: ${path}`);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
resolvePageComponent
|
|
14
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Vite } from '@adonisjs/vite';
|
|
1
2
|
import { HttpContext } from '@adonisjs/core/http';
|
|
2
3
|
import { NextFn } from '@adonisjs/core/types/http';
|
|
3
|
-
import { ResolvedConfig, PageProps, MaybePromise } from './types.js';
|
|
4
|
+
import { ResolvedConfig, Data, PageProps, PageObject, MaybePromise } from './types.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Symbol used to identify lazy props
|
|
@@ -13,16 +14,17 @@ declare class Inertia {
|
|
|
13
14
|
#private;
|
|
14
15
|
protected ctx: HttpContext;
|
|
15
16
|
protected config: ResolvedConfig;
|
|
16
|
-
|
|
17
|
+
protected vite?: Vite | undefined;
|
|
18
|
+
constructor(ctx: HttpContext, config: ResolvedConfig, vite?: Vite | undefined);
|
|
19
|
+
/**
|
|
20
|
+
* Share data for the current request.
|
|
21
|
+
* This data will override any shared data defined in the config.
|
|
22
|
+
*/
|
|
23
|
+
share(data: Record<string, Data>): void;
|
|
17
24
|
/**
|
|
18
25
|
* Render a page using Inertia
|
|
19
26
|
*/
|
|
20
|
-
render<TPageProps extends Record<string, any> = PageProps, TViewProps extends Record<string, any> = PageProps>(component: string, pageProps?: TPageProps, viewProps?: TViewProps): Promise<string |
|
|
21
|
-
component: string;
|
|
22
|
-
version: string | number;
|
|
23
|
-
props: any;
|
|
24
|
-
url: string;
|
|
25
|
-
}>;
|
|
27
|
+
render<TPageProps extends Record<string, any> = PageProps, TViewProps extends Record<string, any> = PageProps>(component: string, pageProps?: TPageProps, viewProps?: TViewProps): Promise<string | PageObject<TPageProps>>;
|
|
26
28
|
/**
|
|
27
29
|
* Create a lazy prop
|
|
28
30
|
*
|
|
@@ -57,7 +59,8 @@ declare module '@adonisjs/core/http' {
|
|
|
57
59
|
*/
|
|
58
60
|
declare class InertiaMiddleware {
|
|
59
61
|
protected config: ResolvedConfig;
|
|
60
|
-
|
|
62
|
+
protected vite?: Vite | undefined;
|
|
63
|
+
constructor(config: ResolvedConfig, vite?: Vite | undefined);
|
|
61
64
|
handle(ctx: HttpContext, next: NextFn): Promise<void>;
|
|
62
65
|
}
|
|
63
66
|
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// src/plugins/edge/plugin.ts
|
|
2
|
+
import { encode } from "html-entities";
|
|
3
|
+
|
|
4
|
+
// src/debug.ts
|
|
5
|
+
import { debuglog } from "node:util";
|
|
6
|
+
var debug_default = debuglog("adonisjs:inertia");
|
|
7
|
+
|
|
8
|
+
// src/plugins/edge/tags.ts
|
|
9
|
+
import { EdgeError } from "edge-error";
|
|
10
|
+
|
|
11
|
+
// src/plugins/edge/utils.ts
|
|
12
|
+
function isSubsetOf(expression, expressions, errorCallback) {
|
|
13
|
+
if (!expressions.includes(expression.type)) {
|
|
14
|
+
errorCallback();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/plugins/edge/tags.ts
|
|
19
|
+
var inertiaTag = {
|
|
20
|
+
block: false,
|
|
21
|
+
tagName: "inertia",
|
|
22
|
+
seekable: true,
|
|
23
|
+
compile(parser, buffer, { filename, loc, properties }) {
|
|
24
|
+
if (properties.jsArg.trim() === "") {
|
|
25
|
+
buffer.writeExpression(`out += state.inertia(state.page)`, filename, loc.start.line);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
properties.jsArg = `(${properties.jsArg})`;
|
|
29
|
+
const parsed = parser.utils.transformAst(
|
|
30
|
+
parser.utils.generateAST(properties.jsArg, loc, filename),
|
|
31
|
+
filename,
|
|
32
|
+
parser
|
|
33
|
+
);
|
|
34
|
+
isSubsetOf(parsed, ["ObjectExpression"], () => {
|
|
35
|
+
const { line, col } = parser.utils.getExpressionLoc(parsed);
|
|
36
|
+
throw new EdgeError(
|
|
37
|
+
`"${properties.jsArg}" is not a valid argument for @inertia`,
|
|
38
|
+
"E_UNALLOWED_EXPRESSION",
|
|
39
|
+
{ line, col, filename }
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
const attributes = parser.utils.stringify(parsed);
|
|
43
|
+
buffer.writeExpression(
|
|
44
|
+
`out += state.inertia(state.page, ${attributes})`,
|
|
45
|
+
filename,
|
|
46
|
+
loc.start.line
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var inertiaHeadTag = {
|
|
51
|
+
block: false,
|
|
52
|
+
tagName: "inertiaHead",
|
|
53
|
+
seekable: false,
|
|
54
|
+
compile(_, buffer, { filename, loc }) {
|
|
55
|
+
buffer.writeExpression(`out += state.inertiaHead(state.page)`, filename, loc.start.line);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/plugins/edge/plugin.ts
|
|
60
|
+
var edgePluginInertia = () => {
|
|
61
|
+
return (edge) => {
|
|
62
|
+
debug_default("sharing globals and inertia tags with edge");
|
|
63
|
+
edge.global(
|
|
64
|
+
"inertia",
|
|
65
|
+
(page = {}, attributes = {}) => {
|
|
66
|
+
if (page.ssrBody)
|
|
67
|
+
return page.ssrBody;
|
|
68
|
+
const className = attributes?.class ? ` class="${attributes.class}"` : "";
|
|
69
|
+
const id = attributes?.id ? ` id="${attributes.id}"` : ' id="app"';
|
|
70
|
+
const tag = attributes?.as || "div";
|
|
71
|
+
const dataPage = encode(JSON.stringify(page));
|
|
72
|
+
return `<${tag}${id}${className} data-page="${dataPage}"></${tag}>`;
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
edge.global("inertiaHead", (page) => {
|
|
76
|
+
const { ssrHead = [] } = page || {};
|
|
77
|
+
return ssrHead.join("\n");
|
|
78
|
+
});
|
|
79
|
+
edge.registerTag(inertiaHeadTag);
|
|
80
|
+
edge.registerTag(inertiaTag);
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
edgePluginInertia
|
|
85
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PluginFn } from '@japa/runner/types';
|
|
2
|
-
import { PageProps } from '../types.js';
|
|
3
2
|
import { ApplicationService } from '@adonisjs/core/types';
|
|
3
|
+
import { PageProps } from '../../types.js';
|
|
4
4
|
import '@adonisjs/core/http';
|
|
5
5
|
|
|
6
6
|
declare module '@japa/api-client' {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
|
+
|
|
3
|
+
type InertiaPluginOptions = {
|
|
4
|
+
ssr?: {
|
|
5
|
+
/**
|
|
6
|
+
* Whether or not to enable server-side rendering
|
|
7
|
+
*/
|
|
8
|
+
enabled: true;
|
|
9
|
+
/**
|
|
10
|
+
* The entrypoint for the server-side rendering
|
|
11
|
+
*/
|
|
12
|
+
entrypoint: string;
|
|
13
|
+
/**
|
|
14
|
+
* The output directory for the server-side rendering bundle
|
|
15
|
+
*/
|
|
16
|
+
output?: string;
|
|
17
|
+
} | {
|
|
18
|
+
enabled: false;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Inertia plugin for Vite that is tailored for AdonisJS
|
|
23
|
+
*/
|
|
24
|
+
declare function inertia(options?: InertiaPluginOptions): PluginOption;
|
|
25
|
+
|
|
26
|
+
export { type InertiaPluginOptions, inertia as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/plugins/vite.ts
|
|
2
|
+
function inertia(options) {
|
|
3
|
+
return {
|
|
4
|
+
name: "vite-plugin-inertia",
|
|
5
|
+
config: (_, { command }) => {
|
|
6
|
+
if (!options?.ssr?.enabled)
|
|
7
|
+
return {};
|
|
8
|
+
if (command === "build") {
|
|
9
|
+
process.env.NODE_ENV = "production";
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
buildSteps: [
|
|
13
|
+
{
|
|
14
|
+
name: "build-client",
|
|
15
|
+
description: "build inertia client bundle",
|
|
16
|
+
config: { build: { outDir: "build/public/assets/" } }
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "build-ssr",
|
|
20
|
+
description: "build inertia server bundle",
|
|
21
|
+
config: {
|
|
22
|
+
build: {
|
|
23
|
+
ssr: true,
|
|
24
|
+
outDir: options.ssr.output || "build/ssr",
|
|
25
|
+
rollupOptions: { input: options.ssr.entrypoint }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
inertia as default
|
|
36
|
+
};
|
package/build/src/types.d.ts
CHANGED
|
@@ -44,9 +44,13 @@ type AssetsVersion = string | number | undefined;
|
|
|
44
44
|
interface InertiaConfig {
|
|
45
45
|
/**
|
|
46
46
|
* Path to the Edge view that will be used as the root view for Inertia responses.
|
|
47
|
-
* @default root (resources/views/
|
|
47
|
+
* @default root (resources/views/inertia_layout.edge)
|
|
48
48
|
*/
|
|
49
49
|
rootView?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Path to your client-side entrypoint file.
|
|
52
|
+
*/
|
|
53
|
+
entrypoint?: string;
|
|
50
54
|
/**
|
|
51
55
|
* The version of your assets. Every client request will be checked against this version.
|
|
52
56
|
* If the version is not the same, the client will do a full reload.
|
|
@@ -56,6 +60,27 @@ interface InertiaConfig {
|
|
|
56
60
|
* Data that should be shared with all rendered pages
|
|
57
61
|
*/
|
|
58
62
|
sharedData?: SharedData;
|
|
63
|
+
/**
|
|
64
|
+
* Options to configure SSR
|
|
65
|
+
*/
|
|
66
|
+
ssr?: {
|
|
67
|
+
/**
|
|
68
|
+
* Enable or disable SSR
|
|
69
|
+
*/
|
|
70
|
+
enabled: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* List of components that should be rendered on the server
|
|
73
|
+
*/
|
|
74
|
+
pages?: string[] | ((ctx: HttpContext, page: string) => MaybePromise<boolean>);
|
|
75
|
+
/**
|
|
76
|
+
* Path to the SSR entrypoint file
|
|
77
|
+
*/
|
|
78
|
+
entrypoint?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Path to the SSR bundled file that will be used in production
|
|
81
|
+
*/
|
|
82
|
+
bundle?: string;
|
|
83
|
+
};
|
|
59
84
|
}
|
|
60
85
|
/**
|
|
61
86
|
* Resolved inertia configuration
|
|
@@ -64,6 +89,21 @@ interface ResolvedConfig {
|
|
|
64
89
|
rootView: string;
|
|
65
90
|
versionCache: VersionCache;
|
|
66
91
|
sharedData: SharedData;
|
|
92
|
+
entrypoint: string;
|
|
93
|
+
ssr: {
|
|
94
|
+
enabled: boolean;
|
|
95
|
+
entrypoint: string;
|
|
96
|
+
pages?: string[] | ((ctx: HttpContext, page: string) => MaybePromise<boolean>);
|
|
97
|
+
bundle: string;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
interface PageObject<TPageProps extends PageProps = PageProps> {
|
|
101
|
+
component: string;
|
|
102
|
+
version: string | number;
|
|
103
|
+
props: TPageProps;
|
|
104
|
+
url: string;
|
|
105
|
+
ssrHead?: string;
|
|
106
|
+
ssrBody?: string;
|
|
67
107
|
}
|
|
68
108
|
|
|
69
|
-
export type { AssetsVersion, Data, InertiaConfig, MaybePromise, PageProps, ResolvedConfig, SharedData, SharedDatumFactory };
|
|
109
|
+
export type { AssetsVersion, Data, InertiaConfig, MaybePromise, PageObject, PageProps, ResolvedConfig, SharedData, SharedDatumFactory };
|