@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/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.scenario.interface";
|
|
2
|
+
import "@vnejs/contracts.text.meet";
|
|
3
|
+
import { regPlugin } from "@vnejs/registry";
|
|
4
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.scenario.interface";
|
|
5
|
+
import { InterfaceActions } from "./modules/actions.js";
|
|
6
|
+
import { InterfaceActionsShow } from "./modules/actions.show.js";
|
|
7
|
+
import { InterfaceControllerAccept } from "./modules/controller.accept.js";
|
|
8
|
+
import { InterfaceController } from "./modules/controller.js";
|
|
9
|
+
import { Interface } from "./modules/interface.js";
|
|
10
|
+
import { InterfaceScenario } from "./modules/scenario.js";
|
|
11
|
+
import { InterfaceView } from "./modules/view.js";
|
|
12
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
13
|
+
InterfaceController,
|
|
14
|
+
InterfaceControllerAccept,
|
|
15
|
+
Interface,
|
|
16
|
+
InterfaceActions,
|
|
17
|
+
InterfaceActionsShow,
|
|
18
|
+
InterfaceScenario,
|
|
19
|
+
InterfaceView,
|
|
20
|
+
]);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import type { InterfaceForcePayload, InterfaceViewPayload } from "@vnejs/contracts.controllers.scenario.interface";
|
|
3
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
4
|
+
export declare class InterfaceActions extends ModuleCore<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
subscribe: () => void;
|
|
7
|
+
onVisible: ({ isForce }?: InterfaceForcePayload) => Promise<import("@vnejs/registry").EmitResults<"vne:interface:visible_changed">> | undefined;
|
|
8
|
+
onTextHide: () => Promise<import("@vnejs/registry").EmitResults<"vne:interface:text_changed">> | undefined;
|
|
9
|
+
onView: ({ view, isForce }?: InterfaceViewPayload) => Promise<void>;
|
|
10
|
+
setVisible: (isVisible: boolean, isForce?: boolean) => Promise<import("@vnejs/registry").EmitResults<"vne:interface:visible_changed">> | undefined;
|
|
11
|
+
setView: (view?: string, isForce?: boolean) => Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
export class InterfaceActions extends ModuleCore {
|
|
3
|
+
name = "interface.actions";
|
|
4
|
+
subscribe = () => {
|
|
5
|
+
this.on(this.EVENTS.INTERFACE.VISIBLE, this.onVisible);
|
|
6
|
+
this.on(this.EVENTS.INTERFACE.TEXT_HIDE, this.onTextHide);
|
|
7
|
+
this.on(this.EVENTS.INTERFACE.VIEW, this.onView);
|
|
8
|
+
};
|
|
9
|
+
onVisible = ({ isForce = false } = {}) => this.setVisible(!this.globalState.interface.isVisible, isForce);
|
|
10
|
+
onTextHide = () => this.emit(this.EVENTS.INTERFACE.TEXT_CHANGED, { tokens: [], uid: "", tokensVisible: 0 });
|
|
11
|
+
onView = ({ view, isForce = false } = {}) => this.setView(view, isForce);
|
|
12
|
+
setVisible = (isVisible, isForce = false) => {
|
|
13
|
+
this.globalState.interface.isVisible = isVisible;
|
|
14
|
+
return this.emit(this.EVENTS.INTERFACE.VISIBLE_CHANGED, { isForce });
|
|
15
|
+
};
|
|
16
|
+
setView = async (view, isForce = false) => {
|
|
17
|
+
this.globalState.interface.view = view ?? "";
|
|
18
|
+
await this.emit(this.EVENTS.INTERFACE.VIEW_CHANGED, { isForce });
|
|
19
|
+
await this.waitRerender();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import type { InterfaceForcePayload } from "@vnejs/contracts.controllers.scenario.interface";
|
|
3
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
4
|
+
export declare class InterfaceActionsShow extends ModuleCore<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
isInShowOrHideProcess: boolean;
|
|
7
|
+
subscribe: () => void;
|
|
8
|
+
onShowGate: () => boolean;
|
|
9
|
+
setInProcessTrue: () => void;
|
|
10
|
+
onShow: ({ isForce }?: InterfaceForcePayload) => Promise<import("@vnejs/registry").EmitResults<"vne:interface:show_changed"> | undefined>;
|
|
11
|
+
setInProcessFalse: () => void;
|
|
12
|
+
onHideGate: () => boolean;
|
|
13
|
+
onHide: ({ isForce }?: InterfaceForcePayload) => Promise<import("@vnejs/registry").EmitResults<"vne:interface:show_changed"> | undefined>;
|
|
14
|
+
setShow: (isShow: boolean, isForce?: boolean) => Promise<import("@vnejs/registry").EmitResults<"vne:interface:show_changed"> | undefined>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
export class InterfaceActionsShow extends ModuleCore {
|
|
3
|
+
name = "interface.actions.show";
|
|
4
|
+
isInShowOrHideProcess = false;
|
|
5
|
+
subscribe = () => {
|
|
6
|
+
const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
|
|
7
|
+
this.on(this.EVENTS.INTERFACE.SHOW, this.onShowGate, { priority: SHOW.GATE, breakFollowing: true, filterFromResult: true });
|
|
8
|
+
this.on(this.EVENTS.INTERFACE.SHOW, this.setInProcessTrue, { priority: SHOW.GATE + 1 });
|
|
9
|
+
this.on(this.EVENTS.INTERFACE.SHOW, this.onShow);
|
|
10
|
+
this.on(this.EVENTS.INTERFACE.SHOW, this.setInProcessFalse, { priority: SHOW.AFTER + 1 });
|
|
11
|
+
this.on(this.EVENTS.INTERFACE.HIDE, this.onHideGate, { priority: HIDE.GATE, breakFollowing: true, filterFromResult: true });
|
|
12
|
+
this.on(this.EVENTS.INTERFACE.HIDE, this.setInProcessTrue, { priority: HIDE.GATE + 1 });
|
|
13
|
+
this.on(this.EVENTS.INTERFACE.HIDE, this.onHide);
|
|
14
|
+
this.on(this.EVENTS.INTERFACE.HIDE, this.setInProcessFalse, { priority: HIDE.CLEANUP + 1 });
|
|
15
|
+
};
|
|
16
|
+
onShowGate = () => this.globalState.interface.isShow || this.isInShowOrHideProcess;
|
|
17
|
+
setInProcessTrue = () => {
|
|
18
|
+
this.isInShowOrHideProcess = true;
|
|
19
|
+
};
|
|
20
|
+
onShow = ({ isForce = false } = {}) => this.setShow(true, isForce);
|
|
21
|
+
setInProcessFalse = () => {
|
|
22
|
+
this.isInShowOrHideProcess = false;
|
|
23
|
+
};
|
|
24
|
+
onHideGate = () => !this.globalState.interface.isShow || this.isInShowOrHideProcess;
|
|
25
|
+
onHide = ({ isForce = false } = {}) => this.setShow(false, isForce);
|
|
26
|
+
setShow = async (isShow, isForce = false) => {
|
|
27
|
+
this.globalState.interface.isShow = isShow;
|
|
28
|
+
if (isShow && !this.globalState.interface.isVisible)
|
|
29
|
+
await this.emit(this.EVENTS.INTERFACE.VISIBLE, { isForce });
|
|
30
|
+
return this.emit(this.EVENTS.INTERFACE.SHOW_CHANGED, { isForce });
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
3
|
+
export declare class InterfaceControllerAccept extends ModuleControllerAccept<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams> {
|
|
4
|
+
name: string;
|
|
5
|
+
EVENT_SHOW: "vne:interface:view_show";
|
|
6
|
+
EVENT_HIDE: "vne:interface:view_hide";
|
|
7
|
+
EVENT_ACCEPT: "vne:interface:interact";
|
|
8
|
+
CONTROLS_ZINDEX: number;
|
|
9
|
+
onAccept: () => undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
export class InterfaceControllerAccept extends ModuleControllerAccept {
|
|
3
|
+
name = "interface.controller.accept";
|
|
4
|
+
EVENT_SHOW = this.EVENTS.INTERFACE.VIEW_SHOW;
|
|
5
|
+
EVENT_HIDE = this.EVENTS.INTERFACE.VIEW_HIDE;
|
|
6
|
+
EVENT_ACCEPT = this.EVENTS.INTERFACE.INTERACT;
|
|
7
|
+
CONTROLS_ZINDEX = this.PARAMS.INTERFACE.ZINDEX;
|
|
8
|
+
onAccept = () => void this.emit(this.globalState.interface.isVisible ? this.EVENTS.INTERACT.EMIT : this.EVENTS.INTERFACE.VISIBLE);
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
import type { InterfaceForcePayload, InterfaceSpeakerChangedPayload, InterfaceTextChangedPayload, InterfaceWallChangedPayload } from "@vnejs/contracts.controllers.scenario.interface";
|
|
3
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
4
|
+
import type { InterfacePluginState } from "../types.js";
|
|
5
|
+
export declare class InterfaceController extends ModuleController<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams, InterfacePluginState> {
|
|
6
|
+
name: string;
|
|
7
|
+
EVENT_UPDATE_VIEW: "vne:interface:view_update";
|
|
8
|
+
EVENT_UPDATE_STATE: "vne:interface:update_state";
|
|
9
|
+
EVENT_UPDATE_FAST: "vne:interface:update_fast";
|
|
10
|
+
EVENT_UPDATE_FORCE: "vne:interface:update_force";
|
|
11
|
+
EVENT_SHOW: "vne:interface:view_show";
|
|
12
|
+
EVENT_HIDE: "vne:interface:view_hide";
|
|
13
|
+
SHOULD_CLEAR_STATE_ON_CLEANUP: boolean;
|
|
14
|
+
CONTROLS: {};
|
|
15
|
+
CONTROLS_UNVISIBLE: {};
|
|
16
|
+
CONTROLS_INDEX: number;
|
|
17
|
+
isStateChangeInProcess: boolean;
|
|
18
|
+
subscribe: () => void;
|
|
19
|
+
init: () => Promise<import("@vnejs/registry").EmitResults<"vne:interface:view">> | undefined;
|
|
20
|
+
onShowChanged: ({ isForce }?: InterfaceForcePayload) => Promise<import("@vnejs/registry").EmitResults<"vne:interface:view_hide" | "vne:interface:view_show">> | undefined;
|
|
21
|
+
onViewChanged: ({ isForce }?: InterfaceForcePayload) => Promise<import("@vnejs/registry").EmitResults<string>> | undefined;
|
|
22
|
+
onTextChanged: ({ tokens, uid, tokensVisible }?: InterfaceTextChangedPayload) => Promise<import("@vnejs/registry").EmitResults<string> | undefined>;
|
|
23
|
+
onWallChanged: ({ wall }?: InterfaceWallChangedPayload) => Promise<import("@vnejs/registry").EmitResults<string> | undefined>;
|
|
24
|
+
onSpeakerChanged: ({ speaker }?: InterfaceSpeakerChangedPayload) => Promise<import("@vnejs/registry").EmitResults<string> | undefined>;
|
|
25
|
+
onStateChanged: () => Promise<void>;
|
|
26
|
+
onVisibleChanged: ({ isForce }?: InterfaceForcePayload) => Promise<void>;
|
|
27
|
+
getDefaultState: () => InterfacePluginState;
|
|
28
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
import { getTextSpeakerInfo } from "@vnejs/contracts.text";
|
|
3
|
+
export class InterfaceController extends ModuleController {
|
|
4
|
+
name = "interface.controller";
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.INTERFACE.VIEW_UPDATE;
|
|
6
|
+
EVENT_UPDATE_STATE = this.EVENTS.INTERFACE.UPDATE_STATE;
|
|
7
|
+
EVENT_UPDATE_FAST = this.EVENTS.INTERFACE.UPDATE_FAST;
|
|
8
|
+
EVENT_UPDATE_FORCE = this.EVENTS.INTERFACE.UPDATE_FORCE;
|
|
9
|
+
EVENT_SHOW = this.EVENTS.INTERFACE.VIEW_SHOW;
|
|
10
|
+
EVENT_HIDE = this.EVENTS.INTERFACE.VIEW_HIDE;
|
|
11
|
+
SHOULD_CLEAR_STATE_ON_CLEANUP = false;
|
|
12
|
+
CONTROLS = {};
|
|
13
|
+
CONTROLS_UNVISIBLE = {};
|
|
14
|
+
CONTROLS_INDEX = this.PARAMS.INTERFACE.ZINDEX;
|
|
15
|
+
isStateChangeInProcess = false;
|
|
16
|
+
subscribe = () => {
|
|
17
|
+
super.subscribe();
|
|
18
|
+
this.on(this.EVENTS.INTERFACE.SHOW_CHANGED, this.onShowChanged);
|
|
19
|
+
this.on(this.EVENTS.INTERFACE.VIEW_CHANGED, this.onViewChanged);
|
|
20
|
+
this.on(this.EVENTS.INTERFACE.TEXT_CHANGED, this.onTextChanged);
|
|
21
|
+
this.on(this.EVENTS.INTERFACE.WALL_CHANGED, this.onWallChanged);
|
|
22
|
+
this.on(this.EVENTS.INTERFACE.SPEAKER_CHANGED, this.onSpeakerChanged);
|
|
23
|
+
this.on(this.EVENTS.INTERFACE.STATE_CHANGED, this.onStateChanged);
|
|
24
|
+
this.on(this.EVENTS.INTERFACE.VISIBLE_CHANGED, this.onVisibleChanged);
|
|
25
|
+
};
|
|
26
|
+
init = () => this.emit(this.EVENTS.INTERFACE.VIEW, { view: this.PARAMS.INTERFACE.DEFAULT_VIEW, isForce: true });
|
|
27
|
+
onShowChanged = ({ isForce = false } = {}) => {
|
|
28
|
+
const { isShow = false } = this.globalState.interface;
|
|
29
|
+
const event = isShow ? this.EVENTS.INTERFACE.VIEW_SHOW : this.EVENTS.INTERFACE.VIEW_HIDE;
|
|
30
|
+
if (this.state.isShow !== isShow)
|
|
31
|
+
return this.emit(event, { isForce });
|
|
32
|
+
};
|
|
33
|
+
onViewChanged = ({ isForce = false } = {}) => {
|
|
34
|
+
const { view = "" } = this.globalState.interface;
|
|
35
|
+
// Do not mark as fast: wait for TRANSITION so React applies isViewActive before the next scenario line (text).
|
|
36
|
+
// Otherwise useTokensHook can receive tokens while the target view is still inactive and never show them.
|
|
37
|
+
if (this.state.view !== view)
|
|
38
|
+
return this.updateStateAndView({ view }, isForce, false);
|
|
39
|
+
};
|
|
40
|
+
onTextChanged = async ({ tokens = [], uid = "", tokensVisible = 0 } = {}) => {
|
|
41
|
+
while (this.isStateChangeInProcess)
|
|
42
|
+
await this.waitRerender();
|
|
43
|
+
return this.updateStateAndViewFast({ tokens, uid, tokensVisible });
|
|
44
|
+
};
|
|
45
|
+
onWallChanged = async ({ wall = [] } = {}) => {
|
|
46
|
+
while (this.isStateChangeInProcess)
|
|
47
|
+
await this.waitRerender();
|
|
48
|
+
return this.updateStateAndViewFast({ wall });
|
|
49
|
+
};
|
|
50
|
+
onSpeakerChanged = async ({ speaker = "" } = {}) => {
|
|
51
|
+
while (this.isStateChangeInProcess)
|
|
52
|
+
await this.waitRerender();
|
|
53
|
+
const speakerInfo = { ...getTextSpeakerInfo(this.globalState["text.speaker"], speaker) };
|
|
54
|
+
return this.updateStateAndViewFast({ speaker, speakerInfo });
|
|
55
|
+
};
|
|
56
|
+
onStateChanged = async () => {
|
|
57
|
+
this.isStateChangeInProcess = true;
|
|
58
|
+
await Promise.all([
|
|
59
|
+
this.emit(this.EVENTS.INTERFACE.SHOW_CHANGED, { isForce: true }),
|
|
60
|
+
this.emit(this.EVENTS.INTERFACE.VIEW_CHANGED, { isForce: true }),
|
|
61
|
+
this.emit(this.EVENTS.INTERFACE.VISIBLE_CHANGED, { isForce: true }),
|
|
62
|
+
]);
|
|
63
|
+
this.isStateChangeInProcess = false;
|
|
64
|
+
};
|
|
65
|
+
onVisibleChanged = async ({ isForce = false } = {}) => {
|
|
66
|
+
const { isVisible = false } = this.globalState.interface;
|
|
67
|
+
if (this.state.isVisible === isVisible)
|
|
68
|
+
return;
|
|
69
|
+
const args = { key: `${this.name}-unvisible`, controls: this.CONTROLS_UNVISIBLE, index: this.CONTROLS_INDEX + 500 };
|
|
70
|
+
await this.emit(isVisible ? this.EVENTS.CONTROLS.POP : this.EVENTS.CONTROLS.PUSH, args);
|
|
71
|
+
await this.updateStateAndView({ isVisible }, isForce, !isForce);
|
|
72
|
+
};
|
|
73
|
+
getDefaultState = () => ({
|
|
74
|
+
tokens: [],
|
|
75
|
+
wall: [],
|
|
76
|
+
uid: "",
|
|
77
|
+
tokensVisible: 0,
|
|
78
|
+
speaker: "",
|
|
79
|
+
speakerInfo: {},
|
|
80
|
+
isShow: false,
|
|
81
|
+
isVisible: false,
|
|
82
|
+
isForce: false,
|
|
83
|
+
view: "",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModuleCore, type ModuleGlobalStateRegistry } from "@vnejs/module.core";
|
|
2
|
+
import type { InterfaceModuleState } from "@vnejs/contracts.controllers.scenario.interface";
|
|
3
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
4
|
+
export declare class Interface extends ModuleCore<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams, InterfaceModuleState> {
|
|
5
|
+
name: string;
|
|
6
|
+
subscribe: () => void;
|
|
7
|
+
onStateSet: (payload: ModuleGlobalStateRegistry) => Promise<import("@vnejs/registry").EmitResults<"vne:interface:state_changed">> | undefined;
|
|
8
|
+
onStateClear: () => Promise<import("@vnejs/registry").EmitResults<"vne:interface:state_changed">> | undefined;
|
|
9
|
+
getDefaultState: () => InterfaceModuleState;
|
|
10
|
+
setNewState: (view?: string, isVisible?: boolean, isShow?: boolean) => Promise<import("@vnejs/registry").EmitResults<"vne:interface:state_changed">> | undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
export class Interface extends ModuleCore {
|
|
3
|
+
name = "interface";
|
|
4
|
+
subscribe = () => {
|
|
5
|
+
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
6
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
7
|
+
};
|
|
8
|
+
onStateSet = (payload) => {
|
|
9
|
+
const moduleState = this.getStateSlice(payload);
|
|
10
|
+
return this.setNewState(moduleState.view, moduleState.isVisible, moduleState.isShow);
|
|
11
|
+
};
|
|
12
|
+
onStateClear = () => this.setNewState(this.PARAMS.INTERFACE.DEFAULT_VIEW, false, false);
|
|
13
|
+
getDefaultState = () => ({ view: this.PARAMS.INTERFACE.DEFAULT_VIEW, isShow: false, isVisible: false });
|
|
14
|
+
setNewState = (view, isVisible, isShow) => {
|
|
15
|
+
Object.assign(this.state, { isShow, view, isVisible });
|
|
16
|
+
return this.emit(this.EVENTS.INTERFACE.STATE_CHANGED);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
3
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
4
|
+
export declare class InterfaceScenario extends ModuleCore<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
execName: string;
|
|
7
|
+
init: () => Promise<import("@vnejs/registry").EmitResults<"vne:scenario:line_exec_reg">> | undefined;
|
|
8
|
+
onLineExec: ({ line }?: LineExecHandlerArg) => Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
3
|
+
export class InterfaceScenario extends ModuleCore {
|
|
4
|
+
name = "interface.scenario";
|
|
5
|
+
execName = "interface";
|
|
6
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.execName, handler: this.onLineExec });
|
|
7
|
+
onLineExec = async ({ line = "" } = {}) => {
|
|
8
|
+
const isForce = this.shared.viewForceAnimationSources.isNotEmpty();
|
|
9
|
+
const [action = "", execArg = ""] = tokenizeExecLine(line).map(String);
|
|
10
|
+
if (action === this.CONST.INTERFACE.EXEC_ACTIONS.SHOW)
|
|
11
|
+
await this.emit(this.EVENTS.INTERFACE.SHOW, { isForce });
|
|
12
|
+
if (action === this.CONST.INTERFACE.EXEC_ACTIONS.HIDE)
|
|
13
|
+
await this.emit(this.EVENTS.INTERFACE.HIDE, { isForce });
|
|
14
|
+
if (action === this.CONST.INTERFACE.EXEC_ACTIONS.VIEW)
|
|
15
|
+
await this.emit(this.EVENTS.INTERFACE.VIEW, { view: execArg, isForce });
|
|
16
|
+
this.emit(this.EVENTS.SCENARIO.NEXT);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
3
|
+
import type { InterfacePluginState } from "../types.js";
|
|
4
|
+
export declare class InterfaceView extends ModuleView<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams, InterfacePluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
EVENT_UPDATE_VIEW: "vne:interface:view_update";
|
|
7
|
+
LOC_LABEL: string;
|
|
8
|
+
TRANSITION: number;
|
|
9
|
+
renderFunc: import("@vnejs/module.components").ViewRenderFunc<InterfacePluginState>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import { render } from "../view/index.js";
|
|
3
|
+
export class InterfaceView extends ModuleView {
|
|
4
|
+
name = "interface.view";
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.INTERFACE.VIEW_UPDATE;
|
|
6
|
+
LOC_LABEL = this.PARAMS.INTERFACE.LOC_LABEL;
|
|
7
|
+
TRANSITION = this.PARAMS.INTERFACE.TRANSITION;
|
|
8
|
+
renderFunc = render;
|
|
9
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings, ModuleControllerState } from "@vnejs/module.components";
|
|
2
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
3
|
+
import type { Constants, InterfaceModuleState, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.scenario.interface";
|
|
4
|
+
import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
|
|
5
|
+
import type { PluginName as InteractPluginName, SubscribeEvents as InteractSubscribeEvents } from "@vnejs/contracts.core.interact";
|
|
6
|
+
import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
|
|
7
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
|
|
8
|
+
import type { PluginName as TextPluginName, Params as TextParams } from "@vnejs/contracts.text";
|
|
9
|
+
import type { InterfaceRuntimeState } from "./utils/interface.js";
|
|
10
|
+
export type InterfacePluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents> & Record<InteractPluginName, InteractSubscribeEvents>;
|
|
11
|
+
export type InterfacePluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants> & Record<PluginName, Constants>;
|
|
12
|
+
export type InterfacePluginSettings = ModuleComponentsSettings;
|
|
13
|
+
export type InterfacePluginParams = ModuleComponentsParams & Record<PluginName, Params> & Record<TextPluginName, TextParams>;
|
|
14
|
+
export type InterfacePluginState = ModuleControllerState & InterfaceModuleState & InterfaceRuntimeState & {
|
|
15
|
+
isFast?: boolean;
|
|
16
|
+
locs?: Record<string, string>;
|
|
17
|
+
prefix?: string;
|
|
18
|
+
postfix?: string;
|
|
19
|
+
transition?: number;
|
|
20
|
+
speakerText?: string;
|
|
21
|
+
speakerName?: string;
|
|
22
|
+
speakerColor?: string;
|
|
23
|
+
color?: string;
|
|
24
|
+
opacity?: number;
|
|
25
|
+
};
|
|
26
|
+
export type InterfacePluginViewState = InterfacePluginState & {
|
|
27
|
+
isViewActive?: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type InterfaceViewProps = ReactComponentProps<InterfacePluginEvents, InterfacePluginConstants, InterfacePluginSettings, InterfacePluginParams, InterfacePluginViewState>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TextSpeakerEntry, TokenizedChar } from "@vnejs/contracts.text";
|
|
2
|
+
import type { WallElement } from "@vnejs/contracts.text.wall";
|
|
3
|
+
export type InterfaceRuntimeState = {
|
|
4
|
+
tokens: TokenizedChar[];
|
|
5
|
+
wall: WallElement[];
|
|
6
|
+
uid: string;
|
|
7
|
+
tokensVisible: number;
|
|
8
|
+
speaker: string;
|
|
9
|
+
speakerInfo: TextSpeakerEntry;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Backdrop } from "@vnejs/uis.react";
|
|
3
|
+
export const InterfaceBackdrop = ({ view = "", transition = 0, PARAMS }) => {
|
|
4
|
+
const backdrop = PARAMS.INTERFACE.VIEW_PROPS[view]?.backdrop;
|
|
5
|
+
return (_jsx(Backdrop, { ...backdrop, transition: transition }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Flex, PositionBox, SmoothText, Text } from "@vnejs/uis.react";
|
|
3
|
+
import { getVneLength } from "@vnejs/uis.utils";
|
|
4
|
+
import { useTokensHook } from "./tokens.hook.js";
|
|
5
|
+
export const InterfaceViewDialog = (props) => {
|
|
6
|
+
const { isViewActive = false, isForce = false, transition, tokensVisible = 0, tokens = [], speakerText, speakerName, speakerColor, opacity, color, uid = "", PARAMS, } = props;
|
|
7
|
+
const propsByView = PARAMS.INTERFACE.VIEW_PROPS.adv;
|
|
8
|
+
const speakerOpacity = speakerName ? 1 : 0;
|
|
9
|
+
const speakerTransition = speakerName ? transition : 0;
|
|
10
|
+
const { realTokens, realTokensVisible } = useTokensHook(isViewActive, tokens, tokensVisible, uid);
|
|
11
|
+
return (_jsx(PositionBox, { ...propsByView.position, opacity: isViewActive ? 1 : 0, transition: transition, children: _jsxs(Flex, { ...propsByView.flex, children: [_jsx(Text, { ...propsByView.speaker, text: speakerText, color: speakerColor, opacity: speakerOpacity, transition: speakerTransition }), _jsx("div", { style: {
|
|
12
|
+
height: getVneLength(6),
|
|
13
|
+
width: "calc(200% / 3)",
|
|
14
|
+
background: `linear-gradient(to right, ${speakerColor} 0%, transparent 100%)`,
|
|
15
|
+
opacity: speakerOpacity,
|
|
16
|
+
transition: `${speakerTransition}ms` || "none",
|
|
17
|
+
} }), _jsx(SmoothText, { ...propsByView.text, opacity: opacity, color: color, tokens: realTokens, tokensVisibleForce: realTokensVisible, transition: transition, isForce: isForce })] }) }));
|
|
18
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Flex, PositionBox, SmoothText } from "@vnejs/uis.react";
|
|
3
|
+
import { useTokensHook } from "./tokens.hook.js";
|
|
4
|
+
export const InterfaceViewLine = (props) => {
|
|
5
|
+
const { isViewActive = false, isForce = false, transition = 0, tokensVisible = 0, tokens = [], opacity, color, uid = "", PARAMS } = props;
|
|
6
|
+
const propsByView = PARAMS.INTERFACE.VIEW_PROPS.line;
|
|
7
|
+
const { realTokens, realTokensVisible } = useTokensHook(isViewActive, tokens, tokensVisible, uid);
|
|
8
|
+
return (_jsx(PositionBox, { ...propsByView.position, opacity: isViewActive ? 1 : 0, transition: transition, children: _jsx(Flex, { ...propsByView.flex, children: _jsx(SmoothText, { ...propsByView.text, opacity: opacity, color: color, transition: transition, isForce: isForce, tokens: realTokens, tokensVisibleForce: realTokensVisible }) }) }));
|
|
9
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Flex, PositionBox, Scrollbar, SmoothText, Text } from "@vnejs/uis.react";
|
|
3
|
+
import { useTokensHook } from "./tokens.hook.js";
|
|
4
|
+
const renderOneText = (wallElement) => (_jsxs("div", { children: [wallElement.speakerName && (_jsx(Text, { ...wallElement.propsByView.text, isInlineBlock: true, color: wallElement.speakerColor, text: `${wallElement.speakerName}:`, marginRight: 12 })), _jsx(SmoothText, { ...wallElement.propsByView.text, isNoScrollBar: true, color: wallElement.color, opacity: wallElement.opacity, transition: wallElement.transition, isForce: wallElement.isForce, tokens: wallElement.tokens, tokensVisibleForce: wallElement.tokensVisible })] }, wallElement.uid));
|
|
5
|
+
const mapWall = ({ uid = "", tokens = [], speaker = "", speakerInfo = {}, transition = 0, props, }) => {
|
|
6
|
+
const propsByView = props.PARAMS.INTERFACE.VIEW_PROPS.wall;
|
|
7
|
+
const speakersInfo = props.PARAMS.TEXT.SPEAKERS_INFO;
|
|
8
|
+
const speakerStyleInfo = speakersInfo[speaker] ?? speakersInfo[props.PARAMS.TEXT.DEFAULT_SPEAKER_NAME];
|
|
9
|
+
const { color, opacity = 1, speakerColor = "white" } = speakerStyleInfo;
|
|
10
|
+
const locs = props.locs ?? {};
|
|
11
|
+
const meet = speakerInfo.meet ?? 0;
|
|
12
|
+
const defaultSpeakerName = props.PARAMS.TEXT.DEFAULT_SPEAKER_NAME;
|
|
13
|
+
const speakerName = locs[`speaker.${speaker}.${meet}`] ??
|
|
14
|
+
locs[`speaker.${speaker}`] ??
|
|
15
|
+
speakersInfo[speaker]?.displayName ??
|
|
16
|
+
(speaker !== defaultSpeakerName ? speaker : undefined);
|
|
17
|
+
return { speakerName, speakerColor, uid, color, opacity, tokens, tokensVisible: tokens.length, transition, isForce: props.isForce, propsByView };
|
|
18
|
+
};
|
|
19
|
+
export const InterfaceViewWall = (props) => {
|
|
20
|
+
const { isViewActive = false, transition = 0, tokensVisible = 0, tokens = [], wall = [], uid = "", speakerName, speakerColor, color, opacity, isForce = false, PARAMS, } = props;
|
|
21
|
+
const propsByView = PARAMS.INTERFACE.VIEW_PROPS.wall;
|
|
22
|
+
const { realTokens, realTokensVisible } = useTokensHook(isViewActive, tokens, tokensVisible, uid);
|
|
23
|
+
const texts = [
|
|
24
|
+
...wall.map((item) => mapWall({ ...item, transition, props })),
|
|
25
|
+
{ speakerName, speakerColor, uid, color, opacity, tokens: realTokens, tokensVisible: realTokensVisible, transition, isForce, propsByView },
|
|
26
|
+
];
|
|
27
|
+
return (_jsx(PositionBox, { ...propsByView.position, opacity: isViewActive ? 1 : 0, transition: transition, children: _jsx(Scrollbar, { ...propsByView.scrollBar, children: _jsx(Flex, { ...propsByView.flex, children: texts.map(renderOneText) }) }) }));
|
|
28
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TokenizedChar } from "@vnejs/contracts.text";
|
|
2
|
+
export declare const useTokensHook: (isShow: boolean, tokens: TokenizedChar[], tokensVisible: number, uid: string) => {
|
|
3
|
+
isShowTokens: boolean;
|
|
4
|
+
realTokensVisible: number;
|
|
5
|
+
realTokens: TokenizedChar[];
|
|
6
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { flushSync, useEffect, useState } from "@vnejs/uis.react";
|
|
2
|
+
const EMPTY_TOKENS = [];
|
|
3
|
+
export const useTokensHook = (isShow, tokens, tokensVisible, uid) => {
|
|
4
|
+
const [savedUid, setSavedUid] = useState("");
|
|
5
|
+
const [tokensSync, setTokensSync] = useState([]);
|
|
6
|
+
const [tokensWrong, setTokensWrong] = useState([]);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (isShow)
|
|
9
|
+
setTokensWrong(tokens);
|
|
10
|
+
}, [isShow]);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
setTimeout(() => {
|
|
13
|
+
if (savedUid === uid) {
|
|
14
|
+
if (!isShow)
|
|
15
|
+
setTokensWrong(tokens);
|
|
16
|
+
setTokensSync(tokens);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
flushSync(() => {
|
|
20
|
+
setSavedUid(uid);
|
|
21
|
+
if (!isShow)
|
|
22
|
+
setTokensWrong(tokens);
|
|
23
|
+
setTokensSync(tokens);
|
|
24
|
+
});
|
|
25
|
+
}, 0);
|
|
26
|
+
}, [tokens]);
|
|
27
|
+
const isShowTokens = tokensSync !== tokensWrong;
|
|
28
|
+
const realTokensVisible = isShowTokens ? tokensVisible : 0;
|
|
29
|
+
const realTokens = isShowTokens ? tokensSync : EMPTY_TOKENS;
|
|
30
|
+
return { isShowTokens, realTokensVisible, realTokens };
|
|
31
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Screen, createRenderFunc, useIsForceHook, useStoreState } from "@vnejs/uis.react";
|
|
3
|
+
import { InterfaceBackdrop, InterfaceViewDialog, InterfaceViewLine, InterfaceViewWall } from "./components/index.js";
|
|
4
|
+
const Interface = (props) => {
|
|
5
|
+
const { store, onMount, emit, EVENTS, PARAMS } = props;
|
|
6
|
+
const state = useStoreState(store, onMount);
|
|
7
|
+
const { isShow = false, isVisible = false, isForce = false, tokensVisible = 0, view = "", locs = {} } = state;
|
|
8
|
+
const { speaker = "", speakerInfo = {}, tokens = [], wall = [], postfix = "", prefix = "", uid = "" } = state;
|
|
9
|
+
const isRealForce = useIsForceHook(isForce);
|
|
10
|
+
const meet = speakerInfo.meet ?? 0;
|
|
11
|
+
const speakersInfo = PARAMS.TEXT.SPEAKERS_INFO;
|
|
12
|
+
const defaultSpeakerName = PARAMS.TEXT.DEFAULT_SPEAKER_NAME;
|
|
13
|
+
const speakerName = locs[`speaker.${speaker}.${meet}`] ??
|
|
14
|
+
locs[`speaker.${speaker}`] ??
|
|
15
|
+
speakersInfo[speaker]?.displayName ??
|
|
16
|
+
(speaker !== defaultSpeakerName ? speaker : undefined);
|
|
17
|
+
const speakerText = speakerName ? `${`${locs[`prefix.${prefix}`] ?? ""} `}${speakerName}${` ${locs[`postfix.${postfix}`] ?? ""}`}` : ".";
|
|
18
|
+
const transition = isRealForce ? 0 : PARAMS.INTERFACE.TRANSITION;
|
|
19
|
+
const speakerStyleInfo = speakersInfo[speaker] ?? speakersInfo[PARAMS.TEXT.DEFAULT_SPEAKER_NAME];
|
|
20
|
+
const { color, opacity = 1, speakerColor = "white" } = speakerStyleInfo;
|
|
21
|
+
const viewProps = {
|
|
22
|
+
isShow,
|
|
23
|
+
isForce: isRealForce,
|
|
24
|
+
transition,
|
|
25
|
+
tokensVisible,
|
|
26
|
+
tokens,
|
|
27
|
+
wall,
|
|
28
|
+
uid,
|
|
29
|
+
locs,
|
|
30
|
+
speakerText,
|
|
31
|
+
speakerName,
|
|
32
|
+
speakerColor,
|
|
33
|
+
opacity,
|
|
34
|
+
color,
|
|
35
|
+
};
|
|
36
|
+
return (_jsxs(Screen, { isShow: isShow, isForce: isRealForce, isHidden: !isVisible, isDisableAutoread: false, isAllowAutoread: Boolean(isShow && isVisible), isIgnoreOnScreenshot: false, transition: transition, zIndex: PARAMS.INTERFACE.ZINDEX, onClick: () => emit(EVENTS.INTERFACE.INTERACT), children: [_jsx(InterfaceBackdrop, { view: view, transition: transition, ...props }), _jsx(InterfaceViewDialog, { view: view, isViewActive: view === "adv", ...viewProps, ...props }), _jsx(InterfaceViewLine, { view: view, isViewActive: view === "line", ...viewProps, ...props }), _jsx(InterfaceViewWall, { view: view, isViewActive: view === "wall", ...viewProps, ...props })] }));
|
|
37
|
+
};
|
|
38
|
+
export const render = createRenderFunc(Interface);
|