@atlaskit/editor-synced-block-provider 2.2.0 → 2.2.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 +15 -0
- package/dist/cjs/common/types.js +7 -24
- package/dist/cjs/hooks/useFetchSyncBlockData.js +49 -0
- package/dist/cjs/hooks/useHandleContentChanges.js +13 -0
- package/dist/cjs/index.js +11 -9
- package/dist/cjs/providers/{confluenceContentAPI.js → confluence/confluenceContentAPI.js} +19 -16
- package/dist/cjs/providers/{inMemory.js → in-memory/inMemory.js} +4 -1
- package/dist/cjs/{common → providers}/syncBlockProvider.js +1 -1
- package/dist/cjs/providers/types.js +23 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +123 -0
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +191 -0
- package/dist/cjs/store-manager/syncBlockStoreManager.js +111 -0
- package/dist/cjs/utils/utils.js +1 -17
- package/dist/es2019/common/types.js +6 -8
- package/dist/es2019/hooks/useFetchSyncBlockData.js +38 -0
- package/dist/es2019/hooks/useHandleContentChanges.js +7 -0
- package/dist/es2019/index.js +8 -6
- package/dist/es2019/providers/{confluenceContentAPI.js → confluence/confluenceContentAPI.js} +19 -16
- package/dist/es2019/providers/{inMemory.js → in-memory/inMemory.js} +4 -1
- package/dist/es2019/{common → providers}/syncBlockProvider.js +1 -1
- package/dist/es2019/providers/types.js +2 -0
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +83 -0
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +115 -0
- package/dist/es2019/store-manager/syncBlockStoreManager.js +79 -0
- package/dist/es2019/utils/utils.js +0 -13
- package/dist/esm/common/types.js +6 -22
- package/dist/esm/hooks/useFetchSyncBlockData.js +42 -0
- package/dist/esm/hooks/useHandleContentChanges.js +7 -0
- package/dist/esm/index.js +8 -6
- package/dist/esm/providers/{confluenceContentAPI.js → confluence/confluenceContentAPI.js} +19 -16
- package/dist/esm/providers/{inMemory.js → in-memory/inMemory.js} +4 -1
- package/dist/esm/{common → providers}/syncBlockProvider.js +1 -1
- package/dist/esm/providers/types.js +16 -0
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +116 -0
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +184 -0
- package/dist/esm/store-manager/syncBlockStoreManager.js +105 -0
- package/dist/esm/utils/utils.js +0 -16
- package/dist/types/common/schema.d.ts +1 -1
- package/dist/types/common/types.d.ts +13 -26
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +4 -0
- package/dist/types/hooks/useHandleContentChanges.d.ts +3 -0
- package/dist/types/index.d.ts +10 -7
- package/dist/{types-ts4.5/providers → types/providers/confluence}/confluenceContentAPI.d.ts +2 -1
- package/dist/types/providers/{inMemory.d.ts → in-memory/inMemory.d.ts} +1 -1
- package/dist/types/{common → providers}/syncBlockProvider.d.ts +2 -1
- package/dist/types/providers/types.d.ts +18 -0
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +23 -0
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +31 -0
- package/dist/types/{common → store-manager}/syncBlockStoreManager.d.ts +7 -25
- package/dist/types/utils/utils.d.ts +1 -2
- package/dist/types-ts4.5/common/schema.d.ts +1 -1
- package/dist/types-ts4.5/common/types.d.ts +13 -26
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +4 -0
- package/dist/types-ts4.5/hooks/useHandleContentChanges.d.ts +3 -0
- package/dist/types-ts4.5/index.d.ts +10 -7
- package/dist/{types/providers → types-ts4.5/providers/confluence}/confluenceContentAPI.d.ts +2 -1
- package/dist/types-ts4.5/providers/{inMemory.d.ts → in-memory/inMemory.d.ts} +1 -1
- package/dist/types-ts4.5/{common → providers}/syncBlockProvider.d.ts +2 -1
- package/dist/types-ts4.5/providers/types.d.ts +18 -0
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +23 -0
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +31 -0
- package/dist/types-ts4.5/{common → store-manager}/syncBlockStoreManager.d.ts +7 -25
- package/dist/types-ts4.5/utils/utils.d.ts +1 -2
- package/package.json +2 -2
- package/dist/cjs/common/syncBlockStoreManager.js +0 -377
- package/dist/es2019/common/syncBlockStoreManager.js +0 -265
- package/dist/esm/common/syncBlockStoreManager.js +0 -370
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
|
-
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; }
|
|
8
|
-
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) { _defineProperty(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; }
|
|
9
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
10
|
-
import uuid from 'uuid';
|
|
11
|
-
import { resourceIdFromSourceAndLocalId } from '../utils/ari';
|
|
12
|
-
import { convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockPMNodeToSyncBlockNode } from '../utils/utils';
|
|
13
|
-
import { rebaseTransaction as _rebaseTransaction } from './rebase-transaction';
|
|
14
|
-
import { SyncBlockStatus } from './types';
|
|
15
|
-
|
|
16
|
-
// Do this typedef to make it clear that
|
|
17
|
-
// this is a local identifier for a resource for local use
|
|
18
|
-
|
|
19
|
-
// A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
|
|
20
|
-
// Supports create, read, update, and delete operations for sync blocks.
|
|
21
|
-
// Designed to manage local in-memory state and synchronize with an external data provider.
|
|
22
|
-
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
23
|
-
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
24
|
-
export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
25
|
-
function SyncBlockStoreManager(dataProvider) {
|
|
26
|
-
_classCallCheck(this, SyncBlockStoreManager);
|
|
27
|
-
this.syncBlocks = new Map();
|
|
28
|
-
this.syncBlockURLRequests = new Map();
|
|
29
|
-
this.dataProvider = dataProvider;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
* @param node - The sync block node to get the source URL for
|
|
35
|
-
* @returns The source URL for the sync block node if it exists. Otherwise trigger fetch and return undefined, syncBlock will update with URL asynchronously.
|
|
36
|
-
*/
|
|
37
|
-
return _createClass(SyncBlockStoreManager, [{
|
|
38
|
-
key: "getSyncBlockSourceURL",
|
|
39
|
-
value: function getSyncBlockSourceURL(node) {
|
|
40
|
-
var _this = this;
|
|
41
|
-
var _node$attrs = node.attrs,
|
|
42
|
-
localId = _node$attrs.localId,
|
|
43
|
-
resourceId = _node$attrs.resourceId;
|
|
44
|
-
if (!localId || !resourceId || !this.dataProvider) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
var existingSyncBlock = this.syncBlocks.get(localId);
|
|
48
|
-
if (!existingSyncBlock) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
var sourceURL = existingSyncBlock.sourceURL;
|
|
52
|
-
if (sourceURL) {
|
|
53
|
-
return sourceURL;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// if the sync block is a reference block, we need to fetch the URL to the source
|
|
57
|
-
// we could optimise this further by checking if the sync block is on the same page as the source
|
|
58
|
-
if (!this.isSourceBlock(node) && !this.syncBlockURLRequests.get(localId)) {
|
|
59
|
-
var syncBlockNode = convertSyncBlockPMNodeToSyncBlockNode(node, false);
|
|
60
|
-
this.syncBlockURLRequests.set(localId, true);
|
|
61
|
-
this.dataProvider.retrieveSyncBlockSourceUrl(syncBlockNode).then(function (sourceURL) {
|
|
62
|
-
var existingSyncBlock = _this.syncBlocks.get(localId);
|
|
63
|
-
if (existingSyncBlock) {
|
|
64
|
-
var syncBlock = _objectSpread(_objectSpread({}, existingSyncBlock), {}, {
|
|
65
|
-
sourceURL: sourceURL
|
|
66
|
-
});
|
|
67
|
-
_this.syncBlocks.set(localId, syncBlock);
|
|
68
|
-
}
|
|
69
|
-
}).finally(function () {
|
|
70
|
-
_this.syncBlockURLRequests.set(localId, false);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
}, {
|
|
76
|
-
key: "fetchSyncBlockData",
|
|
77
|
-
value: function () {
|
|
78
|
-
var _fetchSyncBlockData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(syncBlockNode) {
|
|
79
|
-
var syncNode, data, sourceURL, fetchSyncBlockDataResult;
|
|
80
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
81
|
-
while (1) switch (_context.prev = _context.next) {
|
|
82
|
-
case 0:
|
|
83
|
-
if (['bodiedSyncBlock', 'syncBlock'].includes(syncBlockNode.type.name)) {
|
|
84
|
-
_context.next = 2;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
throw new Error('Node is not a sync block');
|
|
88
|
-
case 2:
|
|
89
|
-
syncNode = convertSyncBlockPMNodeToSyncBlockNode(syncBlockNode, false);
|
|
90
|
-
if (this.dataProvider) {
|
|
91
|
-
_context.next = 5;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
throw new Error('Data provider not set');
|
|
95
|
-
case 5:
|
|
96
|
-
_context.next = 7;
|
|
97
|
-
return this.dataProvider.fetchNodesData([syncNode]);
|
|
98
|
-
case 7:
|
|
99
|
-
data = _context.sent;
|
|
100
|
-
if (data) {
|
|
101
|
-
_context.next = 10;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
throw new Error('Failed to fetch sync block node data');
|
|
105
|
-
case 10:
|
|
106
|
-
sourceURL = this.getSyncBlockSourceURL(syncBlockNode);
|
|
107
|
-
fetchSyncBlockDataResult = data[0];
|
|
108
|
-
if (!('status' in fetchSyncBlockDataResult)) {
|
|
109
|
-
// only adds it to the map if it did not error out
|
|
110
|
-
this.syncBlocks.set(syncBlockNode.attrs.localId, {
|
|
111
|
-
syncNode: syncNode,
|
|
112
|
-
sourceURL: sourceURL,
|
|
113
|
-
syncBlockData: fetchSyncBlockDataResult
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
return _context.abrupt("return", fetchSyncBlockDataResult);
|
|
117
|
-
case 14:
|
|
118
|
-
case "end":
|
|
119
|
-
return _context.stop();
|
|
120
|
-
}
|
|
121
|
-
}, _callee, this);
|
|
122
|
-
}));
|
|
123
|
-
function fetchSyncBlockData(_x) {
|
|
124
|
-
return _fetchSyncBlockData.apply(this, arguments);
|
|
125
|
-
}
|
|
126
|
-
return fetchSyncBlockData;
|
|
127
|
-
}()
|
|
128
|
-
/**
|
|
129
|
-
* Add/update a sync block node to/from the local cache
|
|
130
|
-
* @param syncBlockNode - The sync block node to update
|
|
131
|
-
*/
|
|
132
|
-
}, {
|
|
133
|
-
key: "updateSyncBlockData",
|
|
134
|
-
value: function updateSyncBlockData(syncBlockNode) {
|
|
135
|
-
try {
|
|
136
|
-
if (!this.isSourceBlock(syncBlockNode)) {
|
|
137
|
-
throw new Error('Node is not a source sync block');
|
|
138
|
-
}
|
|
139
|
-
var _syncBlockNode$attrs = syncBlockNode.attrs,
|
|
140
|
-
localId = _syncBlockNode$attrs.localId,
|
|
141
|
-
resourceId = _syncBlockNode$attrs.resourceId;
|
|
142
|
-
if (!localId || !resourceId) {
|
|
143
|
-
throw new Error('Local ID or resource ID is not set');
|
|
144
|
-
}
|
|
145
|
-
var existingSyncBlock = this.syncBlocks.get(localId);
|
|
146
|
-
var sourceURL = existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.sourceURL;
|
|
147
|
-
var syncBlock = {
|
|
148
|
-
syncNode: convertSyncBlockPMNodeToSyncBlockNode(syncBlockNode),
|
|
149
|
-
sourceURL: sourceURL,
|
|
150
|
-
syncBlockData: _objectSpread(_objectSpread({}, convertSyncBlockPMNodeToSyncBlockData(syncBlockNode)), {}, {
|
|
151
|
-
sourceDocumentAri: resourceId // same as resourceId ARI when content property API
|
|
152
|
-
})
|
|
153
|
-
};
|
|
154
|
-
this.syncBlocks.set(localId, syncBlock);
|
|
155
|
-
} catch (_unused) {
|
|
156
|
-
//TODO: EDITOR-1921 - add error analytics
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Save content of bodiedSyncBlock nodes in local cache to backend
|
|
162
|
-
*
|
|
163
|
-
* @returns true if saving all nodes successfully, false if fail to save some/all nodes
|
|
164
|
-
*/
|
|
165
|
-
}, {
|
|
166
|
-
key: "flushBodiedSyncBlocks",
|
|
167
|
-
value: (function () {
|
|
168
|
-
var _flushBodiedSyncBlocks = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
169
|
-
var bodiedSyncBlockNodes, bodiedSyncBlockData, resourceIds;
|
|
170
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
171
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
172
|
-
case 0:
|
|
173
|
-
_context2.prev = 0;
|
|
174
|
-
if (this.dataProvider) {
|
|
175
|
-
_context2.next = 3;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
throw new Error('Data provider not set');
|
|
179
|
-
case 3:
|
|
180
|
-
bodiedSyncBlockNodes = [];
|
|
181
|
-
bodiedSyncBlockData = [];
|
|
182
|
-
Array.from(this.syncBlocks.values()).forEach(function (syncBlock) {
|
|
183
|
-
if (syncBlock.syncNode.type === 'bodiedSyncBlock') {
|
|
184
|
-
bodiedSyncBlockNodes.push(syncBlock.syncNode);
|
|
185
|
-
bodiedSyncBlockData.push(syncBlock.syncBlockData);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
if (!(bodiedSyncBlockNodes.length === 0)) {
|
|
189
|
-
_context2.next = 8;
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
return _context2.abrupt("return", Promise.resolve(true));
|
|
193
|
-
case 8:
|
|
194
|
-
_context2.next = 10;
|
|
195
|
-
return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
196
|
-
case 10:
|
|
197
|
-
resourceIds = _context2.sent;
|
|
198
|
-
return _context2.abrupt("return", resourceIds.every(function (resourceId) {
|
|
199
|
-
return resourceId !== undefined;
|
|
200
|
-
}));
|
|
201
|
-
case 14:
|
|
202
|
-
_context2.prev = 14;
|
|
203
|
-
_context2.t0 = _context2["catch"](0);
|
|
204
|
-
return _context2.abrupt("return", false);
|
|
205
|
-
case 17:
|
|
206
|
-
case "end":
|
|
207
|
-
return _context2.stop();
|
|
208
|
-
}
|
|
209
|
-
}, _callee2, this, [[0, 14]]);
|
|
210
|
-
}));
|
|
211
|
-
function flushBodiedSyncBlocks() {
|
|
212
|
-
return _flushBodiedSyncBlocks.apply(this, arguments);
|
|
213
|
-
}
|
|
214
|
-
return flushBodiedSyncBlocks;
|
|
215
|
-
}()
|
|
216
|
-
/**
|
|
217
|
-
* Get the URL for a sync block.
|
|
218
|
-
* @param localId - The local ID of the sync block to get the URL for
|
|
219
|
-
* @returns
|
|
220
|
-
*/
|
|
221
|
-
)
|
|
222
|
-
}, {
|
|
223
|
-
key: "getSyncBlockURL",
|
|
224
|
-
value: function getSyncBlockURL(localId) {
|
|
225
|
-
var syncBlock = this.syncBlocks.get(localId);
|
|
226
|
-
return syncBlock === null || syncBlock === void 0 ? void 0 : syncBlock.sourceURL;
|
|
227
|
-
}
|
|
228
|
-
}, {
|
|
229
|
-
key: "setEditorView",
|
|
230
|
-
value: function setEditorView(editorView) {
|
|
231
|
-
this.editorView = editorView;
|
|
232
|
-
}
|
|
233
|
-
}, {
|
|
234
|
-
key: "isSourceBlock",
|
|
235
|
-
value: function isSourceBlock(node) {
|
|
236
|
-
var _this$dataProvider;
|
|
237
|
-
if (node.type.name !== 'bodiedSyncBlock') {
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
var _node$attrs2 = node.attrs,
|
|
241
|
-
resourceId = _node$attrs2.resourceId,
|
|
242
|
-
localId = _node$attrs2.localId;
|
|
243
|
-
var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
244
|
-
if (!sourceId) {
|
|
245
|
-
return false;
|
|
246
|
-
}
|
|
247
|
-
return typeof resourceId === 'string' && typeof sourceId === 'string' && typeof localId === 'string' && resourceId === resourceIdFromSourceAndLocalId(sourceId, localId);
|
|
248
|
-
}
|
|
249
|
-
}, {
|
|
250
|
-
key: "registerConfirmationCallback",
|
|
251
|
-
value: function registerConfirmationCallback(callback) {
|
|
252
|
-
var _this2 = this;
|
|
253
|
-
this.confirmationCallback = callback;
|
|
254
|
-
return function () {
|
|
255
|
-
_this2.confirmationCallback = undefined;
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
}, {
|
|
259
|
-
key: "requireConfirmationBeforeDelete",
|
|
260
|
-
value: function requireConfirmationBeforeDelete() {
|
|
261
|
-
return !!this.confirmationCallback;
|
|
262
|
-
}
|
|
263
|
-
}, {
|
|
264
|
-
key: "createSyncBlockNode",
|
|
265
|
-
value: function createSyncBlockNode() {
|
|
266
|
-
var _this$dataProvider2;
|
|
267
|
-
var blockInstanceId = uuid();
|
|
268
|
-
var sourceId = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.getSourceId();
|
|
269
|
-
if (!sourceId) {
|
|
270
|
-
throw new Error('Provider of sync block plugin is not set');
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// This should be generated by the data provider implementation as it differs between data providers
|
|
274
|
-
var resourceId = resourceIdFromSourceAndLocalId(sourceId, blockInstanceId);
|
|
275
|
-
var syncBlockNode = {
|
|
276
|
-
attrs: {
|
|
277
|
-
resourceId: resourceId,
|
|
278
|
-
localId: blockInstanceId
|
|
279
|
-
},
|
|
280
|
-
type: 'bodiedSyncBlock'
|
|
281
|
-
};
|
|
282
|
-
return syncBlockNode;
|
|
283
|
-
}
|
|
284
|
-
}, {
|
|
285
|
-
key: "deleteSyncBlocksWithConfirmation",
|
|
286
|
-
value: function () {
|
|
287
|
-
var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(tr, syncBlockIds) {
|
|
288
|
-
var _this3 = this;
|
|
289
|
-
var confirmed, _this$editorView;
|
|
290
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
291
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
292
|
-
case 0:
|
|
293
|
-
if (!this.confirmationCallback) {
|
|
294
|
-
_context3.next = 7;
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
this.confirmationTransaction = tr;
|
|
298
|
-
_context3.next = 4;
|
|
299
|
-
return this.confirmationCallback();
|
|
300
|
-
case 4:
|
|
301
|
-
confirmed = _context3.sent;
|
|
302
|
-
if (confirmed) {
|
|
303
|
-
(_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
|
|
304
|
-
// Need to update the BE on deletion
|
|
305
|
-
syncBlockIds.forEach(function (_ref) {
|
|
306
|
-
var localId = _ref.localId;
|
|
307
|
-
return _this3.syncBlocks.delete(localId);
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
this.confirmationTransaction = undefined;
|
|
311
|
-
case 7:
|
|
312
|
-
case "end":
|
|
313
|
-
return _context3.stop();
|
|
314
|
-
}
|
|
315
|
-
}, _callee3, this);
|
|
316
|
-
}));
|
|
317
|
-
function deleteSyncBlocksWithConfirmation(_x2, _x3) {
|
|
318
|
-
return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
|
|
319
|
-
}
|
|
320
|
-
return deleteSyncBlocksWithConfirmation;
|
|
321
|
-
}()
|
|
322
|
-
}, {
|
|
323
|
-
key: "rebaseTransaction",
|
|
324
|
-
value: function rebaseTransaction(incomingTr, state) {
|
|
325
|
-
if (!this.confirmationTransaction) {
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
this.confirmationTransaction = _rebaseTransaction(this.confirmationTransaction, incomingTr, state);
|
|
329
|
-
}
|
|
330
|
-
}]);
|
|
331
|
-
}();
|
|
332
|
-
export function useFetchSyncBlockData(manager, syncBlockNode) {
|
|
333
|
-
var _useState = useState(null),
|
|
334
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
335
|
-
fetchSyncBlockDataResult = _useState2[0],
|
|
336
|
-
setFetchSyncBlockDataResult = _useState2[1];
|
|
337
|
-
var fetchSyncBlockNode = useCallback(function () {
|
|
338
|
-
manager.fetchSyncBlockData(syncBlockNode).then(function (data) {
|
|
339
|
-
if ('status' in data) {
|
|
340
|
-
// if there is an error, we don't want to replace real existing data with the error data
|
|
341
|
-
if (!fetchSyncBlockDataResult || 'status' in fetchSyncBlockDataResult) {
|
|
342
|
-
setFetchSyncBlockDataResult(data);
|
|
343
|
-
}
|
|
344
|
-
} else {
|
|
345
|
-
setFetchSyncBlockDataResult(data);
|
|
346
|
-
}
|
|
347
|
-
}).catch(function () {
|
|
348
|
-
//TODO: EDITOR-1921 - add error analytics
|
|
349
|
-
if (!fetchSyncBlockDataResult || 'status' in fetchSyncBlockDataResult) {
|
|
350
|
-
setFetchSyncBlockDataResult({
|
|
351
|
-
status: SyncBlockStatus.Errored
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}, [manager, syncBlockNode, fetchSyncBlockDataResult]);
|
|
356
|
-
useEffect(function () {
|
|
357
|
-
fetchSyncBlockNode();
|
|
358
|
-
var interval = window.setInterval(fetchSyncBlockNode, 3000);
|
|
359
|
-
return function () {
|
|
360
|
-
window.clearInterval(interval);
|
|
361
|
-
};
|
|
362
|
-
}, [fetchSyncBlockNode]);
|
|
363
|
-
return fetchSyncBlockDataResult;
|
|
364
|
-
}
|
|
365
|
-
export function useHandleContentChanges(manager, syncBlockNode) {
|
|
366
|
-
useEffect(function () {
|
|
367
|
-
//TODO: EDITOR-1921 - add error analytics
|
|
368
|
-
manager.updateSyncBlockData(syncBlockNode);
|
|
369
|
-
}, [manager, syncBlockNode]);
|
|
370
|
-
}
|