@atlaskit/editor-synced-block-provider 2.10.2 → 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 (79) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/{providers → clients}/block-service/ari.js +2 -2
  3. package/dist/cjs/{utils → clients/confluence}/ari.js +5 -5
  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 +12 -12
  12. package/dist/cjs/providers/syncBlockProvider.js +14 -9
  13. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +35 -9
  14. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +52 -10
  15. package/dist/cjs/store-manager/syncBlockStoreManager.js +14 -158
  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 +4 -4
  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 +12 -12
  27. package/dist/es2019/providers/syncBlockProvider.js +14 -9
  28. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +24 -0
  29. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +39 -1
  30. package/dist/es2019/store-manager/syncBlockStoreManager.js +12 -119
  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 +4 -4
  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 +12 -12
  42. package/dist/esm/providers/syncBlockProvider.js +14 -9
  43. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +36 -9
  44. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +52 -10
  45. package/dist/esm/store-manager/syncBlockStoreManager.js +14 -159
  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 +1 -1
  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/index.d.ts +4 -3
  54. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +5 -0
  55. package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +17 -1
  56. package/dist/types/store-manager/syncBlockStoreManager.d.ts +4 -59
  57. package/dist/types/utils/utils.d.ts +1 -2
  58. package/dist/types-ts4.5/{providers → clients}/block-service/ari.d.ts +1 -1
  59. package/dist/types-ts4.5/{utils → clients/block-service}/blockService.d.ts +1 -1
  60. package/dist/types-ts4.5/clients/confluence/ari.d.ts +9 -0
  61. package/dist/types-ts4.5/{utils → clients/confluence}/contentProperty.d.ts +1 -1
  62. package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +2 -0
  63. package/dist/types-ts4.5/clients/confluence/utils.d.ts +2 -0
  64. package/dist/types-ts4.5/index.d.ts +4 -3
  65. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +5 -0
  66. package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +17 -1
  67. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +4 -59
  68. package/dist/types-ts4.5/utils/utils.d.ts +1 -2
  69. package/package.json +2 -2
  70. package/dist/types/utils/ari.d.ts +0 -9
  71. package/dist/types/utils/sourceInfo.d.ts +0 -2
  72. package/dist/types-ts4.5/utils/ari.d.ts +0 -9
  73. package/dist/types-ts4.5/utils/sourceInfo.d.ts +0 -2
  74. /package/dist/cjs/{utils → clients/block-service}/blockService.js +0 -0
  75. /package/dist/cjs/{utils → clients/confluence}/contentProperty.js +0 -0
  76. /package/dist/es2019/{utils → clients/block-service}/blockService.js +0 -0
  77. /package/dist/es2019/{utils → clients/confluence}/contentProperty.js +0 -0
  78. /package/dist/esm/{utils → clients/block-service}/blockService.js +0 -0
  79. /package/dist/esm/{utils → clients/confluence}/contentProperty.js +0 -0
@@ -7,11 +7,11 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
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
8
  import _regeneratorRuntime from "@babel/runtime/regenerator";
9
9
  import { useMemo } from 'react';
