@netless/window-manager 0.4.20 → 0.4.23

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,14 @@
1
+ ## 0.4.23
2
+
3
+ 1. 修复可写进入立即切换成只读造成初始化 camera 失败的问题
4
+
5
+ ## 0.4.22
6
+
7
+ 1. 修复只读端先加入时视角跟随失败的问题
8
+
9
+ ## 0.4.21
10
+
11
+ 1. 添加 `manager.refresh()` 方法用于从其他房间 `copy` `attributes`
1
12
  ## 0.4.20
2
13
 
3
14
  1. 导出 Page 相关类型
@@ -15,4 +15,6 @@ export declare class AppListeners {
15
15
  private moveCameraToContainHandler;
16
16
  private cursorMoveHandler;
17
17
  private rootDirRemovedHandler;
18
+ private refreshHandler;
19
+ private initMainViewCameraHandler;
18
20
  }
@@ -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;
@@ -31,6 +31,12 @@ export declare type StoreContext = {
31
31
  safeUpdateAttributes: (keys: string[], value: any) => void;
32
32
  safeSetAttributes: (attributes: any) => void;
33
33
  };
34
+ export declare type ICamera = Camera & {
35
+ id: string;
36
+ };
37
+ export declare type ISize = Size & {
38
+ id: string;
39
+ };
34
40
  export declare class AttributesDelegate {
35
41
  private context;
36
42
  constructor(context: StoreContext);
@@ -55,12 +61,9 @@ export declare class AttributesDelegate {
55
61
  setMainViewSceneIndex(index: number): void;
56
62
  getMainViewCamera(): MainViewCamera;
57
63
  getMainViewSize(): MainViewSize;
58
- setMainViewCamera(camera: (Camera & {
59
- id: string;
60
- }) | undefined): void;
61
- setMainViewSize(size: (Size & {
62
- id: string;
63
- }) | undefined): void;
64
+ setMainViewCamera(camera: ICamera): void;
65
+ setMainViewSize(size: ISize): void;
66
+ setMainViewCameraAndSize(camera: ICamera, size: ISize): void;
64
67
  setAppFocus: (appId: string, focus: boolean) => void;
65
68
  updateCursor(uid: string, position: Position): void;
66
69
  updateCursorState(uid: string, cursorState: string | undefined): void;
@@ -39,6 +39,7 @@ export declare type EmitterEvent = {
39
39
  rootDirRemoved: undefined;
40
40
  setReadonly: boolean;
41
41
  changePageState: undefined;
42
+ writableChange: boolean;
42
43
  };
43
44
  export declare type EmitterType = Emittery<EmitterEvent>;
44
45
  export declare const emitter: EmitterType;
@@ -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;
@@ -9,10 +9,13 @@ export declare class MainViewProxy {
9
9
  private store;
10
10
  private sideEffectManager;
11
11
  constructor(manager: AppManager);
12
+ private startListenWritableChange;
13
+ ensureCameraAndSize(): void;
12
14
  private get mainViewCamera();
13
15
  private get mainViewSize();
14
16
  private moveCameraSizeByAttributes;
15
17
  start(): void;
18
+ addCameraReaction: () => void;
16
19
  setCameraAndSize(): void;
17
20
  private cameraReaction;
18
21
  private sizeChangeHandler;
@@ -13,7 +13,9 @@ 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",
18
+ InitMainViewCamera = "InitMainViewCamera"
17
19
  }
18
20
  export declare const MagixEventName = "__WindowManger";
19
21
  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,8 @@ var Events = /* @__PURE__ */ ((Events2) => {
41
41
  Events2["MoveCameraToContain"] = "MoveCameraToContain";
42
42
  Events2["CursorMove"] = "CursorMove";
43
43
  Events2["RootDirRemoved"] = "RootDirRemoved";
44
+ Events2["Refresh"] = "Refresh";
45
+ Events2["InitMainViewCamera"] = "InitMainViewCamera";
44
46
  return Events2;
45
47
  })(Events || {});
46
48
  const MagixEventName = "__WindowManger";
@@ -465,6 +467,14 @@ class AppListeners {
465
467
  this.rootDirRemovedHandler();
466
468
  break;
467
469
  }
470
+ case Events.Refresh: {
471
+ this.refreshHandler();
472
+ break;
473
+ }
474
+ case Events.InitMainViewCamera: {
475
+ this.initMainViewCameraHandler();
476
+ break;
477
+ }
468
478
  }
469
479
  }
470
480
  };
@@ -500,6 +510,12 @@ class AppListeners {
500
510
  this.manager.mainViewProxy.rebind();
501
511
  emitter.emit("rootDirRemoved");
502
512
  };
