@netless/window-manager 0.3.22 → 0.3.25
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.
- package/.vscode/settings.json +1 -0
- package/dist/AppListener.d.ts +1 -0
- package/dist/AppManager.d.ts +2 -0
- package/dist/AppProxy.d.ts +3 -2
- package/dist/AttributesDelegate.d.ts +0 -4
- package/dist/BoxManager.d.ts +1 -1
- package/dist/Cursor/Cursor.d.ts +8 -12
- package/dist/Cursor/index.d.ts +5 -14
- package/dist/MainView.d.ts +3 -2
- package/dist/ViewManager.d.ts +3 -2
- package/dist/constants.d.ts +2 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.es.js +41 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +41 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +5 -5
- package/src/AppContext.ts +1 -1
- package/src/AppListener.ts +9 -1
- package/src/AppManager.ts +11 -4
- package/src/AppProxy.ts +9 -7
- package/src/AttributesDelegate.ts +0 -28
- package/src/BoxManager.ts +21 -24
- package/src/Cursor/Cursor.ts +34 -59
- package/src/Cursor/index.ts +53 -130
- package/src/MainView.ts +11 -12
- package/src/constants.ts +1 -0
- package/src/index.ts +93 -55
- package/src/style.css +1 -1
- package/src/viewManager.ts +4 -5
- package/vite.config.js +4 -2
- package/dist/Base/Context.d.ts +0 -13
- package/dist/Base/index.d.ts +0 -8
- package/src/Base/Context.ts +0 -49
- package/src/Base/index.ts +0 -10
package/src/Cursor/index.ts
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import {
|
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
|
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
|
30
|
-
|
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("
|
35
|
-
wrapper.addEventListener("
|
36
|
-
wrapper.addEventListener("
|
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.
|
60
|
+
return this.manager.focusApp?.view;
|
96
61
|
}
|
97
62
|
|
98
|
-
private mouseMoveListener =
|
63
|
+
private mouseMoveListener = throttle((event: MouseEvent) => {
|
99
64
|
this.updateCursor(this.getType(event), event.clientX, event.clientY);
|
100
|
-
},
|
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.
|
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.
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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 = (
|
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.
|
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.
|
172
|
-
this.
|
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("
|
224
|
-
wrapper.removeEventListener("
|
225
|
-
wrapper.removeEventListener("
|
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
|
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.
|
60
|
-
this.store.setMainViewSize({ ...this.mainView.size, id: this.
|
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.
|
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 =
|
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.
|
107
|
-
if (!isEqual(this.mainViewSize, {...this.mainView.size, id: this.
|
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.
|
135
|
+
this.manager.boxManager.blurAllBox();
|
137
136
|
}
|
138
137
|
|
139
138
|
public setMainViewSize = debounce(size => {
|
140
|
-
this.store.setMainViewSize({ ...size, id: this.
|
139
|
+
this.store.setMainViewSize({ ...size, id: this.manager.uid });
|
141
140
|
}, 50);
|
142
141
|
|
143
142
|
private addCameraListener() {
|
package/src/constants.ts
CHANGED
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
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
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
|
-
|
283
|
-
|
284
|
-
|
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
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
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
|
-
|
331
|
-
|
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> {
|
@@ -490,6 +499,35 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
490
499
|
addEmitterOnceListener(`destroy-${kind}`, listener);
|
491
500
|
}
|
492
501
|
|
502
|
+
public setBoxState(boxState: TeleBoxState): void {
|
503
|
+
if (!this.canOperate) return;
|
504
|
+
switch (boxState) {
|
505
|
+
case "normal":
|
506
|
+
this.setMaximized(false);
|
507
|
+
this.setMinimized(false);
|
508
|
+
break;
|
509
|
+
case "maximized":
|
510
|
+
this.setMaximized(true);
|
511
|
+
this.setMinimized(false);
|
512
|
+
break;
|
513
|
+
case "minimized":
|
514
|
+
this.setMinimized(true);
|
515
|
+
break;
|
516
|
+
default:
|
517
|
+
break;
|
518
|
+
}
|
519
|
+
}
|
520
|
+
|
521
|
+
public setMaximized(maximized: boolean): void {
|
522
|
+
if (!this.canOperate) return;
|
523
|
+
this.appManager?.boxManager.setMaximized(maximized, false);
|
524
|
+
}
|
525
|
+
|
526
|
+
public setMinimized(minimized: boolean): void {
|
527
|
+
if (!this.canOperate) return;
|
528
|
+
this.appManager?.boxManager.setMinimized(minimized, false);
|
529
|
+
}
|
530
|
+
|
493
531
|
/**
|
494
532
|
* 设置 ViewMode
|
495
533
|
*/
|
package/src/style.css
CHANGED
package/src/viewManager.ts
CHANGED
@@ -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
|
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.
|
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(
|
13
|
+
__APP_DEPENDENCIES__: JSON.stringify({
|
14
|
+
dependencies, peerDependencies, devDependencies
|
15
|
+
}),
|
14
16
|
},
|
15
17
|
plugins: [
|
16
18
|
svelte({
|
package/dist/Base/Context.d.ts
DELETED
@@ -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;
|
package/dist/Base/index.d.ts
DELETED
@@ -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
|
-
}
|
package/src/Base/Context.ts
DELETED
@@ -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
|
-
};
|