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,6 @@
import MessageBox from './src/messageBox';
import type { SFCWithInstall } from 'element-plus/es/utils';
declare const _MessageBox: SFCWithInstall<typeof MessageBox>;
export default _MessageBox;
export declare const ElMessageBox: SFCWithInstall<import("./src/message-box.type").IElMessageBox>;
export * from './src/message-box.type';

View File

@@ -0,0 +1,20 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var messageBox = require('./src/messageBox.js');
const _MessageBox = messageBox["default"];
_MessageBox.install = (app) => {
_MessageBox._context = app._context;
app.config.globalProperties.$msgbox = _MessageBox;
app.config.globalProperties.$messageBox = _MessageBox;
app.config.globalProperties.$alert = _MessageBox.alert;
app.config.globalProperties.$confirm = _MessageBox.confirm;
app.config.globalProperties.$prompt = _MessageBox.prompt;
};
const ElMessageBox = _MessageBox;
exports.ElMessageBox = ElMessageBox;
exports["default"] = _MessageBox;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../../../../packages/components/message-box/index.ts"],"sourcesContent":["import MessageBox from './src/messageBox'\n\nimport type { App } from 'vue'\nimport type { SFCWithInstall } from '@element-plus/utils'\n\nconst _MessageBox = MessageBox as SFCWithInstall<typeof MessageBox>\n\n_MessageBox.install = (app: App) => {\n _MessageBox._context = app._context\n app.config.globalProperties.$msgbox = _MessageBox\n app.config.globalProperties.$messageBox = _MessageBox\n app.config.globalProperties.$alert = _MessageBox.alert\n app.config.globalProperties.$confirm = _MessageBox.confirm\n app.config.globalProperties.$prompt = _MessageBox.prompt\n}\n\nexport default _MessageBox\nexport const ElMessageBox = _MessageBox\n\nexport * from './src/message-box.type'\n"],"names":["MessageBox"],"mappings":";;;;;;AACK,MAAC,WAAW,GAAGA,sBAAW;AAC/B,WAAW,CAAC,OAAO,GAAG,CAAC,GAAG,KAAK;AAC/B,EAAE,WAAW,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AACtC,EAAE,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,GAAG,WAAW,CAAC;AACpD,EAAE,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,WAAW,GAAG,WAAW,CAAC;AACxD,EAAE,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC;AACzD,EAAE,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC;AAC7D,EAAE,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC;AAC3D,CAAC,CAAC;AAEU,MAAC,YAAY,GAAG;;;;;"}

View File

