swico 2.8.0 → 2.9.0-beta.1

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.1",
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,6 +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 interpolatePathParams: (pathTemplate: string, path: string) => {};
4
5
  export declare const formatAncPath: (ancPath: string) => string;
5
6
  export declare const pathNameList: {
6
7
  path: 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.formatAncPath = 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,6 +61,7 @@ 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;
@@ -86,7 +87,7 @@ const getLocation = (historyLocation) => {
86
87
  const routerBaseLength = formatRouterBase.length;
87
88
  const path = pathname.slice(routerBaseLength);
88
89
  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);
90
+ const params = (0, exports.interpolatePathParams)(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
90
91
  return {
91
92
  state: state !== null && state !== void 0 ? state : {},
92
93
  hash,
@@ -142,7 +143,9 @@ const getHistory = (router) => {
142
143
  break;
143
144
  case 'object':
144
145
  const formatOption = getFormatHistoryOption(to, exports.pathNameList, 'push');
145
- router.navigate(formatOption, { state: to.state });
146
+ router.navigate(formatOption, {
147
+ state: Object.assign({ navType: 'push' }, (to.state || {}))
148
+ });
146
149
  break;
147
150
  default:
148
151
  throw `An error occurred while executing history.push operation: unexpected type of 'to':${typeof to}`;
@@ -155,7 +158,10 @@ const getHistory = (router) => {
155
158
  break;
156
159
  case 'object':
157
160
  const formatOption = getFormatHistoryOption(to, exports.pathNameList, 'replace');
158
- router.navigate(formatOption, { state: to.state, replace: true });
161
+ router.navigate(formatOption, {
162
+ state: Object.assign({ navType: 'replace' }, (to.state || {})),
163
+ replace: true
164
+ });
159
165
  break;
160
166
  default:
161
167
  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}`;
@@ -26,7 +26,16 @@ const getRouter = () => {
26
26
  }
27
27
  else {
28
28
  const { query, name, hash, params, path, state } = options;
29
- router.push({ name, path, query, hash, params, state: { swicoState: state } });
29
+ router.push({
30
+ name,
31
+ path,
32
+ query,
33
+ hash,
34
+ params,
35
+ state: {
36
+ swicoState: Object.assign({ navType: 'push' }, (state || {}))
37
+ }
38
+ });
30
39
  }
31
40
  },
32
41
  replace: (options) => {
@@ -35,7 +44,16 @@ const getRouter = () => {
35
44
  }
36
45
  else {
37
46
  const { query, name, hash, params, path, state } = options;
38
- router.replace({ name, path, query, hash, params, state: { swicoState: state } });
47
+ router.replace({
48
+ name,
49
+ path,
50
+ query,
51
+ hash,
52
+ params,
53
+ state: {
54
+ swicoState: Object.assign({ navType: 'replace' }, (state || {}))
55
+ }
56
+ });
39
57
  }
40
58
  },
41
59
  go: router.go,
@@ -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("../.swico-react/$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
  }