@atlaskit/editor-synced-block-provider 2.10.1 → 2.10.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/{providers → clients}/block-service/ari.js +2 -2
  3. package/dist/cjs/{utils → clients/confluence}/ari.js +6 -6
  4. package/dist/cjs/{utils → clients/confluence}/sourceInfo.js +7 -7
  5. package/dist/cjs/clients/confluence/utils.js +9 -0
  6. package/dist/cjs/hooks/useFetchSyncBlockData.js +5 -6
  7. package/dist/cjs/hooks/useFetchSyncBlockTitle.js +1 -1
  8. package/dist/cjs/hooks/useHandleContentChanges.js +1 -1
  9. package/dist/cjs/index.js +27 -14
  10. package/dist/cjs/providers/block-service/blockServiceAPI.js +4 -4
  11. package/dist/cjs/providers/confluence/confluenceContentAPI.js +33 -26
  12. package/dist/cjs/providers/syncBlockProvider.js +38 -3
  13. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +86 -19
  14. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +52 -10
  15. package/dist/cjs/store-manager/syncBlockStoreManager.js +14 -157
  16. package/dist/cjs/utils/utils.js +8 -4
  17. package/dist/es2019/{providers → clients}/block-service/ari.js +1 -1
  18. package/dist/es2019/{utils → clients/confluence}/ari.js +5 -5
  19. package/dist/es2019/{utils → clients/confluence}/sourceInfo.js +5 -5
  20. package/dist/es2019/clients/confluence/utils.js +3 -0
  21. package/dist/es2019/hooks/useFetchSyncBlockData.js +5 -6
  22. package/dist/es2019/hooks/useFetchSyncBlockTitle.js +1 -1
  23. package/dist/es2019/hooks/useHandleContentChanges.js +1 -1
  24. package/dist/es2019/index.js +14 -4
  25. package/dist/es2019/providers/block-service/blockServiceAPI.js +4 -4
  26. package/dist/es2019/providers/confluence/confluenceContentAPI.js +19 -13
  27. package/dist/es2019/providers/syncBlockProvider.js +38 -3
  28. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +75 -10
  29. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +39 -1
  30. package/dist/es2019/store-manager/syncBlockStoreManager.js +12 -117
  31. package/dist/es2019/utils/utils.js +3 -3
  32. package/dist/esm/{providers → clients}/block-service/ari.js +1 -1
  33. package/dist/esm/{utils → clients/confluence}/ari.js +5 -5
  34. package/dist/esm/{utils → clients/confluence}/sourceInfo.js +7 -7
  35. package/dist/esm/clients/confluence/utils.js +3 -0
  36. package/dist/esm/hooks/useFetchSyncBlockData.js +5 -6
  37. package/dist/esm/hooks/useFetchSyncBlockTitle.js +1 -1
  38. package/dist/esm/hooks/useHandleContentChanges.js +1 -1
  39. package/dist/esm/index.js +14 -4
  40. package/dist/esm/providers/block-service/blockServiceAPI.js +4 -4
  41. package/dist/esm/providers/confluence/confluenceContentAPI.js +33 -26
  42. package/dist/esm/providers/syncBlockProvider.js +38 -3
  43. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +87 -19
  44. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +52 -10
  45. package/dist/esm/store-manager/syncBlockStoreManager.js +14 -157
  46. package/dist/esm/utils/utils.js +7 -3
  47. package/dist/types/{providers → clients}/block-service/ari.d.ts +1 -1
  48. package/dist/types/{utils → clients/block-service}/blockService.d.ts +3 -3
  49. package/dist/types/clients/confluence/ari.d.ts +9 -0
  50. package/dist/types/{utils → clients/confluence}/contentProperty.d.ts +1 -1
  51. package/dist/types/clients/confluence/sourceInfo.d.ts +2 -0
  52. package/dist/types/clients/confluence/utils.d.ts +2 -0
  53. package/dist/types/common/types.d.ts +3 -1
  54. package/dist/types/index.d.ts +5 -4
  55. package/dist/types/providers/syncBlockProvider.d.ts +10 -1
  56. package/dist/types/providers/types.d.ts +20 -8
  57. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +6 -0
  58. package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +17 -1
  59. package/dist/types/store-manager/syncBlockStoreManager.d.ts +4 -59
  60. package/dist/types/utils/utils.d.ts +1 -2
  61. package/dist/types-ts4.5/{providers → clients}/block-service/ari.d.ts +1 -1
  62. package/dist/types-ts4.5/{utils → clients/block-service}/blockService.d.ts +3 -3
  63. package/dist/types-ts4.5/clients/confluence/ari.d.ts +9 -0
  64. package/dist/types-ts4.5/{utils → clients/confluence}/contentProperty.d.ts +1 -1
  65. package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +2 -0
  66. package/dist/types-ts4.5/clients/confluence/utils.d.ts +2 -0
  67. package/dist/types-ts4.5/common/types.d.ts +3 -1
  68. package/dist/types-ts4.5/index.d.ts +5 -4
  69. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +10 -1
  70. package/dist/types-ts4.5/providers/types.d.ts +20 -8
  71. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +6 -0
  72. package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +17 -1
  73. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +4 -59
  74. package/dist/types-ts4.5/utils/utils.d.ts +1 -2
  75. package/package.json +5 -5
  76. package/dist/types/utils/ari.d.ts +0 -9
  77. package/dist/types/utils/sourceInfo.d.ts +0 -2
  78. package/dist/types-ts4.5/utils/ari.d.ts +0 -9
  79. package/dist/types-ts4.5/utils/sourceInfo.d.ts +0 -2
  80. /package/dist/cjs/{utils → clients/block-service}/blockService.js +0 -0
  81. /package/dist/cjs/{utils → clients/confluence}/contentProperty.js +0 -0
  82. /package/dist/es2019/{utils → clients/block-service}/blockService.js +0 -0
  83. /package/dist/es2019/{utils → clients/confluence}/contentProperty.js +0 -0
  84. /package/dist/esm/{utils → clients/block-service}/blockService.js +0 -0
  85. /package/dist/esm/{utils → clients/confluence}/contentProperty.js +0 -0