10
+ import { getConfluencePageAri, getPageARIFromContentPropertyResourceId, getLocalIdFromConfluencePageAri, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from '../../clients/confluence/ari';
11
+ import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../clients/confluence/contentProperty';
12
+ import { isBlogPageType } from '../../clients/confluence/utils';
10
13
  import { SyncBlockError } from '../../common/types';
11
- import { getConfluencePageAri, getPageARIFromResourceId, getLocalIdFromAri, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from '../../utils/ari';
12
- import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../utils/contentProperty';
13
14
  import { stringifyError } from '../../utils/errorHandling';
14
- import { isBlogPageType } from '../../utils/utils';
15
15
 
16
16
  /**
17
17
  * Configuration for Content API providers
@@ -63,8 +63,8 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
63
63
  return _regeneratorRuntime.wrap(function _callee$(_context) {
64
64
  while (1) switch (_context.prev = _context.next) {
65
65
  case 0:
66
- _getPageIdAndTypeFrom = getPageIdAndTypeFromAri(resourceId), pageId = _getPageIdAndTypeFrom.id, pageType = _getPageIdAndTypeFrom.type;
67
- localId = getLocalIdFromAri(resourceId);
66
+ _getPageIdAndTypeFrom = getPageIdAndTypeFromConfluencePageAri(resourceId), pageId = _getPageIdAndTypeFrom.id, pageType = _getPageIdAndTypeFrom.type;
67
+ localId = getLocalIdFromConfluencePageAri(resourceId);
68
68
  _context.prev = 2;
69
69
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
70
70
  options = {
@@ -133,10 +133,10 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
133
133
  }, {
134
134
  key: "retrieveSourceInfoFetchData",
135
135
  value: function retrieveSourceInfoFetchData(resourceId) {
136
- var pageARI = getPageARIFromResourceId(resourceId);
136
+ var pageARI = getPageARIFromContentPropertyResourceId(resourceId);
137
137
  var sourceLocalId;
138
138
  try {
139
- sourceLocalId = getLocalIdFromAri(resourceId);
139
+ sourceLocalId = getLocalIdFromConfluencePageAri(resourceId);
140
140
  } catch (error) {
141
141
  // EDITOR-1921: log analytic here, safe to continue
142
142
  }
@@ -219,7 +219,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
219
219
  case 0:
220
220
  resourceId = data.resourceId;
221
221
  _context3.prev = 1;
222
- match = getPageIdAndTypeFromAri(data.resourceId);
222
+ match = getPageIdAndTypeFromConfluencePageAri(data.resourceId);
223
223
  _context3.next = 8;
224
224
  break;
225
225
  case 5:
@@ -232,7 +232,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
232
232
  _match = match, pageId = _match.id, pageType = _match.type;
233
233
  _context3.prev = 9;
234
234
  // Update existing content property
235
- localId = getLocalIdFromAri(resourceId);
235
+ localId = getLocalIdFromConfluencePageAri(resourceId);
236
236
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
237
237
  sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
238
238
  syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({}, data), {}, {
@@ -305,7 +305,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
305
305
  while (1) switch (_context4.prev = _context4.next) {
306
306
  case 0:
307
307
  _context4.prev = 0;
308
- match = getPageIdAndTypeFromAri(resourceId);
308
+ match = getPageIdAndTypeFromConfluencePageAri(resourceId);
309
309
  _context4.next = 7;
310
310
  break;
311
311
  case 4:
@@ -319,7 +319,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
319
319
  case 7:
320
320
  _match2 = match, pageId = _match2.id, pageType = _match2.type;
321
321
  _context4.prev = 8;
322
- localId = getLocalIdFromAri(resourceId);
322
+ localId = getLocalIdFromConfluencePageAri(resourceId);
323
323
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
324
324
  options = {
325
325
  pageId: pageId,
@@ -362,7 +362,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
362
362
  }, {
363
363
  key: "generateResourceId",
364
364
  value: function generateResourceId(sourceId, localId) {
365
- return resourceIdFromSourceAndLocalId(sourceId, localId);
365
+ return resourceIdFromConfluencePageSourceIdAndLocalId(sourceId, localId);
366
366
  }
367
367
  }]);
368
368
  }();
@@ -10,10 +10,10 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
10
10
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
11
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
12
12
  import { useMemo } from 'react';
13
+ import { getPageIdAndTypeFromConfluencePageAri } from '../clients/confluence/ari';
14
+ import { fetchConfluenceSourceInfo } from '../clients/confluence/sourceInfo';
13
15
  import { SyncBlockError } from '../common/types';
14
16
  import { SyncBlockDataProvider } from '../providers/types';
15
- import { getPageIdAndTypeFromAri } from '../utils/ari';
16
- import { fetchSourceInfo } from '../utils/sourceInfo';
17
17
  export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
18
18
  // the source document ARI; that the source sync block is on.
19
19
 
@@ -226,7 +226,10 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
226
226
  return Promise.reject(error);
227
227
  }
228
228
  }
229
- return pageARI ? fetchSourceInfo(pageARI, sourceLocalId) : Promise.resolve(undefined);
229
+
230
+ // TODO: EDITOR-3312 - based on the source sync block product,
231
+ // execute fetchConfluenceSourceInfo or fetchJiraItemSourceInfo or similar...
232
+ return pageARI ? fetchConfluenceSourceInfo(pageARI, sourceLocalId) : Promise.resolve(undefined);
230
233
  }
231
234
  }, {
232
235
  key: "generateResourceId",
@@ -261,16 +264,18 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
261
264
  }
262
265
  var _syncBlockInstance$da = syncBlockInstance.data,
263
266
  sourceAri = _syncBlockInstance$da.sourceAri,
264
- resourceId = _syncBlockInstance$da.resourceId,
265
- contentProduct = _syncBlockInstance$da.product;
267
+ product = _syncBlockInstance$da.product;
268
+ if (!sourceAri || !product) {
269
+ return undefined;
270
+ }
266
271
 
267
- // Temp solution to get the pageId from resource since the sourceDocumentAri is not available for older sync blocks
268
- var pageARI = sourceAri || resourceId;
269
- var _getPageIdAndTypeFrom = getPageIdAndTypeFromAri(pageARI),
272
+ // TODO: EDITOR-3312 - based on the source sync block product,
273
+ // execute getPageIdAndTypeFromConfluencePageAri or getJiraItemIdAndTypeFromJiraItemAri or similar...
274
+ var _getPageIdAndTypeFrom = getPageIdAndTypeFromConfluencePageAri(sourceAri),
270
275
  contentId = _getPageIdAndTypeFrom.id;
271
276
  return {
272
277
  contentId: contentId,
273
- contentProduct: contentProduct || 'confluence-page'
278
+ contentProduct: product
274
279
  };
275
280
  }
276
281
  }]);
@@ -13,6 +13,12 @@ import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
13
13
  import { SyncBlockError } from '../common/types';
14
14
  import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
15
15
  import { createSyncBlockNode } from '../utils/utils';
16
+
17
+ // A store manager responsible for the lifecycle and state management of reference sync blocks in an editor instance.
18
+ // Designed to manage local in-memory state and synchronize with an external data provider.
19
+ // Supports fetch, cache, and subscription for sync block data.
20
+ // Handles fetching source URL and title for sync blocks.
21
+ // Can be used in both editor and renderer contexts.
16
22
  export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
17
23
  function ReferenceSyncBlockStoreManager(dataProvider) {
18
24
  _classCallCheck(this, ReferenceSyncBlockStoreManager);
@@ -116,6 +122,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
116
122
  return;
117
123
  }
118
124
 
125
+ // TODO: EDITOR-3312 - retrieve the source info based on the source sync block product
126
+
119
127
  // if the sync block is a reference block, we need to fetch the URL to the source
120
128
  // we could optimise this further by checking if the sync block is on the same page as the source
121
129
  if (!this.syncBlockURLRequests.get(resourceId)) {
@@ -137,21 +145,33 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
137
145
  });
138
146
  }
139
147
  }
148
+
149
+ /**
150
+ * Fetch sync block data for a given array of sync block nodes.
151
+ * @param syncBlockNodes - The array of sync block nodes to fetch data for
152
+ * @returns The fetched sync block data results
153
+ */
140
154
  }, {
141
155
  key: "fetchSyncBlocksData",
142
- value: function () {
156
+ value: (function () {
143
157
  var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockNodes) {
144
158
  var _this2 = this;
145
159
  var nodesToFetch, blocksWithNotFoundError, data, resolvedData;
146
160
  return _regeneratorRuntime.wrap(function _callee2$(_context3) {
147
161
  while (1) switch (_context3.prev = _context3.next) {
148
162
  case 0:
149
- if (this.dataProvider) {
163
+ if (!(syncBlockNodes.length === 0)) {
150
164
  _context3.next = 2;
151
165
  break;
152
166
  }
153
- throw new Error('Data provider not set');
167
+ return _context3.abrupt("return", Promise.resolve([]));
154
168
  case 2:
169
+ if (this.dataProvider) {
170
+ _context3.next = 4;
171
+ break;
172
+ }
173
+ throw new Error('Data provider not set');
174
+ case 4:
155
175
  // Don't fetch for not_found error since the source is already deleted
156
176
  nodesToFetch = [], blocksWithNotFoundError = [];
157
177
  syncBlockNodes.forEach(function (node) {
@@ -162,16 +182,16 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
162
182
  nodesToFetch.push(node);
163
183
  }
164
184
  });
165
- _context3.next = 6;
185
+ _context3.next = 8;
166
186
  return this.dataProvider.fetchNodesData(nodesToFetch);
167
- case 6:
187
+ case 8:
168
188
  data = _context3.sent;
169
189
  if (data) {
170
- _context3.next = 9;
190
+ _context3.next = 11;
171
191
  break;
172
192
  }
173
193
  throw new Error('Failed to fetch sync block node data');
174
- case 9:
194
+ case 11:
175
195
  resolvedData = [];
176
196
  data.forEach(function (syncBlockInstance) {
177
197
  var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
@@ -194,7 +214,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
194
214
  }
195
215
  });
196
216
  return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
197
- case 12:
217
+ case 14:
198
218
  case "end":
199
219
  return _context3.stop();
200
220
  }
@@ -204,7 +224,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
204
224
  return _fetchSyncBlocksData.apply(this, arguments);
205
225
  }
206
226
  return fetchSyncBlocksData;
207
- }()
227
+ }())
208
228
  }, {
209
229
  key: "updateCache",
210
230
  value: function updateCache(syncBlock) {
@@ -400,10 +420,17 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
400
420
  }, {
401
421
  key: "destroy",
402
422
  value: function destroy() {
423
+ this.dataProvider = undefined;
403
424
  this.syncBlockCache.clear();
404
425
  this.subscriptions.clear();
426
+ this.titleSubscriptions.clear();
405
427
  this.syncBlockURLRequests.clear();
406
428
  this.providerFactories.clear();
429
+ this.isRefreshingSubscriptions = false;
430
+ this.providerFactories.forEach(function (providerFactory) {
431
+ providerFactory.destroy();
432
+ });
433
+ this.providerFactories.clear();
407
434
  }
408
435
  }]);
