@vnejs/plugins.views.scenario.interface.controls 0.1.2 → 0.1.4

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/plugins.views.scenario.interface.controls.contract";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import "@vnejs/plugins.views.scenario.interface.controls.contract";
2
+ import { regPlugin } from "@vnejs/shared";
3
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.views.scenario.interface.controls.contract";
4
+ import { InterfaceControlsController } from "./modules/controller.js";
5
+ import { InterfaceControlsView } from "./modules/view.js";
6
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [InterfaceControlsController, InterfaceControlsView]);
@@ -0,0 +1,30 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import type { InterfaceControlsPluginConstants, InterfaceControlsPluginEvents, InterfaceControlsPluginParams, InterfaceControlsPluginSettings } from "../types.js";
3
+ import type { InterfaceControlsClickPayload, InterfaceControlsForcePayload, InterfaceControlsIconItem, InterfaceControlsIconSrc, InterfaceControlsPluginState } from "../utils/interface.controls.js";
4
+ export declare class InterfaceControlsController extends ModuleController<InterfaceControlsPluginEvents, InterfaceControlsPluginConstants, InterfaceControlsPluginSettings, InterfaceControlsPluginParams, InterfaceControlsPluginState> {
5
+ name: string;
6
+ updateEvent: "vne:interface_controls:update";
7
+ controls: {
8
+ abstract_interface_hide: () => undefined;
9
+ abstract_arrow_right: () => undefined;
10
+ abstract_arrow_bottom: () => undefined;
11
+ };
12
+ controlsUnvisible: {
13
+ abstract_any: () => undefined;
14
+ };
15
+ controlsIndex: number;
16
+ controlsCheckNext: boolean;
17
+ subscribe: () => void;
18
+ init: () => void;
19
+ beforeShow: () => Promise<void>;
20
+ onShowChanged: ({ isForce }?: InterfaceControlsForcePayload) => false | Promise<unknown[]> | undefined;
21
+ onViewChanged: ({ isForce }?: InterfaceControlsForcePayload) => false | Promise<unknown[]> | undefined;
22
+ onVisibleChanged: ({ isForce }?: InterfaceControlsForcePayload) => Promise<false | unknown[] | undefined>;
23
+ onStateChanged: () => Promise<unknown[]> | undefined;
24
+ onClick: ({ index }?: InterfaceControlsClickPayload) => void | undefined;
25
+ onIcons: () => Promise<InterfaceControlsIconSrc[]>;
26
+ onMemoryCleared: () => Promise<unknown[] | undefined>;
27
+ toggleUnvisibleControls: (isVisible: boolean) => Promise<unknown[]> | undefined;
28
+ getDefaultState: () => InterfaceControlsPluginState;
29
+ getOneIconSrcs: ({ icon, iconHover }?: InterfaceControlsIconItem) => Promise<InterfaceControlsIconSrc>;
30
+ }
@@ -0,0 +1,64 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ export class InterfaceControlsController extends ModuleController {
3
+ name = "interface.controls.controller";
4
+ updateEvent = this.EVENTS.INTERFACE_CONTROLS_VIEW.UPDATE;
5
+ controls = {
6
+ [this.CONST.CONTROLS.BUTTONS.INTERFACE_HIDE]: () => void this.emit(this.EVENTS.INTERFACE.VISIBLE),
7
+ [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => void this.emit(this.EVENTS.INTERFACE.INTERACT),
8
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => void this.emit(this.EVENTS.INTERFACE.VISIBLE),
9
+ };
10
+ controlsUnvisible = { [this.CONST.CONTROLS.BUTTONS.ANY]: () => void this.emit(this.EVENTS.INTERFACE.VISIBLE) };
11
+ controlsIndex = this.PARAMS.INTERFACE.ZINDEX + 100;
12
+ controlsCheckNext = true;
13
+ subscribe = () => {
14
+ this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.SHOW, this.onShow);
15
+ this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.HIDE, this.onHide);
16
+ this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.CLICK, this.onClick);
17
+ this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.ICONS, this.onIcons);
18
+ this.on(this.EVENTS.INTERFACE.SHOW_CHANGED, this.onShowChanged);
19
+ this.on(this.EVENTS.INTERFACE.VIEW_CHANGED, this.onViewChanged);
20
+ this.on(this.EVENTS.INTERFACE.STATE_CHANGED, this.onStateChanged);
21
+ this.on(this.EVENTS.INTERFACE.VISIBLE_CHANGED, this.onVisibleChanged);
22
+ this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
23
+ };
24
+ init = () => {
25
+ Object.assign(this.controls, this.PARAMS.INTERFACE_CONTROLS_VIEW.CONTROLS_EXTENSIONS);
26
+ };
27
+ beforeShow = async () => this.updateState({ icons: (await this.emitOne(this.EVENTS.INTERFACE_CONTROLS_VIEW.ICONS)) });
28
+ onShowChanged = ({ isForce = false } = {}) => {
29
+ const { isShow = false } = this.globalState.interface;
30
+ const event = isShow ? this.EVENTS.INTERFACE_CONTROLS_VIEW.SHOW : this.EVENTS.INTERFACE_CONTROLS_VIEW.HIDE;
31
+ return this.state.isShow !== isShow && this.emit(event, { isForce });
32
+ };
33
+ onViewChanged = ({ isForce = false } = {}) => {
34
+ const { view = "" } = this.globalState.interface;
35
+ return this.state.view !== view && this.updateStateAndView({ view }, isForce, !isForce);
36
+ };
37
+ onVisibleChanged = async ({ isForce = false } = {}) => {
38
+ const { isVisible = false } = this.globalState.interface;
39
+ this.toggleUnvisibleControls(isVisible);
40
+ return this.state.isVisible !== isVisible && this.updateStateAndView({ isVisible }, isForce, !isForce);
41
+ };
42
+ onStateChanged = () => {
43
+ const { isShow = false, isVisible = false, view = "" } = this.globalState.interface;
44
+ this.toggleUnvisibleControls(isVisible);
45
+ return this.updateStateAndViewForce({ isVisible, isShow, view });
46
+ };
47
+ onClick = ({ index = 0 } = {}) => this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS[index]?.onClick?.(this);
48
+ onIcons = () => Promise.all(this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS.map(this.getOneIconSrcs));
49
+ onMemoryCleared = async () => this.updateStateAndViewFast({ icons: (await this.emitOne(this.EVENTS.INTERFACE_CONTROLS_VIEW.ICONS)) });
50
+ toggleUnvisibleControls = (isVisible) => {
51
+ const args = { key: `${this.name}-unvisible`, controls: this.controlsUnvisible, index: this.controlsIndex + 500 };
52
+ return this.emit(isVisible ? this.EVENTS.CONTROLS.POP : this.EVENTS.CONTROLS.PUSH, args);
53
+ };
54
+ getDefaultState = () => ({ isShow: false, isVisible: false, isForce: false, view: "" });
55
+ getOneIconSrcs = async ({ icon = "", iconHover = "" } = {}) => {
56
+ const result = {};
57
+ const quality = this.shared.settings[this.SETTINGS.LAYER.QUALITY];
58
+ if (icon)
59
+ result.src = (await this.loadImageMedia(`interface/${icon}`, "icons", quality)).src;
60
+ if (iconHover)
61
+ result.srcHover = (await this.loadImageMedia(`interface/${iconHover}`, "icons", quality)).src;
62
+ return result;
63
+ };
64
+ }
@@ -0,0 +1,10 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { InterfaceControlsPluginConstants, InterfaceControlsPluginEvents, InterfaceControlsPluginParams, InterfaceControlsPluginSettings } from "../types.js";
3
+ import type { InterfaceControlsPluginState } from "../utils/interface.controls.js";
4
+ export declare class InterfaceControlsView extends ModuleView<InterfaceControlsPluginEvents, InterfaceControlsPluginConstants, InterfaceControlsPluginSettings, InterfaceControlsPluginParams, InterfaceControlsPluginState> {
5
+ name: string;
6
+ animationTime: number;
7
+ updateEvent: "vne:interface_controls:update";
8
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<InterfaceControlsPluginState>;
9
+ updateHandler: (state?: InterfaceControlsPluginState | 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 InterfaceControlsView extends ModuleView {
4
+ name = "interface.controls.view";
5
+ animationTime = this.PARAMS.INTERFACE.TRANSITION;
6
+ updateEvent = this.EVENTS.INTERFACE_CONTROLS_VIEW.UPDATE;
7
+ renderFunc = render;
8
+ updateHandler = this.onUpdateStoreComponent;
9
+ }
@@ -0,0 +1,10 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { SettingsKeys as LayerSettingsKeys, PluginName as LayerPluginName } from "@vnejs/plugins.canvas.layer.contract";
3
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName, SubscribeEvents as ControlsSubscribeEvents } from "@vnejs/plugins.controls.contract";
4
+ import type { PluginName as MemoryPluginName, SubscribeEvents as MemorySubscribeEvents } from "@vnejs/plugins.core.memory.contract";
5
+ import type { Params as InterfaceParams, PluginName as InterfacePluginName, SubscribeEvents as InterfaceSubscribeEvents } from "@vnejs/plugins.views.scenario.interface.contract";
6
+ import type { Params, PluginName, SubscribeEvents } from "@vnejs/plugins.views.scenario.interface.controls.contract";
7
+ export type InterfaceControlsPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<InterfacePluginName, InterfaceSubscribeEvents> & Record<ControlsPluginName, ControlsSubscribeEvents> & Record<MemoryPluginName, MemorySubscribeEvents>;
8
+ export type InterfaceControlsPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
9
+ export type InterfaceControlsPluginSettings = ModuleComponentsSettings & Record<LayerPluginName, LayerSettingsKeys>;
10
+ export type InterfaceControlsPluginParams = ModuleComponentsParams & Record<PluginName, Params> & Record<InterfacePluginName, InterfaceParams>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { ModuleController } from "@vnejs/module.components";
2
+ import type { InterfaceControlsIconItem } from "@vnejs/plugins.views.scenario.interface.controls.contract";
3
+ import type { InterfaceControlsPluginConstants, InterfaceControlsPluginEvents, InterfaceControlsPluginParams, InterfaceControlsPluginSettings } from "../types.js";
4
+ export type InterfaceControlsController = ModuleController<InterfaceControlsPluginEvents, InterfaceControlsPluginConstants, InterfaceControlsPluginSettings, InterfaceControlsPluginParams, InterfaceControlsPluginState>;
5
+ export type { InterfaceControlsIconItem };
6
+ export type InterfaceControlsIconSrc = {
7
+ src?: string;
8
+ srcHover?: string;
9
+ };
10
+ export type InterfaceControlsPluginState = {
11
+ isShow: boolean;
12
+ isVisible: boolean;
13
+ isForce: boolean;
14
+ view: string;
15
+ icons?: InterfaceControlsIconSrc[];
16
+ };
17
+ export type InterfaceControlsClickPayload = {
18
+ index?: number;
19
+ };
20
+ export type InterfaceControlsForcePayload = {
21
+ isForce?: boolean;
22
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { InterfaceControlsPluginState } from "../utils/interface.controls.js";
3
+ export declare const render: ViewRenderFunc<InterfaceControlsPluginState>;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createElement as _createElement } from "react";
3
+ import { Flex, Icon, View, createRenderFunc, useCallback, useIsForceHook, useMemo, useStoreState } from "@vnejs/uis.react";
4
+ const renderIcon = ({ src, srcHover, props }, i) => (_createElement(Icon, { ...props, srcHover: srcHover, src: src, value: i, key: src }));
5
+ const InterfaceControls = ({ store, onMount, emit, EVENTS, PARAMS }) => {
6
+ const { isShow = false, isVisible = false, isForce = false, view = "", icons = [] } = useStoreState(store, onMount);
7
+ const isRealForce = useIsForceHook(isForce);
8
+ const onClick = useCallback((index = 0) => emit(EVENTS.INTERFACE_CONTROLS_VIEW.CLICK, { index }), [emit, EVENTS.INTERFACE_CONTROLS_VIEW.CLICK]);
9
+ const transition = isRealForce ? 0 : PARAMS.INTERFACE.TRANSITION;
10
+ const propsByView = useMemo(() => PARAMS.INTERFACE_CONTROLS_VIEW.VIEW_PROPS[view] || {}, [view, PARAMS.INTERFACE_CONTROLS_VIEW.VIEW_PROPS]);
11
+ const propsIcon = useMemo(() => ({ ...propsByView.icon, transition, onClick }), [propsByView, transition, onClick]);
12
+ const propsView = useMemo(() => ({ ...propsByView.view, isShow, isForce: isRealForce, transition }), [propsByView, isShow, isRealForce, transition]);
13
+ const iconsWithProps = useMemo(() => icons.map(({ src, srcHover }) => ({ src, srcHover, props: propsIcon })), [icons, propsIcon]);
14
+ return (_jsx(View, { ...propsView, isHidden: !isVisible, zIndex: PARAMS.INTERFACE.ZINDEX + 100, children: _jsx(Flex, { ...propsByView.flex, children: iconsWithProps.map(renderIcon) }) }));
15
+ };
16
+ export const render = createRenderFunc(InterfaceControls);
package/package.json CHANGED
@@ -1,17 +1,49 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.scenario.interface.controls",
3
- "version": "0.1.2",
4
- "main": "index.js",
3
+ "version": "0.1.4",
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": "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"
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
- "description": ""
32
+ "dependencies": {
33
+ "@vnejs/plugins.views.scenario.interface.controls.contract": "~0.0.1",
34
+ "@vnejs/plugins.views.scenario.interface.contract": "~0.0.1"
35
+ },
36
+ "peerDependencies": {
37
+ "@vnejs/helpers": "~0.1.0",
38
+ "@vnejs/module": "~0.0.1",
39
+ "@vnejs/module.components": "~0.0.1",
40
+ "@vnejs/plugins.canvas.layer.contract": "~0.0.1",
41
+ "@vnejs/plugins.controls.contract": "~0.0.1",
42
+ "@vnejs/plugins.core.memory.contract": "~0.0.1",
43
+ "@vnejs/shared": "~0.0.9",
44
+ "@vnejs/uis.react": "~0.1.0"
45
+ },
46
+ "devDependencies": {
47
+ "@vnejs/configs.ts-common": "~0.0.1"
48
+ }
17
49
  }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ import "@vnejs/plugins.views.scenario.interface.controls.contract";
