swico 1.6.0-beta.3 → 1.6.0-beta.5

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.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/src/index.react.d.ts +1 -1
  3. package/src/index.react.js +1 -1
  4. package/src/index.vue.d.ts +1 -1
  5. package/src/index.vue.js +1 -1
  6. package/src/project-path/.swico-react/$env/config.d.ts +3 -0
  7. package/src/project-path/.swico-react/$env/config.js +5 -0
  8. package/src/project-path/.swico-react/$env/history.d.ts +18 -0
  9. package/src/project-path/.swico-react/$env/history.js +168 -0
  10. package/src/project-path/.swico-react/$env/index.d.ts +13 -0
  11. package/src/project-path/.swico-react/$env/index.js +109 -0
  12. package/src/project-path/.swico-react/$env/routes.d.ts +3 -0
  13. package/src/project-path/.swico-react/$env/routes.js +3 -0
  14. package/src/project-path/.swico-react/loading.d.ts +2 -0
  15. package/src/project-path/.swico-react/loading.js +3 -0
  16. package/src/project-path/.swico-react/react-hooks.d.ts +3 -0
  17. package/src/project-path/.swico-react/react-hooks.js +73 -0
  18. package/src/project-path/.swico-vue/$env/config.d.ts +3 -0
  19. package/src/project-path/.swico-vue/$env/config.js +5 -0
  20. package/src/project-path/.swico-vue/Container.vue +15 -0
  21. package/src/project-path/.swico-vue/vue-hooks.d.ts +4 -0
  22. package/src/project-path/.swico-vue/vue-hooks.js +85 -0
  23. package/src/project-path/src/global.d.ts +3 -0
  24. package/src/project-path/src/global.js +3 -0
  25. package/src/project-path/src/layout/Layout.d.ts +2 -0
  26. package/src/project-path/src/layout/Layout.js +6 -0
  27. package/src/project-path/src/layout/index.d.ts +3 -0
  28. package/src/project-path/src/layout/index.js +8 -0
  29. package/src/task.js +2 -2
  30. package/src/utils/config.js +10 -16
  31. package/src/utils/tools.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swico",
3
- "version": "1.6.0-beta.3",
3
+ "version": "1.6.0-beta.5",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -10,7 +10,7 @@ export declare const Link: FC<{
10
10
  children: ReactNode;
11
11
  }>;
12
12
  export { Outlet } from 'react-router-dom';
13
- export { useLocation, useNav } from './template/react/react-hooks';
13
+ export { useLocation, useNav } from './project-path/.swico-react/react-hooks';
14
14
  export { history } from './mock-history';
15
15
  export interface DefineSwicoConfigType {
16
16
  (env: 'base', config: CustomConfigType['base']): any;
@@ -13,7 +13,7 @@ var Link = function (_a) {
13
13
  exports.Link = Link;
14
14
  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
- var react_hooks_1 = require("./template/react/react-hooks");
16
+ var react_hooks_1 = require("./project-path/.swico-react/react-hooks");
17
17
  Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return react_hooks_1.useLocation; } });
18
18
  Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return react_hooks_1.useNav; } });
19
19
  var mock_history_1 = require("./mock-history");
@@ -3,7 +3,7 @@ import { App } from 'vue';
3
3
  import { Router } from 'vue-router';
4
4
  export type CustomConfigType = GlobalData['customConfig'];
5
5
  export { RouterView as Outlet } from 'vue-router';
6
- export { useLocation, useNav } from './template/vue/vue-hooks';
6
+ export { useLocation, useNav } from './project-path/.swico-vue/vue-hooks';
7
7
  export { history } from './mock-history';
8
8
  export type { GlobalSwicoConfigType };
9
9
  export declare const Link: import("vue").DefineComponent<{
package/src/index.vue.js CHANGED
@@ -5,7 +5,7 @@ var vue_1 = require("vue");
5
5
  var vue_router_1 = require("vue-router");
6
6
  var vue_router_2 = require("vue-router");
7
7
  Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return vue_router_2.RouterView; } });
8
- var vue_hooks_1 = require("./template/vue/vue-hooks");
8
+ var vue_hooks_1 = require("./project-path/.swico-vue/vue-hooks");
9
9
  Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return vue_hooks_1.useLocation; } });
