You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
12 KiB

3 months ago
  1. {"ast":null,"code":"import { defineComponent, ref, computed, onMounted, watch, openBlock, createBlock, Transition, unref, withCtx, withDirectives, createElementVNode, normalizeClass, normalizeStyle, createCommentVNode, resolveDynamicComponent, renderSlot, createElementBlock, toDisplayString, Fragment, withModifiers, createVNode, vShow } from 'vue';\nimport { useEventListener, useResizeObserver, useTimeoutFn } from '@vueuse/core';\nimport { ElBadge } from '../../badge/index.mjs';\nimport { ElIcon } from '../../icon/index.mjs';\nimport { messageProps, messageEmits } from './message.mjs';\nimport { getLastOffset, getOffsetOrSpace } from './instance.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { useGlobalComponentSettings } from '../../config-provider/src/hooks/use-global-config.mjs';\nimport { TypeComponentsMap, TypeComponents } from '../../../utils/vue/icon.mjs';\nimport { EVENT_CODE } from '../../../constants/aria.mjs';\nconst __default__ = defineComponent({\n name: \"ElMessage\"\n});\nconst _sfc_main = /* @__PURE__ */defineComponent({\n ...__default__,\n props: messageProps,\n emits: messageEmits,\n setup(__props, {\n expose\n }) {\n const props = __props;\n const {\n Close\n } = TypeComponents;\n const {\n ns,\n zIndex\n } = useGlobalComponentSettings(\"message\");\n const {\n currentZIndex,\n nextZIndex\n } = zIndex;\n const messageRef = ref();\n const visible = ref(false);\n const height = ref(0);\n let stopTimer = void 0;\n const badgeType = computed(() => props.type ? props.type === \"error\" ? \"danger\" : props.type : \"info\");\n const typeClass = computed(() => {\n const type = props.type;\n return {\n [ns.bm(\"icon\", type)]: type && TypeComponentsMap[type]\n };\n });\n const iconComponent = computed(() => props.icon || TypeComponentsMap[props.type] || \"\");\n const lastOffset = computed(() => getLastOffset(props.id));\n const offset = computed(() => getOffsetOrSpace(props.id, props.offset) + lastOffset.value);\n const bottom = computed(() => height.value + offset.value);\n const customStyle = computed(() => ({\n top: `${offset.value}px`,\n zIndex: currentZIndex.value\n }));\n function startTimer() {\n if (props.duration === 0) return;\n ({\n stop: stopTimer\n } = useTimeoutFn(() => {\n close();\n }, props.duration));\n }\n function clearTimer() {\n stopTimer == null ? void 0 : stopTimer();\n }\n function close() {\n visible.value = false;\n }\n function keydown({\n code\n }) {\n if (code === EVENT_CODE.esc) {\n close();\n }\n }\n onMounted(() => {\n startTimer();\n nextZIndex();\n visible.value = true;\n });\n watch(() => props.repeatNum, () => {\n clearTimer();\n startTimer();\n });\n useEventListener(document, \"keydown\", keydown);\n useResizeObserver(messageRef, () => {\n height.value = messageRef.value.getBoundingClientRect().height;\n });\n expose({\n visible,\n bottom,\n close\n });\n return (_ctx, _cache) => {\n return openBlock(), createBlock(Transition, {\n name: unref(ns).b(\"fade\"),\n onBeforeLeave: _ctx.onClose,\n onAfterLeave: $event => _ctx.$emit(\"destroy\"),\n persisted: \"\"\n }, {\n default: withCtx(() => [withDirectives(createElementVNode(\"div\", {\n id: _ctx.id,\n ref_key: \"messageRef\",\n ref: messageRef,\n class: normalizeClass([unref(ns).b(), {\n [unref(ns).m(_ctx.type)]: _ctx.type\n }, unref(ns).is(\"center\", _ctx.center), unref(ns).is(\"closable\", _ctx.showClose), unref(ns).is(\"plain\", _ctx.plain), _ctx.customClass]),\n style: normalizeStyle(unref(customStyle)),\n role: \"alert\",\n onMouseenter: clearTimer,\n onMouseleave: startTimer\n }, [_ctx.repeatNum > 1 ? (openBlock(), createBlock(unref(ElBadge),