UNPKG

@zohodesk/dot

Version:

In this Library, we Provide Some Basic Components to Build Your Application

256 lines (220 loc) 13.4 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _react = _interopRequireWildcard(require("react")); var _defaultProps = require("./props/defaultProps"); var _propTypes = require("./props/propTypes"); var _TextEditor = _interopRequireDefault(require("../TextEditor/TextEditor")); var _Textarea = _interopRequireDefault(require("@zohodesk/components/es/Textarea/Textarea")); var _VelocityAnimationGroup = _interopRequireDefault(require("@zohodesk/components/es/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup")); var _editorUtils = require("../../../utils/editorUtils"); var _TextEditorWrapperModule = _interopRequireDefault(require("./TextEditorWrapper.module.css")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } 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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } 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; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /* eslint-disable react/no-deprecated */ var TextEditorWrapper = /*#__PURE__*/function (_Component) { _inherits(TextEditorWrapper, _Component); var _super = _createSuper(TextEditorWrapper); function TextEditorWrapper(props) { var _this; _classCallCheck(this, TextEditorWrapper); _this = _super.call(this, props); var value = props.value, isEditorDefaultOpen = props.isEditorDefaultOpen; _this.state = { isEditorShow: isEditorDefaultOpen ? true : !!value }; _this.handleTextareaFocus = _this.handleTextareaFocus.bind(_assertThisInitialized(_this)); _this.toggleEdit = _this.toggleEdit.bind(_assertThisInitialized(_this)); _this.focusCallback = _this.focusCallback.bind(_assertThisInitialized(_this)); return _this; } _createClass(TextEditorWrapper, [{ key: "handleTextareaFocus", value: function handleTextareaFocus() { var _this2 = this; var _this$props = this.props, isReadOnly = _this$props.isReadOnly, isDisabled = _this$props.isDisabled; if (!isReadOnly && !isDisabled) { this.setState({ isEditorShow: true }, function () { setTimeout(function () { editor[_this2.props.id].squireInstance.focus(); }, 300); }); } } }, { key: "toggleEdit", value: function toggleEdit(value) { this.setState({ isEditorShow: value }); } }, { key: "focusCallback", value: function focusCallback() { var onFocus = this.props.onFocus; this.setState({ isEditorFocus: true }); onFocus && onFocus(); } }, { key: "UNSAFE_componentWillReceiveProps", value: function UNSAFE_componentWillReceiveProps(np) { var _this$props2 = this.props, id = _this$props2.id, value = _this$props2.value; if (np.value || typeof editor != 'undefined' && (0, _editorUtils.editorContentValidate)(editor[id])) { this.setState({ isEditorShow: true }); } else { if (!this.state.isEditorFocus && !this.props.isEditorDefaultOpen) { this.setState({ isEditorShow: false }); } } // if (np.value !== value && np.value == '') { // editor[id].setContent(''); // } } }, { key: "render", value: function render() { var isEditorShow = this.state.isEditorShow; var _this$props3 = this.props, id = _this$props3.id, onChange = _this$props3.onChange, value = _this$props3.value, onAttachmentUpload = _this$props3.onAttachmentUpload, needEditor = _this$props3.needEditor, dataId = _this$props3.dataId, isReadOnly = _this$props3.isReadOnly, isDisabled = _this$props3.isDisabled, getRef = _this$props3.getRef, textBoxSize = _this$props3.textBoxSize, textBoxVariant = _this$props3.textBoxVariant, editorMode = _this$props3.editorMode, editorSize = _this$props3.editorSize, editorBorder = _this$props3.editorBorder, EDITORURL = _this$props3.EDITORURL, isCustomScroll = _this$props3.isCustomScroll, initCallback = _this$props3.initCallback, loadingComponent = _this$props3.loadingComponent, handleAlertMessage = _this$props3.handleAlertMessage, editorCallback = _this$props3.editorCallback, editorBlurCallback = _this$props3.editorBlurCallback, editorOptions = _this$props3.editorOptions, changeEditorContent = _this$props3.changeEditorContent, shouldEditorUpdateContent = _this$props3.shouldEditorUpdateContent, setInlineAttachmentInProgress = _this$props3.setInlineAttachmentInProgress, handleEditorDropUpload = _this$props3.handleEditorDropUpload, ImgLazyLoad = _this$props3.ImgLazyLoad, i18nKeys = _this$props3.i18nKeys, isEditorDefaultOpen = _this$props3.isEditorDefaultOpen, needInlineAttachment = _this$props3.needInlineAttachment, customProps = _this$props3.customProps, dataSelectorId = _this$props3.dataSelectorId; var _customProps$Textarea = customProps.Textarea1Props, Textarea1Props = _customProps$Textarea === void 0 ? {} : _customProps$Textarea, _customProps$Textarea2 = customProps.Textarea2Props, Textarea2Props = _customProps$Textarea2 === void 0 ? {} : _customProps$Textarea2, _customProps$TextEdit = customProps.TextEditorProps, TextEditorProps = _customProps$TextEdit === void 0 ? {} : _customProps$TextEdit; var defaultObj = { needEditorFocus: !value }; var editorOptionsObject = Object.assign(defaultObj, editorOptions); return /*#__PURE__*/_react["default"].createElement("div", { className: _TextEditorWrapperModule["default"].container, "data-selector-id": dataSelectorId }, !isEditorShow ? /*#__PURE__*/_react["default"].createElement(_Textarea["default"], _extends({ onFocus: this.handleTextareaFocus, text: value, animated: !needEditor, onChange: onChange, dataId: dataId, isReadOnly: isReadOnly, isDisabled: isDisabled, needEffect: !(isReadOnly || isDisabled), getRef: getRef, size: textBoxSize, variant: textBoxVariant, customClass: _TextEditorWrapperModule["default"].textBox }, Textarea1Props)) : null, /*#__PURE__*/_react["default"].createElement(_VelocityAnimationGroup["default"], { name: "slideDown", runOnMount: true, enterDuration: '300', exitDuration: '400', isActive: isEditorShow, component: "div" }, /*#__PURE__*/_react["default"].createElement("div", { className: _TextEditorWrapperModule["default"].textEditor }, isEditorShow && needEditor ? /*#__PURE__*/_react["default"].createElement(_TextEditor["default"], _extends({ id: id, value: value, onChange: !isReadOnly && !isDisabled ? onChange : null, editorOptions: editorOptionsObject, onUpload: onAttachmentUpload, editorMode: editorMode, type: editorSize, border: editorBorder, dataId: dataId, getRef: getRef, plainTextSwitchCallback: !isReadOnly && !isDisabled ? onChange : null, EDITORURL: EDITORURL, isCustomScroll: isCustomScroll, initCallback: initCallback, loadingComponent: loadingComponent, handleAlertMessage: handleAlertMessage, toggleEdit: this.toggleEdit, isEditorDefaultOpen: isEditorDefaultOpen, editorCallback: editorCallback, i18nKeys: i18nKeys, ImgLazyLoad: ImgLazyLoad, blurCallback: editorBlurCallback, changeEditorContent: changeEditorContent, shouldUpdateContent: shouldEditorUpdateContent, setInlineAttachmentInProgress: setInlineAttachmentInProgress, handleDropUpload: handleEditorDropUpload, onFocus: this.focusCallback, needInlineAttachment: needInlineAttachment }, TextEditorProps)) : /*#__PURE__*/_react["default"].createElement(_Textarea["default"], _extends({ onFocus: this.handleTextareaFocus, text: value, animated: !needEditor, onChange: onChange, dataId: dataId, isReadOnly: isReadOnly, isDisabled: isDisabled, needEffect: !(isReadOnly || isDisabled), getRef: getRef, size: textBoxSize, variant: textBoxVariant }, Textarea2Props))))); } }]); return TextEditorWrapper; }(_react.Component); exports["default"] = TextEditorWrapper; TextEditorWrapper.propTypes = _propTypes.propTypes; TextEditorWrapper.defaultProps = _defaultProps.defaultProps;