@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
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/app/app.ts') })
|
|
3
|
+
}}}
|
|
4
|
+
import '../css/app.css';
|
|
5
|
+
|
|
6
|
+
import { createInertiaApp } from '@inertiajs/svelte'
|
|
7
|
+
import { resolvePageComponent } from '@adonisjs/inertia/helpers'
|
|
8
|
+
|
|
9
|
+
const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
|
|
10
|
+
|
|
11
|
+
createInertiaApp({
|
|
12
|
+
progress: { color: '#5468FF' },
|
|
13
|
+
|
|
14
|
+
title: (title) => {{ '`${title} - ${appName}`' }},
|
|
15
|
+
|
|
16
|
+
resolve: (name) => {
|
|
17
|
+
return resolvePageComponent(
|
|
18
|
+
{{ '`../pages/${name}.svelte`' }},
|
|
19
|
+
import.meta.glob('../pages/**/*.svelte'),
|
|
20
|
+
)
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
setup({ el, App, props }) {
|
|
24
|
+
{{#if ssr}}
|
|
25
|
+
new App({ target: el, props, hydrate: true })
|
|
26
|
+
{{#else}}
|
|
27
|
+
new App({ target: el, props })
|
|
28
|
+
{{/if}}
|
|
29
|
+
},
|
|
30
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/errors/server_error.svelte') })
|
|
3
|
+
}}}
|
|
4
|
+
<script>
|
|
5
|
+
export let error
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<div>
|
|
9
|
+
<div class="container">
|
|
10
|
+
<div class="title">Server Error</div>
|
|
11
|
+
|
|
12
|
+
<span>{error.message}</span>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/home.svelte') })
|
|
3
|
+
}}}
|
|
4
|
+
<script>
|
|
5
|
+
export let version
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<svelte:head>
|
|
9
|
+
<title>Homepage</title>
|
|
10
|
+
</svelte:head>
|
|
11
|
+
|
|
12
|
+
<div class="container">
|
|
13
|
+
<div class="title">AdonisJS \{ version \} x Inertia x Svelte</div>
|
|
14
|
+
|
|
15
|
+
<span>
|
|
16
|
+
Learn more about AdonisJS and Inertia.js by visiting the
|
|
17
|
+
<a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
|
|
18
|
+
</span>
|
|
19
|
+
</div>
|
|
@@ -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 Svelte</title>
|
|
12
|
+
|
|
13
|
+
{{ "@vite(['inertia/app/app.ts', `inertia/pages/${page.component}.svelte`])" }}
|
|
14
|
+
@inertiaHead()
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
@inertia()
|
|
19
|
+
</body>
|
|
20
|
+
|
|
21
|
+
</html>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/app/ssr.ts') })
|
|
3
|
+
}}}
|
|
4
|
+
|
|
5
|
+
import { createInertiaApp } from '@inertiajs/svelte'
|
|
6
|
+
|
|
7
|
+
export default function render(page: any) {
|
|
8
|
+
return createInertiaApp({
|
|
9
|
+
page,
|
|
10
|
+
resolve: (name) => {
|
|
11
|
+
const pages = import.meta.glob('../pages/**/*.svelte', { eager: true })
|
|
12
|
+
{{ 'return pages[`../pages/${name}.svelte`]' }}
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
"paths": {
|
|
10
|
+
"~/*": ["./*"],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
"include": ["./**/*.ts", "./**/*.svelte"],
|
|
14
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/app/app.ts') })
|
|
3
|
+
}}}
|
|
4
|
+
import '../css/app.css';
|
|
5
|
+
|
|
6
|
+
{{#if ssr}}
|
|
7
|
+
import { createSSRApp, h } from 'vue'
|
|
8
|
+
{{#else}}
|
|
9
|
+
import { createApp, h } from 'vue'
|
|
10
|
+
{{/if}}
|
|
11
|
+
import type { DefineComponent } from 'vue'
|
|
12
|
+
import { createInertiaApp } from '@inertiajs/vue3'
|
|
13
|
+
import { resolvePageComponent } from '@adonisjs/inertia/helpers'
|
|
14
|
+
|
|
15
|
+
const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
|
|
16
|
+
|
|
17
|
+
createInertiaApp({
|
|
18
|
+
progress: { color: '#5468FF' },
|
|
19
|
+
|
|
20
|
+
title: (title) => {{ '`${title} - ${appName}`' }},
|
|
21
|
+
|
|
22
|
+
resolve: (name) => {
|
|
23
|
+
return resolvePageComponent(
|
|
24
|
+
{{ '`../pages/${name}.vue`' }},
|
|
25
|
+
import.meta.glob<DefineComponent>('../pages/**/*.vue'),
|
|
26
|
+
)
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
setup({ el, App, props, plugin }) {
|
|
30
|
+
{{#if ssr}}
|
|
31
|
+
createSSRApp({ render: () => h(App, props) })
|
|
32
|
+
{{#else}}
|
|
33
|
+
createApp({ render: () => h(App, props) })
|
|
34
|
+
{{/if}}
|
|
35
|
+
.use(plugin)
|
|
36
|
+
.mount(el)
|
|
37
|
+
},
|
|
38
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/errors/server_error.vue') })
|
|
3
|
+
}}}
|
|
4
|
+
<script setup lang="ts">
|
|
5
|
+
defineProps<{ error: any }>();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<template>
|
|
9
|
+
<div class="container">
|
|
10
|
+
<div class="title">Server Error</div>
|
|
11
|
+
|
|
12
|
+
<span>\{\{ error.message \}\}</span>
|
|
13
|
+
</div>
|
|
14
|
+
</template>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/home.vue') })
|
|
3
|
+
}}}
|
|
4
|
+
<script setup lang="ts">
|
|
5
|
+
import { Head } from '@inertiajs/vue3'
|
|
6
|
+
|
|
7
|
+
defineProps<{ version: number }>()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<Head title="Homepage" />
|
|
12
|
+
|
|
13
|
+
<div class="container">
|
|
14
|
+
<div class="title">AdonisJS \{\{ version \}\} x Inertia x Vue.js</div>
|
|
15
|
+
|
|
16
|
+
<span>
|
|
17
|
+
Learn more about AdonisJS and Inertia.js by visiting the
|
|
18
|
+
<a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
|
|
19
|
+
</span>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
@@ -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 VueJS</title>
|
|
12
|
+
|
|
13
|
+
{{ "@vite(['inertia/app/app.ts', `inertia/pages/${page.component}.vue`])" }}
|
|
14
|
+
@inertiaHead()
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
@inertia()
|
|
19
|
+
</body>
|
|
20
|
+
|
|
21
|
+
</html>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/app/ssr.ts') })
|
|
3
|
+
}}}
|
|
4
|
+
|
|
5
|
+
import { createInertiaApp } from '@inertiajs/vue3'
|
|
6
|
+
import { renderToString } from '@vue/server-renderer'
|
|
7
|
+
import { createSSRApp, h, type DefineComponent } from 'vue'
|
|
8
|
+
|
|
9
|
+
export default function render(page: any) {
|
|
10
|
+
return createInertiaApp({
|
|
11
|
+
page,
|
|
12
|
+
render: renderToString,
|
|
13
|
+
resolve: (name) => {
|
|
14
|
+
const pages = import.meta.glob<DefineComponent>('../pages/**/*.vue', { eager: true })
|
|
15
|
+
{{ 'return pages[`../pages/${name}.vue`]' }}
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
setup({ App, props, plugin }) {
|
|
19
|
+
return createSSRApp({ render: () => h(App, props) }).use(plugin)
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -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": "vue",
|
|
11
|
+
"paths": {
|
|
12
|
+
"~/*": ["./*"],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
"include": ["./**/*.ts", "./**/*.vue"],
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/inertia",
|
|
3
3
|
"description": "Official Inertia.js adapter for AdonisJS",
|
|
4
|
-
"version": "1.0.0-
|
|
4
|
+
"version": "1.0.0-20",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.16.0"
|
|
7
7
|
},
|
|
@@ -16,12 +16,14 @@
|
|
|
16
16
|
"./services/main": "./build/services/inertia.js",
|
|
17
17
|
"./inertia_middleware": "./build/src/inertia_middleware.js",
|
|
18
18
|
"./inertia_provider": "./build/providers/inertia_provider.js",
|
|
19
|
-
"./plugins/edge": "./build/src/plugins/edge.js",
|
|
20
|
-
"./plugins/api_client": "./build/src/plugins/api_client.js"
|
|
19
|
+
"./plugins/edge": "./build/src/plugins/edge/plugin.js",
|
|
20
|
+
"./plugins/api_client": "./build/src/plugins/japa/api_client.js",
|
|
21
|
+
"./client": "./build/src/plugins/vite.js",
|
|
22
|
+
"./helpers": "./build/src/helpers.js"
|
|
21
23
|
},
|
|
22
24
|
"scripts": {
|
|
23
25
|
"clean": "del-cli build",
|
|
24
|
-
"copy:templates": "copyfiles \"stubs/**/*.stub\" build",
|
|
26
|
+
"copy:templates": "copyfiles --up 1 \"stubs/**/*.stub\" build",
|
|
25
27
|
"typecheck": "tsc --noEmit",
|
|
26
28
|
"lint": "eslint . --ext=.ts",
|
|
27
29
|
"format": "prettier --write .",
|
|
@@ -36,55 +38,59 @@
|
|
|
36
38
|
"prepublishOnly": "npm run build"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
|
-
"@adonisjs/assembler": "
|
|
40
|
-
"@adonisjs/core": "6.1
|
|
41
|
-
"@adonisjs/eslint-config": "^1.
|
|
42
|
-
"@adonisjs/prettier-config": "^1.
|
|
43
|
-
"@adonisjs/session": "7.
|
|
44
|
-
"@adonisjs/tsconfig": "^1.
|
|
45
|
-
"@
|
|
46
|
-
"@japa/
|
|
47
|
-
"@japa/
|
|
48
|
-
"@japa/
|
|
49
|
-
"@japa/
|
|
50
|
-
"@japa/
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@types/
|
|
55
|
-
"
|
|
41
|
+
"@adonisjs/assembler": "^7.2.3",
|
|
42
|
+
"@adonisjs/core": "6.3.1",
|
|
43
|
+
"@adonisjs/eslint-config": "^1.3.0",
|
|
44
|
+
"@adonisjs/prettier-config": "^1.3.0",
|
|
45
|
+
"@adonisjs/session": "7.3.0",
|
|
46
|
+
"@adonisjs/tsconfig": "^1.3.0",
|
|
47
|
+
"@adonisjs/vite": "^3.0.0-8",
|
|
48
|
+
"@japa/api-client": "^2.0.2",
|
|
49
|
+
"@japa/assert": "2.1.0",
|
|
50
|
+
"@japa/expect-type": "^2.0.1",
|
|
51
|
+
"@japa/file-system": "^2.2.0",
|
|
52
|
+
"@japa/plugin-adonisjs": "^3.0.0",
|
|
53
|
+
"@japa/runner": "3.1.1",
|
|
54
|
+
"@japa/snapshot": "^2.0.4",
|
|
55
|
+
"@swc/core": "^1.4.8",
|
|
56
|
+
"@types/node": "^20.11.30",
|
|
57
|
+
"@types/qs": "^6.9.14",
|
|
58
|
+
"@types/supertest": "^6.0.2",
|
|
59
|
+
"@vavite/multibuild": "^4.1.1",
|
|
60
|
+
"c8": "^9.1.0",
|
|
56
61
|
"copyfiles": "^2.4.1",
|
|
57
62
|
"del-cli": "^5.1.0",
|
|
58
|
-
"edge
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
63
|
+
"edge-parser": "^9.0.2",
|
|
64
|
+
"edge.js": "^6.0.2",
|
|
65
|
+
"eslint": "^8.57.0",
|
|
66
|
+
"get-port": "^7.1.0",
|
|
67
|
+
"np": "^10.0.2",
|
|
68
|
+
"prettier": "^3.2.5",
|
|
69
|
+
"supertest": "^6.3.4",
|
|
70
|
+
"tinybench": "^2.6.0",
|
|
71
|
+
"ts-node": "^10.9.2",
|
|
72
|
+
"tsup": "^8.0.2",
|
|
73
|
+
"typescript": "~5.4.3",
|
|
74
|
+
"vite": "^5.2.6"
|
|
68
75
|
},
|
|
69
76
|
"dependencies": {
|
|
70
|
-
"@poppinss/utils": "^6.
|
|
77
|
+
"@poppinss/utils": "^6.7.2",
|
|
71
78
|
"crc-32": "^1.2.2",
|
|
72
|
-
"
|
|
79
|
+
"edge-error": "^4.0.1",
|
|
80
|
+
"html-entities": "^2.5.2",
|
|
81
|
+
"locate-path": "^7.2.0",
|
|
73
82
|
"qs": "^6.11.2"
|
|
74
83
|
},
|
|
75
84
|
"peerDependencies": {
|
|
76
|
-
"@adonisjs/
|
|
77
|
-
"@adonisjs/
|
|
78
|
-
"@adonisjs/
|
|
79
|
-
"@japa/api-client": "^2.0.
|
|
85
|
+
"@adonisjs/core": "^6.2.0",
|
|
86
|
+
"@adonisjs/session": "^7.0.0",
|
|
87
|
+
"@adonisjs/vite": "^3.0.0-8",
|
|
88
|
+
"@japa/api-client": "^2.0.0",
|
|
80
89
|
"edge.js": "^6.0.0"
|
|
81
90
|
},
|
|
82
91
|
"peerDependenciesMeta": {
|
|
83
|
-
"@adonisjs/assembler": {
|
|
84
|
-
"optional": false
|
|
85
|
-
},
|
|
86
92
|
"@japa/api-client": {
|
|
87
|
-
"optional":
|
|
93
|
+
"optional": true
|
|
88
94
|
}
|
|
89
95
|
},
|
|
90
96
|
"author": "Julien Ripouteau <julien@ripouteau.com>,adonisjs",
|
|
@@ -121,11 +127,13 @@
|
|
|
121
127
|
"entry": [
|
|
122
128
|
"./index.ts",
|
|
123
129
|
"./src/types.ts",
|
|
130
|
+
"./src/helpers.ts",
|
|
131
|
+
"./src/plugins/vite.ts",
|
|
124
132
|
"./services/inertia.ts",
|
|
125
133
|
"./src/inertia_middleware.ts",
|
|
126
134
|
"./providers/inertia_provider.ts",
|
|
127
|
-
"./src/plugins/edge.ts",
|
|
128
|
-
"./src/plugins/api_client.ts"
|
|
135
|
+
"./src/plugins/edge/plugin.ts",
|
|
136
|
+
"./src/plugins/japa/api_client.ts"
|
|
129
137
|
],
|
|
130
138
|
"outDir": "./build",
|
|
131
139
|
"clean": true,
|
package/build/chunk-GDULL3NT.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// src/inertia.ts
|
|
2
|
-
var kLazySymbol = Symbol("lazy");
|
|
3
|
-
var Inertia = class {
|
|
4
|
-
constructor(ctx, config) {
|
|
5
|
-
this.ctx = ctx;
|
|
6
|
-
this.config = config;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Check if a value is a lazy prop
|
|
10
|
-
*/
|
|
11
|
-
#isLazyProps(value) {
|
|
12
|
-
return typeof value === "object" && value && kLazySymbol in value;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Pick props to resolve based on x-inertia-partial-data header
|
|
16
|
-
*
|
|
17
|
-
* If header is not present, resolve all props except lazy props
|
|
18
|
-
* If header is present, resolve only the props that are listed in the header
|
|
19
|
-
*/
|
|
20
|
-
#pickPropsToResolve(component, props) {
|
|
21
|
-
const partialData = this.ctx.request.header("x-inertia-partial-data")?.split(",").filter(Boolean);
|
|
22
|
-
const partialComponent = this.ctx.request.header("x-inertia-partial-component");
|
|
23
|
-
let entriesToResolve = Object.entries(props);
|
|
24
|
-
if (partialData && partialComponent === component) {
|
|
25
|
-
entriesToResolve = entriesToResolve.filter(([key]) => partialData.includes(key));
|
|
26
|
-
} else {
|
|
27
|
-
entriesToResolve = entriesToResolve.filter(([key]) => !this.#isLazyProps(props[key]));
|
|
28
|
-
}
|
|
29
|
-
return entriesToResolve;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Resolve the props that will be sent to the client
|
|
33
|
-
*/
|
|
34
|
-
async #resolvePageProps(component, props) {
|
|
35
|
-
const entriesToResolve = this.#pickPropsToResolve(component, props);
|
|
36
|
-
const entries = entriesToResolve.map(async ([key, value]) => {
|
|
37
|
-
if (typeof value === "function") {
|
|
38
|
-
return [key, await value(this.ctx)];
|
|
39
|
-
}
|
|
40
|
-
if (this.#isLazyProps(value)) {
|
|
41
|
-
const lazyValue = value[kLazySymbol];
|
|
42
|
-
return [key, await lazyValue()];
|
|
43
|
-
}
|
|
44
|
-
return [key, value];
|
|
45
|
-
});
|
|
46
|
-
return Object.fromEntries(await Promise.all(entries));
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Build the page object that will be returned to the client
|
|
50
|
-
*
|
|
51
|
-
* See https://inertiajs.com/the-protocol#the-page-object
|
|
52
|
-
*/
|
|
53
|
-
async #buildPageObject(component, pageProps) {
|
|
54
|
-
return {
|
|
55
|
-
component,
|
|
56
|
-
version: this.config.versionCache.getVersion(),
|
|
57
|
-
props: await this.#resolvePageProps(component, { ...this.config.sharedData, ...pageProps }),
|
|
58
|
-
url: this.ctx.request.url(true)
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Render a page using Inertia
|
|
63
|
-
*/
|
|
64
|
-
async render(component, pageProps, viewProps) {
|
|
65
|
-
const pageObject = await this.#buildPageObject(component, pageProps);
|
|
66
|
-
const isInertiaRequest = !!this.ctx.request.header("x-inertia");
|
|
67
|
-
if (!isInertiaRequest) {
|
|
68
|
-
return this.ctx.view.render(this.config.rootView, { ...viewProps, page: pageObject });
|
|
69
|
-
}
|
|
70
|
-
return pageObject;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Create a lazy prop
|
|
74
|
-
*
|
|
75
|
-
* Lazy props are never resolved on first visit, but only when the client
|
|
76
|
-
* request a partial reload explicitely with this value.
|
|
77
|
-
*
|
|
78
|
-
* See https://inertiajs.com/partial-reloads#lazy-data-evaluation
|
|
79
|
-
*/
|
|
80
|
-
lazy(callback) {
|
|
81
|
-
return { [kLazySymbol]: callback };
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* This method can be used to redirect the user to an external website
|
|
85
|
-
* or even a non-inertia route of your application.
|
|
86
|
-
*
|
|
87
|
-
* See https://inertiajs.com/redirects#external-redirects
|
|
88
|
-
*/
|
|
89
|
-
async location(url) {
|
|
90
|
-
this.ctx.response.header("X-Inertia-Location", url);
|
|
91
|
-
this.ctx.response.status(409);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// src/inertia_middleware.ts
|
|
96
|
-
var InertiaMiddleware = class {
|
|
97
|
-
constructor(config) {
|
|
98
|
-
this.config = config;
|
|
99
|
-
}
|
|
100
|
-
async handle(ctx, next) {
|
|
101
|
-
const { response, request } = ctx;
|
|
102
|
-
ctx.inertia = new Inertia(ctx, this.config);
|
|
103
|
-
await next();
|
|
104
|
-
const isInertiaRequest = !!request.header("x-inertia");
|
|
105
|
-
if (!isInertiaRequest)
|
|
106
|
-
return;
|
|
107
|
-
response.header("Vary", "Accept");
|
|
108
|
-
response.header("X-Inertia", "true");
|
|
109
|
-
const method = request.method();
|
|
110
|
-
if (response.getStatus() === 302 && ["PUT", "PATCH", "DELETE"].includes(method)) {
|
|
111
|
-
response.status(303);
|
|
112
|
-
}
|
|
113
|
-
const version = this.config.versionCache.getVersion().toString();
|
|
114
|
-
if (method === "GET" && request.header("x-inertia-version", "") !== version) {
|
|
115
|
-
response.header("x-inertia-location", request.url());
|
|
116
|
-
response.status(409);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export {
|
|
122
|
-
InertiaMiddleware
|
|
123
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// src/plugins/edge.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.ts
|
|
9
|
-
var edgePluginInertia = () => {
|
|
10
|
-
return (edge) => {
|
|
11
|
-
debug_default("sharing globals and inertia tags with edge");
|
|
12
|
-
edge.global("inertia", (page = {}) => {
|
|
13
|
-
if (page.ssrBody)
|
|
14
|
-
return page.ssrBody;
|
|
15
|
-
return `<div id="app" data-page="${encode(JSON.stringify(page))}"></div>`;
|
|
16
|
-
});
|
|
17
|
-
edge.global("inertiaHead", (page) => {
|
|
18
|
-
const { ssrHead = [] } = page || {};
|
|
19
|
-
return ssrHead.join("\n");
|
|
20
|
-
});
|
|
21
|
-
edge.registerTag({
|
|
22
|
-
block: false,
|
|
23
|
-
tagName: "inertia",
|
|
24
|
-
seekable: false,
|
|
25
|
-
compile(_, buffer, { filename, loc }) {
|
|
26
|
-
buffer.writeExpression(`out += state.inertia(state.page)`, filename, loc.start.line);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
edge.registerTag({
|
|
30
|
-
block: false,
|
|
31
|
-
tagName: "inertiaHead",
|
|
32
|
-
seekable: false,
|
|
33
|
-
compile(_, buffer, { filename, loc }) {
|
|
34
|
-
buffer.writeExpression(`out += state.inertiaHead(state.page)`, filename, loc.start.line);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
export {
|
|
40
|
-
edgePluginInertia
|
|
41
|
-
};
|
|
File without changes
|