@vaadin/hilla-file-router 24.6.4 → 24.7.0-alpha10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/hilla-file-router",
3
- "version": "24.6.4",
3
+ "version": "24.7.0-alpha10",
4
4
  "description": "Hilla file-based router",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -26,8 +26,9 @@
26
26
  "build:copy": "cd src && copyfiles *.d.ts **/*.d.ts ..",
27
27
  "lint": "eslint src test",
28
28
  "lint:fix": "eslint src test --fix",
29
- "test": "mocha test/**/*.spec.{ts,tsx} --config ../../../.mocharc.cjs",
30
- "test:coverage": "c8 --experimental-monocart -c ../../../.c8rc.json npm test",
29
+ "test": "vitest --run",
30
+ "test:coverage": "vitest --run --coverage",
31
+ "test:watch": "vitest",
31
32
  "typecheck": "tsc --noEmit"
32
33
  },
33
34
  "exports": {
@@ -57,37 +58,14 @@
57
58
  "access": "public"
58
59
  },
59
60
  "peerDependencies": {
60
- "react": "^18.2.0",
61
- "react-dom": "^18.2.0",
62
- "react-router-dom": "^6.28.0"
63
- },
64
- "devDependencies": {
65
- "@types/chai-as-promised": "^7.1.8",
66
- "@types/chai-fs": "^2.0.4",
67
- "@types/chai-like": "^1.1.3",
68
- "@types/deep-equal-in-any-order": "^1.0.3",
69
- "@types/mocha": "^10.0.6",
70
- "@types/sinon": "^10.0.17",
71
- "@types/sinon-chai": "^3.2.12",
72
- "chai": "^5.1.2",
73
- "chai-as-promised": "^7.1.2",
74
- "chai-deep-equal-ignore-undefined": "^1.1.1",
75
- "chai-fs": "^2.0.0",
76
- "chai-like": "^1.1.1",
77
- "deep-equal-in-any-order": "^2.0.6",
78
- "mocha": "^10.2.0",
79
- "sinon": "^16.0.0",
80
- "sinon-chai": "^3.7.0",
81
- "type-fest": "^4.9.0"
61
+ "react": "18 || 19",
62
+ "react-dom": "18 || 19",
63
+ "react-router": "7"
82
64
  },
83
65
  "dependencies": {
84
- "@types/chai": "^5.0.1",
85
- "@vaadin/hilla-generator-utils": "24.6.4",
86
- "@vaadin/hilla-react-auth": "24.6.4",
87
- "@vaadin/hilla-react-signals": "24.6.4",
88
- "react": "^18.2.0",
89
- "rollup": "^4.12.0",
90
- "c8": "^10.1.3",
91
- "typescript": "5.7.2"
66
+ "@vaadin/hilla-generator-utils": "24.7.0-alpha10",
67
+ "@vaadin/hilla-react-auth": "24.7.0-alpha10",
68
+ "@vaadin/hilla-react-signals": "24.7.0-alpha10",
69
+ "typescript": "5.7.3"
92
70
  }
93
71
  }
@@ -1,5 +1,5 @@
1
1
  import { type ComponentType } from 'react';
2
- import { type RouteObject } from 'react-router-dom';
2
+ import { type RouteObject } from 'react-router';
3
3
  import type { AgnosticRoute, RouterBuildOptions, RouterConfiguration, ViewConfig } from '../types.js';
