Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rc-notification

Package Overview
Dependencies
Maintainers
7
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rc-notification - npm Package Compare versions

Comparing version 5.0.0-alpha.9 to 5.0.0

43

es/Notice.js

@@ -8,26 +8,23 @@ import _extends from "@babel/runtime/helpers/esm/extends";

var prefixCls = props.prefixCls,
style = props.style,
className = props.className,
_props$duration = props.duration,
duration = _props$duration === void 0 ? 4.5 : _props$duration,
eventKey = props.eventKey,
content = props.content,
closable = props.closable,
_props$closeIcon = props.closeIcon,
closeIcon = _props$closeIcon === void 0 ? 'x' : _props$closeIcon,
divProps = props.props,
onClick = props.onClick,
onNoticeClose = props.onNoticeClose;
style = props.style,
className = props.className,
_props$duration = props.duration,
duration = _props$duration === void 0 ? 4.5 : _props$duration,
eventKey = props.eventKey,
content = props.content,
closable = props.closable,
_props$closeIcon = props.closeIcon,
closeIcon = _props$closeIcon === void 0 ? 'x' : _props$closeIcon,
divProps = props.props,
onClick = props.onClick,
onNoticeClose = props.onNoticeClose;
var _React$useState = React.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
hovering = _React$useState2[0],
setHovering = _React$useState2[1]; // ======================== Close =========================
_React$useState2 = _slicedToArray(_React$useState, 2),
hovering = _React$useState2[0],
setHovering = _React$useState2[1];
// ======================== Close =========================
var onInternalClose = function onInternalClose() {
onNoticeClose(eventKey);
}; // ======================== Effect ========================
};
// ======================== Effect ========================
React.useEffect(function () {

@@ -42,4 +39,4 @@ if (!hovering && duration > 0) {

}
}, [duration, hovering]); // ======================== Render ========================
}, [duration, hovering]);
// ======================== Render ========================
var noticePrefixCls = "".concat(prefixCls, "-notice");

@@ -46,0 +43,0 @@ return /*#__PURE__*/React.createElement("div", _extends({}, divProps, {

@@ -19,3 +19,3 @@ import * as React from 'react';

}
export declare type Placement = 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight';
export type Placement = 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight';
export interface NotificationsRef {

@@ -22,0 +22,0 @@ open: (config: OpenConfig) => void;

@@ -9,23 +9,20 @@ import _extends from "@babel/runtime/helpers/esm/extends";

import classNames from 'classnames';
import Notice from './Notice'; // ant-notification ant-notification-topRight
import Notice from './Notice';
// ant-notification ant-notification-topRight
var Notifications = /*#__PURE__*/React.forwardRef(function (props, ref) {
var _props$prefixCls = props.prefixCls,
prefixCls = _props$prefixCls === void 0 ? 'rc-notification' : _props$prefixCls,
container = props.container,
motion = props.motion,
maxCount = props.maxCount,
className = props.className,
style = props.style,
onAllRemoved = props.onAllRemoved;
prefixCls = _props$prefixCls === void 0 ? 'rc-notification' : _props$prefixCls,
container = props.container,
motion = props.motion,
maxCount = props.maxCount,
className = props.className,
style = props.style,
onAllRemoved = props.onAllRemoved;
var _React$useState = React.useState([]),
_React$useState2 = _slicedToArray(_React$useState, 2),
configList = _React$useState2[0],
setConfigList = _React$useState2[1]; // ======================== Close =========================
_React$useState2 = _slicedToArray(_React$useState, 2),
configList = _React$useState2[0],
setConfigList = _React$useState2[1];
// ======================== Close =========================
var onNoticeClose = function onNoticeClose(key) {
var _config$onClose;
// Trigger close event

@@ -41,5 +38,4 @@ var config = configList.find(function (item) {

});
}; // ========================= Refs =========================
};
// ========================= Refs =========================
React.useImperativeHandle(ref, function () {

@@ -49,9 +45,7 @@ return {

setConfigList(function (list) {
var clone = _toConsumableArray(list); // Replace if exist
var clone = _toConsumableArray(list);
// Replace if exist
var index = clone.findIndex(function (item) {
return item.key === config.key;
});
if (index >= 0) {

@@ -62,7 +56,5 @@ clone[index] = config;

}
if (maxCount > 0 && clone.length > maxCount) {
clone = clone.slice(-maxCount);
}
return clone;

@@ -78,9 +70,8 @@ });

};
}); // ====================== Placements ======================
});
// ====================== Placements ======================
var _React$useState3 = React.useState({}),
_React$useState4 = _slicedToArray(_React$useState3, 2),
placements = _React$useState4[0],
setPlacements = _React$useState4[1];
_React$useState4 = _slicedToArray(_React$useState3, 2),
placements = _React$useState4[0],
setPlacements = _React$useState4[1];
React.useEffect(function () {

@@ -90,4 +81,3 @@ var nextPlacements = {};

var _config$placement = config.placement,
placement = _config$placement === void 0 ? 'topRight' : _config$placement;
placement = _config$placement === void 0 ? 'topRight' : _config$placement;
if (placement) {

@@ -97,4 +87,4 @@ nextPlacements[placement] = nextPlacements[placement] || [];

}
}); // Fill exist placements to avoid empty list causing remove without motion
});
// Fill exist placements to avoid empty list causing remove without motion
Object.keys(placements).forEach(function (placement) {

@@ -104,19 +94,15 @@ nextPlacements[placement] = nextPlacements[placement] || [];

setPlacements(nextPlacements);
}, [configList]); // Clean up container if all notices fade out
}, [configList]);
// Clean up container if all notices fade out
var onAllNoticeRemoved = function onAllNoticeRemoved(placement) {
setPlacements(function (originPlacements) {
var clone = _objectSpread({}, originPlacements);
var list = clone[placement] || [];
if (!list.length) {
delete clone[placement];
}
return clone;
});
}; // Effect tell that placements is empty now
};
// Effect tell that placements is empty now
var emptyRef = React.useRef(false);

