@vnejs/plugins.views.intro 0.1.1 → 0.1.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.
@@ -0,0 +1,11 @@
1
+ export const BACKGROUND = "Menu/loading";
2
+
3
+ export const TRANSITION = 500;
4
+ export const ZINDEX = 2000;
5
+ export const LOC_LABEL = "intro";
6
+
7
+ export const VIEW_PROPS = {
8
+ texts: { position: { top: 240, left: 120, right: 720 }, flex: { direction: "column", gap: 60 }, text: { size: 96 } },
9
+ hint: { position: { bottom: 120, left: 120, right: 120 }, text: { size: 60, align: "center" } },
10
+ screen: { transition: TRANSITION, zIndex: ZINDEX },
11
+ };
package/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import { regPlugin } from "@vnejs/shared";
2
2
 
3
3
  import { SUBSCRIBE_EVENTS } from "./const/events";
4
+ import * as params from "./const/params";
4
5
 
6
+ import { IntroController } from "./modules/controller";
5
7
  import { Intro } from "./modules/intro";
8
+ import { IntroView } from "./modules/view";
6
9
 
7
- regPlugin("INTRO", { events: SUBSCRIBE_EVENTS }, [Intro]);
10
+ regPlugin("INTRO", { events: SUBSCRIBE_EVENTS, params }, [IntroController, Intro, IntroView]);
@@ -0,0 +1,21 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ export class IntroController extends ModuleController {
4
+ name = "intro.controller";
5
+
6
+ emitInteract = () => this.emit(this.EVENTS.INTRO.INTERACT);
7
+
8
+ bgName = this.PARAMS.INTRO.BACKGROUND;
9
+ updateEvent = this.EVENTS.INTRO.UPDATE;
10
+ controls = { [this.CONST.CONTROLS.BUTTONS.ANY]: this.emitInteract };
11
+ controlsIndex = this.PARAMS.INTRO.ZINDEX;
12
+
13
+ subscribe = () => {
14
+ this.on(this.EVENTS.INTRO.SHOW, this.onShow);
15
+ this.on(this.EVENTS.INTRO.HIDE, this.onHide);
16
+
17
+ this.on(this.EVENTS.SYSTEM.STARTED, this.loadBgMedia);
18
+ };
19
+
20
+ beforeShow = async () => this.updateState({ bgSrc: (await this.loadBgMedia()).src });
21
+ }
package/modules/intro.js CHANGED
@@ -4,26 +4,31 @@ export class Intro extends Module {
4
4
  name = "intro";
5
5
 
6
6
  subscribe = () => {
7
- this.on(this.EVENTS.INTRO.CLICK, this.onIntroInteract);
8
-
9
- this.on(this.EVENTS.INTRO.INTERACT, this.onIntroInteract);
10
7
  this.on(this.EVENTS.INTRO.SKIP, this.onIntroSkip);
8
+ this.on(this.EVENTS.INTRO.CLICK, this.onIntroClick);
9
+ this.on(this.EVENTS.INTRO.INTERACT, this.onIntroInteract);
11
10
  };
12
11
  init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.execHandler });
13
-
14
- execHandler = async (line, args) => {
12
+ execHandler = () => {
15
13
  if (this.isShowed) return setImmediate(this.emitSkip);
16
- if (line === "show") return this.emit(this.EVENTS.INTRO.SHOW);
17
- if (line === "hide") this.isShowed = true;
18
- if (line === "hide") return this.emit(this.EVENTS.INTRO.HIDE);
14
+
15
+ this.isShowed = true;
16
+
17
+ return this.emit(this.EVENTS.INTRO.SHOW);
19
18
  };
20
19
 
21
- onIntroInteract = () => {
22
- // log
20
+ onIntroClick = async () => {
21
+ this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "click" } });
22
+ await this.emit(this.EVENTS.INTRO.HIDE);
23
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
24
+ };
25
+ onIntroInteract = async () => {
26
+ this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "interact" } });
27
+ await this.emit(this.EVENTS.INTRO.HIDE);
23
28
  this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
