@atlaskit/editor-synced-block-provider 4.3.1 → 4.3.2
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 +12 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +45 -37
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +79 -39
- package/dist/cjs/store-manager/syncBlockStoreManager.js +125 -116
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +6 -1
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +29 -1
- package/dist/es2019/store-manager/syncBlockStoreManager.js +91 -91
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +45 -37
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +79 -39
- package/dist/esm/store-manager/syncBlockStoreManager.js +125 -116
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +3 -1
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +3 -1
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +3 -1
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +3 -1
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +3 -1
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +3 -1
- package/package.json +2 -2
|
@@ -19,17 +19,21 @@ import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
|
19
19
|
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
20
20
|
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
21
21
|
export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
22
|
-
function SourceSyncBlockStoreManager(dataProvider) {
|
|
22
|
+
function SourceSyncBlockStoreManager(dataProvider, viewMode) {
|
|
23
23
|
var _this = this;
|
|
24
24
|
_classCallCheck(this, SourceSyncBlockStoreManager);
|
|
25
25
|
_defineProperty(this, "hasReceivedContentChange", false);
|
|
26
26
|
_defineProperty(this, "setPendingDeletion", function (Ids, value) {
|
|
27
|
+
if (_this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
27
30
|
var syncBlock = _this.syncBlockCache.get(Ids.resourceId);
|
|
28
31
|
if (syncBlock) {
|
|
29
32
|
syncBlock.pendingDeletion = value;
|
|
30
33
|
}
|
|
31
34
|
});
|
|
32
35
|
this.dataProvider = dataProvider;
|
|
36
|
+
this.viewMode = viewMode;
|
|
33
37
|
this.syncBlockCache = new Map();
|
|
34
38
|
this.creationCompletionCallbacks = new Map();
|
|
35
39
|
}
|
|
@@ -67,6 +71,9 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
67
71
|
key: "updateSyncBlockData",
|
|
68
72
|
value: function updateSyncBlockData(syncBlockNode) {
|
|
69
73
|
try {
|
|
74
|
+
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
70
77
|
if (!this.isSourceBlock(syncBlockNode)) {
|
|
71
78
|
throw new Error('Invalid sync block node type provided for updateSyncBlockData');
|
|
72
79
|
}
|
|
@@ -127,6 +134,12 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
127
134
|
while (1) switch (_context.prev = _context.next) {
|
|
128
135
|
case 0:
|
|
129
136
|
_context.prev = 0;
|
|
137
|
+
if (!(this.viewMode === 'view' && fg('platform_synced_block_patch_8'))) {
|
|
138
|
+
_context.next = 3;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
return _context.abrupt("return", false);
|
|
142
|
+
case 3:
|
|
130
143
|
bodiedSyncBlockNodes = [];
|
|
131
144
|
bodiedSyncBlockData = [];
|
|
132
145
|
Array.from(this.syncBlockCache.values()).forEach(function (syncBlockData) {
|
|
@@ -156,21 +169,21 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
156
169
|
}
|
|
157
170
|
});
|
|
158
171
|
if (!(bodiedSyncBlockNodes.length === 0)) {
|
|
159
|
-
_context.next =
|
|
172
|
+
_context.next = 8;
|
|
160
173
|
break;
|
|
161
174
|
}
|
|
162
175
|
return _context.abrupt("return", Promise.resolve(true));
|
|
163
|
-
case
|
|
176
|
+
case 8:
|
|
164
177
|
if (this.dataProvider) {
|
|
165
|
-
_context.next =
|
|
178
|
+
_context.next = 10;
|
|
166
179
|
break;
|
|
167
180
|
}
|
|
168
181
|
throw new Error('Data provider not set');
|
|
169
|
-
case
|
|
182
|
+
case 10:
|
|
170
183
|
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 || _this$saveExperience.start({});
|
|
171
|
-
_context.next =
|
|
184
|
+
_context.next = 13;
|
|
172
185
|
return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
173
|
-
case
|
|
186
|
+
case 13:
|
|
174
187
|
writeResults = _context.sent;
|
|
175
188
|
writeResults.forEach(function (result) {
|
|
176
189
|
// set isDirty to true for cases where it failed to save the sync block to the BE
|
|
@@ -184,7 +197,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
184
197
|
if (!writeResults.every(function (result) {
|
|
185
198
|
return result.resourceId && !result.error;
|
|
186
199
|
})) {
|
|
187
|
-
_context.next =
|
|
200
|
+
_context.next = 21;
|
|
188
201
|
break;
|
|
189
202
|
}
|
|
190
203
|
(_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 || _this$saveExperience2.success();
|
|
@@ -195,7 +208,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
195
208
|
}
|
|
196
209
|
});
|
|
197
210
|
return _context.abrupt("return", true);
|
|
198
|
-
case
|
|
211
|
+
case 21:
|
|
199
212
|
(_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure();
|
|
200
213
|
writeResults.filter(function (result) {
|
|
201
214
|
return !result.resourceId || result.error;
|
|
@@ -204,28 +217,28 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
204
217
|
(_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, updateErrorPayload(result.error || 'Failed to write data', result.resourceId));
|
|
205
218
|
});
|
|
206
219
|
return _context.abrupt("return", false);
|
|
207
|
-
case 22:
|
|
208
|
-
_context.next = 29;
|
|
209
|
-
break;
|
|
210
220
|
case 24:
|
|
211
|
-
_context.
|
|
221
|
+
_context.next = 31;
|
|
222
|
+
break;
|
|
223
|
+
case 26:
|
|
224
|
+
_context.prev = 26;
|
|
212
225
|
_context.t0 = _context["catch"](0);
|
|
213
226
|
logException(_context.t0, {
|
|
214
227
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
215
228
|
});
|
|
216
229
|
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, updateErrorPayload(_context.t0.message));
|
|
217
230
|
return _context.abrupt("return", false);
|
|
218
|
-
case
|
|
219
|
-
_context.prev =
|
|
231
|
+
case 31:
|
|
232
|
+
_context.prev = 31;
|
|
220
233
|
if (fg('platform_synced_block_patch_7')) {
|
|
221
234
|
(_this$flushCompletion = this.flushCompletionCallback) === null || _this$flushCompletion === void 0 || _this$flushCompletion.call(this);
|
|
222
235
|
}
|
|
223
|
-
return _context.finish(
|
|
224
|
-
case
|
|
236
|
+
return _context.finish(31);
|
|
237
|
+
case 34:
|
|
225
238
|
case "end":
|
|
226
239
|
return _context.stop();
|
|
227
240
|
}
|
|
228
|
-
}, _callee, this, [[0,
|
|
241
|
+
}, _callee, this, [[0, 26, 31, 34]]);
|
|
229
242
|
}));
|
|
230
243
|
function flush() {
|
|
231
244
|
return _flush.apply(this, arguments);
|
|
@@ -235,6 +248,9 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
235
248
|
}, {
|
|
236
249
|
key: "hasUnsavedChanges",
|
|
237
250
|
value: function hasUnsavedChanges() {
|
|
251
|
+
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
238
254
|
return this.hasReceivedContentChange && Array.from(this.syncBlockCache.values()).some(function (syncBlockData) {
|
|
239
255
|
return syncBlockData.isDirty;
|
|
240
256
|
});
|
|
@@ -252,6 +268,9 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
252
268
|
}, {
|
|
253
269
|
key: "commitPendingCreation",
|
|
254
270
|
value: function commitPendingCreation(success, resourceId) {
|
|
271
|
+
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
255
274
|
var onCompletion = this.creationCompletionCallbacks.get(resourceId);
|
|
256
275
|
if (onCompletion) {
|
|
257
276
|
this.creationCompletionCallbacks.delete(resourceId);
|
|
@@ -318,6 +337,9 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
318
337
|
key: "createBodiedSyncBlockNode",
|
|
319
338
|
value: function createBodiedSyncBlockNode(attrs, onCompletion) {
|
|
320
339
|
var _this4 = this;
|
|
340
|
+
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
321
343
|
var resourceId = attrs.resourceId,
|
|
322
344
|
blockInstanceId = attrs.localId;
|
|
323
345
|
try {
|
|
@@ -377,21 +399,27 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
377
399
|
while (1) switch (_context2.prev = _context2.next) {
|
|
378
400
|
case 0:
|
|
379
401
|
_context2.prev = 0;
|
|
380
|
-
if (this.
|
|
402
|
+
if (!(this.viewMode === 'view' && fg('platform_synced_block_patch_8'))) {
|
|
381
403
|
_context2.next = 3;
|
|
382
404
|
break;
|
|
383
405
|
}
|
|
384
|
-
|
|
406
|
+
return _context2.abrupt("return", false);
|
|
385
407
|
case 3:
|
|
408
|
+
if (this.dataProvider) {
|
|
409
|
+
_context2.next = 5;
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
throw new Error('Data provider not set');
|
|
413
|
+
case 5:
|
|
386
414
|
syncBlockIds.forEach(function (Ids) {
|
|
387
415
|
_this5.setPendingDeletion(Ids, true);
|
|
388
416
|
});
|
|
389
417
|
(_this$deleteExperienc = this.deleteExperience) === null || _this$deleteExperienc === void 0 || _this$deleteExperienc.start({});
|
|
390
|
-
_context2.next =
|
|
418
|
+
_context2.next = 9;
|
|
391
419
|
return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
|
|
392
420
|
return attrs.resourceId;
|
|
393
421
|
}), reason);
|
|
394
|
-
case
|
|
422
|
+
case 9:
|
|
395
423
|
results = _context2.sent;
|
|
396
424
|
isDeleteSuccessful = results.every(function (result) {
|
|
397
425
|
return result.success;
|
|
@@ -425,8 +453,8 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
425
453
|
}
|
|
426
454
|
syncBlockIds.forEach(callback);
|
|
427
455
|
return _context2.abrupt("return", isDeleteSuccessful);
|
|
428
|
-
case
|
|
429
|
-
_context2.prev =
|
|
456
|
+
case 17:
|
|
457
|
+
_context2.prev = 17;
|
|
430
458
|
_context2.t0 = _context2["catch"](0);
|
|
431
459
|
syncBlockIds.forEach(function (Ids) {
|
|
432
460
|
var _this5$fireAnalyticsE4;
|
|
@@ -438,11 +466,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
438
466
|
});
|
|
439
467
|
onDeleteCompleted(false);
|
|
440
468
|
return _context2.abrupt("return", false);
|
|
441
|
-
case
|
|
469
|
+
case 23:
|
|
442
470
|
case "end":
|
|
443
471
|
return _context2.stop();
|
|
444
472
|
}
|
|
445
|
-
}, _callee2, this, [[0,
|
|
473
|
+
}, _callee2, this, [[0, 17]]);
|
|
446
474
|
}));
|
|
447
475
|
function _delete(_x, _x2, _x3, _x4) {
|
|
448
476
|
return _delete2.apply(this, arguments);
|
|
@@ -462,20 +490,26 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
462
490
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
463
491
|
while (1) switch (_context3.prev = _context3.next) {
|
|
464
492
|
case 0:
|
|
465
|
-
if (this.
|
|
493
|
+
if (!(this.viewMode === 'view' && fg('platform_synced_block_patch_8'))) {
|
|
466
494
|
_context3.next = 2;
|
|
467
495
|
break;
|
|
468
496
|
}
|
|
469
497
|
return _context3.abrupt("return", Promise.resolve());
|
|
470
498
|
case 2:
|
|
499
|
+
if (this.deletionRetryInfo) {
|
|
500
|
+
_context3.next = 4;
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
return _context3.abrupt("return", Promise.resolve());
|
|
504
|
+
case 4:
|
|
471
505
|
_this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted, deletionReason = _this$deletionRetryIn.deletionReason;
|
|
472
506
|
if (!this.confirmationCallback) {
|
|
473
|
-
_context3.next =
|
|
507
|
+
_context3.next = 8;
|
|
474
508
|
break;
|
|
475
509
|
}
|
|
476
|
-
_context3.next =
|
|
510
|
+
_context3.next = 8;
|
|
477
511
|
return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
|
|
478
|
-
case
|
|
512
|
+
case 8:
|
|
479
513
|
case "end":
|
|
480
514
|
return _context3.stop();
|
|
481
515
|
}
|
|
@@ -509,21 +543,27 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
509
543
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
510
544
|
while (1) switch (_context4.prev = _context4.next) {
|
|
511
545
|
case 0:
|
|
546
|
+
if (!(this.viewMode === 'view' && fg('platform_synced_block_patch_8'))) {
|
|
547
|
+
_context4.next = 2;
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
return _context4.abrupt("return", Promise.resolve());
|
|
551
|
+
case 2:
|
|
512
552
|
if (!this.confirmationCallback) {
|
|
513
|
-
_context4.next =
|
|
553
|
+
_context4.next = 14;
|
|
514
554
|
break;
|
|
515
555
|
}
|
|
516
|
-
_context4.next =
|
|
556
|
+
_context4.next = 5;
|
|
517
557
|
return this.confirmationCallback(syncBlockIds, deletionReason);
|
|
518
|
-
case
|
|
558
|
+
case 5:
|
|
519
559
|
confirmed = _context4.sent;
|
|
520
560
|
if (!confirmed) {
|
|
521
|
-
_context4.next =
|
|
561
|
+
_context4.next = 13;
|
|
522
562
|
break;
|
|
523
563
|
}
|
|
524
|
-
_context4.next =
|
|
564
|
+
_context4.next = 9;
|
|
525
565
|
return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
|
|
526
|
-
case
|
|
566
|
+
case 9:
|
|
527
567
|
isDeleteSuccessful = _context4.sent;
|
|
528
568
|
if (!isDeleteSuccessful) {
|
|
529
569
|
// If deletion failed, save deletion info for potential retry
|
|
@@ -537,11 +577,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
537
577
|
} else {
|
|
538
578
|
destroyCallback();
|
|
539
579
|
}
|
|
540
|
-
_context4.next =
|
|
580
|
+
_context4.next = 14;
|
|
541
581
|
break;
|
|
542
|
-
case
|
|
582
|
+
case 13:
|
|
543
583
|
destroyCallback();
|
|
544
|
-
case
|
|
584
|
+
case 14:
|
|
545
585
|
case "end":
|
|
546
586
|
return _context4.stop();
|
|
547
587
|
}
|
|
@@ -21,12 +21,12 @@ import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
|
|
21
21
|
// SourceSyncBlockStoreManager is responsible for the lifecycle and state management of source sync blocks in an editor instance.
|
|
22
22
|
// Can be used in both editor and renderer contexts.
|
|
23
23
|
export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
24
|
-
function SyncBlockStoreManager(dataProvider) {
|
|
24
|
+
function SyncBlockStoreManager(dataProvider, viewMode) {
|
|
25
25
|
_classCallCheck(this, SyncBlockStoreManager);
|
|
26
26
|
// In future, if reference manager needs to reach to source manager and read its current in memory cache
|
|
27
27
|
// we can pass the source manager as a parameter to the reference manager constructor
|
|
28
|
-
this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider);
|
|
29
|
-
this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider);
|
|
28
|
+
this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider, viewMode);
|
|
29
|
+
this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider, viewMode);
|
|
30
30
|
this.dataProvider = dataProvider;
|
|
31
31
|
this.referenceSyncBlockStoreManager.setRealTimeSubscriptionsEnabled(true);
|
|
32
32
|
}
|
|
@@ -35,7 +35,7 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
35
35
|
value: function () {
|
|
36
36
|
var _fetchReferencesSourceInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceId, blockInstanceId, isSourceSyncBlock) {
|
|
37
37
|
var _this = this;
|
|
38
|
-
var _this$fetchReferences, _response$references, _this$
|
|
38
|
+
var _this$fetchReferences, _response$references, _this$fetchReferences5, _response$references2, response, _this$fetchReferences2, _this$fetchReferences3, _this$fetchReferences4, sourceInfoPromises, sourceInfos, sourceSyncBlockData, _this$fireAnalyticsEv;
|
|
39
39
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
40
40
|
while (1) switch (_context2.prev = _context2.next) {
|
|
41
41
|
case 0:
|
|
@@ -63,114 +63,20 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
63
63
|
});
|
|
64
64
|
case 10:
|
|
65
65
|
if (!(!response.references || ((_response$references = response.references) === null || _response$references === void 0 ? void 0 : _response$references.length) === 0)) {
|
|
66
|
-
_context2.next =
|
|
66
|
+
_context2.next = 17;
|
|
67
67
|
break;
|
|
68
68
|
}
|
|
69
69
|
if (!fg('platform_synced_block_patch_8')) {
|
|
70
|
-
_context2.next =
|
|
70
|
+
_context2.next = 15;
|
|
71
71
|
break;
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
// Verify that a reference sync block for this specific source actually
|
|
78
|
-
// exists on the current page by checking if the reference manager has
|
|
79
|
-
// an active subscription for the derived reference resourceId.
|
|
80
|
-
referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
|
|
81
|
-
hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
|
|
82
|
-
if (!hasUnregisteredReferenceOnPage) {
|
|
83
|
-
_context2.next = 27;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
_context2.next = 18;
|
|
87
|
-
return this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
|
|
88
|
-
case 18:
|
|
89
|
-
_sourceSyncBlockData = _context2.sent;
|
|
90
|
-
references = [];
|
|
91
|
-
if (_sourceSyncBlockData) {
|
|
92
|
-
references.push(_objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
|
|
93
|
-
onSameDocument: Boolean(_sourceSyncBlockData === null || _sourceSyncBlockData === void 0 ? void 0 : _sourceSyncBlockData.onSameDocument),
|
|
94
|
-
hasAccess: true,
|
|
95
|
-
isSource: true
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
_context2.next = 23;
|
|
99
|
-
return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(referenceResourceId);
|
|
100
|
-
case 23:
|
|
101
|
-
unregisteredReferenceData = _context2.sent;
|
|
102
|
-
if (unregisteredReferenceData) {
|
|
103
|
-
references.push(_objectSpread(_objectSpread({}, unregisteredReferenceData), {}, {
|
|
104
|
-
onSameDocument: true,
|
|
105
|
-
hasAccess: true,
|
|
106
|
-
isSource: false
|
|
107
|
-
}));
|
|
108
|
-
}
|
|
109
|
-
(_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
|
|
110
|
-
return _context2.abrupt("return", {
|
|
111
|
-
references: references
|
|
112
|
-
});
|
|
113
|
-
case 27:
|
|
114
|
-
// No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
|
|
115
|
-
(_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.success();
|
|
116
|
-
return _context2.abrupt("return", {
|
|
117
|
-
references: []
|
|
118
|
-
});
|
|
119
|
-
case 29:
|
|
120
|
-
if (isSourceSyncBlock) {
|
|
121
|
-
_context2.next = 44;
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
// Though no references registered yet for this reference sync block,
|
|
125
|
-
// still show the source and the current page itself since they are known
|
|
126
|
-
// but not saved yet.
|
|
127
|
-
_references = [];
|
|
128
|
-
_context2.next = 33;
|
|
129
|
-
return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
|
|
130
|
-
case 33:
|
|
131
|
-
_sourceSyncBlockData2 = _context2.sent;
|
|
132
|
-
if (_sourceSyncBlockData2) {
|
|
133
|
-
_references.push(_objectSpread(_objectSpread({}, _sourceSyncBlockData2), {}, {
|
|
134
|
-
onSameDocument: Boolean(_sourceSyncBlockData2 === null || _sourceSyncBlockData2 === void 0 ? void 0 : _sourceSyncBlockData2.onSameDocument),
|
|
135
|
-
hasAccess: true,
|
|
136
|
-
isSource: true
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
_context2.next = 37;
|
|
140
|
-
return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
|
|
141
|
-
case 37:
|
|
142
|
-
currentPageData = _context2.sent;
|
|
143
|
-
if (currentPageData) {
|
|
144
|
-
_references.push(_objectSpread(_objectSpread({}, currentPageData), {}, {
|
|
145
|
-
onSameDocument: true,
|
|
146
|
-
hasAccess: true,
|
|
147
|
-
isSource: false
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
if (!(_references.length === 0)) {
|
|
151
|
-
_context2.next = 42;
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
(_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.failure({
|
|
155
|
-
reason: 'No references found for reference synced block'
|
|
156
|
-
});
|
|
157
|
-
return _context2.abrupt("return", {
|
|
158
|
-
error: SyncBlockError.Errored
|
|
159
|
-
});
|
|
160
|
-
case 42:
|
|
161
|
-
(_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.success();
|
|
162
|
-
return _context2.abrupt("return", {
|
|
163
|
-
references: _references
|
|
164
|
-
});
|
|
165
|
-
case 44:
|
|
166
|
-
_context2.next = 48;
|
|
167
|
-
break;
|
|
168
|
-
case 46:
|
|
73
|
+
return _context2.abrupt("return", this.getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock));
|
|
74
|
+
case 15:
|
|
169
75
|
// No reference found
|
|
170
76
|
if (isSourceSyncBlock) {
|
|
171
|
-
(_this$
|
|
77
|
+
(_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
|
|
172
78
|
} else {
|
|
173
|
-
(_this$
|
|
79
|
+
(_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.failure({
|
|
174
80
|
reason: 'No references found for reference synced block'
|
|
175
81
|
});
|
|
176
82
|
}
|
|
@@ -179,8 +85,8 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
179
85
|
} : {
|
|
180
86
|
error: SyncBlockError.Errored
|
|
181
87
|
});
|
|
182
|
-
case
|
|
183
|
-
(_this$
|
|
88
|
+
case 17:
|
|
89
|
+
(_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.success();
|
|
184
90
|
sourceInfoPromises = ((_response$references2 = response.references) !== null && _response$references2 !== void 0 ? _response$references2 : []).map( /*#__PURE__*/function () {
|
|
185
91
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(reference) {
|
|
186
92
|
var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
|
|
@@ -218,13 +124,13 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
218
124
|
return _ref.apply(this, arguments);
|
|
219
125
|
};
|
|
220
126
|
}());
|
|
221
|
-
_context2.next =
|
|
127
|
+
_context2.next = 21;
|
|
222
128
|
return Promise.all(sourceInfoPromises);
|
|
223
|
-
case
|
|
129
|
+
case 21:
|
|
224
130
|
sourceInfos = _context2.sent;
|
|
225
|
-
_context2.next =
|
|
131
|
+
_context2.next = 24;
|
|
226
132
|
return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
|
|
227
|
-
case
|
|
133
|
+
case 24:
|
|
228
134
|
sourceSyncBlockData = _context2.sent;
|
|
229
135
|
if (sourceSyncBlockData) {
|
|
230
136
|
sourceInfos.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
|
|
@@ -237,8 +143,8 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
237
143
|
return _context2.abrupt("return", {
|
|
238
144
|
references: sourceInfos
|
|
239
145
|
});
|
|
240
|
-
case
|
|
241
|
-
_context2.prev =
|
|
146
|
+
case 29:
|
|
147
|
+
_context2.prev = 29;
|
|
242
148
|
_context2.t0 = _context2["catch"](0);
|
|
243
149
|
logException(_context2.t0, {
|
|
244
150
|
location: 'editor-synced-block-provider/syncBlockStoreManager'
|
|
@@ -247,11 +153,11 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
247
153
|
return _context2.abrupt("return", {
|
|
248
154
|
error: SyncBlockError.Errored
|
|
249
155
|
});
|
|
250
|
-
case
|
|
156
|
+
case 34:
|
|
251
157
|
case "end":
|
|
252
158
|
return _context2.stop();
|
|
253
159
|
}
|
|
254
|
-
}, _callee2, this, [[0,
|
|
160
|
+
}, _callee2, this, [[0, 29]]);
|
|
255
161
|
}));
|
|
256
162
|
function fetchReferencesSourceInfo(_x, _x2, _x3) {
|
|
257
163
|
return _fetchReferencesSourceInfo.apply(this, arguments);
|
|
@@ -280,16 +186,119 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
280
186
|
}, {
|
|
281
187
|
key: "destroy",
|
|
282
188
|
value: function destroy() {
|
|
283
|
-
var _this$
|
|
189
|
+
var _this$fetchReferences6, _this$fetchSourceInfo4;
|
|
284
190
|
this.referenceSyncBlockStoreManager.destroy();
|
|
285
191
|
this.sourceSyncBlockStoreManager.destroy();
|
|
286
|
-
(_this$
|
|
192
|
+
(_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.abort({
|
|
287
193
|
reason: 'editorDestroyed'
|
|
288
194
|
});
|
|
289
195
|
(_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.abort({
|
|
290
196
|
reason: 'editorDestroyed'
|
|
291
197
|
});
|
|
292
198
|
}
|
|
199
|
+
}, {
|
|
200
|
+
key: "getUnregisteredReferences",
|
|
201
|
+
value: function () {
|
|
202
|
+
var _getUnregisteredReferences = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resourceId, blockInstanceId, isSourceSyncBlock) {
|
|
203
|
+
var _this$fetchReferences0;
|
|
204
|
+
var _this$fetchReferences8, referenceResourceId, hasUnregisteredReferenceOnPage, _this$fetchReferences7, _sourceSyncBlockData, _references, sourceSyncBlockReference, referenceSyncBlockReference, references, sourceSyncBlockData, currentPageData, _this$fetchReferences9;
|
|
205
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
206
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
207
|
+
case 0:
|
|
208
|
+
if (!isSourceSyncBlock) {
|
|
209
|
+
_context3.next = 13;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
// Verify that a reference sync block for this specific source actually
|
|
213
|
+
// exists on the current page by checking if the reference manager has
|
|
214
|
+
// an active subscription for the derived reference resourceId.
|
|
215
|
+
referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
|
|
216
|
+
hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
|
|
217
|
+
if (!hasUnregisteredReferenceOnPage) {
|
|
218
|
+
_context3.next = 11;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
_context3.next = 6;
|
|
222
|
+
return this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
|
|
223
|
+
case 6:
|
|
224
|
+
_sourceSyncBlockData = _context3.sent;
|
|
225
|
+
_references = [];
|
|
226
|
+
if (_sourceSyncBlockData) {
|
|
227
|
+
sourceSyncBlockReference = _objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
|
|
228
|
+
onSameDocument: true,
|
|
229
|
+
hasAccess: true,
|
|
230
|
+
isSource: true
|
|
231
|
+
});
|
|
232
|
+
referenceSyncBlockReference = _objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
|
|
233
|
+
onSameDocument: true,
|
|
234
|
+
hasAccess: true,
|
|
235
|
+
isSource: false
|
|
236
|
+
});
|
|
237
|
+
_references.push(sourceSyncBlockReference, referenceSyncBlockReference);
|
|
238
|
+
}
|
|
239
|
+
(_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.success();
|
|
240
|
+
return _context3.abrupt("return", {
|
|
241
|
+
references: _references
|
|
242
|
+
});
|
|
243
|
+
case 11:
|
|
244
|
+
// No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
|
|
245
|
+
(_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.success();
|
|
246
|
+
return _context3.abrupt("return", {
|
|
247
|
+
references: []
|
|
248
|
+
});
|
|
249
|
+
case 13:
|
|
250
|
+
// Though no references registered yet for this reference sync block,
|
|
251
|
+
// still show the source and the current page itself since they are known
|
|
252
|
+
// but not saved yet.
|
|
253
|
+
references = [];
|
|
254
|
+
_context3.next = 16;
|
|
255
|
+
return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
|
|
256
|
+
case 16:
|
|
257
|
+
sourceSyncBlockData = _context3.sent;
|
|
258
|
+
if (sourceSyncBlockData) {
|
|
259
|
+
references.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
|
|
260
|
+
onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
|
|
261
|
+
hasAccess: true,
|
|
262
|
+
isSource: true
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
_context3.next = 20;
|
|
266
|
+
return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
|
|
267
|
+
case 20:
|
|
268
|
+
currentPageData = _context3.sent;
|
|
269
|
+
if (currentPageData) {
|
|
270
|
+
references.push(_objectSpread(_objectSpread({}, currentPageData), {}, {
|
|
271
|
+
onSameDocument: true,
|
|
272
|
+
hasAccess: true,
|
|
273
|
+
isSource: false
|
|
274
|
+
}));
|
|
275
|
+
}
|
|
276
|
+
if (!(references.length === 0)) {
|
|
277
|
+
_context3.next = 25;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
(_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 || _this$fetchReferences9.failure({
|
|
281
|
+
reason: 'No references found for reference synced block'
|
|
282
|
+
});
|
|
283
|
+
return _context3.abrupt("return", {
|
|
284
|
+
error: SyncBlockError.Errored
|
|
285
|
+
});
|
|
286
|
+
case 25:
|
|
287
|
+
(_this$fetchReferences0 = this.fetchReferencesExperience) === null || _this$fetchReferences0 === void 0 || _this$fetchReferences0.success();
|
|
288
|
+
return _context3.abrupt("return", {
|
|
289
|
+
references: references
|
|
290
|
+
});
|
|
291
|
+
case 27:
|
|
292
|
+
case "end":
|
|
293
|
+
return _context3.stop();
|
|
294
|
+
}
|
|
295
|
+
}, _callee3, this);
|
|
296
|
+
}));
|
|
297
|
+
function getUnregisteredReferences(_x5, _x6, _x7) {
|
|
298
|
+
return _getUnregisteredReferences.apply(this, arguments);
|
|
299
|
+
}
|
|
300
|
+
return getUnregisteredReferences;
|
|
301
|
+
}()
|
|
293
302
|
}]);
|
|
294
303
|
}();
|
|
295
304
|
var createSyncBlockStoreManager = function createSyncBlockStoreManager(dataProvider) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { RendererSyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { Experience } from '@atlaskit/editor-common/experiences';
|
|
3
3
|
import type { ProviderFactory, MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
4
|
+
import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
4
5
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
5
6
|
import type { BlockInstanceId, ResourceId, SyncBlockNode, SyncBlockPrefetchData } from '../common/types';
|
|
6
7
|
import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProviderInterface, TitleSubscriptionCallback, SyncBlockSourceInfo } from '../providers/types';
|
|
7
8
|
export declare class ReferenceSyncBlockStoreManager {
|
|
9
|
+
private viewMode?;
|
|
8
10
|
private dataProvider?;
|
|
9
11
|
private isCacheDirty;
|
|
10
12
|
private fireAnalyticsEvent?;
|
|
@@ -22,7 +24,7 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
22
24
|
private _subscriptionManager;
|
|
23
25
|
private _providerFactoryManager;
|
|
24
26
|
private _batchFetcher;
|
|
25
|
-
constructor(dataProvider?: SyncBlockDataProviderInterface);
|
|
27
|
+
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode);
|
|
26
28
|
/**
|
|
27
29
|
* Enables or disables real-time GraphQL subscriptions for block updates.
|
|
28
30
|
* When enabled, the store manager will subscribe to real-time updates
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
2
3
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import type { ResourceId, SyncBlockAttrs, BlockInstanceId, DeletionReason, ReferenceSyncBlockData } from '../common/types';
|
|
4
5
|
import type { SyncBlockDataProviderInterface, SyncBlockSourceInfo } from '../providers/types';
|
|
@@ -7,6 +8,7 @@ type OnDelete = () => void;
|
|
|
7
8
|
type OnCompletion = (success: boolean) => void;
|
|
8
9
|
type DestroyCallback = () => void;
|
|
9
10
|
export declare class SourceSyncBlockStoreManager {
|
|
11
|
+
private viewMode?;
|
|
10
12
|
private dataProvider?;
|
|
11
13
|
private fireAnalyticsEvent?;
|
|
12
14
|
private syncBlockCache;
|
|
@@ -19,7 +21,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
19
21
|
private saveExperience;
|
|
20
22
|
private deleteExperience;
|
|
21
23
|
private fetchSourceInfoExperience;
|
|
22
|
-
constructor(dataProvider?: SyncBlockDataProviderInterface);
|
|
24
|
+
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode);
|
|
23
25
|
/**
|
|
24
26
|
* Register a callback to be invoked after flush() completes.
|
|
25
27
|
* Used by the pm-plugin to dispatch a transaction so that
|