@netless/window-manager 1.0.5 → 1.0.6-beta.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/dist/index.d.ts +29 -1
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AppManager.ts +6 -2
- package/src/ExtendPluginManager.ts +55 -0
- package/src/index.ts +16 -0
package/package.json
CHANGED
package/src/AppManager.ts
CHANGED
@@ -523,7 +523,7 @@ export class AppManager {
|
|
523
523
|
throw new Error("appAttributes is undefined");
|
524
524
|
}
|
525
525
|
|
526
|
-
this.appCreateQueue.push<AppProxy>(async() => {
|
526
|
+
this.appCreateQueue.push<AppProxy>(async () => {
|
527
527
|
this.appStatus.set(id, AppStatus.StartCreate);
|
528
528
|
const appProxy = await this.baseInsertApp(
|
529
529
|
{
|
@@ -534,7 +534,11 @@ export class AppManager {
|
|
534
534
|
id,
|
535
535
|
false
|
536
536
|
);
|
537
|
-
if (
|
537
|
+
if (
|
538
|
+
appProxy &&
|
539
|
+
this.store.focus === id &&
|
540
|
+
this._focusAppCreatedResolve
|
541
|
+
) {
|
538
542
|
this._focusAppCreatedResolve(appProxy);
|
539
543
|
}
|
540
544
|
return appProxy;
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import type { WindowManager } from ".";
|
2
|
+
import Emittery from "emittery";
|
3
|
+
import type { EmitterType } from "./InternalEmitter";
|
4
|
+
import { appRegister } from "./Register";
|
5
|
+
|
6
|
+
export interface ExtendContext {
|
7
|
+
readonly manager: ExtendPluginManager;
|
8
|
+
readonly windowManager: WindowManager;
|
9
|
+
readonly internalEmitter: EmitterType;
|
10
|
+
}
|
11
|
+
|
12
|
+
export abstract class ExtendPlugin extends Emittery {
|
13
|
+
context!: ExtendContext;
|
14
|
+
abstract readonly kind: string;
|
15
|
+
protected _inject(context: ExtendContext) {
|
16
|
+
this.context = context;
|
17
|
+
}
|
18
|
+
abstract onCreate(): void;
|
19
|
+
abstract onDestroy(): void;
|
20
|
+
}
|
21
|
+
|
22
|
+
export type ExtendPluginInstance<T extends ExtendPlugin> = T;
|
23
|
+
|
24
|
+
export interface ExtendManagerOptions {
|
25
|
+
readonly windowManager: WindowManager;
|
26
|
+
readonly internalEmitter: EmitterType;
|
27
|
+
}
|
28
|
+
|
29
|
+
export class ExtendPluginManager {
|
30
|
+
private extends: Map<string, ExtendPluginInstance<any>> = new Map();
|
31
|
+
private context: ExtendContext;
|
32
|
+
constructor(props: ExtendManagerOptions) {
|
33
|
+
this.context = {
|
34
|
+
manager: this,
|
35
|
+
windowManager: props.windowManager,
|
36
|
+
internalEmitter: props.internalEmitter,
|
37
|
+
};
|
38
|
+
}
|
39
|
+
|
40
|
+
hasRegister(kind: string) {
|
41
|
+
return appRegister.appClasses.has(kind);
|
42
|
+
}
|
43
|
+
|
44
|
+
use(extend: ExtendPluginInstance<any>) {
|
45
|
+
this.extends.set(extend.kind, extend);
|
46
|
+
extend._inject(this.context);
|
47
|
+
extend.onCreate();
|
48
|
+
}
|
49
|
+
destroy() {
|
50
|
+
this.extends.forEach(extend => {
|
51
|
+
this.extends.delete(extend.kind);
|
52
|
+
extend.onDestroy();
|
53
|
+
});
|
54
|
+
}
|
55
|
+
}
|
package/src/index.ts
CHANGED
@@ -57,6 +57,8 @@ import type { PageController, AddPageParams, PageState } from "./Page";
|
|
57
57
|
import { boxEmitter } from "./BoxEmitter";
|
58
58
|
import { IframeBridge } from "./View/IframeBridge";
|
59
59
|
import { setOptions } from "@netless/app-media-player";
|
60
|
+
import type { ExtendPluginInstance } from "./ExtendPluginManager";
|
61
|
+
import { ExtendPluginManager } from "./ExtendPluginManager";
|
60
62
|
export * from "./View/IframeBridge";
|
61
63
|
|
62
64
|
export type WindowMangerAttributes = {
|
@@ -196,6 +198,8 @@ export class WindowManager
|
|
196
198
|
private containerResizeObserver?: ContainerResizeObserver;
|
197
199
|
public containerSizeRatio = WindowManager.containerSizeRatio;
|
198
200
|
|
201
|
+
private extendPluginManager?: ExtendPluginManager;
|
202
|
+
|
199
203
|
constructor(context: InvisiblePluginContext) {
|
200
204
|
super(context);
|
201
205
|
WindowManager.displayer = context.displayer;
|
@@ -275,6 +279,11 @@ export class WindowManager
|
|
275
279
|
params.cursorOptions,
|
276
280
|
params.applianceIcons
|
277
281
|
);
|
282
|
+
manager.extendPluginManager = new ExtendPluginManager({
|
283
|
+
internalEmitter: internalEmitter,
|
284
|
+
windowManager: manager,
|
285
|
+
});
|
286
|
+
|
278
287
|
if (containerSizeRatio) {
|
279
288
|
manager.containerSizeRatio = containerSizeRatio;
|
280
289
|
}
|
@@ -919,6 +928,7 @@ export class WindowManager
|
|
919
928
|
this.containerResizeObserver?.disconnect();
|
920
929
|
this.appManager?.destroy();
|
921
930
|
this.cursorManager?.destroy();
|
931
|
+
this.extendPluginManager?.destroy();
|
922
932
|
WindowManager.container = undefined;
|
923
933
|
WindowManager.wrapper = undefined;
|
924
934
|
WindowManager.sizer = undefined;
|
@@ -1083,6 +1093,10 @@ export class WindowManager
|
|
1083
1093
|
this._iframeBridge || (this._iframeBridge = new IframeBridge(this, this.appManager));
|
1084
1094
|
return this._iframeBridge;
|
1085
1095
|
}
|
1096
|
+
|
1097
|
+
public useExtendPlugin(extend: ExtendPluginInstance<any>) {
|
1098
|
+
this.extendPluginManager?.use(extend);
|
1099
|
+
}
|
1086
1100
|
}
|
1087
1101
|
|
1088
1102
|
setupBuiltin();
|
@@ -1091,3 +1105,5 @@ export * from "./typings";
|
|
1091
1105
|
|
1092
1106
|
export { BuiltinApps } from "./BuiltinApps";
|
1093
1107
|
export type { PublicEvent } from "./callback";
|
1108
|
+
|
1109
|
+
export * from "./ExtendPluginManager";
|