tdesign-vue
Version:
585 lines (577 loc) • 24.4 kB
JavaScript
/**
* tdesign v1.11.2
* (c) 2025 tdesign
* @license MIT
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var tdesignIconsVue = require('tdesign-icons-vue');
var button_index = require('../button/index.js');
var dialog_actions = require('./actions.js');
var dialog_props = require('./props.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var utils_mixins = require('../utils/mixins.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_transferDom = require('../utils/transfer-dom.js');
var utils_event = require('../utils/event.js');
var hooks_useDestroyOnClose = require('../hooks/useDestroyOnClose.js');
var dialog_stack = require('./stack.js');
var _common_js_utils_getScrollbarWidth = require('../_common/js/utils/getScrollbarWidth.js');
var isNumber = require('../_chunks/dep-aa0a4aac.js');
var throttle = require('../_chunks/dep-13309278.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('vue');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/setStyle.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../_chunks/dep-62de1188.js');
require('../_chunks/dep-867c284e.js');
require('../_chunks/dep-738b4f21.js');
require('../_chunks/dep-a4308f57.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-fcf0662d.js');
require('../_chunks/dep-e4278c54.js');
require('../utils/dom.js');
require('raf');
require('../utils/easing.js');
require('../loading/props.js');
require('@babel/runtime/helpers/readOnlyError');
require('@vue/composition-api');
require('../_chunks/dep-7c854ec6.js');
require('../_chunks/dep-eceed11d.js');
require('../_chunks/dep-201f7798.js');
require('../_chunks/dep-d3015b4c.js');
require('../_chunks/dep-f8a85d6a.js');
require('../_chunks/dep-5b117689.js');
require('../_chunks/dep-6478392e.js');
require('../_chunks/dep-47bca35e.js');
require('../_chunks/dep-07fb8c0e.js');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-a4a18104.js');
require('../_chunks/dep-27dd8cc6.js');
require('dayjs');
require('../_chunks/dep-87c765cc.js');
require('../_chunks/dep-75cd6d52.js');
require('../_chunks/dep-b1a02818.js');
require('../_chunks/dep-3d8ab37d.js');
require('../_chunks/dep-ecccff93.js');
require('../_chunks/dep-a4cecac4.js');
require('../_chunks/dep-ab142eaf.js');
require('../_chunks/dep-6ad3de7c.js');
require('../_chunks/dep-8b1e056e.js');
require('../_chunks/dep-5db8defc.js');
require('../_chunks/dep-6e4c473c.js');
require('../_chunks/dep-234b7c02.js');
require('../_chunks/dep-a4747856.js');
require('../_chunks/dep-932dd69e.js');
require('../_chunks/dep-9f4caea4.js');
require('../_chunks/dep-dbd838d6.js');
require('../_chunks/dep-b3120c1b.js');
require('../_chunks/dep-68ba2357.js');
require('../_chunks/dep-173eb46c.js');
require('../config.js');
require('../_chunks/dep-013a3403.js');
require('../_chunks/dep-8cb0d589.js');
require('../_chunks/dep-d23147db.js');
require('../_chunks/dep-de60f5aa.js');
require('../_chunks/dep-63b02f7b.js');
require('../_chunks/dep-bebcd284.js');
require('../_chunks/dep-3eec664c.js');
require('../_chunks/dep-eeb2e214.js');
require('../_chunks/dep-315a67f0.js');
require('../_chunks/dep-f84d1ea5.js');
require('../_chunks/dep-362bc4d7.js');
require('../_chunks/dep-2e32c1f2.js');
require('../_chunks/dep-f14aac54.js');
require('../utils/withInstall.js');
require('../button/props.js');
require('../utils/ripple.js');
require('../_chunks/dep-ece3c062.js');
require('../utils/helper.js');
require('../_chunks/dep-f3761329.js');
require('../_chunks/dep-848a5a32.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default["default"](e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function getCSSValue(v) {
return isNaN(Number(v)) ? v : "".concat(Number(v), "px");
}
var mousePosition;
var getClickPosition = function getClickPosition(e) {
mousePosition = {
x: e.clientX,
y: e.clientY
};
setTimeout(function () {
mousePosition = null;
}, 100);
};
if (typeof window !== "undefined" && window.document && window.document.documentElement) {
document.documentElement.addEventListener("click", getClickPosition, true);
}
var key = 1;
var _Dialog = utils_mixins["default"](dialog_actions["default"], configProvider_configReceiver["default"]("dialog"), configProvider_configReceiver.getGlobalIconMixins(), configProvider_configReceiver.getAttachConfigMixins("dialog")).extend({
name: "TDialog",
components: {
TButton: button_index.Button
},
data: function data() {
return {
uid: 0,
scrollWidth: 0,
disX: 0,
disY: 0,
windowInnerWidth: 0,
windowInnerHeight: 0,
dialogW: 0,
dialogH: 0,
dLeft: 0,
dTop: 0,
styleEl: null,
timer: null,
animationEnd: false
};
},
props: _objectSpread(_objectSpread({}, dialog_props["default"]), {}, {
instanceGlobal: Object
}),
computed: {
isModal: function isModal() {
return this.mode === "modal";
},
isModeLess: function isModeLess() {
return this.mode === "modeless";
},
isNormal: function isNormal() {
return this.mode === "normal";
},
isFullScreen: function isFullScreen() {
return this.mode === "full-screen";
},
maskClass: function maskClass() {
return ["".concat(this.componentName, "__mask"), !this.showOverlay && "".concat(this.classPrefix, "-is-hidden")];
},
dialogClass: function dialogClass() {
var dialogClass = ["".concat(this.componentName), "".concat(this.componentName, "__modal-").concat(this.theme), this.isModeLess && this.draggable && "".concat(this.componentName, "--draggable")];
if (this.isFullScreen) {
dialogClass.push("".concat(this.componentName, "__fullscreen"));
} else {
dialogClass.push("".concat(this.componentName, "--default"));
}
return dialogClass;
},
positionClass: function positionClass() {
if (this.isNormal) return [];
if (this.isFullScreen) return ["".concat(this.componentName, "__position_fullscreen")];
var dialogClass = ["".concat(this.componentName, "__position"), !!this.top && "".concat(this.componentName, "--top"), "".concat(this.placement && !this.top ? "".concat(this.componentName, "--").concat(this.placement) : "")];
return dialogClass;
},
wrapClass: function wrapClass() {
return [!this.isNormal && "".concat(this.componentName, "__wrap")];
},
ctxClass: function ctxClass() {
return ["".concat(this.componentName, "__ctx"), _defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"]({}, "".concat(this.classPrefix, "-dialog__ctx--fixed"), this.mode === "modal" || this.isFullScreen), "".concat(this.classPrefix, "-dialog__ctx--absolute"), this.isModal && this.showInAttachedElement), "".concat(this.componentName, "__ctx--modeless"), this.isModeLess)];
},
positionStyle: function positionStyle() {
if (this.isFullScreen) return {};
var topStyle = {};
if (this.top !== void 0) {
if (isNumber.isNumber(this.top) && this.top < 0) {
topStyle.paddingTop = "".concat(this.top, "px");
} else {
topStyle.paddingTop = this.top;
}
}
return topStyle;
},
computedDialogStyle: function computedDialogStyle() {
return !this.isFullScreen ? _objectSpread({
width: getCSSValue(this.width)
}, this.dialogStyle) : _objectSpread({}, this.dialogStyle);
},
computedAttach: function computedAttach() {
return this.showInAttachedElement || this.isNormal ? void 0 : this.attach || this.globalAttach();
}
},
watch: {
visible: {
handler: function handler(value) {
var _this = this;
if (typeof window === "undefined") return;
if (value) {
this.animationEnd = false;
if (this.isModal && !this.showInAttachedElement || this.isFullScreen) {
if (this.preventScrollThrough) {
this.$nextTick(function () {
document.head.appendChild(_this.styleEl);
});
}
this.$nextTick(function () {
var target = _this.$refs.dialog;
if (mousePosition && target) {
target.style.transformOrigin = "".concat(mousePosition.x - target.offsetLeft, "px ").concat(mousePosition.y - target.offsetTop, "px");
}
});
}
document.activeElement.blur();
} else {
this.clearStyleFunc();
}
this.$nextTick(function () {
_this.storeUid(value);
});
this.addKeyboardEvent(value);
if (this.isModeLess && this.draggable) {
this.$nextTick(function () {
_this.initDragEvent(value);
});
}
if (value && !this.destroyOnClose && requestAnimationFrame) {
requestAnimationFrame(function () {
hooks_useDestroyOnClose.updateElement(_this);
});
}
},
immediate: true
}
},
mounted: function mounted() {
var hasScrollBar = document.documentElement.scrollHeight > document.documentElement.clientHeight;
var scrollWidth = hasScrollBar ? _common_js_utils_getScrollbarWidth.getScrollbarWidth() : 0;
if (this.draggable) {
window.addEventListener("resize", throttle.throttle(this.resizeAdjustPosition, 1e3));
}
this.uid = this._uid;
this.styleEl = document.createElement("style");
this.styleEl.dataset.id = "td_dialog_".concat(+new Date(), "_").concat(key += 1);
this.styleEl.innerHTML = "\n html body {\n overflow-y: hidden;\n width: calc(100% - ".concat(scrollWidth, "px);\n }\n ");
if (this.visible && this.isModal && this.preventScrollThrough && !this.showInAttachedElement) {
document.head.appendChild(this.styleEl);
}
},
beforeDestroy: function beforeDestroy() {
this.addKeyboardEvent(false);
this.destroySelf();
this.destroySelfStyle();
},
directives: {
TransferDom: utils_transferDom["default"]
},
methods: {
clearStyleFunc: function clearStyleFunc() {
var _this2 = this;
clearTimeout(this.timer);
this.timer = setTimeout(function () {
_this2.destroySelfStyle();
}, 150);
},
destroySelfStyle: function destroySelfStyle() {
var _this$styleEl$parentN, _this$styleEl$parentN2;
(_this$styleEl$parentN = this.styleEl.parentNode) === null || _this$styleEl$parentN === void 0 || (_this$styleEl$parentN2 = _this$styleEl$parentN.removeChild) === null || _this$styleEl$parentN2 === void 0 || _this$styleEl$parentN2.call(_this$styleEl$parentN, this.styleEl);
},
destroySelf: function destroySelf() {
var _this$$el$parentNode, _this$$el$parentNode$;
(_this$$el$parentNode = this.$el.parentNode) === null || _this$$el$parentNode === void 0 || (_this$$el$parentNode$ = _this$$el$parentNode.removeChild) === null || _this$$el$parentNode$ === void 0 || _this$$el$parentNode$.call(_this$$el$parentNode, this.$el);
},
storeUid: function storeUid(flag) {
if (flag) {
dialog_stack["default"].push(this.uid);
} else {
dialog_stack["default"].pop(this.uid);
}
},
addKeyboardEvent: function addKeyboardEvent(status) {
if (status) {
document.addEventListener("keydown", this.keyboardEvent);
this.confirmOnEnter && document.addEventListener("keydown", this.keyboardEnterEvent);
} else {
document.removeEventListener("keydown", this.keyboardEvent);
this.confirmOnEnter && document.removeEventListener("keydown", this.keyboardEnterEvent);
}
},
keyboardEvent: function keyboardEvent(e) {
if (e.code === "Escape" && dialog_stack["default"].top === this.uid) {
var _this$closeOnEscKeydo;
utils_event.emitEvent(this, "esc-keydown", {
e: e
});
if ((_this$closeOnEscKeydo = this.closeOnEscKeydown) !== null && _this$closeOnEscKeydo !== void 0 ? _this$closeOnEscKeydo : this.global.closeOnEscKeydown) {
this.emitCloseEvent({
e: e,
trigger: "esc"
});
}
}
},
keyboardEnterEvent: function keyboardEnterEvent(e) {
var code = e.code;
if ((code === "Enter" || code === "NumpadEnter") && dialog_stack["default"].top === this.uid) {
utils_event.emitEvent(this, "confirm", {
e: e
});
}
},
overlayAction: function overlayAction(e) {
var _this$closeOnOverlayC;
if (e.target !== this.$refs.dialogPosition) {
return;
}
utils_event.emitEvent(this, "overlay-click", {
e: e
});
if (this.showOverlay && ((_this$closeOnOverlayC = this.closeOnOverlayClick) !== null && _this$closeOnOverlayC !== void 0 ? _this$closeOnOverlayC : this.global.closeOnOverlayClick)) {
this.emitCloseEvent({
e: e,
trigger: "overlay"
});
}
},
closeBtnAction: function closeBtnAction(e) {
utils_event.emitEvent(this, "close-btn-click", {
e: e
});
this.emitCloseEvent({
trigger: "close-btn",
e: e
});
},
cancelBtnAction: function cancelBtnAction(e) {
utils_event.emitEvent(this, "cancel", {
e: e
});
this.emitCloseEvent({
trigger: "cancel",
e: e
});
},
confirmBtnAction: function confirmBtnAction(e) {
utils_event.emitEvent(this, "confirm", {
e: e
});
},
beforeEnter: function beforeEnter() {
utils_event.emitEvent(this, "before-open");
},
afterEnter: function afterEnter() {
utils_event.emitEvent(this, "opened");
},
beforeLeave: function beforeLeave() {
utils_event.emitEvent(this, "before-close");
},
afterLeave: function afterLeave() {
if (this.isModeLess && this.draggable) {
var target = this.$refs.dialog;
if (!target) return;
target.style.position = "relative";
target.style.left = "unset";
target.style.top = "unset";
}
utils_event.emitEvent(this, "closed");
this.animationEnd = true;
},
emitCloseEvent: function emitCloseEvent(context) {
utils_event.emitEvent(this, "close", context);
this.$emit("update:visible", false);
},
hasEventOn: function hasEventOn(name) {
var _this$_events;
var eventFuncs = (_this$_events = this["_events"]) === null || _this$_events === void 0 ? void 0 : _this$_events[name];
return !!(eventFuncs !== null && eventFuncs !== void 0 && eventFuncs.length);
},
getIcon: function getIcon() {
var h = this.$createElement;
var _this$useGlobalIcon = this.useGlobalIcon({
InfoCircleFilledIcon: tdesignIconsVue.InfoCircleFilledIcon,
CheckCircleFilledIcon: tdesignIconsVue.CheckCircleFilledIcon,
ErrorCircleFilledIcon: tdesignIconsVue.ErrorCircleFilledIcon
}),
InfoCircleFilledIcon = _this$useGlobalIcon.InfoCircleFilledIcon,
CheckCircleFilledIcon = _this$useGlobalIcon.CheckCircleFilledIcon,
ErrorCircleFilledIcon = _this$useGlobalIcon.ErrorCircleFilledIcon;
var icon = {
info: h(InfoCircleFilledIcon, {
"class": "".concat(this.classPrefix, "-is-info")
}),
warning: h(ErrorCircleFilledIcon, {
"class": "".concat(this.classPrefix, "-is-warning")
}),
danger: h(ErrorCircleFilledIcon, {
"class": "".concat(this.classPrefix, "-is-error")
}),
success: h(CheckCircleFilledIcon, {
"class": "".concat(this.classPrefix, "-is-success")
})
};
return icon[this.theme];
},
mousedownHandler: function mousedownHandler(targetEvent) {
var target = this.$refs.dialog;
this.disX = targetEvent.clientX - target.offsetLeft;
this.disY = targetEvent.clientY - target.offsetTop;
this.dialogW = target.offsetWidth;
this.dialogH = target.offsetHeight;
this.windowInnerWidth = window.innerWidth || document.documentElement.clientWidth;
this.windowInnerHeight = window.innerHeight || document.documentElement.clientHeight;
if (this.dialogW > this.windowInnerWidth || this.dialogH > this.windowInnerHeight) return;
document.addEventListener("mousemove", this.mouseMoverHandler);
document.addEventListener("mouseup", this.mouseUpHandler);
document.addEventListener("dragend", this.mouseUpHandler);
},
mouseMoverHandler: function mouseMoverHandler(documentEvent) {
var target = this.$refs.dialog;
var left = documentEvent.clientX - this.disX;
var top = documentEvent.clientY - this.disY;
if (left < 0) left = 0;
if (top < 0) top = 0;
if (this.windowInnerWidth - target.offsetWidth - left < 0) left = this.windowInnerWidth - target.offsetWidth;
if (this.windowInnerHeight - target.offsetHeight - top < 0) top = this.windowInnerHeight - target.offsetHeight;
target.style.position = "absolute";
target.style.left = "".concat(left, "px");
target.style.top = "".concat(top, "px");
},
mouseUpHandler: function mouseUpHandler() {
document.removeEventListener("mousemove", this.mouseMoverHandler);
document.removeEventListener("mouseup", this.mouseUpHandler);
document.removeEventListener("dragend", this.mouseUpHandler);
},
initDragEvent: function initDragEvent(status) {
var target = this.$refs.dialog;
if (status) {
target.addEventListener("mousedown", this.mousedownHandler);
} else {
target.removeEventListener("mousedown", this.mousedownHandler);
}
},
resizeAdjustPosition: function resizeAdjustPosition() {
if (this.visible) {
var target = this.$refs.dialog;
target.style.left = "".concat(this.dLeft * (window.innerWidth / this.windowInnerWidth), "px");
target.style.top = "".concat(this.dTop * (window.innerHeight / this.windowInnerHeight), "px");
}
},
onStopDown: function onStopDown(e) {
if (this.isModeLess && this.draggable) e.stopPropagation();
},
renderDialog: function renderDialog() {
var _this$instanceGlobal, _this$instanceGlobal2, _this$instanceGlobal3;
var h = this.$createElement;
var _this$useGlobalIcon2 = this.useGlobalIcon({
CloseIcon: tdesignIconsVue.CloseIcon
}),
CloseIcon = _this$useGlobalIcon2.CloseIcon;
var defaultHeader = h("h5", {
"class": "title"
});
var defaultCloseBtn = h(CloseIcon);
var body = utils_renderTnode.renderContent(this, "default", "body");
var defaultFooter = h("div", [this.getCancelBtn({
cancelBtn: this.cancelBtn,
globalCancel: ((_this$instanceGlobal = this.instanceGlobal) === null || _this$instanceGlobal === void 0 ? void 0 : _this$instanceGlobal.cancel) || this.global.cancel,
className: "".concat(this.componentName, "__cancel")
}), this.getConfirmBtn({
theme: this.theme,
confirmBtn: this.confirmBtn,
confirmLoading: this.confirmLoading,
globalConfirm: ((_this$instanceGlobal2 = this.instanceGlobal) === null || _this$instanceGlobal2 === void 0 ? void 0 : _this$instanceGlobal2.confirm) || this.global.confirm,
globalConfirmBtnTheme: ((_this$instanceGlobal3 = this.instanceGlobal) === null || _this$instanceGlobal3 === void 0 ? void 0 : _this$instanceGlobal3.confirmBtnTheme) || this.global.confirmBtnTheme,
className: "".concat(this.componentName, "__confirm")
})]);
var headerClassName = this.isFullScreen ? ["".concat(this.componentName, "__header"), "".concat(this.componentName, "__header--fullscreen")] : "".concat(this.componentName, "__header");
var closeClassName = this.isFullScreen ? ["".concat(this.componentName, "__close"), "".concat(this.componentName, "__close--fullscreen")] : "".concat(this.componentName, "__close");
var bodyClassName = this.theme === "default" ? ["".concat(this.componentName, "__body")] : ["".concat(this.componentName, "__body"), "".concat(this.componentName, "__body__icon")];
var footerContent = utils_renderTnode.renderTNodeJSX(this, "footer", defaultFooter);
if (this.isFullScreen && footerContent) {
bodyClassName.push("".concat(this.componentName, "__body--fullscreen"));
} else if (this.isFullScreen) {
bodyClassName.push("".concat(this.componentName, "__body--fullscreen--without-footer"));
}
var footerClassName = this.isFullScreen ? ["".concat(this.componentName, "__footer"), "".concat(this.componentName, "__footer--fullscreen")] : "".concat(this.componentName, "__footer");
var footer = this.footer ? h("div", {
"class": footerClassName,
"on": {
"mousedown": this.onStopDown
}
}, [footerContent]) : null;
return h("div", {
"class": this.wrapClass
}, [h("div", {
"class": this.positionClass,
"style": this.positionStyle,
"on": {
"click": this.overlayAction
},
"ref": "dialogPosition"
}, [h("div", {
"key": "dialog",
"ref": "dialog",
"class": this.dialogClass,
"style": this.computedDialogStyle
}, [h("div", {
"class": headerClassName,
"on": {
"mousedown": this.onStopDown
}
}, [h("div", {
"class": "".concat(this.componentName, "__header-content")
}, [this.getIcon(), utils_renderTnode.renderTNodeJSX(this, "header", defaultHeader)]), this.closeBtn ? h("span", {
"class": closeClassName,
"on": {
"click": this.closeBtnAction
}
}, [utils_renderTnode.renderTNodeJSX(this, "closeBtn", defaultCloseBtn)]) : null]), h("div", {
"class": bodyClassName,
"on": {
"mousedown": this.onStopDown
}
}, [body]), footer])])]);
}
},
render: function render() {
var h = arguments[0];
var maskView = (this.isModal || this.isFullScreen) && h("div", {
"key": "mask",
"class": this.maskClass
});
var dialogView = this.renderDialog();
var view = [maskView, dialogView];
var ctxStyle = {
zIndex: this.zIndex
};
if (this.destroyOnClose && !this.visible && this.animationEnd) return null;
return h("transition", {
"attrs": {
"duration": 300,
"name": "".concat(this.componentName, "-zoom__vue")
},
"on": {
"beforeEnter": this.beforeEnter,
"afterEnter": this.afterEnter,
"beforeLeave": this.beforeLeave,
"afterLeave": this.afterLeave
}
}, [h("div", {
"directives": [{
name: "show",
value: this.visible
}, {
name: "transfer-dom",
value: this.computedAttach
}],
"class": this.ctxClass,
"style": ctxStyle
}, [view])]);
}
});
exports["default"] = _Dialog;
//# sourceMappingURL=dialog.js.map