swico 0.9.0-beta2 → 0.9.0-beta20

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.9.0-beta2",
3
+ "version": "0.9.0-beta20",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -32,32 +32,20 @@
32
32
  "dependencies": {
33
33
  "react": "~18.2.0",
34
34
  "react-dom": "~18.2.0",
35
- "react-router-dom": "6.22.3",
35
+ "react-router-dom": "6.23.0",
36
36
  "vue": "~3.4.14",
37
- "vue-router": "^4.2.5",
38
- "history": "5.3.0"
37
+ "vue-router": "^4.2.5"
39
38
  },
40
39
  "devDependencies": {
41
- "@types/react": "18.2.79",
42
- "@types/react-dom": "18.2.25",
43
- "@vue/compiler-sfc": "3.4.14",
44
- "eslint-plugin-react": "7.33.2",
45
- "eslint-plugin-react-hooks": "4.3.0",
46
- "eslint-plugin-vue": "9.19.2",
47
- "vue-loader": "17.4.2",
48
- "vue-style-loader": "4.1.3",
49
- "webpack": "5.88.2",
50
- "webpack-bundle-analyzer": "4.9.1",
51
- "webpack-cli": "5.1.4",
52
- "webpack-dev-server": "4.15.2",
53
- "webpack-merge": "5.9.0",
54
- "webpackbar": "6.0.1",
55
40
  "@babel/types": "7.23.9",
56
41
  "@commitlint/cli": "18.5.0",
57
42
  "@commitlint/config-conventional": "18.5.0",
58
43
  "@swc/core": "1.4.6",
44
+ "@types/react": "18.2.79",
45
+ "@types/react-dom": "18.2.25",
59
46
  "@typescript-eslint/eslint-plugin": "6.19.0",
60
47
  "@typescript-eslint/parser": "6.19.0",
48
+ "@vue/compiler-sfc": "3.4.14",
61
49
  "autoprefixer": "10.3.7",
62
50
  "chalk": "4.1.2",
63
51
  "chokidar": "3.6.0",
@@ -68,6 +56,9 @@
68
56
  "css-loader": "6.3.0",
69
57
  "esbuild-loader": "4.0.3",
70
58
  "eslint": "8.48.0",
59
+ "eslint-plugin-react": "7.33.2",
60
+ "eslint-plugin-react-hooks": "4.3.0",
61
+ "eslint-plugin-vue": "9.19.2",
71
62
  "eslint-webpack-plugin": "4.0.0",
72
63
  "fork-ts-checker-webpack-plugin": "9.0.2",
73
64
  "html-loader": "5.0.0",
@@ -85,6 +76,14 @@
85
76
  "style-loader": "3.3.0",
86
77
  "swc-loader": "0.2.6",
87
78
  "ts-node": "10.9.1",
88
- "typescript": "5.3.3"
79
+ "typescript": "5.3.3",
80
+ "vue-loader": "17.4.2",
81
+ "vue-style-loader": "4.1.3",
82
+ "webpack": "5.88.2",
83
+ "webpack-bundle-analyzer": "4.9.1",
84
+ "webpack-cli": "5.1.4",
85
+ "webpack-dev-server": "4.15.2",
86
+ "webpack-merge": "5.9.0",
87
+ "webpackbar": "6.0.1"
89
88
  }
90
89
  }
