@atlaskit/editor-synced-block-provider 2.9.0 → 2.10.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 +28 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +3 -2
- 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 +15 -0
- package/dist/cjs/providers/syncBlockProvider.js +82 -14
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +26 -0
- package/dist/cjs/store-manager/syncBlockStoreManager.js +5 -0
- package/dist/cjs/utils/ari.js +3 -32
- package/dist/cjs/utils/sourceInfo.js +3 -3
- package/dist/es2019/hooks/useFetchSyncBlockData.js +3 -2
- 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 +14 -1
- package/dist/es2019/providers/syncBlockProvider.js +78 -12
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +25 -0
- package/dist/es2019/store-manager/syncBlockStoreManager.js +3 -0
- package/dist/es2019/utils/ari.js +2 -31
- package/dist/es2019/utils/sourceInfo.js +3 -3
- package/dist/esm/hooks/useFetchSyncBlockData.js +3 -2
- 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 +16 -1
- package/dist/esm/providers/syncBlockProvider.js +82 -14
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +26 -0
- package/dist/esm/store-manager/syncBlockStoreManager.js +5 -0
- package/dist/esm/utils/ari.js +2 -31
- package/dist/esm/utils/sourceInfo.js +3 -3
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +2 -0
- package/dist/types/index.d.ts +2 -1
- 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 +59 -3
- package/dist/types/providers/types.d.ts +20 -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 +0 -15
- package/dist/types/utils/sourceInfo.d.ts +1 -1
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +2 -1
- 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 +59 -3
- package/dist/types-ts4.5/providers/types.d.ts +20 -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 +0 -15
- package/dist/types-ts4.5/utils/sourceInfo.d.ts +1 -1
- package/package.json +3 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 2.10.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`a05464ea42678`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a05464ea42678) -
|
|
8
|
+
EDITOR-2791 bump adf-schema
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 2.10.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [`00d86f82d23fa`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/00d86f82d23fa) -
|
|
16
|
+
Move ARI checks to providers
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
|
|
22
|
+
## 2.9.1
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- [`e3aafa008fcf4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e3aafa008fcf4) -
|
|
27
|
+
EDITOR-2771 Pass parent Editor/Renderer data providers through SyncBlockDataProvider to the nested
|
|
28
|
+
renderer
|
|
29
|
+
- Updated dependencies
|
|
30
|
+
|
|
3
31
|
## 2.9.0
|
|
4
32
|
|
|
5
33
|
### 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
|
@@ -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
|
/**
|
|
@@ -134,6 +134,21 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
134
134
|
}
|
|
135
135
|
return fetchData;
|
|
136
136
|
}()
|
|
137
|
+
}, {
|
|
138
|
+
key: "retrieveSourceInfoFetchData",
|
|
139
|
+
value: function retrieveSourceInfoFetchData(resourceId) {
|
|
140
|
+
var pageARI = (0, _ari.getPageARIFromResourceId)(resourceId);
|
|
141
|
+
var sourceLocalId;
|
|
142
|
+
try {
|
|
143
|
+
sourceLocalId = (0, _ari.getLocalIdFromAri)(resourceId);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
// EDITOR-1921: log analytic here, safe to continue
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
pageARI: pageARI,
|
|
149
|
+
sourceLocalId: sourceLocalId
|
|
150
|
+
};
|
|
151
|
+
}
|
|
137
152
|
}]);
|
|
138
153
|
}();
|
|
139
154
|
/**
|
|
@@ -17,12 +17,21 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
17
17
|
var _react = require("react");
|
|
18
18
|
var _types = require("../common/types");
|
|
19
19
|
var _types2 = require("../providers/types");
|
|
20
|
-
var _ari = require("../utils/ari");
|
|
21
20
|
var _sourceInfo = require("../utils/sourceInfo");
|
|
22
21
|
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
22
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
24
23
|
var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
25
|
-
|
|
24
|
+
// the source document ARI; that the source sync block is on.
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Constructor for the SyncBlockProvider
|
|
28
|
+
*
|
|
29
|
+
* @param fetchProvider
|
|
30
|
+
* @param writeProvider
|
|
31
|
+
* @param sourceId
|
|
32
|
+
* @param nestedRendererDataProviders
|
|
33
|
+
*/
|
|
34
|
+
function SyncBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
|
|
26
35
|
var _this;
|
|
27
36
|
(0, _classCallCheck2.default)(this, SyncBlockProvider);
|
|
28
37
|
_this = _callSuper(this, SyncBlockProvider);
|
|
@@ -30,19 +39,44 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
30
39
|
_this.fetchProvider = fetchProvider;
|
|
31
40
|
_this.writeProvider = writeProvider;
|
|
32
41
|
_this.sourceId = sourceId;
|
|
42
|
+
_this.providerOptions = providerOptions;
|
|
33
43
|
return _this;
|
|
34
44
|
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Check if the node is supported by the provider
|
|
48
|
+
*
|
|
49
|
+
* @param node
|
|
50
|
+
*
|
|
51
|
+
* @returns True if the node is supported, false otherwise
|
|
52
|
+
*/
|
|
35
53
|
(0, _inherits2.default)(SyncBlockProvider, _SyncBlockDataProvide);
|
|
36
54
|
return (0, _createClass2.default)(SyncBlockProvider, [{
|
|
37
55
|
key: "isNodeSupported",
|
|
38
56
|
value: function isNodeSupported(node) {
|
|
39
|
-
return node.type === 'syncBlock';
|
|
57
|
+
return node.type === 'syncBlock' || node.type === 'bodiedSyncBlock';
|
|
40
58
|
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get the data key for the node
|
|
62
|
+
*
|
|
63
|
+
* @param node
|
|
64
|
+
*
|
|
65
|
+
* @returns The data key
|
|
66
|
+
*/
|
|
41
67
|
}, {
|
|
42
68
|
key: "nodeDataKey",
|
|
43
69
|
value: function nodeDataKey(node) {
|
|
44
70
|
return node.attrs.localId;
|
|
45
71
|
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Fetch the data from the fetch provider
|
|
75
|
+
*
|
|
76
|
+
* @param nodes
|
|
77
|
+
*
|
|
78
|
+
* @returns Array of {resourceId?: string, error?: string}.
|
|
79
|
+
*/
|
|
46
80
|
}, {
|
|
47
81
|
key: "fetchNodesData",
|
|
48
82
|
value: function fetchNodesData(nodes) {
|
|
@@ -70,6 +104,7 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
70
104
|
}
|
|
71
105
|
|
|
72
106
|
/**
|
|
107
|
+
* Write the data to the write provider
|
|
73
108
|
*
|
|
74
109
|
* @param nodes
|
|
75
110
|
* @param data
|
|
@@ -114,10 +149,18 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
114
149
|
return _writeNodesData.apply(this, arguments);
|
|
115
150
|
}
|
|
116
151
|
return writeNodesData;
|
|
117
|
-
}()
|
|
152
|
+
}()
|
|
153
|
+
/**
|
|
154
|
+
* Delete the data from the write provider
|
|
155
|
+
*
|
|
156
|
+
* @param resourceIds
|
|
157
|
+
*
|
|
158
|
+
* @returns Array of {resourceId?: string, error?: string}.
|
|
159
|
+
*/
|
|
160
|
+
)
|
|
118
161
|
}, {
|
|
119
162
|
key: "deleteNodesData",
|
|
120
|
-
value: function () {
|
|
163
|
+
value: (function () {
|
|
121
164
|
var _deleteNodesData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resourceIds) {
|
|
122
165
|
var _this4 = this;
|
|
123
166
|
var results;
|
|
@@ -152,28 +195,42 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
152
195
|
}
|
|
153
196
|
return deleteNodesData;
|
|
154
197
|
}()
|
|
198
|
+
/**
|
|
199
|
+
* Get the source id
|
|
200
|
+
*
|
|
201
|
+
* @returns The source id
|
|
202
|
+
*/
|
|
203
|
+
)
|
|
155
204
|
}, {
|
|
156
205
|
key: "getSourceId",
|
|
157
206
|
value: function getSourceId() {
|
|
158
207
|
return this.sourceId;
|
|
159
208
|
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Retrieve the source info from the source id
|
|
212
|
+
*
|
|
213
|
+
* @param node
|
|
214
|
+
*
|
|
215
|
+
* @returns The source info
|
|
216
|
+
*/
|
|
160
217
|
}, {
|
|
161
218
|
key: "retrieveSyncBlockSourceInfo",
|
|
162
219
|
value: function retrieveSyncBlockSourceInfo(node) {
|
|
220
|
+
// with content API, this is the concatenation of the page ARI and the block's localId.
|
|
221
|
+
// with block service, this is the ARI of the block.
|
|
222
|
+
// this can be cleaned up from the specific providers and placed here after platform_synced_blocks_block_service_provider
|
|
163
223
|
var resourceId = node.attrs.resourceId;
|
|
164
224
|
var pageARI;
|
|
165
225
|
var sourceLocalId;
|
|
166
226
|
if (resourceId && typeof resourceId === 'string') {
|
|
167
227
|
try {
|
|
168
|
-
|
|
228
|
+
var fetchData = this.fetchProvider.retrieveSourceInfoFetchData(resourceId, this.sourceId);
|
|
229
|
+
pageARI = fetchData.pageARI;
|
|
230
|
+
sourceLocalId = fetchData.sourceLocalId;
|
|
169
231
|
} catch (error) {
|
|
170
232
|
return Promise.reject(error);
|
|
171
233
|
}
|
|
172
|
-
try {
|
|
173
|
-
sourceLocalId = (0, _ari.getLocalIdFromAri)(resourceId);
|
|
174
|
-
} catch (error) {
|
|
175
|
-
// EDITOR-1921: log analytic here, safe to continue
|
|
176
|
-
}
|
|
177
234
|
}
|
|
178
235
|
return pageARI ? (0, _sourceInfo.fetchSourceInfo)(pageARI, sourceLocalId) : Promise.resolve(undefined);
|
|
179
236
|
}
|
|
@@ -182,10 +239,21 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
182
239
|
value: function generateResourceId(sourceId, localId) {
|
|
183
240
|
return this.writeProvider.generateResourceId(sourceId, localId);
|
|
184
241
|
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Get the synced block renderer provider options
|
|
245
|
+
*
|
|
246
|
+
* @returns The synced block renderer provider options
|
|
247
|
+
*/
|
|
248
|
+
}, {
|
|
249
|
+
key: "getSyncedBlockRendererProviderOptions",
|
|
250
|
+
value: function getSyncedBlockRendererProviderOptions() {
|
|
251
|
+
return this.providerOptions;
|
|
252
|
+
}
|
|
185
253
|
}]);
|
|
186
254
|
}(_types2.SyncBlockDataProvider);
|
|
187
|
-
var useMemoizedSyncedBlockProvider = exports.useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId) {
|
|
255
|
+
var useMemoizedSyncedBlockProvider = exports.useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions) {
|
|
188
256
|
return (0, _react.useMemo)(function () {
|
|
189
|
-
return new SyncBlockProvider(fetchProvider, writeProvider, sourceId);
|
|
190
|
-
}, [fetchProvider, writeProvider, sourceId]);
|
|
257
|
+
return new SyncBlockProvider(fetchProvider, writeProvider, sourceId, providerOptions);
|
|
258
|
+
}, [fetchProvider, writeProvider, sourceId, providerOptions]);
|
|
191
259
|
};
|
|
@@ -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
|
}();
|
|
@@ -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,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];
|
|
@@ -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
|
@@ -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 { getLocalIdFromAri, getPageARIFromResourceId, 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
|
/**
|