@atlaskit/editor-synced-block-provider 3.27.0 → 3.27.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.
@@ -542,128 +542,216 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
542
542
  return Promise.resolve(undefined);
543
543
  }
544
544
 
545
+ /**
546
+ * Processes prefetched data and updates the cache.
547
+ * @param prefetchedData - The prefetched data to process
548
+ * @returns {Promise<void>}
549
+ */
550
+ }, {
551
+ key: "processPrefetchedData",
552
+ value: (function () {
553
+ var _processPrefetchedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(prefetchedData) {
554
+ var _this$fetchExperience,
555
+ _this7 = this;
556
+ var prefetchedResolvedData, _this$processFetchedD, hasUnexpectedError, hasExpectedError, _this$fetchExperience2, _this$fetchExperience3, _this$fetchExperience4, _this$fetchExperience5;
557
+ return _regeneratorRuntime.wrap(function _callee2$(_context3) {
558
+ while (1) switch (_context3.prev = _context3.next) {
559
+ case 0:
560
+ if (prefetchedData) {
561
+ _context3.next = 2;
562
+ break;
563
+ }
564
+ return _context3.abrupt("return");
565
+ case 2:
566
+ // start the fetch experience (this should be started much earlier to properly track performance, but better late than never)
567
+ (_this$fetchExperience = this.fetchExperience) === null || _this$fetchExperience === void 0 || _this$fetchExperience.start({});
568
+
569
+ // mark the sync block requests as in fly
570
+ prefetchedData.resourceIds.forEach(function (resourceId) {
571
+ _this7.syncBlockFetchDataRequests.set(resourceId, true);
572
+ });
573
+ _context3.prev = 4;
574
+ _context3.next = 7;
575
+ return prefetchedData.prefetchPromise;
576
+ case 7:
577
+ prefetchedResolvedData = _context3.sent;
578
+ _this$processFetchedD = this.processFetchedData(prefetchedResolvedData), hasUnexpectedError = _this$processFetchedD.hasUnexpectedError, hasExpectedError = _this$processFetchedD.hasExpectedError;
579
+ if (hasUnexpectedError) {
580
+ (_this$fetchExperience2 = this.fetchExperience) === null || _this$fetchExperience2 === void 0 || _this$fetchExperience2.failure({
581
+ reason: 'Unexpected error during prefetch'
582
+ });
583
+ } else if (hasExpectedError) {
584
+ (_this$fetchExperience3 = this.fetchExperience) === null || _this$fetchExperience3 === void 0 || _this$fetchExperience3.abort({
585
+ reason: 'Expected error: NotFound or PermissionDenied during prefetch'
586
+ });
587
+ } else {
588
+ (_this$fetchExperience4 = this.fetchExperience) === null || _this$fetchExperience4 === void 0 || _this$fetchExperience4.success();
589
+ }
590
+ _context3.next = 15;
591
+ break;
592
+ case 12:
593
+ _context3.prev = 12;
594
+ _context3.t0 = _context3["catch"](4);
595
+ (_this$fetchExperience5 = this.fetchExperience) === null || _this$fetchExperience5 === void 0 || _this$fetchExperience5.failure({
596
+ reason: "Prefetch promise rejected: ".concat(_context3.t0.message)
597
+ });
598
+ case 15:
599
+ _context3.prev = 15;
600
+ // Clean up in-flight markers so subsequent fetches (e.g. refreshSubscriptions) are not blocked
601
+ prefetchedData.resourceIds.forEach(function (resourceId) {
602
+ _this7.syncBlockFetchDataRequests.delete(resourceId);
603
+ });
604
+ return _context3.finish(15);
605
+ case 18:
606
+ case "end":
607
+ return _context3.stop();
608
+ }
609
+ }, _callee2, this, [[4, 12, 15, 18]]);
610
+ }));
611
+ function processPrefetchedData(_x) {
612
+ return _processPrefetchedData.apply(this, arguments);
613
+ }
614
+ return processPrefetchedData;
615
+ }()
545
616
  /**
546
617
  * Fetch sync block data for a given array of sync block nodes.
547
618
  * @param syncBlockNodes - The array of sync block nodes to fetch data for
548
619
  * @returns The fetched sync block data results
549
620
  */
