@netless/window-manager 0.3.0 → 0.3.3
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 -2
- package/dist/Base/Context.d.ts +3 -1
- package/dist/BoxManager.d.ts +6 -1
- package/dist/ViewManager.d.ts +1 -2
- 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/example/index.tsx +3 -2
- package/package.json +2 -2
- package/src/AppContext.ts +2 -8
- package/src/AppListener.ts +0 -17
- package/src/AppManager.ts +12 -8
- package/src/Base/Context.ts +9 -2
- package/src/BoxManager.ts +21 -1
- package/src/Cursor/Cursor.ts +1 -1
- package/src/Utils/Common.ts +1 -1
- package/src/index.ts +3 -3
- package/src/viewManager.ts +6 -25
package/example/index.tsx
CHANGED
@@ -237,6 +237,7 @@ const replay = () => {
|
|
237
237
|
}
|
238
238
|
|
239
239
|
const onRef = (ref) => {
|
240
|
+
const uid = Math.random().toString().substr(3, 8)
|
240
241
|
sdk.joinRoom({
|
241
242
|
uuid: process.env.ROOM_UUID,
|
242
243
|
roomToken: process.env.ROOM_TOKEN,
|
@@ -244,12 +245,12 @@ const onRef = (ref) => {
|
|
244
245
|
useMultiViews: true,
|
245
246
|
userPayload: {
|
246
247
|
userId: "111",
|
247
|
-
cursorName:
|
248
|
+
cursorName: uid,
|
248
249
|
avatar: "https://avatars.githubusercontent.com/u/8299540?s=60&v=4",
|
249
250
|
},
|
250
251
|
isWritable: !(isWritable === "false"),
|
251
252
|
cursorAdapter: undefined,
|
252
|
-
uid:
|
253
|
+
uid: uid,
|
253
254
|
disableMagixEventDispatchLimit: true,
|
254
255
|
}).then(async room => {
|
255
256
|
if (room.isWritable) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@netless/window-manager",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.3",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.es.js",
|
6
6
|
"module": "dist/index.es.js",
|
@@ -24,7 +24,7 @@
|
|
24
24
|
"@juggle/resize-observer": "^3.3.1",
|
25
25
|
"@netless/app-docs-viewer": "^0.1.21",
|
26
26
|
"@netless/app-media-player": "0.1.0-beta.5",
|
27
|
-
"@netless/telebox-insider": "0.2.
|
27
|
+
"@netless/telebox-insider": "0.2.5",
|
28
28
|
"emittery": "^0.9.2",
|
29
29
|
"lodash": "^4.17.21",
|
30
30
|
"p-retry": "^4.6.1",
|
package/src/AppContext.ts
CHANGED
@@ -8,7 +8,6 @@ import {
|
|
8
8
|
toJS
|
9
9
|
} from 'white-web-sdk';
|
10
10
|
import { BoxNotCreatedError } from './Utils/error';
|
11
|
-
import { setScenePath, wait } from './Utils/Common';
|
12
11
|
import type { Room, SceneDefinition, View } from "white-web-sdk";
|
13
12
|
import type { ReadonlyTeleBox } from "@netless/telebox-insider";
|
14
13
|
import type Emittery from "emittery";
|
@@ -102,13 +101,8 @@ export class AppContext<TAttrs extends Record<string, any>, AppOptions = any> {
|
|
102
101
|
|
103
102
|
public async setScenePath(scenePath: string): Promise<void> {
|
104
103
|
if (!this.appProxy.box) return;
|
105
|
-
|
106
|
-
|
107
|
-
} else {
|
108
|
-
this.emitter.emit("focus", true);
|
109
|
-
await wait(50);
|
110
|
-
setScenePath(this.getRoom(), scenePath);
|
111
|
-
}
|
104
|
+
this.appProxy.setFullPath(scenePath);
|
105
|
+
this.manager.viewManager.switchAppToWriter(this.appId);
|
112
106
|
}
|
113
107
|
|
114
108
|
public mountView(dom: HTMLDivElement): void {
|
package/src/AppListener.ts
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
import { Events, MagixEventName } from "./constants";
|
2
|
-
import { ViewVisionMode } from "white-web-sdk";
|
3
2
|
import type { Event } from "white-web-sdk";
|
4
3
|
import type { AppManager } from "./AppManager";
|
5
4
|
|
6
5
|
export class AppListeners {
|
7
6
|
private displayer = this.manager.displayer;
|
8
7
|
private boxManager = this.manager.boxManager;
|
9
|
-
private appProxies = this.manager.appProxies;
|
10
8
|
|
11
9
|
constructor(private manager: AppManager) {}
|
12
10
|
|
@@ -30,10 +28,6 @@ export class AppListeners {
|
|
30
28
|
this.appResizeHandler(data.payload);
|
31
29
|
break;
|
32
30
|
}
|
33
|
-
case Events.AppBlur: {
|
34
|
-
this.appBlurHandler(data.payload);
|
35
|
-
break;
|
36
|
-
}
|
37
31
|
case Events.AppBoxStateChange: {
|
38
32
|
this.appBoxStateHandler(data.payload);
|
39
33
|
break;
|
@@ -57,21 +51,10 @@ export class AppListeners {
|
|
57
51
|
this.manager.room?.refreshViewSize();
|
58
52
|
};
|
59
53
|
|
60
|
-
private appBlurHandler = (payload: any) => {
|
61
|
-
const proxy = this.appProxies.get(payload.appId);
|
62
|
-
if (proxy) {
|
63
|
-
proxy.appEmitter.emit("writableChange", false);
|
64
|
-
if (proxy.view?.mode === ViewVisionMode.Writable) {
|
65
|
-
this.manager.viewManager.refreshViews();
|
66
|
-
}
|
67
|
-
}
|
68
|
-
};
|
69
|
-
|
70
54
|
private appBoxStateHandler = (payload: any) => {
|
71
55
|
this.boxManager.setBoxState(payload.state);
|
72
56
|
};
|
73
57
|
|
74
|
-
|
75
58
|
private switchViewsToFreedomHandler = () => {
|
76
59
|
this.manager.viewManager.freedomAllViews();
|
77
60
|
};
|
package/src/AppManager.ts
CHANGED
@@ -80,16 +80,20 @@ export class AppManager {
|
|
80
80
|
this.refresher?.add("maximized", () => {
|
81
81
|
return autorun(
|
82
82
|
() => {
|
83
|
-
const maximized = this.attributes.maximized
|
84
|
-
this.boxManager.
|
83
|
+
const maximized = this.attributes.maximized;
|
84
|
+
if (this.boxManager.maximized !== maximized) {
|
85
|
+
this.boxManager.setMaximized(Boolean(maximized));
|
86
|
+
}
|
85
87
|
}
|
86
88
|
)
|
87
89
|
});
|
88
90
|
this.refresher?.add("minimized", () => {
|
89
91
|
return autorun(
|
90
92
|
() => {
|
91
|
-
const minimized = this.attributes.minimized
|
92
|
-
this.boxManager.
|
93
|
+
const minimized = this.attributes.minimized;
|
94
|
+
if (this.boxManager.minimized !== minimized) {
|
95
|
+
this.boxManager.setMinimized(Boolean(minimized));
|
96
|
+
}
|
93
97
|
}
|
94
98
|
)
|
95
99
|
});
|
@@ -98,7 +102,7 @@ export class AppManager {
|
|
98
102
|
if (!mainScenePath) return;
|
99
103
|
const sceneState = this.displayer.state.sceneState;
|
100
104
|
if (sceneState.scenePath !== mainScenePath) {
|
101
|
-
this.room
|
105
|
+
setScenePath(this.room, mainScenePath);
|
102
106
|
}
|
103
107
|
}
|
104
108
|
this.displayerWritableListener(!this.room?.isWritable);
|
@@ -170,7 +174,7 @@ export class AppManager {
|
|
170
174
|
this.appStatus.set(appId, AppStatus.StartCreate);
|
171
175
|
this.store.setupAppAttributes(params, appId, isDynamicPPT);
|
172
176
|
if (this.boxManager.boxState === TELE_BOX_STATE.Minimized) {
|
173
|
-
this.boxManager.
|
177
|
+
this.boxManager.setBoxState(TELE_BOX_STATE.Normal);
|
174
178
|
}
|
175
179
|
const needFocus = this.boxManager.boxState !== TELE_BOX_STATE.Minimized;
|
176
180
|
if (needFocus) {
|
@@ -246,9 +250,9 @@ export class AppManager {
|
|
246
250
|
const isManualWritable =
|
247
251
|
this.windowManger.readonly === undefined || this.windowManger.readonly === false;
|
248
252
|
if (this.windowManger.readonly === undefined) {
|
249
|
-
this.boxManager.
|
253
|
+
this.boxManager.setReadonly(isReadonly);
|
250
254
|
} else {
|
251
|
-
this.boxManager.
|
255
|
+
this.boxManager.setReadonly(!(isWritable && isManualWritable));
|
252
256
|
}
|
253
257
|
this.appProxies.forEach(appProxy => {
|
254
258
|
appProxy.emitAppIsWritableChange();
|
package/src/Base/Context.ts
CHANGED
@@ -14,16 +14,23 @@ export class Context {
|
|
14
14
|
};
|
15
15
|
|
16
16
|
public get uid() {
|
17
|
-
return this.
|
17
|
+
return this.findMember(this.observerId)?.payload?.uid || "";
|
18
18
|
}
|
19
19
|
|
20
|
-
|
20
|
+
public findMember = (memberId: number) => {
|
21
21
|
const roomMembers = this.manager.room?.state.roomMembers;
|
22
22
|
return roomMembers?.find(member => member.memberId === memberId);
|
23
23
|
}
|
24
24
|
|
25
|
+
public findMemberByUid = (uid: string) => {
|
26
|
+
const roomMembers = this.manager.room?.state.roomMembers;
|
27
|
+
return roomMembers?.find(member => member.payload?.uid === uid);
|
28
|
+
}
|
29
|
+
|
25
30
|
public memoizeFindMember = memoize(this.findMember);
|
26
31
|
|
32
|
+
public memoizeFindMemberByUid = memoize(this.findMemberByUid);
|
33
|
+
|
27
34
|
public updateManagerRect() {
|
28
35
|
this.manager.boxManager.updateManagerRect();
|
29
36
|
}
|
package/src/BoxManager.ts
CHANGED
@@ -102,10 +102,18 @@ export class BoxManager {
|
|
102
102
|
});
|
103
103
|
}
|
104
104
|
|
105
|
-
public get boxState()
|
105
|
+
public get boxState() {
|
106
106
|
return this.teleBoxManager.state;
|
107
107
|
}
|
108
108
|
|
109
|
+
public get maximized() {
|
110
|
+
return this.teleBoxManager.maximized;
|
111
|
+
}
|
112
|
+
|
113
|
+
public get minimized() {
|
114
|
+
return this.teleBoxManager.minimized;
|
115
|
+
}
|
116
|
+
|
109
117
|
public createBox(params: CreateBoxParams): void {
|
110
118
|
if (!this.teleBoxManager) return;
|
111
119
|
let { minwidth = MIN_WIDTH, minheight = MIN_HEIGHT } = params.app.config ?? {};
|
@@ -286,6 +294,18 @@ export class BoxManager {
|
|
286
294
|
callbacks.emit("boxStateChange", state);
|
287
295
|
}
|
288
296
|
|
297
|
+
public setMaximized(maximized: boolean) {
|
298
|
+
this.teleBoxManager.setMaximized(maximized, true);
|
299
|
+
}
|
300
|
+
|
301
|
+
public setMinimized(minimized: boolean) {
|
302
|
+
this.teleBoxManager.setMinimized(minimized, true);
|
303
|
+
}
|
304
|
+
|
305
|
+
public setReadonly(readonly: boolean) {
|
306
|
+
this.teleBoxManager.setReadonly(readonly);
|
307
|
+
}
|
308
|
+
|
289
309
|
public destroy() {
|
290
310
|
this.teleBoxManager.destroy();
|
291
311
|
}
|
package/src/Cursor/Cursor.ts
CHANGED
@@ -180,7 +180,7 @@ export class Cursor extends Base {
|
|
180
180
|
}
|
181
181
|
|
182
182
|
public setMember() {
|
183
|
-
this.member = this.context.
|
183
|
+
this.member = this.context.memoizeFindMemberByUid(this.memberId);
|
184
184
|
this.component?.$set(omit(this.initProps(), ["x", "y", "visible"]));
|
185
185
|
}
|
186
186
|
|
package/src/Utils/Common.ts
CHANGED
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.3";
|
174
174
|
|
175
175
|
public appListeners?: AppListeners;
|
176
176
|
|
@@ -449,7 +449,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
449
449
|
public setReadonly(readonly: boolean): void {
|
450
450
|
if (this.room?.isWritable) {
|
451
451
|
this.readonly = readonly;
|
452
|
-
this.appManager?.boxManager.
|
452
|
+
this.appManager?.boxManager.setReadonly(readonly);
|
453
453
|
}
|
454
454
|
}
|
455
455
|
|
@@ -504,7 +504,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
504
504
|
|
505
505
|
public get boxState(): TeleBoxState {
|
506
506
|
if (this.appManager) {
|
507
|
-
return this.appManager.boxManager.
|
507
|
+
return this.appManager.boxManager.boxState;
|
508
508
|
} else {
|
509
509
|
throw new AppManagerNotInitError();
|
510
510
|
}
|
package/src/viewManager.ts
CHANGED
@@ -2,11 +2,9 @@ import { Base } from "./Base";
|
|
2
2
|
import { callbacks, WindowManager } from "./index";
|
3
3
|
import { reaction, ViewVisionMode } from "white-web-sdk";
|
4
4
|
import { SET_SCENEPATH_DELAY } from "./constants";
|
5
|
-
import { TELE_BOX_STATE } from "@netless/telebox-insider";
|
6
5
|
import {
|
7
6
|
notifyMainViewModeChange,
|
8
7
|
setScenePath,
|
9
|
-
setViewFocusScenePath,
|
10
8
|
setViewMode,
|
11
9
|
} from "./Utils/Common";
|
12
10
|
import type { View } from "white-web-sdk";
|
@@ -15,6 +13,7 @@ import type { AppManager } from "./AppManager";
|
|
15
13
|
export class ViewManager extends Base {
|
16
14
|
private views: Map<string, View> = new Map();
|
17
15
|
private timer?: number;
|
16
|
+
private appTimer?: number;
|
18
17
|
|
19
18
|
private mainViewProxy = this.manager.mainViewProxy;
|
20
19
|
private displayer = this.manager.displayer;
|
@@ -96,24 +95,6 @@ export class ViewManager extends Base {
|
|
96
95
|
});
|
97
96
|
}
|
98
97
|
|
99
|
-
public refreshViews(): void {
|
100
|
-
const focus = this.store.focus;
|
101
|
-
this.setMainViewFocusScenePath();
|
102
|
-
if (focus) {
|
103
|
-
const appProxy = this.manager.appProxies.get(focus);
|
104
|
-
appProxy?.switchToWritable();
|
105
|
-
} else {
|
106
|
-
this.switchMainViewToWriter();
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
public setMainViewFocusScenePath() {
|
111
|
-
const mainViewScenePath = this.store.getMainViewScenePath();
|
112
|
-
if (mainViewScenePath) {
|
113
|
-
setViewFocusScenePath(this.manager.mainView, mainViewScenePath);
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
98
|
public freedomAllViews(): void {
|
118
99
|
this.manager.appProxies.forEach(appProxy => {
|
119
100
|
appProxy.setViewFocusScenePath();
|
@@ -131,15 +112,15 @@ export class ViewManager extends Base {
|
|
131
112
|
}
|
132
113
|
|
133
114
|
public switchAppToWriter(id: string): void {
|
115
|
+
if (this.appTimer) {
|
116
|
+
clearTimeout(this.appTimer);
|
117
|
+
}
|
134
118
|
this.freedomAllViews();
|
135
119
|
// 为了同步端不闪烁, 需要给 room setScenePath 一个延迟
|
136
|
-
setTimeout(() => {
|
120
|
+
this.appTimer = setTimeout(() => {
|
137
121
|
const appProxy = this.manager.appProxies.get(id);
|
138
122
|
if (appProxy) {
|
139
|
-
|
140
|
-
if (boxState && boxState === TELE_BOX_STATE.Minimized) {
|
141
|
-
return;
|
142
|
-
}
|
123
|
+
if (this.manager.boxManager.minimized) return;
|
143
124
|
appProxy.setScenePath();
|
144
125
|
appProxy.switchToWritable();
|
145
126
|
appProxy.focusBox();
|