@netless/window-manager 0.3.17-canary.1 → 0.4.0-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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ ## 0.3.18
2
+
3
+ 1. 修复最小化时刷新页面 box 位置错误的问题
4
+
5
+ ## 0.3.17
6
+
7
+ 1. 同步 box 的 `z-index` 以保持顺序
8
+ 2. 更新 `telebox-insider` 使用新的 `focus` 和 `blur` api 以保持状态的正确
9
+ 3. 更新 `@netless/app-docs-viewer@0.1.26` 减少滚动同步频率
10
+ 4. 修复最小化时没有清理 `focus` 状态的问题
package/README.md CHANGED
@@ -2,54 +2,14 @@
2
2
 
3
3
  - 目录
4
4
  - [references](docs/api.md)
5
+ - [从白板迁移](docs/migrate.md)
5
6
  ## MainView
6
7
 
7
8
  `MainView` 也就是主白板, 是垫在所有窗口下面的主白板
8
9
 
9
10
  因为多窗口的原因,所以抽象出来一个主白板, 并且把以前部分对 `room` 的操作, 迁移到对 `mainView` 操作
10
11
 
11
- ### 注意事项
12
-
13
- 多窗口模式必须开启白板的 `useMultiViews` 和 `useMobXState` 选项
14
-
15
- 会造成原本以下 `room` 上的一些方法和 `state` 失效
16
-
17
- `方法`
18
-
19
- - `room.bindHtmlElement()` 用 `WindowManager.mount()` 代替
20
- - `room.scalePptToFit()` 暂无代替,不再推荐调用 `scalePptToFit`
21
- - `room.setScenePath()` 用 `manager.setMainViewScenePath()` 代替
22
- - `room.setSceneIndex()` 用 `manager.setMainViewSceneIndex()` 代替
23
-
24
- > 为了方便使用 `manager` 替换了 `room` 上的一些方法可以直接对 `mainView` 生效
25
-
26
- - `room.disableCameraTransform`
27
- - `room.moveCamera`
28
- - `room.moveCameraToContain`
29
- - `room.convertToPointInWorld`
30
- - `room.setCameraBound`
31
-
32
- `camera`
33
-
34
- - `room.state.cameraState` 用 `manager.mainView.camera` 和 `manager.mainView.size` 代替
35
-
36
- 想要监听主白板 `camera` 的变化, 请使用如下方式代替
37
-
38
- ```javascript
39
- manager.mainView.callbacks.on("onCameraUpdated", camera => {
40
- console.log(camera);
41
- });
42
- ```
43
-
44
- 监听主白板 `size` 变化
45
-
46
- ```javascript
47
- manager.mainView.callbacks.on("onSizeUpdated", size => {
48
- console.log(size);
49
- });
50
- ```
51
-
52
- ### 接入
12
+ ### 快速开始
53
13
 
