@netless/window-manager 0.4.0-canary.6 → 0.4.0-canary.7
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/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/{App → src/App}/Storage/StorageEvent.d.ts +0 -0
- package/dist/{App → src/App}/Storage/index.d.ts +0 -0
- package/dist/{App → src/App}/Storage/typings.d.ts +3 -0
- package/dist/{App → src/App}/Storage/utils.d.ts +0 -0
- package/dist/{AppContext.d.ts → src/AppContext.d.ts} +0 -0
- package/dist/{AppListener.d.ts → src/AppListener.d.ts} +0 -1
- package/dist/{AppManager.d.ts → src/AppManager.d.ts} +3 -4
- package/dist/{AppProxy.d.ts → src/AppProxy.d.ts} +2 -3
- package/dist/{AttributesDelegate.d.ts → src/AttributesDelegate.d.ts} +0 -0
- package/dist/{Base → src/Base}/Context.d.ts +0 -1
- package/dist/{Base → src/Base}/index.d.ts +0 -0
- package/dist/{BoxManager.d.ts → src/BoxManager.d.ts} +2 -1
- package/dist/src/BuiltinApps.d.ts +6 -0
- package/dist/src/ContainerResizeObserver.d.ts +10 -0
- package/dist/{Cursor → src/Cursor}/Cursor.d.ts +0 -0
- package/dist/{Cursor → src/Cursor}/icons.d.ts +0 -0
- package/dist/{Cursor → src/Cursor}/index.d.ts +0 -0
- package/dist/src/Helper.d.ts +6 -0
- package/dist/{ReconnectRefresher.d.ts → src/ReconnectRefresher.d.ts} +0 -0
- package/dist/{Register → src/Register}/index.d.ts +0 -0
- package/dist/{Register → src/Register}/loader.d.ts +0 -0
- package/dist/{Register → src/Register}/storage.d.ts +0 -0
- package/dist/{Utils → src/Utils}/Common.d.ts +3 -1
- package/dist/{Utils → src/Utils}/Reactive.d.ts +0 -0
- package/dist/{Utils → src/Utils}/RoomHacker.d.ts +0 -0
- package/dist/{Utils → src/Utils}/error.d.ts +0 -0
- package/dist/{Utils → src/Utils}/log.d.ts +0 -0
- package/dist/{MainView.d.ts → src/View/MainView.d.ts} +2 -4
- package/dist/src/View/ViewManager.d.ts +13 -0
- package/dist/{constants.d.ts → src/constants.d.ts} +0 -5
- package/dist/{index.d.ts → src/index.d.ts} +3 -10
- package/dist/{typings.d.ts → src/typings.d.ts} +1 -0
- package/dist/style.css +1 -1
- package/package.json +3 -3
- package/src/App/Storage/index.ts +2 -2
- package/src/App/Storage/typings.ts +6 -0
- package/src/AppContext.ts +0 -1
- package/src/AppListener.ts +0 -8
- package/src/AppManager.ts +31 -25
- package/src/AppProxy.ts +14 -36
- 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/Helper.ts +30 -0
- package/src/Utils/Common.ts +35 -13
- package/src/{MainView.ts → View/MainView.ts} +7 -25
- package/src/View/ViewManager.ts +53 -0
- package/src/constants.ts +0 -2
- package/src/index.ts +16 -67
- package/src/style.css +6 -0
- package/src/typings.ts +1 -0
- 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
package/src/AppProxy.ts
CHANGED
@@ -2,16 +2,15 @@ import Emittery from "emittery";
|
|
2
2
|
import { AppAttributes, AppEvents, Events } from "./constants";
|
3
3
|
import { AppContext } from "./AppContext";
|
4
4
|
import { appRegister } from "./Register";
|
5
|
-
import { autorun
|
6
|
-
import {
|
5
|
+
import { autorun } from "white-web-sdk";
|
6
|
+
import { emitter } from "./index";
|
7
7
|
import { Fields } from "./AttributesDelegate";
|
8
8
|
import { get } from "lodash";
|
9
9
|
import { log } from "./Utils/log";
|
10
10
|
import {
|
11
|
-
notifyMainViewModeChange,
|
12
11
|
setScenePath,
|
13
12
|
setViewFocusScenePath,
|
14
|
-
|
13
|
+
getScenePath
|
15
14
|
} from "./Utils/Common";
|
16
15
|
import type {
|
17
16
|
AppEmitterEvent,
|
@@ -37,7 +36,6 @@ export class AppProxy extends Base {
|
|
37
36
|
private boxManager = this.manager.boxManager;
|
38
37
|
private appProxies = this.manager.appProxies;
|
39
38
|
private viewManager = this.manager.viewManager;
|
40
|
-
private cameraStore = this.manager.cameraStore;
|
41
39
|
private kind: string;
|
42
40
|
public isAddApp: boolean;
|
43
41
|
private status: "normal" | "destroyed" = "normal";
|
@@ -98,17 +96,25 @@ export class AppProxy extends Base {
|
|
98
96
|
|
99
97
|
public getFullScenePath(): string | undefined {
|
100
98
|
if (this.scenePath) {
|
101
|
-
return get(this.appAttributes, [Fields.FullPath], this.
|
99
|
+
return get(this.appAttributes, [Fields.FullPath], this.getFullScenePathFromScenes());
|
102
100
|
}
|
103
101
|
}
|
104
102
|
|
103
|
+
private getFullScenePathFromScenes() {
|
104
|
+
const sceneIndex = get(this.appAttributes, ["state", "SceneIndex"], 0);
|
105
|
+
const fullPath = getScenePath(this.manager.room, this.scenePath, sceneIndex);
|
106
|
+
if (fullPath) {
|
107
|
+
this.setFullPath(fullPath);
|
108
|
+
}
|
109
|
+
return fullPath;
|
110
|
+
}
|
111
|
+
|
105
112
|
public setFullPath(path: string) {
|
106
113
|
this.manager.safeUpdateAttributes(["apps", this.id, Fields.FullPath], path);
|
107
114
|
}
|
108
115
|
|
109
116
|
public async baseInsertApp(
|
110
117
|
skipUpdate = false,
|
111
|
-
focus?: boolean
|
112
118
|
): Promise<{ appId: string; app: NetlessApp }> {
|
113
119
|
const params = this.params;
|
114
120
|
if (!params.kind) {
|
@@ -122,9 +128,6 @@ export class AppProxy extends Base {
|
|
122
128
|
throw new Error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
|
123
129
|
}
|
124
130
|
this.context.updateManagerRect();
|
125
|
-
if (focus) {
|
126
|
-
this.focusApp();
|
127
|
-
}
|
128
131
|
return {
|
129
132
|
appId: this.id,
|
130
133
|
app: appImpl,
|
@@ -133,7 +136,6 @@ export class AppProxy extends Base {
|
|
133
136
|
|
134
137
|
private focusApp() {
|
135
138
|
this.focusBox();
|
136
|
-
this.context.switchAppToWriter(this.id);
|
137
139
|
this.store.setMainViewFocusPath(this.manager.mainView);
|
138
140
|
}
|
139
141
|
|
@@ -205,9 +207,6 @@ export class AppProxy extends Base {
|
|
205
207
|
|
206
208
|
private afterSetupApp(boxInitState: AppInitState | undefined): void {
|
207
209
|
if (boxInitState) {
|
208
|
-
if (boxInitState.focus && this.scenePath) {
|
209
|
-
this.context.switchAppToWriter(this.id);
|
210
|
-
}
|
211
210
|
if (!boxInitState?.x || !boxInitState.y) {
|
212
211
|
this.boxManager?.setBoxInitState(this.id);
|
213
212
|
}
|
@@ -226,29 +225,10 @@ export class AppProxy extends Base {
|
|
226
225
|
await this.destroy(true, false, true);
|
227
226
|
const params = this.params;
|
228
227
|
const appProxy = new AppProxy(params, this.manager, this.id, this.isAddApp);
|
229
|
-
await appProxy.baseInsertApp(true
|
228
|
+
await appProxy.baseInsertApp(true);
|
230
229
|
this.boxManager?.updateBoxState(currentAppState);
|
231
230
|
}
|
232
231
|
|
233
|
-
public switchToWritable() {
|
234
|
-
appRegister.notifyApp(this.kind, "focus", { appId: this.id });
|
235
|
-
this.cameraStore.switchView(this.id, this.view, () => {
|
236
|
-
if (this.view) {
|
237
|
-
if (this.view.mode === ViewVisionMode.Writable) return;
|
238
|
-
try {
|
239
|
-
if (this.manager.mainView.mode === ViewVisionMode.Writable) {
|
240
|
-
this.store.setMainViewFocusPath(this.manager.mainView);
|
241
|
-
notifyMainViewModeChange(callbacks, ViewVisionMode.Freedom);
|
242
|
-
setViewMode(this.manager.mainView, ViewVisionMode.Freedom);
|
243
|
-
}
|
244
|
-
setViewMode(this.view, ViewVisionMode.Writable);
|
245
|
-
} catch (error) {
|
246
|
-
log("switch view failed", error);
|
247
|
-
}
|
248
|
-
}
|
249
|
-
});
|
250
|
-
}
|
251
|
-
|
252
232
|
public getAppInitState = (id: string) => {
|
253
233
|
const attrs = this.store.getAppState(id);
|
254
234
|
if (!attrs) return;
|
@@ -364,7 +344,6 @@ export class AppProxy extends Base {
|
|
364
344
|
|
365
345
|
private async createView(): Promise<View> {
|
366
346
|
const view = await this.viewManager.createView(this.id);
|
367
|
-
this.cameraStore.register(this.id, view);
|
368
347
|
this.setViewFocusScenePath();
|
369
348
|
return view;
|
370
349
|
}
|
@@ -388,7 +367,6 @@ export class AppProxy extends Base {
|
|
388
367
|
this.store.cleanAppAttributes(this.id);
|
389
368
|
}
|
390
369
|
this.appProxies.delete(this.id);
|
391
|
-
this.cameraStore.unregister(this.id, this.view);
|
392
370
|
|
393
371
|
this.viewManager.destroyView(this.id);
|
394
372
|
this.manager.appStatus.delete(this.id);
|
package/src/Base/Context.ts
CHANGED
package/src/BoxManager.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AppAttributes,
|
1
|
+
import { AppAttributes, Events, MIN_HEIGHT, MIN_WIDTH } from "./constants";
|
2
2
|
import { debounce, maxBy } from "lodash";
|
3
3
|
import {
|
4
4
|
TELE_BOX_MANAGER_EVENT,
|
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
TeleBoxCollector,
|
7
7
|
TeleBoxManager,
|
8
8
|
} from "@netless/telebox-insider";
|
9
|
-
import { WindowManager } from "./index";
|
9
|
+
import { emitter, WindowManager } from "./index";
|
10
10
|
import type { AddAppOptions, AppInitState, EmitterType, CallbacksType } from "./index";
|
11
11
|
import type {
|
12
12
|
TeleBoxManagerUpdateConfig,
|
@@ -145,6 +145,11 @@ export class BoxManager {
|
|
145
145
|
this.teleBoxManager.events.on("z_index", box => {
|
146
146
|
this.context.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
|
147
147
|
});
|
148
|
+
emitter.on("playgroundSizeChange", this.playgroundSizeChangeListener);
|
149
|
+
}
|
150
|
+
|
151
|
+
private playgroundSizeChangeListener = () => {
|
152
|
+
this.updateManagerRect();
|
148
153
|
}
|
149
154
|
|
150
155
|
private get mainView() {
|
@@ -251,12 +256,8 @@ export class BoxManager {
|
|
251
256
|
}
|
252
257
|
|
253
258
|
public setCollectorContainer(container: HTMLElement) {
|
254
|
-
const styles = {
|
255
|
-
...DEFAULT_COLLECTOR_STYLE,
|
256
|
-
...this.createTeleBoxManagerConfig?.collectorStyles,
|
257
|
-
};
|
258
259
|
const collector = new TeleBoxCollector({
|
259
|
-
styles
|
260
|
+
styles: this.createTeleBoxManagerConfig?.collectorStyles,
|
260
261
|
}).mount(container);
|
261
262
|
this.teleBoxManager.setCollector(collector);
|
262
263
|
}
|
@@ -391,6 +392,7 @@ export class BoxManager {
|
|
391
392
|
}
|
392
393
|
|
393
394
|
public destroy() {
|
395
|
+
emitter.off("playgroundSizeChange", this.playgroundSizeChangeListener);
|
394
396
|
this.teleBoxManager.destroy();
|
395
397
|
}
|
396
398
|
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import AppDocsViewer from "@netless/app-docs-viewer";
|
2
|
+
import AppMediaPlayer, { setOptions } from "@netless/app-media-player";
|
3
|
+
import { WindowManager } from "./index";
|
4
|
+
import "@netless/app-docs-viewer/dist/style.css";
|
5
|
+
|
6
|
+
export const setupBuiltin = () => {
|
7
|
+
if (WindowManager.debug) {
|
8
|
+
setOptions({ verbose: true });
|
9
|
+
}
|
10
|
+
|
11
|
+
WindowManager.register({
|
12
|
+
kind: AppDocsViewer.kind,
|
13
|
+
src: AppDocsViewer,
|
14
|
+
});
|
15
|
+
WindowManager.register({
|
16
|
+
kind: AppMediaPlayer.kind,
|
17
|
+
src: AppMediaPlayer,
|
18
|
+
});
|
19
|
+
};
|
20
|
+
|
21
|
+
export const BuiltinApps = {
|
22
|
+
DocsViewer: AppDocsViewer.kind as string,
|
23
|
+
MediaPlayer: AppMediaPlayer.kind as string,
|
24
|
+
};
|
@@ -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/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
|
+
};
|
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));
|
@@ -1,17 +1,16 @@
|
|
1
|
-
import { AnimationMode, reaction
|
2
|
-
import { Base } from "
|
3
|
-
import { callbacks, emitter } from "
|
1
|
+
import { AnimationMode, reaction } from "white-web-sdk";
|
2
|
+
import { Base } from "../Base";
|
3
|
+
import { callbacks, emitter } from "../index";
|
4
4
|
import { createView } from "./ViewManager";
|
5
5
|
import { debounce, isEmpty, isEqual } from "lodash";
|
6
|
-
import { Fields } from "
|
7
|
-
import {
|
6
|
+
import { Fields } from "../AttributesDelegate";
|
7
|
+
import { setViewFocusScenePath } from "../Utils/Common";
|
8
8
|
import { SideEffectManager } from "side-effect-manager";
|
9
9
|
import type { Camera, Size, View } from "white-web-sdk";
|
10
|
-
import type { AppManager } from "
|
10
|
+
import type { AppManager } from "../AppManager";
|
11
11
|
|
12
12
|
export class MainViewProxy extends Base {
|
13
13
|
private scale?: number;
|
14
|
-
private cameraStore = this.manager.cameraStore;
|
15
14
|
private started = false;
|
16
15
|
private mainViewIsAddListener = false;
|
17
16
|
private mainView: View;
|
@@ -23,7 +22,6 @@ export class MainViewProxy extends Base {
|
|
23
22
|
super(manager);
|
24
23
|
this.mainView = this.createMainView();
|
25
24
|
this.moveCameraSizeByAttributes();
|
26
|
-
this.cameraStore.register(this.viewId, this.mainView);
|
27
25
|
emitter.once("mainViewMounted").then(() => {
|
28
26
|
setTimeout(() => {
|
29
27
|
this.start();
|
@@ -34,7 +32,7 @@ export class MainViewProxy extends Base {
|
|
34
32
|
});
|
35
33
|
const playgroundSizeChangeListener = () => {
|
36
34
|
this.sizeChangeHandler(this.mainViewSize);
|
37
|
-
}
|
35
|
+
};
|
38
36
|
this.sideEffectManager.add(() => {
|
39
37
|
emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
|
40
38
|
return () => emitter.off("playgroundSizeChange", playgroundSizeChangeListener);
|
@@ -103,9 +101,6 @@ export class MainViewProxy extends Base {
|
|
103
101
|
if (mainViewScenePath) {
|
104
102
|
setViewFocusScenePath(mainView, mainViewScenePath);
|
105
103
|
}
|
106
|
-
if (!this.store.focus) {
|
107
|
-
this.switchViewModeToWriter();
|
108
|
-
}
|
109
104
|
return mainView;
|
110
105
|
}
|
111
106
|
|
@@ -138,7 +133,6 @@ export class MainViewProxy extends Base {
|
|
138
133
|
|
139
134
|
public async mainViewClickHandler(): Promise<void> {
|
140
135
|
if (!this.manager.canOperate) return;
|
141
|
-
if (this.view.mode === ViewVisionMode.Writable) return;
|
142
136
|
this.store.cleanFocus();
|
143
137
|
this.context.blurFocusBox();
|
144
138
|
}
|
@@ -163,17 +157,6 @@ export class MainViewProxy extends Base {
|
|
163
157
|
callbacks.emit("cameraStateChange", this.cameraState);
|
164
158
|
};
|
165
159
|
|
166
|
-
public switchViewModeToWriter(): void {
|
167
|
-
if (!this.manager.canOperate) return;
|
168
|
-
if (this.view) {
|
169
|
-
if (this.view.mode === ViewVisionMode.Writable) return;
|
170
|
-
this.cameraStore.switchView(this.viewId, this.mainView, () => {
|
171
|
-
notifyMainViewModeChange(callbacks, ViewVisionMode.Writable);
|
172
|
-
setViewMode(this.view, ViewVisionMode.Writable);
|
173
|
-
});
|
174
|
-
}
|
175
|
-
}
|
176
|
-
|
177
160
|
public moveCameraToContian(size: Size): void {
|
178
161
|
if (!isEmpty(size)) {
|
179
162
|
this.view.moveCameraToContain({
|
@@ -210,7 +193,6 @@ export class MainViewProxy extends Base {
|
|
210
193
|
|
211
194
|
public destroy() {
|
212
195
|
this.stop();
|
213
|
-
this.cameraStore.unregister(this.viewId, this.mainView);
|
214
196
|
this.sideEffectManager.flushAll();
|
215
197
|
}
|
216
198
|
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import type { View , Displayer} from "white-web-sdk";
|
2
|
+
|
3
|
+
export class ViewManager {
|
4
|
+
public views: Map<string, View> = new Map();
|
5
|
+
|
6
|
+
constructor(private displayer: Displayer) {}
|
7
|
+
|
8
|
+
public createView(id: string): View {
|
9
|
+
const view = createView(this.displayer);
|
10
|
+
this.views.set(id, view);
|
11
|
+
return view;
|
12
|
+
}
|
13
|
+
|
14
|
+
public getView(id: string): View | undefined {
|
15
|
+
return this.views.get(id);
|
16
|
+
}
|
17
|
+
|
18
|
+
public destroyView(id: string): void {
|
19
|
+
const view = this.views.get(id);
|
20
|
+
if (view) {
|
21
|
+
view.release();
|
22
|
+
this.views.delete(id);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
public setViewScenePath(id: string, scenePath: string): void {
|
27
|
+
const view = this.views.get(id);
|
28
|
+
if (view) {
|
29
|
+
view.focusScenePath = scenePath;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
public destroy() {
|
34
|
+
this.views.forEach(view => {
|
35
|
+
view.release();
|
36
|
+
});
|
37
|
+
this.views.clear();
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
export const createView = (displayer: Displayer): View => {
|
43
|
+
const view = displayer.views.createView();
|
44
|
+
setDefaultCameraBound(view);
|
45
|
+
return view;
|
46
|
+
};
|
47
|
+
|
48
|
+
export const setDefaultCameraBound = (view: View) => {
|
49
|
+
view.setCameraBound({
|
50
|
+
maxContentMode: () => 10,
|
51
|
+
minContentMode: () => 0.1,
|
52
|
+
});
|
53
|
+
};
|
package/src/constants.ts
CHANGED
package/src/index.ts
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
import AppDocsViewer from "@netless/app-docs-viewer";
|
2
|
-
import AppMediaPlayer, { setOptions } from "@netless/app-media-player";
|
3
1
|
import Emittery from "emittery";
|
4
2
|
import pRetry from "p-retry";
|
5
3
|
import { AppManager } from "./AppManager";
|
6
4
|
import { appRegister } from "./Register";
|
5
|
+
import { ContainerResizeObserver } from "./ContainerResizeObserver";
|
7
6
|
import { createBoxManager } from "./BoxManager";
|
8
7
|
import { CursorManager } from "./Cursor";
|
9
8
|
import { DEFAULT_CONTAINER_RATIO, Events, REQUIRE_VERSION } from "./constants";
|
@@ -11,12 +10,13 @@ import { Fields } from "./AttributesDelegate";
|
|
11
10
|
import { initDb } from "./Register/storage";
|
12
11
|
import { isNull, isObject } from "lodash";
|
13
12
|
import { log } from "./Utils/log";
|
13
|
+
import { ReconnectRefresher } from "./ReconnectRefresher";
|
14
14
|
import { replaceRoomFunction } from "./Utils/RoomHacker";
|
15
|
-
import {
|
16
|
-
import { setupWrapper } from "./
|
15
|
+
import { setupBuiltin } from "./BuiltinApps";
|
16
|
+
import { setupWrapper } from "./Helper";
|
17
|
+
import { version } from "../package.json";
|
17
18
|
import "./style.css";
|
18
19
|
import "@netless/telebox-insider/dist/style.css";
|
19
|
-
import "@netless/app-docs-viewer/dist/style.css";
|
20
20
|
import {
|
21
21
|
addEmitterOnceListener,
|
22
22
|
ensureValidScenePath,
|
@@ -59,9 +59,6 @@ import type { AppListeners } from "./AppListener";
|
|
59
59
|
import type { NetlessApp, RegisterParams } from "./typings";
|
60
60
|
import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
|
61
61
|
import type { AppProxy } from "./AppProxy";
|
62
|
-
import { ReconnectRefresher } from "./ReconnectRefresher";
|
63
|
-
|
64
|
-
const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
|
65
62
|
|
66
63
|
export type WindowMangerAttributes = {
|
67
64
|
modelValue?: string;
|
@@ -186,7 +183,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
186
183
|
public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
|
187
184
|
private static isCreated = false;
|
188
185
|
|
189
|
-
public version =
|
186
|
+
public version = version;
|
190
187
|
|
191
188
|
public appListeners?: AppListeners;
|
192
189
|
|
@@ -200,6 +197,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
200
197
|
private boxManager?: BoxManager;
|
201
198
|
private static params?: MountParams;
|
202
199
|
|
200
|
+
private containerResizeObserver?: ContainerResizeObserver;
|
201
|
+
|
203
202
|
constructor(context: InvisiblePluginContext) {
|
204
203
|
super(context);
|
205
204
|
WindowManager.displayer = context.displayer;
|
@@ -225,9 +224,6 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
225
224
|
}
|
226
225
|
let manager = await this.initManager(room);
|
227
226
|
this.debug = Boolean(debug);
|
228
|
-
if (this.debug) {
|
229
|
-
setOptions({ verbose: true });
|
230
|
-
}
|
231
227
|
log("Already insert room", manager);
|
232
228
|
|
233
229
|
if (isRoom(this.displayer)) {
|
@@ -321,7 +317,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
321
317
|
style.textContent = overwriteStyles;
|
322
318
|
playground.appendChild(style);
|
323
319
|
}
|
324
|
-
manager.
|
320
|
+
manager.containerResizeObserver = ContainerResizeObserver.create(
|
321
|
+
playground,
|
322
|
+
sizer,
|
323
|
+
wrapper,
|
324
|
+
emitter
|
325
|
+
);
|
325
326
|
WindowManager.wrapper = wrapper;
|
326
327
|
return mainViewElement;
|
327
328
|
}
|
@@ -700,62 +701,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
700
701
|
}
|
701
702
|
}
|
702
703
|
}
|
703
|
-
|
704
|
-
private containerResizeObserver?: ResizeObserver;
|
705
|
-
|
706
|
-
private observePlaygroundSize(
|
707
|
-
container: HTMLElement,
|
708
|
-
sizer: HTMLElement,
|
709
|
-
wrapper: HTMLDivElement
|
710
|
-
) {
|
711
|
-
this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
|
712
|
-
|
713
|
-
this.containerResizeObserver = new ResizeObserver(entries => {
|
714
|
-
const containerRect = entries[0]?.contentRect;
|
715
|
-
if (containerRect) {
|
716
|
-
this.updateSizer(containerRect, sizer, wrapper);
|
717
|
-
this.cursorManager?.updateContainerRect();
|
718
|
-
this.boxManager?.updateManagerRect();
|
719
|
-
emitter.emit("playgroundSizeChange", containerRect);
|
720
|
-
}
|
721
|
-
});
|
722
|
-
|
723
|
-
this.containerResizeObserver.observe(container);
|
724
|
-
}
|
725
|
-
|
726
|
-
private updateSizer(
|
727
|
-
{ width, height }: DOMRectReadOnly,
|
728
|
-
sizer: HTMLElement,
|
729
|
-
wrapper: HTMLDivElement
|
730
|
-
) {
|
731
|
-
if (width && height) {
|
732
|
-
if (height / width > WindowManager.containerSizeRatio) {
|
733
|
-
height = width * WindowManager.containerSizeRatio;
|
734
|
-
sizer.classList.toggle("netless-window-manager-sizer-horizontal", true);
|
735
|
-
} else {
|
736
|
-
width = height / WindowManager.containerSizeRatio;
|
737
|
-
sizer.classList.toggle("netless-window-manager-sizer-horizontal", false);
|
738
|
-
}
|
739
|
-
wrapper.style.width = `${width}px`;
|
740
|
-
wrapper.style.height = `${height}px`;
|
741
|
-
}
|
742
|
-
}
|
743
704
|
}
|
744
705
|
|
745
|
-
|
746
|
-
kind: AppDocsViewer.kind,
|
747
|
-
src: AppDocsViewer,
|
748
|
-
});
|
749
|
-
WindowManager.register({
|
750
|
-
kind: AppMediaPlayer.kind,
|
751
|
-
src: AppMediaPlayer,
|
752
|
-
});
|
753
|
-
|
754
|
-
export const BuiltinApps = {
|
755
|
-
DocsViewer: AppDocsViewer.kind as string,
|
756
|
-
MediaPlayer: AppMediaPlayer.kind as string,
|
757
|
-
};
|
706
|
+
setupBuiltin();
|
758
707
|
|
759
708
|
export * from "./typings";
|
760
709
|
|
761
|
-
export {
|
710
|
+
export { BuiltinApps } from "./BuiltinApps";
|