@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
59 lines • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var react_1 = require("react");
var image_1 = require("@atlaskit/icon/glyph/editor/image");
var analytics_1 = require("../../analytics");
var ToolbarButton_1 = require("../ToolbarButton");
var ToolbarMedia = (function (_super) {
tslib_1.__extends(ToolbarMedia, _super);
function ToolbarMedia() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = { disabled: false };
_this.handlePluginStateChange = function (pluginState) {
_this.setState({
disabled: !pluginState.allowsUploads
});
};
_this.handleClickMediaButton = function () {
_this.pluginState.showMediaPicker();
return true;
};
return _this;
}
ToolbarMedia.prototype.componentDidMount = function () {
this.setPluginState(this.props);
};
ToolbarMedia.prototype.componentWillUpdate = function (nextProps) {
if (!this.pluginState) {
this.setPluginState(nextProps);
}
};
ToolbarMedia.prototype.componentWillUnmount = function () {
var pluginState = this.pluginState;
if (pluginState) {
pluginState.unsubscribe(this.handlePluginStateChange);
}
};
ToolbarMedia.prototype.render = function () {
if (this.state.disabled) {
return null;
}
return (React.createElement(ToolbarButton_1.default, { onClick: this.handleClickMediaButton, title: "Insert files and images", iconBefore: React.createElement(image_1.default, { label: "Insert files and images" }) }));
};
ToolbarMedia.prototype.setPluginState = function (props) {
var editorView = props.editorView, pluginKey = props.pluginKey;
var pluginState = pluginKey.getState(editorView.state);
if (pluginState) {
this.pluginState = pluginState;
pluginState.subscribe(this.handlePluginStateChange);
}
};
return ToolbarMedia;
}(react_1.PureComponent));
tslib_1.__decorate([
analytics_1.analyticsDecorator('atlassian.editor.media.button')
], ToolbarMedia.prototype, "handleClickMediaButton", void 0);
exports.default = ToolbarMedia;
//# sourceMappingURL=index.js.map