@tldraw/editor 3.13.0-canary.3095a57e7c2c → 3.13.0-canary.42efa4c14663

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.
@@ -1844,6 +1844,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1844
1844
  * @public
1845
1845
  */
1846
1846
  getCamera(): TLCamera;
1847
+ private _getFollowingPresence;
1847
1848
  private getViewportPageBoundsForFollowing;
1848
1849
  private getCameraForFollowing;
1849
1850
  /**
package/dist-cjs/index.js CHANGED
@@ -376,7 +376,7 @@ function debugEnableLicensing() {
376
376
  }
377
377
  (0, import_utils.registerTldrawLibraryVersion)(
378
378
  "@tldraw/editor",
379
- "3.13.0-canary.3095a57e7c2c",
379
+ "3.13.0-canary.42efa4c14663",
380
380
  "cjs"
381
381
  );
382
382
  //# sourceMappingURL=index.js.map
@@ -1950,12 +1950,22 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
1950
1950
  }
1951
1951
  return baseCamera;
1952
1952
  }
1953
+ _getFollowingPresence(targetUserId) {
1954
+ const visited = [this.user.getId()];
1955
+ const collaborators = this.getCollaborators();
1956
+ let leaderPresence = null;
1957
+ while (targetUserId && !visited.includes(targetUserId)) {
1958
+ leaderPresence = collaborators.find((c) => c.userId === targetUserId) ?? null;
1959
+ targetUserId = leaderPresence?.followingUserId ?? null;
1960
+ if (leaderPresence) {
1961
+ visited.push(leaderPresence.userId);
1962
+ }
1963
+ }
1964
+ return leaderPresence;
1965
+ }
1953
1966
  getViewportPageBoundsForFollowing() {
1954
- const followingUserId = this.getInstanceState().followingUserId;
1955
- if (!followingUserId) return null;
1956
- const leaderPresence = this.getCollaborators().find((c) => c.userId === followingUserId);
1957
- if (!leaderPresence) return null;
1958
- if (!leaderPresence.camera || !leaderPresence.screenBounds) return null;
1967
+ const leaderPresence = this._getFollowingPresence(this.getInstanceState().followingUserId);
1968
+ if (!leaderPresence?.camera || !leaderPresence?.screenBounds) return null;
1959
1969
  const { w: lw, h: lh } = leaderPresence.screenBounds;
1960
1970
  const { x: lx, y: ly, z: lz } = leaderPresence.camera;
1961
1971
  const theirViewport = new import_Box.Box(-lx, -ly, lw / lz, lh / lz);
@@ -2862,34 +2872,30 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
2862
2872
  */
2863
2873
  startFollowingUser(userId) {
2864
2874
  this.stopFollowingUser();
2865
- const leaderPresences = this._getCollaboratorsQuery().get().filter((p) => p.userId === userId);
2866
- if (!leaderPresences.length) {
2867
- console.warn("User not found");
2868
- return this;
2869
- }
2870
2875
  const thisUserId = this.user.getId();
2871
2876
  if (!thisUserId) {
2872
2877
  console.warn("You should set the userId for the current instance before following a user");
2873
2878
  }
2874
- if (leaderPresences.some((p) => p.followingUserId === thisUserId)) {
2879
+ const leaderPresence = this._getFollowingPresence(userId);
2880
+ if (!leaderPresence) {
2875
2881
  return this;
2876
2882
  }
2877
2883
  const latestLeaderPresence = (0, import_state.computed)("latestLeaderPresence", () => {
2878
- return this.getCollaborators().find((p) => p.userId === userId);
2884
+ return this._getFollowingPresence(userId);
2879
2885
  });
2880
2886
  (0, import_state.transact)(() => {
2881
2887
  this.updateInstanceState({ followingUserId: userId }, { history: "ignore" });
2882
2888
  const dispose = (0, import_state.react)("update current page", () => {
2883
- const leaderPresence = latestLeaderPresence.get();
2884
- if (!leaderPresence) {
2889
+ const leaderPresence2 = latestLeaderPresence.get();
2890
+ if (!leaderPresence2) {
2885
2891
  this.stopFollowingUser();
2886
2892
  return;
2887
2893
  }
2888
- if (leaderPresence.currentPageId !== this.getCurrentPageId() && this.getPage(leaderPresence.currentPageId)) {
2894
+ if (leaderPresence2.currentPageId !== this.getCurrentPageId() && this.getPage(leaderPresence2.currentPageId)) {
2889
2895
  this.run(
2890
2896
  () => {
2891
2897
  this.store.put([
2892
- { ...this.getInstanceState(), currentPageId: leaderPresence.currentPageId }
2898
+ { ...this.getInstanceState(), currentPageId: leaderPresence2.currentPageId }
2893
2899
  ]);
2894
2900
  this._isLockedOnFollowingUser.set(true);
2895
2901
  },
@@ -2904,8 +2910,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
2904
2910
  this.off("stop-following", cancel);
2905
2911
  };
2906
2912
  const moveTowardsUser = () => {
2907
- const leaderPresence = latestLeaderPresence.get();
2908
- if (!leaderPresence) {
2913
+ const leaderPresence2 = latestLeaderPresence.get();
2914
+ if (!leaderPresence2) {
2909
2915
  this.stopFollowingUser();
2910
2916
  return;
2911
2917
  }