UNPKG

@atlaskit/editor-plugin-card

Version:

Card plugin for @atlaskit/editor-core

65 lines • 3.29 kB
import React from 'react'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/useSharedPluginStateWithSelector'; import { AssetsConfigModalWithWrappers as AssetsConfigModal } from '@atlaskit/link-datasource/assets-config-modal-with-wrappers'; import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID } from '@atlaskit/link-datasource/assets-modal'; import { ConfluenceSearchConfigModalWithWrappers as ConfluenceSearchConfigModal } from '@atlaskit/link-datasource/confluence-search-config-modal-with-wrappers'; import { CONFLUENCE_SEARCH_DATASOURCE_ID } from '@atlaskit/link-datasource/confluence-search-modal'; import { JiraIssuesConfigModalWithWrappers as JiraIssuesConfigModal } from '@atlaskit/link-datasource/jira-issues-config-modal-with-wrappers'; import { JIRA_LIST_OF_LINKS_DATASOURCE_ID } from '@atlaskit/link-datasource/jira-issues-modal'; import { EditorSmartCardProviderValueGuard } from '@atlaskit/link-provider/editor-smart-card-provider-value-guard'; import { useSmartLinkContext } from '@atlaskit/link-provider/use-smart-link-context'; 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;