UNPKG

tdesign-vue

Version:
117 lines (113 loc) 4.18 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import Vue from 'vue'; import NotificationList from './notificationList.js'; import { getAttach } from '../utils/dom.js'; import './notification.js'; import 'lodash-es'; import 'tdesign-icons-vue'; import '../utils/render-tnode.js'; import '@babel/runtime/helpers/readOnlyError'; import '@babel/runtime/helpers/typeof'; import '@vue/composition-api'; import './props.js'; 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 '@babel/runtime/helpers/slicedToArray'; import '../utils/mixins.js'; import './const.js'; import 'raf'; import '../utils/easing.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 seed = 0; var instanceMap = /* @__PURE__ */new Map(); var NotificationFunction = function NotificationFunction(options) { seed += 1; var hackOptions = _objectSpread({ placement: "top-right", zIndex: 6e3, attach: "body", id: seed }, options); hackOptions.content = options.content ? options.content : ""; var attachEl = getAttach(hackOptions.attach); if (!instanceMap.get(attachEl)) { instanceMap.set(attachEl, {}); } var tmpInstance = instanceMap.get(attachEl)[hackOptions.placement]; if (!tmpInstance) { var list = new NotificationList({ propsData: { placement: hackOptions.placement } }); list.add(hackOptions); list.$mount(); instanceMap.get(attachEl)[hackOptions.placement] = list; attachEl.appendChild(list.$el); tmpInstance = instanceMap.get(attachEl)[hackOptions.placement]; } else { tmpInstance.add(hackOptions); } return new Promise(function (resolve) { tmpInstance.$nextTick(function () { var list = tmpInstance.$children; resolve(list[list.length - 1]); }); }); }; var showThemeNotification = function showThemeNotification(theme, options) { var hackOptions = _objectSpread(_objectSpread({}, options), {}, { theme: theme }); return NotificationFunction(hackOptions); }; var extraApi = { info: function info(options) { return showThemeNotification("info", options); }, success: function success(options) { return showThemeNotification("success", options); }, warning: function warning(options) { return showThemeNotification("warning", options); }, error: function error(options) { return showThemeNotification("error", options); }, close: function close(promise) { promise.then(function (instance) { return instance.close(); }); }, closeAll: function closeAll() { instanceMap.forEach(function (attach) { Object.keys(attach).forEach(function (placement) { attach[placement].removeAll(); }); }); } }; var NotificationPlugin = showThemeNotification; Object.keys(extraApi).forEach(function (funcName) { NotificationPlugin[funcName] = extraApi[funcName]; }); NotificationPlugin.install = function () { Vue.prototype.$notify = NotificationPlugin; Vue.prototype.$notification = NotificationPlugin; }; var notify = NotificationPlugin; var NotifyPlugin = NotificationPlugin; export { NotificationPlugin, NotifyPlugin, NotifyPlugin as default, notify }; //# sourceMappingURL=plugin.js.map