swico 0.7.3 → 0.8.0-beta2
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.react.d.ts +1 -1
- package/src/index.react.js +2 -1
- package/src/index.vue.d.ts +1 -1
- package/src/index.vue.js +2 -1
- package/src/mock-history.d.ts +1 -1
- package/src/template/react/$env/history.d.ts +3 -1
- package/src/template/react/$env/history.js +5 -3
- package/src/template/react/react-hooks.d.ts +2 -1
- package/src/template/react/react-hooks.js +32 -20
- package/src/template/vue/$env/history.d.ts +1 -1
- package/src/template/vue/vue-hooks.d.ts +2 -1
- package/src/template/vue/vue-hooks.js +31 -1
- package/src/{global-type.d.ts → typings/global-type.d.ts} +11 -13
- package/src/template/react/$env/router.d.ts +0 -9
- package/src/template/react/$env/router.js +0 -43
- /package/src/{global-type.js → typings/global-type.js} +0 -0
package/package.json
CHANGED
package/src/index.react.d.ts
CHANGED
|
@@ -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 } from './template/react/react-hooks';
|
|
13
|
+
export { useLocation, useNav } from './template/react/react-hooks';
|
|
14
14
|
export { history } from './mock-history';
|
|
15
15
|
export interface DefineSwicoConfigType {
|
|
16
16
|
(env: 'base', config: CustomConfigType['base']): any;
|
package/src/index.react.js
CHANGED
|
@@ -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.defineGlobal = exports.defineConfig = exports.history = exports.useLocation = exports.Outlet = exports.Link = void 0;
|
|
6
|
+
exports.defineGlobal = exports.defineConfig = exports.history = exports.useNav = exports.useLocation = exports.Outlet = exports.Link = void 0;
|
|
7
7
|
var react_router_dom_1 = require("react-router-dom");
|
|
8
8
|
var react_1 = __importDefault(require("react"));
|
|
9
9
|
var Link = function (_a) {
|
|
@@ -15,6 +15,7 @@ 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
16
|
var react_hooks_1 = require("./template/react/react-hooks");
|
|
17
17
|
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return react_hooks_1.useLocation; } });
|
|
18
|
+
Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return react_hooks_1.useNav; } });
|
|
18
19
|
var mock_history_1 = require("./mock-history");
|
|
19
20
|
Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
|
|
20
21
|
var defineConfig = function (env, config) { return config; };
|
package/src/index.vue.d.ts
CHANGED
|
@@ -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 } from './template/vue/vue-hooks';
|
|
6
|
+
export { useLocation, useNav } from './template/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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineGlobal = exports.defineConfig = exports.Link = exports.history = exports.useLocation = exports.Outlet = void 0;
|
|
3
|
+
exports.defineGlobal = exports.defineConfig = exports.Link = exports.history = exports.useNav = exports.useLocation = exports.Outlet = void 0;
|
|
4
4
|
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
8
|
var vue_hooks_1 = require("./template/vue/vue-hooks");
|
|
9
9
|
Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return vue_hooks_1.useLocation; } });
|
|
10
|
+
Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return vue_hooks_1.useNav; } });
|
|
10
11
|
var mock_history_1 = require("./mock-history");
|
|
11
12
|
Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
|
|
12
13
|
exports.Link = (0, vue_1.defineComponent)({
|
package/src/mock-history.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SwicoHistoryType } from './global-type';
|
|
1
|
+
import { SwicoHistoryType } from './typings/global-type';
|
|
2
2
|
export declare const history: SwicoHistoryType;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ConfigRouterType } from '../../../utils/config';
|
|
2
|
-
import { SwicoHistoryType } from '../../../global-type';
|
|
2
|
+
import { SwicoHistoryType } from '../../../typings/global-type';
|
|
3
3
|
export { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
|
|
4
|
+
export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
|
|
5
|
+
export declare const interpolatePath: (pathTemplate: string, params: Record<string, any>) => string;
|
|
4
6
|
export declare const formatAncPath: (ancPath: string) => string;
|
|
5
7
|
export declare const pathNameList: {
|
|
6
8
|
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.getOriHistory = exports.history = exports.pathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
|
|
6
|
+
exports.getOriHistory = exports.history = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = exports.HistoryRouter = void 0;
|
|
7
7
|
var qs_1 = __importDefault(require("qs"));
|
|
8
8
|
var history_1 = require("history");
|
|
9
9
|
var routes_1 = __importDefault(require("./routes"));
|
|
@@ -30,6 +30,7 @@ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
|
30
30
|
}
|
|
31
31
|
return true;
|
|
32
32
|
};
|
|
33
|
+
exports.compareURLPatterns = compareURLPatterns;
|
|
33
34
|
var interpolatePath = function (pathTemplate, params) {
|
|
34
35
|
var pathParts = pathTemplate.split('/');
|
|
35
36
|
var interpolatedParts = pathParts.map(function (part) {
|
|
@@ -47,6 +48,7 @@ var interpolatePath = function (pathTemplate, params) {
|
|
|
47
48
|
});
|
|
48
49
|
return interpolatedParts.join('/');
|
|
49
50
|
};
|
|
51
|
+
exports.interpolatePath = interpolatePath;
|
|
50
52
|
var interpolatePathParams = function (pathTemplate, path) {
|
|
51
53
|
var _a;
|
|
52
54
|
if (pathTemplate === void 0) { pathTemplate = ''; }
|
|
@@ -88,7 +90,7 @@ var getLocation = function (originalHistory) {
|
|
|
88
90
|
var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
|
|
89
91
|
var routerBaseLength = formatRouterBase.length;
|
|
90
92
|
var path = pathname.slice(routerBaseLength);
|
|
91
|
-
var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || compareURLPatterns(path, item.path); });
|
|
93
|
+
var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
|
|
92
94
|
var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
|
|
93
95
|
return {
|
|
94
96
|
hash: hash,
|
|
@@ -112,7 +114,7 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
|
|
|
112
114
|
}
|
|
113
115
|
if (name) {
|
|
114
116
|
var fullPath = (_a = pathList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path;
|
|
115
|
-
var targetPath = fullPath ? interpolatePath(fullPath, params) : null;
|
|
117
|
+
var targetPath = fullPath ? (0, exports.interpolatePath)(fullPath, params) : null;
|
|
116
118
|
if (targetPath) {
|
|
117
119
|
obj.pathname = "".concat(formatRouterBase).concat(targetPath);
|
|
118
120
|
}
|
|
@@ -3,35 +3,17 @@ 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.useLocation = void 0;
|
|
6
|
+
exports.useNav = exports.useLocation = void 0;
|
|
7
7
|
var react_router_dom_1 = require("react-router-dom");
|
|
8
8
|
var history_1 = require("./$env/history");
|
|
9
9
|
var qs_1 = __importDefault(require("qs"));
|
|
10
|
-
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
11
|
-
var patternWithValuesParts = urlPatternWithValues.split('/');
|
|
12
|
-
var patternWithParamsParts = urlPatternWithParams.split('/');
|
|
13
|
-
if (patternWithValuesParts.length !== patternWithParamsParts.length) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
for (var i = 0; i < patternWithValuesParts.length; i++) {
|
|
17
|
-
var valuePart = patternWithValuesParts[i];
|
|
18
|
-
var paramPart = patternWithParamsParts[i];
|
|
19
|
-
if (paramPart.startsWith(':') && paramPart !== '') {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (valuePart !== paramPart) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
};
|
|
28
10
|
var useLocation = function () {
|
|
29
11
|
var _a, _b;
|
|
30
12
|
var location = (0, react_router_dom_1.useLocation)();
|
|
31
13
|
var params = (0, react_router_dom_1.useParams)();
|
|
32
14
|
var search = location.search, hash = location.hash, pathname = location.pathname;
|
|
33
15
|
var name = (_a = history_1.pathNameList.find(function (item) {
|
|
34
|
-
return (Object.keys(params).length > 0 && compareURLPatterns(pathname, item.path)) ||
|
|
16
|
+
return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
|
|
35
17
|
item.path === pathname;
|
|
36
18
|
})) === null || _a === void 0 ? void 0 : _a.name;
|
|
37
19
|
var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
|
|
@@ -46,3 +28,33 @@ var useLocation = function () {
|
|
|
46
28
|
};
|
|
47
29
|
};
|
|
48
30
|
exports.useLocation = useLocation;
|
|
31
|
+
var getFormatNavPath = function (to) {
|
|
32
|
+
var _a;
|
|
33
|
+
var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
|
|
34
|
+
var search = query ? "?".concat(qs_1.default.stringify(query)) : '';
|
|
35
|
+
var formatHash = hash ? (hash.startsWith('#') ? hash : "#".concat(hash)) : '';
|
|
36
|
+
var formatPath = name ? (_a = history_1.pathNameList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path : path;
|
|
37
|
+
var newPath = formatPath ? (0, history_1.interpolatePath)(formatPath, params || {}) : null;
|
|
38
|
+
newPath = newPath + search + formatHash;
|
|
39
|
+
return newPath;
|
|
40
|
+
};
|
|
41
|
+
var useNav = function () {
|
|
42
|
+
var navigate = (0, react_router_dom_1.useNavigate)();
|
|
43
|
+
var newNavigate = function (to, options) {
|
|
44
|
+
switch (typeof to) {
|
|
45
|
+
case 'string':
|
|
46
|
+
navigate(to, options);
|
|
47
|
+
break;
|
|
48
|
+
case 'number':
|
|
49
|
+
navigate(to);
|
|
50
|
+
break;
|
|
51
|
+
case 'object':
|
|
52
|
+
navigate(getFormatNavPath(to), options);
|
|
53
|
+
break;
|
|
54
|
+
default:
|
|
55
|
+
throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return newNavigate;
|
|
59
|
+
};
|
|
60
|
+
exports.useNav = useNav;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { UseLocationType } from '../../global-type';
|
|
1
|
+
import { UseLocationType, UseNavType } from '../../typings/global-type';
|
|
2
2
|
export declare const getFormatRouterBase: (routerBase: any) => any;
|
|
3
3
|
export declare const useLocation: UseLocationType;
|
|
4
|
+
export declare const useNav: UseNavType;
|
|
@@ -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.useLocation = exports.getFormatRouterBase = void 0;
|
|
6
|
+
exports.useNav = exports.useLocation = exports.getFormatRouterBase = void 0;
|
|
7
7
|
var vue_router_1 = require("vue-router");
|
|
8
8
|
var qs_1 = __importDefault(require("qs"));
|
|
9
9
|
var vue_1 = require("vue");
|
|
@@ -38,3 +38,33 @@ var useLocation = function () {
|
|
|
38
38
|
return location;
|
|
39
39
|
};
|
|
40
40
|
exports.useLocation = useLocation;
|
|
41
|
+
var useNav = function () {
|
|
42
|
+
var router = (0, vue_router_1.useRouter)();
|
|
43
|
+
var newNavigate = function (to, options) {
|
|
44
|
+
switch (typeof to) {
|
|
45
|
+
case 'string':
|
|
46
|
+
if (options.replace) {
|
|
47
|
+
router.replace(to);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
router.push(to);
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case 'number':
|
|
54
|
+
router.go(to);
|
|
55
|
+
break;
|
|
56
|
+
case 'object':
|
|
57
|
+
if (options.replace) {
|
|
58
|
+
router.replace(to);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
router.push(to);
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return newNavigate;
|
|
69
|
+
};
|
|
70
|
+
exports.useNav = useNav;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export type SwicoLocationType = {
|
|
2
|
+
query?: Record<string, any>;
|
|
3
|
+
params?: Record<string, any>;
|
|
4
|
+
hash: string;
|
|
2
5
|
name: string;
|
|
3
6
|
path: string;
|
|
4
7
|
pathname: string;
|
|
5
8
|
search: string;
|
|
6
|
-
query?: Record<string, any>;
|
|
7
|
-
hash: string;
|
|
8
|
-
params?: Record<string, any>;
|
|
9
9
|
};
|
|
10
10
|
export type SwicoHistoryOptionType = {
|
|
11
11
|
query?: Record<string, any>;
|
|
@@ -22,14 +22,12 @@ export type SwicoHistoryType = {
|
|
|
22
22
|
back: () => void;
|
|
23
23
|
location: SwicoLocationType;
|
|
24
24
|
};
|
|
25
|
-
export type UseLocationType =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
params?: Record<string, any>;
|
|
34
|
-
};
|
|
25
|
+
export type UseLocationType = () => SwicoLocationType;
|
|
26
|
+
export type NavOptionsType = {
|
|
27
|
+
replace: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type UseNavType = () => {
|
|
30
|
+
(to: string, options?: NavOptionsType): void;
|
|
31
|
+
(to: number): void;
|
|
32
|
+
(to: SwicoHistoryOptionType, options?: NavOptionsType): void;
|
|
35
33
|
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
import type { History } from '@remix-run/router';
|
|
3
|
-
interface PropsType {
|
|
4
|
-
basename?: string;
|
|
5
|
-
children: ReactNode;
|
|
6
|
-
history: History;
|
|
7
|
-
}
|
|
8
|
-
declare const HistoryRouter: React.FC<PropsType>;
|
|
9
|
-
export default HistoryRouter;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
var react_1 = __importStar(require("react"));
|
|
27
|
-
var react_router_dom_1 = require("react-router-dom");
|
|
28
|
-
var HistoryRouter = function (props) {
|
|
29
|
-
var basename = props.basename, children = props.children, history = props.history;
|
|
30
|
-
var _a = (0, react_1.useState)({
|
|
31
|
-
action: history.action,
|
|
32
|
-
location: history.location
|
|
33
|
-
}), state = _a[0], setState = _a[1];
|
|
34
|
-
react_1.default.useLayoutEffect(function () { return history.listen(setState); }, [history]);
|
|
35
|
-
return react_1.default.createElement(react_router_dom_1.Router, {
|
|
36
|
-
basename: basename,
|
|
37
|
-
children: children,
|
|
38
|
-
location: state.location,
|
|
39
|
-
navigationType: state.action,
|
|
40
|
-
navigator: history
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
exports.default = HistoryRouter;
|
|
File without changes
|