PluginProbe ʕ •ᴥ•ʔ
VK Blocks / 1.126.2
VK Blocks v1.126.2
1.126.4 1.126.3 1.126.1 1.126.2 1.126.0 1.125.0 1.124.0 1.123.0 1.122.0 1.121.0 1.120.0 1.119.2 1.119.1 1.119.0 1.118.7 1.82.0.0 1.82.0.1 1.83.0.0 1.83.0.1 1.84.0.0 1.84.0.1 1.85.0.2 1.85.0.3 1.85.1.0 1.85.1.1 1.86.0.0 1.86.0.1 1.86.1.0 1.87.0.0 1.87.0.1 1.88.0.1 1.88.0.2 1.89.0.0 1.9.2 1.90.0.0 1.90.0.1 1.90.1.1 1.91.0.0 1.91.1.1 1.92.0.0 1.92.0.1 1.92.1.0 1.92.1.1 1.93.0.0 trunk 1.93.0.1 0.1.1 1.93.1.0 0.10.3 1.93.1.1 0.11.0 1.94.0.0 0.12.6 1.94.0.1 0.15.1 1.94.1.0 0.16.2 1.94.2.1 0.17.6 1.94.2.2 0.2.2 1.95.0.3 0.22.4 1.95.0.4 0.26.7 1.96.2.0 0.3.2 1.96.2.1 0.31.0 1.97.0.1 0.35.5 1.97.0.2 0.37.5 1.99.0.0 0.38.8 1.99.0.1 0.39.4 0.4.7 0.41.0 0.42.0 0.44.13 0.45.2 0.46.1 0.47.0 0.48.0 0.49.8 0.5.2 0.50.3 0.51.0 0.52.2 0.53.2 0.54.0 0.55.0 0.56.2 0.56.3 0.57.6 0.58.10 0.59.0 0.6.0 0.60.1 0.61.2 0.7.1 0.8.2 1.0.16 1.10.0 1.100.0.0 1.100.0.1 1.102.0.0 1.102.0.1 1.103.0.0 1.104.0.0 1.104.0.1 1.105.1.0 1.105.1.1 1.106.0.0 1.106.0.1 1.107.0.0 1.107.0.1 1.107.0.2 1.108.0.0 1.108.0.1 1.109.0.0 1.109.0.1 1.11.4 1.110.0.0 1.110.0.1 1.111.0.0 1.111.0.1 1.111.0.2 1.112.0.0 1.112.0.1 1.113.0.0 1.113.0.1 1.114.0.0 1.114.0.1 1.114.2.0 1.114.2.1 1.115.0.0 1.115.0.1 1.115.1.0 1.115.1.1 1.115.2.0 1.115.2.1 1.116.0.0 1.116.0.1 1.116.1.0 1.116.1.1 1.116.2.0 1.117.0.0 1.117.0.1 1.117.1.0 1.118.2 1.118.5 1.12.0 1.13.2 1.14.1 1.15.1 1.16.11 1.17.0 1.18.6 1.19.0 1.19.1 1.2.3 1.20.7 1.21.0 1.22.4 1.23.0 1.24.5 1.25.1 1.26.2 1.27.7.2 1.28.0.1 1.29.2.0 1.3.9 1.30.0.1 1.31.0.1 1.32.0.2 1.33.2.1 1.36.1.5 1.37.0.0 1.39.2.1 1.4.6 1.40.0.1 1.40.1.0 1.40.1.1 1.41.0.0 1.41.0.1 1.41.2.2 1.41.2.3 1.43.0.0 1.43.0.1 1.43.0.2 1.44.0.0 1.44.0.1 1.45.0.0 1.45.0.1 1.46.0.0 1.46.0.1 1.47.0.0 1.47.0.1 1.47.1.0 1.48.0.0 1.48.0.1 1.48.0.2 1.48.1.0 1.48.1.1 1.5.0 1.50.0.0 1.50.0.1 1.51.0.0 1.51.0.1 1.52.0.0 1.52.0.1 1.53.0.0 1.53.0.1 1.54.0.0 1.54.0.1 1.55.0.0 1.55.0.1 1.56.0.0 1.56.0.1 1.57.0.0 1.57.0.2 1.57.0.3 1.57.0.4 1.57.0.5 1.57.1.0 1.57.1.1 1.57.1.2 1.58.0.0 1.58.0.1 1.59.0.0 1.59.0.1 1.6.0 1.60.0.0 1.60.0.1 1.63.0.0 1.63.0.1 1.64.0.0 1.64.0.1 1.64.1.0 1.64.1.2 1.67.0.0 1.67.0.1 1.68.0.0 1.68.0.1 1.69.0.0 1.69.0.1 1.69.1.1 1.69.1.2 1.7.1 1.70.0.0 1.70.0.1 1.71.0.0 1.71.0.1 1.72.0.0 1.72.1.0 1.72.1.1 1.73.0.0 1.73.0.1 1.74.0.0 1.74.0.1 1.75.0.0 1.75.1.0 1.75.1.1 1.76.0.0 1.76.0.1 1.76.1.0 1.76.1.1 1.76.2.0 1.76.2.1 1.77.0.0 1.77.0.1 1.78.0.0 1.78.0.1 1.79.0.0 1.79.0.1 1.79.0.2 1.79.0.3 1.79.1.0 1.79.1.1 1.8.2 1.80.1.0 1.80.1.1 1.80.1.2 1.81.0.1 1.81.0.2
vk-blocks / src / blocks / slider-item / edit.js
vk-blocks / src / blocks / slider-item Last commit date
deprecated 4 months ago GenerateBgImage.js 4 months ago block.json 3 months ago edit.js 2 weeks ago icon.svg 4 months ago index.js 4 months ago index.php 4 months ago save.js 4 months ago style.scss 1 week ago
edit.js
303 lines
1 /**
2 * External dependencies
3 */
4 import classnames from 'classnames';
5
6 /* eslint camelcase: 0 */
7 import { __ } from '@wordpress/i18n';
8 import { useEffect } from '@wordpress/element';
9 import {
10 InspectorControls,
11 BlockControls,
12 BlockVerticalAlignmentToolbar,
13 InnerBlocks,
14 useBlockProps,
15 } from '@wordpress/block-editor';
16 import {
17 RangeControl,
18 RadioControl,
19 PanelBody,
20 BaseControl,
21 ToolbarGroup,
22 ToggleControl,
23 } from '@wordpress/components';
24 import { AdvancedMediaUpload } from '@vkblocks/components/advanced-media-upload';
25 import BackgroundImageToolbar from '@vkblocks/components/background-image-toolbar';
26 import GenerateBgImage from './GenerateBgImage';
27 import { isHexColor } from '@vkblocks/utils/is-hex-color';
28 import { AdvancedColorPalette } from '@vkblocks/components/advanced-color-palette';
29 import {
30 isParentReusableBlock,
31 hasBlockIdCollision,
32 shouldUpdateBlockId,
33 } from '@vkblocks/utils/is-parent-reusable-block';
34 import LinkToolbar from '@vkblocks/components/link-toolbar';
35 import { sanitizeSlug } from '@vkblocks/utils/sanitizeSlug';
36 import { toPresetSpacingVar } from '@vkblocks/utils/to-preset-spacing-var';
37
38 const prefix = 'vk_slider_item';
39
40 export default function SliderItemEdit(props) {
41 const { attributes, setAttributes, clientId } = props;
42 const {
43 verticalAlignment,
44 bgColor,
45 opacity,
46 bgSize,
47 bgImageMobile,
48 bgImageTablet,
49 bgImage,
50 linkUrl,
51 linkTarget,
52 relAttribute,
53 linkDescription,
54 contentWidth,
55 blockId,
56 } = attributes;
57
58 useEffect(() => {
59 if (attributes.clientId !== undefined) {
60 setAttributes({ clientId: undefined });
61 }
62 // issue #2556: blockId を毎リロードで上書きすると dirty 化するため、
63 // 「未確定」または「再利用ブロック外での実衝突(複製)」のときだけ再採番する。
64 if (
65 shouldUpdateBlockId({
66 blockId,
67 isInReusableBlock: isParentReusableBlock(clientId),
68 hasCollision: hasBlockIdCollision(clientId, blockId),
69 })
70 ) {
71 setAttributes({ blockId: clientId });
72 }
73 }, [clientId]);
74
75 const spacingPaddingLeft = attributes?.style?.spacing?.padding?.left;
76 const spacingPaddingRight = attributes?.style?.spacing?.padding?.right;
77 const spacingPaddingLeftVar = toPresetSpacingVar(spacingPaddingLeft);
78 const spacingPaddingRightVar = toPresetSpacingVar(spacingPaddingRight);
79
80 let classPaddingLR = '';
81 if (contentWidth) {
82 classPaddingLR += `is-layout-constrained`;
83 }
84 if (!spacingPaddingLeft && !spacingPaddingRight) {
85 classPaddingLR += ` ${prefix}-paddingLR-use`;
86 }
87
88 let containerClass = '';
89 if (contentWidth) {
90 containerClass = `${prefix}_container container`;
91 } else {
92 containerClass = `${prefix}_container`;
93 }
94
95 const opacityClass = opacity && opacity * 10;
96 const bgAreaClasses = classnames('vk_slider_item-background-area', {
97 [`has-background`]: bgColor !== undefined,
98 [`has-${sanitizeSlug(bgColor)}-background-color`]:
99 bgColor !== undefined && !isHexColor(bgColor),
100 [`has-background-dim`]: opacity !== undefined,
101 [`has-background-dim-${opacityClass}`]: opacityClass !== undefined,
102 });
103
104 const bgAreaStyles = {
105 backgroundColor: isHexColor(bgColor) ? bgColor : undefined,
106 paddingLeft: spacingPaddingLeftVar,
107 paddingRight: spacingPaddingRightVar,
108 };
109
110 const GetBgImage = (
111 <>
112 {(bgImage || bgImageTablet || bgImageMobile) && (
113 <GenerateBgImage prefix={prefix} blockId={blockId} {...props} />
114 )}
115 <div className={bgAreaClasses} style={bgAreaStyles}></div>
116 </>
117 );
118
119 const blockProps = useBlockProps({
120 className: `vk_slider_item vk_valign-${verticalAlignment} ${prefix}-${blockId} ${classPaddingLR} ${prefix}-paddingVertical-none swiper-slide`,
121 style: {
122 paddingLeft: spacingPaddingLeftVar,
123 paddingRight: spacingPaddingRightVar,
124 },
125 });
126
127 return (
128 <>
129 <BlockControls>
130 <BlockVerticalAlignmentToolbar
131 onChange={(alignment) =>
132 setAttributes({ verticalAlignment: alignment })
133 }
134 value={verticalAlignment}
135 />
136 <BackgroundImageToolbar
137 sidebarClass={'vk_slider_item_sidebar_bgImage'}
138 {...props}
139 />
140 <ToolbarGroup>
141 <LinkToolbar
142 linkUrl={linkUrl}
143 setLinkUrl={(url) => setAttributes({ linkUrl: url })}
144 linkTarget={linkTarget}
145 setLinkTarget={(target) =>
146 setAttributes({ linkTarget: target })
147 }
148 relAttribute={relAttribute}
149 setRelAttribute={(rel) =>
150 setAttributes({ relAttribute: rel })
151 }
152 linkDescription={linkDescription}
153 setLinkDescription={(description) =>
154 setAttributes({ linkDescription: description })
155 }
156 />
157 </ToolbarGroup>
158 </BlockControls>
159 <InspectorControls>
160 <PanelBody
161 title={__('Layout Setting', 'vk-blocks')}
162 initialOpen={true}
163 >
164 <BaseControl
165 label={__('Vertical align', 'vk-blocks')}
166 id={`vk_sliderItem-verticalAlign`}
167 >
168 <BlockVerticalAlignmentToolbar
169 onChange={(alignment) =>
170 setAttributes({
171 verticalAlignment: alignment,
172 })
173 }
174 value={verticalAlignment}
175 />
176 </BaseControl>
177 <BaseControl
178 label={__('Content Area Width', 'vk-blocks')}
179 id={`vk_slider-effect`}
180 >
181 <ToggleControl
182 label={__(
183 'Use content width for inner blocks.',
184 'vk-blocks'
185 )}
186 checked={contentWidth}
187 onChange={(checked) =>
188 setAttributes({ contentWidth: checked })
189 }
190 help={__(
191 'Nested blocks should inherit the content width.',
192 'vk-blocks'
193 )}
194 />
195 </BaseControl>
196 </PanelBody>
197 <PanelBody
198 title={__('Background Setting', 'vk-blocks')}
199 initialOpen={false}
200 >
201 <BaseControl
202 label={__('Color Setting', 'vk-blocks')}
203 id={`vk_sliderItem-colorSetting`}
204 help={__(
205 'The color will cover the background image. To display the image, set the opacity to 0.',
206 'vk-blocks'
207 )}
208 >
209 <AdvancedColorPalette
210 enableAlpha={false}
211 schema={'bgColor'}
212 {...props}
213 />
214 </BaseControl>
215 <BaseControl
216 label={__('Opacity Setting', 'vk-blocks')}
217 id={`vk_sliderItem-opacitySetting`}
218 >
219 <RangeControl
220 value={opacity}
221 onChange={(value) => {
222 setAttributes({ opacity: value });
223 }}
224 min={0}
225 max={1}
226 step={0.1}
227 />
228 </BaseControl>
229 <BaseControl
230 label={__('Background Image Size', 'vk-blocks')}
231 id={`vk_sliderItem-backgroundImageSize`}
232 >
233 <RadioControl
234 selected={bgSize}
235 options={[
236 {
237 label: __('cover', 'vk-blocks'),
238 value: 'cover',
239 },
240 {
241 label: __('repeat', 'vk-blocks'),
242 value: 'repeat',
243 },
244 ]}
245 onChange={(value) =>
246 setAttributes({ bgSize: value })
247 }
248 />
249 </BaseControl>
250 <BaseControl
251 label={__('Background Image PC', 'vk-blocks')}
252 id={`vk_sliderItem-backgroundImagePC`}
253 className={'vk_slider_item_sidebar_bgImage'}
254 >
255 <div
256 className={
257 'vk_slider_item_sidebar_bgImage_button_container'
258 }
259 >
260 <AdvancedMediaUpload
261 schema={'bgImage'}
262 schemaId={'bgImageId'}
263 {...props}
264 />
265 </div>
266 </BaseControl>
267 <BaseControl
268 label={__('Background Image Tablet', 'vk-blocks')}
269 className={'vk_slider_item_sidebar_bgImage'}
270 id={`vk_sliderItem-backgroundImageTablet`}
271 >
272 <AdvancedMediaUpload
273 schema={'bgImageTablet'}
274 schemaId={'bgImageTabletId'}
275 {...props}
276 />
277 </BaseControl>
278 <BaseControl
279 label={__('Background Image Mobile', 'vk-blocks')}
280 className={'vk_slider_item_sidebar_bgImage'}
281 id={`vk_sliderItem-backgroundImageMobile`}
282 >
283 <AdvancedMediaUpload
284 schema={'bgImageMobile'}
285 schemaId={'bgImageMobileId'}
286 {...props}
287 />
288 </BaseControl>
289 </PanelBody>
290 </InspectorControls>
291 <div {...blockProps}>
292 {GetBgImage}
293 <div className={containerClass}>
294 <InnerBlocks
295 templateLock={false}
296 template={[['core/paragraph']]}
297 />
298 </div>
299 </div>
300 </>
301 );
302 }
303