Socket
Socket
Sign inDemoInstall

rc-notification

Package Overview
Dependencies
Maintainers
6
Versions
75
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 4.3.0 to 4.3.2

17

es/index.js

@@ -1,15 +0,2 @@

"use strict";
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
var Notification_1 = __importDefault(require("./Notification"));
exports.default = Notification_1.default;
import Notification from './Notification';
export default Notification;

2

es/Notice.d.ts

@@ -32,3 +32,3 @@ import React, { Component } from 'react';

componentWillUnmount(): void;
close: (e?: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => void;
close: (e?: React.MouseEvent<HTMLAnchorElement>) => void;
startCloseTimer: () => void;

@@ -35,0 +35,0 @@ clearCloseTimer: () => void;

@@ -1,3 +0,1 @@

"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

@@ -27,152 +25,136 @@

var __importStar = this && this.__importStar || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) {
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
}
result["default"] = mod;
return result;
};
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import classNames from 'classnames';
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
var Notice =
/** @class */
function () {
var Notice = /*#__PURE__*/function (_Component) {
_inherits(Notice, _Component);
Object.defineProperty(exports, "__esModule", {
value: true
});
var _super = _createSuper(Notice);
var react_1 = __importStar(require("react"));
function Notice() {
var _this;
var react_dom_1 = __importDefault(require("react-dom"));
_classCallCheck(this, Notice);
var classnames_1 = __importDefault(require("classnames"));
_this = _super.apply(this, arguments);
_this.closeTimer = null;
var Notice = /*#__PURE__*/function (_react_1$Component) {
_inherits(Notice, _react_1$Component);
_this.close = function (e) {
if (e) {
e.stopPropagation();
}
var _super = _createSuper(Notice);
_this.clearCloseTimer();
function Notice() {
var _this;
var onClose = _this.props.onClose;
_classCallCheck(this, Notice);
if (onClose) {
onClose();
}
};
_this = _super.apply(this, arguments);
_this.closeTimer = null;
_this.startCloseTimer = function () {
if (_this.props.duration) {
_this.closeTimer = window.setTimeout(function () {
_this.close();
}, _this.props.duration * 1000);
}
};
_this.close = function (e) {
if (e) {
e.stopPropagation();
}
_this.clearCloseTimer = function () {
if (_this.closeTimer) {
clearTimeout(_this.closeTimer);
_this.closeTimer = null;
}
};
_this.clearCloseTimer();
return _this;
}
var onClose = _this.props.onClose;
if (onClose) {
onClose();
_createClass(Notice, [{
key: "componentDidMount",
value: function componentDidMount() {
this.startCloseTimer();
}
};
_this.startCloseTimer = function () {
if (_this.props.duration) {
_this.closeTimer = window.setTimeout(function () {
_this.close();
}, _this.props.duration * 1000);
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (this.props.duration !== prevProps.duration || this.props.update) {
this.restartCloseTimer();
}
}
};
_this.clearCloseTimer = function () {
if (_this.closeTimer) {
clearTimeout(_this.closeTimer);
_this.closeTimer = null;
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.clearCloseTimer();
}
};
}, {
key: "restartCloseTimer",
value: function restartCloseTimer() {
this.clearCloseTimer();
this.startCloseTimer();
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return _this;
}
var _this$props = this.props,
prefixCls = _this$props.prefixCls,
className = _this$props.className,
closable = _this$props.closable,
closeIcon = _this$props.closeIcon,
style = _this$props.style,
onClick = _this$props.onClick,
children = _this$props.children,
holder = _this$props.holder;
var componentClass = "".concat(prefixCls, "-notice");
var dataOrAriaAttributeProps = Object.keys(this.props).reduce(function (acc, key) {
if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-' || key === 'role') {
acc[key] = _this2.props[key];
}
_createClass(Notice, [{
key: "componentDidMount",
value: function componentDidMount() {
this.startCloseTimer();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (this.props.duration !== prevProps.duration || this.props.update) {
this.restartCloseTimer();
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.clearCloseTimer();
}
}, {
key: "restartCloseTimer",
value: function restartCloseTimer() {
this.clearCloseTimer();
this.startCloseTimer();
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return acc;
}, {});
var node = React.createElement("div", Object.assign({
className: classNames(componentClass, className, _defineProperty({}, "".concat(componentClass, "-closable"), closable)),
style: style,
onMouseEnter: this.clearCloseTimer,
onMouseLeave: this.startCloseTimer,
onClick: onClick
}, dataOrAriaAttributeProps), React.createElement("div", {
className: "".concat(componentClass, "-content")
}, children), closable ? React.createElement("a", {
tabIndex: 0,
onClick: this.close,
className: "".concat(componentClass, "-close")
}, closeIcon || React.createElement("span", {
className: "".concat(componentClass, "-close-x")
})) : null);
var _this$props = this.props,
prefixCls = _this$props.prefixCls,
className = _this$props.className,
closable = _this$props.closable,
closeIcon = _this$props.closeIcon,
style = _this$props.style,
onClick = _this$props.onClick,
children = _this$props.children,
holder = _this$props.holder;
var componentClass = "".concat(prefixCls, "-notice");
var dataOrAriaAttributeProps = Object.keys(this.props).reduce(function (acc, key) {
if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-' || key === 'role') {
acc[key] = _this2.props[key];
if (holder) {
return ReactDOM.createPortal(node, holder);
}
return acc;
}, {});
var node = react_1.default.createElement("div", Object.assign({
className: classnames_1.default(componentClass, className, _defineProperty({}, "".concat(componentClass, "-closable"), closable)),
style: style,
onMouseEnter: this.clearCloseTimer,
onMouseLeave: this.startCloseTimer,
onClick: onClick
}, dataOrAriaAttributeProps), react_1.default.createElement("div", {
className: "".concat(componentClass, "-content")
}, children), closable ? react_1.default.createElement("a", {
tabIndex: 0,
onClick: this.close,
className: "".concat(componentClass, "-close")
}, closeIcon || react_1.default.createElement("span", {
className: "".concat(componentClass, "-close-x")
})) : null);
if (holder) {
return react_dom_1.default.createPortal(node, holder);
return node;
}
}]);
return node;
return Notice;
}(Component);
Notice.defaultProps = {
onClose: function onClose() {},
duration: 1.5,
style: {
right: '50%'
}
}]);
};
return Notice;
}(react_1.Component);
}();
exports.default = Notice;
Notice.defaultProps = {
onClose: function onClose() {},
duration: 1.5,
style: {
right: '50%'
}
};
export default Notice;

@@ -51,5 +51,5 @@ import React, { Component } from 'react';

add: (notice: NoticeContent, holderCallback?: HolderReadyCallback) => void;
remove: (key: React.ReactText) => void;
remove: (key: React.Key) => void;
render(): JSX.Element;
}
export default Notification;

@@ -1,2 +0,2 @@

"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

@@ -7,4 +7,2 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

@@ -36,36 +34,9 @@

var __importStar = this && this.__importStar || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) {
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
}
result["default"] = mod;
return result;
};
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
var react_1 = __importStar(require("react"));
var react_dom_1 = __importDefault(require("react-dom"));
var rc_animate_1 = __importDefault(require("rc-animate"));
var createChainedFunction_1 = __importDefault(require("rc-util/lib/createChainedFunction"));
var classnames_1 = __importDefault(require("classnames"));
var Notice_1 = __importDefault(require("./Notice"));
var useNotification_1 = __importDefault(require("./useNotification"));
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Animate from 'rc-animate';
import createChainedFunction from "rc-util/es/createChainedFunction";
import classnames from 'classnames';
import Notice from './Notice';
import _useNotification from './useNotification';
var seed = 0;