24
29
  };
25
30
  onIntroSkip = () => {
26
- // log
31
+ this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "skip" } });
27
32
  this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
28
33
  };
29
34
 
@@ -0,0 +1,14 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import { render } from "../view";
4
+
5
+ export class IntroView extends ModuleView {
6
+ name = "intro.view";
7
+
8
+ locLabel = this.PARAMS.INTRO.LOC_LABEL;
9
+ animationTime = this.PARAMS.INTRO.TRANSITION;
10
+ updateEvent = this.EVENTS.INTRO.UPDATE;
11
+
12
+ renderFunc = render;
13
+ updateHandler = this.onUpdateStoreComponent;
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.intro",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -0,0 +1,13 @@
1
+ import { useMemo } from "react";
2
+
3
+ import { PositionBox, Text } from "@vnejs/uis.react";
4
+
5
+ export const IntroHint = ({ text = "", ...props } = {}) => {
6
+ const propsText = useMemo(() => ({ ...props.PARAMS.INTRO.VIEW_PROPS.hint.text, text }), [text]);
7
+
8
+ return (
9
+ <PositionBox {...props.PARAMS.INTRO.VIEW_PROPS.hint.position}>
10
+ <Text {...propsText} />
11
+ </PositionBox>
12
+ );
13
+ };
@@ -0,0 +1,23 @@
1
+ import { useMemo } from "react";
2
+
3
+ import { PositionBox, Text, Flex } from "@vnejs/uis.react";
4
+
5
+ const renderText = ({ text, props }, i) => (
6
+ <Text
7
+ {...props}
8
+ text={text}
9
+ key={i}
10
+ />
11
+ );
12
+
13
+ export const IntroTexts = ({ text = "", ...props } = {}) => {
14
+ const propsByView = props.PARAMS.INTRO.VIEW_PROPS.texts;
15
+
16
+ const textsObj = useMemo(() => text.split("\n").map((line) => ({ text: line, props: props.PARAMS.INTRO.VIEW_PROPS.texts.text })), [text]);
17
+
18
+ return (
19
+ <PositionBox {...propsByView.position}>
20
+ <Flex {...propsByView.flex}>{textsObj.map(renderText)}</Flex>
21
+ </PositionBox>
22
+ );
23
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./IntroHint";
2
+ export * from "./IntroTexts";
package/view/index.jsx ADDED
@@ -0,0 +1,28 @@
1
+ import { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+
4
+ import { Screen } from "@vnejs/uis.react";
5
+
6
+ import { IntroHint, IntroTexts } from "./components";
7
+
8
+ const Intro = ({ store, onMount, ...props } = {}) => {
9
+ const [{ isShow = false, isForce = false, bgSrc = "", locs = {} }, setState] = useState({});
10
+
11
+ useEffect(() => store.subscribe(setState), []);
12
+ useEffect(() => void onMount(), []);
13
+
14
+ const onClick = useCallback(() => props.emit(props.EVENTS.INTRO.CLICK), []);
15
+
16
+ const propsTexts = useMemo(() => ({ ...props, text: locs.intro }), [locs]);
17
+ const propsHint = useMemo(() => ({ ...props, text: locs.hint }), [locs]);
18
+ const propsScreen = useMemo(() => ({ ...props.PARAMS.INTRO.VIEW_PROPS.screen, bgSrc, isShow, isForce, onClick }), [bgSrc, isShow, isForce]);
19
+
20
+ return (
21
+ <Screen {...propsScreen}>
22
+ <IntroTexts {...propsTexts} />
23
+ <IntroHint {...propsHint} />
24
+ </Screen>
25
+ );
26
+ };
27
+
28
+ export const render = (props, root) => createRoot(root).render(<Intro {...props} />);