@atlaskit/editor-synced-block-provider 2.2.3 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/hooks/useFetchSyncBlockData.js +5 -30
  3. package/dist/cjs/providers/confluence/confluenceContentAPI.js +50 -0
  4. package/dist/cjs/providers/in-memory/inMemory.js +7 -0
  5. package/dist/cjs/providers/syncBlockProvider.js +75 -19
  6. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +319 -63
  7. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +35 -11
  8. package/dist/cjs/store-manager/syncBlockStoreManager.js +27 -4
  9. package/dist/cjs/utils/contentProperty.js +54 -1
  10. package/dist/cjs/utils/mergeFetchSyncBlockDataResult.js +38 -0
  11. package/dist/es2019/hooks/useFetchSyncBlockData.js +6 -31
  12. package/dist/es2019/providers/confluence/confluenceContentAPI.js +31 -1
  13. package/dist/es2019/providers/in-memory/inMemory.js +7 -0
  14. package/dist/es2019/providers/syncBlockProvider.js +31 -3
  15. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +172 -44
  16. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +16 -4
  17. package/dist/es2019/store-manager/syncBlockStoreManager.js +21 -4
  18. package/dist/es2019/utils/contentProperty.js +54 -0
  19. package/dist/es2019/utils/mergeFetchSyncBlockDataResult.js +30 -0
  20. package/dist/esm/hooks/useFetchSyncBlockData.js +6 -31
  21. package/dist/esm/providers/confluence/confluenceContentAPI.js +51 -1
  22. package/dist/esm/providers/in-memory/inMemory.js +7 -0
  23. package/dist/esm/providers/syncBlockProvider.js +73 -17
  24. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +320 -64
  25. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +35 -11
  26. package/dist/esm/store-manager/syncBlockStoreManager.js +27 -4
  27. package/dist/esm/utils/contentProperty.js +53 -0
  28. package/dist/esm/utils/mergeFetchSyncBlockDataResult.js +31 -0
  29. package/dist/types/common/schema.d.ts +1 -1
  30. package/dist/types/providers/confluence/confluenceContentAPI.d.ts +2 -1
  31. package/dist/types/providers/syncBlockProvider.d.ts +3 -2
  32. package/dist/types/providers/types.d.ts +8 -0
  33. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +24 -8
  34. package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +1 -1
  35. package/dist/types/store-manager/syncBlockStoreManager.d.ts +12 -4
  36. package/dist/types/utils/contentProperty.d.ts +35 -0
  37. package/dist/types/utils/mergeFetchSyncBlockDataResult.d.ts +12 -0
  38. package/dist/types-ts4.5/common/schema.d.ts +1 -1
  39. package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +2 -1
  40. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +3 -2
  41. package/dist/types-ts4.5/providers/types.d.ts +8 -0
  42. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +24 -8
  43. package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +1 -1
  44. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +12 -4
  45. package/dist/types-ts4.5/utils/contentProperty.d.ts +35 -0
  46. package/dist/types-ts4.5/utils/mergeFetchSyncBlockDataResult.d.ts +12 -0
  47. package/package.json +1 -1
@@ -1,10 +1,15 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
4
  import _createClass from "@babel/runtime/helpers/createClass";
5
- import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
6
6
  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; }
7
7
  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) { _defineProperty(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; }
8
+ 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; } } }; }
9
+ 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; } }
10
+ 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; }
11
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
12
+ import { resolveFetchSyncBlockDataResult } from '../utils/mergeFetchSyncBlockDataResult';
8
13
  var createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
