@atlaskit/editor-synced-block-provider 2.8.0 → 2.9.1
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 +16 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +3 -2
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/providers/block-service/blockServiceAPI.js +14 -8
- package/dist/cjs/providers/confluence/confluenceContentAPI.js +5 -0
- package/dist/cjs/providers/syncBlockProvider.js +79 -7
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +26 -0
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +2 -5
- package/dist/cjs/store-manager/syncBlockStoreManager.js +5 -0
- package/dist/cjs/utils/ari.js +32 -4
- package/dist/es2019/hooks/useFetchSyncBlockData.js +3 -2
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +12 -8
- package/dist/es2019/providers/confluence/confluenceContentAPI.js +4 -1
- package/dist/es2019/providers/syncBlockProvider.js +73 -5
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +25 -0
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +2 -5
- package/dist/es2019/store-manager/syncBlockStoreManager.js +3 -0
- package/dist/es2019/utils/ari.js +31 -1
- package/dist/esm/hooks/useFetchSyncBlockData.js +3 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +15 -9
- package/dist/esm/providers/confluence/confluenceContentAPI.js +6 -1
- package/dist/esm/providers/syncBlockProvider.js +79 -7
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +26 -0
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +2 -5
- package/dist/esm/store-manager/syncBlockStoreManager.js +5 -0
- package/dist/esm/utils/ari.js +31 -3
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +2 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +1 -0
- package/dist/types/providers/confluence/confluenceContentAPI.d.ts +1 -0
- package/dist/types/providers/syncBlockProvider.d.ts +60 -3
- package/dist/types/providers/types.d.ts +23 -0
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +3 -0
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +2 -0
- package/dist/types/utils/ari.d.ts +15 -1
- package/dist/types/utils/blockService.d.ts +1 -1
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +1 -0
- package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +1 -0
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +60 -3
- package/dist/types-ts4.5/providers/types.d.ts +23 -0
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +3 -0
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +2 -0
- package/dist/types-ts4.5/utils/ari.d.ts +15 -1
- package/dist/types-ts4.5/utils/blockService.d.ts +1 -1
- package/package.json +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 2.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e3aafa008fcf4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e3aafa008fcf4) -
|
|
8
|
+
EDITOR-2771 Pass parent Editor/Renderer data providers through SyncBlockDataProvider to the nested
|
|
9
|
+
renderer
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 2.9.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [`e0dc40edfc665`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e0dc40edfc665) -
|
|
17
|
+
Update the resource ID generation for blockAri format
|
|
18
|
+
|
|
3
19
|
## 2.8.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -72,8 +72,9 @@ var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyn
|
|
|
72
72
|
};
|
|
73
73
|
}, [localId, referenceSyncBlockStoreManager, resourceId]);
|
|
74
74
|
return {
|
|
75
|
-
syncBlockInstance: syncBlockInstance,
|
|
76
75
|
isLoading: isLoading,
|
|
77
|
-
|
|
76
|
+
providerFactory: referenceSyncBlockStoreManager.getProviderFactory(resourceId || ''),
|
|
77
|
+
reloadData: reloadData,
|
|
78
|
+
syncBlockInstance: syncBlockInstance
|
|
78
79
|
};
|
|
79
80
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "SyncedBlockProvider", {
|
|
|
27
27
|
return _syncBlockProvider.SyncBlockProvider;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "blockResourceIdFromSourceAndLocalId", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _ari.blockResourceIdFromSourceAndLocalId;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
Object.defineProperty(exports, "convertSyncBlockJSONNodeToSyncBlockNode", {
|
|
31
37
|
enumerable: true,
|
|
32
38
|
get: function get() {
|
|
@@ -57,6 +63,24 @@ Object.defineProperty(exports, "getConfluencePageAri", {
|
|
|
57
63
|
return _ari.getConfluencePageAri;
|
|
58
64
|
}
|
|
59
65
|
});
|
|
66
|
+
Object.defineProperty(exports, "getLocalIdFromAri", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function get() {
|
|
69
|
+
return _ari.getLocalIdFromAri;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "getLocalIdFromResourceId", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function get() {
|
|
75
|
+
return _ari.getLocalIdFromResourceId;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "getPageARIFromResourceId", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function get() {
|
|
81
|
+
return _ari.getPageARIFromResourceId;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
60
84
|
Object.defineProperty(exports, "getPageIdAndTypeFromAri", {
|
|
61
85
|
enumerable: true,
|
|
62
86
|
get: function get() {
|
|
@@ -75,6 +99,12 @@ Object.defineProperty(exports, "resolveSyncBlockInstance", {
|
|
|
75
99
|
return _resolveSyncBlockInstance.resolveSyncBlockInstance;
|
|
76
100
|
}
|
|
77
101
|
});
|
|
102
|
+
Object.defineProperty(exports, "resourceIdFromSourceAndLocalId", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: function get() {
|
|
105
|
+
return _ari.resourceIdFromSourceAndLocalId;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
78
108
|
Object.defineProperty(exports, "useFetchSyncBlockData", {
|
|
79
109
|
enumerable: true,
|
|
80
110
|
get: function get() {
|
|
@@ -34,21 +34,22 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
34
34
|
return (0, _createClass2.default)(BlockServiceADFFetchProvider, [{
|
|
35
35
|
key: "fetchData",
|
|
36
36
|
value: // resourceId is the ARI of the block. E.G ari:cloud:blocks:site-123:synced-block/uuid-456
|
|
37
|
+
// in the content API provider, this was the concatenation of the source document's ARI and the local ID. E.G ari:cloud:confluence:site-123:page/pageId/uuid-456
|
|
37
38
|
function () {
|
|
38
39
|
var _fetchData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(resourceId) {
|
|
39
|
-
var localId,
|
|
40
|
+
var localId, blockContentResponse, value, syncedBlockData;
|
|
40
41
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
41
42
|
while (1) switch (_context.prev = _context.next) {
|
|
42
43
|
case 0:
|
|
43
|
-
localId = (0, _ari.
|
|
44
|
+
localId = (0, _ari.getLocalIdFromResourceId)(resourceId);
|
|
44
45
|
_context.prev = 1;
|
|
45
46
|
_context.next = 4;
|
|
46
47
|
return (0, _blockService.getSyncedBlockContent)({
|
|
47
48
|
blockAri: resourceId
|
|
48
49
|
});
|
|
49
50
|
case 4:
|
|
50
|
-
|
|
51
|
-
value =
|
|
51
|
+
blockContentResponse = _context.sent;
|
|
52
|
+
value = blockContentResponse.content;
|
|
52
53
|
if (value) {
|
|
53
54
|
_context.next = 8;
|
|
54
55
|
break;
|
|
@@ -58,7 +59,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
58
59
|
resourceId: resourceId
|
|
59
60
|
});
|
|
60
61
|
case 8:
|
|
61
|
-
// Parse the synced block content from the
|
|
62
|
+
// Parse the synced block content from the response's content
|
|
62
63
|
syncedBlockData = JSON.parse(value);
|
|
63
64
|
return _context.abrupt("return", {
|
|
64
65
|
data: {
|
|
@@ -106,7 +107,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
106
107
|
}
|
|
107
108
|
return (0, _createClass2.default)(BlockServiceADFWriteProvider, [{
|
|
108
109
|
key: "writeData",
|
|
109
|
-
value: // it will first try to update and if it can't (404) then it will try to create
|
|
110
|
+
value: // it will first try to update and if it can't (404) then it will try to create
|
|
110
111
|
function () {
|
|
111
112
|
var _writeData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(data) {
|
|
112
113
|
var resourceId;
|
|
@@ -137,7 +138,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
137
138
|
}
|
|
138
139
|
_context2.next = 13;
|
|
139
140
|
return (0, _blockService.createSyncedBlock)({
|
|
140
|
-
blockAri:
|
|
141
|
+
blockAri: resourceId,
|
|
141
142
|
blockInstanceId: data.blockInstanceId,
|
|
142
143
|
sourceAri: resourceId,
|
|
143
144
|
product: 'confluence-page',
|
|
@@ -166,7 +167,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
166
167
|
return _writeData.apply(this, arguments);
|
|
167
168
|
}
|
|
168
169
|
return writeData;
|
|
169
|
-
}() // soft deletes the source synced block
|
|
170
|
+
}() // soft deletes the source synced block
|
|
170
171
|
}, {
|
|
171
172
|
key: "deleteData",
|
|
172
173
|
value: function () {
|
|
@@ -214,6 +215,11 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
214
215
|
}
|
|
215
216
|
return deleteData;
|
|
216
217
|
}()
|
|
218
|
+
}, {
|
|
219
|
+
key: "generateResourceId",
|
|
220
|
+
value: function generateResourceId(sourceId, localId) {
|
|
221
|
+
return (0, _ari.blockResourceIdFromSourceAndLocalId)(sourceId, localId);
|
|
222
|
+
}
|
|
217
223
|
}]);
|
|
218
224
|
}();
|
|
219
225
|
/**
|
|
@@ -343,6 +343,11 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
343
343
|
}
|
|
344
344
|
return deleteData;
|
|
345
345
|
}()
|
|
346
|
+
}, {
|
|
347
|
+
key: "generateResourceId",
|
|
348
|
+
value: function generateResourceId(sourceId, localId) {
|
|
349
|
+
return (0, _ari.resourceIdFromSourceAndLocalId)(sourceId, localId);
|
|
350
|
+
}
|
|
346
351
|
}]);
|
|
347
352
|
}();
|
|
348
353
|
/**
|
|
@@ -22,7 +22,15 @@ var _sourceInfo = require("../utils/sourceInfo");
|
|
|
22
22
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
23
23
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
24
24
|
var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Constructor for the SyncBlockProvider
|
|
27
|
+
*
|
|
28
|
+
* @param fetchProvider
|
|
29
|
+
* @param writeProvider
|
|
30
|
+
* @param sourceId
|
|
31
|
+
* @param nestedRendererDataProviders
|
|
32
|
+
*/
|
|
33
|
+
function SyncBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
|
|
26
34
|
var _this;
|
|
27
35
|
(0, _classCallCheck2.default)(this, SyncBlockProvider);
|
|
28
36
|
_this = _callSuper(this, SyncBlockProvider);
|
|
@@ -30,19 +38,44 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
30
38
|
_this.fetchProvider = fetchProvider;
|
|
31
39
|
_this.writeProvider = writeProvider;
|
|
32
40
|
_this.sourceId = sourceId;
|
|
41
|
+
_this.providerOptions = providerOptions;
|
|
33
42
|
return _this;
|
|
34
43
|
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check if the node is supported by the provider
|
|
47
|
+
*
|
|
48
|
+
* @param node
|
|
49
|
+
*
|
|
50
|
+
* @returns True if the node is supported, false otherwise
|
|
51
|
+
*/
|
|
35
52
|
(0, _inherits2.default)(SyncBlockProvider, _SyncBlockDataProvide);
|
|
36
53
|
return (0, _createClass2.default)(SyncBlockProvider, [{
|
|
37
54
|
key: "isNodeSupported",
|
|
38
55
|
value: function isNodeSupported(node) {
|
|
39
|
-
return node.type === 'syncBlock';
|
|
56
|
+
return node.type === 'syncBlock' || node.type === 'bodiedSyncBlock';
|
|
40
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get the data key for the node
|
|
61
|
+
*
|
|
62
|
+
* @param node
|
|
63
|
+
*
|
|
64
|
+
* @returns The data key
|
|
65
|
+
*/
|
|
41
66
|
}, {
|
|
42
67
|
key: "nodeDataKey",
|
|
43
68
|
value: function nodeDataKey(node) {
|
|
44
69
|
return node.attrs.localId;
|
|
45
70
|
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Fetch the data from the fetch provider
|
|
74
|
+
*
|
|
75
|
+
* @param nodes
|
|
76
|
+
*
|
|
77
|
+
* @returns Array of {resourceId?: string, error?: string}.
|
|
78
|
+
*/
|
|
46
79
|
}, {
|
|
47
80
|
key: "fetchNodesData",
|
|
48
81
|
value: function fetchNodesData(nodes) {
|
|
@@ -70,6 +103,7 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
70
103
|
}
|
|
71
104
|
|
|
72
105
|
/**
|
|
106
|
+
* Write the data to the write provider
|
|
73
107
|
*
|
|
74
108
|
* @param nodes
|
|
75
109
|
* @param data
|
|
@@ -114,10 +148,18 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
114
148
|
return _writeNodesData.apply(this, arguments);
|
|
115
149
|
}
|
|
116
150
|
return writeNodesData;
|
|
117
|
-
}()
|
|
151
|
+
}()
|
|
152
|
+
/**
|
|
153
|
+
* Delete the data from the write provider
|
|
154
|
+
*
|
|
155
|
+
* @param resourceIds
|
|
156
|
+
*
|
|
157
|
+
* @returns Array of {resourceId?: string, error?: string}.
|
|
158
|
+
*/
|
|
159
|
+
)
|
|
118
160
|
}, {
|
|
119
161
|
key: "deleteNodesData",
|
|
120
|
-
value: function () {
|
|
162
|
+
value: (function () {
|
|
121
163
|
var _deleteNodesData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resourceIds) {
|
|
122
164
|
var _this4 = this;
|
|
123
165
|
var results;
|
|
@@ -152,11 +194,25 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
152
194
|
}
|
|
153
195
|
return deleteNodesData;
|
|
154
196
|
}()
|
|
197
|
+
/**
|
|
198
|
+
* Get the source id
|
|
199
|
+
*
|
|
200
|
+
* @returns The source id
|
|
201
|
+
*/
|
|
202
|
+
)
|
|
155
203
|
}, {
|
|
156
204
|
key: "getSourceId",
|
|
157
205
|
value: function getSourceId() {
|
|
158
206
|
return this.sourceId;
|
|
159
207
|
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Retrieve the source info from the source id
|
|
211
|
+
*
|
|
212
|
+
* @param node
|
|
213
|
+
*
|
|
214
|
+
* @returns The source info
|
|
215
|
+
*/
|
|
160
216
|
}, {
|
|
161
217
|
key: "retrieveSyncBlockSourceInfo",
|
|
162
218
|
value: function retrieveSyncBlockSourceInfo(node) {
|
|
@@ -177,10 +233,26 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
177
233
|
}
|
|
178
234
|
return pageARI ? (0, _sourceInfo.fetchSourceInfo)(pageARI, sourceLocalId) : Promise.resolve(undefined);
|
|
179
235
|
}
|
|
236
|
+
}, {
|
|
237
|
+
key: "generateResourceId",
|
|
238
|
+
value: function generateResourceId(sourceId, localId) {
|
|
239
|
+
return this.writeProvider.generateResourceId(sourceId, localId);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Get the synced block renderer provider options
|
|
244
|
+
*
|
|
245
|
+
* @returns The synced block renderer provider options
|
|
246
|
+
*/
|
|
247
|
+
}, {
|
|
248
|
+
key: "getSyncedBlockRendererProviderOptions",
|
|
249
|
+
value: function getSyncedBlockRendererProviderOptions() {
|
|
250
|
+
return this.providerOptions;
|
|
251
|
+
}
|
|
180
252
|
}]);
|
|
181
253
|
}(_types2.SyncBlockDataProvider);
|
|
182
|
-
var useMemoizedSyncedBlockProvider = exports.useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId) {
|
|
254
|
+
var useMemoizedSyncedBlockProvider = exports.useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
|
|
183
255
|
return (0, _react.useMemo)(function () {
|
|
184
|
-
return new SyncBlockProvider(fetchProvider, writeProvider, sourceId);
|
|
185
|
-
}, [fetchProvider, writeProvider, sourceId]);
|
|
256
|
+
return new SyncBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions);
|
|
257
|
+
}, [fetchProvider, writeProvider, sourceId, providerOptions]);
|
|
186
258
|
};
|
|
@@ -11,6 +11,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
11
11
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
12
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
13
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
+
var _providerFactory = require("@atlaskit/editor-common/provider-factory");
|
|
14
15
|
var _types = require("../common/types");
|
|
15
16
|
var _resolveSyncBlockInstance = require("../utils/resolveSyncBlockInstance");
|
|
16
17
|
var _utils = require("../utils/utils");
|
|
@@ -28,6 +29,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
28
29
|
this.titleSubscriptions = new Map();
|
|
29
30
|
this.dataProvider = dataProvider;
|
|
30
31
|
this.syncBlockURLRequests = new Map();
|
|
32
|
+
this.providerFactories = new Map();
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -243,6 +245,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
243
245
|
key: "deleteFromCache",
|
|
244
246
|
value: function deleteFromCache(resourceId) {
|
|
245
247
|
this.syncBlockCache.delete(resourceId);
|
|
248
|
+
this.providerFactories.delete(resourceId);
|
|
246
249
|
}
|
|
247
250
|
}, {
|
|
248
251
|
key: "subscribeToSyncBlock",
|
|
@@ -338,12 +341,35 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
338
341
|
}
|
|
339
342
|
return (_syncBlock$data = syncBlock.data) === null || _syncBlock$data === void 0 ? void 0 : _syncBlock$data.sourceURL;
|
|
340
343
|
}
|
|
344
|
+
}, {
|
|
345
|
+
key: "getProviderFactory",
|
|
346
|
+
value: function getProviderFactory(resourceId) {
|
|
347
|
+
if (!this.dataProvider) {
|
|
348
|
+
return undefined;
|
|
349
|
+
}
|
|
350
|
+
var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
|
|
351
|
+
parentDataProviders = _this$dataProvider$ge.parentDataProviders;
|
|
352
|
+
if (!this.providerFactories.has(resourceId)) {
|
|
353
|
+
// TODO: EDITOR-2771 - In follow up PR, create media & emoji providers per ref sync block
|
|
354
|
+
// The media & emoji providers will be set later, once we get ref sync block data with page ID
|
|
355
|
+
// So we need to keep the reference to the Provider Factory so we can then set media & emoji providers later
|
|
356
|
+
this.providerFactories.set(resourceId, _providerFactory.ProviderFactory.create({
|
|
357
|
+
emojiProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.emojiProvider,
|
|
358
|
+
mediaProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mediaProvider,
|
|
359
|
+
mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
|
|
360
|
+
profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
|
|
361
|
+
taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
|
|
362
|
+
}));
|
|
363
|
+
}
|
|
364
|
+
return this.providerFactories.get(resourceId);
|
|
365
|
+
}
|
|
341
366
|
}, {
|
|
342
367
|
key: "destroy",
|
|
343
368
|
value: function destroy() {
|
|
344
369
|
this.syncBlockCache.clear();
|
|
345
370
|
this.subscriptions.clear();
|
|
346
371
|
this.syncBlockURLRequests.clear();
|
|
372
|
+
this.providerFactories.clear();
|
|
347
373
|
}
|
|
348
374
|
}]);
|
|
349
375
|
}();
|
|
@@ -12,7 +12,6 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
12
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
13
|
var _uuid = _interopRequireDefault(require("uuid"));
|
|
14
14
|
var _rebaseTransaction2 = require("../common/rebase-transaction");
|
|
15
|
-
var _ari = require("../utils/ari");
|
|
16
15
|
var _utils = require("../utils/utils");
|
|
17
16
|
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
|
|
18
17
|
var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
@@ -165,12 +164,10 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
165
164
|
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
|
|
166
165
|
var localId = (0, _uuid.default)();
|
|
167
166
|
var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
168
|
-
if (!sourceId) {
|
|
167
|
+
if (!this.dataProvider || !sourceId) {
|
|
169
168
|
throw new Error('Provider of sync block plugin is not set');
|
|
170
169
|
}
|
|
171
|
-
|
|
172
|
-
// This should be generated by the data provider implementation as it differs between data providers
|
|
173
|
-
var resourceId = (0, _ari.resourceIdFromSourceAndLocalId)(sourceId, localId);
|
|
170
|
+
var resourceId = this.dataProvider.generateResourceId(sourceId, localId);
|
|
174
171
|
return {
|
|
175
172
|
resourceId: resourceId,
|
|
176
173
|
localId: localId
|
|
@@ -171,6 +171,11 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
171
171
|
// only applicable to source sync block, for now (will be refactored further)
|
|
172
172
|
this.sourceSyncBlockStoreManager.rebaseTransaction(incomingTr, state);
|
|
173
173
|
}
|
|
174
|
+
}, {
|
|
175
|
+
key: "getReferenceSyncBlockProviderFactory",
|
|
176
|
+
value: function getReferenceSyncBlockProviderFactory(resourceId) {
|
|
177
|
+
return this.referenceSyncBlockStoreManager.getProviderFactory(resourceId);
|
|
178
|
+
}
|
|
174
179
|
}, {
|
|
175
180
|
key: "destroy",
|
|
176
181
|
value: function destroy() {
|
package/dist/cjs/utils/ari.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.resourceIdFromSourceAndLocalId = exports.getPageIdAndTypeFromAri = exports.getPageARIFromResourceId = exports.
|
|
6
|
+
exports.resourceIdFromSourceAndLocalId = exports.getPageIdAndTypeFromAri = exports.getPageARIFromResourceId = exports.getLocalIdFromResourceId = exports.getLocalIdFromAri = exports.getConfluencePageAri = exports.blockResourceIdFromSourceAndLocalId = void 0;
|
|
7
7
|
/* eslint-disable require-unicode-regexp */
|
|
8
8
|
|
|
9
9
|
var getConfluencePageAri = exports.getConfluencePageAri = function getConfluencePageAri(pageId, cloudId) {
|
|
@@ -34,9 +34,37 @@ var getPageARIFromResourceId = exports.getPageARIFromResourceId = function getPa
|
|
|
34
34
|
}
|
|
35
35
|
throw new Error("Invalid resourceId: ".concat(resourceId));
|
|
36
36
|
};
|
|
37
|
-
var getContentPropertyAri = exports.getContentPropertyAri = function getContentPropertyAri(contentPropertyId, cloudId) {
|
|
38
|
-
return "ari:cloud:confluence:".concat(cloudId, ":content/").concat(contentPropertyId);
|
|
39
|
-
};
|
|
40
37
|
var resourceIdFromSourceAndLocalId = exports.resourceIdFromSourceAndLocalId = function resourceIdFromSourceAndLocalId(sourceId, localId) {
|
|
41
38
|
return sourceId + '/' + localId;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* For the following functions, they are used for the block service API provider.
|
|
43
|
+
* The resourceId/blockResourceId always refers to the block ARI.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param sourceId - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
|
|
48
|
+
* @param localId - the localId of the block node. A randomly generated UUID
|
|
49
|
+
* @returns the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
|
|
50
|
+
*/
|
|
51
|
+
var blockResourceIdFromSourceAndLocalId = exports.blockResourceIdFromSourceAndLocalId = function blockResourceIdFromSourceAndLocalId(sourceId, localId) {
|
|
52
|
+
var match = sourceId.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/.*/);
|
|
53
|
+
if (!(match !== null && match !== void 0 && match[1])) {
|
|
54
|
+
throw new Error("Invalid source ARI: ".concat(sourceId));
|
|
55
|
+
}
|
|
56
|
+
var cloudId = match[1];
|
|
57
|
+
return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(localId);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
|
|
62
|
+
* @returns the localId of the block node. A randomly generated UUID
|
|
63
|
+
*/
|
|
64
|
+
var getLocalIdFromResourceId = exports.getLocalIdFromResourceId = function getLocalIdFromResourceId(ari) {
|
|
65
|
+
var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
|
|
66
|
+
if (match !== null && match !== void 0 && match[2]) {
|
|
67
|
+
return match[2];
|
|
68
|
+
}
|
|
69
|
+
throw new Error("Invalid page ARI: ".concat(ari));
|
|
42
70
|
};
|
|
@@ -36,8 +36,9 @@ export const useFetchSyncBlockData = (manager, resourceId, localId) => {
|
|
|
36
36
|
};
|
|
37
37
|
}, [localId, referenceSyncBlockStoreManager, resourceId]);
|
|
38
38
|
return {
|
|
39
|
-
syncBlockInstance,
|
|
40
39
|
isLoading,
|
|
41
|
-
|
|
40
|
+
providerFactory: referenceSyncBlockStoreManager.getProviderFactory(resourceId || ''),
|
|
41
|
+
reloadData,
|
|
42
|
+
syncBlockInstance
|
|
42
43
|
};
|
|
43
44
|
};
|
package/dist/es2019/index.js
CHANGED
|
@@ -10,6 +10,6 @@ export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders
|
|
|
10
10
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
|
|
11
11
|
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
12
12
|
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
13
|
-
export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
|
|
13
|
+
export { blockResourceIdFromSourceAndLocalId, getConfluencePageAri, getLocalIdFromAri, getLocalIdFromResourceId, getPageARIFromResourceId, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from './utils/ari';
|
|
14
14
|
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode } from './utils/utils';
|
|
15
15
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { SyncBlockError } from '../../common/types';
|
|
3
|
-
import {
|
|
3
|
+
import { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from '../../utils/ari';
|
|
4
4
|
import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../utils/blockService';
|
|
5
5
|
import { stringifyError } from '../../utils/errorHandling';
|
|
6
6
|
const mapBlockError = error => {
|
|
@@ -18,13 +18,14 @@ const mapBlockError = error => {
|
|
|
18
18
|
*/
|
|
19
19
|
class BlockServiceADFFetchProvider {
|
|
20
20
|
// resourceId is the ARI of the block. E.G ari:cloud:blocks:site-123:synced-block/uuid-456
|
|
21
|
+
// in the content API provider, this was the concatenation of the source document's ARI and the local ID. E.G ari:cloud:confluence:site-123:page/pageId/uuid-456
|
|
21
22
|
async fetchData(resourceId) {
|
|
22
|
-
const localId =
|
|
23
|
+
const localId = getLocalIdFromResourceId(resourceId);
|
|
23
24
|
try {
|
|
24
|
-
const
|
|
25
|
+
const blockContentResponse = await getSyncedBlockContent({
|
|
25
26
|
blockAri: resourceId
|
|
26
27
|
});
|
|
27
|
-
const value =
|
|
28
|
+
const value = blockContentResponse.content;
|
|
28
29
|
if (!value) {
|
|
29
30
|
return {
|
|
30
31
|
error: SyncBlockError.NotFound,
|
|
@@ -32,7 +33,7 @@ class BlockServiceADFFetchProvider {
|
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
// Parse the synced block content from the
|
|
36
|
+
// Parse the synced block content from the response's content
|
|
36
37
|
const syncedBlockData = JSON.parse(value);
|
|
37
38
|
return {
|
|
38
39
|
data: {
|
|
@@ -61,7 +62,7 @@ class BlockServiceADFFetchProvider {
|
|
|
61
62
|
* ADFWriteProvider implementation that writes synced block data to Block Service API
|
|
62
63
|
*/
|
|
63
64
|
class BlockServiceADFWriteProvider {
|
|
64
|
-
// it will first try to update and if it can't (404) then it will try to create
|
|
65
|
+
// it will first try to update and if it can't (404) then it will try to create
|
|
65
66
|
async writeData(data) {
|
|
66
67
|
const {
|
|
67
68
|
resourceId
|
|
@@ -80,7 +81,7 @@ class BlockServiceADFWriteProvider {
|
|
|
80
81
|
if (error.status === 404) {
|
|
81
82
|
// Create the block
|
|
82
83
|
await createSyncedBlock({
|
|
83
|
-
blockAri:
|
|
84
|
+
blockAri: resourceId,
|
|
84
85
|
blockInstanceId: data.blockInstanceId,
|
|
85
86
|
sourceAri: resourceId,
|
|
86
87
|
product: 'confluence-page',
|
|
@@ -100,7 +101,7 @@ class BlockServiceADFWriteProvider {
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
// soft deletes the source synced block
|
|
104
|
+
// soft deletes the source synced block
|
|
104
105
|
async deleteData(resourceId) {
|
|
105
106
|
try {
|
|
106
107
|
await deleteSyncedBlock({
|
|
@@ -126,6 +127,9 @@ class BlockServiceADFWriteProvider {
|
|
|
126
127
|
};
|
|
127
128
|
}
|
|
128
129
|
}
|
|
130
|
+
generateResourceId(sourceId, localId) {
|
|
131
|
+
return blockResourceIdFromSourceAndLocalId(sourceId, localId);
|
|
132
|
+
}
|
|
129
133
|
}
|
|
130
134
|
|
|
131
135
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { SyncBlockError } from '../../common/types';
|
|
4
|
-
import { getLocalIdFromAri, getPageIdAndTypeFromAri } from '../../utils/ari';
|
|
4
|
+
import { getLocalIdFromAri, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from '../../utils/ari';
|
|
5
5
|
import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../utils/contentProperty';
|
|
6
6
|
import { stringifyError } from '../../utils/errorHandling';
|
|
7
7
|
import { isBlogPageType } from '../../utils/utils';
|
|
@@ -227,6 +227,9 @@ class ConfluenceADFWriteProvider {
|
|
|
227
227
|
error: deleteResult.errors.join()
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
|
+
generateResourceId(sourceId, localId) {
|
|
231
|
+
return resourceIdFromSourceAndLocalId(sourceId, localId);
|
|
232
|
+
}
|
|
230
233
|
}
|
|
231
234
|
|
|
232
235
|
/**
|