@@ -0,0 +1,498 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var index$1 = require('../../button/index.js');
var index$2 = require('../../input/index.js');
var index$3 = require('../../overlay/index.js');
var index$4 = require('../../icon/index.js');
var iconsVue = require('@element-plus/icons-vue');
var focusTrap = require('../../focus-trap/src/focus-trap.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var index = require('../../../directives/trap-focus/index.js');
var icon = require('../../../utils/vue/icon.js');
var validator = require('../../../utils/vue/validator.js');
var useGlobalConfig = require('../../config-provider/src/hooks/use-global-config.js');
var index$5 = require('../../../hooks/use-id/index.js');
var index$6 = require('../../../hooks/use-draggable/index.js');
var shared = require('@vue/shared');
var index$7 = require('../../../hooks/use-lockscreen/index.js');
var index$8 = require('../../../hooks/use-same-target/index.js');
const _sfc_main = vue.defineComponent({
name: "ElMessageBox",
directives: {
TrapFocus: index["default"]
},
components: {
ElButton: index$1.ElButton,
ElFocusTrap: focusTrap["default"],
ElInput: index$2.ElInput,
ElOverlay: index$3.ElOverlay,
ElIcon: index$4.ElIcon,
...icon.TypeComponents
},
inheritAttrs: false,
props: {
buttonSize: {
type: String,
validator: validator.isValidComponentSize
},
modal: {
type: Boolean,
default: true
},
lockScroll: {
type: Boolean,
default: true
},
showClose: {
type: Boolean,
default: true
},
closeOnClickModal: {
type: Boolean,
default: true
},
closeOnPressEscape: {
type: Boolean,
default: true
},
closeOnHashChange: {
type: Boolean,
default: true
},
center: Boolean,
draggable: Boolean,
overflow: Boolean,
roundButton: Boolean,
container: {
type: String,
default: "body"
},
boxType: {
type: String,
default: ""
}
},
emits: ["vanish", "action"],
setup(props, { emit }) {
const {
locale,
zIndex,
ns,
size: btnSize
} = useGlobalConfig.useGlobalComponentSettings("message-box", vue.computed(() => props.buttonSize));
const { t } = locale;
const { nextZIndex } = zIndex;
const visible = vue.ref(false);
const state = vue.reactive({
autofocus: true,
beforeClose: null,
callback: null,
cancelButtonText: "",
cancelButtonClass: "",
confirmButtonText: "",
confirmButtonClass: "",
customClass: "",
customStyle: {},
dangerouslyUseHTMLString: false,
distinguishCancelAndClose: false,
icon: "",
closeIcon: "",
inputPattern: null,
inputPlaceholder: "",
inputType: "text",
inputValue: "",
inputValidator: void 0,
inputErrorMessage: "",
message: "",
modalFade: true,
modalClass: "",
showCancelButton: false,
showConfirmButton: true,
type: "",
title: void 0,
showInput: false,
action: "",
confirmButtonLoading: false,
cancelButtonLoading: false,
confirmButtonLoadingIcon: vue.markRaw(iconsVue.Loading),
cancelButtonLoadingIcon: vue.markRaw(iconsVue.Loading),
confirmButtonDisabled: false,
editorErrorMessage: "",
validateError: false,
zIndex: nextZIndex()
});
const typeClass = vue.computed(() => {
const type = state.type;
return { [ns.bm("icon", type)]: type && icon.TypeComponentsMap[type] };
});
const contentId = index$5.useId();
const inputId = index$5.useId();
const iconComponent = vue.computed(() => {
const type = state.type;
return state.icon || type && icon.TypeComponentsMap[type] || "";
});
const hasMessage = vue.computed(() => !!state.message);
const rootRef = vue.ref();
const headerRef = vue.ref();
const focusStartRef = vue.ref();
const inputRef = vue.ref();
const confirmRef = vue.ref();
const confirmButtonClasses = vue.computed(() => state.confirmButtonClass);
vue.watch(() => state.inputValue, async (val) => {
await vue.nextTick();
if (props.boxType === "prompt" && val) {
validate();
}
}, { immediate: true });
vue.watch(() => visible.value, (val) => {
var _a, _b;
if (val) {
if (props.boxType !== "prompt") {
if (state.autofocus) {
focusStartRef.value = (_b = (_a = confirmRef.value) == null ? void 0 : _a.$el) != null ? _b : rootRef.value;
} else {
focusStartRef.value = rootRef.value;
}
}
state.zIndex = nextZIndex();
}
if (props.boxType !== "prompt")
return;
if (val) {
vue.nextTick().then(() => {
var _a2;
if (inputRef.value && inputRef.value.$el) {
if (state.autofocus) {
focusStartRef.value = (_a2 = getInputElement()) != null ? _a2 : rootRef.value;
} else {
focusStartRef.value = rootRef.value;
}
}
});
} else {
state.editorErrorMessage = "";
state.validateError = false;
}
});
const draggable = vue.computed(() => props.draggable);
const overflow = vue.computed(() => props.overflow);
const { isDragging } = index$6.useDraggable(rootRef, headerRef, draggable, overflow);
vue.onMounted(async () => {
await vue.nextTick();
if (props.closeOnHashChange) {
window.addEventListener("hashchange", doClose);
}
});
vue.onBeforeUnmount(() => {
if (props.closeOnHashChange) {
window.removeEventListener("hashchange", doClose);
}
});
function doClose() {
if (!visible.value)
return;
visible.value = false;
vue.nextTick(() => {
if (state.action)
emit("action", state.action);
});
}
const handleWrapperClick = () => {
if (props.closeOnClickModal) {
handleAction(state.distinguishCancelAndClose ? "close" : "cancel");
}
};
const overlayEvent = index$8.useSameTarget(handleWrapperClick);
const handleInputEnter = (e) => {
if (state.inputType !== "textarea") {
e.preventDefault();
return handleAction("confirm");
}
};
const handleAction = (action) => {
var _a;
if (props.boxType === "prompt" && action === "confirm" && !validate()) {
return;
}
state.action = action;
if (state.beforeClose) {
(_a = state.beforeClose) == null ? void 0 : _a.call(state, action, state, doClose);
} else {
doClose();
}
};
const validate = () => {
if (props.boxType === "prompt") {
const inputPattern = state.inputPattern;
if (inputPattern && !inputPattern.test(state.inputValue || "")) {
state.editorErrorMessage = state.inputErrorMessage || t("el.messagebox.error");
state.validateError = true;
return false;
}
const inputValidator = state.inputValidator;
if (shared.isFunction(inputValidator)) {
const validateResult = inputValidator(state.inputValue);
if (validateResult === false) {
state.editorErrorMessage = state.inputErrorMessage || t("el.messagebox.error");
state.validateError = true;
return false;
}
if (shared.isString(validateResult)) {
state.editorErrorMessage = validateResult;
state.validateError = true;
return false;
}
}
}
state.editorErrorMessage = "";
state.validateError = false;
return true;
};
const getInputElement = () => {
var _a, _b;
const inputRefs = (_a = inputRef.value) == null ? void 0 : _a.$refs;
return (_b = inputRefs == null ? void 0 : inputRefs.input) != null ? _b : inputRefs == null ? void 0 : inputRefs.textarea;
};
const handleClose = () => {
handleAction("close");
};
const onCloseRequested = () => {
if (props.closeOnPressEscape) {
handleClose();
}
};
if (props.lockScroll) {
index$7.useLockscreen(visible);
}
return {
...vue.toRefs(state),
ns,
overlayEvent,
visible,
hasMessage,
typeClass,
contentId,
inputId,
btnSize,
iconComponent,
confirmButtonClasses,
rootRef,
focusStartRef,
headerRef,
inputRef,
isDragging,
confirmRef,
doClose,
handleClose,
onCloseRequested,
handleWrapperClick,
handleInputEnter,
handleAction,
t
};
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_el_icon = vue.resolveComponent("el-icon");
const _component_el_input = vue.resolveComponent("el-input");
const _component_el_button = vue.resolveComponent("el-button");
const _component_el_focus_trap = vue.resolveComponent("el-focus-trap");
const _component_el_overlay = vue.resolveComponent("el-overlay");
return vue.openBlock(), vue.createBlock(vue.Transition, {
name: "fade-in-linear",
onAfterLeave: ($event) => _ctx.$emit("vanish"),
persisted: ""
}, {
default: vue.withCtx(() => [
vue.withDirectives(vue.createVNode(_component_el_overlay, {
"z-index": _ctx.zIndex,
"overlay-class": [_ctx.ns.is("message-box"), _ctx.modalClass],
mask: _ctx.modal
}, {
default: vue.withCtx(() => [
vue.createElementVNode("div", {
role: "dialog",
"aria-label": _ctx.title,
"aria-modal": "true",
"aria-describedby": !_ctx.showInput ? _ctx.contentId : void 0,
class: vue.normalizeClass(`${_ctx.ns.namespace.value}-overlay-message-box`),
onClick: _ctx.overlayEvent.onClick,
onMousedown: _ctx.overlayEvent.onMousedown,
onMouseup: _ctx.overlayEvent.onMouseup
}, [
vue.createVNode(_component_el_focus_trap, {
loop: "",
trapped: _ctx.visible,
"focus-trap-el": _ctx.rootRef,
"focus-start-el": _ctx.focusStartRef,
onReleaseRequested: _ctx.onCloseRequested
}, {
default: vue.withCtx(() => [
vue.createElementVNode("div", {
ref: "rootRef",
class: vue.normalizeClass([
_ctx.ns.b(),
_ctx.customClass,
_ctx.ns.is("draggable", _ctx.draggable),
_ctx.ns.is("dragging", _ctx.isDragging),
{ [_ctx.ns.m("center")]: _ctx.center }
]),
style: vue.normalizeStyle(_ctx.customStyle),
tabindex: "-1",
onClick: vue.withModifiers(() => {
}, ["stop"])
}, [
_ctx.title !== null && _ctx.title !== void 0 ? (vue.openBlock(), vue.createElementBlock("div", {
key: 0,
ref: "headerRef",
class: vue.normalizeClass([_ctx.ns.e("header"), { "show-close": _ctx.showClose }])
}, [
vue.createElementVNode("div", {
class: vue.normalizeClass(_ctx.ns.e("title"))
}, [
_ctx.iconComponent && _ctx.center ? (vue.openBlock(), vue.createBlock(_component_el_icon, {
key: 0,
class: vue.normalizeClass([_ctx.ns.e("status"), _ctx.typeClass])
}, {
default: vue.withCtx(() => [
(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.iconComponent)))
]),
_: 1
}, 8, ["class"])) : vue.createCommentVNode("v-if", true),
vue.createElementVNode("span", null, vue.toDisplayString(_ctx.title), 1)
], 2),
_ctx.showClose ? (vue.openBlock(), vue.createElementBlock("button", {
key: 0,
type: "button",
class: vue.normalizeClass(_ctx.ns.e("headerbtn")),
"aria-label": _ctx.t("el.messagebox.close"),
onClick: ($event) => _ctx.handleAction(_ctx.distinguishCancelAndClose ? "close" : "cancel"),
onKeydown: vue.withKeys(vue.withModifiers(($event) => _ctx.handleAction(_ctx.distinguishCancelAndClose ? "close" : "cancel"), ["prevent"]), ["enter"])
}, [
vue.createVNode(_component_el_icon, {
class: vue.normalizeClass(_ctx.ns.e("close"))
}, {
default: vue.withCtx(() => [
(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.closeIcon || "close")))
]),
_: 1
}, 8, ["class"])
], 42, ["aria-label", "onClick", "onKeydown"])) : vue.createCommentVNode("v-if", true)
], 2)) : vue.createCommentVNode("v-if", true),
vue.createElementVNode("div", {
id: _ctx.contentId,
class: vue.normalizeClass(_ctx.ns.e("content"))
}, [
vue.createElementVNode("div", {
class: vue.normalizeClass(_ctx.ns.e("container"))
}, [
_ctx.iconComponent && !_ctx.center && _ctx.hasMessage ? (vue.openBlock(), vue.createBlock(_component_el_icon, {
key: 0,
class: vue.normalizeClass([_ctx.ns.e("status"), _ctx.typeClass])
}, {
default: vue.withCtx(() => [
(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.iconComponent)))
]),
_: 1
}, 8, ["class"])) : vue.createCommentVNode("v-if", true),
_ctx.hasMessage ? (vue.openBlock(), vue.createElementBlock("div", {
key: 1,
class: vue.normalizeClass(_ctx.ns.e("message"))
}, [
vue.renderSlot(_ctx.$slots, "default", {}, () => [
!_ctx.dangerouslyUseHTMLString ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.showInput ? "label" : "p"), {
key: 0,
for: _ctx.showInput ? _ctx.inputId : void 0,
textContent: vue.toDisplayString(_ctx.message)
}, null, 8, ["for", "textContent"])) : (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.showInput ? "label" : "p"), {
key: 1,
for: _ctx.showInput ? _ctx.inputId : void 0,
innerHTML: _ctx.message
}, null, 8, ["for", "innerHTML"]))
])
], 2)) : vue.createCommentVNode("v-if", true)
], 2),
vue.withDirectives(vue.createElementVNode("div", {
class: vue.normalizeClass(_ctx.ns.e("input"))
}, [
vue.createVNode(_component_el_input, {
id: _ctx.inputId,
ref: "inputRef",
modelValue: _ctx.inputValue,
"onUpdate:modelValue": ($event) => _ctx.inputValue = $event,
type: _ctx.inputType,
placeholder: _ctx.inputPlaceholder,
"aria-invalid": _ctx.validateError,
class: vue.normalizeClass({ invalid: _ctx.validateError }),
onKeydown: vue.withKeys(_ctx.handleInputEnter, ["enter"])
}, null, 8, ["id", "modelValue", "onUpdate:modelValue", "type", "placeholder", "aria-invalid", "class", "onKeydown"]),
vue.createElementVNode("div", {
class: vue.normalizeClass(_ctx.ns.e("errormsg")),
style: vue.normalizeStyle({
visibility: !!_ctx.editorErrorMessage ? "visible" : "hidden"
})
}, vue.toDisplayString(_ctx.editorErrorMessage), 7)
], 2), [
[vue.vShow, _ctx.showInput]
])
], 10, ["id"]),
vue.createElementVNode("div", {
class: vue.normalizeClass(_ctx.ns.e("btns"))
}, [
_ctx.showCancelButton ? (vue.openBlock(), vue.createBlock(_component_el_button, {
key: 0,
loading: _ctx.cancelButtonLoading,
"loading-icon": _ctx.cancelButtonLoadingIcon,
class: vue.normalizeClass([_ctx.cancelButtonClass]),
round: _ctx.roundButton,
size: _ctx.btnSize,
onClick: ($event) => _ctx.handleAction("cancel"),
onKeydown: vue.withKeys(vue.withModifiers(($event) => _ctx.handleAction("cancel"), ["prevent"]), ["enter"])
}, {
default: vue.withCtx(() => [
vue.createTextVNode(vue.toDisplayString(_ctx.cancelButtonText || _ctx.t("el.messagebox.cancel")), 1)
]),
_: 1
}, 8, ["loading", "loading-icon", "class", "round", "size", "onClick", "onKeydown"])) : vue.createCommentVNode("v-if", true),
vue.withDirectives(vue.createVNode(_component_el_button, {
ref: "confirmRef",
type: "primary",
loading: _ctx.confirmButtonLoading,
"loading-icon": _ctx.confirmButtonLoadingIcon,
class: vue.normalizeClass([_ctx.confirmButtonClasses]),
round: _ctx.roundButton,
disabled: _ctx.confirmButtonDisabled,
size: _ctx.btnSize,
onClick: ($event) => _ctx.handleAction("confirm"),
onKeydown: vue.withKeys(vue.withModifiers(($event) => _ctx.handleAction("confirm"), ["prevent"]), ["enter"])
}, {
default: vue.withCtx(() => [
vue.createTextVNode(vue.toDisplayString(_ctx.confirmButtonText || _ctx.t("el.messagebox.confirm")), 1)
]),
_: 1
}, 8, ["loading", "loading-icon", "class", "round", "disabled", "size", "onClick", "onKeydown"]), [
[vue.vShow, _ctx.showConfirmButton]
])
], 2)
], 14, ["onClick"])
]),
_: 3
}, 8, ["trapped", "focus-trap-el", "focus-start-el", "onReleaseRequested"])
], 42, ["aria-label", "aria-describedby", "onClick", "onMousedown", "onMouseup"])
]),
_: 3
}, 8, ["z-index", "overlay-class", "mask"]), [
[vue.vShow, _ctx.visible]
])
]),
_: 3
}, 8, ["onAfterLeave"]);
}
var MessageBoxConstructor = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "index.vue"]]);
exports["default"] = MessageBoxConstructor;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,151 @@
import type { AppContext, CSSProperties, Component, VNode } from 'vue';
import type { ComponentSize } from 'element-plus/es/constants';
type MessageType = '' | 'primary' | 'success' | 'warning' | 'info' | 'error';
export type Action = 'confirm' | 'close' | 'cancel';
export type MessageBoxType = '' | 'prompt' | 'alert' | 'confirm';
export type MessageBoxData = MessageBoxInputData & Action;
export interface MessageBoxInputData {
value: string;
action: Action;
}
export type MessageBoxInputValidator = ((value: string) => boolean | string) | undefined;
export declare interface MessageBoxState {
autofocus: boolean;
title: string | undefined;
message: string;
type: MessageType;
icon: string | Component;
closeIcon: string | Component;
customClass: string;
customStyle: CSSProperties;
showInput: boolean;
inputValue: string;
inputPlaceholder: string;
inputType: string;
inputPattern: RegExp | null;
inputValidator: MessageBoxInputValidator;
inputErrorMessage: string;
showConfirmButton: boolean;
showCancelButton: boolean;
action: Action;
dangerouslyUseHTMLString: boolean;
confirmButtonText: string;
cancelButtonText: string;
confirmButtonLoading: boolean;
cancelButtonLoading: boolean;
confirmButtonLoadingIcon: string | Component;
cancelButtonLoadingIcon: string | Component;
confirmButtonClass: string;
confirmButtonDisabled: boolean;
cancelButtonClass: string;
editorErrorMessage: string;
beforeClose: null | ((action: Action, instance: MessageBoxState, done: () => void) => void);
callback: null | Callback;
distinguishCancelAndClose: boolean;
modalFade: boolean;
modalClass: string;
validateError: boolean;
zIndex: number;
}
export type Callback = ((value: string, action: Action) => any) | ((action: Action) => any);
/** Options used in MessageBox */
export interface ElMessageBoxOptions {
/**
* auto focus when open message-box
*/
autofocus?: boolean;
/** Callback before MessageBox closes, and it will prevent MessageBox from closing */
beforeClose?: (action: Action, instance: MessageBoxState, done: () => void) => void;
/** Custom class name for MessageBox */
customClass?: string;
/** Custom inline style for MessageBox */
customStyle?: CSSProperties;
/** modal class name for MessageBox */
modalClass?: string;
/** MessageBox closing callback if you don't prefer Promise */
callback?: Callback;
/** Text content of cancel button */
cancelButtonText?: string;
/** Text content of confirm button */
confirmButtonText?: string;
/** Loading Icon content of cancel button */
cancelButtonLoadingIcon?: string | Component;
/** Loading Icon content of confirm button */
confirmButtonLoadingIcon?: string | Component;
/** Custom class name of cancel button */
cancelButtonClass?: string;
/** Custom class name of confirm button */
confirmButtonClass?: string;
/** Whether to align the content in center */
center?: boolean;
/** Whether MessageBox can be drag */
draggable?: boolean;
/** Draggable MessageBox can overflow the viewport */
overflow?: boolean;
/** Content of the MessageBox */
message?: string | VNode | (() => VNode);
/** Title of the MessageBox */
title?: string | ElMessageBoxOptions;
/** Message type, used for icon display */
type?: MessageType;
/** Message box type */
boxType?: MessageBoxType;
/** Custom icon component */
icon?: string | Component;
/** Custom close icon component */
closeIcon?: string | Component;
/** Whether message is treated as HTML string */
dangerouslyUseHTMLString?: boolean;
/** Whether to distinguish canceling and closing */
distinguishCancelAndClose?: boolean;
/** Whether to lock body scroll when MessageBox prompts */
lockScroll?: boolean;
/** Whether to show a cancel button */
showCancelButton?: boolean;
/** Whether to show a confirm button */
showConfirmButton?: boolean;
/** Whether to show a close button */
showClose?: boolean;
/** Whether to use round button */
roundButton?: boolean;
/** Whether MessageBox can be closed by clicking the mask */
closeOnClickModal?: boolean;
/** Whether MessageBox can be closed by pressing the ESC */
closeOnPressEscape?: boolean;
/** Whether to close MessageBox when hash changes */
closeOnHashChange?: boolean;
/** Whether to show an input */
showInput?: boolean;
/** Placeholder of input */
inputPlaceholder?: string;
/** Initial value of input */
inputValue?: string;
/** Regexp for the input */
inputPattern?: RegExp;
/** Input Type: text, textArea, password or number */
inputType?: string;
/** Validation function for the input. Should returns a boolean or string. If a string is returned, it will be assigned to inputErrorMessage */
inputValidator?: MessageBoxInputValidator;
/** Error message when validation fails */
inputErrorMessage?: string;
/** Custom size of confirm and cancel buttons */
buttonSize?: ComponentSize;
/** Custom element to append the message box to */
appendTo?: HTMLElement | string;
}
export type ElMessageBoxShortcutMethod = ((message: ElMessageBoxOptions['message'], options?: ElMessageBoxOptions, appContext?: AppContext | null) => Promise<MessageBoxData>) & ((message: ElMessageBoxOptions['message'], title: ElMessageBoxOptions['title'], options?: ElMessageBoxOptions, appContext?: AppContext | null) => Promise<MessageBoxData>);
export interface IElMessageBox {
_context: AppContext | null;
/** Show a message box */
/** Show a message box */
(options: ElMessageBoxOptions, appContext?: AppContext | null): Promise<MessageBoxData>;
/** Show an alert message box */
alert: ElMessageBoxShortcutMethod;
/** Show a confirm message box */
confirm: ElMessageBoxShortcutMethod;
/** Show a prompt message box */
prompt: ElMessageBoxShortcutMethod;
/** Close current message box */
close(): void;
}
export {};

