This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import type { ComponentInternalInstance, VNode } from 'vue';
import type { Mutable } from 'element-plus/es/utils';
import type { MessageHandler, MessagePlacement, MessageProps } from './message';
export type MessageContext = {
id: string;
vnode: VNode;
handler: MessageHandler;
vm: ComponentInternalInstance;
props: Mutable<MessageProps>;
};
export declare const placementInstances: import("vue").ShallowReactive<Record<"top" | "bottom" | "top-left" | "top-right" | "bottom-left" | "bottom-right", MessageContext[]>>;
export declare const getOrCreatePlacementInstances: (placement: MessagePlacement) => MessageContext[];
export declare const getInstance: (id: string, placement: MessagePlacement) => {
current: MessageContext;
prev: MessageContext | undefined;
};
export declare const getLastOffset: (id: string, placement: MessagePlacement) => number;
export declare const getOffsetOrSpace: (id: string, offset: number, placement: MessagePlacement) => number;

View File

@@ -0,0 +1,33 @@
import { shallowReactive } from 'vue';
const placementInstances = shallowReactive({});
const getOrCreatePlacementInstances = (placement) => {
if (!placementInstances[placement]) {
placementInstances[placement] = shallowReactive([]);
}
return placementInstances[placement];
};
const getInstance = (id, placement) => {
const instances = placementInstances[placement] || [];
const idx = instances.findIndex((instance) => instance.id === id);
const current = instances[idx];
let prev;
if (idx > 0) {
prev = instances[idx - 1];
}
return { current, prev };
};
const getLastOffset = (id, placement) => {
const { prev } = getInstance(id, placement);
if (!prev)
return 0;
return prev.vm.exposed.bottom.value;
};
const getOffsetOrSpace = (id, offset, placement) => {
const instances = placementInstances[placement] || [];
const idx = instances.findIndex((instance) => instance.id === id);
return idx > 0 ? 16 : offset;
};
export { getInstance, getLastOffset, getOffsetOrSpace, getOrCreatePlacementInstances, placementInstances };
//# sourceMappingURL=instance.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"instance.mjs","sources":["../../../../../../packages/components/message/src/instance.ts"],"sourcesContent":["import { shallowReactive } from 'vue'\n\nimport type { ComponentInternalInstance, VNode } from 'vue'\nimport type { Mutable } from '@element-plus/utils'\nimport type { MessageHandler, MessagePlacement, MessageProps } from './message'\n\nexport type MessageContext = {\n id: string\n vnode: VNode\n handler: MessageHandler\n vm: ComponentInternalInstance\n props: Mutable<MessageProps>\n}\n\nexport const placementInstances = shallowReactive(\n {} as Record<MessagePlacement, MessageContext[]>\n)\n\nexport const getOrCreatePlacementInstances = (placement: MessagePlacement) => {\n if (!placementInstances[placement]) {\n placementInstances[placement] = shallowReactive([])\n }\n return placementInstances[placement]\n}\n\nexport const getInstance = (id: string, placement: MessagePlacement) => {\n const instances = placementInstances[placement] || []\n const idx = instances.findIndex((instance) => instance.id === id)\n const current = instances[idx]\n let prev: MessageContext | undefined\n if (idx > 0) {\n prev = instances[idx - 1]\n }\n return { current, prev }\n}\n\nexport const getLastOffset = (\n id: string,\n placement: MessagePlacement\n): number => {\n const { prev } = getInstance(id, placement)\n if (!prev) return 0\n return prev.vm.exposed!.bottom.value\n}\n\nexport const getOffsetOrSpace = (\n id: string,\n offset: number,\n placement: MessagePlacement\n) => {\n const instances = placementInstances[placement] || []\n const idx = instances.findIndex((instance) => instance.id === id)\n return idx > 0 ? 16 : offset\n}\n"],"names":[],"mappings":";;AACY,MAAC,kBAAkB,GAAG,eAAe,CAAC,EAAE,EAAE;AAC1C,MAAC,6BAA6B,GAAG,CAAC,SAAS,KAAK;AAC5D,EAAE,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE;AACtC,IAAI,kBAAkB,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;AACxD,GAAG;AACH,EAAE,OAAO,kBAAkB,CAAC,SAAS,CAAC,CAAC;AACvC,EAAE;AACU,MAAC,WAAW,GAAG,CAAC,EAAE,EAAE,SAAS,KAAK;AAC9C,EAAE,MAAM,SAAS,GAAG,kBAAkB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;AACxD,EAAE,MAAM,GAAG,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AACpE,EAAE,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;AACjC,EAAE,IAAI,IAAI,CAAC;AACX,EAAE,IAAI,GAAG,GAAG,CAAC,EAAE;AACf,IAAI,IAAI,GAAG,SAAS,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AAC9B,GAAG;AACH,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,EAAE;AACU,MAAC,aAAa,GAAG,CAAC,EAAE,EAAE,SAAS,KAAK;AAChD,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;AAC9C,EAAE,IAAI,CAAC,IAAI;AACX,IAAI,OAAO,CAAC,CAAC;AACb,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;AACtC,EAAE;AACU,MAAC,gBAAgB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,KAAK;AAC3D,EAAE,MAAM,SAAS,GAAG,kBAAkB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;AACxD,EAAE,MAAM,GAAG,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AACpE,EAAE,OAAO,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC;AAC/B;;;;"}

