PromoCursed/node_modules/.cache/babel-loader/1dcd7996a5edea82c38ba94c8605abb5c6c621bcbbfc73c015ea3100f5c04737.json

1 line
15 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nvar _excluded = [\"getContainer\", \"motion\", \"prefixCls\", \"maxCount\", \"className\", \"style\", \"onAllRemoved\", \"stack\", \"renderNotifications\"];\nimport * as React from 'react';\nimport Notifications from \"../Notifications\";\nvar defaultGetContainer = function defaultGetContainer() {\n return document.body;\n};\nvar uniqueKey = 0;\nfunction mergeConfig() {\n var clone = {};\n for (var _len = arguments.length, objList = new Array(_len), _key = 0; _key < _len; _key++) {\n objList[_key] = arguments[_key];\n }\n objList.forEach(function (obj) {\n if (obj) {\n Object.keys(obj).forEach(function (key) {\n var val = obj[key];\n if (val !== undefined) {\n clone[key] = val;\n }\n });\n }\n });\n return clone;\n}\nexport default function useNotification() {\n var rootConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n var _rootConfig$getContai = rootConfig.getContainer,\n getContainer = _rootConfig$getContai === void 0 ? defaultGetContainer : _rootConfig$getContai,\n motion = rootConfig.motion,\n prefixCls = rootConfig.prefixCls,\n maxCount = rootConfig.maxCount,\n className = rootConfig.className,\n style = rootConfig.style,\n onAllRemoved = rootConfig.onAllRemoved,\n stack = rootConfig.stack,\n renderNotifications = rootConfig.renderNotifications,\n shareConfig = _objectWithoutProperties(rootConfig, _excluded);\n var _React$useState = React.useState(),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n container = _React$useState2[0],\n setContainer = _React$useState2[1];\n var notificationsRef = React.useRef();\n var contextHolder = /*#__PURE__*/React.createElement(Notifications, {\n container: container,\n ref: notificationsRef,\n prefixCls: prefixCls,\n motion: motion,\n maxCount: maxCount,\n className: className,\n style: style,\n onAllRemoved: onAllRemoved,\n stack: stack,\n renderNotifications: renderNotifications\n });\n var _React$useState3 = React.useState([]),\n _React$useState4 = _slicedToArray(_React$useState3, 2),\n taskQueue = _React$useState4[0],\n setTaskQueue = _React$useState4[1];\n\n // ========================= Refs =========================\n var api = React.useMemo(function () {\n return {\n open: function open(config) {\n var mergedConfig = mergeConfig(shareConfig, config);\n if (mergedConfig.key === null || mergedConfig.key === undefined) {\n mergedConfig.key = \"rc-notification-\".concat(uniqueKey);\n uniqueKey += 1;\n }\n setTaskQueue(function (queue) {\n return [].concat(_toConsumableArray(queue), [{\n type: 'open',\n config: mergedConfig\n }]);\n });\n },\n close: function close(key) {\n setTaskQueue(function (queue) {\n return [].concat(_toConsumableArray(queue), [{\n type: 'close',\n key: key\n }]);\n });\n },\n destroy: function destroy() {\n setTaskQueue(function (queue) {\n return [].concat(_toConsumableArray(queue), [{\n type: 'destroy'\n }]);\n });\n }\n };\n }, []);\n\n // ======================= Container ======================\n // React 18 should all in effect that we will check container in each render\n // Which means getContainer should be stable.\n React.useEffect(function () {\n setContainer(getContainer());\n });\n\n // ======================== Effect ========================\n React.useEffect(function () {\n // Flush task when node ready\n if (notificationsRef.current && taskQueue.length) {\n taskQueue.forEach(function (task) {\n switch (task.type) {\n case 'open':\n