@netless/window-manager 1.0.0-canary.25 → 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/WhiteboardView.d.ts +3 -3
- package/dist/AppListener.d.ts +0 -2
- package/dist/constants.d.ts +0 -2
- package/dist/index.cjs.js +11 -11
- package/dist/index.d.ts +11 -8
- package/dist/index.es.js +51 -44
- package/dist/index.umd.js +10 -10
- package/package.json +1 -1
- 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/View/CameraSynchronizer.ts +2 -2
- package/src/View/MainView.ts +3 -1
- package/src/constants.ts +0 -2
- package/src/index.ts +44 -29
package/package.json
CHANGED
package/src/App/AppProxy.ts
CHANGED
@@ -345,6 +345,10 @@ export class AppProxy implements PageRemoveService {
|
|
345
345
|
this.box$.setValue(box);
|
346
346
|
if (this.isAddApp && this.box) {
|
347
347
|
this.store.updateAppState(appId, AppAttributes.ZIndex, this.box.zIndex);
|
348
|
+
this.store.updateAppState(appId, AppAttributes.Size, {
|
349
|
+
width: this.box.intrinsicWidth,
|
350
|
+
height: this.box.intrinsicHeight,
|
351
|
+
});
|
348
352
|
this.boxManager.focusBox({ appId }, false);
|
349
353
|
}
|
350
354
|
} catch (error: any) {
|
@@ -10,11 +10,11 @@ import type { View } from "white-web-sdk";
|
|
10
10
|
import type { TeleBoxRect } from "@netless/telebox-insider";
|
11
11
|
import type { ICamera } from "../AttributesDelegate";
|
12
12
|
|
13
|
-
export type WhiteBoardViewCamera = Omit<ICamera, "
|
13
|
+
export type WhiteBoardViewCamera = Omit<ICamera, "id">;
|
14
14
|
|
15
15
|
export class WhiteBoardView implements PageController {
|
16
16
|
public readonly pageState$: ReadonlyVal<PageState>;
|
17
|
-
public readonly
|
17
|
+
public readonly baseCamera$: ReadonlyVal<WhiteBoardViewCamera>;
|
18
18
|
|
19
19
|
constructor(
|
20
20
|
public view: View,
|
@@ -30,13 +30,13 @@ export class WhiteBoardView implements PageController {
|
|
30
30
|
})
|
31
31
|
);
|
32
32
|
const camera$ = new Val<WhiteBoardViewCamera>(
|
33
|
-
pick(this.view.camera, ["centerX", "centerY"])
|
33
|
+
pick(this.view.camera, ["centerX", "centerY", "scale"])
|
34
34
|
);
|
35
|
-
this.
|
35
|
+
this.baseCamera$ = camera$;
|
36
36
|
this.appProxy.sideEffectManager.add(() =>
|
37
37
|
appProxy.camera$.subscribe(camera => {
|
38
38
|
if (camera) {
|
39
|
-
camera$.setValue(pick(camera, ["centerX", "centerY"]));
|
39
|
+
camera$.setValue(pick(camera, ["centerX", "centerY", "scale"]));
|
40
40
|
}
|
41
41
|
})
|
42
42
|
);
|
@@ -96,7 +96,7 @@ export class WhiteBoardView implements PageController {
|
|
96
96
|
return this.appProxy.removeSceneByIndex(needRemoveIndex);
|
97
97
|
};
|
98
98
|
|
99
|
-
public
|
99
|
+
public setBaseRect(rect: Omit<TeleBoxRect, "x" | "y">) {
|
100
100
|
this.appProxy.updateSize(rect.width, rect.height);
|
101
101
|
}
|
102
102
|
}
|
package/src/AppListener.ts
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
import { callbacks } from "./callback";
|
2
2
|
import { emitter } from "./InternalEmitter";
|
3
3
|
import { Events, MagixEventName } from "./constants";
|
4
|
-
import { isEqual, omit } from "lodash";
|
5
4
|
import { setViewFocusScenePath } from "./Utils/Common";
|
6
|
-
import type {
|
5
|
+
import type { Event } from "white-web-sdk";
|
7
6
|
import type { AppManager } from "./AppManager";
|
8
7
|
import type { TeleBoxState } from "@netless/telebox-insider";
|
9
8
|
|
@@ -50,14 +49,6 @@ export class AppListeners {
|
|
50
49
|
this.setMainViewScenePathHandler(data.payload);
|
51
50
|
break;
|
52
51
|
}
|
53
|
-
case Events.MoveCamera: {
|
54
|
-
this.moveCameraHandler(data.payload);
|
55
|
-
break;
|
56
|
-
}
|
57
|
-
case Events.MoveCameraToContain: {
|
58
|
-
this.moveCameraToContainHandler(data.payload);
|
59
|
-
break;
|
60
|
-
}
|
61
52
|
case Events.CursorMove: {
|
62
53
|
this.cursorMoveHandler(data.payload);
|
63
54
|
break;
|
@@ -102,17 +93,6 @@ export class AppListeners {
|
|
102
93
|
callbacks.emit("mainViewScenePathChange", nextScenePath);
|
103
94
|
};
|
104
95
|
|
105
|
-
private moveCameraHandler = (
|
106
|
-
payload: Camera & { animationMode?: AnimationMode | undefined }
|
107
|
-
) => {
|
108
|
-
if (isEqual(omit(payload, ["animationMode"]), { ...this.manager.mainView.camera })) return;
|
109
|
-
this.manager.mainView.moveCamera(payload);
|
110
|
-
};
|
111
|
-
|
112
|
-
private moveCameraToContainHandler = (payload: any) => {
|
113
|
-
this.manager.mainView.moveCameraToContain(payload);
|
114
|
-
};
|
115
|
-
|
116
96
|
private cursorMoveHandler = (payload: any) => {
|
117
97
|
emitter.emit("cursorMove", payload);
|
118
98
|
};
|
package/src/AppManager.ts
CHANGED
@@ -409,7 +409,7 @@ export class AppManager {
|
|
409
409
|
};
|
410
410
|
|
411
411
|
public addAppsChangeListener = () => {
|
412
|
-
this.refresher
|
412
|
+
this.refresher.add("apps", () => {
|
413
413
|
return safeListenPropsUpdated(
|
414
414
|
() => this.attributes.apps,
|
415
415
|
() => {
|
@@ -800,6 +800,7 @@ export class AppManager {
|
|
800
800
|
}
|
801
801
|
|
802
802
|
public async onReconnected() {
|
803
|
+
this.attributesUpdateCallback(this.attributes.apps);
|
803
804
|
const appProxies = Array.from(this.appProxies.values());
|
804
805
|
const reconnected = appProxies.map(appProxy => {
|
805
806
|
return appProxy.onReconnected();
|
@@ -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
@@ -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;
|
@@ -657,6 +655,22 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
657
655
|
}
|
658
656
|
}
|
659
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
|
+
|
660
674
|
public get cameraState(): CameraState {
|
661
675
|
if (this.appManager) {
|
662
676
|
return this.appManager.mainViewProxy.cameraState;
|
@@ -763,30 +777,31 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
763
777
|
return this.appManager?.closeApp(appId);
|
764
778
|
}
|
765
779
|
|
766
|
-
public moveCamera(
|
767
|
-
camera: Partial<Camera> & { animationMode?: AnimationMode | undefined }
|
768
|
-
): void {
|
769
|
-
const pureCamera = omit(camera, ["animationMode"]);
|
780
|
+
public moveCamera(camera: Partial<Camera> ): void {
|
770
781
|
const mainViewCamera = { ...this.mainView.camera };
|
771
|
-
|
772
|
-
|
773
|
-
this.appManager
|
774
|
-
|
775
|
-
this.appManager
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
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
|
+
}
|
790
805
|
}
|
791
806
|
|
792
807
|
public convertToPointInWorld(point: Point): Point {
|