UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

173 lines (165 loc) 6.66 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _defineProperty = require('@babel/runtime/helpers/defineProperty'); var vue = require('vue'); var message_messageList = require('./messageList.js'); var utils_dom = require('../utils/dom.js'); var isObject = require('lodash/isObject'); var isString = require('lodash/isString'); require('./const.js'); require('./message.js'); require('../_chunks/dep-9783e4ef.js'); require('../_chunks/dep-0a0a2988.js'); require('../_chunks/dep-38e8405e.js'); require('../_chunks/dep-0e9e4ce6.js'); require('../_chunks/dep-ac484abb.js'); require('../loading/index.js'); require('../loading/directive.js'); require('../loading/plugin.js'); require('../loading/loading.js'); require('@babel/runtime/helpers/slicedToArray'); require('../loading/icon/gradient.js'); require('../_common/js/loading/circle-adapter.js'); require('../_common/js/utils/set-style.js'); require('../_common/js/utils/helper.js'); require('@babel/runtime/helpers/toConsumableArray'); require('@babel/runtime/helpers/objectWithoutProperties'); require('lodash/isNull'); require('lodash/isUndefined'); require('lodash/isNumber'); require('lodash/isArray'); require('../hooks/useConfig.js'); require('../config-provider/useConfig.js'); require('lodash/isFunction'); require('lodash/cloneDeep'); require('../config-provider/context.js'); require('lodash/mergeWith'); require('lodash/merge'); require('../_common/js/global-config/default-config.js'); require('../_common/js/global-config/locale/en_US.js'); require('../_chunks/dep-8d10b59f.js'); require('../utils/render-tnode.js'); require('lodash/isEmpty'); require('lodash/camelCase'); require('lodash/kebabCase'); require('../loading/props.js'); require('../hooks/useTeleport.js'); require('../utils/easing.js'); require('../utils/withInstall.js'); require('./props.js'); require('./animation.js'); require('../hooks/tnode.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject); var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } var instanceMap = /* @__PURE__ */new Map(); function handleParams(params) { var options = _objectSpread({ duration: 3e3, attach: "body", zIndex: message_messageList.DEFAULT_Z_INDEX, placement: "top" }, 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 = utils_dom.getAttach(attach); if (!instanceMap.get(attachDom)) { instanceMap.set(attachDom, {}); } var p = instanceMap.get(attachDom)[placement]; var mgKey; if (!p) { var wrapper = document.createElement("div"); var instance = vue.createApp(message_messageList.MessageList, { zIndex: options.zIndex, placement: options.placement }).mount(wrapper); mgKey = instance.add(options); instanceMap.get(attachDom)[placement] = instance; attachDom.appendChild(wrapper); } else { mgKey = p.add(options); } return new Promise(function (resolve) { var ins = instanceMap.get(attachDom)[placement]; vue.nextTick(function () { var msg = ins.messageList; resolve(msg === null || msg === void 0 ? void 0 : msg.find(function (mg) { var _mg$$; return ((_mg$$ = mg.$) === null || _mg$$ === void 0 || (_mg$$ = _mg$$.vnode) === null || _mg$$ === void 0 ? void 0 : _mg$$.key) === mgKey; })); }); }); }; var showThemeMessage = function showThemeMessage(theme, params, duration) { var options = { theme: theme }; if (isString__default["default"](params)) { options.content = params; } else if (isObject__default["default"](params) && !(params instanceof Array)) { options = _objectSpread(_objectSpread({}, options), params); } (duration || duration === 0) && (options.duration = duration); return MessageFunction(options); }; 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 === null || instance === void 0 ? void 0 : 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 = []; }); }); } } }; var MessagePlugin = showThemeMessage; MessagePlugin.install = function (app) { app.config.globalProperties.$message = showThemeMessage; Object.keys(extraApi).forEach(function (funcName) { app.config.globalProperties.$message[funcName] = extraApi[funcName]; }); }; Object.keys(extraApi).forEach(function (funcName) { MessagePlugin[funcName] = extraApi[funcName]; }); exports["default"] = MessagePlugin; //# sourceMappingURL=plugin.js.map