@netless/window-manager 0.4.28 → 0.4.29
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 +5 -0
- package/dist/App/AppContext.d.ts +1 -1
- package/dist/App/AppProxy.d.ts +1 -1
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.es.js +11 -9
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/docs/api.md +3 -1
- package/package.json +1 -1
- package/src/App/AppContext.ts +8 -4
- package/src/App/AppProxy.ts +2 -5
- package/src/index.ts +9 -3
package/docs/api.md
CHANGED
@@ -218,9 +218,11 @@ manager.addPage({ scene: { name: "page2" } }) // 传入 page 信息
|
|
218
218
|
<h3 id="removePage">removePage</h3>
|
219
219
|
|
220
220
|
> 移除一页
|
221
|
+
> 当只剩一页时, 最后一页不允许被删除
|
221
222
|
|
222
223
|
```ts
|
223
|
-
const success = await manager.removePage(
|
224
|
+
const success = await manager.removePage() // 默认删除当前页
|
225
|
+
const success = await manager.removePage(1) // 可以删除指定 index
|
224
226
|
```
|
225
227
|
|
226
228
|
<h3 id="refresh">refresh</h3>
|
package/package.json
CHANGED
package/src/App/AppContext.ts
CHANGED
@@ -231,13 +231,17 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
|
|
231
231
|
}
|
232
232
|
};
|
233
233
|
|
234
|
-
public removePage = async (index
|
235
|
-
|
234
|
+
public removePage = async (index?: number): Promise<boolean> => {
|
235
|
+
const needRemoveIndex = index === undefined ? this.pageState.index : index;
|
236
|
+
if (this.pageState.length === 1) {
|
237
|
+
console.warn(`[WindowManager]: can not remove the last page`);
|
238
|
+
return false;
|
239
|
+
}
|
240
|
+
if (needRemoveIndex < 0 || needRemoveIndex >= this.pageState.length) {
|
236
241
|
console.warn(`[WindowManager]: page index ${index} out of range`);
|
237
242
|
return false;
|
238
243
|
}
|
239
|
-
this.appProxy.removeSceneByIndex(
|
240
|
-
return true;
|
244
|
+
return this.appProxy.removeSceneByIndex(needRemoveIndex);;
|
241
245
|
}
|
242
246
|
|
243
247
|
public get pageState(): PageState {
|
package/src/App/AppProxy.ts
CHANGED
@@ -27,7 +27,8 @@ import type { SceneState, View, SceneDefinition } from "white-web-sdk";
|
|
27
27
|
import type { AppManager } from "../AppManager";
|
28
28
|
import type { NetlessApp } from "../typings";
|
29
29
|
import type { ReadonlyTeleBox } from "@netless/telebox-insider";
|
30
|
-
import {
|
30
|
+
import type { PageRemoveService, PageState } from "../Page";
|
31
|
+
import { calculateNextIndex } from "../Page";
|
31
32
|
|
32
33
|
export type AppEmitter = Emittery<AppEmitterEvent>;
|
33
34
|
|
@@ -415,10 +416,6 @@ export class AppProxy implements PageRemoveService {
|
|
415
416
|
public async removeSceneByIndex(index: number) {
|
416
417
|
const scenePath = this._pageState.getFullPath(index);
|
417
418
|
if (scenePath) {
|
418
|
-
// 不能删除所有场景
|
419
|
-
if (this.pageState.length <= 1) {
|
420
|
-
return false;
|
421
|
-
}
|
422
419
|
const nextIndex = calculateNextIndex(index, this.pageState);
|
423
420
|
// 只修改 focus path 不修改 FullPath
|
424
421
|
this.setSceneIndexWithoutSync(nextIndex);
|
package/src/index.ts
CHANGED
@@ -537,17 +537,23 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
537
537
|
}
|
538
538
|
}
|
539
539
|
|
540
|
-
|
540
|
+
/**
|
541
|
+
* 删除一页
|
542
|
+
* 默认删除当前页, 可以删除指定 index 页
|
543
|
+
* 最低保留一页
|
544
|
+
*/
|
545
|
+
public async removePage(index?: number): Promise<boolean> {
|
541
546
|
if (this.appManager) {
|
547
|
+
const needRemoveIndex = index === undefined ? this.pageState.index : index;
|
542
548
|
if (this.pageState.length === 1) {
|
543
549
|
console.warn(`[WindowManager]: can not remove the last page`);
|
544
550
|
return false;
|
545
551
|
}
|
546
|
-
if (
|
552
|
+
if (needRemoveIndex < 0 || needRemoveIndex >= this.pageState.length) {
|
547
553
|
console.warn(`[WindowManager]: index ${index} out of range`);
|
548
554
|
return false;
|
549
555
|
}
|
550
|
-
return this.appManager.removeSceneByIndex(
|
556
|
+
return this.appManager.removeSceneByIndex(needRemoveIndex);;
|
551
557
|
} else {
|
552
558
|
return false;
|
553
559
|
}
|