@netless/window-manager 0.4.6 → 0.4.8

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.
@@ -0,0 +1,87 @@
1
+ import { callbacks, emitter } from "./index";
2
+ import type { View } from "white-web-sdk";
3
+ import type { AppProxy } from "./AppProxy";
4
+
5
+ export type RedoUndoContext = {
6
+ mainView: () => View;
7
+ focus: () => string | undefined;
8
+ getAppProxy: (id: string) => AppProxy | undefined;
9
+ };
10
+
11
+ export class RedoUndo {
12
+ constructor(private context: RedoUndoContext) {
13
+ emitter.on("focusedChange", changed => {
14
+ this.disposePrevFocusViewRedoUndoListeners(changed.prev);
15
+ setTimeout(() => {
16
+ this.addRedoUndoListeners(changed.focused);
17
+ }, 0);
18
+ });
19
+ emitter.on("rootDirRemoved", () => {
20
+ this.disposePrevFocusViewRedoUndoListeners(context.focus());
21
+ this.addRedoUndoListeners(context.focus());
22
+ });
23
+ this.addRedoUndoListeners(context.focus());
24
+ }
25
+
26
+ private addRedoUndoListeners = (focused: string | undefined) => {
27
+ if (focused === undefined) {
28
+ this.addViewCallbacks(
29
+ this.context.mainView(),
30
+ this.onCanRedoStepsUpdate,
31
+ this.onCanUndoStepsUpdate
32
+ );
33
+ } else {
34
+ const focusApp = this.context.getAppProxy(focused);
35
+ if (focusApp && focusApp.view) {
36
+ this.addViewCallbacks(
37
+ focusApp.view,
38
+ this.onCanRedoStepsUpdate,
39
+ this.onCanUndoStepsUpdate
40
+ );
41
+ }
42
+ }
43
+ };
44
+
45
+ private addViewCallbacks = (
46
+ view: View,
47
+ redoListener: (steps: number) => void,
48
+ undoListener: (steps: number) => void
49
+ ) => {
50
+ redoListener(view.canRedoSteps);
51
+ undoListener(view.canUndoSteps);
52
+ view.callbacks.on("onCanRedoStepsUpdate", redoListener);
53
+ view.callbacks.on("onCanUndoStepsUpdate", undoListener);
54
+ };
55
+
56
+ private disposeViewCallbacks = (view: View) => {
57
+ view.callbacks.off("onCanRedoStepsUpdate", this.onCanRedoStepsUpdate);
58
+ view.callbacks.off("onCanUndoStepsUpdate", this.onCanUndoStepsUpdate);
59
+ };
60
+
61
+ private onCanRedoStepsUpdate = (steps: number) => {
62
+ callbacks.emit("canRedoStepsChange", steps);
63
+ };
64
+
65
+ private onCanUndoStepsUpdate = (steps: number) => {
66
+ callbacks.emit("canUndoStepsChange", steps);
67
+ };
68
+
69
+ private disposePrevFocusViewRedoUndoListeners = (prevFocused: string | undefined) => {
70
+ let view: View | undefined = undefined;
71
+ if (prevFocused === undefined) {
72
+ view = this.context.mainView();
73
+ } else {
74
+ const appProxy = this.context.getAppProxy(prevFocused);
75
+ if (appProxy && appProxy.view) {
76
+ view = appProxy.view;
77
+ }
78
+ }
79
+ if (view) {
80
+ this.disposeViewCallbacks(view);
81
+ }
82
+ };
83
+
84
+ public destroy() {
85
+ this.disposePrevFocusViewRedoUndoListeners(this.context.focus());
86
+ }
87
+ }
@@ -15,6 +15,7 @@ class AppRegister {
15
15
  public appClasses: Map<string, () => Promise<NetlessApp>> = new Map();
16
16
 
17
17
  public async register(params: RegisterParams): Promise<void> {
18
+ this.appClassesCache.delete(params.kind);
18
19
  this.registered.set(params.kind, params);
19
20
 
20
21
  const srcOrAppOrFunction = params.src;
@@ -110,6 +110,17 @@ export class MainViewProxy {
110
110
  }
111
111
  }
112
112
 
113
+ public rebind(): void {
114
+ const divElement = this.mainView.divElement;
115
+ const disableCameraTransform = this.mainView.disableCameraTransform;
116
+ this.stop();
117
+ this.mainView.release();
118
+ this.mainView = this.createMainView();
119
+ this.mainView.disableCameraTransform = disableCameraTransform;
120
+ this.mainView.divElement = divElement;
121
+ this.start();
122
+ }
123
+
113
124
  private onCameraUpdatedByDevice = (camera: Camera) => {
114
125
  this.store.setMainViewCamera({ ...camera, id: this.manager.uid });
115
126
  if (!isEqual(this.mainViewSize, { ...this.mainView.size, id: this.manager.uid })) {
package/src/index.ts CHANGED
@@ -138,6 +138,9 @@ export type EmitterEvent = {
138
138
  onReconnected: void;
139
139
  removeScenes: string;
140
140
  cursorMove: CursorMovePayload;
141
+ updateManagerRect: undefined;
142
+ focusedChange: { focused: string | undefined, prev: string | undefined };
143
+ rootDirRemoved: undefined;
141
144
  };
142
145
 
143
146
  export type EmitterType = Emittery<EmitterEvent>;
@@ -180,7 +183,7 @@ export const callbacks: CallbacksType = new Emittery();
180
183
  export const reconnectRefresher = new ReconnectRefresher({ emitter });
181
184
 
182
185
  export type AddPageParams = {
183
- index?: number;
186
+ after?: boolean;
184
187
  scene?: SceneDefinition;
185
188
  }
186
189
 
@@ -374,7 +377,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
374
377
  }
375
378
  }
376
379
  }
377
- this.boxManager?.updateManagerRect();
380
+ emitter.emit("updateManagerRect");
378
381
  this.appManager?.refresh();
379
382
  this.appManager?.resetMaximized();
380
383
  this.appManager?.resetMinimized();
@@ -519,11 +522,13 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
519
522
 
520
523
  public async addPage(params?: AddPageParams): Promise<void> {
521
524
  if (this.appManager) {
522
- const index = params?.index;
523
- if (Number.isSafeInteger(index)) {
524
- this.room.putScenes(ROOT_DIR, [params?.scene || {}], index);
525
+ const after = params?.after;
526
+ const scene = params?.scene;
527
+ if (after) {
528
+ const nextIndex = this.mainViewSceneIndex + 1;
529
+ this.room.putScenes(ROOT_DIR, [scene || {}], nextIndex);
525
530
  } else {
526
- this.room.putScenes(ROOT_DIR, [params?.scene || {}]);
531
+ this.room.putScenes(ROOT_DIR, [scene || {}]);
527
532
  }
528
533
  }
529
534
  }