View File

@@ -0,0 +1,108 @@
import type { AppContext, ExtractPropTypes, VNode, __ExtractPublicPropTypes } from 'vue';
import type { Mutable } from 'element-plus/es/utils';
import type MessageConstructor from './message.vue';
export declare const messageTypes: readonly ["primary", "success", "info", "warning", "error"];
export declare const messagePlacement: readonly ["top", "top-left", "top-right", "bottom", "bottom-left", "bottom-right"];
export declare const MESSAGE_DEFAULT_PLACEMENT = "top";
export type MessageType = typeof messageTypes[number];
export type MessagePlacement = typeof messagePlacement[number];
/** @deprecated please use `MessageType` instead */
export type messageType = MessageType;
export interface MessageConfigContext {
max?: number;
grouping?: boolean;
duration?: number;
offset?: number;
showClose?: boolean;
plain?: boolean;
placement?: string;
}
export declare const messageDefaults: Mutable<{
readonly customClass: "";
readonly dangerouslyUseHTMLString: false;
readonly duration: 3000;
readonly icon: undefined;
readonly id: "";
readonly message: "";
readonly onClose: undefined;
readonly showClose: false;
readonly type: "info";
readonly plain: false;
readonly offset: 16;
readonly placement: undefined;
readonly zIndex: 0;
readonly grouping: false;
readonly repeatNum: 1;
readonly appendTo: HTMLElement;
}>;
export declare const messageProps: {
readonly customClass: import("element-plus/es/utils").EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
readonly dangerouslyUseHTMLString: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly duration: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 3000, boolean>;
readonly icon: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => (string | import("vue").Component) & {}) | (() => string | import("vue").Component) | ((new (...args: any[]) => (string | import("vue").Component) & {}) | (() => string | import("vue").Component))[], unknown, unknown, undefined, boolean>;
readonly id: import("element-plus/es/utils").EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
readonly message: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => string | VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => VNode)) | (() => string | VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => VNode)) | ((new (...args: any[]) => string | VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => VNode)) | (() => string | VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => VNode)))[], unknown, unknown, "", boolean>;
readonly onClose: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => () => void) | (() => () => void) | {
(): () => void;
new (): any;
readonly prototype: any;
} | ((new (...args: any[]) => () => void) | (() => () => void) | {
(): () => void;
new (): any;
readonly prototype: any;
})[], unknown, unknown, undefined, boolean>;
readonly showClose: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly type: import("element-plus/es/utils").EpPropFinalized<StringConstructor, "error" | "primary" | "success" | "warning" | "info", unknown, "info", boolean>;
readonly plain: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly offset: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 16, boolean>;
readonly placement: import("element-plus/es/utils").EpPropFinalized<StringConstructor, "top" | "bottom" | "top-left" | "top-right" | "bottom-left" | "bottom-right", unknown, undefined, boolean>;
readonly zIndex: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 0, boolean>;
readonly grouping: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly repeatNum: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 1, boolean>;
};
export type MessageProps = ExtractPropTypes<typeof messageProps>;
export type MessagePropsPublic = __ExtractPublicPropTypes<typeof messageProps>;
export declare const messageEmits: {
destroy: () => boolean;
};
export type MessageEmits = typeof messageEmits;
export type MessageInstance = InstanceType<typeof MessageConstructor> & unknown;
export type MessageOptions = Partial<Mutable<Omit<MessageProps, 'id'> & {
appendTo?: HTMLElement | string;
}>>;
export type MessageParams = MessageOptions | MessageOptions['message'];
export type MessageParamsNormalized = Omit<MessageProps, 'id'> & {
/**
* @description set the root element for the message, default to `document.body`
*/
appendTo: HTMLElement;
};
export type MessageOptionsWithType = Omit<MessageOptions, 'type'>;
export type MessageParamsWithType = MessageOptionsWithType | MessageOptions['message'];
export interface MessageHandler {
/**
* @description close the Message
*/
close: () => void;
}
export type MessageFn = {
(options?: MessageParams, appContext?: null | AppContext): MessageHandler;
closeAll(type?: MessageType): void;
closeAllByPlacement(position: MessagePlacement): void;
};
export type MessageTypedFn = (options?: MessageParamsWithType, appContext?: null | AppContext) => MessageHandler;
export type Message = MessageFn & {
primary: MessageTypedFn;
success: MessageTypedFn;
warning: MessageTypedFn;
info: MessageTypedFn;
error: MessageTypedFn;
};

