@atlaskit/editor-synced-block-provider 2.2.2 → 2.2.3

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 2.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b32a210dc472a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b32a210dc472a) -
8
+ Refactor async logic
9
+
3
10
  ## 2.2.2
4
11
 
5
12
  ### Patch Changes
@@ -4,10 +4,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.useFetchSyncBlockData = void 0;
7
+ exports.useFetchSyncBlockData = exports.SYNC_BLOCK_FETCH_INTERVAL = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _react = require("react");
10
10
  var _types = require("../common/types");
11
+ var SYNC_BLOCK_FETCH_INTERVAL = exports.SYNC_BLOCK_FETCH_INTERVAL = 3000;
11
12
  var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyncBlockData(manager, syncBlockNode) {
12
13
  var _useState = (0, _react.useState)(null),
13
14
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -40,7 +41,7 @@ var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyn
40
41
  }, [manager, syncBlockNode]);
41
42
  (0, _react.useEffect)(function () {
42
43
  fetchSyncBlockNode();
43
- var interval = window.setInterval(fetchSyncBlockNode, 3000);
44
+ var interval = window.setInterval(fetchSyncBlockNode, SYNC_BLOCK_FETCH_INTERVAL);
44
45
  return function () {
45
46
  window.clearInterval(interval);
46
47
  };
@@ -7,7 +7,10 @@ exports.useHandleContentChanges = void 0;
7
7
  var _react = require("react");
8
8
  var useHandleContentChanges = exports.useHandleContentChanges = function useHandleContentChanges(manager, syncBlockNode) {
9
9
  (0, _react.useEffect)(function () {
10
- //TODO: EDITOR-1921 - add error analytics
11
- manager.updateSyncBlockData(syncBlockNode);
10
+ try {
11
+ manager.updateSyncBlockData(syncBlockNode);
12
+ } catch (_unused) {
13
+ //TODO: EDITOR-1921 - add error analytics
14
+ }
12
15
  }, [manager, syncBlockNode]);
13
16
  };
@@ -81,27 +81,35 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
81
81
  resourceId: syncBlockNode.attrs.resourceId
82
82
  });
83
83
  }
84
- _context.next = 7;
84
+ _context.prev = 5;
85
+ _context.next = 8;
85
86
  return this.dataProvider.fetchNodesData([syncNode]);
86
- case 7:
87
+ case 8:
87
88
  data = _context.sent;
88
89
  if (data) {
89
- _context.next = 10;
90
+ _context.next = 11;
90
91
  break;
91
92
  }
92
93
  throw new Error('Failed to fetch sync block node data');
93
- case 10:
94
+ case 11:
95
+ _context.next = 16;
96
+ break;
97
+ case 13:
98
+ _context.prev = 13;
99
+ _context.t0 = _context["catch"](5);
100
+ throw new Error('Failed to fetch sync block node data');
101
+ case 16:
94
102
  fetchSyncBlockDataResult = data[0];
95
103
  if (!fetchSyncBlockDataResult.error && fetchSyncBlockDataResult.data) {
96
104
  // only adds it to the map if it did not error out
97
105
  this.syncBlockCache.set(syncBlockNode.attrs.localId, _objectSpread(_objectSpread({}, existingSyncBlock), fetchSyncBlockDataResult.data));
98
106
  }
99
107
  return _context.abrupt("return", fetchSyncBlockDataResult);
100
- case 13:
108
+ case 19:
101
109
  case "end":
102
110
  return _context.stop();
103
111
  }
104
- }, _callee, this);
112
+ }, _callee, this, [[5, 13]]);
105
113
  }));
