@atlaskit/editor-synced-block-provider 2.5.2 → 2.7.0
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 +15 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +60 -6
- package/dist/cjs/index.js +24 -5
- package/dist/cjs/providers/confluence/confluenceContentAPI.js +86 -73
- package/dist/cjs/providers/syncBlockProvider.js +60 -36
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +24 -20
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +78 -17
- package/dist/cjs/store-manager/syncBlockStoreManager.js +46 -8
- package/dist/cjs/utils/errorHandling.js +13 -0
- package/dist/cjs/utils/utils.js +32 -1
- package/dist/es2019/hooks/useFetchSyncBlockData.js +35 -6
- package/dist/es2019/index.js +7 -6
- package/dist/es2019/providers/confluence/confluenceContentAPI.js +62 -40
- package/dist/es2019/providers/syncBlockProvider.js +15 -9
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +16 -14
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +64 -12
- package/dist/es2019/store-manager/syncBlockStoreManager.js +34 -8
- package/dist/es2019/utils/errorHandling.js +7 -0
- package/dist/es2019/utils/utils.js +31 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +60 -6
- package/dist/esm/index.js +7 -6
- package/dist/esm/providers/confluence/confluenceContentAPI.js +79 -66
- package/dist/esm/providers/syncBlockProvider.js +60 -36
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +21 -17
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +79 -18
- package/dist/esm/store-manager/syncBlockStoreManager.js +46 -8
- package/dist/esm/utils/errorHandling.js +7 -0
- package/dist/esm/utils/utils.js +31 -0
- package/dist/types/common/schema.d.ts +1 -1
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +6 -3
- package/dist/types/index.d.ts +10 -9
- package/dist/types/providers/confluence/confluenceContentAPI.d.ts +2 -2
- package/dist/types/providers/syncBlockProvider.d.ts +4 -3
- package/dist/types/providers/types.d.ts +6 -2
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +2 -1
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +15 -3
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +22 -3
- package/dist/types/utils/errorHandling.d.ts +1 -0
- package/dist/types/utils/utils.d.ts +6 -1
- package/dist/types-ts4.5/common/schema.d.ts +1 -1
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +6 -3
- package/dist/types-ts4.5/index.d.ts +10 -9
- package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +2 -2
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +4 -3
- package/dist/types-ts4.5/providers/types.d.ts +6 -2
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +2 -1
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +15 -3
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +22 -3
- package/dist/types-ts4.5/utils/errorHandling.d.ts +1 -0
- package/dist/types-ts4.5/utils/utils.d.ts +6 -1
- package/package.json +2 -2
- package/dist/cjs/utils/createSyncBlock.js +0 -15
- package/dist/es2019/utils/createSyncBlock.js +0 -9
- package/dist/esm/utils/createSyncBlock.js +0 -9
- package/dist/types/utils/createSyncBlock.d.ts +0 -2
- package/dist/types-ts4.5/utils/createSyncBlock.d.ts +0 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import { createSyncBlockNode } from '../utils/createSyncBlock';
|
|
3
2
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
3
|
+
import { createSyncBlockNode } from '../utils/utils';
|
|
4
4
|
export class ReferenceSyncBlockStoreManager {
|
|
5
5
|
constructor(dataProvider) {
|
|
6
6
|
_defineProperty(this, "isRefreshingSubscriptions", false);
|
|
@@ -117,19 +117,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
117
117
|
deleteFromCache(resourceId) {
|
|
118
118
|
this.syncBlockCache.delete(resourceId);
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
// check node is a sync block, as we only support sync block subscriptions
|
|
122
|
-
if (node.type.name !== 'syncBlock') {
|
|
123
|
-
return () => {};
|
|
124
|
-
}
|
|
125
|
-
const {
|
|
126
|
-
resourceId,
|
|
127
|
-
localId
|
|
128
|
-
} = node.attrs;
|
|
129
|
-
if (!localId || !resourceId) {
|
|
130
|
-
return () => {};
|
|
131
|
-
}
|
|
132
|
-
|
|
120
|
+
subscribeToSyncBlock(resourceId, localId, callback) {
|
|
133
121
|
// add to subscriptions map
|
|
134
122
|
const resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
135
123
|
this.subscriptions.set(resourceId, {
|
|
@@ -193,6 +181,20 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
193
181
|
}
|
|
194
182
|
};
|
|
195
183
|
}
|
|
184
|
+
subscribe(node, callback) {
|
|
185
|
+
// check node is a sync block, as we only support sync block subscriptions
|
|
186
|
+
if (node.type.name !== 'syncBlock') {
|
|
187
|
+
return () => {};
|
|
188
|
+
}
|
|
189
|
+
const {
|
|
190
|
+
resourceId,
|
|
191
|
+
localId
|
|
192
|
+
} = node.attrs;
|
|
193
|
+
if (!localId || !resourceId) {
|
|
194
|
+
return () => {};
|
|
195
|
+
}
|
|
196
|
+
return this.subscribeToSyncBlock(resourceId, localId, callback);
|
|
197
|
+
}
|
|
196
198
|
|
|
197
199
|
/**
|
|
198
200
|
* Get the URL for a sync block.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import uuid from 'uuid';
|
|
2
2
|
import { rebaseTransaction } from '../common/rebase-transaction';
|
|
3
3
|
import { resourceIdFromSourceAndLocalId } from '../utils/ari';
|
|
4
|
-
import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
4
|
+
import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode } from '../utils/utils';
|
|
5
5
|
export class SourceSyncBlockStoreManager {
|
|
6
6
|
constructor(dataProvider) {
|
|
7
7
|
this.dataProvider = dataProvider;
|
|
@@ -50,8 +50,8 @@ export class SourceSyncBlockStoreManager {
|
|
|
50
50
|
if (bodiedSyncBlockNodes.length === 0) {
|
|
51
51
|
return Promise.resolve(true);
|
|
52
52
|
}
|
|
53
|
-
const
|
|
54
|
-
return
|
|
53
|
+
const writeResults = await this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
54
|
+
return writeResults.every(result => result.resourceId !== undefined);
|
|
55
55
|
} catch {
|
|
56
56
|
//TODO: EDITOR-1921 - add error analytics
|
|
57
57
|
return false;
|
|
@@ -60,6 +60,27 @@ export class SourceSyncBlockStoreManager {
|
|
|
60
60
|
setEditorView(editorView) {
|
|
61
61
|
this.editorView = editorView;
|
|
62
62
|
}
|
|
63
|
+
registerPendingCreation(resourceId) {
|
|
64
|
+
this.pendingResourceId = resourceId;
|
|
65
|
+
}
|
|
66
|
+
registerCreationCallback(callback) {
|
|
67
|
+
this.creationCallback = callback;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Fires callback to insert node (if creation is successful) and clears pending creation data
|
|
72
|
+
* @param success
|
|
73
|
+
*/
|
|
74
|
+
commitPendingCreation(success) {
|
|
75
|
+
if (success && this.creationCallback) {
|
|
76
|
+
this.creationCallback();
|
|
77
|
+
}
|
|
78
|
+
this.pendingResourceId = undefined;
|
|
79
|
+
this.creationCallback = undefined;
|
|
80
|
+
}
|
|
81
|
+
hasPendingCreation() {
|
|
82
|
+
return !!this.pendingResourceId;
|
|
83
|
+
}
|
|
63
84
|
registerConfirmationCallback(callback) {
|
|
64
85
|
this.confirmationCallback = callback;
|
|
65
86
|
return () => {
|
|
@@ -69,24 +90,55 @@ export class SourceSyncBlockStoreManager {
|
|
|
69
90
|
requireConfirmationBeforeDelete() {
|
|
70
91
|
return !!this.confirmationCallback;
|
|
71
92
|
}
|
|
72
|
-
|
|
93
|
+
generateBodiedSyncBlockAttrs() {
|
|
73
94
|
var _this$dataProvider;
|
|
74
|
-
const
|
|
95
|
+
const localId = uuid();
|
|
75
96
|
const sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
76
97
|
if (!sourceId) {
|
|
77
98
|
throw new Error('Provider of sync block plugin is not set');
|
|
78
99
|
}
|
|
79
100
|
|
|
80
101
|
// This should be generated by the data provider implementation as it differs between data providers
|
|
81
|
-
const resourceId = resourceIdFromSourceAndLocalId(sourceId,
|
|
82
|
-
|
|
83
|
-
|
|
102
|
+
const resourceId = resourceIdFromSourceAndLocalId(sourceId, localId);
|
|
103
|
+
return {
|
|
104
|
+
resourceId,
|
|
105
|
+
localId
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
createBodiedSyncBlockNode(attrs) {
|
|
109
|
+
try {
|
|
110
|
+
if (!this.dataProvider) {
|
|
111
|
+
throw new Error('Data provider not set');
|
|
112
|
+
}
|
|
113
|
+
const {
|
|
84
114
|
resourceId,
|
|
85
115
|
localId: blockInstanceId
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
116
|
+
} = attrs;
|
|
117
|
+
this.dataProvider.writeNodesData([createBodiedSyncBlockNode(blockInstanceId, resourceId)], [{
|
|
118
|
+
content: [],
|
|
119
|
+
blockInstanceId,
|
|
120
|
+
resourceId: resourceId
|
|
121
|
+
}]).then(results => {
|
|
122
|
+
results.forEach(result => {
|
|
123
|
+
const resourceId = result.resourceId;
|
|
124
|
+
if (resourceId) {
|
|
125
|
+
this.commitPendingCreation(true);
|
|
126
|
+
} else {
|
|
127
|
+
this.commitPendingCreation(false);
|
|
128
|
+
// TODO: EDITOR-1921 - add error analytics
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}).catch(_reason => {
|
|
132
|
+
this.commitPendingCreation(false);
|
|
133
|
+
// TODO: EDITOR-1921 - add error analytics
|
|
134
|
+
});
|
|
135
|
+
this.registerPendingCreation(resourceId);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (this.hasPendingCreation()) {
|
|
138
|
+
this.commitPendingCreation(false);
|
|
139
|
+
}
|
|
140
|
+
// TODO: EDITOR-1921 - add error analytics
|
|
141
|
+
}
|
|
90
142
|
}
|
|
91
143
|
async deleteSyncBlocksWithConfirmation(tr, syncBlockIds) {
|
|
92
144
|
if (this.confirmationCallback) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { convertPMNodeToSyncBlockNode } from '../utils/utils';
|
|
2
2
|
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
3
3
|
import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
|
4
4
|
|
|
@@ -19,16 +19,15 @@ export class SyncBlockStoreManager {
|
|
|
19
19
|
* @returns The fetched sync block data results
|
|
20
20
|
*/
|
|
21
21
|
fetchSyncBlocksData(nodes) {
|
|
22
|
-
const syncBlockNodes = nodes.filter(node =>
|
|
23
|
-
return node.type.name === 'syncBlock' && node.attrs.resourceId && node.attrs.localId;
|
|
24
|
-
}).map(node => {
|
|
25
|
-
return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
|
|
26
|
-
}) || [];
|
|
22
|
+
const syncBlockNodes = nodes.map(node => convertPMNodeToSyncBlockNode(node)).filter(node => node !== undefined) || [];
|
|
27
23
|
if (syncBlockNodes.length === 0) {
|
|
28
24
|
return Promise.resolve([]);
|
|
29
25
|
}
|
|
30
26
|
return this.referenceSyncBlockStoreManager.fetchSyncBlocksData(syncBlockNodes);
|
|
31
27
|
}
|
|
28
|
+
getReferenceSyncBlockStoreManager() {
|
|
29
|
+
return this.referenceSyncBlockStoreManager;
|
|
30
|
+
}
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
33
|
* Add/update a sync block node to/from the local cache
|
|
@@ -75,9 +74,36 @@ export class SyncBlockStoreManager {
|
|
|
75
74
|
// only applicable to source sync block, for now (will be refactored further)
|
|
76
75
|
return this.sourceSyncBlockStoreManager.requireConfirmationBeforeDelete();
|
|
77
76
|
}
|
|
78
|
-
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
|
|
80
|
+
*/
|
|
81
|
+
registerCreationCallback(callback) {
|
|
82
|
+
this.sourceSyncBlockStoreManager.registerCreationCallback(callback);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @returns true if waiting for the result of saving new bodiedSyncBlock to backend
|
|
88
|
+
*/
|
|
89
|
+
hasPendingCreation() {
|
|
90
|
+
return this.sourceSyncBlockStoreManager.hasPendingCreation();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @returns attributes for a new bodiedSyncBlock node
|
|
95
|
+
*/
|
|
96
|
+
generateBodiedSyncBlockAttrs() {
|
|
97
|
+
return this.sourceSyncBlockStoreManager.generateBodiedSyncBlockAttrs();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Save bodiedSyncBlock with empty content to backend
|
|
102
|
+
* @param attrs attributes Ids of the node
|
|
103
|
+
*/
|
|
104
|
+
createBodiedSyncBlockNode(attrs) {
|
|
79
105
|
// only applicable to source sync block, for now (will be refactored further)
|
|
80
|
-
return this.sourceSyncBlockStoreManager.
|
|
106
|
+
return this.sourceSyncBlockStoreManager.createBodiedSyncBlockNode(attrs);
|
|
81
107
|
}
|
|
82
108
|
subscribeToSyncBlockData(node, callback) {
|
|
83
109
|
return this.referenceSyncBlockStoreManager.subscribe(node, callback);
|
|
@@ -7,4 +7,35 @@ export const convertSyncBlockPMNodeToSyncBlockData = node => {
|
|
|
7
7
|
};
|
|
8
8
|
export const isBlogPageType = pageType => {
|
|
9
9
|
return pageType === 'blogpost';
|
|
10
|
+
};
|
|
11
|
+
export const createSyncBlockNode = (localId, resourceId) => {
|
|
12
|
+
return {
|
|
13
|
+
type: 'syncBlock',
|
|
14
|
+
attrs: {
|
|
15
|
+
localId,
|
|
16
|
+
resourceId
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export const createBodiedSyncBlockNode = (localId, resourceId) => {
|
|
21
|
+
return {
|
|
22
|
+
type: 'bodiedSyncBlock',
|
|
23
|
+
attrs: {
|
|
24
|
+
localId,
|
|
25
|
+
resourceId
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export const convertSyncBlockJSONNodeToSyncBlockNode = node => {
|
|
30
|
+
if (node.type !== 'syncBlock' || !node.attrs || !('localId' in node.attrs) || !('resourceId' in node.attrs) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
|
|
34
|
+
};
|
|
35
|
+
export const convertPMNodeToSyncBlockNode = node => {
|
|
36
|
+
var _node$attrs, _node$attrs2;
|
|
37
|
+
if (node.type.name !== 'syncBlock' || !((_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.localId) || !((_node$attrs2 = node.attrs) !== null && _node$attrs2 !== void 0 && _node$attrs2.resourceId) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
|
|
10
41
|
};
|
|
@@ -1,18 +1,72 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
5
|
+
import { SyncBlockError } from '../common/types';
|
|
6
|
+
import { createSyncBlockNode } from '../utils/utils';
|
|
7
|
+
export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resourceId, localId) {
|
|
5
8
|
var _useState = useState(null),
|
|
6
9
|
_useState2 = _slicedToArray(_useState, 2),
|
|
7
10
|
syncBlockInstance = _useState2[0],
|
|
8
11
|
setSyncBlockInstance = _useState2[1];
|
|
12
|
+
var _useState3 = useState(true),
|
|
13
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
14
|
+
isLoading = _useState4[0],
|
|
15
|
+
setIsLoading = _useState4[1];
|
|
16
|
+
var referenceSyncBlockStoreManager = manager.getReferenceSyncBlockStoreManager();
|
|
17
|
+
var reloadData = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
18
|
+
var syncBlockNode;
|
|
19
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
20
|
+
while (1) switch (_context.prev = _context.next) {
|
|
21
|
+
case 0:
|
|
22
|
+
if (!isLoading) {
|
|
23
|
+
_context.next = 2;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
return _context.abrupt("return");
|
|
27
|
+
case 2:
|
|
28
|
+
syncBlockNode = resourceId && localId ? createSyncBlockNode(localId, resourceId) : null;
|
|
29
|
+
if (syncBlockNode) {
|
|
30
|
+
_context.next = 5;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
return _context.abrupt("return");
|
|
34
|
+
case 5:
|
|
35
|
+
setIsLoading(true);
|
|
36
|
+
_context.prev = 6;
|
|
37
|
+
_context.next = 9;
|
|
38
|
+
return referenceSyncBlockStoreManager.fetchSyncBlocksData([syncBlockNode]);
|
|
39
|
+
case 9:
|
|
40
|
+
_context.next = 14;
|
|
41
|
+
break;
|
|
42
|
+
case 11:
|
|
43
|
+
_context.prev = 11;
|
|
44
|
+
_context.t0 = _context["catch"](6);
|
|
45
|
+
// Set error state if fetching fails
|
|
46
|
+
setSyncBlockInstance({
|
|
47
|
+
resourceId: resourceId || '',
|
|
48
|
+
error: SyncBlockError.Errored
|
|
49
|
+
});
|
|
50
|
+
case 14:
|
|
51
|
+
setIsLoading(false);
|
|
52
|
+
case 15:
|
|
53
|
+
case "end":
|
|
54
|
+
return _context.stop();
|
|
55
|
+
}
|
|
56
|
+
}, _callee, null, [[6, 11]]);
|
|
57
|
+
})), [isLoading, localId, referenceSyncBlockStoreManager, resourceId]);
|
|
9
58
|
useEffect(function () {
|
|
10
|
-
var unsubscribe =
|
|
59
|
+
var unsubscribe = referenceSyncBlockStoreManager.subscribeToSyncBlock(resourceId || '', localId || '', function (data) {
|
|
11
60
|
setSyncBlockInstance(data);
|
|
61
|
+
setIsLoading(false);
|
|
12
62
|
});
|
|
13
63
|
return function () {
|
|
14
64
|
unsubscribe();
|
|
15
65
|
};
|
|
16
|
-
}, [
|
|
17
|
-
return
|
|
66
|
+
}, [localId, referenceSyncBlockStoreManager, resourceId]);
|
|
67
|
+
return {
|
|
68
|
+
syncBlockInstance: syncBlockInstance,
|
|
69
|
+
isLoading: isLoading,
|
|
70
|
+
reloadData: reloadData
|
|
71
|
+
};
|
|
18
72
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/* eslint-disable @atlaskit/editor/no-re-export */
|
|
2
2
|
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
3
|
+
export { rebaseTransaction } from './common/rebase-transaction';
|
|
4
|
+
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
5
|
+
export { SyncBlockError } from './common/types';
|
|
5
6
|
export { useFetchSyncBlockData } from './hooks/useFetchSyncBlockData';
|
|
6
7
|
export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
|
|
7
8
|
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
8
|
-
export { SyncBlockError } from './common/types';
|
|
9
|
-
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
10
9
|
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
|
|
10
|
+
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
|
|
11
|
+
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
12
|
+
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
11
13
|
export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
|
|
12
|
-
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
13
|
-
export { rebaseTransaction } from './common/rebase-transaction';
|
|
14
|
+
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode } from './utils/utils';
|
|
14
15
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
@@ -8,6 +8,7 @@ import { useMemo } from 'react';
|
|
|
8
8
|
import { SyncBlockError } from '../../common/types';
|
|
9
9
|
import { getLocalIdFromAri, getPageIdAndTypeFromAri } from '../../utils/ari';
|
|
10
10
|
import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../utils/contentProperty';
|
|
11
|
+
import { stringifyError } from '../../utils/errorHandling';
|
|
11
12
|
import { isBlogPageType } from '../../utils/utils';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -163,7 +164,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
163
164
|
}
|
|
164
165
|
return _context2.abrupt("return", key);
|
|
165
166
|
case 9:
|
|
166
|
-
|
|
167
|
+
return _context2.abrupt("return", Promise.reject('Failed to create blog post content property'));
|
|
167
168
|
case 10:
|
|
168
169
|
_context2.next = 20;
|
|
169
170
|
break;
|
|
@@ -178,7 +179,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
178
179
|
}
|
|
179
180
|
return _context2.abrupt("return", key);
|
|
180
181
|
case 19:
|
|
181
|
-
|
|
182
|
+
return _context2.abrupt("return", Promise.reject('Failed to create page content property'));
|
|
182
183
|
case 20:
|
|
183
184
|
case "end":
|
|
184
185
|
return _context2.stop();
|
|
@@ -195,17 +196,26 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
195
196
|
key: "writeData",
|
|
196
197
|
value: function () {
|
|
197
198
|
var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
|
|
198
|
-
var
|
|
199
|
+
var match, resourceId, _match, pageId, pageType, localId, key, options, updatePayload, updateResult;
|
|
199
200
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
200
201
|
while (1) switch (_context3.prev = _context3.next) {
|
|
201
202
|
case 0:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
resourceId = data.resourceId;
|
|
204
|
+
_context3.prev = 1;
|
|
205
|
+
match = getPageIdAndTypeFromAri(data.resourceId);
|
|
206
|
+
_context3.next = 8;
|
|
207
|
+
break;
|
|
208
|
+
case 5:
|
|
209
|
+
_context3.prev = 5;
|
|
210
|
+
_context3.t0 = _context3["catch"](1);
|
|
211
|
+
return _context3.abrupt("return", {
|
|
212
|
+
error: stringifyError(_context3.t0)
|
|
213
|
+
});
|
|
214
|
+
case 8:
|
|
215
|
+
_match = match, pageId = _match.id, pageType = _match.type;
|
|
216
|
+
_context3.prev = 9;
|
|
207
217
|
// Update existing content property
|
|
208
|
-
localId = getLocalIdFromAri(
|
|
218
|
+
localId = getLocalIdFromAri(resourceId);
|
|
209
219
|
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
210
220
|
options = {
|
|
211
221
|
pageId: pageId,
|
|
@@ -214,60 +224,50 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
214
224
|
cloudId: this.config.cloudId,
|
|
215
225
|
pageType: pageType
|
|
216
226
|
};
|
|
217
|
-
|
|
218
|
-
_context3.next = 20;
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
_context3.next = 8;
|
|
227
|
+
_context3.next = 15;
|
|
222
228
|
return updateContentProperty(options);
|
|
223
|
-
case
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
229
|
+
case 15:
|
|
230
|
+
updatePayload = _context3.sent;
|
|
231
|
+
updateResult = isBlogPageType(pageType) ? updatePayload.data.confluence.updateValueBlogPostProperty.blogPostProperty : updatePayload.data.confluence.updateValuePageProperty.pageProperty;
|
|
232
|
+
if (!((updateResult === null || updateResult === void 0 ? void 0 : updateResult.key) === key)) {
|
|
233
|
+
_context3.next = 21;
|
|
227
234
|
break;
|
|
228
235
|
}
|
|
229
|
-
return _context3.abrupt("return",
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
236
|
+
return _context3.abrupt("return", {
|
|
237
|
+
resourceId: resourceId
|
|
238
|
+
});
|
|
239
|
+
case 21:
|
|
240
|
+
if (updateResult) {
|
|
241
|
+
_context3.next = 25;
|
|
233
242
|
break;
|
|
234
243
|
}
|
|
235
|
-
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, data, pageType))
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
244
|
+
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, data, pageType).then(function () {
|
|
245
|
+
return {
|
|
246
|
+
resourceId: resourceId
|
|
247
|
+
};
|
|
248
|
+
}, function (error) {
|
|
249
|
+
return {
|
|
250
|
+
error: error
|
|
251
|
+
};
|
|
252
|
+
}));
|
|
253
|
+
case 25:
|
|
254
|
+
return _context3.abrupt("return", {
|
|
255
|
+
error: "Failed to update ".concat(pageType, " content property")
|
|
256
|
+
});
|
|
257
|
+
case 26:
|
|
258
|
+
_context3.next = 31;
|
|
240
259
|
break;
|
|
241
|
-
case
|
|
242
|
-
_context3.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
_context3.next = 27;
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
return _context3.abrupt("return", key);
|
|
251
|
-
case 27:
|
|
252
|
-
if (!(_contentProperty3.data.confluence.updateValuePageProperty.pageProperty === null)) {
|
|
253
|
-
_context3.next = 31;
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, data, pageType));
|
|
260
|
+
case 28:
|
|
261
|
+
_context3.prev = 28;
|
|
262
|
+
_context3.t1 = _context3["catch"](9);
|
|
263
|
+
return _context3.abrupt("return", {
|
|
264
|
+
error: "Failed to write ".concat(pageType)
|
|
265
|
+
});
|
|
257
266
|
case 31:
|
|
258
|
-
throw new Error('Failed to update content property');
|
|
259
|
-
case 32:
|
|
260
|
-
_context3.next = 36;
|
|
261
|
-
break;
|
|
262
|
-
case 34:
|
|
263
|
-
// Create new content property
|
|
264
|
-
_key = getContentPropertyKey(this.config.contentPropertyKey, data.blockInstanceId);
|
|
265
|
-
return _context3.abrupt("return", this.createNewContentProperty(pageId, _key, data, pageType));
|
|
266
|
-
case 36:
|
|
267
267
|
case "end":
|
|
268
268
|
return _context3.stop();
|
|
269
269
|
}
|
|
270
|
-
}, _callee3, this);
|
|
270
|
+
}, _callee3, this, [[1, 5], [9, 28]]);
|
|
271
271
|
}));
|
|
272
272
|
function writeData(_x6) {
|
|
273
273
|
return _writeData.apply(this, arguments);
|
|
@@ -278,11 +278,25 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
278
278
|
key: "deleteData",
|
|
279
279
|
value: function () {
|
|
280
280
|
var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(resourceId) {
|
|
281
|
-
var
|
|
281
|
+
var deletePayload, deleteResult, match, _match2, pageId, pageType, localId, key, options, _stringifyError;
|
|
282
282
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
283
283
|
while (1) switch (_context4.prev = _context4.next) {
|
|
284
284
|
case 0:
|
|
285
|
-
|
|
285
|
+
_context4.prev = 0;
|
|
286
|
+
match = getPageIdAndTypeFromAri(resourceId);
|
|
287
|
+
_context4.next = 7;
|
|
288
|
+
break;
|
|
289
|
+
case 4:
|
|
290
|
+
_context4.prev = 4;
|
|
291
|
+
_context4.t0 = _context4["catch"](0);
|
|
292
|
+
return _context4.abrupt("return", {
|
|
293
|
+
resourceId: resourceId,
|
|
294
|
+
success: false,
|
|
295
|
+
error: stringifyError(_context4.t0)
|
|
296
|
+
});
|
|
297
|
+
case 7:
|
|
298
|
+
_match2 = match, pageId = _match2.id, pageType = _match2.type;
|
|
299
|
+
_context4.prev = 8;
|
|
286
300
|
localId = getLocalIdFromAri(resourceId);
|
|
287
301
|
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
288
302
|
options = {
|
|
@@ -291,33 +305,32 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
291
305
|
cloudId: this.config.cloudId,
|
|
292
306
|
pageType: pageType
|
|
293
307
|
};
|
|
294
|
-
_context4.
|
|
295
|
-
_context4.next = 7;
|
|
308
|
+
_context4.next = 14;
|
|
296
309
|
return deleteContentProperty(options);
|
|
297
|
-
case
|
|
310
|
+
case 14:
|
|
298
311
|
deletePayload = _context4.sent;
|
|
299
312
|
deleteResult = isBlogPageType(pageType) ? deletePayload.data.confluence.deleteBlogPostProperty : deletePayload.data.confluence.deletePageProperty;
|
|
300
|
-
_context4.next =
|
|
313
|
+
_context4.next = 21;
|
|
301
314
|
break;
|
|
302
|
-
case
|
|
303
|
-
_context4.prev =
|
|
304
|
-
_context4.
|
|
315
|
+
case 18:
|
|
316
|
+
_context4.prev = 18;
|
|
317
|
+
_context4.t1 = _context4["catch"](8);
|
|
305
318
|
return _context4.abrupt("return", {
|
|
306
319
|
resourceId: resourceId,
|
|
307
320
|
success: false,
|
|
308
|
-
error: "Fail to delete ".concat(pageType, " content property")
|
|
321
|
+
error: (_stringifyError = stringifyError(_context4.t1)) !== null && _stringifyError !== void 0 ? _stringifyError : "Fail to delete ".concat(pageType, " content property")
|
|
309
322
|
});
|
|
310
|
-
case
|
|
323
|
+
case 21:
|
|
311
324
|
return _context4.abrupt("return", {
|
|
312
325
|
resourceId: resourceId,
|
|
313
326
|
success: deleteResult.success,
|
|
314
327
|
error: deleteResult.errors.join()
|
|
315
328
|
});
|
|
316
|
-
case
|
|
329
|
+
case 22:
|
|
317
330
|
case "end":
|
|
318
331
|
return _context4.stop();
|
|
319
332
|
}
|
|
320
|
-
}, _callee4, this, [[4,
|
|
333
|
+
}, _callee4, this, [[0, 4], [8, 18]]);
|
|
321
334
|
}));
|
|
322
335
|
function deleteData(_x7) {
|
|
323
336
|
return _deleteData.apply(this, arguments);
|