@vnejs/plugins.views.scenario.interface 0.2.0 → 0.2.2
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/modules/controller.js +3 -1
- package/dist/modules/interface.d.ts +2 -2
- package/dist/modules/interface.js +3 -2
- package/dist/view/components/InterfaceBackdrop.js +7 -7
- package/package.json +1 -1
- package/src/modules/controller.ts +3 -1
- package/src/modules/interface.ts +3 -2
- package/src/tests/setup.ts +1 -7
- package/src/view/components/InterfaceBackdrop.tsx +7 -18
- package/src/view/components/InterfaceViewDialog.tsx +4 -1
- package/src/view/components/InterfaceViewLine.tsx +4 -1
- package/tsconfig.json +2 -9
|
@@ -31,8 +31,10 @@ export class InterfaceController extends ModuleController {
|
|
|
31
31
|
};
|
|
32
32
|
onViewChanged = ({ isForce = false } = {}) => {
|
|
33
33
|
const { view = "" } = this.globalState.interface;
|
|
34
|
+
// Do not mark as fast: wait for TRANSITION so React applies isViewActive before the next scenario line (text).
|
|
35
|
+
// Otherwise useTokensHook can receive tokens while the target view is still inactive and never show them.
|
|
34
36
|
if (this.state.view !== view)
|
|
35
|
-
return this.updateStateAndView({ view }, isForce,
|
|
37
|
+
return this.updateStateAndView({ view }, isForce, false);
|
|
36
38
|
};
|
|
37
39
|
onTextChanged = async ({ tokens = [], uid = "", tokensVisible = 0 } = {}) => {
|
|
38
40
|
while (this.isStateChangeInProcess)
|
|
@@ -17,10 +17,10 @@ export declare class Interface extends ModuleCore<InterfacePluginEvents, Interfa
|
|
|
17
17
|
onTextSpeakerChanged: ({ speaker }?: InterfaceSpeakerChangedPayload) => Promise<unknown[]> | undefined;
|
|
18
18
|
onTextEmitBefore: () => Promise<unknown[]> | undefined;
|
|
19
19
|
onTextHide: () => Promise<unknown[]> | undefined;
|
|
20
|
-
onView: ({ view, isForce }?: InterfaceViewPayload) => Promise<
|
|
20
|
+
onView: ({ view, isForce }?: InterfaceViewPayload) => Promise<void>;
|
|
21
21
|
onStateSet: (payload: ModuleGlobalStateRegistry) => Promise<unknown[]> | undefined;
|
|
22
22
|
onStateClear: () => Promise<unknown[]> | undefined;
|
|
23
|
-
setView: (view?: string, isForce?: boolean) => Promise<
|
|
23
|
+
setView: (view?: string, isForce?: boolean) => Promise<void>;
|
|
24
24
|
setShow: (isShow: boolean, isForce?: boolean) => Promise<unknown[] | undefined>;
|
|
25
25
|
setVisible: (isVisible: boolean, isForce?: boolean) => Promise<unknown[]> | undefined;
|
|
26
26
|
emitTextChanged: (tokens?: InterfaceTextChangedPayload["tokens"], uid?: string, tokensVisible?: number) => Promise<unknown[]> | undefined;
|
|
@@ -51,9 +51,10 @@ export class Interface extends ModuleCore {
|
|
|
51
51
|
return this.setNewState(moduleState?.view, moduleState?.isVisible, moduleState?.isShow);
|
|
52
52
|
};
|
|
53
53
|
onStateClear = () => this.setNewState(this.PARAMS.INTERFACE.DEFAULT_VIEW, false, false);
|
|
54
|
-
setView = (view, isForce = false) => {
|
|
54
|
+
setView = async (view, isForce = false) => {
|
|
55
55
|
this.state.view = view ?? "";
|
|
56
|
-
|
|
56
|
+
await this.emit(this.EVENTS.INTERFACE.VIEW_CHANGED, { isForce });
|
|
57
|
+
await this.waitRerender();
|
|
57
58
|
};
|
|
58
59
|
setShow = async (isShow, isForce = false) => {
|
|
59
60
|
this.state.isShow = isShow;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Backdrop,
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Backdrop, useMemo } from "@vnejs/uis.react";
|
|
3
3
|
export const InterfaceBackdrop = ({ view = "", transition = 0, PARAMS }) => {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return
|
|
4
|
+
const props = useMemo(() => {
|
|
5
|
+
const backdrop = PARAMS.INTERFACE.VIEW_PROPS[view]?.backdrop;
|
|
6
|
+
return { ...backdrop, transition };
|
|
7
|
+
}, [view, transition, PARAMS.INTERFACE.VIEW_PROPS]);
|
|
8
|
+
return _jsx(Backdrop, { ...props });
|
|
9
9
|
};
|
package/package.json
CHANGED
|
@@ -55,7 +55,9 @@ export class InterfaceController extends ModuleController<
|
|
|
55
55
|
onViewChanged = ({ isForce = false }: InterfaceForcePayload = {}) => {
|
|
56
56
|
const { view = "" } = this.globalState.interface;
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
// Do not mark as fast: wait for TRANSITION so React applies isViewActive before the next scenario line (text).
|
|
59
|
+
// Otherwise useTokensHook can receive tokens while the target view is still inactive and never show them.
|
|
60
|
+
if (this.state.view !== view) return this.updateStateAndView({ view }, isForce, false);
|
|
59
61
|
};
|
|
60
62
|
onTextChanged = async ({ tokens = [], uid = "", tokensVisible = 0 }: InterfaceTextChangedPayload = {}) => {
|
|
61
63
|
while (this.isStateChangeInProcess) await this.waitRerender();
|
package/src/modules/interface.ts
CHANGED
|
@@ -82,10 +82,11 @@ export class Interface extends ModuleCore<
|
|
|
82
82
|
};
|
|
83
83
|
onStateClear = () => this.setNewState(this.PARAMS.INTERFACE.DEFAULT_VIEW, false, false);
|
|
84
84
|
|
|
85
|
-
setView = (view?: string, isForce = false) => {
|
|
85
|
+
setView = async (view?: string, isForce = false) => {
|
|
86
86
|
this.state.view = view ?? "";
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
await this.emit(this.EVENTS.INTERFACE.VIEW_CHANGED, { isForce });
|
|
89
|
+
await this.waitRerender();
|
|
89
90
|
};
|
|
90
91
|
setShow = async (isShow: boolean, isForce = false) => {
|
|
91
92
|
this.state.isShow = isShow;
|
package/src/tests/setup.ts
CHANGED
|
@@ -3,13 +3,7 @@ import { SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scena
|
|
|
3
3
|
import { SUBSCRIBE_EVENTS as TEXT_EVENTS, PLUGIN_NAME as TEXT } from "@vnejs/contracts.text";
|
|
4
4
|
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.scenario.interface";
|
|
5
5
|
import { SourcesSet } from "@vnejs/sources-set";
|
|
6
|
-
import {
|
|
7
|
-
createTestModule as baseCreateTestModule,
|
|
8
|
-
registerCoreVne,
|
|
9
|
-
registerVnePlugin,
|
|
10
|
-
stubEvent,
|
|
11
|
-
stubSilentEvent,
|
|
12
|
-
} from "@vnejs/test-utils";
|
|
6
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubEvent, stubSilentEvent } from "@vnejs/test-utils";
|
|
13
7
|
|
|
14
8
|
export const registerInterfacePluginVne = () => {
|
|
15
9
|
registerCoreVne();
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
import { Backdrop,
|
|
1
|
+
import { Backdrop, useMemo } from "@vnejs/uis.react";
|
|
2
|
+
import type { BackdropProps } from "@vnejs/uis.react";
|
|
2
3
|
|
|
3
4
|
import type { InterfaceViewProps } from "../../types.js";
|
|
4
5
|
|
|
5
6
|
export const InterfaceBackdrop = ({ view = "", transition = 0, PARAMS }: InterfaceViewProps) => {
|
|
6
|
-
const
|
|
7
|
+
const props = useMemo((): BackdropProps => {
|
|
8
|
+
const backdrop = PARAMS.INTERFACE.VIEW_PROPS[view as keyof typeof PARAMS.INTERFACE.VIEW_PROPS]?.backdrop;
|
|
9
|
+
return { ...(backdrop as BackdropProps), transition };
|
|
10
|
+
}, [view, transition, PARAMS.INTERFACE.VIEW_PROPS]);
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
const propsPosition = useMemo(() => ({ ...propsByView.flatPosition, transition }), [propsByView, transition]);
|
|
10
|
-
|
|
11
|
-
const styleFlatBackdrop = useMemo(
|
|
12
|
-
() => ({ ...propsByView.flatStyle, width: "100%", height: "100%", transition: `${transition}ms` }),
|
|
13
|
-
[propsByView, transition],
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<>
|
|
18
|
-
<Backdrop {...propsBackdrop} />
|
|
19
|
-
<PositionBox {...propsPosition}>
|
|
20
|
-
<div style={styleFlatBackdrop} />
|
|
21
|
-
</PositionBox>
|
|
22
|
-
</>
|
|
23
|
-
);
|
|
12
|
+
return <Backdrop {...props} />;
|
|
24
13
|
};
|
|
@@ -9,7 +9,10 @@ export const InterfaceViewDialog = (props: InterfaceViewProps) => {
|
|
|
9
9
|
|
|
10
10
|
const propsByView = PARAMS.INTERFACE.VIEW_PROPS.adv;
|
|
11
11
|
|
|
12
|
-
const propsPosition = useMemo(
|
|
12
|
+
const propsPosition = useMemo(
|
|
13
|
+
() => ({ ...propsByView.position, opacity: isViewActive ? 1 : 0, transition }),
|
|
14
|
+
[isViewActive, transition, propsByView.position],
|
|
15
|
+
);
|
|
13
16
|
|
|
14
17
|
const speakerOpacity = speakerName ? 1 : 0;
|
|
15
18
|
const speakerTransition = speakerName ? transition : 0;
|
|
@@ -15,7 +15,10 @@ export const InterfaceViewLine = (props: InterfaceViewProps) => {
|
|
|
15
15
|
() => ({ ...propsByView.text, opacity, color, transition, ...propsTextTokens }),
|
|
16
16
|
[opacity, color, transition, propsTextTokens, propsByView.text],
|
|
17
17
|
);
|
|
18
|
-
const propsPosition = useMemo(
|
|
18
|
+
const propsPosition = useMemo(
|
|
19
|
+
() => ({ ...propsByView.position, opacity: isViewActive ? 1 : 0, transition }),
|
|
20
|
+
[isViewActive, transition, propsByView.position],
|
|
21
|
+
);
|
|
19
22
|
|
|
20
23
|
return (
|
|
21
24
|
<PositionBox {...propsPosition}>
|
package/tsconfig.json
CHANGED
|
@@ -5,13 +5,6 @@
|
|
|
5
5
|
"outDir": "dist",
|
|
6
6
|
"jsx": "react-jsx"
|
|
7
7
|
},
|
|
8
|
-
"include": [
|
|
9
|
-
|
|
10
|
-
"src/**/*.tsx"
|
|
11
|
-
],
|
|
12
|
-
"exclude": [
|
|
13
|
-
"dist",
|
|
14
|
-
"node_modules",
|
|
15
|
-
"src/tests"
|
|
16
|
-
]
|
|
8
|
+
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
|
9
|
+
"exclude": ["dist", "node_modules", "src/tests"]
|
|
17
10
|
}
|