@vnejs/plugins.views.settings 0.1.3 → 0.2.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.
Files changed (39) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +6 -0
  3. package/dist/modules/controller.d.ts +38 -0
  4. package/dist/modules/controller.js +117 -0
  5. package/dist/modules/view.d.ts +11 -0
  6. package/dist/modules/view.js +10 -0
  7. package/dist/types.d.ts +10 -0
  8. package/dist/types.js +1 -0
  9. package/dist/utils/settings.d.ts +25 -0
  10. package/dist/utils/settings.js +1 -0
  11. package/dist/view/SettingsExampleText.d.ts +9 -0
  12. package/dist/view/SettingsExampleText.js +25 -0
  13. package/dist/view/SettingsTabContent.d.ts +15 -0
  14. package/dist/view/SettingsTabContent.js +32 -0
  15. package/dist/view/index.d.ts +3 -0
  16. package/dist/view/index.js +18 -0
  17. package/package.json +52 -7
  18. package/src/index.ts +9 -0
  19. package/src/modules/controller.ts +161 -0
  20. package/src/modules/view.ts +22 -0
  21. package/src/tests/controller.test.ts +93 -0
  22. package/src/tests/setup.ts +44 -0
  23. package/src/types.ts +20 -0
  24. package/src/utils/settings.ts +28 -0
  25. package/src/view/SettingsExampleText.tsx +61 -0
  26. package/src/view/SettingsTabContent.tsx +118 -0
  27. package/src/view/index.tsx +63 -0
  28. package/tsconfig.json +10 -0
  29. package/const/events.js +0 -7
  30. package/const/params.js +0 -43
  31. package/index.js +0 -9
  32. package/modules/controller.js +0 -132
  33. package/modules/view.js +0 -14
  34. package/view/components/SettingsControls.jsx +0 -22
  35. package/view/components/SettingsCross.jsx +0 -13
  36. package/view/components/SettingsExampleText.jsx +0 -40
  37. package/view/components/SettingsTabContent.jsx +0 -66
  38. package/view/components/index.js +0 -4
  39. package/view/index.jsx +0 -42
