UNPKG

asp-smart-ui-plus-test

Version:

A Component Library for Vue 3

165 lines (158 loc) 6.37 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var core = require('@vueuse/core'); var index = require('element-plus/es/utils/index'); var index$2 = require('element-plus/es/constants/index'); var ElBadge = require('element-plus/es/components/badge/index'); var index$3 = require('element-plus/es/components/icon/index'); var index$1 = require('element-plus/es/hooks/index'); var message = require('./message.js'); var instance = require('./instance.js'); var pluginVue_exportHelper = require('../../../../../_virtual/plugin-vue_export-helper.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var ElBadge__default = /*#__PURE__*/_interopDefaultLegacy(ElBadge); const _hoisted_1 = ["id"]; const _hoisted_2 = ["innerHTML"]; const __default__ = vue.defineComponent({ name: "AspMessage" }); const _sfc_main = /* @__PURE__ */ vue.defineComponent({ ...__default__, props: message.messageProps, emits: message.messageEmits, setup(__props, { expose }) { const props = __props; const { Close } = index.TypeComponents; const ns = index$1.useNamespace("message"); const messageRef = vue.ref(); const visible = vue.ref(false); const height = vue.ref(0); let stopTimer = void 0; const badgeType = vue.computed( () => props.type ? props.type === "error" ? "danger" : props.type : "info" ); const typeClass = vue.computed(() => { const type = props.type; return { [ns.bm("icon", type)]: type && index.TypeComponentsMap[type] }; }); const iconComponent = vue.computed( () => props.icon || index.TypeComponentsMap[props.type] || "" ); const lastOffset = vue.computed(() => instance.getLastOffset(props.id)); const offset = vue.computed(() => props.offset + lastOffset.value); const bottom = vue.computed(() => height.value + offset.value); const customStyle = vue.computed(() => ({ top: `${offset.value}px`, zIndex: props.zIndex })); function startTimer() { if (props.duration === 0) return; ({ stop: stopTimer } = core.useTimeoutFn(() => { close(); }, props.duration)); } function clearTimer() { stopTimer == null ? void 0 : stopTimer(); } function close() { visible.value = false; } function keydown({ code }) { if (code === index$2.EVENT_CODE.esc) { close(); } } vue.onMounted(() => { startTimer(); visible.value = true; }); vue.watch( () => props.repeatNum, () => { clearTimer(); startTimer(); } ); core.useEventListener(document, "keydown", keydown); core.useResizeObserver(messageRef, () => { height.value = messageRef.value.getBoundingClientRect().height; }); expose({ visible, bottom, close }); return (_ctx, _cache) => { return vue.openBlock(), vue.createBlock(vue.Transition, { name: vue.unref(ns).b("fade"), onBeforeLeave: _ctx.onClose, onAfterLeave: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("destroy")), persisted: "" }, { default: vue.withCtx(() => [ vue.withDirectives(vue.createElementVNode("div", { id: _ctx.id, ref_key: "messageRef", ref: messageRef, class: vue.normalizeClass([ vue.unref(ns).b(), { [vue.unref(ns).m(_ctx.type)]: _ctx.type && !_ctx.icon }, vue.unref(ns).is("center", _ctx.center), vue.unref(ns).is("closable", _ctx.showClose), _ctx.customClass ]), style: vue.normalizeStyle(vue.unref(customStyle)), role: "alert", onMouseenter: clearTimer, onMouseleave: startTimer }, [ _ctx.repeatNum > 1 ? (vue.openBlock(), vue.createBlock(vue.unref(ElBadge__default["default"]), { key: 0, value: _ctx.repeatNum, type: vue.unref(badgeType), class: vue.normalizeClass(vue.unref(ns).e("badge")) }, null, 8, ["value", "type", "class"])) : vue.createCommentVNode("v-if", true), vue.unref(iconComponent) ? (vue.openBlock(), vue.createBlock(vue.unref(index$3.ElIcon), { key: 1, class: vue.normalizeClass([vue.unref(ns).e("icon"), vue.unref(typeClass)]) }, { default: vue.withCtx(() => [ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(vue.unref(iconComponent)))) ]), _: 1 }, 8, ["class"])) : vue.createCommentVNode("v-if", true), vue.renderSlot(_ctx.$slots, "default", {}, () => [ !_ctx.dangerouslyUseHTMLString ? (vue.openBlock(), vue.createElementBlock("p", { key: 0, class: vue.normalizeClass(vue.unref(ns).e("content")) }, vue.toDisplayString(_ctx.message), 3)) : (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 1 }, [ vue.createCommentVNode(" Caution here, message could've been compromised, never use user's input as message "), vue.createElementVNode("p", { class: vue.normalizeClass(vue.unref(ns).e("content")), innerHTML: _ctx.message }, null, 10, _hoisted_2) ], 2112)) ]), _ctx.showClose ? (vue.openBlock(), vue.createBlock(vue.unref(index$3.ElIcon), { key: 2, class: vue.normalizeClass(vue.unref(ns).e("closeBtn")), onClick: vue.withModifiers(close, ["stop"]) }, { default: vue.withCtx(() => [ vue.createVNode(vue.unref(Close)) ]), _: 1 }, 8, ["class", "onClick"])) : vue.createCommentVNode("v-if", true) ], 46, _hoisted_1), [ [vue.vShow, visible.value] ]) ]), _: 3 }, 8, ["name", "onBeforeLeave"]); }; } }); var MessageConstructor = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "E:\\code\\SmartUIPlus\\asp-packages\\components\\pc\\basic\\message\\src\\message.vue"]]); exports["default"] = MessageConstructor;