@netless/window-manager 0.3.12 → 0.3.16-canary.1
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/README.md +3 -21
- package/dist/MainView.d.ts +3 -4
- package/dist/index.d.ts +1 -0
- 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/docs/api.md +113 -0
- package/package.json +3 -3
- package/src/MainView.ts +21 -33
- package/src/index.ts +4 -1
package/docs/api.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# API
|
2
|
+
|
3
|
+
## 目录
|
4
|
+
- [静态方法](#static-methods)
|
5
|
+
- [`mount`](#mount)
|
6
|
+
- [`register`](#register)
|
7
|
+
- [实例方法](#instance-methods)
|
8
|
+
- [`addApp`](#addApp)
|
9
|
+
- [`closeApp`](#closeApp)
|
10
|
+
- [实例属性](#prototypes)
|
11
|
+
- [事件回调](#events)
|
12
|
+
|
13
|
+
<h2 id="static-methods">静态方法</h2>
|
14
|
+
|
15
|
+
<h3 id="mount">WindowManager.mount</h3>
|
16
|
+
|
17
|
+
> 挂载 WindowManager
|
18
|
+
|
19
|
+
```typescript
|
20
|
+
const manager = await WindowManager.mount(
|
21
|
+
room: room,
|
22
|
+
container: document.getElementById("container")
|
23
|
+
// 完整配置见下方
|
24
|
+
);
|
25
|
+
```
|
26
|
+
|
27
|
+
参数
|
28
|
+
|
29
|
+
| name | type | default | desc |
|
30
|
+
| ---------------------- | --------------------------------------- | ------- | ---------------------------- |
|
31
|
+
| room | [require] Room | | 房间实例 |
|
32
|
+
| container | [require] HTMLElement | | 房间挂载容器 |
|
33
|
+
| containerSizeRatio | [optional] number | 9 / 16 | 多窗口区域的高宽比,默认为 9 : 16 |
|
34
|
+
| chessboard | [optional] boolean | true | 多窗口区域以外的空间显示 PS 棋盘背景,默认 true |
|
35
|
+
| collectorContainer | [optional] HTMLElement | | 用于多窗口最小化图标挂载的 dom |
|
36
|
+
| collectorStyles | [optional] Partial{CSSStyleDeclaration} | | 配置 collector 的样式 |
|
37
|
+
| overwriteStyles | [optional] string | | 用于覆盖窗口的样式 |
|
38
|
+
| cursor | [optional] boolean | false | 开启光标同步 |
|
39
|
+
| disableCameraTransform | [optional] boolean | | 禁用主白板的相机移动 |
|
40
|
+
| prefersColorScheme | [optional] string | light | auto, light, dark |
|
41
|
+
| debug | [optional] boolean | false | 打印日志信息
|
42
|
+
|
43
|
+
<h3 id="register">WindowManager.register</h3>
|
44
|
+
|
45
|
+
> 注册 `APP` 到 `WindowManager`
|
46
|
+
|
47
|
+
```typescript
|
48
|
+
WindowManager.register({
|
49
|
+
kind: "helloWorld",
|
50
|
+
src: NetlessApp,
|
51
|
+
appOptions: () => "appOptions",
|
52
|
+
addHooks: (emitter) => {
|
53
|
+
emitter.on("created", result => {
|
54
|
+
console.log("HelloWordResult", result);
|
55
|
+
});
|
56
|
+
emitter.on("focus", result => {
|
57
|
+
console.log("HelloWorld focus", result);
|
58
|
+
})
|
59
|
+
emitter.on("destroy", result => {
|
60
|
+
console.log("HelloWorld destroy", result);
|
61
|
+
})
|
62
|
+
}
|
63
|
+
})
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
<h2 id="instance-methods">实例方法</h2>
|
68
|
+
|
69
|
+
<h3 id="addApp">addApp</h3>
|
70
|
+
|
71
|
+
> 添加 `app` 至白板
|
72
|
+
|
73
|
+
```typescript
|
74
|
+
const appId = await manager.addApp({
|
75
|
+
kind: "helloWorld"
|
76
|
+
options: { // 可选配置
|
77
|
+
scenePath: "/hello-world"
|
78
|
+
}
|
79
|
+
})
|
80
|
+
```
|
81
|
+
具体参数请参考 `APP` 本身的要求
|
82
|
+
|
83
|
+
<h3 id="closeApp">closeApp</h3>
|
84
|
+
|
85
|
+
> 关闭已经打开的 `APP`
|
86
|
+
|
87
|
+
```typescript
|
88
|
+
manager.closeApp(appId)
|
89
|
+
```
|
90
|
+
|
91
|
+
<h2 id="prototypes">实例属性</h2>
|
92
|
+
|
93
|
+
| name | type | default | desc |
|
94
|
+
| ------------------ | ------- | ------- | ------ |
|
95
|
+
| mainView | View | | 主白板 |
|
96
|
+
| boxState | string | | 当前窗口状态 |
|
97
|
+
| darkMode | boolean | | 黑夜模式 |
|
98
|
+
| prefersColorScheme | string | | 颜色主题 |
|
99
|
+
|
100
|
+
|
101
|
+
<h2 id="events">事件回调</h2>
|
102
|
+
|
103
|
+
```typescript
|
104
|
+
manager.callbacks.on(events, listener)
|
105
|
+
```
|
106
|
+
|
107
|
+
| name | type | default | desc |
|
108
|
+
| ------------------------ | -------------- | ------- | -------------------------- |
|
109
|
+
| mainViewModeChange | ViewVisionMode | | |
|
110
|
+
| boxStateChange | string | | normal,minimized,maximized |
|
111
|
+
| darkModeChange | boolean | | |
|
112
|
+
| prefersColorSchemeChange | string | | auto,light,dark |
|
113
|
+
| cameraStateChange | CameraState | | |
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@netless/window-manager",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.16-canary.1",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.es.js",
|
6
6
|
"module": "dist/index.es.js",
|
@@ -22,9 +22,9 @@
|
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
24
|
"@juggle/resize-observer": "^3.3.1",
|
25
|
-
"@netless/app-docs-viewer": "0.1.
|
25
|
+
"@netless/app-docs-viewer": "0.1.24",
|
26
26
|
"@netless/app-media-player": "0.1.0-beta.5",
|
27
|
-
"@netless/telebox-insider": "0.2.
|
27
|
+
"@netless/telebox-insider": "0.2.10",
|
28
28
|
"emittery": "^0.9.2",
|
29
29
|
"lodash": "^4.17.21",
|
30
30
|
"p-retry": "^4.6.1",
|
package/src/MainView.ts
CHANGED
@@ -26,6 +26,9 @@ export class MainViewProxy extends Base {
|
|
26
26
|
this.start();
|
27
27
|
}, 200); // 等待 mainView 挂载完毕再进行监听,否则会触发不必要的 onSizeUpdated
|
28
28
|
});
|
29
|
+
emitter.on("playgroundSizeChange", () => {
|
30
|
+
this.sizeChangeHandler(this.mainViewSize);
|
31
|
+
});
|
29
32
|
}
|
30
33
|
|
31
34
|
private get mainViewCamera() {
|
@@ -43,10 +46,9 @@ export class MainViewProxy extends Base {
|
|
43
46
|
|
44
47
|
public start() {
|
45
48
|
if (this.started) return;
|
49
|
+
this.sizeChangeHandler(this.mainViewSize);
|
46
50
|
this.addCameraListener();
|
47
51
|
this.manager.refresher?.add(Fields.MainViewCamera, this.cameraReaction);
|
48
|
-
this.manager.refresher?.add(Fields.MainViewSize, this.sizeReaction);
|
49
|
-
this.view.callbacks.on("onSizeUpdated", this.sizeListener);
|
50
52
|
this.started = true;
|
51
53
|
}
|
52
54
|
|
@@ -60,6 +62,7 @@ export class MainViewProxy extends Base {
|
|
60
62
|
() => this.mainViewCamera,
|
61
63
|
camera => {
|
62
64
|
if (camera && camera.id !== this.context.uid) {
|
65
|
+
this.moveCameraToContian(this.mainViewSize);
|
63
66
|
this.moveCamera(camera);
|
64
67
|
}
|
65
68
|
},
|
@@ -69,20 +72,12 @@ export class MainViewProxy extends Base {
|
|
69
72
|
);
|
70
73
|
};
|
71
74
|
|
72
|
-
private
|
73
|
-
|
74
|
-
()
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
this.moveCamera(this.mainViewCamera);
|
79
|
-
}
|
80
|
-
},
|
81
|
-
{
|
82
|
-
fireImmediately: true,
|
83
|
-
}
|
84
|
-
);
|
85
|
-
};
|
75
|
+
private sizeChangeHandler = debounce((size: Size) => {
|
76
|
+
if (size) {
|
77
|
+
this.moveCameraToContian(size);
|
78
|
+
this.moveCamera(this.mainViewCamera);
|
79
|
+
}
|
80
|
+
}, 30);
|
86
81
|
|
87
82
|
public get view(): View {
|
88
83
|
return this.mainView;
|
@@ -94,9 +89,6 @@ export class MainViewProxy extends Base {
|
|
94
89
|
|
95
90
|
public createMainView(): View {
|
96
91
|
const mainView = createView(this.manager.displayer);
|
97
|
-
mainView.callbacks.on("onSizeUpdated", () => {
|
98
|
-
this.context.updateManagerRect();
|
99
|
-
});
|
100
92
|
const mainViewScenePath = this.store.getMainViewScenePath();
|
101
93
|
if (mainViewScenePath) {
|
102
94
|
setViewFocusScenePath(mainView, mainViewScenePath);
|
@@ -107,9 +99,9 @@ export class MainViewProxy extends Base {
|
|
107
99
|
return mainView;
|
108
100
|
}
|
109
101
|
|
110
|
-
private
|
102
|
+
private onCameraUpdatedByDevice = (camera: Camera) => {
|
111
103
|
this.store.setMainViewCamera({ ...camera, id: this.context.uid });
|
112
|
-
if (this.
|
104
|
+
if (!isEqual(this.mainViewSize, {...this.mainView.size, id: this.context.uid})) {
|
113
105
|
this.setMainViewSize(this.view.size);
|
114
106
|
}
|
115
107
|
};
|
@@ -141,28 +133,25 @@ export class MainViewProxy extends Base {
|
|
141
133
|
this.context.blurFocusBox();
|
142
134
|
}
|
143
135
|
|
144
|
-
private sizeListener = (size: Size) => {
|
145
|
-
this.setMainViewSize(size);
|
146
|
-
callbacks.emit("cameraStateChange", this.cameraState);
|
147
|
-
};
|
148
|
-
|
149
136
|
public setMainViewSize = debounce(size => {
|
150
137
|
this.store.setMainViewSize({ ...size, id: this.context.uid });
|
151
138
|
}, 50);
|
152
139
|
|
153
140
|
private addCameraListener() {
|
154
|
-
this.view.callbacks.on("onCameraUpdatedByDevice", this.
|
155
|
-
this.view.callbacks.on("onCameraUpdated", this.
|
141
|
+
this.view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
|
142
|
+
this.view.callbacks.on("onCameraUpdated", this.onCameraOrSizeUpdated);
|
143
|
+
this.view.callbacks.on("onSizeUpdated", this.onCameraOrSizeUpdated);
|
156
144
|
}
|
157
145
|
|
158
146
|
private removeCameraListener() {
|
159
|
-
this.view.callbacks.off("onCameraUpdatedByDevice", this.
|
160
|
-
this.view.callbacks.off("onCameraUpdated", this.
|
147
|
+
this.view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
|
148
|
+
this.view.callbacks.off("onCameraUpdated", this.onCameraOrSizeUpdated);
|
149
|
+
this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
|
161
150
|
}
|
162
151
|
|
163
|
-
private
|
152
|
+
private onCameraOrSizeUpdated = () => {
|
164
153
|
callbacks.emit("cameraStateChange", this.cameraState);
|
165
|
-
}
|
154
|
+
};
|
166
155
|
|
167
156
|
public switchViewModeToWriter(): void {
|
168
157
|
if (!this.manager.canOperate) return;
|
@@ -206,7 +195,6 @@ export class MainViewProxy extends Base {
|
|
206
195
|
this.removeCameraListener();
|
207
196
|
this.manager.refresher?.remove(Fields.MainViewCamera);
|
208
197
|
this.manager.refresher?.remove(Fields.MainViewSize);
|
209
|
-
this.view.callbacks.off("onSizeUpdated", this.sizeListener);
|
210
198
|
this.started = false;
|
211
199
|
}
|
212
200
|
|
package/src/index.ts
CHANGED
@@ -135,6 +135,7 @@ export type EmitterEvent = {
|
|
135
135
|
mainViewMounted: undefined;
|
136
136
|
observerIdChange: number;
|
137
137
|
boxStateChange: string;
|
138
|
+
playgroundSizeChange: DOMRect;
|
138
139
|
};
|
139
140
|
|
140
141
|
export const emitter: Emittery<EmitterEvent> = new Emittery();
|
@@ -175,7 +176,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
175
176
|
public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
|
176
177
|
private static isCreated = false;
|
177
178
|
|
178
|
-
public version = "0.3.
|
179
|
+
public version = "0.3.16-canary.1";
|
179
180
|
|
180
181
|
public appListeners?: AppListeners;
|
181
182
|
|
@@ -699,6 +700,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
699
700
|
if (containerRect) {
|
700
701
|
this.updateSizer(containerRect, sizer, wrapper);
|
701
702
|
this.cursorManager?.updateContainerRect();
|
703
|
+
this.appManager?.boxManager.updateManagerRect();
|
704
|
+
emitter.emit("playgroundSizeChange", containerRect);
|
702
705
|
}
|
703
706
|
});
|
704
707
|
|