@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
69 lines • 3.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var react_1 = require("react");
var mention_1 = require("@atlaskit/mention");
var mention_with_profilecard_1 = require("./mention-with-profilecard");
var GENERIC_USER_IDS = ['HipChat', 'all', 'here'];
var noop = function () { };
var MentionWithProviders = (function (_super) {
tslib_1.__extends(MentionWithProviders, _super);
function MentionWithProviders() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = { profilecardProvider: null };
return _this;
}
MentionWithProviders.prototype.componentWillMount = function () {
this.updateProfilecardProvider(this.props);
};
MentionWithProviders.prototype.componentWillReceiveProps = function (nextProps) {
if (nextProps.profilecardProvider !== this.props.profilecardProvider) {
this.updateProfilecardProvider(nextProps);
}
};
MentionWithProviders.prototype.updateProfilecardProvider = function (props) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var resolvedProfilecardProvider, err_1;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!props.profilecardProvider) return [3 /*break*/, 5];
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, props.profilecardProvider];
case 2:
resolvedProfilecardProvider = _a.sent();
this.setState({ profilecardProvider: resolvedProfilecardProvider });
return [3 /*break*/, 4];
case 3:
err_1 = _a.sent();
this.setState({ profilecardProvider: null });
return [3 /*break*/, 4];
case 4: return [3 /*break*/, 6];
case 5:
this.setState({ profilecardProvider: null });
_a.label = 6;
case 6: return [2 /*return*/];
}
});
});
};
MentionWithProviders.prototype.render = function () {
var _a = this.props, accessLevel = _a.accessLevel, eventHandlers = _a.eventHandlers, id = _a.id, mentionProvider = _a.mentionProvider, portal = _a.portal, text = _a.text;
var profilecardProvider = this.state.profilecardProvider;
var actionHandlers = {};
['onClick', 'onMouseEnter', 'onMouseLeave'].forEach(function (handler) {
actionHandlers[handler] = eventHandlers && eventHandlers[handler] || noop;
});
// tslint:disable-next-line:variable-name
var MentionComponent = (profilecardProvider && GENERIC_USER_IDS.indexOf(id) === -1)
? mention_with_profilecard_1.default
: mention_1.ResourcedMention;
return (React.createElement(MentionComponent, tslib_1.__assign({ id: id, text: text, accessLevel: accessLevel, mentionProvider: mentionProvider, profilecardProvider: profilecardProvider, portal: portal }, actionHandlers)));
};
return MentionWithProviders;
}(react_1.PureComponent));
exports.default = MentionWithProviders;
//# sourceMappingURL=mention-with-providers.js.map