rsuite 5.76.0 → 5.76.2
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 +18 -0
- package/cjs/CustomProvider/CustomProvider.d.ts +13 -15
- package/cjs/CustomProvider/CustomProvider.js +6 -4
- package/cjs/internals/utils/index.d.ts +0 -1
- package/cjs/internals/utils/index.js +1 -4
- package/cjs/toaster/ToastContainer.d.ts +6 -6
- package/cjs/toaster/ToastContainer.js +52 -39
- package/cjs/toaster/render.d.ts +3 -0
- package/cjs/toaster/render.js +43 -0
- package/cjs/toaster/toaster.js +34 -20
- package/cjs/useToaster/useToaster.js +10 -5
- package/dist/rsuite.js +18 -18
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/CustomProvider/CustomProvider.d.ts +13 -15
- package/esm/CustomProvider/CustomProvider.js +7 -5
- package/esm/internals/utils/index.d.ts +0 -1
- package/esm/internals/utils/index.js +0 -1
- package/esm/toaster/ToastContainer.d.ts +6 -6
- package/esm/toaster/ToastContainer.js +53 -40
- package/esm/toaster/render.d.ts +3 -0
- package/esm/toaster/render.js +35 -0
- package/esm/toaster/toaster.js +32 -20
- package/esm/useToaster/useToaster.js +10 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [5.76.2](https://github.com/rsuite/rsuite/compare/v5.76.1...v5.76.2) (2025-01-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **ToastContainer:** fix the server-side rendering error ([#4099](https://github.com/rsuite/rsuite/issues/4099)) ([e5113a2](https://github.com/rsuite/rsuite/commit/e5113a2478fce93ea45353c8e808c0691eed02ee))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [5.76.1](https://github.com/rsuite/rsuite/compare/v5.76.0...v5.76.1) (2024-12-30)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **useToaster:** support dynamic container of useToaster with correct styles ([#4088](https://github.com/rsuite/rsuite/issues/4088)) ([62b1a12](https://github.com/rsuite/rsuite/commit/62b1a128bd0f68ddc22a5b0f1acf27c5bc56a69e))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
1
19
|
# [5.76.0](https://github.com/rsuite/rsuite/compare/v5.75.0...v5.76.0) (2024-12-20)
|
|
2
20
|
|
|
3
21
|
|
|
@@ -142,9 +142,7 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
|
|
|
142
142
|
formattedMonthPattern: string;
|
|
143
143
|
formattedDayPattern: string;
|
|
144
144
|
shortDateFormat: string;
|
|
145
|
-
shortTimeFormat: string;
|
|
146
|
-
* The prefix of the component CSS class
|
|
147
|
-
*/
|
|
145
|
+
shortTimeFormat: string;
|
|
148
146
|
dateLocale: any;
|
|
149
147
|
} | undefined;
|
|
150
148
|
Calendar?: {
|
|
@@ -165,9 +163,7 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
|
|
|
165
163
|
formattedMonthPattern: string;
|
|
166
164
|
formattedDayPattern: string;
|
|
167
165
|
shortDateFormat: string;
|
|
168
|
-
shortTimeFormat: string;
|
|
169
|
-
* The prefix of the component CSS class
|
|
170
|
-
*/
|
|
166
|
+
shortTimeFormat: string;
|
|
171
167
|
dateLocale: any;
|
|
172
168
|
} | undefined;
|
|
173
169
|
DatePicker?: {
|
|
@@ -188,9 +184,7 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
|
|
|
188
184
|
formattedMonthPattern: string;
|
|
189
185
|
formattedDayPattern: string;
|
|
190
186
|
shortDateFormat: string;
|
|
191
|
-
shortTimeFormat: string;
|
|
192
|
-
* The prefix of the component CSS class
|
|
193
|
-
*/
|
|
187
|
+
shortTimeFormat: string;
|
|
194
188
|
dateLocale: any;
|
|
195
189
|
} | undefined;
|
|
196
190
|
DateRangePicker?: {
|
|
@@ -212,14 +206,14 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
|
|
|
212
206
|
formattedMonthPattern: string;
|
|
213
207
|
formattedDayPattern: string;
|
|
214
208
|
shortDateFormat: string;
|
|
215
|
-
shortTimeFormat: string;
|
|
216
|
-
* The prefix of the component CSS class
|
|
217
|
-
*/
|
|
209
|
+
shortTimeFormat: string;
|
|
218
210
|
dateLocale: any;
|
|
219
211
|
} | undefined;
|
|
220
212
|
Combobox?: {
|
|
221
213
|
noResultsText: string;
|
|
222
|
-
placeholder: string;
|
|
214
|
+
placeholder: string; /**
|
|
215
|
+
* The locale object that contains the language and formatting rules for the date.
|
|
216
|
+
*/
|
|
223
217
|
searchPlaceholder: string;
|
|
224
218
|
checkAll: string;
|
|
225
219
|
} | undefined;
|
|
@@ -227,7 +221,9 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
|
|
|
227
221
|
newItem: string;
|
|
228
222
|
createOption: string;
|
|
229
223
|
noResultsText: string;
|
|
230
|
-
placeholder: string;
|
|
224
|
+
placeholder: string; /**
|
|
225
|
+
* The locale object that contains the language and formatting rules for the date.
|
|
226
|
+
*/
|
|
231
227
|
searchPlaceholder: string;
|
|
232
228
|
checkAll: string;
|
|
233
229
|
} | undefined;
|
|
@@ -235,7 +231,9 @@ export declare const CustomContext: React.Context<CustomProviderProps<{
|
|
|
235
231
|
newItem: string;
|
|
236
232
|
createOption: string;
|
|
237
233
|
noResultsText: string;
|
|
238
|
-
placeholder: string;
|
|
234
|
+
placeholder: string; /**
|
|
235
|
+
* The locale object that contains the language and formatting rules for the date.
|
|
236
|
+
*/
|
|
239
237
|
searchPlaceholder: string;
|
|
240
238
|
checkAll: string;
|
|
241
239
|
} | undefined;
|
|
@@ -32,14 +32,15 @@ function CustomProvider(props) {
|
|
|
32
32
|
_props$iconClassPrefi = props.iconClassPrefix,
|
|
33
33
|
iconClassPrefix = _props$iconClassPrefi === void 0 ? classPrefix : _props$iconClassPrefi,
|
|
34
34
|
theme = props.theme,
|
|
35
|
-
|
|
35
|
+
_props$toastContainer = props.toastContainer,
|
|
36
|
+
toastContainer = _props$toastContainer === void 0 ? _ToastContainer.defaultToasterContainer : _props$toastContainer,
|
|
36
37
|
disableRipple = props.disableRipple,
|
|
37
38
|
csp = props.csp,
|
|
38
39
|
disableInlineStyles = props.disableInlineStyles,
|
|
39
40
|
rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
40
41
|
var toasters = (0, _react.useRef)(new Map());
|
|
41
42
|
var _usePortal = (0, _hooks.usePortal)({
|
|
42
|
-
container:
|
|
43
|
+
container: toastContainer,
|
|
43
44
|
waitMount: true
|
|
44
45
|
}),
|
|
45
46
|
Portal = _usePortal.Portal;
|
|
@@ -49,9 +50,10 @@ function CustomProvider(props) {
|
|
|
49
50
|
theme: theme,
|
|
50
51
|
toasters: toasters,
|
|
51
52
|
disableRipple: disableRipple,
|
|
52
|
-
components: components
|
|
53
|
+
components: components,
|
|
54
|
+
toastContainer: toastContainer
|
|
53
55
|
}, rest);
|
|
54
|
-
}, [classPrefix, theme, disableRipple, components, rest]);
|
|
56
|
+
}, [classPrefix, theme, disableRipple, components, toastContainer, rest]);
|
|
55
57
|
var iconContext = (0, _react.useMemo)(function () {
|
|
56
58
|
return {
|
|
57
59
|
classPrefix: iconClassPrefix,
|
|
@@ -13,7 +13,6 @@ export { placementPolyfill } from './placementPolyfill';
|
|
|
13
13
|
export { mergeRefs } from './mergeRefs';
|
|
14
14
|
export { shallowEqual, shallowEqualArray } from './shallowEqual';
|
|
15
15
|
export { composeFunctions } from './composeFunctions';
|
|
16
|
-
export { render } from './render';
|
|
17
16
|
export { safeSetSelection } from './safeSetSelection';
|
|
18
17
|
export { getStringLength } from './getStringLength';
|
|
19
18
|
export { getDataGroupBy } from './getDataGroupBy';
|
|
@@ -20,7 +20,6 @@ var _exportNames = {
|
|
|
20
20
|
shallowEqual: true,
|
|
21
21
|
shallowEqualArray: true,
|
|
22
22
|
composeFunctions: true,
|
|
23
|
-
render: true,
|
|
24
23
|
safeSetSelection: true,
|
|
25
24
|
getStringLength: true,
|
|
26
25
|
getDataGroupBy: true,
|
|
@@ -32,7 +31,7 @@ var _exportNames = {
|
|
|
32
31
|
isFocusLeaving: true,
|
|
33
32
|
isFocusableElement: true
|
|
34
33
|
};
|
|
35
|
-
exports.warnOnce = exports.tplTransform = exports.stringifyReactNode = exports.shallowEqualArray = exports.shallowEqual = exports.safeSetSelection = exports.
|
|
34
|
+
exports.warnOnce = exports.tplTransform = exports.stringifyReactNode = exports.shallowEqualArray = exports.shallowEqual = exports.safeSetSelection = exports.reactToString = exports.prefix = exports.placementPolyfill = exports.mergeRefs = exports.isOneOf = exports.isFocusableElement = exports.isFocusLeaving = exports.isFocusEntering = exports.guid = exports.getStringLength = exports.getSafeRegExpString = exports.getDataGroupBy = exports.getDOMNode = exports.getClassNamePrefix = exports.deprecateComponent = exports.defaultClassPrefix = exports.createComponent = exports.createChainedFunction = exports.composeFunctions = exports.attachParent = exports.ReactChildren = void 0;
|
|
36
35
|
var _BrowserDetection = require("./BrowserDetection");
|
|
37
36
|
Object.keys(_BrowserDetection).forEach(function (key) {
|
|
38
37
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -77,8 +76,6 @@ exports.shallowEqual = _shallowEqual.shallowEqual;
|
|
|
77
76
|
exports.shallowEqualArray = _shallowEqual.shallowEqualArray;
|
|
78
77
|
var _composeFunctions = require("./composeFunctions");
|
|
79
78
|
exports.composeFunctions = _composeFunctions.composeFunctions;
|
|
80
|
-
var _render = require("./render");
|
|
81
|
-
exports.render = _render.render;
|
|
82
79
|
var _safeSetSelection = require("./safeSetSelection");
|
|
83
80
|
exports.safeSetSelection = _safeSetSelection.safeSetSelection;
|
|
84
81
|
var _getStringLength = require("./getStringLength");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { WithAsProps, RsRefForwardingComponent } from '../internals/types';
|
|
3
|
+
export declare const defaultToasterContainer: () => HTMLElement | null;
|
|
3
4
|
export type PlacementType = 'topCenter' | 'bottomCenter' | 'topStart' | 'topEnd' | 'bottomStart' | 'bottomEnd';
|
|
4
5
|
export declare const toastPlacements: PlacementType[];
|
|
5
6
|
export interface ToastContainerProps extends WithAsProps {
|
|
@@ -21,10 +22,6 @@ export interface ToastContainerProps extends WithAsProps {
|
|
|
21
22
|
* Reset the hide timer if the mouse moves over the message.
|
|
22
23
|
*/
|
|
23
24
|
mouseReset?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Callback fired when the component mounts
|
|
26
|
-
*/
|
|
27
|
-
callback?: (ref: React.RefObject<ToastContainerInstance>) => void;
|
|
28
25
|
}
|
|
29
26
|
interface PushOptions {
|
|
30
27
|
duration?: number;
|
|
@@ -32,7 +29,6 @@ interface PushOptions {
|
|
|
32
29
|
container?: HTMLElement | (() => HTMLElement);
|
|
33
30
|
}
|
|
34
31
|
export interface ToastContainerInstance {
|
|
35
|
-
root: HTMLElement;
|
|
36
32
|
push: (message: React.ReactNode, options?: PushOptions) => string;
|
|
37
33
|
remove: (key: string) => void;
|
|
38
34
|
clear: () => void;
|
|
@@ -41,8 +37,12 @@ export interface ToastContainerInstance {
|
|
|
41
37
|
export interface NodeProps extends WithAsProps {
|
|
42
38
|
onClose?: (event?: React.MouseEvent<HTMLDivElement>) => void;
|
|
43
39
|
}
|
|
40
|
+
export type GetInstancePropsType = Omit<ToastContainerProps, 'container' | 'placement'> & {
|
|
41
|
+
container: HTMLElement | null;
|
|
42
|
+
placement: PlacementType;
|
|
43
|
+
};
|
|
44
44
|
interface ToastContainerComponent extends RsRefForwardingComponent<'div', ToastContainerProps> {
|
|
45
|
-
getInstance: (props:
|
|
45
|
+
getInstance: (props: GetInstancePropsType) => Promise<[React.RefObject<ToastContainerInstance>, string]>;
|
|
46
46
|
}
|
|
47
47
|
declare const ToastContainer: ToastContainerComponent;
|
|
48
48
|
export default ToastContainer;
|
|
@@ -3,22 +3,28 @@
|
|
|
3
3
|
|
|
4
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
5
|
exports.__esModule = true;
|
|
6
|
-
exports.toastPlacements = exports.default = void 0;
|
|
6
|
+
exports.toastPlacements = exports.defaultToasterContainer = exports.default = void 0;
|
|
7
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
8
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
7
9
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
8
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _reactDom = require("react-dom");
|
|
11
12
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
12
13
|
var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
|
|
13
14
|
var _Transition = _interopRequireDefault(require("../Animation/Transition"));
|
|
15
|
+
var _ToastContext = _interopRequireDefault(require("./ToastContext"));
|
|
16
|
+
var _canUseDOM = _interopRequireDefault(require("dom-lib/canUseDOM"));
|
|
14
17
|
var _hooks = require("../internals/hooks");
|
|
15
18
|
var _utils = require("../internals/utils");
|
|
16
|
-
var
|
|
17
|
-
var _excluded = ["as", "className", "classPrefix", "placement"
|
|
19
|
+
var _render = require("./render");
|
|
20
|
+
var _excluded = ["as", "className", "classPrefix", "placement"],
|
|
18
21
|
_excluded2 = ["className"],
|
|
19
22
|
_excluded3 = ["container"];
|
|
20
23
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
21
24
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
25
|
+
var defaultToasterContainer = exports.defaultToasterContainer = function defaultToasterContainer() {
|
|
26
|
+
return _canUseDOM.default ? document.body : null;
|
|
27
|
+
};
|
|
22
28
|
var toastPlacements = exports.toastPlacements = ['topCenter', 'bottomCenter', 'topStart', 'topEnd', 'bottomStart', 'bottomEnd'];
|
|
23
29
|
var useMessages = function useMessages() {
|
|
24
30
|
var _useState = (0, _react.useState)([]),
|
|
@@ -87,7 +93,6 @@ var useMessages = function useMessages() {
|
|
|
87
93
|
};
|
|
88
94
|
};
|
|
89
95
|
var ToastContainer = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
90
|
-
var rootRef = (0, _react.useRef)();
|
|
91
96
|
var _props$as = props.as,
|
|
92
97
|
Component = _props$as === void 0 ? 'div' : _props$as,
|
|
93
98
|
className = props.className,
|
|
@@ -95,7 +100,6 @@ var ToastContainer = /*#__PURE__*/_react.default.forwardRef(function (props, ref
|
|
|
95
100
|
classPrefix = _props$classPrefix === void 0 ? 'toast-container' : _props$classPrefix,
|
|
96
101
|
_props$placement = props.placement,
|
|
97
102
|
placement = _props$placement === void 0 ? 'topCenter' : _props$placement,
|
|
98
|
-
callback = props.callback,
|
|
99
103
|
rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
100
104
|
var _useClassNames = (0, _hooks.useClassNames)(classPrefix),
|
|
101
105
|
withClassPrefix = _useClassNames.withClassPrefix,
|
|
@@ -109,7 +113,6 @@ var ToastContainer = /*#__PURE__*/_react.default.forwardRef(function (props, ref
|
|
|
109
113
|
messages = _useMessages.messages;
|
|
110
114
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
111
115
|
return {
|
|
112
|
-
root: rootRef.current,
|
|
113
116
|
push: push,
|
|
114
117
|
clear: clear,
|
|
115
118
|
remove: remove
|
|
@@ -118,9 +121,15 @@ var ToastContainer = /*#__PURE__*/_react.default.forwardRef(function (props, ref
|
|
|
118
121
|
var elements = messages.map(function (item) {
|
|
119
122
|
var mouseReset = item.mouseReset,
|
|
120
123
|
duration = item.duration,
|
|
121
|
-
node = item.node
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
node = item.node;
|
|
125
|
+
return /*#__PURE__*/_react.default.createElement(_ToastContext.default.Provider, {
|
|
126
|
+
value: {
|
|
127
|
+
usedToaster: true,
|
|
128
|
+
mouseReset: mouseReset,
|
|
129
|
+
duration: duration
|
|
130
|
+
},
|
|
131
|
+
key: item.key
|
|
132
|
+
}, /*#__PURE__*/_react.default.createElement(_Transition.default, {
|
|
124
133
|
in: item.visible,
|
|
125
134
|
exitedClassName: rootPrefix('toast-fade-exited'),
|
|
126
135
|
exitingClassName: rootPrefix('toast-fade-exiting'),
|
|
@@ -139,40 +148,44 @@ var ToastContainer = /*#__PURE__*/_react.default.forwardRef(function (props, ref
|
|
|
139
148
|
}),
|
|
140
149
|
className: merge(rootPrefix('toast'), (_node$props2 = node.props) === null || _node$props2 === void 0 ? void 0 : _node$props2.className, transitionClassName)
|
|
141
150
|
}));
|
|
142
|
-
});
|
|
143
|
-
return /*#__PURE__*/_react.default.createElement(_ToastContext.default.Provider, {
|
|
144
|
-
value: {
|
|
145
|
-
usedToaster: true,
|
|
146
|
-
mouseReset: mouseReset,
|
|
147
|
-
duration: duration
|
|
148
|
-
},
|
|
149
|
-
key: item.key
|
|
150
|
-
}, container ? /*#__PURE__*/(0, _reactDom.createPortal)(toastWithTransition, typeof container === 'function' ? container() : container) : toastWithTransition);
|
|
151
|
+
}));
|
|
151
152
|
});
|
|
152
153
|
return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({}, rest, {
|
|
153
|
-
ref: function ref(selfRef) {
|
|
154
|
-
rootRef.current = selfRef;
|
|
155
|
-
callback === null || callback === void 0 || callback(selfRef);
|
|
156
|
-
},
|
|
157
154
|
className: classes
|
|
158
155
|
}), elements);
|
|
159
156
|
});
|
|
160
|
-
ToastContainer.getInstance = function (
|
|
161
|
-
var
|
|
162
|
-
rest
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
157
|
+
ToastContainer.getInstance = /*#__PURE__*/function () {
|
|
158
|
+
var _ref2 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(props) {
|
|
159
|
+
var container, rest, getRefResolve, getRefPromise, containerRef, containerId;
|
|
160
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
161
|
+
while (1) switch (_context.prev = _context.next) {
|
|
162
|
+
case 0:
|
|
163
|
+
container = props.container, rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded3);
|
|
164
|
+
getRefResolve = null;
|
|
165
|
+
getRefPromise = new Promise(function (res) {
|
|
166
|
+
getRefResolve = res;
|
|
167
|
+
});
|
|
168
|
+
containerRef = /*#__PURE__*/_react.default.createRef(); // promise containerId & containerRef all have value
|
|
169
|
+
containerId = (0, _render.render)(/*#__PURE__*/_react.default.createElement(ToastContainer, (0, _extends2.default)({}, rest, {
|
|
170
|
+
ref: function ref(_ref3) {
|
|
171
|
+
containerRef.current = _ref3;
|
|
172
|
+
getRefResolve && getRefResolve();
|
|
173
|
+
}
|
|
174
|
+
})), container);
|
|
175
|
+
_context.next = 7;
|
|
176
|
+
return getRefPromise;
|
|
177
|
+
case 7:
|
|
178
|
+
return _context.abrupt("return", [containerRef, containerId]);
|
|
179
|
+
case 8:
|
|
180
|
+
case "end":
|
|
181
|
+
return _context.stop();
|
|
182
|
+
}
|
|
183
|
+
}, _callee);
|
|
184
|
+
}));
|
|
185
|
+
return function (_x) {
|
|
186
|
+
return _ref2.apply(this, arguments);
|
|
187
|
+
};
|
|
188
|
+
}();
|
|
176
189
|
ToastContainer.displayName = 'ToastContainer';
|
|
177
190
|
ToastContainer.propTypes = {
|
|
178
191
|
className: _propTypes.default.string,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.render = render;
|
|
7
|
+
exports.toasterKeyOfContainerElement = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _utils = require("../internals/utils");
|
|
10
|
+
var ReactDOM = _interopRequireWildcard(require("react-dom"));
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
var majorVersion = parseInt(_react.default.version);
|
|
14
|
+
var SuperposedReactDOM = ReactDOM;
|
|
15
|
+
var toasterKeyOfContainerElement = exports.toasterKeyOfContainerElement = 'toasterId';
|
|
16
|
+
function render(element, container) {
|
|
17
|
+
var mountElement = document.createElement('div');
|
|
18
|
+
mountElement.className = 'rs-toaster-mount-element';
|
|
19
|
+
var containerElement = container;
|
|
20
|
+
|
|
21
|
+
// Add the detached element to the root
|
|
22
|
+
containerElement.appendChild(mountElement);
|
|
23
|
+
var newContainerId = (0, _utils.guid)();
|
|
24
|
+
if (!containerElement[toasterKeyOfContainerElement]) {
|
|
25
|
+
// attach the containerId to the containerElement
|
|
26
|
+
containerElement[toasterKeyOfContainerElement] = newContainerId;
|
|
27
|
+
}
|
|
28
|
+
if (majorVersion >= 18) {
|
|
29
|
+
/**
|
|
30
|
+
* ignore react 18 warnings
|
|
31
|
+
* Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client".
|
|
32
|
+
*/
|
|
33
|
+
ReactDOM['__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED'].usingClientEntryPoint = true;
|
|
34
|
+
var createRoot = SuperposedReactDOM.createRoot;
|
|
35
|
+
var root = createRoot(mountElement, {
|
|
36
|
+
identifierPrefix: 'rs-root-'
|
|
37
|
+
});
|
|
38
|
+
root.render(element);
|
|
39
|
+
} else {
|
|
40
|
+
SuperposedReactDOM.render(element, mountElement);
|
|
41
|
+
}
|
|
42
|
+
return containerElement[toasterKeyOfContainerElement];
|
|
43
|
+
}
|
package/cjs/toaster/toaster.js
CHANGED
|
@@ -5,17 +5,20 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
8
9
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
9
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
var _ToastContainer =
|
|
11
|
-
var
|
|
12
|
-
var
|
|
11
|
+
var _ToastContainer = _interopRequireWildcard(require("./ToastContainer"));
|
|
12
|
+
var _render = require("./render");
|
|
13
|
+
var _excluded = ["placement", "container"];
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
16
|
var containers = new Map();
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
|
-
* Create a container
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
+
* Create a container instance.
|
|
20
|
+
* @param placement
|
|
21
|
+
* @param props
|
|
19
22
|
*/
|
|
20
23
|
function createContainer(_x, _x2) {
|
|
21
24
|
return _createContainer.apply(this, arguments);
|
|
@@ -23,10 +26,11 @@ function createContainer(_x, _x2) {
|
|
|
23
26
|
/**
|
|
24
27
|
* Get the container by ID. Use default ID when ID is not available.
|
|
25
28
|
* @param containerId
|
|
29
|
+
* @param placement
|
|
26
30
|
*/
|
|
27
31
|
function _createContainer() {
|
|
28
|
-
_createContainer = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(
|
|
29
|
-
var _yield$ToastContainer, container;
|
|
32
|
+
_createContainer = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(placement, props) {
|
|
33
|
+
var _yield$ToastContainer, container, containerId;
|
|
30
34
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
31
35
|
while (1) switch (_context.prev = _context.next) {
|
|
32
36
|
case 0:
|
|
@@ -35,9 +39,10 @@ function _createContainer() {
|
|
|
35
39
|
case 2:
|
|
36
40
|
_yield$ToastContainer = _context.sent;
|
|
37
41
|
container = _yield$ToastContainer[0];
|
|
38
|
-
|
|
42
|
+
containerId = _yield$ToastContainer[1];
|
|
43
|
+
containers.set(containerId + "_" + placement, container);
|
|
39
44
|
return _context.abrupt("return", container);
|
|
40
|
-
case
|
|
45
|
+
case 7:
|
|
41
46
|
case "end":
|
|
42
47
|
return _context.stop();
|
|
43
48
|
}
|
|
@@ -45,11 +50,8 @@ function _createContainer() {
|
|
|
45
50
|
}));
|
|
46
51
|
return _createContainer.apply(this, arguments);
|
|
47
52
|
}
|
|
48
|
-
function getContainer(containerId) {
|
|
49
|
-
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
return containers.get(containerId || defaultContainerId);
|
|
53
|
+
function getContainer(containerId, placement) {
|
|
54
|
+
return containers.get(containerId + "_" + placement);
|
|
53
55
|
}
|
|
54
56
|
var _toaster = function toaster(message) {
|
|
55
57
|
return _toaster.push(message);
|
|
@@ -59,13 +61,25 @@ _toaster.push = function (message, options) {
|
|
|
59
61
|
options = {};
|
|
60
62
|
}
|
|
61
63
|
var _options = options,
|
|
62
|
-
|
|
64
|
+
_options$placement = _options.placement,
|
|
65
|
+
placement = _options$placement === void 0 ? 'topCenter' : _options$placement,
|
|
66
|
+
_options$container = _options.container,
|
|
67
|
+
container = _options$container === void 0 ? _ToastContainer.defaultToasterContainer : _options$container,
|
|
63
68
|
restOptions = (0, _objectWithoutPropertiesLoose2.default)(_options, _excluded);
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
var containerElement = typeof container === 'function' ? container() : container;
|
|
70
|
+
var containerElementId = containerElement ? containerElement[_render.toasterKeyOfContainerElement] : null;
|
|
71
|
+
if (containerElementId) {
|
|
72
|
+
var existedContainer = getContainer(containerElementId, placement);
|
|
73
|
+
if (existedContainer) {
|
|
74
|
+
var _existedContainer$cur;
|
|
75
|
+
return (_existedContainer$cur = existedContainer.current) === null || _existedContainer$cur === void 0 ? void 0 : _existedContainer$cur.push(message, restOptions);
|
|
76
|
+
}
|
|
67
77
|
}
|
|
68
|
-
|
|
78
|
+
var newOptions = (0, _extends2.default)({}, options, {
|
|
79
|
+
container: containerElement,
|
|
80
|
+
placement: placement
|
|
81
|
+
});
|
|
82
|
+
return createContainer(placement, newOptions).then(function (ref) {
|
|
69
83
|
var _ref$current;
|
|
70
84
|
return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.push(message, restOptions);
|
|
71
85
|
});
|
|
@@ -19,7 +19,8 @@ var _CustomProvider = require("../CustomProvider/CustomProvider");
|
|
|
19
19
|
*/
|
|
20
20
|
var useToaster = function useToaster() {
|
|
21
21
|
var _useContext = (0, _react.useContext)(_CustomProvider.CustomContext),
|
|
22
|
-
toasters = _useContext.toasters
|
|
22
|
+
toasters = _useContext.toasters,
|
|
23
|
+
toastContainer = _useContext.toastContainer;
|
|
23
24
|
return (0, _react.useMemo)(function () {
|
|
24
25
|
return {
|
|
25
26
|
/**
|
|
@@ -31,9 +32,13 @@ var useToaster = function useToaster() {
|
|
|
31
32
|
* @returns The key of the toast message.
|
|
32
33
|
*/
|
|
33
34
|
push: function push(message, options) {
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
var container = (typeof (options === null || options === void 0 ? void 0 : options.container) === 'function' ? options === null || options === void 0 ? void 0 : options.container() : options === null || options === void 0 ? void 0 : options.container) || toastContainer;
|
|
36
|
+
if (container === toastContainer) {
|
|
37
|
+
var _toasters$current;
|
|
38
|
+
return toasters === null || toasters === void 0 || (_toasters$current = toasters.current) === null || _toasters$current === void 0 || (_toasters$current = _toasters$current.get((options === null || options === void 0 ? void 0 : options.placement) || 'topCenter')) === null || _toasters$current === void 0 ? void 0 : _toasters$current.push(message, options);
|
|
39
|
+
} else {
|
|
40
|
+
return _toaster.default.push(message, options);
|
|
41
|
+
}
|
|
37
42
|
},
|
|
38
43
|
/**
|
|
39
44
|
* Remove a toast message.
|
|
@@ -55,6 +60,6 @@ var useToaster = function useToaster() {
|
|
|
55
60
|
}) : _toaster.default.clear();
|
|
56
61
|
}
|
|
57
62
|
};
|
|
58
|
-
}, [toasters]);
|
|
63
|
+
}, [toastContainer, toasters]);
|
|
59
64
|
};
|
|
60
65
|
var _default = exports.default = useToaster;
|