409
436
  }();
@@ -7,6 +7,11 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
7
7
  import uuid from 'uuid';
8
8
  import { rebaseTransaction as _rebaseTransaction } from '../common/rebase-transaction';
9
9
  import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode as _createBodiedSyncBlockNode } from '../utils/utils';
10
+ // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
11
+ // Designed to manage local in-memory state and synchronize with an external data provider.
12
+ // Supports create, flush, and delete operations for source sync blocks.
13
+ // Handles caching, debouncing updates, and publish/subscribe for local changes.
14
+ // Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
10
15
  export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
11
16
  function SourceSyncBlockStoreManager(dataProvider) {
12
17
  var _this = this;
@@ -20,14 +25,22 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
20
25
  this.dataProvider = dataProvider;
21
26
  this.syncBlockCache = new Map();
22
27
  }
23
-
24
- /**
25
- * Add/update a sync block node to/from the local cache
26
- * @param syncBlockNode - The sync block node to update
27
- */
28
28
  return _createClass(SourceSyncBlockStoreManager, [{
29
+ key: "isSourceBlock",
30
+ value: function isSourceBlock(node) {
31
+ return node.type.name === 'bodiedSyncBlock';
32
+ }
33
+
34
+ /**
35
+ * Add/update a sync block node to/from the local cache
36
+ * @param syncBlockNode - The sync block node to update
37
+ */
38
+ }, {
29
39
  key: "updateSyncBlockData",
30
40
  value: function updateSyncBlockData(syncBlockNode) {
41
+ if (!this.isSourceBlock(syncBlockNode)) {
42
+ throw new Error('Invalid sync block node type provided for updateSyncBlockData');
43
+ }
31
44
  var _syncBlockNode$attrs = syncBlockNode.attrs,
32
45
  localId = _syncBlockNode$attrs.localId,
33
46
  resourceId = _syncBlockNode$attrs.resourceId;
@@ -45,9 +58,9 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
45
58
  * @returns true if saving all nodes successfully, false if fail to save some/all nodes
46
59
  */
47
60
  }, {
48
- key: "flushBodiedSyncBlocks",
61
+ key: "flush",
49
62
  value: (function () {
50
- var _flushBodiedSyncBlocks = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
63
+ var _flush = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
51
64
  var bodiedSyncBlockNodes, bodiedSyncBlockData, writeResults;
52
65
  return _regeneratorRuntime.wrap(function _callee$(_context) {
53
66
  while (1) switch (_context.prev = _context.next) {
@@ -97,10 +110,10 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
97
110
  }
98
111
  }, _callee, this, [[0, 14]]);
99
112
  }));
100
- function flushBodiedSyncBlocks() {
101
- return _flushBodiedSyncBlocks.apply(this, arguments);
113
+ function flush() {
114
+ return _flush.apply(this, arguments);
102
115
  }
103
- return flushBodiedSyncBlocks;
116
+ return flush;
104
117
  }())
105
118
  }, {
106
119
  key: "setEditorView",
@@ -112,6 +125,10 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
112
125
  value: function registerPendingCreation(resourceId) {
113
126
  this.pendingResourceId = resourceId;
114
127
  }
128
+
129
+ /**
130
+ * Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
131
+ */
115
132
  }, {
116
133
  key: "registerCreationCallback",
117
134
  value: function registerCreationCallback(callback) {
@@ -131,6 +148,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
131
148
  this.pendingResourceId = undefined;
132
149
  this.creationCallback = undefined;
133
150
  }
151
+
152
+ /**
153
+ *
154
+ * @returns true if waiting for the result of saving new bodiedSyncBlock to backend
155
+ */
134
156
  }, {
135
157
  key: "hasPendingCreation",
136
158
  value: function hasPendingCreation() {
@@ -150,6 +172,10 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
150
172
  value: function requireConfirmationBeforeDelete() {
151
173
  return !!this.confirmationCallback;
152
174
  }
175
+
176
+ /**
177
+ * @returns attributes for a new bodiedSyncBlock node
178
+ */
153
179
  }, {
154
180
  key: "generateBodiedSyncBlockAttrs",
155
181
  value: function generateBodiedSyncBlockAttrs() {
@@ -166,6 +192,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
166
192
  localId: localId
167
193
  };
168
194
  }
195
+
196
+ /**
197
+ * Create a bodiedSyncBlock node with empty content to backend
198
+ * @param attrs attributes Ids of the node
199
+ */
169
200
  }, {
170
201
  key: "createBodiedSyncBlockNode",
171
202
  value: function createBodiedSyncBlockNode(attrs) {
@@ -284,5 +315,16 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
284
315
  }
285
316
  this.confirmationTransaction = _rebaseTransaction(this.confirmationTransaction, incomingTr, state);
286
317
  }
318
+ }, {
319
+ key: "destroy",
320
+ value: function destroy() {
321
+ this.syncBlockCache.clear();
322
+ this.confirmationCallback = undefined;
323
+ this.confirmationTransaction = undefined;
324
+ this.pendingResourceId = undefined;
325
+ this.creationCallback = undefined;
326
+ this.dataProvider = undefined;
327
+ this.editorView = undefined;
328
+ }
287
329
  }]);
