@netless/window-manager 0.4.5 → 0.4.8-canary.0

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
+ }
@@ -33,7 +33,7 @@ export const replaceRoomFunction = (room: Room | Player, manager: WindowManager)
33
33
  },
34
34
  });
35
35
 
36
- room.moveCamera = (camera: Camera) => manager.mainView.moveCamera(camera);
36
+ room.moveCamera = (camera: Camera) => manager.moveCamera(camera);
37
37
  room.moveCameraToContain = (...args) => manager.moveCameraToContain(...args);
38
38
  room.convertToPointInWorld = (...args) => manager.mainView.convertToPointInWorld(...args);
39
39
  room.setCameraBound = (...args) => manager.mainView.setCameraBound(...args);
@@ -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
@@ -6,7 +6,7 @@ import { checkVersion, setupWrapper } from "./Helper";
6
6
  import { ContainerResizeObserver } from "./ContainerResizeObserver";
7
7
  import { createBoxManager } from "./BoxManager";
8
8
  import { CursorManager } from "./Cursor";
9
- import { DEFAULT_CONTAINER_RATIO, Events } from "./constants";
9
+ import { DEFAULT_CONTAINER_RATIO, Events, ROOT_DIR } from "./constants";
10
10
  import { Fields } from "./AttributesDelegate";
11
11
  import { initDb } from "./Register/storage";
12
12
  import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
@@ -15,6 +15,7 @@ import { log } from "./Utils/log";
15
15
  import { ReconnectRefresher } from "./ReconnectRefresher";
16
16
  import { replaceRoomFunction } from "./Utils/RoomHacker";
17
17
  import { setupBuiltin } from "./BuiltinApps";
18
+ import "video.js/dist/video-js.css";
18
19
  import "./style.css";
19
20
  import "@netless/telebox-insider/dist/style.css";
20
21
  import type { LoadAppEvent } from "./Register";
@@ -137,6 +138,9 @@ export type EmitterEvent = {
137
138
  onReconnected: void;
138
139
  removeScenes: string;
139
140
  cursorMove: CursorMovePayload;
141
+ updateManagerRect: undefined;
142
+ focusedChange: { focused: string | undefined, prev: string | undefined };
143
+ rootDirRemoved: undefined;
140
144
  };
141
145
 
142
146
  export type EmitterType = Emittery<EmitterEvent>;
@@ -178,6 +182,11 @@ export const callbacks: CallbacksType = new Emittery();
178
182
 
179
183
  export const reconnectRefresher = new ReconnectRefresher({ emitter });
180
184
 
185
+ export type AddPageParams = {
186
+ after?: boolean;
187
+ scene?: SceneDefinition;
188
+ }
189
+
181
190
  export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
182
191
  public static kind = "WindowManager";
183
192
  public static displayer: Displayer;
@@ -368,7 +377,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
368
377
  }
369
378
  }
370
379
  }
371
- this.boxManager?.updateManagerRect();
380
+ emitter.emit("updateManagerRect");
372
381
  this.appManager?.refresh();
373
382
  this.appManager?.resetMaximized();
374
383
  this.appManager?.resetMinimized();
@@ -483,6 +492,47 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
483
492
  }
484
493
  }
485
494
 
495
+ public async nextPage(): Promise<boolean> {
496
+ if (this.appManager) {
497
+ const nextIndex = this.mainViewSceneIndex + 1;
498
+ if (nextIndex >= this.mainViewScenesLength) {
499
+ console.warn(`[WindowManager]: current page is the last page`);
500
+ return false;
501
+ };
502
+ await this.appManager.setMainViewSceneIndex(nextIndex);
503
+ return true;
504
+ } else {
505
+ return false;
506
+ }
507
+ }
508
+
509
+ public async prevPage(): Promise<boolean> {
510
+ if (this.appManager) {
511
+ const prevIndex = this.mainViewSceneIndex - 1;
512
+ if (prevIndex < 0) {
513
+ console.warn(`[WindowManager]: current page is the first page`);
514
+ return false;
515
+ };
516
+ await this.appManager.setMainViewSceneIndex(prevIndex);
517
+ return true;
518
+ } else {
519
+ return false;
520
+ }
521
+ }
522
+
523
+ public async addPage(params?: AddPageParams): Promise<void> {
524
+ if (this.appManager) {
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);
530
+ } else {
531
+ this.room.putScenes(ROOT_DIR, [scene || {}]);
532
+ }
533
+ }
534
+ }
535
+
486
536
  /**
487
537
  * 返回 mainView 的 ScenePath
488
538
  */