Skip to content

Commit 387432d

Browse files
authored
Merge branch 'develop' into fix/design-library-add-new-patterns-to-stackable-category
2 parents 376721a + 2b2d5d5 commit 387432d

File tree

11 files changed

+629
-9
lines changed

11 files changed

+629
-9
lines changed

gulpfile.js

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,81 @@ ${ blockDesignSystem });
411411
cb()
412412
} )
413413

414+
gulp.task( 'generate-design-library-default-placeholders-php', function( cb ) {
415+
const fs = require( 'fs' )
416+
417+
let defaultPlaceholders = 'array()'
418+
419+
const toAssocArray = ( key, value, cb, indent ) => {
420+
if ( typeof value === 'object' ) {
421+
const parsed = cb( value, indent + 1 )
422+
return `"${ key }" => ${ parsed }`
423+
}
424+
425+
return `"${ key }" => "${ value }"`
426+
}
427+
428+
const parsePlaceholders = ( obj, indent ) => {
429+
let content = ''
430+
const tab = '\t'.repeat( indent )
431+
432+
if ( typeof obj === 'object' ) {
433+
content += 'array(\n'
434+
435+
Object.entries( obj ).forEach( ( [ key, value ], index, bds ) => {
436+
content += tab + toAssocArray( key, value, parsePlaceholders, indent )
437+
438+
if ( index !== bds.length - 1 ) {
439+
content += ',\n'
440+
} else {
441+
content += '\n'
442+
}
443+
} )
444+
content += `\t`.repeat( indent - 1 ) + ')'
445+
}
446+
return content
447+
}
448+
449+
const jsonPath = path.resolve( __dirname, `src/components/design-library-list/default.json` )
450+
if ( fs.existsSync( jsonPath ) ) {
451+
const fileContent = fs.readFileSync( jsonPath, 'utf-8' )
452+
const raw = JSON.parse( fileContent )
453+
defaultPlaceholders = parsePlaceholders( raw, 4 )
454+
}
455+
456+
// Generate PHP variable string
457+
const script = `<?php
458+
// This is a generated file by gulp generate-design-library-default-placeholders-php
459+
// Use src/components/design-library-list/default.json if you want to edit this file.
460+
461+
// Exit if accessed directly.
462+
if ( ! defined( 'ABSPATH' ) ) {
463+
exit;
464+
}
465+
466+
if ( ! class_exists( 'Stackable_Design_Library_Placeholders' ) ) {
467+
class Stackable_Design_Library_Placeholders {
468+
469+
function __construct() {
470+
}
471+
472+
public static function get_default() {
473+
$default_placeholders = ${ defaultPlaceholders };
474+
475+
return $default_placeholders;
476+
}
477+
}
478+
479+
new Stackable_Design_Library_Placeholders();
480+
}
481+
?>
482+
`
483+
// Write PHP variable to file
484+
fs.writeFileSync( path.resolve( __dirname, 'src/design-library/default-placeholders.php' ), script )
485+
486+
cb()
487+
} )
488+
414489
gulp.task( 'generate-translations-js', gulp.series(
415490
// The collect function has an issue where it will not continue if the
416491
// folder will it writes to doesn't exist, create it to prevent an error.
@@ -703,7 +778,7 @@ gulp.task( 'style-deprecated', gulp.parallel(
703778
* END deprecated build styles, we still build these
704779
********************************************************************/
705780

706-
gulp.task( 'build-process', gulp.parallel( 'style', 'style-editor', 'welcome-styles', 'style-deprecated', 'generate-translations-js', 'generate-stk-block-typesphp' ) )
781+
gulp.task( 'build-process', gulp.parallel( 'style', 'style-editor', 'welcome-styles', 'style-deprecated', 'generate-translations-js', 'generate-stk-block-typesphp', 'generate-design-library-default-placeholders-php' ) )
707782

708783
gulp.task( 'build-block-design-system', gulp.parallel( 'generate-block-design-system-php', 'generate-block-design-system-scss' ) )
709784

@@ -740,6 +815,11 @@ const watchFuncs = ( basePath = '.' ) => {
740815
[ `${ basePath }/src/block/**/block.json` ],
741816
gulp.parallel( [ 'generate-stk-block-typesphp' ] )
742817
)
818+
819+
gulp.watch(
820+
[ `${ basePath }/src/components/design-library-list/default.json` ],
821+
gulp.parallel( [ 'generate-design-library-default-placeholders-php' ] )
822+
)
743823
}
744824

745825
gulp.task( 'watch', gulp.series( 'build-block-design-system', 'build-process', function watch( done ) {

plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ function is_frontend() {
230230
require_once( plugin_dir_path( __FILE__ ) . 'src/kses.php' );
231231
require_once( plugin_dir_path( __FILE__ ) . 'src/dynamic-breakpoints.php' );
232232
require_once( plugin_dir_path( __FILE__ ) . 'src/design-library/init.php' );
233+
require_once( plugin_dir_path( __FILE__ ) . 'src/design-library/default-placeholders.php' );
233234
require_once( plugin_dir_path( __FILE__ ) . 'src/styles/block-design-system.php' );
234235
require_once( plugin_dir_path( __FILE__ ) . 'src/plugins/theme-block-style-inheritance/index.php' );
235236
require_once( plugin_dir_path( __FILE__ ) . 'src/global-settings.php' );

src/block-components/image/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const Controls = props => {
175175
newAttributes.imageWidth = ''
176176
newAttributes.imageWidthUnit = '%'
177177
// We need the width of the image block to compare
178-
if ( width < imageBlockWidth ) {
178+
if ( width && width < imageBlockWidth ) {
179179
newAttributes.imageWidth = width
180180
newAttributes.imageWidthUnit = 'px'
181181
}

src/block/progress-bar/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const Edit = props => {
120120
</div>
121121
{ /* Add our progress style here because we're adjusting the value using a hook */ }
122122
<style>
123-
{ `.editor-styles-wrapper .stk-${ props.attributes.uniqueId } .stk-progress-bar { --progress-value:${ derivedValue }% !important; }` }
123+
{ `.editor-styles-wrapper .stk-${ props.attributes.uniqueId } .stk-progress-bar { --progress-value:${ derivedProgressValue }% !important; }` }
124124
</style>
125125
</BlockDiv>
126126
{ props.isHovered && <MarginBottom /> }

src/block/progress-circle/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const Edit = props => {
132132
</div>
133133
{ /* Add our progress style here because we're adjusting the value using a hook */ }
134134
<style>
135-
{ `.editor-styles-wrapper .stk-${ props.attributes.uniqueId } .stk-progress-circle { --progress-value:${ derivedValue } }` }
135+
{ `.editor-styles-wrapper .stk-${ props.attributes.uniqueId } .stk-progress-circle { --progress-value:${ derivedProgressValue } }` }
136136
</style>
137137
</BlockDiv>
138138
{ props.isHovered && <MarginBottom /> }

src/components/advanced-autosuggest-control/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class AdvancedAutosuggestControl extends Component {
279279
this.setState( { isShowingSuggestions: false } )
280280
}
281281

282-
if ( shouldShowSuggestions ) {
282+
if ( shouldShowSuggestions && this.state.containerRect ) {
283283
// We need to add styling to position the
284284
// suggestion drop down correctly. Scrolling
285285
// the editor/inspector breaks the position, so

src/components/variation-picker/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const VariationPicker = props => {
1818
const {
1919
icon = layout,
2020
label = __( 'Choose variation' ), // Dev note: no text domain here since this will use WP's translation.
21-
instructions = __( 'Select a variation to start with.' ), // Dev note: no text domain here since this will use WP's translation.
21+
instructions = __( 'Select a variation to start with.', i18n ),
2222
variations,
2323
onSelect,
2424
allowSkip,

0 commit comments

Comments
 (0)