@netless/window-manager 0.4.0-canary.2 → 0.4.0-canary.20

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 (82) hide show
  1. package/.idea/inspectionProfiles/Project_Default.xml +7 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/.idea/window-manager.iml +12 -0
  5. package/.vscode/settings.json +1 -0
  6. package/CHANGELOG.md +29 -1
  7. package/README.md +1 -0
  8. package/dist/App/MagixEvent/index.d.ts +29 -0
  9. package/dist/App/Storage/StorageEvent.d.ts +8 -0
  10. package/dist/App/Storage/index.d.ts +39 -0
  11. package/dist/App/Storage/typings.d.ts +22 -0
  12. package/dist/App/Storage/utils.d.ts +5 -0
  13. package/dist/AppContext.d.ts +40 -16
  14. package/dist/AppListener.d.ts +1 -1
  15. package/dist/AppManager.d.ts +15 -11
  16. package/dist/AppProxy.d.ts +6 -5
  17. package/dist/AttributesDelegate.d.ts +2 -2
  18. package/dist/BoxManager.d.ts +6 -3
  19. package/dist/BuiltinApps.d.ts +5 -0
  20. package/dist/ContainerResizeObserver.d.ts +10 -0
  21. package/dist/Cursor/Cursor.d.ts +8 -11
  22. package/dist/Cursor/index.d.ts +5 -16
  23. package/dist/Helper.d.ts +6 -0
  24. package/dist/ReconnectRefresher.d.ts +0 -1
  25. package/dist/Register/storage.d.ts +5 -1
  26. package/dist/Utils/Common.d.ts +7 -2
  27. package/dist/Utils/Reactive.d.ts +1 -1
  28. package/dist/Utils/RoomHacker.d.ts +1 -1
  29. package/dist/{MainView.d.ts → View/MainView.d.ts} +5 -6
  30. package/dist/View/ViewManager.d.ts +13 -0
  31. package/dist/constants.d.ts +3 -7
  32. package/dist/index.d.ts +25 -10
  33. package/dist/index.es.js +41 -1
  34. package/dist/index.es.js.map +1 -1
  35. package/dist/index.umd.js +41 -1
  36. package/dist/index.umd.js.map +1 -1
  37. package/dist/style.css +1 -1
  38. package/dist/typings.d.ts +3 -2
  39. package/docs/api.md +36 -6
  40. package/docs/concept.md +9 -0
  41. package/package.json +7 -6
  42. package/src/App/MagixEvent/index.ts +68 -0
  43. package/src/App/Storage/StorageEvent.ts +21 -0
  44. package/src/App/Storage/index.ts +289 -0
  45. package/src/App/Storage/typings.ts +23 -0
  46. package/src/App/Storage/utils.ts +17 -0
  47. package/src/AppContext.ts +66 -24
  48. package/src/AppListener.ts +15 -14
  49. package/src/AppManager.ts +141 -63
  50. package/src/AppProxy.ts +50 -52
  51. package/src/AttributesDelegate.ts +2 -2
  52. package/src/BoxManager.ts +40 -24
  53. package/src/BuiltinApps.ts +23 -0
  54. package/src/ContainerResizeObserver.ts +62 -0
  55. package/src/Cursor/Cursor.ts +22 -36
  56. package/src/Cursor/index.ts +33 -139
  57. package/src/Helper.ts +30 -0
  58. package/src/ReconnectRefresher.ts +0 -5
  59. package/src/Register/index.ts +25 -16
  60. package/src/Register/loader.ts +1 -1
  61. package/src/Register/storage.ts +6 -1
  62. package/src/Utils/Common.ts +66 -13
  63. package/src/Utils/Reactive.ts +9 -3
  64. package/src/Utils/RoomHacker.ts +42 -13
  65. package/src/{MainView.ts → View/MainView.ts} +25 -36
  66. package/src/View/ViewManager.ts +52 -0
  67. package/src/constants.ts +3 -4
  68. package/src/index.ts +96 -72
  69. package/src/shim.d.ts +5 -0
  70. package/src/style.css +7 -1
  71. package/src/typings.ts +3 -2
  72. package/vite.config.js +8 -2
  73. package/dist/Base/Context.d.ts +0 -13
  74. package/dist/Base/index.d.ts +0 -7
  75. package/dist/Utils/CameraStore.d.ts +0 -15
  76. package/dist/ViewManager.d.ts +0 -29
  77. package/dist/sdk.d.ts +0 -14
  78. package/src/Base/Context.ts +0 -49
  79. package/src/Base/index.ts +0 -10
  80. package/src/Utils/CameraStore.ts +0 -72
  81. package/src/sdk.ts +0 -39
  82. package/src/viewManager.ts +0 -177
