@netless/window-manager 0.4.0-canary.17 → 0.4.0-canary.20
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/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/window-manager.iml +12 -0
- package/.vscode/settings.json +1 -0
- package/CHANGELOG.md +30 -2
- package/dist/AppListener.d.ts +1 -0
- package/dist/AppManager.d.ts +8 -6
- package/dist/AppProxy.d.ts +3 -2
- package/dist/AttributesDelegate.d.ts +2 -2
- package/dist/BoxManager.d.ts +4 -3
- package/dist/BuiltinApps.d.ts +0 -1
- package/dist/Cursor/Cursor.d.ts +8 -11
- package/dist/Cursor/index.d.ts +5 -16
- package/dist/Utils/RoomHacker.d.ts +1 -1
- package/dist/View/MainView.d.ts +4 -3
- package/dist/constants.d.ts +3 -2
- package/dist/index.d.ts +15 -2
- 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/docs/api.md +28 -0
- package/docs/concept.md +5 -0
- package/package.json +5 -5
- package/src/AppListener.ts +14 -6
- package/src/AppManager.ts +62 -34
- package/src/AppProxy.ts +12 -8
- package/src/AttributesDelegate.ts +2 -2
- package/src/BoxManager.ts +29 -20
- package/src/BuiltinApps.ts +0 -1
- package/src/Cursor/Cursor.ts +22 -36
- package/src/Cursor/index.ts +33 -139
- package/src/Utils/RoomHacker.ts +28 -15
- package/src/View/MainView.ts +17 -12
- package/src/constants.ts +3 -2
- package/src/index.ts +46 -3
- package/src/shim.d.ts +2 -1
- package/src/style.css +1 -1
- package/vite.config.js +5 -2
- package/dist/Base/Context.d.ts +0 -12
- package/dist/Base/index.d.ts +0 -7
- package/src/Base/Context.ts +0 -45
- package/src/Base/index.ts +0 -10
package/src/Cursor/Cursor.ts
CHANGED
@@ -1,42 +1,34 @@
|
|
1
|
-
import App from
|
2
|
-
import { ApplianceMap } from
|
3
|
-
import { ApplianceNames } from
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import { get, omit } from 'lodash';
|
7
|
-
import type { Position } from '../AttributesDelegate';
|
1
|
+
import App from "./Cursor.svelte";
|
2
|
+
import { ApplianceMap } from "./icons";
|
3
|
+
import { ApplianceNames } from "white-web-sdk";
|
4
|
+
import { omit } from "lodash";
|
5
|
+
import type { Position } from "../AttributesDelegate";
|
8
6
|
import type { RoomMember } from "white-web-sdk";
|
9
7
|
import type { CursorManager } from "./index";
|
10
8
|
import type { SvelteComponent } from "svelte";
|
11
|
-
import {
|
12
|
-
import type { AppManager } from '../AppManager';
|
9
|
+
import type { AppManager } from "../AppManager";
|
13
10
|
|
14
11
|
export type Payload = {
|
15
|
-
[key: string]: any
|
16
|
-
}
|
17
|
-
|
12
|
+
[key: string]: any;
|
13
|
+
};
|
18
14
|
|
19
|
-
export class Cursor
|
15
|
+
export class Cursor {
|
20
16
|
private member?: RoomMember;
|
21
17
|
private timer?: number;
|
22
18
|
private component?: SvelteComponent;
|
23
19
|
|
24
20
|
constructor(
|
25
|
-
manager: AppManager,
|
26
|
-
addCursorChangeListener: (uid: string, callback: (position: Position, state: CursorState) => void) => void,
|
27
|
-
private cursors: any,
|
21
|
+
private manager: AppManager,
|
28
22
|
private memberId: string,
|
29
23
|
private cursorManager: CursorManager,
|
30
|
-
private wrapper?: HTMLElement
|
24
|
+
private wrapper?: HTMLElement
|
31
25
|
) {
|
32
|
-
super(manager);
|
33
26
|
this.setMember();
|
34
27
|
this.createCursor();
|
35
|
-
addCursorChangeListener(this.memberId, this.onCursorChange);
|
36
28
|
this.autoHidden();
|
37
29
|
}
|
38
30
|
|
39
|
-
|
31
|
+
public move = (position: Position) => {
|
40
32
|
if (position.type === "main") {
|
41
33
|
const rect = this.cursorManager.wrapperRect;
|
42
34
|
if (this.component && rect) {
|
@@ -45,7 +37,6 @@ export class Cursor extends Base {
|
|
45
37
|
}
|
46
38
|
} else {
|
47
39
|
const focusView = this.cursorManager.focusView;
|
48
|
-
// TODO 可以存一个当前 focusView 的 Rect 这样只有 focus 切换的时候才调用 getBoundingClientRect
|
49
40
|
const viewRect = focusView?.divElement?.getBoundingClientRect();
|
50
41
|
const viewCamera = focusView?.camera;
|
51
42
|
if (focusView && viewRect && viewCamera && this.component) {
|
@@ -53,10 +44,11 @@ export class Cursor extends Base {
|
|
53
44
|
this.moveCursor(position, viewRect, focusView);
|
54
45
|
}
|
55
46
|
}
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
47
|
+
};
|
48
|
+
|
49
|
+
public leave = () => {
|
50
|
+
this.hide();
|
51
|
+
};
|
60
52
|
|
61
53
|
private moveCursor(cursor: Position, rect: DOMRect, view: any) {
|
62
54
|
const { x, y, type } = cursor;
|
@@ -124,21 +116,12 @@ export class Cursor extends Base {
|
|
124
116
|
}
|
125
117
|
}
|
126
118
|
|
127
|
-
public get cursorState(): CursorState | undefined {
|
128
|
-
return get(this.cursors, [this.memberId, Fields.CursorState]);
|
129
|
-
}
|
130
|
-
|
131
|
-
public get cursorPosition(): Position | undefined {
|
132
|
-
return get(this.cursors, [this.memberId, Fields.Position]);
|
133
|
-
}
|
134
|
-
|
135
119
|
private autoHidden() {
|
136
120
|
if (this.timer) {
|
137
121
|
clearTimeout(this.timer);
|
138
122
|
}
|
139
123
|
this.timer = window.setTimeout(() => {
|
140
124
|
this.hide();
|
141
|
-
this.store.updateCursorState(this.memberId, CursorState.Leave);
|
142
125
|
}, 1000 * 10); // 10 秒钟自动隐藏
|
143
126
|
}
|
144
127
|
|
@@ -176,7 +159,7 @@ export class Cursor extends Base {
|
|
176
159
|
}
|
177
160
|
|
178
161
|
public setMember() {
|
179
|
-
this.member = this.
|
162
|
+
this.member = this.manager.findMemberByUid(this.memberId);
|
180
163
|
this.updateComponent();
|
181
164
|
}
|
182
165
|
|
@@ -188,13 +171,16 @@ export class Cursor extends Base {
|
|
188
171
|
if (this.component) {
|
189
172
|
this.component.$destroy();
|
190
173
|
}
|
191
|
-
this.manager.refresher?.remove(this.memberId);
|
192
174
|
this.cursorManager.cursorInstances.delete(this.memberId);
|
175
|
+
if (this.timer) {
|
176
|
+
clearTimeout(this.timer);
|
177
|
+
}
|
193
178
|
}
|
194
179
|
|
195
180
|
public hide() {
|
196
181
|
if (this.component) {
|
197
182
|
this.component.$set({ visible: false });
|
183
|
+
this.destroy();
|
198
184
|
}
|
199
185
|
}
|
200
186
|
}
|
package/src/Cursor/index.ts
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
import { Base } from "../Base";
|
3
|
-
import { compact, debounce, get, uniq } from "lodash";
|
1
|
+
import { throttle } from "lodash";
|
4
2
|
import { Cursor } from "./Cursor";
|
5
|
-
import { CursorState } from "../constants";
|
3
|
+
import { CursorState, Events } from "../constants";
|
6
4
|
import { emitter, WindowManager } from "../index";
|
7
|
-
import { Fields } from "../AttributesDelegate";
|
8
|
-
import { onObjectInserted } from "../Utils/Reactive";
|
9
5
|
import { SideEffectManager } from "side-effect-manager";
|
10
|
-
import type {
|
6
|
+
import type { CursorMovePayload } from "../index";
|
7
|
+
import type { PositionType } from "../AttributesDelegate";
|
11
8
|
import type { Point, RoomMember, View } from "white-web-sdk";
|
12
9
|
import type { AppManager } from "../AppManager";
|
13
10
|
|
@@ -21,30 +18,36 @@ export type MoveCursorParams = {
|
|
21
18
|
x: number;
|
22
19
|
y: number;
|
23
20
|
};
|
24
|
-
export class CursorManager
|
21
|
+
export class CursorManager {
|
25
22
|
public containerRect?: DOMRect;
|
26
23
|
public wrapperRect?: DOMRect;
|
27
24
|
public cursorInstances: Map<string, Cursor> = new Map();
|
28
25
|
public roomMembers?: readonly RoomMember[];
|
29
26
|
private mainViewElement?: HTMLDivElement;
|
30
27
|
private sideEffectManager = new SideEffectManager();
|
28
|
+
private store = this.manager.store;
|
31
29
|
|
32
|
-
constructor(private
|
33
|
-
|
34
|
-
this.roomMembers = this.appManager.room?.state.roomMembers;
|
30
|
+
constructor(private manager: AppManager) {
|
31
|
+
this.roomMembers = this.manager.room?.state.roomMembers;
|
35
32
|
const wrapper = WindowManager.wrapper;
|
36
33
|
if (wrapper) {
|
37
34
|
this.setupWrapper(wrapper);
|
38
35
|
}
|
39
|
-
emitter.on("
|
40
|
-
this.
|
36
|
+
emitter.on("cursorMove", payload => {
|
37
|
+
let cursorInstance = this.cursorInstances.get(payload.uid);
|
38
|
+
if (!cursorInstance) {
|
39
|
+
cursorInstance = new Cursor(this.manager, payload.uid, this, WindowManager.wrapper);
|
40
|
+
this.cursorInstances.set(payload.uid, cursorInstance);
|
41
|
+
}
|
42
|
+
if (payload.state === CursorState.Leave) {
|
43
|
+
cursorInstance.leave();
|
44
|
+
} else {
|
45
|
+
cursorInstance.move(payload.position);
|
46
|
+
}
|
41
47
|
});
|
42
48
|
}
|
43
49
|
|
44
50
|
public setupWrapper(wrapper: HTMLElement) {
|
45
|
-
if (this.manager.refresher?.hasReactor("cursors")) {
|
46
|
-
this.destroy();
|
47
|
-
}
|
48
51
|
this.sideEffectManager.add(() => {
|
49
52
|
wrapper.addEventListener("pointerenter", this.mouseMoveListener);
|
50
53
|
wrapper.addEventListener("pointermove", this.mouseMoveListener);
|
@@ -56,77 +59,38 @@ export class CursorManager extends Base {
|
|
56
59
|
};
|
57
60
|
});
|
58
61
|
|
59
|
-
this.initCursorAttributes();
|
60
62
|
this.wrapperRect = wrapper.getBoundingClientRect();
|
61
|
-
this.startReaction(wrapper);
|
62
63
|
}
|
63
64
|
|
64
65
|
public setMainViewDivElement(div: HTMLDivElement) {
|
65
66
|
this.mainViewElement = div;
|
66
67
|
}
|
67
68
|
|
68
|
-
private startReaction(wrapper: HTMLElement) {
|
69
|
-
this.manager.refresher?.add("cursors", () => {
|
70
|
-
return onObjectInserted(this.cursors, () => {
|
71
|
-
this.handleRoomMembersChange(wrapper);
|
72
|
-
});
|
73
|
-
});
|
74
|
-
}
|
75
|
-
|
76
|
-
private getUids = (members: readonly RoomMember[] | undefined) => {
|
77
|
-
return compact(uniq(members?.map(member => member.payload?.uid)));
|
78
|
-
};
|
79
|
-
|
80
|
-
private handleRoomMembersChange = debounce((wrapper: HTMLElement) => {
|
81
|
-
const uids = this.getUids(this.roomMembers);
|
82
|
-
const cursors = Object.keys(this.cursors);
|
83
|
-
if (uids?.length) {
|
84
|
-
cursors.map(uid => {
|
85
|
-
if (uids.includes(uid) && !this.cursorInstances.has(uid)) {
|
86
|
-
if (uid === this.context.uid) {
|
87
|
-
return;
|
88
|
-
}
|
89
|
-
const component = new Cursor(
|
90
|
-
this.appManager,
|
91
|
-
this.addCursorChangeListener,
|
92
|
-
this.cursors,
|
93
|
-
uid,
|
94
|
-
this,
|
95
|
-
wrapper
|
96
|
-
);
|
97
|
-
this.cursorInstances.set(uid, component);
|
98
|
-
}
|
99
|
-
});
|
100
|
-
}
|
101
|
-
}, 100);
|
102
|
-
|
103
|
-
public get cursors() {
|
104
|
-
return this.manager.attributes?.[Fields.Cursors];
|
105
|
-
}
|
106
|
-
|
107
69
|
public get boxState() {
|
108
70
|
return this.store.getBoxState();
|
109
71
|
}
|
110
72
|
|
111
73
|
public get focusView() {
|
112
|
-
return this.
|
74
|
+
return this.manager.focusApp?.view;
|
113
75
|
}
|
114
76
|
|
115
|
-
private mouseMoveListener =
|
77
|
+
private mouseMoveListener = throttle((event: MouseEvent) => {
|
116
78
|
this.updateCursor(this.getType(event), event.clientX, event.clientY);
|
117
|
-
},
|
79
|
+
}, 16);
|
118
80
|
|
119
81
|
private updateCursor(event: EventType, clientX: number, clientY: number) {
|
120
82
|
if (this.wrapperRect && this.manager.canOperate) {
|
121
|
-
const view = event.type === "main" ? this.
|
83
|
+
const view = event.type === "main" ? this.manager.mainView : this.focusView;
|
122
84
|
const point = this.getPoint(view, clientX, clientY);
|
123
85
|
if (point) {
|
124
|
-
this.
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
86
|
+
this.manager.dispatchInternalEvent(Events.CursorMove, {
|
87
|
+
uid: this.manager.uid,
|
88
|
+
position: {
|
89
|
+
x: point.x,
|
90
|
+
y: point.y,
|
91
|
+
type: event.type,
|
92
|
+
},
|
93
|
+
} as CursorMovePayload);
|
130
94
|
}
|
131
95
|
}
|
132
96
|
}
|
@@ -151,7 +115,7 @@ export class CursorManager extends Base {
|
|
151
115
|
*/
|
152
116
|
private getType = (event: MouseEvent | Touch): EventType => {
|
153
117
|
const target = event.target as HTMLElement;
|
154
|
-
const focusApp = this.
|
118
|
+
const focusApp = this.manager.focusApp;
|
155
119
|
switch (target.parentElement) {
|
156
120
|
case this.mainViewElement: {
|
157
121
|
return { type: "main" };
|
@@ -165,25 +129,8 @@ export class CursorManager extends Base {
|
|
165
129
|
}
|
166
130
|
};
|
167
131
|
|
168
|
-
private initCursorAttributes() {
|
169
|
-
this.store.updateCursor(this.context.uid, {
|
170
|
-
x: 0,
|
171
|
-
y: 0,
|
172
|
-
type: "main",
|
173
|
-
});
|
174
|
-
this.store.updateCursorState(this.context.uid, CursorState.Leave);
|
175
|
-
}
|
176
|
-
|
177
|
-
private setNormalCursorState() {
|
178
|
-
const cursorState = this.store.getCursorState(this.context.uid);
|
179
|
-
if (cursorState !== CursorState.Normal) {
|
180
|
-
this.store.updateCursorState(this.context.uid, CursorState.Normal);
|
181
|
-
}
|
182
|
-
}
|
183
|
-
|
184
132
|
private mouseLeaveListener = () => {
|
185
|
-
this.hideCursor(this.
|
186
|
-
this.store.updateCursorState(this.context.uid, CursorState.Leave);
|
133
|
+
this.hideCursor(this.manager.uid);
|
187
134
|
};
|
188
135
|
|
189
136
|
public updateContainerRect() {
|
@@ -191,16 +138,6 @@ export class CursorManager extends Base {
|
|
191
138
|
this.wrapperRect = WindowManager.wrapper?.getBoundingClientRect();
|
192
139
|
}
|
193
140
|
|
194
|
-
public setRoomMembers(members: readonly RoomMember[]) {
|
195
|
-
this.roomMembers = members;
|
196
|
-
this.cursorInstances.forEach(cursor => {
|
197
|
-
cursor.setMember();
|
198
|
-
});
|
199
|
-
if (WindowManager.wrapper) {
|
200
|
-
this.handleRoomMembersChange(WindowManager.wrapper);
|
201
|
-
}
|
202
|
-
}
|
203
|
-
|
204
141
|
public deleteCursor(uid: string) {
|
205
142
|
this.store.cleanCursor(uid);
|
206
143
|
const cursor = this.cursorInstances.get(uid);
|
@@ -216,48 +153,6 @@ export class CursorManager extends Base {
|
|
216
153
|
}
|
217
154
|
}
|
218
155
|
|
219
|
-
public cleanMemberAttributes(members: readonly RoomMember[]) {
|
220
|
-
const uids = this.getUids(members);
|
221
|
-
const needDeleteIds: string[] = [];
|
222
|
-
const cursors = Object.keys(this.cursors);
|
223
|
-
cursors.map(cursorId => {
|
224
|
-
const index = uids.findIndex(id => id === cursorId);
|
225
|
-
if (index === -1) {
|
226
|
-
needDeleteIds.push(cursorId);
|
227
|
-
}
|
228
|
-
});
|
229
|
-
needDeleteIds.forEach(uid => {
|
230
|
-
this.deleteCursor(uid);
|
231
|
-
});
|
232
|
-
}
|
233
|
-
|
234
|
-
public onReconnect() {
|
235
|
-
if (this.cursorInstances.size) {
|
236
|
-
this.cursorInstances.forEach(cursor => cursor.destroy());
|
237
|
-
this.cursorInstances.clear();
|
238
|
-
}
|
239
|
-
this.roomMembers = this.appManager.room?.state.roomMembers;
|
240
|
-
if (WindowManager.wrapper) {
|
241
|
-
this.handleRoomMembersChange(WindowManager.wrapper);
|
242
|
-
}
|
243
|
-
}
|
244
|
-
|
245
|
-
public addCursorChangeListener = (
|
246
|
-
uid: string,
|
247
|
-
callback: (position: Position, state: CursorState) => void
|
248
|
-
) => {
|
249
|
-
this.manager.refresher?.add(uid, () => {
|
250
|
-
const disposer = autorun(() => {
|
251
|
-
const position = get(this.cursors, [uid, Fields.Position]);
|
252
|
-
const state = get(this.cursors, [uid, Fields.CursorState]);
|
253
|
-
if (position) {
|
254
|
-
callback(position, state);
|
255
|
-
}
|
256
|
-
});
|
257
|
-
return disposer;
|
258
|
-
});
|
259
|
-
};
|
260
|
-
|
261
156
|
public destroy() {
|
262
157
|
this.sideEffectManager.flushAll();
|
263
158
|
if (this.cursorInstances.size) {
|
@@ -266,6 +161,5 @@ export class CursorManager extends Base {
|
|
266
161
|
});
|
267
162
|
this.cursorInstances.clear();
|
268
163
|
}
|
269
|
-
this.manager.refresher?.remove("cursors");
|
270
164
|
}
|
271
165
|
}
|
package/src/Utils/RoomHacker.ts
CHANGED
@@ -1,22 +1,13 @@
|
|
1
1
|
import { emitter } from "../index";
|
2
2
|
import { isPlayer } from "white-web-sdk";
|
3
|
-
import type { WindowManager } from
|
4
|
-
import type { Camera, Room
|
3
|
+
import type { WindowManager } from "../index";
|
4
|
+
import type { Camera, Room, Player, PlayerSeekingResult } from "white-web-sdk";
|
5
5
|
|
6
6
|
// 修改多窗口状态下一些失效的方法实现到 manager 的 mainview 上, 降低迁移成本
|
7
7
|
export const replaceRoomFunction = (room: Room, manager: WindowManager) => {
|
8
8
|
if (isPlayer(room)) {
|
9
9
|
const player = room as unknown as Player;
|
10
|
-
|
11
|
-
// eslint-disable-next-line no-inner-declarations
|
12
|
-
async function newSeek(time: number): Promise<PlayerSeekingResult> {
|
13
|
-
const seekResult = await originSeek.call(player, time);
|
14
|
-
if (seekResult === "success") {
|
15
|
-
emitter.emit("seek", time);
|
16
|
-
}
|
17
|
-
return seekResult;
|
18
|
-
}
|
19
|
-
player.seekToProgressTime = newSeek;
|
10
|
+
delegateSeekToProgressTime(player);
|
20
11
|
} else {
|
21
12
|
const descriptor = Object.getOwnPropertyDescriptor(room, "disableCameraTransform");
|
22
13
|
if (descriptor) return;
|
@@ -32,13 +23,13 @@ export const replaceRoomFunction = (room: Room, manager: WindowManager) => {
|
|
32
23
|
Object.defineProperty(room, "canUndoSteps", {
|
33
24
|
get() {
|
34
25
|
return manager.mainView.canUndoSteps;
|
35
|
-
}
|
26
|
+
},
|
36
27
|
});
|
37
28
|
|
38
29
|
Object.defineProperty(room, "canRedoSteps", {
|
39
30
|
get() {
|
40
31
|
return manager.mainView.canRedoSteps;
|
41
|
-
}
|
32
|
+
},
|
42
33
|
});
|
43
34
|
|
44
35
|
room.moveCamera = (camera: Camera) => manager.mainView.moveCamera(camera);
|
@@ -52,6 +43,28 @@ export const replaceRoomFunction = (room: Room, manager: WindowManager) => {
|
|
52
43
|
room.redo = () => manager.mainView.redo();
|
53
44
|
room.undo = () => manager.mainView.undo();
|
54
45
|
room.cleanCurrentScene = () => manager.mainView.cleanCurrentScene();
|
46
|
+
delegateRemoveScenes(room);
|
55
47
|
}
|
48
|
+
};
|
56
49
|
|
57
|
-
|
50
|
+
const delegateRemoveScenes = (room: Room) => {
|
51
|
+
const originRemoveScenes = room.removeScenes;
|
52
|
+
room.removeScenes = (scenePath: string) => {
|
53
|
+
const result = originRemoveScenes.call(room, scenePath);
|
54
|
+
emitter.emit("removeScenes", scenePath);
|
55
|
+
return result;
|
56
|
+
};
|
57
|
+
};
|
58
|
+
|
59
|
+
const delegateSeekToProgressTime = (player: Player) => {
|
60
|
+
const originSeek = player.seekToProgressTime;
|
61
|
+
// eslint-disable-next-line no-inner-declarations
|
62
|
+
async function newSeek(time: number): Promise<PlayerSeekingResult> {
|
63
|
+
const seekResult = await originSeek.call(player, time);
|
64
|
+
if (seekResult === "success") {
|
65
|
+
emitter.emit("seek", time);
|
66
|
+
}
|
67
|
+
return seekResult;
|
68
|
+
}
|
69
|
+
player.seekToProgressTime = newSeek;
|
70
|
+
};
|
package/src/View/MainView.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import { AnimationMode, reaction } 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";
|
@@ -9,17 +8,16 @@ import { SideEffectManager } from "side-effect-manager";
|
|
9
8
|
import type { Camera, Size, View } from "white-web-sdk";
|
10
9
|
import type { AppManager } from "../AppManager";
|
11
10
|
|
12
|
-
export class MainViewProxy
|
11
|
+
export class MainViewProxy {
|
13
12
|
private scale?: number;
|
14
13
|
private started = false;
|
15
14
|
private mainViewIsAddListener = false;
|
16
15
|
private mainView: View;
|
17
|
-
private
|
16
|
+
private store = this.manager.store;
|
18
17
|
|
19
18
|
private sideEffectManager = new SideEffectManager();
|
20
19
|
|
21
|
-
constructor(manager: AppManager) {
|
22
|
-
super(manager);
|
20
|
+
constructor(private manager: AppManager) {
|
23
21
|
this.mainView = this.createMainView();
|
24
22
|
this.moveCameraSizeByAttributes();
|
25
23
|
emitter.once("mainViewMounted").then(() => {
|
@@ -62,15 +60,15 @@ export class MainViewProxy extends Base {
|
|
62
60
|
}
|
63
61
|
|
64
62
|
public setCameraAndSize(): void {
|
65
|
-
this.store.setMainViewCamera({ ...this.mainView.camera, id: this.
|
66
|
-
this.store.setMainViewSize({ ...this.mainView.size, id: this.
|
63
|
+
this.store.setMainViewCamera({ ...this.mainView.camera, id: this.manager.uid });
|
64
|
+
this.store.setMainViewSize({ ...this.mainView.size, id: this.manager.uid });
|
67
65
|
}
|
68
66
|
|
69
67
|
private cameraReaction = () => {
|
70
68
|
return reaction(
|
71
69
|
() => this.mainViewCamera,
|
72
70
|
camera => {
|
73
|
-
if (camera && camera.id !== this.
|
71
|
+
if (camera && camera.id !== this.manager.uid) {
|
74
72
|
this.moveCameraToContian(this.mainViewSize);
|
75
73
|
this.moveCamera(camera);
|
76
74
|
}
|
@@ -105,9 +103,16 @@ export class MainViewProxy extends Base {
|
|
105
103
|
return mainView;
|
106
104
|
}
|
107
105
|
|
106
|
+
public onReconnect(): void {
|
107
|
+
const mainViewScenePath = this.store.getMainViewScenePath();
|
108
|
+
if (mainViewScenePath) {
|
109
|
+
setViewFocusScenePath(this.view, mainViewScenePath);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
108
113
|
private onCameraUpdatedByDevice = (camera: Camera) => {
|
109
|
-
this.store.setMainViewCamera({ ...camera, id: this.
|
110
|
-
if (!isEqual(this.mainViewSize, { ...this.mainView.size, id: this.
|
114
|
+
this.store.setMainViewCamera({ ...camera, id: this.manager.uid });
|
115
|
+
if (!isEqual(this.mainViewSize, { ...this.mainView.size, id: this.manager.uid })) {
|
111
116
|
this.setMainViewSize(this.view.size);
|
112
117
|
}
|
113
118
|
};
|
@@ -135,11 +140,11 @@ export class MainViewProxy extends Base {
|
|
135
140
|
public async mainViewClickHandler(): Promise<void> {
|
136
141
|
if (!this.manager.canOperate) return;
|
137
142
|
this.store.cleanFocus();
|
138
|
-
this.
|
143
|
+
this.manager.boxManager?.blurAllBox();
|
139
144
|
}
|
140
145
|
|
141
146
|
public setMainViewSize = debounce(size => {
|
142
|
-
this.store.setMainViewSize({ ...size, id: this.
|
147
|
+
this.store.setMainViewSize({ ...size, id: this.manager.uid });
|
143
148
|
}, 50);
|
144
149
|
|
145
150
|
private addCameraListener() {
|
package/src/constants.ts
CHANGED
@@ -10,7 +10,8 @@ export enum Events {
|
|
10
10
|
SetMainViewScenePath = "SetMainViewScenePath",
|
11
11
|
SetMainViewSceneIndex = "SetMainViewSceneIndex",
|
12
12
|
SwitchViewsToFreedom = "SwitchViewsToFreedom",
|
13
|
-
MoveCameraToContain = "MoveCameraToContain"
|
13
|
+
MoveCameraToContain = "MoveCameraToContain",
|
14
|
+
CursorMove = "CursorMove",
|
14
15
|
}
|
15
16
|
|
16
17
|
export const MagixEventName = "__WindowManger";
|
@@ -37,7 +38,7 @@ export enum CursorState {
|
|
37
38
|
Normal = "normal",
|
38
39
|
}
|
39
40
|
|
40
|
-
export const REQUIRE_VERSION = "2.16.
|
41
|
+
export const REQUIRE_VERSION = "2.16.1";
|
41
42
|
|
42
43
|
export const MIN_WIDTH = 340 / 720;
|
43
44
|
export const MIN_HEIGHT = 340 / 720;
|
package/src/index.ts
CHANGED
@@ -32,7 +32,7 @@ import {
|
|
32
32
|
ParamsInvalidError,
|
33
33
|
WhiteWebSDKInvalidError,
|
34
34
|
} from "./Utils/error";
|
35
|
-
import type { Apps } from "./AttributesDelegate";
|
35
|
+
import type { Apps, Position } from "./AttributesDelegate";
|
36
36
|
import {
|
37
37
|
InvisiblePlugin,
|
38
38
|
isPlayer,
|
@@ -125,6 +125,8 @@ export type AppInitState = {
|
|
125
125
|
zIndex?: number;
|
126
126
|
};
|
127
127
|
|
128
|
+
export type CursorMovePayload = { uid: string; state?: "leave"; position: Position };
|
129
|
+
|
128
130
|
export type EmitterEvent = {
|
129
131
|
onCreated: undefined;
|
130
132
|
InitReplay: AppInitState;
|
@@ -139,6 +141,8 @@ export type EmitterEvent = {
|
|
139
141
|
boxStateChange: string;
|
140
142
|
playgroundSizeChange: DOMRect;
|
141
143
|
onReconnected: void;
|
144
|
+
removeScenes: string;
|
145
|
+
cursorMove: CursorMovePayload;
|
142
146
|
};
|
143
147
|
|
144
148
|
export type EmitterType = Emittery<EmitterEvent>;
|
@@ -187,6 +191,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
187
191
|
private static isCreated = false;
|
188
192
|
|
189
193
|
public version = __APP_VERSION__;
|
194
|
+
public dependencies = __APP_DEPENDENCIES__;
|
190
195
|
|
191
196
|
public appListeners?: AppListeners;
|
192
197
|
|
@@ -205,6 +210,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
205
210
|
constructor(context: InvisiblePluginContext) {
|
206
211
|
super(context);
|
207
212
|
WindowManager.displayer = context.displayer;
|
213
|
+
(window as any).NETLESS_DEPS = __APP_DEPENDENCIES__;
|
208
214
|
}
|
209
215
|
|
210
216
|
public static async mount(params: MountParams): Promise<WindowManager> {
|
@@ -478,7 +484,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
478
484
|
/**
|
479
485
|
* 返回 mainView 的 ScenePath
|
480
486
|
*/
|
481
|
-
public getMainViewScenePath(): string {
|
487
|
+
public getMainViewScenePath(): string | undefined {
|
482
488
|
return this.appManager?.store.getMainViewScenePath();
|
483
489
|
}
|
484
490
|
|
@@ -526,6 +532,35 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
526
532
|
this.viewMode = mode;
|
527
533
|
}
|
528
534
|
|
535
|
+
public setBoxState(boxState: TeleBoxState): void {
|
536
|
+
if (!this.canOperate) return;
|
537
|
+
switch (boxState) {
|
538
|
+
case "normal":
|
539
|
+
this.setMaximized(false);
|
540
|
+
this.setMinimized(false);
|
541
|
+
break;
|
542
|
+
case "maximized":
|
543
|
+
this.setMaximized(true);
|
544
|
+
this.setMinimized(false);
|
545
|
+
break;
|
546
|
+
case "minimized":
|
547
|
+
this.setMinimized(true);
|
548
|
+
break;
|
549
|
+
default:
|
550
|
+
break;
|
551
|
+
}
|
552
|
+
}
|
553
|
+
|
554
|
+
public setMaximized(maximized: boolean): void {
|
555
|
+
if (!this.canOperate) return;
|
556
|
+
this.boxManager?.setMaximized(maximized, false);
|
557
|
+
}
|
558
|
+
|
559
|
+
public setMinimized(minimized: boolean): void {
|
560
|
+
if (!this.canOperate) return;
|
561
|
+
this.boxManager?.setMinimized(minimized, false);
|
562
|
+
}
|
563
|
+
|
529
564
|
public get mainView(): View {
|
530
565
|
if (this.appManager) {
|
531
566
|
return this.appManager.mainViewProxy.view;
|
@@ -589,7 +624,11 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
589
624
|
} else {
|
590
625
|
throw new Error("[WindowManager]: mainViewSceneDir not found");
|
591
626
|
}
|
592
|
-
}
|
627
|
+
}
|
628
|
+
|
629
|
+
public get topApp(): string | undefined {
|
630
|
+
return this.boxManager?.getTopBox()?.id;
|
631
|
+
}
|
593
632
|
|
594
633
|
/**
|
595
634
|
* 查询所有的 App
|
@@ -731,6 +770,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
731
770
|
}
|
732
771
|
}
|
733
772
|
}
|
773
|
+
|
774
|
+
private _removeScenes = (scenePath: string) => {
|
775
|
+
this.room.removeScenes(scenePath);
|
776
|
+
};
|
734
777
|
}
|
735
778
|
|
736
779
|
setupBuiltin();
|
package/src/shim.d.ts
CHANGED