@atlaskit/editor-synced-block-provider 2.9.0 → 2.10.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/cjs/hooks/useFetchSyncBlockData.js +3 -2
  3. package/dist/cjs/index.js +7 -6
  4. package/dist/cjs/providers/block-service/ari.js +34 -0
  5. package/dist/cjs/providers/block-service/blockServiceAPI.js +15 -1
  6. package/dist/cjs/providers/confluence/confluenceContentAPI.js +15 -0
  7. package/dist/cjs/providers/syncBlockProvider.js +82 -14
  8. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +26 -0
  9. package/dist/cjs/store-manager/syncBlockStoreManager.js +5 -0
  10. package/dist/cjs/utils/ari.js +3 -32
  11. package/dist/cjs/utils/sourceInfo.js +3 -3
  12. package/dist/es2019/hooks/useFetchSyncBlockData.js +3 -2
  13. package/dist/es2019/index.js +2 -1
  14. package/dist/es2019/providers/block-service/ari.js +28 -0
  15. package/dist/es2019/providers/block-service/blockServiceAPI.js +13 -1
  16. package/dist/es2019/providers/confluence/confluenceContentAPI.js +14 -1
  17. package/dist/es2019/providers/syncBlockProvider.js +78 -12
  18. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +25 -0
  19. package/dist/es2019/store-manager/syncBlockStoreManager.js +3 -0
  20. package/dist/es2019/utils/ari.js +2 -31
  21. package/dist/es2019/utils/sourceInfo.js +3 -3
  22. package/dist/esm/hooks/useFetchSyncBlockData.js +3 -2
  23. package/dist/esm/index.js +2 -1
  24. package/dist/esm/providers/block-service/ari.js +28 -0
  25. package/dist/esm/providers/block-service/blockServiceAPI.js +15 -1
  26. package/dist/esm/providers/confluence/confluenceContentAPI.js +16 -1
  27. package/dist/esm/providers/syncBlockProvider.js +82 -14
  28. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +26 -0
  29. package/dist/esm/store-manager/syncBlockStoreManager.js +5 -0
  30. package/dist/esm/utils/ari.js +2 -31
  31. package/dist/esm/utils/sourceInfo.js +3 -3
  32. package/dist/types/hooks/useFetchSyncBlockData.d.ts +2 -0
  33. package/dist/types/index.d.ts +2 -1
  34. package/dist/types/providers/block-service/ari.d.ts +13 -0
  35. package/dist/types/providers/block-service/blockServiceAPI.d.ts +3 -2
  36. package/dist/types/providers/confluence/confluenceContentAPI.d.ts +3 -2
  37. package/dist/types/providers/syncBlockProvider.d.ts +59 -3
  38. package/dist/types/providers/types.d.ts +20 -0
  39. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +3 -0
  40. package/dist/types/store-manager/syncBlockStoreManager.d.ts +2 -0
  41. package/dist/types/utils/ari.d.ts +0 -15
  42. package/dist/types/utils/sourceInfo.d.ts +1 -1
  43. package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +2 -0
  44. package/dist/types-ts4.5/index.d.ts +2 -1
  45. package/dist/types-ts4.5/providers/block-service/ari.d.ts +13 -0
  46. package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +3 -2
  47. package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +3 -2
  48. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +59 -3
  49. package/dist/types-ts4.5/providers/types.d.ts +20 -0
  50. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +3 -0
  51. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +2 -0
  52. package/dist/types-ts4.5/utils/ari.d.ts +0 -15
  53. package/dist/types-ts4.5/utils/sourceInfo.d.ts +1 -1
  54. package/package.json +3 -8
@@ -2,22 +2,56 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { useMemo } from 'react';
3
3
  import { SyncBlockError } from '../common/types';
4
4
  import { SyncBlockDataProvider } from '../providers/types';
5
- import { getLocalIdFromAri, getPageARIFromResourceId } from '../utils/ari';
6
5
  import { fetchSourceInfo } from '../utils/sourceInfo';
