@adonisjs/inertia 1.0.0-0 → 1.0.0-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.css.stub +39 -0
- package/build/chunk-CXICUKHN.js +165 -0
- package/build/{stubs/config.stub → config.stub} +9 -1
- package/build/index.d.ts +18 -3
- package/build/index.js +231 -11
- package/build/providers/inertia_provider.d.ts +12 -12
- package/build/providers/inertia_provider.js +47 -46
- package/build/react/app.tsx.stub +25 -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 +25 -0
- package/build/solid/app.tsx.stub +24 -0
- package/build/solid/home.tsx.stub +21 -0
- package/build/solid/root.edge.stub +21 -0
- package/build/solid/ssr.tsx.stub +19 -0
- package/build/solid/tsconfig.json.stub +26 -0
- package/build/src/helpers.d.ts +12 -0
- package/build/src/helpers.js +14 -0
- package/build/src/inertia_middleware.d.ts +68 -7
- package/build/src/inertia_middleware.js +6 -47
- package/build/src/plugins/edge/plugin.d.ts +8 -0
- package/build/src/plugins/edge/plugin.js +85 -0
- package/build/src/plugins/{api_client.d.ts → japa/api_client.d.ts} +9 -4
- package/build/src/plugins/japa/api_client.js +70 -0
- package/build/src/plugins/vite.d.ts +26 -0
- package/build/src/plugins/vite.js +33 -0
- package/build/src/types.d.ts +72 -8
- package/build/src/types.js +0 -9
- package/build/vue/app.ts.stub +27 -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 +26 -0
- package/package.json +64 -47
- package/build/configure.js +0 -82
- package/build/src/debug.d.ts +0 -3
- package/build/src/debug.js +0 -10
- package/build/src/define_config.d.ts +0 -5
- package/build/src/define_config.js +0 -14
- package/build/src/inertia.d.ts +0 -39
- package/build/src/inertia.js +0 -119
- package/build/src/plugins/api_client.js +0 -62
- package/build/src/plugins/edge.d.ts +0 -5
- package/build/src/plugins/edge.js +0 -43
- package/build/src/version_cache.d.ts +0 -27
- package/build/src/version_cache.js +0 -68
- package/build/stubs/main.d.ts +0 -1
- package/build/stubs/main.js +0 -10
- package/providers/inertia_provider.ts +0 -66
- package/src/debug.ts +0 -12
- package/src/define_config.ts +0 -17
- package/src/inertia.ts +0 -140
- package/src/inertia_middleware.ts +0 -54
- package/src/plugins/api_client.ts +0 -127
- package/src/plugins/edge.ts +0 -50
- package/src/types.ts +0 -48
- package/src/version_cache.ts +0 -74
package/build/src/types.d.ts
CHANGED
|
@@ -1,20 +1,47 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* VersionCache is used to cache the version of the assets.
|
|
5
|
+
*
|
|
6
|
+
* If the user has provided a version, it will be used.
|
|
7
|
+
* Otherwise, we will compute a hash from the manifest file
|
|
8
|
+
* and cache it.
|
|
9
|
+
*/
|
|
10
|
+
declare class VersionCache {
|
|
11
|
+
#private;
|
|
12
|
+
protected appRoot: URL;
|
|
13
|
+
protected assetsVersion?: AssetsVersion;
|
|
14
|
+
constructor(appRoot: URL, assetsVersion?: AssetsVersion);
|
|
15
|
+
/**
|
|
16
|
+
* Pre-compute the version
|
|
17
|
+
*/
|
|
18
|
+
computeVersion(): Promise<this>;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the current assets version
|
|
21
|
+
*/
|
|
22
|
+
getVersion(): string | number;
|
|
23
|
+
/**
|
|
24
|
+
* Set the assets version
|
|
25
|
+
*/
|
|
26
|
+
setVersion(version: AssetsVersion): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
3
30
|
/**
|
|
4
31
|
* Props that will be passed to inertia render method
|
|
5
32
|
*/
|
|
6
|
-
|
|
33
|
+
type PageProps = Record<string, unknown>;
|
|
7
34
|
/**
|
|
8
35
|
* Shared data types
|
|
9
36
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
37
|
+
type Data = string | number | object | boolean;
|
|
38
|
+
type SharedDatumFactory = (ctx: HttpContext) => MaybePromise<Data>;
|
|
39
|
+
type SharedData = Record<string, Data | SharedDatumFactory>;
|
|
13
40
|
/**
|
|
14
41
|
* Allowed values for the assets version
|
|
15
42
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
43
|
+
type AssetsVersion = string | number | undefined;
|
|
44
|
+
interface InertiaConfig {
|
|
18
45
|
/**
|
|
19
46
|
* Path to the Edge view that will be used as the root view for Inertia responses.
|
|
20
47
|
* @default root (resources/views/root.edge)
|
|
@@ -29,4 +56,41 @@ export interface InertiaConfig {
|
|
|
29
56
|
* Data that should be shared with all rendered pages
|
|
30
57
|
*/
|
|
31
58
|
sharedData?: SharedData;
|
|
59
|
+
/**
|
|
60
|
+
* Options to configure SSR
|
|
61
|
+
*/
|
|
62
|
+
ssr?: {
|
|
63
|
+
/**
|
|
64
|
+
* Enable or disable SSR
|
|
65
|
+
*/
|
|
66
|
+
enabled: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* List of components that should be rendered on the server
|
|
69
|
+
*/
|
|
70
|
+
pages?: string[];
|
|
71
|
+
/**
|
|
72
|
+
* Path to the SSR entrypoint file
|
|
73
|
+
*/
|
|
74
|
+
entrypoint?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Path to the SSR bundled file that will be used in production
|
|
77
|
+
*/
|
|
78
|
+
bundle?: string;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Resolved inertia configuration
|
|
83
|
+
*/
|
|
84
|
+
interface ResolvedConfig {
|
|
85
|
+
rootView: string;
|
|
86
|
+
versionCache: VersionCache;
|
|
87
|
+
sharedData: SharedData;
|
|
88
|
+
ssr: {
|
|
89
|
+
enabled: boolean;
|
|
90
|
+
entrypoint: string;
|
|
91
|
+
pages?: string[];
|
|
92
|
+
bundle: string;
|
|
93
|
+
};
|
|
32
94
|
}
|
|
95
|
+
|
|
96
|
+
export type { AssetsVersion, Data, InertiaConfig, MaybePromise, PageProps, ResolvedConfig, SharedData, SharedDatumFactory };
|
package/build/src/types.js
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/app.ts') })
|
|
3
|
+
}}}
|
|
4
|
+
import './css/app.css';
|
|
5
|
+
|
|
6
|
+
import { createApp, h } from 'vue'
|
|
7
|
+
import type { DefineComponent } from 'vue'
|
|
8
|
+
import { createInertiaApp } from '@inertiajs/vue3'
|
|
9
|
+
|
|
10
|
+
const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
|
|
11
|
+
|
|
12
|
+
createInertiaApp({
|
|
13
|
+
progress: { color: '#5468FF' },
|
|
14
|
+
|
|
15
|
+
title: (title) => {{ '`${title} - ${appName}`' }},
|
|
16
|
+
|
|
17
|
+
resolve: (name) => {
|
|
18
|
+
const pages = import.meta.glob<DefineComponent>('./pages/**/*.vue', { eager: true })
|
|
19
|
+
{{ 'return pages[`./pages/${name}.vue`]' }}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
setup({ el, App, props, plugin }) {
|
|
23
|
+
createApp({ render: () => h(App, props) })
|
|
24
|
+
.use(plugin)
|
|
25
|
+
.mount(el)
|
|
26
|
+
},
|
|
27
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/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 className="container">
|
|
14
|
+
<div className="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/inertia">AdonisJS documentation</a>.
|
|
19
|
+
</span>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/views/root.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(['resources/app.ts'])
|
|
14
|
+
@inertiaHead()
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
@inertia()
|
|
19
|
+
</body>
|
|
20
|
+
|
|
21
|
+
</html>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/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,26 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/tsconfig.json') })
|
|
3
|
+
}}}
|
|
4
|
+
{
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
"jsx": "preserve",
|
|
8
|
+
"jsxImportSource": "vue",
|
|
9
|
+
"lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
|
|
10
|
+
"useDefineForClassFields": true,
|
|
11
|
+
"baseUrl": ".",
|
|
12
|
+
"module": "ESNext",
|
|
13
|
+
"moduleResolution": "Bundler",
|
|
14
|
+
"paths": {
|
|
15
|
+
"@/*": ["./*"],
|
|
16
|
+
"~/*": ["../*"],
|
|
17
|
+
},
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"types": ["vite/client"],
|
|
20
|
+
"allowSyntheticDefaultImports": true,
|
|
21
|
+
"esModuleInterop": true,
|
|
22
|
+
"verbatimModuleSyntax": true,
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
},
|
|
25
|
+
"include": ["./**/*.ts", "./**/*.vue"],
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
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-10",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.16.0"
|
|
7
7
|
},
|
|
8
8
|
"main": "build/index.js",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"files": [
|
|
11
|
-
"
|
|
12
|
-
"providers",
|
|
13
|
-
"build/src",
|
|
14
|
-
"build/providers",
|
|
15
|
-
"build/stubs",
|
|
16
|
-
"build/services",
|
|
17
|
-
"build/index.js",
|
|
18
|
-
"build/index.d.ts",
|
|
19
|
-
"build/configure.js"
|
|
11
|
+
"build"
|
|
20
12
|
],
|
|
21
13
|
"exports": {
|
|
22
14
|
".": "./build/index.js",
|
|
@@ -24,12 +16,14 @@
|
|
|
24
16
|
"./services/main": "./build/services/inertia.js",
|
|
25
17
|
"./inertia_middleware": "./build/src/inertia_middleware.js",
|
|
26
18
|
"./inertia_provider": "./build/providers/inertia_provider.js",
|
|
27
|
-
"./plugins/edge": "./build/src/plugins/edge.js",
|
|
28
|
-
"./plugins/api_client": "./build/src/plugins/japa/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"
|
|
29
23
|
},
|
|
30
24
|
"scripts": {
|
|
31
25
|
"clean": "del-cli build",
|
|
32
|
-
"copy:templates": "copyfiles \"stubs/**/*.stub\" build",
|
|
26
|
+
"copy:templates": "copyfiles --up 1 \"stubs/**/*.stub\" build",
|
|
33
27
|
"typecheck": "tsc --noEmit",
|
|
34
28
|
"lint": "eslint . --ext=.ts",
|
|
35
29
|
"format": "prettier --write .",
|
|
@@ -37,60 +31,65 @@
|
|
|
37
31
|
"pretest": "npm run lint",
|
|
38
32
|
"test": "c8 npm run quick:test",
|
|
39
33
|
"prebuild": "npm run lint && npm run clean",
|
|
40
|
-
"build": "
|
|
34
|
+
"build": "tsup-node",
|
|
41
35
|
"postbuild": "npm run copy:templates",
|
|
42
36
|
"release": "np",
|
|
43
37
|
"version": "npm run build",
|
|
44
38
|
"prepublishOnly": "npm run build"
|
|
45
39
|
},
|
|
46
40
|
"devDependencies": {
|
|
47
|
-
"@adonisjs/assembler": "
|
|
48
|
-
"@adonisjs/core": "6.1
|
|
49
|
-
"@adonisjs/eslint-config": "^1.
|
|
50
|
-
"@adonisjs/prettier-config": "^1.
|
|
51
|
-
"@adonisjs/session": "7.
|
|
52
|
-
"@adonisjs/tsconfig": "^1.
|
|
53
|
-
"@
|
|
54
|
-
"@japa/
|
|
55
|
-
"@japa/
|
|
56
|
-
"@japa/
|
|
57
|
-
"@japa/
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"
|
|
41
|
+
"@adonisjs/assembler": "^7.2.3",
|
|
42
|
+
"@adonisjs/core": "6.3.1",
|
|
43
|
+
"@adonisjs/eslint-config": "^1.2.2",
|
|
44
|
+
"@adonisjs/prettier-config": "^1.2.2",
|
|
45
|
+
"@adonisjs/session": "7.1.1",
|
|
46
|
+
"@adonisjs/tsconfig": "^1.2.2",
|
|
47
|
+
"@adonisjs/vite": "^3.0.0-2",
|
|
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.2",
|
|
56
|
+
"@types/node": "^20.11.24",
|
|
57
|
+
"@types/qs": "^6.9.12",
|
|
58
|
+
"@types/supertest": "^6.0.2",
|
|
59
|
+
"@vavite/multibuild": "^4.1.1",
|
|
60
|
+
"c8": "^9.1.0",
|
|
63
61
|
"copyfiles": "^2.4.1",
|
|
64
62
|
"del-cli": "^5.1.0",
|
|
65
|
-
"edge
|
|
66
|
-
"
|
|
63
|
+
"edge-parser": "^9.0.1",
|
|
64
|
+
"edge.js": "^6.0.1",
|
|
65
|
+
"eslint": "^8.57.0",
|
|
67
66
|
"get-port": "^7.0.0",
|
|
68
|
-
"np": "^
|
|
69
|
-
"prettier": "^3.
|
|
70
|
-
"supertest": "^6.3.
|
|
71
|
-
"tinybench": "^2.
|
|
72
|
-
"ts-node": "^10.9.
|
|
73
|
-
"
|
|
67
|
+
"np": "^10.0.0",
|
|
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.3.3",
|
|
74
|
+
"vite": "^5.1.4"
|
|
74
75
|
},
|
|
75
76
|
"dependencies": {
|
|
76
|
-
"@poppinss/utils": "^6.
|
|
77
|
+
"@poppinss/utils": "^6.7.2",
|
|
77
78
|
"crc-32": "^1.2.2",
|
|
79
|
+
"edge-error": "^4.0.1",
|
|
78
80
|
"html-entities": "^2.4.0",
|
|
79
81
|
"qs": "^6.11.2"
|
|
80
82
|
},
|
|
81
83
|
"peerDependencies": {
|
|
82
|
-
"@adonisjs/
|
|
83
|
-
"@adonisjs/
|
|
84
|
-
"@adonisjs/
|
|
85
|
-
"@japa/api-client": "^2.0.
|
|
84
|
+
"@adonisjs/core": "^6.2.0",
|
|
85
|
+
"@adonisjs/session": "^7.0.0",
|
|
86
|
+
"@adonisjs/vite": "^3.0.0-2",
|
|
87
|
+
"@japa/api-client": "^2.0.0",
|
|
86
88
|
"edge.js": "^6.0.0"
|
|
87
89
|
},
|
|
88
90
|
"peerDependenciesMeta": {
|
|
89
|
-
"@adonisjs/assembler": {
|
|
90
|
-
"optional": false
|
|
91
|
-
},
|
|
92
91
|
"@japa/api-client": {
|
|
93
|
-
"optional":
|
|
92
|
+
"optional": true
|
|
94
93
|
}
|
|
95
94
|
},
|
|
96
95
|
"author": "Julien Ripouteau <julien@ripouteau.com>,adonisjs",
|
|
@@ -122,5 +121,23 @@
|
|
|
122
121
|
"tests/**",
|
|
123
122
|
"tests_helpers/**"
|
|
124
123
|
]
|
|
124
|
+
},
|
|
125
|
+
"tsup": {
|
|
126
|
+
"entry": [
|
|
127
|
+
"./index.ts",
|
|
128
|
+
"./src/types.ts",
|
|
129
|
+
"./src/helpers.ts",
|
|
130
|
+
"./src/plugins/vite.ts",
|
|
131
|
+
"./services/inertia.ts",
|
|
132
|
+
"./src/inertia_middleware.ts",
|
|
133
|
+
"./providers/inertia_provider.ts",
|
|
134
|
+
"./src/plugins/edge/plugin.ts",
|
|
135
|
+
"./src/plugins/japa/api_client.ts"
|
|
136
|
+
],
|
|
137
|
+
"outDir": "./build",
|
|
138
|
+
"clean": true,
|
|
139
|
+
"format": "esm",
|
|
140
|
+
"dts": true,
|
|
141
|
+
"target": "esnext"
|
|
125
142
|
}
|
|
126
143
|
}
|
package/build/configure.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/inertia
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
const ADAPTERS = ['Vue 3', 'React', 'Svelte'];
|
|
10
|
-
const ADAPTERS_INFO = {
|
|
11
|
-
'Vue 3': {
|
|
12
|
-
dependencies: [
|
|
13
|
-
{ name: '@inertiajs/vue3', isDevDependency: false },
|
|
14
|
-
{ name: 'vue', isDevDependency: false },
|
|
15
|
-
{ name: '@vitejs/plugin-vue', isDevDependency: true },
|
|
16
|
-
],
|
|
17
|
-
},
|
|
18
|
-
'React': {
|
|
19
|
-
dependencies: [
|
|
20
|
-
{ name: '@inertiajs/inertia-react', isDevDependency: false },
|
|
21
|
-
{ name: 'react', isDevDependency: false },
|
|
22
|
-
{ name: 'react-dom', isDevDependency: false },
|
|
23
|
-
{ name: '@vitejs/plugin-react', isDevDependency: true },
|
|
24
|
-
{ name: '@types/react', isDevDependency: true },
|
|
25
|
-
{ name: '@types/react-dom', isDevDependency: true },
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
'Svelte': {
|
|
29
|
-
dependencies: [
|
|
30
|
-
{ name: '@inertiajs/inertia-svelte', isDevDependency: false },
|
|
31
|
-
{ name: 'svelte', isDevDependency: false },
|
|
32
|
-
{ name: '@sveltejs/vite-plugin-svelte', isDevDependency: true },
|
|
33
|
-
],
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Configures the package
|
|
38
|
-
*/
|
|
39
|
-
export async function configure(command) {
|
|
40
|
-
/**
|
|
41
|
-
* Prompt for adapter
|
|
42
|
-
*/
|
|
43
|
-
const adapter = await command.prompt.choice('Select the Inertia adapter you want to use', ADAPTERS, { name: 'adapter' });
|
|
44
|
-
const pkgToInstall = ADAPTERS_INFO[adapter].dependencies;
|
|
45
|
-
/**
|
|
46
|
-
* Prompt for SSR
|
|
47
|
-
*/
|
|
48
|
-
const withSsr = await command.prompt.confirm('Do you want to enable server-side rendering?', {
|
|
49
|
-
name: 'ssr',
|
|
50
|
-
});
|
|
51
|
-
if (withSsr) {
|
|
52
|
-
pkgToInstall.push(...(ADAPTERS_INFO[adapter].ssrDependencies || []));
|
|
53
|
-
}
|
|
54
|
-
const codemods = await command.createCodemods();
|
|
55
|
-
/**
|
|
56
|
-
* Publish provider
|
|
57
|
-
*/
|
|
58
|
-
await codemods.updateRcFile((rcFile) => {
|
|
59
|
-
rcFile.addProvider('@adonisjs/inertia/inertia_provider');
|
|
60
|
-
});
|
|
61
|
-
/**
|
|
62
|
-
* Add Inertia middleware
|
|
63
|
-
*/
|
|
64
|
-
codemods.registerMiddleware('router', [
|
|
65
|
-
{ path: '@adonisjs/inertia/inertia_middleware', position: 'after' },
|
|
66
|
-
]);
|
|
67
|
-
/**
|
|
68
|
-
* Publish config
|
|
69
|
-
*/
|
|
70
|
-
await command.publishStub('config.stub');
|
|
71
|
-
/**
|
|
72
|
-
* Install packages
|
|
73
|
-
*/
|
|
74
|
-
const shouldInstallPackages = await command.prompt.confirm(`Do you want to install dependencies ${pkgToInstall.map((pkg) => pkg.name).join(', ')}?`, { name: 'install' });
|
|
75
|
-
if (shouldInstallPackages) {
|
|
76
|
-
command.installPackages(pkgToInstall);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
command.listPackagesToInstall(pkgToInstall);
|
|
80
|
-
}
|
|
81
|
-
command.logger.success('Inertia was configured successfully. Please note that you still need to update your vite config, setup your Edge root view and others things. Read the docs for more info.');
|
|
82
|
-
}
|
package/build/src/debug.d.ts
DELETED
package/build/src/debug.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/inertia
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { debuglog } from 'node:util';
|
|
10
|
-
export default debuglog('adonisjs:inertia');
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/inertia
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Define the Inertia configuration
|
|
11
|
-
*/
|
|
12
|
-
export function defineConfig(config) {
|
|
13
|
-
return config;
|
|
14
|
-
}
|
package/build/src/inertia.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
import type { InertiaConfig, MaybePromise, PageProps, AssetsVersion } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Main class used to interact with Inertia
|
|
5
|
-
*/
|
|
6
|
-
export declare class Inertia {
|
|
7
|
-
#private;
|
|
8
|
-
protected ctx: HttpContext;
|
|
9
|
-
protected config: InertiaConfig;
|
|
10
|
-
protected version: AssetsVersion;
|
|
11
|
-
constructor(ctx: HttpContext, config: InertiaConfig, version: AssetsVersion);
|
|
12
|
-
/**
|
|
13
|
-
* Render a page using Inertia
|
|
14
|
-
*/
|
|
15
|
-
render(component: string, pageProps?: PageProps): Promise<string | {
|
|
16
|
-
component: string;
|
|
17
|
-
version: AssetsVersion;
|
|
18
|
-
props: any;
|
|
19
|
-
url: string;
|
|
20
|
-
}>;
|
|
21
|
-
/**
|
|
22
|
-
* Create a lazy prop
|
|
23
|
-
*
|
|
24
|
-
* Lazy props are never resolved on first visit, but only when the client
|
|
25
|
-
* request a partial reload explicitely with this value.
|
|
26
|
-
*
|
|
27
|
-
* See https://inertiajs.com/partial-reloads#lazy-data-evaluation
|
|
28
|
-
*/
|
|
29
|
-
lazy(callback: () => MaybePromise<any>): {
|
|
30
|
-
[x: symbol]: () => MaybePromise<any>;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* This method can be used to redirect the user to an external website
|
|
34
|
-
* or even a non-inertia route of your application.
|
|
35
|
-
*
|
|
36
|
-
* See https://inertiajs.com/redirects#external-redirects
|
|
37
|
-
*/
|
|
38
|
-
location(url: string): Promise<void>;
|
|
39
|
-
}
|
package/build/src/inertia.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/inertia
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Main class used to interact with Inertia
|
|
11
|
-
*/
|
|
12
|
-
export class Inertia {
|
|
13
|
-
ctx;
|
|
14
|
-
config;
|
|
15
|
-
version;
|
|
16
|
-
/**
|
|
17
|
-
* The name of the Edge view that will be used to render the page.
|
|
18
|
-
*/
|
|
19
|
-
#edgeRootView;
|
|
20
|
-
/**
|
|
21
|
-
* Symbol used to identify lazy props
|
|
22
|
-
*/
|
|
23
|
-
#kLazySymbol = Symbol('lazy');
|
|
24
|
-
constructor(ctx, config = {}, version) {
|
|
25
|
-
this.ctx = ctx;
|
|
26
|
-
this.config = config;
|
|
27
|
-
this.version = version;
|
|
28
|
-
this.#edgeRootView = config.rootView || 'root';
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Check if a value is a lazy prop
|
|
32
|
-
*/
|
|
33
|
-
#isLazyProps(value) {
|
|
34
|
-
return typeof value === 'object' && value && this.#kLazySymbol in value;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Pick props to resolve based on x-inertia-partial-data header
|
|
38
|
-
*
|
|
39
|
-
* If header is not present, resolve all props except lazy props
|
|
40
|
-
* If header is present, resolve only the props that are listed in the header
|
|
41
|
-
*/
|
|
42
|
-
#pickPropsToResolve(component, props) {
|
|
43
|
-
const partialData = this.ctx.request
|
|
44
|
-
.header('x-inertia-partial-data')
|
|
45
|
-
?.split(',')
|
|
46
|
-
.filter(Boolean);
|
|
47
|
-
const partialComponent = this.ctx.request.header('x-inertia-partial-component');
|
|
48
|
-
let entriesToResolve = Object.entries(props);
|
|
49
|
-
if (partialData && partialComponent === component) {
|
|
50
|
-
entriesToResolve = entriesToResolve.filter(([key]) => partialData.includes(key));
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
entriesToResolve = entriesToResolve.filter(([key]) => !this.#isLazyProps(props[key]));
|
|
54
|
-
}
|
|
55
|
-
return entriesToResolve;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Resolve the props that will be sent to the client
|
|
59
|
-
*/
|
|
60
|
-
async #resolvePageProps(component, props) {
|
|
61
|
-
const entriesToResolve = this.#pickPropsToResolve(component, props);
|
|
62
|
-
const entries = entriesToResolve.map(async ([key, value]) => {
|
|
63
|
-
if (typeof value === 'function') {
|
|
64
|
-
return [key, await value(this.ctx)];
|
|
65
|
-
}
|
|
66
|
-
if (this.#isLazyProps(value)) {
|
|
67
|
-
const lazyValue = value[this.#kLazySymbol];
|
|
68
|
-
return [key, await lazyValue()];
|
|
69
|
-
}
|
|
70
|
-
return [key, value];
|
|
71
|
-
});
|
|
72
|
-
return Object.fromEntries(await Promise.all(entries));
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Build the page object that will be returned to the client
|
|
76
|
-
*
|
|
77
|
-
* See https://inertiajs.com/the-protocol#the-page-object
|
|
78
|
-
*/
|
|
79
|
-
async #buildPageObject(component, pageProps) {
|
|
80
|
-
return {
|
|
81
|
-
component,
|
|
82
|
-
version: this.version,
|
|
83
|
-
props: await this.#resolvePageProps(component, { ...this.config.sharedData, ...pageProps }),
|
|
84
|
-
url: this.ctx.request.url(true),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Render a page using Inertia
|
|
89
|
-
*/
|
|
90
|
-
async render(component, pageProps) {
|
|
91
|
-
const pageObject = await this.#buildPageObject(component, pageProps);
|
|
92
|
-
const isInertiaRequest = !!this.ctx.request.header('x-inertia');
|
|
93
|
-
if (!isInertiaRequest) {
|
|
94
|
-
return this.ctx.view.render(this.#edgeRootView, { page: pageObject });
|
|
95
|
-
}
|
|
96
|
-
return pageObject;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Create a lazy prop
|
|
100
|
-
*
|
|
101
|
-
* Lazy props are never resolved on first visit, but only when the client
|
|
102
|
-
* request a partial reload explicitely with this value.
|
|
103
|
-
*
|
|
104
|
-
* See https://inertiajs.com/partial-reloads#lazy-data-evaluation
|
|
105
|
-
*/
|
|
106
|
-
lazy(callback) {
|
|
107
|
-
return { [this.#kLazySymbol]: callback };
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* This method can be used to redirect the user to an external website
|
|
111
|
-
* or even a non-inertia route of your application.
|
|
112
|
-
*
|
|
113
|
-
* See https://inertiajs.com/redirects#external-redirects
|
|
114
|
-
*/
|
|
115
|
-
async location(url) {
|
|
116
|
-
this.ctx.response.header('X-Inertia-Location', url);
|
|
117
|
-
this.ctx.response.status(409);
|
|
118
|
-
}
|
|
119
|
-
}
|