import React from 'react' import cls from 'classnames' import i18n from 'i18next' import newEventActions from 'actions/newEvent' import newEventStores from 'stores/newEvent' import { getEventBlockByBid, getEventNodeById } from 'stores/funcs/newEvent' import { shallowEqualImmutable } from 'utils/utils' import { autoTextarea } from 'utils/commons/autoTextarea' class EditMemo extends React.Component { constructor(props) { super(props) this.state = { value: props.value } this.textarea = React.createRef() this.resetTextarea = this.resetTextarea.bind(this) this.onChange = this.onChange.bind(this) this.onBlur = this.onBlur.bind(this) this.getZIndex = this.getZIndex.bind(this) } componentDidMount() { if (this.textarea && this.textarea.current) { this.resetTextarea() } } componentDidUpdate(preProps) { if (preProps.value !== this.props.value) { this.setState( { value: this.props.value }, () => { if (this.textarea && this.textarea.current) { this.resetTextarea() } } ) } } resetTextarea() { this.textarea.current.removeAttribute('style') delete this.textarea.current._length delete this.textarea.current.currHeight autoTextarea(this.textarea.current, 0, undefined) } onChange(e) { let val = e && e.target ? e.target.value : e this.setState({ value: val }) } onBlur() { this.props.onChange && this.props.onChange({ memo: this.state.value }) } getZIndex() { let max = 99999 if (this.props.active) { return max } else if (this.props.order !== undefined) { return max - (this.props.order + 1) } else { return 0 } } render() { return (