@vnejs/plugins.scenario.autoread 0.1.1 → 0.1.2

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,4 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { PARAMS, PLUGIN_NAME, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "@vnejs/plugins.scenario.autoread.contract";
3
+ import { Autoread } from "./modules/autoread.js";
4
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS, settings: SETTINGS_KEYS }, [Autoread]);
@@ -0,0 +1,19 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { AutoreadSourcePayload } from "@vnejs/plugins.scenario.autoread.contract";
3
+ import type { AutoreadPluginConstants, AutoreadPluginEvents, AutoreadPluginParams, AutoreadPluginSettings } from "../types.js";
4
+ import type { SettingsChangedPayload } from "../utils/autoread.js";
5
+ export declare class Autoread extends Module<AutoreadPluginEvents, AutoreadPluginConstants, AutoreadPluginSettings, AutoreadPluginParams> {
6
+ name: string;
7
+ disableSources: string[];
8
+ autoreadTimeout: ReturnType<typeof setTimeout> | undefined;
9
+ subscribe: () => void;
10
+ init: () => Promise<[unknown[] | undefined, unknown[] | undefined]>;
11
+ onTry: () => Promise<void | unknown[]>;
12
+ onPush: ({ source }?: AutoreadSourcePayload) => void;
13
+ onPop: ({ source }?: AutoreadSourcePayload) => void;
14
+ onSettingsChanged: ({ name, value }?: SettingsChangedPayload) => false | Promise<unknown[]> | undefined;
15
+ onStateSet: () => void;
16
+ createTimeout: () => void;
17
+ clearTimeout: () => void;
18
+ emitAutoread: () => Promise<unknown[]> | undefined;
19
+ }
@@ -0,0 +1,55 @@
1
+ import { Module } from "@vnejs/module";
2
+ export class Autoread extends Module {
3
+ name = "autoread";
4
+ disableSources = [];
5
+ autoreadTimeout;
6
+ subscribe = () => {
7
+ this.on(this.EVENTS.AUTOREAD.TRY, this.onTry);
8
+ this.on(this.EVENTS.AUTOREAD.PUSH, this.onPush);
9
+ this.on(this.EVENTS.AUTOREAD.POP, this.onPop);
10
+ this.on(this.EVENTS.SETTINGS.CHANGED, this.onSettingsChanged);
11
+ this.on(this.EVENTS.STATE.CLEAR, this.clearTimeout);
12
+ this.on(this.EVENTS.STATE.SET, this.onStateSet);
13
+ };
14
+ init = () => Promise.all([
15
+ this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.AUTOREAD.ENABLED, value: this.PARAMS.AUTOREAD.DEFAULT_ENABLED }),
16
+ this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.AUTOREAD.DELAY, value: this.PARAMS.AUTOREAD.DEFAULT_DELAY }),
17
+ ]);
18
+ onTry = async () => {
19
+ this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "try" } });
20
+ if (!this.shared.settings[this.SETTINGS.AUTOREAD.ENABLED] || this.disableSources.length)
21
+ return;
22
+ await this.waitRerender();
23
+ const elements = document.elementsFromPoint(window.innerHeight / 2, window.innerHeight / 2);
24
+ for (let i = 0; i < elements.length; i++) {
25
+ if (elements[i].hasAttribute("vne-autoread-allow"))
26
+ return this.emit(this.EVENTS.INTERACT.EMIT);
27
+ if (elements[i].hasAttribute("vne-autoread-disable"))
28
+ return this.createTimeout();
29
+ }
30
+ this.createTimeout();
31
+ };
32
+ onPush = ({ source = "" } = {}) => {
33
+ this.disableSources.push(source);
34
+ this.clearTimeout();
35
+ };
36
+ onPop = ({ source = "" } = {}) => {
37
+ this.disableSources = this.disableSources.filter((s) => s !== source);
38
+ if (!this.disableSources.length)
39
+ this.createTimeout();
40
+ };
41
+ onSettingsChanged = ({ name, value } = {}) => name === this.SETTINGS.AUTOREAD.ENABLED && this.emit(value ? this.EVENTS.AUTOREAD.POP : this.EVENTS.AUTOREAD.PUSH, { source: this.name });
42
+ onStateSet = () => {
43
+ this.disableSources = [];
44
+ this.clearTimeout();
45
+ this.createTimeout();
46
+ };
47
+ createTimeout = () => {
48
+ this.autoreadTimeout = setTimeout(this.emitAutoread, this.shared.settings[this.SETTINGS.AUTOREAD.DELAY] || 0);
49
+ };
50
+ clearTimeout = () => {
51
+ if (this.autoreadTimeout)
52
+ clearTimeout(this.autoreadTimeout);
53
+ };
54
+ emitAutoread = () => this.emit(this.EVENTS.AUTOREAD.TRY);
55
+ }
@@ -0,0 +1,10 @@
1
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
2
+ import type { PluginName as InteractPluginName, SubscribeEvents as InteractSubscribeEvents } from "@vnejs/plugins.core.interact.contract";
3
+ import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/plugins.core.logs.contract";
4
+ import type { PluginName as SettingsPluginName, SubscribeEvents as SettingsSubscribeEvents } from "@vnejs/plugins.core.settings.contract";
5
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
6
+ import type { Params, PluginName, SettingsKeys, SubscribeEvents } from "@vnejs/plugins.scenario.autoread.contract";
7
+ export type AutoreadPluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<InteractPluginName, InteractSubscribeEvents> & Record<LogsPluginName, LogsSubscribeEvents> & Record<SettingsPluginName, SettingsSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
8
+ export type AutoreadPluginConstants = VnePluginConstantsMapRegistry;
9
+ export type AutoreadPluginSettings = VnePluginSettingsMapRegistry & Record<PluginName, SettingsKeys>;
10
+ export type AutoreadPluginParams = VnePluginParamsMapRegistry & Record<PluginName, Params>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { AutoreadSourcePayload } from "@vnejs/plugins.scenario.autoread.contract";
2
+ export type SettingsChangedPayload = {
3
+ name?: string;
4
+ value?: unknown;
5
+ };
6
+ export type { AutoreadSourcePayload };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,17 +1,46 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.scenario.autoread",
3
- "version": "0.1.1",
4
- "main": "index.js",
3
+ "version": "0.1.2",
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.scenario.autoread.contract": "~0.0.1"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/module": "~0.0.1",
37
+ "@vnejs/plugins.core.interact.contract": "~0.0.1",
38
+ "@vnejs/plugins.core.logs.contract": "~0.0.1",
39
+ "@vnejs/plugins.core.settings.contract": "~0.0.1",
40
+ "@vnejs/plugins.core.state.contract": "~0.0.1",
41
+ "@vnejs/shared": "~0.0.9"
42
+ },
43
+ "devDependencies": {
44
+ "@vnejs/configs.ts-common": "~0.0.1"
45
+ }
17
46
  }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { PARAMS, PLUGIN_NAME, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "@vnejs/plugins.scenario.autoread.contract";
3
+
4
+ import { Autoread } from "./modules/autoread.js";
5
+
6
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS, settings: SETTINGS_KEYS }, [Autoread]);
@@ -1,9 +1,14 @@
1
1
  import { Module } from "@vnejs/module";
