tdesign-vue-next
Version:
TDesign Component for vue-next
115 lines (111 loc) • 4.42 kB
JavaScript
/**
* tdesign v1.11.5
* (c) 2025 tdesign
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { createApp, nextTick } from 'vue';
import NotificationList from './notification-list.js';
import { getAttach } from '../utils/dom.js';
import './notification.js';
import 'tdesign-icons-vue-next';
import 'lodash-es';
import '../_chunks/dep-7c56a7f5.js';
import '../utils/render-tnode.js';
import './props.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 '../hooks/useGlobalIcon.js';
import './utils/animate.js';
import './consts/index.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 wrapper = document.createElement("div");
var instance = createApp(NotificationList, {
placement: hackOptions.placement
}).mount(wrapper);
instance.add(hackOptions);
instanceMap.get(attachEl)[hackOptions.placement] = instance;
tmpInstance = instance;
attachEl.appendChild(instance.$el);
} else {
tmpInstance.add(hackOptions);
}
return new Promise(function (resolve) {
var ins = instanceMap.get(attachEl)[hackOptions.placement];
nextTick(function () {
var notificationList = ins.notificationList;
resolve(notificationList === null || notificationList === void 0 ? void 0 : notificationList.find(function (notify) {
var _notify$$;
return ((_notify$$ = notify.$) === null || _notify$$ === void 0 || (_notify$$ = _notify$$.vnode) === null || _notify$$ === void 0 ? void 0 : _notify$$.key) === hackOptions.id;
}));
});
});
};
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;
NotificationPlugin.install = function (app) {
app.config.globalProperties.$notify = showThemeNotification;
Object.keys(extraApi).forEach(function (funcName) {
app.config.globalProperties.$notify[funcName] = extraApi[funcName];
});
};
Object.keys(extraApi).forEach(function (funcName) {
NotificationPlugin[funcName] = extraApi[funcName];
});
var NotifyPlugin = NotificationPlugin;
export { NotifyPlugin, NotificationPlugin as default };
//# sourceMappingURL=plugin.js.map