@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.
- package/build/debug-CBMTuPUm.js +3 -0
- package/build/factories/main.js +59 -172
- package/build/headers-DafWEpBh.js +11 -0
- package/build/index.js +5 -24
- package/build/inertia-D5A2KtfR.js +57 -0
- package/build/inertia_manager-Di3J3hSG.js +403 -0
- package/build/providers/inertia_provider.d.ts +2 -2
- package/build/providers/inertia_provider.js +25 -79
- package/build/src/client/helpers.d.ts +27 -0
- package/build/src/client/helpers.js +13 -0
- package/build/src/client/react/context.d.ts +24 -0
- package/build/src/client/react/index.d.ts +3 -0
- package/build/src/client/react/index.js +29 -0
- package/build/src/client/react/link.d.ts +64 -0
- package/build/src/client/react/router.d.ts +33 -0
- package/build/src/client/vite.d.ts +3 -1
- package/build/src/client/vite.js +16 -29
- package/build/src/define_config.d.ts +1 -0
- package/build/src/index_pages.d.ts +27 -0
- package/build/src/inertia.d.ts +15 -7
- package/build/src/inertia_manager.d.ts +1 -0
- package/build/src/inertia_middleware.d.ts +6 -3
- package/build/src/inertia_middleware.js +45 -111
- package/build/src/plugins/edge/plugin.js +49 -81
- package/build/src/plugins/japa/api_client.js +44 -59
- package/build/src/props.d.ts +16 -9
- package/build/src/server_renderer.d.ts +2 -2
- package/build/src/types.d.ts +17 -28
- package/build/src/types.js +1 -0
- package/build/tests/types/react.spec.d.ts +65 -0
- package/package.json +47 -25
- package/build/chunk-4EZ2J6OA.js +0 -7
- package/build/chunk-74S2VAL7.js +0 -761
- package/build/chunk-DISC5OYC.js +0 -46
- package/build/chunk-MLKGABMK.js +0 -9
- package/build/chunk-PDP56GPP.js +0 -75
package/build/factories/main.js
CHANGED
|
@@ -1,175 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
Inertia,
|
|
6
|
-
ServerRenderer
|
|
7
|
-
} from "../chunk-74S2VAL7.js";
|
|
8
|
-
import {
|
|
9
|
-
InertiaHeaders
|
|
10
|
-
} from "../chunk-DISC5OYC.js";
|
|
11
|
-
import "../chunk-4EZ2J6OA.js";
|
|
12
|
-
import "../chunk-MLKGABMK.js";
|
|
13
|
-
|
|
14
|
-
// factories/inertia_factory.ts
|
|
1
|
+
import { n as ServerRenderer, r as Inertia } from "../inertia_manager-Di3J3hSG.js";
|
|
2
|
+
import { t as InertiaHeaders } from "../headers-DafWEpBh.js";
|
|
3
|
+
import "../debug-CBMTuPUm.js";
|
|
4
|
+
import { t as defineConfig } from "../inertia-D5A2KtfR.js";
|
|
15
5
|
import { HttpContextFactory } from "@adonisjs/core/factories/http";
|
|
16
6
|
var InertiaFactory = class {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* Configures the factory for partial reloads of a specific component
|
|
72
|
-
*
|
|
73
|
-
* @param component - Name of the component to partially reload
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```typescript
|
|
77
|
-
* const inertia = factory
|
|
78
|
-
* .partialReload('UserProfile')
|
|
79
|
-
* .only(['name', 'email'])
|
|
80
|
-
* .create()
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
partialReload(component) {
|
|
84
|
-
const self = this;
|
|
85
|
-
const request = this.#parameters.ctx.request;
|
|
86
|
-
request.request.headers[InertiaHeaders.PartialComponent] = component;
|
|
87
|
-
return {
|
|
88
|
-
/**
|
|
89
|
-
* Specifies which props to include in the partial reload
|
|
90
|
-
*
|
|
91
|
-
* @param props - Array of property names to include
|
|
92
|
-
*/
|
|
93
|
-
only(props) {
|
|
94
|
-
request.request.headers[InertiaHeaders.PartialOnly] = props.join(",");
|
|
95
|
-
return this;
|
|
96
|
-
},
|
|
97
|
-
/**
|
|
98
|
-
* Specifies which props to exclude from the partial reload
|
|
99
|
-
*
|
|
100
|
-
* @param props - Array of property names to exclude
|
|
101
|
-
*/
|
|
102
|
-
except(props) {
|
|
103
|
-
request.request.headers[InertiaHeaders.PartialExcept] = props.join(",");
|
|
104
|
-
return this;
|
|
105
|
-
},
|
|
106
|
-
/**
|
|
107
|
-
* Specifies which props should be reset during the partial reload
|
|
108
|
-
*
|
|
109
|
-
* @param props - Array of property names to reset
|
|
110
|
-
*/
|
|
111
|
-
reset(props) {
|
|
112
|
-
request.request.headers[InertiaHeaders.Reset] = props.join(",");
|
|
113
|
-
return this;
|
|
114
|
-
},
|
|
115
|
-
/**
|
|
116
|
-
* Creates the Inertia instance with partial reload configuration
|
|
117
|
-
*/
|
|
118
|
-
create() {
|
|
119
|
-
return self.create();
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Sets the assets version for cache busting
|
|
125
|
-
*
|
|
126
|
-
* @param version - Version string or function for asset versioning
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```typescript
|
|
130
|
-
* factory.withVersion('1.0.0')
|
|
131
|
-
* // or
|
|
132
|
-
* factory.withVersion(() => Date.now().toString())
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
withVersion(version) {
|
|
136
|
-
this.#parameters.config = { ...this.#parameters.config, assetsVersion: version };
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Sets the Vite instance for asset handling
|
|
141
|
-
*
|
|
142
|
-
* @param options - Vite configuration object
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* factory.withVite(viteInstance)
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
withVite(options) {
|
|
150
|
-
this.#vite = options;
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Creates a new Inertia instance with the configured parameters
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```typescript
|
|
158
|
-
* const inertia = factory
|
|
159
|
-
* .merge({ config: customConfig })
|
|
160
|
-
* .withVersion('1.0.0')
|
|
161
|
-
* .create()
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
create() {
|
|
165
|
-
return new Inertia(
|
|
166
|
-
this.#parameters.ctx,
|
|
167
|
-
this.#parameters.config,
|
|
168
|
-
this.#vite,
|
|
169
|
-
this.#vite ? new ServerRenderer(this.#parameters.config, this.#vite) : void 0
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
export {
|
|
174
|
-
InertiaFactory
|
|
7
|
+
#vite;
|
|
8
|
+
#parameters = {
|
|
9
|
+
ctx: new HttpContextFactory().create(),
|
|
10
|
+
config: defineConfig({})
|
|
11
|
+
};
|
|
12
|
+
constructor() {
|
|
13
|
+
this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia] = "true";
|
|
14
|
+
}
|
|
15
|
+
merge(parameters) {
|
|
16
|
+
if (parameters.ctx) this.#parameters.ctx = parameters.ctx;
|
|
17
|
+
if (parameters.config) this.#parameters.config = defineConfig(parameters.config);
|
|
18
|
+
this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia] = "true";
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
withoutInertia() {
|
|
22
|
+
delete this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia];
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
partialReload(component) {
|
|
26
|
+
const self = this;
|
|
27
|
+
const request = this.#parameters.ctx.request;
|
|
28
|
+
request.request.headers[InertiaHeaders.PartialComponent] = component;
|
|
29
|
+
return {
|
|
30
|
+
only(props) {
|
|
31
|
+
request.request.headers[InertiaHeaders.PartialOnly] = props.join(",");
|
|
32
|
+
return this;
|
|
33
|
+
},
|
|
34
|
+
except(props) {
|
|
35
|
+
request.request.headers[InertiaHeaders.PartialExcept] = props.join(",");
|
|
36
|
+
return this;
|
|
37
|
+
},
|
|
38
|
+
reset(props) {
|
|
39
|
+
request.request.headers[InertiaHeaders.Reset] = props.join(",");
|
|
40
|
+
return this;
|
|
41
|
+
},
|
|
42
|
+
create() {
|
|
43
|
+
return self.create();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
withVersion(version) {
|
|
48
|
+
this.#parameters.config = {
|
|
49
|
+
...this.#parameters.config,
|
|
50
|
+
assetsVersion: version
|
|
51
|
+
};
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
withVite(options) {
|
|
55
|
+
this.#vite = options;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
create() {
|
|
59
|
+
return new Inertia(this.#parameters.ctx, this.#parameters.config, this.#vite, this.#vite ? new ServerRenderer(this.#parameters.config, this.#vite) : void 0);
|
|
60
|
+
}
|
|
175
61
|
};
|
|
62
|
+
export { InertiaFactory };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const InertiaHeaders = {
|
|
2
|
+
Inertia: "x-inertia",
|
|
3
|
+
Reset: "x-inertia-reset",
|
|
4
|
+
Version: "x-inertia-version",
|
|
5
|
+
Location: "x-inertia-location",
|
|
6
|
+
ErrorBag: "x-inertia-error-bag",
|
|
7
|
+
PartialOnly: "x-inertia-partial-data",
|
|
8
|
+
PartialExcept: "x-inertia-partial-except",
|
|
9
|
+
PartialComponent: "x-inertia-partial-component"
|
|
10
|
+
};
|
|
11
|
+
export { InertiaHeaders as t };
|
package/build/index.js
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./
|
|
5
|
-
|
|
6
|
-
Inertia,
|
|
7
|
-
InertiaManager,
|
|
8
|
-
ServerRenderer,
|
|
9
|
-
symbols_exports
|
|
10
|
-
} from "./chunk-74S2VAL7.js";
|
|
11
|
-
import {
|
|
12
|
-
InertiaHeaders
|
|
13
|
-
} from "./chunk-DISC5OYC.js";
|
|
14
|
-
import "./chunk-4EZ2J6OA.js";
|
|
15
|
-
import "./chunk-MLKGABMK.js";
|
|
16
|
-
export {
|
|
17
|
-
Inertia,
|
|
18
|
-
InertiaHeaders,
|
|
19
|
-
InertiaManager,
|
|
20
|
-
ServerRenderer,
|
|
21
|
-
defineConfig,
|
|
22
|
-
indexPages,
|
|
23
|
-
symbols_exports as symbols
|
|
24
|
-
};
|
|
1
|
+
import { i as symbols_exports, n as ServerRenderer, r as Inertia, t as InertiaManager } from "./inertia_manager-Di3J3hSG.js";
|
|
2
|
+
import { t as InertiaHeaders } from "./headers-DafWEpBh.js";
|
|
3
|
+
import "./debug-CBMTuPUm.js";
|
|
4
|
+
import { n as indexPages, t as defineConfig } from "./inertia-D5A2KtfR.js";
|
|
5
|
+
export { Inertia, InertiaHeaders, InertiaManager, ServerRenderer, defineConfig, indexPages, symbols_exports as symbols };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import lodash from "@poppinss/utils/lodash";
|
|
2
|
+
const GLOB = {
|
|
3
|
+
vue3: ["**/*.vue"],
|
|
4
|
+
react: ["**/*.ts", "**/*.tsx"]
|
|
5
|
+
};
|
|
6
|
+
const SUPPORTED_FRAMEWORKS = Object.keys(GLOB);
|
|
7
|
+
const TYPES_EXTRACTION_HELPER = {
|
|
8
|
+
vue3: `import type { VNodeProps, AllowedComponentProps, ComponentInstance } from 'vue'
|
|
9
|
+
|
|
10
|
+
type ExtractProps<T> = Omit<
|
|
11
|
+
ComponentInstance<T>['$props'],
|
|
12
|
+
keyof VNodeProps | keyof AllowedComponentProps
|
|
13
|
+
>`,
|
|
14
|
+
react: `import type React from 'react'
|
|
15
|
+
import type { Prettify } from '@adonisjs/core/types/common'
|
|
16
|
+
|
|
17
|
+
type ExtractProps<T> =
|
|
18
|
+
T extends React.FC<infer Props>
|
|
19
|
+
? Prettify<Omit<Props, 'children'>>
|
|
20
|
+
: T extends React.Component<infer Props>
|
|
21
|
+
? Prettify<Omit<Props, 'children'>>
|
|
22
|
+
: never`
|
|
23
|
+
};
|
|
24
|
+
const indexPages = function(config) {
|
|
25
|
+
if (!SUPPORTED_FRAMEWORKS.includes(config.framework)) throw new Error(`Unsupported framework "${config.framework}". Types generation is available only for ${SUPPORTED_FRAMEWORKS.join(",")}`);
|
|
26
|
+
return { run(_, indexGenerator) {
|
|
27
|
+
indexGenerator.add("inertiaPages", {
|
|
28
|
+
source: "inertia/pages",
|
|
29
|
+
glob: GLOB[config.framework],
|
|
30
|
+
output: ".adonisjs/server/pages.d.ts",
|
|
31
|
+
as(vfs, buffer, __, helpers) {
|
|
32
|
+
const filesList = vfs.asList();
|
|
33
|
+
buffer.writeLine(`import '@adonisjs/inertia/types'`);
|
|
34
|
+
buffer.writeLine(TYPES_EXTRACTION_HELPER[config.framework]);
|
|
35
|
+
buffer.write(`declare module '@adonisjs/inertia/types' {`).indent();
|
|
36
|
+
buffer.write(`export interface InertiaPages {`).indent();
|
|
37
|
+
Object.keys(filesList).forEach((key) => {
|
|
38
|
+
buffer.write(`'${key}': ExtractProps<(typeof import('${helpers.toImportPath(filesList[key])}'))['default']>`);
|
|
39
|
+
});
|
|
40
|
+
buffer.dedent().write(`}`);
|
|
41
|
+
buffer.dedent().write(`}`);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
} };
|
|
45
|
+
};
|
|
46
|
+
function defineConfig(config) {
|
|
47
|
+
return lodash.merge({
|
|
48
|
+
rootView: "inertia_layout",
|
|
49
|
+
history: { encrypt: false },
|
|
50
|
+
ssr: {
|
|
51
|
+
enabled: false,
|
|
52
|
+
bundle: "ssr/ssr.js",
|
|
53
|
+
entrypoint: "inertia/ssr.tsx"
|
|
54
|
+
}
|
|
55
|
+
}, config);
|
|
56
|
+
}
|
|
57
|
+
export { indexPages as n, defineConfig as t };
|