@vnejs/plugins.views.screens.confirm 0.1.4 → 0.1.5
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 +6 -0
- package/dist/modules/confirm.d.ts +15 -0
- package/dist/modules/confirm.js +24 -0
- package/dist/modules/controller.d.ts +18 -0
- package/dist/modules/controller.js +20 -0
- package/dist/modules/view.d.ts +10 -0
- package/dist/modules/view.js +9 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.js +1 -0
- package/dist/utils/confirm.d.ts +17 -0
- package/dist/utils/confirm.js +1 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +16 -0
- package/package.json +35 -6
- package/src/index.ts +8 -0
- package/src/modules/confirm.ts +33 -0
- package/src/modules/controller.ts +36 -0
- package/src/modules/view.ts +21 -0
- package/src/types.ts +14 -0
- package/src/utils/confirm.ts +19 -0
- package/src/view/index.tsx +68 -0
- package/tsconfig.json +10 -0
- package/const/events.js +0 -9
- package/const/params.js +0 -11
- package/index.js +0 -11
- package/modules/confirm.js +0 -27
- package/modules/controller.js +0 -26
- package/modules/view.js +0 -13
- package/view/index.jsx +0 -45
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.views.screens.confirm.contract";
|
|
3
|
+
import { ConfirmController } from "./modules/controller.js";
|
|
4
|
+
import { Confirm } from "./modules/confirm.js";
|
|
5
|
+
import { ConfirmView } from "./modules/view.js";
|
|
6
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [ConfirmController, Confirm, ConfirmView]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import type { ConfirmPluginConstants, ConfirmPluginEvents, ConfirmPluginParams, ConfirmPluginSettings } from "../types.js";
|
|
3
|
+
import type { ConfirmEmitPayload } from "../utils/confirm.js";
|
|
4
|
+
export declare class Confirm extends Module<ConfirmPluginEvents, ConfirmPluginConstants, ConfirmPluginSettings, ConfirmPluginParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
acceptCallback?: () => void | Promise<void>;
|
|
7
|
+
declineCallback?: () => void | Promise<void>;
|
|
8
|
+
subscribe: () => void;
|
|
9
|
+
onEmit: ({ onAccept, onDecline, ...args }?: ConfirmEmitPayload) => Promise<unknown[]> | undefined;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
onAccept: () => Promise<(void | unknown[])[]>;
|
|
12
|
+
onDecline: () => Promise<(void | unknown[])[]>;
|
|
13
|
+
accept: () => void | Promise<void> | undefined;
|
|
14
|
+
decline: () => void | Promise<void> | undefined;
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
export class Confirm extends Module {
|
|
3
|
+
name = "confirm";
|
|
4
|
+
acceptCallback;
|
|
5
|
+
declineCallback;
|
|
6
|
+
subscribe = () => {
|
|
7
|
+
this.on(this.EVENTS.CONFIRM.EMIT, this.onEmit);
|
|
8
|
+
this.on(this.EVENTS.CONFIRM.ACCEPT, this.onAccept);
|
|
9
|
+
this.on(this.EVENTS.CONFIRM.DECLINE, this.onDecline);
|
|
10
|
+
};
|
|
11
|
+
onEmit = ({ onAccept, onDecline, ...args } = {}) => {
|
|
12
|
+
this.acceptCallback = onAccept;
|
|
13
|
+
this.declineCallback = onDecline;
|
|
14
|
+
return this.emit(this.EVENTS.CONFIRM.SHOW, { ...args, onClose: this.onClose });
|
|
15
|
+
};
|
|
16
|
+
onClose = () => {
|
|
17
|
+
delete this.acceptCallback;
|
|
18
|
+
delete this.declineCallback;
|
|
19
|
+
};
|
|
20
|
+
onAccept = () => Promise.all([this.accept(), this.emit(this.EVENTS.CONFIRM.HIDE)].filter(Boolean));
|
|
21
|
+
onDecline = () => Promise.all([this.decline(), this.emit(this.EVENTS.CONFIRM.HIDE)].filter(Boolean));
|
|
22
|
+
accept = () => this.acceptCallback?.();
|
|
23
|
+
decline = () => this.declineCallback?.();
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
import type { ConfirmPluginConstants, ConfirmPluginEvents, ConfirmPluginParams, ConfirmPluginSettings } from "../types.js";
|
|
3
|
+
import type { ConfirmPluginState } from "../utils/confirm.js";
|
|
4
|
+
export declare class ConfirmController extends ModuleController<ConfirmPluginEvents, ConfirmPluginConstants, ConfirmPluginSettings, ConfirmPluginParams, ConfirmPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
maxCurrentItem: number;
|
|
7
|
+
updateEvent: "vne:confirm:update";
|
|
8
|
+
controls: {
|
|
9
|
+
abstract_interact: () => undefined;
|
|
10
|
+
abstract_accept: () => undefined;
|
|
11
|
+
abstract_back: () => undefined;
|
|
12
|
+
abstract_arrow_left: () => Promise<void>;
|
|
13
|
+
abstract_arrow_right: () => Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
controlsIndex: number;
|
|
16
|
+
subscribe: () => void;
|
|
17
|
+
beforeShow: (args?: {}) => void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
export class ConfirmController extends ModuleController {
|
|
3
|
+
name = "confirm.controller";
|
|
4
|
+
maxCurrentItem = 1;
|
|
5
|
+
updateEvent = this.EVENTS.CONFIRM.UPDATE;
|
|
6
|
+
controls = {
|
|
7
|
+
[this.CONST.CONTROLS.BUTTONS.INTERACT]: () => void this.emit(this.maxCurrentItem === 0 ? this.EVENTS.CONFIRM.ACCEPT : this.EVENTS.CONFIRM.DECLINE),
|
|
8
|
+
[this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => void this.emit(this.EVENTS.CONFIRM.ACCEPT),
|
|
9
|
+
[this.CONST.CONTROLS.BUTTONS.BACK]: () => void this.emit(this.EVENTS.CONFIRM.DECLINE),
|
|
10
|
+
[this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: this.decCurrentItem,
|
|
11
|
+
[this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: this.incCurrentItem,
|
|
12
|
+
};
|
|
13
|
+
controlsIndex = this.PARAMS.CONFIRM.ZINDEX;
|
|
14
|
+
subscribe = () => {
|
|
15
|
+
this.on(this.EVENTS.CONFIRM.SHOW, this.onShow);
|
|
16
|
+
this.on(this.EVENTS.CONFIRM.HIDE, this.onHide);
|
|
17
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onHide);
|
|
18
|
+
};
|
|
19
|
+
beforeShow = (args = {}) => this.updateState(args);
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import type { ConfirmPluginConstants, ConfirmPluginEvents, ConfirmPluginParams, ConfirmPluginSettings } from "../types.js";
|
|
3
|
+
import type { ConfirmPluginState } from "../utils/confirm.js";
|
|
4
|
+
export declare class ConfirmView extends ModuleView<ConfirmPluginEvents, ConfirmPluginConstants, ConfirmPluginSettings, ConfirmPluginParams, ConfirmPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
animationTime: number;
|
|
7
|
+
updateEvent: "vne:confirm:update";
|
|
8
|
+
renderFunc: import("@vnejs/module.components").ViewRenderFunc<ConfirmPluginState>;
|
|
9
|
+
updateHandler: (state?: ConfirmPluginState | undefined) => Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import { render } from "../view/index.js";
|
|
3
|
+
export class ConfirmView extends ModuleView {
|
|
4
|
+
name = "confirm.view";
|
|
5
|
+
animationTime = this.PARAMS.CONFIRM.TRANSITION;
|
|
6
|
+
updateEvent = this.EVENTS.CONFIRM.UPDATE;
|
|
7
|
+
renderFunc = render;
|
|
8
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
9
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/plugins.controls.contract";
|
|
3
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
|
|
4
|
+
import type { Params, PluginName, SubscribeEvents } from "@vnejs/plugins.views.screens.confirm.contract";
|
|
5
|
+
export type ConfirmPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
|
|
6
|
+
export type ConfirmPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
|
|
7
|
+
export type ConfirmPluginSettings = ModuleComponentsSettings;
|
|
8
|
+
export type ConfirmPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ConfirmPluginState = {
|
|
2
|
+
isShow: boolean;
|
|
3
|
+
isForce: boolean;
|
|
4
|
+
text?: string;
|
|
5
|
+
textAccept?: string;
|
|
6
|
+
textDecline?: string;
|
|
7
|
+
currentItem?: number | null;
|
|
8
|
+
};
|
|
9
|
+
export type ConfirmEmitPayload = {
|
|
10
|
+
onAccept?: () => void | Promise<void>;
|
|
11
|
+
onDecline?: () => void | Promise<void>;
|
|
12
|
+
text?: string;
|
|
13
|
+
textAccept?: string;
|
|
14
|
+
textDecline?: string;
|
|
15
|
+
onClose?: () => void;
|
|
16
|
+
};
|
|
17
|
+
export type ConfirmShowPayload = Omit<ConfirmEmitPayload, "onAccept" | "onDecline">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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 renderTitleLine = ({ text, props }) => (_createElement(Text, { ...props, text: text, key: text }));
|
|
5
|
+
const mapChoices = (text, i) => ({ text, value: i === 0 });
|
|
6
|
+
const ConfirmView = ({ store, onMount, PARAMS, emit, EVENTS }) => {
|
|
7
|
+
const { isShow = false, isForce = false, text = "", textAccept = "", textDecline = "", currentItem: selectedIndex = null, } = useStoreState(store, onMount);
|
|
8
|
+
const texts = useMemo(() => [textAccept, textDecline].filter(Boolean).map(mapChoices), [textAccept, textDecline]);
|
|
9
|
+
const onClick = useCallback((isAccept) => void emit(isAccept ? EVENTS.CONFIRM.ACCEPT : EVENTS.CONFIRM.DECLINE), [emit, EVENTS.CONFIRM.ACCEPT, EVENTS.CONFIRM.DECLINE]);
|
|
10
|
+
const propsView = PARAMS.CONFIRM.VIEW_PROPS;
|
|
11
|
+
const propsScreen = useMemo(() => ({ ...propsView.screen, isShow, isForce }), [isShow, isForce, propsView.screen]);
|
|
12
|
+
const propsControls = useMemo(() => ({ ...propsView.controls, selectedIndex: selectedIndex ?? undefined, texts, onClick }), [propsView.controls, selectedIndex, texts, onClick]);
|
|
13
|
+
const textsWithProps = useMemo(() => (text || "").split("\n").map((line) => ({ text: line, props: propsView.text })), [text, propsView.text]);
|
|
14
|
+
return (_jsx(Screen, { ...propsScreen, children: _jsx(PositionBox, { ...propsView.position, children: _jsxs(Flex, { ...propsView.flex, children: [_jsx(Flex, { ...propsView.flexTitles, children: textsWithProps.map(renderTitleLine) }), _jsx(TextControls, { ...propsControls })] }) }) }));
|
|
15
|
+
};
|
|
16
|
+
export const render = createRenderFunc(ConfirmView);
|
package/package.json
CHANGED
|
@@ -1,17 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.views.screens.confirm",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.5",
|
|
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
|
+
],
|
|
5
20
|
"scripts": {
|
|
6
21
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
7
23
|
"publish:major:plugin": "npm run publish:major",
|
|
8
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
9
25
|
"publish:patch:plugin": "npm run publish:patch",
|
|
10
|
-
"publish:major": "
|
|
11
|
-
"publish:minor": "
|
|
12
|
-
"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"
|
|
13
29
|
},
|
|
14
30
|
"author": "",
|
|
15
31
|
"license": "ISC",
|
|
16
|
-
"
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/plugins.views.screens.confirm.contract": "~0.0.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/module": "~0.0.1",
|
|
37
|
+
"@vnejs/module.components": "~0.0.1",
|
|
38
|
+
"@vnejs/plugins.controls.contract": "~0.0.1",
|
|
39
|
+
"@vnejs/plugins.core.state.contract": "~0.0.1",
|
|
40
|
+
"@vnejs/shared": "~0.0.9",
|
|
41
|
+
"@vnejs/uis.react": "~0.1.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@vnejs/configs.ts-common": "~0.0.1"
|
|
45
|
+
}
|
|
17
46
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.views.screens.confirm.contract";
|
|
3
|
+
|
|
4
|
+
import { ConfirmController } from "./modules/controller.js";
|
|
5
|
+
import { Confirm } from "./modules/confirm.js";
|
|
6
|
+
import { ConfirmView } from "./modules/view.js";
|
|
7
|
+
|
|
8
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [ConfirmController, Confirm, ConfirmView]);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
import type { ConfirmPluginConstants, ConfirmPluginEvents, ConfirmPluginParams, ConfirmPluginSettings } from "../types.js";
|
|
4
|
+
import type { ConfirmEmitPayload } from "../utils/confirm.js";
|
|
5
|
+
|
|
6
|
+
export class Confirm extends Module<ConfirmPluginEvents, ConfirmPluginConstants, ConfirmPluginSettings, ConfirmPluginParams> {
|
|
7
|
+
name = "confirm";
|
|
8
|
+
|
|
9
|
+
acceptCallback?: () => void | Promise<void>;
|
|
10
|
+
declineCallback?: () => void | Promise<void>;
|
|
11
|
+
|
|
12
|
+
subscribe = () => {
|
|
13
|
+
this.on(this.EVENTS.CONFIRM.EMIT, this.onEmit);
|
|
14
|
+
this.on(this.EVENTS.CONFIRM.ACCEPT, this.onAccept);
|
|
15
|
+
this.on(this.EVENTS.CONFIRM.DECLINE, this.onDecline);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
onEmit = ({ onAccept, onDecline, ...args }: ConfirmEmitPayload = {}) => {
|
|
19
|
+
this.acceptCallback = onAccept;
|
|
20
|
+
this.declineCallback = onDecline;
|
|
21
|
+
return this.emit(this.EVENTS.CONFIRM.SHOW, { ...args, onClose: this.onClose });
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
onClose = () => {
|
|
25
|
+
delete this.acceptCallback;
|
|
26
|
+
delete this.declineCallback;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
onAccept = () => Promise.all([this.accept(), this.emit(this.EVENTS.CONFIRM.HIDE)].filter(Boolean));
|
|
30
|
+
onDecline = () => Promise.all([this.decline(), this.emit(this.EVENTS.CONFIRM.HIDE)].filter(Boolean));
|
|
31
|
+
accept = () => this.acceptCallback?.();
|
|
32
|
+
decline = () => this.declineCallback?.();
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { ConfirmPluginConstants, ConfirmPluginEvents, ConfirmPluginParams, ConfirmPluginSettings } from "../types.js";
|
|
4
|
+
import type { ConfirmPluginState } from "../utils/confirm.js";
|
|
5
|
+
|
|
6
|
+
export class ConfirmController extends ModuleController<
|
|
7
|
+
ConfirmPluginEvents,
|
|
8
|
+
ConfirmPluginConstants,
|
|
9
|
+
ConfirmPluginSettings,
|
|
10
|
+
ConfirmPluginParams,
|
|
11
|
+
ConfirmPluginState
|
|
12
|
+
> {
|
|
13
|
+
name = "confirm.controller";
|
|
14
|
+
|
|
15
|
+
maxCurrentItem = 1;
|
|
16
|
+
|
|
17
|
+
updateEvent = this.EVENTS.CONFIRM.UPDATE;
|
|
18
|
+
controls = {
|
|
19
|
+
[this.CONST.CONTROLS.BUTTONS.INTERACT]: () =>
|
|
20
|
+
void this.emit(this.maxCurrentItem === 0 ? this.EVENTS.CONFIRM.ACCEPT : this.EVENTS.CONFIRM.DECLINE),
|
|
21
|
+
[this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => void this.emit(this.EVENTS.CONFIRM.ACCEPT),
|
|
22
|
+
[this.CONST.CONTROLS.BUTTONS.BACK]: () => void this.emit(this.EVENTS.CONFIRM.DECLINE),
|
|
23
|
+
[this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: this.decCurrentItem,
|
|
24
|
+
[this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: this.incCurrentItem,
|
|
25
|
+
};
|
|
26
|
+
controlsIndex = this.PARAMS.CONFIRM.ZINDEX;
|
|
27
|
+
|
|
28
|
+
subscribe = () => {
|
|
29
|
+
this.on(this.EVENTS.CONFIRM.SHOW, this.onShow);
|
|
30
|
+
this.on(this.EVENTS.CONFIRM.HIDE, this.onHide);
|
|
31
|
+
|
|
32
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onHide);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
beforeShow = (args = {}) => this.updateState(args as Partial<ConfirmPluginState>);
|
|
36
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { render } from "../view/index.js";
|
|
4
|
+
import type { ConfirmPluginConstants, ConfirmPluginEvents, ConfirmPluginParams, ConfirmPluginSettings } from "../types.js";
|
|
5
|
+
import type { ConfirmPluginState } from "../utils/confirm.js";
|
|
6
|
+
|
|
7
|
+
export class ConfirmView extends ModuleView<
|
|
8
|
+
ConfirmPluginEvents,
|
|
9
|
+
ConfirmPluginConstants,
|
|
10
|
+
ConfirmPluginSettings,
|
|
11
|
+
ConfirmPluginParams,
|
|
12
|
+
ConfirmPluginState
|
|
13
|
+
> {
|
|
14
|
+
name = "confirm.view";
|
|
15
|
+
|
|
16
|
+
animationTime = this.PARAMS.CONFIRM.TRANSITION;
|
|
17
|
+
updateEvent = this.EVENTS.CONFIRM.UPDATE;
|
|
18
|
+
|
|
19
|
+
renderFunc = render;
|
|
20
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
21
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/plugins.controls.contract";
|
|
3
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
|
|
4
|
+
import type { Params, PluginName, SubscribeEvents } from "@vnejs/plugins.views.screens.confirm.contract";
|
|
5
|
+
|
|
6
|
+
export type ConfirmPluginEvents = ModuleComponentsEvents &
|
|
7
|
+
Record<PluginName, SubscribeEvents> &
|
|
8
|
+
Record<StatePluginName, StateSubscribeEvents>;
|
|
9
|
+
|
|
10
|
+
export type ConfirmPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
|
|
11
|
+
|
|
12
|
+
export type ConfirmPluginSettings = ModuleComponentsSettings;
|
|
13
|
+
|
|
14
|
+
export type ConfirmPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type ConfirmPluginState = {
|
|
2
|
+
isShow: boolean;
|
|
3
|
+
isForce: boolean;
|
|
4
|
+
text?: string;
|
|
5
|
+
textAccept?: string;
|
|
6
|
+
textDecline?: string;
|
|
7
|
+
currentItem?: number | null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ConfirmEmitPayload = {
|
|
11
|
+
onAccept?: () => void | Promise<void>;
|
|
12
|
+
onDecline?: () => void | Promise<void>;
|
|
13
|
+
text?: string;
|
|
14
|
+
textAccept?: string;
|
|
15
|
+
textDecline?: string;
|
|
16
|
+
onClose?: () => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type ConfirmShowPayload = Omit<ConfirmEmitPayload, "onAccept" | "onDecline">;
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { ConfirmPluginConstants, ConfirmPluginEvents, ConfirmPluginParams, ConfirmPluginSettings } from "../types.js";
|
|
6
|
+
import type { ConfirmPluginState } from "../utils/confirm.js";
|
|
7
|
+
|
|
8
|
+
type ConfirmComponentProps = ReactComponentProps<
|
|
9
|
+
ConfirmPluginEvents,
|
|
10
|
+
ConfirmPluginConstants,
|
|
11
|
+
ConfirmPluginSettings,
|
|
12
|
+
ConfirmPluginParams,
|
|
13
|
+
ConfirmPluginState
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
const renderTitleLine = ({ text, props }: { text: string; props: Record<string, unknown> }) => (
|
|
17
|
+
<Text
|
|
18
|
+
{...props}
|
|
19
|
+
text={text}
|
|
20
|
+
key={text}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const mapChoices = (text: string, i: number) => ({ text, value: i === 0 });
|
|
25
|
+
|
|
26
|
+
const ConfirmView = ({ store, onMount, PARAMS, emit, EVENTS }: ConfirmComponentProps) => {
|
|
27
|
+
const {
|
|
28
|
+
isShow = false,
|
|
29
|
+
isForce = false,
|
|
30
|
+
text = "",
|
|
31
|
+
textAccept = "",
|
|
32
|
+
textDecline = "",
|
|
33
|
+
currentItem: selectedIndex = null,
|
|
34
|
+
} = useStoreState<ConfirmPluginState>(store, onMount);
|
|
35
|
+
|
|
36
|
+
const texts = useMemo(() => [textAccept, textDecline].filter(Boolean).map(mapChoices), [textAccept, textDecline]);
|
|
37
|
+
|
|
38
|
+
const onClick = useCallback(
|
|
39
|
+
(isAccept?: unknown) => void emit(isAccept ? EVENTS.CONFIRM.ACCEPT : EVENTS.CONFIRM.DECLINE),
|
|
40
|
+
[emit, EVENTS.CONFIRM.ACCEPT, EVENTS.CONFIRM.DECLINE],
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const propsView = PARAMS.CONFIRM.VIEW_PROPS;
|
|
44
|
+
|
|
45
|
+
const propsScreen = useMemo(() => ({ ...propsView.screen, isShow, isForce }), [isShow, isForce, propsView.screen]);
|
|
46
|
+
const propsControls = useMemo(
|
|
47
|
+
() => ({ ...propsView.controls, selectedIndex: selectedIndex ?? undefined, texts, onClick }),
|
|
48
|
+
[propsView.controls, selectedIndex, texts, onClick],
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const textsWithProps = useMemo(
|
|
52
|
+
() => (text || "").split("\n").map((line) => ({ text: line, props: propsView.text })),
|
|
53
|
+
[text, propsView.text],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Screen {...propsScreen}>
|
|
58
|
+
<PositionBox {...propsView.position}>
|
|
59
|
+
<Flex {...propsView.flex}>
|
|
60
|
+
<Flex {...propsView.flexTitles}>{textsWithProps.map(renderTitleLine)}</Flex>
|
|
61
|
+
<TextControls {...propsControls} />
|
|
62
|
+
</Flex>
|
|
63
|
+
</PositionBox>
|
|
64
|
+
</Screen>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const render: ViewRenderFunc<ConfirmPluginState> = createRenderFunc(ConfirmView);
|
package/tsconfig.json
ADDED
package/const/events.js
DELETED
package/const/params.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const TRANSITION = 500;
|
|
2
|
-
export const ZINDEX = 9000;
|
|
3
|
-
|
|
4
|
-
export const VIEW_PROPS = {
|
|
5
|
-
screen: { withBlur: true, withDark: true, zIndex: ZINDEX, transition: TRANSITION },
|
|
6
|
-
position: { isCentered: true },
|
|
7
|
-
flex: { direction: "column", gap: 60 },
|
|
8
|
-
flexTitles: { direction: "column", gap: 12 },
|
|
9
|
-
controls: { wrapWidth: 3120, flexGap: 0, flexJustify: "center", textSize: 72, textWidth: 780, textAlign: "center" },
|
|
10
|
-
text: { size: 96, width: 3120, align: "center" },
|
|
11
|
-
};
|
package/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { regPlugin } from "@vnejs/shared";
|
|
2
|
-
|
|
3
|
-
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
4
|
-
|
|
5
|
-
import * as params from "./const/params";
|
|
6
|
-
|
|
7
|
-
import { Confirm } from "./modules/confirm";
|
|
8
|
-
import { ConfirmController } from "./modules/controller";
|
|
9
|
-
import { ConfirmView } from "./modules/view";
|
|
10
|
-
|
|
11
|
-
regPlugin("CONFIRM", { events: SUBSCRIBE_EVENTS, params }, [Confirm, ConfirmController, ConfirmView]);
|
package/modules/confirm.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Module } from "@vnejs/module";
|
|
2
|
-
|
|
3
|
-
export class Confirm extends Module {
|
|
4
|
-
name = "confirm";
|
|
5
|
-
|
|
6
|
-
subscribe = () => {
|
|
7
|
-
this.on(this.EVENTS.CONFIRM.EMIT, this.onEmit);
|
|
8
|
-
this.on(this.EVENTS.CONFIRM.ACCEPT, this.onAccept);
|
|
9
|
-
this.on(this.EVENTS.CONFIRM.DECLINE, this.onDecline);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
onEmit = ({ onAccept, onDecline, ...args } = {}) => {
|
|
13
|
-
this.onAccept = onAccept;
|
|
14
|
-
this.onDecline = onDecline;
|
|
15
|
-
return this.emit(this.EVENTS.CONFIRM.SHOW, { ...args, onClose: this.onClose });
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
onClose = () => {
|
|
19
|
-
delete this.onAccept;
|
|
20
|
-
delete this.onDecline;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
onAccept = () => Promise.all([this.accept(), this.emit(this.EVENTS.CONFIRM.HIDE)].filter(Boolean));
|
|
24
|
-
onDecline = () => Promise.all([this.decline(), this.emit(this.EVENTS.CONFIRM.HIDE)].filter(Boolean));
|
|
25
|
-
accept = () => this.onAccept && this.onAccept();
|
|
26
|
-
decline = () => this.onDecline && this.onDecline();
|
|
27
|
-
}
|
package/modules/controller.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
-
|
|
3
|
-
export class ConfirmController extends ModuleController {
|
|
4
|
-
name = "confirm.controller";
|
|
5
|
-
|
|
6
|
-
maxCurrentItem = 1;
|
|
7
|
-
|
|
8
|
-
updateEvent = this.EVENTS.CONFIRM.UPDATE;
|
|
9
|
-
controls = {
|
|
10
|
-
[this.CONST.CONTROLS.BUTTONS.INTERACT]: () => this.emit(this.maxCurrentItem === 0 ? this.EVENTS.CONFIRM.ACCEPT : this.EVENTS.CONFIRM.DECLINE),
|
|
11
|
-
[this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => this.emit(this.EVENTS.CONFIRM.ACCEPT),
|
|
12
|
-
[this.CONST.CONTROLS.BUTTONS.BACK]: () => this.emit(this.EVENTS.CONFIRM.DECLINE),
|
|
13
|
-
[this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: this.decCurrentItem,
|
|
14
|
-
[this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: this.incCurrentItem,
|
|
15
|
-
};
|
|
16
|
-
controlsIndex = this.PARAMS.CONFIRM.ZINDEX;
|
|
17
|
-
|
|
18
|
-
subscribe = () => {
|
|
19
|
-
this.on(this.EVENTS.CONFIRM.SHOW, this.onShow);
|
|
20
|
-
this.on(this.EVENTS.CONFIRM.HIDE, this.onHide);
|
|
21
|
-
|
|
22
|
-
this.on(this.EVENTS.STATE.CLEAR, this.onHide);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
beforeShow = (args) => this.setState(args);
|
|
26
|
-
}
|
package/modules/view.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
-
|
|
3
|
-
import { render } from "../view";
|
|
4
|
-
|
|
5
|
-
export class ConfirmView extends ModuleView {
|
|
6
|
-
name = "confirm.view";
|
|
7
|
-
|
|
8
|
-
animationTime = this.PARAMS.CONFIRM.TRANSITION;
|
|
9
|
-
updateEvent = this.EVENTS.CONFIRM.UPDATE;
|
|
10
|
-
|
|
11
|
-
renderFunc = render;
|
|
12
|
-
updateHandler = this.onUpdateStoreComponent;
|
|
13
|
-
}
|
package/view/index.jsx
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
-
import { createRoot } from "react-dom/client";
|
|
3
|
-
|
|
4
|
-
import { Flex, PositionBox, Screen, Text, TextControls } from "@vnejs/uis.react";
|
|
5
|
-
|
|
6
|
-
const renderTitleLine = ({ text, props } = {}) => (
|
|
7
|
-
<Text
|
|
8
|
-
{...props}
|
|
9
|
-
text={text}
|
|
10
|
-
key={text}
|
|
11
|
-
/>
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
const mapChoises = (text, i) => ({ text, value: i === 0 });
|
|
15
|
-
|
|
16
|
-
const ConfirmView = ({ store, onMount, ...props } = {}) => {
|
|
17
|
-
const [{ isShow = false, isForce = false, text = "", textAccept = "", textDecline = "", currentItem: selectedIndex = null }, setState] = useState({});
|
|
18
|
-
|
|
19
|
-
useEffect(() => store.subscribe(setState), []);
|
|
20
|
-
useEffect(() => void onMount(), []);
|
|
21
|
-
|
|
22
|
-
const texts = useMemo(() => [textAccept, textDecline].filter(Boolean).map(mapChoises), [textAccept, textDecline]);
|
|
23
|
-
|
|
24
|
-
const onClick = useCallback((isAccept) => props.emit(isAccept ? props.EVENTS.CONFIRM.ACCEPT : props.EVENTS.CONFIRM.DECLINE), []);
|
|
25
|
-
|
|
26
|
-
const propsView = props.PARAMS.CONFIRM.VIEW_PROPS;
|
|
27
|
-
|
|
28
|
-
const propsScreen = useMemo(() => ({ ...propsView.screen, isShow, isForce }), [isShow, isForce]);
|
|
29
|
-
const propsControls = useMemo(() => ({ ...propsView.controls, selectedIndex, texts, onClick }), [selectedIndex, texts]);
|
|
30
|
-
|
|
31
|
-
const textsWithProps = useMemo(() => (text || "").split("\n").map((text = "") => ({ text, props: propsView.text })), [text]);
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<Screen {...propsScreen}>
|
|
35
|
-
<PositionBox {...propsView.position}>
|
|
36
|
-
<Flex {...propsView.flex}>
|
|
37
|
-
<Flex {...propsView.flexTitles}>{textsWithProps.map(renderTitleLine)}</Flex>
|
|
38
|
-
<TextControls {...propsControls} />
|
|
39
|
-
</Flex>
|
|
40
|
-
</PositionBox>
|
|
41
|
-
</Screen>
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const render = (props, root) => createRoot(root).render(<ConfirmView {...props} />);
|