@netless/window-manager 0.4.11-canary.0 → 0.4.11-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/CHANGELOG.md +11 -2
- package/dist/AppManager.d.ts +2 -0
- package/dist/InternalEmitter.d.ts +1 -0
- package/dist/PageState.d.ts +12 -0
- package/dist/callback.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.es.js +4 -4
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +4 -4
- package/dist/index.umd.js.map +1 -1
- package/docs/advanced.md +24 -0
- package/docs/api.md +9 -0
- package/package.json +1 -1
- package/src/AppManager.ts +19 -9
- package/src/InternalEmitter.ts +1 -0
- package/src/PageState.ts +31 -0
- package/src/Utils/Common.ts +2 -1
- package/src/callback.ts +2 -0
- package/src/index.ts +13 -1
package/docs/advanced.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
- [撤销重做](#redo-undo)
|
5
5
|
- [清屏](#clean-current-scene)
|
6
6
|
- [判断是否打开某种 APP](#has-kind)
|
7
|
+
- [页面控制器](#page-control)
|
7
8
|
|
8
9
|
|
9
10
|
<h3 id="redo-undo">撤销重做</h3>
|
@@ -64,3 +65,26 @@ manager.emitter.on("ready", () => { // ready 事件在所有 app 创建完成后
|
|
64
65
|
const hasSlide = apps.some(app => app.kind === "Slide"); // 判断已经打开的 APP 中是否有 Slide
|
65
66
|
});
|
66
67
|
```
|
68
|
+
|
69
|
+
<br>
|
70
|
+
|
71
|
+
<h3 id="page-control">页面控制器</h3>
|
72
|
+
|
73
|
+
`manager` 提供了一个 `pageState` 来获取当前的 index 和总页数
|
74
|
+
|
75
|
+
```ts
|
76
|
+
manager.pageState.index // 当前的 index
|
77
|
+
manager.pageState.length // 总页数
|
78
|
+
|
79
|
+
manager.emitter.on("pageStateChange", state => {
|
80
|
+
// 当前 index 变化和总页数变化会触发此事件
|
81
|
+
});
|
82
|
+
```
|
83
|
+
|
84
|
+
上一页/下一页/添加一页
|
85
|
+
|
86
|
+
```ts
|
87
|
+
manager.nextPage()
|
88
|
+
manager.prevPage()
|
89
|
+
manager.addPage()
|
90
|
+
```
|
package/docs/api.md
CHANGED
@@ -229,6 +229,7 @@ manager.addPage({ scene: { name: "page2" } }) // 传入 page 信息
|
|
229
229
|
| canRedoSteps | number | | 当前 focus 的 view 可以重做的步数 |
|
230
230
|
| canRedoSteps | number | | 当前 focus 的 view 可以撤销的步数 |
|
231
231
|
| sceneState | SceneState | | 兼容原本 SDK 的 sceneState 属性, 只对 mainView 生效 |
|
232
|
+
| pageState | PageState | | 组合 mainView 的 index 和 scenes 的修改 |
|
232
233
|
|
233
234
|
<br>
|
234
235
|
|
@@ -253,6 +254,7 @@ manager.callbacks.on(events, listener)
|
|
253
254
|
| loadApp | LoadAppEvent | | 加载远程APP 事件 |
|
254
255
|
| ready | undefined | | 当所有 APP 创建完毕时触发 |
|
255
256
|
| sceneStateChange | SceneState | | 当 sceneState 修改时触发 |
|
257
|
+
| pageStateChange | PageState | | |
|
256
258
|
|
257
259
|
```ts
|
258
260
|
type LoadAppEvent = {
|
@@ -260,4 +262,11 @@ type LoadAppEvent = {
|
|
260
262
|
status: "start" | "success" | "failed";
|
261
263
|
reason?: string;
|
262
264
|
}
|
265
|
+
```
|
266
|
+
|
267
|
+
```ts
|
268
|
+
type PageState = {
|
269
|
+
index: number;
|
270
|
+
length: number;
|
271
|
+
}
|
263
272
|
```
|
package/package.json
CHANGED
package/src/AppManager.ts
CHANGED
@@ -107,7 +107,7 @@ export class AppManager {
|
|
107
107
|
|
108
108
|
private onRemoveScenes = (scenePath: string) => {
|
109
109
|
if (scenePath === ROOT_DIR) {
|
110
|
-
this.setMainViewScenePath(
|
110
|
+
this.setMainViewScenePath("");
|
111
111
|
this.createRootDirScenesCallback();
|
112
112
|
this.onRootDirRemoved();
|
113
113
|
emitter.emit("rootDirRemoved");
|
@@ -116,7 +116,7 @@ export class AppManager {
|
|
116
116
|
const mainViewScenePath = this.store.getMainViewScenePath();
|
117
117
|
if (this.room && mainViewScenePath) {
|
118
118
|
if (mainViewScenePath === scenePath) {
|
119
|
-
this.setMainViewScenePath(
|
119
|
+
this.setMainViewScenePath("");
|
120
120
|
}
|
121
121
|
}
|
122
122
|
};
|
@@ -163,7 +163,7 @@ export class AppManager {
|
|
163
163
|
this.updateSceneState(this.callbacksNode);
|
164
164
|
this.mainViewScenesLength = this.callbacksNode.scenes.length;
|
165
165
|
if (isRecreate) {
|
166
|
-
|
166
|
+
this.emitMainViewScenesChange(this.callbacksNode.scenes.length);
|
167
167
|
}
|
168
168
|
}
|
169
169
|
};
|
@@ -171,7 +171,12 @@ export class AppManager {
|
|
171
171
|
private onSceneChange = (node: ScenesCallbacksNode) => {
|
172
172
|
this.mainViewScenesLength = node.scenes.length;
|
173
173
|
this.updateSceneState(node);
|
174
|
-
|
174
|
+
this.emitMainViewScenesChange(this.mainViewScenesLength);
|
175
|
+
};
|
176
|
+
|
177
|
+
private emitMainViewScenesChange = (length: number) => {
|
178
|
+
callbacks.emit("mainViewScenesLengthChange", length);
|
179
|
+
emitter.emit("changePageState");
|
175
180
|
};
|
176
181
|
|
177
182
|
private updateSceneState = (node: ScenesCallbacksNode) => {
|
@@ -264,6 +269,7 @@ export class AppManager {
|
|
264
269
|
const mainSceneIndex = get(this.attributes, "_mainSceneIndex");
|
265
270
|
if (mainSceneIndex !== undefined && this._prevSceneIndex !== mainSceneIndex) {
|
266
271
|
callbacks.emit("mainViewSceneIndexChange", mainSceneIndex);
|
272
|
+
emitter.emit("changePageState");
|
267
273
|
if (this.callbacksNode) {
|
268
274
|
this.updateSceneState(this.callbacksNode);
|
269
275
|
}
|
@@ -300,10 +306,7 @@ export class AppManager {
|
|
300
306
|
if (!this.attributes.apps || Object.keys(this.attributes.apps).length === 0) {
|
301
307
|
const mainScenePath = this.store.getMainViewScenePath();
|
302
308
|
if (!mainScenePath) return;
|
303
|
-
|
304
|
-
if (sceneState.scenePath !== mainScenePath) {
|
305
|
-
setScenePath(this.room, mainScenePath);
|
306
|
-
}
|
309
|
+
this.resetScenePath(mainScenePath);
|
307
310
|
}
|
308
311
|
this.displayerWritableListener(!this.room?.isWritable);
|
309
312
|
this.displayer.callbacks.on("onEnableWriteNowChanged", this.displayerWritableListener);
|
@@ -389,7 +392,7 @@ export class AppManager {
|
|
389
392
|
this.boxManager?.setMinimized(Boolean(minimized));
|
390
393
|
}, 0);
|
391
394
|
}
|
392
|
-
}
|
395
|
+
};
|
393
396
|
|
394
397
|
public refresh() {
|
395
398
|
this.attributesUpdateCallback(this.attributes.apps);
|
@@ -434,6 +437,13 @@ export class AppManager {
|
|
434
437
|
}
|
435
438
|
}
|
436
439
|
|
440
|
+
private resetScenePath(scenePath: string) {
|
441
|
+
const sceneState = this.displayer.state.sceneState;
|
442
|
+
if (sceneState.scenePath !== scenePath) {
|
443
|
+
setScenePath(this.room, scenePath);
|
444
|
+
}
|
445
|
+
}
|
446
|
+
|
437
447
|
public async addApp(params: AddAppParams, isDynamicPPT: boolean): Promise<string | undefined> {
|
438
448
|
log("addApp", params);
|
439
449
|
const { appId, needFocus } = await this.beforeAddApp(params, isDynamicPPT);
|
package/src/InternalEmitter.ts
CHANGED
package/src/PageState.ts
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import type { AppManager } from "./AppManager";
|
2
|
+
import { callbacks } from "./callback";
|
3
|
+
import { emitter } from "./InternalEmitter";
|
4
|
+
|
5
|
+
export type PageState = {
|
6
|
+
index: number;
|
7
|
+
length: number;
|
8
|
+
}
|
9
|
+
|
10
|
+
export class PageStateImpl {
|
11
|
+
constructor(private manager: AppManager) {
|
12
|
+
emitter.on("changePageState", () => {
|
13
|
+
callbacks.emit("pageStateChange", this.toObject())
|
14
|
+
});
|
15
|
+
};
|
16
|
+
|
17
|
+
public get index(): number {
|
18
|
+
return this.manager?.store.getMainViewSceneIndex() || 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
public get length(): number {
|
22
|
+
return this.manager?.mainViewScenesLength || 0;
|
23
|
+
}
|
24
|
+
|
25
|
+
public toObject(): PageState {
|
26
|
+
return {
|
27
|
+
index: this.index,
|
28
|
+
length: this.length
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
package/src/Utils/Common.ts
CHANGED
@@ -33,7 +33,8 @@ export const setViewSceneIndex = (view: View, index: number) => {
|
|
33
33
|
export const setScenePath = (room: Room | undefined, scenePath: string) => {
|
34
34
|
if (room && room.isWritable) {
|
35
35
|
if (room.state.sceneState.scenePath !== scenePath) {
|
36
|
-
|
36
|
+
const nextScenePath = scenePath === "/" ? "" : scenePath;
|
37
|
+
room.setScenePath(nextScenePath);
|
37
38
|
}
|
38
39
|
}
|
39
40
|
};
|
package/src/callback.ts
CHANGED
@@ -2,6 +2,7 @@ import Emittery from "emittery";
|
|
2
2
|
import type { TeleBoxColorScheme, TELE_BOX_STATE } from "@netless/telebox-insider";
|
3
3
|
import type { CameraState, SceneState, ViewVisionMode } from "white-web-sdk";
|
4
4
|
import type { LoadAppEvent } from "./Register";
|
5
|
+
import type { PageState } from "./PageState";
|
5
6
|
|
6
7
|
export type PublicEvent = {
|
7
8
|
mainViewModeChange: ViewVisionMode;
|
@@ -18,6 +19,7 @@ export type PublicEvent = {
|
|
18
19
|
loadApp: LoadAppEvent;
|
19
20
|
ready: undefined; // 所有 APP 创建完毕时触发
|
20
21
|
sceneStateChange: SceneState;
|
22
|
+
pageStateChange: PageState;
|
21
23
|
};
|
22
24
|
|
23
25
|
export type CallbacksType = Emittery<PublicEvent>;
|
package/src/index.ts
CHANGED
@@ -13,6 +13,7 @@ import { initDb } from "./Register/storage";
|
|
13
13
|
import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
|
14
14
|
import { isEqual, isNull, isObject, omit } from "lodash";
|
15
15
|
import { log } from "./Utils/log";
|
16
|
+
import { PageStateImpl } from "./PageState";
|
16
17
|
import { ReconnectRefresher } from "./ReconnectRefresher";
|
17
18
|
import { replaceRoomFunction } from "./Utils/RoomHacker";
|
18
19
|
import { setupBuiltin } from "./BuiltinApps";
|
@@ -56,6 +57,7 @@ import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider"
|
|
56
57
|
import type { AppProxy } from "./AppProxy";
|
57
58
|
import type { PublicEvent } from "./Callback";
|
58
59
|
import type Emittery from "emittery";
|
60
|
+
import type { PageState } from "./PageState";
|
59
61
|
|
60
62
|
export type WindowMangerAttributes = {
|
61
63
|
modelValue?: string;
|
@@ -168,6 +170,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
168
170
|
public cursorManager?: CursorManager;
|
169
171
|
public viewMode = ViewMode.Broadcaster;
|
170
172
|
public isReplay = isPlayer(this.displayer);
|
173
|
+
private _pageState?: PageStateImpl;
|
171
174
|
|
172
175
|
private boxManager?: BoxManager;
|
173
176
|
private static params?: MountParams;
|
@@ -235,6 +238,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
235
238
|
await manager.ensureAttributes();
|
236
239
|
|
237
240
|
manager.appManager = new AppManager(manager);
|
241
|
+
manager._pageState = new PageStateImpl(manager.appManager);
|
238
242
|
manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor));
|
239
243
|
|
240
244
|
if (params.container) {
|
@@ -678,6 +682,14 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
678
682
|
}
|
679
683
|
}
|
680
684
|
|
685
|
+
public get pageState(): PageState {
|
686
|
+
if (this._pageState) {
|
687
|
+
return this._pageState.toObject();
|
688
|
+
} else {
|
689
|
+
throw new AppManagerNotInitError();
|
690
|
+
}
|
691
|
+
}
|
692
|
+
|
681
693
|
/**
|
682
694
|
* 查询所有的 App
|
683
695
|
*/
|
@@ -875,4 +887,4 @@ setupBuiltin();
|
|
875
887
|
export * from "./typings";
|
876
888
|
|
877
889
|
export { BuiltinApps } from "./BuiltinApps";
|
878
|
-
export type { PublicEvent } from "./callback";
|
890
|
+
export type { PublicEvent } from "./callback";
|