@atlaskit/editor-synced-block-provider 0.5.0 → 0.5.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 +7 -0
- package/dist/cjs/common/syncBlockStoreManager.js +10 -4
- package/dist/cjs/providers/confluenceContentAPI.js +17 -11
- package/dist/cjs/utils/ari.js +4 -1
- package/dist/es2019/common/syncBlockStoreManager.js +10 -4
- package/dist/es2019/providers/confluenceContentAPI.js +4 -1
- package/dist/es2019/utils/ari.js +3 -0
- package/dist/esm/common/syncBlockStoreManager.js +10 -4
- package/dist/esm/providers/confluenceContentAPI.js +18 -12
- package/dist/esm/utils/ari.js +3 -0
- package/dist/types/utils/ari.d.ts +1 -0
- package/dist/types-ts4.5/utils/ari.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
10
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
12
|
var _uuid = _interopRequireDefault(require("uuid"));
|
|
13
|
+
var _ari = require("../utils/ari");
|
|
13
14
|
var _rebaseTransaction2 = require("./rebase-transaction");
|
|
14
15
|
// Do this typedef to make it clear that
|
|
15
16
|
// this is a local identifier for a resource for local use
|
|
@@ -32,13 +33,18 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
32
33
|
}, {
|
|
33
34
|
key: "isSourceBlock",
|
|
34
35
|
value: function isSourceBlock(node) {
|
|
36
|
+
var _this$dataProvider;
|
|
35
37
|
if (node.type.name !== 'syncBlock') {
|
|
36
38
|
return false;
|
|
37
39
|
}
|
|
38
40
|
var _node$attrs = node.attrs,
|
|
39
41
|
resourceId = _node$attrs.resourceId,
|
|
40
42
|
localId = _node$attrs.localId;
|
|
41
|
-
|
|
43
|
+
var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
44
|
+
if (!sourceId) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return typeof resourceId === 'string' && typeof sourceId === 'string' && typeof localId === 'string' && resourceId === (0, _ari.resourceIdFromSourceAndLocalId)(sourceId, localId);
|
|
42
48
|
}
|
|
43
49
|
}, {
|
|
44
50
|
key: "registerConfirmationCallback",
|
|
@@ -57,10 +63,10 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
57
63
|
}, {
|
|
58
64
|
key: "createSyncBlockNode",
|
|
59
65
|
value: function createSyncBlockNode() {
|
|
60
|
-
var _this$
|
|
66
|
+
var _this$dataProvider2;
|
|
61
67
|
var localId = (0, _uuid.default)();
|
|
62
|
-
var sourceId = (_this$
|
|
63
|
-
var resourceId = sourceId ?
|
|
68
|
+
var sourceId = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.getSourceId();
|
|
69
|
+
var resourceId = sourceId ? (0, _ari.resourceIdFromSourceAndLocalId)(sourceId, localId) : localId;
|
|
64
70
|
var syncBlockNode = {
|
|
65
71
|
attrs: {
|
|
66
72
|
resourceId: resourceId,
|
|
@@ -142,46 +142,52 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
142
142
|
while (1) switch (_context3.prev = _context3.next) {
|
|
143
143
|
case 0:
|
|
144
144
|
pageId = (0, _ari.getPageIdFromAri)(data.resourceId);
|
|
145
|
+
if (!(data.sourceDocumentAri && data.resourceId !== (0, _ari.resourceIdFromSourceAndLocalId)(data.sourceDocumentAri, data.localId))) {
|
|
146
|
+
_context3.next = 3;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
return _context3.abrupt("return", Promise.reject('Resource ARI differs from source document ARI'));
|
|
150
|
+
case 3:
|
|
145
151
|
syncedBlockValue = JSON.stringify({
|
|
146
152
|
content: data.content
|
|
147
153
|
});
|
|
148
154
|
if (!data.resourceId) {
|
|
149
|
-
_context3.next =
|
|
155
|
+
_context3.next = 21;
|
|
150
156
|
break;
|
|
151
157
|
}
|
|
152
158
|
// Update existing content property
|
|
153
159
|
localId = (0, _ari.getLocalIdFromAri)(data.resourceId);
|
|
154
160
|
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
155
|
-
_context3.next =
|
|
161
|
+
_context3.next = 9;
|
|
156
162
|
return (0, _contentProperty.updateContentProperty)({
|
|
157
163
|
pageId: pageId,
|
|
158
164
|
key: key,
|
|
159
165
|
value: syncedBlockValue,
|
|
160
166
|
cloudId: this.config.cloudId
|
|
161
167
|
});
|
|
162
|
-
case
|
|
168
|
+
case 9:
|
|
163
169
|
contentProperty = _context3.sent;
|
|
164
170
|
if (!(((_contentProperty$data3 = contentProperty.data.confluence.updateValuePageProperty.pageProperty) === null || _contentProperty$data3 === void 0 ? void 0 : _contentProperty$data3.key) === key)) {
|
|
165
|
-
_context3.next =
|
|
171
|
+
_context3.next = 14;
|
|
166
172
|
break;
|
|
167
173
|
}
|
|
168
174
|
return _context3.abrupt("return", key);
|
|
169
|
-
case
|
|
175
|
+
case 14:
|
|
170
176
|
if (!(contentProperty.data.confluence.updateValuePageProperty.pageProperty === null)) {
|
|
171
|
-
_context3.next =
|
|
177
|
+
_context3.next = 18;
|
|
172
178
|
break;
|
|
173
179
|
}
|
|
174
180
|
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncedBlockValue));
|
|
175
|
-
case
|
|
181
|
+
case 18:
|
|
176
182
|
throw new Error('Failed to update content property');
|
|
177
|
-
case 17:
|
|
178
|
-
_context3.next = 21;
|
|
179
|
-
break;
|
|
180
183
|
case 19:
|
|
184
|
+
_context3.next = 23;
|
|
185
|
+
break;
|
|
186
|
+
case 21:
|
|
181
187
|
// Create new content property
|
|
182
188
|
_key = getContentPropertyKey(this.config.contentPropertyKey, data.localId);
|
|
183
189
|
return _context3.abrupt("return", this.createNewContentProperty(pageId, _key, syncedBlockValue));
|
|
184
|
-
case
|
|
190
|
+
case 23:
|
|
185
191
|
case "end":
|
|
186
192
|
return _context3.stop();
|
|
187
193
|
}
|
package/dist/cjs/utils/ari.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getPageIdFromAri = exports.getLocalIdFromAri = exports.getContentPropertyIdFromAri = exports.getContentPropertyAri = exports.getConfluencePageAri = void 0;
|
|
6
|
+
exports.resourceIdFromSourceAndLocalId = exports.getPageIdFromAri = exports.getLocalIdFromAri = exports.getContentPropertyIdFromAri = exports.getContentPropertyAri = exports.getConfluencePageAri = void 0;
|
|
7
7
|
var getConfluencePageAri = exports.getConfluencePageAri = function getConfluencePageAri(pageId, cloudId) {
|
|
8
8
|
return "ari:cloud:confluence:".concat(cloudId, ":page/").concat(pageId);
|
|
9
9
|
};
|
|
@@ -39,4 +39,7 @@ var getContentPropertyIdFromAri = exports.getContentPropertyIdFromAri = function
|
|
|
39
39
|
return match[1];
|
|
40
40
|
}
|
|
41
41
|
throw new Error("Invalid content property ARI: ".concat(ari));
|
|
42
|
+
};
|
|
43
|
+
var resourceIdFromSourceAndLocalId = exports.resourceIdFromSourceAndLocalId = function resourceIdFromSourceAndLocalId(sourceId, localId) {
|
|
44
|
+
return sourceId + '/' + localId;
|
|
42
45
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import uuid from 'uuid';
|
|
2
|
+
import { resourceIdFromSourceAndLocalId } from '../utils/ari';
|
|
2
3
|
import { rebaseTransaction } from './rebase-transaction';
|
|
3
4
|
|
|
4
5
|
// Do this typedef to make it clear that
|
|
@@ -18,6 +19,7 @@ export class SyncBlockStoreManager {
|
|
|
18
19
|
this.editorView = editorView;
|
|
19
20
|
}
|
|
20
21
|
isSourceBlock(node) {
|
|
22
|
+
var _this$dataProvider;
|
|
21
23
|
if (node.type.name !== 'syncBlock') {
|
|
22
24
|
return false;
|
|
23
25
|
}
|
|
@@ -25,7 +27,11 @@ export class SyncBlockStoreManager {
|
|
|
25
27
|
resourceId,
|
|
26
28
|
localId
|
|
27
29
|
} = node.attrs;
|
|
28
|
-
|
|
30
|
+
const sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
31
|
+
if (!sourceId) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return typeof resourceId === 'string' && typeof sourceId === 'string' && typeof localId === 'string' && resourceId === resourceIdFromSourceAndLocalId(sourceId, localId);
|
|
29
35
|
}
|
|
30
36
|
registerConfirmationCallback(callback) {
|
|
31
37
|
this.confirmationCallback = callback;
|
|
@@ -37,10 +43,10 @@ export class SyncBlockStoreManager {
|
|
|
37
43
|
return !!this.confirmationCallback;
|
|
38
44
|
}
|
|
39
45
|
createSyncBlockNode() {
|
|
40
|
-
var _this$
|
|
46
|
+
var _this$dataProvider2;
|
|
41
47
|
const localId = uuid();
|
|
42
|
-
const sourceId = (_this$
|
|
43
|
-
const resourceId = sourceId ?
|
|
48
|
+
const sourceId = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.getSourceId();
|
|
49
|
+
const resourceId = sourceId ? resourceIdFromSourceAndLocalId(sourceId, localId) : localId;
|
|
44
50
|
const syncBlockNode = {
|
|
45
51
|
attrs: {
|
|
46
52
|
resourceId,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { getLocalIdFromAri, getPageIdFromAri } from '../utils/ari';
|
|
3
|
+
import { getLocalIdFromAri, getPageIdFromAri, resourceIdFromSourceAndLocalId } from '../utils/ari';
|
|
4
4
|
import { getContentProperty, createContentProperty, updateContentProperty } from '../utils/contentProperty';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -81,6 +81,9 @@ class ConfluenceADFWriteProvider {
|
|
|
81
81
|
}
|
|
82
82
|
async writeData(data) {
|
|
83
83
|
const pageId = getPageIdFromAri(data.resourceId);
|
|
84
|
+
if (data.sourceDocumentAri && data.resourceId !== resourceIdFromSourceAndLocalId(data.sourceDocumentAri, data.localId)) {
|
|
85
|
+
return Promise.reject('Resource ARI differs from source document ARI');
|
|
86
|
+
}
|
|
84
87
|
const syncedBlockValue = JSON.stringify({
|
|
85
88
|
content: data.content
|
|
86
89
|
});
|
package/dist/es2019/utils/ari.js
CHANGED
|
@@ -3,6 +3,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
|
3
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
import uuid from 'uuid';
|
|
6
|
+
import { resourceIdFromSourceAndLocalId } from '../utils/ari';
|
|
6
7
|
import { rebaseTransaction as _rebaseTransaction } from './rebase-transaction';
|
|
7
8
|
|
|
8
9
|
// Do this typedef to make it clear that
|
|
@@ -27,13 +28,18 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
27
28
|
}, {
|
|
28
29
|
key: "isSourceBlock",
|
|
29
30
|
value: function isSourceBlock(node) {
|
|
31
|
+
var _this$dataProvider;
|
|
30
32
|
if (node.type.name !== 'syncBlock') {
|
|
31
33
|
return false;
|
|
32
34
|
}
|
|
33
35
|
var _node$attrs = node.attrs,
|
|
34
36
|
resourceId = _node$attrs.resourceId,
|
|
35
37
|
localId = _node$attrs.localId;
|
|
36
|
-
|
|
38
|
+
var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
39
|
+
if (!sourceId) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return typeof resourceId === 'string' && typeof sourceId === 'string' && typeof localId === 'string' && resourceId === resourceIdFromSourceAndLocalId(sourceId, localId);
|
|
37
43
|
}
|
|
38
44
|
}, {
|
|
39
45
|
key: "registerConfirmationCallback",
|
|
@@ -52,10 +58,10 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
52
58
|
}, {
|
|
53
59
|
key: "createSyncBlockNode",
|
|
54
60
|
value: function createSyncBlockNode() {
|
|
55
|
-
var _this$
|
|
61
|
+
var _this$dataProvider2;
|
|
56
62
|
var localId = uuid();
|
|
57
|
-
var sourceId = (_this$
|
|
58
|
-
var resourceId = sourceId ?
|
|
63
|
+
var sourceId = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.getSourceId();
|
|
64
|
+
var resourceId = sourceId ? resourceIdFromSourceAndLocalId(sourceId, localId) : localId;
|
|
59
65
|
var syncBlockNode = {
|
|
60
66
|
attrs: {
|
|
61
67
|
resourceId: resourceId,
|
|
@@ -4,7 +4,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
|
4
4
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
5
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
6
|
import { useMemo } from 'react';
|
|
7
|
-
import { getLocalIdFromAri, getPageIdFromAri } from '../utils/ari';
|
|
7
|
+
import { getLocalIdFromAri, getPageIdFromAri, resourceIdFromSourceAndLocalId } from '../utils/ari';
|
|
8
8
|
import { getContentProperty, createContentProperty, updateContentProperty } from '../utils/contentProperty';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -136,46 +136,52 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
136
136
|
while (1) switch (_context3.prev = _context3.next) {
|
|
137
137
|
case 0:
|
|
138
138
|
pageId = getPageIdFromAri(data.resourceId);
|
|
139
|
+
if (!(data.sourceDocumentAri && data.resourceId !== resourceIdFromSourceAndLocalId(data.sourceDocumentAri, data.localId))) {
|
|
140
|
+
_context3.next = 3;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
return _context3.abrupt("return", Promise.reject('Resource ARI differs from source document ARI'));
|
|
144
|
+
case 3:
|
|
139
145
|
syncedBlockValue = JSON.stringify({
|
|
140
146
|
content: data.content
|
|
141
147
|
});
|
|
142
148
|
if (!data.resourceId) {
|
|
143
|
-
_context3.next =
|
|
149
|
+
_context3.next = 21;
|
|
144
150
|
break;
|
|
145
151
|
}
|
|
146
152
|
// Update existing content property
|
|
147
153
|
localId = getLocalIdFromAri(data.resourceId);
|
|
148
154
|
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
149
|
-
_context3.next =
|
|
155
|
+
_context3.next = 9;
|
|
150
156
|
return updateContentProperty({
|
|
151
157
|
pageId: pageId,
|
|
152
158
|
key: key,
|
|
153
159
|
value: syncedBlockValue,
|
|
154
160
|
cloudId: this.config.cloudId
|
|
155
161
|
});
|
|
156
|
-
case
|
|
162
|
+
case 9:
|
|
157
163
|
contentProperty = _context3.sent;
|
|
158
164
|
if (!(((_contentProperty$data3 = contentProperty.data.confluence.updateValuePageProperty.pageProperty) === null || _contentProperty$data3 === void 0 ? void 0 : _contentProperty$data3.key) === key)) {
|
|
159
|
-
_context3.next =
|
|
165
|
+
_context3.next = 14;
|
|
160
166
|
break;
|
|
161
167
|
}
|
|
162
168
|
return _context3.abrupt("return", key);
|
|
163
|
-
case
|
|
169
|
+
case 14:
|
|
164
170
|
if (!(contentProperty.data.confluence.updateValuePageProperty.pageProperty === null)) {
|
|
165
|
-
_context3.next =
|
|
171
|
+
_context3.next = 18;
|
|
166
172
|
break;
|
|
167
173
|
}
|
|
168
174
|
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncedBlockValue));
|
|
169
|
-
case
|
|
175
|
+
case 18:
|
|
170
176
|
throw new Error('Failed to update content property');
|
|
171
|
-
case 17:
|
|
172
|
-
_context3.next = 21;
|
|
173
|
-
break;
|
|
174
177
|
case 19:
|
|
178
|
+
_context3.next = 23;
|
|
179
|
+
break;
|
|
180
|
+
case 21:
|
|
175
181
|
// Create new content property
|
|
176
182
|
_key = getContentPropertyKey(this.config.contentPropertyKey, data.localId);
|
|
177
183
|
return _context3.abrupt("return", this.createNewContentProperty(pageId, _key, syncedBlockValue));
|
|
178
|
-
case
|
|
184
|
+
case 23:
|
|
179
185
|
case "end":
|
|
180
186
|
return _context3.stop();
|
|
181
187
|
}
|
package/dist/esm/utils/ari.js
CHANGED
|
@@ -33,4 +33,7 @@ export var getContentPropertyIdFromAri = function getContentPropertyIdFromAri(ar
|
|
|
33
33
|
return match[1];
|
|
34
34
|
}
|
|
35
35
|
throw new Error("Invalid content property ARI: ".concat(ari));
|
|
36
|
+
};
|
|
37
|
+
export var resourceIdFromSourceAndLocalId = function resourceIdFromSourceAndLocalId(sourceId, localId) {
|
|
38
|
+
return sourceId + '/' + localId;
|
|
36
39
|
};
|
|
@@ -8,3 +8,4 @@ export declare const getPageIdFromAri: (ari: string) => string;
|
|
|
8
8
|
export declare const getLocalIdFromAri: (ari: string) => string;
|
|
9
9
|
export declare const getContentPropertyAri: (contentPropertyId: string, cloudId: string) => string;
|
|
10
10
|
export declare const getContentPropertyIdFromAri: (ari: string) => string;
|
|
11
|
+
export declare const resourceIdFromSourceAndLocalId: (sourceId: string, localId: string) => string;
|
|
@@ -8,3 +8,4 @@ export declare const getPageIdFromAri: (ari: string) => string;
|
|
|
8
8
|
export declare const getLocalIdFromAri: (ari: string) => string;
|
|
9
9
|
export declare const getContentPropertyAri: (contentPropertyId: string, cloudId: string) => string;
|
|
10
10
|
export declare const getContentPropertyIdFromAri: (ari: string) => string;
|
|
11
|
+
export declare const resourceIdFromSourceAndLocalId: (sourceId: string, localId: string) => string;
|
package/package.json
CHANGED