@vnejs/plugins.controllers.screens.eula 0.0.0-stage → 0.2.15

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 @@
1
+ import "@vnejs/contracts.controllers.screens.eula";
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import "@vnejs/contracts.controllers.screens.eula";
2
+ import { regPlugin } from "@vnejs/registry";
3
+ import { PARAMS, PLUGIN_NAME, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.eula";
4
+ import { EulaControllerAccept } from "./modules/controller.accept.js";
5
+ import { EulaControllerArrows } from "./modules/controller.arrows.js";
6
+ import { EulaController } from "./modules/controller.js";
7
+ import { Eula } from "./modules/eula.js";
8
+ import { EulaHideState } from "./modules/hide.state.js";
9
+ import { EulaView } from "./modules/view.js";
10
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS, settings: SETTINGS_KEYS }, [
11
+ EulaController,
12
+ EulaControllerAccept,
13
+ EulaControllerArrows,
14
+ EulaHideState,
15
+ Eula,
16
+ EulaView,
17
+ ]);
@@ -0,0 +1,12 @@
1
+ import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
2
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
3
+ import type { EulaPluginState } from "../types.js";
4
+ export declare class EulaControllerAccept extends ModuleControllerAccept<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams, EulaPluginState> {
5
+ name: string;
6
+ EVENT_SHOW: "vne:eula:show";
7
+ EVENT_HIDE: "vne:eula:hide";
8
+ EVENT_ACCEPT: "vne:eula:accept";
9
+ CONTROLS_ZINDEX: number;
10
+ IS_INTERACT_ENABLED: boolean;
11
+ onAccept: () => Promise<void>;
12
+ }
@@ -0,0 +1,13 @@
1
+ import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
2
+ export class EulaControllerAccept extends ModuleControllerAccept {
3
+ name = "eula.controller.accept";
4
+ EVENT_SHOW = this.EVENTS.EULA.SHOW;
5
+ EVENT_HIDE = this.EVENTS.EULA.HIDE;
6
+ EVENT_ACCEPT = this.EVENTS.EULA.ACCEPT;
7
+ CONTROLS_ZINDEX = this.PARAMS.EULA.ZINDEX;
8
+ IS_INTERACT_ENABLED = false;
9
+ onAccept = async () => {
10
+ await this.emit(this.EVENTS.SETTINGS.SET, { name: this.SETTINGS.EULA.ACCEPTED_VERSION, value: this.PARAMS.EULA.VERSION });
11
+ await this.emit(this.EVENTS.EULA.HIDE);
12
+ };
13
+ }
@@ -0,0 +1,15 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+ import type { Lang } from "@vnejs/contracts.controllers.screens.eula";
3
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
4
+ export declare class EulaControllerArrows extends ModuleControllerArrowsVertical<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams> {
5
+ name: string;
6
+ EVENT_SHOW: "vne:eula:show";
7
+ EVENT_HIDE: "vne:eula:hide";
8
+ EVENT_UPDATE_STATE: "vne:eula:update_state";
9
+ EVENT_UPDATE_FAST: "vne:eula:update_fast";
10
+ CONTROLS_ZINDEX: number;
11
+ getLang: () => Lang;
12
+ getContentLines: () => string[];
13
+ getMaxCurrentItem: () => number;
14
+ isArrowItemAvailable: (index: number) => boolean;
15
+ }
@@ -0,0 +1,18 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+ import { getEulaContentLines } from "../utils/eula.js";
3
+ export class EulaControllerArrows extends ModuleControllerArrowsVertical {
4
+ name = "eula.controller.arrows";
5
+ EVENT_SHOW = this.EVENTS.EULA.SHOW;
6
+ EVENT_HIDE = this.EVENTS.EULA.HIDE;
7
+ EVENT_UPDATE_STATE = this.EVENTS.EULA.UPDATE_STATE;
8
+ EVENT_UPDATE_FAST = this.EVENTS.EULA.UPDATE_FAST;
9
+ CONTROLS_ZINDEX = this.PARAMS.EULA.ZINDEX;
10
+ getLang = () => {
11
+ const value = this.shared.settings?.[this.SETTINGS.EULA.LANG];
12
+ const langs = Object.values(this.PARAMS.EULA.LANGS);
13
+ return langs.includes(value) ? value : this.PARAMS.EULA.DEFAULT_LANG;
14
+ };
15
+ getContentLines = () => getEulaContentLines(this.PARAMS.EULA.LINES[this.getLang()] || "");
16
+ getMaxCurrentItem = () => Math.max(this.getContentLines().length - 1, 0);
17
+ isArrowItemAvailable = (index) => Boolean(this.getContentLines()[index]?.trim());
18
+ }
@@ -0,0 +1,22 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import type { Lang } from "@vnejs/contracts.controllers.screens.eula";
3
+ import type { SettingsChangedResult } from "@vnejs/contracts.core.settings";
4
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
5
+ import type { EulaPluginState } from "../types.js";
6
+ export declare class EulaController extends ModuleController<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams, EulaPluginState> {
7
+ name: string;
8
+ EVENT_UPDATE_VIEW: "vne:eula:update";
9
+ EVENT_UPDATE_STATE: "vne:eula:update_state";
10
+ EVENT_UPDATE_FAST: "vne:eula:update_fast";
11
+ EVENT_UPDATE_FORCE: "vne:eula:update_force";
12
+ EVENT_SHOW: "vne:eula:show";
13
+ EVENT_HIDE: "vne:eula:hide";
14
+ CONTROLS: {
15
+ abstract_back: () => undefined;
16
+ };
17
+ CONTROLS_INDEX: number;
18
+ emitExit: () => undefined;
19
+ onShowBefore: () => void;
20
+ getLang: () => Lang;
21
+ onSettingChange: (payload?: SettingsChangedResult) => Promise<import("@vnejs/registry").EmitResults<string>> | undefined;
22
+ }
@@ -0,0 +1,28 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ export class EulaController extends ModuleController {
3
+ name = "eula.controller";
4
+ EVENT_UPDATE_VIEW = this.EVENTS.EULA.UPDATE;
5
+ EVENT_UPDATE_STATE = this.EVENTS.EULA.UPDATE_STATE;
6
+ EVENT_UPDATE_FAST = this.EVENTS.EULA.UPDATE_FAST;
7
+ EVENT_UPDATE_FORCE = this.EVENTS.EULA.UPDATE_FORCE;
8
+ EVENT_SHOW = this.EVENTS.EULA.SHOW;
9
+ EVENT_HIDE = this.EVENTS.EULA.HIDE;
10
+ CONTROLS = {
11
+ [this.CONST.CONTROLS.BUTTONS.BACK]: () => void this.emitExit(),
12
+ };
13
+ CONTROLS_INDEX = this.PARAMS.EULA.ZINDEX;
14
+ emitExit = () => void this.emit(this.EVENTS.EULA.EXIT);
15
+ onShowBefore = () => this.updateState({ lang: this.getLang() });
16
+ getLang = () => {
17
+ const value = this.shared.settings?.[this.SETTINGS.EULA.LANG];
18
+ const langs = Object.values(this.PARAMS.EULA.LANGS);
19
+ return langs.includes(value) ? value : this.PARAMS.EULA.DEFAULT_LANG;
20
+ };
21
+ onSettingChange = (payload) => {
22
+ if (!this.state.isShow)
23
+ return;
24
+ return payload?.name === this.SETTINGS.EULA.LANG
25
+ ? this.updateStateAndViewFast({ lang: this.getLang(), currentArrowVerticalItem: null })
26
+ : this.updateViewFast();
27
+ };
28
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
3
+ export declare class Eula extends ModuleCore<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams> {
4
+ name: string;
5
+ subscribe: () => void;
6
+ setup: () => Promise<[import("@vnejs/registry").EmitResults<"vne:settings:init"> | undefined, import("@vnejs/registry").EmitResults<"vne:settings:init"> | undefined]>;
7
+ onExit: () => Promise<import("@vnejs/registry").EmitResults<"vne:system:close">> | undefined;
8
+ onMainMenuShow: () => Promise<void>;
9
+ }
@@ -0,0 +1,24 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class Eula extends ModuleCore {
3
+ name = "eula";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.EULA.EXIT, this.onExit);
6
+ this.on(this.EVENTS.MAINMENU.SHOW, this.onMainMenuShow, { priority: this.CONST.COMPONENTS.LIFECYCLE_PRIORITY.SHOW.MAIN });
7
+ };
8
+ setup = () => Promise.all([
9
+ this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.EULA.ACCEPTED_VERSION, value: "" }),
10
+ this.emit(this.EVENTS.SETTINGS.INIT, {
11
+ name: this.SETTINGS.EULA.LANG,
12
+ value: this.PARAMS.EULA.DEFAULT_LANG,
13
+ options: [this.PARAMS.EULA.LANGS.RU, this.PARAMS.EULA.LANGS.EN],
14
+ }),
15
+ ]);
16
+ onExit = () => this.emit(this.EVENTS.SYSTEM.CLOSE);
17
+ onMainMenuShow = async () => {
18
+ if (!this.PARAMS.EULA.ENABLED)
19
+ return;
20
+ if (this.shared.settings?.[this.SETTINGS.EULA.ACCEPTED_VERSION] === this.PARAMS.EULA.VERSION)
21
+ return;
22
+ this.emit(this.EVENTS.EULA.SHOW);
23
+ };
24
+ }
@@ -0,0 +1,6 @@
1
+ import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
2
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
3
+ export declare class EulaHideState extends ModuleControllerHideOnState<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams> {
4
+ name: string;
5
+ EVENT_HIDE: "vne:eula:hide";
6
+ }
@@ -0,0 +1,5 @@
1
+ import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
2
+ export class EulaHideState extends ModuleControllerHideOnState {
3
+ name = "eula.hide.state";
4
+ EVENT_HIDE = this.EVENTS.EULA.HIDE;
5
+ }
@@ -0,0 +1,10 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
3
+ import type { EulaPluginState } from "../types.js";
4
+ export declare class EulaView extends ModuleView<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams, EulaPluginState> {
5
+ name: string;
6
+ EVENT_UPDATE_VIEW: "vne:eula:update";
7
+ LOC_LABEL: string;
8
+ TRANSITION: number;
9
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<EulaPluginState>;
10
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import { render } from "../view/index.js";
3
+ export class EulaView extends ModuleView {
4
+ name = "eula.view";
5
+ EVENT_UPDATE_VIEW = this.EVENTS.EULA.UPDATE;
6
+ LOC_LABEL = this.PARAMS.EULA.LOC_LABEL;
7
+ TRANSITION = this.PARAMS.EULA.TRANSITION;
8
+ renderFunc = render;
9
+ }
@@ -0,0 +1,19 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { Lang, Params, PluginName, SettingsKeys, SubscribeEvents } from "@vnejs/contracts.controllers.screens.eula";
3
+ import type { PluginName as MainMenuPluginName, SubscribeEvents as MainMenuSubscribeEvents } from "@vnejs/contracts.controllers.screens.mainmenu";
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 { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
7
+ import type { PluginName as SystemPluginName, SubscribeEvents as SystemSubscribeEvents } from "@vnejs/contracts.core.system";
8
+ export type EulaPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<SettingsPluginName, SettingsSubscribeEvents> & Record<SystemPluginName, SystemSubscribeEvents> & Record<MainMenuPluginName, MainMenuSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
9
+ export type EulaPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
10
+ export type EulaPluginSettings = ModuleComponentsSettings & Record<PluginName, SettingsKeys>;
11
+ export type EulaPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
12
+ export type EulaPluginState = {
13
+ isShow: boolean;
14
+ isForce: boolean;
15
+ locs?: Record<string, string>;
16
+ lang?: Lang;
17
+ currentArrowVerticalItem?: number | null;
18
+ currentItem?: number | null;
19
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const getEulaContentLines: (text: string) => string[];
@@ -0,0 +1 @@
1
+ export const getEulaContentLines = (text) => text.split("\n").filter((line) => line.trim() !== "");
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { EulaPluginState } from "../types.js";
3
+ export declare const render: ViewRenderFunc<EulaPluginState>;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Flex, PositionBox, Screen, Text, TextControls, createRenderFunc, useStoreState } from "@vnejs/uis.react";
3
+ import { getEulaContentLines } from "../utils/eula.js";
4
+ const mapChoice = (text, i) => ({ text, value: i === 0 });
5
+ const EulaScreen = ({ store, onMount, PARAMS, SETTINGS, emit, EVENTS }) => {
6
+ const { isShow = false, isForce = false, locs = {}, lang = PARAMS.EULA.DEFAULT_LANG, currentArrowVerticalItem: contentSelectedIndex = null, currentItem: selectedIndex = null, } = useStoreState(store, onMount);
7
+ const contentTexts = getEulaContentLines(PARAMS.EULA.LINES[lang] || "").map((text) => ({ text, isHoverable: false }));
8
+ const langOptions = Object.values(PARAMS.EULA.LANGS)
9
+ .map((value) => ({ text: locs[`lang.value.${value}`], value }))
10
+ .filter(({ text }) => Boolean(text));
11
+ const langSelectedIndex = langOptions.findIndex(({ value }) => value === lang);
12
+ const buttonTexts = [locs.accept, locs.exit].filter(Boolean).map(mapChoice);
13
+ const onLangClick = (value) => {
14
+ if (!Object.values(PARAMS.EULA.LANGS).includes(value))
15
+ return;
16
+ emit(EVENTS.SETTINGS.SET, { name: SETTINGS.EULA.LANG, value });
17
+ };
18
+ const propsByView = PARAMS.EULA.VIEW_PROPS;
19
+ return (_jsx(Screen, { ...propsByView.screen, isShow: isShow, isForce: isForce, children: _jsx(PositionBox, { ...propsByView.position, children: _jsxs(Flex, { direction: Flex.DIRECTION.COLUMN, ...propsByView.flex, children: [_jsx(Text, { ...propsByView.title, text: locs.title }), _jsxs(Flex, { align: Flex.ALIGN.CENTER, justify: Flex.JUSTIFY.SPACE_BETWEEN, width: propsByView.lang.row.width, gap: propsByView.lang.row.gap, children: [_jsx(Text, { size: propsByView.lang.row.textSize, width: propsByView.lang.row.titleWidth, text: locs["lang.title"] }), _jsx(TextControls, { ...propsByView.lang.controls, value: lang, texts: langOptions, selectedIndex: langSelectedIndex >= 0 ? langSelectedIndex : undefined, onClick: onLangClick })] }), _jsx(TextControls, { ...propsByView.content.controls, texts: contentTexts, selectedIndex: contentSelectedIndex ?? undefined }), _jsx(TextControls, { ...propsByView.controls, selectedIndex: selectedIndex ?? undefined, texts: buttonTexts, onClick: (isAccept) => emit(isAccept ? EVENTS.EULA.ACCEPT : EVENTS.EULA.EXIT) })] }) }) }));
20
+ };
21
+ export const render = createRenderFunc(EulaScreen);
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.controllers.screens.eula",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.15",
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.screens.eula": "~0.2.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/module.core": "~0.2.0",
37
+ "@vnejs/module.components": "~0.2.0",
38
+ "@vnejs/module.controller.accept": "~0.2.0",
39
+ "@vnejs/module.controller.arrows.vertical": "~0.2.0",
40
+ "@vnejs/module.controller.hide.on.state": "~0.2.0",
41
+ "@vnejs/contracts.controls": "~0.2.0",
42
+ "@vnejs/contracts.core.settings": "~0.2.0",
43
+ "@vnejs/contracts.core.system": "~0.2.0",
44
+ "@vnejs/contracts.controllers.screens.mainmenu": "~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.core.system": "~0.2.0",
55
+ "@vnejs/contracts.controllers.screens.eula": "~0.2.0",
56
+ "@vnejs/contracts.controllers.screens.mainmenu": "~0.2.0",
57
+ "@vnejs/module.core": "~0.2.0",
58
+ "@vnejs/module.components": "~0.2.0",
59
+ "@vnejs/module.controller.accept": "~0.2.0",
60
+ "@vnejs/module.controller.arrows.vertical": "~0.2.0",
61
+ "@vnejs/module.controller.hide.on.state": "~0.2.0",
62
+ "@vnejs/registry": "~0.2.0",
63
+ "@vnejs/uis.react": "~0.2.0"
64
+ }
65
+ }
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ import "@vnejs/contracts.controllers.screens.eula";
2
+
3
+ import { regPlugin } from "@vnejs/registry";
4
+
5
+ import { PARAMS, PLUGIN_NAME, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.eula";
6
+
7
+ import { EulaControllerAccept } from "./modules/controller.accept.js";
8
+ import { EulaControllerArrows } from "./modules/controller.arrows.js";
9
+ import { EulaController } from "./modules/controller.js";
10
+ import { Eula } from "./modules/eula.js";
11
+ import { EulaHideState } from "./modules/hide.state.js";
12
+ import { EulaView } from "./modules/view.js";
13
+
14
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS, settings: SETTINGS_KEYS }, [
15
+ EulaController,
16
+ EulaControllerAccept,
17
+ EulaControllerArrows,
18
+ EulaHideState,
19
+ Eula,
20
+ EulaView,
21
+ ]);
@@ -0,0 +1,20 @@
1
+ import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
2
+
3
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
4
+ import type { EulaPluginState } from "../types.js";
5
+ export class EulaControllerAccept extends ModuleControllerAccept<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams, EulaPluginState> {
6
+ name = "eula.controller.accept";
7
+
8
+ EVENT_SHOW = this.EVENTS.EULA.SHOW;
9
+ EVENT_HIDE = this.EVENTS.EULA.HIDE;
10
+ EVENT_ACCEPT = this.EVENTS.EULA.ACCEPT;
11
+
12
+ CONTROLS_ZINDEX = this.PARAMS.EULA.ZINDEX;
13
+
14
+ IS_INTERACT_ENABLED = false;
15
+
16
+ onAccept = async () => {
17
+ await this.emit(this.EVENTS.SETTINGS.SET, { name: this.SETTINGS.EULA.ACCEPTED_VERSION, value: this.PARAMS.EULA.VERSION });
18
+ await this.emit(this.EVENTS.EULA.HIDE);
19
+ };
20
+ }
@@ -0,0 +1,29 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+
3
+ import type { Lang } from "@vnejs/contracts.controllers.screens.eula";
4
+ import type { SettingsChangedResult } from "@vnejs/contracts.core.settings";
5
+
6
+ import { getEulaContentLines } from "../utils/eula.js";
7
+
8
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
9
+
10
+ export class EulaControllerArrows extends ModuleControllerArrowsVertical<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams> {
11
+ name = "eula.controller.arrows";
12
+
13
+ EVENT_SHOW = this.EVENTS.EULA.SHOW;
14
+ EVENT_HIDE = this.EVENTS.EULA.HIDE;
15
+ EVENT_UPDATE_STATE = this.EVENTS.EULA.UPDATE_STATE;
16
+ EVENT_UPDATE_FAST = this.EVENTS.EULA.UPDATE_FAST;
17
+
18
+ CONTROLS_ZINDEX = this.PARAMS.EULA.ZINDEX;
19
+
20
+ getLang = (): Lang => {
21
+ const value = this.shared.settings?.[this.SETTINGS.EULA.LANG];
22
+ const langs = Object.values(this.PARAMS.EULA.LANGS) as Lang[];
23
+
24
+ return langs.includes(value as Lang) ? (value as Lang) : this.PARAMS.EULA.DEFAULT_LANG;
25
+ };
26
+ getContentLines = () => getEulaContentLines(this.PARAMS.EULA.LINES[this.getLang()] || "");
27
+ getMaxCurrentItem = () => Math.max(this.getContentLines().length - 1, 0);
28
+ isArrowItemAvailable = (index: number) => Boolean(this.getContentLines()[index]?.trim());
29
+ }
@@ -0,0 +1,40 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ import type { Lang } from "@vnejs/contracts.controllers.screens.eula";
4
+ import type { SettingsChangedResult } from "@vnejs/contracts.core.settings";
5
+
6
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
7
+ import type { EulaPluginState } from "../types.js";
8
+
9
+ export class EulaController extends ModuleController<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams, EulaPluginState> {
10
+ name = "eula.controller";
11
+
12
+ EVENT_UPDATE_VIEW = this.EVENTS.EULA.UPDATE;
13
+ EVENT_UPDATE_STATE = this.EVENTS.EULA.UPDATE_STATE;
14
+ EVENT_UPDATE_FAST = this.EVENTS.EULA.UPDATE_FAST;
15
+ EVENT_UPDATE_FORCE = this.EVENTS.EULA.UPDATE_FORCE;
16
+ EVENT_SHOW = this.EVENTS.EULA.SHOW;
17
+ EVENT_HIDE = this.EVENTS.EULA.HIDE;
18
+
19
+ CONTROLS = {
20
+ [this.CONST.CONTROLS.BUTTONS.BACK]: () => void this.emitExit(),
21
+ };
22
+ CONTROLS_INDEX = this.PARAMS.EULA.ZINDEX;
23
+
24
+ emitExit = () => void this.emit(this.EVENTS.EULA.EXIT);
25
+
26
+ onShowBefore = () => this.updateState({ lang: this.getLang() });
27
+ getLang = (): Lang => {
28
+ const value = this.shared.settings?.[this.SETTINGS.EULA.LANG];
29
+ const langs = Object.values(this.PARAMS.EULA.LANGS) as Lang[];
30
+
31
+ return langs.includes(value as Lang) ? (value as Lang) : this.PARAMS.EULA.DEFAULT_LANG;
32
+ };
33
+ onSettingChange = (payload?: SettingsChangedResult) => {
34
+ if (!this.state.isShow) return;
35
+
36
+ return payload?.name === this.SETTINGS.EULA.LANG
37
+ ? this.updateStateAndViewFast({ lang: this.getLang(), currentArrowVerticalItem: null })
38
+ : this.updateViewFast();
39
+ };
40
+ }
@@ -0,0 +1,32 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
4
+
5
+ export class Eula extends ModuleCore<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams> {
6
+ name = "eula";
7
+
8
+ subscribe = () => {
9
+ this.on(this.EVENTS.EULA.EXIT, this.onExit);
10
+ this.on(this.EVENTS.MAINMENU.SHOW, this.onMainMenuShow, { priority: this.CONST.COMPONENTS.LIFECYCLE_PRIORITY.SHOW.MAIN });
11
+ };
12
+
13
+ setup = () =>
14
+ Promise.all([
15
+ this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.EULA.ACCEPTED_VERSION, value: "" }),
16
+ this.emit(this.EVENTS.SETTINGS.INIT, {
17
+ name: this.SETTINGS.EULA.LANG,
18
+ value: this.PARAMS.EULA.DEFAULT_LANG,
19
+ options: [this.PARAMS.EULA.LANGS.RU, this.PARAMS.EULA.LANGS.EN],
20
+ }),
21
+ ]);
22
+
23
+ onExit = () => this.emit(this.EVENTS.SYSTEM.CLOSE);
24
+
25
+ onMainMenuShow = async () => {
26
+ if (!this.PARAMS.EULA.ENABLED) return;
27
+
28
+ if (this.shared.settings?.[this.SETTINGS.EULA.ACCEPTED_VERSION] === this.PARAMS.EULA.VERSION) return;
29
+
30
+ this.emit(this.EVENTS.EULA.SHOW);
31
+ };
32
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
2
+
3
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
4
+
5
+ export class EulaHideState extends ModuleControllerHideOnState<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams> {
6
+ name = "eula.hide.state";
7
+
8
+ EVENT_HIDE = this.EVENTS.EULA.HIDE;
9
+ }
@@ -0,0 +1,17 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
4
+ import type { EulaPluginState } from "../types.js";
5
+
6
+ import { render } from "../view/index.js";
7
+ export class EulaView extends ModuleView<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams, EulaPluginState> {
8
+ name = "eula.view";
9
+
10
+ EVENT_UPDATE_VIEW = this.EVENTS.EULA.UPDATE;
11
+
12
+ LOC_LABEL = this.PARAMS.EULA.LOC_LABEL;
13
+
14
+ TRANSITION = this.PARAMS.EULA.TRANSITION;
15
+
16
+ renderFunc = render;
17
+ }
@@ -0,0 +1,65 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as SETTINGS_EVENTS } from "@vnejs/contracts.core.settings";
6
+
7
+ import { EulaControllerAccept } from "../modules/controller.accept.js";
8
+
9
+ import { CONTROLS_EVENTS, createEulaTestModule, PARAMS, registerEulaPluginVne, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "./setup.js";
10
+
11
+ describe("EulaControllerAccept", () => {
12
+ beforeEach(() => {
13
+ registerEulaPluginVne();
14
+ });
15
+
16
+ it("SHOW pushes ACCEPT without INTERACT", async () => {
17
+ const { module, observer } = createEulaTestModule(EulaControllerAccept);
18
+ const accept = module as EulaControllerAccept;
19
+ const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
20
+
21
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
22
+
23
+ expect(push).toHaveBeenCalledExactlyOnceWith(
24
+ expect.objectContaining({
25
+ key: "eula.controller.accept",
26
+ checkNext: true,
27
+ index: accept.PARAMS.EULA.ZINDEX + 1,
28
+ }),
29
+ );
30
+ expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.ACCEPT);
31
+ expect(push.mock.calls[0][0].controls).not.toHaveProperty(accept.CONST.CONTROLS.BUTTONS.INTERACT);
32
+ });
33
+
34
+ it("HIDE pops ACCEPT controls", async () => {
35
+ const { observer } = createEulaTestModule(EulaControllerAccept);
36
+ const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
37
+
38
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
39
+ await observer.emit(SUBSCRIBE_EVENTS.HIDE);
40
+
41
+ expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "eula.controller.accept" });
42
+ });
43
+
44
+ it("ACCEPT emits EULA.ACCEPT", async () => {
45
+ const { module, observer } = createEulaTestModule(EulaControllerAccept);
46
+ const accept = module as EulaControllerAccept;
47
+ const acceptEvent = spyEvent(observer, SUBSCRIBE_EVENTS.ACCEPT);
48
+
49
+ accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.ACCEPT]();
50
+ await Promise.resolve();
51
+
52
+ expect(acceptEvent).toHaveBeenCalledOnce();
53
+ });
54
+
55
+ it("ACCEPT saves version and hides", async () => {
56
+ const { observer } = createEulaTestModule(EulaControllerAccept);
57
+ const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
58
+ const settingsSet = spyEvent(observer, SETTINGS_EVENTS.SET);
59
+
60
+ await observer.emit(SUBSCRIBE_EVENTS.ACCEPT);
61
+
62
+ expect(settingsSet).toHaveBeenCalledExactlyOnceWith({ name: SETTINGS_KEYS.ACCEPTED_VERSION, value: PARAMS.VERSION });
63
+ expect(hide).toHaveBeenCalledOnce();
64
+ });
65
+ });
@@ -0,0 +1,110 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as SETTINGS_EVENTS } from "@vnejs/contracts.core.settings";
6
+
7
+ import { EulaControllerArrows } from "../modules/controller.arrows.js";
8
+ import { EulaController } from "../modules/controller.js";
9
+
10
+ import { CONTROLS_EVENTS, PARAMS, SETTINGS_KEYS, createEulaTestModule, registerEulaPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
11
+
12
+ const lines = {
13
+ ru: "Первая\n\nВторая\nТретья",
14
+ en: "First\n\nSecond\nThird",
15
+ };
16
+
17
+ describe("EulaControllerArrows", () => {
18
+ beforeEach(() => {
19
+ registerEulaPluginVne();
20
+ PARAMS.LINES.ru = lines.ru;
21
+ PARAMS.LINES.en = lines.en;
22
+ });
23
+
24
+ afterEach(() => {
25
+ PARAMS.LINES.ru = "";
26
+ PARAMS.LINES.en = "";
27
+ });
28
+
29
+ it("SHOW pushes arrow controls above the controller layer", async () => {
30
+ const { module, observer } = createEulaTestModule(EulaControllerArrows);
31
+ const arrows = module as EulaControllerArrows;
32
+ const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
33
+
34
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
35
+
36
+ expect(arrows.currentItem).toBeNull();
37
+ expect(push).toHaveBeenCalledExactlyOnceWith(
38
+ expect.objectContaining({
39
+ key: "eula.controller.arrows",
40
+ checkNext: true,
41
+ index: arrows.PARAMS.EULA.ZINDEX + 1,
42
+ }),
43
+ );
44
+ });
45
+
46
+ it("HIDE pops arrow controls", async () => {
47
+ const { observer } = createEulaTestModule(EulaControllerArrows);
48
+ const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
49
+
50
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
51
+ await observer.emit(SUBSCRIBE_EVENTS.HIDE);
52
+
53
+ expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "eula.controller.arrows" });
54
+ });
55
+
56
+ it("first ARROW_BOTTOM selects 0 and emits UPDATE_STATE plus UPDATE_FAST", async () => {
57
+ const { module, observer } = createEulaTestModule(EulaControllerArrows);
58
+ const arrows = module as EulaControllerArrows;
59
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
60
+ const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
61
+
62
+ await arrows.incCurrentItem();
63
+
64
+ expect(arrows.currentItem).toBe(0);
65
+ expect(stateUpdate).toHaveBeenCalledExactlyOnceWith({ currentArrowVerticalItem: 0 });
66
+ expect(updateFast).toHaveBeenCalledOnce();
67
+ });
68
+
69
+ it("arrow wrap cycles non-empty lines", async () => {
70
+ const { module, observer } = createEulaTestModule(EulaControllerArrows);
71
+ const arrows = module as EulaControllerArrows;
72
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
73
+
74
+ await arrows.incCurrentItem();
75
+ await arrows.incCurrentItem();
76
+ await arrows.incCurrentItem();
77
+ expect(arrows.currentItem).toBe(2);
78
+
79
+ await arrows.incCurrentItem();
80
+ expect(arrows.currentItem).toBe(0);
81
+ expect(stateUpdate).toHaveBeenLastCalledWith({ currentArrowVerticalItem: 0 });
82
+ });
83
+
84
+ it("isArrowItemAvailable skips empty lines", async () => {
85
+ const { module } = createEulaTestModule(EulaControllerArrows);
86
+ const arrows = module as EulaControllerArrows;
87
+
88
+ expect(arrows.isArrowItemAvailable(0)).toBe(true);
89
+ expect(arrows.isArrowItemAvailable(1)).toBe(true);
90
+ expect(arrows.isArrowItemAvailable(2)).toBe(true);
91
+ });
92
+ });
93
+
94
+ describe("EulaController", () => {
95
+ beforeEach(() => {
96
+ registerEulaPluginVne();
97
+ });
98
+
99
+ it("SETTINGS.CHANGED lang resets currentArrowVerticalItem while shown", async () => {
100
+ const { module, observer } = createEulaTestModule(EulaController);
101
+ const controller = module as EulaController;
102
+ const update = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE);
103
+
104
+ controller.state.isShow = true;
105
+ await observer.emit(SETTINGS_EVENTS.CHANGED, { name: SETTINGS_KEYS.LANG });
106
+
107
+ expect(controller.state.currentArrowVerticalItem).toBeNull();
108
+ expect(update).toHaveBeenCalled();
109
+ });
110
+ });
@@ -0,0 +1,55 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as SYSTEM_EVENTS } from "@vnejs/contracts.core.system";
6
+
7
+ import { Eula } from "../modules/eula.js";
8
+
9
+ import { createEulaTestModule, MAINMENU_EVENTS, PARAMS, registerEulaPluginVne, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "./setup.js";
10
+
11
+ describe("Eula", () => {
12
+ beforeEach(() => {
13
+ registerEulaPluginVne();
14
+ });
15
+
16
+ it("onMainMenuShow emits SHOW when version mismatch", async () => {
17
+ const { observer } = createEulaTestModule(Eula);
18
+ const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
19
+
20
+ await observer.emit(MAINMENU_EVENTS.SHOW);
21
+
22
+ expect(show).toHaveBeenCalledOnce();
23
+ });
24
+
25
+ it("onMainMenuShow skips when ENABLED is false", async () => {
26
+ const { module, observer } = createEulaTestModule(Eula);
27
+ const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
28
+
29
+ (module as Eula).PARAMS.EULA.ENABLED = false;
30
+
31
+ await observer.emit(MAINMENU_EVENTS.SHOW);
32
+
33
+ expect(show).not.toHaveBeenCalled();
34
+ });
35
+
36
+ it("onMainMenuShow skips when version matches", async () => {
37
+ const { observer } = createEulaTestModule(Eula, {
38
+ shared: { settings: { [SETTINGS_KEYS.ACCEPTED_VERSION]: PARAMS.VERSION } },
39
+ });
40
+ const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
41
+
42
+ await observer.emit(MAINMENU_EVENTS.SHOW);
43
+
44
+ expect(show).not.toHaveBeenCalled();
45
+ });
46
+
47
+ it("onExit emits SYSTEM.CLOSE", async () => {
48
+ const { observer } = createEulaTestModule(Eula);
49
+ const close = spyEvent(observer, SYSTEM_EVENTS.CLOSE);
50
+
51
+ await observer.emit(SUBSCRIBE_EVENTS.EXIT);
52
+
53
+ expect(close).toHaveBeenCalledOnce();
54
+ });
55
+ });
@@ -0,0 +1,27 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as STATE_EVENTS } from "@vnejs/contracts.core.state";
6
+
7
+ import { EulaHideState } from "../modules/hide.state.js";
8
+
9
+ import { createEulaTestModule, registerEulaPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
10
+
11
+ describe("EulaHideState", () => {
12
+ beforeEach(() => {
13
+ registerEulaPluginVne();
14
+ });
15
+
16
+ it("STATE.SET and STATE.CLEAR emit HIDE with isForce", async () => {
17
+ const { observer } = createEulaTestModule(EulaHideState);
18
+ const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
19
+
20
+ await observer.emit(STATE_EVENTS.SET);
21
+ await observer.emit(STATE_EVENTS.CLEAR);
22
+
23
+ expect(hide).toHaveBeenCalledTimes(2);
24
+ expect(hide).toHaveBeenNthCalledWith(1, { isForce: true });
25
+ expect(hide).toHaveBeenNthCalledWith(2, { isForce: true });
26
+ });
27
+ });
@@ -0,0 +1,43 @@
1
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubSilentEvent } from "@vnejs/test-utils";
2
+
3
+ import { PARAMS, PLUGIN_NAME, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.eula";
4
+ import { PARAMS as MAINMENU_PARAMS, PLUGIN_NAME as MAINMENU, SUBSCRIBE_EVENTS as MAINMENU_EVENTS } from "@vnejs/contracts.controllers.screens.mainmenu";
5
+ import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
6
+
7
+ export const registerEulaPluginVne = () => {
8
+ registerCoreVne();
9
+ registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
10
+ registerVnePlugin(MAINMENU, { events: MAINMENU_EVENTS, params: MAINMENU_PARAMS });
11
+ registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: { ...PARAMS, ENABLED: true }, settings: SETTINGS_KEYS });
12
+ };
13
+
14
+ export const createEulaTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
15
+ ModuleClass: T,
16
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
17
+ ) => {
18
+ const result = baseCreateTestModule(ModuleClass, {
19
+ state: {
20
+ eula: { isShow: false },
21
+ ...(options.state ?? {}),
22
+ },
23
+ shared: {
24
+ settings: {
25
+ [SETTINGS_KEYS.ACCEPTED_VERSION]: "",
26
+ [SETTINGS_KEYS.LANG]: PARAMS.DEFAULT_LANG,
27
+ ...(options.shared?.settings ?? {}),
28
+ },
29
+ ...(options.shared ?? {}),
30
+ },
31
+ ...options,
32
+ });
33
+
34
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW);
35
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.HIDE);
36
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE);
37
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
38
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
39
+
40
+ return result;
41
+ };
42
+
43
+ export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, MAINMENU_EVENTS, SETTINGS_KEYS, CONTROLS_EVENTS };
package/src/types.ts ADDED
@@ -0,0 +1,30 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+
3
+ import type { Lang, Params, PluginName, SettingsKeys, SubscribeEvents } from "@vnejs/contracts.controllers.screens.eula";
4
+ import type { PluginName as MainMenuPluginName, SubscribeEvents as MainMenuSubscribeEvents } from "@vnejs/contracts.controllers.screens.mainmenu";
5
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
6
+ import type { PluginName as SettingsPluginName, SubscribeEvents as SettingsSubscribeEvents } from "@vnejs/contracts.core.settings";
7
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
8
+ import type { PluginName as SystemPluginName, SubscribeEvents as SystemSubscribeEvents } from "@vnejs/contracts.core.system";
9
+
10
+ export type EulaPluginEvents = ModuleComponentsEvents &
11
+ Record<PluginName, SubscribeEvents> &
12
+ Record<SettingsPluginName, SettingsSubscribeEvents> &
13
+ Record<SystemPluginName, SystemSubscribeEvents> &
14
+ Record<MainMenuPluginName, MainMenuSubscribeEvents> &
15
+ Record<StatePluginName, StateSubscribeEvents>;
16
+
17
+ export type EulaPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
18
+
19
+ export type EulaPluginSettings = ModuleComponentsSettings & Record<PluginName, SettingsKeys>;
20
+
21
+ export type EulaPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
22
+
23
+ export type EulaPluginState = {
24
+ isShow: boolean;
25
+ isForce: boolean;
26
+ locs?: Record<string, string>;
27
+ lang?: Lang;
28
+ currentArrowVerticalItem?: number | null;
29
+ currentItem?: number | null;
30
+ };
@@ -0,0 +1 @@
1
+ export const getEulaContentLines = (text: string) => text.split("\n").filter((line) => line.trim() !== "");
@@ -0,0 +1,94 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+
3
+ import { Flex, PositionBox, Screen, Text, TextControls, createRenderFunc, useStoreState } from "@vnejs/uis.react";
4
+
5
+ import type { ReactComponentProps } from "@vnejs/uis.react";
6
+
7
+ import type { Lang } from "@vnejs/contracts.controllers.screens.eula";
8
+
9
+ import { getEulaContentLines } from "../utils/eula.js";
10
+
11
+ import type { EulaPluginConstants, EulaPluginEvents, EulaPluginParams, EulaPluginSettings } from "../types.js";
12
+ import type { EulaPluginState } from "../types.js";
13
+
14
+ type EulaComponentProps = ReactComponentProps<EulaPluginEvents, EulaPluginConstants, EulaPluginSettings, EulaPluginParams, EulaPluginState>;
15
+
16
+ const mapChoice = (text: string, i: number) => ({ text, value: i === 0 });
17
+
18
+ const EulaScreen = ({ store, onMount, PARAMS, SETTINGS, emit, EVENTS }: EulaComponentProps) => {
19
+ const {
20
+ isShow = false,
21
+ isForce = false,
22
+ locs = {},
23
+ lang = PARAMS.EULA.DEFAULT_LANG,
24
+ currentArrowVerticalItem: contentSelectedIndex = null,
25
+ currentItem: selectedIndex = null,
26
+ } = useStoreState<EulaPluginState>(store, onMount);
27
+
28
+ const contentTexts = getEulaContentLines(PARAMS.EULA.LINES[lang] || "").map((text) => ({ text, isHoverable: false }));
29
+ const langOptions = Object.values(PARAMS.EULA.LANGS)
30
+ .map((value) => ({ text: locs[`lang.value.${value}`], value }))
31
+ .filter(({ text }) => Boolean(text));
32
+ const langSelectedIndex = langOptions.findIndex(({ value }) => value === lang);
33
+ const buttonTexts = [locs.accept, locs.exit].filter(Boolean).map(mapChoice);
34
+
35
+ const onLangClick = (value?: unknown) => {
36
+ if (!Object.values(PARAMS.EULA.LANGS).includes(value as Lang)) return;
37
+
38
+ emit(EVENTS.SETTINGS.SET, { name: SETTINGS.EULA.LANG, value });
39
+ };
40
+
41
+ const propsByView = PARAMS.EULA.VIEW_PROPS;
42
+
43
+ return (
44
+ <Screen
45
+ {...propsByView.screen}
46
+ isShow={isShow}
47
+ isForce={isForce}
48
+ >
49
+ <PositionBox {...propsByView.position}>
50
+ <Flex
51
+ direction={Flex.DIRECTION.COLUMN}
52
+ {...propsByView.flex}
53
+ >
54
+ <Text
55
+ {...propsByView.title}
56
+ text={locs.title}
57
+ />
58
+ <Flex
59
+ align={Flex.ALIGN.CENTER}
60
+ justify={Flex.JUSTIFY.SPACE_BETWEEN}
61
+ width={propsByView.lang.row.width}
62
+ gap={propsByView.lang.row.gap}
63
+ >
64
+ <Text
65
+ size={propsByView.lang.row.textSize}
66
+ width={propsByView.lang.row.titleWidth}
67
+ text={locs["lang.title"]}
68
+ />
69
+ <TextControls
70
+ {...propsByView.lang.controls}
71
+ value={lang}
72
+ texts={langOptions}
73
+ selectedIndex={langSelectedIndex >= 0 ? langSelectedIndex : undefined}
74
+ onClick={onLangClick}
75
+ />
76
+ </Flex>
77
+ <TextControls
78
+ {...propsByView.content.controls}
79
+ texts={contentTexts}
80
+ selectedIndex={contentSelectedIndex ?? undefined}
81
+ />
82
+ <TextControls
83
+ {...propsByView.controls}
84
+ selectedIndex={selectedIndex ?? undefined}
85
+ texts={buttonTexts}
86
+ onClick={(isAccept?: unknown) => emit(isAccept ? EVENTS.EULA.ACCEPT : EVENTS.EULA.EXIT)}
87
+ />
88
+ </Flex>
89
+ </PositionBox>
90
+ </Screen>
91
+ );
92
+ };
93
+
94
+ export const render: ViewRenderFunc<EulaPluginState> = createRenderFunc(EulaScreen);
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "jsx": "react-jsx"
7
+ },
8
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
9
+ "exclude": ["dist", "node_modules", "src/tests"]
10
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.