@netless/window-manager 0.4.20 → 0.4.21

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 CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.4.21
2
+
3
+ 1. 添加 `manager.refresh()` 方法用于从其他房间 `copy` `attributes`
1
4
  ## 0.4.20
2
5
 
3
6
  1. 导出 Page 相关类型
@@ -15,4 +15,5 @@ export declare class AppListeners {
15
15
  private moveCameraToContainHandler;
16
16
  private cursorMoveHandler;
17
17
  private rootDirRemovedHandler;
18
+ private refreshHandler;
18
19
  }
@@ -50,15 +50,18 @@ export declare class AppManager {
50
50
  get uid(): string;
51
51
  getMainViewSceneDir(): string;
52
52
  private onCreated;
53
+ addAppsChangeListener: () => void;
54
+ addAppCloseListener: () => void;
53
55
  private onMainViewIndexChange;
54
56
  private onFocusChange;
57
+ attributesUpdateCallback: import("lodash").DebouncedFunc<(apps: any) => Promise<void>>;
55
58
  /**
56
59
  * 插件更新 attributes 时的回调
57
60
  *
58
61
  * @param {*} attributes
59
62
  * @memberof WindowManager
60
63
  */
61
- attributesUpdateCallback(apps: any): Promise<void>;
64
+ _attributesUpdateCallback(apps: any): Promise<void>;
62
65
  private onRegisteredChange;
63
66
  private onMinimized;
64
67
  refresh(): void;
@@ -14,7 +14,9 @@ export declare class ReconnectRefresher {
14
14
  setContext(ctx: ReconnectRefresherContext): void;
15
15
  private onPhaseChanged;
16
16
  private onReconnected;
17
+ private _onReconnected;
17
18
  private releaseDisposers;
19
+ refresh(): void;
18
20
  add(id: string, func: any): void;
19
21
  remove(id: string): void;
20
22
  hasReactor(id: string): boolean;
@@ -13,7 +13,8 @@ export declare enum Events {
13
13
  MoveCamera = "MoveCamera",
14
14
  MoveCameraToContain = "MoveCameraToContain",
15
15
  CursorMove = "CursorMove",
16
- RootDirRemoved = "RootDirRemoved"
16
+ RootDirRemoved = "RootDirRemoved",
17
+ Refresh = "Refresh"
17
18
  }
18
19
  export declare const MagixEventName = "__WindowManger";
19
20
  export declare enum AppAttributes {
package/dist/index.d.ts CHANGED
@@ -229,6 +229,9 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
229
229
  completeImageUpload(uuid: string, url: string): void;
230
230
  lockImage(uuid: string, locked: boolean): void;
231
231
  lockImages(locked: boolean): void;
232
+ refresh(): void;
233
+ /** @inner */
234
+ _refresh(): void;
232
235
  private isDynamicPPT;
233
236
  private ensureAttributes;
234
237
  }
package/dist/index.es.js CHANGED
@@ -41,6 +41,7 @@ var Events = /* @__PURE__ */ ((Events2) => {
41
41
  Events2["MoveCameraToContain"] = "MoveCameraToContain";
42
42
  Events2["CursorMove"] = "CursorMove";
43
43
  Events2["RootDirRemoved"] = "RootDirRemoved";
44
+ Events2["Refresh"] = "Refresh";
44
45
  return Events2;
45
46
  })(Events || {});
46
47
  const MagixEventName = "__WindowManger";
@@ -465,6 +466,10 @@ class AppListeners {
465
466
  this.rootDirRemovedHandler();
466
467
  break;
467
468
  }
469
+ case Events.Refresh: {
470
+ this.refreshHandler();
471
+ break;
472
+ }
468
473
  }
469
474
  }
470
475
  };
@@ -500,6 +505,9 @@ class AppListeners {
500
505
  this.manager.mainViewProxy.rebind();
501
506
  emitter.emit("rootDirRemoved");
502
507
  };
508
+ this.refreshHandler = () => {
509
+ this.manager.windowManger._refresh();
510
+ };
503
511
  }
504
512
  get boxManager() {
505
513
  return this.manager.boxManager;
@@ -1916,6 +1924,22 @@ class AppManager {
1916
1924
  };
1917
1925
  callbacks$1.emit("sceneStateChange", this.sceneState);
1918
1926
  };
