@vnejs/plugins.controllers.screens.disclaimer 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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -0
- package/dist/modules/controller.accept.d.ts +11 -0
- package/dist/modules/controller.accept.js +13 -0
- package/dist/modules/controller.d.ts +15 -0
- package/dist/modules/controller.js +15 -0
- package/dist/modules/disclaimer.d.ts +8 -0
- package/dist/modules/disclaimer.js +13 -0
- package/dist/modules/view.d.ts +10 -0
- package/dist/modules/view.js +9 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.js +1 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +15 -0
- package/package.json +57 -4
- package/src/index.ts +17 -0
- package/src/modules/controller.accept.ts +25 -0
- package/src/modules/controller.ts +30 -0
- package/src/modules/disclaimer.ts +25 -0
- package/src/modules/view.ts +23 -0
- package/src/tests/accept.test.ts +67 -0
- package/src/tests/disclaimer.test.ts +34 -0
- package/src/tests/setup.ts +31 -0
- package/src/types.ts +33 -0
- package/src/view/index.tsx +62 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.screens.disclaimer";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.screens.disclaimer";
|
|
2
|
+
import { regPlugin } from "@vnejs/registry";
|
|
3
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.disclaimer";
|
|
4
|
+
import { DisclaimerControllerAccept } from "./modules/controller.accept.js";
|
|
5
|
+
import { DisclaimerController } from "./modules/controller.js";
|
|
6
|
+
import { Disclaimer } from "./modules/disclaimer.js";
|
|
7
|
+
import { DisclaimerView } from "./modules/view.js";
|
|
8
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
9
|
+
DisclaimerController,
|
|
10
|
+
DisclaimerControllerAccept,
|
|
11
|
+
Disclaimer,
|
|
12
|
+
DisclaimerView,
|
|
13
|
+
]);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
|
|
3
|
+
import type { DisclaimerPluginState } from "../types.js";
|
|
4
|
+
export declare class DisclaimerControllerAccept extends ModuleControllerAccept<DisclaimerPluginEvents, DisclaimerPluginConstants, DisclaimerPluginSettings, DisclaimerPluginParams, DisclaimerPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
EVENT_SHOW: "vne:disclaimer:show";
|
|
7
|
+
EVENT_HIDE: "vne:disclaimer:hide";
|
|
8
|
+
EVENT_ACCEPT: "vne:disclaimer:accept";
|
|
9
|
+
CONTROLS_ZINDEX: number;
|
|
10
|
+
onAccept: () => Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
export class DisclaimerControllerAccept extends ModuleControllerAccept {
|
|
3
|
+
name = "disclaimer.controller.accept";
|
|
4
|
+
EVENT_SHOW = this.EVENTS.DISCLAIMER.SHOW;
|
|
5
|
+
EVENT_HIDE = this.EVENTS.DISCLAIMER.HIDE;
|
|
6
|
+
EVENT_ACCEPT = this.EVENTS.DISCLAIMER.ACCEPT;
|
|
7
|
+
CONTROLS_ZINDEX = this.PARAMS.DISCLAIMER.ZINDEX;
|
|
8
|
+
onAccept = async () => {
|
|
9
|
+
this.emit(this.EVENTS.LOGS.EMIT, { action: this.CONST.DISCLAIMER.LOGS_ACTIONS.ACCEPT });
|
|
10
|
+
await this.emit(this.EVENTS.DISCLAIMER.HIDE);
|
|
11
|
+
this.emit(this.EVENTS.SCENARIO.NEXT);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
|
|
3
|
+
import type { DisclaimerPluginState } from "../types.js";
|
|
4
|
+
export declare class DisclaimerController extends ModuleController<DisclaimerPluginEvents, DisclaimerPluginConstants, DisclaimerPluginSettings, DisclaimerPluginParams, DisclaimerPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
EVENT_UPDATE_VIEW: "vne:disclaimer:update";
|
|
7
|
+
EVENT_UPDATE_STATE: "vne:disclaimer:update_state";
|
|
8
|
+
EVENT_UPDATE_FAST: "vne:disclaimer:update_fast";
|
|
9
|
+
EVENT_UPDATE_FORCE: "vne:disclaimer:update_force";
|
|
10
|
+
EVENT_SHOW: "vne:disclaimer:show";
|
|
11
|
+
EVENT_HIDE: "vne:disclaimer:hide";
|
|
12
|
+
CONTROLS: {};
|
|
13
|
+
CONTROLS_INDEX: number;
|
|
14
|
+
onShowBefore: (args?: {}) => void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
export class DisclaimerController extends ModuleController {
|
|
3
|
+
name = "disclaimer.controller";
|
|
4
|
+
EVENT_UPDATE_VIEW = this.EVENTS.DISCLAIMER.UPDATE;
|
|
5
|
+
EVENT_UPDATE_STATE = this.EVENTS.DISCLAIMER.UPDATE_STATE;
|
|
6
|
+
EVENT_UPDATE_FAST = this.EVENTS.DISCLAIMER.UPDATE_FAST;
|
|
7
|
+
EVENT_UPDATE_FORCE = this.EVENTS.DISCLAIMER.UPDATE_FORCE;
|
|
8
|
+
EVENT_SHOW = this.EVENTS.DISCLAIMER.SHOW;
|
|
9
|
+
EVENT_HIDE = this.EVENTS.DISCLAIMER.HIDE;
|
|
10
|
+
CONTROLS = {};
|
|
11
|
+
CONTROLS_INDEX = this.PARAMS.DISCLAIMER.ZINDEX;
|
|
12
|
+
onShowBefore = (args = {}) => {
|
|
13
|
+
return this.updateState(args);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
3
|
+
import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
|
|
4
|
+
export declare class Disclaimer extends ModuleCore<DisclaimerPluginEvents, DisclaimerPluginConstants, DisclaimerPluginSettings, DisclaimerPluginParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
init: () => Promise<import("@vnejs/registry").EmitResults<"vne:scenario:line_exec_reg">> | undefined;
|
|
7
|
+
onLineExec: ({ line }?: LineExecHandlerArg) => Promise<import("@vnejs/registry").EmitResults<"vne:disclaimer:show">> | undefined;
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
3
|
+
export class Disclaimer extends ModuleCore {
|
|
4
|
+
name = "disclaimer";
|
|
5
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
|
|
6
|
+
onLineExec = ({ line = "" } = {}) => {
|
|
7
|
+
const [action = "", id = ""] = tokenizeExecLine(line).map(String);
|
|
8
|
+
if (action !== this.CONST.DISCLAIMER.EXEC_ACTIONS.SHOW)
|
|
9
|
+
return;
|
|
10
|
+
this.emit(this.EVENTS.LOGS.EMIT, { action: this.CONST.DISCLAIMER.LOGS_ACTIONS.SHOW, id });
|
|
11
|
+
return this.emit(this.EVENTS.DISCLAIMER.SHOW, { id });
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
|
|
3
|
+
import type { DisclaimerPluginState } from "../types.js";
|
|
4
|
+
export declare class DisclaimerView extends ModuleView<DisclaimerPluginEvents, DisclaimerPluginConstants, DisclaimerPluginSettings, DisclaimerPluginParams, DisclaimerPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
EVENT_UPDATE_VIEW: "vne:disclaimer:update";
|
|
7
|
+
LOC_LABEL: string;
|
|
8
|
+
TRANSITION: number;
|
|
9
|
+
renderFunc: import("@vnejs/module.components").ViewRenderFunc<DisclaimerPluginState>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import { render } from "../view/index.js";
|
|
3
|
+
export class DisclaimerView extends ModuleView {
|
|
4
|
+
name = "disclaimer.view";
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.DISCLAIMER.UPDATE;
|
|
6
|
+
LOC_LABEL = this.PARAMS.DISCLAIMER.LOC_LABEL;
|
|
7
|
+
TRANSITION = this.PARAMS.DISCLAIMER.TRANSITION;
|
|
8
|
+
renderFunc = render;
|
|
9
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.screens.disclaimer";
|
|
3
|
+
import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
|
|
4
|
+
import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
|
|
5
|
+
import type { Constants as ScenarioConstants, PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
|
|
6
|
+
import type { PluginName as LocsPluginName, SubscribeEvents as LocsSubscribeEvents } from "@vnejs/contracts.text.locs";
|
|
7
|
+
export type DisclaimerPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<LogsPluginName, LogsSubscribeEvents> & Record<LocsPluginName, LocsSubscribeEvents>;
|
|
8
|
+
export type DisclaimerPluginConstants = ModuleComponentsConstants & Record<PluginName, Constants> & Record<ControlsPluginName, ControlsConstants> & Record<ScenarioPluginName, ScenarioConstants>;
|
|
9
|
+
export type DisclaimerPluginSettings = ModuleComponentsSettings;
|
|
10
|
+
export type DisclaimerPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
|
11
|
+
export type DisclaimerPluginState = {
|
|
12
|
+
isShow: boolean;
|
|
13
|
+
isForce: boolean;
|
|
14
|
+
id?: string;
|
|
15
|
+
locs?: Record<string, string>;
|
|
16
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
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, useStoreState } from "@vnejs/uis.react";
|
|
4
|
+
const renderTextLine = ({ text, props }, i) => (_createElement(Text, { ...props, text: text, key: i }));
|
|
5
|
+
const DisclaimerScreen = ({ store, onMount, PARAMS, emit, EVENTS }) => {
|
|
6
|
+
const { isShow = false, isForce = false, id = "", locs = {} } = useStoreState(store, onMount);
|
|
7
|
+
const title = locs[`${id}.title`] || "";
|
|
8
|
+
const body = locs[`${id}.text`] || "";
|
|
9
|
+
const accept = locs.accept || "";
|
|
10
|
+
const propsByView = PARAMS.DISCLAIMER.VIEW_PROPS;
|
|
11
|
+
const bodyLines = body.split("\n").map((text) => ({ text, props: propsByView.text }));
|
|
12
|
+
const buttonTexts = accept ? [{ text: accept, value: true }] : [];
|
|
13
|
+
return (_jsx(Screen, { ...propsByView.screen, isShow: isShow, isForce: isForce, children: _jsx(PositionBox, { ...propsByView.position, children: _jsxs(Flex, { ...propsByView.flex, children: [_jsxs(Flex, { ...propsByView.flexTexts, children: [_jsx(Text, { ...propsByView.title, text: title }), bodyLines.map(renderTextLine)] }), _jsx(TextControls, { ...propsByView.controls, texts: buttonTexts, onClick: () => void emit(EVENTS.DISCLAIMER.ACCEPT) })] }) }) }));
|
|
14
|
+
};
|
|
15
|
+
export const render = createRenderFunc(DisclaimerScreen);
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.controllers.screens.disclaimer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
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.disclaimer": "~0.2.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/helpers": "~0.2.0",
|
|
37
|
+
"@vnejs/module.core": "~0.2.0",
|
|
38
|
+
"@vnejs/module.components": "~0.2.0",
|
|
39
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
40
|
+
"@vnejs/contracts.controls": "~0.2.0",
|
|
41
|
+
"@vnejs/contracts.text.locs": "~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.text.locs": "~0.2.0",
|
|
51
|
+
"@vnejs/contracts.controllers.screens.disclaimer": "~0.2.0",
|
|
52
|
+
"@vnejs/helpers": "~0.2.0",
|
|
53
|
+
"@vnejs/module.core": "~0.2.0",
|
|
54
|
+
"@vnejs/module.components": "~0.2.0",
|
|
55
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
56
|
+
"@vnejs/registry": "~0.2.0",
|
|
57
|
+
"@vnejs/uis.react": "~0.2.0"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.screens.disclaimer";
|
|
2
|
+
|
|
3
|
+
import { regPlugin } from "@vnejs/registry";
|
|
4
|
+
|
|
5
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.disclaimer";
|
|
6
|
+
|
|
7
|
+
import { DisclaimerControllerAccept } from "./modules/controller.accept.js";
|
|
8
|
+
import { DisclaimerController } from "./modules/controller.js";
|
|
9
|
+
import { Disclaimer } from "./modules/disclaimer.js";
|
|
10
|
+
import { DisclaimerView } from "./modules/view.js";
|
|
11
|
+
|
|
12
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
13
|
+
DisclaimerController,
|
|
14
|
+
DisclaimerControllerAccept,
|
|
15
|
+
Disclaimer,
|
|
16
|
+
DisclaimerView,
|
|
17
|
+
]);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
|
|
3
|
+
import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
|
|
4
|
+
import type { DisclaimerPluginState } from "../types.js";
|
|
5
|
+
export class DisclaimerControllerAccept extends ModuleControllerAccept<
|
|
6
|
+
DisclaimerPluginEvents,
|
|
7
|
+
DisclaimerPluginConstants,
|
|
8
|
+
DisclaimerPluginSettings,
|
|
9
|
+
DisclaimerPluginParams,
|
|
10
|
+
DisclaimerPluginState
|
|
11
|
+
> {
|
|
12
|
+
name = "disclaimer.controller.accept";
|
|
13
|
+
|
|
14
|
+
EVENT_SHOW = this.EVENTS.DISCLAIMER.SHOW;
|
|
15
|
+
EVENT_HIDE = this.EVENTS.DISCLAIMER.HIDE;
|
|
16
|
+
EVENT_ACCEPT = this.EVENTS.DISCLAIMER.ACCEPT;
|
|
17
|
+
|
|
18
|
+
CONTROLS_ZINDEX = this.PARAMS.DISCLAIMER.ZINDEX;
|
|
19
|
+
|
|
20
|
+
onAccept = async () => {
|
|
21
|
+
this.emit(this.EVENTS.LOGS.EMIT, { action: this.CONST.DISCLAIMER.LOGS_ACTIONS.ACCEPT });
|
|
22
|
+
await this.emit(this.EVENTS.DISCLAIMER.HIDE);
|
|
23
|
+
this.emit(this.EVENTS.SCENARIO.NEXT);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { DisclaimerShowPayload } from "@vnejs/contracts.controllers.screens.disclaimer";
|
|
4
|
+
|
|
5
|
+
import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
|
|
6
|
+
import type { DisclaimerPluginState } from "../types.js";
|
|
7
|
+
|
|
8
|
+
export class DisclaimerController extends ModuleController<
|
|
9
|
+
DisclaimerPluginEvents,
|
|
10
|
+
DisclaimerPluginConstants,
|
|
11
|
+
DisclaimerPluginSettings,
|
|
12
|
+
DisclaimerPluginParams,
|
|
13
|
+
DisclaimerPluginState
|
|
14
|
+
> {
|
|
15
|
+
name = "disclaimer.controller";
|
|
16
|
+
|
|
17
|
+
EVENT_UPDATE_VIEW = this.EVENTS.DISCLAIMER.UPDATE;
|
|
18
|
+
EVENT_UPDATE_STATE = this.EVENTS.DISCLAIMER.UPDATE_STATE;
|
|
19
|
+
EVENT_UPDATE_FAST = this.EVENTS.DISCLAIMER.UPDATE_FAST;
|
|
20
|
+
EVENT_UPDATE_FORCE = this.EVENTS.DISCLAIMER.UPDATE_FORCE;
|
|
21
|
+
EVENT_SHOW = this.EVENTS.DISCLAIMER.SHOW;
|
|
22
|
+
EVENT_HIDE = this.EVENTS.DISCLAIMER.HIDE;
|
|
23
|
+
|
|
24
|
+
CONTROLS = {};
|
|
25
|
+
CONTROLS_INDEX = this.PARAMS.DISCLAIMER.ZINDEX;
|
|
26
|
+
|
|
27
|
+
onShowBefore = (args = {}) => {
|
|
28
|
+
return this.updateState(args as DisclaimerShowPayload);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
4
|
+
|
|
5
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
6
|
+
|
|
7
|
+
import type { DisclaimerShowPayload } from "@vnejs/contracts.controllers.screens.disclaimer";
|
|
8
|
+
|
|
9
|
+
import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
|
|
10
|
+
|
|
11
|
+
export class Disclaimer extends ModuleCore<DisclaimerPluginEvents, DisclaimerPluginConstants, DisclaimerPluginSettings, DisclaimerPluginParams> {
|
|
12
|
+
name = "disclaimer";
|
|
13
|
+
|
|
14
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
|
|
15
|
+
|
|
16
|
+
onLineExec = ({ line = "" }: LineExecHandlerArg = {}) => {
|
|
17
|
+
const [action = "", id = ""] = tokenizeExecLine(line).map(String);
|
|
18
|
+
|
|
19
|
+
if (action !== this.CONST.DISCLAIMER.EXEC_ACTIONS.SHOW) return;
|
|
20
|
+
|
|
21
|
+
this.emit(this.EVENTS.LOGS.EMIT, { action: this.CONST.DISCLAIMER.LOGS_ACTIONS.SHOW, id });
|
|
22
|
+
|
|
23
|
+
return this.emit(this.EVENTS.DISCLAIMER.SHOW, { id } satisfies DisclaimerShowPayload);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
|
|
4
|
+
import type { DisclaimerPluginState } from "../types.js";
|
|
5
|
+
|
|
6
|
+
import { render } from "../view/index.js";
|
|
7
|
+
export class DisclaimerView extends ModuleView<
|
|
8
|
+
DisclaimerPluginEvents,
|
|
9
|
+
DisclaimerPluginConstants,
|
|
10
|
+
DisclaimerPluginSettings,
|
|
11
|
+
DisclaimerPluginParams,
|
|
12
|
+
DisclaimerPluginState
|
|
13
|
+
> {
|
|
14
|
+
name = "disclaimer.view";
|
|
15
|
+
|
|
16
|
+
EVENT_UPDATE_VIEW = this.EVENTS.DISCLAIMER.UPDATE;
|
|
17
|
+
|
|
18
|
+
LOC_LABEL = this.PARAMS.DISCLAIMER.LOC_LABEL;
|
|
19
|
+
|
|
20
|
+
TRANSITION = this.PARAMS.DISCLAIMER.TRANSITION;
|
|
21
|
+
|
|
22
|
+
renderFunc = render;
|
|
23
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { DisclaimerControllerAccept } from "../modules/controller.accept.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, createDisclaimerTestModule, registerDisclaimerPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("DisclaimerControllerAccept", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerDisclaimerPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("SHOW pushes ACCEPT and INTERACT controls", async () => {
|
|
15
|
+
const { module, observer } = createDisclaimerTestModule(DisclaimerControllerAccept);
|
|
16
|
+
const accept = module as DisclaimerControllerAccept;
|
|
17
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
18
|
+
|
|
19
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
20
|
+
|
|
21
|
+
expect(push).toHaveBeenCalledExactlyOnceWith(
|
|
22
|
+
expect.objectContaining({
|
|
23
|
+
key: "disclaimer.controller.accept",
|
|
24
|
+
checkNext: true,
|
|
25
|
+
index: accept.PARAMS.DISCLAIMER.ZINDEX + 1,
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.ACCEPT);
|
|
29
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.INTERACT);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("HIDE pops ACCEPT controls", async () => {
|
|
33
|
+
const { observer } = createDisclaimerTestModule(DisclaimerControllerAccept);
|
|
34
|
+
const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
|
|
35
|
+
|
|
36
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
37
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
38
|
+
|
|
39
|
+
expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "disclaimer.controller.accept" });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("ACCEPT and INTERACT emit DISCLAIMER.ACCEPT", async () => {
|
|
43
|
+
const { module, observer } = createDisclaimerTestModule(DisclaimerControllerAccept);
|
|
44
|
+
const accept = module as DisclaimerControllerAccept;
|
|
45
|
+
const acceptEvent = spyEvent(observer, SUBSCRIBE_EVENTS.ACCEPT);
|
|
46
|
+
|
|
47
|
+
accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.ACCEPT]();
|
|
48
|
+
accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.INTERACT]();
|
|
49
|
+
await Promise.resolve();
|
|
50
|
+
await Promise.resolve();
|
|
51
|
+
|
|
52
|
+
expect(acceptEvent).toHaveBeenCalledTimes(2);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("ACCEPT hides and emits next", async () => {
|
|
56
|
+
const { observer } = createDisclaimerTestModule(DisclaimerControllerAccept);
|
|
57
|
+
const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
|
|
58
|
+
const next = vi.fn();
|
|
59
|
+
|
|
60
|
+
observer.subscribe("vne:scenario:next", next);
|
|
61
|
+
|
|
62
|
+
await observer.emit(SUBSCRIBE_EVENTS.ACCEPT);
|
|
63
|
+
|
|
64
|
+
expect(hide).toHaveBeenCalledOnce();
|
|
65
|
+
expect(next).toHaveBeenCalledOnce();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { Disclaimer } from "../modules/disclaimer.js";
|
|
6
|
+
|
|
7
|
+
import { createDisclaimerTestModule, registerDisclaimerPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("Disclaimer", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerDisclaimerPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("line exec show emits SHOW with id", async () => {
|
|
15
|
+
const { module, observer } = createDisclaimerTestModule(Disclaimer, { subscribe: false });
|
|
16
|
+
const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
|
|
17
|
+
|
|
18
|
+
await (module as Disclaimer).init();
|
|
19
|
+
await (module as Disclaimer).onLineExec({ line: "show setting" });
|
|
20
|
+
|
|
21
|
+
expect(show).toHaveBeenCalledOnce();
|
|
22
|
+
expect(show).toHaveBeenCalledWith({ id: "setting" });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("line exec ignores unknown action", async () => {
|
|
26
|
+
const { module, observer } = createDisclaimerTestModule(Disclaimer, { subscribe: false });
|
|
27
|
+
const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
|
|
28
|
+
|
|
29
|
+
await (module as Disclaimer).init();
|
|
30
|
+
await (module as Disclaimer).onLineExec({ line: "setting" });
|
|
31
|
+
|
|
32
|
+
expect(show).not.toHaveBeenCalled();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubSilentEvent } from "@vnejs/test-utils";
|
|
2
|
+
|
|
3
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.disclaimer";
|
|
4
|
+
import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
|
|
5
|
+
|
|
6
|
+
export const registerDisclaimerPluginVne = () => {
|
|
7
|
+
registerCoreVne();
|
|
8
|
+
registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
|
|
9
|
+
registerVnePlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const createDisclaimerTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
13
|
+
ModuleClass: T,
|
|
14
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
15
|
+
) => {
|
|
16
|
+
const result = baseCreateTestModule(ModuleClass, {
|
|
17
|
+
state: {
|
|
18
|
+
disclaimer: { isShow: false, id: "" },
|
|
19
|
+
...(options.state ?? {}),
|
|
20
|
+
},
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW);
|
|
25
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.HIDE);
|
|
26
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE);
|
|
27
|
+
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, CONTROLS_EVENTS };
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.screens.disclaimer";
|
|
4
|
+
import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
|
|
5
|
+
import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
|
|
6
|
+
import type {
|
|
7
|
+
Constants as ScenarioConstants,
|
|
8
|
+
PluginName as ScenarioPluginName,
|
|
9
|
+
SubscribeEvents as ScenarioSubscribeEvents,
|
|
10
|
+
} from "@vnejs/contracts.core.scenario";
|
|
11
|
+
import type { PluginName as LocsPluginName, SubscribeEvents as LocsSubscribeEvents } from "@vnejs/contracts.text.locs";
|
|
12
|
+
|
|
13
|
+
export type DisclaimerPluginEvents = ModuleComponentsEvents &
|
|
14
|
+
Record<PluginName, SubscribeEvents> &
|
|
15
|
+
Record<ScenarioPluginName, ScenarioSubscribeEvents> &
|
|
16
|
+
Record<LogsPluginName, LogsSubscribeEvents> &
|
|
17
|
+
Record<LocsPluginName, LocsSubscribeEvents>;
|
|
18
|
+
|
|
19
|
+
export type DisclaimerPluginConstants = ModuleComponentsConstants &
|
|
20
|
+
Record<PluginName, Constants> &
|
|
21
|
+
Record<ControlsPluginName, ControlsConstants> &
|
|
22
|
+
Record<ScenarioPluginName, ScenarioConstants>;
|
|
23
|
+
|
|
24
|
+
export type DisclaimerPluginSettings = ModuleComponentsSettings;
|
|
25
|
+
|
|
26
|
+
export type DisclaimerPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
|
27
|
+
|
|
28
|
+
export type DisclaimerPluginState = {
|
|
29
|
+
isShow: boolean;
|
|
30
|
+
isForce: boolean;
|
|
31
|
+
id?: string;
|
|
32
|
+
locs?: Record<string, string>;
|
|
33
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
|
|
8
|
+
import type { DisclaimerPluginState } from "../types.js";
|
|
9
|
+
type DisclaimerComponentProps = ReactComponentProps<
|
|
10
|
+
DisclaimerPluginEvents,
|
|
11
|
+
DisclaimerPluginConstants,
|
|
12
|
+
DisclaimerPluginSettings,
|
|
13
|
+
DisclaimerPluginParams,
|
|
14
|
+
DisclaimerPluginState
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
const renderTextLine = ({ text, props }: { text: string; props: Record<string, unknown> }, i: number) => (
|
|
18
|
+
<Text
|
|
19
|
+
{...props}
|
|
20
|
+
text={text}
|
|
21
|
+
key={i}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const DisclaimerScreen = ({ store, onMount, PARAMS, emit, EVENTS }: DisclaimerComponentProps) => {
|
|
26
|
+
const { isShow = false, isForce = false, id = "", locs = {} } = useStoreState<DisclaimerPluginState>(store, onMount);
|
|
27
|
+
|
|
28
|
+
const title = locs[`${id}.title`] || "";
|
|
29
|
+
const body = locs[`${id}.text`] || "";
|
|
30
|
+
const accept = locs.accept || "";
|
|
31
|
+
|
|
32
|
+
const propsByView = PARAMS.DISCLAIMER.VIEW_PROPS;
|
|
33
|
+
const bodyLines = body.split("\n").map((text) => ({ text, props: propsByView.text }));
|
|
34
|
+
const buttonTexts = accept ? [{ text: accept, value: true }] : [];
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Screen
|
|
38
|
+
{...propsByView.screen}
|
|
39
|
+
isShow={isShow}
|
|
40
|
+
isForce={isForce}
|
|
41
|
+
>
|
|
42
|
+
<PositionBox {...propsByView.position}>
|
|
43
|
+
<Flex {...propsByView.flex}>
|
|
44
|
+
<Flex {...propsByView.flexTexts}>
|
|
45
|
+
<Text
|
|
46
|
+
{...propsByView.title}
|
|
47
|
+
text={title}
|
|
48
|
+
/>
|
|
49
|
+
{bodyLines.map(renderTextLine)}
|
|
50
|
+
</Flex>
|
|
51
|
+
<TextControls
|
|
52
|
+
{...propsByView.controls}
|
|
53
|
+
texts={buttonTexts}
|
|
54
|
+
onClick={() => void emit(EVENTS.DISCLAIMER.ACCEPT)}
|
|
55
|
+
/>
|
|
56
|
+
</Flex>
|
|
57
|
+
</PositionBox>
|
|
58
|
+
</Screen>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const render: ViewRenderFunc<DisclaimerPluginState> = createRenderFunc(DisclaimerScreen);
|
package/tsconfig.json
ADDED
package/README.md
DELETED