@@ -1,6 +1,5 @@
1
- import { ConfigRouterType } from '../../../utils/config';
2
- import { SwicoHistoryType } from '../../../typings/global-type';
3
- export { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
1
+ import { SwicoHistoryType, SwicoLocationType } from '../../../typings/global-type';
2
+ import React from 'react';
4
3
  export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
5
4
  export declare const interpolatePath: (pathTemplate: string, params: Record<string, any>) => string;
6
5
  export declare const formatAncPath: (ancPath: string) => string;
@@ -8,5 +7,13 @@ export declare const pathNameList: {
8
7
  path: string;
9
8
  name: string;
10
9
  }[];
10
+ export declare const getHistory: (router: any) => {
11
+ go: (delta: any) => void;
12
+ forward: () => void;
13
+ back: () => void;
14
+ push: (to: any) => void;
15
+ replace: (to: any) => void;
16
+ readonly location: SwicoLocationType;
17
+ };
11
18
  export declare let history: SwicoHistoryType;
12
- export declare const getOriHistory: (routerType: ConfigRouterType['type']) => import("history").HashHistory;
19
+ export declare const RouterProvider: () => React.JSX.Element;
@@ -1,15 +1,39 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getOriHistory = exports.history = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = exports.HistoryRouter = void 0;
29
+ exports.RouterProvider = exports.history = exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
30
+ var index_1 = require("./index");
7
31
  var qs_1 = __importDefault(require("qs"));
8
- var history_1 = require("history");
9
32
  var routes_1 = __importDefault(require("./routes"));
10
33
  var config_1 = require("./config");
11
34
  var react_router_dom_1 = require("react-router-dom");
12
- Object.defineProperty(exports, "HistoryRouter", { enumerable: true, get: function () { return react_router_dom_1.unstable_HistoryRouter; } });
35
+ var layout_1 = __importDefault(require("../../layout"));
36
+ var react_1 = __importStar(require("react"));
13
37
  var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
14
38
  var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
15
39
  var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
@@ -86,14 +110,15 @@ var getPathNameList = function (routes) {
86
110
  return list;
87
111
  };
88
112
  exports.pathNameList = getPathNameList(routes_1.default);
89
- var getLocation = function (originalHistory) {
90
- var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search, _b = _a.state, state = _b === void 0 ? {} : _b;
113
+ var getLocation = function (historyLocation) {
114
+ console.log('historyLocation', historyLocation);
115
+ var pathname = historyLocation.pathname, hash = historyLocation.hash, search = historyLocation.search, state = historyLocation.state;
91
116
  var routerBaseLength = formatRouterBase.length;
92
117
  var path = pathname.slice(routerBaseLength);
93
118
  var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
94
119
  var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
95
120
  return {
96
- state: state,
121
+ state: state !== null && state !== void 0 ? state : {},
97
122
  hash: hash,
98
123
  search: search,
99
124
  pathname: pathname,
@@ -103,22 +128,21 @@ var getLocation = function (originalHistory) {
103
128
  path: path
104
129
  };
105
130
  };
106
- var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
131
+ var getFormatHistoryOption = function (to, pathList, type) {
107
132
  var _a;
108
- var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query, state = to.state;
133
+ var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
109
134
  var obj = {
110
135
  hash: hash,
111
- state: state,
112
136
  search: query ? qs_1.default.stringify(query) : undefined
113
137
  };
114
138
  if (path) {
115
- obj.pathname = "".concat(formatRouterBase).concat(path);
139
+ obj.pathname = path;
116
140
  }
117
141
  if (name) {
118
142
  var fullPath = (_a = pathList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path;
119
143
  var targetPath = fullPath ? (0, exports.interpolatePath)(fullPath, params) : null;
120
144
  if (targetPath) {
121
- obj.pathname = "".concat(formatRouterBase).concat(targetPath);
145
+ obj.pathname = targetPath;
122
146
  }
123
147
  else {
124
148
  throw "An error occurred while executing 'history.".concat(type, "' operation: The path for the name \"").concat(name, "\" could not be found");
@@ -126,21 +150,25 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
126
150
  }
127
151
  return obj;
128
152
  };
129
- var getOriHistory = function (routerType) {
130
- var _a;
131
- var originalHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
132
- exports.history = {
133
- go: originalHistory.go,
134
- forward: originalHistory.forward,
135
- back: originalHistory.back,
153
+ var getHistory = function (router) {
154
+ return {
155
+ go: function (delta) {
156
+ router.navigate(delta);
157
+ },
158
+ forward: function () {
159
+ router.navigate(1);
160
+ },
161
+ back: function () {
162
+ router.navigate(-1);
163
+ },
136
164
  push: function (to) {
137
165
  switch (typeof to) {
138
166
  case 'string':
139
- originalHistory.push("".concat(formatRouterBase).concat(to));
167
+ router.navigate(to);
140
168
  break;
141
169
  case 'object':
142
- var formatOption = getFormatHistoryOption(to, formatRouterBase, exports.pathNameList, 'push');
143
- originalHistory.push(formatOption);
170
+ var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'push');
171
+ router.navigate(formatOption, { state: to.state });
144
172
  break;
145
173
  default:
146
174
  throw "An error occurred while executing history.push operation: unexpected type of 'to':".concat(typeof to);
@@ -149,20 +177,41 @@ var getOriHistory = function (routerType) {
149
177
  replace: function (to) {
150
178
  switch (typeof to) {
151
179
  case 'string':
152
- originalHistory.replace("".concat(formatRouterBase).concat(to));
180
+ router.navigate(to, { replace: true });
153
181
  break;
154
182
  case 'object':
155
- var formatOption = getFormatHistoryOption(to, formatRouterBase, exports.pathNameList, 'replace');
156
- originalHistory.replace(formatOption);
183
+ var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'replace');
184
+ router.navigate(formatOption, { state: to.state, replace: true });
157
185
  break;
158
186
  default:
159
187
  throw "An error occurred while executing history.replace operation: unexpected type of 'to':".concat(typeof to);
160
188
  }
161
189
  },
162
190
  get location() {
163
- return getLocation(originalHistory);
191
+ return getLocation(router.state.location);
164
192
  }
165
193
  };
166
- return originalHistory;
167
194
  };
168
- exports.getOriHistory = getOriHistory;
195
+ exports.getHistory = getHistory;
196
+ var RouterProvider = function () {
197
+ var routeList = [
198
+ {
199
+ element: react_1.default.createElement(layout_1.default, null),
200
+ path: '/',
201
+ children: (0, index_1.getChildrenRouteList)(routes_1.default, '')
202
+ }
203
+ ];
204
+ var router = (config_1.routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList, {
205
+ basename: config_1.routerBase
206
+ });
207
+ if (config_1.routerBase && config_1.routerBase !== '/') {
208
+ if (config_1.routerType === 'browser' && window.location.pathname === '/') {
209
+ window.location.replace("".concat(config_1.routerBase));
210
+ }
211
+ }
212
+ (0, react_1.useLayoutEffect)(function () {
213
+ exports.history = (0, exports.getHistory)(router);
214
+ });
215
+ return react_1.default.createElement(react_router_dom_1.RouterProvider, { router: router });
216
+ };
217
+ exports.RouterProvider = RouterProvider;
@@ -9,3 +9,4 @@ export type RoutesItemType = {
9
9
  redirect?: string;
10
10
  name?: string;
11
11
  };
12
+ export declare const getChildrenRouteList: (childrenRoutes: RoutesItemType[], ancPathKey: string) => any;
@@ -26,32 +26,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.getChildrenRouteList = void 0;
29
30
  var client_1 = require("react-dom/client");
30
31
  var react_1 = __importStar(require("react"));
31
32
  var react_router_dom_1 = require("react-router-dom");
32
- var routes_1 = __importDefault(require("./routes"));
33
33
  var loading_1 = __importDefault(require("../loading"));
34
34
  var history_1 = require("./history");
35
- var config_1 = require("./config");
36
35
  require("../../global");
37
- var layout_1 = __importDefault(require("../../layout"));
38
- var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
36
+ var getChildrenRouteList = function (childrenRoutes, ancPathKey) {
39
37
  return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
40
38
  var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
41
39
  var newAncPathKey = "".concat(ancPathKey, "-").concat(path);
42
- return (react_1.default.createElement(react_router_dom_1.Route, { element: redirect ? (react_1.default.createElement(react_router_dom_1.Navigate, { to: redirect, replace: true })) : component ? (react_1.default.createElement(react_1.Suspense, { fallback: (0, react_1.createElement)(loading_1.default) }, (0, react_1.createElement)((0, react_1.lazy)(component)))) : (react_1.default.createElement(react_router_dom_1.Outlet, null)), key: newAncPathKey, path: path }, renderChildrenRouteList(children, newAncPathKey)));
40
+ return {
41
+ element: redirect ? (react_1.default.createElement(react_router_dom_1.Navigate, { to: redirect, replace: true })) : component ? (react_1.default.createElement(react_1.Suspense, { fallback: react_1.default.createElement(loading_1.default, null) }, (0, react_1.createElement)((0, react_1.lazy)(component)))) : (react_1.default.createElement(react_router_dom_1.Outlet, null)),
42
+ key: newAncPathKey,
43
+ path: path.startsWith('/') ? path.slice(1) : path,
44
+ children: (0, exports.getChildrenRouteList)(children, newAncPathKey)
45
+ };
43
46
  });
44
47
  };
45
- var App = function () {
46
- var originalHistory = (0, history_1.getOriHistory)(config_1.routerType);
47
- if (config_1.routerBase && config_1.routerBase !== '/') {
48
- if (config_1.routerType === 'browser' && window.location.pathname === '/') {
49
- window.location.replace("".concat(config_1.routerBase));
50
- }
51
- }
52
- return (react_1.default.createElement(history_1.HistoryRouter, { basename: config_1.routerBase, history: originalHistory },
53
- react_1.default.createElement(react_router_dom_1.Routes, null,
54
- react_1.default.createElement(react_router_dom_1.Route, { element: react_1.default.createElement(layout_1.default, null), path: '' }, renderChildrenRouteList(routes_1.default, '')))));
55
- };
48
+ exports.getChildrenRouteList = getChildrenRouteList;
56
49
  var root = (0, client_1.createRoot)(document.getElementById('root'));
57
- root.render(react_1.default.createElement(App, null));
50
+ root.render(react_1.default.createElement(history_1.RouterProvider, null));
@@ -22,7 +22,7 @@ var useLocation = function () {
22
22
  var _a, _b;
23
23
  var location = (0, react_router_dom_1.useLocation)();
24
24
  var params = (0, react_router_dom_1.useParams)();
25
- var search = location.search, hash = location.hash, pathname = location.pathname, _c = location.state, state = _c === void 0 ? {} : _c;
25
+ var search = location.search, hash = location.hash, pathname = location.pathname, state = location.state;
26
26
  var name = (_a = history_1.pathNameList.find(function (item) {
27
27
  return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
28
28
  item.path === pathname;
@@ -30,7 +30,7 @@ var useLocation = function () {
30
30
  var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
31
31
  return {
32
32
  name: name,
33
- state: state,
33
+ state: state !== null && state !== void 0 ? state : {},
34
34
  path: pathname,
35
35
  pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
36
36
  search: '',