floating-live 0.16.0-alpha.2 → 0.16.0-alpha.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.
package/dist/app.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { CommandOptions, CommandCallOptions, AppCommandMap, CommandFunction } fr
|
|
|
2
2
|
import { AppError } from "./error";
|
|
3
3
|
import { AppEventDetailMap, AppEventEmitOptions, AppEventListener } from "./event";
|
|
4
4
|
import { AppHookMap, HookCallOptions, HookContext, HookFunction, HookUseOptions } from "./hook";
|
|
5
|
-
import { PluginContext,
|
|
5
|
+
import { PluginContext, PluginInitOptions } from "./plugin";
|
|
6
6
|
import { CustomEventEmitter } from "./utils/EventEmitter";
|
|
7
7
|
import { AppValueMap, ValueOptions } from "./value";
|
|
8
8
|
export declare class App extends CustomEventEmitter implements PluginContext {
|
|
@@ -19,7 +19,7 @@ export declare class App extends CustomEventEmitter implements PluginContext {
|
|
|
19
19
|
throw(err?: Error): void;
|
|
20
20
|
error(id: string, detail?: Record<string, any>): AppError;
|
|
21
21
|
/** 注册插件 */
|
|
22
|
-
register(plugin: any, options?:
|
|
22
|
+
register(plugin: any, options?: PluginInitOptions): void;
|
|
23
23
|
/** 取消注册插件 */
|
|
24
24
|
unregister(pluginName: string): void;
|
|
25
25
|
getPlugin(pluginName: string): void;
|
|
@@ -4,7 +4,7 @@ import { AppError, ErrorOptions } from "../../error";
|
|
|
4
4
|
import { AppEventListener, AppEventEmitOptions, AppEventDetailMap } from "../../event";
|
|
5
5
|
import { HookUseOptions, HookCallOptions, AppHookMap, HookFunction, HookContext } from "../../hook";
|
|
6
6
|
import { AppValueMap, ValueOptions } from "../../value";
|
|
7
|
-
import type { PluginContext, PluginConstructor,
|
|
7
|
+
import type { PluginContext, PluginConstructor, PluginInitOptions, AppPluginExposesMap } from "../types";
|
|
8
8
|
export declare class CommonPluginContext implements PluginContext {
|
|
9
9
|
#private;
|
|
10
10
|
get safe(): boolean;
|
|
@@ -18,9 +18,9 @@ export declare class CommonPluginContext implements PluginContext {
|
|
|
18
18
|
*/
|
|
19
19
|
throw(err: AppError): void;
|
|
20
20
|
error(id: string, options: ErrorOptions): AppError;
|
|
21
|
-
register(plugin: PluginConstructor, options?:
|
|
21
|
+
register(plugin: PluginConstructor, options?: PluginInitOptions): void;
|
|
22
22
|
unregister(pluginName: string): void;
|
|
23
|
-
getPluginExposes<
|
|
23
|
+
getPluginExposes<K extends keyof AppPluginExposesMap>(pluginName: K): AppPluginExposesMap[K];
|
|
24
24
|
whenRegister<T>(pluginName: string, callback: (exposes: any) => (() => void) | undefined): (() => void) | void;
|
|
25
25
|
hasPlugin(pluginName: string): boolean;
|
|
26
26
|
registerValue<K extends keyof AppValueMap>(name: K, options: ValueOptions<AppValueMap[K]>): void;
|
|
@@ -2,7 +2,7 @@ import { App } from "../../app";
|
|
|
2
2
|
import { AppCommandMap, CommandCallOptions, CommandFunction, CommandOptions } from "../../command";
|
|
3
3
|
import { AppEventDetailMap, AppEventEmitOptions } from "../../event";
|
|
4
4
|
import { AppHookMap, HookCallOptions, HookContext, HookFunction, HookUseOptions } from "../../hook";
|
|
5
|
-
import { PluginConstructor,
|
|
5
|
+
import { PluginConstructor, PluginInitOptions } from "../types";
|
|
6
6
|
import { CommonPluginContext } from "./CommonPluginContext";
|
|
7
7
|
export interface PluginPermissions {
|
|
8
8
|
"plugin.register"?: boolean;
|
|
@@ -22,7 +22,7 @@ export declare class SafePluginContext extends CommonPluginContext {
|
|
|
22
22
|
permissions: PluginPermissions;
|
|
23
23
|
});
|
|
24
24
|
private throwNotPermitted;
|
|
25
|
-
register(plugin: PluginConstructor, options?:
|
|
25
|
+
register(plugin: PluginConstructor, options?: PluginInitOptions): void;
|
|
26
26
|
unregister(pluginName: string): void;
|
|
27
27
|
emit<K extends keyof AppEventDetailMap>(type: K, detail: AppEventDetailMap[K], options?: AppEventEmitOptions & EventInit): void;
|
|
28
28
|
call<T extends keyof AppCommandMap>(name: T, ...args: Parameters<AppCommandMap[T]>): ReturnType<AppCommandMap[T]>;
|
package/dist/plugin/manager.js
CHANGED
|
@@ -38,9 +38,11 @@ export class PluginManager {
|
|
|
38
38
|
return;
|
|
39
39
|
// 执行插件函数
|
|
40
40
|
const plugin = new pluginConstructor(pluginCtx, registerCtx.options || {});
|
|
41
|
-
// 调用插件的
|
|
42
|
-
await plugin.
|
|
43
|
-
|
|
41
|
+
// 调用插件的init钩子
|
|
42
|
+
await plugin.init?.(pluginCtx, registerCtx.options || {});
|
|
43
|
+
// 调用插件的expose钩子
|
|
44
|
+
const exposes = await plugin.expose?.(pluginCtx);
|
|
45
|
+
this.list.set(pluginName, { plugin, context: pluginCtx, exposes });
|
|
44
46
|
this.app.emit("plugin:register", { pluginName });
|
|
45
47
|
return plugin;
|
|
46
48
|
})
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -6,16 +6,17 @@ import { AppValueMap, ValueOptions } from "../value";
|
|
|
6
6
|
/** 插件对象 */
|
|
7
7
|
export interface PluginItem {
|
|
8
8
|
pluginName: string;
|
|
9
|
-
|
|
10
|
-
destroy?(ctx: PluginContext): void
|
|
9
|
+
init?(ctx: PluginContext, options?: Record<string, any>): void | Promise<void>;
|
|
10
|
+
destroy?(ctx: PluginContext): void | Promise<void>;
|
|
11
|
+
expose?(ctx: PluginContext): any;
|
|
11
12
|
}
|
|
12
13
|
/** 插件构造器 */
|
|
13
14
|
export interface PluginConstructor {
|
|
14
15
|
pluginName: string;
|
|
15
16
|
new (ctx: PluginContext, options: any): PluginItem;
|
|
16
17
|
}
|
|
17
|
-
/**
|
|
18
|
-
export interface
|
|
18
|
+
/** 插件初始化选项 */
|
|
19
|
+
export interface PluginInitOptions {
|
|
19
20
|
}
|
|
20
21
|
/** 插件上下文 */
|
|
21
22
|
export interface PluginContext {
|
|
@@ -32,11 +33,11 @@ export interface PluginContext {
|
|
|
32
33
|
/** 生成错误 */
|
|
33
34
|
error(id: string, options: ErrorOptions): AppError;
|
|
34
35
|
/** 注册插件 */
|
|
35
|
-
register(plugin: PluginConstructor, options?:
|
|
36
|
+
register(plugin: PluginConstructor, options?: PluginInitOptions): void;
|
|
36
37
|
/** 取消注册插件 */
|
|
37
38
|
unregister(pluginName: string): void;
|
|
38
39
|
/** 获取插件暴露对象 */
|
|
39
|
-
getPluginExposes<
|
|
40
|
+
getPluginExposes<K extends keyof AppPluginExposesMap>(pluginName: K): AppPluginExposesMap[K];
|
|
40
41
|
/** 等待plugin注册 */
|
|
41
42
|
whenRegister(pluginName: string, callback: (exposes: any) => (() => void) | void): void;
|
|
42
43
|
/** 是否存在插件 */
|
|
@@ -71,3 +72,6 @@ export interface PluginContext {
|
|
|
71
72
|
setValue<K extends keyof AppValueMap>(name: K, value: AppValueMap[K]): void;
|
|
72
73
|
destroy(): void;
|
|
73
74
|
}
|
|
75
|
+
export interface AppPluginExposesMap {
|
|
76
|
+
"": {};
|
|
77
|
+
}
|