@vnejs/plugins.view.coralina.mainmenu 0.0.1 → 0.1.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.
@@ -0,0 +1,14 @@
1
+ export const BACKGROUND = "Menu/loading";
2
+
3
+ export const VIEW_PROPS = {
4
+ background: { withDark: false, withBlur: false },
5
+
6
+ controls: {
7
+ position: { bottom: 240, left: 240 },
8
+ props: { textSize: 96, flexGap: 60, flexDirection: "column" },
9
+ },
10
+ };
11
+
12
+ export const TRANSITION = 500;
13
+ export const ZINDEX = 3000;
14
+ export const LOC_LABEL = "mainMenu";
package/index.js CHANGED
@@ -1,8 +1,9 @@
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
 
5
6
  import { MainMenuController } from "./modules/controller";
6
7
  import { MainMenuView } from "./modules/view";
7
8
 
8
- regPlugin("MAINMENU_VIEW", { events: SUBSCRIBE_EVENTS }, [MainMenuController, MainMenuView]);
9
+ regPlugin("MAINMENU_VIEW", { events: SUBSCRIBE_EVENTS, params }, [MainMenuController, MainMenuView]);
@@ -1,18 +1,23 @@
1
- import { Module } from "@vnejs/module";
1
+ import { ModuleController } from "@vnejs/module.components";
2
2
 
3
3
  const toStateItem = ({ onClick, ...item }) => item;
4
4
  const onRealItems = (item) => !item.isDisabled && !item.isHide;
5
5
 
