swico 0.7.2 → 0.8.0-beta1

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": "swico",
3
- "version": "0.7.2",
3
+ "version": "0.8.0-beta1",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -32,14 +32,14 @@
32
32
  "dependencies": {
33
33
  "react": "~18.2.0",
34
34
  "react-dom": "~18.2.0",
35
- "react-router-dom": "6.4.5",
35
+ "react-router-dom": "6.22.3",
36
36
  "vue": "~3.4.14",
37
37
  "vue-router": "^4.2.5",
38
38
  "history": "5.3.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/react": "18.2.0",
42
- "@types/react-dom": "18.2.0",
41
+ "@types/react": "18.2.79",
42
+ "@types/react-dom": "18.2.25",
43
43
  "@vue/compiler-sfc": "3.4.14",
44
44
  "eslint-plugin-react": "7.33.2",
45
45
  "eslint-plugin-react-hooks": "4.3.0",
@@ -10,7 +10,7 @@ export declare const Link: FC<{
10
10
  children: ReactNode;
11
11
  }>;
12
12
  export { Outlet } from 'react-router-dom';
13
- export { useLocation } from './template/react/react-hooks';
13
+ export { useLocation, useNav } from './template/react/react-hooks';
14
14
  export { history } from './mock-history';
15
15
  export interface DefineSwicoConfigType {
16
16
  (env: 'base', config: CustomConfigType['base']): any;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.defineGlobal = exports.defineConfig = exports.history = exports.useLocation = exports.Outlet = exports.Link = void 0;
6
+ exports.defineGlobal = exports.defineConfig = exports.history = exports.useNav = exports.useLocation = exports.Outlet = exports.Link = void 0;
7
7
  var react_router_dom_1 = require("react-router-dom");
8
8
  var react_1 = __importDefault(require("react"));
9
9
  var Link = function (_a) {
@@ -15,6 +15,7 @@ var react_router_dom_2 = require("react-router-dom");
15
15
  Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return react_router_dom_2.Outlet; } });
16
16
  var react_hooks_1 = require("./template/react/react-hooks");
17
17
  Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return react_hooks_1.useLocation; } });
18
+ Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return react_hooks_1.useNav; } });
18
19
  var mock_history_1 = require("./mock-history");
19
20
  Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
20
21
  var defineConfig = function (env, config) { return config; };
@@ -3,7 +3,7 @@ import { App } from 'vue';
3
3
  import { Router } from 'vue-router';
4
4
  export type CustomConfigType = GlobalData['customConfig'];
5
5
  export { RouterView as Outlet } from 'vue-router';
6
- export { useLocation } from './template/vue/vue-hooks';
6
+ export { useLocation, useNav } from './template/vue/vue-hooks';
7
7
  export { history } from './mock-history';
8
8
  export type { GlobalSwicoConfigType };
9
9
  export declare const Link: import("vue").DefineComponent<{
package/src/index.vue.js CHANGED
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineGlobal = exports.defineConfig = exports.Link = exports.history = exports.useLocation = exports.Outlet = void 0;
3
+ exports.defineGlobal = exports.defineConfig = exports.Link = exports.history = exports.useNav = exports.useLocation = exports.Outlet = void 0;
4
4
  var vue_1 = require("vue");
5
5
  var vue_router_1 = require("vue-router");
6
6
  var vue_router_2 = require("vue-router");
7
7
  Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return vue_router_2.RouterView; } });
8
8
  var vue_hooks_1 = require("./template/vue/vue-hooks");
9
9
  Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return vue_hooks_1.useLocation; } });
10
+ Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return vue_hooks_1.useNav; } });
10
11
  var mock_history_1 = require("./mock-history");
11
12
  Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