1927
+ this.addAppsChangeListener = () => {
1928
+ var _a;
1929
+ (_a = this.refresher) == null ? void 0 : _a.add("apps", () => {
1930
+ return safeListenPropsUpdated(() => this.attributes.apps, () => {
1931
+ this.attributesUpdateCallback(this.attributes.apps);
1932
+ });
1933
+ });
1934
+ };
1935
+ this.addAppCloseListener = () => {
1936
+ var _a;
1937
+ (_a = this.refresher) == null ? void 0 : _a.add("appsClose", () => {
1938
+ return onObjectRemoved(this.attributes.apps, () => {
1939
+ this.onAppDelete(this.attributes.apps);
1940
+ });
1941
+ });
1942
+ };
1919
1943
  this.onMainViewIndexChange = (index) => {
1920
1944
  if (index !== void 0 && this._prevSceneIndex !== index) {
1921
1945
  callbacks$1.emit("mainViewSceneIndexChange", index);
@@ -1943,6 +1967,7 @@ class AppManager {
1943
1967
  }
1944
1968
  }
1945
1969
  };
1970
+ this.attributesUpdateCallback = debounce((apps) => this._attributesUpdateCallback(apps), 100);
1946
1971
  this.onRegisteredChange = (registered) => {
1947
1972
  if (!registered)
1948
1973
  return;
@@ -2153,46 +2178,38 @@ class AppManager {
2153
2178
  }
2154
2179
  }
