swico 0.6.2-beta5 → 0.6.2-beta6

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.6.2-beta5",
3
+ "version": "0.6.2-beta6",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -5,7 +5,5 @@ export declare const pathNameList: {
5
5
  path: string;
6
6
  name: string;
7
7
  }[];
8
- export declare const getHistory: (routerBase: ConfigRouterType['base'], routerType: ConfigRouterType['type']) => {
9
- history: SwicoHistoryType;
10
- originalHistory: import("history").HashHistory;
11
- };
8
+ export declare let history: SwicoHistoryType;
9
+ export declare const getOriHistory: (routerType: ConfigRouterType['type']) => import("history").HashHistory;
@@ -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.getHistory = exports.pathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
6
+ exports.getOriHistory = exports.history = exports.pathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
7
7
  var qs_1 = __importDefault(require("qs"));
8
8
  var history_1 = require("history");
9
9
  var routes_1 = __importDefault(require("./routes"));
@@ -122,11 +122,10 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
122
122
  }
123
123
  return obj;
124
124
  };
125
- var getHistory = function (routerBase, routerType) {
125
+ var getOriHistory = function (routerType) {
126
126
  var _a;
127
- var history;
128
127
  var originalHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
129
- history = {
128
+ exports.history = {
130
129
  go: originalHistory.go,
131
130
  forward: originalHistory.forward,
132
131
  back: originalHistory.back,
@@ -160,6 +159,6 @@ var getHistory = function (routerBase, routerType) {
160
159
  return getLocation(originalHistory);
161
160
  }
162
161
  };
163
- return { history: history, originalHistory: originalHistory };
162
+ return originalHistory;
164
163
  };
165
- exports.getHistory = getHistory;
164
+ exports.getOriHistory = getOriHistory;
@@ -1,6 +1,5 @@
1
1
  import { FC } from 'react';
2
2
  import '../../global';
3
- export declare const history: SwicoHistoryType;
4
3
  export type RoutesItemType = {
5
4
  component?: () => Promise<{
6
5
  default: FC;
@@ -26,7 +26,6 @@ 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.history = void 0;
30
29
  var client_1 = require("react-dom/client");
31
30
  var react_1 = __importStar(require("react"));
32
31
  var react_router_dom_1 = require("react-router-dom");
@@ -36,8 +35,6 @@ var history_1 = require("./history");
36
35
  var config_1 = require("./config");
37
36
  require("../../global");
38
37
  var layout_1 = __importDefault(require("../../layout"));
39
- var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType), swicoHistory = _a.history, originalHistory = _a.originalHistory;
40
- exports.history = swicoHistory;
41
38
  var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
42
39
  return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
43
40
  var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
@@ -46,13 +43,14 @@ var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
46
43
  });
47
44
  };
