@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
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { SourcesSet } from "@vnejs/sources-set";
|
|
2
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubEvent, stubSilentEvent } from "@vnejs/test-utils";
|
|
3
|
+
|
|
4
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.scenario.interface";
|
|
5
|
+
import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
|
|
6
|
+
import { SUBSCRIBE_EVENTS as INTERACT_EVENTS } from "@vnejs/contracts.core.interact";
|
|
7
|
+
import { SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scenario";
|
|
8
|
+
import { SUBSCRIBE_EVENTS as TEXT_EVENTS, PLUGIN_NAME as TEXT } from "@vnejs/contracts.text";
|
|
9
|
+
|
|
10
|
+
export const registerInterfacePluginVne = () => {
|
|
11
|
+
registerCoreVne();
|
|
12
|
+
registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
|
|
13
|
+
registerVnePlugin(TEXT, { events: TEXT_EVENTS });
|
|
14
|
+
registerVnePlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS });
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const createInterfaceTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
18
|
+
ModuleClass: T,
|
|
19
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
20
|
+
) => {
|
|
21
|
+
const result = baseCreateTestModule(ModuleClass, {
|
|
22
|
+
state: {
|
|
23
|
+
interface: { view: PARAMS.DEFAULT_VIEW, isShow: false, isVisible: false },
|
|
24
|
+
text: { tokens: [], uid: "", texts: [], speaker: "" },
|
|
25
|
+
scenario: { label: "start" },
|
|
26
|
+
...(options.state ?? {}),
|
|
27
|
+
},
|
|
28
|
+
shared: {
|
|
29
|
+
viewForceAnimationSources: new SourcesSet(),
|
|
30
|
+
interfaceTextShowAllTokensOnChange: true,
|
|
31
|
+
...(options.shared ?? {}),
|
|
32
|
+
},
|
|
33
|
+
...options,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
stubEvent(result.observer, TEXT_EVENTS.REPLACE, ({ text }) => text);
|
|
37
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.VIEW_UPDATE);
|
|
38
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.VIEW_SHOW);
|
|
39
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.VIEW_HIDE);
|
|
40
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.INTERACT);
|
|
41
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW_CHANGED);
|
|
42
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.VISIBLE_CHANGED);
|
|
43
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.VISIBLE);
|
|
44
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.STATE_CHANGED);
|
|
45
|
+
stubSilentEvent(result.observer, CONTROLS_EVENTS.PUSH);
|
|
46
|
+
stubSilentEvent(result.observer, CONTROLS_EVENTS.POP);
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, SCENARIO_EVENTS, TEXT_EVENTS, CONTROLS_EVENTS, INTERACT_EVENTS };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { InterfaceActions } from "../modules/actions.js";
|
|
6
|
+
import { InterfaceActionsShow } from "../modules/actions.show.js";
|
|
7
|
+
|
|
8
|
+
import { createInterfaceTestModule, registerInterfacePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
9
|
+
|
|
10
|
+
describe("InterfaceActionsShow", () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
registerInterfacePluginVne();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("SHOW sets isShow and emits SHOW_CHANGED", async () => {
|
|
16
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActionsShow);
|
|
17
|
+
const showChanged = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW_CHANGED);
|
|
18
|
+
|
|
19
|
+
await (module as InterfaceActionsShow).onShow();
|
|
20
|
+
|
|
21
|
+
expect(module.globalState.interface.isShow).toBe(true);
|
|
22
|
+
expect(showChanged).toHaveBeenCalledOnce();
|
|
23
|
+
expect(showChanged).toHaveBeenCalledWith({ isForce: false });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("SHOW makes interface visible when it was hidden", async () => {
|
|
27
|
+
const { module, observer, state, shared } = createInterfaceTestModule(InterfaceActionsShow);
|
|
28
|
+
const actions = new InterfaceActions();
|
|
29
|
+
actions.inject({ observer, state, shared });
|
|
30
|
+
actions.subscribe();
|
|
31
|
+
const visibleChanged = spyEvent(observer, SUBSCRIBE_EVENTS.VISIBLE_CHANGED);
|
|
32
|
+
|
|
33
|
+
await (module as InterfaceActionsShow).onShow();
|
|
34
|
+
|
|
35
|
+
expect(module.globalState.interface.isVisible).toBe(true);
|
|
36
|
+
expect(visibleChanged).toHaveBeenCalledOnce();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("direct SHOW still emits SHOW_CHANGED when the interface is already shown", async () => {
|
|
40
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActionsShow);
|
|
41
|
+
module.globalState.interface.isShow = true;
|
|
42
|
+
const showChanged = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW_CHANGED);
|
|
43
|
+
|
|
44
|
+
await (module as InterfaceActionsShow).onShow();
|
|
45
|
+
|
|
46
|
+
expect(module.globalState.interface.isShow).toBe(true);
|
|
47
|
+
expect(showChanged).toHaveBeenCalledOnce();
|
|
48
|
+
expect(showChanged).toHaveBeenCalledWith({ isForce: false });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("HIDE clears isShow and emits SHOW_CHANGED", async () => {
|
|
52
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActionsShow);
|
|
53
|
+
module.globalState.interface.isShow = true;
|
|
54
|
+
const showChanged = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW_CHANGED);
|
|
55
|
+
|
|
56
|
+
await (module as InterfaceActionsShow).onHide();
|
|
57
|
+
|
|
58
|
+
expect(module.globalState.interface.isShow).toBe(false);
|
|
59
|
+
expect(showChanged).toHaveBeenCalledOnce();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("SHOW gate stops later subscribers when the interface is already shown", async () => {
|
|
63
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActionsShow);
|
|
64
|
+
module.globalState.interface.isShow = true;
|
|
65
|
+
const later = vi.fn();
|
|
66
|
+
observer.subscribe(SUBSCRIBE_EVENTS.SHOW, later);
|
|
67
|
+
|
|
68
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
69
|
+
|
|
70
|
+
expect(later).not.toHaveBeenCalled();
|
|
71
|
+
expect(module.globalState.interface.isShow).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("SHOW gate lets later subscribers run when the interface is hidden", async () => {
|
|
75
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActionsShow);
|
|
76
|
+
const later = vi.fn();
|
|
77
|
+
observer.subscribe(SUBSCRIBE_EVENTS.SHOW, later);
|
|
78
|
+
|
|
79
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
80
|
+
|
|
81
|
+
expect(later).toHaveBeenCalledOnce();
|
|
82
|
+
expect(module.globalState.interface.isShow).toBe(true);
|
|
83
|
+
expect((module as InterfaceActionsShow).isInShowOrHideProcess).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("HIDE gate stops later subscribers when the interface is already hidden", async () => {
|
|
87
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActionsShow);
|
|
88
|
+
const later = vi.fn();
|
|
89
|
+
observer.subscribe(SUBSCRIBE_EVENTS.HIDE, later);
|
|
90
|
+
|
|
91
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
92
|
+
|
|
93
|
+
expect(later).not.toHaveBeenCalled();
|
|
94
|
+
expect(module.globalState.interface.isShow).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("HIDE gate lets later subscribers run when the interface is shown", async () => {
|
|
98
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActionsShow);
|
|
99
|
+
module.globalState.interface.isShow = true;
|
|
100
|
+
const later = vi.fn();
|
|
101
|
+
observer.subscribe(SUBSCRIBE_EVENTS.HIDE, later);
|
|
102
|
+
|
|
103
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
104
|
+
|
|
105
|
+
expect(later).toHaveBeenCalledOnce();
|
|
106
|
+
expect(module.globalState.interface.isShow).toBe(false);
|
|
107
|
+
expect((module as InterfaceActionsShow).isInShowOrHideProcess).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("SHOW gate stops HIDE subscribers while show is in progress", async () => {
|
|
111
|
+
const { module, observer } = createInterfaceTestModule(InterfaceActionsShow);
|
|
112
|
+
const actions = module as InterfaceActionsShow;
|
|
113
|
+
let release!: () => void;
|
|
114
|
+
const pending = new Promise<void>((resolve) => {
|
|
115
|
+
release = resolve;
|
|
116
|
+
});
|
|
117
|
+
observer.subscribe(SUBSCRIBE_EVENTS.VISIBLE, () => pending);
|
|
118
|
+
const later = vi.fn();
|
|
119
|
+
observer.subscribe(SUBSCRIBE_EVENTS.HIDE, later);
|
|
120
|
+
|
|
121
|
+
const showing = observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
122
|
+
await vi.waitFor(() => expect(actions.isInShowOrHideProcess).toBe(true));
|
|
123
|
+
|
|
124
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
125
|
+
|
|
126
|
+
expect(later).not.toHaveBeenCalled();
|
|
127
|
+
release();
|
|
128
|
+
await showing;
|
|
129
|
+
expect(actions.isInShowOrHideProcess).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
});
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ModuleComponentsConstants,
|
|
3
|
+
ModuleComponentsEvents,
|
|
4
|
+
ModuleComponentsParams,
|
|
5
|
+
ModuleComponentsSettings,
|
|
6
|
+
ModuleControllerState,
|
|
7
|
+
} from "@vnejs/module.components";
|
|
8
|
+
|
|
9
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
10
|
+
|
|
11
|
+
import type { Constants, InterfaceModuleState, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.scenario.interface";
|
|
12
|
+
import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
|
|
13
|
+
import type { PluginName as InteractPluginName, SubscribeEvents as InteractSubscribeEvents } from "@vnejs/contracts.core.interact";
|
|
14
|
+
import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
|
|
15
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
|
|
16
|
+
import type { PluginName as TextPluginName, Params as TextParams } from "@vnejs/contracts.text";
|
|
17
|
+
|
|
18
|
+
import type { InterfaceRuntimeState } from "./utils/interface.js";
|
|
19
|
+
|
|
20
|
+
export type InterfacePluginEvents = ModuleComponentsEvents &
|
|
21
|
+
Record<PluginName, SubscribeEvents> &
|
|
22
|
+
Record<ScenarioPluginName, ScenarioSubscribeEvents> &
|
|
23
|
+
Record<StatePluginName, StateSubscribeEvents> &
|
|
24
|
+
Record<InteractPluginName, InteractSubscribeEvents>;
|
|
25
|
+
|
|
26
|
+
export type InterfacePluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants> & Record<PluginName, Constants>;
|
|
27
|
+
|
|
28
|
+
export type InterfacePluginSettings = ModuleComponentsSettings;
|
|
29
|
+
|
|
30
|
+
export type InterfacePluginParams = ModuleComponentsParams & Record<PluginName, Params> & Record<TextPluginName, TextParams>;
|
|
31
|
+
|
|
32
|
+
export type InterfacePluginState = ModuleControllerState &
|
|
33
|
+
InterfaceModuleState &
|
|
34
|
+
InterfaceRuntimeState & {
|
|
35
|
+
isFast?: boolean;
|
|
36
|
+
locs?: Record<string, string>;
|
|
37
|
+
prefix?: string;
|
|
38
|
+
postfix?: string;
|
|
39
|
+
transition?: number;
|
|
40
|
+
speakerText?: string;
|
|
41
|
+
speakerName?: string;
|
|
42
|
+
speakerColor?: string;
|
|
43
|
+
color?: string;
|
|
44
|
+
opacity?: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type InterfacePluginViewState = InterfacePluginState & {
|
|
48
|
+
isViewActive?: boolean;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type InterfaceViewProps = ReactComponentProps<
|
|
52
|
+
InterfacePluginEvents,
|
|
53
|
+
InterfacePluginConstants,
|
|
54
|
+
InterfacePluginSettings,
|
|
55
|
+
InterfacePluginParams,
|
|
56
|
+
InterfacePluginViewState
|
|
57
|
+
>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TextSpeakerEntry, TokenizedChar } from "@vnejs/contracts.text";
|
|
2
|
+
import type { WallElement } from "@vnejs/contracts.text.wall";
|
|
3
|
+
|
|
4
|
+
export type InterfaceRuntimeState = {
|
|
5
|
+
tokens: TokenizedChar[];
|
|
6
|
+
wall: WallElement[];
|
|
7
|
+
uid: string;
|
|
8
|
+
tokensVisible: number;
|
|
9
|
+
speaker: string;
|
|
10
|
+
speakerInfo: TextSpeakerEntry;
|
|
11
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Backdrop } from "@vnejs/uis.react";
|
|
2
|
+
|
|
3
|
+
import type { BackdropProps } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import type { InterfaceViewProps } from "../../types.js";
|
|
6
|
+
|
|
7
|
+
export const InterfaceBackdrop = ({ view = "", transition = 0, PARAMS }: InterfaceViewProps) => {
|
|
8
|
+
const backdrop = PARAMS.INTERFACE.VIEW_PROPS[view as keyof typeof PARAMS.INTERFACE.VIEW_PROPS]?.backdrop;
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<Backdrop
|
|
12
|
+
{...(backdrop as BackdropProps)}
|
|
13
|
+
transition={transition}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Flex, PositionBox, SmoothText, Text } from "@vnejs/uis.react";
|
|
2
|
+
import { getVneLength } from "@vnejs/uis.utils";
|
|
3
|
+
|
|
4
|
+
import type { InterfaceViewProps } from "../../types.js";
|
|
5
|
+
|
|
6
|
+
import { useTokensHook } from "./tokens.hook.js";
|
|
7
|
+
|
|
8
|
+
export const InterfaceViewDialog = (props: InterfaceViewProps) => {
|
|
9
|
+
const {
|
|
10
|
+
isViewActive = false,
|
|
11
|
+
isForce = false,
|
|
12
|
+
transition,
|
|
13
|
+
tokensVisible = 0,
|
|
14
|
+
tokens = [],
|
|
15
|
+
speakerText,
|
|
16
|
+
speakerName,
|
|
17
|
+
speakerColor,
|
|
18
|
+
opacity,
|
|
19
|
+
color,
|
|
20
|
+
uid = "",
|
|
21
|
+
PARAMS,
|
|
22
|
+
} = props;
|
|
23
|
+
|
|
24
|
+
const propsByView = PARAMS.INTERFACE.VIEW_PROPS.adv;
|
|
25
|
+
|
|
26
|
+
const speakerOpacity = speakerName ? 1 : 0;
|
|
27
|
+
const speakerTransition = speakerName ? transition : 0;
|
|
28
|
+
|
|
29
|
+
const { realTokens, realTokensVisible } = useTokensHook(isViewActive, tokens, tokensVisible, uid);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<PositionBox
|
|
33
|
+
{...propsByView.position}
|
|
34
|
+
opacity={isViewActive ? 1 : 0}
|
|
35
|
+
transition={transition}
|
|
36
|
+
>
|
|
37
|
+
<Flex {...propsByView.flex}>
|
|
38
|
+
<Text
|
|
39
|
+
{...propsByView.speaker}
|
|
40
|
+
text={speakerText}
|
|
41
|
+
color={speakerColor}
|
|
42
|
+
opacity={speakerOpacity}
|
|
43
|
+
transition={speakerTransition}
|
|
44
|
+
/>
|
|
45
|
+
<div
|
|
46
|
+
style={{
|
|
47
|
+
height: getVneLength(6),
|
|
48
|
+
width: "calc(200% / 3)",
|
|
49
|
+
background: `linear-gradient(to right, ${speakerColor} 0%, transparent 100%)`,
|
|
50
|
+
opacity: speakerOpacity,
|
|
51
|
+
transition: `${speakerTransition}ms` || "none",
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
<SmoothText
|
|
55
|
+
{...propsByView.text}
|
|
56
|
+
opacity={opacity}
|
|
57
|
+
color={color}
|
|
58
|
+
tokens={realTokens}
|
|
59
|
+
tokensVisibleForce={realTokensVisible}
|
|
60
|
+
transition={transition}
|
|
61
|
+
isForce={isForce}
|
|
62
|
+
/>
|
|
63
|
+
</Flex>
|
|
64
|
+
</PositionBox>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Flex, PositionBox, SmoothText } from "@vnejs/uis.react";
|
|
2
|
+
|
|
3
|
+
import type { InterfaceViewProps } from "../../types.js";
|
|
4
|
+
|
|
5
|
+
import { useTokensHook } from "./tokens.hook.js";
|
|
6
|
+
|
|
7
|
+
export const InterfaceViewLine = (props: InterfaceViewProps) => {
|
|
8
|
+
const { isViewActive = false, isForce = false, transition = 0, tokensVisible = 0, tokens = [], opacity, color, uid = "", PARAMS } = props;
|
|
9
|
+
|
|
10
|
+
const propsByView = PARAMS.INTERFACE.VIEW_PROPS.line;
|
|
11
|
+
|
|
12
|
+
const { realTokens, realTokensVisible } = useTokensHook(isViewActive, tokens, tokensVisible, uid);
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<PositionBox
|
|
16
|
+
{...propsByView.position}
|
|
17
|
+
opacity={isViewActive ? 1 : 0}
|
|
18
|
+
transition={transition}
|
|
19
|
+
>
|
|
20
|
+
<Flex {...propsByView.flex}>
|
|
21
|
+
<SmoothText
|
|
22
|
+
{...propsByView.text}
|
|
23
|
+
opacity={opacity}
|
|
24
|
+
color={color}
|
|
25
|
+
transition={transition}
|
|
26
|
+
isForce={isForce}
|
|
27
|
+
tokens={realTokens}
|
|
28
|
+
tokensVisibleForce={realTokensVisible}
|
|
29
|
+
/>
|
|
30
|
+
</Flex>
|
|
31
|
+
</PositionBox>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Flex, PositionBox, Scrollbar, SmoothText, Text } from "@vnejs/uis.react";
|
|
2
|
+
|
|
3
|
+
import type { Params as InterfaceContractParams } from "@vnejs/contracts.controllers.scenario.interface";
|
|
4
|
+
import type { TextSpeakerInfo, TokenizedChar } from "@vnejs/contracts.text";
|
|
5
|
+
import type { WallElement } from "@vnejs/contracts.text.wall";
|
|
6
|
+
|
|
7
|
+
import type { InterfaceViewProps } from "../../types.js";
|
|
8
|
+
|
|
9
|
+
import { useTokensHook } from "./tokens.hook.js";
|
|
10
|
+
|
|
11
|
+
type WallTextElement = {
|
|
12
|
+
speakerName?: string;
|
|
13
|
+
speakerColor?: string;
|
|
14
|
+
uid: string;
|
|
15
|
+
color?: string;
|
|
16
|
+
opacity?: number;
|
|
17
|
+
tokens: TokenizedChar[];
|
|
18
|
+
tokensVisible: number;
|
|
19
|
+
transition?: number;
|
|
20
|
+
isForce?: boolean;
|
|
21
|
+
propsByView: InterfaceContractParams["VIEW_PROPS"]["wall"];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const renderOneText = (wallElement: WallTextElement) => (
|
|
25
|
+
<div key={wallElement.uid}>
|
|
26
|
+
{wallElement.speakerName && (
|
|
27
|
+
<Text
|
|
28
|
+
{...wallElement.propsByView.text}
|
|
29
|
+
isInlineBlock={true}
|
|
30
|
+
color={wallElement.speakerColor}
|
|
31
|
+
text={`${wallElement.speakerName}:`}
|
|
32
|
+
marginRight={12}
|
|
33
|
+
/>
|
|
34
|
+
)}
|
|
35
|
+
<SmoothText
|
|
36
|
+
{...wallElement.propsByView.text}
|
|
37
|
+
isNoScrollBar={true}
|
|
38
|
+
color={wallElement.color}
|
|
39
|
+
opacity={wallElement.opacity}
|
|
40
|
+
transition={wallElement.transition}
|
|
41
|
+
isForce={wallElement.isForce}
|
|
42
|
+
tokens={wallElement.tokens}
|
|
43
|
+
tokensVisibleForce={wallElement.tokensVisible}
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const mapWall = ({
|
|
49
|
+
uid = "",
|
|
50
|
+
tokens = [],
|
|
51
|
+
speaker = "",
|
|
52
|
+
speakerInfo = {},
|
|
53
|
+
transition = 0,
|
|
54
|
+
props,
|
|
55
|
+
}: WallElement & { transition?: number; props: InterfaceViewProps }) => {
|
|
56
|
+
const propsByView = props.PARAMS.INTERFACE.VIEW_PROPS.wall;
|
|
57
|
+
const speakersInfo = props.PARAMS.TEXT.SPEAKERS_INFO;
|
|
58
|
+
const speakerStyleInfo: TextSpeakerInfo = speakersInfo[speaker] ?? speakersInfo[props.PARAMS.TEXT.DEFAULT_SPEAKER_NAME];
|
|
59
|
+
const { color, opacity = 1, speakerColor = "white" } = speakerStyleInfo;
|
|
60
|
+
const locs = props.locs ?? {};
|
|
61
|
+
const meet = speakerInfo.meet ?? 0;
|
|
62
|
+
const defaultSpeakerName = props.PARAMS.TEXT.DEFAULT_SPEAKER_NAME;
|
|
63
|
+
const speakerName =
|
|
64
|
+
locs[`speaker.${speaker}.${meet}`] ??
|
|
65
|
+
locs[`speaker.${speaker}`] ??
|
|
66
|
+
speakersInfo[speaker]?.displayName ??
|
|
67
|
+
(speaker !== defaultSpeakerName ? speaker : undefined);
|
|
68
|
+
|
|
69
|
+
return { speakerName, speakerColor, uid, color, opacity, tokens, tokensVisible: tokens.length, transition, isForce: props.isForce, propsByView };
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const InterfaceViewWall = (props: InterfaceViewProps) => {
|
|
73
|
+
const {
|
|
74
|
+
isViewActive = false,
|
|
75
|
+
transition = 0,
|
|
76
|
+
tokensVisible = 0,
|
|
77
|
+
tokens = [],
|
|
78
|
+
wall = [],
|
|
79
|
+
uid = "",
|
|
80
|
+
speakerName,
|
|
81
|
+
speakerColor,
|
|
82
|
+
color,
|
|
83
|
+
opacity,
|
|
84
|
+
isForce = false,
|
|
85
|
+
PARAMS,
|
|
86
|
+
} = props;
|
|
87
|
+
|
|
88
|
+
const propsByView = PARAMS.INTERFACE.VIEW_PROPS.wall;
|
|
89
|
+
|
|
90
|
+
const { realTokens, realTokensVisible } = useTokensHook(isViewActive, tokens, tokensVisible, uid);
|
|
91
|
+
|
|
92
|
+
const texts = [
|
|
93
|
+
...wall.map((item) => mapWall({ ...item, transition, props })),
|
|
94
|
+
{ speakerName, speakerColor, uid, color, opacity, tokens: realTokens, tokensVisible: realTokensVisible, transition, isForce, propsByView },
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<PositionBox
|
|
99
|
+
{...propsByView.position}
|
|
100
|
+
opacity={isViewActive ? 1 : 0}
|
|
101
|
+
transition={transition}
|
|
102
|
+
>
|
|
103
|
+
<Scrollbar {...propsByView.scrollBar}>
|
|
104
|
+
<Flex {...propsByView.flex}>{texts.map(renderOneText)}</Flex>
|
|
105
|
+
</Scrollbar>
|
|
106
|
+
</PositionBox>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { flushSync, useEffect, useState } from "@vnejs/uis.react";
|
|
2
|
+
|
|
3
|
+
import type { TokenizedChar } from "@vnejs/contracts.text";
|
|
4
|
+
|
|
5
|
+
const EMPTY_TOKENS: TokenizedChar[] = [];
|
|
6
|
+
|
|
7
|
+
export const useTokensHook = (isShow: boolean, tokens: TokenizedChar[], tokensVisible: number, uid: string) => {
|
|
8
|
+
const [savedUid, setSavedUid] = useState("");
|
|
9
|
+
const [tokensSync, setTokensSync] = useState([] as TokenizedChar[]);
|
|
10
|
+
const [tokensWrong, setTokensWrong] = useState([] as TokenizedChar[]);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (isShow) setTokensWrong(tokens);
|
|
14
|
+
}, [isShow]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
if (savedUid === uid) {
|
|
18
|
+
if (!isShow) setTokensWrong(tokens);
|
|
19
|
+
setTokensSync(tokens);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
flushSync(() => {
|
|
23
|
+
setSavedUid(uid);
|
|
24
|
+
if (!isShow) setTokensWrong(tokens);
|
|
25
|
+
setTokensSync(tokens);
|
|
26
|
+
});
|
|
27
|
+
}, 0);
|
|
28
|
+
}, [tokens]);
|
|
29
|
+
|
|
30
|
+
const isShowTokens = tokensSync !== tokensWrong;
|
|
31
|
+
const realTokensVisible = isShowTokens ? tokensVisible : 0;
|
|
32
|
+
const realTokens = isShowTokens ? tokensSync : EMPTY_TOKENS;
|
|
33
|
+
|
|
34
|
+
return { isShowTokens, realTokensVisible, realTokens };
|
|
35
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ViewRenderFunc } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { Screen, createRenderFunc, useIsForceHook, useStoreState } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
6
|
+
|
|
7
|
+
import type { TextSpeakerInfo } from "@vnejs/contracts.text";
|
|
8
|
+
|
|
9
|
+
import type { InterfacePluginConstants, InterfacePluginEvents, InterfacePluginParams, InterfacePluginSettings } from "../types.js";
|
|
10
|
+
import type { InterfacePluginState } from "../types.js";
|
|
11
|
+
|
|
12
|
+
import { InterfaceBackdrop, InterfaceViewDialog, InterfaceViewLine, InterfaceViewWall } from "./components/index.js";
|
|
13
|
+
|
|
14
|
+
type InterfaceComponentProps = ReactComponentProps<
|
|
15
|
+
InterfacePluginEvents,
|
|
16
|
+
InterfacePluginConstants,
|
|
17
|
+
InterfacePluginSettings,
|
|
18
|
+
InterfacePluginParams,
|
|
19
|
+
InterfacePluginState
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
const Interface = (props: InterfaceComponentProps) => {
|
|
23
|
+
const { store, onMount, emit, EVENTS, PARAMS } = props;
|
|
24
|
+
const state = useStoreState<InterfacePluginState>(store, onMount);
|
|
25
|
+
|
|
26
|
+
const { isShow = false, isVisible = false, isForce = false, tokensVisible = 0, view = "", locs = {} } = state;
|
|
27
|
+
const { speaker = "", speakerInfo = {}, tokens = [], wall = [], postfix = "", prefix = "", uid = "" } = state;
|
|
28
|
+
|
|
29
|
+
const isRealForce = useIsForceHook(isForce);
|
|
30
|
+
|
|
31
|
+
const meet = speakerInfo.meet ?? 0;
|
|
32
|
+
const speakersInfo = PARAMS.TEXT.SPEAKERS_INFO;
|
|
33
|
+
const defaultSpeakerName = PARAMS.TEXT.DEFAULT_SPEAKER_NAME;
|
|
34
|
+
const speakerName =
|
|
35
|
+
locs[`speaker.${speaker}.${meet}`] ??
|
|
36
|
+
locs[`speaker.${speaker}`] ??
|
|
37
|
+
speakersInfo[speaker]?.displayName ??
|
|
38
|
+
(speaker !== defaultSpeakerName ? speaker : undefined);
|
|
39
|
+
const speakerText = speakerName ? `${`${locs[`prefix.${prefix}`] ?? ""} `}${speakerName}${` ${locs[`postfix.${postfix}`] ?? ""}`}` : ".";
|
|
40
|
+
const transition = isRealForce ? 0 : PARAMS.INTERFACE.TRANSITION;
|
|
41
|
+
const speakerStyleInfo: TextSpeakerInfo = speakersInfo[speaker] ?? speakersInfo[PARAMS.TEXT.DEFAULT_SPEAKER_NAME];
|
|
42
|
+
|
|
43
|
+
const { color, opacity = 1, speakerColor = "white" } = speakerStyleInfo;
|
|
44
|
+
|
|
45
|
+
const viewProps = {
|
|
46
|
+
isShow,
|
|
47
|
+
isForce: isRealForce,
|
|
48
|
+
transition,
|
|
49
|
+
tokensVisible,
|
|
50
|
+
tokens,
|
|
51
|
+
wall,
|
|
52
|
+
uid,
|
|
53
|
+
locs,
|
|
54
|
+
speakerText,
|
|
55
|
+
speakerName,
|
|
56
|
+
speakerColor,
|
|
57
|
+
opacity,
|
|
58
|
+
color,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Screen
|
|
63
|
+
isShow={isShow}
|
|
64
|
+
isForce={isRealForce}
|
|
65
|
+
isHidden={!isVisible}
|
|
66
|
+
isDisableAutoread={false}
|
|
67
|
+
isAllowAutoread={Boolean(isShow && isVisible)}
|
|
68
|
+
isIgnoreOnScreenshot={false}
|
|
69
|
+
transition={transition}
|
|
70
|
+
zIndex={PARAMS.INTERFACE.ZINDEX}
|
|
71
|
+
onClick={() => emit(EVENTS.INTERFACE.INTERACT)}
|
|
72
|
+
>
|
|
73
|
+
<InterfaceBackdrop
|
|
74
|
+
view={view}
|
|
75
|
+
transition={transition}
|
|
76
|
+
{...props}
|
|
77
|
+
/>
|
|
78
|
+
<InterfaceViewDialog
|
|
79
|
+
view={view}
|
|
80
|
+
isViewActive={view === "adv"}
|
|
81
|
+
{...viewProps}
|
|
82
|
+
{...props}
|
|
83
|
+
/>
|
|
84
|
+
<InterfaceViewLine
|
|
85
|
+
view={view}
|
|
86
|
+
isViewActive={view === "line"}
|
|
87
|
+
{...viewProps}
|
|
88
|
+
{...props}
|
|
89
|
+
/>
|
|
90
|
+
<InterfaceViewWall
|
|
91
|
+
view={view}
|
|
92
|
+
isViewActive={view === "wall"}
|
|
93
|
+
{...viewProps}
|
|
94
|
+
{...props}
|
|
95
|
+
/>
|
|
96
|
+
</Screen>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const render: ViewRenderFunc<InterfacePluginState> = createRenderFunc(Interface);
|
package/tsconfig.json
ADDED
package/README.md
DELETED