Skip to content

Commit f725ce0

Browse files
committed
fix #850
1 parent 75ba2df commit f725ce0

File tree

5 files changed

+93
-103
lines changed

5 files changed

+93
-103
lines changed

Diff for: src/blocks/section-break-the-grid/edit.js

+22-21
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ import { useSelect } from '@wordpress/data';
3030
import { __, sprintf } from '@wordpress/i18n';
3131
import { pullLeft, pullRight } from '@wordpress/icons';
3232

33-
import { toNumber, getMediaType, isVideoType } from '@smb/helper';
33+
import {
34+
toNumber,
35+
getMediaType,
36+
isVideoType,
37+
cleanEmptyObject,
38+
} from '@smb/helper';
3439

3540
import Figure from '@smb/component/figure';
3641
import ResolutionTool from '@smb/component/resolution-tool';
@@ -1394,29 +1399,25 @@ export default function ( {
13941399
positionValue: backgroundText.position,
13951400
onPositionChange: ( value ) => {
13961401
newBackgroundText.position.top =
1397-
null != value?.top
1398-
? value?.top.match( /^\d+$/ )
1399-
? `${ value?.top }px`
1400-
: value?.top
1401-
: undefined;
1402+
null != value?.top &&
1403+
value?.top.match( /^\d+$/ )
1404+
? `${ value?.top }px`
1405+
: value?.top;
14021406
newBackgroundText.position.right =
1403-
null != value?.right
1404-
? value?.right.match( /^\d+$/ )
1405-
? `${ value?.right }px`
1406-
: value?.right
1407-
: undefined;
1407+
null != value?.right &&
1408+
value?.right.match( /^\d+$/ )
1409+
? `${ value?.right }px`
1410+
: value?.right;
14081411
newBackgroundText.position.bottom =
1409-
null != value?.bottom
1410-
? value?.bottom.match( /^\d+$/ )
1411-
? `${ value?.bottom }px`
1412-
: value?.bottom
1413-
: undefined;
1412+
null != value?.bottom &&
1413+
value?.bottom.match( /^\d+$/ )
1414+
? `${ value?.bottom }px`
1415+
: value?.bottom;
14141416
newBackgroundText.position.left =
1415-
null != value?.left
1416-
? value?.left.match( /^\d+$/ )
1417-
? `${ value?.left }px`
1418-
: value?.left
1419-
: undefined;
1417+
null != value?.left &&
1418+
value?.left.match( /^\d+$/ )
1419+
? `${ value?.left }px`
1420+
: value?.left;
14201421

14211422
setAttributes( {
14221423
backgroundText: cleanEmptyObject( {

Diff for: src/blocks/section-with-bgimage/edit.js

+22-21
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ import ResponsiveTabPanel from '@smb/component/responsive-tab-panel';
3131
import Figure from '@smb/component/figure';
3232
import ResolutionTool from '@smb/component/resolution-tool';
3333

34-
import { toNumber, getMediaType, isVideoType } from '@smb/helper';
34+
import {
35+
toNumber,
36+
getMediaType,
37+
isVideoType,
38+
cleanEmptyObject,
39+
} from '@smb/helper';
3540

3641
import { PanelBasicSettings } from '../section/components/basic';
3742
import { Edit as Header } from '../section/components/header';
@@ -1178,29 +1183,25 @@ export default function ( {
11781183
positionValue: backgroundText.position,
11791184
onPositionChange: ( value ) => {
11801185
newBackgroundText.position.top =
1181-
null != value?.top
1182-
? value?.top.match( /^\d+$/ )
1183-
? `${ value?.top }px`
1184-
: value?.top
1185-
: undefined;
1186+
null != value?.top &&
1187+
value?.top.match( /^\d+$/ )
1188+
? `${ value?.top }px`
1189+
: value?.top;
11861190
newBackgroundText.position.right =
1187-
null != value?.right
1188-
? value?.right.match( /^\d+$/ )
1189-
? `${ value?.right }px`
1190-
: value?.right
1191-
: undefined;
1191+
null != value?.right &&
1192+
value?.right.match( /^\d+$/ )
1193+
? `${ value?.right }px`
1194+
: value?.right;
11921195
newBackgroundText.position.bottom =
1193-
null != value?.bottom
1194-
? value?.bottom.match( /^\d+$/ )
1195-
? `${ value?.bottom }px`
1196-
: value?.bottom
1197-
: undefined;
1196+
null != value?.bottom &&
1197+
value?.bottom.match( /^\d+$/ )
1198+
? `${ value?.bottom }px`
1199+
: value?.bottom;
11981200
newBackgroundText.position.left =
1199-
null != value?.left
1200-
? value?.left.match( /^\d+$/ )
1201-
? `${ value?.left }px`
1202-
: value?.left
1203-
: undefined;
1201+
null != value?.left &&
1202+
value?.left.match( /^\d+$/ )
1203+
? `${ value?.left }px`
1204+
: value?.left;
12041205

12051206
setAttributes( {
12061207
backgroundText: cleanEmptyObject( {

Diff for: src/blocks/section-with-bgvideo/edit.js

+17-21
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import { useSelect } from '@wordpress/data';
2727
import { __ } from '@wordpress/i18n';
2828

29-
import { toNumber } from '@smb/helper';
29+
import { toNumber, cleanEmptyObject } from '@smb/helper';
3030

3131
import { PanelBasicSettings } from '../section/components/basic';
3232
import { Edit as Header } from '../section/components/header';
@@ -510,29 +510,25 @@ export default function ( {
510510
positionValue: backgroundText.position,
511511
onPositionChange: ( value ) => {
512512
newBackgroundText.position.top =
513-
null != value?.top
514-
? value?.top.match( /^\d+$/ )
515-
? `${ value?.top }px`
516-
: value?.top
517-
: undefined;
513+
null != value?.top &&
514+
value?.top.match( /^\d+$/ )
515+
? `${ value?.top }px`
516+
: value?.top;
518517
newBackgroundText.position.right =
519-
null != value?.right
520-
? value?.right.match( /^\d+$/ )
521-
? `${ value?.right }px`
522-
: value?.right
523-
: undefined;
518+
null != value?.right &&
519+
value?.right.match( /^\d+$/ )
520+
? `${ value?.right }px`
521+
: value?.right;
524522
newBackgroundText.position.bottom =
525-
null != value?.bottom
526-
? value?.bottom.match( /^\d+$/ )
527-
? `${ value?.bottom }px`
528-
: value?.bottom
529-
: undefined;
523+
null != value?.bottom &&
524+
value?.bottom.match( /^\d+$/ )
525+
? `${ value?.bottom }px`
526+
: value?.bottom;
530527
newBackgroundText.position.left =
531-
null != value?.left
532-
? value?.left.match( /^\d+$/ )
533-
? `${ value?.left }px`
534-
: value?.left
535-
: undefined;
528+
null != value?.left &&
529+
value?.left.match( /^\d+$/ )
530+
? `${ value?.left }px`
531+
: value?.left;
536532

537533
setAttributes( {
538534
backgroundText: cleanEmptyObject( {

Diff for: src/blocks/section/components/background.js

+16-20
Original file line numberDiff line numberDiff line change
@@ -1097,30 +1097,26 @@ export const generateStylesForSectionBackground = ( {
10971097
!! backgroundText?.lineHeight
10981098
? backgroundText.lineHeight
10991099
: undefined;
1100-
styles[ '--smb-section--background-text-top' ] = !! backgroundText
1101-
?.position?.top
1102-
? backgroundText.position.top.match( /^\d+$/ )
1100+
styles[ '--smb-section--background-text-top' ] =
1101+
!! backgroundText?.position?.top &&
1102+
backgroundText.position.top.match( /^\d+$/ )
11031103
? `${ backgroundText.position.top }px`
1104-
: backgroundText.position.top
1105-
: undefined;
1106-
styles[ '--smb-section--background-text-right' ] = !! backgroundText
1107-
?.position?.right
1108-
? backgroundText.position.right.match( /^\d+$/ )
1104+
: backgroundText.position.top;
1105+
styles[ '--smb-section--background-text-right' ] =
1106+
!! backgroundText?.position?.right &&
1107+
backgroundText.position.right.match( /^\d+$/ )
11091108
? `${ backgroundText.position.right }px`
1110-
: backgroundText.position.right
1111-
: undefined;
1112-
styles[ '--smb-section--background-text-bottom' ] = !! backgroundText
1113-
?.position?.bottom
1114-
? backgroundText.position.bottom.match( /^\d+$/ )
1109+
: backgroundText.position.right;
1110+
styles[ '--smb-section--background-text-bottom' ] =
1111+
!! backgroundText?.position?.bottom &&
1112+
backgroundText.position.bottom.match( /^\d+$/ )
11151113
? `${ backgroundText.position.bottom }px`
1116-
: backgroundText.position.bottom
1117-
: undefined;
1118-
styles[ '--smb-section--background-text-left' ] = !! backgroundText
1119-
?.position?.left
1120-
? backgroundText.position.left.match( /^\d+$/ )
1114+
: backgroundText.position.bottom;
1115+
styles[ '--smb-section--background-text-left' ] =
1116+
!! backgroundText?.position?.left &&
1117+
backgroundText.position.left.match( /^\d+$/ )
11211118
? `${ backgroundText.position.left }px`
1122-
: backgroundText.position.left
1123-
: undefined;
1119+
: backgroundText.position.left;
11241120
}
11251121

11261122
return styles;

Diff for: src/blocks/section/edit.js

+16-20
Original file line numberDiff line numberDiff line change
@@ -534,29 +534,25 @@ export default function ( {
534534
positionValue: backgroundText.position,
535535
onPositionChange: ( value ) => {
536536
newBackgroundText.position.top =
537-
null != value?.top
538-
? value?.top.match( /^\d+$/ )
539-
? `${ value?.top }px`
540-
: value?.top
541-
: undefined;
537+
null != value?.top &&
538+
value?.top.match( /^\d+$/ )
539+
? `${ value?.top }px`
540+
: value?.top;
542541
newBackgroundText.position.right =
543-
null != value?.right
544-
? value?.right.match( /^\d+$/ )
545-
? `${ value?.right }px`
546-
: value?.right
547-
: undefined;
542+
null != value?.right &&
543+
value?.right.match( /^\d+$/ )
544+
? `${ value?.right }px`
545+
: value?.right;
548546
newBackgroundText.position.bottom =
549-
null != value?.bottom
550-
? value?.bottom.match( /^\d+$/ )
551-
? `${ value?.bottom }px`
552-
: value?.bottom
553-
: undefined;
547+
null != value?.bottom &&
548+
value?.bottom.match( /^\d+$/ )
549+
? `${ value?.bottom }px`
550+
: value?.bottom;
554551
newBackgroundText.position.left =
555-
null != value?.left
556-
? value?.left.match( /^\d+$/ )
557-
? `${ value?.left }px`
558-
: value?.left
559-
: undefined;
552+
null != value?.left &&
553+
value?.left.match( /^\d+$/ )
554+
? `${ value?.left }px`
555+
: value?.left;
560556

561557
setAttributes( {
562558
backgroundText: cleanEmptyObject( {

0 commit comments

Comments
 (0)