UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

45 lines 2.12 kB
import * as tslib_1 from "tslib"; import LinkIcon from '@atlaskit/icon/glyph/editor/link'; import * as React from 'react'; import { PureComponent } from 'react'; import { analyticsDecorator as analytics } from '../../analytics'; import { addLink, tooltip } from '../../keymaps'; import { PluginKey } from '../../prosemirror'; import ToolbarButton from '../ToolbarButton'; import { OuterContainer } from './styles'; export var stateKey = new PluginKey('hypelinkPlugin'); var ToolbarHyperlink = (function (_super) { tslib_1.__extends(ToolbarHyperlink, _super); function ToolbarHyperlink() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = {}; _this.toggleLinkPanel = function () { var _a = _this.props, pluginState = _a.pluginState, editorView = _a.editorView; pluginState.showLinkPanel(editorView); return true; }; _this.handlePluginStateChange = function (pluginState) { _this.setState({ disabled: !pluginState.linkable || pluginState.active }); }; return _this; } ToolbarHyperlink.prototype.componentDidMount = function () { this.props.pluginState.subscribe(this.handlePluginStateChange); }; ToolbarHyperlink.prototype.componentWillUnmount = function () { this.props.pluginState.unsubscribe(this.handlePluginStateChange); }; ToolbarHyperlink.prototype.render = function () { var _a = this.state, adding = _a.adding, disabled = _a.disabled; return (React.createElement(OuterContainer, null, React.createElement(ToolbarButton, { disabled: disabled || this.props.disabled, onClick: this.toggleLinkPanel, selected: adding, title: tooltip(addLink), iconBefore: React.createElement(LinkIcon, { label: "Add link" }) }))); }; return ToolbarHyperlink; }(PureComponent)); export default ToolbarHyperlink; tslib_1.__decorate([ analytics('atlassian.editor.format.hyperlink.button') ], ToolbarHyperlink.prototype, "toggleLinkPanel", void 0); //# sourceMappingURL=index.js.map