tdesign-vue
Version:
162 lines (158 loc) • 5.83 kB
JavaScript
/**
* tdesign v1.14.1
* (c) 2025 tdesign
* @license MIT
*/
import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { MessageList, DEFAULT_Z_INDEX } from './messageList.js';
import { getAttach } from '../utils/dom.js';
import './const.js';
import './message.js';
import 'tdesign-icons-vue';
import '../loading/index.js';
import '../loading/directive.js';
import 'lodash-es';
import '../loading/plugin.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/setStyle.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import '../config-provider/config-receiver.js';
import '../config-provider/context.js';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-ba613a02.js';
import '../_chunks/dep-fdb1b253.js';
import 'dayjs';
import '../_common/js/global-config/t.js';
import '../utils/mixins.js';
import '../utils/render-tnode.js';
import '@babel/runtime/helpers/readOnlyError';
import '@vue/composition-api';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../config.js';
import 'raf';
import '../utils/easing.js';
import '../utils/withInstall.js';
import './props.js';
import './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();
var defaultMessageOptions = {
duration: 3e3,
attach: "body",
zIndex: DEFAULT_Z_INDEX,
placement: "top"
};
function handleParams(params) {
var options = _objectSpread(_objectSpread({}, defaultMessageOptions), 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 messageKey = null;
if (!p || !attachDom.contains(p.$el)) {
var instance = new MessageList({
propsData: {
zIndex: options.zIndex,
placement: options.placement
}
}).$mount();
messageKey = instance.add(options);
instanceMap.get(attachDom)[placement] = instance;
attachDom.appendChild(instance.$el);
} else {
messageKey = p.add(options);
}
return new Promise(function (resolve) {
var ins = instanceMap.get(attachDom)[placement];
ins.$nextTick(function () {
var msg = ins.$children;
resolve(messageKey ? ins.getMessageInstance(messageKey) : msg[msg.length - 1]);
});
});
};
var showThemeMessage = function showThemeMessage(theme, params, duration) {
var options = {
theme: theme
};
if (typeof params === "string") {
options.content = params;
} else if (_typeof(params) === "object" && !(params instanceof Array)) {
options = _objectSpread(_objectSpread({}, options), params);
}
(duration || duration === 0) && (options.duration = duration);
return MessageFunction(options);
};
var setMessageConfig = function setMessageConfig(_ref) {
var placement = _ref.placement,
attach = _ref.attach,
offset = _ref.offset,
zIndex = _ref.zIndex;
attach && (defaultMessageOptions.attach = attach);
offset && (defaultMessageOptions.offset = offset);
placement && (defaultMessageOptions.placement = placement);
zIndex && (defaultMessageOptions.zIndex = zIndex);
};
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.close();
});
},
closeAll: function closeAll() {
if (instanceMap instanceof Map) {
instanceMap.forEach(function (attach) {
Object.keys(attach).forEach(function (placement) {
var instance = attach[placement];
instance.list = [];
});
});
}
},
config: setMessageConfig
};
var MessagePlugin = showThemeMessage;
Object.keys(extraApi).forEach(function (funcName) {
MessagePlugin[funcName] = extraApi[funcName];
});
MessagePlugin.install = function () {
Vue.prototype.$message = MessagePlugin;
};
var message = MessagePlugin;
export { MessagePlugin, MessagePlugin as default, message };
//# sourceMappingURL=plugin.js.map