6
- export class MainMenuController extends Module.Controller {
6
+ export class MainMenuController extends ModuleController {
7
7
  name = "mainmenu.controller";
8
8
 
9
+ emitAccept = () => this.emit(this.EVENTS.MAINMENU_VIEW.ACCEPT);
10
+
11
+ bgName = this.PARAMS.MAINMENU_VIEW.BACKGROUND;
12
+
9
13
  updateEvent = this.EVENTS.MAINMENU_VIEW.UPDATE;
10
14
  controls = {
11
15
  [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decCurrentItem,
12
16
  [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incCurrentItem,
13
- [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => this.emit(this.EVENTS.MAINMENU_VIEW.ACCEPT),
17
+ [this.CONST.CONTROLS.BUTTONS.ACCEPT]: this.emitAccept,
18
+ [this.CONST.CONTROLS.BUTTONS.INTERACT]: this.emitAccept,
14
19
  };
15
- controlsIndex = 2000;
20
+ controlsIndex = this.PARAMS.MAINMENU_VIEW.ZINDEX;
16
21
 
17
22
  subscribe = () => {
18
23
  this.on(this.EVENTS.MAINMENU.SHOW, this.onShow);
@@ -23,28 +28,22 @@ export class MainMenuController extends Module.Controller {
23
28
 
24
29
  this.on(this.EVENTS.LOCS.LANG_CHANGED, this.updateView);
25
30
 
26
- this.on(this.EVENTS.STATE.CLEAR, this.onHideForce);
27
31
  this.on(this.EVENTS.STATE.SET, this.onHideForce);
32
+ this.on(this.EVENTS.STATE.CLEAR, this.onHideForce);
33
+ this.on(this.EVENTS.STATE.CLEAR, this.loadBgMedia);
34
+ this.on(this.EVENTS.SYSTEM.STARTED, this.loadBgMedia);
28
35
  };
29
36
 
30
37
  beforeShow = async () => {
31
- const items = (await this.getItems()).map(toStateItem);
38
+ const items = (await this.emitOne(this.EVENTS.MAINMENU.ITEMS)).map(toStateItem);
32
39
 
33
- this.updateState({ items, realItems: items.filter(onRealItems) });
40
+ this.updateState({ items, realItems: items.filter(onRealItems), bgSrc: (await this.loadBgMedia()).src });
34
41
 
35
- this.currentItem = null;
36
42
  this.maxCurrentItem = this.state.realItems.length - 1;
37
43
  };
38
44
 
39
- onAccept = async () => this.click(await this.getRealItems(), this.currentItem);
40
- onClick = async ({ index } = {}) => this.click(await this.getItems(), index);
45
+ onAccept = async () => this.click((await this.emitOne(this.EVENTS.MAINMENU.ITEMS)).filter(onRealItems), this.currentItem);
46
+ onClick = async ({ index } = {}) => this.click(await this.emitOne(this.EVENTS.MAINMENU.ITEMS), index);
41
47
 
42
- click = (items, index) => index !== null && items[index] && items[index].onClick && items[index].onClick();
43
-
44
- getItems = async () => {
45
- const [items] = await this.emit(this.EVENTS.MAINMENU.ITEMS);
46
-
47
- return items;
48
- };
49
- getRealItems = async () => (await this.getItems()).filter(onRealItems);
48
+ click = (items, index) => index !== null && items[index]?.onClick?.();
50
49
  }
package/modules/view.js CHANGED
@@ -1,12 +1,14 @@
1
- import { Module } from "@vnejs/module";
1
+ import { ModuleView } from "@vnejs/module.components";
2
2
 
3
3
  import { render } from "../view";
4
4
 
5
- export class MainMenuView extends Module.View {
5
+ export class MainMenuView extends ModuleView {
6
6
  name = "mainmenu.view";
7
- locLabel = "mainMenu";
8
- animationTime = 500;
9
- renderFunc = render;
7
+
8
+ locLabel = this.PARAMS.MAINMENU_VIEW.LOC_LABEL;
9
+ animationTime = this.PARAMS.MAINMENU_VIEW.TRANSITION;
10
10
  updateEvent = this.EVENTS.MAINMENU_VIEW.UPDATE;
11
+
12
+ renderFunc = render;
11
13
  updateHandler = this.onUpdateReactComponent;
12
14
  }
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.mainmenu",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
7
+ "publish:major:plugin": "npm run publish:major",
8
+ "publish:minor:plugin": "npm run publish:minor",
9
+ "publish:patch:plugin": "npm run publish:patch",
7
10
  "publish:major": "npm version major && npm publish --access public",
8
11
  "publish:minor": "npm version minor && npm publish --access public",
9
12
  "publish:patch": "npm version patch && npm publish --access public"
10
13
  },
11
14
  "author": "",
12
15
  "license": "ISC",
13
- "description": "",
14
- "peerDependencies": {
15
- "@vnejs/shared": "*",
16
- "@vnejs/module": "*"
17
- }
16
+ "description": ""
18
17
  }
package/view/index.jsx CHANGED
@@ -1,43 +1,65 @@
1
1
  import React from "react";
2
2
  import ReactDOM from "react-dom";
3
3
 
4
- import { cn } from "@bem-react/classname";
4
+ import { PositionBox, Screen, TextControls } from "@vnejs/uis.base";
5
5
 
6
- import "./index.styl";
6
+ class MainMenuControls extends React.Component {
7
+ state = {};
7
8
 
8
- const b = cn("MainMenu");
9
+ componentDidUpdate(props) {
10
+ const { items = [] } = this.props;
9
11
 
10
- class MainMenu extends React.Component {
11
- state = {};
12
+ if (items !== props.items || this.props.realItems !== props.realItems || this.props.locs !== props.locs) this.setState({ texts: items.map(this.mapItems) });
13
+ if (this.props.currentItem !== props.currentItem) this.setState({ selectedIndex: items.findIndex(this.findSelectedIndex) });
14
+ }
15
+ componentDidMount() {
16
+ this.setState({ texts: this.props.items.map(this.mapItems), selectedIndex: this.props.items.findIndex(this.findSelectedIndex) });
17
+ }
18
+
19
+ mapItems = ({ locKey, isDisabled, isHide }, i) => ({ text: this.props.locs[locKey], isDisabled, isNotRender: isHide, value: i });
20
+ findSelectedIndex = (value) => this.props.realItems[this.props.currentItem]?.locKey === value?.locKey;
12
21
 
13
- onClick = ({ currentTarget: { dataset: { index = 0 } = {} } = {} }) =>
14
- this.props.emit(this.props.EVENTS.MAINMENU_VIEW.CLICK, { index });
22
+ onClick = (index) => this.props.emit(this.props.EVENTS.MAINMENU_VIEW.CLICK, { index });
15
23
 
16
- renderOneButton = ({ locKey, isDisabled, isHide }, i) => {
17
- const { currentItem = null, locs = {}, realItems = [] } = this.state;
18
- const isCurrent = currentItem !== null && realItems[currentItem].locKey === locKey;
24
+ render() {
25
+ const { texts = [], selectedIndex = null } = this.state;
19
26
 
20
27
  return (
21
- !isHide && (
22
- <div
23
- className={`${b("button", { isDisabled, isCurrent })} textWrap_96`}
24
- onClick={isDisabled ? undefined : this.onClick}
25
- data-index={i}
26
- key={locKey}
27
- >
28
- <span className="text">{locs[locKey]}</span>
29
- </div>
30
- )
28
+ <TextControls
29
+ selectedIndex={selectedIndex}
30
+ texts={texts}
31
+ onClick={this.onClick}
32
+ {...this.props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.controls.props}
33
+ />
31
34
  );
32
- };
35
+ }
36
+ }
37
+
38
+ class MainMenu extends React.Component {
39
+ state = {};
33
40
 
34
41
  render() {
35
- const { isShow = false, items = [] } = this.state;
42
+ const { isShow = false, items = [], bgSrc = "", currentItem = null, realItems = [], locs = {} } = this.state;
36
43
 
37
44
  return (
38
- <div className={b({ isShow })} data-html2canvas-ignore="1">
39
- <div className={b("menu")}>{items.map(this.renderOneButton)}</div>
40
- </div>
45
+ <Screen
46
+ isShow={isShow}
47
+ bgSrc={bgSrc}
48
+ zIndex={this.props.PARAMS.MAINMENU_VIEW.ZINDEX}
49
+ transition={this.props.PARAMS.MAINMENU_VIEW.TRANSITION}
50
+ withBackgroundDark={this.props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.background.withDark}
51
+ withBackgroundBlur={this.props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.background.withBlur}
52
+ >
53
+ <PositionBox {...this.props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.controls.position}>
54
+ <MainMenuControls
55
+ {...this.props}
56
+ items={items}
57
+ realItems={realItems}
58
+ currentItem={currentItem}
59
+ locs={locs}
60
+ />
61
+ </PositionBox>
62
+ </Screen>
41
63
  );
42
64
  }
43
65
  }
package/view/index.styl DELETED
@@ -1,46 +0,0 @@
1
- .MainMenu
2
- position: absolute
3
- top: 0
4
- bottom: 0
5
- left: 0
6
- right: 0
7
- opacity: 0
8
- pointer-events: none
9
- transition: opacity 500ms
10
- z-index: 3000
11
-
12
- &_isShow
13
- opacity: 1
14
- pointer-events: all
15
-
16
- &-menu
17
- position: absolute
18
- bottom: 6.25%
19
- left: 6.25%
20
- display: flex
21
- align-items: flex-start
22
- justify-content: flex-end
23
- flex-direction: column
24
- overflow: auto
25
- gap: calc(50 / 2160 * 100%)
26
- height: 100%
27
- z-index: 3100
28
-
29
- &-button
30
- line-height: 125%
31
- opacity: 0.5
32
- color: white
33
- text-align: center
34
- font-family: 'Montserrat'
35
- transition: color 300ms, text-shadow 300ms
36
- color: rgba(255,255,255,0.6)
37
- text-shadow: initial
38
-
39
- &:not(&_isDisabled)
40
- cursor: pointer
41
- opacity: 1
42
-
43
- &_isCurrent,
44
- &:not(&_isDisabled):hover
45
- color: rgba(255,255,255,0.85)
46
- text-shadow: 0px 5px 25px rgba(255,255,255,0.75)
@@ -1,23 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <svg width="3840" height="2160" viewBox="0 0 3840 2160" fill="none" xmlns="http://www.w3.org/2000/svg">
3
- <defs>
4
- <clipPath id="clip_path_1">
5
- <rect width="3840" height="2160" />
6
- </clipPath>
7
- </defs>
8
- <g clip-path="url(#clip_path_1)">
9
- <rect width="3840" height="2160" fill="#FFFFFF" fill-rule="evenodd" fill-opacity="0" />
10
- <g fill="#512DA8" fill-rule="evenodd" fill-opacity="0" transform="translate(734 -423)">
11
- <path id="Треугольник" d="M0 0L2257.32 753.47L753.469 2257.32L0 0Z" />
12
- <path d="M0.395996 1.1864L753.116 2256.26L753.469 2257.32L754.26 2256.53L2256.53 754.261L2257.32 753.47L2256.26 753.116L1.1864 0.396027L0 0L0.395996 1.1864ZM1.5824 1.58243L753.906 2255.47L2255.47 753.907L1.5824 1.58243Z" fill="#FFFFFF" fill-rule="evenodd" fill-opacity="0.251" />
13
- </g>
14
- <g fill="#512DA8" fill-rule="evenodd" fill-opacity="0" transform="translate(734 327)">
15
- <path id="Треугольник" d="M2257.32 0L0 753.47L1503.85 2257.32L2257.32 0Z" />
16
- <path d="M2257.32 0L2256.14 0.395996L1.0603 753.116L0 753.47L0.790466 754.261L1503.06 2256.53L1503.85 2257.32L1504.21 2256.26L2256.93 1.18643L2257.32 0ZM2255.74 1.58243L1503.42 2255.47L1.85077 753.907L2255.74 1.58243Z" fill="#FFFFFF" fill-rule="evenodd" fill-opacity="0.251" />
17
- </g>
18
- <g fill="#512DA8" fill-rule="evenodd" fill-opacity="0" transform="translate(0 415)">
19
- <path id="Треугольник" d="M0 1063.38L3840 2126.77L3840 0L0 1063.38Z" />
20
- <path d="M1.87353 1063.9L0 1063.38L1.87353 1062.87L3839 0.276917L3840 0L3840 2126.77L3839 2126.49L1.87353 1063.9ZM3.74707 1063.38L3839 2125.45L3839 1.31458L3.74707 1063.38Z" fill="#FFFFFF" fill-rule="evenodd" fill-opacity="0.251" />
21
- </g>
22
- </g>
23
- </svg>