@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
package/src/viewManager.ts
DELETED
@@ -1,177 +0,0 @@
|
|
1
|
-
import { Base } from "./Base";
|
2
|
-
import { callbacks, WindowManager } from "./index";
|
3
|
-
import { reaction, ViewVisionMode } from "white-web-sdk";
|
4
|
-
import { SET_SCENEPATH_DELAY } from "./constants";
|
5
|
-
import { notifyMainViewModeChange, setScenePath, setViewMode } from "./Utils/Common";
|
6
|
-
import type { View, Displayer } from "white-web-sdk";
|
7
|
-
import type { AppManager } from "./AppManager";
|
8
|
-
|
9
|
-
export class ViewManager extends Base {
|
10
|
-
private views: Map<string, View> = new Map();
|
11
|
-
private timer?: number;
|
12
|
-
private appTimer?: number;
|
13
|
-
|
14
|
-
private mainViewProxy = this.manager.mainViewProxy;
|
15
|
-
private displayer = this.manager.displayer;
|
16
|
-
|
17
|
-
constructor(manager: AppManager) {
|
18
|
-
super(manager);
|
19
|
-
setTimeout(() => {
|
20
|
-
// 延迟初始化 focus 的 reaction
|
21
|
-
this.manager.refresher?.add("focus", () => {
|
22
|
-
return reaction(
|
23
|
-
() => this.store.focus,
|
24
|
-
focus => {
|
25
|
-
if (focus) {
|
26
|
-
this.switchAppToWriter(focus);
|
27
|
-
} else {
|
28
|
-
this.switchMainViewToWriter();
|
29
|
-
this.context.blurFocusBox();
|
30
|
-
}
|
31
|
-
},
|
32
|
-
{ fireImmediately: true }
|
33
|
-
);
|
34
|
-
});
|
35
|
-
}, 100);
|
36
|
-
}
|
37
|
-
|
38
|
-
public get currentScenePath(): string {
|
39
|
-
return this.displayer.state.sceneState.scenePath;
|
40
|
-
}
|
41
|
-
|
42
|
-
public get mainView(): View {
|
43
|
-
return this.mainViewProxy.view;
|
44
|
-
}
|
45
|
-
|
46
|
-
public createView(appId: string): View {
|
47
|
-
const view = createView(this.displayer);
|
48
|
-
setViewMode(view, ViewVisionMode.Freedom);
|
49
|
-
this.views.set(appId, view);
|
50
|
-
return view;
|
51
|
-
}
|
52
|
-
|
53
|
-
public destroyView(appId: string): void {
|
54
|
-
const view = this.views.get(appId);
|
55
|
-
if (view) {
|
56
|
-
this.releaseView(view);
|
57
|
-
this.views.delete(appId);
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
private releaseView(view: View) {
|
62
|
-
if (!(view as any).didRelease) {
|
63
|
-
view.release();
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
public getView(appId: string): View | undefined {
|
68
|
-
return this.views.get(appId);
|
69
|
-
}
|
70
|
-
|
71
|
-
public switchMainViewToWriter(): Promise<boolean> | undefined {
|
72
|
-
if (this.timer) {
|
73
|
-
clearTimeout(this.timer);
|
74
|
-
}
|
75
|
-
if (this.mainView.mode === ViewVisionMode.Writable) return;
|
76
|
-
this.freedomAllViews();
|
77
|
-
return new Promise((resolve, reject) => {
|
78
|
-
this.timer = window.setTimeout(() => {
|
79
|
-
try {
|
80
|
-
const mainViewScenePath = this.store.getMainViewScenePath();
|
81
|
-
if (mainViewScenePath) {
|
82
|
-
this.freedomAllViews();
|
83
|
-
setScenePath(this.manager.room, mainViewScenePath);
|
84
|
-
this.mainViewProxy.switchViewModeToWriter();
|
85
|
-
}
|
86
|
-
resolve(true);
|
87
|
-
} catch (error) {
|
88
|
-
reject(error);
|
89
|
-
}
|
90
|
-
}, SET_SCENEPATH_DELAY);
|
91
|
-
});
|
92
|
-
}
|
93
|
-
|
94
|
-
public freedomAllViews(): void {
|
95
|
-
this.manager.appProxies.forEach(appProxy => {
|
96
|
-
appProxy.setViewFocusScenePath();
|
97
|
-
if (appProxy.view) {
|
98
|
-
setViewMode(appProxy.view, ViewVisionMode.Freedom);
|
99
|
-
}
|
100
|
-
});
|
101
|
-
if (this.mainView.mode === ViewVisionMode.Writable) {
|
102
|
-
notifyMainViewModeChange(callbacks, ViewVisionMode.Freedom);
|
103
|
-
setViewMode(this.mainView, ViewVisionMode.Freedom);
|
104
|
-
}
|
105
|
-
if (!this.mainView.focusScenePath) {
|
106
|
-
this.store.setMainViewFocusPath(this.mainView);
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
public switchAppToWriter(id: string): void {
|
111
|
-
if (this.appTimer) {
|
112
|
-
clearTimeout(this.appTimer);
|
113
|
-
}
|
114
|
-
this.freedomAllViews();
|
115
|
-
// 为了同步端不闪烁, 需要给 room setScenePath 一个延迟
|
116
|
-
this.appTimer = setTimeout(() => {
|
117
|
-
const appProxy = this.manager.appProxies.get(id);
|
118
|
-
if (appProxy) {
|
119
|
-
if (this.manager.boxManager?.minimized) return;
|
120
|
-
appProxy.setScenePath();
|
121
|
-
appProxy.switchToWritable();
|
122
|
-
appProxy.focusBox();
|
123
|
-
}
|
124
|
-
}, SET_SCENEPATH_DELAY);
|
125
|
-
}
|
126
|
-
|
127
|
-
public destroy(): void {
|
128
|
-
this.mainViewProxy.removeMainViewListener();
|
129
|
-
if (WindowManager.wrapper) {
|
130
|
-
WindowManager.wrapper.parentNode?.removeChild(WindowManager.wrapper);
|
131
|
-
WindowManager.wrapper = undefined;
|
132
|
-
}
|
133
|
-
this.releaseView(this.mainView);
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
|
-
export const createView = (displayer: Displayer): View => {
|
138
|
-
const view = displayer.views.createView();
|
139
|
-
setDefaultCameraBound(view);
|
140
|
-
return view;
|
141
|
-
};
|
142
|
-
|
143
|
-
export const setDefaultCameraBound = (view: View) => {
|
144
|
-
view.setCameraBound({
|
145
|
-
maxContentMode: () => 10,
|
146
|
-
minContentMode: () => 0.1,
|
147
|
-
});
|
148
|
-
};
|
149
|
-
|
150
|
-
export const setupWrapper = (
|
151
|
-
root: HTMLElement
|
152
|
-
): {
|
153
|
-
playground: HTMLDivElement;
|
154
|
-
wrapper: HTMLDivElement;
|
155
|
-
sizer: HTMLDivElement;
|
156
|
-
mainViewElement: HTMLDivElement;
|
157
|
-
} => {
|
158
|
-
const playground = document.createElement("div");
|
159
|
-
playground.className = "netless-window-manager-playground";
|
160
|
-
|
161
|
-
const sizer = document.createElement("div");
|
162
|
-
sizer.className = "netless-window-manager-sizer";
|
163
|
-
|
164
|
-
const wrapper = document.createElement("div");
|
165
|
-
wrapper.className = "netless-window-manager-wrapper";
|
166
|
-
|
167
|
-
const mainViewElement = document.createElement("div");
|
168
|
-
mainViewElement.className = "netless-window-manager-main-view";
|
169
|
-
|
170
|
-
playground.appendChild(sizer);
|
171
|
-
sizer.appendChild(wrapper);
|
172
|
-
wrapper.appendChild(mainViewElement);
|
173
|
-
root.appendChild(playground);
|
174
|
-
WindowManager.wrapper = wrapper;
|
175
|
-
|
176
|
-
return { playground, wrapper, sizer, mainViewElement };
|
177
|
-
};
|