UNPKG

tdesign-vue-next

Version:
156 lines (152 loc) 6.09 kB
/** * tdesign v1.15.2 * (c) 2025 tdesign * @license MIT */ import { _ as _defineProperty } from '../_chunks/dep-0bd8597f.mjs'; import { createVNode, render, nextTick } from 'vue'; import { DEFAULT_Z_INDEX, MessageList } from './message-list.mjs'; import { g as getAttach } from '../_chunks/dep-d58b61b6.mjs'; import { isString, isObject } from 'lodash-es'; import '../_chunks/dep-612a2c2b.mjs'; import '../_chunks/dep-15464fee.mjs'; import './consts/index.mjs'; import './message.mjs'; import 'tdesign-icons-vue-next'; import '../loading/index.mjs'; import '../loading/directive.mjs'; import '../loading/plugin.mjs'; import '../loading/loading.mjs'; import '../_chunks/dep-614f307d.mjs'; import '../_chunks/dep-32b59907.mjs'; import '../loading/icon/gradient.mjs'; import '../_chunks/dep-465c43e8.mjs'; import '../_chunks/dep-d0add92f.mjs'; import '../config-provider/hooks/useConfig.mjs'; import '../config-provider/utils/context.mjs'; import '../_chunks/dep-afae046d.mjs'; import '../_chunks/dep-779bddf7.mjs'; import '../_chunks/dep-8a6c1499.mjs'; import '../_chunks/dep-5c28ada1.mjs'; import '../_chunks/dep-d913bc66.mjs'; import '../_chunks/dep-1690abc9.mjs'; import '../_chunks/dep-62c11543.mjs'; import '../_chunks/dep-27c2b283.mjs'; import '../_chunks/dep-67238d91.mjs'; import '../_chunks/dep-6b6765a0.mjs'; import '../_chunks/dep-3ea2b330.mjs'; import '../loading/props.mjs'; import './style/css.mjs'; import './props.mjs'; import './utils/index.mjs'; import './utils/animation.mjs'; 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, context) { 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 || !attachDom.contains(p.el)) { var wrapper = document.createElement("div"); var instance = createVNode(MessageList, { zIndex: options.zIndex, placement: options.placement }); if (context !== null && context !== void 0 ? context : MessagePlugin._context) { instance.appContext = context !== null && context !== void 0 ? context : MessagePlugin._context; } attachDom.appendChild(wrapper); render(instance, wrapper); mgKey = instance.component.exposed.add(options); instanceMap.get(attachDom)[placement] = instance; } else { mgKey = p.component.exposed.add(options); } return new Promise(function (resolve) { var ins = instanceMap.get(attachDom)[placement]; nextTick(function () { var msg = ins.component.exposed.messageList.value; 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, context) { 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, context); }; var extraApi = { info: function info(params, duration, context) { return showThemeMessage("info", params, duration, context); }, success: function success(params, duration, context) { return showThemeMessage("success", params, duration, context); }, warning: function warning(params, duration, context) { return showThemeMessage("warning", params, duration, context); }, error: function error(params, duration, context) { return showThemeMessage("error", params, duration, context); }, question: function question(params, duration, context) { return showThemeMessage("question", params, duration, context); }, loading: function loading(params, duration, context) { return showThemeMessage("loading", params, duration, context); }, 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.component.exposed.removeAll(); }); }); } } }; 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]; }); MessagePlugin._context = app._context; }; Object.keys(extraApi).forEach(function (funcName) { MessagePlugin[funcName] = extraApi[funcName]; }); export { MessagePlugin, MessagePlugin as default }; //# sourceMappingURL=plugin.mjs.map