7
6
  export class SyncBlockProvider extends SyncBlockDataProvider {
8
- constructor(fetchProvider, writeProvider, sourceId) {
7
+ // the source document ARI; that the source sync block is on.
8
+
9
+ /**
10
+ * Constructor for the SyncBlockProvider
11
+ *
12
+ * @param fetchProvider
13
+ * @param writeProvider
14
+ * @param sourceId
15
+ * @param nestedRendererDataProviders
16
+ */
17
+ constructor(fetchProvider, writeProvider, sourceId, providerOptions) {
9
18
  super();
10
19
  _defineProperty(this, "name", 'syncBlockProvider');
11
20
  this.fetchProvider = fetchProvider;
12
21
  this.writeProvider = writeProvider;
13
22
  this.sourceId = sourceId;
23
+ this.providerOptions = providerOptions;
14
24
  }
25
+
26
+ /**
27
+ * Check if the node is supported by the provider
28
+ *
29
+ * @param node
30
+ *
31
+ * @returns True if the node is supported, false otherwise
32
+ */
15
33
  isNodeSupported(node) {
16
- return node.type === 'syncBlock';
34
+ return node.type === 'syncBlock' || node.type === 'bodiedSyncBlock';
17
35
  }
36
+
37
+ /**
38
+ * Get the data key for the node
39
+ *
40
+ * @param node
41
+ *
42
+ * @returns The data key
43
+ */
18
44
  nodeDataKey(node) {
19
45
  return node.attrs.localId;
20
46
  }
47
+
48
+ /**
49
+ * Fetch the data from the fetch provider
50
+ *
51
+ * @param nodes
52
+ *
53
+ * @returns Array of {resourceId?: string, error?: string}.
54
+ */
21
55
  fetchNodesData(nodes) {
22
56
  const resourceIdSet = new Set(nodes.map(node => node.attrs.resourceId));
23
57
  const resourceIds = [...resourceIdSet];
@@ -38,6 +72,7 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
38
72
  }
39
73
 
40
74
  /**
75
+ * Write the data to the write provider
41
76
  *
42
77
  * @param nodes
43
78
  * @param data
@@ -62,6 +97,14 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
62
97
  }
63
98
  });
64
99
  }
100
+
101
+ /**
102
+ * Delete the data from the write provider
103
+ *
104
+ * @param resourceIds
105
+ *
106
+ * @returns Array of {resourceId?: string, error?: string}.
107
+ */
65
108
  async deleteNodesData(resourceIds) {
66
109
  const results = await Promise.allSettled(resourceIds.map(resourceId => this.writeProvider.deleteData(resourceId)));
67
110
  return results.map((result, index) => {
@@ -76,10 +119,27 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
76
119
  }
77
120
  });
78
121
  }
122
+
123
+ /**
124
+ * Get the source id
125
+ *
126
+ * @returns The source id
127
+ */
79
128
  getSourceId() {
80
129
  return this.sourceId;
81
130
  }
131
+
132
+ /**
133
+ * Retrieve the source info from the source id
134
+ *
135
+ * @param node
136
+ *
137
+ * @returns The source info
138
+ */
82
139
  retrieveSyncBlockSourceInfo(node) {
140
+ // with content API, this is the concatenation of the page ARI and the block's localId.
141
+ // with block service, this is the ARI of the block.
142
+ // this can be cleaned up from the specific providers and placed here after platform_synced_blocks_block_service_provider
83
143
  const {
84
144
  resourceId
85
145
  } = node.attrs;
@@ -87,24 +147,30 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
87
147
  let sourceLocalId;
88
148
  if (resourceId && typeof resourceId === 'string') {
89
149
  try {
90
- pageARI = getPageARIFromResourceId(resourceId);
150
+ const fetchData = this.fetchProvider.retrieveSourceInfoFetchData(resourceId, this.sourceId);
151
+ pageARI = fetchData.pageARI;
152
+ sourceLocalId = fetchData.sourceLocalId;
91
153
  } catch (error) {
92
154
  return Promise.reject(error);
93
155
  }
94
- try {
95
- sourceLocalId = getLocalIdFromAri(resourceId);
96
- } catch (error) {
97
- // EDITOR-1921: log analytic here, safe to continue
98
- }
99
156
  }
100
157
  return pageARI ? fetchSourceInfo(pageARI, sourceLocalId) : Promise.resolve(undefined);
101
158
  }
102
159
  generateResourceId(sourceId, localId) {
103
160
  return this.writeProvider.generateResourceId(sourceId, localId);
104
161
  }
162
+
163
+ /**
164
+ * Get the synced block renderer provider options
165
+ *
166
+ * @returns The synced block renderer provider options
167
+ */
168
+ getSyncedBlockRendererProviderOptions() {
169
+ return this.providerOptions;
170
+ }
105
171
  }
