@vnejs/plugins.views.cursor 0.1.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.
- package/index.js +6 -0
- package/modules/controller.js +28 -0
- package/modules/view.js +12 -0
- package/package.json +17 -0
- package/view/index.jsx +17 -0
package/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
|
|
14
|
+
this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
onViewSet = async ({ view } = {}) => {
|
|
18
|
+
this.updateState({ view });
|
|
19
|
+
|
|
20
|
+
return this.state.view && this.updateStateAndViewFast(await this.loadSrcs(this.state.view));
|
|
21
|
+
};
|
|
22
|
+
onMoved = () => this.updateStateAndViewFast({ x: this.globalState.cursor.x, y: this.globalState.cursor.y });
|
|
23
|
+
|
|
24
|
+
onMemoryCleared = async () => this.state.view && this.updateStateAndViewFast(await this.loadSrcs(this.state.view));
|
|
25
|
+
|
|
26
|
+
loadSrcs = async (view) => ({ srcDefault: (await this.loadIconMedia(view, "default")).src, srcPointer: (await this.loadIconMedia(view, "pointer")).src });
|
|
27
|
+
loadIconMedia = (view, type) => this.loadImageMedia(`cursor/${view}/${type}`, "icons", this.shared.settings[this.SETTINGS.LAYER.QUALITY]);
|
|
28
|
+
}
|
package/modules/view.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/plugins.views.cursor",
|
|
3
|
+
"version": "0.1.1",
|
|
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,17 @@
|
|
|
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} />);
|