@netless/window-manager 1.0.0-canary.25 → 1.0.0-canary.28

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 (71) hide show
  1. package/dist/index.cjs.js +93 -12
  2. package/dist/index.es.js +1585 -698
  3. package/dist/index.umd.js +93 -12
  4. package/dist/{App → src/App}/AppContext.d.ts +0 -0
  5. package/dist/{App → src/App}/AppPageStateImpl.d.ts +0 -0
  6. package/dist/{App → src/App}/AppProxy.d.ts +0 -0
  7. package/dist/{App → src/App}/MagixEvent/index.d.ts +0 -0
  8. package/dist/{App → src/App}/Storage/StorageEvent.d.ts +0 -0
  9. package/dist/{App → src/App}/Storage/index.d.ts +0 -0
  10. package/dist/{App → src/App}/Storage/typings.d.ts +0 -0
  11. package/dist/{App → src/App}/Storage/utils.d.ts +0 -0
  12. package/dist/{App → src/App}/WhiteboardView.d.ts +6 -4
  13. package/dist/{App → src/App}/index.d.ts +0 -0
  14. package/dist/{App → src/App}/type.d.ts +0 -0
  15. package/dist/{AppListener.d.ts → src/AppListener.d.ts} +0 -2
  16. package/dist/{AppManager.d.ts → src/AppManager.d.ts} +0 -0
  17. package/dist/{AttributesDelegate.d.ts → src/AttributesDelegate.d.ts} +0 -0
  18. package/dist/{BoxEmitter.d.ts → src/BoxEmitter.d.ts} +0 -0
  19. package/dist/{BoxManager.d.ts → src/BoxManager.d.ts} +2 -4
  20. package/dist/{BuiltinApps.d.ts → src/BuiltinApps.d.ts} +3 -0
  21. package/dist/{Cursor → src/Cursor}/Cursor.d.ts +0 -0
  22. package/dist/{Cursor → src/Cursor}/icons.d.ts +0 -0
  23. package/dist/{Cursor → src/Cursor}/index.d.ts +0 -0
  24. package/dist/{Helper.d.ts → src/Helper.d.ts} +1 -1
  25. package/dist/{InternalEmitter.d.ts → src/InternalEmitter.d.ts} +0 -0
  26. package/dist/{Page → src/Page}/PageController.d.ts +0 -0
  27. package/dist/{Page → src/Page}/index.d.ts +0 -0
  28. package/dist/{PageState.d.ts → src/PageState.d.ts} +0 -0
  29. package/dist/{ReconnectRefresher.d.ts → src/ReconnectRefresher.d.ts} +0 -0
  30. package/dist/{RedoUndo.d.ts → src/RedoUndo.d.ts} +0 -0
  31. package/dist/{Register → src/Register}/index.d.ts +0 -0
  32. package/dist/{Register → src/Register}/loader.d.ts +0 -0
  33. package/dist/{Register → src/Register}/storage.d.ts +0 -0
  34. package/dist/{Utils → src/Utils}/AppCreateQueue.d.ts +0 -0
  35. package/dist/{Utils → src/Utils}/Common.d.ts +0 -0
  36. package/dist/{Utils → src/Utils}/Reactive.d.ts +0 -0
  37. package/dist/{Utils → src/Utils}/RoomHacker.d.ts +0 -0
  38. package/dist/{Utils → src/Utils}/error.d.ts +0 -0
  39. package/dist/{Utils → src/Utils}/log.d.ts +0 -0
  40. package/dist/{View → src/View}/CameraSynchronizer.d.ts +0 -0
  41. package/dist/{View → src/View}/MainView.d.ts +0 -0
  42. package/dist/{View → src/View}/ViewManager.d.ts +0 -0
  43. package/dist/{View → src/View}/ViewSync.d.ts +0 -0
  44. package/dist/{callback.d.ts → src/callback.d.ts} +5 -0
  45. package/dist/{constants.d.ts → src/constants.d.ts} +0 -2
  46. package/dist/src/image.d.ts +19 -0
  47. package/dist/{index.d.ts → src/index.d.ts} +16 -12
  48. package/dist/src/shim.d.ts +11 -0
  49. package/dist/{typings.d.ts → src/typings.d.ts} +6 -0
  50. package/dist/style.css +1 -1
  51. package/docs/app-context.md +2 -2
  52. package/package.json +10 -5
  53. package/playwright.config.ts +28 -0
  54. package/pnpm-lock.yaml +514 -21
  55. package/src/App/AppContext.ts +2 -2
  56. package/src/App/AppProxy.ts +18 -7
  57. package/src/App/WhiteboardView.ts +23 -18
  58. package/src/AppListener.ts +1 -21
  59. package/src/AppManager.ts +2 -1
  60. package/src/BoxManager.ts +32 -36
  61. package/src/BuiltinApps.ts +5 -0
  62. package/src/Helper.ts +3 -2
  63. package/src/Utils/Common.ts +3 -0
  64. package/src/View/CameraSynchronizer.ts +5 -9
  65. package/src/View/MainView.ts +3 -1
  66. package/src/callback.ts +1 -0
  67. package/src/constants.ts +0 -2
  68. package/src/index.ts +62 -34
  69. package/src/style.css +3 -41
  70. package/src/typings.ts +6 -0
  71. package/vite.config.js +5 -3
