@vnejs/module.controller.tabs 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -4
- package/dist/index.js +17 -7
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/index.ts +21 -8
- package/src/types.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare abstract class ModuleControllerTabs<TEvents extends ModuleControl
|
|
|
6
6
|
abstract EVENT_SHOW: string;
|
|
7
7
|
abstract EVENT_HIDE: string;
|
|
8
8
|
abstract EVENT_TAB_SET: string;
|
|
9
|
-
abstract
|
|
9
|
+
abstract EVENT_UPDATE_STATE: string;
|
|
10
10
|
abstract CONTROLS_ZINDEX: number;
|
|
11
11
|
CONTROLS: {
|
|
12
12
|
abstract_tab_prev: () => undefined;
|
|
@@ -17,10 +17,11 @@ export declare abstract class ModuleControllerTabs<TEvents extends ModuleControl
|
|
|
17
17
|
getDefaultState: () => TState;
|
|
18
18
|
getTabKeys: () => string[];
|
|
19
19
|
abstract onTabSet: (payload?: ModuleControllerTabsTabSetPayload) => void | Promise<void>;
|
|
20
|
-
applyTab: (tab: string) => Promise<
|
|
20
|
+
applyTab: (tab: string) => Promise<import("@vnejs/shared").EmitResults<string>> | undefined;
|
|
21
21
|
onTabSetEvent: (payload?: ModuleControllerTabsTabSetPayload) => Promise<void>;
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
onShowBefore: ({ tab }?: ModuleControllerTabsTabSetPayload) => void;
|
|
23
|
+
onShow: () => Promise<import("@vnejs/shared").EmitResults<"vne:controls:push">> | undefined;
|
|
24
|
+
onHide: () => Promise<import("@vnejs/shared").EmitResults<"vne:controls:pop">> | undefined;
|
|
24
25
|
onPrevTab: () => undefined;
|
|
25
26
|
onNextTab: () => undefined;
|
|
26
27
|
getNewTab: (isNext: boolean) => string;
|
package/dist/index.js
CHANGED
|
@@ -6,16 +6,18 @@ export class ModuleControllerTabs extends ModuleCore {
|
|
|
6
6
|
};
|
|
7
7
|
TABS = {};
|
|
8
8
|
subscribe = () => {
|
|
9
|
-
|
|
10
|
-
this.on(this.
|
|
9
|
+
const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
|
|
10
|
+
this.on(this.EVENT_SHOW, this.onShowBefore, { priority: SHOW.BEFORE });
|
|
11
|
+
this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.CONTROLS });
|
|
12
|
+
this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.CONTROLS });
|
|
11
13
|
this.on(this.EVENT_TAB_SET, this.onTabSetEvent);
|
|
12
|
-
this.on(this.
|
|
14
|
+
this.on(this.EVENT_UPDATE_STATE, this.updateState);
|
|
13
15
|
};
|
|
14
|
-
getDefaultState = () => ({});
|
|
16
|
+
getDefaultState = () => ({ isShow: false });
|
|
15
17
|
getTabKeys = () => Object.keys(this.TABS);
|
|
16
18
|
applyTab = (tab) => {
|
|
17
19
|
this.updateState({ tab });
|
|
18
|
-
return this.emit(this.
|
|
20
|
+
return this.emit(this.EVENT_UPDATE_STATE, { tab });
|
|
19
21
|
};
|
|
20
22
|
onTabSetEvent = async (payload = {}) => {
|
|
21
23
|
const { tab, isForce } = payload;
|
|
@@ -26,8 +28,11 @@ export class ModuleControllerTabs extends ModuleCore {
|
|
|
26
28
|
await this.applyTab(tab);
|
|
27
29
|
return this.onTabSet(payload);
|
|
28
30
|
};
|
|
29
|
-
|
|
31
|
+
onShowBefore = ({ tab } = {}) => {
|
|
30
32
|
this.updateState({ tab: tab ?? this.getTabKeys()[0] });
|
|
33
|
+
};
|
|
34
|
+
onShow = () => {
|
|
35
|
+
this.updateState({ isShow: true });
|
|
31
36
|
return this.emit(this.EVENTS.CONTROLS.PUSH, {
|
|
32
37
|
key: this.name,
|
|
33
38
|
controls: this.CONTROLS,
|
|
@@ -35,7 +40,12 @@ export class ModuleControllerTabs extends ModuleCore {
|
|
|
35
40
|
checkNext: true,
|
|
36
41
|
});
|
|
37
42
|
};
|
|
38
|
-
onHide = () =>
|
|
43
|
+
onHide = () => {
|
|
44
|
+
if (!this.state.isShow)
|
|
45
|
+
return;
|
|
46
|
+
this.updateState({ isShow: false });
|
|
47
|
+
return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name });
|
|
48
|
+
};
|
|
39
49
|
onPrevTab = () => void this.emit(this.EVENT_TAB_SET, { tab: this.getNewTab(false) });
|
|
40
50
|
onNextTab = () => void this.emit(this.EVENT_TAB_SET, { tab: this.getNewTab(true) });
|
|
41
51
|
getNewTab = (isNext) => {
|
package/dist/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type ModuleControllerTabsConstants = ModuleCoreConstants & Record<Control
|
|
|
5
5
|
export type ModuleControllerTabsSettings = ModuleCoreSettings;
|
|
6
6
|
export type ModuleControllerTabsParams = ModuleCoreParams;
|
|
7
7
|
export type ModuleControllerTabsState = {
|
|
8
|
+
isShow: boolean;
|
|
8
9
|
tab?: string;
|
|
9
10
|
};
|
|
10
11
|
export type ModuleControllerTabsTabSetPayload = {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -31,7 +31,7 @@ export abstract class ModuleControllerTabs<
|
|
|
31
31
|
abstract EVENT_SHOW: string;
|
|
32
32
|
abstract EVENT_HIDE: string;
|
|
33
33
|
abstract EVENT_TAB_SET: string;
|
|
34
|
-
abstract
|
|
34
|
+
abstract EVENT_UPDATE_STATE: string;
|
|
35
35
|
|
|
36
36
|
abstract CONTROLS_ZINDEX: number;
|
|
37
37
|
|
|
@@ -43,13 +43,16 @@ export abstract class ModuleControllerTabs<
|
|
|
43
43
|
TABS: Record<string, unknown> = {};
|
|
44
44
|
|
|
45
45
|
subscribe = () => {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
|
|
47
|
+
|
|
48
|
+
this.on(this.EVENT_SHOW, this.onShowBefore, { priority: SHOW.BEFORE });
|
|
49
|
+
this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.CONTROLS });
|
|
50
|
+
this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.CONTROLS });
|
|
48
51
|
this.on(this.EVENT_TAB_SET, this.onTabSetEvent);
|
|
49
|
-
this.on(this.
|
|
52
|
+
this.on(this.EVENT_UPDATE_STATE, this.updateState);
|
|
50
53
|
};
|
|
51
54
|
|
|
52
|
-
getDefaultState = (): TState => ({}) as TState;
|
|
55
|
+
getDefaultState = (): TState => ({ isShow: false }) as TState;
|
|
53
56
|
|
|
54
57
|
getTabKeys = () => Object.keys(this.TABS);
|
|
55
58
|
|
|
@@ -57,7 +60,7 @@ export abstract class ModuleControllerTabs<
|
|
|
57
60
|
|
|
58
61
|
applyTab = (tab: string) => {
|
|
59
62
|
this.updateState({ tab } as Partial<TState>);
|
|
60
|
-
return this.emit(this.
|
|
63
|
+
return this.emit(this.EVENT_UPDATE_STATE, { tab } satisfies Partial<ModuleControllerTabsState>);
|
|
61
64
|
};
|
|
62
65
|
|
|
63
66
|
onTabSetEvent = async (payload: ModuleControllerTabsTabSetPayload = {}) => {
|
|
@@ -69,8 +72,12 @@ export abstract class ModuleControllerTabs<
|
|
|
69
72
|
return this.onTabSet(payload);
|
|
70
73
|
};
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
onShowBefore = ({ tab }: ModuleControllerTabsTabSetPayload = {}) => {
|
|
73
76
|
this.updateState({ tab: tab ?? this.getTabKeys()[0] } as Partial<TState>);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
onShow = () => {
|
|
80
|
+
this.updateState({ isShow: true } as Partial<TState>);
|
|
74
81
|
|
|
75
82
|
return this.emit(this.EVENTS.CONTROLS.PUSH, {
|
|
76
83
|
key: this.name,
|
|
@@ -80,7 +87,13 @@ export abstract class ModuleControllerTabs<
|
|
|
80
87
|
} satisfies ControlsPushPayload);
|
|
81
88
|
};
|
|
82
89
|
|
|
83
|
-
onHide = () =>
|
|
90
|
+
onHide = () => {
|
|
91
|
+
if (!this.state.isShow) return;
|
|
92
|
+
|
|
93
|
+
this.updateState({ isShow: false } as Partial<TState>);
|
|
94
|
+
|
|
95
|
+
return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name } satisfies ControlsPopPayload);
|
|
96
|
+
};
|
|
84
97
|
|
|
85
98
|
onPrevTab = () => void this.emit(this.EVENT_TAB_SET, { tab: this.getNewTab(false) } satisfies ModuleControllerTabsTabSetPayload);
|
|
86
99
|
onNextTab = () => void this.emit(this.EVENT_TAB_SET, { tab: this.getNewTab(true) } satisfies ModuleControllerTabsTabSetPayload);
|