swico 0.9.0-beta8 → 0.9.0

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-beta8",
3
+ "version": "0.9.0",
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,5 +1,4 @@
1
- import { ConfigRouterType } from '../../../utils/config';
2
- import { SwicoHistoryType } from '../../../typings/global-type';
1
+ import { SwicoHistoryType, 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,12 @@ export declare const pathNameList: {
7
6
  path: string;
8
7
  name: string;
9
8
  }[];
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
+ };
10
17
  export declare let history: SwicoHistoryType;
11
- export declare const getRouter: (routerType: ConfigRouterType['type']) => import("@remix-run/router").Router;
@@ -3,13 +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.history = exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
8
7
  var qs_1 = __importDefault(require("qs"));
9
- var history_1 = require("history");
10
8
  var routes_1 = __importDefault(require("./routes"));
11
9
  var config_1 = require("./config");
12
- var react_router_dom_1 = require("react-router-dom");
13
10
  var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
14
11
  var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
15
12
  var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
@@ -86,8 +83,9 @@ var getPathNameList = function (routes) {
86
83
  return list;
87
84
  };
88
85
  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, state = _a.state;
86
+ var getLocation = function (historyLocation) {
87
+ console.log('historyLocation', historyLocation);
88
+ var pathname = historyLocation.pathname, hash = historyLocation.hash, search = historyLocation.search, state = historyLocation.state;
91
89
  var routerBaseLength = formatRouterBase.length;
92
90
  var path = pathname.slice(routerBaseLength);
93
91
  var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
@@ -125,12 +123,8 @@ var getFormatHistoryOption = function (to, pathList, type) {
125
123
  }
126
124
  return obj;
127
125
  };
128
- var getRouter = function (routerType) {
129
- var _a;
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();
133
- exports.history = {
126
+ var getHistory = function (router) {
127
+ return {
134
128
  go: function (delta) {
135
129
  router.navigate(delta);
136
130
  },
@@ -167,9 +161,8 @@ var getRouter = function (routerType) {
167
161
  }
168
162
  },
169
163
  get location() {
170
- return getLocation(oriHistory);
164
+ return getLocation(router.state.location);
171
165
  }
172
166
  };
173
- return router;
174
167
  };
175
- exports.getRouter = getRouter;
168
+ exports.getHistory = getHistory;
@@ -32,29 +32,43 @@ var react_1 = __importStar(require("react"));
32
32
  var react_router_dom_1 = require("react-router-dom");
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");
36
+ var layout_1 = __importDefault(require("../../layout"));
37
+ var routes_1 = __importDefault(require("./routes"));
38
+ var config_1 = require("./config");
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
- 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)),
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)),
43
45
  key: newAncPathKey,
44
- path: path,
46
+ path: path.startsWith('/') ? path.slice(1) : path,
45
47
  children: (0, exports.getChildrenRouteList)(children, newAncPathKey)
46
48
  };
47
49
  });
48
50
  };
49
51
  exports.getChildrenRouteList = getChildrenRouteList;
50
52
  var App = function () {
51
- 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, {
61
+ basename: config_1.routerBase
62
+ });
52
63
  if (config_1.routerBase && config_1.routerBase !== '/') {
53
64
  if (config_1.routerType === 'browser' && window.location.pathname === '/') {
54
65
  window.location.replace("".concat(config_1.routerBase));
55
66
  }
56
67
  }
57
- return react_1.default.createElement(react_router_dom_1.RouterProvider, { router: router, basename: config_1.routerBase });
68
+ (0, react_1.useLayoutEffect)(function () {
69
+ history_1.history = (0, history_1.getHistory)(router);
70
+ });
71
+ return react_1.default.createElement(react_router_dom_1.RouterProvider, { router: router });
58
72
  };
59
73
  var root = (0, client_1.createRoot)(document.getElementById('root'));
60
74
  root.render(react_1.default.createElement(App, null));