Skip to content

Commit dc38e85

Browse files
authored
fix (icon list): revert fix to icon list item, use splitting instead (#3384)
1 parent 7dd6949 commit dc38e85

File tree

2 files changed

+3
-47
lines changed

2 files changed

+3
-47
lines changed

src/block/icon-list-item/edit.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import blockStyles from './style'
55
import { getUseSvgDef } from '../icon-list/util'
66
import {
77
convertToListItems,
8-
useOnPaste,
98
useEnter,
109
} from './util'
1110

@@ -110,7 +109,6 @@ const Edit = props => {
110109
] )
111110

112111
const useEnterRef = useEnter( text, clientId )
113-
const onPaste = useOnPaste( clientId, parentBlock?.clientId, attributes, setAttributes )
114112

115113
const onMerge = forward => {
116114
mergeBlocks( forward )
@@ -173,7 +171,6 @@ const Edit = props => {
173171
tagName="span"
174172
className={ textClassNames }
175173
onMerge={ onMerge }
176-
onPaste={ onPaste }
177174
onReplace={ onReplace
178175
? ( blocks, ...args ) => {
179176
onReplace(

src/block/icon-list-item/util.js

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
* WordPress dependencies
44
*/
55
import { useRefEffect } from '@wordpress/compose'
6-
import { useCallback, useRef } from '@wordpress/element'
6+
import { useRef } from '@wordpress/element'
77
import {
8-
useSelect, useDispatch, dispatch,
8+
useSelect,
9+
useDispatch,
910
} from '@wordpress/data'
1011
import {
1112
cloneBlock,
1213
switchToBlockType,
1314
createBlock,
1415
getDefaultBlockName,
15-
pasteHandler,
1616
} from '@wordpress/blocks'
1717
import { store as blockEditorStore } from '@wordpress/block-editor'
1818
import { ENTER } from '@wordpress/keycodes'
@@ -123,44 +123,3 @@ export const useEnter = ( text, clientId ) => {
123123
[ clientId ]
124124
)
125125
}
126-
127-
export const useOnPaste = ( clientId, parentClientId, attributes, setAttributes ) => {
128-
const { insertBlocks } = useDispatch( blockEditorStore )
129-
const { getBlockIndex } = useSelect( blockEditorStore )
130-
131-
return useCallback( event => {
132-
event.preventDefault()
133-
const html = event.clipboardData.getData( 'text/html' )
134-
const plain = event.clipboardData.getData( 'text/plain' )
135-
136-
// Convert first to core/list block.
137-
const list = pasteHandler( {
138-
HTML: html,
139-
plainText: plain,
140-
mode: 'BLOCKS',
141-
} )
142-
143-
// If list[0] has inner blocks, it has been converted to core/list block, else list has core/paragraph elements.
144-
const items = list[ 0 ].innerBlocks.length ? list[ 0 ].innerBlocks : list
145-
146-
const content = items.map( item => item.attributes.content.toPlainText().replaceAll( '\n', '<br>' ) )
147-
148-
// If current icon list item has no text, use the first item as text.
149-
if ( ! attributes.text ) {
150-
const firstItem = content.shift()
151-
setAttributes( { text: firstItem } )
152-
}
153-
154-
// create new icon list items
155-
const newBlocks = content.map( text => {
156-
const block = createBlock( 'stackable/icon-list-item', {
157-
...attributes,
158-
text,
159-
} )
160-
161-
return block
162-
} )
163-
dispatch( 'core/block-editor' ).__unstableMarkNextChangeAsNotPersistent()
164-
insertBlocks( newBlocks, getBlockIndex( clientId ) + 1, parentClientId )
165-
}, [ clientId, parentClientId, attributes, setAttributes ] )
166-
}

0 commit comments

Comments
 (0)