@atlaskit/editor-synced-block-renderer 3.0.0 → 3.1.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 +19 -0
- package/dist/cjs/getSyncedBlockNodeComponent.js +15 -2
- package/dist/cjs/ui/SyncedBlockErrorComponent.js +27 -17
- package/dist/cjs/ui/SyncedBlockNodeComponentRenderer.js +12 -27
- package/dist/cjs/ui/SyncedBlockRenderer.js +8 -7
- package/dist/es2019/getSyncedBlockNodeComponent.js +15 -2
- package/dist/es2019/ui/SyncedBlockErrorComponent.js +28 -18
- package/dist/es2019/ui/SyncedBlockNodeComponentRenderer.js +16 -20
- package/dist/es2019/ui/SyncedBlockRenderer.js +9 -7
- package/dist/esm/getSyncedBlockNodeComponent.js +15 -2
- package/dist/esm/ui/SyncedBlockErrorComponent.js +27 -17
- package/dist/esm/ui/SyncedBlockNodeComponentRenderer.js +13 -26
- package/dist/esm/ui/SyncedBlockRenderer.js +8 -7
- package/dist/types/getSyncedBlockNodeComponent.d.ts +1 -1
- package/dist/types/ui/SyncedBlockNodeComponentRenderer.d.ts +2 -2
- package/dist/types/ui/SyncedBlockRenderer.d.ts +2 -2
- package/dist/types-ts4.5/getSyncedBlockNodeComponent.d.ts +1 -1
- package/dist/types-ts4.5/ui/SyncedBlockNodeComponentRenderer.d.ts +2 -2
- package/dist/types-ts4.5/ui/SyncedBlockRenderer.d.ts +2 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-renderer
|
|
2
2
|
|
|
3
|
+
## 3.1.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
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 3.0.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [`7e3353721fa66`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7e3353721fa66) -
|
|
19
|
+
[ux] EDITOR-1822 update sync blocks ui to new design
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
|
|
3
22
|
## 3.0.0
|
|
4
23
|
|
|
5
24
|
### Major Changes
|
|
@@ -6,19 +6,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.getSyncedBlockNodeComponent = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
|
|
9
10
|
var _SyncedBlockNodeComponentRenderer = require("./ui/SyncedBlockNodeComponentRenderer");
|
|
10
11
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
12
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
var isSyncBlockDataProvider = function isSyncBlockDataProvider(dataProvider) {
|
|
14
|
+
return dataProvider.name === 'syncBlockProvider';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// For rendering synced block nodes in Renderer
|
|
12
18
|
var getSyncedBlockNodeComponent = exports.getSyncedBlockNodeComponent = function getSyncedBlockNodeComponent(dataProvider, doc) {
|
|
13
19
|
var content = doc.content;
|
|
14
20
|
var isEmpty = !content || !Array.isArray(content) || content.length === 0;
|
|
15
21
|
var syncBlockNodes = isEmpty ? [] : content.filter(function (node) {
|
|
16
22
|
return node.type === 'syncBlock';
|
|
17
23
|
});
|
|
18
|
-
var
|
|
24
|
+
var syncBlockStoreManager = isSyncBlockDataProvider(dataProvider) ? new _editorSyncedBlockProvider.SyncBlockStoreManager(dataProvider) : undefined;
|
|
25
|
+
if (!syncBlockStoreManager) {
|
|
26
|
+
// TODO: EDITOR-2533 - returns a function that always renders error state
|
|
27
|
+
throw new Error('Data provider is not a SyncBlockDataProvider');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Pre-fetch sync block data
|
|
31
|
+
syncBlockStoreManager.getReferenceSyncBlockStoreManager().fetchSyncBlocksData(syncBlockNodes);
|
|
19
32
|
return function (props) {
|
|
20
33
|
return (0, _SyncedBlockNodeComponentRenderer.SyncedBlockNodeComponentRenderer)(_objectSpread(_objectSpread({}, props), {}, {
|
|
21
|
-
|
|
34
|
+
syncBlockStoreManager: syncBlockStoreManager
|
|
22
35
|
}));
|
|
23
36
|
};
|
|
24
37
|
};
|
|
@@ -6,27 +6,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.SyncedBlockErrorComponent = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _syncBlock = require("@atlaskit/editor-common/sync-block");
|
|
9
10
|
var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
|
|
10
11
|
var _SyncedBlockPermissionDenied = require("./SyncedBlockPermissionDenied");
|
|
11
12
|
var SyncedBlockErrorComponent = exports.SyncedBlockErrorComponent = function SyncedBlockErrorComponent(_ref) {
|
|
12
13
|
var error = _ref.error,
|
|
13
14
|
resourceId = _ref.resourceId;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
var getErrorContent = function getErrorContent() {
|
|
16
|
+
switch (error) {
|
|
17
|
+
case _editorSyncedBlockProvider.SyncBlockError.Forbidden:
|
|
18
|
+
if (resourceId) {
|
|
19
|
+
var _getPageIdAndTypeFrom = (0, _editorSyncedBlockProvider.getPageIdAndTypeFromAri)(resourceId),
|
|
20
|
+
contentId = _getPageIdAndTypeFrom.id;
|
|
21
|
+
if (contentId) {
|
|
22
|
+
return /*#__PURE__*/_react.default.createElement(_SyncedBlockPermissionDenied.SyncedBlockPermissionDenied, {
|
|
23
|
+
contentId: contentId
|
|
24
|
+
});
|
|
25
|
+
}
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement("div", null, "Something went wrong");
|
|
28
|
+
case _editorSyncedBlockProvider.SyncBlockError.NotFound:
|
|
29
|
+
return /*#__PURE__*/_react.default.createElement("div", null, "Sync Block Not Found");
|
|
30
|
+
case _editorSyncedBlockProvider.SyncBlockError.Errored:
|
|
31
|
+
default:
|
|
32
|
+
return /*#__PURE__*/_react.default.createElement("div", null, "Something went wrong");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return (
|
|
36
|
+
/*#__PURE__*/
|
|
37
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
|
|
38
|
+
_react.default.createElement("div", {
|
|
39
|
+
className: _syncBlock.SyncBlockSharedCssClassName.error
|
|
40
|
+
}, getErrorContent())
|
|
41
|
+
);
|
|
32
42
|
};
|
|
@@ -1,50 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.SyncedBlockNodeComponentRenderer = void 0;
|
|
9
|
-
var
|
|
10
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
9
|
var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
|
|
12
10
|
var _renderer = require("@atlaskit/renderer");
|
|
13
11
|
var _actions = require("@atlaskit/renderer/actions");
|
|
14
12
|
var _SyncedBlockErrorComponent = require("./SyncedBlockErrorComponent");
|
|
15
13
|
var _SyncedBlockLoadingState = require("./SyncedBlockLoadingState");
|
|
16
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
17
14
|
var SyncedBlockNodeComponentRenderer = exports.SyncedBlockNodeComponentRenderer = function SyncedBlockNodeComponentRenderer(props) {
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
if (data) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
props.dataPromise.then(function (data) {
|
|
30
|
-
setData(data);
|
|
31
|
-
});
|
|
32
|
-
}, [props.dataPromise, data]);
|
|
33
|
-
if (!data) {
|
|
15
|
+
var resourceId = props.resourceId,
|
|
16
|
+
localId = props.localId,
|
|
17
|
+
syncBlockStoreManager = props.syncBlockStoreManager;
|
|
18
|
+
var _useFetchSyncBlockDat = (0, _editorSyncedBlockProvider.useFetchSyncBlockData)(syncBlockStoreManager, resourceId, localId),
|
|
19
|
+
syncBlockInstance = _useFetchSyncBlockDat.syncBlockInstance,
|
|
20
|
+
isLoading = _useFetchSyncBlockDat.isLoading;
|
|
21
|
+
if (isLoading && !syncBlockInstance) {
|
|
34
22
|
return /*#__PURE__*/_react.default.createElement(_SyncedBlockLoadingState.SyncedBlockLoadingState, null);
|
|
35
23
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
if (fetchResult !== null && fetchResult !== void 0 && fetchResult.error || !(fetchResult !== null && fetchResult !== void 0 && fetchResult.data)) {
|
|
40
|
-
var _fetchResult$error;
|
|
24
|
+
if (syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error || !(syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.data)) {
|
|
25
|
+
var _syncBlockInstance$er;
|
|
41
26
|
return /*#__PURE__*/_react.default.createElement(_SyncedBlockErrorComponent.SyncedBlockErrorComponent, {
|
|
42
|
-
error: (
|
|
27
|
+
error: (_syncBlockInstance$er = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : _editorSyncedBlockProvider.SyncBlockError.Errored,
|
|
43
28
|
resourceId: props.resourceId
|
|
44
29
|
});
|
|
45
30
|
}
|
|
46
31
|
var syncBlockDoc = {
|
|
47
|
-
content:
|
|
32
|
+
content: syncBlockInstance.data.content,
|
|
48
33
|
version: 1,
|
|
49
34
|
type: 'doc'
|
|
50
35
|
};
|
|
@@ -47,22 +47,23 @@ var SyncedBlockRendererWrapper = function SyncedBlockRendererWrapper(_ref) {
|
|
|
47
47
|
var SyncedBlockRendererComponent = function SyncedBlockRendererComponent(_ref2) {
|
|
48
48
|
var useFetchSyncBlockData = _ref2.useFetchSyncBlockData,
|
|
49
49
|
syncBlockRendererDataProviders = _ref2.syncBlockRendererDataProviders;
|
|
50
|
-
var
|
|
50
|
+
var _useFetchSyncBlockDat = useFetchSyncBlockData(),
|
|
51
|
+
syncBlockInstance = _useFetchSyncBlockDat.syncBlockInstance;
|
|
51
52
|
var providerFactory = (0, _react.useMemo)(function () {
|
|
52
53
|
return convertSyncBlockRendererDataProvidersToProviderFactory(syncBlockRendererDataProviders);
|
|
53
54
|
}, [syncBlockRendererDataProviders]);
|
|
54
|
-
if (!
|
|
55
|
+
if (!syncBlockInstance) {
|
|
55
56
|
return /*#__PURE__*/_react.default.createElement(_SyncedBlockLoadingState.SyncedBlockLoadingState, null);
|
|
56
57
|
}
|
|
57
|
-
if (
|
|
58
|
-
var
|
|
58
|
+
if (syncBlockInstance.error || !syncBlockInstance.data) {
|
|
59
|
+
var _syncBlockInstance$er;
|
|
59
60
|
return /*#__PURE__*/_react.default.createElement(_SyncedBlockErrorComponent.SyncedBlockErrorComponent, {
|
|
60
|
-
error: (
|
|
61
|
-
resourceId:
|
|
61
|
+
error: (_syncBlockInstance$er = syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : _editorSyncedBlockProvider.SyncBlockError.Errored,
|
|
62
|
+
resourceId: syncBlockInstance.resourceId
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
return /*#__PURE__*/_react.default.createElement(SyncedBlockRendererWrapper, {
|
|
65
|
-
fetchedData:
|
|
66
|
+
fetchedData: syncBlockInstance.data,
|
|
66
67
|
providerFactory: providerFactory
|
|
67
68
|
});
|
|
68
69
|
};
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
+
import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
1
2
|
import { SyncedBlockNodeComponentRenderer } from './ui/SyncedBlockNodeComponentRenderer';
|
|
3
|
+
const isSyncBlockDataProvider = dataProvider => {
|
|
4
|
+
return dataProvider.name === 'syncBlockProvider';
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// For rendering synced block nodes in Renderer
|
|
2
8
|
export const getSyncedBlockNodeComponent = (dataProvider, doc) => {
|
|
3
9
|
const {
|
|
4
10
|
content
|
|
5
11
|
} = doc;
|
|
6
12
|
const isEmpty = !content || !Array.isArray(content) || content.length === 0;
|
|
7
13
|
const syncBlockNodes = isEmpty ? [] : content.filter(node => node.type === 'syncBlock');
|
|
8
|
-
const
|
|
14
|
+
const syncBlockStoreManager = isSyncBlockDataProvider(dataProvider) ? new SyncBlockStoreManager(dataProvider) : undefined;
|
|
15
|
+
if (!syncBlockStoreManager) {
|
|
16
|
+
// TODO: EDITOR-2533 - returns a function that always renders error state
|
|
17
|
+
throw new Error('Data provider is not a SyncBlockDataProvider');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Pre-fetch sync block data
|
|
21
|
+
syncBlockStoreManager.getReferenceSyncBlockStoreManager().fetchSyncBlocksData(syncBlockNodes);
|
|
9
22
|
return props => SyncedBlockNodeComponentRenderer({
|
|
10
23
|
...props,
|
|
11
|
-
|
|
24
|
+
syncBlockStoreManager
|
|
12
25
|
});
|
|
13
26
|
};
|
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { SyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
|
|
2
3
|
import { getPageIdAndTypeFromAri, SyncBlockError } from '@atlaskit/editor-synced-block-provider';
|
|
3
4
|
import { SyncedBlockPermissionDenied } from './SyncedBlockPermissionDenied';
|
|
4
5
|
export const SyncedBlockErrorComponent = ({
|
|
5
6
|
error,
|
|
6
7
|
resourceId
|
|
7
8
|
}) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
const getErrorContent = () => {
|
|
10
|
+
switch (error) {
|
|
11
|
+
case SyncBlockError.Forbidden:
|
|
12
|
+
if (resourceId) {
|
|
13
|
+
const {
|
|
14
|
+
id: contentId
|
|
15
|
+
} = getPageIdAndTypeFromAri(resourceId);
|
|
16
|
+
if (contentId) {
|
|
17
|
+
return /*#__PURE__*/React.createElement(SyncedBlockPermissionDenied, {
|
|
18
|
+
contentId: contentId
|
|
19
|
+
});
|
|
20
|
+
}
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
22
|
+
return /*#__PURE__*/React.createElement("div", null, "Something went wrong");
|
|
23
|
+
case SyncBlockError.NotFound:
|
|
24
|
+
return /*#__PURE__*/React.createElement("div", null, "Sync Block Not Found");
|
|
25
|
+
case SyncBlockError.Errored:
|
|
26
|
+
default:
|
|
27
|
+
return /*#__PURE__*/React.createElement("div", null, "Something went wrong");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return (
|
|
31
|
+
/*#__PURE__*/
|
|
32
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
|
|
33
|
+
React.createElement("div", {
|
|
34
|
+
className: SyncBlockSharedCssClassName.error
|
|
35
|
+
}, getErrorContent())
|
|
36
|
+
);
|
|
27
37
|
};
|
|
@@ -1,35 +1,31 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { SyncBlockError } from '@atlaskit/editor-synced-block-provider';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SyncBlockError, useFetchSyncBlockData } from '@atlaskit/editor-synced-block-provider';
|
|
3
3
|
import { ReactRenderer } from '@atlaskit/renderer';
|
|
4
4
|
import { RendererActionsContext } from '@atlaskit/renderer/actions';
|
|
5
5
|
import { SyncedBlockErrorComponent } from './SyncedBlockErrorComponent';
|
|
6
6
|
import { SyncedBlockLoadingState } from './SyncedBlockLoadingState';
|
|
7
7
|
export const SyncedBlockNodeComponentRenderer = props => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
19
|
-
}, [props.dataPromise, data]);
|
|
20
|
-
if (!data) {
|
|
8
|
+
const {
|
|
9
|
+
resourceId,
|
|
10
|
+
localId,
|
|
11
|
+
syncBlockStoreManager
|
|
12
|
+
} = props;
|
|
13
|
+
const {
|
|
14
|
+
syncBlockInstance,
|
|
15
|
+
isLoading
|
|
16
|
+
} = useFetchSyncBlockData(syncBlockStoreManager, resourceId, localId);
|
|
17
|
+
if (isLoading && !syncBlockInstance) {
|
|
21
18
|
return /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null);
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var _fetchResult$error;
|
|
20
|
+
if (syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error || !(syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.data)) {
|
|
21
|
+
var _syncBlockInstance$er;
|
|
26
22
|
return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
|
|
27
|
-
error: (
|
|
23
|
+
error: (_syncBlockInstance$er = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : SyncBlockError.Errored,
|
|
28
24
|
resourceId: props.resourceId
|
|
29
25
|
});
|
|
30
26
|
}
|
|
31
27
|
const syncBlockDoc = {
|
|
32
|
-
content:
|
|
28
|
+
content: syncBlockInstance.data.content,
|
|
33
29
|
version: 1,
|
|
34
30
|
type: 'doc'
|
|
35
31
|
};
|
|
@@ -41,22 +41,24 @@ const SyncedBlockRendererComponent = ({
|
|
|
41
41
|
useFetchSyncBlockData,
|
|
42
42
|
syncBlockRendererDataProviders
|
|
43
43
|
}) => {
|
|
44
|
-
const
|
|
44
|
+
const {
|
|
45
|
+
syncBlockInstance
|
|
46
|
+
} = useFetchSyncBlockData();
|
|
45
47
|
const providerFactory = useMemo(() => {
|
|
46
48
|
return convertSyncBlockRendererDataProvidersToProviderFactory(syncBlockRendererDataProviders);
|
|
47
49
|
}, [syncBlockRendererDataProviders]);
|
|
48
|
-
if (!
|
|
50
|
+
if (!syncBlockInstance) {
|
|
49
51
|
return /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null);
|
|
50
52
|
}
|
|
51
|
-
if (
|
|
52
|
-
var
|
|
53
|
+
if (syncBlockInstance.error || !syncBlockInstance.data) {
|
|
54
|
+
var _syncBlockInstance$er;
|
|
53
55
|
return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
|
|
54
|
-
error: (
|
|
55
|
-
resourceId:
|
|
56
|
+
error: (_syncBlockInstance$er = syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : SyncBlockError.Errored,
|
|
57
|
+
resourceId: syncBlockInstance.resourceId
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
return /*#__PURE__*/React.createElement(SyncedBlockRendererWrapper, {
|
|
59
|
-
fetchedData:
|
|
61
|
+
fetchedData: syncBlockInstance.data,
|
|
60
62
|
providerFactory: providerFactory
|
|
61
63
|
});
|
|
62
64
|
};
|
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
4
5
|
import { SyncedBlockNodeComponentRenderer } from './ui/SyncedBlockNodeComponentRenderer';
|
|
6
|
+
var isSyncBlockDataProvider = function isSyncBlockDataProvider(dataProvider) {
|
|
7
|
+
return dataProvider.name === 'syncBlockProvider';
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// For rendering synced block nodes in Renderer
|
|
5
11
|
export var getSyncedBlockNodeComponent = function getSyncedBlockNodeComponent(dataProvider, doc) {
|
|
6
12
|
var content = doc.content;
|
|
7
13
|
var isEmpty = !content || !Array.isArray(content) || content.length === 0;
|
|
8
14
|
var syncBlockNodes = isEmpty ? [] : content.filter(function (node) {
|
|
9
15
|
return node.type === 'syncBlock';
|
|
10
16
|
});
|
|
11
|
-
var
|
|
17
|
+
var syncBlockStoreManager = isSyncBlockDataProvider(dataProvider) ? new SyncBlockStoreManager(dataProvider) : undefined;
|
|
18
|
+
if (!syncBlockStoreManager) {
|
|
19
|
+
// TODO: EDITOR-2533 - returns a function that always renders error state
|
|
20
|
+
throw new Error('Data provider is not a SyncBlockDataProvider');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Pre-fetch sync block data
|
|
24
|
+
syncBlockStoreManager.getReferenceSyncBlockStoreManager().fetchSyncBlocksData(syncBlockNodes);
|
|
12
25
|
return function (props) {
|
|
13
26
|
return SyncedBlockNodeComponentRenderer(_objectSpread(_objectSpread({}, props), {}, {
|
|
14
|
-
|
|
27
|
+
syncBlockStoreManager: syncBlockStoreManager
|
|
15
28
|
}));
|
|
16
29
|
};
|
|
17
30
|
};
|
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { SyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
|
|
2
3
|
import { getPageIdAndTypeFromAri, SyncBlockError } from '@atlaskit/editor-synced-block-provider';
|
|
3
4
|
import { SyncedBlockPermissionDenied } from './SyncedBlockPermissionDenied';
|
|
4
5
|
export var SyncedBlockErrorComponent = function SyncedBlockErrorComponent(_ref) {
|
|
5
6
|
var error = _ref.error,
|
|
6
7
|
resourceId = _ref.resourceId;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
var getErrorContent = function getErrorContent() {
|
|
9
|
+
switch (error) {
|
|
10
|
+
case SyncBlockError.Forbidden:
|
|
11
|
+
if (resourceId) {
|
|
12
|
+
var _getPageIdAndTypeFrom = getPageIdAndTypeFromAri(resourceId),
|
|
13
|
+
contentId = _getPageIdAndTypeFrom.id;
|
|
14
|
+
if (contentId) {
|
|
15
|
+
return /*#__PURE__*/React.createElement(SyncedBlockPermissionDenied, {
|
|
16
|
+
contentId: contentId
|
|
17
|
+
});
|
|
18
|
+
}
|
|
16
19
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
20
|
+
return /*#__PURE__*/React.createElement("div", null, "Something went wrong");
|
|
21
|
+
case SyncBlockError.NotFound:
|
|
22
|
+
return /*#__PURE__*/React.createElement("div", null, "Sync Block Not Found");
|
|
23
|
+
case SyncBlockError.Errored:
|
|
24
|
+
default:
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", null, "Something went wrong");
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
return (
|
|
29
|
+
/*#__PURE__*/
|
|
30
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
|
|
31
|
+
React.createElement("div", {
|
|
32
|
+
className: SyncBlockSharedCssClassName.error
|
|
33
|
+
}, getErrorContent())
|
|
34
|
+
);
|
|
25
35
|
};
|
|
@@ -1,41 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { SyncBlockError } from '@atlaskit/editor-synced-block-provider';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SyncBlockError, useFetchSyncBlockData } from '@atlaskit/editor-synced-block-provider';
|
|
4
3
|
import { ReactRenderer } from '@atlaskit/renderer';
|
|
5
4
|
import { RendererActionsContext } from '@atlaskit/renderer/actions';
|
|
6
5
|
import { SyncedBlockErrorComponent } from './SyncedBlockErrorComponent';
|
|
7
6
|
import { SyncedBlockLoadingState } from './SyncedBlockLoadingState';
|
|
8
7
|
export var SyncedBlockNodeComponentRenderer = function SyncedBlockNodeComponentRenderer(props) {
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
if (data) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
props.dataPromise.then(function (data) {
|
|
21
|
-
setData(data);
|
|
22
|
-
});
|
|
23
|
-
}, [props.dataPromise, data]);
|
|
24
|
-
if (!data) {
|
|
8
|
+
var resourceId = props.resourceId,
|
|
9
|
+
localId = props.localId,
|
|
10
|
+
syncBlockStoreManager = props.syncBlockStoreManager;
|
|
11
|
+
var _useFetchSyncBlockDat = useFetchSyncBlockData(syncBlockStoreManager, resourceId, localId),
|
|
12
|
+
syncBlockInstance = _useFetchSyncBlockDat.syncBlockInstance,
|
|
13
|
+
isLoading = _useFetchSyncBlockDat.isLoading;
|
|
14
|
+
if (isLoading && !syncBlockInstance) {
|
|
25
15
|
return /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null);
|
|
26
16
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
if (fetchResult !== null && fetchResult !== void 0 && fetchResult.error || !(fetchResult !== null && fetchResult !== void 0 && fetchResult.data)) {
|
|
31
|
-
var _fetchResult$error;
|
|
17
|
+
if (syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error || !(syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.data)) {
|
|
18
|
+
var _syncBlockInstance$er;
|
|
32
19
|
return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
|
|
33
|
-
error: (
|
|
20
|
+
error: (_syncBlockInstance$er = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : SyncBlockError.Errored,
|
|
34
21
|
resourceId: props.resourceId
|
|
35
22
|
});
|
|
36
23
|
}
|
|
37
24
|
var syncBlockDoc = {
|
|
38
|
-
content:
|
|
25
|
+
content: syncBlockInstance.data.content,
|
|
39
26
|
version: 1,
|
|
40
27
|
type: 'doc'
|
|
41
28
|
};
|
|
@@ -39,22 +39,23 @@ var SyncedBlockRendererWrapper = function SyncedBlockRendererWrapper(_ref) {
|
|
|
39
39
|
var SyncedBlockRendererComponent = function SyncedBlockRendererComponent(_ref2) {
|
|
40
40
|
var useFetchSyncBlockData = _ref2.useFetchSyncBlockData,
|
|
41
41
|
syncBlockRendererDataProviders = _ref2.syncBlockRendererDataProviders;
|
|
42
|
-
var
|
|
42
|
+
var _useFetchSyncBlockDat = useFetchSyncBlockData(),
|
|
43
|
+
syncBlockInstance = _useFetchSyncBlockDat.syncBlockInstance;
|
|
43
44
|
var providerFactory = useMemo(function () {
|
|
44
45
|
return convertSyncBlockRendererDataProvidersToProviderFactory(syncBlockRendererDataProviders);
|
|
45
46
|
}, [syncBlockRendererDataProviders]);
|
|
46
|
-
if (!
|
|
47
|
+
if (!syncBlockInstance) {
|
|
47
48
|
return /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null);
|
|
48
49
|
}
|
|
49
|
-
if (
|
|
50
|
-
var
|
|
50
|
+
if (syncBlockInstance.error || !syncBlockInstance.data) {
|
|
51
|
+
var _syncBlockInstance$er;
|
|
51
52
|
return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
|
|
52
|
-
error: (
|
|
53
|
-
resourceId:
|
|
53
|
+
error: (_syncBlockInstance$er = syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : SyncBlockError.Errored,
|
|
54
|
+
resourceId: syncBlockInstance.resourceId
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
return /*#__PURE__*/React.createElement(SyncedBlockRendererWrapper, {
|
|
57
|
-
fetchedData:
|
|
58
|
+
fetchedData: syncBlockInstance.data,
|
|
58
59
|
providerFactory: providerFactory
|
|
59
60
|
});
|
|
60
61
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocNode } from '@atlaskit/adf-schema';
|
|
2
|
-
import { type
|
|
2
|
+
import { type SyncBlockInstance, type SyncBlockNode } from '@atlaskit/editor-synced-block-provider';
|
|
3
3
|
import type { NodeDataProvider } from '@atlaskit/node-data-provider';
|
|
4
4
|
import { type SyncedBlockNodeProps } from './ui/SyncedBlockNodeComponentRenderer';
|
|
5
5
|
export declare const getSyncedBlockNodeComponent: (dataProvider: NodeDataProvider<SyncBlockNode, SyncBlockInstance>, doc: DocNode) => (props: SyncedBlockNodeProps) => import("react").JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
3
3
|
import { type NodeProps } from '@atlaskit/renderer';
|
|
4
4
|
export interface SyncedBlockProps {
|
|
5
5
|
localId?: string;
|
|
@@ -7,5 +7,5 @@ export interface SyncedBlockProps {
|
|
|
7
7
|
}
|
|
8
8
|
export type SyncedBlockNodeProps = NodeProps<SyncedBlockProps>;
|
|
9
9
|
export declare const SyncedBlockNodeComponentRenderer: (props: SyncedBlockNodeProps & {
|
|
10
|
-
|
|
10
|
+
syncBlockStoreManager: SyncBlockStoreManager;
|
|
11
11
|
}) => React.JSX.Element;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ProviderFactory, type SyncedBlockRendererDataProviders } from '@atlaskit/editor-common/provider-factory';
|
|
3
|
-
import { type
|
|
3
|
+
import { type UseFetchSyncBlockDataResult } from '@atlaskit/editor-synced-block-provider';
|
|
4
4
|
export type SyncedBlockRendererProps = {
|
|
5
5
|
syncBlockRendererDataProviders: SyncedBlockRendererDataProviders;
|
|
6
|
-
useFetchSyncBlockData: () =>
|
|
6
|
+
useFetchSyncBlockData: () => UseFetchSyncBlockDataResult;
|
|
7
7
|
};
|
|
8
8
|
export declare const convertSyncBlockRendererDataProvidersToProviderFactory: (dataProviders: SyncedBlockRendererDataProviders) => ProviderFactory;
|
|
9
9
|
export declare const SyncedBlockRenderer: React.MemoExoticComponent<({ useFetchSyncBlockData, syncBlockRendererDataProviders, }: SyncedBlockRendererProps) => React.JSX.Element>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocNode } from '@atlaskit/adf-schema';
|
|
2
|
-
import { type
|
|
2
|
+
import { type SyncBlockInstance, type SyncBlockNode } from '@atlaskit/editor-synced-block-provider';
|
|
3
3
|
import type { NodeDataProvider } from '@atlaskit/node-data-provider';
|
|
4
4
|
import { type SyncedBlockNodeProps } from './ui/SyncedBlockNodeComponentRenderer';
|
|
5
5
|
export declare const getSyncedBlockNodeComponent: (dataProvider: NodeDataProvider<SyncBlockNode, SyncBlockInstance>, doc: DocNode) => (props: SyncedBlockNodeProps) => import("react").JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
3
3
|
import { type NodeProps } from '@atlaskit/renderer';
|
|
4
4
|
export interface SyncedBlockProps {
|
|
5
5
|
localId?: string;
|
|
@@ -7,5 +7,5 @@ export interface SyncedBlockProps {
|
|
|
7
7
|
}
|
|
8
8
|
export type SyncedBlockNodeProps = NodeProps<SyncedBlockProps>;
|
|
9
9
|
export declare const SyncedBlockNodeComponentRenderer: (props: SyncedBlockNodeProps & {
|
|
10
|
-
|
|
10
|
+
syncBlockStoreManager: SyncBlockStoreManager;
|
|
11
11
|
}) => React.JSX.Element;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ProviderFactory, type SyncedBlockRendererDataProviders } from '@atlaskit/editor-common/provider-factory';
|
|
3
|
-
import { type
|
|
3
|
+
import { type UseFetchSyncBlockDataResult } from '@atlaskit/editor-synced-block-provider';
|
|
4
4
|
export type SyncedBlockRendererProps = {
|
|
5
5
|
syncBlockRendererDataProviders: SyncedBlockRendererDataProviders;
|
|
6
|
-
useFetchSyncBlockData: () =>
|
|
6
|
+
useFetchSyncBlockData: () => UseFetchSyncBlockDataResult;
|
|
7
7
|
};
|
|
8
8
|
export declare const convertSyncBlockRendererDataProvidersToProviderFactory: (dataProviders: SyncedBlockRendererDataProviders) => ProviderFactory;
|
|
9
9
|
export declare const SyncedBlockRenderer: React.MemoExoticComponent<({ useFetchSyncBlockData, syncBlockRendererDataProviders, }: SyncedBlockRendererProps) => React.JSX.Element>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-synced-block-renderer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "SyncedBlockRenderer for @atlaskit/editor-plugin-synced-block",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@atlaskit/button": "^23.5.0",
|
|
32
32
|
"@atlaskit/css": "^0.15.0",
|
|
33
33
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
34
|
-
"@atlaskit/editor-synced-block-provider": "^2.
|
|
34
|
+
"@atlaskit/editor-synced-block-provider": "^2.6.0",
|
|
35
35
|
"@atlaskit/heading": "^5.2.0",
|
|
36
36
|
"@atlaskit/icon": "^28.5.0",
|
|
37
37
|
"@atlaskit/image": "^3.0.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"relay-runtime": "npm:atl-relay-compiler@0.0.0-main-5980a913"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@atlaskit/editor-common": "^110.
|
|
46
|
+
"@atlaskit/editor-common": "^110.22.0",
|
|
47
47
|
"react": "^18.2.0",
|
|
48
48
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
49
49
|
},
|