@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
61 lines • 2.39 kB
JavaScript
import * as tslib_1 from "tslib";
import MentionIcon from '@atlaskit/icon/glyph/editor/mention';
import * as React from 'react';
import { PureComponent } from 'react';
import { analyticsDecorator as analytics } from '../../analytics';
import { ToolbarButton } from './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(ToolbarButton, { onClick: this.handleInsertMention, disabled: disabled, title: "Mention a person (@)", iconBefore: React.createElement(MentionIcon, { 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;
}(PureComponent));
export default ToolbarMention;
tslib_1.__decorate([
analytics('atlassian.editor.mention.button')
], ToolbarMention.prototype, "handleInsertMention", void 0);
//# sourceMappingURL=index.js.map