@lemon-fe/kits 1.4.15 → 1.4.16
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/es/app-provider/index.js +17 -9
- package/package.json +3 -3
package/es/app-provider/index.js
CHANGED
|
@@ -12,7 +12,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
13
|
import React, { createContext, useMemo, useContext, useCallback } from 'react';
|
|
14
14
|
import { PageLoading, message, Modal, ConfigProvider, Result, Button, RequestErrorMessage } from '@lemon-fe/components';
|
|
15
|
-
import { HooksConfigProvider } from '@lemon-fe/hooks';
|
|
15
|
+
import { HooksConfigProvider, useLatestRef } from '@lemon-fe/hooks';
|
|
16
16
|
import { isRequestError } from '@lemon-fe/utils';
|
|
17
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -33,11 +33,15 @@ export default function AppProvider(props) {
|
|
|
33
33
|
modalApi = _Modal$useModal2[0],
|
|
34
34
|
modalContextHolder = _Modal$useModal2[1];
|
|
35
35
|
var localeCtx = useContext(ConfigProvider.ConfigContext).locale;
|
|
36
|
+
|
|
37
|
+
// 这么做是因为antd设计的useMessage不合理,每次渲染都会重新创建messageApi,导致AppContext重新创建以及其他hook重新执行,这个在antd@5中应该修复了
|
|
38
|
+
var messageApiRef = useLatestRef(messageApi);
|
|
39
|
+
var modalApiRef = useLatestRef(modalApi);
|
|
36
40
|
var locale = props.locale || localeCtx;
|
|
37
41
|
var _showError = useCallback(function (err) {
|
|
38
42
|
if (isRequestError(err)) {
|
|
39
43
|
if (err.message.length > 30) {
|
|
40
|
-
|
|
44
|
+
modalApiRef.current.error({
|
|
41
45
|
title: locale === null || locale === void 0 ? void 0 : locale.Common.requestErrorTitle,
|
|
42
46
|
width: 420,
|
|
43
47
|
content: /*#__PURE__*/_jsx(RequestErrorMessage, {
|
|
@@ -45,12 +49,12 @@ export default function AppProvider(props) {
|
|
|
45
49
|
})
|
|
46
50
|
});
|
|
47
51
|
} else {
|
|
48
|
-
|
|
52
|
+
messageApiRef.current.error( /*#__PURE__*/_jsx(RequestErrorMessage, {
|
|
49
53
|
error: err
|
|
50
54
|
}));
|
|
51
55
|
}
|
|
52
56
|
} else {
|
|
53
|
-
|
|
57
|
+
messageApiRef.current.warning( /*#__PURE__*/_jsx(RequestErrorMessage, {
|
|
54
58
|
error: err
|
|
55
59
|
}));
|
|
56
60
|
}
|
|
@@ -63,16 +67,20 @@ export default function AppProvider(props) {
|
|
|
63
67
|
}, []);
|
|
64
68
|
var appContext = useMemo(function () {
|
|
65
69
|
return {
|
|
66
|
-
message
|
|
67
|
-
|
|
70
|
+
get message() {
|
|
71
|
+
return messageApiRef.current;
|
|
72
|
+
},
|
|
73
|
+
get modal() {
|
|
74
|
+
return modalApiRef.current;
|
|
75
|
+
},
|
|
68
76
|
batchOperatorConfig: batchOperatorConfig
|
|
69
77
|
};
|
|
70
|
-
}, [batchOperatorConfig
|
|
78
|
+
}, [batchOperatorConfig]);
|
|
71
79
|
var hooksConfig = useMemo(function () {
|
|
72
80
|
var result = _objectSpread({
|
|
73
81
|
showToast: function showToast() {
|
|
74
82
|
var _locale$Common;
|
|
75
|
-
return
|
|
83
|
+
return messageApiRef.current.loading(locale === null || locale === void 0 || (_locale$Common = locale.Common) === null || _locale$Common === void 0 ? void 0 : _locale$Common.waitingText, 0);
|
|
76
84
|
},
|
|
77
85
|
cancelToast: function cancelToast(hide) {
|
|
78
86
|
hide();
|
|
@@ -107,7 +115,7 @@ export default function AppProvider(props) {
|
|
|
107
115
|
}
|
|
108
116
|
}, props.hooksConfig);
|
|
109
117
|
return result;
|
|
110
|
-
}, [props.hooksConfig,
|
|
118
|
+
}, [props.hooksConfig, locale, _showError]);
|
|
111
119
|
return /*#__PURE__*/_jsxs(AppContext.Provider, {
|
|
112
120
|
value: appContext,
|
|
113
121
|
children: [messageContextHolder, modalContextHolder, /*#__PURE__*/_jsx(HooksConfigProvider, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/kits",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.16",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@ant-design/icons": "^4.7.0",
|
|
27
|
-
"@lemon-fe/components": "^1.4.
|
|
27
|
+
"@lemon-fe/components": "^1.4.16",
|
|
28
28
|
"@lemon-fe/hooks": "^1.4.15",
|
|
29
29
|
"@lemon-fe/utils": "^1.4.15",
|
|
30
30
|
"ag-grid-community": "29.2.0",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"registry": "https://registry.npmjs.org"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "07adb2db36e623c556574f37a3208e9de1da9cc7"
|
|
50
50
|
}
|