9
14
  return {
10
15
  type: 'syncBlock',
@@ -17,108 +22,359 @@ var createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
17
22
  export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
18
23
  function ReferenceSyncBlockStoreManager(dataProvider) {
19
24
  _classCallCheck(this, ReferenceSyncBlockStoreManager);
20
- this.dataProvider = dataProvider;
25
+ _defineProperty(this, "isInitialized", false);
26
+ _defineProperty(this, "isRefreshingSubscriptions", false);
21
27
  this.syncBlockCache = new Map();
28
+ this.subscriptions = new Map();
29
+ this.dataProvider = dataProvider;
22
30
  this.syncBlockURLRequests = new Map();
23
31
  }
24
-
25
- /**
26
- *
27
- * @param localId - The local ID of the sync block to get the source URL for
28
- * @param resourceId - The resource ID of the sync block to get the source URL for
29
- * Fetches source URl for a sync block and updates sync block data with the source URL asynchronously.
30
- */
31
32
  return _createClass(ReferenceSyncBlockStoreManager, [{
33
+ key: "init",
34
+ value: function () {
35
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(editorView) {
36
+ var _this = this;
37
+ var syncBlockNodes, dataResults;
38
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
39
+ while (1) switch (_context.prev = _context.next) {
40
+ case 0:
41
+ if (!(!this.editorView && !this.isInitialized)) {
42
+ _context.next = 15;
43
+ break;
44
+ }
45
+ this.editorView = editorView;
46
+ syncBlockNodes = editorView.state.doc.children.filter(function (node) {
47
+ return node.type.name === 'syncBlock';
48
+ }).map(function (node) {
49
+ return node.toJSON();
50
+ }) || [];
51
+ if (!(syncBlockNodes.length > 0)) {
52
+ _context.next = 15;
53
+ break;
54
+ }
55
+ _context.prev = 4;
56
+ _context.next = 7;
57
+ return this.fetchSyncBlocksData(syncBlockNodes);
58
+ case 7:
59
+ dataResults = _context.sent;
60
+ if (dataResults) {
61
+ _context.next = 10;
62
+ break;
63
+ }
64
+ throw new Error('No data results returned when initializing sync block store manager');
65
+ case 10:
66
+ dataResults.forEach(function (dataResult) {
67
+ _this.updateCache(dataResult);
68
+ });
69
+ _context.next = 15;
70
+ break;
71
+ case 13:
72
+ _context.prev = 13;
73
+ _context.t0 = _context["catch"](4);
74
+ case 15:
75
+ this.isInitialized = true;
76
+ case 16:
77
+ case "end":
78
+ return _context.stop();
79
+ }
80
+ }, _callee, this, [[4, 13]]);
81
+ }));
82
+ function init(_x) {
83
+ return _init.apply(this, arguments);
84
+ }
85
+ return init;
86
+ }()
87
+ /**
88
+ * Refreshes the subscriptions for all sync blocks.
89
+ * @returns {Promise<void>}
90
+ */
91
+ }, {
92
+ key: "refreshSubscriptions",
93
+ value: (function () {
94
+ var _refreshSubscriptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
95
+ var syncBlocks, _iterator, _step, _loop;
96
+ return _regeneratorRuntime.wrap(function _callee2$(_context3) {
97
+ while (1) switch (_context3.prev = _context3.next) {
98
+ case 0:
99
+ if (!(this.isRefreshingSubscriptions || !this.isInitialized)) {
100
+ _context3.next = 2;
101
+ break;
102
+ }
103
+ return _context3.abrupt("return");
104
+ case 2:
105
+ this.isRefreshingSubscriptions = true;
106
+ syncBlocks = [];
107
+ _iterator = _createForOfIteratorHelper(this.subscriptions.entries());
108
+ _context3.prev = 5;
109
+ _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
110
+ var _step$value, resourceId, callbacks;
111
+ return _regeneratorRuntime.wrap(function _loop$(_context2) {
112
+ while (1) switch (_context2.prev = _context2.next) {
113
+ case 0:
114
+ _step$value = _slicedToArray(_step.value, 2), resourceId = _step$value[0], callbacks = _step$value[1];
115
+ Object.keys(callbacks).forEach(function (localId) {
116
+ syncBlocks.push(createSyncBlockNode(localId, resourceId));
117
+ });
118
+ case 2:
119
+ case "end":
120
+ return _context2.stop();
121
+ }
122
+ }, _loop);
123
+ });
124
+ _iterator.s();
125
+ case 8:
126
+ if ((_step = _iterator.n()).done) {
127
+ _context3.next = 12;
128
+ break;
129
+ }
130
+ return _context3.delegateYield(_loop(), "t0", 10);
131
+ case 10:
132
+ _context3.next = 8;
133
+ break;
134
+ case 12:
135
+ _context3.next = 17;
136
+ break;
137
+ case 14:
138
+ _context3.prev = 14;
139
+ _context3.t1 = _context3["catch"](5);
140
+ _iterator.e(_context3.t1);
141
+ case 17:
142
+ _context3.prev = 17;
143
+ _iterator.f();
144
+ return _context3.finish(17);
145
+ case 20:
146
+ _context3.prev = 20;
147
+ _context3.next = 23;
148
+ return this.fetchSyncBlocksData(syncBlocks);
149
+ case 23:
150
+ _context3.next = 27;
151
+ break;
152
+ case 25:
153
+ _context3.prev = 25;
154
+ _context3.t2 = _context3["catch"](20);
155
+ case 27:
156
+ _context3.prev = 27;
157
+ this.isRefreshingSubscriptions = false;
158
+ return _context3.finish(27);
159
+ case 30:
160
+ case "end":
161
+ return _context3.stop();
162
+ }
163
+ }, _callee2, this, [[5, 14, 17, 20], [20, 25, 27, 30]]);
164
+ }));
165
+ function refreshSubscriptions() {
166
+ return _refreshSubscriptions.apply(this, arguments);
167
+ }
168
+ return refreshSubscriptions;
169
+ }())
170
+ }, {
32
171
  key: "fetchSyncBlockSourceURL",
33
- value: function fetchSyncBlockSourceURL(_ref) {
34
- var _this = this;
35
- var localId = _ref.localId,
36
- resourceId = _ref.resourceId;
37
- if (!localId || !resourceId || !this.dataProvider) {
172
+ value: function fetchSyncBlockSourceURL(resourceId) {
173
+ var _this2 = this;
174
+ if (!resourceId || !this.dataProvider) {
38
175
  return;
39
176
  }
40
177
 
41
178
  // if the sync block is a reference block, we need to fetch the URL to the source
42
179
  // we could optimise this further by checking if the sync block is on the same page as the source
43
- if (!this.syncBlockURLRequests.get(localId)) {
44
- this.syncBlockURLRequests.set(localId, true);
45
- this.dataProvider.retrieveSyncBlockSourceUrl(createSyncBlockNode(localId, resourceId)).then(function (sourceURL) {
46
- var existingSyncBlock = _this.syncBlockCache.get(localId);
47
- if (existingSyncBlock) {
48
- existingSyncBlock.sourceURL = sourceURL;
180
+ if (!this.syncBlockURLRequests.get(resourceId)) {
181
+ this.syncBlockURLRequests.set(resourceId, true);
182
+ this.dataProvider.retrieveSyncBlockSourceUrl(createSyncBlockNode('', resourceId)).then(function (sourceURL) {
183
+ var existingSyncBlock = _this2.getFromCache(resourceId);
184
+ if (existingSyncBlock && existingSyncBlock.data) {
185
+ existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
186
+ sourceURL: sourceURL
187
+ });
188
+ _this2.updateCache(existingSyncBlock);
49
189
  }
50
190
  }).finally(function () {
51
- _this.syncBlockURLRequests.set(localId, false);
191
+ _this2.syncBlockURLRequests.set(resourceId, false);
52
192
  });
53
193
  }
54
194
  }
195
+
196
+ /**
197
+ * Fetch sync block data for a given sync block node.
198
+ * @param syncBlockNode - The sync block node to fetch data for
199
+ * @returns The fetched sync block data result
200
+ */
55
201
  }, {
56
202
  key: "fetchSyncBlockData",
57
- value: function () {
58
- var _fetchSyncBlockData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(syncBlockNode) {
59
- var syncNode, existingSyncBlock, data, fetchSyncBlockDataResult;
60
- return _regeneratorRuntime.wrap(function _callee$(_context) {
61
- while (1) switch (_context.prev = _context.next) {
203
+ value: (function () {
204
+ var _fetchSyncBlockData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(syncBlockNode) {
205
+ var syncNode, data;
206
+ return _regeneratorRuntime.wrap(function _callee3$(_context4) {
207
+ while (1) switch (_context4.prev = _context4.next) {
62
208
  case 0:
63
209
  if (this.dataProvider) {
64
- _context.next = 2;
210
+ _context4.next = 2;
65
211
  break;
66
212
  }
67
213
  throw new Error('Data provider not set');
68
214
  case 2:
69
- syncNode = createSyncBlockNode(syncBlockNode.attrs.localId, syncBlockNode.attrs.resourceId); // async fetch source URL if it is not already fetched
70
- existingSyncBlock = this.syncBlockCache.get(syncBlockNode.attrs.localId);
71
- if (!(existingSyncBlock !== null && existingSyncBlock !== void 0 && existingSyncBlock.sourceURL)) {
72
- this.fetchSyncBlockSourceURL({
73
- localId: syncBlockNode.attrs.localId,
74
- resourceId: syncBlockNode.attrs.resourceId
75
- });
215
+ syncNode = createSyncBlockNode(syncBlockNode.attrs.localId, syncBlockNode.attrs.resourceId);
216
+ _context4.next = 5;
217
+ return this.fetchSyncBlocksData([syncNode]);
218
+ case 5:
219
+ data = _context4.sent;
220
+ if (!(!data || data.length === 0)) {
221
+ _context4.next = 8;
222
+ break;
76
223
  }
77
- _context.prev = 5;
78
- _context.next = 8;
79
- return this.dataProvider.fetchNodesData([syncNode]);
224
+ throw new Error('Failed to fetch sync block data');
80
225
  case 8:
81
- data = _context.sent;
226
+ return _context4.abrupt("return", data[0]);
227
+ case 9:
228
+ case "end":
229
+ return _context4.stop();
230
+ }
231
+ }, _callee3, this);
232
+ }));
233
+ function fetchSyncBlockData(_x2) {
234
+ return _fetchSyncBlockData.apply(this, arguments);
235
+ }
236
+ return fetchSyncBlockData;
237
+ }())
238
+ }, {
239
+ key: "fetchSyncBlocksData",
240
+ value: function () {
241
+ var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(syncBlockNodes) {
242
+ var _this3 = this;
243
+ var data, resolvedData;
244
+ return _regeneratorRuntime.wrap(function _callee4$(_context5) {
245
+ while (1) switch (_context5.prev = _context5.next) {
246
+ case 0:
247
+ if (this.dataProvider) {
248
+ _context5.next = 2;
249
+ break;
250
+ }
251
+ throw new Error('Data provider not set');
252
+ case 2:
253
+ _context5.next = 4;
254
+ return this.dataProvider.fetchNodesData(syncBlockNodes);
255
+ case 4:
256
+ data = _context5.sent;
82
257
  if (data) {
83
- _context.next = 11;
258
+ _context5.next = 7;
84
259
  break;
85
260
  }
86
261
  throw new Error('Failed to fetch sync block node data');
87
- case 11:
88
- _context.next = 16;
89
- break;
90
- case 13:
91
- _context.prev = 13;
92
- _context.t0 = _context["catch"](5);
93
- throw new Error('Failed to fetch sync block node data');
94
- case 16:
95
- fetchSyncBlockDataResult = data[0];
96
- if (!fetchSyncBlockDataResult.error && fetchSyncBlockDataResult.data) {
97
- // only adds it to the map if it did not error out
98
- this.syncBlockCache.set(syncBlockNode.attrs.localId, _objectSpread(_objectSpread({}, existingSyncBlock), fetchSyncBlockDataResult.data));
99
- }
100
- return _context.abrupt("return", fetchSyncBlockDataResult);
101
- case 19:
262
+ case 7:
263
+ resolvedData = [];
264
+ data.forEach(function (fetchSyncBlockDataResult) {
265
+ var _resolvedFetchSyncBlo;
266
+ if (!fetchSyncBlockDataResult.resourceId) {
267
+ return;
268
+ }
269
+ var existingSyncBlock = _this3.getFromCache(fetchSyncBlockDataResult.resourceId);
270
+ var resolvedFetchSyncBlockDataResult = existingSyncBlock ? resolveFetchSyncBlockDataResult(existingSyncBlock, fetchSyncBlockDataResult) : fetchSyncBlockDataResult;
271
+ _this3.updateCache(resolvedFetchSyncBlockDataResult);
272
+ resolvedData.push(resolvedFetchSyncBlockDataResult);
273
+
274
+ // fetch source URL if not already present
275
+ if (!((_resolvedFetchSyncBlo = resolvedFetchSyncBlockDataResult.data) !== null && _resolvedFetchSyncBlo !== void 0 && _resolvedFetchSyncBlo.sourceURL) && resolvedFetchSyncBlockDataResult.resourceId) {
276
+ _this3.fetchSyncBlockSourceURL(resolvedFetchSyncBlockDataResult.resourceId);
277
+ }
278
+ });
279
+ return _context5.abrupt("return", resolvedData);
280
+ case 10:
102
281
  case "end":
103
- return _context.stop();
282
+ return _context5.stop();
104
283
  }
105
- }, _callee, this, [[5, 13]]);
284
+ }, _callee4, this);
106
285
  }));
107
- function fetchSyncBlockData(_x) {
108
- return _fetchSyncBlockData.apply(this, arguments);
286
+ function fetchSyncBlocksData(_x3) {
287
+ return _fetchSyncBlocksData.apply(this, arguments);
109
288
  }
110
- return fetchSyncBlockData;
289
+ return fetchSyncBlocksData;
111
290
  }()
291
+ }, {
292
+ key: "updateCache",
293
+ value: function updateCache(syncBlock) {
294
+ var resourceId = syncBlock.resourceId;
295
+ if (resourceId) {
296
+ this.syncBlockCache.set(resourceId, syncBlock);
297
+ var callbacks = this.subscriptions.get(resourceId);
298
+ if (callbacks) {
299
+ Object.values(callbacks).forEach(function (callback) {
300
+ callback(syncBlock);
301
+ });
302
+ }
303
+ }
304
+ }
305
+ }, {
306
+ key: "getFromCache",
307
+ value: function getFromCache(resourceId) {
308
+ return this.syncBlockCache.get(resourceId);
309
+ }
310
+ }, {
311
+ key: "deleteFromCache",
312
+ value: function deleteFromCache(resourceId) {
313
+ this.syncBlockCache.delete(resourceId);
314
+ }
315
+ }, {
316
+ key: "subscribe",
317
+ value: function subscribe(node, callback) {
318
+ var _this4 = this;
319
+ // check node is a sync block, as we only support sync block subscriptions
320
+ if (node.type.name !== 'syncBlock') {
321
+ return function () {};
322
+ }
323
+ var _node$attrs = node.attrs,
324
+ resourceId = _node$attrs.resourceId,
325
+ localId = _node$attrs.localId;
326
+ if (!localId || !resourceId) {
327
+ return function () {};
328
+ }
329
+
330
+ // add to subscriptions map
331
+ var resourceSubscriptions = this.subscriptions.get(resourceId) || {};
332
+ this.subscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
333
+
334
+ // call the callback immediately if we have cached data
335
+ var cachedData = this.getFromCache(resourceId);
336
+ if (cachedData) {
337
+ callback(cachedData);
338
+ } else {
339
+ this.fetchSyncBlockData(node).catch(function () {});
340
+ }
341
+ return function () {
342
+ var resourceSubscriptions = _this4.subscriptions.get(resourceId);
343
+ if (resourceSubscriptions) {
344
+ delete resourceSubscriptions[localId];
345
+ if (Object.keys(resourceSubscriptions).length === 0) {
346
+ _this4.subscriptions.delete(resourceId);
347
+ _this4.deleteFromCache(resourceId);
348
+ } else {
349
+ _this4.subscriptions.set(resourceId, resourceSubscriptions);
350
+ }
351
+ }
352
+ };
353
+ }
354
+
112
355
  /**
113
356
  * Get the URL for a sync block.
114
- * @param localId - The local ID of the sync block to get the URL for
357
+ * @param resourceId - The resource ID of the sync block
115
358
  * @returns
116
359
  */
117
360
  }, {
118
361
  key: "getSyncBlockURL",
119
- value: function getSyncBlockURL(localId) {
120
- var syncBlock = this.syncBlockCache.get(localId);
121
- return syncBlock === null || syncBlock === void 0 ? void 0 : syncBlock.sourceURL;
362
+ value: function getSyncBlockURL(resourceId) {
363
+ var _syncBlock$data;
364
+ var syncBlock = this.getFromCache(resourceId);
365
+ if (!syncBlock) {
366
+ return undefined;
367
+ }
368
+ return (_syncBlock$data = syncBlock.data) === null || _syncBlock$data === void 0 ? void 0 : _syncBlock$data.sourceURL;
369
+ }
370
+ }, {
371
+ key: "destroy",
372
+ value: function destroy() {
373
+ this.syncBlockCache.clear();
374
+ this.subscriptions.clear();
375
+ this.syncBlockURLRequests.clear();
376
+ this.editorView = undefined;
377
+ this.isInitialized = false;
122
378
  }
123
379
  }]);
124
380
  }();
@@ -136,12 +136,12 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
136
136
  value: function () {
137
137
  var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(tr, syncBlockIds) {
138
138
  var _this2 = this;
139
- var confirmed, _this$editorView;
139
+ var confirmed, _this$editorView, results;
140
140
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
141
141
  while (1) switch (_context2.prev = _context2.next) {
142
142
  case 0:
143
143
  if (!this.confirmationCallback) {
144
- _context2.next = 7;
144
+ _context2.next = 19;
145
145
  break;
146
146
  }
147
147
  this.confirmationTransaction = tr;
@@ -149,20 +149,44 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
149
149
  return this.confirmationCallback();
150
150
  case 4:
151
151
  confirmed = _context2.sent;
152
- if (confirmed) {
153
- (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
154
- // Need to update the BE on deletion
155
- syncBlockIds.forEach(function (_ref) {
156
- var localId = _ref.localId;
157
- return _this2.syncBlockCache.delete(localId);
158
- });
152
+ if (!confirmed) {
153
+ _context2.next = 18;
154
+ break;
155
+ }
156
+ (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
157
+ _context2.prev = 7;
158
+ if (this.dataProvider) {
159
+ _context2.next = 10;
160
+ break;
159
161
  }
162
+ throw new Error('Data provider not set');
163
+ case 10:
164
+ _context2.next = 12;
165
+ return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
166
+ return attrs.resourceId;
167
+ }));
168
+ case 12:
169
+ results = _context2.sent;
170
+ results.forEach(function (result) {
171
+ if (result.success) {
172
+ // Only delete when it's deleted successfully in backend
173
+ _this2.syncBlockCache.delete(result.resourceId);
174
+ } else {
175
+ // TODO: EDITOR-1921 - add error analytics with result.error
176
+ }
177
+ });
178
+ _context2.next = 18;
179
+ break;
180
+ case 16:
181
+ _context2.prev = 16;
182
+ _context2.t0 = _context2["catch"](7);
183
+ case 18:
160
184
  this.confirmationTransaction = undefined;
161
- case 7:
185
+ case 19:
162
186
  case "end":
163
187
  return _context2.stop();
164
188
  }
165
- }, _callee2, this);
189
+ }, _callee2, this, [[7, 16]]);
166
190
  }));