@@ -20,6 +20,11 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
20
20
  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; } } }; }
21
21
  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; } }
22
22
  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
+ // A store manager responsible for the lifecycle and state management of reference sync blocks in an editor instance.
24
+ // Designed to manage local in-memory state and synchronize with an external data provider.
25
+ // Supports fetch, cache, and subscription for sync block data.
26
+ // Handles fetching source URL and title for sync blocks.
27
+ // Can be used in both editor and renderer contexts.
23
28
  var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
24
29
  function ReferenceSyncBlockStoreManager(dataProvider) {
25
30
  (0, _classCallCheck2.default)(this, ReferenceSyncBlockStoreManager);
@@ -123,6 +128,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
123
128
  return;
124
129
  }
125
130
 
131
+ // TODO: EDITOR-3312 - retrieve the source info based on the source sync block product
132
+
126
133
  // if the sync block is a reference block, we need to fetch the URL to the source
127
134
  // we could optimise this further by checking if the sync block is on the same page as the source
128
135
  if (!this.syncBlockURLRequests.get(resourceId)) {
@@ -144,21 +151,33 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
144
151
  });
145
152
  }
146
153
  }
154
+
155
+ /**
156
+ * Fetch sync block data for a given array of sync block nodes.
157
+ * @param syncBlockNodes - The array of sync block nodes to fetch data for
158
+ * @returns The fetched sync block data results
159
+ */
147
160
  }, {
148
161
  key: "fetchSyncBlocksData",
149
- value: function () {
162
+ value: (function () {
150
163
  var _fetchSyncBlocksData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockNodes) {
151
164
  var _this2 = this;
152
165
  var nodesToFetch, blocksWithNotFoundError, data, resolvedData;
153
166
  return _regenerator.default.wrap(function _callee2$(_context3) {
154
167
  while (1) switch (_context3.prev = _context3.next) {
155
168
  case 0:
156
- if (this.dataProvider) {
169
+ if (!(syncBlockNodes.length === 0)) {
157
170
  _context3.next = 2;
158
171
  break;
159
172
  }
160
- throw new Error('Data provider not set');
173
+ return _context3.abrupt("return", Promise.resolve([]));
161
174
  case 2:
175
+ if (this.dataProvider) {
176
+ _context3.next = 4;
177
+ break;
178
+ }
179
+ throw new Error('Data provider not set');
180
+ case 4:
162
181
  // Don't fetch for not_found error since the source is already deleted
163
182
  nodesToFetch = [], blocksWithNotFoundError = [];
164
183
  syncBlockNodes.forEach(function (node) {
@@ -169,16 +188,16 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
169
188
  nodesToFetch.push(node);
170
189
  }
171
190
  });
172
- _context3.next = 6;
191
+ _context3.next = 8;
173
192
  return this.dataProvider.fetchNodesData(nodesToFetch);
174
- case 6:
193
+ case 8:
175
194
  data = _context3.sent;
176
195
  if (data) {
177
- _context3.next = 9;
196
+ _context3.next = 11;
178
197
  break;
179
198
  }
180
199
  throw new Error('Failed to fetch sync block node data');
181
- case 9:
200
+ case 11:
182
201
  resolvedData = [];
183
202
  data.forEach(function (syncBlockInstance) {
184
203
  var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
@@ -201,7 +220,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
201
220
  }
202
221
  });
203
222
  return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
204
- case 12:
223
+ case 14:
205
224
  case "end":
206
225
  return _context3.stop();
207
226
  }
@@ -211,7 +230,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
211
230
  return _fetchSyncBlocksData.apply(this, arguments);
212
231
  }
213
232
  return fetchSyncBlocksData;
214
- }()
233
+ }())
215
234
  }, {
216
235
  key: "updateCache",
217
236
  value: function updateCache(syncBlock) {
@@ -348,28 +367,76 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
348
367
  return undefined;
349
368
  }
350
369
  var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
351
- parentDataProviders = _this$dataProvider$ge.parentDataProviders;
352
- if (!this.providerFactories.has(resourceId)) {
353
- // TODO: EDITOR-2771 - In follow up PR, create media & emoji providers per ref sync block
354
- // The media & emoji providers will be set later, once we get ref sync block data with page ID
355
- // So we need to keep the reference to the Provider Factory so we can then set media & emoji providers later
356
- this.providerFactories.set(resourceId, _providerFactory.ProviderFactory.create({
357
- emojiProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.emojiProvider,
358
- mediaProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mediaProvider,
370
+ parentDataProviders = _this$dataProvider$ge.parentDataProviders,
371
+ providerCreator = _this$dataProvider$ge.providerCreator;
372
+ var providerFactory = this.providerFactories.get(resourceId);
373
+ if (!providerFactory) {
374
+ providerFactory = _providerFactory.ProviderFactory.create({
359
375
  mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
360
376
  profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
361
377
  taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
362
- }));
378
+ });
379
+ this.providerFactories.set(resourceId, providerFactory);
380
+ }
381
+ if (providerCreator) {
382
+ this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
383
+ }
384
+ return providerFactory;
385
+ }
386
+ }, {
387
+ key: "retrieveDynamicProviders",
388
+ value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
389
+ if (!this.dataProvider) {
390
+ return;
391
+ }
392
+ var hasMediaProvider = providerFactory.hasProvider('mediaProvider');
393
+ var hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
394
+ if (hasMediaProvider && hasEmojiProvider) {
395
+ return;
396
+ }
397
+ var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo(this.syncBlockCache.get(resourceId));
398
+ if (!parentInfo) {
399
+ return;
400
+ }
401
+ var contentId = parentInfo.contentId,
402
+ contentProduct = parentInfo.contentProduct;
403
+ if (!hasMediaProvider) {
404
+ if (providerCreator.createMediaProvider && contentId && contentProduct) {
405
+ var mediaProvider = providerCreator.createMediaProvider({
406
+ contentProduct: contentProduct,
407
+ contentId: contentId
408
+ });
409
+ if (mediaProvider) {
410
+ providerFactory.setProvider('mediaProvider', mediaProvider);
411
+ }
412
+ }
413
+ }
414
+ if (!hasEmojiProvider) {
415
+ if (providerCreator.createEmojiProvider && contentId && contentProduct) {
416
+ var emojiProvider = providerCreator.createEmojiProvider({
417
+ contentProduct: contentProduct,
418
+ contentId: contentId
419
+ });
420
+ if (emojiProvider) {
421
+ providerFactory.setProvider('emojiProvider', emojiProvider);
422
+ }
423
+ }
363
424
  }
364
- return this.providerFactories.get(resourceId);
365
425
  }
