@atlaskit/editor-synced-block-provider 2.13.1 → 2.14.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.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +9 -1
- package/dist/cjs/providers/syncBlockProvider.js +9 -4
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +13 -3
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +127 -34
- package/dist/es2019/hooks/useFetchSyncBlockData.js +10 -1
- package/dist/es2019/providers/syncBlockProvider.js +9 -4
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +10 -2
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +84 -34
- package/dist/esm/hooks/useFetchSyncBlockData.js +9 -1
- package/dist/esm/providers/syncBlockProvider.js +9 -4
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +13 -3
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +127 -34
- package/dist/types/providers/syncBlockProvider.d.ts +1 -1
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +17 -1
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +1 -1
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +17 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 2.14.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`433b512284284`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/433b512284284) -
|
|
8
|
+
[EDITOR-2558] Update bodiedSyncBlock deletion failure flow
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 2.14.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [`8f3a22c66ae60`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8f3a22c66ae60) -
|
|
16
|
+
Update to read from ssr cache
|
|
17
|
+
|
|
3
18
|
## 2.13.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -14,7 +14,15 @@ var _types = require("../common/types");
|
|
|
14
14
|
var _errorHandling = require("../utils/errorHandling");
|
|
15
15
|
var _utils = require("../utils/utils");
|
|
16
16
|
var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyncBlockData(manager, resourceId, localId, fireAnalyticsEvent) {
|
|
17
|
-
var _useState = (0, _react.useState)(
|
|
17
|
+
var _useState = (0, _react.useState)(function () {
|
|
18
|
+
if (resourceId) {
|
|
19
|
+
var _manager$referenceMan;
|
|
20
|
+
var _ref = (manager === null || manager === void 0 || (_manager$referenceMan = manager.referenceManager) === null || _manager$referenceMan === void 0 ? void 0 : _manager$referenceMan.getInitialSyncBlockData(resourceId)) || {},
|
|
21
|
+
data = _ref.data;
|
|
22
|
+
return data || null;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}),
|
|
18
26
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
19
27
|
syncBlockInstance = _useState2[0],
|
|
20
28
|
setSyncBlockInstance = _useState2[1];
|
|
@@ -73,7 +73,7 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
73
73
|
}, {
|
|
74
74
|
key: "nodeDataKey",
|
|
75
75
|
value: function nodeDataKey(node) {
|
|
76
|
-
return node.attrs.
|
|
76
|
+
return node.attrs.resourceId;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
@@ -298,8 +298,13 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
298
298
|
}
|
|
299
299
|
}]);
|
|
300
300
|
}(_types2.SyncBlockDataProvider);
|
|
301
|
-
var useMemoizedSyncedBlockProvider = exports.useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
|
|
301
|
+
var useMemoizedSyncedBlockProvider = exports.useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions, getSSRData) {
|
|
302
302
|
return (0, _react.useMemo)(function () {
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
var syncBlockProvider = new SyncBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions);
|
|
304
|
+
var ssrData = getSSRData ? getSSRData() : undefined;
|
|
305
|
+
if (ssrData) {
|
|
306
|
+
syncBlockProvider.setSSRData(ssrData);
|
|
307
|
+
}
|
|
308
|
+
return syncBlockProvider;
|
|
309
|
+
}, [fetchProvider, writeProvider, sourceId, providerOptions, getSSRData]);
|
|
305
310
|
};
|
|
@@ -52,6 +52,13 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
52
52
|
value: function updateFireAnalyticsEvent(fireAnalyticsEvent) {
|
|
53
53
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
54
54
|
}
|
|
55
|
+
}, {
|
|
56
|
+
key: "getInitialSyncBlockData",
|
|
57
|
+
value: function getInitialSyncBlockData(resourceId) {
|
|
58
|
+
var _this$dataProvider;
|
|
59
|
+
var syncBlockNode = (0, _utils.createSyncBlockNode)('', resourceId);
|
|
60
|
+
return this.getFromCache(resourceId) || ((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 || (_this$dataProvider = _this$dataProvider.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.data);
|
|
61
|
+
}
|
|
55
62
|
|
|
56
63
|
/**
|
|
57
64
|
* Refreshes the subscriptions for all sync blocks.
|
|
@@ -315,17 +322,20 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
315
322
|
}, {
|
|
316
323
|
key: "subscribeToSyncBlock",
|
|
317
324
|
value: function subscribeToSyncBlock(resourceId, localId, callback) {
|
|
318
|
-
var
|
|
325
|
+
var _this$dataProvider2,
|
|
326
|
+
_this3 = this;
|
|
319
327
|
// add to subscriptions map
|
|
320
328
|
var resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
321
329
|
this.subscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, (0, _defineProperty2.default)({}, localId, callback)));
|
|
330
|
+
var syncBlockNode = (0, _utils.createSyncBlockNode)(localId, resourceId);
|
|
322
331
|
|
|
323
332
|
// call the callback immediately if we have cached data
|
|
324
|
-
|
|
333
|
+
// prefer cache from store manager first, should update data provider to use the same cache
|
|
334
|
+
var cachedData = this.getFromCache(resourceId) || ((_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 || (_this$dataProvider2 = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.data);
|
|
325
335
|
if (cachedData) {
|
|
326
336
|
callback(cachedData);
|
|
327
337
|
} else {
|
|
328
|
-
this.fetchSyncBlocksData([
|
|
338
|
+
this.fetchSyncBlocksData([syncBlockNode]).catch(function (error) {
|
|
329
339
|
var _this3$fireAnalyticsE;
|
|
330
340
|
(0, _monitoring.logException)(error, {
|
|
331
341
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
@@ -117,7 +117,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
117
117
|
case 10:
|
|
118
118
|
writeResults = _context.sent;
|
|
119
119
|
if (!writeResults.every(function (result) {
|
|
120
|
-
return
|
|
120
|
+
return result.resourceId !== undefined;
|
|
121
121
|
})) {
|
|
122
122
|
_context.next = 15;
|
|
123
123
|
break;
|
|
@@ -125,7 +125,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
125
125
|
return _context.abrupt("return", true);
|
|
126
126
|
case 15:
|
|
127
127
|
writeResults.filter(function (result) {
|
|
128
|
-
return result.
|
|
128
|
+
return result.resourceId === undefined;
|
|
129
129
|
}).forEach(function (result) {
|
|
130
130
|
var _this2$fireAnalyticsE;
|
|
131
131
|
(_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, (0, _errorHandling.updateErrorPayload)(result.error || 'Failed to write data'));
|
|
@@ -274,49 +274,40 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
}, {
|
|
277
|
-
key: "
|
|
277
|
+
key: "delete",
|
|
278
278
|
value: function () {
|
|
279
|
-
var
|
|
279
|
+
var _delete2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockIds, onDelete, onDeleteCompleted) {
|
|
280
280
|
var _this5 = this;
|
|
281
|
-
var
|
|
281
|
+
var results, callback, isDeleteSuccessful, _this$fireAnalyticsEv4;
|
|
282
282
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
283
283
|
while (1) switch (_context2.prev = _context2.next) {
|
|
284
284
|
case 0:
|
|
285
|
-
|
|
286
|
-
_context2.next = 22;
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
_context2.next = 3;
|
|
290
|
-
return this.confirmationCallback(syncBlockIds.length);
|
|
291
|
-
case 3:
|
|
292
|
-
confirmed = _context2.sent;
|
|
293
|
-
if (!confirmed) {
|
|
294
|
-
_context2.next = 22;
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
deleteCallback();
|
|
298
|
-
_context2.prev = 6;
|
|
285
|
+
_context2.prev = 0;
|
|
299
286
|
if (this.dataProvider) {
|
|
300
|
-
_context2.next =
|
|
287
|
+
_context2.next = 3;
|
|
301
288
|
break;
|
|
302
289
|
}
|
|
303
290
|
throw new Error('Data provider not set');
|
|
304
|
-
case
|
|
291
|
+
case 3:
|
|
305
292
|
syncBlockIds.forEach(function (Ids) {
|
|
306
293
|
_this5.setPendingDeletion(Ids, true);
|
|
307
294
|
});
|
|
308
|
-
_context2.next =
|
|
295
|
+
_context2.next = 6;
|
|
309
296
|
return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
|
|
310
297
|
return attrs.resourceId;
|
|
311
298
|
}));
|
|
312
|
-
case
|
|
299
|
+
case 6:
|
|
313
300
|
results = _context2.sent;
|
|
314
|
-
|
|
301
|
+
isDeleteSuccessful = results.every(function (result) {
|
|
315
302
|
return result.success;
|
|
316
|
-
})
|
|
303
|
+
});
|
|
304
|
+
onDeleteCompleted(isDeleteSuccessful);
|
|
305
|
+
if (isDeleteSuccessful) {
|
|
306
|
+
onDelete();
|
|
317
307
|
callback = function callback(Ids) {
|
|
318
308
|
return _this5.syncBlockCache.delete(Ids.resourceId);
|
|
319
309
|
};
|
|
310
|
+
this.clearPendingDeletion();
|
|
320
311
|
} else {
|
|
321
312
|
callback = function callback(Ids) {
|
|
322
313
|
_this5.setPendingDeletion(Ids, false);
|
|
@@ -329,11 +320,10 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
329
320
|
});
|
|
330
321
|
}
|
|
331
322
|
syncBlockIds.forEach(callback);
|
|
332
|
-
_context2.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
_context2.
|
|
336
|
-
_context2.t0 = _context2["catch"](6);
|
|
323
|
+
return _context2.abrupt("return", isDeleteSuccessful);
|
|
324
|
+
case 14:
|
|
325
|
+
_context2.prev = 14;
|
|
326
|
+
_context2.t0 = _context2["catch"](0);
|
|
337
327
|
syncBlockIds.forEach(function (Ids) {
|
|
338
328
|
_this5.setPendingDeletion(Ids, false);
|
|
339
329
|
});
|
|
@@ -341,17 +331,119 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
341
331
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
342
332
|
});
|
|
343
333
|
(_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.deleteErrorPayload)(_context2.t0.message));
|
|
344
|
-
|
|
334
|
+
onDeleteCompleted(false);
|
|
335
|
+
return _context2.abrupt("return", false);
|
|
336
|
+
case 21:
|
|
345
337
|
case "end":
|
|
346
338
|
return _context2.stop();
|
|
347
339
|
}
|
|
348
|
-
}, _callee2, this, [[
|
|
340
|
+
}, _callee2, this, [[0, 14]]);
|
|
341
|
+
}));
|
|
342
|
+
function _delete(_x, _x2, _x3) {
|
|
343
|
+
return _delete2.apply(this, arguments);
|
|
344
|
+
}
|
|
345
|
+
return _delete;
|
|
346
|
+
}()
|
|
347
|
+
}, {
|
|
348
|
+
key: "isRetryingDeletion",
|
|
349
|
+
value: function isRetryingDeletion() {
|
|
350
|
+
return !!this.deletionRetryInfo;
|
|
351
|
+
}
|
|
352
|
+
}, {
|
|
353
|
+
key: "retryDeletion",
|
|
354
|
+
value: function () {
|
|
355
|
+
var _retryDeletion = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
356
|
+
var _this$deletionRetryIn, syncBlockIds, onDelete, onDeleteCompleted;
|
|
357
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
358
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
359
|
+
case 0:
|
|
360
|
+
if (this.deletionRetryInfo) {
|
|
361
|
+
_context3.next = 2;
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
return _context3.abrupt("return", Promise.resolve());
|
|
365
|
+
case 2:
|
|
366
|
+
_this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted;
|
|
367
|
+
if (!this.confirmationCallback) {
|
|
368
|
+
_context3.next = 6;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
_context3.next = 6;
|
|
372
|
+
return this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
373
|
+
case 6:
|
|
374
|
+
case "end":
|
|
375
|
+
return _context3.stop();
|
|
376
|
+
}
|
|
377
|
+
}, _callee3, this);
|
|
349
378
|
}));
|
|
350
|
-
function
|
|
379
|
+
function retryDeletion() {
|
|
380
|
+
return _retryDeletion.apply(this, arguments);
|
|
381
|
+
}
|
|
382
|
+
return retryDeletion;
|
|
383
|
+
}()
|
|
384
|
+
}, {
|
|
385
|
+
key: "clearPendingDeletion",
|
|
386
|
+
value: function clearPendingDeletion() {
|
|
387
|
+
var _this$deletionRetryIn2;
|
|
388
|
+
(_this$deletionRetryIn2 = this.deletionRetryInfo) === null || _this$deletionRetryIn2 === void 0 || _this$deletionRetryIn2.destroyCallback();
|
|
389
|
+
this.deletionRetryInfo = undefined;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
*
|
|
394
|
+
* @param syncBlockIds - The sync block ids to delete
|
|
395
|
+
* @param onDelete - The callback to delete sync block node from document
|
|
396
|
+
* @param onDeleteCompleted - The callback for after the deletion is saved to BE (whether successful or not)
|
|
397
|
+
* @param destroyCallback - The callback to clear any reference stored for deletion (regardless if deletion is completed or abort)
|
|
398
|
+
*/
|
|
399
|
+
}, {
|
|
400
|
+
key: "deleteSyncBlocksWithConfirmation",
|
|
401
|
+
value: (function () {
|
|
402
|
+
var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(syncBlockIds, onDelete, onDeleteCompleted, destroyCallback) {
|
|
403
|
+
var confirmed, isDeleteSuccessful;
|
|
404
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
405
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
406
|
+
case 0:
|
|
407
|
+
if (!this.confirmationCallback) {
|
|
408
|
+
_context4.next = 12;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
_context4.next = 3;
|
|
412
|
+
return this.confirmationCallback(syncBlockIds.length);
|
|
413
|
+
case 3:
|
|
414
|
+
confirmed = _context4.sent;
|
|
415
|
+
if (!confirmed) {
|
|
416
|
+
_context4.next = 11;
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
_context4.next = 7;
|
|
420
|
+
return this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
421
|
+
case 7:
|
|
422
|
+
isDeleteSuccessful = _context4.sent;
|
|
423
|
+
if (!isDeleteSuccessful) {
|
|
424
|
+
// If deletion failed, save deletion info for potential retry
|
|
425
|
+
this.deletionRetryInfo = {
|
|
426
|
+
syncBlockIds: syncBlockIds,
|
|
427
|
+
onDelete: onDelete,
|
|
428
|
+
onDeleteCompleted: onDeleteCompleted,
|
|
429
|
+
destroyCallback: destroyCallback
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
_context4.next = 12;
|
|
433
|
+
break;
|
|
434
|
+
case 11:
|
|
435
|
+
destroyCallback();
|
|
436
|
+
case 12:
|
|
437
|
+
case "end":
|
|
438
|
+
return _context4.stop();
|
|
439
|
+
}
|
|
440
|
+
}, _callee4, this);
|
|
441
|
+
}));
|
|
442
|
+
function deleteSyncBlocksWithConfirmation(_x4, _x5, _x6, _x7) {
|
|
351
443
|
return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
|
|
352
444
|
}
|
|
353
445
|
return deleteSyncBlocksWithConfirmation;
|
|
354
|
-
}()
|
|
446
|
+
}())
|
|
355
447
|
}, {
|
|
356
448
|
key: "destroy",
|
|
357
449
|
value: function destroy() {
|
|
@@ -360,6 +452,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
360
452
|
this.pendingResourceId = undefined;
|
|
361
453
|
this.creationCallback = undefined;
|
|
362
454
|
this.dataProvider = undefined;
|
|
455
|
+
this.clearPendingDeletion();
|
|
363
456
|
}
|
|
364
457
|
}]);
|
|
365
458
|
}();
|
|
@@ -4,7 +4,16 @@ import { SyncBlockError } from '../common/types';
|
|
|
4
4
|
import { fetchErrorPayload } from '../utils/errorHandling';
|
|
5
5
|
import { createSyncBlockNode } from '../utils/utils';
|
|
6
6
|
export const useFetchSyncBlockData = (manager, resourceId, localId, fireAnalyticsEvent) => {
|
|
7
|
-
const [syncBlockInstance, setSyncBlockInstance] = useState(
|
|
7
|
+
const [syncBlockInstance, setSyncBlockInstance] = useState(() => {
|
|
8
|
+
if (resourceId) {
|
|
9
|
+
var _manager$referenceMan;
|
|
10
|
+
const {
|
|
11
|
+
data
|
|
12
|
+
} = (manager === null || manager === void 0 ? void 0 : (_manager$referenceMan = manager.referenceManager) === null || _manager$referenceMan === void 0 ? void 0 : _manager$referenceMan.getInitialSyncBlockData(resourceId)) || {};
|
|
13
|
+
return data || null;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
});
|
|
8
17
|
const [isLoading, setIsLoading] = useState(true);
|
|
9
18
|
const reloadData = useCallback(async () => {
|
|
10
19
|
if (isLoading) {
|
|
@@ -46,7 +46,7 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
46
46
|
* @returns The data key
|
|
47
47
|
*/
|
|
48
48
|
nodeDataKey(node) {
|
|
49
|
-
return node.attrs.
|
|
49
|
+
return node.attrs.resourceId;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -201,8 +201,13 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
export const useMemoizedSyncedBlockProvider = (fetchProvider, writeProvider, sourceId, providerOptions) => {
|
|
204
|
+
export const useMemoizedSyncedBlockProvider = (fetchProvider, writeProvider, sourceId, providerOptions, getSSRData) => {
|
|
205
205
|
return useMemo(() => {
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
const syncBlockProvider = new SyncBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions);
|
|
207
|
+
const ssrData = getSSRData ? getSSRData() : undefined;
|
|
208
|
+
if (ssrData) {
|
|
209
|
+
syncBlockProvider.setSSRData(ssrData);
|
|
210
|
+
}
|
|
211
|
+
return syncBlockProvider;
|
|
212
|
+
}, [fetchProvider, writeProvider, sourceId, providerOptions, getSSRData]);
|
|
208
213
|
};
|
|
@@ -31,6 +31,11 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
31
31
|
updateFireAnalyticsEvent(fireAnalyticsEvent) {
|
|
32
32
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
33
33
|
}
|
|
34
|
+
getInitialSyncBlockData(resourceId) {
|
|
35
|
+
var _this$dataProvider, _this$dataProvider$ge;
|
|
36
|
+
const syncBlockNode = createSyncBlockNode('', resourceId);
|
|
37
|
+
return this.getFromCache(resourceId) || ((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : (_this$dataProvider$ge = _this$dataProvider.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider$ge === void 0 ? void 0 : _this$dataProvider$ge.data);
|
|
38
|
+
}
|
|
34
39
|
|
|
35
40
|
/**
|
|
36
41
|
* Refreshes the subscriptions for all sync blocks.
|
|
@@ -200,19 +205,22 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
200
205
|
this.providerFactories.delete(resourceId);
|
|
201
206
|
}
|
|
202
207
|
subscribeToSyncBlock(resourceId, localId, callback) {
|
|
208
|
+
var _this$dataProvider2, _this$dataProvider2$g;
|
|
203
209
|
// add to subscriptions map
|
|
204
210
|
const resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
205
211
|
this.subscriptions.set(resourceId, {
|
|
206
212
|
...resourceSubscriptions,
|
|
207
213
|
[localId]: callback
|
|
208
214
|
});
|
|
215
|
+
const syncBlockNode = createSyncBlockNode(localId, resourceId);
|
|
209
216
|
|
|
210
217
|
// call the callback immediately if we have cached data
|
|
211
|
-
|
|
218
|
+
// prefer cache from store manager first, should update data provider to use the same cache
|
|
219
|
+
const cachedData = this.getFromCache(resourceId) || ((_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : (_this$dataProvider2$g = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2$g === void 0 ? void 0 : _this$dataProvider2$g.data);
|
|
212
220
|
if (cachedData) {
|
|
213
221
|
callback(cachedData);
|
|
214
222
|
} else {
|
|
215
|
-
this.fetchSyncBlocksData([
|
|
223
|
+
this.fetchSyncBlocksData([syncBlockNode]).catch(error => {
|
|
216
224
|
var _this$fireAnalyticsEv7;
|
|
217
225
|
logException(error, {
|
|
218
226
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
@@ -83,10 +83,10 @@ export class SourceSyncBlockStoreManager {
|
|
|
83
83
|
return Promise.resolve(true);
|
|
84
84
|
}
|
|
85
85
|
const writeResults = await this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
86
|
-
if (writeResults.every(result =>
|
|
86
|
+
if (writeResults.every(result => result.resourceId !== undefined)) {
|
|
87
87
|
return true;
|
|
88
88
|
} else {
|
|
89
|
-
writeResults.filter(result => result.
|
|
89
|
+
writeResults.filter(result => result.resourceId === undefined).forEach(result => {
|
|
90
90
|
var _this$fireAnalyticsEv2;
|
|
91
91
|
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 ? void 0 : _this$fireAnalyticsEv2.call(this, updateErrorPayload(result.error || 'Failed to write data'));
|
|
92
92
|
});
|
|
@@ -205,42 +205,91 @@ export class SourceSyncBlockStoreManager {
|
|
|
205
205
|
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, createErrorPayload(error.message));
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
async
|
|
208
|
+
async delete(syncBlockIds, onDelete, onDeleteCompleted) {
|
|
209
|
+
try {
|
|
210
|
+
if (!this.dataProvider) {
|
|
211
|
+
throw new Error('Data provider not set');
|
|
212
|
+
}
|
|
213
|
+
syncBlockIds.forEach(Ids => {
|
|
214
|
+
this.setPendingDeletion(Ids, true);
|
|
215
|
+
});
|
|
216
|
+
const results = await this.dataProvider.deleteNodesData(syncBlockIds.map(attrs => attrs.resourceId));
|
|
217
|
+
let callback;
|
|
218
|
+
const isDeleteSuccessful = results.every(result => result.success);
|
|
219
|
+
onDeleteCompleted(isDeleteSuccessful);
|
|
220
|
+
if (isDeleteSuccessful) {
|
|
221
|
+
onDelete();
|
|
222
|
+
callback = Ids => this.syncBlockCache.delete(Ids.resourceId);
|
|
223
|
+
this.clearPendingDeletion();
|
|
224
|
+
} else {
|
|
225
|
+
callback = Ids => {
|
|
226
|
+
this.setPendingDeletion(Ids, false);
|
|
227
|
+
};
|
|
228
|
+
results.filter(result => result.resourceId === undefined).forEach(result => {
|
|
229
|
+
var _this$fireAnalyticsEv7;
|
|
230
|
+
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, deleteErrorPayload(result.error || 'Failed to delete synced block'));
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
syncBlockIds.forEach(callback);
|
|
234
|
+
return isDeleteSuccessful;
|
|
235
|
+
} catch (error) {
|
|
236
|
+
var _this$fireAnalyticsEv8;
|
|
237
|
+
syncBlockIds.forEach(Ids => {
|
|
238
|
+
this.setPendingDeletion(Ids, false);
|
|
239
|
+
});
|
|
240
|
+
logException(error, {
|
|
241
|
+
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
242
|
+
});
|
|
243
|
+
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, deleteErrorPayload(error.message));
|
|
244
|
+
onDeleteCompleted(false);
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
isRetryingDeletion() {
|
|
249
|
+
return !!this.deletionRetryInfo;
|
|
250
|
+
}
|
|
251
|
+
async retryDeletion() {
|
|
252
|
+
if (!this.deletionRetryInfo) {
|
|
253
|
+
return Promise.resolve();
|
|
254
|
+
}
|
|
255
|
+
const {
|
|
256
|
+
syncBlockIds,
|
|
257
|
+
onDelete,
|
|
258
|
+
onDeleteCompleted
|
|
259
|
+
} = this.deletionRetryInfo;
|
|
260
|
+
if (this.confirmationCallback) {
|
|
261
|
+
await this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
clearPendingDeletion() {
|
|
265
|
+
var _this$deletionRetryIn;
|
|
266
|
+
(_this$deletionRetryIn = this.deletionRetryInfo) === null || _this$deletionRetryIn === void 0 ? void 0 : _this$deletionRetryIn.destroyCallback();
|
|
267
|
+
this.deletionRetryInfo = undefined;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
*
|
|
272
|
+
* @param syncBlockIds - The sync block ids to delete
|
|
273
|
+
* @param onDelete - The callback to delete sync block node from document
|
|
274
|
+
* @param onDeleteCompleted - The callback for after the deletion is saved to BE (whether successful or not)
|
|
275
|
+
* @param destroyCallback - The callback to clear any reference stored for deletion (regardless if deletion is completed or abort)
|
|
276
|
+
*/
|
|
277
|
+
async deleteSyncBlocksWithConfirmation(syncBlockIds, onDelete, onDeleteCompleted, destroyCallback) {
|
|
209
278
|
if (this.confirmationCallback) {
|
|
210
279
|
const confirmed = await this.confirmationCallback(syncBlockIds.length);
|
|
211
280
|
if (confirmed) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
let callback;
|
|
222
|
-
if (results.every(result => result.success)) {
|
|
223
|
-
callback = Ids => this.syncBlockCache.delete(Ids.resourceId);
|
|
224
|
-
} else {
|
|
225
|
-
callback = Ids => {
|
|
226
|
-
this.setPendingDeletion(Ids, false);
|
|
227
|
-
};
|
|
228
|
-
results.filter(result => result.resourceId === undefined).forEach(result => {
|
|
229
|
-
var _this$fireAnalyticsEv7;
|
|
230
|
-
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, deleteErrorPayload(result.error || 'Failed to delete synced block'));
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
syncBlockIds.forEach(callback);
|
|
234
|
-
} catch (error) {
|
|
235
|
-
var _this$fireAnalyticsEv8;
|
|
236
|
-
syncBlockIds.forEach(Ids => {
|
|
237
|
-
this.setPendingDeletion(Ids, false);
|
|
238
|
-
});
|
|
239
|
-
logException(error, {
|
|
240
|
-
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
241
|
-
});
|
|
242
|
-
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, deleteErrorPayload(error.message));
|
|
281
|
+
const isDeleteSuccessful = await this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
282
|
+
if (!isDeleteSuccessful) {
|
|
283
|
+
// If deletion failed, save deletion info for potential retry
|
|
284
|
+
this.deletionRetryInfo = {
|
|
285
|
+
syncBlockIds,
|
|
286
|
+
onDelete,
|
|
287
|
+
onDeleteCompleted,
|
|
288
|
+
destroyCallback
|
|
289
|
+
};
|
|
243
290
|
}
|
|
291
|
+
} else {
|
|
292
|
+
destroyCallback();
|
|
244
293
|
}
|
|
245
294
|
}
|
|
246
295
|
}
|
|
@@ -250,5 +299,6 @@ export class SourceSyncBlockStoreManager {
|
|
|
250
299
|
this.pendingResourceId = undefined;
|
|
251
300
|
this.creationCallback = undefined;
|
|
252
301
|
this.dataProvider = undefined;
|
|
302
|
+
this.clearPendingDeletion();
|
|
253
303
|
}
|
|
254
304
|
}
|
|
@@ -7,7 +7,15 @@ import { SyncBlockError } from '../common/types';
|
|
|
7
7
|
import { fetchErrorPayload } from '../utils/errorHandling';
|
|
8
8
|
import { createSyncBlockNode } from '../utils/utils';
|
|
9
9
|
export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resourceId, localId, fireAnalyticsEvent) {
|
|
10
|
-
var _useState = useState(
|
|
10
|
+
var _useState = useState(function () {
|
|
11
|
+
if (resourceId) {
|
|
12
|
+
var _manager$referenceMan;
|
|
13
|
+
var _ref = (manager === null || manager === void 0 || (_manager$referenceMan = manager.referenceManager) === null || _manager$referenceMan === void 0 ? void 0 : _manager$referenceMan.getInitialSyncBlockData(resourceId)) || {},
|
|
14
|
+
data = _ref.data;
|
|
15
|
+
return data || null;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}),
|
|
11
19
|
_useState2 = _slicedToArray(_useState, 2),
|
|
12
20
|
syncBlockInstance = _useState2[0],
|
|
13
21
|
setSyncBlockInstance = _useState2[1];
|
|
@@ -66,7 +66,7 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
66
66
|
}, {
|
|
67
67
|
key: "nodeDataKey",
|
|
68
68
|
value: function nodeDataKey(node) {
|
|
69
|
-
return node.attrs.
|
|
69
|
+
return node.attrs.resourceId;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
@@ -291,8 +291,13 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
291
291
|
}
|
|
292
292
|
}]);
|
|
293
293
|
}(SyncBlockDataProvider);
|
|
294
|
-
export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
|
|
294
|
+
export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions, getSSRData) {
|
|
295
295
|
return useMemo(function () {
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
var syncBlockProvider = new SyncBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions);
|
|
297
|
+
var ssrData = getSSRData ? getSSRData() : undefined;
|
|
298
|
+
if (ssrData) {
|
|
299
|
+
syncBlockProvider.setSSRData(ssrData);
|
|
300
|
+
}
|
|
301
|
+
return syncBlockProvider;
|
|
302
|
+
}, [fetchProvider, writeProvider, sourceId, providerOptions, getSSRData]);
|
|
298
303
|
};
|
|
@@ -46,6 +46,13 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
46
46
|
value: function updateFireAnalyticsEvent(fireAnalyticsEvent) {
|
|
47
47
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
48
48
|
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "getInitialSyncBlockData",
|
|
51
|
+
value: function getInitialSyncBlockData(resourceId) {
|
|
52
|
+
var _this$dataProvider;
|
|
53
|
+
var syncBlockNode = createSyncBlockNode('', resourceId);
|
|
54
|
+
return this.getFromCache(resourceId) || ((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 || (_this$dataProvider = _this$dataProvider.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.data);
|
|
55
|
+
}
|
|
49
56
|
|
|
50
57
|
/**
|
|
51
58
|
* Refreshes the subscriptions for all sync blocks.
|
|
@@ -309,17 +316,20 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
309
316
|
}, {
|
|
310
317
|
key: "subscribeToSyncBlock",
|
|
311
318
|
value: function subscribeToSyncBlock(resourceId, localId, callback) {
|
|
312
|
-
var
|
|
319
|
+
var _this$dataProvider2,
|
|
320
|
+
_this3 = this;
|
|
313
321
|
// add to subscriptions map
|
|
314
322
|
var resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
315
323
|
this.subscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
|
|
324
|
+
var syncBlockNode = createSyncBlockNode(localId, resourceId);
|
|
316
325
|
|
|
317
326
|
// call the callback immediately if we have cached data
|
|
318
|
-
|
|
327
|
+
// prefer cache from store manager first, should update data provider to use the same cache
|
|
328
|
+
var cachedData = this.getFromCache(resourceId) || ((_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 || (_this$dataProvider2 = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.data);
|
|
319
329
|
if (cachedData) {
|
|
320
330
|
callback(cachedData);
|
|
321
331
|
} else {
|
|
322
|
-
this.fetchSyncBlocksData([
|
|
332
|
+
this.fetchSyncBlocksData([syncBlockNode]).catch(function (error) {
|
|
323
333
|
var _this3$fireAnalyticsE;
|
|
324
334
|
logException(error, {
|
|
325
335
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
@@ -110,7 +110,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
110
110
|
case 10:
|
|
111
111
|
writeResults = _context.sent;
|
|
112
112
|
if (!writeResults.every(function (result) {
|
|
113
|
-
return
|
|
113
|
+
return result.resourceId !== undefined;
|
|
114
114
|
})) {
|
|
115
115
|
_context.next = 15;
|
|
116
116
|
break;
|
|
@@ -118,7 +118,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
118
118
|
return _context.abrupt("return", true);
|
|
119
119
|
case 15:
|
|
120
120
|
writeResults.filter(function (result) {
|
|
121
|
-
return result.
|
|
121
|
+
return result.resourceId === undefined;
|
|
122
122
|
}).forEach(function (result) {
|
|
123
123
|
var _this2$fireAnalyticsE;
|
|
124
124
|
(_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, updateErrorPayload(result.error || 'Failed to write data'));
|
|
@@ -267,49 +267,40 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
}, {
|
|
270
|
-
key: "
|
|
270
|
+
key: "delete",
|
|
271
271
|
value: function () {
|
|
272
|
-
var
|
|
272
|
+
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockIds, onDelete, onDeleteCompleted) {
|
|
273
273
|
var _this5 = this;
|
|
274
|
-
var
|
|
274
|
+
var results, callback, isDeleteSuccessful, _this$fireAnalyticsEv4;
|
|
275
275
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
276
276
|
while (1) switch (_context2.prev = _context2.next) {
|
|
277
277
|
case 0:
|
|
278
|
-
|
|
279
|
-
_context2.next = 22;
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
_context2.next = 3;
|
|
283
|
-
return this.confirmationCallback(syncBlockIds.length);
|
|
284
|
-
case 3:
|
|
285
|
-
confirmed = _context2.sent;
|
|
286
|
-
if (!confirmed) {
|
|
287
|
-
_context2.next = 22;
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
deleteCallback();
|
|
291
|
-
_context2.prev = 6;
|
|
278
|
+
_context2.prev = 0;
|
|
292
279
|
if (this.dataProvider) {
|
|
293
|
-
_context2.next =
|
|
280
|
+
_context2.next = 3;
|
|
294
281
|
break;
|
|
295
282
|
}
|
|
296
283
|
throw new Error('Data provider not set');
|
|
297
|
-
case
|
|
284
|
+
case 3:
|
|
298
285
|
syncBlockIds.forEach(function (Ids) {
|
|
299
286
|
_this5.setPendingDeletion(Ids, true);
|
|
300
287
|
});
|
|
301
|
-
_context2.next =
|
|
288
|
+
_context2.next = 6;
|
|
302
289
|
return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
|
|
303
290
|
return attrs.resourceId;
|
|
304
291
|
}));
|
|
305
|
-
case
|
|
292
|
+
case 6:
|
|
306
293
|
results = _context2.sent;
|
|
307
|
-
|
|
294
|
+
isDeleteSuccessful = results.every(function (result) {
|
|
308
295
|
return result.success;
|
|
309
|
-
})
|
|
296
|
+
});
|
|
297
|
+
onDeleteCompleted(isDeleteSuccessful);
|
|
298
|
+
if (isDeleteSuccessful) {
|
|
299
|
+
onDelete();
|
|
310
300
|
callback = function callback(Ids) {
|
|
311
301
|
return _this5.syncBlockCache.delete(Ids.resourceId);
|
|
312
302
|
};
|
|
303
|
+
this.clearPendingDeletion();
|
|
313
304
|
} else {
|
|
314
305
|
callback = function callback(Ids) {
|
|
315
306
|
_this5.setPendingDeletion(Ids, false);
|
|
@@ -322,11 +313,10 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
322
313
|
});
|
|
323
314
|
}
|
|
324
315
|
syncBlockIds.forEach(callback);
|
|
325
|
-
_context2.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
_context2.
|
|
329
|
-
_context2.t0 = _context2["catch"](6);
|
|
316
|
+
return _context2.abrupt("return", isDeleteSuccessful);
|
|
317
|
+
case 14:
|
|
318
|
+
_context2.prev = 14;
|
|
319
|
+
_context2.t0 = _context2["catch"](0);
|
|
330
320
|
syncBlockIds.forEach(function (Ids) {
|
|
331
321
|
_this5.setPendingDeletion(Ids, false);
|
|
332
322
|
});
|
|
@@ -334,17 +324,119 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
334
324
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
335
325
|
});
|
|
336
326
|
(_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, deleteErrorPayload(_context2.t0.message));
|
|
337
|
-
|
|
327
|
+
onDeleteCompleted(false);
|
|
328
|
+
return _context2.abrupt("return", false);
|
|
329
|
+
case 21:
|
|
338
330
|
case "end":
|
|
339
331
|
return _context2.stop();
|
|
340
332
|
}
|
|
341
|
-
}, _callee2, this, [[
|
|
333
|
+
}, _callee2, this, [[0, 14]]);
|
|
334
|
+
}));
|
|
335
|
+
function _delete(_x, _x2, _x3) {
|
|
336
|
+
return _delete2.apply(this, arguments);
|
|
337
|
+
}
|
|
338
|
+
return _delete;
|
|
339
|
+
}()
|
|
340
|
+
}, {
|
|
341
|
+
key: "isRetryingDeletion",
|
|
342
|
+
value: function isRetryingDeletion() {
|
|
343
|
+
return !!this.deletionRetryInfo;
|
|
344
|
+
}
|
|
345
|
+
}, {
|
|
346
|
+
key: "retryDeletion",
|
|
347
|
+
value: function () {
|
|
348
|
+
var _retryDeletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
349
|
+
var _this$deletionRetryIn, syncBlockIds, onDelete, onDeleteCompleted;
|
|
350
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
351
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
352
|
+
case 0:
|
|
353
|
+
if (this.deletionRetryInfo) {
|
|
354
|
+
_context3.next = 2;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
return _context3.abrupt("return", Promise.resolve());
|
|
358
|
+
case 2:
|
|
359
|
+
_this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted;
|
|
360
|
+
if (!this.confirmationCallback) {
|
|
361
|
+
_context3.next = 6;
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
_context3.next = 6;
|
|
365
|
+
return this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
366
|
+
case 6:
|
|
367
|
+
case "end":
|
|
368
|
+
return _context3.stop();
|
|
369
|
+
}
|
|
370
|
+
}, _callee3, this);
|
|
342
371
|
}));
|
|
343
|
-
function
|
|
372
|
+
function retryDeletion() {
|
|
373
|
+
return _retryDeletion.apply(this, arguments);
|
|
374
|
+
}
|
|
375
|
+
return retryDeletion;
|
|
376
|
+
}()
|
|
377
|
+
}, {
|
|
378
|
+
key: "clearPendingDeletion",
|
|
379
|
+
value: function clearPendingDeletion() {
|
|
380
|
+
var _this$deletionRetryIn2;
|
|
381
|
+
(_this$deletionRetryIn2 = this.deletionRetryInfo) === null || _this$deletionRetryIn2 === void 0 || _this$deletionRetryIn2.destroyCallback();
|
|
382
|
+
this.deletionRetryInfo = undefined;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
*
|
|
387
|
+
* @param syncBlockIds - The sync block ids to delete
|
|
388
|
+
* @param onDelete - The callback to delete sync block node from document
|
|
389
|
+
* @param onDeleteCompleted - The callback for after the deletion is saved to BE (whether successful or not)
|
|
390
|
+
* @param destroyCallback - The callback to clear any reference stored for deletion (regardless if deletion is completed or abort)
|
|
391
|
+
*/
|
|
392
|
+
}, {
|
|
393
|
+
key: "deleteSyncBlocksWithConfirmation",
|
|
394
|
+
value: (function () {
|
|
395
|
+
var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(syncBlockIds, onDelete, onDeleteCompleted, destroyCallback) {
|
|
396
|
+
var confirmed, isDeleteSuccessful;
|
|
397
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
398
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
399
|
+
case 0:
|
|
400
|
+
if (!this.confirmationCallback) {
|
|
401
|
+
_context4.next = 12;
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
_context4.next = 3;
|
|
405
|
+
return this.confirmationCallback(syncBlockIds.length);
|
|
406
|
+
case 3:
|
|
407
|
+
confirmed = _context4.sent;
|
|
408
|
+
if (!confirmed) {
|
|
409
|
+
_context4.next = 11;
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
_context4.next = 7;
|
|
413
|
+
return this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
414
|
+
case 7:
|
|
415
|
+
isDeleteSuccessful = _context4.sent;
|
|
416
|
+
if (!isDeleteSuccessful) {
|
|
417
|
+
// If deletion failed, save deletion info for potential retry
|
|
418
|
+
this.deletionRetryInfo = {
|
|
419
|
+
syncBlockIds: syncBlockIds,
|
|
420
|
+
onDelete: onDelete,
|
|
421
|
+
onDeleteCompleted: onDeleteCompleted,
|
|
422
|
+
destroyCallback: destroyCallback
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
_context4.next = 12;
|
|
426
|
+
break;
|
|
427
|
+
case 11:
|
|
428
|
+
destroyCallback();
|
|
429
|
+
case 12:
|
|
430
|
+
case "end":
|
|
431
|
+
return _context4.stop();
|
|
432
|
+
}
|
|
433
|
+
}, _callee4, this);
|
|
434
|
+
}));
|
|
435
|
+
function deleteSyncBlocksWithConfirmation(_x4, _x5, _x6, _x7) {
|
|
344
436
|
return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
|
|
345
437
|
}
|
|
346
438
|
return deleteSyncBlocksWithConfirmation;
|
|
347
|
-
}()
|
|
439
|
+
}())
|
|
348
440
|
}, {
|
|
349
441
|
key: "destroy",
|
|
350
442
|
value: function destroy() {
|
|
@@ -353,6 +445,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
353
445
|
this.pendingResourceId = undefined;
|
|
354
446
|
this.creationCallback = undefined;
|
|
355
447
|
this.dataProvider = undefined;
|
|
448
|
+
this.clearPendingDeletion();
|
|
356
449
|
}
|
|
357
450
|
}]);
|
|
358
451
|
}();
|
|
@@ -95,4 +95,4 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
95
95
|
*/
|
|
96
96
|
retrieveSyncBlockParentInfo(sourceAri: string, sourceProduct: SyncBlockProduct): SyncBlockParentInfo | undefined;
|
|
97
97
|
}
|
|
98
|
-
export declare const useMemoizedSyncedBlockProvider: (fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string, providerOptions: SyncedBlockRendererProviderOptions) => SyncBlockProvider;
|
|
98
|
+
export declare const useMemoizedSyncedBlockProvider: (fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string, providerOptions: SyncedBlockRendererProviderOptions, getSSRData?: () => Record<string, SyncBlockInstance> | undefined) => SyncBlockProvider;
|
|
@@ -15,6 +15,7 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
15
15
|
constructor(dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void);
|
|
16
16
|
generateResourceIdForReference(sourceId: ResourceId): ResourceId;
|
|
17
17
|
updateFireAnalyticsEvent(fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): void;
|
|
18
|
+
getInitialSyncBlockData(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
18
19
|
/**
|
|
19
20
|
* Refreshes the subscriptions for all sync blocks.
|
|
20
21
|
* @returns {Promise<void>}
|
|
@@ -3,12 +3,16 @@ import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
|
3
3
|
import type { ResourceId, SyncBlockAttrs } from '../common/types';
|
|
4
4
|
import type { SyncBlockDataProvider } from '../providers/types';
|
|
5
5
|
export type ConfirmationCallback = (syncBlockCount: number) => Promise<boolean>;
|
|
6
|
+
type OnDelete = () => void;
|
|
7
|
+
type OnDeleteCompleted = (success: boolean) => void;
|
|
8
|
+
type DestroyCallback = () => void;
|
|
6
9
|
export type CreationCallback = () => void;
|
|
7
10
|
export declare class SourceSyncBlockStoreManager {
|
|
8
11
|
private dataProvider?;
|
|
9
12
|
private fireAnalyticsEvent?;
|
|
10
13
|
private syncBlockCache;
|
|
11
14
|
private confirmationCallback?;
|
|
15
|
+
private deletionRetryInfo?;
|
|
12
16
|
private pendingResourceId?;
|
|
13
17
|
private creationCallback?;
|
|
14
18
|
constructor(dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: SyncBlockEventPayload) => void);
|
|
@@ -51,6 +55,18 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
51
55
|
*/
|
|
52
56
|
createBodiedSyncBlockNode(attrs: SyncBlockAttrs): void;
|
|
53
57
|
private setPendingDeletion;
|
|
54
|
-
|
|
58
|
+
private delete;
|
|
59
|
+
isRetryingDeletion(): boolean;
|
|
60
|
+
retryDeletion(): Promise<void>;
|
|
61
|
+
clearPendingDeletion(): void;
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param syncBlockIds - The sync block ids to delete
|
|
65
|
+
* @param onDelete - The callback to delete sync block node from document
|
|
66
|
+
* @param onDeleteCompleted - The callback for after the deletion is saved to BE (whether successful or not)
|
|
67
|
+
* @param destroyCallback - The callback to clear any reference stored for deletion (regardless if deletion is completed or abort)
|
|
68
|
+
*/
|
|
69
|
+
deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], onDelete: OnDelete, onDeleteCompleted: OnDeleteCompleted, destroyCallback: DestroyCallback): Promise<void>;
|
|
55
70
|
destroy(): void;
|
|
56
71
|
}
|
|
72
|
+
export {};
|
|
@@ -95,4 +95,4 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
95
95
|
*/
|
|
96
96
|
retrieveSyncBlockParentInfo(sourceAri: string, sourceProduct: SyncBlockProduct): SyncBlockParentInfo | undefined;
|
|
97
97
|
}
|
|
98
|
-
export declare const useMemoizedSyncedBlockProvider: (fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string, providerOptions: SyncedBlockRendererProviderOptions) => SyncBlockProvider;
|
|
98
|
+
export declare const useMemoizedSyncedBlockProvider: (fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string, providerOptions: SyncedBlockRendererProviderOptions, getSSRData?: () => Record<string, SyncBlockInstance> | undefined) => SyncBlockProvider;
|
|
@@ -15,6 +15,7 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
15
15
|
constructor(dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void);
|
|
16
16
|
generateResourceIdForReference(sourceId: ResourceId): ResourceId;
|
|
17
17
|
updateFireAnalyticsEvent(fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): void;
|
|
18
|
+
getInitialSyncBlockData(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
18
19
|
/**
|
|
19
20
|
* Refreshes the subscriptions for all sync blocks.
|
|
20
21
|
* @returns {Promise<void>}
|
|
@@ -3,12 +3,16 @@ import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
|
3
3
|
import type { ResourceId, SyncBlockAttrs } from '../common/types';
|
|
4
4
|
import type { SyncBlockDataProvider } from '../providers/types';
|
|
5
5
|
export type ConfirmationCallback = (syncBlockCount: number) => Promise<boolean>;
|
|
6
|
+
type OnDelete = () => void;
|
|
7
|
+
type OnDeleteCompleted = (success: boolean) => void;
|
|
8
|
+
type DestroyCallback = () => void;
|
|
6
9
|
export type CreationCallback = () => void;
|
|
7
10
|
export declare class SourceSyncBlockStoreManager {
|
|
8
11
|
private dataProvider?;
|
|
9
12
|
private fireAnalyticsEvent?;
|
|
10
13
|
private syncBlockCache;
|
|
11
14
|
private confirmationCallback?;
|
|
15
|
+
private deletionRetryInfo?;
|
|
12
16
|
private pendingResourceId?;
|
|
13
17
|
private creationCallback?;
|
|
14
18
|
constructor(dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: SyncBlockEventPayload) => void);
|
|
@@ -51,6 +55,18 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
51
55
|
*/
|
|
52
56
|
createBodiedSyncBlockNode(attrs: SyncBlockAttrs): void;
|
|
53
57
|
private setPendingDeletion;
|
|
54
|
-
|
|
58
|
+
private delete;
|
|
59
|
+
isRetryingDeletion(): boolean;
|
|
60
|
+
retryDeletion(): Promise<void>;
|
|
61
|
+
clearPendingDeletion(): void;
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param syncBlockIds - The sync block ids to delete
|
|
65
|
+
* @param onDelete - The callback to delete sync block node from document
|
|
66
|
+
* @param onDeleteCompleted - The callback for after the deletion is saved to BE (whether successful or not)
|
|
67
|
+
* @param destroyCallback - The callback to clear any reference stored for deletion (regardless if deletion is completed or abort)
|
|
68
|
+
*/
|
|
69
|
+
deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], onDelete: OnDelete, onDeleteCompleted: OnDeleteCompleted, destroyCallback: DestroyCallback): Promise<void>;
|
|
55
70
|
destroy(): void;
|
|
56
71
|
}
|
|
72
|
+
export {};
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"category": "Layout and structure"
|
|
7
7
|
}
|
|
8
8
|
},
|
|
9
|
-
"repository": "https://
|
|
9
|
+
"repository": "https://bitbucket.org/atlassian/atlassian-frontend-monorepo",
|
|
10
10
|
"main": "dist/cjs/index.js",
|
|
11
11
|
"module": "dist/esm/index.js",
|
|
12
12
|
"module:es2019": "dist/es2019/index.js",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"uuid": "^3.1.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@atlaskit/editor-common": "^110.
|
|
37
|
+
"@atlaskit/editor-common": "^110.41.0",
|
|
38
38
|
"react": "^18.2.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@testing-library/react": "^
|
|
41
|
+
"@testing-library/react": "^16.3.0",
|
|
42
42
|
"react-dom": "^18.2.0"
|
|
43
43
|
},
|
|
44
44
|
"techstack": {
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"name": "@atlaskit/editor-synced-block-provider",
|
|
80
|
-
"version": "2.
|
|
80
|
+
"version": "2.14.1",
|
|
81
81
|
"description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
|
|
82
82
|
"author": "Atlassian Pty Ltd",
|
|
83
83
|
"license": "Apache-2.0",
|