@atlaskit/editor-synced-block-provider 0.1.3 → 0.3.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 +14 -0
- package/dist/cjs/common/schema.js +18 -0
- package/dist/cjs/common/syncBlockProvider.js +24 -12
- package/dist/cjs/common/syncBlockStoreManager.js +8 -5
- package/dist/cjs/index.js +33 -0
- package/dist/cjs/providers/confluenceContentAPI.js +238 -0
- package/dist/cjs/utils/ari.js +42 -0
- package/dist/cjs/utils/contentProperty.js +192 -0
- package/dist/es2019/common/schema.js +13 -0
- package/dist/es2019/common/syncBlockProvider.js +25 -13
- package/dist/es2019/common/syncBlockStoreManager.js +8 -5
- package/dist/es2019/index.js +4 -1
- package/dist/es2019/providers/confluenceContentAPI.js +150 -0
- package/dist/es2019/utils/ari.js +32 -0
- package/dist/es2019/utils/contentProperty.js +160 -0
- package/dist/esm/common/schema.js +13 -0
- package/dist/esm/common/syncBlockProvider.js +24 -12
- package/dist/esm/common/syncBlockStoreManager.js +8 -5
- package/dist/esm/index.js +4 -1
- package/dist/esm/providers/confluenceContentAPI.js +232 -0
- package/dist/esm/utils/ari.js +36 -0
- package/dist/esm/utils/contentProperty.js +185 -0
- package/dist/types/common/schema.d.ts +6 -0
- package/dist/types/common/syncBlockProvider.d.ts +3 -1
- package/dist/types/common/syncBlockStoreManager.d.ts +2 -1
- package/dist/types/common/types.d.ts +2 -0
- package/dist/types/index.d.ts +4 -1
- package/dist/types/providers/confluenceContentAPI.d.ts +41 -0
- package/dist/types/utils/ari.d.ts +10 -0
- package/dist/types/utils/contentProperty.d.ts +61 -0
- package/dist/types-ts4.5/common/schema.d.ts +6 -0
- package/dist/types-ts4.5/common/syncBlockProvider.d.ts +3 -1
- package/dist/types-ts4.5/common/syncBlockStoreManager.d.ts +2 -1
- package/dist/types-ts4.5/common/types.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +4 -1
- package/dist/types-ts4.5/providers/confluenceContentAPI.d.ts +41 -0
- package/dist/types-ts4.5/utils/ari.d.ts +10 -0
- package/dist/types-ts4.5/utils/contentProperty.d.ts +61 -0
- package/package.json +2 -2
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
import { getLocalIdFromAri, getPageIdFromAri } from '../utils/ari';
|
|
8
|
+
import { getContentProperty, createContentProperty, updateContentProperty } from '../utils/contentProperty';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for Content API providers
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
var getContentPropertyKey = function getContentPropertyKey(contentPropertyKey, localId) {
|
|
15
|
+
return contentPropertyKey + '-' + localId;
|
|
16
|
+
};
|
|
17
|
+
var parseSyncedBlockContentPropertyValue = function parseSyncedBlockContentPropertyValue(value) {
|
|
18
|
+
try {
|
|
19
|
+
if (typeof value === 'string') {
|
|
20
|
+
return JSON.parse(value);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.error('Failed to parse synced block content:', error);
|
|
26
|
+
return {
|
|
27
|
+
content: undefined
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* ADFFetchProvider implementation that fetches synced block data from Confluence Content API
|
|
34
|
+
*/
|
|
35
|
+
var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
|
|
36
|
+
function ConfluenceADFFetchProvider(config) {
|
|
37
|
+
_classCallCheck(this, ConfluenceADFFetchProvider);
|
|
38
|
+
this.config = config;
|
|
39
|
+
}
|
|
40
|
+
return _createClass(ConfluenceADFFetchProvider, [{
|
|
41
|
+
key: "fetchData",
|
|
42
|
+
value: function () {
|
|
43
|
+
var _fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resourceId) {
|
|
44
|
+
var _contentProperty$data, pageId, localId, key, options, contentProperty, value, syncedBlockData;
|
|
45
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
46
|
+
while (1) switch (_context.prev = _context.next) {
|
|
47
|
+
case 0:
|
|
48
|
+
_context.prev = 0;
|
|
49
|
+
pageId = getPageIdFromAri(resourceId);
|
|
50
|
+
localId = getLocalIdFromAri(resourceId);
|
|
51
|
+
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
52
|
+
options = {
|
|
53
|
+
pageId: pageId,
|
|
54
|
+
key: key,
|
|
55
|
+
cloudId: this.config.cloudId
|
|
56
|
+
};
|
|
57
|
+
_context.next = 7;
|
|
58
|
+
return getContentProperty(options);
|
|
59
|
+
case 7:
|
|
60
|
+
contentProperty = _context.sent;
|
|
61
|
+
value = (_contentProperty$data = contentProperty.data.confluence.page.properties) === null || _contentProperty$data === void 0 || (_contentProperty$data = _contentProperty$data[0]) === null || _contentProperty$data === void 0 ? void 0 : _contentProperty$data.value;
|
|
62
|
+
if (value) {
|
|
63
|
+
_context.next = 11;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
throw new Error('Content property value does not exist');
|
|
67
|
+
case 11:
|
|
68
|
+
// Parse the synced block content from the property value
|
|
69
|
+
syncedBlockData = parseSyncedBlockContentPropertyValue(value);
|
|
70
|
+
return _context.abrupt("return", {
|
|
71
|
+
content: syncedBlockData.content
|
|
72
|
+
});
|
|
73
|
+
case 15:
|
|
74
|
+
_context.prev = 15;
|
|
75
|
+
_context.t0 = _context["catch"](0);
|
|
76
|
+
// eslint-disable-next-line no-console
|
|
77
|
+
console.error('Failed to fetch synced block data:', _context.t0);
|
|
78
|
+
return _context.abrupt("return", {
|
|
79
|
+
content: undefined
|
|
80
|
+
});
|
|
81
|
+
case 19:
|
|
82
|
+
case "end":
|
|
83
|
+
return _context.stop();
|
|
84
|
+
}
|
|
85
|
+
}, _callee, this, [[0, 15]]);
|
|
86
|
+
}));
|
|
87
|
+
function fetchData(_x) {
|
|
88
|
+
return _fetchData.apply(this, arguments);
|
|
89
|
+
}
|
|
90
|
+
return fetchData;
|
|
91
|
+
}()
|
|
92
|
+
}]);
|
|
93
|
+
}();
|
|
94
|
+
/**
|
|
95
|
+
* ADFWriteProvider implementation that writes synced block data to Confluence Content API
|
|
96
|
+
*/
|
|
97
|
+
var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
98
|
+
function ConfluenceADFWriteProvider(config) {
|
|
99
|
+
var _this = this;
|
|
100
|
+
_classCallCheck(this, ConfluenceADFWriteProvider);
|
|
101
|
+
_defineProperty(this, "createNewContentProperty", /*#__PURE__*/function () {
|
|
102
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(pageId, key, value) {
|
|
103
|
+
var _contentProperty$data2;
|
|
104
|
+
var contentProperty;
|
|
105
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
106
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
107
|
+
case 0:
|
|
108
|
+
_context2.next = 2;
|
|
109
|
+
return createContentProperty({
|
|
110
|
+
pageId: pageId,
|
|
111
|
+
key: key,
|
|
112
|
+
value: value,
|
|
113
|
+
cloudId: _this.config.cloudId
|
|
114
|
+
});
|
|
115
|
+
case 2:
|
|
116
|
+
contentProperty = _context2.sent;
|
|
117
|
+
if (!(((_contentProperty$data2 = contentProperty.data.confluence.createPageProperty.pageProperty) === null || _contentProperty$data2 === void 0 ? void 0 : _contentProperty$data2.key) === key)) {
|
|
118
|
+
_context2.next = 7;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
return _context2.abrupt("return", key);
|
|
122
|
+
case 7:
|
|
123
|
+
throw new Error('Failed to create content property');
|
|
124
|
+
case 8:
|
|
125
|
+
case "end":
|
|
126
|
+
return _context2.stop();
|
|
127
|
+
}
|
|
128
|
+
}, _callee2);
|
|
129
|
+
}));
|
|
130
|
+
return function (_x2, _x3, _x4) {
|
|
131
|
+
return _ref.apply(this, arguments);
|
|
132
|
+
};
|
|
133
|
+
}());
|
|
134
|
+
this.config = config;
|
|
135
|
+
}
|
|
136
|
+
return _createClass(ConfluenceADFWriteProvider, [{
|
|
137
|
+
key: "writeData",
|
|
138
|
+
value: function () {
|
|
139
|
+
var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(sourceId, localId, data, resourceId) {
|
|
140
|
+
var pageId, syncedBlockValue, _contentProperty$data3, _localId, key, contentProperty, _key;
|
|
141
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
142
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
143
|
+
case 0:
|
|
144
|
+
_context3.prev = 0;
|
|
145
|
+
pageId = getPageIdFromAri(sourceId);
|
|
146
|
+
syncedBlockValue = JSON.stringify({
|
|
147
|
+
content: data
|
|
148
|
+
});
|
|
149
|
+
if (!resourceId) {
|
|
150
|
+
_context3.next = 20;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
// Update existing content property
|
|
154
|
+
_localId = getLocalIdFromAri(resourceId);
|
|
155
|
+
key = getContentPropertyKey(this.config.contentPropertyKey, _localId);
|
|
156
|
+
_context3.next = 8;
|
|
157
|
+
return updateContentProperty({
|
|
158
|
+
pageId: pageId,
|
|
159
|
+
key: key,
|
|
160
|
+
value: syncedBlockValue,
|
|
161
|
+
cloudId: this.config.cloudId
|
|
162
|
+
});
|
|
163
|
+
case 8:
|
|
164
|
+
contentProperty = _context3.sent;
|
|
165
|
+
if (!(((_contentProperty$data3 = contentProperty.data.confluence.updateValuePageProperty.pageProperty) === null || _contentProperty$data3 === void 0 ? void 0 : _contentProperty$data3.key) === key)) {
|
|
166
|
+
_context3.next = 13;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
return _context3.abrupt("return", key);
|
|
170
|
+
case 13:
|
|
171
|
+
if (!(contentProperty.data.confluence.updateValuePageProperty.pageProperty === null)) {
|
|
172
|
+
_context3.next = 17;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncedBlockValue));
|
|
176
|
+
case 17:
|
|
177
|
+
throw new Error('Failed to update content property');
|
|
178
|
+
case 18:
|
|
179
|
+
_context3.next = 22;
|
|
180
|
+
break;
|
|
181
|
+
case 20:
|
|
182
|
+
// Create new content property
|
|
183
|
+
_key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
184
|
+
return _context3.abrupt("return", this.createNewContentProperty(pageId, _key, syncedBlockValue));
|
|
185
|
+
case 22:
|
|
186
|
+
_context3.next = 28;
|
|
187
|
+
break;
|
|
188
|
+
case 24:
|
|
189
|
+
_context3.prev = 24;
|
|
190
|
+
_context3.t0 = _context3["catch"](0);
|
|
191
|
+
// eslint-disable-next-line no-console
|
|
192
|
+
console.error('Failed to write synced block data:', _context3.t0);
|
|
193
|
+
return _context3.abrupt("return", Promise.reject(_context3.t0));
|
|
194
|
+
case 28:
|
|
195
|
+
case "end":
|
|
196
|
+
return _context3.stop();
|
|
197
|
+
}
|
|
198
|
+
}, _callee3, this, [[0, 24]]);
|
|
199
|
+
}));
|
|
200
|
+
function writeData(_x5, _x6, _x7, _x8) {
|
|
201
|
+
return _writeData.apply(this, arguments);
|
|
202
|
+
}
|
|
203
|
+
return writeData;
|
|
204
|
+
}()
|
|
205
|
+
}]);
|
|
206
|
+
}();
|
|
207
|
+
/**
|
|
208
|
+
* Factory function to create both providers with shared configuration
|
|
209
|
+
*/
|
|
210
|
+
var createContentAPIProviders = function createContentAPIProviders(config) {
|
|
211
|
+
var fetchProvider = new ConfluenceADFFetchProvider(config);
|
|
212
|
+
var writeProvider = new ConfluenceADFWriteProvider(config);
|
|
213
|
+
return {
|
|
214
|
+
fetchProvider: fetchProvider,
|
|
215
|
+
writeProvider: writeProvider
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Convenience function to create providers with default content property key
|
|
221
|
+
*/
|
|
222
|
+
export var createContentAPIProvidersWithDefaultKey = function createContentAPIProvidersWithDefaultKey(cloudId) {
|
|
223
|
+
return createContentAPIProviders({
|
|
224
|
+
cloudId: cloudId,
|
|
225
|
+
contentPropertyKey: 'editor-synced-block'
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
export var useMemoizedContentAPIProviders = function useMemoizedContentAPIProviders(cloudId) {
|
|
229
|
+
return useMemo(function () {
|
|
230
|
+
return createContentAPIProvidersWithDefaultKey(cloudId);
|
|
231
|
+
}, [cloudId]);
|
|
232
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export var getConfluencePageAri = function getConfluencePageAri(pageId, cloudId) {
|
|
2
|
+
return "ari:cloud:confluence:".concat(cloudId, ":page/").concat(pageId);
|
|
3
|
+
};
|
|
4
|
+
export var getPageIdFromAri = function getPageIdFromAri(ari) {
|
|
5
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
6
|
+
var match = ari.match(/ari:cloud:confluence:[^:]+:page\/(\d+)/);
|
|
7
|
+
if (match !== null && match !== void 0 && match[1]) {
|
|
8
|
+
return match[1];
|
|
9
|
+
}
|
|
10
|
+
throw new Error("Invalid page ARI: ".concat(ari));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param ari ari:cloud:confluence:<cloudId>:page/<pageId>/<localId>
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export var getLocalIdFromAri = function getLocalIdFromAri(ari) {
|
|
19
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
20
|
+
var match = ari.match(/ari:cloud:confluence:[^:]+:page\/\d+\/([a-zA-Z0-9-]+)/);
|
|
21
|
+
if (match !== null && match !== void 0 && match[1]) {
|
|
22
|
+
return match[1];
|
|
23
|
+
}
|
|
24
|
+
throw new Error("Invalid page ARI: ".concat(ari));
|
|
25
|
+
};
|
|
26
|
+
export var getContentPropertyAri = function getContentPropertyAri(contentPropertyId, cloudId) {
|
|
27
|
+
return "ari:cloud:confluence:".concat(cloudId, ":content/").concat(contentPropertyId);
|
|
28
|
+
};
|
|
29
|
+
export var getContentPropertyIdFromAri = function getContentPropertyIdFromAri(ari) {
|
|
30
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
31
|
+
var match = ari.match(/ari:cloud:confluence:[^:]+:content\/([^/]+)/);
|
|
32
|
+
if (match) {
|
|
33
|
+
return match[1];
|
|
34
|
+
}
|
|
35
|
+
throw new Error("Invalid content property ARI: ".concat(ari));
|
|
36
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
import { getConfluencePageAri } from './ari';
|
|
7
|
+
var COMMON_HEADERS = {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
Accept: 'application/json'
|
|
10
|
+
};
|
|
11
|
+
var AGG_HEADERS = {
|
|
12
|
+
'X-ExperimentalApi': 'confluence-agg-beta'
|
|
13
|
+
};
|
|
14
|
+
var GRAPHQL_ENDPOINT = '/gateway/api/graphql';
|
|
15
|
+
var GET_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET';
|
|
16
|
+
var CREATE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_CREATE';
|
|
17
|
+
var UPDATE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_UPDATE';
|
|
18
|
+
/**
|
|
19
|
+
* Query to get the page property by key
|
|
20
|
+
* @param documentARI
|
|
21
|
+
* @param key
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
var GET_QUERY = "query ".concat(GET_OPERATION_NAME, " ($id: ID!, $keys: [String]!) {\n\t\t\t\t\tconfluence {\n\t\t\t\t\t\tpage (id: $id) {\n\t\t\t\t\t\t\tproperties(keys: $keys) {\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}");
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Query to create a page property with key and value
|
|
28
|
+
* @param documentARI
|
|
29
|
+
* @param key
|
|
30
|
+
* @param value
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
var CREATE_QUERY = "mutation ".concat(CREATE_OPERATION_NAME, " ($input: ConfluenceCreatePagePropertyInput!){\n\t\t\t\t\t\tconfluence {\n\t\t\t\t\t\t\tcreatePageProperty(input: $input) {\n\t\t\t\t\t\t\t\tpageProperty {\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}");
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Query to update a page property with key and value without bumping the version
|
|
37
|
+
* @param documentARI
|
|
38
|
+
* @param key
|
|
39
|
+
* @param value
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
var UPDATE_QUERY = "mutation ".concat(UPDATE_OPERATION_NAME, " ($input: ConfluenceUpdateValuePagePropertyInput!) {\n\t\t\t\t\t\tconfluence {\n\t\t\t\t\t\t\tupdateValuePageProperty(input: $input) {\n\t\t\t\t\t\t\t\tpageProperty {\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}");
|
|
43
|
+
export var getContentProperty = /*#__PURE__*/function () {
|
|
44
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
45
|
+
var pageId, key, cloudId, documentARI, bodyData, response, contentProperty;
|
|
46
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
47
|
+
while (1) switch (_context.prev = _context.next) {
|
|
48
|
+
case 0:
|
|
49
|
+
pageId = _ref.pageId, key = _ref.key, cloudId = _ref.cloudId;
|
|
50
|
+
documentARI = getConfluencePageAri(pageId, cloudId);
|
|
51
|
+
bodyData = {
|
|
52
|
+
query: GET_QUERY,
|
|
53
|
+
operationName: GET_OPERATION_NAME,
|
|
54
|
+
variables: {
|
|
55
|
+
id: documentARI,
|
|
56
|
+
keys: [key]
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
_context.next = 5;
|
|
60
|
+
return fetch(GRAPHQL_ENDPOINT, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
|
|
63
|
+
body: JSON.stringify(bodyData)
|
|
64
|
+
});
|
|
65
|
+
case 5:
|
|
66
|
+
response = _context.sent;
|
|
67
|
+
if (response.ok) {
|
|
68
|
+
_context.next = 8;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
throw new Error("Failed to get content property: ".concat(response.statusText));
|
|
72
|
+
case 8:
|
|
73
|
+
_context.next = 10;
|
|
74
|
+
return response.json();
|
|
75
|
+
case 10:
|
|
76
|
+
contentProperty = _context.sent;
|
|
77
|
+
return _context.abrupt("return", contentProperty);
|
|
78
|
+
case 12:
|
|
79
|
+
case "end":
|
|
80
|
+
return _context.stop();
|
|
81
|
+
}
|
|
82
|
+
}, _callee);
|
|
83
|
+
}));
|
|
84
|
+
return function getContentProperty(_x) {
|
|
85
|
+
return _ref2.apply(this, arguments);
|
|
86
|
+
};
|
|
87
|
+
}();
|
|
88
|
+
export var updateContentProperty = /*#__PURE__*/function () {
|
|
89
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
|
|
90
|
+
var pageId, key, value, cloudId, documentARI, bodyData, response, contentProperty;
|
|
91
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
92
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
pageId = _ref3.pageId, key = _ref3.key, value = _ref3.value, cloudId = _ref3.cloudId;
|
|
95
|
+
documentARI = getConfluencePageAri(pageId, cloudId);
|
|
96
|
+
bodyData = {
|
|
97
|
+
query: UPDATE_QUERY,
|
|
98
|
+
operationName: UPDATE_OPERATION_NAME,
|
|
99
|
+
variables: {
|
|
100
|
+
input: {
|
|
101
|
+
pageId: documentARI,
|
|
102
|
+
key: key,
|
|
103
|
+
value: value,
|
|
104
|
+
useSameVersion: true
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
_context2.next = 5;
|
|
109
|
+
return fetch(GRAPHQL_ENDPOINT, {
|
|
110
|
+
method: 'POST',
|
|
111
|
+
headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
|
|
112
|
+
body: JSON.stringify(bodyData)
|
|
113
|
+
});
|
|
114
|
+
case 5:
|
|
115
|
+
response = _context2.sent;
|
|
116
|
+
if (response.ok) {
|
|
117
|
+
_context2.next = 8;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
throw new Error("Failed to update content property: ".concat(response.statusText));
|
|
121
|
+
case 8:
|
|
122
|
+
_context2.next = 10;
|
|
123
|
+
return response.json();
|
|
124
|
+
case 10:
|
|
125
|
+
contentProperty = _context2.sent;
|
|
126
|
+
return _context2.abrupt("return", contentProperty);
|
|
127
|
+
case 12:
|
|
128
|
+
case "end":
|
|
129
|
+
return _context2.stop();
|
|
130
|
+
}
|
|
131
|
+
}, _callee2);
|
|
132
|
+
}));
|
|
133
|
+
return function updateContentProperty(_x2) {
|
|
134
|
+
return _ref4.apply(this, arguments);
|
|
135
|
+
};
|
|
136
|
+
}();
|
|
137
|
+
export var createContentProperty = /*#__PURE__*/function () {
|
|
138
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
|
|
139
|
+
var pageId, key, value, cloudId, documentARI, escapedValue, bodyData, response, contentProperty;
|
|
140
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
141
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
142
|
+
case 0:
|
|
143
|
+
pageId = _ref5.pageId, key = _ref5.key, value = _ref5.value, cloudId = _ref5.cloudId;
|
|
144
|
+
documentARI = getConfluencePageAri(pageId, cloudId); // eslint-disable-next-line require-unicode-regexp
|
|
145
|
+
escapedValue = value.replace(/"/g, '\\"');
|
|
146
|
+
bodyData = {
|
|
147
|
+
query: CREATE_QUERY,
|
|
148
|
+
operationName: CREATE_OPERATION_NAME,
|
|
149
|
+
variables: {
|
|
150
|
+
input: {
|
|
151
|
+
pageId: documentARI,
|
|
152
|
+
key: key,
|
|
153
|
+
value: escapedValue
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
_context3.next = 6;
|
|
158
|
+
return fetch(GRAPHQL_ENDPOINT, {
|
|
159
|
+
method: 'POST',
|
|
160
|
+
headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
|
|
161
|
+
body: JSON.stringify(bodyData)
|
|
162
|
+
});
|
|
163
|
+
case 6:
|
|
164
|
+
response = _context3.sent;
|
|
165
|
+
if (response.ok) {
|
|
166
|
+
_context3.next = 9;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
throw new Error("Failed to create content property: ".concat(response.statusText));
|
|
170
|
+
case 9:
|
|
171
|
+
_context3.next = 11;
|
|
172
|
+
return response.json();
|
|
173
|
+
case 11:
|
|
174
|
+
contentProperty = _context3.sent;
|
|
175
|
+
return _context3.abrupt("return", contentProperty);
|
|
176
|
+
case 13:
|
|
177
|
+
case "end":
|
|
178
|
+
return _context3.stop();
|
|
179
|
+
}
|
|
180
|
+
}, _callee3);
|
|
181
|
+
}));
|
|
182
|
+
return function createContentProperty(_x3) {
|
|
183
|
+
return _ref6.apply(this, arguments);
|
|
184
|
+
};
|
|
185
|
+
}();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We currently do not need any of the new features, like nested tables
|
|
3
|
+
* Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
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">;
|
|
@@ -20,5 +20,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
20
20
|
* @returns the resource ids of the nodes that were written
|
|
21
21
|
*/
|
|
22
22
|
writeNodesData: (nodes: SyncBlockNode[], data: SyncBlockData[]) => Promise<Array<string | undefined>>;
|
|
23
|
+
getSourceId: () => string;
|
|
23
24
|
}
|
|
24
|
-
export declare const useFetchDocNode: (editorView: EditorView, node: PMNode, defaultDocNode: DocNode, provider?:
|
|
25
|
+
export declare const useFetchDocNode: (editorView: EditorView, node: PMNode, defaultDocNode: DocNode, provider?: SyncBlockDataProvider) => DocNode;
|
|
26
|
+
export declare const useMemoizedSyncedBlockProvider: (fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string) => SyncBlockProvider;
|
|
@@ -17,7 +17,8 @@ export declare class SyncBlockStoreManager {
|
|
|
17
17
|
private syncBlocks;
|
|
18
18
|
private confirmationCallback?;
|
|
19
19
|
private editorView?;
|
|
20
|
-
|
|
20
|
+
private dataProvider?;
|
|
21
|
+
constructor(dataProvider?: SyncBlockDataProvider);
|
|
21
22
|
setEditorView(editorView: EditorView | undefined): void;
|
|
22
23
|
isSourceBlock(node: PMNode): boolean;
|
|
23
24
|
registerConfirmationCallback(callback: ConfirmationCallback): () => void;
|
|
@@ -12,6 +12,7 @@ export type SyncBlockNode = {
|
|
|
12
12
|
};
|
|
13
13
|
export type SyncBlockData = {
|
|
14
14
|
content: ADFEntity | undefined;
|
|
15
|
+
resourceId?: string;
|
|
15
16
|
};
|
|
16
17
|
export interface ADFFetchProvider {
|
|
17
18
|
fetchData: (resourceId: string) => Promise<SyncBlockData>;
|
|
@@ -21,4 +22,5 @@ export interface ADFWriteProvider {
|
|
|
21
22
|
}
|
|
22
23
|
export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockData> {
|
|
23
24
|
abstract writeNodesData: (nodes: SyncBlockNode[], data: SyncBlockData[]) => Promise<Array<string | undefined>>;
|
|
25
|
+
abstract getSourceId: () => string;
|
|
24
26
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export { SyncBlockProvider as SyncedBlockProvider, useFetchDocNode, } from './common/syncBlockProvider';
|
|
1
|
+
export { SyncBlockProvider as SyncedBlockProvider, useFetchDocNode, useMemoizedSyncedBlockProvider, } from './common/syncBlockProvider';
|
|
2
2
|
export { SyncBlockStoreManager } from './common/syncBlockStoreManager';
|
|
3
3
|
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockData, SyncBlockNode, } from './common/types';
|
|
4
4
|
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
|
|
5
|
+
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
6
|
+
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluenceContentAPI';
|
|
7
|
+
export { getConfluencePageAri } from './utils/ari';
|
|
5
8
|
export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
|
+
import type { ADFFetchProvider, ADFWriteProvider, SyncBlockData } from '../common/types';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for Content API providers
|
|
5
|
+
*/
|
|
6
|
+
interface ContentAPIConfig {
|
|
7
|
+
cloudId: string;
|
|
8
|
+
contentPropertyKey: string;
|
|
9
|
+
}
|
|
10
|
+
export type SyncedBlockContentPropertyValue = {
|
|
11
|
+
content?: ADFEntity;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* ADFFetchProvider implementation that fetches synced block data from Confluence Content API
|
|
15
|
+
*/
|
|
16
|
+
declare class ConfluenceADFFetchProvider implements ADFFetchProvider {
|
|
17
|
+
private config;
|
|
18
|
+
constructor(config: ContentAPIConfig);
|
|
19
|
+
fetchData(resourceId: string): Promise<SyncBlockData>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* ADFWriteProvider implementation that writes synced block data to Confluence Content API
|
|
23
|
+
*/
|
|
24
|
+
declare class ConfluenceADFWriteProvider implements ADFWriteProvider {
|
|
25
|
+
private config;
|
|
26
|
+
constructor(config: ContentAPIConfig);
|
|
27
|
+
private createNewContentProperty;
|
|
28
|
+
writeData(sourceId: string, localId: string, data: ADFEntity, resourceId?: string): Promise<string>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convenience function to create providers with default content property key
|
|
32
|
+
*/
|
|
33
|
+
export declare const createContentAPIProvidersWithDefaultKey: (cloudId: string) => {
|
|
34
|
+
fetchProvider: ConfluenceADFFetchProvider;
|
|
35
|
+
writeProvider: ConfluenceADFWriteProvider;
|
|
36
|
+
};
|
|
37
|
+
export declare const useMemoizedContentAPIProviders: (cloudId: string) => {
|
|
38
|
+
fetchProvider: ConfluenceADFFetchProvider;
|
|
39
|
+
writeProvider: ConfluenceADFWriteProvider;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const getConfluencePageAri: (pageId: string, cloudId: string) => string;
|
|
2
|
+
export declare const getPageIdFromAri: (ari: string) => string;
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param ari ari:cloud:confluence:<cloudId>:page/<pageId>/<localId>
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const getLocalIdFromAri: (ari: string) => string;
|
|
9
|
+
export declare const getContentPropertyAri: (contentPropertyId: string, cloudId: string) => string;
|
|
10
|
+
export declare const getContentPropertyIdFromAri: (ari: string) => string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
type GetContentPropertyOptions = {
|
|
2
|
+
cloudId: string;
|
|
3
|
+
key: string;
|
|
4
|
+
pageId: string;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
};
|
|
7
|
+
type CreateContentPropertyOptions = {
|
|
8
|
+
cloudId: string;
|
|
9
|
+
key: string;
|
|
10
|
+
pageId: string;
|
|
11
|
+
value: string;
|
|
12
|
+
};
|
|
13
|
+
type UpdateContentPropertyOptions = {
|
|
14
|
+
cloudId: string;
|
|
15
|
+
key: string;
|
|
16
|
+
pageId: string;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
export type GetContentPropertyResult = {
|
|
21
|
+
data: {
|
|
22
|
+
confluence: {
|
|
23
|
+
page: {
|
|
24
|
+
properties: [
|
|
25
|
+
{
|
|
26
|
+
key: string | null;
|
|
27
|
+
value: string | null;
|
|
28
|
+
}
|
|
29
|
+
] | null;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type UpdateContentPropertyResult = {
|
|
35
|
+
data: {
|
|
36
|
+
confluence: {
|
|
37
|
+
updateValuePageProperty: {
|
|
38
|
+
pageProperty: {
|
|
39
|
+
key: string | null;
|
|
40
|
+
value: string | null;
|
|
41
|
+
} | null;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export type CreateContentPropertyResult = {
|
|
47
|
+
data: {
|
|
48
|
+
confluence: {
|
|
49
|
+
createPageProperty: {
|
|
50
|
+
pageProperty: {
|
|
51
|
+
key: string | null;
|
|
52
|
+
value: string | null;
|
|
53
|
+
} | null;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export declare const getContentProperty: ({ pageId, key, cloudId, }: GetContentPropertyOptions) => Promise<GetContentPropertyResult>;
|
|
59
|
+
export declare const updateContentProperty: ({ pageId, key, value, cloudId, }: UpdateContentPropertyOptions) => Promise<UpdateContentPropertyResult>;
|
|
60
|
+
export declare const createContentProperty: ({ pageId, key, value, cloudId, }: CreateContentPropertyOptions) => Promise<CreateContentPropertyResult>;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We currently do not need any of the new features, like nested tables
|
|
3
|
+
* Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
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">;
|
|
@@ -20,5 +20,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
20
20
|
* @returns the resource ids of the nodes that were written
|
|
21
21
|
*/
|
|
22
22
|
writeNodesData: (nodes: SyncBlockNode[], data: SyncBlockData[]) => Promise<Array<string | undefined>>;
|
|
23
|
+
getSourceId: () => string;
|
|
23
24
|
}
|
|
24
|
-
export declare const useFetchDocNode: (editorView: EditorView, node: PMNode, defaultDocNode: DocNode, provider?:
|
|
25
|
+
export declare const useFetchDocNode: (editorView: EditorView, node: PMNode, defaultDocNode: DocNode, provider?: SyncBlockDataProvider) => DocNode;
|
|
26
|
+
export declare const useMemoizedSyncedBlockProvider: (fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string) => SyncBlockProvider;
|
|
@@ -17,7 +17,8 @@ export declare class SyncBlockStoreManager {
|
|
|
17
17
|
private syncBlocks;
|
|
18
18
|
private confirmationCallback?;
|
|
19
19
|
private editorView?;
|
|
20
|
-
|
|
20
|
+
private dataProvider?;
|
|
21
|
+
constructor(dataProvider?: SyncBlockDataProvider);
|
|
21
22
|
setEditorView(editorView: EditorView | undefined): void;
|
|
22
23
|
isSourceBlock(node: PMNode): boolean;
|
|
23
24
|
registerConfirmationCallback(callback: ConfirmationCallback): () => void;
|
|
@@ -12,6 +12,7 @@ export type SyncBlockNode = {
|
|
|
12
12
|
};
|
|
13
13
|
export type SyncBlockData = {
|
|
14
14
|
content: ADFEntity | undefined;
|
|
15
|
+
resourceId?: string;
|
|
15
16
|
};
|
|
16
17
|
export interface ADFFetchProvider {
|
|
17
18
|
fetchData: (resourceId: string) => Promise<SyncBlockData>;
|
|
@@ -21,4 +22,5 @@ export interface ADFWriteProvider {
|
|
|
21
22
|
}
|
|
22
23
|
export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockData> {
|
|
23
24
|
abstract writeNodesData: (nodes: SyncBlockNode[], data: SyncBlockData[]) => Promise<Array<string | undefined>>;
|
|
25
|
+
abstract getSourceId: () => string;
|
|
24
26
|
}
|