@vaadin/hilla-file-router 24.4.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/.lintstagedrc.js +6 -0
- package/package.json +88 -0
- package/runtime/createMenuItems.d.ts +14 -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 +11 -0
- package/runtime/utils.d.ts.map +1 -0
- package/runtime/utils.js +11 -0
- package/runtime/utils.js.map +7 -0
- package/runtime.d.ts +5 -0
- package/runtime.d.ts.map +1 -0
- package/runtime.js +5 -0
- package/runtime.js.map +7 -0
- 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/internal.d.ts +21 -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.ts +72 -0
- package/vite-plugin/collectRoutesFromFS.d.ts +41 -0
- package/vite-plugin/collectRoutesFromFS.d.ts.map +1 -0
- package/vite-plugin/collectRoutesFromFS.js +71 -0
- package/vite-plugin/collectRoutesFromFS.js.map +7 -0
- package/vite-plugin/createRoutesFromMeta.d.ts +10 -0
- package/vite-plugin/createRoutesFromMeta.d.ts.map +1 -0
- package/vite-plugin/createRoutesFromMeta.js +79 -0
- package/vite-plugin/createRoutesFromMeta.js.map +7 -0
- package/vite-plugin/createViewConfigJson.d.ts +9 -0
- package/vite-plugin/createViewConfigJson.d.ts.map +1 -0
- package/vite-plugin/createViewConfigJson.js +70 -0
- package/vite-plugin/createViewConfigJson.js.map +7 -0
- 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 +28 -0
- package/vite-plugin/utils.d.ts.map +1 -0
- package/vite-plugin/utils.js +49 -0
- package/vite-plugin/utils.js.map +7 -0
- package/vite-plugin.d.ts +34 -0
- package/vite-plugin.d.ts.map +1 -0
- package/vite-plugin.js +70 -0
- package/vite-plugin.js.map +7 -0
package/.lintstagedrc.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vaadin/hilla-file-router",
|
|
3
|
+
"version": "24.4.0-alpha10",
|
|
4
|
+
"description": "Hilla file-based router",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"module": "index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/vaadin/hilla.git",
|
|
11
|
+
"directory": "packages/ts/hilla-file-router"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"Hilla",
|
|
15
|
+
"Vite",
|
|
16
|
+
"Plugin",
|
|
17
|
+
"File",
|
|
18
|
+
"Router",
|
|
19
|
+
"Routing"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean:build": "git clean -fx . -e .vite -e node_modules",
|
|
23
|
+
"build": "concurrently npm:build:*",
|
|
24
|
+
"build:esbuild": "tsx ../../../scripts/build.ts",
|
|
25
|
+
"build:dts": "tsc --isolatedModules -p tsconfig.build.json",
|
|
26
|
+
"build:copy": "cd src && copyfiles *.d.ts **/*.d.ts ..",
|
|
27
|
+
"lint": "eslint src test",
|
|
28
|
+
"lint:fix": "eslint src test --fix",
|
|
29
|
+
"test": "mocha test/**/*.spec.ts --config ../../../.mocharc.cjs",
|
|
30
|
+
"test:coverage": "c8 -c ../../../.c8rc.json npm test",
|
|
31
|
+
"typecheck": "tsc --noEmit"
|
|
32
|
+
},
|
|
33
|
+
"exports": {
|
|
34
|
+
"./runtime.js": {
|
|
35
|
+
"default": "./runtime.js"
|
|
36
|
+
},
|
|
37
|
+
"./types.js": {
|
|
38
|
+
"types": "./types.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./vite-plugin.js": {
|
|
41
|
+
"default": "./vite-plugin.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"author": "Vaadin Ltd",
|
|
45
|
+
"license": "Apache-2.0",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/vaadin/hilla/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://vaadin.com",
|
|
50
|
+
"files": [
|
|
51
|
+
"*.{d.ts.map,d.ts,js.map,js}",
|
|
52
|
+
"runtime",
|
|
53
|
+
"shared",
|
|
54
|
+
"vite-plugin"
|
|
55
|
+
],
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"react": "^18.2.0",
|
|
61
|
+
"react-router-dom": "^6.21.1"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@esm-bundle/chai": "^4.3.4-fix.0",
|
|
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-as-promised": "^7.1.1",
|
|
73
|
+
"chai-fs": "^2.0.0",
|
|
74
|
+
"chai-like": "^1.1.1",
|
|
75
|
+
"deep-equal-in-any-order": "^2.0.6",
|
|
76
|
+
"mocha": "^10.2.0",
|
|
77
|
+
"rimraf": "^5.0.5",
|
|
78
|
+
"sinon": "^16.0.0",
|
|
79
|
+
"sinon-chai": "^3.7.0",
|
|
80
|
+
"type-fest": "^4.9.0"
|
|
81
|
+
},
|
|
82
|
+
"dependencies": {
|
|
83
|
+
"@vaadin/hilla-generator-utils": "24.4.0-alpha10",
|
|
84
|
+
"react": "^18.2.0",
|
|
85
|
+
"rollup": "^4.12.0",
|
|
86
|
+
"typescript": "5.3.2"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MenuItem } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates menu items from the views provided by the server. The views are sorted according to the
|
|
4
|
+
* {@link ViewConfig.menu.order} and filtered out if they are explicitly excluded via {@link ViewConfig.menu.exclude}.
|
|
5
|
+
*
|
|
6
|
+
* @param vaadinObject - The Vaadin object containing the server views.
|
|
7
|
+
* @returns A list of menu items.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createMenuItems(vaadinObject?: Readonly<{
|
|
10
|
+
server?: Readonly<{
|
|
11
|
+
views: Readonly<Record<string, import("../shared/internal.js").ServerViewConfig>>;
|
|
12
|
+
}> | undefined;
|
|
13
|
+
}> | undefined): readonly MenuItem[];
|
|
14
|
+
//# sourceMappingURL=createMenuItems.d.ts.map
|
|
@@ -0,0 +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;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,YAAY;;;;cAAkC,GAAG,SAAS,QAAQ,EAAE,CAwBnG"}
|
|
@@ -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 type { VaadinWindow } from '../shared/internal.js';\nimport { RouteParamType } from '../shared/routeParamType.js';\nimport type { MenuItem, ViewConfig } from '../types.js';\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 as VaadinWindow).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": "AACA,SAAS,sBAAsB;AAUxB,SAAS,gBAAgB,eAAgB,OAAwB,QAA6B;AACnG,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-dom';
|
|
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,kBAAkB,CAAC;AAEpD,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-dom';\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-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"],
|
|
5
|
+
"mappings": "AACA,SAAS,kBAAkB;AAMpB,SAAS,gBAAqD;AACnE,QAAM,UAAU,WAAW;AAC3B,SAAO,QAAQ,QAAQ,SAAS,CAAC,GAAG;AACtC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
*/
|
|
10
|
+
export declare function transformRoute<T, U>(route: T, getChildren: (route: T) => IterableIterator<T> | null | undefined, transformer: (route: T, children: readonly U[]) => U): U;
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function transformRoute(route, getChildren, transformer) {
|
|
2
|
+
const children = getChildren(route);
|
|
3
|
+
return transformer(
|
|
4
|
+
route,
|
|
5
|
+
children ? Array.from(children, (child) => transformRoute(child, getChildren, transformer)) : []
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
transformRoute
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/runtime/utils.ts"],
|
|
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
|
+
"names": []
|
|
7
|
+
}
|
package/runtime.d.ts
ADDED
package/runtime.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
package/runtime.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/runtime.ts"],
|
|
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
|
+
"names": []
|
|
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,21 @@
|
|
|
1
|
+
import type { ViewConfig } from '../types.js';
|
|
2
|
+
import type { RouteParamType } from './routeParamType.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Internal type used for server communication and menu building. It extends the
|
|
6
|
+
* view configuration with the route parameters.
|
|
7
|
+
*/
|
|
8
|
+
export type ServerViewConfig = Readonly<{ params?: Readonly<Record<string, RouteParamType>> }> & ViewConfig;
|
|
9
|
+
|
|
10
|
+
export type VaadinServer = Readonly<{
|
|
11
|
+
views: Readonly<Record<string, ServerViewConfig>>;
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
export type VaadinObject = Readonly<{
|
|
15
|
+
server?: VaadinServer;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
export type VaadinWindow = Readonly<{
|
|
19
|
+
Vaadin?: VaadinObject;
|
|
20
|
+
}> &
|
|
21
|
+
Window;
|
|
@@ -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.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { RouteParamType } from './shared/routeParamType.js';
|
|
2
|
+
|
|
3
|
+
export type ViewConfig = Readonly<{
|
|
4
|
+
/**
|
|
5
|
+
* View title used in the main layout header, as <title> and as the default
|
|
6
|
+
* for the menu entry. If not defined, the component name will be taken,
|
|
7
|
+
* transformed from camelCase.
|
|
8
|
+
*/
|
|
9
|
+
title?: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Same as in the explicit React Router configuration.
|
|
13
|
+
*/
|
|
14
|
+
rolesAllowed?: readonly string[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Allows overriding the route path configuration. Uses the same syntax as
|
|
18
|
+
* the path property with React Router. This can be used to define a route
|
|
19
|
+
* that conflicts with the file name conventions, e.g. /foo/index.
|
|
20
|
+
*/
|
|
21
|
+
route?: string;
|
|
22
|
+
|
|
23
|
+
menu?: Readonly<{
|
|
24
|
+
/**
|
|
25
|
+
* Title to use in the menu. Falls back the title property of the view
|
|
26
|
+
* itself if not defined.
|
|
27
|
+
*/
|
|
28
|
+
title?: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Used to determine the order in the menu. Ties are resolved based on the
|
|
32
|
+
* used title. Entries without explicitly defined ordering are put below
|
|
33
|
+
* entries with an order.
|
|
34
|
+
*/
|
|
35
|
+
order?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Set to true to explicitly exclude a view from the automatically
|
|
38
|
+
* populated menu.
|
|
39
|
+
*/
|
|
40
|
+
exclude?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Icon to use in the menu.
|
|
43
|
+
*/
|
|
44
|
+
icon?: string;
|
|
45
|
+
}>;
|
|
46
|
+
}>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A module that exports a component and an optional view configuration.
|
|
50
|
+
*/
|
|
51
|
+
export type RouteModule<C = unknown> = Readonly<{
|
|
52
|
+
default: C;
|
|
53
|
+
config?: ViewConfig;
|
|
54
|
+
}>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A framework-agnostic object generated from the file-based route.
|
|
58
|
+
*/
|
|
59
|
+
export type AgnosticRoute<C = unknown> = Readonly<{
|
|
60
|
+
path: string;
|
|
61
|
+
module?: RouteModule<C>;
|
|
62
|
+
children?: ReadonlyArray<AgnosticRoute<T>>;
|
|
63
|
+
}>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A menu item used in for building the navigation menu.
|
|
67
|
+
*/
|
|
68
|
+
export type MenuItem = Readonly<{
|
|
69
|
+
to: string;
|
|
70
|
+
icon?: string;
|
|
71
|
+
title?: string;
|
|
72
|
+
}>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Logger } from 'vite';
|
|
2
|
+
export type RouteMeta = Readonly<{
|
|
3
|
+
path: string;
|
|
4
|
+
file?: URL;
|
|
5
|
+
layout?: URL;
|
|
6
|
+
children: RouteMeta[];
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Routes collector options.
|
|
10
|
+
*/
|
|
11
|
+
export type CollectRoutesOptions = Readonly<{
|
|
12
|
+
/**
|
|
13
|
+
* The list of extensions for files that will be collected as routes.
|
|
14
|
+
*/
|
|
15
|
+
extensions: readonly string[];
|
|
16
|
+
/**
|
|
17
|
+
* The parent directory of the current directory. This is a
|
|
18
|
+
* nested parameter used inside the function only.
|
|
19
|
+
*/
|
|
20
|
+
parent?: URL;
|
|
21
|
+
/**
|
|
22
|
+
* The Vite logger instance.
|
|
23
|
+
*/
|
|
24
|
+
logger: Logger;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Collect route metadata from the file system and build a route tree.
|
|
28
|
+
*
|
|
29
|
+
* It accepts files that start with `$` as special files.
|
|
30
|
+
* - `$layout` contains a component that wraps the child components.
|
|
31
|
+
* - `$index` contains a component that will be used as the index page of the directory.
|
|
32
|
+
*
|
|
33
|
+
* It accepts files that start with `_` as private files. They will be ignored.
|
|
34
|
+
*
|
|
35
|
+
* @param dir - The directory to collect routes from.
|
|
36
|
+
* @param options - The options object.
|
|
37
|
+
*
|
|
38
|
+
* @returns The route metadata tree.
|
|
39
|
+
*/
|
|
40
|
+
export default function collectRoutesFromFS(dir: URL, { extensions, logger, parent }: CollectRoutesOptions): Promise<RouteMeta>;
|
|
41
|
+
//# sourceMappingURL=collectRoutesFromFS.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectRoutesFromFS.d.ts","sourceRoot":"","sources":["../src/vite-plugin/collectRoutesFromFS.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,QAAQ,EAAE,SAAS,EAAE,CAAC;CACvB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C;;OAEG;IACH,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B;;;OAGG;IACH,MAAM,CAAC,EAAE,GAAG,CAAC;IACb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAiBH;;;;;;;;;;;;;GAaG;AACH,wBAA8B,mBAAmB,CAC/C,GAAG,EAAE,GAAG,EACR,EAAE,UAAU,EAAE,MAAM,EAAE,MAAY,EAAE,EAAE,oBAAoB,GACzD,OAAO,CAAC,SAAS,CAAC,CAuDpB"}
|