@netless/window-manager 0.4.24 → 0.4.27-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 (46) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/__mocks__/white-web-sdk.ts +41 -0
  3. package/dist/App/AppContext.d.ts +2 -1
  4. package/dist/App/AppProxy.d.ts +7 -3
  5. package/dist/AppListener.d.ts +1 -0
  6. package/dist/AppManager.d.ts +2 -0
  7. package/dist/ContainerResizeObserver.d.ts +2 -1
  8. package/dist/InternalEmitter.d.ts +8 -2
  9. package/dist/Page/PageController.d.ts +5 -0
  10. package/dist/Page/index.d.ts +2 -0
  11. package/dist/Utils/Common.d.ts +2 -1
  12. package/dist/Utils/error.d.ts +3 -0
  13. package/dist/View/MainView.d.ts +4 -1
  14. package/dist/constants.d.ts +1 -0
  15. package/dist/index.cjs.js +12 -12
  16. package/dist/index.cjs.js.map +1 -1
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.es.js +263 -61
  19. package/dist/index.es.js.map +1 -1
  20. package/dist/index.umd.js +12 -12
  21. package/dist/index.umd.js.map +1 -1
  22. package/dist/typings.d.ts +1 -0
  23. package/docs/advanced.md +29 -4
  24. package/docs/api.md +17 -0
  25. package/docs/app-context.md +149 -100
  26. package/package.json +5 -9
  27. package/pnpm-lock.yaml +793 -2690
  28. package/src/App/AppContext.ts +20 -11
  29. package/src/App/AppProxy.ts +61 -5
  30. package/src/App/Storage/index.ts +14 -8
  31. package/src/AppListener.ts +22 -0
  32. package/src/AppManager.ts +57 -24
  33. package/src/ContainerResizeObserver.ts +12 -1
  34. package/src/InternalEmitter.ts +7 -2
  35. package/src/Page/PageController.ts +6 -0
  36. package/src/Page/index.ts +18 -0
  37. package/src/PageState.ts +2 -1
  38. package/src/ReconnectRefresher.ts +4 -1
  39. package/src/Utils/Common.ts +14 -2
  40. package/src/Utils/RoomHacker.ts +2 -2
  41. package/src/Utils/error.ts +4 -0
  42. package/src/View/MainView.ts +37 -8
  43. package/src/constants.ts +1 -0
  44. package/src/index.ts +26 -1
  45. package/src/typings.ts +1 -0
  46. package/vite.config.js +9 -1
package/src/constants.ts CHANGED
@@ -9,6 +9,7 @@ export enum Events {
9
9
  WindowCreated = "WindowCreated",
10
10
  SetMainViewScenePath = "SetMainViewScenePath",
11
11
  SetMainViewSceneIndex = "SetMainViewSceneIndex",
12
+ SetAppFocusIndex = "SetAppFocusIndex",
12
13
  SwitchViewsToFreedom = "SwitchViewsToFreedom",
13
14
  MoveCamera = "MoveCamera",
14
15
  MoveCameraToContain = "MoveCameraToContain",
package/src/index.ts CHANGED
@@ -11,7 +11,7 @@ import { emitter } 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";
14
- import { isEqual, isNull, isObject, omit } from "lodash";
14
+ import { isEqual, isNull, isObject, omit, isNumber } from "lodash";
15
15
  import { log } from "./Utils/log";
16
16
  import { PageStateImpl } from "./PageState";
17
17
  import { ReconnectRefresher } from "./ReconnectRefresher";
@@ -32,6 +32,7 @@ import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
32
32
  import {
33
33
  AppCreateError,
34
34
  AppManagerNotInitError,
35
+ BindContainerRoomPhaseInvalidError,
35
36
  InvalidScenePath,
36
37
  ParamsInvalidError,
37
38
  } from "./Utils/error";
@@ -319,6 +320,9 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
319
320
  }
320
321
 
321
322
  public bindContainer(container: HTMLElement) {
323
+ if (this.room.phase !== RoomPhase.Connected) {
324
+ throw new BindContainerRoomPhaseInvalidError();
325
+ }
322
326
  if (WindowManager.isCreated && WindowManager.container) {
323
327
  if (WindowManager.container.firstChild) {
324
328
  container.appendChild(WindowManager.container.firstChild);
@@ -533,6 +537,18 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
533
537
  }
534
538
  }
535
539
 
540
+ public async removePage(index: number): Promise<boolean> {
541
+ if (this.appManager) {
542
+ if (index < 0 || index >= this.pageState.length) {
543
+ console.warn(`[WindowManager]: index ${index} out of range`);
544
+ return false;
545
+ }
546
+ return this.appManager.removeSceneByIndex(index);;
547
+ } else {
548
+ return false;
549
+ }
550
+ }
551
+
536
552
  /**
537
553
  * 返回 mainView 的 ScenePath
538
554
  */
@@ -893,6 +909,15 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
893
909
  this.appManager?.refresher?.refresh();
894
910
  }
895
911
 
912
+ public setContainerSizeRatio(ratio: number) {
913
+ if (!isNumber(ratio)) {
914
+ throw new Error(`[WindowManager]: updateContainerSizeRatio error, ratio must be a number. but got ${ratio}`);
915
+ }
916
+ WindowManager.containerSizeRatio = ratio;
917
+ this.containerSizeRatio = ratio;
918
+ emitter.emit("containerSizeRatioUpdate", ratio);
919
+ }
920
+
896
921
  private isDynamicPPT(scenes: SceneDefinition[]) {
897
922
  const sceneSrc = scenes[0]?.ppt?.src;
898
923
  return sceneSrc?.startsWith("pptx://");
package/src/typings.ts CHANGED
@@ -80,3 +80,4 @@ export type { ReadonlyTeleBox, TeleBoxRect };
80
80
  export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room, Player };
81
81
  export type { Storage, StorageStateChangedEvent, StorageStateChangedListener } from "./App/Storage";
82
82
  export * from "./Page";
83
+ export * from "./Utils/error";
package/vite.config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { defineConfig } from "vite";
2
+ import { defineConfig } from 'vitest/config'
3
3
  import { svelte } from "@sveltejs/vite-plugin-svelte";
4
4
  import { dependencies, peerDependencies, version, devDependencies } from "./package.json"
5
5
  import { omit } from "lodash";
@@ -8,6 +8,14 @@ export default defineConfig(({ mode }) => {
8
8
  const isProd = mode === "production";
9
9
 
10
10
  return {
11
+ test: {
12
+ environment: "jsdom",
13
+ deps: {
14
+ inline: [
15
+ "@juggle/resize-observer"
16
+ ]
17
+ }
18
+ },
11
19
  define: {
12
20
  __APP_VERSION__: JSON.stringify(version),
13
21
  __APP_DEPENDENCIES__: JSON.stringify({