View File

@@ -0,0 +1,3 @@
'use strict';
//# sourceMappingURL=message-box.type.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"message-box.type.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}

View File

@@ -0,0 +1,3 @@
import type { IElMessageBox } from './message-box.type';
declare const _default: IElMessageBox;
export default _default;

View File

@@ -0,0 +1,141 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var index = require('./index.js');
var core = require('@vueuse/core');
var shared = require('@vue/shared');
var types = require('../../../utils/types.js');
const messageInstance = /* @__PURE__ */ new Map();
const getAppendToElement = (props) => {
let appendTo = document.body;
if (props.appendTo) {
if (shared.isString(props.appendTo)) {
appendTo = document.querySelector(props.appendTo);
}
if (types.isElement(props.appendTo)) {
appendTo = props.appendTo;
}
if (!types.isElement(appendTo)) {
appendTo = document.body;
}
}
return appendTo;
};
const initInstance = (props, container, appContext = null) => {
const vnode = vue.createVNode(index["default"], props, shared.isFunction(props.message) || vue.isVNode(props.message) ? {
default: shared.isFunction(props.message) ? props.message : () => props.message
} : null);
vnode.appContext = appContext;
vue.render(vnode, container);
getAppendToElement(props).appendChild(container.firstElementChild);
return vnode.component;
};
const genContainer = () => {
return document.createElement("div");
};
const showMessage = (options, appContext) => {
const container = genContainer();
options.onVanish = () => {
vue.render(null, container);
messageInstance.delete(vm);
};
options.onAction = (action) => {
const currentMsg = messageInstance.get(vm);
let resolve;
if (options.showInput) {
resolve = { value: vm.inputValue, action };
} else {
resolve = action;
}
if (options.callback) {
options.callback(resolve, instance.proxy);
} else {
if (action === "cancel" || action === "close") {
if (options.distinguishCancelAndClose && action !== "cancel") {
currentMsg.reject("close");
} else {
currentMsg.reject("cancel");
}
} else {
currentMsg.resolve(resolve);
}
}
};
const instance = initInstance(options, container, appContext);
const vm = instance.proxy;
for (const prop in options) {
if (shared.hasOwn(options, prop) && !shared.hasOwn(vm.$props, prop)) {
if (prop === "closeIcon" && shared.isObject(options[prop])) {
vm[prop] = vue.markRaw(options[prop]);
} else {
vm[prop] = options[prop];
}
}
}
vm.visible = true;
return vm;
};
function MessageBox(options, appContext = null) {
if (!core.isClient)
return Promise.reject();
let callback;
if (shared.isString(options) || vue.isVNode(options)) {
options = {
message: options
};
} else {
callback = options.callback;
}
return new Promise((resolve, reject) => {
const vm = showMessage(options, appContext != null ? appContext : MessageBox._context);
messageInstance.set(vm, {
options,
callback,
resolve,
reject
});
});
}
const MESSAGE_BOX_VARIANTS = ["alert", "confirm", "prompt"];
const MESSAGE_BOX_DEFAULT_OPTS = {
alert: { closeOnPressEscape: false, closeOnClickModal: false },
confirm: { showCancelButton: true },
prompt: { showCancelButton: true, showInput: true }
};
MESSAGE_BOX_VARIANTS.forEach((boxType) => {
MessageBox[boxType] = messageBoxFactory(boxType);
});
function messageBoxFactory(boxType) {
return (message, title, options, appContext) => {
let titleOrOpts = "";
if (shared.isObject(title)) {
options = title;
titleOrOpts = "";
} else if (types.isUndefined(title)) {
titleOrOpts = "";
} else {
titleOrOpts = title;
}
return MessageBox(Object.assign({
title: titleOrOpts,
message,
type: "",
...MESSAGE_BOX_DEFAULT_OPTS[boxType]
}, options, {
boxType
}), appContext);
};
}
MessageBox.close = () => {
messageInstance.forEach((_, vm) => {
vm.doClose();
});
messageInstance.clear();
};
MessageBox._context = null;
exports["default"] = MessageBox;
//# sourceMappingURL=messageBox.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
import 'element-plus/es/components/base/style/css';
import 'element-plus/theme-chalk/el-message-box.css';
import 'element-plus/es/components/button/style/css';
import 'element-plus/es/components/input/style/css';
import 'element-plus/es/components/overlay/style/css';

View File

@@ -0,0 +1,9 @@
'use strict';
require('../../base/style/css.js');
require('element-plus/theme-chalk/el-message-box.css');
require('../../button/style/css.js');
require('../../input/style/css.js');
require('../../overlay/style/css.js');
//# sourceMappingURL=css.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}

View File

@@ -0,0 +1,5 @@
import 'element-plus/es/components/base/style';
import 'element-plus/theme-chalk/src/message-box.scss';
import 'element-plus/es/components/button/style';
import 'element-plus/es/components/input/style';
import 'element-plus/es/components/overlay/style';

View File

@@ -0,0 +1,9 @@
'use strict';
require('../../base/style/index.js');
require('element-plus/theme-chalk/src/message-box.scss');
require('../../button/style/index.js');
require('../../input/style/index.js');
require('../../overlay/style/index.js');
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}