tdesign-vue-next
Version:
TDesign Component for vue-next
130 lines (126 loc) • 5.38 kB
JavaScript
/**
* tdesign v1.15.2
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _defineProperty } from '../_chunks/dep-0bd8597f.mjs';
import { createVNode, render, nextTick } from 'vue';
import NotificationList from './notification-list.mjs';
import { g as getAttach } from '../_chunks/dep-d58b61b6.mjs';
import './style/css.mjs';
import '../_chunks/dep-612a2c2b.mjs';
import '../_chunks/dep-15464fee.mjs';
import './notification.mjs';
import 'tdesign-icons-vue-next';
import 'lodash-es';
import '../_chunks/dep-465c43e8.mjs';
import '../_chunks/dep-d0add92f.mjs';
import '../_chunks/dep-32b59907.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-614f307d.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 './props.mjs';
import './utils/index.mjs';
import './utils/animate.mjs';
import './consts/index.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 seed = 0;
var instanceMap = /* @__PURE__ */new Map();
var NotificationFunction = function NotificationFunction(options, context) {
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 = createVNode(NotificationList, {
placement: hackOptions.placement
});
if (context !== null && context !== void 0 ? context : NotificationPlugin._context) {
instance.appContext = context !== null && context !== void 0 ? context : NotificationPlugin._context;
}
attachEl.appendChild(wrapper);
render(instance, wrapper);
instance.component.exposed.add(hackOptions);
instanceMap.get(attachEl)[hackOptions.placement] = instance;
tmpInstance = instance;
} else {
tmpInstance.component.exposed.add(hackOptions);
}
return new Promise(function (resolve) {
var ins = instanceMap.get(attachEl)[hackOptions.placement];
nextTick(function () {
var _ins$component$expose;
var notificationList = (_ins$component$expose = ins.component.exposed.notificationList.value) !== null && _ins$component$expose !== void 0 ? _ins$component$expose : [];
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, context) {
var hackOptions = _objectSpread(_objectSpread({}, options), {}, {
theme: theme
});
return NotificationFunction(hackOptions, context);
};
var extraApi = {
info: function info(options, context) {
return showThemeNotification("info", options, context);
},
success: function success(options, context) {
return showThemeNotification("success", options, context);
},
warning: function warning(options, context) {
return showThemeNotification("warning", options, context);
},
error: function error(options, context) {
return showThemeNotification("error", options, context);
},
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].component.exposed.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];
});
NotificationPlugin._context = app._context;
};
Object.keys(extraApi).forEach(function (funcName) {
NotificationPlugin[funcName] = extraApi[funcName];
});
var NotifyPlugin = NotificationPlugin;
export { NotifyPlugin, NotificationPlugin as default };
//# sourceMappingURL=plugin.mjs.map