From 9be5a92c7dacec81f2b9d1d8bb0b1398b9dc33a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?So=CC=88ren=20Wrede?= Date: Sun, 4 Nov 2018 20:46:18 +0100 Subject: [PATCH 1/5] Change embed urls to embed block --- packages/block-library/src/audio/edit.js | 13 +++++++++++++ packages/block-library/src/image/edit.js | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/block-library/src/audio/edit.js b/packages/block-library/src/audio/edit.js index ed5c7d5aee2d9..ee2966208d015 100644 --- a/packages/block-library/src/audio/edit.js +++ b/packages/block-library/src/audio/edit.js @@ -21,6 +21,11 @@ import { } from '@wordpress/editor'; import { getBlobByURL, isBlobURL } from '@wordpress/blob'; +/** + * Internal dependencies + */ +import { createUpgradedEmbedBlock } from '../embed/util'; + const ALLOWED_MEDIA_TYPES = [ 'audio' ]; class AudioEdit extends Component { @@ -73,6 +78,14 @@ class AudioEdit extends Component { // Set the block's src from the edit component's state, and switch off // the editing UI. if ( newSrc !== src ) { + // Check if there's an embed block that handles this URL. + const embedBlock = createUpgradedEmbedBlock( + { attributes: { url: newSrc } } + ); + if ( undefined !== embedBlock ) { + this.props.onReplace( embedBlock ); + return; + } setAttributes( { src: newSrc, id: undefined } ); } diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index fa675533d775d..dbca445eccdd3 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -46,6 +46,7 @@ import { compose } from '@wordpress/compose'; /** * Internal dependencies */ +import { createUpgradedEmbedBlock } from '../embed/util'; import ImageSize from './image-size'; /** @@ -186,6 +187,14 @@ class ImageEdit extends Component { const { url } = this.props.attributes; if ( newURL !== url ) { + // Check if there's an embed block that handles this URL. + const embedBlock = createUpgradedEmbedBlock( + { attributes: { url: newURL } } + ); + if ( undefined !== embedBlock ) { + this.props.onReplace( embedBlock ); + return; + } this.props.setAttributes( { url: newURL, id: undefined, From abb00d3819e4031758fbd62078a66a3493731ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?So=CC=88ren=20Wrede?= Date: Tue, 13 Nov 2018 17:24:40 +0100 Subject: [PATCH 2/5] image error --- packages/block-library/src/image/edit.js | 26 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 5f5375b434138..2e0ad0f59e4ac 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -104,6 +104,7 @@ class ImageEdit extends Component { this.getFilename = this.getFilename.bind( this ); this.toggleIsEditing = this.toggleIsEditing.bind( this ); this.onUploadError = this.onUploadError.bind( this ); + this.onImageError = this.onImageError.bind( this ); this.state = { captionFocused: false, @@ -198,14 +199,6 @@ class ImageEdit extends Component { const { url } = this.props.attributes; if ( newURL !== url ) { - // Check if there's an embed block that handles this URL. - const embedBlock = createUpgradedEmbedBlock( - { attributes: { url: newURL } } - ); - if ( undefined !== embedBlock ) { - this.props.onReplace( embedBlock ); - return; - } this.props.setAttributes( { url: newURL, id: undefined, @@ -217,6 +210,16 @@ class ImageEdit extends Component { } ); } + onImageError( url ) { + // Check if there's an embed block that handles this URL. + const embedBlock = createUpgradedEmbedBlock( + { attributes: { url } } + ); + if ( undefined !== embedBlock ) { + this.props.onReplace( embedBlock ); + } + } + onSetCustomHref( value ) { this.props.setAttributes( { href: value } ); } @@ -518,7 +521,12 @@ class ImageEdit extends Component { // Disable reason: Image itself is not meant to be // interactive, but should direct focus to block // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions - const img = {; + const img = { this.onImageError( url ) } + />; if ( ! isResizable || ! imageWidthWithinContainer ) { return ( From 8d47ac758c6b1348cb4185dc0fe88402b795b365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?So=CC=88ren=20Wrede?= Date: Tue, 13 Nov 2018 17:27:11 +0100 Subject: [PATCH 3/5] one line --- packages/block-library/src/image/edit.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 2e0ad0f59e4ac..785cf1b41ac49 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -521,12 +521,7 @@ class ImageEdit extends Component { // Disable reason: Image itself is not meant to be // interactive, but should direct focus to block // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions - const img = { this.onImageError( url ) } - />; + const img = { this.onImageError( url ) } />; if ( ! isResizable || ! imageWidthWithinContainer ) { return ( From 71e420a9fb63a1f618b361b23af66bf0c78a9e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Wrede?= Date: Thu, 15 Nov 2018 11:40:25 +0100 Subject: [PATCH 4/5] Update packages/block-library/src/image/edit.js --- packages/block-library/src/image/edit.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 0d6e2e961af12..7f1377e474338 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -519,7 +519,6 @@ class ImageEdit extends Component { } else { defaultedAlt = __( 'This image has an empty alt attribute' ); } - const img = ( // Disable reason: Image itself is not meant to be interactive, but // should direct focus to block. From 47ec4cb215c5b7fcb6490badf804a9cafbfde734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?So=CC=88ren=20Wrede?= Date: Thu, 15 Nov 2018 11:42:03 +0100 Subject: [PATCH 5/5] Merge master --- packages/block-library/src/image/edit.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 7f1377e474338..2301340bf7052 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -519,6 +519,7 @@ class ImageEdit extends Component { } else { defaultedAlt = __( 'This image has an empty alt attribute' ); } + const img = ( // Disable reason: Image itself is not meant to be interactive, but // should direct focus to block.