@vnejs/plugins.views.cursor 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
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { PLUGIN_NAME } from "@vnejs/plugins.views.cursor.contract";
3
+ import { CursorController } from "./modules/controller.js";
4
+ import { CursorView } from "./modules/view.js";
5
+ regPlugin(PLUGIN_NAME, {}, [CursorController, CursorView]);
@@ -0,0 +1,13 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import type { CursorViewPluginConstants, CursorViewPluginEvents, CursorViewPluginParams, CursorViewPluginSettings } from "../types.js";
3
+ import type { CursorViewPluginState, CursorViewSetPayload } from "../utils/cursor.js";
4
+ export declare class CursorController extends ModuleController<CursorViewPluginEvents, CursorViewPluginConstants, CursorViewPluginSettings, CursorViewPluginParams, CursorViewPluginState> {
5
+ name: string;
6
+ updateEvent: "vne:cursor:update";
7
+ subscribe: () => void;
8
+ onViewSet: ({ view }?: CursorViewSetPayload) => Promise<unknown[] | undefined>;
9
+ onMoved: () => Promise<unknown[]> | undefined;
10
+ onMemoryCleared: () => "" | Promise<unknown[] | undefined> | undefined;
11
+ changeView: (view?: string) => Promise<unknown[] | undefined>;
12
+ loadIconMedia: (view: string, type: string) => Promise<HTMLImageElement>;
13
+ }
@@ -0,0 +1,26 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ export class CursorController extends ModuleController {
3
+ name = "cursor.controller";
4
+ updateEvent = this.EVENTS.CURSOR.UPDATE;
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.CURSOR.SHOW, this.onShow);
7
+ this.on(this.EVENTS.CURSOR.HIDE, this.onHide);
8
+ this.on(this.EVENTS.CURSOR.MOVED, this.onMoved);
9
+ this.on(this.EVENTS.CURSOR.VIEW_SET, this.onViewSet);
10
+ this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
11
+ };
12
+ onViewSet = ({ view } = {}) => {
13
+ this.updateState({ view });
14
+ return this.changeView(view);
15
+ };
16
+ onMoved = () => this.updateStateAndViewFast({ x: this.globalState.cursor.x, y: this.globalState.cursor.y });
17
+ onMemoryCleared = () => this.state.view && this.changeView(this.state.view);
18
+ changeView = async (view = "") => {
19
+ const [mediaDefault, mediaHover] = await Promise.all([this.loadIconMedia(view, "default"), this.loadIconMedia(view, "pointer")]);
20
+ return this.updateStateAndViewFast({
21
+ srcDefault: mediaDefault.src,
22
+ srcPointer: mediaHover.src,
23
+ });
24
+ };
25
+ loadIconMedia = (view, type) => this.loadImageMedia(`cursor/${view}/${type}`, "icons", this.shared.settings[this.SETTINGS.LAYER.QUALITY]);
26
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { CursorViewPluginConstants, CursorViewPluginEvents, CursorViewPluginParams, CursorViewPluginSettings } from "../types.js";
3
+ import type { CursorViewPluginState } from "../utils/cursor.js";
4
+ export declare class CursorView extends ModuleView<CursorViewPluginEvents, CursorViewPluginConstants, CursorViewPluginSettings, CursorViewPluginParams, CursorViewPluginState> {
5
+ name: string;
6
+ updateEvent: "vne:cursor:update";
7
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<CursorViewPluginState>;
8
+ updateHandler: (state?: CursorViewPluginState | undefined) => Promise<void>;
9
+ }
@@ -0,0 +1,8 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import { render } from "../view/index.js";
3
+ export class CursorView extends ModuleView {
4
+ name = "cursor.view";
5
+ updateEvent = this.EVENTS.CURSOR.UPDATE;
6
+ renderFunc = render;
7
+ updateHandler = this.onUpdateStoreComponent;
8
+ }
@@ -0,0 +1,7 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { PluginName as CursorPluginName, SubscribeEvents as CursorSubscribeEvents } from "@vnejs/plugins.controls.cursor.contract";
3
+ import type { PluginName as MemoryPluginName, SubscribeEvents as MemorySubscribeEvents } from "@vnejs/plugins.core.memory.contract";
4
+ export type CursorViewPluginEvents = ModuleComponentsEvents & Record<CursorPluginName, CursorSubscribeEvents> & Record<MemoryPluginName, MemorySubscribeEvents>;
5
+ export type CursorViewPluginConstants = ModuleComponentsConstants;
6
+ export type CursorViewPluginSettings = ModuleComponentsSettings;
7
+ export type CursorViewPluginParams = ModuleComponentsParams;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ export type CursorViewPluginState = {
2
+ isShow: boolean;
3
+ isForce: boolean;
4
+ x?: number;
5
+ y?: number;
6
+ view?: string;
7
+ srcDefault?: string;
8
+ srcPointer?: string;
9
+ };
10
+ export type CursorViewSetPayload = {
11
+ view?: string;
12
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { CursorViewPluginState } from "../utils/cursor.js";
3
+ export declare const render: ViewRenderFunc<CursorViewPluginState>;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Cursor, createRenderFunc, useMemo, useStoreState } from "@vnejs/uis.react";
3
+ const CursorViewComponent = ({ store, onMount }) => {
4
+ const { isShow = false, x = 0, y = 0, srcDefault = "", srcPointer = "" } = useStoreState(store, onMount);
5
+ const propsCursor = useMemo(() => ({ isShow, forceX: x, forceY: y, srcDefault, srcPointer }), [isShow, x, y, srcDefault, srcPointer]);
6
+ return _jsx(Cursor, { ...propsCursor });
7
+ };
8
+ export const render = createRenderFunc(CursorViewComponent);
package/package.json CHANGED
@@ -1,17 +1,46 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.cursor",
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.cursor.contract": "~0.0.1"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/module.components": "~0.0.1",
37
+ "@vnejs/plugins.controls.cursor.contract": "~0.0.1",
38
+ "@vnejs/plugins.core.components.contract": "~0.0.1",
39
+ "@vnejs/plugins.core.memory.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,7 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { PLUGIN_NAME } from "@vnejs/plugins.views.cursor.contract";
3
+
4
+ import { CursorController } from "./modules/controller.js";
5
+ import { CursorView } from "./modules/view.js";
6
+
7
+ regPlugin(PLUGIN_NAME, {}, [CursorController, CursorView]);
@@ -0,0 +1,46 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ import type { CursorViewPluginConstants, CursorViewPluginEvents, CursorViewPluginParams, CursorViewPluginSettings } from "../types.js";
4
+ import type { CursorViewPluginState, CursorViewSetPayload } from "../utils/cursor.js";
5
+
6
+ export class CursorController extends ModuleController<
7
+ CursorViewPluginEvents,
8
+ CursorViewPluginConstants,
9
+ CursorViewPluginSettings,
10
+ CursorViewPluginParams,
11
+ CursorViewPluginState
12
+ > {
13
+ name = "cursor.controller";
14
+
15
+ updateEvent = this.EVENTS.CURSOR.UPDATE;
16
+
17
+ subscribe = () => {
18
+ this.on(this.EVENTS.CURSOR.SHOW, this.onShow);
19
+ this.on(this.EVENTS.CURSOR.HIDE, this.onHide);
20
+ this.on(this.EVENTS.CURSOR.MOVED, this.onMoved);
21
+ this.on(this.EVENTS.CURSOR.VIEW_SET, this.onViewSet);
22
+ this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
23
+ };
24
+
25
+ onViewSet = ({ view }: CursorViewSetPayload = {}) => {
26
+ this.updateState({ view });
27
+
28
+ return this.changeView(view);
29
+ };
30
+
31
+ onMoved = () => this.updateStateAndViewFast({ x: this.globalState.cursor.x, y: this.globalState.cursor.y });
32
+
33
+ onMemoryCleared = () => this.state.view && this.changeView(this.state.view);
34
+
35
+ changeView = async (view = "") => {
36
+ const [mediaDefault, mediaHover] = await Promise.all([this.loadIconMedia(view, "default"), this.loadIconMedia(view, "pointer")]);
37
+
38
+ return this.updateStateAndViewFast({
39
+ srcDefault: mediaDefault.src,
40
+ srcPointer: mediaHover.src,
41
+ });
42
+ };
43
+
44
+ loadIconMedia = (view: string, type: string) =>
45
+ this.loadImageMedia(`cursor/${view}/${type}`, "icons", this.shared.settings[this.SETTINGS.LAYER.QUALITY]);
46
+ }
@@ -0,0 +1,20 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import { render } from "../view/index.js";
4
+ import type { CursorViewPluginConstants, CursorViewPluginEvents, CursorViewPluginParams, CursorViewPluginSettings } from "../types.js";
5
+ import type { CursorViewPluginState } from "../utils/cursor.js";
6
+
7
+ export class CursorView extends ModuleView<
8
+ CursorViewPluginEvents,
9
+ CursorViewPluginConstants,
10
+ CursorViewPluginSettings,
11
+ CursorViewPluginParams,
12
+ CursorViewPluginState
13
+ > {
14
+ name = "cursor.view";
15
+
16
+ updateEvent = this.EVENTS.CURSOR.UPDATE;
17
+
18
+ renderFunc = render;
19
+ updateHandler = this.onUpdateStoreComponent;
20
+ }
package/src/types.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { PluginName as CursorPluginName, SubscribeEvents as CursorSubscribeEvents } from "@vnejs/plugins.controls.cursor.contract";
3
+ import type { PluginName as MemoryPluginName, SubscribeEvents as MemorySubscribeEvents } from "@vnejs/plugins.core.memory.contract";
4
+
5
+ export type CursorViewPluginEvents = ModuleComponentsEvents & Record<CursorPluginName, CursorSubscribeEvents> & Record<MemoryPluginName, MemorySubscribeEvents>;
6
+
7
+ export type CursorViewPluginConstants = ModuleComponentsConstants;
8
+
9
+ export type CursorViewPluginSettings = ModuleComponentsSettings;
10
+
11
+ export type CursorViewPluginParams = ModuleComponentsParams;
@@ -0,0 +1,13 @@
1
+ export type CursorViewPluginState = {
2
+ isShow: boolean;
3
+ isForce: boolean;
4
+ x?: number;
5
+ y?: number;
6
+ view?: string;
7
+ srcDefault?: string;
8
+ srcPointer?: string;
9
+ };
10
+
11
+ export type CursorViewSetPayload = {
12
+ view?: string;
13
+ };
@@ -0,0 +1,24 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { ReactComponentProps } from "@vnejs/uis.react";
3
+ import { Cursor, createRenderFunc, useMemo, useStoreState } from "@vnejs/uis.react";
4
+
5
+ import type { CursorViewPluginConstants, CursorViewPluginEvents, CursorViewPluginParams, CursorViewPluginSettings } from "../types.js";
6
+ import type { CursorViewPluginState } from "../utils/cursor.js";
7
+
8
+ type CursorViewComponentProps = ReactComponentProps<
9
+ CursorViewPluginEvents,
10
+ CursorViewPluginConstants,
11
+ CursorViewPluginSettings,
12
+ CursorViewPluginParams,
13
+ CursorViewPluginState
14
+ >;
15
+
16
+ const CursorViewComponent = ({ store, onMount }: CursorViewComponentProps) => {
17
+ const { isShow = false, x = 0, y = 0, srcDefault = "", srcPointer = "" } = useStoreState<CursorViewPluginState>(store, onMount);
18
+
19
+ const propsCursor = useMemo(() => ({ isShow, forceX: x, forceY: y, srcDefault, srcPointer }), [isShow, x, y, srcDefault, srcPointer]);
20
+
21
+ return <Cursor {...propsCursor} />;
22
+ };
23
+
24
+ export const render: ViewRenderFunc<CursorViewPluginState> = createRenderFunc(CursorViewComponent);
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/index.js DELETED
@@ -1,6 +0,0 @@
1
- import { regPlugin } from "@vnejs/shared";
2
-
3
- import { CursorController } from "./modules/controller";
4
- import { CursorView } from "./modules/view";
5
-
6
- regPlugin("CURSOR_VIEW", {}, [CursorController, CursorView]);
@@ -1,32 +0,0 @@
1
- import { ModuleController } from "@vnejs/module.components";
2
-
3
- export class CursorController extends ModuleController {
4
- name = "cursor.controller";
5
-
6
- updateEvent = this.EVENTS.CURSOR.UPDATE;
7
-
8
- subscribe = () => {
9
- this.on(this.EVENTS.CURSOR.SHOW, this.onShow);
10
- this.on(this.EVENTS.CURSOR.HIDE, this.onHide);
11
- this.on(this.EVENTS.CURSOR.MOVED, this.onMoved);
12
- this.on(this.EVENTS.CURSOR.VIEW_SET, this.onViewSet);
13
- this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
14
- };
15
-
16
- onViewSet = ({ view } = {}) => {
17
- this.updateState({ view });
18
-
19
- return this.changeView(view);
20
- };
21
- onMoved = () => this.updateStateAndViewFast({ x: this.globalState.cursor.x, y: this.globalState.cursor.y });
22
-
23
- onMemoryCleared = () => this.state.view && this.changeView(this.state.view);
24
-
25
- changeView = async (view) => {
26
- const [mediaDefault, mediaHover, uid] = await Promise.all([this.loadIconMedia(view, "default"), this.loadIconMedia(view, "pointer")]);
27
-
28
- return this.updateStateAndViewFast({ srcDefault: mediaDefault.src, srcPointer: mediaHover.src });
29
- };
30
-
31
- loadIconMedia = (view, type) => this.loadImageMedia(`cursor/${view}/${type}`, "icons", this.shared.settings[this.SETTINGS.LAYER.QUALITY]);
32
- }
package/modules/view.js DELETED
@@ -1,12 +0,0 @@
1
- import { ModuleView } from "@vnejs/module.components";
2
-
3
- import { render } from "../view";
4
-
5
- export class CursorView extends ModuleView {
6
- name = "cursor.view";
7
-
8
- updateEvent = this.EVENTS.CURSOR.UPDATE;
9
-
10
- renderFunc = render;
11
- updateHandler = this.onUpdateStoreComponent;
12
- }
package/view/index.jsx DELETED
@@ -1,17 +0,0 @@
1
- import { useEffect, useMemo, useState } from "react";
2
- import { createRoot } from "react-dom/client";
3
-
4
- import { Cursor } from "@vnejs/uis.react";
5
-
6
- const CursorView = ({ store, onMount } = {}) => {
7
- const [{ isShow = false, x = 0, y = 0, srcDefault = "", srcPointer = "" }, setState] = useState({});
8
-
9
- useEffect(() => store.subscribe(setState), []);
10
- useEffect(() => void onMount(), []);
11
-
12
- const propsCursor = useMemo(() => ({ isShow, forceX: x, forceY: y, srcDefault, srcPointer }), [isShow, x, y, srcDefault, srcPointer]);
13
-
14
- return <Cursor {...propsCursor} />;
15
- };
16
-
17
- export const render = (props, root) => createRoot(root).render(<CursorView {...props} />);