2
+
3
+ import { regPlugin } from "@vnejs/shared";
4
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.views.scenario.interface.controls.contract";
5
+
6
+ import { InterfaceControlsController } from "./modules/controller.js";
7
+ import { InterfaceControlsView } from "./modules/view.js";
8
+
9
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [InterfaceControlsController, InterfaceControlsView]);
@@ -1,15 +1,30 @@
1
1
  import { ModuleController } from "@vnejs/module.components";
2
2
 
3
- export class InterfaceControlsController extends ModuleController {
3
+ import type { InterfaceControlsPluginConstants, InterfaceControlsPluginEvents, InterfaceControlsPluginParams, InterfaceControlsPluginSettings } from "../types.js";
4
+ import type {
5
+ InterfaceControlsClickPayload,
6
+ InterfaceControlsForcePayload,
7
+ InterfaceControlsIconItem,
8
+ InterfaceControlsIconSrc,
9
+ InterfaceControlsPluginState,
10
+ } from "../utils/interface.controls.js";
11
+
12
+ export class InterfaceControlsController extends ModuleController<
13
+ InterfaceControlsPluginEvents,
14
+ InterfaceControlsPluginConstants,
15
+ InterfaceControlsPluginSettings,
16
+ InterfaceControlsPluginParams,
17
+ InterfaceControlsPluginState
18
+ > {
4
19
  name = "interface.controls.controller";
5
20
 
6
21
  updateEvent = this.EVENTS.INTERFACE_CONTROLS_VIEW.UPDATE;
7
22
  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),
23
+ [this.CONST.CONTROLS.BUTTONS.INTERFACE_HIDE]: () => void this.emit(this.EVENTS.INTERFACE.VISIBLE),
24
+ [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => void this.emit(this.EVENTS.INTERFACE.INTERACT),
25
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => void this.emit(this.EVENTS.INTERFACE.VISIBLE),
11
26
  };
12
- controlsUnvisible = { [this.CONST.CONTROLS.BUTTONS.ANY]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE) };
27
+ controlsUnvisible = { [this.CONST.CONTROLS.BUTTONS.ANY]: () => void this.emit(this.EVENTS.INTERFACE.VISIBLE) };
13
28
  controlsIndex = this.PARAMS.INTERFACE.ZINDEX + 100;
