@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 2.10.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`27e34de207285`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/27e34de207285) -
|
|
8
|
+
EDITOR-2771 Create media & emoji provider per each reference sync block
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 2.10.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`a05464ea42678`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a05464ea42678) -
|
|
16
|
+
EDITOR-2791 bump adf-schema
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
19
|
+
## 2.10.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- [`00d86f82d23fa`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/00d86f82d23fa) -
|
|
24
|
+
Move ARI checks to providers
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies
|
|
29
|
+
|
|
3
30
|
## 2.9.1
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -60,13 +60,13 @@ Object.defineProperty(exports, "createSyncBlockNode", {
|
|
|
60
60
|
Object.defineProperty(exports, "getConfluencePageAri", {
|
|
61
61
|
enumerable: true,
|
|
62
62
|
get: function get() {
|
|
63
|
-
return
|
|
63
|
+
return _ari2.getConfluencePageAri;
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
Object.defineProperty(exports, "getLocalIdFromAri", {
|
|
67
67
|
enumerable: true,
|
|
68
68
|
get: function get() {
|
|
69
|
-
return
|
|
69
|
+
return _ari2.getLocalIdFromAri;
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
Object.defineProperty(exports, "getLocalIdFromResourceId", {
|
|
@@ -78,13 +78,13 @@ Object.defineProperty(exports, "getLocalIdFromResourceId", {
|
|
|
78
78
|
Object.defineProperty(exports, "getPageARIFromResourceId", {
|
|
79
79
|
enumerable: true,
|
|
80
80
|
get: function get() {
|
|
81
|
-
return
|
|
81
|
+
return _ari2.getPageARIFromResourceId;
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
Object.defineProperty(exports, "getPageIdAndTypeFromAri", {
|
|
85
85
|
enumerable: true,
|
|
86
86
|
get: function get() {
|
|
87
|
-
return
|
|
87
|
+
return _ari2.getPageIdAndTypeFromAri;
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
Object.defineProperty(exports, "rebaseTransaction", {
|
|
@@ -102,7 +102,7 @@ Object.defineProperty(exports, "resolveSyncBlockInstance", {
|
|
|
102
102
|
Object.defineProperty(exports, "resourceIdFromSourceAndLocalId", {
|
|
103
103
|
enumerable: true,
|
|
104
104
|
get: function get() {
|
|
105
|
-
return
|
|
105
|
+
return _ari2.resourceIdFromSourceAndLocalId;
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
108
|
Object.defineProperty(exports, "useFetchSyncBlockData", {
|
|
@@ -146,11 +146,12 @@ var _types = require("./common/types");
|
|
|
146
146
|
var _useFetchSyncBlockData = require("./hooks/useFetchSyncBlockData");
|
|
147
147
|
var _useFetchSyncBlockTitle = require("./hooks/useFetchSyncBlockTitle");
|
|
148
148
|
var _useHandleContentChanges = require("./hooks/useHandleContentChanges");
|
|
149
|
+
var _ari = require("./providers/block-service/ari");
|
|
149
150
|
var _blockServiceAPI = require("./providers/block-service/blockServiceAPI");
|
|
150
151
|
var _confluenceContentAPI = require("./providers/confluence/confluenceContentAPI");
|
|
151
152
|
var _syncBlockProvider = require("./providers/syncBlockProvider");
|
|
152
153
|
var _referenceSyncBlockStoreManager = require("./store-manager/referenceSyncBlockStoreManager");
|
|
153
154
|
var _syncBlockStoreManager = require("./store-manager/syncBlockStoreManager");
|
|
154
|
-
var
|
|
155
|
+
var _ari2 = require("./utils/ari");
|
|
155
156
|
var _utils = require("./utils/utils");
|
|
156
157
|
var _resolveSyncBlockInstance = require("./utils/resolveSyncBlockInstance");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getLocalIdFromResourceId = exports.blockResourceIdFromSourceAndLocalId = void 0;
|
|
7
|
+
/* eslint-disable require-unicode-regexp */
|
|
8
|
+
/**
|
|
9
|
+
* Generates a unique block ARI from a source ARI and a local ID.
|
|
10
|
+
* @param sourceId - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
|
|
11
|
+
* @param localId - the localId of the block node. A randomly generated UUID
|
|
12
|
+
* @returns the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
|
|
13
|
+
*/
|
|
14
|
+
var blockResourceIdFromSourceAndLocalId = exports.blockResourceIdFromSourceAndLocalId = function blockResourceIdFromSourceAndLocalId(sourceId, localId) {
|
|
15
|
+
var match = sourceId.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/.*/);
|
|
16
|
+
if (!(match !== null && match !== void 0 && match[1])) {
|
|
17
|
+
throw new Error("Invalid source ARI: ".concat(sourceId));
|
|
18
|
+
}
|
|
19
|
+
var cloudId = match[1];
|
|
20
|
+
return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(localId);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Extracts the local ID from a block ARI.
|
|
25
|
+
* @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
|
|
26
|
+
* @returns the localId of the block node. A randomly generated UUID
|
|
27
|
+
*/
|
|
28
|
+
var getLocalIdFromResourceId = exports.getLocalIdFromResourceId = function getLocalIdFromResourceId(ari) {
|
|
29
|
+
var match = ari.match(/ari:cloud:blocks:[^:]+:synced-block\/([a-zA-Z0-9-]+)/);
|
|
30
|
+
if (match !== null && match !== void 0 && match[1]) {
|
|
31
|
+
return match[1];
|
|
32
|
+
}
|
|
33
|
+
throw new Error("Invalid page ARI: ".concat(ari));
|
|
34
|
+
};
|
|
@@ -11,9 +11,9 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
11
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
12
|
var _react = require("react");
|
|
13
13
|
var _types = require("../../common/types");
|
|
14
|
-
var _ari = require("../../utils/ari");
|
|
15
14
|
var _blockService = require("../../utils/blockService");
|
|
16
15
|
var _errorHandling = require("../../utils/errorHandling");
|
|
16
|
+
var _ari = require("./ari");
|
|
17
17
|
var mapBlockError = function mapBlockError(error) {
|
|
18
18
|
switch (error.status) {
|
|
19
19
|
case 403:
|
|
@@ -96,6 +96,20 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
96
96
|
}
|
|
97
97
|
return fetchData;
|
|
98
98
|
}()
|
|
99
|
+
}, {
|
|
100
|
+
key: "retrieveSourceInfoFetchData",
|
|
101
|
+
value: function retrieveSourceInfoFetchData(resourceId, pageARI) {
|
|
102
|
+
var sourceLocalId;
|
|
103
|
+
try {
|
|
104
|
+
sourceLocalId = (0, _ari.getLocalIdFromResourceId)(resourceId);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
// EDITOR-1921: log analytic here, safe to continue
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
pageARI: pageARI,
|
|
110
|
+
sourceLocalId: sourceLocalId
|
|
111
|
+
};
|
|
112
|
+
}
|
|
99
113
|
}]);
|
|
100
114
|
}();
|
|
101
115
|
/**
|
|
@@ -17,6 +17,8 @@ var _ari = require("../../utils/ari");
|
|
|
17
17
|
var _contentProperty3 = require("../../utils/contentProperty");
|
|
18
18
|
var _errorHandling = require("../../utils/errorHandling");
|
|
19
19
|
var _utils = require("../../utils/utils");
|
|
20
|
+
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; }
|
|
21
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
20
22
|
/**
|
|
21
23
|
* Configuration for Content API providers
|
|
22
24
|
*/
|
|
@@ -134,6 +136,21 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
134
136
|
}
|
|
135
137
|
return fetchData;
|
|
136
138
|
}()
|
|
139
|
+
}, {
|
|
140
|
+
key: "retrieveSourceInfoFetchData",
|
|
141
|
+
value: function retrieveSourceInfoFetchData(resourceId) {
|
|
142
|
+
var pageARI = (0, _ari.getPageARIFromResourceId)(resourceId);
|
|
143
|
+
var sourceLocalId;
|
|
144
|
+
try {
|
|
145
|
+
sourceLocalId = (0, _ari.getLocalIdFromAri)(resourceId);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
// EDITOR-1921: log analytic here, safe to continue
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
pageARI: pageARI,
|
|
151
|
+
sourceLocalId: sourceLocalId
|
|
152
|
+
};
|
|
153
|
+
}
|
|
137
154
|
}]);
|
|
138
155
|
}();
|
|
139
156
|
/**
|
|
@@ -202,7 +219,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
202
219
|
key: "writeData",
|
|
203
220
|
value: function () {
|
|
204
221
|
var _writeData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(data) {
|
|
205
|
-
var match, resourceId, _match, pageId, pageType, localId, key, options, updatePayload, updateResult;
|
|
222
|
+
var match, resourceId, _match, pageId, pageType, localId, key, sourceAri, syncBlockDataWithSourceDocumentAri, options, updatePayload, updateResult;
|
|
206
223
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
207
224
|
while (1) switch (_context3.prev = _context3.next) {
|
|
208
225
|
case 0:
|
|
@@ -223,28 +240,33 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
223
240
|
// Update existing content property
|
|
224
241
|
localId = (0, _ari.getLocalIdFromAri)(resourceId);
|
|
225
242
|
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
243
|
+
sourceAri = (0, _ari.getConfluencePageAri)(pageId, this.config.cloudId, pageType);
|
|
244
|
+
syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({}, data), {}, {
|
|
245
|
+
product: 'confluence-page',
|
|
246
|
+
sourceAri: sourceAri
|
|
247
|
+
});
|
|
226
248
|
options = {
|
|
227
249
|
pageId: pageId,
|
|
228
250
|
key: key,
|
|
229
|
-
value:
|
|
251
|
+
value: syncBlockDataWithSourceDocumentAri,
|
|
230
252
|
cloudId: this.config.cloudId,
|
|
231
253
|
pageType: pageType
|
|
232
254
|
};
|
|
233
|
-
_context3.next =
|
|
255
|
+
_context3.next = 17;
|
|
234
256
|
return (0, _contentProperty3.updateContentProperty)(options);
|
|
235
|
-
case
|
|
257
|
+
case 17:
|
|
236
258
|
updatePayload = _context3.sent;
|
|
237
259
|
updateResult = (0, _utils.isBlogPageType)(pageType) ? updatePayload.data.confluence.updateValueBlogPostProperty.blogPostProperty : updatePayload.data.confluence.updateValuePageProperty.pageProperty;
|
|
238
260
|
if (!((updateResult === null || updateResult === void 0 ? void 0 : updateResult.key) === key)) {
|
|
239
|
-
_context3.next =
|
|
261
|
+
_context3.next = 23;
|
|
240
262
|
break;
|
|
241
263
|
}
|
|
242
264
|
return _context3.abrupt("return", {
|
|
243
265
|
resourceId: resourceId
|
|
244
266
|
});
|
|
245
|
-
case
|
|
267
|
+
case 23:
|
|
246
268
|
if (updateResult) {
|
|
247
|
-
_context3.next =
|
|
269
|
+
_context3.next = 27;
|
|
248
270
|
break;
|
|
249
271
|
}
|
|
250
272
|
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, data, pageType).then(function () {
|
|
@@ -256,24 +278,24 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
256
278
|
error: error
|
|
257
279
|
};
|
|
258
280
|
}));
|
|
259
|
-
case
|
|
281
|
+
case 27:
|
|
260
282
|
return _context3.abrupt("return", {
|
|
261
283
|
error: "Failed to update ".concat(pageType, " content property")
|
|
262
284
|
});
|
|
263
|
-
case 26:
|
|
264
|
-
_context3.next = 31;
|
|
265
|
-
break;
|
|
266
285
|
case 28:
|
|
267
|
-
_context3.
|
|
286
|
+
_context3.next = 33;
|
|
287
|
+
break;
|
|
288
|
+
case 30:
|
|
289
|
+
_context3.prev = 30;
|
|
268
290
|
_context3.t1 = _context3["catch"](9);
|
|
269
291
|
return _context3.abrupt("return", {
|
|
270
292
|
error: "Failed to write ".concat(pageType)
|
|
271
293
|
});
|
|
272
|
-
case
|
|
294
|
+
case 33:
|
|
273
295
|
case "end":
|
|
274
296
|
return _context3.stop();
|
|
275
297
|
}
|
|
276
|
-
}, _callee3, this, [[1, 5], [9,
|
|
298
|
+
}, _callee3, this, [[1, 5], [9, 30]]);
|
|
277
299
|
}));
|
|
278
300
|
function writeData(_x6) {
|
|
279
301
|
return _writeData.apply(this, arguments);
|
|
@@ -22,6 +22,8 @@ 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
|
+
// the source document ARI; that the source sync block is on.
|
|
26
|
+
|
|
25
27
|
/**
|
|
26
28
|
* Constructor for the SyncBlockProvider
|
|
27
29
|
*
|
|
@@ -216,20 +218,20 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
216
218
|
}, {
|
|
217
219
|
key: "retrieveSyncBlockSourceInfo",
|
|
218
220
|
value: function retrieveSyncBlockSourceInfo(node) {
|
|
221
|
+
// with content API, this is the concatenation of the page ARI and the block's localId.
|
|
222
|
+
// with block service, this is the ARI of the block.
|
|
223
|
+
// this can be cleaned up from the specific providers and placed here after platform_synced_blocks_block_service_provider
|
|
219
224
|
var resourceId = node.attrs.resourceId;
|
|
220
225
|
var pageARI;
|
|
221
226
|
var sourceLocalId;
|
|
222
227
|
if (resourceId && typeof resourceId === 'string') {
|
|
223
228
|
try {
|
|
224
|
-
|
|
229
|
+
var fetchData = this.fetchProvider.retrieveSourceInfoFetchData(resourceId, this.sourceId);
|
|
230
|
+
pageARI = fetchData.pageARI;
|
|
231
|
+
sourceLocalId = fetchData.sourceLocalId;
|
|
225
232
|
} catch (error) {
|
|
226
233
|
return Promise.reject(error);
|
|
227
234
|
}
|
|
228
|
-
try {
|
|
229
|
-
sourceLocalId = (0, _ari.getLocalIdFromAri)(resourceId);
|
|
230
|
-
} catch (error) {
|
|
231
|
-
// EDITOR-1921: log analytic here, safe to continue
|
|
232
|
-
}
|
|
233
235
|
}
|
|
234
236
|
return pageARI ? (0, _sourceInfo.fetchSourceInfo)(pageARI, sourceLocalId) : Promise.resolve(undefined);
|
|
235
237
|
}
|
|
@@ -249,6 +251,35 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
249
251
|
value: function getSyncedBlockRendererProviderOptions() {
|
|
250
252
|
return this.providerOptions;
|
|
251
253
|
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Retrieve the parent info for the sync block
|
|
257
|
+
*
|
|
258
|
+
* @param resourceId
|
|
259
|
+
* @param syncBlockInstance
|
|
260
|
+
*
|
|
261
|
+
* @returns The parent info for the sync block
|
|
262
|
+
*/
|
|
263
|
+
}, {
|
|
264
|
+
key: "retrieveSyncBlockParentInfo",
|
|
265
|
+
value: function retrieveSyncBlockParentInfo(syncBlockInstance) {
|
|
266
|
+
if (!syncBlockInstance || !syncBlockInstance.data) {
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
var _syncBlockInstance$da = syncBlockInstance.data,
|
|
270
|
+
sourceAri = _syncBlockInstance$da.sourceAri,
|
|
271
|
+
resourceId = _syncBlockInstance$da.resourceId,
|
|
272
|
+
contentProduct = _syncBlockInstance$da.product;
|
|
273
|
+
|
|
274
|
+
// Temp solution to get the pageId from resource since the sourceDocumentAri is not available for older sync blocks
|
|
275
|
+
var pageARI = sourceAri || resourceId;
|
|
276
|
+
var _getPageIdAndTypeFrom = (0, _ari.getPageIdAndTypeFromAri)(pageARI),
|
|
277
|
+
contentId = _getPageIdAndTypeFrom.id;
|
|
278
|
+
return {
|
|
279
|
+
contentId: contentId,
|
|
280
|
+
contentProduct: contentProduct || 'confluence-page'
|
|
281
|
+
};
|
|
282
|
+
}
|
|
252
283
|
}]);
|
|
253
284
|
}(_types2.SyncBlockDataProvider);
|
|
254
285
|
var useMemoizedSyncedBlockProvider = exports.useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
|
|
@@ -348,20 +348,61 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
348
348
|
return undefined;
|
|
349
349
|
}
|
|
350
350
|
var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
|
|
351
|
-
parentDataProviders = _this$dataProvider$ge.parentDataProviders
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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,
|
|
351
|
+
parentDataProviders = _this$dataProvider$ge.parentDataProviders,
|
|
352
|
+
providerCreator = _this$dataProvider$ge.providerCreator;
|
|
353
|
+
var providerFactory = this.providerFactories.get(resourceId);
|
|
354
|
+
if (!providerFactory) {
|
|
355
|
+
providerFactory = _providerFactory.ProviderFactory.create({
|
|
359
356
|
mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
|
|
360
357
|
profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
|
|
361
358
|
taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
|
|
362
|
-
})
|
|
359
|
+
});
|
|
360
|
+
this.providerFactories.set(resourceId, providerFactory);
|
|
361
|
+
}
|
|
362
|
+
if (providerCreator) {
|
|
363
|
+
this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
|
|
364
|
+
}
|
|
365
|
+
return providerFactory;
|
|
366
|
+
}
|
|
367
|
+
}, {
|
|
368
|
+
key: "retrieveDynamicProviders",
|
|
369
|
+
value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
|
|
370
|
+
if (!this.dataProvider) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
var hasMediaProvider = providerFactory.hasProvider('mediaProvider');
|
|
374
|
+
var hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
|
|
375
|
+
if (hasMediaProvider && hasEmojiProvider) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo(this.syncBlockCache.get(resourceId));
|
|
379
|
+
if (!parentInfo) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
var contentId = parentInfo.contentId,
|
|
383
|
+
contentProduct = parentInfo.contentProduct;
|
|
384
|
+
if (!hasMediaProvider) {
|
|
385
|
+
if (providerCreator.createMediaProvider && contentId && contentProduct) {
|
|
386
|
+
var mediaProvider = providerCreator.createMediaProvider({
|
|
387
|
+
contentProduct: contentProduct,
|
|
388
|
+
contentId: contentId
|
|
389
|
+
});
|
|
390
|
+
if (mediaProvider) {
|
|
391
|
+
providerFactory.setProvider('mediaProvider', mediaProvider);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (!hasEmojiProvider) {
|
|
396
|
+
if (providerCreator.createEmojiProvider && contentId && contentProduct) {
|
|
397
|
+
var emojiProvider = providerCreator.createEmojiProvider({
|
|
398
|
+
contentProduct: contentProduct,
|
|
399
|
+
contentId: contentId
|
|
400
|
+
});
|
|
401
|
+
if (emojiProvider) {
|
|
402
|
+
providerFactory.setProvider('emojiProvider', emojiProvider);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
363
405
|
}
|
|
364
|
-
return this.providerFactories.get(resourceId);
|
|
365
406
|
}
|
|
366
407
|
}, {
|
|
367
408
|
key: "destroy",
|
|
@@ -10,6 +10,7 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
10
10
|
var _utils = require("../utils/utils");
|
|
11
11
|
var _referenceSyncBlockStoreManager = require("./referenceSyncBlockStoreManager");
|
|
12
12
|
var _sourceSyncBlockStoreManager = require("./sourceSyncBlockStoreManager");
|
|
13
|
+
// eslint-disable-next-line no-restricted-imports
|
|
13
14
|
// A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
|
|
14
15
|
// Supports create, read, update, and delete operations for sync blocks.
|
|
15
16
|
// Designed to manage local in-memory state and synchronize with an external data provider.
|
package/dist/cjs/utils/ari.js
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
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.getLocalIdFromAri = exports.getConfluencePageAri = void 0;
|
|
7
7
|
/* eslint-disable require-unicode-regexp */
|
|
8
8
|
|
|
9
9
|
var getConfluencePageAri = exports.getConfluencePageAri = function getConfluencePageAri(pageId, cloudId) {
|
|
10
10
|
var pageType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'page';
|
|
11
11
|
return "ari:cloud:confluence:".concat(cloudId, ":").concat(pageType, "/").concat(pageId);
|
|
12
12
|
};
|
|
13
|
+
|
|
14
|
+
// For extracting from Page ARI and also the content property's version of resourceId
|
|
13
15
|
var getPageIdAndTypeFromAri = exports.getPageIdAndTypeFromAri = function getPageIdAndTypeFromAri(ari) {
|
|
14
16
|
var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
|
|
15
17
|
if (match !== null && match !== void 0 && match[2]) {
|
|
@@ -36,35 +38,4 @@ var getPageARIFromResourceId = exports.getPageARIFromResourceId = function getPa
|
|
|
36
38
|
};
|
|
37
39
|
var resourceIdFromSourceAndLocalId = exports.resourceIdFromSourceAndLocalId = function resourceIdFromSourceAndLocalId(sourceId, localId) {
|
|
38
40
|
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));
|
|
70
41
|
};
|
|
@@ -69,15 +69,15 @@ var getSourceInfo = /*#__PURE__*/function () {
|
|
|
69
69
|
};
|
|
70
70
|
}();
|
|
71
71
|
var fetchSourceInfo = exports.fetchSourceInfo = /*#__PURE__*/function () {
|
|
72
|
-
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(
|
|
72
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(pageAri, localId) {
|
|
73
73
|
var _response$data, _contentData$space, _getPageIdAndTypeFrom, pageType, response, contentData, title, url, _ref3, base;
|
|
74
74
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
75
75
|
while (1) switch (_context2.prev = _context2.next) {
|
|
76
76
|
case 0:
|
|
77
77
|
_context2.prev = 0;
|
|
78
|
-
_getPageIdAndTypeFrom = (0, _ari.getPageIdAndTypeFromAri)(
|
|
78
|
+
_getPageIdAndTypeFrom = (0, _ari.getPageIdAndTypeFromAri)(pageAri), pageType = _getPageIdAndTypeFrom.type;
|
|
79
79
|
_context2.next = 4;
|
|
80
|
-
return getSourceInfo(
|
|
80
|
+
return getSourceInfo(pageAri);
|
|
81
81
|
case 4:
|
|
82
82
|
response = _context2.sent;
|
|
83
83
|
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];
|
package/dist/es2019/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 const blockResourceIdFromSourceAndLocalId = (sourceId, localId) => {
|
|
9
|
+
const match = sourceId.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/.*/);
|
|
10
|
+
if (!(match !== null && match !== void 0 && match[1])) {
|
|
11
|
+
throw new Error(`Invalid source ARI: ${sourceId}`);
|
|
12
|
+
}
|
|
13
|
+
const cloudId = match[1];
|
|
14
|
+
return `ari:cloud:blocks:${cloudId}:synced-block/${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 const getLocalIdFromResourceId = ari => {
|
|
23
|
+
const 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: ${ari}`);
|
|
28
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { SyncBlockError } from '../../common/types';
|
|
3
|
-
import { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from '../../utils/ari';
|
|
4
3
|
import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../utils/blockService';
|
|
5
4
|
import { stringifyError } from '../../utils/errorHandling';
|
|
5
|
+
import { blockResourceIdFromSourceAndLocalId, getLocalIdFromResourceId } from './ari';
|
|
6
6
|
const mapBlockError = error => {
|
|
7
7
|
switch (error.status) {
|
|
8
8
|
case 403:
|
|
@@ -56,6 +56,18 @@ class BlockServiceADFFetchProvider {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
retrieveSourceInfoFetchData(resourceId, pageARI) {
|
|
60
|
+
let sourceLocalId;
|
|
61
|
+
try {
|
|
62
|
+
sourceLocalId = getLocalIdFromResourceId(resourceId);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// EDITOR-1921: log analytic here, safe to continue
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
pageARI,
|
|
68
|
+
sourceLocalId
|
|
69
|
+
};
|
|
70
|
+
}
|
|
59
71
|
}
|
|
60
72
|
|
|
61
73
|
/**
|
|
@@ -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, resourceIdFromSourceAndLocalId } from '../../utils/ari';
|
|
4
|
+
import { getConfluencePageAri, getPageARIFromResourceId, 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';
|
|
@@ -98,6 +98,19 @@ class ConfluenceADFFetchProvider {
|
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
retrieveSourceInfoFetchData(resourceId) {
|
|
102
|
+
const pageARI = getPageARIFromResourceId(resourceId);
|
|
103
|
+
let sourceLocalId;
|
|
104
|
+
try {
|
|
105
|
+
sourceLocalId = getLocalIdFromAri(resourceId);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
// EDITOR-1921: log analytic here, safe to continue
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
pageARI,
|
|
111
|
+
sourceLocalId
|
|
112
|
+
};
|
|
113
|
+
}
|
|
101
114
|
}
|
|
102
115
|
|
|
103
116
|
/**
|
|
@@ -153,10 +166,16 @@ class ConfluenceADFWriteProvider {
|
|
|
153
166
|
// Update existing content property
|
|
154
167
|
const localId = getLocalIdFromAri(resourceId);
|
|
155
168
|
const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
169
|
+
const sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
|
|
170
|
+
const syncBlockDataWithSourceDocumentAri = {
|
|
171
|
+
...data,
|
|
172
|
+
product: 'confluence-page',
|
|
173
|
+
sourceAri
|
|
174
|
+
};
|
|
156
175
|
const options = {
|
|
157
176
|
pageId,
|
|
158
177
|
key,
|
|
159
|
-
value:
|
|
178
|
+
value: syncBlockDataWithSourceDocumentAri,
|
|
160
179
|
cloudId: this.config.cloudId,
|
|
161
180
|
pageType
|
|
162
181
|
};
|