From dc38e850ad1db79a8fc973cf87a788cfd8f98b73 Mon Sep 17 00:00:00 2001 From: Alquen Antonio Sarmiento Date: Wed, 15 Jan 2025 18:56:31 +0800 Subject: [PATCH] fix (icon list): revert fix to icon list item, use splitting instead (#3384) --- src/block/icon-list-item/edit.js | 3 -- src/block/icon-list-item/util.js | 47 ++------------------------------ 2 files changed, 3 insertions(+), 47 deletions(-) diff --git a/src/block/icon-list-item/edit.js b/src/block/icon-list-item/edit.js index 5684ae2f5..51f183dc9 100644 --- a/src/block/icon-list-item/edit.js +++ b/src/block/icon-list-item/edit.js @@ -5,7 +5,6 @@ import blockStyles from './style' import { getUseSvgDef } from '../icon-list/util' import { convertToListItems, - useOnPaste, useEnter, } from './util' @@ -110,7 +109,6 @@ const Edit = props => { ] ) const useEnterRef = useEnter( text, clientId ) - const onPaste = useOnPaste( clientId, parentBlock?.clientId, attributes, setAttributes ) const onMerge = forward => { mergeBlocks( forward ) @@ -173,7 +171,6 @@ const Edit = props => { tagName="span" className={ textClassNames } onMerge={ onMerge } - onPaste={ onPaste } onReplace={ onReplace ? ( blocks, ...args ) => { onReplace( diff --git a/src/block/icon-list-item/util.js b/src/block/icon-list-item/util.js index f869f43dd..ca48a416e 100644 --- a/src/block/icon-list-item/util.js +++ b/src/block/icon-list-item/util.js @@ -3,16 +3,16 @@ * WordPress dependencies */ import { useRefEffect } from '@wordpress/compose' -import { useCallback, useRef } from '@wordpress/element' +import { useRef } from '@wordpress/element' import { - useSelect, useDispatch, dispatch, + useSelect, + useDispatch, } from '@wordpress/data' import { cloneBlock, switchToBlockType, createBlock, getDefaultBlockName, - pasteHandler, } from '@wordpress/blocks' import { store as blockEditorStore } from '@wordpress/block-editor' import { ENTER } from '@wordpress/keycodes' @@ -123,44 +123,3 @@ export const useEnter = ( text, clientId ) => { [ clientId ] ) } - -export const useOnPaste = ( clientId, parentClientId, attributes, setAttributes ) => { - const { insertBlocks } = useDispatch( blockEditorStore ) - const { getBlockIndex } = useSelect( blockEditorStore ) - - return useCallback( event => { - event.preventDefault() - const html = event.clipboardData.getData( 'text/html' ) - const plain = event.clipboardData.getData( 'text/plain' ) - - // Convert first to core/list block. - const list = pasteHandler( { - HTML: html, - plainText: plain, - mode: 'BLOCKS', - } ) - - // If list[0] has inner blocks, it has been converted to core/list block, else list has core/paragraph elements. - const items = list[ 0 ].innerBlocks.length ? list[ 0 ].innerBlocks : list - - const content = items.map( item => item.attributes.content.toPlainText().replaceAll( '\n', '
' ) ) - - // If current icon list item has no text, use the first item as text. - if ( ! attributes.text ) { - const firstItem = content.shift() - setAttributes( { text: firstItem } ) - } - - // create new icon list items - const newBlocks = content.map( text => { - const block = createBlock( 'stackable/icon-list-item', { - ...attributes, - text, - } ) - - return block - } ) - dispatch( 'core/block-editor' ).__unstableMarkNextChangeAsNotPersistent() - insertBlocks( newBlocks, getBlockIndex( clientId ) + 1, parentClientId ) - }, [ clientId, parentClientId, attributes, setAttributes ] ) -}