UNPKG

@atlaskit/editor-plugin-mentions

Version:

Mentions plugin for @atlaskit/editor-core

100 lines (99 loc) 5.2 kB
/* InlineInviteRecaptchaContainer.tsx generated by @compiled/babel-plugin v0.39.1 */ "use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.InlineInviteRecaptchaContainer = void 0; var _runtime = require("@compiled/react/runtime"); var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _react = _interopRequireWildcard(require("react")); var _mentionPlaceholder = require("../pm-plugins/mentionPlaceholder"); var _analytics = require("../ui/type-ahead/analytics"); 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); } /** * Container that renders the recaptcha component from the mention provider and manages handleSuccess. * Does NOT pass email - the provider's component uses useInlineInviteRecaptcha hook internally * and wires showRecaptcha to the provider. When user clicks invite item, type-ahead calls * mentionProvider.showInlineInviteRecaptcha(email) which passes email to the component. */ var InlineInviteRecaptchaContainer = exports.InlineInviteRecaptchaContainer = function InlineInviteRecaptchaContainer(_ref) { var _api$mention2, _api$core3; var mentionProvider = _ref.mentionProvider, api = _ref.api; var _useState = (0, _react.useState)(null), _useState2 = (0, _slicedToArray2.default)(_useState, 2), provider = _useState2[0], setProvider = _useState2[1]; (0, _react.useEffect)(function () { if (!mentionProvider) { return; } var isMounted = true; mentionProvider.then(function (resolvedProvider) { if (!isMounted) { return; } setProvider(resolvedProvider); }).catch(function () { // Silently handle promise rejection }); return function () { isMounted = false; setProvider(null); }; }, [mentionProvider]); var handleSuccess = (0, _react.useCallback)(function (userId, email) { var _api$mention, _api$core; if (!(api !== null && api !== void 0 && (_api$mention = api.mention) !== null && _api$mention !== void 0 && (_api$mention = _api$mention.commands) !== null && _api$mention !== void 0 && _api$mention.insertMention) || !(api !== null && api !== void 0 && (_api$core = api.core) !== null && _api$core !== void 0 && (_api$core = _api$core.actions) !== null && _api$core !== void 0 && _api$core.execute)) { return; } var name = email.split('@')[0] || email; api.core.actions.execute(api.mention.commands.insertMention({ id: userId, name: name, userType: 'DEFAULT', accessLevel: 'CONTAINER' })); api.core.actions.execute(function (_ref2) { var tr = _ref2.tr; tr.setMeta(_mentionPlaceholder.mentionPlaceholderPluginKey, { action: _mentionPlaceholder.MENTION_PLACEHOLDER_ACTIONS.HIDE_PLACEHOLDER }); return tr; }); }, [api]); var handleClose = (0, _react.useCallback)(function () { var _api$core2; if (!(api !== null && api !== void 0 && (_api$core2 = api.core) !== null && _api$core2 !== void 0 && (_api$core2 = _api$core2.actions) !== null && _api$core2 !== void 0 && _api$core2.execute)) { return; } api.core.actions.execute(function (_ref3) { var tr = _ref3.tr; tr.setMeta(_mentionPlaceholder.mentionPlaceholderPluginKey, { action: _mentionPlaceholder.MENTION_PLACEHOLDER_ACTIONS.HIDE_PLACEHOLDER }); return tr; }); }, [api]); var handleReady = (0, _react.useCallback)(function (showRecaptcha) { if (provider) { if (showRecaptcha) { provider.showInlineInviteRecaptcha = showRecaptcha; } else { delete provider.showInlineInviteRecaptcha; } } }, [provider]); if (!(provider !== null && provider !== void 0 && provider.InlineInviteRecaptcha) || !(api !== null && api !== void 0 && (_api$mention2 = api.mention) !== null && _api$mention2 !== void 0 && (_api$mention2 = _api$mention2.commands) !== null && _api$mention2 !== void 0 && _api$mention2.insertMention) || !(api !== null && api !== void 0 && (_api$core3 = api.core) !== null && _api$core3 !== void 0 && (_api$core3 = _api$core3.actions) !== null && _api$core3 !== void 0 && _api$core3.execute)) { return null; } var RecaptchaComponent = provider.InlineInviteRecaptcha; return /*#__PURE__*/_react.default.createElement(RecaptchaComponent, { analyticsSource: _analytics.MENTION_SOURCE, onSuccess: handleSuccess, onClose: handleClose, onReady: handleReady }); };