tdesign-vue
Version:
178 lines (174 loc) • 7.41 kB
JavaScript
/**
* tdesign v1.14.1
* (c) 2025 tdesign
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, inject, computed, onMounted } from '@vue/composition-api';
import props from './menu-item-props.js';
import Ripple from '../utils/ripple.js';
import { renderTNodeJSX, renderContent } from '../utils/render-tnode.js';
import { getKeepAnimationMixins } from '../config-provider/config-receiver.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import { Tooltip } from '../tooltip/index.js';
import '../_common/js/utils/setStyle.js';
import '../config.js';
import '@babel/runtime/helpers/readOnlyError';
import '@babel/runtime/helpers/typeof';
import 'vue';
import 'lodash-es';
import '../config-provider/context.js';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-ba613a02.js';
import '../_chunks/dep-fdb1b253.js';
import 'dayjs';
import '../_common/js/global-config/t.js';
import '@babel/runtime/helpers/slicedToArray';
import '../config-provider/useConfig.js';
import '../tooltip/tooltip.js';
import '../_chunks/dep-6a4dc7bb.js';
import '../tooltip/props.js';
import '../popup/props.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../utils/dom.js';
import 'raf';
import '../utils/easing.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../popup/container.js';
import '../utils/mixins.js';
import '../utils/event.js';
import '../popup/utils.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
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(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; }
var keepAnimationMixins = getKeepAnimationMixins();
var _MenuItem = defineComponent({
name: "TMenuItem",
mixins: [keepAnimationMixins],
props: _objectSpread({}, props),
directives: {
ripple: Ripple
},
setup: function setup(props2, ctx) {
var menu = inject("TdMenu");
var submenu = inject("TdSubmenu", null);
var active = computed(function () {
return menu.activeValue.value === props2.value;
});
var collapsed = computed(function () {
var _menu$collapsed;
return (_menu$collapsed = menu.collapsed) === null || _menu$collapsed === void 0 ? void 0 : _menu$collapsed.value;
});
var classPrefix = usePrefixClass();
var classes = computed(function () {
return ["".concat(classPrefix.value, "-menu__item"), _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(classPrefix.value, "-is-active"), active.value), "".concat(classPrefix.value, "-is-disabled"), props2.disabled), "".concat(classPrefix.value, "-menu__item--plain"), !ctx.slots.icon && !props2.icon), "".concat(classPrefix.value, "-submenu__item"), !!submenu && !menu.isHead)];
});
var handleClick = function handleClick(e) {
var _props2$onClick, _submenu$closeParentP;
e.stopPropagation();
if (props2.disabled) return;
if (menu.activeValue.value !== props2.value) {
menu.select(props2.value);
}
ctx.emit("click", {
e: e,
value: props2.value
});
(_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 || _props2$onClick.call(props2, {
e: e,
value: props2.value
});
if (props2.to || props2.routerLink && props2.href) {
var router = props2.router || ctx.root.$router;
var methods = props2.replace ? "replace" : "push";
router[methods](props2.to || props2.href)["catch"](function (err) {
if (err.name !== "NavigationDuplicated" && !err.message.includes("Avoided redundant navigation to current location")) {
throw err;
}
});
}
submenu === null || submenu === void 0 || (_submenu$closeParentP = submenu.closeParentPopup) === null || _submenu$closeParentP === void 0 || _submenu$closeParentP.call(submenu, e);
};
onMounted(function () {
var _menu$vMenu;
menu === null || menu === void 0 || (_menu$vMenu = menu.vMenu) === null || _menu$vMenu === void 0 || _menu$vMenu.add({
value: props2.value,
parent: submenu === null || submenu === void 0 ? void 0 : submenu.value,
vnode: ctx.slots["default"] && ctx.slots["default"]()
});
});
var activeValues = menu.activeValues.value;
if (activeValues.includes(props2.value) && !activeValues.includes(submenu === null || submenu === void 0 ? void 0 : submenu.value)) {
activeValues.push(submenu === null || submenu === void 0 ? void 0 : submenu.value);
}
return {
menu: menu,
active: active,
collapsed: collapsed,
classes: classes,
handleClick: handleClick,
classPrefix: classPrefix
};
},
render: function render() {
var _this = this,
_this$$parent$$vnode;
var h = arguments[0];
var router = this.router || this.$router;
var liContent = h("li", {
"directives": [{
name: "ripple",
value: this.keepAnimation.ripple
}],
"class": this.classes,
"on": {
"click": this.handleClick
}
}, [renderTNodeJSX(this, "icon"), this.routerLink ? h("a", {
"attrs": {
"href": this.href ? this.href : this.to ? router === null || router === void 0 ? void 0 : router.resolve(this.to).href : "",
"target": this.target
},
"class": "".concat(this.classPrefix, "-menu__item-link"),
"on": {
"click": function click(e) {
return e.preventDefault();
}
}
}, [h("span", {
"class": "".concat(this.classPrefix, "-menu__content")
}, [renderContent(this, "default", "content")])]) : this.href ? h("a", {
"attrs": {
"href": this.href,
"target": this.target
},
"class": "".concat(this.classPrefix, "-menu__item-link"),
"on": {
"click": function click(e) {
return _this.disabled && e.preventDefault();
}
}
}, [h("span", {
"class": "".concat(this.classPrefix, "-menu__content")
}, [renderContent(this, "default", "content")])]) : h("span", {
"class": "".concat(this.classPrefix, "-menu__content")
}, [renderContent(this, "default", "content")])]);
if (this.collapsed && /tmenu/i.test((_this$$parent$$vnode = this.$parent.$vnode) === null || _this$$parent$$vnode === void 0 ? void 0 : _this$$parent$$vnode.tag)) {
return h(Tooltip, {
"attrs": {
"content": function content() {
return renderContent(_this, "default", "content");
},
"placement": "right"
}
}, [liContent]);
}
return liContent;
}
});
export { _MenuItem as default };
//# sourceMappingURL=menu-item.js.map