litestar-vite-plugin 0.6.4 → 0.6.5
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/inertia-helpers/index.js +22 -20
- package/package.json +1 -1
package/inertia-helpers/index.js
CHANGED
|
@@ -94,27 +94,28 @@ export function currentRoute() {
|
|
|
94
94
|
export function isRoute(url, routeName) {
|
|
95
95
|
url = getRelativeUrlPath(url);
|
|
96
96
|
url = url === '/' ? url : url.replace(/\/$/, '');
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
97
|
+
const routeNameRegex = new RegExp('^' + routeName.replace(/\*/g, '.*') + '$');
|
|
98
|
+
for (const routeName in routes) {
|
|
99
|
+
if (routeNameRegex.test(routeName)) {
|
|
100
|
+
const routePattern = routes[routeName];
|
|
101
|
+
const regexPattern = routePattern.replace(/\//g, '\\/').replace(/\{([^}]+):([^}]+)\}/g, (match, paramName, paramType) => {
|
|
102
|
+
switch (paramType) {
|
|
103
|
+
case 'str':
|
|
104
|
+
case 'path':
|
|
105
|
+
return '([^/]+)';
|
|
106
|
+
case 'uuid':
|
|
107
|
+
return '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
|
|
108
|
+
default:
|
|
109
|
+
return '([^/]+)';
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
113
|
+
if (regex.test(url)) {
|
|
114
|
+
return true;
|
|
109
115
|
}
|
|
110
|
-
}
|
|
111
|
-
const regex = new RegExp(`^${regexPattern}$`);
|
|
112
|
-
return regex.test(url);
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
console.error(error);
|
|
116
|
-
return false;
|
|
116
|
+
}
|
|
117
117
|
}
|
|
118
|
+
return false;
|
|
118
119
|
}
|
|
119
120
|
export function isCurrentRoute(routeName) {
|
|
120
121
|
const currentRouteName = currentRoute();
|
|
@@ -122,7 +123,8 @@ export function isCurrentRoute(routeName) {
|
|
|
122
123
|
console.error("Could not match current window location to a named route.");
|
|
123
124
|
return false;
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
+
const routeNameRegex = new RegExp('^' + routeName.replace(/\*/g, '.*') + '$');
|
|
127
|
+
return routeNameRegex.test(currentRouteName);
|
|
126
128
|
}
|
|
127
129
|
globalThis.routes = globalThis.routes || {};
|
|
128
130
|
globalThis.route = route;
|