@netless/window-manager 0.4.0-canary.1 → 0.4.0-canary.13
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/dist/App/MagixEvent/index.d.ts +29 -0
- package/dist/App/Storage/StorageEvent.d.ts +8 -0
- package/dist/App/Storage/index.d.ts +38 -0
- package/dist/App/Storage/typings.d.ts +21 -0
- package/dist/App/Storage/utils.d.ts +5 -0
- package/dist/AppContext.d.ts +40 -16
- package/dist/AppListener.d.ts +0 -1
- package/dist/AppManager.d.ts +8 -7
- package/dist/AppProxy.d.ts +3 -3
- package/dist/Base/Context.d.ts +0 -1
- package/dist/BoxManager.d.ts +1 -0
- package/dist/BuiltinApps.d.ts +6 -0
- package/dist/ContainerResizeObserver.d.ts +10 -0
- package/dist/Cursor/Cursor.d.ts +2 -3
- package/dist/Cursor/index.d.ts +7 -4
- package/dist/Helper.d.ts +6 -0
- package/dist/ReconnectRefresher.d.ts +5 -2
- package/dist/Utils/Common.d.ts +3 -1
- package/dist/Utils/Reactive.d.ts +1 -1
- package/dist/{MainView.d.ts → View/MainView.d.ts} +2 -4
- package/dist/View/ViewManager.d.ts +13 -0
- package/dist/constants.d.ts +1 -6
- package/dist/index.d.ts +14 -13
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/typings.d.ts +3 -2
- package/package.json +6 -5
- package/src/App/MagixEvent/index.ts +68 -0
- package/src/App/Storage/StorageEvent.ts +21 -0
- package/src/App/Storage/index.ts +284 -0
- package/src/App/Storage/typings.ts +21 -0
- package/src/App/Storage/utils.ts +17 -0
- package/src/AppContext.ts +65 -20
- package/src/AppListener.ts +1 -8
- package/src/AppManager.ts +68 -35
- package/src/AppProxy.ts +37 -46
- package/src/Base/Context.ts +0 -4
- package/src/BoxManager.ts +9 -7
- package/src/BuiltinApps.ts +24 -0
- package/src/ContainerResizeObserver.ts +62 -0
- package/src/Cursor/Cursor.ts +23 -34
- package/src/Cursor/index.ts +70 -41
- package/src/Helper.ts +30 -0
- package/src/ReconnectRefresher.ts +13 -5
- package/src/Utils/Common.ts +35 -13
- package/src/Utils/Reactive.ts +9 -3
- package/src/Utils/RoomHacker.ts +16 -0
- package/src/{MainView.ts → View/MainView.ts} +9 -25
- package/src/View/ViewManager.ts +53 -0
- package/src/constants.ts +1 -3
- package/src/index.ts +47 -86
- package/src/shim.d.ts +4 -0
- package/src/style.css +6 -0
- package/src/typings.ts +3 -2
- package/vite.config.js +4 -1
- package/dist/Utils/CameraStore.d.ts +0 -15
- package/dist/ViewManager.d.ts +0 -29
- package/dist/sdk.d.ts +0 -14
- package/src/Utils/CameraStore.ts +0 -72
- package/src/sdk.ts +0 -39
- package/src/viewManager.ts +0 -177
@@ -0,0 +1,62 @@
|
|
1
|
+
import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
|
2
|
+
import { WindowManager } from "./index";
|
3
|
+
import type { EmitterType} from "./index";
|
4
|
+
|
5
|
+
const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
|
6
|
+
|
7
|
+
export class ContainerResizeObserver {
|
8
|
+
private containerResizeObserver?: ResizeObserver;
|
9
|
+
|
10
|
+
constructor(private emitter: EmitterType) {}
|
11
|
+
|
12
|
+
public static create(
|
13
|
+
container: HTMLElement,
|
14
|
+
sizer: HTMLElement,
|
15
|
+
wrapper: HTMLDivElement,
|
16
|
+
emitter: EmitterType,
|
17
|
+
) {
|
18
|
+
const containerResizeObserver = new ContainerResizeObserver(emitter);
|
19
|
+
containerResizeObserver.observePlaygroundSize(container, sizer, wrapper);
|
20
|
+
return containerResizeObserver;
|
21
|
+
}
|
22
|
+
|
23
|
+
public observePlaygroundSize(
|
24
|
+
container: HTMLElement,
|
25
|
+
sizer: HTMLElement,
|
26
|
+
wrapper: HTMLDivElement
|
27
|
+
) {
|
28
|
+
this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
|
29
|
+
|
30
|
+
this.containerResizeObserver = new ResizeObserver(entries => {
|
31
|
+
const containerRect = entries[0]?.contentRect;
|
32
|
+
if (containerRect) {
|
33
|
+
this.updateSizer(containerRect, sizer, wrapper);
|
34
|
+
this.emitter.emit("playgroundSizeChange", containerRect)
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
this.containerResizeObserver.observe(container);
|
39
|
+
}
|
40
|
+
|
41
|
+
private updateSizer(
|
42
|
+
{ width, height }: DOMRectReadOnly,
|
43
|
+
sizer: HTMLElement,
|
44
|
+
wrapper: HTMLDivElement
|
45
|
+
) {
|
46
|
+
if (width && height) {
|
47
|
+
if (height / width > WindowManager.containerSizeRatio) {
|
48
|
+
height = width * WindowManager.containerSizeRatio;
|
49
|
+
sizer.classList.toggle("netless-window-manager-sizer-horizontal", true);
|
50
|
+
} else {
|
51
|
+
width = height / WindowManager.containerSizeRatio;
|
52
|
+
sizer.classList.toggle("netless-window-manager-sizer-horizontal", false);
|
53
|
+
}
|
54
|
+
wrapper.style.width = `${width}px`;
|
55
|
+
wrapper.style.height = `${height}px`;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
public disconnect() {
|
60
|
+
this.containerResizeObserver?.disconnect();
|
61
|
+
}
|
62
|
+
}
|
package/src/Cursor/Cursor.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import App from './Cursor.svelte';
|
2
|
-
import pRetry from 'p-retry';
|
3
2
|
import { ApplianceMap } from './icons';
|
4
|
-
import { ApplianceNames
|
3
|
+
import { ApplianceNames } from 'white-web-sdk';
|
5
4
|
import { CursorState } from '../constants';
|
6
5
|
import { Fields } from '../AttributesDelegate';
|
7
6
|
import { get, omit } from 'lodash';
|
@@ -19,54 +18,44 @@ export type Payload = {
|
|
19
18
|
|
20
19
|
export class Cursor extends Base {
|
21
20
|
private member?: RoomMember;
|
22
|
-
private disposer: any;
|
23
21
|
private timer?: number;
|
24
22
|
private component?: SvelteComponent;
|
25
23
|
|
26
24
|
constructor(
|
27
25
|
manager: AppManager,
|
26
|
+
addCursorChangeListener: (uid: string, callback: (position: Position, state: CursorState) => void) => void,
|
28
27
|
private cursors: any,
|
29
28
|
private memberId: string,
|
30
29
|
private cursorManager: CursorManager,
|
31
|
-
private wrapper?: HTMLElement
|
30
|
+
private wrapper?: HTMLElement,
|
32
31
|
) {
|
33
32
|
super(manager);
|
34
33
|
this.setMember();
|
35
34
|
this.createCursor();
|
36
|
-
|
37
|
-
this.disposer && this.disposer();
|
38
|
-
if (!this.cursorPosition) {
|
39
|
-
console.warn(`${memberId} not exist`);
|
40
|
-
}
|
41
|
-
this.startReaction();
|
42
|
-
}, { retries: 3 });
|
35
|
+
addCursorChangeListener(this.memberId, this.onCursorChange);
|
43
36
|
this.autoHidden();
|
44
37
|
}
|
45
38
|
|
46
|
-
private
|
47
|
-
|
48
|
-
const
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
const rect = this.cursorManager.wrapperRect;
|
53
|
-
if (this.component && rect) {
|
54
|
-
this.autoHidden();
|
55
|
-
this.moveCursor(cursor, rect, this.manager.mainView);
|
56
|
-
}
|
57
|
-
} else {
|
58
|
-
const focusView = this.cursorManager.focusView;
|
59
|
-
const viewRect = focusView?.divElement?.getBoundingClientRect();
|
60
|
-
const viewCamera = focusView?.camera;
|
61
|
-
if (focusView && viewRect && viewCamera && this.component) {
|
62
|
-
this.autoHidden();
|
63
|
-
this.moveCursor(cursor, viewRect, focusView);
|
64
|
-
}
|
39
|
+
private onCursorChange = (position: Position, state: CursorState) => {
|
40
|
+
if (position.type === "main") {
|
41
|
+
const rect = this.cursorManager.wrapperRect;
|
42
|
+
if (this.component && rect) {
|
43
|
+
this.autoHidden();
|
44
|
+
this.moveCursor(position, rect, this.manager.mainView);
|
65
45
|
}
|
66
|
-
|
67
|
-
|
46
|
+
} else {
|
47
|
+
const focusView = this.cursorManager.focusView;
|
48
|
+
// TODO 可以存一个当前 focusView 的 Rect 这样只有 focus 切换的时候才调用 getBoundingClientRect
|
49
|
+
const viewRect = focusView?.divElement?.getBoundingClientRect();
|
50
|
+
const viewCamera = focusView?.camera;
|
51
|
+
if (focusView && viewRect && viewCamera && this.component) {
|
52
|
+
this.autoHidden();
|
53
|
+
this.moveCursor(position, viewRect, focusView);
|
68
54
|
}
|
69
|
-
}
|
55
|
+
}
|
56
|
+
if (state && state === CursorState.Leave) {
|
57
|
+
this.hide();
|
58
|
+
}
|
70
59
|
}
|
71
60
|
|
72
61
|
private moveCursor(cursor: Position, rect: DOMRect, view: any) {
|
@@ -196,10 +185,10 @@ export class Cursor extends Base {
|
|
196
185
|
}
|
197
186
|
|
198
187
|
public destroy() {
|
199
|
-
this.disposer && this.disposer();
|
200
188
|
if (this.component) {
|
201
189
|
this.component.$destroy();
|
202
190
|
}
|
191
|
+
this.manager.refresher?.remove(this.memberId);
|
203
192
|
this.cursorManager.cursorInstances.delete(this.memberId);
|
204
193
|
}
|
205
194
|
|
package/src/Cursor/index.ts
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import
|
1
|
+
import { autorun } from "white-web-sdk";
|
2
|
+
import { Base } from "../Base";
|
3
|
+
import { compact, debounce, get, uniq } from "lodash";
|
4
|
+
import { Cursor } from "./Cursor";
|
5
|
+
import { CursorState } from "../constants";
|
6
|
+
import { emitter, WindowManager } from "../index";
|
7
|
+
import { Fields } from "../AttributesDelegate";
|
8
|
+
import { onObjectInserted } from "../Utils/Reactive";
|
9
|
+
import { SideEffectManager } from "side-effect-manager";
|
10
|
+
import type { PositionType, Position } from "../AttributesDelegate";
|
9
11
|
import type { Point, RoomMember, View } from "white-web-sdk";
|
10
12
|
import type { AppManager } from "../AppManager";
|
11
13
|
|
@@ -18,32 +20,42 @@ export type MoveCursorParams = {
|
|
18
20
|
uid: string;
|
19
21
|
x: number;
|
20
22
|
y: number;
|
21
|
-
}
|
23
|
+
};
|
22
24
|
export class CursorManager extends Base {
|
23
25
|
public containerRect?: DOMRect;
|
24
26
|
public wrapperRect?: DOMRect;
|
25
27
|
public cursorInstances: Map<string, Cursor> = new Map();
|
26
28
|
public roomMembers?: readonly RoomMember[];
|
27
29
|
private mainViewElement?: HTMLDivElement;
|
30
|
+
private sideEffectManager = new SideEffectManager();
|
28
31
|
|
29
32
|
constructor(private appManager: AppManager) {
|
30
33
|
super(appManager);
|
31
34
|
this.roomMembers = this.appManager.room?.state.roomMembers;
|
32
35
|
const wrapper = WindowManager.wrapper;
|
33
36
|
if (wrapper) {
|
34
|
-
|
37
|
+
this.setupWrapper(wrapper);
|
35
38
|
}
|
39
|
+
emitter.on("onReconnected", () => {
|
40
|
+
this.onReconnect();
|
41
|
+
});
|
36
42
|
}
|
37
43
|
|
38
44
|
public setupWrapper(wrapper: HTMLElement) {
|
39
45
|
if (this.manager.refresher?.hasReactor("cursors")) {
|
40
46
|
this.destroy();
|
41
47
|
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
this.sideEffectManager.add(() => {
|
49
|
+
wrapper.addEventListener("pointerenter", this.mouseMoveListener);
|
50
|
+
wrapper.addEventListener("pointermove", this.mouseMoveListener);
|
51
|
+
wrapper.addEventListener("pointerleave", this.mouseLeaveListener);
|
52
|
+
return () => {
|
53
|
+
wrapper.removeEventListener("pointerenter", this.mouseMoveListener);
|
54
|
+
wrapper.removeEventListener("pointermove", this.mouseMoveListener);
|
55
|
+
wrapper.removeEventListener("pointerleave", this.mouseLeaveListener);
|
56
|
+
};
|
57
|
+
});
|
58
|
+
|
47
59
|
this.initCursorAttributes();
|
48
60
|
this.wrapperRect = wrapper.getBoundingClientRect();
|
49
61
|
this.startReaction(wrapper);
|
@@ -58,27 +70,25 @@ export class CursorManager extends Base {
|
|
58
70
|
return onObjectInserted(this.cursors, () => {
|
59
71
|
this.handleRoomMembersChange(wrapper);
|
60
72
|
});
|
61
|
-
})
|
73
|
+
});
|
62
74
|
}
|
63
75
|
|
64
76
|
private getUids = (members: readonly RoomMember[] | undefined) => {
|
65
77
|
return compact(uniq(members?.map(member => member.payload?.uid)));
|
66
|
-
}
|
78
|
+
};
|
67
79
|
|
68
80
|
private handleRoomMembersChange = debounce((wrapper: HTMLElement) => {
|
69
81
|
const uids = this.getUids(this.roomMembers);
|
70
82
|
const cursors = Object.keys(this.cursors);
|
71
83
|
if (uids?.length) {
|
72
84
|
cursors.map(uid => {
|
73
|
-
if (
|
74
|
-
uids.includes(uid) &&
|
75
|
-
!this.cursorInstances.has(uid)
|
76
|
-
) {
|
85
|
+
if (uids.includes(uid) && !this.cursorInstances.has(uid)) {
|
77
86
|
if (uid === this.context.uid) {
|
78
87
|
return;
|
79
88
|
}
|
80
89
|
const component = new Cursor(
|
81
90
|
this.appManager,
|
91
|
+
this.addCursorChangeListener,
|
82
92
|
this.cursors,
|
83
93
|
uid,
|
84
94
|
this,
|
@@ -86,7 +96,7 @@ export class CursorManager extends Base {
|
|
86
96
|
);
|
87
97
|
this.cursorInstances.set(uid, component);
|
88
98
|
}
|
89
|
-
})
|
99
|
+
});
|
90
100
|
}
|
91
101
|
}, 100);
|
92
102
|
|
@@ -106,13 +116,6 @@ export class CursorManager extends Base {
|
|
106
116
|
this.updateCursor(this.getType(event), event.clientX, event.clientY);
|
107
117
|
}, 5);
|
108
118
|
|
109
|
-
private touchMoveListener = debounce((event: TouchEvent) => {
|
110
|
-
if (event.touches.length === 1) {
|
111
|
-
const touchEvent = event.touches[0];
|
112
|
-
this.updateCursor(this.getType(touchEvent), touchEvent.clientX, touchEvent.clientY);
|
113
|
-
}
|
114
|
-
}, 5);
|
115
|
-
|
116
119
|
private updateCursor(event: EventType, clientX: number, clientY: number) {
|
117
120
|
if (this.wrapperRect && this.manager.canOperate) {
|
118
121
|
const view = event.type === "main" ? this.appManager.mainView : this.focusView;
|
@@ -128,7 +131,11 @@ export class CursorManager extends Base {
|
|
128
131
|
}
|
129
132
|
}
|
130
133
|
|
131
|
-
private getPoint = (
|
134
|
+
private getPoint = (
|
135
|
+
view: View | undefined,
|
136
|
+
clientX: number,
|
137
|
+
clientY: number
|
138
|
+
): Point | undefined => {
|
132
139
|
const rect = view?.divElement?.getBoundingClientRect();
|
133
140
|
if (rect) {
|
134
141
|
const point = view?.convertToPointInWorld({
|
@@ -137,7 +144,7 @@ export class CursorManager extends Base {
|
|
137
144
|
});
|
138
145
|
return point;
|
139
146
|
}
|
140
|
-
}
|
147
|
+
};
|
141
148
|
|
142
149
|
/**
|
143
150
|
* 因为窗口内框在不同分辨率下的大小不一样,所以这里通过来鼠标事件的 target 来判断是在主白板还是在 APP 中
|
@@ -147,7 +154,7 @@ export class CursorManager extends Base {
|
|
147
154
|
const focusApp = this.appManager.focusApp;
|
148
155
|
switch (target.parentElement) {
|
149
156
|
case this.mainViewElement: {
|
150
|
-
return { type: "main" };
|
157
|
+
return { type: "main" };
|
151
158
|
}
|
152
159
|
case focusApp?.view?.divElement: {
|
153
160
|
return { type: "app" };
|
@@ -224,19 +231,41 @@ export class CursorManager extends Base {
|
|
224
231
|
});
|
225
232
|
}
|
226
233
|
|
227
|
-
public
|
228
|
-
const wrapper = WindowManager.wrapper;
|
229
|
-
if (wrapper) {
|
230
|
-
wrapper.removeEventListener("mousemove", this.mouseMoveListener);
|
231
|
-
wrapper.removeEventListener("touchstart", this.touchMoveListener);
|
232
|
-
wrapper.removeEventListener("touchmove", this.touchMoveListener);
|
233
|
-
wrapper.removeEventListener("mouseleave", this.mouseLeaveListener);
|
234
|
-
wrapper.removeEventListener("touchend", this.mouseLeaveListener);
|
235
|
-
}
|
234
|
+
public onReconnect() {
|
236
235
|
if (this.cursorInstances.size) {
|
237
236
|
this.cursorInstances.forEach(cursor => cursor.destroy());
|
238
237
|
this.cursorInstances.clear();
|
239
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
|
+
public destroy() {
|
262
|
+
this.sideEffectManager.flushAll();
|
263
|
+
if (this.cursorInstances.size) {
|
264
|
+
this.cursorInstances.forEach(cursor => {
|
265
|
+
cursor.destroy();
|
266
|
+
});
|
267
|
+
this.cursorInstances.clear();
|
268
|
+
}
|
240
269
|
this.manager.refresher?.remove("cursors");
|
241
270
|
}
|
242
271
|
}
|
package/src/Helper.ts
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
import { WindowManager } from "./index";
|
2
|
+
|
3
|
+
export const setupWrapper = (
|
4
|
+
root: HTMLElement
|
5
|
+
): {
|
6
|
+
playground: HTMLDivElement;
|
7
|
+
wrapper: HTMLDivElement;
|
8
|
+
sizer: HTMLDivElement;
|
9
|
+
mainViewElement: HTMLDivElement;
|
10
|
+
} => {
|
11
|
+
const playground = document.createElement("div");
|
12
|
+
playground.className = "netless-window-manager-playground";
|
13
|
+
|
14
|
+
const sizer = document.createElement("div");
|
15
|
+
sizer.className = "netless-window-manager-sizer";
|
16
|
+
|
17
|
+
const wrapper = document.createElement("div");
|
18
|
+
wrapper.className = "netless-window-manager-wrapper";
|
19
|
+
|
20
|
+
const mainViewElement = document.createElement("div");
|
21
|
+
mainViewElement.className = "netless-window-manager-main-view";
|
22
|
+
|
23
|
+
playground.appendChild(sizer);
|
24
|
+
sizer.appendChild(wrapper);
|
25
|
+
wrapper.appendChild(mainViewElement);
|
26
|
+
root.appendChild(playground);
|
27
|
+
WindowManager.wrapper = wrapper;
|
28
|
+
|
29
|
+
return { playground, wrapper, sizer, mainViewElement };
|
30
|
+
};
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
1
|
+
import { debounce, isFunction } from "lodash";
|
2
2
|
import { log } from "./Utils/log";
|
3
3
|
import { RoomPhase } from "white-web-sdk";
|
4
4
|
import type { Room } from "white-web-sdk";
|
5
|
+
import type { EmitterType } from "./index";
|
5
6
|
|
6
7
|
export type ReconnectRefresherContext = {
|
7
|
-
|
8
|
-
}
|
8
|
+
emitter: EmitterType;
|
9
|
+
};
|
9
10
|
|
10
11
|
// 白板重连之后会刷新所有的对象,导致 listener 失效, 所以这里在重连之后重新对所有对象进行监听
|
11
12
|
export class ReconnectRefresher {
|
@@ -14,12 +15,19 @@ export class ReconnectRefresher {
|
|
14
15
|
private reactors: Map<string, any> = new Map();
|
15
16
|
private disposers: Map<string, any> = new Map();
|
16
17
|
|
17
|
-
constructor(
|
18
|
+
constructor(private ctx: ReconnectRefresherContext) {}
|
19
|
+
|
20
|
+
public setRoom(room: Room | undefined) {
|
18
21
|
this.room = room;
|
19
22
|
this.phase = room?.phase;
|
23
|
+
room?.callbacks.off("onPhaseChanged", this.onPhaseChanged);
|
20
24
|
room?.callbacks.on("onPhaseChanged", this.onPhaseChanged);
|
21
25
|
}
|
22
26
|
|
27
|
+
public setContext(ctx: ReconnectRefresherContext) {
|
28
|
+
this.ctx = ctx;
|
29
|
+
}
|
30
|
+
|
23
31
|
private onPhaseChanged = (phase: RoomPhase) => {
|
24
32
|
if (phase === RoomPhase.Connected && this.phase === RoomPhase.Reconnecting) {
|
25
33
|
this.onReconnected();
|
@@ -35,7 +43,7 @@ export class ReconnectRefresher {
|
|
35
43
|
this.disposers.set(id, func());
|
36
44
|
}
|
37
45
|
});
|
38
|
-
this.ctx.
|
46
|
+
this.ctx.emitter.emit("onReconnected", undefined);
|
39
47
|
}, 3000);
|
40
48
|
|
41
49
|
private releaseDisposers() {
|
package/src/Utils/Common.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { appRegister } from
|
2
|
-
import { debounce } from
|
3
|
-
import { emitter } from
|
4
|
-
import { v4 } from
|
1
|
+
import { appRegister } from "../Register";
|
2
|
+
import { debounce } from "lodash";
|
3
|
+
import { emitter } from "../index";
|
4
|
+
import { v4 } from "uuid";
|
5
5
|
import type { PublicEvent } from "../index";
|
6
6
|
import type { Displayer, ViewVisionMode, Room, View } from "white-web-sdk";
|
7
7
|
import type Emittery from "emittery";
|
@@ -26,7 +26,21 @@ export const setScenePath = (room: Room | undefined, scenePath: string) => {
|
|
26
26
|
room.setScenePath(scenePath);
|
27
27
|
}
|
28
28
|
}
|
29
|
-
}
|
29
|
+
};
|
30
|
+
|
31
|
+
export const getScenePath = (
|
32
|
+
room: Room | undefined,
|
33
|
+
dir: string | undefined,
|
34
|
+
index: number
|
35
|
+
): string | undefined => {
|
36
|
+
if (room && dir) {
|
37
|
+
const scenes = entireScenes(room);
|
38
|
+
const scene = scenes[dir]?.[index];
|
39
|
+
if (scene) {
|
40
|
+
return `${dir}/${scene.name}`;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
};
|
30
44
|
|
31
45
|
export const setViewMode = (view: View, mode: ViewVisionMode) => {
|
32
46
|
if (!(view as any).didRelease && view.mode !== mode) {
|
@@ -44,7 +58,7 @@ export const emitError = (error: Error) => {
|
|
44
58
|
|
45
59
|
export const addEmitterOnceListener = (event: any, listener: any) => {
|
46
60
|
emitter.once(event).then(listener);
|
47
|
-
}
|
61
|
+
};
|
48
62
|
|
49
63
|
export const notifyMainViewModeChange = debounce(
|
50
64
|
(callbacks: Emittery<PublicEvent>, mode: ViewVisionMode) => {
|
@@ -53,9 +67,10 @@ export const notifyMainViewModeChange = debounce(
|
|
53
67
|
200
|
54
68
|
);
|
55
69
|
|
56
|
-
export const makeValidScenePath = (displayer: Displayer, scenePath: string) => {
|
57
|
-
const scenes =
|
58
|
-
|
70
|
+
export const makeValidScenePath = (displayer: Displayer, scenePath: string, index = 0) => {
|
71
|
+
const scenes = entireScenes(displayer)[scenePath];
|
72
|
+
if (!scenes) return;
|
73
|
+
const firstSceneName = scenes[index].name;
|
59
74
|
if (scenePath === "/") {
|
60
75
|
return `/${firstSceneName}`;
|
61
76
|
} else {
|
@@ -63,9 +78,13 @@ export const makeValidScenePath = (displayer: Displayer, scenePath: string) => {
|
|
63
78
|
}
|
64
79
|
};
|
65
80
|
|
81
|
+
export const entireScenes = (displayer: Displayer) => {
|
82
|
+
return displayer.entireScenes();
|
83
|
+
};
|
84
|
+
|
66
85
|
export const isValidScenePath = (scenePath: string) => {
|
67
86
|
return scenePath.startsWith("/");
|
68
|
-
}
|
87
|
+
};
|
69
88
|
|
70
89
|
export const ensureValidScenePath = (scenePath: string) => {
|
71
90
|
if (scenePath.endsWith("/")) {
|
@@ -73,11 +92,14 @@ export const ensureValidScenePath = (scenePath: string) => {
|
|
73
92
|
} else {
|
74
93
|
return scenePath;
|
75
94
|
}
|
76
|
-
}
|
95
|
+
};
|
77
96
|
|
78
97
|
export const getVersionNumber = (version: string) => {
|
79
|
-
const versionString = version
|
98
|
+
const versionString = version
|
99
|
+
.split(".")
|
100
|
+
.map(s => s.padStart(2, "0"))
|
101
|
+
.join("");
|
80
102
|
return parseInt(versionString);
|
81
103
|
};
|
82
104
|
|
83
|
-
export const wait = (time: number) => new Promise(
|
105
|
+
export const wait = (time: number) => new Promise(resolve => setTimeout(resolve, time));
|
package/src/Utils/Reactive.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { listenUpdated, unlistenUpdated, reaction, UpdateEventKind } from "white-web-sdk";
|
2
2
|
import type { AkkoObjectUpdatedProperty , AkkoObjectUpdatedListener } from "white-web-sdk";
|
3
|
+
import { isObject } from "lodash";
|
3
4
|
|
4
5
|
// 兼容 13 和 14 版本 SDK
|
5
6
|
export const onObjectByEvent = (event: UpdateEventKind) => {
|
@@ -30,7 +31,8 @@ export const onObjectByEvent = (event: UpdateEventKind) => {
|
|
30
31
|
|
31
32
|
export const safeListenPropsUpdated = <T>(
|
32
33
|
getProps: () => T,
|
33
|
-
callback: AkkoObjectUpdatedListener<T
|
34
|
+
callback: AkkoObjectUpdatedListener<T>,
|
35
|
+
onDestroyed?: (props: unknown) => void
|
34
36
|
) => {
|
35
37
|
let disposeListenUpdated: (() => void) | null = null;
|
36
38
|
const disposeReaction = reaction(
|
@@ -41,8 +43,12 @@ export const safeListenPropsUpdated = <T>(
|
|
41
43
|
disposeListenUpdated = null;
|
42
44
|
}
|
43
45
|
const props = getProps();
|
44
|
-
|
45
|
-
|
46
|
+
if (isObject(props)) {
|
47
|
+
disposeListenUpdated = () => unlistenUpdated(props, callback);
|
48
|
+
listenUpdated(props, callback);
|
49
|
+
} else {
|
50
|
+
onDestroyed?.(props);
|
51
|
+
}
|
46
52
|
},
|
47
53
|
{ fireImmediately: true }
|
48
54
|
);
|
package/src/Utils/RoomHacker.ts
CHANGED
@@ -29,6 +29,18 @@ export const replaceRoomFunction = (room: Room, manager: WindowManager) => {
|
|
29
29
|
},
|
30
30
|
});
|
31
31
|
|
32
|
+
Object.defineProperty(room, "canUndoSteps", {
|
33
|
+
get() {
|
34
|
+
return manager.mainView.canUndoSteps;
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
Object.defineProperty(room, "canRedoSteps", {
|
39
|
+
get() {
|
40
|
+
return manager.mainView.canRedoSteps;
|
41
|
+
}
|
42
|
+
});
|
43
|
+
|
32
44
|
room.moveCamera = (camera: Camera) => manager.mainView.moveCamera(camera);
|
33
45
|
room.moveCameraToContain = (...args) => manager.moveCameraToContain(...args);
|
34
46
|
room.convertToPointInWorld = (...args) => manager.mainView.convertToPointInWorld(...args);
|
@@ -36,6 +48,10 @@ export const replaceRoomFunction = (room: Room, manager: WindowManager) => {
|
|
36
48
|
room.scenePreview = (...args) => manager.mainView.scenePreview(...args);
|
37
49
|
room.fillSceneSnapshot = (...args) => manager.mainView.fillSceneSnapshot(...args);
|
38
50
|
room.generateScreenshot = (...args) => manager.mainView.generateScreenshot(...args);
|
51
|
+
room.setMemberState = (...args) => manager.mainView.setMemberState(...args);
|
52
|
+
room.redo = () => manager.mainView.redo();
|
53
|
+
room.undo = () => manager.mainView.undo();
|
54
|
+
room.cleanCurrentScene = () => manager.mainView.cleanCurrentScene();
|
39
55
|
}
|
40
56
|
|
41
57
|
};
|