@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
@@ -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,180 +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
- // eslint-disable-next-line no-restricted-imports
14
- // A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
15
- // Supports create, read, update, and delete operations for sync blocks.
16
- // Designed to manage local in-memory state and synchronize with an external data provider.
17
- // Handles caching, debouncing updates, and publish/subscribe for local changes.
18
- // 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.
19
17
  var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/function () {
20
18
  function SyncBlockStoreManager(dataProvider) {
21
19
  (0, _classCallCheck2.default)(this, SyncBlockStoreManager);
22
- 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
23
22
  this.sourceSyncBlockStoreManager = new _sourceSyncBlockStoreManager.SourceSyncBlockStoreManager(dataProvider);
23
+ this.referenceSyncBlockStoreManager = new _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager(dataProvider);
24
24
  }
25
-
26
- /**
27
- * Fetch sync block data for a given array of sync block nodes.
28
- * @param nodes - The array of sync block nodes to fetch data for
29
- * @returns The fetched sync block data results
30
- */
31
25
  return (0, _createClass2.default)(SyncBlockStoreManager, [{
32
- key: "fetchSyncBlocksData",
33
- value: function fetchSyncBlocksData(nodes) {
34
- var syncBlockNodes = nodes.map(function (node) {
35
- return (0, _utils.convertPMNodeToSyncBlockNode)(node);
36
- }).filter(function (node) {
37
- return node !== undefined;
38
- }) || [];
39
- if (syncBlockNodes.length === 0) {
40
- return Promise.resolve([]);
41
- }
42
- return this.referenceSyncBlockStoreManager.fetchSyncBlocksData(syncBlockNodes);
43
- }
44
- }, {
45
- key: "getReferenceSyncBlockStoreManager",
46
- value: function getReferenceSyncBlockStoreManager() {
26
+ key: "referenceManager",
27
+ get: function get() {
47
28
  return this.referenceSyncBlockStoreManager;
48
29
  }
49
-
50
- /**
51
- * Add/update a sync block node to/from the local cache
52
- * @param syncBlockNode - The sync block node to update
53
- */
54
- }, {
55
- key: "updateSyncBlockData",
56
- value: function updateSyncBlockData(syncBlockNode) {
57
- if (this.isSourceBlock(syncBlockNode)) {
58
- return this.sourceSyncBlockStoreManager.updateSyncBlockData(syncBlockNode);
59
- } else {
60
- throw new Error('Invalid sync block node type provided for updateSyncBlockData');
61
- }
62
- }
63
-
64
- /**
65
- * Save content of bodiedSyncBlock nodes in local cache to backend
66
- *
67
- * @returns true if saving all nodes successfully, false if fail to save some/all nodes
68
- */
69
- }, {
70
- key: "flushBodiedSyncBlocks",
71
- value: function flushBodiedSyncBlocks() {
72
- // only applicable to source sync block, for now (will be refactored further)
73
- return this.sourceSyncBlockStoreManager.flushBodiedSyncBlocks();
74
- }
75
-
76
- /**
77
- * Get the URL for a sync block.
78
- * @param resourceId - The resource ID of the sync block to get the URL for
79
- * @returns
80
- */
81
- }, {
82
- key: "getSyncBlockURL",
83
- value: function getSyncBlockURL(resourceId) {
84
- // only applicable to reference sync block, for now (will be refactored further)
85
- return this.referenceSyncBlockStoreManager.getSyncBlockURL(resourceId);
86
- }
87
- }, {
88
- key: "setEditorView",
89
- value: function setEditorView(editorView) {
90
- this.sourceSyncBlockStoreManager.setEditorView(editorView);
91
- }
92
- }, {
93
- key: "isSourceBlock",
94
- value: function isSourceBlock(node) {
95
- return node.type.name === 'bodiedSyncBlock';
96
- }
97
- }, {
98
- key: "registerConfirmationCallback",
99
- value: function registerConfirmationCallback(callback) {
100
- // only applicable to source sync block, for now (will be refactored further)
101
- return this.sourceSyncBlockStoreManager.registerConfirmationCallback(callback);
102
- }
103
- }, {
104
- key: "requireConfirmationBeforeDelete",
105
- value: function requireConfirmationBeforeDelete() {
106
- // only applicable to source sync block, for now (will be refactored further)
107
- return this.sourceSyncBlockStoreManager.requireConfirmationBeforeDelete();
108
- }
109
-
110
- /**
111
- * Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
112
- */
113
- }, {
114
- key: "registerCreationCallback",
115
- value: function registerCreationCallback(callback) {
116
- this.sourceSyncBlockStoreManager.registerCreationCallback(callback);
117
- }
118
-
119
- /**
120
- *
121
- * @returns true if waiting for the result of saving new bodiedSyncBlock to backend
122
- */
123
- }, {
124
- key: "hasPendingCreation",
125
- value: function hasPendingCreation() {
126
- return this.sourceSyncBlockStoreManager.hasPendingCreation();
127
- }
128
-
129
- /**
130
- * @returns attributes for a new bodiedSyncBlock node
131
- */
132
- }, {
133
- key: "generateBodiedSyncBlockAttrs",
134
- value: function generateBodiedSyncBlockAttrs() {
135
- return this.sourceSyncBlockStoreManager.generateBodiedSyncBlockAttrs();
136
- }
137
-
138
- /**
139
- * Save bodiedSyncBlock with empty content to backend
140
- * @param attrs attributes Ids of the node
141
- */
142
- }, {
143
- key: "createBodiedSyncBlockNode",
144
- value: function createBodiedSyncBlockNode(attrs) {
145
- // only applicable to source sync block, for now (will be refactored further)
146
- return this.sourceSyncBlockStoreManager.createBodiedSyncBlockNode(attrs);
147
- }
148
- }, {
149
- key: "subscribeToSyncBlockData",
150
- value: function subscribeToSyncBlockData(node, callback) {
151
- return this.referenceSyncBlockStoreManager.subscribe(node, callback);
152
- }
153
- }, {
154
- key: "subscribeToSyncBlockSourceTitle",
155
- value: function subscribeToSyncBlockSourceTitle(node, callback) {
156
- return this.referenceSyncBlockStoreManager.subscribeToSourceTitle(node, callback);
157
- }
158
- }, {
159
- key: "refreshSubscriptions",
160
- value: function refreshSubscriptions() {
161
- this.referenceSyncBlockStoreManager.refreshSubscriptions();
162
- }
163
- }, {
164
- key: "deleteSyncBlocksWithConfirmation",
165
- value: function deleteSyncBlocksWithConfirmation(tr, syncBlockIds) {
166
- // only applicable to source sync block, for now (will be refactored further)
167
- return this.sourceSyncBlockStoreManager.deleteSyncBlocksWithConfirmation(tr, syncBlockIds);
168
- }
169
- }, {
170
- key: "rebaseTransaction",
171
- value: function rebaseTransaction(incomingTr, state) {
172
- // only applicable to source sync block, for now (will be refactored further)
173
- this.sourceSyncBlockStoreManager.rebaseTransaction(incomingTr, state);
174
- }
175
30
  }, {
176
- key: "getReferenceSyncBlockProviderFactory",
177
- value: function getReferenceSyncBlockProviderFactory(resourceId) {
178
- return this.referenceSyncBlockStoreManager.getProviderFactory(resourceId);
31
+ key: "sourceManager",
32
+ get: function get() {
33
+ return this.sourceSyncBlockStoreManager;
179
34
  }
180
35
  }, {
181
36
  key: "destroy",
182
37
  value: function destroy() {
183
38
  this.referenceSyncBlockStoreManager.destroy();
39
+ this.sourceSyncBlockStoreManager.destroy();
184
40
  }
185
41
  }]);
186
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];
@@ -3,7 +3,7 @@
3
3
  export const getConfluencePageAri = (pageId, cloudId, pageType = 'page') => `ari:cloud:confluence:${cloudId}:${pageType}/${pageId}`;
4
4
 
5
5
  // For extracting from Page ARI and also the content property's version of resourceId
6
- export const getPageIdAndTypeFromAri = ari => {
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
  };
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
2
2
  export const useFetchSyncBlockTitle = (manager, syncBlockNode) => {
3
3
  const [sourceTitle, setSourceTitle] = useState(undefined);
4
4
  useEffect(() => {
5
- const unsubscribe = manager.subscribeToSyncBlockSourceTitle(syncBlockNode, title => {
5
+ const unsubscribe = manager.referenceManager.subscribeToSourceTitle(syncBlockNode, title => {
6
6
  setSourceTitle(title);
7
7
  });
8
8
  return () => {
@@ -2,7 +2,7 @@ import { useEffect } from 'react';
2
2
  export const useHandleContentChanges = (manager, syncBlockNode) => {
3
3
  useEffect(() => {
4
4
  try {
5
- manager.updateSyncBlockData(syncBlockNode);
5
+ manager.sourceManager.updateSyncBlockData(syncBlockNode);
6
6
  } catch {
7
7
  //TODO: EDITOR-1921 - add error analytics
8
8
  }
@@ -1,16 +1,26 @@
1
1
  /* eslint-disable @atlaskit/editor/no-re-export */
2
2
 
3
+ // common
3
4
  export { rebaseTransaction } from './common/rebase-transaction';
4
5
  export { SyncBlockError } from './common/types';
6
+ // hooks
5
7
  export { useFetchSyncBlockData } from './hooks/useFetchSyncBlockData';
6
8
  export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
7
9
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
8
- export { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from './providers/block-service/ari';
10
+
11
+ // clients
12
+ export { blockResourceIdFromSourceAndLocalId, getLocalIdFromBlockResourceId } from './clients/block-service/ari';
13
+ export { getConfluencePageAri, getLocalIdFromConfluencePageAri, getPageARIFromContentPropertyResourceId, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from './clients/confluence/ari';
14
+
15
+ // providers
9
16
  export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/blockServiceAPI';
10
17
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
18
+ export { fetchConfluenceSourceInfo } from './clients/confluence/sourceInfo';
11
19
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
20
+ // store managers
12
21
  export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
13
22
  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
- export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
23
+
24
+ // utils
25
+ export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
26
+ export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes } from './utils/utils';
@@ -1,8 +1,8 @@
1
1
  import { useMemo } from 'react';
2
+ import { blockResourceIdFromSourceAndLocalId, getLocalIdFromBlockResourceId } from '../../clients/block-service/ari';
3
+ import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../clients/block-service/blockService';
2
4
  import { SyncBlockError } from '../../common/types';
3
- import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../utils/blockService';
4
5
  import { stringifyError } from '../../utils/errorHandling';
5
- import { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from './ari';
6
6
  const mapBlockError = error => {
7
7
  switch (error.status) {
8
8
  case 403:
@@ -20,7 +20,7 @@ class BlockServiceADFFetchProvider {
20
20
  // resourceId is the ARI of the block. E.G ari:cloud:blocks:site-123:synced-block/uuid-456
21
21
  // in the content API provider, this was the concatenation of the source document's ARI and the local ID. E.G ari:cloud:confluence:site-123:page/pageId/uuid-456
22
22
  async fetchData(resourceId) {
23
- const localId = getLocalIdFromResourceId(resourceId);
23
+ const localId = getLocalIdFromBlockResourceId(resourceId);
24
24
  try {
25
25
  const blockContentResponse = await getSyncedBlockContent({
26
26
  blockAri: resourceId
@@ -59,7 +59,7 @@ class BlockServiceADFFetchProvider {
59
59
  retrieveSourceInfoFetchData(resourceId, pageARI) {
60
60
  let sourceLocalId;
61
61
  try {
62
- sourceLocalId = getLocalIdFromResourceId(resourceId);
62
+ sourceLocalId = getLocalIdFromBlockResourceId(resourceId);
63
63
  } catch (error) {
64
64
  // EDITOR-1921: log analytic here, safe to continue
65
65
  }
@@ -1,10 +1,10 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { useMemo } from 'react';
3
+ import { getConfluencePageAri, getPageARIFromContentPropertyResourceId, getLocalIdFromConfluencePageAri, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from '../../clients/confluence/ari';
4
+ import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../clients/confluence/contentProperty';
5
+ import { isBlogPageType } from '../../clients/confluence/utils';
3
6
  import { SyncBlockError } from '../../common/types';
4
- import { getConfluencePageAri, getPageARIFromResourceId, getLocalIdFromAri, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from '../../utils/ari';
5
- import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../utils/contentProperty';
6
7
  import { stringifyError } from '../../utils/errorHandling';
7
- import { isBlogPageType } from '../../utils/utils';
8
8
 
9
9
  /**
10
10
  * Configuration for Content API providers
@@ -51,8 +51,8 @@ class ConfluenceADFFetchProvider {
51
51
  const {
52
52
  id: pageId,
53
53
  type: pageType
54
- } = getPageIdAndTypeFromAri(resourceId);
55
- const localId = getLocalIdFromAri(resourceId);
54
+ } = getPageIdAndTypeFromConfluencePageAri(resourceId);
55
+ const localId = getLocalIdFromConfluencePageAri(resourceId);
56
56
  try {
57
57
  const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
58
58
  const options = {
@@ -99,10 +99,10 @@ class ConfluenceADFFetchProvider {
99
99
  }
100
100
  }
101
101
  retrieveSourceInfoFetchData(resourceId) {
102
- const pageARI = getPageARIFromResourceId(resourceId);
102
+ const pageARI = getPageARIFromContentPropertyResourceId(resourceId);
103
103
  let sourceLocalId;
104
104
  try {
105
- sourceLocalId = getLocalIdFromAri(resourceId);
105
+ sourceLocalId = getLocalIdFromConfluencePageAri(resourceId);
106
106
  } catch (error) {
107
107
  // EDITOR-1921: log analytic here, safe to continue
108
108
  }
@@ -152,7 +152,7 @@ class ConfluenceADFWriteProvider {
152
152
  resourceId
153
153
  } = data;
154
154
  try {
155
- match = getPageIdAndTypeFromAri(data.resourceId);
155
+ match = getPageIdAndTypeFromConfluencePageAri(data.resourceId);
156
156
  } catch (error) {
157
157
  return {
158
158
  error: stringifyError(error)
@@ -164,7 +164,7 @@ class ConfluenceADFWriteProvider {
164
164
  } = match;
165
165
  try {
166
166
  // Update existing content property
167
- const localId = getLocalIdFromAri(resourceId);
167
+ const localId = getLocalIdFromConfluencePageAri(resourceId);
168
168
  const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
169
169
  const sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
170
170
  const syncBlockDataWithSourceDocumentAri = {
@@ -209,7 +209,7 @@ class ConfluenceADFWriteProvider {
209
209
  async deleteData(resourceId) {
210
210
  let deletePayload, deleteResult, match;
211
211
  try {
212
- match = getPageIdAndTypeFromAri(resourceId);
212
+ match = getPageIdAndTypeFromConfluencePageAri(resourceId);
213
213
  } catch (error) {
214
214
  return {
215
215
  resourceId,
@@ -222,7 +222,7 @@ class ConfluenceADFWriteProvider {
222
222
  type: pageType
223
223
  } = match;
224
224
  try {
225
- const localId = getLocalIdFromAri(resourceId);
225
+ const localId = getLocalIdFromConfluencePageAri(resourceId);
226
226
  const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
227
227
  const options = {
228
228
  pageId,
@@ -247,7 +247,7 @@ class ConfluenceADFWriteProvider {
247
247
  };
248
248
  }
249
249
  generateResourceId(sourceId, localId) {
250
- return resourceIdFromSourceAndLocalId(sourceId, localId);
250
+ return resourceIdFromConfluencePageSourceIdAndLocalId(sourceId, localId);
251
251
  }
252
252
  }
253
253