106
- export const useMemoizedSyncedBlockProvider = (fetchProvider, writeProvider, sourceId) => {
172
+ export const useMemoizedSyncedBlockProvider = (fetchProvider, writeProvider, sourceId, providerOptions) => {
107
173
  return useMemo(() => {
108
- return new SyncBlockProvider(fetchProvider, writeProvider, sourceId);
109
- }, [fetchProvider, writeProvider, sourceId]);
174
+ return new SyncBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions);
175
+ }, [fetchProvider, writeProvider, sourceId, providerOptions]);
110
176
  };
@@ -1,4 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
2
3
  import { SyncBlockError } from '../common/types';
3
4
  import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
4
5
  import { createSyncBlockNode } from '../utils/utils';
@@ -10,6 +11,7 @@ export class ReferenceSyncBlockStoreManager {
10
11
  this.titleSubscriptions = new Map();
11
12
  this.dataProvider = dataProvider;
12
13
  this.syncBlockURLRequests = new Map();
14
+ this.providerFactories = new Map();
13
15
  }
14
16
 
15
17
  /**
@@ -134,6 +136,7 @@ export class ReferenceSyncBlockStoreManager {
134
136
  }
135
137
  deleteFromCache(resourceId) {
136
138
  this.syncBlockCache.delete(resourceId);
139
+ this.providerFactories.delete(resourceId);
137
140
  }
138
141
  subscribeToSyncBlock(resourceId, localId, callback) {
139
142
  // add to subscriptions map
@@ -227,9 +230,31 @@ export class ReferenceSyncBlockStoreManager {
227
230
  }
228
231
  return (_syncBlock$data = syncBlock.data) === null || _syncBlock$data === void 0 ? void 0 : _syncBlock$data.sourceURL;
229
232
  }
233
+ getProviderFactory(resourceId) {
234
+ if (!this.dataProvider) {
235
+ return undefined;
236
+ }
237
+ const {
238
+ parentDataProviders
239
+ } = this.dataProvider.getSyncedBlockRendererProviderOptions();
240
+ if (!this.providerFactories.has(resourceId)) {
241
+ // TODO: EDITOR-2771 - In follow up PR, create media & emoji providers per ref sync block
242
+ // The media & emoji providers will be set later, once we get ref sync block data with page ID
243
+ // So we need to keep the reference to the Provider Factory so we can then set media & emoji providers later
244
+ this.providerFactories.set(resourceId, ProviderFactory.create({
245
+ emojiProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.emojiProvider,
246
+ mediaProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mediaProvider,
247
+ mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
248
+ profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
249
+ taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
250
+ }));
251
+ }
252
+ return this.providerFactories.get(resourceId);
253
+ }
230
254
  destroy() {
231
255
  this.syncBlockCache.clear();
232
256
  this.subscriptions.clear();
233
257
  this.syncBlockURLRequests.clear();
258
+ this.providerFactories.clear();
234
259
  }
235
260
  }
@@ -122,6 +122,9 @@ export class SyncBlockStoreManager {
122
122
  // only applicable to source sync block, for now (will be refactored further)
123
123
  this.sourceSyncBlockStoreManager.rebaseTransaction(incomingTr, state);
124
124
  }
125
+ getReferenceSyncBlockProviderFactory(resourceId) {
126
+ return this.referenceSyncBlockStoreManager.getProviderFactory(resourceId);
127
+ }
125
128
  destroy() {
126
129
  this.referenceSyncBlockStoreManager.destroy();
127
130
  }
@@ -1,6 +1,8 @@
1
1
  /* eslint-disable require-unicode-regexp */
2
2
 
