|
| 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 globalColorSchemes = { |
| 7 | + initialize: () => { |
| 8 | + // Add some default content that we will select |
| 9 | + |
| 10 | + const headingBlock = wp.blocks.createBlock( |
| 11 | + 'stackable/heading', |
| 12 | + { |
| 13 | + uniqueId: '3dcffca', |
| 14 | + // Retain our text |
| 15 | + text: 'The World is Yours to Explore', |
| 16 | + textTag: 'h1', |
| 17 | + } |
| 18 | + ) |
| 19 | + |
| 20 | + const columnsBlock = wp.blocks.createBlock( |
| 21 | + 'stackable/columns', |
| 22 | + { |
| 23 | + uniqueId: '1dbe04e', |
| 24 | + blockMargin: { bottom: '' }, |
| 25 | + align: 'full', |
| 26 | + hasBackground: true, |
| 27 | + }, |
| 28 | + [ |
| 29 | + wp.blocks.createBlock( |
| 30 | + 'stackable/column', |
| 31 | + { |
| 32 | + uniqueId: 'f957abc', |
| 33 | + }, |
| 34 | + [ |
| 35 | + wp.blocks.createBlock( |
| 36 | + 'stackable/heading', |
| 37 | + { |
| 38 | + uniqueId: 'a8ebea7', |
| 39 | + // Retain our text |
| 40 | + text: 'Explore the World with Us', |
| 41 | + textTag: 'h2', |
| 42 | + } |
| 43 | + ), |
| 44 | + wp.blocks.createBlock( |
| 45 | + 'stackable/text', |
| 46 | + { |
| 47 | + uniqueId: '57e76a1', |
| 48 | + // Retain our text |
| 49 | + text: 'Discover breathtaking destinations, plan your next adventure, and make unforgettable memories with our travel guides and tips.', |
| 50 | + } |
| 51 | + ), |
| 52 | + wp.blocks.createBlock( |
| 53 | + 'stackable/button-group', |
| 54 | + { uniqueId: 'e063798' }, |
| 55 | + [ |
| 56 | + wp.blocks.createBlock( |
| 57 | + 'stackable/button', |
| 58 | + { |
| 59 | + uniqueId: '5d04ca8', |
| 60 | + // Retain our text |
| 61 | + text: 'Start your journey', |
| 62 | + url: '', |
| 63 | + } |
| 64 | + ), |
| 65 | + ] |
| 66 | + ), |
| 67 | + ] |
| 68 | + ), |
| 69 | + ] |
| 70 | + ) |
| 71 | + |
| 72 | + // Insert our block |
| 73 | + dispatch( 'core/block-editor' ).insertBlocks( [ headingBlock, columnsBlock ], 0 ) |
| 74 | + // Open the global settings sidebar. |
| 75 | + dispatch( 'core/edit-post' )?.openGeneralSidebar( 'stackable-global-settings/sidebar' ) |
| 76 | + |
| 77 | + setTimeout( () => { |
| 78 | + document.querySelector( '.ugb-global-color-schemes__panel:not(.is-opened) .components-panel__body-title button' )?.click() |
| 79 | + }, 200 ) |
| 80 | + }, |
| 81 | + steps: [ |
| 82 | + { |
| 83 | + title: '👋 ' + __( 'Welcome to Your Global Color Schemes', i18n ), |
| 84 | + description: __( 'You can use the Global Color Schemes to easily apply consistent color themes across your entire website for effortless branding.', i18n ), |
| 85 | + size: 'medium', |
| 86 | + anchor: '.ugb-global-color-schemes__panel .components-panel__body-title', |
| 87 | + position: 'left', |
| 88 | + }, |
| 89 | + { |
| 90 | + title: __( 'Default Color Scheme', i18n ), |
| 91 | + description: __( 'The default color scheme is the color scheme that is applied to your entire website by default.', i18n ), |
| 92 | + help: createInterpolateElement( __( 'Click the <strong>Default Color Scheme</strong> button to continue.', i18n ), { |
| 93 | + strong: <strong />, |
| 94 | + } ), |
| 95 | + anchor: '.ugb-global-color-schemes__panel .stk-global-color-scheme__color-scheme-item[data-item-key="scheme-default-1"]', |
| 96 | + position: 'left', |
| 97 | + nextEventTarget: '.ugb-global-color-schemes__panel .stk-global-color-scheme__color-scheme-item[data-item-key="scheme-default-1"]', |
| 98 | + glowTarget: '.ugb-global-color-schemes__panel .stk-global-color-scheme__color-scheme-item[data-item-key="scheme-default-1"]', |
| 99 | + postStep: () => { |
| 100 | + document.querySelector( '.ugb-global-color-schemes__panel .stk-global-color-scheme__color-scheme-item[data-item-key="scheme-default-1"]' )?.click() |
| 101 | + }, |
| 102 | + }, |
| 103 | + { |
| 104 | + title: __( 'Setting the Default Color Scheme', i18n ), |
| 105 | + description: __( 'To make things easy, we\'ve added some color scheme presets. Pick the 2nd one to quickly see how your entire design system will instantly change in the Style Guide preview below.', i18n ), |
| 106 | + help: createInterpolateElement( __( 'Click this <strong>color scheme preset</strong> to continue.', i18n ), { |
| 107 | + strong: <strong />, |
| 108 | + } ), |
| 109 | + size: 'medium', |
| 110 | + anchor: '.stk-preset-color-schemes__preset-wrapper > .stk-global-color-scheme__preview:nth-child(2)', |
| 111 | + position: 'left', |
| 112 | + nextEventTarget: '.stk-preset-color-schemes__preset-wrapper > .stk-global-color-scheme__preview:nth-child(2)', |
| 113 | + glowTarget: '.stk-preset-color-schemes__preset-wrapper > .stk-global-color-scheme__preview:nth-child(2)', |
| 114 | + postStep: () => { |
| 115 | + document.querySelector( '.stk-preset-color-schemes__preset-wrapper > .stk-global-color-scheme__preview:nth-child(2) button' )?.click() |
| 116 | + }, |
| 117 | + }, |
| 118 | + { |
| 119 | + title: __( 'See the Stackable Blocks Change Colors', i18n ), |
| 120 | + description: __( 'Notice how all Stackable blocks changed their colors across your site. You can further customize the colors below to match your brand or style.', i18n ), |
| 121 | + offsetX: '300px', |
| 122 | + }, |
| 123 | + { |
| 124 | + title: __( 'Go Back to Color Schemes', i18n ), |
| 125 | + description: __( 'Let\'s see another way that color schemes can help with your site\'s design. Click the back button to return to the list of color schemes.', i18n ), |
| 126 | + help: createInterpolateElement( __( 'Click the <strong>Back</strong> button to continue.', i18n ), { |
| 127 | + strong: <strong />, |
| 128 | + } ), |
| 129 | + anchor: '.stk-inspector-sub-header button', |
| 130 | + position: 'left', |
| 131 | + glowTarget: '.stk-inspector-sub-header button', |
| 132 | + nextEventTarget: '.stk-inspector-sub-header button', |
| 133 | + postStep: () => { |
| 134 | + document.querySelector( '.stk-inspector-sub-header button' )?.click() |
| 135 | + }, |
| 136 | + }, |
| 137 | + { |
| 138 | + title: __( 'Background Schemes', i18n ), |
| 139 | + description: __( 'The columns block on this page has its block background enabled. You can assign a different color scheme to blocks with backgrounds turned on.', i18n ), |
| 140 | + help: createInterpolateElement( __( 'Click the <strong>Background Scheme</strong> button to continue.', i18n ), { |
| 141 | + strong: <strong />, |
| 142 | + } ), |
| 143 | + anchor: '.ugb-global-color-schemes__panel .stk-global-color-scheme__color-scheme-item[data-item-key="scheme-default-2"]', |
| 144 | + position: 'left', |
| 145 | + nextEventTarget: '.ugb-global-color-schemes__panel .stk-global-color-scheme__color-scheme-item[data-item-key="scheme-default-2"]', |
| 146 | + glowTarget: '.ugb-global-color-schemes__panel .stk-global-color-scheme__color-scheme-item[data-item-key="scheme-default-2"]', |
| 147 | + postStep: () => { |
| 148 | + document.querySelector( '.ugb-global-color-schemes__panel .stk-global-color-scheme__color-scheme-item[data-item-key="scheme-default-2"]' )?.click() |
| 149 | + }, |
| 150 | + }, |
| 151 | + { |
| 152 | + title: __( 'Pick a Darker Background Color Scheme', i18n ), |
| 153 | + description: __( 'Let\'s choose a darker color scheme preset for the background. This background color scheme will be used on blocks when the block background is enabled, giving your design more contrast and customization.', i18n ), |
| 154 | + help: createInterpolateElement( __( 'Click this <strong>color scheme preset</strong> to continue.', i18n ), { |
| 155 | + strong: <strong />, |
| 156 | + } ), |
| 157 | + size: 'medium', |
| 158 | + anchor: '.stk-preset-color-schemes__preset-wrapper > .stk-global-color-scheme__preview:nth-child(8)', |
| 159 | + position: 'left', |
| 160 | + nextEventTarget: '.stk-preset-color-schemes__preset-wrapper > .stk-global-color-scheme__preview:nth-child(8)', |
| 161 | + glowTarget: '.stk-preset-color-schemes__preset-wrapper > .stk-global-color-scheme__preview:nth-child(8)', |
| 162 | + preStep: () => { |
| 163 | + setTimeout( () => { |
| 164 | + const targetElTop = document.querySelector( '.stk-preset-color-schemes__preset-wrapper' )?.getBoundingClientRect()?.top |
| 165 | + const editorSidebar = document.querySelector( '.interface-complementary-area.editor-sidebar' ) |
| 166 | + editorSidebar.scrollTo( { |
| 167 | + top: targetElTop - editorSidebar.getBoundingClientRect().top - 300, |
| 168 | + behavior: 'smooth', |
| 169 | + } ) |
| 170 | + }, 100 ) |
| 171 | + }, |
| 172 | + postStep: () => { |
| 173 | + document.querySelector( '.stk-preset-color-schemes__preset-wrapper > .stk-global-color-scheme__preview:nth-child(8) button' )?.click() |
| 174 | + }, |
| 175 | + }, |
| 176 | + { |
| 177 | + title: __( 'Looking Good! Background Scheme Updated', i18n ), |
| 178 | + description: __( 'The columns block now uses your chosen darker background, and its content colors automatically follow the scheme for a nice, coordinated look.', i18n ), |
| 179 | + offsetX: '300px', |
| 180 | + }, |
| 181 | + { |
| 182 | + title: __( 'Open the Inspector Sidebar', i18n ), |
| 183 | + description: __( 'Now let\'s open the Inspector sidebar so you can see where to further customize this color scheme.', i18n ), |
| 184 | + help: createInterpolateElement( __( 'Click the <strong>Inspector Controls</strong> button to continue.', i18n ), { |
| 185 | + strong: <strong />, |
| 186 | + } ), |
| 187 | + anchor: '[aria-controls="edit-post:block"]', |
| 188 | + position: 'left-top', |
| 189 | + offsetY: '-30px', |
| 190 | + offsetX: '-8px', |
| 191 | + glowTarget: '[aria-controls="edit-post:block"]', |
| 192 | + nextEventTarget: '[aria-controls="edit-post:block"]', |
| 193 | + postStep: () => { |
| 194 | + dispatch( 'core/edit-post' ).openGeneralSidebar( 'edit-post/block' ) |
| 195 | + // Make sure the Inner Column is selected. |
| 196 | + const block = select( 'core/block-editor' ).getSelectedBlock() |
| 197 | + if ( block?.name !== 'stackable/column' ) { |
| 198 | + // Look for the first "stackable/columns" block |
| 199 | + const allBlocks = select( 'core/block-editor' ).getBlocks() |
| 200 | + const columnsBlock = allBlocks.find( block => block.name === 'stackable/columns' ) |
| 201 | + if ( columnsBlock ) { |
| 202 | + dispatch( 'core/block-editor' ).selectBlock( columnsBlock.clientId ) |
| 203 | + setTimeout( () => { |
| 204 | + document.querySelector( '.edit-post-sidebar__panel-tab.ugb-tab--style:not(.is-active)' )?.click() |
| 205 | + setTimeout( () => { |
| 206 | + document.querySelector( '.ugb-block-background-panel:not(is-opened) button' )?.click() |
| 207 | + }, 100 ) |
| 208 | + }, 100 ) |
| 209 | + } |
| 210 | + } |
| 211 | + }, |
| 212 | + }, |
| 213 | + { |
| 214 | + title: __( 'Switch Between Color Schemes Anytime', i18n ), |
| 215 | + description: __( 'If you have multiple global color schemes set up, you can easily change your block\'s style by switching the color scheme option here to instantly apply a new look.', i18n ), |
| 216 | + anchor: '.stk-control:has([data-attribute="backgroundColorScheme"])', |
| 217 | + position: 'left', |
| 218 | + glowTarget: '.stk-control:has([data-attribute="backgroundColorScheme"])', |
| 219 | + nextEventTarget: '.stk-control:has([data-attribute="backgroundColorScheme"]) select', |
| 220 | + }, |
| 221 | + { |
| 222 | + title: __( 'Global Color Schemes Ready!', i18n ), |
| 223 | + description: __( 'You\'re all set! Start customizing and applying your global color schemes to make your site look great.', i18n ), |
| 224 | + offsetX: '300px', |
| 225 | + offsetY: '100px', |
| 226 | + }, |
| 227 | + ], |
| 228 | +} |
0 commit comments