@vnejs/module 0.0.14 → 0.0.15

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,39 @@
1
+ import type { Observer } from "@vnejs/observer";
2
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
3
+ export type { ModuleGlobalState, ModuleGlobalStateRegistry, ModuleInject, ModuleMedia, ModuleShared } from "./types.js";
4
+ import type { ModuleGlobalStateRegistry, ModuleInject, ModuleMedia, ModuleShared } from "./types.js";
5
+ export declare class Module {
6
+ isReady: boolean;
7
+ isOnlyLocalState: boolean;
8
+ EVENTS: VnePluginEventsMapRegistry;
9
+ CONST: VnePluginConstantsMapRegistry;
10
+ SETTINGS: VnePluginSettingsMapRegistry;
11
+ PARAMS: VnePluginParamsMapRegistry;
12
+ observer?: Observer;
13
+ on: (...args: Parameters<Observer["subscribe"]>) => undefined;
14
+ emit: (...args: Parameters<Observer["emit"]>) => Promise<unknown[]> | undefined;
15
+ emitOne: (...args: Parameters<Observer["emitOne"]>) => Promise<unknown> | undefined;
16
+ emitReal: (...args: Parameters<Observer["emitReal"]>) => Promise<unknown> | undefined;
17
+ shared?: ModuleShared;
18
+ media?: ModuleMedia;
19
+ name: string;
20
+ globalState: ModuleGlobalStateRegistry;
21
+ state: unknown;
22
+ inject: ({ observer, state, shared, media }?: ModuleInject) => void;
23
+ subscribe: () => void;
24
+ init: () => Promise<void>;
25
+ setState: (state?: unknown) => void;
26
+ updateState: (state?: Record<string, unknown>) => void;
27
+ setDefaultState: () => void;
28
+ setStateFromGlobalState: ({ [this.name]: state }: ModuleGlobalStateRegistry) => void;
29
+ getState: () => unknown;
30
+ getDefaultState: () => {};
31
+ waitCheck: (checkFunc: () => boolean) => Promise<void>;
32
+ waitRerenderCheck: (checkFunc: () => boolean) => Promise<void>;
33
+ waitIsReady: () => Promise<void>;
34
+ waitTimeout: (time: number) => Promise<void>;
35
+ waitImmediate: () => Promise<void>;
36
+ waitRender: () => Promise<number>;
37
+ waitRerender: () => Promise<void>;
38
+ getIsReady: () => boolean;
39
+ }
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ import { VNE } from "@vnejs/shared";
2
+ export class Module {
3
+ isReady = false;
4
+ isOnlyLocalState = false;
5
+ EVENTS = VNE.EVENTS;
6
+ CONST = VNE.CONST;
7
+ SETTINGS = VNE.SETTINGS;
8
+ PARAMS = VNE.PARAMS;
9
+ observer;
10
+ on = (...args) => this.observer?.subscribe(...args);
11
+ emit = (...args) => this.observer?.emit(...args);
12
+ emitOne = (...args) => this.observer?.emitOne(...args);
13
+ emitReal = (...args) => this.observer?.emitReal(...args);
14
+ shared;
15
+ media;
16
+ name;
17
+ globalState;
18
+ state;
19
+ inject = ({ observer, state, shared, media } = {}) => {
20
+ this.observer = observer;
21
+ this.globalState = state ?? {};
22
+ this.setState(this.getDefaultState() || {});
23
+ this.shared = shared;
24
+ this.media = media;
25
+ }; // abstract
26
+ subscribe = () => { }; // implement
27
+ init = async () => { }; // implement
28
+ setState = (state = {}) => {
29
+ if (this.isOnlyLocalState) {
30
+ this.state = state;
31
+ }
32
+ else {
33
+ this.globalState[this.name] = state;
34
+ this.state = this.globalState[this.name];
35
+ }
36
+ }; // abstract
37
+ updateState = (state = {}) => this.setState({ ...this.state, ...state });
38
+ setDefaultState = () => this.setState(this.getDefaultState());
39
+ setStateFromGlobalState = ({ [this.name]: state }) => this.setState(state);
40
+ getState = () => this.state;
41
+ getDefaultState = () => ({}); // implement
42
+ waitCheck = async (checkFunc) => {
43
+ while (!checkFunc())
44
+ await this.waitTimeout(0);
45
+ };
46
+ waitRerenderCheck = async (checkFunc) => {
47
+ while (!checkFunc())
48
+ await this.waitRerender();
49
+ };
50
+ waitIsReady = () => this.waitCheck(this.getIsReady);
51
+ waitTimeout = (time) => new Promise((resolve) => setTimeout(resolve, time));
52
+ waitImmediate = () => new Promise((resolve) => {
53
+ const maybeSetImmediate = globalThis.setImmediate;
54
+ if (typeof maybeSetImmediate === "function")
55
+ maybeSetImmediate(resolve);
56
+ else
57
+ setTimeout(resolve, 0);
58
+ });
59
+ waitRender = () => new Promise((resolve) => requestAnimationFrame(resolve));
60
+ waitRerender = () => new Promise((resolve) => requestAnimationFrame(() => setTimeout(resolve, 0)));
61
+ getIsReady = () => this.isReady;
62
+ }
@@ -0,0 +1,29 @@
1
+ import type { Observer } from "@vnejs/observer";
2
+ /**
3
+ * Extend in consumer packages via module augmentation:
4
+ *
5
+ * @example
6
+ * declare module "@vnejs/module" {
7
+ * interface ModuleShared {
8
+ * settings: Record<string, unknown>;
9
+ * lang: string;
10
+ * }
11
+ * interface ModuleGlobalState {
12
+ * text: { tokens: string[] };
13
+ * }
14
+ * }
15
+ */
16
+ export interface ModuleShared {
17
+ }
18
+ /** Global module state registry; defaults to string-keyed records per module name. */
19
+ export interface ModuleGlobalState {
20
+ }
21
+ export type ModuleGlobalStateRegistry = ModuleGlobalState & Record<string, unknown>;
22
+ /** Media bucket id → path/key → url or asset path. */
23
+ export type ModuleMedia = Record<string, Record<string, string>>;
24
+ export type ModuleInject = {
25
+ observer?: Observer;
26
+ state?: ModuleGlobalStateRegistry;
27
+ shared?: ModuleShared;
28
+ media?: ModuleMedia;
29
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,19 +1,26 @@
1
1
  {
2
2
  "name": "@vnejs/module",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "",
5
- "main": "index.js",
6
- "types": "index.d.ts",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
7
10
  "scripts": {
8
11
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "build": "tsc -p tsconfig.json",
10
- "publish:major": "npm version major && npm publish --access public --legacy-peer-deps",
11
- "publish:minor": "npm version minor && npm publish --access public --legacy-peer-deps",
12
- "publish:patch": "npm version patch && npm publish --access public --legacy-peer-deps"
12
+ "build": "rm -rf dist && tsc -p tsconfig.json",
13
+ "publish:major": "npm run build && npm version major && npm publish --access public --legacy-peer-deps",
14
+ "publish:minor": "npm run build && npm version minor && npm publish --access public --legacy-peer-deps",
15
+ "publish:patch": "npm run build && npm version patch && npm publish --access public --legacy-peer-deps"
13
16
  },
14
17
  "author": "",
15
18
  "license": "ISC",
16
19
  "peerDependencies": {
20
+ "@vnejs/observer": "~0.0.1",
17
21
  "@vnejs/shared": "~0.0.9"
22
+ },
23
+ "devDependencies": {
24
+ "typescript": "^6.0.3"
18
25
  }
19
26
  }
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./modules/module";
package/index.js DELETED
@@ -1 +0,0 @@
1
- export * from "./modules/module";
package/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./modules/module";
2
-
@@ -1,44 +0,0 @@
1
- import type { VnePluginConstants, VnePluginEvents, VnePluginParams, VnePluginSettings, VneNamespace } from "@vnejs/shared";
2
- export type ModuleInject = {
3
- on?: (...args: unknown[]) => unknown;
4
- emit?: (...args: unknown[]) => unknown;
5
- emitOne?: (...args: unknown[]) => unknown;
6
- emitReal?: (...args: unknown[]) => unknown;
7
- state?: Record<string, unknown>;
8
- shared?: unknown;
9
- media?: unknown;
10
- };
11
- export declare class Module {
12
- isReady: boolean;
13
- isOnlyLocalState: boolean;
14
- EVENTS: Record<VneNamespace, VnePluginEvents>;
15
- CONST: Record<VneNamespace, VnePluginConstants>;
16
- SETTINGS: Record<VneNamespace, VnePluginSettings>;
17
- PARAMS: Record<VneNamespace, VnePluginParams>;
18
- on?: ModuleInject["on"];
19
- emit?: ModuleInject["emit"];
20
- emitOne?: ModuleInject["emitOne"];
21
- emitReal?: ModuleInject["emitReal"];
22
- shared?: unknown;
23
- media?: unknown;
24
- name: string;
25
- globalState: Record<string, unknown>;
26
- state: unknown;
27
- inject: ({ on, emit, emitOne, emitReal, state, shared, media }?: ModuleInject) => void;
28
- subscribe: () => void;
29
- init: () => Promise<void>;
30
- setState: (state?: unknown) => void;
31
- updateState: (state?: Record<string, unknown>) => void;
32
- setDefaultState: () => void;
33
- setStateFromGlobalState: ({ [this.name]: state }: Record<string, unknown>) => void;
34
- getState: () => unknown;
35
- getDefaultState: () => {};
36
- waitCheck: (checkFunc: () => boolean) => Promise<void>;
37
- waitRerenderCheck: (checkFunc: () => boolean) => Promise<void>;
38
- waitIsReady: () => Promise<void>;
39
- waitTimeout: (time: number) => Promise<void>;
40
- waitImmediate: () => Promise<void>;
41
- waitRender: () => Promise<number>;
42
- waitRerender: () => Promise<void>;
43
- getIsReady: () => boolean;
44
- }
package/modules/module.js DELETED
@@ -1,59 +0,0 @@
1
- import { VNE } from "@vnejs/shared";
2
- export class Module {
3
- constructor() {
4
- this.isReady = false;
5
- this.isOnlyLocalState = false;
6
- this.EVENTS = VNE.EVENTS;
7
- this.CONST = VNE.CONST;
8
- this.SETTINGS = VNE.SETTINGS;
9
- this.PARAMS = VNE.PARAMS;
10
- this.inject = ({ on, emit, emitOne, emitReal, state, shared, media } = {}) => {
11
- // observer
12
- this.on = on;
13
- this.emit = emit;
14
- this.emitOne = emitOne;
15
- this.emitReal = emitReal;
16
- // state
17
- this.globalState = state ?? {};
18
- this.setState(this.getDefaultState() || {});
19
- this.shared = shared;
20
- this.media = media;
21
- }; // abstract
22
- this.subscribe = () => { }; // implement
23
- this.init = async () => { }; // implement
24
- this.setState = (state = {}) => {
25
- if (this.isOnlyLocalState) {
26
- this.state = state;
27
- }
28
- else {
29
- this.globalState[this.name] = state;
30
- this.state = this.globalState[this.name];
31
- }
32
- }; // abstract
33
- this.updateState = (state = {}) => this.setState({ ...this.state, ...state });
34
- this.setDefaultState = () => this.setState(this.getDefaultState());
35
- this.setStateFromGlobalState = ({ [this.name]: state }) => this.setState(state);
36
- this.getState = () => this.state;
37
- this.getDefaultState = () => ({}); // implement
38
- this.waitCheck = async (checkFunc) => {
39
- while (!checkFunc())
40
- await this.waitTimeout(0);
41
- };
42
- this.waitRerenderCheck = async (checkFunc) => {
43
- while (!checkFunc())
44
- await this.waitRerender();
45
- };
46
- this.waitIsReady = () => this.waitCheck(this.getIsReady);
47
- this.waitTimeout = (time) => new Promise((resolve) => setTimeout(resolve, time));
48
- this.waitImmediate = () => new Promise((resolve) => {
49
- const maybeSetImmediate = globalThis.setImmediate;
50
- if (typeof maybeSetImmediate === "function")
51
- maybeSetImmediate(resolve);
52
- else
53
- setTimeout(resolve, 0);
54
- });
55
- this.waitRender = () => new Promise((resolve) => requestAnimationFrame(resolve));
56
- this.waitRerender = () => new Promise((resolve) => requestAnimationFrame(() => setTimeout(resolve, 0)));
57
- this.getIsReady = () => this.isReady;
58
- }
59
- }
package/modules/module.ts DELETED
@@ -1,98 +0,0 @@
1
- import { VNE } from "@vnejs/shared";
2
- import type { VnePluginConstants, VnePluginEvents, VnePluginParams, VnePluginSettings, VneNamespace } from "@vnejs/shared";
3
-
4
- export type ModuleInject = {
5
- on?: (...args: unknown[]) => unknown;
6
- emit?: (...args: unknown[]) => unknown;
7
- emitOne?: (...args: unknown[]) => unknown;
8
- emitReal?: (...args: unknown[]) => unknown;
9
- state?: Record<string, unknown>;
10
- shared?: unknown;
11
- media?: unknown;
12
- };
13
-
14
- export class Module {
15
- isReady = false;
16
- isOnlyLocalState = false;
17
-
18
- EVENTS: Record<VneNamespace, VnePluginEvents> = VNE.EVENTS;
19
- CONST: Record<VneNamespace, VnePluginConstants> = VNE.CONST;
20
- SETTINGS: Record<VneNamespace, VnePluginSettings> = VNE.SETTINGS;
21
- PARAMS: Record<VneNamespace, VnePluginParams> = VNE.PARAMS;
22
-
23
- // runtime-injected
24
- on?: ModuleInject["on"];
25
- emit?: ModuleInject["emit"];
26
- emitOne?: ModuleInject["emitOne"];
27
- emitReal?: ModuleInject["emitReal"];
28
-
29
- shared?: unknown;
30
- media?: unknown;
31
-
32
- name!: string;
33
- globalState!: Record<string, unknown>;
34
- state!: unknown;
35
-
36
- inject = ({ on, emit, emitOne, emitReal, state, shared, media }: ModuleInject = {}) => {
37
- // observer
38
- this.on = on;
39
- this.emit = emit;
40
- this.emitOne = emitOne;
41
- this.emitReal = emitReal;
42
-
43
- // state
44
- this.globalState = state ?? {};
45
- this.setState(this.getDefaultState() || {});
46
-
47
- this.shared = shared;
48
- this.media = media;
49
- }; // abstract
50
-
51
- subscribe = () => {}; // implement
52
-
53
- init = async () => {}; // implement
54
-
55
- setState = (state: unknown = {}) => {
56
- if (this.isOnlyLocalState) {
57
- this.state = state;
58
- } else {
59
- this.globalState[this.name] = state;
60
- this.state = this.globalState[this.name];
61
- }
62
- }; // abstract
63
-
64
- updateState = (state: Record<string, unknown> = {}) => this.setState({ ...(this.state as Record<string, unknown>), ...state });
65
-
66
- setDefaultState = () => this.setState(this.getDefaultState());
67
-
68
- setStateFromGlobalState = ({ [this.name]: state }: Record<string, unknown>) => this.setState(state);
69
-
70
- getState = () => this.state;
71
-
72
- getDefaultState = () => ({}); // implement
73
-
74
- waitCheck = async (checkFunc: () => boolean) => {
75
- while (!checkFunc()) await this.waitTimeout(0);
76
- };
77
-
78
- waitRerenderCheck = async (checkFunc: () => boolean) => {
79
- while (!checkFunc()) await this.waitRerender();
80
- };
81
-
82
- waitIsReady = () => this.waitCheck(this.getIsReady);
83
-
84
- waitTimeout = (time: number) => new Promise<void>((resolve) => setTimeout(resolve, time));
85
-
86
- waitImmediate = () =>
87
- new Promise<void>((resolve) => {
88
- const maybeSetImmediate = (globalThis as unknown as { setImmediate?: (cb: () => void) => unknown }).setImmediate;
89
- if (typeof maybeSetImmediate === "function") maybeSetImmediate(resolve);
90
- else setTimeout(resolve, 0);
91
- });
92
-
93
- waitRender = () => new Promise<number>((resolve) => requestAnimationFrame(resolve));
94
-
95
- waitRerender = () => new Promise<void>((resolve) => requestAnimationFrame(() => setTimeout(resolve, 0)));
96
-
97
- getIsReady = () => this.isReady;
98
- }
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ES2020",
5
- "moduleResolution": "Bundler",
6
- "strict": true,
7
- "skipLibCheck": true,
8
- "declaration": true,
9
- "noEmitOnError": true,
10
- "esModuleInterop": true,
11
- "forceConsistentCasingInFileNames": true
12
- },
13
- "include": ["index.ts", "modules/**/*.ts"]
14
- }
15
-