366
426
  }, {
367
427
  key: "destroy",
368
428
  value: function destroy() {
429
+ this.dataProvider = undefined;
369
430
  this.syncBlockCache.clear();
370
431
  this.subscriptions.clear();
432
+ this.titleSubscriptions.clear();
371
433
  this.syncBlockURLRequests.clear();
372
434
  this.providerFactories.clear();
435
+ this.isRefreshingSubscriptions = false;
436
+ this.providerFactories.forEach(function (providerFactory) {
437
+ providerFactory.destroy();
438
+ });
439
+ this.providerFactories.clear();
373
440
  }
374
441
  }]);
375
442
  }();
@@ -14,6 +14,11 @@ var _uuid = _interopRequireDefault(require("uuid"));
14
14
  var _rebaseTransaction2 = require("../common/rebase-transaction");
15
15
  var _utils = require("../utils/utils");
16
16
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
17
+ // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
18
+ // Designed to manage local in-memory state and synchronize with an external data provider.
19
+ // Supports create, flush, and delete operations for source sync blocks.
20
+ // Handles caching, debouncing updates, and publish/subscribe for local changes.
21
+ // Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
17
22
  var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PURE__*/function () {
18
23
  function SourceSyncBlockStoreManager(dataProvider) {
19
24
  var _this = this;
@@ -27,14 +32,22 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
27
32
  this.dataProvider = dataProvider;
28
33
  this.syncBlockCache = new Map();
29
34
  }
30
-
31
- /**
32
- * Add/update a sync block node to/from the local cache
33
- * @param syncBlockNode - The sync block node to update
34
- */
35
35
  return (0, _createClass2.default)(SourceSyncBlockStoreManager, [{
36
+ key: "isSourceBlock",
37
+ value: function isSourceBlock(node) {
38
+ return node.type.name === 'bodiedSyncBlock';
39
+ }
40
+
41
+ /**
42
+ * Add/update a sync block node to/from the local cache
43
+ * @param syncBlockNode - The sync block node to update
44
+ */
45
+ }, {
36
46
  key: "updateSyncBlockData",
37
47
  value: function updateSyncBlockData(syncBlockNode) {
48
+ if (!this.isSourceBlock(syncBlockNode)) {
49
+ throw new Error('Invalid sync block node type provided for updateSyncBlockData');
50
+ }
38
51
  var _syncBlockNode$attrs = syncBlockNode.attrs,
39
52
  localId = _syncBlockNode$attrs.localId,
40
53
  resourceId = _syncBlockNode$attrs.resourceId;
@@ -52,9 +65,9 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
52
65
  * @returns true if saving all nodes successfully, false if fail to save some/all nodes
53
66
  */
54
67
  }, {
55
- key: "flushBodiedSyncBlocks",
68
+ key: "flush",
56
69
  value: (function () {
57
- var _flushBodiedSyncBlocks = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
70
+ var _flush = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
58
71
  var bodiedSyncBlockNodes, bodiedSyncBlockData, writeResults;
59
72
  return _regenerator.default.wrap(function _callee$(_context) {
60
73
  while (1) switch (_context.prev = _context.next) {
@@ -104,10 +117,10 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
104
117
  }
105
118
  }, _callee, this, [[0, 14]]);
106
119
  }));
107
- function flushBodiedSyncBlocks() {
108
- return _flushBodiedSyncBlocks.apply(this, arguments);
120
+ function flush() {
121
+ return _flush.apply(this, arguments);
109
122
  }
110
- return flushBodiedSyncBlocks;
123
+ return flush;
111
124
  }())
112
125
  }, {
113
126
  key: "setEditorView",
@@ -119,6 +132,10 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
119
132
  value: function registerPendingCreation(resourceId) {
120
133
  this.pendingResourceId = resourceId;
121
134
  }
135
+
136
+ /**
137
+ * Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
138
+ */
122
139
  }, {
123
140
  key: "registerCreationCallback",
124
141
  value: function registerCreationCallback(callback) {
@@ -138,6 +155,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
138
155
  this.pendingResourceId = undefined;
139
156
  this.creationCallback = undefined;
140
157
  }
158
+
159
+ /**
160
+ *
161
+ * @returns true if waiting for the result of saving new bodiedSyncBlock to backend
162
+ */
141
163
  }, {
142
164
  key: "hasPendingCreation",
143
165
  value: function hasPendingCreation() {
@@ -157,6 +179,10 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
157
179
  value: function requireConfirmationBeforeDelete() {
158
180
  return !!this.confirmationCallback;
159
181
  }
182
+
183
+ /**
184
+ * @returns attributes for a new bodiedSyncBlock node
185
+ */
160
186
  }, {
161
187
  key: "generateBodiedSyncBlockAttrs",
162
188
  value: function generateBodiedSyncBlockAttrs() {
@@ -173,6 +199,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
173
199
  localId: localId
174
200
  };
175
201
  }
202
+
203
+ /**
204
+ * Create a bodiedSyncBlock node with empty content to backend
205
+ * @param attrs attributes Ids of the node
206
+ */
176
207
  }, {
177
208
  key: "createBodiedSyncBlockNode",
178
209
  value: function createBodiedSyncBlockNode(attrs) {
@@ -291,5 +322,16 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
291
322
  }
292
323
  this.confirmationTransaction = (0, _rebaseTransaction2.rebaseTransaction)(this.confirmationTransaction, incomingTr, state);
293
324
  }
325
+ }, {
326
+ key: "destroy",
327
+ value: function destroy() {
328
+ this.syncBlockCache.clear();
329
+ this.confirmationCallback = undefined;
330
+ this.confirmationTransaction = undefined;
331
+ this.pendingResourceId = undefined;
332
+ this.creationCallback = undefined;
333
+ this.dataProvider = undefined;
334
+ this.editorView = undefined;
335
+ }
294
336
  }]);
