@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 22.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`63c2a47db7f66`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/63c2a47db7f66) -
|
|
8
|
+
Pass the current editor document into the lookup for synced locations behind
|
|
9
|
+
platform_editor_blocks_patch_12, including references added, removed, or unsynced before saving.
|
|
10
|
+
Reconcile saved references with the current document, preserving locations on other documents.
|
|
11
|
+
|
|
12
|
+
## 22.0.6
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [`ed9aabfa3a701`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ed9aabfa3a701) -
|
|
17
|
+
Fix synced-block reference rendering with fetch-only providers by skipping local same-document
|
|
18
|
+
detection when reference IDs cannot be generated.
|
|
19
|
+
|
|
3
20
|
## 22.0.5
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -398,6 +398,11 @@ var SyncedBlockProvider = exports.SyncedBlockProvider = /*#__PURE__*/function (_
|
|
|
398
398
|
resourceId: resourceId
|
|
399
399
|
};
|
|
400
400
|
}
|
|
401
|
+
}, {
|
|
402
|
+
key: "canGenerateResourceIdForReference",
|
|
403
|
+
value: function canGenerateResourceIdForReference() {
|
|
404
|
+
return this.writeProvider !== undefined;
|
|
405
|
+
}
|
|
401
406
|
}, {
|
|
402
407
|
key: "generateResourceIdForReference",
|
|
403
408
|
value: function generateResourceIdForReference(sourceId) {
|
|
@@ -187,6 +187,12 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
187
187
|
value: function getSubscribedResourceIds() {
|
|
188
188
|
return this._subscriptionManager.getSubscribedResourceIds();
|
|
189
189
|
}
|
|
190
|
+
}, {
|
|
191
|
+
key: "getSubscribedLocalIds",
|
|
192
|
+
value: function getSubscribedLocalIds(resourceId) {
|
|
193
|
+
var _this$_subscriptionMa;
|
|
194
|
+
return Object.keys((_this$_subscriptionMa = this._subscriptionManager.getSubscriptions().get(resourceId)) !== null && _this$_subscriptionMa !== void 0 ? _this$_subscriptionMa : {});
|
|
195
|
+
}
|
|
190
196
|
|
|
191
197
|
/**
|
|
192
198
|
* Registers a listener that will be called when subscriptions change.
|
|
@@ -266,8 +272,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
266
272
|
}, {
|
|
267
273
|
key: "getSameDocumentReferenceParts",
|
|
268
274
|
value: function getSameDocumentReferenceParts(resourceId) {
|
|
275
|
+
var _this$dataProvider$ca, _this$dataProvider3;
|
|
269
276
|
var parsed = (0, _resourceId.parseResourceId)(resourceId);
|
|
270
|
-
if (!parsed || !this.dataProvider || this.dataProvider.generateResourceIdForReference(parsed.uuid) !== resourceId) {
|
|
277
|
+
if (!parsed || !this.dataProvider || (0, _isExperimentEnabled.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) {
|
|
271
278
|
return undefined;
|
|
272
279
|
}
|
|
273
280
|
return parsed;
|
|
@@ -761,8 +768,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
761
768
|
var sanitizedSyncBlock = this.normalizeReferenceData(syncBlock);
|
|
762
769
|
var resourceId = sanitizedSyncBlock.resourceId;
|
|
763
770
|
if (resourceId) {
|
|
764
|
-
var _this$
|
|
765
|
-
(_this$
|
|
771
|
+
var _this$dataProvider4;
|
|
772
|
+
(_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 || _this$dataProvider4.updateCache((0, _defineProperty2.default)({}, resourceId, sanitizedSyncBlock), {
|
|
766
773
|
strategy: 'merge',
|
|
767
774
|
source: 'network'
|
|
768
775
|
});
|
|
@@ -773,15 +780,15 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
773
780
|
}, {
|
|
774
781
|
key: "getFromCache",
|
|
775
782
|
value: function getFromCache(resourceId) {
|
|
776
|
-
var _this$
|
|
783
|
+
var _this$dataProvider5;
|
|
777
784
|
var syncBlockNode = (0, _utils.createSyncBlockNode)('', resourceId);
|
|
778
|
-
return (_this$
|
|
785
|
+
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;
|
|
779
786
|
}
|
|
780
787
|
}, {
|
|
781
788
|
key: "deleteFromCache",
|
|
782
789
|
value: function deleteFromCache(resourceId) {
|
|
783
|
-
var _this$
|
|
784
|
-
(_this$
|
|
790
|
+
var _this$dataProvider6;
|
|
791
|
+
(_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 || _this$dataProvider6.removeFromCache([resourceId]);
|
|
785
792
|
this._providerFactoryManager.deleteFactory(resourceId);
|
|
786
793
|
// Evict in-flight source-info promise and reset reschedule counter
|
|
787
794
|
// so a stale resolution can't silently merge into a re-fetched entry.
|
|
@@ -1265,7 +1272,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
1265
1272
|
}, {
|
|
1266
1273
|
key: "destroy",
|
|
1267
1274
|
value: function destroy() {
|
|
1268
|
-
var _this$
|
|
1275
|
+
var _this$dataProvider7, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo2;
|
|
1269
1276
|
// Mark destroyed first so in-flight timer callbacks can early-return.
|
|
1270
1277
|
this.isDestroyed = true;
|
|
1271
1278
|
|
|
@@ -1291,7 +1298,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
1291
1298
|
this._subscriptionManager.destroy();
|
|
1292
1299
|
this._providerFactoryManager.destroy();
|
|
1293
1300
|
this._batchFetcher.destroy();
|
|
1294
|
-
(_this$
|
|
1301
|
+
(_this$dataProvider7 = this.dataProvider) === null || _this$dataProvider7 === void 0 || _this$dataProvider7.resetCache();
|
|
1295
1302
|
this.dataProvider = undefined;
|
|
1296
1303
|
this.syncBlockFetchDataRequests.clear();
|
|
1297
1304
|
this.syncBlockSourceInfoRequests.clear();
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.useMemoizedSyncBlockStoreManager = exports.SyncBlockStoreManager = void 0;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
11
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
12
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
13
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -20,6 +21,9 @@ var _experienceTracking = require("../utils/experienceTracking");
|
|
|
20
21
|
var _utils = require("../utils/utils");
|
|
21
22
|
var _referenceSyncBlockStoreManager = require("./referenceSyncBlockStoreManager");
|
|
22
23
|
var _sourceSyncBlockStoreManager = require("./sourceSyncBlockStoreManager");
|
|
24
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
25
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
26
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
23
27
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
24
28
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
25
29
|
// A parent store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
|
|
@@ -44,49 +48,80 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
44
48
|
value: function isSyncBlock(node) {
|
|
45
49
|
return this.sourceSyncBlockStoreManager.isSourceBlock(node) || this.referenceSyncBlockStoreManager.isReferenceBlock(node);
|
|
46
50
|
}
|
|
51
|
+
}, {
|
|
52
|
+
key: "getDocumentReferenceIds",
|
|
53
|
+
value: function getDocumentReferenceIds(resourceId, doc) {
|
|
54
|
+
var _this = this;
|
|
55
|
+
if (!doc) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
var localIds = new Set();
|
|
59
|
+
doc.descendants(function (node) {
|
|
60
|
+
if (_this.referenceManager.isReferenceBlock(node) && node.attrs.resourceId === resourceId && node.attrs.localId) {
|
|
61
|
+
localIds.add(node.attrs.localId);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return localIds;
|
|
65
|
+
}
|
|
47
66
|
}, {
|
|
48
67
|
key: "fetchReferencesSourceInfo",
|
|
49
68
|
value: function () {
|
|
50
|
-
var _fetchReferencesSourceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
51
|
-
var
|
|
52
|
-
var _this$fetchReferences, _response$references, _this$
|
|
53
|
-
return _regenerator.default.wrap(function (
|
|
54
|
-
while (1) switch (
|
|
69
|
+
var _fetchReferencesSourceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resourceId, blockInstanceId, isSourceSyncBlock, doc) {
|
|
70
|
+
var _this2 = this;
|
|
71
|
+
var _this$fetchReferences, _response$references, _this$fetchReferences4, response, _this$fetchReferences2, patchEnabled, referenceResourceId, documentIds, localIds, references, _this$fetchReferences3, sourceInfoPromises, sourceInfos, sourceSyncBlockData, registeredLocalIds, _iterator, _step, reference, localSourceInfos, _this$fireAnalyticsEv, _t;
|
|
72
|
+
return _regenerator.default.wrap(function (_context3) {
|
|
73
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
55
74
|
case 0:
|
|
56
|
-
|
|
75
|
+
_context3.prev = 0;
|
|
57
76
|
if (this.dataProvider) {
|
|
58
|
-
|
|
77
|
+
_context3.next = 1;
|
|
59
78
|
break;
|
|
60
79
|
}
|
|
61
80
|
throw new Error('Data provider not set');
|
|
62
81
|
case 1:
|
|
63
82
|
(_this$fetchReferences = this.fetchReferencesExperience) === null || _this$fetchReferences === void 0 || _this$fetchReferences.start();
|
|
64
|
-
|
|
83
|
+
_context3.next = 2;
|
|
65
84
|
return this.dataProvider.fetchReferences(resourceId, isSourceSyncBlock);
|
|
66
85
|
case 2:
|
|
67
|
-
response =
|
|
86
|
+
response = _context3.sent;
|
|
68
87
|
if (!response.error) {
|
|
69
|
-
|
|
88
|
+
_context3.next = 3;
|
|
70
89
|
break;
|
|
71
90
|
}
|
|
72
91
|
(_this$fetchReferences2 = this.fetchReferencesExperience) === null || _this$fetchReferences2 === void 0 || _this$fetchReferences2.failure({
|
|
73
92
|
reason: response.error
|
|
74
93
|
});
|
|
75
|
-
return
|
|
94
|
+
return _context3.abrupt("return", {
|
|
76
95
|
error: response.error
|
|
77
96
|
});
|
|
78
97
|
case 3:
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
patchEnabled = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_blocks_patch_12');
|
|
99
|
+
referenceResourceId = patchEnabled && isSourceSyncBlock ? this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId) : resourceId;
|
|
100
|
+
documentIds = patchEnabled ? this.getDocumentReferenceIds(referenceResourceId, doc) : undefined;
|
|
101
|
+
localIds = patchEnabled ? documentIds ? (0, _toConsumableArray2.default)(documentIds) : this.referenceSyncBlockStoreManager.getSubscribedLocalIds(referenceResourceId) : []; // Saved references on this document can already have been removed in the editor.
|
|
102
|
+
references = ((_response$references = response.references) !== null && _response$references !== void 0 ? _response$references : []).filter(function (reference) {
|
|
103
|
+
return documentIds === undefined || !reference.onSameDocument || Boolean(reference.blockInstanceId && documentIds.has(reference.blockInstanceId));
|
|
104
|
+
});
|
|
105
|
+
if (!(references.length === 0 && localIds.length === 0)) {
|
|
106
|
+
_context3.next = 5;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (!(documentIds !== undefined)) {
|
|
110
|
+
_context3.next = 4;
|
|
81
111
|
break;
|
|
82
112
|
}
|
|
83
|
-
return _context2.abrupt("return", this.getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock));
|
|
84
|
-
case 4:
|
|
85
113
|
(_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
|
|
86
|
-
|
|
114
|
+
return _context3.abrupt("return", {
|
|
115
|
+
references: []
|
|
116
|
+
});
|
|
117
|
+
case 4:
|
|
118
|
+
return _context3.abrupt("return", this.getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock));
|
|
119
|
+
case 5:
|
|
120
|
+
(_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.success();
|
|
121
|
+
sourceInfoPromises = references.map( /*#__PURE__*/function () {
|
|
87
122
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(reference) {
|
|
88
|
-
var
|
|
89
|
-
var sourceInfo,
|
|
123
|
+
var _this2$fetchSourceInf, _this2$dataProvider, _this2$fetchSourceInf3;
|
|
124
|
+
var sourceInfo, _this2$fetchSourceInf2;
|
|
90
125
|
return _regenerator.default.wrap(function (_context) {
|
|
91
126
|
while (1) switch (_context.prev = _context.next) {
|
|
92
127
|
case 0:
|
|
@@ -94,23 +129,23 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
94
129
|
_context.next = 1;
|
|
95
130
|
break;
|
|
96
131
|
}
|
|
97
|
-
return _context.abrupt("return",
|
|
132
|
+
return _context.abrupt("return", _this2.fetchRestrictedReferenceInfo(reference.documentAri));
|
|
98
133
|
case 1:
|
|
99
|
-
(
|
|
134
|
+
(_this2$fetchSourceInf = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf === void 0 || _this2$fetchSourceInf.start();
|
|
100
135
|
_context.next = 2;
|
|
101
|
-
return (
|
|
136
|
+
return (_this2$dataProvider = _this2.dataProvider) === null || _this2$dataProvider === void 0 ? void 0 : _this2$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, (0, _ari.getProductFromSourceAri)(reference.documentAri), reference.hasAccess);
|
|
102
137
|
case 2:
|
|
103
138
|
sourceInfo = _context.sent;
|
|
104
139
|
if (sourceInfo) {
|
|
105
140
|
_context.next = 3;
|
|
106
141
|
break;
|
|
107
142
|
}
|
|
108
|
-
(
|
|
143
|
+
(_this2$fetchSourceInf2 = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf2 === void 0 || _this2$fetchSourceInf2.failure({
|
|
109
144
|
reason: "no source info returned for ari: ".concat(reference.documentAri)
|
|
110
145
|
});
|
|
111
146
|
return _context.abrupt("return", undefined);
|
|
112
147
|
case 3:
|
|
113
|
-
(
|
|
148
|
+
(_this2$fetchSourceInf3 = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf3 === void 0 || _this2$fetchSourceInf3.success();
|
|
114
149
|
return _context.abrupt("return", _objectSpread(_objectSpread(_objectSpread({}, sourceInfo), {}, {
|
|
115
150
|
onSameDocument: reference.onSameDocument
|
|
116
151
|
}, reference.locationScope !== undefined && {
|
|
@@ -125,18 +160,18 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
125
160
|
}
|
|
126
161
|
}, _callee);
|
|
127
162
|
}));
|
|
128
|
-
return function (
|
|
163
|
+
return function (_x5) {
|
|
129
164
|
return _ref.apply(this, arguments);
|
|
130
165
|
};
|
|
131
166
|
}());
|
|
132
|
-
|
|
167
|
+
_context3.next = 6;
|
|
133
168
|
return Promise.all(sourceInfoPromises);
|
|
134
|
-
case 5:
|
|
135
|
-
sourceInfos = _context2.sent;
|
|
136
|
-
_context2.next = 6;
|
|
137
|
-
return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
|
|
138
169
|
case 6:
|
|
139
|
-
|
|
170
|
+
sourceInfos = _context3.sent;
|
|
171
|
+
_context3.next = 7;
|
|
172
|
+
return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
|
|
173
|
+
case 7:
|
|
174
|
+
sourceSyncBlockData = _context3.sent;
|
|
140
175
|
if (sourceSyncBlockData) {
|
|
141
176
|
sourceInfos.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
|
|
142
177
|
onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
|
|
@@ -145,26 +180,74 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
145
180
|
productType: sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.productType
|
|
146
181
|
}));
|
|
147
182
|
}
|
|
148
|
-
|
|
183
|
+
|
|
184
|
+
// Only instances in this editor belong to its unsaved document. A matching
|
|
185
|
+
// local ID on another document must not hide an unsaved copy here.
|
|
186
|
+
registeredLocalIds = new Set();
|
|
187
|
+
_iterator = _createForOfIteratorHelper(references);
|
|
188
|
+
try {
|
|
189
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
190
|
+
reference = _step.value;
|
|
191
|
+
if (reference.onSameDocument && reference.blockInstanceId) {
|
|
192
|
+
registeredLocalIds.add(reference.blockInstanceId);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
} catch (err) {
|
|
196
|
+
_iterator.e(err);
|
|
197
|
+
} finally {
|
|
198
|
+
_iterator.f();
|
|
199
|
+
}
|
|
200
|
+
_context3.next = 8;
|
|
201
|
+
return Promise.all(localIds.filter(function (localId) {
|
|
202
|
+
return !registeredLocalIds.has(localId);
|
|
203
|
+
}).map( /*#__PURE__*/function () {
|
|
204
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(localId) {
|
|
205
|
+
var sourceInfo;
|
|
206
|
+
return _regenerator.default.wrap(function (_context2) {
|
|
207
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
208
|
+
case 0:
|
|
209
|
+
_context2.next = 1;
|
|
210
|
+
return _this2.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(localId);
|
|
211
|
+
case 1:
|
|
212
|
+
sourceInfo = _context2.sent;
|
|
213
|
+
return _context2.abrupt("return", sourceInfo ? _objectSpread(_objectSpread({}, sourceInfo), {}, {
|
|
214
|
+
onSameDocument: true,
|
|
215
|
+
hasAccess: true,
|
|
216
|
+
isSource: false
|
|
217
|
+
}) : undefined);
|
|
218
|
+
case 2:
|
|
219
|
+
case "end":
|
|
220
|
+
return _context2.stop();
|
|
221
|
+
}
|
|
222
|
+
}, _callee2);
|
|
223
|
+
}));
|
|
224
|
+
return function (_x6) {
|
|
225
|
+
return _ref2.apply(this, arguments);
|
|
226
|
+
};
|
|
227
|
+
}()));
|
|
228
|
+
case 8:
|
|
229
|
+
localSourceInfos = _context3.sent;
|
|
230
|
+
sourceInfos.push.apply(sourceInfos, (0, _toConsumableArray2.default)(localSourceInfos));
|
|
231
|
+
return _context3.abrupt("return", {
|
|
149
232
|
references: sourceInfos
|
|
150
233
|
});
|
|
151
|
-
case
|
|
152
|
-
|
|
153
|
-
_t =
|
|
234
|
+
case 9:
|
|
235
|
+
_context3.prev = 9;
|
|
236
|
+
_t = _context3["catch"](0);
|
|
154
237
|
(0, _error.logException)(_t, {
|
|
155
238
|
location: 'editor-synced-block-provider/syncBlockStoreManager'
|
|
156
239
|
});
|
|
157
240
|
(_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(this, (0, _errorHandling.fetchReferencesErrorPayload)(_t.message, resourceId, (0, _utils.getSourceProductFromResourceIdSafe)(resourceId)));
|
|
158
|
-
return
|
|
241
|
+
return _context3.abrupt("return", {
|
|
159
242
|
error: _types.SyncBlockError.Errored
|
|
160
243
|
});
|
|
161
|
-
case
|
|
244
|
+
case 10:
|
|
162
245
|
case "end":
|
|
163
|
-
return
|
|
246
|
+
return _context3.stop();
|
|
164
247
|
}
|
|
165
|
-
},
|
|
248
|
+
}, _callee3, this, [[0, 9]]);
|
|
166
249
|
}));
|
|
167
|
-
function fetchReferencesSourceInfo(_x, _x2, _x3) {
|
|
250
|
+
function fetchReferencesSourceInfo(_x, _x2, _x3, _x4) {
|
|
168
251
|
return _fetchReferencesSourceInfo.apply(this, arguments);
|
|
169
252
|
}
|
|
170
253
|
return fetchReferencesSourceInfo;
|
|
@@ -191,13 +274,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
191
274
|
}, {
|
|
192
275
|
key: "destroy",
|
|
193
276
|
value: function destroy() {
|
|
194
|
-
var _this$
|
|
277
|
+
var _this$fetchReferences5, _this$fetchSourceInfo;
|
|
195
278
|
this.referenceSyncBlockStoreManager.destroy();
|
|
196
279
|
this.sourceSyncBlockStoreManager.destroy();
|
|
197
|
-
(_this$
|
|
280
|
+
(_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.abort({
|
|
198
281
|
reason: 'editorDestroyed'
|
|
199
282
|
});
|
|
200
|
-
(_this$
|
|
283
|
+
(_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.abort({
|
|
201
284
|
reason: 'editorDestroyed'
|
|
202
285
|
});
|
|
203
286
|
}
|
|
@@ -209,41 +292,41 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
209
292
|
}, {
|
|
210
293
|
key: "fetchRestrictedReferenceInfo",
|
|
211
294
|
value: (function () {
|
|
212
|
-
var _fetchRestrictedReferenceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
213
|
-
var _this$
|
|
214
|
-
var productType, url, _this$
|
|
215
|
-
return _regenerator.default.wrap(function (
|
|
216
|
-
while (1) switch (
|
|
295
|
+
var _fetchRestrictedReferenceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(documentAri) {
|
|
296
|
+
var _this$fetchSourceInfo2;
|
|
297
|
+
var productType, url, _this$dataProvider, _this$fetchSourceInfo3, sourceInfo, _this$fetchSourceInfo4, _t2;
|
|
298
|
+
return _regenerator.default.wrap(function (_context4) {
|
|
299
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
217
300
|
case 0:
|
|
218
301
|
if (documentAri) {
|
|
219
|
-
|
|
302
|
+
_context4.next = 1;
|
|
220
303
|
break;
|
|
221
304
|
}
|
|
222
|
-
return
|
|
305
|
+
return _context4.abrupt("return", {
|
|
223
306
|
sourceAri: '',
|
|
224
307
|
hasAccess: false,
|
|
225
308
|
onSameDocument: false
|
|
226
309
|
});
|
|
227
310
|
case 1:
|
|
228
311
|
productType = (0, _ari.getProductFromSourceAri)(documentAri);
|
|
229
|
-
(_this$
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return (_this$
|
|
312
|
+
(_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.start();
|
|
313
|
+
_context4.prev = 2;
|
|
314
|
+
_context4.next = 3;
|
|
315
|
+
return (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(undefined, documentAri, productType, false);
|
|
233
316
|
case 3:
|
|
234
|
-
sourceInfo =
|
|
317
|
+
sourceInfo = _context4.sent;
|
|
235
318
|
url = sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url;
|
|
236
|
-
(_this$
|
|
237
|
-
|
|
319
|
+
(_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 || _this$fetchSourceInfo3.success();
|
|
320
|
+
_context4.next = 5;
|
|
238
321
|
break;
|
|
239
322
|
case 4:
|
|
240
|
-
|
|
241
|
-
_t2 =
|
|
242
|
-
(_this$
|
|
323
|
+
_context4.prev = 4;
|
|
324
|
+
_t2 = _context4["catch"](2);
|
|
325
|
+
(_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.failure({
|
|
243
326
|
reason: _t2.message
|
|
244
327
|
});
|
|
245
328
|
case 5:
|
|
246
|
-
return
|
|
329
|
+
return _context4.abrupt("return", {
|
|
247
330
|
sourceAri: documentAri,
|
|
248
331
|
productType: productType,
|
|
249
332
|
url: url,
|
|
@@ -252,11 +335,11 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
252
335
|
});
|
|
253
336
|
case 6:
|
|
254
337
|
case "end":
|
|
255
|
-
return
|
|
338
|
+
return _context4.stop();
|
|
256
339
|
}
|
|
257
|
-
},
|
|
340
|
+
}, _callee4, this, [[2, 4]]);
|
|
258
341
|
}));
|
|
259
|
-
function fetchRestrictedReferenceInfo(
|
|
342
|
+
function fetchRestrictedReferenceInfo(_x7) {
|
|
260
343
|
return _fetchRestrictedReferenceInfo.apply(this, arguments);
|
|
261
344
|
}
|
|
262
345
|
return fetchRestrictedReferenceInfo;
|
|
@@ -264,14 +347,14 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
264
347
|
}, {
|
|
265
348
|
key: "getUnregisteredReferences",
|
|
266
349
|
value: function () {
|
|
267
|
-
var _getUnregisteredReferences = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
268
|
-
var _this$
|
|
269
|
-
var _this$
|
|
270
|
-
return _regenerator.default.wrap(function (
|
|
271
|
-
while (1) switch (
|
|
350
|
+
var _getUnregisteredReferences = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(resourceId, blockInstanceId, isSourceSyncBlock) {
|
|
351
|
+
var _this$fetchReferences9;
|
|
352
|
+
var _this$fetchReferences7, referenceResourceId, hasUnregisteredReferenceOnPage, _this$fetchReferences6, _sourceSyncBlockData, _references, sourceSyncBlockReference, referenceSyncBlockReference, references, sourceSyncBlockData, currentPageData, _this$fetchReferences8;
|
|
353
|
+
return _regenerator.default.wrap(function (_context5) {
|
|
354
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
272
355
|
case 0:
|
|
273
356
|
if (!isSourceSyncBlock) {
|
|
274
|
-
|
|
357
|
+
_context5.next = 3;
|
|
275
358
|
break;
|
|
276
359
|
}
|
|
277
360
|
// Verify that a reference sync block for this specific source actually
|
|
@@ -280,13 +363,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
280
363
|
referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
|
|
281
364
|
hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
|
|
282
365
|
if (!hasUnregisteredReferenceOnPage) {
|
|
283
|
-
|
|
366
|
+
_context5.next = 2;
|
|
284
367
|
break;
|
|
285
368
|
}
|
|
286
|
-
|
|
369
|
+
_context5.next = 1;
|
|
287
370
|
return this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
|
|
288
371
|
case 1:
|
|
289
|
-
_sourceSyncBlockData =
|
|
372
|
+
_sourceSyncBlockData = _context5.sent;
|
|
290
373
|
_references = [];
|
|
291
374
|
if (_sourceSyncBlockData) {
|
|
292
375
|
sourceSyncBlockReference = _objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
|
|
@@ -301,14 +384,14 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
301
384
|
});
|
|
302
385
|
_references.push(sourceSyncBlockReference, referenceSyncBlockReference);
|
|
303
386
|
}
|
|
304
|
-
(_this$
|
|
305
|
-
return
|
|
387
|
+
(_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.success();
|
|
388
|
+
return _context5.abrupt("return", {
|
|
306
389
|
references: _references
|
|
307
390
|
});
|
|
308
391
|
case 2:
|
|
309
392
|
// No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
|
|
310
|
-
(_this$
|
|
311
|
-
return
|
|
393
|
+
(_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.success();
|
|
394
|
+
return _context5.abrupt("return", {
|
|
312
395
|
references: []
|
|
313
396
|
});
|
|
314
397
|
case 3:
|
|
@@ -316,10 +399,10 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
316
399
|
// still show the source and the current page itself since they are known
|
|
317
400
|
// but not saved yet.
|
|
318
401
|
references = [];
|
|
319
|
-
|
|
402
|
+
_context5.next = 4;
|
|
320
403
|
return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
|
|
321
404
|
case 4:
|
|
322
|
-
sourceSyncBlockData =
|
|
405
|
+
sourceSyncBlockData = _context5.sent;
|
|
323
406
|
if (sourceSyncBlockData) {
|
|
324
407
|
references.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
|
|
325
408
|
onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
|
|
@@ -327,10 +410,10 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
327
410
|
isSource: true
|
|
328
411
|
}));
|
|
329
412
|
}
|
|
330
|
-
|
|
413
|
+
_context5.next = 5;
|
|
331
414
|
return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
|
|
332
415
|
case 5:
|
|
333
|
-
currentPageData =
|
|
416
|
+
currentPageData = _context5.sent;
|
|
334
417
|
if (currentPageData) {
|
|
335
418
|
references.push(_objectSpread(_objectSpread({}, currentPageData), {}, {
|
|
336
419
|
onSameDocument: true,
|
|
@@ -339,27 +422,27 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
339
422
|
}));
|
|
340
423
|
}
|
|
341
424
|
if (!(references.length === 0)) {
|
|
342
|
-
|
|
425
|
+
_context5.next = 6;
|
|
343
426
|
break;
|
|
344
427
|
}
|
|
345
|
-
(_this$
|
|
428
|
+
(_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.failure({
|
|
346
429
|
reason: 'No references found for reference synced block'
|
|
347
430
|
});
|
|
348
|
-
return
|
|
431
|
+
return _context5.abrupt("return", {
|
|
349
432
|
error: _types.SyncBlockError.Errored
|
|
350
433
|
});
|
|
351
434
|
case 6:
|
|
352
|
-
(_this$
|
|
353
|
-
return
|
|
435
|
+
(_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 || _this$fetchReferences9.success();
|
|
436
|
+
return _context5.abrupt("return", {
|
|
354
437
|
references: references
|
|
355
438
|
});
|
|
356
439
|
case 7:
|
|
357
440
|
case "end":
|
|
358
|
-
return
|
|
441
|
+
return _context5.stop();
|
|
359
442
|
}
|
|
360
|
-
},
|
|
443
|
+
}, _callee5, this);
|
|
361
444
|
}));
|
|
362
|
-
function getUnregisteredReferences(
|
|
445
|
+
function getUnregisteredReferences(_x8, _x9, _x0) {
|
|
363
446
|
return _getUnregisteredReferences.apply(this, arguments);
|
|
364
447
|
}
|
|
365
448
|
return getUnregisteredReferences;
|
|
@@ -252,6 +252,9 @@ export class SyncedBlockProvider extends SyncBlockDataProviderInterface {
|
|
|
252
252
|
resourceId
|
|
253
253
|
};
|
|
254
254
|
}
|
|
255
|
+
canGenerateResourceIdForReference() {
|
|
256
|
+
return this.writeProvider !== undefined;
|
|
257
|
+
}
|
|
255
258
|
generateResourceIdForReference(sourceId) {
|
|
256
259
|
if (!this.writeProvider) {
|
|
257
260
|
throw new Error('Write provider not set');
|