@vnejs/plugins.controllers.scenario.choose 0.0.0-stage → 0.2.21

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,2 @@
1
+ import "@vnejs/contracts.scenario.choose";
2
+ import "@vnejs/contracts.controllers.scenario.choose";
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ import "@vnejs/contracts.scenario.choose";
2
+ import "@vnejs/contracts.controllers.scenario.choose";
3
+ import { regPlugin } from "@vnejs/registry";
4
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.scenario.choose";
5
+ import { ChooseViewBridge } from "./modules/bridge.js";
6
+ import { ChooseViewControllerAccept } from "./modules/controller.accept.js";
7
+ import { ChooseViewControllerArrows } from "./modules/controller.arrows.js";
8
+ import { ChooseViewController } from "./modules/controller.js";
9
+ import { ChooseViewView } from "./modules/view.js";
10
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
11
+ ChooseViewBridge,
12
+ ChooseViewController,
13
+ ChooseViewControllerAccept,
14
+ ChooseViewControllerArrows,
15
+ ChooseViewView,
16
+ ]);
@@ -0,0 +1,9 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { ChooseVisibilityPayload } from "@vnejs/contracts.scenario.choose";
3
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
4
+ export declare class ChooseViewBridge extends ModuleCore<ChoosePluginEvents, ChoosePluginConstants, ChoosePluginSettings, ChoosePluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onChooseShow: (payload?: ChooseVisibilityPayload) => Promise<import("@vnejs/registry").EmitResults<"vne:choose_view:show">> | undefined;
8
+ onChooseHide: (payload?: ChooseVisibilityPayload) => Promise<import("@vnejs/registry").EmitResults<"vne:choose_view:hide">> | undefined;
9
+ }
@@ -0,0 +1,10 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class ChooseViewBridge extends ModuleCore {
3
+ name = "choose_view.bridge";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.CHOOSE.SHOW, this.onChooseShow);
6
+ this.on(this.EVENTS.CHOOSE.HIDE, this.onChooseHide);
7
+ };
8
+ onChooseShow = (payload = {}) => this.emit(this.EVENTS.CHOOSE_VIEW.SHOW, payload);
9
+ onChooseHide = (payload = {}) => this.emit(this.EVENTS.CHOOSE_VIEW.HIDE, payload);
10
+ }
@@ -0,0 +1,12 @@
1
+ import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
2
+ import type { ChoosePluginControllerState } from "../utils/choose.js";
3
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
4
+ export declare class ChooseViewControllerAccept extends ModuleControllerAccept<ChoosePluginEvents, ChoosePluginConstants, ChoosePluginSettings, ChoosePluginParams, ChoosePluginControllerState> {
5
+ name: string;
6
+ EVENT_SHOW: "vne:choose_view:show";
7
+ EVENT_HIDE: "vne:choose_view:hide";
8
+ EVENT_ACCEPT: "vne:choose_view:accept";
9
+ EVENT_UPDATE_STATE: "vne:choose_view:update_state";
10
+ CONTROLS_ZINDEX: number;
11
+ onAccept: () => void;
12
+ }
@@ -0,0 +1,14 @@
1
+ import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
2
+ export class ChooseViewControllerAccept extends ModuleControllerAccept {
3
+ name = "choose_view.controller.accept";
4
+ EVENT_SHOW = this.EVENTS.CHOOSE_VIEW.SHOW;
5
+ EVENT_HIDE = this.EVENTS.CHOOSE_VIEW.HIDE;
6
+ EVENT_ACCEPT = this.EVENTS.CHOOSE_VIEW.ACCEPT;
7
+ EVENT_UPDATE_STATE = this.EVENTS.CHOOSE_VIEW.UPDATE_STATE;
8
+ CONTROLS_ZINDEX = this.PARAMS.CHOOSE_VIEW.ZINDEX;
9
+ onAccept = () => {
10
+ const index = this.state.currentArrowVerticalItem;
11
+ if (index != null)
12
+ void this.emit(this.EVENTS.CHOOSE.OPTION, { index });
13
+ };
14
+ }
@@ -0,0 +1,13 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
3
+ export declare class ChooseViewControllerArrows extends ModuleControllerArrowsVertical<ChoosePluginEvents, ChoosePluginConstants, ChoosePluginSettings, ChoosePluginParams> {
4
+ name: string;
5
+ EVENT_SHOW: "vne:choose_view:show";
6
+ EVENT_HIDE: "vne:choose_view:hide";
7
+ EVENT_UPDATE_STATE: "vne:choose_view:update_state";
8
+ EVENT_UPDATE_FAST: "vne:choose_view:update_fast";
9
+ CONTROLS_ZINDEX: number;
10
+ getChooseOptions: () => import("@vnejs/contracts.scenario.choose").ChooseOption[];
11
+ getMaxCurrentItem: () => number;
12
+ isArrowItemAvailable: (index: number) => boolean;
13
+ }
@@ -0,0 +1,12 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+ export class ChooseViewControllerArrows extends ModuleControllerArrowsVertical {
3
+ name = "choose_view.controller.arrows";
4
+ EVENT_SHOW = this.EVENTS.CHOOSE_VIEW.SHOW;
5
+ EVENT_HIDE = this.EVENTS.CHOOSE_VIEW.HIDE;
6
+ EVENT_UPDATE_STATE = this.EVENTS.CHOOSE_VIEW.UPDATE_STATE;
7
+ EVENT_UPDATE_FAST = this.EVENTS.CHOOSE_VIEW.UPDATE_FAST;
8
+ CONTROLS_ZINDEX = this.PARAMS.CHOOSE_VIEW.ZINDEX;
9
+ getChooseOptions = () => this.globalState.choose?.options ?? [];
10
+ getMaxCurrentItem = () => this.getChooseOptions().length - 1;
11
+ isArrowItemAvailable = (index) => !this.getChooseOptions()[index]?.hided;
12
+ }
@@ -0,0 +1,18 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import type { ChoosePluginControllerState } from "../utils/choose.js";
3
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
4
+ export declare class ChooseViewController extends ModuleController<ChoosePluginEvents, ChoosePluginConstants, ChoosePluginSettings, ChoosePluginParams, ChoosePluginControllerState> {
5
+ name: string;
6
+ EVENT_UPDATE_VIEW: "vne:choose_view:update";
7
+ EVENT_UPDATE_STATE: "vne:choose_view:update_state";
8
+ EVENT_UPDATE_FAST: "vne:choose_view:update_fast";
9
+ EVENT_UPDATE_FORCE: "vne:choose_view:update_force";
10
+ EVENT_SHOW: "vne:choose_view:show";
11
+ EVENT_HIDE: "vne:choose_view:hide";
12
+ CONTROLS: {};
13
+ CONTROLS_EXTENSIONS: {
14
+ [x: string]: (controls: unknown) => void | Promise<void>;
15
+ };
16
+ CONTROLS_INDEX: number;
17
+ onShowBefore: () => Promise<void>;
18
+ }
@@ -0,0 +1,16 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ export class ChooseViewController extends ModuleController {
3
+ name = "choose_view.controller";
4
+ EVENT_UPDATE_VIEW = this.EVENTS.CHOOSE_VIEW.UPDATE;
5
+ EVENT_UPDATE_STATE = this.EVENTS.CHOOSE_VIEW.UPDATE_STATE;
6
+ EVENT_UPDATE_FAST = this.EVENTS.CHOOSE_VIEW.UPDATE_FAST;
7
+ EVENT_UPDATE_FORCE = this.EVENTS.CHOOSE_VIEW.UPDATE_FORCE;
8
+ EVENT_SHOW = this.EVENTS.CHOOSE_VIEW.SHOW;
9
+ EVENT_HIDE = this.EVENTS.CHOOSE_VIEW.HIDE;
10
+ CONTROLS = {};
11
+ CONTROLS_EXTENSIONS = this.PARAMS.CHOOSE_VIEW.CONTROLS_EXTENSIONS;
12
+ CONTROLS_INDEX = this.PARAMS.CHOOSE_VIEW.ZINDEX;
13
+ onShowBefore = async () => {
14
+ this.updateState(structuredClone(this.globalState.choose));
15
+ };
16
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { ChoosePluginControllerState } from "../utils/choose.js";
3
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
4
+ export declare class ChooseViewView extends ModuleView<ChoosePluginEvents, ChoosePluginConstants, ChoosePluginSettings, ChoosePluginParams, ChoosePluginControllerState> {
5
+ name: string;
6
+ EVENT_UPDATE_VIEW: "vne:choose_view:update";
7
+ TRANSITION: number;
8
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<ChoosePluginControllerState>;
9
+ }
@@ -0,0 +1,8 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import { render } from "../view/index.js";
3
+ export class ChooseViewView extends ModuleView {
4
+ name = "choose_view.view";
5
+ EVENT_UPDATE_VIEW = this.EVENTS.CHOOSE_VIEW.UPDATE;
6
+ TRANSITION = this.PARAMS.CHOOSE_VIEW.TRANSITION;
7
+ renderFunc = render;
8
+ }
@@ -0,0 +1,13 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { PluginName, SubscribeEvents, Params } from "@vnejs/contracts.controllers.scenario.choose";
3
+ import type { PluginName as ControlsPluginName, Constants as ControlsConstants } from "@vnejs/contracts.controls";
4
+ import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
5
+ import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
6
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
7
+ import type { PluginName as VendorsPluginName, SubscribeEvents as VendorsSubscribeEvents } from "@vnejs/contracts.core.vendors";
8
+ import type { PluginName as ChoosePluginName, SubscribeEvents as ChooseSubscribeEvents, Params as ChooseParams } from "@vnejs/contracts.scenario.choose";
9
+ import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
10
+ export type ChoosePluginEvents = ModuleComponentsEvents & Record<ChoosePluginName, ChooseSubscribeEvents> & Record<PluginName, SubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents> & Record<VendorsPluginName, VendorsSubscribeEvents> & Record<LogsPluginName, LogsSubscribeEvents> & Record<TextPluginName, TextSubscribeEvents>;
11
+ export type ChoosePluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
12
+ export type ChoosePluginSettings = ModuleComponentsSettings;
13
+ export type ChoosePluginParams = ModuleComponentsParams & Record<ChoosePluginName, ChooseParams> & Record<PluginName, Params>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { ModuleControllerState } from "@vnejs/module.components";
2
+ import type { ChooseOption, ChoosePluginModelState } from "@vnejs/contracts.controllers.scenario.choose";
3
+ export type ChoosePluginControllerState = ModuleControllerState & ChoosePluginModelState & {
4
+ currentItem?: number | null;
5
+ currentArrowVerticalItem?: number | null;
6
+ };
7
+ export type ChooseViewOption = ChooseOption;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { ChoosePluginControllerState } from "../utils/choose.js";
3
+ export declare const render: ViewRenderFunc<ChoosePluginControllerState>;
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createElement as _createElement } from "react";
3
+ import { Flex, PositionBox, Screen, Text, TextControls, createRenderFunc, useIsForceHook, useStoreState } from "@vnejs/uis.react";
4
+ const renderOptionWithCoords = ({ text, isDisabled, isNotRender, value, coords, props, currentItem, onClick }) => {
5
+ const [x = 0, y = 0] = coords ?? [];
6
+ const positionProps = { left: `${x}%`, top: `${y}%`, translateX: "-50%", translateY: "-50%", isNotRender };
7
+ const propsText = {
8
+ ...props.PARAMS.CHOOSE_VIEW.VIEW_PROPS.text,
9
+ isDisabled,
10
+ isHoverable: !isDisabled,
11
+ onClick,
12
+ text,
13
+ value,
14
+ isSelected: currentItem === value,
15
+ };
16
+ return (_createElement(PositionBox, { ...positionProps, key: value },
17
+ _jsx(Text, { ...propsText })));
18
+ };
19
+ const Choose = ({ store, onMount, emit, EVENTS, PARAMS }) => {
20
+ const { isShow = false, isForce = false, options = [], args = {}, currentArrowVerticalItem: currentItem = null, } = useStoreState(store, onMount);
21
+ const onClick = (value) => void emit(EVENTS.CHOOSE.OPTION, { index: Number(value) });
22
+ const isRealForce = useIsForceHook(isForce);
23
+ const title = typeof args.title === "string" ? args.title : null;
24
+ const optionsMapped = options.map(({ text, hided, coords, disabled }, i) => ({
25
+ text,
26
+ i,
27
+ coords,
28
+ isNotRender: Boolean(hided),
29
+ isDisabled: Boolean(disabled),
30
+ }));
31
+ const textsInfo = optionsMapped.map(({ i, ...obj }) => ({ value: i, isSelected: currentItem === i, ...obj }));
32
+ const optionsRegular = textsInfo.filter((e) => !e.coords);
33
+ const optionsWithCoords = textsInfo.filter((e) => e.coords);
34
+ const propsView = PARAMS.CHOOSE_VIEW.VIEW_PROPS;
35
+ return (_jsxs(Screen, { ...propsView.screen, isDisableAutoread: true, isIgnoreOnScreenshot: false, isShow: isShow, isForce: isRealForce, children: [optionsWithCoords.map((option) => renderOptionWithCoords({ ...option, currentItem, onClick, props: { store, onMount, emit, EVENTS, PARAMS } })), _jsx(PositionBox, { ...propsView.position, children: _jsxs(Flex, { direction: propsView.wrap.flexDirection, gap: propsView.wrap.flexGap, align: propsView.wrap.flexAlign, children: [title ? (_jsx(Text, { ...propsView.title, text: title })) : null, _jsx(TextControls, { ...propsView.controls, texts: optionsRegular, onClick: onClick })] }) })] }));
36
+ };
37
+ export const render = createRenderFunc(Choose);
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.controllers.scenario.choose",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.21",
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.scenario.choose": "~0.2.0",
34
+ "@vnejs/contracts.controllers.scenario.choose": "~0.2.0"
35
+ },
36
+ "peerDependencies": {
37
+ "@vnejs/contracts.controls": "~0.2.0",
38
+ "@vnejs/module.components": "~0.2.0",
39
+ "@vnejs/module.core": "~0.2.0",
40
+ "@vnejs/module.controller.arrows.vertical": "~0.2.0",
41
+ "@vnejs/module.controller.accept": "~0.2.0",
42
+ "@vnejs/registry": "~0.2.0",
43
+ "@vnejs/uis.react": "~0.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "@vnejs/configs.ts-common": "~0.2.0",
47
+ "@vnejs/configs.vitest": "~0.2.0",
48
+ "@vnejs/test-utils": "~0.2.0",
49
+ "@vnejs/contracts.controls": "~0.2.0",
50
+ "@vnejs/contracts.scenario.choose": "~0.2.0",
51
+ "@vnejs/contracts.text": "~0.2.0",
52
+ "@vnejs/contracts.controllers.scenario.choose": "~0.2.0",
53
+ "@vnejs/helpers": "~0.2.0",
54
+ "@vnejs/module.components": "~0.2.0",
55
+ "@vnejs/module.core": "~0.2.0",
56
+ "@vnejs/module.controller.arrows.vertical": "~0.2.0",
57
+ "@vnejs/module.controller.accept": "~0.2.0",
58
+ "@vnejs/registry": "~0.2.0",
59
+ "@vnejs/sources-set": "~0.2.0",
60
+ "@vnejs/uis.react": "~0.2.0"
61
+ }
62
+ }
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ import "@vnejs/contracts.scenario.choose";
2
+ import "@vnejs/contracts.controllers.scenario.choose";
3
+
4
+ import { regPlugin } from "@vnejs/registry";
5
+
6
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.scenario.choose";
7
+
8
+ import { ChooseViewBridge } from "./modules/bridge.js";
9
+ import { ChooseViewControllerAccept } from "./modules/controller.accept.js";
10
+ import { ChooseViewControllerArrows } from "./modules/controller.arrows.js";
11
+ import { ChooseViewController } from "./modules/controller.js";
12
+ import { ChooseViewView } from "./modules/view.js";
13
+
14
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
15
+ ChooseViewBridge,
16
+ ChooseViewController,
17
+ ChooseViewControllerAccept,
18
+ ChooseViewControllerArrows,
19
+ ChooseViewView,
20
+ ]);
@@ -0,0 +1,18 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { ChooseVisibilityPayload } from "@vnejs/contracts.scenario.choose";
4
+
5
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
6
+
7
+ export class ChooseViewBridge extends ModuleCore<ChoosePluginEvents, ChoosePluginConstants, ChoosePluginSettings, ChoosePluginParams> {
8
+ name = "choose_view.bridge";
9
+
10
+ subscribe = () => {
11
+ this.on(this.EVENTS.CHOOSE.SHOW, this.onChooseShow);
12
+ this.on(this.EVENTS.CHOOSE.HIDE, this.onChooseHide);
13
+ };
14
+
15
+ onChooseShow = (payload: ChooseVisibilityPayload = {}) => this.emit(this.EVENTS.CHOOSE_VIEW.SHOW, payload);
16
+
17
+ onChooseHide = (payload: ChooseVisibilityPayload = {}) => this.emit(this.EVENTS.CHOOSE_VIEW.HIDE, payload);
18
+ }
@@ -0,0 +1,28 @@
1
+ import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
2
+
3
+ import type { ChoosePluginControllerState } from "../utils/choose.js";
4
+
5
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
6
+
7
+ export class ChooseViewControllerAccept extends ModuleControllerAccept<
8
+ ChoosePluginEvents,
9
+ ChoosePluginConstants,
10
+ ChoosePluginSettings,
11
+ ChoosePluginParams,
12
+ ChoosePluginControllerState
13
+ > {
14
+ name = "choose_view.controller.accept";
15
+
16
+ EVENT_SHOW = this.EVENTS.CHOOSE_VIEW.SHOW;
17
+ EVENT_HIDE = this.EVENTS.CHOOSE_VIEW.HIDE;
18
+ EVENT_ACCEPT = this.EVENTS.CHOOSE_VIEW.ACCEPT;
19
+ EVENT_UPDATE_STATE = this.EVENTS.CHOOSE_VIEW.UPDATE_STATE;
20
+
21
+ CONTROLS_ZINDEX = this.PARAMS.CHOOSE_VIEW.ZINDEX;
22
+
23
+ onAccept = () => {
24
+ const index = this.state.currentArrowVerticalItem;
25
+
26
+ if (index != null) void this.emit(this.EVENTS.CHOOSE.OPTION, { index });
27
+ };
28
+ }
@@ -0,0 +1,25 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+
3
+ import type { ChoosePluginModelState } from "@vnejs/contracts.controllers.scenario.choose";
4
+
5
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
6
+
7
+ export class ChooseViewControllerArrows extends ModuleControllerArrowsVertical<
8
+ ChoosePluginEvents,
9
+ ChoosePluginConstants,
10
+ ChoosePluginSettings,
11
+ ChoosePluginParams
12
+ > {
13
+ name = "choose_view.controller.arrows";
14
+
15
+ EVENT_SHOW = this.EVENTS.CHOOSE_VIEW.SHOW;
16
+ EVENT_HIDE = this.EVENTS.CHOOSE_VIEW.HIDE;
17
+ EVENT_UPDATE_STATE = this.EVENTS.CHOOSE_VIEW.UPDATE_STATE;
18
+ EVENT_UPDATE_FAST = this.EVENTS.CHOOSE_VIEW.UPDATE_FAST;
19
+
20
+ CONTROLS_ZINDEX = this.PARAMS.CHOOSE_VIEW.ZINDEX;
21
+
22
+ getChooseOptions = () => (this.globalState.choose as ChoosePluginModelState | undefined)?.options ?? [];
23
+ getMaxCurrentItem = () => this.getChooseOptions().length - 1;
24
+ isArrowItemAvailable = (index: number) => !this.getChooseOptions()[index]?.hided;
25
+ }
@@ -0,0 +1,30 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ import type { ChoosePluginControllerState } from "../utils/choose.js";
4
+
5
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
6
+
7
+ export class ChooseViewController extends ModuleController<
8
+ ChoosePluginEvents,
9
+ ChoosePluginConstants,
10
+ ChoosePluginSettings,
11
+ ChoosePluginParams,
12
+ ChoosePluginControllerState
13
+ > {
14
+ name = "choose_view.controller";
15
+
16
+ EVENT_UPDATE_VIEW = this.EVENTS.CHOOSE_VIEW.UPDATE;
17
+ EVENT_UPDATE_STATE = this.EVENTS.CHOOSE_VIEW.UPDATE_STATE;
18
+ EVENT_UPDATE_FAST = this.EVENTS.CHOOSE_VIEW.UPDATE_FAST;
19
+ EVENT_UPDATE_FORCE = this.EVENTS.CHOOSE_VIEW.UPDATE_FORCE;
20
+ EVENT_SHOW = this.EVENTS.CHOOSE_VIEW.SHOW;
21
+ EVENT_HIDE = this.EVENTS.CHOOSE_VIEW.HIDE;
22
+
23
+ CONTROLS = {};
24
+ CONTROLS_EXTENSIONS = this.PARAMS.CHOOSE_VIEW.CONTROLS_EXTENSIONS;
25
+ CONTROLS_INDEX = this.PARAMS.CHOOSE_VIEW.ZINDEX;
26
+
27
+ onShowBefore = async () => {
28
+ this.updateState(structuredClone(this.globalState.choose));
29
+ };
30
+ }
@@ -0,0 +1,23 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import type { ChoosePluginControllerState } from "../utils/choose.js";
4
+
5
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
6
+
7
+ import { render } from "../view/index.js";
8
+
9
+ export class ChooseViewView extends ModuleView<
10
+ ChoosePluginEvents,
11
+ ChoosePluginConstants,
12
+ ChoosePluginSettings,
13
+ ChoosePluginParams,
14
+ ChoosePluginControllerState
15
+ > {
16
+ name = "choose_view.view";
17
+
18
+ EVENT_UPDATE_VIEW = this.EVENTS.CHOOSE_VIEW.UPDATE;
19
+
20
+ TRANSITION = this.PARAMS.CHOOSE_VIEW.TRANSITION;
21
+
22
+ renderFunc = render;
23
+ }
@@ -0,0 +1,70 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as CHOOSE_EVENTS } from "@vnejs/contracts.scenario.choose";
6
+
7
+ import { ChooseViewControllerAccept } from "../modules/controller.accept.js";
8
+
9
+ import { CONTROLS_EVENTS, createChooseTestModule, registerChoosePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
10
+
11
+ describe("ChooseViewControllerAccept", () => {
12
+ beforeEach(() => {
13
+ registerChoosePluginVne();
14
+ });
15
+
16
+ it("SHOW pushes ACCEPT and INTERACT controls", async () => {
17
+ const { module, observer } = createChooseTestModule(ChooseViewControllerAccept);
18
+ const accept = module as ChooseViewControllerAccept;
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: "choose_view.controller.accept",
26
+ checkNext: true,
27
+ index: accept.PARAMS.CHOOSE_VIEW.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).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.INTERACT);
32
+ });
33
+
34
+ it("HIDE pops ACCEPT controls", async () => {
35
+ const { observer } = createChooseTestModule(ChooseViewControllerAccept);
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: "choose_view.controller.accept" });
42
+ });
43
+
44
+ it("ACCEPT and INTERACT emit CHOOSE_VIEW.ACCEPT", async () => {
45
+ const { module, observer } = createChooseTestModule(ChooseViewControllerAccept);
46
+ const accept = module as ChooseViewControllerAccept;
47
+ const acceptEvent = spyEvent(observer, SUBSCRIBE_EVENTS.ACCEPT);
48
+
49
+ accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.ACCEPT]();
50
+ accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.INTERACT]();
51
+ await Promise.resolve();
52
+ await Promise.resolve();
53
+
54
+ expect(acceptEvent).toHaveBeenCalledTimes(2);
55
+ });
56
+
57
+ it("ACCEPT control emits OPTION with currentArrowVerticalItem", async () => {
58
+ const { module, observer } = createChooseTestModule(ChooseViewControllerAccept, {
59
+ state: { choose: { options: [{ index: 0, text: "A" }], args: {}, isShow: true } },
60
+ });
61
+ const option = spyEvent(observer, CHOOSE_EVENTS.OPTION);
62
+ const accept = module as ChooseViewControllerAccept;
63
+
64
+ await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, { currentArrowVerticalItem: 0 });
65
+ accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.ACCEPT]();
66
+ await Promise.resolve();
67
+
68
+ expect(option).toHaveBeenCalledExactlyOnceWith({ index: 0 });
69
+ });
70
+ });
@@ -0,0 +1,132 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { ChooseViewControllerArrows } from "../modules/controller.arrows.js";
6
+
7
+ import { CONTROLS_EVENTS, createChooseTestModule, registerChoosePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ const visibleOptions = {
10
+ choose: {
11
+ options: [
12
+ { index: 0, text: "A" },
13
+ { index: 1, text: "B" },
14
+ ],
15
+ args: {},
16
+ isShow: true,
17
+ },
18
+ };
19
+
20
+ const optionsWithHided = {
21
+ choose: {
22
+ options: [
23
+ { index: 0, text: "A", hided: true },
24
+ { index: 1, text: "B" },
25
+ { index: 2, text: "C", hided: true },
26
+ { index: 3, text: "D" },
27
+ ],
28
+ args: {},
29
+ isShow: true,
30
+ },
31
+ };
32
+
33
+ describe("ChooseViewControllerArrows", () => {
34
+ beforeEach(() => {
35
+ registerChoosePluginVne();
36
+ });
37
+
38
+ it("SHOW pushes arrow controls above the controller layer", async () => {
39
+ const { module, observer } = createChooseTestModule(ChooseViewControllerArrows, { state: visibleOptions });
40
+ const arrows = module as ChooseViewControllerArrows;
41
+ const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
42
+
43
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
44
+
45
+ expect(arrows.currentItem).toBeNull();
46
+ expect(push).toHaveBeenCalledExactlyOnceWith(
47
+ expect.objectContaining({
48
+ key: "choose_view.controller.arrows",
49
+ checkNext: true,
50
+ index: arrows.PARAMS.CHOOSE_VIEW.ZINDEX + 1,
51
+ }),
52
+ );
53
+ });
54
+
55
+ it("HIDE pops arrow controls", async () => {
56
+ const { observer } = createChooseTestModule(ChooseViewControllerArrows, { state: visibleOptions });
57
+ const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
58
+
59
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
60
+ await observer.emit(SUBSCRIBE_EVENTS.HIDE);
61
+
62
+ expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "choose_view.controller.arrows" });
63
+ });
64
+
65
+ it("first ARROW_BOTTOM selects 0 and emits UPDATE_STATE plus UPDATE_FAST", async () => {
66
+ const { module, observer } = createChooseTestModule(ChooseViewControllerArrows, { state: visibleOptions });
67
+ const arrows = module as ChooseViewControllerArrows;
68
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
69
+ const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
70
+
71
+ await arrows.incCurrentItem();
72
+
73
+ expect(arrows.currentItem).toBe(0);
74
+ expect(stateUpdate).toHaveBeenCalledExactlyOnceWith({ currentArrowVerticalItem: 0 });
75
+ expect(updateFast).toHaveBeenCalledOnce();
76
+ });
77
+
78
+ it("arrow wrap cycles items", async () => {
79
+ const { module, observer } = createChooseTestModule(ChooseViewControllerArrows, { state: visibleOptions });
80
+ const arrows = module as ChooseViewControllerArrows;
81
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
82
+
83
+ await arrows.incCurrentItem();
84
+ await arrows.incCurrentItem();
85
+ expect(arrows.currentItem).toBe(1);
86
+
87
+ await arrows.incCurrentItem();
88
+ expect(arrows.currentItem).toBe(0);
89
+ expect(stateUpdate).toHaveBeenLastCalledWith({ currentArrowVerticalItem: 0 });
90
+
91
+ await arrows.decCurrentItem();
92
+ expect(arrows.currentItem).toBe(1);
93
+ });
94
+
95
+ it("first ARROW_UP selects the last item", async () => {
96
+ const { module } = createChooseTestModule(ChooseViewControllerArrows, { state: visibleOptions });
97
+ const arrows = module as ChooseViewControllerArrows;
98
+
99
+ await arrows.decCurrentItem();
100
+
101
+ expect(arrows.currentItem).toBe(1);
102
+ });
103
+
104
+ it("skips hided options and keeps the original index", async () => {
105
+ const { module, observer } = createChooseTestModule(ChooseViewControllerArrows, { state: optionsWithHided });
106
+ const arrows = module as ChooseViewControllerArrows;
107
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
108
+
109
+ await arrows.incCurrentItem();
110
+ expect(arrows.currentItem).toBe(1);
111
+ expect(stateUpdate).toHaveBeenLastCalledWith({ currentArrowVerticalItem: 1 });
112
+
113
+ await arrows.incCurrentItem();
114
+ expect(arrows.currentItem).toBe(3);
115
+ expect(stateUpdate).toHaveBeenLastCalledWith({ currentArrowVerticalItem: 3 });
116
+
117
+ await arrows.incCurrentItem();
118
+ expect(arrows.currentItem).toBe(1);
119
+
120
+ await arrows.decCurrentItem();
121
+ expect(arrows.currentItem).toBe(3);
122
+ });
123
+
124
+ it("first ARROW_UP skips a trailing hided option", async () => {
125
+ const { module } = createChooseTestModule(ChooseViewControllerArrows, { state: optionsWithHided });
126
+ const arrows = module as ChooseViewControllerArrows;
127
+
128
+ await arrows.decCurrentItem();
129
+
130
+ expect(arrows.currentItem).toBe(3);
131
+ });
132
+ });
@@ -0,0 +1,33 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as CHOOSE_EVENTS } from "@vnejs/contracts.scenario.choose";
6
+
7
+ import { ChooseViewBridge } from "../modules/bridge.js";
8
+
9
+ import { createChooseTestModule, registerChoosePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
10
+
11
+ describe("ChooseViewBridge", () => {
12
+ beforeEach(() => {
13
+ registerChoosePluginVne();
14
+ });
15
+
16
+ it("CHOOSE.SHOW bridges to VIEW.SHOW", async () => {
17
+ const { observer } = createChooseTestModule(ChooseViewBridge);
18
+ const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
19
+
20
+ await observer.emit(CHOOSE_EVENTS.SHOW);
21
+
22
+ expect(show).toHaveBeenCalledOnce();
23
+ });
24
+
25
+ it("CHOOSE.HIDE bridges to VIEW.HIDE", async () => {
26
+ const { observer } = createChooseTestModule(ChooseViewBridge);
27
+ const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
28
+
29
+ await observer.emit(CHOOSE_EVENTS.HIDE, { isForce: true });
30
+
31
+ expect(hide).toHaveBeenCalledExactlyOnceWith({ isForce: true });
32
+ });
33
+ });
@@ -0,0 +1,40 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as CHOOSE_EVENTS } from "@vnejs/contracts.scenario.choose";
6
+
7
+ import { ChooseViewControllerAccept } from "../modules/controller.accept.js";
8
+ import { ChooseViewController } from "../modules/controller.js";
9
+
10
+ import { createChooseTestModule, registerChoosePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
11
+
12
+ describe("ChooseViewController", () => {
13
+ beforeEach(() => {
14
+ registerChoosePluginVne();
15
+ });
16
+
17
+ it("SHOW loads choose state from globalState", async () => {
18
+ const { module, observer } = createChooseTestModule(ChooseViewController, {
19
+ state: { choose: { options: [{ index: 0, text: "A" }], args: {}, isShow: true } },
20
+ });
21
+
22
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
23
+
24
+ expect((module as ChooseViewController).state.options).toHaveLength(1);
25
+ });
26
+
27
+ it("ACCEPT control emits OPTION with currentArrowVerticalItem", async () => {
28
+ const { module, observer } = createChooseTestModule(ChooseViewControllerAccept, {
29
+ state: { choose: { options: [{ index: 0, text: "A" }], args: {}, isShow: true } },
30
+ });
31
+ const option = spyEvent(observer, CHOOSE_EVENTS.OPTION);
32
+ const accept = module as ChooseViewControllerAccept;
33
+
34
+ await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, { currentArrowVerticalItem: 0 });
35
+ accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.ACCEPT]();
36
+ await Promise.resolve();
37
+
38
+ expect(option).toHaveBeenCalledExactlyOnceWith({ index: 0 });
39
+ });
40
+ });
@@ -0,0 +1,86 @@
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 type { ChooseViewControllerAccept } from "../modules/controller.accept.js";
8
+ import type { ChooseViewController } from "../modules/controller.js";
9
+
10
+ import type { Choose } from "../../../../../plugins/scenario/choose/src/modules/choose.js";
11
+ import { CHOOSE_EVENTS, createChooseIntegrationModules, SUBSCRIBE_EVENTS } from "./setup.js";
12
+
13
+ describe("Choose integration (scenario + view)", () => {
14
+ let choose: Choose;
15
+ let controller: ChooseViewController;
16
+ let accept: ChooseViewControllerAccept;
17
+ let observer: ReturnType<typeof createChooseIntegrationModules>["observer"];
18
+
19
+ beforeEach(() => {
20
+ ({ choose, controller, accept, observer } = createChooseIntegrationModules());
21
+ });
22
+
23
+ it("EMIT on CHOOSE opens UI via SHOW → VIEW.SHOW bridge", async () => {
24
+ const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
25
+
26
+ await observer.emit(CHOOSE_EVENTS.EMIT, {
27
+ options: [{ index: 0, optionLine: { line: '% choose.option "Pick me" 0 0', args: {} } }],
28
+ });
29
+
30
+ expect(choose.state.isShow).toBe(true);
31
+ expect(choose.state.options[0]?.text).toBe("Pick me");
32
+ expect(show).toHaveBeenCalledOnce();
33
+ expect(controller.state.options).toHaveLength(1);
34
+ expect(controller.state.options[0]?.text).toBe("Pick me");
35
+ });
36
+
37
+ it("OPTION on CHOOSE closes UI via HIDE → VIEW.HIDE bridge", async () => {
38
+ const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
39
+
40
+ choose.setState({ options: [{ index: 3, text: "A" }], args: {}, isShow: true });
41
+ controller.updateState({ isShow: true });
42
+
43
+ await observer.emit(CHOOSE_EVENTS.OPTION, { index: 0 });
44
+
45
+ expect(hide).toHaveBeenCalledOnce();
46
+ expect(choose.state.isShow).toBe(false);
47
+ });
48
+
49
+ it("STATE.SET with another open choice refreshes controller options", async () => {
50
+ choose.setState({ id: "choice-a", options: [{ index: 0, text: "A" }], args: {}, isShow: true });
51
+ controller.updateState({ id: "choice-a", options: [{ index: 0, text: "A" }], args: {}, isShow: true });
52
+
53
+ await observer.emit(STATE_EVENTS.SET, {
54
+ choose: { id: "choice-b", options: [{ index: 1, text: "B" }], args: {}, isShow: true },
55
+ });
56
+
57
+ expect(controller.state.options[0]?.text).toBe("B");
58
+ expect(controller.state.id).toBe("choice-b");
59
+ expect(choose.state.isShow).toBe(true);
60
+ });
61
+
62
+ it("CHOOSE.SHOW forwards isForce payload through bridge to VIEW.SHOW", async () => {
63
+ const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
64
+
65
+ choose.setState({ options: [{ index: 0, text: "A" }], args: {}, isShow: true });
66
+
67
+ await observer.emit(CHOOSE_EVENTS.SHOW, { isForce: true });
68
+
69
+ expect(show).toHaveBeenCalledExactlyOnceWith({ isForce: true });
70
+ });
71
+
72
+ it("ACCEPT on controller emits CHOOSE.OPTION and closes via bridge", async () => {
73
+ const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
74
+
75
+ choose.setState({ options: [{ index: 2, text: "B" }], args: {}, isShow: true });
76
+ controller.updateState({ isShow: true });
77
+ accept.updateState({ currentArrowVerticalItem: 0 });
78
+
79
+ accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.ACCEPT]();
80
+
81
+ await new Promise<void>((resolve) => setTimeout(resolve, 0));
82
+
83
+ expect(hide).toHaveBeenCalledOnce();
84
+ expect(choose.state.isShow).toBe(false);
85
+ });
86
+ });
@@ -0,0 +1,100 @@
1
+ import { SourcesSet } from "@vnejs/sources-set";
2
+ import {
3
+ createTestModule as baseCreateTestModule,
4
+ createTestObserver,
5
+ registerCoreVne,
6
+ registerVnePlugin,
7
+ stubEvent,
8
+ stubSilentEvent,
9
+ } from "@vnejs/test-utils";
10
+
11
+ import { PARAMS as CHOOSE_VIEW_PARAMS, PLUGIN_NAME as CHOOSE_VIEW, SUBSCRIBE_EVENTS as CHOOSE_VIEW_EVENTS } from "@vnejs/contracts.controllers.scenario.choose";
12
+ import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
13
+ import { CONSTANTS as CHOOSE_CONST, PARAMS as CHOOSE_PARAMS, PLUGIN_NAME as CHOOSE, SUBSCRIBE_EVENTS as CHOOSE_EVENTS } from "@vnejs/contracts.scenario.choose";
14
+ import { SUBSCRIBE_EVENTS as TEXT_EVENTS, PLUGIN_NAME as TEXT } from "@vnejs/contracts.text";
15
+
16
+ import { ChooseViewBridge } from "../modules/bridge.js";
17
+ import { ChooseViewControllerAccept } from "../modules/controller.accept.js";
18
+ import { ChooseViewController } from "../modules/controller.js";
19
+
20
+ import { Choose } from "../../../../../plugins/scenario/choose/src/modules/choose.js";
21
+ import { ChooseEmit } from "../../../../../plugins/scenario/choose/src/modules/emit.js";
22
+ import { ChooseOption } from "../../../../../plugins/scenario/choose/src/modules/option.js";
23
+ import { ChooseOptionText } from "../../../../../plugins/scenario/choose/src/modules/option.text.js";
24
+ import { ChooseSkip } from "../../../../../plugins/scenario/choose/src/modules/skip.js";
25
+
26
+ export const registerChoosePluginVne = () => {
27
+ registerCoreVne();
28
+ registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
29
+ registerVnePlugin(TEXT, { events: TEXT_EVENTS });
30
+ registerVnePlugin(CHOOSE, { constants: CHOOSE_CONST, events: CHOOSE_EVENTS, params: CHOOSE_PARAMS });
31
+ registerVnePlugin(CHOOSE_VIEW, { events: CHOOSE_VIEW_EVENTS, params: CHOOSE_VIEW_PARAMS });
32
+ };
33
+
34
+ export const createChooseTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
35
+ ModuleClass: T,
36
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
37
+ ) => {
38
+ const result = baseCreateTestModule(ModuleClass, {
39
+ state: {
40
+ choose: { options: [], args: {}, isShow: false },
41
+ scenario: { curLine: 0, label: "start" },
42
+ ...(options.state ?? {}),
43
+ },
44
+ shared: {
45
+ viewForceAnimationSources: new SourcesSet(),
46
+ ...(options.shared ?? {}),
47
+ },
48
+ ...options,
49
+ });
50
+
51
+ stubSilentEvent(result.observer, CHOOSE_VIEW_EVENTS.SHOW);
52
+ stubSilentEvent(result.observer, CHOOSE_VIEW_EVENTS.HIDE);
53
+ stubSilentEvent(result.observer, CHOOSE_VIEW_EVENTS.UPDATE);
54
+ stubSilentEvent(result.observer, CHOOSE_VIEW_EVENTS.UPDATE_STATE);
55
+ stubSilentEvent(result.observer, CHOOSE_VIEW_EVENTS.UPDATE_FAST);
56
+ stubSilentEvent(result.observer, CONTROLS_EVENTS.PUSH);
57
+ stubSilentEvent(result.observer, CONTROLS_EVENTS.POP);
58
+
59
+ return result;
60
+ };
61
+
62
+ export { CHOOSE_VIEW_EVENTS as SUBSCRIBE_EVENTS, CHOOSE_EVENTS, CONTROLS_EVENTS };
63
+
64
+ export const createChooseIntegrationModules = () => {
65
+ registerChoosePluginVne();
66
+
67
+ const observer = createTestObserver();
68
+ const state = {
69
+ choose: { options: [], args: {}, isShow: false },
70
+ scenario: { curLine: 0, label: "start" },
71
+ };
72
+ const shared = { viewForceAnimationSources: new SourcesSet() };
73
+
74
+ stubEvent(observer, TEXT_EVENTS.REPLACE, ({ text }) => text);
75
+ stubEvent(observer, CHOOSE_EVENTS.OPTION_REPLACE, ({ index }) => index);
76
+ stubSilentEvent(observer, CHOOSE_VIEW_EVENTS.UPDATE);
77
+ stubSilentEvent(observer, CHOOSE_VIEW_EVENTS.UPDATE_STATE);
78
+ stubSilentEvent(observer, CHOOSE_VIEW_EVENTS.UPDATE_FAST);
79
+ stubSilentEvent(observer, CHOOSE_VIEW_EVENTS.ACCEPT);
80
+ stubSilentEvent(observer, CONTROLS_EVENTS.PUSH);
81
+ stubSilentEvent(observer, CONTROLS_EVENTS.POP);
82
+
83
+ const attach = <T extends new () => InstanceType<T>>(ModuleClass: T) => {
84
+ const module = new ModuleClass();
85
+ module.inject({ observer, state, shared, media: {} });
86
+ module.subscribe();
87
+ return module;
88
+ };
89
+
90
+ const choose = attach(Choose);
91
+ attach(ChooseEmit);
92
+ attach(ChooseOptionText);
93
+ attach(ChooseOption);
94
+ attach(ChooseSkip);
95
+ attach(ChooseViewBridge);
96
+ const controller = attach(ChooseViewController);
97
+ const accept = attach(ChooseViewControllerAccept);
98
+
99
+ return { observer, state, choose, controller, accept };
100
+ };
package/src/types.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+
3
+ import type { PluginName, SubscribeEvents, Params } from "@vnejs/contracts.controllers.scenario.choose";
4
+ import type { PluginName as ControlsPluginName, Constants as ControlsConstants } from "@vnejs/contracts.controls";
5
+ import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
6
+ import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
7
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
8
+ import type { PluginName as VendorsPluginName, SubscribeEvents as VendorsSubscribeEvents } from "@vnejs/contracts.core.vendors";
9
+ import type { PluginName as ChoosePluginName, SubscribeEvents as ChooseSubscribeEvents, Params as ChooseParams } from "@vnejs/contracts.scenario.choose";
10
+ import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
11
+
12
+ export type ChoosePluginEvents = ModuleComponentsEvents &
13
+ Record<ChoosePluginName, ChooseSubscribeEvents> &
14
+ Record<PluginName, SubscribeEvents> &
15
+ Record<ScenarioPluginName, ScenarioSubscribeEvents> &
16
+ Record<StatePluginName, StateSubscribeEvents> &
17
+ Record<VendorsPluginName, VendorsSubscribeEvents> &
18
+ Record<LogsPluginName, LogsSubscribeEvents> &
19
+ Record<TextPluginName, TextSubscribeEvents>;
20
+
21
+ export type ChoosePluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
22
+
23
+ export type ChoosePluginSettings = ModuleComponentsSettings;
24
+
25
+ export type ChoosePluginParams = ModuleComponentsParams & Record<ChoosePluginName, ChooseParams> & Record<PluginName, Params>;
@@ -0,0 +1,11 @@
1
+ import type { ModuleControllerState } from "@vnejs/module.components";
2
+
3
+ import type { ChooseOption, ChoosePluginModelState } from "@vnejs/contracts.controllers.scenario.choose";
4
+
5
+ export type ChoosePluginControllerState = ModuleControllerState &
6
+ ChoosePluginModelState & {
7
+ currentItem?: number | null;
8
+ currentArrowVerticalItem?: number | null;
9
+ };
10
+
11
+ export type ChooseViewOption = ChooseOption;
@@ -0,0 +1,117 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+
3
+ import { Flex, PositionBox, Screen, Text, TextControls, createRenderFunc, useIsForceHook, useStoreState } from "@vnejs/uis.react";
4
+
5
+ import type { ReactComponentProps } from "@vnejs/uis.react";
6
+
7
+ import type { ChooseOption } from "@vnejs/contracts.controllers.scenario.choose";
8
+
9
+ import type { ChoosePluginControllerState } from "../utils/choose.js";
10
+
11
+ import type { ChoosePluginConstants, ChoosePluginEvents, ChoosePluginParams, ChoosePluginSettings } from "../types.js";
12
+
13
+ type ChooseComponentProps = ReactComponentProps<
14
+ ChoosePluginEvents,
15
+ ChoosePluginConstants,
16
+ ChoosePluginSettings,
17
+ ChoosePluginParams,
18
+ ChoosePluginControllerState
19
+ >;
20
+
21
+ type OptionWithCoordsProps = {
22
+ text?: string;
23
+ isDisabled?: boolean;
24
+ isNotRender?: boolean;
25
+ value?: number;
26
+ coords?: number[];
27
+ props: ChooseComponentProps;
28
+ currentItem?: number | null;
29
+ onClick: (value?: unknown) => void;
30
+ };
31
+
32
+ const renderOptionWithCoords = ({ text, isDisabled, isNotRender, value, coords, props, currentItem, onClick }: OptionWithCoordsProps) => {
33
+ const [x = 0, y = 0] = coords ?? [];
34
+ const positionProps = { left: `${x}%`, top: `${y}%`, translateX: "-50%", translateY: "-50%", isNotRender };
35
+ const propsText = {
36
+ ...props.PARAMS.CHOOSE_VIEW.VIEW_PROPS.text,
37
+ isDisabled,
38
+ isHoverable: !isDisabled,
39
+ onClick,
40
+ text,
41
+ value,
42
+ isSelected: currentItem === value,
43
+ };
44
+
45
+ return (
46
+ <PositionBox
47
+ {...positionProps}
48
+ key={value}
49
+ >
50
+ <Text {...propsText} />
51
+ </PositionBox>
52
+ );
53
+ };
54
+
55
+ const Choose = ({ store, onMount, emit, EVENTS, PARAMS }: ChooseComponentProps) => {
56
+ const {
57
+ isShow = false,
58
+ isForce = false,
59
+ options = [],
60
+ args = {},
61
+ currentArrowVerticalItem: currentItem = null,
62
+ } = useStoreState<ChoosePluginControllerState>(store, onMount);
63
+
64
+ const onClick = (value?: unknown) => void emit(EVENTS.CHOOSE.OPTION, { index: Number(value) });
65
+
66
+ const isRealForce = useIsForceHook(isForce);
67
+
68
+ const title = typeof args.title === "string" ? args.title : null;
69
+
70
+ const optionsMapped = options.map(({ text, hided, coords, disabled }: ChooseOption, i: number) => ({
71
+ text,
72
+ i,
73
+ coords,
74
+ isNotRender: Boolean(hided),
75
+ isDisabled: Boolean(disabled),
76
+ }));
77
+ const textsInfo = optionsMapped.map(({ i, ...obj }) => ({ value: i, isSelected: currentItem === i, ...obj }));
78
+ const optionsRegular = textsInfo.filter((e) => !e.coords);
79
+ const optionsWithCoords = textsInfo.filter((e) => e.coords);
80
+
81
+ const propsView = PARAMS.CHOOSE_VIEW.VIEW_PROPS;
82
+
83
+ return (
84
+ <Screen
85
+ {...propsView.screen}
86
+ isDisableAutoread={true}
87
+ isIgnoreOnScreenshot={false}
88
+ isShow={isShow}
89
+ isForce={isRealForce}
90
+ >
91
+ {optionsWithCoords.map((option) =>
92
+ renderOptionWithCoords({ ...option, currentItem, onClick, props: { store, onMount, emit, EVENTS, PARAMS } as ChooseComponentProps }),
93
+ )}
94
+ <PositionBox {...propsView.position}>
95
+ <Flex
96
+ direction={propsView.wrap.flexDirection}
97
+ gap={propsView.wrap.flexGap}
98
+ align={propsView.wrap.flexAlign}
99
+ >
100
+ {title ? (
101
+ <Text
102
+ {...propsView.title}
103
+ text={title}
104
+ />
105
+ ) : null}
106
+ <TextControls
107
+ {...propsView.controls}
108
+ texts={optionsRegular}
109
+ onClick={onClick}
110
+ />
111
+ </Flex>
112
+ </PositionBox>
113
+ </Screen>
114
+ );
115
+ };
116
+
117
+ export const render: ViewRenderFunc<ChoosePluginControllerState> = createRenderFunc(Choose);
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.