@@ -131,8 +117,7 @@ React.useEffect(function () {

}
}, [placements]); // ======================== Render ========================
}, [placements]);
// ======================== Render ========================
if (!container) {
return null;
}
var placementList = Object.keys(placements);

@@ -160,7 +145,7 @@ return /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(React.Fragment, null, placementList.map(function (placement) {

var config = _ref.config,
motionClassName = _ref.className,
motionStyle = _ref.style;
motionClassName = _ref.className,
motionStyle = _ref.style;
var key = config.key;
var configClassName = config.className,
configStyle = config.style;
configStyle = config.style;
return /*#__PURE__*/React.createElement(Notice, _extends({}, config, {

@@ -178,7 +163,5 @@ ref: nodeRef,

});
if (process.env.NODE_ENV !== 'production') {
Notifications.displayName = 'Notifications';
}
export default Notifications;

@@ -5,3 +5,3 @@ import * as React from 'react';

import type { CSSMotionProps } from 'rc-motion';
declare type OptionalConfig = Partial<OpenConfig>;
type OptionalConfig = Partial<OpenConfig>;
export interface NotificationConfig {

@@ -8,0 +8,0 @@ prefixCls?: string;

@@ -7,16 +7,11 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";

import Notifications from './Notifications';
var defaultGetContainer = function defaultGetContainer() {
return document.body;
};
var uniqueKey = 0;
function mergeConfig() {
var clone = {};
for (var _len = arguments.length, objList = new Array(_len), _key = 0; _key < _len; _key++) {
objList[_key] = arguments[_key];
}
objList.forEach(function (obj) {

@@ -26,3 +21,2 @@ if (obj) {

var val = obj[key];
if (val !== undefined) {

@@ -36,21 +30,17 @@ clone[key] = val;

}
export default function useNotification() {
var rootConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _rootConfig$getContai = rootConfig.getContainer,
getContainer = _rootConfig$getContai === void 0 ? defaultGetContainer : _rootConfig$getContai,
motion = rootConfig.motion,
prefixCls = rootConfig.prefixCls,
maxCount = rootConfig.maxCount,
className = rootConfig.className,
style = rootConfig.style,
onAllRemoved = rootConfig.onAllRemoved,
shareConfig = _objectWithoutProperties(rootConfig, _excluded);
getContainer = _rootConfig$getContai === void 0 ? defaultGetContainer : _rootConfig$getContai,
motion = rootConfig.motion,
prefixCls = rootConfig.prefixCls,
maxCount = rootConfig.maxCount,
className = rootConfig.className,
style = rootConfig.style,
onAllRemoved = rootConfig.onAllRemoved,
shareConfig = _objectWithoutProperties(rootConfig, _excluded);
var _React$useState = React.useState(),
_React$useState2 = _slicedToArray(_React$useState, 2),
container = _React$useState2[0],
setContainer = _React$useState2[1];
_React$useState2 = _slicedToArray(_React$useState, 2),
container = _React$useState2[0],
setContainer = _React$useState2[1];
var notificationsRef = React.useRef();

@@ -67,9 +57,7 @@ var contextHolder = /*#__PURE__*/React.createElement(Notifications, {

});
var _React$useState3 = React.useState([]),
_React$useState4 = _slicedToArray(_React$useState3, 2),
taskQueue = _React$useState4[0],
setTaskQueue = _React$useState4[1]; // ========================= Refs =========================
_React$useState4 = _slicedToArray(_React$useState3, 2),
taskQueue = _React$useState4[0],
setTaskQueue = _React$useState4[1];
// ========================= Refs =========================
var api = React.useMemo(function () {

@@ -79,3 +67,2 @@ return {

var mergedConfig = mergeConfig(shareConfig, config);
if (mergedConfig.key === null || mergedConfig.key === undefined) {

@@ -85,3 +72,2 @@ mergedConfig.key = "rc-notification-".concat(uniqueKey);

}
setTaskQueue(function (queue) {

@@ -110,10 +96,10 @@ return [].concat(_toConsumableArray(queue), [{

};
}, []); // ======================= Container ======================
}, []);
// ======================= Container ======================
// React 18 should all in effect that we will check container in each render
// Which means getContainer should be stable.
React.useEffect(function () {
setContainer(getContainer());
}); // ======================== Effect ========================
});
// ======================== Effect ========================
React.useEffect(function () {

@@ -127,7 +113,5 @@ // Flush task when node ready

break;
case 'close':
notificationsRef.current.close(task.key);
break;
case 'destroy':

@@ -140,5 +124,5 @@ notificationsRef.current.destroy();

}
}, [taskQueue]); // ======================== Return ========================
}, [taskQueue]);
// ======================== Return ========================
return [api, contextHolder];
}
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -20,5 +19,3 @@ value: true

});
var _useNotification = _interopRequireDefault(require("./useNotification"));
var _Notice = _interopRequireDefault(require("./Notice"));
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -11,39 +9,32 @@ value: true

exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var Notify = /*#__PURE__*/React.forwardRef(function (props, ref) {
var prefixCls = props.prefixCls,
style = props.style,
className = props.className,
_props$duration = props.duration,
duration = _props$duration === void 0 ? 4.5 : _props$duration,
eventKey = props.eventKey,
content = props.content,
closable = props.closable,
_props$closeIcon = props.closeIcon,
closeIcon = _props$closeIcon === void 0 ? 'x' : _props$closeIcon,
divProps = props.props,
onClick = props.onClick,
onNoticeClose = props.onNoticeClose;
style = props.style,
className = props.className,
_props$duration = props.duration,
duration = _props$duration === void 0 ? 4.5 : _props$duration,
eventKey = props.eventKey,
content = props.content,
closable = props.closable,
_props$closeIcon = props.closeIcon,
closeIcon = _props$closeIcon === void 0 ? 'x' : _props$closeIcon,
divProps = props.props,
onClick = props.onClick,
onNoticeClose = props.onNoticeClose;
var _React$useState = React.useState(false),
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
hovering = _React$useState2[0],
setHovering = _React$useState2[1]; // ======================== Close =========================
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
hovering = _React$useState2[0],
setHovering = _React$useState2[1];
// ======================== Close =========================
var onInternalClose = function onInternalClose() {
onNoticeClose(eventKey);
}; // ======================== Effect ========================
};
// ======================== Effect ========================
React.useEffect(function () {

@@ -58,4 +49,4 @@ if (!hovering && duration > 0) {

}
}, [duration, hovering]); // ======================== Render ========================
}, [duration, hovering]);
// ======================== Render ========================
var noticePrefixCls = "".concat(prefixCls, "-notice");

@@ -62,0 +53,0 @@ return /*#__PURE__*/React.createElement("div", (0, _extends2.default)({}, divProps, {

@@ -19,3 +19,3 @@ import * as React from 'react';

}
export declare type Placement = 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight';
export type Placement = 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight';
export interface NotificationsRef {

@@ -22,0 +22,0 @@ open: (config: OpenConfig) => void;

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -11,41 +9,30 @@ value: true

exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var React = _interopRequireWildcard(require("react"));
var _reactDom = require("react-dom");
var _rcMotion = require("rc-motion");
var _classnames = _interopRequireDefault(require("classnames"));
var _Notice = _interopRequireDefault(require("./Notice"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
// ant-notification ant-notification-topRight
var Notifications = /*#__PURE__*/React.forwardRef(function (props, ref) {
var _props$prefixCls = props.prefixCls,
prefixCls = _props$prefixCls === void 0 ? 'rc-notification' : _props$prefixCls,
container = props.container,
motion = props.motion,
maxCount = props.maxCount,
className = props.className,
style = props.style,
onAllRemoved = props.onAllRemoved;
prefixCls = _props$prefixCls === void 0 ? 'rc-notification' : _props$prefixCls,
container = props.container,
motion = props.motion,
maxCount = props.maxCount,
className = props.className,
style = props.style,
onAllRemoved = props.onAllRemoved;
var _React$useState = React.useState([]),
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
configList = _React$useState2[0],
setConfigList = _React$useState2[1]; // ======================== Close =========================
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
configList = _React$useState2[0],
setConfigList = _React$useState2[1];
// ======================== Close =========================
var onNoticeClose = function onNoticeClose(key) {
var _config$onClose;
// Trigger close event

@@ -61,5 +48,4 @@ var config = configList.find(function (item) {

});
}; // ========================= Refs =========================
};
// ========================= Refs =========================
React.useImperativeHandle(ref, function () {

@@ -69,8 +55,7 @@ return {

setConfigList(function (list) {
var clone = (0, _toConsumableArray2.default)(list); // Replace if exist
var clone = (0, _toConsumableArray2.default)(list);
// Replace if exist
var index = clone.findIndex(function (item) {
return item.key === config.key;
});
if (index >= 0) {

@@ -81,7 +66,5 @@ clone[index] = config;

}
if (maxCount > 0 && clone.length > maxCount) {
clone = clone.slice(-maxCount);
}
return clone;

@@ -97,9 +80,8 @@ });

};
}); // ====================== Placements ======================
});
// ====================== Placements ======================
var _React$useState3 = React.useState({}),
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
placements = _React$useState4[0],
setPlacements = _React$useState4[1];
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
placements = _React$useState4[0],
setPlacements = _React$useState4[1];
React.useEffect(function () {

@@ -109,4 +91,3 @@ var nextPlacements = {};

var _config$placement = config.placement,
placement = _config$placement === void 0 ? 'topRight' : _config$placement;
placement = _config$placement === void 0 ? 'topRight' : _config$placement;
if (placement) {

@@ -116,4 +97,4 @@ nextPlacements[placement] = nextPlacements[placement] || [];

}
}); // Fill exist placements to avoid empty list causing remove without motion
});
// Fill exist placements to avoid empty list causing remove without motion
Object.keys(placements).forEach(function (placement) {

@@ -123,4 +104,4 @@ nextPlacements[placement] = nextPlacements[placement] || [];

setPlacements(nextPlacements);
}, [configList]); // Clean up container if all notices fade out
}, [configList]);
// Clean up container if all notices fade out
var onAllNoticeRemoved = function onAllNoticeRemoved(placement) {

@@ -130,12 +111,9 @@ setPlacements(function (originPlacements) {

var list = clone[placement] || [];
if (!list.length) {
delete clone[placement];
}
return clone;
});
}; // Effect tell that placements is empty now
};
// Effect tell that placements is empty now
var emptyRef = React.useRef(false);

@@ -150,8 +128,7 @@ React.useEffect(function () {

}
}, [placements]); // ======================== Render ========================
}, [placements]);
// ======================== Render ========================
if (!container) {
return null;
}
var placementList = Object.keys(placements);

