@netless/window-manager 1.0.7-beta.0 → 1.0.7-beta.10
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 +258 -162
- package/dist/index.js +14 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8489 -6798
- package/dist/index.mjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +3 -3
- package/src/App/AppContext.ts +27 -2
- package/src/App/AppProxy.ts +57 -6
- package/src/App/Storage/index.ts +1 -0
- package/src/AppListener.ts +17 -17
- package/src/AppManager.ts +88 -8
- package/src/AttributesDelegate.ts +82 -12
- package/src/BoxEmitter.ts +2 -0
- package/src/BoxManager.ts +82 -4
- package/src/Cursor/index.ts +1 -0
- package/src/InternalEmitter.ts +3 -0
- package/src/Utils/extendClass.ts +62 -0
- package/src/callback.ts +10 -1
- package/src/index.ts +92 -11
- package/src/shim.d.ts +4 -0
- package/src/typings.ts +2 -1
package/src/AppManager.ts
CHANGED
|
@@ -9,7 +9,8 @@ import { calculateNextIndex } from "./Page";
|
|
|
9
9
|
import { callbacks } from "./callback";
|
|
10
10
|
import { debounce, get, isInteger, orderBy } from "lodash";
|
|
11
11
|
import { internalEmitter } from "./InternalEmitter";
|
|
12
|
-
import {
|
|
12
|
+
import { createAttributesDelegate, Fields } from "./AttributesDelegate";
|
|
13
|
+
import type { AttributesDelegate } from "./AttributesDelegate";
|
|
13
14
|
import { log } from "./Utils/log";
|
|
14
15
|
import { MainViewProxy } from "./View/MainView";
|
|
15
16
|
import { safeListenPropsUpdated } from "./Utils/Reactive";
|
|
@@ -41,19 +42,23 @@ import type {
|
|
|
41
42
|
} from "white-web-sdk";
|
|
42
43
|
import type { AddAppParams, BaseInsertParams, TeleBoxRect } from "./index";
|
|
43
44
|
import type {
|
|
45
|
+
BoxBlurredPayload,
|
|
44
46
|
BoxClosePayload,
|
|
45
47
|
BoxFocusPayload,
|
|
46
48
|
BoxMovePayload,
|
|
47
49
|
BoxResizePayload,
|
|
48
50
|
BoxStateChangePayload,
|
|
49
51
|
} from "./BoxEmitter";
|
|
52
|
+
import { getExtendClass } from "./Utils/extendClass";
|
|
53
|
+
import type { TeleBoxState } from "@netless/telebox-insider";
|
|
50
54
|
|
|
51
55
|
export class AppManager {
|
|
56
|
+
static readonly kind = "AppManager";
|
|
52
57
|
public displayer: Displayer;
|
|
53
58
|
public viewManager: ViewManager;
|
|
54
59
|
public appProxies: Map<string, AppProxy> = new Map();
|
|
55
60
|
public appStatus: Map<string, AppStatus> = new Map();
|
|
56
|
-
public store
|
|
61
|
+
public store!: AttributesDelegate;
|
|
57
62
|
public mainViewProxy: MainViewProxy;
|
|
58
63
|
public refresher: ReconnectRefresher;
|
|
59
64
|
public isReplay = this.windowManger.isReplay;
|
|
@@ -67,7 +72,9 @@ export class AppManager {
|
|
|
67
72
|
private callbacksNode: ScenesCallbacksNode | null = null;
|
|
68
73
|
private appCreateQueue = new AppCreateQueue();
|
|
69
74
|
|
|
70
|
-
private _focusAppCreatedResolve?: (appProxy
|
|
75
|
+
private _focusAppCreatedResolve?: (appProxy?: AppProxy) => void;
|
|
76
|
+
private _focusAppId: string | undefined;
|
|
77
|
+
private _resolveTimer: number | undefined;
|
|
71
78
|
|
|
72
79
|
private sideEffectManager = new SideEffectManager();
|
|
73
80
|
|
|
@@ -75,9 +82,24 @@ export class AppManager {
|
|
|
75
82
|
|
|
76
83
|
public rootDirRemoving = false;
|
|
77
84
|
|
|
85
|
+
private _useBoxesStatus = false;
|
|
86
|
+
|
|
87
|
+
public get useBoxesStatus() {
|
|
88
|
+
return this._useBoxesStatus;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public set useBoxesStatus(value: boolean) {
|
|
92
|
+
this._useBoxesStatus = value;
|
|
93
|
+
}
|
|
94
|
+
|
|
78
95
|
constructor(public windowManger: WindowManager) {
|
|
79
96
|
this.displayer = windowManger.displayer;
|
|
80
|
-
this.store.setContext({
|
|
97
|
+
// this.store.setContext({
|
|
98
|
+
// getAttributes: () => this.attributes,
|
|
99
|
+
// safeSetAttributes: attributes => this.safeSetAttributes(attributes),
|
|
100
|
+
// safeUpdateAttributes: (keys, val) => this.safeUpdateAttributes(keys, val),
|
|
101
|
+
// });
|
|
102
|
+
this.store = createAttributesDelegate(WindowManager.extendClass, {
|
|
81
103
|
getAttributes: () => this.attributes,
|
|
82
104
|
safeSetAttributes: attributes => this.safeSetAttributes(attributes),
|
|
83
105
|
safeUpdateAttributes: (keys, val) => this.safeUpdateAttributes(keys, val),
|
|
@@ -322,8 +344,12 @@ export class AppManager {
|
|
|
322
344
|
|
|
323
345
|
private async onCreated() {
|
|
324
346
|
if (Object.keys(this.attributes.apps).length && this.store.focus) {
|
|
325
|
-
|
|
347
|
+
this._focusAppId = this.store.focus;
|
|
348
|
+
await new Promise<AppProxy | undefined>(resolve => {
|
|
326
349
|
this._focusAppCreatedResolve = resolve;
|
|
350
|
+
this._resolveTimer = setTimeout(() => {
|
|
351
|
+
resolve(this.appProxies.get(this._focusAppId || ''));
|
|
352
|
+
}, 500);
|
|
327
353
|
}).then(() => {
|
|
328
354
|
this.focusByAttributes(this.attributes.apps);
|
|
329
355
|
});
|
|
@@ -336,9 +362,11 @@ export class AppManager {
|
|
|
336
362
|
boxEmitter.on("focus", this.onBoxFocus);
|
|
337
363
|
boxEmitter.on("close", this.onBoxClose);
|
|
338
364
|
boxEmitter.on("boxStateChange", this.onBoxStateChange);
|
|
365
|
+
boxEmitter.on("blurred", this.onBoxBlurred);
|
|
339
366
|
|
|
340
367
|
this.addAppsChangeListener();
|
|
341
368
|
this.addAppCloseListener();
|
|
369
|
+
this.addBoxesStatusChangeListener();
|
|
342
370
|
this.refresher.add("maximized", () => {
|
|
343
371
|
return autorun(() => {
|
|
344
372
|
const maximized = this.attributes.maximized;
|
|
@@ -413,6 +441,14 @@ export class AppManager {
|
|
|
413
441
|
callbacks.emit("onBoxFocus", payload);
|
|
414
442
|
};
|
|
415
443
|
|
|
444
|
+
private onBoxBlurred = (payload: BoxBlurredPayload) => {
|
|
445
|
+
const focus = this.attributes.focus;
|
|
446
|
+
if (focus === payload.appId) {
|
|
447
|
+
this.windowManger.safeSetAttributes({ focus: undefined });
|
|
448
|
+
callbacks.emit("onBoxBlurred", payload);
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
416
452
|
private onBoxClose = (payload: BoxClosePayload) => {
|
|
417
453
|
const appProxy = this.appProxies.get(payload.appId);
|
|
418
454
|
if (appProxy) {
|
|
@@ -426,6 +462,39 @@ export class AppManager {
|
|
|
426
462
|
callbacks.emit("onBoxStateChange", payload);
|
|
427
463
|
};
|
|
428
464
|
|
|
465
|
+
private notifyBoxesStatusChange = debounce(() => {
|
|
466
|
+
const entries = Object.entries(this.attributes.boxesStatus);
|
|
467
|
+
if (entries.length > 0) {
|
|
468
|
+
entries.forEach(([appId, status]) => {
|
|
469
|
+
const appProxy = this.appProxies.get(appId);
|
|
470
|
+
if (appProxy) {
|
|
471
|
+
appProxy.notifyBoxStatusChange(status as TeleBoxState);
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}, 50);
|
|
476
|
+
|
|
477
|
+
public addBoxesStatusChangeListener = () => {
|
|
478
|
+
this.refresher.add("boxesStatus", () => {
|
|
479
|
+
return safeListenPropsUpdated(
|
|
480
|
+
() => this.attributes.boxesStatus,
|
|
481
|
+
() => {
|
|
482
|
+
this.boxManager?.setBoxesStatus(this.attributes.boxesStatus);
|
|
483
|
+
this.notifyBoxesStatusChange();
|
|
484
|
+
}
|
|
485
|
+
);
|
|
486
|
+
});
|
|
487
|
+
this.refresher.add("lastNotMinimizedBoxesStatus", () => {
|
|
488
|
+
return safeListenPropsUpdated(
|
|
489
|
+
() => this.attributes.lastNotMinimizedBoxesStatus,
|
|
490
|
+
() => {
|
|
491
|
+
this.boxManager?.setLastNotMinimizedBoxesStatus(
|
|
492
|
+
this.attributes.lastNotMinimizedBoxesStatus
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
);
|
|
496
|
+
});
|
|
497
|
+
};
|
|
429
498
|
public addAppsChangeListener = () => {
|
|
430
499
|
this.refresher.add("apps", () => {
|
|
431
500
|
return safeListenPropsUpdated(
|
|
@@ -532,7 +601,7 @@ export class AppManager {
|
|
|
532
601
|
if (!appAttributes) {
|
|
533
602
|
throw new Error("appAttributes is undefined");
|
|
534
603
|
}
|
|
535
|
-
|
|
604
|
+
|
|
536
605
|
this.appCreateQueue.push<AppProxy>(async () => {
|
|
537
606
|
this.appStatus.set(id, AppStatus.StartCreate);
|
|
538
607
|
const appProxy = await this.baseInsertApp(
|
|
@@ -540,15 +609,21 @@ export class AppManager {
|
|
|
540
609
|
kind: app.kind,
|
|
541
610
|
options: app.options,
|
|
542
611
|
isDynamicPPT: app.isDynamicPPT,
|
|
612
|
+
forceNormal: app.forceNormal,
|
|
613
|
+
forceTop: app.forceTop,
|
|
614
|
+
isDragContent: app.isDragContent,
|
|
543
615
|
},
|
|
544
616
|
id,
|
|
545
617
|
false
|
|
546
618
|
);
|
|
547
619
|
if (
|
|
548
620
|
appProxy &&
|
|
549
|
-
this.
|
|
621
|
+
this._focusAppId === id &&
|
|
550
622
|
this._focusAppCreatedResolve
|
|
551
623
|
) {
|
|
624
|
+
if (this._resolveTimer) {
|
|
625
|
+
clearTimeout(this._resolveTimer);
|
|
626
|
+
}
|
|
552
627
|
this._focusAppCreatedResolve(appProxy);
|
|
553
628
|
}
|
|
554
629
|
return appProxy;
|
|
@@ -697,7 +772,8 @@ export class AppManager {
|
|
|
697
772
|
console.warn("[WindowManager]: app duplicate exists and cannot be created again");
|
|
698
773
|
return;
|
|
699
774
|
}
|
|
700
|
-
const
|
|
775
|
+
const AppProxyClass = getExtendClass(AppProxy, WindowManager.extendClass);
|
|
776
|
+
const appProxy = new AppProxyClass(params, this, appId, isAddApp);
|
|
701
777
|
if (appProxy) {
|
|
702
778
|
await appProxy.baseInsertApp(focus);
|
|
703
779
|
this.appStatus.delete(appId);
|
|
@@ -874,6 +950,10 @@ export class AppManager {
|
|
|
874
950
|
this.sideEffectManager.flushAll();
|
|
875
951
|
this._prevFocused = undefined;
|
|
876
952
|
this._prevSceneIndex = undefined;
|
|
953
|
+
if (this._resolveTimer) {
|
|
954
|
+
clearTimeout(this._resolveTimer);
|
|
955
|
+
}
|
|
877
956
|
this._focusAppCreatedResolve = undefined;
|
|
957
|
+
this._resolveTimer = undefined;
|
|
878
958
|
}
|
|
879
959
|
}
|
|
@@ -4,11 +4,15 @@ import { setViewFocusScenePath } from "./Utils/Common";
|
|
|
4
4
|
import type { AddAppParams, AppSyncAttributes } from "./index";
|
|
5
5
|
import type { Camera, Size, View } from "white-web-sdk";
|
|
6
6
|
import type { Cursor } from "./Cursor/Cursor";
|
|
7
|
+
import { getExtendClass } from "./Utils/extendClass";
|
|
8
|
+
import type { ExtendClass } from "./Utils/extendClass";
|
|
9
|
+
import type { NotMinimizedBoxState, TeleBoxState } from "@netless/telebox-insider";
|
|
7
10
|
|
|
8
11
|
export enum Fields {
|
|
9
12
|
Apps = "apps",
|
|
10
13
|
Focus = "focus",
|
|
11
14
|
State = "state",
|
|
15
|
+
/** 默认窗口状态, (用于窗口状态的统一管理) */
|
|
12
16
|
BoxState = "boxState",
|
|
13
17
|
MainViewCamera = "mainViewCamera",
|
|
14
18
|
MainViewSize = "mainViewSize",
|
|
@@ -19,6 +23,10 @@ export enum Fields {
|
|
|
19
23
|
FullPath = "fullPath",
|
|
20
24
|
Registered = "registered",
|
|
21
25
|
IframeBridge = "iframeBridge",
|
|
26
|
+
/** 所有窗口状态, (用于窗口状态的单独管理) */
|
|
27
|
+
BoxesStatus = "boxesStatus",
|
|
28
|
+
/** 上次非最小化窗口状态 */
|
|
29
|
+
LastNotMinimizedBoxesStatus = "lastNotMinimizedBoxesStatus",
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export type Apps = {
|
|
@@ -45,6 +53,7 @@ export type ICamera = Camera & { id: string };
|
|
|
45
53
|
export type ISize = Size & { id: string };
|
|
46
54
|
|
|
47
55
|
export class AttributesDelegate {
|
|
56
|
+
static readonly kind = "AttributesDelegate";
|
|
48
57
|
constructor(private context: StoreContext) {}
|
|
49
58
|
|
|
50
59
|
public setContext(context: StoreContext) {
|
|
@@ -79,6 +88,42 @@ export class AttributesDelegate {
|
|
|
79
88
|
return get(this.attributes, ["minimized"]);
|
|
80
89
|
}
|
|
81
90
|
|
|
91
|
+
public getBoxesStatus(): Record<string, TeleBoxState> | undefined {
|
|
92
|
+
return get(this.attributes, [Fields.BoxesStatus]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public getBoxStatus(id: string): TeleBoxState | undefined {
|
|
96
|
+
return get(this.attributes, [Fields.BoxesStatus, id]);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public setBoxStatus(id: string, status?: TeleBoxState) {
|
|
100
|
+
const attributes = this.attributes;
|
|
101
|
+
if (!attributes.boxesStatus) {
|
|
102
|
+
this.context.safeSetAttributes({ boxesStatus: {} });
|
|
103
|
+
}
|
|
104
|
+
if (this.getBoxStatus(id) !== status) {
|
|
105
|
+
this.context.safeUpdateAttributes([Fields.BoxesStatus, id], status);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public getLastNotMinimizedBoxesStatus(): Record<string, NotMinimizedBoxState> | undefined {
|
|
110
|
+
return get(this.attributes, [Fields.LastNotMinimizedBoxesStatus]);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public getLastNotMinimizedBoxStatus(id: string): NotMinimizedBoxState | undefined {
|
|
114
|
+
return get(this.attributes, [Fields.LastNotMinimizedBoxesStatus, id]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public setLastNotMinimizedBoxStatus(id: string, status?: NotMinimizedBoxState) {
|
|
118
|
+
const attributes = this.attributes;
|
|
119
|
+
if (!attributes.lastNotMinimizedBoxesStatus) {
|
|
120
|
+
this.context.safeSetAttributes({ lastNotMinimizedBoxesStatus: {} });
|
|
121
|
+
}
|
|
122
|
+
if (this.getLastNotMinimizedBoxStatus(id) !== status) {
|
|
123
|
+
this.context.safeUpdateAttributes([Fields.LastNotMinimizedBoxesStatus, id], status);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
82
127
|
public setupAppAttributes(params: AddAppParams, id: string, isDynamicPPT: boolean) {
|
|
83
128
|
const attributes = this.attributes;
|
|
84
129
|
if (!attributes.apps) {
|
|
@@ -89,7 +134,14 @@ export class AttributesDelegate {
|
|
|
89
134
|
attrNames.push("scenes");
|
|
90
135
|
}
|
|
91
136
|
const options = pick(params.options, attrNames);
|
|
92
|
-
const attrs: AppSyncAttributes = {
|
|
137
|
+
const attrs: AppSyncAttributes = {
|
|
138
|
+
kind: params.kind,
|
|
139
|
+
options,
|
|
140
|
+
isDynamicPPT,
|
|
141
|
+
forceTop: params.forceTop,
|
|
142
|
+
forceNormal: params.forceNormal,
|
|
143
|
+
isDragContent: params.isDragContent,
|
|
144
|
+
};
|
|
93
145
|
if (typeof params.src === "string") {
|
|
94
146
|
attrs.src = params.src;
|
|
95
147
|
}
|
|
@@ -249,14 +301,32 @@ export type Cursors = {
|
|
|
249
301
|
[key: string]: Cursor;
|
|
250
302
|
};
|
|
251
303
|
|
|
252
|
-
export const store = new AttributesDelegate({
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
});
|
|
304
|
+
// export const store = new AttributesDelegate({
|
|
305
|
+
// getAttributes: () => {
|
|
306
|
+
// throw new Error("getAttributes not implemented");
|
|
307
|
+
// },
|
|
308
|
+
// safeSetAttributes: () => {
|
|
309
|
+
// throw new Error("safeSetAttributes not implemented");
|
|
310
|
+
// },
|
|
311
|
+
// safeUpdateAttributes: () => {
|
|
312
|
+
// throw new Error("safeUpdateAttributes not implemented");
|
|
313
|
+
// },
|
|
314
|
+
// });
|
|
315
|
+
|
|
316
|
+
export const createAttributesDelegate = (
|
|
317
|
+
extendClass?: ExtendClass,
|
|
318
|
+
context: StoreContext = {
|
|
319
|
+
getAttributes: () => {
|
|
320
|
+
throw new Error("getAttributes not implemented");
|
|
321
|
+
},
|
|
322
|
+
safeSetAttributes: () => {
|
|
323
|
+
throw new Error("safeSetAttributes not implemented");
|
|
324
|
+
},
|
|
325
|
+
safeUpdateAttributes: () => {
|
|
326
|
+
throw new Error("safeUpdateAttributes not implemented");
|
|
327
|
+
},
|
|
328
|
+
}
|
|
329
|
+
) => {
|
|
330
|
+
const AttributesDelegateClass = getExtendClass(AttributesDelegate, extendClass);
|
|
331
|
+
return new AttributesDelegateClass(context);
|
|
332
|
+
};
|
package/src/BoxEmitter.ts
CHANGED
|
@@ -3,6 +3,7 @@ import Emittery from "emittery";
|
|
|
3
3
|
|
|
4
4
|
export type BoxMovePayload = { appId: string; x: number; y: number };
|
|
5
5
|
export type BoxFocusPayload = { appId: string };
|
|
6
|
+
export type BoxBlurredPayload = { appId: string };
|
|
6
7
|
export type BoxResizePayload = {
|
|
7
8
|
appId: string;
|
|
8
9
|
width: number;
|
|
@@ -19,6 +20,7 @@ export type BoxEvent = {
|
|
|
19
20
|
resize: BoxResizePayload;
|
|
20
21
|
close: BoxClosePayload;
|
|
21
22
|
boxStateChange: BoxStateChangePayload;
|
|
23
|
+
blurred: BoxBlurredPayload;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
export type BoxEmitterType = Emittery<BoxEvent>;
|
package/src/BoxManager.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AppAttributes, Events, MIN_HEIGHT, MIN_WIDTH } from "./constants";
|
|
2
2
|
import { debounce } from "lodash";
|
|
3
|
-
import { TELE_BOX_STATE
|
|
3
|
+
import { TELE_BOX_STATE } from "@netless/telebox-insider";
|
|
4
4
|
import { WindowManager } from "./index";
|
|
5
5
|
import type { BoxEmitterType } from "./BoxEmitter";
|
|
6
6
|
import type { AddAppOptions, AppInitState } from "./index";
|
|
@@ -12,12 +12,15 @@ import type {
|
|
|
12
12
|
TeleBoxColorScheme,
|
|
13
13
|
TeleBoxRect,
|
|
14
14
|
TeleBoxConfig,
|
|
15
|
+
TeleBoxState,
|
|
16
|
+
NotMinimizedBoxState,
|
|
15
17
|
} from "@netless/telebox-insider";
|
|
16
18
|
import type Emittery from "emittery";
|
|
17
19
|
import type { NetlessApp } from "./typings";
|
|
18
20
|
import type { View } from "white-web-sdk";
|
|
19
21
|
import type { CallbacksType } from "./callback";
|
|
20
22
|
import type { EmitterType } from "./InternalEmitter";
|
|
23
|
+
import { getExtendClass, TeleBoxManager, TeleBoxCollector } from "./Utils/extendClass";
|
|
21
24
|
|
|
22
25
|
export { TELE_BOX_STATE };
|
|
23
26
|
|
|
@@ -29,6 +32,10 @@ export type CreateBoxParams = {
|
|
|
29
32
|
options?: AddAppOptions;
|
|
30
33
|
canOperate?: boolean;
|
|
31
34
|
smartPosition?: boolean;
|
|
35
|
+
boxStatus?: TeleBoxState;
|
|
36
|
+
forceTop?: boolean;
|
|
37
|
+
forceNormal?: boolean;
|
|
38
|
+
isDragContent?: boolean;
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
type AppId = { appId: string };
|
|
@@ -45,12 +52,15 @@ export type CreateTeleBoxManagerConfig = {
|
|
|
45
52
|
collectorContainer?: HTMLElement;
|
|
46
53
|
collectorStyles?: Partial<CSSStyleDeclaration>;
|
|
47
54
|
prefersColorScheme?: TeleBoxColorScheme;
|
|
55
|
+
useBoxesStatus?: boolean;
|
|
48
56
|
};
|
|
49
57
|
|
|
50
58
|
export type BoxManagerContext = {
|
|
51
59
|
safeSetAttributes: (attributes: any) => void;
|
|
52
60
|
getMainView: () => View;
|
|
53
61
|
updateAppState: (appId: string, field: AppAttributes, value: any) => void;
|
|
62
|
+
setBoxStatus: (appId: string, status?: TeleBoxState) => void;
|
|
63
|
+
setLastNotMinimizedBoxStatus: (appId: string, status?: NotMinimizedBoxState) => void;
|
|
54
64
|
emitter: EmitterType;
|
|
55
65
|
boxEmitter: BoxEmitterType;
|
|
56
66
|
callbacks: CallbacksType;
|
|
@@ -67,11 +77,22 @@ export const createBoxManager = (
|
|
|
67
77
|
boxEmitter: BoxEmitterType,
|
|
68
78
|
options: CreateTeleBoxManagerConfig
|
|
69
79
|
) => {
|
|
70
|
-
|
|
80
|
+
const BoxManagerClass = getExtendClass(BoxManager, WindowManager.extendClass);
|
|
81
|
+
return new BoxManagerClass(
|
|
71
82
|
{
|
|
72
83
|
safeSetAttributes: (attributes: any) => manager.safeSetAttributes(attributes),
|
|
73
84
|
getMainView: () => manager.mainView,
|
|
74
85
|
updateAppState: (...args) => manager.appManager?.store.updateAppState(...args),
|
|
86
|
+
setBoxStatus: (id: string, boxStatus?: TeleBoxState) =>
|
|
87
|
+
manager.appManager?.store.setBoxStatus(id, boxStatus),
|
|
88
|
+
setLastNotMinimizedBoxStatus: (
|
|
89
|
+
id: string,
|
|
90
|
+
lastNotMinimizedBoxStatus?: NotMinimizedBoxState
|
|
91
|
+
) =>
|
|
92
|
+
manager.appManager?.store.setLastNotMinimizedBoxStatus(
|
|
93
|
+
id,
|
|
94
|
+
lastNotMinimizedBoxStatus
|
|
95
|
+
),
|
|
75
96
|
canOperate: () => manager.canOperate,
|
|
76
97
|
notifyContainerRectUpdate: (rect: TeleBoxRect) =>
|
|
77
98
|
manager.appManager?.notifyContainerRectUpdate(rect),
|
|
@@ -86,6 +107,7 @@ export const createBoxManager = (
|
|
|
86
107
|
};
|
|
87
108
|
|
|
88
109
|
export class BoxManager {
|
|
110
|
+
static readonly kind = "BoxManager";
|
|
89
111
|
public teleBoxManager: TeleBoxManager;
|
|
90
112
|
|
|
91
113
|
constructor(
|
|
@@ -167,9 +189,32 @@ export class BoxManager {
|
|
|
167
189
|
}
|
|
168
190
|
}
|
|
169
191
|
});
|
|
192
|
+
this.teleBoxManager.events.on("blurred", box => {
|
|
193
|
+
if (box) {
|
|
194
|
+
if (this.canOperate) {
|
|
195
|
+
boxEmitter.emit("blurred", { appId: box.id });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
170
199
|
this.teleBoxManager.events.on("z_index", box => {
|
|
171
200
|
this.context.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
|
|
172
201
|
});
|
|
202
|
+
this.teleBoxManager.events.on(
|
|
203
|
+
"box_status",
|
|
204
|
+
(box: { id: string; boxStatus?: TeleBoxState }) => {
|
|
205
|
+
if (this.canOperate) {
|
|
206
|
+
this.context.setBoxStatus(box.id, box.boxStatus);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
this.teleBoxManager.events.on(
|
|
211
|
+
"last_not_minimized_box_status",
|
|
212
|
+
(box: { id: string; boxStatus?: NotMinimizedBoxState }) => {
|
|
213
|
+
if (this.canOperate) {
|
|
214
|
+
this.context.setLastNotMinimizedBoxStatus(box.id, box.boxStatus);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
);
|
|
173
218
|
emitter.on("playgroundSizeChange", () => this.updateManagerRect());
|
|
174
219
|
emitter.on("updateManagerRect", () => this.updateManagerRect());
|
|
175
220
|
}
|
|
@@ -228,6 +273,10 @@ export class BoxManager {
|
|
|
228
273
|
width,
|
|
229
274
|
height,
|
|
230
275
|
id: params.appId,
|
|
276
|
+
boxStatus: params.boxStatus,
|
|
277
|
+
forceTop: params.forceTop,
|
|
278
|
+
forceNormal: params.forceNormal,
|
|
279
|
+
isDragContent: params.isDragContent,
|
|
231
280
|
};
|
|
232
281
|
this.teleBoxManager.create(createBoxConfig, params.smartPosition);
|
|
233
282
|
this.context.emitter.emit(`${params.appId}${Events.WindowCreated}` as any);
|
|
@@ -247,6 +296,27 @@ export class BoxManager {
|
|
|
247
296
|
}
|
|
248
297
|
}
|
|
249
298
|
}
|
|
299
|
+
public setBoxesStatus(status?: Record<string, TeleBoxState>): void {
|
|
300
|
+
const map = new Map(Object.entries(status ?? {}));
|
|
301
|
+
this.teleBoxManager.setBoxesStatus(map, true);
|
|
302
|
+
this.context.callbacks.emit("onBoxesStatusChange", map);
|
|
303
|
+
this.context.emitter.emit("boxesStatusChange", map);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// public setBoxStatus(appId: string, status?: TeleBoxState, skipUpdate = false): void {
|
|
307
|
+
// this.teleBoxManager.update(appId, { boxStatus: status }, true);
|
|
308
|
+
// }
|
|
309
|
+
|
|
310
|
+
public setLastNotMinimizedBoxesStatus(status?: Record<string, NotMinimizedBoxState>): void {
|
|
311
|
+
const map = new Map(Object.entries(status ?? {}));
|
|
312
|
+
this.teleBoxManager.setLastNotMinimizedBoxesStatus(map, true);
|
|
313
|
+
this.context.callbacks.emit("onLastNotMinimizedBoxesStatusChange", map);
|
|
314
|
+
this.context.emitter.emit("lastNotMinimizedBoxesStatusChange", map);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// public setLastNotMinimizedBoxStatus(appId: string, status?: NotMinimizedBoxState): void {
|
|
318
|
+
// this.teleBoxManager.update(appId, { lastNotMinimizedBoxStatus: status }, true);
|
|
319
|
+
// }
|
|
250
320
|
|
|
251
321
|
public setupBoxManager(
|
|
252
322
|
createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig
|
|
@@ -263,9 +333,11 @@ export class BoxManager {
|
|
|
263
333
|
},
|
|
264
334
|
fence: false,
|
|
265
335
|
prefersColorScheme: createTeleBoxManagerConfig?.prefersColorScheme,
|
|
336
|
+
useBoxesStatus: createTeleBoxManagerConfig?.useBoxesStatus || false,
|
|
266
337
|
};
|
|
267
338
|
|
|
268
|
-
const
|
|
339
|
+
const TeleBoxManagerClass = getExtendClass(TeleBoxManager, WindowManager.extendClass);
|
|
340
|
+
const manager = new TeleBoxManagerClass(initManagerState);
|
|
269
341
|
if (this.teleBoxManager) {
|
|
270
342
|
this.teleBoxManager.destroy();
|
|
271
343
|
}
|
|
@@ -278,7 +350,8 @@ export class BoxManager {
|
|
|
278
350
|
}
|
|
279
351
|
|
|
280
352
|
public setCollectorContainer(container: HTMLElement) {
|
|
281
|
-
const
|
|
353
|
+
const TeleBoxCollectorClass = getExtendClass(TeleBoxCollector, WindowManager.extendClass);
|
|
354
|
+
const collector = new TeleBoxCollectorClass({
|
|
282
355
|
styles: this.createTeleBoxManagerConfig?.collectorStyles,
|
|
283
356
|
}).mount(container);
|
|
284
357
|
this.teleBoxManager.setCollector(collector);
|
|
@@ -318,6 +391,11 @@ export class BoxManager {
|
|
|
318
391
|
width: state.width || 0.5,
|
|
319
392
|
height: state.height || 0.5,
|
|
320
393
|
zIndex: state.zIndex,
|
|
394
|
+
boxStatus: state.boxStatus,
|
|
395
|
+
lastNotMinimizedBoxStatus: state.lastNotMinimizedBoxStatus,
|
|
396
|
+
forceTop: state.forceTop,
|
|
397
|
+
forceNormal: state.forceNormal,
|
|
398
|
+
isDragContent: state.isDragContent,
|
|
321
399
|
},
|
|
322
400
|
true
|
|
323
401
|
);
|
package/src/Cursor/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ export type MoveCursorParams = {
|
|
|
26
26
|
const LocalCursorSideEffectId = "local-cursor";
|
|
27
27
|
|
|
28
28
|
export class CursorManager {
|
|
29
|
+
static readonly kind = "CursorManager";
|
|
29
30
|
public containerRect?: DOMRect;
|
|
30
31
|
public wrapperRect?: DOMRect;
|
|
31
32
|
public cursorInstances: Map<string, Cursor> = new Map();
|
package/src/InternalEmitter.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Emittery from "emittery";
|
|
2
2
|
import type { AppInitState, CursorMovePayload } from "./index";
|
|
3
|
+
import type { NotMinimizedBoxState, TeleBoxState } from "@netless/telebox-insider";
|
|
3
4
|
|
|
4
5
|
export type RemoveSceneParams = {
|
|
5
6
|
scenePath: string;
|
|
@@ -28,6 +29,8 @@ export type EmitterEvent = {
|
|
|
28
29
|
changePageState: undefined;
|
|
29
30
|
writableChange: boolean;
|
|
30
31
|
containerSizeRatioUpdate: number;
|
|
32
|
+
boxesStatusChange: Map<string, TeleBoxState>;
|
|
33
|
+
lastNotMinimizedBoxesStatusChange: Map<string, NotMinimizedBoxState>;
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
export type EmitterType = Emittery<EmitterEvent>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AppContext, AppProxy } from "../App";
|
|
2
|
+
import { AppManager } from "../AppManager";
|
|
3
|
+
import { AttributesDelegate } from "../AttributesDelegate";
|
|
4
|
+
import { BoxManager } from "../BoxManager";
|
|
5
|
+
import { CursorManager } from "../Cursor";
|
|
6
|
+
import { TeleBoxManager, TeleBoxCollector } from "@netless/telebox-insider";
|
|
7
|
+
|
|
8
|
+
export { AppManager } from "../AppManager";
|
|
9
|
+
export { AppContext, AppProxy } from "../App";
|
|
10
|
+
export { BoxManager } from "../BoxManager";
|
|
11
|
+
export { AttributesDelegate } from "../AttributesDelegate";
|
|
12
|
+
export { CursorManager } from "../Cursor";
|
|
13
|
+
export { TeleBoxManager, TeleBoxCollector } from "@netless/telebox-insider";
|
|
14
|
+
|
|
15
|
+
export type ExtendClassAble =
|
|
16
|
+
| typeof AppManager
|
|
17
|
+
| typeof AppProxy
|
|
18
|
+
| typeof AppContext
|
|
19
|
+
| typeof BoxManager
|
|
20
|
+
| typeof AttributesDelegate
|
|
21
|
+
| typeof CursorManager
|
|
22
|
+
| typeof TeleBoxManager
|
|
23
|
+
| typeof TeleBoxCollector;
|
|
24
|
+
|
|
25
|
+
export type ExtendClass = {
|
|
26
|
+
AppManager?: typeof AppManager;
|
|
27
|
+
BoxManager?: typeof BoxManager;
|
|
28
|
+
AttributesDelegate?: typeof AttributesDelegate;
|
|
29
|
+
CursorManager?: typeof CursorManager;
|
|
30
|
+
AppProxy?: typeof AppProxy;
|
|
31
|
+
AppContext?: typeof AppContext;
|
|
32
|
+
TeleBoxManager?: typeof TeleBoxManager;
|
|
33
|
+
TeleBoxCollector?: typeof TeleBoxCollector;
|
|
34
|
+
};
|
|
35
|
+
export function getExtendClass<T extends ExtendClassAble>(
|
|
36
|
+
baseClass: T,
|
|
37
|
+
extendClass?: ExtendClass
|
|
38
|
+
): T {
|
|
39
|
+
if (baseClass.kind && extendClass && Object.keys(extendClass).includes(baseClass.kind)) {
|
|
40
|
+
switch (baseClass.kind) {
|
|
41
|
+
case "AppManager":
|
|
42
|
+
return (extendClass?.AppManager || AppManager) as T;
|
|
43
|
+
case "BoxManager":
|
|
44
|
+
return (extendClass?.BoxManager || BoxManager) as T;
|
|
45
|
+
case "AttributesDelegate":
|
|
46
|
+
return (extendClass?.AttributesDelegate || AttributesDelegate) as T;
|
|
47
|
+
case "CursorManager":
|
|
48
|
+
return (extendClass?.CursorManager || CursorManager) as T;
|
|
49
|
+
case "AppProxy":
|
|
50
|
+
return (extendClass?.AppProxy || AppProxy) as T;
|
|
51
|
+
case "AppContext":
|
|
52
|
+
return (extendClass?.AppContext || AppContext) as T;
|
|
53
|
+
case "TeleBoxManager":
|
|
54
|
+
return (extendClass?.TeleBoxManager || TeleBoxManager) as T;
|
|
55
|
+
case "TeleBoxCollector":
|
|
56
|
+
return (extendClass?.TeleBoxCollector || TeleBoxCollector) as T;
|
|
57
|
+
default:
|
|
58
|
+
return baseClass;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return baseClass;
|
|
62
|
+
}
|
package/src/callback.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import Emittery from "emittery";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
TeleBoxColorScheme,
|
|
4
|
+
TELE_BOX_STATE,
|
|
5
|
+
TeleBoxState,
|
|
6
|
+
NotMinimizedBoxState,
|
|
7
|
+
} from "@netless/telebox-insider";
|
|
3
8
|
import type { CameraState, SceneState, View, ViewVisionMode } from "white-web-sdk";
|
|
4
9
|
import type { LoadAppEvent } from "./Register";
|
|
5
10
|
import type { PageState } from "./Page";
|
|
6
11
|
import type {
|
|
12
|
+
BoxBlurredPayload,
|
|
7
13
|
BoxClosePayload,
|
|
8
14
|
BoxFocusPayload,
|
|
9
15
|
BoxMovePayload,
|
|
@@ -33,6 +39,7 @@ export type PublicEvent = {
|
|
|
33
39
|
onBoxMove: BoxMovePayload;
|
|
34
40
|
onBoxResize: BoxResizePayload;
|
|
35
41
|
onBoxFocus: BoxFocusPayload;
|
|
42
|
+
onBoxBlurred: BoxBlurredPayload;
|
|
36
43
|
onBoxClose: BoxClosePayload;
|
|
37
44
|
onBoxStateChange: BoxStateChangePayload;
|
|
38
45
|
onMainViewMounted: View;
|
|
@@ -40,6 +47,8 @@ export type PublicEvent = {
|
|
|
40
47
|
onAppViewMounted: AppPayload;
|
|
41
48
|
onAppSetup: string;
|
|
42
49
|
onAppScenePathChange: AppPayload;
|
|
50
|
+
onBoxesStatusChange: Map<string, TeleBoxState>;
|
|
51
|
+
onLastNotMinimizedBoxesStatusChange: Map<string, NotMinimizedBoxState>;
|
|
43
52
|
};
|
|
44
53
|
|
|
45
54
|
export type CallbacksType = Emittery<PublicEvent>;
|