@netless/window-manager 0.2.18 → 0.2.19-canary.0
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/AppListener.d.ts +1 -5
- package/dist/AppManager.d.ts +1 -0
- package/dist/AttributesDelegate.d.ts +0 -1
- package/dist/Cursor/Cursor.d.ts +0 -1
- package/dist/Cursor/index.d.ts +9 -10
- package/dist/MainView.d.ts +10 -1
- package/dist/ViewManager.d.ts +3 -14
- package/dist/constants.d.ts +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/AppListener.ts +0 -4
- package/src/AppManager.ts +23 -11
- package/src/AppProxy.ts +8 -4
- package/src/AttributesDelegate.ts +0 -10
- package/src/Cursor/Cursor.ts +0 -4
- package/src/Cursor/index.ts +59 -70
- package/src/MainView.ts +78 -13
- package/src/constants.ts +1 -1
- package/src/index.ts +7 -26
- package/src/viewManager.ts +12 -97
package/src/viewManager.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
+
import { Base } from './Base';
|
1
2
|
import { callbacks, WindowManager } from './index';
|
2
|
-
import { debounce } from 'lodash';
|
3
3
|
import { reaction, ViewVisionMode } from 'white-web-sdk';
|
4
4
|
import { SET_SCENEPATH_DELAY } from './constants';
|
5
5
|
import { TELE_BOX_STATE } from '@netless/telebox-insider';
|
@@ -9,16 +9,14 @@ import {
|
|
9
9
|
setViewFocusScenePath,
|
10
10
|
setViewMode,
|
11
11
|
} from "./Utils/Common";
|
12
|
-
import type {
|
12
|
+
import type { Displayer, View } from "white-web-sdk";
|
13
13
|
import type { AppManager } from "./AppManager";
|
14
14
|
import type { CameraStore } from "./Utils/CameraStore";
|
15
|
-
import { Base } from './Base';
|
16
15
|
|
17
16
|
export class ViewManager extends Base {
|
18
|
-
public mainView: View;
|
19
17
|
private views: Map<string, View> = new Map();
|
20
|
-
private mainViewIsAddListener = false;
|
21
18
|
private timer?: number;
|
19
|
+
private mainViewProxy = this.manager.mainViewProxy;
|
22
20
|
|
23
21
|
constructor(
|
24
22
|
private displayer: Displayer,
|
@@ -26,8 +24,6 @@ export class ViewManager extends Base {
|
|
26
24
|
private cameraStore: CameraStore
|
27
25
|
) {
|
28
26
|
super(manager);
|
29
|
-
this.mainView = this.createMainView();
|
30
|
-
this.addMainViewCameraListener();
|
31
27
|
setTimeout(() => { // 延迟初始化 focus 的 reaction
|
32
28
|
this.manager.refresher?.add("focus", () => {
|
33
29
|
return reaction(
|
@@ -37,38 +33,23 @@ export class ViewManager extends Base {
|
|
37
33
|
this.switchAppToWriter(focus);
|
38
34
|
} else {
|
39
35
|
this.switchMainViewToWriter();
|
36
|
+
this.manager.boxManager.blurFocusBox();
|
40
37
|
}
|
41
38
|
},
|
42
39
|
{ fireImmediately: true }
|
43
40
|
)
|
44
41
|
});
|
45
|
-
}, 100)
|
42
|
+
}, 100);
|
46
43
|
}
|
47
44
|
|
48
45
|
public get currentScenePath(): string {
|
49
46
|
return this.displayer.state.sceneState.scenePath;
|
50
47
|
}
|
51
48
|
|
52
|
-
public
|
53
|
-
|
54
|
-
this.cameraStore.setCamera("mainView", mainView.camera);
|
55
|
-
mainView.callbacks.on("onSizeUpdated", () => {
|
56
|
-
this.manager.boxManager.updateManagerRect();
|
57
|
-
});
|
58
|
-
const mainViewScenePath = this.store.getMainViewScenePath();
|
59
|
-
if (mainViewScenePath) {
|
60
|
-
setViewFocusScenePath(mainView, mainViewScenePath);
|
61
|
-
}
|
62
|
-
if (!this.store.focus) {
|
63
|
-
this.switchMainViewModeToWriter();
|
64
|
-
}
|
65
|
-
return mainView;
|
49
|
+
public get mainView(): View {
|
50
|
+
return this.mainViewProxy.view;
|
66
51
|
}
|
67
52
|
|
68
|
-
public setMainViewSize = debounce(size => {
|
69
|
-
this.store.setMainViewSize({ ...size });
|
70
|
-
}, 200);
|
71
|
-
|
72
53
|
public createView(appId: string): View {
|
73
54
|
const view = this.displayer.views.createView();
|
74
55
|
this.cameraStore.setCamera(appId, view.camera);
|
@@ -95,76 +76,20 @@ export class ViewManager extends Base {
|
|
95
76
|
return this.views.get(appId);
|
96
77
|
}
|
97
78
|
|
98
|
-
private addMainViewCameraListener() {
|
99
|
-
this.mainView.callbacks.on("onCameraUpdated", this.mainViewCameraListener);
|
100
|
-
}
|
101
|
-
|
102
|
-
private removeMainViewCameraListener() {
|
103
|
-
this.mainView.callbacks.off("onCameraUpdated", this.mainViewCameraListener);
|
104
|
-
}
|
105
|
-
|
106
|
-
public switchMainViewToFreedom(): void {
|
107
|
-
this.store.setMainViewFocusPath();
|
108
|
-
notifyMainViewModeChange(callbacks, ViewVisionMode.Freedom);
|
109
|
-
setViewMode(this.mainView, ViewVisionMode.Freedom);
|
110
|
-
}
|
111
|
-
|
112
|
-
public switchMainViewModeToWriter(): void {
|
113
|
-
if (!this.manager.canOperate) return;
|
114
|
-
if (this.mainView) {
|
115
|
-
if (this.mainView.mode === ViewVisionMode.Writable) return;
|
116
|
-
notifyMainViewModeChange(callbacks, ViewVisionMode.Writable);
|
117
|
-
setViewMode(this.mainView, ViewVisionMode.Writable);
|
118
|
-
}
|
119
|
-
}
|
120
|
-
|
121
|
-
public addMainViewListener(): void {
|
122
|
-
if (this.mainViewIsAddListener) return;
|
123
|
-
if (this.mainView.divElement) {
|
124
|
-
this.mainView.divElement.addEventListener("click", this.mainViewClickListener);
|
125
|
-
this.mainView.divElement.addEventListener("touchend", this.mainViewClickListener);
|
126
|
-
this.mainViewIsAddListener = true;
|
127
|
-
}
|
128
|
-
}
|
129
|
-
|
130
|
-
public removeMainViewListener(): void {
|
131
|
-
if (this.mainView.divElement) {
|
132
|
-
this.mainView.divElement.removeEventListener("click", this.mainViewClickListener);
|
133
|
-
this.mainView.divElement.removeEventListener("touchend", this.mainViewClickListener);
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
|
-
private mainViewClickListener = () => {
|
138
|
-
this.mainViewClickHandler();
|
139
|
-
};
|
140
|
-
|
141
|
-
public async mainViewClickHandler(): Promise<void> {
|
142
|
-
if (!this.manager.canOperate) return;
|
143
|
-
if (this.mainView.mode === ViewVisionMode.Writable) return;
|
144
|
-
this.store.cleanFocus();
|
145
|
-
this.manager.boxManager.blurFocusBox();
|
146
|
-
}
|
147
|
-
|
148
|
-
private mainViewCameraListener = (camera: Camera) => {
|
149
|
-
this.cameraStore.setCamera("mainView", camera);
|
150
|
-
};
|
151
|
-
|
152
79
|
public switchMainViewToWriter(): Promise<boolean> | undefined {
|
153
80
|
if (this.timer) {
|
154
81
|
clearTimeout(this.timer);
|
155
82
|
}
|
156
83
|
if (this.mainView.mode === ViewVisionMode.Writable) return;
|
84
|
+
this.freedomAllViews();
|
157
85
|
return new Promise((resolve, reject) => {
|
158
86
|
this.timer = window.setTimeout(() => {
|
159
87
|
try {
|
160
88
|
const mainViewScenePath = this.store.getMainViewScenePath();
|
161
89
|
if (mainViewScenePath) {
|
162
90
|
this.freedomAllViews();
|
163
|
-
this.removeMainViewCameraListener();
|
164
91
|
setScenePath(this.manager.room, mainViewScenePath);
|
165
|
-
this.
|
166
|
-
this.manager.cameraStore.recoverCamera("mainView", this.mainView);
|
167
|
-
this.addMainViewCameraListener();
|
92
|
+
this.mainViewProxy.switchViewModeToWriter();
|
168
93
|
}
|
169
94
|
resolve(true);
|
170
95
|
} catch (error) {
|
@@ -179,15 +104,8 @@ export class ViewManager extends Base {
|
|
179
104
|
this.setMainViewFocusScenePath();
|
180
105
|
if (focus) {
|
181
106
|
const appProxy = this.manager.appProxies.get(focus);
|
182
|
-
|
183
|
-
if (appProxy.view?.mode === ViewVisionMode.Writable) return;
|
184
|
-
appProxy.removeCameraListener();
|
185
|
-
appProxy.switchToWritable();
|
186
|
-
appProxy.recoverCamera();
|
187
|
-
appProxy.addCameraListener();
|
188
|
-
}
|
107
|
+
appProxy?.switchToWritable();
|
189
108
|
} else {
|
190
|
-
if (this.manager.mainView.mode === ViewVisionMode.Writable) return;
|
191
109
|
this.switchMainViewToWriter();
|
192
110
|
}
|
193
111
|
}
|
@@ -210,7 +128,7 @@ export class ViewManager extends Base {
|
|
210
128
|
notifyMainViewModeChange(callbacks, ViewVisionMode.Freedom);
|
211
129
|
this.mainView.mode = ViewVisionMode.Freedom;
|
212
130
|
}
|
213
|
-
if (!this.
|
131
|
+
if (!this.mainView.focusScenePath) {
|
214
132
|
this.store.setMainViewFocusPath();
|
215
133
|
}
|
216
134
|
}
|
@@ -225,18 +143,15 @@ export class ViewManager extends Base {
|
|
225
143
|
if (boxState && boxState === TELE_BOX_STATE.Minimized) {
|
226
144
|
return;
|
227
145
|
}
|
228
|
-
appProxy.removeCameraListener();
|
229
146
|
appProxy.setScenePath();
|
230
147
|
appProxy.switchToWritable();
|
231
|
-
appProxy.recoverCamera();
|
232
|
-
appProxy.addCameraListener();
|
233
148
|
appProxy.focusBox();
|
234
149
|
}
|
235
150
|
}, SET_SCENEPATH_DELAY);
|
236
151
|
}
|
237
152
|
|
238
153
|
public destroy(): void {
|
239
|
-
this.removeMainViewListener();
|
154
|
+
this.mainViewProxy.removeMainViewListener();
|
240
155
|
if (WindowManager.wrapper) {
|
241
156
|
WindowManager.wrapper.parentNode?.removeChild(WindowManager.wrapper);
|
242
157
|
WindowManager.wrapper = undefined;
|