288
330
  }();
@@ -1,181 +1,36 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
- // eslint-disable-next-line no-restricted-imports
4
-
5
- import { convertPMNodeToSyncBlockNode } from '../utils/utils';
6
3
  import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
7
4
  import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
8
5
 
9
- // A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
10
- // Supports create, read, update, and delete operations for sync blocks.
11
- // Designed to manage local in-memory state and synchronize with an external data provider.
12
- // Handles caching, debouncing updates, and publish/subscribe for local changes.
13
- // Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
6
+ // A parent store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
7
+ // Contains two child store managers: ReferenceSyncBlockStoreManager and SourceSyncBlockStoreManager.
8
+ // ReferenceSyncBlockStoreManager is responsible for the lifecycle and state management of reference sync blocks in an editor instance.
9
+ // SourceSyncBlockStoreManager is responsible for the lifecycle and state management of source sync blocks in an editor instance.
10
+ // Can be used in both editor and renderer contexts.
14
11
  export var SyncBlockStoreManager = /*#__PURE__*/function () {
15
12
  function SyncBlockStoreManager(dataProvider) {
16
13
  _classCallCheck(this, SyncBlockStoreManager);
17
- this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider);
14
+ // In future, if reference manager needs to reach to source manager and read it's current in memorey cache
15
+ // we can pass the source manager as a parameter to the reference manager constructor
18
16
  this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider);
