-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathinner-blocks.js
52 lines (48 loc) · 1.26 KB
/
inner-blocks.js
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
49
50
51
52
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { useEntityBlockEditor } from '@wordpress/core-data';
import { InnerBlocks, useInnerBlocksProps } from '@wordpress/block-editor';
import { useRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import useIsDraggingWithin from './use-is-dragging-within';
export default function WidgetAreaInnerBlocks( { id } ) {
const [ blocks, onInput, onChange ] = useEntityBlockEditor(
'root',
'postType'
);
const innerBlocksRef = useRef();
const isDraggingWithinInnerBlocks = useIsDraggingWithin( innerBlocksRef );
const shouldHighlightDropZone = isDraggingWithinInnerBlocks;
// Using the experimental hook so that we can control the className of the element.
const innerBlocksProps = useInnerBlocksProps(
{ ref: innerBlocksRef },
{
value: blocks,
onInput,
onChange,
templateLock: false,
renderAppender: InnerBlocks.ButtonBlockAppender,
}
);
return (
<div
data-widget-area-id={ id }
className={ clsx(
'wp-block-widget-area__inner-blocks block-editor-inner-blocks editor-styles-wrapper',
{
'wp-block-widget-area__highlight-drop-zone':
shouldHighlightDropZone,
}
) }
>
<div { ...innerBlocksProps } />
</div>
);
}