litestar-vite-plugin 0.6.5 → 0.6.7
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.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T>;
|
|
2
|
-
export declare function route(routeName: string,
|
|
2
|
+
export declare function route(routeName: string, options?: {
|
|
3
|
+
relativeUrl?: boolean;
|
|
4
|
+
}, ...args: any[]): string;
|
|
3
5
|
export declare function getRelativeUrlPath(url: string): string;
|
|
4
6
|
export declare function toRoute(url: string): string | null;
|
|
5
7
|
export declare function currentRoute(): string | null;
|
package/inertia-helpers/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export async function resolvePageComponent(path, pages) {
|
|
|
9
9
|
}
|
|
10
10
|
throw new Error(`Page not found: ${path}`);
|
|
11
11
|
}
|
|
12
|
-
export function route(routeName, ...args) {
|
|
12
|
+
export function route(routeName, options = {}, ...args) {
|
|
13
13
|
let url = globalThis.routes[routeName];
|
|
14
14
|
if (!url) {
|
|
15
15
|
console.error(`URL '${routeName}' not found in routes.`);
|
|
@@ -51,7 +51,11 @@ export function route(routeName, ...args) {
|
|
|
51
51
|
console.error(error.message);
|
|
52
52
|
return "#";
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
if (options.relativeUrl) {
|
|
55
|
+
return url;
|
|
56
|
+
}
|
|
57
|
+
const fullUrl = new URL(url, window.location.origin);
|
|
58
|
+
return fullUrl.href;
|
|
55
59
|
}
|
|
56
60
|
export function getRelativeUrlPath(url) {
|
|
57
61
|
try {
|
|
@@ -63,6 +67,9 @@ export function getRelativeUrlPath(url) {
|
|
|
63
67
|
return url;
|
|
64
68
|
}
|
|
65
69
|
}
|
|
70
|
+
function routePatternToRegex(pattern) {
|
|
71
|
+
return new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
|
|
72
|
+
}
|
|
66
73
|
export function toRoute(url) {
|
|
67
74
|
url = getRelativeUrlPath(url);
|
|
68
75
|
url = url === '/' ? url : url.replace(/\/$/, '');
|
|
@@ -94,7 +101,7 @@ export function currentRoute() {
|
|
|
94
101
|
export function isRoute(url, routeName) {
|
|
95
102
|
url = getRelativeUrlPath(url);
|
|
96
103
|
url = url === '/' ? url : url.replace(/\/$/, '');
|
|
97
|
-
const routeNameRegex =
|
|
104
|
+
const routeNameRegex = routePatternToRegex(routeName);
|
|
98
105
|
for (const routeName in routes) {
|
|
99
106
|
if (routeNameRegex.test(routeName)) {
|
|
100
107
|
const routePattern = routes[routeName];
|
|
@@ -123,7 +130,7 @@ export function isCurrentRoute(routeName) {
|
|
|
123
130
|
console.error("Could not match current window location to a named route.");
|
|
124
131
|
return false;
|
|
125
132
|
}
|
|
126
|
-
const routeNameRegex =
|
|
133
|
+
const routeNameRegex = routePatternToRegex(routeName);
|
|
127
134
|
return routeNameRegex.test(currentRouteName);
|
|
128
135
|
}
|
|
129
136
|
globalThis.routes = globalThis.routes || {};
|