UNPKG

tdesign-vue

Version:
176 lines (172 loc) 6.45 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, ref, computed, watchEffect, provide, watch, onMounted } from '@vue/composition-api'; import props from './props.js'; import { renderContent, renderTNodeJSX } from '../utils/render-tnode.js'; import VMenu from './v-menu.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import '@babel/runtime/helpers/readOnlyError'; import '@babel/runtime/helpers/typeof'; import 'vue'; import 'lodash-es'; import '@babel/runtime/helpers/classCallCheck'; import '@babel/runtime/helpers/createClass'; import '../config-provider/useConfig.js'; 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'; 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 _Menu = defineComponent({ name: "TMenu", props: _objectSpread({}, props), model: { prop: "value", event: "change" }, setup: function setup(props2, ctx) { var mode = ref(props2.expandType); var theme = computed(function () { return props2.theme; }); var isMutex = computed(function () { return props2.expandMutex; }); var classPrefix = usePrefixClass(); var collapsed = computed(function () { return props2.collapsed; }); var menuClass = computed(function () { return ["".concat(classPrefix.value, "-default-menu"), "".concat(classPrefix.value, "-menu--").concat(props2.theme), _defineProperty({}, "".concat(classPrefix.value, "-is-collapsed"), props2.collapsed)]; }); var innerClasses = computed(function () { return ["".concat(classPrefix.value, "-menu"), "".concat(classPrefix.value, "-menu--scroll")]; }); var expandWidth = computed(function () { var width = props2.width; var format = function format(val) { return typeof val === "number" ? "".concat(val, "px") : val; }; if (Array.isArray(width)) return width.map(function (item) { return format(item); }); return [format(width), "64px"]; }); var styles = computed(function () { return { height: "100%", width: props2.collapsed ? expandWidth.value[1] : expandWidth.value[0] }; }); var activeValue = ref(props2.defaultValue || props2.value); var activeValues = ref([]); var expandValues = ref(props2.expanded || []); var deliver = function deliver(evt) { var func = "on".concat(evt[0].toUpperCase() + evt.slice(1)); return function (val) { if (typeof props2[func] === "function") { props2[func](val); } ctx.emit(evt, val); }; }; var emitChange = deliver("change"); var emitExpand = deliver("expand"); watchEffect(function () { mode.value = props2.collapsed ? "popup" : props2.expandType; }); var vMenu = new VMenu({ isMutex: isMutex.value, expandValues: expandValues.value }); provide("TdMenu", { activeValue: activeValue, activeValues: activeValues, expandValues: expandValues, mode: mode, theme: theme, isHead: false, vMenu: vMenu, collapsed: collapsed, select: function select(value) { emitChange(value); }, open: function open(value, type) { var expanded = _toConsumableArray(expandValues.value); if (mode.value === "normal") { expanded = vMenu.expand(value); } else { var index = expanded.indexOf(value); if (type === "add") { if (index === -1) { expanded.push(value); } } else if (type === "remove") { expanded.splice(index, 1); } } emitExpand(expanded); } }); watch(function () { return props2.expanded; }, function (value) { expandValues.value = value; vMenu.expandValues = new Set(value); }); var updateActiveValues = function updateActiveValues(value) { activeValue.value = value; activeValues.value = vMenu.select(value); }; watch(function () { return props2.value; }, updateActiveValues); watch(function () { return props2.defaultValue; }, updateActiveValues); onMounted(function () { activeValues.value = vMenu.select(activeValue.value); }); return { styles: styles, menuClass: menuClass, innerClasses: innerClasses, activeValue: activeValue, activeValues: activeValues, expandValues: expandValues, classPrefix: classPrefix }; }, render: function render() { var h = arguments[0]; if (this.$slots.options) { console.warn("TDesign Warn: `options` slot is going to be deprecated, please use `operations` for slot instead."); } var operations = renderContent(this, "operations", "options"); var logo = renderTNodeJSX(this, "logo"); return h("div", { "class": this.menuClass, "style": this.styles }, [h("div", { "class": "".concat(this.classPrefix, "-default-menu__inner") }, [logo && h("div", { "class": "".concat(this.classPrefix, "-menu__logo") }, [logo]), h("ul", { "class": this.innerClasses }, [renderContent(this, "default", "content")]), operations && h("div", { "class": "".concat(this.classPrefix, "-menu__operations") }, [operations])])]); } }); export { _Menu as default }; //# sourceMappingURL=menu.js.map