@atlaskit/editor-synced-block-provider 0.2.0 → 0.4.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/rebase-transaction.js +31 -0
- package/dist/cjs/common/syncBlockProvider.js +24 -12
- package/dist/cjs/common/syncBlockStoreManager.js +24 -11
- package/dist/cjs/index.js +34 -1
- 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/rebase-transaction.js +26 -0
- package/dist/es2019/common/syncBlockProvider.js +25 -13
- package/dist/es2019/common/syncBlockStoreManager.js +18 -7
- package/dist/es2019/index.js +5 -2
- 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/rebase-transaction.js +26 -0
- package/dist/esm/common/syncBlockProvider.js +24 -12
- package/dist/esm/common/syncBlockStoreManager.js +24 -11
- package/dist/esm/index.js +5 -2
- 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/rebase-transaction.d.ts +11 -0
- package/dist/types/common/syncBlockProvider.d.ts +3 -1
- package/dist/types/common/syncBlockStoreManager.d.ts +5 -2
- package/dist/types/common/types.d.ts +1 -0
- package/dist/types/index.d.ts +5 -2
- 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/rebase-transaction.d.ts +11 -0
- package/dist/types-ts4.5/common/syncBlockProvider.d.ts +3 -1
- package/dist/types-ts4.5/common/syncBlockStoreManager.d.ts +5 -2
- package/dist/types-ts4.5/common/types.d.ts +1 -0
- package/dist/types-ts4.5/index.d.ts +5 -2
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`acb8231bc9e0c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/acb8231bc9e0c) -
|
|
8
|
+
EDITOR-1779 - "rebase" the transaction to reflect the latest document state
|
|
9
|
+
|
|
10
|
+
## 0.3.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [`9e7a5a0bb1869`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9e7a5a0bb1869) -
|
|
15
|
+
Add content api sync block provider
|
|
16
|
+
|
|
3
17
|
## 0.2.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rebaseTransaction = void 0;
|
|
7
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
8
|
+
/**
|
|
9
|
+
* Rebase `currentTr` over `incomingTr` based on the provided `state`.
|
|
10
|
+
* This function adjusts the steps in `currentTr` to account for the changes made by `incomingTr`.
|
|
11
|
+
*
|
|
12
|
+
* @param currentTr - The transaction to be rebased.
|
|
13
|
+
* @param incomingTr - The transaction that has already been applied to the state.
|
|
14
|
+
* @param state - The editor state after applying `incomingTr`.
|
|
15
|
+
* @returns A new transaction that represents `currentTr` rebased over `incomingTr`.
|
|
16
|
+
*/
|
|
17
|
+
var rebaseTransaction = exports.rebaseTransaction = function rebaseTransaction(currentTr, incomingTr, state) {
|
|
18
|
+
if (!incomingTr.docChanged) {
|
|
19
|
+
return currentTr;
|
|
20
|
+
}
|
|
21
|
+
var currentMapping = new _transform.Mapping(incomingTr.mapping.maps);
|
|
22
|
+
var rebasedTransaction = state.tr;
|
|
23
|
+
currentTr.steps.forEach(function (step) {
|
|
24
|
+
var mappedStep = step.map(currentMapping);
|
|
25
|
+
if (mappedStep) {
|
|
26
|
+
rebasedTransaction.step(mappedStep);
|
|
27
|
+
currentMapping.appendMap(mappedStep.getMap());
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return rebasedTransaction;
|
|
31
|
+
};
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.useFetchDocNode = exports.SyncBlockProvider = void 0;
|
|
7
|
+
exports.useMemoizedSyncedBlockProvider = exports.useFetchDocNode = exports.SyncBlockProvider = void 0;
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
@@ -55,6 +55,9 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
55
55
|
});
|
|
56
56
|
return Promise.all(resourceIds);
|
|
57
57
|
});
|
|
58
|
+
(0, _defineProperty2.default)(_this, "getSourceId", function () {
|
|
59
|
+
return _this.sourceId;
|
|
60
|
+
});
|
|
58
61
|
_this.fetchProvider = fetchProvider;
|
|
59
62
|
_this.writeProvider = writeProvider;
|
|
60
63
|
_this.sourceId = sourceId;
|
|
@@ -68,25 +71,34 @@ var useFetchDocNode = exports.useFetchDocNode = function useFetchDocNode(editorV
|
|
|
68
71
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
69
72
|
docNode = _useState2[0],
|
|
70
73
|
setDocNode = _useState2[1];
|
|
74
|
+
var fetchNode = function fetchNode(editorView, node, provider) {
|
|
75
|
+
var nodes = [(0, _utils.convertSyncBlockPMNodeToSyncBlockData)(node, false)];
|
|
76
|
+
provider === null || provider === void 0 || provider.fetchNodesData(nodes).then(function (data) {
|
|
77
|
+
var _data$;
|
|
78
|
+
if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
|
|
79
|
+
var newNode = editorView.state.schema.nodeFromJSON(data[0].content);
|
|
80
|
+
setDocNode(_objectSpread(_objectSpread({}, newNode.toJSON()), {}, {
|
|
81
|
+
version: 1
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
71
86
|
(0, _react.useEffect)(function () {
|
|
72
87
|
if (!provider) {
|
|
73
88
|
return;
|
|
74
89
|
}
|
|
90
|
+
fetchNode(editorView, node, provider);
|
|
75
91
|
var interval = window.setInterval(function () {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var _data$;
|
|
79
|
-
if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
|
|
80
|
-
var newNode = editorView.state.schema.nodeFromJSON(data[0].content);
|
|
81
|
-
setDocNode(_objectSpread(_objectSpread({}, newNode.toJSON()), {}, {
|
|
82
|
-
version: 1
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}, 1000);
|
|
92
|
+
fetchNode(editorView, node, provider);
|
|
93
|
+
}, 3000);
|
|
87
94
|
return function () {
|
|
88
95
|
window.clearInterval(interval);
|
|
89
96
|
};
|
|
90
97
|
}, [editorView, node, provider]);
|
|
91
98
|
return docNode;
|
|
99
|
+
};
|
|
100
|
+
var useMemoizedSyncedBlockProvider = exports.useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvider(fetchProvider, writeProvider, sourceId) {
|
|
101
|
+
return (0, _react.useMemo)(function () {
|
|
102
|
+
return new SyncBlockProvider(fetchProvider, writeProvider, sourceId);
|
|
103
|
+
}, [fetchProvider, writeProvider, sourceId]);
|
|
92
104
|
};
|
|
@@ -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 _rebaseTransaction2 = require("./rebase-transaction");
|
|
13
14
|
// Do this typedef to make it clear that
|
|
14
15
|
// this is a local identifier for a resource for local use
|
|
15
16
|
// A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
|
|
@@ -18,9 +19,10 @@ var _uuid = _interopRequireDefault(require("uuid"));
|
|
|
18
19
|
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
19
20
|
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
20
21
|
var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
21
|
-
function SyncBlockStoreManager(
|
|
22
|
+
function SyncBlockStoreManager(dataProvider) {
|
|
22
23
|
(0, _classCallCheck2.default)(this, SyncBlockStoreManager);
|
|
23
24
|
this.syncBlocks = new Map();
|
|
25
|
+
this.dataProvider = dataProvider;
|
|
24
26
|
}
|
|
25
27
|
return (0, _createClass2.default)(SyncBlockStoreManager, [{
|
|
26
28
|
key: "setEditorView",
|
|
@@ -30,14 +32,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
30
32
|
}, {
|
|
31
33
|
key: "isSourceBlock",
|
|
32
34
|
value: function isSourceBlock(node) {
|
|
33
|
-
var _this$syncBlocks$get;
|
|
34
35
|
if (node.type.name !== 'syncBlock') {
|
|
35
36
|
return false;
|
|
36
37
|
}
|
|
37
38
|
var _node$attrs = node.attrs,
|
|
38
39
|
resourceId = _node$attrs.resourceId,
|
|
39
40
|
localId = _node$attrs.localId;
|
|
40
|
-
return
|
|
41
|
+
return resourceId.includes(localId);
|
|
41
42
|
}
|
|
42
43
|
}, {
|
|
43
44
|
key: "registerConfirmationCallback",
|
|
@@ -56,15 +57,18 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
56
57
|
}, {
|
|
57
58
|
key: "createSyncBlockNode",
|
|
58
59
|
value: function createSyncBlockNode() {
|
|
60
|
+
var _this$dataProvider;
|
|
59
61
|
// TODO: EDITOR-1644 - properly implement creation of the synced block
|
|
60
62
|
// below is a temporary implementation for the creation of the synced block
|
|
61
63
|
// the resource id needs to have pageId and content property key in it
|
|
64
|
+
// Note: If the data provider is not set, the resource id will be the local id
|
|
62
65
|
|
|
63
|
-
var blockInstanceId = (0, _uuid.default)();
|
|
64
66
|
var localId = (0, _uuid.default)();
|
|
67
|
+
var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
68
|
+
var resourceId = sourceId ? "".concat(sourceId, "/").concat(localId) : localId;
|
|
65
69
|
var syncBlockNode = {
|
|
66
70
|
attrs: {
|
|
67
|
-
resourceId:
|
|
71
|
+
resourceId: resourceId,
|
|
68
72
|
localId: localId
|
|
69
73
|
},
|
|
70
74
|
type: 'syncBlock'
|
|
@@ -85,23 +89,24 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
85
89
|
while (1) switch (_context.prev = _context.next) {
|
|
86
90
|
case 0:
|
|
87
91
|
if (!this.confirmationCallback) {
|
|
88
|
-
_context.next =
|
|
92
|
+
_context.next = 7;
|
|
89
93
|
break;
|
|
90
94
|
}
|
|
91
|
-
|
|
95
|
+
this.confirmationTransaction = tr;
|
|
96
|
+
_context.next = 4;
|
|
92
97
|
return this.confirmationCallback();
|
|
93
|
-
case
|
|
98
|
+
case 4:
|
|
94
99
|
confirmed = _context.sent;
|
|
95
100
|
if (confirmed) {
|
|
96
|
-
|
|
97
|
-
(_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(tr.setMeta('isConfirmedSyncBlockDeletion', true));
|
|
101
|
+
(_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
|
|
98
102
|
// Need to update the BE on deletion
|
|
99
103
|
syncBlockIds.forEach(function (_ref) {
|
|
100
104
|
var resourceId = _ref.resourceId;
|
|
101
105
|
return _this2.syncBlocks.delete(resourceId);
|
|
102
106
|
});
|
|
103
107
|
}
|
|
104
|
-
|
|
108
|
+
this.confirmationTransaction = undefined;
|
|
109
|
+
case 7:
|
|
105
110
|
case "end":
|
|
106
111
|
return _context.stop();
|
|
107
112
|
}
|
|
@@ -112,5 +117,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
112
117
|
}
|
|
113
118
|
return deleteSyncBlocksWithConfirmation;
|
|
114
119
|
}()
|
|
120
|
+
}, {
|
|
121
|
+
key: "rebaseTransaction",
|
|
122
|
+
value: function rebaseTransaction(incomingTr, state) {
|
|
123
|
+
if (!this.confirmationTransaction) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
this.confirmationTransaction = (0, _rebaseTransaction2.rebaseTransaction)(this.confirmationTransaction, incomingTr, state);
|
|
127
|
+
}
|
|
115
128
|
}]);
|
|
116
129
|
}();
|
package/dist/cjs/index.js
CHANGED
|
@@ -21,12 +21,24 @@ Object.defineProperty(exports, "convertSyncBlockPMNodeToSyncBlockData", {
|
|
|
21
21
|
return _utils.convertSyncBlockPMNodeToSyncBlockData;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "createContentAPIProvidersWithDefaultKey", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _confluenceContentAPI.createContentAPIProvidersWithDefaultKey;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
Object.defineProperty(exports, "generateSyncBlockSourceUrl", {
|
|
25
31
|
enumerable: true,
|
|
26
32
|
get: function get() {
|
|
27
33
|
return _utils.generateSyncBlockSourceUrl;
|
|
28
34
|
}
|
|
29
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "getConfluencePageAri", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return _ari.getConfluencePageAri;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
30
42
|
Object.defineProperty(exports, "getDefaultSyncBlockSchema", {
|
|
31
43
|
enumerable: true,
|
|
32
44
|
get: function get() {
|
|
@@ -45,14 +57,35 @@ Object.defineProperty(exports, "inMemoryWriteProvider", {
|
|
|
45
57
|
return _inMemory.inMemoryWriteProvider;
|
|
46
58
|
}
|
|
47
59
|
});
|
|
60
|
+
Object.defineProperty(exports, "rebaseTransaction", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function get() {
|
|
63
|
+
return _rebaseTransaction.rebaseTransaction;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
48
66
|
Object.defineProperty(exports, "useFetchDocNode", {
|
|
49
67
|
enumerable: true,
|
|
50
68
|
get: function get() {
|
|
51
69
|
return _syncBlockProvider.useFetchDocNode;
|
|
52
70
|
}
|
|
53
71
|
});
|
|
72
|
+
Object.defineProperty(exports, "useMemoizedContentAPIProviders", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function get() {
|
|
75
|
+
return _confluenceContentAPI.useMemoizedContentAPIProviders;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "useMemoizedSyncedBlockProvider", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function get() {
|
|
81
|
+
return _syncBlockProvider.useMemoizedSyncedBlockProvider;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
54
84
|
var _syncBlockProvider = require("./common/syncBlockProvider");
|
|
55
85
|
var _syncBlockStoreManager = require("./common/syncBlockStoreManager");
|
|
56
86
|
var _inMemory = require("./providers/inMemory");
|
|
87
|
+
var _schema = require("./common/schema");
|
|
88
|
+
var _confluenceContentAPI = require("./providers/confluenceContentAPI");
|
|
89
|
+
var _ari = require("./utils/ari");
|
|
57
90
|
var _utils = require("./utils/utils");
|
|
58
|
-
var
|
|
91
|
+
var _rebaseTransaction = require("./common/rebase-transaction");
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useMemoizedContentAPIProviders = exports.createContentAPIProvidersWithDefaultKey = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
var _react = require("react");
|
|
14
|
+
var _ari = require("../utils/ari");
|
|
15
|
+
var _contentProperty = require("../utils/contentProperty");
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for Content API providers
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
var getContentPropertyKey = function getContentPropertyKey(contentPropertyKey, localId) {
|
|
21
|
+
return contentPropertyKey + '-' + localId;
|
|
22
|
+
};
|
|
23
|
+
var parseSyncedBlockContentPropertyValue = function parseSyncedBlockContentPropertyValue(value) {
|
|
24
|
+
try {
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
return JSON.parse(value);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.error('Failed to parse synced block content:', error);
|
|
32
|
+
return {
|
|
33
|
+
content: undefined
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* ADFFetchProvider implementation that fetches synced block data from Confluence Content API
|
|
40
|
+
*/
|
|
41
|
+
var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
|
|
42
|
+
function ConfluenceADFFetchProvider(config) {
|
|
43
|
+
(0, _classCallCheck2.default)(this, ConfluenceADFFetchProvider);
|
|
44
|
+
this.config = config;
|
|
45
|
+
}
|
|
46
|
+
return (0, _createClass2.default)(ConfluenceADFFetchProvider, [{
|
|
47
|
+
key: "fetchData",
|
|
48
|
+
value: function () {
|
|
49
|
+
var _fetchData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(resourceId) {
|
|
50
|
+
var _contentProperty$data, pageId, localId, key, options, contentProperty, value, syncedBlockData;
|
|
51
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
52
|
+
while (1) switch (_context.prev = _context.next) {
|
|
53
|
+
case 0:
|
|
54
|
+
_context.prev = 0;
|
|
55
|
+
pageId = (0, _ari.getPageIdFromAri)(resourceId);
|
|
56
|
+
localId = (0, _ari.getLocalIdFromAri)(resourceId);
|
|
57
|
+
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
58
|
+
options = {
|
|
59
|
+
pageId: pageId,
|
|
60
|
+
key: key,
|
|
61
|
+
cloudId: this.config.cloudId
|
|
62
|
+
};
|
|
63
|
+
_context.next = 7;
|
|
64
|
+
return (0, _contentProperty.getContentProperty)(options);
|
|
65
|
+
case 7:
|
|
66
|
+
contentProperty = _context.sent;
|
|
67
|
+
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;
|
|
68
|
+
if (value) {
|
|
69
|
+
_context.next = 11;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
throw new Error('Content property value does not exist');
|
|
73
|
+
case 11:
|
|
74
|
+
// Parse the synced block content from the property value
|
|
75
|
+
syncedBlockData = parseSyncedBlockContentPropertyValue(value);
|
|
76
|
+
return _context.abrupt("return", {
|
|
77
|
+
content: syncedBlockData.content
|
|
78
|
+
});
|
|
79
|
+
case 15:
|
|
80
|
+
_context.prev = 15;
|
|
81
|
+
_context.t0 = _context["catch"](0);
|
|
82
|
+
// eslint-disable-next-line no-console
|
|
83
|
+
console.error('Failed to fetch synced block data:', _context.t0);
|
|
84
|
+
return _context.abrupt("return", {
|
|
85
|
+
content: undefined
|
|
86
|
+
});
|
|
87
|
+
case 19:
|
|
88
|
+
case "end":
|
|
89
|
+
return _context.stop();
|
|
90
|
+
}
|
|
91
|
+
}, _callee, this, [[0, 15]]);
|
|
92
|
+
}));
|
|
93
|
+
function fetchData(_x) {
|
|
94
|
+
return _fetchData.apply(this, arguments);
|
|
95
|
+
}
|
|
96
|
+
return fetchData;
|
|
97
|
+
}()
|
|
98
|
+
}]);
|
|
99
|
+
}();
|
|
100
|
+
/**
|
|
101
|
+
* ADFWriteProvider implementation that writes synced block data to Confluence Content API
|
|
102
|
+
*/
|
|
103
|
+
var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
104
|
+
function ConfluenceADFWriteProvider(config) {
|
|
105
|
+
var _this = this;
|
|
106
|
+
(0, _classCallCheck2.default)(this, ConfluenceADFWriteProvider);
|
|
107
|
+
(0, _defineProperty2.default)(this, "createNewContentProperty", /*#__PURE__*/function () {
|
|
108
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(pageId, key, value) {
|
|
109
|
+
var _contentProperty$data2;
|
|
110
|
+
var contentProperty;
|
|
111
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
112
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
113
|
+
case 0:
|
|
114
|
+
_context2.next = 2;
|
|
115
|
+
return (0, _contentProperty.createContentProperty)({
|
|
116
|
+
pageId: pageId,
|
|
117
|
+
key: key,
|
|
118
|
+
value: value,
|
|
119
|
+
cloudId: _this.config.cloudId
|
|
120
|
+
});
|
|
121
|
+
case 2:
|
|
122
|
+
contentProperty = _context2.sent;
|
|
123
|
+
if (!(((_contentProperty$data2 = contentProperty.data.confluence.createPageProperty.pageProperty) === null || _contentProperty$data2 === void 0 ? void 0 : _contentProperty$data2.key) === key)) {
|
|
124
|
+
_context2.next = 7;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
return _context2.abrupt("return", key);
|
|
128
|
+
case 7:
|
|
129
|
+
throw new Error('Failed to create content property');
|
|
130
|
+
case 8:
|
|
131
|
+
case "end":
|
|
132
|
+
return _context2.stop();
|
|
133
|
+
}
|
|
134
|
+
}, _callee2);
|
|
135
|
+
}));
|
|
136
|
+
return function (_x2, _x3, _x4) {
|
|
137
|
+
return _ref.apply(this, arguments);
|
|
138
|
+
};
|
|
139
|
+
}());
|
|
140
|
+
this.config = config;
|
|
141
|
+
}
|
|
142
|
+
return (0, _createClass2.default)(ConfluenceADFWriteProvider, [{
|
|
143
|
+
key: "writeData",
|
|
144
|
+
value: function () {
|
|
145
|
+
var _writeData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(sourceId, localId, data, resourceId) {
|
|
146
|
+
var pageId, syncedBlockValue, _contentProperty$data3, _localId, key, contentProperty, _key;
|
|
147
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
148
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
149
|
+
case 0:
|
|
150
|
+
_context3.prev = 0;
|
|
151
|
+
pageId = (0, _ari.getPageIdFromAri)(sourceId);
|
|
152
|
+
syncedBlockValue = JSON.stringify({
|
|
153
|
+
content: data
|
|
154
|
+
});
|
|
155
|
+
if (!resourceId) {
|
|
156
|
+
_context3.next = 20;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
// Update existing content property
|
|
160
|
+
_localId = (0, _ari.getLocalIdFromAri)(resourceId);
|
|
161
|
+
key = getContentPropertyKey(this.config.contentPropertyKey, _localId);
|
|
162
|
+
_context3.next = 8;
|
|
163
|
+
return (0, _contentProperty.updateContentProperty)({
|
|
164
|
+
pageId: pageId,
|
|
165
|
+
key: key,
|
|
166
|
+
value: syncedBlockValue,
|
|
167
|
+
cloudId: this.config.cloudId
|
|
168
|
+
});
|
|
169
|
+
case 8:
|
|
170
|
+
contentProperty = _context3.sent;
|
|
171
|
+
if (!(((_contentProperty$data3 = contentProperty.data.confluence.updateValuePageProperty.pageProperty) === null || _contentProperty$data3 === void 0 ? void 0 : _contentProperty$data3.key) === key)) {
|
|
172
|
+
_context3.next = 13;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
return _context3.abrupt("return", key);
|
|
176
|
+
case 13:
|
|
177
|
+
if (!(contentProperty.data.confluence.updateValuePageProperty.pageProperty === null)) {
|
|
178
|
+
_context3.next = 17;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncedBlockValue));
|
|
182
|
+
case 17:
|
|
183
|
+
throw new Error('Failed to update content property');
|
|
184
|
+
case 18:
|
|
185
|
+
_context3.next = 22;
|
|
186
|
+
break;
|
|
187
|
+
case 20:
|
|
188
|
+
// Create new content property
|
|
189
|
+
_key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
190
|
+
return _context3.abrupt("return", this.createNewContentProperty(pageId, _key, syncedBlockValue));
|
|
191
|
+
case 22:
|
|
192
|
+
_context3.next = 28;
|
|
193
|
+
break;
|
|
194
|
+
case 24:
|
|
195
|
+
_context3.prev = 24;
|
|
196
|
+
_context3.t0 = _context3["catch"](0);
|
|
197
|
+
// eslint-disable-next-line no-console
|
|
198
|
+
console.error('Failed to write synced block data:', _context3.t0);
|
|
199
|
+
return _context3.abrupt("return", Promise.reject(_context3.t0));
|
|
200
|
+
case 28:
|
|
201
|
+
case "end":
|
|
202
|
+
return _context3.stop();
|
|
203
|
+
}
|
|
204
|
+
}, _callee3, this, [[0, 24]]);
|
|
205
|
+
}));
|
|
206
|
+
function writeData(_x5, _x6, _x7, _x8) {
|
|
207
|
+
return _writeData.apply(this, arguments);
|
|
208
|
+
}
|
|
209
|
+
return writeData;
|
|
210
|
+
}()
|
|
211
|
+
}]);
|
|
212
|
+
}();
|
|
213
|
+
/**
|
|
214
|
+
* Factory function to create both providers with shared configuration
|
|
215
|
+
*/
|
|
216
|
+
var createContentAPIProviders = function createContentAPIProviders(config) {
|
|
217
|
+
var fetchProvider = new ConfluenceADFFetchProvider(config);
|
|
218
|
+
var writeProvider = new ConfluenceADFWriteProvider(config);
|
|
219
|
+
return {
|
|
220
|
+
fetchProvider: fetchProvider,
|
|
221
|
+
writeProvider: writeProvider
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Convenience function to create providers with default content property key
|
|
227
|
+
*/
|
|
228
|
+
var createContentAPIProvidersWithDefaultKey = exports.createContentAPIProvidersWithDefaultKey = function createContentAPIProvidersWithDefaultKey(cloudId) {
|
|
229
|
+
return createContentAPIProviders({
|
|
230
|
+
cloudId: cloudId,
|
|
231
|
+
contentPropertyKey: 'editor-synced-block'
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
var useMemoizedContentAPIProviders = exports.useMemoizedContentAPIProviders = function useMemoizedContentAPIProviders(cloudId) {
|
|
235
|
+
return (0, _react.useMemo)(function () {
|
|
236
|
+
return createContentAPIProvidersWithDefaultKey(cloudId);
|
|
237
|
+
}, [cloudId]);
|
|
238
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPageIdFromAri = exports.getLocalIdFromAri = exports.getContentPropertyIdFromAri = exports.getContentPropertyAri = exports.getConfluencePageAri = void 0;
|
|
7
|
+
var getConfluencePageAri = exports.getConfluencePageAri = function getConfluencePageAri(pageId, cloudId) {
|
|
8
|
+
return "ari:cloud:confluence:".concat(cloudId, ":page/").concat(pageId);
|
|
9
|
+
};
|
|
10
|
+
var getPageIdFromAri = exports.getPageIdFromAri = function getPageIdFromAri(ari) {
|
|
11
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
12
|
+
var match = ari.match(/ari:cloud:confluence:[^:]+:page\/(\d+)/);
|
|
13
|
+
if (match !== null && match !== void 0 && match[1]) {
|
|
14
|
+
return match[1];
|
|
15
|
+
}
|
|
16
|
+
throw new Error("Invalid page ARI: ".concat(ari));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param ari ari:cloud:confluence:<cloudId>:page/<pageId>/<localId>
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
var getLocalIdFromAri = exports.getLocalIdFromAri = function getLocalIdFromAri(ari) {
|
|
25
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
26
|
+
var match = ari.match(/ari:cloud:confluence:[^:]+:page\/\d+\/([a-zA-Z0-9-]+)/);
|
|
27
|
+
if (match !== null && match !== void 0 && match[1]) {
|
|
28
|
+
return match[1];
|
|
29
|
+
}
|
|
30
|
+
throw new Error("Invalid page ARI: ".concat(ari));
|
|
31
|
+
};
|
|
32
|
+
var getContentPropertyAri = exports.getContentPropertyAri = function getContentPropertyAri(contentPropertyId, cloudId) {
|
|
33
|
+
return "ari:cloud:confluence:".concat(cloudId, ":content/").concat(contentPropertyId);
|
|
34
|
+
};
|
|
35
|
+
var getContentPropertyIdFromAri = exports.getContentPropertyIdFromAri = function getContentPropertyIdFromAri(ari) {
|
|
36
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
37
|
+
var match = ari.match(/ari:cloud:confluence:[^:]+:content\/([^/]+)/);
|
|
38
|
+
if (match) {
|
|
39
|
+
return match[1];
|
|
40
|
+
}
|
|
41
|
+
throw new Error("Invalid content property ARI: ".concat(ari));
|
|
42
|
+
};
|