UNPKG

tdesign-vue-next

Version:
147 lines (143 loc) 5.42 kB
/** * tdesign v1.11.5 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { createApp, nextTick } from 'vue'; import { MessageList, DEFAULT_Z_INDEX } from './message-list.js'; import { getAttach } from '../utils/dom.js'; import { isString, isObject } from 'lodash-es'; import './consts/index.js'; import './message.js'; import 'tdesign-icons-vue-next'; import '../loading/index.js'; import '../loading/directive.js'; import '../loading/plugin.js'; import '../loading/loading.js'; import '@babel/runtime/helpers/slicedToArray'; import '../loading/icon/gradient.js'; import '../hooks/useConfig.js'; import '../config-provider/hooks/useConfig.js'; import '../config-provider/utils/context.js'; import '../_chunks/dep-c75b9b8e.js'; import '@babel/runtime/helpers/typeof'; import '../_chunks/dep-caecb55d.js'; import 'dayjs'; import '../_chunks/dep-d60f6309.js'; import '../_chunks/dep-56c3d46e.js'; import '@babel/runtime/helpers/toConsumableArray'; import '@babel/runtime/helpers/objectWithoutProperties'; import '../_chunks/dep-7c56a7f5.js'; import '../utils/render-tnode.js'; import '../hooks/useTeleport.js'; import '../loading/props.js'; import '../utils/withInstall.js'; import './props.js'; import '../hooks/useGlobalIcon.js'; import './utils/animation.js'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var instanceMap = /* @__PURE__ */new Map(); function handleParams(params) { var options = _objectSpread({ duration: 3e3, attach: "body", zIndex: DEFAULT_Z_INDEX, placement: "top" }, params); options.content = params.content; return options; } var MessageFunction = function MessageFunction(props) { var options = handleParams(props); var attach = options.attach, placement = options.placement; var attachDom = getAttach(attach); if (!instanceMap.get(attachDom)) { instanceMap.set(attachDom, {}); } var p = instanceMap.get(attachDom)[placement]; var mgKey; if (!p) { var wrapper = document.createElement("div"); var instance = createApp(MessageList, { zIndex: options.zIndex, placement: options.placement }).mount(wrapper); mgKey = instance.add(options); instanceMap.get(attachDom)[placement] = instance; attachDom.appendChild(wrapper); } else { mgKey = p.add(options); } return new Promise(function (resolve) { var ins = instanceMap.get(attachDom)[placement]; nextTick(function () { var msg = ins.messageList; resolve(msg === null || msg === void 0 ? void 0 : msg.find(function (mg) { var _mg$$; return ((_mg$$ = mg.$) === null || _mg$$ === void 0 || (_mg$$ = _mg$$.vnode) === null || _mg$$ === void 0 ? void 0 : _mg$$.key) === mgKey; })); }); }); }; var showThemeMessage = function showThemeMessage(theme, params, duration) { var options = { theme: theme }; if (isString(params)) { options.content = params; } else if (isObject(params) && !(params instanceof Array)) { options = _objectSpread(_objectSpread({}, options), params); } (duration || duration === 0) && (options.duration = duration); return MessageFunction(options); }; var extraApi = { info: function info(params, duration) { return showThemeMessage("info", params, duration); }, success: function success(params, duration) { return showThemeMessage("success", params, duration); }, warning: function warning(params, duration) { return showThemeMessage("warning", params, duration); }, error: function error(params, duration) { return showThemeMessage("error", params, duration); }, question: function question(params, duration) { return showThemeMessage("question", params, duration); }, loading: function loading(params, duration) { return showThemeMessage("loading", params, duration); }, close: function close(promise) { promise.then(function (instance) { return instance === null || instance === void 0 ? void 0 : instance.close(); }); }, closeAll: function closeAll() { if (instanceMap instanceof Map) { instanceMap.forEach(function (attach) { Object.keys(attach).forEach(function (placement) { var instance = attach[placement]; instance.list = []; }); }); } } }; var MessagePlugin = showThemeMessage; MessagePlugin.install = function (app) { app.config.globalProperties.$message = showThemeMessage; Object.keys(extraApi).forEach(function (funcName) { app.config.globalProperties.$message[funcName] = extraApi[funcName]; }); }; Object.keys(extraApi).forEach(function (funcName) { MessagePlugin[funcName] = extraApi[funcName]; }); export { MessagePlugin, MessagePlugin as default }; //# sourceMappingURL=plugin.js.map