167
191
  function deleteSyncBlocksWithConfirmation(_x, _x2) {
168
192
  return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
@@ -14,6 +14,12 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
14
14
  this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider);
15
15
  this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider);
16
16
  }
17
+
18
+ /**
19
+ * Fetch sync block data for a given sync block node.
20
+ * @param syncBlockNode - The sync block node to fetch data for
21
+ * @returns The fetched sync block data result
22
+ */
17
23
  return _createClass(SyncBlockStoreManager, [{
18
24
  key: "fetchSyncBlockData",
19
25
  value: function fetchSyncBlockData(syncBlockNode) {
@@ -54,20 +60,22 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
54
60
 
55
61
  /**
56
62
  * Get the URL for a sync block.
57
- * @param localId - The local ID of the sync block to get the URL for
63
+ * @param resourceId - The resource ID of the sync block to get the URL for
58
64
  * @returns
59
65
  */
60
66
  }, {
61
67
  key: "getSyncBlockURL",
62
- value: function getSyncBlockURL(localId) {
68
+ value: function getSyncBlockURL(resourceId) {
63
69
  // only applicable to reference sync block, for now (will be refactored further)
64
- return this.referenceSyncBlockStoreManager.getSyncBlockURL(localId);
70
+ return this.referenceSyncBlockStoreManager.getSyncBlockURL(resourceId);
65
71
  }
66
72
  }, {
67
73
  key: "setEditorView",
68
74
  value: function setEditorView(editorView) {
69
- // only applicable to source sync block, for now (will be refactored further)
70
75
  this.sourceSyncBlockStoreManager.setEditorView(editorView);
76
+ if (editorView) {
77
+ this.referenceSyncBlockStoreManager.init(editorView);
78
+ }
71
79
  }
72
80
  }, {
73
81
  key: "isSourceBlock",
@@ -92,6 +100,16 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
92
100
  // only applicable to source sync block, for now (will be refactored further)
93
101
  return this.sourceSyncBlockStoreManager.createSyncBlockNode();
94
102
  }
103
+ }, {
104
+ key: "subscribeToSyncBlockData",
105
+ value: function subscribeToSyncBlockData(node, callback) {
106
+ return this.referenceSyncBlockStoreManager.subscribe(node, callback);
107
+ }
108
+ }, {
109
+ key: "refreshSubscriptions",
110
+ value: function refreshSubscriptions() {
111
+ this.referenceSyncBlockStoreManager.refreshSubscriptions();
112
+ }
95
113
  }, {
96
114
  key: "deleteSyncBlocksWithConfirmation",
97
115
  value: function deleteSyncBlocksWithConfirmation(tr, syncBlockIds) {
@@ -104,5 +122,10 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
104
122
  // only applicable to source sync block, for now (will be refactored further)
105
123
  this.sourceSyncBlockStoreManager.rebaseTransaction(incomingTr, state);
106
124
  }
125
+ }, {
126
+ key: "destroy",
127
+ value: function destroy() {
128
+ this.referenceSyncBlockStoreManager.destroy();
129
+ }
107
130
  }]);
108
131
  }();
