@vnejs/plugins.views.scenario.interface 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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, !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<unknown[]> | undefined;
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<unknown[]> | undefined;
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
- return this.emit(this.EVENTS.INTERFACE.VIEW_CHANGED, { isForce });
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 { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Backdrop, PositionBox, useMemo } from "@vnejs/uis.react";
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 propsByView = useMemo(() => PARAMS.INTERFACE.VIEW_PROPS[view]?.backdrop || {}, [view, PARAMS.INTERFACE.VIEW_PROPS]);
5
- const propsBackdrop = useMemo(() => ({ ...propsByView.props, transition }), [propsByView, transition]);
6
- const propsPosition = useMemo(() => ({ ...propsByView.flatPosition, transition }), [propsByView, transition]);
7
- const styleFlatBackdrop = useMemo(() => ({ ...propsByView.flatStyle, width: "100%", height: "100%", transition: `${transition}ms` }), [propsByView, transition]);
8
- return (_jsxs(_Fragment, { children: [_jsx(Backdrop, { ...propsBackdrop }), _jsx(PositionBox, { ...propsPosition, children: _jsx("div", { style: styleFlatBackdrop }) })] }));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.scenario.interface",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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
- if (this.state.view !== view) return this.updateStateAndView({ view }, isForce, !isForce);
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();
@@ -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
- return this.emit(this.EVENTS.INTERFACE.VIEW_CHANGED, { isForce });
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;
@@ -1,24 +1,13 @@
1
- import { Backdrop, PositionBox, useMemo } from "@vnejs/uis.react";
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 propsByView = useMemo(() => PARAMS.INTERFACE.VIEW_PROPS[view as keyof typeof PARAMS.INTERFACE.VIEW_PROPS]?.backdrop || {}, [view, PARAMS.INTERFACE.VIEW_PROPS]);
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
- const propsBackdrop = useMemo(() => ({ ...propsByView.props, transition }), [propsByView, transition]);
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
  };