UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

57 lines 2.27 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { PureComponent } from 'react'; import ImageIcon from '@atlaskit/icon/glyph/editor/image'; import { analyticsDecorator as analytics } from '../../analytics'; import ToolbarButton from '../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, { onClick: this.handleClickMediaButton, title: "Insert files and images", iconBefore: React.createElement(ImageIcon, { 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; }(PureComponent)); export default ToolbarMedia; tslib_1.__decorate([ analytics('atlassian.editor.media.button') ], ToolbarMedia.prototype, "handleClickMediaButton", void 0); //# sourceMappingURL=index.js.map