|
| 1 | +import { __ } from '@wordpress/i18n' |
| 2 | +import { i18n } from 'stackable' |
| 3 | +import { dispatch, select } from '@wordpress/data' |
| 4 | +import { createInterpolateElement } from '@wordpress/element' |
| 5 | + |
| 6 | +export const blockBackgrounds = { |
| 7 | + initialize: () => { |
| 8 | + // Add some default content that we will select |
| 9 | + |
| 10 | + const blockObject = wp.blocks.createBlock( |
| 11 | + 'stackable/columns', |
| 12 | + { |
| 13 | + uniqueId: '1dbe04e', |
| 14 | + blockMargin: { bottom: '' }, |
| 15 | + align: 'full', |
| 16 | + containerWidth: 50, |
| 17 | + containerHorizontalAlign: 'flex-start', |
| 18 | + containerWidthUnit: '%', |
| 19 | + }, |
| 20 | + [ |
| 21 | + wp.blocks.createBlock( |
| 22 | + 'stackable/column', |
| 23 | + { |
| 24 | + uniqueId: 'f957abc', |
| 25 | + columnSpacing: { |
| 26 | + top: '', right: '', bottom: '', left: '', |
| 27 | + }, |
| 28 | + }, |
| 29 | + [ |
| 30 | + wp.blocks.createBlock( |
| 31 | + 'stackable/heading', |
| 32 | + { |
| 33 | + uniqueId: 'a8ebea7', |
| 34 | + // Retain our text |
| 35 | + text: 'Explore the World with Us', |
| 36 | + textTag: 'h2', |
| 37 | + } |
| 38 | + ), |
| 39 | + wp.blocks.createBlock( |
| 40 | + 'stackable/text', |
| 41 | + { |
| 42 | + uniqueId: '57e76a1', |
| 43 | + // Retain our text |
| 44 | + text: 'Discover breathtaking destinations, plan your next adventure, and make unforgettable memories with our travel guides and tips.', |
| 45 | + } |
| 46 | + ), |
| 47 | + wp.blocks.createBlock( |
| 48 | + 'stackable/button-group', |
| 49 | + { uniqueId: 'e063798' }, |
| 50 | + [ |
| 51 | + wp.blocks.createBlock( |
| 52 | + 'stackable/button', |
| 53 | + { |
| 54 | + uniqueId: '5d04ca8', |
| 55 | + // Retain our text |
| 56 | + text: 'Start your journey', |
| 57 | + url: '', |
| 58 | + } |
| 59 | + ), |
| 60 | + ] |
| 61 | + ), |
| 62 | + ] |
| 63 | + ), |
| 64 | + ] |
| 65 | + ) |
| 66 | + // Insert our block |
| 67 | + dispatch( 'core/block-editor' ).insertBlocks( [ blockObject ], 0 ) |
| 68 | + |
| 69 | + // Select the inner columns block for the tour |
| 70 | + dispatch( 'core/block-editor' ).selectBlock( blockObject.clientId ) |
| 71 | + }, |
| 72 | + steps: [ |
| 73 | + { |
| 74 | + title: __( 'Discover Stackable Block Backgrounds & Containers', i18n ), |
| 75 | + description: __( 'Welcome! Let\'s enhance your page by first adding a background to the Columns block. The Style Tab lets you tweak backgrounds, colors, borders, and typography for a custom look.', i18n ), |
| 76 | + help: createInterpolateElement( __( 'Click the <strong>Style Tab</strong> in the sidebar to get started.', i18n ), { |
| 77 | + strong: <strong />, |
| 78 | + } ), |
| 79 | + anchor: '.edit-post-sidebar__panel-tab.ugb-tab--style', |
| 80 | + position: 'left', |
| 81 | + glowTarget: '.edit-post-sidebar__panel-tab.ugb-tab--style', |
| 82 | + nextEventTarget: '.edit-post-sidebar__panel-tab.ugb-tab--style', |
| 83 | + preStep: () => { |
| 84 | + // Open the inspector sidebar |
| 85 | + dispatch( 'core/edit-post' ).openGeneralSidebar( 'edit-post/block' ) |
| 86 | + |
| 87 | + // Look for the first "stackable/columns" block |
| 88 | + const allBlocks = select( 'core/block-editor' ).getBlocks() |
| 89 | + const columnsBlock = allBlocks.find( block => block.name === 'stackable/columns' ) |
| 90 | + if ( columnsBlock ) { |
| 91 | + dispatch( 'core/block-editor' ).selectBlock( columnsBlock.clientId ) |
| 92 | + } |
| 93 | + }, |
| 94 | + postStep: () => { |
| 95 | + // Click the tab |
| 96 | + document.querySelector( '.edit-post-sidebar__panel-tab.ugb-tab--style:not(.is-active)' )?.click() |
| 97 | + }, |
| 98 | + }, |
| 99 | + { |
| 100 | + title: __( 'Enable a Block Background', i18n ), |
| 101 | + description: __( 'Turn on the background option to instantly add a background layer to your section. Watch as your design transforms with a single toggle.', i18n ), |
| 102 | + help: createInterpolateElement( __( 'Toggle ON the <strong>Background</strong> option to continue.', i18n ), { |
| 103 | + strong: <strong />, |
| 104 | + } ), |
| 105 | + anchor: '.ugb-block-background-panel .components-panel__body-title', |
| 106 | + position: 'left', |
| 107 | + glowTarget: '.ugb-block-background-panel .components-panel__body-title', |
| 108 | + nextEventTarget: '.ugb-block-background-panel .components-panel__body-title input[type="checkbox"]', |
| 109 | + nextEvent: 'mousedown', |
| 110 | + preStep: () => { |
| 111 | + // Open the inspector sidebar |
| 112 | + dispatch( 'core/edit-post' ).openGeneralSidebar( 'edit-post/block' ) |
| 113 | + |
| 114 | + // Look for the first "stackable/columns" block |
| 115 | + const allBlocks = select( 'core/block-editor' ).getBlocks() |
| 116 | + const columnsBlock = allBlocks.find( block => block.name === 'stackable/columns' ) |
| 117 | + if ( columnsBlock ) { |
| 118 | + dispatch( 'core/block-editor' ).selectBlock( columnsBlock.clientId ) |
| 119 | + } |
| 120 | + |
| 121 | + setTimeout( () => { |
| 122 | + // Click the tab |
| 123 | + document.querySelector( '.edit-post-sidebar__panel-tab.ugb-tab--style:not(.is-active)' )?.click() |
| 124 | + }, 100 ) |
| 125 | + }, |
| 126 | + }, |
| 127 | + { |
| 128 | + title: __( 'Customize the Background Color', i18n ), |
| 129 | + description: __( 'Now let\'s personalize your section. Choose a background color to help your content stand out or integrate it seamlessly into your page design.', i18n ), |
| 130 | + help: createInterpolateElement( __( 'Open the <strong>Background Color</strong> panel to select a color.', i18n ), { |
| 131 | + strong: <strong />, |
| 132 | + } ), |
| 133 | + anchor: '.stk-color-palette-control', |
| 134 | + position: 'left', |
| 135 | + glowTarget: '.ugb-block-background-panel .block-editor-panel-color-gradient-settings__dropdown', |
| 136 | + nextEventTarget: '.ugb-block-background-panel .block-editor-panel-color-gradient-settings__dropdown', |
| 137 | + nextEvent: 'mousedown', |
| 138 | + preStep: () => { |
| 139 | + // Toggle background on |
| 140 | + document.querySelector( '.ugb-block-background-panel:not(is-opened)' )?.click() |
| 141 | + document.querySelector( '.ugb-block-background-panel .ugb-toggle-panel-form-toggle:not(is-checked) input' )?.click() |
| 142 | + }, |
| 143 | + postStep: () => { |
| 144 | + // Click the tab |
| 145 | + document.querySelector( '.ugb-block-background-panel .stk-color-palette-control .block-editor-panel-color-gradient-settings__dropdown:not(is-open)' )?.click() |
| 146 | + }, |
| 147 | + }, |
| 148 | + { |
| 149 | + title: __( 'Pick Your Brand Color', i18n ), |
| 150 | + description: __( 'Select a color that matches your brand or mood. Try out different colors and instantly see the changes on your block.', i18n ), |
| 151 | + help: createInterpolateElement( __( 'Choose a <strong>Color</strong> from the palette to apply it.', i18n ), { |
| 152 | + strong: <strong />, |
| 153 | + } ), |
| 154 | + anchor: '.stk-color-palette-control__popover-content', |
| 155 | + position: 'left', |
| 156 | + glowTarget: '.stk-color-palette-control__popover-content', |
| 157 | + nextEvent: 'mousedown', |
| 158 | + nextEventTarget: '.stk-color-palette-control__popover-content *', |
| 159 | + postStep: () => { |
| 160 | + // Click the color picker |
| 161 | + document.querySelector( '.ugb-block-background-panel .stk-color-palette-control .block-editor-panel-color-gradient-settings__dropdown.is-open' )?.click() |
| 162 | + }, |
| 163 | + }, |
| 164 | + { |
| 165 | + title: __( 'Add a Container for Better Layout', i18n ), |
| 166 | + description: __( 'Turn on the Container option to give your columns content a background, padding, and improved alignment for a polished look.', i18n ), |
| 167 | + help: createInterpolateElement( __( 'Toggle ON the <strong>Container</strong> to proceed.', i18n ), { |
| 168 | + strong: <strong />, |
| 169 | + } ), |
| 170 | + anchor: '.ugb-panel--container-size .components-panel__body-title', |
| 171 | + position: 'left', |
| 172 | + glowTarget: '.ugb-panel--container-size .components-panel__body-title', |
| 173 | + nextEventTarget: '.ugb-panel--container-size .components-panel__body-title input[type="checkbox"]', |
| 174 | + nextEvent: 'mousedown', |
| 175 | + preStep: () => { |
| 176 | + // Click the tab |
| 177 | + document.querySelector( '.ugb-block-background-panel .stk-color-palette-control .block-editor-panel-color-gradient-settings__dropdown.is-open' )?.click() |
| 178 | + |
| 179 | + const allBlocks = select( 'core/block-editor' ).getBlocks() |
| 180 | + const columnsBlock = allBlocks.find( block => block.name === 'stackable/columns' ) |
| 181 | + if ( columnsBlock && columnsBlock.innerBlocks[ 0 ] ) { |
| 182 | + dispatch( 'core/block-editor' ).selectBlock( columnsBlock.innerBlocks[ 0 ].clientId ) |
| 183 | + document.querySelector( '.edit-post-sidebar__panel-tab.ugb-tab--layout:not(.is-active)' )?.click() |
| 184 | + setTimeout( () => { |
| 185 | + document.querySelector( '.ugb-panel--layout.is-opened .components-panel__body-title button' )?.click() |
| 186 | + }, 100 ) |
| 187 | + } |
| 188 | + }, |
| 189 | + }, |
| 190 | + { |
| 191 | + title: __( 'Block Backgrounds & Containers Recap', i18n ), |
| 192 | + description: __( 'Great job! You\'ve learned how to add and customize block backgrounds and containers. These features are available in most Stackable blocks, helping you create beautiful, consistent layouts with ease.', i18n ), |
| 193 | + preStep: () => { |
| 194 | + // Toggle background on |
| 195 | + document.querySelector( '.ugb-panel--container-size:not(is-opened)' )?.click() |
| 196 | + document.querySelector( '.ugb-panel--container-size .ugb-toggle-panel-form-toggle:not(is-checked) input' )?.click() |
| 197 | + }, |
| 198 | + }, |
| 199 | + { |
| 200 | + title: __( 'Tip: Style All Blocks Efficiently', i18n ), |
| 201 | + description: createInterpolateElement( __( 'Use the <strong>Stackable Design System</strong> to manage styles for all Stackable blocks globally. Perfect for a unified look and quick design changes!', i18n ), { |
| 202 | + strong: <strong />, |
| 203 | + } ), |
| 204 | + anchor: '[aria-controls="stackable-global-settings:sidebar"]', |
| 205 | + position: 'left-top', |
| 206 | + offsetY: '-30px', |
| 207 | + offsetX: '-8px', |
| 208 | + glowTarget: '[aria-controls="stackable-global-settings:sidebar"]', |
| 209 | + }, |
| 210 | + ], |
| 211 | +} |
0 commit comments