@netless/window-manager 0.4.60 → 0.4.61

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/index.ts CHANGED
@@ -55,6 +55,8 @@ import type { PublicEvent } from "./callback";
55
55
  import type Emittery from "emittery";
56
56
  import type { PageController, AddPageParams, PageState } from "./Page";
57
57
  import { boxEmitter } from "./BoxEmitter";
58
+ import { IframeBridge } from "./View/IframeBridge";
59
+ export * from "./View/IframeBridge";
58
60
 
59
61
  export type WindowMangerAttributes = {
60
62
  modelValue?: string;
@@ -364,9 +366,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
364
366
  /**
365
367
  * 注册插件
366
368
  */
367
- public static register<AppOptions = any, SetupResult = any, Attributes = any>(
368
- params: RegisterParams<AppOptions, SetupResult, Attributes>
369
- ): Promise<void> {
369
+ public static register(params: RegisterParams<any, any, any>): Promise<void> {
370
370
  return appRegister.register(params);
371
371
  }
372
372
 
@@ -820,6 +820,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
820
820
  WindowManager.playground.parentNode?.removeChild(WindowManager.playground);
821
821
  }
822
822
  WindowManager.params = undefined;
823
+ this._iframeBridge?.destroy();
824
+ this._iframeBridge = undefined;
823
825
  log("Destroyed");
824
826
  }
825
827
 
@@ -925,8 +927,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
925
927
  }
926
928
 
927
929
  public setContainerSizeRatio(ratio: number) {
928
- if (!isNumber(ratio)) {
929
- throw new Error(`[WindowManager]: updateContainerSizeRatio error, ratio must be a number. but got ${ratio}`);
930
+ if (!isNumber(ratio) || !(ratio > 0)) {
931
+ throw new Error(`[WindowManager]: updateContainerSizeRatio error, ratio must be a positive number. but got ${ratio}`);
930
932
  }
931
933
  WindowManager.containerSizeRatio = ratio;
932
934
  this.containerSizeRatio = ratio;
@@ -958,7 +960,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
958
960
  if (!this.attributes[Fields.Registered]) {
959
961
  this.safeSetAttributes({ [Fields.Registered]: {} });
960
962
  }
963
+ if (!this.attributes[Fields.IframeBridge]) {
964
+ this.safeSetAttributes({ [Fields.IframeBridge]: {} });
965
+ }
966
+ }
967
+ }
968
+
969
+ private _iframeBridge?: IframeBridge;
970
+ public getIframeBridge() {
971
+ if (!this.appManager) {
972
+ throw new Error("[WindowManager]: should call getIframeBridge() after await mount()");
961
973
  }
974
+ this._iframeBridge || (this._iframeBridge = new IframeBridge(this, this.appManager));
975
+ return this._iframeBridge;
962
976
  }
963
977
  }
964
978
 
package/src/style.css CHANGED
@@ -193,3 +193,7 @@
193
193
  right: 10px;
194
194
  bottom: 15px;
195
195
  }
196
+
197
+ .netless-iframe-brdige-hidden {
198
+ display: none;
199
+ }
package/src/typings.ts CHANGED
@@ -14,7 +14,7 @@ import type { AppContext } from "./App";
14
14
  import type { ReadonlyTeleBox, TeleBoxRect } from "@netless/telebox-insider";
15
15
  import type { PageState } from "./Page";
16
16
 
17
- export interface NetlessApp<Attributes = any, MagixEventPayloads = any, AppOptions = any, SetupResult = any> {
17
+ export interface NetlessApp<Attributes extends {} = any, MagixEventPayloads = any, AppOptions = any, SetupResult = any> {
18
18
  kind: string;
19
19
  config?: {
20
20
  /** Box width relative to whiteboard. 0~1. Default 0.5. */
@@ -65,7 +65,7 @@ export type RegisterEvents<SetupResult = any> = {
65
65
  focus: RegisterEventData;
66
66
  };
67
67
 
68
- export type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any> = {
68
+ export type RegisterParams<AppOptions = any, SetupResult = any, Attributes extends {} = any> = {
69
69
  kind: string;
70
70
  src:
71
71
  | NetlessApp<Attributes, SetupResult>