| 1 |
import { useDispatch, useSelect } from '@wordpress/data'; |
| 2 |
|
| 3 |
export const useContentHighlight = () => { |
| 4 |
const { getBlockInsertionPoint } = useSelect( |
| 5 |
(select) => select('core/block-editor'), |
| 6 |
[], |
| 7 |
); |
| 8 |
const { toggleBlockHighlight, showInsertionPoint, hideInsertionPoint } = |
| 9 |
useDispatch('core/block-editor'); |
| 10 |
|
| 11 |
const toggleHighlight = (clientIds, { isHighlighted }) => { |
| 12 |
toggleBlockHighlight(clientIds[0], isHighlighted); |
| 13 |
}; |
| 14 |
|
| 15 |
const toggleInsertionPoint = ({ isVisible }) => { |
| 16 |
if (!isVisible) { |
| 17 |
hideInsertionPoint(); |
| 18 |
return; |
| 19 |
} |
| 20 |
const { rootClientId, index } = getBlockInsertionPoint(); |
| 21 |
showInsertionPoint(rootClientId, index); |
| 22 |
}; |
| 23 |
|
| 24 |
return { toggleHighlight, toggleInsertionPoint }; |
| 25 |
}; |
| 26 |
|