1 line
15 KiB
JSON
1 line
15 KiB
JSON
{"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 notificationsRef.current.open(task.config);\n break;\n case 'close':\n notificationsRef.current.close(task.key);\n break;\n case 'destroy':\n notificationsRef.current.destroy();\n break;\n }\n });\n\n // React 17 will mix order of effect & setState in async\n // - open: setState[0]\n // - effect[0]\n // - open: setState[1]\n // - effect setState([]) * here will clean up [0, 1] in React 17\n setTaskQueue(function (oriQueue) {\n return oriQueue.filter(function (task) {\n return !taskQueue.includes(task);\n });\n });\n }\n }, [taskQueue]);\n\n // ======================== Return ========================\n return [api, contextHolder];\n}","map":{"version":3,"names":["_toConsumableArray","_slicedToArray","_objectWithoutProperties","_excluded","React","Notifications","defaultGetContainer","document","body","uniqueKey","mergeConfig","clone","_len","arguments","length","objList","Array","_key","forEach","obj","Object","keys","key","val","undefined","useNotification","rootConfig","_rootConfig$getContai","getContainer","motion","prefixCls","maxCount","className","style","onAllRemoved","stack","renderNotifications","shareConfig","_React$useState","useState","_React$useState2","container","setContainer","notificationsRef","useRef","contextHolder","createElement","ref","_React$useState3","_React$useState4","taskQueue","setTaskQueue","api","useMemo","open","config","mergedConfig","concat","queue","type","close","destroy","useEffect","current","task","oriQueue","filter","includes"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/rc-notification/es/hooks/useNotification.js"],"sourcesContent":["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 notificationsRef.current.open(task.config);\n break;\n case 'close':\n notificationsRef.current.close(task.key);\n break;\n case 'destroy':\n notificationsRef.current.destroy();\n break;\n }\n });\n\n // React 17 will mix order of effect & setState in async\n // - open: setState[0]\n // - effect[0]\n // - open: setState[1]\n // - effect setState([]) * here will clean up [0, 1] in React 17\n setTaskQueue(function (oriQueue) {\n return oriQueue.filter(function (task) {\n return !taskQueue.includes(task);\n });\n });\n }\n }, [taskQueue]);\n\n // ======================== Return ========================\n return [api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