PromoCursed/node_modules/.cache/babel-loader/8a035cc22b37963a7125fd0ebb88a881e06c1e80f2053f92ebda92ce06740047.json

1 line
24 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"\"use client\";\n\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\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 useMessage, { useInternalMessage } from './useMessage';\nimport { wrapPromiseFn } from './util';\nlet message = null;\nlet act = callback => callback();\nlet taskQueue = [];\nlet defaultGlobalConfig = {};\nfunction getGlobalContext() {\n const {\n getContainer,\n duration,\n rtl,\n maxCount,\n top\n } = defaultGlobalConfig;\n const mergedContainer = (getContainer === null || getContainer === void 0 ? void 0 : getContainer()) || document.body;\n return {\n getContainer: () => mergedContainer,\n duration,\n rtl,\n maxCount,\n top\n };\n}\nconst GlobalHolder = /*#__PURE__*/React.forwardRef((props, ref) => {\n const {\n messageConfig,\n sync\n } = props;\n const {\n getPrefixCls\n } = useContext(ConfigContext);\n const prefixCls = defaultGlobalConfig.prefixCls || getPrefixCls('message');\n const appConfig = useContext(AppConfigContext);\n const [api, holder] = useInternalMessage(Object.assign(Object.assign(Object.assign({}, messageConfig), {\n prefixCls\n }), appConfig.message));\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 [messageConfig, setMessageConfig] = React.useState(getGlobalContext);\n const sync = () => {\n setMessageConfig(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 messageConfig: messageConfig\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 (!message) {\n const holderFragment = document.createDocumentFragment();\n const newMessage = {\n fragment: holderFragment\n };\n message = newMessage;\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 // React 18 test env will throw if call immediately in ref\n Promise.resolve().then(() => {\n if (!newMessage.instance && instance) {\n newMessage.instance = instance;\n newMessage.sync = sync;\n flushNotice();\n }\n });\n }\n }), holderFragment);\n });\n return;\n }\n // Notification not ready\n if (!message.instance) {\n return;\n }\n // >>> Execute task\n taskQueue.forEach(task => {\n const {\n type,\n skipped\n } = task;\n // Only `skipped` when user call notice but cancel it immediately\n // and instance not ready\n if (!skipped) {\n switch (type) {\n case 'open':\n {\n act(() => {\n const closeFn = message.instance.open(Object.assign(Object.assign({}, defaultGlobalConfig), task.config));\n closeFn === null || closeFn === void 0 ? void 0 : closeFn.then(task.resolve);\n task.setCloseFn(closeFn);\n });\n break;\n