@netless/forge-whiteboard 1.0.7 → 1.1.0-beta.1

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.
@@ -27733,11 +27733,17 @@ var ImageModel = class extends ElementModel {
27733
27733
  }
27734
27734
  styleKeys() {
27735
27735
  return {
27736
- include: [],
27736
+ include: ["src"],
27737
27737
  exclude: ["dashArray", "strokeColor", "fillColor", "strokeWidth"]
27738
27738
  };
27739
27739
  }
27740
- onStyleKeyUpdate(_key) {
27740
+ onStyleKeyUpdate(key) {
27741
+ if (key === "src") {
27742
+ const imgElement = this.imageSets.querySelector(`[id='${this.uuid}']`);
27743
+ if (imgElement) {
27744
+ imgElement.src = this.src;
27745
+ }
27746
+ }
27741
27747
  }
27742
27748
  editorConfig() {
27743
27749
  const cfg = new EditorConfig();
@@ -28839,6 +28845,9 @@ var SelectElementsModel = class extends import_eventemitter33.default {
28839
28845
  _defineProperty23(this, "hasPermission", void 0);
28840
28846
  _defineProperty23(this, "observers", /* @__PURE__ */ new Map());
28841
28847
  _defineProperty23(this, "handleUserLeave", (user) => {
28848
+ if (user.id === this.userManager.selfId) {
28849
+ return;
28850
+ }
28842
28851
  const cb = this.observers.get(user.id);
28843
28852
  if (cb) {
28844
28853
  (0, import_forge_room6.removeDeepObserver)(this.requestUserMap(user.id), cb);
@@ -28851,6 +28860,7 @@ var SelectElementsModel = class extends import_eventemitter33.default {
28851
28860
  };
28852
28861
  if (this.observers.has(user.id)) {
28853
28862
  (0, import_forge_room6.removeDeepObserver)(this.requestUserMap(user.id), this.observers.get(user.id));
28863
+ this.observers.delete(user.id);
28854
28864
  }
28855
28865
  this.requestUserMap(user.id).observeDeep(observer);
28856
28866
  this.observers.set(user.id, observer);
@@ -29923,18 +29933,25 @@ var Camera = class extends import_eventemitter37.default {
29923
29933
  }
29924
29934
  });
29925
29935
  _defineProperty28(this, "handleUserLeave", (user) => {
29936
+ if (user.id === this.userManager.selfId) {
29937
+ return;
29938
+ }
29926
29939
  const cb = this.observers.get(user.id);
29927
29940
  if (cb) {
29928
29941
  (0, import_forge_room7.removeObserver)(this.requestUserMap(user.id), cb);
29929
29942
  }
29930
29943
  });
29931
29944
  _defineProperty28(this, "handleUserJoin", (user) => {
29945
+ if (this.observers.has(user.id)) {
29946
+ const cb = this.observers.get(user.id);
29947
+ if (cb) {
29948
+ (0, import_forge_room7.removeObserver)(this.requestUserMap(user.id), cb);
29949
+ this.observers.delete(user.id);
29950
+ }
29951
+ }
29932
29952
  const observer = (evt) => {
29933
29953
  this.handleViewMatrixUpdate(user.id, evt);
29934
29954
  };
29935
- if (this.observers.has(user.id)) {
29936
- (0, import_forge_room7.removeObserver)(this.requestUserMap(user.id), observer);
29937
- }
29938
29955
  this.requestUserMap(user.id).observe(observer);
29939
29956
  this.observers.set(user.id, observer);
29940
29957
  });
@@ -30563,12 +30580,22 @@ var TrashedElementsModel = class extends import_eventemitter39.default {
30563
30580
  _defineProperty33(this, "hasPermission", void 0);
30564
30581
  _defineProperty33(this, "observers", /* @__PURE__ */ new Map());
30565
30582
  _defineProperty33(this, "handleUserLeave", (user) => {
30583
+ if (user.id === this.userManager.selfId) {
30584
+ return;
30585
+ }
30566
30586
  const cb = this.observers.get(user.id);
30567
30587
  if (cb) {
30568
30588
  (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(user.id), cb);
30569
30589
  }
30570
30590
  });
30571
30591
  _defineProperty33(this, "handleUserJoin", (user) => {
30592
+ if (this.observers.has(user.id)) {
30593
+ const cb = this.observers.get(user.id);
30594
+ if (cb) {
30595
+ (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(user.id), cb);
30596
+ this.observers.delete(user.id);
30597
+ }
30598
+ }
30572
30599
  const observer = (evts) => {
30573
30600
  this.handleUserTrashElementsChange(user.id, evts);
30574
30601
  };
@@ -30741,6 +30768,9 @@ var PageModel = class extends import_eventemitter310.default {
30741
30768
  _defineProperty35(this, "observers", /* @__PURE__ */ new Map());
30742
30769
  _defineProperty35(this, "hasPermission", void 0);
30743
30770
  _defineProperty35(this, "handleUserLeave", (user) => {
30771
+ if (this.userManager.selfId === user.id) {
30772
+ return;
30773
+ }
30744
30774
  const cb = this.observers.get(user.id);
30745
30775
  if (cb) {
30746
30776
  (0, import_forge_room9.removeObserver)(this.requestUserMap(user.id), cb);
@@ -30792,7 +30822,7 @@ var PageModel = class extends import_eventemitter310.default {
30792
30822
  this.userManager = userManager;
30793
30823
  this.requestUserMap = requestUserMap;
30794
30824
  this.whiteboardAttrsMap = whiteboardAttrsMap;
30795
- this.userManager.userIdList().forEach((userId) => {
30825
+ new Set(this.userManager.userIdList().concat(this.userManager.selfId)).forEach((userId) => {
30796
30826
  this.createCurrentPageObserver(userId);
30797
30827
  });
30798
30828
  this.userManager.on("join", this.handleUserJoin);
@@ -30801,6 +30831,13 @@ var PageModel = class extends import_eventemitter310.default {
30801
30831
  this.pageMap.observe(this.handlePageMapChange);
30802
30832
  }
30803
30833
  createCurrentPageObserver(userId) {
30834
+ if (this.observers.has(userId)) {
30835
+ const cb = this.observers.get(userId);
30836
+ if (cb) {
30837
+ (0, import_forge_room9.removeObserver)(this.requestUserMap(userId), cb);
30838
+ this.observers.delete(userId);
30839
+ }
30840
+ }
30804
30841
  const observer = (evt) => {
30805
30842
  this.handleUserCurrentPageChange(userId, evt);
30806
30843
  };
@@ -30836,7 +30873,8 @@ var PageModel = class extends import_eventemitter310.default {
30836
30873
  return true;
30837
30874
  }
30838
30875
  addPage(id) {
30839
- if (!this.modifyDetect(id)) {
30876
+ let focus = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
30877
+ if (!focus && !this.modifyDetect(id)) {
30840
30878
  return false;
30841
30879
  }
30842
30880
  if (this.pageMap.has(id)) {
@@ -31703,6 +31741,11 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
31703
31741
  _defineProperty43(this, "enableToolEvent", () => {
31704
31742
  return !(this.inputType === "pen" && !this.isPenEvent);
31705
31743
  });
31744
+ _defineProperty43(this, "handleWritableChanged", (userId, writable) => {
31745
+ if (userId === this.userId && writable && this.linkWhiteboardId) {
31746
+ this.linkToWhiteboard(this.linkWhiteboardId);
31747
+ }
31748
+ });
31706
31749
  _defineProperty43(this, "handleViewportUpdate", (evt) => {
31707
31750
  if (evt.keysChanged.has("viewportWidth") || evt.keysChanged.has("viewportHeight")) {
31708
31751
  const rect = this.rootElement.getBoundingClientRect();
@@ -32139,6 +32182,9 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32139
32182
  }
32140
32183
  };
32141
32184
  this.emitter.clearPage = () => {
32185
+ if (!this.writableManager().isWritable()) {
32186
+ return;
32187
+ }
32142
32188
  this.getCurrentRendererModel().then((model) => {
32143
32189
  if (model) {
32144
32190
  if (model.elements.doc) {
@@ -32152,9 +32198,15 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32152
32198
  });
32153
32199
  };
32154
32200
  this.emitter.undo = () => {
32201
+ if (!this.writableManager().isWritable()) {
32202
+ return;
32203
+ }
32155
32204
  this.undoManager?.undo();
32156
32205
  };
32157
32206
  this.emitter.redo = () => {
32207
+ if (!this.writableManager().isWritable()) {
32208
+ return;
32209
+ }
32158
32210
  this.undoManager?.redo();
32159
32211
  };
32160
32212
  this.emitter.rasterizeViewport = (scale, page) => {
@@ -32296,6 +32348,10 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32296
32348
  });
32297
32349
  window.addEventListener("forge-whiteboard-synced-status", this.addWhiteboardStatus);
32298
32350
  }
32351
+ addPage(id) {
32352
+ let focus = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
32353
+ return this.pageModel.addPage(id, focus);
32354
+ }
32299
32355
  userMap(userId) {
32300
32356
  return this.getMap(`user/${userId}`);
32301
32357
  }
@@ -32303,7 +32359,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32303
32359
  _WhiteboardApplication.instanceCount.set(this.appId, (_WhiteboardApplication.instanceCount.get(this.appId) ?? 0) + 1);
32304
32360
  (0, import_forge_room12.log)(`whiteboard ${this.appId} initialize. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
32305
32361
  this.appDoc.transact(() => {
32306
- this.permissions = new WhiteboardPermissions(this.userManager, (userId) => {
32362
+ this.permissions = new WhiteboardPermissions(this.writableManager, this.userManager, (userId) => {
32307
32363
  return this.userMap(userId);
32308
32364
  });
32309
32365
  this.permissions.setPermission(WhiteboardPermissionFlag.all);
@@ -32499,6 +32555,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32499
32555
  }
32500
32556
  this.rootElement.appendChild(this.liveCursor.container);
32501
32557
  this.getMap("attrs").observe(this.handleViewportUpdate);
32558
+ this.writableManager().on("writableChanged", this.handleWritableChanged);
32502
32559
  }, "whiteboard-initialize");
32503
32560
  }
32504
32561
  clearElements() {