!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],t):"object"==typeof exports?exports["openstack-uicore-foundation"]=t():e["openstack-uicore-foundation"]=t()}(this,(()=>(()=>{"use strict";var e={8779:e=>{e.exports=require("@babel/runtime/helpers/defineProperty")},8213:e=>{e.exports=require("@babel/runtime/helpers/extends")},3838:e=>{e.exports=require("@babel/runtime/helpers/objectWithoutProperties")},6689:e=>{e.exports=require("react")},9231:e=>{e.exports=require("react-rte")}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}(()=>{r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t}})(),(()=>{r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})}})(),(()=>{r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var n={};return(()=>{r.r(n),r.d(n,{default:()=>h});var e=r(8213),t=r.n(e),o=r(3838),i=r.n(o),l=r(8779),a=r.n(l),s=r(6689),u=r.n(s);const c=["onChange","value","error","className","id","maxLength"];function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function d(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){a()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}class h extends u().Component{constructor(e){var t;if(super(e),this.RichTextEditor=null,this.getTextAlignClassName=null,this.getTextAlignStyles=null,"undefined"!=typeof window){const{default:e,getTextAlignClassName:t,getTextAlignStyles:n}=r(9231);this.RichTextEditor=e,this.getTextAlignClassName=t,this.getTextAlignStyles=n}this.state={editorValue:null===(t=this.RichTextEditor)||void 0===t?void 0:t.createEmptyValue(),currentValue:null},this.handleChange=this.handleChange.bind(this)}static getDerivedStateFromProps(e,t){const{value:n}=e,{editorValue:o,currentValue:i}=t;if(null!=i&&n===i)return t;let l=o.setContentFromString(n,"html");if("undefined"!=typeof window){const{getTextAlignBlockMetadata:e}=r(9231);l=o.setContentFromString(n,"html",{customBlockFn:e})}return d(d({},t),{},{editorValue:l,currentValue:n})}handleChange(e){let t=this.state.editorValue;if(this.setState({editorValue:e}),(t?t.getEditorState().getCurrentContent():null)!==e.getEditorState().getCurrentContent()){let t=e.toString("html",{blockStyleFn:this.getTextAlignStyles});if(t="<p><br></p>"===t?"":t,this.setState({currentValue:t}),t!==this.props.value){let e={target:{id:this.props.id,value:t,type:"texteditor"}};this.props.onChange(e)}}}render(){const e=this.props,{onChange:r,value:n,error:o,className:l,id:a,maxLength:s}=e,p=i()(e,c),{currentValue:d,editorValue:h}=this.state,g=this.props.hasOwnProperty("error")&&""!==o,f=s-d.length;return u().createElement("div",{className:"editor-input"},this.RichTextEditor&&u().createElement(this.RichTextEditor,t()({id:a,className:l+" "+(g?"error":""),value:h,onChange:this.handleChange,blockStyleFn:this.getTextAlignClassName},p)),!!s&&u().createElement("p",null,u().createElement("i",null,"characters left: ",f)),g&&u().createElement("p",{className:"error-label"},o))}}})(),n})()));
//# sourceMappingURL=editor-input.js.map