@vaadin/hilla-file-router 24.4.0-alpha4 → 24.4.0-alpha6
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 +20 -10
- package/runtime/createMenuItems.d.ts +44 -0
- package/runtime/createMenuItems.d.ts.map +1 -0
- package/runtime/createMenuItems.js +17 -0
- package/runtime/createMenuItems.js.map +7 -0
- package/runtime/createRoute.d.ts +13 -0
- package/runtime/createRoute.d.ts.map +1 -0
- package/runtime/createRoute.js +17 -0
- package/runtime/createRoute.js.map +7 -0
- package/runtime/toReactRouter.d.ts +12 -0
- package/runtime/toReactRouter.d.ts.map +1 -0
- package/runtime/toReactRouter.js +25 -0
- package/runtime/toReactRouter.js.map +7 -0
- package/runtime/useViewConfig.d.ts +6 -0
- package/runtime/useViewConfig.d.ts.map +1 -0
- package/runtime/useViewConfig.js +9 -0
- package/runtime/useViewConfig.js.map +7 -0
- package/runtime/utils.d.ts +9 -56
- package/runtime/utils.d.ts.map +1 -1
- package/runtime/utils.js +0 -22
- package/runtime/utils.js.map +2 -2
- package/runtime.d.ts +4 -17
- package/runtime.d.ts.map +1 -1
- package/runtime.js +4 -27
- package/runtime.js.map +2 -2
- package/shared/convertComponentNameToTitle.d.ts +9 -0
- package/shared/convertComponentNameToTitle.d.ts.map +1 -0
- package/shared/convertComponentNameToTitle.js +18 -0
- package/shared/convertComponentNameToTitle.js.map +7 -0
- package/shared/routeParamType.d.ts +9 -0
- package/shared/routeParamType.d.ts.map +1 -0
- package/shared/routeParamType.js +10 -0
- package/shared/routeParamType.js.map +7 -0
- package/shared/traverse.d.ts +10 -0
- package/shared/traverse.d.ts.map +1 -0
- package/shared/traverse.js +14 -0
- package/shared/traverse.js.map +7 -0
- package/types.d.js +1 -0
- package/types.d.js.map +7 -0
- package/types.d.ts +83 -0
- package/vite-plugin/collectRoutesFromFS.d.ts +16 -0
- package/vite-plugin/collectRoutesFromFS.d.ts.map +1 -1
- package/vite-plugin/collectRoutesFromFS.js.map +2 -2
- package/vite-plugin/createRoutesFromMeta.d.ts +8 -1
- package/vite-plugin/createRoutesFromMeta.d.ts.map +1 -1
- package/vite-plugin/createRoutesFromMeta.js +15 -13
- package/vite-plugin/createRoutesFromMeta.js.map +2 -2
- package/vite-plugin/createViewConfigJson.d.ts +7 -1
- package/vite-plugin/createViewConfigJson.d.ts.map +1 -1
- package/vite-plugin/createViewConfigJson.js +36 -22
- package/vite-plugin/createViewConfigJson.js.map +2 -2
- package/vite-plugin/generateRuntimeFiles.d.ts +25 -0
- package/vite-plugin/generateRuntimeFiles.d.ts.map +1 -0
- package/vite-plugin/generateRuntimeFiles.js +36 -0
- package/vite-plugin/generateRuntimeFiles.js.map +7 -0
- package/vite-plugin/utils.d.ts +11 -3
- package/vite-plugin/utils.d.ts.map +1 -1
- package/vite-plugin/utils.js +42 -7
- package/vite-plugin/utils.js.map +2 -2
- package/{vite-plugin-file-router.d.ts → vite-plugin.d.ts} +5 -9
- package/vite-plugin.d.ts.map +1 -0
- package/vite-plugin.js +54 -0
- package/vite-plugin.js.map +7 -0
- package/vite-plugin-file-router.d.ts.map +0 -1
- package/vite-plugin-file-router.js +0 -57
- package/vite-plugin-file-router.js.map +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-file-router",
|
|
3
|
-
"version": "24.4.0-
|
|
3
|
+
"version": "24.4.0-alpha6",
|
|
4
4
|
"description": "Hilla file-based router",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -34,8 +34,11 @@
|
|
|
34
34
|
"./runtime.js": {
|
|
35
35
|
"default": "./runtime.js"
|
|
36
36
|
},
|
|
37
|
-
"./
|
|
38
|
-
"
|
|
37
|
+
"./types.js": {
|
|
38
|
+
"types": "./types.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./vite-plugin.js": {
|
|
41
|
+
"default": "./vite-plugin.js"
|
|
39
42
|
}
|
|
40
43
|
},
|
|
41
44
|
"author": "Vaadin Ltd",
|
|
@@ -47,30 +50,37 @@
|
|
|
47
50
|
"files": [
|
|
48
51
|
"*.{d.ts.map,d.ts,js.map,js}",
|
|
49
52
|
"runtime",
|
|
53
|
+
"shared",
|
|
50
54
|
"vite-plugin"
|
|
51
55
|
],
|
|
52
56
|
"publishConfig": {
|
|
53
57
|
"access": "public"
|
|
54
58
|
},
|
|
55
59
|
"peerDependencies": {
|
|
56
|
-
"react
|
|
60
|
+
"react": "^18.2.0",
|
|
61
|
+
"react-router": "^6.21.1",
|
|
62
|
+
"react-router-dom": "^6.21.1"
|
|
57
63
|
},
|
|
58
64
|
"devDependencies": {
|
|
59
65
|
"@esm-bundle/chai": "^4.3.4-fix.0",
|
|
66
|
+
"@types/chai-as-promised": "^7.1.8",
|
|
67
|
+
"@types/chai-fs": "^2.0.4",
|
|
60
68
|
"@types/chai-like": "^1.1.3",
|
|
61
69
|
"@types/deep-equal-in-any-order": "^1.0.3",
|
|
62
70
|
"@types/mocha": "^10.0.6",
|
|
63
|
-
"@types/sinon": "^
|
|
71
|
+
"@types/sinon": "^10.0.17",
|
|
72
|
+
"chai-as-promised": "^7.1.1",
|
|
73
|
+
"chai-fs": "^2.0.0",
|
|
64
74
|
"chai-like": "^1.1.1",
|
|
65
75
|
"deep-equal-in-any-order": "^2.0.6",
|
|
66
76
|
"mocha": "^10.2.0",
|
|
67
77
|
"rimraf": "^5.0.5",
|
|
68
|
-
"sinon": "^
|
|
69
|
-
"type-fest": "^4.9.0"
|
|
70
|
-
"typescript": "^5.3.3"
|
|
78
|
+
"sinon": "^16.0.0",
|
|
79
|
+
"type-fest": "^4.9.0"
|
|
71
80
|
},
|
|
72
81
|
"dependencies": {
|
|
73
|
-
"@vaadin/hilla-generator-utils": "24.4.0-
|
|
74
|
-
"react": "^18.2.0"
|
|
82
|
+
"@vaadin/hilla-generator-utils": "24.4.0-alpha6",
|
|
83
|
+
"react": "^18.2.0",
|
|
84
|
+
"typescript": "5.3.2"
|
|
75
85
|
}
|
|
76
86
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RouteParamType } from '../shared/routeParamType.js';
|
|
2
|
+
import type { ViewConfig } from '../types.js';
|
|
3
|
+
export type VaadinServer = Readonly<{
|
|
4
|
+
views: Record<string, ViewConfig>;
|
|
5
|
+
}>;
|
|
6
|
+
export type VaadinObject = Readonly<{
|
|
7
|
+
server?: VaadinServer;
|
|
8
|
+
}>;
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
Vaadin?: VaadinObject;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export type MenuItem = Readonly<{
|
|
15
|
+
to: string;
|
|
16
|
+
icon?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates menu items from the views provided by the server. The views are sorted according to the
|
|
21
|
+
* {@link ViewConfig.menu.order} and filtered out if they are explicitly excluded via {@link ViewConfig.menu.exclude}.
|
|
22
|
+
*
|
|
23
|
+
* @param vaadinObject - The Vaadin object containing the server views.
|
|
24
|
+
* @returns A list of menu items.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createMenuItems(vaadinObject?: Readonly<{
|
|
27
|
+
server?: Readonly<{
|
|
28
|
+
views: Record<string, Readonly<{
|
|
29
|
+
title?: string | undefined;
|
|
30
|
+
params?: Readonly<Record<string, RouteParamType>> | undefined;
|
|
31
|
+
rolesAllowed?: string[] | undefined;
|
|
32
|
+
route?: string | undefined;
|
|
33
|
+
lazy?: boolean | undefined;
|
|
34
|
+
register?: boolean | undefined;
|
|
35
|
+
menu?: Readonly<{
|
|
36
|
+
title?: string | undefined;
|
|
37
|
+
order?: number | undefined;
|
|
38
|
+
exclude?: boolean | undefined;
|
|
39
|
+
icon?: string | undefined;
|
|
40
|
+
}> | undefined;
|
|
41
|
+
}>>;
|
|
42
|
+
}> | undefined;
|
|
43
|
+
}> | undefined): readonly MenuItem[];
|
|
44
|
+
//# sourceMappingURL=createMenuItems.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMenuItems.d.ts","sourceRoot":"","sources":["../src/runtime/createMenuItems.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACnC,CAAC,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC;IAClC,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC,CAAC;AAEH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,CAAC,EAAE,YAAY,CAAC;KACvB;CACF;AAED,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,YAAY;;;;;;;;;;;;;;;;;cAAgB,GAAG,SAAS,QAAQ,EAAE,CAwBjF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RouteParamType } from "../shared/routeParamType.js";
|
|
2
|
+
function createMenuItems(vaadinObject = window.Vaadin) {
|
|
3
|
+
return vaadinObject?.server?.views ? Object.entries(vaadinObject.server.views).filter(
|
|
4
|
+
([_key, value]) => !value.menu?.exclude && !(value.params && Object.values(value.params).some((p) => p === RouteParamType.Required))
|
|
5
|
+
).sort(([_a, a], [_b, b]) => (a.menu?.order ?? 0) - (b.menu?.order ?? 0)).map(([path, config]) => {
|
|
6
|
+
const _path = config.params ? Object.keys(config.params).reduce((acc, key) => acc.replaceAll(key, ""), path) : path;
|
|
7
|
+
return {
|
|
8
|
+
to: _path,
|
|
9
|
+
icon: config.menu?.icon,
|
|
10
|
+
title: config.menu?.title ?? config.title
|
|
11
|
+
};
|
|
12
|
+
}) : [];
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
createMenuItems
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=createMenuItems.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/runtime/createMenuItems.ts"],
|
|
4
|
+
"sourcesContent": ["import { RouteParamType } from '../shared/routeParamType.js';\nimport type { ViewConfig } from '../types.js';\n\nexport type VaadinServer = Readonly<{\n views: Record<string, ViewConfig>;\n}>;\n\nexport type VaadinObject = Readonly<{\n server?: VaadinServer;\n}>;\n\ndeclare global {\n interface Window {\n Vaadin?: VaadinObject;\n }\n}\n\nexport type MenuItem = Readonly<{\n to: string;\n icon?: string;\n title?: string;\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} and filtered out if they are explicitly excluded via {@link ViewConfig.menu.exclude}.\n *\n * @param vaadinObject - The Vaadin object containing the server views.\n * @returns A list of menu items.\n */\nexport function createMenuItems(vaadinObject = window.Vaadin): readonly MenuItem[] {\n return vaadinObject?.server?.views\n ? Object.entries(vaadinObject.server.views)\n // Filter out the views that are explicitly excluded from the menu.\n .filter(\n ([_key, value]) =>\n !value.menu?.exclude &&\n !(value.params && Object.values(value.params).some((p) => p === RouteParamType.Required)),\n )\n // Sort views according to the order specified in the view configuration.\n .sort(([_a, a], [_b, b]) => (a.menu?.order ?? 0) - (b.menu?.order ?? 0))\n // Map the views to menu items.\n .map(([path, config]) => {\n const _path = config.params\n ? Object.keys(config.params).reduce((acc, key) => acc.replaceAll(key, ''), path)\n : path;\n\n return {\n to: _path,\n icon: config.menu?.icon,\n title: config.menu?.title ?? config.title,\n };\n })\n : [];\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,sBAAsB;AA8BxB,SAAS,gBAAgB,eAAe,OAAO,QAA6B;AACjF,SAAO,cAAc,QAAQ,QACzB,OAAO,QAAQ,aAAa,OAAO,KAAK,EAErC;AAAA,IACC,CAAC,CAAC,MAAM,KAAK,MACX,CAAC,MAAM,MAAM,WACb,EAAE,MAAM,UAAU,OAAO,OAAO,MAAM,MAAM,EAAE,KAAK,CAAC,MAAM,MAAM,eAAe,QAAQ;AAAA,EAC3F,EAEC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,SAAS,MAAM,EAAE,MAAM,SAAS,EAAE,EAEtE,IAAI,CAAC,CAAC,MAAM,MAAM,MAAM;AACvB,UAAM,QAAQ,OAAO,SACjB,OAAO,KAAK,OAAO,MAAM,EAAE,OAAO,CAAC,KAAK,QAAQ,IAAI,WAAW,KAAK,EAAE,GAAG,IAAI,IAC7E;AAEJ,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,MAAM,OAAO,MAAM;AAAA,MACnB,OAAO,OAAO,MAAM,SAAS,OAAO;AAAA,IACtC;AAAA,EACF,CAAC,IACH,CAAC;AACP;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgnosticRoute, RouteModule } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a single framework-agnostic route object. Later, it can be transformed into a framework-specific route object,
|
|
4
|
+
* e.g., the one used by React Router.
|
|
5
|
+
*
|
|
6
|
+
* @param path - A route path segment.
|
|
7
|
+
* @param children - An array of child routes.
|
|
8
|
+
*
|
|
9
|
+
* @returns A framework-agnostic route object.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createRoute<C = unknown>(path: string, children?: ReadonlyArray<AgnosticRoute<C>>): AgnosticRoute<C>;
|
|
12
|
+
export declare function createRoute<C = unknown>(path: string, module: RouteModule<C>, children?: ReadonlyArray<AgnosticRoute<C>>): AgnosticRoute<C>;
|
|
13
|
+
//# sourceMappingURL=createRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRoute.d.ts","sourceRoot":"","sources":["../src/runtime/createRoute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE9D;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AACrH,wBAAgB,WAAW,CAAC,CAAC,GAAG,OAAO,EACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,QAAQ,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GACzC,aAAa,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function createRoute(path, moduleOrChildren, children) {
|
|
2
|
+
let module;
|
|
3
|
+
if (Array.isArray(moduleOrChildren)) {
|
|
4
|
+
children = moduleOrChildren;
|
|
5
|
+
} else {
|
|
6
|
+
module = moduleOrChildren;
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
path: module?.config?.route ?? path,
|
|
10
|
+
module,
|
|
11
|
+
children
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
createRoute
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=createRoute.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/runtime/createRoute.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-param-reassign */\nimport type { AgnosticRoute, RouteModule } from '../types.js';\n\n/**\n * Create a single framework-agnostic route object. Later, it can be transformed into a framework-specific route object,\n * e.g., the one used by React Router.\n *\n * @param path - A route path segment.\n * @param children - An array of child routes.\n *\n * @returns A framework-agnostic route object.\n */\nexport function createRoute<C = unknown>(path: string, children?: ReadonlyArray<AgnosticRoute<C>>): AgnosticRoute<C>;\nexport function createRoute<C = unknown>(\n path: string,\n module: RouteModule<C>,\n children?: ReadonlyArray<AgnosticRoute<C>>,\n): AgnosticRoute<C>;\nexport function createRoute<C = unknown>(\n path: string,\n moduleOrChildren?: ReadonlyArray<AgnosticRoute<C>> | RouteModule<C>,\n children?: ReadonlyArray<AgnosticRoute<C>>,\n): AgnosticRoute<C> {\n let module: RouteModule<C> | undefined;\n if (Array.isArray(moduleOrChildren)) {\n children = moduleOrChildren;\n } else {\n module = moduleOrChildren as RouteModule<C> | undefined;\n }\n\n return {\n path: module?.config?.route ?? path,\n module,\n children,\n };\n}\n"],
|
|
5
|
+
"mappings": "AAkBO,SAAS,YACd,MACA,kBACA,UACkB;AAClB,MAAI;AACJ,MAAI,MAAM,QAAQ,gBAAgB,GAAG;AACnC,eAAW;AAAA,EACb,OAAO;AACL,aAAS;AAAA,EACX;AAEA,SAAO;AAAA,IACL,MAAM,QAAQ,QAAQ,SAAS;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ComponentType } from 'react';
|
|
2
|
+
import type { RouteObject } from 'react-router';
|
|
3
|
+
import type { AgnosticRoute } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Transforms framework-agnostic route tree into a format that can be used by React Router.
|
|
6
|
+
*
|
|
7
|
+
* @param routes - Generated routes
|
|
8
|
+
*
|
|
9
|
+
* @returns The React Router tree.
|
|
10
|
+
*/
|
|
11
|
+
export declare function toReactRouter(routes: AgnosticRoute<ComponentType>): RouteObject;
|
|
12
|
+
//# sourceMappingURL=toReactRouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toReactRouter.d.ts","sourceRoot":"","sources":["../src/runtime/toReactRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,OAAO,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,GAAG,WAAW,CAkB/E"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
import { convertComponentNameToTitle } from "../shared/convertComponentNameToTitle.js";
|
|
3
|
+
import { transformRoute } from "./utils.js";
|
|
4
|
+
function toReactRouter(routes) {
|
|
5
|
+
return transformRoute(
|
|
6
|
+
routes,
|
|
7
|
+
(route) => route.children?.values(),
|
|
8
|
+
({ path, module }, children) => {
|
|
9
|
+
const title = module?.config?.title ?? convertComponentNameToTitle(module?.default);
|
|
10
|
+
return {
|
|
11
|
+
path,
|
|
12
|
+
element: module?.default ? createElement(module.default) : void 0,
|
|
13
|
+
children: children.length > 0 ? children : void 0,
|
|
14
|
+
handle: {
|
|
15
|
+
...module?.config,
|
|
16
|
+
title
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
toReactRouter
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=toReactRouter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/runtime/toReactRouter.ts"],
|
|
4
|
+
"sourcesContent": ["import { type ComponentType, createElement } from 'react';\nimport type { RouteObject } from 'react-router';\nimport { convertComponentNameToTitle } from '../shared/convertComponentNameToTitle.js';\nimport type { AgnosticRoute } from '../types.js';\nimport { transformRoute } from './utils.js';\n\n/**\n * Transforms framework-agnostic route tree into a format that can be used by React Router.\n *\n * @param routes - Generated routes\n *\n * @returns The React Router tree.\n */\nexport function toReactRouter(routes: AgnosticRoute<ComponentType>): RouteObject {\n return transformRoute(\n routes,\n (route) => route.children?.values(),\n ({ path, module }, children) => {\n const title = module?.config?.title ?? convertComponentNameToTitle(module?.default);\n\n return {\n path,\n element: module?.default ? createElement(module.default) : undefined,\n children: children.length > 0 ? (children as RouteObject[]) : undefined,\n handle: {\n ...module?.config,\n title,\n },\n } satisfies RouteObject;\n },\n );\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAA6B,qBAAqB;AAElD,SAAS,mCAAmC;AAE5C,SAAS,sBAAsB;AASxB,SAAS,cAAc,QAAmD;AAC/E,SAAO;AAAA,IACL;AAAA,IACA,CAAC,UAAU,MAAM,UAAU,OAAO;AAAA,IAClC,CAAC,EAAE,MAAM,OAAO,GAAG,aAAa;AAC9B,YAAM,QAAQ,QAAQ,QAAQ,SAAS,4BAA4B,QAAQ,OAAO;AAElF,aAAO;AAAA,QACL;AAAA,QACA,SAAS,QAAQ,UAAU,cAAc,OAAO,OAAO,IAAI;AAAA,QAC3D,UAAU,SAAS,SAAS,IAAK,WAA6B;AAAA,QAC9D,QAAQ;AAAA,UACN,GAAG,QAAQ;AAAA,UACX;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useViewConfig.d.ts","sourceRoot":"","sources":["../src/runtime/useViewConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,UAAU,KAAK,CAAC,GAAG,SAAS,CAGnE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/runtime/useViewConfig.ts"],
|
|
4
|
+
"sourcesContent": ["import type { UIMatch } from '@remix-run/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
|
+
"mappings": "AACA,SAAS,kBAAkB;AAMpB,SAAS,gBAAqD;AACnE,QAAM,UAAU,WAAW;AAC3B,SAAO,QAAQ,QAAQ,SAAS,CAAC,GAAG;AACtC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/runtime/utils.d.ts
CHANGED
|
@@ -1,58 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
rolesAllowed?: string[];
|
|
12
|
-
/**
|
|
13
|
-
* Allows overriding the route path configuration. Uses the same syntax as
|
|
14
|
-
* the path property with React Router. This can be used to define a route
|
|
15
|
-
* that conflicts with the file name conventions, e.g. /foo/index
|
|
16
|
-
*/
|
|
17
|
-
route?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Controls whether the view implementation will be lazy loaded the first time
|
|
20
|
-
* it's used or always included in the bundle. If set to undefined (which is
|
|
21
|
-
* the default), views mapped to / and /login will be eager and any other view
|
|
22
|
-
* will be lazy (this is in sync with defaults in Flow)
|
|
23
|
-
*/
|
|
24
|
-
lazy?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* If set to false, then the route will not be registered with React Router,
|
|
27
|
-
* but it will still be included in the main menu and used to configure
|
|
28
|
-
* Spring Security
|
|
29
|
-
*/
|
|
30
|
-
register?: boolean;
|
|
31
|
-
menu?: Readonly<{
|
|
32
|
-
/**
|
|
33
|
-
* Title to use in the menu. Falls back the title property of the view
|
|
34
|
-
* itself if not defined.
|
|
35
|
-
*/
|
|
36
|
-
title?: string;
|
|
37
|
-
/**
|
|
38
|
-
* Used to determine the order in the menu. Ties are resolved based on the
|
|
39
|
-
* used title. Entries without explicitly defined ordering are put below
|
|
40
|
-
* entries with an order.
|
|
41
|
-
*/
|
|
42
|
-
order?: number;
|
|
43
|
-
/**
|
|
44
|
-
* Set to true to explicitly exclude a view from the automatically
|
|
45
|
-
* populated menu.
|
|
46
|
-
*/
|
|
47
|
-
exclude?: boolean;
|
|
48
|
-
}>;
|
|
49
|
-
}>;
|
|
50
|
-
export type AgnosticRoute<T> = Readonly<{
|
|
51
|
-
path: string;
|
|
52
|
-
module?: T;
|
|
53
|
-
children?: ReadonlyArray<AgnosticRoute<T>>;
|
|
54
|
-
}>;
|
|
1
|
+
/**
|
|
2
|
+
* Transforms the whole route tree into a new format.
|
|
3
|
+
*
|
|
4
|
+
* @param route - The route to transform.
|
|
5
|
+
* @param getChildren - A function that returns the children of the route.
|
|
6
|
+
* @param transformer - A function that transforms the route and its children.
|
|
7
|
+
*
|
|
8
|
+
* @returns The transformed route.
|
|
9
|
+
*/
|
|
55
10
|
export declare function transformRoute<T, U>(route: T, getChildren: (route: T) => IterableIterator<T> | null | undefined, transformer: (route: T, children: readonly U[]) => U): U;
|
|
56
|
-
export declare function extractComponentName(component?: unknown): string | undefined;
|
|
57
|
-
export declare function adjustViewTitle(config?: ViewConfig, componentName?: string): ViewConfig | undefined;
|
|
58
11
|
//# sourceMappingURL=utils.d.ts.map
|
package/runtime/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/runtime/utils.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/runtime/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EACjC,KAAK,EAAE,CAAC,EACR,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EACjE,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,KAAK,CAAC,GACnD,CAAC,CAOH"}
|
package/runtime/utils.js
CHANGED
|
@@ -5,29 +5,7 @@ function transformRoute(route, getChildren, transformer) {
|
|
|
5
5
|
children ? Array.from(children, (child) => transformRoute(child, getChildren, transformer)) : []
|
|
6
6
|
);
|
|
7
7
|
}
|
|
8
|
-
function extractComponentName(component) {
|
|
9
|
-
if (component && (typeof component === "object" || typeof component === "function") && "name" in component && typeof component.name === "string") {
|
|
10
|
-
return component.name;
|
|
11
|
-
}
|
|
12
|
-
return void 0;
|
|
13
|
-
}
|
|
14
|
-
const viewPattern = /view/giu;
|
|
15
|
-
const upperCaseSplitPattern = /(?=[A-Z])/gu;
|
|
16
|
-
function adjustViewTitle(config, componentName) {
|
|
17
|
-
if (config?.title) {
|
|
18
|
-
return config;
|
|
19
|
-
}
|
|
20
|
-
if (componentName) {
|
|
21
|
-
return {
|
|
22
|
-
...config,
|
|
23
|
-
title: componentName.replace(viewPattern, "").split(upperCaseSplitPattern).join(" ")
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return config;
|
|
27
|
-
}
|
|
28
8
|
export {
|
|
29
|
-
adjustViewTitle,
|
|
30
|
-
extractComponentName,
|
|
31
9
|
transformRoute
|
|
32
10
|
};
|
|
33
11
|
//# sourceMappingURL=utils.js.map
|
package/runtime/utils.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/runtime/utils.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Transforms the whole route tree into a new format.\n *\n * @param route - The route to transform.\n * @param getChildren - A function that returns the children of the route.\n * @param transformer - A function that transforms the route and its children.\n *\n * @returns The transformed route.\n */\nexport function transformRoute<T, U>(\n route: T,\n getChildren: (route: T) => IterableIterator<T> | null | undefined,\n transformer: (route: T, children: readonly U[]) => U,\n): U {\n const children = getChildren(route);\n\n return transformer(\n route,\n children ? Array.from(children, (child) => transformRoute(child, getChildren, transformer)) : [],\n );\n}\n"],
|
|
5
|
+
"mappings": "AASO,SAAS,eACd,OACA,aACA,aACG;AACH,QAAM,WAAW,YAAY,KAAK;AAElC,SAAO;AAAA,IACL;AAAA,IACA,WAAW,MAAM,KAAK,UAAU,CAAC,UAAU,eAAe,OAAO,aAAa,WAAW,CAAC,IAAI,CAAC;AAAA,EACjG;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/runtime.d.ts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
default: ComponentType<P>;
|
|
6
|
-
config?: ViewConfig;
|
|
7
|
-
}>;
|
|
8
|
-
/**
|
|
9
|
-
* Transforms generated routes into a format that can be used by React Router.
|
|
10
|
-
*
|
|
11
|
-
* @param routes - Generated routes
|
|
12
|
-
*/
|
|
13
|
-
export declare function toReactRouter(routes: AgnosticRoute<RouteModule>): RouteObject;
|
|
14
|
-
/**
|
|
15
|
-
* Hook to return the {@link ViewConfig} for the current route.
|
|
16
|
-
*/
|
|
17
|
-
export declare function useViewConfig<M extends ViewConfig>(): M | undefined;
|
|
1
|
+
export * from './runtime/createRoute.js';
|
|
2
|
+
export * from './runtime/toReactRouter.js';
|
|
3
|
+
export * from './runtime/useViewConfig.js';
|
|
4
|
+
export * from './runtime/createMenuItems.js';
|
|
18
5
|
//# sourceMappingURL=runtime.d.ts.map
|
package/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["src/runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["src/runtime.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC"}
|
package/runtime.js
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
adjustViewTitle,
|
|
6
|
-
extractComponentName
|
|
7
|
-
} from "./runtime/utils.js";
|
|
8
|
-
function toReactRouter(routes) {
|
|
9
|
-
return transformRoute(
|
|
10
|
-
routes,
|
|
11
|
-
(route) => route.children?.values(),
|
|
12
|
-
({ path, module }, children) => ({
|
|
13
|
-
path,
|
|
14
|
-
element: module?.default ? createElement(module.default) : void 0,
|
|
15
|
-
children: children.length > 0 ? children : void 0,
|
|
16
|
-
handle: adjustViewTitle(module?.config, extractComponentName(module?.default))
|
|
17
|
-
})
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
function useViewConfig() {
|
|
21
|
-
const matches = useMatches();
|
|
22
|
-
return matches[matches.length - 1]?.handle;
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
toReactRouter,
|
|
26
|
-
useViewConfig
|
|
27
|
-
};
|
|
1
|
+
export * from "./runtime/createRoute.js";
|
|
2
|
+
export * from "./runtime/toReactRouter.js";
|
|
3
|
+
export * from "./runtime/useViewConfig.js";
|
|
4
|
+
export * from "./runtime/createMenuItems.js";
|
|
28
5
|
//# sourceMappingURL=runtime.js.map
|
package/runtime.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/runtime.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export * from './runtime/createRoute.js';\nexport * from './runtime/toReactRouter.js';\nexport * from './runtime/useViewConfig.js';\nexport * from './runtime/createMenuItems.js';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the name of the component to a page title.
|
|
3
|
+
*
|
|
4
|
+
* @param component - The component to convert the name from.
|
|
5
|
+
*
|
|
6
|
+
* @returns The page title.
|
|
7
|
+
*/
|
|
8
|
+
export declare function convertComponentNameToTitle(component?: unknown): string | undefined;
|
|
9
|
+
//# sourceMappingURL=convertComponentNameToTitle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertComponentNameToTitle.d.ts","sourceRoot":"","sources":["../src/shared/convertComponentNameToTitle.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAmBnF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const viewPattern = /view/giu;
|
|
2
|
+
const upperCaseSplitPattern = /(?=[A-Z])/gu;
|
|
3
|
+
function convertComponentNameToTitle(component) {
|
|
4
|
+
let name;
|
|
5
|
+
if (typeof component === "string") {
|
|
6
|
+
name = component;
|
|
7
|
+
} else if (component && (typeof component === "object" || typeof component === "function") && "name" in component && typeof component.name === "string") {
|
|
8
|
+
({ name } = component);
|
|
9
|
+
}
|
|
10
|
+
if (name) {
|
|
11
|
+
return name.replace(viewPattern, "").split(upperCaseSplitPattern).join(" ");
|
|
12
|
+
}
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
convertComponentNameToTitle
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=convertComponentNameToTitle.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/shared/convertComponentNameToTitle.ts"],
|
|
4
|
+
"sourcesContent": ["const viewPattern = /view/giu;\nconst upperCaseSplitPattern = /(?=[A-Z])/gu;\n\n/**\n * Converts the name of the component to a page title.\n *\n * @param component - The component to convert the name from.\n *\n * @returns The page title.\n */\nexport function convertComponentNameToTitle(component?: unknown): string | undefined {\n let name: string | undefined;\n\n if (typeof component === 'string') {\n name = component;\n } else if (\n component &&\n (typeof component === 'object' || typeof component === 'function') &&\n 'name' in component &&\n typeof component.name === 'string'\n ) {\n ({ name } = component);\n }\n\n if (name) {\n return name.replace(viewPattern, '').split(upperCaseSplitPattern).join(' ');\n }\n\n return undefined;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,MAAM,cAAc;AACpB,MAAM,wBAAwB;AASvB,SAAS,4BAA4B,WAAyC;AACnF,MAAI;AAEJ,MAAI,OAAO,cAAc,UAAU;AACjC,WAAO;AAAA,EACT,WACE,cACC,OAAO,cAAc,YAAY,OAAO,cAAc,eACvD,UAAU,aACV,OAAO,UAAU,SAAS,UAC1B;AACA,KAAC,EAAE,KAAK,IAAI;AAAA,EACd;AAEA,MAAI,MAAM;AACR,WAAO,KAAK,QAAQ,aAAa,EAAE,EAAE,MAAM,qBAAqB,EAAE,KAAK,GAAG;AAAA,EAC5E;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routeParamType.d.ts","sourceRoot":"","sources":["../src/shared/routeParamType.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,cAAc;IACxB,QAAQ,QAAQ;IAChB,QAAQ,QAAQ;IAChB,QAAQ,MAAM;CACf"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var RouteParamType = /* @__PURE__ */ ((RouteParamType2) => {
|
|
2
|
+
RouteParamType2["Required"] = "req";
|
|
3
|
+
RouteParamType2["Optional"] = "opt";
|
|
4
|
+
RouteParamType2["Wildcard"] = "*";
|
|
5
|
+
return RouteParamType2;
|
|
6
|
+
})(RouteParamType || {});
|
|
7
|
+
export {
|
|
8
|
+
RouteParamType
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=routeParamType.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/shared/routeParamType.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The type of route parameter.\n */\nexport enum RouteParamType {\n Required = 'req',\n Optional = 'opt',\n Wildcard = '*',\n}\n"],
|
|
5
|
+
"mappings": "AAGO,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,cAAW;AACX,EAAAA,gBAAA,cAAW;AACX,EAAAA,gBAAA,cAAW;AAHD,SAAAA;AAAA,GAAA;",
|
|
6
|
+
"names": ["RouteParamType"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Traverse a tree and yield the sequence of parent nodes to each leaf node.
|
|
3
|
+
*
|
|
4
|
+
* @param tree - The tree to traverse.
|
|
5
|
+
* @param parents - The sequence of parent nodes for the current node.
|
|
6
|
+
*/
|
|
7
|
+
export default function traverse<T extends {
|
|
8
|
+
children?: readonly T[];
|
|
9
|
+
}>(tree: T, parents?: readonly T[]): Generator<readonly T[], undefined, undefined>;
|
|
10
|
+
//# sourceMappingURL=traverse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../src/shared/traverse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAW,QAAQ,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAC,EAAE,CAAA;CAAE,EACrE,IAAI,EAAE,CAAC,EACP,OAAO,GAAE,SAAS,CAAC,EAAO,GACzB,SAAS,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,CAW/C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function* traverse(tree, parents = []) {
|
|
2
|
+
const chain = [...parents, tree];
|
|
3
|
+
const children = tree.children ?? [];
|
|
4
|
+
if (children.length === 0) {
|
|
5
|
+
yield chain;
|
|
6
|
+
}
|
|
7
|
+
for (const child of children) {
|
|
8
|
+
yield* traverse(child, chain);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
traverse as default
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=traverse.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/shared/traverse.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Traverse a tree and yield the sequence of parent nodes to each leaf node.\n *\n * @param tree - The tree to traverse.\n * @param parents - The sequence of parent nodes for the current node.\n */\nexport default function* traverse<T extends { children?: readonly T[] }>(\n tree: T,\n parents: readonly T[] = [],\n): Generator<readonly T[], undefined, undefined> {\n const chain = [...parents, tree];\n const children = tree.children ?? [];\n\n if (children.length === 0) {\n yield chain;\n }\n\n for (const child of children) {\n yield* traverse(child, chain);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAMe,UAAR,SACL,MACA,UAAwB,CAAC,GACsB;AAC/C,QAAM,QAAQ,CAAC,GAAG,SAAS,IAAI;AAC/B,QAAM,WAAW,KAAK,YAAY,CAAC;AAEnC,MAAI,SAAS,WAAW,GAAG;AACzB,UAAM;AAAA,EACR;AAEA,aAAW,SAAS,UAAU;AAC5B,WAAO,SAAS,OAAO,KAAK;AAAA,EAC9B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/types.d.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.d.js.map
|