3
3
  export const getConfluencePageAri = (pageId, cloudId, pageType = 'page') => `ari:cloud:confluence:${cloudId}:${pageType}/${pageId}`;
4
+
5
+ // For extracting from Page ARI and also the content property's version of resourceId
4
6
  export const getPageIdAndTypeFromAri = ari => {
5
7
  const match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
6
8
  if (match !== null && match !== void 0 && match[2]) {
@@ -27,35 +29,4 @@ export const getPageARIFromResourceId = resourceId => {
27
29
  };
28
30
  export const resourceIdFromSourceAndLocalId = (sourceId, localId) => {
29
31
  return sourceId + '/' + localId;
30
- };
31
-
32
- /**
33
- * For the following functions, they are used for the block service API provider.
34
- * The resourceId/blockResourceId always refers to the block ARI.
35
- */
36
-
37
- /**
38
- * @param sourceId - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
39
- * @param localId - the localId of the block node. A randomly generated UUID
40
- * @returns the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
41
- */
42
- export const blockResourceIdFromSourceAndLocalId = (sourceId, localId) => {
43
- const match = sourceId.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/.*/);
44
- if (!(match !== null && match !== void 0 && match[1])) {
45
- throw new Error(`Invalid source ARI: ${sourceId}`);
46
- }
47
- const cloudId = match[1];
48
- return `ari:cloud:blocks:${cloudId}:synced-block/${localId}`;
49
- };
50
-
51
- /**
52
- * @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
53
- * @returns the localId of the block node. A randomly generated UUID
54
- */
55
- export const getLocalIdFromResourceId = ari => {
56
- const match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
57
- if (match !== null && match !== void 0 && match[2]) {
58
- return match[2];
59
- }
60
- throw new Error(`Invalid page ARI: ${ari}`);
61
32
  };
@@ -52,13 +52,13 @@ const getSourceInfo = async ari => {
52
52
  }
53
53
  return await response.json();
54
54
  };
55
- export const fetchSourceInfo = async (ari, localId) => {
55
+ export const fetchSourceInfo = async (pageAri, localId) => {
56
56
  try {
57
57
  var _response$data, _response$data$conten, _response$data$conten2, _contentData$space;
58
58
  const {
59
59
  type: pageType
60
- } = getPageIdAndTypeFromAri(ari);
61
- const response = await getSourceInfo(ari);
60
+ } = getPageIdAndTypeFromAri(pageAri);
61
+ const response = await getSourceInfo(pageAri);
62
62
  const contentData = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : (_response$data$conten = _response$data.content) === null || _response$data$conten === void 0 ? void 0 : (_response$data$conten2 = _response$data$conten.nodes) === null || _response$data$conten2 === void 0 ? void 0 : _response$data$conten2[0];
63
63
  if (!contentData) {
64
64
  throw new Error(`Failed to get content data`);
@@ -65,8 +65,9 @@ export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resou
65
65
  };
66
66
  }, [localId, referenceSyncBlockStoreManager, resourceId]);
67
67
  return {
68
- syncBlockInstance: syncBlockInstance,
69
68
  isLoading: isLoading,
70
- reloadData: reloadData
69
+ providerFactory: referenceSyncBlockStoreManager.getProviderFactory(resourceId || ''),
70
+ reloadData: reloadData,
71
+ syncBlockInstance: syncBlockInstance
71
72
  };
72
73
  };
package/dist/esm/index.js CHANGED
@@ -5,11 +5,12 @@ export { SyncBlockError } from './common/types';
5
5
  export { useFetchSyncBlockData } from './hooks/useFetchSyncBlockData';
6
6
  export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
