@atlaskit/editor-synced-block-provider 2.3.1 → 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.
Files changed (48) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/hooks/useFetchSyncBlockData.js +5 -5
  3. package/dist/cjs/index.js +6 -12
  4. package/dist/cjs/providers/types.js +5 -0
  5. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +68 -176
  6. package/dist/cjs/store-manager/syncBlockStoreManager.js +14 -14
  7. package/dist/cjs/utils/createSyncBlock.js +15 -0
  8. package/dist/cjs/utils/{mergeFetchSyncBlockDataResult.js → resolveSyncBlockInstance.js} +6 -6
  9. package/dist/es2019/hooks/useFetchSyncBlockData.js +4 -4
  10. package/dist/es2019/index.js +2 -2
  11. package/dist/es2019/providers/types.js +7 -0
  12. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +13 -63
  13. package/dist/es2019/store-manager/syncBlockStoreManager.js +13 -13
  14. package/dist/es2019/utils/createSyncBlock.js +9 -0
  15. package/dist/es2019/utils/{mergeFetchSyncBlockDataResult.js → resolveSyncBlockInstance.js} +5 -5
  16. package/dist/esm/hooks/useFetchSyncBlockData.js +5 -5
  17. package/dist/esm/index.js +2 -2
  18. package/dist/esm/providers/types.js +7 -0
  19. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +67 -175
  20. package/dist/esm/store-manager/syncBlockStoreManager.js +14 -14
  21. package/dist/esm/utils/createSyncBlock.js +9 -0
  22. package/dist/esm/utils/{mergeFetchSyncBlockDataResult.js → resolveSyncBlockInstance.js} +5 -5
  23. package/dist/types/hooks/useFetchSyncBlockData.d.ts +2 -2
  24. package/dist/types/index.d.ts +2 -2
  25. package/dist/types/providers/confluence/confluenceContentAPI.d.ts +2 -2
  26. package/dist/types/providers/syncBlockProvider.d.ts +2 -2
  27. package/dist/types/providers/types.d.ts +10 -5
  28. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +2 -12
  29. package/dist/types/store-manager/syncBlockStoreManager.d.ts +5 -5
  30. package/dist/types/utils/createSyncBlock.d.ts +2 -0
  31. package/dist/types/utils/resolveSyncBlockInstance.d.ts +12 -0
  32. package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +2 -2
  33. package/dist/types-ts4.5/index.d.ts +2 -2
  34. package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +2 -2
  35. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -2
  36. package/dist/types-ts4.5/providers/types.d.ts +10 -5
  37. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +2 -12
  38. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +5 -5
  39. package/dist/types-ts4.5/utils/createSyncBlock.d.ts +2 -0
  40. package/dist/types-ts4.5/utils/resolveSyncBlockInstance.d.ts +12 -0
  41. package/package.json +3 -3
  42. package/dist/cjs/providers/in-memory/inMemory.js +0 -38
  43. package/dist/es2019/providers/in-memory/inMemory.js +0 -32
  44. package/dist/esm/providers/in-memory/inMemory.js +0 -32
  45. package/dist/types/providers/in-memory/inMemory.d.ts +0 -3
  46. package/dist/types/utils/mergeFetchSyncBlockDataResult.d.ts +0 -12
  47. package/dist/types-ts4.5/providers/in-memory/inMemory.d.ts +0 -3
  48. 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 { resolveFetchSyncBlockDataResult } from '../utils/mergeFetchSyncBlockDataResult';
