@vnejs/plugins.controllers.scenario.interface 0.0.0-stage → 0.2.16
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 +2 -0
- package/dist/index.js +20 -0
- package/dist/modules/actions.d.ts +12 -0
- package/dist/modules/actions.js +21 -0
- package/dist/modules/actions.show.d.ts +15 -0
- package/dist/modules/actions.show.js +32 -0
- package/dist/modules/controller.accept.d.ts +10 -0
- package/dist/modules/controller.accept.js +9 -0
- package/dist/modules/controller.d.ts +28 -0
- package/dist/modules/controller.js +85 -0
- package/dist/modules/interface.d.ts +11 -0
- package/dist/modules/interface.js +18 -0
- package/dist/modules/scenario.d.ts +9 -0
- package/dist/modules/scenario.js +18 -0
- package/dist/modules/view.d.ts +10 -0
- package/dist/modules/view.js +9 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.js +1 -0
- package/dist/utils/interface.d.ts +10 -0
- package/dist/utils/interface.js +1 -0
- package/dist/view/components/InterfaceBackdrop.d.ts +2 -0
- package/dist/view/components/InterfaceBackdrop.js +6 -0
- package/dist/view/components/InterfaceViewDialog.d.ts +2 -0
- package/dist/view/components/InterfaceViewDialog.js +18 -0
- package/dist/view/components/InterfaceViewLine.d.ts +2 -0
- package/dist/view/components/InterfaceViewLine.js +9 -0
- package/dist/view/components/InterfaceViewWall.d.ts +2 -0
- package/dist/view/components/InterfaceViewWall.js +28 -0
- package/dist/view/components/index.d.ts +4 -0
- package/dist/view/components/index.js +4 -0
- package/dist/view/components/tokens.hook.d.ts +6 -0
- package/dist/view/components/tokens.hook.js +31 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +38 -0
- package/package.json +62 -4
- package/src/index.ts +24 -0
- package/src/modules/actions.show.ts +49 -0
- package/src/modules/actions.ts +33 -0
- package/src/modules/controller.accept.ts +20 -0
- package/src/modules/controller.ts +123 -0
- package/src/modules/interface.ts +36 -0
- package/src/modules/scenario.ts +27 -0
- package/src/modules/view.ts +23 -0
- package/src/tests/accept.test.ts +78 -0
- package/src/tests/actions.test.ts +44 -0
- package/src/tests/controller.test.ts +42 -0
- package/src/tests/interface.test.ts +20 -0
- package/src/tests/scenario.test.ts +53 -0
- package/src/tests/setup.ts +51 -0
- package/src/tests/show.test.ts +131 -0
- package/src/types.ts +57 -0
- package/src/utils/interface.ts +11 -0
- package/src/view/components/InterfaceBackdrop.tsx +16 -0
- package/src/view/components/InterfaceViewDialog.tsx +66 -0
- package/src/view/components/InterfaceViewLine.tsx +33 -0
- package/src/view/components/InterfaceViewWall.tsx +108 -0
- package/src/view/components/index.ts +4 -0
- package/src/view/components/tokens.hook.ts +35 -0
- package/src/view/index.tsx +100 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.controllers.scenario.interface",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.16",
|
|
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": "npx @vnejs/monorepo test",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
23
|
+
"publish:major:plugin": "npm run publish:major",
|
|
24
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
25
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
29
|
+
},
|
|
30
|
+
"author": "",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/contracts.controllers.scenario.interface": "~0.2.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/helpers": "~0.2.0",
|
|
37
|
+
"@vnejs/module.core": "~0.2.0",
|
|
38
|
+
"@vnejs/module.components": "~0.2.0",
|
|
39
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
40
|
+
"@vnejs/contracts.text": "~0.2.0",
|
|
41
|
+
"@vnejs/contracts.text.meet": "~0.2.0",
|
|
42
|
+
"@vnejs/contracts.text.wall": "~0.2.0",
|
|
43
|
+
"@vnejs/registry": "~0.2.0",
|
|
44
|
+
"@vnejs/uis.react": "~0.2.0",
|
|
45
|
+
"@vnejs/uis.utils": "~0.2.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@vnejs/configs.ts-common": "~0.2.0",
|
|
49
|
+
"@vnejs/configs.vitest": "~0.2.0",
|
|
50
|
+
"@vnejs/test-utils": "~0.2.0",
|
|
51
|
+
"@vnejs/contracts.text": "~0.2.0",
|
|
52
|
+
"@vnejs/sources-set": "~0.2.0",
|
|
53
|
+
"@vnejs/helpers": "~0.2.0",
|
|
54
|
+
"@vnejs/module.core": "~0.2.0",
|
|
55
|
+
"@vnejs/module.components": "~0.2.0",
|
|
56
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
57
|
+
"@vnejs/contracts.text.meet": "~0.2.0",
|
|
58
|
+
"@vnejs/contracts.text.wall": "~0.2.0",
|
|
59
|
+
"@vnejs/registry": "~0.2.0",
|
|
60
|
+
"@vnejs/uis.react": "~0.2.0",
|
|
61
|
+
"@vnejs/uis.utils": "~0.2.0",
|
|
62
|
+
"@vnejs/contracts.controllers.scenario.interface": "~0.2.0"
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.scenario.interface";
|
|
2
|
+
import "@vnejs/contracts.text.meet";
|
|
3
|
+
|
|
4
|
+
import { regPlugin } from "@vnejs/registry";
|
|
5
|
+
|
|
6
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.scenario.interface";
|
|
7
|
+
|
|
8
|
+
import { InterfaceActions } from "./modules/actions.js";
|
|
9
|
+
import { InterfaceActionsShow } from "./modules/actions.show.js";
|
|
10
|
+
import { InterfaceControllerAccept } from "./modules/controller.accept.js";
|
|
11
|
+
import { InterfaceController } from "./modules/controller.js";
|
|
12
|
+
import { Interface } from "./modules/interface.js";
|
|
13
|
+
import { InterfaceScenario } from "./modules/scenario.js";
|
|
14
|
+
import { InterfaceView } from "./modules/view.js";
|
|
15
|
+
|
|
16
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
17
|
+
InterfaceController,
|
|
18
|
+
InterfaceControllerAccept,
|
|
19
|
+
Interface,
|
|
20
|
+
InterfaceActions,
|
|
21
|
+
InterfaceActionsShow,
|
|
22
|
+
InterfaceScenario,
|
|
23
|
+
InterfaceView,
|
|
24
|
+
]);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { InterfaceForcePayload } from "@vnejs/contracts.controllers.scenario.interface";
|
|
4
|
+
|
|
5
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
6
|
+
|
|
7
|
+
export class InterfaceActionsShow extends ModuleCore<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams> {
|
|
8
|
+
name = "interface.actions.show";
|
|
9
|
+
|
|
10
|
+
isInShowOrHideProcess = false;
|
|
11
|
+
|
|
12
|
+
subscribe = () => {
|
|
13
|
+
const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
|
|
14
|
+
|
|
15
|
+
this.on(this.EVENTS.INTERFACE.SHOW, this.onShowGate, { priority: SHOW.GATE, breakFollowing: true, filterFromResult: true });
|
|
16
|
+
this.on(this.EVENTS.INTERFACE.SHOW, this.setInProcessTrue, { priority: SHOW.GATE + 1 });
|
|
17
|
+
this.on(this.EVENTS.INTERFACE.SHOW, this.onShow);
|
|
18
|
+
this.on(this.EVENTS.INTERFACE.SHOW, this.setInProcessFalse, { priority: SHOW.AFTER + 1 });
|
|
19
|
+
|
|
20
|
+
this.on(this.EVENTS.INTERFACE.HIDE, this.onHideGate, { priority: HIDE.GATE, breakFollowing: true, filterFromResult: true });
|
|
21
|
+
this.on(this.EVENTS.INTERFACE.HIDE, this.setInProcessTrue, { priority: HIDE.GATE + 1 });
|
|
22
|
+
this.on(this.EVENTS.INTERFACE.HIDE, this.onHide);
|
|
23
|
+
this.on(this.EVENTS.INTERFACE.HIDE, this.setInProcessFalse, { priority: HIDE.CLEANUP + 1 });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
onShowGate = () => this.globalState.interface.isShow || this.isInShowOrHideProcess;
|
|
27
|
+
|
|
28
|
+
setInProcessTrue = () => {
|
|
29
|
+
this.isInShowOrHideProcess = true;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
onShow = ({ isForce = false }: InterfaceForcePayload = {}) => this.setShow(true, isForce);
|
|
33
|
+
|
|
34
|
+
setInProcessFalse = () => {
|
|
35
|
+
this.isInShowOrHideProcess = false;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
onHideGate = () => !this.globalState.interface.isShow || this.isInShowOrHideProcess;
|
|
39
|
+
|
|
40
|
+
onHide = ({ isForce = false }: InterfaceForcePayload = {}) => this.setShow(false, isForce);
|
|
41
|
+
|
|
42
|
+
setShow = async (isShow: boolean, isForce = false) => {
|
|
43
|
+
this.globalState.interface.isShow = isShow;
|
|
44
|
+
|
|
45
|
+
if (isShow && !this.globalState.interface.isVisible) await this.emit(this.EVENTS.INTERFACE.VISIBLE, { isForce });
|
|
46
|
+
|
|
47
|
+
return this.emit(this.EVENTS.INTERFACE.SHOW_CHANGED, { isForce });
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { InterfaceForcePayload, InterfaceViewPayload } from "@vnejs/contracts.controllers.scenario.interface";
|
|
4
|
+
|
|
5
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
6
|
+
|
|
7
|
+
export class InterfaceActions extends ModuleCore<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams> {
|
|
8
|
+
name = "interface.actions";
|
|
9
|
+
|
|
10
|
+
subscribe = () => {
|
|
11
|
+
this.on(this.EVENTS.INTERFACE.VISIBLE, this.onVisible);
|
|
12
|
+
this.on(this.EVENTS.INTERFACE.TEXT_HIDE, this.onTextHide);
|
|
13
|
+
this.on(this.EVENTS.INTERFACE.VIEW, this.onView);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
onVisible = ({ isForce = false }: InterfaceForcePayload = {}) => this.setVisible(!this.globalState.interface.isVisible, isForce);
|
|
17
|
+
|
|
18
|
+
onTextHide = () => this.emit(this.EVENTS.INTERFACE.TEXT_CHANGED, { tokens: [], uid: "", tokensVisible: 0 });
|
|
19
|
+
|
|
20
|
+
onView = ({ view, isForce = false }: InterfaceViewPayload = {}) => this.setView(view, isForce);
|
|
21
|
+
|
|
22
|
+
setVisible = (isVisible: boolean, isForce = false) => {
|
|
23
|
+
this.globalState.interface.isVisible = isVisible;
|
|
24
|
+
|
|
25
|
+
return this.emit(this.EVENTS.INTERFACE.VISIBLE_CHANGED, { isForce });
|
|
26
|
+
};
|
|
27
|
+
setView = async (view?: string, isForce = false) => {
|
|
28
|
+
this.globalState.interface.view = view ?? "";
|
|
29
|
+
|
|
30
|
+
await this.emit(this.EVENTS.INTERFACE.VIEW_CHANGED, { isForce });
|
|
31
|
+
await this.waitRerender();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
|
|
3
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
export class InterfaceControllerAccept extends ModuleControllerAccept<
|
|
6
|
+
InterfacePluginEvents,
|
|
7
|
+
InterfacePluginConstants,
|
|
8
|
+
InterfacePluginSettings,
|
|
9
|
+
InterfacePluginParams
|
|
10
|
+
> {
|
|
11
|
+
name = "interface.controller.accept";
|
|
12
|
+
|
|
13
|
+
EVENT_SHOW = this.EVENTS.INTERFACE.VIEW_SHOW;
|
|
14
|
+
EVENT_HIDE = this.EVENTS.INTERFACE.VIEW_HIDE;
|
|
15
|
+
EVENT_ACCEPT = this.EVENTS.INTERFACE.INTERACT;
|
|
16
|
+
|
|
17
|
+
CONTROLS_ZINDEX = this.PARAMS.INTERFACE.ZINDEX;
|
|
18
|
+
|
|
19
|
+
onAccept = () => void this.emit(this.globalState.interface.isVisible ? this.EVENTS.INTERACT.EMIT : this.EVENTS.INTERFACE.VISIBLE);
|
|
20
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { ControlsPopPayload, ControlsPushPayload } from "@vnejs/module.components";
|
|
4
|
+
|
|
5
|
+
import { getTextSpeakerInfo } from "@vnejs/contracts.text";
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
InterfaceForcePayload,
|
|
9
|
+
InterfaceSpeakerChangedPayload,
|
|
10
|
+
InterfaceTextChangedPayload,
|
|
11
|
+
InterfaceWallChangedPayload,
|
|
12
|
+
} from "@vnejs/contracts.controllers.scenario.interface";
|
|
13
|
+
|
|
14
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
15
|
+
import type { InterfacePluginState } from "../types.js";
|
|
16
|
+
|
|
17
|
+
export class InterfaceController extends ModuleController<
|
|
18
|
+
InterfacePluginEvents,
|
|
19
|
+
InterfacePluginConstants,
|
|
20
|
+
InterfacePluginSettings,
|
|
21
|
+
InterfacePluginParams,
|
|
22
|
+
InterfacePluginState
|
|
23
|
+
> {
|
|
24
|
+
name = "interface.controller";
|
|
25
|
+
|
|
26
|
+
EVENT_UPDATE_VIEW = this.EVENTS.INTERFACE.VIEW_UPDATE;
|
|
27
|
+
EVENT_UPDATE_STATE = this.EVENTS.INTERFACE.UPDATE_STATE;
|
|
28
|
+
EVENT_UPDATE_FAST = this.EVENTS.INTERFACE.UPDATE_FAST;
|
|
29
|
+
EVENT_UPDATE_FORCE = this.EVENTS.INTERFACE.UPDATE_FORCE;
|
|
30
|
+
EVENT_SHOW = this.EVENTS.INTERFACE.VIEW_SHOW;
|
|
31
|
+
EVENT_HIDE = this.EVENTS.INTERFACE.VIEW_HIDE;
|
|
32
|
+
|
|
33
|
+
SHOULD_CLEAR_STATE_ON_CLEANUP = false;
|
|
34
|
+
|
|
35
|
+
CONTROLS = {};
|
|
36
|
+
CONTROLS_UNVISIBLE = {};
|
|
37
|
+
CONTROLS_INDEX = this.PARAMS.INTERFACE.ZINDEX;
|
|
38
|
+
|
|
39
|
+
isStateChangeInProcess = false;
|
|
40
|
+
|
|
41
|
+
subscribe = () => {
|
|
42
|
+
super.subscribe();
|
|
43
|
+
|
|
44
|
+
this.on(this.EVENTS.INTERFACE.SHOW_CHANGED, this.onShowChanged);
|
|
45
|
+
this.on(this.EVENTS.INTERFACE.VIEW_CHANGED, this.onViewChanged);
|
|
46
|
+
this.on(this.EVENTS.INTERFACE.TEXT_CHANGED, this.onTextChanged);
|
|
47
|
+
this.on(this.EVENTS.INTERFACE.WALL_CHANGED, this.onWallChanged);
|
|
48
|
+
this.on(this.EVENTS.INTERFACE.SPEAKER_CHANGED, this.onSpeakerChanged);
|
|
49
|
+
this.on(this.EVENTS.INTERFACE.STATE_CHANGED, this.onStateChanged);
|
|
50
|
+
this.on(this.EVENTS.INTERFACE.VISIBLE_CHANGED, this.onVisibleChanged);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
init = () => this.emit(this.EVENTS.INTERFACE.VIEW, { view: this.PARAMS.INTERFACE.DEFAULT_VIEW, isForce: true });
|
|
54
|
+
|
|
55
|
+
onShowChanged = ({ isForce = false }: InterfaceForcePayload = {}) => {
|
|
56
|
+
const { isShow = false } = this.globalState.interface;
|
|
57
|
+
const event = isShow ? this.EVENTS.INTERFACE.VIEW_SHOW : this.EVENTS.INTERFACE.VIEW_HIDE;
|
|
58
|
+
|
|
59
|
+
if (this.state.isShow !== isShow) return this.emit(event, { isForce });
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
onViewChanged = ({ isForce = false }: InterfaceForcePayload = {}) => {
|
|
63
|
+
const { view = "" } = this.globalState.interface;
|
|
64
|
+
|
|
65
|
+
// Do not mark as fast: wait for TRANSITION so React applies isViewActive before the next scenario line (text).
|
|
66
|
+
// Otherwise useTokensHook can receive tokens while the target view is still inactive and never show them.
|
|
67
|
+
if (this.state.view !== view) return this.updateStateAndView({ view }, isForce, false);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
onTextChanged = async ({ tokens = [], uid = "", tokensVisible = 0 }: InterfaceTextChangedPayload = {}) => {
|
|
71
|
+
while (this.isStateChangeInProcess) await this.waitRerender();
|
|
72
|
+
|
|
73
|
+
return this.updateStateAndViewFast({ tokens, uid, tokensVisible });
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
onWallChanged = async ({ wall = [] }: InterfaceWallChangedPayload = {}) => {
|
|
77
|
+
while (this.isStateChangeInProcess) await this.waitRerender();
|
|
78
|
+
|
|
79
|
+
return this.updateStateAndViewFast({ wall });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
onSpeakerChanged = async ({ speaker = "" }: InterfaceSpeakerChangedPayload = {}) => {
|
|
83
|
+
while (this.isStateChangeInProcess) await this.waitRerender();
|
|
84
|
+
|
|
85
|
+
const speakerInfo = { ...getTextSpeakerInfo(this.globalState["text.speaker"], speaker) };
|
|
86
|
+
|
|
87
|
+
return this.updateStateAndViewFast({ speaker, speakerInfo });
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
onStateChanged = async () => {
|
|
91
|
+
this.isStateChangeInProcess = true;
|
|
92
|
+
await Promise.all([
|
|
93
|
+
this.emit(this.EVENTS.INTERFACE.SHOW_CHANGED, { isForce: true }),
|
|
94
|
+
this.emit(this.EVENTS.INTERFACE.VIEW_CHANGED, { isForce: true }),
|
|
95
|
+
this.emit(this.EVENTS.INTERFACE.VISIBLE_CHANGED, { isForce: true }),
|
|
96
|
+
]);
|
|
97
|
+
this.isStateChangeInProcess = false;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
onVisibleChanged = async ({ isForce = false }: InterfaceForcePayload = {}) => {
|
|
101
|
+
const { isVisible = false } = this.globalState.interface;
|
|
102
|
+
|
|
103
|
+
if (this.state.isVisible === isVisible) return;
|
|
104
|
+
|
|
105
|
+
const args = { key: `${this.name}-unvisible`, controls: this.CONTROLS_UNVISIBLE, index: this.CONTROLS_INDEX + 500 } satisfies ControlsPushPayload &
|
|
106
|
+
ControlsPopPayload;
|
|
107
|
+
await this.emit(isVisible ? this.EVENTS.CONTROLS.POP : this.EVENTS.CONTROLS.PUSH, args);
|
|
108
|
+
await this.updateStateAndView({ isVisible }, isForce, !isForce);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
getDefaultState = (): InterfacePluginState => ({
|
|
112
|
+
tokens: [],
|
|
113
|
+
wall: [],
|
|
114
|
+
uid: "",
|
|
115
|
+
tokensVisible: 0,
|
|
116
|
+
speaker: "",
|
|
117
|
+
speakerInfo: {},
|
|
118
|
+
isShow: false,
|
|
119
|
+
isVisible: false,
|
|
120
|
+
isForce: false,
|
|
121
|
+
view: "",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ModuleCore, type ModuleGlobalStateRegistry } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { InterfaceModuleState } from "@vnejs/contracts.controllers.scenario.interface";
|
|
4
|
+
|
|
5
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
6
|
+
|
|
7
|
+
export class Interface extends ModuleCore<
|
|
8
|
+
InterfacePluginEvents,
|
|
9
|
+
InterfacePluginConstants,
|
|
10
|
+
InterfacePluginSettings,
|
|
11
|
+
InterfacePluginParams,
|
|
12
|
+
InterfaceModuleState
|
|
13
|
+
> {
|
|
14
|
+
name = "interface";
|
|
15
|
+
|
|
16
|
+
subscribe = () => {
|
|
17
|
+
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
18
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
onStateSet = (payload: ModuleGlobalStateRegistry) => {
|
|
22
|
+
const moduleState = this.getStateSlice(payload);
|
|
23
|
+
|
|
24
|
+
return this.setNewState(moduleState.view, moduleState.isVisible, moduleState.isShow);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
onStateClear = () => this.setNewState(this.PARAMS.INTERFACE.DEFAULT_VIEW, false, false);
|
|
28
|
+
|
|
29
|
+
getDefaultState = (): InterfaceModuleState => ({ view: this.PARAMS.INTERFACE.DEFAULT_VIEW, isShow: false, isVisible: false });
|
|
30
|
+
|
|
31
|
+
setNewState = (view?: string, isVisible?: boolean, isShow?: boolean) => {
|
|
32
|
+
Object.assign(this.state, { isShow, view, isVisible });
|
|
33
|
+
|
|
34
|
+
return this.emit(this.EVENTS.INTERFACE.STATE_CHANGED);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
4
|
+
|
|
5
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
6
|
+
|
|
7
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
8
|
+
|
|
9
|
+
export class InterfaceScenario extends ModuleCore<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams> {
|
|
10
|
+
name = "interface.scenario";
|
|
11
|
+
|
|
12
|
+
execName = "interface";
|
|
13
|
+
|
|
14
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.execName, handler: this.onLineExec });
|
|
15
|
+
|
|
16
|
+
onLineExec = async ({ line = "" }: LineExecHandlerArg = {}) => {
|
|
17
|
+
const isForce = this.shared.viewForceAnimationSources.isNotEmpty();
|
|
18
|
+
|
|
19
|
+
const [action = "", execArg = ""] = tokenizeExecLine(line).map(String);
|
|
20
|
+
|
|
21
|
+
if (action === this.CONST.INTERFACE.EXEC_ACTIONS.SHOW) await this.emit(this.EVENTS.INTERFACE.SHOW, { isForce });
|
|
22
|
+
if (action === this.CONST.INTERFACE.EXEC_ACTIONS.HIDE) await this.emit(this.EVENTS.INTERFACE.HIDE, { isForce });
|
|
23
|
+
if (action === this.CONST.INTERFACE.EXEC_ACTIONS.VIEW) await this.emit(this.EVENTS.INTERFACE.VIEW, { view: execArg, isForce });
|
|
24
|
+
|
|
25
|
+
this.emit(this.EVENTS.SCENARIO.NEXT);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
4
|
+
import type { InterfacePluginState } from "../types.js";
|
|
5
|
+
|
|
6
|
+
import { render } from "../view/index.js";
|
|
7
|
+
export class InterfaceView extends ModuleView<
|
|
8
|
+
InterfacePluginEvents,
|
|
9
|
+
InterfacePluginConstants,
|
|
10
|
+
InterfacePluginSettings,
|
|
11
|
+
InterfacePluginParams,
|
|
12
|
+
InterfacePluginState
|
|
13
|
+
> {
|
|
14
|
+
name = "interface.view";
|
|
15
|
+
|
|
16
|
+
EVENT_UPDATE_VIEW = this.EVENTS.INTERFACE.VIEW_UPDATE;
|
|
17
|
+
|
|
18
|
+
LOC_LABEL = this.PARAMS.INTERFACE.LOC_LABEL;
|
|
19
|
+
|
|
20
|
+
TRANSITION = this.PARAMS.INTERFACE.TRANSITION;
|
|
21
|
+
|
|
22
|
+
renderFunc = render;
|
|
23
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { InterfaceControllerAccept } from "../modules/controller.accept.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, createInterfaceTestModule, INTERACT_EVENTS, PARAMS, registerInterfacePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("InterfaceControllerAccept", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerInterfacePluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("VIEW_SHOW pushes ACCEPT and INTERACT controls", async () => {
|
|
15
|
+
const { module, observer } = createInterfaceTestModule(InterfaceControllerAccept);
|
|
16
|
+
const accept = module as InterfaceControllerAccept;
|
|
17
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
18
|
+
|
|
19
|
+
await observer.emit(SUBSCRIBE_EVENTS.VIEW_SHOW);
|
|
20
|
+
|
|
21
|
+
expect(push).toHaveBeenCalledExactlyOnceWith(
|
|
22
|
+
expect.objectContaining({
|
|
23
|
+
key: "interface.controller.accept",
|
|
24
|
+
checkNext: true,
|
|
25
|
+
index: accept.PARAMS.INTERFACE.ZINDEX + 1,
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.ACCEPT);
|
|
29
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.INTERACT);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("VIEW_HIDE pops ACCEPT controls", async () => {
|
|
33
|
+
const { observer } = createInterfaceTestModule(InterfaceControllerAccept);
|
|
34
|
+
const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
|
|
35
|
+
|
|
36
|
+
await observer.emit(SUBSCRIBE_EVENTS.VIEW_SHOW);
|
|
37
|
+
await observer.emit(SUBSCRIBE_EVENTS.VIEW_HIDE);
|
|
38
|
+
|
|
39
|
+
expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "interface.controller.accept" });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("ACCEPT and INTERACT emit INTERFACE.INTERACT", async () => {
|
|
43
|
+
const { module, observer } = createInterfaceTestModule(InterfaceControllerAccept);
|
|
44
|
+
const accept = module as InterfaceControllerAccept;
|
|
45
|
+
const interact = spyEvent(observer, SUBSCRIBE_EVENTS.INTERACT);
|
|
46
|
+
|
|
47
|
+
accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.ACCEPT]();
|
|
48
|
+
accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.INTERACT]();
|
|
49
|
+
await Promise.resolve();
|
|
50
|
+
await Promise.resolve();
|
|
51
|
+
|
|
52
|
+
expect(interact).toHaveBeenCalledTimes(2);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("INTERACT emits VISIBLE when interface is hidden", async () => {
|
|
56
|
+
const { observer } = createInterfaceTestModule(InterfaceControllerAccept);
|
|
57
|
+
const visible = spyEvent(observer, SUBSCRIBE_EVENTS.VISIBLE);
|
|
58
|
+
const emit = spyEvent(observer, INTERACT_EVENTS.EMIT);
|
|
59
|
+
|
|
60
|
+
await observer.emit(SUBSCRIBE_EVENTS.INTERACT);
|
|
61
|
+
|
|
62
|
+
expect(visible).toHaveBeenCalledOnce();
|
|
63
|
+
expect(emit).not.toHaveBeenCalled();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("INTERACT emits INTERACT.EMIT when interface is visible", async () => {
|
|
67
|
+
const { observer } = createInterfaceTestModule(InterfaceControllerAccept, {
|
|
68
|
+
state: { interface: { view: PARAMS.DEFAULT_VIEW, isShow: true, isVisible: true } },
|
|
69
|
+
});
|
|
70
|
+
const visible = spyEvent(observer, SUBSCRIBE_EVENTS.VISIBLE);
|
|
71
|
+
const emit = spyEvent(observer, INTERACT_EVENTS.EMIT);
|
|
72
|
+
|
|
73
|
+
await observer.emit(SUBSCRIBE_EVENTS.INTERACT);
|
|
74
|
+
|
|
75
|
+
expect(emit).toHaveBeenCalledOnce();
|
|
76
|
+
expect(visible).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { InterfaceActions } from "../modules/actions.js";
|
|
6
|
+
|
|
7
|
+
import { createInterfaceTestModule, registerInterfacePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("InterfaceActions", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerInterfacePluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("VISIBLE toggles isVisible", async () => {
|
|
15
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActions);
|
|
16
|
+
const visibleChanged = spyEvent(observer, SUBSCRIBE_EVENTS.VISIBLE_CHANGED);
|
|
17
|
+
|
|
18
|
+
await (module as InterfaceActions).onVisible();
|
|
19
|
+
|
|
20
|
+
expect(module.globalState.interface.isVisible).toBe(true);
|
|
21
|
+
expect(visibleChanged).toHaveBeenCalledWith({ isForce: false });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("TEXT_HIDE emits empty TEXT_CHANGED", async () => {
|
|
25
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActions);
|
|
26
|
+
const textChanged = spyEvent(observer, SUBSCRIBE_EVENTS.TEXT_CHANGED);
|
|
27
|
+
|
|
28
|
+
await (module as InterfaceActions).onTextHide();
|
|
29
|
+
|
|
30
|
+
expect(textChanged).toHaveBeenCalledOnce();
|
|
31
|
+
expect(textChanged).toHaveBeenCalledWith({ tokens: [], uid: "", tokensVisible: 0 });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("VIEW writes view and emits VIEW_CHANGED", async () => {
|
|
35
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActions);
|
|
36
|
+
const viewChanged = spyEvent(observer, SUBSCRIBE_EVENTS.VIEW_CHANGED);
|
|
37
|
+
|
|
38
|
+
await (module as InterfaceActions).onView({ view: "wall" });
|
|
39
|
+
|
|
40
|
+
expect(module.globalState.interface.view).toBe("wall");
|
|
41
|
+
expect(viewChanged).toHaveBeenCalledOnce();
|
|
42
|
+
expect(viewChanged).toHaveBeenCalledWith({ isForce: false });
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { InterfaceController } from "../modules/controller.js";
|
|
6
|
+
|
|
7
|
+
import { createInterfaceTestModule, PARAMS, registerInterfacePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("InterfaceController", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerInterfacePluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("init emits default view", () => {
|
|
15
|
+
const { module, observer } = createInterfaceTestModule(InterfaceController, { subscribe: false });
|
|
16
|
+
const view = spyEvent(observer, SUBSCRIBE_EVENTS.VIEW);
|
|
17
|
+
|
|
18
|
+
(module as InterfaceController).init();
|
|
19
|
+
|
|
20
|
+
expect(view).toHaveBeenCalledExactlyOnceWith({ view: PARAMS.DEFAULT_VIEW, isForce: true });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("onShowChanged emits VIEW_SHOW when interface becomes visible", async () => {
|
|
24
|
+
const { module, observer } = createInterfaceTestModule(InterfaceController, {
|
|
25
|
+
state: { interface: { view: "line", isShow: true, isVisible: false } },
|
|
26
|
+
});
|
|
27
|
+
const viewShow = spyEvent(observer, SUBSCRIBE_EVENTS.VIEW_SHOW);
|
|
28
|
+
|
|
29
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW_CHANGED, {});
|
|
30
|
+
|
|
31
|
+
expect(viewShow).toHaveBeenCalledOnce();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("onTextChanged updates controller tokens", async () => {
|
|
35
|
+
const { module, observer } = createInterfaceTestModule(InterfaceController);
|
|
36
|
+
|
|
37
|
+
await observer.emit(SUBSCRIBE_EVENTS.TEXT_CHANGED, { tokens: ["Hello"], uid: "1", tokensVisible: 1 });
|
|
38
|
+
|
|
39
|
+
expect((module as InterfaceController).state.tokens).toEqual(["Hello"]);
|
|
40
|
+
expect((module as InterfaceController).state.uid).toBe("1");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { Interface } from "../modules/interface.js";
|
|
4
|
+
|
|
5
|
+
import { createInterfaceTestModule, PARAMS, registerInterfacePluginVne } from "./setup.js";
|
|
6
|
+
|
|
7
|
+
describe("Interface", () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
registerInterfacePluginVne();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("onStateClear resets to default view", async () => {
|
|
13
|
+
const { module } = createInterfaceTestModule(Interface);
|
|
14
|
+
|
|
15
|
+
(module as Interface).state = { view: "wall", isShow: true, isVisible: true };
|
|
16
|
+
await (module as Interface).onStateClear();
|
|
17
|
+
|
|
18
|
+
expect((module as Interface).state).toEqual({ view: PARAMS.DEFAULT_VIEW, isShow: false, isVisible: false });
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { InterfaceScenario } from "../modules/scenario.js";
|
|
6
|
+
|
|
7
|
+
import { createInterfaceTestModule, registerInterfacePluginVne, SCENARIO_EVENTS, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("InterfaceScenario", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerInterfacePluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("init registers scenario line exec handler", async () => {
|
|
15
|
+
const { module, observer } = createInterfaceTestModule(InterfaceScenario, { subscribe: false });
|
|
16
|
+
const lineExecReg = spyEvent(observer, SCENARIO_EVENTS.LINE_EXEC_REG);
|
|
17
|
+
|
|
18
|
+
await (module as InterfaceScenario).init();
|
|
19
|
+
|
|
20
|
+
expect(lineExecReg).toHaveBeenCalledOnce();
|
|
21
|
+
expect(lineExecReg).toHaveBeenCalledWith({ module: "interface", handler: (module as InterfaceScenario).onLineExec });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("onLineExec show emits SHOW", async () => {
|
|
25
|
+
const { module, observer } = createInterfaceTestModule(InterfaceScenario);
|
|
26
|
+
const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
|
|
27
|
+
|
|
28
|
+
await (module as InterfaceScenario).onLineExec({ line: "show" });
|
|
29
|
+
|
|
30
|
+
expect(show).toHaveBeenCalledOnce();
|
|
31
|
+
expect(show).toHaveBeenCalledWith({ isForce: false });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("onLineExec hide emits HIDE", async () => {
|
|
35
|
+
const { module, observer } = createInterfaceTestModule(InterfaceScenario);
|
|
36
|
+
const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
|
|
37
|
+
|
|
38
|
+
await (module as InterfaceScenario).onLineExec({ line: "hide" });
|
|
39
|
+
|
|
40
|
+
expect(hide).toHaveBeenCalledOnce();
|
|
41
|
+
expect(hide).toHaveBeenCalledWith({ isForce: false });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("onLineExec view emits VIEW", async () => {
|
|
45
|
+
const { module, observer } = createInterfaceTestModule(InterfaceScenario);
|
|
46
|
+
const view = spyEvent(observer, SUBSCRIBE_EVENTS.VIEW);
|
|
47
|
+
|
|
48
|
+
await (module as InterfaceScenario).onLineExec({ line: "view wall" });
|
|
49
|
+
|
|
50
|
+
expect(view).toHaveBeenCalledOnce();
|
|
51
|
+
expect(view).toHaveBeenCalledWith({ view: "wall", isForce: false });
|
|
52
|
+
});
|
|
53
|
+
});
|