UNPKG

@zohodesk/dot

Version:

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

229 lines (196 loc) 13.5 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 _Label = _interopRequireDefault(require("@zohodesk/components/lib/Label/Label")); var _ValidationMessage = _interopRequireDefault(require("../ValidationMessage/ValidationMessage")); var _TextEditorWrapper = _interopRequireDefault(require("../TextEditorWrapper/TextEditorWrapper")); var _FieldContainer = _interopRequireDefault(require("../FieldContainer/FieldContainer")); var _FieldsModule = _interopRequireDefault(require("../Fields.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); } var TextEditorField = /*#__PURE__*/function (_PureComponent) { _inherits(TextEditorField, _PureComponent); var _super = _createSuper(TextEditorField); function TextEditorField(props) { var _this; _classCallCheck(this, TextEditorField); _this = _super.call(this, props); _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this)); _this.handleGetRef = _this.handleGetRef.bind(_assertThisInitialized(_this)); _this.handleLabelClick = _this.handleLabelClick.bind(_assertThisInitialized(_this)); _this.renderEnd = _this.renderEnd.bind(_assertThisInitialized(_this)); return _this; } _createClass(TextEditorField, [{ key: "handleChange", value: function handleChange(value) { var _this$props = this.props, id = _this$props.id, onChange = _this$props.onChange; onChange && onChange(id, value); } }, { key: "handleGetRef", value: function handleGetRef(el) { var _this$props2 = this.props, getRef = _this$props2.getRef, id = _this$props2.id; this.textEditor = el; getRef && getRef(el, id); } }, { key: "handleLabelClick", value: function handleLabelClick() { var _this$props3 = this.props, isFocusOnLabelClick = _this$props3.isFocusOnLabelClick, isDisabled = _this$props3.isDisabled, isReadOnly = _this$props3.isReadOnly; if (isFocusOnLabelClick && !isDisabled && !isReadOnly && this.textEditor && this.textEditor.focus) { this.textEditor.focus(); } } }, { key: "renderEnd", value: function renderEnd() { var children = this.props.children; return children ? children : null; } }, { key: "render", value: function render() { var _this$props4 = this.props, labelName = _this$props4.labelName, id = _this$props4.id, isMandatory = _this$props4.isMandatory, value = _this$props4.value, validationMessage = _this$props4.validationMessage, validationPalette = _this$props4.validationPalette, isReadOnly = _this$props4.isReadOnly, onAttachmentUpload = _this$props4.onAttachmentUpload, needEditor = _this$props4.needEditor, dataId = _this$props4.dataId, dataSelectorId = _this$props4.dataSelectorId, isDisabled = _this$props4.isDisabled, fieldSize = _this$props4.fieldSize, textBoxSize = _this$props4.textBoxSize, textBoxVariant = _this$props4.textBoxVariant, labelPalette = _this$props4.labelPalette, labelCustomClass = _this$props4.labelCustomClass, infoText = _this$props4.infoText, isLocked = _this$props4.isLocked, lockedInfoText = _this$props4.lockedInfoText, errorType = _this$props4.errorType, EDITORURL = _this$props4.EDITORURL, editorMode = _this$props4.editorMode, isCustomScroll = _this$props4.isCustomScroll, initCallback = _this$props4.initCallback, loadingComponent = _this$props4.loadingComponent, handleAlertMessage = _this$props4.handleAlertMessage, editorCallback = _this$props4.editorCallback, editorBlurCallback = _this$props4.editorBlurCallback, editorOptions = _this$props4.editorOptions, onFocus = _this$props4.onFocus, isEditorDefaultOpen = _this$props4.isEditorDefaultOpen, changeEditorContent = _this$props4.changeEditorContent, shouldEditorUpdateContent = _this$props4.shouldEditorUpdateContent, setInlineAttachmentInProgress = _this$props4.setInlineAttachmentInProgress, handleEditorDropUpload = _this$props4.handleEditorDropUpload, ImgLazyLoad = _this$props4.ImgLazyLoad, needInlineAttachment = _this$props4.needInlineAttachment, i18nKeys = _this$props4.i18nKeys, className = _this$props4.className, ePhiData = _this$props4.ePhiData, customProps = _this$props4.customProps; var _customProps$LabelPro = customProps.LabelProps, LabelProps = _customProps$LabelPro === void 0 ? {} : _customProps$LabelPro, _customProps$TextEdit = customProps.TextEditorWrapperProps, TextEditorWrapperProps = _customProps$TextEdit === void 0 ? {} : _customProps$TextEdit, _customProps$Validati = customProps.ValidationMessageProps, ValidationMessageProps = _customProps$Validati === void 0 ? {} : _customProps$Validati; return /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(_FieldsModule["default"].container, " ").concat(isDisabled ? _FieldsModule["default"].disabled : isReadOnly ? _FieldsModule["default"].readonly : '', " ").concat(className || ''), "data-selector-id": dataSelectorId }, labelName && /*#__PURE__*/_react["default"].createElement(_FieldContainer["default"], { infoText: infoText, isLocked: isLocked, lockedInfoText: lockedInfoText, ePhiData: ePhiData, dataId: dataId, renderProps: { end: this.renderEnd } }, /*#__PURE__*/_react["default"].createElement(_Label["default"], _extends({ text: labelName, size: fieldSize === 'small' ? 'small' : 'medium', htmlFor: !isReadOnly && !isDisabled ? id : undefined, palette: isMandatory ? 'mandatory' : isDisabled ? 'primary' : labelPalette, onClick: this.handleLabelClick, customClass: "".concat(_FieldsModule["default"].fieldLabel, " ").concat(labelCustomClass, " ").concat(isMandatory ? _FieldsModule["default"].labelMandatory : ''), dataId: isDisabled ? "".concat(dataId, "_label_disabled") : isMandatory ? "".concat(dataId, "_label_mandatory") : "".concat(dataId, "_label") }, LabelProps))), /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(_FieldsModule["default"].fieldContainer, " ").concat(labelName ? _FieldsModule["default"]["fieldMargin_".concat(fieldSize)] : '') }, /*#__PURE__*/_react["default"].createElement(_TextEditorWrapper["default"], _extends({ needEditor: needEditor, onChange: this.handleChange, id: id, value: value, isReadOnly: isReadOnly, getRef: this.handleGetRef, onAttachmentUpload: onAttachmentUpload, dataId: dataId, isDisabled: isDisabled, textBoxSize: fieldSize === 'medium' ? textBoxSize : 'xsmall', textBoxVariant: textBoxVariant, EDITORURL: EDITORURL, editorMode: editorMode, isCustomScroll: isCustomScroll, initCallback: initCallback, loadingComponent: loadingComponent, handleAlertMessage: handleAlertMessage, editorCallback: editorCallback, i18nKeys: i18nKeys, ImgLazyLoad: ImgLazyLoad, editorOptions: editorOptions, editorBlurCallback: editorBlurCallback, onFocus: onFocus, isEditorDefaultOpen: isEditorDefaultOpen, changeEditorContent: changeEditorContent, shouldEditorUpdateContent: shouldEditorUpdateContent, setInlineAttachmentInProgress: setInlineAttachmentInProgress, handleEditorDropUpload: handleEditorDropUpload, needInlineAttachment: needInlineAttachment }, TextEditorWrapperProps))), validationMessage && /*#__PURE__*/_react["default"].createElement(_ValidationMessage["default"], _extends({ text: validationMessage, palette: validationPalette, type: errorType, dataId: "".concat(dataId, "_ValidationMessage") }, ValidationMessageProps))); } }]); return TextEditorField; }(_react.PureComponent); exports["default"] = TextEditorField; TextEditorField.propTypes = _propTypes.propTypes; TextEditorField.defaultProps = _defaultProps.defaultProps; // if (__DOCS__) { // TextEditorField.docs = { // componentGroup: 'Fields' // }; // }