@netless/window-manager 0.4.61 → 0.4.63

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/src/RedoUndo.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { callbacks } from "./callback";
2
- import { emitter } from "./InternalEmitter";
2
+ import { internalEmitter } from "./InternalEmitter";
3
3
  import type { View } from "white-web-sdk";
4
4
  import type { AppProxy } from "./App";
5
5
 
@@ -11,13 +11,13 @@ export type RedoUndoContext = {
11
11
 
12
12
  export class RedoUndo {
13
13
  constructor(private context: RedoUndoContext) {
14
- emitter.on("focusedChange", changed => {
14
+ internalEmitter.on("focusedChange", changed => {
15
15
  this.disposePrevFocusViewRedoUndoListeners(changed.prev);
16
16
  setTimeout(() => {
17
17
  this.addRedoUndoListeners(changed.focused);
18
18
  }, 0);
19
19
  });
20
- emitter.on("rootDirRemoved", () => {
20
+ internalEmitter.on("rootDirRemoved", () => {
21
21
  this.disposePrevFocusViewRedoUndoListeners(context.focus());
22
22
  this.addRedoUndoListeners(context.focus());
23
23
  });
@@ -1,6 +1,6 @@
1
1
  import { appRegister } from "../Register";
2
2
  import { debounce } from "lodash";
3
- import { emitter } from "../InternalEmitter";
3
+ import { internalEmitter } from "../InternalEmitter";
4
4
  import { ROOT_DIR } from "../constants";
5
5
  import { ScenePathType } from "white-web-sdk";
6
6
  import { v4 } from "uuid";
@@ -69,15 +69,15 @@ export const setViewMode = (view: View, mode: ViewVisionMode) => {
69
69
  };
70
70
 
71
71
  export const emitError = (error: Error) => {
72
- if (emitter.listenerCount("error") > 0) {
73
- emitter.emit("error", error);
72
+ if (internalEmitter.listenerCount("error") > 0) {
73
+ internalEmitter.emit("error", error);
74
74
  } else {
75
75
  console.log("[WindowManager]:", error);
76
76
  }
77
77
  };
78
78
 
79
79
  export const addEmitterOnceListener = (event: any, listener: any) => {
80
- emitter.once(event).then(listener);
80
+ internalEmitter.once(event).then(listener);
81
81
  };
82
82
 
83
83
  export const notifyMainViewModeChange = debounce(
@@ -1,4 +1,4 @@
1
- import { emitter } from "../InternalEmitter";
1
+ import { internalEmitter } from "../InternalEmitter";
2
2
  import { isPlayer } from "white-web-sdk";
3
3
  import type { WindowManager } from "../index";
4
4
  import type { Camera, Room, Player, PlayerSeekingResult } from "white-web-sdk";
@@ -66,7 +66,7 @@ const delegateRemoveScenes = (room: Room, manager: WindowManager) => {
66
66
  manager.appManager?.updateRootDirRemoving(true);
67
67
  }
68
68
  const result = originRemoveScenes.call(room, scenePath);
69
- emitter.emit("removeScenes", { scenePath, index });
69
+ internalEmitter.emit("removeScenes", { scenePath, index });
70
70
  return result;
71
71
  };
72
72
  };
@@ -76,9 +76,9 @@ const delegateSeekToProgressTime = (player: Player) => {
76
76
  // eslint-disable-next-line no-inner-declarations
77
77
  async function newSeek(time: number): Promise<PlayerSeekingResult> {
78
78
  // seek 时需要先关闭所有的 app 防止内部使用的 mobx 出现错误
79
- await emitter.emit("seekStart");
79
+ await internalEmitter.emit("seekStart");
80
80
  const seekResult = await originSeek.call(player, time);
81
- emitter.emit("seek", time);
81
+ internalEmitter.emit("seek", time);
82
82
  return seekResult;
83
83
  }
84
84
  player.seekToProgressTime = newSeek;
@@ -2,7 +2,7 @@ import { AnimationMode, reaction, ViewMode } from "white-web-sdk";
2
2
  import { callbacks } from "../callback";
3
3
  import { createView } from "./ViewManager";
4
4
  import { debounce, get, isEmpty, isEqual } from "lodash";
5
- import { emitter } from "../InternalEmitter";
5
+ import { internalEmitter } from "../InternalEmitter";
6
6
  import { Fields } from "../AttributesDelegate";
7
7
  import { setViewFocusScenePath } from "../Utils/Common";
8
8
  import { SideEffectManager } from "side-effect-manager";
@@ -23,7 +23,7 @@ export class MainViewProxy {
23
23
  constructor(private manager: AppManager) {
24
24
  this.mainView = this.createMainView();
25
25
  this.moveCameraSizeByAttributes();
26
- emitter.once("mainViewMounted").then(() => {
26
+ internalEmitter.once("mainViewMounted").then(() => {
27
27
  this.addMainViewListener();
28
28
  this.start();
29
29
  this.ensureCameraAndSize();
@@ -33,13 +33,13 @@ export class MainViewProxy {
33
33
  this.sizeChangeHandler(this.mainViewSize);
34
34
  };
35
35
  this.sideEffectManager.add(() => {
36
- return emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
36
+ return internalEmitter.on("playgroundSizeChange", playgroundSizeChangeListener);
37
37
  });
38
38
  this.sideEffectManager.add(() => {
39
- return emitter.on("containerSizeRatioUpdate", this.onUpdateContainerSizeRatio);
39
+ return internalEmitter.on("containerSizeRatioUpdate", this.onUpdateContainerSizeRatio);
40
40
  });
41
41
  this.sideEffectManager.add(() => {
42
- return emitter.on("startReconnect", () => {
42
+ return internalEmitter.on("startReconnect", () => {
43
43
  if (!this.didRelease) {
44
44
  this.mainView.release();
45
45
  }
@@ -49,7 +49,7 @@ export class MainViewProxy {
49
49
 
50
50
  private startListenWritableChange = () => {
51
51
  this.sideEffectManager.add(() => {
52
- return emitter.on("writableChange", isWritable => {
52
+ return internalEmitter.on("writableChange", isWritable => {
53
53
  if (isWritable) {
54
54
  this.ensureCameraAndSize();
55
55
  }
package/src/callback.ts CHANGED
@@ -20,6 +20,8 @@ export type PublicEvent = {
20
20
  ready: undefined; // 所有 APP 创建完毕时触发
21
21
  sceneStateChange: SceneState;
22
22
  pageStateChange: PageState;
23
+ fullscreenChange: boolean;
24
+ appsChange: string[]; // APP 列表变化时触发
23
25
  };
24
26
 
25
27
  export type CallbacksType = Emittery<PublicEvent>;
package/src/index.ts CHANGED
@@ -7,7 +7,7 @@ import { ContainerResizeObserver } from "./ContainerResizeObserver";
7
7
  import { createBoxManager } from "./BoxManager";
8
8
  import { CursorManager } from "./Cursor";
9
9
  import { DEFAULT_CONTAINER_RATIO, Events, INIT_DIR, ROOT_DIR } from "./constants";
10
- import { emitter } from "./InternalEmitter";
10
+ import { internalEmitter } from "./InternalEmitter";
11
11
  import { Fields } from "./AttributesDelegate";
12
12
  import { initDb } from "./Register/storage";
13
13
  import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
@@ -130,7 +130,7 @@ export type MountParams = {
130
130
  container?: HTMLElement;
131
131
  /** 白板高宽比例, 默认为 9 / 16 */
132
132
  containerSizeRatio?: number;
133
- /** 显示 PS 透明背景,默认 true */
133
+ /** @deprecated 显示 PS 透明背景,默认 true */
134
134
  chessboard?: boolean;
135
135
  collectorContainer?: HTMLElement;
136
136
  collectorStyles?: Partial<CSSStyleDeclaration>;
@@ -140,14 +140,16 @@ export type MountParams = {
140
140
  disableCameraTransform?: boolean;
141
141
  prefersColorScheme?: TeleBoxColorScheme;
142
142
  applianceIcons?: ApplianceIcons;
143
+ fullscreen?: boolean;
143
144
  };
144
145
 
145
- export const reconnectRefresher = new ReconnectRefresher({ emitter });
146
+ export const reconnectRefresher = new ReconnectRefresher({ emitter: internalEmitter });
146
147
 
147
148
  export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any> implements PageController {
148
149
  public static kind = "WindowManager";
149
150
  public static displayer: Displayer;
150
151
  public static wrapper?: HTMLElement;
152
+ public static sizer?: HTMLElement;
151
153
  public static playground?: HTMLElement;
152
154
  public static container?: HTMLElement;
153
155
  public static debug = false;
@@ -166,6 +168,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
166
168
  public viewMode = ViewMode.Broadcaster;
167
169
  public isReplay = isPlayer(this.displayer);
168
170
  private _pageState?: PageStateImpl;
171
+ private _fullscreen?: boolean;
169
172
 
170
173
  private boxManager?: BoxManager;
171
174
  private static params?: MountParams;
@@ -234,6 +237,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
234
237
  }
235
238
  await manager.ensureAttributes();
236
239
 
240
+ manager._fullscreen = params.fullscreen;
237
241
  manager.appManager = new AppManager(manager);
238
242
  manager._pageState = new PageStateImpl(manager.appManager);
239
243
  manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor), params.applianceIcons);
@@ -246,7 +250,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
246
250
  }
247
251
 
248
252
  replaceRoomFunction(room, manager);
249
- emitter.emit("onCreated");
253
+ internalEmitter.emit("onCreated");
250
254
  WindowManager.isCreated = true;
251
255
  try {
252
256
  await initDb();
@@ -282,9 +286,17 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
282
286
  private static initContainer(
283
287
  manager: WindowManager,
284
288
  container: HTMLElement,
285
- chessboard: boolean | undefined,
286
- overwriteStyles: string | undefined
289
+ params: {
290
+ chessboard?: boolean,
291
+ overwriteStyles?: string,
292
+ fullscreen?: boolean,
293
+ }
287
294
  ) {
295
+ const {
296
+ chessboard,
297
+ overwriteStyles,
298
+ fullscreen,
299
+ } = params;
288
300
  if (!WindowManager.container) {
289
301
  WindowManager.container = container;
290
302
  }
@@ -293,6 +305,9 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
293
305
  if (chessboard) {
294
306
  sizer.classList.add("netless-window-manager-chess-sizer");
295
307
  }
308
+ if (fullscreen) {
309
+ sizer.classList.add("netless-window-manager-fullscreen");
310
+ }
296
311
  if (overwriteStyles) {
297
312
  const style = document.createElement("style");
298
313
  style.textContent = overwriteStyles;
@@ -302,9 +317,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
302
317
  playground,
303
318
  sizer,
304
319
  wrapper,
305
- emitter
320
+ internalEmitter
306
321
  );
307
322
  WindowManager.wrapper = wrapper;
323
+ WindowManager.sizer = sizer;
308
324
  return mainViewElement;
309
325
  }
310
326
 
@@ -323,16 +339,11 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
323
339
  } else {
324
340
  if (WindowManager.params) {
325
341
  const params = WindowManager.params;
326
- const mainViewElement = WindowManager.initContainer(
327
- this,
328
- container,
329
- params.chessboard,
330
- params.overwriteStyles
331
- );
342
+ const mainViewElement = WindowManager.initContainer(this, container, params);
332
343
  if (this.boxManager) {
333
344
  this.boxManager.destroy();
334
345
  }
335
- const boxManager = createBoxManager(this, callbacks, emitter, boxEmitter, {
346
+ const boxManager = createBoxManager(this, callbacks, internalEmitter, boxEmitter, {
336
347
  collectorContainer: params.collectorContainer,
337
348
  collectorStyles: params.collectorStyles,
338
349
  prefersColorScheme: params.prefersColorScheme,
@@ -345,7 +356,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
345
356
  }
346
357
  }
347
358
  }
348
- emitter.emit("updateManagerRect");
359
+ internalEmitter.emit("updateManagerRect");
349
360
  this.appManager?.refresh();
350
361
  this.appManager?.resetMaximized();
351
362
  this.appManager?.resetMinimized();
@@ -385,7 +396,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
385
396
  // 移除根目录时需要做一些异步的释放操作 addApp 需要等待释放完成才可以继续添加
386
397
  if (this.appManager.rootDirRemoving) {
387
398
  return new Promise((resolve, reject) => {
388
- emitter.once("rootDirRemoved").then(async () => {
399
+ internalEmitter.once("rootDirRemoved").then(async () => {
389
400
  try {
390
401
  const appId = await this._addApp(params);
391
402
  resolve(appId);
@@ -515,6 +526,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
515
526
  }
516
527
  }
517
528
 
529
+ public async jumpPage(index: number): Promise<boolean> {
530
+ if (this.appManager) {
531
+ if (index < 0 || index >= this.pageState.length) {
532
+ console.warn(`[WindowManager]: index ${index} out of range`);
533
+ return false;
534
+ }
535
+ await this.appManager.setMainViewSceneIndex(index);
536
+ return true;
537
+ } else {
538
+ return false;
539
+ }
540
+ }
541
+
518
542
  public async addPage(params?: AddPageParams): Promise<void> {
519
543
  if (this.appManager) {
520
544
  const after = params?.after;
@@ -570,7 +594,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
570
594
  public setReadonly(readonly: boolean): void {
571
595
  this.readonly = readonly;
572
596
  this.boxManager?.setReadonly(readonly);
573
- emitter.emit("setReadonly", readonly);
597
+ internalEmitter.emit("setReadonly", readonly);
574
598
  }
575
599
 
576
600
  /**
@@ -633,6 +657,14 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
633
657
  this.boxManager?.setMinimized(minimized, false);
634
658
  }
635
659
 
660
+ public setFullscreen(fullscreen: boolean): void {
661
+ if (this._fullscreen !== fullscreen) {
662
+ this._fullscreen = fullscreen;
663
+ WindowManager.sizer?.classList.toggle("netless-window-manager-fullscreen", fullscreen);
664
+ callbacks.emit("fullscreenChange", fullscreen);
665
+ }
666
+ }
667
+
636
668
  public get mainView(): View {
637
669
  if (this.appManager) {
638
670
  return this.appManager.mainViewProxy.view;
@@ -734,6 +766,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
734
766
  }
735
767
  }
736
768
 
769
+ public get fullscreen(): boolean {
770
+ return Boolean(this._fullscreen);
771
+ }
772
+
737
773
  /**
738
774
  * 查询所有的 App
739
775
  */
@@ -815,6 +851,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
815
851
  this.cursorManager?.destroy();
816
852
  WindowManager.container = undefined;
817
853
  WindowManager.wrapper = undefined;
854
+ WindowManager.sizer = undefined;
818
855
  WindowManager.isCreated = false;
819
856
  if (WindowManager.playground) {
820
857
  WindowManager.playground.parentNode?.removeChild(WindowManager.playground);
@@ -932,7 +969,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
932
969
  }
933
970
  WindowManager.containerSizeRatio = ratio;
934
971
  this.containerSizeRatio = ratio;
935
- emitter.emit("containerSizeRatioUpdate", ratio);
972
+ internalEmitter.emit("containerSizeRatioUpdate", ratio);
936
973
  }
937
974
 
938
975
  private isDynamicPPT(scenes: SceneDefinition[]) {
package/src/style.css CHANGED
@@ -197,3 +197,11 @@
197
197
  .netless-iframe-brdige-hidden {
198
198
  display: none;
199
199
  }
200
+
201
+ .netless-window-manager-fullscreen .telebox-titlebar,
202
+ .netless-window-manager-fullscreen .telebox-max-titlebar-maximized,
203
+ .netless-window-manager-fullscreen .netless-app-slide-footer,
204
+ .netless-window-manager-fullscreen .telebox-footer-wrap,
205
+ .netless-window-manager-fullscreen .telebox-titlebar-wrap {
206
+ display: none;
207
+ }