UNPKG

tdesign-mobile-vue

Version:
115 lines (111 loc) 3.99 kB
/** * tdesign v1.15.0 * (c) 2026 TDesign Group * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { createApp } from 'vue'; import { isObject } from 'lodash-es'; import Toast from './toast.js'; import { getAttach } from '../shared/dom.js'; import { isBrowser } from '../shared/util.js'; import 'tdesign-icons-vue-next'; import '../hooks/tnode.js'; import '../hooks/render-tnode.js'; import '../_common/js/utils/general.js'; import '../overlay/index.js'; import '../overlay/overlay.js'; import '../config.js'; import '../overlay/props.js'; import '../hooks/useClass.js'; import '../config-provider/useConfig.js'; import '../config-provider/context.js'; import '../_common/js/global-config/mobile/default-config.js'; import '../_common/js/global-config/mobile/locale/zh_CN.js'; import '../_chunks/dep-5428cfc4.js'; import '@babel/runtime/helpers/typeof'; import '../_chunks/dep-db9f269e.js'; import 'dayjs'; import '../shared/component.js'; import './props.js'; import '../hooks/useLockScroll.js'; import '../_util/useTouch.js'; import '../_util/getScrollParent.js'; import '@babel/runtime/helpers/slicedToArray'; 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 instance = null; var app; function ToastPlugin(props) { var _instance; if (!isBrowser) return; var root = document.createElement("div"); var container = getAttach(isObject(props) ? props.attach : "body"); if (container) { container.appendChild(root); } else { console.error("attach is not exist"); } var propsObject = _objectSpread({ duration: 2e3 }, parseOptions(props)); (_instance = instance) === null || _instance === void 0 || _instance.clear(); instance = Toast; instance.clear = function () { clearTimeout(instance.timer); app.unmount(); root.remove(); if (propsObject.onClose) { propsObject.onClose(); } instance = null; }; if (propsObject.duration && propsObject.duration > 0) { instance.timer = setTimeout(function () { instance.clear(); if (propsObject.onDestroy) { propsObject.onDestroy(); } }, propsObject.duration); } app = createApp(instance, _objectSpread({}, propsObject)); app.mount(root); return instance; } ToastPlugin.clear = function () { var _instance2; return (_instance2 = instance) === null || _instance2 === void 0 ? void 0 : _instance2.clear(); }; ToastPlugin.error = function (options) { return ToastPlugin(_objectSpread(_objectSpread({}, parseOptions(options)), {}, { theme: "error" })); }; ToastPlugin.loading = function (options) { return ToastPlugin(_objectSpread(_objectSpread({}, parseOptions(options)), {}, { theme: "loading" })); }; ToastPlugin.warning = function (options) { return ToastPlugin(_objectSpread(_objectSpread({}, parseOptions(options)), {}, { theme: "warning" })); }; ToastPlugin.success = function (options) { return ToastPlugin(_objectSpread(_objectSpread({}, parseOptions(options)), {}, { theme: "success" })); }; function parseOptions(message) { if (typeof message === "string") { return { message: message }; } return message; } ToastPlugin.install = function (app2) { app2.config.globalProperties.$toast = ToastPlugin; }; export { ToastPlugin, ToastPlugin as default }; //# sourceMappingURL=plugin.js.map