106
114
  function fetchSyncBlockData(_x) {
107
115
  return _fetchSyncBlockData.apply(this, arguments);
@@ -27,18 +27,15 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
27
27
  return (0, _createClass2.default)(SourceSyncBlockStoreManager, [{
28
28
  key: "updateSyncBlockData",
29
29
  value: function updateSyncBlockData(syncBlockNode) {
30
- try {
31
- var _syncBlockNode$attrs = syncBlockNode.attrs,
32
- localId = _syncBlockNode$attrs.localId,
33
- resourceId = _syncBlockNode$attrs.resourceId;
34
- if (!localId || !resourceId) {
35
- throw new Error('Local ID or resource ID is not set');
36
- }
37
- var syncBlockData = (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
38
- this.syncBlockCache.set(localId, syncBlockData);
39
- } catch (_unused) {
40
- //TODO: EDITOR-1921 - add error analytics
30
+ var _syncBlockNode$attrs = syncBlockNode.attrs,
31
+ localId = _syncBlockNode$attrs.localId,
32
+ resourceId = _syncBlockNode$attrs.resourceId;
33
+ if (!localId || !resourceId) {
34
+ throw new Error('Local ID or resource ID is not set');
41
35
  }
36
+ var syncBlockData = (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
37
+ this.syncBlockCache.set(localId, syncBlockData);
38
+ return true;
42
39
  }
43
40
 
44
41
  /**
@@ -23,6 +23,9 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
23
23
  return (0, _createClass2.default)(SyncBlockStoreManager, [{
24
24
  key: "fetchSyncBlockData",
25
25
  value: function fetchSyncBlockData(syncBlockNode) {
26
+ if (!['bodiedSyncBlock', 'syncBlock'].includes(syncBlockNode.type.name)) {
27
+ throw new Error('Node is not a sync block');
28
+ }
26
29
  if (this.isSourceBlock(syncBlockNode)) {
27
30
  return Promise.reject(new Error('Invalid sync block node type provided for fetchSyncBlockData'));
28
31
  }
@@ -37,7 +40,7 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
37
40
  key: "updateSyncBlockData",
38
41
  value: function updateSyncBlockData(syncBlockNode) {
39
42
  if (this.isSourceBlock(syncBlockNode)) {
40
- this.sourceSyncBlockStoreManager.updateSyncBlockData(syncBlockNode);
43
+ return this.sourceSyncBlockStoreManager.updateSyncBlockData(syncBlockNode);
41
44
  } else {
42
45
  throw new Error('Invalid sync block node type provided for updateSyncBlockData');
43
46
  }
@@ -1,5 +1,6 @@
1
1
  import { useCallback, useEffect, useState } from 'react';
2
2
  import { SyncBlockError } from '../common/types';
3
+ export const SYNC_BLOCK_FETCH_INTERVAL = 3000;
3
4
  export const useFetchSyncBlockData = (manager, syncBlockNode) => {
4
5
  const [fetchSyncBlockDataResult, setFetchSyncBlockDataResult] = useState(null);
5
6
  const fetchSyncBlockNode = useCallback(() => {
@@ -29,7 +30,7 @@ export const useFetchSyncBlockData = (manager, syncBlockNode) => {
29
30
  }, [manager, syncBlockNode]);
30
31
  useEffect(() => {
31
32
  fetchSyncBlockNode();
32
- const interval = window.setInterval(fetchSyncBlockNode, 3000);
33
+ const interval = window.setInterval(fetchSyncBlockNode, SYNC_BLOCK_FETCH_INTERVAL);
33
34
  return () => {
34
35
  window.clearInterval(interval);
35
36
  };
@@ -1,7 +1,10 @@
1
1
  import { useEffect } from 'react';
2
2
  export const useHandleContentChanges = (manager, syncBlockNode) => {
3
3
  useEffect(() => {
4
- //TODO: EDITOR-1921 - add error analytics
5
- manager.updateSyncBlockData(syncBlockNode);
4
+ try {
5
+ manager.updateSyncBlockData(syncBlockNode);
6
+ } catch {
7
+ //TODO: EDITOR-1921 - add error analytics
8
+ }
6
9
  }, [manager, syncBlockNode]);
7
10
  };
@@ -56,8 +56,13 @@ export class ReferenceSyncBlockStoreManager {
56
56
  resourceId: syncBlockNode.attrs.resourceId
57
57
  });
58
58
  }
59
- const data = await this.dataProvider.fetchNodesData([syncNode]);
60
- if (!data) {
59
+ let data;
60
+ try {
61
+ data = await this.dataProvider.fetchNodesData([syncNode]);
62
+ if (!data) {
63
+ throw new Error('Failed to fetch sync block node data');
64
+ }
65
+ } catch (error) {
61
66
  throw new Error('Failed to fetch sync block node data');
62
67
  }
63
68
  const fetchSyncBlockDataResult = data[0];
@@ -13,19 +13,16 @@ export class SourceSyncBlockStoreManager {
13
13
  * @param syncBlockNode - The sync block node to update
14
14
  */
15
15
  updateSyncBlockData(syncBlockNode) {
16
- try {
17
- const {
18
- localId,
19
- resourceId
20
- } = syncBlockNode.attrs;
21
- if (!localId || !resourceId) {
22
- throw new Error('Local ID or resource ID is not set');
23
- }
24
- const syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
25
- this.syncBlockCache.set(localId, syncBlockData);
26
- } catch {
27
- //TODO: EDITOR-1921 - add error analytics
16
+ const {
17
+ localId,
18
+ resourceId
19
+ } = syncBlockNode.attrs;
20
+ if (!localId || !resourceId) {
21
+ throw new Error('Local ID or resource ID is not set');
28
22
  }
23
+ const syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
24
+ this.syncBlockCache.set(localId, syncBlockData);
25
+ return true;
29
26
  }
30
27
 
31
28
  /**
@@ -12,6 +12,9 @@ export class SyncBlockStoreManager {
12
12
  this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider);
13
13
  }
14
14
  fetchSyncBlockData(syncBlockNode) {
15
+ if (!['bodiedSyncBlock', 'syncBlock'].includes(syncBlockNode.type.name)) {
16
+ throw new Error('Node is not a sync block');
17
+ }
15
18
  if (this.isSourceBlock(syncBlockNode)) {
16
19
  return Promise.reject(new Error('Invalid sync block node type provided for fetchSyncBlockData'));
17
20
  }
@@ -24,7 +27,7 @@ export class SyncBlockStoreManager {
24
27
  */
25
28
  updateSyncBlockData(syncBlockNode) {
26
29
  if (this.isSourceBlock(syncBlockNode)) {
27
- this.sourceSyncBlockStoreManager.updateSyncBlockData(syncBlockNode);
30
+ return this.sourceSyncBlockStoreManager.updateSyncBlockData(syncBlockNode);
28
31
  } else {
29
32
  throw new Error('Invalid sync block node type provided for updateSyncBlockData');
30
33
  }
@@ -1,6 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import { useCallback, useEffect, useState } from 'react';
3
3
  import { SyncBlockError } from '../common/types';
4
+ export var SYNC_BLOCK_FETCH_INTERVAL = 3000;
4
5
  export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, syncBlockNode) {
5
6
  var _useState = useState(null),
6
7
  _useState2 = _slicedToArray(_useState, 2),
@@ -33,7 +34,7 @@ export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, syncB
33
34
  }, [manager, syncBlockNode]);
34
35
  useEffect(function () {
35
36
  fetchSyncBlockNode();
36
- var interval = window.setInterval(fetchSyncBlockNode, 3000);
37
+ var interval = window.setInterval(fetchSyncBlockNode, SYNC_BLOCK_FETCH_INTERVAL);
37
38
  return function () {
38
39
  window.clearInterval(interval);
39
40
  };
@@ -1,7 +1,10 @@
1
1
  import { useEffect } from 'react';
2
2
  export var useHandleContentChanges = function useHandleContentChanges(manager, syncBlockNode) {
3
3
  useEffect(function () {
4
- //TODO: EDITOR-1921 - add error analytics
5
- manager.updateSyncBlockData(syncBlockNode);
4
+ try {
5
+ manager.updateSyncBlockData(syncBlockNode);
6
+ } catch (_unused) {
7
+ //TODO: EDITOR-1921 - add error analytics
8
+ }
6
9
  }, [manager, syncBlockNode]);
7
10
  };
@@ -74,27 +74,35 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
74
74
  resourceId: syncBlockNode.attrs.resourceId
75
75
  });
76
76
  }
77
- _context.next = 7;
77
+ _context.prev = 5;
78
+ _context.next = 8;
78
79
  return this.dataProvider.fetchNodesData([syncNode]);
79
- case 7:
80
+ case 8:
80
81
  data = _context.sent;
81
82
  if (data) {
82
- _context.next = 10;
83
+ _context.next = 11;
83
84
  break;
84
85
  }
85
86
  throw new Error('Failed to fetch sync block node data');
86
- case 10:
87
+ case 11:
88
+ _context.next = 16;
89
+ break;
90
+ case 13:
91
+ _context.prev = 13;
92
+ _context.t0 = _context["catch"](5);
93
+ throw new Error('Failed to fetch sync block node data');
94
+ case 16:
87
95
  fetchSyncBlockDataResult = data[0];
88
96
  if (!fetchSyncBlockDataResult.error && fetchSyncBlockDataResult.data) {
89
97
  // only adds it to the map if it did not error out
90
98
  this.syncBlockCache.set(syncBlockNode.attrs.localId, _objectSpread(_objectSpread({}, existingSyncBlock), fetchSyncBlockDataResult.data));
91
99
  }
92
100
  return _context.abrupt("return", fetchSyncBlockDataResult);
93
- case 13:
101
+ case 19:
94
102
  case "end":
95
103
  return _context.stop();
96
104
  }
97
- }, _callee, this);
105
+ }, _callee, this, [[5, 13]]);
98
106
  }));
