-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (43 loc) · 1.24 KB
/
index.js
File metadata and controls
48 lines (43 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* WordPress dependencies
*/
import { useRefEffect } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';
export default function useFlashEditableBlocks( rootClientId = '' ) {
const { getEnabledClientIdsTree } = unlock( useSelect( blockEditorStore ) );
return useRefEffect( ( element ) => {
const flashEditableBlocks = () => {
getEnabledClientIdsTree( rootClientId ).forEach(
( { clientId } ) => {
const blockElement = element.querySelector(
`[data-block="${ clientId }"]`
);
if ( ! blockElement ) {
return;
}
blockElement.classList.remove( 'has-editable-outline' );
// Force reflow to trigger the animation.
// eslint-disable-next-line no-unused-expressions
blockElement.offsetWidth;
blockElement.classList.add( 'has-editable-outline' );
}
);
};
const handleClick = ( event ) => {
if ( event.defaultPrevented ) {
return;
}
event.preventDefault();
flashEditableBlocks();
};
element.addEventListener( 'click', handleClick );
return () => {
element.removeEventListener( 'click', handleClick );
};
} );
}