@atlaskit/editor-synced-block-provider 2.10.1 → 2.10.3

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.
Files changed (85) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/{providers → clients}/block-service/ari.js +2 -2
  3. package/dist/cjs/{utils → clients/confluence}/ari.js +6 -6
  4. package/dist/cjs/{utils → clients/confluence}/sourceInfo.js +7 -7
  5. package/dist/cjs/clients/confluence/utils.js +9 -0
  6. package/dist/cjs/hooks/useFetchSyncBlockData.js +5 -6
  7. package/dist/cjs/hooks/useFetchSyncBlockTitle.js +1 -1
  8. package/dist/cjs/hooks/useHandleContentChanges.js +1 -1
  9. package/dist/cjs/index.js +27 -14
  10. package/dist/cjs/providers/block-service/blockServiceAPI.js +4 -4
  11. package/dist/cjs/providers/confluence/confluenceContentAPI.js +33 -26
  12. package/dist/cjs/providers/syncBlockProvider.js +38 -3
  13. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +86 -19
  14. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +52 -10
  15. package/dist/cjs/store-manager/syncBlockStoreManager.js +14 -157
  16. package/dist/cjs/utils/utils.js +8 -4
  17. package/dist/es2019/{providers → clients}/block-service/ari.js +1 -1
  18. package/dist/es2019/{utils → clients/confluence}/ari.js +5 -5
  19. package/dist/es2019/{utils → clients/confluence}/sourceInfo.js +5 -5
  20. package/dist/es2019/clients/confluence/utils.js +3 -0
  21. package/dist/es2019/hooks/useFetchSyncBlockData.js +5 -6
  22. package/dist/es2019/hooks/useFetchSyncBlockTitle.js +1 -1
  23. package/dist/es2019/hooks/useHandleContentChanges.js +1 -1
  24. package/dist/es2019/index.js +14 -4
  25. package/dist/es2019/providers/block-service/blockServiceAPI.js +4 -4
  26. package/dist/es2019/providers/confluence/confluenceContentAPI.js +19 -13
  27. package/dist/es2019/providers/syncBlockProvider.js +38 -3
  28. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +75 -10
  29. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +39 -1
  30. package/dist/es2019/store-manager/syncBlockStoreManager.js +12 -117
  31. package/dist/es2019/utils/utils.js +3 -3
  32. package/dist/esm/{providers → clients}/block-service/ari.js +1 -1
  33. package/dist/esm/{utils → clients/confluence}/ari.js +5 -5
  34. package/dist/esm/{utils → clients/confluence}/sourceInfo.js +7 -7
  35. package/dist/esm/clients/confluence/utils.js +3 -0
  36. package/dist/esm/hooks/useFetchSyncBlockData.js +5 -6
  37. package/dist/esm/hooks/useFetchSyncBlockTitle.js +1 -1
  38. package/dist/esm/hooks/useHandleContentChanges.js +1 -1
  39. package/dist/esm/index.js +14 -4
  40. package/dist/esm/providers/block-service/blockServiceAPI.js +4 -4
  41. package/dist/esm/providers/confluence/confluenceContentAPI.js +33 -26
  42. package/dist/esm/providers/syncBlockProvider.js +38 -3
  43. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +87 -19
  44. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +52 -10
  45. package/dist/esm/store-manager/syncBlockStoreManager.js +14 -157
  46. package/dist/esm/utils/utils.js +7 -3
  47. package/dist/types/{providers → clients}/block-service/ari.d.ts +1 -1
  48. package/dist/types/{utils → clients/block-service}/blockService.d.ts +3 -3
  49. package/dist/types/clients/confluence/ari.d.ts +9 -0
  50. package/dist/types/{utils → clients/confluence}/contentProperty.d.ts +1 -1
  51. package/dist/types/clients/confluence/sourceInfo.d.ts +2 -0
  52. package/dist/types/clients/confluence/utils.d.ts +2 -0
  53. package/dist/types/common/types.d.ts +3 -1
  54. package/dist/types/index.d.ts +5 -4
  55. package/dist/types/providers/syncBlockProvider.d.ts +10 -1
  56. package/dist/types/providers/types.d.ts +20 -8
  57. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +6 -0
  58. package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +17 -1
  59. package/dist/types/store-manager/syncBlockStoreManager.d.ts +4 -59
  60. package/dist/types/utils/utils.d.ts +1 -2
  61. package/dist/types-ts4.5/{providers → clients}/block-service/ari.d.ts +1 -1
  62. package/dist/types-ts4.5/{utils → clients/block-service}/blockService.d.ts +3 -3
  63. package/dist/types-ts4.5/clients/confluence/ari.d.ts +9 -0
  64. package/dist/types-ts4.5/{utils → clients/confluence}/contentProperty.d.ts +1 -1
  65. package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +2 -0
  66. package/dist/types-ts4.5/clients/confluence/utils.d.ts +2 -0
  67. package/dist/types-ts4.5/common/types.d.ts +3 -1
  68. package/dist/types-ts4.5/index.d.ts +5 -4
  69. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +10 -1
  70. package/dist/types-ts4.5/providers/types.d.ts +20 -8
  71. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +6 -0
  72. package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +17 -1
  73. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +4 -59
  74. package/dist/types-ts4.5/utils/utils.d.ts +1 -2
  75. package/package.json +5 -5
  76. package/dist/types/utils/ari.d.ts +0 -9
  77. package/dist/types/utils/sourceInfo.d.ts +0 -2
  78. package/dist/types-ts4.5/utils/ari.d.ts +0 -9
  79. package/dist/types-ts4.5/utils/sourceInfo.d.ts +0 -2
  80. /package/dist/cjs/{utils → clients/block-service}/blockService.js +0 -0
  81. /package/dist/cjs/{utils → clients/confluence}/contentProperty.js +0 -0
  82. /package/dist/es2019/{utils → clients/block-service}/blockService.js +0 -0
  83. /package/dist/es2019/{utils → clients/confluence}/contentProperty.js +0 -0
  84. /package/dist/esm/{utils → clients/block-service}/blockService.js +0 -0
  85. /package/dist/esm/{utils → clients/confluence}/contentProperty.js +0 -0
