feat: initial commit - Phase 1 & 2 core features

This commit is contained in:
hiderfong
2026-04-22 17:07:33 +08:00
commit 1773bda06b
25005 changed files with 6252106 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
import { SFCWithInstall } from "../../utils/vue/typescript.js";
import "../../utils/index.js";
import { _default } from "./src/tab-pane.vue.js";
import { TabPaneInstance, TabPaneProps, TabPanePropsPublic, tabPaneProps } from "./src/tab-pane.js";
import { TabPaneName, TabsPaneContext, TabsRootContext, tabsRootContextKey } from "./src/constants.js";
import { TabBarInstance, TabBarProps, TabBarPropsPublic, tabBarProps } from "./src/tab-bar.js";
import { TabNavEmits, TabNavInstance, TabNavProps, TabNavPropsPublic, tabNavEmits, tabNavProps } from "./src/tab-nav.js";
import { Tabs, TabsEmits, TabsInstance, TabsPanes, TabsProps, TabsPropsPublic, tabsEmits, tabsProps } from "./src/tabs.js";
//#region ../../packages/components/tabs/index.d.ts
declare const ElTabs: SFCWithInstall<typeof Tabs> & {
TabPane: typeof _default;
};
declare const ElTabPane: SFCWithInstall<typeof _default>;
//#endregion
export { ElTabPane, ElTabs, ElTabs as default, TabBarInstance, TabBarProps, TabBarPropsPublic, TabNavEmits, TabNavInstance, TabNavProps, TabNavPropsPublic, TabPaneInstance, TabPaneName, TabPaneProps, TabPanePropsPublic, TabsEmits, TabsInstance, TabsPaneContext, TabsPanes, TabsProps, TabsPropsPublic, TabsRootContext, tabBarProps, tabNavEmits, tabNavProps, tabPaneProps, tabsEmits, tabsProps, tabsRootContextKey };
+15
View File
@@ -0,0 +1,15 @@
import { withInstall, withNoopInstall } from "../../utils/vue/install.mjs";
import { tabsRootContextKey } from "./src/constants.mjs";
import { tabBarProps } from "./src/tab-bar.mjs";
import { tabNavEmits, tabNavProps } from "./src/tab-nav.mjs";
import Tabs, { tabsEmits, tabsProps } from "./src/tabs.mjs";
import { tabPaneProps } from "./src/tab-pane.mjs";
import tab_pane_default from "./src/tab-pane2.mjs";
//#region ../../packages/components/tabs/index.ts
const ElTabs = withInstall(Tabs, { TabPane: tab_pane_default });
const ElTabPane = withNoopInstall(tab_pane_default);
//#endregion
export { ElTabPane, ElTabs, ElTabs as default, tabBarProps, tabNavEmits, tabNavProps, tabPaneProps, tabsEmits, tabsProps, tabsRootContextKey };
//# sourceMappingURL=index.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","names":["TabPane"],"sources":["../../../../../packages/components/tabs/index.ts"],"sourcesContent":["import { withInstall, withNoopInstall } from '@element-plus/utils'\nimport Tabs from './src/tabs'\nimport TabPane from './src/tab-pane.vue'\n\nimport type { SFCWithInstall } from '@element-plus/utils'\n\nexport const ElTabs: SFCWithInstall<typeof Tabs> & {\n TabPane: typeof TabPane\n} = withInstall(Tabs, {\n TabPane,\n})\nexport const ElTabPane: SFCWithInstall<typeof TabPane> =\n withNoopInstall(TabPane)\nexport default ElTabs\n\nexport * from './src/tabs'\nexport * from './src/tab-bar'\nexport * from './src/tab-nav'\nexport * from './src/tab-pane'\nexport * from './src/constants'\n"],"mappings":";;;;;;;;;AAMA,MAAa,SAET,YAAY,MAAM,EACpB,2BACD,CAAC;AACF,MAAa,YACX,gBAAgBA,iBAAQ"}
@@ -0,0 +1,28 @@
import { TabPaneProps } from "./tab-pane.js";
import { TabNavInstance } from "./tab-nav.js";
import { TabsProps } from "./tabs.js";
import { ComputedRef, InjectionKey, Ref, Slots, UnwrapRef, VNode } from "vue";
//#region ../../packages/components/tabs/src/constants.d.ts
type TabPaneName = string | number;
type TabsPaneContext = UnwrapRef<{
uid: number;
getVnode: () => VNode;
slots: Slots;
props: TabPaneProps;
paneName: ComputedRef<TabPaneName | undefined>;
active: ComputedRef<boolean>;
index: Ref<string | undefined>;
isClosable: ComputedRef<boolean>;
isFocusInsidePane: () => boolean | undefined;
}>;
interface TabsRootContext {
props: TabsProps;
currentName: Ref<TabPaneName>;
registerPane: (pane: TabsPaneContext) => void;
unregisterPane: (pane: TabsPaneContext) => void;
nav$: Ref<TabNavInstance | undefined>;
}
declare const tabsRootContextKey: InjectionKey<TabsRootContext>;
//#endregion
export { TabPaneName, TabsPaneContext, TabsRootContext, tabsRootContextKey };
@@ -0,0 +1,6 @@
//#region ../../packages/components/tabs/src/constants.ts
const tabsRootContextKey = Symbol("tabsRootContextKey");
//#endregion
export { tabsRootContextKey };
//# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"constants.mjs","names":[],"sources":["../../../../../../packages/components/tabs/src/constants.ts"],"sourcesContent":["import type {\n ComputedRef,\n InjectionKey,\n Ref,\n Slots,\n UnwrapRef,\n VNode,\n} from 'vue'\nimport type { TabsProps } from './tabs'\nimport type { TabPaneProps } from './tab-pane'\nimport type { TabNavInstance } from './tab-nav'\n\nexport type TabPaneName = string | number\n\nexport type TabsPaneContext = UnwrapRef<{\n uid: number\n getVnode: () => VNode\n slots: Slots\n props: TabPaneProps\n paneName: ComputedRef<TabPaneName | undefined>\n active: ComputedRef<boolean>\n index: Ref<string | undefined>\n isClosable: ComputedRef<boolean>\n isFocusInsidePane: () => boolean | undefined\n}>\n\nexport interface TabsRootContext {\n props: TabsProps\n currentName: Ref<TabPaneName>\n registerPane: (pane: TabsPaneContext) => void\n unregisterPane: (pane: TabsPaneContext) => void\n nav$: Ref<TabNavInstance | undefined>\n}\n\nexport const tabsRootContextKey: InjectionKey<TabsRootContext> =\n Symbol('tabsRootContextKey')\n"],"mappings":";AAkCA,MAAa,qBACX,OAAO,qBAAqB"}
+105
View File
@@ -0,0 +1,105 @@
import { EpPropFinalized } from "../../../utils/vue/props/types.js";
import { Mutable } from "../../../utils/typescript.js";
import "../../../utils/index.js";
import { TabPaneName, TabsPaneContext } from "./constants.js";
import { _default } from "./tab-bar.vue.js";
import * as vue from "vue";
import { ExtractPublicPropTypes } from "vue";
//#region ../../packages/components/tabs/src/tab-bar.d.ts
/**
* @deprecated Removed after 3.0.0, Use `TabBarProps` instead.
*/
declare const tabBarProps: {
readonly tabs: EpPropFinalized<(new (...args: any[]) => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (() => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (((new (...args: any[]) => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (() => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[])) | null)[], unknown, unknown, () => [], boolean>;
readonly tabRefs: EpPropFinalized<(new (...args: any[]) => {
[key: string]: HTMLDivElement;
[key: number]: HTMLDivElement;
}) | (() => {
[key: string]: HTMLDivElement;
[key: number]: HTMLDivElement;
}) | (((new (...args: any[]) => {
[key: string]: HTMLDivElement;
[key: number]: HTMLDivElement;
}) | (() => {
[key: string]: HTMLDivElement;
[key: number]: HTMLDivElement;
})) | null)[], unknown, unknown, () => Mutable<{}>, boolean>;
};
type TabBarProps = {
tabs?: TabsPaneContext[];
tabRefs?: {
[key: TabPaneName]: HTMLDivElement;
};
};
/**
* @deprecated Removed after 3.0.0, Use `TabBarProps` instead.
*/
type TabBarPropsPublic = ExtractPublicPropTypes<typeof tabBarProps>;
type TabBarInstance = InstanceType<typeof _default> & unknown;
//#endregion
export { TabBarInstance, TabBarProps, TabBarPropsPublic, tabBarProps };
+21
View File
@@ -0,0 +1,21 @@
import { buildProps, definePropType } from "../../../utils/vue/props/runtime.mjs";
import { mutable } from "../../../utils/typescript.mjs";
//#region ../../packages/components/tabs/src/tab-bar.ts
/**
* @deprecated Removed after 3.0.0, Use `TabBarProps` instead.
*/
const tabBarProps = buildProps({
tabs: {
type: definePropType(Array),
default: () => mutable([])
},
tabRefs: {
type: definePropType(Object),
default: () => mutable({})
}
});
//#endregion
export { tabBarProps };
//# sourceMappingURL=tab-bar.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"tab-bar.mjs","names":[],"sources":["../../../../../../packages/components/tabs/src/tab-bar.ts"],"sourcesContent":["import { buildProps, definePropType, mutable } from '@element-plus/utils'\n\nimport type { ExtractPublicPropTypes } from 'vue'\nimport type { TabPaneName, TabsPaneContext } from './constants'\nimport type TabBar from './tab-bar.vue'\n\n/**\n * @deprecated Removed after 3.0.0, Use `TabBarProps` instead.\n */\nexport const tabBarProps = buildProps({\n tabs: {\n type: definePropType<TabsPaneContext[]>(Array),\n default: () => mutable([] as const),\n },\n tabRefs: {\n type: definePropType<{ [key: TabPaneName]: HTMLDivElement }>(Object),\n default: () => mutable({} as const),\n },\n} as const)\n\nexport type TabBarProps = {\n tabs?: TabsPaneContext[]\n tabRefs?: { [key: TabPaneName]: HTMLDivElement }\n}\n\n/**\n * @deprecated Removed after 3.0.0, Use `TabBarProps` instead.\n */\nexport type TabBarPropsPublic = ExtractPublicPropTypes<typeof tabBarProps>\nexport type TabBarInstance = InstanceType<typeof TabBar> & unknown\n"],"mappings":";;;;;;;AASA,MAAa,cAAc,WAAW;CACpC,MAAM;EACJ,MAAM,eAAkC,MAAM;EAC9C,eAAe,QAAQ,EAAE,CAAU;EACpC;CACD,SAAS;EACP,MAAM,eAAuD,OAAO;EACpE,eAAe,QAAQ,EAAE,CAAU;EACpC;CACF,CAAU"}
@@ -0,0 +1,18 @@
import { TabPaneName, TabsPaneContext } from "./constants.js";
import { TabBarProps } from "./tab-bar.js";
import * as vue from "vue";
import { CSSProperties } from "vue";
//#region ../../packages/components/tabs/src/tab-bar.vue.d.ts
declare const __VLS_export: vue.DefineComponent<TabBarProps, {
/** @description tab root html element */ref: vue.Ref<HTMLDivElement | undefined, HTMLDivElement | undefined>; /** @description method to manually update tab bar style, return the updated style */
update: () => CSSProperties;
}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<TabBarProps> & Readonly<{}>, {
tabs: TabsPaneContext[];
tabRefs: {
[key: TabPaneName]: HTMLDivElement;
};
}, {}, {}, {}, string, vue.ComponentProvideOptions, false, {}, any>;
declare const _default: typeof __VLS_export;
//#endregion
export { _default };
@@ -0,0 +1,93 @@
import { isUndefined } from "../../../utils/types.mjs";
import { capitalize } from "../../../utils/strings.mjs";
import { throwError } from "../../../utils/error.mjs";
import { useNamespace } from "../../../hooks/use-namespace/index.mjs";
import { tabsRootContextKey } from "./constants.mjs";
import { tabBarProps } from "./tab-bar.mjs";
import { useResizeObserver } from "@vueuse/core";
import { computed, createCommentVNode, createElementBlock, defineComponent, inject, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, openBlock, ref, unref, watch } from "vue";
//#region ../../packages/components/tabs/src/tab-bar.vue?vue&type=script&setup=true&lang.ts
const COMPONENT_NAME = "ElTabBar";
var tab_bar_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
name: COMPONENT_NAME,
__name: "tab-bar",
props: tabBarProps,
setup(__props, { expose: __expose }) {
const props = __props;
const rootTabs = inject(tabsRootContextKey);
if (!rootTabs) throwError(COMPONENT_NAME, "<el-tabs><el-tab-bar /></el-tabs>");
const ns = useNamespace("tabs");
const barRef = ref();
const barStyle = ref();
/**
* when defaultValue is not set, the bar is always shown.
*
* when defaultValue is set, the bar will be hidden until style is calculated
* to avoid the bar showing in the wrong position on initial render.
*/
const renderActiveBar = computed(() => isUndefined(rootTabs.props.defaultValue) || Boolean(barStyle.value?.transform));
const getBarStyle = () => {
let offset = 0;
let tabSize = 0;
const sizeName = ["top", "bottom"].includes(rootTabs.props.tabPosition) ? "width" : "height";
const sizeDir = sizeName === "width" ? "x" : "y";
const position = sizeDir === "x" ? "left" : "top";
props.tabs.every((tab) => {
if (isUndefined(tab.paneName)) return false;
const $el = props.tabRefs[tab.paneName];
if (!$el) return false;
if (!tab.active) return true;
offset = $el[`offset${capitalize(position)}`];
tabSize = $el[`client${capitalize(sizeName)}`];
const tabStyles = window.getComputedStyle($el);
if (sizeName === "width") {
tabSize -= Number.parseFloat(tabStyles.paddingLeft) + Number.parseFloat(tabStyles.paddingRight);
offset += Number.parseFloat(tabStyles.paddingLeft);
}
return false;
});
return {
[sizeName]: `${tabSize}px`,
transform: `translate${capitalize(sizeDir)}(${offset}px)`
};
};
const update = () => barStyle.value = getBarStyle();
const tabObservers = [];
const observerTabs = () => {
tabObservers.forEach((observer) => observer.stop());
tabObservers.length = 0;
Object.values(props.tabRefs).forEach((tab) => {
tabObservers.push(useResizeObserver(tab, update));
});
};
watch(() => props.tabs, async () => {
await nextTick();
update();
observerTabs();
}, { immediate: true });
const barObserver = useResizeObserver(barRef, () => update());
onBeforeUnmount(() => {
tabObservers.forEach((observer) => observer.stop());
tabObservers.length = 0;
barObserver.stop();
});
__expose({
ref: barRef,
update
});
return (_ctx, _cache) => {
return renderActiveBar.value ? (openBlock(), createElementBlock("div", {
key: 0,
ref_key: "barRef",
ref: barRef,
class: normalizeClass([unref(ns).e("active-bar"), unref(ns).is(unref(rootTabs).props.tabPosition)]),
style: normalizeStyle(barStyle.value)
}, null, 6)) : createCommentVNode("v-if", true);
};
}
});
//#endregion
export { tab_bar_vue_vue_type_script_setup_true_lang_default as default };
//# sourceMappingURL=tab-bar.vue_vue_type_script_setup_true_lang.mjs.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
import tab_bar_vue_vue_type_script_setup_true_lang_default from "./tab-bar.vue_vue_type_script_setup_true_lang.mjs";
//#region ../../packages/components/tabs/src/tab-bar.vue
var tab_bar_default = tab_bar_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { tab_bar_default as default };
//# sourceMappingURL=tab-bar2.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"tab-bar2.mjs","names":[],"sources":["../../../../../../packages/components/tabs/src/tab-bar.vue"],"sourcesContent":["<template>\n <div\n v-if=\"renderActiveBar\"\n ref=\"barRef\"\n :class=\"[ns.e('active-bar'), ns.is(rootTabs!.props.tabPosition)]\"\n :style=\"barStyle\"\n />\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, inject, nextTick, onBeforeUnmount, ref, watch } from 'vue'\nimport { useResizeObserver } from '@vueuse/core'\nimport { capitalize, isUndefined, throwError } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport { tabsRootContextKey } from './constants'\n\nimport type { TabBarProps } from './tab-bar'\nimport type { CSSProperties } from 'vue'\n\nconst COMPONENT_NAME = 'ElTabBar'\ndefineOptions({\n name: COMPONENT_NAME,\n})\nconst props = withDefaults(defineProps<TabBarProps>(), {\n tabs: () => [],\n tabRefs: () => ({}),\n})\n\nconst rootTabs = inject(tabsRootContextKey)\nif (!rootTabs) throwError(COMPONENT_NAME, '<el-tabs><el-tab-bar /></el-tabs>')\n\nconst ns = useNamespace('tabs')\n\nconst barRef = ref<HTMLDivElement>()\nconst barStyle = ref<CSSProperties>()\n/**\n * when defaultValue is not set, the bar is always shown.\n *\n * when defaultValue is set, the bar will be hidden until style is calculated\n * to avoid the bar showing in the wrong position on initial render.\n */\nconst renderActiveBar = computed(\n () =>\n isUndefined(rootTabs.props.defaultValue) ||\n Boolean(barStyle.value?.transform)\n)\n\nconst getBarStyle = (): CSSProperties => {\n let offset = 0\n let tabSize = 0\n\n const sizeName = ['top', 'bottom'].includes(rootTabs.props.tabPosition)\n ? 'width'\n : 'height'\n const sizeDir = sizeName === 'width' ? 'x' : 'y'\n const position = sizeDir === 'x' ? 'left' : 'top'\n\n props.tabs.every((tab) => {\n if (isUndefined(tab.paneName)) return false\n const $el = props.tabRefs[tab.paneName]\n if (!$el) return false\n\n if (!tab.active) {\n return true\n }\n\n offset = $el[`offset${capitalize(position)}`]\n tabSize = $el[`client${capitalize(sizeName)}`]\n\n const tabStyles = window.getComputedStyle($el)\n\n if (sizeName === 'width') {\n tabSize -=\n Number.parseFloat(tabStyles.paddingLeft) +\n Number.parseFloat(tabStyles.paddingRight)\n offset += Number.parseFloat(tabStyles.paddingLeft)\n }\n return false\n })\n\n return {\n [sizeName]: `${tabSize}px`,\n transform: `translate${capitalize(sizeDir)}(${offset}px)`,\n }\n}\n\nconst update = () => (barStyle.value = getBarStyle())\n\nconst tabObservers = [] as ReturnType<typeof useResizeObserver>[]\nconst observerTabs = () => {\n tabObservers.forEach((observer) => observer.stop())\n tabObservers.length = 0\n\n Object.values(props.tabRefs).forEach((tab) => {\n tabObservers.push(useResizeObserver(tab, update))\n })\n}\n\nwatch(\n () => props.tabs,\n async () => {\n await nextTick()\n update()\n\n observerTabs()\n },\n { immediate: true }\n)\nconst barObserver = useResizeObserver(barRef, () => update())\n\nonBeforeUnmount(() => {\n tabObservers.forEach((observer) => observer.stop())\n tabObservers.length = 0\n barObserver.stop()\n})\n\ndefineExpose({\n /** @description tab root html element */\n ref: barRef,\n /** @description method to manually update tab bar style, return the updated style */\n update,\n})\n</script>\n"],"mappings":""}
+302
View File
@@ -0,0 +1,302 @@
import { EpPropFinalized, EpPropMergeType } from "../../../utils/vue/props/types.js";
import "../../../utils/index.js";
import { TabPaneName, TabsPaneContext } from "./constants.js";
import { TabBarInstance } from "./tab-bar.js";
import * as vue from "vue";
import { ExtractPropTypes, ExtractPublicPropTypes } from "vue";
import * as vue_jsx_runtime0 from "vue/jsx-runtime";
//#region ../../packages/components/tabs/src/tab-nav.d.ts
declare const tabNavProps: {
readonly panes: EpPropFinalized<(new (...args: any[]) => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (() => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (((new (...args: any[]) => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (() => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[])) | null)[], unknown, unknown, () => [], boolean>;
readonly currentName: EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, "", boolean>;
readonly editable: BooleanConstructor;
readonly type: EpPropFinalized<StringConstructor, "" | "card" | "border-card", unknown, "", boolean>;
readonly stretch: BooleanConstructor;
readonly tabindex: EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, undefined, boolean>;
};
declare const tabNavEmits: {
tabClick: (tab: TabsPaneContext, tabName: TabPaneName, ev: Event) => boolean;
tabRemove: (tab: TabsPaneContext, ev: Event) => boolean;
};
type TabNavProps = ExtractPropTypes<typeof tabNavProps>;
type TabNavPropsPublic = ExtractPublicPropTypes<typeof tabNavProps>;
type TabNavEmits = typeof tabNavEmits;
declare const TabNav: vue.DefineComponent<ExtractPropTypes<{
readonly panes: EpPropFinalized<(new (...args: any[]) => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (() => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (((new (...args: any[]) => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (() => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[])) | null)[], unknown, unknown, () => [], boolean>;
readonly currentName: EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, "", boolean>;
readonly editable: BooleanConstructor;
readonly type: EpPropFinalized<StringConstructor, "" | "card" | "border-card", unknown, "", boolean>;
readonly stretch: BooleanConstructor;
readonly tabindex: EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, undefined, boolean>;
}>, () => vue_jsx_runtime0.JSX.Element, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
tabClick: (tab: TabsPaneContext, tabName: TabPaneName, ev: Event) => boolean;
tabRemove: (tab: TabsPaneContext, ev: Event) => boolean;
}, string, vue.PublicProps, Readonly<ExtractPropTypes<{
readonly panes: EpPropFinalized<(new (...args: any[]) => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (() => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (((new (...args: any[]) => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[]) | (() => {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[])) | null)[], unknown, unknown, () => [], boolean>;
readonly currentName: EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, "", boolean>;
readonly editable: BooleanConstructor;
readonly type: EpPropFinalized<StringConstructor, "" | "card" | "border-card", unknown, "", boolean>;
readonly stretch: BooleanConstructor;
readonly tabindex: EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, undefined, boolean>;
}>> & Readonly<{
onTabClick?: ((tab: {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}, tabName: TabPaneName, ev: Event) => any) | undefined;
onTabRemove?: ((tab: {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}, ev: Event) => any) | undefined;
}>, {
readonly type: EpPropMergeType<StringConstructor, "" | "card" | "border-card", unknown>;
readonly tabindex: EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>;
readonly stretch: boolean;
readonly editable: boolean;
readonly panes: {
uid: number;
getVnode: () => vue.VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}[];
readonly currentName: EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>;
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
type TabNavInstance = InstanceType<typeof TabNav> & {
scrollToActiveTab: () => Promise<void>;
removeFocus: () => void;
focusActiveTab: () => void;
scheduleRender: () => void;
tabListRef: HTMLDivElement | undefined;
tabBarRef: TabBarInstance | undefined;
};
//#endregion
export { TabNavEmits, TabNavInstance, TabNavProps, TabNavPropsPublic, tabNavEmits, tabNavProps };
+291
View File
@@ -0,0 +1,291 @@
import { EVENT_CODE } from "../../../constants/aria.mjs";
import { getEventCode } from "../../../utils/dom/event.mjs";
import { rAF } from "../../../utils/raf.mjs";
import { throwError } from "../../../utils/error.mjs";
import { buildProps, definePropType } from "../../../utils/vue/props/runtime.mjs";
import { mutable } from "../../../utils/typescript.mjs";
import { isGreaterThan } from "../../../utils/numbers.mjs";
import { useNamespace } from "../../../hooks/use-namespace/index.mjs";
import { ElIcon } from "../../icon/index.mjs";
import useWheel from "../../virtual-list/src/hooks/use-wheel.mjs";
import { tabsRootContextKey } from "./constants.mjs";
import tab_bar_default from "./tab-bar2.mjs";
import { useDocumentVisibility, useElementSize, useResizeObserver, useWindowFocus } from "@vueuse/core";
import { clamp as clamp$1 } from "lodash-unified";
import { ArrowLeft, ArrowRight, Close } from "@element-plus/icons-vue";
import { computed, createVNode, defineComponent, inject, nextTick, onMounted, onUpdated, ref, shallowRef, triggerRef, watch } from "vue";
//#region ../../packages/components/tabs/src/tab-nav.tsx
const tabNavProps = buildProps({
panes: {
type: definePropType(Array),
default: () => mutable([])
},
currentName: {
type: [String, Number],
default: ""
},
editable: Boolean,
type: {
type: String,
values: [
"card",
"border-card",
""
],
default: ""
},
stretch: Boolean,
tabindex: {
type: [String, Number],
default: void 0
}
});
const tabNavEmits = {
tabClick: (tab, tabName, ev) => ev instanceof Event,
tabRemove: (tab, ev) => ev instanceof Event
};
const COMPONENT_NAME = "ElTabNav";
const TabNav = /* @__PURE__ */ defineComponent({
name: COMPONENT_NAME,
props: tabNavProps,
emits: tabNavEmits,
setup(props, { expose, emit }) {
const rootTabs = inject(tabsRootContextKey);
if (!rootTabs) throwError(COMPONENT_NAME, `<el-tabs><tab-nav /></el-tabs>`);
const ns = useNamespace("tabs");
const visibility = useDocumentVisibility();
const focused = useWindowFocus();
const navScroll$ = ref();
const nav$ = ref();
const el$ = ref();
const tabRefsMap = ref({});
const tabBarRef = ref();
const scrollable = ref(false);
const navOffset = ref(0);
const isFocus = ref(false);
const focusable = ref(true);
const isWheelScrolling = ref(false);
const tracker = shallowRef();
const isHorizontal = computed(() => ["top", "bottom"].includes(rootTabs.props.tabPosition));
const sizeName = computed(() => isHorizontal.value ? "width" : "height");
const navStyle = computed(() => {
const dir = sizeName.value === "width" ? "X" : "Y";
return {
transition: isWheelScrolling.value ? "none" : void 0,
transform: `translate${dir}(-${navOffset.value}px)`
};
});
const { width: navContainerWidth, height: navContainerHeight } = useElementSize(navScroll$);
const { width: navWidth, height: navHeight } = useElementSize(nav$, {
width: 0,
height: 0
}, { box: "border-box" });
const navContainerSize = computed(() => isHorizontal.value ? navContainerWidth.value : navContainerHeight.value);
const navSize = computed(() => isHorizontal.value ? navWidth.value : navHeight.value);
const { onWheel } = useWheel({
atStartEdge: computed(() => navOffset.value <= 0),
atEndEdge: computed(() => navSize.value - navOffset.value <= navContainerSize.value),
layout: computed(() => isHorizontal.value ? "horizontal" : "vertical")
}, (offset) => {
navOffset.value = clamp$1(navOffset.value + offset, 0, navSize.value - navContainerSize.value);
});
const handleWheel = (event) => {
isWheelScrolling.value = true;
onWheel(event);
rAF(() => {
isWheelScrolling.value = false;
});
};
const scrollPrev = () => {
if (!navScroll$.value) return;
const containerSize = navScroll$.value.getBoundingClientRect()[sizeName.value];
const currentOffset = navOffset.value;
if (!currentOffset) return;
navOffset.value = currentOffset > containerSize ? currentOffset - containerSize : 0;
};
const scrollNext = () => {
if (!navScroll$.value || !nav$.value) return;
const navSize = nav$.value.getBoundingClientRect()[sizeName.value];
const containerSize = navScroll$.value.getBoundingClientRect()[sizeName.value];
const currentOffset = navOffset.value;
if (!isGreaterThan(navSize - currentOffset, containerSize)) return;
navOffset.value = navSize - currentOffset > containerSize * 2 ? currentOffset + containerSize : navSize - containerSize;
};
const scrollToActiveTab = async () => {
const nav = nav$.value;
if (!scrollable.value || !el$.value || !navScroll$.value || !nav) return;
await nextTick();
const activeTab = tabRefsMap.value[props.currentName];
if (!activeTab) return;
const navScroll = navScroll$.value;
const activeTabBounding = activeTab.getBoundingClientRect();
const navScrollBounding = navScroll.getBoundingClientRect();
const navScrollLeft = navScrollBounding.left + 1;
const navScrollRight = navScrollBounding.right - 1;
const navBounding = nav.getBoundingClientRect();
const maxOffset = isHorizontal.value ? navBounding.width - navScrollBounding.width : navBounding.height - navScrollBounding.height;
const currentOffset = navOffset.value;
let newOffset = currentOffset;
if (isHorizontal.value) {
if (activeTabBounding.left < navScrollLeft) newOffset = currentOffset - (navScrollLeft - activeTabBounding.left);
if (activeTabBounding.right > navScrollRight) newOffset = currentOffset + activeTabBounding.right - navScrollRight;
} else {
if (activeTabBounding.top < navScrollBounding.top) newOffset = currentOffset - (navScrollBounding.top - activeTabBounding.top);
if (activeTabBounding.bottom > navScrollBounding.bottom) newOffset = currentOffset + (activeTabBounding.bottom - navScrollBounding.bottom);
}
newOffset = Math.max(newOffset, 0);
navOffset.value = Math.min(newOffset, maxOffset);
};
const update = () => {
if (!nav$.value || !navScroll$.value) return;
props.stretch && tabBarRef.value?.update();
const navSize = nav$.value.getBoundingClientRect()[sizeName.value];
const containerSize = navScroll$.value.getBoundingClientRect()[sizeName.value];
const currentOffset = navOffset.value;
if (containerSize < navSize) {
scrollable.value = scrollable.value || {};
scrollable.value.prev = currentOffset;
scrollable.value.next = isGreaterThan(navSize, currentOffset + containerSize);
if (isGreaterThan(containerSize, navSize - currentOffset)) navOffset.value = navSize - containerSize;
} else {
scrollable.value = false;
if (currentOffset > 0) navOffset.value = 0;
}
};
const changeTab = (event) => {
const code = getEventCode(event);
let step = 0;
switch (code) {
case EVENT_CODE.left:
case EVENT_CODE.up:
step = -1;
break;
case EVENT_CODE.right:
case EVENT_CODE.down:
step = 1;
break;
default: return;
}
const tabList = Array.from(event.currentTarget.querySelectorAll("[role=tab]:not(.is-disabled)"));
let nextIndex = tabList.indexOf(event.target) + step;
if (nextIndex < 0) nextIndex = tabList.length - 1;
else if (nextIndex >= tabList.length) nextIndex = 0;
tabList[nextIndex].focus({ preventScroll: true });
tabList[nextIndex].click();
setFocus();
};
const setFocus = () => {
if (focusable.value) isFocus.value = true;
};
const removeFocus = () => isFocus.value = false;
const setRefs = (el, key) => {
tabRefsMap.value[key] = el;
};
const focusActiveTab = async () => {
await nextTick();
tabRefsMap.value[props.currentName]?.focus({ preventScroll: true });
};
watch(visibility, (visibility) => {
if (visibility === "hidden") focusable.value = false;
else if (visibility === "visible") setTimeout(() => focusable.value = true, 50);
});
watch(focused, (focused) => {
if (focused) setTimeout(() => focusable.value = true, 50);
else focusable.value = false;
});
useResizeObserver(el$, () => {
rAF(update);
});
onMounted(() => setTimeout(() => scrollToActiveTab(), 0));
onUpdated(() => update());
expose({
scrollToActiveTab,
removeFocus,
focusActiveTab,
tabListRef: nav$,
tabBarRef,
scheduleRender: () => triggerRef(tracker)
});
return () => {
const scrollBtn = scrollable.value ? [createVNode("span", {
"class": [ns.e("nav-prev"), ns.is("disabled", !scrollable.value.prev)],
"onClick": scrollPrev
}, [createVNode(ElIcon, null, { default: () => [createVNode(ArrowLeft, null, null)] })]), createVNode("span", {
"class": [ns.e("nav-next"), ns.is("disabled", !scrollable.value.next)],
"onClick": scrollNext
}, [createVNode(ElIcon, null, { default: () => [createVNode(ArrowRight, null, null)] })])] : null;
const tabs = props.panes.map((pane, index) => {
const uid = pane.uid;
const disabled = pane.props.disabled;
const tabName = pane.props.name ?? pane.index ?? `${index}`;
const closable = !disabled && (pane.isClosable || pane.props.closable !== false && props.editable);
pane.index = `${index}`;
const btnClose = closable ? createVNode(ElIcon, {
"class": "is-icon-close",
"onClick": (ev) => emit("tabRemove", pane, ev)
}, { default: () => [createVNode(Close, null, null)] }) : null;
const tabLabelContent = pane.slots.label?.() || pane.props.label;
const tabindex = !disabled && pane.active ? props.tabindex ?? rootTabs.props.tabindex : -1;
return createVNode("div", {
"ref": (el) => setRefs(el, tabName),
"class": [
ns.e("item"),
ns.is(rootTabs.props.tabPosition),
ns.is("active", pane.active),
ns.is("disabled", disabled),
ns.is("closable", closable),
ns.is("focus", isFocus.value)
],
"id": `tab-${tabName}`,
"key": `tab-${uid}`,
"aria-controls": `pane-${tabName}`,
"role": "tab",
"aria-selected": pane.active,
"tabindex": tabindex,
"onFocus": () => setFocus(),
"onBlur": () => removeFocus(),
"onClick": (ev) => {
removeFocus();
emit("tabClick", pane, tabName, ev);
},
"onKeydown": (ev) => {
const code = getEventCode(ev);
if (closable && (code === EVENT_CODE.delete || code === EVENT_CODE.backspace)) emit("tabRemove", pane, ev);
}
}, [...[tabLabelContent, btnClose]]);
});
tracker.value;
return createVNode("div", {
"ref": el$,
"class": [
ns.e("nav-wrap"),
ns.is("scrollable", !!scrollable.value),
ns.is(rootTabs.props.tabPosition)
]
}, [scrollBtn, createVNode("div", {
"class": ns.e("nav-scroll"),
"ref": navScroll$
}, [props.panes.length > 0 ? createVNode("div", {
"class": [
ns.e("nav"),
ns.is(rootTabs.props.tabPosition),
ns.is("stretch", props.stretch && ["top", "bottom"].includes(rootTabs.props.tabPosition))
],
"ref": nav$,
"style": navStyle.value,
"role": "tablist",
"onKeydown": changeTab,
"onWheel": handleWheel
}, [...[!props.type ? createVNode(tab_bar_default, {
"ref": tabBarRef,
"tabs": [...props.panes],
"tabRefs": tabRefsMap.value
}, null) : null, tabs]]) : null])]);
};
}
});
//#endregion
export { TabNav as default, tabNavEmits, tabNavProps };
//# sourceMappingURL=tab-nav.mjs.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,51 @@
import { EpPropFinalized, EpPropMergeType } from "../../../utils/vue/props/types.js";
import "../../../utils/index.js";
import { _default } from "./tab-pane.vue.js";
import * as vue from "vue";
import { ExtractPublicPropTypes } from "vue";
//#region ../../packages/components/tabs/src/tab-pane.d.ts
/**
* @deprecated Removed after 3.0.0, Use `TabPaneProps` instead.
*/
declare const tabPaneProps: {
readonly label: EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
readonly name: {
readonly type: vue.PropType<EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly closable: EpPropFinalized<BooleanConstructor, unknown, unknown, undefined, boolean>;
readonly disabled: BooleanConstructor;
readonly lazy: BooleanConstructor;
};
type TabPaneProps = {
/**
* @description title of the tab
*/
label?: string;
/**
* @description identifier corresponding to the name of Tabs, representing the alias of the tab-pane, the default is ordinal number of the tab-pane in the sequence, e.g. the first tab-pane is '0'
*/
name?: string | number;
/**
* @description whether Tab is closable
*/
closable?: boolean;
/**
* @description whether Tab is disabled
*/
disabled?: boolean;
/**
* @description whether Tab is lazily rendered
*/
lazy?: boolean;
};
/**
* @deprecated Removed after 3.0.0, Use `TabPaneProps` instead.
*/
type TabPanePropsPublic = ExtractPublicPropTypes<typeof tabPaneProps>;
type TabPaneInstance = InstanceType<typeof _default> & unknown;
//#endregion
export { TabPaneInstance, TabPaneProps, TabPanePropsPublic, tabPaneProps };
+23
View File
@@ -0,0 +1,23 @@
import { buildProps } from "../../../utils/vue/props/runtime.mjs";
//#region ../../packages/components/tabs/src/tab-pane.ts
/**
* @deprecated Removed after 3.0.0, Use `TabPaneProps` instead.
*/
const tabPaneProps = buildProps({
label: {
type: String,
default: ""
},
name: { type: [String, Number] },
closable: {
type: Boolean,
default: void 0
},
disabled: Boolean,
lazy: Boolean
});
//#endregion
export { tabPaneProps };
//# sourceMappingURL=tab-pane.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"tab-pane.mjs","names":[],"sources":["../../../../../../packages/components/tabs/src/tab-pane.ts"],"sourcesContent":["import { buildProps } from '@element-plus/utils'\n\nimport type { ExtractPublicPropTypes } from 'vue'\nimport type TabPane from './tab-pane.vue'\n\n/**\n * @deprecated Removed after 3.0.0, Use `TabPaneProps` instead.\n */\nexport const tabPaneProps = buildProps({\n /**\n * @description title of the tab\n */\n label: {\n type: String,\n default: '',\n },\n /**\n * @description identifier corresponding to the name of Tabs, representing the alias of the tab-pane, the default is ordinal number of the tab-pane in the sequence, e.g. the first tab-pane is '0'\n */\n name: {\n type: [String, Number],\n },\n /**\n * @description whether Tab is closable\n */\n closable: {\n type: Boolean,\n default: undefined,\n },\n /**\n * @description whether Tab is disabled\n */\n disabled: Boolean,\n /**\n * @description whether Tab is lazily rendered\n */\n lazy: Boolean,\n} as const)\n\nexport type TabPaneProps = {\n /**\n * @description title of the tab\n */\n label?: string\n /**\n * @description identifier corresponding to the name of Tabs, representing the alias of the tab-pane, the default is ordinal number of the tab-pane in the sequence, e.g. the first tab-pane is '0'\n */\n name?: string | number\n /**\n * @description whether Tab is closable\n */\n closable?: boolean\n /**\n * @description whether Tab is disabled\n */\n disabled?: boolean\n /**\n * @description whether Tab is lazily rendered\n */\n lazy?: boolean\n}\n\n/**\n * @deprecated Removed after 3.0.0, Use `TabPaneProps` instead.\n */\nexport type TabPanePropsPublic = ExtractPublicPropTypes<typeof tabPaneProps>\n\nexport type TabPaneInstance = InstanceType<typeof TabPane> & unknown\n"],"mappings":";;;;;;AAQA,MAAa,eAAe,WAAW;CAIrC,OAAO;EACL,MAAM;EACN,SAAS;EACV;CAID,MAAM,EACJ,MAAM,CAAC,QAAQ,OAAO,EACvB;CAID,UAAU;EACR,MAAM;EACN,SAAS;EACV;CAID,UAAU;CAIV,MAAM;CACP,CAAU"}
@@ -0,0 +1,21 @@
import { TabPaneProps } from "./tab-pane.js";
import * as vue from "vue";
//#region ../../packages/components/tabs/src/tab-pane.vue.d.ts
declare var __VLS_1: {};
type __VLS_Slots = {} & {
default?: (props: typeof __VLS_1) => any;
};
declare const __VLS_base: vue.DefineComponent<TabPaneProps, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<TabPaneProps> & Readonly<{}>, {
closable: boolean;
label: string;
}, {}, {}, {}, string, vue.ComponentProvideOptions, false, {}, any>;
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
declare const _default: typeof __VLS_export;
type __VLS_WithSlots<T, S> = T & {
new (): {
$slots: S;
};
};
//#endregion
export { _default };
@@ -0,0 +1,73 @@
import { throwError } from "../../../utils/error.mjs";
import { useNamespace } from "../../../hooks/use-namespace/index.mjs";
import { tabsRootContextKey } from "./constants.mjs";
import { tabPaneProps } from "./tab-pane.mjs";
import { computed, createCommentVNode, createElementBlock, defineComponent, getCurrentInstance, inject, normalizeClass, onBeforeUnmount, onBeforeUpdate, openBlock, reactive, ref, renderSlot, unref, useSlots, vShow, watch, withDirectives } from "vue";
//#region ../../packages/components/tabs/src/tab-pane.vue?vue&type=script&setup=true&lang.ts
const _hoisted_1 = [
"id",
"aria-hidden",
"aria-labelledby"
];
const COMPONENT_NAME = "ElTabPane";
var tab_pane_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
name: COMPONENT_NAME,
__name: "tab-pane",
props: tabPaneProps,
setup(__props) {
const props = __props;
const instance = getCurrentInstance();
const slots = useSlots();
const tabsRoot = inject(tabsRootContextKey);
if (!tabsRoot) throwError(COMPONENT_NAME, "usage: <el-tabs><el-tab-pane /></el-tabs/>");
const ns = useNamespace("tab-pane");
const paneRef = ref();
const index = ref();
const isClosable = computed(() => props.closable ?? tabsRoot.props.closable);
const active = computed(() => tabsRoot.currentName.value === (props.name ?? index.value));
const loaded = ref(active.value);
const paneName = computed(() => props.name ?? index.value);
const shouldBeRender = computed(() => !props.lazy || loaded.value || active.value);
const isFocusInsidePane = () => {
return paneRef.value?.contains(document.activeElement);
};
watch(active, (val) => {
if (val) loaded.value = true;
});
const pane = reactive({
uid: instance.uid,
getVnode: () => instance.vnode,
slots,
props,
paneName,
active,
index,
isClosable,
isFocusInsidePane
});
tabsRoot.registerPane(pane);
onBeforeUnmount(() => {
tabsRoot.unregisterPane(pane);
});
onBeforeUpdate(() => {
if (slots.label) tabsRoot.nav$.value?.scheduleRender();
});
return (_ctx, _cache) => {
return shouldBeRender.value ? withDirectives((openBlock(), createElementBlock("div", {
key: 0,
id: `pane-${paneName.value}`,
ref_key: "paneRef",
ref: paneRef,
class: normalizeClass(unref(ns).b()),
role: "tabpanel",
"aria-hidden": !active.value,
"aria-labelledby": `tab-${paneName.value}`
}, [renderSlot(_ctx.$slots, "default")], 10, _hoisted_1)), [[vShow, active.value]]) : createCommentVNode("v-if", true);
};
}
});
//#endregion
export { tab_pane_vue_vue_type_script_setup_true_lang_default as default };
//# sourceMappingURL=tab-pane.vue_vue_type_script_setup_true_lang.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"tab-pane.vue_vue_type_script_setup_true_lang.mjs","names":[],"sources":["../../../../../../packages/components/tabs/src/tab-pane.vue"],"sourcesContent":["<template>\n <div\n v-if=\"shouldBeRender\"\n v-show=\"active\"\n :id=\"`pane-${paneName}`\"\n ref=\"paneRef\"\n :class=\"ns.b()\"\n role=\"tabpanel\"\n :aria-hidden=\"!active\"\n :aria-labelledby=\"`tab-${paneName}`\"\n >\n <slot />\n </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport {\n computed,\n getCurrentInstance,\n inject,\n onBeforeUnmount,\n onBeforeUpdate,\n reactive,\n ref,\n useSlots,\n watch,\n} from 'vue'\nimport { throwError } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport { tabsRootContextKey } from './constants'\n\nimport type { TabPaneProps } from './tab-pane'\n\nconst COMPONENT_NAME = 'ElTabPane'\ndefineOptions({\n name: COMPONENT_NAME,\n})\nconst props = withDefaults(defineProps<TabPaneProps>(), {\n label: '',\n closable: undefined,\n})\n\nconst instance = getCurrentInstance()!\nconst slots = useSlots()\n\nconst tabsRoot = inject(tabsRootContextKey)\nif (!tabsRoot)\n throwError(COMPONENT_NAME, 'usage: <el-tabs><el-tab-pane /></el-tabs/>')\n\nconst ns = useNamespace('tab-pane')\n\nconst paneRef = ref<HTMLDivElement>()\nconst index = ref<string>()\nconst isClosable = computed(() => props.closable ?? tabsRoot.props.closable)\nconst active = computed(\n () => tabsRoot.currentName.value === (props.name ?? index.value)\n)\nconst loaded = ref(active.value)\nconst paneName = computed(() => props.name ?? index.value)\nconst shouldBeRender = computed(\n () => !props.lazy || loaded.value || active.value\n)\n\nconst isFocusInsidePane = () => {\n return paneRef.value?.contains(document.activeElement)\n}\n\nwatch(active, (val) => {\n if (val) loaded.value = true\n})\n\nconst pane = reactive({\n uid: instance.uid,\n getVnode: () => instance.vnode,\n slots,\n props,\n paneName,\n active,\n index,\n isClosable,\n isFocusInsidePane,\n})\n\ntabsRoot.registerPane(pane)\n\nonBeforeUnmount(() => {\n tabsRoot.unregisterPane(pane)\n})\n\nonBeforeUpdate(() => {\n if (slots.label) tabsRoot.nav$.value?.scheduleRender()\n})\n</script>\n"],"mappings":";;;;;;;;;;;;AAiCA,MAAM,iBAAiB;;;;;;EAIvB,MAAM,QAAQ;EAKd,MAAM,WAAW,oBAAoB;EACrC,MAAM,QAAQ,UAAS;EAEvB,MAAM,WAAW,OAAO,mBAAkB;AAC1C,MAAI,CAAC,SACH,YAAW,gBAAgB,6CAA4C;EAEzE,MAAM,KAAK,aAAa,WAAU;EAElC,MAAM,UAAU,KAAoB;EACpC,MAAM,QAAQ,KAAY;EAC1B,MAAM,aAAa,eAAe,MAAM,YAAY,SAAS,MAAM,SAAQ;EAC3E,MAAM,SAAS,eACP,SAAS,YAAY,WAAW,MAAM,QAAQ,MAAM,OAC5D;EACA,MAAM,SAAS,IAAI,OAAO,MAAK;EAC/B,MAAM,WAAW,eAAe,MAAM,QAAQ,MAAM,MAAK;EACzD,MAAM,iBAAiB,eACf,CAAC,MAAM,QAAQ,OAAO,SAAS,OAAO,MAC9C;EAEA,MAAM,0BAA0B;AAC9B,UAAO,QAAQ,OAAO,SAAS,SAAS,cAAa;;AAGvD,QAAM,SAAS,QAAQ;AACrB,OAAI,IAAK,QAAO,QAAQ;IACzB;EAED,MAAM,OAAO,SAAS;GACpB,KAAK,SAAS;GACd,gBAAgB,SAAS;GACzB;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAAA;AAED,WAAS,aAAa,KAAI;AAE1B,wBAAsB;AACpB,YAAS,eAAe,KAAI;IAC7B;AAED,uBAAqB;AACnB,OAAI,MAAM,MAAO,UAAS,KAAK,OAAO,gBAAe;IACtD;;UAzFS,eAAA,qCADR,mBAWM,OAAA;;IARH,IAAE,QAAU,SAAA;aACT;IAAJ,KAAI;IACH,OAAK,eAAE,MAAA,GAAE,CAAC,GAAC,CAAA;IACZ,MAAK;IACJ,eAAW,CAAG,OAAA;IACd,mBAAe,OAAS,SAAA;OAEzB,WAAQ,KAAA,QAAA,UAAA,8BARA,OAAA,MAAM"}
@@ -0,0 +1,8 @@
import tab_pane_vue_vue_type_script_setup_true_lang_default from "./tab-pane.vue_vue_type_script_setup_true_lang.mjs";
//#region ../../packages/components/tabs/src/tab-pane.vue
var tab_pane_default = tab_pane_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { tab_pane_default as default };
//# sourceMappingURL=tab-pane2.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"tab-pane2.mjs","names":[],"sources":["../../../../../../packages/components/tabs/src/tab-pane.vue"],"sourcesContent":["<template>\n <div\n v-if=\"shouldBeRender\"\n v-show=\"active\"\n :id=\"`pane-${paneName}`\"\n ref=\"paneRef\"\n :class=\"ns.b()\"\n role=\"tabpanel\"\n :aria-hidden=\"!active\"\n :aria-labelledby=\"`tab-${paneName}`\"\n >\n <slot />\n </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport {\n computed,\n getCurrentInstance,\n inject,\n onBeforeUnmount,\n onBeforeUpdate,\n reactive,\n ref,\n useSlots,\n watch,\n} from 'vue'\nimport { throwError } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport { tabsRootContextKey } from './constants'\n\nimport type { TabPaneProps } from './tab-pane'\n\nconst COMPONENT_NAME = 'ElTabPane'\ndefineOptions({\n name: COMPONENT_NAME,\n})\nconst props = withDefaults(defineProps<TabPaneProps>(), {\n label: '',\n closable: undefined,\n})\n\nconst instance = getCurrentInstance()!\nconst slots = useSlots()\n\nconst tabsRoot = inject(tabsRootContextKey)\nif (!tabsRoot)\n throwError(COMPONENT_NAME, 'usage: <el-tabs><el-tab-pane /></el-tabs/>')\n\nconst ns = useNamespace('tab-pane')\n\nconst paneRef = ref<HTMLDivElement>()\nconst index = ref<string>()\nconst isClosable = computed(() => props.closable ?? tabsRoot.props.closable)\nconst active = computed(\n () => tabsRoot.currentName.value === (props.name ?? index.value)\n)\nconst loaded = ref(active.value)\nconst paneName = computed(() => props.name ?? index.value)\nconst shouldBeRender = computed(\n () => !props.lazy || loaded.value || active.value\n)\n\nconst isFocusInsidePane = () => {\n return paneRef.value?.contains(document.activeElement)\n}\n\nwatch(active, (val) => {\n if (val) loaded.value = true\n})\n\nconst pane = reactive({\n uid: instance.uid,\n getVnode: () => instance.vnode,\n slots,\n props,\n paneName,\n active,\n index,\n isClosable,\n isFocusInsidePane,\n})\n\ntabsRoot.registerPane(pane)\n\nonBeforeUnmount(() => {\n tabsRoot.unregisterPane(pane)\n})\n\nonBeforeUpdate(() => {\n if (slots.label) tabsRoot.nav$.value?.scheduleRender()\n})\n</script>\n"],"mappings":""}
+156
View File
@@ -0,0 +1,156 @@
import { EpPropFinalized, EpPropMergeType } from "../../../utils/vue/props/types.js";
import { Awaitable } from "../../../utils/typescript.js";
import "../../../utils/index.js";
import { TabPaneName, TabsPaneContext } from "./constants.js";
import { TabNavInstance } from "./tab-nav.js";
import * as vue from "vue";
import { ExtractPropTypes, ExtractPublicPropTypes, VNode } from "vue";
import * as vue_jsx_runtime0 from "vue/jsx-runtime";
//#region ../../packages/components/tabs/src/tabs.d.ts
declare const tabsProps: {
readonly type: EpPropFinalized<StringConstructor, "" | "card" | "border-card", unknown, "", boolean>;
readonly closable: BooleanConstructor;
readonly addable: BooleanConstructor;
readonly modelValue: {
readonly type: vue.PropType<EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly defaultValue: {
readonly type: vue.PropType<EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly editable: BooleanConstructor;
readonly tabPosition: EpPropFinalized<StringConstructor, "top" | "bottom" | "left" | "right", unknown, "top", boolean>;
readonly beforeLeave: EpPropFinalized<(new (...args: any[]) => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | (() => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | {
(): (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>;
new (): any;
readonly prototype: any;
} | (((new (...args: any[]) => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | (() => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | {
(): (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>;
new (): any;
readonly prototype: any;
}) | null)[], unknown, unknown, () => true, boolean>;
readonly stretch: BooleanConstructor;
readonly tabindex: EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, 0, boolean>;
};
type TabsProps = ExtractPropTypes<typeof tabsProps>;
type TabsPropsPublic = ExtractPublicPropTypes<typeof tabsProps>;
declare const tabsEmits: {
"update:modelValue": (name: TabPaneName) => name is string | number;
tabClick: (pane: TabsPaneContext, ev: Event) => boolean;
tabChange: (name: TabPaneName) => name is string | number;
edit: (paneName: TabPaneName | undefined, action: "remove" | "add") => boolean;
tabRemove: (name: TabPaneName) => name is string | number;
tabAdd: () => boolean;
};
type TabsEmits = typeof tabsEmits;
type TabsPanes = Record<number, TabsPaneContext>;
declare const Tabs: vue.DefineComponent<ExtractPropTypes<{
readonly type: EpPropFinalized<StringConstructor, "" | "card" | "border-card", unknown, "", boolean>;
readonly closable: BooleanConstructor;
readonly addable: BooleanConstructor;
readonly modelValue: {
readonly type: vue.PropType<EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly defaultValue: {
readonly type: vue.PropType<EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly editable: BooleanConstructor;
readonly tabPosition: EpPropFinalized<StringConstructor, "top" | "bottom" | "left" | "right", unknown, "top", boolean>;
readonly beforeLeave: EpPropFinalized<(new (...args: any[]) => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | (() => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | {
(): (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>;
new (): any;
readonly prototype: any;
} | (((new (...args: any[]) => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | (() => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | {
(): (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>;
new (): any;
readonly prototype: any;
}) | null)[], unknown, unknown, () => true, boolean>;
readonly stretch: BooleanConstructor;
readonly tabindex: EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, 0, boolean>;
}>, () => vue_jsx_runtime0.JSX.Element, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
"update:modelValue": (name: TabPaneName) => name is string | number;
tabClick: (pane: TabsPaneContext, ev: Event) => boolean;
tabChange: (name: TabPaneName) => name is string | number;
edit: (paneName: TabPaneName | undefined, action: "remove" | "add") => boolean;
tabRemove: (name: TabPaneName) => name is string | number;
tabAdd: () => boolean;
}, string, vue.PublicProps, Readonly<ExtractPropTypes<{
readonly type: EpPropFinalized<StringConstructor, "" | "card" | "border-card", unknown, "", boolean>;
readonly closable: BooleanConstructor;
readonly addable: BooleanConstructor;
readonly modelValue: {
readonly type: vue.PropType<EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly defaultValue: {
readonly type: vue.PropType<EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly editable: BooleanConstructor;
readonly tabPosition: EpPropFinalized<StringConstructor, "top" | "bottom" | "left" | "right", unknown, "top", boolean>;
readonly beforeLeave: EpPropFinalized<(new (...args: any[]) => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | (() => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | {
(): (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>;
new (): any;
readonly prototype: any;
} | (((new (...args: any[]) => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | (() => (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>) | {
(): (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>;
new (): any;
readonly prototype: any;
}) | null)[], unknown, unknown, () => true, boolean>;
readonly stretch: BooleanConstructor;
readonly tabindex: EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, 0, boolean>;
}>> & Readonly<{
"onUpdate:modelValue"?: ((name: TabPaneName) => any) | undefined;
onTabClick?: ((pane: {
uid: number;
getVnode: () => VNode;
slots: vue.Slots;
props: {
label?: string | undefined;
name?: (string | number) | undefined;
closable?: boolean | undefined;
disabled?: boolean | undefined;
lazy?: boolean | undefined;
};
paneName: TabPaneName | undefined;
active: boolean;
index: string | undefined;
isClosable: boolean;
isFocusInsidePane: () => boolean | undefined;
}, ev: Event) => any) | undefined;
onTabChange?: ((name: TabPaneName) => any) | undefined;
onEdit?: ((paneName: TabPaneName | undefined, action: "remove" | "add") => any) | undefined;
onTabRemove?: ((name: TabPaneName) => any) | undefined;
onTabAdd?: (() => any) | undefined;
}>, {
readonly type: EpPropMergeType<StringConstructor, "" | "card" | "border-card", unknown>;
readonly closable: boolean;
readonly tabindex: EpPropMergeType<readonly [StringConstructor, NumberConstructor], unknown, unknown>;
readonly stretch: boolean;
readonly editable: boolean;
readonly tabPosition: EpPropMergeType<StringConstructor, "top" | "bottom" | "left" | "right", unknown>;
readonly beforeLeave: (newName: TabPaneName, oldName: TabPaneName) => Awaitable<void | boolean>;
readonly addable: boolean;
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
type TabsInstance = InstanceType<typeof Tabs> & {
currentName: TabPaneName;
tabNavRef: TabNavInstance | undefined;
};
//#endregion
export { Tabs, TabsEmits, TabsInstance, TabsPanes, TabsProps, TabsPropsPublic, tabsEmits, tabsProps };
+177
View File
@@ -0,0 +1,177 @@
import { EVENT_CODE } from "../../../constants/aria.mjs";
import { UPDATE_MODEL_EVENT } from "../../../constants/event.mjs";
import { getEventCode } from "../../../utils/dom/event.mjs";
import { isNumber, isString, isUndefined as isUndefined$1 } from "../../../utils/types.mjs";
import { buildProps, definePropType } from "../../../utils/vue/props/runtime.mjs";
import { useNamespace } from "../../../hooks/use-namespace/index.mjs";
import { useOrderedChildren } from "../../../hooks/use-ordered-children/index.mjs";
import { ElIcon } from "../../icon/index.mjs";
import { tabsRootContextKey } from "./constants.mjs";
import TabNav from "./tab-nav.mjs";
import { omit } from "lodash-unified";
import { Plus } from "@element-plus/icons-vue";
import { computed, createVNode, defineComponent, getCurrentInstance, nextTick, provide, ref, renderSlot, watch } from "vue";
//#region ../../packages/components/tabs/src/tabs.tsx
const tabsProps = buildProps({
type: {
type: String,
values: [
"card",
"border-card",
""
],
default: ""
},
closable: Boolean,
addable: Boolean,
modelValue: { type: [String, Number] },
defaultValue: { type: [String, Number] },
editable: Boolean,
tabPosition: {
type: String,
values: [
"top",
"right",
"bottom",
"left"
],
default: "top"
},
beforeLeave: {
type: definePropType(Function),
default: () => true
},
stretch: Boolean,
tabindex: {
type: [String, Number],
default: 0
}
});
const isPaneName = (value) => isString(value) || isNumber(value);
const tabsEmits = {
[UPDATE_MODEL_EVENT]: (name) => isPaneName(name),
tabClick: (pane, ev) => ev instanceof Event,
tabChange: (name) => isPaneName(name),
edit: (paneName, action) => ["remove", "add"].includes(action),
tabRemove: (name) => isPaneName(name),
tabAdd: () => true
};
const Tabs = /* @__PURE__ */ defineComponent({
name: "ElTabs",
props: tabsProps,
emits: tabsEmits,
setup(props, { emit, slots, expose }) {
const ns = useNamespace("tabs");
const isVertical = computed(() => ["left", "right"].includes(props.tabPosition));
const { children: panes, addChild: registerPane, removeChild: unregisterPane, ChildrenSorter: PanesSorter } = useOrderedChildren(getCurrentInstance(), "ElTabPane");
const nav$ = ref();
const currentName = ref((isUndefined$1(props.modelValue) ? props.defaultValue : props.modelValue) ?? "0");
const setCurrentName = async (value, trigger = false) => {
if (currentName.value === value || isUndefined$1(value)) return;
try {
let canLeave;
if (props.beforeLeave) {
const result = props.beforeLeave(value, currentName.value);
canLeave = result instanceof Promise ? await result : result;
} else canLeave = true;
if (canLeave !== false) {
const isFocusInsidePane = panes.value.find((item) => item.paneName === currentName.value)?.isFocusInsidePane();
currentName.value = value;
if (trigger) {
emit(UPDATE_MODEL_EVENT, value);
emit("tabChange", value);
}
nav$.value?.removeFocus?.();
if (isFocusInsidePane) nav$.value?.focusActiveTab();
}
} catch {}
};
const handleTabClick = (tab, tabName, event) => {
if (tab.props.disabled) return;
emit("tabClick", tab, event);
setCurrentName(tabName, true);
};
const handleTabRemove = (pane, ev) => {
if (pane.props.disabled || isUndefined$1(pane.props.name)) return;
ev.stopPropagation();
emit("edit", pane.props.name, "remove");
emit("tabRemove", pane.props.name);
};
const handleTabAdd = () => {
emit("edit", void 0, "add");
emit("tabAdd");
};
const handleKeydown = (event) => {
const code = getEventCode(event);
if ([EVENT_CODE.enter, EVENT_CODE.numpadEnter].includes(code)) handleTabAdd();
};
const swapChildren = (vnode) => {
const actualFirstChild = vnode.el.firstChild;
const firstChild = ["bottom", "right"].includes(props.tabPosition) ? vnode.children[0].el : vnode.children[1].el;
if (actualFirstChild !== firstChild) actualFirstChild.before(firstChild);
};
watch(() => props.modelValue, (modelValue) => setCurrentName(modelValue));
watch(currentName, async () => {
await nextTick();
nav$.value?.scrollToActiveTab();
});
provide(tabsRootContextKey, {
props,
currentName,
registerPane,
unregisterPane,
nav$
});
expose({
currentName,
get tabNavRef() {
return omit(nav$.value, ["scheduleRender"]);
}
});
return () => {
const addSlot = slots["add-icon"];
const newButton = props.editable || props.addable ? createVNode("div", {
"class": [ns.e("new-tab"), isVertical.value && ns.e("new-tab-vertical")],
"tabindex": props.tabindex,
"onClick": handleTabAdd,
"onKeydown": handleKeydown
}, [addSlot ? renderSlot(slots, "add-icon") : createVNode(ElIcon, { "class": ns.is("icon-plus") }, { default: () => [createVNode(Plus, null, null)] })]) : null;
const tabNav = () => createVNode(TabNav, {
"ref": nav$,
"currentName": currentName.value,
"editable": props.editable,
"type": props.type,
"panes": panes.value,
"stretch": props.stretch,
"onTabClick": handleTabClick,
"onTabRemove": handleTabRemove
}, null);
const header = createVNode("div", { "class": [
ns.e("header"),
isVertical.value && ns.e("header-vertical"),
ns.is(props.tabPosition)
] }, [createVNode(PanesSorter, null, {
default: tabNav,
$stable: true
}), newButton]);
const panels = createVNode("div", { "class": ns.e("content") }, [renderSlot(slots, "default")]);
return createVNode("div", {
"class": [
ns.b(),
ns.m(props.tabPosition),
{
[ns.m("card")]: props.type === "card",
[ns.m("border-card")]: props.type === "border-card"
}
],
"onVnodeMounted": swapChildren,
"onVnodeUpdated": swapChildren
}, [panels, header]);
};
}
});
//#endregion
export { Tabs as default, tabsEmits, tabsProps };
//# sourceMappingURL=tabs.mjs.map
File diff suppressed because one or more lines are too long
+2
View File
@@ -0,0 +1,2 @@
import "../../base/style/css.mjs";
import "element-plus/theme-chalk/el-tabs.css";
@@ -0,0 +1,2 @@
import "../../base/style/index.mjs";
import "element-plus/theme-chalk/src/tabs.scss";