@netless/window-manager 0.4.22 → 0.4.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "0.4.22",
3
+ "version": "0.4.23",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",
package/src/AppManager.ts CHANGED
@@ -585,6 +585,7 @@ export class AppManager {
585
585
  } else {
586
586
  this.mainView.disableCameraTransform = true;
587
587
  }
588
+ emitter.emit("writableChange", isWritable);
588
589
  };
589
590
 
590
591
  public safeSetAttributes(attributes: any) {
@@ -38,6 +38,11 @@ export type StoreContext = {
38
38
  safeUpdateAttributes: (keys: string[], value: any) => void;
39
39
  safeSetAttributes: (attributes: any) => void;
40
40
  }
41
+
42
+ export type ICamera = Camera & { id: string };
43
+
44
+ export type ISize = Size & { id: string };
45
+
41
46
  export class AttributesDelegate {
42
47
 
43
48
  constructor(private context: StoreContext) {}
@@ -152,14 +157,21 @@ export class AttributesDelegate {
152
157
  return get(this.attributes, [Fields.MainViewSize]);
153
158
  }
154
159
 
155
- public setMainViewCamera(camera: (Camera & { id: string }) | undefined) {
160
+ public setMainViewCamera(camera: ICamera) {
156
161
  this.context.safeSetAttributes({ [Fields.MainViewCamera]: { ...camera } });
157
162
  }
158
163
 
159
- public setMainViewSize(size: (Size & { id: string }) | undefined) {
164
+ public setMainViewSize(size: ISize) {
160
165
  this.context.safeSetAttributes({ [Fields.MainViewSize]: { ...size } });
161
166
  }
162
167
 
168
+ public setMainViewCameraAndSize(camera: ICamera, size: ISize) {
169
+ this.context.safeSetAttributes({
170
+ [Fields.MainViewCamera]: { ...camera },
171
+ [Fields.MainViewSize]: { ...size },
172
+ });
173
+ }
174
+
163
175
  public setAppFocus = (appId: string, focus: boolean) => {
164
176
  if (focus) {
165
177
  this.context.safeSetAttributes({ [Fields.Focus]: appId });
@@ -24,6 +24,7 @@ export type EmitterEvent = {
24
24
  rootDirRemoved: undefined;
25
25
  setReadonly: boolean;
26
26
  changePageState: undefined;
27
+ writableChange: boolean;
27
28
  };
28
29
 
29
30
  export type EmitterType = Emittery<EmitterEvent>;
@@ -25,10 +25,8 @@ export class MainViewProxy {
25
25
  emitter.once("mainViewMounted").then(() => {
26
26
  this.addMainViewListener();
27
27
  this.start();
28
- if (!this.mainViewCamera || !this.mainViewSize) {
29
- manager.dispatchInternalEvent(Events.InitMainViewCamera)
30
- this.setCameraAndSize();
31
- }
28
+ this.ensureCameraAndSize();
29
+ this.startListenWritableChange();
32
30
  });
33
31
  const playgroundSizeChangeListener = () => {
34
32
  this.sizeChangeHandler(this.mainViewSize);
@@ -39,6 +37,23 @@ export class MainViewProxy {
39
37
  });
40
38
  }
41
39
 
40
+ private startListenWritableChange = () => {
41
+ this.sideEffectManager.add(() => {
42
+ return emitter.on("writableChange", isWritable => {
43
+ if (isWritable) {
44
+ this.ensureCameraAndSize();
45
+ }
46
+ });
47
+ });
48
+ }
49
+
50
+ public ensureCameraAndSize() {
51
+ if (!this.mainViewCamera || !this.mainViewSize) {
52
+ this.manager.dispatchInternalEvent(Events.InitMainViewCamera);
53
+ this.setCameraAndSize();
54
+ }
55
+ }
56
+
42
57
  private get mainViewCamera() {
43
58
  return this.store.getMainViewCamera();
44
59
  }
@@ -62,11 +77,12 @@ export class MainViewProxy {
62
77
 
63
78
  public addCameraReaction = () => {
64
79
  this.manager.refresher?.add(Fields.MainViewCamera, this.cameraReaction);
65
- }
80
+ };
66
81
 
67
82
  public setCameraAndSize(): void {
68
- this.store.setMainViewCamera({ ...this.mainView.camera, id: this.manager.uid });
69
- this.store.setMainViewSize({ ...this.mainView.size, id: this.manager.uid });
83
+ const camera = { ...this.mainView.camera, id: this.manager.uid };
84
+ const size = { ...this.mainView.size, id: this.manager.uid };
85
+ this.store.setMainViewCameraAndSize(camera, size);
70
86
  }
71
87
 
72
88
  private cameraReaction = () => {
@@ -77,7 +93,8 @@ export class MainViewProxy {
77
93
  this.moveCameraToContian(this.mainViewSize);
78
94
  this.moveCamera(camera);
79
95
  }
80
- }, { fireImmediately: true }
96
+ },
97
+ { fireImmediately: true }
81
98
  );
82
99
  };
83
100