@netless/window-manager 0.4.7 → 0.4.9-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.
Files changed (44) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +1 -0
  3. package/dist/AppContext.d.ts +4 -4
  4. package/dist/AppManager.d.ts +12 -9
  5. package/dist/BoxManager.d.ts +4 -3
  6. package/dist/ContainerResizeObserver.d.ts +1 -1
  7. package/dist/Helper.d.ts +2 -0
  8. package/dist/InternalEmitter.d.ts +41 -0
  9. package/dist/ReconnectRefresher.d.ts +1 -1
  10. package/dist/RedoUndo.d.ts +18 -0
  11. package/dist/Utils/AppCreateQueue.d.ts +2 -0
  12. package/dist/Utils/Common.d.ts +1 -1
  13. package/dist/View/MainView.d.ts +1 -0
  14. package/dist/callback.d.ts +21 -0
  15. package/dist/index.d.ts +5 -52
  16. package/dist/index.es.js +5 -5
  17. package/dist/index.es.js.map +1 -1
  18. package/dist/index.umd.js +5 -5
  19. package/dist/index.umd.js.map +1 -1
  20. package/dist/style.css +1 -1
  21. package/docs/advanced.md +13 -0
  22. package/docs/api.md +15 -1
  23. package/docs/develop-app.md +50 -0
  24. package/package.json +3 -3
  25. package/src/AppContext.ts +51 -33
  26. package/src/AppListener.ts +2 -1
  27. package/src/AppManager.ts +90 -82
  28. package/src/AppProxy.ts +8 -4
  29. package/src/BoxManager.ts +7 -13
  30. package/src/ContainerResizeObserver.ts +1 -1
  31. package/src/Cursor/Cursor.ts +2 -1
  32. package/src/Cursor/index.ts +4 -2
  33. package/src/Helper.ts +6 -0
  34. package/src/InternalEmitter.ts +27 -0
  35. package/src/ReconnectRefresher.ts +1 -1
  36. package/src/RedoUndo.ts +88 -0
  37. package/src/Register/index.ts +1 -0
  38. package/src/Register/loader.ts +1 -1
  39. package/src/Utils/AppCreateQueue.ts +10 -0
  40. package/src/Utils/Common.ts +2 -2
  41. package/src/Utils/RoomHacker.ts +3 -3
  42. package/src/View/MainView.ts +13 -1
  43. package/src/callback.ts +23 -0
  44. package/src/index.ts +23 -57
@@ -0,0 +1,23 @@
1
+ import Emittery from "emittery";
2
+ import type { TeleBoxColorScheme, TELE_BOX_STATE } from "@netless/telebox-insider";
3
+ import type { CameraState, ViewVisionMode } from "white-web-sdk";
4
+ import type { LoadAppEvent } from "./Register";
5
+
6
+ export type PublicEvent = {
7
+ mainViewModeChange: ViewVisionMode;
8
+ boxStateChange: `${TELE_BOX_STATE}`;
9
+ darkModeChange: boolean;
10
+ prefersColorSchemeChange: TeleBoxColorScheme;
11
+ cameraStateChange: CameraState;
12
+ mainViewScenePathChange: string;
13
+ mainViewSceneIndexChange: number;
14
+ focusedChange: string | undefined;
15
+ mainViewScenesLengthChange: number;
16
+ canRedoStepsChange: number;
17
+ canUndoStepsChange: number;
18
+ loadApp: LoadAppEvent;
19
+ ready: undefined; // 所有 APP 创建完毕时触发
20
+ };
21
+
22
+ export type CallbacksType = Emittery<PublicEvent>;
23
+ export const callbacks: CallbacksType = new Emittery();
package/src/index.ts CHANGED
@@ -1,12 +1,13 @@
1
- import Emittery from "emittery";
2
1
  import pRetry from "p-retry";
3
2
  import { AppManager } from "./AppManager";
4
3
  import { appRegister } from "./Register";
4
+ import { callbacks } from "./callback";
5
5
  import { checkVersion, setupWrapper } from "./Helper";
6
6
  import { ContainerResizeObserver } from "./ContainerResizeObserver";
7
7
  import { createBoxManager } from "./BoxManager";
8
8
  import { CursorManager } from "./Cursor";
9
9
  import { DEFAULT_CONTAINER_RATIO, Events, ROOT_DIR } from "./constants";
10
+ import { emitter } from "./InternalEmitter";
10
11
  import { Fields } from "./AttributesDelegate";
11
12
  import { initDb } from "./Register/storage";
12
13
  import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
@@ -18,7 +19,6 @@ import { setupBuiltin } from "./BuiltinApps";
18
19
  import "video.js/dist/video-js.css";
19
20
  import "./style.css";
20
21
  import "@netless/telebox-insider/dist/style.css";
