@atlaskit/editor-plugin-synced-block
Version:
SyncedBlock plugin for @atlaskit/editor-core
35 lines • 2.54 kB
JavaScript
import React from 'react';
import { SyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
import { SyncBlockError } from '@atlaskit/editor-synced-block-provider';
import { SyncBlockLabel } from './SyncBlockLabel';
const SyncBlockRendererWrapperDataId = 'sync-block-plugin-renderer-wrapper';
const SyncBlockRendererWrapperComponent = ({
syncedBlockRenderer,
useFetchSyncBlockData,
useFetchSyncBlockTitle,
localId,
api
}) => {
var _syncBlockFetchResult, _syncBlockFetchResult2, _syncBlockFetchResult3, _syncBlockFetchResult4, _syncBlockFetchResult5, _syncBlockFetchResult6;
const syncBlockFetchResult = useFetchSyncBlockData();
const title = useFetchSyncBlockTitle === null || useFetchSyncBlockTitle === void 0 ? void 0 : useFetchSyncBlockTitle();
const contentUpdatedAt = syncBlockFetchResult === null || syncBlockFetchResult === void 0 ? void 0 : (_syncBlockFetchResult = syncBlockFetchResult.syncBlockInstance) === null || _syncBlockFetchResult === void 0 ? void 0 : (_syncBlockFetchResult2 = _syncBlockFetchResult.data) === null || _syncBlockFetchResult2 === void 0 ? void 0 : _syncBlockFetchResult2.contentUpdatedAt;
const isUnpublishedBlock = ((_syncBlockFetchResult3 = syncBlockFetchResult.syncBlockInstance) === null || _syncBlockFetchResult3 === void 0 ? void 0 : (_syncBlockFetchResult4 = _syncBlockFetchResult3.data) === null || _syncBlockFetchResult4 === void 0 ? void 0 : _syncBlockFetchResult4.status) === 'unpublished';
const isUnsyncedBlock = isUnpublishedBlock || (syncBlockFetchResult === null || syncBlockFetchResult === void 0 ? void 0 : (_syncBlockFetchResult5 = syncBlockFetchResult.syncBlockInstance) === null || _syncBlockFetchResult5 === void 0 ? void 0 : (_syncBlockFetchResult6 = _syncBlockFetchResult5.error) === null || _syncBlockFetchResult6 === void 0 ? void 0 : _syncBlockFetchResult6.type) === SyncBlockError.NotFound;
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
"data-testid": SyncBlockRendererWrapperDataId
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
,
className: SyncBlockSharedCssClassName.renderer
}, syncedBlockRenderer({
syncBlockFetchResult,
api
})), /*#__PURE__*/React.createElement(SyncBlockLabel, {
isSource: false,
title: title,
contentUpdatedAt: contentUpdatedAt,
localId: localId,
isUnsyncedBlock: isUnsyncedBlock
}));
};
export const SyncBlockRendererWrapper = /*#__PURE__*/React.memo(SyncBlockRendererWrapperComponent);