-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathedit.js
More file actions
157 lines (139 loc) · 3.85 KB
/
edit.js
File metadata and controls
157 lines (139 loc) · 3.85 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Internal dependencies
*/
import blockStyles from './style'
/**
* External dependencies
*/
import { version as VERSION, i18n } from 'stackable'
import { last } from 'lodash'
import classnames from 'classnames'
import {
InspectorBottomTip,
InspectorStyleControls,
InspectorTabs,
useBlockCssGenerator,
} from '~stackable/components'
import {
BlockDiv,
ContainerDiv,
ConditionalDisplay,
getAlignmentClasses,
EffectsAnimations,
CustomAttributes,
CustomCSS,
Responsive,
Advanced,
MarginBottom,
BlockLink,
Transform,
} from '~stackable/block-components'
import {
withBlockAttributeContext, withBlockWrapperIsHovered, withQueryLoopContext,
} from '~stackable/higher-order'
import { substituteCoreIfDisabled } from '~stackable/util'
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose'
import { InnerBlocks } from '@wordpress/block-editor'
import { __ } from '@wordpress/i18n'
import { memo } from '@wordpress/element'
import { useSelect } from '@wordpress/data'
export const TEMPLATE = [
[ 'stackable/icon-label', { blockMargin: { bottom: 0 } }, [
[ 'stackable/icon', { contentAlign: 'left' } ],
[ 'stackable/heading', {
text: __( 'Icon Box', i18n ), hasP: true, textTag: 'h4',
} ],
] ],
substituteCoreIfDisabled( 'stackable/text', {
text: 'Description for this block. Use this space for describing your block.',
} ),
]
const Edit = props => {
const {
className,
} = props
const { hasInnerBlocks, innerBlocks } = useSelect( select => {
const { getBlock } = select( 'core/block-editor' )
const innerBlocks = getBlock( props.clientId ).innerBlocks
return {
hasInnerBlocks: innerBlocks.length > 0,
innerBlocks,
}
}, [ props.clientId ] )
const blockAlignmentClass = getAlignmentClasses( props.attributes )
const blockClassNames = classnames( [
className,
'stk-block-icon-box',
] )
const contentClassNames = classnames( [
'stk-block-content',
'stk-inner-blocks',
blockAlignmentClass,
'stk-block-icon-box__content',
] )
const lastBlockName = last( innerBlocks )?.name
const renderAppender = hasInnerBlocks ? ( [ 'stackable/text', 'core/paragraph' ].includes( lastBlockName ) ? () => <></> : InnerBlocks.DefaultBlockAppender ) : InnerBlocks.ButtonBlockAppender
// Generate the CSS styles for the block.
const blockCss = useBlockCssGenerator( {
attributes: props.attributes,
blockStyles,
clientId: props.clientId,
context: props.context,
setAttributes: props.setAttributes,
blockState: props.blockState,
version: VERSION,
} )
return (
<>
<InspectorControls />
<BlockDiv
blockHoverClass={ props.blockHoverClass }
clientId={ props.clientId }
attributes={ props.attributes }
className={ blockClassNames }
>
{ blockCss && <style key="block-css">{ blockCss }</style> }
<CustomCSS mainBlockClass="stk-block-icon-box" />
<ContainerDiv className={ contentClassNames }>
<InnerBlocks
template={ TEMPLATE }
templateLock={ false }
renderAppender={ renderAppender }
/>
</ContainerDiv>
</BlockDiv>
{ props.isHovered && <MarginBottom /> }
</>
)
}
const InspectorControls = memo( () => {
return (
<>
<InspectorTabs hasLayoutPanel={ false } />
<BlockDiv.InspectorControls />
<BlockLink.InspectorControls />
<Advanced.InspectorControls />
<Transform.InspectorControls />
<EffectsAnimations.InspectorControls />
<CustomAttributes.InspectorControls />
<CustomCSS.InspectorControls mainBlockClass="stk-block-icon-box" />
<Responsive.InspectorControls />
<ConditionalDisplay.InspectorControls />
<ContainerDiv.InspectorControls
sizeSelector=".stk-block-content"
hasContentVerticalAlign={ true }
/>
<InspectorStyleControls>
<InspectorBottomTip />
</InspectorStyleControls>
</>
)
} )
export default compose(
withBlockWrapperIsHovered,
withQueryLoopContext,
withBlockAttributeContext,
)( Edit )