@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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -0
- package/dist/modules/fields.controller.arrows.d.ts +18 -0
- package/dist/modules/fields.controller.arrows.horizontal.d.ts +12 -0
- package/dist/modules/fields.controller.arrows.horizontal.js +11 -0
- package/dist/modules/fields.controller.arrows.js +33 -0
- package/dist/modules/fields.controller.d.ts +44 -0
- package/dist/modules/fields.controller.js +157 -0
- package/dist/modules/fields.view.d.ts +10 -0
- package/dist/modules/fields.view.js +9 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +1 -0
- package/dist/utils/settings.d.ts +6 -0
- package/dist/utils/settings.js +1 -0
- package/dist/view/SettingsExampleText.d.ts +9 -0
- package/dist/view/SettingsExampleText.js +23 -0
- package/dist/view/SettingsTabContent.d.ts +15 -0
- package/dist/view/SettingsTabContent.js +32 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +10 -0
- package/package.json +64 -4
- package/src/index.ts +17 -0
- package/src/modules/fields.controller.arrows.horizontal.ts +22 -0
- package/src/modules/fields.controller.arrows.ts +52 -0
- package/src/modules/fields.controller.ts +200 -0
- package/src/modules/fields.view.ts +23 -0
- package/src/tests/arrows.horizontal.test.ts +62 -0
- package/src/tests/arrows.test.ts +106 -0
- package/src/tests/controller.test.ts +235 -0
- package/src/tests/setup.ts +46 -0
- package/src/types.ts +32 -0
- package/src/utils/settings.ts +7 -0
- package/src/view/SettingsExampleText.tsx +60 -0
- package/src/view/SettingsTabContent.tsx +118 -0
- package/src/view/index.tsx +66 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
package/src/types.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { Constants, Params, PluginName, SettingsField, SettingsTab, SubscribeEvents } from "@vnejs/contracts.controllers.common.settings";
|
|
4
|
+
import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
|
|
5
|
+
import type { PluginName as SettingsPluginName, SubscribeEvents as SettingsSubscribeEvents } from "@vnejs/contracts.core.settings";
|
|
6
|
+
import type { SettingsKeys as TextsizeSettingsKeys, PluginName as TextsizePluginName } from "@vnejs/contracts.settings.textsize";
|
|
7
|
+
import type { Params as TextSmoothParams, PluginName as TextSmoothPluginName, SettingsKeys as TextSmoothSettingsKeys } from "@vnejs/contracts.text.smooth";
|
|
8
|
+
|
|
9
|
+
import type { SettingsViewTabContent } from "./utils/settings.js";
|
|
10
|
+
|
|
11
|
+
export type SettingsViewPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<SettingsPluginName, SettingsSubscribeEvents>;
|
|
12
|
+
|
|
13
|
+
export type SettingsViewPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants> & Record<PluginName, Constants>;
|
|
14
|
+
|
|
15
|
+
export type SettingsViewPluginSettings = ModuleComponentsSettings &
|
|
16
|
+
Record<TextSmoothPluginName, TextSmoothSettingsKeys> &
|
|
17
|
+
Record<TextsizePluginName, TextsizeSettingsKeys>;
|
|
18
|
+
|
|
19
|
+
export type SettingsViewPluginParams = ModuleComponentsParams & Record<PluginName, Params> & Record<TextSmoothPluginName, TextSmoothParams>;
|
|
20
|
+
|
|
21
|
+
export type SettingsViewPluginState = {
|
|
22
|
+
isShow: boolean;
|
|
23
|
+
isForce: boolean;
|
|
24
|
+
tab?: SettingsTab;
|
|
25
|
+
tabKey?: string;
|
|
26
|
+
tabsContent?: Record<string, SettingsViewTabContent>;
|
|
27
|
+
fields?: SettingsField[];
|
|
28
|
+
locs?: Record<string, string>;
|
|
29
|
+
showTextExample?: boolean;
|
|
30
|
+
currentArrowVerticalItem?: number | null;
|
|
31
|
+
currentItemInner?: number | null;
|
|
32
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { SmoothText, useEffect, useState } from "@vnejs/uis.react";
|
|
2
|
+
|
|
3
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import { tokenizeText } from "@vnejs/helpers";
|
|
6
|
+
|
|
7
|
+
import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
|
|
8
|
+
import type { SettingsViewPluginState } from "../types.js";
|
|
9
|
+
type SettingsExampleTextProps = ReactComponentProps<
|
|
10
|
+
SettingsViewPluginEvents,
|
|
11
|
+
SettingsViewPluginConstants,
|
|
12
|
+
SettingsViewPluginSettings,
|
|
13
|
+
SettingsViewPluginParams,
|
|
14
|
+
SettingsViewPluginState
|
|
15
|
+
> & {
|
|
16
|
+
isShow?: boolean;
|
|
17
|
+
locs?: Record<string, string>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type SmoothTextTokens = NonNullable<Parameters<typeof SmoothText>[0]["tokens"]>;
|
|
21
|
+
|
|
22
|
+
export const SettingsExampleText = ({ isShow = false, locs = {}, PARAMS, shared, SETTINGS }: SettingsExampleTextProps) => {
|
|
23
|
+
const [tokens, setTokens] = useState<SmoothTextTokens>([]);
|
|
24
|
+
|
|
25
|
+
const isForce = shared.textProcessSkipSources.isNotEmpty();
|
|
26
|
+
|
|
27
|
+
const text = locs["fields.text.example"] ?? "";
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (isShow) setTokens(tokenizeText(text) as SmoothTextTokens);
|
|
31
|
+
}, [isShow, text]);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
setTokens((prev) => (prev.length ? [...prev] : prev));
|
|
35
|
+
}, [isForce]);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (isShow || isForce) return;
|
|
39
|
+
|
|
40
|
+
const tm = setTimeout(() => setTokens([]), PARAMS.SETTINGS_VIEW.TRANSITION);
|
|
41
|
+
|
|
42
|
+
return () => clearTimeout(tm);
|
|
43
|
+
}, [isShow, isForce, PARAMS.SETTINGS_VIEW.TRANSITION]);
|
|
44
|
+
|
|
45
|
+
const charDelay = isForce ? 0 : PARAMS.TEXT_SMOOTH.TOKEN_RENDER_DELAY / Number(shared.settings[SETTINGS.TEXT_SMOOTH.TOKEN_RENDER_SPEED]);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<SmoothText
|
|
49
|
+
tokens={tokens}
|
|
50
|
+
isForce={isForce}
|
|
51
|
+
charDelay={charDelay}
|
|
52
|
+
tokensVisibleForce={isForce ? tokens.length : null}
|
|
53
|
+
transition={PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.transition}
|
|
54
|
+
size={PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.size}
|
|
55
|
+
color={PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.color}
|
|
56
|
+
height={PARAMS.SETTINGS_VIEW.VIEW_PROPS.exampleText.height}
|
|
57
|
+
scrollBarTextSize={Number(shared.settings[SETTINGS.TEXTSIZE.VALUE])}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Flex, PositionBox, Settings } from "@vnejs/uis.react";
|
|
2
|
+
|
|
3
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import type { SettingsActionContext, SettingsField } from "@vnejs/contracts.controllers.common.settings";
|
|
6
|
+
|
|
7
|
+
import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
|
|
8
|
+
import type { SettingsViewPluginState } from "../types.js";
|
|
9
|
+
|
|
10
|
+
import { SettingsExampleText } from "./SettingsExampleText.js";
|
|
11
|
+
|
|
12
|
+
type SettingsTabContentProps = ReactComponentProps<
|
|
13
|
+
SettingsViewPluginEvents,
|
|
14
|
+
SettingsViewPluginConstants,
|
|
15
|
+
SettingsViewPluginSettings,
|
|
16
|
+
SettingsViewPluginParams,
|
|
17
|
+
SettingsViewPluginState
|
|
18
|
+
> & {
|
|
19
|
+
isShow?: boolean;
|
|
20
|
+
isForce?: boolean;
|
|
21
|
+
locs?: Record<string, string>;
|
|
22
|
+
fields?: SettingsField[];
|
|
23
|
+
showTextExample?: boolean;
|
|
24
|
+
currentItem?: number | null;
|
|
25
|
+
currentItemInner?: number | null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type SettingsItem = NonNullable<Parameters<typeof Settings>[0]["settings"]>[number];
|
|
29
|
+
|
|
30
|
+
export const SettingsTabContent = ({
|
|
31
|
+
isShow = false,
|
|
32
|
+
isForce = false,
|
|
33
|
+
locs = {},
|
|
34
|
+
fields = [],
|
|
35
|
+
showTextExample = false,
|
|
36
|
+
currentItem = null,
|
|
37
|
+
currentItemInner = null,
|
|
38
|
+
PARAMS,
|
|
39
|
+
emit,
|
|
40
|
+
EVENTS,
|
|
41
|
+
shared,
|
|
42
|
+
SETTINGS,
|
|
43
|
+
store,
|
|
44
|
+
onMount,
|
|
45
|
+
CONST,
|
|
46
|
+
}: SettingsTabContentProps) => {
|
|
47
|
+
const mapFields = ({
|
|
48
|
+
locKey = "",
|
|
49
|
+
type = "",
|
|
50
|
+
settingKey = "",
|
|
51
|
+
options = [],
|
|
52
|
+
titleToggledLocKey = "",
|
|
53
|
+
titleUntoggledLocKey = "",
|
|
54
|
+
valueMap = "",
|
|
55
|
+
...fieldProps
|
|
56
|
+
}: SettingsField = {}) => {
|
|
57
|
+
const onChange = (value: unknown) => void emit(EVENTS.SETTINGS.SET, { name: settingKey, value });
|
|
58
|
+
|
|
59
|
+
const titles = { title: locs[locKey], titleToggled: locs[titleToggledLocKey], titleUntoggled: locs[titleUntoggledLocKey] };
|
|
60
|
+
const valueMapReal = valueMap ? PARAMS.SETTINGS_VIEW.VALUE_MAPS[valueMap] : null;
|
|
61
|
+
|
|
62
|
+
const optionsReal = options.map((option) => {
|
|
63
|
+
const result: Record<string, unknown> = { ...option };
|
|
64
|
+
|
|
65
|
+
if (option.locKey) {
|
|
66
|
+
delete result.locKey;
|
|
67
|
+
result.text = locs[option.locKey];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (option.action) {
|
|
71
|
+
delete result.action;
|
|
72
|
+
result.onClick = () => PARAMS.SETTINGS_VIEW.ACTIONS[option.action!]({ emit, emitOne: emit, emitReal: emit } as SettingsActionContext, locs);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return result;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return { ...titles, value: shared.settings[settingKey], type, onChange, props: fieldProps, options: optionsReal, valueMap: valueMapReal };
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Do not memoize mapped settings: shared.settings is mutated in place on SETTINGS.CHANGED.
|
|
82
|
+
const propsSettings = {
|
|
83
|
+
...PARAMS.SETTINGS_VIEW.VIEW_PROPS.fieldProps,
|
|
84
|
+
transition: isForce ? 0 : PARAMS.SETTINGS_VIEW.TRANSITION,
|
|
85
|
+
settings: fields.map(mapFields) as SettingsItem[],
|
|
86
|
+
selectedIndex: isShow ? (currentItem ?? undefined) : -1,
|
|
87
|
+
selectedIndexInner: isShow ? (currentItemInner ?? undefined) : -1,
|
|
88
|
+
} as Parameters<typeof Settings>[0];
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<PositionBox
|
|
92
|
+
isCentered={true}
|
|
93
|
+
opacity={isShow ? 1 : 0}
|
|
94
|
+
transition={isForce ? 0 : PARAMS.SETTINGS_VIEW.TRANSITION}
|
|
95
|
+
>
|
|
96
|
+
<Flex
|
|
97
|
+
direction={Flex.DIRECTION.COLUMN}
|
|
98
|
+
gap={PARAMS.SETTINGS_VIEW.VIEW_PROPS.fieldsGap}
|
|
99
|
+
>
|
|
100
|
+
<Settings {...propsSettings} />
|
|
101
|
+
{showTextExample && (
|
|
102
|
+
<SettingsExampleText
|
|
103
|
+
store={store}
|
|
104
|
+
onMount={onMount}
|
|
105
|
+
PARAMS={PARAMS}
|
|
106
|
+
emit={emit}
|
|
107
|
+
EVENTS={EVENTS}
|
|
108
|
+
shared={shared}
|
|
109
|
+
CONST={CONST}
|
|
110
|
+
SETTINGS={SETTINGS}
|
|
111
|
+
locs={locs}
|
|
112
|
+
isShow={isShow}
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
</Flex>
|
|
116
|
+
</PositionBox>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ViewRenderFunc } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { View, createRenderFunc, useIsForceHook, useStoreState } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
6
|
+
|
|
7
|
+
import type { SettingsViewPluginConstants, SettingsViewPluginEvents, SettingsViewPluginParams, SettingsViewPluginSettings } from "../types.js";
|
|
8
|
+
import type { SettingsViewPluginState } from "../types.js";
|
|
9
|
+
|
|
10
|
+
import { SettingsTabContent } from "./SettingsTabContent.js";
|
|
11
|
+
|
|
12
|
+
type SettingsComponentProps = ReactComponentProps<
|
|
13
|
+
SettingsViewPluginEvents,
|
|
14
|
+
SettingsViewPluginConstants,
|
|
15
|
+
SettingsViewPluginSettings,
|
|
16
|
+
SettingsViewPluginParams,
|
|
17
|
+
SettingsViewPluginState
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
const SettingsViewComponent = ({ store, onMount, PARAMS, emit, EVENTS, shared, CONST, SETTINGS }: SettingsComponentProps) => {
|
|
21
|
+
const {
|
|
22
|
+
isShow = false,
|
|
23
|
+
isForce = false,
|
|
24
|
+
locs = {},
|
|
25
|
+
tabsContent = {},
|
|
26
|
+
tabKey = "",
|
|
27
|
+
currentArrowVerticalItem = null,
|
|
28
|
+
currentItemInner = null,
|
|
29
|
+
} = useStoreState<SettingsViewPluginState>(store, onMount);
|
|
30
|
+
|
|
31
|
+
const isRealForce = useIsForceHook(isForce);
|
|
32
|
+
|
|
33
|
+
const propsByView = PARAMS.SETTINGS_VIEW.VIEW_PROPS;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<View
|
|
37
|
+
{...propsByView.view}
|
|
38
|
+
isShow={isShow}
|
|
39
|
+
isForce={isRealForce}
|
|
40
|
+
transition={isRealForce ? 0 : PARAMS.SETTINGS_VIEW.TRANSITION}
|
|
41
|
+
>
|
|
42
|
+
{Object.entries(tabsContent).map(([key, content]) => (
|
|
43
|
+
<SettingsTabContent
|
|
44
|
+
key={key}
|
|
45
|
+
store={store}
|
|
46
|
+
onMount={onMount}
|
|
47
|
+
PARAMS={PARAMS}
|
|
48
|
+
emit={emit}
|
|
49
|
+
EVENTS={EVENTS}
|
|
50
|
+
shared={shared}
|
|
51
|
+
CONST={CONST}
|
|
52
|
+
SETTINGS={SETTINGS}
|
|
53
|
+
isForce={isRealForce}
|
|
54
|
+
currentItem={currentArrowVerticalItem}
|
|
55
|
+
currentItemInner={currentItemInner}
|
|
56
|
+
isShow={tabKey === key}
|
|
57
|
+
fields={content.fields}
|
|
58
|
+
showTextExample={content.showTextExample}
|
|
59
|
+
locs={content.locs ?? locs}
|
|
60
|
+
/>
|
|
61
|
+
))}
|
|
62
|
+
</View>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const render: ViewRenderFunc<SettingsViewPluginState> = createRenderFunc(SettingsViewComponent);
|
package/tsconfig.json
ADDED
package/README.md
DELETED