14
29
  controlsCheckNext = true;
15
30
 
@@ -26,22 +41,25 @@ export class InterfaceControlsController extends ModuleController {
26
41
 
27
42
  this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
28
43
  };
29
- init = () => Object.assign(this.controls, this.PARAMS.INTERFACE_CONTROLS_VIEW.CONTROLS_EXTENSIONS);
44
+ init = () => {
45
+ Object.assign(this.controls, this.PARAMS.INTERFACE_CONTROLS_VIEW.CONTROLS_EXTENSIONS);
46
+ };
30
47
 
31
- beforeShow = async () => this.updateState({ icons: await this.emitOne(this.EVENTS.INTERFACE_CONTROLS_VIEW.ICONS) });
48
+ beforeShow = async () =>
49
+ this.updateState({ icons: (await this.emitOne(this.EVENTS.INTERFACE_CONTROLS_VIEW.ICONS)) as InterfaceControlsIconSrc[] });
32
50
 
33
- onShowChanged = ({ isForce = false } = {}) => {
51
+ onShowChanged = ({ isForce = false }: InterfaceControlsForcePayload = {}) => {
34
52
  const { isShow = false } = this.globalState.interface;
35
53
  const event = isShow ? this.EVENTS.INTERFACE_CONTROLS_VIEW.SHOW : this.EVENTS.INTERFACE_CONTROLS_VIEW.HIDE;
36
54
 
37
55
  return this.state.isShow !== isShow && this.emit(event, { isForce });
38
56
  };
39
- onViewChanged = ({ isForce = false } = {}) => {
57
+ onViewChanged = ({ isForce = false }: InterfaceControlsForcePayload = {}) => {
40
58
  const { view = "" } = this.globalState.interface;
41
59
 
42
60
  return this.state.view !== view && this.updateStateAndView({ view }, isForce, !isForce);
43
61
  };
44
- onVisibleChanged = async ({ isForce = false } = {}) => {
62
+ onVisibleChanged = async ({ isForce = false }: InterfaceControlsForcePayload = {}) => {
45
63
  const { isVisible = false } = this.globalState.interface;
46
64
 
47
65
  this.toggleUnvisibleControls(isVisible);
@@ -56,21 +74,24 @@ export class InterfaceControlsController extends ModuleController {
56
74
  return this.updateStateAndViewForce({ isVisible, isShow, view });
57
75
  };
58
76
 
59
- onClick = ({ index = 0 } = {}) => this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS?.[index]?.onClick(this);
77
+ onClick = ({ index = 0 }: InterfaceControlsClickPayload = {}) => this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS[index]?.onClick?.(this);
78
+
60
79
  onIcons = () => Promise.all(this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS.map(this.getOneIconSrcs));
61
80
 
62
- onMemoryCleared = async () => this.updateStateAndViewFast({ icons: await this.emitOne(this.EVENTS.INTERFACE_CONTROLS_VIEW.ICONS) });
81
+ onMemoryCleared = async () =>
82
+ this.updateStateAndViewFast({ icons: (await this.emitOne(this.EVENTS.INTERFACE_CONTROLS_VIEW.ICONS)) as InterfaceControlsIconSrc[] });
63
83
 
64
- toggleUnvisibleControls = (isVisible) => {
84
+ toggleUnvisibleControls = (isVisible: boolean) => {
65
85
  const args = { key: `${this.name}-unvisible`, controls: this.controlsUnvisible, index: this.controlsIndex + 500 };
66
86
 
67
87
  return this.emit(isVisible ? this.EVENTS.CONTROLS.POP : this.EVENTS.CONTROLS.PUSH, args);
68
88
  };
69
89
 
70
- getDefaultState = () => ({ isShow: false, isVisible: false, view: "" });
90
+ getDefaultState = (): InterfaceControlsPluginState => ({ isShow: false, isVisible: false, isForce: false, view: "" });
71
91
 
72
- getOneIconSrcs = async ({ icon = "", iconHover = "" } = {}) => {
73
- const [result, quality] = [{}, this.shared.settings[this.SETTINGS.LAYER.QUALITY]];
92
+ getOneIconSrcs = async ({ icon = "", iconHover = "" }: InterfaceControlsIconItem = {}): Promise<InterfaceControlsIconSrc> => {
93
+ const result: InterfaceControlsIconSrc = {};
94
+ const quality = this.shared.settings[this.SETTINGS.LAYER.QUALITY];
74
95
 
75
96
  if (icon) result.src = (await this.loadImageMedia(`interface/${icon}`, "icons", quality)).src;
76
97
  if (iconHover) result.srcHover = (await this.loadImageMedia(`interface/${iconHover}`, "icons", quality)).src;
@@ -0,0 +1,21 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import { render } from "../view/index.js";
4
+ import type { InterfaceControlsPluginConstants, InterfaceControlsPluginEvents, InterfaceControlsPluginParams, InterfaceControlsPluginSettings } from "../types.js";
5
+ import type { InterfaceControlsPluginState } from "../utils/interface.controls.js";
6
+
7
+ export class InterfaceControlsView extends ModuleView<
8
+ InterfaceControlsPluginEvents,
9
+ InterfaceControlsPluginConstants,
10
+ InterfaceControlsPluginSettings,
11
+ InterfaceControlsPluginParams,
12
+ InterfaceControlsPluginState
13
+ > {
14
+ name = "interface.controls.view";
15
+
16
+ animationTime = this.PARAMS.INTERFACE.TRANSITION;
17
+ updateEvent = this.EVENTS.INTERFACE_CONTROLS_VIEW.UPDATE;
18
+
19
+ renderFunc = render;
20
+ updateHandler = this.onUpdateStoreComponent;
21
+ }
package/src/types.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { SettingsKeys as LayerSettingsKeys, PluginName as LayerPluginName } from "@vnejs/plugins.canvas.layer.contract";
3
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName, SubscribeEvents as ControlsSubscribeEvents } from "@vnejs/plugins.controls.contract";
4
+ import type { PluginName as MemoryPluginName, SubscribeEvents as MemorySubscribeEvents } from "@vnejs/plugins.core.memory.contract";
5
+ import type { Params as InterfaceParams, PluginName as InterfacePluginName, SubscribeEvents as InterfaceSubscribeEvents } from "@vnejs/plugins.views.scenario.interface.contract";
6
+ import type { Params, PluginName, SubscribeEvents } from "@vnejs/plugins.views.scenario.interface.controls.contract";
7
+
8
+ export type InterfaceControlsPluginEvents = ModuleComponentsEvents &
9
+ Record<PluginName, SubscribeEvents> &
10
+ Record<InterfacePluginName, InterfaceSubscribeEvents> &
11
+ Record<ControlsPluginName, ControlsSubscribeEvents> &
12
+ Record<MemoryPluginName, MemorySubscribeEvents>;
13
+
14
+ export type InterfaceControlsPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
15
+
16
+ export type InterfaceControlsPluginSettings = ModuleComponentsSettings & Record<LayerPluginName, LayerSettingsKeys>;
17
+
18
+ export type InterfaceControlsPluginParams = ModuleComponentsParams &
19
+ Record<PluginName, Params> &
20
+ Record<InterfacePluginName, InterfaceParams>;
@@ -0,0 +1,35 @@
1
+ import type { ModuleController } from "@vnejs/module.components";
2
+ import type { InterfaceControlsIconItem } from "@vnejs/plugins.views.scenario.interface.controls.contract";
3
+
4
+ import type { InterfaceControlsPluginConstants, InterfaceControlsPluginEvents, InterfaceControlsPluginParams, InterfaceControlsPluginSettings } from "../types.js";
5
+
6
+ export type InterfaceControlsController = ModuleController<
7
+ InterfaceControlsPluginEvents,
8
+ InterfaceControlsPluginConstants,
9
+ InterfaceControlsPluginSettings,
10
+ InterfaceControlsPluginParams,
11
+ InterfaceControlsPluginState
12
+ >;
13
+
14
+ export type { InterfaceControlsIconItem };
15
+
16
+ export type InterfaceControlsIconSrc = {
17
+ src?: string;
18
+ srcHover?: string;
19
+ };
20
+
21
+ export type InterfaceControlsPluginState = {
22
+ isShow: boolean;
23
+ isVisible: boolean;
24
+ isForce: boolean;
25
+ view: string;
26
+ icons?: InterfaceControlsIconSrc[];
27
+ };
28
+
29
+ export type InterfaceControlsClickPayload = {
30
+ index?: number;
31
+ };
32
+
33
+ export type InterfaceControlsForcePayload = {
34
+ isForce?: boolean;
35
+ };
@@ -0,0 +1,64 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { ReactComponentProps } from "@vnejs/uis.react";
3
+ import { Flex, Icon, View, createRenderFunc, useCallback, useIsForceHook, useMemo, useStoreState } from "@vnejs/uis.react";
4
+
5
+ import type {
6
+ InterfaceControlsPluginConstants,
7
+ InterfaceControlsPluginEvents,
8
+ InterfaceControlsPluginParams,
9
+ InterfaceControlsPluginSettings,
10
+ } from "../types.js";
11
+ import type { InterfaceControlsIconSrc, InterfaceControlsPluginState } from "../utils/interface.controls.js";
12
+
13
+ type InterfaceControlsComponentProps = ReactComponentProps<
14
+ InterfaceControlsPluginEvents,
15
+ InterfaceControlsPluginConstants,
16
+ InterfaceControlsPluginSettings,
17
+ InterfaceControlsPluginParams,
18
+ InterfaceControlsPluginState
19
+ >;
20
+
21
+ type IconWithProps = InterfaceControlsIconSrc & {
22
+ props: Record<string, unknown>;
23
+ };
24
+
25
+ const renderIcon = ({ src, srcHover, props }: IconWithProps, i: number) => (
26
+ <Icon
27
+ {...props}
28
+ srcHover={srcHover}
29
+ src={src}
30
+ value={i}
31
+ key={src}
32
+ />
33
+ );
34
+
35
+ const InterfaceControls = ({ store, onMount, emit, EVENTS, PARAMS }: InterfaceControlsComponentProps) => {
36
+ const { isShow = false, isVisible = false, isForce = false, view = "", icons = [] } = useStoreState<InterfaceControlsPluginState>(store, onMount);
37
+
38
+ const isRealForce = useIsForceHook(isForce);
39
+
40
+ const onClick = useCallback((index = 0) => emit(EVENTS.INTERFACE_CONTROLS_VIEW.CLICK, { index }), [emit, EVENTS.INTERFACE_CONTROLS_VIEW.CLICK]);
41
+
42
+ const transition = isRealForce ? 0 : PARAMS.INTERFACE.TRANSITION;
43
+
44
+ const propsByView = useMemo(
45
+ () => PARAMS.INTERFACE_CONTROLS_VIEW.VIEW_PROPS[view as keyof typeof PARAMS.INTERFACE_CONTROLS_VIEW.VIEW_PROPS] || {},
46
+ [view, PARAMS.INTERFACE_CONTROLS_VIEW.VIEW_PROPS],
47
+ );
48
+ const propsIcon = useMemo(() => ({ ...propsByView.icon, transition, onClick }), [propsByView, transition, onClick]);
49
+ const propsView = useMemo(() => ({ ...propsByView.view, isShow, isForce: isRealForce, transition }), [propsByView, isShow, isRealForce, transition]);
50
+
51
+ const iconsWithProps = useMemo(() => icons.map(({ src, srcHover }) => ({ src, srcHover, props: propsIcon })), [icons, propsIcon]);
52
+
53
+ return (
54
+ <View
55
+ {...propsView}
56
+ isHidden={!isVisible}
57
+ zIndex={PARAMS.INTERFACE.ZINDEX + 100}
58
+ >
59
+ <Flex {...propsByView.flex}>{iconsWithProps.map(renderIcon)}</Flex>
60
+ </View>
61
+ );
62
+ };
63
+
64
+ export const render: ViewRenderFunc<InterfaceControlsPluginState> = createRenderFunc(InterfaceControls);
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"]
10
+ }
package/const/events.js DELETED
@@ -1,8 +0,0 @@
1
- export const SUBSCRIBE_EVENTS = {
2
- SHOW: "vne:interface_controls:show",
3
- HIDE: "vne:interface_controls:hide",
4
- UPDATE: "vne:interface_controls:update",
5
-
6
- CLICK: "vne:interface_controls:click",
7
- ICONS: "vne:interface_controls:icons",
8
- };
package/const/params.js DELETED
@@ -1,22 +0,0 @@
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 DELETED
@@ -1,9 +0,0 @@
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]);
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 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/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, 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} />);