@vnejs/plugins.views.scenario.interface.controls 0.1.2
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/const/events.js +8 -0
- package/const/params.js +22 -0
- package/index.js +9 -0
- package/modules/controller.js +80 -0
- package/modules/view.js +13 -0
- package/package.json +17 -0
- package/view/index.jsx +45 -0
package/const/events.js
ADDED
package/const/params.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getVneLength } from "@vnejs/uis.utils";
|
|
2
|
+
|
|
3
|
+
export const VIEW_PROPS = {
|
|
4
|
+
adv: {
|
|
5
|
+
icon: { width: 96, height: 96, isOpacityOnHover: true },
|
|
6
|
+
view: { left: 360, bottom: 24, translateX: getVneLength(240) },
|
|
7
|
+
flex: { gap: 36 },
|
|
8
|
+
},
|
|
9
|
+
line: {
|
|
10
|
+
icon: { width: 96, height: 96, isOpacityOnHover: true },
|
|
11
|
+
view: { left: 360, bottom: 24 },
|
|
12
|
+
flex: { gap: 36 },
|
|
13
|
+
},
|
|
14
|
+
wall: {
|
|
15
|
+
icon: { width: 96, height: 96, isOpacityOnHover: true },
|
|
16
|
+
view: { left: 144, bottom: 144 },
|
|
17
|
+
flex: { gap: 36 },
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const ITEMS = [];
|
|
22
|
+
export const CONTROLS_EXTENSIONS = {};
|
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
|
|
3
|
+
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
4
|
+
import * as params from "./const/params";
|
|
5
|
+
|
|
6
|
+
import { InterfaceControlsController } from "./modules/controller";
|
|
7
|
+
import { InterfaceControlsView } from "./modules/view";
|
|
8
|
+
|
|
9
|
+
regPlugin("INTERFACE_CONTROLS_VIEW", { events: SUBSCRIBE_EVENTS, params }, [InterfaceControlsController, InterfaceControlsView]);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
export class InterfaceControlsController extends ModuleController {
|
|
4
|
+
name = "interface.controls.controller";
|
|
5
|
+
|
|
6
|
+
updateEvent = this.EVENTS.INTERFACE_CONTROLS_VIEW.UPDATE;
|
|
7
|
+
controls = {
|
|
8
|
+
[this.CONST.CONTROLS.BUTTONS.INTERFACE_HIDE]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE),
|
|
9
|
+
[this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => this.emit(this.EVENTS.INTERFACE.INTERACT),
|
|
10
|
+
[this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE),
|
|
11
|
+
};
|
|
12
|
+
controlsUnvisible = { [this.CONST.CONTROLS.BUTTONS.ANY]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE) };
|
|
13
|
+
controlsIndex = this.PARAMS.INTERFACE.ZINDEX + 100;
|
|
14
|
+
controlsCheckNext = true;
|
|
15
|
+
|
|
16
|
+
subscribe = () => {
|
|
17
|
+
this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.SHOW, this.onShow);
|
|
18
|
+
this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.HIDE, this.onHide);
|
|
19
|
+
this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.CLICK, this.onClick);
|
|
20
|
+
this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.ICONS, this.onIcons);
|
|
21
|
+
|
|
22
|
+
this.on(this.EVENTS.INTERFACE.SHOW_CHANGED, this.onShowChanged);
|
|
23
|
+
this.on(this.EVENTS.INTERFACE.VIEW_CHANGED, this.onViewChanged);
|
|
24
|
+
this.on(this.EVENTS.INTERFACE.STATE_CHANGED, this.onStateChanged);
|
|
25
|
+
this.on(this.EVENTS.INTERFACE.VISIBLE_CHANGED, this.onVisibleChanged);
|
|
26
|
+
|
|
27
|
+
this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
|
|
28
|
+
};
|
|
29
|
+
init = () => Object.assign(this.controls, this.PARAMS.INTERFACE_CONTROLS_VIEW.CONTROLS_EXTENSIONS);
|
|
30
|
+
|
|
31
|
+
beforeShow = async () => this.updateState({ icons: await this.emitOne(this.EVENTS.INTERFACE_CONTROLS_VIEW.ICONS) });
|
|
32
|
+
|
|
33
|
+
onShowChanged = ({ isForce = false } = {}) => {
|
|
34
|
+
const { isShow = false } = this.globalState.interface;
|
|
35
|
+
const event = isShow ? this.EVENTS.INTERFACE_CONTROLS_VIEW.SHOW : this.EVENTS.INTERFACE_CONTROLS_VIEW.HIDE;
|
|
36
|
+
|
|
37
|
+
return this.state.isShow !== isShow && this.emit(event, { isForce });
|
|
38
|
+
};
|
|
39
|
+
onViewChanged = ({ isForce = false } = {}) => {
|
|
40
|
+
const { view = "" } = this.globalState.interface;
|
|
41
|
+
|
|
42
|
+
return this.state.view !== view && this.updateStateAndView({ view }, isForce, !isForce);
|
|
43
|
+
};
|
|
44
|
+
onVisibleChanged = async ({ isForce = false } = {}) => {
|
|
45
|
+
const { isVisible = false } = this.globalState.interface;
|
|
46
|
+
|
|
47
|
+
this.toggleUnvisibleControls(isVisible);
|
|
48
|
+
|
|
49
|
+
return this.state.isVisible !== isVisible && this.updateStateAndView({ isVisible }, isForce, !isForce);
|
|
50
|
+
};
|
|
51
|
+
onStateChanged = () => {
|
|
52
|
+
const { isShow = false, isVisible = false, view = "" } = this.globalState.interface;
|
|
53
|
+
|
|
54
|
+
this.toggleUnvisibleControls(isVisible);
|
|
55
|
+
|
|
56
|
+
return this.updateStateAndViewForce({ isVisible, isShow, view });
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
onClick = ({ index = 0 } = {}) => this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS?.[index]?.onClick(this);
|
|
60
|
+
onIcons = () => Promise.all(this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS.map(this.getOneIconSrcs));
|
|
61
|
+
|
|
62
|
+
onMemoryCleared = async () => this.updateStateAndViewFast({ icons: await this.emitOne(this.EVENTS.INTERFACE_CONTROLS_VIEW.ICONS) });
|
|
63
|
+
|
|
64
|
+
toggleUnvisibleControls = (isVisible) => {
|
|
65
|
+
const args = { key: `${this.name}-unvisible`, controls: this.controlsUnvisible, index: this.controlsIndex + 500 };
|
|
66
|
+
|
|
67
|
+
return this.emit(isVisible ? this.EVENTS.CONTROLS.POP : this.EVENTS.CONTROLS.PUSH, args);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
getDefaultState = () => ({ isShow: false, isVisible: false, view: "" });
|
|
71
|
+
|
|
72
|
+
getOneIconSrcs = async ({ icon = "", iconHover = "" } = {}) => {
|
|
73
|
+
const [result, quality] = [{}, this.shared.settings[this.SETTINGS.LAYER.QUALITY]];
|
|
74
|
+
|
|
75
|
+
if (icon) result.src = (await this.loadImageMedia(`interface/${icon}`, "icons", quality)).src;
|
|
76
|
+
if (iconHover) result.srcHover = (await this.loadImageMedia(`interface/${iconHover}`, "icons", quality)).src;
|
|
77
|
+
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
}
|
package/modules/view.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { render } from "../view";
|
|
4
|
+
|
|
5
|
+
export class InterfaceControlsView extends ModuleView {
|
|
6
|
+
name = "interface.controls.view";
|
|
7
|
+
|
|
8
|
+
animationTime = this.PARAMS.INTERFACE.TRANSITION;
|
|
9
|
+
updateEvent = this.EVENTS.INTERFACE_CONTROLS_VIEW.UPDATE;
|
|
10
|
+
|
|
11
|
+
renderFunc = render;
|
|
12
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
13
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/plugins.views.scenario.interface.controls",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major:plugin": "npm run publish:major",
|
|
8
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
9
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
10
|
+
"publish:major": "npm version major && npm publish --access public",
|
|
11
|
+
"publish:minor": "npm version minor && npm publish --access public",
|
|
12
|
+
"publish:patch": "npm version patch && npm publish --access public"
|
|
13
|
+
},
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"description": ""
|
|
17
|
+
}
|
package/view/index.jsx
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
|
|
4
|
+
import { Flex, Icon, useIsForceHook, View } from "@vnejs/uis.react";
|
|
5
|
+
|
|
6
|
+
const renderIcon = ({ src, srcHover, props }, i) => (
|
|
7
|
+
<Icon
|
|
8
|
+
{...props}
|
|
9
|
+
srcHover={srcHover}
|
|
10
|
+
src={src}
|
|
11
|
+
value={i}
|
|
12
|
+
key={src}
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const InterfaceControls = ({ store, onMount, ...props } = {}) => {
|
|
17
|
+
const [{ isShow = false, isVisible = false, isForce = false, view = "", icons = [] }, setState] = useState({});
|
|
18
|
+
|
|
19
|
+
useEffect(() => store.subscribe(setState), []);
|
|
20
|
+
useEffect(() => void onMount(), []);
|
|
21
|
+
|
|
22
|
+
const isRealForce = useIsForceHook(isForce);
|
|
23
|
+
|
|
24
|
+
const onClick = useCallback((index = 0) => props.emit(props.EVENTS.INTERFACE_CONTROLS_VIEW.CLICK, { index }), []);
|
|
25
|
+
|
|
26
|
+
const transition = isRealForce ? 0 : props.PARAMS.INTERFACE.TRANSITION;
|
|
27
|
+
|
|
28
|
+
const propsByView = useMemo(() => props.PARAMS.INTERFACE_CONTROLS_VIEW.VIEW_PROPS[view] || {}, [view]);
|
|
29
|
+
const propsIcon = useMemo(() => ({ ...propsByView.icon, transition, onClick }), [propsByView, transition]);
|
|
30
|
+
const propsView = useMemo(() => ({ ...propsByView.view, isShow, isForce: isRealForce, transition }), [propsByView, isShow, isRealForce, transition]);
|
|
31
|
+
|
|
32
|
+
const iconsWithProps = useMemo(() => icons.map(({ src, srcHover }) => ({ src, srcHover, props: propsIcon })), [icons, propsIcon]);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<View
|
|
36
|
+
{...propsView}
|
|
37
|
+
isHidden={!isVisible}
|
|
38
|
+
zIndex={props.PARAMS.INTERFACE.ZINDEX + 100}
|
|
39
|
+
>
|
|
40
|
+
<Flex {...propsByView.flex}>{iconsWithProps.map(renderIcon)}</Flex>
|
|
41
|
+
</View>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const render = (props, root) => createRoot(root).render(<InterfaceControls {...props} />);
|