@vaadin/hilla-file-router 24.5.0-beta3 → 24.5.0-beta5
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.5.0-
|
|
3
|
+
"version": "24.5.0-beta5",
|
|
4
4
|
"description": "Hilla file-based router",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -79,9 +79,9 @@
|
|
|
79
79
|
"type-fest": "^4.9.0"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@vaadin/hilla-generator-utils": "24.5.0-
|
|
83
|
-
"@vaadin/hilla-react-auth": "24.5.0-
|
|
84
|
-
"@vaadin/hilla-react-signals": "24.5.0-
|
|
82
|
+
"@vaadin/hilla-generator-utils": "24.5.0-beta5",
|
|
83
|
+
"@vaadin/hilla-react-auth": "24.5.0-beta5",
|
|
84
|
+
"@vaadin/hilla-react-signals": "24.5.0-beta5",
|
|
85
85
|
"react": "^18.2.0",
|
|
86
86
|
"rollup": "^4.12.0",
|
|
87
87
|
"typescript": "5.6.2"
|
|
@@ -2,7 +2,7 @@ function __REGISTER__(feature, vaadinObj = window.Vaadin ??= {}) {
|
|
|
2
2
|
vaadinObj.registrations ??= [];
|
|
3
3
|
vaadinObj.registrations.push({
|
|
4
4
|
is: feature ? `${"@vaadin/hilla-file-router"}/${feature}` : "@vaadin/hilla-file-router",
|
|
5
|
-
version: "24.5.0-
|
|
5
|
+
version: "24.5.0-beta5"
|
|
6
6
|
});
|
|
7
7
|
}
|
|
8
8
|
import { signal } from "@vaadin/hilla-react-signals";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyLayouts.d.ts","sourceRoot":"","sources":["../src/vite-plugin/applyLayouts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"applyLayouts.d.ts","sourceRoot":"","sources":["../src/vite-plugin/applyLayouts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC;AA+CH;;;;;;GAMG;AACH,wBAA8B,YAAY,CACxC,SAAS,EAAE,SAAS,SAAS,EAAE,EAC/B,WAAW,EAAE,GAAG,GACf,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CAW/B"}
|
|
@@ -13,14 +13,34 @@ function enableFlowLayout(route) {
|
|
|
13
13
|
children: route.children.map(enableFlowLayout)
|
|
14
14
|
} : routeWithFlowLayout;
|
|
15
15
|
}
|
|
16
|
+
function layoutExists(layoutPaths, path) {
|
|
17
|
+
const splitPath = path.split("/");
|
|
18
|
+
return layoutPaths.some((layout) => {
|
|
19
|
+
if (layout.length === 0) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
const splitLayout = layout.split("/");
|
|
23
|
+
if (splitLayout.length > splitPath.length) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
for (let i = 0; i < splitLayout.length; i++) {
|
|
27
|
+
if (splitPath[i] !== splitLayout[i]) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
16
34
|
async function applyLayouts(routeMeta, layoutsFile) {
|
|
17
35
|
if (!existsSync(layoutsFile)) {
|
|
18
36
|
return routeMeta;
|
|
19
37
|
}
|
|
20
38
|
const layoutContents = await readFile(layoutsFile, "utf-8");
|
|
21
39
|
const availableLayouts = JSON.parse(layoutContents);
|
|
22
|
-
const layoutPaths =
|
|
23
|
-
return routeMeta.map(
|
|
40
|
+
const layoutPaths = availableLayouts.map((layout) => stripLeadingSlash(layout.path));
|
|
41
|
+
return routeMeta.map(
|
|
42
|
+
(route) => layoutExists(layoutPaths, stripLeadingSlash(route.path)) ? enableFlowLayout(route) : route
|
|
43
|
+
);
|
|
24
44
|
}
|
|
25
45
|
export {
|
|
26
46
|
applyLayouts as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/vite-plugin/applyLayouts.ts"],
|
|
4
|
-
"sourcesContent": ["import { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport type { RouteMeta } from './collectRoutesFromFS.js';\n\n/**\n * The information about a particular server-side layout.\n */\nexport type LayoutMeta = Readonly<{\n path: string;\n}>;\n\nfunction stripLeadingSlash(path: string) {\n return path.startsWith('/') ? path.slice(1) : path;\n}\n\nfunction enableFlowLayout(route: RouteMeta): RouteMeta {\n const routeWithFlowLayout = {\n ...route,\n flowLayout: true,\n };\n return route.children\n ? {\n ...routeWithFlowLayout,\n children: route.children.map(enableFlowLayout),\n }\n : routeWithFlowLayout;\n}\n\n/**\n * Enables Flow layout flag on the matching routes based on the information from the layouts JSON file.\n *\n * @param routeMeta - The routes tree to process.\n * @param layoutsFile - The server layouts JSON file.\n * @returns Processed routes tree.\n */\nexport default async function applyLayouts(\n routeMeta: readonly RouteMeta[],\n layoutsFile: URL,\n): Promise<readonly RouteMeta[]> {\n if (!existsSync(layoutsFile)) {\n return routeMeta;\n }\n const layoutContents = await readFile(layoutsFile, 'utf-8');\n const availableLayouts: readonly LayoutMeta[] = JSON.parse(layoutContents);\n const layoutPaths =
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAUzB,SAAS,kBAAkB,MAAc;AACvC,SAAO,KAAK,WAAW,GAAG,IAAI,KAAK,MAAM,CAAC,IAAI;AAChD;AAEA,SAAS,iBAAiB,OAA6B;AACrD,QAAM,sBAAsB;AAAA,IAC1B,GAAG;AAAA,IACH,YAAY;AAAA,EACd;AACA,SAAO,MAAM,WACT;AAAA,IACE,GAAG;AAAA,IACH,UAAU,MAAM,SAAS,IAAI,gBAAgB;AAAA,EAC/C,IACA;AACN;AASA,eAAO,aACL,WACA,aAC+B;AAC/B,MAAI,CAAC,WAAW,WAAW,GAAG;AAC5B,WAAO;AAAA,EACT;AACA,QAAM,iBAAiB,MAAM,SAAS,aAAa,OAAO;AAC1D,QAAM,mBAA0C,KAAK,MAAM,cAAc;AACzE,QAAM,cAAc,
|
|
4
|
+
"sourcesContent": ["import { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport type { RouteMeta } from './collectRoutesFromFS.js';\n\n/**\n * The information about a particular server-side layout.\n */\nexport type LayoutMeta = Readonly<{\n path: string;\n}>;\n\nfunction stripLeadingSlash(path: string) {\n return path.startsWith('/') ? path.slice(1) : path;\n}\n\nfunction enableFlowLayout(route: RouteMeta): RouteMeta {\n const routeWithFlowLayout = {\n ...route,\n flowLayout: true,\n };\n return route.children\n ? {\n ...routeWithFlowLayout,\n children: route.children.map(enableFlowLayout),\n }\n : routeWithFlowLayout;\n}\n\n/**\n * Check if there is a layout available that can handle the given path.\n * Layouts match the starting parts of the path so '/' will match all paths\n * and '/home' matches '/home' anything with the start path '/home/*'\n *\n * @param layoutPaths - available layout paths\n * @param path - to check for layout\n */\nfunction layoutExists(layoutPaths: string[], path: string) {\n const splitPath: string[] = path.split('/');\n\n return layoutPaths.some((layout) => {\n if (layout.length === 0) {\n return true;\n }\n const splitLayout: string[] = layout.split('/');\n if (splitLayout.length > splitPath.length) {\n return false;\n }\n for (let i = 0; i < splitLayout.length; i++) {\n if (splitPath[i] !== splitLayout[i]) {\n return false;\n }\n }\n return true;\n });\n}\n\n/**\n * Enables Flow layout flag on the matching routes based on the information from the layouts JSON file.\n *\n * @param routeMeta - The routes tree to process.\n * @param layoutsFile - The server layouts JSON file.\n * @returns Processed routes tree.\n */\nexport default async function applyLayouts(\n routeMeta: readonly RouteMeta[],\n layoutsFile: URL,\n): Promise<readonly RouteMeta[]> {\n if (!existsSync(layoutsFile)) {\n return routeMeta;\n }\n const layoutContents = await readFile(layoutsFile, 'utf-8');\n const availableLayouts: readonly LayoutMeta[] = JSON.parse(layoutContents);\n const layoutPaths = availableLayouts.map((layout) => stripLeadingSlash(layout.path));\n\n return routeMeta.map((route) =>\n layoutExists(layoutPaths, stripLeadingSlash(route.path)) ? enableFlowLayout(route) : route,\n );\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAUzB,SAAS,kBAAkB,MAAc;AACvC,SAAO,KAAK,WAAW,GAAG,IAAI,KAAK,MAAM,CAAC,IAAI;AAChD;AAEA,SAAS,iBAAiB,OAA6B;AACrD,QAAM,sBAAsB;AAAA,IAC1B,GAAG;AAAA,IACH,YAAY;AAAA,EACd;AACA,SAAO,MAAM,WACT;AAAA,IACE,GAAG;AAAA,IACH,UAAU,MAAM,SAAS,IAAI,gBAAgB;AAAA,EAC/C,IACA;AACN;AAUA,SAAS,aAAa,aAAuB,MAAc;AACzD,QAAM,YAAsB,KAAK,MAAM,GAAG;AAE1C,SAAO,YAAY,KAAK,CAAC,WAAW;AAClC,QAAI,OAAO,WAAW,GAAG;AACvB,aAAO;AAAA,IACT;AACA,UAAM,cAAwB,OAAO,MAAM,GAAG;AAC9C,QAAI,YAAY,SAAS,UAAU,QAAQ;AACzC,aAAO;AAAA,IACT;AACA,aAAS,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;AAC3C,UAAI,UAAU,CAAC,MAAM,YAAY,CAAC,GAAG;AACnC,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC;AACH;AASA,eAAO,aACL,WACA,aAC+B;AAC/B,MAAI,CAAC,WAAW,WAAW,GAAG;AAC5B,WAAO;AAAA,EACT;AACA,QAAM,iBAAiB,MAAM,SAAS,aAAa,OAAO;AAC1D,QAAM,mBAA0C,KAAK,MAAM,cAAc;AACzE,QAAM,cAAc,iBAAiB,IAAI,CAAC,WAAW,kBAAkB,OAAO,IAAI,CAAC;AAEnF,SAAO,UAAU;AAAA,IAAI,CAAC,UACpB,aAAa,aAAa,kBAAkB,MAAM,IAAI,CAAC,IAAI,iBAAiB,KAAK,IAAI;AAAA,EACvF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|