UNPKG

tdesign-vue

Version:
195 lines (191 loc) 6.63 kB
/** * tdesign v1.15.0 * (c) 2026 tdesign * @license MIT */ import { h as helper } from '../_chunks/dep-53490f85.js'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import Vue from 'vue'; import { getVNodeComponentName, getVueComponentName } from '../utils/helper.js'; import props from './props.js'; import _TabPanel from './tab-panel.js'; import TTabNav from './tab-nav.js'; import { emitEvent } from '../utils/event.js'; import { getClassPrefixMixins } from '../config-provider/config-receiver.js'; import mixins from '../utils/mixins.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import 'lodash-es'; import './tab-panel-props.js'; import '../utils/render-tnode.js'; import '@babel/runtime/helpers/readOnlyError'; import '@babel/runtime/helpers/typeof'; import '@vue/composition-api'; import '../hooks/useDestroyOnClose.js'; import 'tdesign-icons-vue'; import './utils/handleDragSort.js'; import './tab-nav-item.js'; import '../utils/ripple.js'; import '../_common/js/utils/setStyle.js'; import '../config.js'; import '../_common/js/tabs/base.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-e5d497fb.js'; import '../_chunks/dep-1618e1d6.js'; import 'dayjs'; import '../_common/js/global-config/t.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 classPrefixMixins = getClassPrefixMixins("tabs"); var _Tabs = mixins(Vue, classPrefixMixins).extend(_objectSpread(_objectSpread({ name: "TTabs", model: { prop: "value", event: "change" }, components: { TTabPanel: _TabPanel, TTabNav: TTabNav } }, { listPanels: null }), {}, { props: _objectSpread({}, props), provide: function provide() { return { parent: this }; }, data: function data() { return { panels: [] }; }, watch: { list: { handler: function handler() { this.listPanels = this.createListPanels(); }, deep: true } }, mounted: function mounted() { this.updatePanels(); }, updated: function updated() { var _this = this; this.$nextTick(function () { _this.updatePanels(); }); }, methods: { updatePanels: function updatePanels() { var _this2 = this; var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$force = _ref.force, force = _ref$force === void 0 ? false : _ref$force; if (!this.listPanels) { this.panels = this.panels || []; return; } var newPanels = this.listPanels.filter(function (child) { return getVNodeComponentName(child) === getVueComponentName(_TabPanel); }).map(function (panel) { return panel.componentInstance; }).filter(Boolean); var isUnchanged = function isUnchanged() { return newPanels.length === _this2.panels.length && _this2.panels.every(function (panel, index) { return panel === newPanels[index]; }); }; if (isUnchanged() && !force) return; this.panels = newPanels; }, onAddTab: function onAddTab(e) { emitEvent(this, "add", { e: e }); }, onChangeTab: function onChangeTab(value) { emitEvent(this, "change", value); }, onRemoveTab: function onRemoveTab(_ref2) { var e = _ref2.e, value = _ref2.value, index = _ref2.index; var panel = this.panels[index]; emitEvent(this, "remove", { value: value, index: index, e: e }); if (!panel) return; emitEvent(panel, "remove", { value: value, e: e }); }, renderHeader: function renderHeader() { var _this3 = this; var h = this.$createElement; var onDragSort = function onDragSort(context) { emitEvent(_this3, "drag-sort", context); }; var tabNavProps = { theme: this.theme, value: this.value, size: this.size, disabled: this.disabled, placement: this.placement, addable: this.addable, panels: this.panels, scrollPosition: this.scrollPosition, dragSort: this.dragSort, onDragSort: onDragSort }; return h("div", { "class": _defineProperty(_defineProperty({}, "".concat(this.componentName, "__header"), true), "".concat(this.classPrefix, "-is-").concat(this.placement), true) }, [h(TTabNav, helper([{}, { "props": tabNavProps }, { "on": { "change": this.onChangeTab, "add": this.onAddTab, "remove": this.onRemoveTab } }]))]); }, createListPanels: function createListPanels() { var h = this.$createElement; return this.list.map(function (item) { return h(_TabPanel, helper([{}, { "props": _objectSpread({}, item) }])); }); }, renderList: function renderList() { if (!this.listPanels) { return this.createListPanels(); } return this.listPanels; }, renderContent: function renderContent() { var _this$$scopedSlots$de, _this$$scopedSlots; var h = this.$createElement; this.listPanels = this.list ? this.renderList() : ((_this$$scopedSlots$de = (_this$$scopedSlots = this.$scopedSlots)["default"]) === null || _this$$scopedSlots$de === void 0 ? void 0 : _this$$scopedSlots$de.call(_this$$scopedSlots, {})) || []; return h("div", { "class": ["".concat(this.componentName, "__content")] }, [this.listPanels]); } }, render: function render() { var h = arguments[0]; return h("div", { "class": this.componentName }, [this.placement !== "bottom" ? [this.renderHeader(), this.renderContent()] : [this.renderContent(), this.renderHeader()]]); } })); export { _Tabs as default }; //# sourceMappingURL=tabs.js.map