@netless/window-manager 0.3.4 → 0.3.5-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 +0 -1
- package/dist/AppManager.d.ts +8 -8
- package/dist/Base/Context.d.ts +0 -2
- package/dist/BoxManager.d.ts +0 -1
- package/dist/Cursor/index.d.ts +1 -0
- 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/dist/typings.d.ts +1 -0
- package/package.json +1 -1
- package/src/AppContext.ts +1 -1
- package/src/AppListener.ts +0 -8
- package/src/AppManager.ts +42 -93
- package/src/AppProxy.ts +1 -0
- package/src/Base/Context.ts +0 -5
- package/src/BoxManager.ts +0 -8
- package/src/Cursor/Cursor.ts +3 -3
- package/src/Cursor/index.ts +13 -8
- package/src/index.ts +3 -2
- package/src/typings.ts +1 -0
- package/src/viewManager.ts +1 -1
package/dist/typings.d.ts
CHANGED
@@ -56,6 +56,7 @@ export declare type RegisterEvents<SetupResult = any> = {
|
|
56
56
|
result: SetupResult;
|
57
57
|
};
|
58
58
|
destroy: RegisterEventData;
|
59
|
+
focus: RegisterEventData;
|
59
60
|
};
|
60
61
|
export declare type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any> = {
|
61
62
|
kind: string;
|
package/package.json
CHANGED
package/src/AppContext.ts
CHANGED
@@ -102,7 +102,7 @@ export class AppContext<TAttrs extends Record<string, any>, AppOptions = any> {
|
|
102
102
|
public async setScenePath(scenePath: string): Promise<void> {
|
103
103
|
if (!this.appProxy.box) return;
|
104
104
|
this.appProxy.setFullPath(scenePath);
|
105
|
-
this.
|
105
|
+
this.appProxy.context.switchAppToWriter(this.appId);
|
106
106
|
}
|
107
107
|
|
108
108
|
public mountView(dom: HTMLDivElement): void {
|
package/src/AppListener.ts
CHANGED
@@ -28,10 +28,6 @@ export class AppListeners {
|
|
28
28
|
this.appResizeHandler(data.payload);
|
29
29
|
break;
|
30
30
|
}
|
31
|
-
case Events.AppBoxStateChange: {
|
32
|
-
this.appBoxStateHandler(data.payload);
|
33
|
-
break;
|
34
|
-
}
|
35
31
|
case Events.SwitchViewsToFreedom: {
|
36
32
|
this.switchViewsToFreedomHandler();
|
37
33
|
break;
|
@@ -51,10 +47,6 @@ export class AppListeners {
|
|
51
47
|
this.manager.room?.refreshViewSize();
|
52
48
|
};
|
53
49
|
|
54
|
-
private appBoxStateHandler = (payload: any) => {
|
55
|
-
this.boxManager.setBoxState(payload.state);
|
56
|
-
};
|
57
|
-
|
58
50
|
private switchViewsToFreedomHandler = () => {
|
59
51
|
this.manager.viewManager.freedomAllViews();
|
60
52
|
};
|
package/src/AppManager.ts
CHANGED
@@ -1,31 +1,20 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
import {
|
12
|
-
import {
|
13
|
-
import {
|
14
|
-
import {
|
15
|
-
autorun,
|
16
|
-
isPlayer,
|
17
|
-
isRoom,
|
18
|
-
ScenePathType,
|
19
|
-
ViewVisionMode
|
20
|
-
} from 'white-web-sdk';
|
21
|
-
import { log } from './Utils/log';
|
22
|
-
import { MainViewProxy } from './MainView';
|
23
|
-
import { onObjectInserted, onObjectRemoved } from './Utils/Reactive';
|
24
|
-
import { ReconnectRefresher } from './ReconnectRefresher';
|
25
|
-
import { ViewManager } from './ViewManager';
|
1
|
+
import { AppAttributes, AppStatus, Events, MagixEventName } from "./constants";
|
2
|
+
import { AppListeners } from "./AppListener";
|
3
|
+
import { AppProxy } from "./AppProxy";
|
4
|
+
import { AttributesDelegate } from "./AttributesDelegate";
|
5
|
+
import { BoxManager, TELE_BOX_STATE } from "./BoxManager";
|
6
|
+
import { callbacks, emitter } from "./index";
|
7
|
+
import { CameraStore } from "./Utils/CameraStore";
|
8
|
+
import { genAppId, makeValidScenePath, setScenePath } from "./Utils/Common";
|
9
|
+
import { autorun, isPlayer, isRoom, ScenePathType, ViewVisionMode } from "white-web-sdk";
|
10
|
+
import { log } from "./Utils/log";
|
11
|
+
import { MainViewProxy } from "./MainView";
|
12
|
+
import { onObjectInserted, onObjectRemoved } from "./Utils/Reactive";
|
13
|
+
import { ReconnectRefresher } from "./ReconnectRefresher";
|
14
|
+
import { ViewManager } from "./ViewManager";
|
26
15
|
import type { Displayer, DisplayerState, Room } from "white-web-sdk";
|
27
16
|
import type { CreateCollectorConfig } from "./BoxManager";
|
28
|
-
import type { AddAppParams, BaseInsertParams, WindowManager
|
17
|
+
import type { AddAppParams, BaseInsertParams, WindowManager, TeleBoxRect } from "./index";
|
29
18
|
export class AppManager {
|
30
19
|
public displayer: Displayer;
|
31
20
|
public boxManager: BoxManager;
|
@@ -39,7 +28,6 @@ export class AppManager {
|
|
39
28
|
|
40
29
|
private appListeners: AppListeners;
|
41
30
|
|
42
|
-
|
43
31
|
constructor(public windowManger: WindowManager, options: CreateCollectorConfig) {
|
44
32
|
this.displayer = windowManger.displayer;
|
45
33
|
this.cameraStore = new CameraStore();
|
@@ -78,24 +66,30 @@ export class AppManager {
|
|
78
66
|
});
|
79
67
|
});
|
80
68
|
this.refresher?.add("maximized", () => {
|
81
|
-
return autorun(
|
82
|
-
|
83
|
-
|
84
|
-
if (this.boxManager.
|
85
|
-
this.boxManager.
|
69
|
+
return autorun(() => {
|
70
|
+
const maximized = this.attributes.maximized;
|
71
|
+
if (this.boxManager.maximized !== maximized) {
|
72
|
+
if (maximized === true && this.boxManager.minimized === false) {
|
73
|
+
const topBox = this.boxManager.getTopBox();
|
74
|
+
if (topBox) {
|
75
|
+
emitter.emit("focus", { appId: topBox.id });
|
76
|
+
}
|
86
77
|
}
|
78
|
+
this.boxManager.setMaximized(Boolean(maximized));
|
87
79
|
}
|
88
|
-
)
|
80
|
+
});
|
89
81
|
});
|
90
82
|
this.refresher?.add("minimized", () => {
|
91
|
-
return autorun(
|
92
|
-
|
93
|
-
|
94
|
-
if (
|
95
|
-
this.
|
83
|
+
return autorun(() => {
|
84
|
+
const minimized = this.attributes.minimized;
|
85
|
+
if (this.boxManager.minimized !== minimized) {
|
86
|
+
if (minimized === true) {
|
87
|
+
this.store.cleanFocus();
|
88
|
+
this.boxManager.blurFocusBox();
|
96
89
|
}
|
90
|
+
this.boxManager.setMinimized(Boolean(minimized));
|
97
91
|
}
|
98
|
-
)
|
92
|
+
});
|
99
93
|
});
|
100
94
|
if (!this.attributes.apps || Object.keys(this.attributes.apps).length === 0) {
|
101
95
|
const mainScenePath = this.store.getMainViewScenePath();
|
@@ -142,7 +136,7 @@ export class AppManager {
|
|
142
136
|
appProxy.destroy(true, false);
|
143
137
|
}
|
144
138
|
});
|
145
|
-
}
|
139
|
+
};
|
146
140
|
|
147
141
|
public bindMainView(divElement: HTMLDivElement, disableCameraTransform: boolean) {
|
148
142
|
const mainView = this.mainViewProxy.view;
|
@@ -151,10 +145,7 @@ export class AppManager {
|
|
151
145
|
if (!mainView.focusScenePath) {
|
152
146
|
this.store.setMainViewFocusPath();
|
153
147
|
}
|
154
|
-
if (
|
155
|
-
this.store.focus === undefined &&
|
156
|
-
mainView.mode !== ViewVisionMode.Writable
|
157
|
-
) {
|
148
|
+
if (this.store.focus === undefined && mainView.mode !== ViewVisionMode.Writable) {
|
158
149
|
this.viewManager.switchMainViewToWriter();
|
159
150
|
}
|
160
151
|
this.mainViewProxy.addMainViewListener();
|
@@ -172,16 +163,16 @@ export class AppManager {
|
|
172
163
|
private async beforeAddApp(params: AddAppParams, isDynamicPPT: boolean) {
|
173
164
|
const appId = await genAppId(params.kind);
|
174
165
|
this.appStatus.set(appId, AppStatus.StartCreate);
|
166
|
+
const attrs = params.attributes ?? {};
|
167
|
+
this.safeUpdateAttributes([appId], attrs);
|
175
168
|
this.store.setupAppAttributes(params, appId, isDynamicPPT);
|
176
|
-
if (this.boxManager.
|
177
|
-
this.boxManager.
|
169
|
+
if (this.boxManager.minimized) {
|
170
|
+
this.boxManager.setMinimized(false);
|
178
171
|
}
|
179
|
-
const needFocus = this.boxManager.
|
172
|
+
const needFocus = !this.boxManager.minimized;
|
180
173
|
if (needFocus) {
|
181
174
|
this.store.setAppFocus(appId, true);
|
182
175
|
}
|
183
|
-
const attrs = params.attributes ?? {};
|
184
|
-
this.safeUpdateAttributes([appId], attrs);
|
185
176
|
return { appId, needFocus };
|
186
177
|
}
|
187
178
|
|
@@ -243,7 +234,7 @@ export class AppManager {
|
|
243
234
|
appProxy.appEmitter.emit("roomStateChange", state);
|
244
235
|
});
|
245
236
|
emitter.emit("observerIdChange", this.displayer.observerId);
|
246
|
-
}
|
237
|
+
};
|
247
238
|
|
248
239
|
private displayerWritableListener = (isReadonly: boolean) => {
|
249
240
|
const isWritable = !isReadonly;
|
@@ -265,7 +256,7 @@ export class AppManager {
|
|
265
256
|
} else {
|
266
257
|
this.mainView.disableCameraTransform = true;
|
267
258
|
}
|
268
|
-
}
|
259
|
+
};
|
269
260
|
|
270
261
|
private get eventName() {
|
271
262
|
return isRoom(this.displayer) ? "onRoomStateChanged" : "onPlayerStateChanged";
|
@@ -359,10 +350,6 @@ export class AppManager {
|
|
359
350
|
this.windowManger.safeSetAttributes({ focus: payload.appId });
|
360
351
|
break;
|
361
352
|
}
|
362
|
-
case "blur": {
|
363
|
-
this.dispatchInternalEvent(Events.AppBlur, payload);
|
364
|
-
break;
|
365
|
-
}
|
366
353
|
case "resize": {
|
367
354
|
if (payload.width && payload.height) {
|
368
355
|
this.dispatchInternalEvent(Events.AppResize, payload);
|
@@ -373,44 +360,6 @@ export class AppManager {
|
|
373
360
|
}
|
374
361
|
break;
|
375
362
|
}
|
376
|
-
case TELE_BOX_STATE.Minimized: {
|
377
|
-
this.safeDispatchMagixEvent(MagixEventName, {
|
378
|
-
eventName: Events.AppBoxStateChange,
|
379
|
-
payload: {
|
380
|
-
...payload,
|
381
|
-
state: eventName,
|
382
|
-
},
|
383
|
-
});
|
384
|
-
|
385
|
-
this.store.cleanFocus();
|
386
|
-
this.boxManager.blurFocusBox();
|
387
|
-
break;
|
388
|
-
}
|
389
|
-
case TELE_BOX_STATE.Maximized: {
|
390
|
-
this.safeDispatchMagixEvent(MagixEventName, {
|
391
|
-
eventName: Events.AppBoxStateChange,
|
392
|
-
payload: {
|
393
|
-
...payload,
|
394
|
-
state: eventName,
|
395
|
-
},
|
396
|
-
});
|
397
|
-
const topBox = this.boxManager.getTopBox();
|
398
|
-
if (topBox) {
|
399
|
-
emitter.emit("focus", { appId: topBox.id });
|
400
|
-
}
|
401
|
-
break;
|
402
|
-
}
|
403
|
-
case TELE_BOX_STATE.Normal: {
|
404
|
-
this.safeDispatchMagixEvent(MagixEventName, {
|
405
|
-
eventName: Events.AppBoxStateChange,
|
406
|
-
payload: {
|
407
|
-
...payload,
|
408
|
-
state: eventName,
|
409
|
-
},
|
410
|
-
});
|
411
|
-
this.safeSetAttributes({ boxState: eventName });
|
412
|
-
break;
|
413
|
-
}
|
414
363
|
case "close": {
|
415
364
|
const appProxy = this.appProxies.get(payload.appId);
|
416
365
|
if (appProxy) {
|
package/src/AppProxy.ts
CHANGED
@@ -211,6 +211,7 @@ export class AppProxy extends Base {
|
|
211
211
|
}
|
212
212
|
|
213
213
|
public switchToWritable() {
|
214
|
+
appRegister.notifyApp(this.kind, "focus", { appId: this.id });
|
214
215
|
this.cameraStore.switchView(this.id, this.view, () => {
|
215
216
|
if (this.view) {
|
216
217
|
if (this.view.mode === ViewVisionMode.Writable) return;
|
package/src/Base/Context.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { memoize } from "lodash";
|
2
1
|
import { emitter } from "../index";
|
3
2
|
import type { AppManager } from "../AppManager";
|
4
3
|
|
@@ -27,10 +26,6 @@ export class Context {
|
|
27
26
|
return roomMembers?.find(member => member.payload?.uid === uid);
|
28
27
|
}
|
29
28
|
|
30
|
-
public memoizeFindMember = memoize(this.findMember);
|
31
|
-
|
32
|
-
public memoizeFindMemberByUid = memoize(this.findMemberByUid);
|
33
|
-
|
34
29
|
public updateManagerRect() {
|
35
30
|
this.manager.boxManager.updateManagerRect();
|
36
31
|
}
|
package/src/BoxManager.ts
CHANGED
@@ -225,9 +225,6 @@ export class BoxManager {
|
|
225
225
|
this.teleBoxManager.setMaximized(Boolean(state.maximized), true);
|
226
226
|
this.teleBoxManager.setMinimized(Boolean(state.minimized), true);
|
227
227
|
}
|
228
|
-
if (state.boxState) {
|
229
|
-
this.teleBoxManager.setState(state.boxState, true);
|
230
|
-
}
|
231
228
|
setTimeout(() => {
|
232
229
|
if (state.focus) {
|
233
230
|
this.teleBoxManager.update(box.id, { focus: true }, true);
|
@@ -289,11 +286,6 @@ export class BoxManager {
|
|
289
286
|
this.teleBoxManager.updateAll(config);
|
290
287
|
}
|
291
288
|
|
292
|
-
public setBoxState(state: TELE_BOX_STATE): void {
|
293
|
-
this.teleBoxManager.setState(state, true);
|
294
|
-
callbacks.emit("boxStateChange", state);
|
295
|
-
}
|
296
|
-
|
297
289
|
public setMaximized(maximized: boolean) {
|
298
290
|
this.teleBoxManager.setMaximized(maximized, true);
|
299
291
|
}
|
package/src/Cursor/Cursor.ts
CHANGED
@@ -36,7 +36,7 @@ export class Cursor extends Base {
|
|
36
36
|
pRetry(() => {
|
37
37
|
this.disposer && this.disposer();
|
38
38
|
if (!this.cursorPosition) {
|
39
|
-
|
39
|
+
console.warn(`${memberId} not exist`);
|
40
40
|
}
|
41
41
|
this.startReaction();
|
42
42
|
}, { retries: 3 });
|
@@ -180,8 +180,8 @@ export class Cursor extends Base {
|
|
180
180
|
}
|
181
181
|
|
182
182
|
public setMember() {
|
183
|
-
this.member = this.context.
|
184
|
-
this.component?.$set(omit(this.initProps(), ["x", "y"
|
183
|
+
this.member = this.context.findMemberByUid(this.memberId);
|
184
|
+
this.component?.$set(omit(this.initProps(), ["x", "y"]));
|
185
185
|
}
|
186
186
|
|
187
187
|
public destroy() {
|
package/src/Cursor/index.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Base } from '../Base';
|
2
2
|
import { Cursor } from './Cursor';
|
3
3
|
import { CursorState } from '../constants';
|
4
|
-
import { debounce } from 'lodash';
|
4
|
+
import { compact, debounce, uniq } from 'lodash';
|
5
5
|
import { Fields } from '../AttributesDelegate';
|
6
6
|
import { onObjectInserted } from '../Utils/Reactive';
|
7
7
|
import { WindowManager } from '../index';
|
@@ -54,8 +54,12 @@ export class CursorManager extends Base {
|
|
54
54
|
})
|
55
55
|
}
|
56
56
|
|
57
|
+
private getUids = (members: readonly RoomMember[] | undefined) => {
|
58
|
+
return compact(uniq(members?.map(member => member.payload?.uid)));
|
59
|
+
}
|
60
|
+
|
57
61
|
private handleRoomMembersChange = debounce((wrapper: HTMLElement) => {
|
58
|
-
const uids = this.
|
62
|
+
const uids = this.getUids(this.roomMembers);
|
59
63
|
const cursors = Object.keys(this.cursors);
|
60
64
|
if (uids?.length) {
|
61
65
|
cursors.map(uid => {
|
@@ -199,14 +203,15 @@ export class CursorManager extends Base {
|
|
199
203
|
}
|
200
204
|
|
201
205
|
public cleanMemberAttributes(members: readonly RoomMember[]) {
|
202
|
-
const uids =
|
203
|
-
const needDeleteIds = [];
|
204
|
-
|
205
|
-
|
206
|
+
const uids = this.getUids(members);
|
207
|
+
const needDeleteIds: string[] = [];
|
208
|
+
const cursors = Object.keys(this.cursors);
|
209
|
+
cursors.map(cursorId => {
|
210
|
+
const index = uids.findIndex(id => id === cursorId);
|
206
211
|
if (index === -1) {
|
207
|
-
needDeleteIds.push(
|
212
|
+
needDeleteIds.push(cursorId);
|
208
213
|
}
|
209
|
-
}
|
214
|
+
});
|
210
215
|
needDeleteIds.forEach(uid => {
|
211
216
|
const instance = this.cursorInstances.get(uid);
|
212
217
|
if (instance) {
|
package/src/index.ts
CHANGED
@@ -170,7 +170,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
170
170
|
public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
|
171
171
|
private static isCreated = false;
|
172
172
|
|
173
|
-
public version = "0.3.
|
173
|
+
public version = "0.3.5-canary.0";
|
174
174
|
|
175
175
|
public appListeners?: AppListeners;
|
176
176
|
|
@@ -384,7 +384,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
384
384
|
if (!isValidScenePath(scenePath)) {
|
385
385
|
throw new InvalidScenePath();
|
386
386
|
}
|
387
|
-
|
387
|
+
const apps = Object.keys(this.apps || {});
|
388
|
+
for (const appId of apps) {
|
388
389
|
const appScenePath = appManager.store.getAppScenePath(appId);
|
389
390
|
if (appScenePath && appScenePath === scenePath) {
|
390
391
|
console.warn(`[WindowManager]: ScenePath ${scenePath} Already opened`);
|
package/src/typings.ts
CHANGED
@@ -59,6 +59,7 @@ export type RegisterEventData = {
|
|
59
59
|
export type RegisterEvents<SetupResult = any> = {
|
60
60
|
created: RegisterEventData & { result: SetupResult; };
|
61
61
|
destroy: RegisterEventData;
|
62
|
+
focus: RegisterEventData;
|
62
63
|
};
|
63
64
|
|
64
65
|
export type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any> = {
|
package/src/viewManager.ts
CHANGED
@@ -104,7 +104,7 @@ export class ViewManager extends Base {
|
|
104
104
|
});
|
105
105
|
if (this.mainView.mode === ViewVisionMode.Writable) {
|
106
106
|
notifyMainViewModeChange(callbacks, ViewVisionMode.Freedom);
|
107
|
-
this.mainView
|
107
|
+
setViewMode(this.mainView, ViewVisionMode.Freedom);
|
108
108
|
}
|
109
109
|
if (!this.mainView.focusScenePath) {
|
110
110
|
this.store.setMainViewFocusPath();
|