@vlian/router 1.0.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.
@@ -0,0 +1,101 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _iterable_to_array_limit(arr, i) {
10
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
+ if (_i == null) return;
12
+ var _arr = [];
13
+ var _n = true;
14
+ var _d = false;
15
+ var _s, _e;
16
+ try {
17
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
+ _arr.push(_s.value);
19
+ if (i && _arr.length === i) break;
20
+ }
21
+ } catch (err) {
22
+ _d = true;
23
+ _e = err;
24
+ } finally{
25
+ try {
26
+ if (!_n && _i["return"] != null) _i["return"]();
27
+ } finally{
28
+ if (_d) throw _e;
29
+ }
30
+ }
31
+ return _arr;
32
+ }
33
+ function _non_iterable_rest() {
34
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
+ }
36
+ function _sliced_to_array(arr, i) {
37
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
+ }
39
+ function _unsupported_iterable_to_array(o, minLen) {
40
+ if (!o) return;
41
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
42
+ var n = Object.prototype.toString.call(o).slice(8, -1);
43
+ if (n === "Object" && o.constructor) n = o.constructor.name;
44
+ if (n === "Map" || n === "Set") return Array.from(n);
45
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
+ }
47
+ import { RouterProvider as Provider, createBrowserRouter } from 'react-router-dom';
48
+ import { useRouterTransform, navigator } from "../provider";
49
+ import React, { useState, useEffect } from 'react';
50
+ import { staticRoutes as defaultStaticRoutes, rootRoutes as defaultRootRoutes } from './routes';
51
+ import { useSquareRotate2Styles } from '../styles/square-rotate';
52
+ export var RouterProvider = function(param) {
53
+ var fetchRoutes = param.fetchRoutes, imports = param.imports, _param_rootRoutes = param.rootRoutes, rootRoutes = _param_rootRoutes === void 0 ? defaultRootRoutes : _param_rootRoutes, _param_staticRoutes = param.staticRoutes, staticRoutes = _param_staticRoutes === void 0 ? defaultStaticRoutes : _param_staticRoutes, options = param.options, _param_isSubApp = param.isSubApp, isSubApp = _param_isSubApp === void 0 ? false : _param_isSubApp, loadingRender = param.loadingRender, _param_loadingSize = param.loadingSize, loadingSize = _param_loadingSize === void 0 ? '24px' : _param_loadingSize, _param_loadingColor = param.loadingColor, loadingColor = _param_loadingColor === void 0 ? 'currentColor' : _param_loadingColor, _param_loadingOpacity = param.loadingOpacity, loadingOpacity = _param_loadingOpacity === void 0 ? 0.25 : _param_loadingOpacity;
54
+ var _useState = _sliced_to_array(useState(), 2), dataRouter = _useState[0], setDataRouter = _useState[1];
55
+ var styles = useSquareRotate2Styles().styles;
56
+ var routeObject = useRouterTransform({
57
+ errorsMap: imports.errors,
58
+ layouts: imports.layouts,
59
+ loadings: imports.loadings,
60
+ views: imports.pages
61
+ }, rootRoutes, {
62
+ staticRoutes: staticRoutes,
63
+ fetchRoutes: fetchRoutes
64
+ }).routeObject;
65
+ useEffect(function() {
66
+ if (routeObject) {
67
+ var router = createBrowserRouter(routeObject, options);
68
+ setDataRouter(router);
69
+ if (isSubApp) {
70
+ window.$router = navigator(router);
71
+ }
72
+ }
73
+ }, [
74
+ routeObject,
75
+ imports,
76
+ rootRoutes,
77
+ staticRoutes
78
+ ]);
79
+ if (!routeObject || !dataRouter) {
80
+ return /*#__PURE__*/ React.createElement("div", {
81
+ className: "w-full h-full flex-center",
82
+ style: {
83
+ width: '100%',
84
+ height: '100%',
85
+ display: 'flex',
86
+ justifyContent: "center",
87
+ alignItems: 'center'
88
+ }
89
+ }, loadingRender || /*#__PURE__*/ React.createElement("div", {
90
+ className: styles.squareRotate2,
91
+ style: {
92
+ '--size': loadingSize,
93
+ '--color': loadingColor,
94
+ '--accent-opacity': loadingOpacity
95
+ }
96
+ }));
97
+ }
98
+ return /*#__PURE__*/ React.createElement(Provider, {
99
+ router: dataRouter
100
+ });
101
+ };
@@ -0,0 +1,4 @@
1
+ import type { RouteItem } from '../types';
2
+ export declare const staticRoutes: RouteItem[];
3
+ export declare const rootRoutes: RouteItem;
4
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/router/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,eAAO,MAAM,YAAY,EAAE,SAAS,EAsBnC,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,SAUxB,CAAA"}
@@ -0,0 +1,33 @@
1
+ export var staticRoutes = [
2
+ // 404
3
+ {
4
+ name: "404",
5
+ path: "/404",
6
+ page: "404",
7
+ handle: {
8
+ title: "页面不存在",
9
+ order: 99999998
10
+ }
11
+ },
12
+ // 全匹配
13
+ {
14
+ name: "notFound",
15
+ path: "*",
16
+ page: "404",
17
+ handle: {
18
+ title: "页面不存在",
19
+ order: 99999999
20
+ }
21
+ }
22
+ ];
23
+ export var rootRoutes = {
24
+ name: "root",
25
+ path: "/",
26
+ page: "root",
27
+ layout: "root",
28
+ handle: {
29
+ title: "首页",
30
+ order: 1
31
+ },
32
+ children: []
33
+ };
@@ -0,0 +1,6 @@
1
+ export declare const useSquareRotate2Styles: () => {
2
+ styles: {
3
+ squareRotate2: string;
4
+ };
5
+ };
6
+ //# sourceMappingURL=square-rotate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"square-rotate.d.ts","sourceRoot":"","sources":["../../src/styles/square-rotate.ts"],"names":[],"mappings":"AA0CA,eAAO,MAAM,sBAAsB;;;;CAiBlC,CAAC"}
@@ -0,0 +1,68 @@
1
+ import Keyframes from '@ant-design/cssinjs/lib/Keyframes';
2
+ import { useStyleRegister } from '@ant-design/cssinjs';
3
+ // 定义动画
4
+ var squareRotate2Animation = new Keyframes('square-rotate-2-animation', {
5
+ '0%': {
6
+ transform: 'rotate(0deg)'
7
+ },
8
+ '100%': {
9
+ transform: 'rotate(360deg)'
10
+ }
11
+ });
12
+ // 定义样式
13
+ var squareRotate2Styles = {
14
+ '--size': '24px',
15
+ '--accent-opacity': '0.25',
16
+ '--color': 'currentColor',
17
+ '--animation-timing-function': 'linear',
18
+ '--animation-duration': '2s',
19
+ position: 'relative',
20
+ width: 'var(--size)',
21
+ height: 'var(--size)',
22
+ '&::before, &::after': {
23
+ content: '""',
24
+ position: 'absolute',
25
+ transform: 'rotate(0deg)',
26
+ animation: "var(--animation-timing-function) var(--animation-duration) infinite ".concat(squareRotate2Animation.getName())
27
+ },
28
+ '&::before': {
29
+ inset: 0,
30
+ backgroundColor: 'var(--color)',
31
+ opacity: 'var(--accent-opacity)'
32
+ },
33
+ '&::after': {
34
+ top: '12.5%',
35
+ left: '12.5%',
36
+ width: '75%',
37
+ height: '75%',
38
+ backgroundColor: 'var(--color)',
39
+ animationDirection: 'reverse'
40
+ }
41
+ };
42
+ // 创建样式钩子
43
+ export var useSquareRotate2Styles = function() {
44
+ var styleId = 'square-rotate-2';
45
+ useStyleRegister({
46
+ theme: null,
47
+ token: {},
48
+ path: [
49
+ styleId
50
+ ]
51
+ }, function() {
52
+ return [
53
+ squareRotate2Animation,
54
+ squareRotate2Styles
55
+ ];
56
+ });
57
+ return {
58
+ styles: {
59
+ squareRotate2: styleId
60
+ }
61
+ };
62
+ }; // 使用示例:
63
+ // import { useSquareRotate2Styles } from './styles/square-rotate-2';
64
+ //
65
+ // function MyComponent() {
66
+ // const { styles } = useSquareRotate2Styles();
67
+ // return <div className={styles.squareRotate2} />;
68
+ // }
@@ -0,0 +1,31 @@
1
+ export type RouteItemHandle = {
2
+ title: string;
3
+ i18nKey?: string;
4
+ order: number;
5
+ icon?: string;
6
+ hideInMenu?: boolean;
7
+ hideFooter?: boolean;
8
+ keepAlive?: boolean;
9
+ needLogin?: boolean;
10
+ roles?: Array<string>;
11
+ name?: string;
12
+ [key: string]: unknown;
13
+ };
14
+ export type RouteItem = {
15
+ layout?: string | null;
16
+ page?: string | null;
17
+ loading?: string | null;
18
+ errors?: string | null;
19
+ name: string;
20
+ path: string | undefined;
21
+ isGroup?: boolean;
22
+ enableRedirection?: boolean;
23
+ handle: RouteItemHandle;
24
+ children?: RouteItem[];
25
+ };
26
+ export type RouteMapType = Record<string, () => Promise<any>>;
27
+ export type LocationQueryValue = string | null;
28
+ export type LocationQuery = Record<string, LocationQueryValue | LocationQueryValue[]>;
29
+ export type LocationQueryValueRaw = LocationQueryValue | number | undefined;
30
+ export type LocationQueryRaw = Record<string | number, LocationQueryValueRaw | LocationQueryValueRaw[]>;
31
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAEtB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAA;AACD,MAAM,MAAM,SAAS,GAAG;IAEtB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAErB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAEzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAE9D,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,IAAI,CAAC;AAE/C,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,CAAC,CAAC;AACtF,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAAC;AAE5E,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,qBAAqB,GAAG,qBAAqB,EAAE,CAAC,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,10 @@
1
+ import type { RouteItem } from "./types";
2
+ export type FormattedMenuItem = {
3
+ path: string | undefined;
4
+ name: string;
5
+ key: string;
6
+ icon?: string;
7
+ children?: FormattedMenuItem[];
8
+ };
9
+ export declare const formatMenusDate: (routes: RouteItem[]) => FormattedMenuItem[];
10
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,iBAAiB,GAAG;IAC5B,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,QAAQ,SAAS,EAAE,KAAG,iBAAiB,EAmBtE,CAAA"}
package/dist/utils.js ADDED
@@ -0,0 +1,24 @@
1
+ export var formatMenusDate = function(routes) {
2
+ return routes.filter(function(item) {
3
+ var _item_handle;
4
+ return !((_item_handle = item.handle) === null || _item_handle === void 0 ? void 0 : _item_handle.hideInMenu);
5
+ }).sort(function(a, b) {
6
+ var _ref, _ref1;
7
+ var _a_handle, _b_handle;
8
+ return ((_ref = (_a_handle = a.handle) === null || _a_handle === void 0 ? void 0 : _a_handle.order) !== null && _ref !== void 0 ? _ref : 99) - ((_ref1 = (_b_handle = b.handle) === null || _b_handle === void 0 ? void 0 : _b_handle.order) !== null && _ref1 !== void 0 ? _ref1 : 99);
9
+ }).reduce(function(acc, item) {
10
+ var _ref;
11
+ var _item_handle, _item_handle1;
12
+ var formatted = {
13
+ path: item.path,
14
+ name: (_ref = (_item_handle = item.handle) === null || _item_handle === void 0 ? void 0 : _item_handle.title) !== null && _ref !== void 0 ? _ref : '',
15
+ icon: (_item_handle1 = item.handle) === null || _item_handle1 === void 0 ? void 0 : _item_handle1.icon,
16
+ key: item.name
17
+ };
18
+ if (Array.isArray(item.children)) {
19
+ formatted.children = formatMenusDate(item.children);
20
+ }
21
+ acc.push(formatted);
22
+ return acc;
23
+ }, []);
24
+ };
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@vlian/router",
3
+ "version": "1.0.3",
4
+ "description": "基于 React Router 的路由管理包,支持动态路由、权限控制、路由转换等功能",
5
+ "keywords": [
6
+ "router",
7
+ "react-router",
8
+ "routing",
9
+ "navigation"
10
+ ],
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "rm -rf dist && swc ./src -d dist --strip-leading-paths && tsc -b",
20
+ "lint": "eslint src --ext .ts,.tsx",
21
+ "clean": "rm -rf dist",
22
+ "prepublishOnly": "npm run build && npm version patch --no-git-tag-version"
23
+ },
24
+ "author": "",
25
+ "license": "MIT",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "peerDependencies": {
30
+ "@ant-design/cssinjs": ">=1.24.0",
31
+ "classnames": ">=2.3.0",
32
+ "react": "^19.2.0",
33
+ "react-dom": "^19.2.0",
34
+ "react-router-dom": "^7.0.0"
35
+ },
36
+ "dependencies": {
37
+ "ahooks": "^3.9.6",
38
+ "@swc/cli": "^0.7.9",
39
+ "@swc/core": "^1.15.3",
40
+ "swc": "^1.0.11",
41
+ "tsup": "^8.0.0",
42
+ "typescript": "^5.9.0",
43
+ "qs": "^6.14.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/qs": "^6.14.0",
47
+ "@swc/cli": "^0.7.9",
48
+ "@swc/core": "^1.15.3",
49
+ "@types/node": "^20.0.0",
50
+ "@types/react": "^19.0.0",
51
+ "@types/react-dom": "^19.0.0",
52
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
53
+ "@typescript-eslint/parser": "^8.0.0",
54
+ "@ant-design/cssinjs": "^1.24.0",
55
+ "eslint": "^9.0.0",
56
+ "eslint-config-prettier": "^9.0.0",
57
+ "eslint-plugin-prettier": "^5.0.0",
58
+ "eslint-plugin-react": "^7.35.0",
59
+ "eslint-plugin-react-hooks": "^5.0.0",
60
+ "exceljs": "^4.4.0",
61
+ "prettier": "^3.0.0",
62
+ "swc": "^1.0.11",
63
+ "tsup": "^8.0.0",
64
+ "turbo": "^2.0.0",
65
+ "typescript": "^5.9.0",
66
+ "vitest": "^2.0.0",
67
+ "react": "^19.2.0",
68
+ "react-dom": "^19.2.0",
69
+ "react-error-boundary": "^6.0.0",
70
+ "react-router-dom": "^7.9.5",
71
+ "react-scrollbars-custom": "^4.1.1"
72
+ },
73
+ "packageManager": "pnpm@10.20.0+sha512.cf9998222162dd85864d0a8102e7892e7ba4ceadebbf5a31f9c2fce48dfce317a9c53b9f6464d1ef9042cba2e02ae02a9f7c143a2b438cd93c91840f0192b9dd"
74
+ }