@@ -16,6 +16,7 @@ var GRAPHQL_ENDPOINT = '/gateway/api/graphql';
16
16
  var GET_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET';
17
17
  var CREATE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_CREATE';
18
18
  var UPDATE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_UPDATE';
19
+ var DELETE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_DELETE';
19
20
  /**
20
21
  * Query to get the page property by key
21
22
  * @param documentARI
@@ -67,6 +68,8 @@ var UPDATE_PAGE_QUERY = "mutation ".concat(UPDATE_OPERATION_NAME, " ($input: Con
67
68
  * @returns
68
69
  */
69
70
  var UPDATE_BLOG_QUERY = "mutation ".concat(UPDATE_OPERATION_NAME, " ($input: ConfluenceUpdateValueBlogPostPropertyInput!) {\n\tconfluence {\n\t\tupdateValueBlogPostProperty(input: $input) {\n\t\t\tblogPostProperty {\n\t\t\t\tkey,\n\t\t\t\tvalue\n\t\t\t}\n\t\t}\n\t}\n}");
71
+ var DELETE_PAGE_QUERY = "mutation ".concat(DELETE_OPERATION_NAME, " ($input: ConfluenceDeletePagePropertyInput!) {\n\t\t\t\t\t\tconfluence {\n\t\t\t\t\t\t\tdeletePageProperty(input: $input) {\n\t\t\t\t\t\t\t\tsuccess, errors {\n\t\t\t\t\t\t\t\t message\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}");
72
+ var DELETE_BLOG_QUERY = "mutation ".concat(DELETE_OPERATION_NAME, " ($input: ConfluenceDeleteBlogPostPropertyInput!) {\n\t\t\t\t\t\tconfluence {\n\t\t\t\t\t\t\tdeleteBlogPostProperty(input: $input) {\n\t\t\t\t\t\t\t\tsuccess, errors {\n\t\t\t\t\t\t\t\t message\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}");
70
73
  export var getContentProperty = /*#__PURE__*/function () {
71
74
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
72
75
  var pageId, key, cloudId, pageType, documentARI, isBlog, bodyData, response;
@@ -224,4 +227,54 @@ export var createContentProperty = /*#__PURE__*/function () {
224
227
  return function createContentProperty(_x3) {
225
228
  return _ref6.apply(this, arguments);
226
229
  };
230
+ }();
231
+ export var deleteContentProperty = /*#__PURE__*/function () {
232
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
233
+ var pageId, cloudId, pageType, key, documentARI, isBlog, bodyData, response;
234
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
235
+ while (1) switch (_context4.prev = _context4.next) {
236
+ case 0:
237
+ pageId = _ref7.pageId, cloudId = _ref7.cloudId, pageType = _ref7.pageType, key = _ref7.key;
238
+ documentARI = getConfluencePageAri(pageId, cloudId, pageType);
239
+ isBlog = isBlogPageType(pageType);
240
+ bodyData = {
241
+ query: isBlog ? DELETE_BLOG_QUERY : DELETE_PAGE_QUERY,
242
+ operationName: DELETE_OPERATION_NAME,
243
+ variables: {
244
+ input: _objectSpread(_objectSpread({}, isBlog ? {
245
+ blogPostId: documentARI
246
+ } : {
247
+ pageId: documentARI
248
+ }), {}, {
249
+ key: key
250
+ })
251
+ }
252
+ };
253
+ _context4.next = 6;
254
+ return fetch(GRAPHQL_ENDPOINT, {
255
+ method: 'POST',
256
+ headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
257
+ body: JSON.stringify(bodyData)
258
+ });
259
+ case 6:
260
+ response = _context4.sent;
261
+ if (response.ok) {
262
+ _context4.next = 9;
263
+ break;
264
+ }
265
+ throw new Error("Failed to delete content property: ".concat(response.statusText));
266
+ case 9:
267
+ _context4.next = 11;
268
+ return response.json();
269
+ case 11:
270
+ return _context4.abrupt("return", _context4.sent);
271
+ case 12:
272
+ case "end":
273
+ return _context4.stop();
274
+ }
275
+ }, _callee4);
276
+ }));
277
+ return function deleteContentProperty(_x4) {
278
+ return _ref8.apply(this, arguments);
279
+ };
227
280
  }();