UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

61 lines 3.11 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import React, { PureComponent } from 'react'; import { ProviderFactory, WithProviders } from '../../provider-factory'; import MentionWithProviders from './mention-with-providers'; var Mention = /*#__PURE__*/function (_PureComponent) { _inherits(Mention, _PureComponent); var _super = _createSuper(Mention); function Mention(props) { var _this; _classCallCheck(this, Mention); _this = _super.call(this, props); _defineProperty(_assertThisInitialized(_this), "renderWithProvider", function (providers) { var _this$props = _this.props, accessLevel = _this$props.accessLevel, eventHandlers = _this$props.eventHandlers, id = _this$props.id, text = _this$props.text; var mentionProvider = providers.mentionProvider, profilecardProvider = providers.profilecardProvider; return /*#__PURE__*/React.createElement(MentionWithProviders, { id: id, text: text, accessLevel: accessLevel, eventHandlers: eventHandlers, mentionProvider: mentionProvider, profilecardProvider: profilecardProvider }); }); _this.providerFactory = props.providers || new ProviderFactory(); return _this; } _createClass(Mention, [{ key: "componentWillUnmount", value: function componentWillUnmount() { if (!this.props.providers) { // new ProviderFactory is created if no `providers` has been set // in this case when component is unmounted it's safe to destroy this providerFactory this.providerFactory.destroy(); } } }, { key: "render", value: function render() { return /*#__PURE__*/React.createElement(WithProviders, { providers: ['mentionProvider', 'profilecardProvider'], providerFactory: this.providerFactory, renderNode: this.renderWithProvider }); } }]); return Mention; }(PureComponent); export { Mention as default };