swico 0.6.2-beta4 → 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-beta4",
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",
package/src/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { GlobalData, GlobalSwicoConfigType } from './utils/config';
2
2
  export type CustomConfigType = GlobalData['customConfig'];
3
3
  export type { GlobalSwicoConfigType };
4
+ export { history } from './mock-history';
4
5
  declare let Outlet: any, Link: any, useLocation: any;
5
6
  export { Outlet, Link, useLocation };
6
7
  export interface DefineSwicoConfigType {
package/src/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineGlobal = exports.defineConfig = exports.useLocation = exports.Link = exports.Outlet = void 0;
3
+ exports.defineGlobal = exports.defineConfig = exports.useLocation = exports.Link = exports.Outlet = exports.history = void 0;
4
+ var mock_history_1 = require("./mock-history");
5
+ Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
4
6
  var Outlet, Link, useLocation;
5
7
  var defineConfig = function (env, config) { return config; };
6
8
  exports.defineConfig = defineConfig;
@@ -11,7 +11,7 @@ export declare const Link: FC<{
11
11
  }>;
12
12
  export { Outlet } from 'react-router-dom';
13
13
  export { useLocation } from './template/react/react-hooks';
14
- export { history } from './template/react/$env/index';
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;
@@ -15,8 +15,8 @@ var react_router_dom_2 = require("react-router-dom");
15
15
  Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return react_router_dom_2.Outlet; } });
16
16
  var react_hooks_1 = require("./template/react/react-hooks");
17
17
  Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return react_hooks_1.useLocation; } });
18
- var index_1 = require("./template/react/$env/index");
19
- Object.defineProperty(exports, "history", { enumerable: true, get: function () { return index_1.history; } });
18
+ var mock_history_1 = require("./mock-history");
19
+ Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
20
20
  var defineConfig = function (env, config) { return config; };
21
21
  exports.defineConfig = defineConfig;
22
22
  var defineGlobal = function (config) {
@@ -4,7 +4,7 @@ import { Router } from 'vue-router';
4
4
  export type CustomConfigType = GlobalData['customConfig'];
5
5
  export { RouterView as Outlet } from 'vue-router';
6
6
  export { useLocation } from './template/vue/vue-hooks';
7
- export { history } from './template/vue/$env/index';
7
+ export { history } from './mock-history';
8
8
  export type { GlobalSwicoConfigType };
9
9
  export declare const Link: import("vue").DefineComponent<{
10
10
  to: {
package/src/index.vue.js CHANGED
@@ -7,8 +7,8 @@ var vue_router_2 = require("vue-router");
7
7
  Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return vue_router_2.RouterView; } });
8
8
  var vue_hooks_1 = require("./template/vue/vue-hooks");
9
9
  Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return vue_hooks_1.useLocation; } });
10
- var index_1 = require("./template/vue/$env/index");
11
- Object.defineProperty(exports, "history", { enumerable: true, get: function () { return index_1.history; } });
10
+ var mock_history_1 = require("./mock-history");
11
+ Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
12
12
  exports.Link = (0, vue_1.defineComponent)({
13
13
  components: {
14
14
  RouterLink: vue_router_1.RouterLink
@@ -0,0 +1 @@
1
+ export declare const history: SwicoHistoryType;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.history = void 0;
4
+ exports.history = {};
@@ -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 let history: any;
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");
@@ -44,15 +43,14 @@ var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
44
43
  });
45
44
  };
46
45
  var App = function () {
47
- var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType), swicoHistory = _a.history, originalHistory = _a.originalHistory;
48
- exports.history = swicoHistory;
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;
@@ -223,7 +223,7 @@ var getFormatRouter = function (routes, templateType) {
223
223
  });
224
224
  };
225
225
  var initCliIndexFile = function (templateType, env) { return __awaiter(void 0, void 0, void 0, function () {
226
- var targetPath, targetTypesPath, replaceFileText, fileTypesText, formatHooksPath, formatHistoryPath, formatHistoryPath;
226
+ var targetPath, targetTypesPath, replaceFileText, fileTypesText, formatHooksPath, formatHistoryPath;
227
227
  return __generator(this, function (_a) {
228
228
  switch (_a.label) {
229
229
  case 0:
@@ -235,22 +235,14 @@ var initCliIndexFile = function (templateType, env) { return __awaiter(void 0, v
235
235
  return [4, fs_extra_1.default.readFile(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".d.ts")), 'utf8')];
236
236
  case 2:
237
237
  fileTypesText = _a.sent();
238
- if (templateType === 'react') {
239
- formatHooksPath = path_1.default
240
- .resolve(projectPath, './src/.swico/react-hooks')
241
- .replaceAll('\\', '/');
242
- replaceFileText = replaceFileText.replaceAll('require("./template/react/react-hooks");', "require(\"".concat(formatHooksPath, "\");"));
243
- formatHistoryPath = path_1.default
244
- .resolve(projectPath, "./src/.swico/.".concat(env, "/index"))
245
- .replaceAll('\\', '/');
246
- replaceFileText = replaceFileText.replaceAll('require("./template/react/$env/index");', "require(\"".concat(formatHistoryPath, "\");"));
247
- }
248
- else {
249
- formatHistoryPath = path_1.default
250
- .resolve(projectPath, "./src/.swico/.".concat(env, "/index"))
251
- .replaceAll('\\', '/');
252
- replaceFileText = replaceFileText.replaceAll('require("./template/vue/$env/index");', "require(\"".concat(formatHistoryPath, "\");"));
253
- }
238
+ formatHooksPath = path_1.default
239
+ .resolve(projectPath, './src/.swico/react-hooks')
240
+ .replaceAll('\\', '/');
241
+ replaceFileText = replaceFileText.replaceAll('require("./template/react/react-hooks");', "require(\"".concat(formatHooksPath, "\");"));
242
+ formatHistoryPath = path_1.default
243
+ .resolve(projectPath, "./src/.swico/.".concat(env, "/history"))
244
+ .replaceAll('\\', '/');
245
+ replaceFileText = replaceFileText.replaceAll('require("./mock-history");', "require(\"".concat(formatHistoryPath, "\");"));
254
246
  return [4, fs_extra_1.default.writeFile(targetPath, replaceFileText)];
255
247
  case 3:
256
248
  _a.sent();
@@ -210,10 +210,10 @@ 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
- fileText = fileText.replaceAll("require(\"".concat(formatHistoryPath, "\");"), 'require("./template/react/$env/index");');
216
+ fileText = fileText.replaceAll("require(\"".concat(formatHistoryPath, "\");"), 'require("./mock-history");');
217
217
  return [4, fs_extra_1.default.writeFile(targetPath, fileText)];
218
218
  case 4:
219
219
  _a.sent();