PromoCursed/node_modules/.cache/babel-loader/7df03e875f51bdf2de47775f66dd68711862223fd16f461be5d2925b6238dcd4.json

1 line
19 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"\"use client\";\n\nimport React, { useContext } from 'react';\nimport { render } from \"rc-util/es/React/render\";\nimport { AppConfigContext } from '../app/context';\nimport ConfigProvider, { ConfigContext, globalConfig, warnContext } from '../config-provider';\nimport PurePanel from './PurePanel';\nimport useNotification, { useInternalNotification } from './useNotification';\nlet notification = null;\nlet act = callback => callback();\nlet taskQueue = [];\nlet defaultGlobalConfig = {};\nfunction getGlobalContext() {\n const {\n getContainer,\n rtl,\n maxCount,\n top,\n bottom,\n showProgress,\n pauseOnHover\n } = defaultGlobalConfig;\n const mergedContainer = (getContainer === null || getContainer === void 0 ? void 0 : getContainer()) || document.body;\n return {\n getContainer: () => mergedContainer,\n rtl,\n maxCount,\n top,\n bottom,\n showProgress,\n pauseOnHover\n };\n}\nconst GlobalHolder = /*#__PURE__*/React.forwardRef((props, ref) => {\n const {\n notificationConfig,\n sync\n } = props;\n const {\n getPrefixCls\n } = useContext(ConfigContext);\n const prefixCls = defaultGlobalConfig.prefixCls || getPrefixCls('notification');\n const appConfig = useContext(AppConfigContext);\n const [api, holder] = useInternalNotification(Object.assign(Object.assign(Object.assign({}, notificationConfig), {\n prefixCls\n }), appConfig.notification));\n React.useEffect(sync, []);\n React.useImperativeHandle(ref, () => {\n const instance = Object.assign({}, api);\n Object.keys(instance).forEach(method => {\n instance[method] = function () {\n sync();\n return api[method].apply(api, arguments);\n };\n });\n return {\n instance,\n sync\n };\n });\n return holder;\n});\nconst GlobalHolderWrapper = /*#__PURE__*/React.forwardRef((_, ref) => {\n const [notificationConfig, setNotificationConfig] = React.useState(getGlobalContext);\n const sync = () => {\n setNotificationConfig(getGlobalContext);\n };\n React.useEffect(sync, []);\n const global = globalConfig();\n const rootPrefixCls = global.getRootPrefixCls();\n const rootIconPrefixCls = global.getIconPrefixCls();\n const theme = global.getTheme();\n const dom = /*#__PURE__*/React.createElement(GlobalHolder, {\n ref: ref,\n sync: sync,\n notificationConfig: notificationConfig\n });\n return /*#__PURE__*/React.createElement(ConfigProvider, {\n prefixCls: rootPrefixCls,\n iconPrefixCls: rootIconPrefixCls,\n theme: theme\n }, global.holderRender ? global.holderRender(dom) : dom);\n});\nfunction flushNotice() {\n if (!notification) {\n const holderFragment = document.createDocumentFragment();\n const newNotification = {\n fragment: holderFragment\n };\n notification = newNotification;\n // Delay render to avoid sync issue\n act(() => {\n render( /*#__PURE__*/React.createElement(GlobalHolderWrapper, {\n ref: node => {\n const {\n instance,\n sync\n } = node || {};\n Promise.resolve().then(() => {\n if (!newNotification.instance && instance) {\n newNotification.instance = instance;\n newNotification.sync = sync;\n flushNotice();\n }\n });\n }\n }), holderFragment);\n });\n return;\n }\n // Notification not ready\n if (!notification.instance) {\n return;\n }\n // >>> Execute task\n taskQueue.forEach(task => {\n // eslint-disable-next-line default-case\n switch (task.type) {\n case 'open':\n {\n act(() => {\n notification.instance.open(Object.assign(Object.assign({}, defaultGlobalConfig), task.config));\n });\n break;\n }\n case 'destroy':\n act(() => {\n notification === null || notification === void 0 ? void 0 : notification.instance.destroy(task.key);\n });\n break;\n }\n });\n // Clean up\n taskQueue = [];\n}\n// ===========================