@vnejs/plugins.views.screens.loading 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,6 @@
1
+ export const SUBSCRIBE_EVENTS = {
2
+ SHOW: "vne:loading:show",
3
+ HIDE: "vne:loading:hide",
4
+ EMIT: "vne:loading:emit",
5
+ UPDATE: "vne:loading:update",
6
+ };
@@ -0,0 +1,13 @@
1
+ export const MIN_SHOW_TIME = 200;
2
+
3
+ export const BACKGROUND = "loading";
4
+
5
+ export const TRANSITION = 500;
6
+ export const ZINDEX = 10000;
7
+ export const LOC_LABEL = "loading";
8
+
9
+ export const VIEW_PROPS = {
10
+ position: { bottom: 120, right: 120 },
11
+ text: { size: 144 },
12
+ screen: { transition: TRANSITION, zIndex: ZINDEX },
13
+ };
package/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+
3
+ import { SUBSCRIBE_EVENTS } from "./const/events";
4
+ import * as params from "./const/params";
5
+
6
+ import { LoadingController } from "./modules/controller";
7
+ import { Loading } from "./modules/loading";
8
+ import { LoadingView } from "./modules/view";
9
+
10
+ regPlugin("LOADING", { events: SUBSCRIBE_EVENTS, params }, [LoadingController, Loading, LoadingView]);
@@ -0,0 +1,23 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ export class LoadingController extends ModuleController {
4
+ name = "loading.controller";
5
+
6
+ bgName = this.PARAMS.LOADING.BACKGROUND;
7
+ controls = {};
8
+ controlsIndex = this.PARAMS.LOADING.ZINDEX;
9
+ updateEvent = this.EVENTS.LOADING.UPDATE;
10
+
11
+ subscribe = () => {
12
+ this.on(this.EVENTS.LOADING.SHOW, this.onShow);
13
+ this.on(this.EVENTS.LOADING.HIDE, this.onHide);
14
+
15
+ this.on(this.EVENTS.SYSTEM.STARTED, this.loadBgMedia);
16
+
17
+ this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
18
+ };
19
+
20
+ beforeShow = async () => this.updateState({ bgSrc: (await this.loadBgMedia()).src });
21
+
22
+ onMemoryCleared = async () => this.updateStateAndViewFast({ bgSrc: (await this.loadBgMedia()).src });
23
+ }
@@ -0,0 +1,17 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ export class Loading extends Module {
4
+ name = "loading";
5
+
6
+ subscribe = () => {
7
+ this.on(this.EVENTS.LOADING.EMIT, this.onLoadingEmit);
8
+ };
9
+
10
+ onLoadingEmit = async ({ promiseFunc } = {}) => {
11
+ this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "start" } });
12
+ await this.emit(this.EVENTS.LOADING.SHOW);
13
+ await Promise.all([promiseFunc(), this.waitTimeout(this.PARAMS.LOADING.MIN_SHOW_TIME)]);
14
+ await this.emit(this.EVENTS.LOADING.HIDE);
15
+ this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "finish" } });
16
+ };
17
+ }
@@ -0,0 +1,14 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import { render } from "../view";
4
+
5
+ export class LoadingView extends ModuleView {
6
+ name = "loading.view";
7
+
8
+ locLabel = this.PARAMS.LOADING.LOC_LABEL;
9
+ animationTime = this.PARAMS.LOADING.TRANSITION;
10
+ updateEvent = this.EVENTS.LOADING.UPDATE;
11
+
12
+ renderFunc = render;
13
+ updateHandler = this.onUpdateStoreComponent;
14
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@vnejs/plugins.views.screens.loading",
3
+ "version": "0.1.4",
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,24 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+
4
+ import { PositionBox, Screen, Text } from "@vnejs/uis.react";
5
+
6
+ const Loading = ({ store, onMount, ...props }) => {
7
+ const [{ isShow = false, isForce = false, bgSrc = "", locs = {} }, setState] = useState({});
8
+
9
+ useEffect(() => store.subscribe(setState), []);
10
+ useEffect(() => void onMount(), []);
11
+
12
+ const propsText = useMemo(() => ({ ...props.PARAMS.LOADING.VIEW_PROPS.text, text: locs.text }), [locs]);
13
+ const propsScreen = useMemo(() => ({ ...props.PARAMS.LOADING.VIEW_PROPS.screen, bgSrc, isShow, isForce }), [bgSrc, isShow, isForce]);
14
+
15
+ return (
16
+ <Screen {...propsScreen}>
17
+ <PositionBox {...props.PARAMS.LOADING.VIEW_PROPS.position}>
18
+ <Text {...propsText} />
19
+ </PositionBox>
20
+ </Screen>
21
+ );
22
+ };
23
+
24
+ export const render = (props, root) => createRoot(root).render(<Loading {...props} />);