@atlaskit/editor-synced-block-provider 2.15.3 → 2.15.5
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.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/index.js +20 -8
- package/dist/cjs/providers/block-service/blockServiceAPI.js +2 -1
- package/dist/cjs/providers/syncBlockProvider.js +16 -10
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +26 -16
- package/dist/cjs/store-manager/syncBlockStoreManager.js +9 -2
- package/dist/cjs/utils/utils.js +19 -1
- package/dist/es2019/index.js +5 -3
- package/dist/es2019/providers/block-service/blockServiceAPI.js +3 -2
- package/dist/es2019/providers/syncBlockProvider.js +11 -9
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +23 -14
- package/dist/es2019/store-manager/syncBlockStoreManager.js +8 -1
- package/dist/es2019/utils/utils.js +18 -0
- package/dist/esm/index.js +5 -3
- package/dist/esm/providers/block-service/blockServiceAPI.js +2 -1
- package/dist/esm/providers/syncBlockProvider.js +16 -10
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +26 -16
- package/dist/esm/store-manager/syncBlockStoreManager.js +8 -1
- package/dist/esm/utils/utils.js +18 -0
- package/dist/types/index.d.ts +4 -3
- package/dist/types/providers/syncBlockProvider.d.ts +2 -1
- package/dist/types/providers/types.d.ts +1 -0
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +4 -3
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +1 -0
- package/dist/types/utils/utils.d.ts +5 -1
- package/dist/types-ts4.5/index.d.ts +4 -3
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -1
- package/dist/types-ts4.5/providers/types.d.ts +1 -0
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +4 -3
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +1 -0
- package/dist/types-ts4.5/utils/utils.d.ts +5 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 2.15.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`a4ed9f55162ae`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a4ed9f55162ae) -
|
|
8
|
+
EDITOR-3960 Refactor Synced Blocks initialization to remove multiple re-renders and duplicated
|
|
9
|
+
fetches
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 2.15.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [`a41bf96788d92`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a41bf96788d92) -
|
|
17
|
+
[ux] Fix sync block permissions denied error to show the correct state
|
|
18
|
+
|
|
3
19
|
## 2.15.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,12 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "ReferenceSyncBlockStoreManager", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
6
|
Object.defineProperty(exports, "SyncBlockError", {
|
|
13
7
|
enumerable: true,
|
|
14
8
|
get: function get() {
|
|
@@ -63,6 +57,12 @@ Object.defineProperty(exports, "fetchConfluencePageInfo", {
|
|
|
63
57
|
return _sourceInfo.fetchConfluencePageInfo;
|
|
64
58
|
}
|
|
65
59
|
});
|
|
60
|
+
Object.defineProperty(exports, "fetchErrorPayload", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function get() {
|
|
63
|
+
return _errorHandling.fetchErrorPayload;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
66
|
Object.defineProperty(exports, "fetchReferences", {
|
|
67
67
|
enumerable: true,
|
|
68
68
|
get: function get() {
|
|
@@ -87,6 +87,12 @@ Object.defineProperty(exports, "getConfluencePageAri", {
|
|
|
87
87
|
return _ari2.getConfluencePageAri;
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
+
Object.defineProperty(exports, "getContentIdAndProductFromResourceId", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function get() {
|
|
93
|
+
return _utils.getContentIdAndProductFromResourceId;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
90
96
|
Object.defineProperty(exports, "getLocalIdFromBlockResourceId", {
|
|
91
97
|
enumerable: true,
|
|
92
98
|
get: function get() {
|
|
@@ -159,6 +165,12 @@ Object.defineProperty(exports, "useMemoizedContentAPIProviders", {
|
|
|
159
165
|
return _confluenceContentAPI.useMemoizedContentAPIProviders;
|
|
160
166
|
}
|
|
161
167
|
});
|
|
168
|
+
Object.defineProperty(exports, "useMemoizedSyncBlockStoreManager", {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
get: function get() {
|
|
171
|
+
return _syncBlockStoreManager.useMemoizedSyncBlockStoreManager;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
162
174
|
Object.defineProperty(exports, "useMemoizedSyncedBlockProvider", {
|
|
163
175
|
enumerable: true,
|
|
164
176
|
get: function get() {
|
|
@@ -176,7 +188,7 @@ var _blockServiceAPI = require("./providers/block-service/blockServiceAPI");
|
|
|
176
188
|
var _confluenceContentAPI = require("./providers/confluence/confluenceContentAPI");
|
|
177
189
|
var _sourceInfo = require("./clients/confluence/sourceInfo");
|
|
178
190
|
var _syncBlockProvider = require("./providers/syncBlockProvider");
|
|
179
|
-
var _referenceSyncBlockStoreManager = require("./store-manager/referenceSyncBlockStoreManager");
|
|
180
191
|
var _syncBlockStoreManager = require("./store-manager/syncBlockStoreManager");
|
|
181
192
|
var _resolveSyncBlockInstance = require("./utils/resolveSyncBlockInstance");
|
|
182
|
-
var _utils = require("./utils/utils");
|
|
193
|
+
var _utils = require("./utils/utils");
|
|
194
|
+
var _errorHandling = require("./utils/errorHandling");
|
|
@@ -386,7 +386,8 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
386
386
|
blockAri: (0, _ari.generateBlockAriFromReference)(_this.sourceAri, block.resourceId),
|
|
387
387
|
blockInstanceId: block.localId
|
|
388
388
|
};
|
|
389
|
-
},
|
|
389
|
+
}),
|
|
390
|
+
noContent: noContent
|
|
390
391
|
});
|
|
391
392
|
case 3:
|
|
392
393
|
return _context6.abrupt("return", {
|
|
@@ -32,7 +32,7 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
32
32
|
* @param sourceId
|
|
33
33
|
* @param nestedRendererDataProviders
|
|
34
34
|
*/
|
|
35
|
-
function SyncBlockProvider(fetchProvider, writeProvider, sourceId
|
|
35
|
+
function SyncBlockProvider(fetchProvider, writeProvider, sourceId) {
|
|
36
36
|
var _this;
|
|
37
37
|
(0, _classCallCheck2.default)(this, SyncBlockProvider);
|
|
38
38
|
_this = _callSuper(this, SyncBlockProvider);
|
|
@@ -40,11 +40,16 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
40
40
|
_this.fetchProvider = fetchProvider;
|
|
41
41
|
_this.writeProvider = writeProvider;
|
|
42
42
|
_this.sourceId = sourceId;
|
|
43
|
-
_this.providerOptions =
|
|
43
|
+
_this.providerOptions = {};
|
|
44
44
|
return _this;
|
|
45
45
|
}
|
|
46
46
|
(0, _inherits2.default)(SyncBlockProvider, _SyncBlockDataProvide);
|
|
47
47
|
return (0, _createClass2.default)(SyncBlockProvider, [{
|
|
48
|
+
key: "setProviderOptions",
|
|
49
|
+
value: function setProviderOptions(providerOptions) {
|
|
50
|
+
this.providerOptions = providerOptions;
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
48
53
|
key: "getProduct",
|
|
49
54
|
value: function getProduct() {
|
|
50
55
|
return this.writeProvider.product;
|
|
@@ -304,12 +309,13 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
304
309
|
}]);
|
|
305
310
|
}(_types2.SyncBlockDataProvider);
|
|
306
311
|
var useMemoizedSyncedBlockProvider = exports.useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions, getSSRData) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
312
|
+
var syncBlockProvider = (0, _react.useMemo)(function () {
|
|
313
|
+
return new SyncBlockProvider(fetchProvider, writeProvider, sourceId);
|
|
314
|
+
}, [fetchProvider, writeProvider, sourceId]);
|
|
315
|
+
syncBlockProvider.setProviderOptions(providerOptions);
|
|
316
|
+
var ssrData = getSSRData ? getSSRData() : undefined;
|
|
317
|
+
if (ssrData) {
|
|
318
|
+
syncBlockProvider.setSSRData(ssrData);
|
|
319
|
+
}
|
|
320
|
+
return syncBlockProvider;
|
|
315
321
|
};
|
|
@@ -39,7 +39,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
39
39
|
this.subscriptions = new Map();
|
|
40
40
|
this.titleSubscriptions = new Map();
|
|
41
41
|
this.dataProvider = dataProvider;
|
|
42
|
-
this.
|
|
42
|
+
this.syncBlockFetchDataRequests = new Map();
|
|
43
|
+
this.syncBlockSourceInfoRequests = new Map();
|
|
43
44
|
this.providerFactories = new Map();
|
|
44
45
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
45
46
|
}
|
|
@@ -160,7 +161,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
160
161
|
if (!resourceId || !this.dataProvider) {
|
|
161
162
|
throw new Error('Data provider or resourceId not set');
|
|
162
163
|
}
|
|
163
|
-
if (this.
|
|
164
|
+
if (this.syncBlockSourceInfoRequests.get(resourceId)) {
|
|
164
165
|
return;
|
|
165
166
|
}
|
|
166
167
|
var existingSyncBlock = this.getFromCache(resourceId);
|
|
@@ -181,7 +182,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
181
182
|
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, (0, _errorHandling.getSourceInfoErrorPayload)('SourceAri, product or blockInstanceId missing'));
|
|
182
183
|
return;
|
|
183
184
|
}
|
|
184
|
-
this.
|
|
185
|
+
this.syncBlockSourceInfoRequests.set(resourceId, true);
|
|
185
186
|
this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent).then(function (sourceInfo) {
|
|
186
187
|
if (!sourceInfo) {
|
|
187
188
|
return;
|
|
@@ -194,7 +195,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
194
195
|
var _this$fireAnalyticsEv3;
|
|
195
196
|
(_this$fireAnalyticsEv3 = _this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(_this, (0, _errorHandling.getSourceInfoErrorPayload)(error.message));
|
|
196
197
|
}).finally(function () {
|
|
197
|
-
_this.
|
|
198
|
+
_this.syncBlockSourceInfoRequests.delete(resourceId);
|
|
198
199
|
});
|
|
199
200
|
} catch (error) {
|
|
200
201
|
var _this$fireAnalyticsEv4;
|
|
@@ -215,7 +216,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
215
216
|
value: (function () {
|
|
216
217
|
var _fetchSyncBlocksData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockNodes) {
|
|
217
218
|
var _this2 = this;
|
|
218
|
-
var nodesToFetch,
|
|
219
|
+
var nodesToFetch, data, resolvedData;
|
|
219
220
|
return _regenerator.default.wrap(function _callee2$(_context3) {
|
|
220
221
|
while (1) switch (_context3.prev = _context3.next) {
|
|
221
222
|
case 0:
|
|
@@ -223,7 +224,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
223
224
|
_context3.next = 2;
|
|
224
225
|
break;
|
|
225
226
|
}
|
|
226
|
-
return _context3.abrupt("return"
|
|
227
|
+
return _context3.abrupt("return");
|
|
227
228
|
case 2:
|
|
228
229
|
if (this.dataProvider) {
|
|
229
230
|
_context3.next = 4;
|
|
@@ -232,18 +233,27 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
232
233
|
throw new Error('Data provider not set');
|
|
233
234
|
case 4:
|
|
234
235
|
// Don't fetch for not_found error since the source is already deleted
|
|
235
|
-
nodesToFetch = []
|
|
236
|
+
nodesToFetch = [];
|
|
236
237
|
syncBlockNodes.forEach(function (node) {
|
|
238
|
+
if (_this2.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
237
241
|
var existingSyncBlock = _this2.getFromCache(node.attrs.resourceId);
|
|
238
242
|
if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.error) === _types.SyncBlockError.NotFound) {
|
|
239
|
-
|
|
240
|
-
} else {
|
|
241
|
-
nodesToFetch.push(node);
|
|
243
|
+
return;
|
|
242
244
|
}
|
|
245
|
+
nodesToFetch.push(node);
|
|
243
246
|
});
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
+
nodesToFetch.forEach(function (node) {
|
|
248
|
+
_this2.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
|
|
249
|
+
});
|
|
250
|
+
_context3.next = 9;
|
|
251
|
+
return this.dataProvider.fetchNodesData(nodesToFetch).finally(function () {
|
|
252
|
+
nodesToFetch.forEach(function (node) {
|
|
253
|
+
_this2.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
case 9:
|
|
247
257
|
data = _context3.sent;
|
|
248
258
|
resolvedData = [];
|
|
249
259
|
data.forEach(function (syncBlockInstance) {
|
|
@@ -263,7 +273,6 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
263
273
|
}
|
|
264
274
|
_this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
265
275
|
});
|
|
266
|
-
return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
|
|
267
276
|
case 12:
|
|
268
277
|
case "end":
|
|
269
278
|
return _context3.stop();
|
|
@@ -527,7 +536,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
527
536
|
|
|
528
537
|
/**
|
|
529
538
|
* Update reference synced blocks on the document with the BE
|
|
530
|
-
*
|
|
539
|
+
*
|
|
531
540
|
* @returns true if the reference synced blocks are updated successfully, false otherwise
|
|
532
541
|
*/
|
|
533
542
|
}, {
|
|
@@ -614,7 +623,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
614
623
|
this.syncBlockCache.clear();
|
|
615
624
|
this.subscriptions.clear();
|
|
616
625
|
this.titleSubscriptions.clear();
|
|
617
|
-
this.
|
|
626
|
+
this.syncBlockFetchDataRequests.clear();
|
|
627
|
+
this.syncBlockSourceInfoRequests.clear();
|
|
618
628
|
this.providerFactories.clear();
|
|
619
629
|
this.isRefreshingSubscriptions = false;
|
|
620
630
|
this.providerFactories.forEach(function (providerFactory) {
|
|
@@ -4,9 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.SyncBlockStoreManager = void 0;
|
|
7
|
+
exports.useMemoizedSyncBlockStoreManager = exports.SyncBlockStoreManager = void 0;
|
|
8
8
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _react = require("react");
|
|
10
11
|
var _referenceSyncBlockStoreManager = require("./referenceSyncBlockStoreManager");
|
|
11
12
|
var _sourceSyncBlockStoreManager = require("./sourceSyncBlockStoreManager");
|
|
12
13
|
// A parent store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
|
|
@@ -39,4 +40,10 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
39
40
|
this.sourceSyncBlockStoreManager.destroy();
|
|
40
41
|
}
|
|
41
42
|
}]);
|
|
42
|
-
}();
|
|
43
|
+
}();
|
|
44
|
+
var useMemoizedSyncBlockStoreManager = exports.useMemoizedSyncBlockStoreManager = function useMemoizedSyncBlockStoreManager(dataProvider, fireAnalyticsEvent) {
|
|
45
|
+
return (0, _react.useMemo)(function () {
|
|
46
|
+
var syncBlockStoreManager = new SyncBlockStoreManager(dataProvider, fireAnalyticsEvent);
|
|
47
|
+
return syncBlockStoreManager;
|
|
48
|
+
}, [dataProvider, fireAnalyticsEvent]);
|
|
49
|
+
};
|
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.createSyncBlockNode = exports.convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockJSONNodeToSyncBlockNode = exports.convertPMNodesToSyncBlockNodes = exports.convertPMNodeToSyncBlockNode = void 0;
|
|
6
|
+
exports.getContentIdAndProductFromResourceId = exports.createSyncBlockNode = exports.convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockJSONNodeToSyncBlockNode = exports.convertPMNodesToSyncBlockNodes = exports.convertPMNodeToSyncBlockNode = void 0;
|
|
7
|
+
/* eslint-disable require-unicode-regexp */
|
|
8
|
+
|
|
7
9
|
var convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNodeToSyncBlockData(node) {
|
|
8
10
|
return {
|
|
9
11
|
blockInstanceId: node.attrs.localId,
|
|
@@ -39,4 +41,20 @@ var convertPMNodesToSyncBlockNodes = exports.convertPMNodesToSyncBlockNodes = fu
|
|
|
39
41
|
}).filter(function (node) {
|
|
40
42
|
return node !== undefined;
|
|
41
43
|
}) || [];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* From a reference block resource id (the resourceId stored in the node attributes)
|
|
48
|
+
* e.g. confluence-page/5769323474/cdf6a1bc-b241-487a-93e9-e30bde363cbc
|
|
49
|
+
* Extracts the source page content id and source product
|
|
50
|
+
*/
|
|
51
|
+
var getContentIdAndProductFromResourceId = exports.getContentIdAndProductFromResourceId = function getContentIdAndProductFromResourceId(resourceId) {
|
|
52
|
+
var match = resourceId.match(/^(confluence-page|jira-work-item)\/([^/]+)/);
|
|
53
|
+
if (match !== null && match !== void 0 && match[2]) {
|
|
54
|
+
return {
|
|
55
|
+
sourceProduct: match[1],
|
|
56
|
+
sourceContentId: match[2]
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
throw new Error("Invalid resourceId: ".concat(resourceId));
|
|
42
60
|
};
|
package/dist/es2019/index.js
CHANGED
|
@@ -17,11 +17,13 @@ export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/b
|
|
|
17
17
|
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
|
|
18
18
|
export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
|
|
19
19
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
|
|
20
|
+
|
|
20
21
|
// store managers
|
|
21
|
-
|
|
22
|
-
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
22
|
+
|
|
23
|
+
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
23
24
|
|
|
24
25
|
// utils
|
|
25
26
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
26
|
-
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes } from './utils/utils';
|
|
27
|
+
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId } from './utils/utils';
|
|
28
|
+
export { fetchErrorPayload } from './utils/errorHandling';
|
|
27
29
|
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|
|
@@ -213,7 +213,7 @@ class BlockServiceADFWriteProvider {
|
|
|
213
213
|
} catch (error) {
|
|
214
214
|
if (error instanceof BlockError) {
|
|
215
215
|
if (error.status === 404) {
|
|
216
|
-
// User should not be blocked by not_found error when deleting,
|
|
216
|
+
// User should not be blocked by not_found error when deleting,
|
|
217
217
|
// hence returns successful result for 404 error
|
|
218
218
|
return {
|
|
219
219
|
resourceId,
|
|
@@ -248,7 +248,8 @@ class BlockServiceADFWriteProvider {
|
|
|
248
248
|
blocks: blocks.map(block => ({
|
|
249
249
|
blockAri: generateBlockAriFromReference(this.sourceAri, block.resourceId),
|
|
250
250
|
blockInstanceId: block.localId
|
|
251
|
-
}),
|
|
251
|
+
})),
|
|
252
|
+
noContent
|
|
252
253
|
});
|
|
253
254
|
return {
|
|
254
255
|
success: true
|
|
@@ -15,12 +15,15 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
15
15
|
* @param sourceId
|
|
16
16
|
* @param nestedRendererDataProviders
|
|
17
17
|
*/
|
|
18
|
-
constructor(fetchProvider, writeProvider, sourceId
|
|
18
|
+
constructor(fetchProvider, writeProvider, sourceId) {
|
|
19
19
|
super();
|
|
20
20
|
_defineProperty(this, "name", 'syncBlockProvider');
|
|
21
21
|
this.fetchProvider = fetchProvider;
|
|
22
22
|
this.writeProvider = writeProvider;
|
|
23
23
|
this.sourceId = sourceId;
|
|
24
|
+
this.providerOptions = {};
|
|
25
|
+
}
|
|
26
|
+
setProviderOptions(providerOptions) {
|
|
24
27
|
this.providerOptions = providerOptions;
|
|
25
28
|
}
|
|
26
29
|
getProduct() {
|
|
@@ -205,12 +208,11 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
205
208
|
}
|
|
206
209
|
}
|
|
207
210
|
export const useMemoizedSyncedBlockProvider = (fetchProvider, writeProvider, sourceId, providerOptions, getSSRData) => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}, [fetchProvider, writeProvider, sourceId, providerOptions, getSSRData]);
|
|
211
|
+
const syncBlockProvider = useMemo(() => new SyncBlockProvider(fetchProvider, writeProvider, sourceId), [fetchProvider, writeProvider, sourceId]);
|
|
212
|
+
syncBlockProvider.setProviderOptions(providerOptions);
|
|
213
|
+
const ssrData = getSSRData ? getSSRData() : undefined;
|
|
214
|
+
if (ssrData) {
|
|
215
|
+
syncBlockProvider.setSSRData(ssrData);
|
|
216
|
+
}
|
|
217
|
+
return syncBlockProvider;
|
|
216
218
|
};
|
|
@@ -22,7 +22,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
22
22
|
this.subscriptions = new Map();
|
|
23
23
|
this.titleSubscriptions = new Map();
|
|
24
24
|
this.dataProvider = dataProvider;
|
|
25
|
-
this.
|
|
25
|
+
this.syncBlockFetchDataRequests = new Map();
|
|
26
|
+
this.syncBlockSourceInfoRequests = new Map();
|
|
26
27
|
this.providerFactories = new Map();
|
|
27
28
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
28
29
|
}
|
|
@@ -76,7 +77,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
76
77
|
if (!resourceId || !this.dataProvider) {
|
|
77
78
|
throw new Error('Data provider or resourceId not set');
|
|
78
79
|
}
|
|
79
|
-
if (this.
|
|
80
|
+
if (this.syncBlockSourceInfoRequests.get(resourceId)) {
|
|
80
81
|
return;
|
|
81
82
|
}
|
|
82
83
|
const existingSyncBlock = this.getFromCache(resourceId);
|
|
@@ -98,7 +99,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
98
99
|
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 ? void 0 : _this$fireAnalyticsEv2.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing'));
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
|
-
this.
|
|
102
|
+
this.syncBlockSourceInfoRequests.set(resourceId, true);
|
|
102
103
|
this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent).then(sourceInfo => {
|
|
103
104
|
if (!sourceInfo) {
|
|
104
105
|
return;
|
|
@@ -111,7 +112,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
111
112
|
var _this$fireAnalyticsEv3;
|
|
112
113
|
(_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 ? void 0 : _this$fireAnalyticsEv3.call(this, getSourceInfoErrorPayload(error.message));
|
|
113
114
|
}).finally(() => {
|
|
114
|
-
this.
|
|
115
|
+
this.syncBlockSourceInfoRequests.delete(resourceId);
|
|
115
116
|
});
|
|
116
117
|
} catch (error) {
|
|
117
118
|
var _this$fireAnalyticsEv4;
|
|
@@ -129,24 +130,32 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
129
130
|
*/
|
|
130
131
|
async fetchSyncBlocksData(syncBlockNodes) {
|
|
131
132
|
if (syncBlockNodes.length === 0) {
|
|
132
|
-
return
|
|
133
|
+
return;
|
|
133
134
|
}
|
|
134
135
|
if (!this.dataProvider) {
|
|
135
136
|
throw new Error('Data provider not set');
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
// Don't fetch for not_found error since the source is already deleted
|
|
139
|
-
const nodesToFetch = []
|
|
140
|
-
blocksWithNotFoundError = [];
|
|
140
|
+
const nodesToFetch = [];
|
|
141
141
|
syncBlockNodes.forEach(node => {
|
|
142
|
+
if (this.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
142
145
|
const existingSyncBlock = this.getFromCache(node.attrs.resourceId);
|
|
143
146
|
if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.error) === SyncBlockError.NotFound) {
|
|
144
|
-
|
|
145
|
-
} else {
|
|
146
|
-
nodesToFetch.push(node);
|
|
147
|
+
return;
|
|
147
148
|
}
|
|
149
|
+
nodesToFetch.push(node);
|
|
150
|
+
});
|
|
151
|
+
nodesToFetch.forEach(node => {
|
|
152
|
+
this.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
|
|
153
|
+
});
|
|
154
|
+
const data = await this.dataProvider.fetchNodesData(nodesToFetch).finally(() => {
|
|
155
|
+
nodesToFetch.forEach(node => {
|
|
156
|
+
this.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
|
|
157
|
+
});
|
|
148
158
|
});
|
|
149
|
-
const data = await this.dataProvider.fetchNodesData(nodesToFetch);
|
|
150
159
|
const resolvedData = [];
|
|
151
160
|
data.forEach(syncBlockInstance => {
|
|
152
161
|
if (!syncBlockInstance.resourceId) {
|
|
@@ -165,7 +174,6 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
165
174
|
}
|
|
166
175
|
this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
167
176
|
});
|
|
168
|
-
return [...resolvedData, ...blocksWithNotFoundError];
|
|
169
177
|
}
|
|
170
178
|
updateCacheWithSourceInfo(resourceId, sourceInfo) {
|
|
171
179
|
const existingSyncBlock = this.getFromCache(resourceId);
|
|
@@ -409,7 +417,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
409
417
|
|
|
410
418
|
/**
|
|
411
419
|
* Update reference synced blocks on the document with the BE
|
|
412
|
-
*
|
|
420
|
+
*
|
|
413
421
|
* @returns true if the reference synced blocks are updated successfully, false otherwise
|
|
414
422
|
*/
|
|
415
423
|
async flush() {
|
|
@@ -460,7 +468,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
460
468
|
this.syncBlockCache.clear();
|
|
461
469
|
this.subscriptions.clear();
|
|
462
470
|
this.titleSubscriptions.clear();
|
|
463
|
-
this.
|
|
471
|
+
this.syncBlockFetchDataRequests.clear();
|
|
472
|
+
this.syncBlockSourceInfoRequests.clear();
|
|
464
473
|
this.providerFactories.clear();
|
|
465
474
|
this.isRefreshingSubscriptions = false;
|
|
466
475
|
this.providerFactories.forEach(providerFactory => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
1
2
|
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
2
3
|
import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
|
3
4
|
|
|
@@ -23,4 +24,10 @@ export class SyncBlockStoreManager {
|
|
|
23
24
|
this.referenceSyncBlockStoreManager.destroy();
|
|
24
25
|
this.sourceSyncBlockStoreManager.destroy();
|
|
25
26
|
}
|
|
26
|
-
}
|
|
27
|
+
}
|
|
28
|
+
export const useMemoizedSyncBlockStoreManager = (dataProvider, fireAnalyticsEvent) => {
|
|
29
|
+
return useMemo(() => {
|
|
30
|
+
const syncBlockStoreManager = new SyncBlockStoreManager(dataProvider, fireAnalyticsEvent);
|
|
31
|
+
return syncBlockStoreManager;
|
|
32
|
+
}, [dataProvider, fireAnalyticsEvent]);
|
|
33
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable require-unicode-regexp */
|
|
2
|
+
|
|
1
3
|
export const convertSyncBlockPMNodeToSyncBlockData = node => {
|
|
2
4
|
return {
|
|
3
5
|
blockInstanceId: node.attrs.localId,
|
|
@@ -29,4 +31,20 @@ export const convertPMNodeToSyncBlockNode = node => {
|
|
|
29
31
|
};
|
|
30
32
|
export const convertPMNodesToSyncBlockNodes = nodes => {
|
|
31
33
|
return nodes.map(node => convertPMNodeToSyncBlockNode(node)).filter(node => node !== undefined) || [];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* From a reference block resource id (the resourceId stored in the node attributes)
|
|
38
|
+
* e.g. confluence-page/5769323474/cdf6a1bc-b241-487a-93e9-e30bde363cbc
|
|
39
|
+
* Extracts the source page content id and source product
|
|
40
|
+
*/
|
|
41
|
+
export const getContentIdAndProductFromResourceId = resourceId => {
|
|
42
|
+
const match = resourceId.match(/^(confluence-page|jira-work-item)\/([^/]+)/);
|
|
43
|
+
if (match !== null && match !== void 0 && match[2]) {
|
|
44
|
+
return {
|
|
45
|
+
sourceProduct: match[1],
|
|
46
|
+
sourceContentId: match[2]
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`Invalid resourceId: ${resourceId}`);
|
|
32
50
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -17,11 +17,13 @@ export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/b
|
|
|
17
17
|
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
|
|
18
18
|
export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
|
|
19
19
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
|
|
20
|
+
|
|
20
21
|
// store managers
|
|
21
|
-
|
|
22
|
-
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
22
|
+
|
|
23
|
+
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
23
24
|
|
|
24
25
|
// utils
|
|
25
26
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
26
|
-
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes } from './utils/utils';
|
|
27
|
+
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId } from './utils/utils';
|
|
28
|
+
export { fetchErrorPayload } from './utils/errorHandling';
|
|
27
29
|
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|
|
@@ -378,7 +378,8 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
378
378
|
blockAri: generateBlockAriFromReference(_this.sourceAri, block.resourceId),
|
|
379
379
|
blockInstanceId: block.localId
|
|
380
380
|
};
|
|
381
|
-
},
|
|
381
|
+
}),
|
|
382
|
+
noContent: noContent
|
|
382
383
|
});
|
|
383
384
|
case 3:
|
|
384
385
|
return _context6.abrupt("return", {
|
|
@@ -25,7 +25,7 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
25
25
|
* @param sourceId
|
|
26
26
|
* @param nestedRendererDataProviders
|
|
27
27
|
*/
|
|
28
|
-
function SyncBlockProvider(fetchProvider, writeProvider, sourceId
|
|
28
|
+
function SyncBlockProvider(fetchProvider, writeProvider, sourceId) {
|
|
29
29
|
var _this;
|
|
30
30
|
_classCallCheck(this, SyncBlockProvider);
|
|
31
31
|
_this = _callSuper(this, SyncBlockProvider);
|
|
@@ -33,11 +33,16 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
33
33
|
_this.fetchProvider = fetchProvider;
|
|
34
34
|
_this.writeProvider = writeProvider;
|
|
35
35
|
_this.sourceId = sourceId;
|
|
36
|
-
_this.providerOptions =
|
|
36
|
+
_this.providerOptions = {};
|
|
37
37
|
return _this;
|
|
38
38
|
}
|
|
39
39
|
_inherits(SyncBlockProvider, _SyncBlockDataProvide);
|
|
40
40
|
return _createClass(SyncBlockProvider, [{
|
|
41
|
+
key: "setProviderOptions",
|
|
42
|
+
value: function setProviderOptions(providerOptions) {
|
|
43
|
+
this.providerOptions = providerOptions;
|
|
44
|
+
}
|
|
45
|
+
}, {
|
|
41
46
|
key: "getProduct",
|
|
42
47
|
value: function getProduct() {
|
|
43
48
|
return this.writeProvider.product;
|
|
@@ -297,12 +302,13 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
297
302
|
}]);
|
|
298
303
|
}(SyncBlockDataProvider);
|
|
299
304
|
export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions, getSSRData) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
305
|
+
var syncBlockProvider = useMemo(function () {
|
|
306
|
+
return new SyncBlockProvider(fetchProvider, writeProvider, sourceId);
|
|
307
|
+
}, [fetchProvider, writeProvider, sourceId]);
|
|
308
|
+
syncBlockProvider.setProviderOptions(providerOptions);
|
|
309
|
+
var ssrData = getSSRData ? getSSRData() : undefined;
|
|
310
|
+
if (ssrData) {
|
|
311
|
+
syncBlockProvider.setSSRData(ssrData);
|
|
312
|
+
}
|
|
313
|
+
return syncBlockProvider;
|
|
308
314
|
};
|
|
@@ -33,7 +33,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
33
33
|
this.subscriptions = new Map();
|
|
34
34
|
this.titleSubscriptions = new Map();
|
|
35
35
|
this.dataProvider = dataProvider;
|
|
36
|
-
this.
|
|
36
|
+
this.syncBlockFetchDataRequests = new Map();
|
|
37
|
+
this.syncBlockSourceInfoRequests = new Map();
|
|
37
38
|
this.providerFactories = new Map();
|
|
38
39
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
39
40
|
}
|
|
@@ -154,7 +155,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
154
155
|
if (!resourceId || !this.dataProvider) {
|
|
155
156
|
throw new Error('Data provider or resourceId not set');
|
|
156
157
|
}
|
|
157
|
-
if (this.
|
|
158
|
+
if (this.syncBlockSourceInfoRequests.get(resourceId)) {
|
|
158
159
|
return;
|
|
159
160
|
}
|
|
160
161
|
var existingSyncBlock = this.getFromCache(resourceId);
|
|
@@ -175,7 +176,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
175
176
|
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing'));
|
|
176
177
|
return;
|
|
177
178
|
}
|
|
178
|
-
this.
|
|
179
|
+
this.syncBlockSourceInfoRequests.set(resourceId, true);
|
|
179
180
|
this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent).then(function (sourceInfo) {
|
|
180
181
|
if (!sourceInfo) {
|
|
181
182
|
return;
|
|
@@ -188,7 +189,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
188
189
|
var _this$fireAnalyticsEv3;
|
|
189
190
|
(_this$fireAnalyticsEv3 = _this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(_this, getSourceInfoErrorPayload(error.message));
|
|
190
191
|
}).finally(function () {
|
|
191
|
-
_this.
|
|
192
|
+
_this.syncBlockSourceInfoRequests.delete(resourceId);
|
|
192
193
|
});
|
|
193
194
|
} catch (error) {
|
|
194
195
|
var _this$fireAnalyticsEv4;
|
|
@@ -209,7 +210,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
209
210
|
value: (function () {
|
|
210
211
|
var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockNodes) {
|
|
211
212
|
var _this2 = this;
|
|
212
|
-
var nodesToFetch,
|
|
213
|
+
var nodesToFetch, data, resolvedData;
|
|
213
214
|
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
214
215
|
while (1) switch (_context3.prev = _context3.next) {
|
|
215
216
|
case 0:
|
|
@@ -217,7 +218,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
217
218
|
_context3.next = 2;
|
|
218
219
|
break;
|
|
219
220
|
}
|
|
220
|
-
return _context3.abrupt("return"
|
|
221
|
+
return _context3.abrupt("return");
|
|
221
222
|
case 2:
|
|
222
223
|
if (this.dataProvider) {
|
|
223
224
|
_context3.next = 4;
|
|
@@ -226,18 +227,27 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
226
227
|
throw new Error('Data provider not set');
|
|
227
228
|
case 4:
|
|
228
229
|
// Don't fetch for not_found error since the source is already deleted
|
|
229
|
-
nodesToFetch = []
|
|
230
|
+
nodesToFetch = [];
|
|
230
231
|
syncBlockNodes.forEach(function (node) {
|
|
232
|
+
if (_this2.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
231
235
|
var existingSyncBlock = _this2.getFromCache(node.attrs.resourceId);
|
|
232
236
|
if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.error) === SyncBlockError.NotFound) {
|
|
233
|
-
|
|
234
|
-
} else {
|
|
235
|
-
nodesToFetch.push(node);
|
|
237
|
+
return;
|
|
236
238
|
}
|
|
239
|
+
nodesToFetch.push(node);
|
|
237
240
|
});
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
+
nodesToFetch.forEach(function (node) {
|
|
242
|
+
_this2.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
|
|
243
|
+
});
|
|
244
|
+
_context3.next = 9;
|
|
245
|
+
return this.dataProvider.fetchNodesData(nodesToFetch).finally(function () {
|
|
246
|
+
nodesToFetch.forEach(function (node) {
|
|
247
|
+
_this2.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
case 9:
|
|
241
251
|
data = _context3.sent;
|
|
242
252
|
resolvedData = [];
|
|
243
253
|
data.forEach(function (syncBlockInstance) {
|
|
@@ -257,7 +267,6 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
257
267
|
}
|
|
258
268
|
_this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
259
269
|
});
|
|
260
|
-
return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
|
|
261
270
|
case 12:
|
|
262
271
|
case "end":
|
|
263
272
|
return _context3.stop();
|
|
@@ -521,7 +530,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
521
530
|
|
|
522
531
|
/**
|
|
523
532
|
* Update reference synced blocks on the document with the BE
|
|
524
|
-
*
|
|
533
|
+
*
|
|
525
534
|
* @returns true if the reference synced blocks are updated successfully, false otherwise
|
|
526
535
|
*/
|
|
527
536
|
}, {
|
|
@@ -608,7 +617,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
608
617
|
this.syncBlockCache.clear();
|
|
609
618
|
this.subscriptions.clear();
|
|
610
619
|
this.titleSubscriptions.clear();
|
|
611
|
-
this.
|
|
620
|
+
this.syncBlockFetchDataRequests.clear();
|
|
621
|
+
this.syncBlockSourceInfoRequests.clear();
|
|
612
622
|
this.providerFactories.clear();
|
|
613
623
|
this.isRefreshingSubscriptions = false;
|
|
614
624
|
this.providerFactories.forEach(function (providerFactory) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import { useMemo } from 'react';
|
|
3
4
|
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
4
5
|
import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
|
5
6
|
|
|
@@ -33,4 +34,10 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
33
34
|
this.sourceSyncBlockStoreManager.destroy();
|
|
34
35
|
}
|
|
35
36
|
}]);
|
|
36
|
-
}();
|
|
37
|
+
}();
|
|
38
|
+
export var useMemoizedSyncBlockStoreManager = function useMemoizedSyncBlockStoreManager(dataProvider, fireAnalyticsEvent) {
|
|
39
|
+
return useMemo(function () {
|
|
40
|
+
var syncBlockStoreManager = new SyncBlockStoreManager(dataProvider, fireAnalyticsEvent);
|
|
41
|
+
return syncBlockStoreManager;
|
|
42
|
+
}, [dataProvider, fireAnalyticsEvent]);
|
|
43
|
+
};
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable require-unicode-regexp */
|
|
2
|
+
|
|
1
3
|
export var convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNodeToSyncBlockData(node) {
|
|
2
4
|
return {
|
|
3
5
|
blockInstanceId: node.attrs.localId,
|
|
@@ -33,4 +35,20 @@ export var convertPMNodesToSyncBlockNodes = function convertPMNodesToSyncBlockNo
|
|
|
33
35
|
}).filter(function (node) {
|
|
34
36
|
return node !== undefined;
|
|
35
37
|
}) || [];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* From a reference block resource id (the resourceId stored in the node attributes)
|
|
42
|
+
* e.g. confluence-page/5769323474/cdf6a1bc-b241-487a-93e9-e30bde363cbc
|
|
43
|
+
* Extracts the source page content id and source product
|
|
44
|
+
*/
|
|
45
|
+
export var getContentIdAndProductFromResourceId = function getContentIdAndProductFromResourceId(resourceId) {
|
|
46
|
+
var match = resourceId.match(/^(confluence-page|jira-work-item)\/([^/]+)/);
|
|
47
|
+
if (match !== null && match !== void 0 && match[2]) {
|
|
48
|
+
return {
|
|
49
|
+
sourceProduct: match[1],
|
|
50
|
+
sourceContentId: match[2]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
throw new Error("Invalid resourceId: ".concat(resourceId));
|
|
36
54
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,8 +11,9 @@ export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders
|
|
|
11
11
|
export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
|
|
12
12
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
|
|
13
13
|
export type { ADFFetchProvider, ADFWriteProvider, SyncBlockDataProvider, SyncBlockInstance, MediaEmojiProviderOptions, SyncedBlockRendererProviderOptions, SyncBlockRendererProviderCreator, } from './providers/types';
|
|
14
|
-
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
15
|
-
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
14
|
+
export { type ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
15
|
+
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager, } from './store-manager/syncBlockStoreManager';
|
|
16
16
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
17
|
-
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, } from './utils/utils';
|
|
17
|
+
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId } from './utils/utils';
|
|
18
|
+
export { fetchErrorPayload } from './utils/errorHandling';
|
|
18
19
|
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|
|
@@ -16,7 +16,8 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
16
16
|
* @param sourceId
|
|
17
17
|
* @param nestedRendererDataProviders
|
|
18
18
|
*/
|
|
19
|
-
constructor(fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string
|
|
19
|
+
constructor(fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string);
|
|
20
|
+
setProviderOptions(providerOptions: SyncedBlockRendererProviderOptions): void;
|
|
20
21
|
getProduct(): SyncBlockProduct | undefined;
|
|
21
22
|
/**
|
|
22
23
|
* Check if the node is supported by the provider
|
|
@@ -85,6 +85,7 @@ export declare abstract class SyncBlockDataProvider extends NodeDataProvider<Syn
|
|
|
85
85
|
abstract getSourceId(): ResourceId;
|
|
86
86
|
abstract getProduct(): SyncBlockProduct | undefined;
|
|
87
87
|
abstract fetchSyncBlockSourceInfo(localId: BlockInstanceId, sourceAri: string, sourceProduct: SyncBlockProduct, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): Promise<SyncBlockSourceInfo | undefined>;
|
|
88
|
+
abstract setProviderOptions(providerOptions: SyncedBlockRendererProviderOptions): void;
|
|
88
89
|
abstract getSyncedBlockRendererProviderOptions(): SyncedBlockRendererProviderOptions;
|
|
89
90
|
abstract retrieveSyncBlockParentInfo(sourceAri: string, sourceProduct: SyncBlockProduct): SyncBlockParentInfo | undefined;
|
|
90
91
|
/**
|
|
@@ -11,7 +11,8 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
11
11
|
private titleSubscriptions;
|
|
12
12
|
private providerFactories;
|
|
13
13
|
private fireAnalyticsEvent?;
|
|
14
|
-
private
|
|
14
|
+
private syncBlockFetchDataRequests;
|
|
15
|
+
private syncBlockSourceInfoRequests;
|
|
15
16
|
private isRefreshingSubscriptions;
|
|
16
17
|
constructor(dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void);
|
|
17
18
|
generateResourceIdForReference(sourceId: ResourceId): ResourceId;
|
|
@@ -28,11 +29,11 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
28
29
|
* @param syncBlockNodes - The array of sync block nodes to fetch data for
|
|
29
30
|
* @returns The fetched sync block data results
|
|
30
31
|
*/
|
|
31
|
-
fetchSyncBlocksData(syncBlockNodes: SyncBlockNode[]): Promise<
|
|
32
|
+
fetchSyncBlocksData(syncBlockNodes: SyncBlockNode[]): Promise<void>;
|
|
32
33
|
private updateCacheWithSourceInfo;
|
|
33
34
|
private updateCache;
|
|
34
35
|
private updateSourceTitleSubscriptions;
|
|
35
|
-
|
|
36
|
+
getFromCache(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
36
37
|
private deleteFromCache;
|
|
37
38
|
subscribeToSyncBlock(resourceId: string, localId: string, callback: SubscriptionCallback): () => void;
|
|
38
39
|
subscribeToSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
|
|
@@ -10,3 +10,4 @@ export declare class SyncBlockStoreManager {
|
|
|
10
10
|
get sourceManager(): SourceSyncBlockStoreManager;
|
|
11
11
|
destroy(): void;
|
|
12
12
|
}
|
|
13
|
+
export declare const useMemoizedSyncBlockStoreManager: (dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: SyncBlockEventPayload) => void) => SyncBlockStoreManager;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { JSONNode } from '@atlaskit/editor-json-transformer';
|
|
2
2
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import type { SyncBlockData, BlockInstanceId, ResourceId, SyncBlockNode } from '../common/types';
|
|
3
|
+
import type { SyncBlockData, BlockInstanceId, ResourceId, SyncBlockNode, SyncBlockProduct } from '../common/types';
|
|
4
4
|
export declare const convertSyncBlockPMNodeToSyncBlockData: (node: PMNode) => SyncBlockData;
|
|
5
5
|
export declare const createSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
|
|
6
6
|
export declare const convertSyncBlockJSONNodeToSyncBlockNode: (node: JSONNode) => SyncBlockNode | undefined;
|
|
7
7
|
export declare const convertPMNodeToSyncBlockNode: (node: PMNode) => SyncBlockNode | undefined;
|
|
8
8
|
export declare const convertPMNodesToSyncBlockNodes: (nodes: PMNode[]) => SyncBlockNode[];
|
|
9
|
+
export declare const getContentIdAndProductFromResourceId: (resourceId: string) => {
|
|
10
|
+
sourceProduct: SyncBlockProduct;
|
|
11
|
+
sourceContentId: string;
|
|
12
|
+
};
|
|
@@ -11,8 +11,9 @@ export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders
|
|
|
11
11
|
export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
|
|
12
12
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
|
|
13
13
|
export type { ADFFetchProvider, ADFWriteProvider, SyncBlockDataProvider, SyncBlockInstance, MediaEmojiProviderOptions, SyncedBlockRendererProviderOptions, SyncBlockRendererProviderCreator, } from './providers/types';
|
|
14
|
-
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
15
|
-
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
14
|
+
export { type ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
15
|
+
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager, } from './store-manager/syncBlockStoreManager';
|
|
16
16
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
17
|
-
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, } from './utils/utils';
|
|
17
|
+
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId } from './utils/utils';
|
|
18
|
+
export { fetchErrorPayload } from './utils/errorHandling';
|
|
18
19
|
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|
|
@@ -16,7 +16,8 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
16
16
|
* @param sourceId
|
|
17
17
|
* @param nestedRendererDataProviders
|
|
18
18
|
*/
|
|
19
|
-
constructor(fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string
|
|
19
|
+
constructor(fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string);
|
|
20
|
+
setProviderOptions(providerOptions: SyncedBlockRendererProviderOptions): void;
|
|
20
21
|
getProduct(): SyncBlockProduct | undefined;
|
|
21
22
|
/**
|
|
22
23
|
* Check if the node is supported by the provider
|
|
@@ -85,6 +85,7 @@ export declare abstract class SyncBlockDataProvider extends NodeDataProvider<Syn
|
|
|
85
85
|
abstract getSourceId(): ResourceId;
|
|
86
86
|
abstract getProduct(): SyncBlockProduct | undefined;
|
|
87
87
|
abstract fetchSyncBlockSourceInfo(localId: BlockInstanceId, sourceAri: string, sourceProduct: SyncBlockProduct, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): Promise<SyncBlockSourceInfo | undefined>;
|
|
88
|
+
abstract setProviderOptions(providerOptions: SyncedBlockRendererProviderOptions): void;
|
|
88
89
|
abstract getSyncedBlockRendererProviderOptions(): SyncedBlockRendererProviderOptions;
|
|
89
90
|
abstract retrieveSyncBlockParentInfo(sourceAri: string, sourceProduct: SyncBlockProduct): SyncBlockParentInfo | undefined;
|
|
90
91
|
/**
|
|
@@ -11,7 +11,8 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
11
11
|
private titleSubscriptions;
|
|
12
12
|
private providerFactories;
|
|
13
13
|
private fireAnalyticsEvent?;
|
|
14
|
-
private
|
|
14
|
+
private syncBlockFetchDataRequests;
|
|
15
|
+
private syncBlockSourceInfoRequests;
|
|
15
16
|
private isRefreshingSubscriptions;
|
|
16
17
|
constructor(dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void);
|
|
17
18
|
generateResourceIdForReference(sourceId: ResourceId): ResourceId;
|
|
@@ -28,11 +29,11 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
28
29
|
* @param syncBlockNodes - The array of sync block nodes to fetch data for
|
|
29
30
|
* @returns The fetched sync block data results
|
|
30
31
|
*/
|
|
31
|
-
fetchSyncBlocksData(syncBlockNodes: SyncBlockNode[]): Promise<
|
|
32
|
+
fetchSyncBlocksData(syncBlockNodes: SyncBlockNode[]): Promise<void>;
|
|
32
33
|
private updateCacheWithSourceInfo;
|
|
33
34
|
private updateCache;
|
|
34
35
|
private updateSourceTitleSubscriptions;
|
|
35
|
-
|
|
36
|
+
getFromCache(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
36
37
|
private deleteFromCache;
|
|
37
38
|
subscribeToSyncBlock(resourceId: string, localId: string, callback: SubscriptionCallback): () => void;
|
|
38
39
|
subscribeToSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
|
|
@@ -10,3 +10,4 @@ export declare class SyncBlockStoreManager {
|
|
|
10
10
|
get sourceManager(): SourceSyncBlockStoreManager;
|
|
11
11
|
destroy(): void;
|
|
12
12
|
}
|
|
13
|
+
export declare const useMemoizedSyncBlockStoreManager: (dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: SyncBlockEventPayload) => void) => SyncBlockStoreManager;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { JSONNode } from '@atlaskit/editor-json-transformer';
|
|
2
2
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import type { SyncBlockData, BlockInstanceId, ResourceId, SyncBlockNode } from '../common/types';
|
|
3
|
+
import type { SyncBlockData, BlockInstanceId, ResourceId, SyncBlockNode, SyncBlockProduct } from '../common/types';
|
|
4
4
|
export declare const convertSyncBlockPMNodeToSyncBlockData: (node: PMNode) => SyncBlockData;
|
|
5
5
|
export declare const createSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
|
|
6
6
|
export declare const convertSyncBlockJSONNodeToSyncBlockNode: (node: JSONNode) => SyncBlockNode | undefined;
|
|
7
7
|
export declare const convertPMNodeToSyncBlockNode: (node: PMNode) => SyncBlockNode | undefined;
|
|
8
8
|
export declare const convertPMNodesToSyncBlockNodes: (nodes: PMNode[]) => SyncBlockNode[];
|
|
9
|
+
export declare const getContentIdAndProductFromResourceId: (resourceId: string) => {
|
|
10
|
+
sourceProduct: SyncBlockProduct;
|
|
11
|
+
sourceContentId: string;
|
|
12
|
+
};
|
package/package.json
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"uuid": "^3.1.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@atlaskit/editor-common": "^110.
|
|
36
|
+
"@atlaskit/editor-common": "^110.46.0",
|
|
37
37
|
"react": "^18.2.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
"name": "@atlaskit/editor-synced-block-provider",
|
|
79
|
-
"version": "2.15.
|
|
79
|
+
"version": "2.15.5",
|
|
80
80
|
"description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
|
|
81
81
|
"author": "Atlassian Pty Ltd",
|
|
82
82
|
"license": "Apache-2.0",
|