@atlaskit/editor-synced-block-provider 2.11.2 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/clients/block-service/blockService.js +130 -50
- package/dist/cjs/common/types.js +1 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/providers/block-service/blockServiceAPI.js +135 -59
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +21 -48
- package/dist/es2019/clients/block-service/blockService.js +57 -0
- package/dist/es2019/common/types.js +1 -0
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +54 -1
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +2 -25
- package/dist/esm/clients/block-service/blockService.js +130 -50
- package/dist/esm/common/types.js +1 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +135 -59
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +18 -45
- package/dist/types/clients/block-service/blockService.d.ts +52 -0
- package/dist/types/common/types.d.ts +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +2 -1
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +1 -7
- package/dist/types-ts4.5/clients/block-service/blockService.d.ts +52 -0
- package/dist/types-ts4.5/common/types.d.ts +2 -1
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +2 -1
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +1 -7
- package/package.json +2 -2
|
@@ -12,10 +12,8 @@ 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 _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
15
|
-
var _utils = require("@atlaskit/editor-common/utils");
|
|
16
|
-
var _rebaseTransaction2 = require("../common/rebase-transaction");
|
|
17
15
|
var _errorHandling = require("../utils/errorHandling");
|
|
18
|
-
var
|
|
16
|
+
var _utils = require("../utils/utils");
|
|
19
17
|
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
|
|
20
18
|
// A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
|
|
21
19
|
// Designed to manage local in-memory state and synchronize with an external data provider.
|
|
@@ -59,7 +57,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
59
57
|
if (!localId || !resourceId) {
|
|
60
58
|
throw new Error('Local ID or resource ID is not set');
|
|
61
59
|
}
|
|
62
|
-
var syncBlockData = (0,
|
|
60
|
+
var syncBlockData = (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
|
|
63
61
|
this.syncBlockCache.set(resourceId, syncBlockData);
|
|
64
62
|
return true;
|
|
65
63
|
} catch (error) {
|
|
@@ -155,11 +153,6 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
155
153
|
}
|
|
156
154
|
return flush;
|
|
157
155
|
}())
|
|
158
|
-
}, {
|
|
159
|
-
key: "setEditorView",
|
|
160
|
-
value: function setEditorView(editorView) {
|
|
161
|
-
this.editorView = editorView;
|
|
162
|
-
}
|
|
163
156
|
}, {
|
|
164
157
|
key: "registerPendingCreation",
|
|
165
158
|
value: function registerPendingCreation(resourceId) {
|
|
@@ -247,7 +240,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
247
240
|
}
|
|
248
241
|
var resourceId = attrs.resourceId,
|
|
249
242
|
blockInstanceId = attrs.localId;
|
|
250
|
-
this.dataProvider.writeNodesData([(0,
|
|
243
|
+
this.dataProvider.writeNodesData([(0, _utils.createBodiedSyncBlockNode)(blockInstanceId, resourceId)], [{
|
|
251
244
|
content: [],
|
|
252
245
|
blockInstanceId: blockInstanceId,
|
|
253
246
|
resourceId: resourceId
|
|
@@ -285,47 +278,40 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
285
278
|
}, {
|
|
286
279
|
key: "deleteSyncBlocksWithConfirmation",
|
|
287
280
|
value: function () {
|
|
288
|
-
var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(
|
|
281
|
+
var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockIds, deleteCallback) {
|
|
289
282
|
var _this5 = this;
|
|
290
|
-
var confirmed,
|
|
283
|
+
var confirmed, results, callback, _this$fireAnalyticsEv4;
|
|
291
284
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
292
285
|
while (1) switch (_context2.prev = _context2.next) {
|
|
293
286
|
case 0:
|
|
294
287
|
if (!this.confirmationCallback) {
|
|
295
|
-
_context2.next =
|
|
288
|
+
_context2.next = 22;
|
|
296
289
|
break;
|
|
297
290
|
}
|
|
298
|
-
|
|
299
|
-
_context2.next = 4;
|
|
291
|
+
_context2.next = 3;
|
|
300
292
|
return this.confirmationCallback(syncBlockIds.length);
|
|
301
|
-
case
|
|
293
|
+
case 3:
|
|
302
294
|
confirmed = _context2.sent;
|
|
303
295
|
if (!confirmed) {
|
|
304
|
-
_context2.next =
|
|
296
|
+
_context2.next = 22;
|
|
305
297
|
break;
|
|
306
298
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
// bodiedSyncBlock deletion is expected to be permanent (cannot be undo)
|
|
310
|
-
// For a normal delete (not triggered by undo), remove it from history so that it cannot be undone
|
|
311
|
-
trToDispatch.setMeta('addToHistory', false);
|
|
312
|
-
}
|
|
313
|
-
(_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(trToDispatch);
|
|
314
|
-
_context2.prev = 9;
|
|
299
|
+
deleteCallback();
|
|
300
|
+
_context2.prev = 6;
|
|
315
301
|
if (this.dataProvider) {
|
|
316
|
-
_context2.next =
|
|
302
|
+
_context2.next = 9;
|
|
317
303
|
break;
|
|
318
304
|
}
|
|
319
305
|
throw new Error('Data provider not set');
|
|
320
|
-
case
|
|
306
|
+
case 9:
|
|
321
307
|
syncBlockIds.forEach(function (Ids) {
|
|
322
308
|
_this5.setPendingDeletion(Ids, true);
|
|
323
309
|
});
|
|
324
|
-
_context2.next =
|
|
310
|
+
_context2.next = 12;
|
|
325
311
|
return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
|
|
326
312
|
return attrs.resourceId;
|
|
327
313
|
}));
|
|
328
|
-
case
|
|
314
|
+
case 12:
|
|
329
315
|
results = _context2.sent;
|
|
330
316
|
if (results.every(function (result) {
|
|
331
317
|
return result.success;
|
|
@@ -345,11 +331,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
345
331
|
});
|
|
346
332
|
}
|
|
347
333
|
syncBlockIds.forEach(callback);
|
|
348
|
-
_context2.next =
|
|
334
|
+
_context2.next = 22;
|
|
349
335
|
break;
|
|
350
|
-
case
|
|
351
|
-
_context2.prev =
|
|
352
|
-
_context2.t0 = _context2["catch"](
|
|
336
|
+
case 17:
|
|
337
|
+
_context2.prev = 17;
|
|
338
|
+
_context2.t0 = _context2["catch"](6);
|
|
353
339
|
syncBlockIds.forEach(function (Ids) {
|
|
354
340
|
_this5.setPendingDeletion(Ids, false);
|
|
355
341
|
});
|
|
@@ -357,38 +343,25 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
357
343
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
358
344
|
});
|
|
359
345
|
(_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.deleteErrorPayload)(_context2.t0.message));
|
|
360
|
-
case
|
|
361
|
-
this.confirmationTransaction = undefined;
|
|
362
|
-
case 26:
|
|
346
|
+
case 22:
|
|
363
347
|
case "end":
|
|
364
348
|
return _context2.stop();
|
|
365
349
|
}
|
|
366
|
-
}, _callee2, this, [[
|
|
350
|
+
}, _callee2, this, [[6, 17]]);
|
|
367
351
|
}));
|
|
368
352
|
function deleteSyncBlocksWithConfirmation(_x, _x2) {
|
|
369
353
|
return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
|
|
370
354
|
}
|
|
371
355
|
return deleteSyncBlocksWithConfirmation;
|
|
372
356
|
}()
|
|
373
|
-
}, {
|
|
374
|
-
key: "rebaseTransaction",
|
|
375
|
-
value: function rebaseTransaction(incomingTr, state) {
|
|
376
|
-
if (!this.confirmationTransaction) {
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
this.confirmationTransaction = (0, _rebaseTransaction2.rebaseTransaction)(this.confirmationTransaction, incomingTr, state);
|
|
380
|
-
}
|
|
381
357
|
}, {
|
|
382
358
|
key: "destroy",
|
|
383
359
|
value: function destroy() {
|
|
384
360
|
this.syncBlockCache.clear();
|
|
385
361
|
this.confirmationCallback = undefined;
|
|
386
|
-
this.confirmationTransaction = undefined;
|
|
387
362
|
this.pendingResourceId = undefined;
|
|
388
363
|
this.creationCallback = undefined;
|
|
389
364
|
this.dataProvider = undefined;
|
|
390
|
-
this.editorView = undefined;
|
|
391
|
-
this.fireAnalyticsEvent = undefined;
|
|
392
365
|
}
|
|
393
366
|
}]);
|
|
394
367
|
}();
|
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
export const isBlockContentResponse = response => {
|
|
2
|
+
const content = response.content;
|
|
3
|
+
return typeof content === 'string';
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves all synced blocks referenced in a document.
|
|
8
|
+
*
|
|
9
|
+
* Calls the Block Service API endpoint: `/v1/block/document/reference/{documentAri}`
|
|
10
|
+
*
|
|
11
|
+
* @param documentAri - The ARI of the document to fetch synced blocks for
|
|
12
|
+
* @returns A promise containing arrays of successfully fetched blocks and any errors encountered
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const { blocks, errors } = await getReferenceSyncedBlocks(
|
|
17
|
+
* 'ari:cloud:confluence:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx:page/88888888'
|
|
18
|
+
* );
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Example response:
|
|
22
|
+
* ```json
|
|
23
|
+
* {
|
|
24
|
+
* "blocks": [
|
|
25
|
+
* {
|
|
26
|
+
* "blockAri": "ari:cloud:blocks:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx:synced-block/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
|
|
27
|
+
* "version": 1,
|
|
28
|
+
* "sourceDocumentAri": "ari:cloud:confluence:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx:page/88888888",
|
|
29
|
+
* "blockInstanceId": "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
|
|
30
|
+
* "content": "string",
|
|
31
|
+
* "status": "active",
|
|
32
|
+
* "createdAt": "2025-10-08T10:30:00.000Z",
|
|
33
|
+
* "createdBy": "557058:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
|
|
34
|
+
* "updatedAt": "2025-10-08T10:30:00.000Z"
|
|
35
|
+
* }
|
|
36
|
+
* ],
|
|
37
|
+
* "errors": [
|
|
38
|
+
* {
|
|
39
|
+
* "blockAri": "ari:cloud:blocks:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx:synced-block/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
|
|
40
|
+
* "code": "error",
|
|
41
|
+
* "reason": "some error reason"
|
|
42
|
+
* }
|
|
43
|
+
* ]
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
* Check https://block-service.dev.atl-paas.net/ for latest API documentation.
|
|
47
|
+
*/
|
|
48
|
+
export const getReferenceSyncedBlocks = async documentAri => {
|
|
49
|
+
const response = await fetch(`${BLOCK_SERVICE_API_URL}/block/document/reference/${encodeURIComponent(documentAri)}`, {
|
|
50
|
+
method: 'GET',
|
|
51
|
+
headers: COMMON_HEADERS
|
|
52
|
+
});
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
throw new BlockError(response.status);
|
|
55
|
+
}
|
|
56
|
+
return await response.json();
|
|
57
|
+
};
|
|
1
58
|
const COMMON_HEADERS = {
|
|
2
59
|
'Content-Type': 'application/json',
|
|
3
60
|
Accept: 'application/json'
|
|
@@ -2,5 +2,6 @@ export let SyncBlockError = /*#__PURE__*/function (SyncBlockError) {
|
|
|
2
2
|
SyncBlockError["Errored"] = "errored";
|
|
3
3
|
SyncBlockError["NotFound"] = "not_found";
|
|
4
4
|
SyncBlockError["Forbidden"] = "forbidden";
|
|
5
|
+
SyncBlockError["InvalidContent"] = "invalid_content"; // content is not a valid JSON
|
|
5
6
|
return SyncBlockError;
|
|
6
7
|
}({});
|
package/dist/es2019/index.js
CHANGED
|
@@ -23,4 +23,5 @@ export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
|
23
23
|
|
|
24
24
|
// utils
|
|
25
25
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
26
|
-
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes } from './utils/utils';
|
|
26
|
+
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes } from './utils/utils';
|
|
27
|
+
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { blockResourceIdFromSourceAndLocalId, getLocalIdFromBlockResourceId } from '../../clients/block-service/ari';
|
|
3
|
-
import { BlockError, createSyncedBlock, deleteSyncedBlock, getSyncedBlockContent, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
3
|
+
import { BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getSyncedBlockContent, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
4
4
|
import { SyncBlockError } from '../../common/types';
|
|
5
5
|
import { stringifyError } from '../../utils/errorHandling';
|
|
6
6
|
const mapBlockError = error => {
|
|
@@ -13,6 +13,59 @@ const mapBlockError = error => {
|
|
|
13
13
|
return SyncBlockError.Errored;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
// convert BlockContentResponse to SyncBlockData
|
|
17
|
+
// throws exception if JSON parsing fails
|
|
18
|
+
// what's missing from BlockContentResponse to SyncBlockData:
|
|
19
|
+
// - updatedAt
|
|
20
|
+
// - sourceURL
|
|
21
|
+
// - sourceTitle
|
|
22
|
+
// - isSynced
|
|
23
|
+
const convertToSyncBlockData = data => {
|
|
24
|
+
return {
|
|
25
|
+
blockInstanceId: data.blockInstanceId,
|
|
26
|
+
content: JSON.parse(data.content),
|
|
27
|
+
createdAt: new Date(data.createdAt).toISOString(),
|
|
28
|
+
createdBy: data.createdBy,
|
|
29
|
+
product: data.product,
|
|
30
|
+
resourceId: data.blockAri,
|
|
31
|
+
sourceAri: data.sourceAri
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export const fetchReferences = async documentAri => {
|
|
35
|
+
let response;
|
|
36
|
+
try {
|
|
37
|
+
response = await getReferenceSyncedBlocks(documentAri);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error instanceof BlockError) {
|
|
40
|
+
return mapBlockError(error);
|
|
41
|
+
}
|
|
42
|
+
return SyncBlockError.Errored;
|
|
43
|
+
}
|
|
44
|
+
const {
|
|
45
|
+
blocks,
|
|
46
|
+
errors
|
|
47
|
+
} = response || {};
|
|
48
|
+
const blocksInstances = (blocks || []).map(blockContentResponse => {
|
|
49
|
+
try {
|
|
50
|
+
return {
|
|
51
|
+
data: convertToSyncBlockData(blockContentResponse),
|
|
52
|
+
resourceId: blockContentResponse.blockAri
|
|
53
|
+
};
|
|
54
|
+
} catch {
|
|
55
|
+
// JSON parsing error, return InvalidContent error
|
|
56
|
+
return {
|
|
57
|
+
error: SyncBlockError.InvalidContent,
|
|
58
|
+
resourceId: blockContentResponse.blockAri
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const errorInstances = (errors || []).map(errorBlock => ({
|
|
63
|
+
error: SyncBlockError.Errored,
|
|
64
|
+
resourceId: errorBlock.blockAri
|
|
65
|
+
}));
|
|
66
|
+
return [...blocksInstances, ...errorInstances];
|
|
67
|
+
};
|
|
68
|
+
|
|
16
69
|
/**
|
|
17
70
|
* ADFFetchProvider implementation that fetches synced block data from Block Service API
|
|
18
71
|
*/
|
|
@@ -2,8 +2,6 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
|
|
3
3
|
import uuid from 'uuid';
|
|
4
4
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
5
|
-
import { pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
|
|
6
|
-
import { rebaseTransaction } from '../common/rebase-transaction';
|
|
7
5
|
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload } from '../utils/errorHandling';
|
|
8
6
|
import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode } from '../utils/utils';
|
|
9
7
|
// A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
|
|
@@ -103,9 +101,6 @@ export class SourceSyncBlockStoreManager {
|
|
|
103
101
|
return false;
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
|
-
setEditorView(editorView) {
|
|
107
|
-
this.editorView = editorView;
|
|
108
|
-
}
|
|
109
104
|
registerPendingCreation(resourceId) {
|
|
110
105
|
this.pendingResourceId = resourceId;
|
|
111
106
|
}
|
|
@@ -212,19 +207,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
212
207
|
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, createErrorPayload(error.message));
|
|
213
208
|
}
|
|
214
209
|
}
|
|
215
|
-
async deleteSyncBlocksWithConfirmation(
|
|
210
|
+
async deleteSyncBlocksWithConfirmation(syncBlockIds, deleteCallback) {
|
|
216
211
|
if (this.confirmationCallback) {
|
|
217
|
-
this.confirmationTransaction = tr;
|
|
218
212
|
const confirmed = await this.confirmationCallback(syncBlockIds.length);
|
|
219
213
|
if (confirmed) {
|
|
220
|
-
|
|
221
|
-
const trToDispatch = this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true);
|
|
222
|
-
if (!trToDispatch.getMeta(pmHistoryPluginKey)) {
|
|
223
|
-
// bodiedSyncBlock deletion is expected to be permanent (cannot be undo)
|
|
224
|
-
// For a normal delete (not triggered by undo), remove it from history so that it cannot be undone
|
|
225
|
-
trToDispatch.setMeta('addToHistory', false);
|
|
226
|
-
}
|
|
227
|
-
(_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.dispatch(trToDispatch);
|
|
214
|
+
deleteCallback();
|
|
228
215
|
try {
|
|
229
216
|
if (!this.dataProvider) {
|
|
230
217
|
throw new Error('Data provider not set');
|
|
@@ -257,23 +244,13 @@ export class SourceSyncBlockStoreManager {
|
|
|
257
244
|
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, deleteErrorPayload(error.message));
|
|
258
245
|
}
|
|
259
246
|
}
|
|
260
|
-
this.confirmationTransaction = undefined;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
rebaseTransaction(incomingTr, state) {
|
|
264
|
-
if (!this.confirmationTransaction) {
|
|
265
|
-
return;
|
|
266
247
|
}
|
|
267
|
-
this.confirmationTransaction = rebaseTransaction(this.confirmationTransaction, incomingTr, state);
|
|
268
248
|
}
|
|
269
249
|
destroy() {
|
|
270
250
|
this.syncBlockCache.clear();
|
|
271
251
|
this.confirmationCallback = undefined;
|
|
272
|
-
this.confirmationTransaction = undefined;
|
|
273
252
|
this.pendingResourceId = undefined;
|
|
274
253
|
this.creationCallback = undefined;
|
|
275
254
|
this.dataProvider = undefined;
|
|
276
|
-
this.editorView = undefined;
|
|
277
|
-
this.fireAnalyticsEvent = undefined;
|
|
278
255
|
}
|
|
279
256
|
}
|
|
@@ -1,13 +1,93 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
1
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
3
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
4
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
5
|
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
6
|
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
|
|
8
|
-
import
|
|
7
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
9
8
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
10
9
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
10
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
11
|
+
export var isBlockContentResponse = function isBlockContentResponse(response) {
|
|
12
|
+
var content = response.content;
|
|
13
|
+
return typeof content === 'string';
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves all synced blocks referenced in a document.
|
|
18
|
+
*
|
|
19
|
+
* Calls the Block Service API endpoint: `/v1/block/document/reference/{documentAri}`
|
|
20
|
+
*
|
|
21
|
+
* @param documentAri - The ARI of the document to fetch synced blocks for
|
|
22
|
+
* @returns A promise containing arrays of successfully fetched blocks and any errors encountered
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const { blocks, errors } = await getReferenceSyncedBlocks(
|
|
27
|
+
* 'ari:cloud:confluence:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx:page/88888888'
|
|
28
|
+
* );
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* Example response:
|
|
32
|
+
* ```json
|
|
33
|
+
* {
|
|
34
|
+
* "blocks": [
|
|
35
|
+
* {
|
|
36
|
+
* "blockAri": "ari:cloud:blocks:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx:synced-block/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
|
|
37
|
+
* "version": 1,
|
|
38
|
+
* "sourceDocumentAri": "ari:cloud:confluence:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx:page/88888888",
|
|
39
|
+
* "blockInstanceId": "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
|
|
40
|
+
* "content": "string",
|
|
41
|
+
* "status": "active",
|
|
42
|
+
* "createdAt": "2025-10-08T10:30:00.000Z",
|
|
43
|
+
* "createdBy": "557058:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
|
|
44
|
+
* "updatedAt": "2025-10-08T10:30:00.000Z"
|
|
45
|
+
* }
|
|
46
|
+
* ],
|
|
47
|
+
* "errors": [
|
|
48
|
+
* {
|
|
49
|
+
* "blockAri": "ari:cloud:blocks:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx:synced-block/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
|
|
50
|
+
* "code": "error",
|
|
51
|
+
* "reason": "some error reason"
|
|
52
|
+
* }
|
|
53
|
+
* ]
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
* Check https://block-service.dev.atl-paas.net/ for latest API documentation.
|
|
57
|
+
*/
|
|
58
|
+
export var getReferenceSyncedBlocks = /*#__PURE__*/function () {
|
|
59
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(documentAri) {
|
|
60
|
+
var response;
|
|
61
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
62
|
+
while (1) switch (_context.prev = _context.next) {
|
|
63
|
+
case 0:
|
|
64
|
+
_context.next = 2;
|
|
65
|
+
return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/document/reference/").concat(encodeURIComponent(documentAri)), {
|
|
66
|
+
method: 'GET',
|
|
67
|
+
headers: COMMON_HEADERS
|
|
68
|
+
});
|
|
69
|
+
case 2:
|
|
70
|
+
response = _context.sent;
|
|
71
|
+
if (response.ok) {
|
|
72
|
+
_context.next = 5;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
throw new BlockError(response.status);
|
|
76
|
+
case 5:
|
|
77
|
+
_context.next = 7;
|
|
78
|
+
return response.json();
|
|
79
|
+
case 7:
|
|
80
|
+
return _context.abrupt("return", _context.sent);
|
|
81
|
+
case 8:
|
|
82
|
+
case "end":
|
|
83
|
+
return _context.stop();
|
|
84
|
+
}
|
|
85
|
+
}, _callee);
|
|
86
|
+
}));
|
|
87
|
+
return function getReferenceSyncedBlocks(_x) {
|
|
88
|
+
return _ref.apply(this, arguments);
|
|
89
|
+
};
|
|
90
|
+
}();
|
|
11
91
|
var COMMON_HEADERS = {
|
|
12
92
|
'Content-Type': 'application/json',
|
|
13
93
|
Accept: 'application/json'
|
|
@@ -25,76 +105,76 @@ export var BlockError = /*#__PURE__*/function (_Error) {
|
|
|
25
105
|
return _createClass(BlockError);
|
|
26
106
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
27
107
|
export var getSyncedBlockContent = /*#__PURE__*/function () {
|
|
28
|
-
var
|
|
108
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref2) {
|
|
29
109
|
var blockAri, response;
|
|
30
|
-
return _regeneratorRuntime.wrap(function
|
|
31
|
-
while (1) switch (
|
|
110
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
111
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
32
112
|
case 0:
|
|
33
|
-
blockAri =
|
|
34
|
-
|
|
113
|
+
blockAri = _ref2.blockAri;
|
|
114
|
+
_context2.next = 3;
|
|
35
115
|
return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(encodeURIComponent(blockAri)), {
|
|
36
116
|
method: 'GET',
|
|
37
117
|
headers: COMMON_HEADERS
|
|
38
118
|
});
|
|
39
119
|
case 3:
|
|
40
|
-
response =
|
|
120
|
+
response = _context2.sent;
|
|
41
121
|
if (response.ok) {
|
|
42
|
-
|
|
122
|
+
_context2.next = 6;
|
|
43
123
|
break;
|
|
44
124
|
}
|
|
45
125
|
throw new BlockError(response.status);
|
|
46
126
|
case 6:
|
|
47
|
-
|
|
127
|
+
_context2.next = 8;
|
|
48
128
|
return response.json();
|
|
49
129
|
case 8:
|
|
50
|
-
return
|
|
130
|
+
return _context2.abrupt("return", _context2.sent);
|
|
51
131
|
case 9:
|
|
52
132
|
case "end":
|
|
53
|
-
return
|
|
133
|
+
return _context2.stop();
|
|
54
134
|
}
|
|
55
|
-
},
|
|
135
|
+
}, _callee2);
|
|
56
136
|
}));
|
|
57
|
-
return function getSyncedBlockContent(
|
|
58
|
-
return
|
|
137
|
+
return function getSyncedBlockContent(_x2) {
|
|
138
|
+
return _ref3.apply(this, arguments);
|
|
59
139
|
};
|
|
60
140
|
}();
|
|
61
141
|
export var deleteSyncedBlock = /*#__PURE__*/function () {
|
|
62
|
-
var
|
|
142
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref4) {
|
|
63
143
|
var blockAri, response;
|
|
64
|
-
return _regeneratorRuntime.wrap(function
|
|
65
|
-
while (1) switch (
|
|
144
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
145
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
66
146
|
case 0:
|
|
67
|
-
blockAri =
|
|
68
|
-
|
|
147
|
+
blockAri = _ref4.blockAri;
|
|
148
|
+
_context3.next = 3;
|
|
69
149
|
return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(encodeURIComponent(blockAri)), {
|
|
70
150
|
method: 'DELETE',
|
|
71
151
|
headers: COMMON_HEADERS
|
|
72
152
|
});
|
|
73
153
|
case 3:
|
|
74
|
-
response =
|
|
154
|
+
response = _context3.sent;
|
|
75
155
|
if (response.ok) {
|
|
76
|
-
|
|
156
|
+
_context3.next = 6;
|
|
77
157
|
break;
|
|
78
158
|
}
|
|
79
159
|
throw new BlockError(response.status);
|
|
80
160
|
case 6:
|
|
81
161
|
case "end":
|
|
82
|
-
return
|
|
162
|
+
return _context3.stop();
|
|
83
163
|
}
|
|
84
|
-
},
|
|
164
|
+
}, _callee3);
|
|
85
165
|
}));
|
|
86
|
-
return function deleteSyncedBlock(
|
|
87
|
-
return
|
|
166
|
+
return function deleteSyncedBlock(_x3) {
|
|
167
|
+
return _ref5.apply(this, arguments);
|
|
88
168
|
};
|
|
89
169
|
}();
|
|
90
170
|
export var updateSyncedBlock = /*#__PURE__*/function () {
|
|
91
|
-
var
|
|
171
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref6) {
|
|
92
172
|
var blockAri, content, response;
|
|
93
|
-
return _regeneratorRuntime.wrap(function
|
|
94
|
-
while (1) switch (
|
|
173
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
174
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
95
175
|
case 0:
|
|
96
|
-
blockAri =
|
|
97
|
-
|
|
176
|
+
blockAri = _ref6.blockAri, content = _ref6.content;
|
|
177
|
+
_context4.next = 3;
|
|
98
178
|
return fetch("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(encodeURIComponent(blockAri)), {
|
|
99
179
|
method: 'PUT',
|
|
100
180
|
headers: COMMON_HEADERS,
|
|
@@ -103,30 +183,30 @@ export var updateSyncedBlock = /*#__PURE__*/function () {
|
|
|
103
183
|
})
|
|
104
184
|
});
|
|
105
185
|
case 3:
|
|
106
|
-
response =
|
|
186
|
+
response = _context4.sent;
|
|
107
187
|
if (response.ok) {
|
|
108
|
-
|
|
188
|
+
_context4.next = 6;
|
|
109
189
|
break;
|
|
110
190
|
}
|
|
111
191
|
throw new BlockError(response.status);
|
|
112
192
|
case 6:
|
|
113
193
|
case "end":
|
|
114
|
-
return
|
|
194
|
+
return _context4.stop();
|
|
115
195
|
}
|
|
116
|
-
},
|
|
196
|
+
}, _callee4);
|
|
117
197
|
}));
|
|
118
|
-
return function updateSyncedBlock(
|
|
119
|
-
return
|
|
198
|
+
return function updateSyncedBlock(_x4) {
|
|
199
|
+
return _ref7.apply(this, arguments);
|
|
120
200
|
};
|
|
121
201
|
}();
|
|
122
202
|
export var createSyncedBlock = /*#__PURE__*/function () {
|
|
123
|
-
var
|
|
203
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref8) {
|
|
124
204
|
var blockAri, blockInstanceId, sourceAri, product, content, response;
|
|
125
|
-
return _regeneratorRuntime.wrap(function
|
|
126
|
-
while (1) switch (
|
|
205
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
206
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
127
207
|
case 0:
|
|
128
|
-
blockAri =
|
|
129
|
-
|
|
208
|
+
blockAri = _ref8.blockAri, blockInstanceId = _ref8.blockInstanceId, sourceAri = _ref8.sourceAri, product = _ref8.product, content = _ref8.content;
|
|
209
|
+
_context5.next = 3;
|
|
130
210
|
return fetch("".concat(BLOCK_SERVICE_API_URL, "/block"), {
|
|
131
211
|
method: 'POST',
|
|
132
212
|
headers: COMMON_HEADERS,
|
|
@@ -139,24 +219,24 @@ export var createSyncedBlock = /*#__PURE__*/function () {
|
|
|
139
219
|
})
|
|
140
220
|
});
|
|
141
221
|
case 3:
|
|
142
|
-
response =
|
|
222
|
+
response = _context5.sent;
|
|
143
223
|
if (response.ok) {
|
|
144
|
-
|
|
224
|
+
_context5.next = 6;
|
|
145
225
|
break;
|
|
146
226
|
}
|
|
147
227
|
throw new BlockError(response.status);
|
|
148
228
|
case 6:
|
|
149
|
-
|
|
229
|
+
_context5.next = 8;
|
|
150
230
|
return response.json();
|
|
151
231
|
case 8:
|
|
152
|
-
return
|
|
232
|
+
return _context5.abrupt("return", _context5.sent);
|
|
153
233
|
case 9:
|
|
154
234
|
case "end":
|
|
155
|
-
return
|
|
235
|
+
return _context5.stop();
|
|
156
236
|
}
|
|
157
|
-
},
|
|
237
|
+
}, _callee5);
|
|
158
238
|
}));
|
|
159
|
-
return function createSyncedBlock(
|
|
160
|
-
return
|
|
239
|
+
return function createSyncedBlock(_x5) {
|
|
240
|
+
return _ref9.apply(this, arguments);
|
|
161
241
|
};
|
|
162
242
|
}();
|
package/dist/esm/common/types.js
CHANGED
|
@@ -2,5 +2,6 @@ export var SyncBlockError = /*#__PURE__*/function (SyncBlockError) {
|
|
|
2
2
|
SyncBlockError["Errored"] = "errored";
|
|
3
3
|
SyncBlockError["NotFound"] = "not_found";
|
|
4
4
|
SyncBlockError["Forbidden"] = "forbidden";
|
|
5
|
+
SyncBlockError["InvalidContent"] = "invalid_content"; // content is not a valid JSON
|
|
5
6
|
return SyncBlockError;
|
|
6
7
|
}({});
|
package/dist/esm/index.js
CHANGED
|
@@ -23,4 +23,5 @@ export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
|
23
23
|
|
|
24
24
|
// utils
|
|
25
25
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
26
|
-
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes } from './utils/utils';
|
|
26
|
+
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes } from './utils/utils';
|
|
27
|
+
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|