View File

@@ -0,0 +1,172 @@
import { defineComponent, ref, computed, onMounted, watch, openBlock, createBlock, Transition, unref, withCtx, withDirectives, createElementVNode, normalizeClass, normalizeStyle, createCommentVNode, resolveDynamicComponent, renderSlot, createElementBlock, toDisplayString, Fragment, withModifiers, createVNode, vShow, nextTick } from 'vue';
import { useEventListener, useResizeObserver, useTimeoutFn } from '@vueuse/core';
import { ElBadge } from '../../badge/index.mjs';
import { ElIcon } from '../../icon/index.mjs';
import { messageProps, messageEmits, MESSAGE_DEFAULT_PLACEMENT } from './message2.mjs';
import { getLastOffset, getOffsetOrSpace } from './instance.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import { useGlobalComponentSettings } from '../../config-provider/src/hooks/use-global-config.mjs';
import { TypeComponentsMap, TypeComponents } from '../../../utils/vue/icon.mjs';
import { EVENT_CODE } from '../../../constants/aria.mjs';
const __default__ = defineComponent({
name: "ElMessage"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
...__default__,
props: messageProps,
emits: messageEmits,
setup(__props, { expose, emit }) {
const props = __props;
const { Close } = TypeComponents;
const isStartTransition = ref(false);
const { ns, zIndex } = useGlobalComponentSettings("message");
const { currentZIndex, nextZIndex } = zIndex;
const messageRef = ref();
const visible = ref(false);
const height = ref(0);
let stopTimer = void 0;
const badgeType = computed(() => props.type ? props.type === "error" ? "danger" : props.type : "info");
const typeClass = computed(() => {
const type = props.type;
return { [ns.bm("icon", type)]: type && TypeComponentsMap[type] };
});
const iconComponent = computed(() => props.icon || TypeComponentsMap[props.type] || "");
const placement = computed(() => props.placement || MESSAGE_DEFAULT_PLACEMENT);
const lastOffset = computed(() => getLastOffset(props.id, placement.value));
const offset = computed(() => {
return getOffsetOrSpace(props.id, props.offset, placement.value) + lastOffset.value;
});
const bottom = computed(() => height.value + offset.value);
const horizontalClass = computed(() => {
if (placement.value.includes("left"))
return ns.is("left");
if (placement.value.includes("right"))
return ns.is("right");
return ns.is("center");
});
const verticalProperty = computed(() => placement.value.startsWith("top") ? "top" : "bottom");
const customStyle = computed(() => ({
[verticalProperty.value]: `${offset.value}px`,
zIndex: currentZIndex.value
}));
function startTimer() {
if (props.duration === 0)
return;
({ stop: stopTimer } = useTimeoutFn(() => {
close();
}, props.duration));
}
function clearTimer() {
stopTimer == null ? void 0 : stopTimer();
}
function close() {
visible.value = false;
nextTick(() => {
var _a;
if (!isStartTransition.value) {
(_a = props.onClose) == null ? void 0 : _a.call(props);
emit("destroy");
}
});
}
function keydown({ code }) {
if (code === EVENT_CODE.esc) {
close();
}
}
onMounted(() => {
startTimer();
nextZIndex();
visible.value = true;
});
watch(() => props.repeatNum, () => {
clearTimer();
startTimer();
});
useEventListener(document, "keydown", keydown);
useResizeObserver(messageRef, () => {
height.value = messageRef.value.getBoundingClientRect().height;
});
expose({
visible,
bottom,
close
});
return (_ctx, _cache) => {
return openBlock(), createBlock(Transition, {
name: unref(ns).b("fade"),
onBeforeEnter: ($event) => isStartTransition.value = true,
onBeforeLeave: _ctx.onClose,
onAfterLeave: ($event) => _ctx.$emit("destroy"),
persisted: ""
}, {
default: withCtx(() => [
withDirectives(createElementVNode("div", {
id: _ctx.id,
ref_key: "messageRef",
ref: messageRef,
class: normalizeClass([
unref(ns).b(),
{ [unref(ns).m(_ctx.type)]: _ctx.type },
unref(ns).is("closable", _ctx.showClose),
unref(ns).is("plain", _ctx.plain),
unref(ns).is("bottom", unref(verticalProperty) === "bottom"),
unref(horizontalClass),
_ctx.customClass
]),
style: normalizeStyle(unref(customStyle)),
role: "alert",
onMouseenter: clearTimer,
onMouseleave: startTimer
}, [
_ctx.repeatNum > 1 ? (openBlock(), createBlock(unref(ElBadge), {
key: 0,
value: _ctx.repeatNum,
type: unref(badgeType),
class: normalizeClass(unref(ns).e("badge"))
}, null, 8, ["value", "type", "class"])) : createCommentVNode("v-if", true),
unref(iconComponent) ? (openBlock(), createBlock(unref(ElIcon), {
key: 1,
class: normalizeClass([unref(ns).e("icon"), unref(typeClass)])
}, {
default: withCtx(() => [
(openBlock(), createBlock(resolveDynamicComponent(unref(iconComponent))))
]),
_: 1
}, 8, ["class"])) : createCommentVNode("v-if", true),
renderSlot(_ctx.$slots, "default", {}, () => [
!_ctx.dangerouslyUseHTMLString ? (openBlock(), createElementBlock("p", {
key: 0,
class: normalizeClass(unref(ns).e("content"))
}, toDisplayString(_ctx.message), 3)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
createCommentVNode(" Caution here, message could've been compromised, never use user's input as message "),
createElementVNode("p", {
class: normalizeClass(unref(ns).e("content")),
innerHTML: _ctx.message
}, null, 10, ["innerHTML"])
], 2112))
]),
_ctx.showClose ? (openBlock(), createBlock(unref(ElIcon), {
key: 2,
class: normalizeClass(unref(ns).e("closeBtn")),
onClick: withModifiers(close, ["stop"])
}, {
default: withCtx(() => [
createVNode(unref(Close))
]),
_: 1
}, 8, ["class", "onClick"])) : createCommentVNode("v-if", true)
], 46, ["id"]), [
[vShow, visible.value]
])
]),
_: 3
}, 8, ["name", "onBeforeEnter", "onBeforeLeave", "onAfterLeave"]);
};
}
});
var MessageConstructor = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "message.vue"]]);
export { MessageConstructor as default };
//# sourceMappingURL=message.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,108 @@
declare function close(): void;
declare function __VLS_template(): {
default?(_: {}): any;
};
declare const __VLS_component: import("vue").DefineComponent<{
readonly customClass: import("element-plus/es/utils").EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
readonly dangerouslyUseHTMLString: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly duration: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 3000, boolean>;
readonly icon: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => (string | import("vue").Component) & {}) | (() => string | import("vue").Component) | ((new (...args: any[]) => (string | import("vue").Component) & {}) | (() => string | import("vue").Component))[], unknown, unknown, undefined, boolean>;
readonly id: import("element-plus/es/utils").EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
readonly message: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)) | (() => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)) | ((new (...args: any[]) => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)) | (() => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)))[], unknown, unknown, "", boolean>;
readonly onClose: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => () => void) | (() => () => void) | {
(): () => void;
new (): any;
readonly prototype: any;
} | ((new (...args: any[]) => () => void) | (() => () => void) | {
(): () => void;
new (): any;
readonly prototype: any;
})[], unknown, unknown, undefined, boolean>;
readonly showClose: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly type: import("element-plus/es/utils").EpPropFinalized<StringConstructor, "error" | "primary" | "success" | "warning" | "info", unknown, "info", boolean>;
readonly plain: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly offset: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 16, boolean>;
readonly placement: import("element-plus/es/utils").EpPropFinalized<StringConstructor, "top" | "bottom" | "top-left" | "top-right" | "bottom-left" | "bottom-right", unknown, undefined, boolean>;
readonly zIndex: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 0, boolean>;
readonly grouping: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly repeatNum: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 1, boolean>;
}, {
visible: import("vue").Ref<boolean>;
bottom: import("vue").ComputedRef<number>;
close: typeof close;
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
destroy: () => void;
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
readonly customClass: import("element-plus/es/utils").EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
readonly dangerouslyUseHTMLString: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly duration: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 3000, boolean>;
readonly icon: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => (string | import("vue").Component) & {}) | (() => string | import("vue").Component) | ((new (...args: any[]) => (string | import("vue").Component) & {}) | (() => string | import("vue").Component))[], unknown, unknown, undefined, boolean>;
readonly id: import("element-plus/es/utils").EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
readonly message: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)) | (() => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)) | ((new (...args: any[]) => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)) | (() => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)))[], unknown, unknown, "", boolean>;
readonly onClose: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => () => void) | (() => () => void) | {
(): () => void;
new (): any;
readonly prototype: any;
} | ((new (...args: any[]) => () => void) | (() => () => void) | {
(): () => void;
new (): any;
readonly prototype: any;
})[], unknown, unknown, undefined, boolean>;
readonly showClose: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly type: import("element-plus/es/utils").EpPropFinalized<StringConstructor, "error" | "primary" | "success" | "warning" | "info", unknown, "info", boolean>;
readonly plain: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly offset: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 16, boolean>;
readonly placement: import("element-plus/es/utils").EpPropFinalized<StringConstructor, "top" | "bottom" | "top-left" | "top-right" | "bottom-left" | "bottom-right", unknown, undefined, boolean>;
readonly zIndex: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 0, boolean>;
readonly grouping: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, false, boolean>;
readonly repeatNum: import("element-plus/es/utils").EpPropFinalized<NumberConstructor, unknown, unknown, 1, boolean>;
}>> & {
onDestroy?: (() => any) | undefined;
}, {
readonly zIndex: number;
readonly offset: number;
readonly icon: import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => (string | import("vue").Component) & {}) | (() => string | import("vue").Component) | ((new (...args: any[]) => (string | import("vue").Component) & {}) | (() => string | import("vue").Component))[], unknown, unknown>;
readonly id: string;
readonly type: import("element-plus/es/utils").EpPropMergeType<StringConstructor, "error" | "primary" | "success" | "warning" | "info", unknown>;
readonly message: import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)) | (() => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)) | ((new (...args: any[]) => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)) | (() => string | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}> | (() => import("vue").VNode)))[], unknown, unknown>;
readonly placement: import("element-plus/es/utils").EpPropMergeType<StringConstructor, "top" | "bottom" | "top-left" | "top-right" | "bottom-left" | "bottom-right", unknown>;
readonly onClose: () => void;
readonly duration: number;
readonly showClose: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
readonly customClass: string;
readonly dangerouslyUseHTMLString: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
readonly plain: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
readonly grouping: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
readonly repeatNum: number;
}>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
export default _default;
type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
$slots: S;
};
};

