|
3 | 3 | * WordPress dependencies |
4 | 4 | */ |
5 | 5 | import { useRefEffect } from '@wordpress/compose' |
6 | | -import { useCallback, useRef } from '@wordpress/element' |
| 6 | +import { useRef } from '@wordpress/element' |
7 | 7 | import { |
8 | | - useSelect, useDispatch, dispatch, |
| 8 | + useSelect, |
| 9 | + useDispatch, |
9 | 10 | } from '@wordpress/data' |
10 | 11 | import { |
11 | 12 | cloneBlock, |
12 | 13 | switchToBlockType, |
13 | 14 | createBlock, |
14 | 15 | getDefaultBlockName, |
15 | | - pasteHandler, |
16 | 16 | } from '@wordpress/blocks' |
17 | 17 | import { store as blockEditorStore } from '@wordpress/block-editor' |
18 | 18 | import { ENTER } from '@wordpress/keycodes' |
@@ -123,44 +123,3 @@ export const useEnter = ( text, clientId ) => { |
123 | 123 | [ clientId ] |
124 | 124 | ) |
125 | 125 | } |
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