swico 0.9.0-beta1 → 0.9.0-beta10
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,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,15 @@ 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
9
|
var history_1 = require("history");
|
|
9
10
|
var routes_1 = __importDefault(require("./routes"));
|
|
10
11
|
var config_1 = require("./config");
|
|
12
|
+
var layout_1 = __importDefault(require("../../layout"));
|
|
11
13
|
var react_router_dom_1 = require("react-router-dom");
|
|
12
|
-
|
|
14
|
+
var react_1 = __importDefault(require("react"));
|
|
13
15
|
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
14
16
|
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
15
17
|
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
@@ -86,14 +88,14 @@ var getPathNameList = function (routes) {
|
|
|
86
88
|
return list;
|
|
87
89
|
};
|
|
88
90
|
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
|
|
91
|
+
var getLocation = function (originalHistory, state) {
|
|
92
|
+
var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
|
|
91
93
|
var routerBaseLength = formatRouterBase.length;
|
|
92
94
|
var path = pathname.slice(routerBaseLength);
|
|
93
95
|
var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
|
|
94
96
|
var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
|
|
95
97
|
return {
|
|
96
|
-
state: state,
|
|
98
|
+
state: state !== null && state !== void 0 ? state : {},
|
|
97
99
|
hash: hash,
|
|
98
100
|
search: search,
|
|
99
101
|
pathname: pathname,
|
|
@@ -103,22 +105,21 @@ var getLocation = function (originalHistory) {
|
|
|
103
105
|
path: path
|
|
104
106
|
};
|
|
105
107
|
};
|
|
106
|
-
var getFormatHistoryOption = function (to,
|
|
108
|
+
var getFormatHistoryOption = function (to, pathList, type) {
|
|
107
109
|
var _a;
|
|
108
|
-
var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query
|
|
110
|
+
var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
|
|
109
111
|
var obj = {
|
|
110
112
|
hash: hash,
|
|
111
|
-
state: state,
|
|
112
113
|
search: query ? qs_1.default.stringify(query) : undefined
|
|
113
114
|
};
|
|
114
115
|
if (path) {
|
|
115
|
-
obj.pathname =
|
|
116
|
+
obj.pathname = path;
|
|
116
117
|
}
|
|
117
118
|
if (name) {
|
|
118
119
|
var fullPath = (_a = pathList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path;
|
|
119
120
|
var targetPath = fullPath ? (0, exports.interpolatePath)(fullPath, params) : null;
|
|
120
121
|
if (targetPath) {
|
|
121
|
-
obj.pathname =
|
|
122
|
+
obj.pathname = targetPath;
|
|
122
123
|
}
|
|
123
124
|
else {
|
|
124
125
|
throw "An error occurred while executing 'history.".concat(type, "' operation: The path for the name \"").concat(name, "\" could not be found");
|
|
@@ -126,21 +127,35 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
|
|
|
126
127
|
}
|
|
127
128
|
return obj;
|
|
128
129
|
};
|
|
129
|
-
var
|
|
130
|
+
var getRouter = function (routerType) {
|
|
130
131
|
var _a;
|
|
131
|
-
var
|
|
132
|
+
var routeList = [
|
|
133
|
+
{
|
|
134
|
+
element: react_1.default.createElement(layout_1.default, null),
|
|
135
|
+
path: '/',
|
|
136
|
+
children: (0, index_1.getChildrenRouteList)(routes_1.default, '')
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
var router = (routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList);
|
|
140
|
+
var oriHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
|
|
132
141
|
exports.history = {
|
|
133
|
-
go:
|
|
134
|
-
|
|
135
|
-
|
|
142
|
+
go: function (delta) {
|
|
143
|
+
router.navigate(delta);
|
|
144
|
+
},
|
|
145
|
+
forward: function () {
|
|
146
|
+
router.navigate(1);
|
|
147
|
+
},
|
|
148
|
+
back: function () {
|
|
149
|
+
router.navigate(-1);
|
|
150
|
+
},
|
|
136
151
|
push: function (to) {
|
|
137
152
|
switch (typeof to) {
|
|
138
153
|
case 'string':
|
|
139
|
-
|
|
154
|
+
router.navigate(to);
|
|
140
155
|
break;
|
|
141
156
|
case 'object':
|
|
142
|
-
var formatOption = getFormatHistoryOption(to,
|
|
143
|
-
|
|
157
|
+
var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'push');
|
|
158
|
+
router.navigate(formatOption, { state: to.state });
|
|
144
159
|
break;
|
|
145
160
|
default:
|
|
146
161
|
throw "An error occurred while executing history.push operation: unexpected type of 'to':".concat(typeof to);
|
|
@@ -149,20 +164,20 @@ var getOriHistory = function (routerType) {
|
|
|
149
164
|
replace: function (to) {
|
|
150
165
|
switch (typeof to) {
|
|
151
166
|
case 'string':
|
|
152
|
-
|
|
167
|
+
router.navigate(to, { replace: true });
|
|
153
168
|
break;
|
|
154
169
|
case 'object':
|
|
155
|
-
var formatOption = getFormatHistoryOption(to,
|
|
156
|
-
|
|
170
|
+
var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'replace');
|
|
171
|
+
router.navigate(formatOption, { state: to.state, replace: true });
|
|
157
172
|
break;
|
|
158
173
|
default:
|
|
159
174
|
throw "An error occurred while executing history.replace operation: unexpected type of 'to':".concat(typeof to);
|
|
160
175
|
}
|
|
161
176
|
},
|
|
162
177
|
get location() {
|
|
163
|
-
return getLocation(
|
|
178
|
+
return getLocation(oriHistory, router.state);
|
|
164
179
|
}
|
|
165
180
|
};
|
|
166
|
-
return
|
|
181
|
+
return router;
|
|
167
182
|
};
|
|
168
|
-
exports.
|
|
183
|
+
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);
|