@vnejs/plugins.view.coralina.settings.defaults 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,16 @@
1
+ export const BACKGROUND = "Menu/save";
2
+
3
+ export const TRANSITION = 500;
4
+ export const ZINDEX = 4000;
5
+ export const LOC_LABEL = "settings";
6
+
7
+ const TEXT_PROPS = { align: "center", width: 3120 };
8
+
9
+ export const VIEW_PROPS = {
10
+ screen: { withBackgroundDark: true, withBackgroundBlur: false, transition: TRANSITION, zIndex: ZINDEX },
11
+ position: { isCentered: true },
12
+ flex: { direction: "column", gap: 120 },
13
+ title: TEXT_PROPS,
14
+ settings: { transition: TRANSITION },
15
+ accept: TEXT_PROPS,
16
+ };
package/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { regPlugin } from "@vnejs/shared";
2
2
 
3
+ import * as params from "./const/params";
4
+
3
5
  import { SettingsDefaultsController } from "./modules/controller";
4
6
  import { SettingsDefaultsView } from "./modules/view";
5
7
 
6
- regPlugin("SETTINGS_DEFAULTS_VIEW", {}, [SettingsDefaultsController, SettingsDefaultsView]);
8
+ regPlugin("SETTINGS_DEFAULTS_VIEW", { params }, [SettingsDefaultsController, SettingsDefaultsView]);
@@ -1,8 +1,16 @@
1
- import { Module } from "@vnejs/module";
1
+ import { ModuleController } from "@vnejs/module.components";
2
2
 