513
+ this.refreshHandler = () => {
514
+ this.manager.windowManger._refresh();
515
+ };
516
+ this.initMainViewCameraHandler = () => {
517
+ this.manager.mainViewProxy.addCameraReaction();
518
+ };
503
519
  }
504
520
  get boxManager() {
505
521
  return this.manager.boxManager;
@@ -1137,6 +1153,12 @@ class AttributesDelegate {
1137
1153
  setMainViewSize(size2) {
1138
1154
  this.context.safeSetAttributes({ ["mainViewSize"]: __spreadValues({}, size2) });
1139
1155
  }
1156
+ setMainViewCameraAndSize(camera, size2) {
1157
+ this.context.safeSetAttributes({
1158
+ ["mainViewCamera"]: __spreadValues({}, camera),
1159
+ ["mainViewSize"]: __spreadValues({}, size2)
1160
+ });
1161
+ }
1140
1162
  updateCursor(uid, position) {
1141
1163
  if (!get(this.attributes, ["cursors"])) {
1142
1164
  this.context.safeUpdateAttributes(["cursors"], {});
@@ -1595,15 +1617,26 @@ class MainViewProxy {
1595
1617
  this.mainViewIsAddListener = false;
1596
1618
  this.store = this.manager.store;
1597
1619
  this.sideEffectManager = new SideEffectManager();
1620
+ this.startListenWritableChange = () => {
1621
+ this.sideEffectManager.add(() => {
1622
+ return emitter.on("writableChange", (isWritable) => {
1623
+ if (isWritable) {
1624
+ this.ensureCameraAndSize();
1625
+ }
1626
+ });
1627
+ });
1628
+ };
1629
+ this.addCameraReaction = () => {
1630
+ var _a;
1631
+ (_a = this.manager.refresher) == null ? void 0 : _a.add(Fields.MainViewCamera, this.cameraReaction);
1632
+ };
1598
1633
  this.cameraReaction = () => {
1599
1634
  return reaction(() => this.mainViewCamera, (camera) => {
1600
1635
  if (camera && camera.id !== this.manager.uid) {
1601
1636
  this.moveCameraToContian(this.mainViewSize);
1602
1637
  this.moveCamera(camera);
1603
1638
  }
1604
- }, {
1605
- fireImmediately: true
1606
- });
1639
+ }, { fireImmediately: true });
1607
1640
  };
1608
1641
  this.sizeChangeHandler = debounce((size2) => {
1609
1642
  if (size2) {
@@ -1629,13 +1662,10 @@ class MainViewProxy {
1629
1662
  this.mainView = this.createMainView();
1630
1663
  this.moveCameraSizeByAttributes();
1631
1664
  emitter.once("mainViewMounted").then(() => {
1632
- setTimeout(() => {
1633
- this.addMainViewListener();
1634
- this.start();
1635
- if (!this.mainViewCamera || !this.mainViewSize) {
1636
- this.setCameraAndSize();
1637
- }
1638
- }, 200);
1665
+ this.addMainViewListener();
1666
+ this.start();
1667
+ this.ensureCameraAndSize();
1668
+ this.startListenWritableChange();
1639
1669
  });
1640
1670
  const playgroundSizeChangeListener = () => {
1641
1671
  this.sizeChangeHandler(this.mainViewSize);
@@ -1645,6 +1675,12 @@ class MainViewProxy {
1645
1675
  return () => emitter.off("playgroundSizeChange", playgroundSizeChangeListener);
1646
1676
  });
1647
1677
  }
1678
+ ensureCameraAndSize() {
1679
+ if (!this.mainViewCamera || !this.mainViewSize) {
1680
+ this.manager.dispatchInternalEvent(Events.InitMainViewCamera);
1681
+ this.setCameraAndSize();
1682
+ }
1683
+ }
1648
1684
  get mainViewCamera() {
1649
1685
  return this.store.getMainViewCamera();
1650
1686
  }
@@ -1656,17 +1692,17 @@ class MainViewProxy {
1656
1692
  this.moveCamera(this.mainViewCamera);
1657
1693
  }
1658
1694
  start() {
1659
- var _a;
1660
1695
  if (this.started)
1661
1696
  return;
1662
1697
  this.sizeChangeHandler(this.mainViewSize);
1663
1698
  this.addCameraListener();
1664
- (_a = this.manager.refresher) == null ? void 0 : _a.add(Fields.MainViewCamera, this.cameraReaction);
1699
+ this.addCameraReaction();
1665
1700
  this.started = true;
1666
1701
  }
1667
1702
  setCameraAndSize() {
1668
- this.store.setMainViewCamera(__spreadProps(__spreadValues({}, this.mainView.camera), { id: this.manager.uid }));
1669
- this.store.setMainViewSize(__spreadProps(__spreadValues({}, this.mainView.size), { id: this.manager.uid }));
1703
+ const camera = __spreadProps(__spreadValues({}, this.mainView.camera), { id: this.manager.uid });
1704
+ const size2 = __spreadProps(__spreadValues({}, this.mainView.size), { id: this.manager.uid });
1705
+ this.store.setMainViewCameraAndSize(camera, size2);
1670
1706
  }
1671
1707
  get view() {
1672
1708
  return this.mainView;
@@ -1916,6 +1952,22 @@ class AppManager {
1916
1952
  };
1917
1953
  callbacks$1.emit("sceneStateChange", this.sceneState);
1918
1954
  };
1955
+ this.addAppsChangeListener = () => {
1956
+ var _a;
1957
+ (_a = this.refresher) == null ? void 0 : _a.add("apps", () => {
1958
+ return safeListenPropsUpdated(() => this.attributes.apps, () => {
1959
+ this.attributesUpdateCallback(this.attributes.apps);
1960
+ });
1961
+ });
1962
+ };
1963
+ this.addAppCloseListener = () => {
1964
+ var _a;
1965
+ (_a = this.refresher) == null ? void 0 : _a.add("appsClose", () => {
1966
+ return onObjectRemoved(this.attributes.apps, () => {
1967
+ this.onAppDelete(this.attributes.apps);
1968
+ });
1969
+ });
1970
+ };
1919
1971
  this.onMainViewIndexChange = (index) => {
1920
1972
  if (index !== void 0 && this._prevSceneIndex !== index) {
1921
1973
  callbacks$1.emit("mainViewSceneIndexChange", index);
@@ -1943,6 +1995,7 @@ class AppManager {
1943
1995
  }
1944
1996
  }
1945
1997
  };
1998
+ this.attributesUpdateCallback = debounce((apps) => this._attributesUpdateCallback(apps), 100);
1946
1999
  this.onRegisteredChange = (registered) => {
1947
2000
  if (!registered)
1948
2001
  return;
@@ -2017,6 +2070,7 @@ class AppManager {
2017
2070
  } else {
2018
2071
  this.mainView.disableCameraTransform = true;
2019
2072
  }
2073
+ emitter.emit("writableChange", isWritable);
2020
2074
  };
2021
2075
  this.updateSceneIndex = () => {
2022
2076
  const scenePath = this.store.getMainViewScenePath();
@@ -2153,46 +2207,38 @@ class AppManager {
2153
2207
  }
2154
2208
  }
2155
2209
  async onCreated() {
2156
- var _a, _b, _c, _d, _e2, _f, _g, _h;
2210
+ var _a, _b, _c, _d, _e2, _f;
2157
2211
  await this.attributesUpdateCallback(this.attributes.apps);
2158
2212
  emitter.emit("updateManagerRect");
2159
2213
  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", () => {
2214
+ this.addAppsChangeListener();
2215
+ this.addAppCloseListener();
2216
+ (_a = this.refresher) == null ? void 0 : _a.add("maximized", () => {
2171
2217
  return autorun(() => {
2172
2218
  var _a2;
2173
2219
  const maximized = this.attributes.maximized;
2174
2220
  (_a2 = this.boxManager) == null ? void 0 : _a2.setMaximized(Boolean(maximized));
2175
2221
  });
2176
2222
  });
2177
- (_d = this.refresher) == null ? void 0 : _d.add("minimized", () => {
2223
+ (_b = this.refresher) == null ? void 0 : _b.add("minimized", () => {
2178
2224
  return autorun(() => {
2179
2225
  const minimized = this.attributes.minimized;
2180
2226
  this.onMinimized(minimized);
2181
2227
  });
2182
2228
  });
2183
- (_e2 = this.refresher) == null ? void 0 : _e2.add("mainViewIndex", () => {
2229
+ (_c = this.refresher) == null ? void 0 : _c.add("mainViewIndex", () => {
2184
2230
  return autorun(() => {
2185
2231
  const mainSceneIndex = get(this.attributes, "_mainSceneIndex");
2186
2232
  this.onMainViewIndexChange(mainSceneIndex);
2187
2233
  });
2188
2234
  });
2189
- (_f = this.refresher) == null ? void 0 : _f.add("focusedChange", () => {
2235
+ (_d = this.refresher) == null ? void 0 : _d.add("focusedChange", () => {
2190
2236
  return autorun(() => {
2191
2237
  const focused = get(this.attributes, "focus");
2192
2238
  this.onFocusChange(focused);
2193
2239
  });
2194
2240
  });
2195
- (_g = this.refresher) == null ? void 0 : _g.add("registeredChange", () => {
2241
+ (_e2 = this.refresher) == null ? void 0 : _e2.add("registeredChange", () => {
2196
2242
  return autorun(() => {
2197
2243
  const registered = get(this.attributes, Fields.Registered);
2198
2244
  this.onRegisteredChange(registered);
@@ -2204,7 +2250,7 @@ class AppManager {
2204
2250
  return;
2205
2251
  this.resetScenePath(mainScenePath);
2206
2252
  }
2207
- this.displayerWritableListener(!((_h = this.room) == null ? void 0 : _h.isWritable));
2253
+ this.displayerWritableListener(!((_f = this.room) == null ? void 0 : _f.isWritable));
2208
2254
  this.displayer.callbacks.on("onEnableWriteNowChanged", this.displayerWritableListener);
2209
2255
  this._prevFocused = this.attributes.focus;
2210
2256
  this.sideEffectManager.add(() => {
@@ -2216,7 +2262,7 @@ class AppManager {
2216
2262
  return () => redoUndo.destroy();
2217
2263
  });
2218
2264
  }
2219
- async attributesUpdateCallback(apps) {
2265
+ async _attributesUpdateCallback(apps) {
2220
2266
  if (apps && WindowManager.container) {
2221
2267
  const appIds = Object.keys(apps);
2222
2268
  if (appIds.length === 0) {
@@ -5517,6 +5563,9 @@ class ReconnectRefresher {
5517
5563
  this.phase = phase;
5518
5564
  };
5519
5565
  this.onReconnected = debounce(() => {
5566
+ this._onReconnected();
5567
+ }, 3e3);
5568
+ this._onReconnected = () => {
5520
5569
  log("onReconnected refresh reactors");
5521
5570
  this.releaseDisposers();
5522
5571
  this.reactors.forEach((func, id2) => {
@@ -5525,7 +5574,7 @@ class ReconnectRefresher {
5525
5574
  }
5526
5575
  });
5527
5576
  this.ctx.emitter.emit("onReconnected", void 0);
5528
- }, 3e3);
5577
+ };
5529
5578
  }
5530
5579
  setRoom(room) {
5531
5580
  this.room = room;
@@ -5544,7 +5593,14 @@ class ReconnectRefresher {
5544
5593
  });
5545
5594
  this.disposers.clear();
5546
5595
  }
5596
+ refresh() {
5597
+ this._onReconnected();
5598
+ }
5547
5599
  add(id2, func) {
5600
+ const disposer = this.disposers.get(id2);
5601
+ if (disposer && isFunction(disposer)) {
5602
+ disposer();
5603
+ }
5548
5604
  if (isFunction(func)) {
5549
5605
  this.reactors.set(id2, func);
5550
5606
  this.disposers.set(id2, func());
@@ -14812,7 +14868,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
14812
14868
  const _WindowManager = class extends InvisiblePlugin {
14813
14869
  constructor(context) {
14814
14870
  super(context);
14815
- this.version = "0.4.20";
14871
+ this.version = "0.4.23";
14816
14872
  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
14873
  this.emitter = callbacks$1;
14818
14874
  this.viewMode = ViewMode.Broadcaster;
@@ -14937,6 +14993,9 @@ const _WindowManager = class extends InvisiblePlugin {
14937
14993
  if (_WindowManager.params) {
14938
14994
  const params = _WindowManager.params;
14939
14995
  const mainViewElement = _WindowManager.initContainer(this, container, params.chessboard, params.overwriteStyles);
14996
+ if (this.boxManager) {
14997
+ this.boxManager.destroy();
14998
+ }
14940
14999
  const boxManager = createBoxManager(this, callbacks$1, emitter, {
14941
15000
  collectorContainer: params.collectorContainer,
14942
15001
  collectorStyles: params.collectorStyles,
@@ -15402,6 +15461,19 @@ const _WindowManager = class extends InvisiblePlugin {
15402
15461
  var _a;
15403
15462
  return (_a = this.focusedView) == null ? void 0 : _a.lockImages(locked);
15404
15463
  }
15464
+ refresh() {
15465
+ var _a;
15466
+ this._refresh();
15467
+ (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.Refresh);
15468
+ }
15469
+ _refresh() {
15470
+ var _a, _b, _c;
15471
+ (_a = this.appManager) == null ? void 0 : _a.mainViewProxy.rebind();
15472
+ if (_WindowManager.container) {
15473
+ this.bindContainer(_WindowManager.container);
15474
+ }
15475
+ (_c = (_b = this.appManager) == null ? void 0 : _b.refresher) == null ? void 0 : _c.refresh();
15476
+ }
15405
15477
  isDynamicPPT(scenes) {
15406
15478
  var _a, _b;
15407
15479
  const sceneSrc = (_b = (_a = scenes[0]) == null ? void 0 : _a.ppt) == null ? void 0 : _b.src;