@netless/window-manager 0.4.21 → 0.4.24
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/CHANGELOG.md +12 -0
- package/dist/AppListener.d.ts +1 -0
- package/dist/AttributesDelegate.d.ts +9 -6
- package/dist/InternalEmitter.d.ts +1 -0
- package/dist/View/MainView.d.ts +3 -0
- package/dist/constants.d.ts +2 -1
- package/dist/index.cjs.js +47 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.es.js +44 -15
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +10 -10
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/AppListener.ts +8 -0
- package/src/AppManager.ts +12 -8
- package/src/AttributesDelegate.ts +14 -2
- package/src/InternalEmitter.ts +1 -0
- package/src/View/MainView.ts +31 -13
- package/src/constants.ts +1 -0
- package/vite.config.js +1 -1
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/window-manager",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.24",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "dist/index.
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"repository": "netless-io/window-manager",
|
package/src/AppListener.ts
CHANGED
|
@@ -63,6 +63,10 @@ export class AppListeners {
|
|
|
63
63
|
this.refreshHandler();
|
|
64
64
|
break;
|
|
65
65
|
}
|
|
66
|
+
case Events.InitMainViewCamera: {
|
|
67
|
+
this.initMainViewCameraHandler();
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
66
70
|
default:
|
|
67
71
|
break;
|
|
68
72
|
}
|
|
@@ -111,4 +115,8 @@ export class AppListeners {
|
|
|
111
115
|
private refreshHandler = () => {
|
|
112
116
|
this.manager.windowManger._refresh();
|
|
113
117
|
}
|
|
118
|
+
|
|
119
|
+
private initMainViewCameraHandler = () => {
|
|
120
|
+
this.manager.mainViewProxy.addCameraReaction();
|
|
121
|
+
}
|
|
114
122
|
}
|
package/src/AppManager.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { AppProxy } from "./App";
|
|
|
5
5
|
import { appRegister } from "./Register";
|
|
6
6
|
import { autorun, isPlayer, isRoom, ScenePathType } from "white-web-sdk";
|
|
7
7
|
import { callbacks } from "./callback";
|
|
8
|
+
import { debounce, get, isInteger, orderBy } from "lodash";
|
|
8
9
|
import { emitter } from "./InternalEmitter";
|
|
9
10
|
import { Fields, store } from "./AttributesDelegate";
|
|
10
|
-
import { debounce, get, isInteger, orderBy } from "lodash";
|
|
11
11
|
import { log } from "./Utils/log";
|
|
12
12
|
import { MainViewProxy } from "./View/MainView";
|
|
13
13
|
import { onObjectRemoved, safeListenPropsUpdated } from "./Utils/Reactive";
|
|
@@ -132,7 +132,7 @@ export class AppManager {
|
|
|
132
132
|
public async onRootDirRemoved(needClose = true) {
|
|
133
133
|
this.setMainViewScenePath(INIT_DIR);
|
|
134
134
|
this.createRootDirScenesCallback();
|
|
135
|
-
|
|
135
|
+
|
|
136
136
|
for (const [id, appProxy] of this.appProxies.entries()) {
|
|
137
137
|
if (appProxy.view) {
|
|
138
138
|
await this.closeApp(id, needClose);
|
|
@@ -312,7 +312,7 @@ export class AppManager {
|
|
|
312
312
|
}
|
|
313
313
|
);
|
|
314
314
|
});
|
|
315
|
-
}
|
|
315
|
+
};
|
|
316
316
|
|
|
317
317
|
public addAppCloseListener = () => {
|
|
318
318
|
this.refresher?.add("appsClose", () => {
|
|
@@ -320,7 +320,7 @@ export class AppManager {
|
|
|
320
320
|
this.onAppDelete(this.attributes.apps);
|
|
321
321
|
});
|
|
322
322
|
});
|
|
323
|
-
}
|
|
323
|
+
};
|
|
324
324
|
|
|
325
325
|
private onMainViewIndexChange = (index: number) => {
|
|
326
326
|
if (index !== undefined && this._prevSceneIndex !== index) {
|
|
@@ -331,7 +331,7 @@ export class AppManager {
|
|
|
331
331
|
}
|
|
332
332
|
this._prevSceneIndex = index;
|
|
333
333
|
}
|
|
334
|
-
}
|
|
334
|
+
};
|
|
335
335
|
|
|
336
336
|
private onFocusChange = (focused: string | undefined) => {
|
|
337
337
|
if (this._prevFocused !== focused) {
|
|
@@ -349,9 +349,12 @@ export class AppManager {
|
|
|
349
349
|
}, 0);
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
|
-
}
|
|
352
|
+
};
|
|
353
353
|
|
|
354
|
-
public attributesUpdateCallback = debounce(
|
|
354
|
+
public attributesUpdateCallback = debounce(
|
|
355
|
+
(apps: any) => this._attributesUpdateCallback(apps),
|
|
356
|
+
100
|
|
357
|
+
);
|
|
355
358
|
|
|
356
359
|
/**
|
|
357
360
|
* 插件更新 attributes 时的回调
|
|
@@ -582,6 +585,7 @@ export class AppManager {
|
|
|
582
585
|
} else {
|
|
583
586
|
this.mainView.disableCameraTransform = true;
|
|
584
587
|
}
|
|
588
|
+
emitter.emit("writableChange", isWritable);
|
|
585
589
|
};
|
|
586
590
|
|
|
587
591
|
public safeSetAttributes(attributes: any) {
|
|
@@ -742,7 +746,7 @@ export class AppManager {
|
|
|
742
746
|
|
|
743
747
|
public updateRootDirRemoving = (removing: boolean) => {
|
|
744
748
|
this.rootDirRemoving = removing;
|
|
745
|
-
}
|
|
749
|
+
};
|
|
746
750
|
|
|
747
751
|
public dispatchInternalEvent(event: Events, payload?: any) {
|
|
748
752
|
this.safeDispatchMagixEvent(MagixEventName, {
|
|
@@ -38,6 +38,11 @@ export type StoreContext = {
|
|
|
38
38
|
safeUpdateAttributes: (keys: string[], value: any) => void;
|
|
39
39
|
safeSetAttributes: (attributes: any) => void;
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
export type ICamera = Camera & { id: string };
|
|
43
|
+
|
|
44
|
+
export type ISize = Size & { id: string };
|
|
45
|
+
|
|
41
46
|
export class AttributesDelegate {
|
|
42
47
|
|
|
43
48
|
constructor(private context: StoreContext) {}
|
|
@@ -152,14 +157,21 @@ export class AttributesDelegate {
|
|
|
152
157
|
return get(this.attributes, [Fields.MainViewSize]);
|
|
153
158
|
}
|
|
154
159
|
|
|
155
|
-
public setMainViewCamera(camera:
|
|
160
|
+
public setMainViewCamera(camera: ICamera) {
|
|
156
161
|
this.context.safeSetAttributes({ [Fields.MainViewCamera]: { ...camera } });
|
|
157
162
|
}
|
|
158
163
|
|
|
159
|
-
public setMainViewSize(size:
|
|
164
|
+
public setMainViewSize(size: ISize) {
|
|
160
165
|
this.context.safeSetAttributes({ [Fields.MainViewSize]: { ...size } });
|
|
161
166
|
}
|
|
162
167
|
|
|
168
|
+
public setMainViewCameraAndSize(camera: ICamera, size: ISize) {
|
|
169
|
+
this.context.safeSetAttributes({
|
|
170
|
+
[Fields.MainViewCamera]: { ...camera },
|
|
171
|
+
[Fields.MainViewSize]: { ...size },
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
163
175
|
public setAppFocus = (appId: string, focus: boolean) => {
|
|
164
176
|
if (focus) {
|
|
165
177
|
this.context.safeSetAttributes({ [Fields.Focus]: appId });
|
package/src/InternalEmitter.ts
CHANGED
package/src/View/MainView.ts
CHANGED
|
@@ -8,6 +8,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
10
|
import type { AppManager } from "../AppManager";
|
|
11
|
+
import { Events } from "../constants";
|
|
11
12
|
|
|
12
13
|
export class MainViewProxy {
|
|
13
14
|
private scale?: number;
|
|
@@ -22,13 +23,10 @@ export class MainViewProxy {
|
|
|
22
23
|
this.mainView = this.createMainView();
|
|
23
24
|
this.moveCameraSizeByAttributes();
|
|
24
25
|
emitter.once("mainViewMounted").then(() => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.setCameraAndSize();
|
|
30
|
-
}
|
|
31
|
-
}, 200); // 等待 mainView 挂载完毕再进行监听,否则会触发不必要的 onSizeUpdated
|
|
26
|
+
this.addMainViewListener();
|
|
27
|
+
this.start();
|
|
28
|
+
this.ensureCameraAndSize();
|
|
29
|
+
this.startListenWritableChange();
|
|
32
30
|
});
|
|
33
31
|
const playgroundSizeChangeListener = () => {
|
|
34
32
|
this.sizeChangeHandler(this.mainViewSize);
|
|
@@ -39,6 +37,23 @@ export class MainViewProxy {
|
|
|
39
37
|
});
|
|
40
38
|
}
|
|
41
39
|
|
|
40
|
+
private startListenWritableChange = () => {
|
|
41
|
+
this.sideEffectManager.add(() => {
|
|
42
|
+
return emitter.on("writableChange", isWritable => {
|
|
43
|
+
if (isWritable) {
|
|
44
|
+
this.ensureCameraAndSize();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public ensureCameraAndSize() {
|
|
51
|
+
if (!this.mainViewCamera || !this.mainViewSize) {
|
|
52
|
+
this.manager.dispatchInternalEvent(Events.InitMainViewCamera);
|
|
53
|
+
this.setCameraAndSize();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
private get mainViewCamera() {
|
|
43
58
|
return this.store.getMainViewCamera();
|
|
44
59
|
}
|
|
@@ -56,13 +71,18 @@ export class MainViewProxy {
|
|
|
56
71
|
if (this.started) return;
|
|
57
72
|
this.sizeChangeHandler(this.mainViewSize);
|
|
58
73
|
this.addCameraListener();
|
|
59
|
-
this.
|
|
74
|
+
this.addCameraReaction();
|
|
60
75
|
this.started = true;
|
|
61
76
|
}
|
|
62
77
|
|
|
78
|
+
public addCameraReaction = () => {
|
|
79
|
+
this.manager.refresher?.add(Fields.MainViewCamera, this.cameraReaction);
|
|
80
|
+
};
|
|
81
|
+
|
|
63
82
|
public setCameraAndSize(): void {
|
|
64
|
-
|
|
65
|
-
|
|
83
|
+
const camera = { ...this.mainView.camera, id: this.manager.uid };
|
|
84
|
+
const size = { ...this.mainView.size, id: this.manager.uid };
|
|
85
|
+
this.store.setMainViewCameraAndSize(camera, size);
|
|
66
86
|
}
|
|
67
87
|
|
|
68
88
|
private cameraReaction = () => {
|
|
@@ -74,9 +94,7 @@ export class MainViewProxy {
|
|
|
74
94
|
this.moveCamera(camera);
|
|
75
95
|
}
|
|
76
96
|
},
|
|
77
|
-
{
|
|
78
|
-
fireImmediately: true,
|
|
79
|
-
}
|
|
97
|
+
{ fireImmediately: true }
|
|
80
98
|
);
|
|
81
99
|
};
|
|
82
100
|
|
package/src/constants.ts
CHANGED
package/vite.config.js
CHANGED
|
@@ -26,7 +26,7 @@ export default defineConfig(({ mode }) => {
|
|
|
26
26
|
lib: {
|
|
27
27
|
// eslint-disable-next-line no-undef
|
|
28
28
|
entry: path.resolve(__dirname, "src/index.ts"),
|
|
29
|
-
formats: ["es", "umd"
|
|
29
|
+
formats: ["es", "umd", "cjs"],
|
|
30
30
|
name: "WindowManager",
|
|
31
31
|
fileName: "index"
|
|
32
32
|
},
|