From 943b72aecdfa160e925e43dad4cfbc9f9b277810 Mon Sep 17 00:00:00 2001 From: Hit Bhalodia <58802366+hbhalodia@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:39:56 +0530 Subject: [PATCH] Fix: Embed blocks: adding captions via toolbar (#64394) * Add the Caption component to be used for consistency on the embed block similar to audio and image * Change the label for the embed caption text Co-authored-by: hbhalodia Co-authored-by: Rishit30G Co-authored-by: t-hamano Co-authored-by: simison --- packages/block-library/src/embed/edit.js | 9 +++++ .../block-library/src/embed/embed-preview.js | 40 ++----------------- 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/packages/block-library/src/embed/edit.js b/packages/block-library/src/embed/edit.js index 12265883d6963c..0b589eb68ecf49 100644 --- a/packages/block-library/src/embed/edit.js +++ b/packages/block-library/src/embed/edit.js @@ -14,6 +14,7 @@ import { embedContentIcon } from './icons'; import EmbedLoading from './embed-loading'; import EmbedPlaceholder from './embed-placeholder'; import EmbedPreview from './embed-preview'; +import { Caption } from '../utils/caption'; /** * External dependencies @@ -277,6 +278,14 @@ const EmbedEdit = ( props ) => { label={ label } insertBlocksAfter={ insertBlocksAfter } /> + ); diff --git a/packages/block-library/src/embed/embed-preview.js b/packages/block-library/src/embed/embed-preview.js index ba079cc2e1e8b6..d53f1148cee13c 100644 --- a/packages/block-library/src/embed/embed-preview.js +++ b/packages/block-library/src/embed/embed-preview.js @@ -13,13 +13,8 @@ import clsx from 'clsx'; */ import { __, sprintf } from '@wordpress/i18n'; import { Placeholder, SandBox } from '@wordpress/components'; -import { - RichText, - BlockIcon, - __experimentalGetElementClassName, -} from '@wordpress/block-editor'; +import { BlockIcon } from '@wordpress/block-editor'; import { Component } from '@wordpress/element'; -import { createBlock, getDefaultBlockName } from '@wordpress/blocks'; import { getAuthority } from '@wordpress/url'; /** @@ -57,19 +52,8 @@ class EmbedPreview extends Component { } render() { - const { - preview, - previewable, - url, - type, - caption, - onCaptionChange, - isSelected, - className, - icon, - label, - insertBlocksAfter, - } = this.props; + const { preview, previewable, url, type, className, icon, label } = + this.props; const { scripts } = preview; const { interactive } = this.state; @@ -139,24 +123,6 @@ class EmbedPreview extends Component {

) } - { ( ! RichText.isEmpty( caption ) || isSelected ) && ( - - insertBlocksAfter( - createBlock( getDefaultBlockName() ) - ) - } - /> - ) } ); }