swico 0.9.0-beta14 → 0.9.0-beta15

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-beta14",
3
+ "version": "0.9.0-beta15",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -1,5 +1,4 @@
1
- import { ConfigRouterType } from '../../../utils/config';
2
- import { SwicoHistoryType } from '../../../typings/global-type';
1
+ import { SwicoLocationType } from '../../../typings/global-type';
3
2
  export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
4
3
  export declare const interpolatePath: (pathTemplate: string, params: Record<string, any>) => string;
5
4
  export declare const formatAncPath: (ancPath: string) => string;
@@ -7,5 +6,11 @@ export declare const pathNameList: {
7
6
  path: string;
8
7
  name: string;
9
8
  }[];
10
- export declare let history: SwicoHistoryType;
11
- export declare const getRouter: (routerType: ConfigRouterType['type']) => import("@remix-run/router").Router;
9
+ export declare const getHistory: (router: any) => {
10
+ go: (delta: any) => void;
11
+ forward: () => void;
12
+ back: () => void;
13
+ push: (to: any) => void;
14
+ replace: (to: any) => void;
15
+ readonly location: SwicoLocationType;
16
+ };
@@ -3,14 +3,10 @@ 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.getRouter = exports.history = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
7
- var index_1 = require("./index");
6
+ exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
8
7
  var qs_1 = __importDefault(require("qs"));
9
8
  var routes_1 = __importDefault(require("./routes"));
10
9
  var config_1 = require("./config");
11
- var layout_1 = __importDefault(require("../../layout"));
12
- var react_router_dom_1 = require("react-router-dom");
13
- var react_1 = __importDefault(require("react"));
14
10
  var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
15
11
  var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
16
12
  var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
@@ -127,16 +123,8 @@ var getFormatHistoryOption = function (to, pathList, type) {
127
123
  }
128
124
  return obj;
129
125
  };
130
- var getRouter = function (routerType) {
131
- var routeList = [
132
- {
133
- element: react_1.default.createElement(layout_1.default, null),
134
- path: '/',
135
- children: (0, index_1.getChildrenRouteList)(routes_1.default, '')
136
- }
137
- ];
138
- var router = (routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList);
139
- exports.history = {
126
+ var getHistory = function (router) {
127
+ return {
140
128
  go: function (delta) {
141
129
  router.navigate(delta);
142
130
  },
@@ -178,6 +166,5 @@ var getRouter = function (routerType) {
178
166
  return getLocation(router.state.location);
179
167
  }
180
168
  };
181
- return router;
182
169
  };
183
- exports.getRouter = getRouter;
170
+ exports.getHistory = getHistory;
@@ -1,5 +1,6 @@
1
1
  import { FC } from 'react';
2
2
  import '../../global';
3
+ import { SwicoHistoryType } from '../../../typings/global-type';
3
4
  export type RoutesItemType = {
4
5
  component?: () => Promise<{
5
6
  default: FC;
@@ -10,3 +11,4 @@ export type RoutesItemType = {
10
11
  name?: string;
11
12
  };
12
13
  export declare const getChildrenRouteList: (childrenRoutes: RoutesItemType[], ancPathKey: string) => any;
14
+ export declare let history: SwicoHistoryType;
@@ -26,7 +26,7 @@ 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
+ exports.history = exports.getChildrenRouteList = void 0;
30
30
  var client_1 = require("react-dom/client");
31
31
  var react_1 = __importStar(require("react"));
32
32
  var react_router_dom_1 = require("react-router-dom");
@@ -34,12 +34,15 @@ 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 layout_1 = __importDefault(require("../../layout"));
38
+ var routes_1 = __importDefault(require("./routes"));
37
39
  var getChildrenRouteList = function (childrenRoutes, ancPathKey) {
38
40
  return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
39
41
  var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
40
42
  var newAncPathKey = "".concat(ancPathKey, "-").concat(path);
41
43
  return {
42
44
  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)),
45
+ key: newAncPathKey,
43
46
  path: path.startsWith('/') ? path.slice(1) : path,
44
47
  children: (0, exports.getChildrenRouteList)(children, newAncPathKey)
45
48
  };
@@ -47,12 +50,22 @@ var getChildrenRouteList = function (childrenRoutes, ancPathKey) {
47
50
  };
48
51
  exports.getChildrenRouteList = getChildrenRouteList;
49
52
  var App = function () {
50
- var router = (0, history_1.getRouter)(config_1.routerType);
53
+ var routeList = [
54
+ {
55
+ element: react_1.default.createElement(layout_1.default, null),
56
+ path: '/',
57
+ children: (0, exports.getChildrenRouteList)(routes_1.default, '')
58
+ }
59
+ ];
60
+ var router = (config_1.routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList);
51
61
  if (config_1.routerBase && config_1.routerBase !== '/') {
52
62
  if (config_1.routerType === 'browser' && window.location.pathname === '/') {
53
63
  window.location.replace("".concat(config_1.routerBase));
54
64
  }
55
65
  }
66
+ (0, react_1.useLayoutEffect)(function () {
67
+ exports.history = (0, history_1.getHistory)(router);
68
+ });
56
69
  return react_1.default.createElement(react_router_dom_1.RouterProvider, { router: router, basename: config_1.routerBase });
57
70
  };
58
71
  var root = (0, client_1.createRoot)(document.getElementById('root'));
@@ -213,7 +213,7 @@ var initCliIndexFile = function (templateType, env) { return __awaiter(void 0, v
213
213
  .replaceAll('\\', '/');
214
214
  replaceFileText = replaceFileText.replaceAll('require("./template/react/react-hooks");', "require(\"".concat(formatHooksPath, "\");"));
215
215
  formatHistoryPath = path_1.default
216
- .resolve(projectPath, "./src/.swico/.".concat(env, "/history"))
216
+ .resolve(projectPath, "./src/.swico/.".concat(env, "/index"))
217
217
  .replaceAll('\\', '/');
218
218
  replaceFileText = replaceFileText.replaceAll('require("./mock-history");', "require(\"".concat(formatHistoryPath, "\");"));
219
219
  return [4, fs_extra_1.default.writeFile(targetPath, replaceFileText)];