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