@vnejs/plugins.core.components 0.0.1 → 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.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import * as constants from "./const/const";
2
+ import { SUBSCRIBE_EVENTS } from "./const/events";
3
+ import { SETTINGS_KEYS } from "./const/settings";
4
+
5
+ type SubscribeEventsType = typeof SUBSCRIBE_EVENTS;
6
+ type SettingsKeysType = typeof SETTINGS_KEYS;
7
+ type ConstantsType = typeof constants;
8
+
9
+ const PLUGIN_NAME = "COMPONENTS";
10
+
11
+ declare global {
12
+ interface EVENTS {
13
+ [PLUGIN_NAME]: SubscribeEventsType;
14
+ }
15
+ }
package/index.js CHANGED
@@ -1,14 +1,7 @@
1
1
  import { regPlugin } from "@vnejs/shared";
2
- import { Module } from "@vnejs/module";
3
2
 
4
3
  import { SUBSCRIBE_EVENTS } from "./const/events";
5
4
 
6
5
  import { Components } from "./modules/components";
7
6
 
8
7
  regPlugin("COMPONENTS", { events: SUBSCRIBE_EVENTS }, [Components]);
9
-
10
- import { ModuleView } from "./extensions/view";
11
- import { ModuleController } from "./extensions/controller";
12
-
13
- Module.View = ModuleView;
14
- Module.Controller = ModuleController;
@@ -8,8 +8,7 @@ export class Components extends Module {
8
8
  };
9
9
 
