litestar-vite-plugin 0.21.0 → 0.22.0
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.
|
@@ -25,26 +25,40 @@ export declare function unwrapPageProps<T extends Record<string, unknown>>(props
|
|
|
25
25
|
* Resolve a page component from a glob import.
|
|
26
26
|
*
|
|
27
27
|
* Used with Inertia.js to dynamically import page components.
|
|
28
|
-
* Automatically unwraps Litestar's `content` prop for ergonomic access
|
|
28
|
+
* Automatically unwraps Litestar's `content` prop for ergonomic access
|
|
29
|
+
* and extracts the default export from ES modules.
|
|
29
30
|
*
|
|
30
31
|
* @param path - Component path or array of paths to try
|
|
31
32
|
* @param pages - Glob import result (e.g., import.meta.glob('./pages/**\/*.vue'))
|
|
32
|
-
* @returns Promise resolving to the component
|
|
33
|
+
* @returns Promise resolving to the component (default export extracted when present)
|
|
33
34
|
* @throws Error if no matching component is found
|
|
34
35
|
*
|
|
35
36
|
* @example
|
|
36
37
|
* ```ts
|
|
37
38
|
* import { resolvePageComponent } from 'litestar-vite-plugin/inertia-helpers'
|
|
38
39
|
*
|
|
40
|
+
* // React — type the glob with the module shape to get proper inference:
|
|
41
|
+
* const pages = import.meta.glob<{ default: ComponentType }>("./pages/**\/*.tsx")
|
|
42
|
+
* createInertiaApp({
|
|
43
|
+
* resolve: (name) => resolvePageComponent(`./pages/${name}.tsx`, pages),
|
|
44
|
+
* // ...
|
|
45
|
+
* })
|
|
46
|
+
*
|
|
47
|
+
* // Vue — type the glob with the component type directly:
|
|
39
48
|
* createInertiaApp({
|
|
40
49
|
* resolve: (name) => resolvePageComponent(
|
|
41
50
|
* `./pages/${name}.vue`,
|
|
42
|
-
* import.meta.glob('./pages/**\/*.vue')
|
|
51
|
+
* import.meta.glob<DefineComponent>('./pages/**\/*.vue')
|
|
43
52
|
* ),
|
|
44
53
|
* // ...
|
|
45
54
|
* })
|
|
46
55
|
* ```
|
|
47
56
|
*/
|
|
57
|
+
export declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<{
|
|
58
|
+
default: T;
|
|
59
|
+
}> | (() => Promise<{
|
|
60
|
+
default: T;
|
|
61
|
+
}>)>): Promise<T>;
|
|
48
62
|
export declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T>;
|
|
49
63
|
/**
|
|
50
64
|
* Offset-based pagination props.
|
|
@@ -52,30 +52,6 @@ function wrapComponent(module) {
|
|
|
52
52
|
}
|
|
53
53
|
return module;
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Resolve a page component from a glob import.
|
|
57
|
-
*
|
|
58
|
-
* Used with Inertia.js to dynamically import page components.
|
|
59
|
-
* Automatically unwraps Litestar's `content` prop for ergonomic access.
|
|
60
|
-
*
|
|
61
|
-
* @param path - Component path or array of paths to try
|
|
62
|
-
* @param pages - Glob import result (e.g., import.meta.glob('./pages/**\/*.vue'))
|
|
63
|
-
* @returns Promise resolving to the component
|
|
64
|
-
* @throws Error if no matching component is found
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* import { resolvePageComponent } from 'litestar-vite-plugin/inertia-helpers'
|
|
69
|
-
*
|
|
70
|
-
* createInertiaApp({
|
|
71
|
-
* resolve: (name) => resolvePageComponent(
|
|
72
|
-
* `./pages/${name}.vue`,
|
|
73
|
-
* import.meta.glob('./pages/**\/*.vue')
|
|
74
|
-
* ),
|
|
75
|
-
* // ...
|
|
76
|
-
* })
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
55
|
export async function resolvePageComponent(path, pages) {
|
|
80
56
|
for (const p of Array.isArray(path) ? path : [path]) {
|
|
81
57
|
const page = pages[p];
|
|
@@ -83,7 +59,11 @@ export async function resolvePageComponent(path, pages) {
|
|
|
83
59
|
continue;
|
|
84
60
|
}
|
|
85
61
|
const resolved = typeof page === "function" ? await page() : await page;
|
|
86
|
-
|
|
62
|
+
const wrapped = wrapComponent(resolved);
|
|
63
|
+
if (wrapped != null && typeof wrapped === "object" && "default" in wrapped) {
|
|
64
|
+
return wrapped.default;
|
|
65
|
+
}
|
|
66
|
+
return wrapped;
|
|
87
67
|
}
|
|
88
68
|
throw new Error(`Page not found: ${path}`);
|
|
89
69
|
}
|