@netless/window-manager 1.0.0-canary.23 → 1.0.0-canary.26
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/App/WhiteboardView.d.ts +3 -3
- package/dist/AppListener.d.ts +0 -2
- package/dist/BoxManager.d.ts +3 -0
- package/dist/Cursor/index.d.ts +3 -2
- package/dist/Helper.d.ts +2 -0
- package/dist/constants.d.ts +0 -2
- package/dist/index.cjs.js +12 -12
- package/dist/index.d.ts +11 -8
- package/dist/index.es.js +106 -64
- package/dist/index.umd.js +12 -12
- package/dist/style.css +1 -1
- package/docs/app-context.md +68 -26
- package/package.json +2 -2
- package/pnpm-lock.yaml +2 -9
- package/src/App/AppContext.ts +13 -5
- package/src/App/AppProxy.ts +4 -0
- package/src/App/WhiteboardView.ts +6 -6
- package/src/AppListener.ts +1 -21
- package/src/AppManager.ts +2 -1
- 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 +2 -2
- package/src/View/MainView.ts +3 -1
- package/src/constants.ts +0 -2
- package/src/index.ts +52 -41
- package/src/style.css +2 -6
package/src/Cursor/Cursor.ts
CHANGED
@@ -7,6 +7,7 @@ import type { RoomMember } from "white-web-sdk";
|
|
7
7
|
import type { CursorManager } from "./index";
|
8
8
|
import type { SvelteComponent } from "svelte";
|
9
9
|
import type { AppManager } from "../AppManager";
|
10
|
+
import type { TeleBoxRect } from "@netless/telebox-insider";
|
10
11
|
|
11
12
|
export type Payload = {
|
12
13
|
[key: string]: any;
|
@@ -50,18 +51,21 @@ export class Cursor {
|
|
50
51
|
this.hide();
|
51
52
|
};
|
52
53
|
|
53
|
-
private moveCursor(cursor: Position, rect:
|
54
|
+
private moveCursor(cursor: Position, rect: TeleBoxRect, view: any) {
|
54
55
|
const { x, y, type } = cursor;
|
55
56
|
const point = view?.screen.convertPointToScreen(x, y);
|
56
57
|
if (point) {
|
57
58
|
let translateX = point.x - 2;
|
58
59
|
let translateY = point.y - 18;
|
59
60
|
if (type === "app") {
|
60
|
-
const wrapperRect = this.cursorManager.
|
61
|
+
const wrapperRect = this.cursorManager.playgroundRect;
|
61
62
|
if (wrapperRect) {
|
62
63
|
translateX = translateX + rect.x - wrapperRect.x;
|
63
64
|
translateY = translateY + rect.y - wrapperRect.y;
|
64
65
|
}
|
66
|
+
} else {
|
67
|
+
translateX = translateX + rect.x;
|
68
|
+
translateY = translateY + rect.y;
|
65
69
|
}
|
66
70
|
if (point.x < 0 || point.x > rect.width || point.y < 0 || point.y > rect.height) {
|
67
71
|
this.component?.$set({ visible: false, x: translateX, y: translateY });
|
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
|
+
};
|
@@ -39,7 +39,7 @@ export class CameraSynchronizer {
|
|
39
39
|
const nextScale = camera.scale * scale;
|
40
40
|
const config: Partial<Camera> & { animationMode: AnimationMode } = {
|
41
41
|
scale: nextScale,
|
42
|
-
animationMode: AnimationMode.
|
42
|
+
animationMode: AnimationMode.Continuous,
|
43
43
|
}
|
44
44
|
if (camera.centerX !== null) {
|
45
45
|
config.centerX = camera.centerX;
|
@@ -59,7 +59,7 @@ export class CameraSynchronizer {
|
|
59
59
|
const nextScale = this.remoteCamera.scale * scale;
|
60
60
|
this.view?.moveCamera({
|
61
61
|
scale: nextScale,
|
62
|
-
animationMode: AnimationMode.
|
62
|
+
animationMode: AnimationMode.Continuous,
|
63
63
|
})
|
64
64
|
}
|
65
65
|
}
|
package/src/View/MainView.ts
CHANGED
@@ -4,7 +4,7 @@ import { debounce, get, isEqual } from "lodash";
|
|
4
4
|
import { emitter } from "../InternalEmitter";
|
5
5
|
import { Events } from "../constants";
|
6
6
|
import { Fields } from "../AttributesDelegate";
|
7
|
-
import { reaction, toJS } from "white-web-sdk";
|
7
|
+
import { AnimationMode, reaction, toJS } from "white-web-sdk";
|
8
8
|
import { releaseView, setScenePath, setViewFocusScenePath } from "../Utils/Common";
|
9
9
|
import { SideEffectManager } from "side-effect-manager";
|
10
10
|
import { Val } from "value-enhancer";
|
@@ -211,12 +211,14 @@ export class MainViewProxy {
|
|
211
211
|
public rebind(): void {
|
212
212
|
const divElement = this.mainView.divElement;
|
213
213
|
const disableCameraTransform = this.mainView.disableCameraTransform;
|
214
|
+
const camera = { ...this.mainView.camera };
|
214
215
|
this.stop();
|
215
216
|
releaseView(this.mainView);
|
216
217
|
this.removeMainViewListener();
|
217
218
|
this.mainView = this.createMainView();
|
218
219
|
this.mainView.disableCameraTransform = disableCameraTransform;
|
219
220
|
this.mainView.divElement = divElement;
|
221
|
+
this.mainView.moveCamera({ ...camera, animationMode: AnimationMode.Immediately });
|
220
222
|
this.addMainViewListener();
|
221
223
|
this.start();
|
222
224
|
}
|
package/src/constants.ts
CHANGED
@@ -10,8 +10,6 @@ export enum Events {
|
|
10
10
|
SetMainViewSceneIndex = "SetMainViewSceneIndex",
|
11
11
|
SetAppFocusIndex = "SetAppFocusIndex",
|
12
12
|
SwitchViewsToFreedom = "SwitchViewsToFreedom",
|
13
|
-
MoveCamera = "MoveCamera",
|
14
|
-
MoveCameraToContain = "MoveCameraToContain",
|
15
13
|
CursorMove = "CursorMove",
|
16
14
|
RootDirRemoved = "RootDirRemoved",
|
17
15
|
Refresh = "Refresh",
|
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";
|
@@ -10,7 +10,7 @@ import { emitter } from "./InternalEmitter";
|
|
10
10
|
import { Fields } from "./AttributesDelegate";
|
11
11
|
import { initDb } from "./Register/storage";
|
12
12
|
import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
|
13
|
-
import { isEqual, isNull, isObject,
|
13
|
+
import { isEqual, isNull, isObject, isNumber } from "lodash";
|
14
14
|
import { log } from "./Utils/log";
|
15
15
|
import { PageStateImpl } from "./PageState";
|
16
16
|
import { ReconnectRefresher } from "./ReconnectRefresher";
|
@@ -27,6 +27,8 @@ import {
|
|
27
27
|
putScenes,
|
28
28
|
wait,
|
29
29
|
} from "./Utils/Common";
|
30
|
+
import { boxEmitter } from "./BoxEmitter";
|
31
|
+
import { Val } from "value-enhancer";
|
30
32
|
import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
|
31
33
|
import * as Errors from "./Utils/error";
|
32
34
|
import type { Apps, Position , ICamera, ISize } from "./AttributesDelegate";
|
@@ -37,15 +39,13 @@ import type {
|
|
37
39
|
Room,
|
38
40
|
InvisiblePluginContext,
|
39
41
|
Camera,
|
40
|
-
AnimationMode,
|
41
42
|
CameraBound,
|
42
43
|
Point,
|
43
|
-
Rectangle,
|
44
44
|
CameraState,
|
45
45
|
Player,
|
46
46
|
ImageInformation,
|
47
47
|
SceneState,
|
48
|
-
} from "white-web-sdk";
|
48
|
+
Rectangle} from "white-web-sdk";
|
49
49
|
import type { AppListeners } from "./AppListener";
|
50
50
|
import type { ApplianceIcons, NetlessApp, RegisterParams } from "./typings";
|
51
51
|
import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
|
@@ -53,8 +53,6 @@ import type { AppProxy } from "./App";
|
|
53
53
|
import type { PublicEvent } from "./callback";
|
54
54
|
import type Emittery from "emittery";
|
55
55
|
import type { PageController, AddPageParams, PageState } from "./Page";
|
56
|
-
import { boxEmitter } from "./BoxEmitter";
|
57
|
-
import { Val } from "value-enhancer";
|
58
56
|
|
59
57
|
export type WindowMangerAttributes = {
|
60
58
|
modelValue?: string;
|
@@ -268,8 +266,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
268
266
|
return manager;
|
269
267
|
}
|
270
268
|
|
271
|
-
private static async initManager(room: Room): Promise<WindowManager> {
|
272
|
-
let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
|
269
|
+
private static async initManager(room: Room): Promise<WindowManager | undefined> {
|
270
|
+
let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager | undefined;
|
273
271
|
if (!manager) {
|
274
272
|
if (isRoom(room)) {
|
275
273
|
if (room.isWritable === false) {
|
@@ -278,18 +276,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
278
276
|
} catch (error) {
|
279
277
|
throw new Error("[WindowManger]: room must be switched to be writable");
|
280
278
|
}
|
281
|
-
manager =
|
282
|
-
|
283
|
-
{}
|
284
|
-
)) as WindowManager;
|
285
|
-
manager.ensureAttributes();
|
279
|
+
manager = await createInvisiblePlugin(room);
|
280
|
+
manager?.ensureAttributes();
|
286
281
|
await wait(500);
|
287
282
|
await room.setWritable(false);
|
288
283
|
} else {
|
289
|
-
manager =
|
290
|
-
WindowManager,
|
291
|
-
{}
|
292
|
-
)) as WindowManager;
|
284
|
+
manager = await createInvisiblePlugin(room);
|
293
285
|
}
|
294
286
|
}
|
295
287
|
}
|
@@ -334,11 +326,13 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
334
326
|
);
|
335
327
|
if (this.boxManager && WindowManager.playground) {
|
336
328
|
this.boxManager.setRoot(WindowManager.playground);
|
329
|
+
this.boxManager.mainViewElement$.setValue(mainViewElement);
|
337
330
|
}
|
338
331
|
this.bindMainView(mainViewElement, params.disableCameraTransform);
|
339
332
|
if (WindowManager.playground) {
|
340
333
|
this.cursorManager?.setupWrapper(WindowManager.playground);
|
341
334
|
}
|
335
|
+
|
342
336
|
}
|
343
337
|
}
|
344
338
|
emitter.emit("updateManagerRect");
|
@@ -661,6 +655,22 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
661
655
|
}
|
662
656
|
}
|
663
657
|
|
658
|
+
public get baseCamera$() {
|
659
|
+
if (this.appManager) {
|
660
|
+
return this.appManager.mainViewProxy.camera$;
|
661
|
+
} else {
|
662
|
+
throw new Errors.AppManagerNotInitError();
|
663
|
+
}
|
664
|
+
}
|
665
|
+
|
666
|
+
public get baseSize$() {
|
667
|
+
if (this.appManager) {
|
668
|
+
return this.appManager.mainViewProxy.size$;
|
669
|
+
} else {
|
670
|
+
throw new Errors.AppManagerNotInitError();
|
671
|
+
}
|
672
|
+
}
|
673
|
+
|
664
674
|
public get cameraState(): CameraState {
|
665
675
|
if (this.appManager) {
|
666
676
|
return this.appManager.mainViewProxy.cameraState;
|
@@ -767,30 +777,31 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
767
777
|
return this.appManager?.closeApp(appId);
|
768
778
|
}
|
769
779
|
|
770
|
-
public moveCamera(
|
771
|
-
camera: Partial<Camera> & { animationMode?: AnimationMode | undefined }
|
772
|
-
): void {
|
773
|
-
const pureCamera = omit(camera, ["animationMode"]);
|
780
|
+
public moveCamera(camera: Partial<Camera> ): void {
|
774
781
|
const mainViewCamera = { ...this.mainView.camera };
|
775
|
-
|
776
|
-
|
777
|
-
this.appManager
|
778
|
-
|
779
|
-
this.appManager
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
782
|
+
const nextCamera = { ...mainViewCamera, ...camera };
|
783
|
+
if (isEqual(nextCamera, mainViewCamera)) return;
|
784
|
+
if (!this.appManager) return;
|
785
|
+
this.appManager.mainViewProxy.storeCamera({
|
786
|
+
id: this.appManager.uid,
|
787
|
+
...nextCamera
|
788
|
+
});
|
789
|
+
}
|
790
|
+
|
791
|
+
public moveCameraToContain(rectangle: Rectangle): void {
|
792
|
+
if (!this.appManager) return;
|
793
|
+
const mainViewSize = this.appManager.mainViewProxy.size$.value;
|
794
|
+
if (mainViewSize) {
|
795
|
+
const wScale = mainViewSize.width / rectangle.width;
|
796
|
+
const hScale = mainViewSize.height / rectangle.height;
|
797
|
+
const nextScale = Math.min(wScale, hScale);
|
798
|
+
this.appManager.mainViewProxy.storeCamera({
|
799
|
+
id: this.appManager.uid,
|
800
|
+
scale: nextScale,
|
801
|
+
centerX: rectangle.originX,
|
802
|
+
centerY: rectangle.originY,
|
803
|
+
});
|
804
|
+
}
|
794
805
|
}
|
795
806
|
|
796
807
|
public convertToPointInWorld(point: Point): Point {
|
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
|
}
|