deprecated
2 weeks ago
_swiper._scss
2 months ago
block.json
2 weeks ago
edit-multiItem.js
2 weeks ago
edit-slider.js
2 weeks ago
edit.js
2 days ago
icon.svg
2 months ago
index.js
2 months ago
index.php
2 months ago
loop-min-slides.js
2 months ago
pause-button.js
2 days ago
save.js
2 days ago
style.scss
2 months ago
view.js
2 days ago
edit.js
834 lines
| 1 | import { AdvancedToggleControl } from '@vkblocks/components/advanced-toggle-control'; |
| 2 | import { __ } from '@wordpress/i18n'; |
| 3 | import { useEffect, useRef } from '@wordpress/element'; |
| 4 | import { |
| 5 | InspectorControls, |
| 6 | BlockControls, |
| 7 | BlockAlignmentToolbar, |
| 8 | InnerBlocks, |
| 9 | useBlockProps, |
| 10 | } from '@wordpress/block-editor'; |
| 11 | import { |
| 12 | PanelBody, |
| 13 | BaseControl, |
| 14 | TextControl, |
| 15 | __experimentalToggleGroupControl as ToggleGroupControl, |
| 16 | __experimentalToggleGroupControlOption as ToggleGroupControlOption, |
| 17 | SelectControl, |
| 18 | ToolbarGroup, |
| 19 | ToolbarDropdownMenu, |
| 20 | Dashicon, |
| 21 | ToggleControl, |
| 22 | RangeControl, |
| 23 | } from '@wordpress/components'; |
| 24 | import { |
| 25 | isParentReusableBlock, |
| 26 | hasBlockIdCollision, |
| 27 | shouldUpdateBlockId, |
| 28 | } from '@vkblocks/utils/is-parent-reusable-block'; |
| 29 | import { editSliderLaunch } from './edit-slider'; |
| 30 | import { MultiItemSetting } from './edit-multiItem'; |
| 31 | import { PauseButton } from './pause-button'; |
| 32 | import ResponsiveSizeControl, { |
| 33 | getMaxByUnit, |
| 34 | } from '@vkblocks/components/responsive-size-control'; |
| 35 | import { useSelect } from '@wordpress/data'; |
| 36 | |
| 37 | // eslint-disable no-shadow |
| 38 | export default function SliderEdit(props) { |
| 39 | const { attributes, setAttributes, clientId } = props; |
| 40 | const { |
| 41 | editorMode, |
| 42 | pc, |
| 43 | tablet, |
| 44 | mobile, |
| 45 | autoPlay, |
| 46 | autoPlayStop, |
| 47 | autoPlayDelay, |
| 48 | pauseButton, |
| 49 | pagination, |
| 50 | width, |
| 51 | loop, |
| 52 | effect, |
| 53 | speed, |
| 54 | slidesPerView, |
| 55 | slidesPerViewMobile, |
| 56 | slidesPerViewTablet, |
| 57 | slidesPerViewPC, |
| 58 | slidesPerGroup, |
| 59 | centeredSlides, |
| 60 | navigationPosition, |
| 61 | direction, |
| 62 | unit, |
| 63 | zoomAnimation, |
| 64 | zoomInitialScale, |
| 65 | zoomFinalScale, |
| 66 | blockId, |
| 67 | } = attributes; |
| 68 | |
| 69 | // インナーブロックを取得 |
| 70 | const innerBlocks = useSelect((select) => |
| 71 | select('core/block-editor').getBlocks(clientId) |
| 72 | ); |
| 73 | |
| 74 | // editorMode と innerBlocks の順序をログ出力 |
| 75 | useEffect(() => { |
| 76 | // 編集モード(default)に戻す時に DOM 要素を正しい順序に復� |
| 77 | � |
| 78 | if (editorMode === 'default') { |
| 79 | const sliderElement = blockRef.current; |
| 80 | |
| 81 | if (sliderElement) { |
| 82 | const wrapper = sliderElement.querySelector( |
| 83 | '.block-editor-block-list__layout' |
| 84 | ); |
| 85 | |
| 86 | if (wrapper && innerBlocks && innerBlocks.length > 0) { |
| 87 | // 現在の DOM 順序を取得 |
| 88 | const currentOrder = Array.from( |
| 89 | wrapper.querySelectorAll('.vk_slider_item') |
| 90 | ) |
| 91 | .map((el) => { |
| 92 | const classMatch = el.className.match( |
| 93 | /vk_slider_item-([a-f0-9\-]+)/ |
| 94 | ); |
| 95 | return classMatch ? classMatch[1] : null; |
| 96 | }) |
| 97 | .filter((id) => id !== null); |
| 98 | |
| 99 | // 期� |
| 100 | される順序 |
| 101 | const expectedOrder = innerBlocks.map( |
| 102 | (b) => b.attributes.blockId || b.clientId |
| 103 | ); |
| 104 | |
| 105 | // 順序が同じなら何もしない(不要な DOM 操作を避ける) |
| 106 | if ( |
| 107 | JSON.stringify(currentOrder) === |
| 108 | JSON.stringify(expectedOrder) |
| 109 | ) { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | // 順序が異なる場合のみ並べ替え |
| 114 | // innerBlocks の順序に従って slider-item を並べ替え |
| 115 | let previousElement = null; |
| 116 | innerBlocks.forEach((block) => { |
| 117 | const blockIdToUse = |
| 118 | block.attributes.blockId || block.clientId; |
| 119 | const element = wrapper.querySelector( |
| 120 | `.vk_slider_item-${blockIdToUse}` |
| 121 | ); |
| 122 | if (!element) { |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | if (previousElement) { |
| 127 | // 前の要素の次に挿� |
| 128 | � |
| 129 | if (previousElement.nextSibling) { |
| 130 | wrapper.insertBefore( |
| 131 | element, |
| 132 | previousElement.nextSibling |
| 133 | ); |
| 134 | } else { |
| 135 | wrapper.appendChild(element); |
| 136 | } |
| 137 | } else if (element !== wrapper.firstChild) { |
| 138 | // 最初の要素が� |
| 139 | �頭にない場合のみ移動 |
| 140 | wrapper.insertBefore(element, wrapper.firstChild); |
| 141 | } |
| 142 | |
| 143 | previousElement = element; |
| 144 | }); |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | }, [editorMode, innerBlocks, clientId]); |
| 149 | |
| 150 | // プレビューモードに戻す時に、Swiper インスタンスをリセットして確実に再初期化 |
| 151 | useEffect(() => { |
| 152 | if (editorMode === 'slide') { |
| 153 | // requestAnimationFrame で React のレンダリングが完了するのを� |
| 154 | ってから初期化 |
| 155 | let timerId; |
| 156 | const rafId = requestAnimationFrame(() => { |
| 157 | timerId = setTimeout(() => { |
| 158 | editSliderLaunch(); |
| 159 | }, 50); |
| 160 | }); |
| 161 | |
| 162 | return () => { |
| 163 | cancelAnimationFrame(rafId); |
| 164 | if (timerId) { |
| 165 | clearTimeout(timerId); |
| 166 | } |
| 167 | }; |
| 168 | } |
| 169 | }, [editorMode]); |
| 170 | |
| 171 | useEffect(() => { |
| 172 | // attributes の clientId は使わなくなったので削除 |
| 173 | if (attributes.clientId !== undefined) { |
| 174 | setAttributes({ clientId: undefined }); |
| 175 | } |
| 176 | |
| 177 | // issue #2556: blockId を毎リロードで上書きすると dirty 化するため、 |
| 178 | // 「未確定」または「再利用ブロック外での実衝突(複製)」のときだけ再採番する。 |
| 179 | if ( |
| 180 | shouldUpdateBlockId({ |
| 181 | blockId, |
| 182 | isInReusableBlock: isParentReusableBlock(clientId), |
| 183 | hasCollision: hasBlockIdCollision(clientId, blockId), |
| 184 | }) |
| 185 | ) { |
| 186 | setAttributes({ blockId: clientId }); |
| 187 | } |
| 188 | |
| 189 | // 1.49 以前では slidesPerViewMobile が定義されていないので互換設定を追加 |
| 190 | if (slidesPerViewMobile === undefined) { |
| 191 | setAttributes({ |
| 192 | slidesPerViewMobile: 1, |
| 193 | }); |
| 194 | } |
| 195 | |
| 196 | // 1.49 以前では slidesPerViewTablet が定義されていないので互換設定を追加 |
| 197 | if (slidesPerViewTablet === undefined) { |
| 198 | setAttributes({ |
| 199 | slidesPerViewTablet: 1, |
| 200 | }); |
| 201 | } |
| 202 | |
| 203 | // 1.49 以前では slidesPerViewPC が定義されていないので互換設定を追加 |
| 204 | if (slidesPerViewPC === undefined) { |
| 205 | if (slidesPerView !== undefined) { |
| 206 | setAttributes({ |
| 207 | slidesPerViewPC: slidesPerView, |
| 208 | }); |
| 209 | } else { |
| 210 | setAttributes({ |
| 211 | slidesPerViewPC: 1, |
| 212 | }); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // 1.49 以前では slidesPerView が定義されていないので互換設定を追加 |
| 217 | if (slidesPerView === undefined) { |
| 218 | setAttributes({ |
| 219 | slidesPerView: 1, |
| 220 | }); |
| 221 | } |
| 222 | |
| 223 | // @since 1.50 |
| 224 | // 1.49 までは slidesPerGroup は 数字での保存のみだったため、 |
| 225 | // 1 の場合は one-by-one に、 1 以外の数字指定だった場合は slides-per-view になるように |
| 226 | if ( |
| 227 | slidesPerGroup === undefined || |
| 228 | slidesPerGroup === null || |
| 229 | slidesPerGroup === '' || |
| 230 | slidesPerGroup === 1 || |
| 231 | slidesPerGroup === 'one-by-one' |
| 232 | ) { |
| 233 | setAttributes({ |
| 234 | slidesPerGroup: 'one-by-one', |
| 235 | }); |
| 236 | } else { |
| 237 | setAttributes({ |
| 238 | slidesPerGroup: 'slides-per-view', |
| 239 | }); |
| 240 | } |
| 241 | |
| 242 | // 1.51 以前では centeredSlides が定義されていないので互換設定を追加 |
| 243 | if (centeredSlides === undefined) { |
| 244 | setAttributes({ centeredSlides: false }); |
| 245 | } |
| 246 | |
| 247 | // 1.49 以前では pagination はブール型だったが文字列型になっための互換処理 |
| 248 | if (pagination === false) { |
| 249 | setAttributes({ pagination: 'hide' }); |
| 250 | } |
| 251 | if (pagination === true) { |
| 252 | setAttributes({ pagination: 'bullets' }); |
| 253 | } |
| 254 | |
| 255 | // 1.49 以前では autoPlayStop が定義されていないので互換設定を追加 |
| 256 | if (autoPlayStop === undefined) { |
| 257 | setAttributes({ autoPlayStop: false }); |
| 258 | } |
| 259 | |
| 260 | // pauseButton 追加前のブロックでは未定義なので互換設定を追加 |
| 261 | if (pauseButton === undefined) { |
| 262 | setAttributes({ pauseButton: false }); |
| 263 | } |
| 264 | |
| 265 | // 1.49 以前では navigationPosition が定義されていないので互換設定を追加 |
| 266 | if (navigationPosition === undefined) { |
| 267 | setAttributes({ navigationPosition: 'mobile-bottom' }); |
| 268 | } |
| 269 | |
| 270 | // 1.67 以前では editorMode が定義されていないので互換設定を追加 |
| 271 | if (editorMode === undefined) { |
| 272 | setAttributes({ editorMode: 'default' }); |
| 273 | } |
| 274 | |
| 275 | // ズームアニメーション設定の初期化 |
| 276 | if (zoomAnimation === undefined) { |
| 277 | setAttributes({ zoomAnimation: false }); |
| 278 | } |
| 279 | if (zoomInitialScale === undefined) { |
| 280 | setAttributes({ zoomInitialScale: 1 }); |
| 281 | } |
| 282 | if (zoomFinalScale === undefined) { |
| 283 | setAttributes({ zoomFinalScale: 1.25 }); |
| 284 | } |
| 285 | |
| 286 | // 1.68 以前では direction が定義されていないので互換設定を追加 |
| 287 | if (direction === undefined) { |
| 288 | setAttributes({ direction: 'rtl' }); |
| 289 | } |
| 290 | }, [clientId]); |
| 291 | |
| 292 | // 複数枚表示が設定されている場合に拡大機能を無効化 |
| 293 | useEffect(() => { |
| 294 | if ( |
| 295 | slidesPerViewPC > 1 || |
| 296 | slidesPerViewTablet > 1 || |
| 297 | slidesPerViewMobile > 1 |
| 298 | ) { |
| 299 | if (zoomAnimation) { |
| 300 | setAttributes({ zoomAnimation: false }); |
| 301 | } |
| 302 | } |
| 303 | }, [ |
| 304 | slidesPerViewPC, |
| 305 | slidesPerViewTablet, |
| 306 | slidesPerViewMobile, |
| 307 | zoomAnimation, |
| 308 | ]); |
| 309 | |
| 310 | // 拡大機能が有効になった場合に複数枚表示設定を1にリセット |
| 311 | useEffect(() => { |
| 312 | if (zoomAnimation) { |
| 313 | if (slidesPerViewPC > 1) { |
| 314 | setAttributes({ slidesPerViewPC: 1 }); |
| 315 | } |
| 316 | if (slidesPerViewTablet > 1) { |
| 317 | setAttributes({ slidesPerViewTablet: 1 }); |
| 318 | } |
| 319 | if (slidesPerViewMobile > 1) { |
| 320 | setAttributes({ slidesPerViewMobile: 1 }); |
| 321 | } |
| 322 | } |
| 323 | }, [ |
| 324 | zoomAnimation, |
| 325 | slidesPerViewPC, |
| 326 | slidesPerViewTablet, |
| 327 | slidesPerViewMobile, |
| 328 | ]); |
| 329 | |
| 330 | // 複数枚動かすときに sliderPerView が小数だと微妙なので対処 |
| 331 | useEffect(() => { |
| 332 | if (slidesPerGroup === 'slides-per-view') { |
| 333 | setAttributes({ |
| 334 | slidesPerViewPC: parseInt(Number(slidesPerViewPC), 10), |
| 335 | }); |
| 336 | setAttributes({ |
| 337 | slidesPerViewTablet: parseInt(Number(slidesPerViewTablet), 10), |
| 338 | }); |
| 339 | setAttributes({ |
| 340 | slidesPerViewMobile: parseInt(Number(slidesPerViewMobile), 10), |
| 341 | }); |
| 342 | } |
| 343 | }, [slidesPerGroup]); |
| 344 | |
| 345 | const containerClass = ' vk_grid-column'; |
| 346 | const ALLOWED_BLOCKS = ['vk-blocks/slider-item']; |
| 347 | const TEMPLATE = [['vk-blocks/slider-item']]; |
| 348 | |
| 349 | // � |
| 350 | のクラス名変更 |
| 351 | let alignClass = ''; |
| 352 | if ('full' === width) { |
| 353 | alignClass = ' alignfull'; |
| 354 | } else if ('wide' === width) { |
| 355 | alignClass = ' alignwide'; |
| 356 | } |
| 357 | |
| 358 | // JS に渡す値の構造体 |
| 359 | const sliderData = { |
| 360 | editorMode, |
| 361 | autoPlay, |
| 362 | autoPlayStop, |
| 363 | autoPlayDelay, |
| 364 | pauseButton, |
| 365 | pagination, |
| 366 | blockId, |
| 367 | width, |
| 368 | loop, |
| 369 | effect, |
| 370 | speed, |
| 371 | slidesPerViewMobile, |
| 372 | slidesPerViewTablet, |
| 373 | slidesPerViewPC, |
| 374 | slidesPerGroup, |
| 375 | centeredSlides, |
| 376 | zoomAnimation, |
| 377 | zoomInitialScale, |
| 378 | zoomFinalScale, |
| 379 | direction, |
| 380 | }; |
| 381 | |
| 382 | // ページネーションの HTML |
| 383 | let pagination_html = ''; |
| 384 | if (pagination !== 'hide') { |
| 385 | pagination_html = ( |
| 386 | <div |
| 387 | className={`swiper-pagination swiper-pagination-${pagination}`} |
| 388 | ></div> |
| 389 | ); |
| 390 | } |
| 391 | |
| 392 | // ナビゲーションの HTML |
| 393 | let navigation_next_html = ''; |
| 394 | let navigation_prev_html = ''; |
| 395 | if (navigationPosition !== 'hide') { |
| 396 | navigation_next_html = ( |
| 397 | <div |
| 398 | className={`swiper-button-next swiper-button-${navigationPosition}`} |
| 399 | ></div> |
| 400 | ); |
| 401 | navigation_prev_html = ( |
| 402 | <div |
| 403 | className={`swiper-button-prev swiper-button-${navigationPosition}`} |
| 404 | ></div> |
| 405 | ); |
| 406 | } |
| 407 | |
| 408 | // 停止/再生ボタンの HTML(プレビュー(slide)モードで Swiper が初期化される時のみ意味を持つため、 |
| 409 | // editorMode === 'slide' かつ自動再生が有効かつ表示設定が ON の時だけ出力) |
| 410 | const pause_button_html = |
| 411 | editorMode === 'slide' && autoPlay && pauseButton ? ( |
| 412 | <PauseButton /> |
| 413 | ) : ( |
| 414 | '' |
| 415 | ); |
| 416 | |
| 417 | const blockRef = useRef(null); |
| 418 | |
| 419 | const blockProps = useBlockProps({ |
| 420 | className: `vk_slider vk_swiper vk_slider_editorMode--${editorMode} vk_slider_${clientId}${alignClass}`, |
| 421 | ref: blockRef, |
| 422 | }); |
| 423 | |
| 424 | return ( |
| 425 | <> |
| 426 | <BlockControls> |
| 427 | <BlockAlignmentToolbar |
| 428 | value={width} |
| 429 | onChange={(nextWidth) => |
| 430 | setAttributes({ width: nextWidth }) |
| 431 | } |
| 432 | controls={['wide', 'full']} |
| 433 | /> |
| 434 | <ToolbarGroup> |
| 435 | <ToolbarDropdownMenu |
| 436 | icon={ |
| 437 | editorMode === 'default' ? ( |
| 438 | <Dashicon icon="edit" /> |
| 439 | ) : ( |
| 440 | <Dashicon icon="visibility" /> |
| 441 | ) |
| 442 | } |
| 443 | label={__('Change Slide Editor Mode', 'vk-blocks')} |
| 444 | controls={[ |
| 445 | { |
| 446 | title: __( |
| 447 | 'Edit ( Stacked Layout ) Mode', |
| 448 | 'vk-blocks' |
| 449 | ), |
| 450 | icon: <Dashicon icon="edit" />, |
| 451 | isActive: editorMode === 'default', |
| 452 | onClick: () => |
| 453 | setAttributes({ editorMode: 'default' }), |
| 454 | }, |
| 455 | { |
| 456 | title: __( |
| 457 | 'Preview ( Slide ) Mode', |
| 458 | 'vk-blocks' |
| 459 | ), |
| 460 | icon: <Dashicon icon="visibility" />, |
| 461 | isActive: editorMode === 'slide', |
| 462 | onClick: () => |
| 463 | setAttributes({ editorMode: 'slide' }), |
| 464 | }, |
| 465 | ]} |
| 466 | /> |
| 467 | </ToolbarGroup> |
| 468 | </BlockControls> |
| 469 | <InspectorControls> |
| 470 | <PanelBody |
| 471 | title={__('Editor Setting', 'vk-blocks')} |
| 472 | initialOpen={true} |
| 473 | > |
| 474 | <BaseControl |
| 475 | label={__('Editor Mode', 'vk-blocks')} |
| 476 | id={`vk_slider-effect`} |
| 477 | > |
| 478 | <ToggleGroupControl |
| 479 | value={editorMode} |
| 480 | onChange={(value) => |
| 481 | setAttributes({ editorMode: value }) |
| 482 | } |
| 483 | isBlock |
| 484 | help={__( |
| 485 | 'In edit mode, the elements are stacked vertically. In preview mode, the slides actually animate.', |
| 486 | 'vk-blocks' |
| 487 | )} |
| 488 | > |
| 489 | <ToggleGroupControlOption |
| 490 | value="default" |
| 491 | label={__('Edit', 'vk-blocks')} |
| 492 | /> |
| 493 | <ToggleGroupControlOption |
| 494 | value="slide" |
| 495 | label={__('Preview', 'vk-blocks')} |
| 496 | /> |
| 497 | </ToggleGroupControl> |
| 498 | </BaseControl> |
| 499 | </PanelBody> |
| 500 | <PanelBody |
| 501 | title={__('Slider Settings', 'vk-blocks')} |
| 502 | initialOpen={false} |
| 503 | > |
| 504 | <BaseControl |
| 505 | label={__('Effect', 'vk-blocks')} |
| 506 | id={`vk_slider-effect`} |
| 507 | > |
| 508 | <SelectControl |
| 509 | value={effect} |
| 510 | onChange={(value) => |
| 511 | setAttributes({ effect: value }) |
| 512 | } |
| 513 | options={[ |
| 514 | { |
| 515 | label: __('Slide', 'vk-blocks'), |
| 516 | value: 'slide', |
| 517 | }, |
| 518 | { |
| 519 | label: __('Fade', 'vk-blocks'), |
| 520 | value: 'fade', |
| 521 | }, |
| 522 | ]} |
| 523 | /> |
| 524 | </BaseControl> |
| 525 | <BaseControl |
| 526 | label={__('Loop', 'vk-blocks')} |
| 527 | id={`vk_slider-loop`} |
| 528 | > |
| 529 | <AdvancedToggleControl |
| 530 | initialFixedTable={loop} |
| 531 | schema={'loop'} |
| 532 | {...props} |
| 533 | /> |
| 534 | </BaseControl> |
| 535 | <BaseControl |
| 536 | label={__('AutoPlay', 'vk-blocks')} |
| 537 | id={`vk_slider-autoPlay`} |
| 538 | > |
| 539 | <AdvancedToggleControl |
| 540 | initialFixedTable={autoPlay} |
| 541 | schema={'autoPlay'} |
| 542 | {...props} |
| 543 | /> |
| 544 | </BaseControl> |
| 545 | |
| 546 | {/* Slide Direction is only available when AutoPlay is enabled because reverseDirection is an autoplay-specific setting in Swiper.js */} |
| 547 | {autoPlay && ( |
| 548 | <BaseControl |
| 549 | label={__('Slide Direction', 'vk-blocks')} |
| 550 | id={`vk_slider-direction`} |
| 551 | > |
| 552 | <SelectControl |
| 553 | value={direction} |
| 554 | options={[ |
| 555 | { |
| 556 | label: __('Right to Left', 'vk-blocks'), |
| 557 | value: 'rtl', |
| 558 | }, |
| 559 | { |
| 560 | label: __('Left to Right', 'vk-blocks'), |
| 561 | value: 'ltr', |
| 562 | }, |
| 563 | ]} |
| 564 | onChange={(value) => |
| 565 | setAttributes({ direction: value }) |
| 566 | } |
| 567 | /> |
| 568 | </BaseControl> |
| 569 | )} |
| 570 | <BaseControl |
| 571 | label={__('Stop AutoPlay when swipe', 'vk-blocks')} |
| 572 | id={`vk_slider-autoPlay`} |
| 573 | > |
| 574 | <AdvancedToggleControl |
| 575 | initialFixedTable={autoPlayStop} |
| 576 | schema={'autoPlayStop'} |
| 577 | {...props} |
| 578 | /> |
| 579 | </BaseControl> |
| 580 | {/* 停止/再生ボタンは自動再生が有効な時のみ意味を持つため、autoPlay が ON の時だけ表示 */} |
| 581 | {autoPlay && ( |
| 582 | <BaseControl |
| 583 | label={__( |
| 584 | 'Display pause / play button', |
| 585 | 'vk-blocks' |
| 586 | )} |
| 587 | id={`vk_slider-pauseButton`} |
| 588 | help={ |
| 589 | <> |
| 590 | {__( |
| 591 | 'Displays a button on the front end that lets visitors pause and resume the autoplay.', |
| 592 | 'vk-blocks' |
| 593 | )}{' '} |
| 594 | {__( |
| 595 | 'When this is off, autoplay keeps running even for visitors whose device requests reduced motion, since there is no button to pause it.', |
| 596 | 'vk-blocks' |
| 597 | )} |
| 598 | </> |
| 599 | } |
| 600 | > |
| 601 | <AdvancedToggleControl |
| 602 | initialFixedTable={pauseButton} |
| 603 | schema={'pauseButton'} |
| 604 | {...props} |
| 605 | /> |
| 606 | </BaseControl> |
| 607 | )} |
| 608 | <BaseControl |
| 609 | label={__('Display Time', 'vk-blocks')} |
| 610 | id={`vk_slider-autoPlay`} |
| 611 | > |
| 612 | <TextControl |
| 613 | type={'number'} |
| 614 | value={autoPlayDelay} |
| 615 | onChange={(value) => { |
| 616 | if ( |
| 617 | Number.isNaN(Number(value)) || |
| 618 | Number(value) < 0 |
| 619 | ) { |
| 620 | setAttributes({ |
| 621 | autoPlayDelay: 0, |
| 622 | }); |
| 623 | } else { |
| 624 | setAttributes({ |
| 625 | autoPlayDelay: parseInt( |
| 626 | Number(value), |
| 627 | 10 |
| 628 | ), |
| 629 | }); |
| 630 | } |
| 631 | }} |
| 632 | min={0} |
| 633 | /> |
| 634 | </BaseControl> |
| 635 | <BaseControl |
| 636 | label={__('Change Speed', 'vk-blocks')} |
| 637 | id={`vk_slider-changeSpeed`} |
| 638 | > |
| 639 | <TextControl |
| 640 | type={'number'} |
| 641 | value={speed} |
| 642 | onChange={(value) => { |
| 643 | if ( |
| 644 | Number.isNaN(Number(value)) || |
| 645 | Number(value) < 0 |
| 646 | ) { |
| 647 | setAttributes({ |
| 648 | speed: 0, |
| 649 | }); |
| 650 | } else { |
| 651 | setAttributes({ |
| 652 | speed: parseInt(Number(value), 10), |
| 653 | }); |
| 654 | } |
| 655 | }} |
| 656 | min={0} |
| 657 | /> |
| 658 | </BaseControl> |
| 659 | <BaseControl |
| 660 | label={__('Pagination Type', 'vk-blocks')} |
| 661 | id={`vk_slider-displayPagination`} |
| 662 | > |
| 663 | <SelectControl |
| 664 | value={pagination} |
| 665 | options={[ |
| 666 | { |
| 667 | label: __('Hide', 'vk-blocks'), |
| 668 | value: 'hide', |
| 669 | }, |
| 670 | { |
| 671 | label: __('Default', 'vk-blocks'), |
| 672 | value: 'bullets', |
| 673 | }, |
| 674 | { |
| 675 | label: __('Number of slides', 'vk-blocks'), |
| 676 | value: 'fraction', |
| 677 | }, |
| 678 | ]} |
| 679 | onChange={(value) => |
| 680 | setAttributes({ pagination: value }) |
| 681 | } |
| 682 | /> |
| 683 | </BaseControl> |
| 684 | <BaseControl |
| 685 | label={__('Navigation Position', 'vk-blocks')} |
| 686 | id={`vk_slider-navigationPosition`} |
| 687 | > |
| 688 | <SelectControl |
| 689 | value={navigationPosition} |
| 690 | options={[ |
| 691 | { |
| 692 | label: __('Hide', 'vk-blocks'), |
| 693 | value: 'hide', |
| 694 | }, |
| 695 | { |
| 696 | label: __('Center', 'vk-blocks'), |
| 697 | value: 'center', |
| 698 | }, |
| 699 | { |
| 700 | label: __( |
| 701 | 'Bottom on Mobile device', |
| 702 | 'vk-blocks' |
| 703 | ), |
| 704 | value: 'mobile-bottom', |
| 705 | }, |
| 706 | ]} |
| 707 | onChange={(value) => |
| 708 | setAttributes({ navigationPosition: value }) |
| 709 | } |
| 710 | /> |
| 711 | </BaseControl> |
| 712 | </PanelBody> |
| 713 | <MultiItemSetting {...props} /> |
| 714 | <PanelBody |
| 715 | title={__('Height', 'vk-blocks')} |
| 716 | initialOpen={false} |
| 717 | > |
| 718 | <ResponsiveSizeControl |
| 719 | label={__('Slide Height for each device', 'vk-blocks')} |
| 720 | valuePC={pc} |
| 721 | valueTablet={tablet} |
| 722 | valueMobile={mobile} |
| 723 | unit={unit} |
| 724 | onChangePC={(value) => setAttributes({ pc: value })} |
| 725 | onChangeTablet={(value) => |
| 726 | setAttributes({ tablet: value }) |
| 727 | } |
| 728 | onChangeMobile={(value) => |
| 729 | setAttributes({ mobile: value }) |
| 730 | } |
| 731 | onChangeUnit={(value) => setAttributes({ unit: value })} |
| 732 | maxPC={getMaxByUnit(unit)} |
| 733 | maxTablet={getMaxByUnit(unit)} |
| 734 | maxMobile={getMaxByUnit(unit)} |
| 735 | /> |
| 736 | </PanelBody> |
| 737 | <PanelBody |
| 738 | title={__('Background Image Zoom Animation', 'vk-blocks')} |
| 739 | initialOpen={false} |
| 740 | > |
| 741 | {effect !== 'fade' && |
| 742 | (slidesPerViewPC > 1 || |
| 743 | slidesPerViewTablet > 1 || |
| 744 | slidesPerViewMobile > 1) ? ( |
| 745 | <div className="alert alert-warning font-size-11px"> |
| 746 | {__( |
| 747 | 'When multiple items are set in "Multi-item Display Setting", zoom settings here will be disabled. Please set all to "1".', |
| 748 | 'vk-blocks' |
| 749 | )} |
| 750 | </div> |
| 751 | ) : ( |
| 752 | <> |
| 753 | <ToggleControl |
| 754 | label={__('Enable', 'vk-blocks')} |
| 755 | checked={zoomAnimation} |
| 756 | onChange={(value) => |
| 757 | setAttributes({ zoomAnimation: value }) |
| 758 | } |
| 759 | help={__( |
| 760 | 'Enabling this will apply a zoom animation to the slide background image.', |
| 761 | 'vk-blocks' |
| 762 | )} |
| 763 | /> |
| 764 | <div className="alert alert-info font-size-11px"> |
| 765 | {__( |
| 766 | 'We recommend using the Fade effect together with Background image Zoom Animation.', |
| 767 | 'vk-blocks' |
| 768 | )} |
| 769 | </div> |
| 770 | {zoomAnimation && ( |
| 771 | <> |
| 772 | <RangeControl |
| 773 | label={__( |
| 774 | 'Initial Background Scale', |
| 775 | 'vk-blocks' |
| 776 | )} |
| 777 | value={zoomInitialScale} |
| 778 | onChange={(value) => |
| 779 | setAttributes({ |
| 780 | zoomInitialScale: value, |
| 781 | }) |
| 782 | } |
| 783 | min={1} |
| 784 | max={3} |
| 785 | step={0.05} |
| 786 | /> |
| 787 | <RangeControl |
| 788 | label={__( |
| 789 | 'Final Background Scale', |
| 790 | 'vk-blocks' |
| 791 | )} |
| 792 | value={zoomFinalScale} |
| 793 | onChange={(value) => |
| 794 | setAttributes({ |
| 795 | zoomFinalScale: value, |
| 796 | }) |
| 797 | } |
| 798 | min={1} |
| 799 | max={3} |
| 800 | step={0.05} |
| 801 | /> |
| 802 | <p className="vk_slider_zoomAnimation_help"> |
| 803 | {__( |
| 804 | '1 means original size. Larger values will zoom in the background image.', |
| 805 | 'vk-blocks' |
| 806 | )} |
| 807 | </p> |
| 808 | </> |
| 809 | )} |
| 810 | </> |
| 811 | )} |
| 812 | </PanelBody> |
| 813 | </InspectorControls> |
| 814 | <div {...blockProps} data-vkb-slider={JSON.stringify(sliderData)}> |
| 815 | <div className={`vk_slider_wrapper`}> |
| 816 | <div> |
| 817 | <InnerBlocks |
| 818 | //編集画面の追加タグ用に2回目のClassを挿� |
| 819 | � |
| 820 | className={`${containerClass} row`} |
| 821 | template={TEMPLATE} |
| 822 | allowedBlocks={ALLOWED_BLOCKS} |
| 823 | /> |
| 824 | </div> |
| 825 | </div> |
| 826 | {navigation_next_html} |
| 827 | {navigation_prev_html} |
| 828 | {pagination_html} |
| 829 | {pause_button_html} |
| 830 | </div> |
| 831 | </> |
| 832 | ); |
| 833 | } |
| 834 |