swico 0.9.0-beta1 → 0.9.0-beta11
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-
|
|
3
|
+
"version": "0.9.0-beta11",
|
|
4
4
|
"description": "Simple, efficient, and practical front-end framework",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -34,30 +34,18 @@
|
|
|
34
34
|
"react-dom": "~18.2.0",
|
|
35
35
|
"react-router-dom": "6.22.3",
|
|
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
1
|
import { ConfigRouterType } from '../../../utils/config';
|
|
2
2
|
import { SwicoHistoryType } from '../../../typings/global-type';
|
|
3
|
-
export { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
|
|
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;
|
|
@@ -9,4 +8,4 @@ export declare const pathNameList: {
|
|
|
9
8
|
name: string;
|
|
10
9
|
}[];
|
|
11
10
|
export declare let history: SwicoHistoryType;
|
|
12
|
-
export declare const
|
|
11
|
+
export declare const getRouter: (routerType: ConfigRouterType['type']) => import("@remix-run/router").Router;
|
|
@@ -3,13 +3,14 @@ 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.
|
|
6
|
+
exports.getRouter = exports.history = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
|
|
7
|
+
var index_1 = require("./index");
|
|
7
8
|
var qs_1 = __importDefault(require("qs"));
|
|
8
|
-
var history_1 = require("history");
|
|
9
9
|
var routes_1 = __importDefault(require("./routes"));
|
|
10
10
|
var config_1 = require("./config");
|
|
11
|
+
var layout_1 = __importDefault(require("../../layout"));
|
|
11
12
|
var react_router_dom_1 = require("react-router-dom");
|
|
12
|
-
|
|
13
|
+
var react_1 = __importDefault(require("react"));
|
|
13
14
|
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
14
15
|
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
15
16
|
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
@@ -86,14 +87,14 @@ var getPathNameList = function (routes) {
|
|
|
86
87
|
return list;
|
|
87
88
|
};
|
|
88
89
|
exports.pathNameList = getPathNameList(routes_1.default);
|
|
89
|
-
var getLocation = function (
|
|
90
|
-
var
|
|
90
|
+
var getLocation = function (historyLocation) {
|
|
91
|
+
var pathname = historyLocation.pathname, hash = historyLocation.hash, search = historyLocation.search, state = historyLocation.state;
|
|
91
92
|
var routerBaseLength = formatRouterBase.length;
|
|
92
93
|
var path = pathname.slice(routerBaseLength);
|
|
93
94
|
var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
|
|
94
95
|
var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
|
|
95
96
|
return {
|
|
96
|
-
state: state,
|
|
97
|
+
state: state !== null && state !== void 0 ? state : {},
|
|
97
98
|
hash: hash,
|
|
98
99
|
search: search,
|
|
99
100
|
pathname: pathname,
|
|
@@ -103,22 +104,21 @@ var getLocation = function (originalHistory) {
|
|
|
103
104
|
path: path
|
|
104
105
|
};
|
|
105
106
|
};
|
|
106
|
-
var getFormatHistoryOption = function (to,
|
|
107
|
+
var getFormatHistoryOption = function (to, pathList, type) {
|
|
107
108
|
var _a;
|
|
108
|
-
var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query
|
|
109
|
+
var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
|
|
109
110
|
var obj = {
|
|
110
111
|
hash: hash,
|
|
111
|
-
state: state,
|
|
112
112
|
search: query ? qs_1.default.stringify(query) : undefined
|
|
113
113
|
};
|
|
114
114
|
if (path) {
|
|
115
|
-
obj.pathname =
|
|
115
|
+
obj.pathname = path;
|
|
116
116
|
}
|
|
117
117
|
if (name) {
|
|
118
118
|
var fullPath = (_a = pathList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path;
|
|
119
119
|
var targetPath = fullPath ? (0, exports.interpolatePath)(fullPath, params) : null;
|
|
120
120
|
if (targetPath) {
|
|
121
|
-
obj.pathname =
|
|
121
|
+
obj.pathname = targetPath;
|
|
122
122
|
}
|
|
123
123
|
else {
|
|
124
124
|
throw "An error occurred while executing 'history.".concat(type, "' operation: The path for the name \"").concat(name, "\" could not be found");
|
|
@@ -126,21 +126,33 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
|
|
|
126
126
|
}
|
|
127
127
|
return obj;
|
|
128
128
|
};
|
|
129
|
-
var
|
|
130
|
-
var
|
|
131
|
-
|
|
129
|
+
var getRouter = function (routerType) {
|
|
130
|
+
var routeList = [
|
|
131
|
+
{
|
|
132
|
+
element: react_1.default.createElement(layout_1.default, null),
|
|
133
|
+
path: '/',
|
|
134
|
+
children: (0, index_1.getChildrenRouteList)(routes_1.default, '')
|
|
135
|
+
}
|
|
136
|
+
];
|
|
137
|
+
var router = (routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList);
|
|
132
138
|
exports.history = {
|
|
133
|
-
go:
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
go: function (delta) {
|
|
140
|
+
router.navigate(delta);
|
|
141
|
+
},
|
|
142
|
+
forward: function () {
|
|
143
|
+
router.navigate(1);
|
|
144
|
+
},
|
|
145
|
+
back: function () {
|
|
146
|
+
router.navigate(-1);
|
|
147
|
+
},
|
|
136
148
|
push: function (to) {
|
|
137
149
|
switch (typeof to) {
|
|
138
150
|
case 'string':
|
|
139
|
-
|
|
151
|
+
router.navigate(to);
|
|
140
152
|
break;
|
|
141
153
|
case 'object':
|
|
142
|
-
var formatOption = getFormatHistoryOption(to,
|
|
143
|
-
|
|
154
|
+
var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'push');
|
|
155
|
+
router.navigate(formatOption, { state: to.state });
|
|
144
156
|
break;
|
|
145
157
|
default:
|
|
146
158
|
throw "An error occurred while executing history.push operation: unexpected type of 'to':".concat(typeof to);
|
|
@@ -149,20 +161,20 @@ var getOriHistory = function (routerType) {
|
|
|
149
161
|
replace: function (to) {
|
|
150
162
|
switch (typeof to) {
|
|
151
163
|
case 'string':
|
|
152
|
-
|
|
164
|
+
router.navigate(to, { replace: true });
|
|
153
165
|
break;
|
|
154
166
|
case 'object':
|
|
155
|
-
var formatOption = getFormatHistoryOption(to,
|
|
156
|
-
|
|
167
|
+
var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'replace');
|
|
168
|
+
router.navigate(formatOption, { state: to.state, replace: true });
|
|
157
169
|
break;
|
|
158
170
|
default:
|
|
159
171
|
throw "An error occurred while executing history.replace operation: unexpected type of 'to':".concat(typeof to);
|
|
160
172
|
}
|
|
161
173
|
},
|
|
162
174
|
get location() {
|
|
163
|
-
return getLocation(
|
|
175
|
+
return getLocation(router.state.location);
|
|
164
176
|
}
|
|
165
177
|
};
|
|
166
|
-
return
|
|
178
|
+
return router;
|
|
167
179
|
};
|
|
168
|
-
exports.
|
|
180
|
+
exports.getRouter = getRouter;
|
|
@@ -26,32 +26,35 @@ 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
35
|
var config_1 = require("./config");
|
|
36
36
|
require("../../global");
|
|
37
|
-
var
|
|
38
|
-
var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
37
|
+
var getChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
39
38
|
return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
|
|
40
39
|
var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
|
|
41
40
|
var newAncPathKey = "".concat(ancPathKey, "-").concat(path);
|
|
42
|
-
return
|
|
41
|
+
return {
|
|
42
|
+
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)),
|
|
43
|
+
key: newAncPathKey,
|
|
44
|
+
path: path.startsWith('/') ? path.slice(1) : path,
|
|
45
|
+
children: (0, exports.getChildrenRouteList)(children, newAncPathKey)
|
|
46
|
+
};
|
|
43
47
|
});
|
|
44
48
|
};
|
|
49
|
+
exports.getChildrenRouteList = getChildrenRouteList;
|
|
45
50
|
var App = function () {
|
|
46
|
-
var
|
|
51
|
+
var router = (0, history_1.getRouter)(config_1.routerType);
|
|
47
52
|
if (config_1.routerBase && config_1.routerBase !== '/') {
|
|
48
53
|
if (config_1.routerType === 'browser' && window.location.pathname === '/') {
|
|
49
54
|
window.location.replace("".concat(config_1.routerBase));
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
|
-
return
|
|
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, '')))));
|
|
57
|
+
return react_1.default.createElement(react_router_dom_1.RouterProvider, { router: router, basename: config_1.routerBase });
|
|
55
58
|
};
|
|
56
59
|
var root = (0, client_1.createRoot)(document.getElementById('root'));
|
|
57
60
|
root.render(react_1.default.createElement(App, null));
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
@@ -11,7 +22,7 @@ var useLocation = function () {
|
|
|
11
22
|
var _a, _b;
|
|
12
23
|
var location = (0, react_router_dom_1.useLocation)();
|
|
13
24
|
var params = (0, react_router_dom_1.useParams)();
|
|
14
|
-
var search = location.search, hash = location.hash, pathname = location.pathname,
|
|
25
|
+
var search = location.search, hash = location.hash, pathname = location.pathname, state = location.state;
|
|
15
26
|
var name = (_a = history_1.pathNameList.find(function (item) {
|
|
16
27
|
return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
|
|
17
28
|
item.path === pathname;
|
|
@@ -19,7 +30,7 @@ var useLocation = function () {
|
|
|
19
30
|
var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
|
|
20
31
|
return {
|
|
21
32
|
name: name,
|
|
22
|
-
state: state,
|
|
33
|
+
state: state !== null && state !== void 0 ? state : {},
|
|
23
34
|
path: pathname,
|
|
24
35
|
pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
|
|
25
36
|
search: '',
|
|
@@ -50,7 +61,7 @@ var useNav = function () {
|
|
|
50
61
|
navigate(to);
|
|
51
62
|
break;
|
|
52
63
|
case 'object':
|
|
53
|
-
navigate(getFormatNavPath(to), options);
|
|
64
|
+
navigate(getFormatNavPath(to), __assign(__assign({}, (options || {})), { state: to.state }));
|
|
54
65
|
break;
|
|
55
66
|
default:
|
|
56
67
|
throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
|