@@ -107,7 +107,7 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
107
107
  const viewWrapper = document.createElement("div");
108
108
  this._viewWrapper = viewWrapper;
109
109
  viewWrapper.className = "window-manager-view-wrapper";
110
- this.box.$content.parentElement?.appendChild(viewWrapper);
110
+ this.box.$main.appendChild(viewWrapper);
111
111
  view.divElement = viewWrapper;
112
112
  this.appProxy.fireMemberStateChange();
113
113
  if (this.isAddApp) {
@@ -115,7 +115,7 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
115
115
  }
116
116
  this.whiteBoardView = new WhiteBoardView(view, this, this.appProxy, this.ensurePageSize);
117
117
  this.appProxy.sideEffectManager.add(() => [
118
- this.box._contentStageRect$.subscribe(rect => {
118
+ this.box._stageRect$.subscribe(rect => {
119
119
  viewWrapper.style.left = `${rect.x}px`;
120
120
  viewWrapper.style.top = `${rect.y}px`;
121
121
  viewWrapper.style.width = `${rect.width}px`;
@@ -32,9 +32,10 @@ import type {
32
32
  import type { SceneState, View, SceneDefinition, MemberState} from "white-web-sdk";
33
33
  import type { AppManager } from "../AppManager";
34
34
  import type { NetlessApp } from "../typings";
35
- import type { ReadonlyTeleBox, TeleBoxRect } from "@netless/telebox-insider";
35
+ import type { ReadonlyTeleBox, TeleBox, TeleBoxRect } from "@netless/telebox-insider";
36
36
  import type { PageRemoveService, PageState } from "../Page";
37
37
  import type { AppState } from "./type";
38
+ import { callbacks } from "../callback";
38
39
 
39
40
  export type AppEmitter = Emittery<AppEmitterEvent>;
40
41
 
@@ -142,10 +143,10 @@ export class AppProxy implements PageRemoveService {
142
143
  });
143
144
  this.camera$.setValue(toJS(this.appAttributes.camera));
144
145
  }
145
- if (!this.size$.value && box.contentStageRect) {
146
- const initialRect = this.computedInitialRect(box.contentStageRect);
147
- const width = initialRect?.width || box.contentStageRect.width;
148
- const height = initialRect?.height || box.contentStageRect.height;
146
+ if (!this.size$.value && box.stageRect) {
147
+ const initialRect = this.computedInitialRect(box.stageRect);
148
+ const width = initialRect?.width || box.stageRect.width;
149
+ const height = initialRect?.height || box.stageRect.height;
149
150
  this.storeSize({
150
151
  id: this.uid,
151
152
  width,
@@ -158,7 +159,7 @@ export class AppProxy implements PageRemoveService {
158
159
  view$: this.view$,
159
160
  camera$: this.camera$,
160
161
  size$: this.size$,
161
- stageRect$: box._contentStageRect$,
162
+ stageRect$: box._stageRect$,
162
163
  storeCamera: this.storeCamera,
163
164
  storeSize: this.storeSize
164
165
  });
@@ -341,10 +342,18 @@ export class AppProxy implements PageRemoveService {
341
342
  options,
342
343
  canOperate: this.manager.canOperate,
343
344
  smartPosition: this.isAddApp,
344
- });
345
+ }) as TeleBox;
346
+ const registerParams = appRegister.registered.get(this.kind);
347
+ if (registerParams?.contentStyles) {
348
+ box?.mountUserStyles(registerParams.contentStyles);
349
+ }
345
350
  this.box$.setValue(box);
346
351
  if (this.isAddApp && this.box) {
347
352
  this.store.updateAppState(appId, AppAttributes.ZIndex, this.box.zIndex);
353
+ this.store.updateAppState(appId, AppAttributes.Size, {
354
+ width: this.box.intrinsicWidth,
355
+ height: this.box.intrinsicHeight,
356
+ });
348
357
  this.boxManager.focusBox({ appId }, false);
349
358
  }
350
359
  } catch (error: any) {
@@ -522,6 +531,7 @@ export class AppProxy implements PageRemoveService {
522
531
  }
523
532
 
524
533
  public setViewFocusScenePath() {
534
+ if (this.status === "destroyed") return;
525
535
  const fullPath = this.getFullScenePath();
526
536
  if (fullPath && this.view) {
527
537
  setViewFocusScenePath(this.view, fullPath);
@@ -622,6 +632,7 @@ export class AppProxy implements PageRemoveService {
622
632
  this.status = "destroyed";
623
633
  try {
624
634
  await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
635
+ callbacks.emit("appClose", { appId: this.id, kind: this.kind, error });
625
636
  await this.appEmitter.emit("destroy", { error });
626
637
  } catch (error) {
627
638
  console.error("[WindowManager]: notifyApp error", error.message, error.stack);
@@ -6,15 +6,17 @@ import type { ReadonlyVal } from "value-enhancer";
6
6
  import type { AddPageParams, PageController, PageState } from "../Page";
7
7
  import type { AppProxy } from "./AppProxy";
8
8
  import type { AppContext } from "./AppContext";
9
- import type { View } from "white-web-sdk";
9
+ import type { Camera, View } from "white-web-sdk";
10
10
  import type { TeleBoxRect } from "@netless/telebox-insider";
11
- import type { ICamera } from "../AttributesDelegate";
11
+ import type { ICamera, ISize } from "../AttributesDelegate";
12
12
 
13
- export type WhiteBoardViewCamera = Omit<ICamera, "scale" | "id">;
13
+ export type WhiteBoardViewCamera = Omit<ICamera, "id">;
14
+ export type WhiteBoardViewRect = Omit<ISize, "id">;
14
15
 
15
16
  export class WhiteBoardView implements PageController {
16
17
  public readonly pageState$: ReadonlyVal<PageState>;
17
- public readonly camera$: ReadonlyVal<WhiteBoardViewCamera>;
18
+ public readonly baseCamera$: ReadonlyVal<WhiteBoardViewCamera>;
19
+ public readonly baseRect$: ReadonlyVal<WhiteBoardViewRect | undefined>;
18
20
 
19
21
  constructor(
20
22
  public view: View,
@@ -23,23 +25,26 @@ export class WhiteBoardView implements PageController {
23
25
  public ensureSize: (size: number) => void
24
26
  ) {
25
27
  const pageState$ = new Val<PageState>(appProxy.pageState);
28
+ const baseRect$ = new Val<WhiteBoardViewRect | undefined>(appProxy.size$.value);
29
+ const pickCamera = (camera: Camera | ICamera) =>
30
+ pick(camera, ["centerX", "centerY", "scale"]);
31
+ const camera$ = new Val<WhiteBoardViewCamera>(pickCamera(this.view.camera));
32
+ this.baseRect$ = baseRect$;
26
33
  this.pageState$ = pageState$;
27
- this.appProxy.sideEffectManager.add(() =>
28
- appProxy.appEmitter.on("pageStateChange", pageState => {
29
- pageState$.setValue(pageState);
30
- })
31
- );
32
- const camera$ = new Val<WhiteBoardViewCamera>(
33
- pick(this.view.camera, ["centerX", "centerY"])
34
- );
35
- this.camera$ = camera$;
36
- this.appProxy.sideEffectManager.add(() =>
34
+ this.baseCamera$ = camera$;
35
+ this.appProxy.sideEffectManager.add(() => [
36
+ appProxy.appEmitter.on("pageStateChange", pageState => pageState$.setValue(pageState)),
37
37
  appProxy.camera$.subscribe(camera => {
38
38
  if (camera) {
39
- camera$.setValue(pick(camera, ["centerX", "centerY"]));
39
+ camera$.setValue(pickCamera(camera));
40
40
  }
41
- })
42
- );
41
+ }),
42
+ appProxy.size$.subscribe(size => {
43
+ if (size) {
44
+ baseRect$.setValue(pick(size, ["width", "height"]));
45
+ }
46
+ }),
47
+ ]);
43
48
  view.disableCameraTransform = true;
44
49
  }
45
50
 
@@ -96,7 +101,7 @@ export class WhiteBoardView implements PageController {
96
101
  return this.appProxy.removeSceneByIndex(needRemoveIndex);
97
102
  };
98
103
 
99
- public setRect(rect: Omit<TeleBoxRect, "x" | "y">) {
104
+ public setBaseRect(rect: Omit<TeleBoxRect, "x" | "y">) {
100
105
  this.appProxy.updateSize(rect.width, rect.height);
101
106
  }
102
107
  }
@@ -1,9 +1,8 @@
1
1
  import { callbacks } from "./callback";
2
2
  import { emitter } from "./InternalEmitter";
3
3
  import { Events, MagixEventName } from "./constants";
4
- import { isEqual, omit } from "lodash";
5
4
  import { setViewFocusScenePath } from "./Utils/Common";
6
- import type { AnimationMode, Camera, Event } from "white-web-sdk";
5
+ import type { Event } from "white-web-sdk";
7
6
  import type { AppManager } from "./AppManager";
8
7
  import type { TeleBoxState } from "@netless/telebox-insider";
9
8
 
@@ -50,14 +49,6 @@ export class AppListeners {
50
49
  this.setMainViewScenePathHandler(data.payload);
51
50
  break;
52
51
  }
53
- case Events.MoveCamera: {
54
- this.moveCameraHandler(data.payload);
55
- break;
56
- }
57
- case Events.MoveCameraToContain: {
58
- this.moveCameraToContainHandler(data.payload);
59
- break;
60
- }
61
52
  case Events.CursorMove: {
62
53
  this.cursorMoveHandler(data.payload);
63
54
  break;
@@ -102,17 +93,6 @@ export class AppListeners {
102
93
  callbacks.emit("mainViewScenePathChange", nextScenePath);
103
94
  };
104
95
 
105
- private moveCameraHandler = (
106
- payload: Camera & { animationMode?: AnimationMode | undefined }
107
- ) => {
108
- if (isEqual(omit(payload, ["animationMode"]), { ...this.manager.mainView.camera })) return;
109
- this.manager.mainView.moveCamera(payload);
110
- };
111
-
112
- private moveCameraToContainHandler = (payload: any) => {
113
- this.manager.mainView.moveCameraToContain(payload);
114
- };
115
-
116
96
  private cursorMoveHandler = (payload: any) => {
117
97
  emitter.emit("cursorMove", payload);
118
98
  };
package/src/AppManager.ts CHANGED
@@ -409,7 +409,7 @@ export class AppManager {
409
409
  };
410
410
 
411
411
  public addAppsChangeListener = () => {
412
- this.refresher?.add("apps", () => {
412
+ this.refresher.add("apps", () => {
413
413
  return safeListenPropsUpdated(
414
414
  () => this.attributes.apps,
415
415
  () => {
@@ -800,6 +800,7 @@ export class AppManager {
800
800
  }
801
801
 
802
802
  public async onReconnected() {
803
+ this.attributesUpdateCallback(this.attributes.apps);
803
804
  const appProxies = Array.from(this.appProxies.values());
804
805
  const reconnected = appProxies.map(appProxy => {
805
806
  return appProxy.onReconnected();
package/src/BoxManager.ts CHANGED
@@ -3,6 +3,7 @@ import { debounce } from "lodash";
3
3
  import { SideEffectManager } from "side-effect-manager";
4
4
  import { TELE_BOX_STATE, TeleBoxManager } from "@netless/telebox-insider";
5
5
  import { WindowManager } from "./index";
6
+ import type { Writeable } from "./typings";
6
7
  import type { BoxEmitterType } from "./BoxEmitter";
7
8
  import type { AddAppOptions } from "./index";
8
9
  import type {
@@ -20,7 +21,6 @@ import type { View } from "white-web-sdk";
20
21
  import type { CallbacksType } from "./callback";
21
22
  import type { EmitterType } from "./InternalEmitter";
22
23
  import type { AppState } from "./App/type";
23
- import { Val } from "value-enhancer";
24
24
 
25
25
  export { TELE_BOX_STATE };
26
26
 
@@ -49,7 +49,8 @@ export type CreateTeleBoxManagerConfig = {
49
49
  collectorStyles?: Partial<CSSStyleDeclaration>;
50
50
  prefersColorScheme?: TeleBoxColorScheme;
51
51
  stageRatio?: number;
52
- highlightStage?: boolean;
52
+ containerStyle?: string;
53
+ stageStyle?: string;
53
54
  };
54
55
 
55
56
  export type BoxManagerContext = {
@@ -92,8 +93,6 @@ export class BoxManager {
92
93
  public teleBoxManager: TeleBoxManager;
93
94
  protected sideEffectManager: SideEffectManager;
94
95
 
95
- public mainViewElement$ = new Val<HTMLElement | undefined>(undefined);
96
-
97
96
  constructor(
98
97
  private context: BoxManagerContext,
99
98
  createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig
@@ -172,28 +171,12 @@ export class BoxManager {
172
171
  this.teleBoxManager.events.on("z_index", box => {
173
172
  this.context.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
174
173
  }),
175
- this.teleBoxManager._stageRect$.subscribe(stage => {
176
- this.updateStyle(this.mainViewElement$.value, stage);
177
- emitter.emit("playgroundSizeChange", stage);
178
- this.context.notifyContainerRectUpdate(stage);
179
- }),
180
- emitter.on("writableChange", isWritable => {
181
- this.teleBoxManager.setHighlightStage(isWritable);
182
- }),
183
174
  emitter.on("containerSizeRatioUpdate", ratio => {
184
175
  this.teleBoxManager._stageRatio$.setValue(ratio);
185
176
  }),
186
177
  ]);
187
178
  }
188
179
 
189
- private updateStyle = (element: HTMLElement | undefined, rect: TeleBoxRect) => {
190
- if (!element) return;
191
- element.style.width = rect.width + "px";
192
- element.style.height = rect.height + "px";
193
- element.style.left = rect.x + "px";
194
- element.style.top = rect.y + "px";
195
- }
196
-
197
180
  private get canOperate() {
198
181
  return this.context.canOperate();
199
182
  }
@@ -232,7 +215,8 @@ export class BoxManager {
232
215
 
233
216
  public createBox(params: CreateBoxParams): ReadonlyTeleBox | undefined {
234
217
  if (!this.teleBoxManager) return;
235
- let { minwidth = MIN_WIDTH, minheight = MIN_HEIGHT } = params.app.config ?? {};
218
+ // eslint-disable-next-line prefer-const
219
+ let { minwidth = MIN_WIDTH, minheight = MIN_HEIGHT, enableShadowDOM = true } = params.app.config ?? {};
236
220
  const { width, height } = params.app.config ?? {};
237
221
  const title = params.options?.title || params.appId;
238
222
  const rect = this.teleBoxManager.rootRect;
@@ -252,6 +236,7 @@ export class BoxManager {
252
236
  width,
253
237
  height,
254
238
  id: params.appId,
239
+ enableShadowDOM,
255
240
  };
256
241
  const box = this.teleBoxManager.create(createBoxConfig, params.smartPosition);
257
242
  this.context.emitter.emit(`${params.appId}${Events.WindowCreated}` as any);
@@ -262,14 +247,21 @@ export class BoxManager {
262
247
  createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig
263
248
  ): TeleBoxManager {
264
249
  const root = WindowManager.playground;
265
- const initManagerState: TeleBoxManagerConfig = {
250
+ const initManagerState: Writeable<TeleBoxManagerConfig> = {
266
251
  stageRatio: createTeleBoxManagerConfig?.stageRatio,
267
252
  root: root,
268
253
  fence: false,
269
254
  prefersColorScheme: createTeleBoxManagerConfig?.prefersColorScheme,
270
- highlightStage: createTeleBoxManagerConfig?.highlightStage,
271
255
  };
272
256
 
257
+ if (createTeleBoxManagerConfig?.containerStyle) {
258
+ initManagerState.containerStyle = createTeleBoxManagerConfig.containerStyle;
259
+ }
260
+
261
+ if (createTeleBoxManagerConfig?.stageStyle) {
262
+ initManagerState.stageStyle = createTeleBoxManagerConfig.stageStyle;
263
+ }
264
+
273
265
  const manager = new TeleBoxManager(initManagerState);
274
266
  if (this.teleBoxManager) {
275
267
  this.teleBoxManager.destroy();
@@ -311,17 +303,15 @@ export class BoxManager {
311
303
  if (!state) return;
312
304
  const box = this.getBox(state.id);
313
305
  if (box) {
314
- this.teleBoxManager.update(
315
- box.id,
316
- {
317
- x: state.position?.x,
318
- y: state.position?.y,
319
- width: state.size?.width || 0.5,
320
- height: state.size?.height || 0.5,
321
- zIndex: state.zIndex,
322
- },
323
- true
324
- );
306
+ if (state.size) {
307
+ box._intrinsicSize$.setValue(state.size, true);
308
+ }
309
+ if (state.position) {
310
+ box._intrinsicCoord$.setValue(state.position, true);
311
+ }
312
+ if (state.zIndex) {
313
+ box._zIndex$.setValue(state.zIndex, true);
314
+ }
325
315
  setTimeout(() => {
326
316
  if (state.focus) {
327
317
  this.teleBoxManager.focusBox(box.id, true);
@@ -338,7 +328,10 @@ export class BoxManager {
338
328
  }
339
329
 
340
330
  public moveBox({ appId, x, y }: MoveBoxParams): void {
341
- this.teleBoxManager.update(appId, { x, y }, true);
331
+ const box = this.getBox(appId);
332
+ if (box) {
333
+ box._intrinsicCoord$.setValue({ x, y}, true);
334
+ }
342
335
  }
343
336
 
344
337
  public focusBox({ appId }: AppId, skipUpdate = true): void {
@@ -346,7 +339,10 @@ export class BoxManager {
346
339
  }
347
340
 
348
341
  public resizeBox({ appId, width, height, skipUpdate }: ResizeBoxParams): void {
349
- this.teleBoxManager.update(appId, { width, height }, skipUpdate);
342
+ const box = this.getBox(appId);
343
+ if (box) {
344
+ box._intrinsicSize$.setValue({ width, height }, skipUpdate);
345
+ }
350
346
  }
351
347
 
352
348
  public setBoxMinSize(params: SetBoxMinSizeParams): void {
@@ -21,3 +21,8 @@ export const BuiltinApps = {
21
21
  DocsViewer: AppDocsViewer.kind as string,
22
22
  MediaPlayer: AppMediaPlayer.kind as string,
23
23
  };
24
+
25
+ export const BuiltinAppsMap = {
26
+ [BuiltinApps.DocsViewer]: AppDocsViewer,
27
+ [BuiltinApps.MediaPlayer]: AppMediaPlayer,
28
+ }
package/src/Helper.ts CHANGED
@@ -7,7 +7,8 @@ import { WindowManager } from "./index";
7
7
  import type { Room, RoomMember } from "white-web-sdk";
8
8
 
9
9
  export const setupWrapper = (
10
- root: HTMLElement
10
+ root: HTMLElement,
11
+ target: HTMLElement
11
12
  ): {
12
13
  playground: HTMLDivElement;
13
14
  mainViewElement: HTMLDivElement;
@@ -17,7 +18,7 @@ export const setupWrapper = (
17
18
 
18
19
  const mainViewElement = document.createElement("div");
19
20
  mainViewElement.className = "netless-window-manager-main-view";
20
- playground.appendChild(mainViewElement);
21
+ target.appendChild(mainViewElement);
21
22
  root.appendChild(playground);
22
23
 
23
24
  return { playground, mainViewElement };
@@ -17,6 +17,9 @@ export const genAppId = async (kind: string) => {
17
17
  };
18
18
 
19
19
  export const setViewFocusScenePath = (view: View, focusScenePath: string) => {
20
+ if ((view as any).didRelease) {
21
+ return;
22
+ }
20
23
  if (view.focusScenePath !== focusScenePath) {
21
24
  view.focusScenePath = focusScenePath;
22
25
  return view;
@@ -30,16 +30,12 @@ export class CameraSynchronizer {
30
30
  this.remoteCamera = camera;
31
31
  this.remoteSize = size;
32
32
  if (this.remoteSize && this.rect) {
33
- let scale: number;
34
- if (size.width < size.height) {
35
- scale = this.rect.width / size.width;
36
- } else {
37
- scale = this.rect.height / size.height;
38
- }
39
- const nextScale = camera.scale * scale;
33
+ const wScale = this.rect.width / size.width;
34
+ const hScale = this.rect.height / size.height;
35
+ const nextScale = camera.scale * Math.min(wScale, hScale);
40
36
  const config: Partial<Camera> & { animationMode: AnimationMode } = {
41
37
  scale: nextScale,
42
- animationMode: AnimationMode.Immediately,
38
+ animationMode: AnimationMode.Continuous,
43
39
  }
44
40
  if (camera.centerX !== null) {
45
41
  config.centerX = camera.centerX;
@@ -59,7 +55,7 @@ export class CameraSynchronizer {
59
55
  const nextScale = this.remoteCamera.scale * scale;
60
56
  this.view?.moveCamera({
61
57
  scale: nextScale,
62
- animationMode: AnimationMode.Immediately,
58
+ animationMode: AnimationMode.Continuous,
63
59
  })
64
60
  }
65
61
  }
@@ -4,7 +4,7 @@ import { debounce, get, isEqual } from "lodash";
4
4
  import { emitter } from "../InternalEmitter";
5
5
  import { Events } from "../constants";
6
6
  import { Fields } from "../AttributesDelegate";
7
- import { reaction, toJS } from "white-web-sdk";
7
+ import { AnimationMode, reaction, toJS } from "white-web-sdk";
8
8
  import { releaseView, setScenePath, setViewFocusScenePath } from "../Utils/Common";
9
9
  import { SideEffectManager } from "side-effect-manager";
10
10
  import { Val } from "value-enhancer";
@@ -211,12 +211,14 @@ export class MainViewProxy {
211
211
  public rebind(): void {
212
212
  const divElement = this.mainView.divElement;
213
213
  const disableCameraTransform = this.mainView.disableCameraTransform;
214
+ const camera = { ...this.mainView.camera };
214
215
  this.stop();
215
216
  releaseView(this.mainView);
216
217
  this.removeMainViewListener();
217
218
  this.mainView = this.createMainView();
218
219
  this.mainView.disableCameraTransform = disableCameraTransform;
219
220
  this.mainView.divElement = divElement;
221
+ this.mainView.moveCamera({ ...camera, animationMode: AnimationMode.Immediately });
220
222
  this.addMainViewListener();
221
223
  this.start();
222
224
  }
package/src/callback.ts CHANGED
@@ -20,6 +20,7 @@ export type PublicEvent = {
20
20
  ready: undefined; // 所有 APP 创建完毕时触发
21
21
  sceneStateChange: SceneState;
22
22
  pageStateChange: PageState;
23
+ appClose: { appId: string; kind: string, error?: Error };
23
24
  };
24
25
 
25
26
  export type CallbacksType = Emittery<PublicEvent>;
package/src/constants.ts CHANGED
@@ -10,8 +10,6 @@ export enum Events {
10
10
  SetMainViewSceneIndex = "SetMainViewSceneIndex",
11
11
  SetAppFocusIndex = "SetAppFocusIndex",
12
12
  SwitchViewsToFreedom = "SwitchViewsToFreedom",
13
- MoveCamera = "MoveCamera",
14
- MoveCameraToContain = "MoveCameraToContain",
15
13
  CursorMove = "CursorMove",
16
14
  RootDirRemoved = "RootDirRemoved",
17
15
  Refresh = "Refresh",