@atlaskit/editor-synced-block-provider 2.5.2 → 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 +7 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +60 -6
- package/dist/cjs/index.js +21 -7
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +20 -16
- package/dist/cjs/store-manager/syncBlockStoreManager.js +5 -0
- package/dist/es2019/hooks/useFetchSyncBlockData.js +35 -6
- package/dist/es2019/index.js +9 -7
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +15 -13
- package/dist/es2019/store-manager/syncBlockStoreManager.js +3 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +60 -6
- package/dist/esm/index.js +9 -7
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +20 -16
- package/dist/esm/store-manager/syncBlockStoreManager.js +5 -0
- package/dist/types/common/schema.d.ts +1 -1
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +6 -3
- package/dist/types/index.d.ts +11 -9
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +2 -1
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +2 -0
- package/dist/types-ts4.5/common/schema.d.ts +1 -1
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +6 -3
- package/dist/types-ts4.5/index.d.ts +11 -9
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +2 -1
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 2.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`261fa27c56fd0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/261fa27c56fd0) -
|
|
8
|
+
EDITOR-2533 implement retry function for sync-block renderer
|
|
9
|
+
|
|
3
10
|
## 2.5.2
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -4,22 +4,76 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.useFetchSyncBlockData =
|
|
7
|
+
exports.useFetchSyncBlockData = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
11
|
var _react = require("react");
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
+
var _types = require("../common/types");
|
|
13
|
+
var _createSyncBlock = require("../utils/createSyncBlock");
|
|
14
|
+
var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyncBlockData(manager, resourceId, localId) {
|
|
12
15
|
var _useState = (0, _react.useState)(null),
|
|
13
16
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
14
17
|
syncBlockInstance = _useState2[0],
|
|
15
18
|
setSyncBlockInstance = _useState2[1];
|
|
19
|
+
var _useState3 = (0, _react.useState)(true),
|
|
20
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
21
|
+
isLoading = _useState4[0],
|
|
22
|
+
setIsLoading = _useState4[1];
|
|
23
|
+
var referenceSyncBlockStoreManager = manager.getReferenceSyncBlockStoreManager();
|
|
24
|
+
var reloadData = (0, _react.useCallback)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
25
|
+
var syncBlockNode;
|
|
26
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
27
|
+
while (1) switch (_context.prev = _context.next) {
|
|
28
|
+
case 0:
|
|
29
|
+
if (!isLoading) {
|
|
30
|
+
_context.next = 2;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
return _context.abrupt("return");
|
|
34
|
+
case 2:
|
|
35
|
+
syncBlockNode = resourceId && localId ? (0, _createSyncBlock.createSyncBlockNode)(localId, resourceId) : null;
|
|
36
|
+
if (syncBlockNode) {
|
|
37
|
+
_context.next = 5;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return _context.abrupt("return");
|
|
41
|
+
case 5:
|
|
42
|
+
setIsLoading(true);
|
|
43
|
+
_context.prev = 6;
|
|
44
|
+
_context.next = 9;
|
|
45
|
+
return referenceSyncBlockStoreManager.fetchSyncBlocksData([syncBlockNode]);
|
|
46
|
+
case 9:
|
|
47
|
+
_context.next = 14;
|
|
48
|
+
break;
|
|
49
|
+
case 11:
|
|
50
|
+
_context.prev = 11;
|
|
51
|
+
_context.t0 = _context["catch"](6);
|
|
52
|
+
// Set error state if fetching fails
|
|
53
|
+
setSyncBlockInstance({
|
|
54
|
+
resourceId: resourceId || '',
|
|
55
|
+
error: _types.SyncBlockError.Errored
|
|
56
|
+
});
|
|
57
|
+
case 14:
|
|
58
|
+
setIsLoading(false);
|
|
59
|
+
case 15:
|
|
60
|
+
case "end":
|
|
61
|
+
return _context.stop();
|
|
62
|
+
}
|
|
63
|
+
}, _callee, null, [[6, 11]]);
|
|
64
|
+
})), [isLoading, localId, referenceSyncBlockStoreManager, resourceId]);
|
|
16
65
|
(0, _react.useEffect)(function () {
|
|
17
|
-
var unsubscribe =
|
|
66
|
+
var unsubscribe = referenceSyncBlockStoreManager.subscribeToSyncBlock(resourceId || '', localId || '', function (data) {
|
|
18
67
|
setSyncBlockInstance(data);
|
|
68
|
+
setIsLoading(false);
|
|
19
69
|
});
|
|
20
70
|
return function () {
|
|
21
71
|
unsubscribe();
|
|
22
72
|
};
|
|
23
|
-
}, [
|
|
24
|
-
return
|
|
73
|
+
}, [localId, referenceSyncBlockStoreManager, resourceId]);
|
|
74
|
+
return {
|
|
75
|
+
syncBlockInstance: syncBlockInstance,
|
|
76
|
+
isLoading: isLoading,
|
|
77
|
+
reloadData: reloadData
|
|
78
|
+
};
|
|
25
79
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "ReferenceSyncBlockStoreManager", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "SyncBlockError", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function get() {
|
|
@@ -33,6 +39,12 @@ Object.defineProperty(exports, "createContentAPIProvidersWithDefaultKey", {
|
|
|
33
39
|
return _confluenceContentAPI.createContentAPIProvidersWithDefaultKey;
|
|
34
40
|
}
|
|
35
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "createSyncBlockNode", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function get() {
|
|
45
|
+
return _createSyncBlock.createSyncBlockNode;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
36
48
|
Object.defineProperty(exports, "getConfluencePageAri", {
|
|
37
49
|
enumerable: true,
|
|
38
50
|
get: function get() {
|
|
@@ -93,15 +105,17 @@ Object.defineProperty(exports, "useMemoizedSyncedBlockProvider", {
|
|
|
93
105
|
return _syncBlockProvider.useMemoizedSyncedBlockProvider;
|
|
94
106
|
}
|
|
95
107
|
});
|
|
96
|
-
var
|
|
97
|
-
var
|
|
108
|
+
var _rebaseTransaction = require("./common/rebase-transaction");
|
|
109
|
+
var _schema = require("./common/schema");
|
|
110
|
+
var _types = require("./common/types");
|
|
98
111
|
var _useFetchSyncBlockData = require("./hooks/useFetchSyncBlockData");
|
|
99
112
|
var _useFetchSyncBlockTitle = require("./hooks/useFetchSyncBlockTitle");
|
|
100
113
|
var _useHandleContentChanges = require("./hooks/useHandleContentChanges");
|
|
101
|
-
var _types = require("./common/types");
|
|
102
|
-
var _schema = require("./common/schema");
|
|
103
114
|
var _confluenceContentAPI = require("./providers/confluence/confluenceContentAPI");
|
|
115
|
+
var _syncBlockProvider = require("./providers/syncBlockProvider");
|
|
116
|
+
var _referenceSyncBlockStoreManager = require("./store-manager/referenceSyncBlockStoreManager");
|
|
117
|
+
var _syncBlockStoreManager = require("./store-manager/syncBlockStoreManager");
|
|
104
118
|
var _ari = require("./utils/ari");
|
|
105
|
-
var
|
|
106
|
-
var
|
|
107
|
-
var
|
|
119
|
+
var _createSyncBlock = require("./utils/createSyncBlock");
|
|
120
|
+
var _resolveSyncBlockInstance = require("./utils/resolveSyncBlockInstance");
|
|
121
|
+
var _utils = require("./utils/utils");
|
|
@@ -229,20 +229,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
229
229
|
this.syncBlockCache.delete(resourceId);
|
|
230
230
|
}
|
|
231
231
|
}, {
|
|
232
|
-
key: "
|
|
233
|
-
value: function
|
|
232
|
+
key: "subscribeToSyncBlock",
|
|
233
|
+
value: function subscribeToSyncBlock(resourceId, localId, callback) {
|
|
234
234
|
var _this3 = this;
|
|
235
|
-
// check node is a sync block, as we only support sync block subscriptions
|
|
236
|
-
if (node.type.name !== 'syncBlock') {
|
|
237
|
-
return function () {};
|
|
238
|
-
}
|
|
239
|
-
var _node$attrs = node.attrs,
|
|
240
|
-
resourceId = _node$attrs.resourceId,
|
|
241
|
-
localId = _node$attrs.localId;
|
|
242
|
-
if (!localId || !resourceId) {
|
|
243
|
-
return function () {};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
235
|
// add to subscriptions map
|
|
247
236
|
var resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
248
237
|
this.subscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, (0, _defineProperty2.default)({}, localId, callback)));
|
|
@@ -276,9 +265,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
276
265
|
if (node.type.name !== 'syncBlock') {
|
|
277
266
|
return function () {};
|
|
278
267
|
}
|
|
279
|
-
var _node$
|
|
280
|
-
resourceId = _node$
|
|
281
|
-
localId = _node$
|
|
268
|
+
var _node$attrs = node.attrs,
|
|
269
|
+
resourceId = _node$attrs.resourceId,
|
|
270
|
+
localId = _node$attrs.localId;
|
|
282
271
|
if (!localId || !resourceId) {
|
|
283
272
|
return function () {};
|
|
284
273
|
}
|
|
@@ -302,6 +291,21 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
302
291
|
}
|
|
303
292
|
};
|
|
304
293
|
}
|
|
294
|
+
}, {
|
|
295
|
+
key: "subscribe",
|
|
296
|
+
value: function subscribe(node, callback) {
|
|
297
|
+
// check node is a sync block, as we only support sync block subscriptions
|
|
298
|
+
if (node.type.name !== 'syncBlock') {
|
|
299
|
+
return function () {};
|
|
300
|
+
}
|
|
301
|
+
var _node$attrs2 = node.attrs,
|
|
302
|
+
resourceId = _node$attrs2.resourceId,
|
|
303
|
+
localId = _node$attrs2.localId;
|
|
304
|
+
if (!localId || !resourceId) {
|
|
305
|
+
return function () {};
|
|
306
|
+
}
|
|
307
|
+
return this.subscribeToSyncBlock(resourceId, localId, callback);
|
|
308
|
+
}
|
|
305
309
|
|
|
306
310
|
/**
|
|
307
311
|
* Get the URL for a sync block.
|
|
@@ -40,6 +40,11 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
40
40
|
}
|
|
41
41
|
return this.referenceSyncBlockStoreManager.fetchSyncBlocksData(syncBlockNodes);
|
|
42
42
|
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "getReferenceSyncBlockStoreManager",
|
|
45
|
+
value: function getReferenceSyncBlockStoreManager() {
|
|
46
|
+
return this.referenceSyncBlockStoreManager;
|
|
47
|
+
}
|
|
43
48
|
|
|
44
49
|
/**
|
|
45
50
|
* Add/update a sync block node to/from the local cache
|
|
@@ -1,14 +1,43 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { SyncBlockError } from '../common/types';
|
|
3
|
+
import { createSyncBlockNode } from '../utils/createSyncBlock';
|
|
4
|
+
export const useFetchSyncBlockData = (manager, resourceId, localId) => {
|
|
4
5
|
const [syncBlockInstance, setSyncBlockInstance] = useState(null);
|
|
6
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
7
|
+
const referenceSyncBlockStoreManager = manager.getReferenceSyncBlockStoreManager();
|
|
8
|
+
const reloadData = useCallback(async () => {
|
|
9
|
+
if (isLoading) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const syncBlockNode = resourceId && localId ? createSyncBlockNode(localId, resourceId) : null;
|
|
13
|
+
if (!syncBlockNode) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
setIsLoading(true);
|
|
17
|
+
try {
|
|
18
|
+
// Fetch sync block data, the `subscribeToSyncBlock` will update the state once data is fetched
|
|
19
|
+
await referenceSyncBlockStoreManager.fetchSyncBlocksData([syncBlockNode]);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
// Set error state if fetching fails
|
|
22
|
+
setSyncBlockInstance({
|
|
23
|
+
resourceId: resourceId || '',
|
|
24
|
+
error: SyncBlockError.Errored
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
setIsLoading(false);
|
|
28
|
+
}, [isLoading, localId, referenceSyncBlockStoreManager, resourceId]);
|
|
5
29
|
useEffect(() => {
|
|
6
|
-
const unsubscribe =
|
|
30
|
+
const unsubscribe = referenceSyncBlockStoreManager.subscribeToSyncBlock(resourceId || '', localId || '', data => {
|
|
7
31
|
setSyncBlockInstance(data);
|
|
32
|
+
setIsLoading(false);
|
|
8
33
|
});
|
|
9
34
|
return () => {
|
|
10
35
|
unsubscribe();
|
|
11
36
|
};
|
|
12
|
-
}, [
|
|
13
|
-
return
|
|
37
|
+
}, [localId, referenceSyncBlockStoreManager, resourceId]);
|
|
38
|
+
return {
|
|
39
|
+
syncBlockInstance,
|
|
40
|
+
isLoading,
|
|
41
|
+
reloadData
|
|
42
|
+
};
|
|
14
43
|
};
|
package/dist/es2019/index.js
CHANGED
|
@@ -1,14 +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';
|
|
6
7
|
export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
|
|
7
8
|
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
8
|
-
export { SyncBlockError } from './common/types';
|
|
9
|
-
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
10
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';
|
|
11
13
|
export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
14
|
+
export { createSyncBlockNode } from './utils/createSyncBlock';
|
|
15
|
+
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
16
|
+
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
@@ -117,19 +117,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
117
117
|
deleteFromCache(resourceId) {
|
|
118
118
|
this.syncBlockCache.delete(resourceId);
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
// check node is a sync block, as we only support sync block subscriptions
|
|
122
|
-
if (node.type.name !== 'syncBlock') {
|
|
123
|
-
return () => {};
|
|
124
|
-
}
|
|
125
|
-
const {
|
|
126
|
-
resourceId,
|
|
127
|
-
localId
|
|
128
|
-
} = node.attrs;
|
|
129
|
-
if (!localId || !resourceId) {
|
|
130
|
-
return () => {};
|
|
131
|
-
}
|
|
132
|
-
|
|
120
|
+
subscribeToSyncBlock(resourceId, localId, callback) {
|
|
133
121
|
// add to subscriptions map
|
|
134
122
|
const resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
135
123
|
this.subscriptions.set(resourceId, {
|
|
@@ -193,6 +181,20 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
193
181
|
}
|
|
194
182
|
};
|
|
195
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
|
+
}
|
|
196
198
|
|
|
197
199
|
/**
|
|
198
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
|
|
@@ -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
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,14 +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';
|
|
6
7
|
export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
|
|
7
8
|
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
8
|
-
export { SyncBlockError } from './common/types';
|
|
9
|
-
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
10
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';
|
|
11
13
|
export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
14
|
+
export { createSyncBlockNode } from './utils/createSyncBlock';
|
|
15
|
+
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
16
|
+
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
@@ -222,20 +222,9 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
222
222
|
this.syncBlockCache.delete(resourceId);
|
|
223
223
|
}
|
|
224
224
|
}, {
|
|
225
|
-
key: "
|
|
226
|
-
value: function
|
|
225
|
+
key: "subscribeToSyncBlock",
|
|
226
|
+
value: function subscribeToSyncBlock(resourceId, localId, callback) {
|
|
227
227
|
var _this3 = this;
|
|
228
|
-
// check node is a sync block, as we only support sync block subscriptions
|
|
229
|
-
if (node.type.name !== 'syncBlock') {
|
|
230
|
-
return function () {};
|
|
231
|
-
}
|
|
232
|
-
var _node$attrs = node.attrs,
|
|
233
|
-
resourceId = _node$attrs.resourceId,
|
|
234
|
-
localId = _node$attrs.localId;
|
|
235
|
-
if (!localId || !resourceId) {
|
|
236
|
-
return function () {};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
228
|
// add to subscriptions map
|
|
240
229
|
var resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
241
230
|
this.subscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
|
|
@@ -269,9 +258,9 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
269
258
|
if (node.type.name !== 'syncBlock') {
|
|
270
259
|
return function () {};
|
|
271
260
|
}
|
|
272
|
-
var _node$
|
|
273
|
-
resourceId = _node$
|
|
274
|
-
localId = _node$
|
|
261
|
+
var _node$attrs = node.attrs,
|
|
262
|
+
resourceId = _node$attrs.resourceId,
|
|
263
|
+
localId = _node$attrs.localId;
|
|
275
264
|
if (!localId || !resourceId) {
|
|
276
265
|
return function () {};
|
|
277
266
|
}
|
|
@@ -295,6 +284,21 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
295
284
|
}
|
|
296
285
|
};
|
|
297
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
|
+
}
|
|
298
302
|
|
|
299
303
|
/**
|
|
300
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
|
|
@@ -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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { rebaseTransaction } from './common/rebase-transaction';
|
|
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';
|
|
4
6
|
export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
|
|
5
7
|
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
6
|
-
export type { SyncBlockData, SyncBlockNode } from './common/types';
|
|
7
|
-
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockInstance, } from './providers/types';
|
|
8
|
-
export { SyncBlockError } from './common/types';
|
|
9
|
-
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
10
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';
|
|
11
13
|
export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
|
|
12
|
-
export {
|
|
13
|
-
export { rebaseTransaction } from './common/rebase-transaction';
|
|
14
|
+
export { createSyncBlockNode } from './utils/createSyncBlock';
|
|
14
15
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
16
|
+
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
@@ -20,8 +20,9 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
20
20
|
private updateSourceTitleSubscriptions;
|
|
21
21
|
private getFromCache;
|
|
22
22
|
private deleteFromCache;
|
|
23
|
-
|
|
23
|
+
subscribeToSyncBlock(resourceId: string, localId: string, callback: SubscriptionCallback): () => void;
|
|
24
24
|
subscribeToSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
|
|
25
|
+
subscribe(node: PMNode, callback: SubscriptionCallback): () => void;
|
|
25
26
|
/**
|
|
26
27
|
* Get the URL for a sync block.
|
|
27
28
|
* @param resourceId - The resource ID of the sync block
|
|
@@ -3,6 +3,7 @@ import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
|
3
3
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { ResourceId, SyncBlockAttrs, SyncBlockNode } from '../common/types';
|
|
5
5
|
import type { SubscriptionCallback, SyncBlockDataProvider, SyncBlockInstance, TitleSubscriptionCallback } from '../providers/types';
|
|
6
|
+
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
6
7
|
import { type ConfirmationCallback } from './sourceSyncBlockStoreManager';
|
|
7
8
|
export declare class SyncBlockStoreManager {
|
|
8
9
|
private referenceSyncBlockStoreManager;
|
|
@@ -14,6 +15,7 @@ export declare class SyncBlockStoreManager {
|
|
|
14
15
|
* @returns The fetched sync block data results
|
|
15
16
|
*/
|
|
16
17
|
fetchSyncBlocksData(nodes: PMNode[]): Promise<SyncBlockInstance[]>;
|
|
18
|
+
getReferenceSyncBlockStoreManager(): ReferenceSyncBlockStoreManager;
|
|
17
19
|
/**
|
|
18
20
|
* Add/update a sync block node to/from the local cache
|
|
19
21
|
* @param syncBlockNode - The sync block node to update
|
|
@@ -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;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { rebaseTransaction } from './common/rebase-transaction';
|
|
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';
|
|
4
6
|
export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
|
|
5
7
|
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
6
|
-
export type { SyncBlockData, SyncBlockNode } from './common/types';
|
|
7
|
-
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockInstance, } from './providers/types';
|
|
8
|
-
export { SyncBlockError } from './common/types';
|
|
9
|
-
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
10
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';
|
|
11
13
|
export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
|
|
12
|
-
export {
|
|
13
|
-
export { rebaseTransaction } from './common/rebase-transaction';
|
|
14
|
+
export { createSyncBlockNode } from './utils/createSyncBlock';
|
|
14
15
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
16
|
+
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
@@ -20,8 +20,9 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
20
20
|
private updateSourceTitleSubscriptions;
|
|
21
21
|
private getFromCache;
|
|
22
22
|
private deleteFromCache;
|
|
23
|
-
|
|
23
|
+
subscribeToSyncBlock(resourceId: string, localId: string, callback: SubscriptionCallback): () => void;
|
|
24
24
|
subscribeToSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
|
|
25
|
+
subscribe(node: PMNode, callback: SubscriptionCallback): () => void;
|
|
25
26
|
/**
|
|
26
27
|
* Get the URL for a sync block.
|
|
27
28
|
* @param resourceId - The resource ID of the sync block
|
|
@@ -3,6 +3,7 @@ import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
|
3
3
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { ResourceId, SyncBlockAttrs, SyncBlockNode } from '../common/types';
|
|
5
5
|
import type { SubscriptionCallback, SyncBlockDataProvider, SyncBlockInstance, TitleSubscriptionCallback } from '../providers/types';
|
|
6
|
+
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
6
7
|
import { type ConfirmationCallback } from './sourceSyncBlockStoreManager';
|
|
7
8
|
export declare class SyncBlockStoreManager {
|
|
8
9
|
private referenceSyncBlockStoreManager;
|
|
@@ -14,6 +15,7 @@ export declare class SyncBlockStoreManager {
|
|
|
14
15
|
* @returns The fetched sync block data results
|
|
15
16
|
*/
|
|
16
17
|
fetchSyncBlocksData(nodes: PMNode[]): Promise<SyncBlockInstance[]>;
|
|
18
|
+
getReferenceSyncBlockStoreManager(): ReferenceSyncBlockStoreManager;
|
|
17
19
|
/**
|
|
18
20
|
* Add/update a sync block node to/from the local cache
|
|
19
21
|
* @param syncBlockNode - The sync block node to update
|
package/package.json
CHANGED