@netless/window-manager 1.0.0-canary.22 → 1.0.0-canary.25
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/App/AppContext.d.ts +1 -1
- package/dist/BoxManager.d.ts +3 -0
- package/dist/Cursor/index.d.ts +3 -2
- package/dist/Helper.d.ts +2 -0
- package/dist/View/CameraSynchronizer.d.ts +1 -1
- package/dist/index.cjs.js +12 -12
- package/dist/index.es.js +75 -48
- package/dist/index.umd.js +12 -12
- package/dist/style.css +1 -1
- package/docs/app-context.md +154 -26
- package/package.json +2 -2
- package/pnpm-lock.yaml +2 -9
- package/src/App/AppContext.ts +13 -5
- package/src/BoxManager.ts +12 -0
- package/src/Cursor/Cursor.ts +6 -2
- package/src/Cursor/index.ts +5 -5
- package/src/Helper.ts +20 -3
- package/src/View/CameraSynchronizer.ts +17 -26
- package/src/index.ts +8 -12
- package/src/style.css +2 -6
package/src/Cursor/index.ts
CHANGED
@@ -5,7 +5,7 @@ import { emitter } from "../InternalEmitter";
|
|
5
5
|
import { SideEffectManager } from "side-effect-manager";
|
6
6
|
import { throttle } from "lodash";
|
7
7
|
import { WindowManager } from "../index";
|
8
|
-
import type { CursorMovePayload , ApplianceIcons} from "../index";
|
8
|
+
import type { CursorMovePayload , ApplianceIcons, TeleBoxRect } from "../index";
|
9
9
|
import type { PositionType } from "../AttributesDelegate";
|
10
10
|
import type { Point, RoomMember, View } from "white-web-sdk";
|
11
11
|
import type { AppManager } from "../AppManager";
|
@@ -23,7 +23,8 @@ export type MoveCursorParams = {
|
|
23
23
|
};
|
24
24
|
|
25
25
|
export class CursorManager {
|
26
|
-
public wrapperRect?:
|
26
|
+
public wrapperRect?: TeleBoxRect;
|
27
|
+
public playgroundRect?: DOMRect;
|
27
28
|
public cursorInstances: Map<string, Cursor> = new Map();
|
28
29
|
public roomMembers?: readonly RoomMember[];
|
29
30
|
private mainViewElement?: HTMLDivElement;
|
@@ -88,8 +89,6 @@ export class CursorManager {
|
|
88
89
|
wrapper.removeEventListener("pointerleave", this.mouseLeaveListener);
|
89
90
|
};
|
90
91
|
});
|
91
|
-
|
92
|
-
this.wrapperRect = wrapper.getBoundingClientRect();
|
93
92
|
}
|
94
93
|
|
95
94
|
public setMainViewDivElement(div: HTMLDivElement) {
|
@@ -167,7 +166,8 @@ export class CursorManager {
|
|
167
166
|
};
|
168
167
|
|
169
168
|
public updateContainerRect() {
|
170
|
-
this.wrapperRect =
|
169
|
+
this.wrapperRect = this.manager.boxManager?.teleBoxManager.stageRect;
|
170
|
+
this.playgroundRect = WindowManager.playground?.getBoundingClientRect();
|
171
171
|
}
|
172
172
|
|
173
173
|
public deleteCursor(uid: string) {
|
package/src/Helper.ts
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
import { getVersionNumber } from "./Utils/Common";
|
1
|
+
import { getVersionNumber, wait } from "./Utils/Common";
|
2
|
+
import { log } from "./Utils/log";
|
2
3
|
import { REQUIRE_VERSION } from "./constants";
|
3
4
|
import { WhiteVersion } from "white-web-sdk";
|
4
5
|
import { WhiteWebSDKInvalidError } from "./Utils/error";
|
5
|
-
import
|
6
|
+
import { WindowManager } from "./index";
|
7
|
+
import type { Room, RoomMember } from "white-web-sdk";
|
6
8
|
|
7
9
|
export const setupWrapper = (
|
8
10
|
root: HTMLElement
|
@@ -40,4 +42,19 @@ export const serializeRoomMembers = (members: readonly RoomMember[]) => {
|
|
40
42
|
uid: member.payload?.uid || "",
|
41
43
|
...member,
|
42
44
|
}));
|
43
|
-
}
|
45
|
+
};
|
46
|
+
|
47
|
+
export const createInvisiblePlugin = async (room: Room) => {
|
48
|
+
try {
|
49
|
+
const manager = (await room.createInvisiblePlugin(WindowManager, {})) as WindowManager;
|
50
|
+
return manager;
|
51
|
+
} catch (error) {
|
52
|
+
// 如果有两个用户同时调用 WindowManager.mount 有概率出现这个错误
|
53
|
+
if (error.message === `invisible plugin "WindowManager" exits`) {
|
54
|
+
await wait(200);
|
55
|
+
return room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
|
56
|
+
} else {
|
57
|
+
log("createInvisiblePlugin failed", error);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { AnimationMode } from "white-web-sdk";
|
2
|
-
import {
|
2
|
+
import { isEqual, pick, throttle } from "lodash";
|
3
3
|
import type { TeleBoxRect } from "@netless/telebox-insider";
|
4
4
|
import type { Camera, View } from "white-web-sdk";
|
5
5
|
import type { ICamera, ISize } from "../AttributesDelegate";
|
@@ -14,12 +14,12 @@ export class CameraSynchronizer {
|
|
14
14
|
|
15
15
|
constructor(protected saveCamera: SaveCamera) {}
|
16
16
|
|
17
|
-
public setRect =
|
17
|
+
public setRect = (rect: TeleBoxRect) => {
|
18
18
|
this.rect = rect;
|
19
19
|
if (this.remoteCamera && this.remoteSize) {
|
20
20
|
this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
|
21
21
|
}
|
22
|
-
}
|
22
|
+
}
|
23
23
|
|
24
24
|
public setView(view: View) {
|
25
25
|
this.view = view;
|
@@ -37,22 +37,17 @@ export class CameraSynchronizer {
|
|
37
37
|
scale = this.rect.height / size.height;
|
38
38
|
}
|
39
39
|
const nextScale = camera.scale * scale;
|
40
|
-
const
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
config.centerY = camera.centerY;
|
50
|
-
}
|
51
|
-
this.view?.moveCamera(config);
|
40
|
+
const config: Partial<Camera> & { animationMode: AnimationMode } = {
|
41
|
+
scale: nextScale,
|
42
|
+
animationMode: AnimationMode.Immediately,
|
43
|
+
}
|
44
|
+
if (camera.centerX !== null) {
|
45
|
+
config.centerX = camera.centerX;
|
46
|
+
}
|
47
|
+
if (camera.centerY !== null) {
|
48
|
+
config.centerY = camera.centerY;
|
52
49
|
}
|
53
|
-
moveCamera();
|
54
|
-
// TODO 直接调用 moveCamera 依然会出现 camera 错误的情况,这里暂时加一个 delay 保证 camera 是对的, 后续需要 SDK 进行修改
|
55
|
-
delay(moveCamera, 50);
|
50
|
+
this.view?.moveCamera(config);
|
56
51
|
}
|
57
52
|
}, 10);
|
58
53
|
|
@@ -62,14 +57,10 @@ export class CameraSynchronizer {
|
|
62
57
|
if (this.rect && this.remoteCamera && needMoveCamera) {
|
63
58
|
const scale = this.rect.width / size.width;
|
64
59
|
const nextScale = this.remoteCamera.scale * scale;
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
})
|
70
|
-
};
|
71
|
-
moveCamera();
|
72
|
-
delay(moveCamera, 50);
|
60
|
+
this.view?.moveCamera({
|
61
|
+
scale: nextScale,
|
62
|
+
animationMode: AnimationMode.Immediately,
|
63
|
+
})
|
73
64
|
}
|
74
65
|
}
|
75
66
|
|
package/src/index.ts
CHANGED
@@ -2,7 +2,7 @@ import pRetry from "p-retry";
|
|
2
2
|
import { AppManager } from "./AppManager";
|
3
3
|
import { appRegister } from "./Register";
|
4
4
|
import { callbacks } from "./callback";
|
5
|
-
import { checkVersion, setupWrapper } from "./Helper";
|
5
|
+
import { checkVersion, createInvisiblePlugin, setupWrapper } from "./Helper";
|
6
6
|
import { createBoxManager } from "./BoxManager";
|
7
7
|
import { CursorManager } from "./Cursor";
|
8
8
|
import { DEFAULT_CONTAINER_RATIO, Events, INIT_DIR, ROOT_DIR } from "./constants";
|
@@ -268,8 +268,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
268
268
|
return manager;
|
269
269
|
}
|
270
270
|
|
271
|
-
private static async initManager(room: Room): Promise<WindowManager> {
|
272
|
-
let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
|
271
|
+
private static async initManager(room: Room): Promise<WindowManager | undefined> {
|
272
|
+
let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager | undefined;
|
273
273
|
if (!manager) {
|
274
274
|
if (isRoom(room)) {
|
275
275
|
if (room.isWritable === false) {
|
@@ -278,18 +278,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
278
278
|
} catch (error) {
|
279
279
|
throw new Error("[WindowManger]: room must be switched to be writable");
|
280
280
|
}
|
281
|
-
manager =
|
282
|
-
|
283
|
-
{}
|
284
|
-
)) as WindowManager;
|
285
|
-
manager.ensureAttributes();
|
281
|
+
manager = await createInvisiblePlugin(room);
|
282
|
+
manager?.ensureAttributes();
|
286
283
|
await wait(500);
|
287
284
|
await room.setWritable(false);
|
288
285
|
} else {
|
289
|
-
manager =
|
290
|
-
WindowManager,
|
291
|
-
{}
|
292
|
-
)) as WindowManager;
|
286
|
+
manager = await createInvisiblePlugin(room);
|
293
287
|
}
|
294
288
|
}
|
295
289
|
}
|
@@ -334,11 +328,13 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
334
328
|
);
|
335
329
|
if (this.boxManager && WindowManager.playground) {
|
336
330
|
this.boxManager.setRoot(WindowManager.playground);
|
331
|
+
this.boxManager.mainViewElement$.setValue(mainViewElement);
|
337
332
|
}
|
338
333
|
this.bindMainView(mainViewElement, params.disableCameraTransform);
|
339
334
|
if (WindowManager.playground) {
|
340
335
|
this.cursorManager?.setupWrapper(WindowManager.playground);
|
341
336
|
}
|
337
|
+
|
342
338
|
}
|
343
339
|
}
|
344
340
|
emitter.emit("updateManagerRect");
|
package/src/style.css
CHANGED
@@ -49,8 +49,7 @@
|
|
49
49
|
}
|
50
50
|
|
51
51
|
.netless-window-manager-main-view {
|
52
|
-
|
53
|
-
height: 100%;
|
52
|
+
position: absolute;
|
54
53
|
}
|
55
54
|
|
56
55
|
|
@@ -180,9 +179,6 @@
|
|
180
179
|
}
|
181
180
|
|
182
181
|
.window-manager-view-wrapper {
|
183
|
-
width: 100%;
|
184
|
-
height: 100%;
|
185
182
|
position: absolute;
|
186
|
-
|
187
|
-
top: 0;
|
183
|
+
z-index: 1;
|
188
184
|
}
|