@vnejs/plugins.view.coralina.settings.defaults 0.1.0 → 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,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]);
@@ -10,8 +10,7 @@ const mapTabInfo = ({ ...tabInfo }) => {
10
10
  export class SettingsDefaultsController extends ModuleController {
11
11
  name = "settings.defaults.controller";
12
12
 
13
- bgName = "Menu/save";
14
-
13
+ bgName = this.PARAMS.SETTINGS_DEFAULTS_VIEW.BACKGROUND;
15
14
  updateEvent = this.EVENTS.SETTINGS_DEFAULTS.UPDATE;
16
15
 
17
16
  subscribe = () => {
@@ -21,11 +20,7 @@ export class SettingsDefaultsController extends ModuleController {
21
20
  this.on(this.EVENTS.SETTINGS.CHANGED, this.onSettingChange);
22
21
  };
23
22
 
24
- init = () => {
25
- this.tab = mapTabInfo(this.PARAMS.SETTINGS_VIEW.TABS.DEFAULT);
26
- };
27
-
28
- beforeShow = async () => this.updateState({ bgSrc: (await this.loadBgMedia()).src, tab: this.tab, currentTab: 0 });
23
+ beforeShow = async () => this.updateState({ bgSrc: (await this.loadBgMedia()).src, tab: mapTabInfo(this.PARAMS.SETTINGS_VIEW.TABS.DEFAULT), currentTab: 0 });
29
24
 
30
25
  emitFunc = (func) => func({ SETTINGS: this.SETTINGS, CONST: this.CONST, platform: window.VneCore.getPlatform() });
31
26
 
package/modules/view.js CHANGED
@@ -5,10 +5,10 @@ import { render } from "../view";
5
5
  export class SettingsDefaultsView extends ModuleView {
6
6
  name = "settings.defaults.view";
7
7
 
8
- locLabel = "settings";
9
- animationTime = 300;
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
11
 
12
12
  renderFunc = render;
13
- updateHandler = this.onUpdateReactComponent;
13
+ updateHandler = this.onUpdateStoreComponent;
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.settings.defaults",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/view/index.jsx CHANGED
@@ -1,74 +1,54 @@
1
- import React from "react";
2
- import ReactDOM from "react-dom";
1
+ import React, { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { createRoot } from "react-dom/client";
3
3
 
4
4
  import { Flex, Text, Screen, Settings, PositionBox } from "@vnejs/uis.base";
5
5
 
6
- export const TRANSITION = 500;
7
- export const ZINDEX = 4000;
8
-
9
- const EMPTY_ARRAY = [];
10
-
11
- class SettingsDefaults extends React.Component {
12
- state = { isShow: false, locs: {}, tokens: EMPTY_ARRAY, tab: { options: [], fields: [] } };
13
-
14
- mapTokens = (token) => ({ token });
15
- recalcTokens = () => this.setState({ tokens: [...this.props.text].map(this.mapTokens) });
16
-
17
- componentDidUpdate(props) {
18
- if (props.text !== this.props.text || (!props.isShow && this.props.isShow)) this.recalcTokens();
19
- }
20
-
21
- onClickConfirm = () => this.props.emit(this.props.EVENTS.SETTINGS_DEFAULTS.CONFIRM);
22
-
23
- mapFields = ({ locKey = "", type = "", settingKey = "", options = [], titleToggledLocKey = "", titleUntoggledLocKey = "", ...props } = {}) => {
24
- const { shared: { settings = {} } = {} } = this.props;
25
- const { locs = {} } = this.state;
26
-
27
- const onChange = (value) => this.props.emit(this.props.EVENTS.SETTINGS.SET, { name: settingKey, value });
28
-
29
- const titles = { title: locs[locKey], titleToggled: locs[titleToggledLocKey], titleUntoggled: locs[titleUntoggledLocKey] };
30
-
31
- return { ...titles, value: settings[settingKey], type, onChange, props, options };
32
- };
33
-
34
- render() {
35
- const { isShow = false, locs = {}, tab = {}, bgSrc = "" } = this.state;
36
-
37
- return (
38
- <Screen
39
- isShow={isShow}
40
- zIndex={ZINDEX}
41
- transition={TRANSITION}
42
- bgSrc={bgSrc}
43
- >
44
- <PositionBox isCentered={true}>
45
- <Flex
46
- direction={Flex.DIRECTION.COLUMN}
47
- gap={120}
48
- >
49
- <Text
50
- align={Text.ALIGNS.CENTER}
51
- width={3120}
52
- text={locs[tab.titleLocKey]}
53
- />
54
- <Settings
55
- selectedIndex={0}
56
- selectedIndexInner={0}
57
- transition={TRANSITION}
58
- settings={tab.fields.map(this.mapFields)}
59
- />
60
-
61
- <Text
62
- align={Text.ALIGNS.CENTER}
63
- width={3120}
64
- text={locs[tab.acceptLocKey]}
65
- onClick={this.onClickConfirm}
66
- />
67
- </Flex>
68
- </PositionBox>
69
- </Screen>
70
- );
71
- }
72
- }
73
-
74
- export const render = (props, root, resolve) => ReactDOM.render(<SettingsDefaults {...props} />, root, resolve);
6
+ const SettingsDefaults = ({ store, onMount, ...props } = {}) => {
7
+ const [{ isShow = false, locs = {}, tab = {}, bgSrc = "" }, setState] = useState({});
8
+
9
+ useEffect(() => store.subscribe(setState), []);
10
+ useEffect(() => void onMount(), []);
11
+
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 });
15
+
16
+ const titles = { title: locs[locKey], titleToggled: locs[titleToggledLocKey], titleUntoggled: locs[titleUntoggledLocKey] };
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), []);
23
+
24
+ const settings = useMemo(() => (tab.fields ? tab.fields.map(mapFields) : []), [tab, mapFields]);
25
+
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
+ );
32
+
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>
51
+ );
52
+ };
53
+
54
+ export const render = (props, root) => createRoot(root).render(<SettingsDefaults {...props} />);