View File

@@ -0,0 +1,113 @@
import { buildProps, definePropType } from '../../../utils/vue/props/runtime.mjs';
import { iconPropType } from '../../../utils/vue/icon.mjs';
import { mutable } from '../../../utils/typescript.mjs';
import { isClient } from '@vueuse/core';
const messageTypes = [
"primary",
"success",
"info",
"warning",
"error"
];
const messagePlacement = [
"top",
"top-left",
"top-right",
"bottom",
"bottom-left",
"bottom-right"
];
const MESSAGE_DEFAULT_PLACEMENT = "top";
const messageDefaults = mutable({
customClass: "",
dangerouslyUseHTMLString: false,
duration: 3e3,
icon: void 0,
id: "",
message: "",
onClose: void 0,
showClose: false,
type: "info",
plain: false,
offset: 16,
placement: void 0,
zIndex: 0,
grouping: false,
repeatNum: 1,
appendTo: isClient ? document.body : void 0
});
const messageProps = buildProps({
customClass: {
type: String,
default: messageDefaults.customClass
},
dangerouslyUseHTMLString: {
type: Boolean,
default: messageDefaults.dangerouslyUseHTMLString
},
duration: {
type: Number,
default: messageDefaults.duration
},
icon: {
type: iconPropType,
default: messageDefaults.icon
},
id: {
type: String,
default: messageDefaults.id
},
message: {
type: definePropType([
String,
Object,
Function
]),
default: messageDefaults.message
},
onClose: {
type: definePropType(Function),
default: messageDefaults.onClose
},
showClose: {
type: Boolean,
default: messageDefaults.showClose
},
type: {
type: String,
values: messageTypes,
default: messageDefaults.type
},
plain: {
type: Boolean,
default: messageDefaults.plain
},
offset: {
type: Number,
default: messageDefaults.offset
},
placement: {
type: String,
values: messagePlacement,
default: messageDefaults.placement
},
zIndex: {
type: Number,
default: messageDefaults.zIndex
},
grouping: {
type: Boolean,
default: messageDefaults.grouping
},
repeatNum: {
type: Number,
default: messageDefaults.repeatNum
}
});
const messageEmits = {
destroy: () => true
};
export { MESSAGE_DEFAULT_PLACEMENT, messageDefaults, messageEmits, messagePlacement, messageProps, messageTypes };
//# sourceMappingURL=message2.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
import type { Message, MessagePlacement, MessageType } from './message';
export declare function closeAll(type?: MessageType): void;
export declare function closeAllByPlacement(placement: MessagePlacement): void;
declare const _default: Message;
export default _default;

