@vnejs/plugins.views.screens.disclaimer 0.2.1

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.views.screens.disclaimer";
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import "@vnejs/contracts.views.screens.disclaimer";
2
+ import { regPlugin } from "@vnejs/shared";
3
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.screens.disclaimer";
4
+ import { DisclaimerController } from "./modules/controller.js";
5
+ import { Disclaimer } from "./modules/disclaimer.js";
6
+ import { DisclaimerView } from "./modules/view.js";
7
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [DisclaimerController, Disclaimer, DisclaimerView]);
@@ -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 "../utils/disclaimer.js";
4
+ export declare class DisclaimerController extends ModuleController<DisclaimerPluginEvents, DisclaimerPluginConstants, DisclaimerPluginSettings, DisclaimerPluginParams, DisclaimerPluginState> {
5
+ name: string;
6
+ emitAccept: () => undefined;
7
+ updateEvent: "vne:disclaimer:update";
8
+ controls: {
9
+ abstract_accept: () => undefined;
10
+ abstract_interact: () => undefined;
11
+ };
12
+ controlsIndex: number;
13
+ subscribe: () => void;
14
+ beforeShow: (args?: {}) => void;
15
+ }
@@ -0,0 +1,16 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ export class DisclaimerController extends ModuleController {
3
+ name = "disclaimer.controller";
4
+ emitAccept = () => void this.emit(this.EVENTS.DISCLAIMER.ACCEPT);
5
+ updateEvent = this.EVENTS.DISCLAIMER.UPDATE;
6
+ controls = {
7
+ [this.CONST.CONTROLS.BUTTONS.ACCEPT]: this.emitAccept,
8
+ [this.CONST.CONTROLS.BUTTONS.INTERACT]: this.emitAccept,
9
+ };
10
+ controlsIndex = this.PARAMS.DISCLAIMER.ZINDEX;
11
+ subscribe = () => {
12
+ this.on(this.EVENTS.DISCLAIMER.SHOW, this.onShow);
13
+ this.on(this.EVENTS.DISCLAIMER.HIDE, this.onHide);
14
+ };
15
+ beforeShow = (args = {}) => this.updateState(args);
16
+ }
@@ -0,0 +1,10 @@
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
+ subscribe: () => void;
7
+ init: () => Promise<unknown[]> | undefined;
8
+ onLineExec: ({ line }?: LineExecHandlerArg) => Promise<unknown[]> | undefined;
9
+ onAccept: () => Promise<void>;
10
+ }
@@ -0,0 +1,21 @@
1
+ import { tokenizeExecLine } from "@vnejs/helpers";
2
+ import { ModuleCore } from "@vnejs/module.core";
3
+ export class Disclaimer extends ModuleCore {
4
+ name = "disclaimer";
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.DISCLAIMER.ACCEPT, this.onAccept);
7
+ };
8
+ init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
9
+ onLineExec = ({ line = "" } = {}) => {
10
+ const [action = "", id = ""] = tokenizeExecLine(line).map(String);
11
+ if (action !== this.CONST.DISCLAIMER.EXEC_ACTIONS.SHOW)
12
+ return;
13
+ this.emitLog({ action, id });
14
+ return this.emit(this.EVENTS.DISCLAIMER.SHOW, { id });
15
+ };
16
+ onAccept = async () => {
17
+ this.emitLog({ action: "accept" });
18
+ await this.emit(this.EVENTS.DISCLAIMER.HIDE);
19
+ this.emitNext();
20
+ };
21
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
3
+ import type { DisclaimerPluginState } from "../utils/disclaimer.js";
4
+ export declare class DisclaimerView extends ModuleView<DisclaimerPluginEvents, DisclaimerPluginConstants, DisclaimerPluginSettings, DisclaimerPluginParams, DisclaimerPluginState> {
5
+ name: string;
6
+ locLabel: string;
7
+ animationTime: number;
8
+ updateEvent: "vne:disclaimer:update";
9
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<DisclaimerPluginState>;
10
+ updateHandler: (state?: DisclaimerPluginState | undefined) => Promise<void>;
11
+ }
@@ -0,0 +1,10 @@
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
+ locLabel = this.PARAMS.DISCLAIMER.LOC_LABEL;
6
+ animationTime = this.PARAMS.DISCLAIMER.TRANSITION;
7
+ updateEvent = this.EVENTS.DISCLAIMER.UPDATE;
8
+ renderFunc = render;
9
+ updateHandler = this.onUpdateStoreComponent;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
3
+ import type { Constants as ScenarioConstants, PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
4
+ import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
5
+ import type { PluginName as LocsPluginName, SubscribeEvents as LocsSubscribeEvents } from "@vnejs/contracts.text.locs";
6
+ import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.views.screens.disclaimer";
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>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export type DisclaimerPluginState = {
2
+ isShow: boolean;
3
+ isForce: boolean;
4
+ id?: string;
5
+ locs?: Record<string, string>;
6
+ };
7
+ export type DisclaimerShowPayload = {
8
+ id?: string;
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { DisclaimerPluginState } from "../utils/disclaimer.js";
3
+ export declare const render: ViewRenderFunc<DisclaimerPluginState>;
@@ -0,0 +1,19 @@
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, useCallback, useMemo, 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 bodyLines = useMemo(() => body.split("\n").map((text) => ({ text, props: PARAMS.DISCLAIMER.VIEW_PROPS.text })), [body, PARAMS.DISCLAIMER.VIEW_PROPS.text]);
11
+ const buttonTexts = useMemo(() => (accept ? [{ text: accept, value: true }] : []), [accept]);
12
+ const onClick = useCallback(() => void emit(EVENTS.DISCLAIMER.ACCEPT), [emit, EVENTS.DISCLAIMER.ACCEPT]);
13
+ const propsByView = PARAMS.DISCLAIMER.VIEW_PROPS;
14
+ const propsScreen = useMemo(() => ({ ...propsByView.screen, isShow, isForce }), [isShow, isForce, propsByView.screen]);
15
+ const propsTitle = useMemo(() => ({ ...propsByView.title, text: title }), [title, propsByView.title]);
16
+ const propsControls = useMemo(() => ({ ...propsByView.controls, texts: buttonTexts, onClick }), [propsByView.controls, buttonTexts, onClick]);
17
+ return (_jsx(Screen, { ...propsScreen, children: _jsx(PositionBox, { ...propsByView.position, children: _jsxs(Flex, { ...propsByView.flex, children: [_jsxs(Flex, { ...propsByView.flexTexts, children: [_jsx(Text, { ...propsTitle }), bodyLines.map(renderTextLine)] }), _jsx(TextControls, { ...propsControls })] }) }) }));
18
+ };
19
+ export const render = createRenderFunc(DisclaimerScreen);
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@vnejs/plugins.views.screens.disclaimer",
3
+ "version": "0.2.1",
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.views.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/contracts.controls": "~0.2.0",
40
+ "@vnejs/contracts.text.locs": "~0.2.0",
41
+ "@vnejs/shared": "~0.2.0",
42
+ "@vnejs/uis.react": "~0.2.0"
43
+ },
44
+ "devDependencies": {
45
+ "@vnejs/configs.ts-common": "~0.2.0",
46
+ "@vnejs/configs.vitest": "~0.2.0",
47
+ "@vnejs/test-utils": "~0.2.0",
48
+ "@vnejs/contracts.controls": "~0.2.0",
49
+ "@vnejs/contracts.text.locs": "~0.2.0",
50
+ "@vnejs/contracts.views.screens.disclaimer": "~0.2.0",
51
+ "@vnejs/helpers": "~0.2.0",
52
+ "@vnejs/module.core": "~0.2.0",
53
+ "@vnejs/module.components": "~0.2.0",
54
+ "@vnejs/shared": "~0.2.0",
55
+ "@vnejs/uis.react": "~0.2.0"
56
+ }
57
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ import "@vnejs/contracts.views.screens.disclaimer";
2
+
3
+ import { regPlugin } from "@vnejs/shared";
4
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.screens.disclaimer";
5
+
6
+ import { DisclaimerController } from "./modules/controller.js";
7
+ import { Disclaimer } from "./modules/disclaimer.js";
8
+ import { DisclaimerView } from "./modules/view.js";
9
+
10
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [DisclaimerController, Disclaimer, DisclaimerView]);
@@ -0,0 +1,30 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
4
+ import type { DisclaimerPluginState, DisclaimerShowPayload } from "../utils/disclaimer.js";
5
+
6
+ export class DisclaimerController extends ModuleController<
7
+ DisclaimerPluginEvents,
8
+ DisclaimerPluginConstants,
9
+ DisclaimerPluginSettings,
10
+ DisclaimerPluginParams,
11
+ DisclaimerPluginState
12
+ > {
13
+ name = "disclaimer.controller";
14
+
15
+ emitAccept = () => void this.emit(this.EVENTS.DISCLAIMER.ACCEPT);
16
+
17
+ updateEvent = this.EVENTS.DISCLAIMER.UPDATE;
18
+ controls = {
19
+ [this.CONST.CONTROLS.BUTTONS.ACCEPT]: this.emitAccept,
20
+ [this.CONST.CONTROLS.BUTTONS.INTERACT]: this.emitAccept,
21
+ };
22
+ controlsIndex = this.PARAMS.DISCLAIMER.ZINDEX;
23
+
24
+ subscribe = () => {
25
+ this.on(this.EVENTS.DISCLAIMER.SHOW, this.onShow);
26
+ this.on(this.EVENTS.DISCLAIMER.HIDE, this.onHide);
27
+ };
28
+
29
+ beforeShow = (args = {}) => this.updateState(args as DisclaimerShowPayload);
30
+ }
@@ -0,0 +1,33 @@
1
+ import { tokenizeExecLine } from "@vnejs/helpers";
2
+ import { ModuleCore } from "@vnejs/module.core";
3
+
4
+ import type { LineExecHandlerArg } from "@vnejs/module.core";
5
+
6
+ import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
7
+ import type { DisclaimerShowPayload } from "../utils/disclaimer.js";
8
+
9
+ export class Disclaimer extends ModuleCore<DisclaimerPluginEvents, DisclaimerPluginConstants, DisclaimerPluginSettings, DisclaimerPluginParams> {
10
+ name = "disclaimer";
11
+
12
+ subscribe = () => {
13
+ this.on(this.EVENTS.DISCLAIMER.ACCEPT, this.onAccept);
14
+ };
15
+
16
+ init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
17
+
18
+ onLineExec = ({ line = "" }: LineExecHandlerArg = {}) => {
19
+ const [action = "", id = ""] = tokenizeExecLine(line).map(String);
20
+
21
+ if (action !== this.CONST.DISCLAIMER.EXEC_ACTIONS.SHOW) return;
22
+
23
+ this.emitLog({ action, id });
24
+
25
+ return this.emit(this.EVENTS.DISCLAIMER.SHOW, { id } satisfies DisclaimerShowPayload);
26
+ };
27
+
28
+ onAccept = async () => {
29
+ this.emitLog({ action: "accept" });
30
+ await this.emit(this.EVENTS.DISCLAIMER.HIDE);
31
+ this.emitNext();
32
+ };
33
+ }
@@ -0,0 +1,22 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import { render } from "../view/index.js";
4
+ import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
5
+ import type { DisclaimerPluginState } from "../utils/disclaimer.js";
6
+
7
+ export class DisclaimerView extends ModuleView<
8
+ DisclaimerPluginEvents,
9
+ DisclaimerPluginConstants,
10
+ DisclaimerPluginSettings,
11
+ DisclaimerPluginParams,
12
+ DisclaimerPluginState
13
+ > {
14
+ name = "disclaimer.view";
15
+
16
+ locLabel = this.PARAMS.DISCLAIMER.LOC_LABEL;
17
+ animationTime = this.PARAMS.DISCLAIMER.TRANSITION;
18
+ updateEvent = this.EVENTS.DISCLAIMER.UPDATE;
19
+
20
+ renderFunc = render;
21
+ updateHandler = this.onUpdateStoreComponent;
22
+ }
@@ -0,0 +1,46 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { Disclaimer } from "../modules/disclaimer.js";
6
+ import { createDisclaimerTestModule, registerDisclaimerPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
7
+
8
+ describe("Disclaimer", () => {
9
+ beforeEach(() => {
10
+ registerDisclaimerPluginVne();
11
+ });
12
+
13
+ it("line exec show emits SHOW with id", async () => {
14
+ const { module, observer } = createDisclaimerTestModule(Disclaimer, { subscribe: false });
15
+ const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
16
+
17
+ await (module as Disclaimer).init();
18
+ await (module as Disclaimer).onLineExec({ line: "show setting" });
19
+
20
+ expect(show).toHaveBeenCalledOnce();
21
+ expect(show).toHaveBeenCalledWith({ id: "setting" });
22
+ });
23
+
24
+ it("line exec ignores unknown action", async () => {
25
+ const { module, observer } = createDisclaimerTestModule(Disclaimer, { subscribe: false });
26
+ const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
27
+
28
+ await (module as Disclaimer).init();
29
+ await (module as Disclaimer).onLineExec({ line: "setting" });
30
+
31
+ expect(show).not.toHaveBeenCalled();
32
+ });
33
+
34
+ it("ACCEPT hides and emits next", async () => {
35
+ const { observer } = createDisclaimerTestModule(Disclaimer);
36
+ const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
37
+ const next = vi.fn();
38
+
39
+ observer.subscribe("vne:scenario:next", next);
40
+
41
+ await observer.emit(SUBSCRIBE_EVENTS.ACCEPT);
42
+
43
+ expect(hide).toHaveBeenCalledOnce();
44
+ expect(next).toHaveBeenCalledOnce();
45
+ });
46
+ });
@@ -0,0 +1,35 @@
1
+ import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
2
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.screens.disclaimer";
3
+ import {
4
+ createTestModule as baseCreateTestModule,
5
+ registerCoreVne,
6
+ registerVnePlugin,
7
+ stubSilentEvent,
8
+ } from "@vnejs/test-utils";
9
+
10
+ export const registerDisclaimerPluginVne = () => {
11
+ registerCoreVne();
12
+ registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
13
+ registerVnePlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS });
14
+ };
15
+
16
+ export const createDisclaimerTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
17
+ ModuleClass: T,
18
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
19
+ ) => {
20
+ const result = baseCreateTestModule(ModuleClass, {
21
+ state: {
22
+ disclaimer: { isShow: false, id: "" },
23
+ ...(options.state ?? {}),
24
+ },
25
+ ...options,
26
+ });
27
+
28
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW);
29
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.HIDE);
30
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE);
31
+
32
+ return result;
33
+ };
34
+
35
+ export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME };
package/src/types.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
3
+ import type { Constants as ScenarioConstants, PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
4
+ import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
5
+ import type { PluginName as LocsPluginName, SubscribeEvents as LocsSubscribeEvents } from "@vnejs/contracts.text.locs";
6
+ import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.views.screens.disclaimer";
7
+
8
+ export type DisclaimerPluginEvents = ModuleComponentsEvents &
9
+ Record<PluginName, SubscribeEvents> &
10
+ Record<ScenarioPluginName, ScenarioSubscribeEvents> &
11
+ Record<LogsPluginName, LogsSubscribeEvents> &
12
+ Record<LocsPluginName, LocsSubscribeEvents>;
13
+
14
+ export type DisclaimerPluginConstants = ModuleComponentsConstants &
15
+ Record<PluginName, Constants> &
16
+ Record<ControlsPluginName, ControlsConstants> &
17
+ Record<ScenarioPluginName, ScenarioConstants>;
18
+
19
+ export type DisclaimerPluginSettings = ModuleComponentsSettings;
20
+
21
+ export type DisclaimerPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
@@ -0,0 +1,10 @@
1
+ export type DisclaimerPluginState = {
2
+ isShow: boolean;
3
+ isForce: boolean;
4
+ id?: string;
5
+ locs?: Record<string, string>;
6
+ };
7
+
8
+ export type DisclaimerShowPayload = {
9
+ id?: string;
10
+ };
@@ -0,0 +1,64 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { ReactComponentProps } from "@vnejs/uis.react";
3
+ import { Flex, PositionBox, Screen, Text, TextControls, createRenderFunc, useCallback, useMemo, useStoreState } from "@vnejs/uis.react";
4
+
5
+ import type { DisclaimerPluginConstants, DisclaimerPluginEvents, DisclaimerPluginParams, DisclaimerPluginSettings } from "../types.js";
6
+ import type { DisclaimerPluginState } from "../utils/disclaimer.js";
7
+
8
+ type DisclaimerComponentProps = ReactComponentProps<
9
+ DisclaimerPluginEvents,
10
+ DisclaimerPluginConstants,
11
+ DisclaimerPluginSettings,
12
+ DisclaimerPluginParams,
13
+ DisclaimerPluginState
14
+ >;
15
+
16
+ const renderTextLine = ({ text, props }: { text: string; props: Record<string, unknown> }, i: number) => (
17
+ <Text
18
+ {...props}
19
+ text={text}
20
+ key={i}
21
+ />
22
+ );
23
+
24
+ const DisclaimerScreen = ({ store, onMount, PARAMS, emit, EVENTS }: DisclaimerComponentProps) => {
25
+ const { isShow = false, isForce = false, id = "", locs = {} } = useStoreState<DisclaimerPluginState>(store, onMount);
26
+
27
+ const title = locs[`${id}.title`] || "";
28
+ const body = locs[`${id}.text`] || "";
29
+ const accept = locs.accept || "";
30
+
31
+ const bodyLines = useMemo(
32
+ () => body.split("\n").map((text) => ({ text, props: PARAMS.DISCLAIMER.VIEW_PROPS.text })),
33
+ [body, PARAMS.DISCLAIMER.VIEW_PROPS.text],
34
+ );
35
+
36
+ const buttonTexts = useMemo(() => (accept ? [{ text: accept, value: true }] : []), [accept]);
37
+
38
+ const onClick = useCallback(() => void emit(EVENTS.DISCLAIMER.ACCEPT), [emit, EVENTS.DISCLAIMER.ACCEPT]);
39
+
40
+ const propsByView = PARAMS.DISCLAIMER.VIEW_PROPS;
41
+
42
+ const propsScreen = useMemo(() => ({ ...propsByView.screen, isShow, isForce }), [isShow, isForce, propsByView.screen]);
43
+ const propsTitle = useMemo(() => ({ ...propsByView.title, text: title }), [title, propsByView.title]);
44
+ const propsControls = useMemo(
45
+ () => ({ ...propsByView.controls, texts: buttonTexts, onClick }),
46
+ [propsByView.controls, buttonTexts, onClick],
47
+ );
48
+
49
+ return (
50
+ <Screen {...propsScreen}>
51
+ <PositionBox {...propsByView.position}>
52
+ <Flex {...propsByView.flex}>
53
+ <Flex {...propsByView.flexTexts}>
54
+ <Text {...propsTitle} />
55
+ {bodyLines.map(renderTextLine)}
56
+ </Flex>
57
+ <TextControls {...propsControls} />
58
+ </Flex>
59
+ </PositionBox>
60
+ </Screen>
61
+ );
62
+ };
63
+
64
+ export const render: ViewRenderFunc<DisclaimerPluginState> = createRenderFunc(DisclaimerScreen);
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
+ }