295
337
  }();
@@ -7,179 +7,36 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.SyncBlockStoreManager = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
- var _utils = require("../utils/utils");
11
10
  var _referenceSyncBlockStoreManager = require("./referenceSyncBlockStoreManager");
12
11
  var _sourceSyncBlockStoreManager = require("./sourceSyncBlockStoreManager");
13
- // A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
14
- // Supports create, read, update, and delete operations for sync blocks.
15
- // Designed to manage local in-memory state and synchronize with an external data provider.
16
- // Handles caching, debouncing updates, and publish/subscribe for local changes.
17
- // Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
12
+ // A parent store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
13
+ // Contains two child store managers: ReferenceSyncBlockStoreManager and SourceSyncBlockStoreManager.
14
+ // ReferenceSyncBlockStoreManager is responsible for the lifecycle and state management of reference sync blocks in an editor instance.
15
+ // SourceSyncBlockStoreManager is responsible for the lifecycle and state management of source sync blocks in an editor instance.
16
+ // Can be used in both editor and renderer contexts.
18
17
  var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/function () {
19
18
  function SyncBlockStoreManager(dataProvider) {
20
19
  (0, _classCallCheck2.default)(this, SyncBlockStoreManager);
21
- this.referenceSyncBlockStoreManager = new _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager(dataProvider);
20
+ // In future, if reference manager needs to reach to source manager and read it's current in memorey cache
21
+ // we can pass the source manager as a parameter to the reference manager constructor
22
22
  this.sourceSyncBlockStoreManager = new _sourceSyncBlockStoreManager.SourceSyncBlockStoreManager(dataProvider);
23
+ this.referenceSyncBlockStoreManager = new _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager(dataProvider);
23
24
  }
24
-
25
- /**
26
- * Fetch sync block data for a given array of sync block nodes.
27
- * @param nodes - The array of sync block nodes to fetch data for
28
- * @returns The fetched sync block data results
29
- */
30
25
  return (0, _createClass2.default)(SyncBlockStoreManager, [{
31
- key: "fetchSyncBlocksData",
32
- value: function fetchSyncBlocksData(nodes) {
33
- var syncBlockNodes = nodes.map(function (node) {
34
- return (0, _utils.convertPMNodeToSyncBlockNode)(node);
35
- }).filter(function (node) {
36
- return node !== undefined;
37
- }) || [];
38
- if (syncBlockNodes.length === 0) {
39
- return Promise.resolve([]);
40
- }
41
- return this.referenceSyncBlockStoreManager.fetchSyncBlocksData(syncBlockNodes);
42
- }
43
- }, {
44
- key: "getReferenceSyncBlockStoreManager",
45
- value: function getReferenceSyncBlockStoreManager() {
26
+ key: "referenceManager",
27
+ get: function get() {
46
28
  return this.referenceSyncBlockStoreManager;
47
29
  }
48
-
49
- /**
50
- * Add/update a sync block node to/from the local cache
51
- * @param syncBlockNode - The sync block node to update
52
- */
53
- }, {
54
- key: "updateSyncBlockData",
55
- value: function updateSyncBlockData(syncBlockNode) {
56
- if (this.isSourceBlock(syncBlockNode)) {
57
- return this.sourceSyncBlockStoreManager.updateSyncBlockData(syncBlockNode);
58
- } else {
59
- throw new Error('Invalid sync block node type provided for updateSyncBlockData');
60
- }
61
- }
62
-
63
- /**
64
- * Save content of bodiedSyncBlock nodes in local cache to backend
65
- *
66
- * @returns true if saving all nodes successfully, false if fail to save some/all nodes
67
- */
68
- }, {
69
- key: "flushBodiedSyncBlocks",
70
- value: function flushBodiedSyncBlocks() {
71
- // only applicable to source sync block, for now (will be refactored further)
72
- return this.sourceSyncBlockStoreManager.flushBodiedSyncBlocks();
73
- }
74
-
75
- /**
76
- * Get the URL for a sync block.
77
- * @param resourceId - The resource ID of the sync block to get the URL for
78
- * @returns
79
- */
80
- }, {
81
- key: "getSyncBlockURL",
82
- value: function getSyncBlockURL(resourceId) {
83
- // only applicable to reference sync block, for now (will be refactored further)
84
- return this.referenceSyncBlockStoreManager.getSyncBlockURL(resourceId);
85
- }
86
- }, {
87
- key: "setEditorView",
88
- value: function setEditorView(editorView) {
89
- this.sourceSyncBlockStoreManager.setEditorView(editorView);
90
- }
91
- }, {
92
- key: "isSourceBlock",
93
- value: function isSourceBlock(node) {
94
- return node.type.name === 'bodiedSyncBlock';
95
- }
96
- }, {
97
- key: "registerConfirmationCallback",
98
- value: function registerConfirmationCallback(callback) {
99
- // only applicable to source sync block, for now (will be refactored further)
100
- return this.sourceSyncBlockStoreManager.registerConfirmationCallback(callback);
101
- }
102
- }, {
103
- key: "requireConfirmationBeforeDelete",
104
- value: function requireConfirmationBeforeDelete() {
105
- // only applicable to source sync block, for now (will be refactored further)
106
- return this.sourceSyncBlockStoreManager.requireConfirmationBeforeDelete();
107
- }
108
-
109
- /**
110
- * Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
111
- */
112
- }, {
113
- key: "registerCreationCallback",
114
- value: function registerCreationCallback(callback) {
115
- this.sourceSyncBlockStoreManager.registerCreationCallback(callback);
116
- }
117
-
118
- /**
119
- *
120
- * @returns true if waiting for the result of saving new bodiedSyncBlock to backend
121
- */
122
- }, {
123
- key: "hasPendingCreation",
124
- value: function hasPendingCreation() {
125
- return this.sourceSyncBlockStoreManager.hasPendingCreation();
126
- }
127
-
128
- /**
129
- * @returns attributes for a new bodiedSyncBlock node
130
- */
131
- }, {
132
- key: "generateBodiedSyncBlockAttrs",
133
- value: function generateBodiedSyncBlockAttrs() {
134
- return this.sourceSyncBlockStoreManager.generateBodiedSyncBlockAttrs();
135
- }
136
-
137
- /**
138
- * Save bodiedSyncBlock with empty content to backend
139
- * @param attrs attributes Ids of the node
140
- */
141
- }, {
142
- key: "createBodiedSyncBlockNode",
143
- value: function createBodiedSyncBlockNode(attrs) {
144
- // only applicable to source sync block, for now (will be refactored further)
145
- return this.sourceSyncBlockStoreManager.createBodiedSyncBlockNode(attrs);
146
- }
147
- }, {
148
- key: "subscribeToSyncBlockData",
149
- value: function subscribeToSyncBlockData(node, callback) {
150
- return this.referenceSyncBlockStoreManager.subscribe(node, callback);
151
- }
152
- }, {
153
- key: "subscribeToSyncBlockSourceTitle",
154
- value: function subscribeToSyncBlockSourceTitle(node, callback) {
155
- return this.referenceSyncBlockStoreManager.subscribeToSourceTitle(node, callback);
156
- }
157
- }, {
158
- key: "refreshSubscriptions",
159
- value: function refreshSubscriptions() {
160
- this.referenceSyncBlockStoreManager.refreshSubscriptions();
161
- }
162
- }, {
163
- key: "deleteSyncBlocksWithConfirmation",
164
- value: function deleteSyncBlocksWithConfirmation(tr, syncBlockIds) {
165
- // only applicable to source sync block, for now (will be refactored further)
166
- return this.sourceSyncBlockStoreManager.deleteSyncBlocksWithConfirmation(tr, syncBlockIds);
167
- }
168
- }, {
169
- key: "rebaseTransaction",
170
- value: function rebaseTransaction(incomingTr, state) {
171
- // only applicable to source sync block, for now (will be refactored further)
172
- this.sourceSyncBlockStoreManager.rebaseTransaction(incomingTr, state);
173
- }
174
30
  }, {
175
- key: "getReferenceSyncBlockProviderFactory",
176
- value: function getReferenceSyncBlockProviderFactory(resourceId) {
177
- return this.referenceSyncBlockStoreManager.getProviderFactory(resourceId);
31
+ key: "sourceManager",
32
+ get: function get() {
33
+ return this.sourceSyncBlockStoreManager;
178
34
  }
179
35
  }, {
180
36
  key: "destroy",
181
37
  value: function destroy() {
182
38
  this.referenceSyncBlockStoreManager.destroy();
39
+ this.sourceSyncBlockStoreManager.destroy();
183
40
  }
184
41
  }]);
185
42
  }();
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isBlogPageType = exports.createSyncBlockNode = exports.createBodiedSyncBlockNode = exports.convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockJSONNodeToSyncBlockNode = exports.convertPMNodeToSyncBlockNode = void 0;
6
+ exports.createSyncBlockNode = exports.createBodiedSyncBlockNode = exports.convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockJSONNodeToSyncBlockNode = exports.convertPMNodesToSyncBlockNodes = exports.convertPMNodeToSyncBlockNode = void 0;
7
7
  var convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNodeToSyncBlockData(node) {
8
8
  return {
9
9
  blockInstanceId: node.attrs.localId,
@@ -11,9 +11,6 @@ var convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockPMNodeToSync
11
11
  resourceId: node.attrs.resourceId
12
12
  };
13
13
  };
14
- var isBlogPageType = exports.isBlogPageType = function isBlogPageType(pageType) {
15
- return pageType === 'blogpost';
16
- };
17
14
  var createSyncBlockNode = exports.createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
18
15
  return {
19
16
  type: 'syncBlock',
@@ -44,4 +41,11 @@ var convertPMNodeToSyncBlockNode = exports.convertPMNodeToSyncBlockNode = functi
44
41
  return undefined;
45
42
  }
46
43
  return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
44
+ };
45
+ var convertPMNodesToSyncBlockNodes = exports.convertPMNodesToSyncBlockNodes = function convertPMNodesToSyncBlockNodes(nodes) {
46
+ return nodes.map(function (node) {
47
+ return convertPMNodeToSyncBlockNode(node);
48
+ }).filter(function (node) {
49
+ return node !== undefined;
50
+ }) || [];
47
51
  };
@@ -19,7 +19,7 @@ export const blockResourceIdFromSourceAndLocalId = (sourceId, localId) => {
19
19
  * @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
20
20
  * @returns the localId of the block node. A randomly generated UUID
21
21
  */
22
- export const getLocalIdFromResourceId = ari => {
22
+ export const getLocalIdFromBlockResourceId = ari => {
23
23
  const match = ari.match(/ari:cloud:blocks:[^:]+:synced-block\/([a-zA-Z0-9-]+)/);
24
24
  if (match !== null && match !== void 0 && match[1]) {
25
25
  return match[1];
@@ -2,8 +2,8 @@
2
2
 
3
3
  export const getConfluencePageAri = (pageId, cloudId, pageType = 'page') => `ari:cloud:confluence:${cloudId}:${pageType}/${pageId}`;
4
4
 
5
- // For extracting from Page ARI and also the content property's version of resourceId
6
- export const getPageIdAndTypeFromAri = ari => {
5
+ // For extracting from Page ARI and also the content property's version of resourceId
6
+ export const getPageIdAndTypeFromConfluencePageAri = ari => {
7
7
  const match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
8
8
  if (match !== null && match !== void 0 && match[2]) {
9
9
  return {
@@ -13,20 +13,20 @@ export const getPageIdAndTypeFromAri = ari => {
13
13
  }
14
14
  throw new Error(`Invalid page ARI: ${ari}`);
15
15
  };
16
- export const getLocalIdFromAri = ari => {
16
+ export const getLocalIdFromConfluencePageAri = ari => {
17
17
  const match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
18
18
  if (match !== null && match !== void 0 && match[2]) {
19
19
  return match[2];
20
20
  }
21
21
  throw new Error(`Invalid page ARI: ${ari}`);
22
22
  };
23
- export const getPageARIFromResourceId = resourceId => {
23
+ export const getPageARIFromContentPropertyResourceId = resourceId => {
24
24
  const match = resourceId.match(/(ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+)\/([a-zA-Z0-9-]+)$/);
25
25
  if (match !== null && match !== void 0 && match[1]) {
26
26
  return match[1];
27
27
  }
28
28
  throw new Error(`Invalid resourceId: ${resourceId}`);
29
29
  };
30
- export const resourceIdFromSourceAndLocalId = (sourceId, localId) => {
30
+ export const resourceIdFromConfluencePageSourceIdAndLocalId = (sourceId, localId) => {
31
31
  return sourceId + '/' + localId;
32
32
  };
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable require-unicode-regexp */
2
2
 
3
- import { getPageIdAndTypeFromAri } from './ari';
3
+ import { getPageIdAndTypeFromConfluencePageAri } from './ari';
4
4
  import { isBlogPageType } from './utils';
5
5
  const COMMON_HEADERS = {
6
6
  'Content-Type': 'application/json',
@@ -31,7 +31,7 @@ const GET_SOURCE_INFO_QUERY = `query ${GET_SOURCE_INFO_OPERATION_NAME} ($id: ID!
31
31
  }
32
32
  }
33
33
  }`;
34
- const getSourceInfo = async ari => {
34
+ const getConfluenceSourceInfo = async ari => {
35
35
  const bodyData = {
36
36
  query: GET_SOURCE_INFO_QUERY,
37
37
  operationName: GET_SOURCE_INFO_OPERATION_NAME,
@@ -52,13 +52,13 @@ const getSourceInfo = async ari => {
52
52
  }
53
53
  return await response.json();
54
54
  };
55
- export const fetchSourceInfo = async (pageAri, localId) => {
55
+ export const fetchConfluenceSourceInfo = async (pageAri, localId) => {
56
56
  try {
57
57
  var _response$data, _response$data$conten, _response$data$conten2, _contentData$space;
58
58
  const {
59
59
  type: pageType
60
- } = getPageIdAndTypeFromAri(pageAri);
61
- const response = await getSourceInfo(pageAri);
60
+ } = getPageIdAndTypeFromConfluencePageAri(pageAri);
61
+ const response = await getConfluenceSourceInfo(pageAri);
62
62
  const contentData = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : (_response$data$conten = _response$data.content) === null || _response$data$conten === void 0 ? void 0 : (_response$data$conten2 = _response$data$conten.nodes) === null || _response$data$conten2 === void 0 ? void 0 : _response$data$conten2[0];
63
63
  if (!contentData) {
64
64
  throw new Error(`Failed to get content data`);
@@ -0,0 +1,3 @@
1
+ export const isBlogPageType = pageType => {
2
+ return pageType === 'blogpost';
3
+ };
@@ -4,7 +4,6 @@ import { createSyncBlockNode } from '../utils/utils';
4
4
  export const useFetchSyncBlockData = (manager, resourceId, localId) => {
5
5
  const [syncBlockInstance, setSyncBlockInstance] = useState(null);
6
6
  const [isLoading, setIsLoading] = useState(true);
7
- const referenceSyncBlockStoreManager = manager.getReferenceSyncBlockStoreManager();
8
7
  const reloadData = useCallback(async () => {
9
8
  if (isLoading) {
10
9
  return;
@@ -16,7 +15,7 @@ export const useFetchSyncBlockData = (manager, resourceId, localId) => {
16
15
  setIsLoading(true);
17
16
  try {
18
17
  // Fetch sync block data, the `subscribeToSyncBlock` will update the state once data is fetched
19
- await referenceSyncBlockStoreManager.fetchSyncBlocksData([syncBlockNode]);
18
+ await manager.referenceManager.fetchSyncBlocksData([syncBlockNode]);
20
19
  } catch (error) {
21
20
  // Set error state if fetching fails
22
21
  setSyncBlockInstance({
@@ -25,19 +24,19 @@ export const useFetchSyncBlockData = (manager, resourceId, localId) => {
25
24
  });
26
25
  }
27
26
  setIsLoading(false);
28
- }, [isLoading, localId, referenceSyncBlockStoreManager, resourceId]);
27
+ }, [isLoading, localId, manager.referenceManager, resourceId]);
29
28
  useEffect(() => {
30
- const unsubscribe = referenceSyncBlockStoreManager.subscribeToSyncBlock(resourceId || '', localId || '', data => {
29
+ const unsubscribe = manager.referenceManager.subscribeToSyncBlock(resourceId || '', localId || '', data => {
31
30
  setSyncBlockInstance(data);
32
31
  setIsLoading(false);
33
32
  });
34
33
  return () => {
35
34
  unsubscribe();
36
35
  };
37
- }, [localId, referenceSyncBlockStoreManager, resourceId]);
36
+ }, [localId, manager.referenceManager, resourceId]);
38
37
  return {
39
38
  isLoading,
40
- providerFactory: referenceSyncBlockStoreManager.getProviderFactory(resourceId || ''),
39
+ providerFactory: manager.referenceManager.getProviderFactory(resourceId || ''),
41
40
  reloadData,
42
41
  syncBlockInstance
43
42
  };