swico 0.9.0-beta6 → 0.9.0-beta8
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 +1 -1
- package/src/index.react.d.ts +1 -1
- package/src/index.react.js +1 -2
- package/src/mock-history.d.ts +0 -4
- package/src/mock-history.js +1 -3
- package/src/template/react/$env/history.d.ts +2 -4
- package/src/template/react/$env/history.js +28 -25
- package/src/template/react/$env/index.d.ts +1 -0
- package/src/template/react/$env/index.js +11 -7
package/package.json
CHANGED
package/src/index.react.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const Link: FC<{
|
|
|
11
11
|
}>;
|
|
12
12
|
export { Outlet } from 'react-router-dom';
|
|
13
13
|
export { useLocation, useNav } from './template/react/react-hooks';
|
|
14
|
-
export { history
|
|
14
|
+
export { history } from './mock-history';
|
|
15
15
|
export interface DefineSwicoConfigType {
|
|
16
16
|
(env: 'base', config: CustomConfigType['base']): any;
|
|
17
17
|
(env: 'dev', config: CustomConfigType['dev']): any;
|
package/src/index.react.js
CHANGED
|
@@ -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.
|
|
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) {
|
|
@@ -18,7 +18,6 @@ Object.defineProperty(exports, "useLocation", { enumerable: true, get: function
|
|
|
18
18
|
Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return react_hooks_1.useNav; } });
|
|
19
19
|
var mock_history_1 = require("./mock-history");
|
|
20
20
|
Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
|
|
21
|
-
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return mock_history_1.Router; } });
|
|
22
21
|
var defineConfig = function (env, config) { return config; };
|
|
23
22
|
exports.defineConfig = defineConfig;
|
|
24
23
|
var defineGlobal = function (config) {
|
package/src/mock-history.d.ts
CHANGED
package/src/mock-history.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
+
import { ConfigRouterType } from '../../../utils/config';
|
|
1
2
|
import { SwicoHistoryType } from '../../../typings/global-type';
|
|
2
|
-
import React, { ReactNode } from 'react';
|
|
3
|
-
export declare const Router: React.FC<{
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
}>;
|
|
6
3
|
export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
|
|
7
4
|
export declare const interpolatePath: (pathTemplate: string, params: Record<string, any>) => string;
|
|
8
5
|
export declare const formatAncPath: (ancPath: string) => string;
|
|
@@ -11,3 +8,4 @@ export declare const pathNameList: {
|
|
|
11
8
|
name: string;
|
|
12
9
|
}[];
|
|
13
10
|
export declare let history: SwicoHistoryType;
|
|
11
|
+
export declare const getRouter: (routerType: ConfigRouterType['type']) => import("@remix-run/router").Router;
|
|
@@ -3,18 +3,13 @@ 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.history = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns =
|
|
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");
|
|
11
12
|
var react_router_dom_1 = require("react-router-dom");
|
|
12
|
-
var react_1 = __importDefault(require("react"));
|
|
13
|
-
var Router = function (_a) {
|
|
14
|
-
var children = _a.children;
|
|
15
|
-
return react_1.default.createElement(react_router_dom_1.unstable_HistoryRouter, { basename: config_1.routerBase, history: getOriHistory(config_1.routerType) }, children);
|
|
16
|
-
};
|
|
17
|
-
exports.Router = Router;
|
|
18
13
|
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
19
14
|
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
20
15
|
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
@@ -108,22 +103,21 @@ var getLocation = function (originalHistory) {
|
|
|
108
103
|
path: path
|
|
109
104
|
};
|
|
110
105
|
};
|
|
111
|
-
var getFormatHistoryOption = function (to,
|
|
106
|
+
var getFormatHistoryOption = function (to, pathList, type) {
|
|
112
107
|
var _a;
|
|
113
|
-
var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query
|
|
108
|
+
var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
|
|
114
109
|
var obj = {
|
|
115
110
|
hash: hash,
|
|
116
|
-
state: state,
|
|
117
111
|
search: query ? qs_1.default.stringify(query) : undefined
|
|
118
112
|
};
|
|
119
113
|
if (path) {
|
|
120
|
-
obj.pathname =
|
|
114
|
+
obj.pathname = path;
|
|
121
115
|
}
|
|
122
116
|
if (name) {
|
|
123
117
|
var fullPath = (_a = pathList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path;
|
|
124
118
|
var targetPath = fullPath ? (0, exports.interpolatePath)(fullPath, params) : null;
|
|
125
119
|
if (targetPath) {
|
|
126
|
-
obj.pathname =
|
|
120
|
+
obj.pathname = targetPath;
|
|
127
121
|
}
|
|
128
122
|
else {
|
|
129
123
|
throw "An error occurred while executing 'history.".concat(type, "' operation: The path for the name \"").concat(name, "\" could not be found");
|
|
@@ -131,21 +125,29 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
|
|
|
131
125
|
}
|
|
132
126
|
return obj;
|
|
133
127
|
};
|
|
134
|
-
var
|
|
128
|
+
var getRouter = function (routerType) {
|
|
135
129
|
var _a;
|
|
136
|
-
var
|
|
130
|
+
var routeList = (0, index_1.getChildrenRouteList)(routes_1.default, '');
|
|
131
|
+
var router = (routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList);
|
|
132
|
+
var oriHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
|
|
137
133
|
exports.history = {
|
|
138
|
-
go:
|
|
139
|
-
|
|
140
|
-
|
|
134
|
+
go: function (delta) {
|
|
135
|
+
router.navigate(delta);
|
|
136
|
+
},
|
|
137
|
+
forward: function () {
|
|
138
|
+
router.navigate(1);
|
|
139
|
+
},
|
|
140
|
+
back: function () {
|
|
141
|
+
router.navigate(-1);
|
|
142
|
+
},
|
|
141
143
|
push: function (to) {
|
|
142
144
|
switch (typeof to) {
|
|
143
145
|
case 'string':
|
|
144
|
-
|
|
146
|
+
router.navigate(to);
|
|
145
147
|
break;
|
|
146
148
|
case 'object':
|
|
147
|
-
var formatOption = getFormatHistoryOption(to,
|
|
148
|
-
|
|
149
|
+
var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'push');
|
|
150
|
+
router.navigate(formatOption, { state: to.state });
|
|
149
151
|
break;
|
|
150
152
|
default:
|
|
151
153
|
throw "An error occurred while executing history.push operation: unexpected type of 'to':".concat(typeof to);
|
|
@@ -154,19 +156,20 @@ var getOriHistory = function (routerType) {
|
|
|
154
156
|
replace: function (to) {
|
|
155
157
|
switch (typeof to) {
|
|
156
158
|
case 'string':
|
|
157
|
-
|
|
159
|
+
router.navigate(to, { replace: true });
|
|
158
160
|
break;
|
|
159
161
|
case 'object':
|
|
160
|
-
var formatOption = getFormatHistoryOption(to,
|
|
161
|
-
|
|
162
|
+
var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'replace');
|
|
163
|
+
router.navigate(formatOption, { state: to.state, replace: true });
|
|
162
164
|
break;
|
|
163
165
|
default:
|
|
164
166
|
throw "An error occurred while executing history.replace operation: unexpected type of 'to':".concat(typeof to);
|
|
165
167
|
}
|
|
166
168
|
},
|
|
167
169
|
get location() {
|
|
168
|
-
return getLocation(
|
|
170
|
+
return getLocation(oriHistory);
|
|
169
171
|
}
|
|
170
172
|
};
|
|
171
|
-
return
|
|
173
|
+
return router;
|
|
172
174
|
};
|
|
175
|
+
exports.getRouter = getRouter;
|
|
@@ -26,31 +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: (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)),
|
|
43
|
+
key: newAncPathKey,
|
|
44
|
+
path: path,
|
|
45
|
+
children: (0, exports.getChildrenRouteList)(children, newAncPathKey)
|
|
46
|
+
};
|
|
43
47
|
});
|
|
44
48
|
};
|
|
49
|
+
exports.getChildrenRouteList = getChildrenRouteList;
|
|
45
50
|
var App = function () {
|
|
51
|
+
var router = (0, history_1.getRouter)(config_1.routerType);
|
|
46
52
|
if (config_1.routerBase && config_1.routerBase !== '/') {
|
|
47
53
|
if (config_1.routerType === 'browser' && window.location.pathname === '/') {
|
|
48
54
|
window.location.replace("".concat(config_1.routerBase));
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
|
-
return
|
|
52
|
-
react_1.default.createElement(react_router_dom_1.Routes, null,
|
|
53
|
-
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 });
|
|
54
58
|
};
|
|
55
59
|
var root = (0, client_1.createRoot)(document.getElementById('root'));
|
|
56
60
|
root.render(react_1.default.createElement(App, null));
|