UNPKG

@atlaskit/editor-plugin-card

Version:

Card plugin for @atlaskit/editor-core

59 lines 2.65 kB
import React from 'react'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'; import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, CONFLUENCE_SEARCH_DATASOURCE_ID, ConfluenceSearchConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource'; import { EditorSmartCardProviderValueGuard, useSmartLinkContext } from '@atlaskit/link-provider'; import { DatasourceErrorBoundary } from '../datasourceErrorBoundary'; import { DatasourceModal } from './index'; var selector = function selector(states) { var _states$cardState, _states$cardState2; return { showDatasourceModal: (_states$cardState = states.cardState) === null || _states$cardState === void 0 ? void 0 : _states$cardState.showDatasourceModal, datasourceModalType: (_states$cardState2 = states.cardState) === null || _states$cardState2 === void 0 ? void 0 : _states$cardState2.datasourceModalType }; }; var ModalWithState = function ModalWithState(_ref) { var api = _ref.api, editorView = _ref.editorView; var cardContext = useSmartLinkContext(); var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['card'], selector), showDatasourceModal = _useSharedPluginState.showDatasourceModal, datasourceModalType = _useSharedPluginState.datasourceModalType; if (!showDatasourceModal || !datasourceModalType) { return null; } var _modalTypeToComponent = modalTypeToComponentMap[datasourceModalType], datasourceId = _modalTypeToComponent.datasourceId, componentType = _modalTypeToComponent.componentType; return /*#__PURE__*/React.createElement(DatasourceErrorBoundary, { view: editorView, datasourceModalType: datasourceModalType }, /*#__PURE__*/React.createElement(DatasourceModal, { view: editorView, cardContext: cardContext, datasourceId: datasourceId, componentType: componentType })); }; var SafeModalWithState = /*#__PURE__*/React.memo(function (_ref2) { var api = _ref2.api, editorView = _ref2.editorView; return /*#__PURE__*/React.createElement(EditorSmartCardProviderValueGuard, null, /*#__PURE__*/React.createElement(ModalWithState, { api: api, editorView: editorView })); }); export var modalTypeToComponentMap = { jira: { componentType: JiraIssuesConfigModal, datasourceId: JIRA_LIST_OF_LINKS_DATASOURCE_ID }, 'confluence-search': { componentType: ConfluenceSearchConfigModal, datasourceId: CONFLUENCE_SEARCH_DATASOURCE_ID }, assets: { componentType: AssetsConfigModal, datasourceId: ASSETS_LIST_OF_LINKS_DATASOURCE_ID } }; export default SafeModalWithState;