21
- import type { LoadAppEvent } from "./Register";
22
22
  import {
23
23
  addEmitterOnceListener,
24
24
  ensureValidScenePath,
@@ -45,15 +45,17 @@ import type {
45
45
  CameraBound,
46
46
  Point,
47
47
  Rectangle,
48
- ViewVisionMode,
49
48
  CameraState,
50
49
  Player,
51
50
  ImageInformation,
51
+ SceneState,
52
52
  } from "white-web-sdk";
53
53
  import type { AppListeners } from "./AppListener";
54
54
  import type { NetlessApp, RegisterParams } from "./typings";
55
55
  import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
56
56
  import type { AppProxy } from "./AppProxy";
57
+ import type { PublicEvent } from "./Callback";
58
+ import type Emittery from "emittery";
57
59
 
58
60
  export type WindowMangerAttributes = {
59
61
  modelValue?: string;
@@ -122,42 +124,6 @@ export type AppInitState = {
122
124
 
123
125
  export type CursorMovePayload = { uid: string; state?: "leave"; position: Position };
124
126
 
125
- export type EmitterEvent = {
126
- onCreated: undefined;
127
- InitReplay: AppInitState;
128
- move: { appId: string; x: number; y: number };
129
- focus: { appId: string };
130
- close: { appId: string };
131
- resize: { appId: string; width: number; height: number; x?: number; y?: number };
132
- error: Error;
133
- seek: number;
134
- mainViewMounted: undefined;
135
- observerIdChange: number;
136
- boxStateChange: string;
137
- playgroundSizeChange: DOMRect;
138
- onReconnected: void;
139
- removeScenes: string;
140
- cursorMove: CursorMovePayload;
141
- };
142
-
143
- export type EmitterType = Emittery<EmitterEvent>;
144
- export const emitter: EmitterType = new Emittery();
145
-
146
- export type PublicEvent = {
147
- mainViewModeChange: ViewVisionMode;
148
- boxStateChange: `${TELE_BOX_STATE}`;
149
- darkModeChange: boolean;
150
- prefersColorSchemeChange: TeleBoxColorScheme;
151
- cameraStateChange: CameraState;
152
- mainViewScenePathChange: string;
153
- mainViewSceneIndexChange: number;
154
- focusedChange: string | undefined;
155
- mainViewScenesLengthChange: number;
156
- canRedoStepsChange: number;
157
- canUndoStepsChange: number;
158
- loadApp: LoadAppEvent;
159
- };
160
-
161
127
  export type MountParams = {
162
128
  room: Room | Player;
163
129
  container?: HTMLElement;
@@ -174,15 +140,12 @@ export type MountParams = {
174
140
  prefersColorScheme?: TeleBoxColorScheme;
175
141
  };
176
142
 
177
- export type CallbacksType = Emittery<PublicEvent>;
178
- export const callbacks: CallbacksType = new Emittery();
179
-
180
143
  export const reconnectRefresher = new ReconnectRefresher({ emitter });
181
144
 
182
145
  export type AddPageParams = {
183
146
  after?: boolean;
184
147
  scene?: SceneDefinition;
185
- }
148
+ };
186
149
 
187
150
  export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
188
151
  public static kind = "WindowManager";
@@ -347,6 +310,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
347
310
  return mainViewElement;
348
311
  }
349
312
 
313
+ public static get registered() {
314
+ return appRegister.registered;
315
+ }
316
+
350
317
  public bindContainer(container: HTMLElement) {
351
318
  if (WindowManager.isCreated && WindowManager.container) {
352
319
  if (WindowManager.container.firstChild) {
@@ -374,7 +341,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
374
341
  }
375
342
  }
376
343
  }
377
- this.boxManager?.updateManagerRect();
344
+ emitter.emit("updateManagerRect");
378
345
  this.appManager?.refresh();
379
346
  this.appManager?.resetMaximized();
380
347
  this.appManager?.resetMinimized();
@@ -492,10 +459,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
492
459
  public async nextPage(): Promise<boolean> {
493
460
  if (this.appManager) {
494
461
  const nextIndex = this.mainViewSceneIndex + 1;
495
- if (nextIndex >= this.mainViewScenesLength) {
462
+ if (nextIndex >= this.mainViewScenesLength) {
496
463
  console.warn(`[WindowManager]: current page is the last page`);
497
464
  return false;
498
- };
465
+ }
499
466
  await this.appManager.setMainViewSceneIndex(nextIndex);
500
467
  return true;
501
468
  } else {
@@ -509,7 +476,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
509
476
  if (prevIndex < 0) {
510
477
  console.warn(`[WindowManager]: current page is the first page`);
511
478
  return false;
512
- };
479
+ }
513
480
  await this.appManager.setMainViewSceneIndex(prevIndex);
514
481
  return true;
515
482
  } else {
@@ -687,20 +654,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
687
654
  }
688
655
 
689
656
  public get canRedoSteps(): number {
690
- const focused = this.focused;
691
- if (focused) {
692
- return this.appManager?.focusApp?.view?.canRedoSteps || 0;
693
- } else {
694
- return this.mainView.canRedoSteps;
695
- }
657
+ return this.focusedView?.canRedoSteps || 0;
696
658
  }
697
659
 
698
660
  public get canUndoSteps(): number {
699
- const focused = this.focused;
700
- if (focused) {
701
- return this.appManager?.focusApp?.view?.canUndoSteps || 0;
661
+ return this.focusedView?.canUndoSteps || 0;
662
+ }
663
+
664
+ public get sceneState(): SceneState {
665
+ if (this.appManager) {
666
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
667
+ return this.appManager.sceneState!;
702
668
  } else {
703
- return this.mainView.canUndoSteps;
669
+ throw new AppManagerNotInitError();
704
670
  }
705
671
  }
706
672