// eslint-disable-next-line filenames/match-exported import React, {PureComponent, PropTypes} from 'react'; import ReactDOM from 'react-dom'; import autobind from 'autobind-decorator'; import {DragSource, DropTarget} from 'react-dnd'; import classnames from 'classnames'; import FileInputButton from '../base/file-input-button'; import {Dropdown, DropdownItem, DropdownButton} from '../base/dropdown/index'; import PromptButton from '../base/prompt-button'; import Button from '../base/button'; import OneLineEditor from '../codemirror/one-line-editor'; @autobind class KeyValueEditorRow extends PureComponent { constructor (props) { super(props); this._nameInput = null; this._valueInput = null; this.state = { dragDirection: 0 }; } focusNameEnd () { if (this._nameInput) { this._nameInput.focusEnd(); } else { console.warn('Unable to focus non-existing nameInput'); } } focusValueEnd () { if (this._valueInput) { this._valueInput.focusEnd(); } else { console.warn('Unable to focus non-existing valueInput'); } } setDragDirection (dragDirection) { if (dragDirection !== this.state.dragDirection) { this.setState({dragDirection}); } } _setNameInputRef (n) { this._nameInput = n; } _setValueInputRef (n) { this._valueInput = n; } _sendChange (patch) { const pair = Object.assign({}, this.props.pair, patch); this.props.onChange && this.props.onChange(pair); } _handleNameChange (name) { this._sendChange({name}); } _handleValueChange (value) { this._sendChange({value}); } _handleFileNameChange (fileName) { this._sendChange({fileName}); } _handleTypeChange (type) { this._sendChange({type}); } _handleDisableChange (disabled) { this._sendChange({disabled}); } _handleFocusName (e) { this.props.onFocusName(this.props.pair, e); } _handleFocusValue (e) { this.props.onFocusValue(this.props.pair, e); } _handleBlurName (e) { if (this.props.onBlurName) { this.props.onBlurName(this.props.pair, e); } } _handleBlurValue (e) { if (this.props.onBlurName) { this.props.onBlurValue(this.props.pair, e); } } _handleDelete () { if (this.props.onDelete) { this.props.onDelete(this.props.pair); } } _handleKeyDown (e, value) { if (this.props.onKeyDown) { this.props.onKeyDown(this.props.pair, e, value); } } _handleAutocompleteNames () { const {handleGetAutocompleteNameConstants} = this.props; if (handleGetAutocompleteNameConstants) { return handleGetAutocompleteNameConstants(this.props.pair); } } _handleAutocompleteValues () { const {handleGetAutocompleteValueConstants} = this.props; if (handleGetAutocompleteValueConstants) { return handleGetAutocompleteValueConstants(this.props.pair); } } render () { const { pair, namePlaceholder, valuePlaceholder, handleRender, handleGetRenderContext, valueInputType, multipart, sortable, noDropZone, hideButtons, forceInput, readOnly, className, isDragging, isDraggingOver, noDelete, connectDragSource, connectDragPreview, connectDropTarget } = this.props; const {dragDirection} = this.state; const classes = classnames(className, { 'key-value-editor__row-wrapper': true, 'key-value-editor__row-wrapper--dragging': isDragging, 'key-value-editor__row-wrapper--dragging-above': isDraggingOver && dragDirection > 0, 'key-value-editor__row-wrapper--dragging-below': isDraggingOver && dragDirection < 0, 'key-value-editor__row-wrapper--disabled': pair.disabled }); let handle = null; if (sortable) { handle = connectDragSource(