From 0a42349267d9c13430716e1b9f9c71209e5093e6 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 23 Nov 2022 15:30:49 +0000 Subject: [PATCH 01/22] Add new prop to control 4th arg to insertBlock --- packages/block-editor/src/components/inserter/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/inserter/index.js b/packages/block-editor/src/components/inserter/index.js index 17183d13a87090..43b689f452931d 100644 --- a/packages/block-editor/src/components/inserter/index.js +++ b/packages/block-editor/src/components/inserter/index.js @@ -260,6 +260,7 @@ export default compose( [ allowedBlockType, directInsertBlock, onSelectOrClose, + selectBlockOnInsert, } = ownProps; if ( ! hasSingleBlockType && ! directInsertBlock ) { @@ -370,7 +371,12 @@ export default compose( [ blockToInsert = createBlock( allowedBlockType.name ); } - insertBlock( blockToInsert, getInsertionIndex(), rootClientId ); + insertBlock( + blockToInsert, + getInsertionIndex(), + rootClientId, + selectBlockOnInsert + ); if ( onSelectOrClose ) { onSelectOrClose(); From 35267a336a14958137fd8901927e4db880b82f43 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 23 Nov 2022 15:31:07 +0000 Subject: [PATCH 02/22] =?UTF-8?q?Don=E2=80=99t=20select=20block=20on=20ins?= =?UTF-8?q?ertion=20from=20offcanvas=20appender?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block-editor/src/components/off-canvas-editor/appender.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-editor/src/components/off-canvas-editor/appender.js b/packages/block-editor/src/components/off-canvas-editor/appender.js index bf4d4e7804fd5f..d58fdb05318777 100644 --- a/packages/block-editor/src/components/off-canvas-editor/appender.js +++ b/packages/block-editor/src/components/off-canvas-editor/appender.js @@ -39,6 +39,7 @@ export const Appender = forwardRef( ( props, ref ) => { position="bottom right" isAppender __experimentalIsQuick + selectBlockOnInsert={ false } { ...props } /> From ec85f0f52fd9a5eabdd7c85b7bc8d5ff4d45800a Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 24 Nov 2022 10:12:25 +0000 Subject: [PATCH 03/22] Make appender --- .../block-editor/src/components/off-canvas-editor/appender.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/appender.js b/packages/block-editor/src/components/off-canvas-editor/appender.js index d58fdb05318777..a8171f54f7a1bf 100644 --- a/packages/block-editor/src/components/off-canvas-editor/appender.js +++ b/packages/block-editor/src/components/off-canvas-editor/appender.js @@ -37,8 +37,7 @@ export const Appender = forwardRef( ( props, ref ) => { ref={ ref } rootClientId={ clientId } position="bottom right" - isAppender - __experimentalIsQuick + isAppender={ true } selectBlockOnInsert={ false } { ...props } /> From 83afff5dfed181dbb352f0dae6209f59154a5604 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 24 Nov 2022 10:31:02 +0000 Subject: [PATCH 04/22] Provide data on inserted block in Inserter block callback --- packages/block-editor/src/components/inserter/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/inserter/index.js b/packages/block-editor/src/components/inserter/index.js index 43b689f452931d..1c95f1a2eedf29 100644 --- a/packages/block-editor/src/components/inserter/index.js +++ b/packages/block-editor/src/components/inserter/index.js @@ -379,7 +379,9 @@ export default compose( [ ); if ( onSelectOrClose ) { - onSelectOrClose(); + onSelectOrClose( { + insertedBlock: blockToInsert, + } ); } const message = sprintf( From c12cf1eef1866503b82deb915398d9e24a6f6c40 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 25 Nov 2022 10:24:58 +0000 Subject: [PATCH 05/22] Extract updater function from Nav Link block This will make this easier to refactor in future From e317c9547d5a2bbe018678a6cf687ccc61743526 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 25 Nov 2022 10:25:09 +0000 Subject: [PATCH 06/22] Extract standalone Link UI component from Nav Link block From c3345fca22f75e0ab57ca483a00fc78c8a85823c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 25 Nov 2022 10:25:16 +0000 Subject: [PATCH 07/22] Rename Link UI props From 61fe222b16208d9ee4711ef64276b61690558e18 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 25 Nov 2022 10:25:20 +0000 Subject: [PATCH 08/22] Remove need for replaceBlock prop and colocate with component From 54ae328bb7e40e2e585aed0728ac65758881dc91 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 25 Nov 2022 10:25:25 +0000 Subject: [PATCH 09/22] Rename more props From 23297bdec828fc94448f382d657af2a36cff500e Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 25 Nov 2022 10:25:32 +0000 Subject: [PATCH 10/22] Remove deps on attributes in favour of generic updater prop From dc69e510246c0b5d111cd6ccab8a2c21c33c724b Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 25 Nov 2022 10:25:39 +0000 Subject: [PATCH 11/22] Colocate transforms control with Link UI component From 7bef73750908883efbddde6d010a344ab80302c4 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 25 Nov 2022 11:05:26 +0000 Subject: [PATCH 12/22] Copy Link UI from Nav Link Block --- .../components/off-canvas-editor/link-ui.js | 209 ++++++++++++++++++ .../off-canvas-editor/update-attributes.js | 103 +++++++++ 2 files changed, 312 insertions(+) create mode 100644 packages/block-editor/src/components/off-canvas-editor/link-ui.js create mode 100644 packages/block-editor/src/components/off-canvas-editor/update-attributes.js diff --git a/packages/block-editor/src/components/off-canvas-editor/link-ui.js b/packages/block-editor/src/components/off-canvas-editor/link-ui.js new file mode 100644 index 00000000000000..6ff6d0e3a82206 --- /dev/null +++ b/packages/block-editor/src/components/off-canvas-editor/link-ui.js @@ -0,0 +1,209 @@ +/** + * WordPress dependencies + */ +import { Popover, Button } from '@wordpress/components'; +import { __, sprintf } from '@wordpress/i18n'; +import { createInterpolateElement } from '@wordpress/element'; +import { store as coreStore } from '@wordpress/core-data'; +import { decodeEntities } from '@wordpress/html-entities'; +import { switchToBlockType } from '@wordpress/blocks'; +import { useSelect, useDispatch } from '@wordpress/data'; + +/** + * Internal dependencies + */ +import { + __experimentalLinkControl as LinkControl, + BlockIcon, + store as blockEditorStore, +} from '../../'; + +/** + * Given the Link block's type attribute, return the query params to give to + * /wp/v2/search. + * + * @param {string} type Link block's type attribute. + * @param {string} kind Link block's entity of kind (post-type|taxonomy) + * @return {{ type?: string, subtype?: string }} Search query params. + */ +export function getSuggestionsQuery( type, kind ) { + switch ( type ) { + case 'post': + case 'page': + return { type: 'post', subtype: type }; + case 'category': + return { type: 'term', subtype: 'category' }; + case 'tag': + return { type: 'term', subtype: 'post_tag' }; + case 'post_format': + return { type: 'post-format' }; + default: + if ( kind === 'taxonomy' ) { + return { type: 'term', subtype: type }; + } + if ( kind === 'post-type' ) { + return { type: 'post', subtype: type }; + } + return {}; + } +} + +/** + * Add transforms to Link Control + * + * @param {Object} props Component props. + * @param {string} props.clientId Block client ID. + */ +function LinkControlTransforms( { clientId } ) { + if ( ! clientId ) { + return null; + } + const { getBlock, blockTransforms } = useSelect( + ( select ) => { + const { + getBlock: _getBlock, + getBlockRootClientId, + getBlockTransformItems, + } = select( blockEditorStore ); + + return { + getBlock: _getBlock, + blockTransforms: getBlockTransformItems( + _getBlock( clientId ), + getBlockRootClientId( clientId ) + ), + }; + }, + [ clientId ] + ); + + const { replaceBlock } = useDispatch( blockEditorStore ); + + const featuredBlocks = [ + 'core/site-logo', + 'core/social-links', + 'core/search', + ]; + const transforms = blockTransforms.filter( ( item ) => { + return featuredBlocks.includes( item?.name ); + } ); + + if ( ! transforms?.length ) { + return null; + } + + return ( +
+

+ { __( 'Transform' ) } +

+
+ { transforms.map( ( item, index ) => { + return ( + + ); + } ) } +
+
+ ); +} + +export function LinkUI( props ) { + const { saveEntityRecord } = useDispatch( coreStore ); + + async function handleCreate( pageTitle ) { + const postType = props?.linkAttributes?.type || 'page'; + + const page = await saveEntityRecord( 'postType', postType, { + title: pageTitle, + status: 'draft', + } ); + + return { + id: page.id, + type: postType, + // Make `title` property consistent with that in `fetchLinkSuggestions` where the `rendered` title (containing HTML entities) + // is also being decoded. By being consistent in both locations we avoid having to branch in the rendering output code. + // Ideally in the future we will update both APIs to utilise the "raw" form of the title which is better suited to edit contexts. + // e.g. + // - title.raw = "Yes & No" + // - title.rendered = "Yes & No" + // - decodeEntities( title.rendered ) = "Yes & No" + // See: + // - https://github.com/WordPress/gutenberg/pull/41063 + // - https://github.com/WordPress/gutenberg/blob/a1e1fdc0e6278457e9f4fc0b31ac6d2095f5450b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js#L212-L218 + title: decodeEntities( page.title.rendered ), + url: page.link, + kind: 'post-type', + }; + } + + return ( + + { + let format; + + if ( props?.linkAttributes.type === 'post' ) { + /* translators: %s: search term. */ + format = __( 'Create draft post: %s' ); + } else { + /* translators: %s: search term. */ + format = __( 'Create draft page: %s' ); + } + + return createInterpolateElement( + sprintf( format, searchTerm ), + { + mark: , + } + ); + } } + noDirectEntry={ !! props?.linkAttributes?.type } + noURLSuggestion={ !! props?.linkAttributes?.type } + suggestionsQuery={ getSuggestionsQuery( + props?.linkAttributes?.type, + props?.linkAttributes?.kind + ) } + onChange={ props.onChange } + onRemove={ props.onRemove } + renderControlBottom={ + ! props?.linkAttributes?.url + ? () => ( + + ) + : null + } + /> + + ); +} diff --git a/packages/block-editor/src/components/off-canvas-editor/update-attributes.js b/packages/block-editor/src/components/off-canvas-editor/update-attributes.js new file mode 100644 index 00000000000000..247498107ac35b --- /dev/null +++ b/packages/block-editor/src/components/off-canvas-editor/update-attributes.js @@ -0,0 +1,103 @@ +/** + * External dependencies + */ +import escapeHtml from 'escape-html'; + +/** + * WordPress dependencies + */ +import { safeDecodeURI } from '@wordpress/url'; + +/** + * @typedef {'post-type'|'custom'|'taxonomy'|'post-type-archive'} WPNavigationLinkKind + */ +/** + * Navigation Link Block Attributes + * + * @typedef {Object} WPNavigationLinkBlockAttributes + * + * @property {string} [label] Link text. + * @property {WPNavigationLinkKind} [kind] Kind is used to differentiate between term and post ids to check post draft status. + * @property {string} [type] The type such as post, page, tag, category and other custom types. + * @property {string} [rel] The relationship of the linked URL. + * @property {number} [id] A post or term id. + * @property {boolean} [opensInNewTab] Sets link target to _blank when true. + * @property {string} [url] Link href. + * @property {string} [title] Link title attribute. + */ +/** + * Link Control onChange handler that updates block attributes when a setting is changed. + * + * @param {Object} updatedValue New block attributes to update. + * @param {Function} setAttributes Block attribute update function. + * @param {WPNavigationLinkBlockAttributes} blockAttributes Current block attributes. + * + */ + +export const updateAttributes = ( + updatedValue = {}, + setAttributes, + blockAttributes = {} +) => { + const { + label: originalLabel = '', + kind: originalKind = '', + type: originalType = '', + } = blockAttributes; + + const { + title: newLabel = '', // the title of any provided Post. + url: newUrl = '', + opensInNewTab, + id, + kind: newKind = originalKind, + type: newType = originalType, + } = updatedValue; + + const newLabelWithoutHttp = newLabel.replace( /http(s?):\/\//gi, '' ); + const newUrlWithoutHttp = newUrl.replace( /http(s?):\/\//gi, '' ); + + const useNewLabel = + newLabel && + newLabel !== originalLabel && + // LinkControl without the title field relies + // on the check below. Specifically, it assumes that + // the URL is the same as a title. + // This logic a) looks suspicious and b) should really + // live in the LinkControl and not here. It's a great + // candidate for future refactoring. + newLabelWithoutHttp !== newUrlWithoutHttp; + + // Unfortunately this causes the escaping model to be inverted. + // The escaped content is stored in the block attributes (and ultimately in the database), + // and then the raw data is "recovered" when outputting into the DOM. + // It would be preferable to store the **raw** data in the block attributes and escape it in JS. + // Why? Because there isn't one way to escape data. Depending on the context, you need to do + // different transforms. It doesn't make sense to me to choose one of them for the purposes of storage. + // See also: + // - https://github.com/WordPress/gutenberg/pull/41063 + // - https://github.com/WordPress/gutenberg/pull/18617. + const label = useNewLabel + ? escapeHtml( newLabel ) + : originalLabel || escapeHtml( newUrlWithoutHttp ); + + // In https://github.com/WordPress/gutenberg/pull/24670 we decided to use "tag" in favor of "post_tag" + const type = newType === 'post_tag' ? 'tag' : newType.replace( '-', '_' ); + + const isBuiltInType = + [ 'post', 'page', 'tag', 'category' ].indexOf( type ) > -1; + + const isCustomLink = + ( ! newKind && ! isBuiltInType ) || newKind === 'custom'; + const kind = isCustomLink ? 'custom' : newKind; + + setAttributes( { + // Passed `url` may already be encoded. To prevent double encoding, decodeURI is executed to revert to the original string. + ...( newUrl && { url: encodeURI( safeDecodeURI( newUrl ) ) } ), + ...( label && { label } ), + ...( undefined !== opensInNewTab && { opensInNewTab } ), + ...( id && Number.isInteger( id ) && { id } ), + ...( kind && { kind } ), + ...( type && type !== 'URL' && { type } ), + } ); +}; From 53c282453adfed2105756d6cb99e4cedd56c5da6 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 25 Nov 2022 11:06:54 +0000 Subject: [PATCH 13/22] Experiment with including Link UI in offcanvas --- .../components/off-canvas-editor/appender.js | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/appender.js b/packages/block-editor/src/components/off-canvas-editor/appender.js index a8171f54f7a1bf..b461ddf427418d 100644 --- a/packages/block-editor/src/components/off-canvas-editor/appender.js +++ b/packages/block-editor/src/components/off-canvas-editor/appender.js @@ -1,15 +1,19 @@ /** * WordPress dependencies */ -import { useSelect } from '@wordpress/data'; -import { forwardRef } from '@wordpress/element'; +import { useSelect, useDispatch } from '@wordpress/data'; +import { forwardRef, useState } from '@wordpress/element'; /** * Internal dependencies */ import { store as blockEditorStore } from '../../store'; import Inserter from '../inserter'; +import { LinkUI } from './link-ui'; +import { updateAttributes } from './update-attributes'; export const Appender = forwardRef( ( props, ref ) => { + const [ insertedBlock, setInsertedBlock ] = useState(); + const { hideInserter, clientId } = useSelect( ( select ) => { const { getTemplateLock, @@ -27,18 +31,58 @@ export const Appender = forwardRef( ( props, ref ) => { }; }, [] ); + const { updateBlockAttributes } = useDispatch( blockEditorStore ); + + const setAttributes = + ( insertedBlockClientId ) => ( _updatedAttributes ) => { + updateBlockAttributes( insertedBlockClientId, _updatedAttributes ); + }; + + let maybeLinkUI; + + if ( insertedBlock ) { + const link = { + url: insertedBlock.attributes.url, + opensInNewTab: insertedBlock.attributes.target === '_blank', + }; + maybeLinkUI = ( + setInsertedBlock( null ) } + hasCreateSuggestion={ false } + onChange={ ( updatedValue ) => { + updateAttributes( + updatedValue, + setAttributes( insertedBlock.clientId ), + insertedBlock.attributes + ); + } } + /> + ); + } + if ( hideInserter ) { return null; } return (
+ { maybeLinkUI } { + setInsertedBlock( _insertedBlock ); + } } { ...props } />
From 6c4fdce864d66966f87f2e9f4bd203f32a54960f Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 25 Nov 2022 16:19:00 +0000 Subject: [PATCH 14/22] Select inserted link attributes to dynamically update UI --- .../src/components/inserter/index.js | 2 +- .../components/off-canvas-editor/appender.js | 31 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/block-editor/src/components/inserter/index.js b/packages/block-editor/src/components/inserter/index.js index 1c95f1a2eedf29..59c04e24d2bbb4 100644 --- a/packages/block-editor/src/components/inserter/index.js +++ b/packages/block-editor/src/components/inserter/index.js @@ -380,7 +380,7 @@ export default compose( [ if ( onSelectOrClose ) { onSelectOrClose( { - insertedBlock: blockToInsert, + insertedBlockId: blockToInsert?.clientId, } ); } diff --git a/packages/block-editor/src/components/off-canvas-editor/appender.js b/packages/block-editor/src/components/off-canvas-editor/appender.js index b461ddf427418d..50b395fcf92465 100644 --- a/packages/block-editor/src/components/off-canvas-editor/appender.js +++ b/packages/block-editor/src/components/off-canvas-editor/appender.js @@ -31,6 +31,17 @@ export const Appender = forwardRef( ( props, ref ) => { }; }, [] ); + const { insertedBlockAttributes } = useSelect( + ( select ) => { + const { getBlockAttributes } = select( blockEditorStore ); + + return { + insertedBlockAttributes: getBlockAttributes( insertedBlock ), + }; + }, + [ insertedBlock ] + ); + const { updateBlockAttributes } = useDispatch( blockEditorStore ); const setAttributes = @@ -42,25 +53,25 @@ export const Appender = forwardRef( ( props, ref ) => { if ( insertedBlock ) { const link = { - url: insertedBlock.attributes.url, - opensInNewTab: insertedBlock.attributes.target === '_blank', + url: insertedBlockAttributes.url, + opensInNewTab: insertedBlockAttributes.target === '_blank', }; maybeLinkUI = ( setInsertedBlock( null ) } hasCreateSuggestion={ false } onChange={ ( updatedValue ) => { updateAttributes( updatedValue, - setAttributes( insertedBlock.clientId ), - insertedBlock.attributes + setAttributes( insertedBlock ), + insertedBlockAttributes ); } } /> @@ -80,8 +91,8 @@ export const Appender = forwardRef( ( props, ref ) => { position="bottom right" isAppender={ true } selectBlockOnInsert={ false } - onSelectOrClose={ ( { insertedBlock: _insertedBlock } ) => { - setInsertedBlock( _insertedBlock ); + onSelectOrClose={ ( { insertedBlockId } ) => { + setInsertedBlock( insertedBlockId ); } } { ...props } /> From 63322ceb109aff269c67f59a4e6f54cedb77ff00 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 28 Nov 2022 10:48:23 +0000 Subject: [PATCH 15/22] Pass title and new tab props to Link UI --- .../block-editor/src/components/off-canvas-editor/appender.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/appender.js b/packages/block-editor/src/components/off-canvas-editor/appender.js index 50b395fcf92465..c6d47c9164b166 100644 --- a/packages/block-editor/src/components/off-canvas-editor/appender.js +++ b/packages/block-editor/src/components/off-canvas-editor/appender.js @@ -54,7 +54,8 @@ export const Appender = forwardRef( ( props, ref ) => { if ( insertedBlock ) { const link = { url: insertedBlockAttributes.url, - opensInNewTab: insertedBlockAttributes.target === '_blank', + opensInNewTab: insertedBlockAttributes.opensInNewTab, + title: insertedBlockAttributes.label, }; maybeLinkUI = ( Date: Mon, 28 Nov 2022 11:21:33 +0000 Subject: [PATCH 16/22] Remove create suggestion and resulting dep on Core Data package --- .../components/off-canvas-editor/link-ui.js | 61 ++----------------- 1 file changed, 6 insertions(+), 55 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/link-ui.js b/packages/block-editor/src/components/off-canvas-editor/link-ui.js index 6ff6d0e3a82206..187b535d8fdba2 100644 --- a/packages/block-editor/src/components/off-canvas-editor/link-ui.js +++ b/packages/block-editor/src/components/off-canvas-editor/link-ui.js @@ -2,10 +2,7 @@ * WordPress dependencies */ import { Popover, Button } from '@wordpress/components'; -import { __, sprintf } from '@wordpress/i18n'; -import { createInterpolateElement } from '@wordpress/element'; -import { store as coreStore } from '@wordpress/core-data'; -import { decodeEntities } from '@wordpress/html-entities'; +import { __ } from '@wordpress/i18n'; import { switchToBlockType } from '@wordpress/blocks'; import { useSelect, useDispatch } from '@wordpress/data'; @@ -55,9 +52,6 @@ export function getSuggestionsQuery( type, kind ) { * @param {string} props.clientId Block client ID. */ function LinkControlTransforms( { clientId } ) { - if ( ! clientId ) { - return null; - } const { getBlock, blockTransforms } = useSelect( ( select ) => { const { @@ -84,6 +78,7 @@ function LinkControlTransforms( { clientId } ) { 'core/social-links', 'core/search', ]; + const transforms = blockTransforms.filter( ( item ) => { return featuredBlocks.includes( item?.name ); } ); @@ -92,6 +87,10 @@ function LinkControlTransforms( { clientId } ) { return null; } + if ( ! clientId ) { + return null; + } + return (

@@ -124,35 +123,6 @@ function LinkControlTransforms( { clientId } ) { } export function LinkUI( props ) { - const { saveEntityRecord } = useDispatch( coreStore ); - - async function handleCreate( pageTitle ) { - const postType = props?.linkAttributes?.type || 'page'; - - const page = await saveEntityRecord( 'postType', postType, { - title: pageTitle, - status: 'draft', - } ); - - return { - id: page.id, - type: postType, - // Make `title` property consistent with that in `fetchLinkSuggestions` where the `rendered` title (containing HTML entities) - // is also being decoded. By being consistent in both locations we avoid having to branch in the rendering output code. - // Ideally in the future we will update both APIs to utilise the "raw" form of the title which is better suited to edit contexts. - // e.g. - // - title.raw = "Yes & No" - // - title.rendered = "Yes & No" - // - decodeEntities( title.rendered ) = "Yes & No" - // See: - // - https://github.com/WordPress/gutenberg/pull/41063 - // - https://github.com/WordPress/gutenberg/blob/a1e1fdc0e6278457e9f4fc0b31ac6d2095f5450b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js#L212-L218 - title: decodeEntities( page.title.rendered ), - url: page.link, - kind: 'post-type', - }; - } - return ( { - let format; - - if ( props?.linkAttributes.type === 'post' ) { - /* translators: %s: search term. */ - format = __( 'Create draft post: %s' ); - } else { - /* translators: %s: search term. */ - format = __( 'Create draft page: %s' ); - } - - return createInterpolateElement( - sprintf( format, searchTerm ), - { - mark: , - } - ); - } } noDirectEntry={ !! props?.linkAttributes?.type } noURLSuggestion={ !! props?.linkAttributes?.type } suggestionsQuery={ getSuggestionsQuery( From 450931e847d1bbda1a4a1e1f94a2baf3716c4d4e Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 28 Nov 2022 12:50:31 +0000 Subject: [PATCH 17/22] Use WP version of escape html over lodash dep --- package-lock.json | 1 + packages/block-editor/package.json | 1 + .../src/components/off-canvas-editor/update-attributes.js | 6 +----- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index ffe9ff267906a8..67746a860933a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17498,6 +17498,7 @@ "@wordpress/deprecated": "file:packages/deprecated", "@wordpress/dom": "file:packages/dom", "@wordpress/element": "file:packages/element", + "@wordpress/escape-html": "file:packages/escape-html", "@wordpress/hooks": "file:packages/hooks", "@wordpress/html-entities": "file:packages/html-entities", "@wordpress/i18n": "file:packages/i18n", diff --git a/packages/block-editor/package.json b/packages/block-editor/package.json index e90f7aaf4619f4..59aee136894e78 100644 --- a/packages/block-editor/package.json +++ b/packages/block-editor/package.json @@ -44,6 +44,7 @@ "@wordpress/deprecated": "file:../deprecated", "@wordpress/dom": "file:../dom", "@wordpress/element": "file:../element", + "@wordpress/escape-html": "file:../escape-html", "@wordpress/hooks": "file:../hooks", "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", diff --git a/packages/block-editor/src/components/off-canvas-editor/update-attributes.js b/packages/block-editor/src/components/off-canvas-editor/update-attributes.js index 247498107ac35b..9f982abc091fd0 100644 --- a/packages/block-editor/src/components/off-canvas-editor/update-attributes.js +++ b/packages/block-editor/src/components/off-canvas-editor/update-attributes.js @@ -1,11 +1,7 @@ -/** - * External dependencies - */ -import escapeHtml from 'escape-html'; - /** * WordPress dependencies */ +import { escapeHtml } from '@wordpress/escape-html'; import { safeDecodeURI } from '@wordpress/url'; /** From 0a713708a55007331e46c2c176afa23caca146fd Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Mon, 28 Nov 2022 12:52:51 +0000 Subject: [PATCH 18/22] Update packages/block-editor/src/components/off-canvas-editor/link-ui.js Co-authored-by: Dave Smith --- .../block-editor/src/components/off-canvas-editor/link-ui.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/block-editor/src/components/off-canvas-editor/link-ui.js b/packages/block-editor/src/components/off-canvas-editor/link-ui.js index 187b535d8fdba2..1f34447605ccb4 100644 --- a/packages/block-editor/src/components/off-canvas-editor/link-ui.js +++ b/packages/block-editor/src/components/off-canvas-editor/link-ui.js @@ -1,3 +1,6 @@ + +// Note: this file is copied directly from packages/block-library/src/navigation-link/link-ui.js + /** * WordPress dependencies */ From defbdbae1590bb0fac2c391ad8624496fceff328 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 28 Nov 2022 16:32:07 +0000 Subject: [PATCH 19/22] Separately import to fix unit tests --- .../src/components/off-canvas-editor/link-ui.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/link-ui.js b/packages/block-editor/src/components/off-canvas-editor/link-ui.js index 1f34447605ccb4..7e576cf79d632d 100644 --- a/packages/block-editor/src/components/off-canvas-editor/link-ui.js +++ b/packages/block-editor/src/components/off-canvas-editor/link-ui.js @@ -12,11 +12,9 @@ import { useSelect, useDispatch } from '@wordpress/data'; /** * Internal dependencies */ -import { - __experimentalLinkControl as LinkControl, - BlockIcon, - store as blockEditorStore, -} from '../../'; +import { store as blockEditorStore } from '../../store'; +import LinkControl from '../link-control'; +import BlockIcon from '../block-icon'; /** * Given the Link block's type attribute, return the query params to give to From 983f4e2237aae2dd579536302823e6569bdf02e6 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 28 Nov 2022 17:19:07 +0000 Subject: [PATCH 20/22] Fix lint --- .../block-editor/src/components/off-canvas-editor/link-ui.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/link-ui.js b/packages/block-editor/src/components/off-canvas-editor/link-ui.js index 7e576cf79d632d..d1bc94896209ea 100644 --- a/packages/block-editor/src/components/off-canvas-editor/link-ui.js +++ b/packages/block-editor/src/components/off-canvas-editor/link-ui.js @@ -1,4 +1,3 @@ - // Note: this file is copied directly from packages/block-library/src/navigation-link/link-ui.js /** From 383faa30d4973677749f91d88941dcc89fcd9e50 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 28 Nov 2022 17:36:24 +0000 Subject: [PATCH 21/22] Use the correct import! --- .../src/components/off-canvas-editor/update-attributes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/update-attributes.js b/packages/block-editor/src/components/off-canvas-editor/update-attributes.js index 9f982abc091fd0..5133cae3878338 100644 --- a/packages/block-editor/src/components/off-canvas-editor/update-attributes.js +++ b/packages/block-editor/src/components/off-canvas-editor/update-attributes.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { escapeHtml } from '@wordpress/escape-html'; +import { escapeHTML } from '@wordpress/escape-html'; import { safeDecodeURI } from '@wordpress/url'; /** @@ -74,8 +74,8 @@ export const updateAttributes = ( // - https://github.com/WordPress/gutenberg/pull/41063 // - https://github.com/WordPress/gutenberg/pull/18617. const label = useNewLabel - ? escapeHtml( newLabel ) - : originalLabel || escapeHtml( newUrlWithoutHttp ); + ? escapeHTML( newLabel ) + : originalLabel || escapeHTML( newUrlWithoutHttp ); // In https://github.com/WordPress/gutenberg/pull/24670 we decided to use "tag" in favor of "post_tag" const type = newType === 'post_tag' ? 'tag' : newType.replace( '-', '_' ); From 13eb8e3b6b07b062ad8d94e37328e531ca168d60 Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Tue, 29 Nov 2022 11:39:55 +0000 Subject: [PATCH 22/22] Close the link appender --- .../block-editor/src/components/off-canvas-editor/appender.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-editor/src/components/off-canvas-editor/appender.js b/packages/block-editor/src/components/off-canvas-editor/appender.js index c6d47c9164b166..b19093543c508c 100644 --- a/packages/block-editor/src/components/off-canvas-editor/appender.js +++ b/packages/block-editor/src/components/off-canvas-editor/appender.js @@ -74,6 +74,7 @@ export const Appender = forwardRef( ( props, ref ) => { setAttributes( insertedBlock ), insertedBlockAttributes ); + setInsertedBlock( null ); } } /> );