'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var shared = require('@vue/shared'); var aria = require('../../../utils/aria.js'); var index = require('../../icon/index.js'); var iconsVue = require('@element-plus/icons-vue'); var props = require('../../../utils/props.js'); var constants = require('../../../utils/constants.js'); require('../../../tokens/index.js'); var tabNav = require('./tab-nav.js'); var tabs = require('../../../tokens/tabs.js'); const tabsProps = props.buildProps({ type: { type: String, values: ["card", "border-card", ""], default: "" }, activeName: { type: String, default: "" }, closable: Boolean, addable: Boolean, modelValue: { type: String, default: "" }, editable: Boolean, tabPosition: { type: String, values: ["top", "right", "bottom", "left"], default: "top" }, beforeLeave: { type: props.definePropType(Function), default: () => true }, stretch: Boolean }); const tabsEmits = { [constants.UPDATE_MODEL_EVENT]: (tabName) => typeof tabName === "string", [constants.INPUT_EVENT]: (tabName) => typeof tabName === "string", "tab-click": (pane, ev) => ev instanceof Event, edit: (paneName, action) => action === "remove" || action === "add", "tab-remove": (paneName) => typeof paneName === "string", "tab-add": () => true }; const getPaneInstanceFromSlot = (vnode, paneInstanceList = []) => { const children = vnode.children || []; Array.from(children).forEach((node) => { let type = node.type; type = type.name || type; if (type === "ElTabPane" && node.component) { paneInstanceList.push(node.component); } else if (type === vue.Fragment || type === "template") { getPaneInstanceFromSlot(node, paneInstanceList); } }); return paneInstanceList; }; var Tabs = vue.defineComponent({ name: "ElTabs", props: tabsProps, emits: tabsEmits, setup(props, { emit, slots, expose }) { const instance = vue.getCurrentInstance(); const nav$ = vue.ref(); const panes = vue.ref([]); const currentName = vue.ref(props.modelValue || props.activeName || "0"); const paneStatesMap = {}; const updatePaneInstances = (isForceUpdate = false) => { if (slots.default) { const children = instance.subTree.children; const content = Array.from(children).find(({ props: props2 }) => (props2 == null ? void 0 : props2.class) === "el-tabs__content"); if (!content) return; const paneInstanceList = getPaneInstanceFromSlot(content).map((paneComponent) => paneStatesMap[paneComponent.uid]); const panesChanged = !(paneInstanceList.length === panes.value.length && paneInstanceList.every((pane, index) => pane.uid === panes.value[index].uid)); if (isForceUpdate || panesChanged) { panes.value = paneInstanceList; } } else if (panes.value.length !== 0) { panes.value = []; } }; const changeCurrentName = (value) => { currentName.value = value; emit(constants.INPUT_EVENT, value); emit(constants.UPDATE_MODEL_EVENT, value); }; const setCurrentName = (value) => { var _a; if (currentName.value === value) return; const canLeave = (_a = props.beforeLeave) == null ? void 0 : _a.call(props, value, currentName.value); if (shared.isPromise(canLeave)) { canLeave.then(() => { var _a2, _b; changeCurrentName(value); (_b = (_a2 = nav$.value) == null ? void 0 : _a2.removeFocus) == null ? void 0 : _b.call(_a2); }, shared.NOOP); } else if (canLeave !== false) { changeCurrentName(value); } }; const handleTabClick = (tab, tabName, event) => { if (tab.props.disabled) return; setCurrentName(tabName); emit("tab-click", tab, event); }; const handleTabRemove = (pane, ev) => { if (pane.props.disabled) return; ev.stopPropagation(); emit("edit", pane.props.name, "remove"); emit("tab-remove", pane.props.name); }; const handleTabAdd = () => { emit("edit", null, "add"); emit("tab-add"); }; vue.onUpdated(() => updatePaneInstances()); vue.onMounted(() => updatePaneInstances()); vue.watch(() => props.activeName, (modelValue) => setCurrentName(modelValue)); vue.watch(() => props.modelValue, (modelValue) => setCurrentName(modelValue)); vue.watch(currentName, async () => { var _a, _b; updatePaneInstances(true); await vue.nextTick(); await ((_a = nav$.value) == null ? void 0 : _a.$nextTick()); (_b = nav$.value) == null ? void 0 : _b.scrollToActiveTab(); }); vue.provide(tabs.tabsRootContextKey, { props, currentName, updatePaneState: (pane) => paneStatesMap[pane.uid] = pane }); expose({ currentName }); return () => { const newButton = props.editable || props.addable ? vue.h("span", { class: "el-tabs__new-tab", tabindex: "0", onClick: handleTabAdd, onKeydown: (ev) => { if (ev.code === aria.EVENT_CODE.enter) handleTabAdd(); } }, [vue.h(index.ElIcon, { class: "is-icon-plus" }, { default: () => vue.h(iconsVue.Plus) })]) : null; const header = vue.h("div", { class: ["el-tabs__header", `is-${props.tabPosition}`] }, [ newButton, vue.h(tabNav["default"], { currentName: currentName.value, editable: props.editable, type: props.type, panes: panes.value, stretch: props.stretch, ref: nav$, onTabClick: handleTabClick, onTabRemove: handleTabRemove }) ]); const panels = vue.h("div", { class: "el-tabs__content" }, [ vue.renderSlot(slots, "default") ]); return vue.h("div", { class: { "el-tabs": true, "el-tabs--card": props.type === "card", [`el-tabs--${props.tabPosition}`]: true, "el-tabs--border-card": props.type === "border-card" } }, props.tabPosition !== "bottom" ? [header, panels] : [panels, header]); }; } }); exports["default"] = Tabs; exports.tabsEmits = tabsEmits; exports.tabsProps = tabsProps; //# sourceMappingURL=tabs.js.map