UNPKG

wix-style-react

Version:
118 lines (98 loc) 4.74 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React from 'react'; import RichTextToolbarButton from './RichTextToolbarButton'; import RichTextInputAreaLinkForm from '../Form/RichTextInputAreaLinkForm'; import Popover from '../../Popover'; import Box from '../../Box'; var RichTextToolbarLinkButton = /*#__PURE__*/function (_React$Component) { _inherits(RichTextToolbarLinkButton, _React$Component); var _super = _createSuper(RichTextToolbarLinkButton); function RichTextToolbarLinkButton() { var _this; _classCallCheck(this, RichTextToolbarLinkButton); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "state", { isFormShown: false }); _defineProperty(_assertThisInitialized(_this), "_onButtonClick", function () { var _this$props = _this.props, onRemove = _this$props.onRemove, data = _this$props.data; var hasRemovableEntityInSelection = data.hasRemovableEntityInSelection; // Checks if the selected text does not contain a link if (!hasRemovableEntityInSelection) { _this.setState({ isFormShown: true }); } else { onRemove(); } }); _defineProperty(_assertThisInitialized(_this), "_onSubmit", function (event, linkData) { var onSubmit = _this.props.onSubmit; onSubmit(event, linkData); _this._onHide(); }); _defineProperty(_assertThisInitialized(_this), "_onHide", function () { _this.setState({ isFormShown: false }); }); return _this; } _createClass(RichTextToolbarLinkButton, [{ key: "render", value: function render() { var _this$props2 = this.props, dataHook = _this$props2.dataHook, tooltipText = _this$props2.tooltipText, isDisabled = _this$props2.isDisabled, isActive = _this$props2.isActive, children = _this$props2.children, data = _this$props2.data; var isFormShown = this.state.isFormShown; var selectedText = data.selectedText; return /*#__PURE__*/React.createElement(Popover, { appendTo: "parent", placement: "bottom", showArrow: true, animate: true, shown: isFormShown, onClickOutside: this._onHide }, /*#__PURE__*/React.createElement(Popover.Element, null, /*#__PURE__*/React.createElement(RichTextToolbarButton, { dataHook: dataHook, onClick: this._onButtonClick, tooltipText: tooltipText, isDisabled: isDisabled, isActive: isActive || this.state.isFormShown }, children)), /*#__PURE__*/React.createElement(Popover.Content, null, /*#__PURE__*/React.createElement(Box, { padding: 3, width: "216px" }, /*#__PURE__*/React.createElement(RichTextInputAreaLinkForm, { dataHook: "richtextarea-form", onSubmit: this._onSubmit, onCancel: this._onHide, data: { text: selectedText } })))); } /* When clicking the button, one of the following occurs: 1. If the selected text does not contain a link, it will show the link insertion form 2. If the selected text contains a link, it will detach that link from the text */ }]); return RichTextToolbarLinkButton; }(React.Component); export default RichTextToolbarLinkButton;