@atlaskit/editor-synced-block-provider 2.10.2 → 2.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/{providers → clients}/block-service/ari.js +2 -2
- package/dist/cjs/{utils → clients/confluence}/ari.js +5 -5
- package/dist/cjs/{utils → clients/confluence}/contentProperty.js +2 -6
- package/dist/cjs/{utils → clients/confluence}/sourceInfo.js +7 -7
- package/dist/cjs/clients/confluence/utils.js +9 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +5 -6
- package/dist/cjs/hooks/useFetchSyncBlockTitle.js +1 -1
- package/dist/cjs/hooks/useHandleContentChanges.js +1 -1
- package/dist/cjs/index.js +27 -14
- package/dist/cjs/providers/block-service/blockServiceAPI.js +4 -4
- package/dist/cjs/providers/confluence/confluenceContentAPI.js +28 -18
- package/dist/cjs/providers/syncBlockProvider.js +14 -9
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +35 -9
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +52 -10
- package/dist/cjs/store-manager/syncBlockStoreManager.js +14 -158
- package/dist/cjs/utils/utils.js +8 -4
- package/dist/es2019/{providers → clients}/block-service/ari.js +1 -1
- package/dist/es2019/{utils → clients/confluence}/ari.js +4 -4
- package/dist/es2019/{utils → clients/confluence}/contentProperty.js +2 -6
- package/dist/es2019/{utils → clients/confluence}/sourceInfo.js +5 -5
- package/dist/es2019/clients/confluence/utils.js +3 -0
- package/dist/es2019/hooks/useFetchSyncBlockData.js +5 -6
- package/dist/es2019/hooks/useFetchSyncBlockTitle.js +1 -1
- package/dist/es2019/hooks/useHandleContentChanges.js +1 -1
- package/dist/es2019/index.js +14 -4
- package/dist/es2019/providers/block-service/blockServiceAPI.js +4 -4
- package/dist/es2019/providers/confluence/confluenceContentAPI.js +28 -18
- package/dist/es2019/providers/syncBlockProvider.js +14 -9
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +24 -0
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +39 -1
- package/dist/es2019/store-manager/syncBlockStoreManager.js +12 -119
- package/dist/es2019/utils/utils.js +3 -3
- package/dist/esm/{providers → clients}/block-service/ari.js +1 -1
- package/dist/esm/{utils → clients/confluence}/ari.js +4 -4
- package/dist/esm/{utils → clients/confluence}/contentProperty.js +2 -6
- package/dist/esm/{utils → clients/confluence}/sourceInfo.js +7 -7
- package/dist/esm/clients/confluence/utils.js +3 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +5 -6
- package/dist/esm/hooks/useFetchSyncBlockTitle.js +1 -1
- package/dist/esm/hooks/useHandleContentChanges.js +1 -1
- package/dist/esm/index.js +14 -4
- package/dist/esm/providers/block-service/blockServiceAPI.js +4 -4
- package/dist/esm/providers/confluence/confluenceContentAPI.js +28 -18
- package/dist/esm/providers/syncBlockProvider.js +14 -9
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +36 -9
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +52 -10
- package/dist/esm/store-manager/syncBlockStoreManager.js +14 -159
- package/dist/esm/utils/utils.js +7 -3
- package/dist/types/{providers → clients}/block-service/ari.d.ts +1 -1
- package/dist/types/{utils → clients/block-service}/blockService.d.ts +1 -1
- package/dist/types/clients/confluence/ari.d.ts +9 -0
- package/dist/types/{utils → clients/confluence}/contentProperty.d.ts +1 -1
- package/dist/types/clients/confluence/sourceInfo.d.ts +2 -0
- package/dist/types/clients/confluence/utils.d.ts +2 -0
- package/dist/types/index.d.ts +4 -3
- package/dist/types/providers/confluence/confluenceContentAPI.d.ts +1 -1
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +5 -0
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +17 -1
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +4 -59
- package/dist/types/utils/utils.d.ts +1 -2
- package/dist/types-ts4.5/{providers → clients}/block-service/ari.d.ts +1 -1
- package/dist/types-ts4.5/{utils → clients/block-service}/blockService.d.ts +1 -1
- package/dist/types-ts4.5/clients/confluence/ari.d.ts +9 -0
- package/dist/types-ts4.5/{utils → clients/confluence}/contentProperty.d.ts +1 -1
- package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +2 -0
- package/dist/types-ts4.5/clients/confluence/utils.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +4 -3
- package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +1 -1
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +5 -0
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +17 -1
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +4 -59
- package/dist/types-ts4.5/utils/utils.d.ts +1 -2
- package/package.json +3 -3
- package/dist/types/utils/ari.d.ts +0 -9
- package/dist/types/utils/sourceInfo.d.ts +0 -2
- package/dist/types-ts4.5/utils/ari.d.ts +0 -9
- package/dist/types-ts4.5/utils/sourceInfo.d.ts +0 -2
- /package/dist/cjs/{utils → clients/block-service}/blockService.js +0 -0
- /package/dist/es2019/{utils → clients/block-service}/blockService.js +0 -0
- /package/dist/esm/{utils → clients/block-service}/blockService.js +0 -0
|
@@ -2,7 +2,7 @@ import { useEffect } from 'react';
|
|
|
2
2
|
export var useHandleContentChanges = function useHandleContentChanges(manager, syncBlockNode) {
|
|
3
3
|
useEffect(function () {
|
|
4
4
|
try {
|
|
5
|
-
manager.updateSyncBlockData(syncBlockNode);
|
|
5
|
+
manager.sourceManager.updateSyncBlockData(syncBlockNode);
|
|
6
6
|
} catch (_unused) {
|
|
7
7
|
//TODO: EDITOR-1921 - add error analytics
|
|
8
8
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
23
|
+
|
|
24
|
+
// utils
|
|
25
|
+
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
26
|
+
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes } from './utils/utils';
|
|
@@ -3,10 +3,10 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
|
3
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
|
+
import { blockResourceIdFromSourceAndLocalId, getLocalIdFromBlockResourceId } from '../../clients/block-service/ari';
|
|
7
|
+
import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
6
8
|
import { SyncBlockError } from '../../common/types';
|
|
7
|
-
import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../utils/blockService';
|
|
8
9
|
import { stringifyError } from '../../utils/errorHandling';
|
|
9
|
-
import { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from './ari';
|
|
10
10
|
var mapBlockError = function mapBlockError(error) {
|
|
11
11
|
switch (error.status) {
|
|
12
12
|
case 403:
|
|
@@ -34,7 +34,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
34
34
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
35
35
|
while (1) switch (_context.prev = _context.next) {
|
|
36
36
|
case 0:
|
|
37
|
-
localId =
|
|
37
|
+
localId = getLocalIdFromBlockResourceId(resourceId);
|
|
38
38
|
_context.prev = 1;
|
|
39
39
|
_context.next = 4;
|
|
40
40
|
return getSyncedBlockContent({
|
|
@@ -94,7 +94,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
94
94
|
value: function retrieveSourceInfoFetchData(resourceId, pageARI) {
|
|
95
95
|
var sourceLocalId;
|
|
96
96
|
try {
|
|
97
|
-
sourceLocalId =
|
|
97
|
+
sourceLocalId = getLocalIdFromBlockResourceId(resourceId);
|
|
98
98
|
} catch (error) {
|
|
99
99
|
// EDITOR-1921: log analytic here, safe to continue
|
|
100
100
|
}
|
|
@@ -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 =
|
|
67
|
-
localId =
|
|
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 = {
|
|
@@ -107,8 +107,18 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
107
107
|
return _context.abrupt("return", {
|
|
108
108
|
data: {
|
|
109
109
|
content: syncedBlockData.content,
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
// If the block instance ID is not set, use the local ID from the fetch data request
|
|
111
|
+
// This is a fallback for the case where the block instance ID is not set in the synced block data (old data)
|
|
112
|
+
blockInstanceId: syncedBlockData.blockInstanceId || localId,
|
|
113
|
+
// If the resource ID is not set, use the resource ID from the fetch data request
|
|
114
|
+
// This is a fallback for the case where the resource ID is not set in the synced block data (old data)
|
|
115
|
+
resourceId: syncedBlockData.resourceId || resourceId,
|
|
116
|
+
// If the product is not set, use the default product 'confluence-page'
|
|
117
|
+
// This is a fallback for the case where the product is not set in the synced block data (old data)
|
|
118
|
+
product: syncedBlockData.product || 'confluence-page',
|
|
119
|
+
// If the source Ari is not set, use the resource ID as the source Ari
|
|
120
|
+
// This is a fallback for the case where the source Ari is not set in the synced block data (old data)
|
|
121
|
+
sourceAri: syncedBlockData.sourceAri || resourceId
|
|
112
122
|
},
|
|
113
123
|
resourceId: resourceId
|
|
114
124
|
});
|
|
@@ -133,10 +143,10 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
133
143
|
}, {
|
|
134
144
|
key: "retrieveSourceInfoFetchData",
|
|
135
145
|
value: function retrieveSourceInfoFetchData(resourceId) {
|
|
136
|
-
var pageARI =
|
|
146
|
+
var pageARI = getPageARIFromContentPropertyResourceId(resourceId);
|
|
137
147
|
var sourceLocalId;
|
|
138
148
|
try {
|
|
139
|
-
sourceLocalId =
|
|
149
|
+
sourceLocalId = getLocalIdFromConfluencePageAri(resourceId);
|
|
140
150
|
} catch (error) {
|
|
141
151
|
// EDITOR-1921: log analytic here, safe to continue
|
|
142
152
|
}
|
|
@@ -212,14 +222,14 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
212
222
|
return _createClass(ConfluenceADFWriteProvider, [{
|
|
213
223
|
key: "writeData",
|
|
214
224
|
value: function () {
|
|
215
|
-
var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(
|
|
225
|
+
var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(syncBlockData) {
|
|
216
226
|
var match, resourceId, _match, pageId, pageType, localId, key, sourceAri, syncBlockDataWithSourceDocumentAri, options, updatePayload, updateResult;
|
|
217
227
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
218
228
|
while (1) switch (_context3.prev = _context3.next) {
|
|
219
229
|
case 0:
|
|
220
|
-
resourceId =
|
|
230
|
+
resourceId = syncBlockData.resourceId;
|
|
221
231
|
_context3.prev = 1;
|
|
222
|
-
match =
|
|
232
|
+
match = getPageIdAndTypeFromConfluencePageAri(resourceId);
|
|
223
233
|
_context3.next = 8;
|
|
224
234
|
break;
|
|
225
235
|
case 5:
|
|
@@ -232,10 +242,10 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
232
242
|
_match = match, pageId = _match.id, pageType = _match.type;
|
|
233
243
|
_context3.prev = 9;
|
|
234
244
|
// Update existing content property
|
|
235
|
-
localId =
|
|
245
|
+
localId = getLocalIdFromConfluencePageAri(resourceId);
|
|
236
246
|
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
237
247
|
sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
|
|
238
|
-
syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({},
|
|
248
|
+
syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({}, syncBlockData), {}, {
|
|
239
249
|
product: 'confluence-page',
|
|
240
250
|
sourceAri: sourceAri
|
|
241
251
|
});
|
|
@@ -263,7 +273,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
263
273
|
_context3.next = 27;
|
|
264
274
|
break;
|
|
265
275
|
}
|
|
266
|
-
return _context3.abrupt("return", this.createNewContentProperty(pageId, key,
|
|
276
|
+
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncBlockDataWithSourceDocumentAri, pageType).then(function () {
|
|
267
277
|
return {
|
|
268
278
|
resourceId: resourceId
|
|
269
279
|
};
|
|
@@ -305,7 +315,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
305
315
|
while (1) switch (_context4.prev = _context4.next) {
|
|
306
316
|
case 0:
|
|
307
317
|
_context4.prev = 0;
|
|
308
|
-
match =
|
|
318
|
+
match = getPageIdAndTypeFromConfluencePageAri(resourceId);
|
|
309
319
|
_context4.next = 7;
|
|
310
320
|
break;
|
|
311
321
|
case 4:
|
|
@@ -319,7 +329,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
319
329
|
case 7:
|
|
320
330
|
_match2 = match, pageId = _match2.id, pageType = _match2.type;
|
|
321
331
|
_context4.prev = 8;
|
|
322
|
-
localId =
|
|
332
|
+
localId = getLocalIdFromConfluencePageAri(resourceId);
|
|
323
333
|
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
324
334
|
options = {
|
|
325
335
|
pageId: pageId,
|
|
@@ -362,7 +372,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
362
372
|
}, {
|
|
363
373
|
key: "generateResourceId",
|
|
364
374
|
value: function generateResourceId(sourceId, localId) {
|
|
365
|
-
return
|
|
375
|
+
return resourceIdFromConfluencePageSourceIdAndLocalId(sourceId, localId);
|
|
366
376
|
}
|
|
367
377
|
}]);
|
|
368
378
|
}();
|
|
@@ -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
|
-
|
|
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
|
-
|
|
265
|
-
|
|
267
|
+
product = _syncBlockInstance$da.product;
|
|
268
|
+
if (!sourceAri || !product) {
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
266
271
|
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
var _getPageIdAndTypeFrom =
|
|
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:
|
|
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 (
|
|
163
|
+
if (!(syncBlockNodes.length === 0)) {
|
|
150
164
|
_context3.next = 2;
|
|
151
165
|
break;
|
|
152
166
|
}
|
|
153
|
-
|
|
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 =
|
|
185
|
+
_context3.next = 8;
|
|
166
186
|
return this.dataProvider.fetchNodesData(nodesToFetch);
|
|
167
|
-
case
|
|
187
|
+
case 8:
|
|
168
188
|
data = _context3.sent;
|
|
169
189
|
if (data) {
|
|
170
|
-
_context3.next =
|
|
190
|
+
_context3.next = 11;
|
|
171
191
|
break;
|
|
172
192
|
}
|
|
173
193
|
throw new Error('Failed to fetch sync block node data');
|
|
174
|
-
case
|
|
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
|
|
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: "
|
|
61
|
+
key: "flush",
|
|
49
62
|
value: (function () {
|
|
50
|
-
var
|
|
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
|
|
101
|
-
return
|
|
113
|
+
function flush() {
|
|
114
|
+
return _flush.apply(this, arguments);
|
|
102
115
|
}
|
|
103
|
-
return
|
|
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
|
}();
|