@atlaskit/editor-synced-block-provider 2.4.0 → 2.5.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 +11 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +5 -5
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/providers/types.js +5 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +68 -176
- package/dist/cjs/store-manager/syncBlockStoreManager.js +14 -14
- package/dist/cjs/utils/createSyncBlock.js +15 -0
- package/dist/cjs/utils/{mergeFetchSyncBlockDataResult.js → resolveSyncBlockInstance.js} +6 -6
- package/dist/es2019/hooks/useFetchSyncBlockData.js +4 -4
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/providers/types.js +7 -0
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +13 -63
- package/dist/es2019/store-manager/syncBlockStoreManager.js +13 -13
- package/dist/es2019/utils/createSyncBlock.js +9 -0
- package/dist/es2019/utils/{mergeFetchSyncBlockDataResult.js → resolveSyncBlockInstance.js} +5 -5
- package/dist/esm/hooks/useFetchSyncBlockData.js +5 -5
- package/dist/esm/index.js +2 -1
- package/dist/esm/providers/types.js +7 -0
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +67 -175
- package/dist/esm/store-manager/syncBlockStoreManager.js +14 -14
- package/dist/esm/utils/createSyncBlock.js +9 -0
- package/dist/esm/utils/{mergeFetchSyncBlockDataResult.js → resolveSyncBlockInstance.js} +5 -5
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +2 -2
- package/dist/types/index.d.ts +2 -1
- package/dist/types/providers/confluence/confluenceContentAPI.d.ts +2 -2
- package/dist/types/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types/providers/types.d.ts +10 -5
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +2 -12
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +5 -5
- package/dist/types/utils/createSyncBlock.d.ts +2 -0
- package/dist/types/utils/resolveSyncBlockInstance.d.ts +12 -0
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +2 -2
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +2 -2
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types-ts4.5/providers/types.d.ts +10 -5
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +2 -12
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +5 -5
- package/dist/types-ts4.5/utils/createSyncBlock.d.ts +2 -0
- package/dist/types-ts4.5/utils/resolveSyncBlockInstance.d.ts +12 -0
- package/package.json +3 -3
- package/dist/types/utils/mergeFetchSyncBlockDataResult.d.ts +0 -12
- package/dist/types-ts4.5/utils/mergeFetchSyncBlockDataResult.d.ts +0 -12
|
@@ -1,52 +1,21 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
return {
|
|
5
|
-
type: 'syncBlock',
|
|
6
|
-
attrs: {
|
|
7
|
-
localId,
|
|
8
|
-
resourceId
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
};
|
|
2
|
+
import { createSyncBlockNode } from '../utils/createSyncBlock';
|
|
3
|
+
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
12
4
|
export class ReferenceSyncBlockStoreManager {
|
|
13
5
|
constructor(dataProvider) {
|
|
14
|
-
_defineProperty(this, "isInitialized", false);
|
|
15
6
|
_defineProperty(this, "isRefreshingSubscriptions", false);
|
|
16
7
|
this.syncBlockCache = new Map();
|
|
17
8
|
this.subscriptions = new Map();
|
|
18
9
|
this.dataProvider = dataProvider;
|
|
19
10
|
this.syncBlockURLRequests = new Map();
|
|
20
11
|
}
|
|
21
|
-
async init(editorView) {
|
|
22
|
-
if (!this.editorView && !this.isInitialized) {
|
|
23
|
-
this.editorView = editorView;
|
|
24
|
-
const syncBlockNodes = editorView.state.doc.children.filter(node => node.type.name === 'syncBlock').map(node => {
|
|
25
|
-
return node.toJSON();
|
|
26
|
-
}) || [];
|
|
27
|
-
if (syncBlockNodes.length > 0) {
|
|
28
|
-
try {
|
|
29
|
-
const dataResults = await this.fetchSyncBlocksData(syncBlockNodes);
|
|
30
|
-
if (!dataResults) {
|
|
31
|
-
throw new Error('No data results returned when initializing sync block store manager');
|
|
32
|
-
}
|
|
33
|
-
dataResults.forEach(dataResult => {
|
|
34
|
-
this.updateCache(dataResult);
|
|
35
|
-
});
|
|
36
|
-
} catch (error) {
|
|
37
|
-
// TODO: EDITOR-1921 - add error analytics
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
this.isInitialized = true;
|
|
42
|
-
}
|
|
43
12
|
|
|
44
13
|
/**
|
|
45
14
|
* Refreshes the subscriptions for all sync blocks.
|
|
46
15
|
* @returns {Promise<void>}
|
|
47
16
|
*/
|
|
48
17
|
async refreshSubscriptions() {
|
|
49
|
-
if (this.isRefreshingSubscriptions
|
|
18
|
+
if (this.isRefreshingSubscriptions) {
|
|
50
19
|
return;
|
|
51
20
|
}
|
|
52
21
|
this.isRefreshingSubscriptions = true;
|
|
@@ -89,23 +58,6 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
89
58
|
});
|
|
90
59
|
}
|
|
91
60
|
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Fetch sync block data for a given sync block node.
|
|
95
|
-
* @param syncBlockNode - The sync block node to fetch data for
|
|
96
|
-
* @returns The fetched sync block data result
|
|
97
|
-
*/
|
|
98
|
-
async fetchSyncBlockData(syncBlockNode) {
|
|
99
|
-
if (!this.dataProvider) {
|
|
100
|
-
throw new Error('Data provider not set');
|
|
101
|
-
}
|
|
102
|
-
const syncNode = createSyncBlockNode(syncBlockNode.attrs.localId, syncBlockNode.attrs.resourceId);
|
|
103
|
-
const data = await this.fetchSyncBlocksData([syncNode]);
|
|
104
|
-
if (!data || data.length === 0) {
|
|
105
|
-
throw new Error('Failed to fetch sync block data');
|
|
106
|
-
}
|
|
107
|
-
return data[0];
|
|
108
|
-
}
|
|
109
61
|
async fetchSyncBlocksData(syncBlockNodes) {
|
|
110
62
|
if (!this.dataProvider) {
|
|
111
63
|
throw new Error('Data provider not set');
|
|
@@ -115,19 +67,19 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
115
67
|
throw new Error('Failed to fetch sync block node data');
|
|
116
68
|
}
|
|
117
69
|
const resolvedData = [];
|
|
118
|
-
data.forEach(
|
|
119
|
-
var
|
|
120
|
-
if (!
|
|
70
|
+
data.forEach(syncBlockInstance => {
|
|
71
|
+
var _resolvedSyncBlockIns;
|
|
72
|
+
if (!syncBlockInstance.resourceId) {
|
|
121
73
|
return;
|
|
122
74
|
}
|
|
123
|
-
const existingSyncBlock = this.getFromCache(
|
|
124
|
-
const
|
|
125
|
-
this.updateCache(
|
|
126
|
-
resolvedData.push(
|
|
75
|
+
const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
|
|
76
|
+
const resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
77
|
+
this.updateCache(resolvedSyncBlockInstance);
|
|
78
|
+
resolvedData.push(resolvedSyncBlockInstance);
|
|
127
79
|
|
|
128
80
|
// fetch source URL if not already present
|
|
129
|
-
if (!((
|
|
130
|
-
this.fetchSyncBlockSourceURL(
|
|
81
|
+
if (!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) && resolvedSyncBlockInstance.resourceId) {
|
|
82
|
+
this.fetchSyncBlockSourceURL(resolvedSyncBlockInstance.resourceId);
|
|
131
83
|
}
|
|
132
84
|
});
|
|
133
85
|
return resolvedData;
|
|
@@ -177,7 +129,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
177
129
|
if (cachedData) {
|
|
178
130
|
callback(cachedData);
|
|
179
131
|
} else {
|
|
180
|
-
this.
|
|
132
|
+
this.fetchSyncBlocksData([createSyncBlockNode(localId, resourceId)]).catch(() => {});
|
|
181
133
|
}
|
|
182
134
|
return () => {
|
|
183
135
|
const resourceSubscriptions = this.subscriptions.get(resourceId);
|
|
@@ -210,7 +162,5 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
210
162
|
this.syncBlockCache.clear();
|
|
211
163
|
this.subscriptions.clear();
|
|
212
164
|
this.syncBlockURLRequests.clear();
|
|
213
|
-
this.editorView = undefined;
|
|
214
|
-
this.isInitialized = false;
|
|
215
165
|
}
|
|
216
166
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createSyncBlockNode } from '../utils/createSyncBlock';
|
|
1
2
|
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
2
3
|
import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
|
3
4
|
|
|
@@ -13,18 +14,20 @@ export class SyncBlockStoreManager {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
|
-
* Fetch sync block data for a given sync block
|
|
17
|
-
* @param
|
|
18
|
-
* @returns The fetched sync block data
|
|
17
|
+
* Fetch sync block data for a given array of sync block nodes.
|
|
18
|
+
* @param nodes - The array of sync block nodes to fetch data for
|
|
19
|
+
* @returns The fetched sync block data results
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
fetchSyncBlocksData(nodes) {
|
|
22
|
+
const syncBlockNodes = nodes.filter(node => {
|
|
23
|
+
return node.type.name === 'syncBlock' && node.attrs.resourceId && node.attrs.localId;
|
|
24
|
+
}).map(node => {
|
|
25
|
+
return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
|
|
26
|
+
}) || [];
|
|
27
|
+
if (syncBlockNodes.length === 0) {
|
|
28
|
+
return Promise.resolve([]);
|
|
23
29
|
}
|
|
24
|
-
|
|
25
|
-
return Promise.reject(new Error('Invalid sync block node type provided for fetchSyncBlockData'));
|
|
26
|
-
}
|
|
27
|
-
return this.referenceSyncBlockStoreManager.fetchSyncBlockData(syncBlockNode);
|
|
30
|
+
return this.referenceSyncBlockStoreManager.fetchSyncBlocksData(syncBlockNodes);
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
/**
|
|
@@ -60,9 +63,6 @@ export class SyncBlockStoreManager {
|
|
|
60
63
|
}
|
|
61
64
|
setEditorView(editorView) {
|
|
62
65
|
this.sourceSyncBlockStoreManager.setEditorView(editorView);
|
|
63
|
-
if (editorView) {
|
|
64
|
-
this.referenceSyncBlockStoreManager.init(editorView);
|
|
65
|
-
}
|
|
66
66
|
}
|
|
67
67
|
isSourceBlock(node) {
|
|
68
68
|
return node.type.name === 'bodiedSyncBlock';
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Merges two
|
|
2
|
+
* Merges two SyncBlockInstance objects,
|
|
3
3
|
* currently it only preserves the sourceURL from the old result,
|
|
4
4
|
* but this can be extended in the future to preserve other fields and resolve conflicts as needed.
|
|
5
5
|
* e.g. compare timestamps or version numbers to determine which data is more recent.
|
|
6
6
|
*
|
|
7
|
-
* @param oldResult - The existing
|
|
8
|
-
* @param newResult - The new
|
|
9
|
-
* @returns A merged
|
|
7
|
+
* @param oldResult - The existing SyncBlockInstance object.
|
|
8
|
+
* @param newResult - The new SyncBlockInstance object to merge.
|
|
9
|
+
* @returns A merged SyncBlockInstance object.
|
|
10
10
|
*/
|
|
11
|
-
export const
|
|
11
|
+
export const resolveSyncBlockInstance = (oldResult, newResult) => {
|
|
12
12
|
var _newResult$data, _oldResult$data;
|
|
13
13
|
// if the old result has no data, we simple return the new result
|
|
14
14
|
if (!oldResult.data) {
|
|
@@ -4,15 +4,15 @@ export var SYNC_BLOCK_FETCH_INTERVAL = 3000;
|
|
|
4
4
|
export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, syncBlockNode) {
|
|
5
5
|
var _useState = useState(null),
|
|
6
6
|
_useState2 = _slicedToArray(_useState, 2),
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
syncBlockInstance = _useState2[0],
|
|
8
|
+
setSyncBlockInstance = _useState2[1];
|
|
9
9
|
useEffect(function () {
|
|
10
10
|
var unsubscribe = manager.subscribeToSyncBlockData(syncBlockNode, function (data) {
|
|
11
|
-
|
|
11
|
+
setSyncBlockInstance(data);
|
|
12
12
|
});
|
|
13
13
|
return function () {
|
|
14
14
|
unsubscribe();
|
|
15
15
|
};
|
|
16
|
-
}, [manager,
|
|
17
|
-
return
|
|
16
|
+
}, [manager, syncBlockNode]);
|
|
17
|
+
return syncBlockInstance;
|
|
18
18
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -9,4 +9,5 @@ export { getDefaultSyncBlockSchema } from './common/schema';
|
|
|
9
9
|
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
|
|
10
10
|
export { getConfluencePageAri } from './utils/ari';
|
|
11
11
|
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
12
|
-
export { rebaseTransaction } from './common/rebase-transaction';
|
|
12
|
+
export { rebaseTransaction } from './common/rebase-transaction';
|
|
13
|
+
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
@@ -6,6 +6,13 @@ import _inherits from "@babel/runtime/helpers/inherits";
|
|
|
6
6
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
7
7
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
8
8
|
import { NodeDataProvider } from '@atlaskit/node-data-provider';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The instance of a sync block, containing its data and metadata.
|
|
12
|
+
* Mainly used for representing the state of a sync block after fetching from a data provider.
|
|
13
|
+
* This will be used in both data processing and rendering contexts.
|
|
14
|
+
*/
|
|
15
|
+
|
|
9
16
|
export var SyncBlockDataProvider = /*#__PURE__*/function (_NodeDataProvider) {
|
|
10
17
|
function SyncBlockDataProvider() {
|
|
11
18
|
_classCallCheck(this, SyncBlockDataProvider);
|
|
@@ -5,111 +5,48 @@ import _createClass from "@babel/runtime/helpers/createClass";
|
|
|
5
5
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
6
6
|
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; }
|
|
7
7
|
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; }
|
|
8
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
9
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
9
10
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
11
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
var createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
|
|
14
|
-
return {
|
|
15
|
-
type: 'syncBlock',
|
|
16
|
-
attrs: {
|
|
17
|
-
localId: localId,
|
|
18
|
-
resourceId: resourceId
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
};
|
|
12
|
+
import { createSyncBlockNode } from '../utils/createSyncBlock';
|
|
13
|
+
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
22
14
|
export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
23
15
|
function ReferenceSyncBlockStoreManager(dataProvider) {
|
|
24
16
|
_classCallCheck(this, ReferenceSyncBlockStoreManager);
|
|
25
|
-
_defineProperty(this, "isInitialized", false);
|
|
26
17
|
_defineProperty(this, "isRefreshingSubscriptions", false);
|
|
27
18
|
this.syncBlockCache = new Map();
|
|
28
19
|
this.subscriptions = new Map();
|
|
29
20
|
this.dataProvider = dataProvider;
|
|
30
21
|
this.syncBlockURLRequests = new Map();
|
|
31
22
|
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Refreshes the subscriptions for all sync blocks.
|
|
26
|
+
* @returns {Promise<void>}
|
|
27
|
+
*/
|
|
32
28
|
return _createClass(ReferenceSyncBlockStoreManager, [{
|
|
33
|
-
key: "init",
|
|
34
|
-
value: function () {
|
|
35
|
-
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(editorView) {
|
|
36
|
-
var _this = this;
|
|
37
|
-
var syncBlockNodes, dataResults;
|
|
38
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
39
|
-
while (1) switch (_context.prev = _context.next) {
|
|
40
|
-
case 0:
|
|
41
|
-
if (!(!this.editorView && !this.isInitialized)) {
|
|
42
|
-
_context.next = 15;
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
this.editorView = editorView;
|
|
46
|
-
syncBlockNodes = editorView.state.doc.children.filter(function (node) {
|
|
47
|
-
return node.type.name === 'syncBlock';
|
|
48
|
-
}).map(function (node) {
|
|
49
|
-
return node.toJSON();
|
|
50
|
-
}) || [];
|
|
51
|
-
if (!(syncBlockNodes.length > 0)) {
|
|
52
|
-
_context.next = 15;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
_context.prev = 4;
|
|
56
|
-
_context.next = 7;
|
|
57
|
-
return this.fetchSyncBlocksData(syncBlockNodes);
|
|
58
|
-
case 7:
|
|
59
|
-
dataResults = _context.sent;
|
|
60
|
-
if (dataResults) {
|
|
61
|
-
_context.next = 10;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
throw new Error('No data results returned when initializing sync block store manager');
|
|
65
|
-
case 10:
|
|
66
|
-
dataResults.forEach(function (dataResult) {
|
|
67
|
-
_this.updateCache(dataResult);
|
|
68
|
-
});
|
|
69
|
-
_context.next = 15;
|
|
70
|
-
break;
|
|
71
|
-
case 13:
|
|
72
|
-
_context.prev = 13;
|
|
73
|
-
_context.t0 = _context["catch"](4);
|
|
74
|
-
case 15:
|
|
75
|
-
this.isInitialized = true;
|
|
76
|
-
case 16:
|
|
77
|
-
case "end":
|
|
78
|
-
return _context.stop();
|
|
79
|
-
}
|
|
80
|
-
}, _callee, this, [[4, 13]]);
|
|
81
|
-
}));
|
|
82
|
-
function init(_x) {
|
|
83
|
-
return _init.apply(this, arguments);
|
|
84
|
-
}
|
|
85
|
-
return init;
|
|
86
|
-
}()
|
|
87
|
-
/**
|
|
88
|
-
* Refreshes the subscriptions for all sync blocks.
|
|
89
|
-
* @returns {Promise<void>}
|
|
90
|
-
*/
|
|
91
|
-
}, {
|
|
92
29
|
key: "refreshSubscriptions",
|
|
93
30
|
value: (function () {
|
|
94
|
-
var _refreshSubscriptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
31
|
+
var _refreshSubscriptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
95
32
|
var syncBlocks, _iterator, _step, _loop;
|
|
96
|
-
return _regeneratorRuntime.wrap(function
|
|
97
|
-
while (1) switch (
|
|
33
|
+
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
|
34
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
98
35
|
case 0:
|
|
99
|
-
if (!
|
|
100
|
-
|
|
36
|
+
if (!this.isRefreshingSubscriptions) {
|
|
37
|
+
_context2.next = 2;
|
|
101
38
|
break;
|
|
102
39
|
}
|
|
103
|
-
return
|
|
40
|
+
return _context2.abrupt("return");
|
|
104
41
|
case 2:
|
|
105
42
|
this.isRefreshingSubscriptions = true;
|
|
106
43
|
syncBlocks = [];
|
|
107
44
|
_iterator = _createForOfIteratorHelper(this.subscriptions.entries());
|
|
108
|
-
|
|
45
|
+
_context2.prev = 5;
|
|
109
46
|
_loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
|
|
110
47
|
var _step$value, resourceId, callbacks;
|
|
111
|
-
return _regeneratorRuntime.wrap(function _loop$(
|
|
112
|
-
while (1) switch (
|
|
48
|
+
return _regeneratorRuntime.wrap(function _loop$(_context) {
|
|
49
|
+
while (1) switch (_context.prev = _context.next) {
|
|
113
50
|
case 0:
|
|
114
51
|
_step$value = _slicedToArray(_step.value, 2), resourceId = _step$value[0], callbacks = _step$value[1];
|
|
115
52
|
Object.keys(callbacks).forEach(function (localId) {
|
|
@@ -117,50 +54,50 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
117
54
|
});
|
|
118
55
|
case 2:
|
|
119
56
|
case "end":
|
|
120
|
-
return
|
|
57
|
+
return _context.stop();
|
|
121
58
|
}
|
|
122
59
|
}, _loop);
|
|
123
60
|
});
|
|
124
61
|
_iterator.s();
|
|
125
62
|
case 8:
|
|
126
63
|
if ((_step = _iterator.n()).done) {
|
|
127
|
-
|
|
64
|
+
_context2.next = 12;
|
|
128
65
|
break;
|
|
129
66
|
}
|
|
130
|
-
return
|
|
67
|
+
return _context2.delegateYield(_loop(), "t0", 10);
|
|
131
68
|
case 10:
|
|
132
|
-
|
|
69
|
+
_context2.next = 8;
|
|
133
70
|
break;
|
|
134
71
|
case 12:
|
|
135
|
-
|
|
72
|
+
_context2.next = 17;
|
|
136
73
|
break;
|
|
137
74
|
case 14:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
_iterator.e(
|
|
75
|
+
_context2.prev = 14;
|
|
76
|
+
_context2.t1 = _context2["catch"](5);
|
|
77
|
+
_iterator.e(_context2.t1);
|
|
141
78
|
case 17:
|
|
142
|
-
|
|
79
|
+
_context2.prev = 17;
|
|
143
80
|
_iterator.f();
|
|
144
|
-
return
|
|
81
|
+
return _context2.finish(17);
|
|
145
82
|
case 20:
|
|
146
|
-
|
|
147
|
-
|
|
83
|
+
_context2.prev = 20;
|
|
84
|
+
_context2.next = 23;
|
|
148
85
|
return this.fetchSyncBlocksData(syncBlocks);
|
|
149
86
|
case 23:
|
|
150
|
-
|
|
87
|
+
_context2.next = 27;
|
|
151
88
|
break;
|
|
152
89
|
case 25:
|
|
153
|
-
|
|
154
|
-
|
|
90
|
+
_context2.prev = 25;
|
|
91
|
+
_context2.t2 = _context2["catch"](20);
|
|
155
92
|
case 27:
|
|
156
|
-
|
|
93
|
+
_context2.prev = 27;
|
|
157
94
|
this.isRefreshingSubscriptions = false;
|
|
158
|
-
return
|
|
95
|
+
return _context2.finish(27);
|
|
159
96
|
case 30:
|
|
160
97
|
case "end":
|
|
161
|
-
return
|
|
98
|
+
return _context2.stop();
|
|
162
99
|
}
|
|
163
|
-
},
|
|
100
|
+
}, _callee, this, [[5, 14, 17, 20], [20, 25, 27, 30]]);
|
|
164
101
|
}));
|
|
165
102
|
function refreshSubscriptions() {
|
|
166
103
|
return _refreshSubscriptions.apply(this, arguments);
|
|
@@ -170,7 +107,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
170
107
|
}, {
|
|
171
108
|
key: "fetchSyncBlockSourceURL",
|
|
172
109
|
value: function fetchSyncBlockSourceURL(resourceId) {
|
|
173
|
-
var
|
|
110
|
+
var _this = this;
|
|
174
111
|
if (!resourceId || !this.dataProvider) {
|
|
175
112
|
return;
|
|
176
113
|
}
|
|
@@ -180,110 +117,67 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
180
117
|
if (!this.syncBlockURLRequests.get(resourceId)) {
|
|
181
118
|
this.syncBlockURLRequests.set(resourceId, true);
|
|
182
119
|
this.dataProvider.retrieveSyncBlockSourceUrl(createSyncBlockNode('', resourceId)).then(function (sourceURL) {
|
|
183
|
-
var existingSyncBlock =
|
|
120
|
+
var existingSyncBlock = _this.getFromCache(resourceId);
|
|
184
121
|
if (existingSyncBlock && existingSyncBlock.data) {
|
|
185
122
|
existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
|
|
186
123
|
sourceURL: sourceURL
|
|
187
124
|
});
|
|
188
|
-
|
|
125
|
+
_this.updateCache(existingSyncBlock);
|
|
189
126
|
}
|
|
190
127
|
}).finally(function () {
|
|
191
|
-
|
|
128
|
+
_this.syncBlockURLRequests.set(resourceId, false);
|
|
192
129
|
});
|
|
193
130
|
}
|
|
194
131
|
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Fetch sync block data for a given sync block node.
|
|
198
|
-
* @param syncBlockNode - The sync block node to fetch data for
|
|
199
|
-
* @returns The fetched sync block data result
|
|
200
|
-
*/
|
|
201
|
-
}, {
|
|
202
|
-
key: "fetchSyncBlockData",
|
|
203
|
-
value: (function () {
|
|
204
|
-
var _fetchSyncBlockData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(syncBlockNode) {
|
|
205
|
-
var syncNode, data;
|
|
206
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
207
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
208
|
-
case 0:
|
|
209
|
-
if (this.dataProvider) {
|
|
210
|
-
_context4.next = 2;
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
throw new Error('Data provider not set');
|
|
214
|
-
case 2:
|
|
215
|
-
syncNode = createSyncBlockNode(syncBlockNode.attrs.localId, syncBlockNode.attrs.resourceId);
|
|
216
|
-
_context4.next = 5;
|
|
217
|
-
return this.fetchSyncBlocksData([syncNode]);
|
|
218
|
-
case 5:
|
|
219
|
-
data = _context4.sent;
|
|
220
|
-
if (!(!data || data.length === 0)) {
|
|
221
|
-
_context4.next = 8;
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
throw new Error('Failed to fetch sync block data');
|
|
225
|
-
case 8:
|
|
226
|
-
return _context4.abrupt("return", data[0]);
|
|
227
|
-
case 9:
|
|
228
|
-
case "end":
|
|
229
|
-
return _context4.stop();
|
|
230
|
-
}
|
|
231
|
-
}, _callee3, this);
|
|
232
|
-
}));
|
|
233
|
-
function fetchSyncBlockData(_x2) {
|
|
234
|
-
return _fetchSyncBlockData.apply(this, arguments);
|
|
235
|
-
}
|
|
236
|
-
return fetchSyncBlockData;
|
|
237
|
-
}())
|
|
238
132
|
}, {
|
|
239
133
|
key: "fetchSyncBlocksData",
|
|
240
134
|
value: function () {
|
|
241
|
-
var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
242
|
-
var
|
|
135
|
+
var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockNodes) {
|
|
136
|
+
var _this2 = this;
|
|
243
137
|
var data, resolvedData;
|
|
244
|
-
return _regeneratorRuntime.wrap(function
|
|
245
|
-
while (1) switch (
|
|
138
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
139
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
246
140
|
case 0:
|
|
247
141
|
if (this.dataProvider) {
|
|
248
|
-
|
|
142
|
+
_context3.next = 2;
|
|
249
143
|
break;
|
|
250
144
|
}
|
|
251
145
|
throw new Error('Data provider not set');
|
|
252
146
|
case 2:
|
|
253
|
-
|
|
147
|
+
_context3.next = 4;
|
|
254
148
|
return this.dataProvider.fetchNodesData(syncBlockNodes);
|
|
255
149
|
case 4:
|
|
256
|
-
data =
|
|
150
|
+
data = _context3.sent;
|
|
257
151
|
if (data) {
|
|
258
|
-
|
|
152
|
+
_context3.next = 7;
|
|
259
153
|
break;
|
|
260
154
|
}
|
|
261
155
|
throw new Error('Failed to fetch sync block node data');
|
|
262
156
|
case 7:
|
|
263
157
|
resolvedData = [];
|
|
264
|
-
data.forEach(function (
|
|
265
|
-
var
|
|
266
|
-
if (!
|
|
158
|
+
data.forEach(function (syncBlockInstance) {
|
|
159
|
+
var _resolvedSyncBlockIns;
|
|
160
|
+
if (!syncBlockInstance.resourceId) {
|
|
267
161
|
return;
|
|
268
162
|
}
|
|
269
|
-
var existingSyncBlock =
|
|
270
|
-
var
|
|
271
|
-
|
|
272
|
-
resolvedData.push(
|
|
163
|
+
var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
|
|
164
|
+
var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
165
|
+
_this2.updateCache(resolvedSyncBlockInstance);
|
|
166
|
+
resolvedData.push(resolvedSyncBlockInstance);
|
|
273
167
|
|
|
274
168
|
// fetch source URL if not already present
|
|
275
|
-
if (!((
|
|
276
|
-
|
|
169
|
+
if (!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) && resolvedSyncBlockInstance.resourceId) {
|
|
170
|
+
_this2.fetchSyncBlockSourceURL(resolvedSyncBlockInstance.resourceId);
|
|
277
171
|
}
|
|
278
172
|
});
|
|
279
|
-
return
|
|
173
|
+
return _context3.abrupt("return", resolvedData);
|
|
280
174
|
case 10:
|
|
281
175
|
case "end":
|
|
282
|
-
return
|
|
176
|
+
return _context3.stop();
|
|
283
177
|
}
|
|
284
|
-
},
|
|
178
|
+
}, _callee2, this);
|
|
285
179
|
}));
|
|
286
|
-
function fetchSyncBlocksData(
|
|
180
|
+
function fetchSyncBlocksData(_x) {
|
|
287
181
|
return _fetchSyncBlocksData.apply(this, arguments);
|
|
288
182
|
}
|
|
289
183
|
return fetchSyncBlocksData;
|
|
@@ -315,7 +209,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
315
209
|
}, {
|
|
316
210
|
key: "subscribe",
|
|
317
211
|
value: function subscribe(node, callback) {
|
|
318
|
-
var
|
|
212
|
+
var _this3 = this;
|
|
319
213
|
// check node is a sync block, as we only support sync block subscriptions
|
|
320
214
|
if (node.type.name !== 'syncBlock') {
|
|
321
215
|
return function () {};
|
|
@@ -336,17 +230,17 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
336
230
|
if (cachedData) {
|
|
337
231
|
callback(cachedData);
|
|
338
232
|
} else {
|
|
339
|
-
this.
|
|
233
|
+
this.fetchSyncBlocksData([createSyncBlockNode(localId, resourceId)]).catch(function () {});
|
|
340
234
|
}
|
|
341
235
|
return function () {
|
|
342
|
-
var resourceSubscriptions =
|
|
236
|
+
var resourceSubscriptions = _this3.subscriptions.get(resourceId);
|
|
343
237
|
if (resourceSubscriptions) {
|
|
344
238
|
delete resourceSubscriptions[localId];
|
|
345
239
|
if (Object.keys(resourceSubscriptions).length === 0) {
|
|
346
|
-
|
|
347
|
-
|
|
240
|
+
_this3.subscriptions.delete(resourceId);
|
|
241
|
+
_this3.deleteFromCache(resourceId);
|
|
348
242
|
} else {
|
|
349
|
-
|
|
243
|
+
_this3.subscriptions.set(resourceId, resourceSubscriptions);
|
|
350
244
|
}
|
|
351
245
|
}
|
|
352
246
|
};
|
|
@@ -373,8 +267,6 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
373
267
|
this.syncBlockCache.clear();
|
|
374
268
|
this.subscriptions.clear();
|
|
375
269
|
this.syncBlockURLRequests.clear();
|
|
376
|
-
this.editorView = undefined;
|
|
377
|
-
this.isInitialized = false;
|
|
378
270
|
}
|
|
379
271
|
}]);
|
|
380
272
|
}();
|