-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathedit.js
More file actions
168 lines (150 loc) · 3.9 KB
/
edit.js
File metadata and controls
168 lines (150 loc) · 3.9 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
158
159
160
161
162
163
164
165
166
167
168
/**
* Internal dependencies
*/
import BlockStyles from './style'
/**
* External dependencies
*/
import classnames from 'classnames'
import {
version as VERSION, i18n, settings,
} from 'stackable'
import { InspectorTabs, AlignButtonsControl } from '~stackable/components'
import { useBlockContext } from '~stackable/hooks'
import {
BlockDiv,
useGeneratedCss,
Image,
Advanced,
CustomCSS,
Responsive,
CustomAttributes,
EffectsAnimations,
ConditionalDisplay,
MarginBottom,
Transform,
getAlignmentClasses,
Link,
Alignment,
Typography,
getTypographyClasses,
} from '~stackable/block-components'
import {
withBlockAttributeContext,
withBlockWrapperIsHovered,
withQueryLoopContext,
} from '~stackable/higher-order'
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n'
import { compose } from '@wordpress/compose'
import { useBlockEditContext } from '@wordpress/block-editor'
import { applyFilters, addFilter } from '@wordpress/hooks'
const heightUnit = [ 'px', 'vh', '%' ]
const Edit = props => {
const {
clientId,
className,
isSelected,
} = props
useGeneratedCss( props.attributes )
const figcaptionClassnames = classnames(
getTypographyClasses( props.attributes, 'figcaption%s' ),
'stk-img-figcaption',
{ 'wp-element-caption': settings.stackable_inherit_caption_styles_from_theme },
)
const blockAlignmentClass = getAlignmentClasses( props.attributes )
const { parentBlock } = useBlockContext( clientId )
// Allow special or layout blocks to disable the link for the image block,
// e.g. image box doesn't need the image to have a link since it has it's
// own link.
const enableLink = applyFilters( 'stackable.edit.image.enable-link', true, parentBlock )
const blockClassNames = classnames( [
className,
'stk-block-image',
blockAlignmentClass,
] )
return (
<>
{ isSelected && (
<>
<InspectorTabs />
<Alignment.InspectorControls />
<Image.InspectorControls
{ ...props }
initialOpen={ true }
heightUnits={ heightUnit }
hasLightbox
/>
{ enableLink && <Link.InspectorControls hasTitle={ true } isAdvancedTab={ true } /> }
<BlockDiv.InspectorControls />
<Advanced.InspectorControls />
<Transform.InspectorControls />
<EffectsAnimations.InspectorControls />
<CustomAttributes.InspectorControls />
<CustomCSS.InspectorControls mainBlockClass="stk-block-image" />
<Responsive.InspectorControls />
<ConditionalDisplay.InspectorControls />
<Typography.InspectorControls
label={ __( 'Caption', i18n ) }
attrNameTemplate="figcaption%s"
hasToggle={ true }
hasTextTag={ false }
hasTextContent={ true }
initialOpen={ false }
/>
</>
) }
<BlockStyles
version={ VERSION }
blockState={ props.blockState }
clientId={ clientId }
/>
<CustomCSS mainBlockClass="stk-block-image" />
<BlockDiv
blockHoverClass={ props.blockHoverClass }
clientId={ props.clientId }
attributes={ props.attributes }
className={ blockClassNames }
>
<Image
showTooltips
heightUnits={ heightUnit }
defaultWidth="100"
defaultHeight="auto"
/>
{ props.attributes.figcaptionShow &&
<Typography
className={ figcaptionClassnames }
attrNameTemplate="figcaption%s"
placeholder={ __( 'Image Caption', i18n ) }
/>
}
</BlockDiv>
{ props.isHovered && <MarginBottom /> }
</>
)
}
export default compose(
withBlockWrapperIsHovered,
withQueryLoopContext,
withBlockAttributeContext,
)( Edit )
addFilter( 'stackable.block-component.typography.before', 'stackable/image', ( output, props ) => {
const { name } = useBlockEditContext()
if ( name !== 'stackable/image' ) {
return output
}
if ( props.attrNameTemplate !== 'figcaption%s' ) {
return output
}
return (
<>
<AlignButtonsControl
label={ __( 'Caption Alignment', i18n ) }
attribute="figcaptionAlignment"
/>
</>
)
} )