import { createElement, Component, Fragment } from '@wordpress/element' import classnames from 'classnames' import { __ } from 'ct-i18n' import _ from 'underscore' import { applyFilters } from '@wordpress/hooks' const ALLOWED_MEDIA_TYPES = ['image'] export default class MultiImageUploader extends Component { params = { height: 250, width: 250, flex_width: true, flex_height: true, } state = { attachment_info: [], } getUrlFor = (attachmentInfo) => attachmentInfo ? (attachmentInfo.width < 700 ? attachmentInfo.sizes.full : _.max( _.values( _.keys(attachmentInfo.sizes).length === 1 ? attachmentInfo.sizes : _.omit(attachmentInfo.sizes, 'full') ), ({ width }) => width ) ).url || attachmentInfo.url : null render() { const actions = applyFilters( 'blocksy.options.ct-multi-image-uploader.actions', [ ({ props, attachment: { attachment_id } }) => ( ), ] ) return (
{ const result = media.map((attachment) => ({ url: this.getUrlFor(attachment), attachment_id: attachment.id, })) this.props.onChange(result) }} gallery={true} allowedTypes={ALLOWED_MEDIA_TYPES} value={this.props.value.map( ({ attachment_id }) => attachment_id )} multiple={true} render={({ open }) => ( {Array.isArray(this.props.value) && this.props.value.length > 0 && (
{this.props.value.map( ({ url, attachment_id, ...attachment }) => (
{ open() }}>
    {actions.map( (a, index) => (
  • {a({ props: this .props, attachment: { ...attachment, url, attachment_id, }, })}
  • ) )}
) )}
)}
)} />
) } }