@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 2.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`424619eee38cb`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/424619eee38cb) -
|
|
8
|
+
EDITOR-2451 add tests and refactor
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
3
14
|
## 2.4.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
|
@@ -11,15 +11,15 @@ var SYNC_BLOCK_FETCH_INTERVAL = exports.SYNC_BLOCK_FETCH_INTERVAL = 3000;
|
|
|
11
11
|
var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyncBlockData(manager, syncBlockNode) {
|
|
12
12
|
var _useState = (0, _react.useState)(null),
|
|
13
13
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
syncBlockInstance = _useState2[0],
|
|
15
|
+
setSyncBlockInstance = _useState2[1];
|
|
16
16
|
(0, _react.useEffect)(function () {
|
|
17
17
|
var unsubscribe = manager.subscribeToSyncBlockData(syncBlockNode, function (data) {
|
|
18
|
-
|
|
18
|
+
setSyncBlockInstance(data);
|
|
19
19
|
});
|
|
20
20
|
return function () {
|
|
21
21
|
unsubscribe();
|
|
22
22
|
};
|
|
23
|
-
}, [manager,
|
|
24
|
-
return
|
|
23
|
+
}, [manager, syncBlockNode]);
|
|
24
|
+
return syncBlockInstance;
|
|
25
25
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -51,6 +51,12 @@ Object.defineProperty(exports, "rebaseTransaction", {
|
|
|
51
51
|
return _rebaseTransaction.rebaseTransaction;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
+
Object.defineProperty(exports, "resolveSyncBlockInstance", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function get() {
|
|
57
|
+
return _resolveSyncBlockInstance.resolveSyncBlockInstance;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
54
60
|
Object.defineProperty(exports, "useFetchSyncBlockData", {
|
|
55
61
|
enumerable: true,
|
|
56
62
|
get: function get() {
|
|
@@ -84,4 +90,5 @@ var _schema = require("./common/schema");
|
|
|
84
90
|
var _confluenceContentAPI = require("./providers/confluence/confluenceContentAPI");
|
|
85
91
|
var _ari = require("./utils/ari");
|
|
86
92
|
var _utils = require("./utils/utils");
|
|
87
|
-
var _rebaseTransaction = require("./common/rebase-transaction");
|
|
93
|
+
var _rebaseTransaction = require("./common/rebase-transaction");
|
|
94
|
+
var _resolveSyncBlockInstance = require("./utils/resolveSyncBlockInstance");
|
|
@@ -13,6 +13,11 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
|
|
|
13
13
|
var _nodeDataProvider = require("@atlaskit/node-data-provider");
|
|
14
14
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
15
15
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
16
|
+
/**
|
|
17
|
+
* The instance of a sync block, containing its data and metadata.
|
|
18
|
+
* Mainly used for representing the state of a sync block after fetching from a data provider.
|
|
19
|
+
* This will be used in both data processing and rendering contexts.
|
|
20
|
+
*/
|
|
16
21
|
var SyncBlockDataProvider = exports.SyncBlockDataProvider = /*#__PURE__*/function (_NodeDataProvider) {
|
|
17
22
|
function SyncBlockDataProvider() {
|
|
18
23
|
(0, _classCallCheck2.default)(this, SyncBlockDataProvider);
|
|
@@ -11,163 +11,100 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
11
11
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
12
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
13
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
var
|
|
14
|
+
var _createSyncBlock = require("../utils/createSyncBlock");
|
|
15
|
+
var _resolveSyncBlockInstance = require("../utils/resolveSyncBlockInstance");
|
|
15
16
|
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; }
|
|
16
17
|
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) { (0, _defineProperty2.default)(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; }
|
|
17
18
|
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; } } }; }
|
|
18
19
|
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; } }
|
|
19
20
|
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; }
|
|
20
|
-
var createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
|
|
21
|
-
return {
|
|
22
|
-
type: 'syncBlock',
|
|
23
|
-
attrs: {
|
|
24
|
-
localId: localId,
|
|
25
|
-
resourceId: resourceId
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
21
|
var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
30
22
|
function ReferenceSyncBlockStoreManager(dataProvider) {
|
|
31
23
|
(0, _classCallCheck2.default)(this, ReferenceSyncBlockStoreManager);
|
|
32
|
-
(0, _defineProperty2.default)(this, "isInitialized", false);
|
|
33
24
|
(0, _defineProperty2.default)(this, "isRefreshingSubscriptions", false);
|
|
34
25
|
this.syncBlockCache = new Map();
|
|
35
26
|
this.subscriptions = new Map();
|
|
36
27
|
this.dataProvider = dataProvider;
|
|
37
28
|
this.syncBlockURLRequests = new Map();
|
|
38
29
|
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Refreshes the subscriptions for all sync blocks.
|
|
33
|
+
* @returns {Promise<void>}
|
|
34
|
+
*/
|
|
39
35
|
return (0, _createClass2.default)(ReferenceSyncBlockStoreManager, [{
|
|
40
|
-
key: "init",
|
|
41
|
-
value: function () {
|
|
42
|
-
var _init = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(editorView) {
|
|
43
|
-
var _this = this;
|
|
44
|
-
var syncBlockNodes, dataResults;
|
|
45
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
46
|
-
while (1) switch (_context.prev = _context.next) {
|
|
47
|
-
case 0:
|
|
48
|
-
if (!(!this.editorView && !this.isInitialized)) {
|
|
49
|
-
_context.next = 15;
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
this.editorView = editorView;
|
|
53
|
-
syncBlockNodes = editorView.state.doc.children.filter(function (node) {
|
|
54
|
-
return node.type.name === 'syncBlock';
|
|
55
|
-
}).map(function (node) {
|
|
56
|
-
return node.toJSON();
|
|
57
|
-
}) || [];
|
|
58
|
-
if (!(syncBlockNodes.length > 0)) {
|
|
59
|
-
_context.next = 15;
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
_context.prev = 4;
|
|
63
|
-
_context.next = 7;
|
|
64
|
-
return this.fetchSyncBlocksData(syncBlockNodes);
|
|
65
|
-
case 7:
|
|
66
|
-
dataResults = _context.sent;
|
|
67
|
-
if (dataResults) {
|
|
68
|
-
_context.next = 10;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
throw new Error('No data results returned when initializing sync block store manager');
|
|
72
|
-
case 10:
|
|
73
|
-
dataResults.forEach(function (dataResult) {
|
|
74
|
-
_this.updateCache(dataResult);
|
|
75
|
-
});
|
|
76
|
-
_context.next = 15;
|
|
77
|
-
break;
|
|
78
|
-
case 13:
|
|
79
|
-
_context.prev = 13;
|
|
80
|
-
_context.t0 = _context["catch"](4);
|
|
81
|
-
case 15:
|
|
82
|
-
this.isInitialized = true;
|
|
83
|
-
case 16:
|
|
84
|
-
case "end":
|
|
85
|
-
return _context.stop();
|
|
86
|
-
}
|
|
87
|
-
}, _callee, this, [[4, 13]]);
|
|
88
|
-
}));
|
|
89
|
-
function init(_x) {
|
|
90
|
-
return _init.apply(this, arguments);
|
|
91
|
-
}
|
|
92
|
-
return init;
|
|
93
|
-
}()
|
|
94
|
-
/**
|
|
95
|
-
* Refreshes the subscriptions for all sync blocks.
|
|
96
|
-
* @returns {Promise<void>}
|
|
97
|
-
*/
|
|
98
|
-
}, {
|
|
99
36
|
key: "refreshSubscriptions",
|
|
100
37
|
value: (function () {
|
|
101
|
-
var _refreshSubscriptions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
38
|
+
var _refreshSubscriptions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
102
39
|
var syncBlocks, _iterator, _step, _loop;
|
|
103
|
-
return _regenerator.default.wrap(function
|
|
104
|
-
while (1) switch (
|
|
40
|
+
return _regenerator.default.wrap(function _callee$(_context2) {
|
|
41
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
105
42
|
case 0:
|
|
106
|
-
if (!
|
|
107
|
-
|
|
43
|
+
if (!this.isRefreshingSubscriptions) {
|
|
44
|
+
_context2.next = 2;
|
|
108
45
|
break;
|
|
109
46
|
}
|
|
110
|
-
return
|
|
47
|
+
return _context2.abrupt("return");
|
|
111
48
|
case 2:
|
|
112
49
|
this.isRefreshingSubscriptions = true;
|
|
113
50
|
syncBlocks = [];
|
|
114
51
|
_iterator = _createForOfIteratorHelper(this.subscriptions.entries());
|
|
115
|
-
|
|
52
|
+
_context2.prev = 5;
|
|
116
53
|
_loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
|
|
117
54
|
var _step$value, resourceId, callbacks;
|
|
118
|
-
return _regenerator.default.wrap(function _loop$(
|
|
119
|
-
while (1) switch (
|
|
55
|
+
return _regenerator.default.wrap(function _loop$(_context) {
|
|
56
|
+
while (1) switch (_context.prev = _context.next) {
|
|
120
57
|
case 0:
|
|
121
58
|
_step$value = (0, _slicedToArray2.default)(_step.value, 2), resourceId = _step$value[0], callbacks = _step$value[1];
|
|
122
59
|
Object.keys(callbacks).forEach(function (localId) {
|
|
123
|
-
syncBlocks.push(createSyncBlockNode(localId, resourceId));
|
|
60
|
+
syncBlocks.push((0, _createSyncBlock.createSyncBlockNode)(localId, resourceId));
|
|
124
61
|
});
|
|
125
62
|
case 2:
|
|
126
63
|
case "end":
|
|
127
|
-
return
|
|
64
|
+
return _context.stop();
|
|
128
65
|
}
|
|
129
66
|
}, _loop);
|
|
130
67
|
});
|
|
131
68
|
_iterator.s();
|
|
132
69
|
case 8:
|
|
133
70
|
if ((_step = _iterator.n()).done) {
|
|
134
|
-
|
|
71
|
+
_context2.next = 12;
|
|
135
72
|
break;
|
|
136
73
|
}
|
|
137
|
-
return
|
|
74
|
+
return _context2.delegateYield(_loop(), "t0", 10);
|
|
138
75
|
case 10:
|
|
139
|
-
|
|
76
|
+
_context2.next = 8;
|
|
140
77
|
break;
|
|
141
78
|
case 12:
|
|
142
|
-
|
|
79
|
+
_context2.next = 17;
|
|
143
80
|
break;
|
|
144
81
|
case 14:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
_iterator.e(
|
|
82
|
+
_context2.prev = 14;
|
|
83
|
+
_context2.t1 = _context2["catch"](5);
|
|
84
|
+
_iterator.e(_context2.t1);
|
|
148
85
|
case 17:
|
|
149
|
-
|
|
86
|
+
_context2.prev = 17;
|
|
150
87
|
_iterator.f();
|
|
151
|
-
return
|
|
88
|
+
return _context2.finish(17);
|
|
152
89
|
case 20:
|
|
153
|
-
|
|
154
|
-
|
|
90
|
+
_context2.prev = 20;
|
|
91
|
+
_context2.next = 23;
|
|
155
92
|
return this.fetchSyncBlocksData(syncBlocks);
|
|
156
93
|
case 23:
|
|
157
|
-
|
|
94
|
+
_context2.next = 27;
|
|
158
95
|
break;
|
|
159
96
|
case 25:
|
|
160
|
-
|
|
161
|
-
|
|
97
|
+
_context2.prev = 25;
|
|
98
|
+
_context2.t2 = _context2["catch"](20);
|
|
162
99
|
case 27:
|
|
163
|
-
|
|
100
|
+
_context2.prev = 27;
|
|
164
101
|
this.isRefreshingSubscriptions = false;
|
|
165
|
-
return
|
|
102
|
+
return _context2.finish(27);
|
|
166
103
|
case 30:
|
|
167
104
|
case "end":
|
|
168
|
-
return
|
|
105
|
+
return _context2.stop();
|
|
169
106
|
}
|
|
170
|
-
},
|
|
107
|
+
}, _callee, this, [[5, 14, 17, 20], [20, 25, 27, 30]]);
|
|
171
108
|
}));
|
|
172
109
|
function refreshSubscriptions() {
|
|
173
110
|
return _refreshSubscriptions.apply(this, arguments);
|
|
@@ -177,7 +114,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
177
114
|
}, {
|
|
178
115
|
key: "fetchSyncBlockSourceURL",
|
|
179
116
|
value: function fetchSyncBlockSourceURL(resourceId) {
|
|
180
|
-
var
|
|
117
|
+
var _this = this;
|
|
181
118
|
if (!resourceId || !this.dataProvider) {
|
|
182
119
|
return;
|
|
183
120
|
}
|
|
@@ -186,111 +123,68 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
186
123
|
// we could optimise this further by checking if the sync block is on the same page as the source
|
|
187
124
|
if (!this.syncBlockURLRequests.get(resourceId)) {
|
|
188
125
|
this.syncBlockURLRequests.set(resourceId, true);
|
|
189
|
-
this.dataProvider.retrieveSyncBlockSourceUrl(createSyncBlockNode('', resourceId)).then(function (sourceURL) {
|
|
190
|
-
var existingSyncBlock =
|
|
126
|
+
this.dataProvider.retrieveSyncBlockSourceUrl((0, _createSyncBlock.createSyncBlockNode)('', resourceId)).then(function (sourceURL) {
|
|
127
|
+
var existingSyncBlock = _this.getFromCache(resourceId);
|
|
191
128
|
if (existingSyncBlock && existingSyncBlock.data) {
|
|
192
129
|
existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
|
|
193
130
|
sourceURL: sourceURL
|
|
194
131
|
});
|
|
195
|
-
|
|
132
|
+
_this.updateCache(existingSyncBlock);
|
|
196
133
|
}
|
|
197
134
|
}).finally(function () {
|
|
198
|
-
|
|
135
|
+
_this.syncBlockURLRequests.set(resourceId, false);
|
|
199
136
|
});
|
|
200
137
|
}
|
|
201
138
|
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Fetch sync block data for a given sync block node.
|
|
205
|
-
* @param syncBlockNode - The sync block node to fetch data for
|
|
206
|
-
* @returns The fetched sync block data result
|
|
207
|
-
*/
|
|
208
|
-
}, {
|
|
209
|
-
key: "fetchSyncBlockData",
|
|
210
|
-
value: (function () {
|
|
211
|
-
var _fetchSyncBlockData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(syncBlockNode) {
|
|
212
|
-
var syncNode, data;
|
|
213
|
-
return _regenerator.default.wrap(function _callee3$(_context4) {
|
|
214
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
215
|
-
case 0:
|
|
216
|
-
if (this.dataProvider) {
|
|
217
|
-
_context4.next = 2;
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
throw new Error('Data provider not set');
|
|
221
|
-
case 2:
|
|
222
|
-
syncNode = createSyncBlockNode(syncBlockNode.attrs.localId, syncBlockNode.attrs.resourceId);
|
|
223
|
-
_context4.next = 5;
|
|
224
|
-
return this.fetchSyncBlocksData([syncNode]);
|
|
225
|
-
case 5:
|
|
226
|
-
data = _context4.sent;
|
|
227
|
-
if (!(!data || data.length === 0)) {
|
|
228
|
-
_context4.next = 8;
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
throw new Error('Failed to fetch sync block data');
|
|
232
|
-
case 8:
|
|
233
|
-
return _context4.abrupt("return", data[0]);
|
|
234
|
-
case 9:
|
|
235
|
-
case "end":
|
|
236
|
-
return _context4.stop();
|
|
237
|
-
}
|
|
238
|
-
}, _callee3, this);
|
|
239
|
-
}));
|
|
240
|
-
function fetchSyncBlockData(_x2) {
|
|
241
|
-
return _fetchSyncBlockData.apply(this, arguments);
|
|
242
|
-
}
|
|
243
|
-
return fetchSyncBlockData;
|
|
244
|
-
}())
|
|
245
139
|
}, {
|
|
246
140
|
key: "fetchSyncBlocksData",
|
|
247
141
|
value: function () {
|
|
248
|
-
var _fetchSyncBlocksData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
249
|
-
var
|
|
142
|
+
var _fetchSyncBlocksData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockNodes) {
|
|
143
|
+
var _this2 = this;
|
|
250
144
|
var data, resolvedData;
|
|
251
|
-
return _regenerator.default.wrap(function
|
|
252
|
-
while (1) switch (
|
|
145
|
+
return _regenerator.default.wrap(function _callee2$(_context3) {
|
|
146
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
253
147
|
case 0:
|
|
254
148
|
if (this.dataProvider) {
|
|
255
|
-
|
|
149
|
+
_context3.next = 2;
|
|
256
150
|
break;
|
|
257
151
|
}
|
|
258
152
|
throw new Error('Data provider not set');
|
|
259
153
|
case 2:
|
|
260
|
-
|
|
154
|
+
_context3.next = 4;
|
|
261
155
|
return this.dataProvider.fetchNodesData(syncBlockNodes);
|
|
262
156
|
case 4:
|
|
263
|
-
data =
|
|
157
|
+
data = _context3.sent;
|
|
264
158
|
if (data) {
|
|
265
|
-
|
|
159
|
+
_context3.next = 7;
|
|
266
160
|
break;
|
|
267
161
|
}
|
|
268
162
|
throw new Error('Failed to fetch sync block node data');
|
|
269
163
|
case 7:
|
|
270
164
|
resolvedData = [];
|
|
271
|
-
data.forEach(function (
|
|
272
|
-
var
|
|
273
|
-
if (!
|
|
165
|
+
data.forEach(function (syncBlockInstance) {
|
|
166
|
+
var _resolvedSyncBlockIns;
|
|
167
|
+
if (!syncBlockInstance.resourceId) {
|
|
274
168
|
return;
|
|
275
169
|
}
|
|
276
|
-
var existingSyncBlock =
|
|
277
|
-
var
|
|
278
|
-
|
|
279
|
-
resolvedData.push(
|
|
170
|
+
var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
|
|
171
|
+
var resolvedSyncBlockInstance = existingSyncBlock ? (0, _resolveSyncBlockInstance.resolveSyncBlockInstance)(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
172
|
+
_this2.updateCache(resolvedSyncBlockInstance);
|
|
173
|
+
resolvedData.push(resolvedSyncBlockInstance);
|
|
280
174
|
|
|
281
175
|
// fetch source URL if not already present
|
|
282
|
-
if (!((
|
|
283
|
-
|
|
176
|
+
if (!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) && resolvedSyncBlockInstance.resourceId) {
|
|
177
|
+
_this2.fetchSyncBlockSourceURL(resolvedSyncBlockInstance.resourceId);
|
|
284
178
|
}
|
|
285
179
|
});
|
|
286
|
-
return
|
|
180
|
+
return _context3.abrupt("return", resolvedData);
|
|
287
181
|
case 10:
|
|
288
182
|
case "end":
|
|
289
|
-
return
|
|
183
|
+
return _context3.stop();
|
|
290
184
|
}
|
|
291
|
-
},
|
|
185
|
+
}, _callee2, this);
|
|
292
186
|
}));
|
|
293
|
-
function fetchSyncBlocksData(
|
|
187
|
+
function fetchSyncBlocksData(_x) {
|
|
294
188
|
return _fetchSyncBlocksData.apply(this, arguments);
|
|
295
189
|
}
|
|
296
190
|
return fetchSyncBlocksData;
|
|
@@ -322,7 +216,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
322
216
|
}, {
|
|
323
217
|
key: "subscribe",
|
|
324
218
|
value: function subscribe(node, callback) {
|
|
325
|
-
var
|
|
219
|
+
var _this3 = this;
|
|
326
220
|
// check node is a sync block, as we only support sync block subscriptions
|
|
327
221
|
if (node.type.name !== 'syncBlock') {
|
|
328
222
|
return function () {};
|
|
@@ -343,17 +237,17 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
343
237
|
if (cachedData) {
|
|
344
238
|
callback(cachedData);
|
|
345
239
|
} else {
|
|
346
|
-
this.
|
|
240
|
+
this.fetchSyncBlocksData([(0, _createSyncBlock.createSyncBlockNode)(localId, resourceId)]).catch(function () {});
|
|
347
241
|
}
|
|
348
242
|
return function () {
|
|
349
|
-
var resourceSubscriptions =
|
|
243
|
+
var resourceSubscriptions = _this3.subscriptions.get(resourceId);
|
|
350
244
|
if (resourceSubscriptions) {
|
|
351
245
|
delete resourceSubscriptions[localId];
|
|
352
246
|
if (Object.keys(resourceSubscriptions).length === 0) {
|
|
353
|
-
|
|
354
|
-
|
|
247
|
+
_this3.subscriptions.delete(resourceId);
|
|
248
|
+
_this3.deleteFromCache(resourceId);
|
|
355
249
|
} else {
|
|
356
|
-
|
|
250
|
+
_this3.subscriptions.set(resourceId, resourceSubscriptions);
|
|
357
251
|
}
|
|
358
252
|
}
|
|
359
253
|
};
|
|
@@ -380,8 +274,6 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
380
274
|
this.syncBlockCache.clear();
|
|
381
275
|
this.subscriptions.clear();
|
|
382
276
|
this.syncBlockURLRequests.clear();
|
|
383
|
-
this.editorView = undefined;
|
|
384
|
-
this.isInitialized = false;
|
|
385
277
|
}
|
|
386
278
|
}]);
|
|
387
279
|
}();
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.SyncBlockStoreManager = void 0;
|
|
8
8
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _createSyncBlock = require("../utils/createSyncBlock");
|
|
10
11
|
var _referenceSyncBlockStoreManager = require("./referenceSyncBlockStoreManager");
|
|
11
12
|
var _sourceSyncBlockStoreManager = require("./sourceSyncBlockStoreManager");
|
|
12
13
|
// A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
|
|
@@ -22,20 +23,22 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
|
-
* Fetch sync block data for a given sync block
|
|
26
|
-
* @param
|
|
27
|
-
* @returns The fetched sync block data
|
|
26
|
+
* Fetch sync block data for a given array of sync block nodes.
|
|
27
|
+
* @param nodes - The array of sync block nodes to fetch data for
|
|
28
|
+
* @returns The fetched sync block data results
|
|
28
29
|
*/
|
|
29
30
|
return (0, _createClass2.default)(SyncBlockStoreManager, [{
|
|
30
|
-
key: "
|
|
31
|
-
value: function
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
key: "fetchSyncBlocksData",
|
|
32
|
+
value: function fetchSyncBlocksData(nodes) {
|
|
33
|
+
var syncBlockNodes = nodes.filter(function (node) {
|
|
34
|
+
return node.type.name === 'syncBlock' && node.attrs.resourceId && node.attrs.localId;
|
|
35
|
+
}).map(function (node) {
|
|
36
|
+
return (0, _createSyncBlock.createSyncBlockNode)(node.attrs.localId, node.attrs.resourceId);
|
|
37
|
+
}) || [];
|
|
38
|
+
if (syncBlockNodes.length === 0) {
|
|
39
|
+
return Promise.resolve([]);
|
|
34
40
|
}
|
|
35
|
-
|
|
36
|
-
return Promise.reject(new Error('Invalid sync block node type provided for fetchSyncBlockData'));
|
|
37
|
-
}
|
|
38
|
-
return this.referenceSyncBlockStoreManager.fetchSyncBlockData(syncBlockNode);
|
|
41
|
+
return this.referenceSyncBlockStoreManager.fetchSyncBlocksData(syncBlockNodes);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/**
|
|
@@ -79,9 +82,6 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
79
82
|
key: "setEditorView",
|
|
80
83
|
value: function setEditorView(editorView) {
|
|
81
84
|
this.sourceSyncBlockStoreManager.setEditorView(editorView);
|
|
82
|
-
if (editorView) {
|
|
83
|
-
this.referenceSyncBlockStoreManager.init(editorView);
|
|
84
|
-
}
|
|
85
85
|
}
|
|
86
86
|
}, {
|
|
87
87
|
key: "isSourceBlock",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSyncBlockNode = void 0;
|
|
7
|
+
var createSyncBlockNode = exports.createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
|
|
8
|
+
return {
|
|
9
|
+
type: 'syncBlock',
|
|
10
|
+
attrs: {
|
|
11
|
+
localId: localId,
|
|
12
|
+
resourceId: resourceId
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -4,21 +4,21 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.resolveSyncBlockInstance = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
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; }
|
|
10
10
|
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) { (0, _defineProperty2.default)(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; }
|
|
11
11
|
/**
|
|
12
|
-
* Merges two
|
|
12
|
+
* Merges two SyncBlockInstance objects,
|
|
13
13
|
* currently it only preserves the sourceURL from the old result,
|
|
14
14
|
* but this can be extended in the future to preserve other fields and resolve conflicts as needed.
|
|
15
15
|
* e.g. compare timestamps or version numbers to determine which data is more recent.
|
|
16
16
|
*
|
|
17
|
-
* @param oldResult - The existing
|
|
18
|
-
* @param newResult - The new
|
|
19
|
-
* @returns A merged
|
|
17
|
+
* @param oldResult - The existing SyncBlockInstance object.
|
|
18
|
+
* @param newResult - The new SyncBlockInstance object to merge.
|
|
19
|
+
* @returns A merged SyncBlockInstance object.
|
|
20
20
|
*/
|
|
21
|
-
var
|
|
21
|
+
var resolveSyncBlockInstance = exports.resolveSyncBlockInstance = function resolveSyncBlockInstance(oldResult, newResult) {
|
|
22
22
|
var _newResult$data, _oldResult$data;
|
|
23
23
|
// if the old result has no data, we simple return the new result
|
|
24
24
|
if (!oldResult.data) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
export const SYNC_BLOCK_FETCH_INTERVAL = 3000;
|
|
3
3
|
export const useFetchSyncBlockData = (manager, syncBlockNode) => {
|
|
4
|
-
const [
|
|
4
|
+
const [syncBlockInstance, setSyncBlockInstance] = useState(null);
|
|
5
5
|
useEffect(() => {
|
|
6
6
|
const unsubscribe = manager.subscribeToSyncBlockData(syncBlockNode, data => {
|
|
7
|
-
|
|
7
|
+
setSyncBlockInstance(data);
|
|
8
8
|
});
|
|
9
9
|
return () => {
|
|
10
10
|
unsubscribe();
|
|
11
11
|
};
|
|
12
|
-
}, [manager,
|
|
13
|
-
return
|
|
12
|
+
}, [manager, syncBlockNode]);
|
|
13
|
+
return syncBlockInstance;
|
|
14
14
|
};
|
package/dist/es2019/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';
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { NodeDataProvider } from '@atlaskit/node-data-provider';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The instance of a sync block, containing its data and metadata.
|
|
5
|
+
* Mainly used for representing the state of a sync block after fetching from a data provider.
|
|
6
|
+
* This will be used in both data processing and rendering contexts.
|
|
7
|
+
*/
|
|
8
|
+
|
|
2
9
|
export class SyncBlockDataProvider extends NodeDataProvider {}
|