@netless/window-manager 0.4.0-canary.14 → 0.4.0-canary.15
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 +1 -0
- package/dist/AppManager.d.ts +2 -1
- package/dist/Utils/Common.d.ts +3 -1
- 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 +8 -6
- package/docs/concept.md +4 -0
- package/package.json +1 -1
- package/src/AppManager.ts +37 -19
- package/src/Utils/Common.ts +22 -1
- package/src/index.ts +10 -0
package/docs/api.md
CHANGED
@@ -107,12 +107,13 @@ manager.closeApp(appId)
|
|
107
107
|
|
108
108
|
<h2 id="prototypes">实例属性</h2>
|
109
109
|
|
110
|
-
| name | type | default | desc
|
111
|
-
| ------------------ | ------- | ------- |
|
112
|
-
| mainView | View | | 主白板
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
| name | type | default | desc |
|
111
|
+
| ------------------ | ------- | ------- | ----------------- |
|
112
|
+
| mainView | View | | 主白板 |
|
113
|
+
| mainViewSceneIndex | number | | 当前主白板的 SceneIndex |
|
114
|
+
| boxState | string | | 当前窗口状态 |
|
115
|
+
| darkMode | boolean | | 黑夜模式 |
|
116
|
+
| prefersColorScheme | string | | 颜色主题 |
|
116
117
|
|
117
118
|
|
118
119
|
<h2 id="events">事件回调</h2>
|
@@ -124,6 +125,7 @@ manager.callbacks.on(events, listener)
|
|
124
125
|
| name | type | default | desc |
|
125
126
|
| ------------------------ | -------------- | ------- | -------------------------- |
|
126
127
|
| mainViewModeChange | ViewVisionMode | | |
|
128
|
+
| mainViewSceneIndexChange | index: number | | |
|
127
129
|
| boxStateChange | string | | normal,minimized,maximized |
|
128
130
|
| darkModeChange | boolean | | |
|
129
131
|
| prefersColorSchemeChange | string | | auto,light,dark |
|
package/docs/concept.md
ADDED
package/package.json
CHANGED
package/src/AppManager.ts
CHANGED
@@ -4,11 +4,11 @@ import { AppListeners } from "./AppListener";
|
|
4
4
|
import { AppProxy } from "./AppProxy";
|
5
5
|
import { autorun, isPlayer, isRoom, ScenePathType } from "white-web-sdk";
|
6
6
|
import { callbacks, emitter, WindowManager, reconnectRefresher } from "./index";
|
7
|
-
import { genAppId, makeValidScenePath, setScenePath, setViewFocusScenePath } from "./Utils/Common";
|
7
|
+
import { entireScenes, genAppId, makeValidScenePath, parseSceneDir, setScenePath, setViewFocusScenePath } from "./Utils/Common";
|
8
8
|
import { log } from "./Utils/log";
|
9
9
|
import { MainViewProxy } from "./View/MainView";
|
10
10
|
import { onObjectRemoved, safeListenPropsUpdated } from "./Utils/Reactive";
|
11
|
-
import { get, sortBy } from "lodash";
|
11
|
+
import { get, isInteger, sortBy } from "lodash";
|
12
12
|
import { store } from "./AttributesDelegate";
|
13
13
|
import { ViewManager } from "./View/ViewManager";
|
14
14
|
import type { ReconnectRefresher } from "./ReconnectRefresher";
|
@@ -212,10 +212,11 @@ export class AppManager {
|
|
212
212
|
emitter.emit("mainViewMounted");
|
213
213
|
}
|
214
214
|
|
215
|
-
public setMainViewFocusPath() {
|
216
|
-
const
|
217
|
-
if (
|
218
|
-
setViewFocusScenePath(this.mainView,
|
215
|
+
public setMainViewFocusPath(scenePath?: string) {
|
216
|
+
const focusScenePath = scenePath || this.store.getMainViewScenePath();
|
217
|
+
if (focusScenePath) {
|
218
|
+
const view = setViewFocusScenePath(this.mainView, focusScenePath);
|
219
|
+
return view?.focusScenePath === focusScenePath;
|
219
220
|
}
|
220
221
|
}
|
221
222
|
|
@@ -377,27 +378,44 @@ export class AppManager {
|
|
377
378
|
}
|
378
379
|
|
379
380
|
private async _setMainViewScenePath(scenePath: string) {
|
380
|
-
this.
|
381
|
-
|
382
|
-
|
383
|
-
|
381
|
+
const success = this.setMainViewFocusPath(scenePath);
|
382
|
+
if (success) {
|
383
|
+
this.safeSetAttributes({ _mainScenePath: scenePath });
|
384
|
+
this.store.setMainViewFocusPath(this.mainView);
|
385
|
+
this.updateSceneIndex();
|
386
|
+
this.dispatchInternalEvent(Events.SetMainViewScenePath, { nextScenePath: scenePath });
|
387
|
+
}
|
388
|
+
}
|
389
|
+
|
390
|
+
private updateSceneIndex = () => {
|
391
|
+
const scenePath = this.store.getMainViewScenePath() as string;
|
392
|
+
const sceneDir = parseSceneDir(scenePath);
|
393
|
+
const scenes = entireScenes(this.displayer)[sceneDir];
|
394
|
+
if (scenes.length) {
|
395
|
+
// "/ppt3/1" -> "1"
|
396
|
+
const pageName = scenePath.replace(sceneDir, "").replace("/", "");
|
397
|
+
const index = scenes.findIndex(scene => scene.name === pageName);
|
398
|
+
if (isInteger(index) && index >= 0) {
|
399
|
+
this.safeSetAttributes({ _mainSceneIndex: index });
|
400
|
+
}
|
401
|
+
}
|
384
402
|
}
|
385
403
|
|
386
404
|
public async setMainViewSceneIndex(index: number) {
|
387
405
|
if (this.room) {
|
388
|
-
this.
|
406
|
+
if (this.store.getMainViewSceneIndex() === index) return;
|
389
407
|
const mainViewScenePath = this.store.getMainViewScenePath() as string;
|
390
408
|
if (mainViewScenePath) {
|
391
|
-
const
|
392
|
-
sceneList.pop();
|
393
|
-
let sceneDir = sceneList.join("/");
|
394
|
-
if (sceneDir === "") {
|
395
|
-
sceneDir = "/";
|
396
|
-
}
|
409
|
+
const sceneDir = parseSceneDir(mainViewScenePath);
|
397
410
|
const scenePath = makeValidScenePath(this.displayer, sceneDir, index);
|
398
411
|
if (scenePath) {
|
399
|
-
this.
|
400
|
-
|
412
|
+
const success = this.setMainViewFocusPath(scenePath);
|
413
|
+
if (success) {
|
414
|
+
this.store.setMainViewScenePath(scenePath);
|
415
|
+
this.safeSetAttributes({ _mainSceneIndex: index });
|
416
|
+
}
|
417
|
+
} else {
|
418
|
+
throw new Error(`[WindowManager]: ${sceneDir}: ${index} not valid index`);
|
401
419
|
}
|
402
420
|
}
|
403
421
|
}
|
package/src/Utils/Common.ts
CHANGED
@@ -17,9 +17,17 @@ export const genAppId = async (kind: string) => {
|
|
17
17
|
export const setViewFocusScenePath = (view: View, focusScenePath: string) => {
|
18
18
|
if (view.focusScenePath !== focusScenePath) {
|
19
19
|
view.focusScenePath = focusScenePath;
|
20
|
+
return view;
|
20
21
|
}
|
21
22
|
};
|
22
23
|
|
24
|
+
export const setViewSceneIndex = (view: View, index: number) => {
|
25
|
+
if (view.focusSceneIndex !== index) {
|
26
|
+
view.focusSceneIndex = index;
|
27
|
+
return view;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
23
31
|
export const setScenePath = (room: Room | undefined, scenePath: string) => {
|
24
32
|
if (room && room.isWritable) {
|
25
33
|
if (room.state.sceneState.scenePath !== scenePath) {
|
@@ -70,7 +78,9 @@ export const notifyMainViewModeChange = debounce(
|
|
70
78
|
export const makeValidScenePath = (displayer: Displayer, scenePath: string, index = 0) => {
|
71
79
|
const scenes = entireScenes(displayer)[scenePath];
|
72
80
|
if (!scenes) return;
|
73
|
-
const
|
81
|
+
const scene = scenes[index];
|
82
|
+
if (!scene) return;
|
83
|
+
const firstSceneName = scene.name;
|
74
84
|
if (scenePath === "/") {
|
75
85
|
return `/${firstSceneName}`;
|
76
86
|
} else {
|
@@ -86,6 +96,17 @@ export const isValidScenePath = (scenePath: string) => {
|
|
86
96
|
return scenePath.startsWith("/");
|
87
97
|
};
|
88
98
|
|
99
|
+
export const parseSceneDir = (scenePath: string) => {
|
100
|
+
const sceneList = scenePath.split("/");
|
101
|
+
sceneList.pop();
|
102
|
+
let sceneDir = sceneList.join("/");
|
103
|
+
// "/page1" 的 dir 为 "/"
|
104
|
+
if (sceneDir === "") {
|
105
|
+
sceneDir = "/";
|
106
|
+
}
|
107
|
+
return sceneDir;
|
108
|
+
}
|
109
|
+
|
89
110
|
export const ensureValidScenePath = (scenePath: string) => {
|
90
111
|
if (scenePath.endsWith("/")) {
|
91
112
|
return scenePath.slice(0, -1);
|
package/src/index.ts
CHANGED
@@ -21,6 +21,7 @@ import {
|
|
21
21
|
ensureValidScenePath,
|
22
22
|
getVersionNumber,
|
23
23
|
isValidScenePath,
|
24
|
+
parseSceneDir,
|
24
25
|
wait,
|
25
26
|
} from "./Utils/Common";
|
26
27
|
import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
|
@@ -575,6 +576,15 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
575
576
|
return this.appManager?.store.getMainViewSceneIndex();
|
576
577
|
}
|
577
578
|
|
579
|
+
public get mainViewSceneDir(): string {
|
580
|
+
const scenePath = this.appManager?.store.getMainViewScenePath();
|
581
|
+
if (scenePath) {
|
582
|
+
return parseSceneDir(scenePath);
|
583
|
+
} else {
|
584
|
+
throw new Error("[WindowManager]: mainViewSceneDir not found");
|
585
|
+
}
|
586
|
+
}
|
587
|
+
|
578
588
|
/**
|
579
589
|
* 查询所有的 App
|
580
590
|
*/
|