@atlaskit/editor-synced-block-provider 2.9.1 → 2.10.2
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 +27 -0
- package/dist/cjs/index.js +7 -6
- package/dist/cjs/providers/block-service/ari.js +34 -0
- package/dist/cjs/providers/block-service/blockServiceAPI.js +15 -1
- package/dist/cjs/providers/confluence/confluenceContentAPI.js +36 -14
- package/dist/cjs/providers/syncBlockProvider.js +37 -6
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +51 -10
- package/dist/cjs/store-manager/syncBlockStoreManager.js +1 -0
- package/dist/cjs/utils/ari.js +3 -32
- package/dist/cjs/utils/sourceInfo.js +3 -3
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/providers/block-service/ari.js +28 -0
- package/dist/es2019/providers/block-service/blockServiceAPI.js +13 -1
- package/dist/es2019/providers/confluence/confluenceContentAPI.js +21 -2
- package/dist/es2019/providers/syncBlockProvider.js +38 -7
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +51 -10
- package/dist/es2019/store-manager/syncBlockStoreManager.js +2 -0
- package/dist/es2019/utils/ari.js +2 -31
- package/dist/es2019/utils/sourceInfo.js +3 -3
- package/dist/esm/index.js +2 -1
- package/dist/esm/providers/block-service/ari.js +28 -0
- package/dist/esm/providers/block-service/blockServiceAPI.js +15 -1
- package/dist/esm/providers/confluence/confluenceContentAPI.js +37 -15
- package/dist/esm/providers/syncBlockProvider.js +38 -7
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +51 -10
- package/dist/esm/store-manager/syncBlockStoreManager.js +2 -0
- package/dist/esm/utils/ari.js +2 -31
- package/dist/esm/utils/sourceInfo.js +3 -3
- package/dist/types/common/types.d.ts +3 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/providers/block-service/ari.d.ts +13 -0
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +3 -2
- package/dist/types/providers/confluence/confluenceContentAPI.d.ts +3 -2
- package/dist/types/providers/syncBlockProvider.d.ts +10 -1
- package/dist/types/providers/types.d.ts +25 -8
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
- package/dist/types/utils/ari.d.ts +0 -15
- package/dist/types/utils/blockService.d.ts +3 -3
- package/dist/types/utils/sourceInfo.d.ts +1 -1
- package/dist/types-ts4.5/common/types.d.ts +3 -1
- package/dist/types-ts4.5/index.d.ts +3 -2
- package/dist/types-ts4.5/providers/block-service/ari.d.ts +13 -0
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +3 -2
- package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +3 -2
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +10 -1
- package/dist/types-ts4.5/providers/types.d.ts +25 -8
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
- package/dist/types-ts4.5/utils/ari.d.ts +0 -15
- package/dist/types-ts4.5/utils/blockService.d.ts +3 -3
- package/dist/types-ts4.5/utils/sourceInfo.d.ts +1 -1
- package/package.json +6 -12
|
@@ -2,9 +2,11 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { SyncBlockError } from '../common/types';
|
|
4
4
|
import { SyncBlockDataProvider } from '../providers/types';
|
|
5
|
-
import {
|
|
5
|
+
import { getPageIdAndTypeFromAri } from '../utils/ari';
|
|
6
6
|
import { fetchSourceInfo } from '../utils/sourceInfo';
|
|
7
7
|
export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
8
|
+
// the source document ARI; that the source sync block is on.
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Constructor for the SyncBlockProvider
|
|
10
12
|
*
|
|
@@ -136,6 +138,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
136
138
|
* @returns The source info
|
|
137
139
|
*/
|
|
138
140
|
retrieveSyncBlockSourceInfo(node) {
|
|
141
|
+
// with content API, this is the concatenation of the page ARI and the block's localId.
|
|
142
|
+
// with block service, this is the ARI of the block.
|
|
143
|
+
// this can be cleaned up from the specific providers and placed here after platform_synced_blocks_block_service_provider
|
|
139
144
|
const {
|
|
140
145
|
resourceId
|
|
141
146
|
} = node.attrs;
|
|
@@ -143,15 +148,12 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
143
148
|
let sourceLocalId;
|
|
144
149
|
if (resourceId && typeof resourceId === 'string') {
|
|
145
150
|
try {
|
|
146
|
-
|
|
151
|
+
const fetchData = this.fetchProvider.retrieveSourceInfoFetchData(resourceId, this.sourceId);
|
|
152
|
+
pageARI = fetchData.pageARI;
|
|
153
|
+
sourceLocalId = fetchData.sourceLocalId;
|
|
147
154
|
} catch (error) {
|
|
148
155
|
return Promise.reject(error);
|
|
149
156
|
}
|
|
150
|
-
try {
|
|
151
|
-
sourceLocalId = getLocalIdFromAri(resourceId);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
// EDITOR-1921: log analytic here, safe to continue
|
|
154
|
-
}
|
|
155
157
|
}
|
|
156
158
|
return pageARI ? fetchSourceInfo(pageARI, sourceLocalId) : Promise.resolve(undefined);
|
|
157
159
|
}
|
|
@@ -167,6 +169,35 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
167
169
|
getSyncedBlockRendererProviderOptions() {
|
|
168
170
|
return this.providerOptions;
|
|
169
171
|
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Retrieve the parent info for the sync block
|
|
175
|
+
*
|
|
176
|
+
* @param resourceId
|
|
177
|
+
* @param syncBlockInstance
|
|
178
|
+
*
|
|
179
|
+
* @returns The parent info for the sync block
|
|
180
|
+
*/
|
|
181
|
+
retrieveSyncBlockParentInfo(syncBlockInstance) {
|
|
182
|
+
if (!syncBlockInstance || !syncBlockInstance.data) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
const {
|
|
186
|
+
sourceAri,
|
|
187
|
+
resourceId,
|
|
188
|
+
product: contentProduct
|
|
189
|
+
} = syncBlockInstance.data;
|
|
190
|
+
|
|
191
|
+
// Temp solution to get the pageId from resource since the sourceDocumentAri is not available for older sync blocks
|
|
192
|
+
const pageARI = sourceAri || resourceId;
|
|
193
|
+
const {
|
|
194
|
+
id: contentId
|
|
195
|
+
} = getPageIdAndTypeFromAri(pageARI);
|
|
196
|
+
return {
|
|
197
|
+
contentId,
|
|
198
|
+
contentProduct: contentProduct || 'confluence-page'
|
|
199
|
+
};
|
|
200
|
+
}
|
|
170
201
|
}
|
|
171
202
|
export const useMemoizedSyncedBlockProvider = (fetchProvider, writeProvider, sourceId, providerOptions) => {
|
|
172
203
|
return useMemo(() => {
|
|
@@ -235,21 +235,62 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
235
235
|
return undefined;
|
|
236
236
|
}
|
|
237
237
|
const {
|
|
238
|
-
parentDataProviders
|
|
238
|
+
parentDataProviders,
|
|
239
|
+
providerCreator
|
|
239
240
|
} = this.dataProvider.getSyncedBlockRendererProviderOptions();
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
// So we need to keep the reference to the Provider Factory so we can then set media & emoji providers later
|
|
244
|
-
this.providerFactories.set(resourceId, ProviderFactory.create({
|
|
245
|
-
emojiProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.emojiProvider,
|
|
246
|
-
mediaProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mediaProvider,
|
|
241
|
+
let providerFactory = this.providerFactories.get(resourceId);
|
|
242
|
+
if (!providerFactory) {
|
|
243
|
+
providerFactory = ProviderFactory.create({
|
|
247
244
|
mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
|
|
248
245
|
profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
|
|
249
246
|
taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
|
|
250
|
-
})
|
|
247
|
+
});
|
|
248
|
+
this.providerFactories.set(resourceId, providerFactory);
|
|
249
|
+
}
|
|
250
|
+
if (providerCreator) {
|
|
251
|
+
this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
|
|
252
|
+
}
|
|
253
|
+
return providerFactory;
|
|
254
|
+
}
|
|
255
|
+
retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
|
|
256
|
+
if (!this.dataProvider) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const hasMediaProvider = providerFactory.hasProvider('mediaProvider');
|
|
260
|
+
const hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
|
|
261
|
+
if (hasMediaProvider && hasEmojiProvider) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const parentInfo = this.dataProvider.retrieveSyncBlockParentInfo(this.syncBlockCache.get(resourceId));
|
|
265
|
+
if (!parentInfo) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const {
|
|
269
|
+
contentId,
|
|
270
|
+
contentProduct
|
|
271
|
+
} = parentInfo;
|
|
272
|
+
if (!hasMediaProvider) {
|
|
273
|
+
if (providerCreator.createMediaProvider && contentId && contentProduct) {
|
|
274
|
+
const mediaProvider = providerCreator.createMediaProvider({
|
|
275
|
+
contentProduct,
|
|
276
|
+
contentId
|
|
277
|
+
});
|
|
278
|
+
if (mediaProvider) {
|
|
279
|
+
providerFactory.setProvider('mediaProvider', mediaProvider);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (!hasEmojiProvider) {
|
|
284
|
+
if (providerCreator.createEmojiProvider && contentId && contentProduct) {
|
|
285
|
+
const emojiProvider = providerCreator.createEmojiProvider({
|
|
286
|
+
contentProduct,
|
|
287
|
+
contentId
|
|
288
|
+
});
|
|
289
|
+
if (emojiProvider) {
|
|
290
|
+
providerFactory.setProvider('emojiProvider', emojiProvider);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
251
293
|
}
|
|
252
|
-
return this.providerFactories.get(resourceId);
|
|
253
294
|
}
|
|
254
295
|
destroy() {
|
|
255
296
|
this.syncBlockCache.clear();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// eslint-disable-next-line no-restricted-imports
|
|
2
|
+
|
|
1
3
|
import { convertPMNodeToSyncBlockNode } from '../utils/utils';
|
|
2
4
|
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
3
5
|
import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
package/dist/es2019/utils/ari.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable require-unicode-regexp */
|
|
2
2
|
|
|
3
3
|
export const getConfluencePageAri = (pageId, cloudId, pageType = 'page') => `ari:cloud:confluence:${cloudId}:${pageType}/${pageId}`;
|
|
4
|
+
|
|
5
|
+
// For extracting from Page ARI and also the content property's version of resourceId
|
|
4
6
|
export const getPageIdAndTypeFromAri = ari => {
|
|
5
7
|
const match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
|
|
6
8
|
if (match !== null && match !== void 0 && match[2]) {
|
|
@@ -27,35 +29,4 @@ export const getPageARIFromResourceId = resourceId => {
|
|
|
27
29
|
};
|
|
28
30
|
export const resourceIdFromSourceAndLocalId = (sourceId, localId) => {
|
|
29
31
|
return sourceId + '/' + localId;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* For the following functions, they are used for the block service API provider.
|
|
34
|
-
* The resourceId/blockResourceId always refers to the block ARI.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param sourceId - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
|
|
39
|
-
* @param localId - the localId of the block node. A randomly generated UUID
|
|
40
|
-
* @returns the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
|
|
41
|
-
*/
|
|
42
|
-
export const blockResourceIdFromSourceAndLocalId = (sourceId, localId) => {
|
|
43
|
-
const match = sourceId.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/.*/);
|
|
44
|
-
if (!(match !== null && match !== void 0 && match[1])) {
|
|
45
|
-
throw new Error(`Invalid source ARI: ${sourceId}`);
|
|
46
|
-
}
|
|
47
|
-
const cloudId = match[1];
|
|
48
|
-
return `ari:cloud:blocks:${cloudId}:synced-block/${localId}`;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
|
|
53
|
-
* @returns the localId of the block node. A randomly generated UUID
|
|
54
|
-
*/
|
|
55
|
-
export const getLocalIdFromResourceId = ari => {
|
|
56
|
-
const match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
|
|
57
|
-
if (match !== null && match !== void 0 && match[2]) {
|
|
58
|
-
return match[2];
|
|
59
|
-
}
|
|
60
|
-
throw new Error(`Invalid page ARI: ${ari}`);
|
|
61
32
|
};
|
|
@@ -52,13 +52,13 @@ const getSourceInfo = async ari => {
|
|
|
52
52
|
}
|
|
53
53
|
return await response.json();
|
|
54
54
|
};
|
|
55
|
-
export const fetchSourceInfo = async (
|
|
55
|
+
export const fetchSourceInfo = 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(
|
|
61
|
-
const response = await getSourceInfo(
|
|
60
|
+
} = getPageIdAndTypeFromAri(pageAri);
|
|
61
|
+
const response = await getSourceInfo(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`);
|
package/dist/esm/index.js
CHANGED
|
@@ -5,11 +5,12 @@ export { SyncBlockError } from './common/types';
|
|
|
5
5
|
export { useFetchSyncBlockData } from './hooks/useFetchSyncBlockData';
|
|
6
6
|
export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
|
|
7
7
|
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
8
|
+
export { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from './providers/block-service/ari';
|
|
8
9
|
export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/blockServiceAPI';
|
|
9
10
|
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
|
|
10
11
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
|
|
11
12
|
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
12
13
|
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
13
|
-
export {
|
|
14
|
+
export { getConfluencePageAri, getLocalIdFromAri, getPageARIFromResourceId, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from './utils/ari';
|
|
14
15
|
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode } from './utils/utils';
|
|
15
16
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint-disable require-unicode-regexp */
|
|
2
|
+
/**
|
|
3
|
+
* Generates a unique block ARI from a source ARI and a local ID.
|
|
4
|
+
* @param sourceId - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
|
|
5
|
+
* @param localId - the localId of the block node. A randomly generated UUID
|
|
6
|
+
* @returns the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
|
|
7
|
+
*/
|
|
8
|
+
export var blockResourceIdFromSourceAndLocalId = function blockResourceIdFromSourceAndLocalId(sourceId, localId) {
|
|
9
|
+
var match = sourceId.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/.*/);
|
|
10
|
+
if (!(match !== null && match !== void 0 && match[1])) {
|
|
11
|
+
throw new Error("Invalid source ARI: ".concat(sourceId));
|
|
12
|
+
}
|
|
13
|
+
var cloudId = match[1];
|
|
14
|
+
return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(localId);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Extracts the local ID from a block ARI.
|
|
19
|
+
* @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
|
|
20
|
+
* @returns the localId of the block node. A randomly generated UUID
|
|
21
|
+
*/
|
|
22
|
+
export var getLocalIdFromResourceId = function getLocalIdFromResourceId(ari) {
|
|
23
|
+
var match = ari.match(/ari:cloud:blocks:[^:]+:synced-block\/([a-zA-Z0-9-]+)/);
|
|
24
|
+
if (match !== null && match !== void 0 && match[1]) {
|
|
25
|
+
return match[1];
|
|
26
|
+
}
|
|
27
|
+
throw new Error("Invalid page ARI: ".concat(ari));
|
|
28
|
+
};
|
|
@@ -4,9 +4,9 @@ import _createClass from "@babel/runtime/helpers/createClass";
|
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
import { SyncBlockError } from '../../common/types';
|
|
7
|
-
import { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from '../../utils/ari';
|
|
8
7
|
import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../utils/blockService';
|
|
9
8
|
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:
|
|
@@ -89,6 +89,20 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
89
89
|
}
|
|
90
90
|
return fetchData;
|
|
91
91
|
}()
|
|
92
|
+
}, {
|
|
93
|
+
key: "retrieveSourceInfoFetchData",
|
|
94
|
+
value: function retrieveSourceInfoFetchData(resourceId, pageARI) {
|
|
95
|
+
var sourceLocalId;
|
|
96
|
+
try {
|
|
97
|
+
sourceLocalId = getLocalIdFromResourceId(resourceId);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
// EDITOR-1921: log analytic here, safe to continue
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
pageARI: pageARI,
|
|
103
|
+
sourceLocalId: sourceLocalId
|
|
104
|
+
};
|
|
105
|
+
}
|
|
92
106
|
}]);
|
|
93
107
|
}();
|
|
94
108
|
/**
|
|
@@ -3,10 +3,12 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
3
3
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
4
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
5
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
6
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
+
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; }
|
|
6
8
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
9
|
import { useMemo } from 'react';
|
|
8
10
|
import { SyncBlockError } from '../../common/types';
|
|
9
|
-
import { getLocalIdFromAri, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from '../../utils/ari';
|
|
11
|
+
import { getConfluencePageAri, getPageARIFromResourceId, getLocalIdFromAri, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from '../../utils/ari';
|
|
10
12
|
import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../utils/contentProperty';
|
|
11
13
|
import { stringifyError } from '../../utils/errorHandling';
|
|
12
14
|
import { isBlogPageType } from '../../utils/utils';
|
|
@@ -128,6 +130,21 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
128
130
|
}
|
|
129
131
|
return fetchData;
|
|
130
132
|
}()
|
|
133
|
+
}, {
|
|
134
|
+
key: "retrieveSourceInfoFetchData",
|
|
135
|
+
value: function retrieveSourceInfoFetchData(resourceId) {
|
|
136
|
+
var pageARI = getPageARIFromResourceId(resourceId);
|
|
137
|
+
var sourceLocalId;
|
|
138
|
+
try {
|
|
139
|
+
sourceLocalId = getLocalIdFromAri(resourceId);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
// EDITOR-1921: log analytic here, safe to continue
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
pageARI: pageARI,
|
|
145
|
+
sourceLocalId: sourceLocalId
|
|
146
|
+
};
|
|
147
|
+
}
|
|
131
148
|
}]);
|
|
132
149
|
}();
|
|
133
150
|
/**
|
|
@@ -196,7 +213,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
196
213
|
key: "writeData",
|
|
197
214
|
value: function () {
|
|
198
215
|
var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
|
|
199
|
-
var match, resourceId, _match, pageId, pageType, localId, key, options, updatePayload, updateResult;
|
|
216
|
+
var match, resourceId, _match, pageId, pageType, localId, key, sourceAri, syncBlockDataWithSourceDocumentAri, options, updatePayload, updateResult;
|
|
200
217
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
201
218
|
while (1) switch (_context3.prev = _context3.next) {
|
|
202
219
|
case 0:
|
|
@@ -217,28 +234,33 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
217
234
|
// Update existing content property
|
|
218
235
|
localId = getLocalIdFromAri(resourceId);
|
|
219
236
|
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
237
|
+
sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
|
|
238
|
+
syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({}, data), {}, {
|
|
239
|
+
product: 'confluence-page',
|
|
240
|
+
sourceAri: sourceAri
|
|
241
|
+
});
|
|
220
242
|
options = {
|
|
221
243
|
pageId: pageId,
|
|
222
244
|
key: key,
|
|
223
|
-
value:
|
|
245
|
+
value: syncBlockDataWithSourceDocumentAri,
|
|
224
246
|
cloudId: this.config.cloudId,
|
|
225
247
|
pageType: pageType
|
|
226
248
|
};
|
|
227
|
-
_context3.next =
|
|
249
|
+
_context3.next = 17;
|
|
228
250
|
return updateContentProperty(options);
|
|
229
|
-
case
|
|
251
|
+
case 17:
|
|
230
252
|
updatePayload = _context3.sent;
|
|
231
253
|
updateResult = isBlogPageType(pageType) ? updatePayload.data.confluence.updateValueBlogPostProperty.blogPostProperty : updatePayload.data.confluence.updateValuePageProperty.pageProperty;
|
|
232
254
|
if (!((updateResult === null || updateResult === void 0 ? void 0 : updateResult.key) === key)) {
|
|
233
|
-
_context3.next =
|
|
255
|
+
_context3.next = 23;
|
|
234
256
|
break;
|
|
235
257
|
}
|
|
236
258
|
return _context3.abrupt("return", {
|
|
237
259
|
resourceId: resourceId
|
|
238
260
|
});
|
|
239
|
-
case
|
|
261
|
+
case 23:
|
|
240
262
|
if (updateResult) {
|
|
241
|
-
_context3.next =
|
|
263
|
+
_context3.next = 27;
|
|
242
264
|
break;
|
|
243
265
|
}
|
|
244
266
|
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, data, pageType).then(function () {
|
|
@@ -250,24 +272,24 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
250
272
|
error: error
|
|
251
273
|
};
|
|
252
274
|
}));
|
|
253
|
-
case
|
|
275
|
+
case 27:
|
|
254
276
|
return _context3.abrupt("return", {
|
|
255
277
|
error: "Failed to update ".concat(pageType, " content property")
|
|
256
278
|
});
|
|
257
|
-
case 26:
|
|
258
|
-
_context3.next = 31;
|
|
259
|
-
break;
|
|
260
279
|
case 28:
|
|
261
|
-
_context3.
|
|
280
|
+
_context3.next = 33;
|
|
281
|
+
break;
|
|
282
|
+
case 30:
|
|
283
|
+
_context3.prev = 30;
|
|
262
284
|
_context3.t1 = _context3["catch"](9);
|
|
263
285
|
return _context3.abrupt("return", {
|
|
264
286
|
error: "Failed to write ".concat(pageType)
|
|
265
287
|
});
|
|
266
|
-
case
|
|
288
|
+
case 33:
|
|
267
289
|
case "end":
|
|
268
290
|
return _context3.stop();
|
|
269
291
|
}
|
|
270
|
-
}, _callee3, this, [[1, 5], [9,
|
|
292
|
+
}, _callee3, this, [[1, 5], [9, 30]]);
|
|
271
293
|
}));
|
|
272
294
|
function writeData(_x6) {
|
|
273
295
|
return _writeData.apply(this, arguments);
|
|
@@ -12,9 +12,11 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
12
12
|
import { useMemo } from 'react';
|
|
13
13
|
import { SyncBlockError } from '../common/types';
|
|
14
14
|
import { SyncBlockDataProvider } from '../providers/types';
|
|
15
|
-
import {
|
|
15
|
+
import { getPageIdAndTypeFromAri } from '../utils/ari';
|
|
16
16
|
import { fetchSourceInfo } from '../utils/sourceInfo';
|
|
17
17
|
export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
18
|
+
// the source document ARI; that the source sync block is on.
|
|
19
|
+
|
|
18
20
|
/**
|
|
19
21
|
* Constructor for the SyncBlockProvider
|
|
20
22
|
*
|
|
@@ -209,20 +211,20 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
209
211
|
}, {
|
|
210
212
|
key: "retrieveSyncBlockSourceInfo",
|
|
211
213
|
value: function retrieveSyncBlockSourceInfo(node) {
|
|
214
|
+
// with content API, this is the concatenation of the page ARI and the block's localId.
|
|
215
|
+
// with block service, this is the ARI of the block.
|
|
216
|
+
// this can be cleaned up from the specific providers and placed here after platform_synced_blocks_block_service_provider
|
|
212
217
|
var resourceId = node.attrs.resourceId;
|
|
213
218
|
var pageARI;
|
|
214
219
|
var sourceLocalId;
|
|
215
220
|
if (resourceId && typeof resourceId === 'string') {
|
|
216
221
|
try {
|
|
217
|
-
|
|
222
|
+
var fetchData = this.fetchProvider.retrieveSourceInfoFetchData(resourceId, this.sourceId);
|
|
223
|
+
pageARI = fetchData.pageARI;
|
|
224
|
+
sourceLocalId = fetchData.sourceLocalId;
|
|
218
225
|
} catch (error) {
|
|
219
226
|
return Promise.reject(error);
|
|
220
227
|
}
|
|
221
|
-
try {
|
|
222
|
-
sourceLocalId = getLocalIdFromAri(resourceId);
|
|
223
|
-
} catch (error) {
|
|
224
|
-
// EDITOR-1921: log analytic here, safe to continue
|
|
225
|
-
}
|
|
226
228
|
}
|
|
227
229
|
return pageARI ? fetchSourceInfo(pageARI, sourceLocalId) : Promise.resolve(undefined);
|
|
228
230
|
}
|
|
@@ -242,6 +244,35 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
242
244
|
value: function getSyncedBlockRendererProviderOptions() {
|
|
243
245
|
return this.providerOptions;
|
|
244
246
|
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Retrieve the parent info for the sync block
|
|
250
|
+
*
|
|
251
|
+
* @param resourceId
|
|
252
|
+
* @param syncBlockInstance
|
|
253
|
+
*
|
|
254
|
+
* @returns The parent info for the sync block
|
|
255
|
+
*/
|
|
256
|
+
}, {
|
|
257
|
+
key: "retrieveSyncBlockParentInfo",
|
|
258
|
+
value: function retrieveSyncBlockParentInfo(syncBlockInstance) {
|
|
259
|
+
if (!syncBlockInstance || !syncBlockInstance.data) {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
var _syncBlockInstance$da = syncBlockInstance.data,
|
|
263
|
+
sourceAri = _syncBlockInstance$da.sourceAri,
|
|
264
|
+
resourceId = _syncBlockInstance$da.resourceId,
|
|
265
|
+
contentProduct = _syncBlockInstance$da.product;
|
|
266
|
+
|
|
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),
|
|
270
|
+
contentId = _getPageIdAndTypeFrom.id;
|
|
271
|
+
return {
|
|
272
|
+
contentId: contentId,
|
|
273
|
+
contentProduct: contentProduct || 'confluence-page'
|
|
274
|
+
};
|
|
275
|
+
}
|
|
245
276
|
}]);
|
|
246
277
|
}(SyncBlockDataProvider);
|
|
247
278
|
export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
|
|
@@ -341,20 +341,61 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
341
341
|
return undefined;
|
|
342
342
|
}
|
|
343
343
|
var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
|
|
344
|
-
parentDataProviders = _this$dataProvider$ge.parentDataProviders
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
this.providerFactories.set(resourceId, ProviderFactory.create({
|
|
350
|
-
emojiProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.emojiProvider,
|
|
351
|
-
mediaProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mediaProvider,
|
|
344
|
+
parentDataProviders = _this$dataProvider$ge.parentDataProviders,
|
|
345
|
+
providerCreator = _this$dataProvider$ge.providerCreator;
|
|
346
|
+
var providerFactory = this.providerFactories.get(resourceId);
|
|
347
|
+
if (!providerFactory) {
|
|
348
|
+
providerFactory = ProviderFactory.create({
|
|
352
349
|
mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
|
|
353
350
|
profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
|
|
354
351
|
taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
|
|
355
|
-
})
|
|
352
|
+
});
|
|
353
|
+
this.providerFactories.set(resourceId, providerFactory);
|
|
354
|
+
}
|
|
355
|
+
if (providerCreator) {
|
|
356
|
+
this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
|
|
357
|
+
}
|
|
358
|
+
return providerFactory;
|
|
359
|
+
}
|
|
360
|
+
}, {
|
|
361
|
+
key: "retrieveDynamicProviders",
|
|
362
|
+
value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
|
|
363
|
+
if (!this.dataProvider) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
var hasMediaProvider = providerFactory.hasProvider('mediaProvider');
|
|
367
|
+
var hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
|
|
368
|
+
if (hasMediaProvider && hasEmojiProvider) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo(this.syncBlockCache.get(resourceId));
|
|
372
|
+
if (!parentInfo) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
var contentId = parentInfo.contentId,
|
|
376
|
+
contentProduct = parentInfo.contentProduct;
|
|
377
|
+
if (!hasMediaProvider) {
|
|
378
|
+
if (providerCreator.createMediaProvider && contentId && contentProduct) {
|
|
379
|
+
var mediaProvider = providerCreator.createMediaProvider({
|
|
380
|
+
contentProduct: contentProduct,
|
|
381
|
+
contentId: contentId
|
|
382
|
+
});
|
|
383
|
+
if (mediaProvider) {
|
|
384
|
+
providerFactory.setProvider('mediaProvider', mediaProvider);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (!hasEmojiProvider) {
|
|
389
|
+
if (providerCreator.createEmojiProvider && contentId && contentProduct) {
|
|
390
|
+
var emojiProvider = providerCreator.createEmojiProvider({
|
|
391
|
+
contentProduct: contentProduct,
|
|
392
|
+
contentId: contentId
|
|
393
|
+
});
|
|
394
|
+
if (emojiProvider) {
|
|
395
|
+
providerFactory.setProvider('emojiProvider', emojiProvider);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
356
398
|
}
|
|
357
|
-
return this.providerFactories.get(resourceId);
|
|
358
399
|
}
|
|
359
400
|
}, {
|
|
360
401
|
key: "destroy",
|
|
@@ -1,5 +1,7 @@
|
|
|
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
|
+
|
|
3
5
|
import { convertPMNodeToSyncBlockNode } from '../utils/utils';
|
|
4
6
|
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
5
7
|
import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
package/dist/esm/utils/ari.js
CHANGED
|
@@ -4,6 +4,8 @@ export var getConfluencePageAri = function getConfluencePageAri(pageId, cloudId)
|
|
|
4
4
|
var pageType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'page';
|
|
5
5
|
return "ari:cloud:confluence:".concat(cloudId, ":").concat(pageType, "/").concat(pageId);
|
|
6
6
|
};
|
|
7
|
+
|
|
8
|
+
// For extracting from Page ARI and also the content property's version of resourceId
|
|
7
9
|
export var getPageIdAndTypeFromAri = function getPageIdAndTypeFromAri(ari) {
|
|
8
10
|
var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
|
|
9
11
|
if (match !== null && match !== void 0 && match[2]) {
|
|
@@ -30,35 +32,4 @@ export var getPageARIFromResourceId = function getPageARIFromResourceId(resource
|
|
|
30
32
|
};
|
|
31
33
|
export var resourceIdFromSourceAndLocalId = function resourceIdFromSourceAndLocalId(sourceId, localId) {
|
|
32
34
|
return sourceId + '/' + localId;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* For the following functions, they are used for the block service API provider.
|
|
37
|
-
* The resourceId/blockResourceId always refers to the block ARI.
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @param sourceId - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
|
|
42
|
-
* @param localId - the localId of the block node. A randomly generated UUID
|
|
43
|
-
* @returns the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
|
|
44
|
-
*/
|
|
45
|
-
export var blockResourceIdFromSourceAndLocalId = function blockResourceIdFromSourceAndLocalId(sourceId, localId) {
|
|
46
|
-
var match = sourceId.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/.*/);
|
|
47
|
-
if (!(match !== null && match !== void 0 && match[1])) {
|
|
48
|
-
throw new Error("Invalid source ARI: ".concat(sourceId));
|
|
49
|
-
}
|
|
50
|
-
var cloudId = match[1];
|
|
51
|
-
return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(localId);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
|
|
56
|
-
* @returns the localId of the block node. A randomly generated UUID
|
|
57
|
-
*/
|
|
58
|
-
export var getLocalIdFromResourceId = function getLocalIdFromResourceId(ari) {
|
|
59
|
-
var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
|
|
60
|
-
if (match !== null && match !== void 0 && match[2]) {
|
|
61
|
-
return match[2];
|
|
62
|
-
}
|
|
63
|
-
throw new Error("Invalid page ARI: ".concat(ari));
|
|
64
35
|
};
|
|
@@ -64,15 +64,15 @@ var getSourceInfo = /*#__PURE__*/function () {
|
|
|
64
64
|
};
|
|
65
65
|
}();
|
|
66
66
|
export var fetchSourceInfo = /*#__PURE__*/function () {
|
|
67
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(
|
|
67
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(pageAri, localId) {
|
|
68
68
|
var _response$data, _contentData$space, _getPageIdAndTypeFrom, pageType, response, contentData, title, url, _ref3, base;
|
|
69
69
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
70
70
|
while (1) switch (_context2.prev = _context2.next) {
|
|
71
71
|
case 0:
|
|
72
72
|
_context2.prev = 0;
|
|
73
|
-
_getPageIdAndTypeFrom = getPageIdAndTypeFromAri(
|
|
73
|
+
_getPageIdAndTypeFrom = getPageIdAndTypeFromAri(pageAri), pageType = _getPageIdAndTypeFrom.type;
|
|
74
74
|
_context2.next = 4;
|
|
75
|
-
return getSourceInfo(
|
|
75
|
+
return getSourceInfo(pageAri);
|
|
76
76
|
case 4:
|
|
77
77
|
response = _context2.sent;
|
|
78
78
|
contentData = (_response$data = response.data) === null || _response$data === void 0 || (_response$data = _response$data.content) === null || _response$data === void 0 || (_response$data = _response$data.nodes) === null || _response$data === void 0 ? void 0 : _response$data[0];
|
|
@@ -2,6 +2,7 @@ import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
|
2
2
|
import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
|
|
3
3
|
export type BlockInstanceId = string;
|
|
4
4
|
export type ResourceId = string;
|
|
5
|
+
export type SyncBlockProduct = 'confluence-page' | 'jira-work-item';
|
|
5
6
|
export type SyncBlockAttrs = {
|
|
6
7
|
localId: BlockInstanceId;
|
|
7
8
|
resourceId: ResourceId;
|
|
@@ -22,8 +23,9 @@ export interface SyncBlockData {
|
|
|
22
23
|
createdAt?: string;
|
|
23
24
|
createdBy?: string;
|
|
24
25
|
isSynced?: boolean;
|
|
26
|
+
product?: SyncBlockProduct;
|
|
25
27
|
resourceId: ResourceId;
|
|
26
|
-
|
|
28
|
+
sourceAri?: string;
|
|
27
29
|
sourceTitle?: string;
|
|
28
30
|
sourceURL?: string;
|
|
29
31
|
updatedAt?: string;
|