@atlaskit/editor-synced-block-provider 2.6.0 → 2.7.1
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 +16 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +2 -2
- package/dist/cjs/index.js +9 -4
- package/dist/cjs/providers/confluence/confluenceContentAPI.js +86 -73
- package/dist/cjs/providers/syncBlockProvider.js +52 -75
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +7 -7
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +78 -17
- package/dist/cjs/store-manager/syncBlockStoreManager.js +41 -8
- package/dist/cjs/utils/errorHandling.js +13 -0
- package/dist/cjs/utils/sourceInfo.js +119 -0
- package/dist/cjs/utils/utils.js +32 -1
- package/dist/es2019/hooks/useFetchSyncBlockData.js +1 -1
- package/dist/es2019/index.js +2 -3
- package/dist/es2019/providers/confluence/confluenceContentAPI.js +62 -40
- package/dist/es2019/providers/syncBlockProvider.js +18 -37
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +4 -4
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +64 -12
- package/dist/es2019/store-manager/syncBlockStoreManager.js +31 -8
- package/dist/es2019/utils/errorHandling.js +7 -0
- package/dist/es2019/utils/sourceInfo.js +89 -0
- package/dist/es2019/utils/utils.js +31 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +1 -1
- package/dist/esm/index.js +2 -3
- package/dist/esm/providers/confluence/confluenceContentAPI.js +79 -66
- package/dist/esm/providers/syncBlockProvider.js +52 -75
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +5 -5
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +79 -18
- package/dist/esm/store-manager/syncBlockStoreManager.js +41 -8
- package/dist/esm/utils/errorHandling.js +7 -0
- package/dist/esm/utils/sourceInfo.js +114 -0
- package/dist/esm/utils/utils.js +31 -0
- package/dist/types/index.d.ts +1 -2
- package/dist/types/providers/confluence/confluenceContentAPI.d.ts +2 -2
- package/dist/types/providers/syncBlockProvider.d.ts +5 -4
- package/dist/types/providers/types.d.ts +7 -3
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +1 -1
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +15 -3
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +20 -3
- package/dist/types/utils/errorHandling.d.ts +1 -0
- package/dist/types/utils/sourceInfo.d.ts +2 -0
- package/dist/types/utils/utils.d.ts +6 -1
- package/dist/types-ts4.5/index.d.ts +1 -2
- package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +2 -2
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +5 -4
- package/dist/types-ts4.5/providers/types.d.ts +7 -3
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +1 -1
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +15 -3
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +20 -3
- package/dist/types-ts4.5/utils/errorHandling.d.ts +1 -0
- package/dist/types-ts4.5/utils/sourceInfo.d.ts +2 -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
|
@@ -13,6 +13,7 @@ import { useMemo } from 'react';
|
|
|
13
13
|
import { SyncBlockError } from '../common/types';
|
|
14
14
|
import { SyncBlockDataProvider } from '../providers/types';
|
|
15
15
|
import { getLocalIdFromAri, getPageARIFromResourceId } from '../utils/ari';
|
|
16
|
+
import { fetchSourceInfo } from '../utils/sourceInfo';
|
|
16
17
|
export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
17
18
|
function SyncBlockProvider(fetchProvider, writeProvider, sourceId) {
|
|
18
19
|
var _this;
|
|
@@ -66,39 +67,63 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
66
67
|
* @param nodes
|
|
67
68
|
* @param data
|
|
68
69
|
*
|
|
69
|
-
* @returns
|
|
70
|
+
* @returns Array of {resourceId?: string, error?: string}.
|
|
71
|
+
* resourceId: resource id of the node if write successfully , error: reason for when write failed
|
|
70
72
|
*/
|
|
71
73
|
}, {
|
|
72
74
|
key: "writeNodesData",
|
|
73
|
-
value: function
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
value: (function () {
|
|
76
|
+
var _writeNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(nodes, data) {
|
|
77
|
+
var _this3 = this;
|
|
78
|
+
var results;
|
|
79
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
80
|
+
while (1) switch (_context.prev = _context.next) {
|
|
81
|
+
case 0:
|
|
82
|
+
_context.next = 2;
|
|
83
|
+
return Promise.allSettled(nodes.map(function (_node, index) {
|
|
84
|
+
if (!data[index].content) {
|
|
85
|
+
return Promise.reject('No Synced Block content to write');
|
|
86
|
+
}
|
|
87
|
+
return _this3.writeProvider.writeData(data[index]);
|
|
88
|
+
}));
|
|
89
|
+
case 2:
|
|
90
|
+
results = _context.sent;
|
|
91
|
+
return _context.abrupt("return", results.map(function (result) {
|
|
92
|
+
if (result.status === 'fulfilled') {
|
|
93
|
+
return result.value;
|
|
94
|
+
} else {
|
|
95
|
+
return {
|
|
96
|
+
error: result.reason
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
100
|
+
case 4:
|
|
101
|
+
case "end":
|
|
102
|
+
return _context.stop();
|
|
103
|
+
}
|
|
104
|
+
}, _callee);
|
|
105
|
+
}));
|
|
106
|
+
function writeNodesData(_x, _x2) {
|
|
107
|
+
return _writeNodesData.apply(this, arguments);
|
|
108
|
+
}
|
|
109
|
+
return writeNodesData;
|
|
110
|
+
}())
|
|
86
111
|
}, {
|
|
87
112
|
key: "deleteNodesData",
|
|
88
113
|
value: function () {
|
|
89
|
-
var _deleteNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
114
|
+
var _deleteNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceIds) {
|
|
90
115
|
var _this4 = this;
|
|
91
116
|
var results;
|
|
92
|
-
return _regeneratorRuntime.wrap(function
|
|
93
|
-
while (1) switch (
|
|
117
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
118
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
94
119
|
case 0:
|
|
95
|
-
|
|
120
|
+
_context2.next = 2;
|
|
96
121
|
return Promise.allSettled(resourceIds.map(function (resourceId) {
|
|
97
122
|
return _this4.writeProvider.deleteData(resourceId);
|
|
98
123
|
}));
|
|
99
124
|
case 2:
|
|
100
|
-
results =
|
|
101
|
-
return
|
|
125
|
+
results = _context2.sent;
|
|
126
|
+
return _context2.abrupt("return", results.map(function (result, index) {
|
|
102
127
|
if (result.status === 'fulfilled') {
|
|
103
128
|
return result.value;
|
|
104
129
|
} else {
|
|
@@ -111,11 +136,11 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
111
136
|
}));
|
|
112
137
|
case 4:
|
|
113
138
|
case "end":
|
|
114
|
-
return
|
|
139
|
+
return _context2.stop();
|
|
115
140
|
}
|
|
116
|
-
},
|
|
141
|
+
}, _callee2);
|
|
117
142
|
}));
|
|
118
|
-
function deleteNodesData(
|
|
143
|
+
function deleteNodesData(_x3) {
|
|
119
144
|
return _deleteNodesData.apply(this, arguments);
|
|
120
145
|
}
|
|
121
146
|
return deleteNodesData;
|
|
@@ -126,8 +151,8 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
126
151
|
return this.sourceId;
|
|
127
152
|
}
|
|
128
153
|
}, {
|
|
129
|
-
key: "
|
|
130
|
-
value: function
|
|
154
|
+
key: "retrieveSyncBlockSourceInfo",
|
|
155
|
+
value: function retrieveSyncBlockSourceInfo(node) {
|
|
131
156
|
var resourceId = node.attrs.resourceId;
|
|
132
157
|
var pageARI;
|
|
133
158
|
var sourceLocalId;
|
|
@@ -143,7 +168,7 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
143
168
|
// EDITOR-1921: log analytic here, safe to continue
|
|
144
169
|
}
|
|
145
170
|
}
|
|
146
|
-
return pageARI ?
|
|
171
|
+
return pageARI ? fetchSourceInfo(pageARI, sourceLocalId) : Promise.resolve(undefined);
|
|
147
172
|
}
|
|
148
173
|
}]);
|
|
149
174
|
}(SyncBlockDataProvider);
|
|
@@ -151,52 +176,4 @@ export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvi
|
|
|
151
176
|
return useMemo(function () {
|
|
152
177
|
return new SyncBlockProvider(fetchProvider, writeProvider, sourceId);
|
|
153
178
|
}, [fetchProvider, writeProvider, sourceId]);
|
|
154
|
-
};
|
|
155
|
-
var fetchURLandTitlefromARI = /*#__PURE__*/function () {
|
|
156
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(ari, sourceLocalId) {
|
|
157
|
-
var response, _payload$data, _payload$data2, payload, url, title;
|
|
158
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
159
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
160
|
-
case 0:
|
|
161
|
-
_context2.next = 2;
|
|
162
|
-
return fetch('/gateway/api/object-resolver/resolve/ari', {
|
|
163
|
-
method: 'POST',
|
|
164
|
-
headers: {
|
|
165
|
-
'Content-Type': 'application/json',
|
|
166
|
-
Accept: 'application/json'
|
|
167
|
-
},
|
|
168
|
-
body: JSON.stringify({
|
|
169
|
-
ari: ari
|
|
170
|
-
})
|
|
171
|
-
});
|
|
172
|
-
case 2:
|
|
173
|
-
response = _context2.sent;
|
|
174
|
-
if (!response.ok) {
|
|
175
|
-
_context2.next = 12;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
_context2.next = 6;
|
|
179
|
-
return response.json();
|
|
180
|
-
case 6:
|
|
181
|
-
payload = _context2.sent;
|
|
182
|
-
url = payload === null || payload === void 0 || (_payload$data = payload.data) === null || _payload$data === void 0 ? void 0 : _payload$data.url;
|
|
183
|
-
title = payload === null || payload === void 0 || (_payload$data2 = payload.data) === null || _payload$data2 === void 0 ? void 0 : _payload$data2.name;
|
|
184
|
-
return _context2.abrupt("return", {
|
|
185
|
-
url: typeof url === 'string' ? sourceLocalId ? url + "?block=".concat(sourceLocalId) : url : undefined,
|
|
186
|
-
title: typeof title === 'string' ? title : undefined
|
|
187
|
-
});
|
|
188
|
-
case 12:
|
|
189
|
-
//eslint-disable-next-line no-console
|
|
190
|
-
console.error('Failed to fetch URL and title from ARI', response.statusText);
|
|
191
|
-
case 13:
|
|
192
|
-
return _context2.abrupt("return", undefined);
|
|
193
|
-
case 14:
|
|
194
|
-
case "end":
|
|
195
|
-
return _context2.stop();
|
|
196
|
-
}
|
|
197
|
-
}, _callee2);
|
|
198
|
-
}));
|
|
199
|
-
return function fetchURLandTitlefromARI(_x2, _x3) {
|
|
200
|
-
return _ref.apply(this, arguments);
|
|
201
|
-
};
|
|
202
|
-
}();
|
|
179
|
+
};
|
|
@@ -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);
|
|
@@ -106,8 +106,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
106
106
|
return refreshSubscriptions;
|
|
107
107
|
}())
|
|
108
108
|
}, {
|
|
109
|
-
key: "
|
|
110
|
-
value: function
|
|
109
|
+
key: "retrieveSyncBlockSourceInfo",
|
|
110
|
+
value: function retrieveSyncBlockSourceInfo(resourceId) {
|
|
111
111
|
var _this = this;
|
|
112
112
|
if (!resourceId || !this.dataProvider) {
|
|
113
113
|
return;
|
|
@@ -117,7 +117,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
117
117
|
// we could optimise this further by checking if the sync block is on the same page as the source
|
|
118
118
|
if (!this.syncBlockURLRequests.get(resourceId)) {
|
|
119
119
|
this.syncBlockURLRequests.set(resourceId, true);
|
|
120
|
-
this.dataProvider.
|
|
120
|
+
this.dataProvider.retrieveSyncBlockSourceInfo(createSyncBlockNode('', resourceId)).then(function (sourceInfo) {
|
|
121
121
|
var existingSyncBlock = _this.getFromCache(resourceId);
|
|
122
122
|
if (existingSyncBlock && existingSyncBlock.data) {
|
|
123
123
|
existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
|
|
@@ -172,7 +172,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
172
172
|
|
|
173
173
|
// fetch source URL and title if not already present
|
|
174
174
|
if ((!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) || !((_resolvedSyncBlockIns2 = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns2 !== void 0 && _resolvedSyncBlockIns2.sourceTitle)) && resolvedSyncBlockInstance.resourceId) {
|
|
175
|
-
_this2.
|
|
175
|
+
_this2.retrieveSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
176
176
|
}
|
|
177
177
|
});
|
|
178
178
|
return _context3.abrupt("return", resolvedData);
|
|
@@ -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,10 +24,10 @@ 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([]);
|
|
@@ -99,11 +99,44 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
99
99
|
// only applicable to source sync block, for now (will be refactored further)
|
|
100
100
|
return this.sourceSyncBlockStoreManager.requireConfirmationBeforeDelete();
|
|
101
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
|
+
*/
|
|
102
135
|
}, {
|
|
103
|
-
key: "
|
|
104
|
-
value: function
|
|
136
|
+
key: "createBodiedSyncBlockNode",
|
|
137
|
+
value: function createBodiedSyncBlockNode(attrs) {
|
|
105
138
|
// only applicable to source sync block, for now (will be refactored further)
|
|
106
|
-
return this.sourceSyncBlockStoreManager.
|
|
139
|
+
return this.sourceSyncBlockStoreManager.createBodiedSyncBlockNode(attrs);
|
|
107
140
|
}
|
|
108
141
|
}, {
|
|
109
142
|
key: "subscribeToSyncBlockData",
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
/* eslint-disable require-unicode-regexp */
|
|
7
|
+
|
|
8
|
+
import { getPageIdAndTypeFromAri } from "./ari";
|
|
9
|
+
import { isBlogPageType } from "./utils";
|
|
10
|
+
var COMMON_HEADERS = {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
Accept: 'application/json'
|
|
13
|
+
};
|
|
14
|
+
var AGG_HEADERS = {
|
|
15
|
+
'X-ExperimentalApi': 'confluence-agg-beta'
|
|
16
|
+
};
|
|
17
|
+
var GRAPHQL_ENDPOINT = '/gateway/api/graphql';
|
|
18
|
+
var GET_SOURCE_INFO_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET_SOURCE_INFO';
|
|
19
|
+
/**
|
|
20
|
+
* Query to get the page subtype by id (i.e. live or classic)
|
|
21
|
+
* @param documentARI
|
|
22
|
+
* @returns subType live if livePage, subType null if classic page
|
|
23
|
+
*/
|
|
24
|
+
var GET_SOURCE_INFO_QUERY = "query ".concat(GET_SOURCE_INFO_OPERATION_NAME, " ($id: ID!) {\n\tcontent (id: $id) {\n\t\tnodes {\n\t\t\tid\n\t\t\tlinks {\n\t\t\t\tbase\n\t\t\t}\n\t\t\tspace {\n\t\t\t\tkey\n\t\t\t}\n\t\t\tsubType\n\t\t\ttitle\n\t\t}\n\t}\n}");
|
|
25
|
+
var getSourceInfo = /*#__PURE__*/function () {
|
|
26
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(ari) {
|
|
27
|
+
var bodyData, response;
|
|
28
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
29
|
+
while (1) switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
bodyData = {
|
|
32
|
+
query: GET_SOURCE_INFO_QUERY,
|
|
33
|
+
operationName: GET_SOURCE_INFO_OPERATION_NAME,
|
|
34
|
+
variables: {
|
|
35
|
+
id: ari
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
_context.next = 3;
|
|
39
|
+
return fetch(GRAPHQL_ENDPOINT, {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
|
|
42
|
+
body: JSON.stringify(bodyData)
|
|
43
|
+
});
|
|
44
|
+
case 3:
|
|
45
|
+
response = _context.sent;
|
|
46
|
+
if (response.ok) {
|
|
47
|
+
_context.next = 6;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
throw new Error("Failed to get url: ".concat(response.statusText));
|
|
51
|
+
case 6:
|
|
52
|
+
_context.next = 8;
|
|
53
|
+
return response.json();
|
|
54
|
+
case 8:
|
|
55
|
+
return _context.abrupt("return", _context.sent);
|
|
56
|
+
case 9:
|
|
57
|
+
case "end":
|
|
58
|
+
return _context.stop();
|
|
59
|
+
}
|
|
60
|
+
}, _callee);
|
|
61
|
+
}));
|
|
62
|
+
return function getSourceInfo(_x) {
|
|
63
|
+
return _ref.apply(this, arguments);
|
|
64
|
+
};
|
|
65
|
+
}();
|
|
66
|
+
export var fetchSourceInfo = /*#__PURE__*/function () {
|
|
67
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(ari, localId) {
|
|
68
|
+
var _response$data, _contentData$space, _getPageIdAndTypeFrom, pageType, response, contentData, title, url, _ref3, base;
|
|
69
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
70
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
71
|
+
case 0:
|
|
72
|
+
_context2.prev = 0;
|
|
73
|
+
_getPageIdAndTypeFrom = getPageIdAndTypeFromAri(ari), pageType = _getPageIdAndTypeFrom.type;
|
|
74
|
+
_context2.next = 4;
|
|
75
|
+
return getSourceInfo(ari);
|
|
76
|
+
case 4:
|
|
77
|
+
response = _context2.sent;
|
|
78
|
+
contentData = (_response$data = response.data) === null || _response$data === void 0 || (_response$data = _response$data.content) === null || _response$data === void 0 || (_response$data = _response$data.nodes) === null || _response$data === void 0 ? void 0 : _response$data[0];
|
|
79
|
+
if (contentData) {
|
|
80
|
+
_context2.next = 8;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
throw new Error("Failed to get content data");
|
|
84
|
+
case 8:
|
|
85
|
+
title = contentData.title;
|
|
86
|
+
_ref3 = contentData.links || {}, base = _ref3.base;
|
|
87
|
+
if (base && (_contentData$space = contentData.space) !== null && _contentData$space !== void 0 && _contentData$space.key && contentData.id) {
|
|
88
|
+
if (isBlogPageType(pageType)) {
|
|
89
|
+
url = "".concat(base, "/spaces/").concat(contentData.space.key, "/blog/edit-v2/").concat(contentData.id);
|
|
90
|
+
} else if (contentData.subType === 'live') {
|
|
91
|
+
url = "".concat(base, "/spaces/").concat(contentData.space.key, "/pages/").concat(contentData.id);
|
|
92
|
+
} else {
|
|
93
|
+
url = "".concat(base, "/spaces/").concat(contentData.space.key, "/pages/edit-v2/").concat(contentData.id);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
url = url && localId ? "".concat(url, "#block-").concat(localId) : url;
|
|
97
|
+
return _context2.abrupt("return", Promise.resolve({
|
|
98
|
+
title: title,
|
|
99
|
+
url: url
|
|
100
|
+
}));
|
|
101
|
+
case 15:
|
|
102
|
+
_context2.prev = 15;
|
|
103
|
+
_context2.t0 = _context2["catch"](0);
|
|
104
|
+
return _context2.abrupt("return", Promise.resolve(undefined));
|
|
105
|
+
case 18:
|
|
106
|
+
case "end":
|
|
107
|
+
return _context2.stop();
|
|
108
|
+
}
|
|
109
|
+
}, _callee2, null, [[0, 15]]);
|
|
110
|
+
}));
|
|
111
|
+
return function fetchSourceInfo(_x2, _x3) {
|
|
112
|
+
return _ref2.apply(this, arguments);
|
|
113
|
+
};
|
|
114
|
+
}();
|
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
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,6 +11,5 @@ export type { ADFFetchProvider, ADFWriteProvider, SyncBlockDataProvider, SyncBlo
|
|
|
11
11
|
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
12
12
|
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
13
13
|
export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
|
|
14
|
-
export { createSyncBlockNode } from './utils/
|
|
14
|
+
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, } from './utils/utils';
|
|
15
15
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
16
|
-
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
@@ -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,11 +15,12 @@ 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
|
+
retrieveSyncBlockSourceInfo(node: SyncBlockNode): Promise<SyncBlockSourceInfo | undefined>;
|
|
24
25
|
}
|
|
25
26
|
export declare const useMemoizedSyncedBlockProvider: (fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string) => SyncBlockProvider;
|