@atlaskit/editor-synced-block-provider 22.0.5 → 22.1.0
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 +17 -0
- package/dist/cjs/providers/syncBlockProvider.js +5 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +16 -9
- package/dist/cjs/store-manager/syncBlockStoreManager.js +171 -88
- package/dist/es2019/providers/syncBlockProvider.js +3 -0
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +14 -9
- package/dist/es2019/store-manager/syncBlockStoreManager.js +59 -15
- package/dist/esm/providers/syncBlockProvider.js +5 -0
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +16 -9
- package/dist/esm/store-manager/syncBlockStoreManager.js +171 -88
- package/dist/types/providers/syncBlockProvider.d.ts +1 -0
- package/dist/types/providers/types.d.ts +1 -0
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +2 -1
- package/package.json +2 -2
|
@@ -127,6 +127,10 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
127
127
|
getSubscribedResourceIds() {
|
|
128
128
|
return this._subscriptionManager.getSubscribedResourceIds();
|
|
129
129
|
}
|
|
130
|
+
getSubscribedLocalIds(resourceId) {
|
|
131
|
+
var _this$_subscriptionMa;
|
|
132
|
+
return Object.keys((_this$_subscriptionMa = this._subscriptionManager.getSubscriptions().get(resourceId)) !== null && _this$_subscriptionMa !== void 0 ? _this$_subscriptionMa : {});
|
|
133
|
+
}
|
|
130
134
|
|
|
131
135
|
/**
|
|
132
136
|
* Registers a listener that will be called when subscriptions change.
|
|
@@ -188,8 +192,9 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
188
192
|
return this.getFromSessionCache(resourceId);
|
|
189
193
|
}
|
|
190
194
|
getSameDocumentReferenceParts(resourceId) {
|
|
195
|
+
var _this$dataProvider$ca, _this$dataProvider3;
|
|
191
196
|
const parsed = parseResourceId(resourceId);
|
|
192
|
-
if (!parsed || !this.dataProvider || this.dataProvider.generateResourceIdForReference(parsed.uuid) !== resourceId) {
|
|
197
|
+
if (!parsed || !this.dataProvider || isExperimentEnabled('platform_editor_blocks_patch_12') && ((_this$dataProvider$ca = (_this$dataProvider3 = this.dataProvider).canGenerateResourceIdForReference) === null || _this$dataProvider$ca === void 0 ? void 0 : _this$dataProvider$ca.call(_this$dataProvider3)) === false || this.dataProvider.generateResourceIdForReference(parsed.uuid) !== resourceId) {
|
|
193
198
|
return undefined;
|
|
194
199
|
}
|
|
195
200
|
return parsed;
|
|
@@ -626,8 +631,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
626
631
|
resourceId
|
|
627
632
|
} = sanitizedSyncBlock;
|
|
628
633
|
if (resourceId) {
|
|
629
|
-
var _this$
|
|
630
|
-
(_this$
|
|
634
|
+
var _this$dataProvider4;
|
|
635
|
+
(_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 ? void 0 : _this$dataProvider4.updateCache({
|
|
631
636
|
[resourceId]: sanitizedSyncBlock
|
|
632
637
|
}, {
|
|
633
638
|
strategy: 'merge',
|
|
@@ -638,13 +643,13 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
638
643
|
}
|
|
639
644
|
}
|
|
640
645
|
getFromCache(resourceId) {
|
|
641
|
-
var _this$
|
|
646
|
+
var _this$dataProvider5, _this$dataProvider5$g;
|
|
642
647
|
const syncBlockNode = createSyncBlockNode('', resourceId);
|
|
643
|
-
return (_this$
|
|
648
|
+
return (_this$dataProvider5 = this.dataProvider) === null || _this$dataProvider5 === void 0 ? void 0 : (_this$dataProvider5$g = _this$dataProvider5.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider5$g === void 0 ? void 0 : _this$dataProvider5$g.data;
|
|
644
649
|
}
|
|
645
650
|
deleteFromCache(resourceId) {
|
|
646
|
-
var _this$
|
|
647
|
-
(_this$
|
|
651
|
+
var _this$dataProvider6;
|
|
652
|
+
(_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 ? void 0 : _this$dataProvider6.removeFromCache([resourceId]);
|
|
648
653
|
this._providerFactoryManager.deleteFactory(resourceId);
|
|
649
654
|
// Evict in-flight source-info promise and reset reschedule counter
|
|
650
655
|
// so a stale resolution can't silently merge into a re-fetched entry.
|
|
@@ -1031,7 +1036,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
1031
1036
|
return success;
|
|
1032
1037
|
}
|
|
1033
1038
|
destroy() {
|
|
1034
|
-
var _this$
|
|
1039
|
+
var _this$dataProvider7, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo6;
|
|
1035
1040
|
// Mark destroyed first so in-flight timer callbacks can early-return.
|
|
1036
1041
|
this.isDestroyed = true;
|
|
1037
1042
|
|
|
@@ -1053,7 +1058,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
1053
1058
|
this._subscriptionManager.destroy();
|
|
1054
1059
|
this._providerFactoryManager.destroy();
|
|
1055
1060
|
this._batchFetcher.destroy();
|
|
1056
|
-
(_this$
|
|
1061
|
+
(_this$dataProvider7 = this.dataProvider) === null || _this$dataProvider7 === void 0 ? void 0 : _this$dataProvider7.resetCache();
|
|
1057
1062
|
this.dataProvider = undefined;
|
|
1058
1063
|
this.syncBlockFetchDataRequests.clear();
|
|
1059
1064
|
this.syncBlockSourceInfoRequests.clear();
|
|
@@ -29,9 +29,21 @@ export class SyncBlockStoreManager {
|
|
|
29
29
|
isSyncBlock(node) {
|
|
30
30
|
return this.sourceSyncBlockStoreManager.isSourceBlock(node) || this.referenceSyncBlockStoreManager.isReferenceBlock(node);
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
getDocumentReferenceIds(resourceId, doc) {
|
|
33
|
+
if (!doc) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
const localIds = new Set();
|
|
37
|
+
doc.descendants(node => {
|
|
38
|
+
if (this.referenceManager.isReferenceBlock(node) && node.attrs.resourceId === resourceId && node.attrs.localId) {
|
|
39
|
+
localIds.add(node.attrs.localId);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return localIds;
|
|
43
|
+
}
|
|
44
|
+
async fetchReferencesSourceInfo(resourceId, blockInstanceId, isSourceSyncBlock, doc) {
|
|
33
45
|
try {
|
|
34
|
-
var _this$fetchReferences, _response$references, _this$
|
|
46
|
+
var _this$fetchReferences, _response$references, _this$fetchReferences4;
|
|
35
47
|
if (!this.dataProvider) {
|
|
36
48
|
throw new Error('Data provider not set');
|
|
37
49
|
}
|
|
@@ -46,11 +58,24 @@ export class SyncBlockStoreManager {
|
|
|
46
58
|
error: response.error
|
|
47
59
|
};
|
|
48
60
|
}
|
|
49
|
-
|
|
61
|
+
const patchEnabled = isExperimentEnabled('platform_editor_blocks_patch_12');
|
|
62
|
+
const referenceResourceId = patchEnabled && isSourceSyncBlock ? this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId) : resourceId;
|
|
63
|
+
const documentIds = patchEnabled ? this.getDocumentReferenceIds(referenceResourceId, doc) : undefined;
|
|
64
|
+
const localIds = patchEnabled ? documentIds ? [...documentIds] : this.referenceSyncBlockStoreManager.getSubscribedLocalIds(referenceResourceId) : [];
|
|
65
|
+
// Saved references on this document can already have been removed in the editor.
|
|
66
|
+
const references = ((_response$references = response.references) !== null && _response$references !== void 0 ? _response$references : []).filter(reference => documentIds === undefined || !reference.onSameDocument || Boolean(reference.blockInstanceId && documentIds.has(reference.blockInstanceId)));
|
|
67
|
+
if (references.length === 0 && localIds.length === 0) {
|
|
68
|
+
if (documentIds !== undefined) {
|
|
69
|
+
var _this$fetchReferences3;
|
|
70
|
+
(_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 ? void 0 : _this$fetchReferences3.success();
|
|
71
|
+
return {
|
|
72
|
+
references: []
|
|
73
|
+
};
|
|
74
|
+
}
|
|
50
75
|
return this.getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock);
|
|
51
76
|
}
|
|
52
|
-
(_this$
|
|
53
|
-
const sourceInfoPromises =
|
|
77
|
+
(_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 ? void 0 : _this$fetchReferences4.success();
|
|
78
|
+
const sourceInfoPromises = references.map(async reference => {
|
|
54
79
|
var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
|
|
55
80
|
if (!reference.hasAccess && isExperimentEnabled('platform_editor_blocks_patch_11')) {
|
|
56
81
|
return this.fetchRestrictedReferenceInfo(reference.documentAri);
|
|
@@ -86,6 +111,25 @@ export class SyncBlockStoreManager {
|
|
|
86
111
|
productType: sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.productType
|
|
87
112
|
});
|
|
88
113
|
}
|
|
114
|
+
|
|
115
|
+
// Only instances in this editor belong to its unsaved document. A matching
|
|
116
|
+
// local ID on another document must not hide an unsaved copy here.
|
|
117
|
+
const registeredLocalIds = new Set();
|
|
118
|
+
for (const reference of references) {
|
|
119
|
+
if (reference.onSameDocument && reference.blockInstanceId) {
|
|
120
|
+
registeredLocalIds.add(reference.blockInstanceId);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const localSourceInfos = await Promise.all(localIds.filter(localId => !registeredLocalIds.has(localId)).map(async localId => {
|
|
124
|
+
const sourceInfo = await this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(localId);
|
|
125
|
+
return sourceInfo ? {
|
|
126
|
+
...sourceInfo,
|
|
127
|
+
onSameDocument: true,
|
|
128
|
+
hasAccess: true,
|
|
129
|
+
isSource: false
|
|
130
|
+
} : undefined;
|
|
131
|
+
}));
|
|
132
|
+
sourceInfos.push(...localSourceInfos);
|
|
89
133
|
return {
|
|
90
134
|
references: sourceInfos
|
|
91
135
|
};
|
|
@@ -114,10 +158,10 @@ export class SyncBlockStoreManager {
|
|
|
114
158
|
return this.sourceSyncBlockStoreManager;
|
|
115
159
|
}
|
|
116
160
|
destroy() {
|
|
117
|
-
var _this$
|
|
161
|
+
var _this$fetchReferences5, _this$fetchSourceInfo4;
|
|
118
162
|
this.referenceSyncBlockStoreManager.destroy();
|
|
119
163
|
this.sourceSyncBlockStoreManager.destroy();
|
|
120
|
-
(_this$
|
|
164
|
+
(_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 ? void 0 : _this$fetchReferences5.abort({
|
|
121
165
|
reason: 'editorDestroyed'
|
|
122
166
|
});
|
|
123
167
|
(_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 ? void 0 : _this$fetchSourceInfo4.abort({
|
|
@@ -161,17 +205,17 @@ export class SyncBlockStoreManager {
|
|
|
161
205
|
};
|
|
162
206
|
}
|
|
163
207
|
async getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock) {
|
|
164
|
-
var _this$
|
|
208
|
+
var _this$fetchReferences9;
|
|
165
209
|
// No reference found
|
|
166
210
|
if (isSourceSyncBlock) {
|
|
167
|
-
var _this$
|
|
211
|
+
var _this$fetchReferences7;
|
|
168
212
|
// Verify that a reference sync block for this specific source actually
|
|
169
213
|
// exists on the current page by checking if the reference manager has
|
|
170
214
|
// an active subscription for the derived reference resourceId.
|
|
171
215
|
const referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
|
|
172
216
|
const hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
|
|
173
217
|
if (hasUnregisteredReferenceOnPage) {
|
|
174
|
-
var _this$
|
|
218
|
+
var _this$fetchReferences6;
|
|
175
219
|
// This is current page data. It is the same for data for source and reference
|
|
176
220
|
const sourceSyncBlockData = await this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
|
|
177
221
|
const references = [];
|
|
@@ -190,14 +234,14 @@ export class SyncBlockStoreManager {
|
|
|
190
234
|
};
|
|
191
235
|
references.push(sourceSyncBlockReference, referenceSyncBlockReference);
|
|
192
236
|
}
|
|
193
|
-
(_this$
|
|
237
|
+
(_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 ? void 0 : _this$fetchReferences6.success();
|
|
194
238
|
return {
|
|
195
239
|
references
|
|
196
240
|
};
|
|
197
241
|
}
|
|
198
242
|
|
|
199
243
|
// No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
|
|
200
|
-
(_this$
|
|
244
|
+
(_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 ? void 0 : _this$fetchReferences7.success();
|
|
201
245
|
return {
|
|
202
246
|
references: []
|
|
203
247
|
};
|
|
@@ -226,15 +270,15 @@ export class SyncBlockStoreManager {
|
|
|
226
270
|
});
|
|
227
271
|
}
|
|
228
272
|
if (references.length === 0) {
|
|
229
|
-
var _this$
|
|
230
|
-
(_this$
|
|
273
|
+
var _this$fetchReferences8;
|
|
274
|
+
(_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 ? void 0 : _this$fetchReferences8.failure({
|
|
231
275
|
reason: 'No references found for reference synced block'
|
|
232
276
|
});
|
|
233
277
|
return {
|
|
234
278
|
error: SyncBlockError.Errored
|
|
235
279
|
};
|
|
236
280
|
}
|
|
237
|
-
(_this$
|
|
281
|
+
(_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 ? void 0 : _this$fetchReferences9.success();
|
|
238
282
|
return {
|
|
239
283
|
references
|
|
240
284
|
};
|
|
@@ -391,6 +391,11 @@ export var SyncedBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
391
391
|
resourceId: resourceId
|
|
392
392
|
};
|
|
393
393
|
}
|
|
394
|
+
}, {
|
|
395
|
+
key: "canGenerateResourceIdForReference",
|
|
396
|
+
value: function canGenerateResourceIdForReference() {
|
|
397
|
+
return this.writeProvider !== undefined;
|
|
398
|
+
}
|
|
394
399
|
}, {
|
|
395
400
|
key: "generateResourceIdForReference",
|
|
396
401
|
value: function generateResourceIdForReference(sourceId) {
|
|
@@ -180,6 +180,12 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
180
180
|
value: function getSubscribedResourceIds() {
|
|
181
181
|
return this._subscriptionManager.getSubscribedResourceIds();
|
|
182
182
|
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "getSubscribedLocalIds",
|
|
185
|
+
value: function getSubscribedLocalIds(resourceId) {
|
|
186
|
+
var _this$_subscriptionMa;
|
|
187
|
+
return Object.keys((_this$_subscriptionMa = this._subscriptionManager.getSubscriptions().get(resourceId)) !== null && _this$_subscriptionMa !== void 0 ? _this$_subscriptionMa : {});
|
|
188
|
+
}
|
|
183
189
|
|
|
184
190
|
/**
|
|
185
191
|
* Registers a listener that will be called when subscriptions change.
|
|
@@ -259,8 +265,9 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
259
265
|
}, {
|
|
260
266
|
key: "getSameDocumentReferenceParts",
|
|
261
267
|
value: function getSameDocumentReferenceParts(resourceId) {
|
|
268
|
+
var _this$dataProvider$ca, _this$dataProvider3;
|
|
262
269
|
var parsed = parseResourceId(resourceId);
|
|
263
|
-
if (!parsed || !this.dataProvider || this.dataProvider.generateResourceIdForReference(parsed.uuid) !== resourceId) {
|
|
270
|
+
if (!parsed || !this.dataProvider || isExperimentEnabled('platform_editor_blocks_patch_12') && ((_this$dataProvider$ca = (_this$dataProvider3 = this.dataProvider).canGenerateResourceIdForReference) === null || _this$dataProvider$ca === void 0 ? void 0 : _this$dataProvider$ca.call(_this$dataProvider3)) === false || this.dataProvider.generateResourceIdForReference(parsed.uuid) !== resourceId) {
|
|
264
271
|
return undefined;
|
|
265
272
|
}
|
|
266
273
|
return parsed;
|
|
@@ -754,8 +761,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
754
761
|
var sanitizedSyncBlock = this.normalizeReferenceData(syncBlock);
|
|
755
762
|
var resourceId = sanitizedSyncBlock.resourceId;
|
|
756
763
|
if (resourceId) {
|
|
757
|
-
var _this$
|
|
758
|
-
(_this$
|
|
764
|
+
var _this$dataProvider4;
|
|
765
|
+
(_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 || _this$dataProvider4.updateCache(_defineProperty({}, resourceId, sanitizedSyncBlock), {
|
|
759
766
|
strategy: 'merge',
|
|
760
767
|
source: 'network'
|
|
761
768
|
});
|
|
@@ -766,15 +773,15 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
766
773
|
}, {
|
|
767
774
|
key: "getFromCache",
|
|
768
775
|
value: function getFromCache(resourceId) {
|
|
769
|
-
var _this$
|
|
776
|
+
var _this$dataProvider5;
|
|
770
777
|
var syncBlockNode = createSyncBlockNode('', resourceId);
|
|
771
|
-
return (_this$
|
|
778
|
+
return (_this$dataProvider5 = this.dataProvider) === null || _this$dataProvider5 === void 0 || (_this$dataProvider5 = _this$dataProvider5.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider5 === void 0 ? void 0 : _this$dataProvider5.data;
|
|
772
779
|
}
|
|
773
780
|
}, {
|
|
774
781
|
key: "deleteFromCache",
|
|
775
782
|
value: function deleteFromCache(resourceId) {
|
|
776
|
-
var _this$
|
|
777
|
-
(_this$
|
|
783
|
+
var _this$dataProvider6;
|
|
784
|
+
(_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 || _this$dataProvider6.removeFromCache([resourceId]);
|
|
778
785
|
this._providerFactoryManager.deleteFactory(resourceId);
|
|
779
786
|
// Evict in-flight source-info promise and reset reschedule counter
|
|
780
787
|
// so a stale resolution can't silently merge into a re-fetched entry.
|
|
@@ -1258,7 +1265,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
1258
1265
|
}, {
|
|
1259
1266
|
key: "destroy",
|
|
1260
1267
|
value: function destroy() {
|
|
1261
|
-
var _this$
|
|
1268
|
+
var _this$dataProvider7, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo2;
|
|
1262
1269
|
// Mark destroyed first so in-flight timer callbacks can early-return.
|
|
1263
1270
|
this.isDestroyed = true;
|
|
1264
1271
|
|
|
@@ -1284,7 +1291,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
1284
1291
|
this._subscriptionManager.destroy();
|
|
1285
1292
|
this._providerFactoryManager.destroy();
|
|
1286
1293
|
this._batchFetcher.destroy();
|
|
1287
|
-
(_this$
|
|
1294
|
+
(_this$dataProvider7 = this.dataProvider) === null || _this$dataProvider7 === void 0 || _this$dataProvider7.resetCache();
|
|
1288
1295
|
this.dataProvider = undefined;
|
|
1289
1296
|
this.syncBlockFetchDataRequests.clear();
|
|
1290
1297
|
this.syncBlockSourceInfoRequests.clear();
|