@fe-free/core 6.0.19 → 6.0.21
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/CHANGELOG.md +16 -0
- package/package.json +3 -3
- package/src/button/index.tsx +2 -2
- package/src/global/error.ts +6 -2
- package/src/i18n.tsx +4 -2
- package/src/route/index.tsx +40 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @fe-free/core
|
|
2
2
|
|
|
3
|
+
## 6.0.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- nextjs
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @fe-free/tool@6.0.21
|
|
10
|
+
- @fe-free/icons@6.0.21
|
|
11
|
+
|
|
12
|
+
## 6.0.20
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- @fe-free/icons@6.0.20
|
|
17
|
+
- @fe-free/tool@6.0.20
|
|
18
|
+
|
|
3
19
|
## 6.0.19
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.21",
|
|
4
4
|
"description": "React 业务核心组件库:CRUD、ProForm 扩展、布局、路由、树、上传等(Antd + ProComponents)",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"i18next-icu": "^2.4.1",
|
|
44
44
|
"react": "^19.2.0",
|
|
45
45
|
"react-i18next": "^16.4.0",
|
|
46
|
-
"@fe-free/icons": "6.0.
|
|
47
|
-
"@fe-free/tool": "6.0.
|
|
46
|
+
"@fe-free/icons": "6.0.21",
|
|
47
|
+
"@fe-free/tool": "6.0.21"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"i18n-extract": "rm -rf ./src/locales/zh-CN && npx i18next-cli extract"
|
package/src/button/index.tsx
CHANGED
|
@@ -8,13 +8,13 @@ function LoadingButton(props: ButtonProps) {
|
|
|
8
8
|
const [loading, setLoading] = useState(false);
|
|
9
9
|
|
|
10
10
|
const handleClick = useCallback(
|
|
11
|
-
(event) => {
|
|
11
|
+
(event: React.MouseEvent<HTMLElement>) => {
|
|
12
12
|
const result = onClick && onClick(event);
|
|
13
13
|
|
|
14
14
|
if (result && typeof (result as Promise<void>).then === 'function') {
|
|
15
15
|
setLoading(true);
|
|
16
16
|
|
|
17
|
-
Promise.resolve(result).finally(() => {
|
|
17
|
+
void Promise.resolve(result).finally(() => {
|
|
18
18
|
setLoading(false);
|
|
19
19
|
});
|
|
20
20
|
}
|
package/src/global/error.ts
CHANGED
|
@@ -6,9 +6,9 @@ import { AxiosError } from 'axios';
|
|
|
6
6
|
class RequestError extends Error {
|
|
7
7
|
silent: boolean | undefined;
|
|
8
8
|
status: string | undefined;
|
|
9
|
-
config: AxiosRequestConfig
|
|
9
|
+
config: AxiosRequestConfig | undefined;
|
|
10
10
|
request: XMLHttpRequest | undefined;
|
|
11
|
-
response: AxiosResponse<any
|
|
11
|
+
response: AxiosResponse<any> | undefined;
|
|
12
12
|
|
|
13
13
|
constructor(
|
|
14
14
|
message: string,
|
|
@@ -73,6 +73,10 @@ function commonHandleError(event) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function initErrorHandle(onError?: (event: ErrorEvent | PromiseRejectionEvent) => void | false) {
|
|
76
|
+
if (typeof window === 'undefined') {
|
|
77
|
+
return () => {};
|
|
78
|
+
}
|
|
79
|
+
|
|
76
80
|
const handleError = (event) => {
|
|
77
81
|
const result = onError?.(event);
|
|
78
82
|
if (result === false) {
|
package/src/i18n.tsx
CHANGED
|
@@ -72,8 +72,10 @@ function initI18n(
|
|
|
72
72
|
|
|
73
73
|
console.log('initI18n', lng, resources);
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
if (typeof window !== 'undefined') {
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
window._i18nResources = resources;
|
|
78
|
+
}
|
|
77
79
|
|
|
78
80
|
void i18n
|
|
79
81
|
.use(LanguageDetector)
|
package/src/route/index.tsx
CHANGED
|
@@ -1,28 +1,49 @@
|
|
|
1
1
|
import type { NavigateFunction } from 'react-router-dom';
|
|
2
2
|
import { generatePath } from 'react-router-dom';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type RouteToolWindow = Window & {
|
|
5
|
+
__routeTool_navigate?: NavigateFunction | null;
|
|
6
|
+
__routeTool_baseName?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function getBrowserWindow() {
|
|
10
|
+
return typeof window === 'undefined' ? null : (window as RouteToolWindow);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getGlobalNavigate() {
|
|
14
|
+
return getBrowserWindow()?.__routeTool_navigate || null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getGlobalBaseName() {
|
|
18
|
+
return getBrowserWindow()?.__routeTool_baseName || '';
|
|
19
|
+
}
|
|
6
20
|
|
|
7
21
|
const routeTool = {
|
|
8
22
|
_baseName: '' as string,
|
|
9
23
|
_navigate: null as NavigateFunction | null,
|
|
10
24
|
setNavigate: (navigate: NavigateFunction) => {
|
|
11
25
|
routeTool._navigate = navigate;
|
|
12
|
-
|
|
26
|
+
const currentWindow = getBrowserWindow();
|
|
27
|
+
if (currentWindow) {
|
|
28
|
+
currentWindow.__routeTool_navigate = navigate;
|
|
29
|
+
}
|
|
13
30
|
},
|
|
14
31
|
setBaseName: (baseName: string) => {
|
|
15
32
|
routeTool._baseName = baseName;
|
|
16
|
-
|
|
33
|
+
const currentWindow = getBrowserWindow();
|
|
34
|
+
if (currentWindow) {
|
|
35
|
+
currentWindow.__routeTool_baseName = baseName;
|
|
36
|
+
}
|
|
17
37
|
},
|
|
18
38
|
getNavigate: () => {
|
|
19
|
-
|
|
39
|
+
const navigate = routeTool._navigate || getGlobalNavigate();
|
|
40
|
+
if (!navigate) {
|
|
20
41
|
throw new Error('routeTool need set navigate first');
|
|
21
42
|
}
|
|
22
|
-
return
|
|
43
|
+
return navigate;
|
|
23
44
|
},
|
|
24
45
|
getBaseName: () => {
|
|
25
|
-
return routeTool._baseName ||
|
|
46
|
+
return routeTool._baseName || getGlobalBaseName();
|
|
26
47
|
},
|
|
27
48
|
generateUrl: ({
|
|
28
49
|
path,
|
|
@@ -37,7 +58,12 @@ const routeTool = {
|
|
|
37
58
|
return `${routeTool.getBaseName()}${generatePath(path, params)}${searchParams ? `?${sp.toString()}` : ''}`;
|
|
38
59
|
},
|
|
39
60
|
setSearchParams: (sp: Record<string, any>) => {
|
|
40
|
-
const
|
|
61
|
+
const currentWindow = getBrowserWindow();
|
|
62
|
+
if (!currentWindow) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const url = new URL(currentWindow.location.href);
|
|
41
67
|
|
|
42
68
|
const p = new URLSearchParams();
|
|
43
69
|
Object.keys(sp).forEach((key) => {
|
|
@@ -54,7 +80,12 @@ const routeTool = {
|
|
|
54
80
|
);
|
|
55
81
|
},
|
|
56
82
|
changeSearchParams: (sp: Record<string, any>) => {
|
|
57
|
-
const
|
|
83
|
+
const currentWindow = getBrowserWindow();
|
|
84
|
+
if (!currentWindow) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const url = new URL(currentWindow.location.href);
|
|
58
89
|
|
|
59
90
|
Object.keys(sp).forEach((key) => {
|
|
60
91
|
const value = sp[key];
|