2
+ import type { AutoreadSourcePayload } from "@vnejs/plugins.scenario.autoread.contract";
2
3
 
3
- export class Autoread extends Module {
4
+ import type { AutoreadPluginConstants, AutoreadPluginEvents, AutoreadPluginParams, AutoreadPluginSettings } from "../types.js";
5
+ import type { SettingsChangedPayload } from "../utils/autoread.js";
6
+
7
+ export class Autoread extends Module<AutoreadPluginEvents, AutoreadPluginConstants, AutoreadPluginSettings, AutoreadPluginParams> {
4
8
  name = "autoread";
5
9
 
6
- disableSources = [];
10
+ disableSources: string[] = [];
11
+ autoreadTimeout: ReturnType<typeof setTimeout> | undefined;
7
12
 
8
13
  subscribe = () => {
9
14
  this.on(this.EVENTS.AUTOREAD.TRY, this.onTry);
@@ -38,17 +43,19 @@ export class Autoread extends Module {
38
43
 
39
44
  this.createTimeout();
40
45
  };
41
- onPush = ({ source } = {}) => {
46
+
47
+ onPush = ({ source = "" }: AutoreadSourcePayload = {}) => {
42
48
  this.disableSources.push(source);
43
49
  this.clearTimeout();
44
50
  };
45
- onPop = ({ source } = {}) => {
51
+
52
+ onPop = ({ source = "" }: AutoreadSourcePayload = {}) => {
46
53
  this.disableSources = this.disableSources.filter((s) => s !== source);
47
54
 
48
55
  if (!this.disableSources.length) this.createTimeout();
49
56
  };
50
57
 
51
- onSettingsChanged = ({ name, value } = {}) =>
58
+ onSettingsChanged = ({ name, value }: SettingsChangedPayload = {}) =>
52
59
  name === this.SETTINGS.AUTOREAD.ENABLED && this.emit(value ? this.EVENTS.AUTOREAD.POP : this.EVENTS.AUTOREAD.PUSH, { source: this.name });
53
60
 
54
61
  onStateSet = () => {
@@ -61,7 +68,10 @@ export class Autoread extends Module {
61
68
  createTimeout = () => {
62
69
  this.autoreadTimeout = setTimeout(this.emitAutoread, this.shared.settings[this.SETTINGS.AUTOREAD.DELAY] || 0);
63
70
  };
64
- clearTimeout = () => clearTimeout(this.autoreadTimeout);
71
+
72
+ clearTimeout = () => {
73
+ if (this.autoreadTimeout) clearTimeout(this.autoreadTimeout);
74
+ };
65
75
 
66
76
  emitAutoread = () => this.emit(this.EVENTS.AUTOREAD.TRY);
67
77
  }
package/src/types.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
2
+ import type { PluginName as InteractPluginName, SubscribeEvents as InteractSubscribeEvents } from "@vnejs/plugins.core.interact.contract";
3
+ import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/plugins.core.logs.contract";
4
+ import type { PluginName as SettingsPluginName, SubscribeEvents as SettingsSubscribeEvents } from "@vnejs/plugins.core.settings.contract";
5
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
6
+ import type { Params, PluginName, SettingsKeys, SubscribeEvents } from "@vnejs/plugins.scenario.autoread.contract";
7
+
8
+ export type AutoreadPluginEvents = VnePluginEventsMapRegistry &
9
+ Record<PluginName, SubscribeEvents> &
10
+ Record<InteractPluginName, InteractSubscribeEvents> &
11
+ Record<LogsPluginName, LogsSubscribeEvents> &
12
+ Record<SettingsPluginName, SettingsSubscribeEvents> &
13
+ Record<StatePluginName, StateSubscribeEvents>;
14
+
15
+ export type AutoreadPluginConstants = VnePluginConstantsMapRegistry;
16
+
17
+ export type AutoreadPluginSettings = VnePluginSettingsMapRegistry & Record<PluginName, SettingsKeys>;
18
+
19
+ export type AutoreadPluginParams = VnePluginParamsMapRegistry & Record<PluginName, Params>;
@@ -0,0 +1,8 @@
1
+ import type { AutoreadSourcePayload } from "@vnejs/plugins.scenario.autoread.contract";
2
+
3
+ export type SettingsChangedPayload = {
4
+ name?: string;
5
+ value?: unknown;
6
+ };
7
+
8
+ export type { AutoreadSourcePayload };
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules"]
9
+ }
package/const/const.js DELETED
File without changes
package/const/events.js DELETED
@@ -1,6 +0,0 @@
1
- export const SUBSCRIBE_EVENTS = {
2
- TRY: "vne:autoread:try",
3
-
4
- PUSH: "vne:autoread:push",
5
- POP: "vne:autoread:pop",
6
- };
package/const/params.js DELETED
@@ -1,2 +0,0 @@
1
- export const DEFAULT_DELAY = 5000;
2
- export const DEFAULT_ENABLED = false;
package/const/settings.js DELETED
@@ -1,4 +0,0 @@
1
- export const SETTINGS_KEYS = {
2
- ENABLED: "vne:autoread:enabled",
3
- DELAY: "vne:autoread:delay",
4
- };
package/index.js DELETED
@@ -1,10 +0,0 @@
1
- import { regPlugin } from "@vnejs/shared";
2
-
3
- import * as constants from "./const/const";
4
- import { SUBSCRIBE_EVENTS } from "./const/events";
5
- import * as params from "./const/params";
6
- import { SETTINGS_KEYS } from "./const/settings";
7
-
8
- import { Autoread } from "./modules/autoread";
9
-
10
- regPlugin("AUTOREAD", { constants, events: SUBSCRIBE_EVENTS, params, settings: SETTINGS_KEYS }, [Autoread]);