@vnejs/plugins.controllers.common.settings 0.0.0-stage → 0.2.17

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 (37) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +13 -0
  3. package/dist/modules/fields.controller.arrows.d.ts +18 -0
  4. package/dist/modules/fields.controller.arrows.horizontal.d.ts +12 -0
  5. package/dist/modules/fields.controller.arrows.horizontal.js +11 -0
  6. package/dist/modules/fields.controller.arrows.js +33 -0
  7. package/dist/modules/fields.controller.d.ts +44 -0
  8. package/dist/modules/fields.controller.js +157 -0
  9. package/dist/modules/fields.view.d.ts +10 -0
  10. package/dist/modules/fields.view.js +9 -0
  11. package/dist/types.d.ts +23 -0
  12. package/dist/types.js +1 -0
  13. package/dist/utils/settings.d.ts +6 -0
  14. package/dist/utils/settings.js +1 -0
  15. package/dist/view/SettingsExampleText.d.ts +9 -0
  16. package/dist/view/SettingsExampleText.js +23 -0
  17. package/dist/view/SettingsTabContent.d.ts +15 -0
  18. package/dist/view/SettingsTabContent.js +32 -0
  19. package/dist/view/index.d.ts +3 -0
  20. package/dist/view/index.js +10 -0
  21. package/package.json +64 -4
  22. package/src/index.ts +17 -0
  23. package/src/modules/fields.controller.arrows.horizontal.ts +22 -0
  24. package/src/modules/fields.controller.arrows.ts +52 -0
  25. package/src/modules/fields.controller.ts +200 -0
  26. package/src/modules/fields.view.ts +23 -0
  27. package/src/tests/arrows.horizontal.test.ts +62 -0
  28. package/src/tests/arrows.test.ts +106 -0
  29. package/src/tests/controller.test.ts +235 -0
  30. package/src/tests/setup.ts +46 -0
  31. package/src/types.ts +32 -0
  32. package/src/utils/settings.ts +7 -0
  33. package/src/view/SettingsExampleText.tsx +60 -0
  34. package/src/view/SettingsTabContent.tsx +118 -0
  35. package/src/view/index.tsx +66 -0
  36. package/tsconfig.json +10 -0
  37. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ import "@vnejs/contracts.controllers.common.settings";
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import "@vnejs/contracts.controllers.common.settings";
2
+ import { regPlugin } from "@vnejs/registry";
3
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.common.settings";
4
+ import { SettingsViewFieldsControllerArrowsHorizontal } from "./modules/fields.controller.arrows.horizontal.js";
5
+ import { SettingsViewFieldsControllerArrows } from "./modules/fields.controller.arrows.js";
6
+ import { SettingsViewFieldsController } from "./modules/fields.controller.js";
7
+ import { SettingsViewFieldsView } from "./modules/fields.view.js";
8
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
9
+ SettingsViewFieldsController,
10
+ SettingsViewFieldsControllerArrows,
11
+ SettingsViewFieldsControllerArrowsHorizontal,
12
+ SettingsViewFieldsView,
13
+ ]);
@@ -0,0 +1,18 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+ import type { SettingsField } from "@vnejs/contracts.controllers.common.settings";
3
+ import type { SettingsViewTabPayload } from "@vnejs/contracts.controllers.common.settings";
4
+ import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
5
+ export declare class SettingsViewFieldsControllerArrows extends ModuleControllerArrowsVertical<SettingsViewPluginEvents, SettingsViewPluginConstants, SettingsViewPluginSettings, SettingsViewPluginParams> {
6
+ name: string;
7
+ EVENT_SHOW: "vne:settings_view:show";
8
+ EVENT_HIDE: "vne:settings_view:hide";
9
+ EVENT_UPDATE_STATE: "vne:settings_view:update_state";
10
+ EVENT_UPDATE_FAST: "vne:settings_view:update_fast";
11
+ CONTROLS_ZINDEX: number;
12
+ fields: SettingsField[];
13
+ subscribe: () => void;
14
+ onTabSet: (payload?: SettingsViewTabPayload) => void;
15
+ onShow: (payload?: SettingsViewTabPayload) => Promise<import("@vnejs/registry").EmitResults<"vne:controls:push">> | undefined;
16
+ getMaxCurrentItem: () => number;
17
+ syncFields: (payload?: SettingsViewTabPayload) => void;
18
+ }
@@ -0,0 +1,12 @@
1
+ import { ModuleControllerArrowsHorizontal } from "@vnejs/module.controller.arrows.horizontal";
2
+ import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
3
+ export declare class SettingsViewFieldsControllerArrowsHorizontal extends ModuleControllerArrowsHorizontal<SettingsViewPluginEvents, SettingsViewPluginConstants, SettingsViewPluginSettings, SettingsViewPluginParams> {
4
+ name: string;
5
+ EVENT_SHOW: "vne:settings_view:show";
6
+ EVENT_HIDE: "vne:settings_view:hide";
7
+ EVENT_UPDATE_STATE: "vne:settings_view:update_state";
8
+ EVENT_UPDATE_FAST: "vne:settings_view:update_fast";
9
+ CONTROLS_ZINDEX: number;
10
+ onArrowLeft: () => undefined;
11
+ onArrowRight: () => undefined;
12
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleControllerArrowsHorizontal } from "@vnejs/module.controller.arrows.horizontal";
2
+ export class SettingsViewFieldsControllerArrowsHorizontal extends ModuleControllerArrowsHorizontal {
3
+ name = "settings.view.fields.controller.arrows.horizontal";
4
+ EVENT_SHOW = this.EVENTS.SETTINGS_VIEW.SHOW;
5
+ EVENT_HIDE = this.EVENTS.SETTINGS_VIEW.HIDE;
6
+ EVENT_UPDATE_STATE = this.EVENTS.SETTINGS_VIEW.UPDATE_STATE;
7
+ EVENT_UPDATE_FAST = this.EVENTS.SETTINGS_VIEW.UPDATE_FAST;
8
+ CONTROLS_ZINDEX = this.PARAMS.SETTINGS_VIEW.ZINDEX;
9
+ onArrowLeft = () => void this.emit(this.EVENTS.SETTINGS_VIEW.ARROW_LEFT);
10
+ onArrowRight = () => void this.emit(this.EVENTS.SETTINGS_VIEW.ARROW_RIGHT);
11
+ }
@@ -0,0 +1,33 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+ export class SettingsViewFieldsControllerArrows extends ModuleControllerArrowsVertical {
3
+ name = "settings.view.fields.controller.arrows";
4
+ EVENT_SHOW = this.EVENTS.SETTINGS_VIEW.SHOW;
5
+ EVENT_HIDE = this.EVENTS.SETTINGS_VIEW.HIDE;
6
+ EVENT_UPDATE_STATE = this.EVENTS.SETTINGS_VIEW.UPDATE_STATE;
7
+ EVENT_UPDATE_FAST = this.EVENTS.SETTINGS_VIEW.UPDATE_FAST;
8
+ CONTROLS_ZINDEX = this.PARAMS.SETTINGS_VIEW.ZINDEX;
9
+ fields = [];
10
+ subscribe = () => {
11
+ super.subscribe();
12
+ this.on(this.EVENTS.SETTINGS_VIEW.TAB_SET, this.onTabSet);
13
+ };
14
+ onTabSet = (payload = {}) => {
15
+ this.syncFields(payload);
16
+ this.currentItem = null;
17
+ this.emitCurrentItem();
18
+ };
19
+ onShow = (payload = {}) => {
20
+ this.syncFields(payload);
21
+ this.currentItem = null;
22
+ return this.emit(this.EVENTS.CONTROLS.PUSH, {
23
+ key: this.name,
24
+ controls: this.CONTROLS,
25
+ index: this.CONTROLS_ZINDEX + 1,
26
+ checkNext: true,
27
+ });
28
+ };
29
+ getMaxCurrentItem = () => Math.max((this.fields.length ?? 1) - 1, 0);
30
+ syncFields = (payload = {}) => {
31
+ this.fields = payload.tab?.fields ?? [];
32
+ };
33
+ }
@@ -0,0 +1,44 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import type { SettingsField } from "@vnejs/contracts.controllers.common.settings";
3
+ import type { SettingsViewTabPayload } from "@vnejs/contracts.controllers.common.settings";
4
+ import type { SettingsViewTabContent } from "../utils/settings.js";
5
+ import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
6
+ import type { SettingsViewPluginState } from "../types.js";
7
+ export declare class SettingsViewFieldsController extends ModuleController<SettingsViewPluginEvents, SettingsViewPluginConstants, SettingsViewPluginSettings, SettingsViewPluginParams, SettingsViewPluginState> {
8
+ name: string;
9
+ EVENT_UPDATE_VIEW: "vne:settings_view:update";
10
+ EVENT_UPDATE_STATE: "vne:settings_view:update_state";
11
+ EVENT_UPDATE_FAST: "vne:settings_view:update_fast";
12
+ EVENT_UPDATE_FORCE: "vne:settings_view:update_force";
13
+ EVENT_SHOW: "vne:settings_view:show";
14
+ EVENT_HIDE: "vne:settings_view:hide";
15
+ CONTROLS: {
16
+ abstract_interact: () => undefined;
17
+ };
18
+ CONTROLS_INDEX: number;
19
+ CONTROLS_CHECK_NEXT: boolean;
20
+ subscribe: () => void;
21
+ onTabSet: (payload?: SettingsViewTabPayload) => Promise<import("@vnejs/registry").EmitResults<string> | undefined>;
22
+ onArrowLeft: () => void | false;
23
+ onArrowRight: () => void | false;
24
+ tabKeyOf: ({ tabKey, tab }?: SettingsViewTabPayload) => string;
25
+ tabContentOf: (tab: SettingsViewTabPayload["tab"], locs?: Record<string, string>) => SettingsViewTabContent;
26
+ applyTab: (payload?: SettingsViewTabPayload) => {
27
+ tab: import("@vnejs/contracts.controllers.common.settings").SettingsTab | undefined;
28
+ tabKey: string;
29
+ tabsContent: {
30
+ [k: string]: SettingsViewTabContent;
31
+ };
32
+ fields: SettingsField[];
33
+ locs: Record<string, string> | undefined;
34
+ showTextExample: boolean;
35
+ currentItemInner: number;
36
+ };
37
+ onUpdateState: (payload?: Partial<SettingsViewPluginState>) => void;
38
+ getFocusedField: () => SettingsField | undefined;
39
+ innerIndexOfField: (field?: SettingsField) => number;
40
+ optionIndexOf: (length: number, index?: number) => number;
41
+ shiftOptions: (direction: -1 | 1) => void;
42
+ onInteract: () => void;
43
+ onShowBefore: (payload?: SettingsViewTabPayload) => Promise<void>;
44
+ }
@@ -0,0 +1,157 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ export class SettingsViewFieldsController extends ModuleController {
3
+ name = "settings.view.fields.controller";
4
+ EVENT_UPDATE_VIEW = this.EVENTS.SETTINGS_VIEW.UPDATE;
5
+ EVENT_UPDATE_STATE = this.EVENTS.SETTINGS_VIEW.UPDATE_STATE;
6
+ EVENT_UPDATE_FAST = this.EVENTS.SETTINGS_VIEW.UPDATE_FAST;
7
+ EVENT_UPDATE_FORCE = this.EVENTS.SETTINGS_VIEW.UPDATE_FORCE;
8
+ EVENT_SHOW = this.EVENTS.SETTINGS_VIEW.SHOW;
9
+ EVENT_HIDE = this.EVENTS.SETTINGS_VIEW.HIDE;
10
+ CONTROLS = {
11
+ [this.CONST.CONTROLS.BUTTONS.INTERACT]: () => void this.onInteract(),
12
+ };
13
+ CONTROLS_INDEX = this.PARAMS.SETTINGS_VIEW.ZINDEX;
14
+ CONTROLS_CHECK_NEXT = true;
15
+ subscribe = () => {
16
+ super.subscribe();
17
+ this.on(this.EVENTS.SETTINGS_VIEW.TAB_SET, this.onTabSet);
18
+ this.on(this.EVENTS.SETTINGS_VIEW.ARROW_LEFT, this.onArrowLeft);
19
+ this.on(this.EVENTS.SETTINGS_VIEW.ARROW_RIGHT, this.onArrowRight);
20
+ };
21
+ onTabSet = async (payload = {}) => {
22
+ if (!this.state.isShow)
23
+ return this.emit(this.EVENT_SHOW, payload);
24
+ const isForce = Boolean(payload.isForce || this.shared.viewForceAnimationSources?.isNotEmpty());
25
+ const next = { ...this.applyTab(payload), currentArrowVerticalItem: null };
26
+ if (isForce)
27
+ return this.updateStateAndViewForce(next);
28
+ const key = next.tabKey;
29
+ const alreadyMounted = Boolean(this.state.tabsContent?.[key]);
30
+ // Mount the incoming tab at opacity 0 first so CSS can crossfade both layers together.
31
+ if (!alreadyMounted) {
32
+ await this.updateStateAndViewFast({ tabsContent: next.tabsContent });
33
+ await this.waitRerender();
34
+ }
35
+ return this.updateStateAndView(next);
36
+ };
37
+ onArrowLeft = () => {
38
+ const field = this.getFocusedField();
39
+ if (!field)
40
+ return;
41
+ if (field.options?.length)
42
+ return this.shiftOptions(-1);
43
+ const { settingKey = "", step = 0, min = 0, type = "" } = field;
44
+ if (!settingKey)
45
+ return;
46
+ if (type === "toggle") {
47
+ return this.shared.settings[settingKey] === true && void this.emit(this.EVENTS.SETTINGS.SET, { name: settingKey, value: false });
48
+ }
49
+ if (type === "range") {
50
+ const newValue = Number(Number(Number(this.shared.settings[settingKey]) - step).toFixed(4));
51
+ return newValue >= min && void this.emit(this.EVENTS.SETTINGS.SET, { name: settingKey, value: newValue });
52
+ }
53
+ };
54
+ onArrowRight = () => {
55
+ const field = this.getFocusedField();
56
+ if (!field)
57
+ return;
58
+ if (field.options?.length)
59
+ return this.shiftOptions(1);
60
+ const { settingKey = "", step = 0, max = 0, type = "" } = field;
61
+ if (!settingKey)
62
+ return;
63
+ if (type === "toggle") {
64
+ return this.shared.settings[settingKey] === false && void this.emit(this.EVENTS.SETTINGS.SET, { name: settingKey, value: true });
65
+ }
66
+ if (type === "range") {
67
+ const newValue = Number(Number(Number(this.shared.settings[settingKey]) + step).toFixed(4));
68
+ return newValue <= max && void this.emit(this.EVENTS.SETTINGS.SET, { name: settingKey, value: newValue });
69
+ }
70
+ };
71
+ tabKeyOf = ({ tabKey, tab } = {}) => tabKey || tab?.titleLocKey || "default";
72
+ tabContentOf = (tab, locs) => ({
73
+ fields: tab?.fields ?? [],
74
+ showTextExample: Boolean(tab?.showTextExample),
75
+ locs,
76
+ });
77
+ applyTab = (payload = {}) => {
78
+ const { tab, locs } = payload;
79
+ const fields = tab?.fields ?? [];
80
+ const key = this.tabKeyOf(payload);
81
+ const tabsContent = payload.tabs
82
+ ? Object.fromEntries(Object.entries(payload.tabs).map(([tabKey, settingsTab]) => [tabKey, this.tabContentOf(settingsTab, locs)]))
83
+ : { ...(this.state.tabsContent ?? {}), [key]: this.tabContentOf(tab, locs) };
84
+ return {
85
+ tab,
86
+ tabKey: key,
87
+ tabsContent,
88
+ fields,
89
+ locs,
90
+ showTextExample: Boolean(tab?.showTextExample),
91
+ currentItemInner: 0,
92
+ };
93
+ };
94
+ onUpdateState = (payload = {}) => {
95
+ const currentArrowVerticalItem = payload.currentArrowVerticalItem;
96
+ const field = currentArrowVerticalItem == null ? undefined : this.state.fields?.[currentArrowVerticalItem];
97
+ this.updateState({ ...payload, currentItemInner: this.innerIndexOfField(field) });
98
+ };
99
+ getFocusedField = () => {
100
+ const { currentArrowVerticalItem, fields = [] } = this.state;
101
+ if (currentArrowVerticalItem == null || !fields.length)
102
+ return;
103
+ return fields[currentArrowVerticalItem];
104
+ };
105
+ innerIndexOfField = (field) => {
106
+ const options = field?.options ?? [];
107
+ if (!options.length)
108
+ return 0;
109
+ const settingKey = field?.settingKey;
110
+ if (!settingKey)
111
+ return 0;
112
+ const index = options.findIndex((option) => option.value === this.shared.settings[settingKey]);
113
+ return index >= 0 ? index : 0;
114
+ };
115
+ optionIndexOf = (length, index = 0) => {
116
+ if (!length)
117
+ return 0;
118
+ return ((index % length) + length) % length;
119
+ };
120
+ shiftOptions = (direction) => {
121
+ const field = this.getFocusedField();
122
+ const options = field?.options ?? [];
123
+ if (!options.length)
124
+ return;
125
+ const currentItemInner = this.optionIndexOf(options.length, (this.state.currentItemInner ?? 0) + direction);
126
+ const option = options[currentItemInner];
127
+ const settingKey = field?.settingKey;
128
+ void this.updateStateAndViewFast({ currentItemInner });
129
+ if (settingKey && option && !option.action) {
130
+ void this.emit(this.EVENTS.SETTINGS.SET, { name: settingKey, value: option.value });
131
+ }
132
+ };
133
+ onInteract = () => {
134
+ const field = this.getFocusedField();
135
+ if (!field)
136
+ return;
137
+ const { settingKey = "", type = "", options = [] } = field;
138
+ const { locs = {} } = this.state;
139
+ if (options?.length) {
140
+ const option = options[this.optionIndexOf(options.length, this.state.currentItemInner ?? 0)];
141
+ if (!option)
142
+ return;
143
+ if (option.action)
144
+ return this.PARAMS.SETTINGS_VIEW.ACTIONS[option.action](this, locs);
145
+ if (settingKey)
146
+ return void this.emit(this.EVENTS.SETTINGS.SET, { name: settingKey, value: option.value });
147
+ return;
148
+ }
149
+ if (!settingKey)
150
+ return;
151
+ if (type === "toggle")
152
+ return void this.emit(this.EVENTS.SETTINGS.SET, { name: settingKey, value: !this.shared.settings[settingKey] });
153
+ };
154
+ onShowBefore = async (payload = {}) => {
155
+ return this.updateState(this.applyTab(payload));
156
+ };
157
+ }
@@ -0,0 +1,10 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
3
+ import type { SettingsViewPluginState } from "../types.js";
4
+ export declare class SettingsViewFieldsView extends ModuleView<SettingsViewPluginEvents, SettingsViewPluginConstants, SettingsViewPluginSettings, SettingsViewPluginParams, SettingsViewPluginState> {
5
+ name: string;
6
+ EVENT_UPDATE_VIEW: "vne:settings_view:update";
7
+ LOC_LABEL: string;
8
+ TRANSITION: number;
9
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<SettingsViewPluginState>;
10
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import { render } from "../view/index.js";
3
+ export class SettingsViewFieldsView extends ModuleView {
4
+ name = "settings.view.fields.view";
5
+ EVENT_UPDATE_VIEW = this.EVENTS.SETTINGS_VIEW.UPDATE;
6
+ LOC_LABEL = this.PARAMS.SETTINGS_VIEW.LOC_LABEL;
7
+ TRANSITION = this.PARAMS.SETTINGS_VIEW.TRANSITION;
8
+ renderFunc = render;
9
+ }
@@ -0,0 +1,23 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { Constants, Params, PluginName, SettingsField, SettingsTab, SubscribeEvents } from "@vnejs/contracts.controllers.common.settings";
3
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
4
+ import type { PluginName as SettingsPluginName, SubscribeEvents as SettingsSubscribeEvents } from "@vnejs/contracts.core.settings";
5
+ import type { SettingsKeys as TextsizeSettingsKeys, PluginName as TextsizePluginName } from "@vnejs/contracts.settings.textsize";
6
+ import type { Params as TextSmoothParams, PluginName as TextSmoothPluginName, SettingsKeys as TextSmoothSettingsKeys } from "@vnejs/contracts.text.smooth";
7
+ import type { SettingsViewTabContent } from "./utils/settings.js";
8
+ export type SettingsViewPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<SettingsPluginName, SettingsSubscribeEvents>;
9
+ export type SettingsViewPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants> & Record<PluginName, Constants>;
10
+ export type SettingsViewPluginSettings = ModuleComponentsSettings & Record<TextSmoothPluginName, TextSmoothSettingsKeys> & Record<TextsizePluginName, TextsizeSettingsKeys>;
11
+ export type SettingsViewPluginParams = ModuleComponentsParams & Record<PluginName, Params> & Record<TextSmoothPluginName, TextSmoothParams>;
12
+ export type SettingsViewPluginState = {
13
+ isShow: boolean;
14
+ isForce: boolean;
15
+ tab?: SettingsTab;
16
+ tabKey?: string;
17
+ tabsContent?: Record<string, SettingsViewTabContent>;
18
+ fields?: SettingsField[];
19
+ locs?: Record<string, string>;
20
+ showTextExample?: boolean;
21
+ currentArrowVerticalItem?: number | null;
22
+ currentItemInner?: number | null;
23
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { SettingsField } from "@vnejs/contracts.controllers.common.settings";
2
+ export type SettingsViewTabContent = {
3
+ fields?: SettingsField[];
4
+ showTextExample?: boolean;
5
+ locs?: Record<string, string>;
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { ReactComponentProps } from "@vnejs/uis.react";
2
+ import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
3
+ import type { SettingsViewPluginState } from "../types.js";
4
+ type SettingsExampleTextProps = ReactComponentProps<SettingsViewPluginEvents, SettingsViewPluginConstants, SettingsViewPluginSettings, SettingsViewPluginParams, SettingsViewPluginState> & {
5
+ isShow?: boolean;
6
+ locs?: Record<string, string>;
7
+ };
8
+ export declare const SettingsExampleText: ({ isShow, locs, PARAMS, shared, SETTINGS }: SettingsExampleTextProps) => import("react").JSX.Element;
9
+ export {};
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { SmoothText, useEffect, useState } from "@vnejs/uis.react";
3
+ import { tokenizeText } from "@vnejs/helpers";
4
+ export const SettingsExampleText = ({ isShow = false, locs = {}, PARAMS, shared, SETTINGS }) => {
5
+ const [tokens, setTokens] = useState([]);
6
+ const isForce = shared.textProcessSkipSources.isNotEmpty();
7
+ const text = locs["fields.text.example"] ?? "";
8
+ useEffect(() => {
9
+ if (isShow)
10
+ setTokens(tokenizeText(text));
11
+ }, [isShow, text]);
12
+ useEffect(() => {
13
+ setTokens((prev) => (prev.length ? [...prev] : prev));
14
+ }, [isForce]);
15
+ useEffect(() => {
16
+ if (isShow || isForce)
17
+ return;
18
+ const tm = setTimeout(() => setTokens([]), PARAMS.SETTINGS_VIEW.TRANSITION);
19
+ return () => clearTimeout(tm);
20
+ }, [isShow, isForce, PARAMS.SETTINGS_VIEW.TRANSITION]);
21
+ const charDelay = isForce ? 0 : PARAMS.TEXT_SMOOTH.TOKEN_RENDER_DELAY / Number(shared.settings[SETTINGS.TEXT_SMOOTH.TOKEN_RENDER_SPEED]);
22
+ return (_jsx(SmoothText, { tokens: tokens, isForce: isForce, charDelay: charDelay, tokensVisibleForce: isForce ? tokens.length : null, transition: PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.transition, size: PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.size, color: PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.color, height: PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.height, scrollBarTextSize: Number(shared.settings[SETTINGS.TEXTSIZE.VALUE]) }));
23
+ };
@@ -0,0 +1,15 @@
1
+ import type { ReactComponentProps } from "@vnejs/uis.react";
2
+ import type { SettingsField } from "@vnejs/contracts.controllers.common.settings";
3
+ import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
4
+ import type { SettingsViewPluginState } from "../types.js";
5
+ type SettingsTabContentProps = ReactComponentProps<SettingsViewPluginEvents, SettingsViewPluginConstants, SettingsViewPluginSettings, SettingsViewPluginParams, SettingsViewPluginState> & {
6
+ isShow?: boolean;
7
+ isForce?: boolean;
8
+ locs?: Record<string, string>;
9
+ fields?: SettingsField[];
10
+ showTextExample?: boolean;
11
+ currentItem?: number | null;
12
+ currentItemInner?: number | null;
13
+ };
14
+ export declare const SettingsTabContent: ({ isShow, isForce, locs, fields, showTextExample, currentItem, currentItemInner, PARAMS, emit, EVENTS, shared, SETTINGS, store, onMount, CONST, }: SettingsTabContentProps) => import("react").JSX.Element;
15
+ export {};
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Flex, PositionBox, Settings } from "@vnejs/uis.react";
3
+ import { SettingsExampleText } from "./SettingsExampleText.js";
4
+ export const SettingsTabContent = ({ isShow = false, isForce = false, locs = {}, fields = [], showTextExample = false, currentItem = null, currentItemInner = null, PARAMS, emit, EVENTS, shared, SETTINGS, store, onMount, CONST, }) => {
5
+ const mapFields = ({ locKey = "", type = "", settingKey = "", options = [], titleToggledLocKey = "", titleUntoggledLocKey = "", valueMap = "", ...fieldProps } = {}) => {
6
+ const onChange = (value) => void emit(EVENTS.SETTINGS.SET, { name: settingKey, value });
7
+ const titles = { title: locs[locKey], titleToggled: locs[titleToggledLocKey], titleUntoggled: locs[titleUntoggledLocKey] };
8
+ const valueMapReal = valueMap ? PARAMS.SETTINGS_VIEW.VALUE_MAPS[valueMap] : null;
9
+ const optionsReal = options.map((option) => {
10
+ const result = { ...option };
11
+ if (option.locKey) {
12
+ delete result.locKey;
13
+ result.text = locs[option.locKey];
14
+ }
15
+ if (option.action) {
16
+ delete result.action;
17
+ result.onClick = () => PARAMS.SETTINGS_VIEW.ACTIONS[option.action]({ emit, emitOne: emit, emitReal: emit }, locs);
18
+ }
19
+ return result;
20
+ });
21
+ return { ...titles, value: shared.settings[settingKey], type, onChange, props: fieldProps, options: optionsReal, valueMap: valueMapReal };
22
+ };
23
+ // Do not memoize mapped settings: shared.settings is mutated in place on SETTINGS.CHANGED.
24
+ const propsSettings = {
25
+ ...PARAMS.SETTINGS_VIEW.VIEW_PROPS.fieldProps,
26
+ transition: isForce ? 0 : PARAMS.SETTINGS_VIEW.TRANSITION,
27
+ settings: fields.map(mapFields),
28
+ selectedIndex: isShow ? (currentItem ?? undefined) : -1,
29
+ selectedIndexInner: isShow ? (currentItemInner ?? undefined) : -1,
30
+ };
31
+ return (_jsx(PositionBox, { isCentered: true, opacity: isShow ? 1 : 0, transition: isForce ? 0 : PARAMS.SETTINGS_VIEW.TRANSITION, children: _jsxs(Flex, { direction: Flex.DIRECTION.COLUMN, gap: PARAMS.SETTINGS_VIEW.VIEW_PROPS.fieldsGap, children: [_jsx(Settings, { ...propsSettings }), showTextExample && (_jsx(SettingsExampleText, { store: store, onMount: onMount, PARAMS: PARAMS, emit: emit, EVENTS: EVENTS, shared: shared, CONST: CONST, SETTINGS: SETTINGS, locs: locs, isShow: isShow }))] }) }));
32
+ };
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { SettingsViewPluginState } from "../types.js";
3
+ export declare const render: ViewRenderFunc<SettingsViewPluginState>;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { View, createRenderFunc, useIsForceHook, useStoreState } from "@vnejs/uis.react";
3
+ import { SettingsTabContent } from "./SettingsTabContent.js";
4
+ const SettingsViewComponent = ({ store, onMount, PARAMS, emit, EVENTS, shared, CONST, SETTINGS }) => {
5
+ const { isShow = false, isForce = false, locs = {}, tabsContent = {}, tabKey = "", currentArrowVerticalItem = null, currentItemInner = null, } = useStoreState(store, onMount);
6
+ const isRealForce = useIsForceHook(isForce);
7
+ const propsByView = PARAMS.SETTINGS_VIEW.VIEW_PROPS;
8
+ return (_jsx(View, { ...propsByView.view, isShow: isShow, isForce: isRealForce, transition: isRealForce ? 0 : PARAMS.SETTINGS_VIEW.TRANSITION, children: Object.entries(tabsContent).map(([key, content]) => (_jsx(SettingsTabContent, { store: store, onMount: onMount, PARAMS: PARAMS, emit: emit, EVENTS: EVENTS, shared: shared, CONST: CONST, SETTINGS: SETTINGS, isForce: isRealForce, currentItem: currentArrowVerticalItem, currentItemInner: currentItemInner, isShow: tabKey === key, fields: content.fields, showTextExample: content.showTextExample, locs: content.locs ?? locs }, key))) }));
9
+ };
10
+ export const render = createRenderFunc(SettingsViewComponent);
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.controllers.common.settings",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.17",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
20
+ "scripts": {
21
+ "test": "npx @vnejs/monorepo test",
22
+ "build": "npx @vnejs/monorepo package",
23
+ "publish:major:plugin": "npm run publish:major",
24
+ "publish:minor:plugin": "npm run publish:minor",
25
+ "publish:patch:plugin": "npm run publish:patch",
26
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
27
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
28
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
29
+ },
30
+ "author": "",
31
+ "license": "ISC",
32
+ "dependencies": {
33
+ "@vnejs/contracts.controllers.common.settings": "~0.2.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/helpers": "~0.2.0",
37
+ "@vnejs/module.core": "~0.2.0",
38
+ "@vnejs/module.components": "~0.2.0",
39
+ "@vnejs/module.controller.arrows.horizontal": "~0.2.0",
40
+ "@vnejs/module.controller.arrows.vertical": "~0.2.0",
41
+ "@vnejs/contracts.controls": "~0.2.0",
42
+ "@vnejs/contracts.core.settings": "~0.2.0",
43
+ "@vnejs/contracts.settings.textsize": "~0.2.0",
44
+ "@vnejs/contracts.text.smooth": "~0.2.0",
45
+ "@vnejs/registry": "~0.2.0",
46
+ "@vnejs/uis.react": "~0.2.0"
47
+ },
48
+ "devDependencies": {
49
+ "@vnejs/configs.ts-common": "~0.2.0",
50
+ "@vnejs/configs.vitest": "~0.2.0",
51
+ "@vnejs/test-utils": "~0.2.0",
52
+ "@vnejs/contracts.controls": "~0.2.0",
53
+ "@vnejs/contracts.core.settings": "~0.2.0",
54
+ "@vnejs/contracts.settings.textsize": "~0.2.0",
55
+ "@vnejs/contracts.text.smooth": "~0.2.0",
56
+ "@vnejs/contracts.controllers.common.settings": "~0.2.0",
57
+ "@vnejs/helpers": "~0.2.0",
58
+ "@vnejs/module.core": "~0.2.0",
59
+ "@vnejs/module.components": "~0.2.0",
60
+ "@vnejs/module.controller.arrows.horizontal": "~0.2.0",
61
+ "@vnejs/module.controller.arrows.vertical": "~0.2.0",
62
+ "@vnejs/registry": "~0.2.0",
63
+ "@vnejs/sources-set": "~0.2.0",
64
+ "@vnejs/uis.react": "~0.2.0"
65
+ }
66
+ }
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ import "@vnejs/contracts.controllers.common.settings";
2
+
3
+ import { regPlugin } from "@vnejs/registry";
4
+
5
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.common.settings";
6
+
7
+ import { SettingsViewFieldsControllerArrowsHorizontal } from "./modules/fields.controller.arrows.horizontal.js";
8
+ import { SettingsViewFieldsControllerArrows } from "./modules/fields.controller.arrows.js";
9
+ import { SettingsViewFieldsController } from "./modules/fields.controller.js";
10
+ import { SettingsViewFieldsView } from "./modules/fields.view.js";
11
+
12
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
13
+ SettingsViewFieldsController,
14
+ SettingsViewFieldsControllerArrows,
15
+ SettingsViewFieldsControllerArrowsHorizontal,
16
+ SettingsViewFieldsView,
17
+ ]);
@@ -0,0 +1,22 @@
1
+ import { ModuleControllerArrowsHorizontal } from "@vnejs/module.controller.arrows.horizontal";
2
+
3
+ import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
4
+
5
+ export class SettingsViewFieldsControllerArrowsHorizontal extends ModuleControllerArrowsHorizontal<
6
+ SettingsViewPluginEvents,
7
+ SettingsViewPluginConstants,
8
+ SettingsViewPluginSettings,
9
+ SettingsViewPluginParams
10
+ > {
11
+ name = "settings.view.fields.controller.arrows.horizontal";
12
+
13
+ EVENT_SHOW = this.EVENTS.SETTINGS_VIEW.SHOW;
14
+ EVENT_HIDE = this.EVENTS.SETTINGS_VIEW.HIDE;
15
+ EVENT_UPDATE_STATE = this.EVENTS.SETTINGS_VIEW.UPDATE_STATE;
16
+ EVENT_UPDATE_FAST = this.EVENTS.SETTINGS_VIEW.UPDATE_FAST;
17
+
18
+ CONTROLS_ZINDEX = this.PARAMS.SETTINGS_VIEW.ZINDEX;
19
+
20
+ onArrowLeft = () => void this.emit(this.EVENTS.SETTINGS_VIEW.ARROW_LEFT);
21
+ onArrowRight = () => void this.emit(this.EVENTS.SETTINGS_VIEW.ARROW_RIGHT);
22
+ }
@@ -0,0 +1,52 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+
3
+ import type { SettingsField } from "@vnejs/contracts.controllers.common.settings";
4
+ import type { SettingsViewTabPayload } from "@vnejs/contracts.controllers.common.settings";
5
+ import type { ControlsPushPayload } from "@vnejs/contracts.controls";
6
+
7
+ import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
8
+
9
+ export class SettingsViewFieldsControllerArrows extends ModuleControllerArrowsVertical<
10
+ SettingsViewPluginEvents,
11
+ SettingsViewPluginConstants,
12
+ SettingsViewPluginSettings,
13
+ SettingsViewPluginParams
14
+ > {
15
+ name = "settings.view.fields.controller.arrows";
16
+
17
+ EVENT_SHOW = this.EVENTS.SETTINGS_VIEW.SHOW;
18
+ EVENT_HIDE = this.EVENTS.SETTINGS_VIEW.HIDE;
19
+ EVENT_UPDATE_STATE = this.EVENTS.SETTINGS_VIEW.UPDATE_STATE;
20
+ EVENT_UPDATE_FAST = this.EVENTS.SETTINGS_VIEW.UPDATE_FAST;
21
+
22
+ CONTROLS_ZINDEX = this.PARAMS.SETTINGS_VIEW.ZINDEX;
23
+
24
+ fields: SettingsField[] = [];
25
+
26
+ subscribe = () => {
27
+ super.subscribe();
28
+ this.on(this.EVENTS.SETTINGS_VIEW.TAB_SET, this.onTabSet);
29
+ };
30
+
31
+ onTabSet = (payload: SettingsViewTabPayload = {}) => {
32
+ this.syncFields(payload);
33
+ this.currentItem = null;
34
+ this.emitCurrentItem();
35
+ };
36
+
37
+ onShow = (payload: SettingsViewTabPayload = {}) => {
38
+ this.syncFields(payload);
39
+ this.currentItem = null;
40
+
41
+ return this.emit(this.EVENTS.CONTROLS.PUSH, {
42
+ key: this.name,
43
+ controls: this.CONTROLS,
44
+ index: this.CONTROLS_ZINDEX + 1,
45
+ checkNext: true,
46
+ } satisfies ControlsPushPayload);
47
+ };
48
+ getMaxCurrentItem = () => Math.max((this.fields.length ?? 1) - 1, 0);
49
+ syncFields = (payload: SettingsViewTabPayload = {}) => {
50
+ this.fields = payload.tab?.fields ?? [];
51
+ };
52
+ }