@yoamigo.com/core 0.4.7 → 1.0.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.
package/dist/router.js CHANGED
@@ -137,13 +137,86 @@ function ScrollRestoration() {
137
137
  }
138
138
 
139
139
  // src/router/index.ts
140
- import { Route, Switch, useParams } from "wouter";
140
+ import { Route, Switch, useParams, useLocation as useLocation3 } from "wouter";
141
+
142
+ // src/router/route-utils.ts
143
+ function filePathToRoutePath(filePath, options = {}) {
144
+ const {
145
+ pagesDir = "/src/pages",
146
+ extensions = [".tsx", ".ts", ".jsx", ".js"]
147
+ } = options;
148
+ let path = filePath;
149
+ if (path.startsWith(pagesDir)) {
150
+ path = path.slice(pagesDir.length);
151
+ }
152
+ for (const ext of extensions) {
153
+ if (path.endsWith(ext)) {
154
+ path = path.slice(0, -ext.length);
155
+ break;
156
+ }
157
+ }
158
+ if (path.endsWith("/index")) {
159
+ path = path.slice(0, -6) || "/";
160
+ }
161
+ path = path.replace(/\[\.\.\.([^\]]+)\]/g, ":$1*");
162
+ path = path.replace(/\[([^\]]+)\]/g, ":$1");
163
+ if (!path.startsWith("/")) {
164
+ path = "/" + path;
165
+ }
166
+ if (path === "" || path === "/index") {
167
+ return "/";
168
+ }
169
+ return path;
170
+ }
171
+ function extractRouteParams(filePath) {
172
+ const matches = filePath.matchAll(/\[\.\.\.([^\]]+)\]|\[([^\]]+)\]/g);
173
+ const params = [];
174
+ for (const match of matches) {
175
+ params.push(match[1] || match[2]);
176
+ }
177
+ return params;
178
+ }
179
+ function createRouteDefinition(filePath, options) {
180
+ const path = filePathToRoutePath(filePath, options);
181
+ const params = extractRouteParams(filePath);
182
+ return {
183
+ path,
184
+ filePath,
185
+ params,
186
+ isDynamic: params.length > 0
187
+ };
188
+ }
189
+ function sortRoutesBySpecificity(routes) {
190
+ return [...routes].sort((a, b) => {
191
+ if (!a.isDynamic && b.isDynamic) return -1;
192
+ if (a.isDynamic && !b.isDynamic) return 1;
193
+ const aSegments = a.path.split("/").filter(Boolean);
194
+ const bSegments = b.path.split("/").filter(Boolean);
195
+ if (aSegments.length !== bSegments.length) {
196
+ return bSegments.length - aSegments.length;
197
+ }
198
+ return a.params.length - b.params.length;
199
+ });
200
+ }
201
+ function generatePath(routePath, params) {
202
+ let path = routePath;
203
+ for (const [key, value] of Object.entries(params)) {
204
+ path = path.replace(new RegExp(`:${key}\\*?`, "g"), encodeURIComponent(value));
205
+ }
206
+ return path;
207
+ }
141
208
  export {
142
209
  Link,
143
210
  Route,
144
211
  Router,
145
212
  ScrollRestoration,
146
213
  Switch,
214
+ createRouteDefinition,
215
+ extractRouteParams,
216
+ filePathToRoutePath,
217
+ generatePath,
218
+ sortRoutesBySpecificity,
219
+ useLocation3 as useLocation,
147
220
  useNavigate,
148
221
  useParams
149
222
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoamigo.com/core",
3
- "version": "0.4.7",
3
+ "version": "1.0.0",
4
4
  "description": "Core components, router, and utilities for YoAmigo templates",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1,6 +0,0 @@
1
- /**
2
- * Initialize builder selection when running in iframe
3
- */
4
- declare function initBuilderSelection(): void;
5
-
6
- export { initBuilderSelection as i };