@@ -5,8 +5,8 @@ export var getConfluencePageAri = function getConfluencePageAri(pageId, cloudId)
5
5
  return "ari:cloud:confluence:".concat(cloudId, ":").concat(pageType, "/").concat(pageId);
6
6
  };
7
7
 
8
- // For extracting from Page ARI and also the content property's version of resourceId
9
- export var getPageIdAndTypeFromAri = function getPageIdAndTypeFromAri(ari) {
8
+ // For extracting from Page ARI and also the content property's version of resourceId
9
+ export var getPageIdAndTypeFromConfluencePageAri = function getPageIdAndTypeFromConfluencePageAri(ari) {
10
10
  var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
11
11
  if (match !== null && match !== void 0 && match[2]) {
12
12
  return {
@@ -16,20 +16,20 @@ export var getPageIdAndTypeFromAri = function getPageIdAndTypeFromAri(ari) {
16
16
  }
17
17
  throw new Error("Invalid page ARI: ".concat(ari));
18
18
  };
19
- export var getLocalIdFromAri = function getLocalIdFromAri(ari) {
19
+ export var getLocalIdFromConfluencePageAri = function getLocalIdFromConfluencePageAri(ari) {
20
20
  var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
21
21
  if (match !== null && match !== void 0 && match[2]) {
22
22
  return match[2];
23
23
  }
24
24
  throw new Error("Invalid page ARI: ".concat(ari));
25
25
  };
26
- export var getPageARIFromResourceId = function getPageARIFromResourceId(resourceId) {
26
+ export var getPageARIFromContentPropertyResourceId = function getPageARIFromContentPropertyResourceId(resourceId) {
27
27
  var match = resourceId.match(/(ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+)\/([a-zA-Z0-9-]+)$/);
28
28
  if (match !== null && match !== void 0 && match[1]) {
29
29
  return match[1];
30
30
  }
31
31
  throw new Error("Invalid resourceId: ".concat(resourceId));
32
32
  };
33
- export var resourceIdFromSourceAndLocalId = function resourceIdFromSourceAndLocalId(sourceId, localId) {
33
+ export var resourceIdFromConfluencePageSourceIdAndLocalId = function resourceIdFromConfluencePageSourceIdAndLocalId(sourceId, localId) {
34
34
  return sourceId + '/' + localId;
35
35
  };
@@ -5,7 +5,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
5
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
6
  /* eslint-disable require-unicode-regexp */
7
7
 
8
- import { getPageIdAndTypeFromAri } from './ari';
8
+ import { getPageIdAndTypeFromConfluencePageAri } from './ari';
9
9
  import { isBlogPageType } from './utils';
10
10
  var COMMON_HEADERS = {
11
11
  'Content-Type': 'application/json',
@@ -22,7 +22,7 @@ var GET_SOURCE_INFO_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET_SOURCE_INFO';
22
22
  * @returns subType live if livePage, subType null if classic page
23
23
  */
24
24
  var GET_SOURCE_INFO_QUERY = "query ".concat(GET_SOURCE_INFO_OPERATION_NAME, " ($id: ID!) {\n\tcontent (id: $id) {\n\t\tnodes {\n\t\t\tid\n\t\t\tlinks {\n\t\t\t\tbase\n\t\t\t}\n\t\t\tspace {\n\t\t\t\tkey\n\t\t\t}\n\t\t\tsubType\n\t\t\ttitle\n\t\t}\n\t}\n}");
25
- var getSourceInfo = /*#__PURE__*/function () {
25
+ var getConfluenceSourceInfo = /*#__PURE__*/function () {
26
26
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(ari) {
27
27
  var bodyData, response;
28
28
  return _regeneratorRuntime.wrap(function _callee$(_context) {
@@ -59,20 +59,20 @@ var getSourceInfo = /*#__PURE__*/function () {
59
59
  }
60
60
  }, _callee);
61
61
  }));
62
- return function getSourceInfo(_x) {
62
+ return function getConfluenceSourceInfo(_x) {
63
63
  return _ref.apply(this, arguments);
64
64
  };
65
65
  }();
66
- export var fetchSourceInfo = /*#__PURE__*/function () {
66
+ export var fetchConfluenceSourceInfo = /*#__PURE__*/function () {
67
67
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(pageAri, localId) {
68
68
  var _response$data, _contentData$space, _getPageIdAndTypeFrom, pageType, response, contentData, title, url, _ref3, base;
69
69
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
70
70
  while (1) switch (_context2.prev = _context2.next) {
71
71
  case 0:
72
72
  _context2.prev = 0;
73
- _getPageIdAndTypeFrom = getPageIdAndTypeFromAri(pageAri), pageType = _getPageIdAndTypeFrom.type;
73
+ _getPageIdAndTypeFrom = getPageIdAndTypeFromConfluencePageAri(pageAri), pageType = _getPageIdAndTypeFrom.type;
74
74
  _context2.next = 4;
75
- return getSourceInfo(pageAri);
75
+ return getConfluenceSourceInfo(pageAri);
76
76
  case 4:
77
77
  response = _context2.sent;
78
78
  contentData = (_response$data = response.data) === null || _response$data === void 0 || (_response$data = _response$data.content) === null || _response$data === void 0 || (_response$data = _response$data.nodes) === null || _response$data === void 0 ? void 0 : _response$data[0];
@@ -108,7 +108,7 @@ export var fetchSourceInfo = /*#__PURE__*/function () {
108
108
  }
109
109
  }, _callee2, null, [[0, 15]]);
110
110
  }));
111
- return function fetchSourceInfo(_x2, _x3) {
111
+ return function fetchConfluenceSourceInfo(_x2, _x3) {
112
112
  return _ref2.apply(this, arguments);
113
113
  };
114
114
  }();
@@ -0,0 +1,3 @@
1
+ export var isBlogPageType = function isBlogPageType(pageType) {
2
+ return pageType === 'blogpost';
3
+ };
@@ -13,7 +13,6 @@ export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resou
13
13
  _useState4 = _slicedToArray(_useState3, 2),
14
14
  isLoading = _useState4[0],
15
15
  setIsLoading = _useState4[1];
16
- var referenceSyncBlockStoreManager = manager.getReferenceSyncBlockStoreManager();
17
16
  var reloadData = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
18
17
  var syncBlockNode;
19
18
  return _regeneratorRuntime.wrap(function _callee$(_context) {
@@ -35,7 +34,7 @@ export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resou
35
34
  setIsLoading(true);
36
35
  _context.prev = 6;
37
36
  _context.next = 9;
38
- return referenceSyncBlockStoreManager.fetchSyncBlocksData([syncBlockNode]);
37
+ return manager.referenceManager.fetchSyncBlocksData([syncBlockNode]);
39
38
  case 9:
40
39
  _context.next = 14;
41
40
  break;
@@ -54,19 +53,19 @@ export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resou
54
53
  return _context.stop();
55
54
  }
56
55
  }, _callee, null, [[6, 11]]);
57
- })), [isLoading, localId, referenceSyncBlockStoreManager, resourceId]);
56
+ })), [isLoading, localId, manager.referenceManager, resourceId]);
58
57
  useEffect(function () {
59
- var unsubscribe = referenceSyncBlockStoreManager.subscribeToSyncBlock(resourceId || '', localId || '', function (data) {
58
+ var unsubscribe = manager.referenceManager.subscribeToSyncBlock(resourceId || '', localId || '', function (data) {
60
59
  setSyncBlockInstance(data);
61
60
  setIsLoading(false);
62
61
  });
63
62
  return function () {
64
63
  unsubscribe();
65
64
  };
66
- }, [localId, referenceSyncBlockStoreManager, resourceId]);
65
+ }, [localId, manager.referenceManager, resourceId]);
67
66
  return {
68
67
  isLoading: isLoading,
69
- providerFactory: referenceSyncBlockStoreManager.getProviderFactory(resourceId || ''),
68
+ providerFactory: manager.referenceManager.getProviderFactory(resourceId || ''),
70
69
  reloadData: reloadData,
71
70
  syncBlockInstance: syncBlockInstance
72
71
  };
