swico 2.8.0 → 2.9.0-beta.2

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": "2.8.0",
3
+ "version": "2.9.0-beta.2",
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
@@ -3,6 +3,7 @@ import { UseLocationType, UseNavType } from './typings/global-type';
3
3
  import { App } from 'vue';
4
4
  import { Router } from 'vue-router';
5
5
  export type CustomConfigType = GlobalData['customConfig'];
6
+ export type * from './typings/global-type';
6
7
  export type { GlobalSwicoConfigType };
7
8
  export { history } from './mock-history';
8
9
  declare let Outlet: any, Link: any, useLocation: UseLocationType, useNav: UseNavType;
@@ -3,6 +3,7 @@ import { CSSProperties, FC, ReactNode } from 'react';
3
3
  import { SwicoHistoryOptionType } from './typings/global-type';
4
4
  import { useLocation, useNav } from './template-root/.swico-react/hooks';
5
5
  export type CustomConfigType = GlobalData['customConfig'];
6
+ export type * from './typings/global-type';
6
7
  export type { GlobalSwicoConfigType };
7
8
  interface LinkPropsType {
8
9
  replace?: boolean;
@@ -8,6 +8,7 @@ export { RouterView } from 'vue-router';
8
8
  export { useLocation, useNav };
9
9
  export { history } from './mock-history';
10
10
  export type { GlobalSwicoConfigType };
11
+ export type * from './typings/global-type';
11
12
  export declare const Outlet: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
12
13
  interface LinkPropsType {
13
14
  replace?: boolean;
@@ -39,7 +39,8 @@ function default_1(_a) {
39
39
  const initialDefineVarsConfig = {
40
40
  SWICO_ENV: JSON.stringify(env),
41
41
  SWICO_ROUTER_BASE: JSON.stringify(routerBase),
42
- SWICO_PUBLIC_PATH: JSON.stringify(publicPath)
42
+ SWICO_PUBLIC_PATH: JSON.stringify(publicPath),
43
+ SWICO_STATIC_PUBLIC_PATH: JSON.stringify(env === 'prod' ? publicPath : '/')
43
44
  };
44
45
  const customDefineVarsConfig = yield (0, main_config_1.getFormatDefineVars)((_e = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.define) !== null && _e !== void 0 ? _e : {});
45
46
  return {
@@ -42,7 +42,8 @@ function default_1(_a) {
42
42
  const initialDefineVarsConfig = {
43
43
  SWICO_ENV: JSON.stringify(env),
44
44
  SWICO_ROUTER_BASE: JSON.stringify(routerBase),
45
- SWICO_PUBLIC_PATH: JSON.stringify(publicPath)
45
+ SWICO_PUBLIC_PATH: JSON.stringify(publicPath),
46
+ SWICO_STATIC_PUBLIC_PATH: JSON.stringify(env === 'prod' ? publicPath : '/')
46
47
  };
47
48
  const customDefineVarsConfig = yield (0, main_config_1.getFormatDefineVars)((_e = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.define) !== null && _e !== void 0 ? _e : {});
48
49
  return {
@@ -1,7 +1,7 @@
1
1
  import { SwicoHistoryType, SwicoLocationType } from '../../../typings/global-type';
2
2
  export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
3
3
  export declare const interpolatePath: (pathTemplate: string, params: Record<string, any>) => string;
4
- export declare const formatAncPath: (ancPath: string) => string;
4
+ export declare const interpolatePathParams: (pathTemplate: string, path: string) => {};
5
5
  export declare const pathNameList: {
6
6
  path: string;
7
7
  name: string;
@@ -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.history = exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
6
+ exports.history = exports.getHistory = exports.pathNameList = exports.interpolatePathParams = exports.interpolatePath = exports.compareURLPatterns = void 0;
7
7
  const qs_1 = __importDefault(require("qs"));
8
8
  const router_1 = require("./router");
9
9
  const lastIndexBase = router_1.routerBase[router_1.routerBase.length - 1];
@@ -61,17 +61,17 @@ const interpolatePathParams = (pathTemplate = '', path) => {
61
61
  }
62
62
  return {};
63
63
  };
64
+ exports.interpolatePathParams = interpolatePathParams;
64
65
  const formatAncPath = (ancPath) => {
65
66
  let newAncPath = ancPath.startsWith('/') ? ancPath : '/' + ancPath;
66
67
  newAncPath = newAncPath.endsWith('/') ? newAncPath.slice(0, -1) : newAncPath;
67
68
  return newAncPath;
68
69
  };
69
- exports.formatAncPath = formatAncPath;
70
70
  const getPathNameList = (routes) => {
71
71
  const list = [];
72
72
  const checkRouteItem = (item, ancPath) => {
73
73
  const { path, name, children, custom } = item;
74
- const newAncPath = `${(0, exports.formatAncPath)(ancPath)}${path.startsWith('/') ? path : '/' + path}`;
74
+ const newAncPath = `${formatAncPath(ancPath)}${path.startsWith('/') ? path : '/' + path}`;
75
75
  list.push({ path: newAncPath, name, custom });
76
76
  if (children) {
77
77
  children.some((item) => checkRouteItem(item, newAncPath));
@@ -86,7 +86,7 @@ const getLocation = (historyLocation) => {
86
86
  const routerBaseLength = formatRouterBase.length;
87
87
  const path = pathname.slice(routerBaseLength);
88
88
  const matchPathNameItem = exports.pathNameList.find((item) => item.path === path || (0, exports.compareURLPatterns)(path, item.path));
89
- const params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
89
+ const params = (0, exports.interpolatePathParams)(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
90
90
  return {
91
91
  state: state !== null && state !== void 0 ? state : {},
92
92
  hash,
@@ -142,7 +142,9 @@ const getHistory = (router) => {
142
142
  break;
143
143
  case 'object':
144
144
  const formatOption = getFormatHistoryOption(to, exports.pathNameList, 'push');
145
- router.navigate(formatOption, { state: to.state });
145
+ router.navigate(formatOption, {
146
+ state: Object.assign({ navType: 'push' }, (to.state || {}))
147
+ });
146
148
  break;
147
149
  default:
148
150
  throw `An error occurred while executing history.push operation: unexpected type of 'to':${typeof to}`;
@@ -155,7 +157,10 @@ const getHistory = (router) => {
155
157
  break;
156
158
  case 'object':
157
159
  const formatOption = getFormatHistoryOption(to, exports.pathNameList, 'replace');
158
- router.navigate(formatOption, { state: to.state, replace: true });
160
+ router.navigate(formatOption, {
161
+ state: Object.assign({ navType: 'replace' }, (to.state || {})),
162
+ replace: true
163
+ });
159
164
  break;
160
165
  default:
161
166
  throw `An error occurred while executing history.replace operation: unexpected type of 'to':${typeof to}`;
@@ -97,8 +97,8 @@ const App = () => {
97
97
  });
98
98
  return react_1.default.createElement(react_router_1.RouterProvider, { router: router });
99
99
  };
100
+ (_a = global_1.default === null || global_1.default === void 0 ? void 0 : global_1.default.onInit) === null || _a === void 0 ? void 0 : _a.call(global_1.default);
100
101
  const rootEle = document.createElement('div');
101
102
  document.body.appendChild(rootEle);
102
103
  const root = (0, client_1.createRoot)(rootEle);
103
104
  root.render(react_1.default.createElement(App, null));
104
- (_a = global_1.default === null || global_1.default === void 0 ? void 0 : global_1.default.onInit) === null || _a === void 0 ? void 0 : _a.call(global_1.default);
@@ -38,6 +38,9 @@ const getFormatNavPath = (to) => {
38
38
  const search = query ? `?${qs_1.default.stringify(query)}` : '';
39
39
  const formatHash = hash ? (hash.startsWith('#') ? hash : `#${hash}`) : '';
40
40
  const formatPath = name ? (_a = history_1.pathNameList.find((item) => item.name === name)) === null || _a === void 0 ? void 0 : _a.path : path;
41
+ if (name && !formatPath) {
42
+ throw `An error occurred while executing 'useNav()' operation: The path for the name "${name}" could not be found`;
43
+ }
41
44
  let newPath = formatPath ? (0, history_1.interpolatePath)(formatPath, params || {}) : '';
42
45
  newPath = newPath + search + formatHash;
43
46
  return newPath;
@@ -53,7 +56,7 @@ const useNav = () => {
53
56
  navigate(to);
54
57
  break;
55
58
  case 'object':
56
- navigate(getFormatNavPath(to), Object.assign(Object.assign({}, (options || {})), { state: to.state }));
59
+ navigate(getFormatNavPath(to), Object.assign(Object.assign({}, (options || {})), { state: Object.assign({ navType: (options === null || options === void 0 ? void 0 : options.replace) ? 'replace' : 'push' }, (to.state || {})) }));
57
60
  break;
58
61
  default:
59
62
  throw `An error occurred while executing useNav() operation: unexpected type of 'to':${typeof to}`;
@@ -1,3 +1,9 @@
1
1
  import { SwicoHistoryType } from '../../../typings/global-type';
2
2
  export declare let history: SwicoHistoryType;
3
+ export declare const formatAncPath: (ancPath: string) => string;
4
+ export declare const pathNameList: {
5
+ path: string;
6
+ name: string;
7
+ custom?: any;
8
+ }[];
3
9
  export declare const getRouter: () => import("vue-router").Router;
@@ -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.getRouter = exports.history = void 0;
6
+ exports.getRouter = exports.pathNameList = exports.formatAncPath = exports.history = void 0;
7
7
  const vue_router_1 = require("vue-router");
8
8
  const router_1 = require("./router");
9
9
  const qs_1 = __importDefault(require("qs"));
@@ -14,6 +14,26 @@ const transformRouteItemCustomToMeta = (routeItem) => {
14
14
  return Object.assign(Object.assign({}, newRouteItem), { children: children === null || children === void 0 ? void 0 : children.map((item) => transformRouteItemCustomToMeta(item)) });
15
15
  };
16
16
  const formatRoutes = router_1.routes.map((routeItem) => transformRouteItemCustomToMeta(routeItem));
17
+ const formatAncPath = (ancPath) => {
18
+ let newAncPath = ancPath.startsWith('/') ? ancPath : '/' + ancPath;
19
+ newAncPath = newAncPath.endsWith('/') ? newAncPath.slice(0, -1) : newAncPath;
20
+ return newAncPath;
21
+ };
22
+ exports.formatAncPath = formatAncPath;
23
+ const getPathNameList = (routes) => {
24
+ const list = [];
25
+ const checkRouteItem = (item, ancPath) => {
26
+ const { path, name, children, custom } = item;
27
+ const newAncPath = `${(0, exports.formatAncPath)(ancPath)}${path.startsWith('/') ? path : '/' + path}`;
28
+ list.push({ path: newAncPath, name, custom });
29
+ if (children) {
30
+ children.some((item) => checkRouteItem(item, newAncPath));
31
+ }
32
+ };
33
+ routes.forEach((item) => checkRouteItem(item, ''));
34
+ return list;
35
+ };
36
+ exports.pathNameList = getPathNameList(router_1.routes);
17
37
  const getRouter = () => {
18
38
  const router = (0, vue_router_1.createRouter)({
19
39
  history: (router_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(router_1.routerBase),
@@ -26,7 +46,16 @@ const getRouter = () => {
26
46
  }
27
47
  else {
28
48
  const { query, name, hash, params, path, state } = options;
29
- router.push({ name, path, query, hash, params, state: { swicoState: state } });
49
+ router.push({
50
+ name,
51
+ path,
52
+ query,
53
+ hash,
54
+ params,
55
+ state: {
56
+ swicoState: Object.assign({ navType: 'push' }, (state || {}))
57
+ }
58
+ });
30
59
  }
31
60
  },
32
61
  replace: (options) => {
@@ -35,7 +64,16 @@ const getRouter = () => {
35
64
  }
36
65
  else {
37
66
  const { query, name, hash, params, path, state } = options;
38
- router.replace({ name, path, query, hash, params, state: { swicoState: state } });
67
+ router.replace({
68
+ name,
69
+ path,
70
+ query,
71
+ hash,
72
+ params,
73
+ state: {
74
+ swicoState: Object.assign({ navType: 'replace' }, (state || {}))
75
+ }
76
+ });
39
77
  }
40
78
  },
41
79
  go: router.go,
@@ -1,9 +1,9 @@
1
1
  import { RouteRecordRaw } from 'vue-router';
2
2
  import { ConfigRouterType } from '../../../main-config';
3
- type RouteItem = RouteRecordRaw & {
3
+ export type RouteItem = RouteRecordRaw & {
4
4
  decorator?: string;
5
+ custom?: any;
5
6
  };
6
7
  export declare const routes: RouteItem[];
7
8
  export declare const routerType: ConfigRouterType['type'];
8
9
  export declare const routerBase: ConfigRouterType['base'];
9
- export {};
@@ -8,6 +8,7 @@ const vue_router_1 = require("vue-router");
8
8
  const qs_1 = __importDefault(require("qs"));
9
9
  const vue_1 = require("vue");
10
10
  const router_1 = require("./$env/router");
11
+ const history_1 = require("./$env/history");
11
12
  const getFormatRouterBase = (routerBase) => {
12
13
  const lastIndexBase = routerBase[routerBase.length - 1];
13
14
  return lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
@@ -45,6 +46,7 @@ exports.useLocation = useLocation;
45
46
  const useNav = () => {
46
47
  const router = (0, vue_router_1.useRouter)();
47
48
  const newNavigate = (to, options) => {
49
+ var _a;
48
50
  switch (typeof to) {
49
51
  case 'string':
50
52
  if (options === null || options === void 0 ? void 0 : options.replace) {
@@ -57,14 +59,21 @@ const useNav = () => {
57
59
  case 'number':
58
60
  router.go(to);
59
61
  break;
60
- case 'object':
62
+ case 'object': {
63
+ const name = to.name;
64
+ if (name && !((_a = history_1.pathNameList.find((item) => item.name === name)) === null || _a === void 0 ? void 0 : _a.path)) {
65
+ throw `An error occurred while executing 'useNav()' operation: The path for the name "${to.name}" could not be found`;
66
+ }
61
67
  if (options === null || options === void 0 ? void 0 : options.replace) {
62
68
  router.replace(to);
63
69
  }
64
70
  else {
65
- router.push(Object.assign(Object.assign({}, to), { state: { swicoState: to.state } }));
71
+ router.push(Object.assign(Object.assign({}, to), { state: {
72
+ swicoState: Object.assign({ navType: (options === null || options === void 0 ? void 0 : options.replace) ? 'replace' : 'push' }, (to.state || {}))
73
+ } }));
66
74
  }
67
75
  break;
76
+ }
68
77
  default:
69
78
  throw `An error occurred while executing useNav() operation: unexpected type of 'to':${typeof to}`;
70
79
  }