@netless/window-manager 0.3.18 → 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.
@@ -2,8 +2,7 @@ import { AppAttributes } from "./constants";
2
2
  import { get, pick } from "lodash";
3
3
  import { setViewFocusScenePath } from "./Utils/Common";
4
4
  import type { AddAppParams, AppSyncAttributes } from "./index";
5
- import type { Camera, Size } from "white-web-sdk";
6
- import type { AppManager } from "./AppManager";
5
+ import type { Camera, Size, View } from "white-web-sdk";
7
6
  import type { Cursor } from "./Cursor/Cursor";
8
7
 
9
8
  export enum Fields {
@@ -17,7 +16,7 @@ export enum Fields {
17
16
  Cursors = "cursors",
18
17
  Position = "position",
19
18
  CursorState = "cursorState",
20
- FullPath = "fullPath"
19
+ FullPath = "fullPath",
21
20
  }
22
21
 
23
22
  export type Apps = {
@@ -33,15 +32,29 @@ export type Position = {
33
32
 
34
33
  export type PositionType = "main" | "app";
35
34
 
35
+ export type StoreContext = {
36
+ getAttributes: () => any;
37
+ safeUpdateAttributes: (keys: string[], value: any) => void;
38
+ safeSetAttributes: (attributes: any) => void;
39
+ }
36
40
  export class AttributesDelegate {
37
- constructor(private manager: AppManager) {}
41
+
42
+ constructor(private context: StoreContext) {}
43
+
44
+ public setContext(context: StoreContext) {
45
+ this.context = context;
46
+ }
47
+
48
+ public get attributes() {
49
+ return this.context.getAttributes();
50
+ }
38
51
 
39
52
  public apps(): Apps {
40
- return get(this.manager.attributes, [Fields.Apps]);
53
+ return get(this.attributes, [Fields.Apps]);
41
54
  }
42
55
 
43
56
  public get focus(): string | undefined {
44
- return get(this.manager.attributes, [Fields.Focus]);
57
+ return get(this.attributes, [Fields.Focus]);
45
58
  }
46
59
 
47
60
  public getAppAttributes(id: string): AppSyncAttributes {
@@ -53,13 +66,17 @@ export class AttributesDelegate {
53
66
  }
54
67
 
55
68
  public getMaximized() {
56
- return get(this.manager.attributes, ["maximized"])
69
+ return get(this.attributes, ["maximized"]);
70
+ }
71
+
72
+ public getMinimized() {
73
+ return get(this.attributes, ["minimized"]);
57
74
  }
58
75
 
59
76
  public setupAppAttributes(params: AddAppParams, id: string, isDynamicPPT: boolean) {
60
- const attributes = this.manager.attributes;
77
+ const attributes = this.attributes;
61
78
  if (!attributes.apps) {
62
- this.manager.safeSetAttributes({ apps: {} });
79
+ this.context.safeSetAttributes({ apps: {} });
63
80
  }
64
81
  const attrNames = ["scenePath", "title"];
65
82
  if (!isDynamicPPT) {
@@ -70,32 +87,32 @@ export class AttributesDelegate {
70
87
  if (typeof params.src === "string") {
71
88
  attrs.src = params.src;
72
89
  }
73
- this.manager.safeUpdateAttributes([Fields.Apps, id], attrs);
74
- this.manager.safeUpdateAttributes([Fields.Apps, id, Fields.State], {
90
+ attrs.createdAt = Date.now();
91
+ this.context.safeUpdateAttributes([Fields.Apps, id], attrs);
92
+ this.context.safeUpdateAttributes([Fields.Apps, id, Fields.State], {
75
93
  [AppAttributes.Size]: {},
76
94
  [AppAttributes.Position]: {},
77
95
  [AppAttributes.SceneIndex]: 0,
78
- [AppAttributes.ZIndex]: 100,
79
96
  });
80
97
  }
81
98
 
82
99
  public updateAppState(appId: string, stateName: AppAttributes, state: any) {
83
- if (get(this.manager.attributes, [Fields.Apps, appId, Fields.State])) {
84
- this.manager.safeUpdateAttributes([Fields.Apps, appId, Fields.State, stateName], state);
100
+ if (get(this.attributes, [Fields.Apps, appId, Fields.State])) {
101
+ this.context.safeUpdateAttributes([Fields.Apps, appId, Fields.State, stateName], state);
85
102
  }
86
103
  }
87
104
 
88
105
  public cleanAppAttributes(id: string) {
89
- this.manager.safeUpdateAttributes([Fields.Apps, id], undefined);
90
- this.manager.safeSetAttributes({ [id]: undefined });
91
- const focus = this.manager.attributes[Fields.Focus];
106
+ this.context.safeUpdateAttributes([Fields.Apps, id], undefined);
107
+ this.context.safeSetAttributes({ [id]: undefined });
108
+ const focus = this.attributes[Fields.Focus];
92
109
  if (focus === id) {
93
110
  this.cleanFocus();
94
111
  }
95
112
  }
96
113
 
97
114
  public cleanFocus() {
98
- this.manager.safeSetAttributes({ [Fields.Focus]: undefined });
115
+ this.context.safeSetAttributes({ [Fields.Focus]: undefined });
99
116
  }
100
117
 
101
118
  public getAppSceneIndex(id: string) {
@@ -107,82 +124,79 @@ export class AttributesDelegate {
107
124
  }
108
125
 
109
126
  public getMainViewScenePath() {
110
- return this.manager.attributes["_mainScenePath"];
127
+ return this.attributes["_mainScenePath"];
111
128
  }
112
129
 
113
130
  public getMainViewSceneIndex() {
114
- return this.manager.attributes["_mainSceneIndex"];
131
+ return this.attributes["_mainSceneIndex"];
115
132
  }
116
133
 
117
134
  public getBoxState() {
118
- return this.manager.attributes[Fields.BoxState];
135
+ return this.attributes[Fields.BoxState];
119
136
  }
120
137
 
121
138
  public setMainViewScenePath(scenePath: string) {
122
- this.manager.safeSetAttributes({ _mainScenePath: scenePath });
139
+ this.context.safeSetAttributes({ _mainScenePath: scenePath });
123
140
  }
124
141
 
125
142
  public setMainViewSceneIndex(index: number) {
126
- this.manager.safeSetAttributes({ _mainSceneIndex: index });
143
+ this.context.safeSetAttributes({ _mainSceneIndex: index });
127
144
  }
128
145
 
129
146
  public getMainViewCamera(): MainViewCamera {
130
- return get(this.manager.attributes, [Fields.MainViewCamera]);
147
+ return get(this.attributes, [Fields.MainViewCamera]);
131
148
  }
132
149
 
133
150
  public getMainViewSize(): MainViewSize {
134
- return get(this.manager.attributes, [Fields.MainViewSize]);
151
+ return get(this.attributes, [Fields.MainViewSize]);
135
152
  }
136
153
 
137
- public setMainViewCamera(camera: Camera & { id: string } | undefined) {
138
- this.manager.safeSetAttributes({ [Fields.MainViewCamera]: { ...camera } });
154
+ public setMainViewCamera(camera: (Camera & { id: string }) | undefined) {
155
+ this.context.safeSetAttributes({ [Fields.MainViewCamera]: { ...camera } });
139
156
  }
140
157
 
141
- public setMainViewSize(size: Size & { id: string } | undefined) {
142
- this.manager.safeSetAttributes({ [Fields.MainViewSize]: { ...size } });
158
+ public setMainViewSize(size: (Size & { id: string }) | undefined) {
159
+ this.context.safeSetAttributes({ [Fields.MainViewSize]: { ...size } });
143
160
  }
144
161
 
145
162
  public setAppFocus(appId: string, focus: boolean) {
146
163
  if (focus) {
147
- this.manager.safeSetAttributes({ [Fields.Focus]: appId });
164
+ this.context.safeSetAttributes({ [Fields.Focus]: appId });
148
165
  } else {
149
- this.manager.safeSetAttributes({ [Fields.Focus]: undefined });
166
+ this.context.safeSetAttributes({ [Fields.Focus]: undefined });
150
167
  }
151
168
  }
152
169
 
153
170
  public updateCursor(uid: string, position: Position) {
154
- if (!get(this.manager.attributes, [Fields.Cursors])) {
155
- this.manager.safeUpdateAttributes([Fields.Cursors], {});
171
+ if (!get(this.attributes, [Fields.Cursors])) {
172
+ this.context.safeUpdateAttributes([Fields.Cursors], {});
156
173
  }
157
- if (!get(this.manager.attributes, [Fields.Cursors, uid])) {
158
- this.manager.safeUpdateAttributes([Fields.Cursors, uid], {});
174
+ if (!get(this.attributes, [Fields.Cursors, uid])) {
175
+ this.context.safeUpdateAttributes([Fields.Cursors, uid], {});
159
176
  }
160
- this.manager.safeUpdateAttributes([Fields.Cursors, uid, Fields.Position], position);
177
+ this.context.safeUpdateAttributes([Fields.Cursors, uid, Fields.Position], position);
161
178
  }
162
179
 
163
180
  public updateCursorState(uid: string, cursorState: string | undefined) {
164
- if (!get(this.manager.attributes, [Fields.Cursors, uid])) {
165
- this.manager.safeUpdateAttributes([Fields.Cursors, uid], {});
181
+ if (!get(this.attributes, [Fields.Cursors, uid])) {
182
+ this.context.safeUpdateAttributes([Fields.Cursors, uid], {});
166
183
  }
167
- this.manager.safeUpdateAttributes(
168
- [Fields.Cursors, uid, Fields.CursorState],
169
- cursorState
170
- );
184
+ this.context.safeUpdateAttributes([Fields.Cursors, uid, Fields.CursorState], cursorState);
171
185
  }
172
186
 
173
187
  public getCursorState(uid: string) {
174
- return get(this.manager.attributes, [Fields.Cursors, uid, Fields.CursorState]);
188
+ return get(this.attributes, [Fields.Cursors, uid, Fields.CursorState]);
175
189
  }
176
190
 
177
191
  public cleanCursor(uid: string) {
178
- this.manager.safeUpdateAttributes([Fields.Cursors, uid], undefined);
192
+ this.context.safeUpdateAttributes([Fields.Cursors, uid], undefined);
179
193
  }
180
194
 
181
195
  // TODO 状态中保存一个 SceneName 优化性能
182
- public setMainViewFocusPath() {
196
+ public setMainViewFocusPath(mainView: View) {
183
197
  const scenePath = this.getMainViewScenePath();
184
198
  if (scenePath) {
185
- setViewFocusScenePath(this.manager.mainView, scenePath);
199
+ setViewFocusScenePath(mainView, scenePath);
186
200
  }
187
201
  }
188
202
  }
@@ -191,15 +205,28 @@ export type MainViewSize = {
191
205
  id: string;
192
206
  width: number;
193
207
  height: number;
194
- }
208
+ };
195
209
 
196
210
  export type MainViewCamera = {
197
211
  id: string;
198
212
  centerX: number;
199
213
  centerY: number;
200
214
  scale: number;
201
- }
215
+ };
202
216
 
203
217
  export type Cursors = {
204
218
  [key: string]: Cursor;
205
- }
219
+ };
220
+
221
+
222
+ export const store = new AttributesDelegate({
223
+ getAttributes: () => {
224
+ throw new Error("getAttributes not implemented")
225
+ },
226
+ safeSetAttributes: () => {
227
+ throw new Error("safeSetAttributes not implemented")
228
+ },
229
+ safeUpdateAttributes: () => {
230
+ throw new Error("safeUpdateAttributes not implemented")
231
+ },
232
+ });
@@ -27,11 +27,11 @@ export class Context {
27
27
  }
28
28
 
29
29
  public updateManagerRect() {
30
- this.manager.boxManager.updateManagerRect();
30
+ this.manager.boxManager?.updateManagerRect();
31
31
  }
32
32
 
33
33
  public blurFocusBox() {
34
- this.manager.boxManager.blurAllBox();
34
+ this.manager.boxManager?.blurAllBox();
35
35
  }
36
36
 
37
37
  public switchAppToWriter(id: string) {
package/src/Base/index.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { AppManager } from "../AppManager";
2
- import { AttributesDelegate } from "../AttributesDelegate";
2
+ import { store } from "../AttributesDelegate";
3
3
  import { createContext } from "./Context";
4
4
 
5
5
  export class Base {
6
- public store = new AttributesDelegate(this.manager);
6
+ public store = store;
7
7
  public context = createContext(this.manager);
8
8
 
9
9
  constructor(public manager: AppManager) {}
package/src/BoxManager.ts CHANGED
@@ -1,22 +1,22 @@
1
- import { callbacks, emitter, WindowManager } from "./index";
2
- import { debounce, maxBy } from "lodash";
3
1
  import { AppAttributes, DEFAULT_COLLECTOR_STYLE, Events, MIN_HEIGHT, MIN_WIDTH } from "./constants";
2
+ import { debounce, maxBy } from "lodash";
4
3
  import {
5
4
  TELE_BOX_MANAGER_EVENT,
6
5
  TELE_BOX_STATE,
7
6
  TeleBoxCollector,
8
7
  TeleBoxManager,
9
8
  } from "@netless/telebox-insider";
10
- import type { AddAppOptions, AppInitState } from "./index";
9
+ import { WindowManager } from "./index";
10
+ import type { AddAppOptions, AppInitState, EmitterType, CallbacksType } from "./index";
11
11
  import type {
12
12
  TeleBoxManagerUpdateConfig,
13
13
  TeleBoxManagerCreateConfig,
14
14
  ReadonlyTeleBox,
15
15
  TeleBoxManagerConfig,
16
16
  TeleBoxColorScheme,
17
+ TeleBoxRect,
17
18
  } from "@netless/telebox-insider";
18
19
  import type Emittery from "emittery";
19
- import type { AppManager } from "./AppManager";
20
20
  import type { NetlessApp } from "./typings";
21
21
  import type { View } from "white-web-sdk";
22
22
 
@@ -48,31 +48,63 @@ export type CreateTeleBoxManagerConfig = {
48
48
  prefersColorScheme?: TeleBoxColorScheme;
49
49
  };
50
50
 
51
+ export type BoxManagerContext = {
52
+ safeSetAttributes: (attributes: any) => void;
53
+ getMainView: () => View;
54
+ updateAppState: (appId: string, field: AppAttributes, value: any) => void;
55
+ emitter: EmitterType;
56
+ callbacks: CallbacksType;
57
+ canOperate: () => boolean;
58
+ notifyContainerRectUpdate: (rect: TeleBoxRect) => void;
59
+ cleanFocus: () => void;
60
+ };
61
+
62
+ export const createBoxManager = (
63
+ manager: WindowManager,
64
+ callbacks: CallbacksType,
65
+ emitter: EmitterType,
66
+ options: CreateTeleBoxManagerConfig
67
+ ) => {
68
+ return new BoxManager(
69
+ {
70
+ safeSetAttributes: (attributes: any) => manager.safeSetAttributes(attributes),
71
+ getMainView: () => manager.mainView,
72
+ updateAppState: (...args) => manager.appManager?.store.updateAppState(...args),
73
+ canOperate: () => manager.canOperate,
74
+ notifyContainerRectUpdate: (rect: TeleBoxRect) =>
75
+ manager.appManager?.notifyContainerRectUpdate(rect),
76
+ cleanFocus: () => manager.appManager?.store.cleanFocus(),
77
+ callbacks,
78
+ emitter,
79
+ },
80
+ options
81
+ );
82
+ };
83
+
51
84
  export class BoxManager {
52
85
  public teleBoxManager: TeleBoxManager;
53
- public appBoxMap: Map<string, string> = new Map();
54
- private mainView = this.manager.mainView;
55
86
 
56
87
  constructor(
57
- private manager: AppManager,
58
- createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig
88
+ private context: BoxManagerContext,
89
+ private createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig
59
90
  ) {
91
+ const { emitter, callbacks } = context;
60
92
  this.teleBoxManager = this.setupBoxManager(createTeleBoxManagerConfig);
61
93
  this.teleBoxManager.events.on(TELE_BOX_MANAGER_EVENT.State, state => {
62
94
  if (state) {
63
- callbacks.emit("boxStateChange", state);
64
- emitter.emit("boxStateChange", state);
95
+ this.context.callbacks.emit("boxStateChange", state);
96
+ this.context.emitter.emit("boxStateChange", state);
65
97
  }
66
98
  });
67
99
  this.teleBoxManager.events.on("minimized", minimized => {
68
- this.manager.safeSetAttributes({ minimized });
100
+ this.context.safeSetAttributes({ minimized });
69
101
  if (minimized) {
70
- this.manager.store.cleanFocus();
102
+ this.context.cleanFocus();
71
103
  this.blurAllBox();
72
104
  }
73
105
  });
74
106
  this.teleBoxManager.events.on("maximized", maximized => {
75
- this.manager.safeSetAttributes({ maximized });
107
+ this.context.safeSetAttributes({ maximized });
76
108
  });
77
109
  this.teleBoxManager.events.on("removed", boxes => {
78
110
  boxes.forEach(box => {
@@ -97,7 +129,7 @@ export class BoxManager {
97
129
  );
98
130
  this.teleBoxManager.events.on("focused", box => {
99
131
  if (box) {
100
- if (this.manager.canOperate) {
132
+ if (this.canOperate) {
101
133
  emitter.emit("focus", { appId: box.id });
102
134
  } else {
103
135
  this.teleBoxManager.blurBox(box.id);
@@ -111,10 +143,19 @@ export class BoxManager {
111
143
  callbacks.emit("prefersColorSchemeChange", colorScheme);
112
144
  });
113
145
  this.teleBoxManager.events.on("z_index", box => {
114
- this.manager.store.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
146
+ console.log("on z_index", box.id, box.zIndex);
147
+ this.context.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
115
148
  });
116
149
  }
117
150
 
151
+ private get mainView() {
152
+ return this.context.getMainView();
153
+ }
154
+
155
+ private get canOperate() {
156
+ return this.context.canOperate();
157
+ }
158
+
118
159
  public get boxState() {
119
160
  return this.teleBoxManager.state;
120
161
  }
@@ -135,6 +176,10 @@ export class BoxManager {
135
176
  return this.teleBoxManager.prefersColorScheme;
136
177
  }
137
178
 
179
+ public get boxSize() {
180
+ return this.teleBoxManager.boxes.length;
181
+ }
182
+
138
183
  public createBox(params: CreateBoxParams): void {
139
184
  if (!this.teleBoxManager) return;
140
185
  let { minwidth = MIN_WIDTH, minheight = MIN_HEIGHT } = params.app.config ?? {};
@@ -159,14 +204,14 @@ export class BoxManager {
159
204
  id: params.appId,
160
205
  };
161
206
  this.teleBoxManager.create(createBoxConfig, params.smartPosition);
162
- emitter.emit(`${params.appId}${Events.WindowCreated}` as any);
207
+ this.context.emitter.emit(`${params.appId}${Events.WindowCreated}` as any);
163
208
  }
164
209
 
165
210
  public setBoxInitState(appId: string): void {
166
211
  const box = this.teleBoxManager.queryOne({ id: appId });
167
212
  if (box) {
168
213
  if (box.state === TELE_BOX_STATE.Maximized) {
169
- emitter.emit("resize", {
214
+ this.context.emitter.emit("resize", {
170
215
  appId: appId,
171
216
  x: box.x,
172
217
  y: box.y,
@@ -193,24 +238,30 @@ export class BoxManager {
193
238
  fence: false,
194
239
  prefersColorScheme: createTeleBoxManagerConfig?.prefersColorScheme,
195
240
  };
196
- const container = createTeleBoxManagerConfig?.collectorContainer || WindowManager.wrapper;
197
- const styles = {
198
- ...DEFAULT_COLLECTOR_STYLE,
199
- ...createTeleBoxManagerConfig?.collectorStyles,
200
- };
201
- const teleBoxCollector = new TeleBoxCollector({
202
- styles: styles,
203
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
204
- }).mount(container!);
205
- initManagerState.collector = teleBoxCollector;
241
+
206
242
  const manager = new TeleBoxManager(initManagerState);
207
243
  if (this.teleBoxManager) {
208
244
  this.teleBoxManager.destroy();
209
245
  }
210
246
  this.teleBoxManager = manager;
247
+ const container = createTeleBoxManagerConfig?.collectorContainer || WindowManager.wrapper;
248
+ if (container) {
249
+ this.setCollectorContainer(container);
250
+ }
211
251
  return manager;
212
252
  }
213
253
 
254
+ public setCollectorContainer(container: HTMLElement) {
255
+ const styles = {
256
+ ...DEFAULT_COLLECTOR_STYLE,
257
+ ...this.createTeleBoxManagerConfig?.collectorStyles,
258
+ };
259
+ const collector = new TeleBoxCollector({
260
+ styles
261
+ }).mount(container);
262
+ this.teleBoxManager.setCollector(collector);
263
+ }
264
+
214
265
  public getBox(appId: string): ReadonlyTeleBox | undefined {
215
266
  return this.teleBoxManager.queryOne({ id: appId });
216
267
  }
@@ -251,7 +302,7 @@ export class BoxManager {
251
302
  );
252
303
  setTimeout(() => {
253
304
  if (state.focus) {
254
- this.teleBoxManager.focusBox(box.id, true)
305
+ this.teleBoxManager.focusBox(box.id, true);
255
306
  }
256
307
  if (state.maximized != null) {
257
308
  this.teleBoxManager.setMaximized(Boolean(state.maximized), true);
@@ -260,7 +311,7 @@ export class BoxManager {
260
311
  this.teleBoxManager.setMinimized(Boolean(state.minimized), true);
261
312
  }
262
313
  }, 50);
263
- callbacks.emit("boxStateChange", this.teleBoxManager.state);
314
+ this.context.callbacks.emit("boxStateChange", this.teleBoxManager.state);
264
315
  }
265
316
  }
266
317
 
@@ -269,7 +320,7 @@ export class BoxManager {
269
320
  if (rect && rect.width > 0 && rect.height > 0) {
270
321
  const containerRect = { x: 0, y: 0, width: rect.width, height: rect.height };
271
322
  this.teleBoxManager.setContainerRect(containerRect);
272
- this.manager.notifyContainerRectUpdate(this.teleBoxManager.containerRect);
323
+ this.context.notifyContainerRectUpdate(this.teleBoxManager.containerRect);
273
324
  }
274
325
  }
275
326
 
@@ -309,7 +360,9 @@ export class BoxManager {
309
360
  }
310
361
 
311
362
  public setMaximized(maximized: boolean) {
312
- this.teleBoxManager.setMaximized(maximized, true);
363
+ if (maximized !== this.maximized) {
364
+ this.teleBoxManager.setMaximized(maximized, true);
365
+ }
313
366
  }
314
367
 
315
368
  public setMinimized(minimized: boolean, skipUpdate = true) {
@@ -334,6 +387,10 @@ export class BoxManager {
334
387
  this.teleBoxManager.setPrefersColorScheme(colorScheme);
335
388
  }
336
389
 
390
+ public setZIndex(id: string, zIndex: number, skipUpdate = true) {
391
+ this.teleBoxManager.update(id, { zIndex }, skipUpdate);
392
+ }
393
+
337
394
  public destroy() {
338
395
  this.teleBoxManager.destroy();
339
396
  }
@@ -70,13 +70,20 @@ export class Cursor extends Base {
70
70
  }
71
71
 
72
72
  private moveCursor(cursor: Position, rect: DOMRect, view: any) {
73
- const { x, y } = cursor;
73
+ const { x, y, type } = cursor;
74
74
  const point = view?.screen.convertPointToScreen(x, y);
75
75
  if (point) {
76
- const translateX = point.x + rect.x - 2;
77
- const translateY = point.y + rect.y - 18;
76
+ let translateX = point.x - 2;
77
+ let translateY = point.y - 18;
78
+ if (type === "app") {
79
+ const wrapperRect = this.cursorManager.wrapperRect;
80
+ if (wrapperRect) {
81
+ translateX = translateX + rect.x - wrapperRect.x;
82
+ translateY = translateY + rect.y - wrapperRect.y;
83
+ }
84
+ }
78
85
  if (point.x < 0 || point.x > rect.width || point.y < 0 || point.y > rect.height) {
79
- this.component?.$set({ visible: false });
86
+ this.component?.$set({ visible: false, x: translateX, y: translateY });
80
87
  } else {
81
88
  this.component?.$set({ visible: true, x: translateX, y: translateY });
82
89
  }
@@ -149,7 +156,7 @@ export class Cursor extends Base {
149
156
  private async createCursor() {
150
157
  if (this.member && this.wrapper) {
151
158
  this.component = new App({
152
- target: document.documentElement,
159
+ target: this.wrapper,
153
160
  props: this.initProps(),
154
161
  });
155
162
  }
@@ -31,17 +31,24 @@ export class CursorManager extends Base {
31
31
  this.roomMembers = this.appManager.room?.state.roomMembers;
32
32
  const wrapper = WindowManager.wrapper;
33
33
  if (wrapper) {
34
- wrapper.addEventListener("mousemove", this.mouseMoveListener);
35
- wrapper.addEventListener("touchstart", this.touchMoveListener);
36
- wrapper.addEventListener("touchmove", this.touchMoveListener);
37
- wrapper.addEventListener("mouseleave", this.mouseLeaveListener);
38
- wrapper.addEventListener("touchend", this.mouseLeaveListener);
39
- this.initCursorAttributes();
40
- this.wrapperRect = wrapper.getBoundingClientRect();
41
- this.startReaction(wrapper);
34
+ this.setupWrapper(wrapper);
42
35
  }
43
36
  }
44
37
 
38
+ public setupWrapper(wrapper: HTMLElement) {
39
+ if (this.manager.refresher?.hasReactor("cursors")) {
40
+ this.destroy();
41
+ }
42
+ wrapper.addEventListener("mousemove", this.mouseMoveListener);
43
+ wrapper.addEventListener("touchstart", this.touchMoveListener);
44
+ wrapper.addEventListener("touchmove", this.touchMoveListener);
45
+ wrapper.addEventListener("mouseleave", this.mouseLeaveListener);
46
+ wrapper.addEventListener("touchend", this.mouseLeaveListener);
47
+ this.initCursorAttributes();
48
+ this.wrapperRect = wrapper.getBoundingClientRect();
49
+ this.startReaction(wrapper);
50
+ }
51
+
45
52
  public setMainViewDivElement(div: HTMLDivElement) {
46
53
  this.mainViewElement = div;
47
54
  }
@@ -1,8 +1,8 @@
1
- import { isFunction } from 'lodash';
2
- import { RoomPhase } from 'white-web-sdk';
1
+ import { isFunction, debounce } from "lodash";
2
+ import { log } from "./Utils/log";
3
+ import { RoomPhase } from "white-web-sdk";
3
4
  import type { Room } from "white-web-sdk";
4
- import type { AppManager } from './AppManager';
5
- import { log } from './Utils/log';
5
+ import type { AppManager } from "./AppManager";
6
6
 
7
7
  // 白板重连之后会刷新所有的对象,导致 listener 失效, 所以这里在重连之后重新对所有对象进行监听
8
8
  export class ReconnectRefresher {
@@ -22,9 +22,9 @@ export class ReconnectRefresher {
22
22
  this.onReconnected();
23
23
  }
24
24
  this.phase = phase;
25
- }
25
+ };
26
26
 
27
- private onReconnected = () => {
27
+ private onReconnected = debounce(() => {
28
28
  log("onReconnected refresh reactors");
29
29
  this.releaseDisposers();
30
30
  this.reactors.forEach((func, id) => {
@@ -33,14 +33,14 @@ export class ReconnectRefresher {
33
33
  }
34
34
  });
35
35
  this.manager.notifyReconnected();
36
- }
36
+ }, 3000);
37
37
 
38
38
  private releaseDisposers() {
39
39
  this.disposers.forEach(disposer => {
40
40
  if (isFunction(disposer)) {
41
41
  disposer();
42
42
  }
43
- })
43
+ });
44
44
  this.disposers.clear();
45
45
  }
46
46
 
@@ -64,6 +64,10 @@ export class ReconnectRefresher {
64
64
  }
65
65
  }
66
66
 
67
+ public hasReactor(id: string) {
68
+ return this.reactors.has(id);
69
+ }
70
+
67
71
  public destroy() {
68
72
  this.room?.callbacks.off("onPhaseChanged", this.onPhaseChanged);
69
73
  this.releaseDisposers();
@@ -1,10 +1,10 @@
1
- import { emitter } from '../index';
2
- import { isPlayer } from 'white-web-sdk';
1
+ import { emitter } from "../index";
2
+ import { isPlayer } from "white-web-sdk";
3
+ import type { WindowManager } from '../index';
3
4
  import type { Camera, Room , Player , PlayerSeekingResult } from "white-web-sdk";
4
- import type { AppManager } from "../AppManager";
5
5
 
6
6
  // 修改多窗口状态下一些失效的方法实现到 manager 的 mainview 上, 降低迁移成本
7
- export const replaceRoomFunction = (room: Room, manager: AppManager) => {
7
+ export const replaceRoomFunction = (room: Room, manager: WindowManager) => {
8
8
  if (isPlayer(room)) {
9
9
  const player = room as unknown as Player;
10
10
  const originSeek = player.seekToProgressTime;
@@ -30,7 +30,7 @@ export const replaceRoomFunction = (room: Room, manager: AppManager) => {
30
30
  });
31
31
 
32
32
  room.moveCamera = (camera: Camera) => manager.mainView.moveCamera(camera);
33
- room.moveCameraToContain = (...args) => manager.mainView.moveCameraToContain(...args);
33
+ room.moveCameraToContain = (...args) => manager.moveCameraToContain(...args);
34
34
  room.convertToPointInWorld = (...args) => manager.mainView.convertToPointInWorld(...args);
35
35
  room.setCameraBound = (...args) => manager.mainView.setCameraBound(...args);
36
36
  room.scenePreview = (...args) => manager.mainView.scenePreview(...args);