3
- export class SettingsDefaultsController extends Module.Controller {
3
+ const mapField = (field) => ({ ...field, isNotRender: typeof field.isNotShowFunc === "function" ? field.isNotShowFunc() : false });
4
+ const mapTabInfo = ({ ...tabInfo }) => {
5
+ if (tabInfo.options) tabInfo.options = [...tabInfo.options.map(mapField)];
6
+
7
+ return tabInfo;
8
+ };
9
+
10
+ export class SettingsDefaultsController extends ModuleController {
4
11
  name = "settings.defaults.controller";
5
12
 
13
+ bgName = this.PARAMS.SETTINGS_DEFAULTS_VIEW.BACKGROUND;
6
14
  updateEvent = this.EVENTS.SETTINGS_DEFAULTS.UPDATE;
7
15
 
8
16
  subscribe = () => {
@@ -12,7 +20,7 @@ export class SettingsDefaultsController extends Module.Controller {
12
20
  this.on(this.EVENTS.SETTINGS.CHANGED, this.onSettingChange);
13
21
  };
14
22
 
15
- beforeShow = () => this.updateState({ defaultSettingsItems: window.VNESettingsDefaultsItems.map(this.emitFunc) });
23
+ beforeShow = async () => this.updateState({ bgSrc: (await this.loadBgMedia()).src, tab: mapTabInfo(this.PARAMS.SETTINGS_VIEW.TABS.DEFAULT), currentTab: 0 });
16
24
 
17
25
  emitFunc = (func) => func({ SETTINGS: this.SETTINGS, CONST: this.CONST, platform: window.VneCore.getPlatform() });
18
26
 
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 SettingsDefaultsView extends Module.View {
5
+ export class SettingsDefaultsView extends ModuleView {
6
6
  name = "settings.defaults.view";
7
- locLabel = "settings_defaults";
8
- animationTime = 300;
9
- renderFunc = render;
7
+
8
+ locLabel = this.PARAMS.SETTINGS_DEFAULTS_VIEW.LOC_LABEL;
9
+ animationTime = this.PARAMS.SETTINGS_DEFAULTS_VIEW.TRANSITION;
10
10
  updateEvent = this.EVENTS.SETTINGS_DEFAULTS.UPDATE;
11
- updateHandler = this.onUpdateReactComponent;
11
+
12
+ renderFunc = render;
13
+ updateHandler = this.onUpdateStoreComponent;
12
14
  }
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.settings.defaults",
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,59 +1,54 @@
1
- import React from "react";
1
+ import React, { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
 
4
- import { cn } from "@bem-react/classname";
4
+ import { Flex, Text, Screen, Settings, PositionBox } from "@vnejs/uis.base";
5
5
 
6
- import "./index.styl";
6
+ const SettingsDefaults = ({ store, onMount, ...props } = {}) => {
7
+ const [{ isShow = false, locs = {}, tab = {}, bgSrc = "" }, setState] = useState({});
7
8
 
8
- const b = cn("SettingsDefaults");
9
+ useEffect(() => store.subscribe(setState), []);
10
+ useEffect(() => void onMount(), []);
9
11
 
10
- class SettingsDefaults extends React.Component {
11
- state = { locs: {} };
12
+ const mapFields = useCallback(
13
+ ({ locKey = "", type = "", settingKey = "", options = [], titleToggledLocKey = "", titleUntoggledLocKey = "", ...fieldProps } = {}) => {
14
+ const onChange = (value) => props.emit(props.EVENTS.SETTINGS.SET, { name: settingKey, value });
12
15
 
13
- onClickValue = (e) => {
14
- const { value, settingKey } = e.currentTarget.dataset;
16
+ const titles = { title: locs[locKey], titleToggled: locs[titleToggledLocKey], titleUntoggled: locs[titleUntoggledLocKey] };
15
17
 
16
- return this.props.emit(this.props.EVENTS.SETTINGS.SET, { name: settingKey, value });
17
- };
18
+ return { ...titles, value: props.shared.settings[settingKey], type, onChange, props: fieldProps, options };
19
+ },
20
+ [locs],
21
+ );
22
+ const onAccept = useCallback(() => props.emit(props.EVENTS.SETTINGS_DEFAULTS.CONFIRM), []);
18
23
 
19
- onClickConfirm = () => this.props.emit(this.props.EVENTS.SETTINGS_DEFAULTS.CONFIRM);
24
+ const settings = useMemo(() => (tab.fields ? tab.fields.map(mapFields) : []), [tab, mapFields]);
20
25
 
21
- renderValues = ({ titleKey = "", value = "" } = {}, settingKey = "") => (
22
- <div
23
- className={b("value", { current: this.props.shared.settings[settingKey] === value }, ["textWrap_120"])}
24
- onClick={this.onClickValue}
25
- data-value={value}
26
- data-setting-key={settingKey}
27
- key={value}
28
- >
29
- <span className="text">{this.state.locs[titleKey]}</span>
30
- </div>
26
+ const propsTitle = useMemo(() => ({ ...props.PARAMS.SETTINGS_DEFAULTS_VIEW.VIEW_PROPS.title, text: locs[tab.titleLocKey] }), [locs, tab]);
27
+ const propsSettings = useMemo(() => ({ ...props.PARAMS.SETTINGS_DEFAULTS_VIEW.VIEW_PROPS.settings, settings }), [settings]);
28
+ const propsAccept = useMemo(
29
+ () => ({ ...props.PARAMS.SETTINGS_DEFAULTS_VIEW.VIEW_PROPS.accept, text: locs[tab.acceptLocKey], onClick: onAccept }),
30
+ [locs, tab],
31
31
  );
32
32
 
33
- renderItem = ({ titleKey = "", settingKey = "", values = [] } = {}, i) => (
34
- <div className={b("item")} key={settingKey}>
35
- <div className={b("name", ["textWrap_120"])}>
36
- <span className="text">{this.state.locs[titleKey]}</span>
37
- </div>
38
- <div className={b("values")}>{values.map((value) => this.renderValues(value, settingKey))}</div>
39
- </div>
33
+ return (
34
+ <Screen
35
+ {...props.PARAMS.SETTINGS_DEFAULTS_VIEW.VIEW_PROPS.screen}
36
+ isShow={isShow}
37
+ bgSrc={bgSrc}
38
+ >
39
+ <PositionBox {...props.PARAMS.SETTINGS_DEFAULTS_VIEW.VIEW_PROPS.position}>
40
+ <Flex {...props.PARAMS.SETTINGS_DEFAULTS_VIEW.VIEW_PROPS.flex}>
41
+ <Text {...propsTitle} />
42
+ <Settings
43
+ {...propsSettings}
44
+ selectedIndex={0}
45
+ selectedIndexInner={0}
46
+ />
47
+ <Text {...propsAccept} />
48
+ </Flex>
49
+ </PositionBox>
50
+ </Screen>
40
51
  );
52
+ };
41
53
 
42
- render() {
43
- const { isShow = false, defaultSettingsItems = [], locs = {} } = this.state;
44
-
45
- return (
46
- <div className={b({ isShow })} data-html2canvas-ignore="1">
47
- <div className={b("title", ["textWrap_120"])}>
48
- <span className="text">{locs.title}</span>
49
- </div>
50
- <div className={b("items")}>{defaultSettingsItems.map(this.renderItem)}</div>
51
- <div className={b("confirm", ["textWrap_120"])} onClick={this.onClickConfirm}>
52
- <span className="text">{locs.confirm}</span>
53
- </div>
54
- </div>
55
- );
56
- }
57
- }
58
-
59
- export const render = (props, root, resolve) => ReactDOM.render(<SettingsDefaults {...props} />, root, resolve);
54
+ export const render = (props, root) => ReactDOM.render(<SettingsDefaults {...props} />, root);
package/view/index.styl DELETED
@@ -1,62 +0,0 @@
1
- .SettingsDefaults
2
- position: absolute
3
- top: 0
4
- right: 0
5
- bottom: 0
6
- left: 0
7
-
8
- display: flex
9
- align-items: center
10
- justify-content: center
11
- flex-direction: column;
12
- gap: calc(180 / 2160* 100%);
13
-
14
- color: rgba(255,255,255,0.6);
15
- font-family: Montserrat;
16
- text-align: center
17
-
18
- opacity: 0
19
- pointer-events: none
20
-
21
- transition: color 300ms, opacity 1000ms
22
-
23
- &-items
24
- width: 100%
25
-
26
- &-item
27
- display: flex
28
- justify-content: space-evenly
29
-
30
- &-item ~ &-item
31
- margin-top: 2.345%
32
-
33
- &-name
34
- width: 20%
35
-
36
- &-values
37
- width: 65%
38
- display: flex
39
- justify-content: space-evenly
40
-
41
- &-value
42
- cursor: pointer
43
- transition: color 300ms
44
-
45
- &:hover
46
- color: rgba(255,255,255,0.75);
47
-
48
- &_current
49
- color: rgba(255,255,255,0.9);
50
-
51
- &-confirm
52
- color: rgba(255,255,255,0.6);
53
- cursor: pointer
54
- transition: color 300ms
55
-
56
- &:hover
57
- color: rgba(255,255,255,1);
58
-
59
- &_isShow
60
- pointer-events: all
61
- opacity: 1
62
-