@atlaskit/editor-synced-block-provider 4.3.1 → 4.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +33 -73
- package/CHANGELOG.md +21 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +45 -37
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +86 -40
- 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 +36 -2
- 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 +86 -40
- 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 +6 -2
- 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 +6 -2
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +3 -1
- package/package.json +3 -3
|
@@ -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);
|
|
@@ -313,11 +332,16 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
313
332
|
/**
|
|
314
333
|
* Create a bodiedSyncBlock node with empty content to backend
|
|
315
334
|
* @param attrs attributes Ids of the node
|
|
335
|
+
* @param node the ProseMirror node to cache
|
|
336
|
+
* @param onCompletion callback invoked when creation completes
|
|
316
337
|
*/
|
|
317
338
|
}, {
|
|
318
339
|
key: "createBodiedSyncBlockNode",
|
|
319
|
-
value: function createBodiedSyncBlockNode(attrs, onCompletion) {
|
|
340
|
+
value: function createBodiedSyncBlockNode(attrs, node, onCompletion) {
|
|
320
341
|
var _this4 = this;
|
|
342
|
+
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
321
345
|
var resourceId = attrs.resourceId,
|
|
322
346
|
blockInstanceId = attrs.localId;
|
|
323
347
|
try {
|
|
@@ -325,6 +349,10 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
325
349
|
if (!this.dataProvider) {
|
|
326
350
|
throw new Error('Data provider not set');
|
|
327
351
|
}
|
|
352
|
+
if (fg('platform_synced_block_update_refactor')) {
|
|
353
|
+
// add the node to the cache
|
|
354
|
+
this.updateSyncBlockData(node);
|
|
355
|
+
}
|
|
328
356
|
this.creationCompletionCallbacks.set(resourceId, onCompletion);
|
|
329
357
|
(_this$createExperienc = this.createExperience) === null || _this$createExperienc === void 0 || _this$createExperienc.start({});
|
|
330
358
|
this.dataProvider.createNodeData({
|
|
@@ -377,21 +405,27 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
377
405
|
while (1) switch (_context2.prev = _context2.next) {
|
|
378
406
|
case 0:
|
|
379
407
|
_context2.prev = 0;
|
|
380
|
-
if (this.
|
|
408
|
+
if (!(this.viewMode === 'view' && fg('platform_synced_block_patch_8'))) {
|
|
381
409
|
_context2.next = 3;
|
|
382
410
|
break;
|
|
383
411
|
}
|
|
384
|
-
|
|
412
|
+
return _context2.abrupt("return", false);
|
|
385
413
|
case 3:
|
|
414
|
+
if (this.dataProvider) {
|
|
415
|
+
_context2.next = 5;
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
throw new Error('Data provider not set');
|
|
419
|
+
case 5:
|
|
386
420
|
syncBlockIds.forEach(function (Ids) {
|
|
387
421
|
_this5.setPendingDeletion(Ids, true);
|
|
388
422
|
});
|
|
389
423
|
(_this$deleteExperienc = this.deleteExperience) === null || _this$deleteExperienc === void 0 || _this$deleteExperienc.start({});
|
|
390
|
-
_context2.next =
|
|
424
|
+
_context2.next = 9;
|
|
391
425
|
return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
|
|
392
426
|
return attrs.resourceId;
|
|
393
427
|
}), reason);
|
|
394
|
-
case
|
|
428
|
+
case 9:
|
|
395
429
|
results = _context2.sent;
|
|
396
430
|
isDeleteSuccessful = results.every(function (result) {
|
|
397
431
|
return result.success;
|
|
@@ -425,8 +459,8 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
425
459
|
}
|
|
426
460
|
syncBlockIds.forEach(callback);
|
|
427
461
|
return _context2.abrupt("return", isDeleteSuccessful);
|
|
428
|
-
case
|
|
429
|
-
_context2.prev =
|
|
462
|
+
case 17:
|
|
463
|
+
_context2.prev = 17;
|
|
430
464
|
_context2.t0 = _context2["catch"](0);
|
|
431
465
|
syncBlockIds.forEach(function (Ids) {
|
|
432
466
|
var _this5$fireAnalyticsE4;
|
|
@@ -438,11 +472,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
438
472
|
});
|
|
439
473
|
onDeleteCompleted(false);
|
|
440
474
|
return _context2.abrupt("return", false);
|
|
441
|
-
case
|
|
475
|
+
case 23:
|
|
442
476
|
case "end":
|
|
443
477
|
return _context2.stop();
|
|
444
478
|
}
|
|
445
|
-
}, _callee2, this, [[0,
|
|
479
|
+
}, _callee2, this, [[0, 17]]);
|
|
446
480
|
}));
|
|
447
481
|
function _delete(_x, _x2, _x3, _x4) {
|
|
448
482
|
return _delete2.apply(this, arguments);
|
|
@@ -462,20 +496,26 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
462
496
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
463
497
|
while (1) switch (_context3.prev = _context3.next) {
|
|
464
498
|
case 0:
|
|
465
|
-
if (this.
|
|
499
|
+
if (!(this.viewMode === 'view' && fg('platform_synced_block_patch_8'))) {
|
|
466
500
|
_context3.next = 2;
|
|
467
501
|
break;
|
|
468
502
|
}
|
|
469
503
|
return _context3.abrupt("return", Promise.resolve());
|
|
470
504
|
case 2:
|
|
505
|
+
if (this.deletionRetryInfo) {
|
|
506
|
+
_context3.next = 4;
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
return _context3.abrupt("return", Promise.resolve());
|
|
510
|
+
case 4:
|
|
471
511
|
_this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted, deletionReason = _this$deletionRetryIn.deletionReason;
|
|
472
512
|
if (!this.confirmationCallback) {
|
|
473
|
-
_context3.next =
|
|
513
|
+
_context3.next = 8;
|
|
474
514
|
break;
|
|
475
515
|
}
|
|
476
|
-
_context3.next =
|
|
516
|
+
_context3.next = 8;
|
|
477
517
|
return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
|
|
478
|
-
case
|
|
518
|
+
case 8:
|
|
479
519
|
case "end":
|
|
480
520
|
return _context3.stop();
|
|
481
521
|
}
|
|
@@ -509,21 +549,27 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
509
549
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
510
550
|
while (1) switch (_context4.prev = _context4.next) {
|
|
511
551
|
case 0:
|
|
552
|
+
if (!(this.viewMode === 'view' && fg('platform_synced_block_patch_8'))) {
|
|
553
|
+
_context4.next = 2;
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
return _context4.abrupt("return", Promise.resolve());
|
|
557
|
+
case 2:
|
|
512
558
|
if (!this.confirmationCallback) {
|
|
513
|
-
_context4.next =
|
|
559
|
+
_context4.next = 14;
|
|
514
560
|
break;
|
|
515
561
|
}
|
|
516
|
-
_context4.next =
|
|
562
|
+
_context4.next = 5;
|
|
517
563
|
return this.confirmationCallback(syncBlockIds, deletionReason);
|
|
518
|
-
case
|
|
564
|
+
case 5:
|
|
519
565
|
confirmed = _context4.sent;
|
|
520
566
|
if (!confirmed) {
|
|
521
|
-
_context4.next =
|
|
567
|
+
_context4.next = 13;
|
|
522
568
|
break;
|
|
523
569
|
}
|
|
524
|
-
_context4.next =
|
|
570
|
+
_context4.next = 9;
|
|
525
571
|
return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
|
|
526
|
-
case
|
|
572
|
+
case 9:
|
|
527
573
|
isDeleteSuccessful = _context4.sent;
|
|
528
574
|
if (!isDeleteSuccessful) {
|
|
529
575
|
// If deletion failed, save deletion info for potential retry
|
|
@@ -537,11 +583,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
537
583
|
} else {
|
|
538
584
|
destroyCallback();
|
|
539
585
|
}
|
|
540
|
-
_context4.next =
|
|
586
|
+
_context4.next = 14;
|
|
541
587
|
break;
|
|
542
|
-
case
|
|
588
|
+
case 13:
|
|
543
589
|
destroyCallback();
|
|
544
|
-
case
|
|
590
|
+
case 14:
|
|
545
591
|
case "end":
|
|
546
592
|
return _context4.stop();
|
|
547
593
|
}
|
|
@@ -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
|