4
4
  interface RouteBase {
5
5
  path?: string;
@@ -66,7 +66,7 @@ export declare class RouterConfigurationBuilder {
66
66
  * @param routes - A list of routes to merge with the current list.
67
67
  * @param callback - A callback to transform the routes during the merge.
68
68
  */
69
- update<T extends RouteBase>(routes: undefined, callback: RouteTransformer<undefined>): this;
69
+ update(routes: undefined, callback: RouteTransformer<undefined>): this;
70
70
  update<T extends RouteBase>(routes: readonly T[], callback?: RouteTransformer<T>): this;
71
71
  /**
72
72
  * Builds the router with the current list of routes.
@@ -1 +1 @@
1
- {"version":3,"file":"RouterConfigurationBuilder.d.ts","sourceRoot":"","sources":["../src/runtime/RouterConfigurationBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,OAAO,CAAC;AAC1D,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EACV,aAAa,EAGb,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,UAAU,SAAS;IACjB,IAAI,CAAC,EAAE,MA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AAa,GAAG,IAAI;IA+FhD;;;;;;OAMG;IACH,OAAO,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAUpC;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,gBAAgB,CAAC,SAAS,CAAC,GAAG,IAAI;IACtE,MAAM,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI;IAuHvF;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,mBAAmB;CAsFzD"}
@@ -1,8 +1,6 @@
1
1
  import { protectRoute } from "@vaadin/hilla-react-auth";
2
2
  import { createElement } from "react";
3
- import {
4
- createBrowserRouter
5
- } from "react-router-dom";
3
+ import { createBrowserRouter } from "react-router";
6
4
  import { convertComponentNameToTitle } from "../shared/convertComponentNameToTitle.js";
7
5
  import { transformTree } from "../shared/transformTree.js";
8
6
  function isReactRouteModule(module) {
@@ -289,22 +287,7 @@ class RouterConfigurationBuilder {
289
287
  const routes = this.#modifiers.reduce((acc, mod) => mod(acc) ?? acc, void 0) ?? [];
290
288
  return {
291
289
  routes,
292
- router: createBrowserRouter([...routes], {
293
- basename: new URL(document.baseURI).pathname,
294
- future: {
295
- // eslint-disable-next-line camelcase
296
- v7_fetcherPersist: true,
297
- // eslint-disable-next-line camelcase
298
- v7_normalizeFormMethod: true,
299
- // eslint-disable-next-line camelcase
300
- v7_partialHydration: true,
301
- // eslint-disable-next-line camelcase
302
- v7_relativeSplatPath: true,
303
- // eslint-disable-next-line camelcase
304
- v7_skipActionErrorRevalidation: true
305
- },
306
- ...options
307
- })
290
+ router: createBrowserRouter([...routes], { basename: new URL(document.baseURI).pathname, ...options })
308
291
  };
309
292
  }
310
293
  #withLayoutSkipping() {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/runtime/RouterConfigurationBuilder.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/consistent-type-assertions */\nimport { protectRoute } from '@vaadin/hilla-react-auth';\nimport { type ComponentType, createElement } from 'react';\nimport {\n createBrowserRouter,\n type IndexRouteObject,\n type NonIndexRouteObject,\n type RouteObject,\n} from 'react-router-dom';\nimport { convertComponentNameToTitle } from '../shared/convertComponentNameToTitle.js';\nimport { transformTree } from '../shared/transformTree.js';\nimport type {\n AgnosticRoute,\n Module,\n RouteModule,\n RouterBuildOptions,\n RouterConfiguration,\n ViewConfig,\n} from '../types.js';\n\ninterface RouteBase {\n path?: string;\n children?: readonly this[];\n}\n\nfunction isReactRouteModule(module?: Module): module is RouteModule<ComponentType> | undefined {\n if (!module) {\n return true;\n }\n\n return (\n ('default' in module && typeof module.default === 'function') ||\n ('config' in module && typeof module.config === 'object')\n );\n}\n\nexport type RouteList = readonly RouteObject[];\nexport type WritableRouteList = RouteObject[];\n\nexport type RouteTransformerOptions<T> = Readonly<{\n children?: RouteList;\n original?: RouteObject;\n overriding?: T;\n dupe: boolean;\n}>;\n\nexport type RouteTransformer<T> = (opts: RouteTransformerOptions<T>) => RouteObject | undefined;\n\ntype RoutesModifier = (routes: RouteList | undefined) => RouteList | undefined;\n\nfunction createRouteKey<T extends RouteBase>(route: T): string {\n return `${route.path ?? ''}-${route.children ? 'n' : 'i'}`;\n}\n\nenum RouteHandleFlags {\n FLOW_LAYOUT = 'flowLayout',\n IGNORE_FALLBACK = 'ignoreFallback',\n SKIP_LAYOUTS = 'skipLayouts',\n}\n\nfunction getRouteHandleFlag<T extends RouteHandleFlags>(route: RouteObject, flag: T): boolean | undefined {\n if (typeof route.handle === 'object' && flag in route.handle) {\n return (route.handle as Record<T, boolean>)[flag];\n }\n\n return undefined;\n}\n\n/**\n * A builder for creating a Vaadin-specific router for React with\n * authentication and server routes support.\n */\nexport class RouterConfigurationBuilder {\n readonly #modifiers: RoutesModifier[] = [];\n\n /**\n * Adds the given routes to the current list of routes. All the routes are\n * deeply merged to preserve the path uniqueness.\n *\n * @param routes - A list of routes to add to the current list.\n */\n withReactRoutes(routes: RouteList): this {\n return this.update(routes);\n }\n\n /**\n * Adds the given file routes to the current list of routes. All the routes\n * are transformed to React RouterObjects and deeply merged to preserve the\n * path uniqueness.\n *\n * @param routes - A list of routes to add to the current list.\n */\n withFileRoutes(routes: readonly AgnosticRoute[]): this {\n return this.update(routes, ({ original, overriding: added, children }) => {\n if (added) {\n const { module, path, flowLayout } = added;\n if (!isReactRouteModule(module)) {\n throw new Error(\n `The module for the \"${path}\" section doesn't have the React component exported by default or a ViewConfig object exported as \"config\"`,\n );\n }\n\n const element = module?.default ? createElement(module.default) : undefined;\n const handle = {\n ...module?.config,\n title: module?.config?.title ?? convertComponentNameToTitle(module?.default),\n flowLayout: module?.config?.flowLayout ?? flowLayout,\n };\n\n if (path === '' && !children) {\n return {\n ...original,\n element,\n handle,\n index: true,\n } as IndexRouteObject;\n }\n\n return {\n ...original,\n path: module?.config?.route ?? path,\n element,\n children,\n handle,\n } as NonIndexRouteObject;\n }\n\n return original;\n });\n }\n\n /**\n * Adds the given server route element to each branch of the current list of\n * routes.\n *\n * @param component - The React component to add to each branch of the\n * current list of routes.\n * @param config - An optional configuration that will be applied to\n * each fallback component.\n */\n withFallback(component: ComponentType, config?: ViewConfig): this {\n this.withLayout(component);\n\n // Fallback adds two routes, so that the index (empty path) has a fallback too\n const fallbackRoutes: RouteList = [\n { path: '*', element: createElement(component), handle: config },\n { index: true, element: createElement(component), handle: config },\n ];\n\n this.update(fallbackRoutes, ({ original, overriding: added, children, dupe }) => {\n if (original && !getRouteHandleFlag(original, RouteHandleFlags.IGNORE_FALLBACK) && !dupe) {\n if (!children) {\n return original;\n }\n\n const _fallback = [...fallbackRoutes];\n\n if (children.some(({ path }) => path === '*')) {\n _fallback.shift();\n }\n\n if (children.some(({ index: i, path }) => i ?? path?.includes('?'))) {\n _fallback.pop();\n }\n\n return {\n ...original,\n children: [...children, ..._fallback],\n } as RouteObject;\n }\n\n return added!;\n });\n\n return this;\n }\n\n /**\n * Adds the layoutComponent as the parent layout to views with the flowLayouts ViewConfiguration set.\n *\n * @param layoutComponent - layout component to use, usually Flow\n */\n withLayout(layoutComponent: ComponentType): this {\n this.#modifiers.push((originalRoutes) => {\n if (!originalRoutes) {\n return originalRoutes;\n }\n\n type Accumulator<T extends RouteList> = Readonly<{\n server: T;\n client: T;\n ambivalent: T;\n }>;\n\n const result = transformTree<RouteList, Accumulator<RouteList>>(originalRoutes, null, (routes, next) =>\n // Split a single routes list onto three separate lists:\n // - A list of server routes\n // - A list of client routes\n // - A list of routes which will be moved to either server or client\n // list. It depends on the parent route.\n routes.reduce<Accumulator<WritableRouteList>>(\n (lists, route) => {\n const { server, client, ambivalent } = next(route.children ?? []);\n\n const flag = getRouteHandleFlag(route, RouteHandleFlags.FLOW_LAYOUT);\n\n // If the route has `flowLayout` flag explicitly enabled, it goes to\n // the server list. The children are also affected by the flag\n // unless they have it explicitly disabled.\n if (flag === true) {\n lists.server.push({\n ...route,\n children: server.length + ambivalent.length > 0 ? [...server, ...ambivalent] : undefined,\n } as RouteObject);\n } else if (server.length > 0) {\n // Even if the route doesn't have the flag, it goes to the server\n // list if any of the children has the flag enabled.\n lists.server.push({\n ...route,\n children: server,\n } as RouteObject);\n }\n\n // If the route has `flowLayout` flag explicitly disabled, it goes\n // to the client list. The route children are not affected by the\n // flag.\n if (flag === false || client.length > 0) {\n lists.client.push({\n ...route,\n children: client.length > 0 ? client : undefined,\n } as RouteObject);\n }\n\n // The route without the flag go to the `default` list. Then it will\n // be moved to either server or client list based on the parent\n // route.\n if (\n flag === undefined &&\n (lists.server.every(({ path }) => path !== route.path) || ambivalent.length > 0)\n ) {\n lists.ambivalent.push({\n ...route,\n children: ambivalent.length > 0 ? ambivalent : undefined,\n } as RouteObject);\n }\n\n return lists;\n },\n { server: [], client: [], ambivalent: [] },\n ),\n );\n\n return [\n ...(result.server.length\n ? [\n // The server routes are wrapped with the route that has a layout\n // element. It also has the `IGNORE_FALLBACK` flag to remove the\n // fallback route from reach.\n {\n element: createElement(layoutComponent),\n children: result.server as RouteObject[],\n handle: {\n [RouteHandleFlags.IGNORE_FALLBACK]: true,\n },\n },\n ]\n : []),\n // The client routes are preserved without wrapping.\n ...result.client,\n // The ambivalent routes are considered as client routes.\n ...result.ambivalent,\n ];\n });\n\n return this;\n }\n\n /**\n * Protects all the routes that require authentication. For more details see\n * {@link @vaadin/hilla-react-auth#protectRoutes} function.\n *\n * @param redirectPath - the path to redirect to if the route is protected\n * and the user is not authenticated.\n */\n protect(redirectPath?: string): this {\n this.update(undefined, ({ original: route, children }) => {\n const finalRoute = protectRoute(route!, redirectPath);\n finalRoute.children = children as RouteObject[] | undefined;\n return finalRoute;\n });\n\n return this;\n }\n\n /**\n * Deeply updates the current list of routes with the given routes merging\n * them in process.\n *\n * @param routes - A list of routes to merge with the current list.\n * @param callback - A callback to transform the routes during the merge.\n */\n update<T extends RouteBase>(routes: undefined, callback: RouteTransformer<undefined>): this;\n update<T extends RouteBase>(routes: readonly T[], callback?: RouteTransformer<T>): this;\n update<T extends RouteBase>(\n routes: readonly T[] | undefined,\n callback: RouteTransformer<T | undefined> = ({ original, overriding, children }) =>\n ({\n ...original,\n ...overriding,\n children,\n }) as RouteObject,\n ): this {\n this.#modifiers.push((existingRoutes) =>\n // Going through the existing and added list of routes.\n transformTree<readonly [RouteList | undefined, readonly T[] | undefined], RouteList | undefined>(\n [existingRoutes, routes],\n null,\n ([original, added], next) => {\n if (original && added) {\n // If we have both original and added routes, we have to merge them.\n const final: Array<RouteObject | undefined> = [];\n const pathKeys = new Set([...original.map(createRouteKey), ...added.map(createRouteKey)]);\n\n for (const pathKey of pathKeys) {\n // We can have multiple routes with the same path, so we have to\n // consider all of them.\n const originalRoutes = original.filter((r) => createRouteKey(r) === pathKey);\n // We can have only one route with the same path in the added list.\n const addedRoutes = added.filter((r) => createRouteKey(r) === pathKey);\n\n if (addedRoutes.length > 1) {\n throw new Error('Adding multiple routes with the same path is not allowed');\n }\n\n const addedRoute = addedRoutes[0] as T | undefined;\n\n if (originalRoutes.length > 0 && addedRoute) {\n // In case we have both original and added routes, we run\n // the callback for each original route in pair with the added\n // route. To make the difference, we flag all the routes except\n // the last one as `dupe`.\n //\n // Why the last one is not `dupe`? According to the\n // `react-router` logic, the last route is the fallback for all\n // routes with the same path. So, if we apply callback to it,\n // we implicitly apply it to all other routes with the same\n // path.\n //\n // In case this logic doesn't work, the user can apply the\n // callback without considering the `dupe` flag.\n for (let i = 0; i < originalRoutes.length; i++) {\n final.push(\n callback({\n original: originalRoutes[i],\n overriding: addedRoute,\n children: next([originalRoutes[i].children, addedRoute.children]),\n dupe: i < originalRoutes.length - 1,\n }) ?? originalRoutes[i],\n );\n }\n } else if (originalRoutes.length > 0) {\n // In case we don't have the added route with the path being\n // processed, we run the callback for each original route.\n for (let i = 0; i < originalRoutes.length; i++) {\n final.push(\n callback({\n original: originalRoutes[i],\n children: next([originalRoutes[i].children, undefined]),\n dupe: i < originalRoutes.length - 1,\n }) ?? originalRoutes[i],\n );\n }\n } else {\n // In case we don't have the original route with the path being\n // processed, we run the callback for only the added route.\n const result = callback({\n overriding: addedRoute,\n children: next([undefined, addedRoute!.children]),\n dupe: false,\n });\n\n if (result) {\n final.push(result);\n }\n }\n }\n\n return final.filter((r) => r != null);\n } else if (original) {\n // If we have only original routes, we run the callback for each\n // original route.\n return original\n .map((route) =>\n callback({\n original: route,\n children: next([route.children, undefined]),\n dupe: false,\n }),\n )\n .filter((r) => r != null);\n } else if (added) {\n // If we have only added routes, we run the callback for each added\n // route.\n return added\n .map((route) =>\n callback({\n overriding: route,\n children: next([undefined, route.children]),\n dupe: false,\n }),\n )\n .filter((r) => r != null);\n }\n\n return undefined;\n },\n ),\n );\n return this;\n }\n\n /**\n * Builds the router with the current list of routes.\n */\n build(options?: RouterBuildOptions): RouterConfiguration {\n this.#withLayoutSkipping();\n const routes = this.#modifiers.reduce<RouteList | undefined>((acc, mod) => mod(acc) ?? acc, undefined) ?? [];\n\n return {\n routes,\n router: createBrowserRouter([...routes], {\n basename: new URL(document.baseURI).pathname,\n future: {\n // eslint-disable-next-line camelcase\n v7_fetcherPersist: true,\n // eslint-disable-next-line camelcase\n v7_normalizeFormMethod: true,\n // eslint-disable-next-line camelcase\n v7_partialHydration: true,\n // eslint-disable-next-line camelcase\n v7_relativeSplatPath: true,\n // eslint-disable-next-line camelcase\n v7_skipActionErrorRevalidation: true,\n },\n ...options,\n }),\n };\n }\n\n #withLayoutSkipping(): this {\n this.#modifiers.push((originalRoutes) => {\n if (!originalRoutes) {\n return originalRoutes;\n }\n\n type Accumulator<T extends RouteList> = Readonly<{\n skipped: T;\n regular: T;\n }>;\n\n const result = transformTree<RouteList, Accumulator<RouteList>>(originalRoutes, null, (routes, next) =>\n // Split a single routes list onto two separate lists.\n routes.reduce<Accumulator<WritableRouteList>>(\n (lists, route) => {\n // If the route has `skipLayout` flag, it goes to the `skipped` list.\n if (getRouteHandleFlag(route, RouteHandleFlags.SKIP_LAYOUTS)) {\n lists.skipped.push(route);\n return lists;\n }\n\n // If the route is leaf, it goes to the `regular` list.\n if (!route.children?.length) {\n lists.regular.push(route);\n return lists;\n }\n\n // As of children, we have to split them into two lists as well.\n const { skipped, regular } = next(route.children ?? []);\n\n // If we have `skipped` list of children, we have to remove the\n // `element` property of the router to prevent the layout from\n // rendering. Then, we add the current route to the `skipped` list.\n if (skipped.length > 0) {\n const { element, ...rest } = route;\n\n lists.skipped.push({\n ...rest,\n children: skipped,\n } as RouteObject);\n }\n\n // In case of `regular` children, we just add the current route to\n // the `regular` list if there are any children.\n if (regular.length > 0) {\n lists.regular.push({\n ...route,\n children: regular,\n } as RouteObject);\n }\n\n return lists;\n },\n { skipped: [], regular: [] },\n ),\n );\n\n // We don't need a fallback for the skipped routes, so we have to wrap\n // them with the route with the `IGNORE_FALLBACK` flag.\n return [\n ...(result.skipped.length\n ? [\n {\n children: result.skipped as RouteObject[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AEhB,kBAAI,mBAAmB,OAAO,gCAA6B,GAAG;AAC5D,sBAAM,QAAQ,KAAK,KAAK;AACxB,uBAAO;AAAA,cACT;AAGA,kBAAI,CAAC,MAAM,UAAU,QAAQ;AAC3B,sBAAM,QAAQ,KAAK,KAAK;AACxB,uBAAO;AAAA,cACT;AAGA,oBAAM,EAAE,SAAS,QAAQ,IAAI,KAAK,MAAM,YAAY,CAAC,CAAC;AAKtD,kBAAI,QAAQ,SAAS,GAAG;AACtB,sBAAM,EAAE,SAAS,GAAG,KAAK,IAAI;AAE7B,sBAAM,QAAQ,KAAK;AAAA,kBACjB,GAAG;AAAA,kBACH,UAAU;AAAA,gBACZ,CAAgB;AAAA,cAClB;AAIA,kBAAI,QAAQ,SAAS,GAAG;AACtB,sBAAM,QAAQ,KAAK;AAAA,kBACjB,GAAG;AAAA,kBACH,UAAU;AAAA,gBACZ,CAAgB;AAAA,cAClB;AAEA,qBAAO;AAAA,YACT;AAAA,YACA,EAAE,SAAS,CAAC,GAAG,SAAS,CAAC,EAAE;AAAA,UAC7B;AAAA;AAAA,MACF;AAIA,aAAO;AAAA,QACL,GAAI,OAAO,QAAQ,SACf;AAAA,UACE;AAAA,YACE,UAAU,OAAO;AAAA,YACjB,QAAQ;AAAA,cACN,CAAC,sCAAgC,GAAG;AAAA,YACtC;AAAA,UACF;AAAA,QACF,IACA,CAAC;AAAA,QACL,GAAG,OAAO;AAAA,MACZ;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/consistent-type-assertions */\nimport { protectRoute } from '@vaadin/hilla-react-auth';\nimport { type ComponentType, createElement } from 'react';\nimport { createBrowserRouter, type IndexRouteObject, type NonIndexRouteObject, type RouteObject } from 'react-router';\nimport { convertComponentNameToTitle } from '../shared/convertComponentNameToTitle.js';\nimport { transformTree } from '../shared/transformTree.js';\nimport type {\n AgnosticRoute,\n Module,\n RouteModule,\n RouterBuildOptions,\n RouterConfiguration,\n ViewConfig,\n} from '../types.js';\n\ninterface RouteBase {\n path?: string;\n children?: readonly this[];\n}\n\nfunction isReactRouteModule(module?: Module): module is RouteModule<ComponentType> | undefined {\n if (!module) {\n return true;\n }\n\n return (\n ('default' in module && typeof module.default === 'function') ||\n ('config' in module && typeof module.config === 'object')\n );\n}\n\nexport type RouteList = readonly RouteObject[];\nexport type WritableRouteList = RouteObject[];\n\nexport type RouteTransformerOptions<T> = Readonly<{\n children?: RouteList;\n original?: RouteObject;\n overriding?: T;\n dupe: boolean;\n}>;\n\nexport type RouteTransformer<T> = (opts: RouteTransformerOptions<T>) => RouteObject | undefined;\n\ntype RoutesModifier = (routes: RouteList | undefined) => RouteList | undefined;\n\nfunction createRouteKey<T extends RouteBase>(route: T): string {\n return `${route.path ?? ''}-${route.children ? 'n' : 'i'}`;\n}\n\nenum RouteHandleFlags {\n FLOW_LAYOUT = 'flowLayout',\n IGNORE_FALLBACK = 'ignoreFallback',\n SKIP_LAYOUTS = 'skipLayouts',\n}\n\nfunction getRouteHandleFlag<T extends RouteHandleFlags>(route: RouteObject, flag: T): boolean | undefined {\n if (typeof route.handle === 'object' && flag in route.handle) {\n return (route.handle as Record<T, boolean>)[flag];\n }\n\n return undefined;\n}\n\n/**\n * A builder for creating a Vaadin-specific router for React with\n * authentication and server routes support.\n */\nexport class RouterConfigurationBuilder {\n readonly #modifiers: RoutesModifier[] = [];\n\n /**\n * Adds the given routes to the current list of routes. All the routes are\n * deeply merged to preserve the path uniqueness.\n *\n * @param routes - A list of routes to add to the current list.\n */\n withReactRoutes(routes: RouteList): this {\n return this.update(routes);\n }\n\n /**\n * Adds the given file routes to the current list of routes. All the routes\n * are transformed to React RouterObjects and deeply merged to preserve the\n * path uniqueness.\n *\n * @param routes - A list of routes to add to the current list.\n */\n withFileRoutes(routes: readonly AgnosticRoute[]): this {\n return this.update(routes, ({ original, overriding: added, children }) => {\n if (added) {\n const { module, path, flowLayout } = added;\n if (!isReactRouteModule(module)) {\n throw new Error(\n `The module for the \"${path}\" section doesn't have the React component exported by default or a ViewConfig object exported as \"config\"`,\n );\n }\n\n const element = module?.default ? createElement(module.default) : undefined;\n const handle = {\n ...module?.config,\n title: module?.config?.title ?? convertComponentNameToTitle(module?.default),\n flowLayout: module?.config?.flowLayout ?? flowLayout,\n };\n\n if (path === '' && !children) {\n return {\n ...original,\n element,\n handle,\n index: true,\n } as IndexRouteObject;\n }\n\n return {\n ...original,\n path: module?.config?.route ?? path,\n element,\n children,\n handle,\n } as NonIndexRouteObject;\n }\n\n return original;\n });\n }\n\n /**\n * Adds the given server route element to each branch of the current list of\n * routes.\n *\n * @param component - The React component to add to each branch of the\n * current list of routes.\n * @param config - An optional configuration that will be applied to\n * each fallback component.\n */\n withFallback(component: ComponentType, config?: ViewConfig): this {\n this.withLayout(component);\n\n // Fallback adds two routes, so that the index (empty path) has a fallback too\n const fallbackRoutes: RouteList = [\n { path: '*', element: createElement(component), handle: config },\n { index: true, element: createElement(component), handle: config },\n ];\n\n this.update(fallbackRoutes, ({ original, overriding: added, children, dupe }) => {\n if (original && !getRouteHandleFlag(original, RouteHandleFlags.IGNORE_FALLBACK) && !dupe) {\n if (!children) {\n return original;\n }\n\n const _fallback = [...fallbackRoutes];\n\n if (children.some(({ path }) => path === '*')) {\n _fallback.shift();\n }\n\n if (children.some(({ index: i, path }) => i ?? path?.includes('?'))) {\n _fallback.pop();\n }\n\n return {\n ...original,\n children: [...children, ..._fallback],\n } as RouteObject;\n }\n\n return added!;\n });\n\n return this;\n }\n\n /**\n * Adds the layoutComponent as the parent layout to views with the flowLayouts ViewConfiguration set.\n *\n * @param layoutComponent - layout component to use, usually Flow\n */\n withLayout(layoutComponent: ComponentType): this {\n this.#modifiers.push((originalRoutes) => {\n if (!originalRoutes) {\n return originalRoutes;\n }\n\n type Accumulator<T extends RouteList> = Readonly<{\n server: T;\n client: T;\n ambivalent: T;\n }>;\n\n const result = transformTree<RouteList, Accumulator<RouteList>>(originalRoutes, null, (routes, next) =>\n // Split a single routes list onto three separate lists:\n // - A list of server routes\n // - A list of client routes\n // - A list of routes which will be moved to either server or client\n // list. It depends on the parent route.\n routes.reduce<Accumulator<WritableRouteList>>(\n (lists, route) => {\n const { server, client, ambivalent } = next(route.children ?? []);\n\n const flag = getRouteHandleFlag(route, RouteHandleFlags.FLOW_LAYOUT);\n\n // If the route has `flowLayout` flag explicitly enabled, it goes to\n // the server list. The children are also affected by the flag\n // unless they have it explicitly disabled.\n if (flag === true) {\n lists.server.push({\n ...route,\n children: server.length + ambivalent.length > 0 ? [...server, ...ambivalent] : undefined,\n } as RouteObject);\n } else if (server.length > 0) {\n // Even if the route doesn't have the flag, it goes to the server\n // list if any of the children has the flag enabled.\n lists.server.push({\n ...route,\n children: server,\n } as RouteObject);\n }\n\n // If the route has `flowLayout` flag explicitly disabled, it goes\n // to the client list. The route children are not affected by the\n // flag.\n if (flag === false || client.length > 0) {\n lists.client.push({\n ...route,\n children: client.length > 0 ? client : undefined,\n } as RouteObject);\n }\n\n // The route without the flag go to the `default` list. Then it will\n // be moved to either server or client list based on the parent\n // route.\n if (\n flag === undefined &&\n (lists.server.every(({ path }) => path !== route.path) || ambivalent.length > 0)\n ) {\n lists.ambivalent.push({\n ...route,\n children: ambivalent.length > 0 ? ambivalent : undefined,\n } as RouteObject);\n }\n\n return lists;\n },\n { server: [], client: [], ambivalent: [] },\n ),\n );\n\n return [\n ...(result.server.length\n ? [\n // The server routes are wrapped with the route that has a layout\n // element. It also has the `IGNORE_FALLBACK` flag to remove the\n // fallback route from reach.\n {\n element: createElement(layoutComponent),\n children: result.server as RouteObject[],\n handle: {\n [RouteHandleFlags.IGNORE_FALLBACK]: true,\n },\n },\n ]\n : []),\n // The client routes are preserved without wrapping.\n ...result.client,\n // The ambivalent routes are considered as client routes.\n ...result.ambivalent,\n ];\n });\n\n return this;\n }\n\n /**\n * Protects all the routes that require authentication. For more details see\n * {@link @vaadin/hilla-react-auth#protectRoutes} function.\n *\n * @param redirectPath - the path to redirect to if the route is protected\n * and the user is not authenticated.\n */\n protect(redirectPath?: string): this {\n this.update(undefined, ({ original: route, children }) => {\n const finalRoute = protectRoute(route!, redirectPath);\n finalRoute.children = children as RouteObject[] | undefined;\n return finalRoute;\n });\n\n return this;\n }\n\n /**\n * Deeply updates the current list of routes with the given routes merging\n * them in process.\n *\n * @param routes - A list of routes to merge with the current list.\n * @param callback - A callback to transform the routes during the merge.\n */\n update(routes: undefined, callback: RouteTransformer<undefined>): this;\n update<T extends RouteBase>(routes: readonly T[], callback?: RouteTransformer<T>): this;\n update<T extends RouteBase>(\n routes: readonly T[] | undefined,\n callback: RouteTransformer<T | undefined> = ({ original, overriding, children }) =>\n ({\n ...original,\n ...overriding,\n children,\n }) as RouteObject,\n ): this {\n this.#modifiers.push((existingRoutes) =>\n // Going through the existing and added list of routes.\n transformTree<readonly [RouteList | undefined, readonly T[] | undefined], RouteList | undefined>(\n [existingRoutes, routes],\n null,\n ([original, added], next) => {\n if (original && added) {\n // If we have both original and added routes, we have to merge them.\n const final: Array<RouteObject | undefined> = [];\n const pathKeys = new Set([...original.map(createRouteKey), ...added.map(createRouteKey)]);\n\n for (const pathKey of pathKeys) {\n // We can have multiple routes with the same path, so we have to\n // consider all of them.\n const originalRoutes = original.filter((r) => createRouteKey(r) === pathKey);\n // We can have only one route with the same path in the added list.\n const addedRoutes = added.filter((r) => createRouteKey(r) === pathKey);\n\n if (addedRoutes.length > 1) {\n throw new Error('Adding multiple routes with the same path is not allowed');\n }\n\n const addedRoute = addedRoutes[0] as T | undefined;\n\n if (originalRoutes.length > 0 && addedRoute) {\n // In case we have both original and added routes, we run\n // the callback for each original route in pair with the added\n // route. To make the difference, we flag all the routes except\n // the last one as `dupe`.\n //\n // Why the last one is not `dupe`? According to the\n // `react-router` logic, the last route is the fallback for all\n // routes with the same path. So, if we apply callback to it,\n // we implicitly apply it to all other routes with the same\n // path.\n //\n // In case this logic doesn't work, the user can apply the\n // callback without considering the `dupe` flag.\n for (let i = 0; i < originalRoutes.length; i++) {\n final.push(\n callback({\n original: originalRoutes[i],\n overriding: addedRoute,\n children: next([originalRoutes[i].children, addedRoute.children]),\n dupe: i < originalRoutes.length - 1,\n }) ?? originalRoutes[i],\n );\n }\n } else if (originalRoutes.length > 0) {\n // In case we don't have the added route with the path being\n // processed, we run the callback for each original route.\n for (let i = 0; i < originalRoutes.length; i++) {\n final.push(\n callback({\n original: originalRoutes[i],\n children: next([originalRoutes[i].children, undefined]),\n dupe: i < originalRoutes.length - 1,\n }) ?? originalRoutes[i],\n );\n }\n } else {\n // In case we don't have the original route with the path being\n // processed, we run the callback for only the added route.\n const result = callback({\n overriding: addedRoute,\n children: next([undefined, addedRoute!.children]),\n dupe: false,\n });\n\n if (result) {\n final.push(result);\n }\n }\n }\n\n return final.filter((r) => r != null);\n } else if (original) {\n // If we have only original routes, we run the callback for each\n // original route.\n return original\n .map((route) =>\n callback({\n original: route,\n children: next([route.children, undefined]),\n dupe: false,\n }),\n )\n .filter((r) => r != null);\n } else if (added) {\n // If we have only added routes, we run the callback for each added\n // route.\n return added\n .map((route) =>\n callback({\n overriding: route,\n children: next([undefined, route.children]),\n dupe: false,\n }),\n )\n .filter((r) => r != null);\n }\n\n return undefined;\n },\n ),\n );\n return this;\n }\n\n /**\n * Builds the router with the current list of routes.\n */\n build(options?: RouterBuildOptions): RouterConfiguration {\n this.#withLayoutSkipping();\n const routes = this.#modifiers.reduce<RouteList | undefined>((acc, mod) => mod(acc) ?? acc, undefined) ?? [];\n\n return {\n routes,\n router: createBrowserRouter([...routes], { basename: new URL(document.baseURI).pathname, ...options }),\n };\n }\n\n #withLayoutSkipping(): this {\n this.#modifiers.push((originalRoutes) => {\n if (!originalRoutes) {\n return originalRoutes;\n }\n\n type Accumulator<T extends RouteList> = Readonly<{\n skipped: T;\n regular: T;\n }>;\n\n const result = transformTree<RouteList, Accumulator<RouteList>>(originalRoutes, null, (routes, next) =>\n // Split a single routes list onto two separate lists.\n routes.reduce<Accumulator<WritableRouteList>>(\n (lists, route) => {\n // If the route has `skipLayout` flag, it goes to the `skipped` list.\n if (getRouteHandleFlag(route, RouteHandleFlags.SKIP_LAYOUTS)) {\n lists.skipped.push(route);\n return lists;\n }\n\n // If the route is leaf, it goes to the `regular` list.\n if (!route.children?.length) {\n lists.regular.push(route);\n return lists;\n }\n\n // As of children, we have to split them into two lists as well.\n const { skipped, regular } = next(route.children ?? []);\n\n // If we have `skipped` list of children, we have to remove the\n // `element` property of the router to prevent the layout from\n // rendering. Then, we add the current route to the `skipped` list.\n if (skipped.length > 0) {\n const { element, ...rest } = route;\n\n lists.skipped.push({\n ...rest,\n children: skipped,\n } as RouteObject);\n }\n\n // In case of `regular` children, we just add the current route to\n // the `regular` list if there are any children.\n if (regular.length > 0) {\n lists.regular.push({\n ...route,\n children: regular,\n } as RouteObject);\n }\n\n return lists;\n },\n { skipped: [], regular: [] },\n ),\n );\n\n // We don't need a fallback for the skipped routes, so we have to wrap\n // them with the route with the `IGNORE_FALLBACK` flag.\n return [\n ...(result.skipped.length\n ? [\n {\n children: result.skipped as RouteObject[],\n handle: {\n [RouteHandleFlags.IGNORE_FALLBACK]: true,\n },\n },\n ]\n : []),\n ...result.regular,\n ];\n });\n\n return this;\n }\n}\n"],
5
+ "mappings": "AACA,SAAS,oBAAoB;AAC7B,SAA6B,qBAAqB;AAClD,SAAS,2BAA8F;AACvG,SAAS,mCAAmC;AAC5C,SAAS,qBAAqB;AAe9B,SAAS,mBAAmB,QAAmE;AAC7F,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SACG,aAAa,UAAU,OAAO,OAAO,YAAY,cACjD,YAAY,UAAU,OAAO,OAAO,WAAW;AAEpD;AAgBA,SAAS,eAAoC,OAAkB;AAC7D,SAAO,GAAG,MAAM,QAAQ,EAAE,IAAI,MAAM,WAAW,MAAM,GAAG;AAC1D;AAEA,IAAK,mBAAL,kBAAKA,sBAAL;AACE,EAAAA,kBAAA,iBAAc;AACd,EAAAA,kBAAA,qBAAkB;AA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,YACjB,QAAQ;AAAA,cACN,CAAC,sCAAgC,GAAG;AAAA,YACtC;AAAA,UACF;AAAA,QACF,IACA,CAAC;AAAA,QACL,GAAG,OAAO;AAAA,MACZ;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;",
6
6
  "names": ["RouteHandleFlags"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createMenuItems.d.ts","sourceRoot":"","sources":["../src/runtime/createMenuItems.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,aAAa,CAAC;AAExD,eAAO,MAAM,WAAW;;;;;;;;aA0BZ,CAAC;aAKc,CAAA;eAEC,CAAC;YAE3B,CAAC;;iBAnCsE,CAAC;AAE1E;;;;;;;GAOG;AACH,wBAAgB,eAAe,IAAI,SAAS,QAAQ,EAAE,CA0BrD"}
1
+ {"version":3,"file":"createMenuItems.d.ts","sourceRoot":"","sources":["../src/runtime/createMenuItems.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,eAAO,MAAM,WAAW;;;;;;;;aA0BJ,CAAC;aAMb,CAAL;eACiC,CAAC;YAKlC,CAAA;;iBAtCsE,CAAC;AAE1E;;;;;;;GAOG;AACH,wBAAgB,eAAe,IAAI,SAAS,QAAQ,EAAE,CA0BrD"}
@@ -2,7 +2,7 @@ function __REGISTER__(feature, vaadinObj = window.Vaadin ??= {}) {
2
2
  vaadinObj.registrations ??= [];
3
3
  vaadinObj.registrations.push({
4
4
  is: feature ? `${"@vaadin/hilla-file-router"}/${feature}` : "@vaadin/hilla-file-router",
5
- version: "24.6.4"
5
+ version: "24.7.0-alpha10"
6
6
  });
7
7
  }
8
8
  import { signal } from "@vaadin/hilla-react-signals";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../scripts/register.js", "../src/runtime/createMenuItems.ts"],
4
- "sourcesContent": ["export function __REGISTER__(feature, vaadinObj = (window.Vaadin ??= {})) {\n vaadinObj.registrations ??= [];\n vaadinObj.registrations.push({\n is: feature ? `${__NAME__}/${feature}` : __NAME__,\n version: __VERSION__,\n });\n}\n", "import { signal } from '@vaadin/hilla-react-signals';\nimport type { VaadinWindow } from '../shared/internal.js';\nimport type { MenuItem, ViewConfig } from '../types.js';\n\nexport const viewsSignal = signal((window as VaadinWindow).Vaadin?.views);\n\n/**\n * Creates menu items from the views provided by the server. The views are sorted according to the\n * {@link ViewConfig.menu.order}, filtered out if they are explicitly excluded via {@link ViewConfig.menu.exclude}.\n * Note that views with no order are put below views with an order. Ties are resolved based on the path string\n * comparison.\n *\n * @returns A list of menu items.\n */\nexport function createMenuItems(): readonly MenuItem[] {\n // @ts-expect-error: esbuild injection\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n __REGISTER__('createMenuItems', (window as VaadinWindow).Vaadin);\n const collator = new Intl.Collator('en-US');\n if (!viewsSignal.value) {\n return [];\n }\n\n return (\n Object.entries(viewsSignal.value)\n // Filter out the views that are explicitly excluded from the menu.\n .filter(([_, value]) => !value.menu?.exclude)\n // Map the views to menu items.\n .map(([path, config]) => ({\n to: path,\n icon: config.menu?.icon,\n title: config.menu?.title ?? config.title,\n order: config.menu?.order,\n }))\n // Sort views according to the order specified in the view configuration.\n .sort((menuA, menuB) => {\n const ordersDiff = (menuA.order ?? Number.MAX_VALUE) - (menuB.order ?? Number.MAX_VALUE);\n return ordersDiff !== 0 ? ordersDiff : collator.compare(menuA.to, menuB.to);\n })\n );\n}\n\n// @ts-expect-error Vite hotswapping\nif (import.meta.hot) {\n // @ts-expect-error Vite hotswapping\n // eslint-disable-next-line\n import.meta.hot.on('fs-route-update', () => {\n fetch('?v-r=routeinfo')\n .then(async (resp) => resp.json())\n .then((json) => {\n viewsSignal.value = json;\n })\n .catch((e) => {\n console.error('Failed to fetch route info', e);\n });\n });\n}\n"],
5
- "mappings": "AAAO,SAAS,aAAa,SAAS,YAAa,OAAO,WAAW,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.registrations.push({\n is: feature ? `${__NAME__}/${feature}` : __NAME__,\n version: __VERSION__,\n });\n}\n", "import { signal } from '@vaadin/hilla-react-signals';\nimport type { VaadinWindow } from '../shared/internal.js';\nimport type { MenuItem } from '../types.js';\n\nexport const viewsSignal = signal((window as VaadinWindow).Vaadin?.views);\n\n/**\n * Creates menu items from the views provided by the server. The views are sorted according to the\n * {@link ViewConfig.menu.order}, filtered out if they are explicitly excluded via {@link ViewConfig.menu.exclude}.\n * Note that views with no order are put below views with an order. Ties are resolved based on the path string\n * comparison.\n *\n * @returns A list of menu items.\n */\nexport function createMenuItems(): readonly MenuItem[] {\n // @ts-expect-error: esbuild injection\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n __REGISTER__('createMenuItems', (window as VaadinWindow).Vaadin);\n const collator = new Intl.Collator('en-US');\n if (!viewsSignal.value) {\n return [];\n }\n\n return (\n Object.entries(viewsSignal.value)\n // Filter out the views that are explicitly excluded from the menu.\n .filter(([_, value]) => !value.menu?.exclude)\n // Map the views to menu items.\n .map(([path, config]) => ({\n to: path,\n icon: config.menu?.icon,\n title: config.menu?.title ?? config.title,\n order: config.menu?.order,\n }))\n // Sort views according to the order specified in the view configuration.\n .sort((menuA, menuB) => {\n const ordersDiff = (menuA.order ?? Number.MAX_VALUE) - (menuB.order ?? Number.MAX_VALUE);\n return ordersDiff !== 0 ? ordersDiff : collator.compare(menuA.to, menuB.to);\n })\n );\n}\n\n// @ts-expect-error Vite hotswapping\nif (import.meta.hot) {\n // @ts-expect-error Vite hotswapping\n // eslint-disable-next-line\n import.meta.hot.on('fs-route-update', () => {\n fetch('?v-r=routeinfo')\n .then(async (resp) => resp.json())\n .then((json) => {\n viewsSignal.value = json;\n })\n .catch((e: unknown) => {\n console.error('Failed to fetch route info', e);\n });\n });\n}\n"],
5
+ "mappings": "AAAO,SAAS,aAAa,SAAS,YAAa,OAAO,WAAW,CAAC,GAAI;AACxE,YAAU,kBAAkB,CAAC;AAC7B,YAAU,cAAc,KAAK;AAAA,IAC3B,IAAI,UAAU,GAAG,2BAAQ,IAAI,OAAO,KAAK;AAAA,IACzC,SAAS;AAAA,EACX,CAAC;AACH;ACNA,SAAS,cAAc;AAIhB,MAAM,cAAc,OAAQ,OAAwB,QAAQ,KAAK;AAUjE,SAAS,kBAAuC;AAGrD,eAAa,mBAAoB,OAAwB,MAAM;AAC/D,QAAM,WAAW,IAAI,KAAK,SAAS,OAAO;AAC1C,MAAI,CAAC,YAAY,OAAO;AACtB,WAAO,CAAC;AAAA,EACV;AAEA,SACE,OAAO,QAAQ,YAAY,KAAK,EAE7B,OAAO,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,EAE3C,IAAI,CAAC,CAAC,MAAM,MAAM,OAAO;AAAA,IACxB,IAAI;AAAA,IACJ,MAAM,OAAO,MAAM;AAAA,IACnB,OAAO,OAAO,MAAM,SAAS,OAAO;AAAA,IACpC,OAAO,OAAO,MAAM;AAAA,EACtB,EAAE,EAED,KAAK,CAAC,OAAO,UAAU;AACtB,UAAM,cAAc,MAAM,SAAS,OAAO,cAAc,MAAM,SAAS,OAAO;AAC9E,WAAO,eAAe,IAAI,aAAa,SAAS,QAAQ,MAAM,IAAI,MAAM,EAAE;AAAA,EAC5E,CAAC;AAEP;AAGA,IAAI,YAAY,KAAK;AAGnB,cAAY,IAAI,GAAG,mBAAmB,MAAM;AAC1C,UAAM,gBAAgB,EACnB,KAAK,OAAO,SAAS,KAAK,KAAK,CAAC,EAChC,KAAK,CAAC,SAAS;AACd,kBAAY,QAAQ;AAAA,IACtB,CAAC,EACA,MAAM,CAAC,MAAe;AACrB,cAAQ,MAAM,8BAA8B,CAAC;AAAA,IAC/C,CAAC;AAAA,EACL,CAAC;AACH;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- import { useMatches } from "react-router-dom";
1
+ import { useMatches } from "react-router";
2
2
  function useViewConfig() {
3
3
  const matches = useMatches();
4
4
  return matches[matches.length - 1]?.handle;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/runtime/useViewConfig.ts"],
4
- "sourcesContent": ["import type { UIMatch } from '@remix-run/router';\nimport { useMatches } from 'react-router-dom';\nimport type { ViewConfig } from '../types.js';\n\n/**\n * Hook to return the {@link ViewConfig} for the current route.\n */\nexport function useViewConfig<M extends ViewConfig>(): M | undefined {\n const matches = useMatches() as ReadonlyArray<UIMatch<unknown, M>>;\n return matches[matches.length - 1]?.handle;\n}\n"],
4
+ "sourcesContent": ["import type { UIMatch } from 'react-router';\nimport { useMatches } from 'react-router';\nimport type { ViewConfig } from '../types.js';\n\n/**\n * Hook to return the {@link ViewConfig} for the current route.\n */\nexport function useViewConfig<M extends ViewConfig>(): M | undefined {\n const matches = useMatches() as ReadonlyArray<UIMatch<unknown, M>>;\n return matches[matches.length - 1]?.handle;\n}\n"],
5
5
  "mappings": "AACA,SAAS,kBAAkB;AAMpB,SAAS,gBAAqD;AACnE,QAAM,UAAU,WAAW;AAC3B,SAAO,QAAQ,QAAQ,SAAS,CAAC,GAAG;AACtC;",
6
6
  "names": []
7
7
  }
package/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { createBrowserRouter, RouteObject } from 'react-router-dom';
1
+ import type { createBrowserRouter, RouteObject } from 'react-router';
2
2
 
3
3
  export type ViewConfig = Readonly<{
4
4
  /**
@@ -10,7 +10,7 @@ const fileExtensions = [".ts", ".tsx", ".js", ".jsx"];
10
10
  class RouteFromMetaProcessor {
11
11
  #manager;
12
12
  #views;
13
- constructor(views, { json: jsonFile, code: codeFile }) {
13
+ constructor(views, { code: codeFile }) {
14
14
  this.#views = views;
15
15
  const codeDir = new URL("./", codeFile);
16
16
  this.#manager = new DependencyManager(new PathManager({ extension: ".js", relativeTo: codeDir }));
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/vite-plugin/createRoutesFromMeta.ts"],
4
- "sourcesContent": ["import { template, transform as transformer } from '@vaadin/hilla-generator-utils/ast.js';\nimport createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport ts, { type CallExpression, type Identifier, type VariableStatement } from 'typescript';\n\nimport { transformTree } from '../shared/transformTree.js';\nimport type { RouteMeta } from './collectRoutesFromFS.js';\nimport type { RuntimeFileUrls } from './generateRuntimeFiles.js';\nimport { convertFSRouteSegmentToURLPatternFormat } from './utils.js';\n\nconst printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\nconst fileExtensions = ['.ts', '.tsx', '.js', '.jsx'];\n\nclass RouteFromMetaProcessor {\n readonly #manager: DependencyManager;\n readonly #views: readonly RouteMeta[];\n\n constructor(views: readonly RouteMeta[], { json: jsonFile, code: codeFile }: RuntimeFileUrls) {\n this.#views = views;\n\n const codeDir = new URL('./', codeFile);\n this.#manager = new DependencyManager(new PathManager({ extension: '.js', relativeTo: codeDir }));\n }\n\n /**\n * Loads all the files from the received metadata and creates a framework-agnostic route tree.\n *\n * @param views - The abstract route tree.\n * @param generatedDir - The directory where the generated view file will be stored.\n */\n process(): string {\n const {\n paths,\n imports: { named, namespace },\n } = this.#manager;\n const errors: string[] = [];\n\n const routes = transformTree<readonly RouteMeta[], readonly CallExpression[]>(this.#views, null, (metas, next) => {\n errors.push(\n ...metas\n .map((route) => route.path)\n .filter((item, index, arr) => arr.indexOf(item) !== index)\n .map((dup) => `console.error(\"Two views share the same path: ${dup}\");`),\n );\n\n return metas.map(({ file, layout, path, children, flowLayout }) => {\n let _children: readonly CallExpression[] | undefined;\n\n if (children) {\n _children = next(children);\n }\n\n let mod: Identifier | undefined;\n if (file) {\n const fileExt = fileExtensions.find((ext) => file.pathname.endsWith(ext));\n mod = namespace.add(paths.createRelativePath(file, fileExt), `Page`);\n } else if (layout) {\n const fileExt = fileExtensions.find((ext) => layout.pathname.endsWith(ext));\n mod = namespace.add(paths.createRelativePath(layout, fileExt), `Layout`);\n }\n\n const moduleExtension = flowLayout ? { flowLayout } : undefined;\n\n return this.#createRouteData(convertFSRouteSegmentToURLPatternFormat(path), mod, moduleExtension, _children);\n });\n });\n\n const agnosticRouteId =\n named.getIdentifier('@vaadin/hilla-file-router/types.js', 'AgnosticRoute') ??\n named.add('@vaadin/hilla-file-router/types.js', 'AgnosticRoute', true);\n\n let routeDeclaration = template(\n `${errors.join('\\n')}\n\nconst routes: readonly AGNOSTIC_ROUTE[] = ROUTE;\n\nexport default routes;\n`,\n [\n transformer((node) =>\n ts.isIdentifier(node) && node.text === 'ROUTE' ? ts.factory.createArrayLiteralExpression(routes, true) : node,\n ),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'AGNOSTIC_ROUTE' ? agnosticRouteId : node)),\n ],\n );\n\n routeDeclaration = [...this.#manager.imports.toCode(), ...routeDeclaration];\n\n const file = createSourceFile(routeDeclaration, 'file-routes.ts');\n return printer.printFile(file);\n }\n\n /**\n * Create an abstract route creation function call. The nested function calls\n * create a route tree.\n *\n * @param path - The path of the route.\n * @param mod - The name of the route module imported as a namespace.\n * @param children - The list of child route call expressions.\n */\n #createRouteData(\n path: string,\n mod: Identifier | undefined,\n extension?: Readonly<Record<string, unknown>>,\n children?: readonly CallExpression[],\n ): CallExpression {\n const { named } = this.#manager.imports;\n\n let extendModuleId: Identifier | undefined;\n let modNode = '';\n\n if (extension) {\n extendModuleId =\n named.getIdentifier('@vaadin/hilla-file-router/runtime.js', 'extendModule') ??\n named.add('@vaadin/hilla-file-router/runtime.js', 'extendModule');\n modNode = `, EXTEND_MODULE(MOD, ${JSON.stringify(extension)})`;\n } else if (mod) {\n modNode = `, MOD`;\n }\n\n const createRouteId =\n named.getIdentifier('@vaadin/hilla-file-router/runtime.js', 'createRoute') ??\n named.add('@vaadin/hilla-file-router/runtime.js', 'createRoute');\n\n return template(\n `const route = CREATE_ROUTE(\"${path}\", ${modNode}${children ? `, CHILDREN` : ''})`,\n ([statement]) => (statement as VariableStatement).declarationList.declarations[0].initializer as CallExpression,\n [\n transformer((node) =>\n ts.isIdentifier(node) && node.text === 'CHILDREN'\n ? ts.factory.createArrayLiteralExpression(children, true)\n : node,\n ),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'MOD' ? (mod ?? ts.factory.createNull()) : node)),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'EXTEND_MODULE' ? extendModuleId : node)),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'CREATE_ROUTE' ? createRouteId : node)),\n ],\n );\n }\n}\n\nexport default function createRoutesFromMeta(views: readonly RouteMeta[], urls: RuntimeFileUrls): string {\n return new RouteFromMetaProcessor(views, urls).process();\n}\n"],
5
- "mappings": "AAAA,SAAS,UAAU,aAAa,mBAAmB;AACnD,OAAO,sBAAsB;AAC7B,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AACxB,OAAO,YAA0E;AAEjF,SAAS,qBAAqB;AAG9B,SAAS,+CAA+C;AAExD,MAAM,UAAU,GAAG,cAAc,EAAE,SAAS,GAAG,YAAY,SAAS,CAAC;AAErE,MAAM,iBAAiB,CAAC,OAAO,QAAQ,OAAO,MAAM;AAEpD,MAAM,uBAAuB;AAAA,EAClB;AAAA,EACA;AAAA,EAET,YAAY,OAA6B,EAAE,MAAM,UAAU,MAAM,SAAS,GAAoB;AAC5F,SAAK,SAAS;AAEd,UAAM,UAAU,IAAI,IAAI,MAAM,QAAQ;AACtC,SAAK,WAAW,IAAI,kBAAkB,IAAI,YAAY,EAAE,WAAW,OAAO,YAAY,QAAQ,CAAC,CAAC;AAAA,EAClG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAkB;AAChB,UAAM;AAAA,MACJ;AAAA,MACA,SAAS,EAAE,OAAO,UAAU;AAAA,IAC9B,IAAI,KAAK;AACT,UAAM,SAAmB,CAAC;AAE1B,UAAM,SAAS,cAA+D,KAAK,QAAQ,MAAM,CAAC,OAAO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A,EACF;AACF;AAEe,SAAR,qBAAsC,OAA6B,MAA+B;AACvG,SAAO,IAAI,uBAAuB,OAAO,IAAI,EAAE,QAAQ;AACzD;",
4
+ "sourcesContent": ["import { template, transform as transformer } from '@vaadin/hilla-generator-utils/ast.js';\nimport createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport ts, { type CallExpression, type Identifier, type VariableStatement } from 'typescript';\n\nimport { transformTree } from '../shared/transformTree.js';\nimport type { RouteMeta } from './collectRoutesFromFS.js';\nimport type { RuntimeFileUrls } from './generateRuntimeFiles.js';\nimport { convertFSRouteSegmentToURLPatternFormat } from './utils.js';\n\nconst printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\nconst fileExtensions = ['.ts', '.tsx', '.js', '.jsx'];\n\nclass RouteFromMetaProcessor {\n readonly #manager: DependencyManager;\n readonly #views: readonly RouteMeta[];\n\n constructor(views: readonly RouteMeta[], { code: codeFile }: RuntimeFileUrls) {\n this.#views = views;\n\n const codeDir = new URL('./', codeFile);\n this.#manager = new DependencyManager(new PathManager({ extension: '.js', relativeTo: codeDir }));\n }\n\n /**\n * Loads all the files from the received metadata and creates a framework-agnostic route tree.\n *\n * @param views - The abstract route tree.\n * @param generatedDir - The directory where the generated view file will be stored.\n */\n process(): string {\n const {\n paths,\n imports: { named, namespace },\n } = this.#manager;\n const errors: string[] = [];\n\n const routes = transformTree<readonly RouteMeta[], readonly CallExpression[]>(this.#views, null, (metas, next) => {\n errors.push(\n ...metas\n .map((route) => route.path)\n .filter((item, index, arr) => arr.indexOf(item) !== index)\n .map((dup) => `console.error(\"Two views share the same path: ${dup}\");`),\n );\n\n return metas.map(({ file, layout, path, children, flowLayout }) => {\n let _children: readonly CallExpression[] | undefined;\n\n if (children) {\n _children = next(children);\n }\n\n let mod: Identifier | undefined;\n if (file) {\n const fileExt = fileExtensions.find((ext) => file.pathname.endsWith(ext));\n mod = namespace.add(paths.createRelativePath(file, fileExt), `Page`);\n } else if (layout) {\n const fileExt = fileExtensions.find((ext) => layout.pathname.endsWith(ext));\n mod = namespace.add(paths.createRelativePath(layout, fileExt), `Layout`);\n }\n\n const moduleExtension = flowLayout ? { flowLayout } : undefined;\n\n return this.#createRouteData(convertFSRouteSegmentToURLPatternFormat(path), mod, moduleExtension, _children);\n });\n });\n\n const agnosticRouteId =\n named.getIdentifier('@vaadin/hilla-file-router/types.js', 'AgnosticRoute') ??\n named.add('@vaadin/hilla-file-router/types.js', 'AgnosticRoute', true);\n\n let routeDeclaration = template(\n `${errors.join('\\n')}\n\nconst routes: readonly AGNOSTIC_ROUTE[] = ROUTE;\n\nexport default routes;\n`,\n [\n transformer((node) =>\n ts.isIdentifier(node) && node.text === 'ROUTE' ? ts.factory.createArrayLiteralExpression(routes, true) : node,\n ),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'AGNOSTIC_ROUTE' ? agnosticRouteId : node)),\n ],\n );\n\n routeDeclaration = [...this.#manager.imports.toCode(), ...routeDeclaration];\n\n const file = createSourceFile(routeDeclaration, 'file-routes.ts');\n return printer.printFile(file);\n }\n\n /**\n * Create an abstract route creation function call. The nested function calls\n * create a route tree.\n *\n * @param path - The path of the route.\n * @param mod - The name of the route module imported as a namespace.\n * @param children - The list of child route call expressions.\n */\n #createRouteData(\n path: string,\n mod: Identifier | undefined,\n extension?: Readonly<Record<string, unknown>>,\n children?: readonly CallExpression[],\n ): CallExpression {\n const { named } = this.#manager.imports;\n\n let extendModuleId: Identifier | undefined;\n let modNode = '';\n\n if (extension) {\n extendModuleId =\n named.getIdentifier('@vaadin/hilla-file-router/runtime.js', 'extendModule') ??\n named.add('@vaadin/hilla-file-router/runtime.js', 'extendModule');\n modNode = `, EXTEND_MODULE(MOD, ${JSON.stringify(extension)})`;\n } else if (mod) {\n modNode = `, MOD`;\n }\n\n const createRouteId =\n named.getIdentifier('@vaadin/hilla-file-router/runtime.js', 'createRoute') ??\n named.add('@vaadin/hilla-file-router/runtime.js', 'createRoute');\n\n return template(\n `const route = CREATE_ROUTE(\"${path}\", ${modNode}${children ? `, CHILDREN` : ''})`,\n ([statement]) => (statement as VariableStatement).declarationList.declarations[0].initializer as CallExpression,\n [\n transformer((node) =>\n ts.isIdentifier(node) && node.text === 'CHILDREN'\n ? ts.factory.createArrayLiteralExpression(children, true)\n : node,\n ),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'MOD' ? (mod ?? ts.factory.createNull()) : node)),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'EXTEND_MODULE' ? extendModuleId : node)),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'CREATE_ROUTE' ? createRouteId : node)),\n ],\n );\n }\n}\n\nexport default function createRoutesFromMeta(views: readonly RouteMeta[], urls: RuntimeFileUrls): string {\n return new RouteFromMetaProcessor(views, urls).process();\n}\n"],
5
+ "mappings": "AAAA,SAAS,UAAU,aAAa,mBAAmB;AACnD,OAAO,sBAAsB;AAC7B,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AACxB,OAAO,YAA0E;AAEjF,SAAS,qBAAqB;AAG9B,SAAS,+CAA+C;AAExD,MAAM,UAAU,GAAG,cAAc,EAAE,SAAS,GAAG,YAAY,SAAS,CAAC;AAErE,MAAM,iBAAiB,CAAC,OAAO,QAAQ,OAAO,MAAM;AAEpD,MAAM,uBAAuB;AAAA,EAClB;AAAA,EACA;AAAA,EAET,YAAY,OAA6B,EAAE,MAAM,SAAS,GAAoB;AAC5E,SAAK,SAAS;AAEd,UAAM,UAAU,IAAI,IAAI,MAAM,QAAQ;AACtC,SAAK,WAAW,IAAI,kBAAkB,IAAI,YAAY,EAAE,WAAW,OAAO,YAAY,QAAQ,CAAC,CAAC;AAAA,EAClG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAkB;AAChB,UAAM;AAAA,MACJ;AAAA,MACA,SAAS,EAA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AAK;AAAA,QACtG,YAAY,CAAC,SAAU,GAAG,aAAa,IAAI,KAAK,KAAK,SAAS,iBAAiB,gBAAgB,IAAK;AAAA,MACtG;AAAA,IACF;AAAA,EACF;AACF;AAEe,SAAR,qBAAsC,OAA6B,MAA+B;AACvG,SAAO,IAAI,uBAAuB,OAAO,IAAI,EAAE,QAAQ;AACzD;",
6
6
  "names": ["file"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"generateRuntimeFiles.d.ts","sourceRoot":"","sources":["../src/vite-plugin/generateRuntimeFiles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAMnC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC;;;OAGG;IACH,IAAI,EAAE,GAAG,CAAC;IACV;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC;IACV;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC;CACd,CAAC,CAAC;AAiCH;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,GAAG,EACb,IAAI,EAAE,eAAe,EACrB,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,IAAI,CAAC,CA8Bf"}
1
+ {"version":3,"file":"generateRuntimeFiles.d.ts","sourceRoot":"","sources":["../src/vite-plugin/generateRuntimeFiles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAMnC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC;;;OAGG;IACH,IAAI,EAAE,GAAG,CAAC;IACV;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC;IACV;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC;CACd,CAAC,CAAC;AAiCH;;;;;;;;GAQG;AAEH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,GAAG,EACb,IAAI,EAAE,eAAe,EACrB,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,IAAI,CAAC,CA8Bf"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/vite-plugin/generateRuntimeFiles.ts"],
4
- "sourcesContent": ["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport type { Logger } from 'vite';\nimport applyLayouts from './applyLayouts.js';\nimport collectRoutesFromFS, { type RouteMeta } from './collectRoutesFromFS.js';\nimport createRoutesFromMeta from './createRoutesFromMeta.js';\nimport createViewConfigJson from './createViewConfigJson.js';\n\n/**\n * The URLs of the files to generate.\n */\nexport type RuntimeFileUrls = Readonly<{\n /**\n * The URL of the JSON file with the leaf routes and their metadata. This file\n * will be processed by the server to provide the final route configuration.\n */\n json: URL;\n /**\n * The URL of the module with the routes tree in a framework-agnostic format.\n */\n code: URL;\n /**\n * The URL of the JSON file containing server layout path information.\n */\n layouts: URL;\n}>;\n\n/**\n * Generates a file conditionally. If the file already exists and its content is the same as the\n * given data, the file will not be overwritten. It is useful to avoid unnecessary server\n * reboot during development.\n *\n * @param url - The URL of the file to generate.\n * @param data - The data to write to the file.\n * @param forceWrite - true to force writing the file even if there are no changes\n * @returns true if the file was written, false otherwise.\n */\nasync function generateRuntimeFile(url: URL, data: string, forceWrite?: boolean): Promise<boolean> {\n await mkdir(new URL('./', url), { recursive: true });\n let shouldWrite = forceWrite ?? false;\n if (!forceWrite) {\n let contents: string | undefined;\n try {\n contents = await readFile(url, 'utf-8');\n } catch (e: unknown) {\n if (!(e != null && typeof e === 'object' && 'code' in e && e.code === 'ENOENT')) {\n throw e;\n }\n }\n shouldWrite = contents !== data;\n }\n if (shouldWrite) {\n await writeFile(url, data, 'utf-8');\n }\n\n return shouldWrite;\n}\n\n/**\n * Collects all file-based routes from the given directory, and based on them generates two files\n * described by {@link RuntimeFileUrls} type.\n * @param viewsDir - The directory that contains file-based routes (views).\n * @param urls - The URLs of the files to generate.\n * @param extensions - The list of extensions that will be collected as routes.\n * @param logger - The Vite logger instance.\n * @param debug - true to debug\n */\nexport async function generateRuntimeFiles(\n viewsDir: URL,\n urls: RuntimeFileUrls,\n extensions: readonly string[],\n logger: Logger,\n debug: boolean,\n): Promise<void> {\n let routeMeta: readonly RouteMeta[];\n try {\n routeMeta = await collectRoutesFromFS(viewsDir, { extensions, logger });\n } catch (e: unknown) {\n if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {\n routeMeta = [];\n } else {\n throw e;\n }\n }\n\n if (debug) {\n logger.info('Collected file-based routes');\n }\n routeMeta = await applyLayouts(routeMeta, urls.layouts);\n const runtimeRoutesCode = createRoutesFromMeta(routeMeta, urls);\n const viewConfigJson = await createViewConfigJson(routeMeta);\n\n const jsonWritten = await generateRuntimeFile(urls.json, viewConfigJson);\n if (debug) {\n logger.info(`Frontend route list is generated: ${String(urls.json)}`);\n }\n // If the metadata has changed, we need to write the TS file also to make Vite HMR updates work properly.\n // Even though the contents of the TS file does not change, the contents of the files imported in the TS\n // files changes and the routes must be re-applied to the React router\n await generateRuntimeFile(urls.code, runtimeRoutesCode, jsonWritten);\n if (debug) {\n logger.info(`File Route module is generated: ${String(urls.code)}`);\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,OAAO,UAAU,iBAAiB;AAE3C,OAAO,kBAAkB;AACzB,OAAO,6BAA6C;AACpD,OAAO,0BAA0B;AACjC,OAAO,0BAA0B;AA+BjC,eAAe,oBAAoB,KAAU,MAAc,YAAwC;AACjG,QAAM,MAAM,IAAI,IAAI,MAAM,GAAG,GAAG,EAAE,WAAW,KAAK,CAAC;AACnD,MAAI,cAAc,cAAc;AAChC,MAAI,CAAC,YAAY;AACf,QAAI;AACJ,QAAI;AACF,iBAAW,MAAM,SAAS,KAAK,OAAO;AAAA,IACxC,SAAS,GAAY;AACnB,UAAI,EAAE,KAAK,QAAQ,OAAO,MAAM,YAAY,UAAU,KAAK,EAAE,SAAS,WAAW;AAC/E,cAAM;AAAA,MACR;AAAA,IACF;AACA,kBAAc,aAAa;AAAA,EAC7B;AACA,MAAI,aAAa;AACf,UAAM,UAAU,KAAK,MAAM,OAAO;AAAA,EACpC;AAEA,SAAO;AACT;AAWA,eAAsB,qBACpB,UACA,MACA,YACA,QACA,OACe;AACf,MAAI;AACJ,MAAI;AACF,gBAAY,MAAM,oBAAoB,UAAU,EAAE,YAAY,OAAO,CAAC;AAAA,EACxE,SAAS,GAAY;AACnB,QAAI,aAAa,SAAS,UAAU,KAAK,EAAE,SAAS,UAAU;AAC5D,kBAAY,CAAC;AAAA,IACf,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI,OAAO;AACT,WAAO,KAAK,6BAA6B;AAAA,EAC3C;AACA,cAAY,MAAM,aAAa,WAAW,KAAK,OAAO;AACtD,QAAM,oBAAoB,qBAAqB,WAAW,IAAI;AAC9D,QAAM,iBAAiB,MAAM,qBAAqB,SAAS;AAE3D,QAAM,cAAc,MAAM,oBAAoB,KAAK,MAAM,cAAc;AACvE,MAAI,OAAO;AACT,WAAO,KAAK,qCAAqC,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,EACtE;AAIA,QAAM,oBAAoB,KAAK,MAAM,mBAAmB,WAAW;AACnE,MAAI,OAAO;AACT,WAAO,KAAK,mCAAmC,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,EACpE;AACF;",
4
+ "sourcesContent": ["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport type { Logger } from 'vite';\nimport applyLayouts from './applyLayouts.js';\nimport collectRoutesFromFS, { type RouteMeta } from './collectRoutesFromFS.js';\nimport createRoutesFromMeta from './createRoutesFromMeta.js';\nimport createViewConfigJson from './createViewConfigJson.js';\n\n/**\n * The URLs of the files to generate.\n */\nexport type RuntimeFileUrls = Readonly<{\n /**\n * The URL of the JSON file with the leaf routes and their metadata. This file\n * will be processed by the server to provide the final route configuration.\n */\n json: URL;\n /**\n * The URL of the module with the routes tree in a framework-agnostic format.\n */\n code: URL;\n /**\n * The URL of the JSON file containing server layout path information.\n */\n layouts: URL;\n}>;\n\n/**\n * Generates a file conditionally. If the file already exists and its content is the same as the\n * given data, the file will not be overwritten. It is useful to avoid unnecessary server\n * reboot during development.\n *\n * @param url - The URL of the file to generate.\n * @param data - The data to write to the file.\n * @param forceWrite - true to force writing the file even if there are no changes\n * @returns true if the file was written, false otherwise.\n */\nasync function generateRuntimeFile(url: URL, data: string, forceWrite?: boolean): Promise<boolean> {\n await mkdir(new URL('./', url), { recursive: true });\n let shouldWrite = forceWrite ?? false;\n if (!forceWrite) {\n let contents: string | undefined;\n try {\n contents = await readFile(url, 'utf-8');\n } catch (e: unknown) {\n if (!(e != null && typeof e === 'object' && 'code' in e && e.code === 'ENOENT')) {\n throw e;\n }\n }\n shouldWrite = contents !== data;\n }\n if (shouldWrite) {\n await writeFile(url, data, 'utf-8');\n }\n\n return shouldWrite;\n}\n\n/**\n * Collects all file-based routes from the given directory, and based on them generates two files\n * described by {@link RuntimeFileUrls} type.\n * @param viewsDir - The directory that contains file-based routes (views).\n * @param urls - The URLs of the files to generate.\n * @param extensions - The list of extensions that will be collected as routes.\n * @param logger - The Vite logger instance.\n * @param debug - true to debug\n */\n// eslint-disable-next-line @typescript-eslint/max-params\nexport async function generateRuntimeFiles(\n viewsDir: URL,\n urls: RuntimeFileUrls,\n extensions: readonly string[],\n logger: Logger,\n debug: boolean,\n): Promise<void> {\n let routeMeta: readonly RouteMeta[];\n try {\n routeMeta = await collectRoutesFromFS(viewsDir, { extensions, logger });\n } catch (e: unknown) {\n if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {\n routeMeta = [];\n } else {\n throw e;\n }\n }\n\n if (debug) {\n logger.info('Collected file-based routes');\n }\n routeMeta = await applyLayouts(routeMeta, urls.layouts);\n const runtimeRoutesCode = createRoutesFromMeta(routeMeta, urls);\n const viewConfigJson = await createViewConfigJson(routeMeta);\n\n const jsonWritten = await generateRuntimeFile(urls.json, viewConfigJson);\n if (debug) {\n logger.info(`Frontend route list is generated: ${String(urls.json)}`);\n }\n // If the metadata has changed, we need to write the TS file also to make Vite HMR updates work properly.\n // Even though the contents of the TS file does not change, the contents of the files imported in the TS\n // files changes and the routes must be re-applied to the React router\n await generateRuntimeFile(urls.code, runtimeRoutesCode, jsonWritten);\n if (debug) {\n logger.info(`File Route module is generated: ${String(urls.code)}`);\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,OAAO,UAAU,iBAAiB;AAE3C,OAAO,kBAAkB;AACzB,OAAO,6BAA6C;AACpD,OAAO,0BAA0B;AACjC,OAAO,0BAA0B;AA+BjC,eAAe,oBAAoB,KAAU,MAAc,YAAwC;AACjG,QAAM,MAAM,IAAI,IAAI,MAAM,GAAG,GAAG,EAAE,WAAW,KAAK,CAAC;AACnD,MAAI,cAAc,cAAc;AAChC,MAAI,CAAC,YAAY;AACf,QAAI;AACJ,QAAI;AACF,iBAAW,MAAM,SAAS,KAAK,OAAO;AAAA,IACxC,SAAS,GAAY;AACnB,UAAI,EAAE,KAAK,QAAQ,OAAO,MAAM,YAAY,UAAU,KAAK,EAAE,SAAS,WAAW;AAC/E,cAAM;AAAA,MACR;AAAA,IACF;AACA,kBAAc,aAAa;AAAA,EAC7B;AACA,MAAI,aAAa;AACf,UAAM,UAAU,KAAK,MAAM,OAAO;AAAA,EACpC;AAEA,SAAO;AACT;AAYA,eAAsB,qBACpB,UACA,MACA,YACA,QACA,OACe;AACf,MAAI;AACJ,MAAI;AACF,gBAAY,MAAM,oBAAoB,UAAU,EAAE,YAAY,OAAO,CAAC;AAAA,EACxE,SAAS,GAAY;AACnB,QAAI,aAAa,SAAS,UAAU,KAAK,EAAE,SAAS,UAAU;AAC5D,kBAAY,CAAC;AAAA,IACf,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI,OAAO;AACT,WAAO,KAAK,6BAA6B;AAAA,EAC3C;AACA,cAAY,MAAM,aAAa,WAAW,KAAK,OAAO;AACtD,QAAM,oBAAoB,qBAAqB,WAAW,IAAI;AAC9D,QAAM,iBAAiB,MAAM,qBAAqB,SAAS;AAE3D,QAAM,cAAc,MAAM,oBAAoB,KAAK,MAAM,cAAc;AACvE,MAAI,OAAO;AACT,WAAO,KAAK,qCAAqC,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,EACtE;AAIA,QAAM,oBAAoB,KAAK,MAAM,mBAAmB,WAAW;AACnE,MAAI,OAAO;AACT,WAAO,KAAK,mCAAmC,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,EACpE;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/vite-plugin/utils.ts"],
4
- "sourcesContent": ["import { RouteParamType } from '../shared/routeParamType.js';\n\nexport const routeParamTypeMap: ReadonlyMap<RouteParamType, RegExp> = new Map([\n [RouteParamType.Wildcard, /\\{\\.\\.\\.(.+)\\}/gu], // e.g. \"{...wildcard}\"\n [RouteParamType.Optional, /\\{\\{(.+)\\}\\}/gu], // e.g. \"{{param}}\"\n [RouteParamType.Required, /\\{(.+)\\}/gu], // e.g. \"{param}\"\n]);\n\n// eslint-disable-next-line consistent-return\nfunction getReplacer(type: RouteParamType): string {\n // eslint-disable-next-line default-case\n switch (type) {\n case RouteParamType.Wildcard:\n return '*';\n case RouteParamType.Optional:\n return ':$1?';\n case RouteParamType.Required:\n return ':$1';\n }\n}\n\n/**\n * Converts a file system pattern to an URL pattern string.\n *\n * @param segment - a string representing a file system pattern:\n * - `{param}` - for a required single parameter;\n * - `{{param}}` - for an optional single parameter;\n * - `{...wildcard}` - for multiple parameters, including none.\n *\n * @returns a string representing a URL pattern, respectively:\n * - `:param`;\n * - `:param?`;\n * - `*`.\n */\nexport function convertFSRouteSegmentToURLPatternFormat(segment: string): string {\n let res = segment;\n\n routeParamTypeMap.forEach((pattern, type) => {\n res = res.replaceAll(pattern, getReplacer(type));\n });\n\n return res;\n}\n\n/**\n * Extracts the parameter name and its type from the route segment.\n *\n * @param segment - A part of the FS route URL.\n * @returns A map of parameter names and their types.\n */\nexport function extractParameterFromRouteSegment(segment: string): Readonly<Record<string, RouteParamType>> {\n let _segment = segment;\n const params: Record<string, RouteParamType> = {};\n\n for (const [type, pattern] of routeParamTypeMap) {\n const _pattern = new RegExp(pattern.source, pattern.flags);\n _segment = _segment.replaceAll(_pattern, (match) => {\n const key = match.replaceAll(pattern, getReplacer(type));\n params[key] = type;\n return '';\n });\n }\n\n return params;\n}\n\n/**\n * A small helper function that clears route path of the control characters in\n * order to sort the routes alphabetically.\n */\nexport function cleanUp(path: string): string {\n let res = path;\n\n for (const pattern of routeParamTypeMap.values()) {\n res = res.replaceAll(pattern, '$1');\n }\n\n return res;\n}\n"],
4
+ "sourcesContent": ["import { RouteParamType } from '../shared/routeParamType.js';\n\nexport const routeParamTypeMap: ReadonlyMap<RouteParamType, RegExp> = new Map([\n [RouteParamType.Wildcard, /\\{\\.\\.\\.(.+)\\}/gu], // e.g. \"{...wildcard}\"\n [RouteParamType.Optional, /\\{\\{(.+)\\}\\}/gu], // e.g. \"{{param}}\"\n [RouteParamType.Required, /\\{(.+)\\}/gu], // e.g. \"{param}\"\n]);\n\n// eslint-disable-next-line @typescript-eslint/consistent-return\nfunction getReplacer(type: RouteParamType): string {\n // eslint-disable-next-line default-case\n switch (type) {\n case RouteParamType.Wildcard:\n return '*';\n case RouteParamType.Optional:\n return ':$1?';\n case RouteParamType.Required:\n return ':$1';\n }\n}\n\n/**\n * Converts a file system pattern to an URL pattern string.\n *\n * @param segment - a string representing a file system pattern:\n * - `{param}` - for a required single parameter;\n * - `{{param}}` - for an optional single parameter;\n * - `{...wildcard}` - for multiple parameters, including none.\n *\n * @returns a string representing a URL pattern, respectively:\n * - `:param`;\n * - `:param?`;\n * - `*`.\n */\nexport function convertFSRouteSegmentToURLPatternFormat(segment: string): string {\n let res = segment;\n\n routeParamTypeMap.forEach((pattern, type) => {\n res = res.replaceAll(pattern, getReplacer(type));\n });\n\n return res;\n}\n\n/**\n * Extracts the parameter name and its type from the route segment.\n *\n * @param segment - A part of the FS route URL.\n * @returns A map of parameter names and their types.\n */\nexport function extractParameterFromRouteSegment(segment: string): Readonly<Record<string, RouteParamType>> {\n let _segment = segment;\n const params: Record<string, RouteParamType> = {};\n\n for (const [type, pattern] of routeParamTypeMap) {\n const _pattern = new RegExp(pattern.source, pattern.flags);\n _segment = _segment.replaceAll(_pattern, (match) => {\n const key = match.replaceAll(pattern, getReplacer(type));\n params[key] = type;\n return '';\n });\n }\n\n return params;\n}\n\n/**\n * A small helper function that clears route path of the control characters in\n * order to sort the routes alphabetically.\n */\nexport function cleanUp(path: string): string {\n let res = path;\n\n for (const pattern of routeParamTypeMap.values()) {\n res = res.replaceAll(pattern, '$1');\n }\n\n return res;\n}\n"],
5
5
  "mappings": "AAAA,SAAS,sBAAsB;AAExB,MAAM,oBAAyD,oBAAI,IAAI;AAAA,EAC5E,CAAC,eAAe,UAAU,kBAAkB;AAAA;AAAA,EAC5C,CAAC,eAAe,UAAU,gBAAgB;AAAA;AAAA,EAC1C,CAAC,eAAe,UAAU,YAAY;AAAA;AACxC,CAAC;AAGD,SAAS,YAAY,MAA8B;AAEjD,UAAQ,MAAM;AAAA,IACZ,KAAK,eAAe;AAClB,aAAO;AAAA,IACT,KAAK,eAAe;AAClB,aAAO;AAAA,IACT,KAAK,eAAe;AAClB,aAAO;AAAA,EACX;AACF;AAeO,SAAS,wCAAwC,SAAyB;AAC/E,MAAI,MAAM;AAEV,oBAAkB,QAAQ,CAAC,SAAS,SAAS;AAC3C,UAAM,IAAI,WAAW,SAAS,YAAY,IAAI,CAAC;AAAA,EACjD,CAAC;AAED,SAAO;AACT;AAQO,SAAS,iCAAiC,SAA2D;AAC1G,MAAI,WAAW;AACf,QAAM,SAAyC,CAAC;AAEhD,aAAW,CAAC,MAAM,OAAO,KAAK,mBAAmB;AAC/C,UAAM,WAAW,IAAI,OAAO,QAAQ,QAAQ,QAAQ,KAAK;AACzD,eAAW,SAAS,WAAW,UAAU,CAAC,UAAU;AAClD,YAAM,MAAM,MAAM,WAAW,SAAS,YAAY,IAAI,CAAC;AACvD,aAAO,GAAG,IAAI;AACd,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAMO,SAAS,QAAQ,MAAsB;AAC5C,MAAI,MAAM;AAEV,aAAW,WAAW,kBAAkB,OAAO,GAAG;AAChD,UAAM,IAAI,WAAW,SAAS,IAAI;AAAA,EACpC;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }