@netless/window-manager 0.3.23 → 0.3.24

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.
@@ -1,10 +1,8 @@
1
- import { Base } from '../Base';
2
- import { Cursor } from './Cursor';
3
- import { CursorState } from '../constants';
4
- import { compact, debounce, uniq } from 'lodash';
5
- import { Fields } from '../AttributesDelegate';
6
- import { onObjectInserted } from '../Utils/Reactive';
7
- import { WindowManager } from '../index';
1
+ import { Cursor } from "./Cursor";
2
+ import { CursorState, Events } from "../constants";
3
+ import { emitter, WindowManager } from "../index";
4
+ import { throttle } from "lodash";
5
+ import type { CursorMovePayload } from "../index";
8
6
  import type { PositionType } from "../AttributesDelegate";
9
7
  import type { Point, RoomMember, View } from "white-web-sdk";
10
8
  import type { AppManager } from "../AppManager";
@@ -18,110 +16,76 @@ export type MoveCursorParams = {
18
16
  uid: string;
19
17
  x: number;
20
18
  y: number;
21
- }
22
- export class CursorManager extends Base {
19
+ };
20
+ export class CursorManager {
23
21
  public containerRect?: DOMRect;
24
22
  public wrapperRect?: DOMRect;
25
23
  public cursorInstances: Map<string, Cursor> = new Map();
26
24
  public roomMembers?: readonly RoomMember[];
27
25
  private mainViewElement?: HTMLDivElement;
26
+ private store = this.manager.store;
28
27
 
29
- constructor(private appManager: AppManager) {
30
- super(appManager);
31
- this.roomMembers = this.appManager.room?.state.roomMembers;
28
+ constructor(private manager: AppManager) {
29
+ this.roomMembers = this.manager.room?.state.roomMembers;
32
30
  const wrapper = WindowManager.wrapper;
33
31
  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();
32
+ wrapper.addEventListener("pointerenter", this.mouseMoveListener);
33
+ wrapper.addEventListener("pointermove", this.mouseMoveListener);
34
+ wrapper.addEventListener("pointerleave", this.mouseLeaveListener);
40
35
  this.wrapperRect = wrapper.getBoundingClientRect();
41
- this.startReaction(wrapper);
42
36
  }
37
+ emitter.on("cursorMove", payload => {
38
+ let cursorInstance = this.cursorInstances.get(payload.uid);
39
+ if (!cursorInstance) {
40
+ cursorInstance = new Cursor(this.manager, payload.uid, this, wrapper);
41
+ this.cursorInstances.set(payload.uid, cursorInstance);
42
+ }
43
+ if (payload.state === CursorState.Leave) {
44
+ cursorInstance.leave();
45
+ } else {
46
+ cursorInstance.move(payload.position);
47
+ }
48
+ });
43
49
  }
44
50
 
45
51
  public setMainViewDivElement(div: HTMLDivElement) {
46
52
  this.mainViewElement = div;
47
53
  }
48
54
 
49
- private startReaction(wrapper: HTMLElement) {
50
- this.manager.refresher?.add("cursors", () => {
51
- return onObjectInserted(this.cursors, () => {
52
- this.handleRoomMembersChange(wrapper);
53
- });
54
- })
55
- }
56
-
57
- private getUids = (members: readonly RoomMember[] | undefined) => {
58
- return compact(uniq(members?.map(member => member.payload?.uid)));
59
- }
60
-
61
- private handleRoomMembersChange = debounce((wrapper: HTMLElement) => {
62
- const uids = this.getUids(this.roomMembers);
63
- const cursors = Object.keys(this.cursors);
64
- if (uids?.length) {
65
- cursors.map(uid => {
66
- if (
67
- uids.includes(uid) &&
68
- !this.cursorInstances.has(uid)
69
- ) {
70
- if (uid === this.context.uid) {
71
- return;
72
- }
73
- const component = new Cursor(
74
- this.appManager,
75
- this.cursors,
76
- uid,
77
- this,
78
- wrapper
79
- );
80
- this.cursorInstances.set(uid, component);
81
- }
82
- })
83
- }
84
- }, 100);
85
-
86
- public get cursors() {
87
- return this.manager.attributes?.[Fields.Cursors];
88
- }
89
-
90
55
  public get boxState() {
91
56
  return this.store.getBoxState();
92
57
  }
93
58
 
94
59
  public get focusView() {
95
- return this.appManager.focusApp?.view;
60
+ return this.manager.focusApp?.view;
96
61
  }
97
62
 
98
- private mouseMoveListener = debounce((event: MouseEvent) => {
63
+ private mouseMoveListener = throttle((event: MouseEvent) => {
99
64
  this.updateCursor(this.getType(event), event.clientX, event.clientY);
100
- }, 5);
101
-
102
- private touchMoveListener = debounce((event: TouchEvent) => {
103
- if (event.touches.length === 1) {
104
- const touchEvent = event.touches[0];
105
- this.updateCursor(this.getType(touchEvent), touchEvent.clientX, touchEvent.clientY);
106
- }
107
- }, 5);
65
+ }, 16);
108
66
 
109
67
  private updateCursor(event: EventType, clientX: number, clientY: number) {
110
68
  if (this.wrapperRect && this.manager.canOperate) {
111
- const view = event.type === "main" ? this.appManager.mainView : this.focusView;
69
+ const view = event.type === "main" ? this.manager.mainView : this.focusView;
112
70
  const point = this.getPoint(view, clientX, clientY);
113
71
  if (point) {
114
- this.setNormalCursorState();
115
- this.store.updateCursor(this.context.uid, {
116
- x: point.x,
117
- y: point.y,
118
- ...event,
119
- });
72
+ this.manager.dispatchInternalEvent(Events.CursorMove, {
73
+ uid: this.manager.uid,
74
+ position: {
75
+ x: point.x,
76
+ y: point.y,
77
+ type: event.type,
78
+ },
79
+ } as CursorMovePayload);
120
80
  }
121
81
  }
122
82
  }
123
83
 
124
- private getPoint = (view: View | undefined, clientX: number, clientY: number): Point | undefined => {
84
+ private getPoint = (
85
+ view: View | undefined,
86
+ clientX: number,
87
+ clientY: number
88
+ ): Point | undefined => {
125
89
  const rect = view?.divElement?.getBoundingClientRect();
126
90
  if (rect) {
127
91
  const point = view?.convertToPointInWorld({
@@ -130,17 +94,17 @@ export class CursorManager extends Base {
130
94
  });
131
95
  return point;
132
96
  }
133
- }
97
+ };
134
98
 
135
99
  /**
136
100
  * 因为窗口内框在不同分辨率下的大小不一样,所以这里通过来鼠标事件的 target 来判断是在主白板还是在 APP 中
137
101
  */
138
102
  private getType = (event: MouseEvent | Touch): EventType => {
139
103
  const target = event.target as HTMLElement;
140
- const focusApp = this.appManager.focusApp;
104
+ const focusApp = this.manager.focusApp;
141
105
  switch (target.parentElement) {
142
106
  case this.mainViewElement: {
143
- return { type: "main" };
107
+ return { type: "main" };
144
108
  }
145
109
  case focusApp?.view?.divElement: {
146
110
  return { type: "app" };
@@ -151,25 +115,12 @@ export class CursorManager extends Base {
151
115
  }
152
116
  };
153
117
 
154
- private initCursorAttributes() {
155
- this.store.updateCursor(this.context.uid, {
156
- x: 0,
157
- y: 0,
158
- type: "main",
159
- });
160
- this.store.updateCursorState(this.context.uid, CursorState.Leave);
161
- }
162
-
163
- private setNormalCursorState() {
164
- const cursorState = this.store.getCursorState(this.context.uid);
165
- if (cursorState !== CursorState.Normal) {
166
- this.store.updateCursorState(this.context.uid, CursorState.Normal);
167
- }
168
- }
169
-
170
118
  private mouseLeaveListener = () => {
171
- this.hideCursor(this.context.uid);
172
- this.store.updateCursorState(this.context.uid, CursorState.Leave);
119
+ this.hideCursor(this.manager.uid);
120
+ this.manager.dispatchInternalEvent(Events.CursorMove, {
121
+ uid: this.manager.uid,
122
+ state: CursorState.Leave,
123
+ } as CursorMovePayload);
173
124
  };
174
125
 
175
126
  public updateContainerRect() {
@@ -177,18 +128,7 @@ export class CursorManager extends Base {
177
128
  this.wrapperRect = WindowManager.wrapper?.getBoundingClientRect();
178
129
  }
179
130
 
180
- public setRoomMembers(members: readonly RoomMember[]) {
181
- this.roomMembers = members;
182
- this.cursorInstances.forEach(cursor => {
183
- cursor.setMember();
184
- });
185
- if (WindowManager.wrapper) {
186
- this.handleRoomMembersChange(WindowManager.wrapper);
187
- }
188
- }
189
-
190
131
  public deleteCursor(uid: string) {
191
- this.store.cleanCursor(uid);
192
132
  const cursor = this.cursorInstances.get(uid);
193
133
  if (cursor) {
194
134
  cursor.destroy();
@@ -202,29 +142,12 @@ export class CursorManager extends Base {
202
142
  }
203
143
  }
204
144
 
205
- public cleanMemberAttributes(members: readonly RoomMember[]) {
206
- const uids = this.getUids(members);
207
- const needDeleteIds: string[] = [];
208
- const cursors = Object.keys(this.cursors);
209
- cursors.map(cursorId => {
210
- const index = uids.findIndex(id => id === cursorId);
211
- if (index === -1) {
212
- needDeleteIds.push(cursorId);
213
- }
214
- });
215
- needDeleteIds.forEach(uid => {
216
- this.deleteCursor(uid);
217
- });
218
- }
219
-
220
145
  public destroy() {
221
146
  const wrapper = WindowManager.wrapper;
222
147
  if (wrapper) {
223
- wrapper.removeEventListener("mousemove", this.mouseMoveListener);
224
- wrapper.removeEventListener("touchstart", this.touchMoveListener);
225
- wrapper.removeEventListener("touchmove", this.touchMoveListener);
226
- wrapper.removeEventListener("mouseleave", this.mouseLeaveListener);
227
- wrapper.removeEventListener("touchend", this.mouseLeaveListener);
148
+ wrapper.removeEventListener("pointerenter", this.mouseMoveListener);
149
+ wrapper.removeEventListener("pointermove", this.mouseMoveListener);
150
+ wrapper.removeEventListener("pointerleave", this.mouseLeaveListener);
228
151
  }
229
152
  if (this.cursorInstances.size) {
230
153
  this.cursorInstances.forEach(cursor => cursor.destroy());
package/src/MainView.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { AnimationMode, reaction, ViewVisionMode } from "white-web-sdk";
2
- import { Base } from "./Base";
3
2
  import { callbacks, emitter } from "./index";
4
3
  import { createView } from "./ViewManager";
5
4
  import { debounce, isEmpty, isEqual } from "lodash";
@@ -8,16 +7,16 @@ import { notifyMainViewModeChange, setViewFocusScenePath, setViewMode } from "./
8
7
  import type { Camera, Size, View } from "white-web-sdk";
9
8
  import type { AppManager } from "./AppManager";
10
9
 
11
- export class MainViewProxy extends Base {
10
+ export class MainViewProxy {
12
11
  private scale?: number;
13
12
  private cameraStore = this.manager.cameraStore;
13
+ private store = this.manager.store;
14
14
  private started = false;
15
15
  private mainViewIsAddListener = false;
16
16
  private mainView: View;
17
17
  private viewId = "mainView";
18
18
 
19
- constructor(manager: AppManager) {
20
- super(manager);
19
+ constructor(private manager: AppManager) {
21
20
  this.mainView = this.createMainView();
22
21
  this.moveCameraSizeByAttributes();
23
22
  this.cameraStore.register(this.viewId, this.mainView);
@@ -56,15 +55,15 @@ export class MainViewProxy extends Base {
56
55
  }
57
56
 
58
57
  public setCameraAndSize(): void {
59
- this.store.setMainViewCamera({ ...this.mainView.camera, id: this.context.uid });
60
- this.store.setMainViewSize({ ...this.mainView.size, id: this.context.uid });
58
+ this.store.setMainViewCamera({ ...this.mainView.camera, id: this.manager.uid });
59
+ this.store.setMainViewSize({ ...this.mainView.size, id: this.manager.uid });
61
60
  }
62
61
 
63
62
  private cameraReaction = () => {
64
63
  return reaction(
65
64
  () => this.mainViewCamera,
66
65
  camera => {
67
- if (camera && camera.id !== this.context.uid) {
66
+ if (camera && camera.id !== this.manager.uid) {
68
67
  this.moveCameraToContian(this.mainViewSize);
69
68
  this.moveCamera(camera);
70
69
  }
@@ -75,7 +74,7 @@ export class MainViewProxy extends Base {
75
74
  );
76
75
  };
77
76
 
78
- private sizeChangeHandler = debounce((size: Size) => {
77
+ private sizeChangeHandler = debounce((size: Size) => {
79
78
  if (size) {
80
79
  this.moveCameraToContian(size);
81
80
  this.moveCamera(this.mainViewCamera);
@@ -103,8 +102,8 @@ export class MainViewProxy extends Base {
103
102
  }
104
103
 
105
104
  private onCameraUpdatedByDevice = (camera: Camera) => {
106
- this.store.setMainViewCamera({ ...camera, id: this.context.uid });
107
- if (!isEqual(this.mainViewSize, {...this.mainView.size, id: this.context.uid})) {
105
+ this.store.setMainViewCamera({ ...camera, id: this.manager.uid });
106
+ if (!isEqual(this.mainViewSize, { ...this.mainView.size, id: this.manager.uid })) {
108
107
  this.setMainViewSize(this.view.size);
109
108
  }
110
109
  };
@@ -133,11 +132,11 @@ export class MainViewProxy extends Base {
133
132
  if (!this.manager.canOperate) return;
134
133
  if (this.view.mode === ViewVisionMode.Writable) return;
135
134
  this.store.cleanFocus();
136
- this.context.blurFocusBox();
135
+ this.manager.boxManager.blurAllBox();
137
136
  }
138
137
 
139
138
  public setMainViewSize = debounce(size => {
140
- this.store.setMainViewSize({ ...size, id: this.context.uid });
139
+ this.store.setMainViewSize({ ...size, id: this.manager.uid });
141
140
  }, 50);
142
141
 
143
142
  private addCameraListener() {
package/src/constants.ts CHANGED
@@ -10,6 +10,7 @@ export enum Events {
10
10
  SetMainViewScenePath = "SetMainViewScenePath",
11
11
  SetMainViewSceneIndex = "SetMainViewSceneIndex",
12
12
  SwitchViewsToFreedom = "SwitchViewsToFreedom",
13
+ CursorMove = "CursorMove",
13
14
  }
14
15
 
15
16
  export const MagixEventName = "__WindowManger";
package/src/index.ts CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  ParamsInvalidError,
31
31
  WhiteWebSDKInvalidError,
32
32
  } from "./Utils/error";
33
- import type { Apps } from "./AttributesDelegate";
33
+ import type { Apps, Position } from "./AttributesDelegate";
34
34
  import {
35
35
  InvisiblePlugin,
36
36
  isPlayer,
@@ -124,6 +124,8 @@ export type AppInitState = {
124
124
  zIndex?: number;
125
125
  };
126
126
 
127
+ export type CursorMovePayload = { uid: string; state?: "leave"; position: Position };
128
+
127
129
  export type EmitterEvent = {
128
130
  onCreated: undefined;
129
131
  InitReplay: AppInitState;
@@ -137,6 +139,8 @@ export type EmitterEvent = {
137
139
  observerIdChange: number;
138
140
  boxStateChange: string;
139
141
  playgroundSizeChange: DOMRect;
142
+ onReconnected: undefined;
143
+ cursorMove: CursorMovePayload;
140
144
  };
141
145
 
142
146
  export const emitter: Emittery<EmitterEvent> = new Emittery();
@@ -272,65 +276,70 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
272
276
  if (WindowManager.isCreated) {
273
277
  throw new Error("[WindowManager]: Already created cannot be created again");
274
278
  }
275
- let manager = await this.initManager(room);
276
- this.debug = Boolean(debug);
277
- if (this.debug) {
278
- setOptions({ verbose: true });
279
- }
280
- log("Already insert room", manager);
279
+ WindowManager.isCreated = true;
280
+ try {
281
+ let manager = await this.initManager(room);
282
+ this.debug = Boolean(debug);
283
+ if (this.debug) {
284
+ setOptions({ verbose: true });
285
+ }
286
+ log("Already insert room", manager);
281
287
 
282
- if (isRoom(this.displayer)) {
283
- if (!manager) {
284
- throw new Error("[WindowManager]: init InvisiblePlugin failed");
288
+ if (isRoom(this.displayer)) {
289
+ if (!manager) {
290
+ throw new Error("[WindowManager]: init InvisiblePlugin failed");
291
+ }
292
+ } else {
293
+ await pRetry(
294
+ async count => {
295
+ manager = await this.initManager(room);
296
+ if (!manager) {
297
+ log(`manager is empty. retrying ${count}`);
298
+ throw new Error();
299
+ }
300
+ },
301
+ { retries: 10 }
302
+ );
285
303
  }
286
- } else {
287
- await pRetry(
288
- async count => {
289
- manager = await this.initManager(room);
290
- if (!manager) {
291
- log(`manager is empty. retrying ${count}`);
292
- throw new Error();
293
- }
294
- },
295
- { retries: 10 }
296
- );
297
- }
298
304
 
299
- if (containerSizeRatio) {
300
- WindowManager.containerSizeRatio = containerSizeRatio;
301
- }
302
- WindowManager.container = container;
303
- const { playground, wrapper, sizer, mainViewElement } = setupWrapper(container);
304
- WindowManager.playground = playground;
305
- if (chessboard) {
306
- sizer.classList.add("netless-window-manager-chess-sizer");
307
- }
308
- if (overwriteStyles) {
309
- const style = document.createElement("style");
310
- style.textContent = overwriteStyles;
311
- playground.appendChild(style);
312
- }
313
- await manager.ensureAttributes();
314
- manager.appManager = new AppManager(manager, {
315
- collectorContainer: collectorContainer,
316
- collectorStyles: collectorStyles,
317
- prefersColorScheme: prefersColorScheme,
318
- });
319
- manager.observePlaygroundSize(playground, sizer, wrapper);
320
- if (cursor) {
321
- manager.cursorManager = new CursorManager(manager.appManager);
322
- }
323
- manager.bindMainView(mainViewElement, disableCameraTransform);
324
- replaceRoomFunction(room, manager.appManager);
325
- emitter.emit("onCreated");
326
- WindowManager.isCreated = true;
327
- try {
328
- await initDb();
305
+ if (containerSizeRatio) {
306
+ WindowManager.containerSizeRatio = containerSizeRatio;
307
+ }
308
+ WindowManager.container = container;
309
+ const { playground, wrapper, sizer, mainViewElement } = setupWrapper(container);
310
+ WindowManager.playground = playground;
311
+ if (chessboard) {
312
+ sizer.classList.add("netless-window-manager-chess-sizer");
313
+ }
314
+ if (overwriteStyles) {
315
+ const style = document.createElement("style");
316
+ style.textContent = overwriteStyles;
317
+ playground.appendChild(style);
318
+ }
319
+ await manager.ensureAttributes();
320
+ manager.appManager = new AppManager(manager, {
321
+ collectorContainer: collectorContainer,
322
+ collectorStyles: collectorStyles,
323
+ prefersColorScheme: prefersColorScheme,
324
+ });
325
+ manager.observePlaygroundSize(playground, sizer, wrapper);
326
+ if (cursor) {
327
+ manager.cursorManager = new CursorManager(manager.appManager);
328
+ }
329
+ manager.bindMainView(mainViewElement, disableCameraTransform);
330
+ replaceRoomFunction(room, manager.appManager);
331
+ emitter.emit("onCreated");
332
+ try {
333
+ await initDb();
334
+ } catch (error) {
335
+ console.warn("[WindowManager]: indexedDB open failed");
336
+ console.log(error);
337
+ }
338
+ return manager;
329
339
  } catch (error) {
330
- console.warn("[WindowManager]: indexedDB open failed");
331
- console.log(error);
340
+ WindowManager.isCreated = false;
341
+ throw error;
332
342
  }
333
- return manager;
334
343
  }
335
344
 
336
345
  private static async initManager(room: Room): Promise<WindowManager> {
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
  pointer-events: none;
@@ -1,4 +1,3 @@
1
- import { Base } from "./Base";
2
1
  import { callbacks, WindowManager } from "./index";
3
2
  import { reaction, ViewVisionMode } from "white-web-sdk";
4
3
  import { SET_SCENEPATH_DELAY } from "./constants";
@@ -6,16 +5,16 @@ import { notifyMainViewModeChange, setScenePath, setViewMode } from "./Utils/Com
6
5
  import type { View, Displayer } from "white-web-sdk";
7
6
  import type { AppManager } from "./AppManager";
8
7
 
9
- export class ViewManager extends Base {
8
+ export class ViewManager {
10
9
  private views: Map<string, View> = new Map();
11
10
  private timer?: number;
12
11
  private appTimer?: number;
13
12
 
14
13
  private mainViewProxy = this.manager.mainViewProxy;
15
14
  private displayer = this.manager.displayer;
15
+ private store = this.manager.store;
16
16
 
17
- constructor(manager: AppManager) {
18
- super(manager);
17
+ constructor(private manager: AppManager) {
19
18
  setTimeout(() => {
20
19
  // 延迟初始化 focus 的 reaction
21
20
  this.manager.refresher?.add("focus", () => {
@@ -26,7 +25,7 @@ export class ViewManager extends Base {
26
25
  this.switchAppToWriter(focus);
27
26
  } else {
28
27
  this.switchMainViewToWriter();
29
- this.context.blurFocusBox();
28
+ this.manager.boxManager.blurAllBox();
30
29
  }
31
30
  },
32
31
  { fireImmediately: true }
package/vite.config.js CHANGED
@@ -1,7 +1,7 @@
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, version } from "./package.json"
4
+ import { dependencies, peerDependencies, version, devDependencies } from "./package.json"
5
5
 
6
6
 
7
7
  export default defineConfig(({ mode }) => {
@@ -10,7 +10,9 @@ export default defineConfig(({ mode }) => {
10
10
  return {
11
11
  define: {
12
12
  __APP_VERSION__: JSON.stringify(version),
13
- __APP_DEPENDENCIES__: JSON.stringify(dependencies),
13
+ __APP_DEPENDENCIES__: JSON.stringify({
14
+ dependencies, peerDependencies, devDependencies
15
+ }),
14
16
  },
15
17
  plugins: [
16
18
  svelte({
@@ -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,8 +0,0 @@
1
- import type { AppManager } from "../AppManager";
2
- import { AttributesDelegate } from "../AttributesDelegate";
3
- export declare class Base {
4
- manager: AppManager;
5
- store: AttributesDelegate;
6
- context: import("./Context").Context;
7
- constructor(manager: AppManager);
8
- }
@@ -1,49 +0,0 @@
1
- import { emitter } from "../index";
2
- import type { AppManager } from "../AppManager";
3
-
4
- export class Context {
5
- public observerId: number;
6
-
7
- constructor(private manager: AppManager) {
8
- this.observerId = manager.displayer.observerId;
9
-
10
- emitter.on("observerIdChange", id => {
11
- this.observerId = id;
12
- });
13
- };
14
-
15
- public get uid() {
16
- return this.manager.room?.uid || "";
17
- }
18
-
19
- public findMember = (memberId: number) => {
20
- const roomMembers = this.manager.room?.state.roomMembers;
21
- return roomMembers?.find(member => member.memberId === memberId);
22
- }
23
-
24
- public findMemberByUid = (uid: string) => {
25
- const roomMembers = this.manager.room?.state.roomMembers;
26
- return roomMembers?.find(member => member.payload?.uid === uid);
27
- }
28
-
29
- public updateManagerRect() {
30
- this.manager.boxManager.updateManagerRect();
31
- }
32
-
33
- public blurFocusBox() {
34
- this.manager.boxManager.blurAllBox();
35
- }
36
-
37
- public switchAppToWriter(id: string) {
38
- this.manager.viewManager.switchAppToWriter(id);
39
- }
40
- }
41
-
42
- let context: Context;
43
-
44
- export const createContext = (manager: AppManager) => {
45
- if (!context) {
46
- context = new Context(manager);
47
- }
48
- return context;
49
- };
package/src/Base/index.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { AppManager } from "../AppManager";
2
- import { AttributesDelegate } from "../AttributesDelegate";
3
- import { createContext } from "./Context";
4
-
5
- export class Base {
6
- public store = new AttributesDelegate(this.manager);
7
- public context = createContext(this.manager);
8
-
9
- constructor(public manager: AppManager) {}
10
- }