@@ -6,7 +6,7 @@ export var useFetchSyncBlockTitle = function useFetchSyncBlockTitle(manager, syn
6
6
  sourceTitle = _useState2[0],
7
7
  setSourceTitle = _useState2[1];
8
8
  useEffect(function () {
9
- var unsubscribe = manager.subscribeToSyncBlockSourceTitle(syncBlockNode, function (title) {
9
+ var unsubscribe = manager.referenceManager.subscribeToSourceTitle(syncBlockNode, function (title) {
10
10
  setSourceTitle(title);
11
11
  });
12
12
  return function () {
@@ -2,7 +2,7 @@ import { useEffect } from 'react';
2
2
  export var useHandleContentChanges = function useHandleContentChanges(manager, syncBlockNode) {
3
3
  useEffect(function () {
4
4
  try {
5
- manager.updateSyncBlockData(syncBlockNode);
5
+ manager.sourceManager.updateSyncBlockData(syncBlockNode);
6
6
  } catch (_unused) {
7
7
  //TODO: EDITOR-1921 - add error analytics
8
8
  }
package/dist/esm/index.js CHANGED
@@ -1,16 +1,26 @@
1
1
  /* eslint-disable @atlaskit/editor/no-re-export */
2
2
 
3
+ // common
3
4
  export { rebaseTransaction } from './common/rebase-transaction';
4
5
  export { SyncBlockError } from './common/types';
6
+ // hooks
5
7
  export { useFetchSyncBlockData } from './hooks/useFetchSyncBlockData';
6
8
  export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
7
9
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
8
- export { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from './providers/block-service/ari';
10
+
11
+ // clients
12
+ export { blockResourceIdFromSourceAndLocalId, getLocalIdFromBlockResourceId } from './clients/block-service/ari';
13
+ export { getConfluencePageAri, getLocalIdFromConfluencePageAri, getPageARIFromContentPropertyResourceId, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from './clients/confluence/ari';
14
+
15
+ // providers
9
16
  export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/blockServiceAPI';
10
17
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
18
+ export { fetchConfluenceSourceInfo } from './clients/confluence/sourceInfo';
11
19
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
20
+ // store managers
12
21
  export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
13
22
  export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
14
- export { getConfluencePageAri, getLocalIdFromAri, getPageARIFromResourceId, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from './utils/ari';
15
- export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode } from './utils/utils';
16
- export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
23
+
24
+ // utils
25
+ export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
26
+ export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes } from './utils/utils';
@@ -3,10 +3,10 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
5
  import { useMemo } from 'react';
6
+ import { blockResourceIdFromSourceAndLocalId, getLocalIdFromBlockResourceId } from '../../clients/block-service/ari';
7
+ import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../clients/block-service/blockService';
6
8
  import { SyncBlockError } from '../../common/types';
7
- import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../utils/blockService';
8
9
  import { stringifyError } from '../../utils/errorHandling';
9
- import { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from './ari';
10
10
  var mapBlockError = function mapBlockError(error) {
11
11
  switch (error.status) {
12
12
  case 403:
@@ -34,7 +34,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
34
34
  return _regeneratorRuntime.wrap(function _callee$(_context) {
35
35
  while (1) switch (_context.prev = _context.next) {
36
36
  case 0:
37
- localId = getLocalIdFromResourceId(resourceId);
37
+ localId = getLocalIdFromBlockResourceId(resourceId);
38
38
  _context.prev = 1;
39
39
  _context.next = 4;
40
40
  return getSyncedBlockContent({
@@ -94,7 +94,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
94
94
  value: function retrieveSourceInfoFetchData(resourceId, pageARI) {
95
95
  var sourceLocalId;
96
96
  try {
97
- sourceLocalId = getLocalIdFromResourceId(resourceId);
97
+ sourceLocalId = getLocalIdFromBlockResourceId(resourceId);
98
98
  } catch (error) {
99
99
  // EDITOR-1921: log analytic here, safe to continue
100
100
  }
@@ -3,13 +3,15 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
4
  import _createClass from "@babel/runtime/helpers/createClass";
5
5
  import _typeof from "@babel/runtime/helpers/typeof";
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
8
  import _regeneratorRuntime from "@babel/runtime/regenerator";
7
9
  import { useMemo } from 'react';
10
+ import { getConfluencePageAri, getPageARIFromContentPropertyResourceId, getLocalIdFromConfluencePageAri, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from '../../clients/confluence/ari';
11
+ import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../clients/confluence/contentProperty';
12
+ import { isBlogPageType } from '../../clients/confluence/utils';
8
13
  import { SyncBlockError } from '../../common/types';
9
- import { getLocalIdFromAri, getPageARIFromResourceId, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from '../../utils/ari';
10
- import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../utils/contentProperty';
11
14
  import { stringifyError } from '../../utils/errorHandling';
12
- import { isBlogPageType } from '../../utils/utils';
13
15
 
14
16
  /**
15
17
  * Configuration for Content API providers
@@ -61,8 +63,8 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
61
63
  return _regeneratorRuntime.wrap(function _callee$(_context) {
62
64
  while (1) switch (_context.prev = _context.next) {
63
65
  case 0:
64
- _getPageIdAndTypeFrom = getPageIdAndTypeFromAri(resourceId), pageId = _getPageIdAndTypeFrom.id, pageType = _getPageIdAndTypeFrom.type;
65
- localId = getLocalIdFromAri(resourceId);
66
+ _getPageIdAndTypeFrom = getPageIdAndTypeFromConfluencePageAri(resourceId), pageId = _getPageIdAndTypeFrom.id, pageType = _getPageIdAndTypeFrom.type;
67
+ localId = getLocalIdFromConfluencePageAri(resourceId);
66
68
  _context.prev = 2;
67
69
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
68
70
  options = {
@@ -131,10 +133,10 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
131
133
  }, {
132
134
  key: "retrieveSourceInfoFetchData",
133
135
  value: function retrieveSourceInfoFetchData(resourceId) {
134
- var pageARI = getPageARIFromResourceId(resourceId);
136
+ var pageARI = getPageARIFromContentPropertyResourceId(resourceId);
135
137
  var sourceLocalId;
136
138
  try {
137
- sourceLocalId = getLocalIdFromAri(resourceId);
139
+ sourceLocalId = getLocalIdFromConfluencePageAri(resourceId);
138
140
  } catch (error) {
139
141
  // EDITOR-1921: log analytic here, safe to continue
140
142
  }
@@ -211,13 +213,13 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
211
213
  key: "writeData",
212
214
  value: function () {
213
215
  var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
214
- var match, resourceId, _match, pageId, pageType, localId, key, options, updatePayload, updateResult;
216
+ var match, resourceId, _match, pageId, pageType, localId, key, sourceAri, syncBlockDataWithSourceDocumentAri, options, updatePayload, updateResult;
215
217
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
216
218
  while (1) switch (_context3.prev = _context3.next) {
217
219
  case 0:
218
220
  resourceId = data.resourceId;
219
221
  _context3.prev = 1;
220
- match = getPageIdAndTypeFromAri(data.resourceId);
222
+ match = getPageIdAndTypeFromConfluencePageAri(data.resourceId);
221
223
  _context3.next = 8;
222
224
  break;
223
225
  case 5:
@@ -230,30 +232,35 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
230
232
  _match = match, pageId = _match.id, pageType = _match.type;
231
233
  _context3.prev = 9;
232
234
  // Update existing content property
233
- localId = getLocalIdFromAri(resourceId);
235
+ localId = getLocalIdFromConfluencePageAri(resourceId);
234
236
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
237
+ sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
238
+ syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({}, data), {}, {
239
+ product: 'confluence-page',
240
+ sourceAri: sourceAri
241
+ });
235
242
  options = {
236
243
  pageId: pageId,
237
244
  key: key,
238
- value: data,
245
+ value: syncBlockDataWithSourceDocumentAri,
239
246
  cloudId: this.config.cloudId,
240
247
  pageType: pageType
241
248
  };
242
- _context3.next = 15;
249
+ _context3.next = 17;
243
250
  return updateContentProperty(options);
244
- case 15:
251
+ case 17:
245
252
  updatePayload = _context3.sent;
246
253
  updateResult = isBlogPageType(pageType) ? updatePayload.data.confluence.updateValueBlogPostProperty.blogPostProperty : updatePayload.data.confluence.updateValuePageProperty.pageProperty;
247
254
  if (!((updateResult === null || updateResult === void 0 ? void 0 : updateResult.key) === key)) {
248
- _context3.next = 21;
255
+ _context3.next = 23;
249
256
  break;
250
257
  }
251
258
  return _context3.abrupt("return", {
252
259
  resourceId: resourceId
253
260
  });
254
- case 21:
261
+ case 23:
255
262
  if (updateResult) {
256
- _context3.next = 25;
263
+ _context3.next = 27;
257
264
  break;
258
265
  }
259
266
  return _context3.abrupt("return", this.createNewContentProperty(pageId, key, data, pageType).then(function () {
@@ -265,24 +272,24 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
265
272
  error: error
266
273
  };
267
274
  }));
268
- case 25:
275
+ case 27:
269
276
  return _context3.abrupt("return", {
270
277
  error: "Failed to update ".concat(pageType, " content property")
271
278
  });
272
- case 26:
273
- _context3.next = 31;
274
- break;
275
279
  case 28:
276
- _context3.prev = 28;
280
+ _context3.next = 33;
281
+ break;
282
+ case 30:
283
+ _context3.prev = 30;
277
284
  _context3.t1 = _context3["catch"](9);
278
285
  return _context3.abrupt("return", {
279
286
  error: "Failed to write ".concat(pageType)
280
287
  });
281
- case 31:
288
+ case 33:
282
289
  case "end":
283
290
  return _context3.stop();
284
291
  }
285
- }, _callee3, this, [[1, 5], [9, 28]]);
292
+ }, _callee3, this, [[1, 5], [9, 30]]);
286
293
  }));
287
294
  function writeData(_x6) {
288
295
  return _writeData.apply(this, arguments);
@@ -298,7 +305,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
298
305
  while (1) switch (_context4.prev = _context4.next) {
299
306
  case 0:
300
307
  _context4.prev = 0;
301
- match = getPageIdAndTypeFromAri(resourceId);
308
+ match = getPageIdAndTypeFromConfluencePageAri(resourceId);
302
309
  _context4.next = 7;
303
310
  break;
304
311
  case 4:
@@ -312,7 +319,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
312
319
  case 7:
313
320
  _match2 = match, pageId = _match2.id, pageType = _match2.type;
314
321
  _context4.prev = 8;
315
- localId = getLocalIdFromAri(resourceId);
322
+ localId = getLocalIdFromConfluencePageAri(resourceId);
316
323
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
317
324
  options = {
318
325
  pageId: pageId,
@@ -355,7 +362,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
355
362
  }, {
356
363
  key: "generateResourceId",
357
364
  value: function generateResourceId(sourceId, localId) {
358
- return resourceIdFromSourceAndLocalId(sourceId, localId);
365
+ return resourceIdFromConfluencePageSourceIdAndLocalId(sourceId, localId);
359
366
  }
360
367
  }]);
361
368
  }();
@@ -10,9 +10,10 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
10
10
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
11
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
12
12
  import { useMemo } from 'react';
13
+ import { getPageIdAndTypeFromConfluencePageAri } from '../clients/confluence/ari';
14
+ import { fetchConfluenceSourceInfo } from '../clients/confluence/sourceInfo';
13
15
  import { SyncBlockError } from '../common/types';
14
16
  import { SyncBlockDataProvider } from '../providers/types';
15
- import { fetchSourceInfo } from '../utils/sourceInfo';
16
17
  export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
17
18
  // the source document ARI; that the source sync block is on.
18
19
 
@@ -210,7 +211,7 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
210
211
  }, {
211
212
  key: "retrieveSyncBlockSourceInfo",
212
213
  value: function retrieveSyncBlockSourceInfo(node) {
213
- // with content API, this is the concatenation of the page ARI and the block's localId.
214
+ // with content API, this is the concatenation of the page ARI and the block's localId.
214
215
  // with block service, this is the ARI of the block.
215
216
  // this can be cleaned up from the specific providers and placed here after platform_synced_blocks_block_service_provider
216
217
  var resourceId = node.attrs.resourceId;
@@ -225,7 +226,10 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
225
226
  return Promise.reject(error);
226
227
  }
227
228
  }
228
- return pageARI ? fetchSourceInfo(pageARI, sourceLocalId) : Promise.resolve(undefined);
229
+
230
+ // TODO: EDITOR-3312 - based on the source sync block product,
231
+ // execute fetchConfluenceSourceInfo or fetchJiraItemSourceInfo or similar...
232
+ return pageARI ? fetchConfluenceSourceInfo(pageARI, sourceLocalId) : Promise.resolve(undefined);
229
233
  }
230
234
  }, {
231
235
  key: "generateResourceId",
@@ -243,6 +247,37 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
243
247
  value: function getSyncedBlockRendererProviderOptions() {
244
248
  return this.providerOptions;
245
249
  }
250
+
251
+ /**
252
+ * Retrieve the parent info for the sync block
253
+ *
254
+ * @param resourceId
255
+ * @param syncBlockInstance
256
+ *
257
+ * @returns The parent info for the sync block
258
+ */
259
+ }, {
260
+ key: "retrieveSyncBlockParentInfo",
261
+ value: function retrieveSyncBlockParentInfo(syncBlockInstance) {
262
+ if (!syncBlockInstance || !syncBlockInstance.data) {
263
+ return undefined;
264
+ }
265
+ var _syncBlockInstance$da = syncBlockInstance.data,
266
+ sourceAri = _syncBlockInstance$da.sourceAri,
267
+ product = _syncBlockInstance$da.product;
268
+ if (!sourceAri || !product) {
269
+ return undefined;
270
+ }
271
+
272
+ // TODO: EDITOR-3312 - based on the source sync block product,
273
+ // execute getPageIdAndTypeFromConfluencePageAri or getJiraItemIdAndTypeFromJiraItemAri or similar...
274
+ var _getPageIdAndTypeFrom = getPageIdAndTypeFromConfluencePageAri(sourceAri),
275
+ contentId = _getPageIdAndTypeFrom.id;
276
+ return {
277
+ contentId: contentId,
278
+ contentProduct: product
279
+ };
280
+ }
246
281
  }]);
247
282
  }(SyncBlockDataProvider);
248
283
  export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
@@ -13,6 +13,12 @@ import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
13
13
  import { SyncBlockError } from '../common/types';
14
14
  import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
15
15
  import { createSyncBlockNode } from '../utils/utils';
16
+
17
+ // A store manager responsible for the lifecycle and state management of reference sync blocks in an editor instance.
18
+ // Designed to manage local in-memory state and synchronize with an external data provider.
19
+ // Supports fetch, cache, and subscription for sync block data.
20
+ // Handles fetching source URL and title for sync blocks.
21
+ // Can be used in both editor and renderer contexts.
16
22
  export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
17
23
  function ReferenceSyncBlockStoreManager(dataProvider) {
18
24
  _classCallCheck(this, ReferenceSyncBlockStoreManager);
@@ -116,6 +122,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
116
122
  return;
117
123
  }
118
124
 
125
+ // TODO: EDITOR-3312 - retrieve the source info based on the source sync block product
126
+
119
127
  // if the sync block is a reference block, we need to fetch the URL to the source
120
128
  // we could optimise this further by checking if the sync block is on the same page as the source
121
129
  if (!this.syncBlockURLRequests.get(resourceId)) {
@@ -137,21 +145,33 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
137
145
  });
138
146
  }
139
147
  }
148
+
149
+ /**
150
+ * Fetch sync block data for a given array of sync block nodes.
151
+ * @param syncBlockNodes - The array of sync block nodes to fetch data for
152
+ * @returns The fetched sync block data results
153
+ */
140
154
  }, {
141
155
  key: "fetchSyncBlocksData",
142
- value: function () {
156
+ value: (function () {
143
157
  var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockNodes) {
144
158
  var _this2 = this;
145
159
  var nodesToFetch, blocksWithNotFoundError, data, resolvedData;
146
160
  return _regeneratorRuntime.wrap(function _callee2$(_context3) {
147
161
  while (1) switch (_context3.prev = _context3.next) {
148
162
  case 0:
149
- if (this.dataProvider) {
163
+ if (!(syncBlockNodes.length === 0)) {
150
164
  _context3.next = 2;
151
165
  break;
152
166
  }
153
- throw new Error('Data provider not set');
167
+ return _context3.abrupt("return", Promise.resolve([]));
154
168
  case 2:
169
+ if (this.dataProvider) {
170
+ _context3.next = 4;
171
+ break;
172
+ }
173
+ throw new Error('Data provider not set');
174
+ case 4:
155
175
  // Don't fetch for not_found error since the source is already deleted
156
176
  nodesToFetch = [], blocksWithNotFoundError = [];
157
177
  syncBlockNodes.forEach(function (node) {
@@ -162,16 +182,16 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
162
182
  nodesToFetch.push(node);
163
183
  }
164
184
  });
165
- _context3.next = 6;
185
+ _context3.next = 8;
166
186
  return this.dataProvider.fetchNodesData(nodesToFetch);
167
- case 6:
187
+ case 8:
168
188
  data = _context3.sent;
169
189
  if (data) {
170
- _context3.next = 9;
190
+ _context3.next = 11;
171
191
  break;
172
192
  }
173
193
  throw new Error('Failed to fetch sync block node data');
174
- case 9:
194
+ case 11:
175
195
  resolvedData = [];
176
196
  data.forEach(function (syncBlockInstance) {
177
197
  var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
@@ -194,7 +214,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
194
214
  }
195
215
  });
196
216
  return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
197
- case 12:
217
+ case 14:
198
218
  case "end":
199
219
  return _context3.stop();
200
220
  }
@@ -204,7 +224,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
204
224
  return _fetchSyncBlocksData.apply(this, arguments);
205
225
  }
206
226
  return fetchSyncBlocksData;
207
- }()
227
+ }())
208
228
  }, {
209
229
  key: "updateCache",
210
230
  value: function updateCache(syncBlock) {
@@ -341,28 +361,76 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
341
361
  return undefined;
342
362
  }
343
363
  var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
344
- parentDataProviders = _this$dataProvider$ge.parentDataProviders;
345
- if (!this.providerFactories.has(resourceId)) {
346
- // TODO: EDITOR-2771 - In follow up PR, create media & emoji providers per ref sync block
347
- // The media & emoji providers will be set later, once we get ref sync block data with page ID
348
- // So we need to keep the reference to the Provider Factory so we can then set media & emoji providers later
349
- this.providerFactories.set(resourceId, ProviderFactory.create({
350
- emojiProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.emojiProvider,
351
- mediaProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mediaProvider,
364
+ parentDataProviders = _this$dataProvider$ge.parentDataProviders,
365
+ providerCreator = _this$dataProvider$ge.providerCreator;
366
+ var providerFactory = this.providerFactories.get(resourceId);
367
+ if (!providerFactory) {
368
+ providerFactory = ProviderFactory.create({
352
369
  mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
353
370
  profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
354
371
  taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
355
- }));
372
+ });
373
+ this.providerFactories.set(resourceId, providerFactory);
374
+ }
375
+ if (providerCreator) {
376
+ this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
377
+ }
378
+ return providerFactory;
379
+ }
380
+ }, {
381
+ key: "retrieveDynamicProviders",
382
+ value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
383
+ if (!this.dataProvider) {
384
+ return;
385
+ }
386
+ var hasMediaProvider = providerFactory.hasProvider('mediaProvider');
387
+ var hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
388
+ if (hasMediaProvider && hasEmojiProvider) {
389
+ return;
390
+ }
391
+ var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo(this.syncBlockCache.get(resourceId));
392
+ if (!parentInfo) {
393
+ return;
394
+ }
395
+ var contentId = parentInfo.contentId,
396
+ contentProduct = parentInfo.contentProduct;
397
+ if (!hasMediaProvider) {
398
+ if (providerCreator.createMediaProvider && contentId && contentProduct) {
399
+ var mediaProvider = providerCreator.createMediaProvider({
400
+ contentProduct: contentProduct,
401
+ contentId: contentId
402
+ });
403
+ if (mediaProvider) {
404
+ providerFactory.setProvider('mediaProvider', mediaProvider);
405
+ }
406
+ }
407
+ }
408
+ if (!hasEmojiProvider) {
409
+ if (providerCreator.createEmojiProvider && contentId && contentProduct) {
410
+ var emojiProvider = providerCreator.createEmojiProvider({
411
+ contentProduct: contentProduct,
412
+ contentId: contentId
413
+ });
414
+ if (emojiProvider) {
415
+ providerFactory.setProvider('emojiProvider', emojiProvider);
416
+ }
417
+ }
356
418
  }
357
- return this.providerFactories.get(resourceId);
358
419
  }
359
420
  }, {
360
421
  key: "destroy",
361
422
  value: function destroy() {
423
+ this.dataProvider = undefined;
362
424
  this.syncBlockCache.clear();
363
425
  this.subscriptions.clear();
426
+ this.titleSubscriptions.clear();
364
427
  this.syncBlockURLRequests.clear();
365
428
  this.providerFactories.clear();
429
+ this.isRefreshingSubscriptions = false;
430
+ this.providerFactories.forEach(function (providerFactory) {
431
+ providerFactory.destroy();
432
+ });
433
+ this.providerFactories.clear();
366
434
  }
367
435
  }]);
368
436
  }();