17
+ this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider);
19
18
  }
20
-
21
- /**
22
- * Fetch sync block data for a given array of sync block nodes.
23
- * @param nodes - The array of sync block nodes to fetch data for
24
- * @returns The fetched sync block data results
25
- */
26
19
  return _createClass(SyncBlockStoreManager, [{
27
- key: "fetchSyncBlocksData",
28
- value: function fetchSyncBlocksData(nodes) {
29
- var syncBlockNodes = nodes.map(function (node) {
30
- return convertPMNodeToSyncBlockNode(node);
31
- }).filter(function (node) {
32
- return node !== undefined;
33
- }) || [];
34
- if (syncBlockNodes.length === 0) {
35
- return Promise.resolve([]);
36
- }
37
- return this.referenceSyncBlockStoreManager.fetchSyncBlocksData(syncBlockNodes);
38
- }
39
- }, {
40
- key: "getReferenceSyncBlockStoreManager",
41
- value: function getReferenceSyncBlockStoreManager() {
20
+ key: "referenceManager",
21
+ get: function get() {
42
22
  return this.referenceSyncBlockStoreManager;
43
23
  }
44
-
45
- /**
46
- * Add/update a sync block node to/from the local cache
47
- * @param syncBlockNode - The sync block node to update
48
- */
49
- }, {
50
- key: "updateSyncBlockData",
51
- value: function updateSyncBlockData(syncBlockNode) {
52
- if (this.isSourceBlock(syncBlockNode)) {
53
- return this.sourceSyncBlockStoreManager.updateSyncBlockData(syncBlockNode);
54
- } else {
55
- throw new Error('Invalid sync block node type provided for updateSyncBlockData');
56
- }
57
- }
58
-
59
- /**
60
- * Save content of bodiedSyncBlock nodes in local cache to backend
61
- *
62
- * @returns true if saving all nodes successfully, false if fail to save some/all nodes
63
- */
64
- }, {
65
- key: "flushBodiedSyncBlocks",
66
- value: function flushBodiedSyncBlocks() {
67
- // only applicable to source sync block, for now (will be refactored further)
68
- return this.sourceSyncBlockStoreManager.flushBodiedSyncBlocks();
69
- }
70
-
71
- /**
72
- * Get the URL for a sync block.
73
- * @param resourceId - The resource ID of the sync block to get the URL for
74
- * @returns
75
- */
76
- }, {
77
- key: "getSyncBlockURL",
78
- value: function getSyncBlockURL(resourceId) {
79
- // only applicable to reference sync block, for now (will be refactored further)
80
- return this.referenceSyncBlockStoreManager.getSyncBlockURL(resourceId);
81
- }
82
- }, {
83
- key: "setEditorView",
84
- value: function setEditorView(editorView) {
85
- this.sourceSyncBlockStoreManager.setEditorView(editorView);
86
- }
87
- }, {
88
- key: "isSourceBlock",
89
- value: function isSourceBlock(node) {
90
- return node.type.name === 'bodiedSyncBlock';
91
- }
92
- }, {
93
- key: "registerConfirmationCallback",
94
- value: function registerConfirmationCallback(callback) {
95
- // only applicable to source sync block, for now (will be refactored further)
96
- return this.sourceSyncBlockStoreManager.registerConfirmationCallback(callback);
97
- }
98
- }, {
99
- key: "requireConfirmationBeforeDelete",
100
- value: function requireConfirmationBeforeDelete() {
101
- // only applicable to source sync block, for now (will be refactored further)
102
- return this.sourceSyncBlockStoreManager.requireConfirmationBeforeDelete();
103
- }
104
-
105
- /**
106
- * Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
107
- */
108
- }, {
109
- key: "registerCreationCallback",
110
- value: function registerCreationCallback(callback) {
111
- this.sourceSyncBlockStoreManager.registerCreationCallback(callback);
112
- }
113
-
114
- /**
115
- *
116
- * @returns true if waiting for the result of saving new bodiedSyncBlock to backend
117
- */
118
- }, {
119
- key: "hasPendingCreation",
120
- value: function hasPendingCreation() {
121
- return this.sourceSyncBlockStoreManager.hasPendingCreation();
122
- }
123
-
124
- /**
125
- * @returns attributes for a new bodiedSyncBlock node
126
- */
127
- }, {
128
- key: "generateBodiedSyncBlockAttrs",
129
- value: function generateBodiedSyncBlockAttrs() {
130
- return this.sourceSyncBlockStoreManager.generateBodiedSyncBlockAttrs();
131
- }
132
-
133
- /**
134
- * Save bodiedSyncBlock with empty content to backend
135
- * @param attrs attributes Ids of the node
136
- */
137
- }, {
138
- key: "createBodiedSyncBlockNode",
139
- value: function createBodiedSyncBlockNode(attrs) {
140
- // only applicable to source sync block, for now (will be refactored further)
141
- return this.sourceSyncBlockStoreManager.createBodiedSyncBlockNode(attrs);
142
- }
143
- }, {
144
- key: "subscribeToSyncBlockData",
145
- value: function subscribeToSyncBlockData(node, callback) {
146
- return this.referenceSyncBlockStoreManager.subscribe(node, callback);
147
- }
148
- }, {
149
- key: "subscribeToSyncBlockSourceTitle",
150
- value: function subscribeToSyncBlockSourceTitle(node, callback) {
151
- return this.referenceSyncBlockStoreManager.subscribeToSourceTitle(node, callback);
152
- }
153
- }, {
154
- key: "refreshSubscriptions",
155
- value: function refreshSubscriptions() {
156
- this.referenceSyncBlockStoreManager.refreshSubscriptions();
157
- }
158
- }, {
159
- key: "deleteSyncBlocksWithConfirmation",
160
- value: function deleteSyncBlocksWithConfirmation(tr, syncBlockIds) {
161
- // only applicable to source sync block, for now (will be refactored further)
162
- return this.sourceSyncBlockStoreManager.deleteSyncBlocksWithConfirmation(tr, syncBlockIds);
163
- }
164
- }, {
165
- key: "rebaseTransaction",
166
- value: function rebaseTransaction(incomingTr, state) {
167
- // only applicable to source sync block, for now (will be refactored further)
168
- this.sourceSyncBlockStoreManager.rebaseTransaction(incomingTr, state);
169
- }
170
24
  }, {
171
- key: "getReferenceSyncBlockProviderFactory",
172
- value: function getReferenceSyncBlockProviderFactory(resourceId) {
173
- return this.referenceSyncBlockStoreManager.getProviderFactory(resourceId);
25
+ key: "sourceManager",
26
+ get: function get() {
27
+ return this.sourceSyncBlockStoreManager;
174
28
  }
175
29
  }, {
176
30
  key: "destroy",
177
31
  value: function destroy() {
178
32
  this.referenceSyncBlockStoreManager.destroy();
33
+ this.sourceSyncBlockStoreManager.destroy();
179
34
  }
180
35
  }]);
181
36
  }();
@@ -5,9 +5,6 @@ export var convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNo
5
5
  resourceId: node.attrs.resourceId
6
6
  };
