@netless/window-manager 0.3.18 → 0.4.0-canary.11

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 (75) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +4 -43
  3. package/dist/App/MagixEvent/index.d.ts +28 -0
  4. package/dist/App/Storage/StorageEvent.d.ts +8 -0
  5. package/dist/App/Storage/index.d.ts +38 -0
  6. package/dist/App/Storage/typings.d.ts +21 -0
  7. package/dist/App/Storage/utils.d.ts +5 -0
  8. package/dist/AppContext.d.ts +42 -17
  9. package/dist/AppListener.d.ts +2 -2
  10. package/dist/AppManager.d.ts +18 -14
  11. package/dist/AppProxy.d.ts +5 -3
  12. package/dist/AttributesDelegate.d.ts +19 -11
  13. package/dist/Base/Context.d.ts +0 -1
  14. package/dist/Base/index.d.ts +1 -2
  15. package/dist/BoxManager.d.ts +24 -7
  16. package/dist/BuiltinApps.d.ts +6 -0
  17. package/dist/ContainerResizeObserver.d.ts +10 -0
  18. package/dist/Cursor/Cursor.d.ts +2 -3
  19. package/dist/Cursor/index.d.ts +9 -5
  20. package/dist/Helper.d.ts +6 -0
  21. package/dist/ReconnectRefresher.d.ts +9 -3
  22. package/dist/Utils/Common.d.ts +3 -1
  23. package/dist/Utils/Reactive.d.ts +1 -1
  24. package/dist/Utils/RoomHacker.d.ts +2 -2
  25. package/dist/Utils/error.d.ts +3 -0
  26. package/dist/{MainView.d.ts → View/MainView.d.ts} +3 -4
  27. package/dist/View/ViewManager.d.ts +13 -0
  28. package/dist/constants.d.ts +3 -7
  29. package/dist/index.d.ts +25 -27
  30. package/dist/index.es.js +1 -1
  31. package/dist/index.es.js.map +1 -1
  32. package/dist/index.umd.js +1 -1
  33. package/dist/index.umd.js.map +1 -1
  34. package/dist/style.css +1 -1
  35. package/dist/typings.d.ts +3 -2
  36. package/docs/api.md +17 -0
  37. package/docs/migrate.md +42 -0
  38. package/package.json +6 -4
  39. package/src/App/MagixEvent/index.ts +66 -0
  40. package/src/App/Storage/StorageEvent.ts +21 -0
  41. package/src/App/Storage/index.ts +284 -0
  42. package/src/App/Storage/typings.ts +21 -0
  43. package/src/App/Storage/utils.ts +17 -0
  44. package/src/AppContext.ts +61 -21
  45. package/src/AppListener.ts +15 -11
  46. package/src/AppManager.ts +141 -95
  47. package/src/AppProxy.ts +49 -52
  48. package/src/AttributesDelegate.ts +76 -49
  49. package/src/Base/Context.ts +2 -6
  50. package/src/Base/index.ts +2 -2
  51. package/src/BoxManager.ts +89 -31
  52. package/src/BuiltinApps.ts +24 -0
  53. package/src/ContainerResizeObserver.ts +62 -0
  54. package/src/Cursor/Cursor.ts +35 -39
  55. package/src/Cursor/index.ts +79 -43
  56. package/src/Helper.ts +30 -0
  57. package/src/ReconnectRefresher.ts +25 -10
  58. package/src/Utils/Common.ts +35 -13
  59. package/src/Utils/Reactive.ts +9 -3
  60. package/src/Utils/RoomHacker.ts +20 -5
  61. package/src/Utils/error.ts +6 -1
  62. package/src/{MainView.ts → View/MainView.ts} +19 -27
  63. package/src/View/ViewManager.ts +53 -0
  64. package/src/constants.ts +2 -3
  65. package/src/index.ts +144 -171
  66. package/src/shim.d.ts +4 -0
  67. package/src/style.css +7 -1
  68. package/src/typings.ts +3 -2
  69. package/vite.config.js +4 -1
  70. package/dist/Utils/CameraStore.d.ts +0 -15
  71. package/dist/ViewManager.d.ts +0 -29
  72. package/dist/sdk.d.ts +0 -14
  73. package/src/Utils/CameraStore.ts +0 -72
  74. package/src/sdk.ts +0 -39
  75. package/src/viewManager.ts +0 -177
