@netless/window-manager 0.3.16-canary.0 → 0.3.16-canary.1

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.3.16-canary.0",
3
+ "version": "0.3.16-canary.1",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",
package/src/MainView.ts CHANGED
@@ -26,6 +26,9 @@ export class MainViewProxy extends Base {
26
26
  this.start();
27
27
  }, 200); // 等待 mainView 挂载完毕再进行监听,否则会触发不必要的 onSizeUpdated
28
28
  });
29
+ emitter.on("playgroundSizeChange", () => {
30
+ this.sizeChangeHandler(this.mainViewSize);
31
+ });
29
32
  }
30
33
 
31
34
  private get mainViewCamera() {
@@ -43,10 +46,9 @@ export class MainViewProxy extends Base {
43
46
 
44
47
  public start() {
45
48
  if (this.started) return;
49
+ this.sizeChangeHandler(this.mainViewSize);
46
50
  this.addCameraListener();
47
51
  this.manager.refresher?.add(Fields.MainViewCamera, this.cameraReaction);
48
- this.manager.refresher?.add(Fields.MainViewSize, this.sizeReaction);
49
- this.view.callbacks.on("onSizeUpdated", this.sizeListener);
50
52
  this.started = true;
51
53
  }
52
54
 
@@ -60,6 +62,7 @@ export class MainViewProxy extends Base {
60
62
  () => this.mainViewCamera,
61
63
  camera => {
62
64
  if (camera && camera.id !== this.context.uid) {
65
+ this.moveCameraToContian(this.mainViewSize);
63
66
  this.moveCamera(camera);
64
67
  }
65
68
  },
@@ -69,20 +72,12 @@ export class MainViewProxy extends Base {
69
72
  );
70
73
  };
71
74
 
72
- private sizeReaction = () => {
73
- return reaction(
74
- () => this.mainViewSize,
75
- size => {
76
- if (size && size.id !== this.context.uid) {
77
- this.moveCameraToContian(size);
78
- this.moveCamera(this.mainViewCamera);
79
- }
80
- },
81
- {
82
- fireImmediately: true,
83
- }
84
- );
85
- };
75
+ private sizeChangeHandler = debounce((size: Size) => {
76
+ if (size) {
77
+ this.moveCameraToContian(size);
78
+ this.moveCamera(this.mainViewCamera);
79
+ }
80
+ }, 30);
86
81
 
87
82
  public get view(): View {
88
83
  return this.mainView;
@@ -104,9 +99,9 @@ export class MainViewProxy extends Base {
104
99
  return mainView;
105
100
  }
106
101
 
107
- private cameraListener = (camera: Camera) => {
102
+ private onCameraUpdatedByDevice = (camera: Camera) => {
108
103
  this.store.setMainViewCamera({ ...camera, id: this.context.uid });
109
- if (this.store.getMainViewSize()?.id !== this.context.uid) {
104
+ if (!isEqual(this.mainViewSize, {...this.mainView.size, id: this.context.uid})) {
110
105
  this.setMainViewSize(this.view.size);
111
106
  }
112
107
  };
@@ -138,28 +133,25 @@ export class MainViewProxy extends Base {
138
133
  this.context.blurFocusBox();
139
134
  }
140
135
 
141
- private sizeListener = (size: Size) => {
142
- this.setMainViewSize(size);
143
- callbacks.emit("cameraStateChange", this.cameraState);
144
- };
145
-
146
136
  public setMainViewSize = debounce(size => {
147
137
  this.store.setMainViewSize({ ...size, id: this.context.uid });
148
138
  }, 50);
149
139
 
150
140
  private addCameraListener() {
151
- this.view.callbacks.on("onCameraUpdatedByDevice", this.cameraListener);
152
- this.view.callbacks.on("onCameraUpdated", this.cameraStateChangeListener);
141
+ this.view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
142
+ this.view.callbacks.on("onCameraUpdated", this.onCameraOrSizeUpdated);
143
+ this.view.callbacks.on("onSizeUpdated", this.onCameraOrSizeUpdated);
153
144
  }
154
145
 
155
146
  private removeCameraListener() {
156
- this.view.callbacks.off("onCameraUpdatedByDevice", this.cameraListener);
157
- this.view.callbacks.off("onCameraUpdated", this.cameraStateChangeListener)
147
+ this.view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
148
+ this.view.callbacks.off("onCameraUpdated", this.onCameraOrSizeUpdated);
149
+ this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
158
150
  }
159
151
 
160
- private cameraStateChangeListener = () => {
152
+ private onCameraOrSizeUpdated = () => {
161
153
  callbacks.emit("cameraStateChange", this.cameraState);
162
- }
154
+ };
163
155
 
164
156
  public switchViewModeToWriter(): void {
165
157
  if (!this.manager.canOperate) return;
@@ -203,7 +195,6 @@ export class MainViewProxy extends Base {
203
195
  this.removeCameraListener();
204
196
  this.manager.refresher?.remove(Fields.MainViewCamera);
205
197
  this.manager.refresher?.remove(Fields.MainViewSize);
206
- this.view.callbacks.off("onSizeUpdated", this.sizeListener);
207
198
  this.started = false;
208
199
  }
209
200
 
package/src/index.ts CHANGED
@@ -135,6 +135,7 @@ export type EmitterEvent = {
135
135
  mainViewMounted: undefined;
136
136
  observerIdChange: number;
137
137
  boxStateChange: string;
138
+ playgroundSizeChange: DOMRect;
138
139
  };
139
140
 
140
141
  export const emitter: Emittery<EmitterEvent> = new Emittery();
@@ -175,7 +176,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
175
176
  public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
176
177
  private static isCreated = false;
177
178
 
178
- public version = "0.3.16-canary.0";
179
+ public version = "0.3.16-canary.1";
179
180
 
180
181
  public appListeners?: AppListeners;
181
182
 
@@ -700,6 +701,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
700
701
  this.updateSizer(containerRect, sizer, wrapper);
701
702
  this.cursorManager?.updateContainerRect();
702
703
  this.appManager?.boxManager.updateManagerRect();
704
+ emitter.emit("playgroundSizeChange", containerRect);
703
705
  }
704
706
  });
705
707