@atlaskit/editor-synced-block-provider 2.5.1 → 2.6.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/hooks/useFetchSyncBlockData.js +60 -6
- package/dist/cjs/hooks/useFetchSyncBlockTitle.js +24 -0
- package/dist/cjs/index.js +28 -7
- package/dist/cjs/providers/syncBlockProvider.js +12 -15
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +75 -21
- package/dist/cjs/store-manager/syncBlockStoreManager.js +10 -0
- package/dist/cjs/utils/resolveSyncBlockInstance.js +4 -3
- package/dist/es2019/hooks/useFetchSyncBlockData.js +35 -6
- package/dist/es2019/hooks/useFetchSyncBlockTitle.js +13 -0
- package/dist/es2019/index.js +10 -7
- package/dist/es2019/providers/syncBlockProvider.js +10 -8
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +71 -20
- package/dist/es2019/store-manager/syncBlockStoreManager.js +6 -0
- package/dist/es2019/utils/resolveSyncBlockInstance.js +4 -3
- package/dist/esm/hooks/useFetchSyncBlockData.js +60 -6
- package/dist/esm/hooks/useFetchSyncBlockTitle.js +17 -0
- package/dist/esm/index.js +10 -7
- package/dist/esm/providers/syncBlockProvider.js +12 -15
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +75 -21
- package/dist/esm/store-manager/syncBlockStoreManager.js +10 -0
- package/dist/esm/utils/resolveSyncBlockInstance.js +4 -3
- package/dist/types/common/schema.d.ts +1 -1
- package/dist/types/common/types.d.ts +1 -0
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +6 -3
- package/dist/types/hooks/useFetchSyncBlockTitle.d.ts +3 -0
- package/dist/types/index.d.ts +12 -9
- package/dist/types/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types/providers/types.d.ts +6 -1
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +6 -2
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +4 -1
- package/dist/types-ts4.5/common/schema.d.ts +1 -1
- package/dist/types-ts4.5/common/types.d.ts +1 -0
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +6 -3
- package/dist/types-ts4.5/hooks/useFetchSyncBlockTitle.d.ts +3 -0
- package/dist/types-ts4.5/index.d.ts +12 -9
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types-ts4.5/providers/types.d.ts +6 -1
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +6 -2
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +4 -1
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
6
6
|
_defineProperty(this, "isRefreshingSubscriptions", false);
|
|
7
7
|
this.syncBlockCache = new Map();
|
|
8
8
|
this.subscriptions = new Map();
|
|
9
|
+
this.titleSubscriptions = new Map();
|
|
9
10
|
this.dataProvider = dataProvider;
|
|
10
11
|
this.syncBlockURLRequests = new Map();
|
|
11
12
|
}
|
|
@@ -35,7 +36,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
35
36
|
this.isRefreshingSubscriptions = false;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
fetchSyncBlockSourceURLAndTitle(resourceId) {
|
|
39
40
|
if (!resourceId || !this.dataProvider) {
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
@@ -44,14 +45,18 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
44
45
|
// we could optimise this further by checking if the sync block is on the same page as the source
|
|
45
46
|
if (!this.syncBlockURLRequests.get(resourceId)) {
|
|
46
47
|
this.syncBlockURLRequests.set(resourceId, true);
|
|
47
|
-
this.dataProvider.
|
|
48
|
+
this.dataProvider.retrieveSyncBlockSourceUrlAndTitle(createSyncBlockNode('', resourceId)).then(sourceInfo => {
|
|
48
49
|
const existingSyncBlock = this.getFromCache(resourceId);
|
|
49
50
|
if (existingSyncBlock && existingSyncBlock.data) {
|
|
50
51
|
existingSyncBlock.data = {
|
|
51
52
|
...existingSyncBlock.data,
|
|
52
|
-
sourceURL
|
|
53
|
+
sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
|
|
54
|
+
sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
|
|
53
55
|
};
|
|
54
56
|
this.updateCache(existingSyncBlock);
|
|
57
|
+
if (sourceInfo !== null && sourceInfo !== void 0 && sourceInfo.title) {
|
|
58
|
+
this.updateSourceTitleSubscriptions(existingSyncBlock.resourceId, sourceInfo.title);
|
|
59
|
+
}
|
|
55
60
|
}
|
|
56
61
|
}).finally(() => {
|
|
57
62
|
this.syncBlockURLRequests.set(resourceId, false);
|
|
@@ -68,7 +73,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
68
73
|
}
|
|
69
74
|
const resolvedData = [];
|
|
70
75
|
data.forEach(syncBlockInstance => {
|
|
71
|
-
var _resolvedSyncBlockIns;
|
|
76
|
+
var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
|
|
72
77
|
if (!syncBlockInstance.resourceId) {
|
|
73
78
|
return;
|
|
74
79
|
}
|
|
@@ -77,9 +82,9 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
77
82
|
this.updateCache(resolvedSyncBlockInstance);
|
|
78
83
|
resolvedData.push(resolvedSyncBlockInstance);
|
|
79
84
|
|
|
80
|
-
// fetch source URL if not already present
|
|
81
|
-
if (!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) && resolvedSyncBlockInstance.resourceId) {
|
|
82
|
-
this.
|
|
85
|
+
// fetch source URL and title if not already present
|
|
86
|
+
if ((!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) || !((_resolvedSyncBlockIns2 = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns2 !== void 0 && _resolvedSyncBlockIns2.sourceTitle)) && resolvedSyncBlockInstance.resourceId) {
|
|
87
|
+
this.fetchSyncBlockSourceURLAndTitle(resolvedSyncBlockInstance.resourceId);
|
|
83
88
|
}
|
|
84
89
|
});
|
|
85
90
|
return resolvedData;
|
|
@@ -98,25 +103,21 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
}
|
|
106
|
+
updateSourceTitleSubscriptions(resourceId, title) {
|
|
107
|
+
const callbacks = this.titleSubscriptions.get(resourceId);
|
|
108
|
+
if (callbacks) {
|
|
109
|
+
Object.values(callbacks).forEach(callback => {
|
|
110
|
+
callback(title);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
101
114
|
getFromCache(resourceId) {
|
|
102
115
|
return this.syncBlockCache.get(resourceId);
|
|
103
116
|
}
|
|
104
117
|
deleteFromCache(resourceId) {
|
|
105
118
|
this.syncBlockCache.delete(resourceId);
|
|
106
119
|
}
|
|
107
|
-
|
|
108
|
-
// check node is a sync block, as we only support sync block subscriptions
|
|
109
|
-
if (node.type.name !== 'syncBlock') {
|
|
110
|
-
return () => {};
|
|
111
|
-
}
|
|
112
|
-
const {
|
|
113
|
-
resourceId,
|
|
114
|
-
localId
|
|
115
|
-
} = node.attrs;
|
|
116
|
-
if (!localId || !resourceId) {
|
|
117
|
-
return () => {};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
+
subscribeToSyncBlock(resourceId, localId, callback) {
|
|
120
121
|
// add to subscriptions map
|
|
121
122
|
const resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
122
123
|
this.subscriptions.set(resourceId, {
|
|
@@ -144,6 +145,56 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
144
145
|
}
|
|
145
146
|
};
|
|
146
147
|
}
|
|
148
|
+
subscribeToSourceTitle(node, callback) {
|
|
149
|
+
var _cachedData$data;
|
|
150
|
+
// check node is a sync block, as we only support sync block subscriptions
|
|
151
|
+
if (node.type.name !== 'syncBlock') {
|
|
152
|
+
return () => {};
|
|
153
|
+
}
|
|
154
|
+
const {
|
|
155
|
+
resourceId,
|
|
156
|
+
localId
|
|
157
|
+
} = node.attrs;
|
|
158
|
+
if (!localId || !resourceId) {
|
|
159
|
+
return () => {};
|
|
160
|
+
}
|
|
161
|
+
const cachedData = this.getFromCache(resourceId);
|
|
162
|
+
if (cachedData !== null && cachedData !== void 0 && (_cachedData$data = cachedData.data) !== null && _cachedData$data !== void 0 && _cachedData$data.sourceTitle) {
|
|
163
|
+
callback(cachedData.data.sourceTitle);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// add to subscriptions map
|
|
167
|
+
const resourceSubscriptions = this.titleSubscriptions.get(resourceId) || {};
|
|
168
|
+
this.titleSubscriptions.set(resourceId, {
|
|
169
|
+
...resourceSubscriptions,
|
|
170
|
+
[localId]: callback
|
|
171
|
+
});
|
|
172
|
+
return () => {
|
|
173
|
+
const resourceSubscriptions = this.titleSubscriptions.get(resourceId);
|
|
174
|
+
if (resourceSubscriptions) {
|
|
175
|
+
delete resourceSubscriptions[localId];
|
|
176
|
+
if (Object.keys(resourceSubscriptions).length === 0) {
|
|
177
|
+
this.titleSubscriptions.delete(resourceId);
|
|
178
|
+
} else {
|
|
179
|
+
this.titleSubscriptions.set(resourceId, resourceSubscriptions);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
subscribe(node, callback) {
|
|
185
|
+
// check node is a sync block, as we only support sync block subscriptions
|
|
186
|
+
if (node.type.name !== 'syncBlock') {
|
|
187
|
+
return () => {};
|
|
188
|
+
}
|
|
189
|
+
const {
|
|
190
|
+
resourceId,
|
|
191
|
+
localId
|
|
192
|
+
} = node.attrs;
|
|
193
|
+
if (!localId || !resourceId) {
|
|
194
|
+
return () => {};
|
|
195
|
+
}
|
|
196
|
+
return this.subscribeToSyncBlock(resourceId, localId, callback);
|
|
197
|
+
}
|
|
147
198
|
|
|
148
199
|
/**
|
|
149
200
|
* Get the URL for a sync block.
|
|
@@ -29,6 +29,9 @@ export class SyncBlockStoreManager {
|
|
|
29
29
|
}
|
|
30
30
|
return this.referenceSyncBlockStoreManager.fetchSyncBlocksData(syncBlockNodes);
|
|
31
31
|
}
|
|
32
|
+
getReferenceSyncBlockStoreManager() {
|
|
33
|
+
return this.referenceSyncBlockStoreManager;
|
|
34
|
+
}
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* Add/update a sync block node to/from the local cache
|
|
@@ -82,6 +85,9 @@ export class SyncBlockStoreManager {
|
|
|
82
85
|
subscribeToSyncBlockData(node, callback) {
|
|
83
86
|
return this.referenceSyncBlockStoreManager.subscribe(node, callback);
|
|
84
87
|
}
|
|
88
|
+
subscribeToSyncBlockSourceTitle(node, callback) {
|
|
89
|
+
return this.referenceSyncBlockStoreManager.subscribeToSourceTitle(node, callback);
|
|
90
|
+
}
|
|
85
91
|
refreshSubscriptions() {
|
|
86
92
|
this.referenceSyncBlockStoreManager.refreshSubscriptions();
|
|
87
93
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @returns A merged SyncBlockInstance object.
|
|
10
10
|
*/
|
|
11
11
|
export const resolveSyncBlockInstance = (oldResult, newResult) => {
|
|
12
|
-
var _newResult$data, _oldResult$data;
|
|
12
|
+
var _newResult$data, _oldResult$data, _newResult$data2, _oldResult$data2;
|
|
13
13
|
// if the old result has no data, we simple return the new result
|
|
14
14
|
if (!oldResult.data) {
|
|
15
15
|
return newResult;
|
|
@@ -19,12 +19,13 @@ export const resolveSyncBlockInstance = (oldResult, newResult) => {
|
|
|
19
19
|
return oldResult;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
// otherwise, we merge the two results, preserving the sourceURL from the old result if it exists
|
|
22
|
+
// otherwise, we merge the two results, preserving the sourceURL and sourceTitle from the old result if it exists
|
|
23
23
|
return {
|
|
24
24
|
...newResult,
|
|
25
25
|
data: {
|
|
26
26
|
...newResult.data,
|
|
27
|
-
sourceURL: ((_newResult$data = newResult.data) === null || _newResult$data === void 0 ? void 0 : _newResult$data.sourceURL) || ((_oldResult$data = oldResult.data) === null || _oldResult$data === void 0 ? void 0 : _oldResult$data.sourceURL) || undefined
|
|
27
|
+
sourceURL: ((_newResult$data = newResult.data) === null || _newResult$data === void 0 ? void 0 : _newResult$data.sourceURL) || ((_oldResult$data = oldResult.data) === null || _oldResult$data === void 0 ? void 0 : _oldResult$data.sourceURL) || undefined,
|
|
28
|
+
sourceTitle: ((_newResult$data2 = newResult.data) === null || _newResult$data2 === void 0 ? void 0 : _newResult$data2.sourceTitle) || ((_oldResult$data2 = oldResult.data) === null || _oldResult$data2 === void 0 ? void 0 : _oldResult$data2.sourceTitle) || undefined
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
};
|
|
@@ -1,18 +1,72 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
5
|
+
import { SyncBlockError } from '../common/types';
|
|
6
|
+
import { createSyncBlockNode } from '../utils/createSyncBlock';
|
|
7
|
+
export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resourceId, localId) {
|
|
5
8
|
var _useState = useState(null),
|
|
6
9
|
_useState2 = _slicedToArray(_useState, 2),
|
|
7
10
|
syncBlockInstance = _useState2[0],
|
|
8
11
|
setSyncBlockInstance = _useState2[1];
|
|
12
|
+
var _useState3 = useState(true),
|
|
13
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
14
|
+
isLoading = _useState4[0],
|
|
15
|
+
setIsLoading = _useState4[1];
|
|
16
|
+
var referenceSyncBlockStoreManager = manager.getReferenceSyncBlockStoreManager();
|
|
17
|
+
var reloadData = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
18
|
+
var syncBlockNode;
|
|
19
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
20
|
+
while (1) switch (_context.prev = _context.next) {
|
|
21
|
+
case 0:
|
|
22
|
+
if (!isLoading) {
|
|
23
|
+
_context.next = 2;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
return _context.abrupt("return");
|
|
27
|
+
case 2:
|
|
28
|
+
syncBlockNode = resourceId && localId ? createSyncBlockNode(localId, resourceId) : null;
|
|
29
|
+
if (syncBlockNode) {
|
|
30
|
+
_context.next = 5;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
return _context.abrupt("return");
|
|
34
|
+
case 5:
|
|
35
|
+
setIsLoading(true);
|
|
36
|
+
_context.prev = 6;
|
|
37
|
+
_context.next = 9;
|
|
38
|
+
return referenceSyncBlockStoreManager.fetchSyncBlocksData([syncBlockNode]);
|
|
39
|
+
case 9:
|
|
40
|
+
_context.next = 14;
|
|
41
|
+
break;
|
|
42
|
+
case 11:
|
|
43
|
+
_context.prev = 11;
|
|
44
|
+
_context.t0 = _context["catch"](6);
|
|
45
|
+
// Set error state if fetching fails
|
|
46
|
+
setSyncBlockInstance({
|
|
47
|
+
resourceId: resourceId || '',
|
|
48
|
+
error: SyncBlockError.Errored
|
|
49
|
+
});
|
|
50
|
+
case 14:
|
|
51
|
+
setIsLoading(false);
|
|
52
|
+
case 15:
|
|
53
|
+
case "end":
|
|
54
|
+
return _context.stop();
|
|
55
|
+
}
|
|
56
|
+
}, _callee, null, [[6, 11]]);
|
|
57
|
+
})), [isLoading, localId, referenceSyncBlockStoreManager, resourceId]);
|
|
9
58
|
useEffect(function () {
|
|
10
|
-
var unsubscribe =
|
|
59
|
+
var unsubscribe = referenceSyncBlockStoreManager.subscribeToSyncBlock(resourceId || '', localId || '', function (data) {
|
|
11
60
|
setSyncBlockInstance(data);
|
|
61
|
+
setIsLoading(false);
|
|
12
62
|
});
|
|
13
63
|
return function () {
|
|
14
64
|
unsubscribe();
|
|
15
65
|
};
|
|
16
|
-
}, [
|
|
17
|
-
return
|
|
66
|
+
}, [localId, referenceSyncBlockStoreManager, resourceId]);
|
|
67
|
+
return {
|
|
68
|
+
syncBlockInstance: syncBlockInstance,
|
|
69
|
+
isLoading: isLoading,
|
|
70
|
+
reloadData: reloadData
|
|
71
|
+
};
|
|
18
72
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
export var useFetchSyncBlockTitle = function useFetchSyncBlockTitle(manager, syncBlockNode) {
|
|
4
|
+
var _useState = useState(undefined),
|
|
5
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
6
|
+
sourceTitle = _useState2[0],
|
|
7
|
+
setSourceTitle = _useState2[1];
|
|
8
|
+
useEffect(function () {
|
|
9
|
+
var unsubscribe = manager.subscribeToSyncBlockSourceTitle(syncBlockNode, function (title) {
|
|
10
|
+
setSourceTitle(title);
|
|
11
|
+
});
|
|
12
|
+
return function () {
|
|
13
|
+
unsubscribe();
|
|
14
|
+
};
|
|
15
|
+
}, [manager, syncBlockNode]);
|
|
16
|
+
return sourceTitle;
|
|
17
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/* eslint-disable @atlaskit/editor/no-re-export */
|
|
2
2
|
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
3
|
+
export { rebaseTransaction } from './common/rebase-transaction';
|
|
4
|
+
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
5
|
+
export { SyncBlockError } from './common/types';
|
|
5
6
|
export { useFetchSyncBlockData } from './hooks/useFetchSyncBlockData';
|
|
7
|
+
export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
|
|
6
8
|
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
7
|
-
export { SyncBlockError } from './common/types';
|
|
8
|
-
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
9
9
|
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
|
|
10
|
+
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
|
|
11
|
+
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
12
|
+
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
10
13
|
export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
+
export { createSyncBlockNode } from './utils/createSyncBlock';
|
|
15
|
+
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
16
|
+
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
@@ -126,8 +126,8 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
126
126
|
return this.sourceId;
|
|
127
127
|
}
|
|
128
128
|
}, {
|
|
129
|
-
key: "
|
|
130
|
-
value: function
|
|
129
|
+
key: "retrieveSyncBlockSourceUrlAndTitle",
|
|
130
|
+
value: function retrieveSyncBlockSourceUrlAndTitle(node) {
|
|
131
131
|
var resourceId = node.attrs.resourceId;
|
|
132
132
|
var pageARI;
|
|
133
133
|
var sourceLocalId;
|
|
@@ -143,7 +143,7 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
143
143
|
// EDITOR-1921: log analytic here, safe to continue
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
return pageARI ?
|
|
146
|
+
return pageARI ? fetchURLandTitlefromARI(pageARI, sourceLocalId) : Promise.resolve(undefined);
|
|
147
147
|
}
|
|
148
148
|
}]);
|
|
149
149
|
}(SyncBlockDataProvider);
|
|
@@ -152,9 +152,9 @@ export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvi
|
|
|
152
152
|
return new SyncBlockProvider(fetchProvider, writeProvider, sourceId);
|
|
153
153
|
}, [fetchProvider, writeProvider, sourceId]);
|
|
154
154
|
};
|
|
155
|
-
var
|
|
155
|
+
var fetchURLandTitlefromARI = /*#__PURE__*/function () {
|
|
156
156
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(ari, sourceLocalId) {
|
|
157
|
-
var response, _payload$data, payload, url;
|
|
157
|
+
var response, _payload$data, _payload$data2, payload, url, title;
|
|
158
158
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
159
159
|
while (1) switch (_context2.prev = _context2.next) {
|
|
160
160
|
case 0:
|
|
@@ -180,17 +180,14 @@ var fetchURLfromARI = /*#__PURE__*/function () {
|
|
|
180
180
|
case 6:
|
|
181
181
|
payload = _context2.sent;
|
|
182
182
|
url = payload === null || payload === void 0 || (_payload$data = payload.data) === null || _payload$data === void 0 ? void 0 : _payload$data.url;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
case 10:
|
|
189
|
-
_context2.next = 13;
|
|
190
|
-
break;
|
|
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
|
+
});
|
|
191
188
|
case 12:
|
|
192
189
|
//eslint-disable-next-line no-console
|
|
193
|
-
console.error('Failed to fetch URL from ARI', response.statusText);
|
|
190
|
+
console.error('Failed to fetch URL and title from ARI', response.statusText);
|
|
194
191
|
case 13:
|
|
195
192
|
return _context2.abrupt("return", undefined);
|
|
196
193
|
case 14:
|
|
@@ -199,7 +196,7 @@ var fetchURLfromARI = /*#__PURE__*/function () {
|
|
|
199
196
|
}
|
|
200
197
|
}, _callee2);
|
|
201
198
|
}));
|
|
202
|
-
return function
|
|
199
|
+
return function fetchURLandTitlefromARI(_x2, _x3) {
|
|
203
200
|
return _ref.apply(this, arguments);
|
|
204
201
|
};
|
|
205
202
|
}();
|
|
@@ -17,6 +17,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
17
17
|
_defineProperty(this, "isRefreshingSubscriptions", false);
|
|
18
18
|
this.syncBlockCache = new Map();
|
|
19
19
|
this.subscriptions = new Map();
|
|
20
|
+
this.titleSubscriptions = new Map();
|
|
20
21
|
this.dataProvider = dataProvider;
|
|
21
22
|
this.syncBlockURLRequests = new Map();
|
|
22
23
|
}
|
|
@@ -105,8 +106,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
105
106
|
return refreshSubscriptions;
|
|
106
107
|
}())
|
|
107
108
|
}, {
|
|
108
|
-
key: "
|
|
109
|
-
value: function
|
|
109
|
+
key: "fetchSyncBlockSourceURLAndTitle",
|
|
110
|
+
value: function fetchSyncBlockSourceURLAndTitle(resourceId) {
|
|
110
111
|
var _this = this;
|
|
111
112
|
if (!resourceId || !this.dataProvider) {
|
|
112
113
|
return;
|
|
@@ -116,13 +117,17 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
116
117
|
// we could optimise this further by checking if the sync block is on the same page as the source
|
|
117
118
|
if (!this.syncBlockURLRequests.get(resourceId)) {
|
|
118
119
|
this.syncBlockURLRequests.set(resourceId, true);
|
|
119
|
-
this.dataProvider.
|
|
120
|
+
this.dataProvider.retrieveSyncBlockSourceUrlAndTitle(createSyncBlockNode('', resourceId)).then(function (sourceInfo) {
|
|
120
121
|
var existingSyncBlock = _this.getFromCache(resourceId);
|
|
121
122
|
if (existingSyncBlock && existingSyncBlock.data) {
|
|
122
123
|
existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
|
|
123
|
-
sourceURL:
|
|
124
|
+
sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
|
|
125
|
+
sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
|
|
124
126
|
});
|
|
125
127
|
_this.updateCache(existingSyncBlock);
|
|
128
|
+
if (sourceInfo !== null && sourceInfo !== void 0 && sourceInfo.title) {
|
|
129
|
+
_this.updateSourceTitleSubscriptions(existingSyncBlock.resourceId, sourceInfo.title);
|
|
130
|
+
}
|
|
126
131
|
}
|
|
127
132
|
}).finally(function () {
|
|
128
133
|
_this.syncBlockURLRequests.set(resourceId, false);
|
|
@@ -156,7 +161,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
156
161
|
case 7:
|
|
157
162
|
resolvedData = [];
|
|
158
163
|
data.forEach(function (syncBlockInstance) {
|
|
159
|
-
var _resolvedSyncBlockIns;
|
|
164
|
+
var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
|
|
160
165
|
if (!syncBlockInstance.resourceId) {
|
|
161
166
|
return;
|
|
162
167
|
}
|
|
@@ -165,9 +170,9 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
165
170
|
_this2.updateCache(resolvedSyncBlockInstance);
|
|
166
171
|
resolvedData.push(resolvedSyncBlockInstance);
|
|
167
172
|
|
|
168
|
-
// fetch source URL if not already present
|
|
169
|
-
if (!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) && resolvedSyncBlockInstance.resourceId) {
|
|
170
|
-
_this2.
|
|
173
|
+
// fetch source URL and title if not already present
|
|
174
|
+
if ((!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) || !((_resolvedSyncBlockIns2 = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns2 !== void 0 && _resolvedSyncBlockIns2.sourceTitle)) && resolvedSyncBlockInstance.resourceId) {
|
|
175
|
+
_this2.fetchSyncBlockSourceURLAndTitle(resolvedSyncBlockInstance.resourceId);
|
|
171
176
|
}
|
|
172
177
|
});
|
|
173
178
|
return _context3.abrupt("return", resolvedData);
|
|
@@ -196,6 +201,16 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
196
201
|
}
|
|
197
202
|
}
|
|
198
203
|
}
|
|
204
|
+
}, {
|
|
205
|
+
key: "updateSourceTitleSubscriptions",
|
|
206
|
+
value: function updateSourceTitleSubscriptions(resourceId, title) {
|
|
207
|
+
var callbacks = this.titleSubscriptions.get(resourceId);
|
|
208
|
+
if (callbacks) {
|
|
209
|
+
Object.values(callbacks).forEach(function (callback) {
|
|
210
|
+
callback(title);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
199
214
|
}, {
|
|
200
215
|
key: "getFromCache",
|
|
201
216
|
value: function getFromCache(resourceId) {
|
|
@@ -207,20 +222,9 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
207
222
|
this.syncBlockCache.delete(resourceId);
|
|
208
223
|
}
|
|
209
224
|
}, {
|
|
210
|
-
key: "
|
|
211
|
-
value: function
|
|
225
|
+
key: "subscribeToSyncBlock",
|
|
226
|
+
value: function subscribeToSyncBlock(resourceId, localId, callback) {
|
|
212
227
|
var _this3 = this;
|
|
213
|
-
// check node is a sync block, as we only support sync block subscriptions
|
|
214
|
-
if (node.type.name !== 'syncBlock') {
|
|
215
|
-
return function () {};
|
|
216
|
-
}
|
|
217
|
-
var _node$attrs = node.attrs,
|
|
218
|
-
resourceId = _node$attrs.resourceId,
|
|
219
|
-
localId = _node$attrs.localId;
|
|
220
|
-
if (!localId || !resourceId) {
|
|
221
|
-
return function () {};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
228
|
// add to subscriptions map
|
|
225
229
|
var resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
226
230
|
this.subscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
|
|
@@ -245,6 +249,56 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
245
249
|
}
|
|
246
250
|
};
|
|
247
251
|
}
|
|
252
|
+
}, {
|
|
253
|
+
key: "subscribeToSourceTitle",
|
|
254
|
+
value: function subscribeToSourceTitle(node, callback) {
|
|
255
|
+
var _cachedData$data,
|
|
256
|
+
_this4 = this;
|
|
257
|
+
// check node is a sync block, as we only support sync block subscriptions
|
|
258
|
+
if (node.type.name !== 'syncBlock') {
|
|
259
|
+
return function () {};
|
|
260
|
+
}
|
|
261
|
+
var _node$attrs = node.attrs,
|
|
262
|
+
resourceId = _node$attrs.resourceId,
|
|
263
|
+
localId = _node$attrs.localId;
|
|
264
|
+
if (!localId || !resourceId) {
|
|
265
|
+
return function () {};
|
|
266
|
+
}
|
|
267
|
+
var cachedData = this.getFromCache(resourceId);
|
|
268
|
+
if (cachedData !== null && cachedData !== void 0 && (_cachedData$data = cachedData.data) !== null && _cachedData$data !== void 0 && _cachedData$data.sourceTitle) {
|
|
269
|
+
callback(cachedData.data.sourceTitle);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// add to subscriptions map
|
|
273
|
+
var resourceSubscriptions = this.titleSubscriptions.get(resourceId) || {};
|
|
274
|
+
this.titleSubscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
|
|
275
|
+
return function () {
|
|
276
|
+
var resourceSubscriptions = _this4.titleSubscriptions.get(resourceId);
|
|
277
|
+
if (resourceSubscriptions) {
|
|
278
|
+
delete resourceSubscriptions[localId];
|
|
279
|
+
if (Object.keys(resourceSubscriptions).length === 0) {
|
|
280
|
+
_this4.titleSubscriptions.delete(resourceId);
|
|
281
|
+
} else {
|
|
282
|
+
_this4.titleSubscriptions.set(resourceId, resourceSubscriptions);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}, {
|
|
288
|
+
key: "subscribe",
|
|
289
|
+
value: function subscribe(node, callback) {
|
|
290
|
+
// check node is a sync block, as we only support sync block subscriptions
|
|
291
|
+
if (node.type.name !== 'syncBlock') {
|
|
292
|
+
return function () {};
|
|
293
|
+
}
|
|
294
|
+
var _node$attrs2 = node.attrs,
|
|
295
|
+
resourceId = _node$attrs2.resourceId,
|
|
296
|
+
localId = _node$attrs2.localId;
|
|
297
|
+
if (!localId || !resourceId) {
|
|
298
|
+
return function () {};
|
|
299
|
+
}
|
|
300
|
+
return this.subscribeToSyncBlock(resourceId, localId, callback);
|
|
301
|
+
}
|
|
248
302
|
|
|
249
303
|
/**
|
|
250
304
|
* Get the URL for a sync block.
|
|
@@ -34,6 +34,11 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
34
34
|
}
|
|
35
35
|
return this.referenceSyncBlockStoreManager.fetchSyncBlocksData(syncBlockNodes);
|
|
36
36
|
}
|
|
37
|
+
}, {
|
|
38
|
+
key: "getReferenceSyncBlockStoreManager",
|
|
39
|
+
value: function getReferenceSyncBlockStoreManager() {
|
|
40
|
+
return this.referenceSyncBlockStoreManager;
|
|
41
|
+
}
|
|
37
42
|
|
|
38
43
|
/**
|
|
39
44
|
* Add/update a sync block node to/from the local cache
|
|
@@ -105,6 +110,11 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
105
110
|
value: function subscribeToSyncBlockData(node, callback) {
|
|
106
111
|
return this.referenceSyncBlockStoreManager.subscribe(node, callback);
|
|
107
112
|
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "subscribeToSyncBlockSourceTitle",
|
|
115
|
+
value: function subscribeToSyncBlockSourceTitle(node, callback) {
|
|
116
|
+
return this.referenceSyncBlockStoreManager.subscribeToSourceTitle(node, callback);
|
|
117
|
+
}
|
|
108
118
|
}, {
|
|
109
119
|
key: "refreshSubscriptions",
|
|
110
120
|
value: function refreshSubscriptions() {
|
|
@@ -12,7 +12,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
12
12
|
* @returns A merged SyncBlockInstance object.
|
|
13
13
|
*/
|
|
14
14
|
export var resolveSyncBlockInstance = function resolveSyncBlockInstance(oldResult, newResult) {
|
|
15
|
-
var _newResult$data, _oldResult$data;
|
|
15
|
+
var _newResult$data, _oldResult$data, _newResult$data2, _oldResult$data2;
|
|
16
16
|
// if the old result has no data, we simple return the new result
|
|
17
17
|
if (!oldResult.data) {
|
|
18
18
|
return newResult;
|
|
@@ -22,10 +22,11 @@ export var resolveSyncBlockInstance = function resolveSyncBlockInstance(oldResul
|
|
|
22
22
|
return oldResult;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// otherwise, we merge the two results, preserving the sourceURL from the old result if it exists
|
|
25
|
+
// otherwise, we merge the two results, preserving the sourceURL and sourceTitle from the old result if it exists
|
|
26
26
|
return _objectSpread(_objectSpread({}, newResult), {}, {
|
|
27
27
|
data: _objectSpread(_objectSpread({}, newResult.data), {}, {
|
|
28
|
-
sourceURL: ((_newResult$data = newResult.data) === null || _newResult$data === void 0 ? void 0 : _newResult$data.sourceURL) || ((_oldResult$data = oldResult.data) === null || _oldResult$data === void 0 ? void 0 : _oldResult$data.sourceURL) || undefined
|
|
28
|
+
sourceURL: ((_newResult$data = newResult.data) === null || _newResult$data === void 0 ? void 0 : _newResult$data.sourceURL) || ((_oldResult$data = oldResult.data) === null || _oldResult$data === void 0 ? void 0 : _oldResult$data.sourceURL) || undefined,
|
|
29
|
+
sourceTitle: ((_newResult$data2 = newResult.data) === null || _newResult$data2 === void 0 ? void 0 : _newResult$data2.sourceTitle) || ((_oldResult$data2 = oldResult.data) === null || _oldResult$data2 === void 0 ? void 0 : _oldResult$data2.sourceTitle) || undefined
|
|
29
30
|
})
|
|
30
31
|
});
|
|
31
32
|
};
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
|
|
4
4
|
* @returns
|
|
5
5
|
*/
|
|
6
|
-
export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"
|
|
6
|
+
export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"doc" | "paragraph" | "text" | "bulletList" | "orderedList" | "listItem" | "heading" | "blockquote" | "codeBlock" | "panel" | "rule" | "expand" | "nestedExpand" | "table" | "tableCell" | "tableHeader" | "tableRow" | "date" | "status" | "layoutSection" | "layoutColumn" | "unsupportedBlock" | "unsupportedInline", "link" | "em" | "strong" | "strike" | "subsup" | "underline" | "code" | "textColor" | "backgroundColor" | "alignment" | "indentation" | "border" | "unsupportedMark" | "unsupportedNodeAttribute" | "typeAheadQuery">;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
1
|
import type { SyncBlockInstance } from '../providers/types';
|
|
3
2
|
import type { SyncBlockStoreManager } from '../store-manager/syncBlockStoreManager';
|
|
4
|
-
export
|
|
5
|
-
|
|
3
|
+
export interface UseFetchSyncBlockDataResult {
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
reloadData: () => Promise<void>;
|
|
6
|
+
syncBlockInstance: SyncBlockInstance | null;
|
|
7
|
+
}
|
|
8
|
+
export declare const useFetchSyncBlockData: (manager: SyncBlockStoreManager, resourceId?: string, localId?: string) => UseFetchSyncBlockDataResult;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { SyncBlockStoreManager } from '../store-manager/syncBlockStoreManager';
|
|
3
|
+
export declare const useFetchSyncBlockTitle: (manager: SyncBlockStoreManager, syncBlockNode: PMNode) => string | undefined;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
3
|
-
export { useFetchSyncBlockData } from './hooks/useFetchSyncBlockData';
|
|
4
|
-
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
5
|
-
export type { SyncBlockData, SyncBlockNode } from './common/types';
|
|
6
|
-
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockInstance, } from './providers/types';
|
|
7
|
-
export { SyncBlockError } from './common/types';
|
|
1
|
+
export { rebaseTransaction } from './common/rebase-transaction';
|
|
8
2
|
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
3
|
+
export { SyncBlockError } from './common/types';
|
|
4
|
+
export type { SyncBlockData, SyncBlockNode } from './common/types';
|
|
5
|
+
export { useFetchSyncBlockData, type UseFetchSyncBlockDataResult, } from './hooks/useFetchSyncBlockData';
|
|
6
|
+
export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
|
|
7
|
+
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
9
8
|
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluence/confluenceContentAPI';
|
|
9
|
+
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
|
|
10
|
+
export type { ADFFetchProvider, ADFWriteProvider, SyncBlockDataProvider, SyncBlockInstance, } from './providers/types';
|
|
11
|
+
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
12
|
+
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
10
13
|
export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
|
|
11
|
-
export {
|
|
12
|
-
export { rebaseTransaction } from './common/rebase-transaction';
|
|
14
|
+
export { createSyncBlockNode } from './utils/createSyncBlock';
|
|
13
15
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
16
|
+
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|