@atlaskit/editor-plugin-card
Version:
Card plugin for @atlaskit/editor-core
66 lines (65 loc) • 2.93 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.modalTypeToComponentMap = exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _hooks = require("@atlaskit/editor-common/hooks");
var _linkDatasource = require("@atlaskit/link-datasource");
var _linkProvider = require("@atlaskit/link-provider");
var _datasourceErrorBoundary = require("../datasourceErrorBoundary");
var _index = require("./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 = (0, _linkProvider.useSmartLinkContext)();
var _useSharedPluginState = (0, _hooks.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.default.createElement(_datasourceErrorBoundary.DatasourceErrorBoundary, {
view: editorView,
datasourceModalType: datasourceModalType
}, /*#__PURE__*/_react.default.createElement(_index.DatasourceModal, {
view: editorView,
cardContext: cardContext,
datasourceId: datasourceId,
componentType: componentType
}));
};
var SafeModalWithState = /*#__PURE__*/_react.default.memo(function (_ref2) {
var api = _ref2.api,
editorView = _ref2.editorView;
return /*#__PURE__*/_react.default.createElement(_linkProvider.EditorSmartCardProviderValueGuard, null, /*#__PURE__*/_react.default.createElement(ModalWithState, {
api: api,
editorView: editorView
}));
});
var modalTypeToComponentMap = exports.modalTypeToComponentMap = {
jira: {
componentType: _linkDatasource.JiraIssuesConfigModal,
datasourceId: _linkDatasource.JIRA_LIST_OF_LINKS_DATASOURCE_ID
},
'confluence-search': {
componentType: _linkDatasource.ConfluenceSearchConfigModal,
datasourceId: _linkDatasource.CONFLUENCE_SEARCH_DATASOURCE_ID
},
assets: {
componentType: _linkDatasource.AssetsConfigModal,
datasourceId: _linkDatasource.ASSETS_LIST_OF_LINKS_DATASOURCE_ID
}
};
var _default = exports.default = SafeModalWithState;