@vaadin/hilla-file-router 24.7.0-alpha13 → 24.7.0-alpha15

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.7.0-alpha13",
3
+ "version": "24.7.0-alpha15",
4
4
  "description": "Hilla file-based router",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -63,9 +63,9 @@
63
63
  "react-router": "7"
64
64
  },
65
65
  "dependencies": {
66
- "@vaadin/hilla-generator-utils": "24.7.0-alpha13",
67
- "@vaadin/hilla-react-auth": "24.7.0-alpha13",
68
- "@vaadin/hilla-react-signals": "24.7.0-alpha13",
66
+ "@vaadin/hilla-generator-utils": "24.7.0-alpha15",
67
+ "@vaadin/hilla-react-auth": "24.7.0-alpha15",
68
+ "@vaadin/hilla-react-signals": "24.7.0-alpha15",
69
69
  "typescript": "5.7.3"
70
70
  }
71
71
  }
@@ -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,EAAwE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAGtH,OAAO,KAAK,EACV,aAAa,EAGb,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,UAAU,SAAS;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,SAAS,IAAI,EAAE,CAAC;CAC5B;AAaD,MAAM,MAAM,SAAS,GAAG,SAAS,WAAW,EAAE,CAAC;AAC/C,MAAM,MAAM,iBAAiB,GAAG,WAAW,EAAE,CAAC;AAE9C,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI,QAAQ,CAAC;IAChD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,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI;IAuHvF;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,mBAAmB;CAsFzD"}
@@ -4,9 +4,6 @@ import { createBrowserRouter } from "react-router";
4
4
  import { convertComponentNameToTitle } from "../shared/convertComponentNameToTitle.js";
5
5
  import { transformTree } from "../shared/transformTree.js";
6
6
  function isReactRouteModule(module) {
7
- if (!module) {
8
- return true;
9
- }
10
7
  return "default" in module && typeof module.default === "function" || "config" in module && typeof module.config === "object";
11
8
  }
12
9
  function createRouteKey(route) {
@@ -46,7 +43,7 @@ class RouterConfigurationBuilder {
46
43
  return this.update(routes, ({ original, overriding: added, children }) => {
47
44
  if (added) {
48
45
  const { module, path, flowLayout } = added;
49
- if (!isReactRouteModule(module)) {
46
+ if (module && !isReactRouteModule(module)) {
50
47
  throw new Error(
51
48
  `The module for the "${path}" section doesn't have the React component exported by default or a ViewConfig object exported as "config"`
52
49
  );
@@ -138,24 +135,24 @@ class RouterConfigurationBuilder {
138
135
  if (flag === true) {
139
136
  lists.server.push({
140
137
  ...route,
141
- children: server.length + ambivalent.length > 0 ? [...server, ...ambivalent] : void 0
138
+ children: route.children ? [...server, ...ambivalent] : void 0
142
139
  });
143
140
  } else if (server.length > 0) {
144
141
  lists.server.push({
145
142
  ...route,
146
- children: server
143
+ children: route.children ? server : void 0
147
144
  });
148
145
  }
149
146
  if (flag === false || client.length > 0) {
150
147
  lists.client.push({
151
148
  ...route,
152
- children: client.length > 0 ? client : void 0
149
+ children: route.children ? client : void 0
153
150
  });
154
151
  }
155
152
  if (flag === void 0 && (lists.server.every(({ path }) => path !== route.path) || ambivalent.length > 0)) {
156
153
  lists.ambivalent.push({
157
154
  ...route,
158
- children: ambivalent.length > 0 ? ambivalent : void 0
155
+ children: route.children ? ambivalent : void 0
159
156
  });
160
157
  }
161
158
  return lists;
@@ -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 { 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,qB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H,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> {\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 (module && !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: route.children ? [...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: route.children ? server : undefined,\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: route.children ? 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: route.children ? 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,QAAsD;AAChF,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;AAClB,EAAAA,kBAAA,kBAAe;AAHZ,SAAAA;AAAA,GAAA;AAML,SAAS,mBAA+C,OAAoB,MAA8B;AACxG,MAAI,OAAO,MAAM,WAAW,YAAY,QAAQ,MAAM,QAAQ;AAC5D,WAAQ,MAAM,OAA8B,IAAI;AAAA,EAClD;AAEA,SAAO;AACT;AAMO,MAAM,2BAA2B;AAAA,EAC7B,aAA+B,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzC,gBAAgB,QAAyB;AACvC,WAAO,KAAK,OAAO,MAAM;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,eAAe,QAAwC;AACrD,WAAO,KAAK,OAAO,QAAQ,CAAC,EAAE,UAAU,YAAY,OAAO,SA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AAO,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;",
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,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"}
1
+ {"version":3,"file":"createMenuItems.d.ts","sourceRoot":"","sources":["../src/runtime/createMenuItems.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,aAAa,CAAC;AAExD,eAAO,MAAM,WAAW;;;;;;;;aA2BH,CAAC;aAMX,CAAC;eAIQ,CAAC;YAEf,CAAH;;iBAvCsE,CAAC;AAU1E;;;;;;;GAOG;AACH,wBAAgB,eAAe,IAAI,SAAS,QAAQ,EAAE,CA4BrD"}
@@ -2,18 +2,25 @@ 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.7.0-alpha13"
5
+ version: "24.7.0-alpha15"
6
6
  });
7
7
  }
8
8
  import { signal } from "@vaadin/hilla-react-signals";
9
9
  const viewsSignal = signal(window.Vaadin?.views);
10
+ function isExcluded(value) {
11
+ return !!value.menu?.exclude;
12
+ }
13
+ function hasVariablePathSegment(path) {
14
+ return path.split("/").some((segment) => segment.startsWith(":"));
15
+ }
10
16
  function createMenuItems() {
11
17
  __REGISTER__("createMenuItems", window.Vaadin);
12
18
  const collator = new Intl.Collator("en-US");
13
19
  if (!viewsSignal.value) {
14
20
  return [];
15
21
  }
16
- return Object.entries(viewsSignal.value).filter(([_, value]) => !value.menu?.exclude).map(([path, config]) => ({
22
+ const views = Object.entries(viewsSignal.value);
23
+ return views.filter(([path, value]) => !isExcluded(value) && !hasVariablePathSegment(path)).map(([path, config]) => ({
17
24
  to: path,
18
25
  icon: config.menu?.icon,
19
26
  title: config.menu?.title ?? config.title,
@@ -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 } 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,GA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\n is: feature ? `${__NAME__}/${feature}` : __NAME__,\n version: __VERSION__,\n });\n}\n", "/// <reference types=\"vite/client\" />\nimport { 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\nfunction isExcluded(value: ViewConfig): boolean {\n return !!value.menu?.exclude;\n}\n\nfunction hasVariablePathSegment(path: string): boolean {\n return path.split('/').some((segment) => segment.startsWith(':'));\n}\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 const views = Object.entries(viewsSignal.value);\n\n return (\n views\n // Filter out the views that are explicitly excluded from the menu.\n .filter(([path, value]) => !isExcluded(value) && !hasVariablePathSegment(path))\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\nif (import.meta.hot) {\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
+ "mapp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