@vnejs/plugins.view.coralina.choose 0.0.2 → 0.1.0

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.
@@ -1,6 +1,8 @@
1
- import { Module } from "@vnejs/module";
1
+ import { ModuleController } from "@vnejs/module.components";
2
2
 
3
- export class ChooseController extends Module.Controller {
3
+ import { ZINDEX } from "../view";
4
+
5
+ export class ChooseController extends ModuleController {
4
6
  name = "choose.controller";
5
7
 
6
8
  maxCurrentItem = 0;
@@ -12,12 +14,11 @@ export class ChooseController extends Module.Controller {
12
14
  [this.CONST.CONTROLS.BUTTONS.MENU]: this.emitGameMenu,
13
15
  [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: this.emitGameMenu,
14
16
  [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => this.emit(this.EVENTS.INTERFACE.HISTORY_BACK),
15
- [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decCurrentItem,
16
- [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incCurrentItem,
17
- [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () =>
18
- this.currentItem !== null && this.emit(this.EVENTS.CHOOSE.OPTION, { index: this.currentItem }),
17
+ [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => this.onArrow(this.decCurrentItem),
18
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => this.onArrow(this.incCurrentItem),
19
+ [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => this.currentItem !== null && this.emit(this.EVENTS.CHOOSE.OPTION, { index: this.currentItem }),
19
20
  };
20
- controlsIndex = 2000;
21
+ controlsIndex = ZINDEX;
21
22
 
22
23
  subscribe = () => {
23
24
  this.on(this.EVENTS.CHOOSE.SHOW, this.onShow);
@@ -26,8 +27,14 @@ export class ChooseController extends Module.Controller {
26
27
 
27
28
  beforeShow = async () => {
28
29
  this.updateState({ ...this.globalState.choose });
29
- this.currentItem = null;
30
30
  this.maxCurrentItem = this.state.options.length - 1;
31
+
32
+ await this.emit(this.EVENTS.INTERFACE.HIDE);
33
+ };
34
+
35
+ onArrow = (cb) => {
36
+ cb();
37
+ while (this.state.options?.[this.currentItem].hided) cb();
31
38
  };
32
39
 
33
40
  getDefaultState = () => ({ options: [], args: {} });
package/modules/view.js CHANGED
@@ -1,10 +1,10 @@
1
- import { Module } from "@vnejs/module";
1
+ import { ModuleView } from "@vnejs/module.components";
2
2
 
3
- import { render } from "../view";
3
+ import { render, TRANSITION } from "../view";
4
4
 
5
- export class ChooseView extends Module.View {
5
+ export class ChooseView extends ModuleView {
6
6
  name = "choose.view";
7
- animationTime = 300;
7
+ animationTime = TRANSITION;
8
8
  renderFunc = render;
9
9
  updateEvent = this.EVENTS.CHOOSE.UPDATE;
10
10
  updateHandler = this.onUpdateReactComponent;
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.choose",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
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,40 +1,79 @@
1
1
  import React from "react";
2
2
  import ReactDOM from "react-dom";
3
3
 
4
- import { cn } from "@bem-react/classname";
4
+ import { Flex, PositionBox, Screen, Text, TextControls } from "@vnejs/uis.base";
5
5
 
6
- import "./index.styl";
7
-
8
- const b = cn("Choose");
6
+ export const TRANSITION = 300;
7
+ export const ZINDEX = 1200;
9
8
 
10
9
  class Choose extends React.Component {
11
- onOptionClick = (e) =>
12
- this.props.emit(this.props.EVENTS.CHOOSE.OPTION, { index: Number(e.currentTarget.dataset.index) });
13
-
14
- renderOption = ({ text, disabled, hided, coords: [x, y] }, index) =>
15
- !hided && (
16
- <div
17
- className={b(
18
- "option",
19
- { disabled, isCurrent: index === this.state.currentItem, coords: Boolean(x) && Boolean(y) },
20
- ["textWrap_60"]
21
- )}
22
- style={{ left: `${x}%`, top: `${y}%` }}
23
- data-index={index}
24
- key={index}
25
- onClick={disabled ? undefined : this.onOptionClick}
26
- >
27
- <span className="text"> {text}</span>
28
- </div>
29
- );
10
+ state = { isShow: false, isForce: false, options: [], optionsRegular: [], optionsWithCoords: [] };
11
+
12
+ onClick = (index) => this.props.emit(this.props.EVENTS.CHOOSE.OPTION, { index });
13
+
14
+ componentDidUpdate(props, state) {
15
+ if (state.options !== this.state.options || state.currentItem !== this.state.currentItem) {
16
+ const { options = [], currentItem = null } = this.state;
17
+
18
+ const textsInfo = options.map(({ text, hided, coords, disabled }, i) => ({
19
+ text,
20
+ isNotRender: Boolean(hided),
21
+ value: i,
22
+ isDisabled: Boolean(disabled),
23
+ isSelected: currentItem === i,
24
+ coords,
25
+ }));
26
+
27
+ this.setState({ optionsRegular: textsInfo.filter((e) => !e.coords), optionsWithCoords: textsInfo.filter((e) => e.coords) });
28
+ }
29
+ }
30
+
31
+ renderOptionWithCoords = ({ text, isDisabled, isNotRender, value, coords: [x, y] } = {}) => (
32
+ <PositionBox
33
+ left={`${x}%`}
34
+ top={`${y}%`}
35
+ translateX={-50}
36
+ translateY={-50}
37
+ isNotRender={isNotRender}
38
+ key={value}
39
+ >
40
+ <Text
41
+ isSelected={this.state.currentItem === value}
42
+ isDisabled={isDisabled}
43
+ textSize={96}
44
+ text={text}
45
+ onClick={this.onClick}
46
+ value={value}
47
+ />
48
+ </PositionBox>
49
+ );
30
50
 
31
51
  render() {
32
- const { isShow = false, options = [], isForce = false } = this.state || {};
52
+ const { isShow = false, isForce = false, optionsRegular = [], optionsWithCoords = [] } = this.state;
33
53
 
34
54
  return (
35
- <div className={b({ isShow, isForce })} vne-autoread-disable={isShow ? "1" : ""}>
36
- <div className={b("options")}>{options.map(this.renderOption)}</div>
37
- </div>
55
+ <Screen
56
+ isShow={isShow}
57
+ isForce={isForce}
58
+ zIndex={ZINDEX}
59
+ withBlur={true}
60
+ withDark={true}
61
+ transition={TRANSITION}
62
+ isDisableAutoread={true}
63
+ isIgnoreOnScreenshot={false}
64
+ >
65
+ {optionsWithCoords.map(this.renderOptionWithCoords)}
66
+ <PositionBox isCentered={true}>
67
+ <TextControls
68
+ flexDirection={Flex.DIRECTION.COLUMN}
69
+ flexGap={60}
70
+ textSize={96}
71
+ textAlign={Text.ALIGNS.CENTER}
72
+ texts={optionsRegular}
73
+ onClick={this.onClick}
74
+ />
75
+ </PositionBox>
76
+ </Screen>
38
77
  );
39
78
  }
40
79
  }
package/view/index.styl DELETED
@@ -1,47 +0,0 @@
1
- .Choose
2
- position: absolute
3
- top: 0
4
- right: 0
5
- bottom: 0
6
- left: 0
7
- background: linear-gradient(0deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.25) 14.04%, rgba(0,0,0,0.45) 27.9%, rgba(0,0,0,0.55) 45.51%, rgba(0,0,0,0.7) 66.85%, rgba(0,0,0,0.85) 100%);
8
- display: flex
9
- justify-content: center
10
- align-items: center
11
- z-index: 3000
12
- opacity: 0
13
- pointer-events: none
14
- font-family: Montserrat
15
-
16
- &-options
17
- display: flex
18
- flex-direction: column
19
- justify-content: center
20
- align-items: center
21
- height: 100%
22
- gap: calc(50 / 2160 * 100%)
23
-
24
- &-option
25
- cursor: pointer
26
- color: rgba(255,255,255,0.6)
27
- transition: text-shadow 300ms, transform 300ms
28
-
29
- &_coords
30
- position: absolute
31
- transform: translate(-50%, -50%)
32
-
33
- &:hover,
34
- &_isCurrent
35
- text-shadow: 0px 5px 25px rgba(255,255,255,0.75);
36
- transform: scale(1.2)
37
-
38
- &_coords:hover
39
- &_coords&_isCurrent
40
- transform: translate(-50%, -50%) scale(1.2)
41
-
42
- &_isShow
43
- opacity: 1
44
- pointer-events: all
45
-
46
- &:not(&_isForce)
47
- transition: opacity 300ms