48
45
  var App = function () {
46
+ var originalHistory = (0, history_1.getOriHistory)(config_1.routerType);
49
47
  if (config_1.routerBase && config_1.routerBase !== '/') {
50
48
  if (config_1.routerType === 'browser' && window.location.pathname === '/') {
51
49
  window.location.replace("".concat(config_1.routerBase));
52
50
  }
53
51
  }
54
52
  window.Swico = {
55
- history: exports.history
53
+ history: history_1.history
56
54
  };
57
55
  return (react_1.default.createElement(history_1.HistoryRouter, { basename: config_1.routerBase, history: originalHistory },
58
56
  react_1.default.createElement(react_router_dom_1.Routes, null,
@@ -0,0 +1,2 @@
1
+ export declare let history: SwicoHistoryType;
2
+ export declare const getRouter: () => import("vue-router").Router;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getRouter = exports.history = void 0;
7
+ var vue_router_1 = require("vue-router");
8
+ var config_1 = require("./config");
9
+ var routes_1 = __importDefault(require("./routes"));
10
+ var qs_1 = __importDefault(require("qs"));
11
+ var getRouter = function () {
12
+ var router = (0, vue_router_1.createRouter)({
13
+ history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
14
+ routes: routes_1.default
15
+ });
16
+ exports.history = {
17
+ push: function (options) {
18
+ if (typeof options === 'string') {
19
+ router.push(options);
20
+ }
21
+ else {
22
+ var query = options.query, name_1 = options.name, hash = options.hash, params = options.params, path = options.path;
23
+ router.push({ name: name_1, path: path, query: query, hash: hash, params: params });
24
+ }
25
+ },
26
+ replace: function (options) {
27
+ if (typeof options === 'string') {
28
+ router.replace(options);
29
+ }
30
+ else {
31
+ var query = options.query, name_2 = options.name, hash = options.hash, params = options.params, path = options.path;
32
+ router.replace({ name: name_2, path: path, query: query, hash: hash, params: params });
33
+ }
34
+ },
35
+ go: router.go,
36
+ back: router.back,
37
+ forward: router.forward,
38
+ get location() {
39
+ var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
40
+ var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
41
+ var _a = router.currentRoute.value, path = _a.path, params = _a.params, query = _a.query, name = _a.name, hash = _a.hash, fullPath = _a.fullPath;
42
+ return {
43
+ path: path,
44
+ pathname: formatRouterBase + path,
45
+ params: params,
46
+ query: query,
47
+ name: name,
48
+ hash: hash,
49
+ search: query ? qs_1.default.stringify(query) : ''
50
+ };
51
+ }
52
+ };
53
+ return router;
54
+ };
55
+ exports.getRouter = getRouter;
@@ -1 +1 @@
1
- export declare const history: SwicoHistoryType;
1
+ export {};
@@ -4,59 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.history = void 0;
8
7
  var vue_1 = require("vue");
9
- var routes_1 = __importDefault(require("./routes"));
10
- var vue_router_1 = require("vue-router");
11
8
  var Container_1 = __importDefault(require("../Container"));
12
- var config_1 = require("./config");
13
9
  var Layout_1 = __importDefault(require("../../layout/Layout"));
14
10
  var global_1 = __importDefault(require("../../global"));
15
- var qs_1 = __importDefault(require("qs"));
16
- var router = (0, vue_router_1.createRouter)({
17
- history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
18
- routes: routes_1.default
19
- });
11
+ var history_1 = require("./history");
12
+ var router = (0, history_1.getRouter)();
20
13
  var app = (0, vue_1.createApp)(Container_1.default);
21
14
  var Swico = { history: null };
22
- exports.history = {
23
- push: function (options) {
24
- if (typeof options === 'string') {
25
- router.push(options);
26
- }
27
- else {
28
- var query = options.query, name_1 = options.name, hash = options.hash, params = options.params, path = options.path;
29
- router.push({ name: name_1, path: path, query: query, hash: hash, params: params });
30
- }
31
- },
32
- replace: function (options) {
33
- if (typeof options === 'string') {
34
- router.replace(options);
35
- }
36
- else {
37
- var query = options.query, name_2 = options.name, hash = options.hash, params = options.params, path = options.path;
38
- router.replace({ name: name_2, path: path, query: query, hash: hash, params: params });
39
- }
40
- },
41
- go: router.go,
42
- back: router.back,
43
- forward: router.forward,
44
- get location() {
45
- var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
46
- var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
47
- var _a = router.currentRoute.value, path = _a.path, params = _a.params, query = _a.query, name = _a.name, hash = _a.hash, fullPath = _a.fullPath;
48
- return {
49
- path: path,
50
- pathname: formatRouterBase + path,
51
- params: params,
52
- query: query,
53
- name: name,
54
- hash: hash,
55
- search: query ? qs_1.default.stringify(query) : ''
56
- };
57
- }
58
- };
59
- Swico.history = exports.history;
15
+ Swico.history = history_1.history;
60
16
  app.component('Layout', Layout_1.default);
61
17
  app.use(router);
62
18
  window.Swico = Swico;
@@ -240,7 +240,7 @@ var initCliIndexFile = function (templateType, env) { return __awaiter(void 0, v
240
240
  .replaceAll('\\', '/');
241
241
  replaceFileText = replaceFileText.replaceAll('require("./template/react/react-hooks");', "require(\"".concat(formatHooksPath, "\");"));
242
242
  formatHistoryPath = path_1.default
243
- .resolve(projectPath, "./src/.swico/.".concat(env, "/index"))
243
+ .resolve(projectPath, "./src/.swico/.".concat(env, "/history"))
244
244
  .replaceAll('\\', '/');
245
245
  replaceFileText = replaceFileText.replaceAll('require("./mock-history");', "require(\"".concat(formatHistoryPath, "\");"));
246
246
  return [4, fs_extra_1.default.writeFile(targetPath, replaceFileText)];
@@ -210,7 +210,7 @@ var initIndexFile = function (env) { return __awaiter(void 0, void 0, void 0, fu
210
210
  _a.label = 3;
211
211
  case 3:
212
212
  formatHistoryPath = path_1.default
213
- .resolve(process.cwd(), "./src/.swico/.".concat(env, "/index"))
213
+ .resolve(process.cwd(), "./src/.swico/.".concat(env, "/history"))
214
214
  .replaceAll('\\', '/');
215
215
  if (!fileText.includes("require(\"".concat(formatHistoryPath, "\");"))) return [3, 5];
216
216
  fileText = fileText.replaceAll("require(\"".concat(formatHistoryPath, "\");"), 'require("./mock-history");');