import React from 'react'; import PropTypes from 'prop-types'; import {connect} from 'react-redux'; import Textarea from 'react-textarea-autosize'; import {gettext} from 'core/utils'; import {VideoComponent} from 'core/ui/components/video'; import {isMediaEditable} from 'core/config'; import * as actions from '../../actions'; import {PlainTextEditor} from 'core/ui/components'; function getTranslationForAssignRights(value) { if (value === 'single-usage') { return gettext('Single Usage'); } else if (value === 'time-restricted') { return gettext('Time Restricted'); } else if (value === 'indefinite-usage') { return gettext('Indefinite Usage'); } else if (typeof value === 'string') { return value; } else { return null; } } /** * @ngdoc React * @module superdesk.core.editor3 * @name MediaBlockComponent * @param {Function} cropImage Dispatches the crop image action. * @param {Object} block Information about the block where this component renders. * @description This component renders an image block within the editor. */ export class MediaBlockComponent extends React.Component { static propTypes: any; static defaultProps: any; container: any; scrollTimeout: any; constructor(props) { super(props); this.onClick = this.onClick.bind(this); this.onClickDelete = this.onClickDelete.bind(this); this.data = this.data.bind(this); this.onChange = this.onChange.bind(this); } /** * @ngdoc method * @name MediaBlockComponent#data * @returns {Object} Image data * @description Returns the image data. */ data() { const {block, contentState} = this.props; const entityKey = block.getEntityAt(0); const entity = contentState.getEntity(entityKey); const {media} = entity.getData(); return media; } /** * @ngdoc method * @name MediaBlockComponent#onClick * @description Handles clicking on the image event. Dispatches the crop image * action. */ onClick(tab) { const {block, cropImage, contentState} = this.props; const entityKey = block.getEntityAt(0); const entity = contentState.getEntity(entityKey); const data = entity.getData(); const isNew = false; const showMetadata = true; const defaultTab = tab; cropImage(entityKey, data, {isNew, showMetadata, defaultTab}); } /** * @ngdoc method * @name MediaBlockComponent#onClickDelete * @description Handles clicking on the delete button. Dispatches the * remove block action. */ onClickDelete() { const {block, removeBlock} = this.props; removeBlock(block.getKey()); } /** * @ngdoc method * @name MediaBlockComponent#onChange * @description Triggered (debounced) when the image caption input is edited. */ onChange(value: string, field: 'description_text' | 'headline') { const {block, changeCaption} = this.props; const entityKey = block.getEntityAt(0); changeCaption(entityKey, value, field); } render() { const {setLocked, showTitle, readOnly} = this.props; const data = this.data(); const rendition = data.renditions.baseImage || data.renditions.viewImage || data.renditions.original; const alt = data.alt_text || data.description_text || data.caption; const mediaType = data.type; const editable = !readOnly && (data._type !== 'externalsource' || isMediaEditable(data)); return (
e.stopPropagation()}> { readOnly ? null : ( ) }
{showTitle ? (