PluginProbe ʕ •ᴥ•ʔ
VK Blocks / trunk
VK Blocks vtrunk
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 / pr-blocks / edit.js
vk-blocks / src / blocks / pr-blocks Last commit date
deprecated 2 months ago block.json 1 month ago edit.js 2 months ago icon.svg 2 months ago index.js 2 months ago index.php 2 months ago save.js 2 months ago style.scss 2 months ago
edit.js
565 lines
1 import { isNotJSON } from '@vkblocks/utils/is-not-json';
2 import { FontAwesome } from '@vkblocks/utils/font-awesome-new';
3 import { fixBrokenUnicode } from '@vkblocks/utils/fixBrokenUnicode';
4 import { iconLabel } from '@vkblocks/utils/icon-label';
5 import { __ } from '@wordpress/i18n';
6 import {
7 RadioControl,
8 PanelBody,
9 Button,
10 BaseControl,
11 CheckboxControl,
12 TextControl,
13 } from '@wordpress/components';
14 import { Component, useEffect } from '@wordpress/element';
15 import {
16 InspectorControls,
17 MediaUpload,
18 RichText,
19 useBlockProps,
20 } from '@wordpress/block-editor';
21
22 import parse from 'html-react-parser';
23 import { isHexColor } from '@vkblocks/utils/is-hex-color';
24 import { AdvancedColorPalette } from '@vkblocks/components/advanced-color-palette';
25 import { sanitizeSlug } from '@vkblocks/utils/sanitizeSlug';
26
27 export default function PrBlocksEdit(props) {
28 const { attributes, setAttributes } = props;
29
30 useEffect(() => {
31 const { icon1, icon2, icon3 } = attributes;
32 const fixes = {};
33 [
34 ['icon1', icon1],
35 ['icon2', icon2],
36 ['icon3', icon3],
37 ].forEach(([key, val]) => {
38 if (val) {
39 const fixed = fixBrokenUnicode(val);
40 if (fixed !== val) {
41 fixes[key] = fixed;
42 }
43 }
44 });
45 if (Object.keys(fixes).length > 0) {
46 setAttributes(fixes);
47 }
48 }, [attributes.icon1, attributes.icon2, attributes.icon3]);
49
50 const {
51 url1,
52 url2,
53 url3,
54 urlOpenType1,
55 urlOpenType2,
56 urlOpenType3,
57 bgType1,
58 bgType2,
59 bgType3,
60 insertImage1,
61 insertImage2,
62 insertImage3,
63 } = attributes;
64
65 const containerClass = `vk_prBlocks row`;
66
67 const blockProps = useBlockProps({
68 className: containerClass,
69 });
70
71 const uploadNonAltImage1 = (insertImage) => {
72 if (isNotJSON(insertImage)) {
73 setAttributes({ insertImage1: insertImage.url });
74 } else {
75 setAttributes({ insertImage1: JSON.stringify(insertImage) });
76 }
77 };
78
79 const uploadNonAltImage2 = (insertImage) => {
80 if (isNotJSON(insertImage)) {
81 setAttributes({ insertImage2: insertImage.url });
82 } else {
83 setAttributes({ insertImage2: JSON.stringify(insertImage) });
84 }
85 };
86
87 const uploadNonAltImage3 = (insertImage) => {
88 if (isNotJSON(insertImage)) {
89 setAttributes({ insertImage3: insertImage.url });
90 } else {
91 setAttributes({ insertImage3: JSON.stringify(insertImage) });
92 }
93 };
94
95 const renderEditAltImage = (insertImage) => {
96 if (isNotJSON(insertImage)) {
97 return !insertImage ? (
98 __('Select image', 'vk-blocks')
99 ) : (
100 <img
101 className={'icon-image'}
102 src={insertImage}
103 alt={__('Upload image', 'vk-blocks')}
104 />
105 );
106 }
107 const IconImageParse = JSON.parse(fixBrokenUnicode(insertImage));
108 return !insertImage ? (
109 __('Select image', 'vk-blocks')
110 ) : (
111 <img
112 className={'icon-image'}
113 src={IconImageParse.sizes.full.url}
114 alt={IconImageParse.alt}
115 />
116 );
117 };
118
119 return (
120 <>
121 <InspectorControls>
122 <PanelBody title={__('PR Block1 Setting', 'vk-blocks')}>
123 <BaseControl
124 label={__('Link URL:', 'vk-blocks')}
125 id={`vk_prBlocks_linkUrl1`}
126 >
127 <TextControl
128 value={url1}
129 onChange={(value) => setAttributes({ url1: value })}
130 />
131 <CheckboxControl
132 label={__('Open link new tab', 'vk-blocks')}
133 checked={urlOpenType1}
134 onChange={(checked) =>
135 setAttributes({ urlOpenType1: checked })
136 }
137 />
138 </BaseControl>
139 <BaseControl
140 label={iconLabel(__('Icon 1', 'vk-blocks'))}
141 id={`vk_prBlocks_Icon1`}
142 >
143 <FontAwesome attributeName={'icon1'} {...props} />
144 <AdvancedColorPalette schema={'color1'} {...props} />
145 <RadioControl
146 label={__('Icon Background:', 'vk-blocks')}
147 selected={bgType1}
148 options={[
149 {
150 label: __('Solid color', 'vk-blocks'),
151 value: '0',
152 },
153 {
154 label: __('No background', 'vk-blocks'),
155 value: '1',
156 },
157 ]}
158 onChange={(value) =>
159 setAttributes({ bgType1: value })
160 }
161 />
162 </BaseControl>
163 <BaseControl
164 // label={ __( 'PR Image 1', 'vk-blocks' ) }
165 help={__(
166 'When you have an image. Image is displayed with priority',
167 'vk-blocks'
168 )}
169 >
170 <h4 className="components-base-control__title">
171 {__('PR Image 1', 'vk-blocks')}
172 </h4>
173 <MediaUpload
174 onSelect={uploadNonAltImage1}
175 type="image"
176 value={insertImage1}
177 render={({ open }) => (
178 <Button
179 onClick={open}
180 className={
181 insertImage1
182 ? 'image-button'
183 : 'button button-large'
184 }
185 >
186 {renderEditAltImage(insertImage1)}
187 </Button>
188 )}
189 />
190 </BaseControl>
191 </PanelBody>
192 <PanelBody title={__('PR Block2 Setting', 'vk-blocks')}>
193 <BaseControl
194 label={__('Link URL:', 'vk-blocks')}
195 id={`vk_prBlocks_linkUrl2`}
196 >
197 <TextControl
198 value={url2}
199 onChange={(value) => setAttributes({ url2: value })}
200 />
201 <CheckboxControl
202 label={__('Open link new tab', 'vk-blocks')}
203 checked={urlOpenType2}
204 onChange={(checked) =>
205 setAttributes({ urlOpenType2: checked })
206 }
207 />
208 </BaseControl>
209 <BaseControl
210 label={iconLabel(__('Icon 2', 'vk-blocks'))}
211 id={`vk_prBlocks_Icon2`}
212 >
213 <FontAwesome attributeName={'icon2'} {...props} />
214 <AdvancedColorPalette schema={'color2'} {...props} />
215 <RadioControl
216 label={__('Icon Background:', 'vk-blocks')}
217 selected={bgType2}
218 options={[
219 {
220 label: __('Solid color', 'vk-blocks'),
221 value: '0',
222 },
223 {
224 label: __('No background', 'vk-blocks'),
225 value: '1',
226 },
227 ]}
228 onChange={(value) =>
229 setAttributes({ bgType2: value })
230 }
231 />
232 </BaseControl>
233 <BaseControl
234 // label={ __( 'PR Image 2', 'vk-blocks' ) }
235 help={__(
236 'When you have an image. Image is displayed with priority.',
237 'vk-blocks'
238 )}
239 >
240 <h4 className="components-base-control__title">
241 {__('PR Image 2', 'vk-blocks')}
242 </h4>
243 <MediaUpload
244 onSelect={uploadNonAltImage2}
245 type="image"
246 value={insertImage2}
247 render={({ open }) => (
248 <Button
249 onClick={open}
250 className={
251 insertImage2
252 ? 'image-button'
253 : 'button button-large'
254 }
255 >
256 {renderEditAltImage(insertImage2)}
257 </Button>
258 )}
259 />
260 </BaseControl>
261 </PanelBody>
262 <PanelBody title={__('PR Block3 Setting', 'vk-blocks')}>
263 <BaseControl
264 label={__('Link URL:', 'vk-blocks')}
265 id={`vk_prBlocks_linkUrl3`}
266 >
267 <TextControl
268 value={url3}
269 onChange={(value) => setAttributes({ url3: value })}
270 />
271 <CheckboxControl
272 label={__('Open link new tab', 'vk-blocks')}
273 checked={urlOpenType3}
274 onChange={(checked) =>
275 setAttributes({ urlOpenType3: checked })
276 }
277 />
278 </BaseControl>
279 <BaseControl
280 label={iconLabel(__('Icon 3', 'vk-blocks'))}
281 id={`vk_prBlocks_Icon3`}
282 >
283 <FontAwesome attributeName={'icon3'} {...props} />
284 <AdvancedColorPalette schema={'color3'} {...props} />
285 <RadioControl
286 label={__('Icon Background:', 'vk-blocks')}
287 selected={bgType3}
288 options={[
289 {
290 label: __('Solid color', 'vk-blocks'),
291 value: '0',
292 },
293 {
294 label: __('No background', 'vk-blocks'),
295 value: '1',
296 },
297 ]}
298 onChange={(value) =>
299 setAttributes({ bgType3: value })
300 }
301 />
302 </BaseControl>
303 <BaseControl
304 // label={ __( 'PR Image 3', 'vk-blocks' ) }
305 help={__(
306 'When you have an image. Image is displayed with priority.',
307 'vk-blocks'
308 )}
309 >
310 <h4 className="components-base-control__title">
311 {__('PR Image 3', 'vk-blocks')}
312 </h4>
313 <MediaUpload
314 onSelect={uploadNonAltImage3}
315 type="image"
316 value={insertImage3}
317 render={({ open }) => (
318 <Button
319 onClick={open}
320 className={
321 insertImage3
322 ? 'image-button'
323 : 'button button-large'
324 }
325 >
326 {renderEditAltImage(insertImage3)}
327 </Button>
328 )}
329 />
330 </BaseControl>
331 </PanelBody>
332 </InspectorControls>
333 <div {...blockProps}>
334 <ComponentBlockEdit
335 attributes={attributes}
336 setAttributes={setAttributes}
337 blockNum={1}
338 />
339 <ComponentBlockEdit
340 attributes={attributes}
341 setAttributes={setAttributes}
342 blockNum={2}
343 />
344 <ComponentBlockEdit
345 attributes={attributes}
346 setAttributes={setAttributes}
347 blockNum={3}
348 />
349 </div>
350 </>
351 );
352 }
353
354 export class ComponentBlockEdit extends Component {
355 render() {
356 const setAttributes = this.props.setAttributes;
357 const {
358 heading1,
359 heading2,
360 heading3,
361 content1,
362 content2,
363 content3,
364 icon1,
365 icon2,
366 icon3,
367 color1,
368 color2,
369 color3,
370 bgType1,
371 bgType2,
372 bgType3,
373 insertImage1,
374 insertImage2,
375 insertImage3,
376 } = this.props.attributes;
377 const blockNum = this.props.blockNum;
378 const blockNumArrIndex = this.props.blockNum - 1;
379
380 const icon = [icon1, icon2, icon3];
381 const color = [color1, color2, color3];
382 const bgType = [bgType1, bgType2, bgType3];
383 const insertImage = [insertImage1, insertImage2, insertImage3];
384
385 let richTextH1Save = '';
386 let richTextPSave = '';
387
388 const renderSaveAltImage = (Image) => {
389 if (isNotJSON(Image)) {
390 return <img src={Image} alt="" />;
391 }
392 const IconImageParse = JSON.parse(fixBrokenUnicode(Image));
393 return (
394 <img
395 src={IconImageParse.sizes.full.url}
396 alt={IconImageParse.alt}
397 />
398 );
399 };
400
401 const renderItemImage = (Image) => {
402 const bgImage = Image[blockNumArrIndex];
403 if (isNotJSON(bgImage)) {
404 return {
405 backgroundImage: `url(${bgImage})`,
406 backgroundRepeat: 'no-repeat 50% center',
407 backgroundSize: 'cover',
408 };
409 }
410 const bgImageParse = JSON.parse(fixBrokenUnicode(bgImage));
411 return {
412 backgroundImage: `url(${bgImageParse.sizes.full.url})`,
413 backgroundRepeat: 'no-repeat 50% center',
414 backgroundSize: 'cover',
415 };
416 };
417
418 const drawElement = (() => {
419 if (insertImage[blockNumArrIndex]) {
420 return (
421 <div
422 className="vk_prBlocks_item_image"
423 style={renderItemImage(insertImage)}
424 >
425 {renderSaveAltImage(insertImage[blockNumArrIndex])}
426 </div>
427 );
428 }
429
430 let iconOuterClass = '';
431 let iconOuterInlineStyle = {};
432 let iconColor = '';
433 if (color[blockNumArrIndex] !== undefined) {
434 // アイコン背景:ベタ塗り
435 if (bgType[blockNumArrIndex] === '0') {
436 //カスタムカラーの時
437 if (isHexColor(color[blockNumArrIndex])) {
438 iconOuterClass = `has-background `;
439 iconOuterInlineStyle = {
440 backgroundColor: `${color[blockNumArrIndex]}`,
441 };
442 //カラーパレットの時
443 } else {
444 iconOuterClass = `has-background has-${sanitizeSlug(color[blockNumArrIndex])}-background-color`;
445 }
446 // アイコン背景:背景なし
447 } else if (bgType[blockNumArrIndex] === '1') {
448 //カスタムカラーの時
449 if (isHexColor(color[blockNumArrIndex])) {
450 iconOuterClass = `has-text-color`;
451 iconOuterInlineStyle = {
452 border: `1px solid ${color[blockNumArrIndex]}`,
453 };
454 iconColor = color[blockNumArrIndex];
455 //カラーパレットの時
456 } else {
457 iconOuterClass = `has-text-color has-${sanitizeSlug(color[blockNumArrIndex])}-color`;
458 }
459 }
460 }
461
462 let faIcon = icon[blockNumArrIndex];
463 if (faIcon) {
464 faIcon = fixBrokenUnicode(faIcon);
465 }
466 //過去バージョンをリカバリーした時にiconを正常に表示する
467 if (faIcon && !faIcon.match(/<i/)) {
468 faIcon = `<i class="${faIcon}"></i>`;
469 }
470 //add class and inline css
471 const faIconFragment = faIcon.split(' ');
472 if (iconColor !== '') {
473 faIconFragment[0] =
474 faIconFragment[0] + ` style="color:${iconColor}" `;
475 } else {
476 faIconFragment[0] = faIconFragment[0] + ` `;
477 }
478 faIconFragment[1] = faIconFragment[1] + ` vk_prBlocks_item_icon `;
479 const faIconTag = faIconFragment.join('');
480
481 return (
482 <div
483 className={`vk_prBlocks_item_icon_outer ${iconOuterClass}`}
484 style={iconOuterInlineStyle}
485 >
486 {parse(faIconTag)}
487 </div>
488 );
489 })();
490
491 // アイコン背景:背景なし
492 let iconOutlineClass = '';
493 if (bgType[blockNumArrIndex] === '1') {
494 iconOutlineClass = 'is-style-outline';
495 }
496
497 if (blockNum === 1) {
498 richTextH1Save = (
499 <RichText
500 className="vk_prBlocks_item_title vk_prBlocks_item_title-1"
501 tagName={'h3'}
502 onChange={(value) => setAttributes({ heading1: value })}
503 value={heading1}
504 placeholder={__('Input Title', 'vk-blocks')}
505 />
506 );
507 richTextPSave = (
508 <RichText
509 className="vk_prBlocks_item_summary vk_prBlocks_item_summary-1"
510 tagName={'p'}
511 onChange={(value) => setAttributes({ content1: value })}
512 value={content1}
513 placeholder={__('Input Content', 'vk-blocks')}
514 />
515 );
516 } else if (blockNum === 2) {
517 richTextH1Save = (
518 <RichText
519 className="vk_prBlocks_item_title vk_prBlocks_item_title-2"
520 tagName={'h3'}
521 onChange={(value) => setAttributes({ heading2: value })}
522 value={heading2}
523 placeholder={__('Input Title', 'vk-blocks')}
524 />
525 );
526 richTextPSave = (
527 <RichText
528 className="vk_prBlocks_item_summary vk_prBlocks_item_summary-2"
529 tagName={'p'}
530 onChange={(value) => setAttributes({ content2: value })}
531 value={content2}
532 placeholder={__('Input Content', 'vk-blocks')}
533 />
534 );
535 } else if (blockNum === 3) {
536 richTextH1Save = (
537 <RichText
538 className="vk_prBlocks_item_title vk_prBlocks_item_title-3"
539 tagName={'h3'}
540 onChange={(value) => setAttributes({ heading3: value })}
541 value={heading3}
542 placeholder={__('Input Title', 'vk-blocks')}
543 />
544 );
545 richTextPSave = (
546 <RichText
547 className="vk_prBlocks_item_summary vk_prBlocks_item_summary-3"
548 tagName={'p'}
549 onChange={(value) => setAttributes({ content3: value })}
550 value={content3}
551 placeholder={__('Input Content', 'vk-blocks')}
552 />
553 );
554 }
555
556 return (
557 <div className={`vk_prBlocks_item col-sm-4 ${iconOutlineClass}`}>
558 {drawElement}
559 {richTextH1Save}
560 {richTextPSave}
561 </div>
562 );
563 }
564 }
565