@netless/window-manager 0.4.27-canary.0 → 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/advanced.md CHANGED
@@ -122,7 +122,16 @@ if (manager.boxState === "maximized") {
122
122
  const app = manager.queryOne(manager.focused)
123
123
  // 有 view 的 app 才可以插入图片, 像是 视频,音频之类的 app 是没有 view 的
124
124
  if (app.view) {
125
- app.view.insertImage()
125
+ var imageInformation = {
126
+ uuid: uuid,
127
+ centerX: centerX,
128
+ centerY: centerY,
129
+ width: width,
130
+ height: height,
131
+ locked: false,
132
+ };
133
+ app.view.insertImage(imageInformation);
134
+ app.view.completeImageUpload(uuid, src);
126
135
  }
127
136
  }
128
137
  ```
package/docs/api.md CHANGED
@@ -27,6 +27,7 @@
27
27
  - [`nextPage`](#nextPage)
28
28
  - [`prevPage`](#prevPage)
29
29
  - [`addPage`](#addPage)
30
+ - [`removePage`](#removePage)
30
31
  - [`refresh`](#refresh)
31
32
  - [`setContainerSizeRatio`](#setContainerSizeRatio)
32
33
  - [实例属性](#prototypes)
@@ -217,9 +218,11 @@ manager.addPage({ scene: { name: "page2" } }) // 传入 page 信息
217
218
  <h3 id="removePage">removePage</h3>
218
219
 
219
220
  > 移除一页
221
+ > 当只剩一页时, 最后一页不允许被删除
220
222
 
221
223
  ```ts
222
- const success = await manager.removePage(1)
224
+ const success = await manager.removePage() // 默认删除当前页
225
+ const success = await manager.removePage(1) // 可以删除指定 index
223
226
  ```
224
227
 
225
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.27-canary.0",
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/AppManager.ts CHANGED
@@ -6,7 +6,7 @@ import { appRegister } from "./Register";
6
6
  import { autorun, isPlayer, isRoom, ScenePathType } from "white-web-sdk";
7
7
  import { callbacks } from "./callback";
8
8
  import { debounce, get, isInteger, orderBy } from "lodash";
9
- import { emitter, RemoveSceneParams } from "./InternalEmitter";
9
+ import { emitter } from "./InternalEmitter";
10
10
  import { Fields, store } from "./AttributesDelegate";
11
11
  import { log } from "./Utils/log";
12
12
  import { MainViewProxy } from "./View/MainView";
@@ -16,7 +16,7 @@ import { RedoUndo } from "./RedoUndo";
16
16
  import { SideEffectManager } from "side-effect-manager";
17
17
  import { ViewManager } from "./View/ViewManager";
18
18
  import type { SyncRegisterAppPayload } from "./Register";
19
- import type { EmitterEvent } from "./InternalEmitter";
19
+ import type { EmitterEvent , RemoveSceneParams } from "./InternalEmitter";
20
20
  import {
21
21
  entireScenes,
22
22
  genAppId,
package/src/Page/index.ts CHANGED
@@ -4,16 +4,15 @@ export * from "./PageController";
4
4
 
5
5
  export const calculateNextIndex = (index: number, pageState: PageState) => {
6
6
  let nextIndex = 0;
7
- if (index === 0) {
8
- return index + 1;
9
- }
10
- if (pageState.index !== 0 && index !== 0) {
11
- const maxIndex = pageState.length - 1;
7
+ const maxIndex = pageState.length - 1;
8
+ if (index === pageState.index) {
12
9
  if (index === maxIndex) {
13
- nextIndex = maxIndex - 1;
14
- } else if (index > 0 && index < maxIndex) {
15
- nextIndex = index + 1;
10
+ nextIndex = index - 1;
11
+ } else {
12
+ nextIndex = pageState.index + 1;
16
13
  }
14
+ } else {
15
+ nextIndex = pageState.index;
17
16
  }
18
17
  return nextIndex;
19
18
  }
package/src/index.ts CHANGED
@@ -537,13 +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) {
542
- if (index < 0 || index >= this.pageState.length) {
547
+ const needRemoveIndex = index === undefined ? this.pageState.index : index;
548
+ if (this.pageState.length === 1) {
549
+ console.warn(`[WindowManager]: can not remove the last page`);
550
+ return false;
551
+ }
552
+ if (needRemoveIndex < 0 || needRemoveIndex >= this.pageState.length) {
543
553
  console.warn(`[WindowManager]: index ${index} out of range`);
544
554
  return false;
545
555
  }
546
- return this.appManager.removeSceneByIndex(index);;
556
+ return this.appManager.removeSceneByIndex(needRemoveIndex);;
547
557
  } else {
548
558
  return false;
549
559
  }