54
14
  ```javascript
55
15
  import { WhiteWebSdk } from "white-web-sdk";
@@ -58,7 +18,7 @@ import "@netless/window-manager/dist/style.css";
58
18
 
59
19
  const sdk = new WhiteWebSdk({
60
20
  appIdentifier: "appIdentifier",
61
- useMobXState: true
21
+ useMobXState: true // 请确保打开这个选项
62
22
  });
63
23
 
64
24
  sdk.joinRoom({
@@ -66,6 +26,7 @@ sdk.joinRoom({
66
26
  roomToken: "room token",
67
27
  invisiblePlugins: [WindowManager],
68
28
  useMultiViews: true, // 多窗口必须用开启 useMultiViews
29
+ disableMagixEventDispatchLimit: true, // 请确保打开这个选项
69
30
  }).then(async room => {
70
31
  const manager = await WindowManager.mount(
71
32
  room,
@@ -2,11 +2,13 @@ import { autorun, listenDisposed, listenUpdated, reaction, unlistenDisposed, unl
2
2
  import type { Room, SceneDefinition, View } from "white-web-sdk";
3
3
  import type { ReadonlyTeleBox } from "@netless/telebox-insider";
4
4
  import type Emittery from "emittery";
5
+ import type { BoxManager } from "./BoxManager";
5
6
  import type { AppEmitterEvent } from "./index";
6
7
  import type { AppManager } from "./AppManager";
7
8
  import type { AppProxy } from "./AppProxy";
8
9
  export declare class AppContext<TAttrs extends Record<string, any>, AppOptions = any> {
9
10
  private manager;
11
+ private boxManager;
10
12
  appId: string;
11
13
  private appProxy;
12
14
  private appOptions?;
@@ -22,11 +24,10 @@ export declare class AppContext<TAttrs extends Record<string, any>, AppOptions =
22
24
  listenDisposed: typeof listenDisposed;
23
25
  unlistenDisposed: typeof unlistenDisposed;
24
26
  };
25
- private boxManager;
26
27
  private store;
27
28
  readonly isAddApp: boolean;
28
29
  readonly isReplay: boolean;
29
- constructor(manager: AppManager, appId: string, appProxy: AppProxy, appOptions?: AppOptions | (() => AppOptions) | undefined);
30
+ constructor(manager: AppManager, boxManager: BoxManager, appId: string, appProxy: AppProxy, appOptions?: AppOptions | (() => AppOptions) | undefined);
30
31
  getDisplayer(): import("white-web-sdk").Displayer<import("white-web-sdk").DisplayerCallbacks>;
31
32
  getAttributes(): TAttrs | undefined;
32
33
  getScenes(): SceneDefinition[] | undefined;
@@ -2,8 +2,8 @@ import type { AppManager } from "./AppManager";
2
2
  export declare class AppListeners {
3
3
  private manager;
4
4
  private displayer;
5
- private boxManager;
6
5
  constructor(manager: AppManager);
6
+ private get boxManager();
7
7
  addListeners(): void;
8
8
  removeListeners(): void;
9
9
  private mainMagixEventListener;
@@ -1,28 +1,27 @@
1
1
  import { AppStatus, Events } from "./constants";
2
2
  import { AppProxy } from "./AppProxy";
3
- import { AttributesDelegate } from "./AttributesDelegate";
4
- import { BoxManager } from "./BoxManager";
3
+ import { WindowManager } from "./index";
5
4
  import { CameraStore } from "./Utils/CameraStore";
6
5
  import { MainViewProxy } from "./MainView";
7
6
  import { ReconnectRefresher } from "./ReconnectRefresher";
8
7
  import { ViewManager } from "./ViewManager";
8
+ import type { BoxManager } from "./BoxManager";
9
9
  import type { Displayer, Room } from "white-web-sdk";
10
- import type { CreateTeleBoxManagerConfig } from "./BoxManager";
11
- import type { AddAppParams, WindowManager, TeleBoxRect } from "./index";
10
+ import type { AddAppParams, TeleBoxRect } from "./index";
12
11
  export declare class AppManager {
13
12
  windowManger: WindowManager;
14
13
  displayer: Displayer;
15
- boxManager: BoxManager;
16
14
  cameraStore: CameraStore;
17
15
  viewManager: ViewManager;
18
16
  appProxies: Map<string, AppProxy>;
19
17
  appStatus: Map<string, AppStatus>;
20
- store: AttributesDelegate;
18
+ store: import("./AttributesDelegate").AttributesDelegate;
21
19
  mainViewProxy: MainViewProxy;
22
20
  refresher?: ReconnectRefresher;
23
21
  isReplay: boolean;
24
22
  private appListeners;
25
- constructor(windowManger: WindowManager, options: CreateTeleBoxManagerConfig);
23
+ boxManager?: BoxManager;
24
+ constructor(windowManger: WindowManager);
26
25
  private onCreated;
27
26
  /**
28
27
  * 插件更新 attributes 时的回调
@@ -31,6 +30,10 @@ export declare class AppManager {
31
30
  * @memberof WindowManager
32
31
  */
33
32
  attributesUpdateCallback(apps: any): Promise<void>;
33
+ refresh(): void;
34
+ setBoxManager(boxManager: BoxManager): void;
35
+ resetMaximized(): void;
36
+ resetMinimized(): void;
34
37
  private onAppDelete;
35
38
  bindMainView(divElement: HTMLDivElement, disableCameraTransform: boolean): void;
36
39
  addApp(params: AddAppParams, isDynamicPPT: boolean): Promise<string | undefined>;
@@ -19,6 +19,9 @@ export declare class AppProxy extends Base {
19
19
  private kind;
20
20
  isAddApp: boolean;
21
21
  private status;
22
+ private stateKey;
23
+ private setupResult?;
24
+ private appContext?;
22
25
  constructor(params: BaseInsertParams, manager: AppManager, appId: string, isAddApp: boolean);
23
26
  private initScenes;
24
27
  get view(): View | undefined;
@@ -1,7 +1,6 @@
1
1
  import { AppAttributes } from "./constants";
2
2
  import type { AddAppParams, AppSyncAttributes } from "./index";
3
- import type { Camera, Size } from "white-web-sdk";
4
- import type { AppManager } from "./AppManager";
3
+ import type { Camera, Size, View } from "white-web-sdk";
5
4
  import type { Cursor } from "./Cursor/Cursor";
6
5
  export declare enum Fields {
7
6
  Apps = "apps",
@@ -26,14 +25,22 @@ export declare type Position = {
26
25
  id?: string;
27
26
  };
28
27
  export declare type PositionType = "main" | "app";
28
+ export declare type StoreContext = {
29
+ getAttributes: () => any;
30
+ safeUpdateAttributes: (keys: string[], value: any) => void;
31
+ safeSetAttributes: (attributes: any) => void;
32
+ };
29
33
  export declare class AttributesDelegate {
30
- private manager;
31
- constructor(manager: AppManager);
34
+ private context;
35
+ constructor(context: StoreContext);
36
+ setContext(context: StoreContext): void;
37
+ get attributes(): any;
32
38
  apps(): Apps;
33
39
  get focus(): string | undefined;
34
40
  getAppAttributes(id: string): AppSyncAttributes;
35
41
  getAppState(id: string): any;
36
- getMaximized(): boolean | undefined;
42
+ getMaximized(): any;
43
+ getMinimized(): any;
37
44
  setupAppAttributes(params: AddAppParams, id: string, isDynamicPPT: boolean): void;
38
45
  updateAppState(appId: string, stateName: AppAttributes, state: any): void;
39
46
  cleanAppAttributes(id: string): void;
@@ -42,23 +49,23 @@ export declare class AttributesDelegate {
42
49
  getAppScenePath(id: string): any;
43
50
  getMainViewScenePath(): any;
44
51
  getMainViewSceneIndex(): any;
45
- getBoxState(): import("@netless/telebox-insider").TELE_BOX_STATE;
52
+ getBoxState(): any;
46
53
  setMainViewScenePath(scenePath: string): void;
47
54
  setMainViewSceneIndex(index: number): void;
48
55
  getMainViewCamera(): MainViewCamera;
49
56
  getMainViewSize(): MainViewSize;
50
- setMainViewCamera(camera: Camera & {
57
+ setMainViewCamera(camera: (Camera & {
51
58
  id: string;
52
- } | undefined): void;
53
- setMainViewSize(size: Size & {
59
+ }) | undefined): void;
60
+ setMainViewSize(size: (Size & {
54
61
  id: string;
55
- } | undefined): void;
62
+ }) | undefined): void;
56
63
  setAppFocus(appId: string, focus: boolean): void;
57
64
  updateCursor(uid: string, position: Position): void;
58
65
  updateCursorState(uid: string, cursorState: string | undefined): void;
59
66
  getCursorState(uid: string): any;
60
67
  cleanCursor(uid: string): void;
61
- setMainViewFocusPath(): void;
68
+ setMainViewFocusPath(mainView: View): void;
62
69
  }
63
70
  export declare type MainViewSize = {
64
71
  id: string;
@@ -74,3 +81,4 @@ export declare type MainViewCamera = {
74
81
  export declare type Cursors = {
75
82
  [key: string]: Cursor;
76
83
  };
84
+ export declare const store: AttributesDelegate;
@@ -1,8 +1,7 @@
1
1
  import type { AppManager } from "../AppManager";
2
- import { AttributesDelegate } from "../AttributesDelegate";
3
2
  export declare class Base {
4
3
  manager: AppManager;
5
- store: AttributesDelegate;
4
+ store: import("../AttributesDelegate").AttributesDelegate;
6
5
  context: import("./Context").Context;
7
6
  constructor(manager: AppManager);
8
7
  }
@@ -1,8 +1,9 @@
1
+ import { AppAttributes } from "./constants";
1
2
  import { TELE_BOX_STATE, TeleBoxManager } from "@netless/telebox-insider";
2
- import type { AddAppOptions, AppInitState } from "./index";
3
- import type { TeleBoxManagerUpdateConfig, ReadonlyTeleBox, TeleBoxColorScheme } from "@netless/telebox-insider";
3
+ import { WindowManager } from "./index";
4
+ import type { AddAppOptions, AppInitState, EmitterType, CallbacksType } from "./index";
5
+ import type { TeleBoxManagerUpdateConfig, ReadonlyTeleBox, TeleBoxColorScheme, TeleBoxRect } from "@netless/telebox-insider";
4
6
  import type Emittery from "emittery";
5
- import type { AppManager } from "./AppManager";
6
7
  import type { NetlessApp } from "./typings";
7
8
  import type { View } from "white-web-sdk";
8
9
  export { TELE_BOX_STATE };
@@ -39,20 +40,34 @@ export declare type CreateTeleBoxManagerConfig = {
39
40
  collectorStyles?: Partial<CSSStyleDeclaration>;
40
41
  prefersColorScheme?: TeleBoxColorScheme;
41
42
  };
43
+ export declare type BoxManagerContext = {
44
+ safeSetAttributes: (attributes: any) => void;
45
+ getMainView: () => View;
46
+ updateAppState: (appId: string, field: AppAttributes, value: any) => void;
47
+ emitter: EmitterType;
48
+ callbacks: CallbacksType;
49
+ canOperate: () => boolean;
50
+ notifyContainerRectUpdate: (rect: TeleBoxRect) => void;
51
+ cleanFocus: () => void;
52
+ };
53
+ export declare const createBoxManager: (manager: WindowManager, callbacks: CallbacksType, emitter: EmitterType, options: CreateTeleBoxManagerConfig) => BoxManager;
42
54
  export declare class BoxManager {
43
- private manager;
55
+ private context;
56
+ private createTeleBoxManagerConfig?;
44
57
  teleBoxManager: TeleBoxManager;
45
- appBoxMap: Map<string, string>;
46
- private mainView;
47
- constructor(manager: AppManager, createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig);
58
+ constructor(context: BoxManagerContext, createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig | undefined);
59
+ private get mainView();
60
+ private get canOperate();
48
61
  get boxState(): "normal" | "minimized" | "maximized";
49
62
  get maximized(): boolean;
50
63
  get minimized(): boolean;
51
64
  get darkMode(): boolean;
52
65
  get prefersColorScheme(): TeleBoxColorScheme;
66
+ get boxSize(): number;
53
67
  createBox(params: CreateBoxParams): void;
54
68
  setBoxInitState(appId: string): void;
55
69
  setupBoxManager(createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig): TeleBoxManager;
70
+ setCollectorContainer(container: HTMLElement): void;
56
71
  getBox(appId: string): ReadonlyTeleBox | undefined;
57
72
  closeBox(appId: string, skipUpdate?: boolean): ReadonlyTeleBox | undefined;
58
73
  boxIsFocus(appId: string): boolean | undefined;
@@ -72,5 +87,6 @@ export declare class BoxManager {
72
87
  focusTopBox(): void;
73
88
  setReadonly(readonly: boolean): void;
74
89
  setPrefersColorScheme(colorScheme: TeleBoxColorScheme): void;
90
+ setZIndex(id: string, zIndex: number, skipUpdate?: boolean): void;
75
91
  destroy(): void;
76
92
  }
@@ -20,12 +20,13 @@ export declare class CursorManager extends Base {
20
20
  roomMembers?: readonly RoomMember[];
21
21
  private mainViewElement?;
22
22
  constructor(appManager: AppManager);
23
+ setupWrapper(wrapper: HTMLElement): void;
23
24
  setMainViewDivElement(div: HTMLDivElement): void;
24
25
  private startReaction;
25
26
  private getUids;
26
27
  private handleRoomMembersChange;
27
28
  get cursors(): any;
28
- get boxState(): import("@netless/telebox-insider").TELE_BOX_STATE;
29
+ get boxState(): any;
29
30
  get focusView(): View | undefined;
30
31
  private mouseMoveListener;
31
32
  private touchMoveListener;
@@ -1,5 +1,5 @@
1
1
  import type { Room } from "white-web-sdk";
2
- import type { AppManager } from './AppManager';
2
+ import type { AppManager } from "./AppManager";
3
3
  export declare class ReconnectRefresher {
4
4
  private manager;
5
5
  private phase?;
@@ -12,5 +12,6 @@ export declare class ReconnectRefresher {
12
12
  private releaseDisposers;
13
13
  add(id: string, func: any): void;
14
14
  remove(id: string): void;
15
+ hasReactor(id: string): boolean;
15
16
  destroy(): void;
16
17
  }
@@ -1,3 +1,3 @@
1
+ import type { WindowManager } from '../index';
1
2
  import type { Room } from "white-web-sdk";
2
- import type { AppManager } from "../AppManager";
3
- export declare const replaceRoomFunction: (room: Room, manager: AppManager) => void;
3
+ export declare const replaceRoomFunction: (room: Room, manager: WindowManager) => void;
@@ -19,3 +19,6 @@ export declare class BoxNotCreatedError extends Error {
19
19
  export declare class InvalidScenePath extends Error {
20
20
  message: string;
21
21
  }
22
+ export declare class BoxManagerNotFoundError extends Error {
23
+ message: string;
24
+ }
package/dist/index.d.ts CHANGED
@@ -49,6 +49,7 @@ export declare type AppSyncAttributes = {
49
49
  state?: any;
50
50
  isDynamicPPT?: boolean;
51
51
  fullPath?: string;
52
+ createdAt?: number;
52
53
  };
53
54
  export declare type AppInitState = {
54
55
  id: string;
@@ -91,7 +92,8 @@ export declare type EmitterEvent = {
91
92
  boxStateChange: string;
92
93
  playgroundSizeChange: DOMRect;
93
94
  };
94
- export declare const emitter: Emittery<EmitterEvent>;
95
+ export declare type EmitterType = Emittery<EmitterEvent>;
96
+ export declare const emitter: EmitterType;
95
97
  export declare type PublicEvent = {
96
98
  mainViewModeChange: ViewVisionMode;
97
99
  boxStateChange: `${TELE_BOX_STATE}`;
@@ -101,7 +103,7 @@ export declare type PublicEvent = {
101
103
  };
102
104
  export declare type MountParams = {
103
105
  room: Room;
104
- container: HTMLElement;
106
+ container?: HTMLElement;
105
107
  /** 白板高宽比例, 默认为 9 / 16 */
106
108
  containerSizeRatio?: number;
107
109
  /** 显示 PS 透明背景,默认 true */
@@ -114,7 +116,8 @@ export declare type MountParams = {
114
116
  disableCameraTransform?: boolean;
115
117
  prefersColorScheme?: TeleBoxColorScheme;
116
118
  };
117
- export declare const callbacks: Emittery<PublicEvent>;
119
+ export declare type CallbacksType = Emittery<PublicEvent>;
120
+ export declare const callbacks: CallbacksType;
118
121
  export declare class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
119
122
  static kind: string;
120
123
  static displayer: Displayer;
@@ -132,24 +135,19 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
132
135
  cursorManager?: CursorManager;
133
136
  viewMode: ViewMode;
134
137
  isReplay: boolean;
138
+ private boxManager?;
139
+ private static params?;
135
140
  constructor(context: InvisiblePluginContext);
136
- /**
137
- * 挂载 WindowManager
138
- * @deprecated
139
- */
140
- static mount(room: Room, container: HTMLElement, collectorContainer?: HTMLElement, options?: {
141
- chessboard: boolean;
142
- containerSizeRatio: number;
143
- collectorStyles?: Partial<CSSStyleDeclaration>;
144
- debug?: boolean;
145
- overwriteStyles?: string;
146
- }): Promise<WindowManager>;
147
141
  static mount(params: MountParams): Promise<WindowManager>;
148
142
  private static initManager;
143
+ private static initContainer;
144
+ bindContainer(container: HTMLElement, collectorContainer?: HTMLElement): void;
149
145
  /**
150
146
  * 注册插件
151
147
  */
152
148
  static register<AppOptions = any, SetupResult = any, Attributes = any>(params: RegisterParams<AppOptions, SetupResult, Attributes>): Promise<void>;
149
+ static setContainer(container: HTMLElement): void;
150
+ static setCollectorContainer(container: HTMLElement): void;
153
151
  /**
154
152
  * 创建一个 app 至白板
155
153
  */
@@ -191,9 +189,9 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
191
189
  get camera(): Camera;
192
190
  get cameraState(): CameraState;
193
191
  get apps(): Apps | undefined;
194
- get boxState(): TeleBoxState;
192
+ get boxState(): TeleBoxState | undefined;
195
193
  get darkMode(): boolean;
196
- get prefersColorScheme(): TeleBoxColorScheme;
194
+ get prefersColorScheme(): TeleBoxColorScheme | undefined;
197
195
  /**
198
196
  * 查询所有的 App
199
197
  */