7
7
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
8
+ export { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from './providers/block-service/ari';
8
9
  export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/blockServiceAPI';
9
10
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
10
11
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
11
12
  export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
12
13
  export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
13
- export { blockResourceIdFromSourceAndLocalId, getConfluencePageAri, getLocalIdFromAri, getLocalIdFromResourceId, getPageARIFromResourceId, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from './utils/ari';
14
+ export { getConfluencePageAri, getLocalIdFromAri, getPageARIFromResourceId, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from './utils/ari';
14
15
  export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode } from './utils/utils';
15
16
  export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
@@ -0,0 +1,28 @@
1
+ /* eslint-disable require-unicode-regexp */
2
+ /**
3
+ * Generates a unique block ARI from a source ARI and a local ID.
4
+ * @param sourceId - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
5
+ * @param localId - the localId of the block node. A randomly generated UUID
6
+ * @returns the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
7
+ */
8
+ export var blockResourceIdFromSourceAndLocalId = function blockResourceIdFromSourceAndLocalId(sourceId, localId) {
9
+ var match = sourceId.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/.*/);
10
+ if (!(match !== null && match !== void 0 && match[1])) {
11
+ throw new Error("Invalid source ARI: ".concat(sourceId));
12
+ }
13
+ var cloudId = match[1];
14
+ return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(localId);
15
+ };
16
+
17
+ /**
18
+ * Extracts the local ID from a block ARI.
19
+ * @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
20
+ * @returns the localId of the block node. A randomly generated UUID
21
+ */
22
+ export var getLocalIdFromResourceId = function getLocalIdFromResourceId(ari) {
23
+ var match = ari.match(/ari:cloud:blocks:[^:]+:synced-block\/([a-zA-Z0-9-]+)/);
24
+ if (match !== null && match !== void 0 && match[1]) {
25
+ return match[1];
26
+ }
27
+ throw new Error("Invalid page ARI: ".concat(ari));
28
+ };
@@ -4,9 +4,9 @@ import _createClass from "@babel/runtime/helpers/createClass";
4
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
5
  import { useMemo } from 'react';
6
6
  import { SyncBlockError } from '../../common/types';
7
- import { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from '../../utils/ari';
8
7
  import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../utils/blockService';
9
8
  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:
@@ -89,6 +89,20 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
89
89
  }
90
90
  return fetchData;
91
91
  }()
92
+ }, {
93
+ key: "retrieveSourceInfoFetchData",
94
+ value: function retrieveSourceInfoFetchData(resourceId, pageARI) {
95
+ var sourceLocalId;
96
+ try {
97
+ sourceLocalId = getLocalIdFromResourceId(resourceId);
98
+ } catch (error) {
99
+ // EDITOR-1921: log analytic here, safe to continue
100
+ }
101
+ return {
102
+ pageARI: pageARI,
103
+ sourceLocalId: sourceLocalId
104
+ };
105
+ }
92
106
  }]);
93
107
  }();
94
108
  /**
@@ -6,7 +6,7 @@ import _typeof from "@babel/runtime/helpers/typeof";
6
6
  import _regeneratorRuntime from "@babel/runtime/regenerator";
7
7
  import { useMemo } from 'react';
8
8
  import { SyncBlockError } from '../../common/types';
9
- import { getLocalIdFromAri, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from '../../utils/ari';
9
+ import { getLocalIdFromAri, getPageARIFromResourceId, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from '../../utils/ari';
10
10
  import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../utils/contentProperty';
11
11
  import { stringifyError } from '../../utils/errorHandling';
12
12
  import { isBlogPageType } from '../../utils/utils';
@@ -128,6 +128,21 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
128
128
  }
129
129
  return fetchData;
130
130
  }()
131
+ }, {
132
+ key: "retrieveSourceInfoFetchData",
133
+ value: function retrieveSourceInfoFetchData(resourceId) {
134
+ var pageARI = getPageARIFromResourceId(resourceId);
135
+ var sourceLocalId;
136
+ try {
137
+ sourceLocalId = getLocalIdFromAri(resourceId);
138
+ } catch (error) {
139
+ // EDITOR-1921: log analytic here, safe to continue
140
+ }
141
+ return {
142
+ pageARI: pageARI,
143
+ sourceLocalId: sourceLocalId
144
+ };
145
+ }
131
146
  }]);
132
147
  }();
133
148
  /**
@@ -12,10 +12,19 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
12
12
  import { useMemo } from 'react';
13
13
  import { SyncBlockError } from '../common/types';
14
14
  import { SyncBlockDataProvider } from '../providers/types';
15
- import { getLocalIdFromAri, getPageARIFromResourceId } from '../utils/ari';
16
15
  import { fetchSourceInfo } from '../utils/sourceInfo';
17
16
  export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
18
- function SyncBlockProvider(fetchProvider, writeProvider, sourceId) {
17
+ // the source document ARI; that the source sync block is on.
18
+
19
+ /**
20
+ * Constructor for the SyncBlockProvider
21
+ *
22
+ * @param fetchProvider
23
+ * @param writeProvider
24
+ * @param sourceId
25
+ * @param nestedRendererDataProviders
26
+ */
27
+ function SyncBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
19
28
  var _this;