2155
2180
  async onCreated() {
2156
- var _a, _b, _c, _d, _e2, _f, _g, _h;
2181
+ var _a, _b, _c, _d, _e2, _f;
2157
2182
  await this.attributesUpdateCallback(this.attributes.apps);
2158
2183
  emitter.emit("updateManagerRect");
2159
2184
  emitter.onAny(this.boxEventListener);
2160
- (_a = this.refresher) == null ? void 0 : _a.add("apps", () => {
2161
- return safeListenPropsUpdated(() => this.attributes.apps, () => {
2162
- this.attributesUpdateCallback(this.attributes.apps);
2163
- });
2164
- });
2165
- (_b = this.refresher) == null ? void 0 : _b.add("appsClose", () => {
2166
- return onObjectRemoved(this.attributes.apps, () => {
2167
- this.onAppDelete(this.attributes.apps);
2168
- });
2169
- });
2170
- (_c = this.refresher) == null ? void 0 : _c.add("maximized", () => {
2185
+ this.addAppsChangeListener();
2186
+ this.addAppCloseListener();
2187
+ (_a = this.refresher) == null ? void 0 : _a.add("maximized", () => {
2171
2188
  return autorun(() => {
2172
2189
  var _a2;
2173
2190
  const maximized = this.attributes.maximized;
2174
2191
  (_a2 = this.boxManager) == null ? void 0 : _a2.setMaximized(Boolean(maximized));
2175
2192
  });
2176
2193
  });
2177
- (_d = this.refresher) == null ? void 0 : _d.add("minimized", () => {
2194
+ (_b = this.refresher) == null ? void 0 : _b.add("minimized", () => {
2178
2195
  return autorun(() => {
2179
2196
  const minimized = this.attributes.minimized;
2180
2197
  this.onMinimized(minimized);
2181
2198
  });
2182
2199
  });
2183
- (_e2 = this.refresher) == null ? void 0 : _e2.add("mainViewIndex", () => {
2200
+ (_c = this.refresher) == null ? void 0 : _c.add("mainViewIndex", () => {
2184
2201
  return autorun(() => {
2185
2202
  const mainSceneIndex = get(this.attributes, "_mainSceneIndex");
2186
2203
  this.onMainViewIndexChange(mainSceneIndex);
2187
2204
  });
2188
2205
  });
2189
- (_f = this.refresher) == null ? void 0 : _f.add("focusedChange", () => {
2206
+ (_d = this.refresher) == null ? void 0 : _d.add("focusedChange", () => {
2190
2207
  return autorun(() => {
2191
2208
  const focused = get(this.attributes, "focus");
2192
2209
  this.onFocusChange(focused);
2193
2210
  });
2194
2211
  });
2195
- (_g = this.refresher) == null ? void 0 : _g.add("registeredChange", () => {
2212
+ (_e2 = this.refresher) == null ? void 0 : _e2.add("registeredChange", () => {
2196
2213
  return autorun(() => {
2197
2214
  const registered = get(this.attributes, Fields.Registered);
2198
2215
  this.onRegisteredChange(registered);
@@ -2204,7 +2221,7 @@ class AppManager {
2204
2221
  return;
2205
2222
  this.resetScenePath(mainScenePath);
2206
2223
  }
2207
- this.displayerWritableListener(!((_h = this.room) == null ? void 0 : _h.isWritable));
2224
+ this.displayerWritableListener(!((_f = this.room) == null ? void 0 : _f.isWritable));
2208
2225
  this.displayer.callbacks.on("onEnableWriteNowChanged", this.displayerWritableListener);
2209
2226
  this._prevFocused = this.attributes.focus;
2210
2227
  this.sideEffectManager.add(() => {
@@ -2216,7 +2233,7 @@ class AppManager {
2216
2233
  return () => redoUndo.destroy();
2217
2234
  });
2218
2235
  }
2219
- async attributesUpdateCallback(apps) {
2236
+ async _attributesUpdateCallback(apps) {
2220
2237
  if (apps && WindowManager.container) {
2221
2238
  const appIds = Object.keys(apps);
2222
2239
  if (appIds.length === 0) {
@@ -5517,6 +5534,9 @@ class ReconnectRefresher {
5517
5534
  this.phase = phase;
5518
5535
  };
5519
5536
  this.onReconnected = debounce(() => {
5537
+ this._onReconnected();
5538
+ }, 3e3);
5539
+ this._onReconnected = () => {
5520
5540
  log("onReconnected refresh reactors");
5521
5541
  this.releaseDisposers();
5522
5542
  this.reactors.forEach((func, id2) => {
@@ -5525,7 +5545,7 @@ class ReconnectRefresher {
5525
5545
  }
5526
5546
  });
5527
5547
  this.ctx.emitter.emit("onReconnected", void 0);
5528
- }, 3e3);
5548
+ };
5529
5549
  }
5530
5550
  setRoom(room) {
5531
5551
  this.room = room;
@@ -5544,7 +5564,14 @@ class ReconnectRefresher {
5544
5564
  });
5545
5565
  this.disposers.clear();
5546
5566
  }
5567
+ refresh() {
5568
+ this._onReconnected();
5569
+ }
5547
5570
  add(id2, func) {
5571
+ const disposer = this.disposers.get(id2);
5572
+ if (disposer && isFunction(disposer)) {
5573
+ disposer();
5574
+ }
5548
5575
  if (isFunction(func)) {
5549
5576
  this.reactors.set(id2, func);
5550
5577
  this.disposers.set(id2, func());
@@ -14812,7 +14839,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
14812
14839
  const _WindowManager = class extends InvisiblePlugin {
14813
14840
  constructor(context) {
14814
14841
  super(context);
14815
- this.version = "0.4.20";
14842
+ this.version = "0.4.21";
14816
14843
  this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.2.26", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^0.1.5", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/jest": "^27.4.1", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jest": "^27.5.1", "jest-canvas-mock": "^2.3.1", "jest-fetch-mock": "^3.0.3", "jest-transform-stub": "^2.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "svelte-jester": "^2.3.2", "ts-jest": "^27.1.4", "typescript": "^4.5.5", "vite": "^2.5.3", "white-web-sdk": "2.16.10" } };
14817
14844
  this.emitter = callbacks$1;
14818
14845
  this.viewMode = ViewMode.Broadcaster;
@@ -14937,6 +14964,9 @@ const _WindowManager = class extends InvisiblePlugin {
14937
14964
  if (_WindowManager.params) {
14938
14965
  const params = _WindowManager.params;
14939
14966
  const mainViewElement = _WindowManager.initContainer(this, container, params.chessboard, params.overwriteStyles);
14967
+ if (this.boxManager) {
14968
+ this.boxManager.destroy();
14969
+ }
14940
14970
  const boxManager = createBoxManager(this, callbacks$1, emitter, {
14941
14971
  collectorContainer: params.collectorContainer,
14942
14972
  collectorStyles: params.collectorStyles,
@@ -15402,6 +15432,19 @@ const _WindowManager = class extends InvisiblePlugin {
15402
15432
  var _a;
15403
15433
  return (_a = this.focusedView) == null ? void 0 : _a.lockImages(locked);
15404
15434
  }
15435
+ refresh() {
15436
+ var _a;
15437
+ this._refresh();
15438
+ (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.Refresh);
15439
+ }
15440
+ _refresh() {
15441
+ var _a, _b, _c;
15442
+ (_a = this.appManager) == null ? void 0 : _a.mainViewProxy.rebind();
15443
+ if (_WindowManager.container) {
15444
+ this.bindContainer(_WindowManager.container);
15445
+ }
15446
+ (_c = (_b = this.appManager) == null ? void 0 : _b.refresher) == null ? void 0 : _c.refresh();
15447
+ }
15405
15448
  isDynamicPPT(scenes) {
15406
15449
  var _a, _b;
15407
15450
  const sceneSrc = (_b = (_a = scenes[0]) == null ? void 0 : _a.ppt) == null ? void 0 : _b.src;