3
- const createSyncBlockNode = (localId, resourceId) => {
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 || !this.isInitialized) {
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(fetchSyncBlockDataResult => {
119
- var _resolvedFetchSyncBlo;
120
- if (!fetchSyncBlockDataResult.resourceId) {
70
+ data.forEach(syncBlockInstance => {
71
+ var _resolvedSyncBlockIns;
72
+ if (!syncBlockInstance.resourceId) {
121
73
  return;
122
74
  }
123
- const existingSyncBlock = this.getFromCache(fetchSyncBlockDataResult.resourceId);
124
- const resolvedFetchSyncBlockDataResult = existingSyncBlock ? resolveFetchSyncBlockDataResult(existingSyncBlock, fetchSyncBlockDataResult) : fetchSyncBlockDataResult;
125
- this.updateCache(resolvedFetchSyncBlockDataResult);
126
- resolvedData.push(resolvedFetchSyncBlockDataResult);
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 (!((_resolvedFetchSyncBlo = resolvedFetchSyncBlockDataResult.data) !== null && _resolvedFetchSyncBlo !== void 0 && _resolvedFetchSyncBlo.sourceURL) && resolvedFetchSyncBlockDataResult.resourceId) {
130
- this.fetchSyncBlockSourceURL(resolvedFetchSyncBlockDataResult.resourceId);
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.fetchSyncBlockData(node).catch(() => {});
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 node.
17
- * @param syncBlockNode - The sync block node to fetch data for
18
- * @returns The fetched sync block data result
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
- fetchSyncBlockData(syncBlockNode) {
21
- if (!['bodiedSyncBlock', 'syncBlock'].includes(syncBlockNode.type.name)) {
22
- throw new Error('Node is not a sync block');
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
- if (this.isSourceBlock(syncBlockNode)) {
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';
@@ -0,0 +1,9 @@
1
+ export const createSyncBlockNode = (localId, resourceId) => {
2
+ return {
3
+ type: 'syncBlock',
4
+ attrs: {
5
+ localId,
6
+ resourceId
7
+ }
8
+ };
9
+ };
@@ -1,14 +1,14 @@
1
1
  /**
2
- * Merges two FetchSyncBlockDataResult objects,
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 FetchSyncBlockDataResult object.
8
- * @param newResult - The new FetchSyncBlockDataResult object to merge.
9
- * @returns A merged FetchSyncBlockDataResult object.
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 resolveFetchSyncBlockDataResult = (oldResult, newResult) => {
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
- fetchSyncBlockDataResult = _useState2[0],
8
- setFetchSyncBlockDataResult = _useState2[1];
7
+ syncBlockInstance = _useState2[0],
8
+ setSyncBlockInstance = _useState2[1];
9
9
  useEffect(function () {
10
10
  var unsubscribe = manager.subscribeToSyncBlockData(syncBlockNode, function (data) {
11
- setFetchSyncBlockDataResult(data);
11
+ setSyncBlockInstance(data);
12
12
  });
13
13
  return function () {
14
14
  unsubscribe();
15
15
  };
16
- }, [manager, setFetchSyncBlockDataResult, syncBlockNode]);
17
- return fetchSyncBlockDataResult;
16
+ }, [manager, syncBlockNode]);
17
+ return syncBlockInstance;
18
18
  };
package/dist/esm/index.js CHANGED
@@ -5,9 +5,9 @@ export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
5
5
  export { useFetchSyncBlockData } from './hooks/useFetchSyncBlockData';
6
6
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
7
7
  export { SyncBlockError } from './common/types';
8
- export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/in-memory/inMemory';
9
8
  export { getDefaultSyncBlockSchema } from './common/schema';
10
9
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
11
10
  export { getConfluencePageAri } from './utils/ari';
12
11
  export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
13
- 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 _regeneratorRuntime from "@babel/runtime/regenerator";
12
- import { resolveFetchSyncBlockDataResult } from '../utils/mergeFetchSyncBlockDataResult';
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 _callee2() {
31
+ var _refreshSubscriptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
95
32
  var syncBlocks, _iterator, _step, _loop;
96
- return _regeneratorRuntime.wrap(function _callee2$(_context3) {
97
- while (1) switch (_context3.prev = _context3.next) {
33
+ return _regeneratorRuntime.wrap(function _callee$(_context2) {
34
+ while (1) switch (_context2.prev = _context2.next) {
98
35
  case 0:
99
- if (!(this.isRefreshingSubscriptions || !this.isInitialized)) {
100
- _context3.next = 2;
36
+ if (!this.isRefreshingSubscriptions) {
37
+ _context2.next = 2;
101
38
  break;
102
39
  }
103
- return _context3.abrupt("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
- _context3.prev = 5;
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$(_context2) {
112
- while (1) switch (_context2.prev = _context2.next) {
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 _context2.stop();
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
- _context3.next = 12;
64
+ _context2.next = 12;
128
65
  break;
129
66
  }
130
- return _context3.delegateYield(_loop(), "t0", 10);
67
+ return _context2.delegateYield(_loop(), "t0", 10);
131
68
  case 10:
132
- _context3.next = 8;
69
+ _context2.next = 8;
133
70
  break;
134
71
  case 12:
135
- _context3.next = 17;
72
+ _context2.next = 17;
136
73
  break;
137
74
  case 14:
138
- _context3.prev = 14;
139
- _context3.t1 = _context3["catch"](5);
140
- _iterator.e(_context3.t1);
75
+ _context2.prev = 14;
76
+ _context2.t1 = _context2["catch"](5);
77
+ _iterator.e(_context2.t1);
141
78
  case 17:
142
- _context3.prev = 17;
79
+ _context2.prev = 17;
143
80
  _iterator.f();
144
- return _context3.finish(17);
81
+ return _context2.finish(17);
145
82
  case 20:
146
- _context3.prev = 20;
147
- _context3.next = 23;
83
+ _context2.prev = 20;
84
+ _context2.next = 23;
148
85
  return this.fetchSyncBlocksData(syncBlocks);
149
86
  case 23:
150
- _context3.next = 27;
87
+ _context2.next = 27;
151
88
  break;
152
89
  case 25:
153
- _context3.prev = 25;
154
- _context3.t2 = _context3["catch"](20);
90
+ _context2.prev = 25;
91
+ _context2.t2 = _context2["catch"](20);
155
92
  case 27:
156
- _context3.prev = 27;
93
+ _context2.prev = 27;
157
94
  this.isRefreshingSubscriptions = false;
158
- return _context3.finish(27);
95
+ return _context2.finish(27);
159
96
  case 30:
160
97
  case "end":
161
- return _context3.stop();
98
+ return _context2.stop();
162
99
  }
163
- }, _callee2, this, [[5, 14, 17, 20], [20, 25, 27, 30]]);
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 _this2 = this;
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 = _this2.getFromCache(resourceId);
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
- _this2.updateCache(existingSyncBlock);
125
+ _this.updateCache(existingSyncBlock);
189
126
  }
190
127
  }).finally(function () {
191
- _this2.syncBlockURLRequests.set(resourceId, false);
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 _callee4(syncBlockNodes) {
242
- var _this3 = this;
135
+ var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockNodes) {
136
+ var _this2 = this;
243
137
  var data, resolvedData;
244
- return _regeneratorRuntime.wrap(function _callee4$(_context5) {
245
- while (1) switch (_context5.prev = _context5.next) {
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
- _context5.next = 2;
142
+ _context3.next = 2;
249
143
  break;
250
144
  }
251
145
  throw new Error('Data provider not set');
252
146
  case 2:
253
- _context5.next = 4;
147
+ _context3.next = 4;
254
148
  return this.dataProvider.fetchNodesData(syncBlockNodes);
255
149
  case 4:
256
- data = _context5.sent;
150
+ data = _context3.sent;
257
151
  if (data) {
258
- _context5.next = 7;
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 (fetchSyncBlockDataResult) {
265
- var _resolvedFetchSyncBlo;
266
- if (!fetchSyncBlockDataResult.resourceId) {
158
+ data.forEach(function (syncBlockInstance) {
159
+ var _resolvedSyncBlockIns;
160
+ if (!syncBlockInstance.resourceId) {
267
161
  return;
268
162
  }
269
- var existingSyncBlock = _this3.getFromCache(fetchSyncBlockDataResult.resourceId);
270
- var resolvedFetchSyncBlockDataResult = existingSyncBlock ? resolveFetchSyncBlockDataResult(existingSyncBlock, fetchSyncBlockDataResult) : fetchSyncBlockDataResult;
271
- _this3.updateCache(resolvedFetchSyncBlockDataResult);
272
- resolvedData.push(resolvedFetchSyncBlockDataResult);
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 (!((_resolvedFetchSyncBlo = resolvedFetchSyncBlockDataResult.data) !== null && _resolvedFetchSyncBlo !== void 0 && _resolvedFetchSyncBlo.sourceURL) && resolvedFetchSyncBlockDataResult.resourceId) {
276
- _this3.fetchSyncBlockSourceURL(resolvedFetchSyncBlockDataResult.resourceId);
169
+ if (!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) && resolvedSyncBlockInstance.resourceId) {
170
+ _this2.fetchSyncBlockSourceURL(resolvedSyncBlockInstance.resourceId);
277
171
  }
278
172
  });
279
- return _context5.abrupt("return", resolvedData);
173
+ return _context3.abrupt("return", resolvedData);
280
174
  case 10:
281
175
  case "end":
282
- return _context5.stop();
176
+ return _context3.stop();
283
177
  }
284
- }, _callee4, this);
178
+ }, _callee2, this);
285
179
  }));
286
- function fetchSyncBlocksData(_x3) {
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 _this4 = this;
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.fetchSyncBlockData(node).catch(function () {});
233
+ this.fetchSyncBlocksData([createSyncBlockNode(localId, resourceId)]).catch(function () {});
340
234
  }
341
235
  return function () {
342
- var resourceSubscriptions = _this4.subscriptions.get(resourceId);
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
- _this4.subscriptions.delete(resourceId);
347
- _this4.deleteFromCache(resourceId);
240
+ _this3.subscriptions.delete(resourceId);
241
+ _this3.deleteFromCache(resourceId);
348
242
  } else {
349
- _this4.subscriptions.set(resourceId, resourceSubscriptions);
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
  }();