@netless/window-manager 0.4.13 → 0.4.14

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.13",
3
+ "version": "0.4.14",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",
@@ -55,6 +55,10 @@ export class AppListeners {
55
55
  this.cursorMoveHandler(data.payload);
56
56
  break;
57
57
  }
58
+ case Events.RootDirRemoved: {
59
+ this.rootDirRemovedHandler();
60
+ break;
61
+ }
58
62
  default:
59
63
  break;
60
64
  }
@@ -93,4 +97,8 @@ export class AppListeners {
93
97
  private cursorMoveHandler = (payload: any) => {
94
98
  emitter.emit("cursorMove", payload);
95
99
  };
100
+
101
+ private rootDirRemovedHandler = () => {
102
+ this.manager.onRootDirRemoved();
103
+ };
96
104
  }
package/src/AppManager.ts CHANGED
@@ -109,10 +109,8 @@ export class AppManager {
109
109
  private onRemoveScenes = (scenePath: string) => {
110
110
  // 如果移除根目录就把 scenePath 设置为初始值
111
111
  if (scenePath === ROOT_DIR) {
112
- this.setMainViewScenePath(INIT_DIR);
113
- this.createRootDirScenesCallback();
114
112
  this.onRootDirRemoved();
115
- emitter.emit("rootDirRemoved");
113
+ this.dispatchInternalEvent(Events.RootDirRemoved);
116
114
  return;
117
115
  }
118
116
  // 如果移除的 path 跟 MainViewScenePath 相同就取当前目录的当前 index
@@ -129,7 +127,10 @@ export class AppManager {
129
127
  * 根目录被删除时所有的 scene 都会被删除.
130
128
  * 所以需要关掉所有开启了 view 的 app
131
129
  */
132
- private onRootDirRemoved() {
130
+ public onRootDirRemoved() {
131
+ this.setMainViewScenePath(INIT_DIR);
132
+ this.createRootDirScenesCallback();
133
+
133
134
  this.appProxies.forEach(appProxy => {
134
135
  if (appProxy.view) {
135
136
  this.closeApp(appProxy.id);
@@ -137,6 +138,8 @@ export class AppManager {
137
138
  });
138
139
  // 删除了根目录的 scenes 之后 mainview 需要重新绑定, 否则主白板会不能渲染
139
140
  this.mainViewProxy.rebind();
141
+
142
+ emitter.emit("rootDirRemoved");
140
143
  }
141
144
 
142
145
  private onReadonlyChanged = () => {
@@ -274,34 +277,13 @@ export class AppManager {
274
277
  this.refresher?.add("mainViewIndex", () => {
275
278
  return autorun(() => {
276
279
  const mainSceneIndex = get(this.attributes, "_mainSceneIndex");
277
- if (mainSceneIndex !== undefined && this._prevSceneIndex !== mainSceneIndex) {
278
- callbacks.emit("mainViewSceneIndexChange", mainSceneIndex);
279
- emitter.emit("changePageState");
280
- if (this.callbacksNode) {
281
- this.updateSceneState(this.callbacksNode);
282
- }
283
- this._prevSceneIndex = mainSceneIndex;
284
- }
280
+ this.onMainViewIndexChange(mainSceneIndex);
285
281
  });
286
282
  });
287
283
  this.refresher?.add("focusedChange", () => {
288
284
  return autorun(() => {
289
285
  const focused = get(this.attributes, "focus");
290
- if (this._prevFocused !== focused) {
291
- callbacks.emit("focusedChange", focused);
292
- emitter.emit("focusedChange", { focused, prev: this._prevFocused });
293
- this._prevFocused = focused;
294
- if (focused !== undefined) {
295
- this.boxManager?.focusBox({ appId: focused });
296
- // 确保 focus 修改的时候, appProxy 已经创建
297
- setTimeout(() => {
298
- const appProxy = this.appProxies.get(focused);
299
- if (appProxy) {
300
- appRegister.notifyApp(appProxy.kind, "focus", { appId: focused });
301
- }
302
- }, 0);
303
- }
304
- }
286
+ this.onFocusChange(focused);
305
287
  });
306
288
  });
307
289
  this.refresher?.add("registeredChange", () => {
@@ -329,6 +311,35 @@ export class AppManager {
329
311
  });
330
312
  }
331
313
 
314
+ private onMainViewIndexChange = (index: number) => {
315
+ if (index !== undefined && this._prevSceneIndex !== index) {
316
+ callbacks.emit("mainViewSceneIndexChange", index);
317
+ emitter.emit("changePageState");
318
+ if (this.callbacksNode) {
319
+ this.updateSceneState(this.callbacksNode);
320
+ }
321
+ this._prevSceneIndex = index;
322
+ }
323
+ }
324
+
325
+ private onFocusChange = (focused: string | undefined) => {
326
+ if (this._prevFocused !== focused) {
327
+ callbacks.emit("focusedChange", focused);
328
+ emitter.emit("focusedChange", { focused, prev: this._prevFocused });
329
+ this._prevFocused = focused;
330
+ if (focused !== undefined) {
331
+ this.boxManager?.focusBox({ appId: focused });
332
+ // 确保 focus 修改的时候, appProxy 已经创建
333
+ setTimeout(() => {
334
+ const appProxy = this.appProxies.get(focused);
335
+ if (appProxy) {
336
+ appRegister.notifyApp(appProxy.kind, "focus", { appId: focused });
337
+ }
338
+ }, 0);
339
+ }
340
+ }
341
+ }
342
+
332
343
  /**
333
344
  * 插件更新 attributes 时的回调
334
345
  *
@@ -717,7 +728,7 @@ export class AppManager {
717
728
  });
718
729
  }
719
730
 
720
- public dispatchInternalEvent(event: Events, payload: any) {
731
+ public dispatchInternalEvent(event: Events, payload?: any) {
721
732
  this.safeDispatchMagixEvent(MagixEventName, {
722
733
  eventName: event,
723
734
  payload: payload,
@@ -0,0 +1,47 @@
1
+ import type { ScenesCallbacks, ScenesCallbacksNode } from "white-web-sdk";
2
+ import type { AppManager } from "../AppManager";
3
+
4
+ export class ScenesCallbackManager {
5
+
6
+ private nodes: Map<string, ScenesCallbacksNode> = new Map();
7
+
8
+ constructor(private manager: AppManager) {}
9
+
10
+ public createNode(path: string, callbacks?: Partial<ScenesCallbacks>): ScenesCallbacksNode | null {
11
+ const node = this.manager.displayer.createScenesCallback(path, callbacks);
12
+ if (node) {
13
+ this.nodes.set(path, node);
14
+ }
15
+ return node;
16
+ }
17
+
18
+ public getScenes(path: string) {
19
+ const node = this.nodes.get(path);
20
+ return node?.scenes;
21
+ }
22
+
23
+ public getScenesOnce(path: string) {
24
+ let node = this.nodes.get(path);
25
+ if (!node) {
26
+ const created = this.createNode(path);
27
+ if (created) {
28
+ node = created;
29
+ }
30
+ }
31
+ const scenes = node?.scenes;
32
+ this.removeNode(path);
33
+ return scenes;
34
+ }
35
+
36
+ public removeNode(path: string) {
37
+ const node = this.nodes.get(path);
38
+ if (node) {
39
+ node.dispose();
40
+ this.nodes.delete(path);
41
+ }
42
+ }
43
+
44
+ public destroy(): void {
45
+ this.nodes.forEach(node => node.dispose());
46
+ }
47
+ }
package/src/constants.ts CHANGED
@@ -13,6 +13,7 @@ export enum Events {
13
13
  MoveCamera = "MoveCamera",
14
14
  MoveCameraToContain = "MoveCameraToContain",
15
15
  CursorMove = "CursorMove",
16
+ RootDirRemoved = "RootDirRemoved",
16
17
  }
17
18
 
18
19
  export const MagixEventName = "__WindowManger";