@vnejs/module.controller.interact 0.2.1

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.
@@ -0,0 +1,20 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { ModuleControllerInteractConstants, ModuleControllerInteractEvents, ModuleControllerInteractParams, ModuleControllerInteractSettings, ModuleControllerInteractState } from "./types.js";
3
+ export type { ModuleControllerInteractConstants, ModuleControllerInteractEvents, ModuleControllerInteractParams, ModuleControllerInteractSettings, ModuleControllerInteractState, } from "./types.js";
4
+ export declare abstract class ModuleControllerInteract<TEvents extends ModuleControllerInteractEvents = ModuleControllerInteractEvents, TConstants extends ModuleControllerInteractConstants = ModuleControllerInteractConstants, TSettings extends ModuleControllerInteractSettings = ModuleControllerInteractSettings, TParams extends ModuleControllerInteractParams = ModuleControllerInteractParams, TState extends ModuleControllerInteractState = ModuleControllerInteractState> extends ModuleCore<TEvents, TConstants, TSettings, TParams, TState> {
5
+ abstract name: string;
6
+ abstract EVENT_SHOW: string;
7
+ abstract EVENT_HIDE: string;
8
+ abstract CONTROLS_ZINDEX: number;
9
+ CONTROLS_CHECK_NEXT: boolean;
10
+ get CONTROLS(): {
11
+ abstract_any: () => undefined;
12
+ };
13
+ subscribe: () => void;
14
+ getDefaultState: () => TState;
15
+ abstract onInteract: () => void | Promise<unknown>;
16
+ onShowControls: () => Promise<import("@vnejs/shared").EmitResults<"vne:controls:push">> | undefined;
17
+ onShowAfter: () => Promise<import("@vnejs/shared").EmitResults<"vne:interact:push">> | undefined;
18
+ onHideBefore: () => Promise<import("@vnejs/shared").EmitResults<"vne:interact:pop">> | undefined;
19
+ onHideControls: () => Promise<import("@vnejs/shared").EmitResults<"vne:controls:pop">> | undefined;
20
+ }
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class ModuleControllerInteract extends ModuleCore {
3
+ CONTROLS_CHECK_NEXT = true;
4
+ get CONTROLS() {
5
+ return {
6
+ [this.CONST.CONTROLS.BUTTONS.ANY]: () => void this.emit(this.EVENTS.INTERACT.EMIT),
7
+ };
8
+ }
9
+ subscribe = () => {
10
+ const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
11
+ this.on(this.EVENT_SHOW, this.onShowControls, { priority: SHOW.CONTROLS });
12
+ this.on(this.EVENT_SHOW, this.onShowAfter, { priority: SHOW.AFTER });
13
+ this.on(this.EVENT_HIDE, this.onHideBefore, { priority: HIDE.BEFORE });
14
+ this.on(this.EVENT_HIDE, this.onHideControls, { priority: HIDE.CONTROLS });
15
+ };
16
+ getDefaultState = () => ({ isShow: false });
17
+ onShowControls = () => {
18
+ this.updateState({ isShow: true });
19
+ return this.emit(this.EVENTS.CONTROLS.PUSH, {
20
+ key: this.name,
21
+ controls: this.CONTROLS,
22
+ index: this.CONTROLS_ZINDEX + 1,
23
+ checkNext: this.CONTROLS_CHECK_NEXT,
24
+ });
25
+ };
26
+ onShowAfter = () => this.emit(this.EVENTS.INTERACT.PUSH, {
27
+ key: this.name,
28
+ handler: () => this.onInteract(),
29
+ });
30
+ onHideBefore = () => {
31
+ if (!this.state.isShow)
32
+ return;
33
+ return this.emit(this.EVENTS.INTERACT.POP, { key: this.name });
34
+ };
35
+ onHideControls = () => {
36
+ if (!this.state.isShow)
37
+ return;
38
+ this.updateState({ isShow: false });
39
+ this.setDefaultState();
40
+ return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name });
41
+ };
42
+ }
@@ -0,0 +1,9 @@
1
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName, SubscribeEvents as ControlsSubscribeEvents } from "@vnejs/contracts.controls";
3
+ export type ModuleControllerInteractEvents = ModuleCoreEvents & Record<ControlsPluginName, ControlsSubscribeEvents>;
4
+ export type ModuleControllerInteractConstants = ModuleCoreConstants & Record<ControlsPluginName, ControlsConstants>;
5
+ export type ModuleControllerInteractSettings = ModuleCoreSettings;
6
+ export type ModuleControllerInteractParams = ModuleCoreParams;
7
+ export type ModuleControllerInteractState = {
8
+ isShow: boolean;
9
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@vnejs/module.controller.interact",
3
+ "version": "0.2.1",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
20
+ "scripts": {
21
+ "test": "echo \"Error: no test specified\" && exit 1",
22
+ "build": "npx @vnejs/monorepo package",
23
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
24
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
25
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
26
+ },
27
+ "author": "",
28
+ "license": "ISC",
29
+ "peerDependencies": {
30
+ "@vnejs/module.core": "~0.2.0",
31
+ "@vnejs/contracts.controls": "~0.2.0",
32
+ "@vnejs/contracts.core.interact": "~0.2.0",
33
+ "@vnejs/shared": "~0.2.0"
34
+ },
35
+ "devDependencies": {
36
+ "@vnejs/configs.ts-common": "~0.2.0",
37
+ "@vnejs/module.core": "~0.2.0",
38
+ "@vnejs/contracts.controls": "~0.2.0",
39
+ "@vnejs/contracts.core.interact": "~0.2.0",
40
+ "@vnejs/shared": "~0.2.0"
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,86 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { ControlsPopPayload, ControlsPushPayload } from "@vnejs/contracts.controls";
3
+ import type { InteractPopPayload, InteractPushPayload } from "@vnejs/contracts.core.interact";
4
+
5
+ import type {
6
+ ModuleControllerInteractConstants,
7
+ ModuleControllerInteractEvents,
8
+ ModuleControllerInteractParams,
9
+ ModuleControllerInteractSettings,
10
+ ModuleControllerInteractState,
11
+ } from "./types.js";
12
+
13
+ export type {
14
+ ModuleControllerInteractConstants,
15
+ ModuleControllerInteractEvents,
16
+ ModuleControllerInteractParams,
17
+ ModuleControllerInteractSettings,
18
+ ModuleControllerInteractState,
19
+ } from "./types.js";
20
+
21
+ export abstract class ModuleControllerInteract<
22
+ TEvents extends ModuleControllerInteractEvents = ModuleControllerInteractEvents,
23
+ TConstants extends ModuleControllerInteractConstants = ModuleControllerInteractConstants,
24
+ TSettings extends ModuleControllerInteractSettings = ModuleControllerInteractSettings,
25
+ TParams extends ModuleControllerInteractParams = ModuleControllerInteractParams,
26
+ TState extends ModuleControllerInteractState = ModuleControllerInteractState,
27
+ > extends ModuleCore<TEvents, TConstants, TSettings, TParams, TState> {
28
+ abstract override name: string;
29
+
30
+ abstract EVENT_SHOW: string;
31
+ abstract EVENT_HIDE: string;
32
+
33
+ abstract CONTROLS_ZINDEX: number;
34
+ CONTROLS_CHECK_NEXT = true;
35
+
36
+ get CONTROLS() {
37
+ return {
38
+ [this.CONST.CONTROLS.BUTTONS.ANY]: () => void this.emit(this.EVENTS.INTERACT.EMIT),
39
+ };
40
+ }
41
+
42
+ subscribe = () => {
43
+ const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
44
+
45
+ this.on(this.EVENT_SHOW, this.onShowControls, { priority: SHOW.CONTROLS });
46
+ this.on(this.EVENT_SHOW, this.onShowAfter, { priority: SHOW.AFTER });
47
+ this.on(this.EVENT_HIDE, this.onHideBefore, { priority: HIDE.BEFORE });
48
+ this.on(this.EVENT_HIDE, this.onHideControls, { priority: HIDE.CONTROLS });
49
+ };
50
+
51
+ getDefaultState = (): TState => ({ isShow: false }) as TState;
52
+
53
+ abstract onInteract: () => void | Promise<unknown>;
54
+
55
+ onShowControls = () => {
56
+ this.updateState({ isShow: true } as Partial<TState>);
57
+
58
+ return this.emit(this.EVENTS.CONTROLS.PUSH, {
59
+ key: this.name,
60
+ controls: this.CONTROLS,
61
+ index: this.CONTROLS_ZINDEX + 1,
62
+ checkNext: this.CONTROLS_CHECK_NEXT,
63
+ } satisfies ControlsPushPayload);
64
+ };
65
+
66
+ onShowAfter = () =>
67
+ this.emit(this.EVENTS.INTERACT.PUSH, {
68
+ key: this.name,
69
+ handler: () => this.onInteract(),
70
+ } satisfies InteractPushPayload);
71
+
72
+ onHideBefore = () => {
73
+ if (!this.state.isShow) return;
74
+
75
+ return this.emit(this.EVENTS.INTERACT.POP, { key: this.name } satisfies InteractPopPayload);
76
+ };
77
+
78
+ onHideControls = () => {
79
+ if (!this.state.isShow) return;
80
+
81
+ this.updateState({ isShow: false } as Partial<TState>);
82
+ this.setDefaultState();
83
+
84
+ return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name } satisfies ControlsPopPayload);
85
+ };
86
+ }
package/src/types.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName, SubscribeEvents as ControlsSubscribeEvents } from "@vnejs/contracts.controls";
3
+
4
+ export type ModuleControllerInteractEvents = ModuleCoreEvents & Record<ControlsPluginName, ControlsSubscribeEvents>;
5
+
6
+ export type ModuleControllerInteractConstants = ModuleCoreConstants & Record<ControlsPluginName, ControlsConstants>;
7
+
8
+ export type ModuleControllerInteractSettings = ModuleCoreSettings;
9
+
10
+ export type ModuleControllerInteractParams = ModuleCoreParams;
11
+
12
+ export type ModuleControllerInteractState = {
13
+ isShow: boolean;
14
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules"]
9
+ }