99
107
  function fetchSyncBlockData(_x) {
100
108
  return _fetchSyncBlockData.apply(this, arguments);
@@ -20,18 +20,15 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
20
20
  return _createClass(SourceSyncBlockStoreManager, [{
21
21
  key: "updateSyncBlockData",
22
22
  value: function updateSyncBlockData(syncBlockNode) {
23
- try {
24
- var _syncBlockNode$attrs = syncBlockNode.attrs,
25
- localId = _syncBlockNode$attrs.localId,
26
- resourceId = _syncBlockNode$attrs.resourceId;
27
- if (!localId || !resourceId) {
28
- throw new Error('Local ID or resource ID is not set');
29
- }
30
- var syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
31
- this.syncBlockCache.set(localId, syncBlockData);
32
- } catch (_unused) {
33
- //TODO: EDITOR-1921 - add error analytics
23
+ var _syncBlockNode$attrs = syncBlockNode.attrs,
24
+ localId = _syncBlockNode$attrs.localId,
25
+ resourceId = _syncBlockNode$attrs.resourceId;
26
+ if (!localId || !resourceId) {
27
+ throw new Error('Local ID or resource ID is not set');
34
28
  }
29
+ var syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
30
+ this.syncBlockCache.set(localId, syncBlockData);
31
+ return true;
35
32
  }
36
33
 
37
34
  /**
@@ -17,6 +17,9 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
17
17
  return _createClass(SyncBlockStoreManager, [{
18
18
  key: "fetchSyncBlockData",
19
19
  value: function fetchSyncBlockData(syncBlockNode) {
20
+ if (!['bodiedSyncBlock', 'syncBlock'].includes(syncBlockNode.type.name)) {
21
+ throw new Error('Node is not a sync block');
22
+ }
20
23
  if (this.isSourceBlock(syncBlockNode)) {
21
24
  return Promise.reject(new Error('Invalid sync block node type provided for fetchSyncBlockData'));
22
25
  }
@@ -31,7 +34,7 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
31
34
  key: "updateSyncBlockData",
32
35
  value: function updateSyncBlockData(syncBlockNode) {
33
36
  if (this.isSourceBlock(syncBlockNode)) {
34
- this.sourceSyncBlockStoreManager.updateSyncBlockData(syncBlockNode);
37
+ return this.sourceSyncBlockStoreManager.updateSyncBlockData(syncBlockNode);
35
38
  } else {
36
39
  throw new Error('Invalid sync block node type provided for updateSyncBlockData');
37
40
  }
@@ -1,4 +1,5 @@
1
1
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { FetchSyncBlockDataResult } from '../providers/types';
3
3
  import type { SyncBlockStoreManager } from '../store-manager/syncBlockStoreManager';
4
+ export declare const SYNC_BLOCK_FETCH_INTERVAL = 3000;
4
5
  export declare const useFetchSyncBlockData: (manager: SyncBlockStoreManager, syncBlockNode: PMNode) => FetchSyncBlockDataResult | null;
@@ -15,7 +15,7 @@ export declare class SourceSyncBlockStoreManager {
15
15
  * Add/update a sync block node to/from the local cache
16
16
  * @param syncBlockNode - The sync block node to update
17
17
  */
18
- updateSyncBlockData(syncBlockNode: PMNode): void;
18
+ updateSyncBlockData(syncBlockNode: PMNode): boolean;
19
19
  /**
20
20
  * Save content of bodiedSyncBlock nodes in local cache to backend
21
21
  *
@@ -13,7 +13,7 @@ export declare class SyncBlockStoreManager {
13
13
  * Add/update a sync block node to/from the local cache
14
14
  * @param syncBlockNode - The sync block node to update
15
15
  */
16
- updateSyncBlockData(syncBlockNode: PMNode): void;
16
+ updateSyncBlockData(syncBlockNode: PMNode): boolean;
17
17
  /**
18
18
  * Save content of bodiedSyncBlock nodes in local cache to backend
19
19
  *
@@ -1,4 +1,5 @@
1
1
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { FetchSyncBlockDataResult } from '../providers/types';
3
3
  import type { SyncBlockStoreManager } from '../store-manager/syncBlockStoreManager';
4
+ export declare const SYNC_BLOCK_FETCH_INTERVAL = 3000;
4
5
  export declare const useFetchSyncBlockData: (manager: SyncBlockStoreManager, syncBlockNode: PMNode) => FetchSyncBlockDataResult | null;
@@ -15,7 +15,7 @@ export declare class SourceSyncBlockStoreManager {
15
15
  * Add/update a sync block node to/from the local cache
16
16
  * @param syncBlockNode - The sync block node to update
17
17
  */
18
- updateSyncBlockData(syncBlockNode: PMNode): void;
18
+ updateSyncBlockData(syncBlockNode: PMNode): boolean;
19
19
  /**
20
20
  * Save content of bodiedSyncBlock nodes in local cache to backend
21
21
  *
@@ -13,7 +13,7 @@ export declare class SyncBlockStoreManager {
13
13
  * Add/update a sync block node to/from the local cache
14
14
  * @param syncBlockNode - The sync block node to update
15
15
  */
16
- updateSyncBlockData(syncBlockNode: PMNode): void;
16
+ updateSyncBlockData(syncBlockNode: PMNode): boolean;
17
17
  /**
18
18
  * Save content of bodiedSyncBlock nodes in local cache to backend
19
19
  *
package/package.json CHANGED
@@ -82,7 +82,7 @@
82
82
  }
83
83
  },
84
84
  "name": "@atlaskit/editor-synced-block-provider",
85
- "version": "2.2.2",
85
+ "version": "2.2.3",
86
86
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
87
87
  "author": "Atlassian Pty Ltd",
88
88
  "license": "Apache-2.0",