package/src/index.ts CHANGED
@@ -1,18 +1,19 @@
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";
6
+ import { createBoxManager } from "./BoxManager";
7
7
  import { CursorManager } from "./Cursor";
8
- import { DEFAULT_CONTAINER_RATIO, REQUIRE_VERSION } from "./constants";
8
+ import { DEFAULT_CONTAINER_RATIO, Events, REQUIRE_VERSION } from "./constants";
9
9
  import { Fields } from "./AttributesDelegate";
10
10
  import { initDb } from "./Register/storage";
11
11
  import { isNull, isObject } from "lodash";
12
12
  import { log } from "./Utils/log";
13
+ import { ReconnectRefresher } from "./ReconnectRefresher";
13
14
  import { replaceRoomFunction } from "./Utils/RoomHacker";
14
- import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
15
- import { setupWrapper } from "./ViewManager";
15
+ import { setupBuiltin } from "./BuiltinApps";
16
+ import { setupWrapper } from "./Helper";
16
17
  import "./style.css";
17
18
  import "@netless/telebox-insider/dist/style.css";
18
19
  import {
@@ -22,7 +23,7 @@ import {
22
23
  isValidScenePath,
23
24
  wait,
24
25
  } from "./Utils/Common";
25
- import type { TELE_BOX_STATE } from "./BoxManager";
26
+ import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
26
27
  import {
27
28
  AppCreateError,
28
29
  AppManagerNotInitError,
@@ -58,8 +59,6 @@ import type { NetlessApp, RegisterParams } from "./typings";
58
59
  import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
59
60
  import type { AppProxy } from "./AppProxy";
60
61
 
61
- const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
62
-
63
62
  export type WindowMangerAttributes = {
64
63
  modelValue?: string;
65
64
  boxState: TELE_BOX_STATE;
@@ -80,14 +79,14 @@ export type AddAppOptions = {
80
79
 
81
80
  export type setAppOptions = AddAppOptions & { appOptions?: any };
82
81
 
83
- export type AddAppParams = {
82
+ export type AddAppParams<TAttributes = any> = {
84
83
  kind: string;
85
84
  // app 地址(本地 app 不需要传)
86
85
  src?: string;
87
86
  // 窗口配置
88
87
  options?: AddAppOptions;
89
88
  // 初始化 attributes
90
- attributes?: any;
89
+ attributes?: TAttributes;
91
90
  };
92
91
 
93
92
  export type BaseInsertParams = {
@@ -108,6 +107,7 @@ export type AppSyncAttributes = {
108
107
  state?: any;
109
108
  isDynamicPPT?: boolean;
110
109
  fullPath?: string;
110
+ createdAt?: number;
111
111
  };
112
112
 
113
113
  export type AppInitState = {
@@ -137,9 +137,11 @@ export type EmitterEvent = {
137
137
  observerIdChange: number;
138
138
  boxStateChange: string;
139
139
  playgroundSizeChange: DOMRect;
140
+ onReconnected: void;
140
141
  };
141
142
 
142
- export const emitter: Emittery<EmitterEvent> = new Emittery();
143
+ export type EmitterType = Emittery<EmitterEvent>;
144
+ export const emitter: EmitterType = new Emittery();
143
145
 
144
146
  export type PublicEvent = {
145
147
  mainViewModeChange: ViewVisionMode;
@@ -147,11 +149,14 @@ export type PublicEvent = {
147
149
  darkModeChange: boolean;
148
150
  prefersColorSchemeChange: TeleBoxColorScheme;
149
151
  cameraStateChange: CameraState;
152
+ mainViewScenePathChange: string;
153
+ mainViewSceneIndexChange: number;
154
+ focusedChange: string | undefined;
150
155
  };
151
156
 
152
157
  export type MountParams = {
153
158
  room: Room;
154
- container: HTMLElement;
159
+ container?: HTMLElement;
155
160
  /** 白板高宽比例, 默认为 9 / 16 */
156
161
  containerSizeRatio?: number;
157
162
  /** 显示 PS 透明背景,默认 true */
@@ -165,7 +170,10 @@ export type MountParams = {
165
170
  prefersColorScheme?: TeleBoxColorScheme;
166
171
  };
167
172
 
168
- export const callbacks: Emittery<PublicEvent> = new Emittery();
173
+ export type CallbacksType = Emittery<PublicEvent>;
174
+ export const callbacks: CallbacksType = new Emittery();
175
+
176
+ export const reconnectRefresher = new ReconnectRefresher({ emitter });
169
177
 
170
178
  export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
171
179
  public static kind = "WindowManager";
@@ -177,7 +185,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
177
185
  public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
178
186
  private static isCreated = false;
179
187
 
180
- public version = "0.3.18";
188
+ public version = __APP_VERSION__;
181
189
 
182
190
  public appListeners?: AppListeners;
183
191
 
@@ -188,93 +196,40 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
188
196
  public viewMode = ViewMode.Broadcaster;
189
197
  public isReplay = isPlayer(this.displayer);
190
198
 
199
+ private boxManager?: BoxManager;
200
+ private static params?: MountParams;
201
+
202
+ private containerResizeObserver?: ContainerResizeObserver;
203
+
191
204
  constructor(context: InvisiblePluginContext) {
192
205
  super(context);
206
+ WindowManager.displayer = context.displayer;
193
207
  }
194
208
 
195
- /**
196
- * 挂载 WindowManager
197
- * @deprecated
198
- */
199
- public static async mount(
200
- room: Room,
201
- container: HTMLElement,
202
- collectorContainer?: HTMLElement,
203
- options?: {
204
- chessboard: boolean;
205
- containerSizeRatio: number;
206
- collectorStyles?: Partial<CSSStyleDeclaration>;
207
- debug?: boolean;
208
- overwriteStyles?: string;
209
- }
210
- ): Promise<WindowManager>;
211
-
212
- public static async mount(params: MountParams): Promise<WindowManager>;
213
-
214
- public static async mount(
215
- params: MountParams | Room,
216
- container?: HTMLElement,
217
- collectorContainer?: HTMLElement,
218
- options?: {
219
- chessboard?: boolean;
220
- containerSizeRatio: number;
221
- collectorStyles?: Partial<CSSStyleDeclaration>;
222
- debug?: boolean;
223
- overwriteStyles?: string;
224
- disableCameraTransform?: boolean;
225
- }
226
- ): Promise<WindowManager> {
227
- let room: Room;
228
- let containerSizeRatio: number | undefined;
229
- let collectorStyles: Partial<CSSStyleDeclaration> | undefined;
230
- let debug: boolean | undefined;
231
- let chessboard = true;
232
- let overwriteStyles: string | undefined;
233
- let cursor: boolean | undefined;
234
- let disableCameraTransform = false;
235
- let prefersColorScheme: TeleBoxColorScheme | undefined = "light";
236
- if ("room" in params) {
237
- room = params.room;
238
- container = params.container;
239
- collectorContainer = params.collectorContainer;
240
- containerSizeRatio = params.containerSizeRatio;
241
- collectorStyles = params.collectorStyles;
242
- debug = params.debug;
243
- if (params.chessboard != null) {
244
- chessboard = params.chessboard;
245
- }
246
- overwriteStyles = params.overwriteStyles;
247
- cursor = params.cursor;
248
- disableCameraTransform = Boolean(params?.disableCameraTransform);
249
- prefersColorScheme = params.prefersColorScheme;
250
- } else {
251
- room = params;
252
- containerSizeRatio = options?.containerSizeRatio;
253
- collectorStyles = options?.collectorStyles;
254
- debug = options?.debug;
255
- if (options?.chessboard != null) {
256
- chessboard = options.chessboard;
257
- }
258
- overwriteStyles = options?.overwriteStyles;
259
- }
209
+ public static async mount(params: MountParams): Promise<WindowManager> {
210
+ const room = params.room;
211
+ WindowManager.container = params.container;
212
+ const containerSizeRatio = params.containerSizeRatio;
213
+ const debug = params.debug;
214
+
215
+ const cursor = params.cursor;
216
+ WindowManager.params = params;
260
217
 
261
218
  this.checkVersion();
262
219
  if (isRoom(room)) {
263
220
  if (room.phase !== RoomPhase.Connected) {
264
221
  throw new Error("[WindowManager]: Room only Connected can be mount");
265
222
  }
266
- }
267
- if (!container) {
268
- throw new Error("[WindowManager]: Container must provide");
223
+ if (room.phase === RoomPhase.Connected) {
224
+ // redo undo 需要设置这个属性
225
+ room.disableSerialization = false;
226
+ }
269
227
  }
270
228
  if (WindowManager.isCreated) {
271
229
  throw new Error("[WindowManager]: Already created cannot be created again");
272
230
  }
273
231
  let manager = await this.initManager(room);
274
232
  this.debug = Boolean(debug);
275
- if (this.debug) {
276
- setOptions({ verbose: true });
277
- }
278
233
  log("Already insert room", manager);
279
234
 
280
235
  if (isRoom(this.displayer)) {
@@ -297,29 +252,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
297
252
  if (containerSizeRatio) {
298
253
  WindowManager.containerSizeRatio = containerSizeRatio;
299
254
  }
300
- WindowManager.container = container;
301
- const { playground, wrapper, sizer, mainViewElement } = setupWrapper(container);
302
- WindowManager.playground = playground;
303
- if (chessboard) {
304
- sizer.classList.add("netless-window-manager-chess-sizer");
305
- }
306
- if (overwriteStyles) {
307
- const style = document.createElement("style");
308
- style.textContent = overwriteStyles;
309
- playground.appendChild(style);
310
- }
311
255
  await manager.ensureAttributes();
312
- manager.appManager = new AppManager(manager, {
313
- collectorContainer: collectorContainer,
314
- collectorStyles: collectorStyles,
315
- prefersColorScheme: prefersColorScheme,
316
- });
317
- manager.observePlaygroundSize(playground, sizer, wrapper);
256
+
257
+ manager.appManager = new AppManager(manager);
258
+
318
259
  if (cursor) {
319
260
  manager.cursorManager = new CursorManager(manager.appManager);
320
261
  }
321
- manager.bindMainView(mainViewElement, disableCameraTransform);
322
- replaceRoomFunction(room, manager.appManager);
262
+
263
+ if (params.container) {
264
+ manager.bindContainer(params.container);
265
+ }
266
+
267
+ replaceRoomFunction(room, manager);
323
268
  emitter.emit("onCreated");
324
269
  WindowManager.isCreated = true;
325
270
  try {
@@ -359,6 +304,79 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
359
304
  return manager;
360
305
  }
361
306
 
307
+ private static initContainer(
308
+ manager: WindowManager,
309
+ container: HTMLElement,
310
+ chessboard: boolean | undefined,
311
+ overwriteStyles: string | undefined
312
+ ) {
313
+ if (!WindowManager.container) {
314
+ WindowManager.container = container;
315
+ }
316
+ const { playground, wrapper, sizer, mainViewElement } = setupWrapper(container);
317
+ WindowManager.playground = playground;
318
+ if (chessboard) {
319
+ sizer.classList.add("netless-window-manager-chess-sizer");
320
+ }
321
+ if (overwriteStyles) {
322
+ const style = document.createElement("style");
323
+ style.textContent = overwriteStyles;
324
+ playground.appendChild(style);
325
+ }
326
+ manager.containerResizeObserver = ContainerResizeObserver.create(
327
+ playground,
328
+ sizer,
329
+ wrapper,
330
+ emitter
331
+ );
332
+ WindowManager.wrapper = wrapper;
333
+ return mainViewElement;
334
+ }
335
+
336
+ public bindContainer(container: HTMLElement) {
337
+ if (WindowManager.isCreated && WindowManager.container) {
338
+ if (WindowManager.container.firstChild) {
339
+ container.appendChild(WindowManager.container.firstChild);
340
+ }
341
+ } else {
342
+ if (WindowManager.params) {
343
+ const params = WindowManager.params;
344
+ const mainViewElement = WindowManager.initContainer(
345
+ this,
346
+ container,
347
+ params.chessboard,
348
+ params.overwriteStyles
349
+ );
350
+ const boxManager = createBoxManager(this, callbacks, emitter, {
351
+ collectorContainer: params.collectorContainer,
352
+ collectorStyles: params.collectorStyles,
353
+ prefersColorScheme: params.prefersColorScheme,
354
+ });
355
+ this.boxManager = boxManager;
356
+ this.appManager?.setBoxManager(boxManager);
357
+ this.bindMainView(mainViewElement, params.disableCameraTransform);
358
+ if (WindowManager.wrapper) {
359
+ this.cursorManager?.setupWrapper(WindowManager.wrapper);
360
+ }
361
+ }
362
+ }
363
+ this.boxManager?.updateManagerRect();
364
+ this.appManager?.refresh();
365
+ this.appManager?.resetMaximized();
366
+ this.appManager?.resetMinimized();
367
+ WindowManager.container = container;
368
+ }
369
+
370
+ public bindCollectorContainer(container: HTMLElement) {
371
+ if (WindowManager.isCreated && this.boxManager) {
372
+ this.boxManager.setCollectorContainer(container);
373
+ } else {
374
+ if (WindowManager.params) {
375
+ WindowManager.params.collectorContainer = container;
376
+ }
377
+ }
378
+ }
379
+
362
380
  /**
363
381
  * 注册插件
364
382
  */
@@ -371,7 +389,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
371
389
  /**
372
390
  * 创建一个 app 至白板
373
391
  */
374
- public async addApp(params: AddAppParams): Promise<string | undefined> {
392
+ public async addApp<T = any>(params: AddAppParams<T>): Promise<string | undefined> {
375
393
  if (this.appManager) {
376
394
  if (!params.kind || typeof params.kind !== "string") {
377
395
  throw new ParamsInvalidError();
@@ -468,10 +486,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
468
486
  * 设置所有 app 的 readonly 模式
469
487
  */
470
488
  public setReadonly(readonly: boolean): void {
471
- if (this.room?.isWritable) {
472
- this.readonly = readonly;
473
- this.appManager?.boxManager.setReadonly(readonly);
474
- }
489
+ this.readonly = readonly;
490
+ this.boxManager?.setReadonly(readonly);
475
491
  }
476
492
 
477
493
  /**
@@ -531,26 +547,30 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
531
547
  return this.appManager?.store.apps();
532
548
  }
533
549
 
534
- public get boxState(): TeleBoxState {
550
+ public get boxState(): TeleBoxState | undefined {
535
551
  if (this.appManager) {
536
- return this.appManager.boxManager.boxState;
552
+ return this.appManager.boxManager?.boxState;
537
553
  } else {
538
554
  throw new AppManagerNotInitError();
539
555
  }
540
556
  }
541
557
 
542
558
  public get darkMode(): boolean {
543
- return Boolean(this.appManager?.boxManager.darkMode);
559
+ return Boolean(this.appManager?.boxManager?.darkMode);
544
560
  }
545
561
 
546
- public get prefersColorScheme(): TeleBoxColorScheme {
562
+ public get prefersColorScheme(): TeleBoxColorScheme | undefined {
547
563
  if (this.appManager) {
548
- return this.appManager.boxManager.prefersColorScheme;
564
+ return this.appManager.boxManager?.prefersColorScheme;
549
565
  } else {
550
566
  throw new AppManagerNotInitError();
551
567
  }
552
568
  }
553
569
 
570
+ public get focused(): string | undefined {
571
+ return this.attributes.focus;
572
+ }
573
+
554
574
  /**
555
575
  * 查询所有的 App
556
576
  */
@@ -585,6 +605,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
585
605
  }>
586
606
  ): void {
587
607
  this.mainView.moveCameraToContain(rectangle);
608
+ this.appManager?.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
609
+ setTimeout(() => {
610
+ this.appManager?.mainViewProxy.setCameraAndSize();
611
+ }, 1000);
588
612
  }
589
613
 
590
614
  public convertToPointInWorld(point: Point): Point {
@@ -613,12 +637,13 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
613
637
  if (WindowManager.playground) {
614
638
  WindowManager.playground.parentNode?.removeChild(WindowManager.playground);
615
639
  }
640
+ WindowManager.params = undefined;
616
641
  log("Destroyed");
617
642
  }
618
643
 
619
- private bindMainView(divElement: HTMLDivElement, disableCameraTransform: boolean) {
644
+ private bindMainView(divElement: HTMLDivElement, disableCameraTransform: boolean | undefined) {
620
645
  if (this.appManager) {
621
- this.appManager.bindMainView(divElement, disableCameraTransform);
646
+ this.appManager.bindMainView(divElement, Boolean(disableCameraTransform));
622
647
  this.cursorManager?.setMainViewDivElement(divElement);
623
648
  }
624
649
  }
@@ -651,7 +676,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
651
676
  }
652
677
 
653
678
  public setPrefersColorScheme(scheme: TeleBoxColorScheme): void {
654
- this.appManager?.boxManager.setPrefersColorScheme(scheme);
679
+ this.appManager?.boxManager?.setPrefersColorScheme(scheme);
655
680
  }
656
681
 
657
682
  private isDynamicPPT(scenes: SceneDefinition[]) {
@@ -686,62 +711,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
686
711
  }
687
712
  }
688
713
  }
689
-
690
- private containerResizeObserver?: ResizeObserver;
691
-
692
- private observePlaygroundSize(
693
- container: HTMLElement,
694
- sizer: HTMLElement,
695
- wrapper: HTMLDivElement
696
- ) {
697
- this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
698
-
699
- this.containerResizeObserver = new ResizeObserver(entries => {
700
- const containerRect = entries[0]?.contentRect;
701
- if (containerRect) {
702
- this.updateSizer(containerRect, sizer, wrapper);
703
- this.cursorManager?.updateContainerRect();
704
- this.appManager?.boxManager.updateManagerRect();
705
- emitter.emit("playgroundSizeChange", containerRect);
706
- }
707
- });
708
-
709
- this.containerResizeObserver.observe(container);
710
- }
711
-
712
- private updateSizer(
713
- { width, height }: DOMRectReadOnly,
714
- sizer: HTMLElement,
715
- wrapper: HTMLDivElement
716
- ) {
717
- if (width && height) {
718
- if (height / width > WindowManager.containerSizeRatio) {
719
- height = width * WindowManager.containerSizeRatio;
720
- sizer.classList.toggle("netless-window-manager-sizer-horizontal", true);
721
- } else {
722
- width = height / WindowManager.containerSizeRatio;
723
- sizer.classList.toggle("netless-window-manager-sizer-horizontal", false);
724
- }
725
- wrapper.style.width = `${width}px`;
726
- wrapper.style.height = `${height}px`;
727
- }
728
- }
729
714
  }
730
715
 
731
- WindowManager.register({
732
- kind: AppDocsViewer.kind,
733
- src: AppDocsViewer,
734
- });
735
- WindowManager.register({
736
- kind: AppMediaPlayer.kind,
737
- src: AppMediaPlayer,
738
- });
739
-
740
- export const BuiltinApps = {
741
- DocsViewer: AppDocsViewer.kind as string,
742
- MediaPlayer: AppMediaPlayer.kind as string,
743
- };
716
+ setupBuiltin();
744
717
 
745
718
  export * from "./typings";
746
719
 
747
- export { WhiteWindowSDK } from "./sdk";
720
+ export { BuiltinApps } from "./BuiltinApps";
package/src/shim.d.ts CHANGED
@@ -4,3 +4,7 @@ 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
+ }
package/src/style.css CHANGED
@@ -115,7 +115,7 @@
115
115
  flex-direction: column;
116
116
  align-items: center;
117
117
  justify-content: center;
118
- position: fixed;
118
+ position: absolute;
119
119
  width: 26px;
120
120
  height: 26px;
121
121
  z-index: 2147483647;
@@ -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,16 @@
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 } 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
+ },
11
14
  plugins: [
12
15
  svelte({
13
16
  emitCss: false,
@@ -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
- };
package/dist/sdk.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { WindowManager } from './index';
2
- import type { MountParams } from "./index";
3
- import type { WhiteWebSdkConfiguration, JoinRoomParams } from "white-web-sdk";
4
- declare type WhiteWindowSDKConfiguration = Omit<WhiteWebSdkConfiguration, "useMobXState">;
5
- declare type WindowJoinRoomParams = {
6
- joinRoomParams: Omit<JoinRoomParams, "useMultiViews" | "disableMagixEventDispatchLimit">;
7
- mountParams: Omit<MountParams, "room">;
8
- };
9
- export declare class WhiteWindowSDK {
10
- private sdk;
11
- constructor(params: WhiteWindowSDKConfiguration);
12
- mount(params: WindowJoinRoomParams): Promise<WindowManager>;
13
- }
14
- export {};