tdesign-vue
Version:
496 lines (488 loc) • 18.9 kB
JavaScript
/**
* tdesign v1.15.0
* (c) 2026 tdesign
* @license MIT
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var helper = require('../_chunks/dep-4009cfe4.js');
var _typeof = require('@babel/runtime/helpers/typeof');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var tdesignIconsVue = require('tdesign-icons-vue');
var button_index = require('../button/index.js');
var drawer_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 dialog_actions = require('../dialog/actions.js');
var _common_js_utils_getScrollbarWidth = require('../_common/js/utils/getScrollbarWidth.js');
var _common_js_drawer_utils = require('../_common/js/drawer/utils.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-721fcdf6.js');
require('../_chunks/dep-591b87f1.js');
require('../_chunks/dep-a2217d56.js');
require('../_chunks/dep-3b2292ce.js');
require('../_chunks/dep-10fcb46d.js');
require('../_chunks/dep-ba7f5924.js');
require('../_chunks/dep-268c68b1.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-9c5b91d3.js');
require('../_chunks/dep-9a74c2be.js');
require('../_chunks/dep-689d381f.js');
require('../_chunks/dep-803744d9.js');
require('../_chunks/dep-84027b7f.js');
require('../_chunks/dep-49400b00.js');
require('../_chunks/dep-f1081d8e.js');
require('../_chunks/dep-2c592e99.js');
require('../_chunks/dep-8eddb350.js');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-0c37520c.js');
require('../_chunks/dep-c13dcbfd.js');
require('dayjs');
require('../_chunks/dep-6f4e680e.js');
require('../_chunks/dep-bb0ececf.js');
require('../_chunks/dep-6eba4d23.js');
require('../_chunks/dep-010db548.js');
require('../_chunks/dep-8d206316.js');
require('../_chunks/dep-2bc87cc8.js');
require('../_chunks/dep-f77d6ad5.js');
require('../_chunks/dep-9dae8101.js');
require('../_chunks/dep-7c84d9a0.js');
require('../_chunks/dep-733a2279.js');
require('../_chunks/dep-d844c9ed.js');
require('../_chunks/dep-c05a9033.js');
require('../_chunks/dep-efe55b82.js');
require('../_chunks/dep-7da70ee1.js');
require('../_chunks/dep-124386d4.js');
require('../_chunks/dep-f5b14344.js');
require('../_chunks/dep-36c2788b.js');
require('../_chunks/dep-fa353fbb.js');
require('../_chunks/dep-d66ab3a4.js');
require('../_chunks/dep-d4d8c513.js');
require('../_common/js/global-config/t.js');
require('../config.js');
require('../_chunks/dep-97fef2be.js');
require('../_chunks/dep-0b47afa3.js');
require('../_chunks/dep-d7516e38.js');
require('../_chunks/dep-74be1050.js');
require('../_chunks/dep-7fbd94e9.js');
require('../_chunks/dep-56f568d3.js');
require('../_chunks/dep-82ce56ef.js');
require('../_chunks/dep-4e96e31a.js');
require('../_chunks/dep-17ce3e74.js');
require('../_chunks/dep-a7198720.js');
require('../_chunks/dep-1e173c2b.js');
require('../_chunks/dep-c9ce9427.js');
require('../_chunks/dep-edb55477.js');
require('../utils/withInstall.js');
require('../button/props.js');
require('../utils/ripple.js');
require('../utils/helper.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var key = 1;
var _Drawer = utils_mixins["default"](dialog_actions["default"], configProvider_configReceiver["default"]("drawer"), configProvider_configReceiver.getGlobalIconMixins(), configProvider_configReceiver.getAttachConfigMixins("drawer")).extend({
name: "TDrawer",
components: {
TButton: button_index.Button
},
props: drawer_props["default"],
directives: {
TransferDom: utils_transferDom["default"]
},
data: function data() {
return {
isSizeDragging: false,
draggedSizeValue: null,
animationStart: false,
animationEnd: true,
styleTimer: null,
styleEl: null
};
},
computed: {
drawerClasses: function drawerClasses() {
return [this.componentName, "".concat(this.componentName, "--").concat(this.placement), _defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"]({}, "".concat(this.componentName, "--open"), this.visible), "".concat(this.componentName, "--attach"), this.showInAttachedElement), "".concat(this.componentName, "--without-mask"), !this.showOverlay), this.drawerClassName];
},
sizeValue: function sizeValue() {
var _this$size;
if (this.draggedSizeValue) return this.draggedSizeValue;
var size = (_this$size = this.size) !== null && _this$size !== void 0 ? _this$size : this.global.size;
var defaultSize = isNaN(Number(size)) ? size : "".concat(size, "px");
return {
small: "300px",
medium: "500px",
large: "760px"
}[size] || defaultSize;
},
wrapperStyles: function wrapperStyles() {
return {
transform: this.visible && this.animationStart ? "translateX(0)" : void 0,
width: this.isHorizontal ? this.sizeValue : "",
height: this.isVertical ? this.sizeValue : ""
};
},
wrapperClasses: function wrapperClasses() {
return ["".concat(this.componentName, "__content-wrapper"), "".concat(this.componentName, "__content-wrapper--").concat(this.placement)];
},
parentNode: function parentNode() {
return this.$el && this.$el.parentNode;
},
modeAndPlacement: function modeAndPlacement() {
return [this.mode, this.placement].join();
},
footerStyle: function footerStyle() {
return {
display: "flex",
justifyContent: this.placement === "right" ? "flex-start" : "flex-end"
};
},
isHorizontal: function isHorizontal() {
return ["right", "left"].includes(this.placement);
},
isVertical: function isVertical() {
return ["top", "bottom"].includes(this.placement);
},
draggableLineStyles: function draggableLineStyles() {
var oppositeMap = {
left: "right",
right: "left",
top: "bottom",
bottom: "top"
};
return _defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"]({
zIndex: 1,
position: "absolute",
background: "transparent"
}, oppositeMap[this.placement], 0), "width", this.isHorizontal ? "16px" : "100%"), "height", this.isHorizontal ? "100%" : "16px"), "cursor", this.isHorizontal ? "col-resize" : "row-resize");
},
computedAttach: function computedAttach() {
return this.attach || this.globalAttach();
}
},
watch: {
modeAndPlacement: {
handler: function handler() {
this.handlePushMode();
},
immediate: true
},
visible: {
handler: function handler(val) {
var _this = this;
if (val) {
this.$nextTick(function () {
var _this$$refs$drawerCon, _this$$refs$drawerCon2;
(_this$$refs$drawerCon = _this.$refs.drawerContainer) === null || _this$$refs$drawerCon === void 0 || (_this$$refs$drawerCon2 = _this$$refs$drawerCon.focus) === null || _this$$refs$drawerCon2 === void 0 || _this$$refs$drawerCon2.call(_this$$refs$drawerCon);
});
}
this.handleScrollThrough(val);
}
}
},
updated: function updated() {
this.updatePushMode();
},
mounted: function mounted() {
var hasScrollBar = window.innerWidth > document.documentElement.clientWidth;
var scrollWidth = hasScrollBar ? _common_js_utils_getScrollbarWidth.getScrollbarWidth() : 0;
this.styleEl = document.createElement("style");
this.styleEl.dataset.id = "td_drawer_".concat(+new Date(), "_").concat(key += 1);
this.styleEl.innerHTML = "\n html body {\n overflow-y: hidden;\n transition: margin 300ms cubic-bezier(0.7, 0.3, 0.1, 1) 0s;\n ".concat(this.mode === "push" ? "" : "width: calc(100% - ".concat(scrollWidth, "px);"), "\n }\n ");
this.handleScrollThrough(this.visible);
},
beforeDestroy: function beforeDestroy() {
this.clearStyleFunc();
},
render: function render() {
var h = arguments[0];
if (this.destroyOnClose && !this.visible && this.animationEnd) return null;
var _this$useGlobalIcon = this.useGlobalIcon({
CloseIcon: tdesignIconsVue.CloseIcon
}),
CloseIcon = _this$useGlobalIcon.CloseIcon;
var defaultCloseBtn = h(CloseIcon, {
"class": "".concat(this.classPrefix, "-submenu-icon")
});
var body = utils_renderTnode.renderContent(this, "default", "body");
var defaultFooter = this.getDefaultFooter();
return h("transition", {
"on": {
"appear": this.afterEnter,
"beforeEnter": this.beforeEnter,
"beforeLeave": this.beforeLeave,
"afterEnter": this.afterEnter,
"afterLeave": this.afterLeave
},
"attrs": {
"duration": {
enter: 10,
leave: 300
}
}
}, [h("div", {
"class": this.drawerClasses,
"style": {
zIndex: this.zIndex
},
"on": {
"keydown": this.onKeyDown
},
"directives": [{
name: "transfer-dom",
value: this.computedAttach
}, {
name: "show",
value: this.visible
}],
"ref": "drawerContainer",
"attrs": {
"tabindex": 0
}
}, [this.showOverlay && h("transition", {
"attrs": {
"duration": 300,
"name": "".concat(this.componentName, "-fade")
}
}, [h("div", {
"key": "mask",
"class": "".concat(this.componentName, "__mask"),
"on": {
"click": this.handleWrapperClick
},
"directives": [{
name: "show",
value: this.visible
}]
})]), h("div", {
"class": this.wrapperClasses,
"style": this.wrapperStyles
}, [this.header !== false ? h("div", {
"class": "".concat(this.componentName, "__header")
}, [utils_renderTnode.renderTNodeJSX(this, "header", h("div"))]) : null, this.closeBtn !== false ? h("div", {
"class": "".concat(this.componentName, "__close-btn"),
"on": {
"click": this.handleCloseBtnClick
}
}, [utils_renderTnode.renderTNodeJSX(this, "closeBtn", defaultCloseBtn)]) : null, h("div", {
"class": "".concat(this.componentName, "__body")
}, [body]), this.footer !== false ? h("div", {
"class": "".concat(this.componentName, "__footer")
}, [utils_renderTnode.renderTNodeJSX(this, "footer", defaultFooter)]) : null, this.sizeDraggable && h("div", {
"style": this.draggableLineStyles,
"on": {
"mousedown": this.enableDrag
}
})])])]);
},
methods: {
clearStyleFunc: function clearStyleFunc() {
var _this2 = this;
clearTimeout(this.styleTimer);
this.styleTimer = setTimeout(function () {
var _this2$styleEl$parent, _this2$styleEl$parent2;
(_this2$styleEl$parent = _this2.styleEl.parentNode) === null || _this2$styleEl$parent === void 0 || (_this2$styleEl$parent2 = _this2$styleEl$parent.removeChild) === null || _this2$styleEl$parent2 === void 0 || _this2$styleEl$parent2.call(_this2$styleEl$parent, _this2.styleEl);
}, 150);
},
beforeEnter: function beforeEnter() {
utils_event.emitEvent(this, "before-open");
},
afterEnter: function afterEnter() {
this.animationStart = true;
this.animationEnd = false;
},
beforeLeave: function beforeLeave() {
utils_event.emitEvent(this, "before-close");
},
afterLeave: function afterLeave() {
this.animationStart = false;
this.animationEnd = true;
},
enableDrag: function enableDrag() {
document.addEventListener("mouseup", this.handleMouseup, true);
document.addEventListener("mousemove", this.handleMousemove, true);
this.isSizeDragging = true;
},
handleMouseup: function handleMouseup() {
document.removeEventListener("mouseup", this.handleMouseup, true);
document.removeEventListener("mousemove", this.handleMousemove, true);
this.isSizeDragging = false;
},
handleMousemove: function handleMousemove(e) {
var x = e.x,
y = e.y;
var maxHeight = document.documentElement.clientHeight;
var maxWidth = document.documentElement.clientWidth;
var offsetHeight = 8;
var offsetWidth = 8;
var max = this.placement === "left" || this.placement === "right" ? maxWidth : maxHeight;
var min = this.placement === "left" || this.placement === "right" ? offsetWidth : offsetHeight;
var _getSizeDraggable = _common_js_drawer_utils.getSizeDraggable(this.sizeDraggable, {
max: max,
min: min
}),
allowSizeDraggable = _getSizeDraggable.allowSizeDraggable,
limitMax = _getSizeDraggable.max,
limitMin = _getSizeDraggable.min;
if (!this.isSizeDragging || !allowSizeDraggable) return;
var moveSize = _common_js_drawer_utils.calcMoveSize(this.placement, {
x: x,
y: y,
maxWidth: maxWidth,
maxHeight: maxHeight,
max: limitMax,
min: limitMin
});
if (typeof moveSize === "undefined") return;
this.draggedSizeValue = "".concat(moveSize, "px");
},
handleScrollThrough: function handleScrollThrough(visible) {
if (!document || !document.body || !this.preventScrollThrough) return;
if (visible) {
if (!this.showInAttachedElement && this.preventScrollThrough) {
document.head.appendChild(this.styleEl);
}
} else {
this.clearStyleFunc();
}
},
handlePushMode: function handlePushMode() {
var _this3 = this;
if (this.mode !== "push") return;
this.$nextTick(function () {
if (!_this3.parentNode) return;
_this3.parentNode.style.cssText = "transition: margin 300ms cubic-bezier(0.7, 0.3, 0.1, 1) 0s;";
});
},
updatePushMode: function updatePushMode() {
if (!this.parentNode) return;
if (this.mode !== "push" || !this.parentNode) return;
var marginStr = {
left: "margin: 0 0 0 ".concat(this.sizeValue),
right: "margin: 0 0 0 -".concat(this.sizeValue),
top: "margin: ".concat(this.sizeValue, " 0 0 0"),
bottom: "margin: -".concat(this.sizeValue, " 0 0 0")
}[this.placement];
if (this.visible) {
this.parentNode.style.cssText += marginStr;
} else {
this.parentNode.style.cssText = this.parentNode.style.cssText.replace(/margin:.+;/, "");
}
},
getDefaultBtn: function getDefaultBtn(btnType, btnApi) {
var h = this.$createElement;
var isCancel = btnType === "cancel";
var clickAction = isCancel ? this.cancelBtnAction : this.confirmBtnAction;
var theme = isCancel ? "default" : "primary";
var isApiObject = _typeof__default["default"](btnApi) === "object";
return h("t-button", helper.helper([{
"attrs": {
"theme": theme
},
"on": {
"click": clickAction
}
}, {
"props": isApiObject ? btnApi : {}
}, {
"class": "".concat(this.componentName, "-").concat(btnType)
}]), [btnApi && _typeof__default["default"](btnApi) === "object" ? btnApi.content : btnApi]);
},
isUseDefault: function isUseDefault(btnApi) {
var baseTypes = ["string", "object"];
return Boolean(btnApi && baseTypes.includes(_typeof__default["default"](btnApi)));
},
getDefaultFooter: function getDefaultFooter() {
var h = this.$createElement;
var confirmBtn = this.getConfirmBtn({
confirmBtn: this.confirmBtn,
globalConfirm: this.global.confirm,
className: "".concat(this.componentName, "__confirm")
});
var cancelBtn = this.getCancelBtn({
cancelBtn: this.cancelBtn,
globalCancel: this.global.cancel,
className: "".concat(this.componentName, "__cancel")
});
return h("div", {
"style": this.footerStyle
}, [this.placement === "right" ? confirmBtn : null, cancelBtn, this.placement !== "right" ? confirmBtn : null]);
},
handleCloseBtnClick: function handleCloseBtnClick(e) {
utils_event.emitEvent(this, "close-btn-click", {
e: e
});
this.closeDrawer({
trigger: "close-btn",
e: e
});
},
handleWrapperClick: function handleWrapperClick(e) {
var _this$closeOnOverlayC;
utils_event.emitEvent(this, "overlay-click", {
e: e
});
if ((_this$closeOnOverlayC = this.closeOnOverlayClick) !== null && _this$closeOnOverlayC !== void 0 ? _this$closeOnOverlayC : this.global.closeOnOverlayClick) {
this.closeDrawer({
trigger: "overlay",
e: e
});
}
},
onKeyDown: function onKeyDown(e) {
if (e.key === "Escape") {
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.closeDrawer({
trigger: "esc",
e: e
});
}
}
},
confirmBtnAction: function confirmBtnAction(e) {
utils_event.emitEvent(this, "confirm", {
e: e
});
},
cancelBtnAction: function cancelBtnAction(e) {
utils_event.emitEvent(this, "cancel", {
e: e
});
this.closeDrawer({
trigger: "cancel",
e: e
});
},
closeDrawer: function closeDrawer(params) {
utils_event.emitEvent(this, "close", params);
this.$emit("update:visible", false);
}
}
});
exports["default"] = _Drawer;
//# sourceMappingURL=drawer.js.map