swico 2.8.0-beta.9 → 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,17 +1,21 @@
1
1
  {
2
2
  "name": "swico",
3
- "version": "2.8.0-beta.9",
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",
7
7
  "exports": {
8
8
  ".": {
9
- "import": "./src/index.js",
9
+ "default": "./src/index.js",
10
10
  "types": "./src/index.d.ts"
11
11
  },
12
12
  "./react": {
13
- "import": "./src/index.react.js",
13
+ "default": "./src/index.react.js",
14
14
  "types": "./src/index.react.d.ts"
15
+ },
16
+ "./vue": {
17
+ "default": "./src/index.vue.js",
18
+ "types": "./src/index.vue.d.ts"
15
19
  }
16
20
  },
17
21
  "keywords": [
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,15 +3,16 @@ 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
- interface PropsType {
8
+ interface LinkPropsType {
8
9
  replace?: boolean;
9
10
  to: string | number | SwicoHistoryOptionType;
10
11
  style?: CSSProperties;
11
12
  className?: string;
12
13
  children: ReactNode;
13
14
  }
14
- export declare const Link: FC<PropsType>;
15
+ export declare const Link: FC<LinkPropsType>;
15
16
  export { Outlet } from 'react-router';
16
17
  export { useLocation, useNav };
17
18
  export { history } from './mock-history';
@@ -2,35 +2,21 @@ import { GlobalData, GlobalSwicoConfigType } from './main-config';
2
2
  import { App } from 'vue';
3
3
  import { Router } from 'vue-router';
4
4
  import { useLocation, useNav } from './template-root/.swico-vue/hooks';
5
+ import { SwicoHistoryOptionType } from './typings/global-type';
5
6
  export type CustomConfigType = GlobalData['customConfig'];
6
7
  export { RouterView } from 'vue-router';
7
8
  export { useLocation, useNav };
8
9
  export { history } from './mock-history';
9
10
  export type { GlobalSwicoConfigType };
11
+ export type * from './typings/global-type';
10
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>;
11
- export declare const Link: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
12
- to: {
13
- required: true;
14
- };
15
- replace: {
16
- type: BooleanConstructor;
17
- };
18
- }>, {
19
- nav: {
20
- (to: string, options?: import("./typings/global-type").NavOptionsType): void;
21
- (to: number): void;
22
- (to: import("./typings/global-type").SwicoHistoryOptionType, options?: import("./typings/global-type").NavOptionsType): void;
23
- };
24
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
25
- to: {
26
- required: true;
27
- };
28
- replace: {
29
- type: BooleanConstructor;
30
- };
31
- }>> & Readonly<{}>, {
32
- replace: boolean;
33
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
13
+ interface LinkPropsType {
14
+ replace?: boolean;
15
+ to: string | number | SwicoHistoryOptionType;
16
+ }
17
+ export declare const Link: import("vue").DefineComponent<LinkPropsType, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<LinkPropsType> & Readonly<{}>, {
18
+ [x: string]: any;
19
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
34
20
  export interface DefineSwicoConfigType {
35
21
  (env: 'base', config: CustomConfigType['base']): any;
36
22
  (env: 'dev', config: CustomConfigType['dev']): any;
@@ -90,6 +90,7 @@ export default function ({ projectPath, entryPath, env, customConfig }: GlobalDa
90
90
  alias: {
91
91
  '@': string;
92
92
  'react-router': string;
93
+ 'swico/react': string;
93
94
  swico: string;
94
95
  qs: string;
95
96
  };
@@ -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 {
@@ -146,7 +147,7 @@ function default_1(_a) {
146
147
  },
147
148
  resolve: {
148
149
  extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
149
- alias: Object.assign({ '@': path_1.default.join(projectPath, '/src'), 'react-router': path_1.default.dirname(require.resolve('react-router')), swico: path_1.default.join(projectPath, '/.swico/index'), qs: path_1.default.dirname(require.resolve('qs')) }, getCustomAliasConfig())
150
+ alias: Object.assign({ '@': path_1.default.join(projectPath, '/src'), 'react-router': path_1.default.dirname(require.resolve('react-router')), 'swico/react': path_1.default.join(projectPath, '/.swico/index'), swico: path_1.default.join(projectPath, '/.swico/index'), qs: path_1.default.dirname(require.resolve('qs')) }, getCustomAliasConfig())
150
151
  },
151
152
  externals: customConfig.base.externals,
152
153
  plugins: [
@@ -125,6 +125,7 @@ export default function ({ projectPath, entryPath, env, customConfig }: GlobalDa
125
125
  '@': string;
126
126
  vue: string;
127
127
  'vue-router': string;
128
+ 'swico/vue': string;
128
129
  swico: string;
129
130
  qs: string;
130
131
  };
@@ -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 {
@@ -254,7 +255,7 @@ function default_1(_a) {
254
255
  },
255
256
  resolve: {
256
257
  extensions: ['.ts', '.js', '.vue', '.json'],
257
- alias: Object.assign({ '@': path_1.default.join(projectPath, '/src'), vue: 'vue/dist/vue.esm-bundler.js', 'vue-router': path_1.default.dirname(require.resolve('vue-router')), swico: path_1.default.join(projectPath, '/.swico/index'), qs: path_1.default.dirname(require.resolve('qs')) }, getCustomAliasConfig())
258
+ alias: Object.assign({ '@': path_1.default.join(projectPath, '/src'), vue: 'vue/dist/vue.esm-bundler.js', 'vue-router': path_1.default.dirname(require.resolve('vue-router')), 'swico/vue': path_1.default.join(projectPath, '/.swico/index'), swico: path_1.default.join(projectPath, '/.swico/index'), qs: path_1.default.dirname(require.resolve('qs')) }, getCustomAliasConfig())
258
259
  },
259
260
  externals: customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.externals,
260
261
  plugins: [
@@ -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,
@@ -24,7 +24,7 @@ const router = (0, history_1.getRouter)();
24
24
  const app = (0, vue_1.createApp)(Container);
25
25
  app.component('SwicoLayout', Layout_1.default);
26
26
  app.use(router);
27
+ (_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, app, router);
27
28
  const rootEle = document.createElement('div');
28
29
  document.body.appendChild(rootEle);
29
30
  app.mount(rootEle);
30
- (_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, app, router);
@@ -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
  }