@veltdev/react 3.0.37 → 3.0.38

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.
@@ -1,3 +1,3 @@
1
- export declare const VELT_SDK_VERSION = "3.0.37";
1
+ export declare const VELT_SDK_VERSION = "3.0.38";
2
2
  export declare const VELT_SDK_INIT_EVENT = "onVeltInit";
3
3
  export declare const VELT_TAB_ID = "veltTabId";
@@ -1,3 +1,3 @@
1
- import { ContactElement, UserContactSelectedPayload } from "@veltdev/types";
1
+ import { ContactElement, SelectedUserContact } from "@veltdev/types";
2
2
  export declare function useContactUtils(): ContactElement | undefined;
3
- export declare function useContactSelected(): UserContactSelectedPayload | undefined;
3
+ export declare function useContactSelected(): SelectedUserContact | undefined;
package/esm/index.js CHANGED
@@ -132,7 +132,7 @@ var loadVelt = function (callback, version, staging, develop, proxyDomain) {
132
132
  }
133
133
  };
134
134
 
135
- var VELT_SDK_VERSION = '3.0.37';
135
+ var VELT_SDK_VERSION = '3.0.38';
136
136
  var VELT_SDK_INIT_EVENT = 'onVeltInit';
137
137
  var VELT_TAB_ID = 'veltTabId';
138
138
 
@@ -3418,21 +3418,40 @@ function useClient() {
3418
3418
  }
3419
3419
  function useIdentify(user, userOptions) {
3420
3420
  var client = useVeltClient().client;
3421
+ // Memoize the identify call
3422
+ var shouldIdentify = React.useMemo(function () {
3423
+ return { user: user, userOptions: userOptions };
3424
+ }, [JSON.stringify(user), JSON.stringify(userOptions)]);
3421
3425
  React.useEffect(function () {
3422
- client && client.identify(user, userOptions);
3423
- }, [client]);
3426
+ if (client) {
3427
+ client.identify(shouldIdentify.user, shouldIdentify.userOptions);
3428
+ }
3429
+ }, [client, shouldIdentify]);
3424
3430
  }
3425
3431
  function useSetDocument(documentId, documentMetadata) {
3426
3432
  var client = useVeltClient().client;
3433
+ // Memoize the setDocument call
3434
+ var shouldSetDocument = React.useMemo(function () {
3435
+ return {
3436
+ documentId: documentId,
3437
+ documentMetadata: documentMetadata
3438
+ };
3439
+ }, [documentId, JSON.stringify(documentMetadata)]);
3427
3440
  React.useEffect(function () {
3428
- client && client.setDocument(documentId, documentMetadata);
3429
- }, [client]);
3441
+ if (client) {
3442
+ client.setDocument(shouldSetDocument.documentId, shouldSetDocument.documentMetadata);
3443
+ }
3444
+ }, [client, shouldSetDocument]);
3430
3445
  }
3431
3446
  function useSetDocumentId(documentId) {
3432
3447
  var client = useVeltClient().client;
3448
+ // Memoize the documentId
3449
+ var memoizedDocumentId = React.useMemo(function () { return documentId; }, [documentId]);
3433
3450
  React.useEffect(function () {
3434
- client && client.setDocumentId(documentId);
3435
- }, [client]);
3451
+ if (client) {
3452
+ client.setDocumentId(memoizedDocumentId);
3453
+ }
3454
+ }, [client, memoizedDocumentId]);
3436
3455
  }
3437
3456
  function useUnsetDocumentId() {
3438
3457
  var client = useVeltClient().client;
@@ -3442,9 +3461,15 @@ function useUnsetDocumentId() {
3442
3461
  }
3443
3462
  function useSetLocation(location, appendLocation) {
3444
3463
  var client = useVeltClient().client;
3464
+ // Memoize the setLocation call
3465
+ var shouldSetLocation = React.useMemo(function () {
3466
+ return { location: location, appendLocation: appendLocation };
3467
+ }, [JSON.stringify(location), appendLocation]);
3445
3468
  React.useEffect(function () {
3446
- client && client.setLocation(location, appendLocation);
3447
- }, [client]);
3469
+ if (client) {
3470
+ client.setLocation(shouldSetLocation.location, shouldSetLocation.appendLocation);
3471
+ }
3472
+ }, [client, shouldSetLocation]);
3448
3473
  }