@@ -1,13 +0,0 @@
1
- import { useMemo } from "react";
2
-
3
- import { PositionBox, Svg } from "@vnejs/uis.react";
4
-
5
- export const SettingsCross = (props = {}) => {
6
- const propsCross = useMemo(() => ({ ...props.PARAMS.SETTINGS_VIEW.VIEW_PROPS.cross.svg, onClick: () => props.emit(props.EVENTS.SETTINGS_VIEW.HIDE) }), []);
7
-
8
- return (
9
- <PositionBox {...props.PARAMS.SETTINGS_VIEW.VIEW_PROPS.cross.position}>
10
- <Svg.Cross {...propsCross} />
11
- </PositionBox>
12
- );
13
- };
@@ -1,40 +0,0 @@
1
- import { useEffect, useMemo, useState } from "react";
2
-
3
- import { SmoothText } from "@vnejs/uis.react";
4
-
5
- import { tokenizeText } from "@vnejs/helpers";
6
-
7
- const EMPTY_ARRAY = [];
8
-
9
- export const SettingsExampleText = ({ isShow = false, locs = {}, ...props } = {}) => {
10
- const [tokens, setTokens] = useState(EMPTY_ARRAY);
11
-
12
- const isForce = Boolean(props.shared.textNoAnimationSources.length);
13
-
14
- const text = useMemo(() => locs["fields.text.example"] ?? "", [locs]);
15
-
16
- useEffect(() => {
17
- if (isShow) setTokens(tokenizeText(text));
18
- }, [isShow, text]);
19
-
20
- useEffect(() => {
21
- if (isShow || isForce) return;
22
-
23
- const tm = setTimeout(() => setTokens(EMPTY_ARRAY), props.PARAMS.SETTINGS_VIEW.TRANSITION);
24
-
25
- return () => clearTimeout(tm);
26
- }, [isShow]);
27
-
28
- return (
29
- <SmoothText
30
- tokens={tokens}
31
- isForce={isForce}
32
- charDelay={props.PARAMS.TEXT.TOKEN_RENDER_DELAY / props.shared.settings[props.SETTINGS.TEXT.TOKEN_RENDER_SPEED]}
33
- transition={props.PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.transition}
34
- size={props.PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.size}
35
- color={props.PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.color}
36
- height={props.PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.height}
37
- scrollBarTextSize={props.shared.settings[props.SETTINGS.TEXTSIZE.VALUE]}
38
- />
39
- );
40
- };
@@ -1,66 +0,0 @@
1
- import { useCallback } from "react";
2
-
3
- import { PositionBox, Settings, Flex } from "@vnejs/uis.react";
4
-
5
- import { SettingsExampleText } from "./SettingsExampleText";
6
-
7
- export const SettingsTabContent = ({ isShow = false, isForce = false, locs = {}, fields = [], ...props } = {}) => {
8
- const mapFields = useCallback(
9
- ({ locKey = "", type = "", settingKey = "", options = [], titleToggledLocKey = "", titleUntoggledLocKey = "", valueMap = "", ...fieldProps } = {}) => {
10
- const onChange = (value) => props.emit(props.EVENTS.SETTINGS.SET, { name: settingKey, value });
11
-
12
- const titles = { title: locs[locKey], titleToggled: locs[titleToggledLocKey], titleUntoggled: locs[titleUntoggledLocKey] };
13
- const valueMapReal = valueMap ? props.PARAMS.SETTINGS_VIEW.VALUE_MAPS[valueMap] : null;
14
-
15
- const optionsReal = options.map((option) => {
16
- const result = { ...option };
17
-
18
- if (option.locKey) {
19
- delete result.locKey;
20
- result.text = locs[option.locKey];
21
- }
22
-
23
- if (option.action) {
24
- delete result.action;
25
- result.onClick = () => props.PARAMS.SETTINGS_VIEW.ACTIONS[option.action](props, locs);
26
- }
27
-
28
- return result;
29
- });
30
-
31
- return { ...titles, value: props.shared.settings[settingKey], type, onChange, props: fieldProps, options: optionsReal, valueMap: valueMapReal };
32
- },
33
- [locs],
34
- );
35
-
36
- return (
37
- <PositionBox
38
- isCentered={true}
39
- opacity={isShow ? 1 : 0}
40
- transition={isForce ? 0 : props.PARAMS.SETTINGS_VIEW.TRANSITION}
41
- >
42
- <Flex
43
- direction={Flex.DIRECTION.COLUMN}
44
- gap={props.PARAMS.SETTINGS_VIEW.VIEW_PROPS.fieldsGap}
45
- >
46
- <Settings
47
- selectedIndex={isShow ? props.currentItem : -1}
48
- selectedIndexInner={isShow ? props.currentItemInner : -1}
49
- transition={isForce ? 0 : props.PARAMS.SETTINGS_VIEW.TRANSITION}
50
- settings={fields.map(mapFields)}
51
- {...props.PARAMS.SETTINGS_VIEW.VIEW_PROPS.fieldProps}
52
- />
53
-
54
- {props.showTextExample && (
55
- <SettingsExampleText
56
- {...props}
57
- locs={locs}
58
- isShow={isShow}
59
- isForce={isForce}
60
- text={locs["fields.text.example"] || ""}
61
- />
62
- )}
63
- </Flex>
64
- </PositionBox>
65
- );
66
- };
@@ -1,4 +0,0 @@
1
- export * from "./SettingsControls";
2
- export * from "./SettingsCross";
3
- export * from "./SettingsExampleText";
4
- export * from "./SettingsTabContent";
package/view/index.jsx DELETED
@@ -1,42 +0,0 @@
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 { SettingsControls, SettingsCross, SettingsTabContent } from "./components";
7
-
8
- const Settings = ({ store, onMount, ...props } = {}) => {
9
- const [state, setState] = useState({});
10
-
11
- const { isShow = false, isForce = false, bgSrc = "", tabs = [], locs = {}, currentTab = 0, currentItem = null, currentItemInner = null } = state;
12
-
13
- useEffect(() => store.subscribe(setState), []);
14
- useEffect(() => void onMount(), []);
15
-
16
- const propsTab = useMemo(() => ({ ...props, isForce, currentItem, currentItemInner, locs }), [isForce, currentItem, currentItemInner, locs]);
17
- const propsScreen = useMemo(() => ({ ...props.PARAMS.SETTINGS_VIEW.VIEW_PROPS.screen, isShow, isForce, bgSrc }), [isShow, isForce, bgSrc]);
18
- const propsControls = useMemo(() => ({ ...props, locs, tabs, currentTab, isForce }), [locs, tabs, currentTab, isForce]);
19
-
20
- const renderTabContent = useCallback(
21
- ({ fields = [], showTextExample = false } = {}, i) => (
22
- <SettingsTabContent
23
- {...propsTab}
24
- key={i}
25
- isShow={currentTab === i}
26
- fields={fields}
27
- showTextExample={showTextExample}
28
- />
29
- ),
30
- [currentTab, propsTab],
31
- );
32
-
33
- return (
34
- <Screen {...propsScreen}>
35
- <SettingsCross {...props} />
36
- <SettingsControls {...propsControls} />
37
- {Object.values(tabs).map(renderTabContent)}
38
- </Screen>
39
- );
40
- };
41
-
42
- export const render = (props, root) => createRoot(root).render(<Settings {...props} />);