View File

@@ -0,0 +1,159 @@
import { isVNode, render, createVNode } from 'vue';
import MessageConstructor from './message.mjs';
import { messageTypes, MESSAGE_DEFAULT_PLACEMENT, messageDefaults, messagePlacement } from './message2.mjs';
import { getOrCreatePlacementInstances, placementInstances } from './instance.mjs';
import { messageConfig } from '../../config-provider/src/config-provider.mjs';
import { isClient } from '@vueuse/core';
import { isNumber, isBoolean, isElement } from '../../../utils/types.mjs';
import { hasOwn, isString, isFunction } from '@vue/shared';
import { debugWarn } from '../../../utils/error.mjs';
let seed = 1;
const normalizeAppendTo = (normalized) => {
const appendTo = normalized.appendTo;
if (!appendTo) {
normalized.appendTo = document.body;
} else if (isString(normalized.appendTo)) {
let appendTo2 = document.querySelector(normalized.appendTo);
if (!isElement(appendTo2)) {
appendTo2 = document.body;
}
normalized.appendTo = appendTo2;
}
};
const normalizePlacement = (normalized) => {
if (!normalized.placement && isString(messageConfig.placement) && messageConfig.placement) {
normalized.placement = messageConfig.placement;
}
if (!normalized.placement) {
normalized.placement = MESSAGE_DEFAULT_PLACEMENT;
}
if (!messagePlacement.includes(normalized.placement)) {
debugWarn("ElMessage", `Invalid placement: ${normalized.placement}. Falling back to '${MESSAGE_DEFAULT_PLACEMENT}'.`);
normalized.placement = MESSAGE_DEFAULT_PLACEMENT;
}
};
const normalizeOptions = (params) => {
const options = !params || isString(params) || isVNode(params) || isFunction(params) ? { message: params } : params;
const normalized = {
...messageDefaults,
...options
};
normalizeAppendTo(normalized);
normalizePlacement(normalized);
if (isBoolean(messageConfig.grouping) && !normalized.grouping) {
normalized.grouping = messageConfig.grouping;
}
if (isNumber(messageConfig.duration) && normalized.duration === 3e3) {
normalized.duration = messageConfig.duration;
}
if (isNumber(messageConfig.offset) && normalized.offset === 16) {
normalized.offset = messageConfig.offset;
}
if (isBoolean(messageConfig.showClose) && !normalized.showClose) {
normalized.showClose = messageConfig.showClose;
}
if (isBoolean(messageConfig.plain) && !normalized.plain) {
normalized.plain = messageConfig.plain;
}
return normalized;
};
const closeMessage = (instance) => {
const placement = instance.props.placement || MESSAGE_DEFAULT_PLACEMENT;
const instances = placementInstances[placement];
const idx = instances.indexOf(instance);
if (idx === -1)
return;
instances.splice(idx, 1);
const { handler } = instance;
handler.close();
};
const createMessage = ({ appendTo, ...options }, context) => {
const id = `message_${seed++}`;
const userOnClose = options.onClose;
const container = document.createElement("div");
const props = {
...options,
id,
onClose: () => {
userOnClose == null ? void 0 : userOnClose();
closeMessage(instance);
},
onDestroy: () => {
render(null, container);
}
};
const vnode = createVNode(MessageConstructor, props, isFunction(props.message) || isVNode(props.message) ? {
default: isFunction(props.message) ? props.message : () => props.message
} : null);
vnode.appContext = context || message._context;
render(vnode, container);
appendTo.appendChild(container.firstElementChild);
const vm = vnode.component;
const handler = {
close: () => {
vm.exposed.close();
}
};
const instance = {
id,
vnode,
vm,
handler,
props: vnode.component.props
};
return instance;
};
const message = (options = {}, context) => {
if (!isClient)
return { close: () => void 0 };
const normalized = normalizeOptions(options);
const instances = getOrCreatePlacementInstances(normalized.placement || MESSAGE_DEFAULT_PLACEMENT);
if (normalized.grouping && instances.length) {
const instance2 = instances.find(({ vnode: vm }) => {
var _a;
return ((_a = vm.props) == null ? void 0 : _a.message) === normalized.message;
});
if (instance2) {
instance2.props.repeatNum += 1;
instance2.props.type = normalized.type;
return instance2.handler;
}
}
if (isNumber(messageConfig.max) && instances.length >= messageConfig.max) {
return { close: () => void 0 };
}
const instance = createMessage(normalized, context);
instances.push(instance);
return instance.handler;
};
messageTypes.forEach((type) => {
message[type] = (options = {}, appContext) => {
const normalized = normalizeOptions(options);
return message({ ...normalized, type }, appContext);
};
});
function closeAll(type) {
for (const placement in placementInstances) {
if (hasOwn(placementInstances, placement)) {
const instances = [...placementInstances[placement]];
for (const instance of instances) {
if (!type || type === instance.props.type) {
instance.handler.close();
}
}
}
}
}
function closeAllByPlacement(placement) {
if (!placementInstances[placement])
return;
const instances = [...placementInstances[placement]];
instances.forEach((instance) => instance.handler.close());
}
message.closeAll = closeAll;
message.closeAllByPlacement = closeAllByPlacement;
message._context = null;
export { closeAll, closeAllByPlacement, message as default };
//# sourceMappingURL=method.mjs.map

File diff suppressed because one or more lines are too long