@atlaskit/editor-synced-block-provider 2.5.2 → 2.7.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 +15 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +60 -6
- package/dist/cjs/index.js +24 -5
- package/dist/cjs/providers/confluence/confluenceContentAPI.js +86 -73
- package/dist/cjs/providers/syncBlockProvider.js +60 -36
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +24 -20
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +78 -17
- package/dist/cjs/store-manager/syncBlockStoreManager.js +46 -8
- package/dist/cjs/utils/errorHandling.js +13 -0
- package/dist/cjs/utils/utils.js +32 -1
- package/dist/es2019/hooks/useFetchSyncBlockData.js +35 -6
- package/dist/es2019/index.js +7 -6
- package/dist/es2019/providers/confluence/confluenceContentAPI.js +62 -40
- package/dist/es2019/providers/syncBlockProvider.js +15 -9
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +16 -14
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +64 -12
- package/dist/es2019/store-manager/syncBlockStoreManager.js +34 -8
- package/dist/es2019/utils/errorHandling.js +7 -0
- package/dist/es2019/utils/utils.js +31 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +60 -6
- package/dist/esm/index.js +7 -6
- package/dist/esm/providers/confluence/confluenceContentAPI.js +79 -66
- package/dist/esm/providers/syncBlockProvider.js +60 -36
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +21 -17
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +79 -18
- package/dist/esm/store-manager/syncBlockStoreManager.js +46 -8
- package/dist/esm/utils/errorHandling.js +7 -0
- package/dist/esm/utils/utils.js +31 -0
- package/dist/types/common/schema.d.ts +1 -1
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +6 -3
- package/dist/types/index.d.ts +10 -9
- package/dist/types/providers/confluence/confluenceContentAPI.d.ts +2 -2
- package/dist/types/providers/syncBlockProvider.d.ts +4 -3
- package/dist/types/providers/types.d.ts +6 -2
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +2 -1
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +15 -3
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +22 -3
- package/dist/types/utils/errorHandling.d.ts +1 -0
- package/dist/types/utils/utils.d.ts +6 -1
- package/dist/types-ts4.5/common/schema.d.ts +1 -1
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +6 -3
- package/dist/types-ts4.5/index.d.ts +10 -9
- package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +2 -2
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +4 -3
- package/dist/types-ts4.5/providers/types.d.ts +6 -2
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +2 -1
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +15 -3
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +22 -3
- package/dist/types-ts4.5/utils/errorHandling.d.ts +1 -0
- package/dist/types-ts4.5/utils/utils.d.ts +6 -1
- package/package.json +2 -2
- package/dist/cjs/utils/createSyncBlock.js +0 -15
- package/dist/es2019/utils/createSyncBlock.js +0 -9
- package/dist/esm/utils/createSyncBlock.js +0 -9
- package/dist/types/utils/createSyncBlock.d.ts +0 -2
- package/dist/types-ts4.5/utils/createSyncBlock.d.ts +0 -2
|
@@ -66,39 +66,63 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
66
66
|
* @param nodes
|
|
67
67
|
* @param data
|
|
68
68
|
*
|
|
69
|
-
* @returns
|
|
69
|
+
* @returns Array of {resourceId?: string, error?: string}.
|
|
70
|
+
* resourceId: resource id of the node if write successfully , error: reason for when write failed
|
|
70
71
|
*/
|
|
71
72
|
}, {
|
|
72
73
|
key: "writeNodesData",
|
|
73
|
-
value: function
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
value: (function () {
|
|
75
|
+
var _writeNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(nodes, data) {
|
|
76
|
+
var _this3 = this;
|
|
77
|
+
var results;
|
|
78
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
79
|
+
while (1) switch (_context.prev = _context.next) {
|
|
80
|
+
case 0:
|
|
81
|
+
_context.next = 2;
|
|
82
|
+
return Promise.allSettled(nodes.map(function (_node, index) {
|
|
83
|
+
if (!data[index].content) {
|
|
84
|
+
return Promise.reject('No Synced Block content to write');
|
|
85
|
+
}
|
|
86
|
+
return _this3.writeProvider.writeData(data[index]);
|
|
87
|
+
}));
|
|
88
|
+
case 2:
|
|
89
|
+
results = _context.sent;
|
|
90
|
+
return _context.abrupt("return", results.map(function (result) {
|
|
91
|
+
if (result.status === 'fulfilled') {
|
|
92
|
+
return result.value;
|
|
93
|
+
} else {
|
|
94
|
+
return {
|
|
95
|
+
error: result.reason
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
case 4:
|
|
100
|
+
case "end":
|
|
101
|
+
return _context.stop();
|
|
102
|
+
}
|
|
103
|
+
}, _callee);
|
|
104
|
+
}));
|
|
105
|
+
function writeNodesData(_x, _x2) {
|
|
106
|
+
return _writeNodesData.apply(this, arguments);
|
|
107
|
+
}
|
|
108
|
+
return writeNodesData;
|
|
109
|
+
}())
|
|
86
110
|
}, {
|
|
87
111
|
key: "deleteNodesData",
|
|
88
112
|
value: function () {
|
|
89
|
-
var _deleteNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
113
|
+
var _deleteNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceIds) {
|
|
90
114
|
var _this4 = this;
|
|
91
115
|
var results;
|
|
92
|
-
return _regeneratorRuntime.wrap(function
|
|
93
|
-
while (1) switch (
|
|
116
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
117
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
94
118
|
case 0:
|
|
95
|
-
|
|
119
|
+
_context2.next = 2;
|
|
96
120
|
return Promise.allSettled(resourceIds.map(function (resourceId) {
|
|
97
121
|
return _this4.writeProvider.deleteData(resourceId);
|
|
98
122
|
}));
|
|
99
123
|
case 2:
|
|
100
|
-
results =
|
|
101
|
-
return
|
|
124
|
+
results = _context2.sent;
|
|
125
|
+
return _context2.abrupt("return", results.map(function (result, index) {
|
|
102
126
|
if (result.status === 'fulfilled') {
|
|
103
127
|
return result.value;
|
|
104
128
|
} else {
|
|
@@ -111,11 +135,11 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
111
135
|
}));
|
|
112
136
|
case 4:
|
|
113
137
|
case "end":
|
|
114
|
-
return
|
|
138
|
+
return _context2.stop();
|
|
115
139
|
}
|
|
116
|
-
},
|
|
140
|
+
}, _callee2);
|
|
117
141
|
}));
|
|
118
|
-
function deleteNodesData(
|
|
142
|
+
function deleteNodesData(_x3) {
|
|
119
143
|
return _deleteNodesData.apply(this, arguments);
|
|
120
144
|
}
|
|
121
145
|
return deleteNodesData;
|
|
@@ -153,12 +177,12 @@ export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvi
|
|
|
153
177
|
}, [fetchProvider, writeProvider, sourceId]);
|
|
154
178
|
};
|
|
155
179
|
var fetchURLandTitlefromARI = /*#__PURE__*/function () {
|
|
156
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
180
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(ari, sourceLocalId) {
|
|
157
181
|
var response, _payload$data, _payload$data2, payload, url, title;
|
|
158
|
-
return _regeneratorRuntime.wrap(function
|
|
159
|
-
while (1) switch (
|
|
182
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
183
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
160
184
|
case 0:
|
|
161
|
-
|
|
185
|
+
_context3.next = 2;
|
|
162
186
|
return fetch('/gateway/api/object-resolver/resolve/ari', {
|
|
163
187
|
method: 'POST',
|
|
164
188
|
headers: {
|
|
@@ -170,18 +194,18 @@ var fetchURLandTitlefromARI = /*#__PURE__*/function () {
|
|
|
170
194
|
})
|
|
171
195
|
});
|
|
172
196
|
case 2:
|
|
173
|
-
response =
|
|
197
|
+
response = _context3.sent;
|
|
174
198
|
if (!response.ok) {
|
|
175
|
-
|
|
199
|
+
_context3.next = 12;
|
|
176
200
|
break;
|
|
177
201
|
}
|
|
178
|
-
|
|
202
|
+
_context3.next = 6;
|
|
179
203
|
return response.json();
|
|
180
204
|
case 6:
|
|
181
|
-
payload =
|
|
205
|
+
payload = _context3.sent;
|
|
182
206
|
url = payload === null || payload === void 0 || (_payload$data = payload.data) === null || _payload$data === void 0 ? void 0 : _payload$data.url;
|
|
183
207
|
title = payload === null || payload === void 0 || (_payload$data2 = payload.data) === null || _payload$data2 === void 0 ? void 0 : _payload$data2.name;
|
|
184
|
-
return
|
|
208
|
+
return _context3.abrupt("return", {
|
|
185
209
|
url: typeof url === 'string' ? sourceLocalId ? url + "?block=".concat(sourceLocalId) : url : undefined,
|
|
186
210
|
title: typeof title === 'string' ? title : undefined
|
|
187
211
|
});
|
|
@@ -189,14 +213,14 @@ var fetchURLandTitlefromARI = /*#__PURE__*/function () {
|
|
|
189
213
|
//eslint-disable-next-line no-console
|
|
190
214
|
console.error('Failed to fetch URL and title from ARI', response.statusText);
|
|
191
215
|
case 13:
|
|
192
|
-
return
|
|
216
|
+
return _context3.abrupt("return", undefined);
|
|
193
217
|
case 14:
|
|
194
218
|
case "end":
|
|
195
|
-
return
|
|
219
|
+
return _context3.stop();
|
|
196
220
|
}
|
|
197
|
-
},
|
|
221
|
+
}, _callee3);
|
|
198
222
|
}));
|
|
199
|
-
return function fetchURLandTitlefromARI(
|
|
223
|
+
return function fetchURLandTitlefromARI(_x4, _x5) {
|
|
200
224
|
return _ref.apply(this, arguments);
|
|
201
225
|
};
|
|
202
226
|
}();
|
|
@@ -9,8 +9,8 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
9
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; } } }; }
|
|
10
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; } }
|
|
11
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; }
|
|
12
|
-
import { createSyncBlockNode } from '../utils/createSyncBlock';
|
|
13
12
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
13
|
+
import { createSyncBlockNode } from '../utils/utils';
|
|
14
14
|
export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
15
15
|
function ReferenceSyncBlockStoreManager(dataProvider) {
|
|
16
16
|
_classCallCheck(this, ReferenceSyncBlockStoreManager);
|
|
@@ -222,20 +222,9 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
222
222
|
this.syncBlockCache.delete(resourceId);
|
|
223
223
|
}
|
|
224
224
|
}, {
|
|
225
|
-
key: "
|
|
226
|
-
value: function
|
|
225
|
+
key: "subscribeToSyncBlock",
|
|
226
|
+
value: function subscribeToSyncBlock(resourceId, localId, callback) {
|
|
227
227
|
var _this3 = this;
|
|
228
|
-
// check node is a sync block, as we only support sync block subscriptions
|
|
229
|
-
if (node.type.name !== 'syncBlock') {
|
|
230
|
-
return function () {};
|
|
231
|
-
}
|
|
232
|
-
var _node$attrs = node.attrs,
|
|
233
|
-
resourceId = _node$attrs.resourceId,
|
|
234
|
-
localId = _node$attrs.localId;
|
|
235
|
-
if (!localId || !resourceId) {
|
|
236
|
-
return function () {};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
228
|
// add to subscriptions map
|
|
240
229
|
var resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
241
230
|
this.subscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
|
|
@@ -269,9 +258,9 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
269
258
|
if (node.type.name !== 'syncBlock') {
|
|
270
259
|
return function () {};
|
|
271
260
|
}
|
|
272
|
-
var _node$
|
|
273
|
-
resourceId = _node$
|
|
274
|
-
localId = _node$
|
|
261
|
+
var _node$attrs = node.attrs,
|
|
262
|
+
resourceId = _node$attrs.resourceId,
|
|
263
|
+
localId = _node$attrs.localId;
|
|
275
264
|
if (!localId || !resourceId) {
|
|
276
265
|
return function () {};
|
|
277
266
|
}
|
|
@@ -295,6 +284,21 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
295
284
|
}
|
|
296
285
|
};
|
|
297
286
|
}
|
|
287
|
+
}, {
|
|
288
|
+
key: "subscribe",
|
|
289
|
+
value: function subscribe(node, callback) {
|
|
290
|
+
// check node is a sync block, as we only support sync block subscriptions
|
|
291
|
+
if (node.type.name !== 'syncBlock') {
|
|
292
|
+
return function () {};
|
|
293
|
+
}
|
|
294
|
+
var _node$attrs2 = node.attrs,
|
|
295
|
+
resourceId = _node$attrs2.resourceId,
|
|
296
|
+
localId = _node$attrs2.localId;
|
|
297
|
+
if (!localId || !resourceId) {
|
|
298
|
+
return function () {};
|
|
299
|
+
}
|
|
300
|
+
return this.subscribeToSyncBlock(resourceId, localId, callback);
|
|
301
|
+
}
|
|
298
302
|
|
|
299
303
|
/**
|
|
300
304
|
* Get the URL for a sync block.
|
|
@@ -5,7 +5,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
5
5
|
import uuid from 'uuid';
|
|
6
6
|
import { rebaseTransaction as _rebaseTransaction } from '../common/rebase-transaction';
|
|
7
7
|
import { resourceIdFromSourceAndLocalId } from '../utils/ari';
|
|
8
|
-
import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
8
|
+
import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode as _createBodiedSyncBlockNode } from '../utils/utils';
|
|
9
9
|
export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
10
10
|
function SourceSyncBlockStoreManager(dataProvider) {
|
|
11
11
|
_classCallCheck(this, SourceSyncBlockStoreManager);
|
|
@@ -40,7 +40,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
40
40
|
key: "flushBodiedSyncBlocks",
|
|
41
41
|
value: (function () {
|
|
42
42
|
var _flushBodiedSyncBlocks = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
43
|
-
var bodiedSyncBlockNodes, bodiedSyncBlockData,
|
|
43
|
+
var bodiedSyncBlockNodes, bodiedSyncBlockData, writeResults;
|
|
44
44
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
45
45
|
while (1) switch (_context.prev = _context.next) {
|
|
46
46
|
case 0:
|
|
@@ -72,9 +72,9 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
72
72
|
_context.next = 10;
|
|
73
73
|
return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
74
74
|
case 10:
|
|
75
|
-
|
|
76
|
-
return _context.abrupt("return",
|
|
77
|
-
return resourceId !== undefined;
|
|
75
|
+
writeResults = _context.sent;
|
|
76
|
+
return _context.abrupt("return", writeResults.every(function (result) {
|
|
77
|
+
return result.resourceId !== undefined;
|
|
78
78
|
}));
|
|
79
79
|
case 14:
|
|
80
80
|
_context.prev = 14;
|
|
@@ -96,6 +96,35 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
96
96
|
value: function setEditorView(editorView) {
|
|
97
97
|
this.editorView = editorView;
|
|
98
98
|
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "registerPendingCreation",
|
|
101
|
+
value: function registerPendingCreation(resourceId) {
|
|
102
|
+
this.pendingResourceId = resourceId;
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "registerCreationCallback",
|
|
106
|
+
value: function registerCreationCallback(callback) {
|
|
107
|
+
this.creationCallback = callback;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Fires callback to insert node (if creation is successful) and clears pending creation data
|
|
112
|
+
* @param success
|
|
113
|
+
*/
|
|
114
|
+
}, {
|
|
115
|
+
key: "commitPendingCreation",
|
|
116
|
+
value: function commitPendingCreation(success) {
|
|
117
|
+
if (success && this.creationCallback) {
|
|
118
|
+
this.creationCallback();
|
|
119
|
+
}
|
|
120
|
+
this.pendingResourceId = undefined;
|
|
121
|
+
this.creationCallback = undefined;
|
|
122
|
+
}
|
|
123
|
+
}, {
|
|
124
|
+
key: "hasPendingCreation",
|
|
125
|
+
value: function hasPendingCreation() {
|
|
126
|
+
return !!this.pendingResourceId;
|
|
127
|
+
}
|
|
99
128
|
}, {
|
|
100
129
|
key: "registerConfirmationCallback",
|
|
101
130
|
value: function registerConfirmationCallback(callback) {
|
|
@@ -111,31 +140,63 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
111
140
|
return !!this.confirmationCallback;
|
|
112
141
|
}
|
|
113
142
|
}, {
|
|
114
|
-
key: "
|
|
115
|
-
value: function
|
|
143
|
+
key: "generateBodiedSyncBlockAttrs",
|
|
144
|
+
value: function generateBodiedSyncBlockAttrs() {
|
|
116
145
|
var _this$dataProvider;
|
|
117
|
-
var
|
|
146
|
+
var localId = uuid();
|
|
118
147
|
var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
119
148
|
if (!sourceId) {
|
|
120
149
|
throw new Error('Provider of sync block plugin is not set');
|
|
121
150
|
}
|
|
122
151
|
|
|
123
152
|
// This should be generated by the data provider implementation as it differs between data providers
|
|
124
|
-
var resourceId = resourceIdFromSourceAndLocalId(sourceId,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
localId: blockInstanceId
|
|
129
|
-
},
|
|
130
|
-
type: 'bodiedSyncBlock'
|
|
153
|
+
var resourceId = resourceIdFromSourceAndLocalId(sourceId, localId);
|
|
154
|
+
return {
|
|
155
|
+
resourceId: resourceId,
|
|
156
|
+
localId: localId
|
|
131
157
|
};
|
|
132
|
-
|
|
158
|
+
}
|
|
159
|
+
}, {
|
|
160
|
+
key: "createBodiedSyncBlockNode",
|
|
161
|
+
value: function createBodiedSyncBlockNode(attrs) {
|
|
162
|
+
var _this2 = this;
|
|
163
|
+
try {
|
|
164
|
+
if (!this.dataProvider) {
|
|
165
|
+
throw new Error('Data provider not set');
|
|
166
|
+
}
|
|
167
|
+
var resourceId = attrs.resourceId,
|
|
168
|
+
blockInstanceId = attrs.localId;
|
|
169
|
+
this.dataProvider.writeNodesData([_createBodiedSyncBlockNode(blockInstanceId, resourceId)], [{
|
|
170
|
+
content: [],
|
|
171
|
+
blockInstanceId: blockInstanceId,
|
|
172
|
+
resourceId: resourceId
|
|
173
|
+
}]).then(function (results) {
|
|
174
|
+
results.forEach(function (result) {
|
|
175
|
+
var resourceId = result.resourceId;
|
|
176
|
+
if (resourceId) {
|
|
177
|
+
_this2.commitPendingCreation(true);
|
|
178
|
+
} else {
|
|
179
|
+
_this2.commitPendingCreation(false);
|
|
180
|
+
// TODO: EDITOR-1921 - add error analytics
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}).catch(function (_reason) {
|
|
184
|
+
_this2.commitPendingCreation(false);
|
|
185
|
+
// TODO: EDITOR-1921 - add error analytics
|
|
186
|
+
});
|
|
187
|
+
this.registerPendingCreation(resourceId);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (this.hasPendingCreation()) {
|
|
190
|
+
this.commitPendingCreation(false);
|
|
191
|
+
}
|
|
192
|
+
// TODO: EDITOR-1921 - add error analytics
|
|
193
|
+
}
|
|
133
194
|
}
|
|
134
195
|
}, {
|
|
135
196
|
key: "deleteSyncBlocksWithConfirmation",
|
|
136
197
|
value: function () {
|
|
137
198
|
var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(tr, syncBlockIds) {
|
|
138
|
-
var
|
|
199
|
+
var _this3 = this;
|
|
139
200
|
var confirmed, _this$editorView, results;
|
|
140
201
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
141
202
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -170,7 +231,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
170
231
|
results.forEach(function (result) {
|
|
171
232
|
if (result.success) {
|
|
172
233
|
// Only delete when it's deleted successfully in backend
|
|
173
|
-
|
|
234
|
+
_this3.syncBlockCache.delete(result.resourceId);
|
|
174
235
|
} else {
|
|
175
236
|
// TODO: EDITOR-1921 - add error analytics with result.error
|
|
176
237
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import {
|
|
3
|
+
import { convertPMNodeToSyncBlockNode } from '../utils/utils';
|
|
4
4
|
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
5
5
|
import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
|
6
6
|
|
|
@@ -24,16 +24,21 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
24
24
|
return _createClass(SyncBlockStoreManager, [{
|
|
25
25
|
key: "fetchSyncBlocksData",
|
|
26
26
|
value: function fetchSyncBlocksData(nodes) {
|
|
27
|
-
var syncBlockNodes = nodes.
|
|
28
|
-
return node
|
|
29
|
-
}).
|
|
30
|
-
return
|
|
27
|
+
var syncBlockNodes = nodes.map(function (node) {
|
|
28
|
+
return convertPMNodeToSyncBlockNode(node);
|
|
29
|
+
}).filter(function (node) {
|
|
30
|
+
return node !== undefined;
|
|
31
31
|
}) || [];
|
|
32
32
|
if (syncBlockNodes.length === 0) {
|
|
33
33
|
return Promise.resolve([]);
|
|
34
34
|
}
|
|
35
35
|
return this.referenceSyncBlockStoreManager.fetchSyncBlocksData(syncBlockNodes);
|
|
36
36
|
}
|
|
37
|
+
}, {
|
|
38
|
+
key: "getReferenceSyncBlockStoreManager",
|
|
39
|
+
value: function getReferenceSyncBlockStoreManager() {
|
|
40
|
+
return this.referenceSyncBlockStoreManager;
|
|
41
|
+
}
|
|
37
42
|
|
|
38
43
|
/**
|
|
39
44
|
* Add/update a sync block node to/from the local cache
|
|
@@ -94,11 +99,44 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
94
99
|
// only applicable to source sync block, for now (will be refactored further)
|
|
95
100
|
return this.sourceSyncBlockStoreManager.requireConfirmationBeforeDelete();
|
|
96
101
|
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
|
|
105
|
+
*/
|
|
106
|
+
}, {
|
|
107
|
+
key: "registerCreationCallback",
|
|
108
|
+
value: function registerCreationCallback(callback) {
|
|
109
|
+
this.sourceSyncBlockStoreManager.registerCreationCallback(callback);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* @returns true if waiting for the result of saving new bodiedSyncBlock to backend
|
|
115
|
+
*/
|
|
116
|
+
}, {
|
|
117
|
+
key: "hasPendingCreation",
|
|
118
|
+
value: function hasPendingCreation() {
|
|
119
|
+
return this.sourceSyncBlockStoreManager.hasPendingCreation();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @returns attributes for a new bodiedSyncBlock node
|
|
124
|
+
*/
|
|
125
|
+
}, {
|
|
126
|
+
key: "generateBodiedSyncBlockAttrs",
|
|
127
|
+
value: function generateBodiedSyncBlockAttrs() {
|
|
128
|
+
return this.sourceSyncBlockStoreManager.generateBodiedSyncBlockAttrs();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Save bodiedSyncBlock with empty content to backend
|
|
133
|
+
* @param attrs attributes Ids of the node
|
|
134
|
+
*/
|
|
97
135
|
}, {
|
|
98
|
-
key: "
|
|
99
|
-
value: function
|
|
136
|
+
key: "createBodiedSyncBlockNode",
|
|
137
|
+
value: function createBodiedSyncBlockNode(attrs) {
|
|
100
138
|
// only applicable to source sync block, for now (will be refactored further)
|
|
101
|
-
return this.sourceSyncBlockStoreManager.
|
|
139
|
+
return this.sourceSyncBlockStoreManager.createBodiedSyncBlockNode(attrs);
|
|
102
140
|
}
|
|
103
141
|
}, {
|
|
104
142
|
key: "subscribeToSyncBlockData",
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -7,4 +7,35 @@ export var convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNo
|
|
|
7
7
|
};
|
|
8
8
|
export var isBlogPageType = function isBlogPageType(pageType) {
|
|
9
9
|
return pageType === 'blogpost';
|
|
10
|
+
};
|
|
11
|
+
export var createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
|
|
12
|
+
return {
|
|
13
|
+
type: 'syncBlock',
|
|
14
|
+
attrs: {
|
|
15
|
+
localId: localId,
|
|
16
|
+
resourceId: resourceId
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export var createBodiedSyncBlockNode = function createBodiedSyncBlockNode(localId, resourceId) {
|
|
21
|
+
return {
|
|
22
|
+
type: 'bodiedSyncBlock',
|
|
23
|
+
attrs: {
|
|
24
|
+
localId: localId,
|
|
25
|
+
resourceId: resourceId
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export var convertSyncBlockJSONNodeToSyncBlockNode = function convertSyncBlockJSONNodeToSyncBlockNode(node) {
|
|
30
|
+
if (node.type !== 'syncBlock' || !node.attrs || !('localId' in node.attrs) || !('resourceId' in node.attrs) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
|
|
34
|
+
};
|
|
35
|
+
export var convertPMNodeToSyncBlockNode = function convertPMNodeToSyncBlockNode(node) {
|
|
36
|
+
var _node$attrs, _node$attrs2;
|
|
37
|
+
if (node.type.name !== 'syncBlock' || !((_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.localId) || !((_node$attrs2 = node.attrs) !== null && _node$attrs2 !== void 0 && _node$attrs2.resourceId) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
|
|
10
41
|
};
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
|
|
4
4
|
* @returns
|
|
5
5
|
*/
|
|
6
|
-
export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"
|
|
6
|
+
export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"doc" | "paragraph" | "text" | "bulletList" | "orderedList" | "listItem" | "heading" | "blockquote" | "codeBlock" | "panel" | "rule" | "expand" | "nestedExpand" | "table" | "tableCell" | "tableHeader" | "tableRow" | "date" | "status" | "layoutSection" | "layoutColumn" | "unsupportedBlock" | "unsupportedInline", "link" | "em" | "strong" | "strike" | "subsup" | "underline" | "code" | "textColor" | "backgroundColor" | "alignment" | "indentation" | "border" | "unsupportedMark" | "unsupportedNodeAttribute" | "typeAheadQuery">;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
1
|
import type { SyncBlockInstance } from '../providers/types';
|
|
3
2
|
import type { SyncBlockStoreManager } from '../store-manager/syncBlockStoreManager';
|
|
4
|
-
export
|
|
5
|
-
|
|
3
|
+
export interface UseFetchSyncBlockDataResult {
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
reloadData: () => Promise<void>;
|
|
6
|
+
syncBlockInstance: SyncBlockInstance | null;
|
|
7
|
+
}
|
|
8
|
+
export declare const useFetchSyncBlockData: (manager: SyncBlockStoreManager, resourceId?: string, localId?: string) => UseFetchSyncBlockDataResult;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { rebaseTransaction } from './common/rebase-transaction';
|
|
2
|
+
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
3
|
+
export { SyncBlockError } from './common/types';
|
|
4
|
+
export type { SyncBlockData, SyncBlockNode } from './common/types';
|
|
5
|
+
export { useFetchSyncBlockData, type UseFetchSyncBlockDataResult, } from './hooks/useFetchSyncBlockData';
|
|
4
6
|
export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
|
|
5
7
|
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
6
|
-
export type { SyncBlockData, SyncBlockNode } from './common/types';
|
|
7
|
-
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockInstance, } from './providers/types';
|
|
8
|
-
export { SyncBlockError } from './common/types';
|
|
9
|
-
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
10
8
|
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluence/confluenceContentAPI';
|
|
9
|
+
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
|
|
10
|
+
export type { ADFFetchProvider, ADFWriteProvider, SyncBlockDataProvider, SyncBlockInstance, } from './providers/types';
|
|
11
|
+
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
12
|
+
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
11
13
|
export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
|
|
12
|
-
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
13
|
-
export { rebaseTransaction } from './common/rebase-transaction';
|
|
14
|
+
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, } from './utils/utils';
|
|
14
15
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SyncBlockData } from '../../common/types';
|
|
2
|
-
import type { ADFFetchProvider, ADFWriteProvider, DeleteSyncBlockResult, SyncBlockInstance } from '../types';
|
|
2
|
+
import type { ADFFetchProvider, ADFWriteProvider, DeleteSyncBlockResult, SyncBlockInstance, WriteSyncBlockResult } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for Content API providers
|
|
5
5
|
*/
|
|
@@ -22,7 +22,7 @@ declare class ConfluenceADFWriteProvider implements ADFWriteProvider {
|
|
|
22
22
|
private config;
|
|
23
23
|
constructor(config: ContentAPIConfig);
|
|
24
24
|
private createNewContentProperty;
|
|
25
|
-
writeData(data: SyncBlockData): Promise<
|
|
25
|
+
writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
|
|
26
26
|
deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
|
|
2
2
|
import { type SyncBlockData, type SyncBlockNode } from '../common/types';
|
|
3
|
-
import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type DeleteSyncBlockResult, type SyncBlockInstance, type SyncBlockSourceInfo } from '../providers/types';
|
|
3
|
+
import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type DeleteSyncBlockResult, type SyncBlockInstance, type SyncBlockSourceInfo, type WriteSyncBlockResult } from '../providers/types';
|
|
4
4
|
export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
5
5
|
name: string;
|
|
6
6
|
private fetchProvider;
|
|
@@ -15,9 +15,10 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
15
15
|
* @param nodes
|
|
16
16
|
* @param data
|
|
17
17
|
*
|
|
18
|
-
* @returns
|
|
18
|
+
* @returns Array of {resourceId?: string, error?: string}.
|
|
19
|
+
* resourceId: resource id of the node if write successfully , error: reason for when write failed
|
|
19
20
|
*/
|
|
20
|
-
writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<
|
|
21
|
+
writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
|
|
21
22
|
deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
|
|
22
23
|
getSourceId(): string;
|
|
23
24
|
retrieveSyncBlockSourceUrlAndTitle(node: SyncBlockNode): Promise<SyncBlockSourceInfo | undefined>;
|
|
@@ -19,15 +19,19 @@ export type SyncBlockSourceInfo = {
|
|
|
19
19
|
title?: string;
|
|
20
20
|
url?: string;
|
|
21
21
|
};
|
|
22
|
+
export type WriteSyncBlockResult = {
|
|
23
|
+
error?: string;
|
|
24
|
+
resourceId?: string;
|
|
25
|
+
};
|
|
22
26
|
export interface ADFFetchProvider {
|
|
23
27
|
fetchData: (resourceId: ResourceId) => Promise<SyncBlockInstance>;
|
|
24
28
|
}
|
|
25
29
|
export interface ADFWriteProvider {
|
|
26
30
|
deleteData: (resourceId: string) => Promise<DeleteSyncBlockResult>;
|
|
27
|
-
writeData: (data: SyncBlockData) => Promise<
|
|
31
|
+
writeData: (data: SyncBlockData) => Promise<WriteSyncBlockResult>;
|
|
28
32
|
}
|
|
29
33
|
export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockInstance> {
|
|
30
|
-
abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<
|
|
34
|
+
abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
|
|
31
35
|
abstract deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
|
|
32
36
|
abstract getSourceId(): ResourceId;
|
|
33
37
|
abstract retrieveSyncBlockSourceUrlAndTitle(node: SyncBlockNode): Promise<SyncBlockSourceInfo | undefined>;
|
|
@@ -20,8 +20,9 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
20
20
|
private updateSourceTitleSubscriptions;
|
|
21
21
|
private getFromCache;
|
|
22
22
|
private deleteFromCache;
|
|
23
|
-
|
|
23
|
+
subscribeToSyncBlock(resourceId: string, localId: string, callback: SubscriptionCallback): () => void;
|
|
24
24
|
subscribeToSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
|
|
25
|
+
subscribe(node: PMNode, callback: SubscriptionCallback): () => void;
|
|
25
26
|
/**
|
|
26
27
|
* Get the URL for a sync block.
|
|
27
28
|
* @param resourceId - The resource ID of the sync block
|