@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/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(1)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "0.4.28",
3
+ "version": "0.4.29",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
@@ -231,13 +231,17 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
231
231
  }
232
232
  };
233
233
 
234
- public removePage = async (index: number): Promise<boolean> => {
235
- if (index < 0 || index >= this.pageState.length) {
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(index);
240
- return true;
244
+ return this.appProxy.removeSceneByIndex(needRemoveIndex);;
241
245
  }
242
246
 
243
247
  public get pageState(): PageState {
@@ -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 { calculateNextIndex, PageRemoveService, PageState } from "../Page";
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
- public async removePage(index: number): Promise<boolean> {
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 (index < 0 || index >= this.pageState.length) {
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(index);;
556
+ return this.appManager.removeSceneByIndex(needRemoveIndex);;
551
557
  } else {
552
558
  return false;
553
559
  }