ziko 2.0.0-beta.2 → 2.0.0-beta.3
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": "ziko",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"front-end",
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// file-based-router/index.js
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
2
|
get_root,
|
|
5
3
|
normalize_path,
|
|
@@ -10,17 +8,21 @@ import {
|
|
|
10
8
|
renderer as ziko_renderer
|
|
11
9
|
} from "../internal-utils/index.js";
|
|
12
10
|
|
|
13
|
-
/**
|
|
14
|
-
* Environment-independent file-based router core
|
|
15
|
-
*/
|
|
16
11
|
export async function createFileBasedRouter({
|
|
17
12
|
pages = {},
|
|
18
13
|
url = typeof location !== 'undefined' ? location.pathname : '/',
|
|
19
14
|
target = typeof document !== 'undefined' ? document.body : null,
|
|
20
15
|
extensions = ['js', 'ts'],
|
|
16
|
+
base = '/',
|
|
21
17
|
renderer = ziko_renderer,
|
|
22
18
|
wrapper,
|
|
23
|
-
|
|
19
|
+
namedExportHandler = {
|
|
20
|
+
Get: async (exportedFn, context) => {
|
|
21
|
+
if (typeof exportedFn === 'function') {
|
|
22
|
+
return await exportedFn(context);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
24
26
|
} = {}) {
|
|
25
27
|
// Normalize target element safely for UI frameworks/DOM wrapper objects
|
|
26
28
|
let mountTarget = target;
|
|
@@ -44,16 +46,20 @@ export async function createFileBasedRouter({
|
|
|
44
46
|
|
|
45
47
|
let currentPath = rawPath.startsWith('/') ? rawPath : '/' + rawPath;
|
|
46
48
|
|
|
47
|
-
// 3. Normalize route masks
|
|
49
|
+
// 3. Normalize route masks and collect modules
|
|
48
50
|
const routes = Object.keys(pages);
|
|
49
51
|
const root = get_root(routes);
|
|
50
52
|
|
|
51
53
|
const pairs = {};
|
|
54
|
+
const modules = {};
|
|
55
|
+
|
|
52
56
|
for (const route of routes) {
|
|
53
57
|
const module = await pages[route]();
|
|
54
58
|
const modComponent = await module.default;
|
|
55
59
|
const normalizedKey = normalize_path(route, root, extensions);
|
|
60
|
+
|
|
56
61
|
pairs[normalizedKey] = modComponent;
|
|
62
|
+
modules[normalizedKey] = { module, rawRoute: route };
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
// 4. Sort routes by precedence (Static -> Dynamic -> Catch-All -> Optional Catch-All)
|
|
@@ -76,7 +82,21 @@ export async function createFileBasedRouter({
|
|
|
76
82
|
|
|
77
83
|
const params = is_dynamic(mask) ? dynamic_routes_parser(mask, currentPath) : {};
|
|
78
84
|
|
|
79
|
-
|
|
85
|
+
if (mask in modules) {
|
|
86
|
+
const { module, rawRoute } = modules[mask];
|
|
87
|
+
for (const exportName in namedExportHandler) {
|
|
88
|
+
if (exportName in module && typeof namedExportHandler[exportName] === 'function') {
|
|
89
|
+
await namedExportHandler[exportName](module[exportName], {
|
|
90
|
+
route: rawRoute,
|
|
91
|
+
mask,
|
|
92
|
+
module,
|
|
93
|
+
currentPath,
|
|
94
|
+
params
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
80
100
|
if (mountTarget && typeof renderer === 'function') {
|
|
81
101
|
await renderer(mountTarget, component, params, wrapper);
|
|
82
102
|
}
|