3449
3474
  function useVeltInitState() {
3450
3475
  var client = useVeltClient().client;
@@ -3476,31 +3501,59 @@ function useCommentUtils() {
3476
3501
  function useCommentAnnotations(documentId, location) {
3477
3502
  var commentElement = useCommentUtils();
3478
3503
  var _a = React.useState(undefined), data = _a[0], setData = _a[1];
3504
+ var subscriptionRef = React.useRef();
3505
+ // Memoize the inputs
3506
+ var inputs = React.useMemo(function () {
3507
+ return { documentId: documentId, location: location };
3508
+ }, [documentId, JSON.stringify(location)]);
3479
3509
  useEffect(function () {
3480
3510
  if (!(commentElement === null || commentElement === void 0 ? void 0 : commentElement.getAllCommentAnnotations))
3481
3511
  return;
3482
- var subscription = commentElement.getAllCommentAnnotations(documentId, location).subscribe(function (res) {
3512
+ // Unsubscribe from the previous subscription if it exists
3513
+ if (subscriptionRef.current) {
3514
+ subscriptionRef.current.unsubscribe();
3515
+ }
3516
+ var subscription = commentElement.getAllCommentAnnotations(inputs.documentId, inputs.location)
3517
+ .subscribe(function (res) {
3483
3518
  setData(res);
3484
3519
  });
3520
+ // Store the new subscription
3521
+ subscriptionRef.current = subscription;
3522
+ // Cleanup function
3485
3523
  return function () {
3486
- subscription.unsubscribe();
3524
+ if (subscriptionRef.current) {
3525
+ subscriptionRef.current.unsubscribe();
3526
+ }
3487
3527
  };
3488
- }, [commentElement === null || commentElement === void 0 ? void 0 : commentElement.getAllCommentAnnotations]);
3528
+ }, [commentElement === null || commentElement === void 0 ? void 0 : commentElement.getAllCommentAnnotations, inputs]);
3489
3529
  return data;
3490
3530
  }
3491
3531
  function useUnreadCommentCountByAnnotationId(annotationId) {
3492
3532
  var commentElement = useCommentUtils();
3493
3533
  var _a = React.useState({ count: 0 }), data = _a[0], setData = _a[1];
3534
+ var subscriptionRef = React.useRef();
3535
+ // Memoize the input
3536
+ var memoizedAnnotationId = React.useMemo(function () { return annotationId; }, [annotationId]);
3494
3537
  useEffect(function () {
3495
3538
  if (!(commentElement === null || commentElement === void 0 ? void 0 : commentElement.getUnreadCommentCountByAnnotationId))
3496
3539
  return;
3497
- var subscription = commentElement.getUnreadCommentCountByAnnotationId(annotationId).subscribe(function (res) {
3540
+ // Unsubscribe from the previous subscription if it exists
3541
+ if (subscriptionRef.current) {
3542
+ subscriptionRef.current.unsubscribe();
3543
+ }
3544
+ var subscription = commentElement.getUnreadCommentCountByAnnotationId(memoizedAnnotationId)
3545
+ .subscribe(function (res) {
3498
3546
  setData(res);
3499
3547
  });
3548
+ // Store the new subscription
3549
+ subscriptionRef.current = subscription;
3550
+ // Cleanup function
3500
3551
  return function () {
3501
- subscription.unsubscribe();
3552
+ if (subscriptionRef.current) {
3553
+ subscriptionRef.current.unsubscribe();
3554
+ }
3502
3555
  };
3503
- }, [commentElement === null || commentElement === void 0 ? void 0 : commentElement.getUnreadCommentCountByAnnotationId]);
3556
+ }, [commentElement === null || commentElement === void 0 ? void 0 : commentElement.getUnreadCommentCountByAnnotationId, memoizedAnnotationId]);
3504
3557
  return data;
3505
3558
  }
3506
3559
  function useUnreadCommentAnnotationCountOnCurrentDocument() {
@@ -3536,31 +3589,57 @@ function useUnreadCommentCountOnCurrentDocument() {
3536
3589
  function useUnreadCommentCountByLocationId(locationId) {
3537
3590
  var commentElement = useCommentUtils();
3538
3591
  var _a = React.useState({ count: 0 }), data = _a[0], setData = _a[1];
3592
+ var subscriptionRef = React.useRef();
3593
+ // Memoize the input
3594
+ var memoizedLocationId = React.useMemo(function () { return locationId; }, [locationId]);
3539
3595
  useEffect(function () {
3540
3596
  if (!(commentElement === null || commentElement === void 0 ? void 0 : commentElement.getUnreadCommentCountByLocationId))
3541
3597
  return;
3542
- var subscription = commentElement.getUnreadCommentCountByLocationId(locationId).subscribe(function (res) {
3598
+ // Unsubscribe from the previous subscription if it exists
3599
+ if (subscriptionRef.current) {
3600
+ subscriptionRef.current.unsubscribe();
3601
+ }
3602
+ var subscription = commentElement.getUnreadCommentCountByLocationId(memoizedLocationId)
3603
+ .subscribe(function (res) {
3543
3604
  setData(res);
3544
3605
  });
3606
+ // Store the new subscription
3607
+ subscriptionRef.current = subscription;
3608
+ // Cleanup function
3545
3609
  return function () {
3546
- subscription.unsubscribe();
3610
+ if (subscriptionRef.current) {
3611
+ subscriptionRef.current.unsubscribe();
3612
+ }
3547
3613
  };
3548
- }, [commentElement === null || commentElement === void 0 ? void 0 : commentElement.getUnreadCommentCountByLocationId]);
3614
+ }, [commentElement === null || commentElement === void 0 ? void 0 : commentElement.getUnreadCommentCountByLocationId, memoizedLocationId]);
3549
3615
  return data;
3550
3616
  }
3551
3617
  function useUnreadCommentAnnotationCountByLocationId(locationId) {
3552
3618
  var commentElement = useCommentUtils();
3553
3619
  var _a = React.useState({ count: 0 }), data = _a[0], setData = _a[1];
3620
+ var subscriptionRef = React.useRef();
3621
+ // Memoize the input
3622
+ var memoizedLocationId = React.useMemo(function () { return locationId; }, [locationId]);
3554
3623
  useEffect(function () {
3555
3624
  if (!(commentElement === null || commentElement === void 0 ? void 0 : commentElement.getUnreadCommentAnnotationCountByLocationId))
3556
3625
  return;
3557
- var subscription = commentElement.getUnreadCommentAnnotationCountByLocationId(locationId).subscribe(function (res) {
3626
+ // Unsubscribe from the previous subscription if it exists
3627
+ if (subscriptionRef.current) {
3628
+ subscriptionRef.current.unsubscribe();
3629
+ }
3630
+ var subscription = commentElement.getUnreadCommentAnnotationCountByLocationId(memoizedLocationId)
3631
+ .subscribe(function (res) {
3558
3632
  setData(res);
3559
3633
  });
3634
+ // Store the new subscription
3635
+ subscriptionRef.current = subscription;
3636
+ // Cleanup function
3560
3637
  return function () {
3561
- subscription.unsubscribe();
3638
+ if (subscriptionRef.current) {
3639
+ subscriptionRef.current.unsubscribe();
3640
+ }
3562
3641
  };
3563
- }, [commentElement === null || commentElement === void 0 ? void 0 : commentElement.getUnreadCommentAnnotationCountByLocationId]);
3642
+ }, [commentElement === null || commentElement === void 0 ? void 0 : commentElement.getUnreadCommentAnnotationCountByLocationId, memoizedLocationId]);
3564
3643
  return data;
3565
3644
  }
3566
3645
  function useCommentModeState() {
@@ -3658,16 +3737,29 @@ function useCommentCopyLinkHandler() {
3658
3737
  function useCommentAnnotationById(config) {
3659
3738
  var commentElement = useCommentUtils();
3660
3739
  var _a = React.useState(undefined), data = _a[0], setData = _a[1];
3740
+ var subscriptionRef = React.useRef();
3741
+ // Memoize the input
3742
+ var memoizedConfig = React.useMemo(function () { return config; }, [config.annotationId, config.documentId]);
3661
3743
  useEffect(function () {
3662
3744
  if (!(commentElement === null || commentElement === void 0 ? void 0 : commentElement.getCommentAnnotationById))
3663
3745
  return;
3664
- var subscription = commentElement.getCommentAnnotationById(config).subscribe(function (res) {
3746
+ // Unsubscribe from the previous subscription if it exists
3747
+ if (subscriptionRef.current) {
3748
+ subscriptionRef.current.unsubscribe();
3749
+ }
3750
+ var subscription = commentElement.getCommentAnnotationById(memoizedConfig)
3751
+ .subscribe(function (res) {
3665
3752
  setData(res);
3666
3753
  });
3754
+ // Store the new subscription
3755
+ subscriptionRef.current = subscription;
3756
+ // Cleanup function
3667
3757
  return function () {
3668
- subscription.unsubscribe();
3758
+ if (subscriptionRef.current) {
3759
+ subscriptionRef.current.unsubscribe();
3760
+ }
3669
3761
  };
3670
- }, [commentElement === null || commentElement === void 0 ? void 0 : commentElement.getCommentAnnotationById]);
3762
+ }, [commentElement === null || commentElement === void 0 ? void 0 : commentElement.getCommentAnnotationById, memoizedConfig]);
3671
3763
  return data;
3672
3764
  }
3673
3765
  function useCommentSidebarActionButtonClick() {