10
10
  init = async () => {
11
- this.props = { emit: this.emit, on: this.on, shared: this.shared, media: this.media, options: this.options };
12
- Object.assign(this.props, { SETTINGS: this.SETTINGS, CONST: this.CONST, EVENTS: this.EVENTS });
11
+ this.props = { emit: this.emit, shared: this.shared, SETTINGS: this.SETTINGS, CONST: this.CONST, EVENTS: this.EVENTS, PARAMS: this.PARAMS };
13
12
 
14
13
  this.shared.viewForceAnimationSources = [];
15
14
 
@@ -21,16 +20,13 @@ export class Components extends Module {
21
20
  await this.waitRender();
22
21
  };
23
22
 
24
- onComponentsReg = async ({ renderFunc } = {}) => {
23
+ onComponentsReg = async ({ renderFunc, store } = {}) => {
25
24
  await this.waitIsReady();
26
25
 
27
26
  let comp = null;
28
27
 
29
- await new Promise(async (resolve) => {
30
- const root = document.createElement("div");
31
-
32
- comp = renderFunc(this.props, root, resolve);
33
- [...root.children].forEach((child) => this.elem.appendChild(child));
28
+ await new Promise((resolve) => {
29
+ comp = renderFunc({ ...this.props, onMount: resolve, store }, this.elem.appendChild(document.createElement("div")), resolve);
34
30
  });
35
31
 
36
32
  return comp;
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.core.components",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
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",
7
10
  "publish:major": "npm version major && npm publish --access public",
8
11
  "publish:minor": "npm version minor && npm publish --access public",
9
12
  "publish:patch": "npm version patch && npm publish --access public"
10
13
  },
11
14
  "author": "",
12
15
  "license": "ISC",
13
- "description": "",
14
- "peerDependencies": {
15
- "@vnejs/shared": "*",
16
- "@vnejs/module": "*"
17
- }
16
+ "description": ""
18
17
  }
@@ -1,97 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
-
3
- export class ModuleController extends Module {
4
- isEmitNextAfterHide = false;
5
-
6
- currentItem = null;
7
- maxCurrentItem = 0;
8
-
9
- beforeShow = null;
10
- afterShow = null;
11
- beforeHide = null;
12
- afterHide = null;
13
-
14
- bgName = null;
15
- updateEvent = null;
16
-
17
- controls = null;
18
- controlsIndex = 0;
19
- controlsCheckNext = false;
20
-
21
- onHide = async ({ force = false, ...args } = {}) => {
22
- if (!this.state.isShow) return;
23
- this.log({ action: "hide" });
24
- if (this.beforeHide) await this.beforeHide(args);
25
- if (this.controls) await this.emit(this.EVENTS.CONTROLS.POP, { key: this.name });
26
- await this.setShow(false, Boolean(force || this.shared.viewForceAnimationSources.length));
27
- if (this.onClose) {
28
- this.onClose();
29
- delete this.onClose;
30
- } else if (this.isEmitNextAfterHide) this.emitNext();
31
- if (this.afterHide) await this.afterHide(args);
32
- };
33
- onShow = async ({ force = false, onClose, ...args } = {}) => {
34
- if (this.state.isShow) return;
35
- this.currentItem = null;
36
- this.log({ action: "show" });
37
- if (onClose) this.onClose = onClose;
38
- if (this.beforeShow) await this.beforeShow(args);
39
- await this.setShow(true, Boolean(force || this.shared.viewForceAnimationSources.length));
40
- if (this.controls)
41
- await this.emit(this.EVENTS.CONTROLS.PUSH, {
42
- key: this.name,
43
- controls: this.controls,
44
- index: this.controlsIndex,
45
- checkNext: this.controlsCheckNext,
46
- });
47
- if (this.onClose) if (this.afterShow) await this.afterShow(args);
48
- };
49
-
50
- onHideForce = (args) => this.onHide({ ...args, force: true });
51
- onShowForce = (args) => this.onShow({ ...args, force: true });
52
-
53
- setShow = async (value, force = false) => {
54
- this.setState({ ...this.state, isShow: value });
55
- await this.updateView(force);
56
- };
57
-
58
- onUpdateStateFromGlobalState = ({ [this.name]: state } = {}) => this.updateStateAndView(state, true);
59
-
60
- loadImageMedia = async (name, mediaType, quality, isTmp, isConstant) => {
61
- const [type, priority] = [this.CONST.MEDIA.TYPES.IMAGE, this.CONST.MEDIA.PRIORITIES.HIGH];
62
- const arg = { type, priority, quality, name, mediaType, isTmp, isConstant };
63
- const [img] = await this.emit(this.EVENTS.MEDIA.LOAD, arg);
64
-
65
- return img;
66
- };
67
- loadBgMedia = () => {
68
- const [layer, quality] = [this.CONST.CANVAS.LAYERS.BG, this.shared.settings[this.SETTINGS.CANVAS.QUALITY]];
69
-
70
- return this.loadImageMedia(this.bgName, layer, quality, false, true);
71
- };
72
-
73
- updateView = (isForce = false, isFast = false) => this.emit(this.updateEvent, { ...this.state, isForce, isFast });
74
- updateViewForce = () => this.emit(this.updateEvent, { ...this.state, isForce: true });
75
- updateViewFast = () => this.emit(this.updateEvent, { ...this.state, isFast: true });
76
- updateStateAndView = async (state, isForce = false, isFast = false) => {
77
- this.updateState(state);
78
-
79
- await this.updateView(isForce, isFast);
80
- };
81
-
82
- incCurrentItem = () => this.setCurrentItem(this.currentItem + 1, 0);
83
- decCurrentItem = () => this.setCurrentItem(this.currentItem - 1, this.maxCurrentItem);
84
- setCurrentItem = async (value, defaultValue) => {
85
- if (this.currentItem === null) {
86
- this.currentItem = defaultValue;
87
- } else {
88
- this.currentItem = value;
89
- if (this.currentItem > this.maxCurrentItem) this.currentItem = 0;
90
- if (this.currentItem < 0) this.currentItem = this.maxCurrentItem;
91
- }
92
-
93
- this.updateStateAndView({ currentItem: this.currentItem }, true);
94
- };
95
-
96
- getDefaultState = () => ({ isShow: false, isForce: false });
97
- }
@@ -1,59 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
-
3
- export class ModuleView extends Module {
4
- animationTime = 0;
5
- renderFunc = null;
6
- updateEvent = null;
7
- updateHandler = null;
8
- canvasInfo = null;
9
- locLabel = null;
10
-
11
- subscribe = () => {
12
- if (this.updateEvent && this.updateHandler) this.on(this.updateEvent, this.updateHandler);
13
- };
14
-
15
- init = async () => {
16
- if (this.renderFunc) await this.regComponent();
17
- if (this.canvasInfo) await this.regCanvas();
18
- };
19
-
20
- regCanvas = async () => {
21
- if (this.canvasInfo) await this.emit(this.EVENTS.CANVAS.CANVAS_REG, this.canvasInfo);
22
- };
23
-
24
- regComponent = async () => {
25
- this.component = await this.emitOne(this.EVENTS.COMPONENTS.REG, { name: this.name, renderFunc: this.renderFunc });
26
- };
27
-
28
- onUpdateReactComponent = async (state = {}) => {
29
- if (!this.isReady) await this.waitIsReady();
30
-
31
- await this.insertExtraDataToState(state);
32
-
33
- return new Promise(async (resolve) => {
34
- if (state.isForce) {
35
- this.component.setState(state);
36
- await this.waitRerender();
37
- this.component.setState({ ...state, isForce: false });
38
- await this.waitRerender();
39
- return resolve();
40
- }
41
- this.component.setState(state);
42
-
43
- return state.isFast ? resolve() : setTimeout(resolve, this.animationTime);
44
- });
45
- };
46
-
47
- setIsForceReact = async (isForce) => {
48
- this.component.setState({ ...this.state, isForce });
49
-
50
- await this.waitRerender();
51
- };
52
-
53
- insertExtraDataToState = async (state) => {
54
- if (this.locLabel)
55
- state.locs = await this.emitOne(this.EVENTS.LOCS.GET, { label: this.locLabel, isConstant: true });
56
-
57
- return state;
58
- };
59
- }