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

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",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",
package/src/AppManager.ts CHANGED
@@ -395,6 +395,9 @@ export class AppManager {
395
395
  if (appProxy) {
396
396
  appProxy.destroy(false, true, payload.error);
397
397
  }
398
+ if (this.boxManager.maximized) {
399
+ this.boxManager.focusTopBox();
400
+ }
398
401
  break;
399
402
  }
400
403
  case "boxStateChange": {
package/src/BoxManager.ts CHANGED
@@ -268,8 +268,8 @@ export class BoxManager {
268
268
  this.teleBoxManager.update(appId, { x, y }, true);
269
269
  }
270
270
 
271
- public focusBox({ appId }: AppId): void {
272
- this.teleBoxManager.update(appId, { focus: true }, true);
271
+ public focusBox({ appId }: AppId, skipUpdate = true): void {
272
+ this.teleBoxManager.update(appId, { focus: true }, skipUpdate);
273
273
  }
274
274
 
275
275
  public resizeBox({ appId, width, height, skipUpdate }: ResizeBoxParams): void {
@@ -315,6 +315,16 @@ export class BoxManager {
315
315
  this.teleBoxManager.setMinimized(minimized, skipUpdate);
316
316
  }
317
317
 
318
+ public focusTopBox(): void {
319
+ const boxes = this.teleBoxManager.query();
320
+ if (boxes.length >= 1) {
321
+ const box = this.getTopBox();
322
+ if (box) {
323
+ this.focusBox({ appId: box.id }, false);
324
+ }
325
+ }
326
+ }
327
+
318
328
  public setReadonly(readonly: boolean) {
319
329
  this.teleBoxManager.setReadonly(readonly);
320
330
  }
package/src/MainView.ts CHANGED
@@ -24,8 +24,14 @@ export class MainViewProxy extends Base {
24
24
  emitter.once("mainViewMounted").then(() => {
25
25
  setTimeout(() => {
26
26
  this.start();
27
+ if (!this.mainViewCamera || !this.mainViewSize) {
28
+ this.setCameraAndSize();
29
+ }
27
30
  }, 200); // 等待 mainView 挂载完毕再进行监听,否则会触发不必要的 onSizeUpdated
28
31
  });
32
+ emitter.on("playgroundSizeChange", () => {
33
+ this.sizeChangeHandler(this.mainViewSize);
34
+ });
29
35
  }
30
36
 
31
37
  private get mainViewCamera() {
@@ -43,10 +49,9 @@ export class MainViewProxy extends Base {
43
49
 
44
50
  public start() {
45
51
  if (this.started) return;
52
+ this.sizeChangeHandler(this.mainViewSize);
46
53
  this.addCameraListener();
47
54
  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
55
  this.started = true;
51
56
  }
52
57
 
@@ -60,6 +65,7 @@ export class MainViewProxy extends Base {
60
65
  () => this.mainViewCamera,
61
66
  camera => {
62
67
  if (camera && camera.id !== this.context.uid) {
68
+ this.moveCameraToContian(this.mainViewSize);
63
69
  this.moveCamera(camera);
64
70
  }
65
71
  },
@@ -69,20 +75,12 @@ export class MainViewProxy extends Base {
69
75
  );
70
76
  };
71
77
 
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
- };
78
+ private sizeChangeHandler = debounce((size: Size) => {
79
+ if (size) {
80
+ this.moveCameraToContian(size);
81
+ this.moveCamera(this.mainViewCamera);
82
+ }
83
+ }, 30);
86
84
 
87
85
  public get view(): View {
88
86
  return this.mainView;
@@ -104,9 +102,9 @@ export class MainViewProxy extends Base {
104
102
  return mainView;
105
103
  }
106
104
 
107
- private cameraListener = (camera: Camera) => {
105
+ private onCameraUpdatedByDevice = (camera: Camera) => {
108
106
  this.store.setMainViewCamera({ ...camera, id: this.context.uid });
109
- if (this.store.getMainViewSize()?.id !== this.context.uid) {
107
+ if (!isEqual(this.mainViewSize, {...this.mainView.size, id: this.context.uid})) {
110
108
  this.setMainViewSize(this.view.size);
111
109
  }
112
110
  };
@@ -138,28 +136,25 @@ export class MainViewProxy extends Base {
138
136
  this.context.blurFocusBox();
139
137
  }
140
138
 
141
- private sizeListener = (size: Size) => {
142
- this.setMainViewSize(size);
143
- callbacks.emit("cameraStateChange", this.cameraState);
144
- };
145
-
146
139
  public setMainViewSize = debounce(size => {
147
140
  this.store.setMainViewSize({ ...size, id: this.context.uid });
148
141
  }, 50);
149
142
 
150
143
  private addCameraListener() {
151
- this.view.callbacks.on("onCameraUpdatedByDevice", this.cameraListener);
152
- this.view.callbacks.on("onCameraUpdated", this.cameraStateChangeListener);
144
+ this.view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
145
+ this.view.callbacks.on("onCameraUpdated", this.onCameraOrSizeUpdated);
146
+ this.view.callbacks.on("onSizeUpdated", this.onCameraOrSizeUpdated);
153
147
  }
154
148
 
155
149
  private removeCameraListener() {
156
- this.view.callbacks.off("onCameraUpdatedByDevice", this.cameraListener);
157
- this.view.callbacks.off("onCameraUpdated", this.cameraStateChangeListener)
150
+ this.view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
151
+ this.view.callbacks.off("onCameraUpdated", this.onCameraOrSizeUpdated);
152
+ this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
158
153
  }
159
154
 
160
- private cameraStateChangeListener = () => {
155
+ private onCameraOrSizeUpdated = () => {
161
156
  callbacks.emit("cameraStateChange", this.cameraState);
162
- }
157
+ };
163
158
 
164
159
  public switchViewModeToWriter(): void {
165
160
  if (!this.manager.canOperate) return;
@@ -203,7 +198,6 @@ export class MainViewProxy extends Base {
203
198
  this.removeCameraListener();
204
199
  this.manager.refresher?.remove(Fields.MainViewCamera);
205
200
  this.manager.refresher?.remove(Fields.MainViewSize);
206
- this.view.callbacks.off("onSizeUpdated", this.sizeListener);
207
201
  this.started = false;
208
202
  }
209
203
 
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";
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