12
13
  exports.Link = (0, vue_1.defineComponent)({
@@ -1,2 +1,2 @@
1
- import { SwicoHistoryType } from './global-type';
1
+ import { SwicoHistoryType } from './typings/global-type';
2
2
  export declare const history: SwicoHistoryType;
@@ -1,2 +1,3 @@
1
- declare const _default: () => JSX.Element;
1
+ import React from 'react';
2
+ declare const _default: () => React.JSX.Element;
2
3
  export default _default;
@@ -1,6 +1,8 @@
1
1
  import { ConfigRouterType } from '../../../utils/config';
2
- import { SwicoHistoryType } from '../../../global-type';
2
+ import { SwicoHistoryType } from '../../../typings/global-type';
3
3
  export { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
4
+ export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
5
+ export declare const interpolatePath: (pathTemplate: string, params: Record<string, any>) => string;
4
6
  export declare const formatAncPath: (ancPath: string) => string;
5
7
  export declare const pathNameList: {
6
8
  path: string;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getOriHistory = exports.history = exports.pathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
6
+ exports.getOriHistory = exports.history = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = exports.HistoryRouter = void 0;
7
7
  var qs_1 = __importDefault(require("qs"));
8
8
  var history_1 = require("history");
9
9
  var routes_1 = __importDefault(require("./routes"));
@@ -30,6 +30,7 @@ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
30
30
  }
31
31
  return true;
32
32
  };
33
+ exports.compareURLPatterns = compareURLPatterns;
33
34
  var interpolatePath = function (pathTemplate, params) {
34
35
  var pathParts = pathTemplate.split('/');
35
36
  var interpolatedParts = pathParts.map(function (part) {
@@ -47,6 +48,7 @@ var interpolatePath = function (pathTemplate, params) {
47
48
  });
48
49
  return interpolatedParts.join('/');
49
50
  };
51
+ exports.interpolatePath = interpolatePath;
50
52
  var interpolatePathParams = function (pathTemplate, path) {
51
53
  var _a;
52
54
  if (pathTemplate === void 0) { pathTemplate = ''; }
@@ -88,7 +90,7 @@ var getLocation = function (originalHistory) {
88
90
  var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
89
91
  var routerBaseLength = formatRouterBase.length;
90
92
  var path = pathname.slice(routerBaseLength);
91
- var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || compareURLPatterns(path, item.path); });
93
+ var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
92
94
  var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
93
95
  return {
94
96
  hash: hash,
@@ -112,7 +114,7 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
112
114
  }
113
115
  if (name) {
114
116
  var fullPath = (_a = pathList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path;
115
- var targetPath = fullPath ? interpolatePath(fullPath, params) : null;
117
+ var targetPath = fullPath ? (0, exports.interpolatePath)(fullPath, params) : null;
116
118
  if (targetPath) {
117
119
  obj.pathname = "".concat(formatRouterBase).concat(targetPath);
118
120
  }
@@ -1,2 +1,3 @@
1
- import type { UseLocationType } from '../../global-type';
1
+ import { UseLocationType, UseNavType } from '../../typings/global-type';
2
2
  export declare const useLocation: UseLocationType;
3
+ export declare const useNav: UseNavType;
@@ -3,27 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useLocation = void 0;
6
+ exports.useNav = exports.useLocation = void 0;
7
7
  var react_router_dom_1 = require("react-router-dom");
8
8
  var history_1 = require("./$env/history");
9
9
  var qs_1 = __importDefault(require("qs"));
10
- var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
11
- var patternWithValuesParts = urlPatternWithValues.split('/');
12
- var patternWithParamsParts = urlPatternWithParams.split('/');
13
- if (patternWithValuesParts.length !== patternWithParamsParts.length) {
14
- return false;
15
- }
16
- for (var i = 0; i < patternWithValuesParts.length; i++) {
17
- var valuePart = patternWithValuesParts[i];
18
- var paramPart = patternWithParamsParts[i];
19
- if (paramPart.startsWith(':') && paramPart !== '') {
20
- continue;
21
- }
22
- if (valuePart !== paramPart) {
23
- return false;
24
- }
25
- }
26
- return true;
10
+ var getFormatNavPath = function (to) {
11
+ var _a;
12
+ var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
13
+ var search = query ? qs_1.default.stringify(query) : '';
14
+ var formatHash = hash ? (hash.startsWith('#') ? hash : "#".concat(hash)) : '';
15
+ var formatPath = name ? (_a = history_1.pathNameList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path : path;
16
+ var newPath = formatPath ? (0, history_1.interpolatePath)(formatPath, params || {}) : null;
17
+ newPath = newPath + search + formatHash;
18
+ return newPath;
27
19
  };
28
20
  var useLocation = function () {
29
21
  var _a, _b;
@@ -31,7 +23,7 @@ var useLocation = function () {
31
23
  var params = (0, react_router_dom_1.useParams)();
32
24
  var search = location.search, hash = location.hash, pathname = location.pathname;
33
25
  var name = (_a = history_1.pathNameList.find(function (item) {
34
- return (Object.keys(params).length > 0 && compareURLPatterns(pathname, item.path)) ||
26
+ return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
35
27
  item.path === pathname;
36
28
  })) === null || _a === void 0 ? void 0 : _a.name;
37
29
  var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
@@ -46,3 +38,23 @@ var useLocation = function () {
46
38
  };
47
39
  };
48
40
  exports.useLocation = useLocation;
41
+ var useNav = function () {
42
+ var navigate = (0, react_router_dom_1.useNavigate)();
43
+ var newNavigate = function (to, options) {
44
+ switch (typeof to) {
45
+ case 'string':
46
+ navigate(to, options);
47
+ break;
48
+ case 'number':
49
+ navigate(to);
50
+ break;
51
+ case 'object':
52
+ navigate(getFormatNavPath(to), options);
53
+ break;
54
+ default:
55
+ throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
56
+ }
57
+ };
58
+ return newNavigate;
59
+ };
60
+ exports.useNav = useNav;
@@ -1,3 +1,3 @@
1
- import { SwicoHistoryType } from '../../../global-type';
1
+ import { SwicoHistoryType } from '../../../typings/global-type';
2
2
  export declare let history: SwicoHistoryType;
3
3
  export declare const getRouter: () => import("vue-router").Router;
@@ -1,3 +1,4 @@
1
- import { UseLocationType } from '../../global-type';
1
+ import { UseLocationType, UseNavType } from '../../typings/global-type';
2
2
  export declare const getFormatRouterBase: (routerBase: any) => any;
3
3
  export declare const useLocation: UseLocationType;
4
+ export declare const useNav: UseNavType;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useLocation = exports.getFormatRouterBase = void 0;
6
+ exports.useNav = exports.useLocation = exports.getFormatRouterBase = void 0;
7
7
  var vue_router_1 = require("vue-router");
8
8
  var qs_1 = __importDefault(require("qs"));
9
9
  var vue_1 = require("vue");
@@ -38,3 +38,33 @@ var useLocation = function () {
38
38
  return location;
39
39
  };
40
40
  exports.useLocation = useLocation;
41
+ var useNav = function () {
42
+ var router = (0, vue_router_1.useRouter)();
43
+ var newNavigate = function (to, options) {
44
+ switch (typeof to) {
45
+ case 'string':
46
+ if (options.replace) {
47
+ router.replace(to);
48
+ }
49
+ else {
50
+ router.push(to);
51
+ }
52
+ break;
53
+ case 'number':
54
+ router.go(to);
55
+ break;
56
+ case 'object':
57
+ if (options.replace) {
58
+ router.replace(to);
59
+ }
60
+ else {
61
+ router.push(to);
62
+ }
63
+ break;
64
+ default:
65
+ throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
66
+ }
67
+ };
68
+ return newNavigate;
69
+ };
70
+ exports.useNav = useNav;
@@ -1,11 +1,11 @@
1
1
  export type SwicoLocationType = {
2
+ query?: Record<string, any>;
3
+ params?: Record<string, any>;
4
+ hash: string;
2
5
  name: string;
3
6
  path: string;
4
7
  pathname: string;
5
8
  search: string;
6
- query?: Record<string, any>;
7
- hash: string;
8
- params?: Record<string, any>;
9
9
  };
10
10
  export type SwicoHistoryOptionType = {
11
11
  query?: Record<string, any>;
@@ -22,14 +22,12 @@ export type SwicoHistoryType = {
22
22
  back: () => void;
23
23
  location: SwicoLocationType;
24
24
  };
25
- export type UseLocationType = {
26
- (): {
27
- name: string;
28
- path: string;
29
- pathname: string;
30
- search: string;
31
- query?: Record<string, any>;
32
- hash: string;
33
- params?: Record<string, any>;
34
- };
25
+ export type UseLocationType = () => SwicoLocationType;
26
+ export type NavOptionsType = {
27
+ replace: boolean;
28
+ };
29
+ export type UseNavType = () => {
30
+ (to: string, options?: NavOptionsType): void;
31
+ (to: number): void;
32
+ (to: SwicoHistoryOptionType, options?: NavOptionsType): void;
35
33
  };
package/README.md DELETED
@@ -1,21 +0,0 @@
1
- # SWICO介绍
2
-
3
- Swico,发音类似于“斯威扣”。
4
-
5
- 为个人独立开发的一款实用的前端框架,它基于前端工程化最新技术栈实现了前端开发从创建项目,获取模板,本地开发,Git提交校验到打包构建的完整过程。
6
-
7
-
8
- ## 主要特性
9
-
10
- - 构建工具基于[Webpack5],并配合[esbuild-loader]和[swc-loader]提升编译构建速率。
11
-
12
- - 提供[Vue3]和[React18]两种开发模板选择,默认集成[TypeScript5]。同时最大化统一这两种模板的开发API。
13
-
14
- - 提供可配置化路由方案,基于[React-Router6]和[Vue-Router4]进行二次封装,支持路由嵌套,懒加载,动态参数,装饰校验等功能。
15
-
16
- - 内置[ESLint] + [Prettier] + [Husky]三大前端编码风格以及代码提交规范约束插件,保证代码风格统一以及 Git 提交规范。
17
-
18
- - 提供配置文件可对部分项目配置进行修改扩展,例如Alias映射,本地请求代理等。
19
-
20
-
21
- 详见:[SWICO 官方文档](http://fanlaboy.gitee.io/swico-docs)
File without changes