10
10
  Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return vue_hooks_1.useNav; } });
11
11
  var mock_history_1 = require("./mock-history");
@@ -0,0 +1,3 @@
1
+ import { ConfigRouterType } from '../../../utils/config';
2
+ export declare const routerType: ConfigRouterType['type'];
3
+ export declare const routerBase: ConfigRouterType['base'];
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.routerBase = exports.routerType = void 0;
4
+ exports.routerType = 'browser';
5
+ exports.routerBase = '/';
@@ -0,0 +1,18 @@
1
+ import { SwicoHistoryType, SwicoLocationType } from '../../../typings/global-type';
2
+ export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
3
+ export declare const interpolatePath: (pathTemplate: string, params: Record<string, any>) => string;
4
+ export declare const formatAncPath: (ancPath: string) => string;
5
+ export declare const pathNameList: {
6
+ path: string;
7
+ name: string;
8
+ custom?: any;
9
+ }[];
10
+ export declare const getHistory: (router: any) => {
11
+ go: (delta: any) => void;
12
+ forward: () => void;
13
+ back: () => void;
14
+ push: (to: any) => void;
15
+ replace: (to: any) => void;
16
+ readonly location: SwicoLocationType;
17
+ };
18
+ export declare let history: SwicoHistoryType;
@@ -0,0 +1,168 @@
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.history = exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
7
+ var qs_1 = __importDefault(require("qs"));
8
+ var routes_1 = __importDefault(require("./routes"));
9
+ var config_1 = require("./config");
10
+ var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
11
+ var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
12
+ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
13
+ var patternWithValuesParts = urlPatternWithValues.split('/');
14
+ var patternWithParamsParts = urlPatternWithParams.split('/');
15
+ if (patternWithValuesParts.length !== patternWithParamsParts.length) {
16
+ return false;
17
+ }
18
+ for (var i = 0; i < patternWithValuesParts.length; i++) {
19
+ var valuePart = patternWithValuesParts[i];
20
+ var paramPart = patternWithParamsParts[i];
21
+ if (paramPart.startsWith(':') && paramPart !== '') {
22
+ continue;
23
+ }
24
+ if (valuePart !== paramPart) {
25
+ return false;
26
+ }
27
+ }
28
+ return true;
29
+ };
30
+ exports.compareURLPatterns = compareURLPatterns;
31
+ var interpolatePath = function (pathTemplate, params) {
32
+ var pathParts = pathTemplate.split('/');
33
+ var interpolatedParts = pathParts.map(function (part) {
34
+ var paramMatch = part.match(/^\:(.+)$/);
35
+ if (paramMatch) {
36
+ var paramName = paramMatch[1];
37
+ if (params[paramName]) {
38
+ return params[paramName];
39
+ }
40
+ else {
41
+ throw "Missing required params '".concat(paramName, "'");
42
+ }
43
+ }
44
+ return part;
45
+ });
46
+ return interpolatedParts.join('/');
47
+ };
48
+ exports.interpolatePath = interpolatePath;
49
+ var interpolatePathParams = function (pathTemplate, path) {
50
+ var _a;
51
+ if (pathTemplate === void 0) { pathTemplate = ''; }
52
+ var regexPattern = pathTemplate.replace(/:(\w+)/g, '([^/]+)');
53
+ var regex = new RegExp("^".concat(regexPattern, "$"));
54
+ var match = path.match(regex);
55
+ if (match) {
56
+ var params_1 = match.slice(1);
57
+ var paramNames = ((_a = pathTemplate.match(/:(\w+)/g)) === null || _a === void 0 ? void 0 : _a.map(function (name) { return name.slice(1); })) || [];
58
+ var result_1 = {};
59
+ paramNames.forEach(function (name, index) {
60
+ result_1[name] = params_1[index];
61
+ });
62
+ return result_1;
63
+ }
64
+ return {};
65
+ };
66
+ var formatAncPath = function (ancPath) {
67
+ var newAncPath = ancPath.startsWith('/') ? ancPath : '/' + ancPath;
68
+ newAncPath = newAncPath.endsWith('/') ? newAncPath.slice(0, -1) : newAncPath;
69
+ return newAncPath;
70
+ };
71
+ exports.formatAncPath = formatAncPath;
72
+ var getPathNameList = function (routes) {
73
+ var list = [];
74
+ var checkRouteItem = function (item, ancPath) {
75
+ var path = item.path, name = item.name, children = item.children, custom = item.custom;
76
+ var newAncPath = "".concat((0, exports.formatAncPath)(ancPath)).concat(path.startsWith('/') ? path : '/' + path);
77
+ list.push({ path: newAncPath, name: name, custom: custom });
78
+ if (children) {
79
+ children.some(function (item) { return checkRouteItem(item, newAncPath); });
80
+ }
81
+ };
82
+ routes.forEach(function (item) { return checkRouteItem(item, ''); });
83
+ return list;
84
+ };
85
+ exports.pathNameList = getPathNameList(routes_1.default);
86
+ var getLocation = function (historyLocation) {
87
+ var pathname = historyLocation.pathname, hash = historyLocation.hash, search = historyLocation.search, state = historyLocation.state;
88
+ var routerBaseLength = formatRouterBase.length;
89
+ var path = pathname.slice(routerBaseLength);
90
+ var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
91
+ var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
92
+ return {
93
+ state: state !== null && state !== void 0 ? state : {},
94
+ hash: hash,
95
+ search: search,
96
+ pathname: pathname,
97
+ query: search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {},
98
+ name: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.name,
99
+ params: params,
100
+ path: path,
101
+ custom: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.custom
102
+ };
103
+ };
104
+ var getFormatHistoryOption = function (to, pathList, type) {
105
+ var _a;
106
+ var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
107
+ var obj = {
108
+ hash: hash,
109
+ search: query ? qs_1.default.stringify(query) : undefined
110
+ };
111
+ if (path) {
112
+ obj.pathname = path;
113
+ }
114
+ if (name) {
115
+ var fullPath = (_a = pathList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path;
116
+ var targetPath = fullPath ? (0, exports.interpolatePath)(fullPath, params) : null;
117
+ if (targetPath) {
118
+ obj.pathname = targetPath;
119
+ }
120
+ else {
121
+ throw "An error occurred while executing 'history.".concat(type, "' operation: The path for the name \"").concat(name, "\" could not be found");
122
+ }
123
+ }
124
+ return obj;
125
+ };
126
+ var getHistory = function (router) {
127
+ return {
128
+ go: function (delta) {
129
+ router.navigate(delta);
130
+ },
131
+ forward: function () {
132
+ router.navigate(1);
133
+ },
134
+ back: function () {
135
+ router.navigate(-1);
136
+ },
137
+ push: function (to) {
138
+ switch (typeof to) {
139
+ case 'string':
140
+ router.navigate(to);
141
+ break;
142
+ case 'object':
143
+ var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'push');
144
+ router.navigate(formatOption, { state: to.state });
145
+ break;
146
+ default:
147
+ throw "An error occurred while executing history.push operation: unexpected type of 'to':".concat(typeof to);
148
+ }
149
+ },
150
+ replace: function (to) {
151
+ switch (typeof to) {
152
+ case 'string':
153
+ router.navigate(to, { replace: true });
154
+ break;
155
+ case 'object':
156
+ var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'replace');
157
+ router.navigate(formatOption, { state: to.state, replace: true });
158
+ break;
159
+ default:
160
+ throw "An error occurred while executing history.replace operation: unexpected type of 'to':".concat(typeof to);
161
+ }
162
+ },
163
+ get location() {
164
+ return getLocation(router.state.location);
165
+ }
166
+ };
167
+ };
168
+ exports.getHistory = getHistory;
@@ -0,0 +1,13 @@
1
+ import { FC } from 'react';
2
+ import '../../global';
3
+ export type RoutesItemType = {
4
+ component?: () => Promise<{
5
+ default: FC;
6
+ }>;
7
+ children?: RoutesItemType[];
8
+ path: string;
9
+ redirect?: string;
10
+ name?: string;
11
+ custom?: any;
12
+ };
13
+ export declare const getChildrenRouteList: (childrenRoutes: RoutesItemType[], ancPathKey: string) => any;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ var __importDefault = (this && this.__importDefault) || function (mod) {
41
+ return (mod && mod.__esModule) ? mod : { "default": mod };
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.getChildrenRouteList = void 0;
45
+ var client_1 = require("react-dom/client");
46
+ var react_1 = __importStar(require("react"));
47
+ var react_router_dom_1 = require("react-router-dom");
48
+ var loading_1 = __importDefault(require("../loading"));
49
+ var history_1 = require("./history");
50
+ require("../../global");
51
+ var layout_1 = __importDefault(require("../../src/layout"));
52
+ var routes_1 = __importDefault(require("./routes"));
53
+ var config_1 = require("./config");
54
+ var Container = (function (_super) {
55
+ __extends(Container, _super);
56
+ function Container() {
57
+ var _this = _super !== null && _super.apply(this, arguments) || this;
58
+ _this.state = {
59
+ error: null
60
+ };
61
+ return _this;
62
+ }
63
+ Container.getDerivedStateFromError = function (error) {
64
+ return { error: error.toString() };
65
+ };
66
+ Container.prototype.componentDidCatch = function (error, errorInfo) {
67
+ };
68
+ Container.prototype.render = function () {
69
+ return this.state.error ? null : this.props.children;
70
+ };
71
+ return Container;
72
+ }(react_1.default.Component));
73
+ var getChildrenRouteList = function (childrenRoutes, ancPathKey) {
74
+ return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
75
+ var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
76
+ var newAncPathKey = "".concat(ancPathKey, "-").concat(path);
77
+ return {
78
+ 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)),
79
+ key: newAncPathKey,
80
+ path: path.startsWith('/') ? path.slice(1) : path,
81
+ children: (0, exports.getChildrenRouteList)(children, newAncPathKey)
82
+ };
83
+ });
84
+ };
85
+ exports.getChildrenRouteList = getChildrenRouteList;
86
+ var App = function () {
87
+ var routeList = [
88
+ {
89
+ element: (react_1.default.createElement(Container, null,
90
+ react_1.default.createElement(layout_1.default, null))),
91
+ path: '/',
92
+ children: (0, exports.getChildrenRouteList)(routes_1.default, '')
93
+ }
94
+ ];
95
+ var router = (config_1.routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList, {
96
+ basename: config_1.routerBase
97
+ });
98
+ if (config_1.routerBase && config_1.routerBase !== '/') {
99
+ if (config_1.routerType === 'browser' && window.location.pathname === '/') {
100
+ window.location.replace("".concat(config_1.routerBase));
101
+ }
102
+ }
103
+ (0, react_1.useLayoutEffect)(function () {
104
+ history_1.history = (0, history_1.getHistory)(router);
105
+ });
106
+ return react_1.default.createElement(react_router_dom_1.RouterProvider, { router: router });
107
+ };
108
+ var root = (0, client_1.createRoot)(document.getElementById('root'));
109
+ root.render(react_1.default.createElement(App, null));
@@ -0,0 +1,3 @@
1
+ import { RoutesItemType } from './index';
2
+ declare const _default: RoutesItemType[];
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = [];
@@ -0,0 +1,2 @@
1
+ declare const _default: () => any;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (function () { return null; });
@@ -0,0 +1,3 @@
1
+ import { UseLocationType, UseNavType } from '../../typings/global-type';
2
+ export declare const useLocation: UseLocationType;
3
+ export declare const useNav: UseNavType;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.useNav = exports.useLocation = void 0;
18
+ var react_router_dom_1 = require("react-router-dom");
19
+ var history_1 = require("./$env/history");
20
+ var qs_1 = __importDefault(require("qs"));
21
+ var useLocation = function () {
22
+ var _a;
23
+ var location = (0, react_router_dom_1.useLocation)();
24
+ var params = (0, react_router_dom_1.useParams)();
25
+ var search = location.search, hash = location.hash, pathname = location.pathname, state = location.state;
26
+ var matchItem = history_1.pathNameList.find(function (item) {
27
+ return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
28
+ item.path === pathname;
29
+ });
30
+ var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
31
+ return {
32
+ name: matchItem === null || matchItem === void 0 ? void 0 : matchItem.name,
33
+ custom: matchItem === null || matchItem === void 0 ? void 0 : matchItem.custom,
34
+ state: state !== null && state !== void 0 ? state : {},
35
+ path: pathname,
36
+ pathname: (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.pathname,
37
+ search: '',
38
+ query: query,
39
+ hash: hash,
40
+ params: params
41
+ };
42
+ };
43
+ exports.useLocation = useLocation;
44
+ var getFormatNavPath = function (to) {
45
+ var _a;
46
+ var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
47
+ var search = query ? "?".concat(qs_1.default.stringify(query)) : '';
48
+ var formatHash = hash ? (hash.startsWith('#') ? hash : "#".concat(hash)) : '';
49
+ var formatPath = name ? (_a = history_1.pathNameList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path : path;
50
+ var newPath = formatPath ? (0, history_1.interpolatePath)(formatPath, params || {}) : null;
51
+ newPath = newPath + search + formatHash;
52
+ return newPath;
53
+ };
54
+ var useNav = function () {
55
+ var navigate = (0, react_router_dom_1.useNavigate)();
56
+ var newNavigate = function (to, options) {
57
+ switch (typeof to) {
58
+ case 'string':
59
+ navigate(to, options);
60
+ break;
61
+ case 'number':
62
+ navigate(to);
63
+ break;
64
+ case 'object':
65
+ navigate(getFormatNavPath(to), __assign(__assign({}, (options || {})), { state: to.state }));
66
+ break;
67
+ default:
68
+ throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
69
+ }
70
+ };
71
+ return newNavigate;
72
+ };
73
+ exports.useNav = useNav;
@@ -0,0 +1,3 @@
1
+ import { ConfigRouterType } from '../../../utils/config';
2
+ export declare const routerType: ConfigRouterType['type'];
3
+ export declare const routerBase: ConfigRouterType['base'];
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.routerBase = exports.routerType = void 0;
4
+ exports.routerType = 'browser';
5
+ exports.routerBase = '/';
@@ -0,0 +1,15 @@
1
+ <script setup lang="ts">
2
+ import { onErrorCaptured, ref } from 'vue';
3
+ const error = ref<string | null>(null);
4
+ onErrorCaptured((err, instance, info) => {
5
+ console.error(err);
6
+ error.value = err.toString();
7
+ return false;
8
+ });
9
+ </script>
10
+
11
+ <template>
12
+ <Layout v-if="!error"><RouterView /></Layout>
13
+ </template>
14
+
15
+ <style scoped></style>
@@ -0,0 +1,4 @@
1
+ import { UseLocationType, UseNavType } from '../../typings/global-type';
2
+ export declare const getFormatRouterBase: (routerBase: any) => any;
3
+ export declare const useLocation: UseLocationType;
4
+ export declare const useNav: UseNavType;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.useNav = exports.useLocation = exports.getFormatRouterBase = void 0;
18
+ var vue_router_1 = require("vue-router");
19
+ var qs_1 = __importDefault(require("qs"));
20
+ var vue_1 = require("vue");
21
+ var config_1 = require("./$env/config");
22
+ var getFormatRouterBase = function (routerBase) {
23
+ var lastIndexBase = routerBase[routerBase.length - 1];
24
+ return lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
25
+ };
26
+ exports.getFormatRouterBase = getFormatRouterBase;
27
+ var useLocation = function () {
28
+ var route = (0, vue_router_1.useRoute)();
29
+ var location = (0, vue_1.reactive)({
30
+ name: '',
31
+ path: '',
32
+ search: '',
33
+ state: {},
34
+ hash: '',
35
+ pathname: '',
36
+ params: {},
37
+ query: {}
38
+ });
39
+ (0, vue_1.watchEffect)(function () {
40
+ var _a;
41
+ var hash = route.hash, path = route.path, params = route.params, fullPath = route.fullPath, query = route.query, name = route.name, meta = route.meta;
42
+ var search = query ? qs_1.default.stringify(query) : '';
43
+ location.name = name;
44
+ location.path = path;
45
+ location.pathname = (0, exports.getFormatRouterBase)(config_1.routerBase) + path;
46
+ location.search = search;
47
+ location.query = query;
48
+ location.hash = hash;
49
+ location.params = params;
50
+ location.state = ((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.swicoState) || {};
51
+ location.custom = meta;
52
+ });
53
+ return location;
54
+ };
55
+ exports.useLocation = useLocation;
56
+ var useNav = function () {
57
+ var router = (0, vue_router_1.useRouter)();
58
+ var newNavigate = function (to, options) {
59
+ switch (typeof to) {
60
+ case 'string':
61
+ if (options === null || options === void 0 ? void 0 : options.replace) {
62
+ router.replace(to);
63
+ }
64
+ else {
65
+ router.push(to);
66
+ }
67
+ break;
68
+ case 'number':
69
+ router.go(to);
70
+ break;
71
+ case 'object':
72
+ if (options === null || options === void 0 ? void 0 : options.replace) {
73
+ router.replace(to);
74
+ }
75
+ else {
76
+ router.push(__assign(__assign({}, to), { state: { swicoState: to.state } }));
77
+ }
78
+ break;
79
+ default:
80
+ throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
81
+ }
82
+ };
83
+ return newNavigate;
84
+ };
85
+ exports.useNav = useNav;
@@ -0,0 +1,3 @@
1
+ import { DefineGlobalConfigType } from '../../index.vue';
2
+ declare const _default: DefineGlobalConfigType;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {};
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var vue_1 = require("vue");
4
+ exports.default = (0, vue_1.defineComponent)({
5
+ template: '<template><slot></slot></template>'
6
+ });
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const _default: () => React.JSX.Element;
3
+ export default _default;
@@ -0,0 +1,8 @@
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
+ var react_router_dom_1 = require("react-router-dom");
7
+ var react_1 = __importDefault(require("react"));
8
+ exports.default = (function () { return react_1.default.createElement(react_router_dom_1.Outlet, null); });
package/src/task.js CHANGED
@@ -46,8 +46,8 @@ var copyVueFiles = function () { return __awaiter(void 0, void 0, void 0, functi
46
46
  return __generator(this, function (_a) {
47
47
  switch (_a.label) {
48
48
  case 0:
49
- filePath = path_1.default.resolve(__dirname, './template/vue/Container.vue');
50
- targetPath = path_1.default.resolve(__dirname, '../dist/src/template/vue/Container.vue');
49
+ filePath = path_1.default.resolve(__dirname, './project-path/.swico-vue/Container.vue');
50
+ targetPath = path_1.default.resolve(__dirname, '../dist/src/project-path/.swico-vue/Container.vue');
51
51
  return [4, fs_extra_1.default.copyFile(filePath, targetPath)];
52
52
  case 1:
53
53
  _a.sent();
@@ -204,10 +204,12 @@ var initCliIndexFile = function (templateType, env) { return __awaiter(void 0, v
204
204
  return [4, fs_extra_1.default.readFile(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".d.ts")), 'utf8')];
205
205
  case 2:
206
206
  fileTypesText = _a.sent();
207
- formatHooksPath = path_1.default
208
- .resolve(projectPath, './.swico/react-hooks')
209
- .replaceAll('\\', '/');
210
- replaceFileText = replaceFileText.replaceAll('require("./template/react/react-hooks");', "require(\"".concat(formatHooksPath, "\");"));
207
+ if (templateType === 'react') {
208
+ formatHooksPath = path_1.default
209
+ .resolve(projectPath, './.swico/react-hooks')
210
+ .replaceAll('\\', '/');
211
+ replaceFileText = replaceFileText.replaceAll('require("./project-path/.swico-react/react-hooks");', "require(\"".concat(formatHooksPath, "\");"));
212
+ }
211
213
  formatHistoryPath = path_1.default
212
214
  .resolve(projectPath, "./.swico/.".concat(env, "/history"))
213
215
  .replaceAll('\\', '/');
@@ -297,7 +299,6 @@ var handleLoadingFile = function (replaceIndexText, envPath) { return __awaiter(
297
299
  return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
298
300
  case 2:
299
301
  _a.sent();
300
- newReplaceIndexText = newReplaceIndexText.replace('"../loading"', '"../../src/loading"');
301
302
  return [3, 4];
302
303
  case 3:
303
304
  e_1 = _a.sent();
@@ -312,11 +313,11 @@ var handleGlobalStyleFile = function (replaceIndexText) {
312
313
  var _a = getGlobalStyleFilePath(), styleFilePath = _a.filePath, styleFileType = _a.fileType;
313
314
  var newReplaceIndexText = replaceIndexText;
314
315
  if (styleFilePath) {
315
- newReplaceIndexText = newReplaceIndexText.replaceAll("require(\"../../global.".concat(styleFileType, "\");"), '');
316
+ newReplaceIndexText = newReplaceIndexText.replaceAll("require(\"../../src/global.".concat(styleFileType, "\");"), '');
316
317
  newReplaceIndexText = "require(\"../../src/global.".concat(styleFileType, "\");\n").concat(replaceIndexText);
317
318
  }
318
319
  else {
319
- newReplaceIndexText = newReplaceIndexText.replaceAll(/require\("\.\.\/\.\.\/global.(less|scss|css)"\);/g, '');
320
+ newReplaceIndexText = newReplaceIndexText.replaceAll(/require\("\.\.\/\.\.\/src\/global.(less|scss|css)"\);/g, '');
320
321
  }
321
322
  return newReplaceIndexText;
322
323
  };
@@ -344,7 +345,7 @@ var initTemplateConfig = function (routerConfig, templateType, env) {
344
345
  switch (_a.label) {
345
346
  case 0:
346
347
  copyTargetPath = path_1.default.resolve(projectPath, "./.swico".concat(envPath));
347
- return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType, "/$env")), copyTargetPath, function (fileName) {
348
+ return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../project-path/.swico-".concat(templateType, "/$env")), copyTargetPath, function (fileName) {
348
349
  return !fileName.endsWith('.d.ts') &&
349
350
  (templateType === 'vue'
350
351
  ? !['Container.js', 'vue-hooks.js'].includes(fileName)
@@ -352,7 +353,7 @@ var initTemplateConfig = function (routerConfig, templateType, env) {
352
353
  })];
353
354
  case 1:
354
355
  _a.sent();
355
- return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), path_1.default.resolve(projectPath, './.swico'), function (fileName) {
356
+ return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../project-path/.swico-".concat(templateType)), path_1.default.resolve(projectPath, './.swico'), function (fileName) {
356
357
  return ['react-hooks.js', 'vue-hooks.js', 'loading.js', 'Container.vue'].includes(fileName);
357
358
  })];
358
359
  case 2:
@@ -371,13 +372,6 @@ var initTemplateConfig = function (routerConfig, templateType, env) {
371
372
  return [4, fs_extra_1.default.writeFile(hooksFilePath, replaceHooksText)];
372
373
  case 6:
373
374
  _a.sent();
374
- replaceIndexText = replaceIndexText.replace('require("../../global");', 'require("../../src/global");');
375
- if (templateType === 'vue') {
376
- replaceIndexText = replaceIndexText.replace('require("../../layout/Layout")', 'require("../../src/layout/Layout")');
377
- }
378
- else if (templateType === 'react') {
379
- replaceIndexText = replaceIndexText.replace('require("../../layout")', 'require("../../src/layout")');
380
- }
381
375
  replaceIndexText = (0, exports.handleGlobalStyleFile)(replaceIndexText);
382
376
  if (!(templateType === 'vue')) return [3, 8];
383
377
  replaceIndexText = replaceIndexText.replace('"../Container"', '"../Container.vue"');
@@ -262,7 +262,7 @@ var initIndexFile = function () { return __awaiter(void 0, void 0, void 0, funct
262
262
  .resolve(projectPath, './.swico/react-hooks')
263
263
  .replaceAll('\\', '/');
264
264
  if (!fileText.includes("require(\"".concat(formatHooksPath, "\");"))) return [3, 3];
265
- fileText = fileText.replaceAll("require(\"".concat(formatHooksPath, "\");"), 'require("./template/react/react-hooks");');
265
+ fileText = fileText.replaceAll("require(\"".concat(formatHooksPath, "\");"), 'require("./project-path/.swico-react/react-hooks");');
266
266
  return [4, fs_extra_1.default.writeFile(targetPath, fileText)];
267
267
  case 2:
268
268
  _a.sent();