7
7
  };
8
- export var isBlogPageType = function isBlogPageType(pageType) {
9
- return pageType === 'blogpost';
10
- };
11
8
  export var createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
12
9
  return {
13
10
  type: 'syncBlock',
@@ -38,4 +35,11 @@ export var convertPMNodeToSyncBlockNode = function convertPMNodeToSyncBlockNode(
38
35
  return undefined;
39
36
  }
40
37
  return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
38
+ };
39
+ export var convertPMNodesToSyncBlockNodes = function convertPMNodesToSyncBlockNodes(nodes) {
40
+ return nodes.map(function (node) {
41
+ return convertPMNodeToSyncBlockNode(node);
42
+ }).filter(function (node) {
43
+ return node !== undefined;
44
+ }) || [];
41
45
  };
@@ -10,4 +10,4 @@ export declare const blockResourceIdFromSourceAndLocalId: (sourceId: string, loc
10
10
  * @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
11
11
  * @returns the localId of the block node. A randomly generated UUID
12
12
  */
13
- export declare const getLocalIdFromResourceId: (ari: string) => string;
13
+ export declare const getLocalIdFromBlockResourceId: (ari: string) => string;
@@ -1,4 +1,4 @@
1
- import type { SyncBlockProduct } from '../common/types';
1
+ import type { SyncBlockProduct } from '../../common/types';
2
2
  export type BlockContentResponse = {
3
3
  blockAri: string;
4
4
  blockInstanceId: string;
@@ -0,0 +1,9 @@
1
+ export type PAGE_TYPE = 'page' | 'blogpost';
2
+ export declare const getConfluencePageAri: (pageId: string, cloudId: string, pageType?: PAGE_TYPE) => string;
3
+ export declare const getPageIdAndTypeFromConfluencePageAri: (ari: string) => {
4
+ id: string;
5
+ type: PAGE_TYPE;
6
+ };
7
+ export declare const getLocalIdFromConfluencePageAri: (ari: string) => string;
8
+ export declare const getPageARIFromContentPropertyResourceId: (resourceId: string) => string;
9
+ export declare const resourceIdFromConfluencePageSourceIdAndLocalId: (sourceId: string, localId: string) => string;
@@ -1,4 +1,4 @@
1
- import type { SyncBlockData } from '../common/types';
1
+ import type { SyncBlockData } from '../../common/types';
2
2
  import { type PAGE_TYPE } from './ari';
3
3
  type GetContentPropertyOptions = {
4
4
  cloudId: string;
@@ -0,0 +1,2 @@
1
+ import type { SyncBlockSourceInfo } from '../../providers/types';
2
+ export declare const fetchConfluenceSourceInfo: (pageAri: string, localId?: string) => Promise<SyncBlockSourceInfo | undefined>;
@@ -0,0 +1,2 @@
1
+ import type { PAGE_TYPE } from './ari';
2
+ export declare const isBlogPageType: (pageType: PAGE_TYPE) => boolean;
@@ -4,13 +4,14 @@ export type { SyncBlockData, SyncBlockNode } from './common/types';
4
4
  export { useFetchSyncBlockData, type UseFetchSyncBlockDataResult, } from './hooks/useFetchSyncBlockData';
5
5
  export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
6
6
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
7
- export { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId, } from './providers/block-service/ari';
7
+ export { blockResourceIdFromSourceAndLocalId, getLocalIdFromBlockResourceId, } from './clients/block-service/ari';
8
+ export { getConfluencePageAri, getLocalIdFromConfluencePageAri, getPageARIFromContentPropertyResourceId, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId, } from './clients/confluence/ari';
8
9
  export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/blockServiceAPI';
9
10
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluence/confluenceContentAPI';
11
+ export { fetchConfluenceSourceInfo } from './clients/confluence/sourceInfo';
10
12
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
11
13
  export type { ADFFetchProvider, ADFWriteProvider, SyncBlockDataProvider, SyncBlockInstance, MediaEmojiProviderOptions, SyncedBlockRendererProviderOptions, SyncBlockRendererProviderCreator, } from './providers/types';
12
14
  export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
13
15
  export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
14
- export { getConfluencePageAri, getLocalIdFromAri, getPageARIFromResourceId, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId, } from './utils/ari';
15
- export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, } from './utils/utils';
16
16
  export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
17
+ export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, } from './utils/utils';