@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
63 lines • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var mention_1 = require("@atlaskit/icon/glyph/editor/mention");
var React = require("react");
var react_1 = require("react");
var analytics_1 = require("../../analytics");
var styles_1 = require("./styles");
var ToolbarMention = (function (_super) {
tslib_1.__extends(ToolbarMention, _super);
function ToolbarMention() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = { disabled: false };
_this.handlePluginStateChange = function (pluginState) {
_this.setState({
disabled: !pluginState.enabled,
});
};
_this.handleInsertMention = function () {
_this.pluginState.insertMentionQuery();
return true;
};
return _this;
}
ToolbarMention.prototype.componentWillMount = function () {
this.setPluginState(this.props);
};
ToolbarMention.prototype.componentWillUpdate = function (nextProps) {
if (!this.pluginState) {
this.setPluginState(nextProps);
}
};
ToolbarMention.prototype.componentWillUnmount = function () {
var pluginState = this.pluginState;
if (pluginState) {
pluginState.unsubscribe(this.handlePluginStateChange);
}
};
ToolbarMention.prototype.render = function () {
var disabled = this.state.disabled;
if (!this.pluginState) {
return null;
}
return (React.createElement(styles_1.ToolbarButton, { onClick: this.handleInsertMention, disabled: disabled, title: "Mention a person (@)", iconBefore: React.createElement(mention_1.default, { label: "Add mention" }) }));
};
ToolbarMention.prototype.setPluginState = function (props) {
var editorView = props.editorView, pluginKey = props.pluginKey;
if (!editorView) {
return;
}
var pluginState = pluginKey.getState(editorView.state);
if (pluginState) {
this.pluginState = pluginState;
pluginState.subscribe(this.handlePluginStateChange);
}
};
return ToolbarMention;
}(react_1.PureComponent));
tslib_1.__decorate([
analytics_1.analyticsDecorator('atlassian.editor.mention.button')
], ToolbarMention.prototype, "handleInsertMention", void 0);
exports.default = ToolbarMention;
//# sourceMappingURL=index.js.map