@rainbow-oh/yee-c 0.8.2 → 0.8.3
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/Input/style/index.less +1 -0
- 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/Input/style/index.less +1 -0
- 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/Input/style/index.less +1 -0
- 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,5 +1,5 @@
|
|
|
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
|
-
var _excluded = ["prefixCls", "id", "status", "title", "content", "style", "className", "icon", "duration", "closable", "showProgress", "pauseOnHover", "onClick", "onClose", "onDestroy", "data-testid"];
|
|
2
|
+
var _excluded = ["prefixCls", "id", "timerGeneration", "placement", "status", "title", "content", "style", "className", "icon", "duration", "closable", "showProgress", "pauseOnHover", "onClick", "onClose", "onDestroy", "data-testid"];
|
|
3
3
|
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); }
|
|
4
4
|
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; }
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
@@ -11,21 +11,30 @@ import { CircleAlert, CircleCheck, CircleX, Info, X } from 'lucide-react';
|
|
|
11
11
|
import React from 'react';
|
|
12
12
|
import Progress from "../Progress";
|
|
13
13
|
import useCountdown from "../hooks/useCountdown";
|
|
14
|
+
import Button from "../Button";
|
|
14
15
|
var icons = {
|
|
15
16
|
info: /*#__PURE__*/React.createElement(Info, {
|
|
16
|
-
size:
|
|
17
|
+
size: 22,
|
|
18
|
+
fill: "currentColor",
|
|
19
|
+
stroke: "#FFF",
|
|
17
20
|
strokeWidth: 2
|
|
18
21
|
}),
|
|
19
22
|
success: /*#__PURE__*/React.createElement(CircleCheck, {
|
|
20
|
-
size:
|
|
23
|
+
size: 22,
|
|
24
|
+
fill: "currentColor",
|
|
25
|
+
stroke: "#FFF",
|
|
21
26
|
strokeWidth: 2
|
|
22
27
|
}),
|
|
23
28
|
warning: /*#__PURE__*/React.createElement(CircleAlert, {
|
|
24
|
-
size:
|
|
29
|
+
size: 22,
|
|
30
|
+
fill: "currentColor",
|
|
31
|
+
stroke: "#FFF",
|
|
25
32
|
strokeWidth: 2
|
|
26
33
|
}),
|
|
27
34
|
error: /*#__PURE__*/React.createElement(CircleX, {
|
|
28
|
-
size:
|
|
35
|
+
size: 22,
|
|
36
|
+
fill: "currentColor",
|
|
37
|
+
stroke: "#FFF",
|
|
29
38
|
strokeWidth: 2
|
|
30
39
|
})
|
|
31
40
|
};
|
|
@@ -33,6 +42,8 @@ var Notice = function Notice(props) {
|
|
|
33
42
|
var _props$prefixCls = props.prefixCls,
|
|
34
43
|
prefixCls = _props$prefixCls === void 0 ? 'yee-notice' : _props$prefixCls,
|
|
35
44
|
key = props.id,
|
|
45
|
+
timerGeneration = props.timerGeneration,
|
|
46
|
+
placement = props.placement,
|
|
36
47
|
status = props.status,
|
|
37
48
|
title = props.title,
|
|
38
49
|
content = props.content,
|
|
@@ -51,26 +62,57 @@ var Notice = function Notice(props) {
|
|
|
51
62
|
onDestroy = props.onDestroy,
|
|
52
63
|
dataTestId = props['data-testid'],
|
|
53
64
|
rest = _objectWithoutProperties(props, _excluded);
|
|
65
|
+
|
|
66
|
+
// The state owner dispatches onClose after removing the notice.
|
|
67
|
+
void onClose;
|
|
68
|
+
var isHoveredRef = React.useRef(false);
|
|
54
69
|
var _useCountdown = useCountdown({
|
|
55
70
|
duration: duration,
|
|
71
|
+
resetKey: timerGeneration,
|
|
56
72
|
onComplete: function onComplete() {
|
|
57
|
-
onDestroy === null || onDestroy === void 0 || onDestroy(key);
|
|
58
|
-
onClose === null || onClose === void 0 || onClose();
|
|
73
|
+
onDestroy === null || onDestroy === void 0 || onDestroy(key, timerGeneration);
|
|
59
74
|
}
|
|
60
75
|
}),
|
|
61
76
|
remaining = _useCountdown.remaining,
|
|
77
|
+
isPaused = _useCountdown.isPaused,
|
|
62
78
|
onPause = _useCountdown.onPause,
|
|
63
79
|
onResume = _useCountdown.onResume;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
React.useEffect(function () {
|
|
81
|
+
if (pauseOnHover && isHoveredRef.current && !isPaused) {
|
|
82
|
+
onPause();
|
|
83
|
+
} else if ((!pauseOnHover || !isHoveredRef.current) && isPaused) {
|
|
84
|
+
onResume();
|
|
85
|
+
}
|
|
86
|
+
}, [isPaused, onPause, onResume, pauseOnHover]);
|
|
87
|
+
var handleMouseEnter = function handleMouseEnter() {
|
|
88
|
+
isHoveredRef.current = true;
|
|
89
|
+
if (pauseOnHover) {
|
|
90
|
+
onPause();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var handleMouseLeave = function handleMouseLeave() {
|
|
94
|
+
isHoveredRef.current = false;
|
|
95
|
+
if (isPaused) {
|
|
96
|
+
onResume();
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
var handleClose = function handleClose(event) {
|
|
100
|
+
event.stopPropagation();
|
|
101
|
+
onDestroy === null || onDestroy === void 0 || onDestroy(key, timerGeneration);
|
|
102
|
+
};
|
|
103
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
104
|
+
if (!onClick || event.key !== 'Enter' && event.key !== ' ') {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
onClick();
|
|
68
109
|
};
|
|
69
110
|
var renderIcon = function renderIcon() {
|
|
70
111
|
if (!icon && !status) {
|
|
71
112
|
return null;
|
|
72
113
|
}
|
|
73
114
|
return /*#__PURE__*/React.createElement("span", {
|
|
115
|
+
"aria-hidden": "true",
|
|
74
116
|
className: "".concat(prefixCls, "-icon")
|
|
75
117
|
}, icon ? icon : status ? icons[status] : null);
|
|
76
118
|
};
|
|
@@ -78,23 +120,33 @@ var Notice = function Notice(props) {
|
|
|
78
120
|
if (!closable) {
|
|
79
121
|
return null;
|
|
80
122
|
}
|
|
81
|
-
return /*#__PURE__*/React.createElement(
|
|
123
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
124
|
+
variant: "text",
|
|
125
|
+
size: "small",
|
|
82
126
|
className: "".concat(prefixCls, "-close"),
|
|
83
127
|
onClick: handleClose,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
128
|
+
"aria-label": "Close notice",
|
|
129
|
+
icon: /*#__PURE__*/React.createElement(X, {
|
|
130
|
+
"aria-hidden": "true",
|
|
131
|
+
size: 14,
|
|
132
|
+
strokeWidth: 2
|
|
133
|
+
})
|
|
134
|
+
});
|
|
90
135
|
};
|
|
136
|
+
var isAssertive = status === 'error' || status === 'warning';
|
|
91
137
|
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
138
|
+
"aria-atomic": "true",
|
|
139
|
+
"aria-live": isAssertive ? 'assertive' : 'polite',
|
|
140
|
+
role: onClick ? 'button' : isAssertive ? 'alert' : 'status',
|
|
141
|
+
tabIndex: onClick ? 0 : undefined,
|
|
142
|
+
"data-placement": placement,
|
|
92
143
|
"data-testid": dataTestId,
|
|
93
|
-
className: clsx(prefixCls, _defineProperty({}, "".concat(prefixCls, "-").concat(status), status), className),
|
|
144
|
+
className: clsx(prefixCls, _defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-").concat(status), status), "".concat(prefixCls, "-clickable"), onClick), "".concat(prefixCls, "-closable"), closable), className),
|
|
94
145
|
style: style,
|
|
95
146
|
onClick: onClick,
|
|
96
|
-
|
|
97
|
-
|
|
147
|
+
onKeyDown: handleKeyDown,
|
|
148
|
+
onMouseEnter: handleMouseEnter,
|
|
149
|
+
onMouseLeave: handleMouseLeave
|
|
98
150
|
}), /*#__PURE__*/React.createElement("div", {
|
|
99
151
|
className: "".concat(prefixCls, "-content-wrapper")
|
|
100
152
|
}, renderIcon(), /*#__PURE__*/React.createElement("div", {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
background-color: var(--yee-notice-bg-color);
|
|
13
13
|
border-radius: var(--yee-notice-border-radius);
|
|
14
14
|
box-shadow: var(--yee-notice-box-shadow);
|
|
15
|
-
cursor:
|
|
15
|
+
cursor: default;
|
|
16
16
|
transition: all 0.3s ease;
|
|
17
17
|
border: var(--yee-notice-border-width) solid transparent;
|
|
18
18
|
overflow: hidden;
|
|
@@ -21,6 +21,18 @@
|
|
|
21
21
|
box-shadow: var(--yee-notice-box-shadow-hover);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
&-clickable {
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&-closable {
|
|
29
|
+
@{pls}-content-wrapper {
|
|
30
|
+
padding-right: calc(
|
|
31
|
+
var(--yee-notice-close-size) + var(--yee-notice-close-right)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
&-content-wrapper {
|
|
25
37
|
display: flex;
|
|
26
38
|
align-items: flex-start;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
type PlacementType = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'top' | 'bottom';
|
|
2
|
+
import { NoticeApi } from './interface';
|
|
4
3
|
declare const useNotice: () => {
|
|
5
|
-
noticeApi:
|
|
6
|
-
open: (props: string | NoticeConfig) => void;
|
|
7
|
-
success: (props: string | NoticeConfig) => void;
|
|
8
|
-
error: (props: string | NoticeConfig) => void;
|
|
9
|
-
warning: (props: string | NoticeConfig) => void;
|
|
10
|
-
info: (props: string | NoticeConfig) => void;
|
|
11
|
-
destroy: (key: string | number) => void;
|
|
12
|
-
clear: (placement?: PlacementType) => void;
|
|
13
|
-
};
|
|
4
|
+
noticeApi: NoticeApi;
|
|
14
5
|
noticeHolders: React.ReactPortal[];
|
|
15
6
|
};
|
|
16
7
|
export default useNotice;
|
|
@@ -4,136 +4,216 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
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; }
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
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); }
|
|
7
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
-
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."); }
|
|
9
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
7
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
8
|
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."); }
|
|
13
9
|
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); }
|
|
14
10
|
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; }
|
|
15
11
|
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; } }
|
|
16
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
|
-
import React, { useCallback, useRef, useState } from 'react';
|
|
13
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
18
14
|
import { createPortal } from 'react-dom';
|
|
19
15
|
import NoticeList from "./notice-list";
|
|
16
|
+
var invokeOnClose = function invokeOnClose(notices) {
|
|
17
|
+
var errors = [];
|
|
18
|
+
notices.forEach(function (notice) {
|
|
19
|
+
try {
|
|
20
|
+
var _notice$onClose;
|
|
21
|
+
(_notice$onClose = notice.onClose) === null || _notice$onClose === void 0 || _notice$onClose.call(notice);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
errors.push(error);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
errors.forEach(function (error) {
|
|
27
|
+
var reportError = globalThis.reportError;
|
|
28
|
+
if (reportError) {
|
|
29
|
+
reportError(error);
|
|
30
|
+
} else {
|
|
31
|
+
console.error(error);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
20
35
|
var useNotice = function useNotice() {
|
|
21
36
|
var _useState = useState(new Map()),
|
|
22
37
|
_useState2 = _slicedToArray(_useState, 2),
|
|
23
38
|
noticesByPlacement = _useState2[0],
|
|
24
39
|
setNoticesByPlacement = _useState2[1];
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
var _useState3 = useState(null),
|
|
41
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
42
|
+
portalContainer = _useState4[0],
|
|
43
|
+
setPortalContainer = _useState4[1];
|
|
44
|
+
var noticesRef = useRef(new Map());
|
|
45
|
+
var generationByKey = useRef(new Map());
|
|
46
|
+
var generation = useRef(0);
|
|
47
|
+
var timerGeneration = useRef(0);
|
|
48
|
+
var autoKey = useRef(0);
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
setPortalContainer(document.body);
|
|
51
|
+
}, []);
|
|
52
|
+
var updateNotices = useCallback(function (updater) {
|
|
53
|
+
var nextNotices = updater(noticesRef.current);
|
|
54
|
+
noticesRef.current = nextNotices;
|
|
55
|
+
setNoticesByPlacement(nextNotices);
|
|
37
56
|
}, []);
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
57
|
+
var onDestroy = useCallback(function (key, expectedTimerGeneration) {
|
|
58
|
+
var _target$onClose, _target2;
|
|
59
|
+
var target;
|
|
60
|
+
noticesRef.current.forEach(function (items) {
|
|
61
|
+
var _target;
|
|
62
|
+
(_target = target) !== null && _target !== void 0 ? _target : target = items.find(function (item) {
|
|
63
|
+
return item.key === key;
|
|
44
64
|
});
|
|
45
|
-
if (filtered.length === 0) {
|
|
46
|
-
newMap.delete(placement);
|
|
47
|
-
} else {
|
|
48
|
-
newMap.set(placement, filtered);
|
|
49
|
-
}
|
|
50
|
-
return newMap;
|
|
51
65
|
});
|
|
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
|
-
|
|
66
|
+
if (!target || expectedTimerGeneration !== undefined && target.timerGeneration !== expectedTimerGeneration) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
generationByKey.current.delete(key);
|
|
70
|
+
updateNotices(function (current) {
|
|
71
|
+
var next = new Map(current);
|
|
72
|
+
next.forEach(function (items, placement) {
|
|
73
|
+
var filtered = items.filter(function (item) {
|
|
74
|
+
return item.key !== key;
|
|
75
|
+
});
|
|
76
|
+
if (filtered.length === 0) {
|
|
77
|
+
next.delete(placement);
|
|
78
|
+
} else if (filtered.length !== items.length) {
|
|
79
|
+
next.set(placement, filtered);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return next;
|
|
83
|
+
});
|
|
84
|
+
(_target$onClose = (_target2 = target).onClose) === null || _target$onClose === void 0 || _target$onClose.call(_target2);
|
|
85
|
+
}, [updateNotices]);
|
|
86
|
+
var add = useCallback(function (props) {
|
|
87
|
+
var _props$placement, _generationByKey$curr;
|
|
88
|
+
var placement = (_props$placement = props.placement) !== null && _props$placement !== void 0 ? _props$placement : 'topRight';
|
|
89
|
+
var key = props.key;
|
|
90
|
+
if (key === undefined || key === null) {
|
|
91
|
+
do {
|
|
92
|
+
key = "__yee_notice_auto_".concat(autoKey.current++);
|
|
93
|
+
} while (generationByKey.current.has(key));
|
|
94
|
+
}
|
|
95
|
+
var keyGeneration = (_generationByKey$curr = generationByKey.current.get(key)) !== null && _generationByKey$curr !== void 0 ? _generationByKey$curr : generation.current++;
|
|
96
|
+
generationByKey.current.set(key, keyGeneration);
|
|
97
|
+
var nextNotice = _objectSpread(_objectSpread({}, props), {}, {
|
|
98
|
+
key: key,
|
|
99
|
+
placement: placement,
|
|
100
|
+
timerGeneration: timerGeneration.current++
|
|
101
|
+
});
|
|
102
|
+
updateNotices(function (current) {
|
|
103
|
+
var next = new Map(current);
|
|
104
|
+
var existingIndex = -1;
|
|
105
|
+
next.forEach(function (items, currentPlacement) {
|
|
106
|
+
var index = items.findIndex(function (item) {
|
|
107
|
+
return item.key === key;
|
|
108
|
+
});
|
|
109
|
+
if (index < 0) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (currentPlacement === placement) {
|
|
113
|
+
existingIndex = index;
|
|
114
|
+
} else {
|
|
115
|
+
var filtered = items.filter(function (item) {
|
|
116
|
+
return item.key !== key;
|
|
102
117
|
});
|
|
103
118
|
if (filtered.length === 0) {
|
|
104
|
-
|
|
105
|
-
} else
|
|
106
|
-
|
|
119
|
+
next.delete(currentPlacement);
|
|
120
|
+
} else {
|
|
121
|
+
next.set(currentPlacement, filtered);
|
|
107
122
|
}
|
|
108
|
-
}
|
|
109
|
-
return newMap;
|
|
123
|
+
}
|
|
110
124
|
});
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
newMap.delete(placement);
|
|
117
|
-
return newMap;
|
|
118
|
-
});
|
|
125
|
+
var targetNotices = (next.get(placement) || []).filter(function (item) {
|
|
126
|
+
return item.key !== key;
|
|
127
|
+
});
|
|
128
|
+
if (existingIndex >= 0) {
|
|
129
|
+
targetNotices.splice(existingIndex, 0, nextNotice);
|
|
119
130
|
} else {
|
|
120
|
-
|
|
131
|
+
targetNotices.push(nextNotice);
|
|
121
132
|
}
|
|
133
|
+
next.set(placement, targetNotices);
|
|
134
|
+
return next;
|
|
135
|
+
});
|
|
136
|
+
return function () {
|
|
137
|
+
if (generationByKey.current.get(key) === keyGeneration) {
|
|
138
|
+
onDestroy(key);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}, [onDestroy, updateNotices]);
|
|
142
|
+
var clear = useCallback(function (placement) {
|
|
143
|
+
var removed = placement ? noticesRef.current.get(placement) || [] : Array.from(noticesRef.current.values()).flat();
|
|
144
|
+
removed.forEach(function (item) {
|
|
145
|
+
return generationByKey.current.delete(item.key);
|
|
146
|
+
});
|
|
147
|
+
updateNotices(function (current) {
|
|
148
|
+
if (!placement) {
|
|
149
|
+
return new Map();
|
|
150
|
+
}
|
|
151
|
+
var next = new Map(current);
|
|
152
|
+
next.delete(placement);
|
|
153
|
+
return next;
|
|
154
|
+
});
|
|
155
|
+
invokeOnClose(removed);
|
|
156
|
+
}, [updateNotices]);
|
|
157
|
+
var noticeApi = useMemo(function () {
|
|
158
|
+
return {
|
|
159
|
+
open: function open(props) {
|
|
160
|
+
return add(typeof props === 'string' ? {
|
|
161
|
+
content: props,
|
|
162
|
+
status: 'info'
|
|
163
|
+
} : _objectSpread({
|
|
164
|
+
status: 'info'
|
|
165
|
+
}, props));
|
|
166
|
+
},
|
|
167
|
+
success: function success(props) {
|
|
168
|
+
return add(typeof props === 'string' ? {
|
|
169
|
+
content: props,
|
|
170
|
+
status: 'success'
|
|
171
|
+
} : _objectSpread(_objectSpread({}, props), {}, {
|
|
172
|
+
status: 'success'
|
|
173
|
+
}));
|
|
174
|
+
},
|
|
175
|
+
error: function error(props) {
|
|
176
|
+
return add(typeof props === 'string' ? {
|
|
177
|
+
content: props,
|
|
178
|
+
status: 'error'
|
|
179
|
+
} : _objectSpread(_objectSpread({}, props), {}, {
|
|
180
|
+
status: 'error'
|
|
181
|
+
}));
|
|
182
|
+
},
|
|
183
|
+
warning: function warning(props) {
|
|
184
|
+
return add(typeof props === 'string' ? {
|
|
185
|
+
content: props,
|
|
186
|
+
status: 'warning'
|
|
187
|
+
} : _objectSpread(_objectSpread({}, props), {}, {
|
|
188
|
+
status: 'warning'
|
|
189
|
+
}));
|
|
190
|
+
},
|
|
191
|
+
info: function info(props) {
|
|
192
|
+
return add(typeof props === 'string' ? {
|
|
193
|
+
content: props,
|
|
194
|
+
status: 'info'
|
|
195
|
+
} : _objectSpread(_objectSpread({}, props), {}, {
|
|
196
|
+
status: 'info'
|
|
197
|
+
}));
|
|
198
|
+
},
|
|
199
|
+
destroy: onDestroy,
|
|
200
|
+
clear: clear
|
|
201
|
+
};
|
|
202
|
+
}, [add, clear, onDestroy]);
|
|
203
|
+
var noticeHolders = useMemo(function () {
|
|
204
|
+
if (!portalContainer) {
|
|
205
|
+
return [];
|
|
122
206
|
}
|
|
123
|
-
};
|
|
124
|
-
var noticeHolders = React.useMemo(function () {
|
|
125
207
|
var holders = [];
|
|
126
208
|
noticesByPlacement.forEach(function (notices, placement) {
|
|
127
209
|
holders.push( /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(NoticeList, {
|
|
128
210
|
items: notices,
|
|
129
211
|
placement: placement,
|
|
130
|
-
onDestroy:
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
}), document.body, "notice-".concat(placement)));
|
|
212
|
+
onDestroy: onDestroy
|
|
213
|
+
}), portalContainer, "notice-".concat(placement)));
|
|
134
214
|
});
|
|
135
215
|
return holders;
|
|
136
|
-
}, [noticesByPlacement]);
|
|
216
|
+
}, [noticesByPlacement, onDestroy, portalContainer]);
|
|
137
217
|
return {
|
|
138
218
|
noticeApi: noticeApi,
|
|
139
219
|
noticeHolders: noticeHolders
|
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
import { Root } from 'react-dom/client';
|
|
2
|
-
import { NoticeConfig, NoticeType, WrapperedNoticeConfig } from './interface';
|
|
3
|
-
type PlacementType = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'top' | 'bottom';
|
|
2
|
+
import { NoticeClose, NoticeConfig, NoticeType, PlacementType, WrapperedNoticeConfig } from './interface';
|
|
4
3
|
declare class NoticeWrapper {
|
|
5
4
|
roots: Map<PlacementType, Root>;
|
|
6
5
|
containers: Map<PlacementType, HTMLElement>;
|
|
7
6
|
notices: Map<PlacementType, NoticeType[]>;
|
|
7
|
+
generationByKey: Map<string | number, number>;
|
|
8
|
+
generation: number;
|
|
9
|
+
timerGeneration: number;
|
|
8
10
|
constructor();
|
|
9
11
|
uuid(): string;
|
|
10
12
|
private createContainer;
|
|
11
13
|
private cleanupContainer;
|
|
12
14
|
unmount(placement?: PlacementType): void;
|
|
13
15
|
render(placement: PlacementType): void;
|
|
14
|
-
show(params: WrapperedNoticeConfig):
|
|
15
|
-
destroy(key: string | number,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
show(params: WrapperedNoticeConfig): NoticeClose;
|
|
17
|
+
destroy(key: string | number, expectedTimerGeneration?: number): void;
|
|
18
|
+
clear(placement?: PlacementType): void;
|
|
19
|
+
open(params: string | NoticeConfig): NoticeClose;
|
|
20
|
+
info(params: string | NoticeConfig): NoticeClose;
|
|
21
|
+
success(params: string | NoticeConfig): NoticeClose;
|
|
22
|
+
warning(params: string | NoticeConfig): NoticeClose;
|
|
23
|
+
error(params: string | NoticeConfig): NoticeClose;
|
|
21
24
|
}
|
|
22
25
|
declare const noticeWrapper: NoticeWrapper;
|
|
23
26
|
export default noticeWrapper;
|
|
24
27
|
export declare const notice: {
|
|
25
|
-
open: (params: string | NoticeConfig) =>
|
|
26
|
-
info: (params: string | NoticeConfig) =>
|
|
27
|
-
success: (params: string | NoticeConfig) =>
|
|
28
|
-
warning: (params: string | NoticeConfig) =>
|
|
29
|
-
error: (params: string | NoticeConfig) =>
|
|
30
|
-
destroy: (key: string | number,
|
|
28
|
+
open: (params: string | NoticeConfig) => NoticeClose;
|
|
29
|
+
info: (params: string | NoticeConfig) => NoticeClose;
|
|
30
|
+
success: (params: string | NoticeConfig) => NoticeClose;
|
|
31
|
+
warning: (params: string | NoticeConfig) => NoticeClose;
|
|
32
|
+
error: (params: string | NoticeConfig) => NoticeClose;
|
|
33
|
+
destroy: (key: string | number, expectedTimerGeneration?: number) => void;
|
|
34
|
+
clear: (placement?: PlacementType) => void;
|
|
31
35
|
};
|