@@ -179,7 +156,7 @@ return /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/React.createElement(React.Fragment, null, placementList.map(function (placement) {

var config = _ref.config,
motionClassName = _ref.className,
motionStyle = _ref.style;
motionClassName = _ref.className,
motionStyle = _ref.style;
var key = config.key;
var configClassName = config.className,
configStyle = config.style;
configStyle = config.style;
return /*#__PURE__*/React.createElement(_Notice.default, (0, _extends2.default)({}, config, {

@@ -197,8 +174,6 @@ ref: nodeRef,

});
if (process.env.NODE_ENV !== 'production') {
Notifications.displayName = 'Notifications';
}
var _default = Notifications;
exports.default = _default;

@@ -5,3 +5,3 @@ import * as React from 'react';

import type { CSSMotionProps } from 'rc-motion';
declare type OptionalConfig = Partial<OpenConfig>;
type OptionalConfig = Partial<OpenConfig>;
export interface NotificationConfig {

@@ -8,0 +8,0 @@ prefixCls?: string;

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -11,28 +9,19 @@ value: true

exports.default = useNotification;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _Notifications = _interopRequireDefault(require("./Notifications"));
var _excluded = ["getContainer", "motion", "prefixCls", "maxCount", "className", "style", "onAllRemoved"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var defaultGetContainer = function defaultGetContainer() {
return document.body;
};
var uniqueKey = 0;
function mergeConfig() {
var clone = {};
for (var _len = arguments.length, objList = new Array(_len), _key = 0; _key < _len; _key++) {
objList[_key] = arguments[_key];
}
objList.forEach(function (obj) {

@@ -42,3 +31,2 @@ if (obj) {

var val = obj[key];
if (val !== undefined) {

@@ -52,20 +40,17 @@ clone[key] = val;

}
function useNotification() {
var rootConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _rootConfig$getContai = rootConfig.getContainer,
getContainer = _rootConfig$getContai === void 0 ? defaultGetContainer : _rootConfig$getContai,
motion = rootConfig.motion,
prefixCls = rootConfig.prefixCls,
maxCount = rootConfig.maxCount,
className = rootConfig.className,
style = rootConfig.style,
onAllRemoved = rootConfig.onAllRemoved,
shareConfig = (0, _objectWithoutProperties2.default)(rootConfig, _excluded);
getContainer = _rootConfig$getContai === void 0 ? defaultGetContainer : _rootConfig$getContai,
motion = rootConfig.motion,
prefixCls = rootConfig.prefixCls,
maxCount = rootConfig.maxCount,
className = rootConfig.className,
style = rootConfig.style,
onAllRemoved = rootConfig.onAllRemoved,
shareConfig = (0, _objectWithoutProperties2.default)(rootConfig, _excluded);
var _React$useState = React.useState(),
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
container = _React$useState2[0],
setContainer = _React$useState2[1];
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
container = _React$useState2[0],
setContainer = _React$useState2[1];
var notificationsRef = React.useRef();

@@ -82,9 +67,7 @@ var contextHolder = /*#__PURE__*/React.createElement(_Notifications.default, {

});
var _React$useState3 = React.useState([]),
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
taskQueue = _React$useState4[0],
setTaskQueue = _React$useState4[1]; // ========================= Refs =========================
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
taskQueue = _React$useState4[0],
setTaskQueue = _React$useState4[1];
// ========================= Refs =========================
var api = React.useMemo(function () {

@@ -94,3 +77,2 @@ return {

var mergedConfig = mergeConfig(shareConfig, config);
if (mergedConfig.key === null || mergedConfig.key === undefined) {

@@ -100,3 +82,2 @@ mergedConfig.key = "rc-notification-".concat(uniqueKey);

}
setTaskQueue(function (queue) {

@@ -125,10 +106,10 @@ return [].concat((0, _toConsumableArray2.default)(queue), [{

};
}, []); // ======================= Container ======================
}, []);
// ======================= Container ======================
// React 18 should all in effect that we will check container in each render
// Which means getContainer should be stable.
React.useEffect(function () {
setContainer(getContainer());
}); // ======================== Effect ========================
});
// ======================== Effect ========================
React.useEffect(function () {

@@ -142,7 +123,5 @@ // Flush task when node ready

break;
case 'close':
notificationsRef.current.close(task.key);
break;
case 'destroy':

@@ -155,5 +134,5 @@ notificationsRef.current.destroy();

}
}, [taskQueue]); // ======================== Return ========================
}, [taskQueue]);
// ======================== Return ========================
return [api, contextHolder];
}
{
"name": "rc-notification",
"version": "5.0.0-alpha.9",
"version": "5.0.0",
"description": "notification ui component for react",

@@ -5,0 +5,0 @@ "engines": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc