Skip to content

Commit

Permalink
Fix: Remove editor usage from some media blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed May 9, 2019
1 parent d17e867 commit c7338ee
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
22 changes: 18 additions & 4 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { getBlobByURL, isBlobURL } from '@wordpress/blob';
import { compose } from '@wordpress/compose';
import {
Disabled,
IconButton,
Expand All @@ -18,9 +19,9 @@ import {
MediaPlaceholder,
RichText,
} from '@wordpress/block-editor';
import { mediaUpload } from '@wordpress/editor';
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { withSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -48,7 +49,12 @@ class AudioEdit extends Component {
}

componentDidMount() {
const { attributes, noticeOperations, setAttributes } = this.props;
const {
attributes,
mediaUpload,
noticeOperations,
setAttributes,
} = this.props;
const { id, src = '' } = attributes;

if ( ! id && isBlobURL( src ) ) {
Expand Down Expand Up @@ -195,5 +201,13 @@ class AudioEdit extends Component {
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
}
}

export default withNotices( AudioEdit );
export default compose( [
withSelect( ( select ) => {
const { getSettings } = select( 'core/block-editor' );
const { __experimentalMediaUpload } = getSettings();
return {
mediaUpload: __experimentalMediaUpload,
};
} ),
withNotices,
] )( AudioEdit );
11 changes: 9 additions & 2 deletions packages/block-library/src/file/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
MediaPlaceholder,
RichText,
} from '@wordpress/block-editor';
import { mediaUpload } from '@wordpress/editor';
import { Component } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';

Expand Down Expand Up @@ -55,7 +54,12 @@ class FileEdit extends Component {
}

componentDidMount() {
const { attributes, noticeOperations, setAttributes } = this.props;
const {
attributes,
mediaUpload,
noticeOperations,
setAttributes,
} = this.props;
const { downloadButtonText, href } = attributes;

// Upload a file drag-and-dropped into the editor
Expand Down Expand Up @@ -242,9 +246,12 @@ class FileEdit extends Component {
export default compose( [
withSelect( ( select, props ) => {
const { getMedia } = select( 'core' );
const { getSettings } = select( 'core/block-editor' );
const { __experimentalMediaUpload } = getSettings();
const { id } = props.attributes;
return {
media: id === undefined ? undefined : getMedia( id ),
mediaUpload: __experimentalMediaUpload,
};
} ),
withNotices,
Expand Down
16 changes: 13 additions & 3 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
MediaPlaceholder,
RichText,
} from '@wordpress/block-editor';
import { mediaUpload } from '@wordpress/editor';
import { Component } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { getPath } from '@wordpress/url';
Expand Down Expand Up @@ -126,7 +125,12 @@ class ImageEdit extends Component {
}

componentDidMount() {
const { attributes, setAttributes, noticeOperations } = this.props;
const {
attributes,
mediaUpload,
noticeOperations,
setAttributes,
} = this.props;
const { id, url = '' } = attributes;

if ( isTemporaryImage( id, url ) ) {
Expand Down Expand Up @@ -720,13 +724,19 @@ export default compose( [
const { getMedia } = select( 'core' );
const { getSettings } = select( 'core/block-editor' );
const { id } = props.attributes;
const { maxWidth, isRTL, imageSizes } = getSettings();
const {
__experimentalMediaUpload,
imageSizes,
isRTL,
maxWidth,
} = getSettings();

return {
image: id ? getMedia( id ) : null,
maxWidth,
isRTL,
imageSizes,
mediaUpload: __experimentalMediaUpload,
};
} ),
withViewportMatch( { isLargeViewport: 'medium' } ),
Expand Down
18 changes: 16 additions & 2 deletions packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
MediaUploadCheck,
RichText,
} from '@wordpress/block-editor';
import { mediaUpload } from '@wordpress/editor';
import { Component, createRef } from '@wordpress/element';
import {
__,
Expand All @@ -32,6 +31,9 @@ import {
compose,
withInstanceId,
} from '@wordpress/compose';
import {
withSelect,
} from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -60,7 +62,12 @@ class VideoEdit extends Component {
}

componentDidMount() {
const { attributes, noticeOperations, setAttributes } = this.props;
const {
attributes,
mediaUpload,
noticeOperations,
setAttributes,
} = this.props;
const { id, src = '' } = attributes;
if ( ! id && isBlobURL( src ) ) {
const file = getBlobByURL( src );
Expand Down Expand Up @@ -301,6 +308,13 @@ class VideoEdit extends Component {
}

export default compose( [
withSelect( ( select ) => {
const { getSettings } = select( 'core/block-editor' );
const { __experimentalMediaUpload } = getSettings();
return {
mediaUpload: __experimentalMediaUpload,
};
} ),
withNotices,
withInstanceId,
] )( VideoEdit );

0 comments on commit c7338ee

Please sign in to comment.