621
+ )
550
622
  }, {
551
623
  key: "fetchSyncBlocksData",
552
624
  value: (function () {
553
- var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockNodes) {
554
- var _this7 = this,
555
- _this$fetchExperience;
556
- var nodesToFetch, data, hasUnexpectedError, hasExpectedError, _this$fetchExperience2, _this$fetchExperience3, _this$fetchExperience4;
557
- return _regeneratorRuntime.wrap(function _callee2$(_context3) {
558
- while (1) switch (_context3.prev = _context3.next) {
625
+ var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(syncBlockNodes) {
626
+ var _this8 = this,
627
+ _this$fetchExperience6;
628
+ var nodesToFetch, data, _this$processFetchedD2, hasUnexpectedError, hasExpectedError, _this$fetchExperience7, _this$fetchExperience8, _this$fetchExperience9;
629
+ return _regeneratorRuntime.wrap(function _callee3$(_context4) {
630
+ while (1) switch (_context4.prev = _context4.next) {
559
631
  case 0:
560
632
  if (!(syncBlockNodes.length === 0)) {
561
- _context3.next = 2;
633
+ _context4.next = 2;
562
634
  break;
563
635
  }
564
- return _context3.abrupt("return");
636
+ return _context4.abrupt("return");
565
637
  case 2:
566
638
  // Don't fetch for not_found error since the source is already deleted
567
639
  nodesToFetch = [];
568
640
  syncBlockNodes.forEach(function (node) {
569
641
  var _existingSyncBlock$er;
570
- if (_this7.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
642
+ if (_this8.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
571
643
  return;
572
644
  }
573
- var existingSyncBlock = _this7.getFromCache(node.attrs.resourceId);
645
+ var existingSyncBlock = _this8.getFromCache(node.attrs.resourceId);
574
646
  if ((existingSyncBlock === null || existingSyncBlock === void 0 || (_existingSyncBlock$er = existingSyncBlock.error) === null || _existingSyncBlock$er === void 0 ? void 0 : _existingSyncBlock$er.type) === SyncBlockError.NotFound) {
575
647
  return;
576
648
  }
577
649
  nodesToFetch.push(node);
578
650
  });
579
651
  if (!(nodesToFetch.length === 0)) {
580
- _context3.next = 6;
652
+ _context4.next = 6;
581
653
  break;
582
654
  }
583
- return _context3.abrupt("return");
655
+ return _context4.abrupt("return");
584
656
  case 6:
585
657
  if (this.dataProvider) {
586
- _context3.next = 8;
658
+ _context4.next = 8;
587
659
  break;
588
660
  }
589
661
  throw new Error('Data provider not set');
590
662
  case 8:
591
663
  nodesToFetch.forEach(function (node) {
592
- _this7.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
664
+ _this8.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
593
665
  });
594
- (_this$fetchExperience = this.fetchExperience) === null || _this$fetchExperience === void 0 || _this$fetchExperience.start({});
595
- _context3.next = 12;
666
+ (_this$fetchExperience6 = this.fetchExperience) === null || _this$fetchExperience6 === void 0 || _this$fetchExperience6.start({});
667
+ _context4.next = 12;
596
668
  return this.dataProvider.fetchNodesData(nodesToFetch).finally(function () {
597
669
  nodesToFetch.forEach(function (node) {
598
- _this7.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
670
+ _this8.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
599
671
  });
600
672
  });
601
673
  case 12:
602
- data = _context3.sent;
603
- hasUnexpectedError = false;
604
- hasExpectedError = false;
605
- data.forEach(function (syncBlockInstance) {
606
- var _resolvedSyncBlockIns;
607
- if (!syncBlockInstance.resourceId) {
608
- var _this7$fireAnalyticsE, _syncBlockInstance$er2;
609
- (_this7$fireAnalyticsE = _this7.fireAnalyticsEvent) === null || _this7$fireAnalyticsE === void 0 || _this7$fireAnalyticsE.call(_this7, fetchErrorPayload(((_syncBlockInstance$er2 = syncBlockInstance.error) === null || _syncBlockInstance$er2 === void 0 ? void 0 : _syncBlockInstance$er2.type) || 'Returned sync block instance does not have resource id'));
610
- return;
611
- }
612
- var existingSyncBlock = _this7.getFromCache(syncBlockInstance.resourceId);
613
- var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
614
- _this7.updateCache(resolvedSyncBlockInstance);
615
-
616
- // Check if this is a newly added unpublished sync block and notify
617
- // Only trigger for sync blocks that were just added (not refreshed or loaded on page init)
618
- if (!syncBlockInstance.error && ((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) === null || _resolvedSyncBlockIns === void 0 ? void 0 : _resolvedSyncBlockIns.status) === 'unpublished' && _this7.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId) && _this7.onUnpublishedSyncBlockDetected) {
619
- // Remove from newly added set after checking to prevent duplicate flags
620
- _this7.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
621
- _this7.onUnpublishedSyncBlockDetected(resolvedSyncBlockInstance.resourceId);
622
- } else if (_this7.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId)) {
623
- // Remove from newly added set even if not unpublished (to clean up)
624
- _this7.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
625
- }
626
- if (syncBlockInstance.error) {
627
- var _this7$fireAnalyticsE2;
628
- (_this7$fireAnalyticsE2 = _this7.fireAnalyticsEvent) === null || _this7$fireAnalyticsE2 === void 0 || _this7$fireAnalyticsE2.call(_this7, fetchErrorPayload(syncBlockInstance.error.type, syncBlockInstance.resourceId));
629
- if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
630
- hasExpectedError = true;
631
- } else if (syncBlockInstance.error) {
632
- hasUnexpectedError = true;
633
- }
634
- return;
635
- } else {
636
- var callbacks = _this7.subscriptions.get(syncBlockInstance.resourceId);
637
- var localIds = callbacks ? Object.keys(callbacks) : [];
638
- localIds.forEach(function (localId) {
639
- var _this7$fireAnalyticsE3, _syncBlockInstance$da2;
640
- (_this7$fireAnalyticsE3 = _this7.fireAnalyticsEvent) === null || _this7$fireAnalyticsE3 === void 0 || _this7$fireAnalyticsE3.call(_this7, fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
641
- });
642
- }
643
- _this7.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
644
- });
674
+ data = _context4.sent;
675
+ _this$processFetchedD2 = this.processFetchedData(data), hasUnexpectedError = _this$processFetchedD2.hasUnexpectedError, hasExpectedError = _this$processFetchedD2.hasExpectedError;
645
676
  if (hasUnexpectedError) {
646
- (_this$fetchExperience2 = this.fetchExperience) === null || _this$fetchExperience2 === void 0 || _this$fetchExperience2.failure({
677
+ (_this$fetchExperience7 = this.fetchExperience) === null || _this$fetchExperience7 === void 0 || _this$fetchExperience7.failure({
647
678
  reason: 'Unexpected error during fetch'
648
679
  });
649
680
  } else if (hasExpectedError) {
650
- (_this$fetchExperience3 = this.fetchExperience) === null || _this$fetchExperience3 === void 0 || _this$fetchExperience3.abort({
681
+ (_this$fetchExperience8 = this.fetchExperience) === null || _this$fetchExperience8 === void 0 || _this$fetchExperience8.abort({
651
682
  reason: 'Expected error: NotFound or PermissionDenied'
652
683
  });
653
684
  } else {
654
- (_this$fetchExperience4 = this.fetchExperience) === null || _this$fetchExperience4 === void 0 || _this$fetchExperience4.success();
685
+ (_this$fetchExperience9 = this.fetchExperience) === null || _this$fetchExperience9 === void 0 || _this$fetchExperience9.success();
655
686
  }
656
- case 17:
687
+ case 15:
657
688
  case "end":
658
- return _context3.stop();
689
+ return _context4.stop();
659
690
  }
660
- }, _callee2, this);
691
+ }, _callee3, this);
661
692
  }));
662
- function fetchSyncBlocksData(_x) {
693
+ function fetchSyncBlocksData(_x2) {
663
694
  return _fetchSyncBlocksData.apply(this, arguments);
664
695
  }
665
696
  return fetchSyncBlocksData;
666
697
  }())
698
+ }, {
699
+ key: "processFetchedData",
700
+ value: function processFetchedData(data) {
701
+ var _this9 = this;
702
+ if (!data) {
703
+ return {
704
+ hasUnexpectedError: false,
705
+ hasExpectedError: false
706
+ };
707
+ }
708
+ var hasUnexpectedError = false;
709
+ var hasExpectedError = false;
710
+ data.forEach(function (syncBlockInstance) {
711
+ var _resolvedSyncBlockIns;
712
+ if (!syncBlockInstance.resourceId) {
713
+ var _this9$fireAnalyticsE, _syncBlockInstance$er2;
714
+ (_this9$fireAnalyticsE = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE === void 0 || _this9$fireAnalyticsE.call(_this9, fetchErrorPayload(((_syncBlockInstance$er2 = syncBlockInstance.error) === null || _syncBlockInstance$er2 === void 0 ? void 0 : _syncBlockInstance$er2.type) || 'Returned sync block instance does not have resource id'));
715
+ return;
716
+ }
717
+ var existingSyncBlock = _this9.getFromCache(syncBlockInstance.resourceId);
718
+ var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
719
+ _this9.updateCache(resolvedSyncBlockInstance);
720
+
721
+ // Check if this is a newly added unpublished sync block and notify
722
+ // Only trigger for sync blocks that were just added (not refreshed or loaded on page init)
723
+ if (!syncBlockInstance.error && ((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) === null || _resolvedSyncBlockIns === void 0 ? void 0 : _resolvedSyncBlockIns.status) === 'unpublished' && _this9.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId) && _this9.onUnpublishedSyncBlockDetected) {
724
+ // Remove from newly added set after checking to prevent duplicate flags
725
+ _this9.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
726
+ _this9.onUnpublishedSyncBlockDetected(resolvedSyncBlockInstance.resourceId);
727
+ } else if (_this9.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId)) {
728
+ // Remove from newly added set even if not unpublished (to clean up)
729
+ _this9.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
730
+ }
731
+ if (syncBlockInstance.error) {
732
+ var _this9$fireAnalyticsE2;
733
+ (_this9$fireAnalyticsE2 = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE2 === void 0 || _this9$fireAnalyticsE2.call(_this9, fetchErrorPayload(syncBlockInstance.error.type, syncBlockInstance.resourceId));
734
+ if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
735
+ hasExpectedError = true;
736
+ } else if (syncBlockInstance.error) {
737
+ hasUnexpectedError = true;
738
+ }
739
+ return;
740
+ } else {
741
+ var callbacks = _this9.subscriptions.get(syncBlockInstance.resourceId);
742
+ var localIds = callbacks ? Object.keys(callbacks) : [];
743
+ localIds.forEach(function (localId) {
744
+ var _this9$fireAnalyticsE3, _syncBlockInstance$da2;
745
+ (_this9$fireAnalyticsE3 = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE3 === void 0 || _this9$fireAnalyticsE3.call(_this9, fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
746
+ });
747
+ }
748
+ _this9.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
749
+ });
750
+ return {
751
+ hasUnexpectedError: hasUnexpectedError,
752
+ hasExpectedError: hasExpectedError
753
+ };
754
+ }
667
755
  }, {
668
756
  key: "updateCacheWithSourceInfo",
669
757
  value: function updateCacheWithSourceInfo(resourceId, sourceInfo) {
@@ -748,7 +836,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
748
836
  var _this$dataProvider7,
749
837
  _this$dataProvider8,
750
838
  _this$dataProvider9,
751
- _this8 = this;
839
+ _this0 = this;
752
840
  // Cancel any pending cache deletion for this resourceId.
753
841
  // This handles the case where a block is moved - the old component unmounts
754
842
  // (scheduling deletion) but the new component mounts and subscribes before
@@ -784,11 +872,11 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
784
872
  this.debouncedBatchedFetchSyncBlocks(resourceId);
785
873
  } else {
786
874
  this.fetchSyncBlocksData([syncBlockNode]).catch(function (error) {
787
- var _this8$fireAnalyticsE;
875
+ var _this0$fireAnalyticsE;
788
876
  logException(error, {
789
877
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
790
878
  });
791
- (_this8$fireAnalyticsE = _this8.fireAnalyticsEvent) === null || _this8$fireAnalyticsE === void 0 || _this8$fireAnalyticsE.call(_this8, fetchErrorPayload(error.message, resourceId));
879
+ (_this0$fireAnalyticsE = _this0.fireAnalyticsEvent) === null || _this0$fireAnalyticsE === void 0 || _this0$fireAnalyticsE.call(_this0, fetchErrorPayload(error.message, resourceId));
792
880
  });
793
881
  }
794
882
  }
@@ -798,19 +886,19 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
798
886
  this.setupGraphQLSubscription(resourceId);
799
887
  }
800
888
  return function () {
801
- var resourceSubscriptions = _this8.subscriptions.get(resourceId);
889
+ var resourceSubscriptions = _this0.subscriptions.get(resourceId);
802
890
  if (resourceSubscriptions) {
803
891
  // Unsubscription means a reference synced block is removed from the document
804
- _this8.isCacheDirty = true;
892
+ _this0.isCacheDirty = true;
805
893
  delete resourceSubscriptions[localId];
806
894
  if (Object.keys(resourceSubscriptions).length === 0) {
807
- _this8.subscriptions.delete(resourceId);
895
+ _this0.subscriptions.delete(resourceId);
808
896
 
809
897
  // Clean up GraphQL subscription when no more local subscribers
810
- _this8.cleanupGraphQLSubscription(resourceId);
898
+ _this0.cleanupGraphQLSubscription(resourceId);
811
899
 
812
900
  // Notify listeners that subscription was removed
813
- _this8.notifySubscriptionChangeListeners();
901
+ _this0.notifySubscriptionChangeListeners();
814
902
 
815
903
  // Delay cache deletion to handle block moves (unmount/remount).
816
904
  // When a block is moved, the old component unmounts before the new one mounts.
@@ -819,14 +907,14 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
819
907
  // TODO: EDITOR-4152 - Rework this logic
820
908
  var deletionTimeout = setTimeout(function () {
821
909
  // Only delete if still no subscribers (wasn't re-subscribed)
822
- if (!_this8.subscriptions.has(resourceId)) {
823
- _this8.deleteFromCache(resourceId);
910
+ if (!_this0.subscriptions.has(resourceId)) {
911
+ _this0.deleteFromCache(resourceId);
824
912
  }
825
- _this8.pendingCacheDeletions.delete(resourceId);
913
+ _this0.pendingCacheDeletions.delete(resourceId);
826
914
  }, 1000);
827
- _this8.pendingCacheDeletions.set(resourceId, deletionTimeout);
915
+ _this0.pendingCacheDeletions.set(resourceId, deletionTimeout);
828
916
  } else {
829
- _this8.subscriptions.set(resourceId, resourceSubscriptions);
917
+ _this0.subscriptions.set(resourceId, resourceSubscriptions);
830
918
  }
831
919
  }
832
920
  };
@@ -835,7 +923,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
835
923
  key: "subscribeToSourceTitle",
836
924
  value: function subscribeToSourceTitle(node, callback) {
837
925
  var _cachedData$data,
838
- _this9 = this;
926
+ _this1 = this;
839
927
  // check node is a sync block, as we only support sync block subscriptions
840
928
  if (node.type.name !== 'syncBlock') {
841
929
  return function () {};
@@ -855,13 +943,13 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
855
943
  var resourceSubscriptions = this.titleSubscriptions.get(resourceId) || {};
856
944
  this.titleSubscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
857
945
  return function () {
858
- var resourceSubscriptions = _this9.titleSubscriptions.get(resourceId);
946
+ var resourceSubscriptions = _this1.titleSubscriptions.get(resourceId);
859
947
  if (resourceSubscriptions) {
860
948
  delete resourceSubscriptions[localId];
861
949
  if (Object.keys(resourceSubscriptions).length === 0) {
862
- _this9.titleSubscriptions.delete(resourceId);
950
+ _this1.titleSubscriptions.delete(resourceId);
863
951
  } else {
864
- _this9.titleSubscriptions.set(resourceId, resourceSubscriptions);
952
+ _this1.titleSubscriptions.set(resourceId, resourceSubscriptions);
865
953
  }
866
954
  }
867
955
  };
@@ -1055,19 +1143,19 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1055
1143
  }, {
1056
1144
  key: "flush",
1057
1145
  value: (function () {
1058
- var _flush = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
1146
+ var _flush = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
1059
1147
  var success, _this$saveExperience, blocks, updateResult, _this$saveExperience2, _this$fireAnalyticsEv1, _this$saveExperience3, _this$fireAnalyticsEv10, _this$saveExperience4;
1060
- return _regeneratorRuntime.wrap(function _callee3$(_context4) {
1061
- while (1) switch (_context4.prev = _context4.next) {
1148
+ return _regeneratorRuntime.wrap(function _callee4$(_context5) {
1149
+ while (1) switch (_context5.prev = _context5.next) {
1062
1150
  case 0:
1063
1151
  if (this.isCacheDirty) {
1064
- _context4.next = 2;
1152
+ _context5.next = 2;
1065
1153
  break;
1066
1154
  }
1067
- return _context4.abrupt("return", true);
1155
+ return _context5.abrupt("return", true);
1068
1156
  case 2:
1069
1157
  success = true;
1070
- _context4.prev = 3;
1158
+ _context5.prev = 3;
1071
1159
  blocks = []; // Collect all reference synced blocks on the current document
1072
1160
  Array.from(this.subscriptions.entries()).forEach(function (_ref2) {
1073
1161
  var _ref3 = _slicedToArray(_ref2, 2),
@@ -1081,7 +1169,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1081
1169
  });
1082
1170
  });
1083
1171
  if (this.dataProvider) {
1084
- _context4.next = 8;
1172
+ _context5.next = 8;
1085
1173
  break;
1086
1174
  }
1087
1175
  throw new Error('Data provider not set');
@@ -1093,10 +1181,10 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1093
1181
  // exactly at a time when the updateReferenceData is being executed asynchronously.
1094
1182
  this.isCacheDirty = false;
1095
1183
  (_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 || _this$saveExperience.start();
1096
- _context4.next = 12;
1184
+ _context5.next = 12;
1097
1185
  return this.dataProvider.updateReferenceData(blocks);
1098
1186
  case 12:
1099
- updateResult = _context4.sent;
1187
+ updateResult = _context5.sent;
1100
1188
  if (!updateResult.success) {
1101
1189
  success = false;
1102
1190
  (_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 || _this$saveExperience2.failure({
@@ -1104,35 +1192,35 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1104
1192
  });
1105
1193
  (_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 || _this$fireAnalyticsEv1.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
1106
1194
  }
1107
- _context4.next = 22;
1195
+ _context5.next = 22;
1108
1196
  break;
1109
1197
  case 16:
1110
- _context4.prev = 16;
1111
- _context4.t0 = _context4["catch"](3);
1198
+ _context5.prev = 16;
1199
+ _context5.t0 = _context5["catch"](3);
1112
1200
  success = false;
1113
- logException(_context4.t0, {
1201
+ logException(_context5.t0, {
1114
1202
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
1115
1203
  });
1116
1204
  (_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure({
1117
- reason: _context4.t0.message
1205
+ reason: _context5.t0.message
1118
1206
  });
1119
- (_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 || _this$fireAnalyticsEv10.call(this, updateReferenceErrorPayload(_context4.t0.message));
1207
+ (_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 || _this$fireAnalyticsEv10.call(this, updateReferenceErrorPayload(_context5.t0.message));
1120
1208
  case 22:
1121
- _context4.prev = 22;
1209
+ _context5.prev = 22;
1122
1210
  if (!success) {
1123
1211
  // set isCacheDirty back to true for cases where it failed to update the reference synced blocks on the BE
1124
1212
  this.isCacheDirty = true;
1125
1213
  } else {
1126
1214
  (_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 || _this$saveExperience4.success();
1127
1215
  }
1128
- return _context4.finish(22);
1216
+ return _context5.finish(22);
1129
1217
  case 25:
1130
- return _context4.abrupt("return", success);
1218
+ return _context5.abrupt("return", success);
1131
1219
  case 26:
1132
1220
  case "end":
1133
- return _context4.stop();
1221
+ return _context5.stop();
1134
1222
  }
1135
- }, _callee3, this, [[3, 16, 22, 25]]);
1223
+ }, _callee4, this, [[3, 16, 22, 25]]);
1136
1224
  }));
1137
1225
  function flush() {
1138
1226
  return _flush.apply(this, arguments);
@@ -1142,7 +1230,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1142
1230
  }, {
1143
1231
  key: "destroy",
1144
1232
  value: function destroy() {
1145
- var _this$saveExperience5, _this$fetchExperience5, _this$fetchSourceInfo2;
1233
+ var _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo2;
1146
1234
  // Clean up all GraphQL subscriptions first
1147
1235
  this.cleanupAllGraphQLSubscriptions();
1148
1236
  if (fg('platform_synced_block_patch_1')) {
@@ -1171,7 +1259,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1171
1259
  (_this$saveExperience5 = this.saveExperience) === null || _this$saveExperience5 === void 0 || _this$saveExperience5.abort({
1172
1260
  reason: 'editorDestroyed'
1173
1261
  });
1174
- (_this$fetchExperience5 = this.fetchExperience) === null || _this$fetchExperience5 === void 0 || _this$fetchExperience5.abort({
1262
+ (_this$fetchExperience0 = this.fetchExperience) === null || _this$fetchExperience0 === void 0 || _this$fetchExperience0.abort({
1175
1263
  reason: 'editorDestroyed'
1176
1264
  });
1177
1265
  (_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.abort({
@@ -1,6 +1,6 @@
1
1
  import type { ADFEntity } from '@atlaskit/adf-utils/types';
2
2
  import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
3
- import type { SyncBlockSourceInfo } from '../providers/types';
3
+ import type { SyncBlockInstance, SyncBlockSourceInfo } from '../providers/types';
4
4
  import type { SYNC_BLOCK_PRODUCTS } from './consts';
5
5
  export type BlockInstanceId = string;
6
6
  export type ResourceId = string;
@@ -73,3 +73,7 @@ export type ReferencesSourceInfo = {
73
73
  };
74
74
  export type DeletionReason = 'source-block-deleted' | 'source-block-unsynced';
75
75
  export type DeletionReasonResponse = DeletionReason | 'source-document-deleted';
76
+ export type SyncBlockPrefetchData = {
77
+ prefetchPromise: Promise<SyncBlockInstance[] | undefined>;
78
+ resourceIds: string[];
79
+ };
@@ -1,6 +1,6 @@
1
1
  export { rebaseTransaction } from './common/rebase-transaction';
2
2
  export { SyncBlockError } from './common/types';
3
- export type { ResourceId, SyncBlockData, SyncBlockNode, SyncBlockProduct, SyncBlockStatus, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData, ReferencesSourceInfo, DeletionReason, } from './common/types';
3
+ export type { ResourceId, SyncBlockData, SyncBlockNode, SyncBlockProduct, SyncBlockStatus, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData, ReferencesSourceInfo, DeletionReason, SyncBlockPrefetchData, } from './common/types';
4
4
  export { useFetchSyncBlockData, type UseFetchSyncBlockDataResult, } from './hooks/useFetchSyncBlockData';
5
5
  export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
6
6
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
@@ -8,7 +8,7 @@ export { generateBlockAri, generateBlockAriFromReference, getLocalIdFromBlockRes
8
8
  export { getConfluencePageAri, getPageIdAndTypeFromConfluencePageAri, } from './clients/confluence/ari';
9
9
  export { fetchMediaToken, type TokenData, type ConfigData, } from './clients/confluence/fetchMediaToken';
10
10
  export { getJiraWorkItemAri, getJiraWorkItemIdFromAri } from './clients/jira/ari';
11
- export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAPIProvider, } from './providers/block-service/blockServiceAPI';
11
+ export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAPIProvider, fetchReferences, batchFetchData, } from './providers/block-service/blockServiceAPI';
12
12
  export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
13
13
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
14
14
  export type { ADFFetchProvider, ADFWriteProvider, BlockNodeIdentifiers, BlockSubscriptionErrorCallback, BlockUpdateCallback, SyncBlockDataProvider, SyncBlockInstance, MediaEmojiProviderOptions, SyncedBlockRendererProviderOptions, SyncBlockRendererProviderCreator, SyncedBlockRendererDataProviders, Unsubscribe, UpdateReferenceSyncBlockResult, WriteSyncBlockResult, SyncBlockParentInfo, SyncBlockSourceInfo, } from './providers/types';
@@ -19,4 +19,3 @@ export { parseResourceId, createResourceIdForReference } from './utils/resourceI
19
19
  export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId, } from './utils/utils';
20
20
  export { fetchErrorPayload } from './utils/errorHandling';
21
21
  export { normaliseSyncBlockProduct, normaliseSyncBlockStatus } from './utils/validValue';
22
- export { fetchReferences } from './providers/block-service/blockServiceAPI';
@@ -20,6 +20,19 @@ import type { ADFFetchProvider, ADFWriteProvider, BlockNodeIdentifiers, DeleteSy
20
20
  export declare const blockAriToResourceId: (blockAri: string) => ResourceId | null;
21
21
  export declare const convertToSyncBlockData: (data: BlockContentResponse, resourceId: ResourceId) => SyncBlockData;
22
22
  export declare const fetchReferences: (documentAri: string) => Promise<SyncBlockInstance[] | SyncBlockError>;
23
+ /**
24
+ * Extracts the resourceId from a block ARI.
25
+ * Block ARI format: ari:cloud:blocks:<cloudId>:synced-block/<resourceId>
26
+ */
27
+ export declare const extractResourceIdFromBlockAri: (blockAri: string) => string | undefined;
28
+ /**
29
+ * Batch fetches multiple synced blocks by their resource IDs.
30
+ * @param cloudId - The cloudId of the block. E.G the cloudId of the confluence page, or the cloudId of the Jira instance
31
+ * @param parentAri - The ARI of the parent of the block. E.G the ARI of the confluence page, or the ARI of the Jira work item
32
+ * @param blockNodeIdentifiers - Array of block node identifiers to fetch
33
+ * @returns Array of SyncBlockInstance results
34
+ */
35
+ export declare const batchFetchData: (cloudId: string, parentAri: string | undefined, blockNodeIdentifiers: BlockNodeIdentifiers[]) => Promise<SyncBlockInstance[]>;
23
36
  interface BlockServiceADFFetchProviderProps {
24
37
  cloudId: string;
25
38
  parentAri: string | undefined;
@@ -33,14 +46,9 @@ declare class BlockServiceADFFetchProvider implements ADFFetchProvider {
33
46
  constructor({ cloudId, parentAri }: BlockServiceADFFetchProviderProps);
34
47
  fetchData(resourceId: string): Promise<SyncBlockInstance>;
35
48
  fetchReferences(referenceResourceId: string): Promise<ReferenceSyncBlockData>;
36
- /**
37
- * Extracts the resourceId from a block ARI.
38
- * Block ARI format: ari:cloud:blocks:<cloudId>:synced-block/<resourceId>
39
- */
40
- private extractResourceIdFromBlockAri;
41
49
  /**
42
50
  * Batch fetches multiple synced blocks by their resource IDs.
43
- * @param resourceIds - Array of resource IDs to fetch
51
+ * @param blockNodeIdentifiers - Array of block node identifiers to fetch
44
52
  * @returns Array of SyncBlockInstance results
45
53
  */
46
54
  batchFetchData(blockNodeIdentifiers: BlockNodeIdentifiers[]): Promise<SyncBlockInstance[]>;
@@ -2,7 +2,7 @@ import { type RendererSyncBlockEventPayload } from '@atlaskit/editor-common/anal
2
2
  import type { Experience } from '@atlaskit/editor-common/experiences';
3
3
  import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
4
4
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
- import { type ResourceId, type SyncBlockNode } from '../common/types';
5
+ import { type ResourceId, type SyncBlockNode, type SyncBlockPrefetchData } from '../common/types';
6
6
  import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProvider, TitleSubscriptionCallback, SyncBlockSourceInfo } from '../providers/types';
7
7
  export declare class ReferenceSyncBlockStoreManager {
8
8
  private dataProvider?;
@@ -102,12 +102,19 @@ export declare class ReferenceSyncBlockStoreManager {
102
102
  private cleanupAllGraphQLSubscriptions;
103
103
  fetchSyncBlockSourceInfoBySourceAri(sourceAri: string, hasAccess?: boolean, urlType?: 'view' | 'edit'): Promise<SyncBlockSourceInfo | undefined>;
104
104
  fetchSyncBlockSourceInfo(resourceId: ResourceId): Promise<SyncBlockSourceInfo | undefined>;
105
+ /**
106
+ * Processes prefetched data and updates the cache.
107
+ * @param prefetchedData - The prefetched data to process
108
+ * @returns {Promise<void>}
109
+ */
110
+ processPrefetchedData(prefetchedData: SyncBlockPrefetchData | undefined): Promise<void>;
105
111
  /**
106
112
  * Fetch sync block data for a given array of sync block nodes.
107
113
  * @param syncBlockNodes - The array of sync block nodes to fetch data for
108
114
  * @returns The fetched sync block data results
109
115
  */
110
116
  fetchSyncBlocksData(syncBlockNodes: SyncBlockNode[]): Promise<void>;
117
+ private processFetchedData;
111
118
  private updateCacheWithSourceInfo;
112
119
  private updateCache;
113
120
  private updateSourceTitleSubscriptions;
@@ -1,6 +1,6 @@
1
1
  import type { ADFEntity } from '@atlaskit/adf-utils/types';
2
2
  import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
3
- import type { SyncBlockSourceInfo } from '../providers/types';
3
+ import type { SyncBlockInstance, SyncBlockSourceInfo } from '../providers/types';
4
4
  import type { SYNC_BLOCK_PRODUCTS } from './consts';
5
5
  export type BlockInstanceId = string;
6
6
  export type ResourceId = string;
@@ -73,3 +73,7 @@ export type ReferencesSourceInfo = {
73
73
  };
74
74
  export type DeletionReason = 'source-block-deleted' | 'source-block-unsynced';
75
75
  export type DeletionReasonResponse = DeletionReason | 'source-document-deleted';
76
+ export type SyncBlockPrefetchData = {
77
+ prefetchPromise: Promise<SyncBlockInstance[] | undefined>;
78
+ resourceIds: string[];
79
+ };
@@ -1,6 +1,6 @@
1
1
  export { rebaseTransaction } from './common/rebase-transaction';
2
2
  export { SyncBlockError } from './common/types';
3
- export type { ResourceId, SyncBlockData, SyncBlockNode, SyncBlockProduct, SyncBlockStatus, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData, ReferencesSourceInfo, DeletionReason, } from './common/types';
3
+ export type { ResourceId, SyncBlockData, SyncBlockNode, SyncBlockProduct, SyncBlockStatus, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData, ReferencesSourceInfo, DeletionReason, SyncBlockPrefetchData, } from './common/types';
4
4
  export { useFetchSyncBlockData, type UseFetchSyncBlockDataResult, } from './hooks/useFetchSyncBlockData';
5
5
  export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
6
6
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
@@ -8,7 +8,7 @@ export { generateBlockAri, generateBlockAriFromReference, getLocalIdFromBlockRes
8
8
  export { getConfluencePageAri, getPageIdAndTypeFromConfluencePageAri, } from './clients/confluence/ari';
9
9
  export { fetchMediaToken, type TokenData, type ConfigData, } from './clients/confluence/fetchMediaToken';
10
10
  export { getJiraWorkItemAri, getJiraWorkItemIdFromAri } from './clients/jira/ari';
11
- export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAPIProvider, } from './providers/block-service/blockServiceAPI';
11
+ export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAPIProvider, fetchReferences, batchFetchData, } from './providers/block-service/blockServiceAPI';
12
12
  export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
13
13
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
14
14
  export type { ADFFetchProvider, ADFWriteProvider, BlockNodeIdentifiers, BlockSubscriptionErrorCallback, BlockUpdateCallback, SyncBlockDataProvider, SyncBlockInstance, MediaEmojiProviderOptions, SyncedBlockRendererProviderOptions, SyncBlockRendererProviderCreator, SyncedBlockRendererDataProviders, Unsubscribe, UpdateReferenceSyncBlockResult, WriteSyncBlockResult, SyncBlockParentInfo, SyncBlockSourceInfo, } from './providers/types';
@@ -19,4 +19,3 @@ export { parseResourceId, createResourceIdForReference } from './utils/resourceI
19
19
  export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId, } from './utils/utils';
20
20
  export { fetchErrorPayload } from './utils/errorHandling';
21
21
  export { normaliseSyncBlockProduct, normaliseSyncBlockStatus } from './utils/validValue';
22
- export { fetchReferences } from './providers/block-service/blockServiceAPI';