swico 2.7.1 → 2.8.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 +1 -1
- package/src/index.d.ts +6 -2
- package/src/index.react.d.ts +15 -3
- package/src/index.react.js +11 -5
- package/src/index.vue.d.ts +25 -2
- package/src/index.vue.js +27 -8
- package/src/main-config/index.js +13 -19
- package/src/{project-path → template-root}/.swico-react/$env/history.js +4 -5
- package/src/{project-path → template-root}/.swico-react/$env/index.d.ts +0 -1
- package/src/{project-path → template-root}/.swico-react/$env/index.js +16 -12
- package/src/{project-path/.swico-react/$env/config.d.ts → template-root/.swico-react/$env/router.d.ts} +2 -0
- package/src/{project-path/.swico-vue/$env/config.js → template-root/.swico-react/$env/router.js} +2 -1
- package/src/{project-path → template-root}/.swico-vue/$env/history.js +5 -6
- package/src/{project-path → template-root}/.swico-vue/$env/index.js +4 -1
- package/src/{project-path/.swico-vue/$env/config.d.ts → template-root/.swico-vue/$env/router.d.ts} +6 -0
- package/src/{project-path/.swico-react/$env/config.js → template-root/.swico-vue/$env/router.js} +2 -1
- package/src/{project-path → template-root}/.swico-vue/hooks.js +2 -2
- package/src/{project-path → template-root}/src/global.d.ts +1 -1
- package/src/project-path/.swico-react/$env/routes.d.ts +0 -3
- package/src/project-path/.swico-react/$env/routes.js +0 -3
- package/src/project-path/.swico-react/Link.d.ts +0 -11
- package/src/project-path/.swico-react/Link.js +0 -14
- package/src/project-path/.swico-react/loading.d.ts +0 -2
- package/src/project-path/.swico-react/loading.js +0 -3
- package/src/project-path/.swico-vue/$env/routes.d.ts +0 -6
- package/src/project-path/.swico-vue/$env/routes.js +0 -3
- package/src/project-path/.swico-vue/Link.d.ts +0 -24
- package/src/project-path/.swico-vue/Link.js +0 -28
- /package/src/{project-path → template-root}/.swico-react/$env/history.d.ts +0 -0
- /package/src/{project-path → template-root}/.swico-react/hooks.d.ts +0 -0
- /package/src/{project-path → template-root}/.swico-react/hooks.js +0 -0
- /package/src/{project-path → template-root}/.swico-vue/$env/history.d.ts +0 -0
- /package/src/{project-path → template-root}/.swico-vue/$env/index.d.ts +0 -0
- /package/src/{project-path → template-root}/.swico-vue/hooks.d.ts +0 -0
- /package/src/{project-path → template-root}/src/global.js +0 -0
- /package/src/{project-path → template-root}/src/layout/Layout.d.ts +0 -0
- /package/src/{project-path → template-root}/src/layout/Layout.js +0 -0
- /package/src/{project-path → template-root}/src/layout/index.d.ts +0 -0
- /package/src/{project-path → template-root}/src/layout/index.js +0 -0
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { GlobalData, GlobalSwicoConfigType } from './main-config';
|
|
2
2
|
import { UseLocationType, UseNavType } from './typings/global-type';
|
|
3
|
+
import { Outlet as ReactOutlet, Link as ReactLink } from './index.react';
|
|
4
|
+
import { Outlet as VueOutlet, Link as VueLink } from './index.vue';
|
|
5
|
+
import { App } from 'vue';
|
|
6
|
+
import { Router } from 'vue-router';
|
|
3
7
|
export type CustomConfigType = GlobalData['customConfig'];
|
|
4
8
|
export type { GlobalSwicoConfigType };
|
|
5
9
|
export { history } from './mock-history';
|
|
6
|
-
declare let Outlet:
|
|
10
|
+
declare let Outlet: typeof ReactOutlet | typeof VueOutlet, Link: typeof ReactLink | typeof VueLink, useLocation: UseLocationType, useNav: UseNavType;
|
|
7
11
|
export { Outlet, Link, useLocation, useNav };
|
|
8
12
|
export interface DefineSwicoConfigType {
|
|
9
13
|
(env: 'base', config: CustomConfigType['base']): CustomConfigType['base'];
|
|
@@ -12,6 +16,6 @@ export interface DefineSwicoConfigType {
|
|
|
12
16
|
}
|
|
13
17
|
export declare const defineConfig: DefineSwicoConfigType;
|
|
14
18
|
export interface DefineGlobalConfigType {
|
|
15
|
-
onInit?: (app:
|
|
19
|
+
onInit?: ((app: App, router: Router) => void) | (() => void);
|
|
16
20
|
}
|
|
17
21
|
export declare const defineGlobal: (config: DefineGlobalConfigType) => DefineGlobalConfigType;
|
package/src/index.react.d.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { GlobalData, GlobalSwicoConfigType } from './main-config';
|
|
2
|
+
import { CSSProperties, FC, ReactNode } from 'react';
|
|
3
|
+
import { useNav, useLocation } from './template-root/.swico-react/hooks';
|
|
4
|
+
import { SwicoHistoryOptionType } from './typings/global-type';
|
|
2
5
|
export type CustomConfigType = GlobalData['customConfig'];
|
|
6
|
+
interface PropsType {
|
|
7
|
+
replace?: boolean;
|
|
8
|
+
to: string | number | SwicoHistoryOptionType;
|
|
9
|
+
style?: CSSProperties;
|
|
10
|
+
className?: string;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare const Link: FC<PropsType>;
|
|
3
14
|
export type { GlobalSwicoConfigType };
|
|
4
|
-
export { default as Link } from './project-path/.swico-react/Link';
|
|
5
15
|
export { Outlet } from 'react-router';
|
|
6
|
-
export { useLocation, useNav }
|
|
16
|
+
export { useLocation, useNav };
|
|
7
17
|
export { history } from './mock-history';
|
|
8
18
|
export interface DefineSwicoConfigType {
|
|
9
19
|
(env: 'base', config: CustomConfigType['base']): any;
|
|
@@ -11,5 +21,7 @@ export interface DefineSwicoConfigType {
|
|
|
11
21
|
(env: 'prod', config: CustomConfigType['prod']): any;
|
|
12
22
|
}
|
|
13
23
|
export declare const defineConfig: DefineSwicoConfigType;
|
|
14
|
-
export
|
|
24
|
+
export interface DefineGlobalConfigType {
|
|
25
|
+
onInit?: () => void;
|
|
26
|
+
}
|
|
15
27
|
export declare const defineGlobal: (config: DefineGlobalConfigType) => DefineGlobalConfigType;
|
package/src/index.react.js
CHANGED
|
@@ -4,13 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.defineGlobal = exports.defineConfig = exports.history = exports.useNav = exports.useLocation = exports.Outlet = exports.Link = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const hooks_1 = require("./template-root/.swico-react/hooks");
|
|
9
|
+
Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return hooks_1.useNav; } });
|
|
10
|
+
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return hooks_1.useLocation; } });
|
|
11
|
+
const Link = ({ replace, to, style, className, children }) => {
|
|
12
|
+
const nav = (0, hooks_1.useNav)();
|
|
13
|
+
return (react_1.default.createElement("a", { onClick: () => {
|
|
14
|
+
nav(to, { replace });
|
|
15
|
+
}, style: style, className: className }, children));
|
|
16
|
+
};
|
|
17
|
+
exports.Link = Link;
|
|
9
18
|
var react_router_1 = require("react-router");
|
|
10
19
|
Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return react_router_1.Outlet; } });
|
|
11
|
-
var hooks_1 = require("./project-path/.swico-react/hooks");
|
|
12
|
-
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return hooks_1.useLocation; } });
|
|
13
|
-
Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return hooks_1.useNav; } });
|
|
14
20
|
var mock_history_1 = require("./mock-history");
|
|
15
21
|
Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
|
|
16
22
|
const defineConfig = (env, config) => config;
|
package/src/index.vue.d.ts
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
import { GlobalData, GlobalSwicoConfigType } from './main-config';
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
import { Router } from 'vue-router';
|
|
4
|
+
import { useLocation, useNav } from './template-root/.swico-vue/hooks';
|
|
4
5
|
export type CustomConfigType = GlobalData['customConfig'];
|
|
5
6
|
export { RouterView } from 'vue-router';
|
|
6
|
-
export { useLocation, useNav }
|
|
7
|
+
export { useLocation, useNav };
|
|
7
8
|
export { history } from './mock-history';
|
|
8
9
|
export type { GlobalSwicoConfigType };
|
|
9
10
|
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>;
|
|
10
|
-
export
|
|
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>;
|
|
11
34
|
export interface DefineSwicoConfigType {
|
|
12
35
|
(env: 'base', config: CustomConfigType['base']): any;
|
|
13
36
|
(env: 'dev', config: CustomConfigType['dev']): any;
|
package/src/index.vue.js
CHANGED
|
@@ -1,23 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.defineGlobal = exports.defineConfig = exports.Link = exports.Outlet = exports.history = exports.useNav = exports.useLocation = exports.RouterView = void 0;
|
|
7
4
|
const vue_1 = require("vue");
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "RouterView", { enumerable: true, get: function () { return vue_router_1.RouterView; } });
|
|
10
|
-
var hooks_1 = require("./project-path/.swico-vue/hooks");
|
|
5
|
+
const hooks_1 = require("./template-root/.swico-vue/hooks");
|
|
11
6
|
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return hooks_1.useLocation; } });
|
|
12
7
|
Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return hooks_1.useNav; } });
|
|
8
|
+
var vue_router_1 = require("vue-router");
|
|
9
|
+
Object.defineProperty(exports, "RouterView", { enumerable: true, get: function () { return vue_router_1.RouterView; } });
|
|
13
10
|
var mock_history_1 = require("./mock-history");
|
|
14
11
|
Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
|
|
15
12
|
exports.Outlet = (0, vue_1.defineComponent)({
|
|
16
13
|
name: 'Outlet',
|
|
17
14
|
template: '<RouterView />'
|
|
18
15
|
});
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
exports.Link = (0, vue_1.defineComponent)({
|
|
17
|
+
name: 'Link',
|
|
18
|
+
props: {
|
|
19
|
+
to: {
|
|
20
|
+
required: true
|
|
21
|
+
},
|
|
22
|
+
replace: {
|
|
23
|
+
type: Boolean
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
setup(props) {
|
|
27
|
+
const nav = (0, hooks_1.useNav)();
|
|
28
|
+
return { nav };
|
|
29
|
+
},
|
|
30
|
+
template: `<a
|
|
31
|
+
@click="
|
|
32
|
+
() => {
|
|
33
|
+
nav(to, { replace });
|
|
34
|
+
}
|
|
35
|
+
"
|
|
36
|
+
>
|
|
37
|
+
<slot></slot>
|
|
38
|
+
</a>`
|
|
39
|
+
});
|
|
21
40
|
const defineConfig = (env, config) => config;
|
|
22
41
|
exports.defineConfig = defineConfig;
|
|
23
42
|
const defineGlobal = (config) => config;
|
package/src/main-config/index.js
CHANGED
|
@@ -160,11 +160,7 @@ const initCliEntryFile = (projectPath, templateType, env) => __awaiter(void 0, v
|
|
|
160
160
|
const formatHooksPath = path_1.default
|
|
161
161
|
.resolve(projectPath, './.swico/hooks')
|
|
162
162
|
.replaceAll('\\', '/');
|
|
163
|
-
replaceEntryText = replaceEntryText.replaceAll(`require("./
|
|
164
|
-
const formatLinkComponentPath = path_1.default
|
|
165
|
-
.resolve(projectPath, './.swico/Link')
|
|
166
|
-
.replaceAll('\\', '/');
|
|
167
|
-
replaceEntryText = replaceEntryText.replaceAll(`require("./project-path/.swico-${templateType}/Link");`, `require("${formatLinkComponentPath}");`);
|
|
163
|
+
replaceEntryText = replaceEntryText.replaceAll(`require("./template-root/.swico-${templateType}/hooks");`, `require("${formatHooksPath}");`);
|
|
168
164
|
const formatHistoryPath = path_1.default
|
|
169
165
|
.resolve(projectPath, `./.swico/.${env}/history`)
|
|
170
166
|
.replaceAll('\\', '/');
|
|
@@ -176,24 +172,22 @@ const formatRouterConfig = ({ routes = [], type = 'browser', base = '/' }, templ
|
|
|
176
172
|
const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
177
173
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
174
|
const formatRouter = getFormatRouter(projectPath, routes, templateType);
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
exports.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const configFilePath = path_1.default.resolve(projectPath, `./.swico${envPath}config.js`);
|
|
185
|
-
let replaceConfigText = yield fs_extra_1.default.readFile(configFilePath, 'utf8');
|
|
175
|
+
const routerFilePath = path_1.default.resolve(projectPath, `./.swico${envPath}router.js`);
|
|
176
|
+
let routerFileText = yield fs_extra_1.default.readFile(routerFilePath, 'utf8');
|
|
177
|
+
let formatRoutesTextData = `exports.routes = ${JSON.stringify(formatRouter)};`;
|
|
178
|
+
formatRoutesTextData = formatRoutesTextData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
179
|
+
routerFileText = routerFileText.replace('exports.routes = [];', formatRoutesTextData);
|
|
186
180
|
if (base) {
|
|
187
|
-
|
|
181
|
+
routerFileText = routerFileText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
188
182
|
return `exports.routerBase = '${templateType === 'react' && type === 'hash' ? '/' : base}';`;
|
|
189
183
|
});
|
|
190
184
|
}
|
|
191
185
|
if (type) {
|
|
192
|
-
|
|
186
|
+
routerFileText = routerFileText.replace(/exports\.routerType\s*=\s*(.*)/gm, function (match, p1) {
|
|
193
187
|
return `exports.routerType = '${type}';`;
|
|
194
188
|
});
|
|
195
189
|
}
|
|
196
|
-
yield fs_extra_1.default.writeFile(
|
|
190
|
+
yield fs_extra_1.default.writeFile(routerFilePath, routerFileText);
|
|
197
191
|
resolve(null);
|
|
198
192
|
}));
|
|
199
193
|
};
|
|
@@ -225,10 +219,10 @@ const handleLoadingFile = (projectPath, replaceIndexText) => __awaiter(void 0, v
|
|
|
225
219
|
let newReplaceIndexText = replaceIndexText;
|
|
226
220
|
try {
|
|
227
221
|
yield fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK);
|
|
228
|
-
newReplaceIndexText = newReplaceIndexText.replace('
|
|
222
|
+
newReplaceIndexText = newReplaceIndexText.replace('const Loading = () => null;', 'const loading = __importDefault(require("../../src/loading"));');
|
|
229
223
|
}
|
|
230
224
|
catch (e) {
|
|
231
|
-
newReplaceIndexText = newReplaceIndexText.replace('"../../src/loading', '
|
|
225
|
+
newReplaceIndexText = newReplaceIndexText.replace('__importDefault(require("../../src/loading"));', '() => null;');
|
|
232
226
|
}
|
|
233
227
|
return newReplaceIndexText;
|
|
234
228
|
});
|
|
@@ -256,8 +250,8 @@ const initTemplateConfig = (routerConfig, templateType, env) => {
|
|
|
256
250
|
const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
257
251
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
258
252
|
const copyTargetPath = path_1.default.resolve(projectPath, `./.swico${envPath}`);
|
|
259
|
-
yield (0, utils_1.copyDirFiles)(path_1.default.resolve(__dirname, `../
|
|
260
|
-
yield (0, utils_1.copyDirFiles)(path_1.default.resolve(__dirname, `../
|
|
253
|
+
yield (0, utils_1.copyDirFiles)(path_1.default.resolve(__dirname, `../template-root/.swico-${templateType}/$env`), copyTargetPath, (fileName) => !fileName.endsWith('.d.ts') && !['hooks.js'].includes(fileName));
|
|
254
|
+
yield (0, utils_1.copyDirFiles)(path_1.default.resolve(__dirname, `../template-root/.swico-${templateType}`), path_1.default.resolve(projectPath, './.swico'), (fileName) => ['hooks.js'].includes(fileName));
|
|
261
255
|
const entryFilePath = path_1.default.resolve(projectPath, './.swico/index.js');
|
|
262
256
|
yield fs_extra_1.default.copyFile(path_1.default.resolve(__dirname, `../index.${templateType}.js`), entryFilePath);
|
|
263
257
|
yield formatRouterConfig(routerConfig, templateType, env);
|
|
@@ -5,10 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.history = exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
|
|
7
7
|
const qs_1 = __importDefault(require("qs"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
8
|
+
const router_1 = require("./router");
|
|
9
|
+
const lastIndexBase = router_1.routerBase[router_1.routerBase.length - 1];
|
|
10
|
+
const formatRouterBase = lastIndexBase === '/' ? router_1.routerBase.slice(0, router_1.routerBase.length - 1) : router_1.routerBase;
|
|
12
11
|
const compareURLPatterns = (urlPatternWithValues, urlPatternWithParams) => {
|
|
13
12
|
const patternWithValuesParts = urlPatternWithValues.split('/');
|
|
14
13
|
const patternWithParamsParts = urlPatternWithParams.split('/');
|
|
@@ -81,7 +80,7 @@ const getPathNameList = (routes) => {
|
|
|
81
80
|
routes.forEach((item) => checkRouteItem(item, ''));
|
|
82
81
|
return list;
|
|
83
82
|
};
|
|
84
|
-
exports.pathNameList = getPathNameList(
|
|
83
|
+
exports.pathNameList = getPathNameList(router_1.routes);
|
|
85
84
|
const getLocation = (historyLocation) => {
|
|
86
85
|
const { pathname, hash, search, state } = historyLocation;
|
|
87
86
|
const routerBaseLength = formatRouterBase.length;
|
|
@@ -35,17 +35,17 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
|
+
var _a;
|
|
38
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
40
|
exports.getChildrenRouteList = void 0;
|
|
40
41
|
const client_1 = require("react-dom/client");
|
|
41
42
|
const react_1 = __importStar(require("react"));
|
|
42
43
|
const react_router_1 = require("react-router");
|
|
43
|
-
const
|
|
44
|
+
const Loading = () => null;
|
|
44
45
|
const history_1 = require("./history");
|
|
45
|
-
require("../../src/global");
|
|
46
|
+
const global_1 = __importDefault(require("../../src/global"));
|
|
46
47
|
const layout_1 = __importDefault(require("../../src/layout"));
|
|
47
|
-
const
|
|
48
|
-
const config_1 = require("./config");
|
|
48
|
+
const router_1 = require("./router");
|
|
49
49
|
class Container extends react_1.default.Component {
|
|
50
50
|
constructor() {
|
|
51
51
|
super(...arguments);
|
|
@@ -67,7 +67,7 @@ const getChildrenRouteList = (childrenRoutes, ancPathKey) => {
|
|
|
67
67
|
const { component, path, children, redirect } = item;
|
|
68
68
|
const newAncPathKey = `${ancPathKey}-${path}`;
|
|
69
69
|
return {
|
|
70
|
-
element: redirect ? (react_1.default.createElement(react_router_1.Navigate, { to: redirect, replace: true })) : component ? (react_1.default.createElement(react_1.Suspense, { fallback: react_1.default.createElement(
|
|
70
|
+
element: redirect ? (react_1.default.createElement(react_router_1.Navigate, { to: redirect, replace: true })) : component ? (react_1.default.createElement(react_1.Suspense, { fallback: react_1.default.createElement(Loading, null) }, (0, react_1.createElement)((0, react_1.lazy)(component)))) : (react_1.default.createElement(react_router_1.Outlet, null)),
|
|
71
71
|
key: newAncPathKey,
|
|
72
72
|
path: path.startsWith('/') ? path.slice(1) : path,
|
|
73
73
|
children: (0, exports.getChildrenRouteList)(children, newAncPathKey)
|
|
@@ -81,15 +81,15 @@ const App = () => {
|
|
|
81
81
|
element: (react_1.default.createElement(Container, null,
|
|
82
82
|
react_1.default.createElement(layout_1.default, null))),
|
|
83
83
|
path: '/',
|
|
84
|
-
children: (0, exports.getChildrenRouteList)(
|
|
84
|
+
children: (0, exports.getChildrenRouteList)(router_1.routes, '')
|
|
85
85
|
}
|
|
86
86
|
];
|
|
87
|
-
const router = (
|
|
88
|
-
basename:
|
|
87
|
+
const router = (router_1.routerType === 'hash' ? react_router_1.createHashRouter : react_router_1.createBrowserRouter)(routeList, {
|
|
88
|
+
basename: router_1.routerBase
|
|
89
89
|
});
|
|
90
|
-
if (
|
|
91
|
-
if (
|
|
92
|
-
window.location.replace(`${
|
|
90
|
+
if (router_1.routerBase && router_1.routerBase !== '/') {
|
|
91
|
+
if (router_1.routerType === 'browser' && window.location.pathname === '/') {
|
|
92
|
+
window.location.replace(`${router_1.routerBase}`);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
(0, react_1.useLayoutEffect)(() => {
|
|
@@ -97,5 +97,9 @@ const App = () => {
|
|
|
97
97
|
});
|
|
98
98
|
return react_1.default.createElement(react_router_1.RouterProvider, { router: router });
|
|
99
99
|
};
|
|
100
|
-
const
|
|
100
|
+
const rootEle = document.createElement('div');
|
|
101
|
+
rootEle.id = 'swico-root';
|
|
102
|
+
document.body.appendChild(rootEle);
|
|
103
|
+
const root = (0, client_1.createRoot)(rootEle);
|
|
101
104
|
root.render(react_1.default.createElement(App, null));
|
|
105
|
+
(_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);
|
package/src/{project-path/.swico-vue/$env/config.js → template-root/.swico-react/$env/router.js}
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.routerBase = exports.routerType = void 0;
|
|
3
|
+
exports.routerBase = exports.routerType = exports.routes = void 0;
|
|
4
|
+
exports.routes = [];
|
|
4
5
|
exports.routerType = 'browser';
|
|
5
6
|
exports.routerBase = '/';
|
|
@@ -5,8 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getRouter = exports.history = void 0;
|
|
7
7
|
const vue_router_1 = require("vue-router");
|
|
8
|
-
const
|
|
9
|
-
const routes_1 = __importDefault(require("./routes"));
|
|
8
|
+
const router_1 = require("./router");
|
|
10
9
|
const qs_1 = __importDefault(require("qs"));
|
|
11
10
|
const transformRouteItemCustomToMeta = (routeItem) => {
|
|
12
11
|
const newRouteItem = Object.assign({}, routeItem);
|
|
@@ -14,10 +13,10 @@ const transformRouteItemCustomToMeta = (routeItem) => {
|
|
|
14
13
|
newRouteItem.meta = custom;
|
|
15
14
|
return Object.assign(Object.assign({}, newRouteItem), { children: children === null || children === void 0 ? void 0 : children.map((item) => transformRouteItemCustomToMeta(item)) });
|
|
16
15
|
};
|
|
17
|
-
const formatRoutes =
|
|
16
|
+
const formatRoutes = router_1.routes.map((routeItem) => transformRouteItemCustomToMeta(routeItem));
|
|
18
17
|
const getRouter = () => {
|
|
19
18
|
const router = (0, vue_router_1.createRouter)({
|
|
20
|
-
history: (
|
|
19
|
+
history: (router_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(router_1.routerBase),
|
|
21
20
|
routes: formatRoutes
|
|
22
21
|
});
|
|
23
22
|
exports.history = {
|
|
@@ -44,8 +43,8 @@ const getRouter = () => {
|
|
|
44
43
|
forward: router.forward,
|
|
45
44
|
get location() {
|
|
46
45
|
var _a, _b;
|
|
47
|
-
const lastIndexBase =
|
|
48
|
-
const formatRouterBase = lastIndexBase === '/' ?
|
|
46
|
+
const lastIndexBase = router_1.routerBase[router_1.routerBase.length - 1];
|
|
47
|
+
const formatRouterBase = lastIndexBase === '/' ? router_1.routerBase.slice(0, router_1.routerBase.length - 1) : router_1.routerBase;
|
|
49
48
|
const { path, params, query, name, hash, fullPath, meta } = router.currentRoute.value;
|
|
50
49
|
return {
|
|
51
50
|
path,
|
|
@@ -24,5 +24,8 @@ 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
|
+
const rootEle = document.createElement('div');
|
|
28
|
+
rootEle.id = 'swico-root';
|
|
29
|
+
document.body.appendChild(rootEle);
|
|
30
|
+
app.mount(rootEle);
|
|
27
31
|
(_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);
|
|
28
|
-
app.mount('#swico-root');
|
package/src/{project-path/.swico-vue/$env/config.d.ts → template-root/.swico-vue/$env/router.d.ts}
RENAMED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { RouteRecordRaw } from 'vue-router';
|
|
1
2
|
import { ConfigRouterType } from '../../../main-config';
|
|
3
|
+
type RouteItem = RouteRecordRaw & {
|
|
4
|
+
decorator?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const routes: RouteItem[];
|
|
2
7
|
export declare const routerType: ConfigRouterType['type'];
|
|
3
8
|
export declare const routerBase: ConfigRouterType['base'];
|
|
9
|
+
export {};
|
package/src/{project-path/.swico-react/$env/config.js → template-root/.swico-vue/$env/router.js}
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.routerBase = exports.routerType = void 0;
|
|
3
|
+
exports.routerBase = exports.routerType = exports.routes = void 0;
|
|
4
|
+
exports.routes = [];
|
|
4
5
|
exports.routerType = 'browser';
|
|
5
6
|
exports.routerBase = '/';
|
|
@@ -7,7 +7,7 @@ exports.useNav = exports.useLocation = exports.getFormatRouterBase = void 0;
|
|
|
7
7
|
const vue_router_1 = require("vue-router");
|
|
8
8
|
const qs_1 = __importDefault(require("qs"));
|
|
9
9
|
const vue_1 = require("vue");
|
|
10
|
-
const
|
|
10
|
+
const router_1 = require("./$env/router");
|
|
11
11
|
const getFormatRouterBase = (routerBase) => {
|
|
12
12
|
const lastIndexBase = routerBase[routerBase.length - 1];
|
|
13
13
|
return lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
|
|
@@ -31,7 +31,7 @@ const useLocation = () => {
|
|
|
31
31
|
const search = query ? qs_1.default.stringify(query) : '';
|
|
32
32
|
location.name = name;
|
|
33
33
|
location.path = path;
|
|
34
|
-
location.pathname = (0, exports.getFormatRouterBase)(
|
|
34
|
+
location.pathname = (0, exports.getFormatRouterBase)(router_1.routerBase) + path;
|
|
35
35
|
location.search = search;
|
|
36
36
|
location.query = query;
|
|
37
37
|
location.hash = hash;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CSSProperties, FC, ReactNode } from 'react';
|
|
2
|
-
import { SwicoHistoryOptionType } from '../../typings/global-type';
|
|
3
|
-
interface PropsType {
|
|
4
|
-
replace?: boolean;
|
|
5
|
-
to: string | number | SwicoHistoryOptionType;
|
|
6
|
-
style?: CSSProperties;
|
|
7
|
-
className?: string;
|
|
8
|
-
children: ReactNode;
|
|
9
|
-
}
|
|
10
|
-
declare const Link: FC<PropsType>;
|
|
11
|
-
export default Link;
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const hooks_1 = require("./hooks");
|
|
8
|
-
const Link = ({ replace, to, style, className, children }) => {
|
|
9
|
-
const nav = (0, hooks_1.useNav)();
|
|
10
|
-
return (react_1.default.createElement("a", { onClick: () => {
|
|
11
|
-
nav(to, { replace });
|
|
12
|
-
}, style: style, className: className }, children));
|
|
13
|
-
};
|
|
14
|
-
exports.default = Link;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
2
|
-
to: {
|
|
3
|
-
required: true;
|
|
4
|
-
};
|
|
5
|
-
replace: {
|
|
6
|
-
type: BooleanConstructor;
|
|
7
|
-
};
|
|
8
|
-
}>, {
|
|
9
|
-
nav: {
|
|
10
|
-
(to: string, options?: import("../../typings/global-type").NavOptionsType): void;
|
|
11
|
-
(to: number): void;
|
|
12
|
-
(to: import("../../typings/global-type").SwicoHistoryOptionType, options?: import("../../typings/global-type").NavOptionsType): void;
|
|
13
|
-
};
|
|
14
|
-
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
15
|
-
to: {
|
|
16
|
-
required: true;
|
|
17
|
-
};
|
|
18
|
-
replace: {
|
|
19
|
-
type: BooleanConstructor;
|
|
20
|
-
};
|
|
21
|
-
}>> & Readonly<{}>, {
|
|
22
|
-
replace: boolean;
|
|
23
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
24
|
-
export default _default;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vue_1 = require("vue");
|
|
4
|
-
const hooks_1 = require("./hooks");
|
|
5
|
-
exports.default = (0, vue_1.defineComponent)({
|
|
6
|
-
name: 'Link',
|
|
7
|
-
props: {
|
|
8
|
-
to: {
|
|
9
|
-
required: true
|
|
10
|
-
},
|
|
11
|
-
replace: {
|
|
12
|
-
type: Boolean
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
setup(props) {
|
|
16
|
-
const nav = (0, hooks_1.useNav)();
|
|
17
|
-
return { nav };
|
|
18
|
-
},
|
|
19
|
-
template: `<a
|
|
20
|
-
@click="
|
|
21
|
-
() => {
|
|
22
|
-
nav(to, { replace });
|
|
23
|
-
}
|
|
24
|
-
"
|
|
25
|
-
>
|
|
26
|
-
<slot></slot>
|
|
27
|
-
</a>`
|
|
28
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|