@adonisjs/inertia 5.0.0-next.0 → 5.0.0-next.1
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/commands/make_page.js +15 -0
- package/build/debug-Ca0ekg3M.js +25 -0
- package/build/factories/inertia_factory.d.ts +25 -0
- package/build/factories/main.js +144 -5
- package/build/headers-B-5pLwyD.js +77 -0
- package/build/index.js +3 -4
- package/build/inertia-ZqLiRJME.js +141 -0
- package/build/inertia_manager-BeqpMsuN.js +1770 -0
- package/build/providers/inertia_provider.js +69 -3
- package/build/src/client/helpers.js +28 -0
- package/build/src/client/react/index.js +144 -1
- package/build/src/client/vue/index.js +95 -1
- package/build/src/headers.d.ts +13 -0
- package/build/src/inertia.d.ts +58 -2
- package/build/src/inertia_middleware.d.ts +37 -1
- package/build/src/inertia_middleware.js +72 -5
- package/build/src/plugins/edge/plugin.js +122 -1
- package/build/src/plugins/japa/api_client.js +50 -1
- package/build/src/props.d.ts +118 -28
- package/build/src/symbols.d.ts +33 -0
- package/build/src/types.d.ts +398 -8
- package/build/tests/helpers.d.ts +26 -0
- package/build/tests/merges.spec.d.ts +1 -0
- package/build/tests/once_props.spec.d.ts +1 -0
- package/build/tests/rescued_deferred_props.spec.d.ts +1 -0
- package/build/tests/scroll.spec.d.ts +1 -0
- package/package.json +28 -26
- package/build/debug-CBMTuPUm.js +0 -3
- package/build/define_config-Dv9Dx2Yq.js +0 -56
- package/build/headers-DafWEpBh.js +0 -11
- package/build/inertia_manager-BdcjpKFf.js +0 -402
|
@@ -1,56 +0,0 @@
|
|
|
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: config.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
|
-
entrypoint: "inertia/ssr.tsx"
|
|
53
|
-
}
|
|
54
|
-
}, config);
|
|
55
|
-
}
|
|
56
|
-
export { indexPages as n, defineConfig as t };
|
|
@@ -1,11 +0,0 @@
|
|
|
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 };
|
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
import { t as InertiaHeaders } from "./headers-DafWEpBh.js";
|
|
2
|
-
import { t as debug_default } from "./debug-CBMTuPUm.js";
|
|
3
|
-
import "node:module";
|
|
4
|
-
import { createHash } from "node:crypto";
|
|
5
|
-
import { BaseSerializer } from "@adonisjs/core/transformers";
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __exportAll = (all, no_symbols) => {
|
|
8
|
-
let target = {};
|
|
9
|
-
for (var name in all) __defProp(target, name, {
|
|
10
|
-
get: all[name],
|
|
11
|
-
enumerable: true
|
|
12
|
-
});
|
|
13
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
var symbols_exports = /* @__PURE__ */ __exportAll({
|
|
17
|
-
ALWAYS_PROP: () => ALWAYS_PROP,
|
|
18
|
-
DEEP_MERGE: () => DEEP_MERGE,
|
|
19
|
-
DEFERRED_PROP: () => DEFERRED_PROP,
|
|
20
|
-
OPTIONAL_PROP: () => OPTIONAL_PROP,
|
|
21
|
-
TO_BE_MERGED: () => TO_BE_MERGED
|
|
22
|
-
});
|
|
23
|
-
const ALWAYS_PROP = Symbol.for("ALWAYS_PROP");
|
|
24
|
-
const OPTIONAL_PROP = Symbol.for("OPTIONAL_PROP");
|
|
25
|
-
const TO_BE_MERGED = Symbol.for("TO_BE_MERGED");
|
|
26
|
-
const DEFERRED_PROP = Symbol.for("DEFERRED_PROP");
|
|
27
|
-
const DEEP_MERGE = Symbol.for("DEEP_MERGE");
|
|
28
|
-
var InertiaSerializer = class extends BaseSerializer {
|
|
29
|
-
wrap = void 0;
|
|
30
|
-
definePaginationMetaData(metaData) {
|
|
31
|
-
return metaData;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const inertiaSerializer = new InertiaSerializer();
|
|
35
|
-
function isObject(value) {
|
|
36
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
37
|
-
}
|
|
38
|
-
function defer(fn, group = "default") {
|
|
39
|
-
return {
|
|
40
|
-
group,
|
|
41
|
-
compute: fn,
|
|
42
|
-
merge() {
|
|
43
|
-
return merge(this);
|
|
44
|
-
},
|
|
45
|
-
deepMerge() {
|
|
46
|
-
return deepMerge(this);
|
|
47
|
-
},
|
|
48
|
-
[DEFERRED_PROP]: true
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function optional(fn) {
|
|
52
|
-
return {
|
|
53
|
-
compute: fn,
|
|
54
|
-
[OPTIONAL_PROP]: true
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function always(value) {
|
|
58
|
-
return {
|
|
59
|
-
value,
|
|
60
|
-
[ALWAYS_PROP]: true
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function merge(value) {
|
|
64
|
-
return {
|
|
65
|
-
value,
|
|
66
|
-
[TO_BE_MERGED]: true,
|
|
67
|
-
[DEEP_MERGE]: false
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function deepMerge(value) {
|
|
71
|
-
return {
|
|
72
|
-
value,
|
|
73
|
-
[TO_BE_MERGED]: true,
|
|
74
|
-
[DEEP_MERGE]: true
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function isDeferredProp(propValue) {
|
|
78
|
-
return DEFERRED_PROP in propValue;
|
|
79
|
-
}
|
|
80
|
-
function isMergeableProp(propValue) {
|
|
81
|
-
return TO_BE_MERGED in propValue;
|
|
82
|
-
}
|
|
83
|
-
function isAlwaysProp(propValue) {
|
|
84
|
-
return ALWAYS_PROP in propValue;
|
|
85
|
-
}
|
|
86
|
-
function isOptionalProp(propValue) {
|
|
87
|
-
return OPTIONAL_PROP in propValue;
|
|
88
|
-
}
|
|
89
|
-
async function unpackPropValue(value, containerResolver) {
|
|
90
|
-
if (value === null) return null;
|
|
91
|
-
return inertiaSerializer.serialize(value, containerResolver);
|
|
92
|
-
}
|
|
93
|
-
async function buildStandardVisitProps(pageProps, containerResolver) {
|
|
94
|
-
const mergeProps = [];
|
|
95
|
-
const deepMergeProps = [];
|
|
96
|
-
const newProps = {};
|
|
97
|
-
const deferredProps = {};
|
|
98
|
-
const unpackedValues = [];
|
|
99
|
-
for (const [key, value] of Object.entries(pageProps)) if (isObject(value)) {
|
|
100
|
-
if (isDeferredProp(value)) {
|
|
101
|
-
deferredProps[value.group] = deferredProps[value.group] ?? [];
|
|
102
|
-
deferredProps[value.group].push(key);
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
if (isOptionalProp(value)) continue;
|
|
106
|
-
if (isAlwaysProp(value)) {
|
|
107
|
-
unpackedValues.push({
|
|
108
|
-
key,
|
|
109
|
-
value: value.value
|
|
110
|
-
});
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (isMergeableProp(value)) {
|
|
114
|
-
if (value[DEEP_MERGE]) deepMergeProps.push(key);
|
|
115
|
-
else mergeProps.push(key);
|
|
116
|
-
if (isObject(value.value) && isDeferredProp(value.value)) {
|
|
117
|
-
deferredProps[value.value.group] = deferredProps[value.value.group] ?? [];
|
|
118
|
-
deferredProps[value.value.group].push(key);
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
unpackedValues.push({
|
|
122
|
-
key,
|
|
123
|
-
value: value.value
|
|
124
|
-
});
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
unpackedValues.push({
|
|
128
|
-
key,
|
|
129
|
-
value
|
|
130
|
-
});
|
|
131
|
-
} else {
|
|
132
|
-
if (typeof value === "function") {
|
|
133
|
-
unpackedValues.push({
|
|
134
|
-
key,
|
|
135
|
-
value
|
|
136
|
-
});
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
newProps[key] = value;
|
|
140
|
-
}
|
|
141
|
-
await Promise.all(unpackedValues.map(async ({ key, value }) => {
|
|
142
|
-
if (typeof value === "function") return Promise.resolve(value()).then((r) => unpackPropValue(r, containerResolver)).then((jsonValue) => {
|
|
143
|
-
newProps[key] = jsonValue;
|
|
144
|
-
});
|
|
145
|
-
else return unpackPropValue(value, containerResolver).then((jsonValue) => {
|
|
146
|
-
newProps[key] = jsonValue;
|
|
147
|
-
});
|
|
148
|
-
}));
|
|
149
|
-
return {
|
|
150
|
-
props: newProps,
|
|
151
|
-
mergeProps,
|
|
152
|
-
deepMergeProps,
|
|
153
|
-
deferredProps
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
async function buildPartialRequestProps(pageProps, cherryPickProps, containerResolver) {
|
|
157
|
-
const mergeProps = [];
|
|
158
|
-
const deepMergeProps = [];
|
|
159
|
-
const newProps = {};
|
|
160
|
-
const unpackedValues = [];
|
|
161
|
-
for (const [key, value] of Object.entries(pageProps)) if (isObject(value)) {
|
|
162
|
-
if (isAlwaysProp(value)) {
|
|
163
|
-
unpackedValues.push({
|
|
164
|
-
key,
|
|
165
|
-
value: value.value
|
|
166
|
-
});
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
if (!cherryPickProps.includes(key)) continue;
|
|
170
|
-
if (isDeferredProp(value)) {
|
|
171
|
-
unpackedValues.push({
|
|
172
|
-
key,
|
|
173
|
-
value: value.compute
|
|
174
|
-
});
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
if (isOptionalProp(value)) {
|
|
178
|
-
unpackedValues.push({
|
|
179
|
-
key,
|
|
180
|
-
value: value.compute
|
|
181
|
-
});
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
if (isMergeableProp(value)) {
|
|
185
|
-
if (value[DEEP_MERGE]) deepMergeProps.push(key);
|
|
186
|
-
else mergeProps.push(key);
|
|
187
|
-
if (isObject(value.value) && isDeferredProp(value.value)) unpackedValues.push({
|
|
188
|
-
key,
|
|
189
|
-
value: value.value.compute
|
|
190
|
-
});
|
|
191
|
-
else unpackedValues.push({
|
|
192
|
-
key,
|
|
193
|
-
value: value.value
|
|
194
|
-
});
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
unpackedValues.push({
|
|
198
|
-
key,
|
|
199
|
-
value
|
|
200
|
-
});
|
|
201
|
-
} else {
|
|
202
|
-
if (!cherryPickProps.includes(key)) continue;
|
|
203
|
-
if (typeof value === "function") {
|
|
204
|
-
unpackedValues.push({
|
|
205
|
-
key,
|
|
206
|
-
value
|
|
207
|
-
});
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
newProps[key] = value;
|
|
211
|
-
}
|
|
212
|
-
await Promise.all(unpackedValues.map(async ({ key, value }) => {
|
|
213
|
-
if (typeof value === "function") return Promise.resolve(value()).then((r) => unpackPropValue(r, containerResolver)).then((jsonValue) => {
|
|
214
|
-
newProps[key] = jsonValue;
|
|
215
|
-
});
|
|
216
|
-
else return unpackPropValue(value, containerResolver).then((jsonValue) => {
|
|
217
|
-
newProps[key] = jsonValue;
|
|
218
|
-
});
|
|
219
|
-
}));
|
|
220
|
-
return {
|
|
221
|
-
props: newProps,
|
|
222
|
-
mergeProps,
|
|
223
|
-
deepMergeProps,
|
|
224
|
-
deferredProps: {}
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
var Inertia = class {
|
|
228
|
-
#sharedStateProviders;
|
|
229
|
-
#cachedRequestInfo;
|
|
230
|
-
#serverRenderer;
|
|
231
|
-
#vite;
|
|
232
|
-
#shouldClearHistory;
|
|
233
|
-
#shouldEncryptHistory;
|
|
234
|
-
#cachedVersion;
|
|
235
|
-
defer = defer;
|
|
236
|
-
always = always;
|
|
237
|
-
merge = merge;
|
|
238
|
-
optional = optional;
|
|
239
|
-
deepMerge = deepMerge;
|
|
240
|
-
constructor(ctx, config, vite, serverRenderer) {
|
|
241
|
-
this.ctx = ctx;
|
|
242
|
-
this.config = config;
|
|
243
|
-
if (debug_default.enabled) debug_default("instantiating inertia instance for request \"%s\" using config %O", ctx.request.url(), this.config);
|
|
244
|
-
this.#shouldClearHistory = false;
|
|
245
|
-
this.#vite = vite;
|
|
246
|
-
this.#serverRenderer = serverRenderer;
|
|
247
|
-
this.#shouldEncryptHistory = config.encryptHistory ?? false;
|
|
248
|
-
this.#cachedVersion = this.config.assetsVersion ? String(this.config.assetsVersion) : void 0;
|
|
249
|
-
}
|
|
250
|
-
#resolveRootView() {
|
|
251
|
-
return typeof this.config.rootView === "function" ? this.config.rootView(this.ctx) : this.config.rootView;
|
|
252
|
-
}
|
|
253
|
-
async #buildPageProps(component, requestInfo, pageProps) {
|
|
254
|
-
let finalProps;
|
|
255
|
-
if (this.#sharedStateProviders) finalProps = {
|
|
256
|
-
...await Promise.all(this.#sharedStateProviders.map((provider) => {
|
|
257
|
-
return typeof provider === "function" ? provider() : provider;
|
|
258
|
-
})).then((resolvedSharedState) => {
|
|
259
|
-
return resolvedSharedState.reduce((result, state) => {
|
|
260
|
-
return {
|
|
261
|
-
...result,
|
|
262
|
-
...state
|
|
263
|
-
};
|
|
264
|
-
}, {});
|
|
265
|
-
}),
|
|
266
|
-
...pageProps
|
|
267
|
-
};
|
|
268
|
-
else finalProps = { ...pageProps };
|
|
269
|
-
if (requestInfo.partialComponent === component) {
|
|
270
|
-
const only = requestInfo.onlyProps;
|
|
271
|
-
const except = requestInfo.exceptProps ?? [];
|
|
272
|
-
const cherryPickProps = Object.keys(finalProps).filter((propName) => {
|
|
273
|
-
if (only) return only.includes(propName) && !except.includes(propName);
|
|
274
|
-
return !except.includes(propName);
|
|
275
|
-
});
|
|
276
|
-
debug_default("building props for a partial reload %O", requestInfo);
|
|
277
|
-
debug_default("cherry picking props %s", cherryPickProps);
|
|
278
|
-
return buildPartialRequestProps(finalProps, cherryPickProps, this.ctx.containerResolver);
|
|
279
|
-
}
|
|
280
|
-
debug_default("building props for a standard visit %O", requestInfo);
|
|
281
|
-
return buildStandardVisitProps(finalProps, this.ctx.containerResolver);
|
|
282
|
-
}
|
|
283
|
-
#handleInertiaRequest(pageObject) {
|
|
284
|
-
this.ctx.response.header(InertiaHeaders.Inertia, "true");
|
|
285
|
-
return pageObject;
|
|
286
|
-
}
|
|
287
|
-
async #renderWithSSR(pageObject, viewProps) {
|
|
288
|
-
if (!this.#serverRenderer) throw new Error("Cannot server render pages without a server renderer");
|
|
289
|
-
debug_default("server-side rendering %O", pageObject);
|
|
290
|
-
const { head, body } = await this.#serverRenderer.render(pageObject);
|
|
291
|
-
return this.ctx.view.render(this.#resolveRootView(), {
|
|
292
|
-
page: {
|
|
293
|
-
ssrHead: head,
|
|
294
|
-
ssrBody: body,
|
|
295
|
-
...pageObject
|
|
296
|
-
},
|
|
297
|
-
...viewProps
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
async #renderClientSide(pageObject, viewProps) {
|
|
301
|
-
debug_default("rendering shell for SPA %O", pageObject);
|
|
302
|
-
return this.ctx.view.render(this.#resolveRootView(), {
|
|
303
|
-
page: pageObject,
|
|
304
|
-
...viewProps
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
requestInfo(reCompute) {
|
|
308
|
-
if (reCompute) this.#cachedRequestInfo = void 0;
|
|
309
|
-
this.#cachedRequestInfo = this.#cachedRequestInfo ?? {
|
|
310
|
-
version: this.ctx.request.header(InertiaHeaders.Version),
|
|
311
|
-
isInertiaRequest: !!this.ctx.request.header(InertiaHeaders.Inertia),
|
|
312
|
-
isPartialRequest: !!this.ctx.request.header(InertiaHeaders.PartialComponent),
|
|
313
|
-
partialComponent: this.ctx.request.header(InertiaHeaders.PartialComponent),
|
|
314
|
-
onlyProps: this.ctx.request.header(InertiaHeaders.PartialOnly)?.split(","),
|
|
315
|
-
exceptProps: this.ctx.request.header(InertiaHeaders.PartialExcept)?.split(","),
|
|
316
|
-
resetProps: this.ctx.request.header(InertiaHeaders.Reset)?.split(","),
|
|
317
|
-
errorBag: this.ctx.request.header(InertiaHeaders.ErrorBag)
|
|
318
|
-
};
|
|
319
|
-
return this.#cachedRequestInfo;
|
|
320
|
-
}
|
|
321
|
-
getVersion() {
|
|
322
|
-
if (this.#cachedVersion) return this.#cachedVersion;
|
|
323
|
-
if (this.#vite?.hasManifestFile) this.#cachedVersion = createHash("md5").update(JSON.stringify(this.#vite.manifest())).digest("hex");
|
|
324
|
-
else this.#cachedVersion = "1";
|
|
325
|
-
return this.#cachedVersion;
|
|
326
|
-
}
|
|
327
|
-
async ssrEnabled(component) {
|
|
328
|
-
if (!this.config.ssr.enabled) return false;
|
|
329
|
-
if (typeof this.config.ssr.pages === "function") return this.config.ssr.pages(this.ctx, component);
|
|
330
|
-
if (this.config.ssr.pages) return this.config.ssr.pages?.includes(component);
|
|
331
|
-
return true;
|
|
332
|
-
}
|
|
333
|
-
share(sharedState) {
|
|
334
|
-
if (!this.#sharedStateProviders) this.#sharedStateProviders = [];
|
|
335
|
-
this.#sharedStateProviders.push(sharedState);
|
|
336
|
-
return this;
|
|
337
|
-
}
|
|
338
|
-
async page(page, pageProps) {
|
|
339
|
-
const requestInfo = this.requestInfo();
|
|
340
|
-
const { props, mergeProps, deferredProps, deepMergeProps } = await this.#buildPageProps(page, requestInfo, pageProps);
|
|
341
|
-
const pageObject = {
|
|
342
|
-
component: page,
|
|
343
|
-
url: this.ctx.request.url(true),
|
|
344
|
-
version: this.getVersion(),
|
|
345
|
-
props,
|
|
346
|
-
deferredProps,
|
|
347
|
-
mergeProps,
|
|
348
|
-
deepMergeProps
|
|
349
|
-
};
|
|
350
|
-
if (this.#shouldClearHistory) pageObject.clearHistory = true;
|
|
351
|
-
if (this.#shouldEncryptHistory) pageObject.encryptHistory = true;
|
|
352
|
-
return pageObject;
|
|
353
|
-
}
|
|
354
|
-
async render(page, pageProps, viewProps) {
|
|
355
|
-
const requestInfo = this.requestInfo();
|
|
356
|
-
const pageObject = await this.page(page, pageProps);
|
|
357
|
-
if (requestInfo.isInertiaRequest) return this.#handleInertiaRequest(pageObject);
|
|
358
|
-
if (await this.ssrEnabled(page)) return this.#renderWithSSR(pageObject, viewProps);
|
|
359
|
-
return this.#renderClientSide(pageObject, viewProps);
|
|
360
|
-
}
|
|
361
|
-
clearHistory() {
|
|
362
|
-
this.#shouldClearHistory = true;
|
|
363
|
-
}
|
|
364
|
-
encryptHistory(encrypt = true) {
|
|
365
|
-
this.#shouldEncryptHistory = encrypt;
|
|
366
|
-
}
|
|
367
|
-
location(url) {
|
|
368
|
-
this.ctx.response.header(InertiaHeaders.Location, url);
|
|
369
|
-
this.ctx.response.status(409);
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
var ServerRenderer = class {
|
|
373
|
-
#config;
|
|
374
|
-
#vite;
|
|
375
|
-
constructor(config, vite) {
|
|
376
|
-
this.#config = config;
|
|
377
|
-
this.#vite = vite;
|
|
378
|
-
}
|
|
379
|
-
async render(pageObject) {
|
|
380
|
-
debug_default("rendering page through SSR entrypoint %s", this.#config.ssr.entrypoint);
|
|
381
|
-
const result = await (await this.#vite.loadServerModule(this.#config.ssr.entrypoint)).default(pageObject);
|
|
382
|
-
debug_default("SSR bundle %o", result);
|
|
383
|
-
return {
|
|
384
|
-
head: result.head,
|
|
385
|
-
body: result.body
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
var InertiaManager = class {
|
|
390
|
-
#vite;
|
|
391
|
-
#config;
|
|
392
|
-
#serverRenderer;
|
|
393
|
-
constructor(config, vite) {
|
|
394
|
-
this.#config = config;
|
|
395
|
-
this.#vite = vite;
|
|
396
|
-
this.#serverRenderer = this.#vite ? new ServerRenderer(this.#config, this.#vite) : void 0;
|
|
397
|
-
}
|
|
398
|
-
createForRequest(ctx) {
|
|
399
|
-
return new Inertia(ctx, this.#config, this.#vite, this.#serverRenderer);
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
export { symbols_exports as i, ServerRenderer as n, Inertia as r, InertiaManager as t };
|