@netless/window-manager 0.4.27 → 0.4.30-canary.0

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
@@ -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.27",
3
+ "version": "0.4.30-canary.0",
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,
@@ -181,7 +181,10 @@ export class AppManager {
181
181
  }
182
182
  this.callbacksNode = this.displayer.createScenesCallback(ROOT_DIR, {
183
183
  onAddScene: this.onSceneChange,
184
- onRemoveScene: this.onSceneChange,
184
+ onRemoveScene: async (node, name) => {
185
+ await this.onSceneChange(node);
186
+ emitter.emit("rootDirSceneRemoved", name);
187
+ },
185
188
  });
186
189
  if (this.callbacksNode) {
187
190
  this.updateSceneState(this.callbacksNode);
@@ -196,13 +199,22 @@ export class AppManager {
196
199
  const nextIndex = calculateNextIndex(index, this.windowManger.pageState);
197
200
  this.setSceneIndexWithoutSync(nextIndex);
198
201
  this.dispatchInternalEvent(Events.SetAppFocusIndex, { type: "main", index: nextIndex });
202
+ const scene = this.callbacksNode?.scenes[index];
199
203
  setTimeout(() => {
200
- const scene = this.callbacksNode?.scenes[index];
201
204
  if (scene) {
202
205
  removeScenes(this.room, `${ROOT_DIR}${scene}`, index)
203
206
  }
204
207
  }, 100);
205
- return true;
208
+ return new Promise<boolean>((resolve, reject) => {
209
+ emitter.once("rootDirSceneRemoved").then(name => {
210
+ if (name === scene) {
211
+ resolve(true);
212
+ }
213
+ }).catch(e => {
214
+ console.log(`[WindowManager]: removePage error: ${e}`);
215
+ reject(false);
216
+ });
217
+ });
206
218
  }
207
219
 
208
220
  public setSceneIndexWithoutSync = (index: number) => {
@@ -215,12 +227,14 @@ export class AppManager {
215
227
  private onSceneChange = (node: ScenesCallbacksNode) => {
216
228
  this.mainViewScenesLength = node.scenes.length;
217
229
  this.updateSceneState(node);
218
- this.emitMainViewScenesChange(this.mainViewScenesLength);
230
+ return this.emitMainViewScenesChange(this.mainViewScenesLength);
219
231
  };
220
232
 
221
233
  private emitMainViewScenesChange = (length: number) => {
222
- callbacks.emit("mainViewScenesLengthChange", length);
223
- emitter.emit("changePageState");
234
+ return Promise.all([
235
+ callbacks.emit("mainViewScenesLengthChange", length),
236
+ emitter.emit("changePageState"),
237
+ ]);
224
238
  };
225
239
 
226
240
  private updateSceneState = (node: ScenesCallbacksNode) => {
@@ -25,7 +25,8 @@ export type EmitterEvent = {
25
25
  cursorMove: CursorMovePayload;
26
26
  updateManagerRect: undefined;
27
27
  focusedChange: { focused: string | undefined; prev: string | undefined };
28
- rootDirRemoved: undefined;
28
+ rootDirRemoved: undefined; // 根目录整个被删除
29
+ rootDirSceneRemoved: string; // 根目录下的场景被删除
29
30
  setReadonly: boolean;
30
31
  changePageState: undefined;
31
32
  writableChange: boolean;
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
  }