ivue-material-plus
Version:
A high quality UI components Library with Vue.js
136 lines (131 loc) • 3.29 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var transferQueue = require('../../utils/transfer-queue.js');
var index = require('./index2.js');
const instances = [];
let name = 1;
let top;
let defaultDuration;
const prefixKey = "ivue_message_key_";
const notificationsId = {};
const message = (type, options) => {
const customizeId = options.id;
const id = customizeId || `${prefixKey}${name++}`;
if (notificationsId[customizeId]) {
return;
}
const userOnClose = options.onClose;
if (typeof options === "string") {
options = {
content: options
};
}
let verticalOffset = top || options.top || 20;
instances.forEach(({ vm: vm2 }) => {
verticalOffset += (vm2.el.offsetHeight || 0) + 16;
});
verticalOffset += 16;
options.duration = defaultDuration || options.duration;
const handleGetIndex = () => {
transferQueue.transferIncrease();
return transferQueue.transferIndex;
};
const tIndex = handleGetIndex();
options = {
...options,
type,
onClose: () => {
close(id, userOnClose);
},
top: verticalOffset,
id,
zIndex: 1010 + tIndex
};
const vm = vue.createVNode(
index["default"],
options,
vue.isVNode(options.content) ? { default: () => message } : null
);
const container = document.createElement("div");
if (customizeId) {
notificationsId[id] = { vm };
}
vm.props.onDestroy = () => {
vue.render(null, container);
};
vue.render(vm, container);
instances.push({ vm });
document.body.appendChild(container.firstElementChild);
return {
close
};
};
const close = (id, userOnClose) => {
const orientedNotifications = instances;
const idx = orientedNotifications.findIndex(({ vm: vm2 }) => {
if (!vm2) {
return;
}
return vm2.component.props.id === id;
});
if (idx === -1) {
return;
}
const { vm } = orientedNotifications[idx];
if (!vm) {
return;
}
userOnClose == null ? void 0 : userOnClose(vm);
const removedHeight = vm.el.offsetHeight;
if (notificationsId[id]) {
orientedNotifications[idx].vm.component.proxy.data.visible = false;
delete notificationsId[id];
}
orientedNotifications.splice(idx, 1);
const len = orientedNotifications.length;
if (len < 1) {
return;
}
for (let i = idx; i < len; i++) {
const { el, component } = orientedNotifications[i].vm;
const pos = parseInt(el.style["top"], 10) - removedHeight - 16;
component.props.top = pos;
}
};
const closeAll = () => {
for (const key in instances) {
instances.forEach(({ vm }) => {
vm.component.proxy.data.visible = false;
});
}
};
var Message = {
info(options) {
return message("info", options);
},
success(options) {
return message("success", options);
},
warning(options) {
return message("warning", options);
},
error(options) {
return message("error", options);
},
loading(options) {
return message("loading", options);
},
config(options) {
if (options.top) {
top = options.top;
}
if (options.duration && options.duration > 0) {
defaultDuration = options.duration;
}
},
close,
closeAll
};
exports["default"] = Message;
//# sourceMappingURL=message.js.map