@@ -80,158 +51,163 @@ var now = Date.now();

var Notification = /*#__PURE__*/function (_react_1$Component) {
_inherits(Notification, _react_1$Component);
var Notification =
/** @class */
function () {
var Notification = /*#__PURE__*/function (_Component) {
_inherits(Notification, _Component);
var _super = _createSuper(Notification);
var _super = _createSuper(Notification);
function Notification() {
var _this;
function Notification() {
var _this;
_classCallCheck(this, Notification);
_classCallCheck(this, Notification);
_this = _super.apply(this, arguments);
_this.state = {
notices: []
};
_this.hookRefs = new Map();
_this = _super.apply(this, arguments);
_this.state = {
notices: []
};
_this.hookRefs = new Map();
_this.add = function (notice, holderCallback) {
// eslint-disable-next-line no-param-reassign
notice.key = notice.key || getUuid();
var key = notice.key;
var maxCount = _this.props.maxCount;
_this.add = function (notice, holderCallback) {
// eslint-disable-next-line no-param-reassign
notice.key = notice.key || getUuid();
var key = notice.key;
var maxCount = _this.props.maxCount;
_this.setState(function (previousState) {
var notices = previousState.notices;
var noticeIndex = notices.map(function (v) {
return v.notice.key;
}).indexOf(key);
var updatedNotices = notices.concat();
_this.setState(function (previousState) {
var notices = previousState.notices;
var noticeIndex = notices.map(function (v) {
return v.notice.key;
}).indexOf(key);
var updatedNotices = notices.concat();
if (noticeIndex !== -1) {
updatedNotices.splice(noticeIndex, 1, {
notice: notice,
holderCallback: holderCallback
});
} else {
if (maxCount && notices.length >= maxCount) {
// XXX, use key of first item to update new added (let React to move exsiting
// instead of remove and mount). Same key was used before for both a) external
// manual control and b) internal react 'key' prop , which is not that good.
// eslint-disable-next-line no-param-reassign
notice.updateKey = updatedNotices[0].notice.updateKey || updatedNotices[0].notice.key;
updatedNotices.shift();
if (noticeIndex !== -1) {
updatedNotices.splice(noticeIndex, 1, {
notice: notice,
holderCallback: holderCallback
});
} else {
if (maxCount && notices.length >= maxCount) {
// XXX, use key of first item to update new added (let React to move exsiting
// instead of remove and mount). Same key was used before for both a) external
// manual control and b) internal react 'key' prop , which is not that good.
// eslint-disable-next-line no-param-reassign
notice.updateKey = updatedNotices[0].notice.updateKey || updatedNotices[0].notice.key;
updatedNotices.shift();
}
updatedNotices.push({
notice: notice,
holderCallback: holderCallback
});
}
updatedNotices.push({
notice: notice,
holderCallback: holderCallback
});
}
return {
notices: updatedNotices
};
});
};
return {
notices: updatedNotices
};
});
};
_this.remove = function (key) {
_this.setState(function (previousState) {
return {
notices: previousState.notices.filter(function (_ref) {
var notice = _ref.notice;
return notice.key !== key;
})
};
});
};
_this.remove = function (key) {
_this.setState(function (previousState) {
return {
notices: previousState.notices.filter(function (_ref) {
var notice = _ref.notice;
return notice.key !== key;
})
};
});
};
return _this;
}
return _this;
}
_createClass(Notification, [{
key: "getTransitionName",
value: function getTransitionName() {
var _this$props = this.props,
prefixCls = _this$props.prefixCls,
animation = _this$props.animation;
var transitionName = this.props.transitionName;
_createClass(Notification, [{
key: "getTransitionName",
value: function getTransitionName() {
var _this$props = this.props,
prefixCls = _this$props.prefixCls,
animation = _this$props.animation;
var transitionName = this.props.transitionName;
if (!transitionName && animation) {
transitionName = "".concat(prefixCls, "-").concat(animation);
}
if (!transitionName && animation) {
transitionName = "".concat(prefixCls, "-").concat(animation);
return transitionName;
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return transitionName;
}
}, {
key: "render",
value: function render() {
var _this2 = this;
var notices = this.state.notices;
var _this$props2 = this.props,
prefixCls = _this$props2.prefixCls,
className = _this$props2.className,
closeIcon = _this$props2.closeIcon,
style = _this$props2.style;
var noticeNodes = notices.map(function (_ref2, index) {
var notice = _ref2.notice,
holderCallback = _ref2.holderCallback;
var update = Boolean(index === notices.length - 1 && notice.updateKey);
var key = notice.updateKey ? notice.updateKey : notice.key;
var onClose = createChainedFunction(_this2.remove.bind(_this2, notice.key), notice.onClose);
var notices = this.state.notices;
var _this$props2 = this.props,
prefixCls = _this$props2.prefixCls,
className = _this$props2.className,
closeIcon = _this$props2.closeIcon,
style = _this$props2.style;
var noticeNodes = notices.map(function (_ref2, index) {
var notice = _ref2.notice,
holderCallback = _ref2.holderCallback;
var update = Boolean(index === notices.length - 1 && notice.updateKey);
var key = notice.updateKey ? notice.updateKey : notice.key;
var onClose = createChainedFunction_1.default(_this2.remove.bind(_this2, notice.key), notice.onClose);
var noticeProps = _objectSpread(_objectSpread(_objectSpread({
prefixCls: prefixCls,
closeIcon: closeIcon
}, notice), notice.props), {}, {
key: key,
update: update,
onClose: onClose,
onClick: notice.onClick,
children: notice.content
});
var noticeProps = _objectSpread(_objectSpread(_objectSpread({
prefixCls: prefixCls,
closeIcon: closeIcon
}, notice), notice.props), {}, {
key: key,
update: update,
onClose: onClose,
onClick: notice.onClick,
children: notice.content
});
if (holderCallback) {
return React.createElement("div", {
key: key,
className: "".concat(prefixCls, "-hook-holder"),
ref: function ref(div) {
if (typeof key === 'undefined') {
return;
}
if (holderCallback) {
return react_1.default.createElement("div", {
key: key,
className: "".concat(prefixCls, "-hook-holder"),
ref: function ref(div) {
if (typeof key === 'undefined') {
return;
if (div) {
_this2.hookRefs.set(key, div);
holderCallback(div, noticeProps);
} else {
_this2.hookRefs.delete(key);
}
}
});
}
if (div) {
_this2.hookRefs.set(key, div);
return React.createElement(Notice, Object.assign({}, noticeProps));
});
return React.createElement("div", {
className: classnames(prefixCls, className),
style: style
}, React.createElement(Animate, {
transitionName: this.getTransitionName()
}, noticeNodes));
}
}]);
holderCallback(div, noticeProps);
} else {
_this2.hookRefs.delete(key);
}
}
});
}
return Notification;
}(Component);
return react_1.default.createElement(Notice_1.default, Object.assign({}, noticeProps));
});
return react_1.default.createElement("div", {
className: classnames_1.default(prefixCls, className),
style: style
}, react_1.default.createElement(rc_animate_1.default, {
transitionName: this.getTransitionName()
}, noticeNodes));
Notification.defaultProps = {
prefixCls: 'rc-notification',
animation: 'fade',
style: {
top: 65,
left: '50%'
}
}]);
};
return Notification;
}(react_1.Component);
}();
Notification.defaultProps = {
prefixCls: 'rc-notification',
animation: 'fade',
style: {
top: 65,
left: '50%'
}
};
Notification.newInstance = function newNotificationInstance(properties, callback) {

@@ -268,3 +244,3 @@ var _ref3 = properties || {},

destroy: function destroy() {
react_dom_1.default.unmountComponentAtNode(div);
ReactDOM.unmountComponentAtNode(div);

@@ -277,3 +253,3 @@ if (div.parentNode) {

useNotification: function useNotification() {
return useNotification_1.default(notification);
return _useNotification(notification);
}

@@ -285,3 +261,3 @@ });

if (process.env.NODE_ENV === 'test' && properties.TEST_RENDER) {
properties.TEST_RENDER(react_1.default.createElement(Notification, Object.assign({}, props, {
properties.TEST_RENDER(React.createElement(Notification, Object.assign({}, props, {
ref: ref

@@ -292,3 +268,3 @@ })));

react_dom_1.default.render(react_1.default.createElement(Notification, Object.assign({}, props, {
ReactDOM.render(React.createElement(Notification, Object.assign({}, props, {
ref: ref

@@ -298,2 +274,2 @@ })), div);

exports.default = Notification;
export default Notification;

@@ -1,3 +0,1 @@

"use strict";
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

@@ -23,27 +21,5 @@

var __importStar = this && this.__importStar || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) {
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
}
result["default"] = mod;
return result;
};
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
var React = __importStar(require("react"));
var Notice_1 = __importDefault(require("./Notice"));
function useNotification(notificationInstance) {
import * as React from 'react';
import Notice from './Notice';
export default function useNotification(notificationInstance) {
var createdRef = React.useRef({});

@@ -61,3 +37,3 @@

if (div && !createdRef.current[key]) {
var noticeEle = React.createElement(Notice_1.default, Object.assign({}, props, {
var noticeEle = React.createElement(Notice, Object.assign({}, props, {
holder: div

@@ -74,4 +50,2 @@ }));

return [notify, React.createElement(React.Fragment, null, elements)];
}
exports.default = useNotification;
}
"use strict";
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var Notification_1 = __importDefault(require("./Notification"));
var _Notification = _interopRequireDefault(require("./Notification"));
exports.default = Notification_1.default;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = _Notification.default;
exports.default = _default;

@@ -32,3 +32,3 @@ import React, { Component } from 'react';

componentWillUnmount(): void;
close: (e?: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => void;
close: (e?: React.MouseEvent<HTMLAnchorElement>) => void;
startCloseTimer: () => void;

@@ -35,0 +35,0 @@ clearCloseTimer: () => void;

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactDom = _interopRequireDefault(require("react-dom"));
var _classnames = _interopRequireDefault(require("classnames"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

@@ -27,152 +44,134 @@

var __importStar = void 0 && (void 0).__importStar || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) {
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
}
result["default"] = mod;
return result;
};
var Notice =
/** @class */
function () {
var Notice = /*#__PURE__*/function (_Component) {
_inherits(Notice, _Component);
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
var _super = _createSuper(Notice);
Object.defineProperty(exports, "__esModule", {
value: true
});
function Notice() {
var _this;
var react_1 = __importStar(require("react"));
_classCallCheck(this, Notice);
var react_dom_1 = __importDefault(require("react-dom"));
_this = _super.apply(this, arguments);
_this.closeTimer = null;
var classnames_1 = __importDefault(require("classnames"));
_this.close = function (e) {
if (e) {
e.stopPropagation();
}
var Notice = /*#__PURE__*/function (_react_1$Component) {
_inherits(Notice, _react_1$Component);
_this.clearCloseTimer();
var _super = _createSuper(Notice);
var onClose = _this.props.onClose;
function Notice() {
var _this;
if (onClose) {
onClose();
}
};
_classCallCheck(this, Notice);
_this.startCloseTimer = function () {
if (_this.props.duration) {
_this.closeTimer = window.setTimeout(function () {
_this.close();
}, _this.props.duration * 1000);
}
};
_this = _super.apply(this, arguments);
_this.closeTimer = null;
_this.clearCloseTimer = function () {
if (_this.closeTimer) {
clearTimeout(_this.closeTimer);
_this.closeTimer = null;
}
};
_this.close = function (e) {
if (e) {
e.stopPropagation();
}
return _this;
}
_this.clearCloseTimer();
var onClose = _this.props.onClose;
if (onClose) {
onClose();
_createClass(Notice, [{
key: "componentDidMount",
value: function componentDidMount() {
this.startCloseTimer();
}
};
_this.startCloseTimer = function () {
if (_this.props.duration) {
_this.closeTimer = window.setTimeout(function () {
_this.close();
}, _this.props.duration * 1000);
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (this.props.duration !== prevProps.duration || this.props.update) {
this.restartCloseTimer();
}
}
};
_this.clearCloseTimer = function () {
if (_this.closeTimer) {
clearTimeout(_this.closeTimer);
_this.closeTimer = null;
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.clearCloseTimer();
}
};
}, {
key: "restartCloseTimer",
value: function restartCloseTimer() {
this.clearCloseTimer();
this.startCloseTimer();
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return _this;
}
var _this$props = this.props,
prefixCls = _this$props.prefixCls,
className = _this$props.className,
closable = _this$props.closable,
closeIcon = _this$props.closeIcon,
style = _this$props.style,
onClick = _this$props.onClick,
children = _this$props.children,
holder = _this$props.holder;
var componentClass = "".concat(prefixCls, "-notice");
var dataOrAriaAttributeProps = Object.keys(this.props).reduce(function (acc, key) {
if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-' || key === 'role') {
acc[key] = _this2.props[key];
}
_createClass(Notice, [{
key: "componentDidMount",
value: function componentDidMount() {
this.startCloseTimer();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (this.props.duration !== prevProps.duration || this.props.update) {
this.restartCloseTimer();
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.clearCloseTimer();
}
}, {
key: "restartCloseTimer",
value: function restartCloseTimer() {
this.clearCloseTimer();
this.startCloseTimer();
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return acc;
}, {});
var _this$props = this.props,
prefixCls = _this$props.prefixCls,
className = _this$props.className,
closable = _this$props.closable,
closeIcon = _this$props.closeIcon,
style = _this$props.style,
onClick = _this$props.onClick,
children = _this$props.children,
holder = _this$props.holder;
var componentClass = "".concat(prefixCls, "-notice");
var dataOrAriaAttributeProps = Object.keys(this.props).reduce(function (acc, key) {
if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-' || key === 'role') {
acc[key] = _this2.props[key];
var node = _react.default.createElement("div", Object.assign({
className: (0, _classnames.default)(componentClass, className, _defineProperty({}, "".concat(componentClass, "-closable"), closable)),
style: style,
onMouseEnter: this.clearCloseTimer,
onMouseLeave: this.startCloseTimer,
onClick: onClick
}, dataOrAriaAttributeProps), _react.default.createElement("div", {
className: "".concat(componentClass, "-content")
}, children), closable ? _react.default.createElement("a", {
tabIndex: 0,
onClick: this.close,
className: "".concat(componentClass, "-close")
}, closeIcon || _react.default.createElement("span", {
className: "".concat(componentClass, "-close-x")
})) : null);
if (holder) {
return _reactDom.default.createPortal(node, holder);
}
return acc;
}, {});
var node = react_1.default.createElement("div", Object.assign({
className: classnames_1.default(componentClass, className, _defineProperty({}, "".concat(componentClass, "-closable"), closable)),
style: style,
onMouseEnter: this.clearCloseTimer,
onMouseLeave: this.startCloseTimer,
onClick: onClick
}, dataOrAriaAttributeProps), react_1.default.createElement("div", {
className: "".concat(componentClass, "-content")
}, children), closable ? react_1.default.createElement("a", {
tabIndex: 0,
onClick: this.close,
className: "".concat(componentClass, "-close")
}, closeIcon || react_1.default.createElement("span", {
className: "".concat(componentClass, "-close-x")
})) : null);
if (holder) {
return react_dom_1.default.createPortal(node, holder);
return node;
}
}]);
return node;
return Notice;
}(_react.Component);
Notice.defaultProps = {
onClose: function onClose() {},
duration: 1.5,
style: {
right: '50%'
}
}]);
};
return Notice;
}(react_1.Component);
}();
exports.default = Notice;
Notice.defaultProps = {
onClose: function onClose() {},
duration: 1.5,
style: {
right: '50%'
}
};
var _default = Notice;
exports.default = _default;

@@ -51,5 +51,5 @@ import React, { Component } from 'react';

add: (notice: NoticeContent, holderCallback?: HolderReadyCallback) => void;
remove: (key: React.ReactText) => void;
remove: (key: React.Key) => void;
render(): JSX.Element;
}
export default Notification;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactDom = _interopRequireDefault(require("react-dom"));
var _rcAnimate = _interopRequireDefault(require("rc-animate"));
var _createChainedFunction = _interopRequireDefault(require("rc-util/lib/createChainedFunction"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Notice = _interopRequireDefault(require("./Notice"));
var _useNotification2 = _interopRequireDefault(require("./useNotification"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

@@ -7,4 +34,2 @@

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

@@ -36,36 +61,2 @@

var __importStar = void 0 && (void 0).__importStar || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) {
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
}
result["default"] = mod;
return result;
};
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
var react_1 = __importStar(require("react"));
var react_dom_1 = __importDefault(require("react-dom"));
var rc_animate_1 = __importDefault(require("rc-animate"));
var createChainedFunction_1 = __importDefault(require("rc-util/lib/createChainedFunction"));
var classnames_1 = __importDefault(require("classnames"));
var Notice_1 = __importDefault(require("./Notice"));
var useNotification_1 = __importDefault(require("./useNotification"));
var seed = 0;

@@ -80,158 +71,163 @@ var now = Date.now();

var Notification = /*#__PURE__*/function (_react_1$Component) {
_inherits(Notification, _react_1$Component);
var Notification =
/** @class */
function () {
var Notification = /*#__PURE__*/function (_Component) {
_inherits(Notification, _Component);
var _super = _createSuper(Notification);
var _super = _createSuper(Notification);
function Notification() {
var _this;
function Notification() {
var _this;
_classCallCheck(this, Notification);
_classCallCheck(this, Notification);
_this = _super.apply(this, arguments);
_this.state = {
notices: []
};
_this.hookRefs = new Map();
_this = _super.apply(this, arguments);
_this.state = {
notices: []
};
_this.hookRefs = new Map();
_this.add = function (notice, holderCallback) {
// eslint-disable-next-line no-param-reassign
notice.key = notice.key || getUuid();
var key = notice.key;
var maxCount = _this.props.maxCount;
_this.add = function (notice, holderCallback) {
// eslint-disable-next-line no-param-reassign
notice.key = notice.key || getUuid();
var key = notice.key;
var maxCount = _this.props.maxCount;
_this.setState(function (previousState) {
var notices = previousState.notices;
var noticeIndex = notices.map(function (v) {
return v.notice.key;
}).indexOf(key);
var updatedNotices = notices.concat();
_this.setState(function (previousState) {
var notices = previousState.notices;
var noticeIndex = notices.map(function (v) {
return v.notice.key;
}).indexOf(key);
var updatedNotices = notices.concat();
if (noticeIndex !== -1) {
updatedNotices.splice(noticeIndex, 1, {
notice: notice,
holderCallback: holderCallback
});
} else {
if (maxCount && notices.length >= maxCount) {
// XXX, use key of first item to update new added (let React to move exsiting
// instead of remove and mount). Same key was used before for both a) external
// manual control and b) internal react 'key' prop , which is not that good.
// eslint-disable-next-line no-param-reassign
notice.updateKey = updatedNotices[0].notice.updateKey || updatedNotices[0].notice.key;
updatedNotices.shift();
if (noticeIndex !== -1) {
updatedNotices.splice(noticeIndex, 1, {
notice: notice,
holderCallback: holderCallback
});
} else {
if (maxCount && notices.length >= maxCount) {
// XXX, use key of first item to update new added (let React to move exsiting
// instead of remove and mount). Same key was used before for both a) external
// manual control and b) internal react 'key' prop , which is not that good.
// eslint-disable-next-line no-param-reassign
notice.updateKey = updatedNotices[0].notice.updateKey || updatedNotices[0].notice.key;
updatedNotices.shift();
}
updatedNotices.push({
notice: notice,
holderCallback: holderCallback
});
}
updatedNotices.push({
notice: notice,
holderCallback: holderCallback
});
}
return {
notices: updatedNotices
};
});
};
return {
notices: updatedNotices
};
});
};
_this.remove = function (key) {
_this.setState(function (previousState) {
return {
notices: previousState.notices.filter(function (_ref) {
var notice = _ref.notice;
return notice.key !== key;
})
};
});
};
_this.remove = function (key) {
_this.setState(function (previousState) {
return {
notices: previousState.notices.filter(function (_ref) {
var notice = _ref.notice;
return notice.key !== key;
})
};
});
};
return _this;
}
return _this;
}
_createClass(Notification, [{
key: "getTransitionName",
value: function getTransitionName() {
var _this$props = this.props,
prefixCls = _this$props.prefixCls,
animation = _this$props.animation;
var transitionName = this.props.transitionName;
_createClass(Notification, [{
key: "getTransitionName",
value: function getTransitionName() {
var _this$props = this.props,
prefixCls = _this$props.prefixCls,
animation = _this$props.animation;
var transitionName = this.props.transitionName;
if (!transitionName && animation) {
transitionName = "".concat(prefixCls, "-").concat(animation);
}
if (!transitionName && animation) {
transitionName = "".concat(prefixCls, "-").concat(animation);
return transitionName;
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return transitionName;
}
}, {
key: "render",
value: function render() {
var _this2 = this;
var notices = this.state.notices;
var _this$props2 = this.props,
prefixCls = _this$props2.prefixCls,
className = _this$props2.className,
closeIcon = _this$props2.closeIcon,
style = _this$props2.style;
var noticeNodes = notices.map(function (_ref2, index) {
var notice = _ref2.notice,
holderCallback = _ref2.holderCallback;
var update = Boolean(index === notices.length - 1 && notice.updateKey);
var key = notice.updateKey ? notice.updateKey : notice.key;
var onClose = (0, _createChainedFunction.default)(_this2.remove.bind(_this2, notice.key), notice.onClose);
var notices = this.state.notices;
var _this$props2 = this.props,
prefixCls = _this$props2.prefixCls,
className = _this$props2.className,
closeIcon = _this$props2.closeIcon,
style = _this$props2.style;
var noticeNodes = notices.map(function (_ref2, index) {
var notice = _ref2.notice,
holderCallback = _ref2.holderCallback;
var update = Boolean(index === notices.length - 1 && notice.updateKey);
var key = notice.updateKey ? notice.updateKey : notice.key;
var onClose = createChainedFunction_1.default(_this2.remove.bind(_this2, notice.key), notice.onClose);
var noticeProps = _objectSpread(_objectSpread(_objectSpread({
prefixCls: prefixCls,
closeIcon: closeIcon
}, notice), notice.props), {}, {
key: key,
update: update,
onClose: onClose,
onClick: notice.onClick,
children: notice.content
});
var noticeProps = _objectSpread(_objectSpread(_objectSpread({
prefixCls: prefixCls,
closeIcon: closeIcon
}, notice), notice.props), {}, {
key: key,
update: update,
onClose: onClose,
onClick: notice.onClick,
children: notice.content
});
if (holderCallback) {
return _react.default.createElement("div", {
key: key,
className: "".concat(prefixCls, "-hook-holder"),
ref: function ref(div) {
if (typeof key === 'undefined') {
return;
}
if (holderCallback) {
return react_1.default.createElement("div", {
key: key,
className: "".concat(prefixCls, "-hook-holder"),
ref: function ref(div) {
if (typeof key === 'undefined') {
return;
if (div) {
_this2.hookRefs.set(key, div);
holderCallback(div, noticeProps);
} else {
_this2.hookRefs.delete(key);
}
}
});
}
if (div) {
_this2.hookRefs.set(key, div);
return _react.default.createElement(_Notice.default, Object.assign({}, noticeProps));
});
return _react.default.createElement("div", {
className: (0, _classnames.default)(prefixCls, className),
style: style
}, _react.default.createElement(_rcAnimate.default, {
transitionName: this.getTransitionName()
}, noticeNodes));
}
}]);
holderCallback(div, noticeProps);
} else {
_this2.hookRefs.delete(key);
}
}
});
}
return Notification;
}(_react.Component);
return react_1.default.createElement(Notice_1.default, Object.assign({}, noticeProps));
});
return react_1.default.createElement("div", {
className: classnames_1.default(prefixCls, className),
style: style
}, react_1.default.createElement(rc_animate_1.default, {
transitionName: this.getTransitionName()
}, noticeNodes));
Notification.defaultProps = {
prefixCls: 'rc-notification',
animation: 'fade',
style: {
top: 65,
left: '50%'
}
}]);
};
return Notification;
}(react_1.Component);
}();
Notification.defaultProps = {
prefixCls: 'rc-notification',
animation: 'fade',
style: {
top: 65,
left: '50%'
}
};
Notification.newInstance = function newNotificationInstance(properties, callback) {

@@ -268,3 +264,3 @@ var _ref3 = properties || {},

destroy: function destroy() {
react_dom_1.default.unmountComponentAtNode(div);
_reactDom.default.unmountComponentAtNode(div);

@@ -277,3 +273,3 @@ if (div.parentNode) {

useNotification: function useNotification() {
return useNotification_1.default(notification);
return (0, _useNotification2.default)(notification);
}

@@ -285,3 +281,3 @@ });

if (process.env.NODE_ENV === 'test' && properties.TEST_RENDER) {
properties.TEST_RENDER(react_1.default.createElement(Notification, Object.assign({}, props, {
properties.TEST_RENDER(_react.default.createElement(Notification, Object.assign({}, props, {
ref: ref

@@ -292,3 +288,3 @@ })));

react_dom_1.default.render(react_1.default.createElement(Notification, Object.assign({}, props, {
_reactDom.default.render(_react.default.createElement(Notification, Object.assign({}, props, {
ref: ref

@@ -298,2 +294,3 @@ })), div);

exports.default = Notification;
var _default = Notification;
exports.default = _default;
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useNotification;
var React = _interopRequireWildcard(require("react"));
var _Notice = _interopRequireDefault(require("./Notice"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

@@ -23,26 +40,2 @@

var __importStar = void 0 && (void 0).__importStar || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) {
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
}
result["default"] = mod;
return result;
};
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
var React = __importStar(require("react"));
var Notice_1 = __importDefault(require("./Notice"));
function useNotification(notificationInstance) {

@@ -61,3 +54,3 @@ var createdRef = React.useRef({});

if (div && !createdRef.current[key]) {
var noticeEle = React.createElement(Notice_1.default, Object.assign({}, props, {
var noticeEle = React.createElement(_Notice.default, Object.assign({}, props, {
holder: div

@@ -74,4 +67,2 @@ }));

return [notify, React.createElement(React.Fragment, null, elements)];
}
exports.default = useNotification;
}
{
"name": "rc-notification",
"version": "4.3.0",
"version": "4.3.2",
"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