@@ -8,29 +8,31 @@ import type {
88 TTabsVariant ,
99} from '@/types' ;
1010import Helper from '@/utils/Helper' ;
11- import type { ComponentInternalInstance , Ref } from 'vue' ;
12- import { isRef } from 'vue' ;
11+ import type { ComponentInternalInstance , Ref , ShallowReactive } from 'vue' ;
12+ import { isRef , shallowReactive } from 'vue' ;
1313
1414/**
1515 * Class TabsProvider which is used for BsTab's component dependency injection.
1616 *
1717 * @author Ahmad Fajar
18- * @since 22/11/2022, modified: 18/08/2024 19:57
18+ * @since 22/11/2022, modified: 01/02/2025 16:18
1919 */
2020class TabsProvider {
21- private _tabItems : ComponentInternalInstance [ ] ;
22- private _tabPanels : ComponentInternalInstance [ ] ;
2321 private _activeTab : ComponentInternalInstance | undefined ;
2422 private _activeTabIndex : number | undefined ;
2523 private _props : TTabsBaseProps ;
2624 private readonly _emit : TEmitFn ;
25+ public tabItems : ShallowReactive < ComponentInternalInstance [ ] > ;
26+ public tabPanels : ShallowReactive < ComponentInternalInstance [ ] > ;
2727
2828 constructor ( tabConfig : Readonly < TTabsBaseProps > , emitter : TEmitFn , activeTab ?: number ) {
2929 this . _props = tabConfig ;
30- this . _tabItems = [ ] ;
31- this . _tabPanels = [ ] ;
30+ this . _activeTab = undefined ;
3231 this . _activeTabIndex = activeTab ;
3332 this . _emit = emitter ;
33+
34+ this . tabItems = shallowReactive < ComponentInternalInstance [ ] > ( [ ] ) ;
35+ this . tabPanels = shallowReactive < ComponentInternalInstance [ ] > ( [ ] ) ;
3436 }
3537
3638 get activeTab ( ) : ComponentInternalInstance | undefined {
@@ -69,22 +71,14 @@ class TabsProvider {
6971 return this . _props . variant ;
7072 }
7173
72- get tabItems ( ) : ComponentInternalInstance [ ] {
73- return this . _tabItems ;
74- }
75-
76- get tabPanels ( ) : ComponentInternalInstance [ ] {
77- return this . _tabPanels ;
78- }
79-
8074 /**
8175 * Register a TabIem.
8276 *
8377 * @param {ComponentInternalInstance } item The TabIem item
8478 * @returns {number } The TabIem index position
8579 */
8680 registerTabItem ( item : ComponentInternalInstance ) : number {
87- return this . _tabItems . push ( item ) ;
81+ return this . tabItems . push ( item ) ;
8882 }
8983
9084 /**
@@ -94,7 +88,7 @@ class TabsProvider {
9488 * @returns {number } The TabPanel index position
9589 */
9690 registerTabPanel ( item : ComponentInternalInstance ) : number {
97- return this . _tabPanels . push ( item ) ;
91+ return this . tabPanels . push ( item ) ;
9892 }
9993
10094 /**
@@ -103,8 +97,8 @@ class TabsProvider {
10397 * @returns {void }
10498 */
10599 unRegisterAll ( ) : void {
106- this . _tabItems = [ ] ;
107- this . _tabPanels = [ ] ;
100+ this . tabItems = [ ] ;
101+ this . tabPanels = [ ] ;
108102 }
109103
110104 /**
@@ -115,20 +109,18 @@ class TabsProvider {
115109 */
116110 unRegisterTab ( key : string | number ) : void {
117111 if ( Helper . isNumber ( key ) ) {
118- this . _tabItems . splice ( key , 1 ) ;
119- this . _tabPanels . splice ( key , 1 ) ;
112+ this . tabItems . splice ( key , 1 ) ;
113+ this . tabPanels . splice ( key , 1 ) ;
120114 } else {
121- let idx = this . _tabPanels . findIndex (
115+ let idx = this . tabPanels . findIndex (
122116 ( el ) => ( el . props as TTabItemOptionProps ) . id === key
123117 ) ;
124118 if ( idx === - 1 ) {
125- idx = this . _tabItems . findIndex (
126- ( el ) => ( el . props as TTabItemOptionProps ) . id === key
127- ) ;
119+ idx = this . tabItems . findIndex ( ( el ) => ( el . props as TTabItemOptionProps ) . id === key ) ;
128120 }
129121
130- this . _tabItems . splice ( idx , 1 ) ;
131- this . _tabPanels . splice ( idx , 1 ) ;
122+ this . tabItems . splice ( idx , 1 ) ;
123+ this . tabPanels . splice ( idx , 1 ) ;
132124 }
133125 }
134126
@@ -155,7 +147,7 @@ class TabsProvider {
155147 Helper . isString ( key ) && pid === `tabItem-${ key } ` ;
156148 }
157149 } ) ;
158- this . tabPanels . forEach ( ( el , idx ) => {
150+ this . tabPanels . forEach ( ( el : ShallowReactive < ComponentInternalInstance > , idx ) => {
159151 const pid = ( el . props as TTabItemOptionProps ) . id ;
160152
161153 if ( ( Helper . isNumber ( key ) && key === idx ) || ( Helper . isString ( key ) && key === pid ) ) {
@@ -177,7 +169,6 @@ class TabsProvider {
177169 ( el . exposed as TRecord ) . isActive = false ;
178170 }
179171 }
180- // console.log(`tabPane-${pid}:active`, (<TTabItemOptionProps>el.props).active);
181172 } ) ;
182173 }
183174
0 commit comments