nexa-router 0.5.2 → 0.6.0
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/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -12
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +1 -11
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +37 -13
- package/dist/link.js.map +1 -1
- package/dist/route.d.ts +2 -1
- package/dist/route.d.ts.map +1 -1
- package/dist/route.js +21 -9
- package/dist/route.js.map +1 -1
- package/dist/view.d.ts +2 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +19 -0
- package/dist/view.js.map +1 -0
- package/package.json +3 -3
- package/dist/guards.d.ts +0 -6
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type { RouteDef, Guard } from './route';
|
|
|
3
3
|
export { matchPath } from './route';
|
|
4
4
|
export { Link } from './link';
|
|
5
5
|
export { createGuards } from './guards';
|
|
6
|
+
export { RouterView } from './view';
|
|
6
7
|
type RouterConfig = {
|
|
7
8
|
routes: RouteDef[];
|
|
8
9
|
mode?: 'hash' | 'history';
|
|
@@ -11,8 +12,11 @@ type RouterConfig = {
|
|
|
11
12
|
};
|
|
12
13
|
};
|
|
13
14
|
export declare function createRouter(config: RouterConfig): {
|
|
14
|
-
navigate: (path: string) => void
|
|
15
|
+
navigate: (path: string) => Promise<void>;
|
|
16
|
+
beforeEach: (guard: Guard) => void;
|
|
15
17
|
currentRoute: import("nexa-reactivity").Signal<RouteDef | null>;
|
|
16
18
|
currentPath: import("nexa-reactivity").Signal<string>;
|
|
19
|
+
params: import("nexa-reactivity").Signal<Record<string, string>>;
|
|
20
|
+
query: import("nexa-reactivity").Signal<Record<string, string>>;
|
|
17
21
|
};
|
|
18
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,SAAS,CAAA;AAE1E,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEnC,KAAK,YAAY,GAAG;IAClB,MAAM,EAAE,QAAQ,EAAE,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,MAAM,CAAC,EAAE;QAAE,UAAU,EAAE,KAAK,EAAE,CAAA;KAAE,CAAA;CACjC,CAAA;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY;qBA4BjB,MAAM;wBAJT,KAAK;;;;;EA+BjC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
import { signal, computed } from 'nexa-reactivity';
|
|
2
|
-
import { matchPath } from './route';
|
|
2
|
+
import { matchPath, parseQuery } from './route';
|
|
3
3
|
export { matchPath } from './route';
|
|
4
4
|
export { Link } from './link';
|
|
5
5
|
export { createGuards } from './guards';
|
|
6
|
+
export { RouterView } from './view';
|
|
6
7
|
export function createRouter(config) {
|
|
7
|
-
const currentPath = signal(window.location.pathname);
|
|
8
|
-
|
|
8
|
+
const currentPath = signal(window.location.pathname + window.location.search);
|
|
9
|
+
const params = signal({});
|
|
10
|
+
const query = signal({});
|
|
11
|
+
const guards = config.guards?.beforeEach ?? [];
|
|
12
|
+
const currentRoute = computed(() => {
|
|
13
|
+
const [path, search] = currentPath.value.split('?');
|
|
14
|
+
query.value = parseQuery(search || '');
|
|
15
|
+
for (const route of config.routes) {
|
|
16
|
+
const match = matchPath(route.path, path);
|
|
17
|
+
if (match) {
|
|
18
|
+
params.value = match;
|
|
19
|
+
return route;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const fallback = config.routes.find(r => r.path === '*');
|
|
23
|
+
if (fallback)
|
|
24
|
+
return fallback;
|
|
25
|
+
return null;
|
|
26
|
+
});
|
|
27
|
+
function beforeEach(guard) {
|
|
28
|
+
guards.push(guard);
|
|
29
|
+
}
|
|
30
|
+
async function navigate(path) {
|
|
31
|
+
const from = currentPath.value;
|
|
32
|
+
for (const guard of guards) {
|
|
33
|
+
const allowed = await guard(path, from);
|
|
34
|
+
if (!allowed)
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
9
37
|
if (config.mode === 'hash') {
|
|
10
38
|
window.location.hash = `#${path}`;
|
|
11
39
|
}
|
|
@@ -14,21 +42,16 @@ export function createRouter(config) {
|
|
|
14
42
|
}
|
|
15
43
|
currentPath.value = path;
|
|
16
44
|
}
|
|
17
|
-
const currentRoute = computed(() => {
|
|
18
|
-
const route = config.routes.find(r => {
|
|
19
|
-
if (r.path === '*')
|
|
20
|
-
return true;
|
|
21
|
-
return matchPath(r.path, currentPath.value);
|
|
22
|
-
});
|
|
23
|
-
return route ?? null;
|
|
24
|
-
});
|
|
25
45
|
window.addEventListener('popstate', () => {
|
|
26
|
-
currentPath.value = window.location.pathname;
|
|
46
|
+
currentPath.value = window.location.pathname + window.location.search;
|
|
27
47
|
});
|
|
28
48
|
return {
|
|
29
49
|
navigate,
|
|
50
|
+
beforeEach,
|
|
30
51
|
currentRoute,
|
|
31
52
|
currentPath,
|
|
53
|
+
params,
|
|
54
|
+
query
|
|
32
55
|
};
|
|
33
56
|
}
|
|
34
57
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":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AAY;QACZ,WAAW;QACX,MAAM;QACN,KAAK;KACN,CAAA;AACH,CAAC"}
|
package/dist/link.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
to: string;
|
|
3
|
-
children?: any;
|
|
4
|
-
}, ctx: any): {
|
|
5
|
-
tag: string;
|
|
6
|
-
props: {
|
|
7
|
-
href: string;
|
|
8
|
-
onClick: (e: Event) => void;
|
|
9
|
-
};
|
|
10
|
-
children: any;
|
|
11
|
-
};
|
|
1
|
+
export declare const Link: import("nexa-runtime").Component;
|
|
12
2
|
//# sourceMappingURL=link.d.ts.map
|
package/dist/link.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,IAAI,kCAwBf,CAAA"}
|
package/dist/link.js
CHANGED
|
@@ -1,14 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
1
|
+
import { defineComponent, h } from 'nexa-runtime';
|
|
2
|
+
const resolveClass = (value) => {
|
|
3
|
+
if (!value)
|
|
4
|
+
return '';
|
|
5
|
+
if (typeof value === 'string')
|
|
6
|
+
return value;
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
return value.map(resolveClass).filter(Boolean).join(' ');
|
|
9
|
+
}
|
|
10
|
+
if (typeof value === 'object') {
|
|
11
|
+
return Object.keys(value).filter(k => value[k]).join(' ');
|
|
12
|
+
}
|
|
13
|
+
return String(value);
|
|
14
|
+
};
|
|
15
|
+
export const Link = defineComponent({
|
|
16
|
+
name: 'Link',
|
|
17
|
+
props: {
|
|
18
|
+
to: { type: String, required: true },
|
|
19
|
+
router: { type: Object, required: true },
|
|
20
|
+
class: { type: [String, Object, Array], default: '' }
|
|
21
|
+
},
|
|
22
|
+
setup(props, { slots }) {
|
|
23
|
+
const handleClick = (e) => {
|
|
24
|
+
e.preventDefault();
|
|
25
|
+
props.router.navigate(props.to);
|
|
26
|
+
};
|
|
27
|
+
return () => {
|
|
28
|
+
const extra = resolveClass(props.class);
|
|
29
|
+
const resolvedClass = extra ? `n-link ${extra}` : 'n-link';
|
|
30
|
+
return h('a', {
|
|
31
|
+
href: props.to,
|
|
32
|
+
onClick: handleClick,
|
|
33
|
+
class: resolvedClass
|
|
34
|
+
}, slots.default?.());
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
|
14
38
|
//# sourceMappingURL=link.js.map
|
package/dist/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,cAAc,CAAA;AAEjD,MAAM,YAAY,GAAG,CAAC,KAAc,EAAU,EAAE;IAC9C,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAA;IACrB,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC1D,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,KAA4B,CAAC,CAAC,MAAM,CAA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|
5
5
|
};
|
|
6
6
|
export type Guard = (to: string, from: string) => boolean | Promise<boolean>;
|
|
7
|
-
export declare function matchPath(pattern: string, path: string):
|
|
7
|
+
export declare function matchPath(pattern: string, path: string): Record<string, string> | null;
|
|
8
|
+
export declare function parseQuery(search: string): Record<string, string>;
|
|
8
9
|
//# sourceMappingURL=route.d.ts.map
|
package/dist/route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,SAAS,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAE5E,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,SAAS,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAE5E,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAsBtF;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAGjE"}
|
package/dist/route.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
export function matchPath(pattern, path) {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const [pathname] = path.split('?');
|
|
3
|
+
const patternParts = pattern.split('/').filter(Boolean);
|
|
4
|
+
const pathParts = pathname.split('/').filter(Boolean);
|
|
5
|
+
if (patternParts.length !== pathParts.length) {
|
|
6
|
+
if (pattern === '*')
|
|
7
|
+
return {};
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const params = {};
|
|
6
11
|
for (let i = 0; i < patternParts.length; i++) {
|
|
7
|
-
if (patternParts[i].startsWith(':'))
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
if (patternParts[i].startsWith(':')) {
|
|
13
|
+
const name = patternParts[i].slice(1);
|
|
14
|
+
params[name] = pathParts[i];
|
|
15
|
+
}
|
|
16
|
+
else if (patternParts[i] !== pathParts[i]) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
11
19
|
}
|
|
12
|
-
return
|
|
20
|
+
return params;
|
|
21
|
+
}
|
|
22
|
+
export function parseQuery(search) {
|
|
23
|
+
const params = new URLSearchParams(search);
|
|
24
|
+
return Object.fromEntries(params.entries());
|
|
13
25
|
}
|
|
14
26
|
//# sourceMappingURL=route.js.map
|
package/dist/route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,IAAY;IACrD,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,IAA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ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,kCAgBrB,CAAA"}
|
package/dist/view.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineComponent, h } from 'nexa-runtime';
|
|
2
|
+
export const RouterView = defineComponent({
|
|
3
|
+
name: 'RouterView',
|
|
4
|
+
props: {
|
|
5
|
+
router: { type: Object, required: true }
|
|
6
|
+
},
|
|
7
|
+
setup(props) {
|
|
8
|
+
return () => {
|
|
9
|
+
const route = props.router.currentRoute.value;
|
|
10
|
+
if (!route || !route.component)
|
|
11
|
+
return h('div', { class: 'n-router-empty' }, '404 Not Found');
|
|
12
|
+
return h(route.component, {
|
|
13
|
+
params: props.router.params.value,
|
|
14
|
+
query: props.router.query.value
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=view.js.map
|
package/dist/view.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,cAAc,CAAA;AAEjD,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAC;IACxC,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE;QACL,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;KACzC;IACD,KAAK,CAAC,KAAK;QACT,OAAO,GAAG,EAAE;YACV,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAA;YAC7C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,SAAS;gBAAE,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,eAAe,CAAC,CAAA;YAE7F,OAAO,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE;gBACxB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;gBACjC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK;aAChC,CAAC,CAAA;QACJ,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexa-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"nexa-runtime": "0.
|
|
16
|
+
"nexa-runtime": "0.6.0"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"nexa-reactivity": "0.
|
|
25
|
+
"nexa-reactivity": "0.6.0"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsc",
|