20
29
  _classCallCheck(this, SyncBlockProvider);
21
30
  _this = _callSuper(this, SyncBlockProvider);
@@ -23,19 +32,44 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
23
32
  _this.fetchProvider = fetchProvider;
24
33
  _this.writeProvider = writeProvider;
25
34
  _this.sourceId = sourceId;
35
+ _this.providerOptions = providerOptions;
26
36
  return _this;
27
37
  }
38
+
39
+ /**
40
+ * Check if the node is supported by the provider
41
+ *
42
+ * @param node
43
+ *
44
+ * @returns True if the node is supported, false otherwise
45
+ */
28
46
  _inherits(SyncBlockProvider, _SyncBlockDataProvide);
29
47
  return _createClass(SyncBlockProvider, [{
30
48
  key: "isNodeSupported",
31
49
  value: function isNodeSupported(node) {
32
- return node.type === 'syncBlock';
50
+ return node.type === 'syncBlock' || node.type === 'bodiedSyncBlock';
33
51
  }
52
+
53
+ /**
54
+ * Get the data key for the node
55
+ *
56
+ * @param node
57
+ *
58
+ * @returns The data key
59
+ */
34
60
  }, {
35
61
  key: "nodeDataKey",
36
62
  value: function nodeDataKey(node) {
37
63
  return node.attrs.localId;
38
64
  }
65
+
66
+ /**
67
+ * Fetch the data from the fetch provider
68
+ *
69
+ * @param nodes
70
+ *
71
+ * @returns Array of {resourceId?: string, error?: string}.
72
+ */
39
73
  }, {
40
74
  key: "fetchNodesData",
41
75
  value: function fetchNodesData(nodes) {
@@ -63,6 +97,7 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
63
97
  }
64
98
 
65
99
  /**
100
+ * Write the data to the write provider
66
101
  *
67
102
  * @param nodes
68
103
  * @param data
@@ -107,10 +142,18 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
107
142
  return _writeNodesData.apply(this, arguments);
108
143
  }
109
144
  return writeNodesData;
110
- }())
145
+ }()
146
+ /**
147
+ * Delete the data from the write provider
148
+ *
149
+ * @param resourceIds
150
+ *
151
+ * @returns Array of {resourceId?: string, error?: string}.
152
+ */
153
+ )
111
154
  }, {
112
155
  key: "deleteNodesData",
113
- value: function () {
156
+ value: (function () {
114
157
  var _deleteNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceIds) {
115
158
  var _this4 = this;
116
159
  var results;
@@ -145,28 +188,42 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
145
188
  }
146
189
  return deleteNodesData;
147
190
  }()
191
+ /**
192
+ * Get the source id
193
+ *
194
+ * @returns The source id
195
+ */
196
+ )
148
197
  }, {
149
198
  key: "getSourceId",
150
199
  value: function getSourceId() {
151
200
  return this.sourceId;
152
201
  }
202
+
203
+ /**
204
+ * Retrieve the source info from the source id
205
+ *
206
+ * @param node
207
+ *
208
+ * @returns The source info
209
+ */
153
210
  }, {
154
211
  key: "retrieveSyncBlockSourceInfo",
155
212
  value: function retrieveSyncBlockSourceInfo(node) {
213
+ // with content API, this is the concatenation of the page ARI and the block's localId.
214
+ // with block service, this is the ARI of the block.
215
+ // this can be cleaned up from the specific providers and placed here after platform_synced_blocks_block_service_provider
156
216
  var resourceId = node.attrs.resourceId;
157
217
  var pageARI;
158
218
  var sourceLocalId;
159
219
  if (resourceId && typeof resourceId === 'string') {
160
220
  try {
161
- pageARI = getPageARIFromResourceId(resourceId);
221
+ var fetchData = this.fetchProvider.retrieveSourceInfoFetchData(resourceId, this.sourceId);
222
+ pageARI = fetchData.pageARI;
223
+ sourceLocalId = fetchData.sourceLocalId;
162
224
  } catch (error) {
163
225
  return Promise.reject(error);
164
226
  }
165
- try {
166
- sourceLocalId = getLocalIdFromAri(resourceId);
167
- } catch (error) {
168
- // EDITOR-1921: log analytic here, safe to continue
169
- }
170
227
  }
171
228
  return pageARI ? fetchSourceInfo(pageARI, sourceLocalId) : Promise.resolve(undefined);
172
229
  }
@@ -175,10 +232,21 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
175
232
  value: function generateResourceId(sourceId, localId) {
176
233
  return this.writeProvider.generateResourceId(sourceId, localId);
177
234
  }
235
+
236
+ /**
237
+ * Get the synced block renderer provider options
238
+ *
239
+ * @returns The synced block renderer provider options
240
+ */
241
+ }, {
242
+ key: "getSyncedBlockRendererProviderOptions",
243
+ value: function getSyncedBlockRendererProviderOptions() {
244
+ return this.providerOptions;
245
+ }
178
246
  }]);
