PromoCursed/node_modules/.cache/babel-loader/55788949de8c0fb3d74913786142b619c4d3ff9ea5e18ddee3249582868881c8.json

1 line
17 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport NoticeList from \"./NoticeList\";\n// ant-notification ant-notification-topRight\nvar Notifications = /*#__PURE__*/React.forwardRef(function (props, ref) {\n var _props$prefixCls = props.prefixCls,\n prefixCls = _props$prefixCls === void 0 ? 'rc-notification' : _props$prefixCls,\n container = props.container,\n motion = props.motion,\n maxCount = props.maxCount,\n className = props.className,\n style = props.style,\n onAllRemoved = props.onAllRemoved,\n stack = props.stack,\n renderNotifications = props.renderNotifications;\n var _React$useState = React.useState([]),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n configList = _React$useState2[0],\n setConfigList = _React$useState2[1];\n\n // ======================== Close =========================\n var onNoticeClose = function onNoticeClose(key) {\n var _config$onClose;\n // Trigger close event\n var config = configList.find(function (item) {\n return item.key === key;\n });\n config === null || config === void 0 || (_config$onClose = config.onClose) === null || _config$onClose === void 0 || _config$onClose.call(config);\n setConfigList(function (list) {\n return list.filter(function (item) {\n return item.key !== key;\n });\n });\n };\n\n // ========================= Refs =========================\n React.useImperativeHandle(ref, function () {\n return {\n open: function open(config) {\n setConfigList(function (list) {\n var clone = _toConsumableArray(list);\n\n // Replace if exist\n var index = clone.findIndex(function (item) {\n return item.key === config.key;\n });\n var innerConfig = _objectSpread({}, config);\n if (index >= 0) {\n var _list$index;\n innerConfig.times = (((_list$index = list[index]) === null || _list$index === void 0 ? void 0 : _list$index.times) || 0) + 1;\n clone[index] = innerConfig;\n } else {\n innerConfig.times = 0;\n clone.push(innerConfig);\n }\n if (maxCount > 0 && clone.length > maxCount) {\n clone = clone.slice(-maxCount);\n }\n return clone;\n });\n },\n close: function close(key) {\n onNoticeClose(key);\n },\n destroy: function destroy() {\n setConfigList([]);\n }\n };\n });\n\n // ====================== Placements ======================\n var _React$useState3 = React.useState({}),\n _React$useState4 = _slicedToArray(_React$useState3, 2),\n placements = _React$useState4[0],\n setPlacements = _React$useState4[1];\n React.useEffect(function () {\n var nextPlacements = {};\n configList.forEach(function (config) {\n var _config$placement = config.placement,\n placement = _config$placement === void 0 ? 'topRight' : _config$placement;\n if (placement) {\n nextPlacements[placement] = nextPlacements[placement] || [];\n nextPlacements[placement].push(config);\n }\n });\n\n // Fill exist placements to avoid empty list causing remove without motion\n Object.keys(placements).forEach(function (placement) {\n nextPlacements[placement] = nextPlacements[placement] || [];\n });\n setPlacements(nextPlacements);\n }, [configList]);\n\n // Clean up container if all notices fade out\n var onAllNoticeRemoved = function onAllNoticeRemoved(placement) {\n setPlacements(function (originPlacements) {\n var clone = _objectSpread({}, originPlacements);\n var list = clone[placement] || [];\n if (!list.length) {\n delete clone[placement];\n }\n return clone;\n });\n };\n\n // Effect tell that