tdesign-mobile-vue
Version:
tdesign-mobile-vue
151 lines (147 loc) • 6.49 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import { ref, defineComponent, h, createApp, nextTick } from 'vue';
import Message from './message.js';
import { isBrowser } from '../shared/util.js';
import 'tdesign-icons-vue-next';
import 'lodash/isObject';
import 'lodash/isString';
import '../link/index.js';
import '../link/link.js';
import '../config.js';
import '../link/props.js';
import '../hooks/tnode.js';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../hooks/render-tnode.js';
import 'lodash/isEmpty';
import '../hooks/useClass.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
import '../_common/js/global-config/mobile/default-config.js';
import '../_common/js/global-config/mobile/locale/zh_CN.js';
import '../_chunks/dep-d5364bc4.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-eb734424.js';
import 'dayjs';
import '../form/hooks.js';
import 'lodash/isBoolean';
import '../shared/component.js';
import './props.js';
import '../shared/useVModel/index.js';
import 'lodash/isNumber';
var _excluded = ["context"];
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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 instanceMap = /* @__PURE__ */new Map();
function destroy(context, root) {
if (context.contains(root)) {
context.removeChild(root);
if (instanceMap.has(root)) {
instanceMap.delete(root);
}
}
}
function create(props) {
if (!isBrowser) return;
var context = props.context,
otherOptions = _objectWithoutProperties(props, _excluded);
if (!context) {
console.error("\u672A\u627E\u5230\u7EC4\u4EF6, \u8BF7\u786E\u8BA4 context \u662F\u5426\u6B63\u786E");
return;
}
var root = document.createElement("div");
context.appendChild(root);
var visible = ref(false);
var component = defineComponent({
render: function render() {
return h(Message, _objectSpread(_objectSpread({}, otherOptions), {}, {
visible: visible.value,
onDurationEnd: function onDurationEnd() {
var _otherOptions$onDurat;
(_otherOptions$onDurat = otherOptions.onDurationEnd) === null || _otherOptions$onDurat === void 0 || _otherOptions$onDurat.call(otherOptions);
visible.value = false;
},
onCloseBtnClick: function onCloseBtnClick() {
visible.value = false;
},
onAfterLeave: function onAfterLeave() {
destroy(context, root);
}
}));
}
});
createApp(component).mount(root);
instanceMap.set(root, {
context: context
});
nextTick(function () {
visible.value = true;
});
}
var defaultProps = {
align: "left",
closeBtn: false,
content: "",
duration: 3e3,
theme: "info",
visible: false,
zIndex: 5e3,
context: isBrowser ? document.body : null,
onDurationEnd: function onDurationEnd() {},
onCloseBtnClick: function onCloseBtnClick() {}
};
["info", "success", "warning", "error"].forEach(function (theme) {
Message[theme] = function (options) {
var props = _objectSpread(_objectSpread({}, defaultProps), {}, {
theme: theme
});
if (typeof options === "string") {
props.content = options;
} else {
props = _objectSpread(_objectSpread({}, props), options);
}
create(props);
};
});
Message.closeAll = function () {
if (instanceMap instanceof Map) {
var _iterator = _createForOfIteratorHelper(instanceMap),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _step$value = _slicedToArray(_step.value, 2),
key = _step$value[0],
value = _step$value[1];
var context = value.context;
destroy(context, key);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
};
Message.install = function (app) {
var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
app.component(name || Message.name, Message);
app.config.globalProperties.$message = Message;
};
var MessagePlugin = Message;
export { MessagePlugin, MessagePlugin as default };
//# sourceMappingURL=index.js.map