179
247
  }(SyncBlockDataProvider);
180
- export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId) {
248
+ export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
181
249
  return useMemo(function () {
182
- return new SyncBlockProvider(fetchProvider, writeProvider, sourceId);
183
- }, [fetchProvider, writeProvider, sourceId]);
250
+ return new SyncBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions);
251
+ }, [fetchProvider, writeProvider, sourceId, providerOptions]);
184
252
  };
@@ -9,6 +9,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
9
9
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
10
10
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
11
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
+ import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
12
13
  import { SyncBlockError } from '../common/types';
13
14
  import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
14
15
  import { createSyncBlockNode } from '../utils/utils';
@@ -21,6 +22,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
21
22
  this.titleSubscriptions = new Map();
22
23
  this.dataProvider = dataProvider;
23
24
  this.syncBlockURLRequests = new Map();
25
+ this.providerFactories = new Map();
24
26
  }
25
27
 
26
28
  /**
@@ -236,6 +238,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
236
238
  key: "deleteFromCache",
237
239
  value: function deleteFromCache(resourceId) {
238
240
  this.syncBlockCache.delete(resourceId);
241
+ this.providerFactories.delete(resourceId);
239
242
  }
240
243
  }, {
241
244
  key: "subscribeToSyncBlock",
@@ -331,12 +334,35 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
331
334
  }
332
335
  return (_syncBlock$data = syncBlock.data) === null || _syncBlock$data === void 0 ? void 0 : _syncBlock$data.sourceURL;
333
336
  }
337
+ }, {
338
+ key: "getProviderFactory",
339
+ value: function getProviderFactory(resourceId) {
340
+ if (!this.dataProvider) {
341
+ return undefined;
342
+ }
343
+ 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,
352
+ mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
353
+ profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
354
+ taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
355
+ }));
356
+ }
357
+ return this.providerFactories.get(resourceId);
358
+ }
334
359
  }, {
335
360
  key: "destroy",
336
361
  value: function destroy() {
337
362
  this.syncBlockCache.clear();
338
363
  this.subscriptions.clear();
339
364
  this.syncBlockURLRequests.clear();
365
+ this.providerFactories.clear();
340
366
  }
341
367
  }]);
342
368
  }();
@@ -165,6 +165,11 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
165
165
  // only applicable to source sync block, for now (will be refactored further)
166
166
  this.sourceSyncBlockStoreManager.rebaseTransaction(incomingTr, state);
167
167
  }
168
+ }, {
169
+ key: "getReferenceSyncBlockProviderFactory",
170
+ value: function getReferenceSyncBlockProviderFactory(resourceId) {
171
+ return this.referenceSyncBlockStoreManager.getProviderFactory(resourceId);
172
+ }
168
173
  }, {
169
174
  key: "destroy",
170
175
  value: function destroy() {