swico 0.5.0-beta7 → 0.5.0-beta9

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.5.0-beta7",
3
+ "version": "0.5.0-beta9",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -7,6 +7,7 @@ exports.useLocation = void 0;
7
7
  var react_router_dom_1 = require("react-router-dom");
8
8
  var qs_1 = __importDefault(require("qs"));
9
9
  var history_1 = require("../react/history");
10
+ var routes_1 = require("../react/routes");
10
11
  var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
11
12
  var patternWithValuesParts = urlPatternWithValues.split('/');
12
13
  var patternWithParamsParts = urlPatternWithParams.split('/');
@@ -30,8 +31,7 @@ var useLocation = function () {
30
31
  var location = (0, react_router_dom_1.useLocation)();
31
32
  var params = (0, react_router_dom_1.useParams)();
32
33
  var search = location.search, hash = location.hash, pathname = location.pathname;
33
- var pathNameList = (0, history_1.getPathNameList)();
34
- console.log('pathnameList', pathNameList);
34
+ var pathNameList = (0, history_1.getPathNameList)(routes_1.routes);
35
35
  var name = (_a = pathNameList.find(function (item) { return (params && compareURLPatterns(pathname, item.path)) || item.path === pathname; })) === null || _a === void 0 ? void 0 : _a.name;
36
36
  var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
37
37
  return {
@@ -1,11 +1,12 @@
1
1
  import { ConfigRouterType } from '../../utils/config';
2
+ import { RoutesItemType } from './index';
2
3
  export { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
3
4
  export declare const formatAncPath: (ancPath: string) => string;
4
- export declare const getPathNameList: () => Array<{
5
+ export declare const getPathNameList: (routes: RoutesItemType[]) => Array<{
5
6
  path: string;
6
7
  name: string;
7
8
  }>;
8
- export declare const getHistory: (routerBase: ConfigRouterType['base'], routerType: ConfigRouterType['type']) => {
9
+ export declare const getHistory: (routerBase: ConfigRouterType['base'], routerType: ConfigRouterType['type'], routes: RoutesItemType[]) => {
9
10
  history: SwicoHistoryType;
10
11
  originalHistory: import("history").HashHistory;
11
12
  };
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getHistory = exports.getPathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
7
- var routes_1 = __importDefault(require("./routes"));
8
7
  var qs_1 = __importDefault(require("qs"));
9
8
  var history_1 = require("history");
10
9
  var react_router_dom_1 = require("react-router-dom");
@@ -32,7 +31,7 @@ var formatAncPath = function (ancPath) {
32
31
  return newAncPath;
33
32
  };
34
33
  exports.formatAncPath = formatAncPath;
35
- var getPathNameList = function () {
34
+ var getPathNameList = function (routes) {
36
35
  var list = [];
37
36
  var checkRouteItem = function (item, ancPath) {
38
37
  var path = item.path, name = item.name, children = item.children;
@@ -42,7 +41,8 @@ var getPathNameList = function () {
42
41
  children.some(function (item) { return checkRouteItem(item, newAncPath); });
43
42
  }
44
43
  };
45
- routes_1.default.forEach(function (item) { return checkRouteItem(item, ''); });
44
+ console.log('rrr', routes);
45
+ routes.forEach(function (item) { return checkRouteItem(item, ''); });
46
46
  return list;
47
47
  };
48
48
  exports.getPathNameList = getPathNameList;
@@ -80,11 +80,11 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
80
80
  }
81
81
  return obj;
82
82
  };
83
- var getHistory = function (routerBase, routerType) {
83
+ var getHistory = function (routerBase, routerType, routes) {
84
84
  var _a;
85
85
  var history;
86
86
  var originalHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
87
- var pathNameList = (0, exports.getPathNameList)();
87
+ var pathNameList = (0, exports.getPathNameList)(routes);
88
88
  var lastIndexBase = routerBase[routerBase.length - 1];
89
89
  var formatRouterBase = lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
90
90
  history = {
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  var client_1 = require("react-dom/client");
30
30
  var react_1 = __importStar(require("react"));
31
31
  var react_router_dom_1 = require("react-router-dom");
32
- var routes_1 = __importDefault(require("./routes"));
32
+ var routes_1 = require("./routes");
33
33
  var loading_1 = __importDefault(require("./loading"));
34
34
  var history_1 = require("./history");
35
35
  var config_1 = require("./config");
@@ -43,7 +43,7 @@ var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
43
43
  });
44
44
  };
45
45
  var App = function () {
46
- var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType), history = _a.history, originalHistory = _a.originalHistory;
46
+ var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType, routes_1.routes), history = _a.history, originalHistory = _a.originalHistory;
47
47
  if (config_1.routerBase && config_1.routerBase !== '/') {
48
48
  if (config_1.routerType === 'browser' && window.location.pathname === '/') {
49
49
  window.location.replace("".concat(config_1.routerBase));
@@ -54,7 +54,7 @@ var App = function () {
54
54
  };
55
55
  return (react_1.default.createElement(history_1.HistoryRouter, { basename: config_1.routerBase, history: originalHistory },
56
56
  react_1.default.createElement(react_router_dom_1.Routes, null,
57
- react_1.default.createElement(react_router_dom_1.Route, { element: react_1.default.createElement(layout_1.default, null), path: '' }, renderChildrenRouteList(routes_1.default, '')))));
57
+ react_1.default.createElement(react_router_dom_1.Route, { element: react_1.default.createElement(layout_1.default, null), path: '' }, renderChildrenRouteList(routes_1.routes, '')))));
58
58
  };
59
59
  var root = (0, client_1.createRoot)(document.getElementById('root'));
60
60
  root.render(react_1.default.createElement(App, null));
@@ -1,3 +1,2 @@
1
1
  import { RoutesItemType } from './index';
2
- declare const _default: RoutesItemType[];
3
- export default _default;
2
+ export declare const routes: RoutesItemType[];
@@ -1,3 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = [];
3
+ exports.routes = void 0;
4
+ exports.routes = [];
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  var vue_1 = require("vue");
8
- var routes_1 = __importDefault(require("./routes"));
8
+ var routes_1 = require("./routes");
9
9
  var vue_router_1 = require("vue-router");
10
10
  var Container_1 = __importDefault(require("./Container"));
11
11
  var config_1 = require("./config");
@@ -14,7 +14,7 @@ var global_1 = __importDefault(require("../global"));
14
14
  var qs_1 = __importDefault(require("qs"));
15
15
  var router = (0, vue_router_1.createRouter)({
16
16
  history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
17
- routes: routes_1.default
17
+ routes: routes_1.routes
18
18
  });
19
19
  var app = (0, vue_1.createApp)(Container_1.default);
20
20
  var Swico = { history: null };
@@ -2,5 +2,5 @@ import { RouteRecordRaw } from 'vue-router';
2
2
  type RouteItem = RouteRecordRaw & {
3
3
  decorator?: string;
4
4
  };
5
- declare const _default: RouteItem[];
6
- export default _default;
5
+ export declare const routes: RouteItem[];
6
+ export {};
@@ -1,3 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = [];
3
+ exports.routes = void 0;
4
+ exports.routes = [];
@@ -246,7 +246,7 @@ var formatTemplateFileText = function (_a, templateType) {
246
246
  switch (_a.label) {
247
247
  case 0:
248
248
  formatRouter = getFormatRouter(routes, templateType);
249
- textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = ".concat(JSON.stringify(formatRouter), ";");
249
+ textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.routes = ".concat(JSON.stringify(formatRouter), ";");
250
250
  modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
251
251
  return [4, (0, tools_1.writeFile)(path_1.default.resolve(__dirname, "../template/".concat(templateType, "/routes.js")), modifiedText)];
252
252
  case 1: