@rainbow-oh/yee-c 0.8.2 → 0.8.4
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/dist/cjs/Form/form-store.js +3 -0
- package/dist/cjs/Input/style/index.less +1 -0
- package/dist/cjs/Select/interface.d.ts +1 -1
- package/dist/cjs/Selector/style/index.less +1 -0
- package/dist/cjs/Table/icon/arrow-icon.js +1 -1
- package/dist/cjs/Table/theader/cell.js +6 -3
- package/dist/cjs/TextArea/style/index.less +1 -0
- package/dist/cjs/VerificationCode/style/index.less +1 -0
- package/dist/cjs/hooks/useCountdown.d.ts +2 -1
- package/dist/cjs/hooks/useCountdown.js +46 -23
- package/dist/cjs/locale/interface.d.ts +3 -0
- package/dist/cjs/locale/lang/en_US.js +4 -1
- package/dist/cjs/locale/lang/ja_JP.js +4 -1
- package/dist/cjs/locale/lang/zh_CN.js +4 -1
- package/dist/cjs/locale/lang/zh_TW.js +4 -1
- package/dist/cjs/message/demo/base.js +1 -1
- package/dist/cjs/message/index.d.ts +1 -1
- package/dist/cjs/message/interface.d.ts +16 -7
- package/dist/cjs/message/message-provider.d.ts +2 -1
- package/dist/cjs/message/message-provider.js +1 -1
- package/dist/cjs/message/message.js +14 -9
- package/dist/cjs/message/style/index.less +3 -1
- package/dist/cjs/message/use-message.d.ts +3 -12
- package/dist/cjs/message/use-message.js +103 -45
- package/dist/cjs/message/wrapper.d.ts +21 -27
- package/dist/cjs/message/wrapper.js +49 -19
- package/dist/cjs/notice/index.d.ts +1 -1
- package/dist/cjs/notice/interface.d.ts +17 -7
- package/dist/cjs/notice/notice-list.d.ts +3 -3
- package/dist/cjs/notice/notice-provider.d.ts +2 -1
- package/dist/cjs/notice/notice-provider.js +1 -1
- package/dist/cjs/notice/notice.js +63 -20
- package/dist/cjs/notice/style/index.less +13 -1
- package/dist/cjs/notice/use-notice.d.ts +2 -11
- package/dist/cjs/notice/use-notice.js +156 -71
- package/dist/cjs/notice/wrapper.d.ts +19 -15
- package/dist/cjs/notice/wrapper.js +122 -52
- package/dist/cjs/style/size.css +3 -3
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +4 -4
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Form/form-store.js +25 -17
- package/dist/esm/Input/style/index.less +1 -0
- package/dist/esm/Select/interface.d.ts +1 -1
- package/dist/esm/Selector/style/index.less +1 -0
- package/dist/esm/Table/icon/arrow-icon.js +1 -1
- package/dist/esm/Table/theader/cell.js +7 -3
- package/dist/esm/TextArea/style/index.less +1 -0
- package/dist/esm/VerificationCode/style/index.less +1 -0
- package/dist/esm/hooks/useCountdown.d.ts +2 -1
- package/dist/esm/hooks/useCountdown.js +44 -14
- package/dist/esm/locale/interface.d.ts +3 -0
- package/dist/esm/locale/lang/en_US.js +4 -1
- package/dist/esm/locale/lang/ja_JP.js +4 -1
- package/dist/esm/locale/lang/zh_CN.js +4 -1
- package/dist/esm/locale/lang/zh_TW.js +4 -1
- package/dist/esm/message/demo/base.js +4 -1
- package/dist/esm/message/index.d.ts +1 -1
- package/dist/esm/message/interface.d.ts +16 -7
- package/dist/esm/message/message-provider.d.ts +2 -1
- package/dist/esm/message/message-provider.js +1 -1
- package/dist/esm/message/message.js +22 -9
- package/dist/esm/message/style/index.less +3 -1
- package/dist/esm/message/use-message.d.ts +3 -12
- package/dist/esm/message/use-message.js +129 -79
- package/dist/esm/message/wrapper.d.ts +21 -27
- package/dist/esm/message/wrapper.js +60 -18
- package/dist/esm/notice/index.d.ts +1 -1
- package/dist/esm/notice/interface.d.ts +17 -7
- package/dist/esm/notice/notice-list.d.ts +3 -3
- package/dist/esm/notice/notice-provider.d.ts +2 -1
- package/dist/esm/notice/notice-provider.js +1 -1
- package/dist/esm/notice/notice.js +73 -21
- package/dist/esm/notice/style/index.less +13 -1
- package/dist/esm/notice/use-notice.d.ts +2 -11
- package/dist/esm/notice/use-notice.js +180 -100
- package/dist/esm/notice/wrapper.d.ts +19 -15
- package/dist/esm/notice/wrapper.js +144 -62
- package/dist/esm/style/size.css +3 -3
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +4 -4
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +2 -2
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +1 -1
- package/src/Form/form-store.ts +5 -0
- package/src/Input/style/index.less +1 -0
- package/src/Select/interface.ts +1 -1
- package/src/Selector/style/index.less +1 -0
- package/src/Table/icon/arrow-icon.tsx +1 -1
- package/src/Table/theader/cell.tsx +6 -3
- package/src/TextArea/style/index.less +1 -0
- package/src/VerificationCode/style/index.less +1 -0
- package/src/hooks/useCountdown.ts +52 -21
- package/src/locale/interface.ts +3 -0
- package/src/locale/lang/en_US.ts +3 -0
- package/src/locale/lang/ja_JP.ts +3 -0
- package/src/locale/lang/zh_CN.ts +3 -0
- package/src/locale/lang/zh_TW.ts +3 -0
- package/src/message/demo/base.tsx +1 -1
- package/src/message/index.ts +1 -1
- package/src/message/interface.ts +22 -7
- package/src/message/message-provider.tsx +3 -2
- package/src/message/message.test.tsx +283 -0
- package/src/message/message.tsx +14 -9
- package/src/message/style/index.less +3 -1
- package/src/message/use-message.tsx +144 -67
- package/src/message/wrapper.tsx +62 -20
- package/src/notice/index.en-US.md +76 -75
- package/src/notice/index.ts +6 -1
- package/src/notice/index.zh-CN.md +3 -2
- package/src/notice/interface.ts +31 -14
- package/src/notice/notice-list.tsx +3 -9
- package/src/notice/notice-provider.tsx +3 -2
- package/src/notice/notice.test.tsx +450 -0
- package/src/notice/notice.tsx +69 -21
- package/src/notice/style/index.less +13 -1
- package/src/notice/use-notice.tsx +210 -94
- package/src/notice/wrapper.tsx +159 -71
- package/src/style/size.css +3 -3
- package/src/version.ts +1 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
3
7
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
8
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
9
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
10
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
11
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
12
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
13
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
14
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
15
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
16
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
-
import React, { useCallback, useRef, useState } from 'react';
|
|
18
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
19
19
|
import { createPortal } from 'react-dom';
|
|
20
20
|
import Message from "./message";
|
|
21
21
|
var useMessage = function useMessage() {
|
|
@@ -23,86 +23,136 @@ var useMessage = function useMessage() {
|
|
|
23
23
|
_useState2 = _slicedToArray(_useState, 2),
|
|
24
24
|
messages = _useState2[0],
|
|
25
25
|
setMessages = _useState2[1];
|
|
26
|
+
var _useState3 = useState(null),
|
|
27
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
28
|
+
portalContainer = _useState4[0],
|
|
29
|
+
setPortalContainer = _useState4[1];
|
|
30
|
+
var messagesRef = useRef([]);
|
|
31
|
+
var generationByKey = useRef(new Map());
|
|
32
|
+
var generation = useRef(0);
|
|
33
|
+
var timerGeneration = useRef(0);
|
|
26
34
|
var count = useRef(0);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
useEffect(function () {
|
|
36
|
+
setPortalContainer(document.body);
|
|
37
|
+
}, []);
|
|
38
|
+
var updateMessages = useCallback(function (updater) {
|
|
39
|
+
var nextMessages = updater(messagesRef.current);
|
|
40
|
+
messagesRef.current = nextMessages;
|
|
41
|
+
setMessages(nextMessages);
|
|
42
|
+
}, []);
|
|
43
|
+
var onDestroy = useCallback(function (key, expectedTimerGeneration) {
|
|
44
|
+
var _target$onClose;
|
|
45
|
+
var target = messagesRef.current.find(function (message) {
|
|
46
|
+
return message.key === key;
|
|
32
47
|
});
|
|
33
|
-
|
|
48
|
+
if (expectedTimerGeneration !== undefined && (target === null || target === void 0 ? void 0 : target.timerGeneration) !== expectedTimerGeneration) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!target) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
generationByKey.current.delete(key);
|
|
55
|
+
updateMessages(function (current) {
|
|
56
|
+
return current.filter(function (message) {
|
|
57
|
+
return message.key !== key;
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
(_target$onClose = target.onClose) === null || _target$onClose === void 0 || _target$onClose.call(target);
|
|
61
|
+
}, [updateMessages]);
|
|
34
62
|
var add = useCallback(function (props) {
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
63
|
+
var _props$key, _generationByKey$curr;
|
|
64
|
+
var key = (_props$key = props.key) !== null && _props$key !== void 0 ? _props$key : count.current++;
|
|
65
|
+
if (typeof key === 'number' && key >= count.current) {
|
|
66
|
+
count.current = key + 1;
|
|
67
|
+
}
|
|
68
|
+
var keyGeneration = (_generationByKey$curr = generationByKey.current.get(key)) !== null && _generationByKey$curr !== void 0 ? _generationByKey$curr : generation.current++;
|
|
69
|
+
generationByKey.current.set(key, keyGeneration);
|
|
70
|
+
var nextMessage = _objectSpread(_objectSpread({}, props), {}, {
|
|
71
|
+
key: key,
|
|
72
|
+
timerGeneration: timerGeneration.current++
|
|
73
|
+
});
|
|
74
|
+
updateMessages(function (current) {
|
|
75
|
+
var exists = current.some(function (item) {
|
|
76
|
+
return item.key === key;
|
|
77
|
+
});
|
|
78
|
+
if (exists) {
|
|
79
|
+
return current.map(function (item) {
|
|
80
|
+
return item.key === key ? nextMessage : item;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return [].concat(_toConsumableArray(current), [nextMessage]);
|
|
40
84
|
});
|
|
41
85
|
return function () {
|
|
42
|
-
|
|
86
|
+
if (generationByKey.current.get(key) === keyGeneration) {
|
|
87
|
+
onDestroy(key);
|
|
88
|
+
}
|
|
43
89
|
};
|
|
90
|
+
}, [onDestroy, updateMessages]);
|
|
91
|
+
var clear = useCallback(function () {
|
|
92
|
+
var currentMessages = messagesRef.current;
|
|
93
|
+
generationByKey.current.clear();
|
|
94
|
+
messagesRef.current = [];
|
|
95
|
+
setMessages([]);
|
|
96
|
+
currentMessages.forEach(function (message) {
|
|
97
|
+
var _message$onClose;
|
|
98
|
+
return (_message$onClose = message.onClose) === null || _message$onClose === void 0 ? void 0 : _message$onClose.call(message);
|
|
99
|
+
});
|
|
44
100
|
}, []);
|
|
45
|
-
var messageApi = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
clear: function clear() {
|
|
102
|
-
setMessages([]);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
var messageHolder = /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", {
|
|
101
|
+
var messageApi = useMemo(function () {
|
|
102
|
+
return {
|
|
103
|
+
open: function open(props) {
|
|
104
|
+
return add(typeof props === 'string' ? {
|
|
105
|
+
content: props,
|
|
106
|
+
status: 'info'
|
|
107
|
+
} : _objectSpread({
|
|
108
|
+
status: 'info'
|
|
109
|
+
}, props));
|
|
110
|
+
},
|
|
111
|
+
info: function info(props) {
|
|
112
|
+
return add(typeof props === 'string' ? {
|
|
113
|
+
content: props,
|
|
114
|
+
status: 'info'
|
|
115
|
+
} : _objectSpread({
|
|
116
|
+
status: 'info'
|
|
117
|
+
}, props));
|
|
118
|
+
},
|
|
119
|
+
success: function success(props) {
|
|
120
|
+
return add(typeof props === 'string' ? {
|
|
121
|
+
content: props,
|
|
122
|
+
status: 'success'
|
|
123
|
+
} : _objectSpread(_objectSpread({}, props), {}, {
|
|
124
|
+
status: 'success'
|
|
125
|
+
}));
|
|
126
|
+
},
|
|
127
|
+
error: function error(props) {
|
|
128
|
+
return add(typeof props === 'string' ? {
|
|
129
|
+
content: props,
|
|
130
|
+
status: 'error'
|
|
131
|
+
} : _objectSpread(_objectSpread({}, props), {}, {
|
|
132
|
+
status: 'error'
|
|
133
|
+
}));
|
|
134
|
+
},
|
|
135
|
+
warning: function warning(props) {
|
|
136
|
+
return add(typeof props === 'string' ? {
|
|
137
|
+
content: props,
|
|
138
|
+
status: 'warning'
|
|
139
|
+
} : _objectSpread(_objectSpread({}, props), {}, {
|
|
140
|
+
status: 'warning'
|
|
141
|
+
}));
|
|
142
|
+
},
|
|
143
|
+
loading: function loading(props) {
|
|
144
|
+
return add(typeof props === 'string' ? {
|
|
145
|
+
content: props,
|
|
146
|
+
status: 'loading'
|
|
147
|
+
} : _objectSpread(_objectSpread({}, props), {}, {
|
|
148
|
+
status: 'loading'
|
|
149
|
+
}));
|
|
150
|
+
},
|
|
151
|
+
destroy: onDestroy,
|
|
152
|
+
clear: clear
|
|
153
|
+
};
|
|
154
|
+
}, [add, clear, onDestroy]);
|
|
155
|
+
var messageHolder = portalContainer ? /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", {
|
|
106
156
|
className: "yee-message-list"
|
|
107
157
|
}, messages.map(function (msg) {
|
|
108
158
|
return /*#__PURE__*/React.createElement(Message, _extends({}, msg, {
|
|
@@ -110,7 +160,7 @@ var useMessage = function useMessage() {
|
|
|
110
160
|
id: msg.key,
|
|
111
161
|
key: msg.key
|
|
112
162
|
}));
|
|
113
|
-
})),
|
|
163
|
+
})), portalContainer) : null;
|
|
114
164
|
return {
|
|
115
165
|
messageApi: messageApi,
|
|
116
166
|
messageHolder: messageHolder
|
|
@@ -1,46 +1,40 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Root } from 'react-dom/client';
|
|
3
|
-
import { MessageConfig, MessageType, WrapperedMessageConfig } from './interface';
|
|
3
|
+
import { MessageClose, MessageConfig, MessageType, WrapperedMessageConfig } from './interface';
|
|
4
4
|
declare class MessageWrapper {
|
|
5
5
|
root: Root | null;
|
|
6
6
|
messages: MessageType[];
|
|
7
7
|
container: HTMLElement | null;
|
|
8
|
+
generationByKey: Map<string | number, number>;
|
|
9
|
+
generation: number;
|
|
10
|
+
timerGeneration: number;
|
|
8
11
|
constructor();
|
|
9
12
|
private createContainer;
|
|
10
13
|
private cleanupContainer;
|
|
11
14
|
uuid(): string;
|
|
12
15
|
unmount(): void;
|
|
13
16
|
render(): void;
|
|
14
|
-
show(params: WrapperedMessageConfig):
|
|
15
|
-
destroy(key: string | number): void;
|
|
16
|
-
open(params: string | MessageConfig):
|
|
17
|
-
info(params: string | MessageConfig):
|
|
18
|
-
success(params: string | MessageConfig):
|
|
19
|
-
warning(params: string | MessageConfig):
|
|
20
|
-
error(params: string | MessageConfig):
|
|
21
|
-
loading(params: string | MessageConfig):
|
|
17
|
+
show(params: WrapperedMessageConfig): MessageClose;
|
|
18
|
+
destroy(key: string | number, expectedTimerGeneration?: number): void;
|
|
19
|
+
open(params: string | MessageConfig): MessageClose;
|
|
20
|
+
info(params: string | MessageConfig): MessageClose;
|
|
21
|
+
success(params: string | MessageConfig): MessageClose;
|
|
22
|
+
warning(params: string | MessageConfig): MessageClose;
|
|
23
|
+
error(params: string | MessageConfig): MessageClose;
|
|
24
|
+
loading(params: string | MessageConfig): MessageClose;
|
|
22
25
|
}
|
|
23
26
|
declare const messageWrapper: MessageWrapper;
|
|
24
27
|
export default messageWrapper;
|
|
25
28
|
export declare const message: {
|
|
26
|
-
open: (params: string | MessageConfig) =>
|
|
27
|
-
info: (params: string | MessageConfig) =>
|
|
28
|
-
success: (params: string | MessageConfig) =>
|
|
29
|
-
warning: (params: string | MessageConfig) =>
|
|
30
|
-
error: (params: string | MessageConfig) =>
|
|
31
|
-
loading: (params: string | MessageConfig) =>
|
|
32
|
-
destroy: (key: string | number) => void;
|
|
29
|
+
open: (params: string | MessageConfig) => MessageClose;
|
|
30
|
+
info: (params: string | MessageConfig) => MessageClose;
|
|
31
|
+
success: (params: string | MessageConfig) => MessageClose;
|
|
32
|
+
warning: (params: string | MessageConfig) => MessageClose;
|
|
33
|
+
error: (params: string | MessageConfig) => MessageClose;
|
|
34
|
+
loading: (params: string | MessageConfig) => MessageClose;
|
|
35
|
+
destroy: (key: string | number, expectedTimerGeneration?: number) => void;
|
|
33
36
|
useMessage: () => {
|
|
34
|
-
messageApi:
|
|
35
|
-
|
|
36
|
-
info: (props: string | MessageConfig) => () => void;
|
|
37
|
-
success: (props: string | MessageConfig) => () => void;
|
|
38
|
-
error: (props: string | MessageConfig) => () => void;
|
|
39
|
-
warning: (props: string | MessageConfig) => () => void;
|
|
40
|
-
loading: (props: string | MessageConfig) => () => void;
|
|
41
|
-
destroy: (key: string | number) => void;
|
|
42
|
-
clear: () => void;
|
|
43
|
-
};
|
|
44
|
-
messageHolder: React.ReactPortal;
|
|
37
|
+
messageApi: import("./interface").MessageApi;
|
|
38
|
+
messageHolder: React.ReactPortal | null;
|
|
45
39
|
};
|
|
46
40
|
};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
2
8
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
9
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -11,15 +17,23 @@ import React from 'react';
|
|
|
11
17
|
import { createRoot } from 'react-dom/client';
|
|
12
18
|
import MessageList from "./message-list";
|
|
13
19
|
import useMessage from "./use-message";
|
|
20
|
+
var noop = function noop() {};
|
|
14
21
|
var MessageWrapper = /*#__PURE__*/function () {
|
|
15
22
|
function MessageWrapper() {
|
|
16
23
|
_classCallCheck(this, MessageWrapper);
|
|
17
24
|
_defineProperty(this, "root", void 0);
|
|
18
25
|
_defineProperty(this, "messages", void 0);
|
|
19
26
|
_defineProperty(this, "container", void 0);
|
|
27
|
+
_defineProperty(this, "generationByKey", void 0);
|
|
28
|
+
_defineProperty(this, "generation", void 0);
|
|
29
|
+
_defineProperty(this, "timerGeneration", void 0);
|
|
20
30
|
this.root = null;
|
|
21
31
|
this.messages = [];
|
|
22
32
|
this.container = null;
|
|
33
|
+
this.generationByKey = new Map();
|
|
34
|
+
this.generation = 0;
|
|
35
|
+
this.timerGeneration = 0;
|
|
36
|
+
this.destroy = this.destroy.bind(this);
|
|
23
37
|
}
|
|
24
38
|
_createClass(MessageWrapper, [{
|
|
25
39
|
key: "createContainer",
|
|
@@ -56,10 +70,14 @@ var MessageWrapper = /*#__PURE__*/function () {
|
|
|
56
70
|
this.root = null;
|
|
57
71
|
this.cleanupContainer();
|
|
58
72
|
this.messages = [];
|
|
73
|
+
this.generationByKey.clear();
|
|
59
74
|
}
|
|
60
75
|
}, {
|
|
61
76
|
key: "render",
|
|
62
77
|
value: function render() {
|
|
78
|
+
if (typeof document === 'undefined') {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
63
81
|
if (this.messages.length === 0) {
|
|
64
82
|
if (this.root) {
|
|
65
83
|
this.root.unmount();
|
|
@@ -74,49 +92,73 @@ var MessageWrapper = /*#__PURE__*/function () {
|
|
|
74
92
|
}
|
|
75
93
|
this.root.render( /*#__PURE__*/React.createElement(MessageList, {
|
|
76
94
|
items: this.messages,
|
|
77
|
-
onDestroy: this.destroy
|
|
95
|
+
onDestroy: this.destroy
|
|
78
96
|
}));
|
|
79
97
|
}
|
|
80
98
|
}, {
|
|
81
99
|
key: "show",
|
|
82
100
|
value: function show(params) {
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
var _params$key,
|
|
102
|
+
_this$generationByKey,
|
|
103
|
+
_this = this;
|
|
104
|
+
if (typeof document === 'undefined') {
|
|
105
|
+
return noop;
|
|
85
106
|
}
|
|
86
|
-
var
|
|
87
|
-
|
|
107
|
+
var key = (_params$key = params.key) !== null && _params$key !== void 0 ? _params$key : this.uuid();
|
|
108
|
+
var keyGeneration = (_this$generationByKey = this.generationByKey.get(key)) !== null && _this$generationByKey !== void 0 ? _this$generationByKey : this.generation++;
|
|
109
|
+
this.generationByKey.set(key, keyGeneration);
|
|
110
|
+
var nextMessage = _objectSpread(_objectSpread({}, params), {}, {
|
|
111
|
+
key: key,
|
|
112
|
+
timerGeneration: this.timerGeneration++
|
|
113
|
+
});
|
|
114
|
+
var exists = this.messages.some(function (item) {
|
|
115
|
+
return item.key === key;
|
|
88
116
|
});
|
|
89
|
-
if (
|
|
117
|
+
if (exists) {
|
|
90
118
|
this.messages = this.messages.map(function (item) {
|
|
91
|
-
|
|
92
|
-
return params;
|
|
93
|
-
}
|
|
94
|
-
return item;
|
|
119
|
+
return item.key === key ? nextMessage : item;
|
|
95
120
|
});
|
|
96
121
|
} else {
|
|
97
|
-
this.messages.
|
|
122
|
+
this.messages = [].concat(_toConsumableArray(this.messages), [nextMessage]);
|
|
98
123
|
}
|
|
99
124
|
this.render();
|
|
125
|
+
return function () {
|
|
126
|
+
if (_this.generationByKey.get(key) === keyGeneration) {
|
|
127
|
+
_this.destroy(key);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
100
130
|
}
|
|
101
131
|
}, {
|
|
102
132
|
key: "destroy",
|
|
103
|
-
value: function destroy(key) {
|
|
133
|
+
value: function destroy(key, expectedTimerGeneration) {
|
|
134
|
+
var _target$onClose;
|
|
135
|
+
var target = this.messages.find(function (item) {
|
|
136
|
+
return item.key === key;
|
|
137
|
+
});
|
|
138
|
+
if (expectedTimerGeneration !== undefined && (target === null || target === void 0 ? void 0 : target.timerGeneration) !== expectedTimerGeneration) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (!target) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
this.generationByKey.delete(key);
|
|
104
145
|
this.messages = this.messages.filter(function (item) {
|
|
105
146
|
return item.key !== key;
|
|
106
147
|
});
|
|
107
148
|
this.render();
|
|
149
|
+
(_target$onClose = target.onClose) === null || _target$onClose === void 0 || _target$onClose.call(target);
|
|
108
150
|
}
|
|
109
151
|
}, {
|
|
110
152
|
key: "open",
|
|
111
153
|
value: function open(params) {
|
|
112
|
-
this.show(typeof params === 'string' ? {
|
|
154
|
+
return this.show(typeof params === 'string' ? {
|
|
113
155
|
content: params
|
|
114
156
|
} : params);
|
|
115
157
|
}
|
|
116
158
|
}, {
|
|
117
159
|
key: "info",
|
|
118
160
|
value: function info(params) {
|
|
119
|
-
this.show(typeof params === 'string' ? {
|
|
161
|
+
return this.show(typeof params === 'string' ? {
|
|
120
162
|
status: 'info',
|
|
121
163
|
content: params
|
|
122
164
|
} : _objectSpread(_objectSpread({}, params), {}, {
|
|
@@ -126,7 +168,7 @@ var MessageWrapper = /*#__PURE__*/function () {
|
|
|
126
168
|
}, {
|
|
127
169
|
key: "success",
|
|
128
170
|
value: function success(params) {
|
|
129
|
-
this.show(typeof params === 'string' ? {
|
|
171
|
+
return this.show(typeof params === 'string' ? {
|
|
130
172
|
status: 'success',
|
|
131
173
|
content: params
|
|
132
174
|
} : _objectSpread(_objectSpread({}, params), {}, {
|
|
@@ -136,7 +178,7 @@ var MessageWrapper = /*#__PURE__*/function () {
|
|
|
136
178
|
}, {
|
|
137
179
|
key: "warning",
|
|
138
180
|
value: function warning(params) {
|
|
139
|
-
this.show(typeof params === 'string' ? {
|
|
181
|
+
return this.show(typeof params === 'string' ? {
|
|
140
182
|
status: 'warning',
|
|
141
183
|
content: params
|
|
142
184
|
} : _objectSpread(_objectSpread({}, params), {}, {
|
|
@@ -146,7 +188,7 @@ var MessageWrapper = /*#__PURE__*/function () {
|
|
|
146
188
|
}, {
|
|
147
189
|
key: "error",
|
|
148
190
|
value: function error(params) {
|
|
149
|
-
this.show(typeof params === 'string' ? {
|
|
191
|
+
return this.show(typeof params === 'string' ? {
|
|
150
192
|
status: 'error',
|
|
151
193
|
content: params
|
|
152
194
|
} : _objectSpread(_objectSpread({}, params), {}, {
|
|
@@ -156,7 +198,7 @@ var MessageWrapper = /*#__PURE__*/function () {
|
|
|
156
198
|
}, {
|
|
157
199
|
key: "loading",
|
|
158
200
|
value: function loading(params) {
|
|
159
|
-
this.show(typeof params === 'string' ? {
|
|
201
|
+
return this.show(typeof params === 'string' ? {
|
|
160
202
|
status: 'loading',
|
|
161
203
|
content: params
|
|
162
204
|
} : _objectSpread(_objectSpread({}, params), {}, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { notice } from './wrapper';
|
|
2
|
-
export type { NoticeConfig } from './interface';
|
|
2
|
+
export type { NoticeApi, NoticeClose, NoticeConfig, PlacementType, } from './interface';
|
|
3
3
|
export * from './notice-provider';
|
|
4
4
|
export { default as useNotice } from './use-notice';
|
|
5
5
|
export default notice;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
export type PlacementType = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'top' | 'bottom';
|
|
2
3
|
export type NoticeConfig = {
|
|
3
|
-
|
|
4
|
-
* test identifier
|
|
5
|
-
*/
|
|
6
|
-
'data-testid'?: string;
|
|
4
|
+
[dataAttribute: `data-${string}`]: string | number | boolean | undefined;
|
|
7
5
|
/**
|
|
8
6
|
* Custom prefix class name
|
|
9
7
|
*/
|
|
@@ -25,7 +23,7 @@ export type NoticeConfig = {
|
|
|
25
23
|
*/
|
|
26
24
|
content: React.ReactNode;
|
|
27
25
|
/**
|
|
28
|
-
* Auto close time (
|
|
26
|
+
* Auto close time (milliseconds), 0 means no auto close
|
|
29
27
|
* @default 4500
|
|
30
28
|
*/
|
|
31
29
|
duration?: number;
|
|
@@ -41,7 +39,7 @@ export type NoticeConfig = {
|
|
|
41
39
|
* Display position
|
|
42
40
|
* @default 'topRight'
|
|
43
41
|
*/
|
|
44
|
-
placement?:
|
|
42
|
+
placement?: PlacementType;
|
|
45
43
|
/**
|
|
46
44
|
* Whether to show progress bar
|
|
47
45
|
*/
|
|
@@ -64,15 +62,27 @@ export type NoticeConfig = {
|
|
|
64
62
|
*/
|
|
65
63
|
closable?: boolean;
|
|
66
64
|
};
|
|
65
|
+
export type NoticeClose = () => void;
|
|
66
|
+
export interface NoticeApi {
|
|
67
|
+
open: (config: string | NoticeConfig) => NoticeClose;
|
|
68
|
+
info: (config: string | NoticeConfig) => NoticeClose;
|
|
69
|
+
success: (config: string | NoticeConfig) => NoticeClose;
|
|
70
|
+
warning: (config: string | NoticeConfig) => NoticeClose;
|
|
71
|
+
error: (config: string | NoticeConfig) => NoticeClose;
|
|
72
|
+
destroy: (key: string | number) => void;
|
|
73
|
+
clear: (placement?: PlacementType) => void;
|
|
74
|
+
}
|
|
67
75
|
export type WrapperedNoticeConfig = NoticeConfig & {
|
|
68
76
|
status?: 'info' | 'success' | 'warning' | 'error';
|
|
69
77
|
};
|
|
70
78
|
export type NoticeType = WrapperedNoticeConfig & {
|
|
71
79
|
key: string | number;
|
|
80
|
+
placement: PlacementType;
|
|
81
|
+
timerGeneration: number;
|
|
72
82
|
};
|
|
73
83
|
export interface NoticeProps extends NoticeType {
|
|
74
84
|
/**
|
|
75
85
|
* Destroy component callback
|
|
76
86
|
*/
|
|
77
|
-
onDestroy?: (key: string | number) => void;
|
|
87
|
+
onDestroy?: (key: string | number, timerGeneration?: number) => void;
|
|
78
88
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { NoticeProps } from './interface';
|
|
2
|
+
import type { NoticeProps, PlacementType } from './interface';
|
|
3
3
|
import './style/index.less';
|
|
4
4
|
declare const NoticeList: ({ items, placement, onDestroy, }: {
|
|
5
5
|
items: NoticeProps[];
|
|
6
|
-
placement?:
|
|
7
|
-
onDestroy: (key: string | number) => void;
|
|
6
|
+
placement?: PlacementType | undefined;
|
|
7
|
+
onDestroy: (key: string | number, timerGeneration?: number) => void;
|
|
8
8
|
}) => React.JSX.Element | null;
|
|
9
9
|
export default NoticeList;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { NoticeApi } from './interface';
|
|
2
3
|
export declare function NoticeProvider({ children }: {
|
|
3
4
|
children: React.ReactNode;
|
|
4
5
|
}): React.JSX.Element;
|
|
5
|
-
export declare function useGlobalNotice():
|
|
6
|
+
export declare function useGlobalNotice(): NoticeApi;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { createContext, useContext } from 'react';
|
|
2
2
|
import useNotice from "./use-notice";
|
|
3
|
-
var NoticeContext = /*#__PURE__*/createContext(
|
|
3
|
+
var NoticeContext = /*#__PURE__*/createContext(undefined);
|
|
4
4
|
export function NoticeProvider(_ref) {
|
|
5
5
|
var children = _ref.children;
|
|
6
6
|
var _useNotice = useNotice(),
|