@@ -1,30 +1,27 @@
1
- import { AnimationMode, reaction, ViewVisionMode } from "white-web-sdk";
2
- import { Base } from "./Base";
3
- import { callbacks, emitter } from "./index";
1
+ import { AnimationMode, reaction } from "white-web-sdk";
2
+ import { callbacks, emitter } from "../index";
4
3
  import { createView } from "./ViewManager";
5
4
  import { debounce, isEmpty, isEqual } from "lodash";
6
- import { Fields } from "./AttributesDelegate";
7
- import { notifyMainViewModeChange, setViewFocusScenePath, setViewMode } from "./Utils/Common";
5
+ import { Fields } from "../AttributesDelegate";
6
+ import { setViewFocusScenePath } from "../Utils/Common";
8
7
  import { SideEffectManager } from "side-effect-manager";
9
8
  import type { Camera, Size, View } from "white-web-sdk";
10
- import type { AppManager } from "./AppManager";
9
+ import type { AppManager } from "../AppManager";
11
10
 
12
- export class MainViewProxy extends Base {
11
+ export class MainViewProxy {
13
12
  private scale?: number;
14
- private cameraStore = this.manager.cameraStore;
15
13
  private started = false;
16
14
  private mainViewIsAddListener = false;
17
15
  private mainView: View;
18
- private viewId = "mainView";
16
+ private store = this.manager.store;
19
17
 
20
18
  private sideEffectManager = new SideEffectManager();
21
19
 
22
- constructor(manager: AppManager) {
23
- super(manager);
20
+ constructor(private manager: AppManager) {
24
21
  this.mainView = this.createMainView();
25
22
  this.moveCameraSizeByAttributes();
26
- this.cameraStore.register(this.viewId, this.mainView);
27
23
  emitter.once("mainViewMounted").then(() => {
24
+ this.addMainViewListener();
28
25
  setTimeout(() => {
29
26
  this.start();
30
27
  if (!this.mainViewCamera || !this.mainViewSize) {
@@ -34,7 +31,7 @@ export class MainViewProxy extends Base {
34
31
  });
35
32
  const playgroundSizeChangeListener = () => {
36
33
  this.sizeChangeHandler(this.mainViewSize);
37
- }
34
+ };
38
35
  this.sideEffectManager.add(() => {
39
36
  emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
40
37
  return () => emitter.off("playgroundSizeChange", playgroundSizeChangeListener);
@@ -63,15 +60,15 @@ export class MainViewProxy extends Base {
63
60
  }
64
61
 
65
62
  public setCameraAndSize(): void {
66
- this.store.setMainViewCamera({ ...this.mainView.camera, id: this.context.uid });
67
- this.store.setMainViewSize({ ...this.mainView.size, id: this.context.uid });
63
+ this.store.setMainViewCamera({ ...this.mainView.camera, id: this.manager.uid });
64
+ this.store.setMainViewSize({ ...this.mainView.size, id: this.manager.uid });
68
65
  }
69
66
 
70
67
  private cameraReaction = () => {
71
68
  return reaction(
72
69
  () => this.mainViewCamera,
73
70
  camera => {
74
- if (camera && camera.id !== this.context.uid) {
71
+ if (camera && camera.id !== this.manager.uid) {
75
72
  this.moveCameraToContian(this.mainViewSize);
76
73
  this.moveCamera(camera);
77
74
  }
@@ -103,15 +100,19 @@ export class MainViewProxy extends Base {
103
100
  if (mainViewScenePath) {
104
101
  setViewFocusScenePath(mainView, mainViewScenePath);
105
102
  }
106
- if (!this.store.focus) {
107
- this.switchViewModeToWriter();
108
- }
109
103
  return mainView;
110
104
  }
111
105
 
106
+ public onReconnect(): void {
107
+ const mainViewScenePath = this.store.getMainViewScenePath();
108
+ if (mainViewScenePath) {
109
+ setViewFocusScenePath(this.view, mainViewScenePath);
110
+ }
111
+ }
112
+
112
113
  private onCameraUpdatedByDevice = (camera: Camera) => {
113
- this.store.setMainViewCamera({ ...camera, id: this.context.uid });
114
- if (!isEqual(this.mainViewSize, { ...this.mainView.size, id: this.context.uid })) {
114
+ this.store.setMainViewCamera({ ...camera, id: this.manager.uid });
115
+ if (!isEqual(this.mainViewSize, { ...this.mainView.size, id: this.manager.uid })) {
115
116
  this.setMainViewSize(this.view.size);
116
117
  }
117
118
  };
@@ -138,13 +139,12 @@ export class MainViewProxy extends Base {
138
139
 
139
140
  public async mainViewClickHandler(): Promise<void> {
140
141
  if (!this.manager.canOperate) return;
141
- if (this.view.mode === ViewVisionMode.Writable) return;
142
142
  this.store.cleanFocus();
143
- this.context.blurFocusBox();
143
+ this.manager.boxManager?.blurAllBox();
144
144
  }
145
145
 
146
146
  public setMainViewSize = debounce(size => {
147
- this.store.setMainViewSize({ ...size, id: this.context.uid });
147
+ this.store.setMainViewSize({ ...size, id: this.manager.uid });
148
148
  }, 50);
149
149
 
150
150
  private addCameraListener() {
@@ -163,17 +163,6 @@ export class MainViewProxy extends Base {
163
163
  callbacks.emit("cameraStateChange", this.cameraState);
164
164
  };
165
165
 
166
- public switchViewModeToWriter(): void {
167
- if (!this.manager.canOperate) return;
168
- if (this.view) {
169
- if (this.view.mode === ViewVisionMode.Writable) return;
170
- this.cameraStore.switchView(this.viewId, this.mainView, () => {
171
- notifyMainViewModeChange(callbacks, ViewVisionMode.Writable);
172
- setViewMode(this.view, ViewVisionMode.Writable);
173
- });
174
- }
175
- }
176
-
177
166
  public moveCameraToContian(size: Size): void {
178
167
  if (!isEmpty(size)) {
179
168
  this.view.moveCameraToContain({
@@ -202,6 +191,7 @@ export class MainViewProxy extends Base {
202
191
  }
203
192
 
204
193
  public stop() {
194
+ this.removeMainViewListener();
205
195
  this.removeCameraListener();
206
196
  this.manager.refresher?.remove(Fields.MainViewCamera);
207
197
  this.manager.refresher?.remove(Fields.MainViewSize);
@@ -210,7 +200,6 @@ export class MainViewProxy extends Base {
210
200
 
211
201
  public destroy() {
212
202
  this.stop();
213
- this.cameraStore.unregister(this.viewId, this.mainView);
214
203
  this.sideEffectManager.flushAll();
215
204
  }
216
205
  }
@@ -0,0 +1,52 @@
1
+ import type { View, Displayer } from "white-web-sdk";
2
+
3
+ export class ViewManager {
4
+ public views: Map<string, View> = new Map();
5
+
6
+ constructor(private displayer: Displayer) {}
7
+
8
+ public createView(id: string): View {
9
+ const view = createView(this.displayer);
10
+ this.views.set(id, view);
11
+ return view;
12
+ }
13
+
14
+ public getView(id: string): View | undefined {
15
+ return this.views.get(id);
16
+ }
17
+
18
+ public destroyView(id: string): void {
19
+ const view = this.views.get(id);
20
+ if (view) {
21
+ view.release();
22
+ this.views.delete(id);
23
+ }
24
+ }
25
+
26
+ public setViewScenePath(id: string, scenePath: string): void {
27
+ const view = this.views.get(id);
28
+ if (view) {
29
+ view.focusScenePath = scenePath;
30
+ }
31
+ }
32
+
33
+ public destroy() {
34
+ this.views.forEach(view => {
35
+ view.release();
36
+ });
37
+ this.views.clear();
38
+ }
39
+ }
40
+
41
+ export const createView = (displayer: Displayer): View => {
42
+ const view = displayer.views.createView();
43
+ setDefaultCameraBound(view);
44
+ return view;
45
+ };
46
+
47
+ export const setDefaultCameraBound = (view: View) => {
48
+ view.setCameraBound({
49
+ maxContentMode: () => 10,
50
+ minContentMode: () => 0.1,
51
+ });
52
+ };
package/src/constants.ts CHANGED
@@ -10,7 +10,8 @@ export enum Events {
10
10
  SetMainViewScenePath = "SetMainViewScenePath",
11
11
  SetMainViewSceneIndex = "SetMainViewSceneIndex",
12
12
  SwitchViewsToFreedom = "SwitchViewsToFreedom",
13
- MoveCameraToContain = "MoveCameraToContain"
13
+ MoveCameraToContain = "MoveCameraToContain",
14
+ CursorMove = "CursorMove",
14
15
  }
15
16
 
16
17
  export const MagixEventName = "__WindowManger";
@@ -37,13 +38,11 @@ export enum CursorState {
37
38
  Normal = "normal",
38
39
  }
39
40
 
40
- export const REQUIRE_VERSION = "2.13.16";
41
+ export const REQUIRE_VERSION = "2.16.1";
41
42
 
42
43
  export const MIN_WIDTH = 340 / 720;
43
44
  export const MIN_HEIGHT = 340 / 720;
44
45
 
45
46
  export const SET_SCENEPATH_DELAY = 100; // 设置 scenePath 的延迟事件
46
47
 
47
- export const DEFAULT_COLLECTOR_STYLE = { right: "10px", bottom: "15px", position: "absolute" };
48
-
49
48
  export const DEFAULT_CONTAINER_RATIO = 9 / 16;
package/src/index.ts CHANGED
@@ -1,9 +1,8 @@
1
- import AppDocsViewer from "@netless/app-docs-viewer";
2
- import AppMediaPlayer, { setOptions } from "@netless/app-media-player";
3
1
  import Emittery from "emittery";
4
2
  import pRetry from "p-retry";
5
3
  import { AppManager } from "./AppManager";
6
4
  import { appRegister } from "./Register";
5
+ import { ContainerResizeObserver } from "./ContainerResizeObserver";
7
6
  import { createBoxManager } from "./BoxManager";
8
7
  import { CursorManager } from "./Cursor";
9
8
  import { DEFAULT_CONTAINER_RATIO, Events, REQUIRE_VERSION } from "./constants";
@@ -11,9 +10,10 @@ import { Fields } from "./AttributesDelegate";
11
10
  import { initDb } from "./Register/storage";
12
11
  import { isNull, isObject } from "lodash";
13
12
  import { log } from "./Utils/log";
13
+ import { ReconnectRefresher } from "./ReconnectRefresher";
14
14
  import { replaceRoomFunction } from "./Utils/RoomHacker";
15
- import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
16
- import { setupWrapper } from "./ViewManager";
15
+ import { setupBuiltin } from "./BuiltinApps";
16
+ import { setupWrapper } from "./Helper";
17
17
  import "./style.css";
18
18
  import "@netless/telebox-insider/dist/style.css";
19
19
  import {
@@ -21,6 +21,7 @@ import {
21
21
  ensureValidScenePath,
22
22
  getVersionNumber,
23
23
  isValidScenePath,
24
+ parseSceneDir,
24
25
  wait,
25
26
  } from "./Utils/Common";
26
27
  import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
@@ -31,7 +32,7 @@ import {
31
32
  ParamsInvalidError,
32
33
  WhiteWebSDKInvalidError,
33
34
  } from "./Utils/error";
34
- import type { Apps } from "./AttributesDelegate";
35
+ import type { Apps, Position } from "./AttributesDelegate";
35
36
  import {
36
37
  InvisiblePlugin,
37
38
  isPlayer,
@@ -59,8 +60,6 @@ import type { NetlessApp, RegisterParams } from "./typings";
59
60
  import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
60
61
  import type { AppProxy } from "./AppProxy";
61
62
 
62
- const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
63
-
64
63
  export type WindowMangerAttributes = {
65
64
  modelValue?: string;
66
65
  boxState: TELE_BOX_STATE;
@@ -126,6 +125,8 @@ export type AppInitState = {
126
125
  zIndex?: number;
127
126
  };
128
127
 
128
+ export type CursorMovePayload = { uid: string; state?: "leave"; position: Position };
129
+
129
130
  export type EmitterEvent = {
130
131
  onCreated: undefined;
131
132
  InitReplay: AppInitState;
@@ -140,6 +141,8 @@ export type EmitterEvent = {
140
141
  boxStateChange: string;
141
142
  playgroundSizeChange: DOMRect;
142
143
  onReconnected: void;
144
+ removeScenes: string;
145
+ cursorMove: CursorMovePayload;
143
146
  };
144
147
 
145
148
  export type EmitterType = Emittery<EmitterEvent>;
@@ -151,6 +154,9 @@ export type PublicEvent = {
151
154
  darkModeChange: boolean;
152
155
  prefersColorSchemeChange: TeleBoxColorScheme;
153
156
  cameraStateChange: CameraState;
157
+ mainViewScenePathChange: string;
158
+ mainViewSceneIndexChange: number;
159
+ focusedChange: string | undefined;
154
160
  };
155
161
 
156
162
  export type MountParams = {
@@ -172,6 +178,8 @@ export type MountParams = {
172
178
  export type CallbacksType = Emittery<PublicEvent>;
173
179
  export const callbacks: CallbacksType = new Emittery();
174
180
 
181
+ export const reconnectRefresher = new ReconnectRefresher({ emitter });
182
+
175
183
  export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
176
184
  public static kind = "WindowManager";
177
185
  public static displayer: Displayer;
@@ -182,7 +190,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
182
190
  public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
183
191
  private static isCreated = false;
184
192
 
185
- public version = "0.4.0-canary.2";
193
+ public version = __APP_VERSION__;
194
+ public dependencies = __APP_DEPENDENCIES__;
186
195
 
187
196
  public appListeners?: AppListeners;
188
197
 
@@ -196,9 +205,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
196
205
  private boxManager?: BoxManager;
197
206
  private static params?: MountParams;
198
207
 
208
+ private containerResizeObserver?: ContainerResizeObserver;
209
+
199
210
  constructor(context: InvisiblePluginContext) {
200
211
  super(context);
201
212
  WindowManager.displayer = context.displayer;
213
+ (window as any).NETLESS_DEPS = __APP_DEPENDENCIES__;
202
214
  }
203
215
 
204
216
  public static async mount(params: MountParams): Promise<WindowManager> {
@@ -215,15 +227,16 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
215
227
  if (room.phase !== RoomPhase.Connected) {
216
228
  throw new Error("[WindowManager]: Room only Connected can be mount");
217
229
  }
230
+ if (room.phase === RoomPhase.Connected && room.isWritable) {
231
+ // redo undo 需要设置这个属性
232
+ room.disableSerialization = false;
233
+ }
218
234
  }
219
235
  if (WindowManager.isCreated) {
220
236
  throw new Error("[WindowManager]: Already created cannot be created again");
221
237
  }
222
238
  let manager = await this.initManager(room);
223
239
  this.debug = Boolean(debug);
224
- if (this.debug) {
225
- setOptions({ verbose: true });
226
- }
227
240
  log("Already insert room", manager);
228
241
 
229
242
  if (isRoom(this.displayer)) {
@@ -317,7 +330,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
317
330
  style.textContent = overwriteStyles;
318
331
  playground.appendChild(style);
319
332
  }
320
- manager.observePlaygroundSize(playground, sizer, wrapper);
333
+ manager.containerResizeObserver = ContainerResizeObserver.create(
334
+ playground,
335
+ sizer,
336
+ wrapper,
337
+ emitter
338
+ );
321
339
  WindowManager.wrapper = wrapper;
322
340
  return mainViewElement;
323
341
  }
@@ -357,8 +375,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
357
375
  }
358
376
 
359
377
  public bindCollectorContainer(container: HTMLElement) {
360
- if (WindowManager.isCreated) {
361
- this.boxManager?.setCollectorContainer(container);
378
+ if (WindowManager.isCreated && this.boxManager) {
379
+ this.boxManager.setCollectorContainer(container);
362
380
  } else {
363
381
  if (WindowManager.params) {
364
382
  WindowManager.params.collectorContainer = container;
@@ -416,6 +434,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
416
434
  const appScenePath = appManager.store.getAppScenePath(appId);
417
435
  if (appScenePath && appScenePath === scenePath) {
418
436
  console.warn(`[WindowManager]: ScenePath ${scenePath} Already opened`);
437
+ if (this.boxManager) {
438
+ const topBox = this.boxManager.getTopBox();
439
+ if (topBox) {
440
+ this.boxManager.setZIndex(appId, topBox.zIndex + 1, false);
441
+ }
442
+ }
419
443
  return;
420
444
  }
421
445
  }
@@ -460,7 +484,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
460
484
  /**
461
485
  * 返回 mainView 的 ScenePath
462
486
  */
463
- public getMainViewScenePath(): string {
487
+ public getMainViewScenePath(): string | undefined {
464
488
  return this.appManager?.store.getMainViewScenePath();
465
489
  }
466
490
 
@@ -475,10 +499,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
475
499
  * 设置所有 app 的 readonly 模式
476
500
  */
477
501
  public setReadonly(readonly: boolean): void {
478
- if (this.room?.isWritable) {
479
- this.readonly = readonly;
480
- this.appManager?.boxManager?.setReadonly(readonly);
481
- }
502
+ this.readonly = readonly;
503
+ this.boxManager?.setReadonly(readonly);
482
504
  }
483
505
 
484
506
  /**
@@ -510,6 +532,35 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
510
532
  this.viewMode = mode;
511
533
  }
512
534
 
535
+ public setBoxState(boxState: TeleBoxState): void {
536
+ if (!this.canOperate) return;
537
+ switch (boxState) {
538
+ case "normal":
539
+ this.setMaximized(false);
540
+ this.setMinimized(false);
541
+ break;
542
+ case "maximized":
543
+ this.setMaximized(true);
544
+ this.setMinimized(false);
545
+ break;
546
+ case "minimized":
547
+ this.setMinimized(true);
548
+ break;
549
+ default:
550
+ break;
551
+ }
552
+ }
553
+
554
+ public setMaximized(maximized: boolean): void {
555
+ if (!this.canOperate) return;
556
+ this.boxManager?.setMaximized(maximized, false);
557
+ }
558
+
559
+ public setMinimized(minimized: boolean): void {
560
+ if (!this.canOperate) return;
561
+ this.boxManager?.setMinimized(minimized, false);
562
+ }
563
+
513
564
  public get mainView(): View {
514
565
  if (this.appManager) {
515
566
  return this.appManager.mainViewProxy.view;
@@ -558,6 +609,27 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
558
609
  }
559
610
  }
560
611
 
612
+ public get focused(): string | undefined {
613
+ return this.attributes.focus;
614
+ }
615
+
616
+ public get mainViewSceneIndex(): number {
617
+ return this.appManager?.store.getMainViewSceneIndex();
618
+ }
619
+
620
+ public get mainViewSceneDir(): string {
621
+ const scenePath = this.appManager?.store.getMainViewScenePath();
622
+ if (scenePath) {
623
+ return parseSceneDir(scenePath);
624
+ } else {
625
+ throw new Error("[WindowManager]: mainViewSceneDir not found");
626
+ }
627
+ }
628
+
629
+ public get topApp(): string | undefined {
630
+ return this.boxManager?.getTopBox()?.id;
631
+ }
632
+
561
633
  /**
562
634
  * 查询所有的 App
563
635
  */
@@ -699,61 +771,13 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
699
771
  }
700
772
  }
701
773
 
702
- private containerResizeObserver?: ResizeObserver;
703
-
704
- private observePlaygroundSize(
705
- container: HTMLElement,
706
- sizer: HTMLElement,
707
- wrapper: HTMLDivElement
708
- ) {
709
- this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
710
-
711
- this.containerResizeObserver = new ResizeObserver(entries => {
712
- const containerRect = entries[0]?.contentRect;
713
- if (containerRect) {
714
- this.updateSizer(containerRect, sizer, wrapper);
715
- this.cursorManager?.updateContainerRect();
716
- this.boxManager?.updateManagerRect();
717
- emitter.emit("playgroundSizeChange", containerRect);
718
- }
719
- });
720
-
721
- this.containerResizeObserver.observe(container);
722
- }
723
-
724
- private updateSizer(
725
- { width, height }: DOMRectReadOnly,
726
- sizer: HTMLElement,
727
- wrapper: HTMLDivElement
728
- ) {
729
- if (width && height) {
730
- if (height / width > WindowManager.containerSizeRatio) {
731
- height = width * WindowManager.containerSizeRatio;
732
- sizer.classList.toggle("netless-window-manager-sizer-horizontal", true);
733
- } else {
734
- width = height / WindowManager.containerSizeRatio;
735
- sizer.classList.toggle("netless-window-manager-sizer-horizontal", false);
736
- }
737
- wrapper.style.width = `${width}px`;
738
- wrapper.style.height = `${height}px`;
739
- }
740
- }
774
+ private _removeScenes = (scenePath: string) => {
775
+ this.room.removeScenes(scenePath);
776
+ };
741
777
  }
742
778
 
743
- WindowManager.register({
744
- kind: AppDocsViewer.kind,
745
- src: AppDocsViewer,
746
- });
747
- WindowManager.register({
748
- kind: AppMediaPlayer.kind,
749
- src: AppMediaPlayer,
750
- });
751
-
752
- export const BuiltinApps = {
753
- DocsViewer: AppDocsViewer.kind as string,
754
- MediaPlayer: AppMediaPlayer.kind as string,
755
- };
779
+ setupBuiltin();
756
780
 
757
781
  export * from "./typings";
758
782
 
759
- export { WhiteWindowSDK } from "./sdk";
783
+ export { BuiltinApps } from "./BuiltinApps";
package/src/shim.d.ts CHANGED
@@ -4,3 +4,8 @@ declare module "*.svelte" {
4
4
  const app: SvelteComponent;
5
5
  export default app;
6
6
  }
7
+
8
+ declare global {
9
+ const __APP_VERSION__: string;
10
+ const __APP_DEPENDENCIES__: Record<string, string>;
11
+ }
package/src/style.css CHANGED
@@ -122,7 +122,7 @@
122
122
  left: 0;
123
123
  top: 0;
124
124
  will-change: transform;
125
- transition: transform 0.05s;
125
+ transition: transform 0.1s;
126
126
  transform-origin: 0 0;
127
127
  user-select: none;
128
128
  }
@@ -167,3 +167,9 @@
167
167
  display: flex;
168
168
  justify-content: center;
169
169
  }
170
+
171
+ .telebox-collector {
172
+ position: absolute;
173
+ right: 10px;
174
+ bottom: 15px;
175
+ }
package/src/typings.ts CHANGED
@@ -12,7 +12,7 @@ import type {
12
12
  import type { AppContext } from "./AppContext";
13
13
  import type { ReadonlyTeleBox, TeleBoxRect } from "@netless/telebox-insider";
14
14
 
15
- export interface NetlessApp<Attributes = any, SetupResult = any, AppOptions = any> {
15
+ export interface NetlessApp<Attributes = any, MagixEventPayloads = any, AppOptions = any, SetupResult = any> {
16
16
  kind: string;
17
17
  config?: {
18
18
  /** Box width relative to whiteboard. 0~1. Default 0.5. */
@@ -28,7 +28,7 @@ export interface NetlessApp<Attributes = any, SetupResult = any, AppOptions = an
28
28
  /** App only single instance. */
29
29
  singleton?: boolean;
30
30
  };
31
- setup: (context: AppContext<Attributes, AppOptions>) => SetupResult;
31
+ setup: (context: AppContext<Attributes, MagixEventPayloads, AppOptions>) => SetupResult;
32
32
  }
33
33
 
34
34
  export type AppEmitterEvent<T = any> = {
@@ -76,3 +76,4 @@ export type AppListenerKeys = keyof AppEmitterEvent;
76
76
  export type { AppContext } from "./AppContext";
77
77
  export type { ReadonlyTeleBox, TeleBoxRect };
78
78
  export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room, Player };
79
+ export type { Storage, StorageStateChangedEvent, StorageStateChangedListener } from "./App/Storage";
package/vite.config.js CHANGED
@@ -1,13 +1,19 @@
1
1
  import path from "path";
2
2
  import { defineConfig } from "vite";
3
3
  import { svelte } from "@sveltejs/vite-plugin-svelte";
4
- import { dependencies ,peerDependencies } from "./package.json"
4
+ import { dependencies, peerDependencies, version, devDependencies } from "./package.json"
5
5
 
6
6
 
7
7
  export default defineConfig(({ mode }) => {
8
8
  const isProd = mode === "production";
9
9
 
10
10
  return {
11
+ define: {
12
+ __APP_VERSION__: JSON.stringify(version),
13
+ __APP_DEPENDENCIES__: JSON.stringify({
14
+ dependencies, peerDependencies, devDependencies
15
+ }),
16
+ },
11
17
  plugins: [
12
18
  svelte({
13
19
  emitCss: false,
@@ -20,7 +26,7 @@ export default defineConfig(({ mode }) => {
20
26
  lib: {
21
27
  // eslint-disable-next-line no-undef
22
28
  entry: path.resolve(__dirname, "src/index.ts"),
23
- formats: ["es","umd"], // TODO cjs 版本待修复
29
+ formats: ["es", "umd"], // TODO cjs 版本待修复
24
30
  name: "WindowManager",
25
31
  fileName: "index"
26
32
  },
@@ -1,13 +0,0 @@
1
- import type { AppManager } from "../AppManager";
2
- export declare class Context {
3
- private manager;
4
- observerId: number;
5
- constructor(manager: AppManager);
6
- get uid(): string;
7
- findMember: (memberId: number) => import("white-web-sdk").RoomMember | undefined;
8
- findMemberByUid: (uid: string) => import("white-web-sdk").RoomMember | undefined;
9
- updateManagerRect(): void;
10
- blurFocusBox(): void;
11
- switchAppToWriter(id: string): void;
12
- }
13
- export declare const createContext: (manager: AppManager) => Context;
@@ -1,7 +0,0 @@
1
- import type { AppManager } from "../AppManager";
2
- export declare class Base {
3
- manager: AppManager;
4
- store: import("../AttributesDelegate").AttributesDelegate;
5
- context: import("./Context").Context;
6
- constructor(manager: AppManager);
7
- }
@@ -1,15 +0,0 @@
1
- import type { Camera, View } from "white-web-sdk";
2
- export declare class CameraStore {
3
- private cameras;
4
- private listeners;
5
- setCamera(id: string, camera: Camera): void;
6
- getCamera(id: string): Camera | undefined;
7
- deleteCamera(id: string): void;
8
- recoverCamera(id: string, view?: View): void;
9
- register(id: string, view: View): void;
10
- unregister(id: string, view?: View): void;
11
- private onListener;
12
- private offListener;
13
- switchView(id: string, view: View | undefined, callback: () => void): Promise<void>;
14
- private getOrCreateListener;
15
- }
@@ -1,29 +0,0 @@
1
- import { Base } from "./Base";
2
- import type { View, Displayer } from "white-web-sdk";
3
- import type { AppManager } from "./AppManager";
4
- export declare class ViewManager extends Base {
5
- private views;
6
- private timer?;
7
- private appTimer?;
8
- private mainViewProxy;
9
- private displayer;
10
- constructor(manager: AppManager);
11
- get currentScenePath(): string;
12
- get mainView(): View;
13
- createView(appId: string): View;
14
- destroyView(appId: string): void;
15
- private releaseView;
16
- getView(appId: string): View | undefined;
17
- switchMainViewToWriter(): Promise<boolean> | undefined;
18
- freedomAllViews(): void;
19
- switchAppToWriter(id: string): void;
20
- destroy(): void;
21
- }
22
- export declare const createView: (displayer: Displayer) => View;
23
- export declare const setDefaultCameraBound: (view: View) => void;
24
- export declare const setupWrapper: (root: HTMLElement) => {
25
- playground: HTMLDivElement;
26
- wrapper: HTMLDivElement;
27
- sizer: HTMLDivElement;
28
- mainViewElement: HTMLDivElement;
29
- };